(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i>>0,start=arguments[1],relativeStart=start>>0,k=0>relativeStart?_Mathmax(len+relativeStart,0):_Mathmin(relativeStart,len),end=arguments[2],relativeEnd=void 0===end?len:end>>0,final=0>relativeEnd?_Mathmax(len+relativeEnd,0):_Mathmin(relativeEnd,len);kabs?c/12.92:(sign$1(c)||1)*pow$8((abs+.055)/1.055,2.4)}function lrgb2rgb(c){var abs=_Mathabs(c);return .0031308end;ascending?i++:i--)range.push(i);return range}for(var limit$2=function(x,min,max){return void 0===min&&(min=0),void 0===max&&(max=1),xmax?max:x},limit$1=limit$2,clip_rgb$3=function(rgb){rgb._clipped=!1,rgb._unclipped=rgb.slice(0);for(var i=0;3>=i;i++)3>i?((0>rgb[i]||255args.length)return null;var l=args.length-1;return"string"==type$p(args[l])?args[l].toLowerCase():null},PI:PI$2,TWOPI:2*PI$2,PITHIRD:PI$2/3,DEG2RAD:PI$2/180,RAD2DEG:180/PI$2},input$h={format:{},autodetect:[]},last$3=utils.last,clip_rgb$2=utils.clip_rgb,type$m=utils.type,_input=input$h,Color$D=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];var me=this;if("object"===type$m(args[0])&&args[0].constructor&&args[0].constructor===this.constructor)return args[0];var mode=last$3(args),autodetect=!1;if(!mode){autodetect=!0,_input.sorted||(_input.autodetect=_input.autodetect.sort(function(a,b){return b.p-a.p}),_input.sorted=!0);for(var i=0,list=_input.autodetect,chk;ik?1/(1-k):0,c=(1-r-k)*f,m=(1-g-k)*f,y=(1-b-k)*f;return[c,m,y,k]};Color$C.prototype.cmyk=function(){return rgb2cmyk(this._rgb)},chroma_1.cmyk=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];return new(Function.prototype.bind.apply(Color$C,[null].concat(args,["cmyk"])))},input$g.format.cmyk=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];args=unpack$z(args,"cmyk");var c=args[0],m=args[1],y=args[2],k=args[3],alpha=4l?(max-min)/(max+min):(max-min)/(2-max-min),r==max?h=(g-b)/(max-min):g==max?h=2+(b-r)/(max-min):b==max&&(h=4+(r-g)/(max-min)),h*=60,0>h&&(h+=360),3hsla[3]?(hsla[3]=3l?l*(1+s):l+s-l*s,t1=2*l-t2,h_=h/360;t3[0]=h_+1/3,t3[1]=h_,t3[2]=h_-1/3;for(var i=0;3>i;i++)0>t3[i]&&(t3[i]+=1),16*t3[i]?t1+6*(t2-t1)*t3[i]:1>2*t3[i]?t2:2>3*t3[i]?t1+6*((t2-t1)*(2/3-t3[i])):t1;assign=[round$5(255*c[0]),round$5(255*c[1]),round$5(255*c[2])],r=assign[0],g=assign[1],b=assign[2]}return 3i;i++)rgb[i]=+rgb[i];return rgb[3]=1,rgb}if(m=css.match(RE_RGBA)){for(var rgb$1=m.slice(1,5),i$1=0;4>i$1;i$1++)rgb$1[i$1]=+rgb$1[i$1];return rgb$1}if(m=css.match(RE_RGB_PCT)){for(var rgb$2=m.slice(1,4),i$2=0;3>i$2;i$2++)rgb$2[i$2]=round$4(2.55*rgb$2[i$2]);return rgb$2[3]=1,rgb$2}if(m=css.match(RE_RGBA_PCT)){for(var rgb$3=m.slice(1,5),i$3=0;3>i$3;i$3++)rgb$3[i$3]=round$4(2.55*rgb$3[i$3]);return rgb$3[3]=+rgb$3[3],rgb$3}if(m=css.match(RE_HSL)){var hsl=m.slice(1,4);hsl[1]*=.01,hsl[2]*=.01;var rgb$4=hsl2rgb(hsl);return rgb$4[3]=1,rgb$4}if(m=css.match(RE_HSLA)){var hsl$1=m.slice(1,4);hsl$1[1]*=.01,hsl$1[2]*=.01;var rgb$5=hsl2rgb(hsl$1);return rgb$5[3]=+m[4],rgb$5}};css2rgb$1.test=function(s){return RE_RGB.test(s)||RE_RGBA.test(s)||RE_RGB_PCT.test(s)||RE_RGBA_PCT.test(s)||RE_HSL.test(s)||RE_HSLA.test(s)};var Color$B=Color_1,input$e=input$h,type$k=utils.type,rgb2css=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];var rgba=unpack$v(args,"rgba"),mode=last$1(args)||"rgb";return"hsl"==mode.substr(0,3)?hsl2css(rgb2hsl_1(rgba),mode):(rgba[0]=round$6(rgba[0]),rgba[1]=round$6(rgba[1]),rgba[2]=round$6(rgba[2]),("rgba"===mode||3rgba[3])&&(rgba[3]=3h&&(h+=360),h/=60;var i=_Mathfloor(h),f=h-i,p=_g*(1-c),q=p+_c*(1-f),t=p+_c*f,v=p+_c;0===i?(assign=[v,t,p],r=assign[0],g=assign[1],b=assign[2]):1===i?(assign$1=[q,v,p],r=assign$1[0],g=assign$1[1],b=assign$1[2]):2===i?(assign$2=[p,v,t],r=assign$2[0],g=assign$2[1],b=assign$2[2]):3===i?(assign$3=[p,q,v],r=assign$3[0],g=assign$3[1],b=assign$3[2]):4===i?(assign$4=[t,p,v],r=assign$4[0],g=assign$4[1],b=assign$4[2]):5===i?(assign$5=[v,p,q],r=assign$5[0],g=assign$5[1],b=assign$5[2]):void 0}return[r,g,b,3h&&(h+=360)),[h,100*delta/255,100*(min/(255-delta))]};Color$z.prototype.hcg=function(){return rgb2hcg(this._rgb)},chroma_1.hcg=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];return new(Function.prototype.bind.apply(Color$z,[null].concat(args,["hcg"])))},input$c.format.hcg=hcg2rgb,input$c.autodetect.push({p:1,test:function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];if(args=unpack$q(args,"hcg"),"array"===type$j(args)&&3===args.length)return"hcg"}});var unpack$p=utils.unpack,last=utils.last,round$3=_Mathround,rgb2hex_1=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];var ref=unpack$p(args,"rgba"),r=ref[0],g=ref[1],b=ref[2],a=ref[3],mode=last(args)||"auto";void 0===a&&(a=1),"auto"===mode&&(mode=1>a?"rgba":"rgb"),r=round$3(r),g=round$3(g),b=round$3(b);var u=r<<16|g<<8|b,str="000000"+u.toString(16);str=str.substr(str.length-6);var hxa="0"+round$3(255*a).toString(16);switch(hxa=hxa.substr(hxa.length-2),mode.toLowerCase()){case"rgba":return"#"+str+hxa;case"argb":return"#"+hxa+str;default:return"#"+str;}},RE_HEX=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,RE_HEXA=/^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/,hex2rgb_1=function(hex){if(hex.match(RE_HEX)){(4===hex.length||7===hex.length)&&(hex=hex.substr(1)),3===hex.length&&(hex=hex.split(""),hex=hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]);var u=parseInt(hex,16);return[u>>16,255&u>>8,255&u,1]}if(hex.match(RE_HEXA)){(5===hex.length||9===hex.length)&&(hex=hex.substr(1)),4===hex.length&&(hex=hex.split(""),hex=hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]+hex[3]+hex[3]);var u$1=parseInt(hex,16),a=_Mathround(100*((255&u$1)/255))/100;return[255&u$1>>24,255&u$1>>16,255&u$1>>8,a]}throw new Error("unknown hex color: "+hex)},Color$y=Color_1,type$i=utils.type,input$b=input$h;Color$y.prototype.hex=function(mode){return rgb2hex_1(this._rgb,mode)},chroma_1.hex=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];return new(Function.prototype.bind.apply(Color$y,[null].concat(args,["hex"])))},input$b.format.hex=hex2rgb_1,input$b.autodetect.push({p:4,test:function(h){for(var rest=[],len=arguments.length-1;0g&&(h=TWOPI$2-h),h/=TWOPI$2),[360*h,s,i]},unpack$n=utils.unpack,limit=utils.limit,TWOPI$1=utils.TWOPI,PITHIRD=utils.PITHIRD,cos$4=_Mathcos,hsi2rgb=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];args=unpack$n(args,"hsi");var h=args[0],s=args[1],i=args[2],r,g,b;return isNaN(h)&&(h=0),isNaN(s)&&(s=0),360h&&(h+=360),h/=360,h<1/3?(b=(1-s)/3,r=(1+s*cos$4(TWOPI$1*h)/cos$4(PITHIRD-TWOPI$1*h))/3,g=1-(b+r)):h<2/3?(h-=1/3,r=(1-s)/3,g=(1+s*cos$4(TWOPI$1*h)/cos$4(PITHIRD-TWOPI$1*h))/3,b=1-(r+g)):(h-=2/3,g=(1-s)/3,b=(1+s*cos$4(TWOPI$1*h)/cos$4(PITHIRD-TWOPI$1*h))/3,r=1-(g+b)),r=limit(3*(i*r)),g=limit(3*(i*g)),b=limit(3*(i*b)),[255*r,255*g,255*b,3h&&(h+=360),h/=60;var i=_Mathfloor(h),f=h-i,p=v*(1-s),q=v*(1-s*f),t=v*(1-s*(1-f));0===i?(assign=[v,t,p],r=assign[0],g=assign[1],b=assign[2]):1===i?(assign$1=[q,v,p],r=assign$1[0],g=assign$1[1],b=assign$1[2]):2===i?(assign$2=[p,v,t],r=assign$2[0],g=assign$2[1],b=assign$2[2]):3===i?(assign$3=[p,q,v],r=assign$3[0],g=assign$3[1],b=assign$3[2]):4===i?(assign$4=[t,p,v],r=assign$4[0],g=assign$4[1],b=assign$4[2]):5===i?(assign$5=[v,p,q],r=assign$5[0],g=assign$5[1],b=assign$5[2]):void 0}return[r,g,b,3h&&(h+=360)),[h,s,v]};Color$v.prototype.hsv=function(){return rgb2hsv(this._rgb)},chroma_1.hsv=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];return new(Function.prototype.bind.apply(Color$v,[null].concat(args,["hsv"])))},input$8.format.hsv=hsv2rgb,input$8.autodetect.push({p:2,test:function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];if(args=unpack$i(args,"hsv"),"array"===type$f(args)&&3===args.length)return"hsv"}});var labConstants={Kn:18,Xn:.95047,Yn:1,Zn:1.08883,t0:.137931034,t1:.206896552,t2:.12841855,t3:.008856452},LAB_CONSTANTS$3=labConstants,unpack$h=utils.unpack,pow$a=_Mathpow,rgb_xyz=function(r){return .04045>=(r/=255)?r/12.92:pow$a((r+.055)/1.055,2.4)},xyz_lab=function(t){return t>LAB_CONSTANTS$3.t3?pow$a(t,1/3):t/LAB_CONSTANTS$3.t2+LAB_CONSTANTS$3.t0},rgb2xyz=function(r,g,b){r=rgb_xyz(r),g=rgb_xyz(g),b=rgb_xyz(b);var x=xyz_lab((.4124564*r+.3575761*g+.1804375*b)/LAB_CONSTANTS$3.Xn),y=xyz_lab((.2126729*r+.7151522*g+.072175*b)/LAB_CONSTANTS$3.Yn),z=xyz_lab((.0193339*r+.119192*g+.9503041*b)/LAB_CONSTANTS$3.Zn);return[x,y,z]},rgb2lab_1=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];var ref=unpack$h(args,"rgb"),r=ref[0],g=ref[1],b=ref[2],ref$1=rgb2xyz(r,g,b),x=ref$1[0],y=ref$1[1],z=ref$1[2],l=116*y-16;return[0>l?0:l,500*(x-y),200*(y-z)]},LAB_CONSTANTS$2=labConstants,unpack$g=utils.unpack,xyz_rgb=function(r){return 255*(.00304>=r?12.92*r:1.055*_Mathpow(r,1/2.4)-.055)},lab_xyz=function(t){return t>LAB_CONSTANTS$2.t1?t*t*t:LAB_CONSTANTS$2.t2*(t-LAB_CONSTANTS$2.t0)},lab2rgb_1=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];args=unpack$g(args,"lab");var l=args[0],a=args[1],b=args[2],x,y,z,r,g,b_;return y=(l+16)/116,x=isNaN(a)?y:y+a/500,z=isNaN(b)?y:y-b/200,y=LAB_CONSTANTS$2.Yn*lab_xyz(y),x=LAB_CONSTANTS$2.Xn*lab_xyz(x),z=LAB_CONSTANTS$2.Zn*lab_xyz(z),r=xyz_rgb(3.2404542*x-1.5371385*y-.4985314*z),g=xyz_rgb(-.969266*x+1.8760108*y+.041556*z),b_=xyz_rgb(.0556434*x-.2040259*y+1.0572252*z),[r,g,b_,3=num){return[num>>16,255&num>>8,255&num,1]}throw new Error("unknown num color: "+num)},input$4.autodetect.push({p:5,test:function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];if(1===args.length&&"number"===type$a(args[0])&&0<=args[0]&&16777215>=args[0])return"num"}});var Color$q=Color_1,input$3=input$h,unpack$7=utils.unpack,type$9=utils.type,round$1=_Mathround;Color$q.prototype.rgb=function(rnd){return void 0===rnd&&(rnd=!0),!1===rnd?this._rgb.slice(0,3):this._rgb.slice(0,3).map(round$1)},Color$q.prototype.rgba=function(rnd){return void 0===rnd&&(rnd=!0),this._rgb.slice(0,4).map(function(v,i){return 3>i?!1===rnd?v:round$1(v):v})},chroma_1.rgb=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];return new(Function.prototype.bind.apply(Color$q,[null].concat(args,["rgb"])))},input$3.format.rgb=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];var rgba=unpack$7(args,"rgba");return void 0===rgba[3]&&(rgba[3]=1),rgba},input$3.autodetect.push({p:3,test:function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];if(args=unpack$7(args,"rgba"),"array"===type$9(args)&&(3===args.length||4===args.length&&"number"==type$9(args[3])&&0<=args[3]&&1>=args[3]))return"rgb"}});var log$1=_Mathlog,temperature2rgb_1=function(kelvin){var temp=kelvin/100,r,g,b;return 66>temp?(r=255,g=6>temp?0:-155.25485562709179-.44596950469579133*(g=temp-2)+104.49216199393888*log$1(g),b=20>temp?0:-254.76935184120902+.8274096064007395*(b=temp-10)+115.67994401066147*log$1(b)):(r=351.97690566805693+.114206453784165*(r=temp-55)-40.25366309332127*log$1(r),g=325.4494125711974+.07943456536662342*(g=temp-50)-28.0852963507957*log$1(g),b=255),[r,g,b,1]},unpack$6=utils.unpack,chroma$7=chroma_1,Color$p=Color_1,input$2=input$h,rgb2temperature=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];for(var rgb=unpack$6(args,"rgb"),r=rgb[0],b=rgb[2],minTemp=1e3,maxTemp=4e4,temp;maxTemp-minTemp>.4;){temp=.5*(maxTemp+minTemp);var rgb$1=temperature2rgb_1(temp);rgb$1[2]/rgb$1[0]>=b/r?maxTemp=temp:minTemp=temp}return _Mathround(temp)};Color$p.prototype.temp=Color$p.prototype.kelvin=Color$p.prototype.temperature=function(){return rgb2temperature(this._rgb)},chroma$7.temp=chroma$7.kelvin=chroma$7.temperature=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];return new(Function.prototype.bind.apply(Color$p,[null].concat(args,["temp"])))},input$2.format.temp=input$2.format.kelvin=input$2.format.temperature=temperature2rgb_1;var unpack$5=utils.unpack,cbrt=Math.cbrt,pow$8=_Mathpow,sign$1=_Mathsign,rgb2oklab_1=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];var ref=unpack$5(args,"rgb"),r=ref[0],g=ref[1],b=ref[2],ref$1=[rgb2lrgb(r/255),rgb2lrgb(g/255),rgb2lrgb(b/255)],lr=ref$1[0],lg=ref$1[1],lb=ref$1[2],l=cbrt(.4122214708*lr+.5363325363*lg+.0514459929*lb),m=cbrt(.2119034982*lr+.6806995451*lg+.1073969566*lb),s=cbrt(.0883024619*lr+.2817188376*lg+.6299787005*lb);return[.2104542553*l+.793617785*m-.0040720468*s,1.9779984951*l-2.428592205*m+.4505937099*s,.0259040371*l+.7827717662*m-.808675766*s]},unpack$4=utils.unpack,pow$7=_Mathpow,sign=_Mathsign,oklab2rgb_1=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];args=unpack$4(args,"lab");var L=args[0],a=args[1],b=args[2],l=pow$7(L+.3963377774*a+.2158037573*b,3),m=pow$7(L-.1055613458*a-.0638541728*b,3),s=pow$7(L-.0894841775*a-1.291485548*b,3);return[255*lrgb2rgb(+4.0767416621*l-3.3077115913*m+.2309699292*s),255*lrgb2rgb(-1.2684380046*l+2.6097574011*m-.3413193965*s),255*lrgb2rgb(-.0041960863*l-.7034186147*m+1.707614701*s),3lum?test(low,mid):test(mid,high)},rgb=(cur_lum>lum?test(new Color$i([0,0,0]),this):test(this,new Color$i([255,255,255]))).rgb();return new Color$i(rgb.concat([this._rgb[3]]))}return rgb2luminance.apply(void 0,this._rgb.slice(0,3))};var rgb2luminance=function(r,g,b){return r=luminance_x(r),g=luminance_x(g),b=luminance_x(b),.2126*r+.7152*g+.0722*b},luminance_x=function(x){return x/=255,.03928>=x?x/12.92:_Mathpow((x+.055)/1.055,2.4)},interpolator$1={},Color$h=Color_1,type$4=utils.type,interpolator=interpolator$1,mix$1=function(col1,col2,f){void 0===f&&(f=.5);for(var rest=[],len=arguments.length-3;0lch[1]&&(lch[1]=0),new Color$e(lch,"lch").alpha(me.alpha(),!0)},Color$e.prototype.desaturate=function(amount){return void 0===amount&&(amount=1),this.saturate(-amount)};var Color$d=Color_1,type$3=utils.type;Color$d.prototype.set=function(mc,value,mutate){void 0===mutate&&(mutate=!1);var ref=mc.split("."),mode=ref[0],channel=ref[1],src=this[mode]();if(channel){var i=mode.indexOf(channel)-("ok"===mode.substr(0,2)?2:0);if(-1hue0&&180A$1;)A$1+=360;for(;360<=A$1;)A$1-=360;xyz[i$1]=A$1}else xyz[i$1]/=cnt[i$1];return alpha/=l,new Color$6(xyz,mode).alpha(.99999=_classes[i];)i++;return i-1}return 0},tMapLightness=function(t){return t},tMapDomain=function(t){return t},getColor=function(val,bypassMap){var col,t;if(null==bypassMap&&(bypassMap=!1),isNaN(val)||null===val)return _nacol;if(!!bypassMap)t=val;else if(_classes&&2<_classes.length){var c=getClass(val);t=c/(_classes.length-2)}else t=_max===_min?1:(val-_min)/(_max-_min);t=tMapDomain(t),bypassMap||(t=tMapLightness(t)),1!==_gamma&&(t=_Mathpow(t,_gamma)),t=_padding[0]+t*(1-_padding[0]-_padding[1]),t=_Mathmin2(1,_Mathmax2(0,t));var k=_Mathfloor(1e4*t);if(_useCache&&_colorCache[k])col=_colorCache[k];else{if("array"===type$2(_colors))for(var i=0,p;i<_pos.length;i++){if(p=_pos[i],t<=p){col=_colors[i];break}if(t>=p&&i===_pos.length-1){col=_colors[i];break}if(t>p&&t<_pos[i+1]){t=(t-p)/(_pos[i+1]-p),col=chroma$4.interpolate(_colors[i],_colors[i+1],t,_mode);break}}else"function"===type$2(_colors)&&(col=_colors(t));_useCache&&(_colorCache[k]=col)}return col},resetCache=function(){return _colorCache={}};setColors(colors);var f=function(v){var c=chroma$4(getColor(v));return _out&&c[_out]?c[_out]():c};return f.classes=function(classes){if(null!=classes){if("array"===type$2(classes))_classes=classes,_domain=[classes[0],classes[classes.length-1]];else{var d=chroma$4.analyze(_domain);_classes=0===classes?[d.min,d.max]:chroma$4.limits(d,"e",classes)}return f}return _classes},f.domain=function(domain){if(!arguments.length)return _domain;_min=domain[0],_max=domain[domain.length-1],_pos=[];var k=_colors.length;if(domain.length===k&&_min!==_max)for(var i=0,list=Array.from(domain),d;i=t||1<=t)return t;for(var i=0;t>=tBreaks[i+1];)i++;var f=(t-tBreaks[i])/(tBreaks[i+1]-tBreaks[i]),out=tOut[i]+f*(tOut[i+1]-tOut[i]);return out})}}return _domain=[_min,_max],f},f.mode=function(_m){return arguments.length?(_mode=_m,resetCache(),f):_mode},f.range=function(colors){return setColors(colors),f},f.out=function(_o){return _out=_o,f},f.spread=function(val){return arguments.length?(_spread=val,f):_spread},f.correctLightness=function(v){return null==v&&(v=!0),_correctLightness=v,resetCache(),tMapLightness=_correctLightness?function(t){for(var L0=getColor(0,!0).lab()[0],L1=getColor(1,!0).lab()[0],L_actual=getColor(t,!0).lab()[0],L_ideal=L0+(L1-L0)*t,L_diff=L_actual-L_ideal,t0=0,t1=1,max_iter=20;.01<_Mathabs(L_diff)&&0L1&&(L_diff*=-1),0>L_diff?(t0=t,t+=.5*(t1-t)):(t1=t,t+=.5*(t0-t)),L_actual=getColor(t,!0).lab()[0],L_diff=L_actual-L_ideal})();return t}:function(t){return t},f},f.padding=function(p){return null==p?_padding:("number"===type$2(p)&&(p=[p,p]),_padding=p,f)},f.colors=function(numColors,out){2>arguments.length&&(out="hex");var result=[];if(0===arguments.length)result=_colors.slice(0);else if(1===numColors)result=[f(.5)];else if(1end;asc?i++:i--)samples.push(.5*(_classes[i-1]+_classes[i]));else samples=_domain;result=samples.map(function(v){return f(v)})}return chroma$4[out]&&(result=result.map(function(c){return c[out]()})),result},f.cache=function(c){return null==c?_useCache:(_useCache=c,f)},f.gamma=function(g){return null==g?_gamma:(_gamma=g,f)},f.nodata=function(d){return null==d?_nacol:(_nacol=chroma$4(d),f)},f},Color$5=Color_1,binom_row=function(n){for(var row=[1,1],i=1,newrow;ib?2*a*b/255:255*(1-2*(1-a/255)*(1-b/255))})),blend.darken=blend_f(each(function(a,b){return a>b?b:a})),blend.lighten=blend_f(each(function(a,b){return a>b?a:b})),blend.dodge=blend_f(each(function(a,b){return 255===a?255:(a=255*(b/255)/(1-a/255),255i;i++)code+="0123456789abcdef".charAt(_Mathfloor(16*random()));return new Color_1(code,"hex")},type=type$p,log=_Mathlog,analyze=function(data,key){void 0===key&&(key=null);var r={min:_NumberMAX_VALUE,max:-1*_NumberMAX_VALUE,sum:0,values:[],count:0};return"object"===type(data)&&(data=Object.values(data)),data.forEach(function(val){key&&"object"===type(val)&&(val=val[key]),void 0===val||null===val||isNaN(val)||(r.values.push(val),r.sum+=val,valr.max&&(r.max=val),r.count+=1)}),r.domain=[r.min,r.max],r.limits=function(mode,num){return limits(r,mode,num)},r},limits=function(data,mode,num){var _MathLOG10E=Math.LOG10E;void 0===mode&&(mode="equal"),void 0===num&&(num=7),"array"==type(data)&&(data=analyze(data));var min=data.min,max=data.max,values=data.values.sort(function(a,b){return a-b});if(1===num)return[min,max];var limits=[];if("c"===mode.substr(0,1)&&(limits.push(min),limits.push(max)),"e"===mode.substr(0,1)){limits.push(min);for(var i=1;i=min)throw new Error("Logarithmic scales are only possible for values > 0");var min_log=_MathLOG10E*log(min),max_log=_MathLOG10E*log(max);limits.push(min);for(var i$1=1;i$1l2?(l1+.05)/(l2+.05):(l2+.05)/(l1+.05)},Color$2=Color_1,sqrt=_Mathsqrt,pow=_Mathpow,atan2=_Mathatan,abs=_Mathabs,cos=_Mathcos,sin=_Mathsin,exp=Math.exp,PI=_MathPI,deltaE=function(a,b,Kl,Kc,Kh){void 0===Kl&&(Kl=1),void 0===Kc&&(Kc=1),void 0===Kh&&(Kh=1);var rad2deg=function(rad){return 360*rad/(2*PI)},deg2rad=function(deg){return 2*PI*deg/360};a=new Color$2(a),b=new Color$2(b);var ref=Array.from(a.lab()),L1=ref[0],a1=ref[1],b1=ref[2],ref$1=Array.from(b.lab()),L2=ref$1[0],a2=ref$1[1],b2=ref$1[2],avgL=(L1+L2)/2,C1=sqrt(pow(a1,2)+pow(b1,2)),C2=sqrt(pow(a2,2)+pow(b2,2)),avgC=(C1+C2)/2,G=.5*(1-sqrt(pow(avgC,7)/(pow(avgC,7)+pow(25,7)))),a1p=a1*(1+G),a2p=a2*(1+G),C1p=sqrt(pow(a1p,2)+pow(b1,2)),C2p=sqrt(pow(a2p,2)+pow(b2,2)),avgCp=(C1p+C2p)/2,arctan1=rad2deg(atan2(b1,a1p)),arctan2=rad2deg(atan2(b2,a2p)),h1p=0<=arctan1?arctan1:arctan1+360,h2p=0<=arctan2?arctan2:arctan2+360,avgHp=180=abs(deltaHp)?deltaHp:h2p<=h1p?deltaHp+360:deltaHp-360,deltaHp=2*sqrt(C1p*C2p)*sin(deg2rad(deltaHp)/2);var deltaCp=C2p-C1p,sl=1+.015*pow(avgL-50,2)/sqrt(20+pow(avgL-50,2)),sc=1+.045*avgCp,sh=1+.015*avgCp*T,deltaTheta=30*exp(-pow((avgHp-275)/25,2)),Rc=2*sqrt(pow(avgCp,7)/(pow(avgCp,7)+pow(25,7))),Rt=-Rc*sin(2*deg2rad(deltaTheta)),result=sqrt(pow((L2-L1)/(Kl*sl),2)+pow(deltaCp/(Kc*sc),2)+pow(deltaHp/(Kh*sh),2)+Rt*(deltaCp/(Kc*sc))*(deltaHp/(Kh*sh)));return _Mathmax2(0,_Mathmin2(100,result))},Color$1=Color_1,distance=function(a,b,mode){void 0===mode&&(mode="lab"),a=new Color$1(a),b=new Color$1(b);var l1=a.get(mode),l2=b.get(mode),sum_sq=0;for(var i in l1){var d=(l1[i]||0)-(l2[i]||0);sum_sq+=d*d}return _Mathsqrt(sum_sq)},valid=function(){for(var args=[],len=arguments.length;len--;)args[len]=arguments[len];try{return new(Function.prototype.bind.apply(Color_1,[null].concat(args))),!0}catch(e){return!1}},chroma$1=chroma_1,scale=scale$2,scales={cool:function(){return scale([chroma$1.hsl(180,1,.9),chroma$1.hsl(250,.7,.4)])},hot:function(){return scale(["#000","#f00","#ff0","#fff"]).mode("rgb")}},colorbrewer={OrRd:["#fff7ec","#fee8c8","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#b30000","#7f0000"],PuBu:["#fff7fb","#ece7f2","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#045a8d","#023858"],BuPu:["#f7fcfd","#e0ecf4","#bfd3e6","#9ebcda","#8c96c6","#8c6bb1","#88419d","#810f7c","#4d004b"],Oranges:["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"],BuGn:["#f7fcfd","#e5f5f9","#ccece6","#99d8c9","#66c2a4","#41ae76","#238b45","#006d2c","#00441b"],YlOrBr:["#ffffe5","#fff7bc","#fee391","#fec44f","#fe9929","#ec7014","#cc4c02","#993404","#662506"],YlGn:["#ffffe5","#f7fcb9","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#006837","#004529"],Reds:["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"],RdPu:["#fff7f3","#fde0dd","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177","#49006a"],Greens:["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"],YlGnBu:["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"],Purples:["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"],GnBu:["#f7fcf0","#e0f3db","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#0868ac","#084081"],Greys:["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"],YlOrRd:["#ffffcc","#ffeda0","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#bd0026","#800026"],PuRd:["#f7f4f9","#e7e1ef","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#980043","#67001f"],Blues:["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"],PuBuGn:["#fff7fb","#ece2f0","#d0d1e6","#a6bddb","#67a9cf","#3690c0","#02818a","#016c59","#014636"],Viridis:["#440154","#482777","#3f4a8a","#31678e","#26838f","#1f9d8a","#6cce5a","#b6de2b","#fee825"],Spectral:["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"],RdYlGn:["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"],RdBu:["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"],PiYG:["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"],PRGn:["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"],RdYlBu:["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"],BrBG:["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"],RdGy:["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#ffffff","#e0e0e0","#bababa","#878787","#4d4d4d","#1a1a1a"],PuOr:["#7f3b08","#b35806","#e08214","#fdb863","#fee0b6","#f7f7f7","#d8daeb","#b2abd2","#8073ac","#542788","#2d004b"],Set2:["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","#e5c494","#b3b3b3"],Accent:["#7fc97f","#beaed4","#fdc086","#ffff99","#386cb0","#f0027f","#bf5b17","#666666"],Set1:["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],Set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],Dark2:["#1b9e77","#d95f02","#7570b3","#e7298a","#66a61e","#e6ab02","#a6761d","#666666"],Paired:["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6","#6a3d9a","#ffff99","#b15928"],Pastel2:["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4","#e6f5c9","#fff2ae","#f1e2cc","#cccccc"],Pastel1:["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc","#e5d8bd","#fddaec","#f2f2f2"]},i=0,list=Object.keys(colorbrewer),key;ip.x&&(minX=p.x),minY>p.y&&(minY=p.y)}var padding=this.opts.padding;maxX+=padding,maxY+=padding,minX-=padding,minY-=padding,this.drawingWidth=maxX-minX,this.drawingHeight=maxY-minY;var scaleX=this.canvas.offsetWidth/this.drawingWidth,scaleY=this.canvas.offsetHeight/this.drawingHeight,scale=scaleXalpha&&(ctx.globalAlpha=alpha),ctx.strokeStyle=gradient,ctx.stroke(),ctx.restore()}drawWedge(line,width=1){if(isNaN(line.from.x)||isNaN(line.from.y)||isNaN(line.to.x)||isNaN(line.to.y))return;let ctx=this.ctx,offsetX=this.offsetX,offsetY=this.offsetY,shortLine=line.clone().shorten(5),l=shortLine.getLeftVector().clone(),r=shortLine.getRightVector().clone();l.x+=offsetX,l.y+=offsetY,r.x+=offsetX,r.y+=offsetY,l=line.getLeftVector().clone(),r=line.getRightVector().clone(),l.x+=offsetX,l.y+=offsetY,r.x+=offsetX,r.y+=offsetY,ctx.save();let normals=Vector2.normals(l,r);normals[0].normalize(),normals[1].normalize();let isRightChiralCenter=line.getRightChiral(),start=l,end=r;isRightChiralCenter&&(start=r,end=l);let t=Vector2.add(start,Vector2.multiplyScalar(normals[0],this.halfBondThickness)),u=Vector2.add(end,Vector2.multiplyScalar(normals[0],1.5+this.halfBondThickness)),v=Vector2.add(end,Vector2.multiplyScalar(normals[1],1.5+this.halfBondThickness)),w=Vector2.add(start,Vector2.multiplyScalar(normals[1],this.halfBondThickness));ctx.beginPath(),ctx.moveTo(t.x,t.y),ctx.lineTo(u.x,u.y),ctx.lineTo(v.x,v.y),ctx.lineTo(w.x,w.y);let gradient=this.ctx.createRadialGradient(r.x,r.y,this.opts.bondLength,r.x,r.y,0);gradient.addColorStop(.4,this.themeManager.getColor(line.getLeftElement())||this.themeManager.getColor("C")),gradient.addColorStop(.6,this.themeManager.getColor(line.getRightElement())||this.themeManager.getColor("C")),ctx.fillStyle=gradient,ctx.fill(),ctx.restore()}drawDashedWedge(line){if(isNaN(line.from.x)||isNaN(line.from.y)||isNaN(line.to.x)||isNaN(line.to.y))return;let ctx=this.ctx,offsetX=this.offsetX,offsetY=this.offsetY,l=line.getLeftVector().clone(),r=line.getRightVector().clone();l.x+=offsetX,l.y+=offsetY,r.x+=offsetX,r.y+=offsetY,ctx.save();let normals=Vector2.normals(l,r);normals[0].normalize(),normals[1].normalize();let isRightChiralCenter=line.getRightChiral(),shortLine=line.clone(),start,end,sStart,sEnd;isRightChiralCenter?(start=r,end=l,shortLine.shortenRight(1),sStart=shortLine.getRightVector().clone(),sEnd=shortLine.getLeftVector().clone()):(start=l,end=r,shortLine.shortenLeft(1),sStart=shortLine.getLeftVector().clone(),sEnd=shortLine.getRightVector().clone()),sStart.x+=offsetX,sStart.y+=offsetY,sEnd.x+=offsetX,sEnd.y+=offsetY;let dir=Vector2.subtract(end,start).normalize();ctx.strokeStyle=this.themeManager.getColor("C"),ctx.lineCap="round",ctx.lineWidth=this.opts.bondThickness,ctx.beginPath();let length=line.getLength(),step=1.25/(length/(3*this.opts.bondThickness)),changed=!1;for(var t=0;1>t;t+=step){let to=Vector2.multiplyScalar(dir,t*length),startDash=Vector2.add(start,to),width=1.5*t,dashOffset=Vector2.multiplyScalar(normals[0],width);!changed&&.5this.opts.fontSizeLarge?dim.width:this.opts.fontSizeLarge;r/=1.5,ctx.globalCompositeOperation="destination-out",ctx.beginPath(),ctx.arc(x+offsetX,y+offsetY,r,0,MathHelper.twoPI,!0),ctx.closePath(),ctx.fill(),ctx.globalCompositeOperation="source-over";let cursorPos=-dim.width/2,cursorPosLeft=-dim.width/2;ctx.fillStyle=this.themeManager.getColor(elementName),ctx.fillText(elementName,x+offsetX+cursorPos,y+this.opts.halfFontSizeLarge+offsetY),cursorPos+=dim.width,charge&&(ctx.font=this.fontSmall,ctx.fillText(chargeText,x+offsetX+cursorPos,y-this.opts.fifthFontSizeSmall+offsetY),cursorPos+=chargeWidth),0maxDist&&(maxDist=dist,a=i,b=j)}}let angle=-Vector2.subtract(this.graph.vertices[a].position,this.graph.vertices[b].position).angle();if(!isNaN(angle)){let remainder=angle%.523599;.2617995>remainder?angle-=remainder:angle+=.523599-remainder;for(var i=0;i{if(counts.has(e)){let count=counts.get(e);molecularFormula+=e+(1vertexA.value.getRingbondCount()||1>vertexB.value.getRingbondCount())return null;for(var i=0;isubTreeDepthB&&(a=edge.sourceId,b=edge.targetId);let subTreeOverlap=this.getSubtreeOverlapScore(b,a,overlapScore.vertexScores);if(subTreeOverlap.value>this.opts.overlapSensitivity){let vertexA=this.graph.vertices[a],vertexB=this.graph.vertices[b],neighboursB=vertexB.getNeighbours(a);if(1===neighboursB.length){let neighbour=this.graph.vertices[neighboursB[0]],angle=neighbour.position.getRotateAwayFromAngle(vertexA.position,vertexB.position,MathHelper.toRad(120));this.rotateSubtree(neighbour.id,vertexB.id,angle,vertexB.position);let newTotalOverlapScore=this.getOverlapScore().total;newTotalOverlapScore>this.totalOverlapScore?this.rotateSubtree(neighbour.id,vertexB.id,-angle,vertexB.position):this.totalOverlapScore=newTotalOverlapScore}else if(2===neighboursB.length){if(0!==vertexB.value.rings.length&&0!==vertexA.value.rings.length)continue;let neighbourA=this.graph.vertices[neighboursB[0]],neighbourB=this.graph.vertices[neighboursB[1]];if(1===neighbourA.value.rings.length&&1===neighbourB.value.rings.length){if(neighbourA.value.rings[0]!==neighbourB.value.rings[0])continue;}else if(0!==neighbourA.value.rings.length||0!==neighbourB.value.rings.length)continue;else{let angleA=neighbourA.position.getRotateAwayFromAngle(vertexA.position,vertexB.position,MathHelper.toRad(120)),angleB=neighbourB.position.getRotateAwayFromAngle(vertexA.position,vertexB.position,MathHelper.toRad(120));this.rotateSubtree(neighbourA.id,vertexB.id,angleA,vertexB.position),this.rotateSubtree(neighbourB.id,vertexB.id,angleB,vertexB.position);let newTotalOverlapScore=this.getOverlapScore().total;newTotalOverlapScore>this.totalOverlapScore?(this.rotateSubtree(neighbourA.id,vertexB.id,-angleA,vertexB.position),this.rotateSubtree(neighbourB.id,vertexB.id,-angleB,vertexB.position)):this.totalOverlapScore=newTotalOverlapScore}}overlapScore=this.getOverlapScore()}}}this.resolveSecondaryOverlaps(overlapScore.scores),this.opts.isomeric&&this.annotateStereochemistry(),this.opts.compactDrawing&&"default"===this.opts.atomVisualization&&this.initPseudoElements(),this.rotateDrawing()}initRings(){let openBonds=new Map;for(var i=this.graph.vertices.length-1;0<=i;i--){let vertex=this.graph.vertices[i];if(0!==vertex.value.ringbonds.length)for(var j=0;jneighbour.value.rings.length&&!neighbour.value.bridgedRing||neighbour.value.bridgedRing&&2>neighbour.value.originalRings.length)&&(vertex.value.isDrawn=!1)}}getBridgedRingRings(ringId){let involvedRings=[],that=this,recurse=function(r){let ring=that.getRing(r);involvedRings.push(r);for(var i=0;imaxSize&&(maxSize=size,largestCommonRing=ring)}return largestCommonRing}getVerticesAt(position,radius,excludeVertexId){let locals=[];for(var i=0;ii;){let a=this.graph.vertices[i],b=this.graph.vertices[j];if(!a.value.isDrawn||!b.value.isDrawn)continue;let dist=Vector2.subtract(a.position,b.position).lengthSq();if(disttotalSideCount[1]?0:1,sideCount:sideCount,position:sideCount[0]>sideCount[1]?0:1,anCount:anCount,bnCount:bnCount}}setRingCenter(ring){let ringSize=ring.getSize(),total=new Vector2(0,0);for(var i=0;is.sideCount[1]){normals[0].multiplyScalar(that.opts.bondSpacing),normals[1].multiplyScalar(that.opts.bondSpacing);let line=new Line(Vector2.add(a,normals[0]),Vector2.add(b,normals[0]),elementA,elementB);line.shorten(this.opts.bondLength-this.opts.shortBondLength*this.opts.bondLength),this.canvasWrapper.drawLine(line),this.canvasWrapper.drawLine(new Line(a,b,elementA,elementB))}else if(s.sideCount[0]s.totalSideCount[1]){normals[0].multiplyScalar(that.opts.bondSpacing),normals[1].multiplyScalar(that.opts.bondSpacing);let line=new Line(Vector2.add(a,normals[0]),Vector2.add(b,normals[0]),elementA,elementB);line.shorten(this.opts.bondLength-this.opts.shortBondLength*this.opts.bondLength),this.canvasWrapper.drawLine(line),this.canvasWrapper.drawLine(new Line(a,b,elementA,elementB))}else if(s.totalSideCount[0]<=s.totalSideCount[1]){normals[0].multiplyScalar(that.opts.bondSpacing),normals[1].multiplyScalar(that.opts.bondSpacing);let line=new Line(Vector2.add(a,normals[1]),Vector2.add(b,normals[1]),elementA,elementB);line.shorten(this.opts.bondLength-this.opts.shortBondLength*this.opts.bondLength),this.canvasWrapper.drawLine(line),this.canvasWrapper.drawLine(new Line(a,b,elementA,elementB))}else;}else if("#"===edge.bondType){normals[0].multiplyScalar(that.opts.bondSpacing/1.5),normals[1].multiplyScalar(that.opts.bondSpacing/1.5);let lineA=new Line(Vector2.add(a,normals[0]),Vector2.add(b,normals[0]),elementA,elementB),lineB=new Line(Vector2.add(a,normals[1]),Vector2.add(b,normals[1]),elementA,elementB);this.canvasWrapper.drawLine(lineA),this.canvasWrapper.drawLine(lineB),this.canvasWrapper.drawLine(new Line(a,b,elementA,elementB))}else if("."===edge.bondType);else{let isChiralCenterA=vertexA.value.isStereoCenter,isChiralCenterB=vertexB.value.isStereoCenter;"up"===edge.wedge?this.canvasWrapper.drawWedge(new Line(a,b,elementA,elementB,isChiralCenterA,isChiralCenterB)):"down"===edge.wedge?this.canvasWrapper.drawDashedWedge(new Line(a,b,elementA,elementB,isChiralCenterA,isChiralCenterB)):this.canvasWrapper.drawLine(new Line(a,b,elementA,elementB,isChiralCenterA,isChiralCenterB))}if(debug){let midpoint=Vector2.midpoint(a,b);this.canvasWrapper.drawDebugText(midpoint.x,midpoint.y,"e: "+edgeId)}}drawVertices(debug){for(var i=this.graph.vertices.length,i=0;i_Mathabs2(_MathPI2-angle)&&this.canvasWrapper.drawPoint(vertex.position.x,vertex.position.y,element)}if(debug){let value="v: "+vertex.id+" "+ArrayHelper.print(atom.ringbonds);this.canvasWrapper.drawDebugText(vertex.position.x,vertex.position.y,value)}else;}if(this.opts.debug)for(var i=0;iring.rings.length)&&(vertex.angle=a,vertex.positioned=!0)},startVertexId,previousVertex?previousVertex.id:null);ring.positioned=!0,ring.center=center;for(var i=0;iVector2.subtract(center,normals[0]).lengthSq()&&(nextCenter=normals[1]);let posA=Vector2.subtract(vertexA.position,nextCenter),posB=Vector2.subtract(vertexB.position,nextCenter);-1===posA.clockwise(posB)?!neighbour.positioned&&this.createRing(neighbour,nextCenter,vertexA,vertexB):!neighbour.positioned&&this.createRing(neighbour,nextCenter,vertexB,vertexA)}else if(1===vertices.length){ring.isSpiro=!0,neighbour.isSpiro=!0;let vertexA=this.graph.vertices[vertices[0]],nextCenter=Vector2.subtract(center,vertexA.position);nextCenter.invert(),nextCenter.normalize();let r=MathHelper.polyCircumradius(this.opts.bondLength,neighbour.getSize());nextCenter.multiplyScalar(r),nextCenter.add(vertexA.position),neighbour.positioned||this.createRing(neighbour,nextCenter,vertexA)}}for(var i=0;ithat.opts.overlapSensitivity&&(score+=s,count++);let position=that.graph.vertices[vertex.id].position.clone();position.multiplyScalar(s),center.add(position)}}),center.divide(score),{value:score/count,center:center}}getCurrentCenterOfMass(){let total=new Vector2(0,0),count=0;for(var i=0;itotal&&(this.rotateSubtree(a.id,overlap.common.id,2*angle,overlap.common.position),this.rotateSubtree(b.id,overlap.common.id,-2*angle,overlap.common.position))}else 1!==overlap.vertices.length||2!==overlap.rings.length}}resolveSecondaryOverlaps(scores){for(var i=0;ithis.opts.overlapSensitivity){let vertex=this.graph.vertices[scores[i].id];if(vertex.isTerminal()){let closest=this.getClosestVertex(vertex);if(closest){let closestPosition=null;closestPosition=closest.isTerminal()?0===closest.id?this.graph.vertices[1].position:closest.previousPosition:0===closest.id?this.graph.vertices[1].position:closest.position;let vertexPreviousPosition=0===vertex.id?this.graph.vertices[1].position:vertex.previousPosition;vertex.position.rotateAwayFrom(closestPosition,vertexPreviousPosition,MathHelper.toRad(20))}}}}getLastVertexWithAngle(vertexId){let angle=0,vertex=null;for(;!angle&&vertexId;)vertex=this.graph.vertices[vertexId],angle=vertex.angle,vertexId=vertex.parentVertexId;return vertex}createNextBond(vertex,previousVertex=null,angle=0,originShortest=!1,skipPositioning=!1){if(vertex.positioned&&!skipPositioning)return;let doubleBondConfigSet=!1;if(previousVertex){let edge=this.graph.getEdge(vertex.id,previousVertex.id);("/"===edge.bondType||"\\"===edge.bondType)&&1==++this.doubleBondConfigCount%2&&null===this.doubleBondConfig&&(this.doubleBondConfig=edge.bondType,doubleBondConfigSet=!0,null===previousVertex.parentVertexId&&vertex.value.branchBond&&("/"===this.doubleBondConfig?this.doubleBondConfig="\\":"\\"===this.doubleBondConfig&&(this.doubleBondConfig="/")))}if(!skipPositioning)if(!previousVertex){let dummy=new Vector2(this.opts.bondLength,0);dummy.rotate(MathHelper.toRad(-60)),vertex.previousPosition=dummy,vertex.setPosition(this.opts.bondLength,0),vertex.angle=MathHelper.toRad(-60),null===vertex.value.bridgedRing&&(vertex.positioned=!0)}else if(0a?_Mathmax3(-1.0472,a):1.0472;else if(!a){let v=this.getLastVertexWithAngle(vertex.id);a=v.angle,a||(a=1.0472)}if(previousVertex&&!doubleBondConfigSet){let bondType=this.graph.getEdge(vertex.id,nextVertex.id).bondType;"/"===bondType?("/"===this.doubleBondConfig||"\\"===this.doubleBondConfig&&(a=-a),this.doubleBondConfig=null):"\\"===bondType&&("/"===this.doubleBondConfig?a=-a:"\\"===this.doubleBondConfig,this.doubleBondConfig=null)}nextVertex.angle=originShortest?a:-a,this.createNextBond(nextVertex,vertex,previousAngle+nextVertex.angle)}}else if(2===neighbours.length){let a=vertex.angle;a||(a=1.0472);let subTreeDepthA=this.graph.getTreeDepth(neighbours[0],vertex.id),subTreeDepthB=this.graph.getTreeDepth(neighbours[1],vertex.id),l=this.graph.vertices[neighbours[0]],r=this.graph.vertices[neighbours[1]];l.value.subtreeDepth=subTreeDepthA,r.value.subtreeDepth=subTreeDepthB;let subTreeDepthC=this.graph.getTreeDepth(previousVertex?previousVertex.id:null,vertex.id);previousVertex&&(previousVertex.value.subtreeDepth=subTreeDepthC);let cis=0,trans=1;"C"===r.value.element&&"C"!==l.value.element&&1subTreeDepthA?(cis=1,trans=0):"C"!==r.value.element&&"C"===l.value.element&&1subTreeDepthB?(cis=0,trans=1):subTreeDepthB>subTreeDepthA&&(cis=1,trans=0);let cisVertex=this.graph.vertices[neighbours[cis]],transVertex=this.graph.vertices[neighbours[trans]],edgeCis=this.graph.getEdge(vertex.id,cisVertex.id),edgeTrans=this.graph.getEdge(vertex.id,transVertex.id),originShortest=!1;subTreeDepthCd1&&d2>d3?(s=this.graph.vertices[neighbours[1]],l=this.graph.vertices[neighbours[0]],r=this.graph.vertices[neighbours[2]]):d3>d1&&d3>d2&&(s=this.graph.vertices[neighbours[2]],l=this.graph.vertices[neighbours[0]],r=this.graph.vertices[neighbours[1]]),previousVertex&&1>previousVertex.value.rings.length&&1>s.value.rings.length&&1>l.value.rings.length&&1>r.value.rings.length&&1===this.graph.getTreeDepth(l.id,vertex.id)&&1===this.graph.getTreeDepth(r.id,vertex.id)&&1d1&&d2>d3&&d2>d4?(w=this.graph.vertices[neighbours[1]],x=this.graph.vertices[neighbours[0]],y=this.graph.vertices[neighbours[2]],z=this.graph.vertices[neighbours[3]]):d3>d1&&d3>d2&&d3>d4?(w=this.graph.vertices[neighbours[2]],x=this.graph.vertices[neighbours[0]],y=this.graph.vertices[neighbours[1]],z=this.graph.vertices[neighbours[3]]):d4>d1&&d4>d2&&d4>d3&&(w=this.graph.vertices[neighbours[3]],x=this.graph.vertices[neighbours[0]],y=this.graph.vertices[neighbours[1]],z=this.graph.vertices[neighbours[2]]),w.angle=-MathHelper.toRad(36),x.angle=MathHelper.toRad(36),y.angle=-MathHelper.toRad(108),z.angle=MathHelper.toRad(108),this.createNextBond(w,vertex,previousAngle+w.angle),this.createNextBond(x,vertex,previousAngle+x.angle),this.createNextBond(y,vertex,previousAngle+y.angle),this.createNextBond(z,vertex,previousAngle+z.angle)}}}getCommonRingbondNeighbour(vertex){let neighbours=vertex.neighbours;for(var i=0;imaxLevels&&(maxLevels=priorities[j][1].length);for(var k=0;kmaxEntries&&(maxEntries=priorities[j][1][k].length)}for(var j=0;jb[1][j][k])return-1;if(a[1][j][k]b[0]?-1:a[0]vertex.getNeighbourCount()||0heteroAtomCount)continue;let previous=null;for(var j=0;j{this.points.push(new Vector2(a[0],a[1]))}),this.weights=[],arr_weights.forEach(w=>{this.weights.push(w)})}draw(){let m=[];for(let x=0,row;xmax&&(max=m[x][y]);abs_max=Math.max(_Mathabs3(min),_Mathabs3(max))}const scale=chroma.scale(this.colormap).domain([-1,1]);for(let x=0;x{this.context.imageSmoothingEnabled=!1,this.context.drawImage(image,0,0,this.width,this.height),callback&&callback(image)},image.onerror=function(err){console.log(err)},image.src=this.canvas.toDataURL()}getSVG(){return convertImage(this.context.getImageData(0,0,this.width,this.height))}setPixel(vec,r,g,b){this.context.fillStyle="rgba("+r+","+g+","+b+","+this.opacity+")",this.context.fillRect(vec.x,vec.y,1,1)}}},{"./PixelsToSvg":16,"./Vector2":28,"chroma-js":2}],11:[function(require,module){"use strict";var _Mathpow2=Math.pow,_Mathsqrt3=Math.sqrt,_Mathmin5=Math.min;const MathHelper=require("./MathHelper"),Vector2=require("./Vector2"),Vertex=require("./Vertex"),Edge=require("./Edge"),Ring=require("./Ring"),Atom=require("./Atom");class Graph{constructor(parseTree,isomeric=!1){this.vertices=[],this.edges=[],this.atomIdxToVertexId=[],this.vertexIdsToEdgeId={},this.isomeric=isomeric,this._atomIdx=0,this._time=0,this._init(parseTree)}_init(node,order=0,parentVertexId=null,isBranch=!1){const element=node.atom.element?node.atom.element:node.atom;let atom=new Atom(element,node.bond);"H"===element&&(node.hasNext||null!==parentVertexId)||(atom.idx=this._atomIdx,this._atomIdx++),atom.branchBond=node.branchBond,atom.ringbonds=node.ringbonds,atom.bracket=node.atom.element?node.atom:null,atom.class=node.atom.class;let vertex=new Vertex(atom),parentVertex=this.vertices[parentVertexId];if(this.addVertex(vertex),null!==atom.idx&&this.atomIdxToVertexId.push(vertex.id),null!==parentVertexId){vertex.setParentVertexId(parentVertexId),vertex.value.addNeighbouringElement(parentVertex.value.element),parentVertex.addChild(vertex.id),parentVertex.value.addNeighbouringElement(atom.element),parentVertex.spanningTreeChildren.push(vertex.id);let edge=new Edge(parentVertexId,vertex.id,1),vertexId=null;isBranch?(edge.setBondType(vertex.value.branchBond||"-"),vertexId=vertex.id,edge.setBondType(vertex.value.branchBond||"-"),vertexId=vertex.id):(edge.setBondType(parentVertex.value.bondType||"-"),vertexId=parentVertex.id);this.addEdge(edge)}let offset=node.ringbondCount+1;atom.bracket&&(offset+=atom.bracket.hcount);let stereoHydrogens=0;if(atom.bracket&&atom.bracket.chirality){atom.isStereoCenter=!0,stereoHydrogens=atom.bracket.hcount;for(var i=0;idist[i][k]+dist[k][j]&&(dist[i][j]=dist[i][k]+dist[k][j]);return dist}getSubgraphDistanceMatrix(vertexIds){let length=vertexIds.length,adja=this.getSubgraphAdjacencyMatrix(vertexIds),dist=Array(length);for(var i=0;idist[i][k]+dist[k][j]&&(dist[i][j]=dist[i][k]+dist[k][j]);return dist}getAdjacencyList(){let length=this.vertices.length,adjacencyList=Array(length);for(var i=0;imax&&(max=d)}return max+1}traverseTree(vertexId,parentVertexId,callback,maxDepth=999999,ignoreFirst=!1,depth=1,visited=null){if(null===visited&&(visited=new Uint8Array(this.vertices.length)),depth>maxDepth+1||1===visited[vertexId])return;visited[vertexId]=1;let vertex=this.vertices[vertexId],neighbours=vertex.getNeighbours(parentVertexId);(!ignoreFirst||1maxEnergy&&!1===arrPositioned[i]&&(maxEnergy=delta,maxEnergyId=i,maxDEX=dEX,maxDEY=dEY)}return[maxEnergyId,maxEnergy,maxDEX,maxDEY]},update=function(index,dEX,dEY){let dxx=0,dyy=0,dxy=0,ux=arrPositionX[index],uy=arrPositionY[index],arrL=matLength[index],arrK=matStrength[index];for(i=length;i--;){if(i===index)continue;let vx=arrPositionX[i],vy=arrPositionY[i],l=arrL[i],k=arrK[i],m=(ux-vx)*(ux-vx),denom=1/_Mathpow2(m+(uy-vy)*(uy-vy),1.5);dxx+=k*(1-l*(uy-vy)*(uy-vy)*denom),dyy+=k*(1-l*m*denom),dxy+=k*(l*(ux-vx)*(uy-vy)*denom)}0==dxx&&(dxx=.1),0===dyy&&(dyy=.1),0===dxy&&(dxy=.1);let dy=dEX/dxx+dEY/dxy;dy/=dxy/dxx-dyy/dxy;let dx=-(dxy*dy+dEX)/dxx;arrPositionX[index]+=dx,arrPositionY[index]+=dy;let arrE=matEnergy[index];dEX=0,dEY=0,ux=arrPositionX[index],uy=arrPositionY[index];let vx,vy,prevEx,prevEy,denom;for(i=length;i--;)index!==i&&(vx=arrPositionX[i],vy=arrPositionY[i],prevEx=arrE[i][0],prevEy=arrE[i][1],denom=1/_Mathsqrt3((ux-vx)*(ux-vx)+(uy-vy)*(uy-vy)),dx=arrK[i]*(ux-vx-arrL[i]*(ux-vx)*denom),dy=arrK[i]*(uy-vy-arrL[i]*(uy-vy)*denom),arrE[i]=[dx,dy],dEX+=dx,dEY+=dy,arrEnergySumX[i]+=dx-prevEx,arrEnergySumY[i]+=dy-prevEy);arrEnergySumX[index]=dEX,arrEnergySumY[index]=dEY},maxEnergyId=0,dEX=0,dEY=0,delta=0,iteration=0,innerIteration=0;for(;maxEnergy>threshold&&maxIteration>iteration;)for(iteration++,[maxEnergyId,maxEnergy,dEX,dEY]=highestEnergy(),delta=maxEnergy,innerIteration=0;delta>innerThreshold&&maxInnerIteration>innerIteration;)innerIteration++,update(maxEnergyId,dEX,dEY),[delta,dEX,dEY]=energy(maxEnergyId);for(i=length;i--;){let index=vertexIds[i],vertex=this.vertices[index];vertex.position.x=arrPositionX[i],vertex.position.y=arrPositionY[i],vertex.positioned=!0,vertex.forcePositioned=!0}}_bridgeDfs(u,visited,disc,low,parent,adj,outBridges){visited[u]=!0,disc[u]=low[u]=++this._time;for(var i=0;idisc[u]&&outBridges.push([u,v]))}}static getConnectedComponents(adjacencyMatrix){let length=adjacencyMatrix.length,visited=Array(length),components=[],count=0;visited.fill(!1);for(var u=0;upeg$maxFailPos&&(peg$maxFailPos=peg$currPos,peg$maxFailExpected=[]),peg$maxFailExpected.push(expected))}function peg$buildSimpleError(message,location){return new peg$SyntaxError(message,null,null,location)}function peg$parsechain(){var s0,s1,s2,s3,s4,s5,s6,s7,s8,s9;if(s0=peg$currPos,s1=peg$currPos,s2=peg$parseatom(),s2!==peg$FAILED){for(s3=[],s4=peg$parsebranch();s4!==peg$FAILED;)s3.push(s4),s4=peg$parsebranch();if(s3!==peg$FAILED){for(s4=[],s5=peg$currPos,s6=peg$parsebond(),s6===peg$FAILED&&(s6=null),s6===peg$FAILED?(peg$currPos=s5,s5=peg$FAILED):(s7=peg$parsering(),s7===peg$FAILED?(peg$currPos=s5,s5=peg$FAILED):(s6=[s6,s7],s5=s6));s5!==peg$FAILED;)s4.push(s5),s5=peg$currPos,s6=peg$parsebond(),s6===peg$FAILED&&(s6=null),s6===peg$FAILED?(peg$currPos=s5,s5=peg$FAILED):(s7=peg$parsering(),s7===peg$FAILED?(peg$currPos=s5,s5=peg$FAILED):(s6=[s6,s7],s5=s6));if(s4!==peg$FAILED){for(s5=[],s6=peg$parsebranch();s6!==peg$FAILED;)s5.push(s6),s6=peg$parsebranch();if(s5===peg$FAILED)peg$currPos=s1,s1=peg$FAILED;else if(s6=peg$parsebond(),s6===peg$FAILED&&(s6=null),s6===peg$FAILED)peg$currPos=s1,s1=peg$FAILED;else if(s7=peg$parsechain(),s7===peg$FAILED&&(s7=null),s7!==peg$FAILED){for(s8=[],s9=peg$parsebranch();s9!==peg$FAILED;)s8.push(s9),s9=peg$parsebranch();s8===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3,s4,s5,s6,s7,s8],s1=s2)}else peg$currPos=s1,s1=peg$FAILED}else peg$currPos=s1,s1=peg$FAILED}else peg$currPos=s1,s1=peg$FAILED}else peg$currPos=s1,s1=peg$FAILED;return s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c0(s1)),s0=s1,s0}function peg$parsebranch(){var s0,s1,s2,s3,s4,s5;return s0=peg$currPos,s1=peg$currPos,40===input.charCodeAt(peg$currPos)?(s2="(",peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c2)),s2===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s3=peg$parsebond(),s3===peg$FAILED&&(s3=null),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s4=peg$parsechain(),s4===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(41===input.charCodeAt(peg$currPos)?(s5=")",peg$currPos++):(s5=peg$FAILED,peg$fail(peg$c4)),s5===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3,s4,s5],s1=s2)))),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c5(s1)),s0=s1,s0}function peg$parseatom(){var s0,s1;return s0=peg$currPos,s1=peg$parseorganicsymbol(),s1===peg$FAILED&&(s1=peg$parsearomaticsymbol(),s1===peg$FAILED&&(s1=peg$parsebracketatom(),s1===peg$FAILED&&(s1=peg$parsewildcard()))),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c6(s1)),s0=s1,s0}function peg$parsebond(){var s0,s1;if(s0=peg$currPos,peg$c7.test(input.charAt(peg$currPos))){if(s1=input.charAt(peg$currPos),s1===input.charAt(peg$currPos+1))throw s1=peg$FAILED,peg$buildSimpleError("The parser encountered a bond repetition.",peg$currPos+1);peg$currPos++}else s1=peg$FAILED,peg$fail(peg$c8);return s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c9(s1)),s0=s1,s0}function peg$parsebracketatom(){var s0,s1,s2,s3,s4,s5,s6,s7,s8,s9;return s0=peg$currPos,s1=peg$currPos,91===input.charCodeAt(peg$currPos)?(s2="[",peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c11)),s2===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s3=peg$parseisotope(),s3===peg$FAILED&&(s3=null),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):("se"===input.substr(peg$currPos,2)?(s4="se",peg$currPos+=2):(s4=peg$FAILED,peg$fail(peg$c13)),s4===peg$FAILED&&("as"===input.substr(peg$currPos,2)?(s4="as",peg$currPos+=2):(s4=peg$FAILED,peg$fail(peg$c15)),s4===peg$FAILED&&(s4=peg$parsearomaticsymbol(),s4===peg$FAILED&&(s4=peg$parseelementsymbol(),s4===peg$FAILED&&(s4=peg$parsewildcard())))),s4===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s5=peg$parsechiral(),s5===peg$FAILED&&(s5=null),s5===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s6=peg$parsehcount(),s6===peg$FAILED&&(s6=null),s6===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s7=peg$parsecharge(),s7===peg$FAILED&&(s7=null),s7===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s8=peg$parseclass(),s8===peg$FAILED&&(s8=null),s8===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(93===input.charCodeAt(peg$currPos)?(s9="]",peg$currPos++):(s9=peg$FAILED,peg$fail(peg$c17)),s9===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3,s4,s5,s6,s7,s8,s9],s1=s2)))))))),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c18(s1)),s0=s1,s0}function peg$parseorganicsymbol(){var s0,s1,s2,s3;return s0=peg$currPos,s1=peg$currPos,66===input.charCodeAt(peg$currPos)?(s2="B",peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c20)),s2===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(114===input.charCodeAt(peg$currPos)?(s3="r",peg$currPos++):(s3=peg$FAILED,peg$fail(peg$c22)),s3===peg$FAILED&&(s3=null),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3],s1=s2)),s1===peg$FAILED&&(s1=peg$currPos,67===input.charCodeAt(peg$currPos)?(s2="C",peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c24)),s2===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(108===input.charCodeAt(peg$currPos)?(s3="l",peg$currPos++):(s3=peg$FAILED,peg$fail(peg$c26)),s3===peg$FAILED&&(s3=null),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3],s1=s2)),s1===peg$FAILED&&(peg$c27.test(input.charAt(peg$currPos))?(s1=input.charAt(peg$currPos),peg$currPos++):(s1=peg$FAILED,peg$fail(peg$c28)))),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c29(s1)),s0=s1,s0}function peg$parsearomaticsymbol(){var s0,s1;return s0=peg$currPos,peg$c30.test(input.charAt(peg$currPos))?(s1=input.charAt(peg$currPos),peg$currPos++):(s1=peg$FAILED,peg$fail(peg$c31)),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c6(s1)),s0=s1,s0}function peg$parsewildcard(){var s0,s1;return s0=peg$currPos,42===input.charCodeAt(peg$currPos)?(s1="*",peg$currPos++):(s1=peg$FAILED,peg$fail(peg$c33)),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c34(s1)),s0=s1,s0}function peg$parseelementsymbol(){var s0,s1,s2,s3;return s0=peg$currPos,s1=peg$currPos,peg$c35.test(input.charAt(peg$currPos))?(s2=input.charAt(peg$currPos),peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c36)),s2===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(peg$c37.test(input.charAt(peg$currPos))?(s3=input.charAt(peg$currPos),peg$currPos++):(s3=peg$FAILED,peg$fail(peg$c38)),s3===peg$FAILED&&(s3=null),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3],s1=s2)),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c39(s1)),s0=s1,s0}function peg$parsering(){var s0,s1,s2,s3,s4;return s0=peg$currPos,s1=peg$currPos,37===input.charCodeAt(peg$currPos)?(s2="%",peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c41)),s2===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(peg$c42.test(input.charAt(peg$currPos))?(s3=input.charAt(peg$currPos),peg$currPos++):(s3=peg$FAILED,peg$fail(peg$c43)),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(peg$c44.test(input.charAt(peg$currPos))?(s4=input.charAt(peg$currPos),peg$currPos++):(s4=peg$FAILED,peg$fail(peg$c45)),s4===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3,s4],s1=s2))),s1===peg$FAILED&&(peg$c44.test(input.charAt(peg$currPos))?(s1=input.charAt(peg$currPos),peg$currPos++):(s1=peg$FAILED,peg$fail(peg$c45))),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c46(s1)),s0=s1,s0}function peg$parsechiral(){var s0,s1,s2,s3,s4,s5,s6;return s0=peg$currPos,s1=peg$currPos,64===input.charCodeAt(peg$currPos)?(s2="@",peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c48)),s2===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(64===input.charCodeAt(peg$currPos)?(s3="@",peg$currPos++):(s3=peg$FAILED,peg$fail(peg$c48)),s3===peg$FAILED&&(s3=peg$currPos,"TH"===input.substr(peg$currPos,2)?(s4="TH",peg$currPos+=2):(s4=peg$FAILED,peg$fail(peg$c50)),s4===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(peg$c51.test(input.charAt(peg$currPos))?(s5=input.charAt(peg$currPos),peg$currPos++):(s5=peg$FAILED,peg$fail(peg$c52)),s5===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(s4=[s4,s5],s3=s4)),s3===peg$FAILED&&(s3=peg$currPos,"AL"===input.substr(peg$currPos,2)?(s4="AL",peg$currPos+=2):(s4=peg$FAILED,peg$fail(peg$c54)),s4===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(peg$c51.test(input.charAt(peg$currPos))?(s5=input.charAt(peg$currPos),peg$currPos++):(s5=peg$FAILED,peg$fail(peg$c52)),s5===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(s4=[s4,s5],s3=s4)),s3===peg$FAILED&&(s3=peg$currPos,"SP"===input.substr(peg$currPos,2)?(s4="SP",peg$currPos+=2):(s4=peg$FAILED,peg$fail(peg$c56)),s4===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(peg$c57.test(input.charAt(peg$currPos))?(s5=input.charAt(peg$currPos),peg$currPos++):(s5=peg$FAILED,peg$fail(peg$c58)),s5===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(s4=[s4,s5],s3=s4)),s3===peg$FAILED&&(s3=peg$currPos,"TB"===input.substr(peg$currPos,2)?(s4="TB",peg$currPos+=2):(s4=peg$FAILED,peg$fail(peg$c60)),s4===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(peg$c42.test(input.charAt(peg$currPos))?(s5=input.charAt(peg$currPos),peg$currPos++):(s5=peg$FAILED,peg$fail(peg$c43)),s5===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(peg$c44.test(input.charAt(peg$currPos))?(s6=input.charAt(peg$currPos),peg$currPos++):(s6=peg$FAILED,peg$fail(peg$c45)),s6===peg$FAILED&&(s6=null),s6===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(s4=[s4,s5,s6],s3=s4))),s3===peg$FAILED&&(s3=peg$currPos,"OH"===input.substr(peg$currPos,2)?(s4="OH",peg$currPos+=2):(s4=peg$FAILED,peg$fail(peg$c62)),s4===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(peg$c42.test(input.charAt(peg$currPos))?(s5=input.charAt(peg$currPos),peg$currPos++):(s5=peg$FAILED,peg$fail(peg$c43)),s5===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(peg$c44.test(input.charAt(peg$currPos))?(s6=input.charAt(peg$currPos),peg$currPos++):(s6=peg$FAILED,peg$fail(peg$c45)),s6===peg$FAILED&&(s6=null),s6===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(s4=[s4,s5,s6],s3=s4)))))))),s3===peg$FAILED&&(s3=null),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3],s1=s2)),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c63(s1)),s0=s1,s0}function peg$parsecharge(){var s0,s1;return s0=peg$currPos,s1=peg$parseposcharge(),s1===peg$FAILED&&(s1=peg$parsenegcharge()),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c64(s1)),s0=s1,s0}function peg$parseposcharge(){var s0,s1,s2,s3,s4,s5;return s0=peg$currPos,s1=peg$currPos,43===input.charCodeAt(peg$currPos)?(s2="+",peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c66)),s2===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(43===input.charCodeAt(peg$currPos)?(s3="+",peg$currPos++):(s3=peg$FAILED,peg$fail(peg$c66)),s3===peg$FAILED&&(s3=peg$currPos,peg$c42.test(input.charAt(peg$currPos))?(s4=input.charAt(peg$currPos),peg$currPos++):(s4=peg$FAILED,peg$fail(peg$c43)),s4===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(peg$c44.test(input.charAt(peg$currPos))?(s5=input.charAt(peg$currPos),peg$currPos++):(s5=peg$FAILED,peg$fail(peg$c45)),s5===peg$FAILED&&(s5=null),s5===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(s4=[s4,s5],s3=s4))),s3===peg$FAILED&&(s3=null),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3],s1=s2)),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c67(s1)),s0=s1,s0}function peg$parsenegcharge(){var s0,s1,s2,s3,s4,s5;return s0=peg$currPos,s1=peg$currPos,45===input.charCodeAt(peg$currPos)?(s2="-",peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c69)),s2===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(45===input.charCodeAt(peg$currPos)?(s3="-",peg$currPos++):(s3=peg$FAILED,peg$fail(peg$c69)),s3===peg$FAILED&&(s3=peg$currPos,peg$c42.test(input.charAt(peg$currPos))?(s4=input.charAt(peg$currPos),peg$currPos++):(s4=peg$FAILED,peg$fail(peg$c43)),s4===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(peg$c44.test(input.charAt(peg$currPos))?(s5=input.charAt(peg$currPos),peg$currPos++):(s5=peg$FAILED,peg$fail(peg$c45)),s5===peg$FAILED&&(s5=null),s5===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(s4=[s4,s5],s3=s4))),s3===peg$FAILED&&(s3=null),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3],s1=s2)),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c70(s1)),s0=s1,s0}function peg$parsehcount(){var s0,s1,s2,s3;return s0=peg$currPos,s1=peg$currPos,72===input.charCodeAt(peg$currPos)?(s2="H",peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c72)),s2===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(peg$c44.test(input.charAt(peg$currPos))?(s3=input.charAt(peg$currPos),peg$currPos++):(s3=peg$FAILED,peg$fail(peg$c45)),s3===peg$FAILED&&(s3=null),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3],s1=s2)),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c73(s1)),s0=s1,s0}function peg$parseclass(){var s0,s1,s2,s3,s4,s5,s6;if(s0=peg$currPos,s1=peg$currPos,58===input.charCodeAt(peg$currPos)?(s2=":",peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c75)),s2!==peg$FAILED){if(s3=peg$currPos,peg$c42.test(input.charAt(peg$currPos))?(s4=input.charAt(peg$currPos),peg$currPos++):(s4=peg$FAILED,peg$fail(peg$c43)),s4!==peg$FAILED){for(s5=[],peg$c44.test(input.charAt(peg$currPos))?(s6=input.charAt(peg$currPos),peg$currPos++):(s6=peg$FAILED,peg$fail(peg$c45));s6!==peg$FAILED;)s5.push(s6),peg$c44.test(input.charAt(peg$currPos))?(s6=input.charAt(peg$currPos),peg$currPos++):(s6=peg$FAILED,peg$fail(peg$c45));s5===peg$FAILED?(peg$currPos=s3,s3=peg$FAILED):(s4=[s4,s5],s3=s4)}else peg$currPos=s3,s3=peg$FAILED;s3===peg$FAILED&&(peg$c76.test(input.charAt(peg$currPos))?(s3=input.charAt(peg$currPos),peg$currPos++):(s3=peg$FAILED,peg$fail(peg$c77))),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3],s1=s2)}else peg$currPos=s1,s1=peg$FAILED;return s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c78(s1)),s0=s1,s0}function peg$parseisotope(){var s0,s1,s2,s3,s4;return s0=peg$currPos,s1=peg$currPos,peg$c42.test(input.charAt(peg$currPos))?(s2=input.charAt(peg$currPos),peg$currPos++):(s2=peg$FAILED,peg$fail(peg$c43)),s2===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(peg$c44.test(input.charAt(peg$currPos))?(s3=input.charAt(peg$currPos),peg$currPos++):(s3=peg$FAILED,peg$fail(peg$c45)),s3===peg$FAILED&&(s3=null),s3===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(peg$c44.test(input.charAt(peg$currPos))?(s4=input.charAt(peg$currPos),peg$currPos++):(s4=peg$FAILED,peg$fail(peg$c45)),s4===peg$FAILED&&(s4=null),s4===peg$FAILED?(peg$currPos=s1,s1=peg$FAILED):(s2=[s2,s3,s4],s1=s2))),s1!==peg$FAILED&&(peg$savedPos=s0,s1=peg$c79(s1)),s0=s1,s0}options=void 0===options?{}:options;var nOpenParentheses=input.split("(").length-1,nCloseParentheses=input.split(")").length-1;if(nOpenParentheses!==nCloseParentheses)throw peg$buildSimpleError("The number of opening parentheses does not match the number of closing parentheses.",0);var peg$FAILED={},peg$startRuleFunctions={chain:peg$parsechain},peg$startRuleFunction=peg$parsechain,peg$c0=function(s){for(var branches=[],rings=[],i=0;i\n"}let colors=function(img){for(var colors={},data=img.data,len=data.length,w=img.width,h=img.height,x=0,y=0,i=0,color;i"+paths+"";var dummyDiv=document.createElement("div");return dummyDiv.innerHTML=output,dummyDiv.firstChild}},{}],17:[function(require,module){"use strict";const Parser=require("./Parser");module.exports=class{constructor(reactionSmiles){this.reactantsSmiles=[],this.reagentsSmiles=[],this.productsSmiles=[],this.reactantsWeights=[],this.reagentsWeights=[],this.productsWeights=[],this.reactants=[],this.reagents=[],this.products=[];let parts=reactionSmiles.split(">");if(3!==parts.length)throw new Error("Invalid reaction SMILES. Did you add fewer than or more than two '>'?");""!==parts[0]&&(this.reactantsSmiles=parts[0].split(".")),""!==parts[1]&&(this.reagentsSmiles=parts[1].split(".")),""!==parts[2]&&(this.productsSmiles=parts[2].split("."));for(var i=0;imax&&(max=weights.reactants[i][j]);if(weights.hasOwnProperty("reagents"))for(let i=0;imax&&(max=weights.reagents[i][j]);if(weights.hasOwnProperty("products"))for(let i=0;imax&&(max=weights.products[i][j]);let abs_max=_Mathmax4(_Mathabs4(min),_Mathabs4(max));if(0===abs_max&&(abs_max=1),weights.hasOwnProperty("reactants"))for(let i=0;ii&&(reactantWeights=weights.reactants[i]);let reactantSvg=document.createElementNS("http://www.w3.org/2000/svg","svg");this.drawer.draw(reaction.reactants[i],reactantSvg,themeName,reactantWeights,infoOnly,[],this.opts.weights.normalize);let element={width:reactantSvg.viewBox.baseVal.width*this.opts.scale,height:reactantSvg.viewBox.baseVal.height*this.opts.scale,svg:reactantSvg};elements.push(element),element.height>maxHeight&&(maxHeight=element.height)}elements.push({width:this.opts.arrow.length*this.opts.scale,height:2*this.opts.arrow.headSize*this.opts.scale,svg:this.getArrow()});let reagentsText="";for(var i=0;ii&&(productWeights=weights.products[i]);let productSvg=document.createElementNS("http://www.w3.org/2000/svg","svg");this.drawer.draw(reaction.products[i],productSvg,themeName,productWeights,infoOnly,[],this.opts.weights.normalize);let element={width:productSvg.viewBox.baseVal.width*this.opts.scale,height:productSvg.viewBox.baseVal.height*this.opts.scale,svg:productSvg};elements.push(element),element.height>maxHeight&&(maxHeight=element.height)}let totalWidth=0;return elements.forEach(element=>{let offsetX=element.offsetX??0,offsetY=element.offsetY??0;element.svg.setAttributeNS(null,"x",_Mathround3(totalWidth+offsetX)),element.svg.setAttributeNS(null,"y",_Mathround3((maxHeight-element.height)/2+offsetY)),element.svg.setAttributeNS(null,"width",_Mathround3(element.width)),element.svg.setAttributeNS(null,"height",_Mathround3(element.height)),svg.appendChild(element.svg),"relative"!==element.position&&(totalWidth+=_Mathround3(element.width+this.opts.spacing+offsetX))}),svg.setAttributeNS(null,"viewBox",`0 0 ${totalWidth} ${maxHeight}`),svg.style.width=totalWidth+"px",svg.style.height=maxHeight+"px",svg}getPlus(){let s=this.opts.plus.size,w=this.opts.plus.thickness,svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),rect_h=document.createElementNS("http://www.w3.org/2000/svg","rect"),rect_v=document.createElementNS("http://www.w3.org/2000/svg","rect");return svg.setAttributeNS(null,"id","plus"),rect_h.setAttributeNS(null,"x",0),rect_h.setAttributeNS(null,"y",s/2-w/2),rect_h.setAttributeNS(null,"width",s),rect_h.setAttributeNS(null,"height",w),rect_h.setAttributeNS(null,"fill",this.themeManager.getColor("C")),rect_v.setAttributeNS(null,"x",s/2-w/2),rect_v.setAttributeNS(null,"y",0),rect_v.setAttributeNS(null,"width",w),rect_v.setAttributeNS(null,"height",s),rect_v.setAttributeNS(null,"fill",this.themeManager.getColor("C")),svg.appendChild(rect_h),svg.appendChild(rect_v),svg.setAttributeNS(null,"viewBox",`0 0 ${s} ${s}`),svg}getArrowhead(){let s=this.opts.arrow.headSize,marker=document.createElementNS("http://www.w3.org/2000/svg","marker"),polygon=document.createElementNS("http://www.w3.org/2000/svg","polygon");return marker.setAttributeNS(null,"id","arrowhead"),marker.setAttributeNS(null,"viewBox",`0 0 ${s} ${s}`),marker.setAttributeNS(null,"markerUnits","userSpaceOnUse"),marker.setAttributeNS(null,"markerWidth",s),marker.setAttributeNS(null,"markerHeight",s),marker.setAttributeNS(null,"refX",0),marker.setAttributeNS(null,"refY",s/2),marker.setAttributeNS(null,"orient","auto"),marker.setAttributeNS(null,"fill",this.themeManager.getColor("C")),polygon.setAttributeNS(null,"points",`0 0, ${s} ${s/2}, 0 ${s}`),marker.appendChild(polygon),marker}getCDArrowhead(){let s=this.opts.arrow.headSize,sw=s*(7/4.5),marker=document.createElementNS("http://www.w3.org/2000/svg","marker"),path=document.createElementNS("http://www.w3.org/2000/svg","path");return marker.setAttributeNS(null,"id","arrowhead"),marker.setAttributeNS(null,"viewBox",`0 0 ${sw} ${s}`),marker.setAttributeNS(null,"markerUnits","userSpaceOnUse"),marker.setAttributeNS(null,"markerWidth",2*sw),marker.setAttributeNS(null,"markerHeight",2*s),marker.setAttributeNS(null,"refX",2.2),marker.setAttributeNS(null,"refY",2.2),marker.setAttributeNS(null,"orient","auto"),marker.setAttributeNS(null,"fill",this.themeManager.getColor("C")),path.setAttributeNS(null,"style","fill-rule:nonzero;"),path.setAttributeNS(null,"d","m 0 0 l 7 2.25 l -7 2.25 c 0 0 0.735 -1.084 0.735 -2.28 c 0 -1.196 -0.735 -2.22 -0.735 -2.22 z"),marker.appendChild(path),marker}getArrow(){let s=this.opts.arrow.headSize,l=this.opts.arrow.length,svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),defs=document.createElementNS("http://www.w3.org/2000/svg","defs"),line=document.createElementNS("http://www.w3.org/2000/svg","line");return defs.appendChild(this.getCDArrowhead()),svg.appendChild(defs),svg.setAttributeNS(null,"id","arrow"),line.setAttributeNS(null,"x1",0),line.setAttributeNS(null,"y1",-this.opts.arrow.thickness/2),line.setAttributeNS(null,"x2",l),line.setAttributeNS(null,"y2",-this.opts.arrow.thickness/2),line.setAttributeNS(null,"stroke-width",this.opts.arrow.thickness),line.setAttributeNS(null,"stroke",this.themeManager.getColor("C")),line.setAttributeNS(null,"marker-end","url(#arrowhead)"),svg.appendChild(line),svg.setAttributeNS(null,"viewBox",`0 ${-s/2} ${l+s*(7/4.5)} ${s}`),svg}}},{"./FormulaToCommonName":9,"./Options":14,"./SvgDrawer":24,"./SvgWrapper":25,"./ThemeManager":26}],19:[function(require,module){"use strict";const Reaction=require("./Reaction");module.exports=class{static parse(reactionSmiles){let reaction=new Reaction(reactionSmiles);return reaction}}},{"./Reaction":17}],20:[function(require,module){"use strict";const ArrayHelper=require("./ArrayHelper"),Vector2=require("./Vector2"),Vertex=require("./Vertex"),RingConnection=require("./RingConnection");class Ring{constructor(members){this.id=null,this.members=members,this.edges=[],this.insiders=[],this.neighbours=[],this.positioned=!1,this.center=new Vector2(0,0),this.rings=[],this.isBridged=!1,this.isPartOfBridged=!1,this.isSpiro=!1,this.isFused=!1,this.centralAngle=0,this.canFlip=!0}clone(){let clone=new Ring(this.members);return clone.id=this.id,clone.insiders=ArrayHelper.clone(this.insiders),clone.neighbours=ArrayHelper.clone(this.neighbours),clone.positioned=this.positioned,clone.center=this.center.clone(),clone.rings=ArrayHelper.clone(this.rings),clone.isBridged=this.isBridged,clone.isPartOfBridged=this.isPartOfBridged,clone.isSpiro=this.isSpiro,clone.isFused=this.isFused,clone.centralAngle=this.centralAngle,clone.canFlip=this.canFlip,clone}getSize(){return this.members.length}getPolygon(vertices){let polygon=[];for(let i=0;imax;){let prev=current;callback(prev),current=vertices[current].getNextInRing(vertices,this.id,previousVertexId),previousVertexId=prev,current==startVertexId&&(current=null),max++}}getOrderedNeighbours(ringConnections){let orderedNeighbours=Array(this.neighbours.length);for(let i=0,vertices;inewPathLength){var l,m,n;if(previousPathLength===newPathLength+1)for(pe_prime[i][j]=[pe[i][j].length],l=pe[i][j].length;l--;)for(pe_prime[i][j][l]=[pe[i][j][l].length],m=pe[i][j][l].length;m--;)for(pe_prime[i][j][l][m]=[pe[i][j][l][m].length],n=pe[i][j][l][m].length;n--;)pe_prime[i][j][l][m][n]=[pe[i][j][l][m][0],pe[i][j][l][m][1]];else pe_prime[i][j]=[];for(d[i][j]=newPathLength,pe[i][j]=[[]],l=pe[i][k][0].length;l--;)pe[i][j][0].push(pe[i][k][0][l]);for(l=pe[k][j][0].length;l--;)pe[i][j][0].push(pe[k][j][0][l])}else if(previousPathLength===newPathLength){if(pe[i][k].length&&pe[k][j].length){var l;if(pe[i][j].length){let tmp=[];for(l=pe[i][k][0].length;l--;)tmp.push(pe[i][k][0][l]);for(l=pe[k][j][0].length;l--;)tmp.push(pe[k][j][0][l]);pe[i][j].push(tmp)}else{let tmp=[];for(l=pe[i][k][0].length;l--;)tmp.push(pe[i][k][0][l]);for(l=pe[k][j][0].length;l--;)tmp.push(pe[k][j][0][l]);pe[i][j][0]=tmp}}}else if(previousPathLength===newPathLength-1){var l;if(pe_prime[i][j].length){let tmp=[];for(l=pe[i][k][0].length;l--;)tmp.push(pe[i][k][0][l]);for(l=pe[k][j][0].length;l--;)tmp.push(pe[k][j][0][l]);pe_prime[i][j].push(tmp)}else{let tmp=[];for(l=pe[i][k][0].length;l--;)tmp.push(pe[i][k][0][l]);for(l=pe[k][j][0].length;l--;)tmp.push(pe[k][j][0][l]);pe_prime[i][j][0]=tmp}}}return{d:d,pe:pe,pe_prime:pe_prime}}static getRingCandidates(d,pe,pe_prime){let length=d.length,candidates=[],c=0;for(let i=0;insssr)return cSssr}else for(let j=0,bonds;jnsssr)return cSssr}return cSssr}static getEdgeCount(adjacencyMatrix){let edgeCount=0,length=adjacencyMatrix.length;for(var i=length-1;i--;)for(var j=length;j--;)1===adjacencyMatrix[i][j]&&edgeCount++;return edgeCount}static getEdgeList(adjacencyMatrix){let length=adjacencyMatrix.length,edgeList=[];for(var i=length-1;i--;)for(var j=length;j--;)1===adjacencyMatrix[i][j]&&edgeList.push([i,j]);return edgeList}static bondsToAtoms(bonds){let atoms=new Set;for(var i=bonds.length;i--;)atoms.add(bonds[i][0]),atoms.add(bonds[i][1]);return atoms}static getBondCount(atoms,adjacencyMatrix){let count=0;for(let u of atoms)for(let v of atoms)u!==v&&(count+=adjacencyMatrix[u][v]);return count/2}static pathSetsContain(pathSets,pathSet,bonds,allBonds,arrBondCount,arrRingCount){for(var i=pathSets.length;i--;){if(SSSR.isSupersetOf(pathSet,pathSets[i]))return!0;if(pathSets[i].size===pathSet.size&&SSSR.areSetsEqual(pathSets[i],pathSet))return!0}let count=0,allContained=!1;for(i=bonds.length;i--;)for(var j=allBonds.length;j--;)(bonds[i][0]===allBonds[j][0]&&bonds[i][1]===allBonds[j][1]||bonds[i][1]===allBonds[j][0]&&bonds[i][0]===allBonds[j][1])&&count++,count===bonds.length&&(allContained=!0);let specialCase=!1;if(allContained)for(let element of pathSet)if(arrRingCount[element]{let smiles=element.getAttribute(attribute);if(null===smiles)throw Error("No SMILES provided.");let currentTheme=theme,weights=null;if(element.hasAttribute("data-smiles-theme")&&(currentTheme=element.getAttribute("data-smiles-theme")),element.hasAttribute("data-smiles-weights")&&(weights=element.getAttribute("data-smiles-weights").split(",").map(parseFloat)),(element.hasAttribute("data-smiles-reactant-weights")||element.hasAttribute("data-smiles-reagent-weights")||element.hasAttribute("data-smiles-product-weights"))&&(weights={reactants:[],reagents:[],products:[]},element.hasAttribute("data-smiles-reactant-weights")&&(weights.reactants=element.getAttribute("data-smiles-reactant-weights").split(";").map(v=>v.split(",").map(parseFloat))),element.hasAttribute("data-smiles-reagent-weights")&&(weights.reagents=element.getAttribute("data-smiles-reagent-weights").split(";").map(v=>v.split(",").map(parseFloat))),element.hasAttribute("data-smiles-product-weights")&&(weights.products=element.getAttribute("data-smiles-product-weights").split(";").map(v=>v.split(",").map(parseFloat)))),element.hasAttribute("data-smiles-options")||element.hasAttribute("data-smiles-reaction-options")){let moleculeOptions={};element.hasAttribute("data-smiles-options")&&(moleculeOptions=JSON.parse(element.getAttribute("data-smiles-options").replaceAll("'","\"")));let reactionOptions={};element.hasAttribute("data-smiles-reaction-options")&&(reactionOptions=JSON.parse(element.getAttribute("data-smiles-reaction-options").replaceAll("'","\"")));let smilesDrawer=new SmilesDrawer(moleculeOptions,reactionOptions);smilesDrawer.draw(smiles,element,currentTheme,successCallback,errorCallback,weights)}else this.draw(smiles,element,currentTheme,successCallback,errorCallback,weights)})}draw(smiles,target,theme="light",successCallback=null,errorCallback=null,weights=null){let rest=[];[smiles,...rest]=smiles.split(" ");let info=rest.join(" "),settings={};if(info.includes("__")){let settingsString=info.substring(info.indexOf("__")+2,info.lastIndexOf("__"));settings=JSON.parse(settingsString.replaceAll("'","\""))}if(settings=Options.extend(!0,{textAboveArrow:"{reagents}",textBelowArrow:""},settings),smiles.includes(">"))try{this.drawReaction(smiles,target,theme,settings,weights,successCallback)}catch(err){errorCallback?errorCallback(err):console.error(err)}else try{this.drawMolecule(smiles,target,theme,weights,successCallback)}catch(err){errorCallback?errorCallback(err):console.error(err)}}drawMolecule(smiles,target,theme,weights,callback){let parseTree=Parser.parse(smiles);if(null===target||"svg"===target){let svg=this.drawer.draw(parseTree,null,theme,weights),dims=this.getDimensions(svg);svg.setAttributeNS(null,"width",""+dims.w),svg.setAttributeNS(null,"height",""+dims.h),callback&&callback(svg)}else if("canvas"===target){let canvas=this.svgToCanvas(this.drawer.draw(parseTree,null,theme,weights));callback&&callback(canvas)}else if("img"===target){let img=this.svgToImg(this.drawer.draw(parseTree,null,theme,weights));callback&&callback(img)}else if(target instanceof HTMLImageElement)this.svgToImg(this.drawer.draw(parseTree,null,theme,weights),target),callback&&callback(target);else if(target instanceof SVGElement)this.drawer.draw(parseTree,target,theme,weights),callback&&callback(target);else{let elements=document.querySelectorAll(target);elements.forEach(element=>{let tag=element.nodeName.toLowerCase();"svg"===tag?(this.drawer.draw(parseTree,element,theme,weights),callback&&callback(element)):"canvas"===tag?(this.svgToCanvas(this.drawer.draw(parseTree,null,theme,weights),element),callback&&callback(element)):"img"===tag&&(this.svgToImg(this.drawer.draw(parseTree,null,theme,weights),element),callback&&callback(element))})}}drawReaction(smiles,target,theme,settings,weights,callback){let reaction=ReactionParser.parse(smiles);if(null===target||"svg"===target){let svg=this.reactionDrawer.draw(reaction,null,theme),dims=this.getDimensions(svg);svg.setAttributeNS(null,"width",""+dims.w),svg.setAttributeNS(null,"height",""+dims.h),callback&&callback(svg)}else if("canvas"===target){let canvas=this.svgToCanvas(this.reactionDrawer.draw(reaction,null,theme,weights,settings.textAboveArrow,settings.textBelowArrow));callback&&callback(canvas)}else if("img"===target){let img=this.svgToImg(this.reactionDrawer.draw(reaction,null,theme,weights,settings.textAboveArrow,settings.textBelowArrow));callback&&callback(img)}else if(target instanceof HTMLImageElement)this.svgToImg(this.reactionDrawer.draw(reaction,null,theme,weights,settings.textAboveArrow,settings.textBelowArrow),target),callback&&callback(target);else if(target instanceof SVGElement)this.reactionDrawer.draw(reaction,target,theme,weights,settings.textAboveArrow,settings.textBelowArrow),callback&&callback(target);else{let elements=document.querySelectorAll(target);elements.forEach(element=>{let tag=element.nodeName.toLowerCase();"svg"===tag?(this.reactionDrawer.draw(reaction,element,theme,weights,settings.textAboveArrow,settings.textBelowArrow),0>=this.reactionDrawer.opts.scale&&(element.style.width=null,element.style.height=null),callback&&callback(element)):"canvas"===tag?(this.svgToCanvas(this.reactionDrawer.draw(reaction,null,theme,weights,settings.textAboveArrow,settings.textBelowArrow),element),callback&&callback(element)):"img"===tag&&(this.svgToImg(this.reactionDrawer.draw(reaction,null,theme,weights,settings.textAboveArrow,settings.textBelowArrow),element),callback&&callback(element))})}}svgToCanvas(svg,canvas=null){null===canvas&&(canvas=document.createElement("canvas"));let dims=this.getDimensions(canvas,svg);return SvgWrapper.svgToCanvas(svg,canvas,dims.w,dims.h),canvas}svgToImg(svg,img=null){null===img&&(img=document.createElement("img"));let dims=this.getDimensions(img,svg);return SvgWrapper.svgToImg(svg,img,dims.w,dims.h),img}getDimensions(element,svg=null){let w=this.drawer.opts.width,h=this.drawer.opts.height;return 0>=this.drawer.opts.scale?(null===w&&(w=element.width),null===h&&(h=element.height),""!==element.style.width&&(w=parseInt(element.style.width)),""!==element.style.height&&(h=parseInt(element.style.height))):svg&&(w=parseFloat(svg.style.width),h=parseFloat(svg.style.height)),{w:w,h:h}}}module.exports=SmilesDrawer},{"./Drawer":6,"./Options":14,"./Parser":15,"./ReactionDrawer":18,"./ReactionParser":19,"./SvgDrawer":24,"./SvgWrapper":25}],24:[function(require,module){"use strict";var _MathPI4=Math.PI,_Mathabs5=Math.abs;const ArrayHelper=require("./ArrayHelper"),Atom=require("./Atom"),DrawerBase=require("./DrawerBase"),Graph=require("./Graph"),Line=require("./Line"),SvgWrapper=require("./SvgWrapper"),ThemeManager=require("./ThemeManager"),Vector2=require("./Vector2"),GaussDrawer=require("./GaussDrawer");module.exports=class{constructor(options,clear=!0){this.preprocessor=new DrawerBase(options),this.opts=this.preprocessor.opts,this.clear=clear,this.svgWrapper=null}draw(data,target,themeName="light",weights=null,infoOnly=!1,highlight_atoms=[],weightsNormalized=!1){null===target||"svg"===target?(target=document.createElementNS("http://www.w3.org/2000/svg","svg"),target.setAttribute("xmlns","http://www.w3.org/2000/svg"),target.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),target.setAttributeNS(null,"width",this.opts.width),target.setAttributeNS(null,"height",this.opts.height)):target instanceof String&&(target=document.getElementById(target));let optionBackup={padding:this.opts.padding,compactDrawing:this.opts.compactDrawing};null!==weights&&(this.opts.padding+=this.opts.weights.additionalPadding,this.opts.compactDrawing=!1);let preprocessor=this.preprocessor;return preprocessor.initDraw(data,themeName,infoOnly,highlight_atoms),infoOnly||(this.themeManager=new ThemeManager(this.opts.themes,themeName),(null===this.svgWrapper||this.clear)&&(this.svgWrapper=new SvgWrapper(this.themeManager,target,this.opts,this.clear))),preprocessor.processGraph(),this.svgWrapper.determineDimensions(preprocessor.graph.vertices),this.drawAtomHighlights(preprocessor.opts.debug),this.drawEdges(preprocessor.opts.debug),this.drawVertices(preprocessor.opts.debug),null!==weights&&this.drawWeights(weights,weightsNormalized),preprocessor.opts.debug&&(console.log(preprocessor.graph),console.log(preprocessor.rings),console.log(preprocessor.ringConnections)),this.svgWrapper.constructSvg(),null!==weights&&(this.opts.padding=optionBackup.padding,this.opts.compactDrawing=optionBackup.padding),target}drawCanvas(data,target,themeName="light",infoOnly=!1){let canvas=null;canvas="string"==typeof target||target instanceof String?document.getElementById(target):target;let svg=document.createElementNS("http://www.w3.org/2000/svg","svg");return svg.setAttribute("xmlns","http://www.w3.org/2000/svg"),svg.setAttributeNS(null,"viewBox","0 0 500 500"),svg.setAttributeNS(null,"width","500"),svg.setAttributeNS(null,"height","500"),svg.setAttributeNS(null,"style","visibility: hidden: position: absolute; left: -1000px"),document.body.appendChild(svg),this.svgDrawer.draw(data,svg,themeName,infoOnly),this.svgDrawer.svgWrapper.toCanvas(canvas,this.svgDrawer.opts.width,this.svgDrawer.opts.height),document.body.removeChild(svg),target}drawAromaticityRing(ring){let svgWrapper=this.svgWrapper;svgWrapper.drawRing(ring.center.x,ring.center.y,ring.getSize())}drawEdges(debug){let preprocessor=this.preprocessor,graph=preprocessor.graph,rings=preprocessor.rings,drawn=Array(this.preprocessor.graph.edges.length);if(drawn.fill(!1),graph.traverseBF(0,vertex=>{let edges=graph.getEdges(vertex.id);for(var i=0;is.sideCount[1]||s.totalSideCount[0]>s.totalSideCount[1]){this.multiplyNormals(normals,opts.bondSpacing);let line=new Line(Vector2.add(a,normals[0]),Vector2.add(b,normals[0]),elementA,elementB);line.shorten(opts.bondLength-opts.shortBondLength*opts.bondLength),svgWrapper.drawLine(line),svgWrapper.drawLine(new Line(a,b,elementA,elementB))}else if(s.sideCount[0]graph.vertices.length&&(isCarbon=!1),"N"===atom.element&&atom.isPartOfAromaticRing&&(hydrogens=0),atom.bracket&&(hydrogens=atom.bracket.hcount,charge=atom.bracket.charge,isotope=atom.bracket.isotope),"allballs"===opts.atomVisualization)svgWrapper.drawBall(vertex.position.x,vertex.position.y,element);else if(atom.isDrawn&&(!isCarbon||atom.drawExplicit||isTerminal||atom.hasAttachedPseudoElements)||1===graph.vertices.length){if("default"===opts.atomVisualization){let attachedPseudoElements=atom.getAttachedPseudoElements();atom.hasAttachedPseudoElements&&graph.vertices.length===Object.keys(attachedPseudoElements).length+1&&(dir="right"),svgWrapper.drawText(vertex.position.x,vertex.position.y,element,hydrogens,dir,isTerminal,charge,isotope,graph.vertices.length,attachedPseudoElements)}else"balls"===opts.atomVisualization&&svgWrapper.drawBall(vertex.position.x,vertex.position.y,element);}else if(2===vertex.getNeighbourCount()&&!0==vertex.forcePositioned){let a=graph.vertices[vertex.neighbours[0]].position,b=graph.vertices[vertex.neighbours[1]].position,angle=Vector2.threePointangle(vertex.position,a,b);.1>_Mathabs5(_MathPI4-angle)&&svgWrapper.drawPoint(vertex.position.x,vertex.position.y,element)}if(debug){let value="v: "+vertex.id+" "+ArrayHelper.print(atom.ringbonds);svgWrapper.drawDebugText(vertex.position.x,vertex.position.y,value)}}if(opts.debug)for(var i=0;i0===w)){if(weights.length!==this.preprocessor.graph.atomIdxToVertexId.length)throw new Error("The number of weights supplied must be equal to the number of (heavy) atoms in the molecule.");let points=[];for(const atomIdx of this.preprocessor.graph.atomIdxToVertexId){let vertex=this.preprocessor.graph.vertices[atomIdx];points.push(new Vector2(vertex.position.x-this.svgWrapper.minX,vertex.position.y-this.svgWrapper.minY))}let gd=new GaussDrawer(points,weights,this.svgWrapper.drawingWidth,this.svgWrapper.drawingHeight,this.opts.weights.sigma,this.opts.weights.interval,this.opts.weights.colormap,this.opts.weights.opacity,weightsNormalized);gd.draw(),this.svgWrapper.addLayer(gd.getSVG())}}getTotalOverlapScore(){return this.preprocessor.getTotalOverlapScore()}getMolecularFormula(graph=null){return this.preprocessor.getMolecularFormula(graph)}multiplyNormals(normals,spacing){normals[0].multiplyScalar(spacing),normals[1].multiplyScalar(spacing)}}},{"./ArrayHelper":3,"./Atom":4,"./DrawerBase":7,"./GaussDrawer":10,"./Graph":11,"./Line":12,"./SvgWrapper":25,"./ThemeManager":26,"./Vector2":28}],25:[function(require,module){"use strict";var _NumberMAX_SAFE_INTEGER3=Number.MAX_SAFE_INTEGER,_NumberMAX_VALUE3=Number.MAX_VALUE,_Mathabs6=Math.abs;function makeid(length){for(var result="",characters="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",charactersLength=characters.length,i=0;in?SvgWrapper.createUnicodeSuperscript(n)+"\u207B":""}determineDimensions(vertices){for(var i=0;ip.x&&(this.minX=p.x),this.minY>p.y&&(this.minY=p.y)}let padding=this.opts.padding;this.maxX+=padding,this.maxY+=padding,this.minX-=padding,this.minY-=padding,this.drawingWidth=this.maxX-this.minX,this.drawingHeight=this.maxY-this.minY}updateViewbox(scale){let x=this.minX,y=this.minY,width=this.maxX-this.minX,height=this.maxY-this.minY;if(!(0>=scale))this.svg&&(this.svg.style.width=scale*width+"px",this.svg.style.height=scale*height+"px");else if(width>height){let diff=width-height;height=width,y-=diff/2}else{let diff=height-width;width=height,x-=diff/2}this.svg.setAttributeNS(null,"viewBox",`${x} ${y} ${width} ${height}`)}drawBall(x,y,elementName){let r=this.opts.bondLength/4.5;x-rthis.maxX&&(this.maxX=x+r),y-rthis.maxY&&(this.maxY=y+r);let ball=document.createElementNS("http://www.w3.org/2000/svg","circle");ball.setAttributeNS(null,"cx",x),ball.setAttributeNS(null,"cy",y),ball.setAttributeNS(null,"r",r),ball.setAttributeNS(null,"fill",this.themeManager.getColor(elementName)),this.vertices.push(ball)}drawWedge(line){let l=line.getLeftVector().clone(),r=line.getRightVector().clone(),normals=Vector2.normals(l,r);normals[0].normalize(),normals[1].normalize();let isRightChiralCenter=line.getRightChiral(),start=l,end=r;isRightChiralCenter&&(start=r,end=l);let t=Vector2.add(start,Vector2.multiplyScalar(normals[0],this.halfBondThickness)),u=Vector2.add(end,Vector2.multiplyScalar(normals[0],3+this.opts.fontSizeLarge/4)),v=Vector2.add(end,Vector2.multiplyScalar(normals[1],3+this.opts.fontSizeLarge/4)),w=Vector2.add(start,Vector2.multiplyScalar(normals[1],this.halfBondThickness)),polygon=document.createElementNS("http://www.w3.org/2000/svg","polygon"),gradient=this.createGradient(line,l.x,l.y,r.x,r.y);polygon.setAttributeNS(null,"points",`${t.x},${t.y} ${u.x},${u.y} ${v.x},${v.y} ${w.x},${w.y}`),polygon.setAttributeNS(null,"fill",`url('#${gradient}')`),this.paths.push(polygon)}drawAtomHighlight(x,y,color="#03fc9d"){let ball=document.createElementNS("http://www.w3.org/2000/svg","circle");ball.setAttributeNS(null,"cx",x),ball.setAttributeNS(null,"cy",y),ball.setAttributeNS(null,"r",this.opts.bondLength/3),ball.setAttributeNS(null,"fill",color),this.highlights.push(ball)}drawDashedWedge(line){if(isNaN(line.from.x)||isNaN(line.from.y)||isNaN(line.to.x)||isNaN(line.to.y))return;let l=line.getLeftVector().clone(),r=line.getRightVector().clone(),normals=Vector2.normals(l,r);normals[0].normalize(),normals[1].normalize();let isRightChiralCenter=line.getRightChiral(),start,end;isRightChiralCenter?(start=r,end=l):(start=l,end=r);let dir=Vector2.subtract(end,start).normalize(),length=line.getLength(),step=1.25/(length/(this.opts.bondLength/10)),gradient=this.createGradient(line);for(let t=0;1>t;t+=step){let to=Vector2.multiplyScalar(dir,t*length),startDash=Vector2.add(start,to),width=this.opts.fontSizeLarge/2*t,dashOffset=Vector2.multiplyScalar(normals[0],width);startDash.subtract(dashOffset);let endDash=startDash.clone();endDash.add(Vector2.multiplyScalar(dashOffset,2)),this.drawLine(new Line(startDash,endDash),null,gradient)}}drawDebugPoint(x,y,debugText="",color="#f00"){let point=document.createElementNS("http://www.w3.org/2000/svg","circle");point.setAttributeNS(null,"cx",x),point.setAttributeNS(null,"cy",y),point.setAttributeNS(null,"r","2"),point.setAttributeNS(null,"fill","#f00"),this.vertices.push(point),this.drawDebugText(x,y,debugText)}drawDebugText(x,y,text){let textElem=document.createElementNS("http://www.w3.org/2000/svg","text");textElem.setAttributeNS(null,"x",x),textElem.setAttributeNS(null,"y",y),textElem.setAttributeNS(null,"class","debug"),textElem.setAttributeNS(null,"fill","#ff0000"),textElem.setAttributeNS(null,"style",` font: 5px Droid Sans, sans-serif; `),textElem.appendChild(document.createTextNode(text)),this.vertices.push(textElem)}drawRing(x,y,s){let circleElem=document.createElementNS("http://www.w3.org/2000/svg","circle"),radius=MathHelper.apothemFromSideLength(this.opts.bondLength,s);circleElem.setAttributeNS(null,"cx",x),circleElem.setAttributeNS(null,"cy",y),circleElem.setAttributeNS(null,"r",radius-this.opts.bondSpacing),circleElem.setAttributeNS(null,"stroke",this.themeManager.getColor("C")),circleElem.setAttributeNS(null,"stroke-width",this.opts.bondThickness),circleElem.setAttributeNS(null,"fill","none"),this.paths.push(circleElem)}drawLine(line,dashed=!1,gradient=null,linecap="round"){let opts=this.opts,stylesArr=[["stroke-width",this.opts.bondThickness],["stroke-linecap",linecap],["stroke-dasharray",dashed?"5, 5":"none"]],l=line.getLeftVector(),r=line.getRightVector(),fromX=l.x,fromY=l.y,toX=r.x,toY=r.y,styles=stylesArr.map(sub=>sub.join(":")).join(";"),lineElem=document.createElementNS("http://www.w3.org/2000/svg","line");lineElem.setAttributeNS(null,"x1",fromX),lineElem.setAttributeNS(null,"y1",fromY),lineElem.setAttributeNS(null,"x2",toX),lineElem.setAttributeNS(null,"y2",toY),lineElem.setAttributeNS(null,"style",styles),this.paths.push(lineElem),null==gradient&&(gradient=this.createGradient(line,fromX,fromY,toX,toY)),lineElem.setAttributeNS(null,"stroke",`url('#${gradient}')`)}drawPoint(x,y,elementName){let r=.75;x-rthis.maxX&&(this.maxX=x+r),y-rthis.maxY&&(this.maxY=y+r);let mask=document.createElementNS("http://www.w3.org/2000/svg","circle");mask.setAttributeNS(null,"cx",x),mask.setAttributeNS(null,"cy",y),mask.setAttributeNS(null,"r","1.5"),mask.setAttributeNS(null,"fill","black"),this.maskElements.push(mask);let point=document.createElementNS("http://www.w3.org/2000/svg","circle");point.setAttributeNS(null,"cx",x),point.setAttributeNS(null,"cy",y),point.setAttributeNS(null,"r",r),point.setAttributeNS(null,"fill",this.themeManager.getColor(elementName)),this.vertices.push(point)}drawText(x,y,elementName,hydrogens,direction,isTerminal,charge,isotope,totalVertices,attachedPseudoElement={}){let text=[],display=elementName;for(let key in 0!==charge&&null!==charge&&(display+=SvgWrapper.createUnicodeCharge(charge)),0!==isotope&&null!==isotope&&(display=SvgWrapper.createUnicodeSuperscript(isotope)+display),text.push([display,elementName]),1===hydrogens?text.push(["H","H"]):1this.maxX&&(this.maxX=x+bbox.width*text.length),x-bbox.width/2this.maxY&&(this.maxY=y+bbox.height)):("right"===direction?"left"!=direction&&(x+bbox.width*text.length>this.maxX&&(this.maxX=x+bbox.width*text.length),x-bbox.width/2this.maxX&&(this.maxX=x+bbox.width*text.length),x-bbox.width*text.lengththis.maxY&&(this.maxY=y+bbox.height),"down"===direction&&y+.8*bbox.height*text.length>this.maxY&&(this.maxY=y+.8*bbox.height*text.length),"up"===direction&&y-.8*bbox.height*text.length{const display=part[0],elementName=part[1];let tspanElem=document.createElementNS("http://www.w3.org/2000/svg","tspan");tspanElem.setAttributeNS(null,"fill",this.themeManager.getColor(elementName)),tspanElem.textContent=display,("up"===direction||"down"===direction)&&(tspanElem.setAttributeNS(null,"x","0px"),"up"===direction?tspanElem.setAttributeNS(null,"y",`-${.9*i}em`):tspanElem.setAttributeNS(null,"y",`${.9*i}em`)),textElem.appendChild(tspanElem)}),textElem.setAttributeNS(null,"data-direction",direction),"left"===direction||"right"===direction?(textElem.setAttributeNS(null,"dominant-baseline","alphabetic"),textElem.setAttributeNS(null,"y","0.36em")):textElem.setAttributeNS(null,"dominant-baseline","central"),"left"===direction&&textElem.setAttributeNS(null,"text-anchor","end"),g.appendChild(textElem),g.setAttributeNS(null,"style",`transform: translateX(${x}px) translateY(${y}px)`);let maskRadius=.75*this.opts.fontSizeLarge;1{result+=["\u2080","\u2081","\u2082","\u2083","\u2084","\u2085","\u2086","\u2087","\u2088","\u2089"][parseInt(d)]}),result}static createUnicodeSuperscript(n){let result="";return n.toString().split("").forEach(d=>{let parsed=parseInt(d);parsed&&(result+=["\u2070","\xB9","\xB2","\xB3","\u2074","\u2075","\u2076","\u2077","\u2078","\u2079"][parseInt(d)])}),result}static replaceNumbersWithSubscript(text){let subscriptNumbers={0:"\u2080",1:"\u2081",2:"\u2082",3:"\u2083",4:"\u2084",5:"\u2085",6:"\u2086",7:"\u2087",8:"\u2088",9:"\u2089"};for(const[key,value]of Object.entries(subscriptNumbers))text=text.replaceAll(key,value);return text}static measureText(text,fontSize,fontFamily,lineHeight=.9){const element=document.createElement("canvas"),ctx=element.getContext("2d");ctx.font=`${fontSize}pt ${fontFamily}`;let textMetrics=ctx.measureText(text),compWidth=_Mathabs6(textMetrics.actualBoundingBoxLeft)+_Mathabs6(textMetrics.actualBoundingBoxRight);return{width:textMetrics.width>compWidth?textMetrics.width:compWidth,height:(_Mathabs6(textMetrics.actualBoundingBoxAscent)+_Mathabs6(textMetrics.actualBoundingBoxAscent))*lineHeight}}static svgToCanvas(svg,canvas,width,height,callback=null){svg.setAttributeNS(null,"width",width),svg.setAttributeNS(null,"height",height);let image=new Image;return image.onload=function(){canvas.width=width,canvas.height=height;let context=canvas.getContext("2d");context.imageSmoothingEnabled=!1,context.drawImage(image,0,0,width,height),callback&&callback(canvas)},image.onerror=function(err){console.log(err)},image.src="data:image/svg+xml;charset-utf-8,"+encodeURIComponent(svg.outerHTML),canvas}static svgToImg(svg,img,width,height){let canvas=document.createElement("canvas");this.svgToCanvas(svg,canvas,width,height,()=>{img.src=canvas.toDataURL("image/png")})}static writeText(text,themeManager,fontSize,fontFamily,maxWidth=_NumberMAX_SAFE_INTEGER3){let svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),style=document.createElementNS("http://www.w3.org/2000/svg","style");style.appendChild(document.createTextNode(` .text { font: ${fontSize}pt ${fontFamily}; dominant-baseline: ideographic; } `)),svg.appendChild(style);let textElem=document.createElementNS("http://www.w3.org/2000/svg","text");textElem.setAttributeNS(null,"class","text");let maxLineWidth=0,totalHeight=0,lines=[];return text.split("\n").forEach(line=>{let dims=SvgWrapper.measureText(line,fontSize,fontFamily,1);if(dims.width>=maxWidth){let totalWordsWidth=0,maxWordsHeight=0,words=line.split(" "),offset=0;for(let i=0,wordDims;imaxWidth&&(lines.push({text:words.slice(offset,i).join(" "),width:totalWordsWidth,height:maxWordsHeight}),totalWordsWidth=0,maxWordsHeight=0,offset=i),wordDims.height>maxWordsHeight&&(maxWordsHeight=wordDims.height),totalWordsWidth+=wordDims.width;offset{totalHeight+=line.height;let tspanElem=document.createElementNS("http://www.w3.org/2000/svg","tspan");tspanElem.setAttributeNS(null,"fill",themeManager.getColor("C")),tspanElem.textContent=line.text,tspanElem.setAttributeNS(null,"x","0px"),tspanElem.setAttributeNS(null,"y",`${totalHeight}px`),textElem.appendChild(tspanElem),line.width>maxLineWidth&&(maxLineWidth=line.width)}),svg.appendChild(textElem),{svg:svg,width:maxLineWidth,height:totalHeight}}}module.exports=SvgWrapper},{"./Line":12,"./MathHelper":13,"./UtilityFunctions":27,"./Vector2":28}],26:[function(require,module){"use strict";module.exports=class{constructor(colors,theme){this.colors=colors,this.theme=this.colors[theme]}getColor(key){return key&&(key=key.toUpperCase(),key in this.theme)?this.theme[key]:this.theme.C}setTheme(theme){this.colors.hasOwnProperty(theme)&&(this.theme=this.colors[theme])}}},{}],27:[function(require,module){"use strict";module.exports={getChargeText:function(charge){return 1===charge?"+":2===charge?"2+":-1===charge?"-":-2===charge?"2-":""}}},{}],28:[function(require,module){"use strict";var _Mathsin5=Math.sin,_Mathcos5=Math.cos,_Mathacos=Math.acos,_Mathsqrt4=Math.sqrt;class Vector2{constructor(x,y){0==arguments.length?(this.x=0,this.y=0):1==arguments.length?(this.x=x.x,this.y=x.y):(this.x=x,this.y=y)}clone(){return new Vector2(this.x,this.y)}toString(){return"("+this.x+","+this.y+")"}add(vec){return this.x+=vec.x,this.y+=vec.y,this}subtract(vec){return this.x-=vec.x,this.y-=vec.y,this}divide(scalar){return this.x/=scalar,this.y/=scalar,this}multiply(v){return this.x*=v.x,this.y*=v.y,this}multiplyScalar(scalar){return this.x*=scalar,this.y*=scalar,this}invert(){return this.x=-this.x,this.y=-this.y,this}angle(){return Math.atan2(this.y,this.x)}distance(vec){return _Mathsqrt4((vec.x-this.x)*(vec.x-this.x)+(vec.y-this.y)*(vec.y-this.y))}distanceSq(vec){return(vec.x-this.x)*(vec.x-this.x)+(vec.y-this.y)*(vec.y-this.y)}clockwise(vec){let a=this.y*vec.x,b=this.x*vec.y;if(a>b)return-1;return a===b?0:1}relativeClockwise(center,vec){let a=(this.y-center.y)*(vec.x-center.x),b=(this.x-center.x)*(vec.y-center.y);if(a>b)return-1;return a===b?0:1}rotate(angle){let tmp=new Vector2(0,0),cosAngle=_Mathcos5(angle),sinAngle=_Mathsin5(angle);return tmp.x=this.x*cosAngle-this.y*sinAngle,tmp.y=this.x*sinAngle+this.y*cosAngle,this.x=tmp.x,this.y=tmp.y,this}rotateAround(angle,vec){let s=_Mathsin5(angle),c=_Mathcos5(angle);this.x-=vec.x,this.y-=vec.y;let x=this.x*c-this.y*s,y=this.x*s+this.y*c;return this.x=x+vec.x,this.y=y+vec.y,this}rotateTo(vec,center,offsetAngle=0){this.x+=.001,this.y-=.001;let a=Vector2.subtract(this,center),b=Vector2.subtract(vec,center),angle=Vector2.angle(b,a);return this.rotateAround(angle+offsetAngle,center),this}rotateAwayFrom(vec,center,angle){this.rotateAround(angle,center);let distSqA=this.distanceSq(vec);this.rotateAround(-2*angle,center);let distSqB=this.distanceSq(vec);distSqBdistSqA?angle:-angle}getRotateToAngle(vec,center){let a=Vector2.subtract(this,center),b=Vector2.subtract(vec,center),angle=Vector2.angle(b,a);return Number.isNaN(angle)?0:angle}isInPolygon(polygon){let inside=!1;for(let i=0,j=polygon.length-1;ithis.y!=polygon[j].y>this.y&&this.x<(polygon[j].x-polygon[i].x)*(this.y-polygon[i].y)/(polygon[j].y-polygon[i].y)+polygon[i].x&&(inside=!inside);return inside}length(){return _Mathsqrt4(this.x*this.x+this.y*this.y)}lengthSq(){return this.x*this.x+this.y*this.y}normalize(){return this.divide(this.length()),this}normalized(){return Vector2.divideScalar(this,this.length())}whichSide(vecA,vecB){return(this.x-vecA.x)*(vecB.y-vecA.y)-(this.y-vecA.y)*(vecB.x-vecA.x)}sameSideAs(vecA,vecB,vecC){let d=this.whichSide(vecA,vecB),dRef=vecC.whichSide(vecA,vecB);return 0>d&&0>dRef||0==d&&0==dRef||0this.neighbours.length?index=2:index=3),null===this.value.bracket.hcount&&0===ringbondIndex&&(index=1),null===this.value.bracket.hcount&&1===ringbondIndex&&(3>this.neighbours.length?index=1:index=2),this.neighbours.splice(index,0,vertexId)}else this.neighbours.push(vertexId);this.neighbourCount++}setParentVertexId(parentVertexId){this.neighbourCount++,this.parentVertexId=parentVertexId,this.neighbours.push(parentVertexId)}isTerminal(){return!!this.value.hasAttachedPseudoElements||null===this.parentVertexId&&2>this.children.length||0===this.children.length}clone(){let clone=new Vertex(this.value,this.position.x,this.position.y);return clone.id=this.id,clone.previousPosition=new Vector2(this.previousPosition.x,this.previousPosition.y),clone.parentVertexId=this.parentVertexId,clone.children=ArrayHelper.clone(this.children),clone.spanningTreeChildren=ArrayHelper.clone(this.spanningTreeChildren),clone.edges=ArrayHelper.clone(this.edges),clone.positioned=this.positioned,clone.angle=this.angle,clone.forcePositioned=this.forcePositioned,clone}equals(vertex){return this.id===vertex.id}getAngle(referenceVector=null,returnAsDegrees=!1){let u=null;return u=referenceVector?Vector2.subtract(this.position,referenceVector):Vector2.subtract(this.position,this.previousPosition),returnAsDegrees?MathHelper.toDeg(u.angle()):u.angle()}getTextDirection(vertices,onlyHorizontal=!1){let neighbours=this.getDrawnNeighbours(vertices),angles=[];if(1===vertices.length)return"right";for(let i=0;i