PageSourceSearch

https://notetube.ai/_next/static/chunks/7298.b7b5d26719d4da6e.js

js notetube.ai collected 2026-10-05 14:14:55 UTC 180,600 bytes, 1 lines download raw bytes

1!function(){try{var t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};t._sentryModuleMetadata=t._sentryModuleMetadata||{},t._sentryModuleMetadata[(new t.Error).stack]=function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];if(null!=i)for(var r in i)i.hasOwnProperty(r)&&(t[r]=i[r])}return t}({},t._sentryModuleMetadata[(new t.Error).stack],{"_sentryBundlerPluginAppKey:notetube-web":!0});var e=(new t.Error).stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="42598aff-18c9-4be1-90ce-f2c6c9c0ab76",t._sentryDebugIdIdentifier="sentry-dbid-42598aff-18c9-4be1-90ce-f2c6c9c0ab76")}catch(t){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7298],{37298:(t,e,i)=>{i.r(e),i.d(e,{default:()=>eL});class r{static clone(t){let e=Array.isArray(t)?[]:{};for(let i in t){let n=t[i];"function"==typeof n.clone?e[i]=n.clone():e[i]="object"==typeof n?r.clone(n):n}return e}static equals(t,e){if(t.length!==e.length)return!1;let i=t.slice().sort(),r=e.slice().sort();for(let t=0;t<i.length;t++)if(i[t]!==r[t])return!1;return!0}static print(t){if(0==t.length)return"";let e="(";for(let i=0;i<t.length;i++)e+=t[i].id?t[i].id+", ":t[i]+", ";return(e=e.substring(0,e.length-2))+")"}static each(t,e){for(let i=0;i<t.length;i++)e(t[i])}static get(t,e,i){for(let r=0;r<t.length;r++)if(t[r][e]==i)return t[r]}static contains(t,e){if(e.property||e.func){if(e.func){for(let i=0;i<t.length;i++)if(e.func(t[i]))return!0}else for(let i=0;i<t.length;i++)if(t[i][e.property]==e.value)return!0}else for(let i=0;i<t.length;i++)if(t[i]==e.value)return!0;return!1}static intersection(t,e){let i=[];for(let r=0;r<t.length;r++)for(let n=0;n<e.length;n++)t[r]===e[n]&&i.push(t[r]);return i}static unique(t){let e={};return t.filter(function(t){return void 0===e[t]&&(e[t]=!0)})}static count(t,e){let i=0;for(let r=0;r<t.length;r++)t[r]===e&&i++;return i}static toggle(t,e){let i=[],r=!1;for(let n=0;n<t.length;n++)t[n]!==e?i.push(t[n]):r=!0;return r||i.push(e),i}static remove(t,e){let i=[];for(let r=0;r<t.length;r++)t[r]!==e&&i.push(t[r]);return i}static removeUnique(t,e){let i=t.indexOf(e);return i>-1&&t.splice(i,1),t}static removeAll(t,e){return t.filter(function(t){return -1===e.indexOf(t)})}static merge(t,e){let i=Array(t.length+e.length);for(let e=0;e<t.length;e++)i[e]=t[e];for(let r=0;r<e.length;r++)i[t.length+r]=e[r];return i}static containsAll(t,e){let i=0;for(let r=0;r<t.length;r++)for(let n=0;n<e.length;n++)t[r]===e[n]&&i++;return i===e.length}static sortByAtomicNumberDesc(t){let e=t.map(function(t,e){return{index:e,value:t.atomicNumber.split(".").map(Number)}});return e.sort(function(t,e){let i=Math.min(e.value.length,t.value.length),r=0;for(;r<i&&e.value[r]===t.value[r];)r++;return r===i?e.value.length-t.value.length:e.value[r]-t.value[r]}),e.map(function(e){return t[e.index]})}static deepCopy(t){let e=[];for(let i=0;i<t.length;i++){let n=t[i];n instanceof Array?e[i]=r.deepCopy(n):e[i]=n}return e}}class n{addNeighbouringElement(t){this.neighbouringElements.push(t)}attachPseudoElement(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;null===i&&(i=0),null===r&&(r=0);let n=i+t+r;this.attachedPseudoElements[n]?this.attachedPseudoElements[n].count+=1:this.attachedPseudoElements[n]={element:t,count:1,hydrogenCount:i,previousElement:e,charge:r},this.hasAttachedPseudoElements=!0}getAttachedPseudoElements(){let t={};return Object.keys(this.attachedPseudoElements).sort().forEach(e=>{t[e]=this.attachedPseudoElements[e]}),t}getAttachedPseudoElementsCount(){return Object.keys(this.attachedPseudoElements).length}isHeteroAtom(){return"C"!==this.element&&"H"!==this.element}addAnchoredRing(t){r.contains(this.anchoredRings,{value:t})||this.anchoredRings.push(t)}getRingbondCount(){return this.ringbonds.length}backupRings(){this.originalRings=Array(this.rings.length);for(let t=0;t<this.rings.length;t++)this.originalRings[t]=this.rings[t]}restoreRings(){this.rings=Array(this.originalRings.length);for(let t=0;t<this.originalRings.length;t++)this.rings[t]=this.originalRings[t]}haveCommonRingbond(t,e){for(let i=0;i<t.ringbonds.length;i++)for(let r=0;r<e.ringbonds.length;r++)if(t.ringbonds[i].id==e.ringbonds[r].id)return!0;return!1}neighbouringElementsEqual(t){if(t.length!==this.neighbouringElements.length)return!1;t.sort(),this.neighbouringElements.sort();for(let e=0;e<this.neighbouringElements.length;e++)if(t[e]!==this.neighbouringElements[e])return!1;return!0}getAtomicNumber(){return n.atomicNumbers[this.element]}countImplicitHydrogens(){if(this.bracket)if(this.bracket.chirality)return 0;else return this.bracket.hcount||0;let t=this.bondCount;if(this.isPartOfAromaticRing){if("C"!==this.element)return 0;t+=1}let e=n.VALENCES[this.element];if(void 0===e)return 0;let i=e.find(e=>e>=t);return void 0!==i?i-t:0}static get atomicNumbers(){return{H:1,He:2,Li:3,Be:4,B:5,b:5,C:6,c:6,N:7,n:7,O:8,o:8,F:9,Ne:10,Na:11,Mg:12,Al:13,Si:14,P:15,p:15,S:16,s:16,Cl:17,Ar:18,K:19,Ca:20,Sc:21,Ti:22,V:23,Cr:24,Mn:25,Fe:26,
1Co:27,Ni:28,Cu:29,Zn:30,Ga:31,Ge:32,As:33,Se:34,Br:35,Kr:36,Rb:37,Sr:38,Y:39,Zr:40,Nb:41,Mo:42,Tc:43,Ru:44,Rh:45,Pd:46,Ag:47,Cd:48,In:49,Sn:50,Sb:51,Te:52,I:53,Xe:54,Cs:55,Ba:56,La:57,Ce:58,Pr:59,Nd:60,Pm:61,Sm:62,Eu:63,Gd:64,Tb:65,Dy:66,Ho:67,Er:68,Tm:69,Yb:70,Lu:71,Hf:72,Ta:73,W:74,Re:75,Os:76,Ir:77,Pt:78,Au:79,Hg:80,Tl:81,Pb:82,Bi:83,Po:84,At:85,Rn:86,Fr:87,Ra:88,Ac:89,Th:90,Pa:91,U:92,Np:93,Pu:94,Am:95,Cm:96,Bk:97,Cf:98,Es:99,Fm:100,Md:101,No:102,Lr:103,Rf:104,Db:105,Sg:106,Bh:107,Hs:108,Mt:109,Ds:110,Rg:111,Cn:112,Uut:113,Uuq:114,Uup:115,Uuh:116,Uus:117,Uuo:118}}constructor(t,e="-"){this.idx=null,this.element=1===t.length?t.toUpperCase():t,this.drawExplicit=!1,this.ringbonds=[],this.rings=[],this.bondType=e,this.branchBond=null,this.isBridge=!1,this.isBridgeNode=!1,this.originalRings=[],this.bridgedRing=null,this.anchoredRings=[],this.bracket=null,this.plane=0,this.attachedPseudoElements={},this.hasAttachedPseudoElements=!1,this.isDrawn=!0,this.isConnectedToRing=!1,this.neighbouringElements=[],this.isPartOfAromaticRing=t!==this.element,this.bondCount=0,this.chirality="",this.isStereoCenter=!1,this.priority=0,this.mainCh
1ain=!1,this.hydrogenDirection="down",this.subtreeDepth=1,this.hasHydrogen=!1,this.class=void 0}}n.VALENCES={H:[1],B:[3],C:[4],N:[3,5],O:[2],F:[1],P:[3,5],S:[2,4,6],Cl:[1],Br:[1],I:[1]};class s{static round(t,e){if(!e)return Math.round(t);{let i=Math.pow(10,e);return Math.round(t*i)/i}}static meanAngle(t){let e=0,i=0;for(let r=0;r<t.length;r++)e+=Math.sin(t[r]),i+=Math.cos(t[r]);return Math.atan2(e/t.length,i/t.length)}static innerAngle(t){return s.toRad((t-2)*180/t)}static polyCircumradius(t,e){return t/(2*Math.sin(Math.PI/e))}static apothem(t,e){return t*Math.cos(Math.PI/e)}static apothemFromSideLength(t,e){let i=s.polyCircumradius(t,e);return s.apothem(i,e)}static centralAngle(t){return s.toRad(360/t)}static toDeg(t){return t*s.degFactor}static toRad(t){return t*s.radFactor}static parityOfPermutation(t){let e=new Uint8Array(t.length),i=0,r=function(i){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return 1===e[i]?n:(n++,e[i]=1,r(t[i],n))};for(let n=0;n<t.length;n++)1!==e[n]&&(i+=1-r(n)%2);return i%2?-1:1}static get radFactor(){return Math.PI/180}static get degFactor(){return 180/Math.PI}static get twoPI(){return 2*Math.PI}}class l{clone(){return new l(this.x,this.y)}toString(){return"("+this.x+","+this.y+")"}add(t){return this.x+=t.x,this.y+=t.y,this}subtract(t){return this.x-=t.x,this.y-=t.y,this}divide(t){return this.x/=t,this.y/=t,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}invert(){return this.x=-this.x,this.y=-this.y,this}angle(){return Math.atan2(this.y,this.x)}distance(t){return Math.sqrt((t.x-this.x)*(t.x-this.x)+(t.y-this.y)*(t.y-this.y))}distanceSq(t){return(t.x-this.x)*(t.x-this.x)+(t.y-this.y)*(t.y-this.y)}clockwise(t){let e=this.y*t.x,i=this.x*t.y;return e>i?-1:+(e!==i)}relativeClockwise(t,e){let i=(this.y-t.y)*(e.x-t.x),r=(this.x-t.x)*(e.y-t.y);return i>r?-1:+(i!==r)}rotate(t){let e=new l(0,0),i=Math.cos(t),r=Math.sin(t);return e.x=this.x*i-this.y*r,e.y=this.x*r+this.y*i,this.x=e.x,this.y=e.y,this}rotateAround(t,e){let i=Math.sin(t),r=Math.cos(t);this.x-=e.x,this.y-=e.y;let n=this.x*r-this.y*i,s=this.x*i+this.y*r;return this.x=n+e.x,this.y=s+e.y,this}rotateTo(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;this.x+=.001,this.y-=.001;let r=l.subtract(this,e),n=l.subtract(t,e),s=l.angle(n,r);return this.rotateAround(s+i,e),this}rotateAwayFrom(t,e,i){this.rotateAround(i,e);let r=this.distanceSq(t);this.rotateAround(-2*i,e),this.distanceSq(t)<r&&this.rotateAround(2*i,e)}getRotateAwayFromAngle(t,e,i){let r=this.clone();r.rotateAround(i,e);let n=r.distanceSq(t);return(r.rotateAround(-2*i,e),r.distanceSq(t)<n)?i:-i}getRotateTowardsAngle(t,e,i){let r=this.clone();r.rotateAround(i,e);let n=r.distanceSq(t);return(r.rotateAround(-2*i,e),r.distanceSq(t)>n)?i:-i}getRotateToAngle(t,e){let i=l.subtract(this,e),r=l.subtract(t,e),n=l.angle(r,i);return Number.isNaN(n)?0:n}isInPolygon(t){let e=!1;for(let i=0,r=t.length-1;i<t.length;r=i++){let n=t[i],s=t[r];n.y>this.y!=s.y>this.y&&this.x<(s.x-n.x)*(this.y-n.y)/(s.y-n.y)+n.x&&(e=!e)}return e}length(){return Math.sqrt(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 l.divideScalar(this,this.length())}whichSide(t,e){return(this.x-t.x)*(e.y-t.y)-(this.y-t.y)*(e.x-t.x)}sameSideAs(t,e,i){let r=this.whichSide(t,e),n=i.whichSide(t,e);return r<0&&n<0||0==r&&0==n||r>0&&n>0}static add(t,e){return new l(t.x+e.x,t.y+e.y)}static subtract(t,e){return new l(t.x-e.x,t.y-e.y)}static multiply(t,e){return new l(t.x*e.x,t.y*e.y)}static multiplyScalar(t,e){return new l(t.x,t.y).multiplyScalar(e)}static midpoint(t,e){return new l((t.x+e.x)/2,(t.y+e.y)/2)}static normals(t,e){let i=l.subtract(e,t);return[new l(-i.y,i.x),new l(i.y,-i.x)]}static units(t,e){let i=l.subtract(e,t);return[new l(-i.y,i.x).normalize(),new l(i.y,-i.x).normalize()]}static divide(t,e){return new l(t.x/e.x,t.y/e.y)}static divideScalar(t,e){return new l(t.x/e,t.y/e)}static dot(t,e){return t.x*e.x+t.y*e.y}static angle(t,e){return Math.acos(l.dot(t,e)/(t.length()*e.length()))}static threePointangle(t,e,i){let r=l.subtract(e,t),n=l.subtract(i,e),s=t.distance(e),o=e.distance(i);
1return Math.acos(l.dot(r,n)/(s*o))}static scalarProjection(t,e){let i=e.normalized();return l.dot(t,i)}static averageDirection(t){let e=new l(0,0);for(let i=0;i<t.length;i++){let r=t[i];e.add(r)}return e.normalize()}constructor(t,e){0==arguments.length?(this.x=0,this.y=0):t instanceof l?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}}class o{setPosition(t,e){this.position.x=t,this.position.y=e}setPositionFromVector(t){this.position.x=t.x,this.position.y=t.y}addChild(t){this.children.push(t),this.neighbours.push(t),this.neighbourCount++}addRingbondChild(t,e){if(this.children.push(t),this.value.bracket){let i=1;0===this.id&&0===this.value.bracket.hcount&&(i=0),1===this.value.bracket.hcount&&0===e&&(i=2),1===this.value.bracket.hcount&&1===e&&(i=this.neighbours.length<3?2:3),null===this.value.bracket.hcount&&0===e&&(i=1),null===this.value.bracket.hcount&&1===e&&(i=this.neighbours.length<3?1:2),this.neighbours.splice(i,0,t)}else this.neighbours.push(t);this.neighbourCount++}setParentVertexId(t){this.neighbourCount++,this.parentVertexId=t,this.neighbours.push(t)}isTerminal(){return!!this.value.hasAttachedPseudoElements||null===this.parentVertexId&&this.children.length<2||0===this.children.length}clone(){let t=new o(this.value,this.position.x,this.position.y);return t.id=this.id,t.previousPosition=new l(this.previousPosition.x,this.previousPosition.y),t.parentVertexId=this.parentVertexId,t.children=r.clone(this.children),t.spanningTreeChildren=r.clone(this.spanningTreeChildren),t.edges=r.clone(this.edges),t.positioned=this.positioned,t.angle=this.angle,t.forcePositioned=this.forcePositioned,t}equals(t){return this.id===t.id}getAngle(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=null;return(i=t?l.subtract(this.position,t):l.subtract(this.position,this.previousPosition),e)?s.toDeg(i.angle()):i.angle()}getTextDirection(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=this.getDrawnNeighbours(t),r=[];if(1===t.length)return"right";for(let e=0;e<i.length;e++)r.push(this.getAngle(t[i[e]].position));let n=s.meanAngle(r);if(this.isTerminal()||e)Math.round(100*n)/100==1.57&&(n-=.2),n=Math.round(Math.round(n/Math.PI)*Math.PI);else{let t=Math.PI/2;n=Math.round(Math.round(n/t)*t)}return 2===n?"down":-2===n?"up":0===n?"right":3===n||-3===n?"left":"down"}getNeighbours(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(null===t)return this.neighbours.slice();let e=[];for(let i=0;i<this.neighbours.length;i++)this.neighbours[i]!==t&&e.push(this.neighbours[i]);return e}getDrawnNeighbours(t){let e=[];for(let i=0;i<this.neighbours.length;i++)t[this.neighbours[i]].value.isDrawn&&e.push(this.neighbours[i]);return e}getNeighbourCount(){return this.neighbourCount}getSpanningTreeNeighbours(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=[];for(let i=0;i<this.spanningTreeChildren.length;i++)(void 0===t||t!=this.spanningTreeChildren[i])&&e.push(this.spanningTreeChildren[i]);return null!=this.parentVertexId&&(void 0===t||t!=this.parentVertexId)&&e.push(this.parentVertexId),e}getNextInRing(t,e,i){let n=this.getNeighbours();for(let s=0;s<n.length;s++)if(r.contains(t[n[s]].value.rings,{value:e})&&n[s]!=i)return n[s];return null}constructor(t,e=0,i=0){this.id=null,this.value=t,this.position=new l(e||0,i||0),this.previousPosition=new l(0,0),this.parentVertexId=null,this.children=[],this.spanningTreeChildren=[],this.edges=[],this.positioned=!1,this.angle=null,this.dir=1,this.neighbourCount=0,this.neighbours=[],this.neighbouringElements=[],this.forcePositioned=!1}}class a{addVertex(t){this.vertices.add(t)}updateOther(t,e){this.firstRingId===e?this.secondRingId=t:this.firstRingId=t}containsRing(t){return this.firstRingId===t||this.secondRingId===t}isBridge(t){if(this.vertices.size>2)return!0;if(2===this.vertices.size){let[e,i]=[...this.vertices],r=new Set(t[i].neighbours);for(let n of t[e].neighbours)if(n!==i&&r.has(n)){let e=t[n].value.rings;if(e.includes(this.firstRingId)||e.includes(this.secondRingId))return!0}}return!1}static isBridge(t,e,i,r){let n=null;for(let s=0;s<t.length;s++)if((n=t[s]).firstRingId===i&&n.secondRingId===r||n.firstRingId===r&&n.secondRingId===i)return n.isBridge(e);return!1}static getNeighbours(t,e){let i=[];for(let r=0;r<t.length;r++){let n=t[r];n.firstRingId===e?i.push(n.secondRingId):n.secondRingId===e&&i.push(n.firstRingId)}return i}static getVertices(t,e,i){for(let r=0;r<t.length;r++){let n=t[r];
1if(n.firstRingId===e&&n.secondRingId===i||n.firstRingId===i&&n.secondRingId===e)return[...n.vertices]}}constructor(t,e){this.id=null,this.firstRingId=t.id,this.secondRingId=e.id,this.vertices=new Set;for(let i=0;i<t.members.length;i++){let r=t.members[i];for(let t=0;t<e.members.length;t++)r===e.members[t]&&this.addVertex(r)}}}class h{clone(){let t=new h(this.members);return t.id=this.id,t.insiders=r.clone(this.insiders),t.neighbours=r.clone(this.neighbours),t.positioned=this.positioned,t.center=this.center.clone(),t.rings=r.clone(this.rings),t.isBridged=this.isBridged,t.isPartOfBridged=this.isPartOfBridged,t.isSpiro=this.isSpiro,t.isFused=this.isFused,t.centralAngle=this.centralAngle,t.canFlip=this.canFlip,t}getSize(){return this.members.length}getPolygon(t){let e=[];for(let i=0;i<this.members.length;i++)e.push(t[this.members[i]].position);return e}getAngle(){return Math.PI-this.centralAngle}eachMember(t,e,i,r){let n=i=i||0===i?i:this.members[0],s=0;for(;null!=n&&s<100;){let l=n;e(l),n=t[n].getNextInRing(t,this.id,r),r=l,n==i&&(n=null),s++}}getOrderedNeighbours(t){let e=Array(this.neighbours.length);for(let i=0;i<this.neighbours.length;i++){let r=a.getVertices(t,this.id,this.neighbours[i]);e[i]={n:r.length,neighbour:this.neighbours[i]}}return e.sort((t,e)=>e.n-t.n),e}isBenzeneLike(t){let e=this.getDoubleBondCount(t),i=this.members.length;return 3===e&&6===i||2===e&&5===i}getDoubleBondCount(t){let e=0;for(let i=0;i<this.members.length;i++){let r=t[this.members[i]].value;("="===r.bondType||"="===r.branchBond)&&e++}return e}contains(t){for(let e=0;e<this.members.length;e++)if(this.members[e]==t)return!0;return!1}constructor(t){this.id=null,this.members=t,this.edges=[],this.insiders=[],this.neighbours=[],this.positioned=!1,this.center=new l(0,0),this.rings=[],this.isBridged=!1,this.isPartOfBridged=!1,this.isSpiro=!1,this.isFused=!1,this.centralAngle=0,this.canFlip=!0}}function g(t){return t?1===t?"+":-1===t?"-":t>0?t+"+":t+"-":""}class d{updateSize(t,e){this.ratio=window.devicePixelRatio||1,1!==this.ratio?(this.canvas.width=t*this.ratio,this.canvas.height=e*this.ratio,this.canvas.style.width=t+"px",this.canvas.style.height=e+"px",this.ctx.setTransform(this.ratio,0,0,this.ratio,0,0)):(this.canvas.width=t*this.ratio,this.canvas.height=e*this.ratio)}setTheme(t){this.colors=t}scale(t){let e=-Number.MAX_VALUE,i=-Number.MAX_VALUE,r=Number.MAX_VALUE,n=Number.MAX_VALUE;for(let s=0;s<t.length;s++){if(!t[s].value.isDrawn)continue;let l=t[s].position;e<l.x&&(e=l.x),i<l.y&&(i=l.y),r>l.x&&(r=l.x),n>l.y&&(n=l.y)}let s=this.opts.padding;e+=s,i+=s,r-=s,n-=s,this.drawingWidth=e-r,this.drawingHeight=i-n;let l=this.canvas.offsetWidth/this.drawingWidth,o=this.canvas.offsetHeight/this.drawingHeight,a=l<o?l:o;this.ctx.scale(a,a),this.offsetX=-r,this.offsetY=-n,l<o?this.offsetY+=this.canvas.offsetHeight/(2*a)-this.drawingHeight/2:this.offsetX+=this.canvas.offsetWidth/(2*a)-this.drawingWidth/2}reset(){this.ctx.setTransform(1,0,0,1,0,0)}getColor(t){return(t=t.toUpperCase())in this.colors?this.colors[t]:this.colors.C}drawCircle(t,e,i,r){let n=!(arguments.length>4)||void 0===arguments[4]||arguments[4],l=arguments.length>5&&void 0!==arguments[5]&&arguments[5],o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"",a=this.ctx,h=this.offsetX,g=this.offsetY;a.save(),a.lineWidth=1.5,a.beginPath(),a.arc(t+h,e+g,i,0,s.twoPI,!0),a.closePath(),l?(n?(a.fillStyle="#f00",a.fill()):(a.strokeStyle="#f00",a.stroke()),this.drawDebugText(t,e,o)):n?(a.fillStyle=r,a.fill()):(a.strokeStyle=r,a.stroke()),a.restore()}drawLine(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,r=this.ctx,n=this.offsetX,s=this.offsetY,l=t.clone().shorten(4),o=l.getLeftVector().clone(),a=l.getRightVector().clone();o.x+=n,o.y+=s,a.x+=n,a.y+=s,e||(r.save(),r.globalCompositeOperation="destination-out",r.beginPath(),r.moveTo(o.x,o.y),r.lineTo(a.x,a.y),r.lineCap="round",r.lineWidth=this.opts.bondThickness+1.2,r.strokeStyle=this.themeManager.getColor("BACKGROUND"),r.stroke(),r.globalCompositeOperation="source-over",r.restore(
1)),o=t.getLeftVector().clone(),a=t.getRightVector().clone(),o.x+=n,o.y+=s,a.x+=n,a.y+=s,r.save(),r.beginPath(),r.moveTo(o.x,o.y),r.lineTo(a.x,a.y),r.lineCap="round",r.lineWidth=this.opts.bondThickness;let h=this.ctx.createLinearGradient(o.x,o.y,a.x,a.y);h.addColorStop(.4,this.themeManager.getColor(t.getLeftElement())||this.themeManager.getColor("C")),h.addColorStop(.6,this.themeManager.getColor(t.getRightElement())||this.themeManager.getColor("C")),e&&(r.setLineDash([1,1.5]),r.lineWidth=this.opts.bondThickness/1.5),i<1&&(r.globalAlpha=i),r.strokeStyle=h,r.stroke(),r.restore()}drawWedge(t){if(arguments.length>1&&void 0!==arguments[1]&&arguments[1],isNaN(t.from.x)||isNaN(t.from.y)||isNaN(t.to.x)||isNaN(t.to.y))return;let e=this.ctx,i=this.offsetX,r=this.offsetY,n=t.clone().shorten(5),s=n.getLeftVector().clone(),o=n.getRightVector().clone();s.x+=i,s.y+=r,o.x+=i,o.y+=r,s=t.getLeftVector().clone(),o=t.getRightVector().clone(),s.x+=i,s.y+=r,o.x+=i,o.y+=r,e.save();let a=l.normals(s,o);a[0].normalize(),a[1].normalize();let h=t.getRightChiral(),g=s,d=o;h&&(g=o,d=s);let u=l.add(g,l.multiplyScalar(a[0],this.halfBondThickness)),c=l.add(d,l.multiplyScalar(a[0],1.5+this.halfBondThickness)),f=l.add(d,l.multiplyScalar(a[1],1.5+this.halfBondThickness)),p=l.add(g,l.multiplyScalar(a[1],this.halfBondThickness));e.beginPath(),e.moveTo(u.x,u.y),e.lineTo(c.x,c.y),e.lineTo(f.x,f.y),e.lineTo(p.x,p.y);let m=this.ctx.createRadialGradient(o.x,o.y,this.opts.bondLength,o.x,o.y,0);m.addColorStop(.4,this.themeManager.getColor(t.getLeftElement())||this.themeManager.getColor("C")),m.addColorStop(.6,this.themeManager.getColor(t.getRightElement())||this.themeManager.getColor("C")),e.fillStyle=m,e.fill(),e.restore()}drawDashedWedge(t){let e,i,r,n;if(isNaN(t.from.x)||isNaN(t.from.y)||isNaN(t.to.x)||isNaN(t.to.y))return;let s=this.ctx,o=this.offsetX,a=this.offsetY,h=t.getLeftVector().clone(),g=t.getRightVector().clone();h.x+=o,h.y+=a,g.x+=o,g.y+=a,s.save();let d=l.normals(h,g);d[0].normalize(),d[1].normalize();let u=t.getRightChiral(),c=t.clone();u?(e=g,i=h,c.shortenRight(1),r=c.getRightVector().clone(),n=c.getLeftVector().clone()):(e=h,i=g,c.shortenLeft(1),r=c.getLeftVector().clone(),n=c.getRightVector().clone()),r.x+=o,r.y+=a,n.x+=o,n.y+=a;let f=l.subtract(i,e).normalize();s.strokeStyle=this.themeManager.getColor("C"),s.lineCap="round",s.lineWidth=this.opts.bondThickness,s.beginPath();let p=t.getLength(),m=1.25/(p/(3*this.opts.bondThickness)),b=!1;for(let i=0;i<1;i+=m){let r=l.multiplyScalar(f,i*p),n=l.add(e,r),o=1.5*i,a=l.multiplyScalar(d[0],o);!b&&i>.5&&(s.stroke(),s.beginPath(),s.strokeStyle=this.themeManager.getColor(t.getRightElement())||this.themeManager.getColor("C"),b=!0),n.subtract(a),s.moveTo(n.x,n.y),n.add(l.multiplyScalar(a,2)),s.lineTo(n.x,n.y)}s.stroke(),s.restore()}drawDebugText(t,e,i){let r=this.ctx;r.save(),r.font="5px Droid Sans, sans-serif",r.textAlign="start",r.textBaseline="top",r.fillStyle="#ff0000",r.fillText(i,t+this.offsetX,e+this.offsetY),r.restore()}drawBall(t,e,i){let r=this.ctx;r.save(),r.beginPath(),r.arc(t+this.offsetX,e+this.offsetY,this.opts.bondLength/4.5,0,s.twoPI,!1),r.fillStyle=this.themeManager.getColor(i),r.fill(),r.restore()}drawPoint(t,e,i){let r=this.ctx,n=this.offsetX,l=this.offsetY;r.save(),r.globalCompositeOperation="destination-out",r.beginPath(),r.arc(t+n,e+l,1.5,0,s.twoPI,!0),r.closePath(),r.fill(),r.globalCompositeOperation="source-over",r.beginPath(),r.arc(t+this.offsetX,e+this.offsetY,.75,0,s.twoPI,!1),r.fillStyle=this.themeManager.getColor(i),r.fill(),r.restore()}drawText(t,e,i,r,n,l,o,a,h){let d=arguments.length>9&&void 0!==arguments[9]?arguments[9]:{},u=this.ctx,c=this.offsetX,f=this.offsetY;u.save(),u.textAlign="start",u.textBaseline="alphabetic";let p="",m=0;o&&(p=g(o),u.font=this.fontSmall,m=u.measureText(p).width);let b="0",v=0;a>0&&(b=a.toString(),u.font=this.fontSmall,v=u.measureText(b).width),1===o&&"N"===i&&"0O"in d&&"0O-1"in d&&(d={"0O":{element:"O",count:2,hydrogenCount:0,previousElement:"C",charge:""}},o=0),u.font=this.fontLarge,u.fillStyle=this.themeManager.getColor("BACKGROUND");let w=u.measureText(i),y=w.width>this.opts.fontSizeLarge?w.width:this.opts.fontSizeLarge;y/=1.5,u.globalCompositeOperation="destination-out",u.beginPath(),u.arc(t+c,e+f,y,0,s.twoPI,!0),u.closePath(),u.fill(),u.globalCompositeOperation="source-over";let S=-w.width/2,x=-w.width/2;u.fillStyle=this.themeManager.getColor(i),u.fillText(i,t+c+S,e+this.opts.halfFontSizeLarge+f),S+=w.width,o&&(u.font=this.fontSmall,u.fillText(p,t+c+S,e-this.opts.fifthFontSizeSmall+f),S+=m),a>0&&(u.font=this.fontSmall,u.fillText(b,t+c+x-v,e-this.opts.fifthFontSizeSmall+f),x-=v),u.font=this.fontLarge;let A=0,C=0;if(1===r){let i=t+c,r=e+f+this.opts.halfFontSizeLarge;x-=A=this.hydrogenWidth,"left"===n?i+=x:"right"===n||"up"===n&&l||"down"===n&&l?i+=S:"up"!==n||l?"down"!==n||l||(r+=this.opts.fontSizeLarge+this.opts.quarterFontSizeLarge,i-=this.halfHydrogenWidth):(r-=this.opts.fontSizeLarge+this.opts.quarterFontSizeLarge,i-=this.halfHydrogenWidth),u.fillText("H",i,r),S+=A}else if(r>1){let i=t+c,s=e+f+this.opts.halfFontSizeLarge;A=this.hydrogenWidth,u.font=this.fontSmall,x-=A+(C=u.measureText(r.toString()).width),"left"===n?i+=x:"right"===n||"up"===n&&l||"down"===n&&l?i+=S:"up"!==n||l?"down"!==n||l||(s+=this.opts.fontSizeLarge+this.opts.quarterFontSizeLarge,i-=this.halfHydrogenWidth):(s-=this.opts.fontSizeLarge+this.opts.quarterFontSizeLarge,i-=this.halfHydrogenWidth),u.font=this.fontLarge,u.fillText("H",i,s),u.font=this.fontSmall,u.fillText(r.toString(),i+this.halfHydrogenWidth+C,s+this.opts.fifthFontSizeSmall),S+=A+this.halfHydrogenWidth+C}for(let i of Object.keys(d)){let r=0,s=0,l=d[i].element,o=d[i].count,a=d[i].hydrogenCount,h=d[i].charge;u.font=this.fontLarge,o>1&&a>0&&(r=u.measureText("(").width,s=u.measureText(")").width);let p=u.measureText(l).width,m=0,b="",v=0;A=0,a>0&&(A=this.hydrogenWidth),u.font=this.fontSmall,o>1&&(m=u.measureText(o).width),0!==h&&(b=g(h),v=u.measureText(b).width),C=0,a>1&&(C=u.measureText(a).width),u.font=this.fontLarge;let w=t+c,y=e+f+this.opts.halfFontSizeLarge;u.fillStyle=this.themeManager.getColor(l),o>0&&(x-=m),o>1&&a>0&&("left"===n?(x-=s,u.fillText(")",w+x,y)):(u.fillText("(",w+S,y),S+=r)),"left"===n?(x-=p,u.fillText(l,w+x,y)):(u.fillText(l,w+S,y),S+=p),a>0&&("left"===n?(x-=A+C,u.fillText("H",w+x,y),a>1&&(u.font=this.fontSmall,u.fillText(a,w+x+A,y+this.opts.fifthFontSizeSmall))):(u.fillText("H",w+S,y),S+=A,a>1&&(u.font=this.fontSmall,u.fillText(a,w+S,y+this.opts.fifthFontSizeSmall),S+=C))),u.font=this.fontLarge,o>1&&a>0&&("left"===n?(x-=r,u.fillText("(",w+x,y)):(u.fillText(")",w+S,y),S+=s)),u.font=this.fontSmall,o>1&&("left"===n?u.fillText(o,w+x+r+s+A+C+p,y+this.opts.fifthFontSizeSmall):(u.fillText(o,w+S,y+this.opts.fifthFontSizeSmall),S+=m)),0!==h&&("left"===n?u.fillText(b,
1w+x+r+s+A+C+p,e-this.opts.fifthFontSizeSmall+f):(u.fillText(b,w+S,e-this.opts.fifthFontSizeSmall+f),S+=v))}u.restore()}drawDebugPoint(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"#f00";this.drawCircle(t,e,2,r,!0,!0,i)}drawAromaticityRing(t){let e=this.ctx,i=s.apothemFromSideLength(this.opts.bondLength,t.getSize());e.save(),e.strokeStyle=this.themeManager.getColor("C"),e.lineWidth=this.opts.bondThickness,e.beginPath(),e.arc(t.center.x+this.offsetX,t.center.y+this.offsetY,i-this.opts.bondSpacing,0,2*Math.PI,!0),e.closePath(),e.stroke(),e.restore()}clear(){this.ctx.clearRect(0,0,this.canvas.offsetWidth,this.canvas.offsetHeight)}constructor(t,e,i){let r=null;if((r=t instanceof String?document.getElementById(t.valueOf()):"string"==typeof t?document.getElementById(t):t)instanceof HTMLCanvasElement)this.canvas=r;else throw Error("First argument was not a canvas or the ID of a canvas.");this.ctx=this.canvas.getContext("2d"),this.themeManager=e,this.opts=i,this.drawingWidth=0,this.drawingHeight=0,this.offsetX=0,this.offsetY=0,this.fontLarge=this.opts.fontSizeLarge+"pt Helvetica, Arial, sans-serif",this.fontSmall=this.opts.fontSizeSmall+"pt Helvetica, Arial, sans-serif",this.updateSize(this.opts.width,this.opts.height),this.ctx.font=this.fontLarge,this.hydrogenWidth=this.ctx.measureText("H").width,this.halfHydrogenWidth=this.hydrogenWidth/2,this.halfBondThickness=this.opts.bondThickness/2}}class u{static build(t,e){let i=new u(t,e,null,new Map);return i.findChildren(),i.sortChildren(),i}static compareAtoms(t,e){if(t.atomicNumber!==e.atomicNumber)return[e.atomicNumber-t.atomicNumber,!1];if(t.cloneDepth&&e.cloneDepth){let i=t.cloneDepth-e.cloneDepth;if(0!==i)return[i,!1]}return t.atomicWeight!==e.atomicWeight?[e.atomicWeight-t.atomicWeight,!1]:[0,t.stereocenter||e.stereocenter]}static compareTrees(t,e){let i=this.compareAtoms(t,e);if(0!==i[0])return i;let r=[t],n=[e],s=!1;for(;0!==r.length;){for(let t=0;t<r.length;++t){let e=r[t].findChildren(),l=n[t].findChildren(),o=Math.max(e.length,l.length);for(let t=0;t<o;++t){if(t>=e.length)return[1,!1];if(t>=l.length)return[-1,!1];if(0!==(i=this.compareAtoms(e[t],l[t]))[0])return i;s||(s=i[1])}}r=r.flatMap(t=>t.sortChildren()),n=n.flatMap(t=>t.sortChildren())}return[0,s]}findChildren(){if(void 0===this.children){this.children=[];let t=this.visited.size+1,e=new Map(this.visited);for(let i of(e.set(this.vertex,t),this.visited=null,this.vertex.neighbours)){let r=this.graph.getEdge(this.vertex.id,i).weight;if(!r)continue;let n=this.graph.vertices[i],s=e.get(n);if(Object.is(n,this.parent))r-=1;else if(void 0===s){let i=new u(this.graph,n,this.vertex,e);this.children.push(i),s=t+1,r-=1}if(r>0){let t=new u(this.graph,n,this.vertex,s);for(;r-- >0;)this.children.push(t)}}if(this.vertex.value.isPartOfAromaticRing){let t=new u(this.graph,6,this.vertex);this.children.push(t)}let i=this.vertex.value.countImplicitHydrogens();if(i>0){let t=new u(this.graph,1,this.vertex);for(;i-- >0;)this.children.push(t)}this.children.sort((t,e)=>u.compareAtoms(t,e)[0])}return this.children}size(){return void 0!==this.children?this.children.reduce((t,e)=>t+e.size(),1):1}sortChildren(){return this.sorted||(this.children.sort((t,e)=>{let[i,r]=u.compareTrees(t,e);if(r&&this.stereocenter)if("@"===this.vertex.value.bracket.chirality)return e.vertex.id-t.vertex.id;else return t.vertex.id-e.vertex.id;return i}),this.sorted=!0),this.children}constructor(t,e,i,r){this.graph=t,this.parent=i,e instanceof o?(this.vertex=e,this.atomicNumber=e.value.getAtomicNumber(),this.atomicWeight=0,this.stereocenter=!!(e.value.bracket&&e.value.bracket.chirality)):(this.vertex=null,this.atomicNumber=e,this.atomicWeight=0,this.stereocenter=!1),r instanceof Map?(this.cloneDepth=void 0,this.visited=r,this.children=void 0,this.sorted=!1):(this.cloneDepth=r,this.visited=null,this.children=[],this.sorted=!0,this.stereocenter=!1)}}class c{static getOrderArray(t,e){let i=u.build(t,e);for(let t=1;t<i.children.length;++t){let e=u.compareTrees(i.children[t-1],i.children[t]);if(0===e[0]&&!e[1])return}let r=e.neighbours.length,n=new Uint8Array(r);for(let t=0;t<r;++t){let r=i.children[t].vertex.id;n[t]=e.neighbours.findIndex(t=>t===r)}return n}}class f{setBondType(t){this.bondType=t,this.weight=f.bonds[t]}static get bonds(){return{".":0,"-":1,"/":1,"\\":1,"=":2,"#":3,$:4}}constructor(t,e,i=1){this.id=null,this.sourceId=t,this.targetId=e,this.weight=i,this.bondType="-",this.isPartOfAromaticRing=!1,this.center=!1,this.wedge=""}}
1class p{_init(t){arguments.length>1&&void 0!==arguments[1]&&arguments[1];let e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],r=t.atom.element?t.atom.element:t.atom,s=new n(r,t.bond);("H"!==r||!t.hasNext&&null===e)&&(s.idx=this._atomIdx,this._atomIdx++),s.branchBond=t.branchBond,s.ringbonds=t.ringbonds,s.bracket=t.atom.element?t.atom:null,s.class=t.atom.class;let l=new o(s),a=this.vertices[e];if(this.addVertex(l),null!==s.idx&&this.atomIdxToVertexId.push(l.id),null!==e){l.setParentVertexId(e),l.value.addNeighbouringElement(a.value.element),a.addChild(l.id),a.value.addNeighbouringElement(s.element),a.spanningTreeChildren.push(l.id);let t=new f(e,l.id,1);i?t.setBondType(l.value.branchBond||"-"):t.setBondType(a.value.bondType||"-"),this.addEdge(t)}let h=t.ringbondCount+1;s.bracket&&(h+=s.bracket.hcount);let g=0;if(s.bracket&&s.bracket.chirality){s.isStereoCenter=!0,g=s.bracket.hcount;for(let t=0;t<g;t++)this._init({atom:"H",isBracket:"false",branches:[],branchCount:0,ringbonds:[],ringbondCount:!1,next:null,hasNext:!1,bond:"-"},t,l.id,!0)}for(let e=0;e<t.branchCount;e++)this._init(t.branches[e],e+h,l.id,!0);t.hasNext&&this._init(t.next,t.branchCount+h,l.id)}clear(){this.vertices=[],this.edges=[],this.vertexIdsToEdgeId={}}addVertex(t){return t.id=this.vertices.length,this.vertices.push(t),t.id}addEdge(t){let e=this.vertices[t.sourceId],i=this.vertices[t.targetId];return t.id=this.edges.length,this.edges.push(t),this.vertexIdsToEdgeId[t.sourceId+"_"+t.targetId]=t.id,this.vertexIdsToEdgeId[t.targetId+"_"+t.sourceId]=t.id,t.isPartOfAromaticRing=e.value.isPartOfAromaticRing&&i.value.isPartOfAromaticRing,e.value.bondCount+=t.weight,i.value.bondCount+=t.weight,e.edges.push(t.id),i.edges.push(t.id),t.id}getEdge(t,e){let i=this.vertexIdsToEdgeId[t+"_"+e];return void 0===i?null:this.edges[i]}getEdges(t){let e=[],i=this.vertices[t];for(let r=0;r<i.neighbours.length;r++)e.push(this.vertexIdsToEdgeId[t+"_"+i.neighbours[r]]);return e}hasEdge(t,e){return void 0!==this.vertexIdsToEdgeId[t+"_"+e]}getVertexList(){let t=[this.vertices.length];for(let e=0;e<this.vertices.length;e++)t[e]=this.vertices[e].id;return t}getEdgeList(){let t=Array(this.edges.length);for(let e=0;e<this.edges.length;e++)t[e]=[this.edges[e].sourceId,this.edges[e].targetId];return t}getAdjacencyMatrix(){let t=this.vertices.length,e=Array(t);for(let i=0;i<t;i++)e[i]=Array(t),e[i].fill(0);for(let t=0;t<this.edges.length;t++){let i=this.edges[t];e[i.sourceId][i.targetId]=1,e[i.targetId][i.sourceId]=1}return e}getComponentsAdjacencyMatrix(){let t=this.vertices.length,e=Array(t),i=this.getBridges();for(let i=0;i<t;i++)e[i]=Array(t),e[i].fill(0);for(let t=0;t<this.edges.length;t++){let i=this.edges[t];e[i.sourceId][i.targetId]=1,e[i.targetId][i.sourceId]=1}for(let t=0;t<i.length;t++)e[i[t][0]][i[t][1]]=0,e[i[t][1]][i[t][0]]=0;return e}getSubgraphAdjacencyMatrix(t){let e=t.length,i=Array(e);for(let r=0;r<e;r++){i[r]=Array(e),i[r].fill(0);for(let n=0;n<e;n++)r!==n&&this.hasEdge(t[r],t[n])&&(i[r][n]=1)}return i}getDistanceMatrix(){let t=this.vertices.length,e=this.getAdjacencyMatrix(),i=Array(t);for(let e=0;e<t;e++)i[e]=Array(t),i[e].fill(1/0);for(let r=0;r<t;r++)for(let n=0;n<t;n++)1===e[r][n]&&(i[r][n]=1);for(let e=0;e<t;e++)for(let r=0;r<t;r++)for(let n=0;n<t;n++)i[r][n]>i[r][e]+i[e][n]&&(i[r][n]=i[r][e]+i[e][n]);return i}getSubgraphDistanceMatrix(t){let e=t.length,i=this.getSubgraphAdjacencyMatrix(t),r=Array(e);for(let t=0;t<e;t++)r[t]=Array(e),r[t].fill(1/0),r[t][t]=0;for(let t=0;t<e;t++)for(let n=0;n<e;n++)1===i[t][n]&&(r[t][n]=1);for(let t=0;t<e;t++)for(let i=0;i<e;i++)for(let n=0;n<e;n++)r[i][n]>r[i][t]+r[t][n]&&(r[i][n]=r[i][t]+r[t][n]);return r}getAdjacencyList(){let t=this.vertices.length,e=Array(t);for(let i=0;i<t;i++){e[i]=[];for(let r=0;r<t;r++)i!==r&&this.hasEdge(this.vertices[i].id,this.vertices[r].id)&&e[i].push(r)}return e}getSubgraphAdjacencyList(t){let e=t.length,i=Array(e);for(let r=0;r<e;r++){i[r]=[];for(let n=0;n<e;n++)r!==n&&this.hasEdge(t[r],t[n])&&i[r].push(n)}return i}getBridgedRingPerimeter(t,e,i){let r=new Set(e.insiders||[]),n=t.filter(t=>!r.has(t));if(n.length<3)return n;let s=new Set(n),l=new Map;for(let t=0;t<n.length;t++){let e=n[t],i=this.vertices[e].neighbours.filter(t=>s.has(t));if(l.set(e,i),2!==i.length)return n}let o=s.has(i)?i:n[0],a=[o],h=null,g=o;for(;a.length<n.length;){let t=l.get(g).filter(t=>t!==h);if(null===h&&t.sort((t,e)=>this.vertices[t].value.smilesOrder-this.vertices[e].value.smilesOrder),0===t.length)return n;let e=t[0];if(e===o)return n;a.push(e),h=g,g=e}return l.get(g).includes(o)?a:n}getBridges(){let t=this.vertices.length,e=Array(t),i=Array(t),r=Array(t),n=Array(t),s=this.getAdjacencyList(),l=[];e.fill(!1),n.fill(null),this._time=0;for(let o=0;o<t;o++)e[o]||this._bridgeDfs(o,e,i,r,n,s,l);return l}traverseBF(t,e){let i=Array(this.vertices.length);i.fill(!1);let r=[t];for(;r.length>0;){let t=r.shift(),n=this.vertices[t];e(n);for(let t=0;t<n.neighbours.length;t++){let e=n.neighbours[t];
1i[e]||(i[e]=!0,r.push(e))}}}getTreeDepth(t,e){if(null===t||null===e)return 0;let i=this.vertices[t].getSpanningTreeNeighbours(e),r=0;for(let e=0;e<i.length;e++){let n=i[e],s=this.getTreeDepth(n,t);s>r&&(r=s)}return r+1}traverseTree(t,e,i){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:999999,n=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:1,l=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null;if(null===l&&(l=new Uint8Array(this.vertices.length)),s>r+1||1===l[t])return;l[t]=1;let o=this.vertices[t],a=o.getNeighbours(e);(!n||s>1)&&i(o);for(let e=0;e<a.length;e++)this.traverseTree(a[e],t,i,r,n,s+1,l)}kkLayout(t,e,i,r,n){let o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:.1,a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:.1,h=arguments.length>7&&void 0!==arguments[7]?arguments[7]:2e3,g=arguments.length>8&&void 0!==arguments[8]?arguments[8]:50,d=arguments.length>9&&void 0!==arguments[9]?arguments[9]:1e9,u=this.getSubgraphDistanceMatrix(t),c=t.length,f=s.polyCircumradius(n,c),p=s.centralAngle(c),m=0,b=new Float32Array(c),v=new Float32Array(c),w=Array(c),y=new Set(r.insiders||[]),S=this.getBridgedRingPerimeter(t,r,i),x=new Set(S),A=S.length,C=A>2?s.polyCircumradius(n,A):f,N=A>0?2*Math.PI/A:p,R=0,E=new Map;if(x.has(i)){let t=S.indexOf(i),r=this.vertices[i];r.positioned&&(R=l.subtract(r.position,e).angle()-t*N)}for(let t=0;t<S.length;t++){let i=S[t],r=this.vertices[i];if(r.positioned)E.set(i,r.position.clone());else{let r=new l(e.x+Math.cos(R+t*N)*C,e.y+Math.sin(R+t*N)*C);E.set(i,r)}}let I=t.filter(t=>y.has(t)),M=Math.max(.35*n,.35*C);for(let t=0;t<I.length;t++){let i=I[t],r=this.vertices[i];if(r.positioned){E.set(i,r.position.clone());continue}let n=r.neighbours.filter(t=>x.has(t)),s=new l(e.x,e.y);if(n.length>0){s=new l(0,0);for(let t=0;t<n.length;t++)s.add(E.get(n[t]));s.divide(n.length);let i=l.subtract(s,e);1e-4>i.lengthSq()?i=new l(Math.cos(t*N),Math.sin(t*N)):i.normalize(),s=i.multiplyScalar(M).add(e.clone())}else s.x+=Math.cos(t*N)*M,s.y+=Math.sin(t*N)*M;E.set(i,s)}for(var k=c;k--;){let i=this.vertices[t[k]];if(i.positioned)b[k]=i.position.x,v[k]=i.position.y;else{let t=E.get(i.id);t?(b[k]=t.x,v[k]=t.y):(b[k]=e.x+Math.cos(m)*f,v[k]=e.y+Math.sin(m)*f)}w[k]=i.positioned,m+=p}let T=Array(c);for(k=c;k--;){T[k]=Array(c);let t=c;for(;t--;)T[k][t]=n*u[k][t]}let B=Array(c);for(k=c;k--;){B[k]=Array(c);let t=c;for(;t--;)B[k][t]=n*Math.pow(u[k][t],-2)}let L=Array(c),O=new Float32Array(c),D=new Float32Array(c);for(k=c;k--;)L[k]=Array(c);for(k=c;k--;){let t=b[k],e=v[k],i=0,r=0,n=c;for(;n--;){if(k===n)continue;let s=b[n],l=v[n],o=1/Math.sqrt((t-s)*(t-s)+(e-l)*(e-l));L[k][n]=[B[k][n]*(t-s-T[k][n]*(t-s)*o),B[k][n]*(e-l-T[k][n]*(e-l)*o)],L[n][k]=L[k][n],i+=L[k][n][0],r+=L[k][n][1]}O[k]=i,D[k]=r}let P=function(t){return[O[t]*O[t]+D[t]*D[t],O[t],D[t]]},z=0,F=0,H=0,_=0,W=0,V=0;for(;d>o&&h>W;)for(W++,[z,d,F,H]=function(){let t=0,e=0,i=0,r=0;for(k=c;k--;){let[n,s,l]=P(k);n>t&&!1===w[k]&&(t=n,e=k,i=s,r=l)}return[e,t,i,r]}(),_=d,V=0;_>a&&g>V;)V++,function(t,e,i){let r,s,l=0,o=0,a=0,h=b[t],g=v[t],d=T[t],u=B[t];for(k=c;k--;){if(k===t)continue;let e=b[k],i=v[k],r=d[k],n=u[k],s=(h-e)*(h-e),c=1/Math.pow(s+(g-i)*(g-i),1.5);l+=n*(1-r*(g-i)*(g-i)*c),o+=n*(1-r*s*c),a+=r*(h-e)*(g-i)*c*n}0===l&&(l=.1),0===o&&(o=.1),0===a&&(a=.1);let f=a/l-o/a;1e-6>Math.abs(f)?(s=-(.1*e),r=-(.1*i)):(r=(e/l+i/a)/f,s=-(a*r+e)/l);let p=Math.sqrt(s*s+r*r);if(p>n){let t=n/p;s*=t,r*=t}b[t]+=s,v[t]+=r;let m=L[t];for(e=0,i=0,h=b[t],g=v[t],k=c;k--;){if(t===k)continue;let n=b[k],l=v[k],o=m[k][0],a=m[k][1],c=1/Math.sqrt((h-n)*(h-n)+(g-l)*(g-l));s=u[k]*(h-n-d[k]*(h-n)*c),r=u[k]*(g-l-d[k]*(g-l)*c),m[k]=[s,r],e+=s,i+=r,O[k]+=s-o,D[k]+=r-a}O[t]=e,D[t]=i}(z,F,H),[_,F,H]=P(z);for(k=c;k--;){let e=t[k],i=this.vertices[e];i.position.x=b[k],i.position.y=v[k],i.positioned=!0,i.forcePositioned=!0}}_bridgeDfs(t,e,i,r,n,s,l){e[t]=!0,i[t]=r[t]=++this._time;for(let o=0;o<s[t].length;o++){let a=s[t][o];e[a]?a!==n[t]&&(r[t]=Math.min(r[t],i[a])):(n[a]=t,this._bridgeDfs(a,e,i,r,n,s,l),r[t]=Math.min(r[t],r[a]),r[a]>i[t]&&l.push([t,a]))}}static getConnectedComponents(t){let e=t.length,i=Array(e),r=[];i.fill(!1);for(let n=0;n<e;n++)if(!i[n]){let e=[];i[n]=!0,e.push(n),p._ccGetDfs(n,i,t,e),e.length>1&&r.push(e)}return r}static getConnectedComponentCount(t){let e=t.length,i=Array(e),r=0;i.fill(!1);for(let n=0;n<e;n++)i[n]||(i[n]=!0,r++,p._ccCountDfs(n,i,t));return r}static _ccCountDfs(t,e,i){for(let r=0;r<i[t].length;r++)i[t][r]&&!e[r]&&t!==r&&(e[r]=!0,p._ccCountDfs(r,e,i))}static _ccGetDfs(t,e,i,r){for(let n=0;n<i[t].length;n++)i[t][n]&&!e[n]&&t!==n&&(e[n]=!0,r.push(n),p._ccGetDfs(n,e,i,r))}constructor(t,e=!1){this.vertices=[],this.edges=[],this.atomIdxToVertexId=[],this.vertexIdsToEdgeId={},this.isomeric=e,this._atomIdx=0,this._time=0,this._init(t)}}class m{clone(){return new m(this.from.clone(),this.to.clone(),this.elementFrom,this.elementTo)}getLength(){let t=this.to.x-this.from.x,e=this.to.y-this.from.y;return Math.sqrt(t*t+e*e)}getAngle(){return l.subtract(this.getRightVector(),this.getLeftVector()).angle()}getRightVector(){return this.from.x<this.to.x?this.to:this.from}getLeftVector(){return this.from.x<this.to.x?this.from:this.to}getRightElement(){return this.from.x<this.to.x?this.elementTo:this.elementFrom}getLeftElement(){return this.from.x<this.to.x?this.elementFrom:this.elementTo}getRightChiral(){return this.from.x<this.to.x?this.chiralTo:this.chiralFrom}getLeftChiral(){return this.from.x<this.to.x?this.chiralFrom:this.chiralTo}setRightVector(t,e){return this.from.x<this.to.x?(this.to.x=t,this.to.y=e):(this.from.x=t,this.from.y=e),this}setLeftVector(t,e){return this.from.x<this.to.x?(this.from.x=t,this.from.y=e):(this.to.x=t,this.to.y=e),this}rotateToXAxis(){let t=this.getLeftVector();return this.setRightVector(t.x+this.getLength(),t.y),this}rotate(t){let e=this.getLeftVector(),i=this.getRightVector(),r=Math.sin(t),n=Math.cos(t),s=n*(i.x-e.x)-r*(i.y-e.y)+e.x,l=r*(i.x-e.x)-n*(i.y-e.y)+e.
1y;return this.setRightVector(s,l),this}shortenFrom(t){let e=l.subtract(this.to,this.from);return e.normalize(),e.multiplyScalar(t),this.from.add(e),this}shortenTo(t){let e=l.subtract(this.from,this.to);return e.normalize(),e.multiplyScalar(t),this.to.add(e),this}shortenRight(t){return this.from.x<this.to.x?this.shortenTo(t):this.shortenFrom(t),this}shortenLeft(t){return this.from.x<this.to.x?this.shortenFrom(t):this.shortenTo(t),this}shorten(t){let e=l.subtract(this.from,this.to);return e.normalize(),e.multiplyScalar(t/2),this.to.add(e),this.from.subtract(e),this}constructor(t=new l(0,0),e=new l(0,0),i=null,r=null,n=!1,s=!1){this.from=t,this.to=e,this.elementFrom=i,this.elementTo=r,this.chiralFrom=n,this.chiralTo=s}}class b{static extend(){let t={},e=!1,i=0,r=arguments.length;for("[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(e=arguments[0],i++);i<r;i++){let r=arguments[i];for(let i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e&&"[object Object]"===Object.prototype.toString.call(r[i])?t[i]=b.extend(!0,t[i],r[i]):t[i]=r[i])}return t}}class v{static getRings(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=t.getComponentsAdjacencyMatrix();if(0===i.length)return[];let r=p.getConnectedComponents(i),n=[];for(let i=0;i<r.length;i++){let s=r[i],l=t.getSubgraphAdjacencyMatrix([...s]),o=new Uint16Array(l.length),a=new Uint16Array(l.length);for(let t=0;t<l.length;t++){a[t]=0,o[t]=0;for(let e=0;e<l[t].length;e++)o[t]+=l[t][e]}let h=0;for(let t=0;t<l.length;t++)for(let e=t+1;e<l.length;e++)h+=l[t][e];let g=h-l.length+1;if(1===g){n.push([...s]);continue}e&&(g=999);let{d,pe:u,pe_prime:c}=v.getPathIncludedDistanceMatrices(l),f=v.getRingCandidates(d,u,c),p=v.getSSSR(f,d,l,u,c,o,a,g);if(p.length<g){let t=v.findMissingRings(l,p,g);for(let e=0;e<t.length;e++)p.push(t[e])}for(let t=0;t<p.length;t++){let e=Array(p[t].size),i=0;for(let r of p[t])e[i++]=s[r];n.push(e)}}return n}static matrixToString(t){let e="";for(let i=0;i<t.length;i++){for(let r=0;r<t[i].length;r++)e+=t[i][r]+" ";e+="\n"}return e}static getPathIncludedDistanceMatrices(t){let e=t.length,i=Array(e),r=Array(e),n=Array(e);var s=0,l=0,o=0,a=0,h=0,g=0;for(s=e;s--;)for(i[s]=Array(e),r[s]=Array(e),n[s]=Array(e),l=e;l--;)i[s][l]=s===l||1===t[s][l]?t[s][l]:1/0,1===i[s][l]?r[s][l]=[[[s,l]]]:r[s][l]=[],n[s][l]=[];for(o=e;o--;)for(s=e;s--;)for(l=e;l--;){let t=i[s][l],e=i[s][o]+i[o][l];if(t>e){if(t===e+1)for(n[s][l]=[r[s][l].length],a=r[s][l].length;a--;)for(n[s][l][a]=[r[s][l][a].length],h=r[s][l][a].length;h--;)for(n[s][l][a][h]=[r[s][l][a][h].length],g=r[s][l][a][h].length;g--;)n[s][l][a][h][g]=[r[s][l][a][h][0],r[s][l][a][h][1]];else n[s][l]=[];for(i[s][l]=e,r[s][l]=[[]],a=r[s][o][0].length;a--;)r[s][l][0].push(r[s][o][0][a]);for(a=r[o][l][0].length;a--;)r[s][l][0].push(r[o][l][0][a])}else if(t===e){if(r[s][o].length&&r[o][l].length)if(r[s][l].length){let t=[];for(a=r[s][o][0].length;a--;)t.push(r[s][o][0][a]);for(a=r[o][l][0].length;a--;)t.push(r[o][l][0][a]);r[s][l].push(t)}else{let t=[];for(a=r[s][o][0].length;a--;)t.push(r[s][o][0][a]);for(a=r[o][l][0].length;a--;)t.push(r[o][l][0][a]);r[s][l][0]=t}}else if(t===e-1)if(n[s][l].length){let t=[];for(a=r[s][o][0].length;a--;)t.push(r[s][o][0][a]);for(a=r[o][l][0].length;a--;)t.push(r[o][l][0][a]);n[s][l].push(t)}else{let t=[];for(a=r[s][o][0].length;a--;)t.push(r[s][o][0][a]);for(a=r[o][l][0].length;a--;)t.push(r[o][l][0][a]);n[s][l][0]=t}}return{d:i,pe:r,pe_prime:n}}static getRingCandidates(t,e,i){let r=t.length,n=[],s=0;for(let l=0;l<r;l++)for(let o=0;o<r;o++)if(0===t[l][o]||1===e[l][o].length&&0===i[l][o])continue;else(s=0!==i[l][o].length?2*(t[l][o]+.5):2*t[l][o])!=1/0&&n.push([s,e[l][o],i[l][o]]);return n.sort(function(t,e){return t[0]-e[0]}),n}static getSSSR(t,e,i,r,n,s,l,o){let a=[],h=[];for(let e=0;e<t.length;e++)if(t[e][0]%2!=0)for(let r=0;r<t[e][2].length;r++){let n=t[e][1][0].concat(t[e][2][r]);for(let t=0;t<n.length;t++)n[t][0].constructor===Array&&(n[t]=n[t][0]);let g=v.bondsToAtoms(n);if(v.getBondCount(g,i)!==g.size||v.pathSetsContain(a,g,n,h,s,l)||(a.push(g),h=h.concat(n)),a.length>=o)return a}else for(let r=0;r<t[e][1].length-1;r++){let n=t[e][1][r].concat(t[e][1][r+1]);for(let t=0;t<n.length;t++)n[t][0].constructor===Array&&(n[t]=n[t][0]);let g=v.bondsToAtoms(n);
1if(v.getBondCount(g,i)!==g.size||v.pathSetsContain(a,g,n,h,s,l)||(a.push(g),h=h.concat(n)),a.length>=o)return a}return a}static getEdgeCount(t){let e=0,i=t.length;for(var r=i-1;r--;)for(var n=i;n--;)1===t[r][n]&&e++;return e}static getEdgeList(t){let e=t.length,i=[];for(var r=e-1;r--;)for(var n=e;n--;)1===t[r][n]&&i.push([r,n]);return i}static bondsToAtoms(t){let e=new Set;for(var i=t.length;i--;)e.add(t[i][0]),e.add(t[i][1]);return e}static getBondCount(t,e){let i=0;for(let r of t)for(let n of t)r!==n&&(i+=e[r][n]);return i/2}static pathSetsContain(t,e,i,r,n,s){for(var l=t.length;l--;){if(v.isSupersetOf(e,t[l]))return!0;if(t[l].size===e.size&&v.areSetsEqual(t[l],e))return!0}let o=0,a=!1;for(l=i.length;l--;)for(var h=r.length;h--;)(i[l][0]===r[h][0]&&i[l][1]===r[h][1]||i[l][1]===r[h][0]&&i[l][0]===r[h][1])&&o++,o===i.length&&(a=!0);let g=!1;if(a){for(let t of e)if(s[t]<n[t]){g=!0;break}}if(a&&!g)return!0;for(let t of e)s[t]++;return!1}static areSetsEqual(t,e){if(t.size!==e.size)return!1;for(let i of t)if(!e.has(i))return!1;return!0}static isSupersetOf(t,e){for(let i of e)if(!t.has(i))return!1;return!0}static findMissingRings(t,e,i){let r=t.length,n=[],s=new Set;for(let i of e){let e=[...i];for(let i=0;i<e.length;i++)for(let r=i+1;r<e.length;r++)if(1===t[e[i]][e[r]]){let t=Math.min(e[i],e[r]),n=Math.max(e[i],e[r]);s.add(t+","+n)}}for(let l=0;l<r;l++)for(let o=l+1;o<r;o++){if(1!==t[l][o])continue;let a=l+","+o;if(s.has(a))continue;let h=v.bfsShortestCycle(t,l,o,r);if(null!==h){let r=new Set(h),l=!1;for(let t of e)if(v.areSetsEqual(r,t)){l=!0;break}for(let t of n)if(v.areSetsEqual(r,t)){l=!0;break}if(!l){n.push(r);let l=[...r];for(let e=0;e<l.length;e++)for(let i=e+1;i<l.length;i++)if(1===t[l[e]][l[i]]){let t=Math.min(l[e],l[i]),r=Math.max(l[e],l[i]);s.add(t+","+r)}if(e.length+n.length>=i)return n}}}return n}static bfsShortestCycle(t,e,i,r){let n=Array(r).fill(!1),s=Array(r).fill(-1),l=[e];for(n[e]=!0;l.length>0;){let o=l.shift();for(let a=0;a<r;a++)if(1===t[o][a]&&(o!==e||a!==i)&&(o!==i||a!==e)){if(a===i){let t=[i],e=o;for(;-1!==e;)t.push(e),e=s[e];return t}n[a]||(n[a]=!0,s[a]=o,l.push(a))}}return null}}class w{getColor(t){return t&&(t=t.toUpperCase())in this.theme?this.theme[t]:this.theme.C}setTheme(t){t in this.colors&&(this.theme=this.colors[t])}constructor(t,e){this.colors=t,this.theme=this.colors[e]}}class y{static getEffectiveShowCarbonsMode(t){let e=t.showCarbons;return((null==e||-1===["none","default","terminal","acyclic","all"].indexOf(e))&&(e="default"),"default"===e&&t.terminalCarbons)?"terminal":e}draw(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"light",r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];this.initDraw(t,i,r),this.infoOnly||(this.themeManager=new w(this.opts.themes,i),this.canvasWrapper=new d(e,this.themeManager,this.opts)),!r&&(this.processGraph(),this.canvasWrapper.scale(this.graph.vertices),this.drawEdges(this.opts.debug),this.drawVertices(this.opts.debug),this.canvasWrapper.reset(),this.opts.debug&&console.debug("DrawerBase::draw()",{graph:this.graph,rings:this.rings,ringConnections:this.ringConnections}))}edgeRingCount(t){let e=this.graph.edges[t],i=this.graph.vertices[e.sourceId],r=this.graph.vertices[e.targetId];return Math.min(i.value.rings.length,r.value.rings.length)}getBridgedRings(){return this.rings.filter(t=>t.isBridged)}getFusedRings(){return this.rings.filter(t=>t.isFused)}getSpiros(){return this.rings.filter(t=>t.isSpiro)}printRingInfo(){let t="";for(let e=0;e<this.rings.length;e++){let i=this.rings[e];t+=i.id+";"+i.members.length+";"+i.neighbours.length+";"+(i.isSpiro?"true;":"false;")+(i.isFused?"true;":"false;")+(i.isBridged?"true;":"false;")+i.rings.length+";\n"}return t}rotateDrawing(){let t=0,e=0,i=0;for(let r=0;r<this.graph.vertices.length;r++){let n=this.graph.vertices[r];if(n.value.isDrawn)for(let s=r+1;s<this.graph.vertices.length;s++){let l=this.graph.vertices[s];if(!l.value.isDrawn)continue;let o=n.position.distanceSq(l.position);o>i&&(i=o,t=r,e=s)}}let r=-l.subtract(this.graph.vertices[t].position,this.graph.vertices[e].position).angle();if(!isNaN(r)){let t=r%.523599;
1t<.2617995?r-=t:r+=.523599-t;for(let t=0;t<this.graph.vertices.length;t++)t!==e&&this.graph.vertices[t].position.rotateAround(r,this.graph.vertices[e].position);for(let t=0;t<this.rings.length;t++)this.rings[t].center.rotateAround(r,this.graph.vertices[e].position)}}getTotalOverlapScore(){return this.totalOverlapScore}getRingCount(){return this.rings.length}hasBridgedRing(){return this.bridgedRing}getHeavyAtomCount(){let t=0;for(let e=0;e<this.graph.vertices.length;e++)"H"!==this.graph.vertices[e].value.element&&t++;return t}getMolecularFormula(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e="",i=new Map,r=null===t?this.graph:new p(t,this.opts.isomeric);for(let t=0;t<r.vertices.length;t++){let e=r.vertices[t].value,n=i.get(e.element)||0;i.set(e.element,n+1);let s=e.countImplicitHydrogens();if(s){let t=i.get("H")||0;i.set("H",t+s)}}if(i.has("C")){let t=i.get("C");e+="C"+(t>1?t:""),i.delete("C")}if(i.has("H")){let t=i.get("H");e+="H"+(t>1?t:""),i.delete("H")}return Object.keys(n.atomicNumbers).sort().map(t=>{if(i.has(t)){let r=i.get(t);e+=t+(r>1?r:"")}}),e}getRingbondType(t,e){if(1>t.value.getRingbondCount()||1>e.value.getRingbondCount())return null;for(let i=0;i<t.value.ringbonds.length;i++)for(let r=0;r<e.value.ringbonds.length;r++)if(t.value.ringbonds[i].id===e.value.ringbonds[r].id)if("-"===t.value.ringbonds[i].bondType)return e.value.ringbonds[r].bond;else return t.value.ringbonds[i].bond;return null}initDraw(t,e,i,r){this.data=t,this.infoOnly=i,this.ringIdCounter=0,this.ringConnectionIdCounter=0,this.graph=new p(t,this.opts.isomeric),this.rings=[],this.ringConnections=[],this.originalRings=[],this.originalRingConnections=[],this.bridgedRing=!1,this.doubleBondConfigCount=null,this.doubleBondConfig=null,this.highlight_atoms=r,this.initRings(),this.initHydrogens()}processGraph(){this.position(),this.fixDoubleBondStereo(),this.restoreRingInformation(),this.resolvePrimaryOverlaps();let t=this.getOverlapScore();this.totalOverlapScore=this.getOverlapScore().total;for(let e=0;e<this.opts.overlapResolutionIterations;e++)for(let e=0;e<this.graph.edges.length;e++){let i=this.graph.edges[e];if(this.isEdgeRotatable(i)){let e=this.graph.getTreeDepth(i.sourceId,i.targetId),r=this.graph.getTreeDepth(i.targetId,i.sourceId),n=i.targetId,l=i.sourceId;if(e>r&&(n=i.sourceId,l=i.targetId),this.getSubtreeOverlapScore(l,n,t.vertexScores).value>this.opts.overlapSensitivity){let e=this.graph.vertices[n],i=this.graph.vertices[l],r=i.getNeighbours(n);if(1===r.length){let t=this.graph.vertices[r[0]],n=t.position.getRotateAwayFromAngle(e.position,i.position,s.toRad(120));this.rotateSubtree(t.id,i.id,n,i.position);let l=this.getOverlapScore().total;l>this.totalOverlapScore?this.rotateSubtree(t.id,i.id,-n,i.position):this.totalOverlapScore=l}else if(2===r.length){if(0!==i.value.rings.length&&0!==e.value.rings.length)continue;let t=this.graph.vertices[r[0]],n=this.graph.vertices[r[1]];if(1===t.value.rings.length&&1===n.value.rings.length){if(t.value.rings[0]!==n.value.rings[0])continue;let r=t.value.rings[0];if(1!==this.getRingExternalConnectionCount(r))continue;let l=0,o=this.totalOverlapScore,a=this.getRing(r),h=s.centralAngle(a.getSize()),g=Math.max(1,Math.floor(a.getSize()/2));for(let t=1;t<=g;t++){let r=h*t;this.rotateSubtree(i.id,e.id,r,i.position);let n=this.getOverlapScore().total;n<o&&(o=n,l=r),this.rotateSubtree(i.id,e.id,-r,i.position),this.rotateSubtree(i.id,e.id,-r,i.position),(n=this.getOverlapScore().total)<o&&(o=n,l=-r),this.rotateSubtree(i.id,e.id,r,i.position)}0!==l&&(this.rotateSubtree(i.id,e.id,l,i.position),this.totalOverlapScore=o)}else{if(0!==t.value.rings.length||0!==n.value.rings.length)continue;let r=t.position.getRotateAwayFromAngle(e.position,i.position,s.toRad(120)),l=n.position.getRotateAwayFromAngle(e.position,i.position,s.toRad(120));this.rotateSubtree(t.id,i.id,r,i.position),this.rotateSubtree(n.id,i.id,l,i.position);let o=this.getOverlapScore().total;o>this.totalOverlapScore?(this.rotateSubtree(t.id,i.id,-r,i.position),this.rotateSubtree(n.id,i.id,-l,i.position)):this.totalOverlapScore=o}}t=this.getOverlapScore()}}}this.resolveSecondaryOverlaps(t.scores),this.resolveRigidRingOverlaps(),t=this.getOverlapScore(),this.resolveSecondaryOverlaps(t.scores),this.opts.isomeric&&this.annotateStereochemistry(),this.opts.compactDrawing&&"default"===this.opts.atomVisualization&&this.initPseudoElements(),this.rotateDrawing()}initRings(){let t=new Map;for(let e=this.graph.vertices.length-1;e>=0;e--){let i=this.graph.vertices[e];if(0!==i.value.ringbonds.length)for(let e=0;e<i.value.ringbonds.length;e++){let r=i.value.ringbonds[e].id,n=i.value.ringbonds[e].bond;if(t.has(r)){let s=i.id,l=t.get(r)[0],o=t.get(r)[1],a=new f(s,l,1);a.setBondType(o||n||"-");let h=this.graph.addEdge(a),g=this.graph.vertices[l];i.addRingbondChild(l,e),i.value.addNeighbouringElement(g.value.element);let d=0;for(let t=0;t<g.value.ringbonds.length;t++)if(g.value.ringbonds[t].id===r){d=t;break}g.addRingbondChild(s,d),g.value.addNeighbouringElement(i.value.element),i.edges.push(h),g.edges.push(h),t.delete(r)}else t.set(r,[i.id,n])}}let e=v.getRings(this.graph,this.opts.experimentalSSSR);if(null!==e&&0!==e.length){for(let t=0;t<e.length;t++){let i=[...e[t]],r=this.addRing(new h(i));for(let t=0;t<i.length;t++)this.graph.vertices[i[t]].value.rings.push(r)}for(let t=0;t<this.rings.length-1;t++)for(let e=t+1;e<this.rings.length;e++){let i=new a(this.rings[t],this.rings[e]);i.vertices.size>0&&this.addRingConnection(i)}for(let t=0;t<this.rings.length;t++){let e=this.rings[t];e.neighbours=a.getNeighbours(this.ringConnections,e.id)}for(let t=0;t<this.rings.length;t++){let e=this.rings[t];this.graph.vertices[e.members[0]].value.addAnchoredRing(e.id)}for(this.backupRingInformation();this.rings.length>0;){let t=-1;for(let e=0;e<this.rings.length;e++){let i=this.rings[e];this.isPartOfBridgedRing(i.id)&&!i.isBridged&&(t=i.id)}if(-1===t)break;let e=this.getRing(t),i=this.getBridgedRingRings(e.id);this.bridgedRing=!0,this.createBridgedRing(i,e.members[0]),this.bridgedRing=!1;for(let t=0;t<i.length;t++)this.removeRing(i[t])}}}initHydrogens(){if(!this.opts.explicitHydrogens)for(let t=0;t<this.graph.vertices.length;t++){let e=this.graph.vertices[t];if("H"!==e.value.element)continue;let i=this.graph.vertices[e.neighbours[0]];i.value.hasHydrogen=!0,(!i.value.isStereoCenter||i.value.rings.length<2&&!i.value.bridgedRing||i.value.bridgedRing&&i.value.originalRings.length<2)&&(e.value.isDrawn=!1)}}getBridgedRingRings(t){let e=[],i=t=>{let r=this.getRing(t);e.push(t);for(let n=0;n<r.neighbours.length;n++){let s=r.neighbours[n];-1===e.indexOf(s)&&s!==t&&a.isBridge(this.ringConnections,this.graph.vertices,t,s)&&i(s)}};i(t);let n=!0;for(;n;){n=!1;for(let t=0;t<this.ringConnections.length;t++){let i=this.ringConnections[t];if(i.vertices.size<2)continue;let r=-1!==e.indexOf(i.firstRingId),s=-1!==e.indexOf(i.secondRingId);r&&!s?(e.push(i.secondRingId),n=!0):s&&!r&&(e.push(i.firstRingId),n=!0)}}return r.unique(e)}isPartOfBridgedRing(t){for(let e=0;e<this.ringConnections.length;e++)if(this.ringConnections[e].containsRing(t)&&this.ringConnections[e].isBridge(this.graph.vertices))return!0;return!1}createBridgedRing(t,e){let i=new Set,n=new Set,s=new Set;for(let e=0;e<t.length;e++){let i=this.getRing(t[e]);i.isPartOfBridged=!0;for(let t=0;t<i.members.length;t++)n.add(i.members[t]);for(let e=0;e<i.neighbours.length;e++){let r=i.neighbours[e];-1===t.indexOf(r)&&s.add(i.neighbours[e])}}let l=new Set;for(let e of n){let n=this.graph.vertices[e],s=r.intersection(t,n.value.rings);1===n.value.rings.length||1===s.length?i.add(n.id):l.add(n.id)}let o=[];for(let t of l){let e=this.graph.vertices[t],r=!1;for(let t=0;t<e.edges.length;t++)1===this.edgeRingCount(e.edges[t])&&(r=!0);r?e.value.isBridgeNode=!0:(e.value.isBridge=!0,o.push(e.id)),i.add(e.id)}let a=new h([...i]);this.addRing(a),a.isBridged=!0,a.insiders=o,a.neighbours=[...s];for(let e=0;e<t.length;e++)a.rings.push(this.getRing(t[e]).clone());for(let t=0;t<a.members.length;t++)this.graph.vertices[a.members[t]].value.bridgedRing=a.id;for(let t=0;t<o.length;t++)this.graph.vertices[o[t]].value.rings=[];for(let e of i){let i=this.graph.vertices[e];i.value.rings=r.removeAll(i.value.rings,t),i.value.rings.push(a.id)}for(let e=0;e<t.length;e++)for(let i=e+1;i<t.length;i++)this.removeRingConnectionsBetween(t[e],t[i]);for(let e of s){let i=this.getRingConnections(e,t);for(let t=0;t<i.length;t++)this.getRingConnection(i[t]).updateOther(a.id,e);this.getRing(e).neighbours.push(a.id)}return a}
1areVerticesInSameRing(t,e){for(let i=0;i<t.value.rings.length;i++)for(let r=0;r<e.value.rings.length;r++)if(t.value.rings[i]===e.value.rings[r])return!0;return!1}getCommonRings(t,e){let i=[];for(let r=0;r<t.value.rings.length;r++)for(let n=0;n<e.value.rings.length;n++)t.value.rings[r]==e.value.rings[n]&&i.push(t.value.rings[r]);return i}getLargestOrAromaticCommonRing(t,e){let i=this.getCommonRings(t,e),r=0,n=null;for(let t=0;t<i.length;t++){let e=this.getRing(i[t]),s=e.getSize();if(e.isBenzeneLike(this.graph.vertices))return e;s>r&&(r=s,n=e)}return n}getVerticesAt(t,e,i){let r=[];for(let n=0;n<this.graph.vertices.length;n++){let s=this.graph.vertices[n];s.id!==i&&s.positioned&&t.distanceSq(s.position)<=e*e&&r.push(s.id)}return r}getClosestVertex(t){let e=99999,i=null;for(let r=0;r<this.graph.vertices.length;r++){let n=this.graph.vertices[r];if(n.id===t.id)continue;let s=t.position.distanceSq(n.position);s<e&&(e=s,i=n)}return i}addRing(t){return t.id=this.ringIdCounter++,this.rings.push(t),t.id}removeRing(t){this.rings=this.rings.filter(function(e){return e.id!==t}),this.ringConnections=this.ringConnections.filter(function(e){return e.firstRingId!==t&&e.secondRingId!==t});for(let e=0;e<this.rings.length;e++){let i=this.rings[e];i.neighbours=i.neighbours.filter(function(e){return e!==t})}}getRing(t){for(let e=0;e<this.rings.length;e++)if(this.rings[e].id==t)return this.rings[e]}addRingConnection(t){return t.id=this.ringConnectionIdCounter++,this.ringConnections.push(t),t.id}removeRingConnection(t){this.ringConnections=this.ringConnections.filter(function(e){return e.id!==t})}removeRingConnectionsBetween(t,e){let i=[];for(let r=0;r<this.ringConnections.length;r++){let n=this.ringConnections[r];(n.firstRingId===t&&n.secondRingId===e||n.firstRingId===e&&n.secondRingId===t)&&i.push(n.id)}for(let t=0;t<i.length;t++)this.removeRingConnection(i[t])}getRingConnection(t){for(let e=0;e<this.ringConnections.length;e++)if(this.ringConnections[e].id==t)return this.ringConnections[e]}getRingConnections(t,e){let i=[];for(let r=0;r<this.ringConnections.length;r++){let n=this.ringConnections[r];for(let r=0;r<e.length;r++){let s=e[r];(n.firstRingId===t&&n.secondRingId===s||n.firstRingId===s&&n.secondRingId===t)&&i.push(n.id)}}return i}getOverlapScore(){let t=0,e=new Float32Array(this.graph.vertices.length);for(let t=0;t<this.graph.vertices.length;t++)e[t]=0;for(let i=0;i<this.graph.vertices.length;i++){let r=this.graph.vertices.length;for(;--r>i;){let n=this.graph.vertices[i],s=this.graph.vertices[r];if(!n.value.isDrawn||!s.value.isDrawn)continue;let o=l.subtract(n.position,s.position).lengthSq();if(o<this.opts.bondLengthSq){let n=(this.opts.bondLength-Math.sqrt(o))/this.opts.bondLength;t+=n,e[i]+=n,e[r]+=n}}}let i=[];for(let t=0;t<this.graph.vertices.length;t++)i.push({id:t,score:e[t]});return i.sort(function(t,e){return e.score-t.score}),{total:t,scores:i,vertexScores:e}}chooseSide(t,e,i){let n=t.getNeighbours(e.id),s=e.getNeighbours(t.id),l=n.length,o=s.length,a=r.merge(n,s),h=[0,0];for(let r=0;r<a.length;r++)this.graph.vertices[a[r]].position.sameSideAs(t.position,e.position,i[0])?h[0]++:h[1]++;let g=[0,0];for(let r=0;r<this.graph.vertices.length;r++)this.graph.vertices[r].position.sameSideAs(t.position,e.position,i[0])?g[0]++:g[1]++;return{totalSideCount:g,totalPosition:g[0]>g[1]?0:1,sideCount:h,position:h[0]>h[1]?0:1,anCount:l,bnCount:o}}setRingCenter(t){let e=t.getSize(),i=new l(0,0);for(let r=0;r<e;r++)i.add(this.graph.vertices[t.members[r]].position);t.center=i.divide(e)}getSubringCenter(t,e){let i=e.value.originalRings,r=t.center,n=Number.MAX_VALUE;for(let e=0;e<i.length;e++)for(let s=0;s<t.rings.length;s++)i[e]===t.rings[s].id&&t.rings[s].getSize()<n&&(r=t.rings[s].center,n=t.rings[s].getSize());return r}drawEdges(t){let e=Array(this.graph.edges.length);if(e.fill(!1),this.graph.traverseBF(0,i=>{let r=this.graph.getEdges(i.id);for(let i=0;i<r.length;i++){let n=r[i];e[n]||(e[n]=!0,this.drawEdge(n,t))}}),!this.bridgedRing)for(let t=0;t<this.rings.length;t++){let e=this.rings[t];this.isRingAromatic(e)&&this.canvasWrapper.drawAromaticityRing(e)}}drawEdge(t,e){let i=this.graph.edges[t],n=this.graph.vertices[i.sourceId],s=this.graph.vertices[i.targetId],o=n.value.element,a=s.value.element;if((!n.value.isDrawn||!s.value.isDrawn)&&"default"===this.opts.atomVisualization)return;let h=n.position,g=s.position,d=this.getEdgeNormals(i),u=r.clone(d);if(u[0].multiplyScalar(10).add(h),u[1].multiplyScalar(10).add(h),"="===i.bondType||"="===this.getRingbondType(n,s)||i.isPartOfAromaticRing&&this.bridgedRing){let t=this.areVerticesInSameRing(n,s),e=this.chooseSide(n,s,u);if(t){let t=this.getLargestOrAromaticCommonRing(n,s).center;d[0].multiplyScalar(this.opts.bondSpacing),d[1].multiplyScalar(this.opts.bondSpacing);let e=null;(e=t.sameSideAs(n.position,s.position,l.add(h,d[0]))?new m(l.add(h,d[0]),l.add(g,d[0]),o,a):new m(l.add(h,d[1]),l.add(g,d[1]),o,a)).shorten(this.opts.bondLength-this.opts.shortBondLength*this.opts.bondLength),i.isPartOfAromaticRing?this.canvasWrapper.drawLine(e,!0):this.canvasWrapper.drawLine(e),this.canvasWrapper.drawLine(new m(h,g,o,a))}else if(i.center||n.isTerminal()&&s.isTerminal()){d[0].multiplyScalar(this.opts.halfBondSpacing),d[1].multiplyScalar(this.opts.halfBondSpacing);let t=new m(l.add(h,d[0]),l.add(g,d[0]),o,a),e=new m(l.add(h,d[1]),l.add(g,d[1]),o,a);this.canvasWrapper.drawLine(t),this.canvasWrapper.drawLine(e)}else if(0==e.anCount&&e.bnCount>1||0==e.bnCount&&e.anCount>1){d[0].multiplyScalar(this.opts.halfBondSpacing),d[1].multiplyScalar(this.opts.halfBondSpacing);let t=new m(l.add(h,d[0]),l.add(g,d[0]),o,a),e=new m(l.add(h,d[1]),l.add(g,d[1]),o,a);this.canvasWrapper.drawLine(t),this.canvasWrapper.drawLine(e)}else if(e.sideCount[0]>e.sideCount[1]){d[0].multiplyScalar(this.opts.bondSpacing),d[1].multiplyScalar(this.opts.bondSpacing);let t=new m(l.add(h,d[0]),l.add(g,d[0]),o,a);t.shorten(this.opts.bondLength-this.opts.shortBondLength*this.opts.bondLength),this.canvasWrapper.drawLine(t),this.canvasWrapper.drawLine(new m(h,g,o,a))}else if(e.sideCount[0]<e.sideCount[1]){d[0].multiplyScalar(this.opts.bondSpacing),d[1].multiplyScalar(this.opts.bondSpacing);let t=new m(l.add(h,d[1]),l.add(g,d[1]),o,a);t.shorten(this.opts.bondLength-this.opts.shortBondLength*this.opts.bondLength),this.canvasWrapper.drawLine(t),this.canvasWrapper.drawLine(new m(h,g,o,a))}else if(e.totalSideCount[0]>e.totalSideCount[1]){d[0].multiplyScalar(this.opts.bondSpacing),d[1].multiplyScalar(this.opts.bondSpacing);let t=new m(l.add(h,d[0]),l.add(g,d[0]),o,a);t.shorten(this.opts.bondLength-this.opts.shortBondLength*this.opts.bondLength),this.canvasWrapper.drawLine(t),this.canvasWrapper.drawLine(new m(h,g,o,a))}else if(e.totalSideCount[0]<=e.totalSideCount[1]){d[0].multiplyScalar(this.opts.bondSpacing),d[1].multiplyScalar(this.opts.bondSpacing);let t=new m(l.add(h,d[1]),l.add(g,d[1]),o,a);t.shorten(this.opts.bondLength-this.opts.shortBondLength*this.opts.bondLength),this.canvasWrapper.drawLine(t),this.canvasWrapper.drawLine(new m(h,g,o,a))}}else if("#"===i.bondType){d[0].multiplyScalar(this.opts.bondSpacing/1.5),d[1].multiplyScalar(this.opts.bondSpacing/1.5);let t=new m(l.add(h,d[0]),l.add(g,d[0]),o,a),e=new m(l.add(h,d[1]),l.add(g,d[1]),o,a);this.canvasWrapper.drawLine(t),this.canvasWrapper.drawLine(e),this.canvasWrapper.drawLine(new m(h,g,o,a))}else if("."===i.bondType);else{let t=n.value.isStereoCenter,e=s.value.isStereoCenter;"up"===i.wedge?this.canvasWrapper.drawWedge(new m(h,g,o,a,t,e)):"down"===i.wedge?this.canvasWrapper.drawDashedWedge(new m(h,g,o,a,t,e)):this.canvasWrapper.drawLine(new m(h,g,o,a,t,e))}if(e){let e=l.midpoint(h,g);this.canvasWrapper.drawDebugText(e.x,e.y,"e: "+t)}}drawVertices(t){for(let e=0;e<this.graph.vertices.length;e++){let i=this.graph.vertices[e],n=i.value,s=0,o=0,a=n.element,h=n.countImplicitHydrogens(),g=i.getTextDirection(this.graph.vertices),d=y.getEffectiveShowCarbonsMode(this.opts),u=("terminal"===d||"C"!==a||!!n.hasAttachedPseudoElements)&&i.isTerminal(),c="C"===n.element;if("C"===a){let t=n.rings&&n.rings.length>0;"none"===d?(c=!0,u=!1):"all"===d?(c=!1,u=!0):"acyclic"!==d||t||(c=!1,u=!0)}if("N"===n.element&&n.isPartOfAromaticRing&&(h=0),n.bracket&&(h=n.bracket.hcount,s=n.bracket.charge,o=n.bracket.isotope),(s||o||this.graph.vertices.length<3)&&(c=!1),"allballs"===this.opts.atomVisualization)this.canvasWrapper.drawBall(i.position.x,i.position.y,a);else if(n.isDrawn&&(!c||n.drawExplicit||u||n.hasAttachedPseudoElements)||1===this.graph.vertices.length)"default"===this.opts.atomVisualization?this.canvasWrapper.drawText(i.position.x,i.position.y,a,h,g,u,s,o,this.graph.vertices.length,n.getAttachedPseudoElements()):"balls"===this.opts.atomVisualization&&this.canvasWrapper.drawBall(i.position.x,i.position.y,a);else if(2===i.getNeighbourCount()&&!0==i.forcePositioned){let t=this.graph.vertices[i.neighbours[0]].position,e=this.graph.vertices[i.neighbours[1]].position;.1>Math.abs(Math.PI-l.threePointangle(i.position,t,e))&&this.canvasWrapper.drawPoint(i.position.x,i.position.y,a)}if(t){let t="v: "+i.id+" "+r.print(n.ringbonds);this.canvasWrapper.drawDebugText(i.position.x,i.position.y,t)}}if(this.opts.debug)for(let t=0;t<this.rings.length;t++){let e=this.rings[t].center;this.canvasWrapper.drawDebugPoint(e.x,e.y,"r: "+this.rings[t].id)}}position(){let t=null;for(let e=0;e<this.graph.vertices.length;e++)if(null!==this.graph.vertices[e].value.bridgedRing){t=this.graph.vertices[e];break}for(let e=0;e<this.rings.length;e++)this.rings[e].isBridged&&(t=this.graph.vertices[this.rings[e].members[0]]);this.rings.length>0&&null===t&&(t=this.graph.vertices[this.rings[0].members[0]]),null===t&&(t=this.graph.vertices[0]),this.createNextBond(t,null,0)}backupRingInformation(){this.originalRings=[],this.originalRingConnections=[];for(let t=0;t<this.rings.length;t++)this.originalRings.push(this.rings[t]);for(let t=0;t<this.ringConnections.length;t++)this.originalRingConnections.push(this.ringConnections[t]);for(let t=0;t<this.graph.vertices.length;t++)this.graph.vertices[t].value.backupRings()}restoreRingInformation(){let t=this.getBridgedRings();this.rings=[],this.ringConnections=[];for(let e=0;e<t.length;e++){let i=t[e];for(let t=0;t<i.rings.length;t++){let e=i.rings[t];this.originalRings[e.id].center=e.center}}for(let t=0;t<this.originalRings.length;t++)this.rings.push(this.originalRings[t]);for(let t=0;t<this.originalRingConnections.length;t++)this.ringConnections.push(this.originalRingConnections[t]);for(let t=0;t<this.graph.vertices.length;t++)this.graph.vertices[t].value.restoreRings()}createRing(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;if(t.positioned)return;e=e||new l(0,0);let n=t.getOrderedNeighbours(this.ringConnections),o=i?l.subtract(i.position,e).angle():0,h=s.polyCircumradius(this.opts.bondLength,t.getSize()),g=s.centralAngle(t.getSize());t.centralAngle=g;let d=o,u=i?i.id:null;if(-1===t.members.indexOf(u)&&(i&&(i.positioned=!1),u=t.members[0]),t.isBridged){this.graph.kkLayout(t.members.slice(),e,i.id,t,this.opts.bondLength,this.opts.kkThreshold,this.opts.kkInnerThreshold,this.opts.kkMaxIteration,this.opts.kkMaxInnerIteration,this.opts.kkMaxEnergy),t.positioned=!0,this.setRingCenter(t),e=t.center;for(let e=0;e<t.rings.length;e++)this.setRingCenter(t.rings[e])}else t.eachMember(this.graph.vertices,i=>{let r=this.graph.vertices[i];r.positioned||r.setPosition(e.x+Math.cos(d)*h,e.y+Math.sin(d)*h),d+=g,(!t.isBridged||t.rings.length<3)&&(r.angle=d,r.positioned=!0)},u,r?r.id:null);t.positioned=!0,t.center=e;for(let i=0;i<n.length;i++){let r=this.getRing(n[i].neighbour);if(r.positioned)continue;let o=a.getVertices(this.ringConnections,t.id,r.id);if(2===o.length){t.isFused=!0,r.isFused=!0;let i=this.graph.vertices[o[0]],n=this.graph.vertices[o[1]],a=l.midpoint(i.position,n.position),h=l.normals(i.position,n.position);h[0].normalize(),h[1].normalize();let g=s.polyCircumradius(this.opts.bondLength,r.getSize()),d=s.apothem(g,r.getSize());h[0].multiplyScalar(d).add(a),h[1].multiplyScalar(d).add(a);let u=h[0];l.subtract(e,h[1]).lengthSq()>l.subtract(e,h[0]).lengthSq()&&(u=h[1]);let c=l.subtract(i.position,u),f=l.subtract(n.position,u);-1===c.clockwise(f)?r.positioned||this.createRing(r,u,i,n):r.positioned||this.createRing(r,u,n,i)}else if(1===o.length){t.isSpiro=!0,r.isSpiro=!0;let i=this.graph.vertices[o[0]],n=l.subtract(e,i.position);n.invert(),n.normalize();let a=s.polyCircumradius(this.opts.bondLength,r.getSize());n.multiplyScalar(a),n.add(i.position),r.positioned||this.createRing(r,n,i)}}for(let e=0;e<t.members.length;e++){let i=this.graph.vertices[t.members[e]],r=i.neighbours;for(let t=0;t<r.length;t++){let e=this.graph.vertices[r[t]];e.positioned||(e.value.isConnectedToRing=!0,this.createNextBond(e,i,0))}}}fixDoubleBondStereo(){let t=this.graph;for(let e=0;e<t.edges.length;e++){let i,r,n=t.edges[e];if("="!==n.bondType)continue;let s=n.sourceId,l=n.targetId;if(t.vertices[s].value.rings.length>0&&t.vertices[l].value.rings.length>0)continue;let o=null,a=null;for(let e of t.vertices[s].getNeighbours()){if(e===l)continue;let i=t.getEdge(s,e);if(i&&("/"===i.bondType||"\\"===i.bondType)){o={nid:e,above:i.sourceId===s?"/"===i.bondType:"\\"===i.bondType};break}}for(let e of t.vertices[l].getNeighbours()){if(e===s)continue;let i=t.getEdge(l,e);if(i&&("/"===i.bondType||"\\"===i.bondType)){a={nid:e,above:i.sourceId===l?"/"===i.bondType:"\\"===i.bondType};break}}if(!o||!a)continue;let h=o.above===a.above,g=t.vertices[s].position,d=t.vertices[l].position,u=t.vertices[o.nid].position,c=t.vertices[a.nid].position,f=d.x-g.x,p=d.y-g.y;if(h===(f*(u.y-g.y)-p*(u.x-g.x)>0==f*(c.y-d.y)-p*(c.x-d.x)>0))continue;let m=0,b=0;for(let e of t.vertices[s].getNeighbours()){if(e===l)continue;let i=t.getEdge(s,e);i&&("/"===i.bondType||"\\"===i.bondType)&&m++}for(let e of t.vertices[l].getNeighbours()){if(e===s)continue;let i=t.getEdge(l,e);i&&("/"===i.bondType||"\\"===i.bondType)&&b++}if(m<=b?(i=o.nid,r=s):(i=a.nid,r=l),t.vertices[i].value.rings.length>0&&(i=r===s?a.nid:o.nid,r=r===s?l:s,t.vertices[i].value.rings.length>0))continue;let v=t.vertices[r].position,w=f*f+p*p;if(w<.001)continue;let y=this;t.traverseTree(i,r,function(t){let e=t.position.x-v.x,i=t.position.y-v.y,r=e*f+i*p;t.position.x=v.x+2*r*f/w-e,t.position.y=v.y+2*r*p/w-i;for(let e=0;e<t.value.anchoredRings.length;e++){let i=y.rings[t.value.anchoredRings[e]];if(i){let t=i.center.x-v.x,e=i.center.y-v.y,r=t*f+e*p;i.center.x=v.x+2*r*f/w-t,i.center.y=v.y+2*r*p/w-e}}})}}rotateSubtree(t,e,i,r){let n=r.clone();this.graph.traverseTree(t,e,t=>
1{t.position.rotateAround(i,n);for(let e=0;e<t.value.anchoredRings.length;e++){let r=this.rings[t.value.anchoredRings[e]];r&&r.center.rotateAround(i,n)}})}getSubtreeOverlapScore(t,e,i){let r=0,n=new l(0,0),s=0;return this.graph.traverseTree(t,e,t=>{if(!t.value.isDrawn)return;let e=i[t.id];e>this.opts.overlapSensitivity&&(r+=e,s++);let l=this.graph.vertices[t.id].position.clone();l.multiplyScalar(e),n.add(l)}),n.divide(r),{value:r/s,center:n}}getCurrentCenterOfMass(){let t=new l(0,0),e=0;for(let i=0;i<this.graph.vertices.length;i++){let r=this.graph.vertices[i];r.positioned&&(t.add(r.position),e++)}return t.divide(e)}getCurrentCenterOfMassInNeigbourhood(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2*this.opts.bondLength,i=new l(0,0),r=0,n=e*e;for(let e=0;e<this.graph.vertices.length;e++){let s=this.graph.vertices[e];s.positioned&&t.distanceSq(s.position)<n&&(i.add(s.position),r++)}return i.divide(r)}resolvePrimaryOverlaps(){let t=[],e=Array(this.graph.vertices.length);for(let i=0;i<this.rings.length;i++){let r=this.rings[i];for(let i=0;i<r.members.length;i++){let n=this.graph.vertices[r.members[i]];if(e[n.id])continue;e[n.id]=!0;let s=this.getNonRingNeighbours(n.id);if(s.length>1){let e=[];for(let t=0;t<n.value.rings.length;t++)e.push(n.value.rings[t]);t.push({common:n,rings:e,vertices:s})}else if(1===s.length&&2===n.value.rings.length){let e=[];for(let t=0;t<n.value.rings.length;t++)e.push(n.value.rings[t]);t.push({common:n,rings:e,vertices:s})}}}for(let e=0;e<t.length;e++){let i=t[e];if(2===i.vertices.length){let t=i.vertices[0],e=i.vertices[1];if(!t.value.isDrawn||!e.value.isDrawn)continue;let r=(2*Math.PI-this.getRing(i.rings[0]).getAngle())/6;this.rotateSubtree(t.id,i.common.id,r,i.common.position),this.rotateSubtree(e.id,i.common.id,-r,i.common.position);let n=this.getOverlapScore(),s=this.getSubtreeOverlapScore(t.id,i.common.id,n.vertexScores),l=this.getSubtreeOverlapScore(e.id,i.common.id,n.vertexScores),o=s.value+l.value;this.rotateSubtree(t.id,i.common.id,-2*r,i.common.position),this.rotateSubtree(e.id,i.common.id,2*r,i.common.position),n=this.getOverlapScore(),s=this.getSubtreeOverlapScore(t.id,i.common.id,n.vertexScores),l=this.getSubtreeOverlapScore(e.id,i.common.id,n.vertexScores),s.value+l.value>o&&(this.rotateSubtree(t.id,i.common.id,2*r,i.common.position),this.rotateSubtree(e.id,i.common.id,-2*r,i.common.position))}else 1===i.vertices.length&&i.rings.length}}resolveSecondaryOverlaps(t){for(let e=0;e<t.length;e++)if(t[e].score>this.opts.overlapSensitivity){let i=this.graph.vertices[t[e].id];if(i.isTerminal()){let t=this.getClosestVertex(i);if(t){let e=null;e=t.isTerminal()?0===t.id?this.graph.vertices[1].position:t.previousPosition:0===t.id?this.graph.vertices[1].position:t.position;let r=0===i.id?this.graph.vertices[1].position:i.previousPosition;i.position.rotateAwayFrom(e,r,s.toRad(20))}}}}getLastAngle(t){for(;t;){let e=this.graph.vertices[t];if(e.value.rings.length>0)break;if(e.angle)return e.angle;t=e.parentVertexId}return 0}createNextBond(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]&&arguments[3],o=arguments.length>4&&void 0!==arguments[4]&&arguments[4];if(t.positioned&&!o)return;let a=!1;if(e){let i=this.graph.getEdge(t.id,e.id);("/"===i.bondType||"\\"===i.bondType)&&++this.doubleBondConfigCount%2==1&&null===this.doubleBondConfig&&(this.doubleBondConfig=i.bondType,a=!0,null===e.parentVertexId&&t.value.branchBond&&("/"===this.doubleBondConfig?this.doubleBondConfig="\\":"\\"===this.doubleBondConfig&&(this.doubleBondConfig="/")))}if(!o)if(e)if(e.value.rings.length>0){let i=e.neighbours,n=null,s=new l(0,0);if(null===e.value.bridgedRing&&e.value.rings.length>1)for(let t=0;t<i.length;t++){let s=this.graph.vertices[i[t]];if(r.containsAll(s.value.rings,e.value.rings)){n=s;break}}if(null===n){for(let t=0;t<i.length;t++){let r=this.graph.vertices[i[t]];r.positioned&&this.areVerticesInSameRing(r,e)&&s.add(l.subtract(r.position,e.position))}if(1>s.lengthSq()){let t=null;s=(t=null!==e.value.bridgedRing?this.getRing(e.value.bridgedRing):this.getRing(e.value.rings[0]))&&t.center?l.subtract(t.center,e.position):new l(1,0)}s.invert().normalize().multiplyScalar(this.opts.bondLength).add(e.position)}
1else s=n.position.clone().rotateAround(Math.PI,e.position);t.previousPosition=e.position,t.setPositionFromVector(s),t.positioned=!0}else{let r=new l(this.opts.bondLength,0);r.rotate(i),r.add(e.position),t.setPositionFromVector(r),t.previousPosition=e.position,t.positioned=!0}else{let e=new l(this.opts.bondLength,0);e.rotate(s.toRad(-60)),t.previousPosition=e,t.setPosition(this.opts.bondLength,0),t.angle=s.toRad(-60),null===t.value.bridgedRing&&(t.positioned=!0)}if(null!==t.value.bridgedRing){let e=this.getRing(t.value.bridgedRing);if(!e.positioned){let i=l.subtract(t.previousPosition,t.position);i.invert(),i.normalize();let r=s.polyCircumradius(this.opts.bondLength,e.members.length);i.multiplyScalar(r),i.add(t.position),this.createRing(e,i,t)}}else if(t.value.rings.length>0){let e=this.getRing(t.value.rings[0]);if(!e.positioned){let i=l.subtract(t.previousPosition,t.position);i.invert(),i.normalize();let r=s.polyCircumradius(this.opts.bondLength,e.getSize());i.multiplyScalar(r),i.add(t.position),this.createRing(e,i,t)}}else{let i=t.getNeighbours(),o=[];for(let t=0;t<i.length;t++)this.graph.vertices[i[t]].value.isDrawn&&o.push(i[t]);e&&(o=r.remove(o,e.id));let h=t.getAngle();if(1===o.length){let i=this.graph.vertices[o[0]],r=e?this.graph.getEdge(t.id,e.id):null,g=this.graph.getEdge(t.id,i.id);if(r&&g&&r.weight+g.weight>=4)r.center=!0,g.center=!0,t.value.drawExplicit=!1,i.drawExplicit=!0,i.angle=0,this.createNextBond(i,t,h+i.angle);else if(e&&e.value.rings.length>0){let e=s.toRad(60),r=-e,n=new l(this.opts.bondLength,0),o=new l(this.opts.bondLength,0);n.rotate(e).add(t.position),o.rotate(r).add(t.position);let a=this.getCurrentCenterOfMass();i.angle=n.distanceSq(a)<o.distanceSq(a)?r:e,this.createNextBond(i,t,h+i.angle)}else{let r=this.getLastAngle(t.id);if(r=r>=0?1.0472:-1.0472,e&&!a){let e=this.graph.getEdge(t.id,i.id).bondType;"/"===e?("/"===this.doubleBondConfig||"\\"===this.doubleBondConfig&&(r=-r),this.doubleBondConfig=null):"\\"===e&&("/"===this.doubleBondConfig?r=-r:this.doubleBondConfig,this.doubleBondConfig=null)}n?i.angle=r:i.angle=-r,this.createNextBond(i,t,h+i.angle)}}else if(2===o.length){let i=t.angle;i||(i=1.0472);let r=this.graph.getTreeDepth(o[0],t.id),n=this.graph.getTreeDepth(o[1],t.id),s=this.graph.vertices[o[0]],l=this.graph.vertices[o[1]];s.value.subtreeDepth=r,l.value.subtreeDepth=n;let a=this.graph.getTreeDepth(e?e.id:null,t.id);e&&(e.value.subtreeDepth=a);let g=0,d=1;"C"===l.value.element&&"C"!==s.value.element&&n>1&&r<5?(g=1,d=0):"C"!==l.value.element&&"C"===s.value.element&&r>1&&n<5?(g=0,d=1):n>r&&(g=1,d=0);let u=this.graph.vertices[o[g]],c=this.graph.vertices[o[d]],f=a<r&&a<n;c.angle=i,u.angle=-i,"\\"===this.doubleBondConfig?"\\"===c.value.branchBond&&(c.angle=-i,u.angle=i):"/"===this.doubleBondConfig&&"/"===c.value.branchBond&&(c.angle=-i,u.angle=i),this.createNextBond(c,t,h+c.angle,f),this.createNextBond(u,t,h+u.angle,f)}else if(o.length>0){let i=o.map(e=>{let i=this.graph.vertices[e],r=this.graph.getTreeDepth(e,t.id);return i.value.subtreeDepth=r,i});if(i.sort((t,e)=>e.value.subtreeDepth-t.value.subtreeDepth),3===o.length&&e&&null!==e.parentVertexId&&e.value.rings.length<1&&i[2].value.rings.length<1&&i[1].value.rings.length<1&&i[0].value.rings.length<1&&1===i[2].value.subtreeDepth&&1===i[1].value.subtreeDepth&&i[0].value.subtreeDepth>1)t.angle>=0?(i[0].angle=-1.0472,i[1].angle=s.toRad(30),i[2].angle=s.toRad(90)):(i[0].angle=1.0472,i[1].angle=-s.toRad(30),i[2].angle=-s.toRad(90)),this.createNextBond(i[0],t,h+i[0].angle),this.createNextBond(i[1],t,h+i[1].angle),this.createNextBond(i[2],t,h+i[2].angle);else{let r=2*Math.PI/(o.length+ +!!e),n=r,s=0;for(o.length%2!=0?(this.createNextBond(i[0],t,h),s=1):n/=2;s<o.length;)this.createNextBond(i[s+0],t,h+n),this.createNextBond(i[s+1],t,h-n),n+=r,s+=2}}}}getCommonRingbondNeighbour(t){let e=t.neighbours;for(let i=0;i<e.length;i++){let n=this.graph.vertices[e[i]];if(r.containsAll(n.value.rings,t.value.rings))return n}return null}isPointInRing(t){for(let e=0;e<this.rings.length;e++){let i=this.rings[e];if(!i.positioned)continue;let r=s.polyCircumradius(this.opts.bondLength,i.getSize()),n=r*r;if(t.distanceSq(i.center)<n)return!0}return!1}isEdgeInRing(t){let e=this.graph.vertices[t.sourceId],i=this.graph.vertices[t.targetId];return this.areVerticesInSameRing(e,i)}isEdgeRotatable(t){let e=this.graph.vertices[t.sourceId],i=this.graph.vertices[t.targetId];return!("-"!==t.bondType||e.isTerminal()||i.isTerminal()||e.value.rings.length>0&&i.value.rings.length>0&&this.areVerticesInSameRing(e,i))}isRingAromatic(t){for(let e=0;e<t.members.length;e++)if(!this.graph.vertices[t.members[e]].value.isPartOfAromaticRing)return!1;return!0}getEdgeNormals(t){let e=this.graph.vertices[t.sourceId].position,i=this.graph.vertices[t.targetId].position;return l.units(e,i)}getNonRingNeighbours(t){let e=[],i=this.graph.vertices[t],n=i.neighbours;for(let t=0;t<n.length;t++){let s=this.graph.vertices[n[t]];0===r.intersection(i.value.rings,s.value.rings).length&&!1==s.value.isBridge&&e.push(s)}return e}getMinimumNonBondedDistance(){let t=1/0;for(let e=0;e<this.graph.vertices.length;e++){let i=this.graph.vertices[e];if(i.value.isDrawn)for(let r=e+1;r<this.graph.vertices.length;r++){if(this.graph.hasEdge(e,r))continue;let n=this.graph.vertices[r];if(!n.value.isDrawn)continue;let s=i.position.distance(n.position);s<t&&(t=s)}}return t}getRingExternalConnectionCount(t){let e=this.getRing(t);if(!e)return 0;let i=new Set(e.members),r=new Set;for(let t=0;t<e.members.length;t++){let n=e.members[t],s=this.graph.vertices[n];for(let t=0;t<s.neighbours.length;t++){let e=s.neighbours[t];
1i.has(e)||r.add("".concat(n,":").concat(e))}}return r.size}resolveRigidRingOverlaps(){let t=this.getOverlapScore().total,e=this.getMinimumNonBondedDistance(),i=.3*this.opts.bondLength;for(let r=0;r<this.graph.edges.length;r++){let n=this.graph.edges[r];if(!this.isEdgeRotatable(n))continue;let l=this.graph.getTreeDepth(n.sourceId,n.targetId),o=this.graph.getTreeDepth(n.targetId,n.sourceId),a=n.targetId,h=n.sourceId;l>o&&(a=n.sourceId,h=n.targetId);let g=this.graph.vertices[a],d=this.graph.vertices[h],u=d.getNeighbours(a);if(2!==u.length)continue;let c=this.graph.vertices[u[0]],f=this.graph.vertices[u[1]];if(1!==c.value.rings.length||1!==f.value.rings.length||c.value.rings[0]!==f.value.rings[0])continue;let p=this.getRing(c.value.rings[0]);if(!p)continue;let m=0,b=t,v=e,w=s.centralAngle(p.getSize()),y=Math.max(1,Math.floor(p.getSize()/2));for(let t=1;t<=y;t++){let e=w*t;for(let t=0;t<2;t++){let r=0===t?e:-e;this.rotateSubtree(d.id,g.id,r,d.position);let n=this.getOverlapScore().total,s=this.getMinimumNonBondedDistance();this.rotateSubtree(d.id,g.id,-r,d.position),!(s<=i)&&(n<b-1e-6||1e-6>=Math.abs(n-b)&&s>v+1e-6)&&(m=r,b=n,v=s)}}0!==m&&(this.rotateSubtree(d.id,g.id,m,d.position),t=b,e=v)}this.totalOverlapScore=t}annotateStereochemistry(){for(let t=0;t<this.graph.vertices.length;t++){let e=this.graph.vertices[t];if(!e.value.isStereoCenter)continue;let i=e.neighbours;if(i.length+e.value.countImplicitHydrogens()!==4){e.value.isStereoCenter=!1;continue}let r=c.getOrderArray(this.graph,e);if(void 0===r){e.value.isStereoCenter=!1;continue}let n=s.parityOfPermutation(r)===("@"===e.value.bracket.chirality?-1:1)?"R":"S";e.value.chirality=n;let l=Array(i.length-1),o=e.value.rings.length>1&&e.value.hasHydrogen,a=+!!e.value.hasHydrogen;for(let t=0;t<r.length-a;t++){l[t]=new Uint32Array(2);let n=this.graph.vertices[i[r[t]]];l[t][0]+=1e5*!n.value.isStereoCenter,l[t][0]+=1e4*!this.areVerticesInSameRing(n,e),l[t][0]+=1e3*!!n.value.isHeteroAtom(),l[t][0]-=1e3*(0===n.value.subtreeDepth),l[t][0]+=1e3-n.value.subtreeDepth,l[t][1]=i[r[t]]}if(l.sort((t,e)=>e[0]-t[0]),!o){let t=l[0][1],s=this._computeWedgeDirection(e,t,r,i,n);if(this.graph.getEdge(e.id,t).wedge=s,e.value.hasHydrogen){let t=i[r[r.length-1]],s=this._computeWedgeDirection(e,t,r,i,n);this.graph.getEdge(e.id,t).wedge=s,e.value.hydrogenDirection="up"===s?"up":"down"}}}}_computeWedgeDirection(t,e,i,r,n){let s=r.length,l=0;for(let t=0;t<s;t++)if(r[i[t]]===e){l=t;break}let o=[];for(let t=0;t<s;t++)r[i[t]]!==e&&o.push(this.graph.vertices[r[i[t]]].position);if(2===o.length){let i=this.graph.vertices[e].position,r=(i.x+o[0].x+o[1].x)/3,n=(i.y+o[0].y+o[1].y)/3;o.push({x:2*t.position.x-r,y:2*t.position.y-n})}let a=(o[1].x-o[0].x)*(o[2].y-o[0].y)-(o[2].x-o[0].x)*(o[1].y-o[0].y);return(l%2==0?a>0:a<0)==("R"===n)?"up":"down"}initPseudoElements(){for(let t=0;t<this.graph.vertices.length;t++){let e=this.graph.vertices[t],i=e.neighbours,r=Array(i.length);for(let t=0;t<i.length;t++)r[t]=this.graph.vertices[i[t]];if(3>e.getNeighbourCount()||e.value.rings.length>0||"P"===e.value.element||"C"===e.value.element&&3===r.length&&"N"===r[0].value.element&&"N"===r[1].value.element&&"N"===r[2].value.element)continue;let n=0,s=0;for(let t=0;t<r.length;t++){let e=r[t],i=e.value.element,l=e.getNeighbourCount();"C"!==i&&"H"!==i&&1===l&&n++,l>1&&s++}if(s>1||n<2)continue;let l=null;for(let t=0;t<r.length;t++){let e=r[t];e.getNeighbourCount()>1&&(l=e)}for(let t=0;t<r.length;t++){let i=r[t];if(i.getNeighbourCount()>1)continue;i.value.isDrawn=!1;let n=i.value.countImplicitHydrogens(),s="";i.value.bracket&&(s=i.value.bracket.charge||0),e.value.attachPseudoElement(i.value.element,l?l.value.element:null,n,s)}}}constructor(t){this.graph=null,this.doubleBondConfigCount=0,this.doubleBondConfig=null,this.ringIdCounter=0,this.ringConnectionIdCounter=0,this.canvasWrapper=null,this.totalOverlapScore=0,this.defaultOptions={width:500,height:500,scale:0,bondThickness:1,bondLength:30,shortBondLength:.8,bondSpacing:.17*30,atomVisualization:"default",isomeric:!0,debug:!1,terminalCarbons:!1,showCarbons:"default",explicitHydrogens:!0,overlapSensitivity:.42,overlapResolutionIterations:1,compactDrawing:!0,fontFamily:"Arial, Helvetica, sans-serif",fontSizeLarge:11,fontSizeSmall:3,padding:10,experimentalSSSR:!1,experimentalWeights:!1,kkThreshold:.1,kkInnerThreshold:.1,kkMaxIteration:2e4,kkMaxInnerIteration:50,kkMaxEnergy:1e9,weights:{colormap:null,additionalPadding:20,sigma:10,interval:0,opacity:1},themes:{dark:{FOREGROUND:"#ffffff",BACKGROUND:"#141414",C:"#ffffff",O:"#e74c3c",N:"#3498db",F:"#27ae60",CL:"#16a085",BR:"#d35400",I:"#8e44ad",P:"#d35400",S:"#f1c40f",B:"#e67e22",SI:"#e67e22",H:"#aaaaaa"},light:{FOREGROUND:"#222222",BACKGROUND:"#ffffff",C:"#222222",O:"#e74c3c",N:"#3498db",F:"#27ae60",CL:"#16a085",BR:"#d35400",I:"#8e44ad",P:"#d35400",S:"#f1c40f",B:"#e67e22",SI:"#e67e22",H:"#666666"},oldschool:{FOREGROUND:"#000000",BACKGROUND:"#ffffff",C:"#000000",O:"#000000",N:"#000000",F:"#000000",CL:"#000000",BR:"#000000",I:"#000000",P:"#000000",S:"#000000",B:"#000000",SI:"#000000",H:"#000000"},solarized:{FOREGROUND:"#586e75",BACKGROUND:"#eee8d5",C:"#586e75",O:"#dc322f",N:"#268bd2",F:"#859900",CL:"#16a085",BR:"#cb4b16",I:"#6c71c4",P:"#d33682",S:"#b58900",B:"#2aa198",SI:"#2aa198",H:"#657b83"},"solarized-dark":{FOREGROUND:"#93a1a1",BACKGROUND:"#073642",C:"#93a1a1",O:"#dc322f",N:"#268bd2",F:"#859900",CL:"#16a085",BR:"#cb4b16",I:"#6c71c4",P:"#d33682",S:"#b58900",B:"#2aa198",SI:"#2aa198",H:"#839496"},matrix:{FOREGROUND:"#678c61",BACKGROUND:"#ffffff",C:"#678c61",O:"#2fc079",N:"#4f7e7e",F:"#90d762",CL:"#82d967",BR:"#23755a",I:"#409931",P:"#c1ff8a",S:"#faff00",B:"#50b45a",SI:"#409931",H:"#426644"},github:{FOREGROUND:"#24292f",BACKGROUND:"#ffffff",C:"#24292f",O:"#cf222e",N:"#0969da",F:"#2da44e",CL:"#6fdd8b",BR:"#bc4c00",I:"#8250df",P:"#bf3989",S:"#d4a72c",B:"#fb8f44",SI:"#bc4c00",H:"#57606a"},carbon:{FOREGROUND:"#161616",BACKGROUND:"#ffffff",C:"#161616",O:"#da1e28",N:"#0f62fe",F:"#198038",CL:"#007d79",BR:"#fa4d56",I:"#8a3ffc",P:"#ff832b",S:"#f1c21b",B:"#8a3800",SI:"#e67e22",H:"#525252"},cyberpunk:{FOREGROUND:"#ea00d9",BACKGROUND:"#ffffff",C:"#ea00d9",O:"#ff3131",N:"#0abdc6",F:"#00ff9f",CL:"#00fe00",BR:"#fe9f20",I:"#ff00ff",P:"#fe7f00",S:"#fcee0c",B:"#ff00ff",SI:"#ffffff",H:"#913cb1"},gruvbox:{FOREGROUND:"#665c54",BACKGROUND:"#fbf1c7",C:"#665c54",O:"#cc241d",N:"#458588",F:"#98971a",CL:"#79740e",BR:"#d65d0e",I:"#b16286",P:"#af3a03",S:"#d79921",B:"#689d6a",SI:"#427b58",H:"#7c6f64"},"gruvbox-dark":{FOREGROUND:"#ebdbb2",BACKGROUND:"#282828",C:"#ebdbb2",O:"#cc241d",N:"#458588",F:"#98971a",CL:"#b8bb26",BR:"#d65d0e",I:"#b16286",P:"#fe8019",S:"#d79921",B:"#8ec07c",SI:"#83a598",H:"#bdae93"},custom:{FOREGROUND:"#222222",BACKGROUND:"#ffffff",C:"#222222",O:"#e74c3c",N:"#3498db",F:"#27ae60",CL:"#16a085",BR:"#d35400",I:"#8e44ad",P:"#d35400",S:"#f1c40f",B:"#e67e22",SI:"#e67e22",H:"#666666"}}},this.opts=b.extend(!0,this.defaultOptions,t),-1===["none","default","terminal","acyclic","all"].indexOf(this.opts.showCarbons)&&(this.opts.showCarbons="default"),this.opts.halfBondSpacing=this.opts.bondSpacing/2,this.opts.bondLengthSq=this.opts.bondLength*this.opts.bondLength,this.opts.halfFontSizeLarge=this.opts.fontSizeLarge/2,this.opts.quarterFontSizeLarge=this.opts.fontSizeLarge/4,this.opts.fifthFontSizeSmall=this.opts.fontSizeSmall/5,this.theme=this.opts.themes.dark}}let S=(t,e=0,i=1)=>I(M(e,t),i),x=t=>{t._clipped=!1,t._unclipped=t.slice(0);for(let e=0;e<=3;e++)e<3?((t[e]<0||t[e]>255)&&(t._clipped=!0),t[e]=S(t[e],0,255)):3===e&&(t[e]=S(t[e],0,1));return t},A={};for(let t of["Boolean","Number","String","Function","Array","Date","RegExp","Undefined","Null"])A[`[object ${t}]`]=t.toLowerCase();function C(t){return A[Object.prototype.toString.call(t)]||"object"}let N=(t,e=null)=>t.length>=3?Array.prototype.slice.call(t):"object"==C(t[0])&&e?e.split("").filter(e=>void 0!==t[0][e]).map(e=>t[0][e]):t[0],R=t=>{if(t.length<2)return null;let e=t.length-1;return"string"==C(t[e])?t[e].toLowerCase():null},{PI:E,min:I,max:M}=Math,k=2*E,T=E/3,B=E/180,L=180/E,O={format:{},autodetect:[]};class D{constructor(...t){if("object"===C(t[0])&&t[0].constructor&&t[0].constructor===this.constructor)return t[0];let e=R(t),i=!1;if(!e){for(let r of(i=!0,O.sorted||(O.autodetect=O.autodetect.sort((t,e)=>
1e.p-t.p),O.sorted=!0),O.autodetect))if(e=r.test(...t))break}if(O.format[e]){let r=O.format[e].apply(null,i?t:t.slice(0,-1));this._rgb=x(r)}else throw Error("unknown format: "+t);3===this._rgb.length&&this._rgb.push(1)}toString(){return"function"==C(this.hex)?this.hex():`[${this._rgb.join(",")}]`}}let P=(...t)=>new P.Color(...t);P.Color=D,P.version="2.6.0";let{max:z}=Math;D.prototype.cmyk=function(){return((...t)=>{let[e,i,r]=N(t,"rgb"),n=1-z(e/=255,z(i/=255,r/=255)),s=n<1?1/(1-n):0;return[(1-e-n)*s,(1-i-n)*s,(1-r-n)*s,n]})(this._rgb)},P.cmyk=(...t)=>new D(...t,"cmyk"),O.format.cmyk=(...t)=>{let[e,i,r,n]=t=N(t,"cmyk"),s=t.length>4?t[4]:1;return 1===n?[0,0,0,s]:[e>=1?0:255*(1-e)*(1-n),i>=1?0:255*(1-i)*(1-n),r>=1?0:255*(1-r)*(1-n),s]},O.autodetect.push({p:2,test:(...t)=>{if("array"===C(t=N(t,"cmyk"))&&4===t.length)return"cmyk"}});let F=t=>Math.round(100*t)/100,H=(...t)=>{let e,i,[r,n,s]=t=N(t,"rgba"),l=I(r/=255,n/=255,s/=255),o=M(r,n,s),a=(o+l)/2;return(o===l?(e=0,i=NaN):e=a<.5?(o-l)/(o+l):(o-l)/(2-o-l),r==o?i=(n-s)/(o-l):n==o?i=2+(s-r)/(o-l):s==o&&(i=4+(r-n)/(o-l)),(i*=60)<0&&(i+=360),t.length>3&&void 0!==t[3])?[i,e,a,t[3]]:[i,e,a]},{round:_}=Math,{round:W}=Math,V=(...t)=>{let e,i,r,[n,s,l]=t=N(t,"hsl");if(0===s)e=i=r=255*l;else{let t=[0,0,0],o=[0,0,0],a=l<.5?l*(1+s):l+s-l*s,h=2*l-a,g=n/360;t[0]=g+1/3,t[1]=g,t[2]=g-1/3;for(let e=0;e<3;e++)t[e]<0&&(t[e]+=1),t[e]>1&&(t[e]-=1),6*t[e]<1?o[e]=h+(a-h)*6*t[e]:2*t[e]<1?o[e]=a:3*t[e]<2?o[e]=h+(a-h)*(2/3-t[e])*6:o[e]=h;[e,i,r]=[W(255*o[0]),W(255*o[1]),W(255*o[2])]}return t.length>3?[e,i,r,t[3]]:[e,i,r,1]},U=/^rgb\(\s*(-?\d+),\s*(-?\d+)\s*,\s*(-?\d+)\s*\)$/,X=/^rgba\(\s*(-?\d+),\s*(-?\d+)\s*,\s*(-?\d+)\s*,\s*([01]|[01]?\.\d+)\)$/,G=/^rgb\(\s*(-?\d+(?:\.\d+)?)%,\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*\)$/,Y=/^rgba\(\s*(-?\d+(?:\.\d+)?)%,\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,q=/^hsl\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*\)$/,j=/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,{round:$}=Math,K=t=>{let e;if(t=t.toLowerCase().trim(),O.format.named)try{return O.format.named(t)}catch(t){}if(e=t.match(U)){let t=e.slice(1,4);for(let e=0;e<3;e++)t[e]=+t[e];return t[3]=1,t}if(e=t.match(X)){let t=e.slice(1,5);for(let e=0;e<4;e++)t[e]=+t[e];return t}if(e=t.match(G)){let t=e.slice(1,4);for(let e=0;e<3;e++)t[e]=$(2.55*t[e]);return t[3]=1,t}if(e=t.match(Y)){let t=e.slice(1,5);for(let e=0;e<3;e++)t[e]=$(2.55*t[e]);return t[3]=+t[3],t}if(e=t.match(q)){let t=e.slice(1,4);t[1]*=.01,t[2]*=.01;let i=V(t);return i[3]=1,i}if(e=t.match(j)){let t=e.slice(1,4);t[1]*=.01,t[2]*=.01;let i=V(t);return i[3]=+e[4],i}};K.test=t=>U.test(t)||X.test(t)||G.test(t)||Y.test(t)||q.test(t)||j.test(t),D.prototype.css=function(t){return((...t)=>{let e=N(t,"rgba"),i=R(t)||"rgb";return"hsl"==i.substr(0,3)?((...t)=>{let e=N(t,"hsla"),i=R(t)||"lsa";return e[0]=F(e[0]||0),e[1]=F(100*e[1])+"%",e[2]=F(100*e[2])+"%","hsla"===i||e.length>3&&e[3]<1?(e[3]=e.length>3?e[3]:1,i="hsla"):e.length=3,`${i}(${e.join(",")})`})(H(e),i):(e[0]=_(e[0]),e[1]=_(e[1]),e[2]=_(e[2]),("rgba"===i||e.length>3&&e[3]<1)&&(e[3]=e.length>3?e[3]:1,i="rgba"),`${i}(${e.slice(0,"rgb"===i?3:4).join(",")})`)}
vendor: 1,803 bytes, line 1
1)(this._rgb,t)},P.css=(...t)=>new D(...t,"css"),O.format.css=K,O.autodetect.push({p:5,test:(t,...e)=>{if(!e.length&&"string"===C(t)&&K.test(t))return"css"}}),O.format.gl=(...t)=>{let e=N(t,"rgba");return e[0]*=255,e[1]*=255,e[2]*=255,e},P.gl=(...t)=>new D(...t,"gl"),D.prototype.gl=function(){let t=this._rgb;return[t[0]/255,t[1]/255,t[2]/255,t[3]]};let{floor:Z}=Math;D.prototype.hcg=function(){return((...t)=>{let e,[i,r,n]=N(t,"rgb"),s=I(i,r,n),l=M(i,r,n),o=l-s;return 0===o?e=NaN:(i===l&&(e=(r-n)/o),r===l&&(e=2+(n-i)/o),n===l&&(e=4+(i-r)/o),(e*=60)<0&&(e+=360)),[e,100*o/255,s/(255-o)*100]})(this._rgb)},P.hcg=(...t)=>new D(...t,"hcg"),O.format.hcg=(...t)=>{let e,i,r,[n,s,l]=t=N(t,"hcg");l*=255;let o=255*s;if(0===s)e=i=r=l;else{360===n&&(n=0),n>360&&(n-=360),n<0&&(n+=360);let t=Z(n/=60),a=n-t,h=l*(1-s),g=h+o*(1-a),d=h+o*a,u=h+o;switch(t){case 0:[e,i,r]=[u,d,h];break;case 1:[e,i,r]=[g,u,h];break;case 2:[e,i,r]=[h,u,d];break;case 3:[e,i,r]=[h,g,u];break;case 4:[e,i,r]=[d,h,u];break;case 5:[e,i,r]=[u,h,g]}}return[e,i,r,t.length>3?t[3]:1]},O.autodetect.push({p:1,test:(...t)=>{if("array"===C(t=N(t,"hcg"))&&3===t.length)return"hcg"}});let J=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,Q=/^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/,tt=t=>{if(t.match(J)){(4===t.length||7===t.length)&&(t=t.substr(1)),3===t.length&&(t=(t=t.split(""))[0]+t[0]+t[1]+t[1]+t[2]+t[2]);let e=parseInt(t,16);return[e>>16,e>>8&255,255&e,1]}if(t.match(Q)){(5===t.length||9===t.length)&&(t=t.substr(1)),4===t.length&&(t=(t=t.split(""))[0]+t[0]+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]);let e=parseInt(t,16),i=Math.round((255&e)/255*100)/100;return[e>>24&255,e>>16&255,e>>8&255,i]}throw Error(`unknown hex color: ${t}`)},{round:te}=Math,ti=(...t)=>{let[e,i,r,n]=N(t,"rgba"),s=R(t)||"auto";void 0===n&&(n=1),"auto"===s&&(s=n<1?"rgba":"rgb"),e=te(e);
1let l="000000"+(e<<16|(i=te(i))<<8|(r=te(r))).toString(16);l=l.substr(l.length-6);let o="0"+te(255*n).toString(16);switch(o=o.substr(o.length-2),s.toLowerCase()){case"rgba":return`#${l}${o}`;case"argb":return`#${o}${l}`;default:return`#${l}`}};D.prototype.hex=function(t){return ti(this._rgb,t)},P.hex=(...t)=>new D(...t,"hex"),O.format.hex=tt,O.autodetect.push({p:4,test:(t,...e)=>{if(!e.length&&"string"===C(t)&&[3,4,5,6,7,8,9].indexOf(t.length)>=0)return"hex"}});let{cos:tr}=Math,{min:tn,sqrt:ts,acos:tl}=Math;D.prototype.hsi=function(){return((...t)=>{let e,[i,r,n]=N(t,"rgb"),s=tn(i/=255,r/=255,n/=255),l=(i+r+n)/3,o=l>0?1-s/l:0;return 0===o?e=NaN:(e=tl(e=(i-r+(i-n))/2/ts((i-r)*(i-r)+(i-n)*(r-n))),n>r&&(e=k-e),e/=k),[360*e,o,l]})(this._rgb)},P.hsi=(...t)=>new D(...t,"hsi"),O.format.hsi=(...t)=>{let e,i,r,[n,s,l]=t=N(t,"hsi");return isNaN(n)&&(n=0),isNaN(s)&&(s=0),n>360&&(n-=360),n<0&&(n+=360),(n/=360)<1/3?i=1-((r=(1-s)/3)+(e=(1+s*tr(k*n)/tr(T-k*n))/3)):n<2/3?(n-=1/3,r=1-((e=(1-s)/3)+(i=(1+s*tr(k*n)/tr(T-k*n))/3))):(n-=2/3,e=1-((i=(1-s)/3)+(r=(1+s*tr(k*n)/tr(T-k*n))/3))),e=S(l*e*3),[255*e,255*(i=S(l*i*3)),255*(r=S(l*r*3)),t.length>3?t[3]:1]},O.autodetect.push({p:2,test:(...t)=>{if("array"===C(t=N(t,"hsi"))&&3===t.length)return"hsi"}}),D.prototype.hsl=function(){return H(this._rgb)},P.hsl=(...t)=>new D(...t,"hsl"),O.format.hsl=V,O.autodetect.push({p:2,test:(...t)=>{if("array"===C(t=N(t,"hsl"))&&3===t.length)return"hsl"}});let{floor:to}=Math,{min:ta,max:th}=Math;D.prototype.hsv=function(){return((...t)=>{let e,i,[r,n,s]=t=N(t,"rgb"),l=ta(r,n,s),o=th(r,n,s),a=o-l;return 0===o?(e=NaN,i=0):(i=a/o,r===o&&(e=(n-s)/a),n===o&&(e=2+(s-r)/a),s===o&&(e=4+(r-n)/a),(e*=60)<0&&(e+=360)),[e,i,o/255]})(this._rgb)},P.hsv=(...t)=>new D(...t,"hsv"),O.format.hsv=(...t)=>{let e,i,r,[n,s,l]=t=N(t,"hsv");if(l*=255,0===s)e=i=r=l;else{360===n&&(n=0),n>360&&(n-=360),n<0&&(n+=360);let t=to(n/=60),o=n-t,a=l*(1-s),h=l*(1-s*o),g=l*(1-s*(1-o));switch(t){case 0:[e,i,r]=[l,g,a];break;case 1:[e,i,r]=[h,l,a];break;case 2:[e,i,r]=[a,l,g];break;case 3:[e,i,r]=[a,h,l];break;case 4:[e,i,r]=[g,a,l];break;case 5:[e,i,r]=[l,a,h]}}return[e,i,r,t.length>3?t[3]:1]},O.autodetect.push({p:2,test:(...t)=>{if("array"===C(t=N(t,"hsv"))&&3===t.length)return"hsv"}});let tg={Kn:18,Xn:.95047,Yn:1,Zn:1.08883,t0:.137931034,t1:.206896552,t2:.12841855,t3:.008856452},{pow:td}=Math,tu=t=>255*(t<=.00304?12.92*t:1.055*td(t,1/2.4)-.055),tc=t=>t>tg.t1?t*t*t:tg.t2*(t-tg.t0),tf=(...t)=>{let e,i,r,n,[s,l,o]=t=N(t,"lab");return i=(s+16)/116,e=isNaN(l)?i:i+l/500,r=isNaN(o)?i:i-o/200,i=tg.Yn*tc(i),n=tu(3.2404542*(e=tg.Xn*tc(e))-1.5371385*i-.4985314*(r=tg.Zn*tc(r))),[n,tu(-.969266*e+1.8760108*i+.041556*r),tu(.0556434*e-.2040259*i+1.0572252*r),t.length>3?t[3]:1]},{pow:tp}=Math,tm=t=>(t/=255)<=.04045?t/12.92:tp((t+.055)/1.055,2.4),tb=t=>t>tg.t3?tp(t,1/3):t/tg.t2+tg.t0,tv=(...t)=>{let[e,i,r]=N(t,"rgb"),[n,s,l]=((t,e,i)=>{t=tm(t);let r=tb((.4124564*t+.3575761*(e=tm(e))+.1804375*(i=tm(i)))/tg.Xn);return[r,tb((.2126729*t+.7151522*e+.072175*i)/tg.Yn),tb((.0193339*t+.119192*e+.9503041*i)/tg.Zn)]})(e,i,r),o=116*s-16;return[o<0?0:o,500*(n-s),200*(s-l)]};D.prototype.lab=function(){return tv(this._rgb)},P.lab=(...t)=>new D(...t,"lab"),O.format.lab=tf,O.autodetect.push({p:2,test:(...t)=>{if("array"===C(t=N(t,"lab"))&&3===t.length)return"lab"}});let{sin:tw,cos:ty}=Math,tS=(...t)=>{let[e,i,r]=N(t,"lch");return isNaN(r)&&(r=0),[e,ty(r*=B)*i,tw(r)*i]},tx=(...t)=>{let[e,i,r]=t=N(t,"lch"),[n,s,l]=tS(e,i,r),[o,a,h]=tf(n,s,l);return[o,a,h,t.length>3?t[3]:1]},{sqrt:tA,atan2:tC,round:tN}=Math,tR=(...t)=>{let[e,i,r]=N(t,"lab"),n=tA(i*i+r*r),s=(tC(r,i)*L+360)%360;return 0===tN(1e4*n)&&(s=NaN),[e,n,s]},tE=(...t)=>{let[e,i,r]=N(t,"rgb"),[n,s,l]=tv(e,i,r);return tR(n,s,l)};D.prototype.lch=function(){return tE(this._rgb)},D.prototype.hcl=function(){return tE(this._rgb).reverse()},P.lch=(...t)=>new D(...t,"lch"),P.hcl=(...t)=>new D(...t,"hcl"),O.format.lch=tx,O.format.hcl=(...t)=>tx(...N(t,"hcl").reverse()),["lch","hcl"].forEach(t=>O.autodetect.push({p:2,test:(...e)=>{if("array"===C(e=N(e,t))&&3===e.length)return t}}));let tI={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",laserlemon:"#ffff54",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrod:"#fafad2",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",maroon2:"#7f0000",maroon3:"#b03060",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",purple2:"#7f007f",purple3:"#a020f0",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",s
1almon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};D.prototype.name=function(){let t=ti(this._rgb,"rgb");for(let e of Object.keys(tI))if(tI[e]===t)return e.toLowerCase();return t},O.format.named=t=>{if(tI[t=t.toLowerCase()])return tt(tI[t]);throw Error("unknown color name: "+t)},O.autodetect.push({p:5,test:(t,...e)=>{if(!e.length&&"string"===C(t)&&tI[t.toLowerCase()])return"named"}}),D.prototype.num=function(){return((...t)=>{let[e,i,r]=N(t,"rgb");return(e<<16)+(i<<8)+r})(this._rgb)},P.num=(...t)=>new D(...t,"num"),O.format.num=t=>{if("number"==C(t)&&t>=0&&t<=0xffffff)return[t>>16,t>>8&255,255&t,1];throw Error("unknown num color: "+t)},O.autodetect.push({p:5,test:(...t)=>{if(1===t.length&&"number"===C(t[0])&&t[0]>=0&&t[0]<=0xffffff)return"num"}});let{round:tM}=Math;D.prototype.rgb=function(t=!0){return!1===t?this._rgb.slice(0,3):this._rgb.slice(0,3).map(tM)},D.prototype.rgba=function(t=!0){return this._rgb.slice(0,4).map((e,i)=>i<3?!1===t?e:tM(e):e)},P.rgb=(...t)=>new D(...t,"rgb"),O.format.rgb=(...t)=>{let e=N(t,"rgba");return void 0===e[3]&&(e[3]=1),e},O.autodetect.push({p:3,test:(...t)=>{if("array"===C(t=N(t,"rgba"))&&(3===t.length||4===t.length&&"number"==C(t[3])&&t[3]>=0&&t[3]<=1))return"rgb"}});let{log:tk}=Math,tT=t=>{let e,i,r,n=t/100;return n<66?(e=255,i=n<6?0:-155.25485562709179-.44596950469579133*(i=n-2)+104.49216199393888*tk(i),r=n<20?0:-254.76935184120902+.8274096064007395*(r=n-10)+115.67994401066147*tk(r)):(e=351.97690566805693+.114206453784165*(e=n-55)-40.25366309332127*tk(e),i=325.4494125711974+.07943456536662342*(i=n-50)-28.0852963507957*tk(i),r=255),[e,i,r,1]},{round:tB}=Math;D.prototype.temp=D.prototype.kelvin=D.prototype.temperature=function(){return((...t)=>{let e,i=N(t,"rgb"),r=i[0],n=i[2],s=1e3,l=4e4;for(;l-s>.4;){let t=tT(e=(l+s)*.5);t[2]/t[0]>=n/r?l=e:s=e}return tB(e)})(this._rgb)},P.temp=P.kelvin=P.temperature=(...t)=>new D(...t,"temp"),O.format.temp=O.format.kelvin=O.format.temperature=tT;let{pow:tL,sign:tO}=Math,tD=(...t)=>{let[e,i,r]=t=N(t,"lab"),n=tL(e+.3963377774*i+.2158037573*r,3),s=tL(e-.1055613458*i-.0638541728*r,3),l=tL(e-.0894841775*i-1.291485548*r,3);return[255*tP(4.0767416621*n-3.3077115913*s+.2309699292*l),255*tP(-1.2684380046*n+2.6097574011*s-.3413193965*l),255*tP(-.0041960863*n-.7034186147*s+1.707614701*l),t.length>3?t[3]:1]};function tP(t){let e=Math.abs(t);return e>.0031308?(tO(t)||1)*(1.055*tL(e,1/2.4)-.055):12.92*t}let{cbrt:tz,pow:tF,sign:tH}=Math,t_=(...t)=>{let[e,i,r]=N(t,"rgb"),[n,s,l]=[tW(e/255),tW(i/255),tW(r/255)],o=tz(.4122214708*n+.5363325363*s+.0514459929*l),a=tz(.2119034982*n+.6806995451*s+.1073969566*l),h=tz(.0883024619*n+.2817188376*s+.6299787005*l);return[.2104542553*o+.793617785*a-.0040720468*h,1.9779984951*o-2.428592205*a+.4505937099*h,.0259040371*o+.7827717662*a-.808675766*h]};function tW(t){let e=Math.abs(t);return e<.04045?t/12.92:(tH(t)||1)*tF((e+.055)/1.055,2.4)}D.prototype.oklab=function(){return t_(this._rgb)},P.oklab=(...t)=>new D(...t,"oklab"),O.format.oklab=tD,O.autodetect.push({p:3,test:(...t)=>{if("array"===C(t=N(t,"oklab"))&&3===t.length)return"oklab"}}),D.prototype.oklch=function(){return((...t)=>{let[e,i,r]=N(t,"rgb"),[n,s,l]=t_(e,i,r);return tR(n,s,l)})(this._rgb)},P.oklch=(...t)=>new D(...t,"oklch"),O.format.oklch=(...t)=>{let[e,i,r]=t=N(t,"lch"),[n,s,l]=tS(e,i,r),[o,a,h]=tD(n,s,l);return[o,a,h,t.length>3?t[3]:1]},O.autodetect.push({p:3,test:(...t)=>{if("array"===C(t=N(t,"oklch"))&&3===t.length)return"oklch"}}),D.prototype.alpha=function(t,e=!1){return void 0!==t&&"number"===C(t)?e?(this._rgb[3]=t,this):new D([this._rgb[0],this._rgb[1],this._rgb[2],t],"rgb"):this._rgb[3]},D.prototype.clipped=function(){return this._rgb._clipped||!1},D.prototype.darken=function(t=1){let e=this.lab();return e[0]-=tg.Kn*t,new D(e,"lab").alpha(this.alpha(),!0)},D.prototype.brighten=function(t=1){return this.darken(-t)},D.prototype.darker=D.prototype.darken,D.prototype.brighter=D.prototype.brighten,D.prototype.get=function(t){let[e,i]=t.split("."),r=this[e]();if(!i)return r;{let t=e.indexOf(i)-2*("ok"===e.substr(0,2));if(t>-1)return r[t];throw Error(`unknown channel ${i} in mode ${e}`)}};let{pow:tV}=Math;D.prototype.luminance=function(t,e="rgb"){if(void 0!==t&&"number"===C(t)){if(0===t)return new D([0,0,0,this._rgb[3]],"rgb");if(1===t)return new D([255,255,255,this._rgb[3]],"rgb");let i=this.luminance(),r=20,n=(i,s)=>{let l=i.interpolate(s,.5,e),o=l.luminance();return!(1e-7>Math.abs(t-o))&&r--?o>t?n(i,l):n(l,s):l},s=(i>t?n(new D([0,0,0]),this):n(this,new D([255,255,255]))).rgb();return new D([...s,this._rgb[3]])}return tU(...this._rgb.slice(0,3))};
vendor: 5,323 bytes, line 1
1let tU=(t,e,i)=>(t=tX(t),.2126*t+.7152*(e=tX(e))+.0722*(i=tX(i))),tX=t=>(t/=255)<=.03928?t/12.92:tV((t+.055)/1.055,2.4),tG={},tY=(t,e,i=.5,...r)=>{let n=r[0]||"lrgb";if(tG[n]||r.length||(n=Object.keys(tG)[0]),!tG[n])throw Error(`interpolation mode ${n} is not defined`);return"object"!==C(t)&&(t=new D(t)),"object"!==C(e)&&(e=new D(e)),tG[n](t,e,i).alpha(t.alpha()+i*(e.alpha()-t.alpha()))};D.prototype.mix=D.prototype.interpolate=function(t,e=.5,...i){return tY(this,t,e,...i)},D.prototype.premultiply=function(t=!1){let e=this._rgb,i=e[3];return t?(this._rgb=[e[0]*i,e[1]*i,e[2]*i,i],this):new D([e[0]*i,e[1]*i,e[2]*i,i],"rgb")},D.prototype.saturate=function(t=1){let e=this.lch();return e[1]+=tg.Kn*t,e[1]<0&&(e[1]=0),new D(e,"lch").alpha(this.alpha(),!0)},D.prototype.desaturate=function(t=1){return this.saturate(-t)},D.prototype.set=function(t,e,i=!1){let[r,n]=t.split("."),s=this[r]();if(!n)return s;{let t=r.indexOf(n)-2*("ok"===r.substr(0,2));if(t>-1){if("string"==C(e))switch(e.charAt(0)){case"+":case"-":s[t]+=+e;break;case"*":s[t]*=e.substr(1);break;case"/":s[t]/=e.substr(1);break;default:s[t]=+e}else if("number"===C(e))s[t]=e;else throw Error("unsupported value for Color.set");let n=new D(s,r);return i?(this._rgb=n._rgb,this):n}throw Error(`unknown channel ${n} in mode ${r}`)}},D.prototype.tint=function(t=.5,...e){return tY(this,"white",t,...e)},D.prototype.shade=function(t=.5,...e){return tY(this,"black",t,...e)},tG.rgb=(t,e,i)=>{let r=t._rgb,n=e._rgb;return new D(r[0]+i*(n[0]-r[0]),r[1]+i*(n[1]-r[1]),r[2]+i*(n[2]-r[2]),"rgb")};let{sqrt:tq,pow:tj}=Math;tG.lrgb=(t,e,i)=>{let[r,n,s]=t._rgb,[l,o,a]=e._rgb;return new D(tq(tj(r,2)*(1-i)+tj(l,2)*i),tq(tj(n,2)*(1-i)+tj(o,2)*i),tq(tj(s,2)*(1-i)+tj(a,2)*i),"rgb")},tG.lab=(t,e,i)=>{let r=t.lab(),n=e.lab();return new D(r[0]+i*(n[0]-r[0]),r[1]+i*(n[1]-r[1]),r[2]+i*(n[2]-r[2]),"lab")};let t$=(t,e,i,r)=>{let n,s,l,o,a,h,g,d,u,c,f,p;return"hsl"===r?(n=t.hsl(),s=e.hsl()):"hsv"===r?(n=t.hsv(),s=e.hsv()):"hcg"===r?(n=t.hcg(),s=e.hcg()):"hsi"===r?(n=t.hsi(),s=e.hsi()):"lch"===r||"hcl"===r?(r="hcl",n=t.hcl(),s=e.hcl()):"oklch"===r&&(n=t.oklch().reverse(),s=e.oklch().reverse()),("h"===r.substr(0,1)||"oklch"===r)&&([l,a,g]=n,[o,h,d]=s),isNaN(l)||isNaN(o)?isNaN(l)?isNaN(o)?c=NaN:(c=o,(1==g||0==g)&&"hsv"!=r&&(u=h)):(c=l,(1==d||0==d)&&"hsv"!=r&&(u=a)):(p=o>l&&o-l>180?o-(l+360):o<l&&l-o>180?o+360-l:o-l,c=l+i*p),void 0===u&&(u=a+i*(h-a)),f=g+i*(d-g),"oklch"===r?new D([f,u,c],r):new D([c,u,f],r)},tK=(t,e,i)=>t$(t,e,i,"lch");tG.lch=tK,tG.hcl=tK,tG.num=(t,e,i)=>{let r=t.num();return new D(r+i*(e.num()-r),"num")},tG.hcg=(t,e,i)=>t$(t,e,i,"hcg"),tG.hsi=(t,e,i)=>t$(t,e,i,"hsi"),tG.hsl=(t,e,i)=>t$(t,e,i,"hsl"),tG.hsv=(t,e,i)=>t$(t,e,i,"hsv"),tG.oklab=(t,e,i)=>{let r=t.oklab(),n=e.oklab();return new D(r[0]+i*(n[0]-r[0]),r[1]+i*(n[1]-r[1]),r[2]+i*(n[2]-r[2]),"oklab")},tG.oklch=(t,e,i)=>t$(t,e,i,"oklch");let{pow:tZ,sqrt:tJ,PI:tQ,cos:t0,sin:t1,atan2:t2}=Math,{pow:t5}=Math;function t3(t){let e="rgb",i=P("#ccc"),r=0,n=[0,1],s=[],l=[0,0],o=!1,a=[],h=!1,g=0,d=1,u=!1,c={},f=!0,p=1,m=function(t){if("string"===C(t=t||["#fff","#000"])&&P.brewer&&P.brewer[t.toLowerCase()]&&(t=P.brewer[t.toLowerCase()]),"array"===C(t)){1===t.length&&(t=[t[0],t[0]]),t=t.slice(0);for(let e=0;e<t.length;e++)t[e]=P(t[e]);s.length=0;for(let e=0;e<t.length;e++)s.push(e/(t.length-1))}return x(),a=t},b=function(t){if(null!=o){let e=o.length-1,i=0;for(;i<e&&t>=o[i];)i++;return i-1}return 0},v=t=>t,w=t=>t,y=function(t,r){let n,h;if(null==r&&(r=!1),isNaN(t)||null===t)return i;h=r?t:o&&o.length>2?b(t)/(o.length-2):d!==g?(t-g)/(d-g):1,h=w(h),r||(h=v(h)),1!==p&&(h=t5(h,p));let u=Math.floor(1e4*(h=S(h=l[0]+h*(1-l[0]-l[1]),0,1)));if(f&&c[u])n=c[u];else{if("array"===C(a))for(let t=0;t<s.length;t++){let i=s[t];if(h<=i||h>=i&&t===s.length-1){n=a[t];break}if(h>i&&h<s[t+1]){h=(h-i)/(s[t+1]-i),n=P.interpolate(a[t],a[t+1],h,e);break}}else"function"===C(a)&&(n=a(h));f&&(c[u]=n)}return n};var x=()=>c={};m(t);let A=function(t){let e=P(y(t));return h&&e[h]?e[h]():e};return A.classes=function(t){if(null!=t){if("array"===C(t))o=t,n=[t[0],t[t.length-1]];else{let e=P.analyze(n);o=0===t?[e.min,e.max]:P.limits(e,"e",t)}return A}return o},A.domain=function(t){if(!arguments.length)return n;g=t[0],d=t[t.length-1],s=[];let e=a.length;if(t.length===e&&g!==d)for(let e of Array.from(t))s.push((e-g)/(d-g));else{for(let t=0;t<e;t++)s.push(t/(e-1));if(t.length>2){let e=t.map((e,i)=>i/(t.length-1)),i=t.map(t=>(t-g)/(d-g));i.every((t,i)=>e[i]===t)||(w=t=>{if(t<=0||t>=1)return t;let r=0;for(;t>=i[r+1];)r++;let n=(t-i[r])/(i[r+1]-i[r]);return e[r]+n*(e[r+1]-e[r])})}}return n=[g,d],A},A.mode=function(t){return arguments.length?(e=t,x(),A):e},A.range=function(t,e){return m(t,e),A},A.out=function(t){return h=t,A},A.spread=function(t){return arguments.length?(r=t,A):r},A.correctLightness=function(t){return null==t&&(t=!0),u=t,x(),v=u?function(t){let e=y(0,!0).lab()[0],i=y(1,!0).lab()[0],r=e>i,n=y(t,!0).lab()[0],s=e+(i-e)*t,l=n-s,o=0,a=1,h=20;for(;Math.abs(l)>.01&&h-- >0;)r&&(l*=-1),l<0?(o=t,t+=(a-t)*.5):(a=t,t+=(o-t)*.5),l=(n=y(t,!0).lab()[0])-s;return t}:t=>t,A},A.padding=function(t){return null!=t?("number"===C(t)&&(t=[t,t]),l=t,A):l},A.colors=function(e,i){arguments.length<2&&(i="hex");let r=[];if(0==arguments.length)r=a.slice(0);else if(1===e)r=[A(.5)];else if(e>1){let t=n[0],i=n[1]-t;
1r=(function(t,e,i){let r=[],n=0<e,s=i?n?e+1:e-1:e;for(let e=t;n?e<s:e>s;n?e++:e--)r.push(e);return r})(0,e,!1).map(r=>A(t+r/(e-1)*i))}else{t=[];let e=[];if(o&&o.length>2)for(let t=1,i=o.length,r=1<=i;r?t<i:t>i;r?t++:t--)e.push((o[t-1]+o[t])*.5);else e=n;r=e.map(t=>A(t))}return P[i]&&(r=r.map(t=>t[i]())),r},A.cache=function(t){return null!=t?(f=t,A):f},A.gamma=function(t){return null!=t?(p=t,A):p},A.nodata=function(t){return null!=t?(i=P(t),A):i},A}let t6=function(t){let e=[1,1];for(let i=1;i<t;i++){let t=[1];for(let i=1;i<=e.length;i++)t[i]=(e[i]||0)+e[i-1];e=t}return e},t4=function(t){let e,i,r,n;if(2===(t=t.map(t=>new D(t))).length)[i,r]=t.map(t=>t.lab()),e=function(t){return new D([0,1,2].map(e=>i[e]+t*(r[e]-i[e])),"lab")};else if(3===t.length)[i,r,n]=t.map(t=>t.lab()),e=function(t){return new D([0,1,2].map(e=>(1-t)*(1-t)*i[e]+2*(1-t)*t*r[e]+t*t*n[e]),"lab")};else if(4===t.length){let s;[i,r,n,s]=t.map(t=>t.lab()),e=function(t){return new D([0,1,2].map(e=>(1-t)*(1-t)*(1-t)*i[e]+3*(1-t)*(1-t)*t*r[e]+3*(1-t)*t*t*n[e]+t*t*t*s[e]),"lab")}}else if(t.length>=5){let i,r,n;i=t.map(t=>t.lab()),r=t6(n=t.length-1),e=function(t){let e=1-t;return new D([0,1,2].map(s=>i.reduce((i,l,o)=>i+r[o]*e**(n-o)*t**o*l[s],0)),"lab")}}else throw RangeError("No point in running bezier with only one color.");return e},t9=(t,e,i)=>{if(!t9[i])throw Error("unknown blend mode "+i);return t9[i](t,e)},t8=t=>(e,i)=>{let r=P(i).rgb(),n=P(e).rgb();
vendor: 6,379 bytes, line 1
1return P.rgb(t(r,n))},t7=t=>(e,i)=>{let r=[];return r[0]=t(e[0],i[0]),r[1]=t(e[1],i[1]),r[2]=t(e[2],i[2]),r};t9.normal=t8(t7(t=>t)),t9.multiply=t8(t7((t,e)=>t*e/255)),t9.screen=t8(t7((t,e)=>255*(1-(1-t/255)*(1-e/255)))),t9.overlay=t8(t7((t,e)=>e<128?2*t*e/255:255*(1-2*(1-t/255)*(1-e/255)))),t9.darken=t8(t7((t,e)=>t>e?e:t)),t9.lighten=t8(t7((t,e)=>t>e?t:e)),t9.dodge=t8(t7((t,e)=>255===t||(t=e/255*255/(1-t/255))>255?255:t)),t9.burn=t8(t7((t,e)=>255*(1-(1-e/255)/(t/255))));let{pow:et,sin:ee,cos:ei}=Math,{floor:er,random:en}=Math,{log:es,pow:el,floor:eo,abs:ea}=Math;function eh(t,e=null){let i={min:Number.MAX_VALUE,max:-1*Number.MAX_VALUE,sum:0,values:[],count:0};return"object"===C(t)&&(t=Object.values(t)),t.forEach(t=>{e&&"object"===C(t)&&(t=t[e]),null==t||isNaN(t)||(i.values.push(t),i.sum+=t,t<i.min&&(i.min=t),t>i.max&&(i.max=t),i.count+=1)}),i.domain=[i.min,i.max],i.limits=(t,e)=>eg(i,t,e),i}function eg(t,e="equal",i=7){"array"==C(t)&&(t=eh(t));let{min:r,max:n}=t,s=t.values.sort((t,e)=>t-e);if(1===i)return[r,n];let l=[];if("c"===e.substr(0,1)&&(l.push(r),l.push(n)),"e"===e.substr(0,1)){l.push(r);for(let t=1;t<i;t++)l.push(r+t/i*(n-r));l.push(n)}else if("l"===e.substr(0,1)){if(r<=0)throw Error("Logarithmic scales are only possible for values > 0");let t=Math.LOG10E*es(r),e=Math.LOG10E*es(n);l.push(r);for(let r=1;r<i;r++)l.push(el(10,t+r/i*(e-t)));l.push(n)}else if("q"===e.substr(0,1)){l.push(r);for(let t=1;t<i;t++){let e=(s.length-1)*t/i,r=eo(e);if(r===e)l.push(s[r]);else{let t=e-r;l.push(s[r]*(1-t)+s[r+1]*t)}}l.push(n)}else if("k"===e.substr(0,1)){let t,e=s.length,o=Array(e),a=Array(i),h=!0,g=0,d=null;(d=[]).push(r);for(let t=1;t<i;t++)d.push(r+t/i*(n-r));for(d.push(n);h;){for(let t=0;t<i;t++)a[t]=0;for(let t=0;t<e;t++){let e,r=s[t],n=Number.MAX_VALUE;for(let s=0;s<i;s++){let i=ea(d[s]-r);i<n&&(n=i,e=s),a[e]++,o[t]=e}}let r=Array(i);for(let t=0;t<i;t++)r[t]=null;for(let i=0;i<e;i++)null===r[t=o[i]]?r[t]=s[i]:r[t]+=s[i];for(let t=0;t<i;t++)r[t]*=1/a[t];h=!1;for(let t=0;t<i;t++)if(r[t]!==d[t]){h=!0;break}d=r,++g>200&&(h=!1)}let u={};for(let t=0;t<i;t++)u[t]=[];for(let i=0;i<e;i++)u[t=o[i]].push(s[i]);let c=[];for(let t=0;t<i;t++)c.push(u[t][0]),c.push(u[t][u[t].length-1]);c=c.sort((t,e)=>t-e),l.push(c[0]);for(let t=1;t<c.length;t+=2){let e=c[t];isNaN(e)||-1!==l.indexOf(e)||l.push(e)}}return l}let{sqrt:ed,pow:eu,min:ec,max:ef,atan2:ep,abs:em,cos:eb,sin:ev,exp:ew,PI:ey}=Math,eS={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"]};for(let t of Object.keys(eS))eS[t.toLowerCase()]=eS[t];Object.assign(P,{average:(t,e="lrgb",i=null)=>{let r=t.length;i||(i=Array.from(Array(r)).map(()=>1));let n=r/i.reduce(function(t,e){return t+e});if(i.forEach((t,e)=>{i[e]*=n}
1),t=t.map(t=>new D(t)),"lrgb"===e)return((t,e)=>{let i=t.length,r=[0,0,0,0];for(let n=0;n<t.length;n++){let s=t[n],l=e[n]/i,o=s._rgb;r[0]+=tZ(o[0],2)*l,r[1]+=tZ(o[1],2)*l,r[2]+=tZ(o[2],2)*l,r[3]+=o[3]*l}return r[0]=tJ(r[0]),r[1]=tJ(r[1]),r[2]=tJ(r[2]),r[3]>.9999999&&(r[3]=1),new D(x(r))})(t,i);let s=t.shift(),l=s.get(e),o=[],a=0,h=0;for(let t=0;t<l.length;t++)if(l[t]=(l[t]||0)*i[0],o.push(isNaN(l[t])?0:i[0]),"h"===e.charAt(t)&&!isNaN(l[t])){let e=l[t]/180*tQ;a+=t0(e)*i[0],h+=t1(e)*i[0]}let g=s.alpha()*i[0];t.forEach((t,r)=>{let n=t.get(e);g+=t.alpha()*i[r+1];for(let t=0;t<l.length;t++)if(!isNaN(n[t]))if(o[t]+=i[r+1],"h"===e.charAt(t)){let e=n[t]/180*tQ;a+=t0(e)*i[r+1],h+=t1(e)*i[r+1]}else l[t]+=n[t]*i[r+1]});for(let t=0;t<l.length;t++)if("h"===e.charAt(t)){let e=t2(h/o[t],a/o[t])/tQ*180;for(;e<0;)e+=360;for(;e>=360;)e-=360;l[t]=e}else l[t]=l[t]/o[t];return g/=r,new D(l,e).alpha(g>.99999?1:g,!0)},bezier:t=>{let e=t4(t);return e.scale=()=>t3(e),e},blend:t9,cubehelix:function(t=300,e=-1.5,i=1,r=1,n=[0,1]){let s=0,l;"array"===C(n)?l=n[1]-n[0]:(l=0,n=[n,n]);let o=function(o){let a=k*((t+120)/360+e*o),h=et(n[0]+l*o,r),g=(0!==s?i[0]+o*s:i)*h*(1-h)/2,d=ei(a),u=ee(a);return P(x([255*(h+g*(-.14861*d+1.78277*u)),255*(h+g*(-.29227*d-.90649*u)),255*(h+1.97294*d*g),1]))};return o.start=function(e){return null==e?t:(t=e,o)},o.rotations=function(t){return null==t?e:(e=t,o)},o.gamma=function(t){return null==t?r:(r=t,o)},o.hue=function(t){return null==t?i:("array"===C(i=t)?0==(s=i[1]-i[0])&&(i=i[1]):s=0,o)},o.lightness=function(t){return null==t?n:("array"===C(t)?(n=t,l=t[1]-t[0]):(n=[t,t],l=0),o)},o.scale=()=>P.scale(o),o.hue(i),o},mix:tY,interpolate:tY,random:()=>{let t="#";for(let e=0;e<6;e++)t+="0123456789abcdef".charAt(er(16*en()));return new D(t,"hex")},scale:t3,analyze:eh,contrast:(t,e)=>{t=new D(t),e=new D(e);let i=t.luminance(),r=e.luminance();return i>r?(i+.05)/(r+.05):(r+.05)/(i+.05)},deltaE:function(t,e,i=1,r=1,n=1){var s=function(t){return 360*t/(2*ey)},l=function(t){return 2*ey*t/360};t=new D(t),e=new D(e);let[o,a,h]=Array.from(t.lab()),[g,d,u]=Array.from(e.lab()),c=(o+g)/2,f=(ed(eu(a,2)+eu(h,2))+ed(eu(d,2)+eu(u,2)))/2,p=.5*(1-ed(eu(f,7)/(eu(f,7)+eu(25,7)))),m=a*(1+p),b=d*(1+p),v=ed(eu(m,2)+eu(h,2)),w=ed(eu(b,2)+eu(u,2)),y=(v+w)/2,S=s(ep(h,m)),x=s(ep(u,b)),A=S>=0?S:S+360,C=x>=0?x:x+360,N=em(A-C)>180?(A+C+360)/2:(A+C)/2,R=1-.17*eb(l(N-30))+.24*eb(l(2*N))+.32*eb(l(3*N+6))-.2*eb(l(4*N-63)),E=C-A;E=180>=em(E)?E:C<=A?E+360:E-360,E=2*ed(v*w)*ev(l(E)/2);let I=w-v,M=1+.015*eu(c-50,2)/ed(20+eu(c-50,2)),k=1+.045*y,T=1+.015*y*R,B=30*ew(-eu((N-275)/25,2)),L=-(2*ed(eu(y,7)/(eu(y,7)+eu(25,7))))*ev(2*l(B));return ef(0,ec(100,ed(eu((g-o)/(i*M),2)+eu(I/(r*k),2)+eu(E/(n*T),2)+I/(r*k)*L*(E/(n*T)))))},distance:function(t,e,i="lab"){t=new D(t),e=new D(e);let r=t.get(i),n=e.get(i),s=0;for(let t in r){let e=(r[t]||0)-(n[t]||0);s+=e*e}return Math.sqrt(s)},limits:eg,valid:(...t)=>{try{return new D(...t),!0}catch(t){return!1}},scales:{cool:()=>t3([P.hsl(180,1,.9),P.hsl(250,.7,.4)]),hot:()=>t3(["#000","#f00","#ff0","#fff"],[0,.25,.75,1]).mode("rgb")},input:O,colors:tI,brewer:eS});class ex{setFromArray(t,e){this.points=[],t.forEach(t=>{this.points.push(new l(t[0],t[1]))}),this.weights=[],e.forEach(t=>{this.weights.push(t)})}draw(){let t=[];for(let e=0;e<this.width;e++){let e=[];for(let t=0;t<this.height;t++)e.push(0);t.push(e)}let e=1/(2*this.sigma*this.sigma);for(let i=0;i<this.points.length;i++){let r=this.points[i],n=this.weights[i];for(let i=0;i<this.width;i++)for(let s=0;s<this.height;s++){let l=i-r.x,o=s-r.y,a=n*Math.exp(-((l*l+o*o)*e));t[i][s]+=a}}let i=1;if(!this.normalized){let e=-Number.MAX_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER;for(let i=0;i<this.width;i++)for(let n=0;n<this.height;n++)t[i][n]<r&&(r=t[i][n]),t[i][n]>e&&(e=t[i][n]);i=Math.max(Math.abs(r),Math.abs(e))}let r=P.scale(this.colormap).domain([-1,1]);for(let e=0;e<this.width;e++)for(let n=0;n<this.height;n++){this.normalized||(t[e][n]=t[e][n]/i),0!==this.interval&&(t[e][n]=Math.round(t[e][n]/this.interval)*this.interval);let[s,o,a]=r(t[e][n]).rgb();this.setPixel(new l(e,n),s,o,a)}}getImage(t){let e=new Image;e.onload=()=>
1{this.context.imageSmoothingEnabled=!1,this.context.drawImage(e,0,0,this.width,this.height),t&&t(e)},e.onerror=t=>{console.log(t)},e.src=this.canvas.toDataURL()}getSVG(){return function(t){let e;function i(t,e){let i=t.length;if(0===i||i>0&&i-1 in t)for(let r=0;r<i&&!1!==e.call(t[r],r,t[r]);r++);else for(let i in t)if(!1===e.call(t[i],i,t[i]))break}function r(t){let e=parseInt(t).toString(16);return 1==e.length?"0"+e:e}function n(t,e,i,n){return void 0===(n=parseInt(n))||255===n?"#"+r(t)+r(e)+r(i):0!==n&&"rgba("+t+","+e+","+i+","+n/255+")"}function s(t,e,i){return"M"+t+" "+e+"h"+i}let l=function(t){let e={},i=t.data,r=i.length,n=t.width,s=0,l=0,o;for(let t=0;t<r;t+=4)i[t+3]>0&&(e[o=i[t]+","+i[t+1]+","+i[t+2]+","+i[t+3]]=e[o]||[],s=t/4%n,l=Math.floor(t/4/n),e[o].push([s,l]));return e}(t),o=(e="",i(l,function(t,r){let l;if(!1===(t=n.apply(null,t.split(","))))return;let o=[],a=1;i(r,function(t,e){l&&e[1]===l[1]&&e[0]===l[0]+a?a++:(l&&(o.push(s(l[0],l[1],a)),a=1),l=e)}),o.push(s(l[0],l[1],a)),e+='<path stroke="'+t+'" d="'+o.join("")+'" />\n'}),e),a='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -0.5 '+t.width+" "+t.height+'" shape-rendering="crispEdges"><g shape-rendering="crispEdges">'+o+"</g></svg>",h=document.createElement("div");return h.innerHTML=a,h.firstChild}(this.context.getImageData(0,0,this.width,this.height))}setPixel(t,e,i,r){this.context.fillStyle="rgba("+e+","+i+","+r+","+this.opacity+")",this.context.fillRect(t.x,t.y,1,1)}constructor(t,e,i,r,n=.3,s=0,l=null,o=1,a=!1){this.points=t,this.weights=e,this.width=i,this.height=r,this.sigma=n,this.interval=s,this.opacity=o,this.normalized=a,null===l&&(l=["#c51b7d","#de77ae","#f1b6da","#fde0ef","#ffffff","#e6f5d0","#b8e186","#7fbc41","#4d9221"]),this.colormap=l,this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.canvas.width=this.width,this.canvas.height=this.height}}class eA{constructSvg(){let t=document.createElementNS("http://www.w3.org/2000/svg","defs"),e=document.createElementNS("http://www.w3.org/2000/svg","mask"),i=document.createElementNS("http://www.w3.org/2000/svg","g"),r=document.createElementNS("http://www.w3.org/2000/svg","g"),n=document.createElementNS("http://www.w3.org/2000/svg","g"),s=document.createElementNS("http://www.w3.org/2000/svg","g"),l=this.paths;{let t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttributeNS(null,"x",this.minX),t.setAttributeNS(null,"y",this.minY),t.setAttributeNS(null,"width",this.maxX-this.minX),t.setAttributeNS(null,"height",this.maxY-this.minY),t.setAttributeNS(null,"fill","white"),e.appendChild(t)}for(let t of(e.setAttributeNS(null,"id",this.uid+"-text-mask"),e.setAttributeNS(null,"maskUnits","userSpaceOnUse"),e.setAttributeNS(null,"x",this.minX),e.setAttributeNS(null,"y",this.minY),e.setAttributeNS(null,"width",this.maxX-this.minX),e.setAttributeNS(null,"height",this.maxY-this.minY),l))n.appendChild(t);for(let t of this.backgroundItems)i.appendChild(t);for(let t of this.highlights)r.appendChild(t);for(let t of this.vertices)s.appendChild(t);for(let t of this.maskElements)e.appendChild(t);for(let e of this.gradients)t.appendChild(e);if(n.setAttributeNS(null,"mask","url(#"+this.uid+"-text-mask)"),this.updateViewbox(this.opts.scale),!this.svg)return this.container.appendChild(t),this.container.appendChild(e),this.container.appendChild(i),this.container.appendChild(n),this.container.appendChild(s),this.container;this.svg.appendChild(t),this.svg.appendChild(e),this.svg.appendChild(i),this.svg.appendChild(r),this.svg.appendChild(n),this.svg.appendChild(s)}addLayer(t){this.backgroundItems.push(t.firstChild)}getBondColor(t,e){let i=this.themeManager.getColor(t.value.element),r=this.themeManager.getColor(e.value.element);if(i===r)return i;let n=this.themeManager.getColor("C"),s=t.position.distance(e.position)/this.opts.bondLength;if(s>.9&&s<1.1){if(i===n)return this.getDefaultGradient(e,r,n);if(r===n)return this.getDefaultGradient(t,i,n)}return this.createLinearGradient(t.position,e.position,[["20%",i],["80%",r]])}getDefaultGradient(t,e,i){let r=this.defaultGradients.get(t);return r||(r=this.createRadialGradient(t.position,this.opts.bondLength,[["20%",e||this.themeManager.getColor(t.value.element)],["80%",i||this.themeManager.getColor("C")]]),this.defaultGradients.set(t,r)),r}createRadialGradient(t,e,i){let r=document.createElementNS("http://www.w3.org/2000/svg","radialGradient"),n=this.uid+"-atom-".concat(this.gradientId++);for(let[s,l]of(r.setAttributeNS(null,"id",n),r.setAttributeNS(null,"gradientUnits","userSpaceOnUse"),r.setAttributeNS(null,"cx",t.x),r.setAttributeNS(null,"cy",t.y),r.setAttributeNS(null,"r",e),i)){let t=document.createElementNS("http://www.w3.org/2000/svg","stop");
1t.setAttributeNS(null,"offset",s),t.setAttributeNS(null,"stop-color",l),r.appendChild(t)}return this.gradients.push(r),"url(#".concat(n,")")}createLinearGradient(t,e,i){let r=document.createElementNS("http://www.w3.org/2000/svg","linearGradient"),n=this.uid+"-bond-".concat(this.gradientId++);for(let[s,l]of(r.setAttributeNS(null,"id",n),r.setAttributeNS(null,"gradientUnits","userSpaceOnUse"),r.setAttributeNS(null,"x1",t.x),r.setAttributeNS(null,"y1",t.y),r.setAttributeNS(null,"x2",e.x),r.setAttributeNS(null,"y2",e.y),i)){let t=document.createElementNS("http://www.w3.org/2000/svg","stop");t.setAttributeNS(null,"offset",s),t.setAttributeNS(null,"stop-color",l),r.appendChild(t)}return this.gradients.push(r),"url(#".concat(n,")")}createSubSuperScripts(t,e){let i=document.createElementNS("http://www.w3.org/2000/svg","tspan");return i.setAttributeNS(null,"baseline-shift",e),i.appendChild(document.createTextNode(t)),i.setAttributeNS(null,"class","sub"),i}static createUnicodeCharge(t){return 1===t?"⁺":-1===t?"⁻":t>1?eA.createUnicodeSuperscript(t)+"⁺":t<-1?eA.createUnicodeSuperscript(t)+"⁻":""}determineDimensions(t){for(let e=0;e<t.length;e++){if(!t[e].value.isDrawn)continue;let i=t[e].position;this.maxX<i.x&&(this.maxX=i.x),this.maxY<i.y&&(this.maxY=i.y),this.minX>i.x&&(this.minX=i.x),this.minY>i.y&&(this.minY=i.y)}let e=this.opts.padding;this.maxX+=e,this.maxY+=e,this.minX-=e,this.minY-=e,this.drawingWidth=this.maxX-this.minX,this.drawingHeight=this.maxY-this.minY}updateViewbox(t){let e=this.minX,i=this.minY,r=this.maxX-this.minX,n=this.maxY-this.minY;if(t<=0)if(r>n){let t=r-n;n=r,i-=t/2}else{let t=n-r;r=n,e-=t/2}else this.svg&&(this.svg.style.width=t*r+"px",this.svg.style.height=t*n+"px");this.svg.setAttributeNS(null,"viewBox","".concat(e," ").concat(i," ").concat(r," ").concat(n))}drawBall(t,e,i){let r=this.opts.bondLength/4.5;t-r<this.minX&&(this.minX=t-r),t+r>this.maxX&&(this.maxX=t+r),e-r<this.minY&&(this.minY=e-r),e+r>this.maxY&&(this.maxY=e+r);let n=document.createElementNS("http://www.w3.org/2000/svg","circle");n.setAttributeNS(null,"cx",t),n.setAttributeNS(null,"cy",e),n.setAttributeNS(null,"r",r),n.setAttributeNS(null,"fill",this.themeManager.getColor(i)),this.vertices.push(n)}drawWedge(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"#000",i=t.getLeftVector().clone(),r=t.getRightVector().clone(),n=l.normals(i,r);n[0].normalize(),n[1].normalize();let s=t.getRightChiral(),o=i,a=r;s&&(o=r,a=i);let h=l.add(o,l.multiplyScalar(n[0],this.halfBondThickness)),g=l.add(a,l.multiplyScalar(n[0],3+this.opts.fontSizeLarge/4)),d=l.add(a,l.multiplyScalar(n[1],3+this.opts.fontSizeLarge/4)),u=l.add(o,l.multiplyScalar(n[1],this.halfBondThickness)),c=document.createElementNS("http://www.w3.org/2000/svg","polygon");c.setAttributeNS(null,"points","".concat(h.x,",").concat(h.y," ").concat(g.x,",").concat(g.y," ").concat(d.x,",").concat(d.y," ").concat(u.x,",").concat(u.y)),c.setAttributeNS(null,"fill",e),this.paths.push(c)}drawAtomHighlight(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"#03fc9d",r=document.createElementNS("http://www.w3.org/2000/svg","circle");r.setAttributeNS(null,"cx",t),r.setAttributeNS(null,"cy",e),r.setAttributeNS(null,"r",this.opts.bondLength/3),r.setAttributeNS(null,"fill",i),this.highlights.push(r)}drawDashedWedge(t){let e,i,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"#000";if(isNaN(t.from.x)||isNaN(t.from.y)||isNaN(t.to.x)||isNaN(t.to.y))return void console.error("Invalid line passed to SvgWrapper.drawDashedWedge()!",t);let n=t.getLeftVector().clone(),s=t.getRightVector().clone(),o=l.normals(n,s);o[0].normalize(),o[1].normalize(),t.getRightChiral()?(e=s,i=n):(e=n,i=s);let a=l.subtract(i,e).normalize(),h=t.getLength(),g=1.25/(h/(this.opts.bondLength/10));for(let t=0;t<1;t+=g){let i=l.multiplyScalar(a,t*h),n=l.add(e,i),s=this.opts.fontSizeLarge/2*t,g=l.multiplyScalar(o[0],s);n.subtract(g);let d=n.clone();d.add(l.multiplyScalar(g,2)),this.drawLine(new m(n,d),!1,r)}}drawDebugPoint(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"#f00",n=document.createElementNS("http://www.w3.org/2000/svg","circle");n.setAttributeNS(null,"cx",t),n.setAttributeNS(null,"cy",e),n.setAttributeNS(null,"r","2"),n.setAttributeNS(null,"fill",r),this.vertices.push(n),this.drawDebugText(t+2,e-2,i,r)}drawDebugText(t,e,i){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"#f00",n=document.createElementNS("http://www.w3.org/2000/svg","text");n.setAttributeNS(null,"x",t),n.setAttributeNS(null,"y",e),n.setAttributeNS(null,"class","debug"),n.setAttributeNS(null,"fill",r),n.setAttributeNS(null,"
1style","font: 5px sans-serif"),n.appendChild(document.createTextNode(i)),this.vertices.push(n)}drawRing(t,e,i){let r=document.createElementNS("http://www.w3.org/2000/svg","circle"),n=s.apothemFromSideLength(this.opts.bondLength,i);r.setAttributeNS(null,"cx",t),r.setAttributeNS(null,"cy",e),r.setAttributeNS(null,"r",n-this.opts.bondSpacing),r.setAttributeNS(null,"stroke",this.themeManager.getColor("C")),r.setAttributeNS(null,"stroke-width",this.opts.bondThickness),r.setAttributeNS(null,"fill","none"),this.paths.push(r)}drawLine(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"#000",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"round",n=t.getLeftVector(),s=t.getRightVector(),l=document.createElementNS("http://www.w3.org/2000/svg","line");l.setAttributeNS(null,"x1",n.x),l.setAttributeNS(null,"y1",n.y),l.setAttributeNS(null,"x2",s.x),l.setAttributeNS(null,"y2",s.y),l.setAttributeNS(null,"stroke",i),l.setAttributeNS(null,"stroke-width",this.opts.bondThickness),l.setAttributeNS(null,"stroke-linecap",r),e&&l.setAttributeNS(null,"stroke-dasharray","5,5"),this.paths.push(l)}drawPoint(t,e,i){t-.75<this.minX&&(this.minX=t-.75),t+.75>this.maxX&&(this.maxX=t+.75),e-.75<this.minY&&(this.minY=e-.75),e+.75>this.maxY&&(this.maxY=e+.75);let r=document.createElementNS("http://www.w3.org/2000/svg","circle");r.setAttributeNS(null,"cx",t),r.setAttributeNS(null,"cy",e),r.setAttributeNS(null,"r","1.5"),r.setAttributeNS(null,"fill","black"),this.maskElements.push(r);let n=document.createElementNS("http://www.w3.org/2000/svg","circle");n.setAttributeNS(null,"cx",t),n.setAttributeNS(null,"cy",e),n.setAttributeNS(null,"r",.75),n.setAttributeNS(null,"fill",this.themeManager.getColor(i)),this.vertices.push(n)}drawText(t,e,i,r,n,s,l,o,a){let h=arguments.length>9&&void 0!==arguments[9]?arguments[9]:{},g=[],d=i;for(let t of(0!==l&&null!==l&&(d+=eA.createUnicodeCharge(l)),0!==o&&null!==o&&(d=eA.createUnicodeSuperscript(o)+d),g.push([d,i]),1===r?g.pu
1sh(["H","H"]):r>1&&g.push(["H"+eA.createUnicodeSubscript(r),"H"]),1===l&&"N"===i&&"0O"in h&&"0O-1"in h&&(h={"0O":{element:"O",count:2,hydrogenCount:0,previousElement:"C",charge:""}},l=0),Object.keys(h))){let e=h[t],i=e.element;e.count>1&&(i+=eA.createUnicodeSubscript(e.count)),e.charge&&(i+=eA.createUnicodeCharge(e.charge)),g.push([i,e.element]);let r=e.hydrogenCount*e.count;1===r?g.push(["H","H"]):r>1&&g.push(["H"+eA.createUnicodeSubscript(r),"H"])}this.write(g,n,t,e,1===a)}drawWeights(t,e,i){let r=this.opts.weights.sigma,n=this.opts.weights.colormap,s=null==n?"#4d9221":n[n.length-1],l=null==n?"#c51b7d":n[0],o=document.createElementNS("http://www.w3.org/2000/svg","g");o.setAttributeNS(null,"style","filter:blur(".concat(r/2,"px)")),this.backgroundItems.push(o);for(let n=0;n<t.length;++n){let a=t[n],h=e[n];if(!a)continue;let g=a>0?s:l;g="rgb(from ".concat(g," r g b / ").concat(Math.abs(a)*i,")");let d=document.createElementNS("http://www.w3.org/2000/svg","circle");d.setAttributeNS(null,"cx",h.x),d.setAttributeNS(null,"cy",h.y),d.setAttributeNS(null,"r",r),d.setAttributeNS(null,"fill",g),o.appendChild(d)}}write(t,e,i,r,n){let s=eA.measureText(t[0][1],this.opts.fontSizeLarge,this.opts.fontFamily);"left"===e&&t[0][0]!==t[0][1]&&(s.width=eA.measureText(t[0][0],this.opts.fontSizeLarge,this.opts.fontFamily).width),n?(i+s.width*t.length>this.maxX&&(this.maxX=i+s.width*t.length),i-s.width/2<this.minX&&(this.minX=i-s.width/2),r-s.height<this.minY&&(this.minY=r-s.height),r+s.height>this.maxY&&(this.maxY=r+s.height)):("right"!==e?(i+s.width*t.length>this.maxX&&(this.maxX=i+s.width*t.length),i-s.width*t.length<this.minX&&(this.minX=i-s.width*t.length)):"left"!==e&&(i+s.width*t.length>this.maxX&&(this.maxX=i+s.width*t.length),i-s.width/2<this.minX&&(this.minX=i-s.width/2)),r-s.height<this.minY&&(this.minY=r-s.height),r+s.height>this.maxY&&(this.maxY=r+s.height),"down"===e&&r+.8*s.height*t.length>this.maxY&&(this.maxY=r+.8*s.height*t.length),"up"===e&&r-.8*s.height*t.length<this.minY&&(this.minY=r-.8*s.height*t.length));let l=i,o=document.createElementNS("http://www.w3.org/2000/svg","text");o.setAttributeNS(null,"class","element");let a=document.createElementNS("http://www.w3.org/2000/svg","g");o.setAttributeNS(null,"fill","#ffffff"),"left"===e&&(t=t.reverse()),("right"===e||"down"===e||"up"===e)&&(i-=s.width/2),"left"===e&&(i+=s.width/2),t.forEach((t,i)=>{let r=t[0],n=t[1],s=document.createElementNS("http://www.w3.org/2000/svg","tspan");s.setAttributeNS(null,"fill",this.themeManager.getColor(n)),s.textContent=r,("up"===e||"down"===e)&&(s.setAttributeNS(null,"x","0px"),"up"===e?s.setAttributeNS(null,"y","-".concat(.9*i,"em")):s.setAttributeNS(null,"y","".concat(.9*i,"em"))),o.appendChild(s)}),o.setAttributeNS(null,"data-direction",e),"left"===e||"right"===e?(o.setAttributeNS(null,"dominant-baseline","alphabetic"),o.setAttributeNS(null,"y","0.36em")):o.setAttributeNS(null,"dominant-baseline","central"),"left"===e&&o.setAttributeNS(null,"text-anchor","end"),a.appendChild(o),a.setAttributeNS(null,"style","transform: translateX(".concat(i,"px) translateY(").concat(r,"px)"));let h=.75*this.opts.fontSizeLarge;t[0][1].length>1&&(h=1.1*this.opts.fontSizeLarge);let g=document.createElementNS("http://www.w3.org/2000/svg","circle");g.setAttributeNS(null,"cx",l),g.setAttributeNS(null,"cy",r),g.setAttributeNS(null,"r",h),g.setAttributeNS(null,"fill","black"),this.maskElements.push(g),this.vertices.push(a)}toCanvas(t,e,i){("string"==typeof t||t instanceof String)&&(t=document.getElementById(t));let r=new Image;r.onload=function(){t.width=e,t.height=i,t.getContext("2d").drawImage(r,0,0,e,i)},r.src="data:image/svg+xml;charset-utf-8,"+encodeURIComponent(this.svg.outerHTML)}static createUnicodeSubscript(t){let e="";return t.toString().split("").forEach(t=>{e+=["₀","₁","₂","₃","₄","₅","₆","₇","₈","₉"][parseInt(t)]}),e}static createUnicodeSuperscript(t){let e="";return t.toString().split("").forEach(t=>{let i=parseInt(t);Number.isFinite(i)&&(e+=["⁰","\xb9","\xb2","\xb3","⁴","⁵","⁶","⁷","⁸","⁹"][i])}),e}static replaceNumbersWithSubscript(t){for(let[e,i]of Object.entries({0:"₀",1:"₁",2:"₂",3:"₃",4:"₄",5:"₅",6:"₆",7:"₇",8:"₈",9:"₉"}))t=t.replaceAll(e,i);return t}static measureText(t,e,i){let r=document.createElement("canvas").getContext("2d");if(!r)return eA.estimateTextSize(t,e);let n=e/16;r.font="16pt ".concat(i);let s=r.measureText(t);return{width:(Math.abs(s.actualBoundingBoxLeft)+Math.abs(s.actualBoundingBoxRight))*n,height:(Math.abs(s.actualBoundingBoxAscent)+Math.abs(s.actualBoundingBoxDescent))*n}}static estimateTextSize(t,e){let i=0;for(let e of String(t))" "===e?i+=.35:/[A-Z]/.test(e)?i+=.68:/[a-z]/.test(e)?i+=.56:/[0-9]/.test(e)?i+=.55:i+=.45;return{width:e*i,height:e}}static svgToCanvas(t,e,i,r){let n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;t.setAttributeNS(null,"width",i),t.setAttributeNS(null,"height",r);let s=new Image;return s.onload=function(){e.width=i,e.height=r;let t=e.getContext("2d");t.imageSmoothingEnabled=!1,t.drawImage(s,0,0,i,r),n&&n(e)},s.onerror=function(t){console.log(t)},s.src="data:image/svg+xml;charset-utf-8,"+encodeURIComponent(t.outerHTML),e}static svgToImg(t,e,i,r){let n=document.createElement("canvas");this.svgToCanvas(t,n,i,r,()=>{e.src=n.toDataURL("image/png")})}static writeText(t,e,i,r){let n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Number.MAX_SAFE_INTEGER,s=document.createElementNS("http://www.w3.org/2000/svg","svg"),l=document.createElementNS("http://www.w3.org/2000/svg","style");l.appendChild(document.createTextNode("\n            .text {\n                font: ".concat(i,"pt ").concat(r,";\n                dominant-baseline: alphabetic;\n            }\n        "))),s.appendChild(l);let o=document.createElementNS("http://www.w3.org/2000/svg","text");o.setAttributeNS(null,"class","text");let a=[];t.split("\n").forEach(t=>{if(eA.measureText(t,i,r).width>=n){let e=t.split(" "),s=0;for(let t=0;t<e.length;t++){let l=e.slice(s,t+1).join(" ");eA.measureText(l,i,r).width>n&&t>s&&(a.push(e.slice(s,t).join(" ")),s=t)}s<e.length&&a.push(e.slice(s,e.length).join(" "))}else a.push(t)});let h=0;return a.forEach((t,n)=>{let s=document.createElementNS("http://www.w3.org/2000/svg","tspan");s.setAttributeNS(null,"fill",e.getColor("C")),s.textContent=t,s.setAttributeNS(null,"x","0px"),s.setAttributeNS(null,"y","".concat(n+1,"em")),o.appendChild(s);let l=eA.measureText(t,i,r);h=Math.max(h,l.width)}),o.setAttributeNS(null,"transform","translate(".concat(h/2,", 0)")),o.setAttributeNS(null,"text-anchor","middle"),s.appendChild(o),{svg:s,width:h,height:(a.length+.4)*i*4/3}}constructor(t,e,i,r=!0){if("string"==typeof e||e instanceof String?this.svg=document.getElementById(e):this.svg=e,this.container=null,this.opts=i,this.uid=function(t){let e="",i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=i.length;for(let t=0;t<5;t++)e+=i.charAt(Math.floor(Math.random()*r));return e}(0),this.gradientId=0,this.defaultGradients=new Map,this.backgroundItems=[],this.paths=[],this.vertices=[],this.gradients=[],this.highlights=[],this.drawingWidth=0,this.drawingHeight=0,this.halfBondThickness=this.opts.bondThickness/2,this.themeManager=t,this.maskElements=[],this.maxX=-Number.MAX_VALUE,this.maxY=-Number.MAX_VALUE,this.minX=Number.MAX_VALUE,this.minY=Number.MAX_VALUE,r)for(;this.svg.firstChild;)this.svg.removeChild(this.svg.firstChild);this.style=document.createElementNS("http://www.w3.org/2000/svg","style"),this.style.appendChild(document.createTextNode("\n                .element {\n                    font: ".concat(this.opts.fontSizeLarge,"pt ").concat(this.opts.fontFamily,";\n                }\n                .sub {\n                    font: ").concat(this.opts.fontSizeSmall,"pt ").concat(this.opts.fontFamily,";\n                }\n            "))),this.svg?this.svg.appendChild(this.style):(this.container=document.createElementNS("http://www.w3.org/2000/svg","g"),this.container.appendChild(this.style))}}class eC{draw(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"light",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,n=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:[],l=arguments.length>6&&void 0!==arguments[6]&&arguments[6];null===e||"svg"===e?((e=document.createElementNS("http://www.w3.org/2000/svg","svg")).setAttribute("xmlns","http://www.w3.org/2000/svg"),e.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),e.setAttributeNS(null,"width",this.opts.width),e.setAttributeNS(null,"height",this.opts.height)):e instanceof String&&(e=document.getElementById(e));let o={padding:this.opts.padding,compactDrawing:this.opts.compactDrawing};null!==r&&(this.opts.padding+=this.opts.weights.additionalPadding,this.opts.compactDrawing=!1);let a=this.preprocessor;return a.initDraw(t,i,n,s),!n&&(this.themeManager=new w(this.opts.themes,i),(null===this.svgWrapper||this.clear)&&(this.svgWrapper=new eA(this.themeManager,e,this.opts,this.clear))),a.processGraph(),this.svgWrapper.determineDimensions(a.graph.vertices),this.drawAtomHighlights(a.opts.debug),this.drawEdges(a.opts.debug),this.drawVertices(a.opts.debug),null!==r&&this.drawWeights(r,l),a.opts.debug&&console.debug("SvgDrawer::draw()",{graph:a.graph,rings:a.rings,ringConnections:a.ringConnections}),this.svgWrapper.constructSvg(),null!==r&&(this.opts.padding=o.padding,this.opts.compactDrawing=o.padding),e}drawCanvas(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"light",r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],n=null;n="string"==typeof e||e instanceof String?document.getElementById(e):e;let s=document.createElementNS("http://www.w3.org/2000/svg","svg");return s.setAttribute("xmlns","http://www.w3.org/2000/svg"),s.setAttributeNS(null,"viewBox","0 0 500 500"),s.setAttributeNS(null,"width","500"),s.setAttributeNS(null,"height","500"),s.setAttributeNS(null,"
1style","visibility: hidden: position: absolute; left: -1000px"),document.body.appendChild(s),this.draw(t,s,i,r),this.svgWrapper.toCanvas(n,this.opts.width,this.opts.height),document.body.removeChild(s),e}drawAromaticityRing(t){this.svgWrapper.drawRing(t.center.x,t.center.y,t.getSize())}drawEdges(t){let e=this.preprocessor,i=e.graph,r=e.rings,n=Array(this.preprocessor.graph.edges.length);if(n.fill(!1),i.traverseBF(0,e=>{let r=i.getEdges(e.id);for(let e=0;e<r.length;e++){let i=r[e];n[i]||(n[i]=!0,this.drawEdge(i,t))}}),!e.bridgedRing)for(let t=0;t<r.length;t++){let i=r[t];e.isRingAromatic(i)&&this.drawAromaticityRing(i)}}drawEdge(t,e){let i=this.preprocessor,n=i.opts,s=this.svgWrapper,o=i.graph.edges[t],a=i.graph.vertices[o.sourceId],h=i.graph.vertices[o.targetId],g=a.value.element,d=h.value.element;if((!a.value.isDrawn||!h.value.isDrawn)&&"default"===i.opts.atomVisualization)return;let u=s.getBondColor(a,h),c=a.position,f=h.position,p=i.getEdgeNormals(o),b=r.clone(p);if(b[0].multiplyScalar(10).add(c),b[1].multiplyScalar(10).add(c),"="===o.bondType||"="===i.getRingbondType(a,h)||o.isPartOfAromaticRing&&i.bridgedRing){let t=i.areVerticesInSameRing(a,h),e=i.chooseSide(a,h,b);if(t){let t=i.getLargestOrAromaticCommonRing(a,h).center;p[0].multiplyScalar(n.bondSpacing),p[1].multiplyScalar(n.bondSpacing);let e=null;(e=t.sameSideAs(a.position,h.position,l.add(c,p[0]))?new m(l.add(c,p[0]),l.add(f,p[0]),g,d):new m(l.add(c,p[1]),l.add(f,p[1]),g,d)).shorten(n.bondLength-n.shortBondLength*n.bondLength),s.drawLine(e,o.isPartOfAromaticRing,u),s.drawLine(new m(c,f,g,d),!1,u)}else if(o.center||a.isTerminal()&&h.isTerminal()||0==e.anCount&&e.bnCount>1||0==e.bnCount&&e.anCount>1){this.multiplyNormals(p,n.halfBondSpacing);let t=new m(l.add(c,p[0]),l.add(f,p[0]),g,d),e=new m(l.add(c,p[1]),l.add(f,p[1]),g,d);s.drawLine(t,!1,u),s.drawLine(e,!1,u)}else if(e.sideCount[0]>e.sideCount[1]||e.totalSideCount[0]>e.totalSideCount[1]){this.multiplyNormals(p,n.bondSpacing);let t=new m(l.add(c,p[0]),l.add(f,p[0]),g,d);t.shorten(n.bondLength-n.shortBondLength*n.bondLength),s.drawLine(t,!1,u),s.drawLine(new m(c,f,g,d),!1,u)}else if(e.sideCount[0]<e.sideCount[1]||e.totalSideCount[0]<=e.totalSideCount[1]){this.multiplyNormals(p,n.bondSpacing);let t=new m(l.add(c,p[1]),l.add(f,p[1]),g,d);t.shorten(n.bondLength-n.shortBondLength*n.bondLength),s.drawLine(t,!1,u),s.drawLine(new m(c,f,g,d),!1,u)}}else if("#"===o.bondType){p[0].multiplyScalar(n.bondSpacing/1.5),p[1].multiplyScalar(n.bondSpacing/1.5);let t=new m(l.add(c,p[0]),l.add(f,p[0]),g,d),e=new m(l.add(c,p[1]),l.add(f,p[1]),g,d);s.drawLine(t,!1,u),s.drawLine(e,!1,u),s.drawLine(new m(c,f,g,d),!1,u)}else if("."===o.bondType);else{let t=a.value.isStereoCenter,e=h.value.isStereoCenter;"up"===o.wedge?s.drawWedge(new m(c,f,g,d,t,e),u):"down"===o.wedge?s.drawDashedWedge(new m(c,f,g,d,t,e),u):s.drawLine(new m(c,f,g,d,t,e),!1,u)}if(e){let e=l.midpoint(c,f);s.drawDebugText(e.x,e.y,"e"+t,"#0c0")}}drawAtomHighlights(t){let e=this.preprocessor,i=e.graph,r=this.svgWrapper;for(let t=0;t<i.vertices.length;t++){let n=i.vertices[t],s=n.value;for(let t=0;t<e.highlight_atoms.length;t++){let i=e.highlight_atoms[t];s.class===i[0]&&r.drawAtomHighlight(n.position.x,n.position.y,i[1])}}}drawVertices(t){let e=this.preprocessor,i=e.opts,n=e.graph,s=e.rings,o=this.svgWrapper;for(let e=0;e<n.vertices.length;e++){let s=n.vertices[e],a=s.value,h=0,g=0,d=a.element,u=a.countImplicitHydrogens(),c=s.getTextDirection(n.vertices,a.hasAttachedPseudoElements),f=y.getEffectiveShowCarbonsMode(i),p=("terminal"===f||"C"!==d||!!a.hasAttachedPseudoElements)&&s.isTerminal(),m="C"===a.element;if("C"===d){let t=a.rings&&a.rings.length>0;"none"===f?(m=!0,p=!1):"all"===f?(m=!1,p=!0):"acyclic"!==f||t||(m=!1,p=!0)}if(a.bracket&&(h=a.bracket.charge,g=a.bracket.isotope),(h||g||n.vertices.length<3)&&(m=!1),"allballs"===i.atomVisualization)o.drawBall(s.position.x,s.position.y,d);else if(a.isDrawn&&(!m||a.drawExplicit||p||a.hasAttachedPseudoElements)||1===n.vertices.length)if("default"===i.atomVisualization){let t=a.getAttachedPseudoElements();a.hasAttachedPseudoElements&&n.vertices.length===Object.keys(t).length+1&&(c="right"),o.drawText(s.position.x,s.position.y,d,u,c,p,h,g,n.vertices.length,t)}else"balls"===i.atomVisualization&&o.drawBall(s.position.x,s.position.y,d);else if(2===s.getNeighbourCount()&&!0==s.forcePositioned){let t=n.vertices[s.neighbours[0]].position,e=n.vertices[s.neighbours[1]].position;.1>Math.abs(Math.PI-l.threePointangle(s.position,t,e))&&o.drawPoint(s.position.x,s.position.y,d)}if(t){let t="v"+s.id+" "+r.print(a.ringbonds);o.drawDebugText(s.position.x,s.position.y,t)}}if(i.debug)for(let t=0;t<s.length;t++){let e=s[t].center;o.drawDebugPoint(e.x,e.y,"r"+s[t].id,"#00f")}}drawWeights(t,e){if(!t)return;let i=this.preprocessor.graph.atomIdxToVertexId;t.length<i.length?i=i.slice(0,t.length):t.length>i.length&&(console.warn("More weights (".concat(t.length,") than heavy atoms (").concat(i.length,"); truncating.")),t=t.slice(0,i.length));let r=0,n=0;for(let e=0;e<t.length;++e){let i=t[e];i&&(i<r&&(r=i),i>n&&(n=i))}if(0===r&&0===n)return;if(this.opts.experimentalWeights){let s=i.map(t=>this.preprocessor.graph.vertices[t].position),l=this.opts.weights.opacity;return e||(l/=Math.max(-r,n)),this.svgWrapper.drawWeights(t,s,l)}let s=this.svgWrapper.minX,o=this.svgWrapper.minY,a=new ex(i.map(t=>{let e=this.preprocessor.graph.vertices[t];return new l(e.position.x-s,e.position.y-o)}),t,this.svgWrapper.drawingWidth,this.svgWrapper.drawingHeight,this.opts.weights.sigma,this.opts.weights.interval,this.opts.weights.colormap,this.opts.weights.opacity,e);a.draw();let h=a.getSVG();h.firstChild.setAttributeNS(null,"transform","translate(".concat(s,",").concat(o,")")),this.svgWrapper.addLayer(h)}getTotalOverlapScore(){return this.preprocessor.getTotalOverlapScore()}getMolecularFormula(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return this.preprocessor.getMolecularFormula(t)}multiplyNormals(t,e){t[0].multiplyScalar(e),t[1].multiplyScalar(e)}constructor(t,e=!0){this.preprocessor=new y(t),this.opts=this.preprocessor.opts,this.clear=e,this.svgWrapper=null}}class eN{draw(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"light",r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],s=null,l=null;if((s=e instanceof String?document.getElementById(e.valueOf()):"string"==typeof e?document.getElementById(e):e)instanceof HTMLCanvasElement)l=s;else throw Error("Second argument was not a canvas or the ID of a canvas.");let o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttribute("xmlns","http://www.w3.org/2000/svg"),o.setAttributeNS(null,"viewBox","0 0 "+this.svgDrawer.opts.width+" "+this.svgDrawer.opts.height),o.setAttributeNS(null,"width",this.svgDrawer.opts.width+""),o.setAttributeNS(null,"height",this.svgDrawer.opts.height+""),this.svgDrawer.draw(t,o,i,null,r,n),this.svgDrawer.svgWrapper.toCanvas(l,this.svgDrawer.opts.width,this.svgDrawer.opts.height)}getTotalOverlapScore(){return this.svgDrawer.getTotalOverlapScore()}getMolecularFormula(){return this.svgDrawer.getMolecularFormula()}constructor(t){this.svgDrawer=new eC(t)}}let eR=function(){"use strict";function t(e,i,r,n){this.message=e,this.expected=i,this.found=r,this.location=n,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,t)}function e(){this.constructor=t}return e.prototype=Error.prototype,t.prototype=new e,t.buildMessage=function(t,e){var i={literal:function(t){return'"'+n(t.text)+'"'},class:function(t){var e,i="";for(e=0;e<t.parts.length;e++)i+=t.parts[e]instanceof Array?s(t.parts[e][0])+"-"+s(t.parts[e][1]):s(t.parts[e]);return"["+(t.inverted?"^":"")+i+"]"},any:function(t){return"any character"},end:function(t){return"end of input"},other:function(t){return t.description}};function r(t){return t.charCodeAt(0).toString(16).toUpperCase()}function n(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(t){return"\\x0"+r(t)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(t){return"\\x"+r(t)})}function s(t){return t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(t){return"\\x0"+r(t)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(t){return"\\x"+r(t)})}return"Expected "+function(t){var e,r,n,s=Array(t.length);for(r=0;r<t.length;r++)s[r]=i[(e=t[r]).type](e);if(s.sort(),s.length>0){for(r=1,n=1;r<s.length;r++)s[r-1]!==s[r]&&(s[n]=s[r],n++);s.length=n}switch(s.length){case 1:return s[0];case 2:return s[0]+" or "+s[1];default:return s.slice(0,-1).join(", ")+", or "+s[s.length-1]}}(t)+" but "+(e?'"'+n(e)+'"':"end of input")+" found."},{SyntaxError:t,parse:function(e,i){if(i=void 0!==i?i:{},e.split("(").length-1!=e.split(")").length-1)throw tg("The number of opening parentheses does not match the number of closing parentheses.",0);var r,n,s,l,o={},a={chain:td},h=td,g=function(t){for(var e=[],i=[],r=0;r<t[1].length;r++)e.push(t[1][r]);for(var r=0;r<t[2].length;r++){var n=t[2][r][0]?t[2][r][0]:"-";i.push({bond:n,id:t[2][r][1]})}for(var r=0;r<t[3].length;r++)e.push(t[3][r]);for(var r=0;r<t[6].length;r++)e.push(t[6][r]);return{atom:t[0],isBracket:!!t[0].element,branches:e,branchCount:e.length,ringbonds:i,ringbondCount:i.length,bond:t[4]?t[4]:"-",next:t[5],hasNext:!!t[5]}},d=ts("(",!1),u=ts(")",!1),c=function(t){var e=t[1]?t[1]:"-";return t[2].branchBond=e,t[2]},f=function(t){return t},p=/^[\-=#$:\/\\.]/,m=tl(["-","=","#","$",":","/","\\","."],!1,!1),b=ts("[",!1),v=ts("se",!1),w=ts("as",!1),y=ts("]",!1),S=ts("B",!1),x=ts("r",!1),A=ts("C",!1),C=ts("l",!1),N=/^[NOPSFI]/,R=tl(["N","O","P","S","F","I"],!1,!1),E=/^[bcnops]/,I=tl(["b","c","n","o","p","s"],!1,!1),M=ts("*",!1),k=/^[A-Z]/,T=tl([["A","Z"]],!1,!1),B=/^[a-z]/,L=tl([["a","z"]],!1,!1),O=ts("%",!1),D=/^[1-9]/,P=tl([["1","9"]],!1,!1),z=/^[0-9]/,F=tl([["0","9"]],!1,!1),H=ts("@",!1),_=ts("TH",!1),W=/^[12]/,V=tl(["1","2"],!1,!1),U=ts("AL",!1),X=ts("SP",!1),G=/^[1-3]/,Y=tl([["1","3"]],!1,!1),q=ts("TB",!1),j=ts("OH",!1),$=ts("+",!1),K=ts("-",!1),Z=ts("H",!1),J=ts(":",!1),Q=/^[0]/,tt=tl(["0"],!1,!1),te=0,ti=[{line:1,column:1}],tr=0,tn=[];if("startRule"in i){if(!(i.startRule in a))throw Error("Can't start parsing from rule \""+i.startRule+'".');h=a[i.startRule]}function ts(t,e){return{type:"literal",text:t,ignoreCase:e}}function tl(t,e,i){return{type:"class",parts:t,inverted:e,ignoreCase:i}}function to(t){var i,r=ti[t];if(r)return r;for(i=t-1;!ti[i];)i--;for(r={line:(r=ti[i]).line,column:r.column};i<t;)10===e.charCodeAt(i)?(r.line++,r.column=1):r.column++,i++;return ti[t]=r,r}function ta(t,e){var i=to(t),r=to(e);return{start:{offset:t,line:i.line,column:i.column},end:{offset:e,line:r.line,column:r.column}}}function th(t){te<tr||(te>tr&&(tr=te,tn=[]),tn.push(t))}function tg(e,i){return new t(e,null,null,i)}function td(){var t,i,r,n,s,l,a,h,d,u,c,p,m,E,I,M,O,ti,tr,tn,ts,tl,to,ta,tg,tb,tv,tw,ty,tS,tx,tA,tC,tN,tR,tE,tI,tM,tk,tT,tB,tL,tO,tD,tP,tz,tF,tH,t_,tW,tV,tU,tX,tG,tY;if(t=te,c=te,66===e.charCodeAt(te)?(p="B",te++):(p=o,th(S)),p!==o?(114===e.charCodeAt(te)?(m="r",te++):(m=o,th(x)),m===o&&(m=null),m!==o?c=p=[p,m]:(te=c,c=o)):(te=c,c=o),c===o&&(c=te,67===e.charCodeAt(te)?(p="C",te++):(p=o,th(A)),p!==o?(108===e.charCodeAt(te)?(m="l",te++):(m=o,th(C)),m===o&&(m=null),m!==o?c=p=[p,m]:(te=c,c=o)):(te=c,c=o),c===o&&(N.test(e.charAt(te))?(c=e.charAt(te),te++):(c=o,th(R)))),c!==o&&(c=(E=c).length>1?E.join(""):E),(u=c)===o&&(u=tf())===o&&(I=te,91===e.charCodeAt(te)?(M="[",te++):(M=o,th(b)),M!==o?(tg=te,D.test(e.charAt(te))?(tb=e.charAt(te),te++):(tb=o,th(P)),tb!==o?(z.test(e.charAt(te))?(tv=e.charAt(te),te++):(tv=o,th(F)),tv===o&&(tv=null),tv!==o?(z.test(e.charAt(te))?(tw=e.charAt(te),te++):(tw=o,th(F)),tw===o&&(tw=null),tw!==o?tg=tb=[tb,tv,tw]:(te=tg,tg=o)):(te=tg,tg=o)):(te=tg,tg=o),tg!==o&&(tg=Number(tg.join(""))),(O=tg)===o&&(O=null),O!==o?("se"===e.substr(te,2)?(ti="se",te+=2):(ti=o,th(v)),ti===o&&("as"===e.substr(te,2)?(ti="as",te+=2):(ti=o,th(w)),ti===o&&(ti=tf())===o&&(ty=te,k.test(e.charAt(te))?(tS=e.charAt(te),te++):(tS=o,th(T)),tS!==o?(B.test(e.charAt(te))?(tx=e.charAt(te),te++):(tx=o,th(L)),tx===o&&(tx=null),tx!==o?ty=tS=[tS,tx]:(te=ty,ty=o)):(te=ty,ty=o),ty!==o&&(ty=ty.join("")),(ti=ty)===o)&&(ti=tp())),ti!==o?(tA=te,64===e.charCodeAt(te)?(tC="@",te++):(tC=o,th(H)),tC!==o?(64===e.charCodeAt(te)?(tN="@",te++):(tN=o,th(H)),tN===o&&(tN=te,"TH"===e.substr(te,2)?(tR="TH",te+=2):(tR=o,th(_)),tR!==o?(W.test(e.charAt(te))?(tE=e.charAt(te),te++):(tE=o,th(V)),tE!==o?tN=tR=[tR,tE]:(te=tN,tN=o)):(te=tN,tN=o),tN===o&&(tN=te,"AL"===e.substr(te,2)?(tR="AL",te+=2):(tR=o,th(U)),tR!==o?(W.test(e.charAt(te))?(tE=e.charAt(te),te++):(tE=o,th(V)),tE!==o?tN=tR=[tR,tE]:(te=tN,tN=o)):(te=tN,tN=o),tN===o&&(tN=te,"SP"===e.substr(te,2)?(tR="SP",te+=2):(tR=o,th(X)),tR!==o?(G.test(e.charAt(te))?(tE=e.charAt(te),te++):(tE=o,th(Y)),tE!==o?tN=tR=[tR,tE]:(te=tN,tN=o)):(te=tN,tN=o),tN===o&&(tN=te,"TB"===e.substr(te,2)?(tR="TB",te+=2):(tR=o,th(q)),tR!==o?(D.test(e.charAt(te))?(tE=e.charAt(te),te++):(tE=o,th(P)),tE!==o?(z.test(e.charAt(te))?(tI=e.charAt(te),te++):(tI=o,th(F)),tI===o&&(tI=null),tI!==o?tN=tR=[tR,tE,tI]:(te=tN,tN=o)):(te=tN,tN=o)):(te=tN,tN=o),tN===o&&(tN=te,"OH"===e.substr(te,2)?(tR="OH",te+=2):(tR=o,th(j)),tR!==o?(D.test(e.charAt(te))?(tE=e.charAt(te),te++):(tE=o,th(P)),tE!==o?(z.test(e.charAt(te))?(tI=e.charAt(te),te++):(tI=o,th(F)),tI===o&&(tI=null),tI!==o?tN=tR=[tR,tE,tI]:(te=tN,tN=o)):(te=tN,tN=o)):(te=tN,tN=o)))))),tN===o&&(tN=null),tN!==o?tA=tC=[tC,tN]:(te=tA,tA=o)):(te=tA,tA=o),tA!==o&&(tA=(tM=tA)[1]?"@"==tM[1]?"@@":tM[1].join("").replace(",",""):"@"),(tr=tA)===o&&(tr=null),tr!==o?(tk=te,72===e.charCodeAt(te)?(tT="H",te++):(tT=o,th(Z
1)),tT!==o?(z.test(e.charAt(te))?(tB=e.charAt(te),te++):(tB=o,th(F)),tB===o&&(tB=null),tB!==o?tk=tT=[tT,tB]:(te=tk,tk=o)):(te=tk,tk=o),tk!==o&&(tk=(tL=tk)[1]?Number(tL[1]):1),(tn=tk)===o&&(tn=null),tn!==o?(tD=te,43===e.charCodeAt(te)?(tP="+",te++):(tP=o,th($)),tP!==o?(43===e.charCodeAt(te)?(tz="+",te++):(tz=o,th($)),tz===o&&(tz=te,D.test(e.charAt(te))?(tF=e.charAt(te),te++):(tF=o,th(P)),tF!==o?(z.test(e.charAt(te))?(tH=e.charAt(te),te++):(tH=o,th(F)),tH===o&&(tH=null),tH!==o?tz=tF=[tF,tH]:(te=tz,tz=o)):(te=tz,tz=o)),tz===o&&(tz=null),tz!==o?tD=tP=[tP,tz]:(te=tD,tD=o)):(te=tD,tD=o),tD!==o&&(tD=(t_=tD)[1]?"+"!=t_[1]?Number(t_[1].join("")):2:1),(tO=tD)===o&&(tW=te,45===e.charCodeAt(te)?(tV="-",te++):(tV=o,th(K)),tV!==o?(45===e.charCodeAt(te)?(tU="-",te++):(tU=o,th(K)),tU===o&&(tU=te,D.test(e.charAt(te))?(tX=e.charAt(te),te++):(tX=o,th(P)),tX!==o?(z.test(e.charAt(te))?(tG=e.charAt(te),te++):(tG=o,th(F)),tG===o&&(tG=null),tG!==o?tU=tX=[tX,tG]:(te=tU,tU=o)):(te=tU,tU=o)),tU===o&&(tU=null),tU!==o?tW=tV=[tV,tU]:(te=tW,tW=o)):(te=tW,tW=o),tW!==o&&(tW=(tY=tW)[1]?"-"!=tY[1]?-Number(tY[1].join("")):-2:-1),tO=tW),(ts=tO)===o&&(ts=null),ts!==o?((tl=function(){var t,i,r,n,s,l,a;if(t=te,58===e.charCodeAt(te)?(i=":",te++):(i=o,th(J)),i!==o){if(r=te,D.test(e.charAt(te))?(n=e.charAt(te),te++):(n=o,th(P)),n!==o){for(s=[],z.test(e.charAt(te))?(l=e.charAt(te),te++):(l=o,th(F));l!==o;)s.push(l),z.test(e.charAt(te))?(l=e.charAt(te),te++):(l=o,th(F));s!==o?r=n=[n,s]:(te=r,r=o)}else te=r,r=o;r===o&&(Q.test(e.charAt(te))?(r=e.charAt(te),te++):(r=o,th(tt))),r!==o?t=i=[i,r]:(te=t,t=o)}else te=t,t=o;return t!==o&&(t=Number((a=t)[1][0]+a[1][1].join(""))),t}())===o&&(tl=null),tl!==o?(93===e.charCodeAt(te)?(to="]",te++):(to=o,th(y)),to!==o?I=M=[M,O,ti,tr,tn,ts,tl,to]:(te=I,I=o)):(te=I,I=o)):(te=I,I=o)):(te=I,I=o)):(te=I,I=o)):(te=I,I=o)):(te=I,I=o)):(te=I,I=o),I!==o&&(I={isotope:(ta=I)[1],element:ta[2],chirality:ta[3],hcount:ta[4],charge:ta[5],class:ta[6]}),(u=I)===o)&&(u=tp()),u!==o&&(u=f(u)),(i=u)!==o){for(r=[],n=tu();n!==o;)r.push(n),n=tu();if(r!==o){for(n=[],s=te,(l=tc())===o&&(l=null),l!==o&&(a=tm())!==o?s=l=[l,a]:(te=s,s=o);s!==o;)n.push(s),s=te,(l=tc())===o&&(l=null),l!==o&&(a=tm())!==o?s=l=[l,a]:(te=s,s=o);if(n!==o){for(s=[],l=tu();l!==o;)s.push(l),l=tu();if(s!==o)if((l=tc())===o&&(l=null),l!==o)if((a=td())===o&&(a=null),a!==o){for(h=[],d=tu();d!==o;)h.push(d),d=tu();h!==o?t=i=[i,r,n,s,l,a,h]:(te=t,t=o)}else te=t,t=o;else te=t,t=o;else te=t,t=o}else te=t,t=o}else te=t,t=o}else te=t,t=o;return t!==o&&(t=g(t)),t}function tu(){var t,i,r,n,s;return t=te,40===e.charCodeAt(te)?(i="(",te++):(i=o,th(d)),i!==o?((r=tc())===o&&(r=null),r!==o&&(n=td())!==o?(41===e.charCodeAt(te)?(s=")",te++):(s=o,th(u)),s!==o?t=i=[i,r,n,s]:(te=t,t=o)):(te=t,t=o)):(te=t,t=o),t!==o&&(t=c(t)),t}function tc(){var t;if(p.test(e.charAt(te))){if((t=e.charAt(te))===e.charAt(te+1)&&(t=o,1))throw tg("The parser encountered a bond repetition.",te+1);te++}else t=o,th(m);return t}function tf(){var t;return E.test(e.charAt(te))?(t=e.charAt(te),te++):(t=o,th(I)),t!==o&&(t=f(t)),t}function tp(){var t;return 42===e.charCodeAt(te)?(t="*",te++):(t=o,th(M)),t}function tm(){var t,i,r,n,s;return t=te,37===e.charCodeAt(te)?(i="%",te++):(i=o,th(O)),i!==o?(D.test(e.charAt(te))?(r=e.charAt(te),te++):(r=o,th(P)),r!==o?(z.test(e.charAt(te))?(n=e.charAt(te),te++):(n=o,th(F)),n!==o?t=i=[i,r,n]:(te=t,t=o)):(te=t,t=o)):(te=t,t=o),t===o&&(z.test(e.charAt(te))?(t=e.charAt(te),te++):(t=o,th(F))),t!==o&&(t=1==(s=t).length?Number(s):Number(s.join("").replace("%",""))),t}if((l=h())!==o&&te===e.length)return l;throw l!==o&&te<e.length&&th({type:"end"}),r=tn,n=tr<e.length?e.charAt(tr):null,s=tr<e.length?ta(tr,tr+1):ta(tr,tr),new t(t.buildMessage(r,n),r,n,s)}}}(),eE={C2H4O2:"acetic acid",C3H6O:"acetone",C2H3N:"acetonitrile",C6H6:"benzene",CCl4:"carbon tetrachloride",C6H5Cl:"chlorobenzene",CHCl3:"chloroform",C6H12:"cyclohexane",C2H4Cl2:"1,2-dichloroethane",C4H10O3:"diethylene glycol",C6H14O3:"diglyme",C4H10O2:"DME",C3H7NO:"DMF",C2H6OS:"DMSO",C2H6O:"ethanol",C2H6O2:"ethylene glycol",C3H8O3:"glycerin",C7H16:"heptane",C6H18N3OP:"HMPA",C6H18N3P:"HMPT",C6H14:"hexane",CH4O:"methanol",C5H12O:"MTBE",CH2Cl2:"methylene chloride",CH5H9NO:"NMP",CH3NO2:"nitromethane",C5H12:"pentane",C5H5N:"pyridine",C7H8:"toluene",C6H15N:"triethyl amine",H2O:"water"};class eI{draw(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"light",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"{reagents}",s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"",l=arguments.length>6&&void 0!==arguments[6]&&arguments[6];if(this.themeManager=new w(this.molOpts.themes,i),this.opts.weights.normalize){let t=-Number.MAX_SAFE_INTEGER,e=Number.MAX_SAFE_INTEGER;if("reactants"in r)for(let i=0;i<r.reactants.length;i++)for(let n=0;n<r.reactants[i].length;n++)r.reactants[i][n]<e&&(e=r.reactants[i][n]),r.reactants[i][n]>t&&(t=r.reactants[i][n]);if("reagents"in r)for(let i=0;i<r.reagents.length;i++)for(let n=0;n<r.reagents[i].length;n++)r.reagents[i][n]<e&&(e=r.reagents[i][n]),r.reagents[i][n]>t&&(t=r.reagents[i][n]);if("products"in r)for(let i=0;i<r.products.length;i++)for(let n=0;n<r.products[i].length;n++)r.products[i][n]<e&&(e=r.products[i][n]),r.products[i][n]>t&&(t=r.products[i][n]);let i=Math.max(Math.abs(e),Math.abs(t));if(0===i&&(i=1),"reactants"in r)for(let t=0;t<r.reactants.length;t++)for(let e=0;e<r.reactants[t].length;e++)r.reactants[t][e]/=i;if("reagents"in r)for(let t=0;t<r.reagents.length;t++)for(let e=0;e<r.reagents[t].length;e++)r.reagents[t][e]/=i;if("products"in r)for(let t=0;t<r.products.length;t++)for(let e=0;e<r.products[t].length;e++)r.products[t][e]/=i}let o=null;for(null===e||"svg"===e?((o=document.createElementNS("http://www.w3.org/2000/svg","svg")).setAttribute("xmlns","http://www.w3.org/2000/svg"),o.setAttributeNS(null,"width","500"),o.setAttributeNS(null,"height","500")):o="string"==typeof e||e instanceof String?document.getElementById(e):e;o.firstChild;)o.removeChild(o.firstChild);let a=[],h=0;for(let e=0;e<t.reactants.length;e++){e>0&&a.push({width:this.opts.plus.size*this.opts.scale,height:this.opts.plus.size*this.opts.scale,svg:this.getPlus()});let n=null;r&&"reactants"in r&&r.reactants.length>e&&(n=r.reactants[e]);let s=document.createElementNS("http://www.w3.org/2000/svg","svg");this.drawer.draw(t.reactants[e],s,i,n,l,[],this.opts.weights.normalize);let o={width:s.viewBox.baseVal.width*this.opts.scale,height:s.viewBox.baseVal.height*this.opts.scale,svg:s};a.push(o),o.height>h&&(h=o.height)}a.push({width:this.opts.arrow.length*this.opts.scale,height:this.opts.arrow.headSize*this.opts.scale*2,svg:this.getArrow()});let g="";for(let e=0;e<t.reagents.length;e++){e>0&&(g+=", ");let i=this.drawer.getMolecularFormula(t.reagents[e]);i in eE&&(i=eE[i]),g+=eA.replaceNumbersWithSubscript(i)}n=n.replace("{reagents}",g);let d=eA.writeText(n,this.themeManager,this.opts.fontSize*this.opts.scale,this.opts.fontFamily,this.opts.arrow.length*this.opts.scale),u=(this.opts.arrow.length*this.opts.scale-d.width)/2;a.push({svg:d.svg,height:d.height,width:d.width,offsetX:-(this.opts.arrow.length*this.opts.scale+this.opts.spacing)+u,offsetY:-(d.height/2)-this.opts.arrow.margin,position:"relative"});let c=eA.writeText(s,this.themeManager,this.opts.fontSize*this.opts.scale,this.opts.fontFamily,this.opts.arrow.length*this.opts.scale);u=(this.opts.arrow.length*this.opts.scale-c.width)/2,a.push({svg:c.svg,height:c.height,width:c.width,offsetX:-(this.opts.arrow.length*this.opts.scale+this.opts.spacing)+u,offsetY:c.height/2+this.opts.arrow.margin,position:"relative"});for(let e=0;e<t.products.length;e++){e>0&&a.push({width:this.opts.plus.size*this.opts.scale,height:this.opts.plus.size*this.opts.scale,svg:this.getPlus()});let n=null;r&&"products"in r&&r.products.length>e&&(n=r.products[e]);let s=document.createElementNS("http://www.w3.org/2000/svg","svg");this.drawer.draw(t.products[e],s,i,n,l,[],this.opts.weights.normalize);let o={width:s.viewBox.baseVal.width*this.opts.scale,height:s.viewBox.baseVal.height*this.opts.scale,svg:s};a.push(o),o.height>h&&(h=o.height)}let f=0;return a.forEach(t=>{let e=t.offsetX||0,i=t.offsetY||0;t.svg.setAttributeNS(null,"x",Math.round(f+e)),t.svg.setAttributeNS(null,"y",Math.round((h-t.height)/2+i)),t.svg.setAttributeNS(null,"width",Math.round(t.width)),t.svg.setAttributeNS(null,"height",Math.round(t.height)),o.appendChild(t.svg),"relative"!==t.position&&(f+=Math.round(t.width+this.opts.spacing+e))}),o.setAttributeNS(null,"viewBox","0 0 ".concat(f," ").concat(h)),o.style.width=f+"px",o.style.height=h+"px",o}getPlus(){let t=this.opts.plus.size,e=this.opts.plus.thickness,i=document.createElementNS("http://www.w3.org/2000/svg","svg"),r=document.createElementNS("http://www.w3.org/2000/svg","rect"),n=document.createElementNS("http://www.w3.org/2000/svg","rect");return i.setAttributeNS(null,"id","plus"),r.setAttributeNS(null,"x",0),r.setAttributeNS(null,"y",t/2-e/2),r.setAttributeNS(null,"width",t),r.setAttributeNS(null,"height",e),r.setAttributeNS(null,"fill",this.themeManager.getColor("C")),n.setAttributeNS(null,"x",t/2-e/2),n.setAttributeNS(null,"y",0),n.setAttributeNS(null,"width",e),n.setAttributeNS(null,"height",t),n.setAttributeNS(null,"fill",this.themeManager.getColor("C")),i.appendChild(r),i.appendChild(n),i.setAttributeNS(null,"viewBox","0 0 ".concat(t," ").concat(t)),i}getArrowhead(){let t=this.opts.arrow.headSize,e=document.createElementNS("http://www.w3.org/2000/svg","marker"),i=document.createElementNS("http://www.w3.org/2000/svg","polygon");return e.setAttributeNS(null,"id","arrowhead"),e.setAttributeNS(null,"viewBox","0 0 ".concat(t," ").concat(t)),e.setAttributeNS(null,"markerUnits","userSpaceOnUse"),e.setAttributeNS(null,"markerWidth",t),e.setAttributeNS(null,"markerHeight",t),e.setAttributeNS(null,"refX",0),e.setAttributeNS(null,"refY",t/2),e.setAttributeNS(null,"orient","auto"),e.setAttributeNS(null,"fill",this.themeManager.getColor("C")),i.setAttributeNS(null,"points","0 0, ".concat(t," ").concat(t/2,", 0 ").concat(t)),e.appendChild(i),e}
1getCDArrowhead(){let t=this.opts.arrow.headSize,e=7/4.5*t,i=document.createElementNS("http://www.w3.org/2000/svg","marker"),r=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttributeNS(null,"id","arrowhead"),i.setAttributeNS(null,"viewBox","0 0 ".concat(e," ").concat(t)),i.setAttributeNS(null,"markerUnits","userSpaceOnUse"),i.setAttributeNS(null,"markerWidth",2*e),i.setAttributeNS(null,"markerHeight",2*t),i.setAttributeNS(null,"refX",2.2),i.setAttributeNS(null,"refY",2.2),i.setAttributeNS(null,"orient","auto"),i.setAttributeNS(null,"fill",this.themeManager.getColor("C")),r.setAttributeNS(null,"style","fill-rule:nonzero;"),r.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"),i.appendChild(r),i}getArrow(){let t=this.opts.arrow.headSize,e=this.opts.arrow.length,i=document.createElementNS("http://www.w3.org/2000/svg","svg"),r=document.createElementNS("http://www.w3.org/2000/svg","defs"),n=document.createElementNS("http://www.w3.org/2000/svg","line");return r.appendChild(this.getCDArrowhead()),i.appendChild(r),i.setAttributeNS(null,"id","arrow"),n.setAttributeNS(null,"x1",0),n.setAttributeNS(null,"y1",-this.opts.arrow.thickness/2),n.setAttributeNS(null,"x2",e),n.setAttributeNS(null,"y2",-this.opts.arrow.thickness/2),n.setAttributeNS(null,"stroke-width",this.opts.arrow.thickness),n.setAttributeNS(null,"stroke",this.themeManager.getColor("C")),n.setAttributeNS(null,"marker-end","url(#arrowhead)"),i.appendChild(n),i.setAttributeNS(null,"viewBox","0 ".concat(-t/2," ").concat(e+7/4.5*t," ").concat(t)),i}constructor(t,e){this.drawer=new eC(e),this.molOpts=this.drawer.opts,this.defaultOptions={scale:this.molOpts.scale>0?this.molOpts.scale:1,fontSize:.8*this.molOpts.fontSizeLarge,fontFamily:"Arial, Helvetica, sans-serif",spacing:10,plus:{size:9,thickness:1},arrow:{length:4*this.molOpts.bondLength,headSize:6,thickness:1,margin:3},weights:{normalize:!1}},this.opts=b.extend(!0,this.defaultOptions,t)}}class eM{constructor(t){this.reactantsSmiles=[],this.reagentsSmiles=[],this.productsSmiles=[],this.reactantsWeights=[],this.reagentsWeights=[],this.productsWeights=[],this.reactants=[],this.reagents=[],this.products=[];let e=t.split(">");if(3!==e.length)throw Error('Invalid reaction SMILES: Expected exactly two ">" symbols.');""!==e[0]&&(this.reactantsSmiles=e[0].split(".")),""!==e[1]&&(this.reagentsSmiles=e[1].split(".")),""!==e[2]&&(this.productsSmiles=e[2].split("."));for(let t=0;t<this.reactantsSmiles.length;t++)this.reactants.push(eR.parse(this.reactantsSmiles[t]));for(let t=0;t<this.reagentsSmiles.length;t++)this.reagents.push(eR.parse(this.reagentsSmiles[t]));for(let t=0;t<this.productsSmiles.length;t++)this.products.push(eR.parse(this.productsSmiles[t]))}}class ek{static parse(t){return new eM(t)}}class eT{static apply(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"data-smiles",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"light",n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null;new eT(t,e).apply(i,r,n,s)}apply(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"data-smiles",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"light",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;document.querySelectorAll("[".concat(t,"]")).forEach(n=>{let s=n.getAttribute(t);if(null===s)throw Error("No SMILES provided.");let l=e,o=null;if(n.hasAttribute("data-smiles-theme")&&(l=n.getAttribute("data-smiles-theme")),n.hasAttribute("data-smiles-weights")&&(o=n.getAttribute("data-smiles-weights").split(",").map(parseFloat)),(n.hasAttribute("data-smiles-reactant-weights")||n.hasAttribute("data-smiles-reagent-weights")||n.hasAttribute("data-smiles-product-weights"))&&(o={reactants:[],reagents:[],products:[]},n.hasAttribute("data-smiles-reactant-weights")&&(o.reactants=n.getAttribute("data-smiles-reactant-weights").split(";").map(t=>t.split(",").map(parseFloat))),n.hasAttribute("data-smiles-reagent-weights")&&(o.reagents=n.getAttribute("data-smiles-reagent-weights").split(";").map(t=>t.split(",").map(parseFloat))),n.hasAttribute("data-smiles-product-weights")&&(o.products=n.getAttribute("data-smiles-product-weights").split(";").map(t=>t.split(",").map(parseFloat)))),n.hasAttribute("data-smiles-options")||n.hasAttribute("data-smiles-reaction-options")){let t={};n.hasAttribute("data-smiles-options")&&(t=JSON.parse(n.getAttribute("data-smiles-options").replace(/'/g,'"')));let e={};n.hasAttribute("data-smiles-reaction-options")&&(e=JSON.parse(n.getAttribute("data-smiles-reaction-options").replace(/'/g,'"'))),new eT(t,e).draw(s,n,l,i,r,o)}else this.draw(s,n,l,i,r,o)})}draw(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"light",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,l=[];[t,...l]=t.split(" ");let o=l.join(" "),a={};if(o.includes("__")&&(a=JSON.parse(o.substring(o.indexOf("__")+2,o.lastIndexOf("__")).replace(/'/g,'"'))),a=b.extend(!0,{textAboveArrow:"{reagents}",textBelowArrow:""},a),t.includes(">
1"))try{this.drawReaction(t,e,i,a,s,r)}catch(t){n?n(t):console.error(t)}else try{this.drawMolecule(t,e,i,s,r)}catch(t){n?n(t):console.error(t)}}drawMolecule(t,e,i,r,n){let s=eR.parse(t);if(null===e||"svg"===e){let t=this.drawer.draw(s,null,i,r),e=this.getDimensions(t);t.setAttributeNS(null,"width",""+e.w),t.setAttributeNS(null,"height",""+e.h),n&&n(t)}else if("canvas"===e){let t=this.svgToCanvas(this.drawer.draw(s,null,i,r));n&&n(t)}else if("img"===e){let t=this.svgToImg(this.drawer.draw(s,null,i,r));n&&n(t)}else e instanceof HTMLImageElement?(this.svgToImg(this.drawer.draw(s,null,i,r),e),n&&n(e)):e instanceof SVGElement?(this.drawer.draw(s,e,i,r),n&&n(e)):document.querySelectorAll(e).forEach(t=>{let e=t.nodeName.toLowerCase();"svg"===e?(this.drawer.draw(s,t,i,r),n&&n(t)):"canvas"===e?(this.svgToCanvas(this.drawer.draw(s,null,i,r),t),n&&n(t)):"img"===e&&(this.svgToImg(this.drawer.draw(s,null,i,r),t),n&&n(t))})}drawReaction(t,e,i,r,n,s){let l=ek.parse(t);if(null===e||"svg"===e){let t=this.reactionDrawer.draw(l,null,i),e=this.getDimensions(t);t.setAttributeNS(null,"width",""+e.w),t.setAttributeNS(null,"height",""+e.h),s&&s(t)}else if("canvas"===e){let t=this.svgToCanvas(this.reactionDrawer.draw(l,null,i,n,r.textAboveArrow,r.textBelowArrow));s&&s(t)}else if("img"===e){let t=this.svgToImg(this.reactionDrawer.draw(l,null,i,n,r.textAboveArrow,r.textBelowArrow));s&&s(t)}else e instanceof HTMLImageElement?(this.svgToImg(this.reactionDrawer.draw(l,null,i,n,r.textAboveArrow,r.textBelowArrow),e),s&&s(e)):e instanceof SVGElement?(this.reactionDrawer.draw(l,e,i,n,r.textAboveArrow,r.textBelowArrow),s&&s(e)):document.querySelectorAll(e).forEach(t=>{let e=t.nodeName.toLowerCase();"svg"===e?(this.reactionDrawer.draw(l,t,i,n,r.textAboveArrow,r.textBelowArrow),this.reactionDrawer.opts.scale<=0&&(t.style.width=null,t.style.height=null),s&&s(t)):"canvas"===e?(this.svgToCanvas(this.reactionDrawer.draw(l,null,i,n,r.textAboveArrow,r.textBelowArrow),t),s&&s(t)):"img"===e&&(this.svgToImg(this.reactionDrawer.draw(l,null,i,n,r.textAboveArrow,r.textBelowArrow),t),s&&s(t))})}svgToCanvas(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;null===e&&(e=document.createElement("canvas"));let i=this.getDimensions(e,t);return eA.svgToCanvas(t,e,i.w,i.h),e}svgToImg(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;null===e&&(e=document.createElement("img"));let i=this.getDimensions(e,t);return eA.svgToImg(t,e,i.w,i.h),e}getDimensions(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=this.drawer.opts.width,r=this.drawer.opts.height;return this.drawer.opts.scale<=0?(t instanceof SVGElement||(null===i&&(i=t.width),null===r&&(r=t.height)),""!==t.style.width&&(i=parseInt(t.style.width)),""!==t.style.height&&(r=parseInt(t.style.height))):e&&(i=parseFloat(e.style.width),r=parseFloat(e.style.height)),{w:i,h:r}}constructor(t={},e={}){this.drawer=new eC(t),this.reactionDrawer=new eI(e,JSON.parse(JSON.stringify(this.drawer.opts)))}}let eB={Version:"2.2.1",Drawer:eN,GaussDrawer:ex,Parser:eR,ReactionDrawer:eI,ReactionParser:ek,SmiDrawer:eT,SvgDrawer:eC};eB.clean=function(t){return t.replace(/[^A-Za-z0-9@.+\-?!()[\]{}/\\=#$:*]/g,"")},eB.apply=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"canvas[data-smiles]",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"light",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,n=new eN(t),s=document.querySelectorAll(e);for(var l=0;l<s.length;l++){let t=s[l];eB.parse(t.getAttribute("data-smiles"),function(e){n.draw(e,t,i,!1)},function(t){r&&r(t)})}},eB.parse=function(t,e,i){try{e&&e(eR.parse(t))}catch(t){i&&i(t)}},eB.parseReaction=function(t,e,i){try{e&&e(ek.parse(t))}catch(t){i&&i(t)}},Array.prototype.fill||Object.defineProperty(Array.prototype,"fill",{value:function(t){if(this==null)throw TypeError("this is null or not defined");for(var e=Object(this),i=e.length>>>0,r=arguments[1],n=0|r,s=n<0?Math.max(i+n,0):Math.min(n,i),l=arguments[2],o=void 0===l?i:0|l,a=o<0?Math.max(i+o,0):Math.min(o,i);s<a;)e[s]=t,s++;return e},writeable:!1}),"undefined"!=typeof window&&window.document&&window.document.createElement&&(window.SmilesDrawer=eB,window.SmiDrawer=eT);let eL=eB}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.