var UDOC={};UDOC.B=function(){var U=new Uint8Array(4),v=U.buffer,W=new Int16Array(v),H=new Uint16Array(v),p=new Int32Array(v),M=new Uint32Array(v),S=new Float32Array(v); return{readShort:function(Z,a){U[0]=Z[a];U[1]=Z[a+1];return W[0]},readUshort:function(Z,a){U[0]=Z[a]; U[1]=Z[a+1];return H[0]},readInt:function(Z,a){U[0]=Z[a];U[1]=Z[a+1];U[2]=Z[a+2];U[3]=Z[a+3];return p[0]},readUint:function(Z,a){U[0]=Z[a]; U[1]=Z[a+1];U[2]=Z[a+2];U[3]=Z[a+3];return M[0]},readUintBE:function(Z,a){U[3]=Z[a];U[2]=Z[a+1];U[1]=Z[a+2]; U[0]=Z[a+3];return M[0]},readFloat:function(Z,a){U[0]=Z[a];U[1]=Z[a+1];U[2]=Z[a+2];U[3]=Z[a+3];return S[0]},readASCII:function(Z,a,Y){var I=""; for(var w=0;wH)H=S;if(Zp)p=Z}return[v,W,H,p]},rectToPath:function(U){return{cmds:["M","L","L","L","Z"],crds:[U[0],U[1],U[2],U[1],U[2],U[3],U[0],U[3]]}},insideBox:function(U,v){return v[0]<=U[0]&&v[1]<=U[1]&&U[2]<=v[2]&&U[3]<=v[3]},isBox:function(U,v){var W=function(g,_){for(var C=0; C<8;C+=2){var O=!0;for(var $=0;$<8;$++)if(Math.abs(_[$]-g[$+C&7])>=2){O=!1;break}if(O)return!0}return!1},M=!1; if(U.cmds.length>10)return!1;var H=U.cmds.join(""),p=U.crds;if(H=="MLLLZ"&&p.length==8||(H=="MLLLLZ"||H=="MLLLL")&&p.length==10){if(p.length==10)p=p.slice(0,8); if(v==null){v=[p[0],p[1],p[0],p[1]];for(var S=0;Sp)M-=2*Math.PI; else while(M(H[1]-W[1])*(w[0]-W[0])},Z=function(){var w=[W[0]-H[0],W[1]-H[1]],q=[p[0]-M[0],p[1]-M[1]],g=W[0]*H[1]-W[1]*H[0],n=p[0]*M[1]-p[1]*M[0],_=1/(w[0]*q[1]-w[1]*q[0]); return[(g*q[0]-n*w[0])*_,(g*q[1]-n*w[1])*_]},a=U,Y,I;W=v[v.length-1];for(I in v){var H=v[I],R=a;a=[]; p=R[R.length-1];for(Y in R){var M=R[Y];if(S(M)){if(!S(p)){a.push(Z())}a.push(M)}else if(S(p)){a.push(Z())}p=M}W=H}return a}}; UDOC.M={getScale:function(U){return Math.sqrt(Math.abs(U[0]*U[3]-U[1]*U[2]))},translate:function(U,v,W){UDOC.M.concat(U,[1,0,0,1,v,W])},rotate:function(U,v){UDOC.M.concat(U,[Math.cos(v),-Math.sin(v),Math.sin(v),Math.cos(v),0,0])},scale:function(U,v,W){UDOC.M.concat(U,[v,0,0,W,0,0])},concat:function(U,v){var W=U[0],H=U[1],p=U[2],M=U[3],S=U[4],Z=U[5]; U[0]=W*v[0]+H*v[2];U[1]=W*v[1]+H*v[3];U[2]=p*v[0]+M*v[2];U[3]=p*v[1]+M*v[3];U[4]=S*v[0]+Z*v[2]+v[4]; U[5]=S*v[1]+Z*v[3]+v[5]},invert:function(U){var v=U[0],W=U[1],H=U[2],p=U[3],M=U[4],S=U[5],Z=v*p-W*H; U[0]=p/Z;U[1]=-W/Z;U[2]=-H/Z;U[3]=v/Z;U[4]=(H*S-p*M)/Z;U[5]=(W*M-v*S)/Z},multPoint:function(U,v){var W=v[0],H=v[1]; return[W*U[0]+H*U[2]+U[4],W*U[1]+H*U[3]+U[5]]},multArray:function(U,v){for(var W=0;WW?R:(116*Y-16)/v,n=a>W?a:(116*Z-16)/v,_=q>W?q:(116*w-16)/v,C=_*96.72,O=n*100,$=g*81.427,b=[C/100,O/100,$/100],V=[3.1338561,-1.6168667,-.4906146,-.9787684,1.9161415,.033454,.0719453,-.2289914,1.4052427],d=[V[0]*b[0]+V[1]*b[1]+V[2]*b[2],V[3]*b[0]+V[4]*b[1]+V[5]*b[2],V[6]*b[0]+V[7]*b[1]+V[8]*b[2]]; for(var G=0;G<3;G++)d[G]=Math.max(0,Math.min(1,UDOC.C.srgbGamma(d[G])));return d}};UDOC.getState=function(U){return{font:UDOC.getFont(),dd:{flat:1},ca:1,colr:[0,0,0],space:"/DeviceGray",CA:1,COLR:[0,0,0],sspace:"/DeviceGray",bmode:"/Normal",SA:!1,OPM:0,AIS:!1,OP:!1,op:!1,SMask:"/None",lwidth:1,lcap:0,ljoin:0,mlimit:10,SM:.1,doff:0,dash:[],ctm:[1,0,0,1,0,0],cpos:[0,0],pth:{cmds:[],crds:[]},cpth:U?UDOC.G.rectToPath(U):null,cpstack:[]}}; UDOC.getFont=function(){return{Tc:0,Tw:0,Th:100,Tl:0,Tf:"Helvetica-Bold",Tfs:1,Tmode:0,Trise:0,Tk:0,Tal:0,Tun:0,Tm:[1,0,0,1,0,0],Tlm:[1,0,0,1,0,0],Trm:[1,0,0,1,0,0]}}; function FromPS(){}FromPS.Parse=function(U,v){U=new Uint8Array(U);var W=0,M=null,S=null,_=!0;while(!(U[W]==37&&U[W+1]==33))W++; var H=FromPS.B.readASCII(U,W,U.length-W),p=H.split(/[\n\r]+/);for(var Z=0;Z>"){var b=[];while(U.length!=0){var V=U.pop();if(V.typ=="mark")break;b.push(V)}b.reverse(); if(g=="]")U.push({typ:"array",val:b});else{var d={};for(var G=0;G=bU.val.length){}else if(an.typ=="string")for(var G=0;G=0; G--)if(W[G].typ=="file"){ap=W[G];break}U.push({typ:"file",val:ap.val})}else if(r=="currentdict"){var N=v[v.length-1]; U.push({typ:"dict",val:N,maxl:1e3})}else if("currentpacking currentoverprint currentglobal currentsystemparams currentuserparams currentpagedevice".split(" ").indexOf(r)!=-1){var f=p[r.slice(7)]; U.push({typ:typeof f=="boolean"?"boolean":"dict",val:f})}else if(r=="gcheck"){var B=U.pop();U.push({typ:"boolean",val:!1})}else if("setpacking setoverprint setglobal setsystemparams setuserparams setpagedevice".split(" ").indexOf(r)!=-1){p[r.slice(3)]=U.pop().val}else if(r=="currentflat"){U.push({typ:"real",val:1})}else if(r=="currentlinewidth"){U.push({typ:"real",val:R.lwidth})}else if(r=="currentdash"){U.push({typ:"array",val:FromPS.makeArr(R.dash,"integer")},{typ:"real",val:R.doff})}else if(r=="currentpoint"){var a7=R.ctm.slice(0); UDOC.M.invert(a7);var aa=UDOC.M.multPoint(a7,R.cpos);U.push({typ:"real",val:aa[0]},{typ:"real",val:aa[1]})}else if(r=="currentscreen"){U.push({typ:"int",val:60},{typ:"real",val:0},{typ:"real",val:0})}else if(r=="setscreen"){U.pop(); U.pop();U.pop()}else if(r=="currenthalftone"){U.push({typ:"dict",val:{},maxl:1e3})}else if(r=="currentblackgeneration"||r=="currentundercolorremoval"){U.push(p.funs[r.slice(7)])}else if(r=="currentcolortransfer"){for(var G=0; G<4;G++)U.push(p.funs.blackgeneration)}else if(r=="findresource"){var cl=U.pop().val.slice(1),bG=U.pop(),P=bG.val.slice(1),aj; if(cl=="Font"){p.res[cl].val[P]={typ:"dict",val:{FontType:{typ:"integer",val:1},FontMatrix:{typ:"array",val:FromPS.makeArr([1,0,0,1,0,0],"real")},FontName:bG,FID:{typ:"fontID",val:Math.floor(Math.random()*16777215)},Encoding:{typ:"array",val:[]},FontBBox:{typ:"array",val:FromPS.makeArr([0,0,1,1],"real")},PaintType:{typ:"integer",val:0}}}}if(cl=="Category"&&P=="Generic")aj={typ:"dict",val:{},maxl:1e3}; else if((cl=="ProcSet"||cl=="Procset")&&P=="CIDInit")aj={typ:"dict",val:{},maxl:1e3};else aj=p.res[cl].val[P]; if(aj==null)throw"e";U.push(aj)}else if(r=="resourcestatus"){var cl=U.pop().val.slice(1),P=U.pop().val.slice(1),aj=p.res[cl].val[P]; if(aj){U.push({typ:"integer",val:1});U.push({typ:"integer",val:Object.keys(aj.val).length})}U.push({typ:"boolean",val:aj!=null})}else if(r=="defineresource"){var cl=U.pop().val.slice(1),bm=U.pop(),P=U.pop().val.slice(1); p.res[cl].val[P]=bm;U.push(bm)}else if(r=="undefineresource"){var cl=U.pop().val.slice(1),P=U.pop().val.slice(1); delete p.res[cl].val[P]}else if(r=="resourceforall"){var cl=U.pop().val.slice(1),b7=U.pop().val,F=U.pop(),af=U.pop().val; if(af.length!=1||af[0]!=42)throw"e";var c3=p.res[cl].val;for(var P in c3){var z=b7.slice(0);for(var G=0; G0?t<>>-y;if(r=="mod")j=t%y;if(r=="exp")j=Math.pow(t,y);if(r=="atan")j=Math.atan2(t,y)*180/Math.PI; if(b$=="real"){Y[0]=j;j=Y[0]}U.push({typ:b$,val:j})}else if("neg abs floor ceiling round truncate sqrt ln sin cos".split(" ").indexOf(r)!=-1){var k=U.pop(),t=k.val,j=0,b$=""; if(r=="neg"||r=="abs"||r=="truncate"||r=="floor"||r=="ceiling"||r=="round")b$=k.typ;else if(r=="sqrt"||r=="sin"||r=="cos"||r=="ln")b$="real"; if(k.typ=="real"){Y[0]=t;t=Y[0]}if(r=="neg")j=-t;if(r=="abs")j=Math.abs(t);if(r=="floor")j=Math.floor(t); if(r=="ceiling")j=Math.ceil(t);if(r=="round")j=Math.round(t);if(r=="truncate")j=Math.trunc(t);if(r=="sqrt")j=Math.sqrt(t); if(r=="ln")j=Math.log(t);if(r=="sin")j=Math.sin(t*Math.PI/180);if(r=="cos")j=Math.cos(t*Math.PI/180); if(r=="ln"&&t<=0)throw"e";if(b$=="real"){Y[0]=j;j=Y[0]}U.push({typ:b$,val:j})}else if("eq ge gt le lt ne".split(" ").indexOf(r)!=-1){var ah=U.pop(),k=U.pop(),ch=k.typ,cv=ah.typ,t=k.val,y=ah.val,j=!1; if(r=="eq"||r=="ne"){var x=k.typ==ah.typ;if(x&&["integer","real","name","null","dict"].indexOf(ch)!=-1)j=t==y; else if(ch=="real"&&cv=="integer"||cv=="real"&&ch=="integer")j=t==y;else if(!x&&(k.typ=="null"||ah.typ=="null"))j=!1; else if(x&&k.typ=="string"){if(t.length!=y.length)j=!1;else{j=!0;for(var G=0;G=y;else if(r=="gt")j=t>y;else if(r=="le")j=t<=y;else if(r=="lt")j=t0&&e.init<=e.limit||e.inc<0&&e.init>=e.limit){W.push(w);FromPS.addProc(e.proc,W); U.push({typ:"integer",val:e.init});e.init+=e.inc}}else{var c=new Float32Array(1);c[0]=e.limit;e.limit=c[0]; c[0]=e.inc;e.inc=c[0];c[0]=e.init;if(e.inc>0&&c[0]<=e.limit||e.inc<0&&c[0]>=e.limit){W.push(w);FromPS.addProc(e.proc,W); U.push({typ:"real",val:c[0]});c[0]+=e.inc;e.init=c[0]}}}else if(r=="loop"){var F=U.pop();W.push({typ:"name",val:r+"---",ctx:{proc:F}})}else if(r=="loop---"){var e=w.ctx; W.push(w);FromPS.addProc(e.proc,W)}else if(r=="pathforall"){var E=U.pop(),c4=U.pop(),bW=U.pop(),bg=U.pop()}else if(r=="forall"){var F=U.pop(),A=U.pop(),e=[F,A,0]; W.push({typ:"name",val:r+"---",ctx:e})}else if(r=="forall---"){var e=w.ctx,F=e[0],A=e[1],G=e[2];if(A.typ=="dict"){var bD=Object.keys(A.val); if(GG)W.pop()}else if(r=="bind"){}else if(r=="xcheck"){var A=U.pop(),q=A.typ;U.push({typ:"boolean",val:q=="procedure"})}else if(r=="status"){var z=U.pop(); U.push({typ:"boolean",val:!1})}else if(r=="cachestatus"){for(var G=0;G<7;G++)U.push({typ:"integer",val:5e3})}else if(r=="setcachelimit"){U.pop()}else if(r=="type"){var V=U.pop(),cp={name:"nametype",dict:"dicttype",boolean:"booleantype",procedure:"operatortype",string:"stringtype",null:"nulltype",integer:"integertype",array:"arraytype",operator:"operatortype",real:"realtype"}; if(cp[V.typ]==null){console.log(V);throw V.typ}U.push({typ:"name",val:"/"+cp[V.typ]})}else if(r=="save"){U.push({typ:"state",val:JSON.parse(JSON.stringify(R))})}else if(r=="restore"){R=p.gst=U.pop().val}else if(r=="clipsave"){R.cpstack.push(JSON.parse(JSON.stringify(R.cpth)))}else if(r=="cliprestore"){R.cpath=R.cpstack.pop()}else if(r=="gsave"){H.push(JSON.parse(JSON.stringify(R)))}else if(r=="grestore"){if(H.length!=0)R=p.gst=H.pop(); else R=UDOC.getState()}else if(r=="grestoreall"){while(H.length!=0)R=p.gst=H.pop()}else if(r=="usertime"||r=="realtime")U.push({typ:"integer",val:r=="usertime"?Date.now()-a:Date.now()}); else if(r=="flush"||r=="readonly"||r=="executeonly"){}else if(r=="flushfile"){FromPS.GetFile(U.pop())}else if(r=="filter"){var aF=U.pop().val,av; if(aF=="/SubFileDecode"){var z=U.pop();if(z.typ!="string")throw"e";var cj=U.pop().val;z=z.val;av=[aF,z,cj]}else av=[aF]; var a1=U.pop();U.push({typ:"file",val:{buff:new Uint8Array,off:0},_flt:av,_src:a1})}else if(r=="begincmap"||r=="endcmap"){}else if(r=="begincodespacerange"||r=="beginbfrange"||r=="beginbfchar"){p.cmnum=U.pop().val}else if(r=="endcodespacerange"||r=="endbfrange"||r=="endbfchar"){var E=r=="endbfrange"?3:2,aS=r.slice(3),N=v[v.length-1],bX=0; if(N[aS]==null)N[aS]=[];for(var G=0;G=0;bC--){var aM=U.pop(),ba=aM.val,f; if(aM.typ=="string"){f=FromPS.strToInt(ba);if(bC==0)bX=ba.length}else{f=[];for(var bn=0;bn=U.buff.length)throw"e";var S=U.buff[M];M++;if(FromPS.isWhite(S))continue;if(S==126){if(H!=0){if(H==3){W.push(p>>>24&255)}if(H==4){W.push(p>>>24&255,p>>>16&255)}var Z=5-H<<3,Y=p>>>Z&255; p=p&(1<>>24&255);W.push(p>>>16&255);W.push(p>>>8&255);W.push(p>>>0&255); H=0;p=0}}},RunLengthDecode:function(U){var v=[],W=U.off;while(!0){if(W>=U.buff.length){console.log(v); throw"e"}var H=U.buff[W];W++;if(H==128){U.off=W;return new Uint8Array(v)}if(H<128){for(var p=0;p>>3]<<16|H[O+8>>>3]<<8|H[O+16>>>3];d=V>>24-(O&7)-C&(1<>>3]<<16|H[O+8>>>3]<<8|H[O+16>>>3];d=V>>24-(O&7)-C&(1<=n){w[n]=_;I[w[n]]=P[0];q[n]=1;_=_+1+3&~3; n++}else{w[n]=_;var h=w[s],z=q[s];v(I,h,I,_,z);I[_+z]=I[P];z++;q[n]=z;n++;_=_+z+3&~3}if(n+1==1<=n){w[n]=_; q[n]=0;n++}else{w[n]=_;var h=w[s],z=q[s];v(I,h,I,_,z);I[_+z]=I[_];z++;q[n]=z;n++;v(I,_,M,S,z);S+=z;_=_+z+3&~3}if(n+1==1<=0){if(v[W][U]!=null)return v[W][U];W--}return null};FromPS.where=function(U,v){var W=v.length-1; while(W>=0){if(v[W][U]!=null)return v[W];W--}return null};FromPS.skipWhite=function(U){var v=U.off,W=U.buff,H=FromPS.isWhite; while(H(W[v])||W[v]==37){while(H(W[v]))v++;if(W[v]==37){while(v1){U.pop();if(U.length!=0)p=FromPS.getFToken(U[U.length-1].val,v)}return p}; FromPS.getFToken=function(U,v){FromPS.skipWhite(U);var W=FromPS.isWhite,H=FromPS.isSpecl,p=U.off,M=U.buff,S=null; if(p>=M.length)return null;var Z=M[p],Y=String.fromCharCode(Z);p++;if(Y=="("){var I=0,R=p;while(!(M[R]==41&&I==0)){if(M[R]==40)I++; if(M[R]==41)I--;if(M[R]==92)R++;R++}var w=[];for(var q=0;q"&&M[p]==62){S={typ:"name",val:Y=="<"?"<<":">>"}; p++}else if(Y=="<"){var w;if(M[p]=="~".charCodeAt(0)){U.off=p+1;var g=FromPS.F.ASCII85Decode(U);w=[]; for(var q=0;qM[5]){M=M.slice(3).concat(M.slice(0,3)); p.reverse();a.reverse();for(var R=0;R0)Z.push([0,W(H[0],[S[0]],v)]);for(var Y=0;Y>1)&255; if(R==4)for(var w=p;w>1)&255;for(var w=p;w>1)&255}if(R==4){for(var w=0; w=0;Y--)M.push(a[Y]);continue}var I=Z["/MediaBox"];if(I==null)I=U["/Pages"]["/MediaBox"]; S+=(I[2]-I[0])*(I[3]-I[1])}var M=[U["/Pages"]],R=-1,w=[-1e9,1e9];while(M.length!=0){var Z=M.pop();if(Z["/Type"]=="/Pages"){var a=Z["/Kids"]; for(var Y=a.length-1;Y>=0;Y--)M.push(a[Y]);continue}R++;if(R=w[1])break}};FromPDF.addCmd=function(U,v,W){var H=U.length,p=new Uint8Array(H);for(var M=0;M>1)]>>(1-(W&1)<<2)&15; else if(H==2)p=U[v+(W>>2)]>>(3-(W&3)<<1)&3;else if(H==1)p=U[v+(W>>3)]>>(7-(W&7)<<0)&1;return p};FromPDF.getString=function(U,v){var W=v["/Subtype"],H="",p=0,M=null,S=v["/ToUnicode"],Z=v["/Encoding"],a=v,at; if(S!=null&&typeof S!="object")S=null;if(W=="/Type0")a=v["/DescendantFonts"][0];if(S!=null)H=FromPDF.toUnicode(U,S); else if(Z=="/WinAnsiEncoding")H=FromPDF.encFromMap(U,FromPDF._win1252);else if(Z=="/MacRomanEncoding")H=FromPDF.encFromMap(U,FromPDF._macRoman); else if(W=="/Type0"){var Y=0,I=a["/CIDSystemInfo"]["/Ordering"];if(I=="Identity")Y=0;else if(I=="Japan1")Y=31; else if(I=="GB1")Y=31;else if(I=="CNS1")Y=31;else if(I=="Korea1")Y=31;else{console.log("unknown ordering",I); Y=0}for(var R=0;R4){H--;W++}return U[W]<<24|U[W+1]<<16|U[W+2]<<8|U[W+3]}; FromPDF.getIndirect=function(U,v,W,H){var p=H[U],Z;if(p.chr=="f")return null;if(p.val!=null)return p.val; if(p.opn)return{typ:"ref",ind:U,gen:v};p.opn=!0;var M=W.off;if(p.chr=="s"){var Y=FromPDF.getIndirect(p.off,p.gen,W,H),I={buff:FromPS.GS(Y),off:0},R=0,w=0; while(R!=U){R=FromPS.getFToken(I).val;w=FromPS.getFToken(I).val}I.off=w+Y["/First"];Z=FromPDF.readObject(I,W,H)}else{W.off=p.off; var q=FromPS.getFToken(W);if(q.val!="<<"){var g=FromPS.getFToken(W),n=FromPS.getFToken(W)}else W.off-=2; Z=FromPDF.readObject(W,W,H)}p.val=Z;W.off=M;p.opn=!1;return Z};FromPDF.readObject=function(U,v,W){var H=FromPS.getFToken(U); if(H.typ=="integer"){var p=U.off,M=FromPS.getFToken(U);if(M&&M.typ=="integer"){FromPS.skipWhite(U);if(U.buff[U.off]==82){U.off++; if(W&&W[H.val])return FromPDF.getIndirect(H.val,M.val,v,W);else return{typ:"ref",ind:H.val,gen:M.val}}}U.off=p}if(H.val=="<<")return FromPDF.readDict(U,v,W); if(H.val=="[")return FromPDF.readArra(U,v,W);if(H.typ=="string"){var S="";for(var Z=0;Z>")throw"e";return H.val};FromPDF.readDict=function(U,v,W){var H={}; while(!0){var p=U.off,M=FromPS.getFToken(U);if(M.typ=="name"&&M.val==">>")break;U.off=p;var S=FromPDF.readObject(U,v,W),Z=FromPDF.readObject(U,v,W); H[S]=Z}if(H["/Length"]!=null&&H["/CFM"]==null){var a=H["/Length"],Y=FromPS.getFToken(U);if(U.buff[U.off]==32)U.off++; if(U.buff[U.off]==13)U.off++;if(U.buff[U.off]==10)U.off++;if(U.off+a>U.buff.length){console.log("too big /Length of a stream",a,U.buff.length-U.off,U.off)}H.buff=U.buff.slice(U.off,U.off+a); U.off+=a;FromPS.getFToken(U)}return H};FromPDF.readArra=function(U,v,W){var H=[];while(!0){var p=U.off,M=FromPS.getFToken(U); if(M.typ=="name"&&M.val=="]")return H;U.off=p;var S=FromPDF.readObject(U,v,W);H.push(S)}};var FromWMF=function(){var U=0,v=53,W=55,H=258,p=259,M=260,S=261,Z=262,a=263,Y=264,I=295,R=313,w=322,q=329,g=513,n=521,_=529,C=531,O=532,$=544,b=552,V=561,d=564,G=804,A=805,r=522,s=523,f=524,ci=525,P=526,at=527,N=1040,h=1042,z=1045,ct=1046,m=1048,cn=1049,cj=1065,bJ=1078,an=1313,j=1336,bU=1352,aD=1051,cc=1055,c6=1564,a9=1565,b2=30,aT=2074,ap=2851,B=1574,a7=298,aa=299,cl=300,bG=301,aj=302,bm=2071,b7=2096,F=2338,af=2610,c3=3379,a4=2368,al=2881,bX=3907,c0=496,c5=247,bh=505,c9=762,a_=763,bM=764,aA=1791,be=1,bN=2,ce=3,bC=4,b9=5,bz=6,b0=7,bT=8,a5=9,bY=10,a2=11,bK=12,K=13,b_=14,bQ=15,aR=16,bu=17,bc=18,ao=19,az=20,c2=21,a6=22,aL=23,bw=24,bf=25,bV=26,cd=27,bR=28,aJ=29,bn=30,ax=31,aH=32,ad=33,bH=34,aB=35,bv=37,aW=38,aZ=42,b5=256,bq=258,bO=512,au=513,by=514,aP=2049,aK=3073,bx=4096,ag=4097,aI=4098,aE=4110,c8=4111,a$=4112,aC=4115,a3=4116,cs=4117,aY=4118,L=4119,bl=4120,ah=4121,k=4122,Q=4568,t=UDOC.B; function y(l,i){l=new Uint8Array(l);var D=0,u={fill:!1,strk:!1,bb:[0,0,1,1],lbb:[0,0,1,1],scl:1,fnt:{nam:"Arial",hgh:25,und:!1,orn:0,chrst:0},tclr:[0,0,0],talg:0},J=t.readShort,T=t.readUshort,o=t.readUint,b4=o(l,0),a0=0; if(b4==2596720087){D=6;var bA=J(l,D+8);u.scl=120/bA;for(var ck=0;ck<4;ck++){u.bb[ck]=Math.round(J(l,D)*u.scl); D+=2}D+=2;D+=6}i.StartPage(u.bb[0],u.bb[1],u.bb[2],u.bb[3]);var X=UDOC.getState(u.bb),bo=T(l,D);D+=2; var bB=T(l,D);D+=2;var bS=T(l,D);D+=2;var bp=o(l,D);D+=4;var bs=T(l,D);D+=2;var b3=o(l,D);D+=4;var bs=T(l,D); D+=2;var e=[];while(!0){var aG=o(l,D)<<1,c4=null;D+=4;var br=T(l,D);D+=2;var c=br,E=D;if(!1){}else if(c==U)break; else if(c==B){var bW=T(l,D);E+=2;var bg=bW;console.log(c,bg)}else if(c==p||c==Z||c==H){}else if(c==bG){var bD=T(l,E); E+=2;var ac=e[bD];if(ac.t=="br"){u.fill=ac.stl!=1;if(ac.stl==0){}else if(ac.stl==1){}else throw ac.stl+" e"; X.colr=ac.clr}else if(ac.t=="pn"){var cp=ac.stl&7;u.strk=cp!=5;if(cp==0||cp==6)X.lwidth=ac.px;else if(cp==5){}else throw cp+" e"; if((ac.stl&4096)!=0)X.ljoin=2;else if((ac.stl&8192)!=0)X.ljoin=0;else X.ljoin=1;X.COLR=ac.clr}else if(ac.t=="fn"){u.fnt=ac; X.font.Tf=ac.nam;X.font.Tfs=Math.abs(ac.hgh);X.font.Tun=ac.und}else throw"e"}else if(c==c0){var bD=T(l,E); E+=2;e[bD]=null}else if(c==s||c==f){var aF=c==s?0:2;u.lbb[aF+1]=J(l,E);E+=2;u.lbb[aF]=J(l,E);E+=2;ch(u,X)}else if(c==bM){c4={t:"br"}; c4.stl=T(l,E);E+=2;c4.clr=[l[E]/255,l[E+1]/255,l[E+2]/255];E+=4;c4.htc=T(l,E);E+=2}else if(c==c9){c4={t:"pn"}; c4.stl=T(l,E);E+=2;c4.px=J(l,E);E+=2;c4.py=J(l,E);E+=2;c4.clr=[l[E]/255,l[E+1]/255,l[E+2]/255];E+=4}else if(c==a_){c4={t:"fn",nam:""}; c4.hgh=J(l,E);E+=2;E+=2*2;c4.orn=J(l,E)/10;E+=2;var av=J(l,E);E+=2;c4.und=l[E+1];E+=2;c4.stk=l[E];c4.chrst=l[D+1]; E+=2;E+=4;while(l[E]!=0){c4.nam+=String.fromCharCode(l[E]);E++}if(av>500)c4.nam+="-Bold"}else if(c==c5){c4={t:"pl"}}else if(c==n)u.tclr=[l[E]/255,l[E+1]/255,l[E+2]/255]; else if(c==aj)u.talg=T(l,E);else if(c==O){UDOC.G.moveTo(X,J(l,E+2),J(l,E))}else if(c==C){if(X.pth.cmds.length==0){var a1=X.ctm.slice(0); UDOC.M.invert(a1);var aS=UDOC.M.multPoint(a1,X.cpos);UDOC.G.moveTo(X,aS[0],aS[1])}UDOC.G.lineTo(X,J(l,E+2),J(l,E)); var cr=u.fill;u.fill=!1;cv(i,X,u);u.fill=cr}else if(c==j){var aM=T(l,E);E+=2;var ba=E;E+=aM*2;for(var ck=0; ck127){ck++;bE=bE<<8|l[E+ck]}as+=String.fromCharCode(bE)}var b6=X.colr;X.colr=u.tclr;i.PutText(X,as,as.length*X.font.Tfs*.5); X.colr=b6}else{console.log(c,aG)}if(c4!=null){var aU=0;while(e[aU]!=null)aU++;e[aU]=c4}D+=aG-6}i.ShowPage(); i.Done()}function b$(l,i){var D=t.readShort,u=t.readUshort,J=t.readUint,T=J(l,i),o,b4,bA;i+=4;if(T==12)throw"e"; else{o=J(l,i);i+=4;b4=J(l,i);i+=4;var ck=u(l,i);i+=2;if(ck!=1)throw"e";var X=u(l,i);i+=2;if(X!=1&&X!=24&&X!=32)throw X+" e"; var bo=J(l,i);i+=4;if(bo!=0)throw"e";var bB=J(l,i);i+=4;var bS=J(l,i);i+=4;var bp=J(l,i);i+=4;bA=J(l,i); i+=4;var bs=J(l,i);i+=4}var b3=o*b4,e=new Uint8Array(b3*4),a0=Math.floor((o*ck*X+31&~31)/8);if(X==1)for(var aG=0; aG>>3)]>>>7-(c&7)&1; e[E]=l[i+c4*4+2];e[E+1]=l[i+c4*4+1];e[E+2]=l[i+c4*4+0];e[E+3]=255}}if(X==24){for(var aG=0;aG500)o.nam+="-Bold"}else if(u==K){T+=16; var bp=x(L,T),bg="";T+=4;var bs=l(L,T);T+=4;var b3=l(L,T);T+=4;var e=cv(L,T);T+=4;var a0=cv(L,T);T+=4; var aG=Q.ctm.slice(0);if(bp==1)Q.ctm=[1,0,0,1,0,0];Q.font.Tm=[1,0,0,-1,0,0];UDOC.M.rotate(Q.font.Tm,k.fnt.orn*Math.PI/180); UDOC.M.translate(Q.font.Tm,e,a0);var br=k.talg;if((br&6)==6)Q.font.Tal=2;else if((br&7)==0)Q.font.Tal=0; else throw br+" e";if((br&24)==24){}else if((br&24)==0)UDOC.M.translate(Q.font.Tm,0,Q.font.Tfs);else console.log("unknown alignment",br); var c=x(L,T);T+=4;var E=x(L,T);T+=4;var c4=x(L,T);T+=4;T+=16;var bW=x(L,T);T+=4;E+=ah-8;for(var bD=0; bD0){UDOC.G.curveTo(Q,aq(L,T),aq(L,T+ai),aq(L,T+2*ai),aq(L,T+3*ai),aq(L,T+4*ai),aq(L,T+5*ai)); T+=6*ai;cr-=3}}else if(u==aD||u==bU){UDOC.G.newPath(Q);var b1=aC(L,T);if(u==aD){UDOC.G.drawRect(Q,b1[0],b1[1],b1[2]-b1[0],b1[3]-b1[1])}else{var aV=(b1[0]+b1[2])/2,cg=(b1[1]+b1[3])/2; UDOC.G.arc(Q,aV,cg,(b1[2]-b1[0])/2,0,2*Math.PI,!1)}UDOC.G.closePath(Q);cs(bl,Q,k,!0)}else if(u==al)bl.Fill(Q,!1); else if(u==c0)bl.Stroke(Q);else if(u==bX){bl.Fill(Q,!1);bl.Stroke(Q)}else if(u==ct||u==m){var c7=[]; for(var bD=0;bD<6;bD++)c7.push(l(L,T+bD*4));T+=24;if(u==ct)Q.ctm=c7;else{var bp=x(L,T);T+=4;if(bp==2){var bj=Q.ctm; Q.ctm=c7;UDOC.M.concat(Q.ctm,bj)}else throw"e"}}else if(u==b){var aQ=x(L,T);T+=4}else if(u==bY){var b1=aC(L,T); T+=16;var am=cv(L,T);T+=4;var cq=cv(L,T);T+=4;var bF=cv(L,T);T+=4;var ab=cv(L,T);T+=4;var ae=cv(L,T); T+=4;var aX=cv(L,T);T+=4;var aN=x(L,T)+ah-8;T+=4;var aw=x(L,T);T+=4;var bZ=x(L,T)+ah-8;T+=4;var bd=x(L,T); T+=4;var ak=x(L,T);T+=4;if(ak!=0)throw"e";var bP=x(L,T);T+=4;var ar=cv(L,T);T+=4;var as=cv(L,T);T+=4; var bE=x(L,aN);aN+=4;var b6=x(L,aN);aN+=4;var aU=x(L,aN);aN+=4;if(b6!=ae||aU!=aX)throw"e";var c1=ch(L,aN); aN+=2;var bI=ch(L,aN);aN+=2;if(bI!=1&&bI!=4&&bI!=8&&bI!=24&&bI!=32)throw bI+" e";var a8=x(L,aN);aN+=4; if(a8!=0)throw a8+" e";var bb=x(L,aN);aN+=4;var cf=x(L,aN);aN+=4;var b8=x(L,aN);aN+=4;var bk=x(L,aN); aN+=4;var bL=x(L,aN);aN+=4;var aO=Math.floor((b6*c1*bI+31&~31)/8),ay=new Uint8Array(b6*aU*4);if(bI==8){for(var cg=0; cg>>1); for(var A=0;Ab9)b9=b0}for(var A=0;A=I[Z+Y+1])return 0;for(var C=0;C<=Y;C++){if(R>=I[Z+C]&&R255){var s=G.indexOf(r);d.push(s==-1?32:G[s-1])}else d.push(r)}}else{for(var A=0; A>2);s[f]=C[A+0]; s[f+1]=C[A+1];s[f+2]=C[A+2]}}var ci=this._res["/XObject"];for(var P in ci){var at=this._xr[ci[P].ind],N=at["/SMask"],h=N!=null?1:0,z=V!=null?1:0; if(!S(at.stream,s)||h+z==1)continue;if(h+z==2&&!S(this._xr[N.ind].stream,G))continue;return P}var P="/I"+(w(ci)+1); ci[P]={typ:"ref",ind:this._xr.length};var ct={"/Type":"/XObject","/Subtype":"/Image","/BitsPerComponent":8,"/ColorSpace":C.length==O*$||r=="/DCTDecode"&&R(C)&&R(C).comps==1?"/DeviceGray":"/DeviceRGB","/Height":$,"/Width":O,stream:s}; if(r!=null)ct["/Filter"]=Z(C);if(b){ct["/SMask"]={typ:"ref",ind:this._xr.length-1}}this._xr.push(ct); return P};function R(C){var O=0;while(O>");if(d){b(C,V($)+"\nstream\n");C.file.req(C.off,d.length); for(var A=0;Athis.size)this.size*=2;var b=new Uint8Array(this.size);for(var V=0;V<$;V++)b[V]=this.data[V]; this.data=b};return U}();function ToEMF(){this._file={file:new ToEMF.MFile,off:0};this._lstw=0;this._curx=0; this._curh=0;this._recs=0;this._lenp=0;this._objs={};this._tabl=1;this._stkf=0;this._tclr=0;this._curt={p:-1,b:-1,t:-1}; this._inited=!1}ToEMF.prototype.StartPage=function(U,v,W,H){this._check();var p=this._file,S=ToEMF.B.writeUint,Z=ToEMF.B.writeInt; this._curh=Math.max(this._curh,H*10);if(!this._inited){this._inited=!0;this._addRec("HEADER",88);ToEMF._writeHeadBox(p,[U,v,W,H]); p.off+=32;ToEMF.B.writeASCII(p.file,p.off," EMF");p.off+=4;S(p.file,p.off,65536);p.off+=4;this._lenp=p.off; p.off+=4+4+4;p.off+=4+4+4;Z(p.file,p.off,1440);p.off+=4;Z(p.file,p.off,900);p.off+=4;Z(p.file,p.off,508); p.off+=4;Z(p.file,p.off,318);p.off+=4;this._trsf([.1,0,0,.1,0,0]);this._addRec("SETBKMODE",12);S(p.file,p.off,1); p.off+=4;this._addRec("SETTEXTALIGN",12);S(p.file,p.off,24);p.off+=4}else{this._curx+=this._lstw;ToEMF._writeHeadBox(p,[0,0,this._curx+W,Math.round(this._curh/10)])}this._lstw=W}; ToEMF.prototype.Stroke=function(U){this._draw(U,1)};ToEMF.prototype.Fill=function(U,v){this._draw(U,2)}; ToEMF.prototype.PutImage=function(U,v,W,H,p){var M=v.length;if((M&3)!=0)M+=4-(M&3);var S=[1,0,0,-1,0,1]; UDOC.M.concat(S,U.ctm);UDOC.M.scale(S,10,10);UDOC.M.scale(S,1,-1);UDOC.M.translate(S,this._curx,this._curh); this._trsf(S);var a=this._file,Y=ToEMF.B.writeUint,I=ToEMF.B.writeInt,R=ToEMF.B.writeUshort,q=8+16+14*4; this._addRec("STRETCHDIBITS",q+40+M);a.off+=16;I(a.file,a.off,Math.round(0));a.off+=4;I(a.file,a.off,Math.round(0)); a.off+=4;a.off+=8;I(a.file,a.off,W);a.off+=4;I(a.file,a.off,H);a.off+=4;Y(a.file,a.off,q);a.off+=4;Y(a.file,a.off,40); a.off+=4;Y(a.file,a.off,q+40);a.off+=4;Y(a.file,a.off,v.length);a.off+=4;a.off+=4;Y(a.file,a.off,13369376); a.off+=4;I(a.file,a.off,Math.round(1));a.off+=4;I(a.file,a.off,Math.round(1));a.off+=4;I(a.file,a.off,40); a.off+=4;I(a.file,a.off,W);a.off+=4;I(a.file,a.off,H);a.off+=4;R(a.file,a.off,1);a.off+=2;R(a.file,a.off,32); a.off+=2;I(a.file,a.off,0);a.off+=4;I(a.file,a.off,v.length);a.off+=4;I(a.file,a.off,3800);a.off+=4; I(a.file,a.off,3800);a.off+=4;a.off+=8;a.file.req(a.off,v.length);if(v.length==W*H*4){for(var g=0;g.05;if(q){g=U.ctm.slice(0); g[1]*=-1;g[2]*=-1;g[4]=R;g[5]=w;R=w=0;this._trsf(g)}var n=8+16+12+4*6+16;this._addRec("EXTTEXTOUTW",n+H*2); p.off+=16;S(p.file,p.off,2);p.off+=4;Y(p.file,p.off,31.25);p.off+=4;Y(p.file,p.off,31.25);p.off+=4;Z(p.file,p.off,Math.round(R)); p.off+=4;Z(p.file,p.off,Math.round(w));p.off+=4;S(p.file,p.off,v.length);p.off+=4;S(p.file,p.off,n); p.off+=4;S(p.file,p.off,0);p.off+=4;p.off+=16;S(p.file,p.off,0);p.off+=4;for(var _=0;_1; if(O){g*=C;if(w=="L")n="POLYLINETO";_=8+20+4*g}this._addRec(n,_);if(O){W.off+=16;H(W.file,W.off,C*q[1]); W.off+=4;R+=C-1}for(var $=0;$this.size)this.size*=2; var H=new Uint8Array(this.size);for(var p=0;p0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new f,this.strm.avail_out=0;var a=o.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==b)throw new Error(d[a]);if(e.header&&o.deflateSetHeader(this.strm,e.header),e.dictionary){var n;if(n="string"==typeof e.dictionary?h.string2buf(e.dictionary):"[object ArrayBuffer]"===_.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,a=o.deflateSetDictionary(this.strm,n),a!==b)throw new Error(d[a]);this._dict_set=!0}}function n(t,e){var a=new i(e);if(a.push(t,!0),a.err)throw a.msg||d[a.err];return a.result}function r(t,e){return e=e||{},e.raw=!0,n(t,e)}function s(t,e){return e=e||{},e.gzip=!0,n(t,e)}var o=t("./zlib/deflate"),l=t("./utils/common"),h=t("./utils/strings"),d=t("./zlib/messages"),f=t("./zlib/zstream"),_=Object.prototype.toString,u=0,c=4,b=0,g=1,m=2,w=-1,p=0,v=8;i.prototype.push=function(t,e){var a,i,n=this.strm,r=this.options.chunkSize;if(this.ended)return!1;i=e===~~e?e:e===!0?c:u,"string"==typeof t?n.input=h.string2buf(t):"[object ArrayBuffer]"===_.call(t)?n.input=new Uint8Array(t):n.input=t,n.next_in=0,n.avail_in=n.input.length;do{if(0===n.avail_out&&(n.output=new l.Buf8(r),n.next_out=0,n.avail_out=r),a=o.deflate(n,i),a!==g&&a!==b)return this.onEnd(a),this.ended=!0,!1;0!==n.avail_out&&(0!==n.avail_in||i!==c&&i!==m)||("string"===this.options.to?this.onData(h.buf2binstring(l.shrinkBuf(n.output,n.next_out))):this.onData(l.shrinkBuf(n.output,n.next_out)))}while((n.avail_in>0||0===n.avail_out)&&a!==g);return i===c?(a=o.deflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===b):i!==m||(this.onEnd(b),n.avail_out=0,!0)},i.prototype.onData=function(t){this.chunks.push(t)},i.prototype.onEnd=function(t){t===b&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=l.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},a.Deflate=i,a.deflate=n,a.deflateRaw=r,a.gzip=s},{"./utils/common":3,"./utils/strings":4,"./zlib/deflate":8,"./zlib/messages":13,"./zlib/zstream":15}],2:[function(t,e,a){"use strict";function i(t){if(!(this instanceof i))return new i(t);this.options=o.assign({chunkSize:16384,windowBits:0,to:""},t||{});var e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0===(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new f,this.strm.avail_out=0;var a=s.inflateInit2(this.strm,e.windowBits);if(a!==h.Z_OK)throw new Error(d[a]);this.header=new _,s.inflateGetHeader(this.strm,this.header)}function n(t,e){var a=new i(e);if(a.push(t,!0),a.err)throw a.msg||d[a.err];return a.result}function r(t,e){return e=e||{},e.raw=!0,n(t,e)}var s=t("./zlib/inflate"),o=t("./utils/common"),l=t("./utils/strings"),h=t("./zlib/constants"),d=t("./zlib/messages"),f=t("./zlib/zstream"),_=t("./zlib/gzheader"),u=Object.prototype.toString;i.prototype.push=function(t,e){var a,i,n,r,d,f,_=this.strm,c=this.options.chunkSize,b=this.options.dictionary,g=!1;if(this.ended)return!1;i=e===~~e?e:e===!0?h.Z_FINISH:h.Z_NO_FLUSH,"string"==typeof t?_.input=l.binstring2buf(t):"[object ArrayBuffer]"===u.call(t)?_.input=new Uint8Array(t):_.input=t,_.next_in=0,_.avail_in=_.input.length;do{if(0===_.avail_out&&(_.output=new o.Buf8(c),_.next_out=0,_.avail_out=c),a=s.inflate(_,h.Z_NO_FLUSH),a===h.Z_NEED_DICT&&b&&(f="string"==typeof b?l.string2buf(b):"[object ArrayBuffer]"===u.call(b)?new Uint8Array(b):b,a=s.inflateSetDictionary(this.strm,f)),a===h.Z_BUF_ERROR&&g===!0&&(a=h.Z_OK,g=!1),a!==h.Z_STREAM_END&&a!==h.Z_OK)return this.onEnd(a),this.ended=!0,!1;_.next_out&&(0!==_.avail_out&&a!==h.Z_STREAM_END&&(0!==_.avail_in||i!==h.Z_FINISH&&i!==h.Z_SYNC_FLUSH)||("string"===this.options.to?(n=l.utf8border(_.output,_.next_out),r=_.next_out-n,d=l.buf2string(_.output,n),_.next_out=r,_.avail_out=c-r,r&&o.arraySet(_.output,_.output,n,r,0),this.onData(d)):this.onData(o.shrinkBuf(_.output,_.next_out)))),0===_.avail_in&&0===_.avail_out&&(g=!0)}while((_.avail_in>0||0===_.avail_out)&&a!==h.Z_STREAM_END);return a===h.Z_STREAM_END&&(i=h.Z_FINISH),i===h.Z_FINISH?(a=s.inflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===h.Z_OK):i!==h.Z_SYNC_FLUSH||(this.onEnd(h.Z_OK),_.avail_out=0,!0)},i.prototype.onData=function(t){this.chunks.push(t)},i.prototype.onEnd=function(t){t===h.Z_OK&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},a.Inflate=i,a.inflate=n,a.inflateRaw=r,a.ungzip=n},{"./utils/common":3,"./utils/strings":4,"./zlib/constants":6,"./zlib/gzheader":9,"./zlib/inflate":11,"./zlib/messages":13,"./zlib/zstream":15}],3:[function(t,e,a){"use strict";var i="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;a.assign=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var a=e.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(var i in a)a.hasOwnProperty(i)&&(t[i]=a[i])}}return t},a.shrinkBuf=function(t,e){return t.length===e?t:t.subarray?t.subarray(0,e):(t.length=e,t)};var n={arraySet:function(t,e,a,i,n){if(e.subarray&&t.subarray)return void t.set(e.subarray(a,a+i),n);for(var r=0;r=252?6:l>=248?5:l>=240?4:l>=224?3:l>=192?2:1;o[254]=o[254]=1,a.string2buf=function(t){var e,a,i,r,s,o=t.length,l=0;for(r=0;r>>6,e[s++]=128|63&a):a<65536?(e[s++]=224|a>>>12,e[s++]=128|a>>>6&63,e[s++]=128|63&a):(e[s++]=240|a>>>18,e[s++]=128|a>>>12&63,e[s++]=128|a>>>6&63,e[s++]=128|63&a);return e},a.buf2binstring=function(t){return i(t,t.length)},a.binstring2buf=function(t){for(var e=new n.Buf8(t.length),a=0,i=e.length;a4)h[n++]=65533,a+=s-1;else{for(r&=2===s?31:3===s?15:7;s>1&&a1?h[n++]=65533:r<65536?h[n++]=r:(r-=65536,h[n++]=55296|r>>10&1023,h[n++]=56320|1023&r)}return i(h,n)},a.utf8border=function(t,e){var a;for(e=e||t.length,e>t.length&&(e=t.length),a=e-1;a>=0&&128===(192&t[a]);)a--;return a<0?e:0===a?e:a+o[t[a]]>e?a:e}},{"./common":3}],5:[function(t,e,a){"use strict";function i(t,e,a,i){for(var n=65535&t|0,r=t>>>16&65535|0,s=0;0!==a;){s=a>2e3?2e3:a,a-=s;do n=n+e[i++]|0,r=r+n|0;while(--s);n%=65521,r%=65521}return n|r<<16|0}e.exports=i},{}],6:[function(t,e,a){"use strict";e.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],7:[function(t,e,a){"use strict";function i(){for(var t,e=[],a=0;a<256;a++){t=a;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e}function n(t,e,a,i){var n=r,s=i+a;t^=-1;for(var o=i;o>>8^n[255&(t^e[o])];return t^-1}var r=i();e.exports=n},{}],8:[function(t,e,a){"use strict";function i(t,e){return t.msg=D[e],e}function n(t){return(t<<1)-(t>4?9:0)}function r(t){for(var e=t.length;--e>=0;)t[e]=0}function s(t){var e=t.state,a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(R.arraySet(t.output,e.pending_buf,e.pending_out,a,t.next_out),t.next_out+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))}function o(t,e){C._tr_flush_block(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,s(t.strm)}function l(t,e){t.pending_buf[t.pending++]=e}function h(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e}function d(t,e,a,i){var n=t.avail_in;return n>i&&(n=i),0===n?0:(t.avail_in-=n,R.arraySet(e,t.input,t.next_in,n,a),1===t.state.wrap?t.adler=N(t.adler,e,n,a):2===t.state.wrap&&(t.adler=O(t.adler,e,n,a)),t.next_in+=n,t.total_in+=n,n)}function f(t,e){var a,i,n=t.max_chain_length,r=t.strstart,s=t.prev_length,o=t.nice_match,l=t.strstart>t.w_size-ft?t.strstart-(t.w_size-ft):0,h=t.window,d=t.w_mask,f=t.prev,_=t.strstart+dt,u=h[r+s-1],c=h[r+s];t.prev_length>=t.good_match&&(n>>=2),o>t.lookahead&&(o=t.lookahead);do if(a=e,h[a+s]===c&&h[a+s-1]===u&&h[a]===h[r]&&h[++a]===h[r+1]){r+=2,a++;do;while(h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&r<_);if(i=dt-(_-r),r=_-dt,i>s){if(t.match_start=e,s=i,i>=o)break;u=h[r+s-1],c=h[r+s]}}while((e=f[e&d])>l&&0!==--n);return s<=t.lookahead?s:t.lookahead}function _(t){var e,a,i,n,r,s=t.w_size;do{if(n=t.window_size-t.lookahead-t.strstart,t.strstart>=s+(s-ft)){R.arraySet(t.window,t.window,s,s,0),t.match_start-=s,t.strstart-=s,t.block_start-=s,a=t.hash_size,e=a;do i=t.head[--e],t.head[e]=i>=s?i-s:0;while(--a);a=s,e=a;do i=t.prev[--e],t.prev[e]=i>=s?i-s:0;while(--a);n+=s}if(0===t.strm.avail_in)break;if(a=d(t.strm,t.window,t.strstart+t.lookahead,n),t.lookahead+=a,t.lookahead+t.insert>=ht)for(r=t.strstart-t.insert,t.ins_h=t.window[r],t.ins_h=(t.ins_h<t.pending_buf_size-5&&(a=t.pending_buf_size-5);;){if(t.lookahead<=1){if(_(t),0===t.lookahead&&e===I)return vt;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var i=t.block_start+a;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,o(t,!1),0===t.strm.avail_out))return vt;if(t.strstart-t.block_start>=t.w_size-ft&&(o(t,!1),0===t.strm.avail_out))return vt}return t.insert=0,e===F?(o(t,!0),0===t.strm.avail_out?yt:xt):t.strstart>t.block_start&&(o(t,!1),0===t.strm.avail_out)?vt:vt}function c(t,e){for(var a,i;;){if(t.lookahead=ht&&(t.ins_h=(t.ins_h<=ht)if(i=C._tr_tally(t,t.strstart-t.match_start,t.match_length-ht),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=ht){t.match_length--;do t.strstart++,t.ins_h=(t.ins_h<=ht&&(t.ins_h=(t.ins_h<4096)&&(t.match_length=ht-1)),t.prev_length>=ht&&t.match_length<=t.prev_length){n=t.strstart+t.lookahead-ht,i=C._tr_tally(t,t.strstart-1-t.prev_match,t.prev_length-ht),t.lookahead-=t.prev_length-1,t.prev_length-=2;do++t.strstart<=n&&(t.ins_h=(t.ins_h<=ht&&t.strstart>0&&(n=t.strstart-1,i=s[n],i===s[++n]&&i===s[++n]&&i===s[++n])){r=t.strstart+dt;do;while(i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&i===s[++n]&&nt.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=ht?(a=C._tr_tally(t,1,t.match_length-ht),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=C._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(o(t,!1),0===t.strm.avail_out))return vt}return t.insert=0,e===F?(o(t,!0),0===t.strm.avail_out?yt:xt):t.last_lit&&(o(t,!1),0===t.strm.avail_out)?vt:kt}function m(t,e){for(var a;;){if(0===t.lookahead&&(_(t),0===t.lookahead)){if(e===I)return vt;break}if(t.match_length=0,a=C._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(o(t,!1),0===t.strm.avail_out))return vt}return t.insert=0,e===F?(o(t,!0),0===t.strm.avail_out?yt:xt):t.last_lit&&(o(t,!1),0===t.strm.avail_out)?vt:kt}function w(t,e,a,i,n){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=i,this.func=n}function p(t){t.window_size=2*t.w_size,r(t.head),t.max_lazy_match=Z[t.level].max_lazy,t.good_match=Z[t.level].good_length,t.nice_match=Z[t.level].nice_length,t.max_chain_length=Z[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=ht-1,t.match_available=0,t.ins_h=0}function v(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=V,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new R.Buf16(2*ot),this.dyn_dtree=new R.Buf16(2*(2*rt+1)),this.bl_tree=new R.Buf16(2*(2*st+1)),r(this.dyn_ltree),r(this.dyn_dtree),r(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new R.Buf16(lt+1),this.heap=new R.Buf16(2*nt+1),r(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new R.Buf16(2*nt+1),r(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function k(t){var e;return t&&t.state?(t.total_in=t.total_out=0,t.data_type=Q,e=t.state,e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?ut:wt,t.adler=2===e.wrap?0:1,e.last_flush=I,C._tr_init(e),H):i(t,K)}function y(t){var e=k(t);return e===H&&p(t.state),e}function x(t,e){return t&&t.state?2!==t.state.wrap?K:(t.state.gzhead=e,H):K}function z(t,e,a,n,r,s){if(!t)return K;var o=1;if(e===Y&&(e=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),r<1||r>$||a!==V||n<8||n>15||e<0||e>9||s<0||s>W)return i(t,K);8===n&&(n=9);var l=new v;return t.state=l,l.strm=t,l.wrap=o,l.gzhead=null,l.w_bits=n,l.w_size=1<L||e<0)return t?i(t,K):K;if(o=t.state,!t.output||!t.input&&0!==t.avail_in||o.status===pt&&e!==F)return i(t,0===t.avail_out?P:K);if(o.strm=t,a=o.last_flush,o.last_flush=e,o.status===ut)if(2===o.wrap)t.adler=0,l(o,31),l(o,139),l(o,8),o.gzhead?(l(o,(o.gzhead.text?1:0)+(o.gzhead.hcrc?2:0)+(o.gzhead.extra?4:0)+(o.gzhead.name?8:0)+(o.gzhead.comment?16:0)),l(o,255&o.gzhead.time),l(o,o.gzhead.time>>8&255),l(o,o.gzhead.time>>16&255),l(o,o.gzhead.time>>24&255),l(o,9===o.level?2:o.strategy>=G||o.level<2?4:0),l(o,255&o.gzhead.os),o.gzhead.extra&&o.gzhead.extra.length&&(l(o,255&o.gzhead.extra.length),l(o,o.gzhead.extra.length>>8&255)),o.gzhead.hcrc&&(t.adler=O(t.adler,o.pending_buf,o.pending,0)),o.gzindex=0,o.status=ct):(l(o,0),l(o,0),l(o,0),l(o,0),l(o,0),l(o,9===o.level?2:o.strategy>=G||o.level<2?4:0),l(o,zt),o.status=wt);else{var _=V+(o.w_bits-8<<4)<<8,u=-1;u=o.strategy>=G||o.level<2?0:o.level<6?1:6===o.level?2:3,_|=u<<6,0!==o.strstart&&(_|=_t),_+=31-_%31,o.status=wt,h(o,_),0!==o.strstart&&(h(o,t.adler>>>16),h(o,65535&t.adler)),t.adler=1}if(o.status===ct)if(o.gzhead.extra){for(d=o.pending;o.gzindex<(65535&o.gzhead.extra.length)&&(o.pending!==o.pending_buf_size||(o.gzhead.hcrc&&o.pending>d&&(t.adler=O(t.adler,o.pending_buf,o.pending-d,d)),s(t),d=o.pending,o.pending!==o.pending_buf_size));)l(o,255&o.gzhead.extra[o.gzindex]),o.gzindex++;o.gzhead.hcrc&&o.pending>d&&(t.adler=O(t.adler,o.pending_buf,o.pending-d,d)),o.gzindex===o.gzhead.extra.length&&(o.gzindex=0,o.status=bt)}else o.status=bt;if(o.status===bt)if(o.gzhead.name){d=o.pending;do{if(o.pending===o.pending_buf_size&&(o.gzhead.hcrc&&o.pending>d&&(t.adler=O(t.adler,o.pending_buf,o.pending-d,d)),s(t),d=o.pending,o.pending===o.pending_buf_size)){f=1;break}f=o.gzindexd&&(t.adler=O(t.adler,o.pending_buf,o.pending-d,d)),0===f&&(o.gzindex=0,o.status=gt)}else o.status=gt;if(o.status===gt)if(o.gzhead.comment){d=o.pending;do{if(o.pending===o.pending_buf_size&&(o.gzhead.hcrc&&o.pending>d&&(t.adler=O(t.adler,o.pending_buf,o.pending-d,d)),s(t),d=o.pending,o.pending===o.pending_buf_size)){f=1;break}f=o.gzindexd&&(t.adler=O(t.adler,o.pending_buf,o.pending-d,d)),0===f&&(o.status=mt)}else o.status=mt;if(o.status===mt&&(o.gzhead.hcrc?(o.pending+2>o.pending_buf_size&&s(t),o.pending+2<=o.pending_buf_size&&(l(o,255&t.adler),l(o,t.adler>>8&255),t.adler=0,o.status=wt)):o.status=wt),0!==o.pending){if(s(t),0===t.avail_out)return o.last_flush=-1,H}else if(0===t.avail_in&&n(e)<=n(a)&&e!==F)return i(t,P);if(o.status===pt&&0!==t.avail_in)return i(t,P);if(0!==t.avail_in||0!==o.lookahead||e!==I&&o.status!==pt){var c=o.strategy===G?m(o,e):o.strategy===X?g(o,e):Z[o.level].func(o,e);if(c!==yt&&c!==xt||(o.status=pt),c===vt||c===yt)return 0===t.avail_out&&(o.last_flush=-1),H;if(c===kt&&(e===U?C._tr_align(o):e!==L&&(C._tr_stored_block(o,0,0,!1),e===T&&(r(o.head),0===o.lookahead&&(o.strstart=0,o.block_start=0,o.insert=0))),s(t),0===t.avail_out))return o.last_flush=-1,H}return e!==F?H:o.wrap<=0?j:(2===o.wrap?(l(o,255&t.adler),l(o,t.adler>>8&255),l(o,t.adler>>16&255),l(o,t.adler>>24&255),l(o,255&t.total_in),l(o,t.total_in>>8&255),l(o,t.total_in>>16&255),l(o,t.total_in>>24&255)):(h(o,t.adler>>>16),h(o,65535&t.adler)),s(t),o.wrap>0&&(o.wrap=-o.wrap),0!==o.pending?H:j)}function E(t){var e;return t&&t.state?(e=t.state.status,e!==ut&&e!==ct&&e!==bt&&e!==gt&&e!==mt&&e!==wt&&e!==pt?i(t,K):(t.state=null,e===wt?i(t,M):H)):K}function A(t,e){var a,i,n,s,o,l,h,d,f=e.length;if(!t||!t.state)return K;if(a=t.state,s=a.wrap,2===s||1===s&&a.status!==ut||a.lookahead)return K;for(1===s&&(t.adler=N(t.adler,e,f,0)),a.wrap=0,f>=a.w_size&&(0===s&&(r(a.head),a.strstart=0,a.block_start=0,a.insert=0),d=new R.Buf8(a.w_size),R.arraySet(d,e,f-a.w_size,a.w_size,0),e=d,f=a.w_size),o=t.avail_in,l=t.next_in,h=t.input,t.avail_in=f,t.next_in=0,t.input=e,_(a);a.lookahead>=ht;){i=a.strstart,n=a.lookahead-(ht-1);do a.ins_h=(a.ins_h<>>24,b>>>=y,g-=y,y=k>>>16&255,0===y)A[o++]=65535&k;else{if(!(16&y)){if(0===(64&y)){k=m[(65535&k)+(b&(1<>>=y,g-=y),g<15&&(b+=E[r++]<>>24,b>>>=y,g-=y,y=k>>>16&255,!(16&y)){if(0===(64&y)){k=w[(65535&k)+(b&(1<d){t.msg="invalid distance too far back",a.mode=i;break t}if(b>>>=y,g-=y,y=o-l,z>y){if(y=z-y,y>_&&a.sane){t.msg="invalid distance too far back",a.mode=i;break t}if(B=0,S=c,0===u){if(B+=f-y,y2;)A[o++]=S[B++],A[o++]=S[B++],A[o++]=S[B++],x-=3;x&&(A[o++]=S[B++],x>1&&(A[o++]=S[B++]))}else{B=o-z;do A[o++]=A[B++],A[o++]=A[B++],A[o++]=A[B++],x-=3;while(x>2);x&&(A[o++]=A[B++],x>1&&(A[o++]=A[B++]))}break}}break}}while(r>3,r-=x,g-=x<<3,b&=(1<>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)}function n(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new w.Buf16(320),this.work=new w.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function r(t){var e;return t&&t.state?(e=t.state,t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=T,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new w.Buf32(bt),e.distcode=e.distdyn=new w.Buf32(gt),e.sane=1,e.back=-1,Z):N}function s(t){var e;return t&&t.state?(e=t.state,e.wsize=0,e.whave=0,e.wnext=0,r(t)):N}function o(t,e){var a,i;return t&&t.state?(i=t.state,e<0?(a=0,e=-e):(a=(e>>4)+1,e<48&&(e&=15)),e&&(e<8||e>15)?N:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=a,i.wbits=e,s(t))):N}function l(t,e){var a,i;return t?(i=new n,t.state=i,i.window=null,a=o(t,e),a!==Z&&(t.state=null),a):N}function h(t){return l(t,wt)}function d(t){if(pt){var e;for(g=new w.Buf32(512),m=new w.Buf32(32),e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(y(z,t.lens,0,288,g,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;y(B,t.lens,0,32,m,0,t.work,{bits:5}),pt=!1}t.lencode=g,t.lenbits=9,t.distcode=m,t.distbits=5}function f(t,e,a,i){var n,r=t.state;return null===r.window&&(r.wsize=1<=r.wsize?(w.arraySet(r.window,e,a-r.wsize,r.wsize,0),r.wnext=0,r.whave=r.wsize):(n=r.wsize-r.wnext,n>i&&(n=i),w.arraySet(r.window,e,a-i,n,r.wnext),i-=n,i?(w.arraySet(r.window,e,a-i,i,0),r.wnext=i,r.whave=r.wsize):(r.wnext+=n,r.wnext===r.wsize&&(r.wnext=0),r.whave>>8&255,a.check=v(a.check,Et,2,0),_=0,u=0,a.mode=F;break}if(a.flags=0,a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&_)<<8)+(_>>8))%31){t.msg="incorrect header check",a.mode=_t;break}if((15&_)!==U){t.msg="unknown compression method",a.mode=_t;break}if(_>>>=4,u-=4,yt=(15&_)+8,0===a.wbits)a.wbits=yt;else if(yt>a.wbits){t.msg="invalid window size",a.mode=_t;break}a.dmax=1<>8&1),512&a.flags&&(Et[0]=255&_,Et[1]=_>>>8&255,a.check=v(a.check,Et,2,0)),_=0,u=0,a.mode=L;case L:for(;u<32;){if(0===l)break t;l--,_+=n[s++]<>>8&255,Et[2]=_>>>16&255,Et[3]=_>>>24&255,a.check=v(a.check,Et,4,0)),_=0,u=0,a.mode=H;case H:for(;u<16;){if(0===l)break t;l--,_+=n[s++]<>8),512&a.flags&&(Et[0]=255&_,Et[1]=_>>>8&255,a.check=v(a.check,Et,2,0)),_=0,u=0,a.mode=j;case j:if(1024&a.flags){for(;u<16;){if(0===l)break t;l--,_+=n[s++]<>>8&255,a.check=v(a.check,Et,2,0)),_=0,u=0}else a.head&&(a.head.extra=null);a.mode=K;case K:if(1024&a.flags&&(g=a.length,g>l&&(g=l),g&&(a.head&&(yt=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Array(a.head.extra_len)),w.arraySet(a.head.extra,n,s,g,yt)),512&a.flags&&(a.check=v(a.check,n,g,s)),l-=g,s+=g,a.length-=g),a.length))break t;a.length=0,a.mode=M;case M:if(2048&a.flags){if(0===l)break t;g=0;do yt=n[s+g++],a.head&&yt&&a.length<65536&&(a.head.name+=String.fromCharCode(yt));while(yt&&g>9&1,a.head.done=!0),t.adler=a.check=0,a.mode=X;break;case q:for(;u<32;){if(0===l)break t;l--,_+=n[s++]<>>=7&u,u-=7&u,a.mode=ht;break}for(;u<3;){if(0===l)break t;l--,_+=n[s++]<>>=1,u-=1,3&_){case 0:a.mode=J;break;case 1:if(d(a),a.mode=at,e===A){_>>>=2,u-=2;break t}break;case 2:a.mode=$;break;case 3:t.msg="invalid block type",a.mode=_t}_>>>=2,u-=2;break;case J:for(_>>>=7&u,u-=7&u;u<32;){if(0===l)break t;l--,_+=n[s++]<>>16^65535)){t.msg="invalid stored block lengths",a.mode=_t;break}if(a.length=65535&_,_=0,u=0,a.mode=Q,e===A)break t;case Q:a.mode=V;case V:if(g=a.length){if(g>l&&(g=l),g>h&&(g=h),0===g)break t;w.arraySet(r,n,s,g,o),l-=g,s+=g,h-=g,o+=g,a.length-=g;break}a.mode=X;break;case $: for(;u<14;){if(0===l)break t;l--,_+=n[s++]<>>=5,u-=5,a.ndist=(31&_)+1,_>>>=5,u-=5,a.ncode=(15&_)+4,_>>>=4,u-=4,a.nlen>286||a.ndist>30){t.msg="too many length or distance symbols",a.mode=_t;break}a.have=0,a.mode=tt;case tt:for(;a.have>>=3,u-=3}for(;a.have<19;)a.lens[At[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,zt={bits:a.lenbits},xt=y(x,a.lens,0,19,a.lencode,0,a.work,zt),a.lenbits=zt.bits,xt){t.msg="invalid code lengths set",a.mode=_t;break}a.have=0,a.mode=et;case et:for(;a.have>>24,mt=St>>>16&255,wt=65535&St,!(gt<=u);){if(0===l)break t;l--,_+=n[s++]<>>=gt,u-=gt,a.lens[a.have++]=wt;else{if(16===wt){for(Bt=gt+2;u>>=gt,u-=gt,0===a.have){t.msg="invalid bit length repeat",a.mode=_t;break}yt=a.lens[a.have-1],g=3+(3&_),_>>>=2,u-=2}else if(17===wt){for(Bt=gt+3;u>>=gt,u-=gt,yt=0,g=3+(7&_),_>>>=3,u-=3}else{for(Bt=gt+7;u>>=gt,u-=gt,yt=0,g=11+(127&_),_>>>=7,u-=7}if(a.have+g>a.nlen+a.ndist){t.msg="invalid bit length repeat",a.mode=_t;break}for(;g--;)a.lens[a.have++]=yt}}if(a.mode===_t)break;if(0===a.lens[256]){t.msg="invalid code -- missing end-of-block",a.mode=_t;break}if(a.lenbits=9,zt={bits:a.lenbits},xt=y(z,a.lens,0,a.nlen,a.lencode,0,a.work,zt),a.lenbits=zt.bits,xt){t.msg="invalid literal/lengths set",a.mode=_t;break}if(a.distbits=6,a.distcode=a.distdyn,zt={bits:a.distbits},xt=y(B,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,zt),a.distbits=zt.bits,xt){t.msg="invalid distances set",a.mode=_t;break}if(a.mode=at,e===A)break t;case at:a.mode=it;case it:if(l>=6&&h>=258){t.next_out=o,t.avail_out=h,t.next_in=s,t.avail_in=l,a.hold=_,a.bits=u,k(t,b),o=t.next_out,r=t.output,h=t.avail_out,s=t.next_in,n=t.input,l=t.avail_in,_=a.hold,u=a.bits,a.mode===X&&(a.back=-1);break}for(a.back=0;St=a.lencode[_&(1<>>24,mt=St>>>16&255,wt=65535&St,!(gt<=u);){if(0===l)break t;l--,_+=n[s++]<>pt)],gt=St>>>24,mt=St>>>16&255,wt=65535&St,!(pt+gt<=u);){if(0===l)break t;l--,_+=n[s++]<>>=pt,u-=pt,a.back+=pt}if(_>>>=gt,u-=gt,a.back+=gt,a.length=wt,0===mt){a.mode=lt;break}if(32&mt){a.back=-1,a.mode=X;break}if(64&mt){t.msg="invalid literal/length code",a.mode=_t;break}a.extra=15&mt,a.mode=nt;case nt:if(a.extra){for(Bt=a.extra;u>>=a.extra,u-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=rt;case rt:for(;St=a.distcode[_&(1<>>24,mt=St>>>16&255,wt=65535&St,!(gt<=u);){if(0===l)break t;l--,_+=n[s++]<>pt)],gt=St>>>24,mt=St>>>16&255,wt=65535&St,!(pt+gt<=u);){if(0===l)break t;l--,_+=n[s++]<>>=pt,u-=pt,a.back+=pt}if(_>>>=gt,u-=gt,a.back+=gt,64&mt){t.msg="invalid distance code",a.mode=_t;break}a.offset=wt,a.extra=15&mt,a.mode=st;case st:if(a.extra){for(Bt=a.extra;u>>=a.extra,u-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){t.msg="invalid distance too far back",a.mode=_t;break}a.mode=ot;case ot:if(0===h)break t;if(g=b-h,a.offset>g){if(g=a.offset-g,g>a.whave&&a.sane){t.msg="invalid distance too far back",a.mode=_t;break}g>a.wnext?(g-=a.wnext,m=a.wsize-g):m=a.wnext-g,g>a.length&&(g=a.length),bt=a.window}else bt=r,m=o-a.offset,g=a.length;g>h&&(g=h),h-=g,a.length-=g;do r[o++]=bt[m++];while(--g);0===a.length&&(a.mode=it);break;case lt:if(0===h)break t;r[o++]=a.length,h--,a.mode=it;break;case ht:if(a.wrap){for(;u<32;){if(0===l)break t;l--,_|=n[s++]<=1&&0===j[N];N--);if(O>N&&(O=N),0===N)return b[g++]=20971520,b[g++]=20971520,w.bits=1,0;for(C=1;C0&&(t===o||1!==N))return-1;for(K[1]=0,Z=1;Zr||t===h&&T>s)return 1;for(;;){B=Z-I,m[R]z?(S=M[P+m[R]],E=L[H+m[R]]):(S=96,E=0),p=1<>I)+v]=B<<24|S<<16|E|0;while(0!==v);for(p=1<>=1;if(0!==p?(F&=p-1,F+=p):F=0,R++,0===--j[Z]){if(Z===N)break;Z=e[a+m[R]]}if(Z>O&&(F&y)!==k){for(0===I&&(I=O),x+=C,D=Z-I,U=1<r||t===h&&T>s)return 1;k=F&y,b[k]=O<<24|D<<16|x-g|0}}return 0!==F&&(b[x+F]=Z-I<<24|64<<16|0),w.bits=O,0}},{"../utils/common":3}],13:[function(t,e,a){"use strict";e.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],14:[function(t,e,a){"use strict";function i(t){for(var e=t.length;--e>=0;)t[e]=0}function n(t,e,a,i,n){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=i,this.max_length=n,this.has_stree=t&&t.length}function r(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}function s(t){return t<256?lt[t]:lt[256+(t>>>7)]}function o(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255}function l(t,e,a){t.bi_valid>W-a?(t.bi_buf|=e<>W-t.bi_valid,t.bi_valid+=a-W):(t.bi_buf|=e<>>=1,a<<=1;while(--e>0);return a>>>1}function f(t){16===t.bi_valid?(o(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}function _(t,e){var a,i,n,r,s,o,l=e.dyn_tree,h=e.max_code,d=e.stat_desc.static_tree,f=e.stat_desc.has_stree,_=e.stat_desc.extra_bits,u=e.stat_desc.extra_base,c=e.stat_desc.max_length,b=0;for(r=0;r<=X;r++)t.bl_count[r]=0;for(l[2*t.heap[t.heap_max]+1]=0,a=t.heap_max+1;ac&&(r=c,b++),l[2*i+1]=r,i>h||(t.bl_count[r]++,s=0,i>=u&&(s=_[i-u]),o=l[2*i],t.opt_len+=o*(r+s),f&&(t.static_len+=o*(d[2*i+1]+s)));if(0!==b){do{for(r=c-1;0===t.bl_count[r];)r--;t.bl_count[r]--,t.bl_count[r+1]+=2,t.bl_count[c]--,b-=2}while(b>0);for(r=c;0!==r;r--)for(i=t.bl_count[r];0!==i;)n=t.heap[--a],n>h||(l[2*n+1]!==r&&(t.opt_len+=(r-l[2*n+1])*l[2*n],l[2*n+1]=r),i--)}}function u(t,e,a){var i,n,r=new Array(X+1),s=0;for(i=1;i<=X;i++)r[i]=s=s+a[i-1]<<1;for(n=0;n<=e;n++){var o=t[2*n+1];0!==o&&(t[2*n]=d(r[o]++,o))}}function c(){var t,e,a,i,r,s=new Array(X+1);for(a=0,i=0;i>=7;i8?o(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function m(t,e,a,i){g(t),i&&(o(t,a),o(t,~a)),N.arraySet(t.pending_buf,t.window,e,a,t.pending),t.pending+=a}function w(t,e,a,i){var n=2*e,r=2*a;return t[n]>1;a>=1;a--)p(t,r,a);n=l;do a=t.heap[1],t.heap[1]=t.heap[t.heap_len--],p(t,r,1),i=t.heap[1],t.heap[--t.heap_max]=a,t.heap[--t.heap_max]=i,r[2*n]=r[2*a]+r[2*i],t.depth[n]=(t.depth[a]>=t.depth[i]?t.depth[a]:t.depth[i])+1,r[2*a+1]=r[2*i+1]=n,t.heap[1]=n++,p(t,r,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],_(t,e),u(r,h,t.bl_count)}function y(t,e,a){var i,n,r=-1,s=e[1],o=0,l=7,h=4;for(0===s&&(l=138,h=3),e[2*(a+1)+1]=65535,i=0;i<=a;i++)n=s,s=e[2*(i+1)+1],++o=3&&0===t.bl_tree[2*nt[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}function B(t,e,a,i){var n;for(l(t,e-257,5),l(t,a-1,5),l(t,i-4,4),n=0;n>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return D;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return I;for(e=32;e0?(t.strm.data_type===U&&(t.strm.data_type=S(t)),k(t,t.l_desc),k(t,t.d_desc),s=z(t),n=t.opt_len+3+7>>>3,r=t.static_len+3+7>>>3,r<=n&&(n=r)):n=r=a+5,a+4<=n&&e!==-1?A(t,e,a,i):t.strategy===O||r===n?(l(t,(F<<1)+(i?1:0),3),v(t,st,ot)):(l(t,(L<<1)+(i?1:0),3),B(t,t.l_desc.max_code+1,t.d_desc.max_code+1,s+1),v(t,t.dyn_ltree,t.dyn_dtree)),b(t),i&&g(t)}function C(t,e,a){return t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&a,t.last_lit++,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(ht[a]+M+1)]++,t.dyn_dtree[2*s(e)]++),t.last_lit===t.lit_bufsize-1}var N=t("../utils/common"),O=4,D=0,I=1,U=2,T=0,F=1,L=2,H=3,j=258,K=29,M=256,P=M+1+K,Y=30,q=19,G=2*P+1,X=15,W=16,J=7,Q=256,V=16,$=17,tt=18,et=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],at=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],it=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],nt=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],rt=512,st=new Array(2*(P+2));i(st);var ot=new Array(2*Y);i(ot);var lt=new Array(rt);i(lt);var ht=new Array(j-H+1);i(ht);var dt=new Array(K);i(dt);var ft=new Array(Y);i(ft);var _t,ut,ct,bt=!1;a._tr_init=E,a._tr_stored_block=A,a._tr_flush_block=R,a._tr_tally=C,a._tr_align=Z},{"../utils/common":3}],15:[function(t,e,a){"use strict";function i(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}e.exports=i},{}],"/":[function(t,e,a){"use strict";var i=t("./lib/utils/common").assign,n=t("./lib/deflate"),r=t("./lib/inflate"),s=t("./lib/zlib/constants"),o={};i(o,n,r,s),e.exports=o},{"./lib/deflate":1,"./lib/inflate":2,"./lib/utils/common":3,"./lib/zlib/constants":6}]},{},[])("/")}); /** * @license * Copyright 2015 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var PDFJS; (function(PDFJS) { "use strict"; var JpegError = (function JpegErrorClosure() { function JpegError(msg) { this.message = 'JPEG error: ' + msg; } JpegError.prototype = new Error(); JpegError.prototype.name = 'JpegError'; JpegError.constructor = JpegError; return JpegError; })(); var JpegImage = (function JpegImageClosure() { // prettier-ignore var dctZigZag = new Uint8Array([ 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 ]); var dctCos1 = 4017; // cos(pi/16) var dctSin1 = 799; // sin(pi/16) var dctCos3 = 3406; // cos(3*pi/16) var dctSin3 = 2276; // sin(3*pi/16) var dctCos6 = 1567; // cos(6*pi/16) var dctSin6 = 3784; // sin(6*pi/16) var dctSqrt2 = 5793; // sqrt(2) var dctSqrt1d2 = 2896; // sqrt(2) / 2 // eslint-disable-next-line no-shadow function JpegImage({ decodeTransform = null, colorTransform = -1 } = {}) { this._decodeTransform = decodeTransform; this._colorTransform = colorTransform; } function buildHuffmanTable(codeLengths, values) { var k = 0, code = [], i, j, length = 16; while (length > 0 && !codeLengths[length - 1]) { length--; } code.push({ children: [], index: 0 }); var p = code[0], q; for (i = 0; i < length; i++) { for (j = 0; j < codeLengths[i]; j++) { p = code.pop(); p.children[p.index] = values[k]; while (p.index > 0) { p = code.pop(); } p.index++; code.push(p); while (code.length <= i) { code.push((q = { children: [], index: 0 })); p.children[p.index] = q.children; p = q; } k++; } if (i + 1 < length) { // p here points to last code code.push((q = { children: [], index: 0 })); p.children[p.index] = q.children; p = q; } } return code[0].children; } function getBlockBufferOffset(component, row, col) { return 64 * ((component.blocksPerLine + 1) * row + col); } function decodeScan( data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive, parseDNLMarker = false ) { var mcusPerLine = frame.mcusPerLine; var progressive = frame.progressive; const startOffset = offset; let bitsData = 0, bitsCount = 0; function readBit() { if (bitsCount > 0) { bitsCount--; return (bitsData >> bitsCount) & 1; } bitsData = data[offset++]; if (bitsData === 0xff) { var nextByte = data[offset++]; if (nextByte) { if (nextByte === /* DNL = */ 0xdc && parseDNLMarker) { offset += 2; // Skip marker length. const scanLines = readUint16(data, offset); offset += 2; if (scanLines > 0 && scanLines !== frame.scanLines) { throw new DNLMarkerError( "Found DNL marker (0xFFDC) while parsing scan data", scanLines ); } } else if (nextByte === /* EOI = */ 0xd9) { if (parseDNLMarker) { // NOTE: only 8-bit JPEG images are supported in this decoder. const maybeScanLines = blockRow * 8; // Heuristic to attempt to handle corrupt JPEG images with too // large `scanLines` parameter, by falling back to the currently // parsed number of scanLines when it's at least one order of // magnitude smaller than expected (fixes issue10880.pdf). if (maybeScanLines > 0 && maybeScanLines < frame.scanLines / 10) { throw new DNLMarkerError( "Found EOI marker (0xFFD9) while parsing scan data, " + "possibly caused by incorrect `scanLines` parameter", maybeScanLines ); } } throw new EOIMarkerError( "Found EOI marker (0xFFD9) while parsing scan data" ); } throw new JpegError( `unexpected marker ${((bitsData << 8) | nextByte).toString(16)}` ); } // unstuff 0 } bitsCount = 7; return bitsData >>> 7; } function decodeHuffman(tree) { var node = tree; while (true) { node = node[readBit()]; switch (typeof node) { case "number": return node; case "object": continue; } throw new JpegError("invalid huffman sequence"); } } function receive(length) { var n = 0; while (length > 0) { n = (n << 1) | readBit(); length--; } return n; } function receiveAndExtend(length) { if (length === 1) { return readBit() === 1 ? 1 : -1; } var n = receive(length); if (n >= 1 << (length - 1)) { return n; } return n + (-1 << length) + 1; } function decodeBaseline(component, blockOffset) { var t = decodeHuffman(component.huffmanTableDC); var diff = t === 0 ? 0 : receiveAndExtend(t); component.blockData[blockOffset] = component.pred += diff; var k = 1; while (k < 64) { var rs = decodeHuffman(component.huffmanTableAC); var s = rs & 15, r = rs >> 4; if (s === 0) { if (r < 15) { break; } k += 16; continue; } k += r; var z = dctZigZag[k]; component.blockData[blockOffset + z] = receiveAndExtend(s); k++; } } function decodeDCFirst(component, blockOffset) { var t = decodeHuffman(component.huffmanTableDC); var diff = t === 0 ? 0 : receiveAndExtend(t) << successive; component.blockData[blockOffset] = component.pred += diff; } function decodeDCSuccessive(component, blockOffset) { component.blockData[blockOffset] |= readBit() << successive; } var eobrun = 0; function decodeACFirst(component, blockOffset) { if (eobrun > 0) { eobrun--; return; } var k = spectralStart, e = spectralEnd; while (k <= e) { var rs = decodeHuffman(component.huffmanTableAC); var s = rs & 15, r = rs >> 4; if (s === 0) { if (r < 15) { eobrun = receive(r) + (1 << r) - 1; break; } k += 16; continue; } k += r; var z = dctZigZag[k]; component.blockData[blockOffset + z] = receiveAndExtend(s) * (1 << successive); k++; } } var successiveACState = 0, successiveACNextValue; function decodeACSuccessive(component, blockOffset) { var k = spectralStart; var e = spectralEnd; var r = 0; var s; var rs; while (k <= e) { const offsetZ = blockOffset + dctZigZag[k]; const sign = component.blockData[offsetZ] < 0 ? -1 : 1; switch (successiveACState) { case 0: // initial state rs = decodeHuffman(component.huffmanTableAC); s = rs & 15; r = rs >> 4; if (s === 0) { if (r < 15) { eobrun = receive(r) + (1 << r); successiveACState = 4; } else { r = 16; successiveACState = 1; } } else { if (s !== 1) { throw new JpegError("invalid ACn encoding"); } successiveACNextValue = receiveAndExtend(s); successiveACState = r ? 2 : 3; } continue; case 1: // skipping r zero items case 2: if (component.blockData[offsetZ]) { component.blockData[offsetZ] += sign * (readBit() << successive); } else { r--; if (r === 0) { successiveACState = successiveACState === 2 ? 3 : 0; } } break; case 3: // set value for a zero item if (component.blockData[offsetZ]) { component.blockData[offsetZ] += sign * (readBit() << successive); } else { component.blockData[offsetZ] = successiveACNextValue << successive; successiveACState = 0; } break; case 4: // eob if (component.blockData[offsetZ]) { component.blockData[offsetZ] += sign * (readBit() << successive); } break; } k++; } if (successiveACState === 4) { eobrun--; if (eobrun === 0) { successiveACState = 0; } } } let blockRow = 0; function decodeMcu(component, decode, mcu, row, col) { var mcuRow = (mcu / mcusPerLine) | 0; var mcuCol = mcu % mcusPerLine; blockRow = mcuRow * component.v + row; var blockCol = mcuCol * component.h + col; const blockOffset = getBlockBufferOffset(component, blockRow, blockCol); decode(component, blockOffset); } function decodeBlock(component, decode, mcu) { blockRow = (mcu / component.blocksPerLine) | 0; var blockCol = mcu % component.blocksPerLine; const blockOffset = getBlockBufferOffset(component, blockRow, blockCol); decode(component, blockOffset); } var componentsLength = components.length; var component, i, j, k, n; var decodeFn; if (progressive) { if (spectralStart === 0) { decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive; } else { decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive; } } else { decodeFn = decodeBaseline; } var mcu = 0, fileMarker; var mcuExpected; if (componentsLength === 1) { mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn; } else { mcuExpected = mcusPerLine * frame.mcusPerColumn; } var h, v; while (mcu <= mcuExpected) { // reset interval stuff var mcuToRead = resetInterval ? Math.min(mcuExpected - mcu, resetInterval) : mcuExpected; // The `mcuToRead === 0` case should only occur when all of the expected // MCU data has been already parsed, i.e. when `mcu === mcuExpected`, but // some corrupt JPEG images contain more data than intended and we thus // want to skip over any extra RSTx markers below (fixes issue11794.pdf). if (mcuToRead > 0) { for (i = 0; i < componentsLength; i++) { components[i].pred = 0; } eobrun = 0; if (componentsLength === 1) { component = components[0]; for (n = 0; n < mcuToRead; n++) { decodeBlock(component, decodeFn, mcu); mcu++; } } else { for (n = 0; n < mcuToRead; n++) { for (i = 0; i < componentsLength; i++) { component = components[i]; h = component.h; v = component.v; for (j = 0; j < v; j++) { for (k = 0; k < h; k++) { decodeMcu(component, decodeFn, mcu, j, k); } } } mcu++; } } } // find marker bitsCount = 0; fileMarker = findNextFileMarker(data, offset); if (!fileMarker) { break; // Reached the end of the image data without finding any marker. } if (fileMarker.invalid) { // Some bad images seem to pad Scan blocks with e.g. zero bytes, skip // past those to attempt to find a valid marker (fixes issue4090.pdf). const partialMsg = mcuToRead > 0 ? "unexpected" : "excessive"; warn( `decodeScan - ${partialMsg} MCU data, current marker is: ${fileMarker.invalid}` ); offset = fileMarker.offset; } if (fileMarker.marker >= 0xffd0 && fileMarker.marker <= 0xffd7) { // RSTx offset += 2; } else { break; } } return offset - startOffset; } // A port of poppler's IDCT method which in turn is taken from: // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz, // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications', // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989, // 988-991. function quantizeAndInverse(component, blockBufferOffset, p) { var qt = component.quantizationTable, blockData = component.blockData; var v0, v1, v2, v3, v4, v5, v6, v7; var p0, p1, p2, p3, p4, p5, p6, p7; var t; if (!qt) { throw new JpegError("missing required Quantization Table."); } // inverse DCT on rows for (var row = 0; row < 64; row += 8) { // gather block data p0 = blockData[blockBufferOffset + row]; p1 = blockData[blockBufferOffset + row + 1]; p2 = blockData[blockBufferOffset + row + 2]; p3 = blockData[blockBufferOffset + row + 3]; p4 = blockData[blockBufferOffset + row + 4]; p5 = blockData[blockBufferOffset + row + 5]; p6 = blockData[blockBufferOffset + row + 6]; p7 = blockData[blockBufferOffset + row + 7]; // dequant p0 p0 *= qt[row]; // check for all-zero AC coefficients if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) { t = (dctSqrt2 * p0 + 512) >> 10; p[row] = t; p[row + 1] = t; p[row + 2] = t; p[row + 3] = t; p[row + 4] = t; p[row + 5] = t; p[row + 6] = t; p[row + 7] = t; continue; } // dequant p1 ... p7 p1 *= qt[row + 1]; p2 *= qt[row + 2]; p3 *= qt[row + 3]; p4 *= qt[row + 4]; p5 *= qt[row + 5]; p6 *= qt[row + 6]; p7 *= qt[row + 7]; // stage 4 v0 = (dctSqrt2 * p0 + 128) >> 8; v1 = (dctSqrt2 * p4 + 128) >> 8; v2 = p2; v3 = p6; v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8; v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8; v5 = p3 << 4; v6 = p5 << 4; // stage 3 v0 = (v0 + v1 + 1) >> 1; v1 = v0 - v1; t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8; v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8; v3 = t; v4 = (v4 + v6 + 1) >> 1; v6 = v4 - v6; v7 = (v7 + v5 + 1) >> 1; v5 = v7 - v5; // stage 2 v0 = (v0 + v3 + 1) >> 1; v3 = v0 - v3; v1 = (v1 + v2 + 1) >> 1; v2 = v1 - v2; t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12; v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12; v7 = t; t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12; v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12; v6 = t; // stage 1 p[row] = v0 + v7; p[row + 7] = v0 - v7; p[row + 1] = v1 + v6; p[row + 6] = v1 - v6; p[row + 2] = v2 + v5; p[row + 5] = v2 - v5; p[row + 3] = v3 + v4; p[row + 4] = v3 - v4; } // inverse DCT on columns for (var col = 0; col < 8; ++col) { p0 = p[col]; p1 = p[col + 8]; p2 = p[col + 16]; p3 = p[col + 24]; p4 = p[col + 32]; p5 = p[col + 40]; p6 = p[col + 48]; p7 = p[col + 56]; // check for all-zero AC coefficients if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) { t = (dctSqrt2 * p0 + 8192) >> 14; // Convert to 8-bit. if (t < -2040) { t = 0; } else if (t >= 2024) { t = 255; } else { t = (t + 2056) >> 4; } blockData[blockBufferOffset + col] = t; blockData[blockBufferOffset + col + 8] = t; blockData[blockBufferOffset + col + 16] = t; blockData[blockBufferOffset + col + 24] = t; blockData[blockBufferOffset + col + 32] = t; blockData[blockBufferOffset + col + 40] = t; blockData[blockBufferOffset + col + 48] = t; blockData[blockBufferOffset + col + 56] = t; continue; } // stage 4 v0 = (dctSqrt2 * p0 + 2048) >> 12; v1 = (dctSqrt2 * p4 + 2048) >> 12; v2 = p2; v3 = p6; v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12; v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12; v5 = p3; v6 = p5; // stage 3 // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when // converting to UInt8 range later. v0 = ((v0 + v1 + 1) >> 1) + 4112; v1 = v0 - v1; t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12; v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12; v3 = t; v4 = (v4 + v6 + 1) >> 1; v6 = v4 - v6; v7 = (v7 + v5 + 1) >> 1; v5 = v7 - v5; // stage 2 v0 = (v0 + v3 + 1) >> 1; v3 = v0 - v3; v1 = (v1 + v2 + 1) >> 1; v2 = v1 - v2; t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12; v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12; v7 = t; t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12; v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12; v6 = t; // stage 1 p0 = v0 + v7; p7 = v0 - v7; p1 = v1 + v6; p6 = v1 - v6; p2 = v2 + v5; p5 = v2 - v5; p3 = v3 + v4; p4 = v3 - v4; // Convert to 8-bit integers. if (p0 < 16) { p0 = 0; } else if (p0 >= 4080) { p0 = 255; } else { p0 >>= 4; } if (p1 < 16) { p1 = 0; } else if (p1 >= 4080) { p1 = 255; } else { p1 >>= 4; } if (p2 < 16) { p2 = 0; } else if (p2 >= 4080) { p2 = 255; } else { p2 >>= 4; } if (p3 < 16) { p3 = 0; } else if (p3 >= 4080) { p3 = 255; } else { p3 >>= 4; } if (p4 < 16) { p4 = 0; } else if (p4 >= 4080) { p4 = 255; } else { p4 >>= 4; } if (p5 < 16) { p5 = 0; } else if (p5 >= 4080) { p5 = 255; } else { p5 >>= 4; } if (p6 < 16) { p6 = 0; } else if (p6 >= 4080) { p6 = 255; } else { p6 >>= 4; } if (p7 < 16) { p7 = 0; } else if (p7 >= 4080) { p7 = 255; } else { p7 >>= 4; } // store block data blockData[blockBufferOffset + col] = p0; blockData[blockBufferOffset + col + 8] = p1; blockData[blockBufferOffset + col + 16] = p2; blockData[blockBufferOffset + col + 24] = p3; blockData[blockBufferOffset + col + 32] = p4; blockData[blockBufferOffset + col + 40] = p5; blockData[blockBufferOffset + col + 48] = p6; blockData[blockBufferOffset + col + 56] = p7; } } function buildComponentData(frame, component) { var blocksPerLine = component.blocksPerLine; var blocksPerColumn = component.blocksPerColumn; var computationBuffer = new Int16Array(64); for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) { for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) { var offset = getBlockBufferOffset(component, blockRow, blockCol); quantizeAndInverse(component, offset, computationBuffer); } } return component.blockData; } function findNextFileMarker(data, currentPos, startPos = currentPos) { const maxPos = data.length - 1; var newPos = startPos < currentPos ? startPos : currentPos; if (currentPos >= maxPos) { return null; // Don't attempt to read non-existent data and just return. } var currentMarker = readUint16(data, currentPos); if (currentMarker >= 0xffc0 && currentMarker <= 0xfffe) { return { invalid: null, marker: currentMarker, offset: currentPos, }; } var newMarker = readUint16(data, newPos); while (!(newMarker >= 0xffc0 && newMarker <= 0xfffe)) { if (++newPos >= maxPos) { return null; // Don't attempt to read non-existent data and just return. } newMarker = readUint16(data, newPos); } return { invalid: currentMarker.toString(16), marker: newMarker, offset: newPos, }; } JpegImage.prototype = { parse(data, { dnlScanLines = null } = {}) { function readDataBlock() { const length = readUint16(data, offset); offset += 2; let endOffset = offset + length - 2; var fileMarker = findNextFileMarker(data, endOffset, offset); if (fileMarker && fileMarker.invalid) { warn( "readDataBlock - incorrect length, current marker is: " + fileMarker.invalid ); endOffset = fileMarker.offset; } var array = data.subarray(offset, endOffset); offset += array.length; return array; } function prepareComponents(frame) { var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH); var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV); for (var i = 0; i < frame.components.length; i++) { component = frame.components[i]; var blocksPerLine = Math.ceil( (Math.ceil(frame.samplesPerLine / 8) * component.h) / frame.maxH ); var blocksPerColumn = Math.ceil( (Math.ceil(frame.scanLines / 8) * component.v) / frame.maxV ); var blocksPerLineForMcu = mcusPerLine * component.h; var blocksPerColumnForMcu = mcusPerColumn * component.v; var blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1); component.blockData = new Int16Array(blocksBufferSize); component.blocksPerLine = blocksPerLine; component.blocksPerColumn = blocksPerColumn; } frame.mcusPerLine = mcusPerLine; frame.mcusPerColumn = mcusPerColumn; } var offset = 0; var jfif = null; var adobe = null; var frame, resetInterval; let numSOSMarkers = 0; var quantizationTables = []; var huffmanTablesAC = [], huffmanTablesDC = []; let fileMarker = readUint16(data, offset); offset += 2; if (fileMarker !== /* SOI (Start of Image) = */ 0xffd8) { throw new JpegError("SOI not found"); } fileMarker = readUint16(data, offset); offset += 2; markerLoop: while (fileMarker !== /* EOI (End of Image) = */ 0xffd9) { var i, j, l; switch (fileMarker) { case 0xffe0: // APP0 (Application Specific) case 0xffe1: // APP1 case 0xffe2: // APP2 case 0xffe3: // APP3 case 0xffe4: // APP4 case 0xffe5: // APP5 case 0xffe6: // APP6 case 0xffe7: // APP7 case 0xffe8: // APP8 case 0xffe9: // APP9 case 0xffea: // APP10 case 0xffeb: // APP11 case 0xffec: // APP12 case 0xffed: // APP13 case 0xffee: // APP14 case 0xffef: // APP15 case 0xfffe: // COM (Comment) var appData = readDataBlock(); if (fileMarker === 0xffe0) { // 'JFIF\x00' if ( appData[0] === 0x4a && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0 ) { jfif = { version: { major: appData[5], minor: appData[6] }, densityUnits: appData[7], xDensity: (appData[8] << 8) | appData[9], yDensity: (appData[10] << 8) | appData[11], thumbWidth: appData[12], thumbHeight: appData[13], thumbData: appData.subarray( 14, 14 + 3 * appData[12] * appData[13] ), }; } } // TODO APP1 - Exif if (fileMarker === 0xffee) { // 'Adobe' if ( appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6f && appData[3] === 0x62 && appData[4] === 0x65 ) { adobe = { version: (appData[5] << 8) | appData[6], flags0: (appData[7] << 8) | appData[8], flags1: (appData[9] << 8) | appData[10], transformCode: appData[11], }; } } break; case 0xffdb: // DQT (Define Quantization Tables) const quantizationTablesLength = readUint16(data, offset); offset += 2; var quantizationTablesEnd = quantizationTablesLength + offset - 2; var z; while (offset < quantizationTablesEnd) { var quantizationTableSpec = data[offset++]; var tableData = new Uint16Array(64); if (quantizationTableSpec >> 4 === 0) { // 8 bit values for (j = 0; j < 64; j++) { z = dctZigZag[j]; tableData[z] = data[offset++]; } } else if (quantizationTableSpec >> 4 === 1) { // 16 bit values for (j = 0; j < 64; j++) { z = dctZigZag[j]; tableData[z] = readUint16(data, offset); offset += 2; } } else { throw new JpegError("DQT - invalid table spec"); } quantizationTables[quantizationTableSpec & 15] = tableData; } break; case 0xffc0: // SOF0 (Start of Frame, Baseline DCT) case 0xffc1: // SOF1 (Start of Frame, Extended DCT) case 0xffc2: // SOF2 (Start of Frame, Progressive DCT) if (frame) { throw new JpegError("Only single frame JPEGs supported"); } offset += 2; // Skip marker length. frame = {}; frame.extended = fileMarker === 0xffc1; frame.progressive = fileMarker === 0xffc2; frame.precision = data[offset++]; const sofScanLines = readUint16(data, offset); offset += 2; frame.scanLines = dnlScanLines || sofScanLines; frame.samplesPerLine = readUint16(data, offset); offset += 2; frame.components = []; frame.componentIds = {}; var componentsCount = data[offset++], componentId; var maxH = 0, maxV = 0; for (i = 0; i < componentsCount; i++) { componentId = data[offset]; var h = data[offset + 1] >> 4; var v = data[offset + 1] & 15; if (maxH < h) { maxH = h; } if (maxV < v) { maxV = v; } var qId = data[offset + 2]; l = frame.components.push({ h, v, quantizationId: qId, quantizationTable: null, // See comment below. }); frame.componentIds[componentId] = l - 1; offset += 3; } frame.maxH = maxH; frame.maxV = maxV; prepareComponents(frame); break; case 0xffc4: // DHT (Define Huffman Tables) const huffmanLength = readUint16(data, offset); offset += 2; for (i = 2; i < huffmanLength; ) { var huffmanTableSpec = data[offset++]; var codeLengths = new Uint8Array(16); var codeLengthSum = 0; for (j = 0; j < 16; j++, offset++) { codeLengthSum += codeLengths[j] = data[offset]; } var huffmanValues = new Uint8Array(codeLengthSum); for (j = 0; j < codeLengthSum; j++, offset++) { huffmanValues[j] = data[offset]; } i += 17 + codeLengthSum; (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[ huffmanTableSpec & 15 ] = buildHuffmanTable(codeLengths, huffmanValues); } break; case 0xffdd: // DRI (Define Restart Interval) offset += 2; // Skip marker length. resetInterval = readUint16(data, offset); offset += 2; break; case 0xffda: // SOS (Start of Scan) // A DNL marker (0xFFDC), if it exists, is only allowed at the end // of the first scan segment and may only occur once in an image. // Furthermore, to prevent an infinite loop, do *not* attempt to // parse DNL markers during re-parsing of the JPEG scan data. const parseDNLMarker = ++numSOSMarkers === 1 && !dnlScanLines; offset += 2; // Skip marker length. var selectorsCount = data[offset++]; var components = [], component; for (i = 0; i < selectorsCount; i++) { const index = data[offset++]; var componentIndex = frame.componentIds[index]; component = frame.components[componentIndex]; component.index = index; var tableSpec = data[offset++]; component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4]; component.huffmanTableAC = huffmanTablesAC[tableSpec & 15]; components.push(component); } var spectralStart = data[offset++]; var spectralEnd = data[offset++]; var successiveApproximation = data[offset++]; try { var processed = decodeScan( data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15, parseDNLMarker ); offset += processed; } catch (ex) { if (ex instanceof DNLMarkerError) { warn(`${ex.message} -- attempting to re-parse the JPEG image.`); return this.parse(data, { dnlScanLines: ex.scanLines }); } else if (ex instanceof EOIMarkerError) { warn(`${ex.message} -- ignoring the rest of the image data.`); break markerLoop; } throw ex; } break; case 0xffdc: // DNL (Define Number of Lines) // Ignore the marker, since it's being handled in `decodeScan`. offset += 4; break; case 0xffff: // Fill bytes if (data[offset] !== 0xff) { // Avoid skipping a valid marker. offset--; } break; default: // Could be incorrect encoding -- the last 0xFF byte of the previous // block could have been eaten by the encoder, hence we fallback to // `startPos = offset - 3` when looking for the next valid marker. const nextFileMarker = findNextFileMarker( data, /* currentPos = */ offset - 2, /* startPos = */ offset - 3 ); if (nextFileMarker && nextFileMarker.invalid) { warn( "JpegImage.parse - unexpected data, current marker is: " + nextFileMarker.invalid ); offset = nextFileMarker.offset; break; } if (offset >= data.length - 1) { warn( "JpegImage.parse - reached the end of the image data " + "without finding an EOI marker (0xFFD9)." ); break markerLoop; } throw new JpegError( "JpegImage.parse - unknown marker: " + fileMarker.toString(16) ); } fileMarker = readUint16(data, offset); offset += 2; } this.width = frame.samplesPerLine; this.height = frame.scanLines; this.jfif = jfif; this.adobe = adobe; this.components = []; for (i = 0; i < frame.components.length; i++) { component = frame.components[i]; // Prevent errors when DQT markers are placed after SOF{n} markers, // by assigning the `quantizationTable` entry after the entire image // has been parsed (fixes issue7406.pdf). var quantizationTable = quantizationTables[component.quantizationId]; if (quantizationTable) { component.quantizationTable = quantizationTable; } this.components.push({ index: component.index, output: buildComponentData(frame, component), scaleX: component.h / frame.maxH, scaleY: component.v / frame.maxV, blocksPerLine: component.blocksPerLine, blocksPerColumn: component.blocksPerColumn, }); } this.numComponents = this.components.length; return undefined; }, _getLinearizedBlockData(width, height, isSourcePDF = false) { var scaleX = this.width / width, scaleY = this.height / height; var component, componentScaleX, componentScaleY, blocksPerScanline; var x, y, i, j, k; var index; var offset = 0; var output; var numComponents = this.components.length; var dataLength = width * height * numComponents; var data = new Uint8ClampedArray(dataLength); var xScaleBlockOffset = new Uint32Array(width); var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs let lastComponentScaleX; for (i = 0; i < numComponents; i++) { component = this.components[i]; componentScaleX = component.scaleX * scaleX; componentScaleY = component.scaleY * scaleY; offset = i; output = component.output; blocksPerScanline = (component.blocksPerLine + 1) << 3; // Precalculate the `xScaleBlockOffset`. Since it doesn't depend on the // component data, that's only necessary when `componentScaleX` changes. if (componentScaleX !== lastComponentScaleX) { for (x = 0; x < width; x++) { j = 0 | (x * componentScaleX); xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7); } lastComponentScaleX = componentScaleX; } // linearize the blocks of the component for (y = 0; y < height; y++) { j = 0 | (y * componentScaleY); index = (blocksPerScanline * (j & mask3LSB)) | ((j & 7) << 3); for (x = 0; x < width; x++) { data[offset] = output[index + xScaleBlockOffset[x]]; offset += numComponents; } } } // decodeTransform contains pairs of multiplier (-256..256) and additive let transform = this._decodeTransform; // In PDF files, JPEG images with CMYK colour spaces are usually inverted // (this can be observed by extracting the raw image data). // Since the conversion algorithms (see below) were written primarily for // the PDF use-cases, attempting to use `JpegImage` to parse standalone // JPEG (CMYK) images may thus result in inverted images (see issue 9513). // // Unfortunately it's not (always) possible to tell, from the image data // alone, if it needs to be inverted. Thus in an attempt to provide better // out-of-box behaviour when `JpegImage` is used standalone, default to // inverting JPEG (CMYK) images if and only if the image data does *not* // come from a PDF file and no `decodeTransform` was passed by the user. if (!isSourcePDF && numComponents === 4 && !transform) { // prettier-ignore transform = new Int32Array([ -256, 255, -256, 255, -256, 255, -256, 255]); } if (transform) { for (i = 0; i < dataLength; ) { for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) { data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1]; } } } return data; }, get _isColorConversionNeeded() { if (this.adobe) { // The adobe transform marker overrides any previous setting. return !!this.adobe.transformCode; } if (this.numComponents === 3) { if (this._colorTransform === 0) { // If the Adobe transform marker is not present and the image // dictionary has a 'ColorTransform' entry, explicitly set to `0`, // then the colours should *not* be transformed. return false; } else if ( this.components[0].index === /* "R" = */ 0x52 && this.components[1].index === /* "G" = */ 0x47 && this.components[2].index === /* "B" = */ 0x42 ) { // If the three components are indexed as RGB in ASCII // then the colours should *not* be transformed. return false; } return true; } // `this.numComponents !== 3` if (this._colorTransform === 1) { // If the Adobe transform marker is not present and the image // dictionary has a 'ColorTransform' entry, explicitly set to `1`, // then the colours should be transformed. return true; } return false; }, _convertYccToRgb: function convertYccToRgb(data) { var Y, Cb, Cr; for (var i = 0, length = data.length; i < length; i += 3) { Y = data[i]; Cb = data[i + 1]; Cr = data[i + 2]; data[i] = Y - 179.456 + 1.402 * Cr; data[i + 1] = Y + 135.459 - 0.344 * Cb - 0.714 * Cr; data[i + 2] = Y - 226.816 + 1.772 * Cb; } return data; }, _convertYcckToRgb: function convertYcckToRgb(data) { var Y, Cb, Cr, k; var offset = 0; for (var i = 0, length = data.length; i < length; i += 4) { Y = data[i]; Cb = data[i + 1]; Cr = data[i + 2]; k = data[i + 3]; data[offset++] = -122.67195406894 + Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr - 5.4080610064599e-5 * Y + 0.00048449797120281 * k - 0.154362151871126) + Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y - 0.00477271405408747 * k + 1.53380253221734) + Y * (0.000961250184130688 * Y - 0.00266257332283933 * k + 0.48357088451265) + k * (-0.000336197177618394 * k + 0.484791561490776); data[offset++] = 107.268039397724 + Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr + 0.000659397001245577 * Y + 0.000426105652938837 * k - 0.176491792462875) + Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y + 0.000770482631801132 * k - 0.151051492775562) + Y * (0.00126935368114843 * Y - 0.00265090189010898 * k + 0.25802910206845) + k * (-0.000318913117588328 * k - 0.213742400323665); data[offset++] = -20.810012546947 + Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr + 0.0020741088115012 * Y - 0.00288260236853442 * k + 0.814272968359295) + Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y + 0.000560833691242812 * k - 0.195152027534049) + Y * (0.00174418132927582 * Y - 0.00255243321439347 * k + 0.116935020465145) + k * (-0.000343531996510555 * k + 0.24165260232407); } // Ensure that only the converted RGB data is returned. return data.subarray(0, offset); }, _convertYcckToCmyk: function convertYcckToCmyk(data) { var Y, Cb, Cr; for (var i = 0, length = data.length; i < length; i += 4) { Y = data[i]; Cb = data[i + 1]; Cr = data[i + 2]; data[i] = 434.456 - Y - 1.402 * Cr; data[i + 1] = 119.541 - Y + 0.344 * Cb + 0.714 * Cr; data[i + 2] = 481.816 - Y - 1.772 * Cb; // K in data[i + 3] is unchanged } return data; }, _convertCmykToRgb: function convertCmykToRgb(data) { var c, m, y, k; var offset = 0; for (var i = 0, length = data.length; i < length; i += 4) { c = data[i]; m = data[i + 1]; y = data[i + 2]; k = data[i + 3]; data[offset++] = 255 + c * (-0.00006747147073602441 * c + 0.0008379262121013727 * m + 0.0002894718188643294 * y + 0.003264231057537806 * k - 1.1185611867203937) + m * (0.000026374107616089405 * m - 0.00008626949158638572 * y - 0.0002748769067499491 * k - 0.02155688794978967) + y * (-0.00003878099212869363 * y - 0.0003267808279485286 * k + 0.0686742238595345) - k * (0.0003361971776183937 * k + 0.7430659151342254); data[offset++] = 255 + c * (0.00013596372813588848 * c + 0.000924537132573585 * m + 0.00010567359618683593 * y + 0.0004791864687436512 * k - 0.3109689587515875) + m * (-0.00023545346108370344 * m + 0.0002702845253534714 * y + 0.0020200308977307156 * k - 0.7488052167015494) + y * (0.00006834815998235662 * y + 0.00015168452363460973 * k - 0.09751927774728933) - k * (0.00031891311758832814 * k + 0.7364883807733168); data[offset++] = 255 + c * (0.000013598650411385307 * c + 0.00012423956175490851 * m + 0.0004751985097583589 * y - 0.0000036729317476630422 * k - 0.05562186980264034) + m * (0.00016141380598724676 * m + 0.0009692239130725186 * y + 0.0007782692450036253 * k - 0.44015232367526463) + y * (5.068882914068769e-7 * y + 0.0017778369011375071 * k - 0.7591454649749609) - k * (0.0003435319965105553 * k + 0.7063770186160144); } // Ensure that only the converted RGB data is returned. return data.subarray(0, offset); }, getData({ width, height, forceRGB = false, isSourcePDF = false }) { if (this.numComponents > 4) { throw new JpegError("Unsupported color mode"); } // Type of data: Uint8ClampedArray(width * height * numComponents) var data = this._getLinearizedBlockData(width, height, isSourcePDF); if (this.numComponents === 1 && forceRGB) { var dataLength = data.length; var rgbData = new Uint8ClampedArray(dataLength * 3); var offset = 0; for (var i = 0; i < dataLength; i++) { var grayColor = data[i]; rgbData[offset++] = grayColor; rgbData[offset++] = grayColor; rgbData[offset++] = grayColor; } return rgbData; } else if (this.numComponents === 3 && this._isColorConversionNeeded) { return this._convertYccToRgb(data); } else if (this.numComponents === 4) { if (this._isColorConversionNeeded) { if (forceRGB) { return this._convertYcckToRgb(data); } return this._convertYcckToCmyk(data); } else if (forceRGB) { return this._convertCmykToRgb(data); } } return data; }, }; return JpegImage; })(); "use strict"; var ArithmeticDecoder = function ArithmeticDecoderClosure() { var QeTable = [{ qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1 }, { qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0 }, { qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0 }, { qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0 }, { qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0 }, { qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0 }, { qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1 }, { qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0 }, { qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0 }, { qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0 }, { qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0 }, { qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0 }, { qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0 }, { qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0 }, { qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1 }, { qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0 }, { qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0 }, { qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0 }, { qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0 }, { qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0 }, { qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0 }, { qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0 }, { qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0 }, { qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0 }, { qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0 }, { qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0 }, { qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0 }, { qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0 }, { qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0 }, { qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0 }, { qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0 }, { qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0 }, { qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0 }, { qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0 }, { qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0 }, { qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0 }, { qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0 }, { qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0 }, { qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0 }, { qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0 }, { qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0 }, { qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0 }, { qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0 }, { qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0 }, { qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0 }, { qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0 }, { qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0 }]; function ArithmeticDecoder(data, start, end) { this.data = data; this.bp = start; this.dataEnd = end; this.chigh = data[start]; this.clow = 0; this.byteIn(); this.chigh = this.chigh << 7 & 0xFFFF | this.clow >> 9 & 0x7F; this.clow = this.clow << 7 & 0xFFFF; this.ct -= 7; this.a = 0x8000; } ArithmeticDecoder.prototype = { byteIn: function ArithmeticDecoder_byteIn() { var data = this.data; var bp = this.bp; if (data[bp] === 0xFF) { var b1 = data[bp + 1]; if (b1 > 0x8F) { this.clow += 0xFF00; this.ct = 8; } else { bp++; this.clow += data[bp] << 9; this.ct = 7; this.bp = bp; } } else { bp++; this.clow += bp < this.dataEnd ? data[bp] << 8 : 0xFF00; this.ct = 8; this.bp = bp; } if (this.clow > 0xFFFF) { this.chigh += this.clow >> 16; this.clow &= 0xFFFF; } }, readBit: function ArithmeticDecoder_readBit(contexts, pos) { var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1; var qeTableIcx = QeTable[cx_index]; var qeIcx = qeTableIcx.qe; var d; var a = this.a - qeIcx; if (this.chigh < qeIcx) { if (a < qeIcx) { a = qeIcx; d = cx_mps; cx_index = qeTableIcx.nmps; } else { a = qeIcx; d = 1 ^ cx_mps; if (qeTableIcx.switchFlag === 1) { cx_mps = d; } cx_index = qeTableIcx.nlps; } } else { this.chigh -= qeIcx; if ((a & 0x8000) !== 0) { this.a = a; return cx_mps; } if (a < qeIcx) { d = 1 ^ cx_mps; if (qeTableIcx.switchFlag === 1) { cx_mps = d; } cx_index = qeTableIcx.nlps; } else { d = cx_mps; cx_index = qeTableIcx.nmps; } } do { if (this.ct === 0) { this.byteIn(); } a <<= 1; this.chigh = this.chigh << 1 & 0xFFFF | this.clow >> 15 & 1; this.clow = this.clow << 1 & 0xFFFF; this.ct--; } while ((a & 0x8000) === 0); this.a = a; contexts[pos] = cx_index << 1 | cx_mps; return d; } }; return ArithmeticDecoder; }(); "use strict"; var JpxImage = function JpxImageClosure() { var SubbandsGainLog2 = { 'LL': 0, 'LH': 1, 'HL': 1, 'HH': 2 }; function JpxImage() { this.failOnCorruptedImage = false; } JpxImage.prototype = { parse: function JpxImage_parse(data) { var head = readUint16(data, 0); if (head === 0xFF4F) { this.parseCodestream(data, 0, data.length); return; } var position = 0, length = data.length; while (position < length) { var headerSize = 8; var lbox = readUint32(data, position); var tbox = readUint32(data, position + 4); position += headerSize; if (lbox === 1) { lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4); position += 8; headerSize += 8; } if (lbox === 0) { lbox = length - position + headerSize; } if (lbox < headerSize) { error('JPX Error: Invalid box field size'); } var dataLength = lbox - headerSize; var jumpDataLength = true; switch (tbox) { case 0x6A703268: jumpDataLength = false; break; case 0x636F6C72: var method = data[position]; if (method === 1) { var colorspace = readUint32(data, position + 3); switch (colorspace) { case 16: case 17: case 18: break; default: warn('Unknown colorspace ' + colorspace); break; } } else if (method === 2) { info('ICC profile not supported'); } break; case 0x6A703263: this.parseCodestream(data, position, position + dataLength); break; case 0x6A502020: if (readUint32(data, position) !== 0x0d0a870a) { warn('Invalid JP2 signature'); } break; case 0x6A501A1A: case 0x66747970: case 0x72726571: case 0x72657320: case 0x69686472: break; default: var headerType = String.fromCharCode(tbox >> 24 & 0xFF, tbox >> 16 & 0xFF, tbox >> 8 & 0xFF, tbox & 0xFF); warn('Unsupported header type ' + tbox + ' (' + headerType + ')'); break; } if (jumpDataLength) { position += dataLength; } } }, parseImageProperties: function JpxImage_parseImageProperties(stream) { var newByte = stream.getByte(); while (newByte >= 0) { var oldByte = newByte; newByte = stream.getByte(); var code = oldByte << 8 | newByte; if (code === 0xFF51) { stream.skip(4); var Xsiz = stream.getInt32() >>> 0; var Ysiz = stream.getInt32() >>> 0; var XOsiz = stream.getInt32() >>> 0; var YOsiz = stream.getInt32() >>> 0; stream.skip(16); var Csiz = stream.getUint16(); this.width = Xsiz - XOsiz; this.height = Ysiz - YOsiz; this.componentsCount = Csiz; this.bitsPerComponent = 8; return; } } error('JPX Error: No size marker found in JPX stream'); }, parseCodestream: function JpxImage_parseCodestream(data, start, end) { var context = {}; var doNotRecover = false; try { var position = start; while (position + 1 < end) { var code = readUint16(data, position); position += 2; var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile; switch (code) { case 0xFF4F: context.mainHeader = true; break; case 0xFFD9: break; case 0xFF51: length = readUint16(data, position); var siz = {}; siz.Xsiz = readUint32(data, position + 4); siz.Ysiz = readUint32(data, position + 8); siz.XOsiz = readUint32(data, position + 12); siz.YOsiz = readUint32(data, position + 16); siz.XTsiz = readUint32(data, position + 20); siz.YTsiz = readUint32(data, position + 24); siz.XTOsiz = readUint32(data, position + 28); siz.YTOsiz = readUint32(data, position + 32); var componentsCount = readUint16(data, position + 36); siz.Csiz = componentsCount; var components = []; j = position + 38; for (var i = 0; i < componentsCount; i++) { var component = { precision: (data[j] & 0x7F) + 1, isSigned: !!(data[j] & 0x80), XRsiz: data[j + 1], YRsiz: data[j + 1] }; calculateComponentDimensions(component, siz); components.push(component); } context.SIZ = siz; context.components = components; calculateTileGrids(context, components); context.QCC = []; context.COC = []; break; case 0xFF5C: length = readUint16(data, position); var qcd = {}; j = position + 2; sqcd = data[j++]; switch (sqcd & 0x1F) { case 0: spqcdSize = 8; scalarExpounded = true; break; case 1: spqcdSize = 16; scalarExpounded = false; break; case 2: spqcdSize = 16; scalarExpounded = true; break; default: throw new Error('Invalid SQcd value ' + sqcd); } qcd.noQuantization = spqcdSize === 8; qcd.scalarExpounded = scalarExpounded; qcd.guardBits = sqcd >> 5; spqcds = []; while (j < length + position) { var spqcd = {}; if (spqcdSize === 8) { spqcd.epsilon = data[j++] >> 3; spqcd.mu = 0; } else { spqcd.epsilon = data[j] >> 3; spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1]; j += 2; } spqcds.push(spqcd); } qcd.SPqcds = spqcds; if (context.mainHeader) { context.QCD = qcd; } else { context.currentTile.QCD = qcd; context.currentTile.QCC = []; } break; case 0xFF5D: length = readUint16(data, position); var qcc = {}; j = position + 2; var cqcc; if (context.SIZ.Csiz < 257) { cqcc = data[j++]; } else { cqcc = readUint16(data, j); j += 2; } sqcd = data[j++]; switch (sqcd & 0x1F) { case 0: spqcdSize = 8; scalarExpounded = true; break; case 1: spqcdSize = 16; scalarExpounded = false; break; case 2: spqcdSize = 16; scalarExpounded = true; break; default: throw new Error('Invalid SQcd value ' + sqcd); } qcc.noQuantization = spqcdSize === 8; qcc.scalarExpounded = scalarExpounded; qcc.guardBits = sqcd >> 5; spqcds = []; while (j < length + position) { spqcd = {}; if (spqcdSize === 8) { spqcd.epsilon = data[j++] >> 3; spqcd.mu = 0; } else { spqcd.epsilon = data[j] >> 3; spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1]; j += 2; } spqcds.push(spqcd); } qcc.SPqcds = spqcds; if (context.mainHeader) { context.QCC[cqcc] = qcc; } else { context.currentTile.QCC[cqcc] = qcc; } break; case 0xFF52: length = readUint16(data, position); var cod = {}; j = position + 2; var scod = data[j++]; cod.entropyCoderWithCustomPrecincts = !!(scod & 1); cod.sopMarkerUsed = !!(scod & 2); cod.ephMarkerUsed = !!(scod & 4); cod.progressionOrder = data[j++]; cod.layersCount = readUint16(data, j); j += 2; cod.multipleComponentTransform = data[j++]; cod.decompositionLevelsCount = data[j++]; cod.xcb = (data[j++] & 0xF) + 2; cod.ycb = (data[j++] & 0xF) + 2; var blockStyle = data[j++]; cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1); cod.resetContextProbabilities = !!(blockStyle & 2); cod.terminationOnEachCodingPass = !!(blockStyle & 4); cod.verticalyStripe = !!(blockStyle & 8); cod.predictableTermination = !!(blockStyle & 16); cod.segmentationSymbolUsed = !!(blockStyle & 32); cod.reversibleTransformation = data[j++]; if (cod.entropyCoderWithCustomPrecincts) { var precinctsSizes = []; while (j < length + position) { var precinctsSize = data[j++]; precinctsSizes.push({ PPx: precinctsSize & 0xF, PPy: precinctsSize >> 4 }); } cod.precinctsSizes = precinctsSizes; } var unsupported = []; if (cod.selectiveArithmeticCodingBypass) { unsupported.push('selectiveArithmeticCodingBypass'); } if (cod.resetContextProbabilities) { unsupported.push('resetContextProbabilities'); } if (cod.terminationOnEachCodingPass) { unsupported.push('terminationOnEachCodingPass'); } if (cod.verticalyStripe) { unsupported.push('verticalyStripe'); } if (cod.predictableTermination) { unsupported.push('predictableTermination'); } if (unsupported.length > 0) { doNotRecover = true; throw new Error('Unsupported COD options (' + unsupported.join(', ') + ')'); } if (context.mainHeader) { context.COD = cod; } else { context.currentTile.COD = cod; context.currentTile.COC = []; } break; case 0xFF90: length = readUint16(data, position); tile = {}; tile.index = readUint16(data, position + 2); tile.length = readUint32(data, position + 4); tile.dataEnd = tile.length + position - 2; tile.partIndex = data[position + 8]; tile.partsCount = data[position + 9]; context.mainHeader = false; if (tile.partIndex === 0) { tile.COD = context.COD; tile.COC = context.COC.slice(0); tile.QCD = context.QCD; tile.QCC = context.QCC.slice(0); } context.currentTile = tile; break; case 0xFF93: tile = context.currentTile; if (tile.partIndex === 0) { initializeTile(context, tile.index); buildPackets(context); } length = tile.dataEnd - position; parseTilePackets(context, data, position, length); break; case 0xFF55: case 0xFF57: case 0xFF58: case 0xFF64: length = readUint16(data, position); break; case 0xFF53: throw new Error('Codestream code 0xFF53 (COC) is ' + 'not implemented'); default: throw new Error('Unknown codestream code: ' + code.toString(16)); } position += length; } } catch (e) { if (doNotRecover || this.failOnCorruptedImage) { error('JPX Error: ' + e.message); } else { warn('JPX: Trying to recover from: ' + e.message); } } this.tiles = transformComponents(context); this.width = context.SIZ.Xsiz - context.SIZ.XOsiz; this.height = context.SIZ.Ysiz - context.SIZ.YOsiz; this.componentsCount = context.SIZ.Csiz; } }; function calculateComponentDimensions(component, siz) { component.x0 = Math.ceil(siz.XOsiz / component.XRsiz); component.x1 = Math.ceil(siz.Xsiz / component.XRsiz); component.y0 = Math.ceil(siz.YOsiz / component.YRsiz); component.y1 = Math.ceil(siz.Ysiz / component.YRsiz); component.width = component.x1 - component.x0; component.height = component.y1 - component.y0; } function calculateTileGrids(context, components) { var siz = context.SIZ; var tile, tiles = []; var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz); var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz); for (var q = 0; q < numYtiles; q++) { for (var p = 0; p < numXtiles; p++) { tile = {}; tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz); tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz); tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz); tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz); tile.width = tile.tx1 - tile.tx0; tile.height = tile.ty1 - tile.ty0; tile.components = []; tiles.push(tile); } } context.tiles = tiles; var componentsCount = siz.Csiz; for (var i = 0, ii = componentsCount; i < ii; i++) { var component = components[i]; for (var j = 0, jj = tiles.length; j < jj; j++) { var tileComponent = {}; tile = tiles[j]; tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz); tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz); tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz); tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz); tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0; tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0; tile.components[i] = tileComponent; } } } function getBlocksDimensions(context, component, r) { var codOrCoc = component.codingStyleParameters; var result = {}; if (!codOrCoc.entropyCoderWithCustomPrecincts) { result.PPx = 15; result.PPy = 15; } else { result.PPx = codOrCoc.precinctsSizes[r].PPx; result.PPy = codOrCoc.precinctsSizes[r].PPy; } result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx); result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy); return result; } function buildPrecincts(context, resolution, dimensions) { var precinctWidth = 1 << dimensions.PPx; var precinctHeight = 1 << dimensions.PPy; var isZeroRes = resolution.resLevel === 0; var precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1); var precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1); var numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0; var numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0; var numprecincts = numprecinctswide * numprecinctshigh; resolution.precinctParameters = { precinctWidth: precinctWidth, precinctHeight: precinctHeight, numprecinctswide: numprecinctswide, numprecinctshigh: numprecinctshigh, numprecincts: numprecincts, precinctWidthInSubband: precinctWidthInSubband, precinctHeightInSubband: precinctHeightInSubband }; } function buildCodeblocks(context, subband, dimensions) { var xcb_ = dimensions.xcb_; var ycb_ = dimensions.ycb_; var codeblockWidth = 1 << xcb_; var codeblockHeight = 1 << ycb_; var cbx0 = subband.tbx0 >> xcb_; var cby0 = subband.tby0 >> ycb_; var cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_; var cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_; var precinctParameters = subband.resolution.precinctParameters; var codeblocks = []; var precincts = []; var i, j, codeblock, precinctNumber; for (j = cby0; j < cby1; j++) { for (i = cbx0; i < cbx1; i++) { codeblock = { cbx: i, cby: j, tbx0: codeblockWidth * i, tby0: codeblockHeight * j, tbx1: codeblockWidth * (i + 1), tby1: codeblockHeight * (j + 1) }; codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0); codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0); codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1); codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1); var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband); var pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband); precinctNumber = pi + pj * precinctParameters.numprecinctswide; codeblock.precinctNumber = precinctNumber; codeblock.subbandType = subband.type; codeblock.Lblock = 3; if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) { continue; } codeblocks.push(codeblock); var precinct = precincts[precinctNumber]; if (precinct !== undefined) { if (i < precinct.cbxMin) { precinct.cbxMin = i; } else if (i > precinct.cbxMax) { precinct.cbxMax = i; } if (j < precinct.cbyMin) { precinct.cbxMin = j; } else if (j > precinct.cbyMax) { precinct.cbyMax = j; } } else { precincts[precinctNumber] = precinct = { cbxMin: i, cbyMin: j, cbxMax: i, cbyMax: j }; } codeblock.precinct = precinct; } } subband.codeblockParameters = { codeblockWidth: xcb_, codeblockHeight: ycb_, numcodeblockwide: cbx1 - cbx0 + 1, numcodeblockhigh: cby1 - cby0 + 1 }; subband.codeblocks = codeblocks; subband.precincts = precincts; } function createPacket(resolution, precinctNumber, layerNumber) { var precinctCodeblocks = []; var subbands = resolution.subbands; for (var i = 0, ii = subbands.length; i < ii; i++) { var subband = subbands[i]; var codeblocks = subband.codeblocks; for (var j = 0, jj = codeblocks.length; j < jj; j++) { var codeblock = codeblocks[j]; if (codeblock.precinctNumber !== precinctNumber) { continue; } precinctCodeblocks.push(codeblock); } } return { layerNumber: layerNumber, codeblocks: precinctCodeblocks }; } function LayerResolutionComponentPositionIterator(context) { var siz = context.SIZ; var tileIndex = context.currentTile.index; var tile = context.tiles[tileIndex]; var layersCount = tile.codingStyleDefaultParameters.layersCount; var componentsCount = siz.Csiz; var maxDecompositionLevelsCount = 0; for (var q = 0; q < componentsCount; q++) { maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount); } var l = 0, r = 0, i = 0, k = 0; this.nextPacket = function JpxImage_nextPacket() { for (; l < layersCount; l++) { for (; r <= maxDecompositionLevelsCount; r++) { for (; i < componentsCount; i++) { var component = tile.components[i]; if (r > component.codingStyleParameters.decompositionLevelsCount) { continue; } var resolution = component.resolutions[r]; var numprecincts = resolution.precinctParameters.numprecincts; for (; k < numprecincts;) { var packet = createPacket(resolution, k, l); k++; return packet; } k = 0; } i = 0; } r = 0; } error('JPX Error: Out of packets'); }; } function ResolutionLayerComponentPositionIterator(context) { var siz = context.SIZ; var tileIndex = context.currentTile.index; var tile = context.tiles[tileIndex]; var layersCount = tile.codingStyleDefaultParameters.layersCount; var componentsCount = siz.Csiz; var maxDecompositionLevelsCount = 0; for (var q = 0; q < componentsCount; q++) { maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount); } var r = 0, l = 0, i = 0, k = 0; this.nextPacket = function JpxImage_nextPacket() { for (; r <= maxDecompositionLevelsCount; r++) { for (; l < layersCount; l++) { for (; i < componentsCount; i++) { var component = tile.components[i]; if (r > component.codingStyleParameters.decompositionLevelsCount) { continue; } var resolution = component.resolutions[r]; var numprecincts = resolution.precinctParameters.numprecincts; for (; k < numprecincts;) { var packet = createPacket(resolution, k, l); k++; return packet; } k = 0; } i = 0; } l = 0; } error('JPX Error: Out of packets'); }; } function ResolutionPositionComponentLayerIterator(context) { var siz = context.SIZ; var tileIndex = context.currentTile.index; var tile = context.tiles[tileIndex]; var layersCount = tile.codingStyleDefaultParameters.layersCount; var componentsCount = siz.Csiz; var l, r, c, p; var maxDecompositionLevelsCount = 0; for (c = 0; c < componentsCount; c++) { var component = tile.components[c]; maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount); } var maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1); for (r = 0; r <= maxDecompositionLevelsCount; ++r) { var maxNumPrecincts = 0; for (c = 0; c < componentsCount; ++c) { var resolutions = tile.components[c].resolutions; if (r < resolutions.length) { maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts); } } maxNumPrecinctsInLevel[r] = maxNumPrecincts; } l = 0; r = 0; c = 0; p = 0; this.nextPacket = function JpxImage_nextPacket() { for (; r <= maxDecompositionLevelsCount; r++) { for (; p < maxNumPrecinctsInLevel[r]; p++) { for (; c < componentsCount; c++) { var component = tile.components[c]; if (r > component.codingStyleParameters.decompositionLevelsCount) { continue; } var resolution = component.resolutions[r]; var numprecincts = resolution.precinctParameters.numprecincts; if (p >= numprecincts) { continue; } for (; l < layersCount;) { var packet = createPacket(resolution, p, l); l++; return packet; } l = 0; } c = 0; } p = 0; } error('JPX Error: Out of packets'); }; } function PositionComponentResolutionLayerIterator(context) { var siz = context.SIZ; var tileIndex = context.currentTile.index; var tile = context.tiles[tileIndex]; var layersCount = tile.codingStyleDefaultParameters.layersCount; var componentsCount = siz.Csiz; var precinctsSizes = getPrecinctSizesInImageScale(tile); var precinctsIterationSizes = precinctsSizes; var l = 0, r = 0, c = 0, px = 0, py = 0; this.nextPacket = function JpxImage_nextPacket() { for (; py < precinctsIterationSizes.maxNumHigh; py++) { for (; px < precinctsIterationSizes.maxNumWide; px++) { for (; c < componentsCount; c++) { var component = tile.components[c]; var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; for (; r <= decompositionLevelsCount; r++) { var resolution = component.resolutions[r]; var sizeInImageScale = precinctsSizes.components[c].resolutions[r]; var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution); if (k === null) { continue; } for (; l < layersCount;) { var packet = createPacket(resolution, k, l); l++; return packet; } l = 0; } r = 0; } c = 0; } px = 0; } error('JPX Error: Out of packets'); }; } function ComponentPositionResolutionLayerIterator(context) { var siz = context.SIZ; var tileIndex = context.currentTile.index; var tile = context.tiles[tileIndex]; var layersCount = tile.codingStyleDefaultParameters.layersCount; var componentsCount = siz.Csiz; var precinctsSizes = getPrecinctSizesInImageScale(tile); var l = 0, r = 0, c = 0, px = 0, py = 0; this.nextPacket = function JpxImage_nextPacket() { for (; c < componentsCount; ++c) { var component = tile.components[c]; var precinctsIterationSizes = precinctsSizes.components[c]; var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; for (; py < precinctsIterationSizes.maxNumHigh; py++) { for (; px < precinctsIterationSizes.maxNumWide; px++) { for (; r <= decompositionLevelsCount; r++) { var resolution = component.resolutions[r]; var sizeInImageScale = precinctsIterationSizes.resolutions[r]; var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution); if (k === null) { continue; } for (; l < layersCount;) { var packet = createPacket(resolution, k, l); l++; return packet; } l = 0; } r = 0; } px = 0; } py = 0; } error('JPX Error: Out of packets'); }; } function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) { var posX = pxIndex * precinctIterationSizes.minWidth; var posY = pyIndex * precinctIterationSizes.minHeight; if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) { return null; } var startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide; return posX / sizeInImageScale.height + startPrecinctRowIndex; } function getPrecinctSizesInImageScale(tile) { var componentsCount = tile.components.length; var minWidth = Number.MAX_VALUE; var minHeight = Number.MAX_VALUE; var maxNumWide = 0; var maxNumHigh = 0; var sizePerComponent = new Array(componentsCount); for (var c = 0; c < componentsCount; c++) { var component = tile.components[c]; var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; var sizePerResolution = new Array(decompositionLevelsCount + 1); var minWidthCurrentComponent = Number.MAX_VALUE; var minHeightCurrentComponent = Number.MAX_VALUE; var maxNumWideCurrentComponent = 0; var maxNumHighCurrentComponent = 0; var scale = 1; for (var r = decompositionLevelsCount; r >= 0; --r) { var resolution = component.resolutions[r]; var widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth; var heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight; minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution); minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution); maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide); maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh); sizePerResolution[r] = { width: widthCurrentResolution, height: heightCurrentResolution }; scale <<= 1; } minWidth = Math.min(minWidth, minWidthCurrentComponent); minHeight = Math.min(minHeight, minHeightCurrentComponent); maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent); maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent); sizePerComponent[c] = { resolutions: sizePerResolution, minWidth: minWidthCurrentComponent, minHeight: minHeightCurrentComponent, maxNumWide: maxNumWideCurrentComponent, maxNumHigh: maxNumHighCurrentComponent }; } return { components: sizePerComponent, minWidth: minWidth, minHeight: minHeight, maxNumWide: maxNumWide, maxNumHigh: maxNumHigh }; } function buildPackets(context) { var siz = context.SIZ; var tileIndex = context.currentTile.index; var tile = context.tiles[tileIndex]; var componentsCount = siz.Csiz; for (var c = 0; c < componentsCount; c++) { var component = tile.components[c]; var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount; var resolutions = []; var subbands = []; for (var r = 0; r <= decompositionLevelsCount; r++) { var blocksDimensions = getBlocksDimensions(context, component, r); var resolution = {}; var scale = 1 << decompositionLevelsCount - r; resolution.trx0 = Math.ceil(component.tcx0 / scale); resolution.try0 = Math.ceil(component.tcy0 / scale); resolution.trx1 = Math.ceil(component.tcx1 / scale); resolution.try1 = Math.ceil(component.tcy1 / scale); resolution.resLevel = r; buildPrecincts(context, resolution, blocksDimensions); resolutions.push(resolution); var subband; if (r === 0) { subband = {}; subband.type = 'LL'; subband.tbx0 = Math.ceil(component.tcx0 / scale); subband.tby0 = Math.ceil(component.tcy0 / scale); subband.tbx1 = Math.ceil(component.tcx1 / scale); subband.tby1 = Math.ceil(component.tcy1 / scale); subband.resolution = resolution; buildCodeblocks(context, subband, blocksDimensions); subbands.push(subband); resolution.subbands = [subband]; } else { var bscale = 1 << decompositionLevelsCount - r + 1; var resolutionSubbands = []; subband = {}; subband.type = 'HL'; subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5); subband.tby0 = Math.ceil(component.tcy0 / bscale); subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5); subband.tby1 = Math.ceil(component.tcy1 / bscale); subband.resolution = resolution; buildCodeblocks(context, subband, blocksDimensions); subbands.push(subband); resolutionSubbands.push(subband); subband = {}; subband.type = 'LH'; subband.tbx0 = Math.ceil(component.tcx0 / bscale); subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5); subband.tbx1 = Math.ceil(component.tcx1 / bscale); subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5); subband.resolution = resolution; buildCodeblocks(context, subband, blocksDimensions); subbands.push(subband); resolutionSubbands.push(subband); subband = {}; subband.type = 'HH'; subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5); subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5); subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5); subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5); subband.resolution = resolution; buildCodeblocks(context, subband, blocksDimensions); subbands.push(subband); resolutionSubbands.push(subband); resolution.subbands = resolutionSubbands; } } component.resolutions = resolutions; component.subbands = subbands; } var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder; switch (progressionOrder) { case 0: tile.packetsIterator = new LayerResolutionComponentPositionIterator(context); break; case 1: tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context); break; case 2: tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context); break; case 3: tile.packetsIterator = new PositionComponentResolutionLayerIterator(context); break; case 4: tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context); break; default: error('JPX Error: Unsupported progression order ' + progressionOrder); } } function parseTilePackets(context, data, offset, dataLength) { var position = 0; var buffer, bufferSize = 0, skipNextBit = false; function readBits(count) { while (bufferSize < count) { var b = data[offset + position]; position++; if (skipNextBit) { buffer = buffer << 7 | b; bufferSize += 7; skipNextBit = false; } else { buffer = buffer << 8 | b; bufferSize += 8; } if (b === 0xFF) { skipNextBit = true; } } bufferSize -= count; return buffer >>> bufferSize & (1 << count) - 1; } function skipMarkerIfEqual(value) { if (data[offset + position - 1] === 0xFF && data[offset + position] === value) { skipBytes(1); return true; } else if (data[offset + position] === 0xFF && data[offset + position + 1] === value) { skipBytes(2); return true; } return false; } function skipBytes(count) { position += count; } function alignToByte() { bufferSize = 0; if (skipNextBit) { position++; skipNextBit = false; } } function readCodingpasses() { if (readBits(1) === 0) { return 1; } if (readBits(1) === 0) { return 2; } var value = readBits(2); if (value < 3) { return value + 3; } value = readBits(5); if (value < 31) { return value + 6; } value = readBits(7); return value + 37; } var tileIndex = context.currentTile.index; var tile = context.tiles[tileIndex]; var sopMarkerUsed = context.COD.sopMarkerUsed; var ephMarkerUsed = context.COD.ephMarkerUsed; var packetsIterator = tile.packetsIterator; while (position < dataLength) { alignToByte(); if (sopMarkerUsed && skipMarkerIfEqual(0x91)) { skipBytes(4); } var packet = packetsIterator.nextPacket(); if (!readBits(1)) { continue; } var layerNumber = packet.layerNumber; var queue = [], codeblock; for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) { codeblock = packet.codeblocks[i]; var precinct = codeblock.precinct; var codeblockColumn = codeblock.cbx - precinct.cbxMin; var codeblockRow = codeblock.cby - precinct.cbyMin; var codeblockIncluded = false; var firstTimeInclusion = false; var valueReady; if (codeblock['included'] !== undefined) { codeblockIncluded = !!readBits(1); } else { precinct = codeblock.precinct; var inclusionTree, zeroBitPlanesTree; if (precinct['inclusionTree'] !== undefined) { inclusionTree = precinct.inclusionTree; } else { var width = precinct.cbxMax - precinct.cbxMin + 1; var height = precinct.cbyMax - precinct.cbyMin + 1; inclusionTree = new InclusionTree(width, height, layerNumber); zeroBitPlanesTree = new TagTree(width, height); precinct.inclusionTree = inclusionTree; precinct.zeroBitPlanesTree = zeroBitPlanesTree; } if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) { while (true) { if (readBits(1)) { valueReady = !inclusionTree.nextLevel(); if (valueReady) { codeblock.included = true; codeblockIncluded = firstTimeInclusion = true; break; } } else { inclusionTree.incrementValue(layerNumber); break; } } } } if (!codeblockIncluded) { continue; } if (firstTimeInclusion) { zeroBitPlanesTree = precinct.zeroBitPlanesTree; zeroBitPlanesTree.reset(codeblockColumn, codeblockRow); while (true) { if (readBits(1)) { valueReady = !zeroBitPlanesTree.nextLevel(); if (valueReady) { break; } } else { zeroBitPlanesTree.incrementValue(); } } codeblock.zeroBitPlanes = zeroBitPlanesTree.value; } var codingpasses = readCodingpasses(); while (readBits(1)) { codeblock.Lblock++; } var codingpassesLog2 = log2(codingpasses); var bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock; var codedDataLength = readBits(bits); queue.push({ codeblock: codeblock, codingpasses: codingpasses, dataLength: codedDataLength }); } alignToByte(); if (ephMarkerUsed) { skipMarkerIfEqual(0x92); } while (queue.length > 0) { var packetItem = queue.shift(); codeblock = packetItem.codeblock; if (codeblock['data'] === undefined) { codeblock.data = []; } codeblock.data.push({ data: data, start: offset + position, end: offset + position + packetItem.dataLength, codingpasses: packetItem.codingpasses }); position += packetItem.dataLength; } } return position; } function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed) { var x0 = subband.tbx0; var y0 = subband.tby0; var width = subband.tbx1 - subband.tbx0; var codeblocks = subband.codeblocks; var right = subband.type.charAt(0) === 'H' ? 1 : 0; var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0; for (var i = 0, ii = codeblocks.length; i < ii; ++i) { var codeblock = codeblocks[i]; var blockWidth = codeblock.tbx1_ - codeblock.tbx0_; var blockHeight = codeblock.tby1_ - codeblock.tby0_; if (blockWidth === 0 || blockHeight === 0) { continue; } if (codeblock['data'] === undefined) { continue; } var bitModel, currentCodingpassType; bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb); currentCodingpassType = 2; var data = codeblock.data, totalLength = 0, codingpasses = 0; var j, jj, dataItem; for (j = 0, jj = data.length; j < jj; j++) { dataItem = data[j]; totalLength += dataItem.end - dataItem.start; codingpasses += dataItem.codingpasses; } var encodedData = new Uint8Array(totalLength); var position = 0; for (j = 0, jj = data.length; j < jj; j++) { dataItem = data[j]; var chunk = dataItem.data.subarray(dataItem.start, dataItem.end); encodedData.set(chunk, position); position += chunk.length; } var decoder = new ArithmeticDecoder(encodedData, 0, totalLength); bitModel.setDecoder(decoder); for (j = 0; j < codingpasses; j++) { switch (currentCodingpassType) { case 0: bitModel.runSignificancePropagationPass(); break; case 1: bitModel.runMagnitudeRefinementPass(); break; case 2: bitModel.runCleanupPass(); if (segmentationSymbolUsed) { bitModel.checkSegmentationSymbol(); } break; } currentCodingpassType = (currentCodingpassType + 1) % 3; } var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width; var sign = bitModel.coefficentsSign; var magnitude = bitModel.coefficentsMagnitude; var bitsDecoded = bitModel.bitsDecoded; var magnitudeCorrection = reversible ? 0 : 0.5; var k, n, nb; position = 0; var interleave = subband.type !== 'LL'; for (j = 0; j < blockHeight; j++) { var row = offset / width | 0; var levelOffset = 2 * row * (levelWidth - width) + right + bottom; for (k = 0; k < blockWidth; k++) { n = magnitude[position]; if (n !== 0) { n = (n + magnitudeCorrection) * delta; if (sign[position] !== 0) { n = -n; } nb = bitsDecoded[position]; var pos = interleave ? levelOffset + (offset << 1) : offset; if (reversible && nb >= mb) { coefficients[pos] = n; } else { coefficients[pos] = n * (1 << mb - nb); } } offset++; position++; } offset += width - blockWidth; } } } function transformTile(context, tile, c) { var component = tile.components[c]; var codingStyleParameters = component.codingStyleParameters; var quantizationParameters = component.quantizationParameters; var decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount; var spqcds = quantizationParameters.SPqcds; var scalarExpounded = quantizationParameters.scalarExpounded; var guardBits = quantizationParameters.guardBits; var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed; var precision = context.components[c].precision; var reversible = codingStyleParameters.reversibleTransformation; var transform = reversible ? new ReversibleTransform() : new IrreversibleTransform(); var subbandCoefficients = []; var b = 0; for (var i = 0; i <= decompositionLevelsCount; i++) { var resolution = component.resolutions[i]; var width = resolution.trx1 - resolution.trx0; var height = resolution.try1 - resolution.try0; var coefficients = new Float32Array(width * height); for (var j = 0, jj = resolution.subbands.length; j < jj; j++) { var mu, epsilon; if (!scalarExpounded) { mu = spqcds[0].mu; epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0); } else { mu = spqcds[b].mu; epsilon = spqcds[b].epsilon; b++; } var subband = resolution.subbands[j]; var gainLog2 = SubbandsGainLog2[subband.type]; var delta = reversible ? 1 : Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048); var mb = guardBits + epsilon - 1; copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed); } subbandCoefficients.push({ width: width, height: height, items: coefficients }); } var result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0); return { left: component.tcx0, top: component.tcy0, width: result.width, height: result.height, items: result.items }; } function transformComponents(context) { var siz = context.SIZ; var components = context.components; var componentsCount = siz.Csiz; var resultImages = []; for (var i = 0, ii = context.tiles.length; i < ii; i++) { var tile = context.tiles[i]; var transformedTiles = []; var c; for (c = 0; c < componentsCount; c++) { transformedTiles[c] = transformTile(context, tile, c); } var tile0 = transformedTiles[0]; var out = new Uint8Array(tile0.items.length * componentsCount); var result = { left: tile0.left, top: tile0.top, width: tile0.width, height: tile0.height, items: out }; var shift, offset, max, min, maxK; var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val; if (tile.codingStyleDefaultParameters.multipleComponentTransform) { var fourComponents = componentsCount === 4; var y0items = transformedTiles[0].items; var y1items = transformedTiles[1].items; var y2items = transformedTiles[2].items; var y3items = fourComponents ? transformedTiles[3].items : null; shift = components[0].precision - 8; offset = (128 << shift) + 0.5; max = 255 * (1 << shift); maxK = max * 0.5; min = -maxK; var component0 = tile.components[0]; var alpha01 = componentsCount - 3; jj = y0items.length; if (!component0.codingStyleParameters.reversibleTransformation) { for (j = 0; j < jj; j++, pos += alpha01) { y0 = y0items[j] + offset; y1 = y1items[j]; y2 = y2items[j]; r = y0 + 1.402 * y2; g = y0 - 0.34413 * y1 - 0.71414 * y2; b = y0 + 1.772 * y1; out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift; out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift; out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift; } } else { for (j = 0; j < jj; j++, pos += alpha01) { y0 = y0items[j] + offset; y1 = y1items[j]; y2 = y2items[j]; g = y0 - (y2 + y1 >> 2); r = g + y2; b = g + y1; out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift; out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift; out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift; } } if (fourComponents) { for (j = 0, pos = 3; j < jj; j++, pos += 4) { k = y3items[j]; out[pos] = k <= min ? 0 : k >= maxK ? 255 : k + offset >> shift; } } } else { for (c = 0; c < componentsCount; c++) { var items = transformedTiles[c].items; shift = components[c].precision - 8; offset = (128 << shift) + 0.5; max = 127.5 * (1 << shift); min = -max; for (pos = c, j = 0, jj = items.length; j < jj; j++) { val = items[j]; out[pos] = val <= min ? 0 : val >= max ? 255 : val + offset >> shift; pos += componentsCount; } } } resultImages.push(result); } return resultImages; } function initializeTile(context, tileIndex) { var siz = context.SIZ; var componentsCount = siz.Csiz; var tile = context.tiles[tileIndex]; for (var c = 0; c < componentsCount; c++) { var component = tile.components[c]; var qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD; component.quantizationParameters = qcdOrQcc; var codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD; component.codingStyleParameters = codOrCoc; } tile.codingStyleDefaultParameters = context.currentTile.COD; } var TagTree = function TagTreeClosure() { function TagTree(width, height) { var levelsLength = log2(Math.max(width, height)) + 1; this.levels = []; for (var i = 0; i < levelsLength; i++) { var level = { width: width, height: height, items: [] }; this.levels.push(level); width = Math.ceil(width / 2); height = Math.ceil(height / 2); } } TagTree.prototype = { reset: function TagTree_reset(i, j) { var currentLevel = 0, value = 0, level; while (currentLevel < this.levels.length) { level = this.levels[currentLevel]; var index = i + j * level.width; if (level.items[index] !== undefined) { value = level.items[index]; break; } level.index = index; i >>= 1; j >>= 1; currentLevel++; } currentLevel--; level = this.levels[currentLevel]; level.items[level.index] = value; this.currentLevel = currentLevel; delete this.value; }, incrementValue: function TagTree_incrementValue() { var level = this.levels[this.currentLevel]; level.items[level.index]++; }, nextLevel: function TagTree_nextLevel() { var currentLevel = this.currentLevel; var level = this.levels[currentLevel]; var value = level.items[level.index]; currentLevel--; if (currentLevel < 0) { this.value = value; return false; } this.currentLevel = currentLevel; level = this.levels[currentLevel]; level.items[level.index] = value; return true; } }; return TagTree; }(); var InclusionTree = function InclusionTreeClosure() { function InclusionTree(width, height, defaultValue) { var levelsLength = log2(Math.max(width, height)) + 1; this.levels = []; for (var i = 0; i < levelsLength; i++) { var items = new Uint8Array(width * height); for (var j = 0, jj = items.length; j < jj; j++) { items[j] = defaultValue; } var level = { width: width, height: height, items: items }; this.levels.push(level); width = Math.ceil(width / 2); height = Math.ceil(height / 2); } } InclusionTree.prototype = { reset: function InclusionTree_reset(i, j, stopValue) { var currentLevel = 0; while (currentLevel < this.levels.length) { var level = this.levels[currentLevel]; var index = i + j * level.width; level.index = index; var value = level.items[index]; if (value === 0xFF) { break; } if (value > stopValue) { this.currentLevel = currentLevel; this.propagateValues(); return false; } i >>= 1; j >>= 1; currentLevel++; } this.currentLevel = currentLevel - 1; return true; }, incrementValue: function InclusionTree_incrementValue(stopValue) { var level = this.levels[this.currentLevel]; level.items[level.index] = stopValue + 1; this.propagateValues(); }, propagateValues: function InclusionTree_propagateValues() { var levelIndex = this.currentLevel; var level = this.levels[levelIndex]; var currentValue = level.items[level.index]; while (--levelIndex >= 0) { level = this.levels[levelIndex]; level.items[level.index] = currentValue; } }, nextLevel: function InclusionTree_nextLevel() { var currentLevel = this.currentLevel; var level = this.levels[currentLevel]; var value = level.items[level.index]; level.items[level.index] = 0xFF; currentLevel--; if (currentLevel < 0) { return false; } this.currentLevel = currentLevel; level = this.levels[currentLevel]; level.items[level.index] = value; return true; } }; return InclusionTree; }(); var BitModel = function BitModelClosure() { var UNIFORM_CONTEXT = 17; var RUNLENGTH_CONTEXT = 18; var LLAndLHContextsLabel = new Uint8Array([0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8]); var HLContextLabel = new Uint8Array([0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8]); var HHContextLabel = new Uint8Array([0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8]); function BitModel(width, height, subband, zeroBitPlanes, mb) { this.width = width; this.height = height; this.contextLabelTable = subband === 'HH' ? HHContextLabel : subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel; var coefficientCount = width * height; this.neighborsSignificance = new Uint8Array(coefficientCount); this.coefficentsSign = new Uint8Array(coefficientCount); this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) : mb > 6 ? new Uint16Array(coefficientCount) : new Uint8Array(coefficientCount); this.processingFlags = new Uint8Array(coefficientCount); var bitsDecoded = new Uint8Array(coefficientCount); if (zeroBitPlanes !== 0) { for (var i = 0; i < coefficientCount; i++) { bitsDecoded[i] = zeroBitPlanes; } } this.bitsDecoded = bitsDecoded; this.reset(); } BitModel.prototype = { setDecoder: function BitModel_setDecoder(decoder) { this.decoder = decoder; }, reset: function BitModel_reset() { this.contexts = new Int8Array(19); this.contexts[0] = 4 << 1 | 0; this.contexts[UNIFORM_CONTEXT] = 46 << 1 | 0; this.contexts[RUNLENGTH_CONTEXT] = 3 << 1 | 0; }, setNeighborsSignificance: function BitModel_setNeighborsSignificance(row, column, index) { var neighborsSignificance = this.neighborsSignificance; var width = this.width, height = this.height; var left = column > 0; var right = column + 1 < width; var i; if (row > 0) { i = index - width; if (left) { neighborsSignificance[i - 1] += 0x10; } if (right) { neighborsSignificance[i + 1] += 0x10; } neighborsSignificance[i] += 0x04; } if (row + 1 < height) { i = index + width; if (left) { neighborsSignificance[i - 1] += 0x10; } if (right) { neighborsSignificance[i + 1] += 0x10; } neighborsSignificance[i] += 0x04; } if (left) { neighborsSignificance[index - 1] += 0x01; } if (right) { neighborsSignificance[index + 1] += 0x01; } neighborsSignificance[index] |= 0x80; }, runSignificancePropagationPass: function BitModel_runSignificancePropagationPass() { var decoder = this.decoder; var width = this.width, height = this.height; var coefficentsMagnitude = this.coefficentsMagnitude; var coefficentsSign = this.coefficentsSign; var neighborsSignificance = this.neighborsSignificance; var processingFlags = this.processingFlags; var contexts = this.contexts; var labels = this.contextLabelTable; var bitsDecoded = this.bitsDecoded; var processedInverseMask = ~1; var processedMask = 1; var firstMagnitudeBitMask = 2; for (var i0 = 0; i0 < height; i0 += 4) { for (var j = 0; j < width; j++) { var index = i0 * width + j; for (var i1 = 0; i1 < 4; i1++, index += width) { var i = i0 + i1; if (i >= height) { break; } processingFlags[index] &= processedInverseMask; if (coefficentsMagnitude[index] || !neighborsSignificance[index]) { continue; } var contextLabel = labels[neighborsSignificance[index]]; var decision = decoder.readBit(contexts, contextLabel); if (decision) { var sign = this.decodeSignBit(i, j, index); coefficentsSign[index] = sign; coefficentsMagnitude[index] = 1; this.setNeighborsSignificance(i, j, index); processingFlags[index] |= firstMagnitudeBitMask; } bitsDecoded[index]++; processingFlags[index] |= processedMask; } } } }, decodeSignBit: function BitModel_decodeSignBit(row, column, index) { var width = this.width, height = this.height; var coefficentsMagnitude = this.coefficentsMagnitude; var coefficentsSign = this.coefficentsSign; var contribution, sign0, sign1, significance1; var contextLabel, decoded; significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0; if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) { sign1 = coefficentsSign[index + 1]; if (significance1) { sign0 = coefficentsSign[index - 1]; contribution = 1 - sign1 - sign0; } else { contribution = 1 - sign1 - sign1; } } else if (significance1) { sign0 = coefficentsSign[index - 1]; contribution = 1 - sign0 - sign0; } else { contribution = 0; } var horizontalContribution = 3 * contribution; significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0; if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) { sign1 = coefficentsSign[index + width]; if (significance1) { sign0 = coefficentsSign[index - width]; contribution = 1 - sign1 - sign0 + horizontalContribution; } else { contribution = 1 - sign1 - sign1 + horizontalContribution; } } else if (significance1) { sign0 = coefficentsSign[index - width]; contribution = 1 - sign0 - sign0 + horizontalContribution; } else { contribution = horizontalContribution; } if (contribution >= 0) { contextLabel = 9 + contribution; decoded = this.decoder.readBit(this.contexts, contextLabel); } else { contextLabel = 9 - contribution; decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1; } return decoded; }, runMagnitudeRefinementPass: function BitModel_runMagnitudeRefinementPass() { var decoder = this.decoder; var width = this.width, height = this.height; var coefficentsMagnitude = this.coefficentsMagnitude; var neighborsSignificance = this.neighborsSignificance; var contexts = this.contexts; var bitsDecoded = this.bitsDecoded; var processingFlags = this.processingFlags; var processedMask = 1; var firstMagnitudeBitMask = 2; var length = width * height; var width4 = width * 4; for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) { indexNext = Math.min(length, index0 + width4); for (var j = 0; j < width; j++) { for (var index = index0 + j; index < indexNext; index += width) { if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) { continue; } var contextLabel = 16; if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) { processingFlags[index] ^= firstMagnitudeBitMask; var significance = neighborsSignificance[index] & 127; contextLabel = significance === 0 ? 15 : 14; } var bit = decoder.readBit(contexts, contextLabel); coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit; bitsDecoded[index]++; processingFlags[index] |= processedMask; } } } }, runCleanupPass: function BitModel_runCleanupPass() { var decoder = this.decoder; var width = this.width, height = this.height; var neighborsSignificance = this.neighborsSignificance; var coefficentsMagnitude = this.coefficentsMagnitude; var coefficentsSign = this.coefficentsSign; var contexts = this.contexts; var labels = this.contextLabelTable; var bitsDecoded = this.bitsDecoded; var processingFlags = this.processingFlags; var processedMask = 1; var firstMagnitudeBitMask = 2; var oneRowDown = width; var twoRowsDown = width * 2; var threeRowsDown = width * 3; var iNext; for (var i0 = 0; i0 < height; i0 = iNext) { iNext = Math.min(i0 + 4, height); var indexBase = i0 * width; var checkAllEmpty = i0 + 3 < height; for (var j = 0; j < width; j++) { var index0 = indexBase + j; var allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && processingFlags[index0 + twoRowsDown] === 0 && processingFlags[index0 + threeRowsDown] === 0 && neighborsSignificance[index0] === 0 && neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0; var i1 = 0, index = index0; var i = i0, sign; if (allEmpty) { var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT); if (!hasSignificantCoefficent) { bitsDecoded[index0]++; bitsDecoded[index0 + oneRowDown]++; bitsDecoded[index0 + twoRowsDown]++; bitsDecoded[index0 + threeRowsDown]++; continue; } i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT); if (i1 !== 0) { i = i0 + i1; index += i1 * width; } sign = this.decodeSignBit(i, j, index); coefficentsSign[index] = sign; coefficentsMagnitude[index] = 1; this.setNeighborsSignificance(i, j, index); processingFlags[index] |= firstMagnitudeBitMask; index = index0; for (var i2 = i0; i2 <= i; i2++, index += width) { bitsDecoded[index]++; } i1++; } for (i = i0 + i1; i < iNext; i++, index += width) { if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) { continue; } var contextLabel = labels[neighborsSignificance[index]]; var decision = decoder.readBit(contexts, contextLabel); if (decision === 1) { sign = this.decodeSignBit(i, j, index); coefficentsSign[index] = sign; coefficentsMagnitude[index] = 1; this.setNeighborsSignificance(i, j, index); processingFlags[index] |= firstMagnitudeBitMask; } bitsDecoded[index]++; } } } }, checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() { var decoder = this.decoder; var contexts = this.contexts; var symbol = decoder.readBit(contexts, UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT); if (symbol !== 0xA) { error('JPX Error: Invalid segmentation symbol'); } } }; return BitModel; }(); var Transform = function TransformClosure() { function Transform() {} Transform.prototype.calculate = function transformCalculate(subbands, u0, v0) { var ll = subbands[0]; for (var i = 1, ii = subbands.length; i < ii; i++) { ll = this.iterate(ll, subbands[i], u0, v0); } return ll; }; Transform.prototype.extend = function extend(buffer, offset, size) { var i1 = offset - 1, j1 = offset + 1; var i2 = offset + size - 2, j2 = offset + size; buffer[i1--] = buffer[j1++]; buffer[j2++] = buffer[i2--]; buffer[i1--] = buffer[j1++]; buffer[j2++] = buffer[i2--]; buffer[i1--] = buffer[j1++]; buffer[j2++] = buffer[i2--]; buffer[i1] = buffer[j1]; buffer[j2] = buffer[i2]; }; Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh, u0, v0) { var llWidth = ll.width, llHeight = ll.height, llItems = ll.items; var width = hl_lh_hh.width; var height = hl_lh_hh.height; var items = hl_lh_hh.items; var i, j, k, l, u, v; for (k = 0, i = 0; i < llHeight; i++) { l = i * 2 * width; for (j = 0; j < llWidth; j++, k++, l += 2) { items[l] = llItems[k]; } } llItems = ll.items = null; var bufferPadding = 4; var rowBuffer = new Float32Array(width + 2 * bufferPadding); if (width === 1) { if ((u0 & 1) !== 0) { for (v = 0, k = 0; v < height; v++, k += width) { items[k] *= 0.5; } } } else { for (v = 0, k = 0; v < height; v++, k += width) { rowBuffer.set(items.subarray(k, k + width), bufferPadding); this.extend(rowBuffer, bufferPadding, width); this.filter(rowBuffer, bufferPadding, width); items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k); } } var numBuffers = 16; var colBuffers = []; for (i = 0; i < numBuffers; i++) { colBuffers.push(new Float32Array(height + 2 * bufferPadding)); } var b, currentBuffer = 0; ll = bufferPadding + height; if (height === 1) { if ((v0 & 1) !== 0) { for (u = 0; u < width; u++) { items[u] *= 0.5; } } } else { for (u = 0; u < width; u++) { if (currentBuffer === 0) { numBuffers = Math.min(width - u, numBuffers); for (k = u, l = bufferPadding; l < ll; k += width, l++) { for (b = 0; b < numBuffers; b++) { colBuffers[b][l] = items[k + b]; } } currentBuffer = numBuffers; } currentBuffer--; var buffer = colBuffers[currentBuffer]; this.extend(buffer, bufferPadding, height); this.filter(buffer, bufferPadding, height); if (currentBuffer === 0) { k = u - numBuffers + 1; for (l = bufferPadding; l < ll; k += width, l++) { for (b = 0; b < numBuffers; b++) { items[k + b] = colBuffers[b][l]; } } } } } return { width: width, height: height, items: items }; }; return Transform; }(); var IrreversibleTransform = function IrreversibleTransformClosure() { function IrreversibleTransform() { Transform.call(this); } IrreversibleTransform.prototype = Object.create(Transform.prototype); IrreversibleTransform.prototype.filter = function irreversibleTransformFilter(x, offset, length) { var len = length >> 1; offset = offset | 0; var j, n, current, next; var alpha = -1.586134342059924; var beta = -0.052980118572961; var gamma = 0.882911075530934; var delta = 0.443506852043971; var K = 1.230174104914001; var K_ = 1 / K; j = offset - 3; for (n = len + 4; n--; j += 2) { x[j] *= K_; } j = offset - 2; current = delta * x[j - 1]; for (n = len + 3; n--; j += 2) { next = delta * x[j + 1]; x[j] = K * x[j] - current - next; if (n--) { j += 2; current = delta * x[j + 1]; x[j] = K * x[j] - current - next; } else { break; } } j = offset - 1; current = gamma * x[j - 1]; for (n = len + 2; n--; j += 2) { next = gamma * x[j + 1]; x[j] -= current + next; if (n--) { j += 2; current = gamma * x[j + 1]; x[j] -= current + next; } else { break; } } j = offset; current = beta * x[j - 1]; for (n = len + 1; n--; j += 2) { next = beta * x[j + 1]; x[j] -= current + next; if (n--) { j += 2; current = beta * x[j + 1]; x[j] -= current + next; } else { break; } } if (len !== 0) { j = offset + 1; current = alpha * x[j - 1]; for (n = len; n--; j += 2) { next = alpha * x[j + 1]; x[j] -= current + next; if (n--) { j += 2; current = alpha * x[j + 1]; x[j] -= current + next; } else { break; } } } }; return IrreversibleTransform; }(); var ReversibleTransform = function ReversibleTransformClosure() { function ReversibleTransform() { Transform.call(this); } ReversibleTransform.prototype = Object.create(Transform.prototype); ReversibleTransform.prototype.filter = function reversibleTransformFilter(x, offset, length) { var len = length >> 1; offset = offset | 0; var j, n; for (j = offset, n = len + 1; n--; j += 2) { x[j] -= x[j - 1] + x[j + 1] + 2 >> 2; } for (j = offset + 1, n = len; n--; j += 2) { x[j] += x[j - 1] + x[j + 1] >> 1; } }; return ReversibleTransform; }(); return JpxImage; }(); "use strict"; var Jbig2Image = function Jbig2ImageClosure() { function ContextCache() {} ContextCache.prototype = { getContexts: function (id) { if (id in this) { return this[id]; } return this[id] = new Int8Array(1 << 16); } }; function DecodingContext(data, start, end) { this.data = data; this.start = start; this.end = end; } DecodingContext.prototype = { get decoder() { var decoder = new ArithmeticDecoder(this.data, this.start, this.end); return shadow(this, 'decoder', decoder); }, get contextCache() { var cache = new ContextCache(); return shadow(this, 'contextCache', cache); } }; function decodeInteger(contextCache, procedure, decoder) { var contexts = contextCache.getContexts(procedure); var prev = 1; function readBits(length) { var v = 0; for (var i = 0; i < length; i++) { var bit = decoder.readBit(contexts, prev); prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256; v = v << 1 | bit; } return v >>> 0; } var sign = readBits(1); var value = readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(32) + 4436 : readBits(12) + 340 : readBits(8) + 84 : readBits(6) + 20 : readBits(4) + 4 : readBits(2); return sign === 0 ? value : value > 0 ? -value : null; } function decodeIAID(contextCache, decoder, codeLength) { var contexts = contextCache.getContexts('IAID'); var prev = 1; for (var i = 0; i < codeLength; i++) { var bit = decoder.readBit(contexts, prev); prev = prev << 1 | bit; } if (codeLength < 31) { return prev & (1 << codeLength) - 1; } return prev & 0x7FFFFFFF; } var SegmentTypes = ['SymbolDictionary', null, null, null, 'IntermediateTextRegion', null, 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null, null, null, null, null, null, 'patternDictionary', null, null, null, 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion', 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null, null, null, null, null, null, 'IntermediateGenericRegion', null, 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion', 'IntermediateGenericRefinementRegion', null, 'ImmediateGenericRefinementRegion', 'ImmediateLosslessGenericRefinementRegion', null, null, null, null, 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles', 'Tables', null, null, null, null, null, null, null, null, 'Extension']; var CodingTemplates = [[{ x: -1, y: -2 }, { x: 0, y: -2 }, { x: 1, y: -2 }, { x: -2, y: -1 }, { x: -1, y: -1 }, { x: 0, y: -1 }, { x: 1, y: -1 }, { x: 2, y: -1 }, { x: -4, y: 0 }, { x: -3, y: 0 }, { x: -2, y: 0 }, { x: -1, y: 0 }], [{ x: -1, y: -2 }, { x: 0, y: -2 }, { x: 1, y: -2 }, { x: 2, y: -2 }, { x: -2, y: -1 }, { x: -1, y: -1 }, { x: 0, y: -1 }, { x: 1, y: -1 }, { x: 2, y: -1 }, { x: -3, y: 0 }, { x: -2, y: 0 }, { x: -1, y: 0 }], [{ x: -1, y: -2 }, { x: 0, y: -2 }, { x: 1, y: -2 }, { x: -2, y: -1 }, { x: -1, y: -1 }, { x: 0, y: -1 }, { x: 1, y: -1 }, { x: -2, y: 0 }, { x: -1, y: 0 }], [{ x: -3, y: -1 }, { x: -2, y: -1 }, { x: -1, y: -1 }, { x: 0, y: -1 }, { x: 1, y: -1 }, { x: -4, y: 0 }, { x: -3, y: 0 }, { x: -2, y: 0 }, { x: -1, y: 0 }]]; var RefinementTemplates = [{ coding: [{ x: 0, y: -1 }, { x: 1, y: -1 }, { x: -1, y: 0 }], reference: [{ x: 0, y: -1 }, { x: 1, y: -1 }, { x: -1, y: 0 }, { x: 0, y: 0 }, { x: 1, y: 0 }, { x: -1, y: 1 }, { x: 0, y: 1 }, { x: 1, y: 1 }] }, { coding: [{ x: -1, y: -1 }, { x: 0, y: -1 }, { x: 1, y: -1 }, { x: -1, y: 0 }], reference: [{ x: 0, y: -1 }, { x: -1, y: 0 }, { x: 0, y: 0 }, { x: 1, y: 0 }, { x: 0, y: 1 }, { x: 1, y: 1 }] }]; var ReusedContexts = [0x9B25, 0x0795, 0x00E5, 0x0195]; var RefinementReusedContexts = [0x0020, 0x0008]; function decodeBitmapTemplate0(width, height, decodingContext) { var decoder = decodingContext.decoder; var contexts = decodingContext.contextCache.getContexts('GB'); var contextLabel, i, j, pixel, row, row1, row2, bitmap = []; var OLD_PIXEL_MASK = 0x7BF7; for (i = 0; i < height; i++) { row = bitmap[i] = new Uint8Array(width); row1 = i < 1 ? row : bitmap[i - 1]; row2 = i < 2 ? row : bitmap[i - 2]; contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4; for (j = 0; j < width; j++) { row[j] = pixel = decoder.readBit(contexts, contextLabel); contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel; } } return bitmap; } function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) { if (mmr) { error('JBIG2 error: MMR encoding is not supported'); } if (templateIndex === 0 && !skip && !prediction && at.length === 4 && at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 && at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) { return decodeBitmapTemplate0(width, height, decodingContext); } var useskip = !!skip; var template = CodingTemplates[templateIndex].concat(at); template.sort(function (a, b) { return a.y - b.y || a.x - b.x; }); var templateLength = template.length; var templateX = new Int8Array(templateLength); var templateY = new Int8Array(templateLength); var changingTemplateEntries = []; var reuseMask = 0, minX = 0, maxX = 0, minY = 0; var c, k; for (k = 0; k < templateLength; k++) { templateX[k] = template[k].x; templateY[k] = template[k].y; minX = Math.min(minX, template[k].x); maxX = Math.max(maxX, template[k].x); minY = Math.min(minY, template[k].y); if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) { reuseMask |= 1 << templateLength - 1 - k; } else { changingTemplateEntries.push(k); } } var changingEntriesLength = changingTemplateEntries.length; var changingTemplateX = new Int8Array(changingEntriesLength); var changingTemplateY = new Int8Array(changingEntriesLength); var changingTemplateBit = new Uint16Array(changingEntriesLength); for (c = 0; c < changingEntriesLength; c++) { k = changingTemplateEntries[c]; changingTemplateX[c] = template[k].x; changingTemplateY[c] = template[k].y; changingTemplateBit[c] = 1 << templateLength - 1 - k; } var sbb_left = -minX; var sbb_top = -minY; var sbb_right = width - maxX; var pseudoPixelContext = ReusedContexts[templateIndex]; var row = new Uint8Array(width); var bitmap = []; var decoder = decodingContext.decoder; var contexts = decodingContext.contextCache.getContexts('GB'); var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift; for (var i = 0; i < height; i++) { if (prediction) { var sltp = decoder.readBit(contexts, pseudoPixelContext); ltp ^= sltp; if (ltp) { bitmap.push(row); continue; } } row = new Uint8Array(row); bitmap.push(row); for (j = 0; j < width; j++) { if (useskip && skip[i][j]) { row[j] = 0; continue; } if (j >= sbb_left && j < sbb_right && i >= sbb_top) { contextLabel = contextLabel << 1 & reuseMask; for (k = 0; k < changingEntriesLength; k++) { i0 = i + changingTemplateY[k]; j0 = j + changingTemplateX[k]; bit = bitmap[i0][j0]; if (bit) { bit = changingTemplateBit[k]; contextLabel |= bit; } } } else { contextLabel = 0; shift = templateLength - 1; for (k = 0; k < templateLength; k++, shift--) { j0 = j + templateX[k]; if (j0 >= 0 && j0 < width) { i0 = i + templateY[k]; if (i0 >= 0) { bit = bitmap[i0][j0]; if (bit) { contextLabel |= bit << shift; } } } } } var pixel = decoder.readBit(contexts, contextLabel); row[j] = pixel; } } return bitmap; } function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) { var codingTemplate = RefinementTemplates[templateIndex].coding; if (templateIndex === 0) { codingTemplate = codingTemplate.concat([at[0]]); } var codingTemplateLength = codingTemplate.length; var codingTemplateX = new Int32Array(codingTemplateLength); var codingTemplateY = new Int32Array(codingTemplateLength); var k; for (k = 0; k < codingTemplateLength; k++) { codingTemplateX[k] = codingTemplate[k].x; codingTemplateY[k] = codingTemplate[k].y; } var referenceTemplate = RefinementTemplates[templateIndex].reference; if (templateIndex === 0) { referenceTemplate = referenceTemplate.concat([at[1]]); } var referenceTemplateLength = referenceTemplate.length; var referenceTemplateX = new Int32Array(referenceTemplateLength); var referenceTemplateY = new Int32Array(referenceTemplateLength); for (k = 0; k < referenceTemplateLength; k++) { referenceTemplateX[k] = referenceTemplate[k].x; referenceTemplateY[k] = referenceTemplate[k].y; } var referenceWidth = referenceBitmap[0].length; var referenceHeight = referenceBitmap.length; var pseudoPixelContext = RefinementReusedContexts[templateIndex]; var bitmap = []; var decoder = decodingContext.decoder; var contexts = decodingContext.contextCache.getContexts('GR'); var ltp = 0; for (var i = 0; i < height; i++) { if (prediction) { var sltp = decoder.readBit(contexts, pseudoPixelContext); ltp ^= sltp; if (ltp) { error('JBIG2 error: prediction is not supported'); } } var row = new Uint8Array(width); bitmap.push(row); for (var j = 0; j < width; j++) { var i0, j0; var contextLabel = 0; for (k = 0; k < codingTemplateLength; k++) { i0 = i + codingTemplateY[k]; j0 = j + codingTemplateX[k]; if (i0 < 0 || j0 < 0 || j0 >= width) { contextLabel <<= 1; } else { contextLabel = contextLabel << 1 | bitmap[i0][j0]; } } for (k = 0; k < referenceTemplateLength; k++) { i0 = i + referenceTemplateY[k] + offsetY; j0 = j + referenceTemplateX[k] + offsetX; if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) { contextLabel <<= 1; } else { contextLabel = contextLabel << 1 | referenceBitmap[i0][j0]; } } var pixel = decoder.readBit(contexts, contextLabel); row[j] = pixel; } } return bitmap; } function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext) { if (huffman) { error('JBIG2 error: huffman is not supported'); } var newSymbols = []; var currentHeight = 0; var symbolCodeLength = log2(symbols.length + numberOfNewSymbols); var decoder = decodingContext.decoder; var contextCache = decodingContext.contextCache; while (newSymbols.length < numberOfNewSymbols) { var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); currentHeight += deltaHeight; var currentWidth = 0; while (true) { var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); if (deltaWidth === null) { break; } currentWidth += deltaWidth; var bitmap; if (refinement) { var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder); if (numberOfInstances > 1) { bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, symbols.concat(newSymbols), symbolCodeLength, 0, 0, 1, 0, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext); } else { var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength); var rdx = decodeInteger(contextCache, 'IARDX', decoder); var rdy = decodeInteger(contextCache, 'IARDY', decoder); var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length]; bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext); } } else { bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext); } newSymbols.push(bitmap); } } var exportedSymbols = []; var flags = [], currentFlag = false; var totalSymbolsLength = symbols.length + numberOfNewSymbols; while (flags.length < totalSymbolsLength) { var runLength = decodeInteger(contextCache, 'IAEX', decoder); while (runLength--) { flags.push(currentFlag); } currentFlag = !currentFlag; } for (var i = 0, ii = symbols.length; i < ii; i++) { if (flags[i]) { exportedSymbols.push(symbols[i]); } } for (var j = 0; j < numberOfNewSymbols; i++, j++) { if (flags[i]) { exportedSymbols.push(newSymbols[j]); } } return exportedSymbols; } function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext) { if (huffman) { error('JBIG2 error: huffman is not supported'); } var bitmap = []; var i, row; for (i = 0; i < height; i++) { row = new Uint8Array(width); if (defaultPixelValue) { for (var j = 0; j < width; j++) { row[j] = defaultPixelValue; } } bitmap.push(row); } var decoder = decodingContext.decoder; var contextCache = decodingContext.contextCache; var stripT = -decodeInteger(contextCache, 'IADT', decoder); var firstS = 0; i = 0; while (i < numberOfSymbolInstances) { var deltaT = decodeInteger(contextCache, 'IADT', decoder); stripT += deltaT; var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); firstS += deltaFirstS; var currentS = firstS; do { var currentT = stripSize === 1 ? 0 : decodeInteger(contextCache, 'IAIT', decoder); var t = stripSize * stripT + currentT; var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength); var applyRefinement = refinement && decodeInteger(contextCache, 'IARI', decoder); var symbolBitmap = inputSymbols[symbolId]; var symbolWidth = symbolBitmap[0].length; var symbolHeight = symbolBitmap.length; if (applyRefinement) { var rdw = decodeInteger(contextCache, 'IARDW', decoder); var rdh = decodeInteger(contextCache, 'IARDH', decoder); var rdx = decodeInteger(contextCache, 'IARDX', decoder); var rdy = decodeInteger(contextCache, 'IARDY', decoder); symbolWidth += rdw; symbolHeight += rdh; symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext); } var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight); var offsetS = currentS - (referenceCorner & 2 ? symbolWidth : 0); var s2, t2, symbolRow; if (transposed) { for (s2 = 0; s2 < symbolHeight; s2++) { row = bitmap[offsetS + s2]; if (!row) { continue; } symbolRow = symbolBitmap[s2]; var maxWidth = Math.min(width - offsetT, symbolWidth); switch (combinationOperator) { case 0: for (t2 = 0; t2 < maxWidth; t2++) { row[offsetT + t2] |= symbolRow[t2]; } break; case 2: for (t2 = 0; t2 < maxWidth; t2++) { row[offsetT + t2] ^= symbolRow[t2]; } break; default: error('JBIG2 error: operator ' + combinationOperator + ' is not supported'); } } currentS += symbolHeight - 1; } else { for (t2 = 0; t2 < symbolHeight; t2++) { row = bitmap[offsetT + t2]; if (!row) { continue; } symbolRow = symbolBitmap[t2]; switch (combinationOperator) { case 0: for (s2 = 0; s2 < symbolWidth; s2++) { row[offsetS + s2] |= symbolRow[s2]; } break; case 2: for (s2 = 0; s2 < symbolWidth; s2++) { row[offsetS + s2] ^= symbolRow[s2]; } break; default: error('JBIG2 error: operator ' + combinationOperator + ' is not supported'); } } currentS += symbolWidth - 1; } i++; var deltaS = decodeInteger(contextCache, 'IADS', decoder); if (deltaS === null) { break; } currentS += deltaS + dsOffset; } while (true); } return bitmap; } function readSegmentHeader(data, start) { var segmentHeader = {}; segmentHeader.number = readUint32(data, start); var flags = data[start + 4]; var segmentType = flags & 0x3F; if (!SegmentTypes[segmentType]) { error('JBIG2 error: invalid segment type: ' + segmentType); } segmentHeader.type = segmentType; segmentHeader.typeName = SegmentTypes[segmentType]; segmentHeader.deferredNonRetain = !!(flags & 0x80); var pageAssociationFieldSize = !!(flags & 0x40); var referredFlags = data[start + 5]; var referredToCount = referredFlags >> 5 & 7; var retainBits = [referredFlags & 31]; var position = start + 6; if (referredFlags === 7) { referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF; position += 3; var bytes = referredToCount + 7 >> 3; retainBits[0] = data[position++]; while (--bytes > 0) { retainBits.push(data[position++]); } } else if (referredFlags === 5 || referredFlags === 6) { error('JBIG2 error: invalid referred-to flags'); } segmentHeader.retainBits = retainBits; var referredToSegmentNumberSize = segmentHeader.number <= 256 ? 1 : segmentHeader.number <= 65536 ? 2 : 4; var referredTo = []; var i, ii; for (i = 0; i < referredToCount; i++) { var number = referredToSegmentNumberSize === 1 ? data[position] : referredToSegmentNumberSize === 2 ? readUint16(data, position) : readUint32(data, position); referredTo.push(number); position += referredToSegmentNumberSize; } segmentHeader.referredTo = referredTo; if (!pageAssociationFieldSize) { segmentHeader.pageAssociation = data[position++]; } else { segmentHeader.pageAssociation = readUint32(data, position); position += 4; } segmentHeader.length = readUint32(data, position); position += 4; if (segmentHeader.length === 0xFFFFFFFF) { if (segmentType === 38) { var genericRegionInfo = readRegionSegmentInformation(data, position); var genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength]; var genericRegionMmr = !!(genericRegionSegmentFlags & 1); var searchPatternLength = 6; var searchPattern = new Uint8Array(searchPatternLength); if (!genericRegionMmr) { searchPattern[0] = 0xFF; searchPattern[1] = 0xAC; } searchPattern[2] = genericRegionInfo.height >>> 24 & 0xFF; searchPattern[3] = genericRegionInfo.height >> 16 & 0xFF; searchPattern[4] = genericRegionInfo.height >> 8 & 0xFF; searchPattern[5] = genericRegionInfo.height & 0xFF; for (i = position, ii = data.length; i < ii; i++) { var j = 0; while (j < searchPatternLength && searchPattern[j] === data[i + j]) { j++; } if (j === searchPatternLength) { segmentHeader.length = i + searchPatternLength; break; } } if (segmentHeader.length === 0xFFFFFFFF) { error('JBIG2 error: segment end was not found'); } } else { error('JBIG2 error: invalid unknown segment length'); } } segmentHeader.headerEnd = position; return segmentHeader; } function readSegments(header, data, start, end) { var segments = []; var position = start; while (position < end) { var segmentHeader = readSegmentHeader(data, position); position = segmentHeader.headerEnd; var segment = { header: segmentHeader, data: data }; if (!header.randomAccess) { segment.start = position; position += segmentHeader.length; segment.end = position; } segments.push(segment); if (segmentHeader.type === 51) { break; } } if (header.randomAccess) { for (var i = 0, ii = segments.length; i < ii; i++) { segments[i].start = position; position += segments[i].header.length; segments[i].end = position; } } return segments; } function readRegionSegmentInformation(data, start) { return { width: readUint32(data, start), height: readUint32(data, start + 4), x: readUint32(data, start + 8), y: readUint32(data, start + 12), combinationOperator: data[start + 16] & 7 }; } var RegionSegmentInformationFieldLength = 17; function processSegment(segment, visitor) { var header = segment.header; var data = segment.data, position = segment.start, end = segment.end; var args, at, i, atLength; switch (header.type) { case 0: var dictionary = {}; var dictionaryFlags = readUint16(data, position); dictionary.huffman = !!(dictionaryFlags & 1); dictionary.refinement = !!(dictionaryFlags & 2); dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3; dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3; dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1; dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1; dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256); dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512); dictionary.template = dictionaryFlags >> 10 & 3; dictionary.refinementTemplate = dictionaryFlags >> 12 & 1; position += 2; if (!dictionary.huffman) { atLength = dictionary.template === 0 ? 4 : 1; at = []; for (i = 0; i < atLength; i++) { at.push({ x: readInt8(data, position), y: readInt8(data, position + 1) }); position += 2; } dictionary.at = at; } if (dictionary.refinement && !dictionary.refinementTemplate) { at = []; for (i = 0; i < 2; i++) { at.push({ x: readInt8(data, position), y: readInt8(data, position + 1) }); position += 2; } dictionary.refinementAt = at; } dictionary.numberOfExportedSymbols = readUint32(data, position); position += 4; dictionary.numberOfNewSymbols = readUint32(data, position); position += 4; args = [dictionary, header.number, header.referredTo, data, position, end]; break; case 6: case 7: var textRegion = {}; textRegion.info = readRegionSegmentInformation(data, position); position += RegionSegmentInformationFieldLength; var textRegionSegmentFlags = readUint16(data, position); position += 2; textRegion.huffman = !!(textRegionSegmentFlags & 1); textRegion.refinement = !!(textRegionSegmentFlags & 2); textRegion.stripSize = 1 << (textRegionSegmentFlags >> 2 & 3); textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3; textRegion.transposed = !!(textRegionSegmentFlags & 64); textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3; textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1; textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27; textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1; if (textRegion.huffman) { var textRegionHuffmanFlags = readUint16(data, position); position += 2; textRegion.huffmanFS = textRegionHuffmanFlags & 3; textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3; textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3; textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3; textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3; textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3; textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3; textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 14); } if (textRegion.refinement && !textRegion.refinementTemplate) { at = []; for (i = 0; i < 2; i++) { at.push({ x: readInt8(data, position), y: readInt8(data, position + 1) }); position += 2; } textRegion.refinementAt = at; } textRegion.numberOfSymbolInstances = readUint32(data, position); position += 4; if (textRegion.huffman) { error('JBIG2 error: huffman is not supported'); } args = [textRegion, header.referredTo, data, position, end]; break; case 38: case 39: var genericRegion = {}; genericRegion.info = readRegionSegmentInformation(data, position); position += RegionSegmentInformationFieldLength; var genericRegionSegmentFlags = data[position++]; genericRegion.mmr = !!(genericRegionSegmentFlags & 1); genericRegion.template = genericRegionSegmentFlags >> 1 & 3; genericRegion.prediction = !!(genericRegionSegmentFlags & 8); if (!genericRegion.mmr) { atLength = genericRegion.template === 0 ? 4 : 1; at = []; for (i = 0; i < atLength; i++) { at.push({ x: readInt8(data, position), y: readInt8(data, position + 1) }); position += 2; } genericRegion.at = at; } args = [genericRegion, data, position, end]; break; case 48: var pageInfo = { width: readUint32(data, position), height: readUint32(data, position + 4), resolutionX: readUint32(data, position + 8), resolutionY: readUint32(data, position + 12) }; if (pageInfo.height === 0xFFFFFFFF) { delete pageInfo.height; } var pageSegmentFlags = data[position + 16]; readUint16(data, position + 17); pageInfo.lossless = !!(pageSegmentFlags & 1); pageInfo.refinement = !!(pageSegmentFlags & 2); pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1; pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3; pageInfo.requiresBuffer = !!(pageSegmentFlags & 32); pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64); args = [pageInfo]; break; case 49: break; case 50: break; case 51: break; case 62: break; default: error('JBIG2 error: segment type ' + header.typeName + '(' + header.type + ') is not implemented'); } var callbackName = 'on' + header.typeName; if (callbackName in visitor) { visitor[callbackName].apply(visitor, args); } } function processSegments(segments, visitor) { for (var i = 0, ii = segments.length; i < ii; i++) { processSegment(segments[i], visitor); } } function parseJbig2(data, start, end) { var position = start; if (data[position] !== 0x97 || data[position + 1] !== 0x4A || data[position + 2] !== 0x42 || data[position + 3] !== 0x32 || data[position + 4] !== 0x0D || data[position + 5] !== 0x0A || data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) { error('JBIG2 error: invalid header'); } var header = {}; position += 8; var flags = data[position++]; header.randomAccess = !(flags & 1); if (!(flags & 2)) { header.numberOfPages = readUint32(data, position); position += 4; } readSegments(header, data, position, end); error('Not implemented'); } function parseJbig2Chunks(chunks) { var visitor = new SimpleSegmentVisitor(); for (var i = 0, ii = chunks.length; i < ii; i++) { var chunk = chunks[i]; var segments = readSegments({}, chunk.data, chunk.start, chunk.end); processSegments(segments, visitor); } return visitor.buffer; } function SimpleSegmentVisitor() {} SimpleSegmentVisitor.prototype = { onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) { this.currentPageInfo = info; var rowSize = info.width + 7 >> 3; var buffer = new Uint8Array(rowSize * info.height); if (info.defaultPixelValue) { for (var i = 0, ii = buffer.length; i < ii; i++) { buffer[i] = 0xFF; } } this.buffer = buffer; }, drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) { var pageInfo = this.currentPageInfo; var width = regionInfo.width, height = regionInfo.height; var rowSize = pageInfo.width + 7 >> 3; var combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator; var buffer = this.buffer; var mask0 = 128 >> (regionInfo.x & 7); var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3); var i, j, mask, offset; switch (combinationOperator) { case 0: for (i = 0; i < height; i++) { mask = mask0; offset = offset0; for (j = 0; j < width; j++) { if (bitmap[i][j]) { buffer[offset] |= mask; } mask >>= 1; if (!mask) { mask = 128; offset++; } } offset0 += rowSize; } break; case 2: for (i = 0; i < height; i++) { mask = mask0; offset = offset0; for (j = 0; j < width; j++) { if (bitmap[i][j]) { buffer[offset] ^= mask; } mask >>= 1; if (!mask) { mask = 128; offset++; } } offset0 += rowSize; } break; default: error('JBIG2 error: operator ' + combinationOperator + ' is not supported'); } }, onImmediateGenericRegion: function SimpleSegmentVisitor_onImmediateGenericRegion(region, data, start, end) { var regionInfo = region.info; var decodingContext = new DecodingContext(data, start, end); var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext); this.drawBitmap(regionInfo, bitmap); }, onImmediateLosslessGenericRegion: function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() { this.onImmediateGenericRegion.apply(this, arguments); }, onSymbolDictionary: function SimpleSegmentVisitor_onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) { var huffmanTables; if (dictionary.huffman) { error('JBIG2 error: huffman is not supported'); } var symbols = this.symbols; if (!symbols) { this.symbols = symbols = {}; } var inputSymbols = []; for (var i = 0, ii = referredSegments.length; i < ii; i++) { inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]); } var decodingContext = new DecodingContext(data, start, end); symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext); }, onImmediateTextRegion: function SimpleSegmentVisitor_onImmediateTextRegion(region, referredSegments, data, start, end) { var regionInfo = region.info; var huffmanTables; var symbols = this.symbols; var inputSymbols = []; for (var i = 0, ii = referredSegments.length; i < ii; i++) { inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]); } var symbolCodeLength = log2(inputSymbols.length); var decodingContext = new DecodingContext(data, start, end); var bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext); this.drawBitmap(regionInfo, bitmap); }, onImmediateLosslessTextRegion: function SimpleSegmentVisitor_onImmediateLosslessTextRegion() { this.onImmediateTextRegion.apply(this, arguments); } }; function Jbig2Image() {} Jbig2Image.prototype = { parseChunks: function Jbig2Image_parseChunks(chunks) { return parseJbig2Chunks(chunks); } }; return Jbig2Image; }(); function log2(x) { var n = 1, i = 0; while (x > n) { n <<= 1; i++; } return i; } function readInt8(data, start) { return data[start] << 24 >> 24; } function readUint16(data, offset) { return data[offset] << 8 | data[offset + 1]; } function readUint32(data, offset) { return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0; } function shadow(obj, prop, value) { Object.defineProperty(obj, prop, { value: value, enumerable: true, configurable: true, writable: false }); return value; } var error = function() { console.error.apply(console, arguments); throw new Error("PDFJS error: " + arguments[0]); }; var warn = function() { console.warn.apply(console, arguments); }; var info = function() { console.info.apply(console, arguments); }; Jbig2Image.prototype.parse = function parseJbig2(data) { var position = 0, end = data.length; if (data[position] !== 151 || data[position + 1] !== 74 || data[position + 2] !== 66 || data[position + 3] !== 50 || data[position + 4] !== 13 || data[position + 5] !== 10 || data[position + 6] !== 26 || data[position + 7] !== 10) { error("JBIG2 error: invalid header"); } var header = {}; position += 8; var flags = data[position++]; header.randomAccess = !(flags & 1); if (!(flags & 2)) { header.numberOfPages = readUint32(data, position); position += 4; } var visitor = this.parseChunks([ { data: data, start: position, end: end } ]); var width = visitor.currentPageInfo.width; var height = visitor.currentPageInfo.height; var bitPacked = visitor.buffer; var data = new Uint8Array(width * height); var q = 0, k = 0; for (var i = 0; i < height; i++) { var mask = 0, buffer; for (var j = 0; j < width; j++) { if (!mask) { mask = 128; buffer = bitPacked[k++]; } data[q++] = buffer & mask ? 0 : 255; mask >>= 1; } } this.width = width; this.height = height; this.data = data; }; PDFJS.JpegImage = JpegImage; PDFJS.JpxImage = JpxImage; PDFJS.Jbig2Image = Jbig2Image; })(PDFJS || (PDFJS = {})); ;(function(){var o,X=0,e=null,n=null;o=window.FFT={};var f={o:function(G){if(G!==0&&(G&G-1)===0){X=G; f.B();f.q();f.i()}else{throw new Error("init: radix-2 required")}},X:function(G,B){f.G(G,B,1)},e:function(G,B){var j=1/X; f.G(G,B,-1);for(var q=0;q>2; for(var P=0;P>1;while(q<=B){B-=q;q>>=1}B+=q;e[G]=B}},i:function(){var G=X>>1,B=X>>2,j=X>>3,q=G+B,i=Math.sin(Math.PI/X),m=2*i*i,Z=Math.sqrt(m*(2-m)),p=n[B]=1,C=n[0]=0; i=2*m;for(var a=1;an){var p=this.type===c.types.logicalOR||this.type===c.types.logicalAND,g=this.value;this.next();var k=this.start,q=this.startLoc,d=this.parseExprOp(this.parseMaybeUnary(null, !1),k,q,d,e);b=this.buildBinary(a,h,b,d,g,p);return this.parseExprOp(b,a,h,n,e)}return b};a.buildBinary=function(b,c,a,n,e,m){b=this.startNodeAt(b,c);b.left=a;b.operator=e;b.right=n;return this.finishNode(b,m?"LogicalExpression":"BinaryExpression")};a.parseMaybeUnary=function(b,a){var d=this.start,n=this.startLoc;if(this.type.prefix){var e=this.startNode();var m=this.type===c.types.incDec;e.operator=this.value;e.prefix=!0;this.next();e.argument=this.parseMaybeUnary(null,!0);this.checkExpressionErrors(b, !0);m?this.checkLVal(e.argument):this.strict&&"delete"===e.operator&&"Identifier"===e.argument.type?this.raiseRecoverable(e.start,"Deleting local variable in strict mode"):a=!0;m=this.finishNode(e,m?"UpdateExpression":"UnaryExpression")}else{m=this.parseExprSubscripts(b);if(this.checkExpressionErrors(b))return m;for(;this.type.postfix&&!this.canInsertSemicolon();)e=this.startNodeAt(d,n),e.operator=this.value,e.prefix=!1,e.argument=m,this.checkLVal(m),this.next(),m=this.finishNode(e,"UpdateExpression")}return!a&& this.eat(c.types.starstar)?this.buildBinary(d,n,m,this.parseMaybeUnary(null,!1),"**",!1):m};a.parseExprSubscripts=function(b){var c=this.start,a=this.startLoc,n=this.parseExprAtom(b),e="ArrowFunctionExpression"===n.type&&")"!==this.input.slice(this.lastTokStart,this.lastTokEnd);return this.checkExpressionErrors(b)||e?n:this.parseSubscripts(n,c,a)};a.parseSubscripts=function(b,a,h,n){for(var e;;)if(this.eat(c.types.dot))e=this.startNodeAt(a,h),e.object=b,e.property=this.parseIdent(!0),e.computed=!1, b=this.finishNode(e,"MemberExpression");else if(this.eat(c.types.bracketL))e=this.startNodeAt(a,h),e.object=b,e.property=this.parseExpression(),e.computed=!0,this.expect(c.types.bracketR),b=this.finishNode(e,"MemberExpression");else if(!n&&this.eat(c.types.parenL))e=this.startNodeAt(a,h),e.callee=b,e.arguments=this.parseExprList(c.types.parenR,!1),b=this.finishNode(e,"CallExpression");else if(this.type===c.types.backQuote)e=this.startNodeAt(a,h),e.tag=b,e.quasi=this.parseTemplate(),b=this.finishNode(e, "TaggedTemplateExpression");else return b};a.parseExprAtom=function(b){var a=this.potentialArrowAt==this.start;switch(this.type){case c.types._super:this.inFunction||this.raise(this.start,"'super' outside of function or class");case c.types._this:return b=this.type===c.types._this?"ThisExpression":"Super",a=this.startNode(),this.next(),this.finishNode(a,b);case c.types.name:b=this.start;var h=this.startLoc,n=this.parseIdent(this.type!==c.types.name);return a&&!this.canInsertSemicolon()&&this.eat(c.types.arrow)? this.parseArrowExpression(this.startNodeAt(b,h),[n]):n;case c.types.regexp:return b=this.value,a=this.parseLiteral(b.value),a.regex={pattern:b.pattern,flags:b.flags},a;case c.types.num:case c.types.string:return this.parseLiteral(this.value);case c.types._null:case c.types._true:case c.types._false:return a=this.startNode(),a.value=this.type===c.types._null?null:this.type===c.types._true,a.raw=this.type.keyword,this.next(),this.finishNode(a,"Literal");case c.types.parenL:return this.parseParenAndDistinguishExpression(a); case c.types.bracketL:return a=this.startNode(),this.next(),a.elements=this.parseExprList(c.types.bracketR,!0,!0,b),this.finishNode(a,"ArrayExpression");case c.types.braceL:return this.parseObj(!1,b);case c.types._function:return a=this.startNode(),this.next(),this.parseFunction(a,!1);case c.types._class:return this.parseClass(this.startNode(),!1);case c.types._new:return this.parseNew();case c.types.backQuote:return this.parseTemplate();default:this.unexpected()}};a.parseLiteral=function(b){var a= this.startNode();a.value=b;a.raw=this.input.slice(this.start,this.end);this.next();return this.finishNode(a,"Literal")};a.parseParenExpression=function(){this.expect(c.types.parenL);var b=this.parseExpression();this.expect(c.types.parenR);return b};a.parseParenAndDistinguishExpression=function(b){var a=this.start,h=this.startLoc;if(6<=this.options.ecmaVersion){this.next();for(var n=this.start,e=this.startLoc,m=[],p=!0,g={shorthandAssign:0,trailingComma:0},k=void 0,q=void 0;this.type!==c.types.parenR;)if(p? p=!1:this.expect(c.types.comma),this.type===c.types.ellipsis){k=this.start;m.push(this.parseParenItem(this.parseRest()));break}else this.type!==c.types.parenL||q||(q=this.start),m.push(this.parseMaybeAssign(!1,g,this.parseParenItem));var p=this.start,f=this.startLoc;this.expect(c.types.parenR);if(b&&!this.canInsertSemicolon()&&this.eat(c.types.arrow))return this.checkPatternErrors(g,!0),q&&this.unexpected(q),this.parseParenArrowList(a,h,m);m.length||this.unexpected(this.lastTokStart);k&&this.unexpected(k); this.checkExpressionErrors(g,!0);1b)return!1; e+=a[c+1];if(e>=b)return!0}}f.__esModule=!0;f.isIdentifierStart=function(b,a){return 65>b?36===b:91>b?!0:97>b?95===b:123>b?!0:65535>=b?170<=b&&g.test(String.fromCharCode(b)):!1===a?!1:c(b,d)};f.isIdentifierChar=function(a,e){return 48>a?36===a:58>a?!0:65>a?!1:91>a?!0:97>a?95===a:123>a?!0:65535>=a?170<=a&&b.test(String.fromCharCode(a)):!1===e?!1:c(a,d)||c(a,h)};f.reservedWords={3:"abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile", 5:"class enum extends super const export import",6:"enum",7:"enum",strict:"implements interface let package private protected public static yield",strictBind:"eval arguments"};f.keywords={5:"break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this",6:"break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this const class extends export import super"}; a="\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0-\u08b4\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fd5\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ad\ua7b0-\ua7b7\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"; var g=new RegExp("["+a+"]"),b=new RegExp("["+a+"\u200c\u200d\u00b7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d01-\u0d03\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1cf8\u1cf9\u1dc0-\u1df5\u1dfc-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f]"); a=null;var d=[0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,6,37,11,29,3,35,5,7,2,4,43,157,99,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,287,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,25,391,63,32,0,449,56,1288, 921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,16481,1,3071,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,1340,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,10591,541],h=[509,0,227,0,150,4,294,9,1368,2,2,1,6,3, 41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,168,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,316,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,9,20855,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,3617,6,792618,239]},{}],3:[function(a,l,f){f.__esModule=!0;f.parse=function(a,b){return(new c.Parser(b,a)).parse()};f.parseExpressionAt=function(a,b,d){a=new c.Parser(d,a,b);a.nextToken(); return a.parseExpression()};f.tokenizer=function(a,b){return new c.Parser(b,a)};var c=a("./state");a("./parseutil");a("./statement");a("./lval");a("./expression");a("./location");f.Parser=c.Parser;f.plugins=c.plugins;l=a("./options");f.defaultOptions=l.defaultOptions;l=a("./locutil");f.Position=l.Position;f.SourceLocation=l.SourceLocation;f.getLineInfo=l.getLineInfo;l=a("./node");f.Node=l.Node;l=a("./tokentype");f.TokenType=l.TokenType;f.tokTypes=l.types;l=a("./tokencontext");f.TokContext=l.TokContext; f.tokContexts=l.types;l=a("./identifier");f.isIdentifierChar=l.isIdentifierChar;f.isIdentifierStart=l.isIdentifierStart;l=a("./tokenize");f.Token=l.Token;a=a("./whitespace");f.isNewLine=a.isNewLine;f.lineBreak=a.lineBreak;f.lineBreakG=a.lineBreakG;f.version="3.1.0"},{"./expression":1,"./identifier":2,"./location":4,"./locutil":5,"./lval":6,"./node":7,"./options":8,"./parseutil":9,"./state":10,"./statement":11,"./tokencontext":12,"./tokenize":13,"./tokentype":14,"./whitespace":16}],4:[function(a,l, f){l=a("./state");var c=a("./locutil");a=l.Parser.prototype;a.raise=function(a,b){var d=c.getLineInfo(this.input,a);b+=" ("+d.line+":"+d.column+")";var h=new SyntaxError(b);h.pos=a;h.loc=d;h.raisedAt=this.pos;throw h;};a.raiseRecoverable=a.raise;a.curPosition=function(){if(this.options.locations)return new c.Position(this.curLine,this.pos-this.lineStart)}},{"./locutil":5,"./state":10}],5:[function(a,l,f){function c(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function"); }f.__esModule=!0;f.getLineInfo=function(a,c){for(var d=1,e=0;;){g.lineBreakG.lastIndex=e;var m=g.lineBreakG.exec(a);if(m&&m.indexthis.options.ecmaVersion||"let"!=this.value)return!1;g.skipWhiteSpace.lastIndex=this.pos;var a=g.skipWhiteSpace.exec(this.input),a=this.pos+a[0].length,d=this.input.charCodeAt(a);if(91===d||123==d)return!0;if(b.isIdentifierStart(d,!0)){for(d=a+1;b.isIdentifierChar(this.input.charCodeAt(d,!0));++d);a=this.input.slice(a,d);if(!this.isKeyword(a))return!0}return!1}; a.parseStatement=function(a,b){var e=this.type,d=this.startNode(),k=void 0;this.isLet()&&(e=c.types._var,k="let");switch(e){case c.types._break:case c.types._continue:return this.parseBreakContinueStatement(d,e.keyword);case c.types._debugger:return this.parseDebuggerStatement(d);case c.types._do:return this.parseDoStatement(d);case c.types._for:return this.parseForStatement(d);case c.types._function:return!a&&6<=this.options.ecmaVersion&&this.unexpected(),this.parseFunctionStatement(d);case c.types._class:return a|| this.unexpected(),this.parseClass(d,!0);case c.types._if:return this.parseIfStatement(d);case c.types._return:return this.parseReturnStatement(d);case c.types._switch:return this.parseSwitchStatement(d);case c.types._throw:return this.parseThrowStatement(d);case c.types._try:return this.parseTryStatement(d);case c.types._const:case c.types._var:return k=k||this.value,a||"var"==k||this.unexpected(),this.parseVarStatement(d,k);case c.types._while:return this.parseWhileStatement(d);case c.types._with:return this.parseWithStatement(d); case c.types.braceL:return this.parseBlock();case c.types.semi:return this.parseEmptyStatement(d);case c.types._export:case c.types._import:return this.options.allowImportExportEverywhere||(b||this.raise(this.start,"'import' and 'export' may only appear at the top level"),this.inModule||this.raise(this.start,"'import' and 'export' may appear only with 'sourceType: module'")),e===c.types._import?this.parseImport(d):this.parseExport(d);default:var k=this.value,m=this.parseExpression();return e===c.types.name&& "Identifier"===m.type&&this.eat(c.types.colon)?this.parseLabeledStatement(d,k,m):this.parseExpressionStatement(d,m)}};a.parseBreakContinueStatement=function(a,b){var e="break"==b;this.next();this.eat(c.types.semi)||this.insertSemicolon()?a.label=null:this.type!==c.types.name?this.unexpected():(a.label=this.parseIdent(),this.semicolon());for(var d=0;d=a)return String.fromCharCode(a);a-=65536;return String.fromCharCode((a>>10)+55296,(a&1023)+56320)}f.__esModule=!0;var b=a("./identifier"),d=a("./tokentype");l=a("./state");var h=a("./locutil"),n=a("./whitespace"),e=function k(a){if(!(this instanceof k))throw new TypeError("Cannot call a class as a function");this.type=a.type;this.value=a.value;this.start=a.start;this.end=a.end;a.options.locations&&(this.loc= new h.SourceLocation(a,a.startLoc,a.endLoc));a.options.ranges&&(this.range=[a.start,a.end])};f.Token=e;a=l.Parser.prototype;var m="object"==typeof Packages&&"[object JavaPackage]"==Object.prototype.toString.call(Packages);a.next=function(){if(this.options.onToken)this.options.onToken(new e(this));this.lastTokEnd=this.end;this.lastTokStart=this.start;this.lastTokEndLoc=this.endLoc;this.lastTokStartLoc=this.startLoc;this.nextToken()};a.getToken=function(){this.next();return new e(this)};"undefined"!== typeof Symbol&&(a[Symbol.iterator]=function(){var a=this;return{next:function(){var b=a.getToken();return{done:b.type===d.types.eof,value:b}}}});a.setStrict=function(a){this.strict=a;if(this.type===d.types.num||this.type===d.types.string){this.pos=this.start;if(this.options.locations)for(;this.pos=this.input.length)return this.finishToken(d.types.eof);if(a.override)return a.override(this);this.readToken(this.fullCharCodeAtPos())};a.readToken=function(a){return b.isIdentifierStart(a,6<=this.options.ecmaVersion)||92===a?this.readWord():this.getTokenFromCode(a)};a.fullCharCodeAtPos=function(){var a=this.input.charCodeAt(this.pos);if(55295>=a||57344<= a)return a;var b=this.input.charCodeAt(this.pos+1);return(a<<10)+b-56613888};a.skipBlockComment=function(){var a=this.options.onComment&&this.curPosition(),b=this.pos,c=this.input.indexOf("*/",this.pos+=2);-1===c&&this.raise(this.pos-2,"Unterminated comment");this.pos=c+2;if(this.options.locations){n.lineBreakG.lastIndex=b;for(var d=void 0;(d=n.lineBreakG.exec(this.input))&&d.indexa||5760<=a&&n.nonASCIIwhitespace.test(String.fromCharCode(a)))++this.pos;else break a}}};a.finishToken=function(a,b){this.end=this.pos;this.options.locations&& (this.endLoc=this.curPosition());var c=this.type;this.type=a;this.value=b;this.updateContext(c)};a.readToken_dot=function(){var a=this.input.charCodeAt(this.pos+1);if(48<=a&&57>=a)return this.readNumber(!0);var b=this.input.charCodeAt(this.pos+2);if(6<=this.options.ecmaVersion&&46===a&&46===b)return this.pos+=3,this.finishToken(d.types.ellipsis);++this.pos;return this.finishToken(d.types.dot)};a.readToken_slash=function(){var a=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos, this.readRegexp()):61===a?this.finishOp(d.types.assign,2):this.finishOp(d.types.slash,1)};a.readToken_mult_modulo_exp=function(a){var b=this.input.charCodeAt(this.pos+1),c=1;a=42===a?d.types.star:d.types.modulo;7<=this.options.ecmaVersion&&42===b&&(++c,a=d.types.starstar,b=this.input.charCodeAt(this.pos+2));return 61===b?this.finishOp(d.types.assign,c+1):this.finishOp(a,c)};a.readToken_pipe_amp=function(a){var b=this.input.charCodeAt(this.pos+1);return b===a?this.finishOp(124===a?d.types.logicalOR: d.types.logicalAND,2):61===b?this.finishOp(d.types.assign,2):this.finishOp(124===a?d.types.bitwiseOR:d.types.bitwiseAND,1)};a.readToken_caret=function(){return 61===this.input.charCodeAt(this.pos+1)?this.finishOp(d.types.assign,2):this.finishOp(d.types.bitwiseXOR,1)};a.readToken_plus_min=function(a){var b=this.input.charCodeAt(this.pos+1);return b===a?45==b&&62==this.input.charCodeAt(this.pos+2)&&n.lineBreak.test(this.input.slice(this.lastTokEnd,this.pos))?(this.skipLineComment(3),this.skipSpace(), this.nextToken()):this.finishOp(d.types.incDec,2):61===b?this.finishOp(d.types.assign,2):this.finishOp(d.types.plusMin,1)};a.readToken_lt_gt=function(a){var b=this.input.charCodeAt(this.pos+1),c=1;if(b===a)return c=62===a&&62===this.input.charCodeAt(this.pos+2)?3:2,61===this.input.charCodeAt(this.pos+c)?this.finishOp(d.types.assign,c+1):this.finishOp(d.types.bitShift,c);if(33==b&&60==a&&45==this.input.charCodeAt(this.pos+2)&&45==this.input.charCodeAt(this.pos+3))return this.inModule&&this.unexpected(), this.skipLineComment(4),this.skipSpace(),this.nextToken();61===b&&(c=2);return this.finishOp(d.types.relational,c)};a.readToken_eq_excl=function(a){var b=this.input.charCodeAt(this.pos+1);return 61===b?this.finishOp(d.types.equality,61===this.input.charCodeAt(this.pos+2)?3:2):61===a&&62===b&&6<=this.options.ecmaVersion?(this.pos+=2,this.finishToken(d.types.arrow)):this.finishOp(61===a?d.types.eq:d.types.prefix,1)};a.getTokenFromCode=function(a){switch(a){case 46:return this.readToken_dot();case 40:return++this.pos, this.finishToken(d.types.parenL);case 41:return++this.pos,this.finishToken(d.types.parenR);case 59:return++this.pos,this.finishToken(d.types.semi);case 44:return++this.pos,this.finishToken(d.types.comma);case 91:return++this.pos,this.finishToken(d.types.bracketL);case 93:return++this.pos,this.finishToken(d.types.bracketR);case 123:return++this.pos,this.finishToken(d.types.braceL);case 125:return++this.pos,this.finishToken(d.types.braceR);case 58:return++this.pos,this.finishToken(d.types.colon);case 63:return++this.pos, this.finishToken(d.types.question);case 96:if(6>this.options.ecmaVersion)break;++this.pos;return this.finishToken(d.types.backQuote);case 48:a=this.input.charCodeAt(this.pos+1);if(120===a||88===a)return this.readRadixNumber(16);if(6<=this.options.ecmaVersion){if(111===a||79===a)return this.readRadixNumber(8);if(98===a||66===a)return this.readRadixNumber(2)}case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(a);case 47:return this.readToken_slash(); case 37:case 42:return this.readToken_mult_modulo_exp(a);case 124:case 38:return this.readToken_pipe_amp(a);case 94:return this.readToken_caret();case 43:case 45:return this.readToken_plus_min(a);case 60:case 62:return this.readToken_lt_gt(a);case 61:case 33:return this.readToken_eq_excl(a);case 126:return this.finishOp(d.types.prefix,1)}this.raise(this.pos,"Unexpected character '"+g(a)+"'")};a.finishOp=function(a,b){var c=this.input.slice(this.pos,this.pos+b);this.pos+=b;return this.finishToken(a, c)};var p=!!c("\uffff","u");a.readRegexp=function(){for(var a=this,b=void 0,e=void 0,f=this.pos;;){this.pos>=this.input.length&&this.raise(f,"Unterminated regular expression");var g=this.input.charAt(this.pos);n.lineBreak.test(g)&&this.raise(f,"Unterminated regular expression");if(b)b=!1;else{if("["===g)e=!0;else if("]"===g&&e)e=!1;else if("/"===g&&!e)break;b="\\"===g}++this.pos}b=this.input.slice(f,this.pos);++this.pos;e=this.readWord1();g=b;if(e){var h=/^[gim]*$/;6<=this.options.ecmaVersion&&(h= /^[gimuy]*$/);h.test(e)||this.raise(f,"Invalid regular expression flag");0<=e.indexOf("u")&&!p&&(g=g.replace(/\\u\{([0-9a-fA-F]+)\}/g,function(b,c,d){c=Number("0x"+c);1114111=k?k-48:Infinity;if(k>=a)break;++this.pos;d=d*a+k}return this.pos===c||null!=b&&this.pos-c!==b?null:d};a.readRadixNumber=function(a){this.pos+=2;var c=this.readInt(a);null==c&&this.raise(this.start+2,"Expected number in radix "+a);b.isIdentifierStart(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");return this.finishToken(d.types.num,c)};a.readNumber=function(a){var c=this.pos,e=!1,f=48===this.input.charCodeAt(this.pos);a|| null!==this.readInt(10)||this.raise(c,"Invalid number");a=this.input.charCodeAt(this.pos);46===a&&(++this.pos,this.readInt(10),e=!0,a=this.input.charCodeAt(this.pos));if(69===a||101===a)a=this.input.charCodeAt(++this.pos),43!==a&&45!==a||++this.pos,null===this.readInt(10)&&this.raise(c,"Invalid number"),e=!0;b.isIdentifierStart(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");a=this.input.slice(c,this.pos);var k=void 0;e?k=parseFloat(a):f&&1!==a.length?/[89]/.test(a)|| this.strict?this.raise(c,"Invalid number"):k=parseInt(a,8):k=parseInt(a,10);return this.finishToken(d.types.num,k)};a.readCodePoint=function(){if(123===this.input.charCodeAt(this.pos)){6>this.options.ecmaVersion&&this.unexpected();var a=++this.pos;var b=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos);++this.pos;1114111=this.input.length&&this.raise(this.start, "Unterminated string constant");var e=this.input.charCodeAt(this.pos);if(e===a)break;92===e?(b+=this.input.slice(c,this.pos),b+=this.readEscapedChar(!1),c=this.pos):(n.isNewLine(e)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}b+=this.input.slice(c,this.pos++);return this.finishToken(d.types.string,b)};a.readTmplToken=function(){for(var a="",b=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated template");var c=this.input.charCodeAt(this.pos);if(96=== c||36===c&&123===this.input.charCodeAt(this.pos+1)){if(this.pos===this.start&&this.type===d.types.template){if(36===c)return this.pos+=2,this.finishToken(d.types.dollarBraceL);++this.pos;return this.finishToken(d.types.backQuote)}a+=this.input.slice(b,this.pos);return this.finishToken(d.types.template,a)}if(92===c)a+=this.input.slice(b,this.pos),a+=this.readEscapedChar(!0),b=this.pos;else if(n.isNewLine(c)){a+=this.input.slice(b,this.pos);++this.pos;switch(c){case 13:10===this.input.charCodeAt(this.pos)&& ++this.pos;case 10:a+="\n";break;default:a+=String.fromCharCode(c)}this.options.locations&&(++this.curLine,this.lineStart=this.pos);b=this.pos}else++this.pos}};a.readEscapedChar=function(a){var b=this.input.charCodeAt(++this.pos);++this.pos;switch(b){case 110:return"\n";case 114:return"\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return g(this.readCodePoint());case 116:return"\t";case 98:return"\b";case 118:return"\x0B";case 102:return"\f";case 13:10===this.input.charCodeAt(this.pos)&& ++this.pos;case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),"";default:if(48<=b&&55>=b){var b=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],c=parseInt(b,8);255=f?1:2;else if(92===f)this.containsEsc=!0,a+=this.input.slice(d,this.pos),d=this.pos,117!=this.input.charCodeAt(++this.pos)&&this.raise(this.pos,"Expecting Unicode escape sequence \\uXXXX"),++this.pos,f=this.readCodePoint(),(c?b.isIdentifierStart:b.isIdentifierChar)(f,e)||this.raise(d, "Invalid Unicode escape"),a+=g(f),d=this.pos;else break;c=!1}return a+this.input.slice(d,this.pos)};a.readWord=function(){var a=this.readWord1(),b=d.types.name;(6<=this.options.ecmaVersion||!this.containsEsc)&&this.keywords.test(a)&&(b=d.keywords[a]);return this.finishToken(b,a)}},{"./identifier":2,"./locutil":5,"./state":10,"./tokentype":14,"./whitespace":16}],14:[function(a,l,f){function c(a,c){return new b(a,{beforeExpr:!0,binop:c})}function g(a){var c=1>=arguments.length||void 0===arguments[1]? {}:arguments[1];c.keyword=a;h[a]=d["_"+a]=new b(a,c)}f.__esModule=!0;var b=function e(a){var b=1>=arguments.length||void 0===arguments[1]?{}:arguments[1];if(!(this instanceof e))throw new TypeError("Cannot call a class as a function");this.label=a;this.keyword=b.keyword;this.beforeExpr=!!b.beforeExpr;this.startsExpr=!!b.startsExpr;this.isLoop=!!b.isLoop;this.isAssign=!!b.isAssign;this.prefix=!!b.prefix;this.postfix=!!b.postfix;this.binop=b.binop||null;this.updateContext=null};f.TokenType=b;a={beforeExpr:!0}; l={startsExpr:!0};var d={num:new b("num",l),regexp:new b("regexp",l),string:new b("string",l),name:new b("name",l),eof:new b("eof"),bracketL:new b("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new b("]"),braceL:new b("{",{beforeExpr:!0,startsExpr:!0}),braceR:new b("}"),parenL:new b("(",{beforeExpr:!0,startsExpr:!0}),parenR:new b(")"),comma:new b(",",a),semi:new b(";",a),colon:new b(":",a),dot:new b("."),question:new b("?",a),arrow:new b("=>",a),template:new b("template"),ellipsis:new b("...",a),backQuote:new b("`", l),dollarBraceL:new b("${",{beforeExpr:!0,startsExpr:!0}),eq:new b("=",{beforeExpr:!0,isAssign:!0}),assign:new b("_=",{beforeExpr:!0,isAssign:!0}),incDec:new b("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new b("prefix",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:c("||",1),logicalAND:c("&&",2),bitwiseOR:c("|",3),bitwiseXOR:c("^",4),bitwiseAND:c("&",5),equality:c("==/!=",6),relational:c("",7),bitShift:c("<>",8),plusMin:new b("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}), modulo:c("%",10),star:c("*",10),slash:c("/",10),starstar:new b("**",{beforeExpr:!0})};f.types=d;var h={};f.keywords=h;g("break");g("case",a);g("catch");g("continue");g("debugger");g("default",a);g("do",{isLoop:!0,beforeExpr:!0});g("else",a);g("finally");g("for",{isLoop:!0});g("function",l);g("if");g("return",a);g("switch");g("throw",a);g("try");g("var");g("const");g("while",{isLoop:!0});g("with");g("new",{beforeExpr:!0,startsExpr:!0});g("this",l);g("super",l);g("class");g("extends",a);g("export"); g("import");g("null",l);g("true",l);g("false",l);g("in",{beforeExpr:!0,binop:7});g("instanceof",{beforeExpr:!0,binop:7});g("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0});g("void",{beforeExpr:!0,prefix:!0,startsExpr:!0});g("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},{}],15:[function(a,l,f){f.__esModule=!0;f.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)};f.has=function(a,f){return Object.prototype.hasOwnProperty.call(a,f)}},{}],16:[function(a,l,f){f.__esModule= !0;f.isNewLine=function(a){return 10===a||13===a||8232===a||8233==a};a=/\r\n?|\n|\u2028|\u2029/;f.lineBreak=a;f.lineBreakG=new RegExp(a.source,"g");f.nonASCIIwhitespace=/[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;f.skipWhiteSpace=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g},{}]},{},[3])(3)}); var UPNG = {}; UPNG.toRGBA8 = function(out) { var w = out.width, h = out.height; if(out.tabs.acTL==null) return [UPNG.toRGBA8.decodeImage(out.data, w, h, out).buffer]; var frms = []; if(out.frames[0].data==null) out.frames[0].data = out.data; var len = w*h*4, img = new Uint8Array(len), empty = new Uint8Array(len), prev=new Uint8Array(len); for(var i=0; i>3)]>>(7-((i&7)<<0)))& 1), cj=3*j; bf[qi]=p[cj]; bf[qi+1]=p[cj+1]; bf[qi+2]=p[cj+2]; bf[qi+3]=(j>2)]>>(6-((i&3)<<1)))& 3), cj=3*j; bf[qi]=p[cj]; bf[qi+1]=p[cj+1]; bf[qi+2]=p[cj+2]; bf[qi+3]=(j>1)]>>(4-((i&1)<<2)))&15), cj=3*j; bf[qi]=p[cj]; bf[qi+1]=p[cj+1]; bf[qi+2]=p[cj+2]; bf[qi+3]=(j>>3)]>>>(7 -((x&7) )))& 1), al=(gr==tr*255)?0:255; bf32[to+x]=(al<<24)|(gr<<16)|(gr<<8)|gr; } else if(depth== 2) for(var x=0; x>>2)]>>>(6 -((x&3)<<1)))& 3), al=(gr==tr* 85)?0:255; bf32[to+x]=(al<<24)|(gr<<16)|(gr<<8)|gr; } else if(depth== 4) for(var x=0; x>>1)]>>>(4 -((x&1)<<2)))&15), al=(gr==tr* 17)?0:255; bf32[to+x]=(al<<24)|(gr<<16)|(gr<<8)|gr; } else if(depth== 8) for(var x=0; x>>2<<5);while(i==0){i=n(N,d,1);m=n(N,d+1,2);d+=3;if(m==0){if((d&7)!=0)d+=8-(d&7); var D=(d>>>3)+4,q=N[D-4]|N[D-3]<<8;if(Z)W=H.H.W(W,w+q);W.set(new R(N.buffer,N.byteOffset+D,q),w);d=D+q<<3; w+=q;continue}if(Z)W=H.H.W(W,w+(1<<17));if(m==1){v=b.J;C=b.h;X=(1<<9)-1;u=(1<<5)-1}if(m==2){J=A(N,d,5)+257; h=A(N,d+5,5)+1;Q=A(N,d+10,4)+4;d+=14;var E=d,j=1;for(var c=0;c<38;c+=2){b.Q[c]=0;b.Q[c+1]=0}for(var c=0; cj)j=K}d+=3*Q;M(b.Q,j);I(b.Q,j,b.u);v=b.w;C=b.d; d=l(b.u,(1<>>4;if(p>>>8==0){W[w++]=p}else if(p==256){break}else{var z=w+p-254; if(p>264){var _=b.q[p-257];z=w+(_>>>3)+A(N,d,_&7);d+=_&7}var $=C[e(N,d)&u];d+=$&15;var s=$>>>4,Y=b.c[s],a=(Y>>>4)+n(N,d,Y&15); d+=Y&15;while(w>>4; if(b<=15){A[I]=b;I++}else{var Z=0,m=0;if(b==16){m=3+l(V,n,2);n+=2;Z=A[I-1]}else if(b==17){m=3+l(V,n,3); n+=3}else if(b==18){m=11+l(V,n,7);n+=7}var J=I+m;while(I>>1; while(An)n=M;A++}while(A>1,I=N[l+1],e=M<<4|I,b=W-I,Z=N[l]<>>15-W;R[J]=e;Z++}}};H.H.l=function(N,W){var R=H.H.m.r,V=15-W;for(var n=0;n>>V}};H.H.M=function(N,W,R){R=R<<(W&7);var V=W>>>3;N[V]|=R;N[V+1]|=R>>>8}; H.H.I=function(N,W,R){R=R<<(W&7);var V=W>>>3;N[V]|=R;N[V+1]|=R>>>8;N[V+2]|=R>>>16};H.H.e=function(N,W,R){return(N[W>>>3]|N[(W>>>3)+1]<<8)>>>(W&7)&(1<>>3]|N[(W>>>3)+1]<<8|N[(W>>>3)+2]<<16)>>>(W&7)&(1<>>3]|N[(W>>>3)+1]<<8|N[(W>>>3)+2]<<16)>>>(W&7)}; H.H.i=function(N,W){return(N[W>>>3]|N[(W>>>3)+1]<<8|N[(W>>>3)+2]<<16|N[(W>>>3)+3]<<24)>>>(W&7)};H.H.m=function(){var N=Uint16Array,W=Uint32Array; return{K:new N(16),j:new N(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new N(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new W(32),J:new N(512),_:[],h:new N(32),$:[],w:new N(32768),C:[],v:[],d:new N(32768),D:[],u:new N(512),Q:[],r:new N(1<<15),s:new W(286),Y:new W(30),a:new W(19),t:new W(15e3),k:new N(1<<16),g:new N(1<<15)}}(); (function(){var N=H.H.m,W=1<<15;for(var R=0;R>>1|(V&1431655765)<<1; V=(V&3435973836)>>>2|(V&858993459)<<2;V=(V&4042322160)>>>4|(V&252645135)<<4;V=(V&4278255360)>>>8|(V&16711935)<<8; N.r[R]=(V>>>16|V<<16)>>>17}function n(A,l,M){while(l--!=0)A.push(0,M)}for(var R=0;R<32;R++){N.q[R]=N.S[R]<<3|N.T[R]; N.c[R]=N.p[R]<<4|N.z[R]}n(N._,144,8);n(N._,255-143,9);n(N._,279-255,7);n(N._,287-279,8);H.H.n(N._,9); H.H.A(N._,9,N.J);H.H.l(N._,9);n(N.$,32,5);H.H.n(N.$,5);H.H.A(N.$,5,N.h);H.H.l(N.$,5);n(N.Q,19,0);n(N.C,286,0); n(N.D,30,0);n(N.v,320,0)}());return H.H.N}() UPNG.decode._readInterlace = function(data, out) { var w = out.width, h = out.height; var bpp = UPNG.decode._getBPP(out), cbpp = bpp>>3, bpl = Math.ceil(w*bpp/8); var img = new Uint8Array( h * bpl ); var di = 0; var starting_row = [ 0, 0, 4, 0, 2, 0, 1 ]; var starting_col = [ 0, 4, 0, 2, 0, 1, 0 ]; var row_increment = [ 8, 8, 8, 4, 4, 2, 2 ]; var col_increment = [ 8, 8, 4, 4, 2, 2, 1 ]; var pass=0; while(pass<7) { var ri = row_increment[pass], ci = col_increment[pass]; var sw = 0, sh = 0; var cr = starting_row[pass]; while(cr>3]; val = (val>>(7-(cdi&7)))&1; img[row*bpl + (col>>3)] |= (val << (7-((col&7)<<0))); } if(bpp==2) { var val = data[cdi>>3]; val = (val>>(6-(cdi&7)))&3; img[row*bpl + (col>>2)] |= (val << (6-((col&3)<<1))); } if(bpp==4) { var val = data[cdi>>3]; val = (val>>(4-(cdi&7)))&15; img[row*bpl + (col>>1)] |= (val << (4-((col&1)<<2))); } if(bpp>=8) { var ii = row*bpl+col*cbpp; for(var j=0; j>3)+j]; } cdi+=bpp; col+=ci; } y++; row += ri; } if(sw*sh!=0) di += sh * (1 + bpll); pass = pass + 1; } return img; } UPNG.decode._getBPP = function(out) { var noc = [1,null,3,1,2,null,4][out.ctype]; return noc * out.depth; } UPNG.decode._filterZero = function(data, out, off, w, h) { var bpp = UPNG.decode._getBPP(out), bpl = Math.ceil(w*bpp/8), paeth = UPNG.decode._paeth; bpp = Math.ceil(bpp/8); var i=0, di=1, type=data[off], x=0; if(type>1) data[off]=[0,0,1][type-2]; if(type==3) for(x=bpp; x>>1) )&255; for(var y=0; y>>1)); for(; x>>1) ); } else { for(; x>8)&255; buff[p+1] = n&255; }, readUint : function(buff,p) { return (buff[p]*(256*256*256)) + ((buff[p+1]<<16) | (buff[p+2]<< 8) | buff[p+3]); }, writeUint : function(buff,p,n){ buff[p]=(n>>24)&255; buff[p+1]=(n>>16)&255; buff[p+2]=(n>>8)&255; buff[p+3]=n&255; }, readASCII : function(buff,p,l){ var s = ""; for(var i=0; i=0 && yoff>=0) { si = (y*sw+x)<<2; ti = (( yoff+y)*tw+xoff+x)<<2; } else { si = ((-yoff+y)*sw-xoff+x)<<2; ti = (y*tw+x)<<2; } if (mode==0) { tb[ti] = sb[si]; tb[ti+1] = sb[si+1]; tb[ti+2] = sb[si+2]; tb[ti+3] = sb[si+3]; } else if(mode==1) { var fa = sb[si+3]*(1/255), fr=sb[si]*fa, fg=sb[si+1]*fa, fb=sb[si+2]*fa; var ba = tb[ti+3]*(1/255), br=tb[ti]*ba, bg=tb[ti+1]*ba, bb=tb[ti+2]*ba; var ifa=1-fa, oa = fa+ba*ifa, ioa = (oa==0?0:1/oa); tb[ti+3] = 255*oa; tb[ti+0] = (fr+br*ifa)*ioa; tb[ti+1] = (fg+bg*ifa)*ioa; tb[ti+2] = (fb+bb*ifa)*ioa; } else if(mode==2){ // copy only differences, otherwise zero var fa = sb[si+3], fr=sb[si], fg=sb[si+1], fb=sb[si+2]; var ba = tb[ti+3], br=tb[ti], bg=tb[ti+1], bb=tb[ti+2]; if(fa==ba && fr==br && fg==bg && fb==bb) { tb[ti]=0; tb[ti+1]=0; tb[ti+2]=0; tb[ti+3]=0; } else { tb[ti]=fr; tb[ti+1]=fg; tb[ti+2]=fb; tb[ti+3]=fa; } } else if(mode==3){ // check if can be blended var fa = sb[si+3], fr=sb[si], fg=sb[si+1], fb=sb[si+2]; var ba = tb[ti+3], br=tb[ti], bg=tb[ti+1], bb=tb[ti+2]; if(fa==ba && fr==br && fg==bg && fb==bb) continue; //if(fa!=255 && ba!=0) return false; if(fa<220 && ba>20) return false; } } return true; } UPNG.encode = function(bufs, w, h, ps, dels, tabs, forbidPlte) { if(ps==null) ps=0; if(forbidPlte==null) forbidPlte = false; var nimg = UPNG.encode.compress(bufs, w, h, ps, [false, false, false, 0, forbidPlte]); UPNG.encode.compressPNG(nimg, -1); return UPNG.encode._main(nimg, w, h, dels, tabs); } UPNG.encodeLL = function(bufs, w, h, cc, ac, depth, dels, tabs) { var nimg = { ctype: 0 + (cc==1 ? 0 : 2) + (ac==0 ? 0 : 4), depth: depth, frames: [] }; var time = Date.now(); var bipp = (cc+ac)*depth, bipl = bipp * w; for(var i=0; i1, pltAlpha = false; var leng = 8 + (16+5+4) /*+ (9+4)*/ + (anim ? 20 : 0); if(tabs["sRGB"]!=null) leng += 8+1+4; if(tabs["pHYs"]!=null) leng += 8+9+4; if(nimg.ctype==3) { var dl = nimg.plte.length; for(var i=0; i>>24)!=255) pltAlpha = true; leng += (8 + dl*3 + 4) + (pltAlpha ? (8 + dl*1 + 4) : 0); } for(var j=0; j>>8)&255, b=(c>>>16)&255; data[offset+ti+0]=r; data[offset+ti+1]=g; data[offset+ti+2]=b; } offset+=dl*3; wUi(data,offset,crc(data,offset-dl*3-4,dl*3+4)); offset+=4; // crc if(pltAlpha) { wUi(data,offset, dl); offset+=4; wAs(data,offset,"tRNS"); offset+=4; for(var i=0; i>>24)&255; offset+=dl; wUi(data,offset,crc(data,offset-dl-4,dl+4)); offset+=4; // crc } } var fi = 0; for(var j=0; j>2, bln>>2)); for(var j=0; jnw && c==img32[i-nw]) ind[i]=ind[i-nw]; else { var cmc = cmap[c]; if(cmc==null) { cmap[c]=cmc=plte.length; plte.push(c); if(plte.length>=300) break; } ind[i]=cmc; } } } //console.log("make palette", Date.now()-time); time = Date.now(); } var cc=plte.length; //console.log("colors:",cc); if(cc<=256 && forbidPlte==false) { if(cc<= 2) depth=1; else if(cc<= 4) depth=2; else if(cc<=16) depth=4; else depth=8; depth = Math.max(depth, minBits); } for(var j=0; j>1)] |= (inj[ii+x]<<(4-(x&1)*4)); else if(depth==2) for(var x=0; x>2)] |= (inj[ii+x]<<(6-(x&3)*2)); else if(depth==1) for(var x=0; x>3)] |= (inj[ii+x]<<(7-(x&7)*1)); } cimg=nimg; ctype=3; bpp=1; } else if(gotAlpha==false && frms.length==1) { // some next "reduced" frames may contain alpha for blending var nimg = new Uint8Array(nw*nh*3), area=nw*nh; for(var i=0; i palette indices", Date.now()-time); time = Date.now(); return {ctype:ctype, depth:depth, plte:plte, frames:frms }; } UPNG.encode.framize = function(bufs,w,h,alwaysBlend,evenCrd,forbidPrev) { /* DISPOSE - 0 : no change - 1 : clear to transparent - 2 : retstore to content before rendering (previous frame disposed) BLEND - 0 : replace - 1 : blend */ var frms = []; for(var j=0; jmax) max=x; if(ymay) may=y; } } if(max==-1) mix=miy=max=may=0; if(evenCrd) { if((mix&1)==1)mix--; if((miy&1)==1)miy--; } var sarea = (max-mix+1)*(may-miy+1); if(sareamax) max=cx; if(cymay) may=cy; } } if(max==-1) mix=miy=max=may=0; if(evenCrd) { if((mix&1)==1)mix--; if((miy&1)==1)miy--; } r = {x:mix, y:miy, width:max-mix+1, height:may-miy+1}; var fr = frms[i]; fr.rect = r; fr.blend = 1; fr.img = new Uint8Array(r.width*r.height*4); if(frms[i-1].dispose==0) { UPNG._copyTile(pimg,w,h, fr.img,r.width,r.height, -r.x,-r.y, 0); UPNG.encode._prepareDiff(cimg,w,h,fr.img,r); //UPNG._copyTile(cimg,w,h, fr.img,r.width,r.height, -r.x,-r.y, 2); } else UPNG._copyTile(cimg,w,h, fr.img,r.width,r.height, -r.x,-r.y, 0); } UPNG.encode._prepareDiff = function(cimg, w,h, nimg, rec) { UPNG._copyTile(cimg,w,h, nimg,rec.width,rec.height, -rec.x,-rec.y, 2); /* var n32 = new Uint32Array(nimg.buffer); var og = new Uint8Array(rec.width*rec.height*4), o32 = new Uint32Array(og.buffer); UPNG._copyTile(cimg,w,h, og,rec.width,rec.height, -rec.x,-rec.y, 0); for(var i=4; i>>2]==o32[(i>>>2)-1]) { n32[i>>>2]=o32[i>>>2]; //var j = i, c=p32[(i>>>2)-1]; //while(p32[j>>>2]==c) { n32[j>>>2]=c; j+=4; } } } for(var i=nimg.length-8; i>0; i-=4) { if(nimg[i+7]!=0 && nimg[i+3]==0 && o32[i>>>2]==o32[(i>>>2)+1]) { n32[i>>>2]=o32[i>>>2]; //var j = i, c=p32[(i>>>2)-1]; //while(p32[j>>>2]==c) { n32[j>>>2]=c; j+=4; } } }*/ } UPNG.encode._filterZero = function(img,h,bpp,bpl,data, filter, levelZero) { var fls = [], ftry=[0,1,2,3,4]; if (filter!=-1) ftry=[filter]; else if(h*bpl>500000 || bpp==1) ftry=[0]; var opts; if(levelZero) opts={level:0}; var CMPR = (data.length>10e6 && UZIP!=null) ? UZIP : pako; var time = Date.now(); for(var i=0; i>1) +256)&255; if(type==4) for(var x=bpp; x>1))&255; for(var x=bpp; x>1))&255; } if(type==4) { for(var x= 0; x>> 1); else c = c >>> 1; } tab[n] = c; } return tab; })(), update : function(c, buf, off, len) { for (var i=0; i>> 8); return c; }, crc : function(b,o,l) { return UPNG.crc.update(0xffffffff,b,o,l) ^ 0xffffffff; } } UPNG.quantize = function(abuf, ps) { var oimg = new Uint8Array(abuf), nimg = oimg.slice(0), nimg32 = new Uint32Array(nimg.buffer); var KD = UPNG.quantize.getKDtree(nimg, ps); var root = KD[0], leafs = KD[1]; var planeDst = UPNG.quantize.planeDst; var sb = oimg, tb = nimg32, len=sb.length; var inds = new Uint8Array(oimg.length>>2), nd; if(oimg.length<20e6) // precise, but slow :( for(var i=0; i>2] = nd.ind; tb[i>>2] = nd.est.rgba; } else for(var i=0; i>2] = nd.ind; tb[i>>2] = nd.est.rgba; } return { abuf:nimg.buffer, inds:inds, plte:leafs }; } UPNG.quantize.getKDtree = function(nimg, ps, err) { if(err==null) err = 0.0001; var nimg32 = new Uint32Array(nimg.buffer); var root = {i0:0, i1:nimg.length, bst:null, est:null, tdst:0, left:null, right:null }; // basic statistic, extra statistic root.bst = UPNG.quantize.stats( nimg,root.i0, root.i1 ); root.est = UPNG.quantize.estats( root.bst ); var leafs = [root]; while(leafs.length maxL) { maxL=leafs[i].est.L; mi=i; } if(maxL=s0 || node.i1<=s0); //console.log(maxL, leafs.length, mi); if(s0wrong) { node.est.L=0; continue; } var ln = {i0:node.i0, i1:s0, bst:null, est:null, tdst:0, left:null, right:null }; ln.bst = UPNG.quantize.stats( nimg, ln.i0, ln.i1 ); ln.est = UPNG.quantize.estats( ln.bst ); var rn = {i0:s0, i1:node.i1, bst:null, est:null, tdst:0, left:null, right:null }; rn.bst = {R:[], m:[], N:node.bst.N-ln.bst.N}; for(var i=0; i<16; i++) rn.bst.R[i] = node.bst.R[i]-ln.bst.R[i]; for(var i=0; i< 4; i++) rn.bst.m[i] = node.bst.m[i]-ln.bst.m[i]; rn.est = UPNG.quantize.estats( rn.bst ); node.left = ln; node.right = rn; leafs[mi]=ln; leafs.push(rn); } leafs.sort(function(a,b) { return b.bst.N-a.bst.N; }); for(var i=0; i0) { node0=nd.right; node1=nd.left; } var ln = UPNG.quantize.getNearest(node0, r,g,b,a); if(ln.tdst<=planeDst*planeDst) return ln; var rn = UPNG.quantize.getNearest(node1, r,g,b,a); return rn.tdst eMq) i1-=4; if(i0>=i1) break; var t = nimg32[i0>>2]; nimg32[i0>>2] = nimg32[i1>>2]; nimg32[i1>>2]=t; i0+=4; i1-=4; } while(vecDot(nimg, i0, e)>eMq) i0-=4; return i0+4; } UPNG.quantize.vecDot = function(nimg, i, e) { return nimg[i]*e[0] + nimg[i+1]*e[1] + nimg[i+2]*e[2] + nimg[i+3]*e[3]; } UPNG.quantize.stats = function(nimg, i0, i1){ var R = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; var m = [0,0,0,0]; var N = (i1-i0)>>2; for(var i=i0; i>>0) }; } UPNG.M4 = { multVec : function(m,v) { return [ m[ 0]*v[0] + m[ 1]*v[1] + m[ 2]*v[2] + m[ 3]*v[3], m[ 4]*v[0] + m[ 5]*v[1] + m[ 6]*v[2] + m[ 7]*v[3], m[ 8]*v[0] + m[ 9]*v[1] + m[10]*v[2] + m[11]*v[3], m[12]*v[0] + m[13]*v[1] + m[14]*v[2] + m[15]*v[3] ]; }, dot : function(x,y) { return x[0]*y[0]+x[1]*y[1]+x[2]*y[2]+x[3]*y[3]; }, sml : function(a,y) { return [a*y[0],a*y[1],a*y[2],a*y[3]]; } } UPNG.encode.concatRGBA = function(bufs) { var tlen = 0; for(var i=0; il)M.push(6/7*W+1/7*l,5/7*W+2/7*l,4/7*W+3/7*l,3/7*W+4/7*l,2/7*W+5/7*l,1/7*W+6/7*l); else M.push(4/5*W+1/5*l,3/5*W+2/5*l,2/5*W+3/5*l,1/5*W+4/5*l,0,255);return M}function T(W,l,M,F,t){var K=Q(W[l],W[l+1]); M.W+=16;for(var $=0;$<64;$+=4){var I=a2(W,M,3);F[$+t]=K[I]}}function u(W,l,M,F,t){var K={W:l*8},$=new Uint8Array(4*4*4); $.fill(255);for(var I=0;I>8;F[t+2]=S>>16;t+=3}c(F,t,K);t+=8}return t}var E=new Uint8Array(16); function D(W,l,M){var F=W[l+1]<<8|W[l],t=W[l+3]<<8|W[l+2],K=(F&31)*(255/31),$=(F>>>5&31)*(255/31),I=(F>>10)*(255/31),O=(t&31)*(255/31),C=(t>>>5&63)*(255/63),j=(t>>11)*(255/31),b=E; b[0]=~~I;b[1]=~~$;b[2]=~~K;b[3]=255;b[12]=~~j;b[13]=~~C;b[14]=~~O;b[15]=255;var h=2/3,_=1-h;b[4]=~~(h*I+_*j); b[5]=~~(h*$+_*C);b[6]=~~(h*K+_*O);b[7]=255;h=1/3;_=1-h;b[8]=~~(h*I+_*j);b[9]=~~(h*$+_*C);b[10]=~~(h*K+_*O); b[11]=255;z(W,M,b,l)}function Y(W,l,M){var F=W[l+1]<<8|W[l],t=W[l+3]<<8|W[l+2],K=(F&31)*(255/31),$=(F>>>5&63)*(255/63),I=(F>>11)*(255/31),O=(t&31)*(255/31),C=(t>>>5&63)*(255/63),j=(t>>11)*(255/31),b=E; b[0]=~~I;b[1]=~~$;b[2]=~~K;b[3]=255;b[4]=~~j;b[5]=~~C;b[6]=~~O;b[7]=255;if(t>8],$=M[(t>>8)+1],I=M[(t>>8)+2],O=M[t&255],C=M[(t&255)+1],j=M[(t&255)+2],b=K>>3<<11|$>>2<<5|I>>3,h=O>>3<<11|C>>2<<5|j>>3; if(b>>5&63)*(255/63)),K=Math.floor((b>>11)*(255/31)),j=Math.floor((h&31)*(255/31)),C=Math.floor((h>>>5&63)*(255/63)),O=Math.floor((h>>11)*(255/31)); W[l+0]=b&255;W[l+1]=b>>8;W[l+2]=h&255;W[l+3]=h>>8;var S=2/3,J=1-S,v=Math.floor(S*K+J*O),V=Math.floor(S*$+J*C),p=Math.floor(S*I+J*j); S=1/3;J=1-S;var w=Math.floor(S*K+J*O),a5=Math.floor(S*$+J*C),y=Math.floor(S*I+J*j),m=l*8+32;for(var i=0; i<64;i+=4){var f=M[i],H=M[i+1],an=M[i+2],a9=F(f,H,an,K,$,I),a8=F(f,H,an,O,C,j),o=F(f,H,an,v,V,p),R=F(f,H,an,w,a5,y),al=Math.min(a9,Math.min(a8,Math.min(o,R))),g=0; if(al==a8)g=1;else if(al==o)g=2;else if(al==R)g=3;W[m>>3]|=g<<(m&7);m+=2}}function z(W,l,M,F){var t=F+4<<3; for(var K=0;K<64;K+=4){var $=W[t>>3]>>(t&7)&3;t+=2;$=$<<2;l[K]=M[$];l[K+1]=M[$+1];l[K+2]=M[$+2];l[K+3]=M[$+3]}}function r(W,l,M,F,t,K){for(var $=0; $<4;$++){var I=(t+$)*l+F<<2,O=$<<4;K[O+0]=W[I+0];K[O+1]=W[I+1];K[O+2]=W[I+2];K[O+3]=W[I+3];K[O+4]=W[I+4]; K[O+5]=W[I+5];K[O+6]=W[I+6];K[O+7]=W[I+7];K[O+8]=W[I+8];K[O+9]=W[I+9];K[O+10]=W[I+10];K[O+11]=W[I+11]; K[O+12]=W[I+12];K[O+13]=W[I+13];K[O+14]=W[I+14];K[O+15]=W[I+15]}}function n(W,l,M,F,t,K){for(var $=0; $<4;$++){var I=(t+$)*l+F<<2,O=$<<4;W[I+0]=K[O+0];W[I+1]=K[O+1];W[I+2]=K[O+2];W[I+3]=K[O+3];W[I+4]=K[O+4]; W[I+5]=K[O+5];W[I+6]=K[O+6];W[I+7]=K[O+7];W[I+8]=K[O+8];W[I+9]=K[O+9];W[I+10]=K[O+10];W[I+11]=K[O+11]; W[I+12]=K[O+12];W[I+13]=K[O+13];W[I+14]=K[O+14];W[I+15]=K[O+15]}}var d="0011001100110011 0001000100010001 0111011101110111 0001001100110111 0000000100010011 0011011101111111 0001001101111111 0000000100110111 0000000000010011 0011011111111111 0000000101111111 0000000000010111 0001011111111111 0000000011111111 0000111111111111 0000000000001111 0000100011101111 0111000100000000 0000000010001110 0111001100010000 0011000100000000 0000100011001110 0000000010001100 0111001100110001 0011000100010000 0000100010001100 0110011001100110 0011011001101100 0001011111101000 0000111111110000 0111000110001110 0011100110011100 0101010101010101 0000111100001111 0101101001011010 0011001111001100 0011110000111100 0101010110101010 0110100101101001 0101101010100101 0111001111001110 0001001111001000 0011001001001100 0011101111011100 0110100110010110 0011110011000011 0110011010011001 0000011001100000 0100111001000000 0010011100100000 0000001001110010 0000010011100100 0110110010010011 0011011011001001 0110001110011100 0011100111000110 0110110011001001 0110001100111001 0111111010000001 0001100011100111 0000111100110011 0011001111110000 0010001011101110 0100010001110111".split(" "),q="0011001102212222 0001001122112221 0000200122112211 0222002200110111 0000000011221122 0011001100220022 0022002211111111 0011001122112211 0000000011112222 0000111111112222 0000111122222222 0012001200120012 0112011201120112 0122012201220122 0011011211221222 0011200122002220 0001001101121122 0111001120012200 0000112211221122 0022002200221111 0111011102220222 0001000122212221 0000001101220122 0000110022102210 0122012200110000 0012001211222222 0110122112210110 0000011012211221 0022110211020022 0110011020022222 0011012201220011 0000200022112221 0000000211221222 0222002200120011 0011001200220222 0120012001200120 0000111122220000 0120120120120120 0120201212010120 0011220011220011 0011112222000011 0101010122222222 0000000021212121 0022112200221122 0022001100220011 0220122102201221 0101222222220101 0000212121212121 0101010101012222 0222011102220111 0002111200021112 0000211221122112 0222011101110222 0002111211120002 0110011001102222 0000000021122112 0110011022222222 0022001100110022 0022112211220022 0000000000002112 0002000100020001 0222122202221222 0101222222222222 0111201122012220".split(" "),Z=[[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,2,0],[0,8,0],[0,2,0],[0,2,0],[0,8,0],[0,8,0],[0,15,0],[0,2,0],[0,8,0],[0,2,0],[0,2,0],[0,8,0],[0,8,0],[0,2,0],[0,2,0],[0,15,0],[0,15,0],[0,6,0],[0,8,0],[0,2,0],[0,8,0],[0,15,0],[0,15,0],[0,2,0],[0,8,0],[0,2,0],[0,2,0],[0,2,0],[0,15,0],[0,15,0],[0,6,0],[0,6,0],[0,2,0],[0,6,0],[0,8,0],[0,15,0],[0,15,0],[0,2,0],[0,2,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,15,0],[0,2,0],[0,2,0],[0,15,0]],ae=[[0,3,15],[0,3,8],[0,15,8],[0,15,3],[0,8,15],[0,3,15],[0,15,3],[0,15,8],[0,8,15],[0,8,15],[0,6,15],[0,6,15],[0,6,15],[0,5,15],[0,3,15],[0,3,8],[0,3,15],[0,3,8],[0,8,15],[0,15,3],[0,3,15],[0,3,8],[0,6,15],[0,10,8],[0,5,3],[0,8,15],[0,8,6],[0,6,10],[0,8,15],[0,5,15],[0,15,10],[0,15,8],[0,8,15],[0,15,3],[0,3,15],[0,5,10],[0,6,10],[0,10,8],[0,8,9],[0,15,10],[0,15,6],[0,3,15],[0,15,8],[0,5,15],[0,15,3],[0,15,6],[0,15,6],[0,15,8],[0,3,15],[0,15,3],[0,5,15],[0,5,15],[0,5,15],[0,8,15],[0,5,15],[0,10,15],[0,5,15],[0,10,15],[0,8,15],[0,13,15],[0,15,3],[0,12,15],[0,3,15],[0,3,8]]; function P(W,l,M,F,t){var K=a2,$={W:0},I=new Uint8Array(4*4*4),O=[null,null,[0,21,43,64],[0,9,18,27,37,46,55,64],[0,4,9,13,17,21,26,30,34,38,43,47,51,55,60,64]],C=[null,null,d,q],j=[null,null,Z,ae]; for(var b=0;b>_&1)!=1)_++;$.W=(l<<3)+_+1; var S=_==4||_==5?K(W,$,2):0,J=_==4?K(W,$,1):0,v=[4,6,6,6,0,0,0,6][_],V=K(W,$,v),p=[4,6,5,7,5,7,7,5][_],w=[0,0,0,0,6,8,7,5][_],a5=[1,1,0,1,0,0,1,1][_],y=[6,4,6,4,2,2,2,4][_],m=[]; for(var i=0;i<4;i++){var f=i==3?w:p;for(var H=0;H>2)-48,a0=g[x]==i>>2?1:0,a4=K(W,$,o-a0),s=ak[a4]/64,a7=(1-s)*m[0*y+2*x+0]+s*m[0*y+2*x+1],ad=(1-s)*m[1*y+2*x+0]+s*m[1*y+2*x+1],ag=(1-s)*m[2*y+2*x+0]+s*m[2*y+2*x+1],a1=(1-s)*m[3*y+2*x+0]+s*m[3*y+2*x+1]; I[i]=a7*255;I[i+1]=ad*255;I[i+2]=ag*255;I[i+3]=a1*255}ak=O[R];$.W=ac;if(R!=0)for(var i=0;i<64;i+=4){var x=al.charCodeAt(i>>2)-48,a0=g[x]==i>>2?1:0,a4=K(W,$,R-a0),s=ak[a4]/64,a1=(1-s)*m[3*y+2*x+0]+s*m[3*y+2*x+1]; I[i+3]=a1*255}ai(I,S);n(M,F,t,h,b,I);l+=16}return l}function ai(W,l){if(l==0)return;for(var M=0;M<64; M+=4){var F=W[M],t=W[M+1],K=W[M+2],$=W[M+3];if(l==1){var I=$;$=F;F=I}if(l==2){var I=$;$=t;t=I}if(l==3){var I=$; $=K;K=I}W[M]=F;W[M+1]=t;W[M+2]=K;W[M+3]=$}}function a2(W,l,M){var F=0,t=M;while(M!=0){F=F|X(W,l)<>3]>>(M&7)&1}function e(W,l,M){var F=l>>1,t=M>>1,K=new Uint8Array(F*t*4); for(var $=0;$>2,p=V==0?0:.25/V; K[O]=~~(h*p+.5);K[O+1]=~~(_*p+.5);K[O+2]=~~(S*p+.5);K[O+3]=V}return K}function A(W,l,M,F,t,K){return(W-F)*(W-F)+(l-t)*(l-t)+(M-K)*(M-K)}function af(W){var l=A,M=0,F=0; for(var t=0;t<64;t+=4){var K=W[t],$=W[t+1],I=W[t+2];for(var O=t+4;O<64;O+=4){var C=l(K,$,I,W[O],W[O+1],W[O+2]); if(C>F){F=C;M=t<<8|O}}}return M}var aj=new ArrayBuffer(4),N=new Uint8Array(aj),ab=new Uint32Array(aj),am=new Uint16Array(aj),a3={Y:function(W,l){N[0]=W[l+0]; N[1]=W[l+1];return am[0]},T:function(W,l){N[0]=W[l+0];N[1]=W[l+1];N[2]=W[l+2];N[3]=W[l+3];return ab[0]},G:function(W,l,M){ab[0]=M; W[l+0]=N[0];W[l+1]=N[1];W[l+2]=N[2];W[l+3]=N[3]},t:function(W,l,M){var F="";for(var t=0;t>1)+1]<<8|a[E+(t>>1)];A[t+0]=(K&af)*N; A[t+1]=(K&ab)*am;A[t+2]=(K&W)*l;A[t+3]=(K&M)*F}E+=e>>>1}else throw"unknown bit count "+Z}else if(c.u&L.i||c.u&L.Q||c.u&L.$){if(Z==8){for(var t=0; t>2)];E+=e>>>2}else throw"unknown bit count "+Z}else{console.log("unknown texture format, head flags: ",Y.u.toString(2),"pixelFormat flags: ",c.u.toString(2)); throw"e"}d.push({width:r,height:n,image:A.buffer});r=r>>>1;n=n>>>1}return d}function aa(G,a,E){var G=new Uint8Array(G),D=255,r=0,n=0; for(var Y=3;Y>1;E=E>>1;n++}z[28]=n;return z.buffer.slice(0,r)}function k(G,a){var E={},D=UTEX.X.T;a+=4;E.u=D(G,a); a+=4;E.height=D(G,a);a+=4;E.width=D(G,a);a+=4;E.pitch=D(G,a);a+=4;E.depth=D(G,a);a+=4;E.c=D(G,a);a+=4; a+=11*4;E.Z=Q(G,a);a+=32;E.v=D(G,a);a+=4;E.g=D(G,a);a+=4;E.a3=D(G,a);a+=4;E.a8=D(G,a);a+=4;a+=4;return E}function B(G,a,E,D,Y){var c=UTEX.X.G,z=L.r|L.D|L.h|L.S; z|=L._|L.N;var r=L.B|L.z|L.A,n=(a*E>>1)*(D?2:1),d=D?1:0;c(G,Y,124);Y+=4;c(G,Y,z);Y+=4;c(G,Y,E);Y+=4; c(G,Y,a);Y+=4;c(G,Y,n);Y+=4;c(G,Y,d);Y+=4;c(G,Y,10);Y+=4;Y+=11*4;T(G,D,Y);Y+=32;c(G,Y,r);Y+=4;Y+=4*4}function Q(G,a){var E={},D=UTEX.X.T; a+=4;E.u=D(G,a);a+=4;E.f=UTEX.X.t(G,a,4);a+=4;E.w=D(G,a);a+=4;E.l=D(G,a);a+=4;E.j=D(G,a);a+=4;E.H=D(G,a); a+=4;E.m=D(G,a);a+=4;return E}function T(G,a,E){var D=UTEX.X.G,Y=L.a;D(G,E,32);E+=4;D(G,E,Y);E+=4;UTEX.X.b(G,E,a?"DXT5":"DXT1"); E+=4;E+=5*4}function u(G,a){var E={},D=UTEX.X.T;E.V=D(G,a);a+=4;E.a4=D(G,a);a+=4;E.a6=D(G,a);a+=4;E.a1=D(G,a); a+=4;E.a0=D(G,a);a+=4;return E}return{encode:aa,decode:a6}}();UTEX.VTF=function(){var L={};function a6(k){var B=new Uint8Array(k),Q=0,T={}; Q=aa(B,Q,T);var u=T.F,G=T.d;if(u*G!=0){var a=new Uint8Array(u*G*4);Q=UTEX.R(B,Q,a,u,G)}var E=T.s,D=T.p,Y=[]; for(var c=0;c>>D-1-c,r=T.height>>>D-1-c;for(var n=0;n=2){Q.depth=u(k,B);B+=2;if(E>=3){B+=3;Q.a5=T(k,B);B+=4}}return D}return{decode:a6}}();(function(){var V={};if(typeof module=="object"){module.exports=V}else{self.UTIF=V}var a3=typeof require==="function"?require("pako"):self.pako; function aI(){if(typeof process=="undefined"||process.env.NODE_ENV=="development")console.log.apply(console,arguments)}(function(V,a3){(function(){"use strict"; var c=function n(){function c(g){this.message="JPEG error: "+g}c.prototype=new Error;c.prototype.name="JpegError"; c.constructor=c;return c}(),O=function j(){var g=new Uint8Array([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]),D=4017,P=799,a=3406,y=2276,W=1567,T=3784,b=5793,I=2896; function O(S){if(S==null)S={};if(S.w==null)S.w=-1;this.V=S.n;this.N=S.w}function R(S,_){var m=0,X=[],B,e,h=16,z; while(h>0&&!S[h-1]){h--}X.push({children:[],index:0});var s=X[0];for(B=0;B0){s=X.pop()}s.index++;X.push(s);while(X.length<=B){X.push(z={children:[],index:0}); s.children[s.index]=z.children;s=z}m++}if(B+10){L--;return A>>L&1}A=S[_++]; if(A===255){var o=S[_++];if(o){if(o===220&&Q){_+=2;var al=t(S,_);_+=2;if(al>0&&al!==m.s){throw new DNLMarkerError("Found DNL marker (0xFFDC) while parsing scan data",al)}}else if(o===217){if(Q){var ay=F*8; if(ay>0&&ay>>7}function aB(o){var al=o;while(!0){al=al[U()];switch(typeof al){case"number":return al;case"object":continue}throw new c("invalid huffman sequence")}}function ax(o){var av=0; while(o>0){av=av<<1|U();o--}return av}function v(o){if(o===1){return U()===1?1:-1}var av=ax(o);if(av>=1<>4;if(a9===0){if(b5<15){break}r+=16;continue}r+=b5; var ae=g[r];x.D[o+ae]=v(a9);r++}}function b4(x,o){var al=aB(x.J),ay=al===0?0:v(al)<0){w--; return}var r=e,al=h;while(r<=al){var ay=aB(x.i),aZ=ay&15,a9=ay>>4;if(aZ===0){if(a9<15){w=ax(a9)+(1<>4;if(aZ===0){if(ay<15){w=ax(ay)+(1<0){for(u=0;u0?"unexpected":"excessive";_=aO.offset}if(aO.M>=65488&&aO.M<=65495){_+=2}else{break}}return _-d}function $(S,_,m){var X=S.$,B=S.D,e,h,z,s,Q,E,p,d,A,L,w,G,au,F,x,ag,u; if(!X){throw new c("missing required Quantization Table.")}for(var M=0;M<64;M+=8){A=B[_+M];L=B[_+M+1]; w=B[_+M+2];G=B[_+M+3];au=B[_+M+4];F=B[_+M+5];x=B[_+M+6];ag=B[_+M+7];A*=X[M];if((L|w|G|au|F|x|ag)===0){u=b*A+512>>10; m[M]=u;m[M+1]=u;m[M+2]=u;m[M+3]=u;m[M+4]=u;m[M+5]=u;m[M+6]=u;m[M+7]=u;continue}L*=X[M+1];w*=X[M+2];G*=X[M+3]; au*=X[M+4];F*=X[M+5];x*=X[M+6];ag*=X[M+7];e=b*A+128>>8;h=b*au+128>>8;z=w;s=x;Q=I*(L-ag)+128>>8;d=I*(L+ag)+128>>8; E=G<<4;p=F<<4;e=e+h+1>>1;h=e-h;u=z*T+s*W+128>>8;z=z*W-s*T+128>>8;s=u;Q=Q+p+1>>1;p=Q-p;d=d+E+1>>1;E=d-E; e=e+s+1>>1;s=e-s;h=h+z+1>>1;z=h-z;u=Q*y+d*a+2048>>12;Q=Q*a-d*y+2048>>12;d=u;u=E*P+p*D+2048>>12;E=E*D-p*P+2048>>12; p=u;m[M]=e+d;m[M+7]=e-d;m[M+1]=h+p;m[M+6]=h-p;m[M+2]=z+E;m[M+5]=z-E;m[M+3]=s+Q;m[M+4]=s-Q}for(var r=0; r<8;++r){A=m[r];L=m[r+8];w=m[r+16];G=m[r+24];au=m[r+32];F=m[r+40];x=m[r+48];ag=m[r+56];if((L|w|G|au|F|x|ag)===0){u=b*A+8192>>14; if(u<-2040){u=0}else if(u>=2024){u=255}else{u=u+2056>>4}B[_+r]=u;B[_+r+8]=u;B[_+r+16]=u;B[_+r+24]=u; B[_+r+32]=u;B[_+r+40]=u;B[_+r+48]=u;B[_+r+56]=u;continue}e=b*A+2048>>12;h=b*au+2048>>12;z=w;s=x;Q=I*(L-ag)+2048>>12; d=I*(L+ag)+2048>>12;E=G;p=F;e=(e+h+1>>1)+4112;h=e-h;u=z*T+s*W+2048>>12;z=z*W-s*T+2048>>12;s=u;Q=Q+p+1>>1; p=Q-p;d=d+E+1>>1;E=d-E;e=e+s+1>>1;s=e-s;h=h+z+1>>1;z=h-z;u=Q*y+d*a+2048>>12;Q=Q*a-d*y+2048>>12;d=u;u=E*P+p*D+2048>>12; E=E*D-p*P+2048>>12;p=u;A=e+d;ag=e-d;L=h+p;x=h-p;w=z+E;F=z-E;G=s+Q;au=s-Q;if(A<16){A=0}else if(A>=4080){A=255}else{A>>=4}if(L<16){L=0}else if(L>=4080){L=255}else{L>>=4}if(w<16){w=0}else if(w>=4080){w=255}else{w>>=4}if(G<16){G=0}else if(G>=4080){G=255}else{G>>=4}if(au<16){au=0}else if(au>=4080){au=255}else{au>>=4}if(F<16){F=0}else if(F>=4080){F=255}else{F>>=4}if(x<16){x=0}else if(x>=4080){x=255}else{x>>=4}if(ag<16){ag=0}else if(ag>=4080){ag=255}else{ag>>=4}B[_+r]=A; B[_+r+8]=L;B[_+r+16]=w;B[_+r+24]=G;B[_+r+32]=au;B[_+r+40]=F;B[_+r+48]=x;B[_+r+56]=ag}}function C(S,_){var m=_.P,X=_.c,B=new Int16Array(64); for(var e=0;e=X){return null}var e=t(S,_);if(e>=65472&&e<=65534){return{u:null,M:e,offset:_}}var h=t(S,B); while(!(h>=65472&&h<=65534)){if(++B>=X){return null}h=t(S,B)}return{u:e.toString(16),M:h,offset:B}}O.prototype={parse(S,_){if(_==null)_={}; var m=_.F,X=0,B=null,e=null,h,z,s=0;function Q(){var b5=t(S,X);X+=2;var ae=X+b5-2,L=f(S,ae,X);if(L&&L.u){ae=L.offset}var a$=S.subarray(X,ae); X+=a$.length;return a$}function E(h){var b5=Math.ceil(h.o/8/h.X),ae=Math.ceil(h.s/8/h.B);for(var w=0; w>4===0){for(G=0; G<64;G++){ag=g[G];r[ag]=S[X++]}}else if(M>>4===1){for(G=0;G<64;G++){ag=g[G];r[ag]=t(S,X);X+=2}}else{throw new c("DQT - invalid table spec")}p[M&15]=r}break; case 65472:case 65473:case 65474:if(h){throw new c("Only single frame JPEGs supported")}X+=2;h={};h.G=L===65473; h.Z=L===65474;h.precision=S[X++];var av=t(S,X),a6,aW=0,aO=0;X+=2;h.s=m||av;h.o=t(S,X);X+=2;h.W=[];h._={}; var aa=S[X++];for(w=0;w>4,aA=S[X+1]&15;if(aW>4===0?A:d)[ax&15]=R(v,b4)}break;case 65501:X+=2;z=t(S,X); X+=2;break;case 65498:var aM=++s===1&&!m,as;X+=2;var aP=S[X++],b7=[];for(w=0;w>4];as.i=d[aq&15];b7.push(as)}var ah=S[X++],o=S[X++],al=S[X++]; try{var ay=J(S,X,h,b7,z,ah,o,al>>4,al&15,aM);X+=ay}catch(ex){if(ex instanceof DNLMarkerError){return this.parse(S,{F:ex.s})}else if(ex instanceof EOIMarkerError){break markerLoop}throw ex}break; case 65500:X+=4;break;case 65535:if(S[X]!==255){X--}break;default:var aZ=f(S,X-2,X-3);if(aZ&&aZ.u){X=aZ.offset; break}if(X>=S.length-1){break markerLoop}throw new c("JpegImage.parse - unknown marker: "+L.toString(16))}L=t(S,X); X+=2}this.width=h.o;this.height=h.s;this.g=B;this.b=e;this.W=[];for(w=0;w>8)+r[A+1]}}}return x},get f(){if(this.b){return!!this.b.a}if(this.p===3){if(this.N===0){return!1}else if(this.W[0].index===82&&this.W[1].index===71&&this.W[2].index===66){return!1}return!0}if(this.N===1){return!0}return!1},z:function b1(S){var _,m,X; for(var B=0,e=S.length;B4){throw new c("Unsupported color mode")}var e=this.Y(_,m,B);if(this.p===1&&X){var h=e.length,z=new Uint8ClampedArray(h*3),s=0; for(var Q=0;Q>24}function t(g,D){return g[D]<<8|g[D+1]}function H(g,D){return(g[D]<<24|g[D+1]<<16|g[D+2]<<8|g[D+3])>>>0}V.JpegDecoder=O}()); V.encodeImage=function(c,O,n,j){var t={t256:[O],t257:[n],t258:[8,8,8,8],t259:[1],t262:[2],t273:[1e3],t277:[4],t278:[n],t279:[O*n*4],t282:[[72,1]],t283:[[72,1]],t284:[1],t286:[[0,1]],t287:[[0,1]],t296:[1],t305:["Photopea (UTIF.js)"],t338:[1]}; if(j)for(var H in j)t[H]=j[H];var g=new Uint8Array(V.encode([t])),D=new Uint8Array(c),P=new Uint8Array(1e3+O*n*4); for(var H=0;H>>3)];if(a==null)a=O.t325;var y=new Uint8Array(O.height*(D>>>3)); if(O.t322!=null){var W=O.t322[0],T=O.t323[0],b=Math.floor((O.width+W-1)/W),l=Math.floor((O.height+T-1)/T),I=new Uint8Array(Math.ceil(W*T*g/8)|0); for(var R=0;R>>3,l=c.t278?c.t278[0]:c.height,I=Math.ceil(W*T*c.width/8); if(W==16&&!c.isLE&&c.t33422==null)for(var R=0;R>>8&255}else if(T==3)for(var P=3; P>>3]>>>7-(C&7)&1;$[1]++;return N}function y($,C){if(n==null){n={}; for(var N=0;N>>1}return $}function W($,C){return $>>C}function T($,C,N,i,S,_){C[N]=W(W(11*$[S]-4*$[S+_]+$[S+_+_]+4,3)+$[i],1); C[N+_]=W(W(5*$[S]+4*$[S+_]-$[S+_+_]+4,3)-$[i],1)}function b($,C,N,i,S,_){var X=$[S-_]-$[S+_],B=$[S],z=$[i]; C[N]=W(W(X+4,3)+B+z,1);C[N+_]=W(W(-X+4,3)+B-z,1)}function l($,C,N,i,S,_){C[N]=W(W(5*$[S]+4*$[S-_]-$[S-_-_]+4,3)+$[i],1); C[N+_]=W(W(11*$[S]-4*$[S-_]+$[S-_-_]+4,3)-$[i],1)}function R($){$=$<0?0:$>4095?4095:$;$=k[$]>>>2;return $}function Y($,C,N,i,S){i=new Uint16Array(i.buffer); var _=Date.now(),X=V._binBE,B=C+N,z,p,Z,A,aK,w,a8,G,au,ab,at,ac,F,aY,x,ak,aR,an;C+=4;while(C>>1)*(Z>>>1));an=new Int16Array((p>>>1)*(Z>>>1));j=new Int16Array(1024); for(var ap=0;ap<1024;ap++){var aH=ap-512,a1=Math.abs(aH),z=Math.floor(768*a1*a1*a1/(255*255*255))+a1; j[ap]=Math.sign(aH)*z}k=new Uint16Array(4096);var av=(1<<16)-1;for(var ap=0;ap<4096;ap++){var a6=ap,ad=av*(Math.pow(113,a6/4095)-1)/112; k[ap]=Math.min(ad,av)}}var b3=aR[a8],aW=K(p,1+t[A]),aa=K(Z,1+t[A]);if(A==0){for(var U=0;U>>1)+v]=$[aV]<<8|$[aV+1]}}else{var b4=[$,C*8],aM=[],aP=0,b7=aW*aa,aQ=[0,0],b8=0,M=0; while(aP0){aM[aP++]=M;b8--}}var aq=(A-1)%3,ah=aq!=1?aW:0,o=aq!=0?aa:0; for(var U=0;U>>1)+ah,ay=U*aW;for(var v=0;v>>1,aZ=aW*2,a9=aa*2; for(var U=0;U>14-aD*2&3; var af=aF[b2];if(af!=0)for(var U=0;U>>1)*(p>>>1)+(v>>>1),a_=b0[aV],a5=aC[aV]-2048,aL=aG[aV]-2048,aw=a4[aV]-2048,aE=(a5<<1)+a_,b6=(aL<<1)+a_,aU=a_+aw,aJ=a_-aw; i[a2]=R(aE);i[a2+1]=R(aU);i[a2+p]=R(aJ);i[a2+p+1]=R(b6)}}C+=aX*4}else if(r==16388){C+=aX*4}else if(aT==8192||aT==8448||aT==9216){}else throw r.toString(16)}}console.log(Date.now()-_)}return Y}(); V.decode._ljpeg_diff=function(c,O,n){var j=V.decode._getbithuff,k,t;k=j(c,O,n[0],n);t=j(c,O,k,0);if((t&1<>>(W[T]>>>8);for(var b=0;b<$;b++)K[++l]=W[T]}for(I=H;I--;)for(R=0; R>>4;k[t+T+1]=f<<4|N>>>4;k[t+T+2]=N<<4|b1>>>4}return}var aN=new Uint16Array(16),z=new Uint8Array(H+1); for(R=0;R>>11;m=15&i>>>22;X=15&i>>>26;for(B=0;B<4&&128<>3))>>>(e&7)&127)<2047)aN[T]=2047; e+=7}for(T=0;T<16;T++,I+=2){var C=aN[T]<<1;V.decode._putsF(k,(R*H+I)*D,C<<16-D)}I-=I&1?1:31}}};V.decode._decodeNikon=function(c,O,n,j,k,t,H){var g=[[0,0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0,5,4,3,6,2,7,1,0,8,9,11,10,12],[0,0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0,57,90,56,39,22,5,4,3,2,1,0,11,12,12],[0,0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0,5,4,6,3,7,2,8,1,9,0,10,11,12],[0,0,1,4,3,1,1,1,1,1,2,0,0,0,0,0,0,5,6,4,7,8,3,9,2,1,0,10,11,12,13,14],[0,0,1,5,1,1,1,1,1,1,1,2,0,0,0,0,0,8,92,75,58,41,7,6,5,4,3,2,1,0,13,14],[0,0,1,4,2,2,3,1,2,0,0,0,0,0,0,0,0,7,6,8,5,9,4,10,3,11,12,2,0,1,13,14]],D=c.t256[0],P=c.t257[0],a=c.t258[0],y=0,K=0,W=V.decode._make_decoder,T=V.decode._getbithuff,b=O[0].exifIFD.makerNote,l=b.t150?b.t150:b.t140,I=0,R=l[I++],Y=l[I++],N=0,C,i,S,_,m,X,B=0; if(R==73||Y==88)I+=2110;if(R==70)y=2;if(a==14)y+=3;var J=[[0,0],[0,0]],$=c.isLE?V._binLE:V._binBE;for(var C=0; C<2;C++)for(var f=0;f<2;f++){J[C][f]=$.readShort(l,I);I+=2}var b1=1<1)N=Math.floor(b1/(aN-1));if(R==68&&Y==32&&N>0)K=$.readShort(l,562);var e=[0,0],h=W(g[y]),z=[j,0,0,0]; for(B=i=0;i>>4;X=(T(n,z,_-m,0)<<1)+1<>>1; if((X&1<<_-1)==0)X-=(1<<_)-(m==0?1:0);if(S<2)e[S]=J[i&1][S]+=X;else e[S&1]+=X;var s=Math.min(Math.max(e[S&1],0),(1<>>3;c[j]|=n>>>16; c[j+1]|=n>>>8;c[j+2]|=n};V.decode._getbithuff=function(c,O,n,j){var k=0,t=V.decode._get_byte,H,g=O[0],D=O[1],P=O[2],a=O[3]; if(n==0||P<0)return 0;while(!a&&P>>32-n; if(j){P-=j[H+1]>>>8;H=j[H+1]&255}else P-=n;if(P<0)throw"e";O[0]=g;O[1]=D;O[2]=P;O[3]=a;return H};V.decode._make_decoder=function(c){var O,n,j,t,H,g=[],D=17; for(O=16;O!=0&&!c[O];O--);g[0]=O;for(j=n=1;n<=O;n++)for(t=0;t>>8}else for(var K=0; K>>8;k[t+(K<<1)+1]=l[K]&255}}else if(b==14||b==12){var R=16-b;for(var K=0;K1}if(!b){if(O[n]==255&&O[n+1]==k)return{jpegOffset:n};if(Y!=null){if(O[n+J]==255&&O[n+J+1]==k)y=n+J; else aI("JPEGInterchangeFormat does not point to SOI");if($==null)aI("JPEGInterchangeFormatLength field is missing"); else if(J>=K||J+C<=K)aI("JPEGInterchangeFormatLength field value is invalid");if(y!=null)return{jpegOffset:y}}}if(b1!=null){N=b1[0]; aN=b1[1]}if(Y!=null)if($!=null)if(C>=2&&J+C<=K){if(O[n+J+C-2]==255&&O[n+J+C-1]==k)W=new Uint8Array(C-2); else W=new Uint8Array(C);for(l=0;l offset to first strip or tile"); if(W==null){var _=0,m=[];m[_++]=255;m[_++]=k;var X=c.t519;if(X==null)throw new Error("JPEGQTables tag is missing"); for(l=0;l>>8;m[_++]=e&255; m[_++]=l|R<<4;for(I=0;I<16;I++)m[_++]=O[n+B[l]+I];for(I=0;I>>8&255;m[_++]=c.height&255;m[_++]=c.width>>>8&255; m[_++]=c.width&255;m[_++]=i;if(i==1){m[_++]=1;m[_++]=17;m[_++]=0}else for(l=0;l<3;l++){m[_++]=l+1;m[_++]=l!=0?17:(N&15)<<4|aN&15; m[_++]=l}if(S!=null&&S[0]!=0){m[_++]=255;m[_++]=D;m[_++]=0;m[_++]=4;m[_++]=S[0]>>>8&255;m[_++]=S[0]&255}W=new Uint8Array(m)}var h=-1; l=0;while(l>>8&255; W[s++]=c.height&255;W[s++]=c.width>>>8&255;W[s++]=c.width&255;W[s++]=i;if(i==1){W[s++]=1;W[s++]=17;W[s++]=0}else for(l=0; l<3;l++){W[s++]=l+1;W[s++]=l!=0?17:(N&15)<<4|aN&15;W[s++]=l}}if(O[K]==255&&O[K+1]==a){var Q=O[K+2]<<8|O[K+3]; T=new Uint8Array(Q+2);T[0]=O[K];T[1]=O[K+1];T[2]=O[K+2];T[3]=O[K+3];for(l=0;l>>8&255;P[y.sofPosition+6]=c.height&255;P[y.sofPosition+7]=c.width>>>8&255; P[y.sofPosition+8]=c.width&255;if(O[n]!=255||O[n+1]!=SOS){P.set(y.sosMarker,a);a+=sosMarker.length}for(H=0; H=0&&D<128)for(var P=0;P=-127&&D<0){for(var P=0; P<-D+1;P++){H[k]=t[O];k++}O++}}};V.decode._decodeThunder=function(c,O,n,j,k){var t=[0,1,0,-1],H=[0,1,2,3,0,-3,-2,-1],g=O+n,D=k*2,P=0; while(O>>6,K=a&63;O++;if(y==3){P=K&15;j[D>>>1]|=P<<4*(1-D&1);D++}if(y==0)for(var W=0; W>>1]|=P<<4*(1-D&1);D++}if(y==2)for(var W=0;W<2;W++){var T=K>>>3*(1-W)&7;if(T!=4){P+=H[T]; j[D>>>1]|=P<<4*(1-D&1);D++}}if(y==1)for(var W=0;W<3;W++){var T=K>>>2*(2-W)&3;if(T!=2){P+=t[T];j[D>>>1]|=P<<4*(1-D&1); D++}}}};V.decode._dmap={"1":0,"011":1,"000011":2,"0000011":3,"010":-1,"000010":-2,"0000010":-3};V.decode._lens=function(){var c=function(D,P,a,y){for(var K=0; K>>3>>3]>>>7-(D&7)&1;if(H==2)N=c[D>>>3]>>>(D&7)&1;D++;a+=N;if(C=="H"){if(g._lens[J][a]!=null){var aN=g._lens[J][a]; a="";P+=aN;if(aN<64){g._addNtimes(y,P,J);T+=P;J=1-J;P=0;f--;if(f==0)C=""}}}else{if(a=="0001"){a="";g._addNtimes(y,R-T,J); T=R}if(a=="001"){a="";C="H";f=2}if(g._dmap[a]!=null){b=I+g._dmap[a];g._addNtimes(y,b-T,J);T=b;a="";J=1-J}}if(y.length==t&&C==""){g._writeBits(y,j,k*8+$*b1); J=0;$++;T=0;K=g._makeDiff(y);y=[]}}};V.decode._findDiff=function(c,O,n){for(var j=0;j=O&&c[j+1]==n)return c[j]}; V.decode._makeDiff=function(c){var O=[];if(c[0]==1)O.push(0,1);for(var n=1;n>>3>>3]>>>7-(P&7)&1;if(H==2)i=c[P>>>3]>>>(P&7)&1;P++;y+=i;if(N){if(D._lens[$][y]!=null){var S=D._lens[$][y]; y="";a+=S;if(S<64){D._addNtimes(K,a,$);$=1-$;a=0}}}else{if(f=="H"){if(D._lens[$][y]!=null){var S=D._lens[$][y]; y="";a+=S;if(S<64){D._addNtimes(K,a,$);b+=a;$=1-$;a=0;b1--;if(b1==0)f=""}}}else{if(y=="0001"){y="";D._addNtimes(K,J-b,$); b=J}if(y=="001"){y="";f="H";b1=2}if(D._dmap[y]!=null){l=R+D._dmap[y];D._addNtimes(K,l-b,$);b=l;y=""; $=1-$}}}if(y.endsWith("000000000001")){if(C>=0)D._writeBits(K,j,k*8+C*aN);if(g){if(H==1)N=(c[P>>>3]>>>7-(P&7)&1)==1; if(H==2)N=(c[P>>>3]>>>(P&7)&1)==1;P++}y="";$=0;C++;b=0;W=D._makeDiff(K);K=[]}}if(K.length==t)D._writeBits(K,j,k*8+C*aN)}; V.decode._addNtimes=function(c,O,n){for(var j=0;j>>3]|=c[j]<<7-(n+j&7)};V.decode._decodeLZW=V.decode._decodeLZW=function(){var c,n,j,k,t=0,H=0,g=0,D=0,P=function(){var R=c>>>3,J=n[R]<<16|n[R+1]<<8|n[R+2],$=J>>>24-(c&7)-H&(1<>>----------------");for(var D=0;D4){c.writeUint(n,j,g);l=g}if(y==1||y==7){for(var I=0;I4){b+=b&1;g+=b}j+=4}return[j,g]};V.toRGBA8=function(c,O){var n=c.width,j=c.height,t=n*j,H=t*4,g=c.data,D=new Uint8Array(t*4),P=c.t262?c.t262[0]:2,a=c.t258?Math.min(32,c.t258[0]):1; if(c.t262==null&&a==1)P=0;if(!1){}else if(P==0){var y=Math.ceil(a*n/8);for(var K=0;K>3)]>>7-(b&7)&1;D[l]=D[l+1]=D[l+2]=(1-I)*255;D[l+3]=255}if(a==4)for(var b=0; b>1)]>>4-4*(b&1)&15;D[l]=D[l+1]=D[l+2]=(15-I)*17;D[l+3]=255}if(a==8)for(var b=0; b>3)]>>7-(b&7)&1; D[l]=D[l+1]=D[l+2]=I*255;D[l+3]=255}if(a==2)for(var b=0;b>2)]>>6-2*(b&3)&3; D[l]=D[l+1]=D[l+2]=I*85;D[l+3]=255}if(a==8)for(var b=0;b>>3)]>>>7-(N&7)&1; else if(a==8)aN=g[i+N*R];else throw a;D[l]=f[aN]>>8;D[l+1]=f[b1+aN]>>8;D[l+2]=f[b1+b1+aN]>>8;D[l+3]=255}}else if(P==5){var R=c.t258?c.t258.length:4,S=R>4?1:0; for(var b=0;b>>1),B=g[_+(Q&1)],E=g[_+2]-128,q=g[_+3]-128,p=B+((q>>2)+(q>>3)+(q>>5)),d=B-((E>>2)+(E>>4)+(E>>5))-((q>>1)+(q>>3)+(q>>4)+(q>>5)),Z=B+(E+(E>>1)+(E>>2)+(E>>6)); D[l]=Math.max(0,Math.min(255,p));D[l+1]=Math.max(0,Math.min(255,d));D[l+2]=Math.max(0,Math.min(255,Z)); D[l+3]=255}}}else aI("Unknown Photometric interpretation: "+P);return D};V.replaceIMG=function(c){if(c==null)c=document.getElementsByTagName("img"); var O=["tif","tiff","dng","cr2","nef"];for(var n=0;nt){t=P;H=D}}V.decodeImage(n,H,j);var a=V.toRGBA8(H),y=H.width,K=H.height,W=V._xhrs.indexOf(c.target),D=V._imgs[W]; V._xhrs.splice(W,1);V._imgs.splice(W,1);var T=document.createElement("canvas");T.width=y;T.height=K; var b=T.getContext("2d"),l=new ImageData(new Uint8ClampedArray(a.buffer),y,K);b.putImageData(l,0,0); D.setAttribute("src",T.toDataURL())};V._binBE={nextZero:function(c,O){while(c[O]!=0)O++;return O},readUshort:function(c,O){return c[O]<<8|c[O+1]},readShort:function(c,O){var n=V._binBE.ui8; n[0]=c[O+1];n[1]=c[O+0];return V._binBE.i16[0]},readInt:function(c,O){var n=V._binBE.ui8;n[0]=c[O+3]; n[1]=c[O+2];n[2]=c[O+1];n[3]=c[O+0];return V._binBE.i32[0]},readUint:function(c,O){var n=V._binBE.ui8; n[0]=c[O+3];n[1]=c[O+2];n[2]=c[O+1];n[3]=c[O+0];return V._binBE.ui32[0]},readASCII:function(c,O,n){var j=""; for(var k=0;k>8&255; c[O+1]=n&255},writeInt:function(c,O,n){var j=V._binBE.ui8;V._binBE.i32[0]=n;c[O+3]=j[0];c[O+2]=j[1]; c[O+1]=j[2];c[O+0]=j[3]},writeUint:function(c,O,n){c[O]=n>>24&255;c[O+1]=n>>16&255;c[O+2]=n>>8&255;c[O+3]=n>>0&255},writeASCII:function(c,O,n){for(var j=0; j>8&255},writeInt:function(c,O,n){var j=V._binBE.ui8; V._binBE.i32[0]=n;c[O+0]=j[0];c[O+1]=j[1];c[O+2]=j[2];c[O+3]=j[3]},writeUint:function(c,O,n){c[O]=n>>>0&255; c[O+1]=n>>>8&255;c[O+2]=n>>>16&255;c[O+3]=n>>>24&255},writeASCII:V._binBE.writeASCII};V._copyTile=function(c,O,n,j,k,t,H,g){var D=Math.min(O,k-H),P=Math.min(n,t-g); for(var a=0;a>--aS&1; aK=s[aK+L]}Z[q]=aK}}function Y(z,s,Q,E){if(z[s+3]!=255)return 0;if(Q==0)return s;for(var q=0;q<2;q++){if(z[s+q]==0){z[s+q]=z.length; z.push(0,0,E,255)}var p=Y(z,z[s+q],Q-1,E+1);if(p!=0)return p}return 0}function J(z){var s=z.c,Q=z.d; while(s<25){var E=z.data[z.a++];if(!z.b)z.a+=E+1>>>8;Q=Q<<8|E;s+=8}z.c=s;z.d=Q}function C(z,s){if(s.c>(s.c-=z)&65535>>16-z}function b1(z,s){var Q=z[0],E=0,q=255,p=0;if(s.c<16)J(s);var d=s.d>>s.c-8&255; E=z[1][d];q=Q[E+3];s.c-=Q[E+2];while(q==255){p=s.d>>--s.c&1;E=Q[E+p];q=Q[E+3]}return q}function aN(z,s){if(z<32768>>16-s)z+=-(1<>>1);else throw p;z[L]=w+i(d[Z],Q)}}A+=s}}function m(z,s){var Q=C(z,s); return z==16?-32768:aN(Q,z)}function e(z,s,Q){var E=c.length-O;for(var q=0;q>>4]}H=y();O+=2;break}else{O+=Q-2}}var aS=n>8?Uint16Array:Uint8Array,A=k*t,aK=new aS(j*A),L={c:0,d:0,b:H==8,a:O,data:c}; if(L.b)e(aK,A,L);else _(aK,A,L);return aK}return h}()}(V,a3))}())// (c) Dean McNamee , 2013. // // https://github.com/deanm/omggif // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. // // omggif is a JavaScript implementation of a GIF 89a encoder and decoder, // including animation and compression. It does not rely on any specific // underlying system, so should run in the browser, Node, or Plask. "use strict"; function GifWriter(buf, width, height, gopts) { var p = 0; var gopts = gopts === undefined ? { } : gopts; var loop_count = gopts.loop === undefined ? null : gopts.loop; var global_palette = gopts.palette === undefined ? null : gopts.palette; if (width <= 0 || height <= 0 || width > 65535 || height > 65535) throw new Error("Width/Height invalid."); function check_palette_and_num_colors(palette) { var num_colors = palette.length; if (num_colors < 2 || num_colors > 256 || num_colors & (num_colors-1)) { throw new Error( "Invalid code/color length, must be power of 2 and 2 .. 256."); } return num_colors; } // - Header. buf[p++] = 0x47; buf[p++] = 0x49; buf[p++] = 0x46; // GIF buf[p++] = 0x38; buf[p++] = 0x39; buf[p++] = 0x61; // 89a // Handling of Global Color Table (palette) and background index. var gp_num_colors_pow2 = 0; var background = 0; if (global_palette !== null) { var gp_num_colors = check_palette_and_num_colors(global_palette); while (gp_num_colors >>= 1) ++gp_num_colors_pow2; gp_num_colors = 1 << gp_num_colors_pow2; --gp_num_colors_pow2; if (gopts.background !== undefined) { background = gopts.background; if (background >= gp_num_colors) throw new Error("Background index out of range."); // The GIF spec states that a background index of 0 should be ignored, so // this is probably a mistake and you really want to set it to another // slot in the palette. But actually in the end most browsers, etc end // up ignoring this almost completely (including for dispose background). if (background === 0) throw new Error("Background index explicitly passed as 0."); } } // - Logical Screen Descriptor. // NOTE(deanm): w/h apparently ignored by implementations, but set anyway. buf[p++] = width & 0xff; buf[p++] = width >> 8 & 0xff; buf[p++] = height & 0xff; buf[p++] = height >> 8 & 0xff; // NOTE: Indicates 0-bpp original color resolution (unused?). buf[p++] = (global_palette !== null ? 0x80 : 0) | // Global Color Table Flag. gp_num_colors_pow2; // NOTE: No sort flag (unused?). buf[p++] = background; // Background Color Index. buf[p++] = 0; // Pixel aspect ratio (unused?). // - Global Color Table if (global_palette !== null) { for (var i = 0, il = global_palette.length; i < il; ++i) { var rgb = global_palette[i]; buf[p++] = rgb >> 16 & 0xff; buf[p++] = rgb >> 8 & 0xff; buf[p++] = rgb & 0xff; } } if (loop_count !== null) { // Netscape block for looping. if (loop_count < 0 || loop_count > 65535) throw new Error("Loop count invalid."); // Extension code, label, and length. buf[p++] = 0x21; buf[p++] = 0xff; buf[p++] = 0x0b; // NETSCAPE2.0 buf[p++] = 0x4e; buf[p++] = 0x45; buf[p++] = 0x54; buf[p++] = 0x53; buf[p++] = 0x43; buf[p++] = 0x41; buf[p++] = 0x50; buf[p++] = 0x45; buf[p++] = 0x32; buf[p++] = 0x2e; buf[p++] = 0x30; // Sub-block buf[p++] = 0x03; buf[p++] = 0x01; buf[p++] = loop_count & 0xff; buf[p++] = loop_count >> 8 & 0xff; buf[p++] = 0x00; // Terminator. } var ended = false; this.addFrame = function(x, y, w, h, indexed_pixels, opts) { if (ended === true) { --p; ended = false; } // Un-end. opts = opts === undefined ? { } : opts; // TODO(deanm): Bounds check x, y. Do they need to be within the virtual // canvas width/height, I imagine? if (x < 0 || y < 0 || x > 65535 || y > 65535) throw new Error("x/y invalid."); if (w <= 0 || h <= 0 || w > 65535 || h > 65535) throw new Error("Width/Height invalid."); if (indexed_pixels.length < w * h) throw new Error("Not enough pixels for the frame size."); var using_local_palette = true; var palette = opts.palette; if (palette === undefined || palette === null) { using_local_palette = false; palette = global_palette; } if (palette === undefined || palette === null) throw new Error("Must supply either a local or global palette."); var num_colors = check_palette_and_num_colors(palette); // Compute the min_code_size (power of 2), destroying num_colors. var min_code_size = 0; while (num_colors >>= 1) ++min_code_size; num_colors = 1 << min_code_size; // Now we can easily get it back. var delay = opts.delay === undefined ? 0 : opts.delay; // From the spec: // 0 - No disposal specified. The decoder is // not required to take any action. // 1 - Do not dispose. The graphic is to be left // in place. // 2 - Restore to background color. The area used by the // graphic must be restored to the background color. // 3 - Restore to previous. The decoder is required to // restore the area overwritten by the graphic with // what was there prior to rendering the graphic. // 4-7 - To be defined. // NOTE(deanm): Dispose background doesn't really work, apparently most // browsers ignore the background palette index and clear to transparency. var disposal = opts.disposal === undefined ? 0 : opts.disposal; if (disposal < 0 || disposal > 3) // 4-7 is reserved. throw new Error("Disposal out of range."); var use_transparency = false; var transparent_index = 0; if (opts.transparent !== undefined && opts.transparent !== null) { use_transparency = true; transparent_index = opts.transparent; if (transparent_index < 0 || transparent_index >= num_colors) throw new Error("Transparent color index."); } if (disposal !== 0 || use_transparency || delay !== 0) { // - Graphics Control Extension buf[p++] = 0x21; buf[p++] = 0xf9; // Extension / Label. buf[p++] = 4; // Byte size. buf[p++] = disposal << 2 | (use_transparency === true ? 1 : 0); buf[p++] = delay & 0xff; buf[p++] = delay >> 8 & 0xff; buf[p++] = transparent_index; // Transparent color index. buf[p++] = 0; // Block Terminator. } // - Image Descriptor buf[p++] = 0x2c; // Image Seperator. buf[p++] = x & 0xff; buf[p++] = x >> 8 & 0xff; // Left. buf[p++] = y & 0xff; buf[p++] = y >> 8 & 0xff; // Top. buf[p++] = w & 0xff; buf[p++] = w >> 8 & 0xff; buf[p++] = h & 0xff; buf[p++] = h >> 8 & 0xff; // NOTE: No sort flag (unused?). // TODO(deanm): Support interlace. buf[p++] = using_local_palette === true ? (0x80 | (min_code_size-1)) : 0; // - Local Color Table if (using_local_palette === true) { for (var i = 0, il = palette.length; i < il; ++i) { var rgb = palette[i]; buf[p++] = rgb >> 16 & 0xff; buf[p++] = rgb >> 8 & 0xff; buf[p++] = rgb & 0xff; } } p = GifWriterOutputLZWCodeStream( buf, p, min_code_size < 2 ? 2 : min_code_size, indexed_pixels); return p; }; this.end = function() { if (ended === false) { buf[p++] = 0x3b; // Trailer. ended = true; } return p; }; this.getOutputBuffer = function() { return buf; }; this.setOutputBuffer = function(v) { buf = v; }; this.getOutputBufferPosition = function() { return p; }; this.setOutputBufferPosition = function(v) { p = v; }; } // Main compression routine, palette indexes -> LZW code stream. // |index_stream| must have at least one entry. function GifWriterOutputLZWCodeStream(buf, p, min_code_size, index_stream) { buf[p++] = min_code_size; var cur_subblock = p++; // Pointing at the length field. var clear_code = 1 << min_code_size; var code_mask = clear_code - 1; var eoi_code = clear_code + 1; var next_code = eoi_code + 1; var cur_code_size = min_code_size + 1; // Number of bits per code. var cur_shift = 0; // We have at most 12-bit codes, so we should have to hold a max of 19 // bits here (and then we would write out). var cur = 0; function emit_bytes_to_buffer(bit_block_size) { while (cur_shift >= bit_block_size) { buf[p++] = cur & 0xff; cur >>= 8; cur_shift -= 8; if (p === cur_subblock + 256) { // Finished a subblock. buf[cur_subblock] = 255; cur_subblock = p++; } } } function emit_code(c) { cur |= c << cur_shift; cur_shift += cur_code_size; emit_bytes_to_buffer(8); } // I am not an expert on the topic, and I don't want to write a thesis. // However, it is good to outline here the basic algorithm and the few data // structures and optimizations here that make this implementation fast. // The basic idea behind LZW is to build a table of previously seen runs // addressed by a short id (herein called output code). All data is // referenced by a code, which represents one or more values from the // original input stream. All input bytes can be referenced as the same // value as an output code. So if you didn't want any compression, you // could more or less just output the original bytes as codes (there are // some details to this, but it is the idea). In order to achieve // compression, values greater then the input range (codes can be up to // 12-bit while input only 8-bit) represent a sequence of previously seen // inputs. The decompressor is able to build the same mapping while // decoding, so there is always a shared common knowledge between the // encoding and decoder, which is also important for "timing" aspects like // how to handle variable bit width code encoding. // // One obvious but very important consequence of the table system is there // is always a unique id (at most 12-bits) to map the runs. 'A' might be // 4, then 'AA' might be 10, 'AAA' 11, 'AAAA' 12, etc. This relationship // can be used for an effecient lookup strategy for the code mapping. We // need to know if a run has been seen before, and be able to map that run // to the output code. Since we start with known unique ids (input bytes), // and then from those build more unique ids (table entries), we can // continue this chain (almost like a linked list) to always have small // integer values that represent the current byte chains in the encoder. // This means instead of tracking the input bytes (AAAABCD) to know our // current state, we can track the table entry for AAAABC (it is guaranteed // to exist by the nature of the algorithm) and the next character D. // Therefor the tuple of (table_entry, byte) is guaranteed to also be // unique. This allows us to create a simple lookup key for mapping input // sequences to codes (table indices) without having to store or search // any of the code sequences. So if 'AAAA' has a table entry of 12, the // tuple of ('AAAA', K) for any input byte K will be unique, and can be our // key. This leads to a integer value at most 20-bits, which can always // fit in an SMI value and be used as a fast sparse array / object key. // Output code for the current contents of the index buffer. var ib_code = index_stream[0] & code_mask; // Load first input index. var code_table = { }; // Key'd on our 20-bit "tuple". emit_code(clear_code); // Spec says first code should be a clear code. // First index already loaded, process the rest of the stream. for (var i = 1, il = index_stream.length; i < il; ++i) { var k = index_stream[i] & code_mask; var cur_key = ib_code << 8 | k; // (prev, k) unique tuple. var cur_code = code_table[cur_key]; // buffer + k. // Check if we have to create a new code table entry. if (cur_code === undefined) { // We don't have buffer + k. // Emit index buffer (without k). // This is an inline version of emit_code, because this is the core // writing routine of the compressor (and V8 cannot inline emit_code // because it is a closure here in a different context). Additionally // we can call emit_byte_to_buffer less often, because we can have // 30-bits (from our 31-bit signed SMI), and we know our codes will only // be 12-bits, so can safely have 18-bits there without overflow. // emit_code(ib_code); cur |= ib_code << cur_shift; cur_shift += cur_code_size; while (cur_shift >= 8) { buf[p++] = cur & 0xff; cur >>= 8; cur_shift -= 8; if (p === cur_subblock + 256) { // Finished a subblock. buf[cur_subblock] = 255; cur_subblock = p++; } } if (next_code === 4096) { // Table full, need a clear. emit_code(clear_code); next_code = eoi_code + 1; cur_code_size = min_code_size + 1; code_table = { }; } else { // Table not full, insert a new entry. // Increase our variable bit code sizes if necessary. This is a bit // tricky as it is based on "timing" between the encoding and // decoder. From the encoders perspective this should happen after // we've already emitted the index buffer and are about to create the // first table entry that would overflow our current code bit size. if (next_code >= (1 << cur_code_size)) ++cur_code_size; code_table[cur_key] = next_code++; // Insert into code table. } ib_code = k; // Index buffer to single input k. } else { ib_code = cur_code; // Index buffer to sequence in code table. } } emit_code(ib_code); // There will still be something in the index buffer. emit_code(eoi_code); // End Of Information. // Flush / finalize the sub-blocks stream to the buffer. emit_bytes_to_buffer(1); // Finish the sub-blocks, writing out any unfinished lengths and // terminating with a sub-block of length 0. If we have already started // but not yet used a sub-block it can just become the terminator. if (cur_subblock + 1 === p) { // Started but unused. buf[cur_subblock] = 0; } else { // Started and used, write length and additional terminator block. buf[cur_subblock] = p - cur_subblock - 1; buf[p++] = 0; } return p; }; var UGIF=function(){var a=function(){var j,F,c,b,H=0,k=0,Z=0,P=0,l=function(){var R=j>>>3,i=F[R+2]<<16|F[R+1]<<8|F[R],M=i>>>(j&7)&(1<>>7,P=b>>>4&7,X=b>>>3&1,l=b>>>0&7,m=f,e=0,V,W=0,G=0,C=0,z=260; if(Z==1)f+=3*(1<>>2&7;G=A();z=B();if((b&1)==0)z=260;B()}else if(L==254){U()}else if(L==255){U()}else throw L}else if(Q==44){var R=A(),i=A(),M=A(),v=A(),t=B(),q=t>>>7; C=t>>>6&1;if(q==1){var l=t>>>0&7;e=f;f+=3*(1<=O.length){alert("Some frames are damaged."); T.pop();break}B();V.d=new Uint8Array(S);var r=a(E,0,Y,V.d,0,Q)}else if(Q==59)break;else throw Q}return{width:F,height:c,data:O,frames:T}}; function D(j,F,O,c,b,H,k,Z){for(var P=0;P=0; k--) { line[k] *= l; } } /** * Add line number j multiplied by l to line number i */ Mat.prototype.addmul = function (i, j, l) { if (this.mirror) this.mirror.addmul(i,j,l); var lineI = this.data[i], lineJ = this.data[j]; for (var k=lineI.length-1; k>=0; k--) { lineI[k] = lineI[k] + l*lineJ[k]; } } /** * Tests if line number i is composed only of zeroes */ Mat.prototype.hasNullLine = function (i) { for (var j=0; j Math.abs(maxValue)) { maxLine = k; maxValue = val; } } if (maxValue === 0) { // The matrix is not invertible. The system may still have solutions. nullLines.push(pivot); } else { // The value of the pivot is maxValue this.multline(maxLine, 1/maxValue); this.swap(maxLine, pivot); for (var i=0; i 0 && result[0].length === 1) { // Convert Nx1 matrices to simple javascript arrays for (var i=0; i>8&255; h[d+1]=T&255},ae:function(h,d,T){var L=[];for(var e=0;e>24&255; h[d+1]=T>>16&255;h[d+2]=T>>8&255;h[d+3]=T>>0&255},f:function(h,d){return U.B.u(h,d)*(4294967295+1)+U.B.u(h,d+4)},z:function(h,d,T){var L=""; for(var e=0;e255)return-1; return U.T.$.b6(h,U.T.$.a_[d])},a0:function(h,d,T){var L=U.B,e=[".notdef"],G=h[d];d++;if(G==0){for(var B=0; B>4,m=$&15;if(x!=15)i.push(x);if(m!=15)i.push(m);if(m==15)break}var u=[0,1,2,3,4,5,6,7,8,9,".","e","e-","reserved","-","endOfNumber"]; for(var z=0;z>>1;T.az=e(h,d);d+=2;T.ad=e(h,d);d+=2; T.ar=e(h,d);d+=2;T.aL=G(h,d,Y);d+=Y*2;d+=2;T.af=G(h,d,Y);d+=Y*2;T.aB=[];for(var A=0;A>>1);return T},av:function(h,d,T){var L=U.B,e=d;d+=2;var G=L.d(h,d); d+=2;var B=L.d(h,d);d+=2;T.aU=L.d(h,d);d+=2;var f=L.d(h,d);d+=2;T.R=[];for(var O=0;O=f.ak||f.ag>=f.at)return null; if(f.j>0){f.h=[];for(var O=0;O>>8;A&=15;if(A==0)d=G.H(h,d,O)}return O},aO:function(h,d,T,L){var e=U.B,G=U.T.U,B=e.p(h,d),f=e.u(h,d+4); d+=8;var O={P:[],Z:[]};for(var s=0;s65535)G++;e.push(U.U.codeToGlyph(h,B))}var O=[]; for(var G=0;G>>1);if($[V*u]<=z)F=V; else a=V}return F*u},O=T.C[L],s=O.aw,Y=-1;if(s==0){if(d>=O.map.length)Y=0;else Y=O.map[d]}else if(s==4){var A=-1,t=O.aL; if(d>t[t.length-1])A=-1;else{A=B(t,1,d);if(t[A]>1)-(O.m.length-A)];else k=d+O.aB[A];Y=k&65535}}else if(s==6){var i=d-O.aU,$=O.R; if(i<0||i>=$.length)Y=0;else Y=$[i]}else if(s==12){var x=O.a9;if(d>x[x.length-2])Y=0;else{var G=B(x,3,d); if(x[G]<=d&&d<=x[G+1]){Y=x[G+2]+(d-x[G])}if(Y==-1)Y=0}}else throw"unknown cmap table format "+O.aw;var m=h["SVG "],n=h.loca; if(Y!=0&&h["CFF "]==null&&(m==null||m.entries[Y]==null)&&n[Y]==n[Y+1]&&[9,10,11,12,13,32,133,160,5760,8232,8233,8239,12288,6158,8203,8204,8205,8288,65279].indexOf(d)==-1&&!(8192<=d&&d<=8202))Y=0; return Y},glyphToPath:function(h,d){var T={B:[],b:[]},L=h["SVG "],e=h["CFF "],G=h.COLR,B=U.U;if(L&&L.entries[d]){var f=L.entries[d]; if(f!=null){if(typeof f=="string"){f=B.SVG.b7(f);L.entries[d]=f}T=f}}else if(G&&G[0]["g"+d]){function O(F){var a=F.toString(16); return(a.length==1?"0":"")+a}var s=h.CPAL,Y=G[0]["g"+d];for(var A=0;A-1)U.U._simpleGlyph(L,T);else U.U._compoGlyph(L,d,T)}},_simpleGlyph:function(h,d){var T=U.U.P; for(var L=0;L>1;G.length=0;f=!0}else if(y=="o3"||y=="o23"){var l;l=G.length%2!==0; if(l&&!f){O=G.shift()+K}B+=G.length>>1;G.length=0;f=!0}else if(y=="o4"){if(G.length>1&&!f){O=G.shift()+K; f=!0}if(s)j.D(e);t+=G.pop();j.G(e,A,t);s=!0}else if(y=="o5"){while(G.length>0){A+=G.shift();t+=G.shift(); j.J(e,A,t)}}else if(y=="o6"||y=="o7"){var D=G.length,Q=y=="o6";for(var o=0;oMath.abs(F-t)){A=z+G.shift()}else{t=F+G.shift()}j.l(e,k,$,x,m,H,b); j.l(e,n,u,z,F,A,t)}}else if(y=="o14"){if(G.length>0&&!f){O=G.shift()+T.nominalWidthX;f=!0}if(G.length==4){var a9=0,_=G.shift(),I=G.shift(),ah=G.shift(),a6=G.shift(),ae=g.Y(T,ah),a4=g.Y(T,a6); U.U._drawCFF(T.CharStrings[ae],d,T,L,e);d.x=_;d.y=I;U.U._drawCFF(T.CharStrings[a4],d,T,L,e)}if(s){j.D(e); s=!1}}else if(y=="o19"||y=="o20"){var l;l=G.length%2!==0;if(l&&!f){O=G.shift()+K}B+=G.length>>1;G.length=0; f=!0;Y+=B+7>>3}else if(y=="o21"){if(G.length>2&&!f){O=G.shift()+K;f=!0}t+=G.pop();A+=G.pop();if(s)j.D(e); j.G(e,A,t);s=!0}else if(y=="o22"){if(G.length>1&&!f){O=G.shift()+K;f=!0}A+=G.pop();if(s)j.D(e);j.G(e,A,t); s=!0}else if(y=="o25"){while(G.length>6){A+=G.shift();t+=G.shift();j.J(e,A,t)}k=A+G.shift();$=t+G.shift(); x=k+G.shift();m=$+G.shift();A=x+G.shift();t=m+G.shift();j.l(e,k,$,x,m,A,t)}else if(y=="o26"){if(G.length%2){A+=G.shift()}while(G.length>0){k=A; $=t+G.shift();x=k+G.shift();m=$+G.shift();A=x;t=m+G.shift();j.l(e,k,$,x,m,A,t)}}else if(y=="o27"){if(G.length%2){t+=G.shift()}while(G.length>0){k=A+G.shift(); $=t;x=k+G.shift();m=$+G.shift();A=x+G.shift();t=m;j.l(e,k,$,x,m,A,t)}}else if(y=="o10"||y=="o29"){var C=y=="o10"?L:T; if(G.length==0){console.log("error: empty stack")}else{var S=G.pop(),q=C.Subrs[S+C.Bias];d.x=A;d.y=t; d.N=B;d.w=f;d.width=O;d.open=s;U.U._drawCFF(q,d,T,L,e);A=d.x;t=d.y;B=d.N;f=d.w;O=d.width;s=d.open}}else if(y=="o30"||y=="o31"){var D,X=G.length,r=0,c=y=="o31"; D=X&~2;r+=X-D;while(r0&&A[i-1]!="e"){A=A.slice(0,i)+" "+A.slice(i); i++;k=!0}}A=A.split(/\s*[\s,]\s*/).map(parseFloat);if(!1){}else if(Y=="translate"){if(A.length==1)h.translate(t,A[0],0); else h.translate(t,A[0],A[1])}else if(Y=="scale"){if(A.length==1)h.scale(t,A[0],A[0]);else h.scale(t,A[0],A[1])}else if(Y=="rotate"){var x=0,m=0; if(A.length!=1){x=A[1];m=A[2]}h.translate(t,-x,-m);h.rotate(t,-Math.PI*A[0]/180);h.translate(t,x,m)}else if(Y=="matrix")t=A; else console.log("unknown transform: ",Y);return t}function G(Y){var A={B:[],b:[]};if(Y==null)return A; var t=new DOMParser,k=t.parseFromString(Y,"image/svg+xml"),i=k.getElementsByTagName("svg")[0],$=i.getAttribute("viewBox"); if($)$=$.trim().split(" ").map(parseFloat);else $=[0,0,1e3,1e3];B(i.children,A);for(var x=0;x=0?1:-1)*Math.acos(Math.max(-1,Math.min(1,as)))},a7=(X-ao)/I,aj=(c-a2)/v,am=ab(1,0,a7,aj),au=ab(a7,aj,(-X-ao)/I,(-c-a2)/v); au=au%(2*Math.PI);var ac=function(a8,i,$,R,P,M,E){var a5=function(w,Z){var an=Math.sin(Z),p=Math.cos(Z),Z=w[0],ai=w[1],ad=w[2],Y=w[3]; w[0]=Z*p+ai*an;w[1]=-Z*an+ai*p;w[2]=ad*p+Y*an;w[3]=-ad*an+Y*p},N=function(w,Z){for(var K=0;KP)M-=2*Math.PI;else while(M>>2,z=e.hb_buffer_get_glyph_positions(x,0)>>>2; for(var F=0;F>>16)+4)}B=new Uint8Array(G.buffer);f=new Uint32Array(G.buffer);O=new Int32Array(G.buffer); if(s!=z){if(Y!=null){e.hb_blob_destroy(Y);e.free(A);e.hb_face_destroy(t);e.hb_font_destroy(k)}A=e.malloc(u.byteLength); B.set(u,A);Y=e.hb_blob_create(A,u.byteLength,2,0,0);t=e.hb_face_create(Y,0);k=e.hb_font_create(t);s=z}if(window.TextEncoder==null){alert("Your browser is too old. Please, update it."); return}if($==null)$=new window.TextEncoder("utf8");var V=e.hb_buffer_create(),H=$.encode(m),b=H.length,g=e.malloc(b); B.set(H,g);e.hb_buffer_add_utf8(V,g,b,0,b);e.free(g);e.hb_buffer_set_direction(V,n?4:5);e.hb_buffer_guess_segment_properties(V); e.hb_shape(k,V,0,0);var j=i(V);e.hb_buffer_destroy(V);var K=j.slice(0);if(!n)K.reverse();for(var l=1; l8514000) { //console.log(PUtils.readASCII(buf , 8514500, 500)); //console.log(PUtils.readASCII(nbuf, 8514500, 500)); } for(var i=0; i>>4); //console.log(CM, CINFO,CMF,FLG); return UZIP.inflateRaw(new Uint8Array(file.buffer, file.byteOffset+2, file.length-6), buf); } UZIP.deflate = function(data, opts/*, buf, off*/) { if(opts==null) opts={level:6}; var off=0, buf=new Uint8Array(50+Math.floor(data.length*1.1)); buf[off]=120; buf[off+1]=156; off+=2; off = UZIP.F.deflateRaw(data, buf, off, opts.level); var crc = UZIP.adler(data, 0, data.length); buf[off+0]=((crc>>>24)&255); buf[off+1]=((crc>>>16)&255); buf[off+2]=((crc>>> 8)&255); buf[off+3]=((crc>>> 0)&255); return new Uint8Array(buf.buffer, 0, off+4); } UZIP.deflateRaw = function(data, opts) { if(opts==null) opts={level:6}; var buf=new Uint8Array(50+Math.floor(data.length*1.1)); var off = UZIP.F.deflateRaw(data, buf, off, opts.level); return new Uint8Array(buf.buffer, 0, off); } UZIP.encode = function(obj, noCmpr) { if(noCmpr==null) noCmpr=false; var tot = 0, wUi = UZIP.bin.writeUint, wUs = UZIP.bin.writeUshort; var zpd = {}; for(var p in obj) { var cpr = !UZIP._noNeed(p) && !noCmpr, buf = obj[p], crc = UZIP.crc.crc(buf,0,buf.length); zpd[p] = { cpr:cpr, usize:buf.length, crc:crc, file: (cpr ? UZIP.deflateRaw(buf) : buf) }; } for(var p in zpd) tot += zpd[p].file.length + 30 + 46 + 2*UZIP.bin.sizeUTF8(p); tot += 22; var data = new Uint8Array(tot), o = 0; var fof = [] for(var p in zpd) { var file = zpd[p]; fof.push(o); o = UZIP._writeHeader(data, o, p, file, 0); } var i=0, ioff = o; for(var p in zpd) { var file = zpd[p]; fof.push(o); o = UZIP._writeHeader(data, o, p, file, 1, fof[i++]); } var csize = o-ioff; wUi(data, o, 0x06054b50); o+=4; o += 4; // disks wUs(data, o, i); o += 2; wUs(data, o, i); o += 2; // number of c d records wUi(data, o, csize); o += 4; wUi(data, o, ioff ); o += 4; o += 2; return data.buffer; } // no need to compress .PNG, .ZIP, .JPEG .... UZIP._noNeed = function(fn) { var ext = fn.split(".").pop().toLowerCase(); return "png,jpg,jpeg,zip".indexOf(ext)!=-1; } UZIP._writeHeader = function(data, o, p, obj, t, roff) { var wUi = UZIP.bin.writeUint, wUs = UZIP.bin.writeUshort; var file = obj.file; wUi(data, o, t==0 ? 0x04034b50 : 0x02014b50); o+=4; // sign if(t==1) o+=2; // ver made by wUs(data, o, 20); o+=2; // ver wUs(data, o, 2048); o+=2; // gflip wUs(data, o, obj.cpr?8:0); o+=2; // cmpr wUi(data, o, 0); o+=4; // time wUi(data, o, obj.crc); o+=4; // crc32 wUi(data, o, file.length); o+=4; // csize wUi(data, o, obj.usize); o+=4; // usize wUs(data, o, UZIP.bin.sizeUTF8(p)); o+=2; // nlen wUs(data, o, 0); o+=2; // elen if(t==1) { o += 2; // comment length o += 2; // disk number o += 6; // attributes wUi(data, o, roff); o+=4; // usize } var nlen = UZIP.bin.writeUTF8(data, o, p); o+= nlen; if(t==0) { data.set(file, o); o += file.length; } return o; } UZIP.crc = { table : ( function() { var tab = new Uint32Array(256); for (var n=0; n<256; n++) { var c = n; for (var k=0; k<8; k++) { if (c & 1) c = 0xedb88320 ^ (c >>> 1); else c = c >>> 1; } tab[n] = c; } return tab; })(), update : function(c, buf, off, len) { for (var i=0; i>> 8); return c; }, crc : function(b,o,l) { return UZIP.crc.update(0xffffffff,b,o,l) ^ 0xffffffff; } } UZIP.adler = function(data,o,len) { var a = 1, b = 0; var off = o, end=o+len; while(off>8)&255; }, readUint : function(buff,p) { return (buff[p+3]*(256*256*256)) + ((buff[p+2]<<16) | (buff[p+1]<< 8) | buff[p]); }, writeUint : function(buff,p,n){ buff[p]=n&255; buff[p+1]=(n>>8)&255; buff[p+2]=(n>>16)&255; buff[p+3]=(n>>24)&255; }, readASCII : function(buff,p,l){ var s = ""; for(var i=0; i> 6)); buff[p+i+1] = (128|((code>> 0)&63)); i+=2; } else if((code&(0xffffffff-(1<<16)+1))==0) { buff[p+i] = (224|(code>>12)); buff[p+i+1] = (128|((code>> 6)&63)); buff[p+i+2] = (128|((code>>0)&63)); i+=3; } else if((code&(0xffffffff-(1<<21)+1))==0) { buff[p+i] = (240|(code>>18)); buff[p+i+1] = (128|((code>>12)&63)); buff[p+i+2] = (128|((code>>6)&63)); buff[p+i+3] = (128|((code>>0)&63)); i+=4; } else throw "e"; } return i; }, sizeUTF8 : function(str) { var strl = str.length, i=0; for(var ci=0; ci>>3; } var lits = U.lits, strt=U.strt, prev=U.prev, li=0, lc=0, bs=0, ebits=0, c=0, nc=0; // last_item, literal_count, block_start if(dlen>2) { nc=UZIP.F._hash(data,0); strt[nc]=0; } var nmch=0,nmci=0; for(i=0; i14000 || lc>26697) && (dlen-i)>100) { if(cvrd>>16)>>16)>(mch>>>16)) mch=0; }//*/ var len = mch>>>16, dst = mch&0xffff; //if(i-dst<0) throw "e"; if(mch!=0) { var len = mch>>>16, dst = mch&0xffff; //if(i-dst<0) throw "e"; var lgi = goodIndex(len, U.of0); U.lhst[257+lgi]++; var dgi = goodIndex(dst, U.df0); U.dhst[ dgi]++; ebits += U.exb[lgi] + U.dxb[dgi]; lits[li] = (len<<23)|(i-cvrd); lits[li+1] = (dst<<16)|(lgi<<8)|dgi; li+=2; cvrd = i + len; } else { U.lhst[data[i]]++; } lc++; } } if(bs!=i || data.length==0) { if(cvrd>>3; } UZIP.F._bestMatch = function(data, i, prev, c, nice, chain) { var ci = (i&0x7fff), pi=prev[ci]; //console.log("----", i); var dif = ((ci-pi + (1<<15)) & 0x7fff); if(pi==ci || c!=UZIP.F._hash(data,i-dif)) return 0; var tl=0, td=0; // top length, top distance var dlim = Math.min(0x7fff, i); while(dif<=dlim && --chain!=0 && pi!=ci /*&& c==UZIP.F._hash(data,i-dif)*/) { if(tl==0 || (data[i+tl]==data[i+tl-dif])) { var cl = UZIP.F._howLong(data, i, dif); if(cl>tl) { tl=cl; td=dif; if(tl>=nice) break; //* if(dif+2maxd) { maxd=curd; pi = ei; } } //*/ } } ci=pi; pi = prev[ci]; dif += ((ci-pi + (1<<15)) & 0x7fff); } return (tl<<16)|td; } UZIP.F._howLong = function(data, i, dif) { if(data[i]!=data[i-dif] || data[i+1]!=data[i+1-dif] || data[i+2]!=data[i+2-dif]) return 0; var oi=i, l = Math.min(data.length, i+258); i+=3; //while(i+4>>23), end = off+(qb&((1<<23)-1)); while(off>16), lgi=(qc>>8)&255, dgi=(qc&255); pos = UZIP.F._writeLit(257+lgi, ltree, out, pos); putsE(out, pos, len-U.of0[lgi]); pos+=U.exb[lgi]; pos = UZIP.F._writeLit(dgi, dtree, out, pos); putsF(out, pos, dst-U.df0[dgi]); pos+=U.dxb[dgi]; off+=len; } } pos = UZIP.F._writeLit(256, ltree, out, pos); } //console.log(pos-opos, fxdSize, dynSize, cstSize); return pos; } UZIP.F._copyExact = function(data,off,len,out,pos) { var p8 = (pos>>>3); out[p8]=(len); out[p8+1]=(len>>>8); out[p8+2]=255-out[p8]; out[p8+3]=255-out[p8+1]; p8+=4; out.set(new Uint8Array(data.buffer, off, len), p8); //for(var i=0; i4 && U.itree[(U.ordr[numh-1]<<1)+1]==0) numh--; return [ML, MD, MH, numl, numd, numh, lset, dset]; } UZIP.F.getSecond= function(a) { var b=[]; for(var i=0; i>1)+","; return b; } UZIP.F.contSize = function(tree, hst) { var s=0; for(var i=0; i15) { UZIP.F._putsE(out, pos, rst, rsl); pos+=rsl; } } return pos; } UZIP.F._lenCodes = function(tree, set) { var len=tree.length; while(len!=2 && tree[len-1]==0) len-=2; // when no distances, keep one code with length 0 for(var i=0; i>>1, 138); if(zc<11) set.push(17, zc-3); else set.push(18, zc-11); i += zc*2-2; } else if(l==prv && nxt==l && nnxt==l) { var lz = i+5; while(lz+2>>1, 6); set.push(16, zc-3); i += zc*2-2; } else set.push(l, 0); } return len>>>1; } UZIP.F._hufTree = function(hst, tree, MAXL) { var list=[], hl = hst.length, tl=tree.length, i=0; for(i=0; iMAXL) { UZIP.F.restrictDepth(l2, MAXL, maxl); maxl = MAXL; } for(i=0; iMD) { var od=dps[i].d; dps[i].d=MD; dbt+=bCost-(1<<(maxl-od)); } else break; dbt = dbt>>>(maxl-MD); while(dbt>0) { var od=dps[i].d; if(od=0; i--) if(dps[i].d==MD && dbt<0) { dps[i].d--; dbt++; } if(dbt!=0) console.log("debt left"); } UZIP.F._goodIndex = function(v, arr) { var i=0; if(arr[i|16]<=v) i|=16; if(arr[i|8]<=v) i|=8; if(arr[i|4]<=v) i|=4; if(arr[i|2]<=v) i|=2; if(arr[i|1]<=v) i|=1; return i; } UZIP.F._writeLit = function(ch, ltree, out, pos) { UZIP.F._putsF(out, pos, ltree[ch<<1]); return pos+ltree[(ch<<1)+1]; } UZIP.F.inflate = function(data, buf) { var u8=Uint8Array; if(data[0]==3 && data[1]==0) return (buf ? buf : new u8(0)); var F=UZIP.F, bitsF = F._bitsF, bitsE = F._bitsE, decodeTiny = F._decodeTiny, makeCodes = F.makeCodes, codes2map=F.codes2map, get17 = F._get17; var U = F.U; var noBuf = (buf==null); if(noBuf) buf = new u8((data.length>>>2)<<3); var BFINAL=0, BTYPE=0, HLIT=0, HDIST=0, HCLEN=0, ML=0, MD=0; var off = 0, pos = 0; var lmap, dmap; while(BFINAL==0) { BFINAL = bitsF(data, pos , 1); BTYPE = bitsF(data, pos+1, 2); pos+=3; //console.log(BFINAL, BTYPE); if(BTYPE==0) { if((pos&7)!=0) pos+=8-(pos&7); var p8 = (pos>>>3)+4, len = data[p8-4]|(data[p8-3]<<8); //console.log(len);//bitsF(data, pos, 16), if(noBuf) buf=UZIP.F._check(buf, off+len); buf.set(new u8(data.buffer, data.byteOffset+p8, len), off); //for(var i=0; itl)tl=l; } pos+=3*HCLEN; //console.log(itree); makeCodes(U.itree, tl); codes2map(U.itree, tl, U.imap); lmap = U.lmap; dmap = U.dmap; pos = decodeTiny(U.imap, (1<>>24))-1; pos+=(ml&0xffffff); makeCodes(U.ltree, mx0); codes2map(U.ltree, mx0, lmap); //var md = decodeTiny(U.imap, (1<>>24))-1; pos+=(md&0xffffff); makeCodes(U.dtree, mx1); codes2map(U.dtree, mx1, dmap); } //var ooff=off, opos=pos; while(true) { var code = lmap[get17(data, pos) & ML]; pos += code&15; var lit = code>>>4; //U.lhst[lit]++; if((lit>>>8)==0) { buf[off++] = lit; } else if(lit==256) { break; } else { var end = off+lit-254; if(lit>264) { var ebs = U.ldef[lit-257]; end = off + (ebs>>>3) + bitsE(data, pos, ebs&7); pos += ebs&7; } //UZIP.F.dst[end-off]++; var dcode = dmap[get17(data, pos) & MD]; pos += dcode&15; var dlit = dcode>>>4; var dbs = U.ddef[dlit], dst = (dbs>>>4) + bitsF(data, pos, dbs&15); pos += dbs&15; //var o0 = off-dst, stp = Math.min(end-off, dst); //if(stp>20) while(off>>3); } //console.log(UZIP.F.dst); //console.log(tlen, dlen, off-tlen+tcnt); return buf.length==off ? buf : buf.slice(0,off); } UZIP.F._check=function(buf, len) { var bl=buf.length; if(len<=bl) return buf; var nbuf = new Uint8Array(Math.max(bl<<1,len)); nbuf.set(buf,0); //for(var i=0; i>>4; if(lit<=15) { tree[i]=lit; i++; } else { var ll = 0, n = 0; if(lit==16) { n = (3 + bitsE(data, pos, 2)); pos += 2; ll = tree[i-1]; } else if(lit==17) { n = (3 + bitsE(data, pos, 3)); pos += 3; } else if(lit==18) { n = (11 + bitsE(data, pos, 7)); pos += 7; } var ni = i+n; while(i>>1; while(imx)mx=v; i++; } while(i>1; var cl = tree[i+1], val = (lit<<4)|cl; // : (0x8000 | (U.of0[lit-257]<<7) | (U.exb[lit-257]<<4) | cl); var rest = (MAX_BITS-cl), i0 = tree[i]<>>(15-MAX_BITS); while(i0!=i1) { var p0 = r15[i0]>>>(15-MAX_BITS); map[p0]=val; i0++; } } } UZIP.F.revCodes = function(tree, MAX_BITS) { var r15 = UZIP.F.U.rev15, imb = 15-MAX_BITS; for(var i=0; i>>imb; } } // used only in deflate UZIP.F._putsE= function(dt, pos, val ) { val = val<<(pos&7); var o=(pos>>>3); dt[o]|=val; dt[o+1]|=(val>>>8); } UZIP.F._putsF= function(dt, pos, val ) { val = val<<(pos&7); var o=(pos>>>3); dt[o]|=val; dt[o+1]|=(val>>>8); dt[o+2]|=(val>>>16); } UZIP.F._bitsE= function(dt, pos, length) { return ((dt[pos>>>3] | (dt[(pos>>>3)+1]<<8) )>>>(pos&7))&((1<>>3] | (dt[(pos>>>3)+1]<<8) | (dt[(pos>>>3)+2]<<16))>>>(pos&7))&((1<>>3] | (dt[(pos>>>3)+1]<<8))>>>(pos&7))&511; } */ UZIP.F._get17= function(dt, pos) { // return at least 17 meaningful bytes return (dt[pos>>>3] | (dt[(pos>>>3)+1]<<8) | (dt[(pos>>>3)+2]<<16) )>>>(pos&7); } UZIP.F._get25= function(dt, pos) { // return at least 17 meaningful bytes return (dt[pos>>>3] | (dt[(pos>>>3)+1]<<8) | (dt[(pos>>>3)+2]<<16) | (dt[(pos>>>3)+3]<<24) )>>>(pos&7); } UZIP.F.U = function(){ var u16=Uint16Array, u32=Uint32Array; return { next_code : new u16(16), bl_count : new u16(16), ordr : [ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ], of0 : [3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999], exb : [0,0,0,0,0,0,0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0], ldef : new u16(32), df0 : [1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577, 65535, 65535], dxb : [0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0], ddef : new u32(32), flmap: new u16( 512), fltree: [], fdmap: new u16( 32), fdtree: [], lmap : new u16(32768), ltree : [], ttree:[], dmap : new u16(32768), dtree : [], imap : new u16( 512), itree : [], //rev9 : new u16( 512) rev15: new u16(1<<15), lhst : new u32(286), dhst : new u32( 30), ihst : new u32(19), lits : new u32(15000), strt : new u16(1<<16), prev : new u16(1<<15) }; } (); (function(){ var U = UZIP.F.U; var len = 1<<15; for(var i=0; i>> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >>> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >>> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >>> 8) | ((x & 0x00ff00ff) << 8)); U.rev15[i] = (((x >>> 16) | (x << 16)))>>>17; } function pushV(tgt, n, sv) { while(n--!=0) tgt.push(0,sv); } for(var i=0; i<32; i++) { U.ldef[i]=(U.of0[i]<<3)|U.exb[i]; U.ddef[i]=(U.df0[i]<<4)|U.dxb[i]; } pushV(U.fltree, 144, 8); pushV(U.fltree, 255-143, 9); pushV(U.fltree, 279-255, 7); pushV(U.fltree,287-279,8); /* var i = 0; for(; i<=143; i++) U.fltree.push(0,8); for(; i<=255; i++) U.fltree.push(0,9); for(; i<=279; i++) U.fltree.push(0,7); for(; i<=287; i++) U.fltree.push(0,8); */ UZIP.F.makeCodes(U.fltree, 9); UZIP.F.codes2map(U.fltree, 9, U.flmap); UZIP.F.revCodes (U.fltree, 9) pushV(U.fdtree,32,5); //for(i=0;i<32; i++) U.fdtree.push(0,5); UZIP.F.makeCodes(U.fdtree, 5); UZIP.F.codes2map(U.fdtree, 5, U.fdmap); UZIP.F.revCodes (U.fdtree, 5) pushV(U.itree,19,0); pushV(U.ltree,286,0); pushV(U.dtree,30,0); pushV(U.ttree,320,0); /* for(var i=0; i< 19; i++) U.itree.push(0,0); for(var i=0; i<286; i++) U.ltree.push(0,0); for(var i=0; i< 30; i++) U.dtree.push(0,0); for(var i=0; i<320; i++) U.ttree.push(0,0); */ })() var paper=function(t,e){var i=(t=t||require("./node/self.js")).window,n=t.document,r=new function(){function t(t,e,r,s,a){function u(n,u){"string"==typeof(u=u||(u=o(e,n))&&(u.get?u:u.value))&&"#"===u[0]&&(u=t[u.substring(1)]||u);var c,f="function"==typeof u,d=u,_=a||f&&!u.base?u&&u.get?n in t:t[n]:null;a&&_||(f&&_&&(u.base=_),f&&!1!==s&&(c=n.match(/^([gs]et|is)(([A-Z])(.*))$/))&&(l[c[3].toLowerCase()+c[4]]=c[2]),d&&!f&&d.get&&"function"==typeof d.get&&i.isPlainObject(d)||(d={value:d,writable:!0}),(o(t,n)||{configurable:!0}).configurable&&(d.configurable=!0,d.enumerable=null!=r?r:!c),h(t,n,d))}var l={};if(e){for(var c in e)e.hasOwnProperty(c)&&!n.test(c)&&u(c);for(var c in l){var f=l[c],d=t["set"+f],_=t["get"+f]||d&&t["is"+f];!_||!0!==s&&0!==_.length||u(c,{get:_,set:d})}}return t}function i(){for(var t=0,e=arguments.length;t0||u+s0?[["dictionary",n.definitions],s]:s},deserialize:function(t,e,i,n,s){var a=t,o=!i,h=o&&t&&t.length&&"dictionary"===t[0][0];if(i=i||{},Array.isArray(t)){var u=t[0],l="dictionary"===u;if(1==t.length&&/^#/.test(u))return i.dictionary[u];a=[];for(var c=(u=r.exports[u])?1:0,f=t.length;ct.length&&(n=t.length);for(u=0;u0){var s=e[r],a=s&&s[n];a&&a.call(this,r)}},statics:{inject:function t(e){var i=e._events;if(i){var n={};r.each(i,function(t,i){var s="string"==typeof t,a=s?t:i,o=r.capitalize(a),h=a.substring(2).toLowerCase();n[h]=s?{}:t,a="_"+a,e["get"+o]=function(){return this[a]},e["set"+o]=function(t){var e=this[a];e&&this.off(h,e),t&&this.on(h,t),this[a]=t}}),e._eventTypes=n}return t.base.apply(this,arguments)}}},a=r.extend({_class:"PaperScope",initialize:function e(){paper=this,this.settings=new r({applyMatrix:!0,insertItems:!0,handleSize:4,hitTolerance:0}),this.project=null,this.projects=[],this.tools=[],this._id=e._id++,e._scopes[this._id]=this;var i=e.prototype;if(!this.support){var n=Q.getContext(1,1)||{};i.support={nativeDash:"setLineDash"in n||"mozDash"in n,nativeBlendModes:tt.nativeModes},Q.release(n)}if(!this.agent){var s=t.navigator.userAgent.toLowerCase(),a=(/(darwin|win|mac|linux|freebsd|sunos)/.exec(s)||[])[0],o="darwin"===a?"mac":a,h=i.agent=i.browser={platform:o};o&&(h[o]=!0),s.replace(/(opera|chrome|safari|webkit|firefox|msie|trident|atom|node)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:v?([.\d]+))?/g,function(t,e,i,n,r){if(!h.chrome){var s="opera"===e?n:/^(node|trident)$/.test(e)?r:i;h.version=s,h.versionNumber=parseFloat(s),e="trident"===e?"msie":e,h.name=e,h[e]=!0}}),h.chrome&&delete h.webkit,h.atom&&delete h.chrome}},version:"0.11.5",getView:function(){var t=this.project;return t&&t._view},getPaper:function(){return this},execute:function(t,e){paper.PaperScript.execute(t,this,e),U.updateFocus()},install:function(t){var e=this;r.each(["project","view","tool"],function(i){r.define(t,i,{configurable:!0,get:function(){return e[i]}})});for(var i in this)!/^_/.test(i)&&this[i]&&(t[i]=this[i])},setup:function(t){return paper=this,this.project=new y(t),this},createCanvas:function(t,e){return Q.getCanvas(t,e)},activate:function(){paper=this},clear:function(){for(var t=this.projects,e=this.tools,i=t.length-1;i>=0;i--)t[i].remove();for(i=e.length-1;i>=0;i--)e[i].remove()},remove:function(){this.clear(),delete a._scopes[this._id]},statics:new function(){function t(t){return t+="Attribute",function(e,i){return e[t](i)||e[t]("data-paper-"+i)}}return{_scopes:{},_id:0,get:function(t){return this._scopes[t]||null},getAttribute:t("get"),hasAttribute:t("has")}}}),o=r.extend(s,{initialize:function(t){this._scope=paper,this._index=this._scope[this._list].push(this)-1,!t&&this._scope[this._reference]||this.activate()},activate:function(){if(!this._scope)return!1;var t=this._scope[this._reference];return t&&t!==this&&t.emit("deactivate"),this._scope[this._reference]=this,this.emit("activate",t),!0},isActive:function(){return this._scope[this._reference]===this},remove:function(){return null!=this._index&&(r.splice(this._scope[this._list],null,this._index,1),this._scope[this._reference]==this&&(this._scope[this._reference]=null),this._scope=null,!0)},getView:function(){return this._scope.getView()}}),h=r.extend({initialize:function(t){this.precision=r.pick(t,5),this.multiplier=Math.pow(10,this.precision)},number:function(t){return this.precision<16?Math.round(t*this.multiplier)/this.multiplier:t},pair:function(t,e,i){return this.number(t)+(i||",")+this.number(e)},point:function(t,e){return this.number(t.x)+(e||",")+this.number(t.y)},size:function(t,e){return this.number(t.width)+(e||",")+this.number(t.height)},rectangle:function(t,e){return this.point(t,e)+(e||",")+this.size(t,e)}});h.instance=new h;var u=new function(){function t(t,e,i){return ti?i:t}function e(t,e,i){function n(t){var e=134217729*t,i=t-e+e;return[i,t-i]}var r=e*e-t*i,a=e*e+t*i;if(3*s(r)1e8)?o(2,-Math.round(h(t))):0}var n=[[.5773502691896257],[0,.7745966692414834],[.33998104358485626,.8611363115940526],[0,.5384693101056831,.906179845938664],[.2386191860831969,.6612093864662645,.932469514203152],[0,.4058451513773972,.7415311855993945,.9491079123427585],[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],[0,.3242534234038089,.6133714327005904,.8360311073266358,.9681602395076261],[.14887433898163122,.4333953941292472,.6794095682990244,.8650633666889845,.9739065285171717],[0,.26954315595234496,.5190961292068118,.7301520055740494,.8870625997680953,.978228658146057],[.1252334085114689,.3678314989981802,.5873179542866175,.7699026741943047,.9041172563704749,.9815606342467192],[0,.2304583159551348,.44849275103644687,.6423493394403402,.8015780907333099,.9175983992229779,.9841830547185881],[.10805494870734367,.31911236892788974,.5152486363581541,.6872929048116855,.827201315069765,.9284348836635735,.9862838086968123],[0,.20119409399743451,.3941513470775634,.5709721726085388,.7244177313601701,.8482065834104272,.937273392400706,.9879925180204854],[.09501250983763744,.2816035507792589,.45801677765722737,.6178762444026438,.755404408355003,.8656312023878318,.9445750230732326,.9894009349916499]],r=[[1],[.8888888888888888,.5555555555555556],[.6521451548625461,.34785484513745385],[.5688888888888889,.47862867049936647,.23692688505618908],[.46791393457269104,.3607615730481386,.17132449237917036],[.4179591836734694,.3818300505051189,.27970539148927664,.1294849661688697],[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626],[.3302393550012598,.31234707704000286,.26061069640293544,.1806481606948574,.08127438836157441],[.29552422471475287,.26926671930999635,.21908636251598204,.1494513491505806,.06667134430868814],[.2729250867779006,.26280454451024665,.23319376459199048,.18629021092773426,.1255803694649046,.05566856711617366],[.24914704581340277,.2334925365383548,.20316742672306592,.16007832854334622,.10693932599531843,.04717533638651183],[.2325515532308739,.22628318026289723,.2078160475368885,.17814598076194574,.13887351021978725,.09212149983772845,.04048400476531588],[.2152638534631578,.2051984637212956,.18553839747793782,.15720316715819355,.12151857068790319,.08015808715976021,.03511946033175186],[.2025782419255613,.19843148532711158,.1861610000155622,.16626920581699392,.13957067792615432,.10715922046717194,.07036604748810812,.03075324199611727],[.1894506104550685,.18260341504492358,.16915651939500254,.14959598881657674,.12462897125553388,.09515851168249279,.062253523938647894,.027152459411754096]],s=Math.abs,a=Math.sqrt,o=Math.pow,h=Math.log2||function(t){return Math.log(t)*Math.LOG2E};return{EPSILON:1e-12,MACHINE_EPSILON:1.12e-16,CURVETIME_EPSILON:1e-8,GEOMETRIC_EPSILON:1e-7,TRIGONOMETRIC_EPSILON:1e-8,KAPPA:4*(a(2)-1)/3,isZero:function(t){return t>=-1e-12&&t<=1e-12},clamp:t,integrate:function(t,e,i,s){for(var a=n[s-2],o=r[s-2],h=.5*(i-e),u=h+e,l=0,c=s+1>>1,f=1&s?o[l++]*t(u):0;l0?(a=n,n=f<=r?.5*(r+a):f):(r=n,n=f>=a?.5*(r+a):f)}return t(n,r,a)},solveQuadratic:function(n,r,o,h,u,l){var c,f=1/0;if(s(n)<1e-12){if(s(r)<1e-12)return s(o)<1e-12?-1:0;c=-o/r}else{var d=e(n,r*=-.5,o);if(d&&s(d)<1.12e-16){var _=i(s(n),s(r),s(o));_&&(d=e(n*=_,r*=_,o*=_))}if(d>=-1.12e-16){var g=d<0?0:a(d),v=r+(r<0?-g:g);0===v?f=-(c=o/n):(c=v/n,f=o/v)}}var p=0,m=null==u,y=u-1e-12,w=l+1e-12;return isFinite(c)&&(m||c>y&&cy&&f0?1.324717957244746*Math.max(x,a(C)):x,P=_-b*S;if(P!==_){do{d(P),P=0===p?_:_-m/p/(1+1.12e-16)}while(b*P>b*_);s(e)*_*_>s(h/_)&&(g=((v=-h/_)-r)/_)}}var I=u.solveQuadratic(e,g,v,l,c,f),M=null==c;return isFinite(_)&&(0===I||I>0&&_!==l[0]&&_!==l[1])&&(M||_>c-1e-12&&_1?a[1]:a[0])):"x"in a?this._set(a.x||0,a.y||0):"width"in a?this._set(a.width||0,a.height||0):"angle"in a?(this._set(a.length||0,0),this.setAngle(a.angle||0)):(this._set(0,0),r=0)}return n&&(this.__read=r),this},set:"#initialize",_set:function(t,e){return this.x=t,this.y=e,this},equals:function(t){return this===t||t&&(this.x===t.x&&this.y===t.y||Array.isArray(t)&&this.x===t[0]&&this.y===t[1])||!1},clone:function(){return new c(this.x,this.y)},toString:function(){var t=h.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y)]},getLength:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},setLength:function(t){if(this.isZero()){var e=this._angle||0;this._set(Math.cos(e)*t,Math.sin(e)*t)}else{var i=t/this.getLength();u.isZero(i)&&this.getAngle(),this._set(this.x*i,this.y*i)}},getAngle:function(){return 180*this.getAngleInRadians.apply(this,arguments)/Math.PI},setAngle:function(t){this.setAngleInRadians.call(this,t*Math.PI/180)},getAngleInDegrees:"#getAngle",setAngleInDegrees:"#setAngle",getAngleInRadians:function(){if(arguments.length){var t=c.read(arguments),e=this.getLength()*t.getLength();if(u.isZero(e))return NaN;var i=this.dot(t)/e;return Math.acos(i<-1?-1:i>1?1:i)}return this.isZero()?this._angle||0:this._angle=Math.atan2(this.y,this.x)},setAngleInRadians:function(t){if(this._angle=t,!this.isZero()){var e=this.getLength();this._set(Math.cos(t)*e,Math.sin(t)*e)}},getQuadrant:function(){return this.x>=0?this.y>=0?1:4:this.y>=0?2:3}},{beans:!1,getDirectedAngle:function(){var t=c.read(arguments);return 180*Math.atan2(this.cross(t),this.dot(t))/Math.PI},getDistance:function(){var t=c.read(arguments),e=t.x-this.x,i=t.y-this.y,n=e*e+i*i;return r.read(arguments)?n:Math.sqrt(n)},normalize:function(t){t===e&&(t=1);var i=this.getLength(),n=0!==i?t/i:0,r=new c(this.x*n,this.y*n);return n>=0&&(r._angle=this._angle),r},rotate:function(t,e){if(0===t)return this.clone();t=t*Math.PI/180;var i=e?this.subtract(e):this,n=Math.sin(t),r=Math.cos(t);return i=new c(i.x*r-i.y*n,i.x*n+i.y*r),e?i.add(e):i},transform:function(t){return t?t._transformPoint(this):this},add:function(){var t=c.read(arguments);return new c(this.x+t.x,this.y+t.y)},subtract:function(){var t=c.read(arguments);return new c(this.x-t.x,this.y-t.y)},multiply:function(){var t=c.read(arguments);return new c(this.x*t.x,this.y*t.y)},divide:function(){var t=c.read(arguments);return new c(this.x/t.x,this.y/t.y)},modulo:function(){var t=c.read(arguments);return new c(this.x%t.x,this.y%t.y)},negate:function(){return new c(-this.x,-this.y)},isInside:function(){return g.read(arguments).contains(this)},isClose:function(){var t=c.read(arguments),e=r.read(arguments);return this.getDistance(t)<=e},isCollinear:function(){var t=c.read(arguments);return c.isCollinear(this.x,this.y,t.x,t.y)},isColinear:"#isCollinear",isOrthogonal:function(){var t=c.read(arguments);return c.isOrthogonal(this.x,this.y,t.x,t.y)},isZero:function(){var t=u.isZero;return t(this.x)&&t(this.y)},isNaN:function(){return isNaN(this.x)||isNaN(this.y)},isInQuadrant:function(t){return this.x*(t>1&&t<4?-1:1)>=0&&this.y*(t>2?-1:1)>=0},dot:function(){var t=c.read(arguments);return this.x*t.x+this.y*t.y},cross:function(){var t=c.read(arguments);return this.x*t.y-this.y*t.x},project:function(){var t=c.read(arguments),e=t.isZero()?0:this.dot(t)/t.dot(t);return new c(t.x*e,t.y*e)},statics:{min:function(){var t=c.read(arguments),e=c.read(arguments);return new c(Math.min(t.x,e.x),Math.min(t.y,e.y))},max:function(){var t=c.read(arguments),e=c.read(arguments);return new c(Math.max(t.x,e.x),Math.max(t.y,e.y))},random:function(){return new c(Math.random(),Math.random())},isCollinear:function(t,e,i,n){return Math.abs(t*n-e*i)<=1e-8*Math.sqrt((t*t+e*e)*(i*i+n*n))},isOrthogonal:function(t,e,i,n){return Math.abs(t*i+e*n)<=1e-8*Math.sqrt((t*t+e*e)*(i*i+n*n))}}},r.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new c(e(this.x),e(this.y))}},{})),f=c.extend({initialize:function(t,e,i,n){this._x=t,this._y=e,this._owner=i,this._setter=n},_set:function(t,e,i){return this._x=t,this._y=e,i||this._owner[this._setter](this),this},getX:function(){return this._x},setX:function(t){this._x=t,this._owner[this._setter](this)},getY:function(){return this._y},setY:function(t){this._y=t,this._owner[this._setter](this)},isSelected:function(){return!!(this._owner._selection&this._getSelection())},setSelected:function(t){this._owner._changeSelection(this._getSelection(),t)},_getSelection:function(){return"setPosition"===this._setter?4:0}}),d=r.extend({_class:"Size",_readIndex:!0,initialize:function(t,e){var i=typeof t,n=this.__read,r=0;if("number"===i){var s="number"==typeof e;this._set(t,s?e:t),n&&(r=s?2:1)}else if("undefined"===i||null===t)this._set(0,0),n&&(r=null===t?1:0);else{var a="string"===i?t.split(/[\s,]+/)||[]:t;r=1,Array.isArray(a)?this._set(+a[0],+(a.length>1?a[1]:a[0])):"width"in a?this._set(a.width||0,a.height||0):"x"in a?this._set(a.x||0,a.y||0):(this._set(0,0),r=0)}return n&&(this.__read=r),this},set:"#initialize",_set:function(t,e){return this.width=t,this.height=e,this},equals:function(t){return t===this||t&&(this.width===t.width&&this.height===t.height||Array.isArray(t)&&this.width===t[0]&&this.height===t[1])||!1},clone:function(){return new d(this.width,this.height)},toString:function(){var t=h.instance;return"{ width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.width),e.number(this.height)]},add:function(){var t=d.read(arguments);return new d(this.width+t.width,this.height+t.height)},subtract:function(){var t=d.read(arguments);return new d(this.width-t.width,this.height-t.height)},multiply:function(){var t=d.read(arguments);return new d(this.width*t.width,this.height*t.height)},divide:function(){var t=d.read(arguments);return new d(this.width/t.width,this.height/t.height)},modulo:function(){var t=d.read(arguments);return new d(this.width%t.width,this.height%t.height)},negate:function(){return new d(-this.width,-this.height)},isZero:function(){var t=u.isZero;return t(this.width)&&t(this.height)},isNaN:function(){return isNaN(this.width)||isNaN(this.height)},statics:{min:function(t,e){return new d(Math.min(t.width,e.width),Math.min(t.height,e.height))},max:function(t,e){return new d(Math.max(t.width,e.width),Math.max(t.height,e.height))},random:function(){return new d(Math.random(),Math.random())}}},r.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new d(e(this.width),e(this.height))}},{})),_=d.extend({initialize:function(t,e,i,n){this._width=t,this._height=e,this._owner=i,this._setter=n},_set:function(t,e,i){return this._width=t,this._height=e,i||this._owner[this._setter](this),this},getWidth:function(){return this._width},setWidth:function(t){this._width=t,this._owner[this._setter](this)},getHeight:function(){return this._height},setHeight:function(t){this._height=t,this._owner[this._setter](this)}}),g=r.extend({_class:"Rectangle",_readIndex:!0,beans:!0,initialize:function(t,i,n,s){var a,o=typeof t;if("number"===o?(this._set(t,i,n,s),a=4):"undefined"===o||null===t?(this._set(0,0,0,0),a=null===t?1:0):1===arguments.length&&(Array.isArray(t)?(this._set.apply(this,t),a=1):t.x!==e||t.width!==e?(this._set(t.x||0,t.y||0,t.width||0,t.height||0),a=1):t.from===e&&t.to===e&&(this._set(0,0,0,0),r.filter(this,t),a=1)),a===e){var h,u,l=c.readNamed(arguments,"from"),f=r.peek(arguments),_=l.x,g=l.y;if(f&&f.x!==e||r.hasNamed(arguments,"to")){var v=c.readNamed(arguments,"to");h=v.x-_,u=v.y-g,h<0&&(_=v.x,h=-h),u<0&&(g=v.y,u=-u)}else{var p=d.read(arguments);h=p.width,u=p.height}this._set(_,g,h,u),a=arguments.__index;var m=arguments.__filtered;m&&(this.__filtered=m)}return this.__read&&(this.__read=a),this},set:"#initialize",_set:function(t,e,i,n){return this.x=t,this.y=e,this.width=i,this.height=n,this},clone:function(){return new g(this.x,this.y,this.width,this.height)},equals:function(t){var e=r.isPlainValue(t)?g.read(arguments):t;return e===this||e&&this.x===e.x&&this.y===e.y&&this.width===e.width&&this.height===e.height||!1},toString:function(){var t=h.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+", width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y),e.number(this.width),e.number(this.height)]},getPoint:function(t){return new(t?c:f)(this.x,this.y,this,"setPoint")},setPoint:function(){var t=c.read(arguments);this.x=t.x,this.y=t.y},getSize:function(t){return new(t?d:_)(this.width,this.height,this,"setSize")},_fw:1,_fh:1,setSize:function(){var t=d.read(arguments),e=this._sx,i=this._sy,n=t.width,r=t.height;e&&(this.x+=(this.width-n)*e),i&&(this.y+=(this.height-r)*i),this.width=n,this.height=r,this._fw=this._fh=1},getLeft:function(){return this.x},setLeft:function(t){if(!this._fw){var e=t-this.x;this.width-=.5===this._sx?2*e:e}this.x=t,this._sx=this._fw=0},getTop:function(){return this.y},setTop:function(t){if(!this._fh){var e=t-this.y;this.height-=.5===this._sy?2*e:e}this.y=t,this._sy=this._fh=0},getRight:function(){return this.x+this.width},setRight:function(t){if(!this._fw){var e=t-this.x;this.width=.5===this._sx?2*e:e}this.x=t-this.width,this._sx=1,this._fw=0},getBottom:function(){return this.y+this.height},setBottom:function(t){if(!this._fh){var e=t-this.y;this.height=.5===this._sy?2*e:e}this.y=t-this.height,this._sy=1,this._fh=0},getCenterX:function(){return this.x+this.width/2},setCenterX:function(t){this._fw||.5===this._sx?this.x=t-this.width/2:(this._sx&&(this.x+=2*(t-this.x)*this._sx),this.width=2*(t-this.x)),this._sx=.5,this._fw=0},getCenterY:function(){return this.y+this.height/2},setCenterY:function(t){this._fh||.5===this._sy?this.y=t-this.height/2:(this._sy&&(this.y+=2*(t-this.y)*this._sy),this.height=2*(t-this.y)),this._sy=.5,this._fh=0},getCenter:function(t){return new(t?c:f)(this.getCenterX(),this.getCenterY(),this,"setCenter")},setCenter:function(){var t=c.read(arguments);return this.setCenterX(t.x),this.setCenterY(t.y),this},getArea:function(){return this.width*this.height},isEmpty:function(){return 0===this.width||0===this.height},contains:function(t){return t&&t.width!==e||4===(Array.isArray(t)?t:arguments).length?this._containsRectangle(g.read(arguments)):this._containsPoint(c.read(arguments))},_containsPoint:function(t){var e=t.x,i=t.y;return e>=this.x&&i>=this.y&&e<=this.x+this.width&&i<=this.y+this.height},_containsRectangle:function(t){var e=t.x,i=t.y;return e>=this.x&&i>=this.y&&e+t.width<=this.x+this.width&&i+t.height<=this.y+this.height},intersects:function(){var t=g.read(arguments),e=r.read(arguments)||0;return t.x+t.width>this.x-e&&t.y+t.height>this.y-e&&t.x=4&&(t[1]+=n?"Y":"X");var r=t[n?0:1],s=t[n?1:0],a="get"+r,o="get"+s,h="set"+r,u="set"+s,l="set"+i;this["get"+i]=function(t){return new(t?c:f)(this[a](),this[o](),this,l)},this[l]=function(){var t=c.read(arguments);this[h](t.x),this[u](t.y)}},{beans:!0})),v=g.extend({initialize:function(t,e,i,n,r,s){this._set(t,e,i,n,!0),this._owner=r,this._setter=s},_set:function(t,e,i,n,r){return this._x=t,this._y=e,this._width=i,this._height=n,r||this._owner[this._setter](this),this}},new function(){var t=g.prototype;return r.each(["x","y","width","height"],function(t){var e=r.capitalize(t),i="_"+t;this["get"+e]=function(){return this[i]},this["set"+e]=function(t){this[i]=t,this._dontNotify||this._owner[this._setter](this)}},r.each(["Point","Size","Center","Left","Top","Right","Bottom","CenterX","CenterY","TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],function(e){var i="set"+e;this[i]=function(){this._dontNotify=!0,t[i].apply(this,arguments),this._dontNotify=!1,this._owner[this._setter](this)}},{isSelected:function(){return!!(2&this._owner._selection)},setSelected:function(t){var e=this._owner;e._changeSelection&&e._changeSelection(2,t)}}))}),p=r.extend({_class:"Matrix",initialize:function t(e,i){var n=arguments.length,r=!0;if(n>=6?this._set.apply(this,arguments):1===n||2===n?e instanceof t?this._set(e._a,e._b,e._c,e._d,e._tx,e._ty,i):Array.isArray(e)?this._set.apply(this,i?e.concat([i]):e):r=!1:n?r=!1:this.reset(),!r)throw new Error("Unsupported matrix parameters");return this},set:"#initialize",_set:function(t,e,i,n,r,s,a){return this._a=t,this._b=e,this._c=i,this._d=n,this._tx=r,this._ty=s,a||this._changed(),this},_serialize:function(t,e){return r.serialize(this.getValues(),t,!0,e)},_changed:function(){var t=this._owner;t&&(t._applyMatrix?t.transform(null,!0):t._changed(9))},clone:function(){return new p(this._a,this._b,this._c,this._d,this._tx,this._ty)},equals:function(t){return t===this||t&&this._a===t._a&&this._b===t._b&&this._c===t._c&&this._d===t._d&&this._tx===t._tx&&this._ty===t._ty},toString:function(){var t=h.instance;return"[["+[t.number(this._a),t.number(this._c),t.number(this._tx)].join(", ")+"], ["+[t.number(this._b),t.number(this._d),t.number(this._ty)].join(", ")+"]]"},reset:function(t){return this._a=this._d=1,this._b=this._c=this._tx=this._ty=0,t||this._changed(),this},apply:function(t,e){var i=this._owner;return!!i&&(i.transform(null,!0,r.pick(t,!0),e),this.isIdentity())},translate:function(){var t=c.read(arguments),e=t.x,i=t.y;return this._tx+=e*this._a+i*this._c,this._ty+=e*this._b+i*this._d,this._changed(),this},scale:function(){var t=c.read(arguments),e=c.read(arguments,0,{readNull:!0});return e&&this.translate(e),this._a*=t.x,this._b*=t.x,this._c*=t.y,this._d*=t.y,e&&this.translate(e.negate()),this._changed(),this},rotate:function(t){t*=Math.PI/180;var e=c.read(arguments,1),i=e.x,n=e.y,r=Math.cos(t),s=Math.sin(t),a=i-i*r+n*s,o=n-i*s-n*r,h=this._a,u=this._b,l=this._c,f=this._d;return this._a=r*h+s*l,this._b=r*u+s*f,this._c=-s*h+r*l,this._d=-s*u+r*f,this._tx+=a*h+o*l,this._ty+=a*u+o*f,this._changed(),this},shear:function(){var t=c.read(arguments),e=c.read(arguments,0,{readNull:!0});e&&this.translate(e);var i=this._a,n=this._b;return this._a+=t.y*this._c,this._b+=t.y*this._d,this._c+=t.x*i,this._d+=t.x*n,e&&this.translate(e.negate()),this._changed(),this},skew:function(){var t=c.read(arguments),e=c.read(arguments,0,{readNull:!0}),i=Math.PI/180,n=new c(Math.tan(t.x*i),Math.tan(t.y*i));return this.shear(n,e)},append:function(t,e){if(t){var i=this._a,n=this._b,r=this._c,s=this._d,a=t._a,o=t._c,h=t._b,u=t._d,l=t._tx,c=t._ty;this._a=a*i+h*r,this._c=o*i+u*r,this._b=a*n+h*s,this._d=o*n+u*s,this._tx+=l*i+c*r,this._ty+=l*n+c*s,e||this._changed()}return this},prepend:function(t,e){if(t){var i=this._a,n=this._b,r=this._c,s=this._d,a=this._tx,o=this._ty,h=t._a,u=t._c,l=t._b,c=t._d,f=t._tx,d=t._ty;this._a=h*i+u*n,this._c=h*r+u*s,this._b=l*i+c*n,this._d=l*r+c*s,this._tx=h*a+u*o+f,this._ty=l*a+c*o+d,e||this._changed()}return this},appended:function(t){return this.clone().append(t)},prepended:function(t){return this.clone().prepend(t)},invert:function(){var t=this._a,e=this._b,i=this._c,n=this._d,r=this._tx,s=this._ty,a=t*n-e*i,o=null;return a&&!isNaN(a)&&isFinite(r)&&isFinite(s)&&(this._a=n/a,this._b=-e/a,this._c=-i/a,this._d=t/a,this._tx=(i*s-n*r)/a,this._ty=(e*r-t*s)/a,o=this),o},inverted:function(){return this.clone().invert()},concatenate:"#append",preConcatenate:"#prepend",chain:"#appended",_shiftless:function(){return new p(this._a,this._b,this._c,this._d,0,0)},_orNullIfIdentity:function(){return this.isIdentity()?null:this},isIdentity:function(){return 1===this._a&&0===this._b&&0===this._c&&1===this._d&&0===this._tx&&0===this._ty},isInvertible:function(){var t=this._a*this._d-this._c*this._b;return t&&!isNaN(t)&&isFinite(this._tx)&&isFinite(this._ty)},isSingular:function(){return!this.isInvertible()},transform:function(t,e,i){return arguments.length<3?this._transformPoint(c.read(arguments)):this._transformCoordinates(t,e,i)},_transformPoint:function(t,e,i){var n=t.x,r=t.y;return e||(e=new c),e._set(n*this._a+r*this._c+this._tx,n*this._b+r*this._d+this._ty,i)},_transformCoordinates:function(t,e,i){for(var n=0,r=2*i;ns[h]&&(s[h]=o)}return e||(e=new g),e._set(r[0],r[1],s[0]-r[0],s[1]-r[1],i)},inverseTransform:function(){return this._inverseTransform(c.read(arguments))},_inverseTransform:function(t,e,i){var n=this._a,r=this._b,s=this._c,a=this._d,o=this._tx,h=this._ty,u=n*a-r*s,l=null;if(u&&!isNaN(u)&&isFinite(o)&&isFinite(h)){var f=t.x-this._tx,d=t.y-this._ty;e||(e=new c),l=e._set((f*a-d*s)/u,(d*n-f*r)/u,i)}return l},decompose:function(){var t,e,i,n=this._a,r=this._b,s=this._c,a=this._d,o=n*a-r*s,h=Math.sqrt,u=Math.atan2,l=180/Math.PI;if(0!==n||0!==r){var f=h(n*n+r*r);t=Math.acos(n/f)*(r>0?1:-1),e=[f,o/f],i=[u(n*s+r*a,f*f),0]}else if(0!==s||0!==a){var d=h(s*s+a*a);t=Math.asin(s/d)*(a>0?1:-1),e=[o/d,d],i=[0,u(n*s+r*a,d*d)]}else t=0,i=e=[0,0];return{translation:this.getTranslation(),rotation:t*l,scaling:new c(e),skewing:new c(i[0]*l,i[1]*l)}},getValues:function(){return[this._a,this._b,this._c,this._d,this._tx,this._ty]},getTranslation:function(){return new c(this._tx,this._ty)},getScaling:function(){return(this.decompose()||{}).scaling},getRotation:function(){return(this.decompose()||{}).rotation},applyToContext:function(t){this.isIdentity()||t.transform(this._a,this._b,this._c,this._d,this._tx,this._ty)}},r.each(["a","b","c","d","tx","ty"],function(t){var e=r.capitalize(t),i="_"+t;this["get"+e]=function(){return this[i]},this["set"+e]=function(t){this[i]=t,this._changed()}},{})),m=r.extend({_class:"Line",initialize:function(t,e,i,n,r){var s=!1;arguments.length>=4?(this._px=t,this._py=e,this._vx=i,this._vy=n,s=r):(this._px=t.x,this._py=t.y,this._vx=e.x,this._vy=e.y,s=i),s||(this._vx-=this._px,this._vy-=this._py)},getPoint:function(){return new c(this._px,this._py)},getVector:function(){return new c(this._vx,this._vy)},getLength:function(){return this.getVector().getLength()},intersect:function(t,e){return m.intersect(this._px,this._py,this._vx,this._vy,t._px,t._py,t._vx,t._vy,!0,e)},getSide:function(t,e){return m.getSide(this._px,this._py,this._vx,this._vy,t.x,t.y,!0,e)},getDistance:function(t){return Math.abs(this.getSignedDistance(t))},getSignedDistance:function(t){return m.getSignedDistance(this._px,this._py,this._vx,this._vy,t.x,t.y,!0)},isCollinear:function(t){return c.isCollinear(this._vx,this._vy,t._vx,t._vy)},isOrthogonal:function(t){return c.isOrthogonal(this._vx,this._vy,t._vx,t._vy)},statics:{intersect:function(t,e,i,n,r,s,a,o,h,l){h||(i-=t,n-=e,a-=r,o-=s);var f=i*o-n*a;if(!u.isZero(f)){var d=t-r,_=e-s,g=(a*_-o*d)/f,v=(i*_-n*d)/f;if(l||-1e-12=1?1:g),new c(t+g*i,e+g*n)}},getSide:function(t,e,i,n,r,s,a,o){a||(i-=t,n-=e);var h=r-t,l=h*n-(s-e)*i;return!o&&u.isZero(l)&&(l=(h*i+h*i)/(i*i+n*n))>=0&&l<=1&&(l=0),l<0?-1:l>0?1:0},getSignedDistance:function(t,e,i,n,r,s,a){return a||(i-=t,n-=e),0===i?n>0?r-t:t-r:0===n?i<0?s-e:e-s:((r-t)*n-(s-e)*i)/Math.sqrt(i*i+n*n)},getDistance:function(t,e,i,n,r,s,a){return Math.abs(m.getSignedDistance(t,e,i,n,r,s,a))}}}),y=o.extend({_class:"Project",_list:"projects",_reference:"project",_compactSerialize:!0,initialize:function(t){o.call(this,!0),this._children=[],this._namedChildren={},this._activeLayer=null,this._currentStyle=new V(null,null,this),this._view=U.create(this,t||Q.getCanvas(1,1)),this._selectionItems={},this._selectionCount=0,this._updateVersion=0},_serialize:function(t,e){return r.serialize(this._children,t,!0,e)},_changed:function(t,e){if(1&t){var i=this._view;i&&(i._needsUpdate=!0,!i._requested&&i._autoUpdate&&i.requestUpdate())}var n=this._changes;if(n&&e){var r=this._changesById,s=e._id,a=r[s];a?a.flags|=t:n.push(r[s]={item:e,flags:t})}},clear:function(){for(var t=this._children,e=t.length-1;e>=0;e--)t[e].remove()},isEmpty:function(){return!this._children.length},remove:function t(){return!!t.base.call(this)&&(this._view&&this._view.remove(),!0)},getView:function(){return this._view},getCurrentStyle:function(){return this._currentStyle},setCurrentStyle:function(t){this._currentStyle.set(t)},getIndex:function(){return this._index},getOptions:function(){return this._scope.settings},getLayers:function(){return this._children},getActiveLayer:function(){return this._activeLayer||new b({project:this,insert:!0})},getSymbolDefinitions:function(){var t=[],e={};return this.getItems({class:P,match:function(i){var n=i._definition,r=n._id;return e[r]||(e[r]=!0,t.push(n)),!1}}),t},getSymbols:"getSymbolDefinitions",getSelectedItems:function(){var t=this._selectionItems,e=[];for(var i in t){var n=t[i],r=n._selection;1&r&&n.isInserted()?e.push(n):r||this._updateSelection(n)}return e},_updateSelection:function(t){var e=t._id,i=this._selectionItems;t._selection?i[e]!==t&&(this._selectionCount++,i[e]=t):i[e]===t&&(this._selectionCount--,delete i[e])},selectAll:function(){for(var t=this._children,e=0,i=t.length;e0){t.save(),t.strokeWidth=1;var h=this._selectionItems,u=this._scope.settings.handleSize,l=this._updateVersion;for(var f in h)h[f]._drawSelection(t,e,u,h,l);t.restore()}}}),w=r.extend(s,{statics:{extend:function t(e){return e._serializeFields&&(e._serializeFields=r.set({},this.prototype._serializeFields,e._serializeFields)),t.base.apply(this,arguments)},NO_INSERT:{insert:!1}},_class:"Item",_name:null,_applyMatrix:!0,_canApplyMatrix:!0,_canScaleStroke:!1,_pivot:null,_visible:!0,_blendMode:"normal",_opacity:1,_locked:!1,_guide:!1,_clipMask:!1,_selection:0,_selectBounds:!0,_selectChildren:!1,_serializeFields:{name:null,applyMatrix:null,matrix:new p,pivot:null,visible:!0,blendMode:"normal",opacity:1,locked:!1,guide:!1,clipMask:!1,selected:!1,data:{}},_prioritize:["applyMatrix"]},new function(){var t=["onMouseDown","onMouseUp","onMouseDrag","onClick","onDoubleClick","onMouseMove","onMouseEnter","onMouseLeave"];return r.each(t,function(t){this._events[t]={install:function(t){this.getView()._countItemEvent(t,1)},uninstall:function(t){this.getView()._countItemEvent(t,-1)}}},{_events:{onFrame:{install:function(){this.getView()._animateItem(this,!0)},uninstall:function(){this.getView()._animateItem(this,!1)}},onLoad:{},onError:{}},statics:{_itemHandlers:t}})},{initialize:function(){},_initialize:function(t,i){var n=t&&r.isPlainObject(t),s=n&&!0===t.internal,a=this._matrix=new p,o=n&&t.project||paper.project,h=paper.settings;return this._id=s?null:l.get(),this._parent=this._index=null,this._applyMatrix=this._canApplyMatrix&&h.applyMatrix,i&&a.translate(i),a._owner=this,this._style=new V(o._currentStyle,this,o),s||n&&0==t.insert||!h.insertItems&&(!n||!0!==t.insert)?this._setProject(o):(n&&t.parent||o)._insertItem(e,this,!0),n&&t!==w.NO_INSERT&&this.set(t,{internal:!0,insert:!0,project:!0,parent:!0}),n},_serialize:function(t,e){function i(i){for(var a in i){var o=s[a];r.equals(o,"leading"===a?1.2*i.fontSize:i[a])||(n[a]=r.serialize(o,t,"data"!==a,e))}}var n={},s=this;return i(this._serializeFields),this instanceof x||i(this._style._defaults),[this._class,n]},_changed:function(t){var i=this._symbol,n=this._parent||i,r=this._project;8&t&&(this._bounds=this._position=this._decomposed=this._globalMatrix=e),n&&40&t&&w._clearBoundsCache(n),2&t&&w._clearBoundsCache(this),r&&r._changed(t,this),i&&i._changed(t)},getId:function(){return this._id},getName:function(){return this._name},setName:function(t){if(this._name&&this._removeNamed(),t===+t+"")throw new Error("Names consisting only of numbers are not supported.");var i=this._getOwner();if(t&&i){var n=i._children,r=i._namedChildren;(r[t]=r[t]||[]).push(this),t in n||(n[t]=this)}this._name=t||e,this._changed(128)},getStyle:function(){return this._style},setStyle:function(t){this.getStyle().set(t)}},r.each(["locked","visible","blendMode","opacity","guide"],function(t){var e=r.capitalize(t),i="_"+t,n={locked:128,visible:137};this["get"+e]=function(){return this[i]},this["set"+e]=function(e){e!=this[i]&&(this[i]=e,this._changed(n[t]||129))}},{}),{beans:!0,getSelection:function(){return this._selection},setSelection:function(t){if(t!==this._selection){this._selection=t;var e=this._project;e&&(e._updateSelection(this),this._changed(129))}},_changeSelection:function(t,e){var i=this._selection;this.setSelection(e?i|t:i&~t)},isSelected:function(){if(this._selectChildren)for(var t=this._children,e=0,i=t.length;e=0;i--)if(e[i].contains(t))return!0;return!1}return t.isInside(this.getInternalBounds())},isInside:function(){return g.read(arguments).contains(this.getBounds())},_asPathItem:function(){return new L.Rectangle({rectangle:this.getInternalBounds(),matrix:this._matrix,insert:!1})},intersects:function(t,e){return t instanceof w&&this._asPathItem().getIntersections(t._asPathItem(),null,e,!0).length>0}},new function(){function t(){return this._hitTest(c.read(arguments),M.getOptions(arguments))}function e(){var t=c.read(arguments),e=M.getOptions(arguments),i=[];return this._hitTest(t,r.set({all:i},e)),i}function i(t,e,i,n){var r=this._children;if(r)for(var s=r.length-1;s>=0;s--){var a=r[s],o=a!==n&&a._hitTest(t,e,i);if(o&&!e.all)return o}return null}return y.inject({hitTest:t,hitTestAll:e,_hitTest:i}),{hitTest:t,hitTestAll:e,_hitTestChildren:i}},{_hitTest:function(t,e,i){function n(t){return t&&_&&!_(t)&&(t=null),t&&e.all&&e.all.push(t),t}function s(e,i){var n=i?l["get"+i]():g.getPosition();if(t.subtract(n).divide(u).length<=1)return new M(e,g,{name:i?r.hyphenate(i):e,point:n})}if(this._locked||!this._visible||this._guide&&!e.guides||this.isEmpty())return null;var a=this._matrix,o=i?i.appended(a):this.getGlobalMatrix().prepend(this.getView()._matrix),h=Math.max(e.tolerance,1e-12),u=e._tolerancePadding=new d(L._getStrokePadding(h,a._shiftless().invert()));if(!(t=a._inverseTransform(t))||!this._children&&!this.getBounds({internal:!0,stroke:!0,handle:!0}).expand(u.multiply(2))._containsPoint(t))return null;var l,c,f=!(e.guides&&!this._guide||e.selected&&!this.isSelected()||e.type&&e.type!==r.hyphenate(this._class)||e.class&&!(this instanceof e.class)),_=e.match,g=this,v=e.position,p=e.center,m=e.bounds;if(f&&this._parent&&(v||p||m)){if((p||m)&&(l=this.getInternalBounds()),!(c=v&&s("position")||p&&s("center","Center"))&&m)for(var y=["TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],w=0;w<8&&!c;w++)c=s("bounds",y[w]);c=n(c)}return c||(c=this._hitTestChildren(t,e,o)||f&&n(this._hitTestSelf(t,e,o,this.getStrokeScaling()?null:o._shiftless().invert()))||null),c&&c.point&&(c.point=a.transform(c.point)),c},_hitTestSelf:function(t,e){if(e.fill&&this.hasFill()&&this._contains(t))return new M("fill",this)},matches:function(t,e){function i(t,e){for(var n in t)if(t.hasOwnProperty(n)){var s=t[n],a=e[n];if(r.isPlainObject(s)&&r.isPlainObject(a)){if(!i(s,a))return!1}else if(!r.equals(s,a))return!1}return!0}var n=typeof t;if("object"===n){for(var s in t)if(t.hasOwnProperty(s)&&!this.matches(s,t[s]))return!1;return!0}if("function"===n)return t(this);if("match"===t)return e(this);var a=/^(empty|editable)$/.test(t)?this["is"+r.capitalize(t)]():"type"===t?r.hyphenate(this._class):this[t];if("class"===t){if("function"==typeof e)return this instanceof e;a=this._class}if("function"==typeof e)return!!e(a);if(e){if(e.test)return e.test(a);if(r.isPlainObject(e))return i(e,a)}return r.equals(a,e)},getItems:function(t){return w._getItems(this,t,this._matrix)},getItem:function(t){return w._getItems(this,t,this._matrix,null,!0)[0]||null},statics:{_getItems:function t(e,i,n,s,a){if(!s){var o="object"==typeof i&&i,h=o&&o.overlapping,u=o&&o.inside,l=(w=h||u)&&g.read([w]);s={items:[],recursive:o&&!1!==o.recursive,inside:!!u,overlapping:!!h,rect:l,path:h&&new L.Rectangle({rectangle:l,insert:!1})},o&&(i=r.filter({},i,{recursive:!0,inside:!0,overlapping:!0}))}var c=e._children,f=s.items;n=(l=s.rect)&&(n||new p);for(var d=0,_=c&&c.length;d<_;d++){var v=c[d],m=n&&n.appended(v._matrix),y=!0;if(l){var w=v.getBounds(m);if(!l.intersects(w))continue;l.contains(w)||s.overlapping&&(w.contains(l)||s.path.intersects(v,m))||(y=!1)}if(y&&v.matches(i)&&(f.push(v),a))break;if(!1!==s.recursive&&t(v,i,m,s,a),a&&f.length>0)break}return f}}},{importJSON:function(t){var e=r.importJSON(t,this);return e!==this?this.addChild(e):e},addChild:function(t){return this.insertChild(e,t)},insertChild:function(t,e){var i=e?this.insertChildren(t,[e]):null;return i&&i[0]},addChildren:function(t){return this.insertChildren(this._children.length,t)},insertChildren:function(t,e){var i=this._children;if(i&&e&&e.length>0){for(var n={},s=(e=r.slice(e)).length-1;s>=0;s--){var a=(l=e[s])&&l._id;!l||n[a]?e.splice(s,1):(l._remove(!1,!0),n[a]=!0)}r.splice(i,e,t,0);for(var o=this._project,h=o._changes,s=0,u=e.length;s=0;n--)i[n]._remove(!0,!1);return i.length>0&&this._changed(11),i},clear:"#removeChildren",reverseChildren:function(){if(this._children){this._children.reverse();for(var t=0,e=this._children.length;t0},isInserted:function(){return!!this._parent&&this._parent.isInserted()},isAbove:function(t){return-1===this._getOrder(t)},isBelow:function(t){return 1===this._getOrder(t)},isParent:function(t){return this._parent===t},isChild:function(t){return t&&t._parent===this},isDescendant:function(t){for(var e=this;e=e._parent;)if(e===t)return!0;return!1},isAncestor:function(t){return!!t&&t.isDescendant(this)},isSibling:function(t){return this._parent===t._parent},isGroupedWith:function(t){for(var e=this._parent;e;){if(e._parent&&/^(Group|Layer|CompoundPath)$/.test(e._class)&&t.isDescendant(e))return!0;e=e._parent}return!1}},r.each(["rotate","scale","shear","skew"],function(t){var e="rotate"===t;this[t]=function(){var i=(e?r:c).read(arguments),n=c.read(arguments,0,{readNull:!0});return this.transform((new p)[t](i,n||this.getPosition(!0)))}},{translate:function(){var t=new p;return this.transform(t.translate.apply(t,arguments))},transform:function(t,e,i,n){var r=this._matrix,s=t&&!t.isIdentity(),a=(e||this._applyMatrix)&&(!r.isIdentity()||s||e&&i&&this._children);if(!s&&!a)return this;if(s){!t.isInvertible()&&r.isInvertible()&&(r._backup=r.getValues()),r.prepend(t,!0);var o=this._style,h=o.getFillColor(!0),u=o.getStrokeColor(!0);h&&h.transform(t),u&&u.transform(t)}if(a&&(a=this._transformContent(r,i,n))){var l=this._pivot;l&&r._transformPoint(l,l,!0),r.reset(!0),n&&this._canApplyMatrix&&(this._applyMatrix=!0)}var c=this._bounds,f=this._position;(s||a)&&this._changed(9);var d=s&&c&&t.decompose();if(d&&d.skewing.isZero()&&d.rotation%90==0){for(var _ in c){var g=c[_];if(g.nonscaling)delete c[_];else if(a||!g.internal){var v=g.rect;t._transformBounds(v,v)}}this._bounds=c;var p=c[this._getBoundsCacheKey(this._boundsOptions||{})];p&&(this._position=p.rect.getCenter(!0))}else s&&f&&this._pivot&&(this._position=t._transformPoint(f,f));return this},_transformContent:function(t,e,i){var n=this._children;if(n){for(var r=0,s=n.length;rr:n1&&s<4?-1:1,s>2?-1:1),o=a.multiply(r),h=o.subtract(a.multiply(n));if(new g(i?o.add(a.multiply(i)):o,h).contains(e))return{point:h,quadrant:s}}}function e(t,e,i,n){var r=t.divide(e);return(!n||r.isInQuadrant(n))&&r.subtract(r.normalize()).multiply(e).divide(i).length<=1}return{_contains:function e(i){if("rectangle"===this._type){var n=t(this,i);return n?i.subtract(n.point).divide(this._radius).getLength()<=1:e.base.call(this,i)}return i.divide(this.size).getLength()<=.5},_hitTestSelf:function i(n,r,s,a){var o=!1,h=this._style,u=r.stroke&&h.hasStroke(),l=r.fill&&h.hasFill();if(u||l){var c=this._type,f=this._radius,d=u?h.getStrokeWidth()/2:0,_=r._tolerancePadding.add(L._getStrokePadding(d,!h.getStrokeScaling()&&a));if("rectangle"===c){var v=_.multiply(2),p=t(this,n,v);if(p)o=e(n.subtract(p.point),f,_,p.quadrant);else{var m=new g(this._size).setCenter(0,0),y=m.expand(v),w=m.expand(v.negate());o=y._containsPoint(n)&&!w._containsPoint(n)}}else o=e(n,f,_)}return o?new M(u?"stroke":"fill",this):i.base.apply(this,arguments)}}},{statics:new function(){function t(t,e,i,n,s){var a=new C(r.getNamed(s),e);return a._type=t,a._size=i,a._radius=n,a}return{Circle:function(){var e=c.readNamed(arguments,"center"),i=r.readNamed(arguments,"radius");return t("circle",e,new d(2*i),i,arguments)},Rectangle:function(){var e=g.readNamed(arguments,"rectangle"),i=d.min(d.readNamed(arguments,"radius"),e.getSize(!0).divide(2));return t("rectangle",e.getCenter(!0),e.getSize(!0),i,arguments)},Ellipse:function(){var e=C._readEllipse(arguments),i=e.radius;return t("ellipse",e.center,i.multiply(2),i,arguments)},_readEllipse:function(t){var e,i;if(r.hasNamed(t,"radius"))e=c.readNamed(t,"center"),i=d.readNamed(t,"radius");else{var n=g.readNamed(t,"rectangle");e=n.getCenter(!0),i=n.getSize(!0).divide(2)}return{center:e,radius:i}}}}}),S=w.extend({_class:"Raster",_applyMatrix:!1,_canApplyMatrix:!1,_boundsOptions:{stroke:!1,handle:!1},_serializeFields:{crossOrigin:null,source:null},_prioritize:["crossOrigin"],initialize:function(t,i){if(!this._initialize(t,i!==e&&c.read(arguments,1))){var r="string"==typeof t?n.getElementById(t):t;r?this.setImage(r):this.setSource(t)}this._size||(this._size=new d,this._loaded=!1)},_equals:function(t){return this.getSource()===t.getSource()},copyContent:function(t){var e=t._image,i=t._canvas;if(e)this._setImage(e);else if(i){var n=Q.getCanvas(t._size);n.getContext("2d").drawImage(i,0,0),this._setImage(n)}this._crossOrigin=t._crossOrigin},getSize:function(){var t=this._size;return new _(t?t.width:0,t?t.height:0,this,"setSize")},setSize:function(){var t=d.read(arguments);if(!t.equals(this._size))if(t.width>0&&t.height>0){var e=this.getElement();this._setImage(Q.getCanvas(t)),e&&this.getContext(!0).drawImage(e,0,0,t.width,t.height)}else this._canvas&&Q.release(this._canvas),this._size=t.clone()},getWidth:function(){return this._size?this._size.width:0},setWidth:function(t){this.setSize(t,this.getHeight())},getHeight:function(){return this._size?this._size.height:0},setHeight:function(t){this.setSize(this.getWidth(),t)},getLoaded:function(){return this._loaded},isEmpty:function(){var t=this._size;return!t||0===t.width&&0===t.height},getResolution:function(){var t=this._matrix,e=new c(0,0).transform(t),i=new c(1,0).transform(t).subtract(e),n=new c(0,1).transform(t).subtract(e);return new d(72/i.getLength(),72/n.getLength())},getPpi:"#getResolution",getImage:function(){return this._image},setImage:function(t){function e(t){var e=i.getView(),n=t&&t.type||"load";e&&i.responds(n)&&(paper=e._scope,i.emit(n,new G(t)))}var i=this;this._setImage(t),this._loaded?setTimeout(e,0):t&&Z.add(t,{load:function(n){i._setImage(t),e(n)},error:e})},_setImage:function(t){this._canvas&&Q.release(this._canvas),t&&t.getContext?(this._image=null,this._canvas=t,this._loaded=!0):(this._image=t,this._canvas=null,this._loaded=!!(t&&t.src&&t.complete)),this._size=new d(t?t.naturalWidth||t.width:0,t?t.naturalHeight||t.height:0),this._context=null,this._changed(521)},getCanvas:function(){if(!this._canvas){var t=Q.getContext(this._size);try{this._image&&t.drawImage(this._image,0,0),this._canvas=t.canvas}catch(e){Q.release(t)}}return this._canvas},setCanvas:"#setImage",getContext:function(t){return this._context||(this._context=this.getCanvas().getContext("2d")),t&&(this._image=null,this._changed(513)),this._context},setContext:function(t){this._context=t},getSource:function(){var t=this._image;return t&&t.src||this.toDataURL()},setSource:function(e){var i=new t.Image,n=this._crossOrigin;n&&(i.crossOrigin=n),i.src=e,this.setImage(i)},getCrossOrigin:function(){var t=this._image;return t&&t.crossOrigin||this._crossOrigin||""},setCrossOrigin:function(t){this._crossOrigin=t;var e=this._image;e&&(e.crossOrigin=t)},getElement:function(){return this._canvas||this._loaded&&this._image}},{beans:!1,getSubCanvas:function(){var t=g.read(arguments),e=Q.getContext(t.getSize());return e.drawImage(this.getCanvas(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),e.canvas},getSubRaster:function(){var t=g.read(arguments),e=new S(w.NO_INSERT);return e._setImage(this.getSubCanvas(t)),e.translate(t.getCenter().subtract(this.getSize().divide(2))),e._matrix.prepend(this._matrix),e.insertAbove(this),e},toDataURL:function(){var t=this._image,e=t&&t.src;if(/^data:/.test(e))return e;var i=this.getCanvas();return i?i.toDataURL.apply(i,arguments):null},drawImage:function(t){var e=c.read(arguments,1);this.getContext(!0).drawImage(t,e.x,e.y)},getAverageColor:function(t){var e,i;if(t?t instanceof A?(i=t,e=t.getBounds()):"object"==typeof t&&("width"in t?e=new g(t):"x"in t&&(e=new g(t.x-.5,t.y-.5,1,1))):e=this.getBounds(),!e)return null;var n=Math.min(e.width,32),s=Math.min(e.height,32),a=S._sampleContext;a?a.clearRect(0,0,33,33):a=S._sampleContext=Q.getContext(new d(32)),a.save();var o=(new p).scale(n/e.width,s/e.height).translate(-e.x,-e.y);o.applyToContext(a),i&&i.draw(a,new r({clip:!0,matrices:[o]})),this._matrix.applyToContext(a);var h=this.getElement(),u=this._size;h&&a.drawImage(h,-u.width/2,-u.height/2),a.restore();for(var l=a.getImageData(.5,.5,Math.ceil(n),Math.ceil(s)).data,c=[0,0,0],f=0,_=0,v=l.length;_0&&(null==t||"object"==typeof t?1===c&&t&&"point"in t?(o=t.point,h=t.handleIn,u=t.handleOut,l=t.selection):(o=t,h=i,u=n,l=r):(o=[t,i],h=n!==e?[n,r]:null,u=s!==e?[s,a]:null)),new z(o,this,"_point"),new z(h,this,"_handleIn"),new z(u,this,"_handleOut"),l&&this.setSelection(l)},_serialize:function(t,e){var i=this._point,n=this._selection,s=n||this.hasHandles()?[i,this._handleIn,this._handleOut]:i;return n&&s.push(n),r.serialize(s,t,!0,e)},_changed:function(t){var e=this._path;if(e){var i,n=e._curves,r=this._index;n&&(t&&t!==this._point&&t!==this._handleIn||!(i=r>0?n[r-1]:e._closed?n[n.length-1]:null)||i._changed(),t&&t!==this._point&&t!==this._handleOut||!(i=n[r])||i._changed()),e._changed(25)}},getPoint:function(){return this._point},setPoint:function(){this._point.set(c.read(arguments))},getHandleIn:function(){return this._handleIn},setHandleIn:function(){this._handleIn.set(c.read(arguments))},getHandleOut:function(){return this._handleOut},setHandleOut:function(){this._handleOut.set(c.read(arguments))},hasHandles:function(){return!this._handleIn.isZero()||!this._handleOut.isZero()},isSmooth:function(){var t=this._handleIn,e=this._handleOut;return!t.isZero()&&!e.isZero()&&t.isCollinear(e)},clearHandles:function(){this._handleIn._set(0,0),this._handleOut._set(0,0)},getSelection:function(){return this._selection},setSelection:function(t){var e=this._selection,i=this._path;this._selection=t=t||0,i&&t!==e&&(i._updateSelection(this,e,t),i._changed(129))},_changeSelection:function(t,e){var i=this._selection;this.setSelection(e?i|t:i&~t)},isSelected:function(){return!!(7&this._selection)},setSelected:function(t){this._changeSelection(7,t)},getIndex:function(){return this._index!==e?this._index:null},getPath:function(){return this._path||null},getCurve:function(){var t=this._path,e=this._index;return t?(e>0&&!t._closed&&e===t._segments.length-1&&e--,t.getCurves()[e]||null):null},getLocation:function(){var t=this.getCurve();return t?new O(t,this===t._segment1?0:1):null},getNext:function(){var t=this._path&&this._path._segments;return t&&(t[this._index+1]||this._path._closed&&t[0])||null},smooth:function(t,i,n){var r=t||{},s=r.type,a=r.factor,o=this.getPrevious(),h=this.getNext(),u=(o||this)._point,l=this._point,f=(h||this)._point,d=u.getDistance(l),_=l.getDistance(f);if(s&&"catmull-rom"!==s){if("geometric"!==s)throw new Error("Smoothing method '"+s+"' not supported.");if(o&&h){var g=u.subtract(f),v=a===e?.4:a,p=v*d/(d+_);i||this.setHandleIn(g.multiply(p)),n||this.setHandleOut(g.multiply(p-v))}}else{var m=a===e?.5:a,y=Math.pow(d,m),w=y*y,x=Math.pow(_,m),b=x*x;if(!i&&o){var C=2*b+3*x*y+w,S=3*x*(x+y);this.setHandleIn(0!==S?new c((b*u._x+C*l._x-w*f._x)/S-l._x,(b*u._y+C*l._y-w*f._y)/S-l._y):new c)}if(!n&&h){var C=2*w+3*y*x+b,S=3*y*(y+x);this.setHandleOut(0!==S?new c((w*f._x+C*l._x-b*u._x)/S-l._x,(w*f._y+C*l._y-b*u._y)/S-l._y):new c)}}},getPrevious:function(){var t=this._path&&this._path._segments;return t&&(t[this._index-1]||this._path._closed&&t[t.length-1])||null},isFirst:function(){return!this._index},isLast:function(){var t=this._path;return t&&this._index===t._segments.length-1||!1},reverse:function(){var t=this._handleIn,e=this._handleOut,i=t.clone();t.set(e),e.set(i)},reversed:function(){return new T(this._point,this._handleOut,this._handleIn)},remove:function(){return!!this._path&&!!this._path.removeSegment(this._index)},clone:function(){return new T(this._point,this._handleIn,this._handleOut)},equals:function(t){return t===this||t&&this._class===t._class&&this._point.equals(t._point)&&this._handleIn.equals(t._handleIn)&&this._handleOut.equals(t._handleOut)||!1},toString:function(){var t=["point: "+this._point];return this._handleIn.isZero()||t.push("handleIn: "+this._handleIn),this._handleOut.isZero()||t.push("handleOut: "+this._handleOut),"{ "+t.join(", ")+" }"},transform:function(t){this._transformCoordinates(t,new Array(6),!0),this._changed()},interpolate:function(t,e,i){var n=1-i,r=i,s=t._point,a=e._point,o=t._handleIn,h=e._handleIn,u=e._handleOut,l=t._handleOut;this._point._set(n*s._x+r*a._x,n*s._y+r*a._y,!0),this._handleIn._set(n*o._x+r*h._x,n*o._y+r*h._y,!0),this._handleOut._set(n*l._x+r*u._x,n*l._y+r*u._y,!0),this._changed()},_transformCoordinates:function(t,e,i){var n=this._point,r=i&&this._handleIn.isZero()?null:this._handleIn,s=i&&this._handleOut.isZero()?null:this._handleOut,a=n._x,o=n._y,h=2;return e[0]=a,e[1]=o,r&&(e[h++]=r._x+a,e[h++]=r._y+o),s&&(e[h++]=s._x+a,e[h++]=s._y+o),t&&(t._transformCoordinates(e,e,h/2),a=e[0],o=e[1],i?(n._x=a,n._y=o,h=2,r&&(r._x=e[h++]-a,r._y=e[h++]-o),s&&(s._x=e[h++]-a,s._y=e[h++]-o)):(r||(e[h++]=a,e[h++]=o),s||(e[h++]=a,e[h++]=o))),e}}),z=c.extend({initialize:function(t,i,n){var r,s,a;if(t)if((r=t[0])!==e)s=t[1];else{var o=t;(r=o.x)===e&&(r=(o=c.read(arguments)).x),s=o.y,a=o.selected}else r=s=0;this._x=r,this._y=s,this._owner=i,i[n]=this,a&&this.setSelected(!0)},_set:function(t,e){return this._x=t,this._y=e,this._owner._changed(this),this},getX:function(){return this._x},setX:function(t){this._x=t,this._owner._changed(this)},getY:function(){return this._y},setY:function(t){this._y=t,this._owner._changed(this)},isZero:function(){var t=u.isZero;return t(this._x)&&t(this._y)},isSelected:function(){return!!(this._owner._selection&this._getSelection())},setSelected:function(t){this._owner._changeSelection(this._getSelection(),t)},_getSelection:function(){var t=this._owner;return this===t._point?1:this===t._handleIn?2:this===t._handleOut?4:0}}),k=r.extend({_class:"Curve",beans:!0,initialize:function(t,e,i,n,r,s,a,o){var h,u,l,c,f,d,_=arguments.length;3===_?(this._path=t,h=e,u=i):_?1===_?"segment1"in t?(h=new T(t.segment1),u=new T(t.segment2)):"point1"in t?(l=t.point1,f=t.handle1,d=t.handle2,c=t.point2):Array.isArray(t)&&(l=[t[0],t[1]],c=[t[6],t[7]],f=[t[2]-t[0],t[3]-t[1]],d=[t[4]-t[6],t[5]-t[7]]):2===_?(h=new T(t),u=new T(e)):4===_?(l=t,f=e,d=i,c=n):8===_&&(l=[t,e],c=[a,o],f=[i-t,n-e],d=[r-a,s-o]):(h=new T,u=new T),this._segment1=h||new T(l,null,f),this._segment2=u||new T(c,d,null)},_serialize:function(t,e){return r.serialize(this.hasHandles()?[this.getPoint1(),this.getHandle1(),this.getHandle2(),this.getPoint2()]:[this.getPoint1(),this.getPoint2()],t,!0,e)},_changed:function(){this._length=this._bounds=e},clone:function(){return new k(this._segment1,this._segment2)},toString:function(){var t=["point1: "+this._segment1._point];return this._segment1._handleOut.isZero()||t.push("handle1: "+this._segment1._handleOut),this._segment2._handleIn.isZero()||t.push("handle2: "+this._segment2._handleIn),t.push("point2: "+this._segment2._point),"{ "+t.join(", ")+" }"},classify:function(){return k.classify(this.getValues())},remove:function(){var t=!1;if(this._path){var e=this._segment2,i=e._handleOut;(t=e.remove())&&this._segment1._handleOut.set(i)}return t},getPoint1:function(){return this._segment1._point},setPoint1:function(){this._segment1._point.set(c.read(arguments))},getPoint2:function(){return this._segment2._point},setPoint2:function(){this._segment2._point.set(c.read(arguments))},getHandle1:function(){return this._segment1._handleOut},setHandle1:function(){this._segment1._handleOut.set(c.read(arguments))},getHandle2:function(){return this._segment2._handleIn},setHandle2:function(){this._segment2._handleIn.set(c.read(arguments))},getSegment1:function(){return this._segment1},getSegment2:function(){return this._segment2},getPath:function(){return this._path},getIndex:function(){return this._segment1._index},getNext:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index-1]||this._path._closed&&t[t.length-1])||null},isFirst:function(){return!this._segment1._index},isLast:function(){var t=this._path;return t&&this._segment1._index===t._curves.length-1||!1},isSelected:function(){return this.getPoint1().isSelected()&&this.getHandle1().isSelected()&&this.getHandle2().isSelected()&&this.getPoint2().isSelected()},setSelected:function(t){this.getPoint1().setSelected(t),this.getHandle1().setSelected(t),this.getHandle2().setSelected(t),this.getPoint2().setSelected(t)},getValues:function(t){return k.getValues(this._segment1,this._segment2,t)},getPoints:function(){for(var t=this.getValues(),e=[],i=0;i<8;i+=2)e.push(new c(t[i],t[i+1]));return e}},{getLength:function(){return null==this._length&&(this._length=k.getLength(this.getValues(),0,1)),this._length},getArea:function(){return k.getArea(this.getValues())},getLine:function(){return new m(this._segment1._point,this._segment2._point)},getPart:function(t,e){return new k(k.getPart(this.getValues(),t,e))},getPartLength:function(t,e){return k.getLength(this.getValues(),t,e)},divideAt:function(t){return this.divideAtTime(t&&t.curve===this?t.time:this.getTimeAt(t))},divideAtTime:function(t,e){var i=null;if(t>=1e-8&&t<=1-1e-8){var n=k.subdivide(this.getValues(),t),r=n[0],s=n[1],a=e||this.hasHandles(),o=this._segment1,h=this._segment2,u=this._path;a&&(o._handleOut._set(r[2]-r[0],r[3]-r[1]),h._handleIn._set(s[4]-s[6],s[5]-s[7]));var l=r[6],f=r[7],d=new T(new c(l,f),a&&new c(r[4]-l,r[5]-f),a&&new c(s[2]-l,s[3]-f));u?(u.insert(o._index+1,d),i=this.getNext()):(this._segment2=d,this._changed(),i=new k(d,h))}return i},splitAt:function(t){var e=this._path;return e?e.splitAt(t):null},splitAtTime:function(t){return this.splitAt(this.getLocationAtTime(t))},divide:function(t,i){return this.divideAtTime(t===e?.5:i?t:this.getTimeAt(t))},split:function(t,i){return this.splitAtTime(t===e?.5:i?t:this.getTimeAt(t))},reversed:function(){return new k(this._segment2.reversed(),this._segment1.reversed())},clearHandles:function(){this._segment1._handleOut._set(0,0),this._segment2._handleIn._set(0,0)},statics:{getValues:function(t,e,i,n){var r=t._point,s=t._handleOut,a=e._handleIn,o=e._point,h=r.x,u=r.y,l=o.x,c=o.y,f=n?[h,u,h,u,l,c,l,c]:[h,u,h+s._x,u+s._y,l+a._x,c+a._y,l,c];return i&&i._transformCoordinates(f,f,4),f},subdivide:function(t,i){var n=t[0],r=t[1],s=t[2],a=t[3],o=t[4],h=t[5],u=t[6],l=t[7];i===e&&(i=.5);var c=1-i,f=c*n+i*s,d=c*r+i*a,_=c*s+i*o,g=c*a+i*h,v=c*o+i*u,p=c*h+i*l,m=c*f+i*_,y=c*d+i*g,w=c*_+i*v,x=c*g+i*p,b=c*m+i*w,C=c*y+i*x;return[[n,r,f,d,m,y,b,C],[b,C,w,x,v,p,u,l]]},getMonoCurves:function(t,e){var i=[],n=e?0:1,r=t[n+0],s=t[n+2],a=t[n+4],o=t[n+6];if(r>=s==s>=a&&s>=a==a>=o||k.isStraight(t))i.push(t);else{var h=3*(s-a)-r+o,l=2*(r+a)-4*s,c=s-r,f=[],d=u.solveQuadratic(h,l,c,f,1e-8,1-1e-8);if(d){f.sort();var _=f[0],g=k.subdivide(t,_);i.push(g[0]),d>1&&(_=(f[1]-_)/(1-_),g=k.subdivide(g[1],_),i.push(g[0])),i.push(g[1])}else i.push(t)}return i},solveCubic:function(t,e,i,n,r,s){var a=t[e],o=t[e+2],h=t[e+4],l=t[e+6],c=0;if(!(ai&&l>i&&o>i&&h>i)){var f=3*(o-a),d=3*(h-o)-f,_=l-a-f-d;c=u.solveCubic(_,d,f,a-i,n,r,s)}return c},getTimeOf:function(t,e){var i=new c(t[0],t[1]),n=new c(t[6],t[7]);if(null===(e.isClose(i,1e-12)?0:e.isClose(n,1e-12)?1:null))for(var r=[e.x,e.y],s=[],a=0;a<2;a++)for(var o=k.solveCubic(t,a,r[a],s,0,1),h=0;h=0&&i<=1){var n=e.getDistance(k.getPoint(t,i),!0);if(n.999999999999?1:k.getTimeOf(t,new c(n+h*s,r+h*a))}for(var u=1/0,l=0,f=0;f<=100;f++)i(f/100);for(var d=.005;d>1e-8;)i(l-d)||i(l+d)||(d/=2);return l},getPart:function(t,e,i){var n=e>i;if(n){var r=e;e=i,i=r}return e>0&&(t=k.subdivide(t,e)[1]),i<1&&(t=k.subdivide(t,(i-e)/(1-e))[0]),n?[t[6],t[7],t[4],t[5],t[2],t[3],t[0],t[1]]:t},isFlatEnough:function(t,e){var i=t[0],n=t[1],r=t[2],s=t[3],a=t[4],o=t[5],h=t[6],u=t[7],l=3*r-2*i-h,c=3*s-2*n-u,f=3*a-2*h-i,d=3*o-2*u-n;return Math.max(l*l,f*f)+Math.max(c*c,d*d)<=16*e*e},getArea:function(t){var e=t[0],i=t[1],n=t[2],r=t[3],s=t[4],a=t[5],o=t[6],h=t[7];return 3*((h-i)*(n+s)-(o-e)*(r+a)+r*(e-s)-n*(i-a)+h*(s+e/3)-o*(a+i/3))/20},getBounds:function(t){for(var e=t.slice(0,2),i=e.slice(),n=[0,0],r=0;r<2;r++)k._addBounds(t[r],t[r+2],t[r+4],t[r+6],r,0,e,i,n);return new g(e[0],e[1],i[0]-e[0],i[1]-e[1])},_addBounds:function(t,e,i,n,r,s,a,o,h){function l(t,e){var i=t-e,n=t+e;io[r]&&(o[r]=n)}s/=2;var c=a[r]-s,f=o[r]+s;if(tf||e>f||i>f||n>f)if(e=0&&o<=1&&h<=0&&h>=-1}}return!1},isLinear:function(t,e,i,n){var r=n.subtract(t).divide(3);return e.equals(r)&&i.negate().equals(r)}},function(t,e){this[e]=function(e){var i=this._segment1,n=this._segment2;return t(i._point,i._handleOut,n._handleIn,n._point,e)},this.statics[e]=function(e,i){var n=e[0],r=e[1],s=e[6],a=e[7];return t(new c(n,r),new c(e[2]-n,e[3]-r),new c(e[4]-s,e[5]-a),new c(s,a),i)}},{statics:{},hasHandles:function(){return!this._segment1._handleOut.isZero()||!this._segment2._handleIn.isZero()},hasLength:function(t){return(!this.getPoint1().equals(this.getPoint2())||this.hasHandles())&&this.getLength()>(t||0)},isCollinear:function(t){return t&&this.isStraight()&&t.isStraight()&&this.getLine().isCollinear(t.getLine())},isHorizontal:function(){return this.isStraight()&&Math.abs(this.getTangentAtTime(.5).y)<1e-8},isVertical:function(){return this.isStraight()&&Math.abs(this.getTangentAtTime(.5).x)<1e-8}}),{beans:!1,getLocationAt:function(t,e){return this.getLocationAtTime(e?t:this.getTimeAt(t))},getLocationAtTime:function(t){return null!=t&&t>=0&&t<=1?new O(this,t):null},getTimeAt:function(t,e){return k.getTimeAt(this.getValues(),t,e)},getParameterAt:"#getTimeAt",getOffsetAtTime:function(t){return this.getPartLength(0,t)},getLocationOf:function(){return this.getLocationAtTime(this.getTimeOf(c.read(arguments)))},getOffsetOf:function(){var t=this.getLocationOf.apply(this,arguments);return t?t.getOffset():null},getTimeOf:function(){return k.getTimeOf(this.getValues(),c.read(arguments))},getParameterOf:"#getTimeOf",getNearestLocation:function(){var t=c.read(arguments),e=this.getValues(),i=k.getNearestTime(e,t),n=k.getPoint(e,i);return new O(this,i,n,null,t.getDistance(n))},getNearestPoint:function(){var t=this.getNearestLocation.apply(this,arguments);return t?t.getPoint():t}},new function(){var t=["getPoint","getTangent","getNormal","getWeightedTangent","getWeightedNormal","getCurvature"];return r.each(t,function(t){this[t+"At"]=function(e,i){var n=this.getValues();return k[t](n,i?e:k.getTimeAt(n,e))},this[t+"AtTime"]=function(e){return k[t](this.getValues(),e)}},{statics:{_evaluateMethods:t}})},new function(){function t(t){var e=t[0],i=t[1],n=t[2],r=t[3],s=t[4],a=t[5],o=9*(n-s)+3*(t[6]-e),h=6*(e+s)-12*n,u=3*(n-e),l=9*(r-a)+3*(t[7]-i),c=6*(i+a)-12*r,f=3*(r-i);return function(t){var e=(o*t+h)*t+u,i=(l*t+c)*t+f;return Math.sqrt(e*e+i*i)}}function i(t,e){return Math.max(2,Math.min(16,Math.ceil(32*Math.abs(e-t))))}function n(t,e,i,n){if(null==e||e<0||e>1)return null;var r=t[0],s=t[1],a=t[2],o=t[3],h=t[4],l=t[5],f=t[6],d=t[7],_=u.isZero;_(a-r)&&_(o-s)&&(a=r,o=s),_(h-f)&&_(l-d)&&(h=f,l=d);var g,v,p=3*(a-r),m=3*(h-a)-p,y=f-r-p-m,w=3*(o-s),x=3*(l-o)-w,b=d-s-w-x;if(0===i)g=0===e?r:1===e?f:((y*e+m)*e+p)*e+r,v=0===e?s:1===e?d:((b*e+x)*e+w)*e+s;else{if(e<1e-8?(g=p,v=w):e>1-1e-8?(g=3*(f-h),v=3*(d-l)):(g=(3*y*e+2*m)*e+p,v=(3*b*e+2*x)*e+w),n){0===g&&0===v&&(e<1e-8||e>1-1e-8)&&(g=h-a,v=l-o);var C=Math.sqrt(g*g+v*v);C&&(g/=C,v/=C)}if(3===i){var h=6*y*e+2*m,l=6*b*e+2*x,S=Math.pow(g*g+v*v,1.5);g=0!==S?(g*l-v*h)/S:0,v=0}}return 2===i?new c(v,-g):new c(g,v)}return{statics:{classify:function(t){function i(t,i,n){var r=i!==e,s=r&&i>0&&i<1,a=r&&n>0&&n<1;return!r||(s||a)&&("loop"!==t||s&&a)||(t="arch",s=a=!1),{type:t,roots:s||a?s&&a?i0?Math.sqrt(y/3):Math.sqrt(-y),x=2*g;return i(y>0?"serpentine":"loop",(_+w)/x,(_-w)/x)},getLength:function(n,r,s,a){if(r===e&&(r=0),s===e&&(s=1),k.isStraight(n)){var o=n;s<1&&(o=k.subdivide(o,s)[0],r/=s),r>0&&(o=k.subdivide(o,r)[1]);var h=o[6]-o[0],l=o[7]-o[1];return Math.sqrt(h*h+l*l)}return u.integrate(a||t(n),r,s,i(r,s))},getTimeAt:function(n,r,s){if(s===e&&(s=r<0?1:0),0===r)return s;var a=Math.abs,o=r>0,h=o?s:0,l=o?1:s,c=t(n),f=k.getLength(n,h,l,c),d=a(r)-f;if(a(d)<1e-12)return o?l:h;if(d>1e-12)return null;var _=r/f,g=0;return u.findRoot(function(t){return g+=u.integrate(c,s,t,i(s,t)),s=t,g-r},c,s+_,h,l,32,1e-12)},getPoint:function(t,e){return n(t,e,0,!1)},getTangent:function(t,e){return n(t,e,1,!0)},getWeightedTangent:function(t,e){return n(t,e,1,!1)},getNormal:function(t,e){return n(t,e,2,!0)},getWeightedNormal:function(t,e){return n(t,e,2,!1)},getCurvature:function(t,e){return n(t,e,3,!1).x},getPeaks:function(t){var e=t[0],i=t[1],n=t[2],r=t[3],s=t[4],a=t[5],o=3*n-e-3*s+t[6],h=3*e-6*n+3*s,l=-3*e+3*n,c=3*r-i-3*a+t[7],f=3*i-6*r+3*a,d=-3*i+3*r,_=[];return u.solveCubic(9*(o*o+c*c),9*(o*h+f*c),2*(h*h+f*f)+3*(l*o+d*c),l*h+f*d,_,1e-8,1-1e-8),_.sort()}}}},new function(){function t(t,e,i,n,r,s,a){var o=!a&&i.getPrevious()===r,h=!a&&i!==r&&i.getNext()===r;if(null!==n&&n>=(o?1e-8:0)&&n<=(h?1-1e-8:1)&&null!==s&&s>=(h?1e-8:0)&&s<=(o?1-1e-8:1)){var u=new O(i,n,null,a),l=new O(r,s,null,a);u._intersection=l,l._intersection=u,e&&!e(u)||O.insert(t,u,!0)}}function e(r,s,a,o,h,u,l,c,f,d,_,g,v){if(++f>=4096||++c>=40)return f;var p,y,w=s[0],x=s[1],b=s[6],C=s[7],S=m.getSignedDistance,P=S(w,x,b,C,s[2],s[3]),I=S(w,x,b,C,s[4],s[5]),M=P*I>0?.75:4/9,T=M*Math.min(0,P,I),z=M*Math.max(0,P,I),O=S(w,x,b,C,r[0],r[1]),A=S(w,x,b,C,r[2],r[3]),L=S(w,x,b,C,r[4],r[5]),N=S(w,x,b,C,r[6],r[7]),B=i(O,A,L,N),D=B[0],j=B[1];if(0===P&&0===I&&0===O&&0===A&&0===L&&0===N||null==(p=n(D,j,T,z))||null==(y=n(D.reverse(),j.reverse(),T,z)))return f;var E=d+(_-d)*p,F=d+(_-d)*y;if(Math.max(v-g,F-E)<1e-9){var R=(E+F)/2,q=(g+v)/2;t(h,u,l?o:a,l?q:R,l?a:o,l?R:q)}else if(r=k.getPart(r,p,y),y-p>.8)if(F-E>v-g){R=(E+F)/2;f=e(s,(V=k.subdivide(r,.5))[0],o,a,h,u,!l,c,f,g,v,E,R),f=e(s,V[1],o,a,h,u,!l,c,f,g,v,R,F)}else{var V=k.subdivide(s,.5),q=(g+v)/2;f=e(V[0],r,o,a,h,u,!l,c,f,g,q,E,F),f=e(V[1],r,o,a,h,u,!l,c,f,q,v,E,F)}else f=v-g>=1e-9?e(s,r,o,a,h,u,!l,c,f,g,v,E,F):e(r,s,a,o,h,u,l,c,f,E,F,g,v);return f}function i(t,e,i,n){var r,s=[0,t],a=[1/3,e],o=[2/3,i],h=[1,n],u=e-(2*t+n)/3,l=i-(t+2*n)/3;if(u*l<0)r=[[s,a,h],[s,o,h]];else{var c=u/l;r=[c>=2?[s,a,h]:c<=.5?[s,o,h]:[s,a,o,h],[s,h]]}return(u||l)<0?r.reverse():r}function n(t,e,i,n){return t[0][1]n?r(e,!1,n):t[0][0]}function r(t,e,i){for(var n=t[0][0],r=t[0][1],s=1,a=t.length;s=i:h<=i)return h===i?o:n+(i-r)*(o-n)/(h-r);n=o,r=h}return null}function s(t,e,i,n,r){var s=u.isZero;if(s(n)&&s(r)){var a=k.getTimeOf(t,new c(e,i));return null===a?[]:[a]}for(var o=Math.atan2(-r,n),h=Math.sin(o),l=Math.cos(o),f=[],d=[],_=0;_<8;_+=2){var g=t[_]-e,v=t[_+1]-i;f.push(g*l-v*h,g*h+v*l)}return k.solveCubic(f,1,0,d,0,1),d}function a(e,i,n,r,a,o,h){for(var u=i[0],l=i[1],c=s(e,u,l,i[6]-u,i[7]-l),f=0,d=c.length;fl(n[0],n[2],n[4],n[6])&&l(i[0],i[2],i[4],i[6])-1e-12l(n[1],n[3],n[5],n[7])&&l(i[1],i[3],i[5],i[7])-1e-12>1,C=1&x,S=6*b,P=6*C,I=new c(i[S],i[S+1]),M=new c(n[P],n[P+1]);I.isClose(M,1e-12)&&t(h,u,r,b,s,C)}}}return h}function l(e,i,n,r){var s=k.classify(e);if("loop"===s.type){var a=s.roots;t(n,r,i,a[0],i,a[1])}return n}function f(t,e){function i(t){var e=t[6]-t[0],i=t[7]-t[1];return e*e+i*i}var n=Math.abs,r=m.getDistance,s=k.isStraight(t),a=k.isStraight(e),o=s&&a,h=i(t)>1,C=k.getTimeOf(v[w],new c(v[x][b?6:0],v[x][b?7:1]));if(null!=C){var S=w?[b,C]:[C,b];(!p.length||n(S[0]-p[0][0])>1e-8&&n(S[1]-p[0][1])>1e-8)&&p.push(S)}if(y>2&&!p.length)break}if(2!==p.length)p=null;else if(!o){var P=k.getPart(t,p[0][0],p[1][0]),I=k.getPart(e,p[0][1],p[1][1]);(n(I[2]-P[2])>1e-7||n(I[3]-P[3])>1e-7||n(I[4]-P[4])>1e-7||n(I[5]-P[5])>1e-7)&&(p=null)}return p}return{getIntersections:function(t){var e=this.getValues(),i=t&&t!==this&&t.getValues();return i?h(e,i,this,t,[]):l(e,this,[])},statics:{getOverlaps:f,getIntersections:function(t,e,i,n,r,s){var a=!e;a&&(e=t);for(var o,u,c=t.length,f=e.length,d=[],_=[],g=0;g=.99999999){var s=t.getNext();s&&(e=0,t=s)}this._setCurve(t),this._time=e,this._point=i||t.getPointAtTime(e),this._overlap=n,this._distance=r,this._intersection=this._next=this._previous=null},_setCurve:function(t){var e=t._path;this._path=e,this._version=e?e._version:0,this._curve=t,this._segment=null,this._segment1=t._segment1,this._segment2=t._segment2},_setSegment:function(t){this._setCurve(t.getCurve()),this._segment=t,this._time=t===this._segment1?0:1,this._point=t._point.clone()},getSegment:function(){var t=this._segment;if(!t){var e=this.getCurve(),i=this.getTime();0===i?t=e._segment1:1===i?t=e._segment2:null!=i&&(t=e.getPartLength(0,i)1?n[r-1]:r>0?n[0]:.5;c.push(k.getLength(i,e?s:0,e?1:s)/2)}function e(t,e,i){return ee&&te||t=1e-8&&n<=1-1e-8,a=r>=1e-8&&r<=1-1e-8;if(s&&a)return!this.isTouching();var o=this.getCurve(),h=n<1e-8?o.getPrevious():o,u=i.getCurve(),l=r<1e-8?u.getPrevious():u;if(n>1-1e-8&&(o=o.getNext()),r>1-1e-8&&(u=u.getNext()),!(h&&o&&l&&u))return!1;var c=[];s||(t(h,!0),t(o,!1)),a||(t(l,!0),t(u,!1));var f=this.getPoint(),d=Math.min.apply(Math,c),_=s?o.getTangentAtTime(n):o.getPointAt(d).subtract(f),g=s?_.negate():h.getPointAt(-d).subtract(f),v=a?u.getTangentAtTime(r):u.getPointAt(d).subtract(f),p=a?v.negate():l.getPointAt(-d).subtract(f),m=g.getAngle(),y=_.getAngle(),w=p.getAngle(),x=v.getAngle();return!!(s?e(m,w,x)^e(y,w,x)&&e(m,x,w)^e(y,x,w):e(w,m,y)^e(x,m,y)&&e(w,y,m)^e(x,y,m))},hasOverlap:function(){return!!this._overlap}},r.each(k._evaluateMethods,function(t){var e=t+"At";this[t]=function(){var t=this.getCurve(),i=this.getTime();return null!=i&&t&&t[e](i,!0)}},{preserve:!0}),new function(){function t(t,e,i){function n(i,n){for(var s=i+n;s>=-1&&s<=r;s+=n){var a=t[(s%r+r)%r];if(!e.getPoint().isClose(a.getPoint(),1e-7))break;if(e.equals(a))return a}return null}for(var r=t.length,s=0,a=r-1;s<=a;){var o,h=s+a>>>1,u=t[h];if(i&&(o=e.equals(u)?u:n(h,-1)||n(h,1)))return e._overlap&&(o._overlap=o._intersection._overlap=!0),o;var l=e.getPath(),c=u.getPath();(l!==c?l._id-c._id:e.getIndex()+e.getTime()-(u.getIndex()+u.getTime()))<0?a=h-1:s=h+1}return t.splice(s,0,e),e}return{statics:{insert:t,expand:function(e){for(var i=e.slice(),n=e.length-1;n>=0;n--)t(i,e[n]._intersection,!1);return i}}}}),A=w.extend({_class:"PathItem",_selectBounds:!1,_canScaleStroke:!0,beans:!0,initialize:function(){},statics:{create:function(t){var e,i,n;if(r.isPlainObject(t)?(i=t.segments,e=t.pathData):Array.isArray(t)?i=t:"string"==typeof t&&(e=t),i){var s=i[0];n=s&&Array.isArray(s[0])}else e&&(n=(e.match(/m/gi)||[]).length>1||/z\s*\S+/i.test(e));return new(n?N:L)(t)}},_asPathItem:function(){return this},isClockwise:function(){return this.getArea()>=0},setClockwise:function(t){this.isClockwise()!=(t=!!t)&&this.reverse()},setPathData:function(t){function e(t,e){var i=+n[t];return o&&(i+=h[e]),i}function i(t){return new c(e(t,"x"),e(t+1,"y"))}var n,r,s,a=t&&t.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/gi),o=!1,h=new c,u=new c;this.clear();for(var l=0,f=a&&a.length;lu&&this[n?"removeSegments":"removeChildren"](u,h);for(c=0;c=0&&e;h--){var u=i[h];e=!1;for(var l=s-1;l>=0&&!e;l--)u.compare(n[l])&&(a[l]||(a[l]=!0,o++),e=!0)}e=e&&o===s}return e}}),L=A.extend({_class:"Path",_serializeFields:{segments:[],closed:!1},initialize:function(t){this._closed=!1,this._segments=[],this._version=0;var i=Array.isArray(t)?"object"==typeof t[0]?t:arguments:!t||t.size!==e||t.x===e&&t.point===e?null:arguments;i&&i.length>0?this.setSegments(i):(this._curves=e,this._segmentSelection=0,i||"string"!=typeof t||(this.setPathData(t),t=null)),this._initialize(!i&&t)},_equals:function(t){return this._closed===t._closed&&r.equals(this._segments,t._segments)},copyContent:function(t){this.setSegments(t._segments),this._closed=t._closed},_changed:function t(i){if(t.base.call(this,i),8&i){if(this._length=this._area=e,16&i)this._version++;else if(this._curves)for(var n=0,r=this._curves.length;n0&&(i(f[0],!0),p.push("z")),p.join("")},isEmpty:function(){return!this._segments.length},_transformContent:function(t){for(var e=this._segments,i=new Array(6),n=0,r=e.length;n0&&e+r-1===u?e-1:e,c=l,f=Math.min(l+r,u);t._curves&&(n.splice.apply(n,[l,0].concat(t._curves)),c+=t._curves.length);for(a=c;a0?t-1:t},add:function(t){return arguments.length>1&&"number"!=typeof t?this._add(T.readList(arguments)):this._add([T.read(arguments)])[0]},insert:function(t,e){return arguments.length>2&&"number"!=typeof e?this._add(T.readList(arguments,1),t):this._add([T.read(arguments,1)],t)[0]},addSegment:function(){return this._add([T.read(arguments)])[0]},insertSegment:function(t){return this._add([T.read(arguments,1)],t)[0]},addSegments:function(t){return this._add(T.readList(t))},insertSegments:function(t,e){return this._add(T.readList(e),t)},removeSegment:function(t){return this.removeSegments(t,t+1)[0]||null},removeSegments:function(t,e,i){t=t||0,e=r.pick(e,this._segments.length);var n=this._segments,s=this._curves,a=n.length,o=n.splice(t,e-t),h=o.length;if(!h)return o;for(l=0;l0&&e===a+(this._closed?1:0)?t-1:t,l=(s=s.splice(f,h)).length-1;l>=0;l--)s[l]._path=null;i&&(o._curves=s.slice(1)),this._adjustCurves(f,f)}return this._changed(25),o},clear:"#removeSegments",hasHandles:function(){for(var t=this._segments,e=0,i=t.length;e0&&this._segmentSelection===7*t},setFullySelected:function(t){t&&this._selectSegments(!0),this.setSelected(t)},setSelection:function t(e){1&e||this._selectSegments(!1),t.base.call(this,e)},_selectSegments:function(t){var e=this._segments,i=e.length,n=t?7:0;this._segmentSelection=n*i;for(var r=0;r0&&this.setSelected(!0)},divideAt:function(t){var e,i=this.getLocationAt(t);return i&&(e=i.getCurve().divideAt(i.getCurveOffset()))?e._segment1:null},splitAt:function(t){var e=this.getLocationAt(t),i=e&&e.index,n=e&&e.time;n>1-1e-8&&(i++,n=0);var r=this.getCurves();if(i>=0&&i=1e-8&&r[i++].divideAtTime(n);var s,a=this.removeSegments(i,this._segments.length,!0);return this._closed?(this.setClosed(!1),s=this):((s=new L(w.NO_INSERT)).insertAbove(this),s.copyAttributes(this)),s._add(a,0),this.addSegment(a[0]),s}return null},split:function(t,i){var n,r=i===e?t:(n=this.getCurves()[t])&&n.getLocationAtTime(i);return null!=r?this.splitAt(r):null},join:function(t,e){var i=e||0;if(t&&t!==this){var n=t._segments,r=this.getLastSegment(),s=t.getLastSegment();if(!s)return this;r&&r._point.isClose(s._point,i)&&t.reverse();var a=t.getFirstSegment();if(r&&r._point.isClose(a._point,i))r.setHandleOut(a._handleOut),this._add(n.slice(1));else{var o=this.getFirstSegment();o&&o._point.isClose(a._point,i)&&t.reverse(),s=t.getLastSegment(),o&&o._point.isClose(s._point,i)?(o.setHandleIn(s._handleIn),this._add(n.slice(0,n.length-1),0)):this._add(n.slice())}t._closed&&this._add([n[0]]),t.remove()}var h=this.getFirstSegment(),u=this.getLastSegment();return h!==u&&h._point.isClose(u._point,i)&&(h.setHandleIn(u._handleIn),u.remove(),this.setClosed(!0)),this},reduce:function(t){for(var e=this.getCurves(),i=t&&t.simplify,n=i?1e-7:0,r=e.length-1;r>=0;r--){var s=e[r];!s.hasHandles()&&(!s.hasLength(n)||i&&s.isCollinear(s.getNext()))&&s.remove()}return this},reverse:function(){this._segments.reverse();for(var t=0,e=this._segments.length;t0&&n.push(new T(e[i-1].curve.slice(6))),this.setSegments(n)},simplify:function(t){var e=new D(this).fit(t||2.5);return e&&this.setSegments(e),!!e},smooth:function(t){function i(t,e){var i=t&&t.index;if(null!=i){var r=t.path;if(r&&r!==n)throw new Error(t._class+" "+i+" of "+r+" is not part of "+n);e&&t instanceof k&&i++}else i="number"==typeof t?t:e;return Math.min(i<0&&h?i%o:i<0?i+o:i,o-1)}var n=this,r=t||{},s=r.type||"asymmetric",a=this._segments,o=a.length,h=this._closed,u=h&&r.from===e&&r.to===e,l=i(r.from,0),c=i(r.to,o-1);if(l>c)if(h)l-=o;else{var f=l;l=c,c=f}if(/^(?:asymmetric|continuous)$/.test(s)){var d="asymmetric"===s,_=Math.min,g=c-l+1,v=g-1,p=u?_(g,4):1,m=p,y=p,w=[];if(h||(m=_(1,l),y=_(1,o-c-1)),(v+=m+y)<=1)return;for(var x=0,b=l-m;x<=v;x++,b++)w[x]=a[(b<0?b+o:b)%o]._point;for(var C=w[0]._x+2*w[1]._x,S=w[0]._y+2*w[1]._y,P=2,I=v-1,M=[C],T=[S],z=[P],O=[],A=[],x=1;x=0;x--)O[x]=(M[x]-O[x+1])/z[x],A[x]=(T[x]-A[x+1])/z[x];O[v]=(3*w[v]._x-O[I])/2,A[v]=(3*w[v]._y-A[I])/2;for(var x=m,F=v-y,b=l;x<=F;x++,b++){var R=a[b<0?b+o:b],q=R._point,V=O[x]-q._x,H=A[x]-q._y;(u||xm)&&R.setHandleIn(-V,-H)}}else for(x=l;x<=c;x++)a[x<0?x+o:x].smooth(r,!u&&x===l,!u&&x===c)},toShape:function(t){function i(t,e){var i=l[t],n=i.getNext(),r=l[e],s=r.getNext();return i._handleOut.isZero()&&n._handleIn.isZero()&&r._handleOut.isZero()&&s._handleIn.isZero()&&n._point.subtract(i._point).isCollinear(s._point.subtract(r._point))}function n(t){var e=l[t],i=e.getNext(),n=e._handleOut,r=i._handleIn;if(n.isOrthogonal(r)){var s=e._point,a=i._point,o=new m(s,n,!0).intersect(new m(a,r,!0),!0);return o&&u.isZero(n.getLength()/o.subtract(s).getLength()-.5522847498307936)&&u.isZero(r.getLength()/o.subtract(a).getLength()-.5522847498307936)}return!1}function r(t,e){return l[t]._point.getDistance(l[e]._point)}if(!this._closed)return null;var s,a,o,h,l=this._segments;if(!this.hasHandles()&&4===l.length&&i(0,2)&&i(1,3)&&function(t){var e=l[t],i=e.getPrevious(),n=e.getNext();return i._handleOut.isZero()&&e._handleIn.isZero()&&e._handleOut.isZero()&&n._handleIn.isZero()&&e._point.subtract(i._point).isOrthogonal(n._point.subtract(e._point))}(1)?(s=C.Rectangle,a=new d(r(0,3),r(0,1)),h=l[1]._point.add(l[2]._point).divide(2)):8===l.length&&n(0)&&n(2)&&n(4)&&n(6)&&i(1,5)&&i(3,7)?(s=C.Rectangle,o=(a=new d(r(1,6),r(0,3))).subtract(new d(r(0,7),r(1,2))).divide(2),h=l[3]._point.add(l[4]._point).divide(2)):4===l.length&&n(0)&&n(1)&&n(2)&&n(3)&&(u.isZero(r(0,2)-r(1,3))?(s=C.Circle,o=r(0,2)/2):(s=C.Ellipse,o=new d(r(2,0)/2,r(3,1)/2)),h=l[1]._point),s){var c=this.getPosition(!0),f=new s({center:c,size:a,radius:o,insert:!1});return f.copyAttributes(this,!0),f._matrix.prepend(this._matrix),f.rotate(h.subtract(c).getAngle()+90),(t===e||t)&&f.insertAbove(this),f}return null},toPath:"#clone",compare:function t(e){if(!e||e instanceof N)return t.base.call(this,e);var i=this.getCurves(),n=e.getCurves(),r=i.length,s=n.length;if(!r||!s)return r==s;for(var a,o,h=i[0].getValues(),u=[],l=0,c=0,f=0;f0?s-1:f,o=v[0][1];break}}for(var d,_=Math.abs,g=u[a];h&&g;){var v=k.getOverlaps(h,g);if(v&&_(v[0][0]-c)<1e-8){1===(c=v[1][0])&&(h=++l=s&&(a=0),g=u[a]||n[a].getValues(),o=0),!h)return d[0]===a&&d[1]===o;continue}}break}return!1},_hitTestSelf:function(t,e,i,n){function r(e,i){return t.subtract(e).divide(i).length<=1}function s(t,i,n){if(!e.selected||i.isSelected()){var s=t._point;if(i!==s&&(i=i.add(s)),r(i,x))return new M(n,g,{segment:t,point:i})}}function a(t,i){return(i||e.segments)&&s(t,t._point,"segment")||!i&&e.handles&&(s(t,t._handleIn,"handle-in")||s(t,t._handleOut,"handle-out"))}function o(t){f.add(t)}function h(e){var i=y||e._index>0&&e._index0||S?0:null;if(null!==P&&(P>0?(u=v.getStrokeJoin(),l=v.getStrokeCap(),c=v.getMiterLimit(),x=x.add(L._getStrokePadding(P,n))):u=l="round"),!e.ends||e.segments||y){if(e.segments||e.handles)for(T=0;T1?h(d.getSegment())||(d=null):r(d.getPoint(),x)||(d=null)}if(!d&&"miter"===u&&m>1)for(var T=0;Tt)return a.getLocationAt(t-s)}if(e.length>0&&t<=this.getLength())return new O(e[e.length-1],1)}else if(t&&t.getPath&&t.getPath()===this)return t;return null}}),new function(){function t(t,e,i,n){function r(e){var i=h[e],n=h[e+1];s==i&&a==n||(t.beginPath(),t.moveTo(s,a),t.lineTo(i,n),t.stroke(),t.beginPath(),t.arc(i,n,o,0,2*Math.PI,!0),t.fill())}for(var s,a,o=n/2,h=new Array(6),u=0,l=e.length;u0&&n(f[0])}return{_draw:function(t,i,n,r){function s(t){return c[(t%f+f)%f]}var a=i.dontStart,o=i.dontFinish||i.clip,h=this.getStyle(),u=h.hasFill(),l=h.hasStroke(),c=h.getDashArray(),f=!paper.support.nativeDash&&l&&c&&c.length;if(a||t.beginPath(),(u||l&&!f||o)&&(e(t,this,r),this._closed&&t.closePath()),!o&&(u||l)&&(this._setStyles(t,i,n),u&&(t.fill(h.getFillRule()),t.shadowColor="rgba(0,0,0,0)"),l)){if(f){a||t.beginPath();var d,_=new B(this,.25,32,!1,r),g=_.length,v=-h.getDashOffset(),p=0;for(v%=g;v>0;)v-=s(p--)+s(p--);for(;v0||d>0)&&_.drawPart(t,Math.max(v,0),Math.max(d,0)),v=d+s(p++)}t.stroke()}},_drawSelected:function(i,n){i.beginPath(),e(i,this,n),i.stroke(),t(i,this._segments,n,paper.settings.handleSize)}}},new function(){function t(t){var e=t._segments;if(!e.length)throw new Error("Use a moveTo() command first");return e[e.length-1]}return{moveTo:function(){var t=this._segments;1===t.length&&this.removeSegment(0),t.length||this._add([new T(c.read(arguments))])},moveBy:function(){throw new Error("moveBy() is unsupported on Path items.")},lineTo:function(){this._add([new T(c.read(arguments))])},cubicCurveTo:function(){var e=c.read(arguments),i=c.read(arguments),n=c.read(arguments),r=t(this);r.setHandleOut(e.subtract(r._point)),this._add([new T(n,i.subtract(n))])},quadraticCurveTo:function(){var e=c.read(arguments),i=c.read(arguments),n=t(this)._point;this.cubicCurveTo(e.add(n.subtract(e).multiply(1/3)),e.add(i.subtract(e).multiply(1/3)),i)},curveTo:function(){var e=c.read(arguments),i=c.read(arguments),n=r.pick(r.read(arguments),.5),s=1-n,a=t(this)._point,o=e.subtract(a.multiply(s*s)).subtract(i.multiply(n*n)).divide(2*n*s);if(o.isNaN())throw new Error("Cannot put a curve through points with parameter = "+n);this.quadraticCurveTo(o,i)},arcTo:function(){var e,i,n,s,a=Math.abs,o=Math.sqrt,h=t(this),l=h._point,f=c.read(arguments),_=r.peek(arguments);if("boolean"==typeof(x=r.pick(_,!0)))var g=(C=l.add(f).divide(2)).add(C.subtract(l).rotate(x?-90:90));else if(r.remain(arguments)<=2)g=f,f=c.read(arguments);else{var v=d.read(arguments),y=u.isZero;if(y(v.width)||y(v.height))return this.lineTo(f);var w=r.read(arguments),x=!!r.read(arguments),b=!!r.read(arguments),C=l.add(f).divide(2),S=(W=l.subtract(C).rotate(-w)).x,P=W.y,I=a(v.width),M=a(v.height),z=I*I,k=M*M,O=S*S,A=P*P,L=o(O/z+A/k);if(L>1&&(z=(I*=L)*I,k=(M*=L)*M),L=(z*k-z*A-k*O)/(z*A+k*O),a(L)<1e-12&&(L=0),L<0)throw new Error("Cannot create an arc with the given arguments");e=new c(I*P/M,-M*S/I).multiply((b===x?-1:1)*o(L)).rotate(w).add(C),i=(n=(s=(new p).translate(e).rotate(w).scale(I,M))._inverseTransform(l)).getDirectedAngle(s._inverseTransform(f)),!x&&i>0?i-=360:x&&i<0&&(i+=360)}if(g){var N=new m(l.add(g).divide(2),g.subtract(l).rotate(90),!0),B=new m(g.add(f).divide(2),f.subtract(g).rotate(90),!0),D=new m(l,f),j=D.getSide(g);if(!(e=N.intersect(B,!0))){if(!j)return this.lineTo(f);throw new Error("Cannot create an arc with the given arguments")}i=(n=l.subtract(e)).getDirectedAngle(f.subtract(e));var E=D.getSide(e);0===E?i=j*a(i):j===E&&(i+=i<0?360:-360)}for(var F=a(i),R=F>=360?4:Math.ceil((F-1e-7)/90),q=i/R,V=q*Math.PI/360,H=4/3*Math.sin(V)/(1+Math.cos(V)),Z=[],U=0;U<=R;U++){var W=f,G=null;if(U0&&(h(t[0],y),h(t[t.length-1],y)),v},_getStrokePadding:function(t,e){if(!e)return[t,t];var i=new c(t,0).transform(e),n=new c(0,t).transform(e),r=i.getAngleInRadians(),s=i.getLength(),a=n.getLength(),o=Math.sin(r),h=Math.cos(r),u=Math.tan(r),l=Math.atan2(a*u,s),f=Math.atan2(a,u*s);return[Math.abs(s*Math.cos(l)*h+a*Math.sin(l)*o),Math.abs(a*Math.sin(f)*h+s*Math.cos(f)*o)]},_addBevelJoin:function(t,e,i,n,r,s,a,o){var h=t.getCurve(),u=h.getPrevious(),l=h.getPoint1().transform(r),f=u.getNormalAtTime(1).multiply(i).transform(s),d=h.getNormalAtTime(0).multiply(i).transform(s);if(f.getDirectedAngle(d)<0&&(f=f.negate(),d=d.negate()),o&&a(l),a(l.add(f)),"miter"===e){var _=new m(l.add(f),new c(-f.y,f.x),!0).intersect(new m(l.add(d),new c(-d.y,d.x),!0),!0);_&&l.getDistance(_)<=n*i&&a(_)}a(l.add(d))},_addSquareCap:function(t,e,i,n,r,s,a){var o=t._point.transform(n),h=t.getLocation(),u=h.getNormal().multiply(0===h.getTime()?i:-i).transform(r);"square"===e&&(a&&(s(o.subtract(u)),s(o.add(u))),o=o.add(u.rotate(-90))),s(o.add(u)),s(o.subtract(u))},getHandleBounds:function(t,e,i,n,r){var s,a,o=i.getStyle();if(r.stroke&&o.hasStroke()){var h=i._getStrokeMatrix(n,r),u=o.getStrokeWidth()/2,l=u;"miter"===o.getStrokeJoin()&&(l=u*o.getMiterLimit()),"square"===o.getStrokeCap()&&(l=Math.max(l,u*Math.SQRT2)),s=L._getStrokePadding(u,h),a=L._getStrokePadding(l,h)}for(var c=new Array(6),f=1/0,d=-f,_=f,v=d,p=0,m=t.length;pd&&(d=I),M<_&&(_=M),T>v&&(v=T)}}return new g(f,_,d-f,v-_)}}});L.inject({statics:new function(){function t(t,e,i){var n=r.getNamed(i),s=new L(n&&0==n.insert&&w.NO_INSERT);return s._add(t),s._closed=e,s.set(n,{insert:!0})}function e(e,i,r){for(var s=new Array(4),a=0;a<4;a++){var o=n[a];s[a]=new T(o._point.multiply(i).add(e),o._handleIn.multiply(i),o._handleOut.multiply(i))}return t(s,!0,r)}var i=.5522847498307936,n=[new T([-1,0],[0,i],[0,-i]),new T([0,-1],[-i,0],[i,0]),new T([1,0],[0,-i],[0,i]),new T([0,1],[i,0],[-i,0])];return{Line:function(){return t([new T(c.readNamed(arguments,"from")),new T(c.readNamed(arguments,"to"))],!1,arguments)},Circle:function(){var t=c.readNamed(arguments,"center"),i=r.readNamed(arguments,"radius");return e(t,new d(i),arguments)},Rectangle:function(){var e,n=g.readNamed(arguments,"rectangle"),r=d.readNamed(arguments,"radius",0,{readNull:!0}),s=n.getBottomLeft(!0),a=n.getTopLeft(!0),o=n.getTopRight(!0),h=n.getBottomRight(!0);if(!r||r.isZero())e=[new T(s),new T(a),new T(o),new T(h)];else{var u=(r=d.min(r,n.getSize(!0).divide(2))).width,l=r.height,c=u*i,f=l*i;e=[new T(s.add(u,0),null,[-c,0]),new T(s.subtract(0,l),[0,f]),new T(a.add(0,l),null,[0,-f]),new T(a.add(u,0),[-c,0],null),new T(o.subtract(u,0),null,[c,0]),new T(o.add(0,l),[0,-f],null),new T(h.subtract(0,l),null,[0,f]),new T(h.subtract(u,0),[c,0])]}return t(e,!0,arguments)},RoundRectangle:"#Rectangle",Ellipse:function(){var t=C._readEllipse(arguments);return e(t.center,t.radius,arguments)},Oval:"#Ellipse",Arc:function(){var t=c.readNamed(arguments,"from"),e=c.readNamed(arguments,"through"),i=c.readNamed(arguments,"to"),n=r.getNamed(arguments),s=new L(n&&0==n.insert&&w.NO_INSERT);return s.moveTo(t),s.arcTo(e,i),s.set(n)},RegularPolygon:function(){for(var e=c.readNamed(arguments,"center"),i=r.readNamed(arguments,"sides"),n=r.readNamed(arguments,"radius"),s=360/i,a=i%3==0,o=new c(0,a?-n:n),h=a?-1:.5,u=new Array(i),l=0;l=0;a--){var o=n[a];n!==i||o instanceof L||(n=r.slice(n)),Array.isArray(o)?n[a]=new L({segments:o,insert:!1}):o instanceof N&&(n.splice.apply(n,[a,1].concat(o.removeChildren())),o.remove())}return t.base.call(this,e,n)},reduce:function t(e){for(var i=this._children,n=i.length-1;n>=0;n--)(r=i[n].reduce(e)).isEmpty()&&r.remove();if(!i.length){var r=new L(w.NO_INSERT);return r.copyAttributes(this),r.insertAbove(this),this.remove(),r}return t.base.call(this)},isClosed:function(){for(var t=this._children,e=0,i=t.length;e=0;d--){var _=h[d].split();_&&(s(_)&&_.getFirstSegment().setHandleIn(0,0),a.getLastSegment().setHandleOut(0,0))}return s(a),i(f,!1,e,n)}function a(t,e){for(var i=t;i;){if(i===e)return;i=i._previous}for(;t._next&&t._next!==e;)t=t._next;if(!t._next){for(;e._previous;)e=e._previous;t._next=e,e._previous=t}}function o(t){for(var e=t.length-1;e>=0;e--)t[e].clearHandles()}function h(t,e,i){var n=t&&t.length;if(n){var s=r.each(t,function(t,e){this[t._id]={container:null,winding:t.isClockwise()?1:-1,index:e}},{}),a=t.slice().sort(function(t,e){return v(e.getArea())-v(t.getArea())}),o=a[0];null==i&&(i=o.isClockwise());for(var h=0;h=0;d--){var _=a[d];if(_.contains(c)){var g=s[_._id];f=g.winding,l.winding+=f,l.container=g.exclude?g.container:_;break}}if(e(l.winding)===e(f))l.exclude=!0,t[l.index]=null;else{var p=l.container;u.setClockwise(p?!p.isClockwise():i)}}}return t}function l(t,e,i){function n(t){return t._path._id+"."+t._segment1._index}for(var r,s,h,u=e&&[],l=!1,c=i||[],f=i&&{},d=(i&&i.length)-1;d>=0;d--)(y=i[d])._path&&(f[n(y)]=!0);for(d=t.length-1;d>=0;d--){var _,g=t[d],v=g._time,p=v,m=e&&!e(g),y=g._curve;if(y&&(y!==s?(l=!y.hasHandles()||f&&f[n(y)],r=[],h=null,s=y):h>=1e-8&&(v/=h)),m)r&&r.push(g);else{if(e&&u.unshift(g),h=p,v<1e-8)_=y._segment1;else if(v>1-1e-8)_=y._segment2;else{var w=y.divideAtTime(v,!0);l&&c.push(y,w),_=w._segment1;for(var x=r.length-1;x>=0;x--){var b=r[x];b._time=(b._time-v)/(1-v)}}g._setSegment(_);var C=_._intersection,S=g._intersection;if(C){a(C,S);for(var P=C;P;)a(P._intersection,C),P=P._next}else _._intersection=S}}return i||o(c),u||t}function c(t,e,i,n,r){function s(s){var a=s[l+0],h=s[l+6];if(!(p<_(a,h)||p>g(a,h))){var f=s[u+0],v=s[u+2],x=s[u+4],b=s[u+6];if(a!==h){var I=p===a?0:p===h?1:y>g(f,v,x,b)||w<_(f,v,x,b)?1:k.solveCubic(s,l,p,T,0,1)>0?T[0]:1,z=0===I?f:1===I?b:k.getPoint(s,I)[i?"y":"x"],O=a>h?1:-1,A=o[l]>o[l+6]?1:-1,L=o[u+6];return p!==a?(zw?S+=O:P=!0,z>d-m&&zw&&(S+=O):f!=L&&(Lw?(S+=O,P=!0):L>y&&zy&&zy||by)&&(P=!0)}}function a(t){var e=t[l+0],n=t[l+2],r=t[l+4],a=t[l+6];if(p<=g(e,n,r,a)&&p>=_(e,n,r,a))for(var o,h=t[u+0],c=t[u+2],f=t[u+4],d=t[u+6],v=y>g(h,c,f,d)||w<_(h,c,f,d)?[t]:k.getMonoCurves(t,i),m=0,x=v.length;ml.quality&&(l=I);break}d-=m}for(_=s.length-1;_>=0;_--)s[_].segment._winding=l}function d(t,e){function i(t){var i;return!(!t||t._visited||e&&(!e[(i=t._winding||{}).winding]||e.unite&&2===i.winding&&i.windingL&&i.windingR))}function n(t){if(t)for(var e=0,i=s.length;e=0;c--){var f=u[c],_=f._path,g=f._segment,v=g.getPrevious(),p=g.getNext();t(v,_)&&t(p,_)&&(g.remove(),v._handleOut._set(0,0),p._handleIn._set(0,0),v===g||v.getCurve().hasLength()||(p._handleIn.set(v._handleIn),v.remove()))}s&&(l(a,n&&function(t){var e=t.getCurve(),i=t.getSegment(),n=t._intersection,r=n._curve,s=n._segment;if(e&&r&&e._path&&r._path)return!0;i&&(i._intersection=null),s&&(s._intersection=null)},h),h&&o(h),i=d(r.each(i,function(t){this.push.apply(this,t._segments)},[])));var m,y=i.length;return y>1&&e?(i!==e&&this.setChildren(i),m=this):1!==y||e||(i[0]!==this&&this.setSegments(i[0].removeSegments()),m=this),m||((m=new N(w.NO_INSERT)).addChildren(i),(m=m.reduce()).copyAttributes(this),this.replaceWith(m)),m},reorient:function(t,i){var n=this._children;return n&&n.length?this.setChildren(h(this.removeChildren(),function(e){return!!(t?e:1&e)},i)):i!==e&&this.setClockwise(i),this},getInteriorPoint:function(){var t=this.getBounds().getCenter(!0);if(!this.contains(t)){for(var e=this.getCurves(),i=t.y,n=[],r=[],s=0,a=e.length;s=_(h,u,l,c)&&i<=g(h,u,l,c))for(var f=k.getMonoCurves(o),d=0,v=f.length;d=m&&i<=y||i>=y&&i<=m)){var w=i===m?p[0]:i===y?p[6]:1===k.solveCubic(p,1,i,r,0,1)?k.getPoint(p,r[0]).x:(p[0]+p[6])/2;n.push(w)}}}n.length>1&&(n.sort(function(t,e){return t-e}),t.x=(n[0]+n[1])/2)}return t}}});var B=r.extend({_class:"PathFlattener",initialize:function(t,e,i,n,r){function s(t,e){var i=k.getValues(t,e,r);h.push(i),a(i,t._index,0,1)}function a(t,i,r,s){if(!(s-r>c)||n&&k.isStraight(t)||k.isFlatEnough(t,e||.25)){var o=t[6]-t[0],h=t[7]-t[1],f=Math.sqrt(o*o+h*h);f>0&&(l+=f,u.push({offset:l,curve:t,index:i,time:s}))}else{var d=k.subdivide(t,.5),_=(r+s)/2;a(d[0],i,r,_),a(d[1],i,_,s)}}for(var o,h=[],u=[],l=0,c=1/(i||32),f=t._segments,d=f[0],_=1,g=f.length;_=t){this.index=e;var a=i[e-1],o=a&&a.index===s.index?a.time:0,h=a?a.offset:0;return{index:s.index,time:o+(s.time-o)*(t-h)/(s.offset-h)}}}return{index:i[n-1].index,time:1}},drawPart:function(t,e,i){for(var n=this._get(e),r=this._get(i),s=n.index,a=r.index;s<=a;s++){var o=k.getPart(this.curves[s],s===n.index?n.time:0,s===r.index?r.time:1);s===n.index&&t.moveTo(o[0],o[1]),t.bezierCurveTo.apply(t,o.slice(2))}}},r.each(k._evaluateMethods,function(t){this[t+"At"]=function(e){var i=this._get(e);return k[t](this.curves[i.index],i.time)}},{})),D=r.extend({initialize:function(t){for(var e,i=this.points=[],n=t._segments,r=t._closed,s=0,a=n.length;s0&&(n=[new T(e[0])],i>1&&(this.fitCubic(n,t,0,i-1,e[1].subtract(e[0]),e[i-2].subtract(e[i-1])),this.closed&&(n.shift(),n.pop()))),n},fitCubic:function(t,e,i,n,r,s){var a=this.points;if(n-i!=1){for(var o,h=this.chordLengthParameterize(i,n),u=Math.max(e,e*e),l=!0,c=0;c<=4;c++){var f=this.generateBezier(i,n,h,r,s),d=this.findMaxError(i,n,f,h);if(d.error=u)break;l=this.reparameterize(i,n,h,f),u=d.error}var _=a[o-1].subtract(a[o+1]);this.fitCubic(t,e,i,o,r,_),this.fitCubic(t,e,o,n,_.negate(),s)}else{var g=a[i],v=a[n],p=g.getDistance(v)/3;this.addCurve(t,[g,g.add(r.normalize(p)),v.add(s.normalize(p)),v])}},addCurve:function(t,e){t[t.length-1].setHandleOut(e[1].subtract(e[0])),t.push(new T(e[3],e[2].subtract(e[3])))},generateBezier:function(t,e,i,n,r){for(var s=Math.abs,a=this.points,o=a[t],h=a[e],u=[[0,0],[0,0]],l=[0,0],c=0,f=e-t+1;c1e-12){var I=u[0][0]*l[1]-u[1][0]*l[0];C=(l[0]*u[1][1]-l[1]*u[0][1])/P,S=I/P}else{var M=u[0][0]+u[0][1],T=u[1][0]+u[1][1];C=S=s(M)>1e-12?l[0]/M:s(T)>1e-12?l[1]/T:0}var z,k,O=h.getDistance(o),A=1e-12*O;if(CO*O&&(C=S=O/3,z=k=null)}return[o,o.add(z||n.normalize(C)),h.add(k||r.normalize(S)),h]},reparameterize:function(t,e,i,n){for(r=t;r<=e;r++)i[r-t]=this.findRoot(n,this.points[r],i[r-t]);for(var r=1,s=i.length;r=s&&(s=h,r=a)}return{error:s,index:r}}}),j=w.extend({_class:"TextItem",_applyMatrix:!1,_canApplyMatrix:!1,_serializeFields:{content:null},_boundsOptions:{stroke:!1,handle:!1},initialize:function(t){this._content="",this._lines=[];var i=t&&r.isPlainObject(t)&&t.x===e&&t.y===e;this._initialize(i&&t,!i&&c.read(arguments))},_equals:function(t){return this._content===t._content},copyContent:function(t){this.setContent(t._content)},getContent:function(){return this._content},setContent:function(t){this._content=""+t,this._lines=this._content.split(/\r\n|\n|\r/gm),this._changed(265)},isEmpty:function(){return!this._content},getCharacterStyle:"#getStyle",setCharacterStyle:"#setStyle",getParagraphStyle:"#getStyle",setParagraphStyle:"#setStyle"}),E=j.extend({_class:"PointText",initialize:function(){j.apply(this,arguments)},getPoint:function(){var t=this._matrix.getTranslation();return new f(t.x,t.y,this,"setPoint")},setPoint:function(){var t=c.read(arguments);this.translate(t.subtract(this._matrix.getTranslation()))},_draw:function(t,e,i){if(this._content){this._setStyles(t,e,i);var n=this._lines,r=this._style,s=r.hasFill(),a=r.hasStroke(),o=r.getLeading(),h=t.shadowColor;t.font=r.getFontStyle(),t.textAlign=r.getJustification();for(var u=0,l=n.length;u1&&(h-=1),a[o]=6*h<1?s+6*(r-s)*h:2*h<1?r:3*h<2?s+(r-s)*(2/3-h)*6:s}return a},"rgb-gray":function(t,e,i){return[.2989*t+.587*e+.114*i]},"gray-rgb":function(t){return[t,t,t]},"gray-hsb":function(t){return[0,0,t]},"gray-hsl":function(t){return[0,0,t]},"gradient-rgb":function(){return[]},"rgb-gradient":function(){return[]}};return r.each(n,function(t,e){s[e]=[],r.each(t,function(t,i){var a=r.capitalize(t),o=/^(hue|saturation)$/.test(t),h=s[e][i]="gradient"===t?function(t){var e=this._components[0];return t=R.read(Array.isArray(t)?t:arguments,0,{readNull:!0}),e!==t&&(e&&e._removeOwner(this),t&&t._addOwner(this)),t}:"gradient"===e?function(){return c.read(arguments,0,{readNull:"highlight"===t,clone:!0})}:function(t){return null==t||isNaN(t)?0:t};this["get"+a]=function(){return this._type===e||o&&/^hs[bl]$/.test(this._type)?this._components[i]:this._convert(e)[i]},this["set"+a]=function(t){this._type===e||o&&/^hs[bl]$/.test(this._type)||(this._components=this._convert(e),this._properties=n[e],this._type=e),this._components[i]=h.call(this,t),this._changed()}},this)},{_class:"Color",_readIndex:!0,initialize:function e(i){var a,o,h,u,l=arguments,c=this.__read,f=0;Array.isArray(i)&&(i=(l=i)[0]);var d=null!=i&&typeof i;if("string"===d&&i in n&&(a=i,i=l[1],Array.isArray(i)?(o=i,h=l[2]):(c&&(f=1),l=r.slice(l,1),d=typeof i)),!o){if(u="number"===d?l:"object"===d&&null!=i.length?i:null){a||(a=u.length>=3?"rgb":"gray");var _=n[a].length;h=u[_],c&&(f+=u===arguments?_+(null!=h?1:0):1),u.length>_&&(u=r.slice(u,0,_))}else if("string"===d)a="rgb",4===(o=t(i)).length&&(h=o[3],o.length--);else if("object"===d)if(i.constructor===e){if(a=i._type,o=i._components.slice(),h=i._alpha,"gradient"===a)for(var g=1,v=o.length;g1?1:t))}var i=this._convert("rgb"),n=t||null==this._alpha?1:this._alpha;return i=[e(i[0]),e(i[1]),e(i[2])],n<1&&i.push(n<0?0:n),t?"#"+((1<<24)+(i[0]<<16)+(i[1]<<8)+i[2]).toString(16).slice(1):(4==i.length?"rgba(":"rgb(")+i.join(",")+")"},toCanvasStyle:function(t,e){if(this._canvasStyle)return this._canvasStyle;if("gradient"!==this._type)return this._canvasStyle=this.toCSS();var i,n=this._components,r=n[0],s=r._stops,a=n[1],o=n[2],h=n[3],u=e&&e.inverted();if(u&&(a=u._transformPoint(a),o=u._transformPoint(o),h&&(h=u._transformPoint(h))),r._radial){var l=o.getDistance(a);if(h){var c=h.subtract(a);c.getLength()>l&&(h=a.add(c.normalize(l-.1)))}var f=h||a;i=t.createRadialGradient(f.x,f.y,0,a.x,a.y,l)}else i=t.createLinearGradient(a.x,a.y,o.x,o.y);for(var d=0,_=s.length;d<_;d++){var g=s[d],v=g._offset;i.addColorStop(null==v?d/(_-1):v,g._color.toCanvasStyle())}return this._canvasStyle=i},transform:function(t){if("gradient"===this._type){for(var e=this._components,i=1,n=e.length;i0&&!(r instanceof N))for(var a=0,o=s.length;a0},hasStroke:function(){var t=this.getStrokeColor();return!!t&&t.alpha>0&&this.getStrokeWidth()>0},hasShadow:function(){var t=this.getShadowColor();return!!t&&t.alpha>0&&(this.getShadowBlur()>0||!this.getShadowOffset().isZero())},getView:function(){return this._project._view},getFontStyle:function(){var t=this.getFontSize();return this.getFontWeight()+" "+t+(/[a-z]/i.test(t+"")?" ":"px ")+this.getFontFamily()},getFont:"#getFontFamily",setFont:"#setFontFamily",getLeading:function t(){var e=t.base.call(this),i=this.getFontSize();return/pt|em|%|px/.test(i)&&(i=this.getView().getPixelSize(i)),null!=e?e:1.2*i}}),H=new function(){function t(t,e,i,n){for(var r=["","webkit","moz","Moz","ms","o"],s=e[0].toUpperCase()+e.substring(1),a=0;a<6;a++){var o=r[a],h=o?o+s:e;if(h in t){if(!i)return t[h];t[h]=n;break}}}return{getStyles:function(t){var e=t&&9!==t.nodeType?t.ownerDocument:t,i=e&&e.defaultView;return i&&i.getComputedStyle(t,"")},getBounds:function(t,e){var i,n=t.ownerDocument,r=n.body,s=n.documentElement;try{i=t.getBoundingClientRect()}catch(t){i={left:0,top:0,width:0,height:0}}var a=i.left-(s.clientLeft||r.clientLeft||0),o=i.top-(s.clientTop||r.clientTop||0);if(!e){var h=n.defaultView;a+=h.pageXOffset||s.scrollLeft||r.scrollLeft,o+=h.pageYOffset||s.scrollTop||r.scrollTop}return new g(a,o,i.width,i.height)},getViewportBounds:function(t){var e=t.ownerDocument,i=e.defaultView,n=e.documentElement;return new g(0,0,i.innerWidth||n.clientWidth,i.innerHeight||n.clientHeight)},getOffset:function(t,e){return H.getBounds(t,e).getPoint()},getSize:function(t){return H.getBounds(t,!0).getSize()},isInvisible:function(t){return H.getSize(t).equals(new d(0,0))},isInView:function(t){return!H.isInvisible(t)&&H.getViewportBounds(t).intersects(H.getBounds(t,!0))},isInserted:function(t){return n.body.contains(t)},getPrefixed:function(e,i){return e&&t(e,i)},setPrefixed:function(e,i,n){if("object"==typeof i)for(var r in i)t(e,r,!0,i[r]);else t(e,i,!0,n)}}},Z={add:function(t,e){if(t)for(var i in e)for(var n=e[i],r=i.split(/[\s,]+/g),s=0,a=r.length;s1?r.hyphenate(i):i.toLowerCase())}function s(t,e,i,n){var o,h=U._focused;if(l[e]=t,t?c[e]=i:delete c[e],e.length>1&&(o=r.camelize(e))in f){f[o]=t;var u=paper&&paper.agent;if("meta"===o&&u&&u.mac)if(t)a={};else{for(var d in a)d in c&&s(!1,d,a[d],n);a=null}}else t&&a&&(a[e]=i);h&&h._handleKeyEvent(t?"keydown":"keyup",n,e,i)}var a,o,h={"\t":"tab"," ":"space","\b":"backspace","":"delete",Spacebar:"space",Del:"delete",Win:"meta",Esc:"escape"},u={tab:"\t",space:" ",enter:"\r"},l={},c={},f=new r({shift:!1,control:!1,alt:!1,meta:!1,capsLock:!1,space:!1}).inject({option:{get:function(){return this.alt}},command:{get:function(){var t=paper&&paper.agent;return t&&t.mac?this.meta:this.control}}});return Z.add(n,{keydown:function(e){var i=t(e),n=paper&&paper.agent;i.length>1||n&&n.chrome&&(e.altKey||n.mac&&e.metaKey||!n.mac&&e.ctrlKey)?s(!0,i,u[i]||(i.length>1?"":i),e):o=i},keypress:function(e){if(o){var i=t(e),n=e.charCode,r=n>=32?String.fromCharCode(n):i.length>1?"":i;i!==o&&(i=r.toLowerCase()),s(!0,i,r,e),o=null}},keyup:function(e){var i=t(e);i in c&&s(!1,i,c[i],e)}}),Z.add(i,{blur:function(t){for(var e in c)s(!1,e,c[e],t)}}),{modifiers:f,isDown:function(t){return!!l[t]}}},X=G.extend({_class:"MouseEvent",initialize:function(t,e,i,n,r){this.type=t,this.event=e,this.point=i,this.target=n,this.delta=r},toString:function(){return"{ type: '"+this.type+"', point: "+this.point+", target: "+this.target+(this.delta?", delta: "+this.delta:"")+", modifiers: "+this.getModifiers()+" }"}}),Y=G.extend({_class:"ToolEvent",_item:null,initialize:function(t,e,i){this.tool=t,this.type=e,this.event=i},_choosePoint:function(t,e){return t||(e?e.clone():null)},getPoint:function(){return this._choosePoint(this._point,this.tool._point)},setPoint:function(t){this._point=t},getLastPoint:function(){return this._choosePoint(this._lastPoint,this.tool._lastPoint)},setLastPoint:function(t){this._lastPoint=t},getDownPoint:function(){return this._choosePoint(this._downPoint,this.tool._downPoint)},setDownPoint:function(t){this._downPoint=t},getMiddlePoint:function(){return!this._middlePoint&&this.tool._lastPoint?this.tool._point.add(this.tool._lastPoint).divide(2):this._middlePoint},setMiddlePoint:function(t){this._middlePoint=t},getDelta:function(){return!this._delta&&this.tool._lastPoint?this.tool._point.subtract(this.tool._lastPoint):this._delta},setDelta:function(t){this._delta=t},getCount:function(){return this.tool[/^mouse(down|up)$/.test(this.type)?"_downCount":"_moveCount"]},setCount:function(t){this.tool[/^mouse(down|up)$/.test(this.type)?"downCount":"count"]=t},getItem:function(){if(!this._item){var t=this.tool._scope.project.hitTest(this.getPoint());if(t){for(var e=t.item,i=e._parent;/^(Group|CompoundPath)$/.test(i._class);)e=i,i=i._parent;this._item=e}}return this._item},setItem:function(t){this._item=t},toString:function(){return"{ type: "+this.type+", point: "+this.getPoint()+", count: "+this.getCount()+", modifiers: "+this.getModifiers()+" }"}}),K=(o.extend({_class:"Tool",_list:"tools",_reference:"tool",_events:["onMouseDown","onMouseUp","onMouseDrag","onMouseMove","onActivate","onDeactivate","onEditOptions","onKeyDown","onKeyUp"],initialize:function(t){o.call(this),this._moveCount=-1,this._downCount=-1,this.set(t)},getMinDistance:function(){return this._minDistance},setMinDistance:function(t){this._minDistance=t,null!=t&&null!=this._maxDistance&&t>this._maxDistance&&(this._maxDistance=t)},getMaxDistance:function(){return this._maxDistance},setMaxDistance:function(t){this._maxDistance=t,null!=this._minDistance&&null!=t&&t255){var u=255-r,l=o-r;d=r+(d-r)*u/l,_=r+(_-r)*u/l,g=r+(g-r)*u/l}}function i(t,e,i){return p(t,e,i)-v(t,e,i)}function n(t,e,i,n){var r,s=[t,e,i],a=p(t,e,i),o=v(t,e,i);r=0===v(o=o===t?0:o===e?1:2,a=a===t?0:a===e?1:2)?1===p(o,a)?2:1:0,s[a]>s[o]?(s[r]=(s[r]-s[o])*n/(s[a]-s[o]),s[a]=n):s[r]=s[a]=0,s[o]=0,d=s[0],_=s[1],g=s[2]}var s,a,o,h,u,l,c,f,d,_,g,v=Math.min,p=Math.max,m=Math.abs,y={multiply:function(){d=u*s/255,_=l*a/255,g=c*o/255},screen:function(){d=u+s-u*s/255,_=l+a-l*a/255,g=c+o-c*o/255},overlay:function(){d=u<128?2*u*s/255:255-2*(255-u)*(255-s)/255,_=l<128?2*l*a/255:255-2*(255-l)*(255-a)/255,g=c<128?2*c*o/255:255-2*(255-c)*(255-o)/255},"soft-light":function(){var t=s*u/255;d=t+u*(255-(255-u)*(255-s)/255-t)/255,_=(t=a*l/255)+l*(255-(255-l)*(255-a)/255-t)/255,g=(t=o*c/255)+c*(255-(255-c)*(255-o)/255-t)/255},"hard-light":function(){d=s<128?2*s*u/255:255-2*(255-s)*(255-u)/255,_=a<128?2*a*l/255:255-2*(255-a)*(255-l)/255,g=o<128?2*o*c/255:255-2*(255-o)*(255-c)/255},"color-dodge":function(){d=0===u?0:255===s?255:v(255,255*u/(255-s)),_=0===l?0:255===a?255:v(255,255*l/(255-a)),g=0===c?0:255===o?255:v(255,255*c/(255-o))},"color-burn":function(){d=255===u?255:0===s?0:p(0,255-255*(255-u)/s),_=255===l?255:0===a?0:p(0,255-255*(255-l)/a),g=255===c?255:0===o?0:p(0,255-255*(255-c)/o)},darken:function(){d=us?u:s,_=l>a?l:a,g=c>o?c:o},difference:function(){(d=u-s)<0&&(d=-d),(_=l-a)<0&&(_=-_),(g=c-o)<0&&(g=-g)},exclusion:function(){d=u+s*(255-u-u)/255,_=l+a*(255-l-l)/255,g=c+o*(255-c-c)/255},hue:function(){n(s,a,o,i(u,l,c)),e(d,_,g,t(u,l,c))},saturation:function(){n(u,l,c,i(s,a,o)),e(d,_,g,t(u,l,c))},luminosity:function(){e(u,l,c,t(s,a,o))},color:function(){e(s,a,o,t(u,l,c))},add:function(){d=v(u+s,255),_=v(l+a,255),g=v(c+o,255)},subtract:function(){d=p(u-s,0),_=p(l-a,0),g=p(c-o,0)},average:function(){d=(u+s)/2,_=(l+a)/2,g=(c+o)/2},negation:function(){d=255-m(255-s-u),_=255-m(255-a-l),g=255-m(255-o-c)}},w=this.nativeModes=r.each(["source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","darker","copy","xor"],function(t){this[t]=!0},{}),x=Q.getContext(1,1);x&&(r.each(y,function(t,e){var i="darken"===e,n=!1;x.save();try{x.fillStyle=i?"#300":"#a00",x.fillRect(0,0,1,1),x.globalCompositeOperation=e,x.globalCompositeOperation===e&&(x.fillStyle=i?"#a00":"#300",x.fillRect(0,0,1,1),n=x.getImageData(0,0,1,1).data[0]!==i?170:51)}catch(t){}x.restore(),w[e]=n}),Q.release(x)),this.process=function(t,e,i,n,r){var v=e.canvas,p="normal"===t;if(p||w[t])i.save(),i.setTransform(1,0,0,1,0,0),i.globalAlpha=n,p||(i.globalCompositeOperation=t),i.drawImage(v,r.x,r.y),i.restore();else{var m=y[t];if(!m)return;for(var x=i.getImageData(r.x,r.y,v.width,v.height),b=x.data,C=e.getImageData(0,0,v.width,v.height).data,S=0,P=b.length;S=2&&!t.hasHandles())if(h>2){a=t._closed?"polygon":"polyline";for(var l=[],c=0;c, License: LGPL - Lesser General Public License Credits: - Algorithm based on */ /* Class: NETXUS.RectanglePacker A class that finds an 'efficient' position for a rectangle inside another rectangle without overlapping the space already taken. Algorithm based on It uses a binary tree to partition the space of the parent rectangle and allocate the passed rectangles by dividing the partitions into filled and empty. */ // Create a NETXUS namespace object if it doesn't exists if (typeof NETXUS === 'undefined') var NETXUS = function() {}; /* Constructor: NETXUS.RectanglePacker Initializes the object with the given maximum dimensions Parameters: width - The containing rectangle maximum width as integer height - The containing rectangle maximum height as integer */ NETXUS.RectanglePacker = function ( width, height ) { this.root = {}; // initialize this.reset( width, height ); } /* Resets the object to its initial state by initializing the internal variables Parameters: width - The containing rectangle maximum width as integer height - The containing rectangle maximum height as integer */ NETXUS.RectanglePacker.prototype.reset = function ( width, height ) { this.root.x = 0; this.root.y = 0; this.root.w = width; this.root.h = height; delete this.root.lft; delete this.root.rgt; this.usedWidth = 0; this.usedHeight = 0; } /* Returns the actual used dimensions of the containing rectangle. Returns: A object composed of the properties: 'w' for width and 'h' for height. */ NETXUS.RectanglePacker.prototype.getDimensions = function () { return { w: this.usedWidth, h: this.usedHeight }; } /* Finds a suitable place for the given rectangle Parameters: w - The rectangle width as integer. h - The rectangle height as integer. Returns: If there is room for the rectangle then returns the coordinates as an object composed of 'x' and 'y' properties. If it doesn't fit returns null */ NETXUS.RectanglePacker.prototype.findCoords = function ( w, h ) { // private function to traverse the node tree by recursion function recursiveFindCoords ( node, w, h ) { // private function to clone a node coords and size function cloneNode ( node ) { return { x: node.x, y: node.y, w: node.w, h: node.h }; } // if we are not at a leaf then go deeper if ( node.lft ) { // check first the left branch if not found then go by the right var coords = recursiveFindCoords( node.lft, w, h ); return coords ? coords : recursiveFindCoords( node.rgt, w, h ); } else { // if already used or it's too big then return if ( node.used || w > node.w || h > node.h ) return null; // if it fits perfectly then use this gap if ( w == node.w && h == node.h ) { node.used = true; return { x: node.x, y: node.y }; } // initialize the left and right leafs by clonning the current one node.lft = cloneNode( node ); node.rgt = cloneNode( node ); // checks if we partition in vertical or horizontal if ( node.w - w > node.h - h ) { node.lft.w = w; node.rgt.x = node.x + w; node.rgt.w = node.w - w; } else { node.lft.h = h; node.rgt.y = node.y + h; node.rgt.h = node.h - h; } return recursiveFindCoords( node.lft, w, h ); } } // perform the search var coords = recursiveFindCoords( this.root, w, h ); // if fitted then recalculate the used dimensions if (coords) { if ( this.usedWidth < coords.x + w ) this.usedWidth = coords.x + w; if ( this.usedHeight < coords.y + h ) this.usedHeight = coords.y + h; } return coords; } function UnionFind(count) { this.roots = new Array(count); this.ranks = new Array(count); for(var i=0; i>>4)+"."+(e[9]&15);k.P=A(e,12,4);k.a=A(e,16,4);k.p=A(e,20,4);k.v=a(e,24); for(var z=0;z<5;z++)k.v+="."+a(e,26+2*z);k.platform=A(e,40,4);k.d=L(e,44);k.k=A(e,48,4);k.l=L(e,52); k.Q=[L(e,56),L(e,60)];k.U=L(e,64);k.A=d(e,68);k.h=A(e,80,4);return k}function F(e,n){var A=I,L={},k=A(e,n); n+=4;for(var z=0;z>>1)}}function u(e,n,A,L){var k=I(n,A); A+=4;e.r=t(n,A,k-1);A+=k;var z=I(n,A);A+=4;var r=I(n,A);A+=4;e.e=i(n,A,r);A+=r;var s=a(n,A);A+=2;var x=n[A]; A++;e.z=t(n,A,x)}function H(e,n,A,L){var k=A-8;e.L=n[A];A++;e.u=n[A];A++;A+=2;var z=I(n,A);A+=4;var r=I(n,A); A+=4;var s=I(n,A);A+=4;var x=I(n,A);A+=4;var j=I(n,A);A+=4;if(z!=0){e.S=[];A=k+z;for(var b=0;bH?l:(116*m-16)/u,c=q>H?q:(116*w-16)/u,p=J>H?J:(116*K-16)/u,d=p*96.72,e=c*100,n=M*81.427,A=d/100,k=e/100,D=n/100,z=v.O,r=[z[0]*A+z[1]*k+z[2]*D,z[3]*A+z[4]*k+z[5]*D,z[6]*A+z[7]*k+z[8]*D]; for(var s=0;s<3;s++)r[s]=Math.max(0,Math.min(255,v.m(r[s])*255));return{g:r[0],q:r[1],N:r[2]}}};v.R=function(){var F=[],o=[]; for(var D=0;D<2e3;D++){var u=D/1e3;F[D]=v.G(u);o[D]=u>.008856?Math.pow(u,1/3):(903.3*u+16)*(1/116)}return[F,o]}(); function C(F,o){var D=o*o*o,u=D*3,H=1/(o-1),w=[];for(var q=0;q1?J.o:null; for(var d=0;d>2]|=t[r]<>2]|=i<>2]|=(192|i>>6)<>2]|=(128|63&i)<=57344?(a[e>>2]|=(224|i>>12)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<>2]|=(240|i>>18)<>2]|=(128|i>>12&63)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<=64?(this.block=a[16],this.start=e-64,this.hash(),this.hashed=!0):this.start=e}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},t.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,h=this.lastByteIndex;t[16]=this.block,t[h>>2]|=o[3&h],this.block=t[16],h>=56&&(this.hashed||this.hash(),t[0]=this.block,t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.hBytes<<3|this.bytes>>>29,t[15]=this.bytes<<3,this.hash()}},t.prototype.hash=function(){var t,h,s=this.h0,i=this.h1,e=this.h2,r=this.h3,o=this.h4,n=this.blocks;for(t=16;t<80;++t)h=n[t-3]^n[t-8]^n[t-14]^n[t-16],n[t]=h<<1|h>>>31;for(t=0;t<20;t+=5)s=(h=(i=(h=(e=(h=(r=(h=(o=(h=s<<5|s>>>27)+(i&e|~i&r)+o+1518500249+n[t]<<0)<<5|o>>>27)+(s&(i=i<<30|i>>>2)|~s&e)+r+1518500249+n[t+1]<<0)<<5|r>>>27)+(o&(s=s<<30|s>>>2)|~o&i)+e+1518500249+n[t+2]<<0)<<5|e>>>27)+(r&(o=o<<30|o>>>2)|~r&s)+i+1518500249+n[t+3]<<0)<<5|i>>>27)+(e&(r=r<<30|r>>>2)|~e&o)+s+1518500249+n[t+4]<<0,e=e<<30|e>>>2;for(;t<40;t+=5)s=(h=(i=(h=(e=(h=(r=(h=(o=(h=s<<5|s>>>27)+(i^e^r)+o+1859775393+n[t]<<0)<<5|o>>>27)+(s^(i=i<<30|i>>>2)^e)+r+1859775393+n[t+1]<<0)<<5|r>>>27)+(o^(s=s<<30|s>>>2)^i)+e+1859775393+n[t+2]<<0)<<5|e>>>27)+(r^(o=o<<30|o>>>2)^s)+i+1859775393+n[t+3]<<0)<<5|i>>>27)+(e^(r=r<<30|r>>>2)^o)+s+1859775393+n[t+4]<<0,e=e<<30|e>>>2;for(;t<60;t+=5)s=(h=(i=(h=(e=(h=(r=(h=(o=(h=s<<5|s>>>27)+(i&e|i&r|e&r)+o-1894007588+n[t]<<0)<<5|o>>>27)+(s&(i=i<<30|i>>>2)|s&e|i&e)+r-1894007588+n[t+1]<<0)<<5|r>>>27)+(o&(s=s<<30|s>>>2)|o&i|s&i)+e-1894007588+n[t+2]<<0)<<5|e>>>27)+(r&(o=o<<30|o>>>2)|r&s|o&s)+i-1894007588+n[t+3]<<0)<<5|i>>>27)+(e&(r=r<<30|r>>>2)|e&o|r&o)+s-1894007588+n[t+4]<<0,e=e<<30|e>>>2;for(;t<80;t+=5)s=(h=(i=(h=(e=(h=(r=(h=(o=(h=s<<5|s>>>27)+(i^e^r)+o-899497514+n[t]<<0)<<5|o>>>27)+(s^(i=i<<30|i>>>2)^e)+r-899497514+n[t+1]<<0)<<5|r>>>27)+(o^(s=s<<30|s>>>2)^i)+e-899497514+n[t+2]<<0)<<5|e>>>27)+(r^(o=o<<30|o>>>2)^s)+i-899497514+n[t+3]<<0)<<5|i>>>27)+(e^(r=r<<30|r>>>2)^o)+s-899497514+n[t+4]<<0,e=e<<30|e>>>2;this.h0=this.h0+s<<0,this.h1=this.h1+i<<0,this.h2=this.h2+e<<0,this.h3=this.h3+r<<0,this.h4=this.h4+o<<0},t.prototype.hex=function(){this.finalize();var t=this.h0,h=this.h1,s=this.h2,i=this.h3,e=this.h4;return r[t>>28&15]+r[t>>24&15]+r[t>>20&15]+r[t>>16&15]+r[t>>12&15]+r[t>>8&15]+r[t>>4&15]+r[15&t]+r[h>>28&15]+r[h>>24&15]+r[h>>20&15]+r[h>>16&15]+r[h>>12&15]+r[h>>8&15]+r[h>>4&15]+r[15&h]+r[s>>28&15]+r[s>>24&15]+r[s>>20&15]+r[s>>16&15]+r[s>>12&15]+r[s>>8&15]+r[s>>4&15]+r[15&s]+r[i>>28&15]+r[i>>24&15]+r[i>>20&15]+r[i>>16&15]+r[i>>12&15]+r[i>>8&15]+r[i>>4&15]+r[15&i]+r[e>>28&15]+r[e>>24&15]+r[e>>20&15]+r[e>>16&15]+r[e>>12&15]+r[e>>8&15]+r[e>>4&15]+r[15&e]},t.prototype.toString=t.prototype.hex,t.prototype.digest=function(){this.finalize();var t=this.h0,h=this.h1,s=this.h2,i=this.h3,e=this.h4;return[t>>24&255,t>>16&255,t>>8&255,255&t,h>>24&255,h>>16&255,h>>8&255,255&h,s>>24&255,s>>16&255,s>>8&255,255&s,i>>24&255,i>>16&255,i>>8&255,255&i,e>>24&255,e>>16&255,e>>8&255,255&e]},t.prototype.array=t.prototype.digest,t.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(20),h=new DataView(t);return h.setUint32(0,this.h0),h.setUint32(4,this.h1),h.setUint32(8,this.h2),h.setUint32(12,this.h3),h.setUint32(16,this.h4),t};var y=c();i?module.exports=y:(h.sha1=y,e&&define(function(){return y}))}();var EXRLoader={parse:function(e){var r={FloatType:1,UnsignedByteType:2,HalfFloatType:3,RGBEFormat:4};this.type=r.FloatType;var a=65536,n=a>>3,t=14,i=65537,o=1<>>20&2047;0===r&&(M.setFloat64(0,e*Math.pow(2,64)),r=(M.getUint32(0)>>>20&2047)-64);var a=r-1022;return[function(e,r){for(var a=Math.min(3,Math.ceil(Math.abs(r)/1023)),n=e,t=0;t>a&(1<n)return!1;I(6,u,h,e,l);var w=O.l;if(u=O.c,h=O.lc,f[t]=w,w==v){if(l.value-a.value>n)throw"Something wrong with hufUnpackEncTable";I(8,u,h,e,l);var p=O.l+c;if(u=O.c,h=O.lc,t+p>o+1)throw"Something wrong with hufUnpackEncTable";for(;p--;)f[t++]=0;t--}else if(w>=s){if(t+(p=w-s+2)>o+1)throw"Something wrong with hufUnpackEncTable";for(;p--;)f[t++]=0;t--}}!function(e){for(var r=0;r<=58;++r)E[r]=0;for(r=0;r0;--r){var n=a+E[r]>>1;E[r]=a,a=n}for(r=0;r0&&(e[r]=t|E[t]++<<6)}}(f)}function x(e){return 63&e}function P(e){return e>>6}var z={c:0,lc:0};function N(e,r,a,n){e=e<<8|te(a,n),r+=8,z.c=e,z.lc=r}var T={c:0,lc:0};function k(e,r,a,n,t,i,o,f,l,u){if(e==r){n<8&&(N(a,n,t,o),a=z.c,n=z.lc);var s=a>>(n-=8);s=new Uint8Array([s])[0];if(l.value+s>u)return!1;for(var v=f[l.value-1];s-- >0;)f[l.value++]=v}else{if(!(l.value32767?r-65536:r}var F={a:0,b:0};function B(e,r){var a=D(e),n=D(r),t=a+(1&n)+(n>>1),i=t,o=t-n;F.a=i,F.b=o}function L(e,r){var a=_(e),n=_(r),t=a-(n>>1)&u,i=n+t-l&u;F.a=i,F.b=t}function X(e,r,a,n,t,i,o){for(var f,l=o<16384,u=a>t?t:a,s=1;s<=u;)s<<=1;for(f=s>>=1,s>>=1;s>=1;){for(var v,c,h,w,p=0,y=p+i*(t-f),d=i*s,g=i*f,A=n*s,S=n*f;p<=y;p+=g){for(var U=p,b=p+n*(a-f);U<=b;U+=S){var m=U+A,M=(C=U+d)+A;l?(B(e[U+r],e[C+r]),v=F.a,h=F.b,B(e[m+r],e[M+r]),c=F.a,w=F.b,B(v,c),e[U+r]=F.a,e[m+r]=F.b,B(h,w),e[C+r]=F.a,e[M+r]=F.b):(L(e[U+r],e[C+r]),v=F.a,h=F.b,L(e[m+r],e[M+r]),c=F.a,w=F.b,L(v,c),e[U+r]=F.a,e[m+r]=F.b,L(h,w),e[C+r]=F.a,e[M+r]=F.b)}if(a&s){var C=U+d;l?B(e[U+r],e[C+r]):L(e[U+r],e[C+r]),v=F.a,e[C+r]=F.b,e[U+r]=v}}if(t&s)for(U=p,b=p+n*(a-f);U<=b;U+=S){m=U+A;l?B(e[U+r],e[m+r]):L(e[U+r],e[m+r]),v=F.a,e[m+r]=F.b,e[U+r]=v}f=s,s>>=1}return p}function V(e,r,a,n,l,u){var s=a.value,v=ne(r,a),c=ne(r,a);a.value+=4;var h=ne(r,a);if(a.value+=4,v<0||v>=i||c<0||c>=i)throw"Something wrong with HUF_ENCSIZE";var w=new Array(i),p=new Array(o);if(function(e){for(var r=0;r8*(n-(a.value-s)))throw"Something wrong with hufUncompress";!function(e,r,a,n){for(;r<=a;r++){var i=P(e[r]),o=x(e[r]);if(i>>o)throw"Invalid table entry";if(o>t){if((s=n[i>>o-t]).len)throw"Invalid table entry";if(s.lit++,s.p){var f=s.p;s.p=new Array(s.lit);for(var l=0;l0;l--){var s;if((s=n[(i<=t;)if((A=r[c>>h-t&f]).len)h-=A.len,k(A.lit,l,c,h,a,0,i,s,v,w),c=T.c,h=T.lc;else{if(!A.p)throw"hufDecode issues";var y;for(y=0;y=d&&P(e[A.p[y]])==(c>>h-d&(1<>=g,h-=g;h>0;){var A;if(!(A=r[c<i||(r[t++]=e[a++],t>i));)r[t++]=e[n++]}function W(e){for(var r=e.byteLength,a=new Array,n=0,t=new DataView(e);r>0;){var i=t.getInt8(n++);if(i<0){r-=(f=-i)+1;for(var o=0;o>8==255?t+=255&n:(a[t]=n,t++),e.value++}function Y(e,r){r[0]=le(e[0]),r[1]=le(e[1]),r[2]=le(e[5]),r[3]=le(e[6]),r[4]=le(e[14]),r[5]=le(e[15]),r[6]=le(e[27]),r[7]=le(e[28]),r[8]=le(e[2]),r[9]=le(e[4]),r[10]=le(e[7]),r[11]=le(e[13]),r[12]=le(e[16]),r[13]=le(e[26]),r[14]=le(e[29]),r[15]=le(e[42]),r[16]=le(e[3]),r[17]=le(e[8]),r[18]=le(e[12]),r[19]=le(e[17]),r[20]=le(e[25]),r[21]=le(e[30]),r[22]=le(e[41]),r[23]=le(e[43]),r[24]=le(e[9]),r[25]=le(e[11]),r[26]=le(e[18]),r[27]=le(e[24]),r[28]=le(e[31]),r[29]=le(e[40]),r[30]=le(e[44]),r[31]=le(e[53]),r[32]=le(e[10]),r[33]=le(e[19]),r[34]=le(e[23]),r[35]=le(e[32]),r[36]=le(e[39]),r[37]=le(e[45]),r[38]=le(e[52]),r[39]=le(e[54]),r[40]=le(e[20]),r[41]=le(e[22]),r[42]=le(e[33]),r[43]=le(e[38]),r[44]=le(e[46]),r[45]=le(e[51]),r[46]=le(e[55]),r[47]=le(e[60]),r[48]=le(e[21]),r[49]=le(e[34]),r[50]=le(e[37]),r[51]=le(e[47]),r[52]=le(e[50]),r[53]=le(e[56]),r[54]=le(e[59]),r[55]=le(e[61]),r[56]=le(e[35]),r[57]=le(e[36]),r[58]=le(e[48]),r[59]=le(e[49]),r[60]=le(e[57]),r[61]=le(e[58]),r[62]=le(e[62]),r[63]=le(e[63])}function j(e){for(var r=.5*Math.cos(.7853975),a=.5*Math.cos(.196349375),n=.5*Math.cos(.39269875),t=.5*Math.cos(3*3.14159/16),i=.5*Math.cos(.981746875),o=.5*Math.cos(3*3.14159/8),f=.5*Math.cos(1.374445625),l=new Array(4),u=new Array(4),s=new Array(4),v=new Array(4),c=0;c<8;++c){var h=8*c;l[0]=n*e[h+2],l[1]=o*e[h+2],l[2]=n*e[h+6],l[3]=o*e[h+6],u[0]=a*e[h+1]+t*e[h+3]+i*e[h+5]+f*e[h+7],u[1]=t*e[h+1]-f*e[h+3]-a*e[h+5]-i*e[h+7],u[2]=i*e[h+1]-a*e[h+3]+f*e[h+5]+t*e[h+7],u[3]=f*e[h+1]-i*e[h+3]+t*e[h+5]-a*e[h+7],s[0]=r*(e[h+0]+e[h+4]),s[3]=r*(e[h+0]-e[h+4]),s[1]=l[0]+l[3],s[2]=l[1]-l[2],v[0]=s[0]+s[1],v[1]=s[3]+s[2],v[2]=s[3]-s[2],v[3]=s[0]-s[1],e[h+0]=v[0]+u[0],e[h+1]=v[1]+u[1],e[h+2]=v[2]+u[2],e[h+3]=v[3]+u[3],e[h+4]=v[3]-u[3],e[h+5]=v[2]-u[2],e[h+6]=v[1]-u[1],e[h+7]=v[0]-u[0]}for(var w=0;w<8;++w)l[0]=n*e[16+w],l[1]=o*e[16+w],l[2]=n*e[48+w],l[3]=o*e[48+w],u[0]=a*e[8+w]+t*e[24+w]+i*e[40+w]+f*e[56+w],u[1]=t*e[8+w]-f*e[24+w]-a*e[40+w]-i*e[56+w],u[2]=i*e[8+w]-a*e[24+w]+f*e[40+w]+t*e[56+w],u[3]=f*e[8+w]-i*e[24+w]+t*e[40+w]-a*e[56+w],s[0]=r*(e[w]+e[32+w]),s[3]=r*(e[w]-e[32+w]),s[1]=l[0]+l[3],s[2]=l[1]-l[2],v[0]=s[0]+s[1],v[1]=s[3]+s[2],v[2]=s[3]-s[2],v[3]=s[0]-s[1],e[0+w]=v[0]+u[0],e[8+w]=v[1]+u[1],e[16+w]=v[2]+u[2],e[24+w]=v[3]+u[3],e[32+w]=v[3]-u[3],e[40+w]=v[2]-u[2],e[48+w]=v[1]-u[1],e[56+w]=v[0]-u[0]}function q(e){for(var r=0;r<64;++r){var a=e[0][r],n=e[1][r],t=e[2][r];e[0][r]=a+1.5747*t,e[1][r]=a-.1873*n-.4682*t,e[2][r]=a+1.8556*n}}function J(e,r,a){for(var n=0;n<64;++n)r[a+n]=ue(K(e[n]))}function K(e){return e<=1?Math.sign(e)*Math.pow(Math.abs(e),2.2):Math.sign(e)*Math.pow(m,Math.abs(e)-1)}function Q(e){var r=e.array.slice(e.offset.value,e.offset.value+e.size),a=new Uint8Array(pako.inflate(r).buffer),n=new Uint8Array(a.length);return Z(a),H(a,n),new DataView(n.buffer)}function $(e){var r=e.viewer,a={value:e.offset.value},n=new Uint8Array(e.width*e.lines*(we.channels.length*e.type*y)),t={version:oe(r,a),unknownUncompressedSize:oe(r,a),unknownCompressedSize:oe(r,a),acCompressedSize:oe(r,a),dcCompressedSize:oe(r,a),rleCompressedSize:oe(r,a),rleUncompressedSize:oe(r,a),rleRawSize:oe(r,a),totalAcUncompressedCount:oe(r,a),totalDcUncompressedCount:oe(r,a),acCompression:oe(r,a)};if(t.version<2)throw"EXRLoader.parse: "+we.compression+" version "+t.version+" is unsupported";for(var i=new Array,o=se(r,a)-y;o>0;){var f=ee(r.buffer,a),l=ie(r,a),u=l>>2&3,s=new Int8Array([(l>>4)-1])[0],v=ie(r,a);i.push({name:f,index:s,type:v,compression:u}),o-=f.length+3}for(var c=we.channels,h=new Array(e.channels),w=0;w=0&&(m.idx[C.index]=M),p.offset=M)}if(t.acCompressedSize>0)switch(t.acCompression){case g:var O=new Uint16Array(t.totalAcUncompressedCount);V(e.array,r,a,t.acCompressedSize,O,t.totalAcUncompressedCount);break;case A:var I=e.array.slice(a.value,a.value+t.totalAcUncompressedCount);O=new Uint16Array(pako.inflate(I).buffer);a.value+=t.totalAcUncompressedCount}if(t.dcCompressedSize>0){var E={array:e.array,offset:a,size:t.dcCompressedSize},R=new Uint16Array(Q(E).buffer);a.value+=t.dcCompressedSize}if(t.rleRawSize>0){I=e.array.slice(a.value,a.value+t.rleCompressedSize);var x=W(pako.inflate(I).buffer);a.value+=t.rleCompressedSize}var P=0,z=new Array(h.length);for(w=0;w>10,a=1023&e;return(e>>15?-1:1)*(r?31===r?a?NaN:1/0:Math.pow(2,r-15)*(1+a/1024):a/1024*6103515625e-14)}function ue(e){M.setFloat32(0,e);var r=M.getInt32(0),a=r>>16&32768,n=r>>12&2047,t=r>>23&255;return t<103?a:t>142?(a|=31744,a|=(255==t?0:1)&&8388607&r):t<113?a|=((n|=2048)>>114-t)+(n>>113-t&1):(a|=t-112<<10|n>>1,a+=1&n)}function se(e,r){var a=e.getUint16(r.value,!0);return r.value+=y,a}function ve(e,r,a,n,t){return"string"===n||"stringvector"===n||"iccProfile"===n?function(e,r,a){var n=(new TextDecoder).decode(new Uint8Array(e).slice(r.value,r.value+a));return r.value=r.value+a,n}(r,a,t):"chlist"===n?function(e,r,a,n){for(var t=a.value,i=[];a.value=n)throw"Something is wrong with PIZ_COMPRESSION BITMAP_SIZE";if(v<=c)for(s=0;s>3]&1<<(7&t))&&(r[n++]=t);for(var i=n-1;nRe?Re-ze:Se,ke.offset=pe,ke.size=xe,Ne=Ae(ke),pe.value+=xe;for(var Fe=0;Fe=Re)break;for(var Le=0;Le(We=qe>Je?qe:Je)?Ke:We)<1e-32)Ge[Oe]=Ge[Oe+1]=Ge[Oe+2]=Ge[Oe+3]=0;else{var Qe=C(We);We=256*Qe[0]/We,Ge[Oe]=qe*We,Ge[Oe+1]=Je*We,Ge[Oe+2]=Ke*We,Ge[Oe+3]=Qe[1]+128}}Pe=Ge}var $e=this.type===r.UnsignedByteType?r.RGBEFormat:r.RGBAFormat;return{header:we,width:Ee,height:Re,data:Pe,format:$e,type:this.type}}};