aldehyde 0.2.32 → 0.2.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.022b9d9e54b55ad6267e.js +1 -0
- package/dist/bundle.022b9d9e54b55ad6267e.js.gz +0 -0
- package/dist/bundle.03c8826fed3306e7bca7.js +1 -0
- package/dist/bundle.17695fcdfc4d8b13d695.js +2 -0
- package/dist/bundle.17695fcdfc4d8b13d695.js.LICENSE.txt +8 -0
- package/dist/bundle.17695fcdfc4d8b13d695.js.gz +0 -0
- package/dist/bundle.1bc3fad9b6dda01db2dc.js +1 -0
- package/dist/bundle.1bc3fad9b6dda01db2dc.js.gz +0 -0
- package/dist/bundle.26e8ea213610dd77dfc5.js +2 -0
- package/dist/bundle.26e8ea213610dd77dfc5.js.LICENSE.txt +22 -0
- package/dist/bundle.26e8ea213610dd77dfc5.js.gz +0 -0
- package/dist/bundle.2e0aa3d0288f29cd9bdb.js +1 -0
- package/dist/bundle.2e0aa3d0288f29cd9bdb.js.gz +0 -0
- package/dist/bundle.3afd92d0051920d083b8.js +1 -0
- package/dist/bundle.3afd92d0051920d083b8.js.gz +0 -0
- package/dist/bundle.3b47a72a98819ce207b4.js +2 -0
- package/dist/bundle.3b47a72a98819ce207b4.js.LICENSE.txt +14 -0
- package/dist/bundle.3b47a72a98819ce207b4.js.gz +0 -0
- package/dist/bundle.4d91709f680596b4b0ac.js +2 -0
- package/dist/bundle.4d91709f680596b4b0ac.js.LICENSE.txt +9 -0
- package/dist/bundle.4d91709f680596b4b0ac.js.gz +0 -0
- package/dist/bundle.4e6573855d62c2c61293.js +1 -0
- package/dist/bundle.4e6573855d62c2c61293.js.gz +0 -0
- package/dist/bundle.51344a730efffedb67a3.js +2 -0
- package/dist/bundle.51344a730efffedb67a3.js.LICENSE.txt +8 -0
- package/dist/bundle.51344a730efffedb67a3.js.gz +0 -0
- package/dist/bundle.59446aa1a6e81028b0f3.js +1 -0
- package/dist/bundle.59446aa1a6e81028b0f3.js.gz +0 -0
- package/dist/bundle.5c631f42a0bc32bcee42.js +1 -0
- package/dist/bundle.5cc46bd3e80bed3462d0.js +2 -0
- package/dist/bundle.5cc46bd3e80bed3462d0.js.LICENSE.txt +1 -0
- package/dist/bundle.5cc46bd3e80bed3462d0.js.gz +0 -0
- package/dist/bundle.5fc1d01501a8fadd2680.js +2 -0
- package/dist/bundle.5fc1d01501a8fadd2680.js.LICENSE.txt +7 -0
- package/dist/bundle.5fc1d01501a8fadd2680.js.gz +0 -0
- package/dist/bundle.6bf28a6aa5ba025b9cbe.js +2 -0
- package/dist/bundle.6bf28a6aa5ba025b9cbe.js.LICENSE.txt +18 -0
- package/dist/bundle.6bf28a6aa5ba025b9cbe.js.gz +0 -0
- package/dist/bundle.6c63d1f8fd32a2e9ca6c.js +75 -0
- package/dist/bundle.6c63d1f8fd32a2e9ca6c.js.LICENSE.txt +17 -0
- package/dist/bundle.6c63d1f8fd32a2e9ca6c.js.gz +0 -0
- package/dist/bundle.75ca758485013fe73c8a.js +1 -0
- package/dist/bundle.75ca758485013fe73c8a.js.gz +0 -0
- package/dist/bundle.79c75972bdb84e2526a0.js +1 -0
- package/dist/bundle.79c75972bdb84e2526a0.js.gz +0 -0
- package/dist/bundle.7c07c768d6aa85f8cb7f.js +1 -0
- package/dist/bundle.7c07c768d6aa85f8cb7f.js.gz +0 -0
- package/dist/bundle.7e85c36e04f1428d40ae.js +2 -0
- package/dist/bundle.7e85c36e04f1428d40ae.js.LICENSE.txt +17 -0
- package/dist/bundle.7e85c36e04f1428d40ae.js.gz +0 -0
- package/dist/bundle.7fe4c9d6d1fad1b785b4.js +1 -0
- package/dist/bundle.7fe4c9d6d1fad1b785b4.js.gz +0 -0
- package/dist/bundle.8a46aaa80505db8f0a31.js +1 -0
- package/dist/bundle.8a46aaa80505db8f0a31.js.gz +0 -0
- package/dist/bundle.8a6c3026f7b0ad7bdc84.js +2 -0
- package/dist/bundle.8a6c3026f7b0ad7bdc84.js.LICENSE.txt +25 -0
- package/dist/bundle.8a6c3026f7b0ad7bdc84.js.gz +0 -0
- package/dist/bundle.9a888a685a8dc8795cb1.js +1 -0
- package/dist/bundle.9d12b63336a9c8d44a9d.js +1 -0
- package/dist/bundle.9d12b63336a9c8d44a9d.js.gz +0 -0
- package/dist/bundle.a7dfe1231cfa8ef5b0d3.js +2 -0
- package/dist/bundle.a7dfe1231cfa8ef5b0d3.js.LICENSE.txt +5 -0
- package/dist/bundle.a7dfe1231cfa8ef5b0d3.js.gz +0 -0
- package/dist/bundle.be6aaf07219b3f9a361f.js +1 -0
- package/dist/bundle.be6aaf07219b3f9a361f.js.gz +0 -0
- package/dist/bundle.c015ad492469b8a18b36.js +1 -0
- package/dist/bundle.c015ad492469b8a18b36.js.gz +0 -0
- package/dist/bundle.c31ad04e1e30564fea70.js +1 -0
- package/dist/bundle.c560447b006cce1238b6.js +2 -0
- package/dist/bundle.c560447b006cce1238b6.js.LICENSE.txt +1 -0
- package/dist/bundle.c560447b006cce1238b6.js.gz +0 -0
- package/dist/bundle.cad48ecfb6c9304f8477.js +2 -0
- package/dist/bundle.cad48ecfb6c9304f8477.js.LICENSE.txt +5 -0
- package/dist/bundle.cad48ecfb6c9304f8477.js.gz +0 -0
- package/dist/bundle.d7eaee8d9bcfcf8b0bd0.js +1 -0
- package/dist/bundle.d7eaee8d9bcfcf8b0bd0.js.gz +0 -0
- package/dist/bundle.d8256eaa6fe575fb9d01.js +8 -0
- package/dist/bundle.d8256eaa6fe575fb9d01.js.LICENSE.txt +8 -0
- package/dist/bundle.d8256eaa6fe575fb9d01.js.gz +0 -0
- package/dist/bundle.dbb253f3029c97475380.js +1 -0
- package/dist/bundle.dbb253f3029c97475380.js.gz +0 -0
- package/dist/bundle.df7845990c0fed52fca8.js +2 -0
- package/dist/bundle.df7845990c0fed52fca8.js.LICENSE.txt +29 -0
- package/dist/bundle.df7845990c0fed52fca8.js.gz +0 -0
- package/dist/bundle.e1ac7a74c5a25a07424c.js +1 -0
- package/dist/bundle.e1ac7a74c5a25a07424c.js.gz +0 -0
- package/dist/bundle.e9b7939a81971b04ce61.js +1 -0
- package/dist/bundle.e9b7939a81971b04ce61.js.gz +0 -0
- package/dist/bundle.eb8b12c34556f700f59a.js +2 -0
- package/dist/bundle.eb8b12c34556f700f59a.js.LICENSE.txt +30 -0
- package/dist/bundle.eb8b12c34556f700f59a.js.gz +0 -0
- package/dist/bundle.f4f8e071565f4dff4698.js +2 -0
- package/dist/bundle.f4f8e071565f4dff4698.js.LICENSE.txt +5 -0
- package/dist/bundle.f4f8e071565f4dff4698.js.gz +0 -0
- package/dist/css/chemstruc-graph-15d5053934e613f20d2b.css +11 -0
- package/dist/css/chemstruc-graph-15d5053934e613f20d2b.css.gz +0 -0
- package/dist/css/common-131a1a93b3a3dde25f8f.css +90 -0
- package/dist/css/html-editor-draft-5e8e152675ab7d201c00.css +886 -0
- package/dist/css/html-editor-draft-5e8e152675ab7d201c00.css.gz +0 -0
- package/dist/css/main-4bd110a5b2a4a3fbef88.css +803 -0
- package/dist/css/main-4bd110a5b2a4a3fbef88.css.gz +0 -0
- package/dist/images/development-30de07a0.png +0 -0
- package/dist/images/pain-point-8f02421e.png +0 -0
- package/dist/images/target-13a5b4b9.png +0 -0
- package/dist/images/time-cost-cb40d2c2.png +0 -0
- package/dist/images/time-prograss-44b86b36.png +0 -0
- package/dist/index.html +4 -0
- package/lib/controls/code-editor/sql-code-editor.d.ts.map +1 -1
- package/lib/controls/code-editor/sql-code-editor.js.map +1 -1
- package/lib/controls/date-picker/index.d.ts +2 -2
- package/lib/controls/entry-control.d.ts.map +1 -1
- package/lib/controls/entry-control.js +2 -2
- package/lib/controls/entry-control.js.map +1 -1
- package/lib/controls/view-control.d.ts.map +1 -1
- package/lib/controls/view-control.js +3 -3
- package/lib/controls/view-control.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/layout/MainPage.js +1 -1
- package/lib/layout/MainPage.js.map +1 -1
- package/lib/layout/header/index.d.ts.map +1 -1
- package/lib/layout/header/index.js.map +1 -1
- package/lib/tmpl/superagent.d.ts.map +1 -1
- package/lib/tmpl/superagent.js +2 -1
- package/lib/tmpl/superagent.js.map +1 -1
- package/lib/welcome/workbench.js.map +1 -1
- package/package.json +2 -3
- package/src/aldehyde/controls/code-editor/sql-code-editor.tsx +1 -2
- package/src/aldehyde/controls/date-picker/index.tsx +2 -2
- package/src/aldehyde/controls/entry-control.tsx +4 -2
- package/src/aldehyde/controls/view-control.tsx +7 -6
- package/src/aldehyde/index.tsx +5 -2
- package/src/aldehyde/layout/MainPage.tsx +1 -1
- package/src/aldehyde/layout/header/index.tsx +0 -1
- package/src/aldehyde/tmpl/superagent.js +3 -1
- package/src/aldehyde/welcome/workbench.tsx +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(self.webpackChunkaldehyde=self.webpackChunkaldehyde||[]).push([[700],{50700:function(t,e,n){n.d(e,{$Tq:function(){return Mo},AUF:function(){return Tt},C8:function(){return Jr},Ciz:function(){return tt},Cv7:function(){return Pt},D34:function(){return hn},DEm:function(){return kt},DYm:function(){return io},Dps:function(){return Sa},Eps:function(){return ao},F_l:function(){return Xt},GoV:function(){return Aa},HIi:function(){return Oo},HYg:function(){return Q},Hlm:function(){return bo},Hrh:function(){return Xr},Hwe:function(){return Ca},I6H:function(){return Fo},Ilx:function(){return D},J41:function(){return ft},Jj2:function(){return Y},Ksv:function(){return Go},Mqr:function(){return Fa},NZY:function(){return Xa},NmG:function(){return No},OAk:function(){return mo},OnW:function(){return fo},QOv:function(){return no},QXZ:function(){return La},QqH:function(){return vo},RmL:function(){return so},Ruh:function(){return un},SZr:function(){return In},Sgu:function(){return _},TPF:function(){return Eo},U9$:function(){return ka},UE_:function(){return H},V4S:function(){return Ra},VA:function(){return Es},Wa4:function(){return Da},X6G:function(){return I},YkY:function(){return F},Yyn:function(){return _n},aUM:function(){return oa},atm:function(){return jo},bDx:function(){return Ka},cMT:function(){return Po},dBq:function(){return Ua},dmV:function(){return Oa},e9t:function(){return Bo},eKO:function(){return N},f0f:function(){return ya},f8s:function(){return za},fYe:function(){return q},g5D:function(){return Ro},gHo:function(){return po},gN2:function(){return vt},ghY:function(){return to},hgN:function(){return W},hxV:function(){return on},j1n:function(){return st},jD1:function(){return Ho},jWx:function(){return $e},jnZ:function(){return ja},k_5:function(){return lo},ksM:function(){return ko},lI3:function(){return ho},ltA:function(){return So},lv1:function(){return jn},m81:function(){return To},mWk:function(){return dt},nHA:function(){return co},o2T:function(){return rt},oEw:function(){return $a},rzF:function(){return Zo},tIy:function(){return xt},uMq:function(){return nt},v$W:function(){return go},vfe:function(){return gt},voO:function(){return vn},wSe:function(){return Pa},wql:function(){return C},xKj:function(){return Ln},xz_:function(){return mn},ymK:function(){return yn},z8H:function(){return eo}});var r=n(15671),i=n(43144),a=n(4942),o=n(69282),s=n.n(o),u=n(93433),l=n(60136),c=n(82963),d=n(61120),h=n(98737),f=n(13092),p=n(86033),m=n(29439),g=n(97326),v=n(11752),y=n(71002),b=n(96486),w=n(15861),x=n(64687),E=n.n(x),O=n(1581),A=n.n(O),S=n(45987),R=n(67079),P=n.n(R),T=n(66721),k=n.n(T),B=n(78230),C={H:"#000000",He:"#89a1a1",Li:"#bd77ed",Be:"#8fbc00",B:"#c18989",C:"#000000",N:"#304ff7",O:"#ff0d0d",F:"#78bc42",Ne:"#80a2af",Na:"#ab5cf2",Mg:"#6fcd00",Al:"#a99393",Si:"#b29478",P:"#ff8000",S:"#c99a19",Cl:"#1fd01f",Ar:"#69acba",K:"#8f40d4",Ca:"#38e900",Sc:"#999999",Ti:"#979a9e",V:"#99999e",Cr:"#8a99c7",Mn:"#9c7ac7",Fe:"#e06633",Co:"#d37e8e",Ni:"#4ece4e",Cu:"#c78033",Zn:"#7d80b0",Ga:"#bc8b8b",Ge:"#668f8f",As:"#b87ddd",Se:"#e59100",Br:"#a62929",Kr:"#59b1c9",Rb:"#702eb0",Sr:"#00ff00",Y:"#66afaf",Zr:"#71abab",Nb:"#67aeb4",Mo:"#54b5b5",Tc:"#3b9e9e",Ru:"#248f8f",Rh:"#0a7d8c",Pd:"#006985",Ag:"#9a9a9a",Cd:"#b29764",In:"#a67573",Sn:"#668080",Sb:"#9e63b5",Te:"#d47a00",I:"#940094",Xe:"#429eb0",Cs:"#57178f",Ba:"#00c900",La:"#5caed1",Ce:"#9d9d7b",Pr:"#8ca581",Nd:"#84a984",Pm:"#71b18a",Sm:"#66b68e",Eu:"#4ac298",Gd:"#37cb9e",Tb:"#28d1a4",Dy:"#1bd7a8",Ho:"#00e98f",Er:"#00e675",Tm:"#00d452",Yb:"#00bf38",Lu:"#00ab24",Hf:"#47b3ec",Ta:"#4da6ff",W:"#2194d6",Re:"#267dab",Os:"#266696",Ir:"#175487",Pt:"#9898a3",Au:"#c19e1c",Hg:"#9797ac",Tl:"#a6544d",Pb:"#575961",Bi:"#9e4fb5",Po:"#ab5c00",At:"#754f45",Rn:"#428296",Fr:"#420066",Ra:"#007d00",Ac:"#6aa2ec",Th:"#00baff",Pa:"#00a1ff",U:"#008fff",Np:"#0080ff",Pu:"#006bff",Am:"#545cf2",Cm:"#785ce3",Bk:"#8a4fe3",Cf:"#a136d4",Es:"#b31fd4",Fm:"#000000",Md:"#000000",No:"#000000",Lr:"#000000",Rf:"#47b3ec",Db:"#4da6ff",Sg:"#2194d6",Bh:"#267dab",Hs:"#266696",Mt:"#175487",Ds:"#9898a3",Rg:"#c19e1c",Cn:"#9797ac",Nh:"#000000",Fl:"#000000",Mc:"#000000",Lv:"#000000",Ts:"#000000",Og:"#000000"},M=[{number:1,label:"H",period:1,group:1,title:"Hydrogen",state:"gas",origin:"primordial",type:"other-nonmetal",mass:1.00794},{number:2,label:"He",period:1,group:8,title:"Helium",state:"gas",origin:"primordial",type:"noble",mass:4.0026022},{number:3,label:"Li",period:2,group:1,title:"Lithium",state:"solid",origin:"primordial",type:"alkali",mass:6.94},{number:4,label:"Be",period:2,group:2,title:"Beryllium",state:"solid",origin:"primordial",type:"alkaline-earth",mass:9.01218315},{number:5,label:"B",period:2,group:3,title:"Boron",state:"solid",origin:"primordial",type:"metalloid",mass:10.81},{number:6,label:"C",period:2,group:4,title:"Carbon",state:"solid",origin:"primordial",type:"other-nonmetal",mass:12.011},{number:7,label:"N",period:2,group:5,title:"Nitrogen",state:"gas",origin:"primordial",type:"other-nonmetal",mass:14.007},{number:8,label:"O",period:2,group:6,leftH:!0,title:"Oxygen",state:"gas",origin:"primordial",type:"other-nonmetal",mass:15.999},{number:9,label:"F",period:2,group:7,leftH:!0,title:"Fluorine",state:"gas",origin:"primordial",type:"halogen",mass:18.9984031636},{number:10,label:"Ne",period:2,group:8,title:"Neon",state:"gas",origin:"primordial",type:"noble",mass:20.17976},{number:11,label:"Na",period:3,group:1,title:"Sodium",state:"solid",origin:"primordial",type:"alkali",mass:22.989769282},{number:12,label:"Mg",period:3,group:2,title:"Magnesium",state:"solid",origin:"primordial",type:"alkaline-earth",mass:24.305},{number:13,label:"Al",period:3,group:3,title:"Aluminium",state:"solid",origin:"primordial",type:"post-transition",mass:26.98153857},{number:14,label:"Si",period:3,group:4,title:"Silicon",state:"solid",origin:"primordial",type:"metalloid",mass:28.085},{number:15,label:"P",period:3,group:5,title:"Phosphorus",state:"solid",origin:"primordial",type:"other-nonmetal",mass:30.9737619985},{number:16,label:"S",period:3,group:6,leftH:!0,title:"Sulfur",state:"solid",origin:"primordial",type:"other-nonmetal",mass:32.06},{number:17,label:"Cl",period:3,group:7,leftH:!0,title:"Chlorine",state:"gas",origin:"primordial",type:"halogen",mass:35.45},{number:18,label:"Ar",period:3,group:8,title:"Argon",state:"gas",origin:"primordial",type:"noble",mass:39.9481},{number:19,label:"K",period:4,group:1,title:"Potassium",state:"solid",origin:"primordial",type:"alkali",mass:39.09831},{number:20,label:"Ca",period:4,group:2,title:"Calcium",state:"solid",origin:"primordial",type:"alkaline-earth",mass:40.0784},{number:21,label:"Sc",period:4,group:3,title:"Scandium",state:"solid",origin:"primordial",type:"transition",mass:44.9559085},{number:22,label:"Ti",period:4,group:4,title:"Titanium",state:"solid",origin:"primordial",type:"transition",mass:47.8671},{number:23,label:"V",period:4,group:5,title:"Vanadium",state:"solid",origin:"primordial",type:"transition",mass:50.94151},{number:24,label:"Cr",period:4,group:6,title:"Chromium",state:"solid",origin:"primordial",type:"transition",mass:51.99616},{number:25,label:"Mn",period:4,group:7,title:"Manganese",state:"solid",origin:"primordial",type:"transition",mass:54.9380443},{number:26,label:"Fe",period:4,group:8,title:"Iron",state:"solid",origin:"primordial",type:"transition",mass:55.8452},{number:27,label:"Co",period:4,group:8,title:"Cobalt",state:"solid",origin:"primordial",type:"transition",mass:58.9331944},{number:28,label:"Ni",period:4,group:8,title:"Nickel",state:"solid",origin:"primordial",type:"transition",mass:58.69344},{number:29,label:"Cu",period:4,group:1,title:"Copper",state:"solid",origin:"primordial",type:"transition",mass:63.5463},{number:30,label:"Zn",period:4,group:2,title:"Zinc",state:"solid",origin:"primordial",type:"transition",mass:65.382},{number:31,label:"Ga",period:4,group:3,title:"Gallium",state:"solid",origin:"primordial",type:"post-transition",mass:69.7231},{number:32,label:"Ge",period:4,group:4,title:"Germanium",state:"solid",origin:"primordial",type:"metalloid",mass:72.6308},{number:33,label:"As",period:4,group:5,title:"Arsenic",state:"solid",origin:"primordial",type:"metalloid",mass:74.9215956},{number:34,label:"Se",period:4,group:6,leftH:!0,title:"Selenium",state:"solid",origin:"primordial",type:"other-nonmetal",mass:78.9718},{number:35,label:"Br",period:4,group:7,leftH:!0,title:"Bromine",state:"liquid",origin:"primordial",type:"halogen",mass:79.904},{number:36,label:"Kr",period:4,group:8,title:"Krypton",state:"gas",origin:"primordial",type:"noble",mass:83.7982},{number:37,label:"Rb",period:5,group:1,title:"Rubidium",state:"solid",origin:"primordial",type:"alkali",mass:85.46783},{number:38,label:"Sr",period:5,group:2,title:"Strontium",state:"solid",origin:"primordial",type:"alkaline-earth",mass:87.621},{number:39,label:"Y",period:5,group:3,title:"Yttrium",state:"solid",origin:"primordial",type:"transition",mass:88.905842},{number:40,label:"Zr",period:5,group:4,title:"Zirconium",state:"solid",origin:"primordial",type:"transition",mass:91.2242},{number:41,label:"Nb",period:5,group:5,title:"Niobium",state:"solid",origin:"primordial",type:"transition",mass:92.906372},{number:42,label:"Mo",period:5,group:6,title:"Molybdenum",state:"solid",origin:"primordial",type:"transition",mass:95.951},{number:43,label:"Tc",period:5,group:7,title:"Technetium",state:"solid",origin:"decay",type:"transition",mass:98},{number:44,label:"Ru",period:5,group:8,title:"Ruthenium",state:"solid",origin:"primordial",type:"transition",mass:101.072},{number:45,label:"Rh",period:5,group:8,title:"Rhodium",state:"solid",origin:"primordial",type:"transition",mass:102.905502},{number:46,label:"Pd",period:5,group:8,title:"Palladium",state:"solid",origin:"primordial",type:"transition",mass:106.421},{number:47,label:"Ag",period:5,group:1,title:"Silver",state:"solid",origin:"primordial",type:"transition",mass:107.86822},{number:48,label:"Cd",period:5,group:2,title:"Cadmium",state:"solid",origin:"primordial",type:"transition",mass:112.4144},{number:49,label:"In",period:5,group:3,title:"Indium",state:"solid",origin:"primordial",type:"post-transition",mass:114.8181},{number:50,label:"Sn",period:5,group:4,title:"Tin",state:"solid",origin:"primordial",type:"post-transition",mass:118.7107},{number:51,label:"Sb",period:5,group:5,title:"Antimony",state:"solid",origin:"primordial",type:"metalloid",mass:121.7601},{number:52,label:"Te",period:5,group:6,title:"Tellurium",state:"solid",origin:"primordial",type:"metalloid",mass:127.603},{number:53,label:"I",period:5,group:7,leftH:!0,title:"Iodine",state:"solid",origin:"primordial",type:"halogen",mass:126.904473},{number:54,label:"Xe",period:5,group:8,title:"Xenon",state:"gas",origin:"primordial",type:"noble",mass:131.2936},{number:55,label:"Cs",period:6,group:1,title:"Caesium",state:"solid",origin:"primordial",type:"alkali",mass:132.905451966},{number:56,label:"Ba",period:6,group:2,title:"Barium",state:"solid",origin:"primordial",type:"alkaline-earth",mass:137.3277},{number:57,label:"La",period:6,group:3,title:"Lanthanum",state:"solid",origin:"primordial",type:"transition",mass:138.905477},{number:58,label:"Ce",period:6,group:3,title:"Cerium",state:"solid",origin:"primordial",type:"lanthanide",mass:140.1161},{number:59,label:"Pr",period:6,group:3,title:"Praseodymium",state:"solid",origin:"primordial",type:"lanthanide",mass:140.907662},{number:60,label:"Nd",period:6,group:3,title:"Neodymium",state:"solid",origin:"primordial",type:"lanthanide",mass:144.2423},{number:61,label:"Pm",period:6,group:3,title:"Promethium",state:"solid",origin:"decay",type:"lanthanide",mass:145},{number:62,label:"Sm",period:6,group:3,title:"Samarium",state:"solid",origin:"primordial",type:"lanthanide",mass:150.362},{number:63,label:"Eu",period:6,group:3,title:"Europium",state:"solid",origin:"primordial",type:"lanthanide",mass:151.9641},{number:64,label:"Gd",period:6,group:3,title:"Gadolinium",state:"solid",origin:"primordial",type:"lanthanide",mass:157.253},{number:65,label:"Tb",period:6,group:3,title:"Terbium",state:"solid",origin:"primordial",type:"lanthanide",mass:158.925352},{number:66,label:"Dy",period:6,group:3,title:"Dysprosium",state:"solid",origin:"primordial",type:"lanthanide",mass:162.5001},{number:67,label:"Ho",period:6,group:3,title:"Holmium",state:"solid",origin:"primordial",type:"lanthanide",mass:164.930332},{number:68,label:"Er",period:6,group:3,title:"Erbium",state:"solid",origin:"primordial",type:"lanthanide",mass:167.2593},{number:69,label:"Tm",period:6,group:3,title:"Thulium",state:"solid",origin:"primordial",type:"lanthanide",mass:168.934222},{number:70,label:"Yb",period:6,group:3,title:"Ytterbium",state:"solid",origin:"primordial",type:"lanthanide",mass:173.0451},{number:71,label:"Lu",period:6,group:3,title:"Lutetium",state:"solid",origin:"primordial",type:"lanthanide",mass:174.96681},{number:72,label:"Hf",period:6,group:4,title:"Hafnium",state:"solid",origin:"primordial",type:"transition",mass:178.492},{number:73,label:"Ta",period:6,group:5,title:"Tantalum",state:"solid",origin:"primordial",type:"transition",mass:180.947882},{number:74,label:"W",period:6,group:6,title:"Tungsten",state:"solid",origin:"primordial",type:"transition",mass:183.841},{number:75,label:"Re",period:6,group:7,title:"Rhenium",state:"solid",origin:"primordial",type:"transition",mass:186.2071},{number:76,label:"Os",period:6,group:8,title:"Osmium",state:"solid",origin:"primordial",type:"transition",mass:190.233},{number:77,label:"Ir",period:6,group:8,title:"Iridium",state:"solid",origin:"primordial",type:"transition",mass:192.2173},{number:78,label:"Pt",period:6,group:8,title:"Platinum",state:"solid",origin:"primordial",type:"transition",mass:195.0849},{number:79,label:"Au",period:6,group:1,title:"Gold",state:"solid",origin:"primordial",type:"transition",mass:196.9665695},{number:80,label:"Hg",period:6,group:2,title:"Mercury",state:"liquid",origin:"primordial",type:"transition",mass:200.5923},{number:81,label:"Tl",period:6,group:3,title:"Thallium",state:"solid",origin:"primordial",type:"post-transition",mass:204.38},{number:82,label:"Pb",period:6,group:4,title:"Lead",state:"solid",origin:"primordial",type:"post-transition",mass:207.21},{number:83,label:"Bi",period:6,group:5,title:"Bismuth",state:"solid",origin:"primordial",type:"post-transition",mass:208.980401},{number:84,label:"Po",period:6,group:6,title:"Polonium",state:"solid",origin:"decay",type:"metalloid",mass:209},{number:85,label:"At",period:6,group:7,title:"Astatine",state:"solid",origin:"decay",type:"halogen",mass:210},{number:86,label:"Rn",period:6,group:8,title:"Radon",state:"gas",origin:"decay",type:"noble",mass:222},{number:87,label:"Fr",period:7,group:1,title:"Francium",state:"solid",origin:"decay",type:"alkali",mass:223},{number:88,label:"Ra",period:7,group:2,title:"Radium",state:"solid",origin:"decay",type:"alkaline-earth",mass:226},{number:89,label:"Ac",period:7,group:3,title:"Actinium",state:"solid",origin:"decay",type:"transition",mass:227},{number:90,label:"Th",period:7,group:3,title:"Thorium",state:"solid",origin:"primordial",type:"actinide",mass:232.03774},{number:91,label:"Pa",period:7,group:3,title:"Protactinium",state:"solid",origin:"decay",type:"actinide",mass:231.035882},{number:92,label:"U",period:7,group:3,title:"Uranium",state:"solid",origin:"primordial",type:"actinide",mass:238.028913},{number:93,label:"Np",period:7,group:3,title:"Neptunium",state:"solid",origin:"decay",type:"actinide",mass:237},{number:94,label:"Pu",period:7,group:3,title:"Plutonium",state:"solid",origin:"decay",type:"actinide",mass:244},{number:95,label:"Am",period:7,group:3,title:"Americium",state:"solid",origin:"synthetic",type:"actinide",mass:243},{number:96,label:"Cm",period:7,group:3,title:"Curium",state:"solid",origin:"synthetic",type:"actinide",mass:247},{number:97,label:"Bk",period:7,group:3,title:"Berkelium",state:"solid",origin:"synthetic",type:"actinide",mass:247},{number:98,label:"Cf",period:7,group:3,title:"Californium",state:"solid",origin:"synthetic",type:"actinide",mass:251},{number:99,label:"Es",period:7,group:3,title:"Einsteinium",state:"solid",origin:"synthetic",type:"actinide",mass:252},{number:100,label:"Fm",period:7,group:3,title:"Fermium",origin:"synthetic",type:"actinide",mass:257},{number:101,label:"Md",period:7,group:3,title:"Mendelevium",origin:"synthetic",type:"actinide",mass:258},{number:102,label:"No",period:7,group:3,title:"Nobelium",origin:"synthetic",type:"actinide",mass:259},{number:103,label:"Lr",period:7,group:3,title:"Lawrencium",origin:"synthetic",type:"actinide",mass:266},{number:104,label:"Rf",period:7,group:4,title:"Rutherfordium",origin:"synthetic",type:"transition",mass:267},{number:105,label:"Db",period:7,group:5,title:"Dubnium",origin:"synthetic",type:"transition",mass:268},{number:106,label:"Sg",period:7,group:6,title:"Seaborgium",origin:"synthetic",type:"transition",mass:269},{number:107,label:"Bh",period:7,group:7,title:"Bohrium",origin:"synthetic",type:"transition",mass:270},{number:108,label:"Hs",period:7,group:8,title:"Hassium",origin:"synthetic",type:"transition",mass:269},{number:109,label:"Mt",period:7,group:8,title:"Meitnerium",origin:"synthetic",type:"transition",mass:278},{number:110,label:"Ds",period:7,group:8,title:"Darmstadtium",origin:"synthetic",type:"transition",mass:281},{number:111,label:"Rg",period:7,group:1,title:"Roentgenium",origin:"synthetic",type:"transition",mass:282},{number:112,label:"Cn",period:7,group:2,title:"Copernicium",origin:"synthetic",type:"transition",mass:285},{number:113,label:"Nh",period:7,group:3,title:"Nihonium",origin:"synthetic",type:"post-transition",mass:286},{number:114,label:"Fl",period:7,group:4,title:"Flerovium",origin:"synthetic",type:"post-transition",mass:289},{number:115,label:"Mc",period:7,group:5,title:"Moscovium",origin:"synthetic",type:"post-transition",mass:289},{number:116,label:"Lv",period:7,group:6,title:"Livermorium",origin:"synthetic",type:"post-transition",mass:293},{number:117,label:"Ts",period:7,group:7,title:"Tennessine",origin:"synthetic",type:"halogen",mass:294},{number:118,label:"Og",period:7,group:8,title:"Oganesson",origin:"synthetic",type:"noble",mass:294}],Z=M.reduce((function(t,e){return t.set(e.label,e),t.set(e.number,e),t}),new Map),N={get:function(t){return Z.get(t)},filter:function(t){return M.filter(t)}},I={"atoms-gen":{title:"Atom Generics",itemSets:[{displayName:"any atom",items:[{label:"A",description:"Any atom except hydrogen"},{label:"AH",description:"Any atom, including hydrogen"}]},{displayName:"except C or H",items:[{label:"Q",description:"Any heteroatom (any atom except C or H)"},{label:"QH",description:"Any atom except C"}]},{displayName:"any metal",items:[{label:"M",description:"Any metal"},{label:"MH",description:"Any metal or hydrogen"}]},{displayName:"any halogen",items:[{label:"X",description:"Any halogen"},{label:"XH",description:"Any halogen or hydrogen"}]}]},"special-nodes":{title:"Special Nodes",itemSets:[{items:[{label:"H+",description:"Proton"},{label:"D",description:"Deuterium"},{label:"T",description:"Tritium"},{label:"R",description:"Pseudoatom"},{label:"Pol",description:"Polymer Bead"}]}]},"group-gen":{title:"Group Generics",itemSets:[{items:[{label:"G",description:"Any group"},{label:"GH",description:"Any group or hydrogen"}]},{items:[{label:"G*",description:"Any group with a ring closure"},{label:"GH*",description:"Any group of hydrogen with a ring closure"}]}],subGroups:{"group-acyclic":{title:"Acyclic",itemSets:[{items:[{label:"ACY",description:"Acyclic group"},{label:"ACH",description:"Acyclic group or hydrogen"}]}],subGroups:{"acyclic-carbo":{title:"Acyclic Carbo",itemSets:[{items:[{label:"ABC",description:"Carbocyclic"},{label:"ABH",description:"Carbocyclic of hydrogen"}]},{displayName:"alkynyl",items:[{label:"AYL",description:"Alkynyl"},{label:"AYH",description:"Alkynyl or hydrogen"}]},{displayName:"alkyl",items:[{label:"ALK",description:"Alkyl"},{label:"ALH",description:"Alkyl or hydrogen"}]},{displayName:"alkenyl",items:[{label:"AEL",description:"Alkenyl"},{label:"AEH",description:"Alkenyl or hydrogen"}]}]},"acyclic-hetero":{title:"Acyclic Hetero",itemSets:[{items:[{label:"AHC",description:"Heteroacyclic"},{label:"AHH",description:"Heterocyclic or hydrogen"}]},{items:[{label:"AOX",description:"Alkoxy"},{label:"AOH",description:"Alkoxy or hydrogen"}]}]}}},"group-cyclic":{title:"Cyclic",itemSets:[{items:[{label:"CYC",description:"Cyclic group"},{label:"CYH",description:"Cyclic group or hydrogen"}]},{displayName:"no carbon",items:[{label:"CXX",description:"Cyclic group with no Carbon atoms"},{label:"CXH",description:"Cyclic group with no Carbon atoms or hydrogen"}]}],subGroups:{"cyclic-carbo":{title:"Cyclic Carbo",itemSets:[{items:[{label:"CBC",description:"Carbocyclic derivatives"},{label:"CBH",description:"Carbocyclic derivatives or hydrogen"}]},{displayName:"atyl",items:[{label:"ARY",description:"Any aryl group"},{label:"ARH",description:"Any aryl group or hydrogen"}]},{displayName:"cycloalkyl",items:[{label:"CAL",description:"Any cycloalkyl group"},{label:"CAH",description:"Any cycloalkyl group or hydrogen"}]},{displayName:"cycloalkenyl",items:[{label:"CEL",description:"Any cyloalkenyl group"},{label:"CEH",description:"Any cyloalkenyl group or hydrogen"}]}]},"cyclic-hetero":{title:"Cyclic Hetero",itemSets:[{items:[{label:"CHC",description:"Heterocyclic group"},{label:"CHH",description:"Heterocyclic group or hydrogen"}]},{displayName:"hetero aryl",items:[{label:"HAR",description:"Heteroaryl group"},{label:"HAH",description:"Heteroaryl group or hydrogen"}]}]}}}}}};function L(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var D=function(){function t(e){(0,r.Z)(this,t),this.notList=e.notList,this.ids=e.ids}return(0,i.Z)(t,[{key:"labelList",value:function(){var t,e=[],n=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return L(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?L(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}(this.ids);try{for(n.s();!(t=n.n()).done;){var r=t.value,i=N.get(r);i&&e.push(i.label)}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"label",value:function(){var t="["+this.labelList().join(",")+"]";return this.notList&&(t="!"+t),t}},{key:"equals",value:function(t){return this.notList===t.notList&&(this.ids||[]).sort().toString()===(t.ids||[]).sort().toString()}}]),t}(),_=function(){function t(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];if((0,r.Z)(this,t),0===n.length)this.x=0,this.y=0,this.z=0;else if(1===arguments.length)this.x=parseFloat(n[0].x||0),this.y=parseFloat(n[0].y||0),this.z=parseFloat(n[0].z||0);else if(2===arguments.length)this.x=parseFloat(n[0]||0),this.y=parseFloat(n[1]||0),this.z=0;else{if(3!==arguments.length)throw new Error("Vec2(): invalid arguments");this.x=parseFloat(n[0]),this.y=parseFloat(n[1]),this.z=parseFloat(n[2])}}return(0,i.Z)(t,[{key:"length",value:function(){return Math.sqrt(this.x*this.x+this.y*this.y)}},{key:"equals",value:function(t){return this.x===t.x&&this.y===t.y&&this.z===t.z}},{key:"add",value:function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z)}},{key:"add_",value:function(t){this.x+=t.x,this.y+=t.y,this.z+=t.z}},{key:"get_xy0",value:function(){return new t(this.x,this.y)}},{key:"sub",value:function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z)}},{key:"scaled",value:function(e){return new t(this.x*e,this.y*e,this.z*e)}},{key:"negated",value:function(){return new t(-this.x,-this.y,-this.z)}},{key:"yComplement",value:function(e){return e=e||0,new t(this.x,e-this.y,this.z)}},{key:"addScaled",value:function(e,n){return new t(this.x+e.x*n,this.y+e.y*n,this.z+e.z*n)}},{key:"normalized",value:function(){return this.scaled(1/this.length())}},{key:"normalize",value:function(){var t=this.length();return!(t<1e-6||(this.x/=t,this.y/=t,0))}},{key:"turnLeft",value:function(){return new t(-this.y,this.x,this.z)}},{key:"coordStr",value:function(){return this.x.toString()+" , "+this.y.toString()}},{key:"toString",value:function(){return"("+this.x.toFixed(2)+","+this.y.toFixed(2)+")"}},{key:"max",value:function(e){return s()(null!=e),t.max(this,e)}},{key:"min",value:function(e){return t.min(this,e)}},{key:"ceil",value:function(){return new t(Math.ceil(this.x),Math.ceil(this.y),Math.ceil(this.z))}},{key:"floor",value:function(){return new t(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))}},{key:"rotate",value:function(t){var e=Math.sin(t),n=Math.cos(t);return this.rotateSC(e,n)}},{key:"rotateSC",value:function(e,n){return s()(0===e||!!e),s()(0===n||!!n),new t(this.x*n-this.y*e,this.x*e+this.y*n,this.z)}},{key:"oxAngle",value:function(){return Math.atan2(this.y,this.x)}}],[{key:"dist",value:function(e,n){return t.diff(e,n).length()}},{key:"max",value:function(e,n){return new t(Math.max(e.x,n.x),Math.max(e.y,n.y),Math.max(e.z,n.z))}},{key:"min",value:function(e,n){return new t(Math.min(e.x,n.x),Math.min(e.y,n.y),Math.min(e.z,n.z))}},{key:"sum",value:function(e,n){return new t(e.x+n.x,e.y+n.y,e.z+n.z)}},{key:"dot",value:function(t,e){return t.x*e.x+t.y*e.y}},{key:"cross",value:function(t,e){return t.x*e.y-t.y*e.x}},{key:"angle",value:function(e,n){return Math.atan2(t.cross(e,n),t.dot(e,n))}},{key:"diff",value:function(e,n){return new t(e.x-n.x,e.y-n.y,e.z-n.z)}},{key:"lc",value:function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];for(var i=new t,a=0;a<arguments.length/2;++a)i=i.addScaled(n[2*a],n[2*a+1]);return i}},{key:"lc2",value:function(e,n,r,i){return new t(e.x*n+r.x*i,e.y*n+r.y*i,e.z*n+r.z*i)}},{key:"centre",value:function(e,n){return t.lc2(e,.5,n,.5)}}]),t}();function j(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return G(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?G(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function G(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}(0,a.Z)(_,"ZERO",new _(0,0)),(0,a.Z)(_,"UNIT",new _(1,1));var F,H=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(){return(0,r.Z)(this,o),a.apply(this,arguments)}return(0,i.Z)(o,[{key:"find",value:function(t){var e,n=j(this);try{for(n.s();!(e=n.n()).done;){var r=e.value;if(t(r))return r}}catch(t){n.e(t)}finally{n.f()}return null}},{key:"equals",value:function(t){return this.isSuperset(t)&&t.isSuperset(this)}},{key:"isSuperset",value:function(t){var e,n=j(t);try{for(n.s();!(e=n.n()).done;){var r=e.value;if(!this.has(r))return!1}}catch(t){n.e(t)}finally{n.f()}return!0}},{key:"filter",value:function(t){return new o(Array.from(this).filter(t))}},{key:"union",value:function(t){var e,n=new o(this),r=j(t);try{for(r.s();!(e=r.n()).done;){var i=e.value;n.add(i)}}catch(t){r.e(t)}finally{r.f()}return n}},{key:"intersection",value:function(t){var e=new o(this);return new o((0,u.Z)(e).filter((function(e){return t.has(e)})))}}],[{key:"unionIntersections",value:function(t){var e=!1,n=t.reduce((function(t,n){var r=!1,i=t.map((function(t){return t.intersection(n).size>0?(e=!0,r=!0,t.union(n)):t}));return r||i.push(n),i}),new Array);return e?o.unionIntersections(n):n}}]),o}((0,h.Z)(Set));function z(t,e){return void 0!==t?t:e}function U(t){return!N.get(t)&&"L"!==t&&"L#"!==t&&"R#"!==t}function V(t){return(t-=0)===W.PATTERN.RADICAL.DOUPLET?1:t===W.PATTERN.RADICAL.SINGLET||t===W.PATTERN.RADICAL.TRIPLET?2:0}!function(t){t.Abs="abs",t.And="&",t.Or="or"}(F||(F={}));var W=function(){function t(e){(0,r.Z)(this,t),this.label=e.label,this.fragment=z(e.fragment,-1),this.alias=z(e.alias,t.attrlist.alias),this.isotope=z(e.isotope,t.attrlist.isotope),this.radical=z(e.radical,t.attrlist.radical),this.charge=z(e.charge,t.attrlist.charge),this.rglabel=z(e.rglabel,t.attrlist.rglabel),this.attpnt=z(e.attpnt,t.attrlist.attpnt),this.explicitValence=z(e.explicitValence,t.attrlist.explicitValence),this.valence=0,this.implicitH=e.implicitH||0,this.pp=e.pp?new _(e.pp):new _,this.sgs=new H,this.ringBondCount=z(e.ringBondCount,t.attrlist.ringBondCount),this.substitutionCount=z(e.substitutionCount,t.attrlist.substitutionCount),this.unsaturatedAtom=z(e.unsaturatedAtom,t.attrlist.unsaturatedAtom),this.hCount=z(e.hCount,t.attrlist.hCount),this.aam=z(e.aam,t.attrlist.aam),this.invRet=z(e.invRet,t.attrlist.invRet),this.exactChangeFlag=z(e.exactChangeFlag,t.attrlist.exactChangeFlag),this.rxnFragmentType=z(e.rxnFragmentType,-1),this.stereoLabel=z(e.stereoLabel,t.attrlist.stereoLabel),this.stereoParity=z(e.stereoParity,t.attrlist.stereoParity),this.atomList=e.atomList?new D(e.atomList):null,this.neighbors=[],this.badConn=!1,Object.defineProperty(this,"pseudo",{enumerable:!0,get:function(){return U(t=this.label)?t:"";var t},set:function(t){U(t)&&(this.label=t)}})}return(0,i.Z)(t,[{key:"clone",value:function(e){var n=new t(this);return e&&e.has(this.fragment)&&(n.fragment=e.get(this.fragment)),n}},{key:"isQuery",value:function(){return null!==this.atomList||"A"===this.label||this.attpnt||this.hCount}},{key:"pureHydrogen",value:function(){return"H"===this.label&&0===this.isotope}},{key:"isPlainCarbon",value:function(){return"C"===this.label&&0===this.isotope&&0===this.radical&&0===this.charge&&this.explicitValence<0&&0===this.ringBondCount&&0===this.substitutionCount&&0===this.unsaturatedAtom&&0===this.hCount&&!this.atomList}},{key:"isPseudo",value:function(){return!this.atomList&&!this.rglabel&&!N.get(this.label)}},{key:"hasRxnProps",value:function(){return!!(this.invRet||this.exactChangeFlag||null!==this.attpnt||this.aam)}},{key:"calcValence",value:function(t){var e=this.label,n=this.charge;if(this.isQuery())return this.implicitH=0,!0;var r=N.get(e);if(!r)return this.implicitH=0,!0;var i=r.group,a=V(this.radical),o=t,s=0,u=Math.abs(n);return 1===i?"H"!==e&&"Li"!==e&&"Na"!==e&&"K"!==e&&"Rb"!==e&&"Cs"!==e&&"Fr"!==e||(o=1,s=1-a-t-u):2===i?t+a+u===2||t+a+u===0?o=2:s=-1:3===i?"B"===e||"Al"===e||"Ga"===e||"In"===e?-1===n?(o=4,s=4-a-t):(o=3,s=3-a-t-u):"Tl"===e&&(-1===n?a+t<=2?(o=2,s=2-a-t):(o=4,s=4-a-t):-2===n?a+t<=3?(o=3,s=3-a-t):(o=5,s=5-a-t):a+t+u<=1?(o=1,s=1-a-t-u):(o=3,s=3-a-t-u)):4===i?"C"===e||"Si"===e||"Ge"===e?(o=4,s=4-a-t-u):"Sn"!==e&&"Pb"!==e||(t+a+u<=2?(o=2,s=2-a-t-u):(o=4,s=4-a-t-u)):5===i?"N"===e||"P"===e?1===n?(o=4,s=4-a-t):2===n?(o=3,s=3-a-t):"N"===e||a+t+u<=3?(o=3,s=3-a-t-u):(o=5,s=5-a-t-u):"Bi"!==e&&"Sb"!==e&&"As"!==e||(1===n?a+t<=2&&"As"!==e?(o=2,s=2-a-t):(o=4,s=4-a-t):2===n?(o=3,s=3-a-t):a+t<=3?(o=3,s=3-a-t-u):(o=5,s=5-a-t-u)):6===i?"O"===e?n>=1?(o=3,s=3-a-t):(o=2,s=2-a-t-u):"S"===e||"Se"===e||"Po"===e?1===n?t<=3?(o=3,s=3-a-t):(o=5,s=5-a-t):t+a+u<=2?(o=2,s=2-a-t-u):t+a+u<=4?(o=4,s=4-a-t-u):(o=6,s=6-a-t-u):"Te"===e&&(-1===n?t<=2&&(o=2,s=2-a-t-u):0!==n&&2!==n||(t<=2?(o=2,s=2-a-t-u):t<=4?(o=4,s=4-a-t-u):0===n&&t<=6?(o=6,s=6-a-t-u):s=-1)):7===i?"F"===e?(o=1,s=1-a-t-u):"Cl"!==e&&"Br"!==e&&"I"!==e&&"At"!==e||(1===n?t<=2?(o=2,s=2-a-t):(3===t||5===t||t>=7)&&(s=-1):0===n&&(t<=1?(o=1,s=1-a-t):2===t||4===t||6===t?1===a?(o=t,s=0):s=-1:t>7&&(s=-1))):8===i&&(t+a+u===0?o=1:s=-1),this.valence=o,this.implicitH=s,!(this.implicitH<0&&(this.valence=t,this.implicitH=0,this.badConn=!0,1))}},{key:"calcValenceMinusHyd",value:function(t){var e=this.charge,n=this.label,r=N.get(this.label);if(!r)return this.implicitH=0,0;var i=r.group,a=V(this.radical);if(3===i){if(("B"===n||"Al"===n||"Ga"===n||"In"===n)&&-1===e&&a+t<=4)return a+t}else if(5===i){if("N"===n||"P"===n){if(1===e)return a+t;if(2===e)return a+t}else if("Sb"===n||"Bi"===n||"As"===n){if(1===e)return a+t;if(2===e)return a+t}}else if(6===i){if("O"===n){if(e>=1)return a+t}else if(("S"===n||"Se"===n||"Po"===n)&&1===e)return a+t}else if(7===i&&("Cl"===n||"Br"===n||"I"===n||"At"===n)&&1===e)return a+t;return a+t+Math.abs(e)}}],[{key:"getAttrHash",value:function(e){var n={};for(var r in t.attrlist)void 0!==e[r]&&(n[r]=e[r]);return n}},{key:"attrGetDefault",value:function(e){if(e in t.attrlist)return t.attrlist[e]}}]),t}();(0,a.Z)(W,"PATTERN",{RADICAL:{NONE:0,SINGLET:1,DOUPLET:2,TRIPLET:3},STEREO_PARITY:{NONE:0,ODD:1,EVEN:2,EITHER:3}}),(0,a.Z)(W,"attrlist",{alias:null,label:"C",isotope:0,radical:0,charge:0,explicitValence:-1,ringBondCount:0,substitutionCount:0,unsaturatedAtom:0,hCount:0,atomList:null,invRet:0,exactChangeFlag:0,rglabel:null,attpnt:null,aam:0,stereoLabel:null,stereoParity:0});var Y,q=function(){function t(e){(0,r.Z)(this,t),this.begin=e.begin,this.end=e.end,this.type=e.type,this.xxx=e.xxx||"",this.stereo=t.PATTERN.STEREO.NONE,this.topology=t.PATTERN.TOPOLOGY.EITHER,this.reactingCenterStatus=0,this.len=0,this.sb=0,this.sa=0,this.angle=0,e.stereo&&(this.stereo=e.stereo),e.topology&&(this.topology=e.topology),e.reactingCenterStatus&&(this.reactingCenterStatus=e.reactingCenterStatus),this.center=new _}return(0,i.Z)(t,[{key:"hasRxnProps",value:function(){return!!this.reactingCenterStatus}},{key:"getCenter",value:function(t){var e=t.atoms.get(this.begin).pp,n=t.atoms.get(this.end).pp;return _.lc2(e,.5,n,.5)}},{key:"getDir",value:function(t){var e=t.atoms.get(this.begin).pp;return t.atoms.get(this.end).pp.sub(e).normalized()}},{key:"clone",value:function(e){var n=new t(this);return e&&(n.begin=e.get(n.begin),n.end=e.get(n.end)),n}}],[{key:"getAttrHash",value:function(e){var n={};for(var r in t.attrlist)(e[r]||"stereo"===r)&&(n[r]=e[r]);return n}},{key:"attrGetDefault",value:function(e){if(e in t.attrlist)return t.attrlist[e]}}]),t}();function $(t,e,n){!function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t,e),e.set(t,n)}function X(t,e){if(e&&0!==e.length){var n=e.map((function(e){return t.atoms.get(e)})).filter((function(t){return null==t?void 0:t.stereoLabel}));if(n.length){var r,i=n[0].stereoLabel;if(n.some((function(t){return(null==t?void 0:t.stereoLabel)!==i})))r=Y.Mixed;else{var a,o=null===(a=i.match(/\D+/g))||void 0===a?void 0:a[0];switch(o){case F.Abs:r=Y.Abs;break;case F.And:r=Y.And;break;case F.Or:r=Y.Or;break;default:throw new Error("Unsupported stereo label: ".concat(o,"."))}}return r}}}(0,a.Z)(q,"PATTERN",{TYPE:{SINGLE:1,DOUBLE:2,TRIPLE:3,AROMATIC:4,SINGLE_OR_DOUBLE:5,SINGLE_OR_AROMATIC:6,DOUBLE_OR_AROMATIC:7,ANY:8,DATIVE:9,HYDROGEN:10},STEREO:{NONE:0,UP:1,EITHER:4,DOWN:6,CIS_TRANS:3},TOPOLOGY:{EITHER:0,RING:1,CHAIN:2},REACTING_CENTER:{NOT_CENTER:-1,UNMARKED:0,CENTER:1,UNCHANGED:2,MADE_OR_BROKEN:4,ORDER_CHANGED:8,MADE_OR_BROKEN_AND_CHANGED:12}}),(0,a.Z)(q,"attrlist",{type:q.PATTERN.TYPE.SINGLE,stereo:q.PATTERN.STEREO.NONE,topology:q.PATTERN.TOPOLOGY.EITHER,reactingCenterStatus:q.PATTERN.REACTING_CENTER.UNMARKED}),function(t){t.Mixed="MIXED",t.Abs="ABS",t.And="AND",t.Or="OR"}(Y||(Y={}));var K=new WeakMap,J=new WeakMap,Q=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1?arguments[1]:void 0;(0,r.Z)(this,t),$(this,K,{writable:!0,value:void 0}),$(this,J,{writable:!0,value:void 0}),n&&(this.stereoFlagPosition=new _(n)),(0,f.Z)(this,J,e)}return(0,i.Z)(t,[{key:"stereoAtoms",get:function(){return(0,u.Z)((0,p.Z)(this,J))}},{key:"enhancedStereoFlag",get:function(){return(0,p.Z)(this,K)}},{key:"clone",value:function(e){var n=new t((0,p.Z)(this,J).map((function(t){return e.get(t)})),this.stereoFlagPosition);return(0,f.Z)(n,K,(0,p.Z)(this,K)),n}},{key:"updateStereoFlag",value:function(t){return(0,f.Z)(this,K,X(t,this.stereoAtoms)),(0,p.Z)(this,K)}},{key:"updateStereoAtom",value:function(t,e,n,r){var i;r&&!(0,p.Z)(this,J).includes(e)&&(0,p.Z)(this,J).push(e),r||(null===(i=t.atoms.get(e))||void 0===i?void 0:i.fragment)===n&&Array.from(t.bonds.values()).filter((function(t){return t.stereo&&t.type!==q.PATTERN.TYPE.DOUBLE})).some((function(t){return t.begin===e}))||(0,f.Z)(this,J,this.stereoAtoms.filter((function(t){return t!==e}))),(0,f.Z)(this,K,X(t,this.stereoAtoms))}},{key:"addStereoAtom",value:function(t){return!(0,p.Z)(this,J).includes(t)&&(this.stereoAtoms.push(t),!0)}},{key:"deleteStereoAtom",value:function(t,e,n){var r;return!((null===(r=t.atoms.get(n))||void 0===r?void 0:r.fragment)===e&&Array.from(t.bonds.values()).filter((function(t){return t.stereo&&t.type!==q.PATTERN.TYPE.DOUBLE})).some((function(t){return t.begin===n}))||((0,f.Z)(this,J,(0,p.Z)(this,J).filter((function(t){return t!==n}))),0))}}],[{key:"getDefaultStereoFlagPosition",value:function(t,e){var n=t.getFragment(e);if(n){var r=n.getCoordBoundingBox();return new _(r.max.x,r.min.y-1)}}}]),t}(),tt={scaled2obj:function(t,e){return t.scaled(1/e.scale)},obj2scaled:function(t,e){return t.scaled(e.scale)}},et={isCorrectStereoCenter:function(t,e,n,r){var i,a=r.atoms.get(t.begin),o=NaN;return 2===(null==n?void 0:n.length)&&(o=n[0].aid===t.begin?n[1].aid:n[0].aid),t.stereo>0&&(1!==(null==n?void 0:n.length)||2!==(null==e?void 0:e.length)||Number(null==a?void 0:a.implicitH)%2!=0)&&(2!==(null==n?void 0:n.length)||2!==(null==e?void 0:e.length)||Number(null==a?void 0:a.implicitH)%2!=0||1!==(null===(i=r.atomGetNeighbors(o))||void 0===i?void 0:i.length))&&1!==(null==e?void 0:e.length)}},nt=function(){function t(){(0,r.Z)(this,t),this.functionalGroupsList=[]}return(0,i.Z)(t,[{key:"getFunctionalGroupsList",value:function(){return this.functionalGroupsList}},{key:"setFunctionalGroupsList",value:function(t){this.functionalGroupsList=t}},{key:"addToFunctionalGroupsList",value:function(t){this.functionalGroupsList=[].concat((0,u.Z)(this.functionalGroupsList),(0,u.Z)(t))}}],[{key:"getInstance",value:function(){return t.instance||(t.instance=new t),t.instance}}]),t}(),rt=function(){function t(){(0,r.Z)(this,t),this.saltsAndSolventsList=[]}return(0,i.Z)(t,[{key:"getSaltsAndSolventsList",value:function(){return this.saltsAndSolventsList}},{key:"setSaltsAndSolventsList",value:function(t){this.saltsAndSolventsList=t}}],[{key:"getInstance",value:function(){return t.instance||(t.instance=new t),t.instance}}]),t}(),it=function(){function t(){(0,r.Z)(this,t);for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];if(1===n.length&&"min"in n[0]&&"max"in n[0]&&(this.p0=n[0].min,this.p1=n[0].max),2===n.length)this.p0=n[0],this.p1=n[1];else if(4===n.length)this.p0=new _(n[0],n[1]),this.p1=new _(n[2],n[3]);else{if(0!==n.length)throw new Error("Box2Abs constructor only accepts 4 numbers or 2 vectors or no args!");this.p0=new _,this.p1=new _}}return(0,i.Z)(t,[{key:"toString",value:function(){return this.p0.toString()+" "+this.p1.toString()}},{key:"clone",value:function(){return new t(this.p0,this.p1)}},{key:"extend",value:function(e,n){return n=n||e,new t(this.p0.sub(e),this.p1.add(n))}},{key:"include",value:function(e){return s()(null!=e),new t(this.p0.min(e),this.p1.max(e))}},{key:"contains",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return s()(null!=t),t.x>=this.p0.x-e&&t.x<=this.p1.x+e&&t.y>=this.p0.y-e&&t.y<=this.p1.y+e}},{key:"translate",value:function(e){return new t(this.p0.add(e),this.p1.add(e))}},{key:"transform",value:function(e,n){return s()("function"==typeof e),new t(e(this.p0,n),e(this.p1,n))}},{key:"sz",value:function(){return this.p1.sub(this.p0)}},{key:"centre",value:function(){return _.centre(this.p0,this.p1)}},{key:"pos",value:function(){return this.p0}}],[{key:"fromRelBox",value:function(e){return new t(e.x,e.y,e.x+e.width,e.y+e.height)}},{key:"union",value:function(e,n){return new t(_.min(e.p0,n.p0),_.max(e.p1,n.p1))}},{key:"segmentIntersection",value:function(t,e,n,r){var i=(t.x-n.x)*(e.y-n.y)-(t.y-n.y)*(e.x-n.x),a=(t.x-r.x)*(e.y-r.y)-(t.y-r.y)*(e.x-r.x),o=(n.x-t.x)*(r.y-t.y)-(n.y-t.y)*(r.x-t.x),s=(n.x-e.x)*(r.y-e.y)-(n.y-e.y)*(r.x-e.x);return i*a<=0&&o*s<=0}}]),t}();function at(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var ot=(0,i.Z)((function t(e,n,i,a){(0,r.Z)(this,t),this.c=e,this.d=n,this.n=n.rotateSC(1,0),this.w=i,this.h=a})),st=function(){function t(e){(0,r.Z)(this,t),this.type=e,this.id=-1,this.label=-1,this.bracketBox=null,this.bracketDir=new _(1,0),this.areas=[],this.hover=!1,this.hovering=null,this.selected=!1,this.selectionPlate=null,this.atoms=[],this.patoms=[],this.bonds=[],this.xBonds=[],this.neiAtoms=[],this.pp=null,this.data={mul:1,connectivity:"ht",name:"",subscript:"n",expanded:void 0,attached:!1,absolute:!0,showUnits:!1,nCharsToDisplay:-1,tagChar:"",daspPos:1,fieldType:"F",fieldName:"",fieldValue:"",units:"",query:"",queryOp:""}}return(0,i.Z)(t,[{key:"getAttr",value:function(t){return this.data[t]}},{key:"getAttrs",value:function(){var t=this,e={};return Object.keys(this.data).forEach((function(n){e[n]=t.data[n]})),e}},{key:"setAttr",value:function(t,e){var n=this.data[t];return this.data[t]=e,n}},{key:"checkAttr",value:function(t,e){return this.data[t]===e}},{key:"updateOffset",value:function(t){this.pp=_.sum(this.bracketBox.p1,t)}},{key:"calculatePP",value:function(e){var n;if("Atom"===this.data.context||"Bond"===this.data.context){var r=[],i=null,a=new _(1,0);this.atoms.forEach((function(t){var n=e.atoms.get(t),i=new _(n.pp),a=new _(.05*3,.05*3),o=new it(i,i).extend(a,a);r.push(o)})),r.forEach((function(t){var e=null;[t.p0.x,t.p1.x].forEach((function(n){[t.p0.y,t.p1.y].forEach((function(t){var r=new _(n,t),i=new _(_.dot(r,a),_.dot(r,a.rotateSC(1,0)));e=e?e.include(i):new it(i,i)}))})),i=i?it.union(i,e):e})),n=i.p0}else n=this.bracketBox.p1.add(new _(.5,.5));for(var o=Array.from(e.sgroups.values()),s=0;s<e.sgroups.size&&ut(o,n);++s)n=n.add(new _(0,.5));if("INDIGO_CIP_DESC"===this.data.fieldName)if(1===this.atoms.length){var u,l=this.atoms[0],c=null===(u=e.atoms.get(l))||void 0===u?void 0:u.pp;c&&(n=c)}else n=t.getMassCentre(e,this.atoms);this.pp=n}},{key:"getAttAtomId",value:function(t){var e,n=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return at(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?at(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}(this.atoms);try{for(n.s();!(e=n.n()).done;){var r=e.value,i=t.atoms.get(r);if(i&&Number.isInteger(i.attpnt))return r}}catch(t){n.e(t)}finally{n.f()}return this.atoms[0]}},{key:"isGroupAttached",value:function(t){var e=this,n=this.getAttAtomId(t),r=t.atomGetNeighbors(n);return!(null!=r&&r.every((function(t){var n=t.aid;return e.atoms.includes(n)})))}}],[{key:"getOffset",value:function(t){return null!=t&&t.pp?_.diff(t.pp,t.bracketBox.p1):null}},{key:"isSaltOrSolvent",value:function(t){return rt.getInstance().getSaltsAndSolventsList().some((function(e){var n=e.name,r=e.abbreviation;return n===t||t===r}))}},{key:"isAtomInSaltOrSolvent",value:function(t,e){var n=this;return e.filter((function(t){return n.isSaltOrSolvent(t.data.name)})).some((function(e){return e.atoms.some((function(e){return e===t}))}))}},{key:"isBondInSaltOrSolvent",value:function(t,e){var n=this;return e.filter((function(t){return n.isSaltOrSolvent(t.data.name)})).some((function(e){return e.bonds.some((function(e){return e===t}))}))}},{key:"filterAtoms",value:function(t,e){for(var n=[],r=0;r<t.length;++r){var i=t[r];"number"!=typeof e[i]?n.push(i):e[i]>=0?n.push(e[i]):n.push(-1)}return n}},{key:"removeNegative",value:function(t){for(var e=[],n=0;n<t.length;++n)t[n]>=0&&e.push(t[n]);return e}},{key:"filter",value:function(e,n,r){n.atoms=t.removeNegative(t.filterAtoms(n.atoms,r))}},{key:"clone",value:function(e,n){var r=new t(e.type);return Object.keys(e.data).forEach((function(t){r.data[t]=e.data[t]})),r.atoms=e.atoms.map((function(t){return n.get(t)})),r.pp=e.pp,r.bracketBox=e.bracketBox,r.patoms=null,r.bonds=null,r.allAtoms=e.allAtoms,r.data.expanded=e.data.expanded,r}},{key:"addAtom",value:function(t,e){t.atoms.push(e)}},{key:"removeAtom",value:function(t,e){if(t)for(var n=0;n<t.atoms.length;++n)if(t.atoms[n]===e)return void t.atoms.splice(n,1)}},{key:"getCrossBonds",value:function(t,e){var n={};return t.bonds.forEach((function(t,r){e.has(t.begin)&&!e.has(t.end)?(n[t.begin]||(n[t.begin]=[]),n[t.begin].push(r)):e.has(t.end)&&!e.has(t.begin)&&(n[t.end]||(n[t.end]=[]),n[t.end].push(r))})),n}},{key:"bracketPos",value:function(t,e,n){var r=t.atoms,i=n?Object.values(n).flat():null;if(i&&2===i.length){var a=e.bonds.get(i[0]).getCenter(e),o=e.bonds.get(i[1]).getCenter(e);t.bracketDir=_.diff(o,a).normalized()}else t.bracketDir=new _(1,0);var s=t.bracketDir,u=null,l=[];r.forEach((function(t){var n=e.atoms.get(t),r=new _(n.pp),i=new _(.05*3,.05*3),a=new it(r,r).extend(i,i);l.push(a)})),l.forEach((function(t){var e=null;[t.p0.x,t.p1.x].forEach((function(n){[t.p0.y,t.p1.y].forEach((function(t){var r=new _(n,t),i=new _(_.dot(r,s),_.dot(r,s.rotateSC(1,0)));e=e?e.include(i):new it(i,i)}))})),u=u?it.union(u,e):e}));var c=new _(.2,.4);u&&(u=u.extend(c,c)),t.bracketBox=u}},{key:"getBracketParameters",value:function(t,e,n,r,i,a){var o,s,u,l,c,d,h=[],f=Object.values(e),p=f.flat();return p.length<2?function(){i=i||new _(1,0),a=a||i.rotateSC(1,0);var t=Math.min(.25,.3*r.sz().x),e=_.lc2(i,r.p0.x,a,.5*(r.p0.y+r.p1.y)),n=_.lc2(i,r.p1.x,a,.5*(r.p0.y+r.p1.y)),o=r.sz().y;h.push(new ot(e,i.negated(),t,o),new ot(n,i,t,o))}():2===p.length&&2===f.length?(o=t.bonds.get(p[0]),s=t.bonds.get(p[1]),u=o.getCenter(t),l=s.getCenter(t),d=(c=_.diff(l,u).normalized()).negated(),h.push(new ot(u.addScaled(d,0),d,.25,1.5),new ot(l.addScaled(c,0),c,.25,1.5))):function(){for(var e=0;e<p.length;++e){var r=t.bonds.get(p[e]),i=r.getCenter(t),a=n.has(r.begin)?r.getDir(t):r.getDir(t).negated();h.push(new ot(i,a,.2,1))}}(),h}},{key:"getObjBBox",value:function(t,e){for(var n=e.atoms.get(t[0]).pp,r=new it(n,n),i=1;i<t.length;++i){var a=t[i],o=e.atoms.get(a).pp;r=r.include(o)}return r}},{key:"getAtoms",value:function(t,e){if(!e.allAtoms)return e.atoms;var n=[];return t.atoms.forEach((function(t,e){n.push(e)})),n}},{key:"getBonds",value:function(e,n){var r=t.getAtoms(e,n),i=[];return e.bonds.forEach((function(t,e){r.indexOf(t.begin)>=0&&r.indexOf(t.end)>=0&&i.push(e)})),i}},{key:"prepareMulForSaving",value:function(t,e){t.atoms.sort((function(t,e){return t-e})),t.atomSet=new H(t.atoms),t.parentAtomSet=new H(t.atomSet);var n=[],r=[];if(e.bonds.forEach((function(e,i){t.parentAtomSet.has(e.begin)&&t.parentAtomSet.has(e.end)?n.push(i):(t.parentAtomSet.has(e.begin)||t.parentAtomSet.has(e.end))&&r.push(i)})),0!==r.length&&2!==r.length)throw Error("Unsupported cross-bonds number");var i=-1,a=-1,o=null;if(2===r.length){var s=e.bonds.get(r[0]);i=t.parentAtomSet.has(s.begin)?s.begin:s.end;var u=e.bonds.get(r[1]);a=t.parentAtomSet.has(u.begin)?u.begin:u.end,o=u}for(var l=a,c=[],d=function(r){var s={};if(t.atoms.forEach((function(n){var r=e.atoms.get(n),i=e.atoms.add(new W(r));c.push(i),t.atomSet.add(i),s[n]=i})),n.forEach((function(t){var n=e.bonds.get(t),r=new q(n);r.begin=s[r.begin],r.end=s[r.end],e.bonds.add(r)})),null!==o){var u=new q(o);u.begin=l,u.end=s[i],e.bonds.add(u),l=s[a]}},h=0;h<t.data.mul-1;h++)d();if(l>=0){var f=e.bonds.get(r[1]);f.begin===a?f.begin=l:f.end=l}t.bonds=r,c.forEach((function(n){e.sGroupForest.getPathToRoot(t.id).reverse().forEach((function(t){e.atomAddToSGroup(t,n)}))}))}},{key:"getMassCentre",value:function(t,e){for(var n=new _,r=0;r<e.length;++r)n=n.addScaled(t.atoms.get(e[r]).pp,1/e.length);return n}}]),t}();function ut(t,e){return t.some((function(t){if(!t.pp)return!1;var n=t.pp.add(new _(.5,.5)),r=e.add(new _(.5,.5));return it.segmentIntersection(t.pp,n,e,r)}))}function lt(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return ct(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?ct(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function ct(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}(0,a.Z)(st,"TYPES",{SUP:"SUP",MUL:"MUL",SRU:"SRU",MON:"MON",MER:"MER",COP:"COP",CRO:"CRO",MOD:"MOD",GRA:"GRA",COM:"COM",MIX:"MIX",FOR:"FOR",DAT:"DAT",ANY:"ANY",GEN:"GEN"});var dt,ht=new WeakMap,ft=function(){function t(e){var n,i,a;(0,r.Z)(this,t),a={writable:!0,value:void 0},function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(n=this,i=ht),i.set(n,a),s()(null!=e),(0,f.Z)(this,ht,e)}return(0,i.Z)(t,[{key:"name",get:function(){return(0,p.Z)(this,ht).data.name}},{key:"relatedSGroupId",get:function(){return(0,p.Z)(this,ht).id}},{key:"isExpanded",get:function(){return(0,p.Z)(this,ht).data.expanded}},{key:"relatedSGroup",get:function(){return(0,p.Z)(this,ht)}}],[{key:"isFunctionalGroup",value:function(t){var e=nt.getInstance().getFunctionalGroupsList(),n=t.data.name;return"SUP"===t.type&&(e.some((function(t){return t.name===n}))||st.isSaltOrSolvent(n))}},{key:"getFunctionalGroupByName",value:function(t){var e,n=nt.getInstance().getFunctionalGroupsList();return t&&(e=n.find((function(e){var n=e.name,r=e.abbreviation;return n===t||r===t}))),e||null}},{key:"atomsInFunctionalGroup",value:function(t,e){if(0===t.size)return null;var n,r=lt(t.values());try{for(r.s();!(n=r.n()).done;)if(n.value.relatedSGroup.atoms.includes(e))return e}catch(t){r.e(t)}finally{r.f()}return null}},{key:"bondsInFunctionalGroup",value:function(t,e,n){if(0===e.size)return null;var r,i=lt(e.values());try{for(i.s();!(r=i.n()).done;){var a=r.value;if(st.getBonds(t,a.relatedSGroup).includes(n))return n}}catch(t){i.e(t)}finally{i.f()}return null}},{key:"findFunctionalGroupByAtom",value:function(t,e){var n,r=lt(t.values());try{for(r.s();!(n=r.n()).done;){var i=n.value;if(i.relatedSGroup.atoms.includes(e))return i.relatedSGroupId}}catch(t){r.e(t)}finally{r.f()}return null}},{key:"findFunctionalGroupByBond",value:function(t,e,n){var r,i=lt(e.values());try{for(i.s();!(r=i.n()).done;){var a=r.value;if(st.getBonds(t,a.relatedSGroup).includes(n))return a.relatedSGroupId}}catch(t){i.e(t)}finally{i.f()}return null}},{key:"clone",value:function(e){return new t((0,p.Z)(e,ht))}},{key:"isAttachmentBond",value:function(t,e){var n=e.begin,r=e.end;return t.atoms.includes(n)&&!t.atoms.includes(r)||t.atoms.includes(r)&&!t.atoms.includes(n)}},{key:"isAttachedSGroup",value:function(e,n){var r,i=lt(n.bonds.values());try{for(i.s();!(r=i.n()).done;){var a=r.value;if(t.isAttachmentBond(e,a))return!0}}catch(t){i.e(t)}finally{i.f()}return!1}},{key:"isAttachmentPointAtom",value:function(e,n){var r,i=n.sgroups,a=n.bonds,o=function(t,e){return e.atoms.includes(t)},s=lt(i.values());try{for(s.s();!(r=s.n()).done;){var u=r.value,l=t.isFunctionalGroup(u),c=u.atoms.includes(e);if(l&&c){var d,h=lt(a.values());try{for(h.s();!(d=h.n()).done;){var f=d.value,p=f.begin===e&&!o(f.end,u),m=f.end===e&&!o(f.begin,u);if(p||m)return!0}}catch(t){h.e(t)}finally{h.f()}if(!this.isAttachedSGroup(u,n))return u.atoms[0]===e}}}catch(t){s.e(t)}finally{s.f()}return!1}},{key:"isFirstAtomInFunctionalGroup",value:function(e,n){var r,i=lt(e.values());try{for(i.s();!(r=i.n()).done;){var a=r.value;if(t.isFunctionalGroup(a)&&n===a.atoms[0])return!0}}catch(t){i.e(t)}finally{i.f()}return!1}},{key:"isAtomInContractedFunctionalGroup",value:function(e,n,r,i){var a=[];return i?n.forEach((function(e){t.isContractedFunctionalGroup(e.item.id,r)&&a.push(e.item.id)})):n.forEach((function(e){t.isContractedFunctionalGroup(e.id,r)&&a.push(e.id)})),a.some((function(t){return e.sgs.has(t)}))}},{key:"isBondInContractedFunctionalGroup",value:function(e,n,r){return(0,u.Z)(n.values()).some((function(n){var i="item"in n?n.item.id:n.id,a="item"in n?n.item.atoms:n.atoms;return t.isContractedFunctionalGroup(i,r)&&a.includes(e.begin)&&a.includes(e.end)}))}},{key:"isContractedFunctionalGroup",value:function(t,e){var n=!1,r=!1;return e.forEach((function(e){e.relatedSGroupId===t&&(n=!0,r=e.isExpanded)})),!r&&n}}]),t}(),pt=(0,i.Z)((function t(e,n,i){(0,r.Z)(this,t),s()(3===arguments.length,"Invalid parameter number."),this.begin=e,this.end=n,this.bid=i,this.dir=new _,this.norm=new _,this.ang=0,this.p=new _,this.loop=-1,this.contra=-1,this.next=-1,this.leftSin=0,this.leftCos=0,this.leftNeighbor=0,this.rightSin=0,this.rightCos=0,this.rightNeighbor=0})),mt=(0,i.Z)((function t(e,n,i){var a=this;(0,r.Z)(this,t),this.hbs=e,this.dblBonds=0,this.aromatic=!0,this.convex=i||!1,e.forEach((function(t){var e=n.bonds.get(n.halfBonds.get(t).bid);e.type!==q.PATTERN.TYPE.AROMATIC&&(a.aromatic=!1),e.type===q.PATTERN.TYPE.DOUBLE&&a.dblBonds++}))})),gt=function(){function t(e){(0,r.Z)(this,t),this.frags=new H,this.resth=(null==e?void 0:e.resth)||!1,this.range=(null==e?void 0:e.range)||"",this.ifthen=(null==e?void 0:e.ifthen)||0,this.index=(null==e?void 0:e.index)||-1}return(0,i.Z)(t,[{key:"getAttrs",value:function(){return{resth:this.resth,range:this.range,ifthen:this.ifthen,index:this.index}}},{key:"clone",value:function(e){var n=new t(this);return this.frags.forEach((function(t){n.frags.add(e?e.get(t):t)})),n}}],[{key:"findRGroupByFragment",value:function(t,e){return t.find((function(t,n){return n.frags.has(e)}))}}]),t}();!function(t){t.OpenAngle="open-angle",t.FilledTriangle="filled-triangle",t.FilledBow="filled-bow",t.DashedOpenAngle="dashed-open-angle",t.Failed="failed",t.BothEndsFilledTriangle="both-ends-filled-triangle",t.EquilibriumFilledTriangle="equilibrium-filled-triangle",t.EquilibriumFilledHalfBow="equilibrium-filled-half-bow",t.EquilibriumOpenAngle="equilibrium-open-angle",t.UnbalancedEquilibriumFilledHalfBow="unbalanced-equilibrium-filled-half-bow",t.UnbalancedEquilibriumOpenHalfAngle="unbalanced-equilibrium-open-half-angle",t.UnbalancedEquilibriumLargeFilledHalfBow="unbalanced-equilibrium-large-filled-half-bow",t.UnbalancedEquilibriumFilledHalfTriangle="unbalanced-equilibrium-filled-half-triangle",t.EllipticalArcFilledBow="elliptical-arc-arrow-filled-bow",t.EllipticalArcFilledTriangle="elliptical-arc-arrow-filled-triangle",t.EllipticalArcOpenAngle="elliptical-arc-arrow-open-angle",t.EllipticalArcOpenHalfAngle="elliptical-arc-arrow-open-half-angle"}(dt||(dt={}));var vt,yt=function(){function t(e){if((0,r.Z)(this,t),this.pos=[],e.pos)for(var n=0;n<e.pos.length;n++){var i=e.pos[n];this.pos[n]=i?new _(e.pos[n]):new _}var a;this.mode=e.mode,t.isElliptical(this)&&(this.height=null!==(a=e.height)&&void 0!==a?a:2)}return(0,i.Z)(t,[{key:"clone",value:function(){return new t(this)}},{key:"center",value:function(){return _.centre(this.pos[0],this.pos[1])}}],[{key:"isElliptical",value:function(t){return[dt.EllipticalArcFilledBow,dt.EllipticalArcFilledTriangle,dt.EllipticalArcOpenHalfAngle,dt.EllipticalArcOpenAngle].includes(t.mode)}}]),t}(),bt=function(){function t(e){(0,r.Z)(this,t),this.pp=null!=e&&e.pp?new _(e.pp):new _}return(0,i.Z)(t,[{key:"clone",value:function(){return new t(this)}}]),t}(),wt=function(){function t(){(0,r.Z)(this,t),this.parent=new Map,this.children=new Map,this.children.set(-1,[]),this.atomSets=new Map}return(0,i.Z)(t,[{key:"getSGroupsBFS",value:function(){for(var t=[],e=Array.from(this.children.get(-1));e.length>0;){var n=e.shift();if("number"!=typeof n)break;var r=this.children.get(n);if(void 0===r)break;r.forEach((function(t){e.push(t)})),t.push(n)}return t}},{key:"getAtomSetRelations",value:function(t,e){var n=this,r=new Map,i=new Map;this.atomSets.delete(t),this.atomSets.forEach((function(t,n){i.set(n,t.isSuperset(e)),r.set(n,e.isSuperset(t)&&!t.equals(e))}));var a=Array.from(this.atomSets.keys()).filter((function(t){if(!i.get(t))return!1;var e=n.children.get(t);return e&&e.findIndex((function(t){return i.get(t)}))<0}));return{children:Array.from(this.atomSets.keys()).filter((function(t){return r.get(t)&&!r.get(n.parent.get(t))})),parent:0===a.length?-1:a[0]}}},{key:"getPathToRoot",value:function(t){for(var e=[],n=t;n>=0;n=this.parent.get(n))e.push(n);return e}},{key:"insert",value:function(t,e,n){var r,i=this,a=t.id,o=t.atoms;if(s()(!this.parent.has(a),"sgid already present in the forest"),s()(!this.children.has(a),"sgid already present in the forest"),!e||!n){var u=this.getAtomSetRelations(a,new H(o));e=u.parent,n=u.children}return n.forEach((function(t){i.resetParentLink(t,a)})),this.children.set(a,n.filter((function(t){return i.parent.get(t)}))),this.parent.set(a,e),null===(r=this.children.get(e))||void 0===r||r.push(a),this.atomSets.set(a,new H(o)),{parent:e,children:n}}},{key:"resetParentLink",value:function(t,e){var n=this.parent.get(t);if(void 0!==n){var r=this.children.get(n);if(r){var i=r.indexOf(t);r.splice(i,1),this.parent.set(t,e)}}}},{key:"remove",value:function(t){var e,n=this;try{s()(this.parent.has(t),"sgid is not in the forest"),s()(this.children.has(t),"sgid is not in the forest")}catch(t){}var r=this.parent.get(t),i=this.children.get(r);if(r&&i){null===(e=this.children.get(t))||void 0===e||e.forEach((function(t){var e;n.parent.set(t,r),null===(e=n.children.get(r))||void 0===e||e.push(t)}));var a=i.indexOf(t);i.splice(a,1),this.children.delete(t),this.parent.delete(t),this.atomSets.delete(t)}}}]),t}();function xt(t,e){var n=e.reduce((function(e,n){var r=t.atoms.get(n);return e.union(r.sgs)}),new H);return Array.from(n).some((function(n){var r=t.sgroups.get(n);if("DAT"===r.type)return!1;var i=st.getAtoms(t,r);return i.length<e.length?i.findIndex((function(t){return-1===e.indexOf(t)}))>=0:e.findIndex((function(t){return-1===i.indexOf(t)}))>=0}))}!function(t){t.ellipse="ellipse",t.rectangle="rectangle",t.line="line"}(vt||(vt={}));var Et=function(){function t(e){if((0,r.Z)(this,t),this.pos=[],null!=e&&e.pos)for(var n=0;n<e.pos.length;n++){var i=e.pos[n];this.pos[n]=i?new _(e.pos[n]):new _}this.mode=(null==e?void 0:e.mode)||vt.line}return(0,i.Z)(t,[{key:"clone",value:function(){return new t(this)}},{key:"center",value:function(){return this.mode===vt.rectangle?_.centre(this.pos[0],this.pos[1]):this.pos[0]}}]),t}();function Ot(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return At(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?At(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function At(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var St=function(t){(0,l.Z)(s,t);var e,n,o=(e=s,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function s(){var t;(0,r.Z)(this,s);for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];return t=o.call.apply(o,[this].concat(n)),(0,a.Z)((0,g.Z)(t),"nextId",0),t}return(0,i.Z)(s,[{key:"add",value:function(t){var e=this.nextId++;return(0,v.Z)((0,d.Z)(s.prototype),"set",this).call(this,e,t),e}},{key:"newId",value:function(){return this.nextId++}},{key:"keyOf",value:function(t){var e,n=Ot(this.entries());try{for(n.s();!(e=n.n()).done;){var r=(0,m.Z)(e.value,2),i=r[0];if(r[1]===t)return i}}catch(t){n.e(t)}finally{n.f()}return null}},{key:"find",value:function(t){var e,n=Ot(this.entries());try{for(n.s();!(e=n.n()).done;){var r=(0,m.Z)(e.value,2),i=r[0];if(t(i,r[1]))return i}}catch(t){n.e(t)}finally{n.f()}return null}},{key:"filter",value:function(t){return new s(Array.from(this).filter((function(e){var n=(0,m.Z)(e,2),r=n[0],i=n[1];return t(r,i)})))}},{key:"some",value:function(t){var e,n=Ot(this.values());try{for(n.s();!(e=n.n()).done;)if(t(e.value))return!0}catch(t){n.e(t)}finally{n.f()}return!1}}]),s}((0,h.Z)(Map));function Rt(t,e){for(var n=0;n<t.length;++n)if(t[n]===e)return!1;return t.push(e),!0}var Pt,Tt=function(){function t(){(0,r.Z)(this,t),this.atoms=new St,this.bonds=new St,this.sgroups=new St,this.halfBonds=new St,this.loops=new St,this.isReaction=!1,this.rxnArrows=new St,this.rxnPluses=new St,this.frags=new St,this.rgroups=new St,this.name="",this.abbreviation="",this.sGroupForest=new wt,this.simpleObjects=new St,this.texts=new St,this.functionalGroups=new St,this.highlights=new St}return(0,i.Z)(t,[{key:"hasRxnProps",value:function(){return!(!this.atoms.find((function(t,e){return e.hasRxnProps()}))&&!this.bonds.find((function(t,e){return e.hasRxnProps()})))}},{key:"hasRxnArrow",value:function(){return this.rxnArrows.size>=1}},{key:"hasRxnPluses",value:function(){return this.rxnPluses.size>0}},{key:"isRxn",value:function(){return this.hasRxnArrow()||this.hasRxnPluses()}},{key:"isBlank",value:function(){return 0===this.atoms.size&&0===this.rxnArrows.size&&0===this.rxnPluses.size&&0===this.simpleObjects.size&&0===this.texts.size}},{key:"clone",value:function(e,n,r,i,a,o){return this.mergeInto(new t,e,n,r,!1,i,a,o)}},{key:"getScaffold",value:function(){var t=this,e=new H;return this.atoms.forEach((function(t,n){e.add(n)})),this.rgroups.forEach((function(n){n.frags.forEach((function(n,r){t.atoms.forEach((function(t,n){t.fragment===r&&e.delete(n)}))}))})),this.clone(e)}},{key:"getFragmentIds",value:function(t){var e=new H;return this.atoms.forEach((function(n,r){n.fragment===t&&e.add(r)})),e}},{key:"getFragment",value:function(t){return this.clone(this.getFragmentIds(t),null,!0)}},{key:"mergeInto",value:function(t,e,n,r,i,a,o,s){var u=this;e=e||new H(this.atoms.keys()),n=n||new H(this.bonds.keys()),o=o||new H(this.simpleObjects.keys()),s=s||new H(this.texts.keys()),a=a||new Map,n=n.filter((function(t){var n=u.bonds.get(t);return e.has(n.begin)&&e.has(n.end)}));var l=new H;this.atoms.forEach((function(t,n){e.has(n)&&l.add(t.fragment)}));var c=new Map;this.frags.forEach((function(e,n){l.has(n)&&c.set(n,t.frags.add(null))}));var d=[];this.rgroups.forEach((function(e,n){var r=i;if(r||(e.frags.forEach((function(t,e){d.push(e),l.has(e)&&(r=!0)})),r)){var a=t.rgroups.get(n);a?e.frags.forEach((function(t,e){d.push(e),l.has(e)&&a.frags.add(c.get(e))})):t.rgroups.set(n,e.clone(c))}})),this.atoms.forEach((function(n,r){e.has(r)&&-1===d.indexOf(n.fragment)&&a.set(r,t.atoms.add(n.clone(c)))})),this.atoms.forEach((function(n,r){e.has(r)&&-1!==d.indexOf(n.fragment)&&a.set(r,t.atoms.add(n.clone(c)))})),c.forEach((function(e,n){var r=u.frags.get(n);r&&r instanceof Q&&t.frags.set(e,u.frags.get(n).clone(a))}));var h=new Map;return this.bonds.forEach((function(e,r){n.has(r)&&h.set(r,t.bonds.add(e.clone(a)))})),this.sgroups.forEach((function(n){if(!n.atoms.some((function(t){return!e.has(t)}))){n=st.clone(n,a);var r=t.sgroups.add(n);n.id=r,n.atoms.forEach((function(e){var n=t.atoms.get(e);n&&n.sgs.add(r)})),"DAT"===n.type?t.sGroupForest.insert(n,-1,[]):t.sGroupForest.insert(n)}})),this.functionalGroups.forEach((function(e){e=ft.clone(e),t.functionalGroups.add(e)})),o.forEach((function(e){t.simpleObjects.add(u.simpleObjects.get(e).clone())})),s.forEach((function(e){t.texts.add(u.texts.get(e).clone())})),r||(t.isReaction=this.isReaction,this.rxnArrows.forEach((function(e){t.rxnArrows.add(e.clone())})),this.rxnPluses.forEach((function(e){t.rxnPluses.add(e.clone())}))),t.name=this.name,t}},{key:"prepareLoopStructure",value:function(){this.initHalfBonds(),this.initNeighbors(),this.updateHalfBonds(Array.from(this.atoms.keys())),this.sortNeighbors(Array.from(this.atoms.keys())),this.findLoops()}},{key:"atomAddToSGroup",value:function(t,e){st.addAtom(this.sgroups.get(t),e),this.atoms.get(e).sgs.add(t)}},{key:"calcConn",value:function(t){for(var e=0,n=0;n<t.neighbors.length;++n){var r=this.halfBonds.get(t.neighbors[n]);switch(this.bonds.get(r.bid).type){case q.PATTERN.TYPE.SINGLE:e+=1;break;case q.PATTERN.TYPE.DOUBLE:e+=2;break;case q.PATTERN.TYPE.TRIPLE:e+=3;break;case q.PATTERN.TYPE.DATIVE:case q.PATTERN.TYPE.HYDROGEN:break;case q.PATTERN.TYPE.AROMATIC:return 1===t.neighbors.length?[-1,!0]:[t.neighbors.length,!0];default:return[-1,!1]}}return[e,!1]}},{key:"findBondId",value:function(t,e){return this.bonds.find((function(n,r){return r.begin===t&&r.end===e||r.begin===e&&r.end===t}))}},{key:"initNeighbors",value:function(){var t=this;this.atoms.forEach((function(t){t.neighbors=[]})),this.bonds.forEach((function(e){var n=t.atoms.get(e.begin),r=t.atoms.get(e.end);n.neighbors.push(e.hb1),r.neighbors.push(e.hb2)}))}},{key:"bondInitHalfBonds",value:function(t,e){(e=e||this.bonds.get(t)).hb1=2*t,e.hb2=2*t+1,this.halfBonds.set(e.hb1,new pt(e.begin,e.end,t)),this.halfBonds.set(e.hb2,new pt(e.end,e.begin,t));var n=this.halfBonds.get(e.hb1),r=this.halfBonds.get(e.hb2);n.contra=e.hb2,r.contra=e.hb1}},{key:"halfBondUpdate",value:function(t){var e=this.halfBonds.get(t),n=this.atoms.get(e.begin).pp,r=this.atoms.get(e.end).pp,i=_.diff(r,n).normalized();e.dir=_.dist(r,n)>1e-4?i:new _(1,0),e.norm=e.dir.turnLeft(),e.ang=e.dir.oxAngle(),e.loop<0&&(e.loop=-1)}},{key:"initHalfBonds",value:function(){var t=this;this.halfBonds.clear(),this.bonds.forEach((function(e,n){t.bondInitHalfBonds(n,e)}))}},{key:"setHbNext",value:function(t,e){this.halfBonds.get(this.halfBonds.get(t).contra).next=e}},{key:"halfBondSetAngle",value:function(t,e){var n=this.halfBonds.get(t),r=this.halfBonds.get(e);r.rightCos=_.dot(r.dir,n.dir),n.leftCos=_.dot(r.dir,n.dir),r.rightSin=_.cross(r.dir,n.dir),n.leftSin=_.cross(r.dir,n.dir),n.leftNeighbor=e,r.rightNeighbor=t}},{key:"atomAddNeighbor",value:function(t){var e,n=this.halfBonds.get(t),r=this.atoms.get(n.begin);for(e=0;e<r.neighbors.length&&!(this.halfBonds.get(r.neighbors[e]).ang>n.ang);++e);r.neighbors.splice(e,0,t);var i=r.neighbors[(e+1)%r.neighbors.length],a=r.neighbors[(e+r.neighbors.length-1)%r.neighbors.length];this.setHbNext(a,t),this.setHbNext(t,i),this.halfBondSetAngle(t,a),this.halfBondSetAngle(i,t)}},{key:"atomSortNeighbors",value:function(t){var e=this,n=this.atoms.get(t),r=this.halfBonds;n.neighbors.sort((function(t,e){return r.get(t).ang-r.get(e).ang})).forEach((function(t,r){var i=n.neighbors[(r+1)%n.neighbors.length];e.halfBonds.get(e.halfBonds.get(t).contra).next=i,e.halfBondSetAngle(i,t)}))}},{key:"sortNeighbors",value:function(t){var e=this;t?t.forEach((function(t){e.atomSortNeighbors(t)})):this.atoms.forEach((function(t,n){e.atomSortNeighbors(n)}))}},{key:"atomUpdateHalfBonds",value:function(t){var e=this;this.atoms.get(t).neighbors.forEach((function(t){e.halfBondUpdate(t),e.halfBondUpdate(e.halfBonds.get(t).contra)}))}},{key:"updateHalfBonds",value:function(t){var e=this;t?t.forEach((function(t){e.atomUpdateHalfBonds(t)})):this.atoms.forEach((function(t,n){e.atomUpdateHalfBonds(n)}))}},{key:"sGroupsRecalcCrossBonds",value:function(){var t=this;this.sgroups.forEach((function(t){t.xBonds=[],t.neiAtoms=[]})),this.bonds.forEach((function(e,n){var r=t.atoms.get(e.begin),i=t.atoms.get(e.end);r.sgs.forEach((function(r){if(!i.sgs.has(r)){var a=t.sgroups.get(r);a.xBonds.push(n),Rt(a.neiAtoms,e.end)}})),i.sgs.forEach((function(i){if(!r.sgs.has(i)){var a=t.sgroups.get(i);a.xBonds.push(n),Rt(a.neiAtoms,e.begin)}}))}))}},{key:"sGroupDelete",value:function(t){var e=this;this.sgroups.get(t).atoms.forEach((function(n){e.atoms.get(n).sgs.delete(t)})),this.sGroupForest.remove(t),this.sgroups.delete(t)}},{key:"atomSetPos",value:function(t,e){this.atoms.get(t).pp=e}},{key:"rxnPlusSetPos",value:function(t,e){this.rxnPluses.get(t).pp=e}},{key:"rxnArrowSetPos",value:function(t,e){var n=this.rxnArrows.get(t);n&&(n.pos=e)}},{key:"simpleObjectSetPos",value:function(t,e){this.simpleObjects.get(t).pos=e}},{key:"textSetPosition",value:function(t,e){var n=this.texts.get(t);n&&(n.position=e)}},{key:"getCoordBoundingBox",value:function(t){var e=null;function n(t){e?t instanceof Array?t.forEach((function(t){e.min=_.min(e.min,t),e.max=_.max(e.max,t)})):(e.min=_.min(e.min,t),e.max=_.max(e.max,t)):e={min:t,max:t}}var r=!t||0===t.size;return this.atoms.forEach((function(e,i){(r||t.has(i))&&n(e.pp)})),r&&(this.rxnPluses.forEach((function(t){n(t.pp)})),this.rxnArrows.forEach((function(t){n(t.pos)})),this.simpleObjects.forEach((function(t){n(t.pos)})),this.texts.forEach((function(t){n(t.position)}))),!e&&r&&(e={min:new _(0,0),max:new _(1,1)}),e}},{key:"getCoordBoundingBoxObj",value:function(){var t=null;return this.atoms.forEach((function(e){var n;n=e.pp,t?(t.min=_.min(t.min,n),t.max=_.max(t.max,n)):t={min:new _(n),max:new _(n)}})),t}},{key:"getBondLengthData",value:function(){var t=this,e=0,n=0;return this.bonds.forEach((function(r){e+=_.dist(t.atoms.get(r.begin).pp,t.atoms.get(r.end).pp),n++})),{cnt:n,totalLength:e}}},{key:"getAvgBondLength",value:function(){var t=this.getBondLengthData();return t.cnt>0?t.totalLength/t.cnt:-1}},{key:"getAvgClosestAtomDistance",value:function(){var t,e,n,r=0,i=0,a=Array.from(this.atoms.keys());for(e=0;e<a.length;++e){for(t=-1,n=0;n<a.length;++n)n!==e&&(i=_.dist(this.atoms.get(a[n]).pp,this.atoms.get(a[e]).pp),(t<0||t>i)&&(t=i));r+=t}return a.length>0?r/a.length:-1}},{key:"checkBondExists",value:function(t,e){return void 0!==this.bonds.find((function(n,r){return r.begin===t&&r.end===e||r.end===t&&r.begin===e}))}},{key:"findConnectedComponent",value:function(t){for(var e=this,n=[t],r=new H;n.length>0;){var i=n.pop();r.add(i),this.atoms.get(i).neighbors.forEach((function(t){var i=e.halfBonds.get(t).end;r.has(i)||n.push(i)}))}return r}},{key:"findConnectedComponents",value:function(t){var e=this;this.halfBonds.size||(this.initHalfBonds(),this.initNeighbors(),this.updateHalfBonds(Array.from(this.atoms.keys())),this.sortNeighbors(Array.from(this.atoms.keys())));var n=new H,r=[];return this.atoms.forEach((function(i,a){if((t||i.fragment<0)&&!n.has(a)){var o=e.findConnectedComponent(a);r.push(o),n=n.union(o)}})),r}},{key:"markFragment",value:function(t){var e=this,n=new Q,r=this.frags.add(n);t.forEach((function(t){var i=e.atoms.get(t);i.stereoLabel&&n.updateStereoAtom(e,t,r,!0),i.fragment=r}))}},{key:"markFragments",value:function(){var t=this;this.findConnectedComponents().forEach((function(e){t.markFragment(e)}))}},{key:"scale",value:function(t){var e=this;1!==t&&(this.atoms.forEach((function(e){e.pp=e.pp.scaled(t)})),this.rxnPluses.forEach((function(e){e.pp=e.pp.scaled(t)})),this.rxnArrows.forEach((function(e){e.pos=e.pos.map((function(e){return e.scaled(t)}))})),this.sgroups.forEach((function(e){e.pp=e.pp?e.pp.scaled(t):null})),this.texts.forEach((function(n){e.rxnArrows.size&&(n.pos=n.pos.map((function(e){return e.scaled(t)})),n.position=n.position.scaled(t))})))}},{key:"rescale",value:function(){var t=this.getAvgBondLength();t<0&&!this.isReaction&&(t=this.getAvgClosestAtomDistance()),t<.001&&(t=1);var e=1/t;this.scale(e)}},{key:"loopHasSelfIntersections",value:function(t){for(var e=0;e<t.length;++e)for(var n=this.halfBonds.get(t[e]),r=this.atoms.get(n.begin).pp,i=this.atoms.get(n.end).pp,a=new H([n.begin,n.end]),o=e+2;o<t.length;++o){var s=this.halfBonds.get(t[o]);if(!a.has(s.begin)&&!a.has(s.end)){var u=this.atoms.get(s.begin).pp,l=this.atoms.get(s.end).pp;if(it.segmentIntersection(r,i,u,l))return!0}}return!1}},{key:"partitionLoop",value:function(t){for(var e=[],n=!0;n;){var r={};n=!1;for(var i=0;i<t.length;++i){var a=t[i],o=this.halfBonds.get(a).begin,s=this.halfBonds.get(a).end;if(s in r){var u=r[s],l=t.slice(u,i+1);e.push(l),i<t.length&&t.splice(u,i-u+1),n=!0;break}r[o]=i}n||e.push(t)}return e}},{key:"halfBondAngle",value:function(t,e){var n=this.halfBonds.get(t),r=this.halfBonds.get(e);return Math.atan2(_.cross(n.dir,r.dir),_.dot(n.dir,r.dir))}},{key:"loopIsConvex",value:function(t){var e=this;return t.every((function(t,n,r){return e.halfBondAngle(t,r[(n+1)%r.length])<=0}))}},{key:"loopIsInner",value:function(t){var e=this,n=2*Math.PI;return t.forEach((function(t,r,i){var a=i[(r+1)%i.length],o=e.halfBonds.get(a),s=e.halfBondAngle(t,a);n+=o.contra===t?Math.PI:s})),Math.abs(n)<Math.PI}},{key:"findLoops",value:function(){var t,e,n,r=this,i=[],a=new H;return this.halfBonds.forEach((function(o,s){if(-1===o.loop)for(t=s,e=0,n=[];e<=r.halfBonds.size;t=r.halfBonds.get(t).next,++e){if(e>0&&t===s){r.partitionLoop(n).forEach((function(t){var e;r.loopIsInner(t)&&!r.loopHasSelfIntersections(t)?(e=Math.min.apply(Math,(0,u.Z)(t)),r.loops.set(e,new mt(t,r,r.loopIsConvex(t)))):e=-2,t.forEach((function(t){r.halfBonds.get(t).loop=e,a.add(r.halfBonds.get(t).bid)})),e>=0&&i.push(e)}));break}n.push(t)}})),{newLoops:i,bondsToMark:Array.from(a)}}},{key:"calcImplicitHydrogen",value:function(t){var e=this.atoms.get(t),n=this.calcConn(e),r=(0,m.Z)(n,2),i=r[0],a=r[1],o=i;if(e.badConn=!1,a)if("C"===e.label&&0===e.charge){if(3===i)return void(e.implicitH=-V(e.radical));if(2===i)return void(e.implicitH=1-V(e.radical))}else{if("O"===e.label&&0===e.charge||"N"===e.label&&0===e.charge&&3===i||"N"===e.label&&1===e.charge&&3===i||"S"===e.label&&0===e.charge&&3===i)return void(e.implicitH=0);e.hasImplicitH||o++}if(o<0||e.isQuery())e.implicitH=0;else if(e.explicitValence>=0){var s=N.get(e.label);e.implicitH=s?e.explicitValence-e.calcValenceMinusHyd(o):0,e.implicitH<0&&(e.implicitH=0,e.badConn=!0)}else e.calcValence(o)}},{key:"setImplicitHydrogen",value:function(t){var e=this;this.sgroups.forEach((function(t){"MRV_IMPLICIT_H"===t.data.fieldName&&(e.atoms.get(t.atoms[0]).hasImplicitH=!0)})),t?t.forEach((function(t){e.atoms.get(t)&&e.calcImplicitHydrogen(t)})):this.atoms.forEach((function(t,n){e.calcImplicitHydrogen(n)}))}},{key:"atomGetNeighbors",value:function(t){var e,n=this;return null===(e=this.atoms.get(t))||void 0===e?void 0:e.neighbors.map((function(t){var e=n.halfBonds.get(t);return{aid:e.end,bid:e.bid}}))}},{key:"getComponents",value:function(){var t=this,e=this.findConnectedComponents(!0),n=[],r=null;this.rxnArrows.forEach((function(t){r=t.center().x})),this.rxnPluses.forEach((function(t){n.push(t.pp.x)})),null!==r&&n.push(r),n.sort((function(t,e){return t-e}));var i=[];e.forEach((function(e){for(var r=t.getCoordBoundingBox(e),a=_.lc2(r.min,.5,r.max,.5),o=0;a.x>n[o];)++o;i[o]=i[o]||new H,i[o]=i[o].union(e)}));var a=[],o=[];return i.forEach((function(e){e&&(1===t.defineRxnFragmentTypeForAtomset(e,r||0)?a.push(e):o.push(e))})),{reactants:a,products:o}}},{key:"defineRxnFragmentTypeForAtomset",value:function(t,e){var n=this.getCoordBoundingBox(t);return _.lc2(n.min,.5,n.max,.5).x<e?1:2}},{key:"getBondFragment",value:function(t){var e,n,r=null===(e=this.bonds.get(t))||void 0===e?void 0:e.begin;return r&&(null===(n=this.atoms.get(r))||void 0===n?void 0:n.fragment)}},{key:"bindSGroupsToFunctionalGroups",value:function(){var t=this;this.sgroups.forEach((function(e){ft.isFunctionalGroup(e)&&t.functionalGroups.add(new ft(e))}))}}]),t}();!function(t){t.Bold="BOLD",t.Italic="ITALIC",t.Subscript="SUBSCRIPT",t.Superscript="SUPERSCRIPT",t.FontSize="CUSTOM_FONT_SIZE"}(Pt||(Pt={}));var kt,Bt=function(){function t(e){var n;(0,r.Z)(this,t),this.pos=(n=null==e?void 0:e.pos)&&n.length?n.map((function(t){return new _(t)})):[new _,new _,new _,new _],this.content=(null==e?void 0:e.content)||"",this.position=null!=e&&e.position?new _(e.position):new _}return(0,i.Z)(t,[{key:"setPos",value:function(t){this.pos=t||[]}},{key:"clone",value:function(){return new t(this)}}]),t}(),Ct=(0,i.Z)((function t(e){(0,r.Z)(this,t);var n=e.atoms,i=e.bonds,a=e.color;this.color=a,this.atoms=n,this.bonds=i})),Mt=function(t){if("object"===(0,y.Z)(t)&&t.y){var e=(0,b.cloneDeep)(t);return e.y=-e.y,e}},Zt=function(t){return(0,b.cloneDeepWith)(t,Mt)};function Nt(t,e,n,r){null==n||n===r||Array.isArray(n)&&0===n.length||(t[e]=n)}function It(t){return("number"==typeof t?t:parseFloat(t)).toFixed(8)}!function(t){t.LOADING="LOADING",t.SUCCESS="SUCCESS",t.FAILURE="FAILURE"}(kt||(kt={}));var Lt,Dt=(Lt=(0,w.Z)(E().mark((function t(e,n){var r;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n.emit(kt.LOADING),t.prev=1,t.next=4,e();case 4:return r=t.sent,n.emit(kt.SUCCESS),t.abrupt("return",r);case 9:return t.prev=9,t.t0=t.catch(1),n.emit(kt.FAILURE),t.abrupt("return",void 0);case 13:case"end":return t.stop()}}),t,null,[[1,9]])}))),function(t,e){return Lt.apply(this,arguments)});function _t(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function jt(t){var e={atoms:Array.from(t.atoms.values()).map((function(t){return"R#"===t.label?function(t){var e={type:"rg-label"};return Nt(e,"location",[t.pp.x,-t.pp.y,t.pp.z]),Nt(e,"attachmentPoints",t.attpnt,0),Nt(e,"$refs",function(t){var e,n,r=[];for(e=0;e<32;e++)t&1<<e&&(n=e+1,r.push(n));return r}(t.rglabel).map((function(t){return"rg-".concat(t)}))),e}(t):"L#"===t.label?(Nt(n={type:"atom-list"},"location",[(e=t).pp.x,-e.pp.y,e.pp.z]),Nt(n,"attachmentPoints",e.attpnt,0),Nt(n,"elements",e.atomList.labelList()),Nt(n,"notList",e.atomList.notList,!1),n):function(t){var e={};return Nt(e,"label",t.label),Nt(e,"alias",t.alias),Nt(e,"location",[t.pp.x,-t.pp.y,t.pp.z]),Nt(e,"charge",t.charge,0),Nt(e,"explicitValence",t.explicitValence,-1),Nt(e,"isotope",t.isotope,0),Nt(e,"radical",t.radical,0),Nt(e,"attachmentPoints",t.attpnt,0),Nt(e,"stereoLabel",t.stereoLabel,null),Nt(e,"stereoParity",t.stereoCare,0),Nt(e,"weight",t.weight,0),Nt(e,"ringBondCount",t.ringBondCount,0),Nt(e,"substitutionCount",t.substitutionCount,0),Nt(e,"unsaturatedAtom",!!t.unsaturatedAtom,!1),Nt(e,"hCount",t.hCount,0),Nt(e,"mapping",parseInt(t.aam),0),Nt(e,"invRet",t.invRet,0),Nt(e,"exactChangeFlag",!!t.exactChangeFlag,!1),e}(t);var e,n}))};0!==t.bonds.size&&(e.bonds=Array.from(t.bonds.values()).map(Gt)),0!==t.sgroups.size&&(e.sgroups=Array.from(t.sgroups.values()).map((function(e){return function(t,e){var n={};switch(Nt(n,"type",e.type),Nt(n,"atoms",e.atoms),e.type){case"GEN":break;case"MUL":Nt(n,"mul",e.data.mul||1);break;case"SRU":Nt(n,"subscript",e.data.subscript||"n"),Nt(n,"connectivity",e.data.connectivity.toUpperCase()||"ht");break;case"SUP":Nt(n,"name",e.data.name||""),Nt(n,"expanded",e.data.expanded),Nt(n,"id",e.id);break;case"DAT":var r=e.data;Nt(n,"placement",r.absolute,!0),Nt(n,"display",r.attached,!1),Nt(n,"context",r.context),Nt(n,"fieldName",r.fieldName),Nt(n,"fieldData",r.fieldValue),Nt(n,"bonds",st.getBonds(t,e))}return n}(t,e)})));var n=t.frags.get(0);return n&&Nt(e,"stereoFlagPosition",n.stereoFlagPosition,null),function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?_t(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):_t(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}({type:"molecule"},e)}function Gt(t){var e={};return Nt(e,"type",t.type),Nt(e,"atoms",[t.begin,t.end]),Nt(e,"stereo",t.stereo,0),Nt(e,"topology",t.topology,0),Nt(e,"center",t.reactingCenterStatus,0),e}function Ft(t){var e=new Tt;return t.atoms.forEach((function(t){var n,r;"rg-label"===t.type&&e.atoms.add(function(t){var e,n,r={label:"R#"};return Nt(r,"pp",{x:t.location[0],y:-t.location[1],z:t.location[2]||0}),Nt(r,"attpnt",t.attachmentPoints),Nt(r,"rglabel",(e=t.$refs.map((function(t){return parseInt(t.slice(3))})),n=0,e.forEach((function(t){n|=1<<t-1})),n)),new W(r)}(t)),"atom-list"===t.type&&e.atoms.add(function(t){var e={label:"L#"};return Nt(e,"pp",{x:t.location[0],y:-t.location[1],z:t.location[2]||0}),Nt(e,"attpnt",t.attachmentPoints),Nt(e,"atomList",{ids:t.elements.map((function(t){var e;return null===(e=N.get(t))||void 0===e?void 0:e.number})).filter((function(t){return t})),notList:t.notList}),new W(e)}(t)),t.type||e.atoms.add((Nt(r={},"label",(n=t).label),Nt(r,"alias",n.alias),Nt(r,"pp",{x:n.location[0],y:-n.location[1],z:n.location[2]||0}),Nt(r,"charge",n.charge),Nt(r,"explicitValence",n.explicitValence),Nt(r,"isotope",n.isotope),Nt(r,"radical",n.radical),Nt(r,"attpnt",n.attachmentPoints),Nt(r,"stereoLabel",n.stereoLabel),Nt(r,"stereoParity",n.stereoParity),Nt(r,"weight",n.weight),Nt(r,"ringBondCount",n.ringBondCount),Nt(r,"substitutionCount",n.substitutionCount),Nt(r,"unsaturatedAtom",Number(Boolean(n.unsaturatedAtom))),Nt(r,"hCount",n.hCount),Nt(r,"aam",n.mapping),Nt(r,"invRet",n.invRet),Nt(r,"exactChangeFlag",Number(Boolean(n.exactChangeFlag))),new W(r)))})),t.bonds&&t.bonds.forEach((function(t){return e.bonds.add((Nt(r={},"type",(n=t).type),Nt(r,"topology",n.topology),Nt(r,"reactingCenterStatus",n.center),Nt(r,"stereo",n.stereo),Nt(r,"begin",n.atoms[0]),Nt(r,"end",n.atoms[1]),new q(r)));var n,r})),t.sgroups&&t.sgroups.forEach((function(t){return e.sgroups.add(function(t){var e=new st(t.type);switch(Nt(e,"atoms",t.atoms),t.type){case"GEN":break;case"MUL":Nt(e.data,"mul",t.mul);break;case"SRU":Nt(e.data,"subscript",t.subscript),Nt(e.data,"connectivity",t.connectivity.toLowerCase());break;case"SUP":Nt(e.data,"name",t.name),Nt(e.data,"expanded",t.expanded),Nt(e,"id",t.id);break;case"DAT":Nt(e.data,"absolute",t.placement),Nt(e.data,"attached",t.display),Nt(e.data,"context",t.context),Nt(e.data,"fieldName",t.fieldName),Nt(e.data,"fieldValue",t.fieldData)}return e}(t))})),e.initHalfBonds(),e.initNeighbors(),e.markFragments(),e.bindSGroupsToFunctionalGroups(),e}function Ht(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function zt(t){var e,n=[],r=new Set,i=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Ht(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ht(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}(t.rgroups.entries());try{for(i.s();!(e=i.n()).done;){var a=(0,m.Z)(e.value,2),o=a[0],s=a[1];s.frags.forEach((function(t){return r.add(t)}));var u=Array.from(s.frags.values()).reduce((function(e,n){return e.union(t.getFragmentIds(n))}),new H);n.push({type:"rgroup",fragment:t.clone(u),center:Ut(t,u),data:{rgnumber:o,rgroup:s}})}}catch(t){i.e(t)}finally{i.f()}var l=Array.from(t.frags.keys()).filter((function(t){return!r.has(t)}));return function(t,e,n){var r=function(t,e,n){var r=new Map;return e.forEach((function(e){var i=n.getFragmentIds(e),a=!1;i.forEach((function(t){var i;null===(i=n.atoms.get(t))||void 0===i||i.sgs.forEach((function(t){a=!0;var n=r.get(t);n?n.add(e):r.set(t,new H([e]))}))})),a||t.push({type:"molecule",fragment:n.clone(i),center:Ut(n,i)})})),r}(t,e,n);H.unionIntersections(Array.from(r.values())).forEach((function(e){var r=new H;e.forEach((function(t){r=r.union(n.getFragmentIds(t))})),t.push({type:"molecule",fragment:n.clone(r),center:Ut(n,r)})}))}(n,l,t),t.rxnArrows.forEach((function(t){n.push({type:"arrow",center:t.pos[0],data:{mode:t.mode,pos:t.pos,height:t.height}})})),t.rxnPluses.forEach((function(t){n.push({type:"plus",center:t.pp,data:{}})})),t.simpleObjects.forEach((function(t){n.push({type:"simpleObject",center:t.pos[0],data:{mode:t.mode,pos:t.pos}})})),t.texts.forEach((function(t){n.push({type:"text",center:t.position,data:{content:t.content,position:t.position,pos:t.pos}})})),n.forEach((function(t){if(t.fragment){var e=Array.from(t.fragment.sgroups.values()).filter((function(t){return t.atoms.every((function(t){return void 0!==t}))})),n=new St;e.forEach((function(t,e){n.set(e,t)})),t.fragment.sgroups=n}})),n}function Ut(t,e){var n=t.getCoordBoundingBox(e);return _.centre(n.min,n.max)}function Vt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Wt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Vt(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Vt(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function Yt(t,e){var n={};return Nt(n,"number",t),Nt(n,"range",e.range,""),Nt(n,"resth",e.resth,!1),Nt(n,"ifthen",e.ifthen,0),n}var qt={$schema:"http://json-schema.org/draft-07/schema#",title:"ket",description:"Ketcher format schema",type:"object",required:["root"],properties:{root:{type:"object",required:["nodes"],properties:{nodes:{type:"array",minItems:0,items:{oneOf:[{$ref:"#/definitions/simpleObject"},{$ref:"#/definitions/text"},{$ref:"#/definitions/arrow"},{$ref:"#/definitions/plus"},{type:"object",required:["$ref"],properties:{$ref:{type:"string",pattern:"^(mol\\d+|rg[1-9]\\d*)"}}}]}}}}},patternProperties:{"^rg[1-9]\\d*":{$ref:"#/definitions/rgroup"},"^mol\\d+":{$ref:"#/definitions/molecule"},"^header$":{$ref:"#/definitions/header"}},additionalProperties:!1,definitions:{header:{type:"object",properties:{moleculeName:{type:"string"}}},rsite:{type:"object",required:["type","location"],properties:{type:{const:"rg-label"},location:{type:"array",minItems:2,maxItems:3,items:{type:"number"}},$refs:{type:"array",items:{type:"string",pattern:"^rg-[1-9]\\d*"}},attachmentPoints:{type:"integer",enum:[0,1,2,3]}}},atom:{type:"object",required:["label"],properties:{label:{type:"string"},location:{type:"array",minItems:2,maxItems:3,items:{type:"number"}},charge:{type:"integer",minimum:-1e3,maximum:1e3},explicitValence:{type:"integer",enum:[-1,0,1,2,3,4,5,6,7,8,9,10,11,12]},isotope:{type:"integer",minimum:0,maximum:1e3},radical:{type:"integer",enum:[0,2,1,3]},attachmentPoints:{type:"integer",enum:[0,1,2,3]},stereoLabel:{type:"string",pattern:"(?:(?:^&|or)[0-9]+$)|(?:^abs$)"},stereoParity:{type:"integer",enum:[0,1,2,3]},ringBondCount:{type:"integer",enum:[0,-2,-1,2,3,4]},substitutionCount:{type:"integer",enum:[0,-2,-1,1,2,3,4,5,6]},unsaturatedAtom:{type:"boolean"},hCount:{type:"integer",enum:[-1,0,1,2,3,4,5]},mapping:{type:"integer",minimum:0},invRet:{type:"integer",enum:[0,1,2]},exactChangeFlag:{type:"boolean"}},additionalProperties:!1},atomlist:{type:"object",required:["type","location"],properties:{type:{enum:["atom-list"]},notList:{type:"boolean"},location:{type:"array",minItems:2,maxItems:3,items:{type:"number"}},elements:{type:"array",minItems:1,items:{type:"string",minLength:1}},attachmentPoints:{type:"integer",enum:[0,1,2,3]}}},bond:{type:"object",required:["atoms","type"],properties:{type:{type:"integer",enum:[1,2,3,4,5,6,7,8,9,10,11,12]},atoms:{type:"array",minItems:2,maxItems:2,uniqueItems:!0,items:{type:"integer",minimum:0}},stereo:{type:"integer",enum:[0,1,3,4,6]},topology:{type:"integer",enum:[0,1,2]},center:{type:"integer",enum:[0,-1,1,2,4,8,12]},stereobox:{type:"integer",enum:[0,1]}}},rgroup:{type:"object",required:["rlogic","type"],properties:{type:{const:"rgroup"},rlogic:{type:"object",required:["number"],properties:{number:{type:"integer",minimum:1},range:{type:"string",maxLength:50,default:""},resth:{type:"boolean",default:!1},ifthen:{type:"integer",minimum:0,default:0}}}},allOf:[{$ref:"#/definitions/structure"}]},molecule:{type:"object",required:["type"],properties:{type:{const:"molecule"}},allOf:[{$ref:"#/definitions/structure"}]},structure:{type:"object",required:["atoms"],properties:{stereoFlagPosition:{type:"object",required:["x","y"],properties:{x:{type:"number"},y:{type:"number"}}},atoms:{type:"array",items:{oneOf:[{$ref:"#/definitions/atom"},{$ref:"#/definitions/rsite"},{$ref:"#/definitions/atomlist"}]}},bonds:{type:"array",items:{$ref:"#/definitions/bond"}},highlight:{$ref:"#/definitions/subset"},selection:{$ref:"#/definitions/subset"},sgroups:{$ref:"#/definitions/sgroups"}}},subset:{type:"array",minItems:1,maxItems:2,items:{oneOf:[{type:"object",required:["entityType","items"],properties:{entityType:{type:"string",const:"atoms"},items:{type:"array",uniqueItems:!0,items:{type:"integer",minimum:0}}}},{type:"object",required:["entityType","items"],properties:{entityType:{type:"string",const:"bonds"},items:{type:"array",uniqueItems:!0,items:{type:"integer",minimum:0}}}}]}},sgroups:{type:"array",items:{required:["atoms","type"],type:"object",properties:{atoms:{type:"array",items:{type:"integer",minimum:0}},type:{type:"string",enum:["GEN","MUL","SRU","SUP","DAT"]}},if:{properties:{type:{const:"DAT"}}},then:{required:["fieldName"],properties:{context:{enum:["Fragment","Multifragment","Bond","Atom","Group"]},fieldName:{type:"string"},fieldValue:{type:"string",minLength:1},display:{type:"boolean"},placement:{type:"boolean"},bonds:{type:"array",items:{type:"integer",minimum:0}}}}}},plus:{type:"object",required:["type","location"],properties:{type:{const:"plus"},location:{type:"array",minItems:2,maxItems:3,items:{type:"number"}}}},arrow:{type:"object",required:["type","data"],properties:{type:{const:"arrow"},data:{type:"object",required:["mode"],properties:{mode:{type:"string"},pos:{type:"array",items:{type:"object",required:["x","y"],properties:{x:{type:"number"},y:{type:"number"},z:{type:"number"}}}},height:{type:"number"}}}}},simpleObject:{type:"object",required:["type","data"],properties:{type:{const:"simpleObject"},data:{type:"object",required:["mode"],properties:{mode:{type:"string",enum:["line","rectangle","circle","ellipse","polyline"]}},if:{properties:{mode:{const:"polyline"}}},then:{required:["pos"],properties:{pos:{type:"array",minItems:2,items:{type:"object",required:["x","y"],properties:{x:{type:"number"},y:{type:"number"},z:{type:"number"}}}}}},else:{required:["pos"],properties:{pos:{type:"array",minItems:2,maxItems:2,items:{type:"object",required:["x","y"],properties:{x:{type:"number"},y:{type:"number"},z:{type:"number"}}}}}}}}},text:{type:"object",required:["type","data"],properties:{type:{const:"text"},data:{type:"object",required:["content"],properties:{content:{type:"string"},pos:{type:"array",items:{type:"object",properties:{x:{type:"number"},y:{type:"number"},z:{type:"number"}}}}}}}}}};function $t(t,e){switch(t.type){case"arrow":case"plus":!function(t,e){"arrow"===t.type?e.rxnArrows.add(new yt(Zt(t.data))):e.rxnPluses.add(new bt({pp:{x:t.location[0],y:-t.location[1],z:t.location[2]}}))}(t,e);break;case"simpleObject":!function(t,e){var n="circle"===t.data.mode?function(t){var e=_.dist(t.data.pos[1],t.data.pos[0]),n=t.data.pos[0];return{mode:vt.ellipse,pos:[{x:n.x-Math.abs(e),y:n.y-Math.abs(e),z:n.z-Math.abs(e)},{x:n.x+Math.abs(e),y:n.y+Math.abs(e),z:n.z+Math.abs(e)}]}}(t):t.data;e.simpleObjects.add(new Et(Zt(n)))}(t,e);break;case"molecule":var n=Ft(t);t.stereoFlagPosition&&(n.frags.get(0).stereoFlagPosition=new _(t.stereoFlagPosition)),n.mergeInto(e);break;case"rgroup":(function(t){var e,n,r=Ft(t),i=(Nt(n={},"range",(e=t.rlogic).range),Nt(n,"resth",e.resth),Nt(n,"ifthen",e.ifthen),new gt(n));return r.frags.forEach((function(t,e){i.frags.add(e)})),t.rlogic&&r.rgroups.set(t.rlogic.number,i),r})(t).mergeInto(e);break;case"text":!function(t,e){var n=Zt(t.data);e.texts.add(new Bt(n))}(t,e)}}var Xt=function(){function t(){(0,r.Z)(this,t)}return(0,i.Z)(t,[{key:"deserialize",value:function(t){var e=new Tt,n=JSON.parse(t);if(!function(t){return(new(A())).compile(qt)(t)}(n))throw new Error("Cannot deserialize input JSON.");var r=n.root.nodes;return Object.keys(r).forEach((function(t){r[t].type?$t(r[t],e):r[t].$ref&&$t(n[r[t].$ref],e)})),e.name=n.header?n.header.moleculeName:null,e}},{key:"serialize",value:function(t){var e={root:{nodes:[]}},n=function(t){var e={};return Nt(e,"moleculeName",t.name,""),Nt(e,"creatorProgram",null,""),Nt(e,"comment",null,""),0!==Object.keys(e).length?e:null}(t);n&&(e.header=n);var r=zt(t),i=0;return r.forEach((function(t){switch(t.type){case"molecule":e.root.nodes.push({$ref:"mol".concat(i)}),e["mol".concat(i++)]=jt(t.fragment);break;case"rgroup":e.root.nodes.push({$ref:"rg".concat(t.data.rgnumber)}),e["rg".concat(t.data.rgnumber)]=function(t,e){var n=Wt({rlogic:Yt(e.rgnumber,e.rgroup)},jt(t));return Wt(Wt({},n),{},{type:"rgroup"})}(t.fragment,t.data);break;case"plus":e.root.nodes.push({type:"plus",location:[(r=(n=t).center).x,-r.y,r.z],prop:n.data});break;case"arrow":e.root.nodes.push({type:"arrow",data:Zt(t.data)});break;case"simpleObject":e.root.nodes.push({type:"simpleObject",data:Zt(t.data)});break;case"text":e.root.nodes.push({type:"text",data:Zt(t.data)})}var n,r})),JSON.stringify(e,null,4)}}]),t}(),Kt={bondTypeMap:{1:q.PATTERN.TYPE.SINGLE,2:q.PATTERN.TYPE.DOUBLE,3:q.PATTERN.TYPE.TRIPLE,4:q.PATTERN.TYPE.AROMATIC,5:q.PATTERN.TYPE.SINGLE_OR_DOUBLE,6:q.PATTERN.TYPE.SINGLE_OR_AROMATIC,7:q.PATTERN.TYPE.DOUBLE_OR_AROMATIC,8:q.PATTERN.TYPE.ANY,9:q.PATTERN.TYPE.DATIVE,10:q.PATTERN.TYPE.HYDROGEN},bondStereoMap:{0:q.PATTERN.STEREO.NONE,1:q.PATTERN.STEREO.UP,4:q.PATTERN.STEREO.EITHER,6:q.PATTERN.STEREO.DOWN,3:q.PATTERN.STEREO.CIS_TRANS},v30bondStereoMap:{0:q.PATTERN.STEREO.NONE,1:q.PATTERN.STEREO.UP,2:q.PATTERN.STEREO.EITHER,3:q.PATTERN.STEREO.DOWN},bondTopologyMap:{0:q.PATTERN.TOPOLOGY.EITHER,1:q.PATTERN.TOPOLOGY.RING,2:q.PATTERN.TOPOLOGY.CHAIN},countsLinePartition:[3,3,3,3,3,3,3,3,3,3,3,6],atomLinePartition:[10,10,10,1,3,2,3,3,3,3,3,3,3,3,3,3,3],bondLinePartition:[3,3,3,3,3,3,3],atomListHeaderPartition:[3,1,1,4,1,1],atomListHeaderLength:11,atomListHeaderItemLength:4,chargeMap:[0,3,2,1,0,-1,-2,-3],valenceMap:[void 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0],implicitHydrogenMap:[void 0,0,1,2,3,4],v30atomPropMap:{CHG:"charge",RAD:"radical",MASS:"isotope",VAL:"explicitValence",HCOUNT:"hCount",INVRET:"invRet",SUBST:"substitutionCount",UNSAT:"unsaturatedAtom",RBCNT:"ringBondCount"},rxnItemsPartition:[3,3,3]},Jt={fmtInfo:Kt,paddedNum:function(t,e,n){var r=(t=parseFloat(t)).toFixed(n||0).replace(",",".");if(r.length>e)throw new Error("number does not fit");return r.padStart(e)},parseDecimalInt:function(t){var e=parseInt(t,10);return isNaN(e)?0:e},partitionLine:function(t,e,n){for(var r=[],i=0,a=0;i<e.length;++i)r.push(t.slice(a,a+e[i])),n&&a++,a+=e[i];return r},partitionLineFixed:function(t,e,n){for(var r=[],i=0;i<t.length;i+=e)r.push(t.slice(i,i+e)),n&&i++;return r},rxnMerge:function(t,e,n,r,i){var a,o=new Tt,s=[],u=[],l=[],c=[],d=[],h=[],f={cnt:0,totalLength:0};for(a=0;a<t.length;++a){var p=t[a],m=p.getBondLengthData();f.cnt+=m.cnt,f.totalLength+=m.totalLength}var g,v,y,b,w=1/(0===f.cnt?1:f.totalLength/f.cnt);for(a=0;a<t.length;++a)(p=t[a]).scale(w);for(a=0;a<t.length;++a){var x=(p=t[a]).getCoordBoundingBoxObj();if(x){var E=a<e?1:a<e+n?2:3;1===E?(s.push(x),c.push(p)):3===E?(u.push(x),d.push(p)):2===E&&(l.push(x),h.push(p)),p.atoms.forEach((function(t){t.rxnFragmentType=E}))}}function O(t,e,n,r,i){var a=new _(r-n.min.x,i?1-n.min.y:-(n.min.y+n.max.y)/2);return e.atoms.forEach((function(t){t.pp.add_(a)})),e.sgroups.forEach((function(t){t.pp&&t.pp.add_(a)})),n.min.add_(a),n.max.add_(a),e.mergeInto(t),n.max.x-n.min.x}if(i){var A=0;for(a=0;a<c.length;++a)A+=O(o,c[a],s[a],A,!1)+2;for(A+=2,a=0;a<d.length;++a)A+=O(o,d[a],u[a],A,!0)+2;for(A+=2,a=0;a<h.length;++a)A+=O(o,h[a],l[a],A,!1)+2}else{for(a=0;a<c.length;++a)c[a].mergeInto(o);for(a=0;a<d.length;++a)d[a].mergeInto(o);for(a=0;a<h.length;++a)h[a].mergeInto(o)}var S=null,R=null;for(a=0;a<s.length-1;++a)g=s[a],v=s[a+1],y=(g.max.x+v.min.x)/2,b=(g.max.y+g.min.y+v.max.y+v.min.y)/4,o.rxnPluses.add(new bt({pp:new _(y,b)}));for(a=0;a<s.length;++a)0===a?((S={}).max=new _(s[a].max),S.min=new _(s[a].min)):(S.max=_.max(S.max,s[a].max),S.min=_.min(S.min,s[a].min));for(a=0;a<l.length-1;++a)g=l[a],v=l[a+1],y=(g.max.x+v.min.x)/2,b=(g.max.y+g.min.y+v.max.y+v.min.y)/4,o.rxnPluses.add(new bt({pp:new _(y,b)}));for(a=0;a<l.length;++a)0===a?((R={}).max=new _(l[a].max),R.min=new _(l[a].min)):(R.max=_.max(R.max,l[a].max),R.min=_.min(R.min,l[a].min));if(v=R,(g=S)||v){var P=g?new _(g.max.x,(g.max.y+g.min.y)/2):null,T=v?new _(v.min.x,(v.max.y+v.min.y)/2):null;P||(P=new _(T.x-3,T.y)),T||(T=new _(P.x+3,P.y));var k=_.lc2(P,.5,T,.5),B=new _(k.x-1,k.y,k.z),C=new _(k.x+1,k.y,k.z);o.rxnArrows.add(new yt({mode:"open-angle",pos:[B,C]}))}else o.rxnArrows.add(new yt({mode:"open-angle",pos:[new _(0,0),new _(2,0)]}));return o.isReaction=!0,o},rgMerge:function(t,e){var n=new Tt;return t.mergeInto(n,null,null,!1,!0),Object.keys(e).forEach((function(t){for(var r=parseInt(t,10),i=function(t){var i=e[r][t];i.rgroups.set(r,new gt);var a=new Q,o=i.frags.add(a);i.rgroups.get(r).frags.add(o),i.atoms.forEach((function(t){t.fragment=o})),i.mergeInto(n)},a=0;a<e[r].length;++a)i(a)})),n}};function Qt(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return te(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?te(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function te(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function ee(t,e){for(var n=new St,r=Jt.partitionLineFixed(t,3,!0),i=Jt.parseDecimalInt(r[0]),a=0;a<i;++a){var o=Jt.parseDecimalInt(r[2*a+1])-1,s=e?r[2*a+2].trim():Jt.parseDecimalInt(r[2*a+2]);n.set(o,s)}return n}function ne(t,e,n){t.data.mul=t.data.subscript-0;var r={};t.atoms=st.filterAtoms(t.atoms,n),t.patoms=st.filterAtoms(t.patoms,n);for(var i=1;i<t.data.mul;++i)for(var a=0;a<t.patoms.length;++a){var o=t.atoms[i*t.patoms.length+a];if(!(o<0)){if(t.patoms[a]<0)throw new Error("parent atom missing");r[o]=t.patoms[a]}}t.patoms=st.removeNegative(t.patoms);var s=function(t){for(var e={},n=0;n<t.length;++n)e[t[n]]=t[n];return e}(t.patoms),u=[];e.bonds.forEach((function(t,e){var n=t.begin in r,i=t.end in r;n&&i||n&&t.end in s||i&&t.begin in s?u.push(e):n?t.begin=r[t.begin]:i&&(t.end=r[t.end])}),t);for(var l=0;l<u.length;++l)e.bonds.delete(u[l]);for(var c in r)e.atoms.delete(+c),n[c]=-1;t.atoms=t.patoms,t.patoms=null}function re(t){t.data.connectivity=(t.data.connectivity||"EU").trim().toLowerCase()}function ie(t){t.data.name=(t.data.subscript||"").trim(),t.data.subscript=""}function ae(t,e,n){}function oe(t,e){t.data.absolute||(t.pp=t.pp.add(st.getMassCentre(e,t.atoms)))}function se(t){}function ue(t){}function le(t){}function ce(t){}function de(t){}function he(t){}function fe(t){}function pe(t){}function me(t){}function ge(t){}function ve(t,e){var n=Jt.partitionLine(e,[10,10,4,1,1,1,3,3,3,3,2,3,2],!1),r=parseFloat(n[0]),i=parseFloat(n[1]),a="A"===n[3].trim(),o="A"===n[4].trim(),s="U"===n[5].trim(),u=n[7].trim();u="ALL"===u?-1:Jt.parseDecimalInt(u);var l=n[10].trim(),c=Jt.parseDecimalInt(n[11].trim());t.pp=new _(r,-i),t.data.attached=a,t.data.absolute=o,t.data.showUnits=s,t.data.nCharsToDisplay=u,t.data.tagChar=l,t.data.daspPos=c}function ye(t,e,n){t.data.fieldValue=(t.data.fieldValue||"")+e,n&&(t.data.fieldValue=t.data.fieldValue.replace(/\s+$/,""),t.data.fieldValue.startsWith('"')&&t.data.fieldValue.endsWith('"')&&(t.data.fieldValue=t.data.fieldValue.substr(1,t.data.fieldValue.length-2)))}var be={readKeyValuePairs:ee,readKeyMultiValuePairs:function(t,e){for(var n=[],r=Jt.partitionLineFixed(t,3,!0),i=Jt.parseDecimalInt(r[0]),a=0;a<i;++a)n.push([Jt.parseDecimalInt(r[2*a+1])-1,e?r[2*a+2].trim():Jt.parseDecimalInt(r[2*a+2])]);return n},loadSGroup:function(t,e,n){var r={SUP:ie,MUL:ne,SRU:re,MON:se,MER:ue,COP:le,CRO:ce,MOD:de,GRA:he,COM:fe,MIX:pe,FOR:me,DAT:oe,ANY:ge,GEN:ae};e.id=t.sgroups.add(e),r[e.type](e,t,n);for(var i=0;i<e.atoms.length;++i)t.atoms.has(e.atoms[i])&&t.atoms.get(e.atoms[i]).sgs.add(e.id);return"DAT"===e.type?t.sGroupForest.insert(e,-1,[]):t.sGroupForest.insert(e),e.id},initSGroup:function(t,e){var n,r=Qt(ee(e,!0));try{for(r.s();!(n=r.n()).done;){var i=(0,m.Z)(n.value,2),a=i[0],o=i[1],s=new st(o);s.number=a,t[a]=s}}catch(t){r.e(t)}finally{r.f()}},applySGroupProp:function(t,e,n,r,i){var a,o=ee(n,!r),s=Qt(o.keys());try{for(s.s();!(a=s.n()).done;){var u=a.value;(i?t[u]:t[u].data)[e]=o.get(u)}}catch(t){s.e(t)}finally{s.f()}},applySGroupArrayProp:function(t,e,n,r){var i=Jt.parseDecimalInt(n.slice(1,4))-1,a=Jt.parseDecimalInt(n.slice(4,8)),o=function(t){for(var e=[],n=0;n<t.length;++n)e[n]=Jt.parseDecimalInt(t[n]);return e}(Jt.partitionLineFixed(n.slice(8),3,!0));if(o.length!==a)throw new Error("File format invalid");r&&(o=o.map((function(t){return t+r}))),t[i][e]=t[i][e].concat(o)},applyDataSGroupName:function(t,e){t.data.fieldName=e},applyDataSGroupQuery:function(t,e){t.data.query=e},applyDataSGroupQueryOp:function(t,e){t.data.queryOp=e},applyDataSGroupDesc:function(t,e){var n=Jt.partitionLine(e,[4,31,2,20,2,3],!1),r=Jt.parseDecimalInt(n[0])-1,i=n[1].trim(),a=n[2].trim(),o=n[3].trim(),s=n[4].trim(),u=n[5].trim(),l=t[r];l.data.fieldType=a,l.data.fieldName=i,l.data.units=o,l.data.query=s,l.data.queryOp=u},applyDataSGroupInfo:ve,applyDataSGroupData:ye,applyDataSGroupInfoLine:function(t,e){ve(t[Jt.parseDecimalInt(e.substr(0,4))-1],e.substr(5))},applyDataSGroupDataLine:function(t,e,n){var r=Jt.parseDecimalInt(e.substr(0,5))-1,i=e.substr(5);ye(t[r],i,n)},applyDataSGroupExpand:function(t,e){t.data.expanded=e}};function we(t){var e=Jt.partitionLine(t,Jt.fmtInfo.atomLinePartition),n={pp:new _(parseFloat(e[0]),-parseFloat(e[1]),parseFloat(e[2])),label:e[4].trim(),explicitValence:Jt.fmtInfo.valenceMap[Jt.parseDecimalInt(e[10])],massDifference:Jt.parseDecimalInt(e[5]),charge:Jt.fmtInfo.chargeMap[Jt.parseDecimalInt(e[6])],hCount:Jt.parseDecimalInt(Jt.parseDecimalInt(e[8])),stereoCare:0!==Jt.parseDecimalInt(e[9]),aam:Jt.parseDecimalInt(e[14]),invRet:Jt.parseDecimalInt(e[15]),exactChangeFlag:Jt.parseDecimalInt(e[16])};return new W(n)}function xe(t){var e=Jt.partitionLine(t,Jt.fmtInfo.bondLinePartition),n={begin:Jt.parseDecimalInt(e[0])-1,end:Jt.parseDecimalInt(e[1])-1,type:Jt.fmtInfo.bondTypeMap[Jt.parseDecimalInt(e[2])],stereo:Jt.fmtInfo.bondStereoMap[Jt.parseDecimalInt(e[3])],xxx:e[4],topology:Jt.fmtInfo.bondTopologyMap[Jt.parseDecimalInt(e[5])],reactingCenterStatus:Jt.parseDecimalInt(e[6])};return new q(n)}function Ee(t){for(var e=Jt.partitionLine(t,Jt.fmtInfo.atomListHeaderPartition),n=Jt.parseDecimalInt(e[0])-1,r="T"===e[2].trim(),i=Jt.parseDecimalInt(e[4].trim()),a=t.slice(Jt.fmtInfo.atomListHeaderLength),o=[],s=Jt.fmtInfo.atomListHeaderItemLength,u=0;u<i;++u)o[u]=Jt.parseDecimalInt(a.slice(u*s,(u+1)*s-1));return{aid:n,atomList:new D({notList:r,ids:o})}}function Oe(t,e){var n,r=new Tt,i=Jt.parseDecimalInt(e[0]),a=Jt.parseDecimalInt(e[1]),o=Jt.parseDecimalInt(e[2]),s=1===Jt.parseDecimalInt(e[4]),u=0===Jt.parseDecimalInt(e[4]),l=Jt.parseDecimalInt(e[5]),c=Jt.parseDecimalInt(e[10]),d=0,h=t.slice(d,d+i);d+=i;var f=t.slice(d,d+a);d+=a;var p=t.slice(d,d+o);d+=o+l,h.map(we).forEach((function(t){return r.atoms.add(t)})),f.map(xe).forEach((function(t){t.stereo&&s&&(r.atoms.get(t.begin).stereoLabel=F.Abs),t.stereo&&u&&(r.atoms.get(t.begin).stereoLabel="".concat(F.And,"1")),r.bonds.add(t)})),p.map(Ee).forEach((function(t){r.atoms.get(t.aid).atomList=t.atomList,r.atoms.get(t.aid).label="L#"}));var m={},g={},v=function(t,e,n,r,i,a){for(var o=new St;n<r;){var s=e[n];if("A"===s.charAt(0)){var u=e[++n],l=/'.+'/.test(u);l&&!o.get("pseudo")&&o.set("pseudo",new St),l||o.get("alias")||o.set("alias",new St),o.get(l?"pseudo":"alias").set(Jt.parseDecimalInt(s.slice(3))-1,u)}else if("M"===s.charAt(0)){var c=s.slice(3,6),d=s.slice(6);if("END"===c)break;if("CHG"===c)o.get("charge")||o.set("charge",be.readKeyValuePairs(d));else if("RAD"===c)o.get("radical")||o.set("radical",be.readKeyValuePairs(d));else if("ISO"===c)o.get("isotope")||o.set("isotope",be.readKeyValuePairs(d));else if("RBC"===c)o.get("ringBondCount")||o.set("ringBondCount",be.readKeyValuePairs(d));else if("SUB"===c)o.get("substitutionCount")||o.set("substitutionCount",be.readKeyValuePairs(d));else if("UNS"===c)o.get("unsaturatedAtom")||o.set("unsaturatedAtom",be.readKeyValuePairs(d));else if("RGP"===c){o.get("rglabel")||o.set("rglabel",new St);for(var h=o.get("rglabel"),f=be.readKeyMultiValuePairs(d),p=0;p<f.length;p++){var m=f[p];h.set(m[0],(h.get(m[0])||0)|1<<m[1]-1)}}else if("LOG"===c){d=d.slice(4);var g=Jt.parseDecimalInt(d.slice(0,3).trim()),v=Jt.parseDecimalInt(d.slice(4,7).trim()),y=Jt.parseDecimalInt(d.slice(8,11).trim()),b=d.slice(12).trim(),w={};v>0&&(w.ifthen=v),w.resth=1===y,w.range=b,a[g]=w}else if("APO"===c)o.get("attpnt")||o.set("attpnt",be.readKeyValuePairs(d));else if("ALS"===c){var x=(O=Jt.partitionLine(d,[1,3,3,1,1,1]),A=Jt.partitionLineFixed(d.slice(10),4,!1),S=void 0,R=void 0,P=void 0,T=void 0,k=void 0,S=Jt.parseDecimalInt(O[1])-1,R=Jt.parseDecimalInt(O[2]),P="T"===O[4].trim(),T=function(t){for(var e=[],n=0;n<t.length;++n){var r=N.get(t[n].trim());r&&e.push(r.number)}return e}(A.slice(0,R)),(k=new St).set(S,new D({notList:P,ids:T})),k);o.get("atomList")||o.set("atomList",new St),o.get("label")||o.set("label",new St),x.forEach((function(t,e){o.get("label").set(e,"L#"),o.get("atomList").set(e,t)}))}else if("STY"===c)be.initSGroup(i,d);else if("SST"===c)be.applySGroupProp(i,"subtype",d);else if("SLB"===c)be.applySGroupProp(i,"label",d,!0);else if("SPL"===c)be.applySGroupProp(i,"parent",d,!0,!0);else if("SCN"===c)be.applySGroupProp(i,"connectivity",d);else if("SAL"===c)be.applySGroupArrayProp(i,"atoms",d,-1);else if("SBL"===c)be.applySGroupArrayProp(i,"bonds",d,-1);else if("SPA"===c)be.applySGroupArrayProp(i,"patoms",d,-1);else if("SMT"===c){var E=Jt.parseDecimalInt(d.slice(0,4))-1;i[E].data.subscript=d.slice(4).trim()}else"SDT"===c?be.applyDataSGroupDesc(i,d):"SDD"===c?be.applyDataSGroupInfoLine(i,d):"SCD"===c?be.applyDataSGroupDataLine(i,d,!1):"SED"===c?be.applyDataSGroupDataLine(i,d,!0):"SDS"===c&&d.slice(7).trim().split(" ").forEach((function(t){var e=Number(t)-1;i[e].data.expanded=!0}))}++n}var O,A,S,R,P,T,k;return o}(0,t,d,Math.min(t.length,d+c),m,g);v.forEach((function(t,e){!function(t,e,n){e.forEach((function(e,r){t.get(r)[n]=e}))}(r.atoms,t,e)}));var y,b={};for(y in m){var w=m[y];if("DAT"===w.type&&0===w.atoms.length){var x=m[y].parent;if(x>=0){var E=m[x-1];"GEN"===E.type&&(w.atoms=[].slice.call(E.atoms))}}}for(y in m)be.loadSGroup(r,m[y],b);var O=[];for(y in m)st.filter(r,m[y],b),0!==m[y].atoms.length||m[y].allAtoms||O.push(+y);for(n=0;n<O.length;++n)r.sGroupForest.remove(O[n]),r.sgroups.delete(O[n]);for(var A in g){var S=parseInt(A,10);r.rgroups.set(S,new gt(g[S]))}return r}function Ae(t){if("$CTAB"!==(t=t.slice(7))[0].trim())throw new Error("RGFile format invalid");for(var e=1;"$"!==t[e].charAt(0);)e++;if("$END CTAB"!==t[e].trim())throw new Error("RGFile format invalid");var n=t.slice(1,e);t=t.slice(e+1);for(var r={};;){if(0===t.length)throw new Error("Unexpected end of file");var i=t[0].trim();if("$END MOL"===i){t=t.slice(1);break}if("$RGP"!==i)throw new Error("RGFile format invalid");var a=parseInt(t[1].trim(),10);for(r[a]=[],t=t.slice(2);;){if(0===t.length)throw new Error("Unexpected end of file");if("$END RGP"===(i=t[0].trim())){t=t.slice(1);break}if("$CTAB"!==i)throw new Error("RGFile format invalid");for(e=1;"$"!==t[e].charAt(0);)e++;if("$END CTAB"!==t[e].trim())throw new Error("RGFile format invalid");r[a].push(t.slice(1,e)),t=t.slice(e+1)}}var o=Se(n),s={};for(var u in r){var l=parseInt(u,10);s[l]=[];for(var c=0;c<r[l].length;++c)s[l].push(Se(r[l][c]))}return Jt.rgMerge(o,s)}function Se(t){var e=Jt.partitionLine(t[0],Jt.fmtInfo.countsLinePartition);return Oe(t=t.slice(1),e)}var Re={parseCTabV2000:Oe,parseRg2000:Ae,parseRxn2000:function(t,e){t=t.slice(4);var n=Jt.partitionLine(t[0],Jt.fmtInfo.rxnItemsPartition),r=n[0]-0,i=n[1]-0,a=n[2]-0;t=t.slice(1);for(var o=[];t.length>0&&"$MOL"===t[0].substr(0,4);){t=t.slice(1);for(var s=0;s<t.length&&"$MOL"!==t[s].substr(0,4);)s++;var u,l=t.slice(0,s);0===l[0].search("\\$MDL")?u=Ae(l):(u=Se(l.slice(3))).name=l[0].trim(),o.push(u),t=t.slice(s)}return Jt.rxnMerge(o,r,i,a,e)}};function Pe(t){var e,n,r,i,a=Ze(t),o={pp:new _(parseFloat(a[2]),-parseFloat(a[3]),parseFloat(a[4])),aam:a[5].trim()},s=a[1].trim();if('"'===s.charAt(0)&&'"'===s.charAt(s.length-1)&&(s=s.substr(1,s.length-2)),"]"===s.charAt(s.length-1)){var u={notList:!1},l=(s=s.substr(0,s.length-1)).match(/NOT ?\[/);if(l){u.notList=!0;var c=(0,m.Z)(l,1)[0];s=s.substr(c.length)}else{if("["!==s.charAt(0))throw new Error("Error: atom list expected, found '"+s+"'");s=s.substr(1)}u.ids=function(t){for(var e=[],n=0;n<t.length;++n){var r=N.get(t[n].trim());r&&e.push(r.number)}return e}(s.split(",")),o.atomList=new D(u),o.label="L#"}else o.label=s;for(a.splice(0,6),i=0;i<a.length;++i)if(n=(e=Ne(a[i],"="))[0],r=e[1],n in Jt.fmtInfo.v30atomPropMap){var d=Jt.parseDecimalInt(r);if("VAL"===n){if(0===d)continue;-1===d&&(d=0)}o[Jt.fmtInfo.v30atomPropMap[n]]=d}else if("RGROUPS"===n){var h=(r=r.trim().substr(1,r.length-2)).split(" ").slice(1);o.rglabel=0;for(var f=0;f<h.length;++f)o.rglabel|=1<<h[f]-1}else"ATTCHPT"===n&&(o.attpnt=r.trim()-0);return new W(o)}function Te(t){var e,n,r,i,a=Ze(t),o={begin:Jt.parseDecimalInt(a[2])-1,end:Jt.parseDecimalInt(a[3])-1,type:Jt.fmtInfo.bondTypeMap[Jt.parseDecimalInt(a[1])]};for(a.splice(0,4),i=0;i<a.length;++i)n=(e=Ne(a[i],"="))[0],r=e[1],"CFG"===n?(o.stereo=Jt.fmtInfo.v30bondStereoMap[Jt.parseDecimalInt(r)],o.type===q.PATTERN.TYPE.DOUBLE&&o.stereo===q.PATTERN.STEREO.EITHER&&(o.stereo=q.PATTERN.STEREO.CIS_TRANS)):"TOPO"===n?o.topology=Jt.fmtInfo.bondTopologyMap[Jt.parseDecimalInt(r)]:"RXCTR"===n?o.reactingCenterStatus=Jt.parseDecimalInt(r):"STBOX"===n&&(o.stereoCare=Jt.parseDecimalInt(r));return new q(o)}function ke(t,e,n){for(n++;"M V30 END COLLECTION"!==e[n].trim();)n++;return++n}function Be(t,e,n,r,i){var a,o="";for(i++;i<e.length;){if("END SGROUP"===(o=De(e[i++]).trim()).trim())return i;for(;"-"===o.charAt(o.length-1);)o=(o.substr(0,o.length-1)+De(e[i++])).trim();var s=Ie(o),u=s[1],l=new st(u);l.number=s[0]-0,l.type=u,l.label=s[2]-0,n[l.number]=l;for(var c={},d=3;d<s.length;++d){var h=Ne(s[d],"=");if(2!==h.length)throw new Error("A record of form AAA=BBB or AAA=(...) expected, got '"+s[d]+"'");var f=h[0];f in c||(c[f]=[]),c[f].push(h[1])}l.atoms=Le(c.ATOMS[0],-1),c.PATOMS&&(l.patoms=Le(c.PATOMS[0],-1)),l.bonds=c.BONDS?Le(c.BONDS[0],-1):[];var p=c.BRKXYZ;if(l.brkxyz=[],p)for(var m=0;m<p.length;++m)l.brkxyz.push(Le(p[m]));c.MULT&&(l.data.subscript=c.MULT[0]-0),c.LABEL&&(l.data.subscript=c.LABEL[0].trim()),c.CONNECT&&(l.data.connectivity=c.CONNECT[0].toLowerCase()),c.FIELDDISP&&be.applyDataSGroupInfo(l,'"'===(a=c.FIELDDISP[0])[0]&&'"'===a[a.length-1]?a.substr(1,a.length-2):a),c.FIELDDATA&&be.applyDataSGroupData(l,c.FIELDDATA[0],!0),c.FIELDNAME&&be.applyDataSGroupName(l,c.FIELDNAME[0]),c.QUERYTYPE&&be.applyDataSGroupQuery(l,c.QUERYTYPE[0]),c.QUERYOP&&be.applyDataSGroupQueryOp(l,c.QUERYOP[0]),be.loadSGroup(t,l,r),c.ESTATE&&be.applyDataSGroupExpand(l,c.ESTATE[0])}throw new Error("S-group declaration incomplete.")}function Ce(t,e){var n=new Tt,r=0;if("M V30 BEGIN CTAB"!==t[r++].trim())throw Error("CTAB V3000 invalid");if("M V30 COUNTS"!==t[r].slice(0,13))throw Error("CTAB V3000 invalid");var i=t[r].slice(14).split(" "),a=1===Jt.parseDecimalInt(i[4]);if("M V30 BEGIN ATOM"===t[++r].trim()){var o;for(r++;r<t.length&&"END ATOM"!==(o=De(t[r++]).trim());){for(;"-"===o.charAt(o.length-1);)o=(o.substring(0,o.length-1)+De(t[r++])).trim();n.atoms.add(Pe(o))}if("M V30 BEGIN BOND"===t[r].trim())for(r++;r<t.length&&"END BOND"!==(o=De(t[r++]).trim());){for(;"-"===o.charAt(o.length-1);)o=(o.substring(0,o.length-1)+De(t[r++])).trim();var s=Te(o);s.stereo&&a&&(n.atoms.get(s.begin).stereoLabel="abs"),n.bonds.add(s)}for(var u={},l={};"M V30 END CTAB"!==t[r].trim();)if("M V30 BEGIN COLLECTION"===t[r].trim())r=ke(0,t,r);else{if("M V30 BEGIN SGROUP"!==t[r].trim())throw Error("CTAB V3000 invalid");r=Be(n,t,u,l,r)}}if("M V30 END CTAB"!==t[r++].trim())throw Error("CTAB V3000 invalid");return e||Me(n,t.slice(r)),n}function Me(t,e){for(var n={},r={},i=0;i<e.length&&0===e[i].search("M V30 BEGIN RGROUP");){var a=e[i++].split(" ").pop();for(n[a]=[],r[a]={};;){var o=e[i].trim();if(0!==o.search("M V30 RLOGIC")){if("M V30 BEGIN CTAB"!==o)throw Error("CTAB V3000 invalid");for(var s=0;s<e.length&&"M V30 END CTAB"!==e[i+s].trim();++s);var u=Ce(e.slice(i,i+s+1),!0);if(n[a].push(u),"M V30 END RGROUP"===e[i=i+s+1].trim()){i++;break}}else{var l=(o=o.slice(13)).trim().split(/\s+/g),c=Jt.parseDecimalInt(l[0]),d=Jt.parseDecimalInt(l[1]),h=l.slice(2).join(" "),f={};c>0&&(f.ifthen=c),f.resth=1===d,f.range=h,r[a]=f,i++}}}Object.keys(n).forEach((function(e){n[e].forEach((function(n){n.rgroups.set(e,new gt(r[e]));var i=n.frags.add({});n.rgroups.get(e).frags.add(i),n.atoms.forEach((function(t){t.fragment=i})),n.mergeInto(t)}))}))}function Ze(t){for(var e=[],n=0,r=0,i=-1,a=!1;r<t.length;r+=1){var o=t[r];if("NOT"===t.substr(r,3)){var s=t.indexOf("]");e.push(t.slice(r,s+1)),i=r=s+1}else"("===o?n+=1:")"===o?n-=1:'"'===o?a=!a:a||" "!==t[r]||0!==n||(r>i+1&&e.push(t.slice(i+1,r)),i=r)}return r>i+1&&e.push(t.slice(i+1,r)),e}function Ne(t,e){var n=t.indexOf(e);return[t.slice(0,n),t.slice(n+1)]}function Ie(t){for(var e=[],n=0,r=!1,i=0;i<t.length;++i){var a=t.charAt(i);'"'===a?r=!r:r||("("===a?n++:")"===a?n--:" "===a&&0===n&&(e.push(t.slice(0,i)),t=t.slice(i+1).trim(),i=0))}if(0!==n)throw new Error("Brace balance broken. S-group properies invalid!");return t.length>0&&e.push(t.trim()),e}function Le(t,e){if(!t)return null;var n=[],r=(t=(t=t.trim()).substr(1,t.length-2)).split(" ");e=e||0;for(var i=1;i<r.length;++i){var a=parseInt(r[i]);isNaN(a)||n.push(a+e)}return n}function De(t){if("M V30 "!==t.slice(0,7))throw new Error("Prefix invalid");return t.slice(7)}var _e={parseCTabV3000:Ce,readRGroups3000:Me,parseRxn3000:function(t,e){var n=(t=t.slice(4))[0].split(/\s+/g).slice(3),r=n[0]-0,i=n[1]-0,a=n.length>2?n[2]-0:0;function o(e){for(var n=e;n<t.length;++n)if("M V30 END CTAB"===t[n].trim())return n}function s(e){for(var n=e;n<t.length;++n)if("M V30 END RGROUP"===t[n].trim())return n}for(var u=[],l=[],c=[],d=null,h=[],f=0;f<t.length;++f){var p,m=t[f].trim();if(m.startsWith("M V30 COUNTS"));else{if("M END"===m)break;if("M V30 BEGIN PRODUCT"===m)d=l;else if("M V30 END PRODUCT"===m)d=null;else if("M V30 BEGIN REACTANT"===m)d=u;else if("M V30 END REACTANT"===m)d=null;else if("M V30 BEGIN AGENT"===m)d=c;else if("M V30 END AGENT"===m)d=null;else if(m.startsWith("M V30 BEGIN RGROUP"))p=s(f),h.push(t.slice(f,p+1)),f=p;else{if("M V30 BEGIN CTAB"!==m)throw new Error("line unrecognized: "+m);p=o(f),d.push(t.slice(f,p+1)),f=p}}}var g=[],v=u.concat(l).concat(c);for(p=0;p<v.length;++p){var y=Ce(v[p],n);g.push(y)}var b=Jt.rxnMerge(g,r,i,a,e);return Me(b,function(t){for(var e=[],n=0;n<t.length;++n)e=e.concat(t[n]);return e}(h)),b}};function je(t){var e=function(t,e,n){for(var r=[],i=0,a=0;i<e.length;++i)r.push(t.slice(a,a+e[i])),a+=e[i];return r}(t[0],Jt.fmtInfo.countsLinePartition),n=e[11].trim();if(t=t.slice(1),"V2000"===n)return Re.parseCTabV2000(t,e);if("V3000"===n)return _e.parseCTabV3000(t,!1);throw new Error("Molfile version unknown: "+n)}var Ge={MUL:st.prepareMulForSaving,SRU:function(t,e){var n=[];if(e.bonds.forEach((function(r,i){var a=e.atoms.get(r.begin),o=e.atoms.get(r.end);(a.sgs.has(t.id)&&!o.sgs.has(t.id)||o.sgs.has(t.id)&&!a.sgs.has(t.id))&&n.push(i)}),t),0!==n.length&&2!==n.length)throw{id:t.id,"error-type":"cross-bond-number",message:"Unsupported cross-bonds number"};t.bonds=n},SUP:function(t,e){var n=[];e.bonds.forEach((function(r,i){var a=e.atoms.get(r.begin),o=e.atoms.get(r.end);(a.sgs.has(t.id)&&!o.sgs.has(t.id)||o.sgs.has(t.id)&&!a.sgs.has(t.id))&&n.push(i)}),t),t.bonds=n},DAT:function(t,e){t.atoms=st.getAtoms(e,t)},GEN:function(t,e){}},Fe={MUL:function(t,e,n,r,i){var a=(n[t.id]+"").padStart(3),o=[];o=(o=(o=o.concat(He("SAL",a,Array.from(t.atomSet.values()),r))).concat(He("SPA",a,Array.from(t.parentAtomSet.values()),r))).concat(He("SBL",a,t.bonds,i));var s="M SMT "+a+" "+t.data.mul;return o.push(s),(o=o.concat(ze(e,t,a))).join("\n")},SRU:function(t,e,n,r,i){var a=(n[t.id]+"").padStart(3),o=[];return(o=(o=(o=o.concat(He("SAL",a,t.atoms,r))).concat(He("SBL",a,t.bonds,i))).concat(ze(e,t,a))).join("\n")},SUP:function(t,e,n,r,i){var a=(n[t.id]+"").padStart(3),o=[];return o=(o=o.concat(He("SAL",a,t.atoms,r))).concat(He("SBL",a,t.bonds,i)),t.data.name&&""!==t.data.name&&o.push("M SMT "+a+" "+t.data.name),o.join("\n")},DAT:function(t,e,n,r){var i=(n[t.id]+"").padStart(3),a=t.data,o=t.pp;a.absolute||(o=o.sub(st.getMassCentre(e,t.atoms)));var s=[];s=s.concat(He("SAL",i,t.atoms,r));var u="M SDT "+i+" "+(a.fieldName||"").padEnd(30)+(a.fieldType||"").padStart(2)+(a.units||"").padEnd(20)+(a.query||"").padStart(2);a.queryOp&&(u+=a.queryOp.padEnd(15)),s.push(u);var l,c="M SDD "+i+" "+Jt.paddedNum(o.x,10,4)+Jt.paddedNum(-o.y,10,4)+" "+(a.attached?"A":"D")+(a.absolute?"A":"R")+(a.showUnits?"U":" ")+" "+(a.nCharnCharsToDisplay>=0?Jt.paddedNum(a.nCharnCharsToDisplay,3):"ALL")+" 1 "+(a.tagChar||" ")+" "+Jt.paddedNum(a.daspPos,1)+" ";return s.push(c),(l=a.fieldValue,l.replace(Ue,"\n")).replace(/\n*$/,"").split("\n").forEach((function(t){for(;t.length>69;)s.push("M SCD "+i+" "+t.slice(0,69)),t=t.slice(69);s.push("M SED "+i+" "+t)})),s.join("\n")},GEN:function(t,e,n,r,i){var a=(n[t.id]+"").padStart(3),o=[];return(o=(o=(o=o.concat(He("SAL",a,t.atoms,r))).concat(He("SBL",a,t.bonds,i))).concat(ze(e,t,a))).join("\n")}};function He(t,e,n,r){if(!n)return[];for(var i=[],a=0;a<Math.floor((n.length+14)/15);++a){for(var o=Math.min(n.length-15*a,15),s="M "+t+" "+e+" "+Jt.paddedNum(o,2),u=0;u<o;++u)s+=" "+Jt.paddedNum(r[n[15*a+u]],3);i.push(s)}return i}function ze(t,e,n){var r=new H(e.atoms),i=st.getCrossBonds(t,r);st.bracketPos(e,t,i);for(var a=e.bracketBox,o=e.bracketDir,s=o.rotateSC(1,0),u=st.getBracketParameters(t,i,r,a,o,s),l=[],c=0;c<u.length;++c){for(var d=u[c],h=d.c.addScaled(d.n,-.5*d.h).yComplement(),f=d.c.addScaled(d.n,.5*d.h).yComplement(),p="M SDI "+n+Jt.paddedNum(4,3),m=[h.x,h.y,f.x,f.y],g=0;g<m.length;++g)p+=Jt.paddedNum(m[g],10,4);l.push(p)}return l}var Ue=/\r\n|[\n\r]/g,Ve={parseCTab:je,parseMol:function(t){if(0===t[0].search("\\$MDL")){var e=Re.parseRg2000(t);return e.name=t[3].trim(),e}var n=je(t.slice(3));return n.name=t[0].trim(),n},parseRxn:function(t,e){var n=t[0].trim().split(" ");if(n.length>1&&"V3000"===n[1])return _e.parseRxn3000(t,e);var r=Re.parseRxn2000(t,e);return r.name=t[1].trim(),r},prepareForSaving:Ge,saveToMolfile:Fe},We=function(){function t(){(0,r.Z)(this,t),this.molecule=null,this.molfile=null,this.reaction=!1,this.mapping={},this.bondMapping={}}return(0,i.Z)(t,[{key:"parseCTFile",value:function(t,e){var n;return(n=0===t[0].search("\\$RXN")?Ve.parseRxn(t,e):Ve.parseMol(t)).initHalfBonds(),n.initNeighbors(),n.bindSGroupsToFunctionalGroups(),n}},{key:"prepareSGroups",value:function(t,e){var n,r=this.molecule,i=[],a=0;if(null===(n=this.molecule)||void 0===n||n.sGroupForest.getSGroupsBFS().reverse().forEach((function(n){var o=r.sgroups.get(n),s=!1;try{Ve.prepareForSaving[o.type](o,r)}catch(e){if(!t||"number"!=typeof e.id)throw new Error("Error: ".concat(e.message));s=!0}(s||!e&&/^INDIGO_.+_DESC$/i.test(o.data.fieldName))&&(a+=+s,i.push(o.id))}),this),a)throw new Error("Warning: "+a+" invalid S-groups were detected. They will be omitted.");for(var o=0;o<i.length;++o)null==r||r.sGroupDelete(i[o])}},{key:"getCTab",value:function(t,e){return this.molecule=t.clone(),this.prepareSGroups(!1,!1),this.molfile="",this.writeCTab2000(e),this.molfile}},{key:"saveMolecule",value:function(e,n,r,i){var a=this;if(this.reaction=e.hasRxnArrow(),this.molfile=""+e.name,this.reaction){if(e.rgroups.size>0)throw new Error("Reactions with r-groups are not supported at the moment");var o=e.getComponents(),s=o.reactants,u=o.products,l=s.concat(u);this.molfile="$RXN\n"+e.name+"\n\n\n"+Jt.paddedNum(s.length,3)+Jt.paddedNum(u.length,3)+Jt.paddedNum(0,3)+"\n";for(var c=0;c<l.length;++c){var d=new t,h=e.clone(l[c],null,!0),f=d.saveMolecule(h,!1,!0);this.molfile+="$MOL\n"+f}return this.molfile}if(e.rgroups.size>0){if(!r){var p=(new t).getCTab(e.getScaffold(),e.rgroups);return this.molfile="$MDL REV 1\n$MOL\n$HDR\n"+e.name+"\n\n\n$END HDR\n",this.molfile+="$CTAB\n"+p+"$END CTAB\n",e.rgroups.forEach((function(n,r){a.molfile+="$RGP\n",a.writePaddedNumber(r,3),a.molfile+="\n",n.frags.forEach((function(n){var r=(new t).getCTab(e.getFragment(n));a.molfile+="$CTAB\n"+r+"$END CTAB\n"})),a.molfile+="$END RGP\n"})),this.molfile+="$END MOL\n",this.molfile}e=e.getScaffold()}return this.molecule=e.clone(),this.prepareSGroups(n,i),this.writeHeader(),this.writeCTab2000(),this.molfile}},{key:"writeHeader",value:function(){var t=new Date;this.writeCR(),this.writeWhiteSpace(2),this.write("Ketcher"),this.writeWhiteSpace(),this.writeCR((t.getMonth()+1+"").padStart(2)+(t.getDate()+"").padStart(2)+(t.getFullYear()%100+"").padStart(2)+(t.getHours()+"").padStart(2)+(t.getMinutes()+"").padStart(2)+"2D 1 1.00000 0.00000 0"),this.writeCR()}},{key:"write",value:function(t){this.molfile+=t}},{key:"writeCR",value:function(t){0===arguments.length&&(t=""),this.molfile+=t+"\n"}},{key:"writeWhiteSpace",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;0===arguments.length&&(t=1),this.write(" ".repeat(Math.max(t,0)))}},{key:"writePadded",value:function(t,e){this.write(t),this.writeWhiteSpace(e-t.length)}},{key:"writePaddedNumber",value:function(t,e){var n=(t-0).toString();this.writeWhiteSpace(e-n.length),this.write(n)}},{key:"writePaddedFloat",value:function(t,e,n){this.write(Jt.paddedNum(t,e,n))}},{key:"writeCTab2000Header",value:function(){this.writePaddedNumber(this.molecule.atoms.size,3),this.writePaddedNumber(this.molecule.bonds.size,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3);var t=Array.from(this.molecule.frags.values()).some((function(t){return!!t&&t.enhancedStereoFlag===Y.Abs}));this.writePaddedNumber(t?1:0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(999,3),this.writeCR(" V2000")}},{key:"writeCTab2000",value:function(t){var e=this;this.writeCTab2000Header(),this.mapping={};var n=1,r=[],i=[];for(this.molecule.atoms.forEach((function(t,a){var o=t.label;null!=t.atomList?(o="L",r.push(a)):t.pseudo?t.pseudo.length>3&&(o="A",i.push({id:a,value:"'".concat(t.pseudo,"'")})):t.alias?i.push({id:a,value:t.alias}):N.get(t.label)||-1!==["A","Q","X","*","R#"].indexOf(t.label)||(o="C",i.push({id:a,value:t.label})),e.writeAtom(t,o),e.mapping[a]=n++}),this),this.bondMapping={},n=1,this.molecule.bonds.forEach((function(t,r){e.bondMapping[r]=n++,e.writeBond(t)}),this);i.length>0;)this.writeAtomProps(i[0]),i.splice(0,1);var a=[],o=[],s=[],u=[],l=[],c=[],d=[],h=[],f=[];this.molecule.atoms.forEach((function(t,e){if(0!==t.charge&&a.push([e,t.charge]),0!==t.isotope&&o.push([e,t.isotope]),0!==t.radical&&s.push([e,t.radical]),null!=t.rglabel&&"R#"===t.label)for(var n=0;n<32;n++)t.rglabel&1<<n&&u.push([e,n+1]);null!=t.attpnt&&c.push([e,t.attpnt]),0!==t.ringBondCount&&d.push([e,t.ringBondCount]),0!==t.substitutionCount&&f.push([e,t.substitutionCount]),0!==t.unsaturatedAtom&&h.push([e,t.unsaturatedAtom])})),t&&t.forEach((function(t,e){if(t.resth||t.ifthen>0||t.range.length>0){var n=" 1 "+Jt.paddedNum(e,3)+" "+Jt.paddedNum(t.ifthen,3)+" "+Jt.paddedNum(t.resth?1:0,3)+" "+t.range;l.push(n)}})),this.writeAtomPropList("M CHG",a),this.writeAtomPropList("M ISO",o),this.writeAtomPropList("M RAD",s),this.writeAtomPropList("M RGP",u);for(var p=0;p<l.length;++p)this.write("M LOG"+l[p]+"\n");if(this.writeAtomPropList("M APO",c),this.writeAtomPropList("M RBC",d),this.writeAtomPropList("M SUB",f),this.writeAtomPropList("M UNS",h),r.length>0)for(var m=0;m<r.length;++m){var g=r[m],v=this.molecule.atoms.get(g).atomList;this.write("M ALS"),this.writePaddedNumber(g+1,4),this.writePaddedNumber(v.ids.length,3),this.writeWhiteSpace(),this.write(v.notList?"T":"F");for(var y=v.labelList(),b=0;b<y.length;++b)this.writeWhiteSpace(),this.writePadded(y[b],3);this.writeWhiteSpace(),this.writeCR()}var w={},x=1,E={};this.molecule.sGroupForest.getSGroupsBFS().forEach((function(t){E[x]=t,w[t]=x++}));for(var O=1;O<x;++O){var A=E[O],S=this.molecule.sgroups.get(A);this.write("M STY"),this.writePaddedNumber(1,3),this.writeWhiteSpace(1),this.writePaddedNumber(O,3),this.writeWhiteSpace(1),this.writePadded(S.type,3),this.writeCR(),this.write("M SLB"),this.writePaddedNumber(1,3),this.writeWhiteSpace(1),this.writePaddedNumber(O,3),this.writeWhiteSpace(1),this.writePaddedNumber(O,3),this.writeCR();var R=this.molecule.sGroupForest.parent.get(A);if(R>=0&&(this.write("M SPL"),this.writePaddedNumber(1,3),this.writeWhiteSpace(1),this.writePaddedNumber(O,3),this.writeWhiteSpace(1),this.writePaddedNumber(w[R],3),this.writeCR()),"SRU"===S.type&&S.data.connectivity){var P=" ".concat(O.toString().padStart(3)," ").concat((S.data.connectivity||"").padEnd(3));this.write("M SCN"),this.writePaddedNumber(1,3),this.write(P.toUpperCase()),this.writeCR()}"SRU"===S.type&&(this.write("M SMT "),this.writePaddedNumber(O,3),this.writeWhiteSpace(),this.write(S.data.subscript||"n"),this.writeCR()),this.writeCR(Ve.saveToMolfile[S.type](S,this.molecule,w,this.mapping,this.bondMapping))}var T=[];if(this.molecule.sgroups.forEach((function(t){t.data.expanded&&T.push(t.id+1)})),T.length){var k="M SDS EXP ".concat(T.length," ").concat(T.join(" "));this.writeCR(k)}this.writeCR("M END")}},{key:"writeAtom",value:function(t,e){var n;this.writePaddedFloat(t.pp.x,10,4),this.writePaddedFloat(-t.pp.y,10,4),this.writePaddedFloat(t.pp.z,10,4),this.writeWhiteSpace(),this.writePadded(e,3),this.writePaddedNumber(0,2),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),void 0===t.hCount&&(t.hCount=0),this.writePaddedNumber(t.hCount,3),void 0===t.stereoCare&&(t.stereoCare=0),this.writePaddedNumber(t.stereoCare,3),n=t.explicitValence<0?0:0===t.explicitValence?15:t.explicitValence,this.writePaddedNumber(n,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),void 0===t.aam&&(t.aam=0),this.writePaddedNumber(t.aam,3),void 0===t.invRet&&(t.invRet=0),this.writePaddedNumber(t.invRet,3),void 0===t.exactChangeFlag&&(t.exactChangeFlag=0),this.writePaddedNumber(t.exactChangeFlag,3),this.writeCR()}},{key:"writeBond",value:function(t){this.writePaddedNumber(this.mapping[t.begin],3),this.writePaddedNumber(this.mapping[t.end],3),this.writePaddedNumber(t.type,3),void 0===t.stereo&&(t.stereo=0),this.writePaddedNumber(t.stereo,3),this.writePadded(t.xxx,3),void 0===t.topology&&(t.topology=0),this.writePaddedNumber(t.topology,3),void 0===t.reactingCenterStatus&&(t.reactingCenterStatus=0),this.writePaddedNumber(t.reactingCenterStatus,3),this.writeCR()}},{key:"writeAtomProps",value:function(t){this.write("A "),this.writePaddedNumber(t.id+1,3),this.writeCR(),this.writeCR(t.value)}},{key:"writeAtomPropList",value:function(t,e){for(var n=this;e.length>0;){for(var r=[];e.length>0&&r.length<8;)r.push(e[0]),e.splice(0,1);this.write(t),this.writePaddedNumber(r.length,3),r.forEach((function(t){n.writeWhiteSpace(),n.writePaddedNumber(n.mapping[t[0]],3),n.writeWhiteSpace(),n.writePaddedNumber(t[1],3)})),this.writeCR()}}}]),t}();function Ye(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function qe(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Ye(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ye(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var $e=function(){function t(e){(0,r.Z)(this,t),this.options=qe(qe({},t.DefaultOptions),e)}return(0,i.Z)(t,[{key:"deserialize",value:function(t){var e=new We,n=null==t?void 0:t.split(/\r\n|[\n\r]/g);try{return e.parseCTFile(n,this.options.reactionRelayout)}catch(t){if(this.options.badHeaderRecover){try{return e.parseCTFile(n.slice(1),this.options.reactionRelayout)}catch(t){}try{return e.parseCTFile([""].concat(n),this.options.reactionRelayout)}catch(t){}}throw t}}},{key:"serialize",value:function(t){return(new We).saveMolecule(t,this.options.ignoreErrors,this.options.noRgroups,this.options.preserveIndigoDesc)}}]),t}();function Xe(t,e,n){this.molecule=t,this.bonds=new St,this.getNeighbors=e,this.context=n}function Ke(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function Je(t,e,n,r){var i=this;this.molecule=t,this.atom_data=e,this.components=n,this.nComponentsInReactants=-1,this.nReactants=r,this.vertices=new Array(this.molecule.atoms.size),this.molecule.atoms.forEach((function(t,e){i.vertices[e]=new Je.VertexDesc}),this),this.edges=new Array(this.molecule.bonds.size),this.molecule.bonds.forEach((function(t,e){i.edges[e]=new Je.EdgeDesc}),this),this.v_seq=[]}function Qe(t,e,n){this.molecule=t,this.atoms=new St,this.getNeighbors=e,this.context=n}function tn(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function en(){this.smiles="",this.writtenAtoms=[],this.writtenComponents=0,this.ignoreErrors=!1}function nn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function rn(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?nn(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):nn(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}(0,a.Z)($e,"DefaultOptions",{badHeaderRecover:!1,ignoreErrors:!1,noRgroups:!1,preserveIndigoDesc:!1,reactionRelayout:!1}),Xe.PARITY={NONE:0,CIS:1,TRANS:2},Xe.prototype.each=function(t){this.bonds.forEach(t)},Xe.prototype.getParity=function(t){return this.bonds.get(t).parity},Xe.prototype.getSubstituents=function(t){return this.bonds.get(t).substituents},Xe.prototype.sameside=function(t,e,n,r){var i=_.diff(t,e),a=new _(-i.y,i.x);if(!a.normalize())return 0;var o=_.diff(n,t),s=_.diff(r,e);if(!o.normalize())return 0;if(!s.normalize())return 0;var u=_.dot(o,a),l=_.dot(s,a);return Math.abs(u)<.001||Math.abs(l)<.001?0:u*l>0?1:-1},Xe.prototype.samesides=function(t,e,n,r){return this.sameside(this.molecule.atoms.get(t).pp,this.molecule.atoms.get(e).pp,this.molecule.atoms.get(n).pp,this.molecule.atoms.get(r).pp)},Xe.prototype.sortSubstituents=function(t){var e=this.molecule.atoms.get(t[0]).pureHydrogen(),n=t[1]<0||this.molecule.atoms.get(t[1]).pureHydrogen(),r=this.molecule.atoms.get(t[2]).pureHydrogen(),i=t[3]<0||this.molecule.atoms.get(t[3]).pureHydrogen();return!(e&&n||r&&i||(n?t[1]=-1:e?(t[0]=t[1],t[1]=-1):t[0]>t[1]&&Ke(t,0,1),i?t[3]=-1:r?(t[2]=t[3],t[3]=-1):t[2]>t[3]&&Ke(t,2,3),0))},Xe.prototype.isGeomStereoBond=function(t,e){var n=this.molecule.bonds.get(t);if(n.type!==q.PATTERN.TYPE.DOUBLE)return!1;var r=this.molecule.atoms.get(n.begin).label,i=this.molecule.atoms.get(n.end).label;if("C"!==r&&"N"!==r&&"Si"!==r&&"Ge"!==r)return!1;if("C"!==i&&"N"!==i&&"Si"!==i&&"Ge"!==i)return!1;var a,o,s=this.getNeighbors.call(this.context,n.begin),u=this.getNeighbors.call(this.context,n.end);if(s.length<2||s.length>3||u.length<2||u.length>3)return!1;for(e[0]=-1,e[1]=-1,e[2]=-1,e[3]=-1,a=0;a<s.length;a++)if((o=s[a]).bid!==t){if(this.molecule.bonds.get(o.bid).type!==q.PATTERN.TYPE.SINGLE)return!1;-1===e[0]?e[0]=o.aid:e[1]=o.aid}for(a=0;a<u.length;a++)if((o=u[a]).bid!==t){if(this.molecule.bonds.get(o.bid).type!==q.PATTERN.TYPE.SINGLE)return!1;-1===e[2]?e[2]=o.aid:e[3]=o.aid}return!(-1!==e[1]&&-1!==this.samesides(n.begin,n.end,e[0],e[1])||-1!==e[3]&&-1!==this.samesides(n.begin,n.end,e[2],e[3]))},Xe.prototype.build=function(t){var e=this;this.molecule.bonds.forEach((function(n,r){var i={parity:0,substituents:[]};if(e.bonds.set(r,i),(!Array.isArray(t)||!t[r])&&e.isGeomStereoBond(r,i.substituents)&&e.sortSubstituents(i.substituents)){var a=e.samesides(n.begin,n.end,i.substituents[0],i.substituents[2]);1===a?i.parity=Xe.PARITY.CIS:-1===a&&(i.parity=Xe.PARITY.TRANS)}}))},Je.VertexDesc=function(){this.dfs_state=0,this.parent_vertex=0,this.parent_edge=0,this.branches=0},Je.EdgeDesc=function(){this.opening_cycles=0,this.closing_cycle=0},Je.SeqElem=function(t,e,n){this.idx=t,this.parent_vertex=e,this.parent_edge=n},Je.prototype.walk=function(){for(var t,e,n=this,r=[],i=0,a=0;;){if(r.length<1){for(var o=-1;i<this.components.length&&-1===o;)null===(o=this.components[i].find((function(t){return 0===n.vertices[t].dfs_state&&(o=t,!0)})))&&(o=-1,i++),i===this.nReactants&&(this.nComponentsInReactants=a);if(o<-1&&this.molecule.atoms.find((function(t){return 0===n.vertices[t].dfs_state&&(o=t,!0)})),-1===o)break;this.vertices[o].parent_vertex=-1,this.vertices[o].parent_edge=-1,r.push(o),a++}var s=r.pop(),u=this.vertices[s].parent_vertex,l=new Je.SeqElem(s,u,this.vertices[s].parent_edge);this.v_seq.push(l),this.vertices[s].dfs_state=2;var c=this.atom_data[s];for(t=0;t<c.neighbours.length;t++){var d=c.neighbours[t].aid,h=c.neighbours[t].bid;if(d!==u)if(2===this.vertices[d].dfs_state){for(this.edges[h].closing_cycle=1,e=s;-1!==e&&this.vertices[e].parent_vertex!==d;)e=this.vertices[e].parent_vertex;if(-1===e)throw new Error("cycle unwind error");this.edges[this.vertices[e].parent_edge].opening_cycles++,this.vertices[s].branches++,l=new Je.SeqElem(d,s,h),this.v_seq.push(l)}else{if(1===this.vertices[d].dfs_state){if(-1===(e=r.indexOf(d)))throw new Error("internal: removing vertex from stack");r.splice(e,1);var f=this.vertices[d].parent_vertex;f>=0&&this.vertices[f].branches--}this.vertices[s].branches++,this.vertices[d].parent_vertex=s,this.vertices[d].parent_edge=h,this.vertices[d].dfs_state=1,r.push(d)}}}},Je.prototype.edgeClosingCycle=function(t){return 0!==this.edges[t].closing_cycle},Je.prototype.numBranches=function(t){return this.vertices[t].branches},Je.prototype.numOpeningCycles=function(t){return this.edges[t].opening_cycles},Je.prototype.toString=function(){var t="";return this.v_seq.forEach((function(e){t+=e.idx+" -> "})),t+="*"},Qe.prototype.each=function(t,e){this.atoms.forEach(t,e)},Qe.prototype.buildFromBonds=function(t){var e=this,n=this.molecule.atoms,r=this.molecule.bonds,i=new H;n.forEach((function(t,a){var o=e.getNeighbors.call(e.context,a);if(2!==o.length)return!1;var s=o[0],u=o[1];if([a,s.aid,u.aid].findIndex((function(t){return["C","Si"].indexOf(n.get(t).label)<0}),e)>=0)return!1;if([s.bid,u.bid].findIndex((function(t){return r.get(t).type!==q.PATTERN.TYPE.DOUBLE}),e)>=0)return!1;var l=e.getNeighbors.call(e.context,s.aid).filter((function(t){return t.aid!==a})),c=e.getNeighbors.call(e.context,u.aid).filter((function(t){return t.aid!==a}));return!(l.length<1||l.length>2||c.length<1||c.length>2||l.concat(c).findIndex((function(t){return r.get(t.bid).type!==q.PATTERN.TYPE.SINGLE}),e)>=0||l.concat(c).findIndex((function(t){return r.get(t.bid).stereo===q.PATTERN.STEREO.EITHER}),e)>=0||(i.add(s.aid).add(u.aid),0))})),i.size>0&&n.forEach((function(t,n){if(!i.has(n)){var r=e.getNeighbors.call(e.context,n),a=!1;r.find((function(t){var e=this.molecule.bonds.get(t.bid);return e.type===q.PATTERN.TYPE.SINGLE&&e.begin===n&&(e.stereo===q.PATTERN.STEREO.UP||e.stereo===q.PATTERN.STEREO.DOWN)&&(a=!0,!0)}),e),a&&e.buildOneCenter(n)}}))},Qe.allowed_stereocenters=[{elem:"C",charge:0,degree:3,n_double_bonds:0,implicit_degree:4},{elem:"C",charge:0,degree:4,n_double_bonds:0,implicit_degree:4},{elem:"Si",charge:0,degree:3,n_double_bonds:0,implicit_degree:4},{elem:"Si",charge:0,degree:4,n_double_bonds:0,implicit_degree:4},{elem:"N",charge:1,degree:3,n_double_bonds:0,implicit_degree:4},{elem:"N",charge:1,degree:4,n_double_bonds:0,implicit_degree:4},{elem:"N",charge:0,degree:3,n_double_bonds:0,implicit_degree:3},{elem:"S",charge:0,degree:4,n_double_bonds:2,implicit_degree:4},{elem:"S",charge:1,degree:3,n_double_bonds:0,implicit_degree:3},{elem:"S",charge:0,degree:3,n_double_bonds:1,implicit_degree:3},{elem:"P",charge:0,degree:3,n_double_bonds:0,implicit_degree:3},{elem:"P",charge:1,degree:4,n_double_bonds:0,implicit_degree:4},{elem:"P",charge:0,degree:4,n_double_bonds:1,implicit_degree:4}],Qe.prototype.buildOneCenter=function(t){var e=this,n=this.molecule.atoms.get(t),r=this.getNeighbors.call(this.context,t),i=r.length,a=-1,o={group:0,type:0,pyramid:[]},s=[],u=0,l=0;o.pyramid[0]=-1,o.pyramid[1]=-1,o.pyramid[2]=-1,o.pyramid[3]=-1;var c=0;if(i>4)throw new Error("stereocenter with %d bonds are not supported"+i);if(r.forEach((function(t,r){var i=e.molecule.atoms.get(t.aid),a=e.molecule.bonds.get(t.bid);if(s[r]={edge_idx:t.bid,nei_idx:t.aid,rank:t.aid,vec:_.diff(i.pp,n.pp).yComplement()},i.pureHydrogen()?(c++,s[r].rank=1e4):"H"===i.label&&(s[r].rank=5e3),!s[r].vec.normalize())throw new Error("zero bond length");if(a.type===q.PATTERN.TYPE.TRIPLE)throw new Error("non-single bonds not allowed near stereocenter");if(a.type===q.PATTERN.TYPE.AROMATIC)throw new Error("aromatic bonds not allowed near stereocenter");a.type===q.PATTERN.TYPE.DOUBLE&&l++})),Qe.allowed_stereocenters.find((function(t){return t.elem===n.label&&t.charge===n.charge&&t.degree===i&&t.n_double_bonds===l&&(a=t.implicit_degree,!0)})),-1===a)throw new Error("unknown stereocenter configuration: "+n.label+", charge "+n.charge+", "+i+" bonds ("+l+" double)");if(4===i&&c>1)throw new Error(c+" hydrogens near stereocenter");if(3===i&&4===a&&c>0)throw new Error("have hydrogen(s) besides implicit hydrogen near stereocenter");if(4===i){s[0].rank>s[1].rank&&tn(s,0,1),s[1].rank>s[2].rank&&tn(s,1,2),s[2].rank>s[3].rank&&tn(s,2,3),s[1].rank>s[2].rank&&tn(s,1,2),s[0].rank>s[1].rank&&tn(s,0,1),s[1].rank>s[2].rank&&tn(s,1,2);for(var d,h,f=-1,p=-1,m=-1,g=-1,v=0,y=0;y<4;y++){var b=this.getBondStereo(t,s[y].edge_idx);if(b===q.PATTERN.STEREO.UP||b===q.PATTERN.STEREO.DOWN){f=y,v=b;break}}if(-1===f)throw new Error("none of 4 bonds going from stereocenter is stereobond");if(-1===p&&((d=Qe.xyzzy(s[f].vec,s[(f+1)%4].vec,s[(f+2)%4].vec))+(h=Qe.xyzzy(s[f].vec,s[(f+1)%4].vec,s[(f+3)%4].vec))!==3&&d+h!==12||(p=(f+1)%4,m=(f+2)%4,g=(f+3)%4)),-1===p&&((d=Qe.xyzzy(s[f].vec,s[(f+2)%4].vec,s[(f+1)%4].vec))+(h=Qe.xyzzy(s[f].vec,s[(f+2)%4].vec,s[(f+3)%4].vec))!==3&&d+h!==12||(p=(f+2)%4,m=(f+1)%4,g=(f+3)%4)),-1===p&&((d=Qe.xyzzy(s[f].vec,s[(f+3)%4].vec,s[(f+1)%4].vec))+(h=Qe.xyzzy(s[f].vec,s[(f+3)%4].vec,s[(f+2)%4].vec))!==3&&d+h!==12||(p=(f+3)%4,m=(f+2)%4,g=(f+1)%4)),-1===p)throw new Error("internal error: can not find opposite bond");if(v===q.PATTERN.STEREO.UP&&this.getBondStereo(t,s[p].edge_idx)===q.PATTERN.STEREO.DOWN)throw new Error("stereo types of the opposite bonds mismatch");if(v===q.PATTERN.STEREO.DOWN&&this.getBondStereo(t,s[p].edge_idx)===q.PATTERN.STEREO.UP)throw new Error("stereo types of the opposite bonds mismatch");if(v===this.getBondStereo(t,s[m].edge_idx))throw new Error("stereo types of non-opposite bonds match");if(v===this.getBondStereo(t,s[g].edge_idx))throw new Error("stereo types of non-opposite bonds match");u=3===f||3===p?v:v===q.PATTERN.STEREO.UP?q.PATTERN.STEREO.DOWN:q.PATTERN.STEREO.UP;var w=Qe.sign(s[0].vec,s[1].vec,s[2].vec);u===q.PATTERN.STEREO.UP&&w>0||u===q.PATTERN.STEREO.DOWN&&w<0?(o.pyramid[0]=s[0].nei_idx,o.pyramid[1]=s[1].nei_idx,o.pyramid[2]=s[2].nei_idx):(o.pyramid[0]=s[0].nei_idx,o.pyramid[1]=s[2].nei_idx,o.pyramid[2]=s[1].nei_idx),o.pyramid[3]=s[3].nei_idx}else if(3===i){s[0].rank>s[1].rank&&tn(s,0,1),s[1].rank>s[2].rank&&tn(s,1,2),s[0].rank>s[1].rank&&tn(s,0,1);var x=this.getBondStereo(t,s[0].edge_idx),E=this.getBondStereo(t,s[1].edge_idx),O=this.getBondStereo(t,s[2].edge_idx),A=0,S=0;if(A+=x===q.PATTERN.STEREO.UP?1:0,A+=E===q.PATTERN.STEREO.UP?1:0,A+=O===q.PATTERN.STEREO.UP?1:0,S+=x===q.PATTERN.STEREO.DOWN?1:0,S+=E===q.PATTERN.STEREO.DOWN?1:0,S+=O===q.PATTERN.STEREO.DOWN?1:0,4===a){if(3===A)throw new Error("all 3 bonds up near stereoatom");if(3===S)throw new Error("all 3 bonds down near stereoatom");if(0===A&&0===S)throw new Error("no up/down bonds near stereoatom -- indefinite case");if(1===A&&1===S)throw new Error("one bond up, one bond down -- indefinite case");if(v=0,2===A)u=q.PATTERN.STEREO.DOWN;else if(2===S)u=q.PATTERN.STEREO.UP;else{for(f=-1,m=-1,g=-1,y=0;y<3;y++){var R=this.getBondStereo(t,s[y].edge_idx);if(R===q.PATTERN.STEREO.UP||R===q.PATTERN.STEREO.DOWN){f=y,v=R,m=(y+1)%3,g=(y+2)%3;break}}if(-1===f)throw new Error("internal error: can not find up or down bond");var P=Qe.xyzzy(s[m].vec,s[g].vec,s[f].vec);if(3===P||4===P)throw new Error("degenerate case for 3 bonds near stereoatom");u=1===P?v:v===q.PATTERN.STEREO.UP?q.PATTERN.STEREO.DOWN:q.PATTERN.STEREO.UP}var T=Qe.sign(s[0].vec,s[1].vec,s[2].vec);u===q.PATTERN.STEREO.UP&&T>0||u===q.PATTERN.STEREO.DOWN&&T<0?(o.pyramid[0]=s[0].nei_idx,o.pyramid[1]=s[1].nei_idx,o.pyramid[2]=s[2].nei_idx):(o.pyramid[0]=s[0].nei_idx,o.pyramid[1]=s[2].nei_idx,o.pyramid[2]=s[1].nei_idx),o.pyramid[3]=-1}else{var k;if(S>0&&A>0)throw new Error("one bond up, one bond down -- indefinite case");if(0===S&&0===A)throw new Error("no up-down bonds attached to stereocenter");k=A>0?1:-1,1!==Qe.xyzzy(s[0].vec,s[1].vec,s[2].vec)&&1!==Qe.xyzzy(s[0].vec,s[2].vec,s[1].vec)&&1!==Qe.xyzzy(s[2].vec,s[1].vec,s[0].vec)||(k=-k),Qe.sign(s[0].vec,s[1].vec,s[2].vec)===k?(o.pyramid[0]=s[0].nei_idx,o.pyramid[1]=s[2].nei_idx,o.pyramid[2]=s[1].nei_idx):(o.pyramid[0]=s[0].nei_idx,o.pyramid[1]=s[1].nei_idx,o.pyramid[2]=s[2].nei_idx),o.pyramid[3]=-1}}this.atoms.set(t,o)},Qe.prototype.getBondStereo=function(t,e){var n=this.molecule.bonds.get(e);return t!==n.begin?0:n.stereo},Qe.xyzzy=function(t,e,n){var r=.001,i=_.cross(t,e),a=_.dot(t,e),o=_.cross(t,n),s=_.dot(t,n);if(Math.abs(i)<r){if(Math.abs(o)<r)throw new Error("degenerate case -- bonds overlap");return o>0?4:8}return i*o<-r*r||s<a?2:1},Qe.sign=function(t,e,n){var r=(t.x-n.x)*(e.y-n.y)-(t.y-n.y)*(e.x-n.x);if(r>.001)return 1;if(r<-.001)return-1;throw new Error("degenerate triangle")},Qe.isPyramidMappingRigid=function(t){var e=t.slice(),n=!0;return e[0]>e[1]&&(tn(e,0,1),n=!n),e[1]>e[2]&&(tn(e,1,2),n=!n),e[2]>e[3]&&(tn(e,2,3),n=!n),e[1]>e[2]&&(tn(e,1,2),n=!n),e[0]>e[1]&&(tn(e,0,1),n=!n),e[1]>e[2]&&(tn(e,1,2),n=!n),n},en._Atom=function(t){this.neighbours=[],this.aromatic=!1,this.lowercase=!1,this.chirality=0,this.branch_cnt=0,this.paren_written=!1,this.h_count=t,this.parent=-1},en.prototype.isBondInRing=function(t){return this.inLoop[t]},en.prototype.saveMolecule=function(t,e){var n,r,i,a=this;e||(this.ignoreErrors=e),(t=t.clone(void 0,void 0,!t.hasRxnArrow(),void 0,void 0,void 0)).initHalfBonds(),t.initNeighbors(),t.sortNeighbors(),t.setImplicitHydrogen(),t.sgroups.forEach((function(e){if("MUL"===e.type)try{st.prepareMulForSaving(e,t)}catch(t){throw Error("Bad s-group ("+t.message+")")}})),this.atoms=new Array(t.atoms.size),t.atoms.forEach((function(t,e){a.atoms[e]=new en._Atom(t.implicitH)}));var o=["B","C","N","O","P","S","Se","As"];t.bonds.forEach((function(e,n){e.type===q.PATTERN.TYPE.AROMATIC&&(a.atoms[e.begin].aromatic=!0,-1!==o.indexOf(t.atoms.get(e.begin).label)&&(a.atoms[e.begin].lowercase=!0),a.atoms[e.end].aromatic=!0,-1!==o.indexOf(t.atoms.get(e.end).label)&&(a.atoms[e.end].lowercase=!0)),a.atoms[e.begin].neighbours.push({aid:e.end,bid:n}),a.atoms[e.end].neighbours.push({aid:e.begin,bid:n})})),this.inLoop=function(){t.prepareLoopStructure();var e=new H;t.loops.forEach((function(n){if(n.hbs.length<=6){var r=n.hbs.map((function(e){return t.halfBonds.get(e).bid}));e=e.union(new H(r))}}));var n={};return e.forEach((function(t){n[t]=1})),n}(),this.touchedCistransbonds=0,this.markCisTrans(t);var s=t.getComponents(),u=s.reactants.concat(s.products),l=new Je(t,this.atoms,u,s.reactants.length);for(l.walk(),this.atoms.forEach((function(t){t.neighbours=[]})),n=0;n<l.v_seq.length;n++){var c=l.v_seq[n],d=c.idx,h=c.parent_edge,f=c.parent_vertex;if(h>=0){var p=this.atoms[d],m=l.numOpeningCycles(h);for(r=0;r<m;r++)this.atoms[f].neighbours.push({aid:-1,bid:-1});if(l.edgeClosingCycle(h)){for(i=0;i<p.neighbours.length;i++)if(-1===p.neighbours[i].aid){p.neighbours[i].aid=f,p.neighbours[i].bid=h;break}if(i===p.neighbours.length)throw new Error("internal: can not put closing bond to its place")}else p.neighbours.push({aid:f,bid:h}),p.parent=f;this.atoms[f].neighbours.push({aid:d,bid:h})}}try{var g=new Qe(t,(function(t){return this.atoms[t].neighbours}),this);g.buildFromBonds(this.ignoreErrors),g.each((function(t,e){var n=-1;-1===t.pyramid[3]&&(n=3);var o=[],s=0,u=a.atoms[e];if(-1!==u.parent)for(i=0;i<4;i++)if(t.pyramid[i]===u.parent){o[s++]=i;break}for(-1!==n&&(o[s++]=n),r=0;r!==u.neighbours.length;r++)if(u.neighbours[r].aid!==u.parent)for(i=0;i<4;i++)if(u.neighbours[r].aid===t.pyramid[i]){if(s>=4)throw new Error("internal: pyramid overflow");o[s++]=i;break}if(4===s)s=o[0],o[0]=o[1],o[1]=o[2],o[2]=o[3],o[3]=s;else if(3!==s)throw new Error("cannot calculate chirality");Qe.isPyramidMappingRigid(o)?a.atoms[e].chirality=1:a.atoms[e].chirality=2}))}catch(t){}var v=[];v.push(0);var y=!0;for(n=0;n<l.v_seq.length;n++){d=(c=l.v_seq[n]).idx,h=c.parent_edge;var b=!0;if((f=c.parent_vertex)>=0){for(l.numBranches(f)>1&&this.atoms[f].branch_cnt>0&&this.atoms[f].paren_written&&(this.smiles+=")"),m=l.numOpeningCycles(h),r=0;r<m;r++){for(i=1;i<v.length&&-1!==v[i];i++);i===v.length?v.push(f):v[i]=f,this.writeCycleNumber(i)}if(f>=0){var w=l.numBranches(f);if(w>1&&this.atoms[f].branch_cnt<w-1&&(l.edgeClosingCycle(h)?this.atoms[f].paren_written=!1:(this.smiles+="(",this.atoms[f].paren_written=!0)),this.atoms[f].branch_cnt++,this.atoms[f].branch_cnt>w)throw new Error("unexpected branch")}var x=t.bonds.get(h),E=0;if(x.type===q.PATTERN.TYPE.SINGLE&&(E=this.calcBondDirection(t,h,f)),1===E&&d===x.end||2===E&&d===x.begin?this.smiles+="/":2===E&&d===x.end||1===E&&d===x.begin?this.smiles+="\\":x.type===q.PATTERN.TYPE.ANY?this.smiles+="~":x.type===q.PATTERN.TYPE.DOUBLE?this.smiles+="=":x.type===q.PATTERN.TYPE.TRIPLE?this.smiles+="#":x.type===q.PATTERN.TYPE.SINGLE_OR_AROMATIC?this.smiles+="-,:":x.type===q.PATTERN.TYPE.DOUBLE_OR_AROMATIC?this.smiles+="=,:":x.type===q.PATTERN.TYPE.SINGLE_OR_DOUBLE?this.smiles+="-,=":x.type!==q.PATTERN.TYPE.AROMATIC||this.atoms[x.begin].lowercase&&this.atoms[x.end].lowercase&&this.isBondInRing(h)?x.type===q.PATTERN.TYPE.SINGLE&&this.atoms[x.begin].aromatic&&this.atoms[x.end].aromatic&&(this.smiles+="-"):this.smiles+=":",l.edgeClosingCycle(h)){for(r=1;r<v.length&&v[r]!==d;r++);if(r===v.length)throw new Error("cycle number not found");this.writeCycleNumber(r),v[r]=-1,b=!1}}else y||(this.smiles+=this.writtenComponents===l.nComponentsInReactants&&0!==l.nReactants?">>":"."),y=!1,this.writtenComponents++;b&&(this.writeAtom(t,d,this.atoms[d].aromatic,this.atoms[d].lowercase,this.atoms[d].chirality),this.writtenAtoms.push(c.idx))}return this.comma=!1,this.writeRadicals(t),this.comma&&(this.smiles+="|"),this.smiles},en.prototype.writeCycleNumber=function(t){if(t>0&&t<10)this.smiles+=t;else if(t>=10&&t<100)this.smiles+="%"+t;else{if(!(t>=100&&t<1e3))throw new Error("bad cycle number: "+t);this.smiles+="%%"+t}},en.prototype.writeAtom=function(t,e,n,r,i){var a,o=t.atoms.get(e),s=!1,u=-1;if("A"!==o.label)if("R"!==o.label&&"R#"!==o.label){a=o.aam,"C"!==o.label&&"P"!==o.label&&"N"!==o.label&&"S"!==o.label&&"O"!==o.label&&"Cl"!==o.label&&"F"!==o.label&&"Br"!==o.label&&"B"!==o.label&&"I"!==o.label&&(s=!0),(o.explicitValence>=0||0!==o.radical||i>0||n&&"C"!==o.label&&"O"!==o.label||n&&"C"===o.label&&this.atoms[e].neighbours.length<3&&0===this.atoms[e].h_count)&&(u=this.atoms[e].h_count);var l=o.label;if(o.atomList&&!o.atomList.notList?(l=o.atomList.label(),s=!1):o.isPseudo()||o.atomList&&o.atomList.notList?(l="*",s=!1):(i||0!==o.charge||o.isotope>0||u>=0||a>0)&&(s=!0),s&&(-1===u&&(u=this.atoms[e].h_count),this.smiles+="["),o.isotope>0&&(this.smiles+=o.isotope),this.smiles+=r?l.toLowerCase():l,i>0&&(this.smiles+=1===i?"@":"@@",o.implicitH>1))throw new Error(o.implicitH+" implicit H near stereocenter");"H"!==o.label&&(u>1||0===u&&!s?this.smiles+="H"+u:1===u&&(this.smiles+="H")),o.charge>1?this.smiles+="+"+o.charge:o.charge<-1?this.smiles+=o.charge:1===o.charge?this.smiles+="+":-1===o.charge&&(this.smiles+="-"),a>0&&(this.smiles+=":"+a),s&&(this.smiles+="]")}else this.smiles+="[*]";else this.smiles+="*"},en.prototype.markCisTrans=function(t){var e=this;this.cis_trans=new Xe(t,(function(t){return this.atoms[t].neighbours}),this),this.cis_trans.build(),this.dbonds=new Array(t.bonds.size),t.bonds.forEach((function(t,n){e.dbonds[n]={ctbond_beg:-1,ctbond_end:-1,saved:0}})),this.cis_trans.each((function(n,r){var i=t.bonds.get(r);if(0!==n.parity&&!e.isBondInRing(r)){var a=e.atoms[i.begin].neighbours,o=e.atoms[i.end].neighbours,s=!0,u=!0;if(a.forEach((function(e){e.bid!==r&&t.bonds.get(e.bid).type===q.PATTERN.TYPE.SINGLE&&(s=!1)})),o.forEach((function(e){e.bid!==r&&t.bonds.get(e.bid).type===q.PATTERN.TYPE.SINGLE&&(u=!1)})),s||u)return;a.forEach((function(n){n.bid!==r&&(t.bonds.get(n.bid).begin===i.begin?e.dbonds[n.bid].ctbond_beg=r:e.dbonds[n.bid].ctbond_end=r)})),o.forEach((function(n){n.bid!==r&&(t.bonds.get(n.bid).begin===i.end?e.dbonds[n.bid].ctbond_beg=r:e.dbonds[n.bid].ctbond_end=r)}))}}))},en.prototype.updateSideBonds=function(t,e){var n=t.bonds.get(e),r=this.cis_trans.getSubstituents(e),i=this.cis_trans.getParity(e),a=[-1,-1,-1,-1];a[0]=t.findBondId(r[0],n.begin),-1!==r[1]&&(a[1]=t.findBondId(r[1],n.begin)),a[2]=t.findBondId(r[2],n.end),-1!==r[3]&&(a[3]=t.findBondId(r[3],n.end));var o=0,s=0,u=0,l=0;if(0!==this.dbonds[a[0]].saved&&(1===this.dbonds[a[0]].saved&&t.bonds.get(a[0]).begin===n.begin||2===this.dbonds[a[0]].saved&&t.bonds.get(a[0]).end===n.begin?o++:s++),-1!==a[1]&&0!==this.dbonds[a[1]].saved&&(2===this.dbonds[a[1]].saved&&t.bonds.get(a[1]).begin===n.begin||1===this.dbonds[a[1]].saved&&t.bonds.get(a[1]).end===n.begin?o++:s++),0!==this.dbonds[a[2]].saved&&(1===this.dbonds[a[2]].saved&&t.bonds.get(a[2]).begin===n.end||2===this.dbonds[a[2]].saved&&t.bonds.get(a[2]).end===n.end?u++:l++),-1!==a[3]&&0!==this.dbonds[a[3]].saved&&(2===this.dbonds[a[3]].saved&&t.bonds.get(a[3]).begin===n.end||1===this.dbonds[a[3]].saved&&t.bonds.get(a[3]).end===n.end?u++:l++),i===Xe.PARITY.CIS?(o+=u,s+=l):(o+=l,s+=u),o>0&&s>0)throw new Error("incompatible cis-trans configuration");return(0!==o||0!==s)&&(o>0&&(this.dbonds[a[0]].saved=t.bonds.get(a[0]).begin===n.begin?1:2,-1!==a[1]&&(this.dbonds[a[1]].saved=t.bonds.get(a[1]).begin===n.begin?2:1),this.dbonds[a[2]].saved=t.bonds.get(a[2]).begin===n.end==(i===Xe.PARITY.CIS)?1:2,-1!==a[3]&&(this.dbonds[a[3]].saved=t.bonds.get(a[3]).begin===n.end==(i===Xe.PARITY.CIS)?2:1)),s>0&&(this.dbonds[a[0]].saved=t.bonds.get(a[0]).begin===n.begin?2:1,-1!==a[1]&&(this.dbonds[a[1]].saved=t.bonds.get(a[1]).begin===n.begin?1:2),this.dbonds[a[2]].saved=t.bonds.get(a[2]).begin===n.end==(i===Xe.PARITY.CIS)?2:1,-1!==a[3]&&(this.dbonds[a[3]].saved=t.bonds.get(a[3]).begin===n.end==(i===Xe.PARITY.CIS)?1:2)),!0)},en.prototype.calcBondDirection=function(t,e,n){var r,i=this;if(-1===this.dbonds[e].ctbond_beg&&-1===this.dbonds[e].ctbond_end)return 0;if(t.bonds.get(e).type!==q.PATTERN.TYPE.SINGLE)throw new Error("internal: directed bond type "+t.bonds.get(e).type);for(;r=0,this.cis_trans.each((function(e,n){0===e.parity||i.isBondInRing(n)||i.updateSideBonds(t,n)&&r++})),r!==this.touchedCistransbonds;)this.touchedCistransbonds=r;return 0===this.dbonds[e].saved&&(n===t.bonds.get(e).begin?this.dbonds[e].saved=1:this.dbonds[e].saved=2),this.dbonds[e].saved},en.prototype.writeRadicals=function(t){var e,n,r=new Array(this.writtenAtoms.length);for(e=0;e<this.writtenAtoms.length;e++)if(!r[e]){var i=t.atoms.get(this.writtenAtoms[e]).radical;if(0!==i)for(this.comma?this.smiles+=",":(this.smiles+=" |",this.comma=!0),i===W.PATTERN.RADICAL.SINGLET?this.smiles+="^3:":i===W.PATTERN.RADICAL.DOUPLET?this.smiles+="^1:":this.smiles+="^4:",this.smiles+=e,n=e+1;n<this.writtenAtoms.length;n++)t.atoms.get(this.writtenAtoms[n]).radical===i&&(r[n]=!0,this.smiles+=","+n)}};var an=function(){function t(e){(0,r.Z)(this,t),this.options=rn(rn({},t.DefaultOptions),e)}return(0,i.Z)(t,[{key:"deserialize",value:function(t){throw new Error("Not implemented yet.")}},{key:"serialize",value:function(t){return(new en).saveMolecule(t,this.options.ignoreErrors)}}]),t}();(0,a.Z)(an,"DefaultOptions",{ignoreErrors:!1});var on,sn=/^[^]+?\$\$\$\$$/gm,un=function(){function t(){(0,r.Z)(this,t)}return(0,i.Z)(t,[{key:"deserialize",value:function(t){for(var e,n=[],r=new $e;null!==(e=sn.exec(t));){var i=e[0].replace(/\r/g,"").trim(),a=i.indexOf("M END");if(-1!==a){var o=i.substr(a+7).trim().split(/^$\n?/m),s=r.deserialize(i.substring(0,a+6)),u=o.reduce((function(t,e){var n=e.match(/^> [ \d]*<(\S+)>/);if(n){var r=n[1],i=e.split("\n")[1].trim();t[r]=Number.isFinite(i)?+i:i.toString()}return t}),{});n.push({struct:s,props:u})}}return n}},{key:"serialize",value:function(t){var e=new $e;return t.reduce((function(t,n){return t+=e.serialize(n.struct),Object.keys(n.props).forEach((function(e){t+="> <".concat(e,">\n"),t+="".concat(n.props[e],"\n\n")})),"".concat(t,"$$$$\n")}),"")}}]),t}();function ln(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function cn(t,e,n,r,i){var a=e;n&&"GET"===t&&(a=function(t,e){return t.replace(/:(\w+)/g,(function(t,n){return e[n]}))}(e,n));var o=fetch(a,{method:t,headers:Object.assign({Accept:"application/json"},r),body:"GET"!==t?n:void 0,credentials:"same-origin"});return i?i(o):o.then((function(t){return t.json().then((function(e){return t.ok?e:Promise.reject(e.error)}))}))}function dn(t,e,n,r,i){return function(o,s,u){var l=Object.assign({},o);return l.options=Object.assign(l.options||{},r,s),cn(t,n+e,JSON.stringify(l),function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ln(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ln(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}({"Content-Type":"application/json"},i),u)}}!function(t){t.Mol="chemical/x-mdl-molfile",t.Rxn="chemical/x-mdl-rxnfile",t.DaylightSmiles="chemical/x-daylight-smiles",t.ExtendedSmiles="chemical/x-chemaxon-cxsmiles",t.DaylightSmarts="chemical/x-daylight-smarts",t.InChI="chemical/x-inchi",t.InChIAuxInfo="chemical/x-inchi-aux",t.CDX="chemical/x-cdx",t.CDXML="chemical/x-cdxml",t.CML="chemical/x-cml",t.KET="chemical/x-indigo-ket",t.UNKNOWN="chemical/x-unknown"}(on||(on={}));var hn,fn=function(){function t(e,n,i){(0,r.Z)(this,t),this.apiPath=e,this.defaultOptions=n,this.customHeaders=i}var e;return(0,i.Z)(t,[{key:"generateInchIKey",value:function(t){return dn("POST","indigo/convert",this.apiPath,this.defaultOptions,this.customHeaders)({struct:t,output_format:"chemical/x-inchi"},{})}},{key:"info",value:(e=(0,w.Z)(E().mark((function t(){var e,n,r,i;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=!1,t.prev=1,t.next=4,cn("GET",this.apiPath+"info");case 4:i=t.sent,e=i.indigo_version,n=i.imago_versions,r=!0,t.next=15;break;case 10:t.prev=10,t.t0=t.catch(1),e="",n=[],r=!1;case 15:return t.abrupt("return",{indigoVersion:e,imagoVersions:n,isAvailable:r});case 16:case"end":return t.stop()}}),t,this,[[1,10]])}))),function(){return e.apply(this,arguments)})},{key:"convert",value:function(t,e){return dn("POST","indigo/convert",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"layout",value:function(t,e){return dn("POST","indigo/layout",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"clean",value:function(t,e){return dn("POST","indigo/clean",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"aromatize",value:function(t,e){return dn("POST","indigo/aromatize",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"dearomatize",value:function(t,e){return dn("POST","indigo/dearomatize",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"calculateCip",value:function(t,e){return dn("POST","indigo/calculate_cip",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"automap",value:function(t,e){return dn("POST","indigo/automap",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"check",value:function(t,e){return dn("POST","indigo/check",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"calculate",value:function(t,e){return dn("POST","indigo/calculate",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"recognize",value:function(t,e){var n=e?"?version=".concat(e):"",r=cn("POST",this.apiPath+"imago/uploads".concat(n),t,{"Content-Type":t.type||"application/octet-stream"}),i=cn.bind(null,"GET",this.apiPath+"imago/uploads/:id");return r.then((function(t){return e=i.bind(null,{id:t.upload_id}),n=function(t){if("FAILURE"===t.state)throw t;return"SUCCESS"===t.state},500,300,new Promise((function(t,r){setTimeout((function i(){e().then((function(e){try{n(e)?t(e):setTimeout(i,500)}catch(t){r(t)}}),(function(t){return r(t)}))}),300)}));var e,n})).then((function(t){return{struct:t.metadata.mol_str}}))}},{key:"generateImageAsBase64",value:function(t,e){var n=(null==e?void 0:e.outputFormat)||"png";return dn("POST","indigo/render",this.apiPath,this.defaultOptions,this.customHeaders)({struct:t},{"render-output-format":n},(function(t){return t.then((function(t){return t.text()}))}))}}]),t}(),pn=((0,i.Z)((function t(e,n){(0,r.Z)(this,t),(0,a.Z)(this,"mode","remote");var i=e;this.customHeaders=n;var o=new URLSearchParams(document.location.search);o.has("api_path")&&(i=o.get("api_path")),this.apiPath=!i||/\/$/.test(i)?i:i+"/"}),[{key:"createStructService",value:function(t){return new fn(this.apiPath,t,this.customHeaders)}}]),(0,i.Z)((function t(e,n,i,a,o){(0,r.Z)(this,t),this.name=e,this.mime=n,this.extensions=i,this.supportsCoords=a||!1,this.options=o||{}}))),mn={molAuto:new pn("MDL Molfile Auto Format detect",on.Mol,[".mol"],!0,{"molfile-saving-mode":"auto"}),mol:new pn("MDL Molfile V2000",on.Mol,[".mol"],!0),molV3000:new pn("MDL Molfile V3000",on.Mol,[".mol"],!0,{"molfile-saving-mode":"3000"}),rxn:new pn("MDL Rxnfile V2000",on.Rxn,[".rxn"],!0),rxnV3000:new pn("MDL Rxnfile V3000",on.Rxn,[".rxn"],!0,{"molfile-saving-mode":"3000"}),smiles:new pn("Daylight SMILES",on.DaylightSmiles,[".smi",".smiles"]),smilesExt:new pn("Extended SMILES",on.ExtendedSmiles,[".cxsmi",".cxsmiles"]),smarts:new pn("Daylight SMARTS",on.DaylightSmarts,[".smarts"]),inChI:new pn("InChI",on.InChI,[".inchi"]),inChIAuxInfo:new pn("InChI AuxInfo",on.InChIAuxInfo,[".inchi"]),cml:new pn("CML",on.CML,[".cml",".mrv"],!0),ket:new pn("Ket Format",on.KET,[".ket"]),cdxml:new pn("CDXML",on.CDXML,[".cdxml"],!0),cdx:new pn("Base64 CDX",on.CDX,[".cdx"],!0),unknown:new pn("Unknown",on.UNKNOWN,["."],!0)},gn={svg:{extension:".svg",name:"SVG Document"},png:{extension:".png",name:"PNG Image"}};function vn(t){return gn[t]}function yn(t){return mn[t]}!function(t){t.mol="mol",t.molV3000="molV3000",t.molAuto="molAuto",t.rxn="rxn",t.rxnV3000="rxnV3000",t.smiles="smiles",t.smilesExt="smilesExt",t.smarts="smarts",t.inChI="inChI",t.inChIAuxInfo="inChIAuxInfo",t.cml="cml",t.ket="ket",t.cdxml="cdxml",t.cdx="cdx",t.unknown="unknown"}(hn||(hn={}));var bn=new WeakMap,wn=function(){function t(e){var n,i,a;(0,r.Z)(this,t),a={writable:!0,value:void 0},function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(n=this,i=bn),i.set(n,a),(0,f.Z)(this,bn,e)}var e,n;return(0,i.Z)(t,[{key:"getStructureFromStructAsync",value:(n=(0,w.Z)(E().mark((function t(e){var n;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=(0,p.Z)(this,bn).serialize(e),t.abrupt("return",n);case 2:case"end":return t.stop()}}),t,this)}))),function(t){return n.apply(this,arguments)})},{key:"getStructureFromStringAsync",value:(e=(0,w.Z)(E().mark((function t(e){return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",(0,p.Z)(this,bn).deserialize(e));case 1:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})}]),t}();var xn=new WeakMap,En=function(){function t(e){var n,i,a;(0,r.Z)(this,t),a={writable:!0,value:void 0},function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(n=this,i=xn),i.set(n,a),(0,f.Z)(this,xn,e)}var e,n;return(0,i.Z)(t,[{key:"getStructureFromStructAsync",value:(n=(0,w.Z)(E().mark((function t(e){var n;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=(0,p.Z)(this,xn).serialize(e),t.abrupt("return",n);case 2:case"end":return t.stop()}}),t,this)}))),function(t){return n.apply(this,arguments)})},{key:"getStructureFromStringAsync",value:(e=(0,w.Z)(E().mark((function t(e){var n;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=(0,p.Z)(this,xn).deserialize(e),t.abrupt("return",n);case 2:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})}]),t}();function On(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function An(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?On(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):On(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function Sn(t,e,n){!function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t,e),e.set(t,n)}var Rn=new WeakMap,Pn=new WeakMap,Tn=new WeakMap,kn=new WeakMap,Bn=function(){function t(e,n,i,a){(0,r.Z)(this,t),Sn(this,Rn,{writable:!0,value:void 0}),Sn(this,Pn,{writable:!0,value:void 0}),Sn(this,Tn,{writable:!0,value:void 0}),Sn(this,kn,{writable:!0,value:void 0}),(0,f.Z)(this,Rn,e),(0,f.Z)(this,Pn,n),(0,f.Z)(this,Tn,i),(0,f.Z)(this,kn,a)}var e,n;return(0,i.Z)(t,[{key:"getStructureFromStructAsync",value:(n=(0,w.Z)(E().mark((function t(e){var n,r,i,a;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=yn((0,p.Z)(this,Tn)),t.prev=1,r=(0,p.Z)(this,Pn).serialize(e),t.next=5,(0,p.Z)(this,Rn).convert({struct:r,output_format:n.mime},An(An({},(0,p.Z)(this,kn)),n.options));case 5:return i=t.sent,t.abrupt("return",i.struct);case 9:throw t.prev=9,t.t0=t.catch(1),a="Server is not compatible"===t.t0.message?"".concat(n.name," is not supported."):"Convert error!\n".concat(t.t0.message||t.t0),new Error(a);case 13:case"end":return t.stop()}}),t,this,[[1,9]])}))),function(t){return n.apply(this,arguments)})},{key:"getStructureFromStringAsync",value:(e=(0,w.Z)(E().mark((function t(e){var n,r,i,a,o,s;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r={struct:void 0,output_format:yn(hn.ket).mime},(i=yn((0,p.Z)(this,Tn)).supportsCoords)?(n=(0,p.Z)(this,Rn).convert,r.struct=e):(n=(0,p.Z)(this,Rn).layout,r.struct=e.trim()),t.prev=3,t.next=6,n(r,(0,p.Z)(this,kn));case 6:return a=t.sent,o=(0,p.Z)(this,Pn).deserialize(a.struct),i||o.rescale(),t.abrupt("return",o);case 12:if(t.prev=12,t.t0=t.catch(3),"Server is not compatible"===t.t0.message){t.next=16;break}throw Error("Convert error!\n".concat(t.t0.message||t.t0));case 16:throw s="smiles"===(0,p.Z)(this,Tn)?"".concat(yn(hn.smilesExt).name," and opening of ").concat(yn(hn.smiles).name):yn((0,p.Z)(this,Tn)).name,Error("".concat(s," is not supported in standalone mode."));case 18:case"end":return t.stop()}}),t,this,[[3,12]])}))),function(t){return e.apply(this,arguments)})}]),t}();var Cn=new WeakMap,Mn=function(){function t(e){var n,i,a;(0,r.Z)(this,t),a={writable:!0,value:void 0},function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(n=this,i=Cn),i.set(n,a),(0,f.Z)(this,Cn,e)}var e,n;return(0,i.Z)(t,[{key:"getStructureFromStructAsync",value:(n=(0,w.Z)(E().mark((function t(e){var n;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=(0,p.Z)(this,Cn).serialize(e),t.abrupt("return",n);case 2:case"end":return t.stop()}}),t,this)}))),function(t){return n.apply(this,arguments)})},{key:"getStructureFromStringAsync",value:(e=(0,w.Z)(E().mark((function t(e){var n;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=(0,p.Z)(this,Cn).deserialize(e),t.abrupt("return",n);case 2:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})}]),t}(),Zn=["reactionRelayout","badHeaderRecover"];var Nn,In,Ln,Dn=new WeakMap,_n=function(){function t(e){var n,i,a;(0,r.Z)(this,t),a={writable:!0,value:void 0},function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(n=this,i=Dn),i.set(n,a),(0,f.Z)(this,Dn,e)}return(0,i.Z)(t,[{key:"separateOptions",value:function(t){if(!t)return[{},{}];var e=t.reactionRelayout,n=t.badHeaderRecover,r=(0,S.Z)(t,Zn),i={};return"boolean"==typeof e&&(i.reactionRelayout=e),"boolean"==typeof n&&(i.badHeaderRecover=n),[i,r]}},{key:"create",value:function(t,e){var n,r=this.separateOptions(e),i=(0,m.Z)(r,2),a=i[0],o=i[1];switch(t){case hn.ket:n=new wn(new Xt);break;case hn.rxn:n=new En(new $e(a));break;case hn.mol:n=new Mn(new $e(a));break;case hn.cml:case hn.inChIAuxInfo:case hn.inChI:case hn.molV3000:case hn.smiles:case hn.rxnV3000:case hn.smilesExt:case hn.smarts:case hn.cdxml:case hn.cdx:case hn.unknown:default:n=new Bn((0,p.Z)(this,Dn),new Xt,t,o)}return n}}]),t}();function jn(t){var e=t.trim();try{if(JSON.parse(e))return hn.ket}catch(t){}if(-1!==e.indexOf("$RXN"))return hn.rxn;if(-1!==e.indexOf("V2000"))return hn.mol;if(-1!==e.indexOf("V3000"))return hn.molV3000;var n=e.match(/^(M {2}END|\$END MOL)$/m);if(n){var r=(n.index||0)+n[0].length;if(r===e.length||-1!==e.slice(r,r+20).search(/^\$(MOL|END CTAB)$/m))return hn.mol}if("<"===e[0]&&-1!==e.indexOf("<molecule"))return hn.cml;var i=e.replace(/\s/g,"").replace(/(\\r)|(\\n)/g,"");return i.length%4==0&&/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/.test(i)&&window.atob(i).startsWith("VjCD0100")?hn.cdx:"InChI"===e.slice(0,5)?hn.inChI:-1===e.indexOf("\n")?hn.smiles:-1!==e.indexOf("<CDXML")?hn.cdxml:hn.unknown}P().el.translateAbs=function(t,e){this.delta=this.delta||new _,this.delta.x+=t-0,this.delta.y+=e-0,this.transform("t"+this.delta.x.toString()+","+this.delta.y.toString())},P().st.translateAbs=function(t,e){this.forEach((function(n){n.translateAbs(t,e)}))},function(t){t.background="background",t.selectionPlate="selectionPlate",t.hovering="hovering",t.warnings="warnings",t.data="data",t.indices="indices"}(Nn||(Nn={})),function(t){t.LabelsOnly="LabelsOnly",t.BondsOnly="BondsOnly",t.LabelsAndBonds="LabelsAndBonds",t.Off="Off"}(In||(In={})),function(t){t.IUPAC="Iupac",t.Classic="Classic",t.On="On",t.Off="Off"}(Ln||(Ln={}));var Gn=function(){function t(e){(0,r.Z)(this,t),this.type=e,this.paths=[],this.boxes=[],this.boundingBox=null,this.oldBoundingBox=null,this.exts=[]}return(0,i.Z)(t,[{key:"add",value:function(t,e,n){this.paths.push(t),e&&(this.boxes.push(e),this.boundingBox=null==this.boundingBox?e:it.union(this.boundingBox,e)),n&&this.exts.push(n)}},{key:"clear",value:function(){this.paths=[],this.boxes=[],this.exts=[],null!==this.boundingBox&&(this.oldBoundingBox=this.boundingBox.clone()),this.boundingBox=null}},{key:"translate",value:function(){if(arguments.length>2)throw new Error("One vector or two scalar arguments expected");if(1===arguments.length){var t=arguments.length<=0?void 0:arguments[0];this.translate(t.x,t.y)}else{for(var e=arguments.length<=0?void 0:arguments[0],n=arguments.length<=1?void 0:arguments[1],r=new _(e,n),i=0;i<this.paths.length;++i)this.paths[i].translateAbs(e,n);for(var a=0;a<this.boxes.length;++a)this.boxes[a]=this.boxes[a].translate(r);null!==this.boundingBox&&(this.boundingBox=this.boundingBox.translate(r))}}}]),t}(),Fn=function(){function t(e){(0,r.Z)(this,t),(0,a.Z)(this,"hover",!1),(0,a.Z)(this,"hovering",null),(0,a.Z)(this,"selected",!1),(0,a.Z)(this,"selectionPlate",null),this.visel=new Gn(e)}return(0,i.Z)(t,[{key:"getVBoxObj",value:function(t){var e=this.visel.boundingBox;return null===e?null:(t.options.offset&&(e=e.translate(t.options.offset.negated())),e.transform(tt.scaled2obj,t.options))}},{key:"setHover",value:function(t,e){if(t){var n="hovering"in this&&null!==this.hovering;if(n)if("set"===this.hovering.type){if(!this.hovering[0])return;n=!this.hovering[0].removed}else n=!this.hovering.removed;n?this.hovering.show():(e.paper.setStart(),this.drawHover(e),this.hovering=e.paper.setFinish())}else this.hovering&&this.hovering.hide();this.hover=t}},{key:"drawHover",value:function(t){throw new Error("ReObject.drawHover is not overridden.")}},{key:"makeSelectionPlate",value:function(t,e,n){throw new Error("ReObject.makeSelectionPlate is not overridden")}}]),t}(),Hn={tfx:function(t){return parseFloat(t).toFixed(8)},relBox:function(t){return{x:t.x,y:t.y,width:t.width,height:t.height}},shiftRayBox:function(t,e,n){s()(!!t),s()(!!e),s()(!!n);var r=[n.p0,new _(n.p1.x,n.p0.y),n.p1,new _(n.p0.x,n.p1.y)].map((function(e){return e.sub(t)}));e=e.normalized();for(var i=r.map((function(t){return _.cross(t,e)})),a=r.map((function(t){return _.dot(t,e)})),o=-1,u=-1,l=0;l<4;++l)i[l]>0?(o<0||a[o]<a[l])&&(o=l):(u<0||a[u]<a[l])&&(u=l);if(u<0||o<0)return 0;var c=a[o]>a[u]?u:o,d=a[o]>a[u]?o:u;return a[c]+Math.abs(i[c])*(a[d]-a[c])/(Math.abs(i[c])+Math.abs(i[d]))},calcCoordinates:function(t,e,n){var r={pos1:null,pos2:null},i={x:e.x-t.x,y:e.y-t.y},a=(Math.pow(n,2)-i.x*i.x-i.y*i.y-Math.pow(n,2))/-2,o=i.x*i.x+i.y*i.y;if(0!==i.x){var s=-2*i.y*a,u=s*s-4*o*(a*a-n*n*i.x*i.x);u>0&&(r.pos1={x:0,y:0},r.pos2={x:0,y:0},r.pos1.y=(-s+Math.sqrt(u))/(2*o),r.pos2.y=(-s-Math.sqrt(u))/(2*o),r.pos1.x=(a-r.pos1.y*i.y)/i.x,r.pos2.x=(a-r.pos2.y*i.y)/i.x)}else r.pos1={x:0,y:0},r.pos2={x:0,y:0},r.pos1.y=a/i.y,r.pos2.y=a/i.y,r.pos1.x=-Math.sqrt(Math.pow(n,2)-Math.pow(a,2)/Math.pow(i.y,2)),r.pos2.x=Math.sqrt(Math.pow(n,2)-Math.pow(a,2)/Math.pow(i.y,2));return null!==r.pos1&&(r.pos1.x+=t.x,r.pos1.y+=t.y),null!==r.pos2&&(r.pos2.x+=t.x,r.pos2.y+=t.y),r}};function zn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Un(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?zn(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):zn(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var Vn=Hn.tfx;function Wn(t,e){return"M"+Vn(t.x)+","+Vn(t.y)+"L"+Vn(e.x)+","+Vn(e.y)+"\t"}function Yn(t,e,n){for(var r=0,i=_.dist(t,e),a=_.diff(e,t).normalized(),o=!0,s="",u=0;r<i;){var l=n[u%n.length],c=r+Math.min(l,i-r);o&&(s+="M "+t.addScaled(a,r).coordStr()+" L "+t.addScaled(a,c).coordStr()),r+=l,o=!o,u++}return s}function qn(t,e){if(P().vml){var n=.16*e.height;t.translateAbs(0,n),e.y+=n}}var $n,Xn={recenterText:qn,arrow:function(t,e,n,r,i){switch(e.mode){case dt.OpenAngle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=o.x+n,u="M".concat(Vn(o.x),",").concat(Vn(o.y))+"L".concat(Vn(s),",").concat(Vn(o.y))+"L".concat(Vn(s-7),",").concat(Vn(o.y-5))+"M".concat(Vn(s),",").concat(Vn(o.y))+"L".concat(Vn(s-7),", ").concat(Vn(o.y+5)),l=k()(u).rotate(r,o.x,o.y).toString();return t.path(l).attr(i.lineattr)}(t,e,n,r,i);case dt.FilledTriangle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=o.x+n,u="M".concat(Vn(o.x),",").concat(Vn(o.y))+"L".concat(Vn(s),",").concat(Vn(o.y))+"L".concat(Vn(s-10),",").concat(Vn(o.y+5))+"L".concat(Vn(s-10),",").concat(Vn(o.y-5))+"L".concat(Vn(s),",").concat(Vn(o.y),"Z"),l=k()(u).rotate(r,o.x,o.y).toString();return t.path(l).attr(Un(Un({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case dt.FilledBow:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=o.x+n,u="M".concat(Vn(o.x),",").concat(Vn(o.y))+"L".concat(Vn(s),",").concat(Vn(o.y))+"L".concat(Vn(s-10),",").concat(Vn(o.y+5))+"L".concat(Vn(s-10+4),",").concat(Vn(o.y))+"L".concat(Vn(s-10),",").concat(Vn(o.y-5))+"L".concat(Vn(s),",").concat(Vn(o.y),"Z"),l=k()(u).rotate(r,o.x,o.y).toString();return t.path(l).attr(Un(Un({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case dt.DashedOpenAngle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];for(var s=[],u=o.x+n,l=0;l<n/3.5;l++)l%2?s.push("L".concat(Vn(o.x+3.5*l),",").concat(Vn(o.y))):s.push("M".concat(Vn(o.x+3.5*l),",").concat(Vn(o.y)));s.push("M".concat(Vn(u),",").concat(Vn(o.y))+"L".concat(Vn(u-10),",").concat(Vn(o.y+5))+"M".concat(Vn(u),",").concat(Vn(o.y))+"L".concat(Vn(u-10),",").concat(Vn(o.y-5)));var c=k()(s.join("")).rotate(r,o.x,o.y).toString();return t.path(c).attr(Un(Un({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case dt.Failed:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=o.x+n,u=s-(s-o.x)/2,l=[];l.push("M".concat(Vn(o.x),",").concat(Vn(o.y))+"L".concat(Vn(s),",").concat(Vn(o.y))+"L".concat(Vn(s-10),",").concat(Vn(o.y+5))+"L".concat(Vn(s-10+4),",").concat(Vn(o.y))+"L".concat(Vn(s-10),",").concat(Vn(o.y-5))+"L".concat(Vn(s),",").concat(Vn(o.y),"Z")),l.push("M".concat(Vn(u+8),",").concat(Vn(o.y+8))+"L".concat(Vn(u-8),",").concat(Vn(o.y-8))),l.push("M".concat(Vn(u+8),",").concat(Vn(o.y-8))+"L".concat(Vn(u-8),",").concat(Vn(o.y+8)));var c=k()(l.join("")).rotate(r,o.x,o.y).toString();return t.path(c).attr(Un(Un({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case dt.BothEndsFilledTriangle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=o.x+n,u="M".concat(Vn(o.x),",").concat(Vn(o.y))+"L".concat(Vn(s),",").concat(Vn(o.y))+"L".concat(Vn(s-10),",").concat(Vn(o.y+5))+"L".concat(Vn(s-10),",").concat(Vn(o.y-5))+"L".concat(Vn(s),",").concat(Vn(o.y))+"M".concat(Vn(o.x),",").concat(Vn(o.y))+"L".concat(Vn(o.x+10),",").concat(Vn(o.y-5))+"L".concat(Vn(o.x+10),",").concat(Vn(o.y+5))+"L".concat(Vn(o.x),",").concat(Vn(o.y)),l=k()(u).rotate(r,o.x,o.y).toString();return t.path(l).attr(Un(Un({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case dt.EquilibriumFilledHalfBow:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=3.5,u=o.x+n,l=[];l.push("M".concat(Vn(o.x),",").concat(Vn(o.y-s))+"L".concat(Vn(u),",").concat(Vn(o.y-s))+"L".concat(Vn(u-9),",").concat(Vn(o.y-7))+"L".concat(Vn(u-9+2),",").concat(Vn(o.y-s),"Z")),l.push("M".concat(Vn(u),",").concat(Vn(o.y+s))+"L".concat(Vn(o.x),",").concat(Vn(o.y+s))+"L".concat(Vn(o.x+9),",").concat(Vn(o.y+7))+"L".concat(Vn(o.x+9-2),",").concat(o.y+s,"Z"));var c=k()(l.join("")).rotate(r,o.x,o.y).toString();return t.path(c).attr(Un(Un({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case dt.EquilibriumFilledTriangle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=3.5,u=o.x+n,l=[];l.push("M".concat(Vn(o.x),",").concat(Vn(o.y-s))+"L".concat(Vn(u),",").concat(Vn(o.y-s))+"L".concat(Vn(u-9),",").concat(Vn(o.y-7))+"L".concat(Vn(u-9),",").concat(Vn(o.y-s))+"L".concat(Vn(u-9),",").concat(Vn(o.y))+"L".concat(Vn(u),",").concat(Vn(o.y-s),"Z")),l.push("M".concat(Vn(o.x),",").concat(Vn(o.y+s))+"L".concat(Vn(u),",").concat(Vn(o.y+s))+"M".concat(Vn(o.x),",").concat(Vn(o.y+s))+"L".concat(Vn(o.x+9),",").concat(Vn(o.y+7))+"L".concat(Vn(o.x+9),",").concat(o.y+s,"Z")+"L".concat(Vn(o.x+9),",").concat(Vn(o.y))+"L".concat(Vn(o.x+9),",").concat(o.y+s,"Z"));var c=k()(l.join("")).rotate(r,o.x,o.y).toString();return t.path(c).attr(Un(Un({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case dt.EquilibriumOpenAngle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=3.5,u=o.x+n,l=[];l.push("M".concat(Vn(o.x),",").concat(Vn(o.y-s))+"L".concat(Vn(u),",").concat(Vn(o.y-s))+"L".concat(Vn(u-7),",").concat(Vn(o.y-5-s))),l.push("M".concat(Vn(o.x),",").concat(Vn(o.y+s))+"L".concat(Vn(u),",").concat(Vn(o.y+s))+"M".concat(Vn(o.x),",").concat(Vn(o.y+s))+"L".concat(Vn(o.x+9),",").concat(Vn(o.y+s+5)));var c=k()(l.join("")).rotate(r,o.x,o.y).toString();return t.path(c).attr(i.lineattr)}(t,e,n,r,i);case dt.UnbalancedEquilibriumFilledHalfBow:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=3.5,u=o.x+n,l=[];l.push("M".concat(Vn(o.x),",").concat(Vn(o.y-s))+"L".concat(Vn(u),",").concat(Vn(o.y-s))+"L".concat(Vn(u-9),",").concat(Vn(o.y-7))+"L".concat(Vn(u-9+2),",").concat(Vn(o.y-s),"Z")),l.push("M".concat(Vn(o.x+15),",").concat(Vn(o.y+s))+"L".concat(Vn(u-15),",").concat(Vn(o.y+s))+"M".concat(Vn(o.x+15),",").concat(Vn(o.y+s))+"L".concat(Vn(o.x+9+15),",").concat(Vn(o.y+7))+"L".concat(Vn(o.x+9-2+15),",").concat(o.y+s,"Z"));var c=k()(l.join("")).rotate(r,o.x,o.y).toString();return t.path(c).attr(Un(Un({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case dt.UnbalancedEquilibriumOpenHalfAngle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=3.5,u=o.x+n,l=[];l.push("M".concat(Vn(o.x),",").concat(Vn(o.y-s))+"L".concat(Vn(u),",").concat(Vn(o.y-s))+"L".concat(Vn(u-7),",").concat(Vn(o.y-5-s))),l.push("M".concat(Vn(o.x+15),",").concat(Vn(o.y+s))+"L".concat(Vn(u-15),",").concat(Vn(o.y+s))+"M".concat(Vn(o.x+15),",").concat(Vn(o.y+s))+"L".concat(Vn(o.x+9+15),",").concat(Vn(o.y+s+5)));var c=k()(l.join("")).rotate(r,o.x,o.y).toString();return t.path(c).attr(i.lineattr)}(t,e,n,r,i);case dt.UnbalancedEquilibriumLargeFilledHalfBow:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=3.5,u=o.x+n,l=[];l.push("M".concat(Vn(o.x),",").concat(Vn(o.y-s))+"L".concat(Vn(u),",").concat(Vn(o.y-s))+"L".concat(Vn(u-9),",").concat(Vn(o.y-10))+"L".concat(Vn(u-9+2),",").concat(Vn(o.y-s),"Z")),l.push("M".concat(Vn(o.x+15),",").concat(Vn(o.y+s))+"L".concat(Vn(u-15),",").concat(Vn(o.y+s))+"M".concat(Vn(o.x+15),",").concat(Vn(o.y+s))+"L".concat(Vn(o.x+9+15),",").concat(Vn(o.y+10))+"L".concat(Vn(o.x+9-2+15),",").concat(o.y+s,"Z"));var c=k()(l.join("")).rotate(r,o.x,o.y).toString();return t.path(c).attr(Un(Un({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case dt.UnbalancedEquilibriumFilledHalfTriangle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=3.5,u=o.x+n,l=[];l.push("M".concat(Vn(o.x),",").concat(Vn(o.y-s))+"L".concat(Vn(u),",").concat(Vn(o.y-s))+"L".concat(Vn(u-9),",").concat(Vn(o.y-7))+"L".concat(Vn(u-9),",").concat(Vn(o.y-s),"Z")),l.push("M".concat(Vn(o.x+15),",").concat(Vn(o.y+s))+"L".concat(Vn(u-15),",").concat(Vn(o.y+s))+"M".concat(Vn(o.x+15),",").concat(Vn(o.y+s))+"L".concat(Vn(o.x+9+15),",").concat(Vn(o.y+7))+"L".concat(Vn(o.x+9+15),",").concat(o.y+s,"Z"));var c=k()(l.join("")).rotate(r,o.x,o.y).toString();return t.path(c).attr(Un(Un({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case dt.EllipticalArcFilledBow:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=e.height,u=s>=0?1:-1,l=10*u,c=5*u,d=4*u,h=o.x+n,f="M".concat(Vn(o.x),",").concat(Vn(o.y))+"A".concat(n/2,",").concat(s,",",0,",",0,",").concat(u>0?1:0,",").concat(Vn(h),",").concat(Vn(o.y))+"L".concat(Vn(h-c),",").concat(Vn(o.y-l))+"l".concat(Vn(c),",").concat(Vn(d))+"l".concat(Vn(c),",").concat(Vn(-d))+"l".concat(Vn(-c),",").concat(l),p=k()(f).rotate(r,o.x,o.y).toString();return t.path(p).attr(Un({},i.lineattr))}(t,e,n,r,i);case dt.EllipticalArcFilledTriangle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=e.height,u=s>=0?1:-1,l=10*u,c=5*u,d=o.x+n,h="M".concat(Vn(o.x),",").concat(Vn(o.y))+"A".concat(n/2,",").concat(s,",",0,",",0,",").concat(u>0?1:0,",").concat(Vn(d),",").concat(Vn(o.y))+"L".concat(Vn(d-c),",").concat(Vn(o.y-l))+"l".concat(Vn(l),",").concat(Vn(0))+"l".concat(Vn(-c),",").concat(Vn(l)),f=k()(h).rotate(r,o.x,o.y).toString();return t.path(f).attr(Un({},i.lineattr))}(t,e,n,r,i);case dt.EllipticalArcOpenAngle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=e.height,u=s>=0?1:-1,l=5*u,c=7*u,d=o.x+n,h="M".concat(Vn(o.x),",").concat(Vn(o.y))+"A".concat(n/2,",").concat(s,",",0,",",0,",").concat(u>0?1:0,",").concat(Vn(d),",").concat(Vn(o.y))+"L".concat(Vn(d-l),",").concat(Vn(o.y-c))+"M".concat(Vn(d),",").concat(Vn(o.y))+"L".concat(Vn(d+l),", ").concat(Vn(o.y-c)),f=k()(h).rotate(r,o.x,o.y).toString();return t.path(f).attr(i.lineattr)}(t,e,n,r,i);case dt.EllipticalArcOpenHalfAngle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];var s=e.height,u=s>=0?1:-1,l=5*u,c=7*u,d=o.x+n,h="M".concat(Vn(o.x),",").concat(Vn(o.y))+"A".concat(n/2,",").concat(s,",",0,",",0,",").concat(u>0?1:0,", ").concat(Vn(d),",").concat(Vn(o.y))+"L".concat(Vn(d+l),", ").concat(Vn(o.y-c)),f=k()(h).rotate(r,o.x,o.y).toString();return t.path(f).attr(i.lineattr)}(t,e,n,r,i)}},plus:function(t,e,n){var r=n.scale/5;return t.path("M{0},{4}L{0},{5}M{2},{1}L{3},{1}",Vn(e.x),Vn(e.y),Vn(e.x-r),Vn(e.x+r),Vn(e.y-r),Vn(e.y+r)).attr(n.lineattr)},aromaticBondPaths:function(t,e,n,r,i,a){return[a&&1&i?Yn(t,n,a):Wn(t,n),a&&2&i?Yn(e,r,a):Wn(e,r)]},bondSingle:function(t,e,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"#000",a=e.p,o=n.p;return t.path(Wn(a,o)).attr(r.lineattr).attr({fill:i,stroke:i})},bondSingleUp:function(t,e,n,r,i){var a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"#000";return t.path("M{0},{1}L{2},{3}L{4},{5}Z",Vn(e.x),Vn(e.y),Vn(n.x),Vn(n.y),Vn(r.x),Vn(r.y)).attr(i.lineattr).attr({fill:a,stroke:a})},bondSingleStereoBold:function(t,e,n,r,i,a){var o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"#000",s=t.path("M{0},{1}L{2},{3}L{4},{5}L{6},{7}Z",Vn(e.x),Vn(e.y),Vn(n.x),Vn(n.y),Vn(r.x),Vn(r.y),Vn(i.x),Vn(i.y)).attr(a.lineattr);return s.attr({stroke:o,fill:o}),s},bondDoubleStereoBold:function(t,e,n,r,i){var a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"#000";return t.set([e,t.path("M{0},{1}L{2},{3}",Vn(n.x),Vn(n.y),Vn(r.x),Vn(r.y)).attr(i.lineattr).attr({stroke:a,fill:a})])},bondSingleDown:function(t,e,n,r,i,a){for(var o,s=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"#000",u=e.p,l=e.norm,c=.7*a.stereoBond,d="",h=0;h<r;++h)d+=Wn((o=u.addScaled(n,i*h)).addScaled(l,c*(h+.5)/(r-.5)),o.addScaled(l,-c*(h+.5)/(r-.5)));return t.path(d).attr(a.lineattr).attr({fill:s,stroke:s})},bondSingleEither:function(t,e,n,r,i,a){for(var o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"#000",s=e.p,u=e.norm,l=.7*a.stereoBond,c="M"+Vn(s.x)+","+Vn(s.y),d=s,h=0;h<r;++h)d=s.addScaled(n,i*(h+.5)).addScaled(u,(1&h?-1:1)*l*(h+.5)/(r-.5)),c+="L"+Vn(d.x)+","+Vn(d.y);return t.path(c).attr(a.lineattr).attr({fill:o,stroke:o})},bondDouble:function(t,e,n,r,i,a,o){return t.path(a?"M{0},{1}L{6},{7}M{4},{5}L{2},{3}":"M{0},{1}L{2},{3}M{4},{5}L{6},{7}",Vn(e.x),Vn(e.y),Vn(r.x),Vn(r.y),Vn(n.x),Vn(n.y),Vn(i.x),Vn(i.y)).attr(o.lineattr)},bondSingleOrDouble:function(t,e,n,r,i){for(var a,o=e.p,s=n.p,u=e.norm,l=i.bondSpace/2,c="",d=o,h=1;h<=r;++h)a=_.lc2(o,(r-h)/r,s,h/r),1&h?c+=Wn(d,a):(c+=Wn(d.addScaled(u,l),a.addScaled(u,l)),c+=Wn(d.addScaled(u,-l),a.addScaled(u,-l))),d=a;return t.path(c).attr(i.lineattr)},bondTriple:function(t,e,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"#000",a=e.p,o=n.p,s=e.norm,u=a.addScaled(s,r.bondSpace),l=o.addScaled(s,r.bondSpace),c=a.addScaled(s,-r.bondSpace),d=o.addScaled(s,-r.bondSpace);return t.path(Wn(a,o)+Wn(u,l)+Wn(c,d)).attr(r.lineattr).attr({fill:i,stroke:i})},bondAromatic:function(t,e,n,r){var i=t.path(e[0]).attr(r.lineattr),a=t.path(e[1]).attr(r.lineattr);return null!=n&&(n>0?i:a).attr({"stroke-dasharray":"- "}),t.set([i,a])},bondAny:function(t,e,n,r){var i=e.p,a=n.p;return t.path(Wn(i,a)).attr(r.lineattr).attr({"stroke-dasharray":"- "})},bondHydrogen:function(t,e,n,r){var i=e.p,a=n.p;return t.path(Wn(i,a)).attr(r.lineattr).attr({"stroke-dasharray":".","stroke-linecap":"square"})},bondDative:function(t,e,n,r){var i=e.p,a=n.p;return t.path(Wn(i,a)).attr(r.lineattr).attr({"arrow-end":"block-midium-long"})},reactingCenter:function(t,e,n){for(var r="",i=0;i<e.length/2;++i)r+=Wn(e[2*i],e[2*i+1]);return t.path(r).attr(n.lineattr)},topologyMark:function(t,e,n,r){var i=t.text(e.x,e.y,n).attr({font:r.font,"font-size":r.fontszsub,fill:"#000"}),a=Hn.relBox(i.getBBox());return qn(i,a),i},radicalCap:function(t,e,n){var r=.9*n.lineWidth,i=r,a=2*r;return t.path("M{0},{1}L{2},{3}L{4},{5}",Vn(e.x-i),Vn(e.y+a),Vn(e.x),Vn(e.y),Vn(e.x+i),Vn(e.y+a)).attr({stroke:"#000","stroke-width":.7*n.lineWidth,"stroke-linecap":"square","stroke-linejoin":"miter"})},radicalBullet:function(t,e,n){return t.circle(Vn(e.x),Vn(e.y),n.lineWidth).attr({stroke:null,fill:"#000"})},bracket:function(t,e,n,r,i,a,o){i=i||.25,a=a||1;var s=r.addScaled(n,-.5*a),u=r.addScaled(n,.5*a),l=s.addScaled(e,-i),c=u.addScaled(e,-i);return t.path("M{0},{1}L{2},{3}L{4},{5}L{6},{7}",Vn(l.x),Vn(l.y),Vn(s.x),Vn(s.y),Vn(u.x),Vn(u.y),Vn(c.x),Vn(c.y)).attr(o.sgroupBracketStyle)},selectionRectangle:function(t,e,n,r){return t.rect(Vn(Math.min(e.x,n.x)),Vn(Math.min(e.y,n.y)),Vn(Math.abs(n.x-e.x)),Vn(Math.abs(n.y-e.y))).attr(r.lassoStyle)},selectionPolygon:function(t,e,n){for(var r=e[e.length-1],i="M"+Vn(r.x)+","+Vn(r.y),a=0;a<e.length;++a)i+="L"+Vn(e[a].x)+","+Vn(e[a].y);return t.path(i).attr(n.lassoStyle)},selectionLine:function(t,e,n,r){return t.path(Wn(e,n)).attr(r.lassoStyle)},ellipse:function(t,e,n){var r=_.diff(e[1],e[0]),i=r.x/2,a=r.y/2;return t.ellipse(e[0].x+i,e[0].y+a,Math.abs(i),Math.abs(a))},rectangle:function(t,e,n){return t.rect(Vn(Math.min(e[0].x,e[1].x)),Vn(Math.min(e[0].y,e[1].y)),Vn(Math.abs(e[1].x-e[0].x)),Vn(Math.abs(e[1].y-e[0].y)))},rectangleArrowHighlightAndSelection:function(t,e,n,r,i){var a=e.pos,o=e.height,s=(0,m.Z)(a,2),u=s[0];s[1];var l=u.x+n,c=o||8,d="M".concat(Vn(u.x-5),",").concat(Vn(u.y))+"L".concat(Vn(u.x-5),",").concat(Vn(u.y-c))+"L".concat(Vn(l+5),",").concat(Vn(u.y-c))+"L".concat(Vn(l+5),",").concat(Vn(u.y+(!o&&c)))+"L".concat(Vn(u.x-5),",").concat(Vn(u.y+(!o&&c)),"Z");return k()(d).rotate(r,u.x,u.y).toString()},polyline:function(t,e,n){for(var r=["M",e[0].x,e[0].y],i=1;i<e.length;i++)r.push("L",e[i].x,e[i].y);return t.path(r)},line:function(t,e,n){var r=["M",e[0].x,e[0].y];return r.push("L",e[1].x,e[1].y),t.path(r)}};function Kn(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}!function(t){t.Off="off",t.Hetero="Hetero",t.Terminal="Terminal",t.TerminalAndHetero="Terminal and Hetero",t.On="on"}($n||($n={}));var Jn=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t){var e;return(0,r.Z)(this,o),(e=a.call(this,"atom")).a=t,e.showLabel=!1,e.hydrogenOnTheLeft=!1,e.color="#000000",e.component=-1,e}return(0,i.Z)(o,[{key:"getVBoxObj",value:function(t){return this.visel.boundingBox?Fn.prototype.getVBoxObj.call(this,t):new it(this.a.pp,this.a.pp)}},{key:"drawHover",value:function(t){var e=this.makeHoverPlate(t);return t.ctab.addReObjectPath(Nn.hovering,this.visel,e),e}},{key:"makeHoverPlate",value:function(t){var e=t.paper,n=t.options,r=tt.obj2scaled(this.a.pp,n),i=this.a,a=t.ctab.sgroups,o=t.ctab.molecule.functionalGroups;return ft.isAtomInContractedFunctionalGroup(i,a,o,!0)?null:e.circle(r.x,r.y,n.atomSelectionPlateRadius).attr(n.hoverStyle)}},{key:"makeSelectionPlate",value:function(t,e,n){var r=this.a,i=t.render.ctab.sgroups,a=t.render.ctab.molecule.functionalGroups;if(ft.isAtomInContractedFunctionalGroup(r,i,a,!0))return null;var o=tt.obj2scaled(this.a.pp,t.render.options);return e.circle(o.x,o.y,n.atomSelectionPlateRadius).attr(n.selectionStyle)}},{key:"show",value:function(t,e,n){var r,i=t.molecule.atoms.get(e),a=t.molecule.sgroups,o=t.molecule.functionalGroups,s=t.render,u=tt.obj2scaled(this.a.pp,s.options);if(ft.isAtomInContractedFunctionalGroup(i,a,o,!1)){if(ft.isAttachmentPointAtom(e,t.molecule)){var l,c,d=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Kn(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Kn(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}(a.values());try{for(d.s();!(c=d.n()).done;){var h=c.value;h.atoms.includes(e)&&(l=h.data.name)}}catch(t){d.e(t)}finally{d.f()}var f=s.paper.text(u.x,u.y,l).attr({"font-weight":700,"font-size":14});t.addReObjectPath(Nn.data,this.visel,f,u,!0)}}else{var p,m,g,v,y,b;this.hydrogenOnTheLeft=function(t,e){if(0===e.a.neighbors.length){var n=N.get(e.a.label);return!n||Boolean(n.leftH)}var r=1,i=1,a=0,o=0;return e.a.neighbors.forEach((function(e){var n=t.halfBonds.get(e).dir;n.x<=0?(r=Math.min(r,Math.abs(n.y)),a++):(i=Math.min(i,Math.abs(n.y)),o++)})),r<.51||i<.51?i<r:o>a}(t.molecule,this),this.showLabel=function(t,e,n){var r=e.showHydrogenLabels!==$n.Off&&e.showHydrogenLabels!==$n.Hetero;if(0===n.a.neighbors.length||n.a.neighbors.length<2&&r||e.carbonExplicitly||n.a.alias||0!==n.a.isotope||0!==n.a.radical||0!==n.a.charge||n.a.explicitValence>=0||null!==n.a.atomList||null!==n.a.rglabel||n.a.badConn&&e.showValenceWarnings||"c"!==n.a.label.toLowerCase())return!0;if(2===n.a.neighbors.length){var i=n.a.neighbors[0],a=n.a.neighbors[1],o=t.molecule.halfBonds.get(i),s=t.molecule.halfBonds.get(a),u=t.bonds.get(o.bid),l=t.bonds.get(s.bid);if(u.b.type===l.b.type&&u.b.stereo===q.PATTERN.STEREO.NONE&&l.b.stereo===q.PATTERN.STEREO.NONE&&Math.abs(_.cross(o.dir,s.dir))<.2)return!0}return!1}(t,s.options,this),this.color="black";var w=null;if(this.showLabel&&(b=function(t,e,n,r){var i={};if(i.text=function(t){if(null!==t.atomList)return t.atomList.label();if(t.pseudo)return t.pseudo;if(t.alias)return t.alias;if("R#"===t.label&&null!==t.rglabel){for(var e="",n=0;n<32;n++)t.rglabel&1<<n&&(e+="R"+(n+1).toString());return e}return t.label}(t.a),""===i.text&&(i="R#"),i.text===t.a.label){var a=N.get(i.text);r.atomColoring&&a&&(t.color=C[i.text]||"#000")}return i.path=e.text(n.x,n.y,i.text).attr({font:r.font,"font-size":r.fontsz,fill:t.color,"font-style":t.a.pseudo?"italic":""}),i.rbb=Hn.relBox(i.path.getBBox()),Xn.recenterText(i.path,i.rbb),null!==t.a.atomList&&tr(i.path,i.rbb,(t.hydrogenOnTheLeft?-1:1)*(i.rbb.width-i.rbb.height)/2,0),t.label=i,i}(this,s.paper,u,n),p=.5*n.lineWidth,m=b.rbb.width/2*(n.zoom>1?1:n.zoom),g=-b.rbb.width/2*(n.zoom>1?1:n.zoom),v=Math.floor(this.a.implicitH),y="H"===b.text,t.addReObjectPath(Nn.data,this.visel,b.path,u,!0)),n.showAtomIds){(w={}).text=e.toString();var x=this.hydrogenOnTheLeft?_.lc(u,1,new _({x:-2,y:0,z:0}),6):_.lc(u,1,new _({x:2,y:0,z:0}),6);this.showLabel&&(x=_.lc(x,1,new _({x:1,y:-3,z:0}),6)),w.path=s.paper.text(x.x,x.y,w.text).attr({font:n.font,"font-size":n.fontszsub,fill:"#070"}),w.rbb=Hn.relBox(w.path.getBBox()),Xn.recenterText(w.path,w.rbb),t.addReObjectPath(Nn.indices,this.visel,w.path,u)}if(this.setHover(this.hover,s),this.showLabel&&!this.a.pseudo){var E=null;if(y&&v>0&&(E=function(t,e,n,r){var i=tt.obj2scaled(t.a.pp,e.options),a=e.options,o=.5*a.lineWidth,s={};return s.text=(n+1).toString(),s.path=e.paper.text(i.x,i.y,s.text).attr({font:a.font,"font-size":a.fontszsub,fill:t.color}),s.rbb=Hn.relBox(s.path.getBBox()),Xn.recenterText(s.path,s.rbb),tr(s.path,s.rbb,r+.5*s.rbb.width+o,.2*t.label.rbb.height),s}(this,s,v,m),m+=E.rbb.width+p,t.addReObjectPath(Nn.data,this.visel,E.path,u,!0)),0!==this.a.radical){var O=function(t,e){var n,r=tt.obj2scaled(t.a.pp,e.options),i=e.options,a=e.paper,o={};switch(t.a.radical){case 1:o.path=a.set(),n=1.6*i.lineWidth,o.path.push(Xn.radicalBullet(a,r.add(new _(-n,0)),i),Xn.radicalBullet(a,r.add(new _(n,0)),i)),o.path.attr("fill",t.color);break;case 2:o.path=a.set(),o.path.push(Xn.radicalBullet(a,r,i)),o.path.attr("fill",t.color);break;case 3:o.path=a.set(),n=1.6*i.lineWidth,o.path.push(Xn.radicalCap(a,r.add(new _(-n,0)),i),Xn.radicalCap(a,r.add(new _(n,0)),i)),o.path.attr("stroke",t.color)}o.rbb=Hn.relBox(o.path.getBBox());var s=-.5*(t.label.rbb.height+o.rbb.height);return 3===t.a.radical&&(s-=i.lineWidth/2),tr(o.path,o.rbb,0,s),o}(this,s);t.addReObjectPath(Nn.data,this.visel,O.path,u,!0)}if(0!==this.a.isotope){var A=function(t,e,n){var r=tt.obj2scaled(t.a.pp,e.options),i=e.options,a=.5*i.lineWidth,o={};return o.text=t.a.isotope.toString(),o.path=e.paper.text(r.x,r.y,o.text).attr({font:i.font,"font-size":i.fontszsub,fill:t.color}),o.rbb=Hn.relBox(o.path.getBBox()),Xn.recenterText(o.path,o.rbb),tr(o.path,o.rbb,n-.5*o.rbb.width-a,-.3*t.label.rbb.height),o}(this,s,g);g-=A.rbb.width+p,t.addReObjectPath(Nn.data,this.visel,A.path,u,!0)}if(!y&&!this.a.alias&&v>0&&function(t,e){return t===$n.On||t===$n.Terminal&&e.a.neighbors.length<2||t===$n.Hetero&&"c"!==e.label.text.toLowerCase()||t===$n.TerminalAndHetero&&(e.a.neighbors.length<2||"c"!==e.label.text.toLowerCase())}(n.showHydrogenLabels,this)){var S=function(t,e,n,r){var i=r.hydroIndex,a=t.hydrogenOnTheLeft,o=tt.obj2scaled(t.a.pp,e.options),s=e.options,u=.5*s.lineWidth,l=r.hydrogen;return l.text="H",l.path=e.paper.text(o.x,o.y,l.text).attr({font:s.font,"font-size":s.fontsz,fill:t.color}),l.rbb=Hn.relBox(l.path.getBBox()),Xn.recenterText(l.path,l.rbb),a||(tr(l.path,l.rbb,r.rightMargin+.5*l.rbb.width+u,0),r.rightMargin+=l.rbb.width+u),n>1&&((i={}).text=n.toString(),i.path=e.paper.text(o.x,o.y,i.text).attr({font:s.font,"font-size":s.fontszsub,fill:t.color}),i.rbb=Hn.relBox(i.path.getBBox()),Xn.recenterText(i.path,i.rbb),a||(tr(i.path,i.rbb,r.rightMargin+.5*i.rbb.width*(s.zoom>1?1:s.zoom)+u,.2*t.label.rbb.height),r.rightMargin+=i.rbb.width+u)),a&&(null!=i&&(tr(i.path,i.rbb,r.leftMargin-.5*i.rbb.width-u,.2*t.label.rbb.height),r.leftMargin-=i.rbb.width+u),tr(l.path,l.rbb,r.leftMargin-.5*l.rbb.width*(n>1&&s.zoom<1?s.zoom:1)-u,0),r.leftMargin-=l.rbb.width+u),Object.assign(r,{hydrogen:l,hydroIndex:i})}(this,s,v,{hydrogen:{},hydroIndex:E,rightMargin:m,leftMargin:g}),R=S.hydrogen;E=S.hydroIndex,m=S.rightMargin,g=S.leftMargin,t.addReObjectPath(Nn.data,this.visel,R.path,u,!0),null!=E&&t.addReObjectPath(Nn.data,this.visel,E.path,u,!0)}if(0!==this.a.charge&&n.showCharge){var P=function(t,e,n){var r=tt.obj2scaled(t.a.pp,e.options),i=e.options,a=.5*i.lineWidth,o={text:""},s=Math.abs(t.a.charge);return 1!==s&&(o.text=s.toString()),t.a.charge<0?o.text+="–":o.text+="+",o.path=e.paper.text(r.x,r.y,o.text).attr({font:i.font,"font-size":i.fontszsub,fill:t.color}),o.rbb=Hn.relBox(o.path.getBBox()),Xn.recenterText(o.path,o.rbb),tr(o.path,o.rbb,n+.5*o.rbb.width+a,-.3*t.label.rbb.height),o}(this,s,m);m+=P.rbb.width+p,t.addReObjectPath(Nn.data,this.visel,P.path,u,!0)}if(this.a.explicitValence>=0&&n.showValence){var T=function(t,e,n){var r=tt.obj2scaled(t.a.pp,e.options),i=e.options,a=.5*i.lineWidth,o={};if(o.text={0:"0",1:"I",2:"II",3:"III",4:"IV",5:"V",6:"VI",7:"VII",8:"VIII",9:"IX",10:"X",11:"XI",12:"XII",13:"XIII",14:"XIV"}[t.a.explicitValence],!o.text)throw new Error("invalid valence "+t.a.explicitValence.toString());return o.text="("+o.text+")",o.path=e.paper.text(r.x,r.y,o.text).attr({font:i.font,"font-size":i.fontszsub,fill:t.color}),o.rbb=Hn.relBox(o.path.getBBox()),Xn.recenterText(o.path,o.rbb),tr(o.path,o.rbb,n+.5*o.rbb.width+a,-.3*t.label.rbb.height),o}(this,s,m);m+=T.rbb.width+p,t.addReObjectPath(Nn.data,this.visel,T.path,u,!0)}if(this.a.badConn&&n.showValenceWarnings){var k=function(t,e,n,r){var i=tt.obj2scaled(t.a.pp,e.options),a=.5*e.options.lineWidth,o=Hn.tfx,s={},u=i.y+t.label.rbb.height/2+a;return s.path=e.paper.path("M{0},{1}L{2},{3}",o(i.x+n),o(u),o(i.x+r),o(u)).attr(e.options.lineattr).attr({stroke:"#F00"}),s.rbb=Hn.relBox(s.path.getBBox()),s}(this,s,g,m);t.addReObjectPath(Nn.warnings,this.visel,k.path,u,!0)}w&&tr(w.path,w.rbb,-.5*b.rbb.width-.5*w.rbb.width-p,.3*b.rbb.height)}this.a.attpnt&&function(t,e,n,r){var i,a,o=tt.obj2scaled(t.a.pp,e.options),s=e.options,u=Hn.tfx;for(i=0;i<4;++i){var l="";if(t.a.attpnt&1<<i){for(l.length>0&&(l+=" "),l+="∗",a=0;a<(0===i?0:i+1);++a)l+="'";var c=new _(o),d=o.addScaled(n,.7*s.scale),h=e.paper.text(d.x,d.y,l).attr({font:s.font,"font-size":s.fontsz,fill:t.color}),f=Hn.relBox(h.getBBox());Xn.recenterText(h,f);var p=n.negated();d=d.addScaled(p,Hn.shiftRayBox(d,p,it.fromRelBox(f))+s.lineWidth/2),c=nr(t,c,n,s.lineWidth);var m=n.rotateSC(1,0),g=d.addScaled(m,.05*s.scale).addScaled(p,.09*s.scale),v=d.addScaled(m,-.05*s.scale).addScaled(p,.09*s.scale),y=e.paper.set();y.push(h,e.paper.path("M{0},{1}L{2},{3}M{4},{5}L{2},{3}L{6},{7}",u(c.x),u(c.y),u(d.x),u(d.y),u(g.x),u(g.y),u(v.x),u(v.y)).attr(e.options.lineattr).attr({"stroke-width":s.lineWidth/2})),r(Nn.indices,t.visel,y,o),n=n.rotate(Math.PI/6)}}}(this,s,er(this,t.molecule),t.addReObjectPath.bind(t));var B=this.a.stereoLabel,M=function(t){var e="";if(t.a.aam>0&&(e+=t.a.aam),t.a.invRet>0)if(e.length>0&&(e+=","),1===t.a.invRet)e+="Inv";else{if(2!==t.a.invRet)throw new Error("Invalid value for the invert/retain flag");e+="Ret"}if(t.a.exactChangeFlag>0){if(e.length>0&&(e+=","),1!==t.a.exactChangeFlag)throw new Error("Invalid value for the exact change flag");e+="ext"}return e}(this),Z=this.a.pseudo?"":function(t){var e="";if(0!==t.a.ringBondCount)if(t.a.ringBondCount>0)e+="rb"+t.a.ringBondCount.toString();else if(-1===t.a.ringBondCount)e+="rb0";else{if(-2!==t.a.ringBondCount)throw new Error("Ring bond count invalid");e+="rb*"}if(0!==t.a.substitutionCount)if(e.length>0&&(e+=","),t.a.substitutionCount>0)e+="s"+t.a.substitutionCount.toString();else if(-1===t.a.substitutionCount)e+="s0";else{if(-2!==t.a.substitutionCount)throw new Error("Substitution count invalid");e+="s*"}if(t.a.unsaturatedAtom>0){if(e.length>0&&(e+=","),1!==t.a.unsaturatedAtom)throw new Error("Unsaturated atom invalid value");e+="u"}return t.a.hCount>0&&(e.length>0&&(e+=","),e+="H"+(t.a.hCount-1).toString()),e}(this),I=Number(null===(r=t.atoms.get(e))||void 0===r?void 0:r.a.fragment),L=t.molecule.frags.get(I),D=(function(t,e,n){if(!t)return!1;var r=t.match(/\D+/g)[0];switch(e){case Ln.Off:return!1;case Ln.On:return!0;case Ln.Classic:return!(n!==Y.Mixed&&r!==F.Or);case Ln.IUPAC:return!(n!==Y.Mixed||r===F.Abs);default:return!0}}(B,n.stereoLabelStyle,null==L?void 0:L.enhancedStereoFlag)?"".concat(B,"\n"):"")+(Z.length>0?"".concat(Z,"\n"):"")+(M.length>0?".".concat(M,"."):"");if(D.length>0){var j=N.get(this.a.label),G=s.paper.text(u.x,u.y,D).attr({font:n.font,"font-size":n.fontszsub,fill:n.atomColoring&&j?C[this.a.label]:"#000"});if(B){var H=function(t,e){return e&&t.colorStereogenicCenters!==In.Off&&t.colorStereogenicCenters!==In.BondsOnly?Qn(t,e):"#000"}(s.options,B);G.node.childNodes[0].setAttribute("fill",H);var z=function(t,e){var n=e.match(/\D+/g)[0],r=+e.replace(n,"");return t.autoFadeOfStereoLabels&&n!==F.Abs&&t.colorStereogenicCenters!==In.Off&&t.colorStereogenicCenters!==In.BondsOnly?Math.max(1-(r-1)/10,.3):1}(s.options,B);G.node.childNodes[0].setAttribute("fill-opacity",z)}var U=Hn.relBox(G.getBBox());Xn.recenterText(G,U);for(var V=this.visel,W=3,$=er(this,t.molecule),X=0;X<V.exts.length;++X)W=Math.max(W,Hn.shiftRayBox(u,$,V.exts[X].translate(u)));W+=Hn.shiftRayBox(u,$.negated(),it.fromRelBox(U)),tr(G,U,($=$.scaled(8+W)).x,$.y),t.addReObjectPath(Nn.data,this.visel,G,u,!0)}var K=t.molecule.highlights,J=!1,Q="";if(K.forEach((function(t){var n,r=null===(n=t.atoms)||void 0===n?void 0:n.includes(e);J=J||r,r&&(Q=t.color)})),J){var et={fill:Q,stroke:"none"},nt=tt.obj2scaled(this.a.pp,t.render.options),rt=s.paper.circle(nt.x,nt.y,.8*n.atomSelectionPlateRadius).attr(et);t.addReObjectPath(Nn.hovering,this.visel,rt)}}}}],[{key:"isSelectable",value:function(){return!0}}]),o}(Fn);function Qn(t,e){switch(e.match(/\D+/g)[0]){case F.And:return t.colorOfAndCenters;case F.Or:return t.colorOfOrCenters;case F.Abs:return t.colorOfAbsoluteCenters;default:return"#000"}}function tr(t,e,n,r){t.translateAbs(n,r),e.x+=n,e.y+=r}function er(t,e){var n=[];t.a.neighbors.forEach((function(t){var r=e.halfBonds.get(t);r&&n.push(r.ang)})),n=n.sort((function(t,e){return t-e}));for(var r=[],i=0;i<n.length-1;++i)r.push(n[(i+1)%n.length]-n[i]);r.push(n[0]-n[n.length-1]+2*Math.PI);for(var a=0,o=-Math.PI/2,s=0;s<n.length;++s)r[s]>a&&(a=r[s],o=n[s]+r[s]/2);return new _(Math.cos(o),Math.sin(o))}function nr(t,e,n,r){for(var i=0,a=t.visel,o=0;o<a.exts.length;++o){var s=a.exts[o].translate(e);i=Math.max(i,Hn.shiftRayBox(e,n,s))}return i>0&&(e=e.addScaled(n,i+r)),e}var rr=function(t){(0,l.Z)(s,t);var e,n,o=(e=s,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function s(t){var e;return(0,r.Z)(this,s),e=o.call(this,"bond"),(0,a.Z)((0,g.Z)(e),"neihbid1",-1),(0,a.Z)((0,g.Z)(e),"neihbid2",-1),e.b=t,e.doubleBondShift=0,e}return(0,i.Z)(s,[{key:"drawHover",value:function(t){var e=this.makeHoverPlate(t);return t.ctab.addReObjectPath(Nn.hovering,this.visel,e),e}},{key:"makeHoverPlate",value:function(t){var e=t.options;hr(this,t.ctab,e);var n=this.b,r=t.ctab.sgroups,i=t.ctab.molecule.functionalGroups;if(ft.isBondInContractedFunctionalGroup(n,r,i))return null;var a=tt.obj2scaled(this.b.center,e);return t.paper.circle(a.x,a.y,.8*e.atomSelectionPlateRadius).attr(e.hoverStyle)}},{key:"makeSelectionPlate",value:function(t,e,n){hr(this,t,n);var r=this.b,i=t.render.ctab.sgroups,a=t.render.ctab.molecule.functionalGroups;if(ft.isBondInContractedFunctionalGroup(r,i,a))return null;var o=tt.obj2scaled(this.b.center,n);return e.circle(o.x,o.y,.8*n.atomSelectionPlateRadius).attr(n.selectionStyle)}},{key:"show",value:function(t,e,n){var r=t.render,i=t.molecule,a=t.molecule.bonds.get(e),o=t.molecule.sgroups,s=t.molecule.functionalGroups;if(!a||!ft.isBondInContractedFunctionalGroup(a,o,s)){var u=r.paper,l=void 0!==this.b.hb1?i.halfBonds.get(this.b.hb1):null,c=void 0!==this.b.hb2?i.halfBonds.get(this.b.hb2):null;if(function(t,e,n){var r=[e.b.begin,e.b.end].map((function(e){var r=n.molecule.atoms.get(e),i=ir(r,t,!1,n);return i<0?-1:r.neighbors[i]}));e.boldStereo=r[0]>=0&&r[1]>=0}(e,this,t),hr(this,t,n),function(t,e){var n=t.b.hb1,r=t.b.hb2;if(!n&&0!==n||!r&&0!==r)t.doubleBondShift=pr(e,t);else{var i=e.halfBonds.get(n).loop,a=e.halfBonds.get(r).loop;if(i>=0&&a>=0){var o=e.loops.get(i).dblBonds,s=e.loops.get(a).dblBonds,u=e.loops.get(i).hbs.length,l=e.loops.get(a).hbs.length;t.doubleBondShift=function(t,e,n,r){return 6===t&&6!==e&&(n>1||1===r)?-1:6===e&&6!==t&&(r>1||1===n)?1:e*n>t*r?-1:e*n<t*r?1:e>t?-1:1}(u,l,o,s)}else t.doubleBondShift=i>=0?-1:a>=0?1:pr(e,t)}}(this,i),l&&c){this.path=function(t,e,n,r){var i,a,o=null,s=t.render,u=t.molecule,l=!(null!==(i=t.atoms.get(n.begin))&&void 0!==i&&i.showLabel),c=!(null!==(a=t.atoms.get(r.begin))&&void 0!==a&&a.showLabel);switch(e.b.type){case q.PATTERN.TYPE.SINGLE:switch(e.b.stereo){case q.PATTERN.STEREO.UP:ar(n.bid,e,t),o=e.boldStereo&&e.neihbid1>=0&&e.neihbid2>=0?sr(s,n,r,e,u):function(t,e,n,r,i){var a=e.p,o=n.p,s=e.norm,u=t.options,l=.7*u.stereoBond,c=o.addScaled(s,l),d=o.addScaled(s,-l);if(r.neihbid2>=0){var h=lr(n,r.neihbid2,u.stereoBond,i);c=h[0],d=h[1]}return Xn.bondSingleUp(t.paper,a,c,d,u,or(u,r,i))}(s,n,r,e,u);break;case q.PATTERN.STEREO.DOWN:o=function(t,e,n,r,i){var a=e.p,o=n.p,s=t.options,u=o.sub(a),l=u.length()+.2;u=u.normalized();var c=1.2*s.lineWidth,d=Math.max(Math.floor((l-s.lineWidth)/(s.lineWidth+c)),0)+2,h=l/(d-1);return Xn.bondSingleDown(t.paper,e,u,d,h,s,or(s,r,i))}(s,n,r,e,u);break;case q.PATTERN.STEREO.EITHER:o=function(t,e,n,r,i){var a=e.p,o=n.p,s=t.options,u=o.sub(a),l=u.length();u=u.normalized();var c=.6*s.lineWidth,d=Math.max(Math.floor((l-s.lineWidth)/(s.lineWidth+c)),0)+2,h=l/(d-.5);return Xn.bondSingleEither(t.paper,e,u,d,h,s,or(s,r,i))}(s,n,r,e,u);break;default:o=Xn.bondSingle(s.paper,n,r,s.options,or(s.options,e,u))}break;case q.PATTERN.TYPE.DOUBLE:ar(n.bid,e,t),o=e.b.stereo===q.PATTERN.STEREO.NONE&&e.boldStereo&&e.neihbid1>=0&&e.neihbid2>=0?function(t,e,n,r,i,a,o){var s=e.p,u=n.p,l=e.norm,c=r.doubleBondShift,d=1.5*t.options.stereoBond,h=s.addScaled(l,d*c),f=u.addScaled(l,d*c);c>0?(a&&(h=h.addScaled(e.dir,d*ur(e.rightCos,e.rightSin))),o&&(f=f.addScaled(e.dir,-d*ur(n.leftCos,n.leftSin)))):c<0&&(a&&(h=h.addScaled(e.dir,d*ur(e.leftCos,e.leftSin))),o&&(f=f.addScaled(e.dir,-d*ur(n.rightCos,n.rightSin))));var p=sr(t,e,n,r,i);return Xn.bondDoubleStereoBold(t.paper,p,h,f,t.options,or(t.options,r,i))}(s,n,r,e,u,l,c):function(t,e,n,r,i,a){var o=r.b.stereo===q.PATTERN.STEREO.CIS_TRANS,s=e.p,u=n.p,l=e.norm,c=o?0:r.doubleBondShift,d=t.options,h=d.bondSpace/2,f=h+c*h,p=c*h-h,m=s.addScaled(l,f),g=u.addScaled(l,f),v=s.addScaled(l,p),y=u.addScaled(l,p);return c>0?(i&&(m=m.addScaled(e.dir,d.bondSpace*ur(e.rightCos,e.rightSin))),a&&(g=g.addScaled(e.dir,-d.bondSpace*ur(n.leftCos,n.leftSin)))):c<0&&(i&&(v=v.addScaled(e.dir,d.bondSpace*ur(e.leftCos,e.leftSin))),a&&(y=y.addScaled(e.dir,-d.bondSpace*ur(n.rightCos,n.rightSin)))),Xn.bondDouble(t.paper,m,v,g,y,o,d)}(s,n,r,e,l,c);break;case q.PATTERN.TYPE.TRIPLE:o=Xn.bondTriple(s.paper,n,r,s.options);break;case q.PATTERN.TYPE.AROMATIC:var d,h;o=n.loop>=0&&(null===(d=u.loops.get(n.loop))||void 0===d?void 0:d.aromatic)||r.loop>=0&&(null===(h=u.loops.get(r.loop))||void 0===h?void 0:h.aromatic)?Xn.bondSingle(s.paper,n,r,s.options):cr(s,n,r,e,l,c);break;case q.PATTERN.TYPE.SINGLE_OR_DOUBLE:o=function(t,e,n){var r=e.p,i=n.p,a=t.options,o=_.dist(r,i)/Number((a.bondSpace+a.lineWidth).toFixed());return 1&o||(o+=1),Xn.bondSingleOrDouble(t.paper,e,n,o,a)}(s,n,r);break;case q.PATTERN.TYPE.SINGLE_OR_AROMATIC:case q.PATTERN.TYPE.DOUBLE_OR_AROMATIC:o=cr(s,n,r,e,l,c);break;case q.PATTERN.TYPE.ANY:o=Xn.bondAny(s.paper,n,r,s.options);break;case q.PATTERN.TYPE.HYDROGEN:o=Xn.bondHydrogen(s.paper,n,r,s.options);break;case q.PATTERN.TYPE.DATIVE:o=Xn.bondDative(s.paper,n,r,s.options);break;default:throw new Error("Bond type "+e.b.type+" not supported")}return o}(t,this,l,c),this.rbb=Hn.relBox(this.path.getBBox()),t.addReObjectPath(Nn.data,this.visel,this.path,null,!0);var d={};d.path=function(t,e,n,r){var i=n.p,a=r.p,o=a.add(i).scaled(.5),s=a.sub(i).normalized(),u=s.rotateSC(1,0),l=[],c=t.options.lineWidth,d=t.options.bondSpace/2,h=c,f=2*c,p=1.5*d,m=1.5*d,g=3*d,v=.2;switch(e.b.reactingCenterStatus){case q.PATTERN.REACTING_CENTER.NOT_CENTER:l.push(o.addScaled(u,g).addScaled(s,v*g)),l.push(o.addScaled(u,-g).addScaled(s,-.2*g)),l.push(o.addScaled(u,g).addScaled(s,-.2*g)),l.push(o.addScaled(u,-g).addScaled(s,v*g));break;case q.PATTERN.REACTING_CENTER.CENTER:l.push(o.addScaled(u,g).addScaled(s,v*g).addScaled(s,h)),l.push(o.addScaled(u,-g).addScaled(s,-.2*g).addScaled(s,h)),l.push(o.addScaled(u,g).addScaled(s,v*g).addScaled(s,-h)),l.push(o.addScaled(u,-g).addScaled(s,-.2*g).addScaled(s,-h)),l.push(o.addScaled(s,p).addScaled(u,m)),l.push(o.addScaled(s,-p).addScaled(u,m)),l.push(o.addScaled(s,p).addScaled(u,-m)),l.push(o.addScaled(s,-p).addScaled(u,-m));break;case q.PATTERN.REACTING_CENTER.MADE_OR_BROKEN:l.push(o.addScaled(u,g).addScaled(s,f)),l.push(o.addScaled(u,-g).addScaled(s,f)),l.push(o.addScaled(u,g).addScaled(s,-f)),l.push(o.addScaled(u,-g).addScaled(s,-f));break;case q.PATTERN.REACTING_CENTER.ORDER_CHANGED:l.push(o.addScaled(u,g)),l.push(o.addScaled(u,-g));break;case q.PATTERN.REACTING_CENTER.MADE_OR_BROKEN_AND_CHANGED:l.push(o.addScaled(u,g).addScaled(s,f)),l.push(o.addScaled(u,-g).addScaled(s,f)),l.push(o.addScaled(u,g).addScaled(s,-f)),l.push(o.addScaled(u,-g).addScaled(s,-f)),l.push(o.addScaled(u,g)),l.push(o.addScaled(u,-g));break;default:return null}return Xn.reactingCenter(t.paper,l,t.options)}(r,this,l,c),d.path&&(d.rbb=Hn.relBox(d.path.getBBox()),t.addReObjectPath(Nn.data,this.visel,d.path,null,!0));var h={};h.path=function(t,e,n,r){var i=t.options,a=null;if(e.b.topology===q.PATTERN.TOPOLOGY.RING)a="rng";else{if(e.b.topology!==q.PATTERN.TOPOLOGY.CHAIN)return null;a="chn"}var o=n.p,s=r.p,u=s.add(o).scaled(.5),l=s.sub(o).normalized().rotateSC(1,0),c=i.lineWidth;e.doubleBondShift>0?l=l.scaled(-e.doubleBondShift):0===e.doubleBondShift&&(c+=i.bondSpace/2);var d=new _(2,1).scaled(i.bondSpace);e.b.type===q.PATTERN.TYPE.TRIPLE&&(c+=i.bondSpace);var h=u.add(new _(l.x*(d.x+c),l.y*(d.y+c)));return Xn.topologyMark(t.paper,h,a,i)}(r,this,l,c),h.path&&(h.rbb=Hn.relBox(h.path.getBBox()),t.addReObjectPath(Nn.data,this.visel,h.path,null,!0)),this.setHover(this.hover,r);var f=null,p=.6*n.subFontSize;n.showBondIds&&(f=dr(e,u,l,c,p,.5,.5,l.norm),t.addReObjectPath(Nn.indices,this.visel,f)),n.showHalfBondIds&&(f=dr(this.b.hb1,u,l,c,p,.8,.2,l.norm),t.addReObjectPath(Nn.indices,this.visel,f),f=dr(this.b.hb2,u,l,c,p,.2,.8,c.norm),t.addReObjectPath(Nn.indices,this.visel,f)),n.showLoopIds&&!n.showBondIds&&(f=dr(l.loop,u,l,c,p,.5,.5,c.norm),t.addReObjectPath(Nn.indices,this.visel,f),f=dr(c.loop,u,l,c,p,.5,.5,l.norm),t.addReObjectPath(Nn.indices,this.visel,f));var m=t.molecule.highlights,g=!1,v="";if(m.forEach((function(t){var n,r=null===(n=t.bonds)||void 0===n?void 0:n.includes(e);g=g||r,r&&(v=t.color)})),g){var y={fill:v,stroke:v,"stroke-width":7*n.lineattr["stroke-width"],"stroke-linecap":"round"},b=tt.obj2scaled(this.b.center,t.render.options),w=function(t,e,n){var r={x:e.p.x,y:e.p.y},i={x:n.p.x,y:n.p.y},a=t.render.paper,o="M".concat(r.x,",").concat(r.y," L").concat(i.x,",").concat(i.y);return a.path(o)}(t,l,c);w.attr(y),t.addReObjectPath(Nn.hovering,this.visel,w,b,!0)}}}}}],[{key:"isSelectable",value:function(){return!0}}]),s}(Fn);function ir(t,e,n,r){return t.neighbors.findIndex((function(t){var i=r.molecule.halfBonds.get(t);if(!i||i.bid===e)return!1;var a=r.bonds.get(i.bid);return!!a&&(a.b.type===q.PATTERN.TYPE.SINGLE&&a.b.stereo===q.PATTERN.STEREO.UP?a.b.end===i.begin||a.boldStereo&&n:!(a.b.type!==q.PATTERN.TYPE.DOUBLE||a.b.stereo!==q.PATTERN.STEREO.NONE||!n||!a.boldStereo))}))}function ar(t,e,n){var r,i,a=[e.b.begin,e.b.end].map((function(e){var r=n.molecule.atoms.get(e);if(!r)return-1;var i=ir(r,t,!0,n);return i<0?-1:r.neighbors[i]}));e.neihbid1=null!==(r=n.atoms.get(e.b.begin))&&void 0!==r&&r.showLabel?-1:a[0],e.neihbid2=null!==(i=n.atoms.get(e.b.end))&&void 0!==i&&i.showLabel?-1:a[1]}function or(t,e,n){var r,i,a="#000";if(0===e.b.stereo)return a;var o=null===(r=n.atoms.get(e.b.begin))||void 0===r?void 0:r.stereoLabel,s=null===(i=n.atoms.get(e.b.end))||void 0===i?void 0:i.stereoLabel,u="";return o&&!s?u=o:!o&&s&&(u=s),u&&t.colorStereogenicCenters!==In.Off&&t.colorStereogenicCenters!==In.LabelsOnly?Qn(t,u):a}function sr(t,e,n,r,i){var a=t.options,o=lr(e,r.neihbid1,a.stereoBond,i),s=lr(n,r.neihbid2,a.stereoBond,i),u=o[0],l=o[1],c=s[0],d=s[1];return Xn.bondSingleStereoBold(t.paper,u,l,c,d,a,or(a,r,i))}function ur(t,e){return e<0||Math.abs(t)>.9?0:e/(1-t)}function lr(t,e,n,r){var i=r.halfBonds.get(e),a=_.dot(t.dir,i.dir),o=_.cross(t.dir,i.dir),s=Math.sqrt(.5*(1-a)),u=i.dir.rotateSC((o>=0?-1:1)*s,Math.sqrt(.5*(1+a))),l=t.p.addScaled(u,.7*n/(s+.3)),c=t.p.addScaled(u.negated(),.7*n/(s+.3));return o>0?[l,c]:[c,l]}function cr(t,e,n,r,i,a){var o=[.125,.125,.005,.125],s=null,u=null,l=t.options,c=r.doubleBondShift;r.b.type===q.PATTERN.TYPE.SINGLE_OR_AROMATIC&&(s=c>0?1:2,u=o.map((function(t){return t*l.scale}))),r.b.type===q.PATTERN.TYPE.DOUBLE_OR_AROMATIC&&(s=3,u=o.map((function(t){return t*l.scale})));var d=function(t,e,n,r,i,a,o,s){var u=t.p,l=e.p,c=t.norm,d=a/2,h=d+n*d,f=n*d-d,p=u.addScaled(c,h),m=l.addScaled(c,h),g=u.addScaled(c,f),v=l.addScaled(c,f);return n>0?(r&&(p=p.addScaled(t.dir,a*ur(t.rightCos,t.rightSin))),i&&(m=m.addScaled(t.dir,-a*ur(e.leftCos,e.leftSin)))):n<0&&(r&&(g=g.addScaled(t.dir,a*ur(t.leftCos,t.leftSin))),i&&(v=v.addScaled(t.dir,-a*ur(e.rightCos,e.rightSin)))),Xn.aromaticBondPaths(p,g,m,v,o,s)}(e,n,c,i,a,l.bondSpace,s,u);return Xn.bondAromatic(t.paper,d,c,l)}function dr(t,e,n,r,i,a,o,s){var u=_.lc(n.p,a,r.p,o,s,i),l=e.text(u.x,u.y,t.toString()),c=Hn.relBox(l.getBBox());return Xn.recenterText(l,c),l}function hr(t,e,n){var r=e.render,i=e.atoms.get(t.b.begin),a=e.atoms.get(t.b.end);if(i&&a&&void 0!==t.b.hb1&&void 0!==t.b.hb2){var o=tt.obj2scaled(i.a.pp,r.options),s=tt.obj2scaled(a.a.pp,r.options),u=e.molecule.halfBonds.get(t.b.hb1),l=e.molecule.halfBonds.get(t.b.hb2);null!=u&&u.dir&&null!=l&&l.dir&&(u.p=fr(i,o,u.dir,2*n.lineWidth),l.p=fr(a,s,l.dir,2*n.lineWidth),t.b.center=_.lc2(i.a.pp,.5,a.a.pp,.5),t.b.len=_.dist(o,s),t.b.sb=5*n.lineWidth,t.b.sa=Math.max(t.b.sb,t.b.len/2-2*n.lineWidth),t.b.angle=180*Math.atan2(u.dir.y,u.dir.x)/Math.PI)}}function fr(t,e,n,r){for(var i=0,a=t.visel,o=0;o<a.exts.length;++o){var s=a.exts[o].translate(e);i=Math.max(i,Hn.shiftRayBox(e,n,s))}return i>0&&(e=e.addScaled(n,i+r)),e}function pr(t,e){if(!e.b.hb1&&0!==e.b.hb1||!e.b.hb2&&0!==e.b.hb2)return 0;var n=t.halfBonds.get(e.b.hb1),r=t.halfBonds.get(e.b.hb2);if(!n||!r)return 0;var i=(n.leftSin>.3?1:0)+(r.rightSin>.3?1:0),a=(r.leftSin>.3?1:0)+(n.rightSin>.3?1:0);return i>a?-1:i<a||(n.leftSin>.3?1:0)+(n.rightSin>.3?1:0)==1?1:0}var mr=new WeakMap,gr=function(t){(0,l.Z)(s,t);var e,n,o=(e=s,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function s(){var t,e,n,i;return(0,r.Z)(this,s),t=o.call(this,"enhancedFlag"),e=(0,g.Z)(t),i={writable:!0,value:void 0},function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,n=mr),n.set(e,i),t}return(0,i.Z)(s,[{key:"hoverPath",value:function(t){var e=it.fromRelBox((0,p.Z)(this,mr).getBBox()),n=e.p1.sub(e.p0),r=e.p0.sub(t.options.offset);return t.paper.rect(r.x,r.y,n.x,n.y)}},{key:"drawHover",value:function(t){var e;if(null===(e=(0,p.Z)(this,mr))||void 0===e||!e.attrs)return null;var n=this.hoverPath(t).attr(t.options.hoverStyle);return t.ctab.addReObjectPath(Nn.hovering,this.visel,n),n}},{key:"makeSelectionPlate",value:function(t,e,n){var r;return null!==(r=(0,p.Z)(this,mr))&&void 0!==r&&r.attrs?this.hoverPath(t.render).attr(n.selectionStyle):null}},{key:"show",value:function(t,e,n){var r,i=t.render,o=t.molecule.frags.get(e);if(null!=o&&o.enhancedStereoFlag){var s=o.stereoFlagPosition?o.stereoFlagPosition:Q.getDefaultStereoFlagPosition(t.molecule,e),u=i.paper,l=tt.obj2scaled(s,n),c=(r={},(0,a.Z)(r,Y.Abs,n.absFlagLabel),(0,a.Z)(r,Y.And,n.andFlagLabel),(0,a.Z)(r,Y.Mixed,n.mixedFlagLabel),(0,a.Z)(r,Y.Or,n.orFlagLabel),r);n.showStereoFlags&&(0,f.Z)(this,mr,u.text(l.x,l.y,o.enhancedStereoFlag?c[o.enhancedStereoFlag]:"").attr({font:n.font,"font-size":n.fontsz,fill:"#000"})),i.ctab.addReObjectPath(Nn.data,this.visel,(0,p.Z)(this,mr),null,!0)}}}],[{key:"isSelectable",value:function(){return!0}}]),s}(Fn);var vr=function(t){(0,l.Z)(s,t);var e,a,o=(e=s,a=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,n=(0,d.Z)(e);if(a){var r=(0,d.Z)(this).constructor;t=Reflect.construct(n,arguments,r)}else t=n.apply(this,arguments);return(0,c.Z)(this,t)});function s(t){var e;return(0,r.Z)(this,s),(e=o.call(this,"frag")).item=t,e}return(0,i.Z)(s,[{key:"fragGetAtoms",value:function(t,e){return Array.from(t.atoms.keys()).filter((function(n){return t.atoms.get(n).a.fragment===e}))}},{key:"fragGetBonds",value:function(t,e){return Array.from(t.bonds.keys()).filter((function(n){var r=t.bonds.get(n).b,i=t.atoms.get(r.begin).a.fragment,a=t.atoms.get(r.end).a.fragment;return i===e&&a===e}))}},{key:"calcBBox",value:function(t,e,r){var i;return t.atoms.forEach((function(t){if(t.a.fragment===e){var a=t.visel.boundingBox;if(a)r||(r=n.g._ui_editor.render),a=a.translate((r.options.offset||new _).negated()).transform(tt.scaled2obj,r.options);else{a=new it(t.a.pp,t.a.pp);var o=new _(.05*3,.05*3);a=a.extend(o,o)}i=i?it.union(i,a):a}})),i}},{key:"_draw",value:function(t,e,n){var r=this.calcBBox(t.ctab,e,t);if(r){var i=tt.obj2scaled(new _(r.p0.x,r.p0.y),t.options),a=tt.obj2scaled(new _(r.p1.x,r.p1.y),t.options);return t.paper.rect(i.x,i.y,a.x-i.x,a.y-i.y,0).attr(n)}}},{key:"draw",value:function(t){return null}},{key:"drawHover",value:function(t){}},{key:"setHover",value:function(t,e){var n=e.ctab.frags.keyOf(this);(n||0===n)&&(n=parseInt(n,10),e.ctab.atoms.forEach((function(r){r.a.fragment===n&&r.setHover(t,e)})),e.ctab.bonds.forEach((function(r){e.ctab.atoms.get(r.b.begin).a.fragment===n&&r.setHover(t,e)})))}}],[{key:"isSelectable",value:function(){return!1}}]),s}(Fn);var yr=new _(.05*3,.05*3),br=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t){var e;return(0,r.Z)(this,o),(e=a.call(this,"rgroup")).labelBox=null,e.item=t,e}return(0,i.Z)(o,[{key:"getAtoms",value:function(t){var e=[];return this.item.frags.forEach((function(n){e=e.concat(t.ctab.frags.get(n).fragGetAtoms(t.ctab,n))})),e}},{key:"getBonds",value:function(t){var e=[];return this.item.frags.forEach((function(n){e=e.concat(t.ctab.frags.get(n).fragGetBonds(t.ctab,n))})),e}},{key:"calcBBox",value:function(t){var e=null;return this.item.frags.forEach((function(n){var r=t.ctab.frags.get(n).calcBBox(t.ctab,n,t);r&&(e=e?it.union(e,r):r)})),e&&(e=e.extend(yr,yr)),e}},{key:"draw",value:function(t,e){var n=this.calcBBox(t);if(!n)return{};var r={data:[]},i=tt.obj2scaled(n.p0,e),a=tt.obj2scaled(n.p1,e),o=t.paper.set();(function(t,e,n,r){r=tt.obj2scaled(r||new _(1,0),e.options);var i=Math.min(.25,.3*n.sz().x),a=n.p1.y-n.p0.y,o=.5*(n.p1.y+n.p0.y),s=Xn.bracket(e.paper,r.negated(),r.negated().rotateSC(1,0),tt.obj2scaled(new _(n.p0.x,o),e.options),i,a,e.options),u=Xn.bracket(e.paper,r,r.rotateSC(1,0),tt.obj2scaled(new _(n.p1.x,o),e.options),i,a,e.options);t.push(s,u)})(o,t,n),r.data.push(o);var s=t.ctab.rgroups.keyOf(this),u=t.paper.set(),l=t.paper.text(i.x,(i.y+a.y)/2,"R"+s+"=").attr({font:e.font,"font-size":e.fontRLabel,fill:"black"}),c=Hn.relBox(l.getBBox());l.translateAbs(-c.width/2-e.lineWidth,0),u.push(l);for(var d={font:e.font,"font-size":e.fontRLogic,fill:"black"},h=[wr(s,this.item)],f=c.height/2+e.lineWidth/2,p=0;p<h.length;++p){var m=t.paper.text(i.x,(i.y+a.y)/2,h[p]).attr(d),g=Hn.relBox(m.getBBox());f+=g.height/2,m.translateAbs(-g.width/2-6*e.lineWidth,f),f+=g.height/2+e.lineWidth/2,r.data.push(m),u.push(m)}return r.data.push(l),this.labelBox=it.fromRelBox(u.getBBox()).transform(tt.scaled2obj,t.options),r}},{key:"_draw",value:function(t,e,n){if(!this.getVBoxObj(t))return null;var r=this.getVBoxObj(t).extend(yr,yr);if(!r)return null;var i=tt.obj2scaled(r.p0,t.options),a=tt.obj2scaled(r.p1,t.options);return t.paper.rect(i.x,i.y,a.x-i.x,a.y-i.y,0).attr(n)}},{key:"drawHover",value:function(t){var e=t.ctab.rgroups.keyOf(this);if(!e)return null;var n=this._draw(t,e,t.options.hoverStyle);return t.ctab.addReObjectPath(Nn.hovering,this.visel,n),this.item.frags.forEach((function(e,n){t.ctab.frags.get(n).drawHover(t)})),n}},{key:"show",value:function(t,e,n){var r=this,i=this.draw(t.render,n);Object.keys(i).forEach((function(e){for(;i[e].length>0;)t.addReObjectPath(Nn.data,r.visel,i[e].shift(),null,!0)}))}}],[{key:"isSelectable",value:function(){return!1}}]),o}(Fn);function wr(t,e){var n,r=e.ifthen>0?"IF ":"",i=e.range.startsWith(">")||e.range.startsWith("<")||e.range.startsWith("=");n=e.range.length>0?i?e.range:"="+e.range:">0";var a=e.resth?" (RestH)":"",o=e.ifthen>0?"\nTHEN R"+e.ifthen.toString():"";return"".concat(r,"R").concat(t.toString()).concat(n).concat(a).concat(o)}function xr(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Er(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?xr(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):xr(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var Or=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t){var e;return(0,r.Z)(this,o),(e=a.call(this,"rxnArrow")).item=t,e}return(0,i.Z)(o,[{key:"calcDistance",value:function(t,e){var n=new _(t.x,t.y),r=this.getReferencePointDistance(t),i=this.item,a=Ar(i.pos,n);if(yt.isElliptical(i)){var o=this.getReferencePoints(),s=(0,m.Z)(o,3),u=s[0],l=s[1],c=s[2];a=Math.min(a,Ar([u,c],n),Ar([c,l],n))}var d=r.minDist<=8/e?r.refPoint:null;return{minDist:a=Math.min(r.minDist,a),refPoint:d}}},{key:"getReferencePointDistance",value:function(t){var e=[];return this.getReferencePoints().forEach((function(n){e.push({minDist:Math.abs(_.dist(t,n)),refPoint:n})})),e.reduce((function(t,e){return t&&t.minDist<e.minDist?t:e}),null)}},{key:"hoverPath",value:function(t){var e=this.generatePath(t,t.options,"selection");return t.paper.path(e)}},{key:"drawHover",value:function(t){var e=this.hoverPath(t).attr(t.options.hoverStyle);return t.ctab.addReObjectPath(Nn.hovering,this.visel,e),e}},{key:"getReferencePoints",value:function(){var t=[],e=this.item,n=(0,m.Z)(e.pos,2),r=n[0],i=n[1],a=e.height;if(t.push(new _(r.x,r.y)),t.push(new _(i.x,i.y)),yt.isElliptical(e)){var o=function(t,e,n){if(0==+Hn.tfx(t)){var r=Math.min(e.x,n.x),i=Math.min(e.y,n.y),a=r+Math.abs(e.x-n.x)/2,o=i+Math.abs(e.y-n.y)/2;return new _(a,o)}var s=Math.hypot(n.x-e.x,n.y-e.y),u=Math.hypot(s/2,t),l=Hn.calcCoordinates(e,n,u).pos1,c=Hn.calcCoordinates(e,n,u).pos2;if(t>0){if(n.x<e.x)return new _(null==l?void 0:l.x,null==l?void 0:l.y);if(n.x>e.x)return new _(null==c?void 0:c.x,null==c?void 0:c.y);if(n.x===e.x){if(n.y>e.y)return new _(null==c?void 0:c.x,null==c?void 0:c.y);if(n.y<e.y)return new _(null==l?void 0:l.x,null==l?void 0:l.y);if(n.y===e.y)return new _(e.x,e.y)}}else{if(n.x>e.x)return new _(null==l?void 0:l.x,null==l?void 0:l.y);if(n.x<e.x)return new _(null==c?void 0:c.x,null==c?void 0:c.y);if(n.x===e.x){if(n.y>e.y)return new _(null==l?void 0:l.x,null==l?void 0:l.y);if(n.y<e.y)return new _(null==c?void 0:c.x,null==c?void 0:c.y);if(n.y===e.y)return new _(e.x,e.y)}}return new _(e.x,e.y)}(a,r,i);t.push(o)}return t}},{key:"makeSelectionPlate",value:function(t,e,n){var r=t.render,i=t.render.options,a=this.getReferencePoints(),o=i.scale,s=t.render.paper.set();return s.push(r.paper.path(this.generatePath(r,i,"selection")).attr(n.selectionStyle)),a.forEach((function(e){var n=tt.obj2scaled(e,t.render.options);s.push(t.render.paper.circle(n.x,n.y,o/8).attr({fill:"black"}))})),s}},{key:"generatePath",value:function(t,e,n){var r,i=this.item,a=yt.isElliptical(i)&&i.height*e.scale,o=i.pos.map((function(t){return tt.obj2scaled(t,e)||new _})),s=this.getArrowParams(o[0].x,o[0].y,o[1].x,o[1].y),u=s.length,l=s.angle;switch(n){case"selection":r=Xn.rectangleArrowHighlightAndSelection(t.paper,{pos:o,height:a},u,l,e);break;case"arrow":r=Xn.arrow(t.paper,Er(Er({},i),{},{pos:o,height:a}),u,l,e)}return r}},{key:"getArrowParams",value:function(t,e,n,r){return{length:Math.hypot(n-t,r-e),angle:P().angle(t,e,n,r)-180}}},{key:"show",value:function(t,e,n){var r=this.generatePath(t.render,n,"arrow"),i=n.offset;null!=i&&r.translateAbs(i.x,i.y),this.visel.add(r,it.fromRelBox(Hn.relBox(r.getBBox())))}}],[{key:"isSelectable",value:function(){return!0}}]),o}(Fn);function Ar(t,e){var n;if((e.x<Math.min(t[0].x,t[1].x)||e.x>Math.max(t[0].x,t[1].x))&&(e.y<Math.min(t[0].y,t[1].y)||e.y>Math.max(t[0].y,t[1].y)))n=Math.min(_.dist(t[0],e),_.dist(t[1],e));else{var r=_.dist(t[0],t[1]),i=_.dist(t[0],e),a=_.dist(t[1],e),o=(r+i+a)/2;n=2/r*Math.sqrt(o*(o-r)*(o-i)*(o-a))}return n}var Sr=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t){var e;return(0,r.Z)(this,o),(e=a.call(this,"rxnPlus")).item=t,e}return(0,i.Z)(o,[{key:"hoverPath",value:function(t){var e=tt.obj2scaled(this.item.pp,t.options),n=t.options.scale;return t.paper.rect(e.x-n/4,e.y-n/4,n/2,n/2,n/8)}},{key:"drawHover",value:function(t){var e=this.hoverPath(t).attr(t.options.hoverStyle);return t.ctab.addReObjectPath(Nn.hovering,this.visel,e),e}},{key:"makeSelectionPlate",value:function(t,e,n){return this.hoverPath(t.render).attr(n.selectionStyle)}},{key:"show",value:function(t,e,n){var r=t.render,i=tt.obj2scaled(this.item.pp,n),a=Xn.plus(r.paper,i,n),o=n.offset;null!=o&&a.translateAbs(o.x,o.y),this.visel.add(a,it.fromRelBox(Hn.relBox(a.getBBox())))}}],[{key:"isSelectable",value:function(){return!0}}]),o}(Fn);var Rr=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t){var e;return(0,r.Z)(this,o),(e=a.call(this,"sgroupData")).sgroup=t,e}return(0,i.Z)(o,[{key:"hoverPath",value:function(t){var e=this.sgroup.dataArea,n=tt.obj2scaled(e.p0,t.options),r=tt.obj2scaled(e.p1,t.options).sub(n);return t.paper.rect(n.x,n.y,r.x,r.y)}},{key:"drawHover",value:function(t){var e=this.hoverPath(t).attr(t.options.hoverStyle);return t.ctab.addReObjectPath(Nn.hovering,this.visel,e),e}},{key:"makeSelectionPlate",value:function(t,e,n){return this.hoverPath(t.render).attr(n.selectionStyle)}}],[{key:"isSelectable",value:function(){return!0}}]),o}(Fn);var Pr=Hn.tfx,Tr=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t){var e;return(0,r.Z)(this,o),(e=a.call(this,"sgroup")).item=t,e}return(0,i.Z)(o,[{key:"draw",value:function(t,e){this.render=t.render;var n=this.render.paper.set(),r=new H(e.atoms),i=st.getCrossBonds(t.molecule,r);st.bracketPos(e,t.molecule,i);var a=e.bracketBox,o=e.bracketDir;e.areas=[a];var s=t.molecule.functionalGroups;if(ft.isContractedFunctionalGroup(e.id,s))e.atoms.forEach((function(n){ft.isAttachmentPointAtom(n,t.molecule)&&(e.firstSgroupAtom=t.molecule.atoms.get(n),e.functionalGroup=!0)}));else switch(e.type){case"MUL":kr(n,this.render,e,i,r,a,o,e.data.mul);break;case"SRU":var u=e.data.connectivity||"eu";"ht"===u&&(u="");var l=e.data.subscript||"n";kr(n,this.render,e,i,r,a,o,l,u);break;case"SUP":kr(n,this.render,e,i,r,a,o,e.data.name,null,{"font-style":"italic"});break;case"GEN":kr(n,this.render,e,i,r,a,o);break;case"DAT":n=function(t,e){return st.bracketPos(e,t.molecule),e.areas=e.bracketBox?[e.bracketBox]:[],null===e.pp&&e.calculatePP(t.molecule),e.data.attached?function(t,e){var n=t.render,r=n.options,i=n.paper,a=i.set();return st.getAtoms(t,e).forEach((function(o){var s=t.atoms.get(o),u=tt.obj2scaled(s.a.pp,r),l=s.visel.boundingBox;null!==l&&(u.x=Math.max(u.x,l.p1.x)),u.x+=r.lineWidth;var c=Br(i,u,e,r),d=Hn.relBox(c.getBBox());c.translateAbs(.5*d.width,-.3*d.height),a.push(c);var h=it.fromRelBox(Hn.relBox(c.getBBox()));h=h.transform(tt.scaled2obj,n.options),e.areas.push(h)})),a}(t,e):function(t,e){var n=t.render,r=n.options,i=n.paper,a=i.set(),o=Br(i,e.pp.scaled(r.scale),e,r),s=Hn.relBox(o.getBBox());o.translateAbs(.5*s.width,-.5*s.height),a.push(o);var u=it.fromRelBox(Hn.relBox(o.getBBox()));return e.dataArea=u.transform(tt.scaled2obj,n.options),t.sgroupData.has(e.id)||t.sgroupData.set(e.id,new Rr(e)),a}(t,e)}(t,e)}return n}},{key:"getTextHighlightDimensions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=0,n=0,r=0,i=0,a=this.item;if(a.functionalGroup&&!a.data.expanded&&a.firstSgroupAtom){var o=a.firstSgroupAtom.pp,s=(0,m.Z)(a.atoms,1)[0],u=this.render.ctab.atoms.get(s),l=u.visel.boundingBox||u.visel.oldBoundingBox;if(l){var c=tt.obj2scaled(o,this.render.options),d=c.x,h=c.y,f=l.p0,p=l.p1;e=d-(r=p.x-f.x+2*t)/2,n=h-(i=p.y-f.y+2*t)/2}}return{startX:e,startY:n,width:r,height:i}}},{key:"makeSelectionPlate",value:function(t,e,n){var r=this.item,i=t.molecule.functionalGroups;if(ft.isContractedFunctionalGroup(r.id,i)){var a=this.getTextHighlightDimensions(this.render.options.fontsz/2),o=a.startX,s=a.startY,u=a.width,l=a.height;return e.rect(o,s,u,l).attr(n.selectionStyle)}}},{key:"drawHover",value:function(t){var e=t.options,n=t.paper,r=this.item,i=function(t,e){var n=t.bracketBox.transform(tt.obj2scaled,e),r=e.lineWidth,i=new _(4*r,6*r);n=n.extend(i,i);var a=t.bracketDir,o=a.rotateSC(1,0),s=_.lc2(a,n.p0.x,o,n.p0.y),u=_.lc2(a,n.p0.x,o,n.p1.y),l=_.lc2(a,n.p1.x,o,n.p0.y),c=_.lc2(a,n.p1.x,o,n.p1.y),d=e.contractedFunctionalGroupSize,h=(l.x+s.x)/2-d/2,f=(u.y+s.y)/2-d/2;if(t.firstSgroupAtom){var p=new _(d/2,d/2,0),m=_.diff(t.firstSgroupAtom.pp.scaled(40),p);h=m.x,f=m.y}return{a0:s,a1:u,b0:l,b1:c,startX:h,startY:f,size:d}}(r,e),a=i.a0,o=i.a1,s=i.b0,u=i.b1,l=t.ctab.molecule.functionalGroups,c=n.set();if(ft.isContractedFunctionalGroup(r.id,l)){var d=this.getTextHighlightDimensions(e.fontsz/2),h=d.startX,f=d.startY,p=d.width,m=d.height;r.hovering=n.rect(h,f,p,m).attr(e.hoverStyle)}else r.hovering=n.path("M{0},{1}L{2},{3}L{4},{5}L{6},{7}L{0},{1}",Pr(a.x),Pr(a.y),Pr(o.x),Pr(o.y),Pr(u.x),Pr(u.y),Pr(s.x),Pr(s.y)).attr(e.hoverStyle);c.push(r.hovering),st.getAtoms(t.ctab.molecule,r).forEach((function(e){c.push(t.ctab.atoms.get(e).makeHoverPlate(t))}),this),st.getBonds(t.ctab.molecule,r).forEach((function(e){c.push(t.ctab.bonds.get(e).makeHoverPlate(t))}),this),t.ctab.addReObjectPath(Nn.hovering,this.visel,c)}},{key:"show",value:function(t){var e=t.render,n=this.item;if("MRV_IMPLICIT_H"!==n.data.fieldName){var r=e.ctab,i=this.draw(r,n);t.addReObjectPath(Nn.data,this.visel,i,null,!0),this.setHover(this.hover,e)}}}],[{key:"isSelectable",value:function(){return!1}}]),o}(Fn);function kr(t,e,n,r,i,a,o,s,u,l){for(var c=function(t,e,n,r,i,a,o){function s(t,e,n,r){this.c=t,this.d=e,this.n=e.rotateSC(1,0),this.w=n,this.h=r}var u=[],l=i.rotateSC(1,0),c=Object.values(e),d=c.flat();return d.length<2?function(){i=i||new _(1,0),l=l||i.rotateSC(1,0);var t=Math.min(.25,.3*r.sz().x),e=_.lc2(i,r.p0.x,l,.5*(r.p0.y+r.p1.y)),n=_.lc2(i,r.p1.x,l,.5*(r.p0.y+r.p1.y)),a=r.sz().y;u.push(new s(e,i.negated(),t,a),new s(n,i,t,a))}():2===d.length&&2===c.length?function(){var e=t.bonds.get(d[0]),n=t.bonds.get(d[1]),r=e.getCenter(t),i=n.getCenter(t),l=-1,c=-1,h=-1,f=-1,p=_.centre(r,i),m=_.diff(i,r).normalized(),g=m.negated(),v=m.rotateSC(1,0),y=v.negated();t.sGroupForest.children.get(o).forEach((function(t){var e=a.ctab.sgroups.get(t).visel.boundingBox;e=e.translate((a.options.offset||new _).negated()).transform(tt.scaled2obj,a.options),l=Math.max(l,Hn.shiftRayBox(r,g,e)),c=Math.max(c,Hn.shiftRayBox(i,m,e)),h=Math.max(h,Hn.shiftRayBox(p,v,e)),f=Math.max(f,Hn.shiftRayBox(p,y,e))}),this),l=Math.max(l+.2,0),c=Math.max(c+.2,0);var b=1.5+(h=Math.max(Math.max(h,f)+.1,0));u.push(new s(r.addScaled(g,l),g,.25,b),new s(i.addScaled(m,c),m,.25,b))}():function(){for(var e=0;e<d.length;++e){var r=t.bonds.get(d[e]),i=r.getCenter(t),a=n.has(r.begin)?r.getDir(t):r.getDir(t).negated();u.push(new s(i,a,.2,1))}}(),u}(e.ctab.molecule,r,i,a,o,e,n.id),d=-1,h=0;h<c.length;++h){var f=c[h],p=Xn.bracket(e.paper,tt.obj2scaled(f.d,e.options),tt.obj2scaled(f.n,e.options),tt.obj2scaled(f.c,e.options),f.w,f.h,e.options);t.push(p),(d<0||c[d].d.x<f.d.x||c[d].d.x===f.d.x&&c[d].d.y>f.d.y)&&(d=h)}var m=c[d];function g(n,r){var i=tt.obj2scaled(m.c.addScaled(m.n,r*m.h),e.options),a=e.paper.text(i.x,i.y,n).attr({font:e.options.font,"font-size":e.options.fontszsub});l&&a.attr(l);var o=it.fromRelBox(Hn.relBox(a.getBBox())),s=Math.max(Hn.shiftRayBox(i,m.d.negated(),o),3)+2;a.translateAbs(s*m.d.x,s*m.d.y),t.push(a)}s&&g(s,.5),u&&g(u,-.5)}function Br(t,e,n,r){var i=t.text(e.x,e.y,n.data.fieldValue).attr({font:r.font,"font-size":r.fontsz}),a=i.getBBox(),o=t.rect(a.x-1,a.y-1,a.width+2,a.height+2,3,3);o=n.selected?o.attr(r.selectionStyle):o.attr({fill:"#fff",stroke:"#fff"});var s=t.set();return s.push(o,i.toFront()),s}var Cr=Hn.tfx,Mr=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t){var e;return(0,r.Z)(this,o),(e=a.call(this,"simpleObject")).item=t,e}return(0,i.Z)(o,[{key:"calcDistance",value:function(t,e){var n,r=new _(t.x,t.y),i=this.getReferencePointDistance(t),a=this.item,o=a.mode,s=a.pos;switch(o){case vt.ellipse:var u=_.diff(s[1],s[0]),l=u.x/2,c=u.y/2,d=_.sum(s[0],new _(l,c)),h=_.diff(r,d);n=0!==l&&0!==c?Math.abs(1-h.x*h.x/(l*l)-h.y*h.y/(c*c)):Zr(s,r);break;case vt.rectangle:var f=Math.min(s[0].x,s[1].x),p=Math.min(s[0].y,s[1].y),m=Math.max(s[0].x,s[1].x),g=Math.max(s[0].y,s[1].y),v=[];r.x>=f&&r.x<=m&&(r.y<p?v.push(p-r.y):r.y>g?v.push(r.y-g):v.push(r.y-p,g-r.y)),r.x<f&&r.y<p&&v.push(_.dist(new _(f,p),r)),r.x>m&&r.y>g&&v.push(_.dist(new _(m,g),r)),r.x<f&&r.y>g&&v.push(_.dist(new _(f,g),r)),r.x>m&&r.y<p&&v.push(_.dist(new _(m,p),r)),r.y>=p&&r.y<=g&&(r.x<f?v.push(f-r.x):r.x>m?v.push(r.x-m):v.push(r.x-f,m-r.x)),n=Math.min.apply(Math,v);break;case vt.line:n=Zr(s,r);break;default:throw new Error("Unsupported shape type")}var y=i.minDist<=8/e?i.refPoint:null;return{minDist:n=Math.min(i.minDist,n),refPoint:y}}},{key:"getReferencePointDistance",value:function(t){var e=[];return this.getReferencePoints().forEach((function(n){e.push({minDist:Math.abs(_.dist(t,n)),refPoint:n})})),e.reduce((function(t,e){return t&&t.minDist<e.minDist?t:e}),null)}},{key:"getReferencePoints",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=[];switch(this.item.mode){case vt.ellipse:case vt.rectangle:var n=new _(Math.min(this.item.pos[0].x,this.item.pos[1].x),Math.min(this.item.pos[0].y,this.item.pos[1].y)),r=Math.abs(_.diff(this.item.pos[0],this.item.pos[1]).x),i=Math.abs(_.diff(this.item.pos[0],this.item.pos[1]).y);e.push(new _(n.x+.5*r,n.y),new _(n.x+r,n.y+.5*i),new _(n.x+.5*r,n.y+i),new _(n.x,n.y+.5*i)),t&&this.item.mode!==vt.rectangle||e.push(n,new _(n.x,n.y+i),new _(n.x+r,n.y+i),new _(n.x+r,n.y));break;case vt.line:this.item.pos.forEach((function(t){return e.push(new _(t.x,t.y,0))}));break;default:throw new Error("Unsupported shape type")}return e}},{key:"hoverPath",value:function(t){var e=[];this.item.pos.forEach((function(n,r){e[r]=tt.obj2scaled(n,t.options)}));var n=t.options.scale,r=[];switch(this.item.mode){case vt.ellipse:var i=_.diff(e[1],e[0]),a=i.x/2,o=i.y/2;r.push(t.paper.ellipse(Cr(e[0].x+a),Cr(e[0].y+o),Cr(Math.abs(a)+n/8),Cr(Math.abs(o)+n/8))),Math.abs(a)-n/8>0&&Math.abs(o)-n/8>0&&r.push(t.paper.ellipse(Cr(e[0].x+a),Cr(e[0].y+o),Cr(Math.abs(a)-n/8),Cr(Math.abs(o)-n/8)));break;case vt.rectangle:r.push(t.paper.rect(Cr(Math.min(e[0].x,e[1].x)-n/8),Cr(Math.min(e[0].y,e[1].y)-n/8),Cr(Math.max(e[0].x,e[1].x)-Math.min(e[0].x,e[1].x)+n/4),Cr(Math.max(e[0].y,e[1].y)-Math.min(e[0].y,e[1].y)+n/4))),Math.max(e[0].x,e[1].x)-Math.min(e[0].x,e[1].x)-n/4>0&&Math.max(e[0].y,e[1].y)-Math.min(e[0].y,e[1].y)-n/4>0&&r.push(t.paper.rect(Cr(Math.min(e[0].x,e[1].x)+n/8),Cr(Math.min(e[0].y,e[1].y)+n/8),Cr(Math.max(e[0].x,e[1].x)-Math.min(e[0].x,e[1].x)-n/4),Cr(Math.max(e[0].y,e[1].y)-Math.min(e[0].y,e[1].y)-n/4)));break;case vt.line:var s=[],u=Math.atan((e[1].y-e[0].y)/(e[1].x-e[0].x)),l={x:0,y:0},c={x:0,y:0},d=e[0].x>e[1].x?-1:1;l.x=e[0].x-d*(n/8*Math.cos(u)),l.y=e[0].y-d*(n/8*Math.sin(u)),c.x=e[1].x+d*(n/8*Math.cos(u)),c.y=e[1].y+d*(n/8*Math.sin(u)),s.push("M",l.x+d*n/8*Math.sin(u),l.y-d*n/8*Math.cos(u)),s.push("L",c.x+d*n/8*Math.sin(u),c.y-d*n/8*Math.cos(u)),s.push("L",c.x-d*n/8*Math.sin(u),c.y+d*n/8*Math.cos(u)),s.push("L",l.x-d*n/8*Math.sin(u),l.y+d*n/8*Math.cos(u)),s.push("L",l.x+d*n/8*Math.sin(u),l.y-d*n/8*Math.cos(u)),r.push(t.paper.path(s));break;default:throw new Error("Unsupported shape type")}return r.map((function(t){return{path:t,stylesApplied:!1}}))}},{key:"drawHover",value:function(t){var e=this.hoverPath(t).map((function(e){return e.stylesApplied?e.path:e.path.attr(t.options.hoverStyle)}));return t.ctab.addReObjectPath(Nn.hovering,this.visel,e),e}},{key:"makeSelectionPlate",value:function(t,e,n){var r=this.item.pos.map((function(e){return tt.obj2scaled(e,t.render.options)||new _})),i=this.getReferencePoints(),a=t.render.options.scale,o=t.render.paper.set();return o.push(Nr(this.item.mode,e,r).attr(n.hoverStyleSimpleObject)),i.forEach((function(e){var n=tt.obj2scaled(e,t.render.options);o.push(t.render.paper.circle(n.x,n.y,a/8).attr({fill:"black"}))})),o}},{key:"show",value:function(t,e){var n=t.render,r=this.item.pos.map((function(t){return tt.obj2scaled(t,e)||new _})),i=Nr(this.item.mode,n.paper,r,e),a=e.offset;null!=a&&i.translateAbs(a.x,a.y),this.visel.add(i,it.fromRelBox(Hn.relBox(i.getBBox())))}}],[{key:"isSelectable",value:function(){return!0}}]),o}(Fn);function Zr(t,e){var n;if((e.x<Math.min(t[0].x,t[1].x)||e.x>Math.max(t[0].x,t[1].x))&&(e.y<Math.min(t[0].y,t[1].y)||e.y>Math.max(t[0].y,t[1].y)))n=Math.min(_.dist(t[0],e),_.dist(t[1],e));else{var r=_.dist(t[0],t[1]),i=_.dist(t[0],e),a=_.dist(t[1],e),o=(r+i+a)/2;n=2/r*Math.sqrt(o*(o-r)*(o-i)*(o-a))}return n}function Nr(t,e,n,r){var i;switch(t){case vt.ellipse:i=Xn.ellipse(e,n,r);break;case vt.rectangle:i=Xn.rectangle(e,n,r);break;case vt.line:i=Xn.line(e,n,r);break;default:throw new Error("Unsupported shape type")}return i}var Ir=Hn.tfx,Lr=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t){var e;return(0,r.Z)(this,o),(e=a.call(this,"loop")).loop=t,e.centre=new _,e.radius=new _,e}return(0,i.Z)(o,[{key:"show",value:function(t,e,n){var r=this,i=t.render.paper,a=t.molecule,o=this.loop;this.centre=new _,o.hbs.forEach((function(e){var i=a.halfBonds.get(e),s=t.bonds.get(i.bid),u=tt.obj2scaled(t.atoms.get(i.begin).a.pp,n);s.b.type!==q.PATTERN.TYPE.AROMATIC&&(o.aromatic=!1),r.centre.add_(u)})),o.convex=!0;for(var s=0;s<this.loop.hbs.length;++s){var u=a.halfBonds.get(o.hbs[s]),l=a.halfBonds.get(o.hbs[(s+1)%o.hbs.length]);Math.atan2(_.cross(u.dir,l.dir),_.dot(u.dir,l.dir))>0&&(o.convex=!1)}if(this.centre=this.centre.scaled(1/o.hbs.length),this.radius=-1,o.hbs.forEach((function(e){var i=a.halfBonds.get(e),o=tt.obj2scaled(t.atoms.get(i.begin).a.pp,n),s=tt.obj2scaled(t.atoms.get(i.end).a.pp,n),u=_.diff(s,o).rotateSC(1,0).normalized(),l=_.dot(_.diff(o,r.centre),u);r.radius=r.radius<0?l:Math.min(r.radius,l)})),this.radius*=.7,o.aromatic){var c=null;if(o.convex&&n.aromaticCircle)c=i.circle(this.centre.x,this.centre.y,this.radius).attr({stroke:"#000","stroke-width":n.lineattr["stroke-width"]});else{for(var d="",h=0;h<o.hbs.length;++h){var f=a.halfBonds.get(o.hbs[h]),p=a.halfBonds.get(o.hbs[(h+1)%o.hbs.length]),m=Math.atan2(_.cross(f.dir,p.dir),_.dot(f.dir,p.dir)),g=(Math.PI-m)/2,v=p.dir.rotate(g),y=tt.obj2scaled(t.atoms.get(p.begin).a.pp,n),b=Math.sin(g);Math.abs(b)<.1&&(b=.1*b/Math.abs(b));var w=n.bondSpace/b,x=y.addScaled(v,-w);d+=0===h?"M":"L",d+=Ir(x.x)+","+Ir(x.y)}d+="Z",c=i.path(d).attr({stroke:"#000","stroke-width":n.lineattr["stroke-width"],"stroke-dasharray":"- "})}t.addReObjectPath(Nn.data,this.visel,c,null,!0)}}},{key:"isValid",value:function(t,e){var n=t.halfBonds;return this.loop.hbs.every((function(t){return n.has(t)&&n.get(t).loop===e}))}}],[{key:"isSelectable",value:function(){return!1}}]),o}(Fn);function Dr(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}var _r=function(t){(0,l.Z)(s,t);var e,n,o=(e=s,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function s(t){var e;return(0,r.Z)(this,s),e=o.call(this,"text"),(0,a.Z)((0,g.Z)(e),"paths",[]),e.item=t,e}return(0,i.Z)(s,[{key:"getReferencePoints",value:function(){if(!this.paths.length)return[];var t=this.getRelBox(this.paths),e=t.p0,n=t.p1,r=this.item.position,i=Math.abs(_.diff(e,n).x)/40,a=Math.abs(_.diff(e,n).y)/40,o=[];return o.push(this.item.position,new _(r.x,r.y+a),new _(r.x+i,r.y+a),new _(r.x+i,r.y)),o}},{key:"hoverPath",value:function(t){var e=this.getRelBox(this.paths),n=e.p0,r=e.p1,i=n.sub(t.options.offset),a=r.sub(n),o=a.x,s=a.y;return t.paper.rect(i.x,i.y,o,s,5)}},{key:"getRelBox",value:function(t){var e=this,n=t[0][0].getBBox().x,r=t[0],i=Math.min.apply(Math,(0,u.Z)(r.map((function(t){return t.getBBox().y})))),a=t.reduce((function(t,n){return e.getRowWidth(n)>e.getRowWidth(t)?n:t}),t[0]),o=a[a.length-1],s=o.getBBox().x+o.getBBox().width,l=t[t.length-1],c=Math.max.apply(Math,(0,u.Z)(l.map((function(t){return t.getBBox().y+t.getBBox().height}))));return{p0:new _(n,i),p1:new _(s,c)}}},{key:"getRowWidth",value:function(t){return t.reduce((function(t,e){return t+e.getBBox().width}),0)}},{key:"drawHover",value:function(t){if(!this.paths.length)return null;var e=this.hoverPath(t).attr(t.options.hoverStyle);return t.ctab.addReObjectPath(Nn.hovering,this.visel,e),e}},{key:"makeSelectionPlate",value:function(t,e,n){return this.paths.length&&e?this.hoverPath(t.render).attr(n.selectionStyle):null}},{key:"show",value:function(t,e,n){var r=this,i=t.render,o=i.paper,s=tt.obj2scaled(this.item.position,n),u=0;this.paths=[];var l=this.item.content?JSON.parse(this.item.content):null;l&&(l.blocks.forEach((function(t){var e=r.getRanges(t,n),i=0,l=[];e.forEach((function(e){var r=(0,m.Z)(e,3),c=r[0],d=r[1],h=r[2];t.text=t.text.replace(/[^\S\r\n]/g," ");var f=o.text(s.x,s.y,t.text.substring(c,d+1)||" ").attr(function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Dr(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Dr(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}({font:n.font,"font-size":n.fontsz,"text-anchor":"start",fill:"#000000"},h));f.translateAbs(i,u+(h.shiftY||0)),l.push(f),i+=f.getBBox().width})),r.paths.push(l);var c=r.getRelBox([l]),d=c.p0,h=c.p1;u+=Math.abs(_.diff(d,h).y)})),this.item.setPos(this.getReferencePoints()),i.ctab.addReObjectPath(Nn.data,this.visel,(0,B.flatten)(this.paths),null,!0))}},{key:"getRanges",value:function(t,e){for(var n=[],r=0,i=this.getStyles(t,r,e),a=1;a<t.text.length;a++){var o=this.getStyles(t,a,e);(0,B.isEqual)(i,o)||(n.push([r,a-1,i]),i=o,r=a)}return n.push([r,t.text.length-1,i]),n}},{key:"getStyles",value:function(t,e,n){var r=t.inlineStyleRanges.filter((function(t){return t.offset<=e&&e<t.offset+t.length})),i=r.reduce((function(t,e){var n;return e.style.includes(Pt.FontSize)?null===(n=e.style.match(/\d+/))||void 0===n?void 0:n[0]:t}),null);return r.reduce((function(t,e){var r=i||n.fontsz,a=.8*(i||n.fontszsub);switch(e.style){case Pt.Bold:t["font-weight"]="bold";break;case Pt.Italic:t["font-style"]="italic";break;case Pt.Subscript:t["font-size"]=a+"px",t.shiftY=r/3;break;case Pt.Superscript:t["font-size"]=a+"px",t.shiftY=-r/3;break;case"".concat(Pt.FontSize,"_").concat(i,"px"):t["font-size"]=i+"px"}return t}),{})}}],[{key:"isSelectable",value:function(){return!0}}]),s}(Fn);function jr(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var Gr=function(){function t(e,n){var i=this;(0,r.Z)(this,t),(0,a.Z)(this,"atoms",new Map),(0,a.Z)(this,"bonds",new Map),(0,a.Z)(this,"reloops",new Map),(0,a.Z)(this,"rxnPluses",new Map),(0,a.Z)(this,"rxnArrows",new Map),(0,a.Z)(this,"frags",new St),(0,a.Z)(this,"rgroups",new St),(0,a.Z)(this,"sgroups",new Map),(0,a.Z)(this,"sgroupData",new Map),(0,a.Z)(this,"enhancedFlags",new Map),(0,a.Z)(this,"simpleObjects",new Map),(0,a.Z)(this,"texts",new Map),(0,a.Z)(this,"initialized",!1),(0,a.Z)(this,"layers",[]),(0,a.Z)(this,"connectedComponents",new St),(0,a.Z)(this,"ccFragmentType",new St),(0,a.Z)(this,"structChanged",!1),(0,a.Z)(this,"atomsChanged",new Map),(0,a.Z)(this,"simpleObjectsChanged",new Map),(0,a.Z)(this,"rxnArrowsChanged",new Map),(0,a.Z)(this,"rxnPlusesChanged",new Map),(0,a.Z)(this,"enhancedFlagsChanged",new Map),(0,a.Z)(this,"bondsChanged",new Map),(0,a.Z)(this,"textsChanged",new Map),this.render=n,this.molecule=e||new Tt,this.initLayers(),this.clearMarks(),e.atoms.forEach((function(t,e){i.atoms.set(e,new Jn(t))})),e.bonds.forEach((function(t,e){i.bonds.set(e,new rr(t))})),e.loops.forEach((function(t,e){i.reloops.set(e,new Lr(t))})),e.rxnPluses.forEach((function(t,e){i.rxnPluses.set(e,new Sr(t))})),e.rxnArrows.forEach((function(t,e){i.rxnArrows.set(e,new Or(t))})),e.simpleObjects.forEach((function(t,e){i.simpleObjects.set(e,new Mr(t))})),e.texts.forEach((function(t,e){i.texts.set(e,new _r(t))})),e.frags.forEach((function(t,e){i.frags.set(e,new vr(t)),t&&i.enhancedFlags.set(e,new gr)})),e.rgroups.forEach((function(t,e){i.rgroups.set(e,new br(t))})),e.sgroups.forEach((function(t,e){i.sgroups.set(e,new Tr(t)),"DAT"!==t.type||t.data.attached||i.sgroupData.set(e,new Rr(t)),ft.isFunctionalGroup(t)&&i.molecule.functionalGroups.set(e,new ft(t))}))}return(0,i.Z)(t,[{key:"connectedComponentRemoveAtom",value:function(t,e){var n=e||this.atoms.get(t);if(n&&!(n.component<0)){var r=this.connectedComponents.get(n.component);r.delete(t),r.size<1&&this.connectedComponents.delete(n.component),n.component=-1}}},{key:"clearConnectedComponents",value:function(){this.connectedComponents.clear(),this.atoms.forEach((function(t){t.component=-1}))}},{key:"getConnectedComponent",value:function(t,e){for(var n=this,r=Array.isArray(t)?Array.from(t):[t],i=new H;r.length>0;){var a=r.pop();i.add(a);var o=this.atoms.get(a);o&&(o.component>=0&&e.add(o.component),o.a.neighbors.forEach((function(t){var e=n.molecule.halfBonds.get(t);if(e){var a=e.end;i.has(a)||r.push(a)}})))}return i}},{key:"addConnectedComponent",value:function(t){var e=this,n=this.connectedComponents.add(t),r=new H,i=this.getConnectedComponent(Array.from(t),r);r.delete(n);var a=-1;return i.forEach((function(t){var r=e.atoms.get(t);r&&(r.component=n,-1!==r.a.rxnFragmentType&&(a=r.a.rxnFragmentType))})),this.ccFragmentType.set(n,a),n}},{key:"removeConnectedComponent",value:function(t){var e=this;return this.connectedComponents.get(t).forEach((function(t){var n=e.atoms.get(t);n&&(n.component=-1)})),this.connectedComponents.delete(t)}},{key:"assignConnectedComponents",value:function(){var t=this;this.atoms.forEach((function(e,n){if(!(e.component>=0)){var r=new H,i=t.getConnectedComponent(n,r);r.forEach((function(e){t.removeConnectedComponent(e)})),t.addConnectedComponent(i)}}))}},{key:"initLayers",value:function(){for(var t in Nn)this.layers[Nn[t]]=this.render.paper.rect(0,0,10,10).attr({class:t+"Layer",fill:"#000",opacity:"0.0"}).toFront()}},{key:"addReObjectPath",value:function(t,e,n){var r=this,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,a=arguments.length>4&&void 0!==arguments[4]&&arguments[4];n&&this.layers[t].node.parentNode&&(Array.isArray(n)?n:[n]).forEach((function(n){var o=r.render.options.offset,s=a?it.fromRelBox(Hn.relBox(n.getBBox())):null,u=i&&s?s.translate(i.negated()):null;null!==o&&(n.translateAbs(o.x,o.y),s=s?s.translate(o):null),e.add(n,s,u),n.insertBefore(r.layers[Nn[t]])}))}},{key:"clearMarks",value:function(){var e=this;Object.keys(t.maps).forEach((function(t){e[t+"Changed"]=new Map})),this.structChanged=!1}},{key:"markItemRemoved",value:function(){this.structChanged=!0}},{key:"markBond",value:function(t,e){this.markItem("bonds",t,e)}},{key:"markAtom",value:function(t,e){this.markItem("atoms",t,e)}},{key:"markItem",value:function(t,e,n){var r=this[t+"Changed"],i=r.has(e)?Math.max(n,r.get(e)):n;r.set(e,i),this[t].has(e)&&this.clearVisel(this[t].get(e).visel)}},{key:"clearVisel",value:function(t){t.paths.forEach((function(t){t.remove()})),t.clear()}},{key:"eachItem",value:function(e){var n=this;Object.keys(t.maps).forEach((function(t){n[t].forEach(e)}))}},{key:"getVBoxObj",value:function(e){var n=this;Fr(e=e||{})&&Object.keys(t.maps).forEach((function(t){e[t]=Array.from(n[t].keys())}));var r=null;return Object.keys(t.maps).forEach((function(t){e[t]&&e[t].forEach((function(e){var i=n[t].get(e).getVBoxObj(n.render);i&&(r=r?it.union(r,i):i.clone())}))})),r=r||new it(0,0,0,0)}},{key:"translate",value:function(t){this.eachItem((function(e){return e.visel.translate(t)}))}},{key:"scale",value:function(t){this.eachItem((function(e){return function(t,e){for(var n=0;n<t.paths.length;++n)Hr(t.paths[n],e)}(e.visel,t)}))}},{key:"clearVisels",value:function(){var t=this;this.eachItem((function(e){return t.clearVisel(e.visel)}))}},{key:"update",value:function(e){var n=this;e=e||!this.initialized,Object.keys(t.maps).forEach((function(t){var r=n[t+"Changed"];e?n[t].forEach((function(t,e){return r.set(e,1)})):r.forEach((function(e,i){n[t].has(i)||r.delete(i)}))})),this.atomsChanged.forEach((function(t,e){return n.connectedComponentRemoveAtom(e)})),this.frags.filter((function(t,e){return!e.calcBBox(n.render.ctab,t,n.render)})).forEach((function(t,e){n.clearVisel(t.visel),n.frags.delete(e),n.molecule.frags.delete(e)})),Object.keys(t.maps).forEach((function(t){var e=n[t+"Changed"];e.forEach((function(r,i){n.clearVisel(n[t].get(i).visel),n.structChanged=n.structChanged||e.get(i)>0}))})),this.sgroups.forEach((function(t){n.clearVisel(t.visel),t.hovering=null,t.selectionPlate=null})),this.frags.forEach((function(t){n.clearVisel(t.visel)})),this.rgroups.forEach((function(t){n.clearVisel(t.visel)})),e&&(this.clearConnectedComponents(),this.molecule.initHalfBonds(),this.molecule.initNeighbors());var r=Array.from(this.atomsChanged.keys());this.molecule.updateHalfBonds(r),this.molecule.sortNeighbors(r),this.assignConnectedComponents(),this.initialized=!0,this.verifyLoops();var i=e||this.structChanged;return i&&this.updateLoops(),this.showLabels(),this.showBonds(),i&&this.showLoops(),this.showReactionSymbols(),this.showSGroups(),this.showFragments(),this.showRGroups(),this.showEnhancedFlags(),this.showSimpleObjects(),this.showTexts(),this.clearMarks(),!0}},{key:"updateLoops",value:function(){var t=this;this.reloops.forEach((function(e){t.clearVisel(e.visel)}));var e=this.molecule.findLoops();e.bondsToMark.forEach((function(e){t.markBond(e,1)})),e.newLoops.forEach((function(e){t.reloops.set(e,new Lr(t.molecule.loops.get(e)))}))}},{key:"showLoops",value:function(){var t=this,e=this.render.options;this.reloops.forEach((function(n,r){n.show(t,r,e)}))}},{key:"showSimpleObjects",value:function(){var t=this,e=this.render.options;this.simpleObjectsChanged.forEach((function(n,r){var i=t.simpleObjects.get(r);i&&i.show(t,e)}))}},{key:"showTexts",value:function(){var t=this,e=this.render.options;this.textsChanged.forEach((function(n,r){var i=t.texts.get(r);i&&i.show(t,r,e)}))}},{key:"showReactionSymbols",value:function(){var t=this,e=this.render.options;this.rxnArrowsChanged.forEach((function(n,r){var i=t.rxnArrows.get(r);i&&i.show(t,r,e)})),this.rxnPlusesChanged.forEach((function(n,r){var i=t.rxnPluses.get(r);i&&i.show(t,r,e)}))}},{key:"showSGroups",value:function(){var t=this;this.molecule.sGroupForest.getSGroupsBFS().reverse().forEach((function(e){var n=t.sgroups.get(e);n&&n.show(t)}))}},{key:"showFragments",value:function(){var t=this;this.frags.forEach((function(e,n){var r=e.draw(t.render,n);r&&t.addReObjectPath(Nn.data,e.visel,r,null,!0)}))}},{key:"showRGroups",value:function(){var t=this,e=this.render.options;this.rgroups.forEach((function(n,r){n.show(t,r,e)}))}},{key:"loopRemove",value:function(t){var e=this,n=this.reloops.get(t);if(n){this.clearVisel(n.visel);var r=[];n.loop.hbs.forEach((function(t){var n=e.molecule.halfBonds.get(t);n&&(n.loop=-1,e.markBond(n.bid,1),e.markAtom(n.begin,1),r.push(n.bid))})),this.reloops.delete(t),this.molecule.loops.delete(t)}}},{key:"verifyLoops",value:function(){var t=this;this.reloops.forEach((function(e,n){e.isValid(t.molecule,n)||t.loopRemove(n)}))}},{key:"showLabels",value:function(){var t=this,e=this.render.options;this.atomsChanged.forEach((function(n,r){var i=t.atoms.get(r);i&&i.show(t,r,e)}))}},{key:"showEnhancedFlags",value:function(){var t=this,e=this.render.options;this.enhancedFlagsChanged.forEach((function(n,r){var i=t.enhancedFlags.get(r);i&&i.show(t,r,e)}))}},{key:"showBonds",value:function(){var t=this,e=this.render.options;this.bondsChanged.forEach((function(n,r){var i=t.bonds.get(r);i&&i.show(t,r,e)}))}},{key:"setSelection",value:function(e){var n=this,r=[];Object.keys(t.maps).forEach((function(i){var a=n[i].values(),o=(0,m.Z)(a,1)[0];(t.maps[i].isSelectable()||o instanceof Tr)&&n[i].forEach((function(t,a){if(t instanceof Jn){var o,s,u=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return jr(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?jr(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}(t.a.sgs.values());try{for(u.s();!(s=u.n()).done;)o=s.value}catch(t){u.e(t)}finally{u.f()}r.push({selected:t.selected,sgroup:o})}if(t instanceof Tr&&ft.isContractedFunctionalGroup(t.item.id,n.molecule.functionalGroups)){var l=r.filter((function(e){return e.sgroup===t.item.id}));t.selected=l.length>0&&l[0].selected}var c=null!=e&&e[i]?e[i].indexOf(a)>-1:t.selected;null===e&&(c=!1),n.showItemSelection(t,c)}))}))}},{key:"showItemSelection",value:function(t,e){var n=function(t){var e,n,r,i;return t&&null!==t.selectionPlate&&(!(null!==(e=t.selectionPlate)&&void 0!==e&&e.items)&&!(null!==(n=t.selectionPlate)&&void 0!==n&&n.removed)||Array.isArray(null===(r=t.selectionPlate)||void 0===r?void 0:r.items)&&!(null!==(i=t.selectionPlate[0])&&void 0!==i&&i.removed))}(t);if(t.selected=e,t instanceof Rr&&(t.sgroup.selected=e),e){if(!n){var r=this.render,i=r.options,a=r.paper;t.selectionPlate=t.makeSelectionPlate(this,a,i),this.addReObjectPath(Nn.selectionPlate,t.visel,t.selectionPlate)}t.selectionPlate&&t.selectionPlate.show()}else n&&t.selectionPlate&&t.selectionPlate.hide()}}]),t}();function Fr(t){return!t||!Object.keys(Gr.maps).some((function(e){return t[e]&&t[e].length>0}))}function Hr(t,e){if("set"===t.type)for(var n=0;n<t.length;++n)Hr(t[n],e);else void 0!==t.attrs&&("font-size"in t.attrs?t.attr("font-size",t.attrs["font-size"]*e):"stroke-width"in t.attrs&&t.attr("stroke-width",t.attrs["stroke-width"]*e)),t.scale(e,e,0,0)}(0,a.Z)(Gr,"maps",{atoms:Jn,bonds:rr,rxnPluses:Sr,rxnArrows:Or,frags:vr,rgroups:br,sgroupData:Rr,enhancedFlags:gr,sgroups:Tr,reloops:Lr,simpleObjects:Mr,texts:_r});var zr=Math.PI/12;function Ur(t,e){var n=_.diff(e,t);return Math.atan2(n.y,n.x)}function Vr(t,e){return e&&(t=Ur(t,e)),Math.round(t/zr)*zr}function Wr(t){var e=Math.round(t/Math.PI*180);return e>180?e-=360:e<=-180&&(e+=360),e}var Yr={calcAngle:Ur,fracAngle:Vr,calcNewAtomPos:function(t,e,n){var r=new _(1,0).rotate(n?Ur(t,e):Vr(t,e));return r.add_(t),r},degrees:Wr,setFracAngle:function(t){zr=Math.PI/180*t},mergeBondsParams:function(t,e,n,r){var i=t.atoms.get(e.begin),a=n.atoms.get(r.begin),o=t.atoms.get(e.end),s=n.atoms.get(r.end),u=Ur(i.pp,o.pp)-Ur(a.pp,s.pp),l=Math.abs(Wr(u)%180),c=_.dist(i.pp,o.pp)/_.dist(a.pp,s.pp);return{merged:!(0,b.inRange)(l,10,170)&&(0,b.inRange)(c,.8,1.2),angle:u,scale:c,cross:Math.abs(Wr(u))>90}}};function qr(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function $r(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?qr(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):qr(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function Xr(t,e){var n=e.width||t.clientWidth-10,r=e.height||t.clientHeight-10;n=n>0?n:0,r=r>0?r:0,this.userOpts=e,this.clientArea=t,this.paper=new(P())(t,n,r),this.sz=_.ZERO,this.ctab=new Gr(new Tt,this),this.options=function(t){var e=t.scale||100;t.rotationStep&&Yr.setFracAngle(t.rotationStep);var n=Math.ceil(e/6*1.9),r=Math.ceil(.7*n),i={"dearomatize-on-load":!1,showAtomIds:!1,showBondIds:!1,showHalfBondIds:!1,showLoopIds:!1,showValenceWarnings:!0,autoScale:!1,autoScaleMargin:0,maxBondLength:0,atomColoring:!0,hideImplicitHydrogen:!1,hideTerminalLabels:!1,carbonExplicitly:!1,showCharge:!0,showHydrogenLabels:"on",showValence:!0,aromaticCircle:!0,scale:e,zoom:1,offset:new _,lineWidth:e/20,bondSpace:t.doubleBondWidth||e/7,stereoBond:t.stereoBondWidth||e/7,subFontSize:r,font:"30px Arial",fontsz:n,fontszsub:r,fontRLabel:1.2*n,fontRLogic:.7*n,lineattr:{stroke:"#000","stroke-width":t.bondThickness||e/20,"stroke-linecap":"round","stroke-linejoin":"round"},selectionStyle:{fill:"#7f7",stroke:"none"},hoverStyle:{stroke:"#0c0","stroke-width":.6*e/20},sgroupBracketStyle:{stroke:"darkgray","stroke-width":.5*e/20},lassoStyle:{stroke:"gray","stroke-width":"1px"},hoverStyleSimpleObject:{stroke:"#0c0","stroke-width":e/4,"stroke-linecap":"round","stroke-opacity":.6},atomSelectionPlateRadius:1.2*n,contractedFunctionalGroupSize:50};return Object.assign({},i,t)}(this.userOpts)}Xr.prototype.updateOptions=function(t){try{var e=JSON.parse(t);if(e&&"object"===(0,y.Z)(e))return this.options=$r($r({},this.options),e),this.options}catch(t){}return!1},Xr.prototype.selectionPolygon=function(t){return Xn.selectionPolygon(this.paper,t,this.options)},Xr.prototype.selectionLine=function(t,e){return Xn.selectionLine(this.paper,t,e,this.options)},Xr.prototype.selectionRectangle=function(t,e){return Xn.selectionRectangle(this.paper,t,e,this.options)},Xr.prototype.view2obj=function(t,e){var n=this.scrollPos();return this.useOldZoom||(t=t.scaled(1/this.options.zoom),n=n.scaled(1/this.options.zoom)),t=e?t:t.add(n).sub(this.options.offset),tt.scaled2obj(t,this.options)},Xr.prototype.obj2view=function(t,e){var n=tt.obj2scaled(t,this.options);return n=e?n:n.add(this.options.offset).sub(this.scrollPos().scaled(1/this.options.zoom)),this.useOldZoom||(n=n.scaled(this.options.zoom)),n},Xr.prototype.scrollPos=function(){return new _(this.clientArea.scrollLeft,this.clientArea.scrollTop)},Xr.prototype.page2obj=function(t){var e=this.clientArea.getBoundingClientRect(),n=e.top,r=e.left,i=new _(t.clientX-r,t.clientY-n);return this.view2obj(i)},Xr.prototype.setPaperSize=function(t){this.sz=t,this.paper.setSize(t.x*this.options.zoom,t.y*this.options.zoom),this.setViewBox(this.options.zoom)},Xr.prototype.setOffset=function(t){var e=new _(t.x-this.options.offset.x,t.y-this.options.offset.y);this.clientArea.scrollLeft+=e.x,this.clientArea.scrollTop+=e.y,this.options.offset=t},Xr.prototype.setZoom=function(t){this.options.zoom=t,this.paper.setSize(this.sz.x*t,this.sz.y*t),this.setViewBox(t)},Xr.prototype.setScrollOffset=function(t,e){var n,r,i,a,o,s,u,l=this.clientArea,c=l.clientWidth,d=l.clientHeight,h=(n=this.sz.scaled(this.options.zoom),r=t,i=e,a=c+t,o=d+e,s=r<0?-r:0,u=i<0?-i:0,n.x<a&&(s+=a-n.x),n.y<o&&(u+=o-n.y),new _(s,u)).scaled(1/this.options.zoom);if(h.x>0||h.y>0){this.setPaperSize(this.sz.add(h));var f=new _(t<0?-t:0,e<0?-e:0).scaled(1/this.options.zoom);(f.x>0||f.y>0)&&(this.ctab.translate(f),this.setOffset(this.options.offset.add(f)))}l.scrollLeft=t*this.options.scale,l.scrollTop=e*this.options.scale,this.update(!1)},Xr.prototype.setScale=function(t){this.options.offset&&(this.options.offset=this.options.offset.scaled(1/t).scaled(t)),this.userOpts.scale*=t,this.options=null,this.update(!0)},Xr.prototype.setViewBox=function(t){this.useOldZoom?this.setScale(t):this.paper.canvas.setAttribute("viewBox","0 0 "+this.sz.x+" "+this.sz.y)},Xr.prototype.setMolecule=function(t){this.paper.clear(),this.ctab=new Gr(t,this),this.options.offset=new _,this.update(!1)},Xr.prototype.update=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;e=e||new _(this.clientArea.clientWidth||100,this.clientArea.clientHeight||100);var n=this.ctab.update(t);if(this.ctab.setSelection(),n){var r=this.options.scale,i=this.ctab.getVBoxObj().transform(tt.obj2scaled,this.options).translate(this.options.offset||new _);if(this.options.downScale&&this.ctab.molecule.rescale(),this.options.autoScale||this.options.downScale){var a=i.sz(),o=this.options.autoScaleMargin,s=new _(o,o),u=e;if(o&&(u.x<2*o+1||u.y<2*o+1))throw new Error("View box too small for the given margin");var l=this.options.rescaleAmount||Math.max(a.x/(u.x-2*o),a.y/(u.y-2*o)),c=this.options.downScale&&l<1;(this.options.maxBondLength/l>1||c)&&(l=1);var d=a.add(s.scaled(2*l));this.paper.setViewBox(i.pos().x-o*l-(u.x*l-d.x)/2,i.pos().y-o*l-(u.y*l-d.y)/2,u.x*l,u.y*l)}else{var h=_.UNIT.scaled(r),f=i.sz().length()>0?i.extend(h,h):i,p=new it(this.scrollPos(),e.scaled(1/this.options.zoom).sub(_.UNIT.scaled(20))),m=it.union(p,f);this.oldCb||(this.oldCb=new it);var g=m.sz().floor(),v=this.oldCb.p0.sub(m.p0).ceil();this.oldBb=i,this.sz&&g.x===this.sz.x&&g.y===this.sz.y||this.setPaperSize(g),this.options.offset=this.options.offset||new _,0===v.x&&0===v.y||(this.setOffset(this.options.offset.add(v)),this.ctab.translate(v))}}};var Kr=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;(0,r.Z)(this,t),this.type=e,this.priority=n}return(0,i.Z)(t,[{key:"execute",value:function(t){throw new Error("Operation.execute() is not implemented")}},{key:"perform",value:function(t){return this.execute(t),this._inverted||(this._inverted=this.invert(),this._inverted._inverted=this),this._inverted}},{key:"invert",value:function(){throw new Error("Operation.invert() is not implemented")}},{key:"isDummy",value:function(t){return!1}}],[{key:"invalidateAtom",value:function(e,n,r){var i=e.atoms.get(n);if(i){e.markAtom(n,r?1:0);var a=e.molecule.halfBonds;i.a.neighbors.forEach((function(n){if(a.has(n)){var i=a.get(n);i&&(e.markBond(i.bid,1),e.markAtom(i.end,0),r&&t.invalidateLoop(e,i.bid))}}));var o=i.a.fragment,s=e.render.options.stereoLabelStyle;e.atoms.forEach((function(t,n){s!==Ln.IUPAC&&s!==Ln.Classic||t.a.fragment===o&&e.markAtom(n,0)}))}}},{key:"invalidateLoop",value:function(t,e){var n=t.bonds.get(e);if(n&&n.b.hb1&&n.b.hb2){var r=t.molecule.halfBonds.get(n.b.hb1),i=t.molecule.halfBonds.get(n.b.hb2);r&&r.loop>=0&&t.loopRemove(r.loop),i&&i.loop>=0&&t.loopRemove(i.loop)}}},{key:"invalidateBond",value:function(e,n){t.invalidateLoop(e,n);var r=e.bonds.get(n);r&&(t.invalidateAtom(e,r.b.begin,0),t.invalidateAtom(e,r.b.end,0))}},{key:"invalidateItem",value:function(e,n,r,i){if("atoms"!==n)return"bonds"===n?(t.invalidateBond(e,r),void(i>0&&t.invalidateLoop(e,r))):void e.markItem(n,r,i);t.invalidateAtom(e,r,i)}},{key:"invalidateEnhancedFlag",value:function(e,n){t.invalidateItem(e,"enhancedFlags",n,1)}}]),t}(),Jr=Object.freeze({ATOM_ADD:"Add atom",ATOM_DELETE:"Delete atom",ATOM_ATTR:"Set atom attribute",ATOM_MOVE:"Move atom",CALC_IMPLICIT_H:"Calculate implicit hydrogen",BOND_ADD:"Add bond",BOND_DELETE:"Delete bond",BOND_ATTR:"Set bond attribute",BOND_MOVE:"Move bond",LOOP_MOVE:"Move loop",S_GROUP_ATOM_ADD:"Add atom to s-group",S_GROUP_ATOM_REMOVE:"Remove atom from s-group",S_GROUP_ATTR:"Set s-group attribute",S_GROUP_CREATE:"Create s-group",S_GROUP_DELETE:"Delete s-group",S_GROUP_ADD_TO_HIERACHY:"Add s-group to hierarchy",S_GROUP_REMOVE_FROM_HIERACHY:"Delete s-group from hierarchy",R_GROUP_ATTR:"Set r-group attribute",R_GROUP_FRAGMENT:"R-group fragment",UPDATE_IF_THEN:"Update",RESTORE_IF_THEN:"Restore",RXN_ARROW_ADD:"Add rxn arrow",RXN_ARROW_DELETE:"Delete rxn arrow",RXN_ARROW_MOVE:"Move rxn arrow",RXN_ARROW_RESIZE:"Resize rxn arrow",RXN_PLUS_ADD:"Add rxn plus",RXN_PLUS_DELETE:"Delete rxn plus",RXN_PLUS_MOVE:"Move rxn plus",S_GROUP_DATA_MOVE:"Move s-group data",CANVAS_LOAD:"Load canvas",ALIGN_DESCRIPTORS:"Align descriptors",SIMPLE_OBJECT_ADD:"Add simple object",SIMPLE_OBJECT_DELETE:"Delete simple object",SIMPLE_OBJECT_MOVE:"Move simple object",SIMPLE_OBJECT_RESIZE:"Resize simple object",RESTORE_DESCRIPTORS_POSITION:"Restore descriptors position",FRAGMENT_ADD:"Add fragment",FRAGMENT_DELETE:"Delete fragment",FRAGMENT_STEREO_FLAG:"Add fragment stereo flag",FRAGMENT_ADD_STEREO_ATOM:"Add stereo atom to fragment",FRAGMENT_DELETE_STEREO_ATOM:"Delete stereo atom from fragment",ENHANCED_FLAG_MOVE:"Move enhanced flag",TEXT_CREATE:"Add text",TEXT_UPDATE:"Edit text",TEXT_DELETE:"Delete text",TEXT_MOVE:"Move text",ADD_HIGHLIGHT:"Highlight",UPDATE_HIGHLIGHT:"Update highlight",REMOVE_HIGHLIGHT:"Remove highlight"});var Qr=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e,n){var i;return(0,r.Z)(this,o),(i=a.call(this,Jr.ATOM_ATTR,1)).data={aid:t,attribute:e,value:n},i.data2=null,i}return(0,i.Z)(o,[{key:"execute",value:function(t){if(this.data){var e=this.data,n=e.aid,r=e.attribute,i=e.value,a=t.molecule.atoms.get(n);this.data2||(this.data2={aid:n,attribute:r,value:a[r]}),a[r]=i,Kr.invalidateAtom(t,n)}}},{key:"invert",value:function(){var t=new o;return t.data=this.data2,t.data2=this.data,t}},{key:"isDummy",value:function(t){var e,n,r;return t.molecule.atoms.get(null===(e=this.data)||void 0===e?void 0:e.aid)[null===(n=this.data)||void 0===n?void 0:n.attribute]===(null===(r=this.data)||void 0===r?void 0:r.value)}}]),o}(Kr);var ti=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e,n){var i;return(0,r.Z)(this,o),(i=a.call(this,Jr.ATOM_MOVE,2)).data={aid:t,d:e,noinvalidate:n},i}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=t.molecule,n=this.data,r=n.aid,i=n.d,a=e.atoms.get(r);if(a){a.pp.add_(i);var o=t.atoms.get(r);if(o){var s=tt.obj2scaled(i,t.render.options);o.visel.translate(s)}this.data.d=i.negated(),this.data.noinvalidate||Kr.invalidateAtom(t,r,1)}}},{key:"invert",value:function(){var t=new o;return t.data=this.data,t}},{key:"isDummy",value:function(){var t=this.data.d;return 0===t.x&&0===t.y}}]),o}(Kr);function ei(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var ni=function(t){(0,l.Z)(n,t);var e=ei(n);function n(t,i){var a;return(0,r.Z)(this,n),(a=e.call(this,Jr.ATOM_ADD)).data={atom:t,pos:i,aid:null},a}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.atom,r=e.pos,i=t.molecule,a={label:""};n&&Object.keys(n).forEach((function(t){a[t]=n[t]})),a.label=a.label||"C","number"!=typeof this.data.aid?this.data.aid=i.atoms.add(new W(a)):i.atoms.set(this.data.aid,new W(a));var o=this.data.aid,s=new Jn(i.atoms.get(o));s.component=t.connectedComponents.add(new H([o])),t.atoms.set(o,s),t.markAtom(o,1),i.atomSetPos(o,new _(r));var u=i.rxnArrows.get(0);u&&(i.atoms.get(o).rxnFragmentType=i.defineRxnFragmentTypeForAtomset(new H([o]),u.pos[0].x))}},{key:"invert",value:function(){var t=new ri;return t.data=this.data,t}}]),n}(Kr),ri=function(t){(0,l.Z)(n,t);var e=ei(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.ATOM_DELETE,5)).data={aid:t,atom:null,pos:null},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data.aid,n=t.molecule;this.data.atom||(this.data.atom=n.atoms.get(e),this.data.pos=this.data.atom.pp);var r=t.atoms.get(e);if(r){var i=t.connectedComponents.get(r.component);i.delete(e),0===i.size&&t.connectedComponents.delete(r.component),t.clearVisel(r.visel),t.atoms.delete(e),t.markItemRemoved(),n.atoms.delete(e)}}},{key:"invert",value:function(){var t=new ni;return t.data=this.data,t}}]),n}(Kr);var ii=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e,n){var i;return(0,r.Z)(this,o),(i=a.call(this,Jr.BOND_ATTR,2)).data={bid:t,attribute:e,value:n},i.data2=null,i}return(0,i.Z)(o,[{key:"execute",value:function(t){if(this.data){var e=this.data,n=e.attribute,r=e.bid,i=e.value,a=t.molecule.bonds.get(r);this.data2||(this.data2={bid:r,attribute:n,value:a[n]}),a[n]=i,Kr.invalidateBond(t,r),"type"===n&&Kr.invalidateLoop(t,r)}}},{key:"isDummy",value:function(t){if(this.data){var e=this.data,n=e.attribute,r=e.bid,i=e.value;return t.molecule.bonds.get(r)[n]===i}return!1}},{key:"invert",value:function(){var t=new o;return t.data=this.data2,t.data2=this.data,t}}]),o}(Kr);var ai=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e){var n;return(0,r.Z)(this,o),(n=a.call(this,Jr.BOND_MOVE,2)).data={bid:t,d:e},n}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=this.data,n=e.bid,r=e.d,i=t.bonds.get(n);if(i){var a=tt.obj2scaled(r,t.render.options);i.visel.translate(a),this.data.d=r.negated()}}},{key:"invert",value:function(){var t=new o;return t.data=this.data,t}}]),o}(Kr);function oi(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var si=function(t){(0,l.Z)(n,t);var e=oi(n);function n(t,i,a){var o;return(0,r.Z)(this,n),(o=e.call(this,Jr.BOND_ADD,1)).data={bond:a,begin:t,end:i,bid:null},o}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.begin,r=e.bond,i=e.end,a=t.molecule;if(n===i)throw new Error("Distinct atoms expected");Kr.invalidateAtom(t,n,1),Kr.invalidateAtom(t,i,1);var o={type:0,begin:0,end:0};r&&Object.keys(r).forEach((function(t){o[t]=r[t]})),o.type=o.type||q.PATTERN.TYPE.SINGLE,o.begin=n,o.end=i;var s=new q(o);"number"==typeof this.data.bid?a.bonds.set(this.data.bid,s):this.data.bid=a.bonds.add(s);var u=this.data.bid,l=a.bonds.get(u);a.bondInitHalfBonds(u),a.atomAddNeighbor(l.hb1),a.atomAddNeighbor(l.hb2),t.bonds.set(u,new rr(l)),t.markBond(u,1)}},{key:"invert",value:function(){var t=new ui;return t.data=this.data,t}}]),n}(Kr),ui=function(t){(0,l.Z)(n,t);var e=oi(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.BOND_DELETE,3)).data={bid:t,bond:null,begin:null,end:null},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data.bid,n=t.molecule;this.data.bond||(this.data.bond=n.bonds.get(e),this.data.begin=this.data.bond.begin,this.data.end=this.data.bond.end),Kr.invalidateBond(t,e);var r=t.bonds.get(e);if(r){[r.b.hb1,r.b.hb2].forEach((function(e){if(void 0!==e){var n=t.molecule.halfBonds.get(e);n&&n.loop>=0&&t.loopRemove(n.loop)}}),t),t.clearVisel(r.visel),t.bonds.delete(e),t.markItemRemoved();var i=n.bonds.get(e);[i.hb1,i.hb2].forEach((function(t){var e=n.halfBonds.get(t);if(e){var r=n.atoms.get(e.begin),i=r.neighbors.indexOf(t),a=(i+r.neighbors.length-1)%r.neighbors.length,o=(i+1)%r.neighbors.length;n.setHbNext(r.neighbors[a],r.neighbors[o]),r.neighbors.splice(i,1)}})),n.halfBonds.delete(i.hb1),n.halfBonds.delete(i.hb2),n.bonds.delete(e)}}},{key:"invert",value:function(){var t=new si;return t.data=this.data,t}}]),n}(Kr);var li=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t){var e;return(0,r.Z)(this,o),(e=a.call(this,Jr.CANVAS_LOAD)).data={struct:t},e}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=t.molecule;t.clearVisels(),this.data.struct&&t.render.setMolecule(this.data.struct),this.data.struct=e}},{key:"invert",value:function(){var t=new o;return t.data=this.data,t}}]),o}(Kr);function ci(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var di=function(t){(0,l.Z)(n,t);var e=ci(n);function n(){var t;return(0,r.Z)(this,n),(t=e.call(this,Jr.ALIGN_DESCRIPTORS)).history={},t}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this,n=t.molecule,r=Array.from(n.sgroups.values()).reverse(),i=n.getCoordBoundingBoxObj(),a=new _(i.max.x,i.min.y).add(new _(2,-1));r.forEach((function(r){e.history[r.id]=new _(r.pp),a=a.add(new _(0,.5)),r.pp=a,n.sgroups.set(r.id,r),Kr.invalidateItem(t,"sgroupData",r.id,1)}))}},{key:"invert",value:function(){return new hi(this.history)}}]),n}(Kr),hi=function(t){(0,l.Z)(n,t);var e=ci(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.RESTORE_DESCRIPTORS_POSITION)).history=t,i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this,n=t.molecule;Array.from(n.sgroups.values()).forEach((function(r){r.pp=e.history[r.id],n.sgroups.set(r.id,r),Kr.invalidateItem(t,"sgroupData",r.id,1)}))}},{key:"invert",value:function(){return new di}}]),n}(Kr);var fi=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e){var n;return(0,r.Z)(this,o),(n=a.call(this,Jr.ENHANCED_FLAG_MOVE)).data={frid:t,p:e},n}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=this.data.frid,n=this.data.p,r=t.molecule.frags.get(e);if(r){var i=r.stereoFlagPosition?new _(r.stereoFlagPosition.x,r.stereoFlagPosition.y):Q.getDefaultStereoFlagPosition(t.molecule,e),a=_.sum(i,n);r.stereoFlagPosition=a,this.data.p=n.negated(),Kr.invalidateItem(t,"enhancedFlags",e,1)}}},{key:"invert",value:function(){var t=new o;return t.data=this.data,t}}]),o}(Kr);function pi(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var mi=function(t){(0,l.Z)(n,t);var e=pi(n);function n(t,i){var a,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return(0,r.Z)(this,n),(a=e.call(this,Jr.UPDATE_IF_THEN)).rgid_new=t,a.rgid_old=i,a.ifThenHistory=new Map,a.skipRgids=o||[],a}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this,n=t.molecule;n.rgroups.forEach((function(t,r){t.ifthen!==e.rgid_old||e.skipRgids.includes(r)||(t.ifthen=e.rgid_new,e.ifThenHistory.set(r,e.rgid_old),n.rgroups.set(r,t))}))}},{key:"invert",value:function(){return new gi(this.rgid_new,this.rgid_old,this.ifThenHistory)}}]),n}(Kr),gi=function(t){(0,l.Z)(n,t);var e=pi(n);function n(t,i,a){var o;return(0,r.Z)(this,n),(o=e.call(this,Jr.RESTORE_IF_THEN)).rgid_new=t,o.rgid_old=i,o.ifThenHistory=a||new Map,o}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule;this.ifThenHistory.forEach((function(t,n){var r=e.rgroups.get(n);r.ifthen=t,e.rgroups.set(n,r)}))}},{key:"invert",value:function(){return new mi(this.rgid_old,this.rgid_new)}}]),n}(Kr);function vi(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var yi=function(t){(0,l.Z)(n,t);var e=vi(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.FRAGMENT_ADD)).frid=void 0===t?null:t,i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=new Q;null===this.frid?this.frid=e.frags.add(n):e.frags.set(this.frid,n),t.frags.set(this.frid,new vr(n)),t.enhancedFlags.set(this.frid,new gr)}},{key:"invert",value:function(){return new bi(this.frid)}}]),n}(Kr),bi=function(t){(0,l.Z)(n,t);var e=vi(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.FRAGMENT_DELETE,100)).frid=t,i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule;if(e.frags.get(this.frid)){Kr.invalidateItem(t,"frags",this.frid,1),t.frags.delete(this.frid),e.frags.delete(this.frid);var n=t.enhancedFlags.get(this.frid);n&&(t.clearVisel(n.visel),t.enhancedFlags.delete(this.frid))}}},{key:"invert",value:function(){return new yi(this.frid)}}]),n}(Kr);function wi(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var xi=function(t){(0,l.Z)(n,t);var e=wi(n);function n(t,i){var a;return(0,r.Z)(this,n),(a=e.call(this,Jr.FRAGMENT_ADD_STEREO_ATOM,100)).data={frid:t,aid:i},a}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.aid,r=e.frid,i=t.molecule.frags.get(r);i&&(i.updateStereoAtom(t.molecule,n,r,!0),Kr.invalidateEnhancedFlag(t,r))}},{key:"invert",value:function(){return new Ei(this.data.frid,this.data.aid)}}]),n}(Kr),Ei=function(t){(0,l.Z)(n,t);var e=wi(n);function n(t,i){var a;return(0,r.Z)(this,n),(a=e.call(this,Jr.FRAGMENT_DELETE_STEREO_ATOM,90)).data={frid:t,aid:i},a}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.aid,r=e.frid,i=t.molecule.frags.get(r);i&&(i.updateStereoAtom(t.molecule,n,r,!1),Kr.invalidateEnhancedFlag(t,r))}},{key:"invert",value:function(){var t=this.data,e=t.aid,n=t.frid;return new xi(n,e)}}]),n}(Kr);var Oi=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t){var e;return(0,r.Z)(this,o),(e=a.call(this,Jr.FRAGMENT_STEREO_FLAG,6)).frid=t,e}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=t.molecule;e.frags.get(this.frid).updateStereoFlag(e),Kr.invalidateEnhancedFlag(t,this.frid)}},{key:"invert",value:function(){return new o(this.frid)}}]),o}(Kr);var Ai=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t){var e;return(0,r.Z)(this,o),(e=a.call(this,Jr.CALC_IMPLICIT_H,10)).atomIds=t,e}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=this.atomIds;t.molecule.setImplicitHydrogen(e)}},{key:"invert",value:function(){return new o(this.atomIds)}}]),o}(Kr);var Si=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e){var n;return(0,r.Z)(this,o),(n=a.call(this,Jr.LOOP_MOVE)).data={id:t,d:e},n}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=this.data,n=e.id,r=e.d,i=t.reloops.get(n);if(i&&i.visel){var a=tt.obj2scaled(r,t.render.options);i.visel.translate(a)}this.data.d=r.negated()}},{key:"invert",value:function(){var t=new o;return t.data=this.data,t}}]),o}(Kr);var Ri=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e,n){var i;return(0,r.Z)(this,o),(i=a.call(this,Jr.R_GROUP_ATTR)).data={rgid:t,attribute:e,value:n},i.data2=null,i}return(0,i.Z)(o,[{key:"execute",value:function(t){if(this.data){var e=this.data,n=e.rgid,r=e.attribute,i=e.value,a=t.molecule.rgroups.get(n);if(!a)return;this.data2||(this.data2={rgid:n,attribute:r,value:a[r]}),a[r]=i,Kr.invalidateItem(t,"rgroups",n)}}},{key:"invert",value:function(){var t=new o;return t.data=this.data2,t.data2=this.data,t}},{key:"isDummy",value:function(t){if(this.data){var e=this.data,n=e.rgid,r=e.attribute,i=e.value;return t.molecule.rgroups.get(n)[r]===i}return!1}}]),o}(Kr);var Pi=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e,n){var i;return(0,r.Z)(this,o),(i=a.call(this,Jr.R_GROUP_FRAGMENT)).rgid_new=t,i.rg_new=n,i.rgid_old=null,i.rg_old=null,i.frid=e,i}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=t.molecule;this.rgid_old=this.rgid_old||gt.findRGroupByFragment(e.rgroups,this.frid),this.rg_old=this.rgid_old?e.rgroups.get(this.rgid_old):null,this.removeOld(e,t),this.setNew(e,t)}},{key:"removeOld",value:function(t,e){this.rg_old&&(this.rg_old.frags.delete(this.frid),e.clearVisel(e.rgroups.get(this.rgid_old).visel),0===this.rg_old.frags.size?(e.rgroups.delete(this.rgid_old),t.rgroups.delete(this.rgid_old),e.markItemRemoved()):e.markItem("rgroups",this.rgid_old,1))}},{key:"setNew",value:function(t,e){if(this.rgid_new){var n=t.rgroups.get(this.rgid_new);n?e.markItem("rgroups",this.rgid_new,1):(n=this.rg_new||new gt,t.rgroups.set(this.rgid_new,n),e.rgroups.set(this.rgid_new,new br(n))),n.frags.add(this.frid)}}},{key:"invert",value:function(){return new o(this.rgid_old,this.frid,this.rg_old)}}]),o}(Kr);var Ti=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e,n){var i;return(0,r.Z)(this,o),(i=a.call(this,Jr.RXN_ARROW_MOVE)).data={id:t,d:e,noinvalidate:n},i}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=t.molecule,n=this.data.id,r=this.data.d;e.rxnArrows.get(n).pos.forEach((function(t){return t.add_(r)})),t.rxnArrows.get(n).visel.translate(tt.obj2scaled(r,t.render.options)),this.data.d=r.negated(),this.data.noinvalidate||Kr.invalidateItem(t,"rxnArrows",n,1)}},{key:"invert",value:function(){var t=new o(this.data.id,this.data.d,this.data.noinvalidate);return t.data=this.data,t}}]),o}(Kr);var ki=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e,n,i,s){var u;return(0,r.Z)(this,o),(u=a.call(this,Jr.RXN_ARROW_RESIZE)).data={id:t,d:e,current:n,anchor:i,noinvalidate:s},u}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=t.molecule,n=this.data.id,r=this.data.d,i=this.data.current,a=e.rxnArrows.get(n),o=this.data.anchor;if(o){var s,u,l,c,d=a.pos[0].get_xy0(),h=a.pos[1].get_xy0();if(yt.isElliptical(a)){var f=(c=t.rxnArrows.get(n)).getReferencePoints();l=(0,m.Z)(f,3)[2]}if(It(o.x)===It(a.pos[1].x)&&It(o.y)===It(a.pos[1].y)&&(a.pos[1].x=o.x=i.x,i.x=h.x,a.pos[1].y=o.y=i.y,i.y=h.y),It(o.x)===It(a.pos[0].x)&&It(o.y)===It(a.pos[0].y)&&(a.pos[0].x=o.x=i.x,i.x=d.x,a.pos[0].y=o.y=i.y,i.y=d.y),It(o.x)===It(null===(s=l)||void 0===s?void 0:s.x)&&It(o.y)===It(null===(u=l)||void 0===u?void 0:u.y)){var p=c.getArrowParams(a.pos[0].x,a.pos[0].y,a.pos[1].x,a.pos[1].y).angle*Math.PI/180,g=Math.cos(p),v=Math.sin(p),y=i.x-o.x,b=(i.y-o.y)*g-y*v;a.height-=b;var w=c.getReferencePoints(),x=(0,m.Z)(w,3)[2];o.y=x.y,o.x=x.x}}else a.pos[1].add_(r);t.rxnArrows.get(n).visel.translate(tt.obj2scaled(r,t.render.options)),this.data.d=r.negated(),this.data.noinvalidate||Kr.invalidateItem(t,"rxnArrows",n,1)}},{key:"invert",value:function(){return new o(this.data.id,this.data.d,this.data.current,this.data.anchor,this.data.noinvalidate)}}]),o}(Kr);var Bi=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e,n){var i;return(0,r.Z)(this,o),(i=a.call(this,Jr.RXN_PLUS_MOVE)).data={id:t,d:e,noinvalidate:n},i}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=this.data,n=e.id,r=e.d,i=e.noinvalidate;t.molecule.rxnPluses.get(n).pp.add_(r);var a=t.rxnPluses.get(n),o=tt.obj2scaled(r,t.render.options);a.visel.translate(o),this.data.d=r.negated(),i||Kr.invalidateItem(t,"rxnPluses",n,1)}},{key:"invert",value:function(){var t=new o;return t.data=this.data,t}}]),o}(Kr);function Ci(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var Mi=function(t){(0,l.Z)(n,t);var e=Ci(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.RXN_PLUS_ADD)).data={plid:null,pos:t},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=new bt;"number"==typeof this.data.plid?e.rxnPluses.set(this.data.plid,n):this.data.plid=e.rxnPluses.add(n);var r=this.data,i=r.pos,a=r.plid,o=e.rxnPluses.get(a);t.rxnPluses.set(a,new Sr(o)),e.rxnPlusSetPos(a,new _(i)),Kr.invalidateItem(t,"rxnPluses",a,1)}},{key:"invert",value:function(){var t=new Zi;return t.data=this.data,t}}]),n}(Kr),Zi=function(t){(0,l.Z)(n,t);var e=Ci(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.RXN_PLUS_DELETE)).data={plid:t,pos:null},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data.plid,n=t.molecule;this.data.pos||(this.data.pos=n.rxnPluses.get(e).pp),t.markItemRemoved();var r=t.rxnPluses.get(e);r&&(t.clearVisel(r.visel),t.rxnPluses.delete(e),n.rxnPluses.delete(e))}},{key:"invert",value:function(){var t=new Mi;return t.data=this.data,t}}]),n}(Kr);function Ni(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var Ii=function(t){(0,l.Z)(n,t);var e=Ni(n);function n(){var t,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:dt.OpenAngle,o=arguments.length>2?arguments[2]:void 0;return(0,r.Z)(this,n),(t=e.call(this,Jr.RXN_ARROW_ADD)).data={pos:i,mode:a,id:o},t}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=new yt({mode:this.data.mode});if(null==this.data.id){var r=e.rxnArrows.add(n);this.data.id=r}else e.rxnArrows.set(this.data.id,n);var i=this.data.id;t.rxnArrows.set(i,new Or(n));var a=(0,u.Z)(this.data.pos);e.rxnArrowSetPos(i,a.map((function(t){return new _(t)}))),Kr.invalidateItem(t,"rxnArrows",i,1)}},{key:"invert",value:function(){return new Li(this.data.id)}}]),n}(Kr),Li=function(t){(0,l.Z)(n,t);var e=Ni(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.RXN_ARROW_DELETE)).data={id:t,pos:[],mode:dt.OpenAngle},i.performed=!1,i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=e.rxnArrows.get(this.data.id);this.data.pos=n.pos,this.data.mode=n.mode,this.performed=!0,t.markItemRemoved(),t.clearVisel(t.rxnArrows.get(this.data.id).visel),t.rxnArrows.delete(this.data.id),e.rxnArrows.delete(this.data.id)}},{key:"invert",value:function(){return new Ii(this.data.pos,this.data.mode,this.data.id)}}]),n}(Kr);function Di(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var _i=function(t){(0,l.Z)(n,t);var e=Di(n);function n(){var t,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:vt.line,o=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=arguments.length>3?arguments[3]:void 0;return(0,r.Z)(this,n),(t=e.call(this,Jr.SIMPLE_OBJECT_ADD)).data={pos:i,mode:a,toCircle:o,id:s},t}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=new Et({mode:this.data.mode});if(null==this.data.id){var r=e.simpleObjects.add(n);this.data.id=r}else e.simpleObjects.set(this.data.id,n);var i=this.data.id;t.simpleObjects.set(i,new Mr(n));var a=(0,u.Z)(this.data.pos);this.data.toCircle&&(a[1]=zi(a[0],a[1])),e.simpleObjectSetPos(i,a.map((function(t){return new _(t)}))),Kr.invalidateItem(t,"simpleObjects",i,1)}},{key:"invert",value:function(){return new ji(this.data.id)}}]),n}(Kr),ji=function(t){(0,l.Z)(n,t);var e=Di(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.SIMPLE_OBJECT_DELETE)).data={id:t,pos:[],mode:vt.line,toCircle:!1},i.performed=!1,i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=e.simpleObjects.get(this.data.id);this.data.pos=n.pos,this.data.mode=n.mode,this.data.toCircle=n.toCircle,this.performed=!0,t.markItemRemoved(),t.clearVisel(t.simpleObjects.get(this.data.id).visel),t.simpleObjects.delete(this.data.id),e.simpleObjects.delete(this.data.id)}},{key:"invert",value:function(){return new _i(this.data.pos,this.data.mode,this.data.toCircle,this.data.id)}}]),n}(Kr),Gi=function(t){(0,l.Z)(n,t);var e=Di(n);function n(t,i,a){var o;return(0,r.Z)(this,n),(o=e.call(this,Jr.SIMPLE_OBJECT_MOVE)).data={id:t,d:i,noinvalidate:a},o}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=this.data.id,r=this.data.d;e.simpleObjects.get(n).pos.forEach((function(t){return t.add_(r)})),t.simpleObjects.get(n).visel.translate(tt.obj2scaled(r,t.render.options)),this.data.d=r.negated(),this.data.noinvalidate||Kr.invalidateItem(t,"simpleObjects",n,1)}},{key:"invert",value:function(){var t=new n(this.data.id,this.data.d,this.data.noinvalidate);return t.data=this.data,t}}]),n}(Kr);function Fi(t,e,n){var r=t.pos[0].get_xy0(),i=t.pos[1].get_xy0();It(e.x)===It(t.pos[1].x)&&(t.pos[1].x=e.x=n.x,n.x=i.x),It(e.y)===It(t.pos[1].y)&&(t.pos[1].y=e.y=n.y,n.y=i.y),It(e.x)===It(t.pos[0].x)&&(t.pos[0].x=e.x=n.x,n.x=r.x),It(e.y)===It(t.pos[0].y)&&(t.pos[0].y=e.y=n.y,n.y=r.y)}var Hi=function(t){(0,l.Z)(n,t);var e=Di(n);function n(t,i,a,o,s,u){var l;return(0,r.Z)(this,n),(l=e.call(this,Jr.SIMPLE_OBJECT_RESIZE)).data={id:t,d:i,current:a,anchor:o,noinvalidate:s,toCircle:u},l}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=this.data.id,r=this.data.d,i=this.data.current,a=e.simpleObjects.get(n),o=this.data.anchor;if(a.mode===vt.ellipse)if(o)Fi(a,o,i);else if(this.data.toCircle){var s=a.pos[1].get_xy0(),u=zi(a.pos[0],i);a.pos[1].x=u.x,a.pos[1].y=u.y,this.data.current=s}else{var l=a.pos[1].get_xy0();a.pos[1].x=i.x,a.pos[1].y=i.y,this.data.current=l}else if(a.mode===vt.line&&o){var c=a.pos[0].get_xy0(),d=a.pos[1].get_xy0();It(o.x)===It(a.pos[1].x)&&It(o.y)===It(a.pos[1].y)&&(a.pos[1].x=o.x=i.x,i.x=d.x,a.pos[1].y=o.y=i.y,i.y=d.y),It(o.x)===It(a.pos[0].x)&&It(o.y)===It(a.pos[0].y)&&(a.pos[0].x=o.x=i.x,i.x=c.x,a.pos[0].y=o.y=i.y,i.y=c.y)}else a.mode===vt.rectangle&&o?Fi(a,o,i):a.pos[1].add_(r);t.simpleObjects.get(n).visel.translate(tt.obj2scaled(r,t.render.options)),this.data.d=r.negated(),this.data.noinvalidate||Kr.invalidateItem(t,"simpleObjects",n,1)}},{key:"invert",value:function(){return new n(this.data.id,this.data.d,this.data.current,this.data.anchor,this.data.noinvalidate,this.data.toCircle)}}]),n}(Kr);function zi(t,e){var n=_.diff(e,t),r=Math.abs(n.x)<Math.abs(n.y)?n.x:n.y;return new _(t.x+(n.x>0?1:-1)*Math.abs(r),t.y+(n.y>0?1:-1)*Math.abs(r),0)}function Ui(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var Vi=function(t){(0,l.Z)(n,t);var e=Ui(n);function n(t,i){var a;return(0,r.Z)(this,n),(a=e.call(this,Jr.S_GROUP_ATOM_ADD,3)).data={sgid:t,aid:i},a}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.aid,r=e.sgid,i=t.molecule,a=i.atoms.get(n);if(i.sgroups.get(r).atoms.indexOf(n)>=0)throw new Error("The same atom cannot be added to an S-group more than once");if(!a)throw new Error("OpSGroupAtomAdd: Atom "+n+" not found");i.atomAddToSGroup(r,n),Kr.invalidateAtom(t,n)}},{key:"invert",value:function(){var t=new Wi;return t.data=this.data,t}}]),n}(Kr),Wi=function(t){(0,l.Z)(n,t);var e=Ui(n);function n(t,i){var a;return(0,r.Z)(this,n),(a=e.call(this,Jr.S_GROUP_ATOM_REMOVE,4)).data={sgid:t,aid:i},a}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.aid,r=e.sgid,i=t.molecule,a=i.atoms.get(n),o=i.sgroups.get(r);a&&o&&(st.removeAtom(o,n),a.sgs.delete(r),Kr.invalidateAtom(t,n))}},{key:"invert",value:function(){var t=new Vi;return t.data=this.data,t}}]),n}(Kr);var Yi=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e,n){var i;return(0,r.Z)(this,o),(i=a.call(this,Jr.S_GROUP_ATTR,4)).data={sgid:t,attr:e,value:n},i}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=t.molecule,n=this.data.sgid,r=e.sgroups.get(n);if(r){var i=t.sgroupData.get(n);"DAT"===r.type&&i&&(t.clearVisel(i.visel),t.sgroupData.delete(n)),this.data.value=r.setAttr(this.data.attr,this.data.value)}}},{key:"invert",value:function(){var t=new o;return t.data=this.data,t}}]),o}(Kr);var qi=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e){var n;return(0,r.Z)(this,o),(n=a.call(this,Jr.S_GROUP_DATA_MOVE)).data={id:t,d:e},n}return(0,i.Z)(o,[{key:"execute",value:function(t){var e,n=this.data,r=n.d,i=n.id;null===(e=t.molecule.sgroups.get(i).pp)||void 0===e||e.add_(r),this.data.d=r.negated(),Kr.invalidateItem(t,"sgroupData",i,1)}},{key:"invert",value:function(){var t=new o;return t.data=this.data,t}}]),o}(Kr);function $i(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var Xi=function(t){(0,l.Z)(n,t);var e=$i(n);function n(t,i,a){var o;return(0,r.Z)(this,n),(o=e.call(this,Jr.S_GROUP_ADD_TO_HIERACHY,100)).data={sgid:t,parent:i,children:a},o}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.sgid,r=e.parent,i=e.children,a=t.molecule,o=a.sgroups.get(n),s=a.sGroupForest.insert(o,r,i);this.data.parent=s.parent,this.data.children=s.children}},{key:"invert",value:function(){var t=new Ki;return t.data=this.data,t}}]),n}(Kr),Ki=function(t){(0,l.Z)(n,t);var e=$i(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.S_GROUP_REMOVE_FROM_HIERACHY,110)).data={sgid:t},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data.sgid,n=t.molecule;this.data.parent=n.sGroupForest.parent.get(e),this.data.children=n.sGroupForest.children.get(e),n.sGroupForest.remove(e)}},{key:"invert",value:function(){var t=new Xi;return t.data=this.data,t}}]),n}(Kr);function Ji(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var Qi=function(t){(0,l.Z)(n,t);var e=Ji(n);function n(t,i,a,o,s){var u;return(0,r.Z)(this,n),(u=e.call(this,Jr.S_GROUP_CREATE)).data={sgid:t,type:i,pp:a,expanded:o,name:s},u}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=new st(this.data.type),r=this.data,i=r.sgid,a=r.pp,o=r.expanded,s=r.name;n.id=i,e.sgroups.set(i,n),a&&(e.sgroups.get(i).pp=new _(a)),o&&(n.data.expanded=o),s&&(n.data.name=s),t.sgroups.set(i,new Tr(e.sgroups.get(i))),ft.isFunctionalGroup(n)&&t.molecule.functionalGroups.add(new ft(n)),this.data.sgid=i}},{key:"invert",value:function(){var t=new ta;return t.data=this.data,t}}]),n}(Kr),ta=function(t){(0,l.Z)(n,t);var e=Ji(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.S_GROUP_DELETE,95)).data={sgid:t},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=this.data.sgid,r=t.sgroups.get(n),i=t.sgroupData.get(n);if(r){if(this.data.type=r.item.type,this.data.pp=r.item.pp,"DAT"===r.item.type&&i&&(t.clearVisel(i.visel),t.sgroupData.delete(n)),t.clearVisel(r.visel),0!==r.item.atoms.length)throw new Error("S-Group not empty!");var a;ft.isFunctionalGroup(r.item)&&(this.data.name=r.item.data.name,this.data.expanded=r.item.expanded,t.molecule.functionalGroups.forEach((function(t,e){t.relatedSGroupId===n&&(a=e)})),t.molecule.functionalGroups.delete(a)),t.sgroups.delete(n),e.sgroups.delete(n)}}},{key:"invert",value:function(){var t=new Qi;return t.data=this.data,t}}]),n}(Kr);function ea(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var na=function(t){(0,l.Z)(n,t);var e=ea(n);function n(t,i,a,o){var s;return(0,r.Z)(this,n),(s=e.call(this,Jr.TEXT_CREATE)).data={content:t,position:i,pos:a,id:o},s}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=new Bt(this.data);if(null==this.data.id){var n=t.molecule.texts.add(e);this.data.id=n}else t.molecule.texts.set(this.data.id,e);var r=this.data.id;t.texts.set(r,new _r(e)),t.molecule.textSetPosition(r,new _(this.data.position)),Kr.invalidateItem(t,"texts",r,1)}},{key:"invert",value:function(){return new ra(this.data.id)}}]),n}(Kr),ra=function(t){(0,l.Z)(n,t);var e=ea(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Jr.TEXT_DELETE)).data={id:t},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=e.texts.get(this.data.id);n&&(this.data.content=n.content,this.data.position=n.position,t.markItemRemoved(),t.clearVisel(t.texts.get(this.data.id).visel),t.texts.delete(this.data.id),e.texts.delete(this.data.id))}},{key:"invert",value:function(){return new na(this.data.content,this.data.position,this.data.pos,this.data.id)}}]),n}(Kr);var ia=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e){var n;return(0,r.Z)(this,o),(n=a.call(this,Jr.TEXT_UPDATE)).data={id:t,content:e},n}return(0,i.Z)(o,[{key:"execute",value:function(t){var e=this.data,n=e.id,r=e.content,i=t.molecule.texts.get(n);i&&(this.data.previousContent=i.content,i.content=r),Kr.invalidateItem(t,"texts",n,1)}},{key:"invert",value:function(){var t=new o(this.data.id,this.data.previousContent);return t.data.previousContent=this.data.content,t}}]),o}(Kr);var aa=function(t){(0,l.Z)(o,t);var e,n,a=(e=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,d.Z)(e);if(n){var i=(0,d.Z)(this).constructor;t=Reflect.construct(r,arguments,i)}else t=r.apply(this,arguments);return(0,c.Z)(this,t)});function o(t,e,n){var i;return(0,r.Z)(this,o),(i=a.call(this,Jr.TEXT_MOVE)).data={id:t,d:e,noinvalidate:n},i}return(0,i.Z)(o,[{key:"execute",value:function(t){var e,n,r=t.molecule,i=this.data.id,a=this.data.d,o=r.texts.get(i);null==o||null===(e=o.position)||void 0===e||e.add_(a),null===(n=t.texts.get(i))||void 0===n||n.visel.translate(tt.obj2scaled(a,t.render.options)),this.data.d=a.negated(),this.data.noinvalidate||Kr.invalidateItem(t,"texts",i,1)}},{key:"invert",value:function(){var t=new o(this.data.id,this.data.d,this.data.noinvalidate);return t.data=this.data,t}}]),o}(Kr),oa=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];(0,r.Z)(this,t),this.operations=e}return(0,i.Z)(t,[{key:"addOp",value:function(t,e){return e&&t.isDummy(e)||this.operations.push(t),t}},{key:"mergeWith",value:function(t){return this.operations=this.operations.concat(t.operations),this}},{key:"perform",value:function(e){var n=new t;return(0,u.Z)(this.operations).sort((function(t,e){return t.priority-e.priority})).forEach((function(t){var r=t.perform(e);n.addOp(r)})),n}},{key:"isDummy",value:function(t){return void 0===this.operations.find((function(e){return!t||!e.isDummy(t)}))}}]),t}();var sa=["id","dist"];function ua(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}var la=.4,ca={atoms:da,bonds:ha,enhancedFlags:function(t,e,n,r,i){var a,o=null;return t.enhancedFlags.forEach((function(n,r){var s=t.molecule.frags.get(r);if(s&&s.enhancedStereoFlag&&i.showStereoFlags){var u=s.stereoFlagPosition?new _(s.stereoFlagPosition.x,s.stereoFlagPosition.y):Q.getDefaultStereoFlagPosition(t.molecule,r);if(u&&!(Math.abs(e.x-u.x)>=1)){var l=Math.abs(e.y-u.y);l<.3&&(!o||l<a)&&(o={id:r,dist:a=l})}}})),o},sgroupData:function(t,e){var n=null,r=null;return t.sgroupData.forEach((function(t,i){if("DAT"!==t.sgroup.type)throw new Error("Data group expected");if("MRV_IMPLICIT_H"!==t.sgroup.data.fieldName){var a=t.sgroup.dataArea,o=a.p0.y<e.y&&a.p1.y>e.y&&a.p0.x<e.x&&a.p1.x>e.x,s=Math.min(Math.abs(a.p0.x-e.x),Math.abs(a.p1.x-e.x));o&&(null===r||s<n)&&(r={id:i,dist:s},n=s)}})),r},sgroups:function(t,e){var n=null,r=la;return t.molecule.sgroups.forEach((function(t,i){if(t.functionalGroup&&!t.expanded){var a=t.firstSgroupAtom.pp,o=t.bracketDir,s=o.rotateSC(1,0),u=new _(_.dot(e,o),_.dot(e,s)),l=new _(.625,.625),c={p0:_.diff(a,l),p1:_.sum(a,l)},d=c.p0.y<u.y&&c.p1.y>u.y&&c.p0.x<u.x&&c.p1.x>u.x,h=Math.min(Math.abs(c.p0.x-u.x),Math.abs(c.p1.x-u.x));d&&(null===n||h<r)&&(n=i,r=h)}else{var f=t.bracketDir,p=f.rotateSC(1,0),m=new _(_.dot(e,f),_.dot(e,p));t.areas.forEach((function(t){var e=t.p0.y<m.y&&t.p1.y>m.y&&t.p0.x<m.x&&t.p1.x>m.x,a=Math.min(Math.abs(t.p0.x-m.x),Math.abs(t.p1.x-m.x));e&&(null===n||a<r)&&(n=i,r=a)}))}})),null!==n?{id:n,dist:r}:null},rxnArrows:function(t,e){var n=null,r=null,i=null;return t.rxnArrows.forEach((function(a,o){var s=a.calcDistance(e,t.render.options.scale);s.minDist<.3&&(!i||s.minDist<n)&&(n=s.minDist,r=s.refPoint,i={id:o,dist:n,ref:r})})),i},rxnPluses:function(t,e){var n=null,r=null;return t.rxnPluses.forEach((function(t,i){var a=t.item.pp,o=Math.max(Math.abs(e.x-a.x),Math.abs(e.y-a.y));o<.3&&(!r||o<n)&&(r={id:i,dist:n=o})})),r},frags:function(t,e,n,r,i){r=Math.min(r||la,la);var a=t.molecule,o=da(t,e,n,r);if(o)return{id:a.atoms.get(o.id).fragment,dist:o.dist};var s=ha(t,e,n,r,i);if(s){var u=a.bonds.get(s.id).begin;return{id:a.atoms.get(u).fragment,dist:s.dist}}return null},rgroups:function(t,e,n,r){r=Math.min(r||la,la);var i=null;return t.rgroups.forEach((function(t,a){if(a!==n&&t.labelBox&&t.labelBox.contains(e,.5)){var o=_.dist(t.labelBox.centre(),e);(!i||o<r)&&(i={id:a,dist:r=o})}})),i},simpleObjects:function(t,e){var n=null,r=null,i=null;return t.simpleObjects.forEach((function(a,o){var s=a.calcDistance(e,t.render.options.scale);s.minDist<.3&&(!i||s.minDist<n)&&(n=s.minDist,r=s.refPoint,i={id:o,dist:n,ref:r})})),i},texts:function(t,e){var n=null,r=null;return t.texts.forEach((function(i,a){var o=i.getReferencePoints(t),s=o[0].x,u=o[0].y,l=o[2].x,c=o[2].y,d=[];e.x>=s&&e.x<=l&&(e.y<u?d.push(u-e.y):e.y>c?d.push(e.y-c):d.push(e.y-u,c-e.y)),e.x<s&&e.y<u&&d.push(_.dist(new _(s,u),e)),e.x>l&&e.y>c&&d.push(_.dist(new _(l,c),e)),e.x<s&&e.y>c&&d.push(_.dist(new _(s,c),e)),e.x>l&&e.y<u&&d.push(_.dist(new _(l,u),e)),e.y>=u&&e.y<=c&&(e.x<s?d.push(s-e.x):e.x>l?d.push(e.x-l):d.push(0));var h=Math.min.apply(Math,d);h<la&&(!r||h<n)&&(r={id:a,dist:n=h})})),r}};function da(t,e,n,r){var i=null,a=la,o=n&&"atoms"===n.map?n.id:null;return r=r||a,r=Math.min(r,a),t.atoms.forEach((function(t,n){if(n!==o){var a=_.dist(e,t.a.pp);a<r&&(i=n,r=a)}})),null!==i?{id:i,dist:r}:null}function ha(t,e,n,r,i){var a=null,o=null,s=.8*la,u=n&&"bonds"===n.map?n.id:null;r=r||s;var l=r=Math.min(r,s);return t.bonds.forEach((function(n,r){if(r!==u){var i=t.atoms.get(n.b.begin).a.pp,a=t.atoms.get(n.b.end).a.pp,s=_.lc2(i,.5,a,.5),c=_.dist(e,s);c<l&&(l=c,o=r)}})),t.bonds.forEach((function(n,i){if(i!==u){var o=t.molecule.halfBonds.get(n.b.hb1),s=o.dir,l=o.norm,c=t.atoms.get(n.b.begin).a.pp,d=t.atoms.get(n.b.end).a.pp;if(_.dot(e.sub(c),s)*_.dot(e.sub(d),s)<0){var h=Math.abs(_.dot(e.sub(c),l));h<r&&(a=i,r=h)}}})),null!==o?{id:o,dist:l}:null!==a&&r>la*i?{id:a,dist:r}:null}var fa={atom:da,item:function(t,e,n,r,i){return(n=n||Object.keys(ca)).reduce((function(n,o){var s=n?n.dist:null,u=ca[o](t,e,r,s,i);return null!==u&&(null===n||u.dist<n.dist)?function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ua(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ua(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}({map:o,id:u.id,dist:u.dist},(0,S.Z)(u,sa)):n}),null)},merge:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:["atoms","bonds"],r=arguments.length>3?arguments[3]:void 0,i={atoms:new Map,bonds:new Map},a=t.molecule;e.atoms.forEach((function(t){i.atoms.set(t,a.atoms.get(t).pp)})),e.bonds.forEach((function(t){var e=a.bonds.get(t);i.bonds.set(t,_.lc2(a.atoms.get(e.begin).pp,.5,a.atoms.get(e.end).pp,.5))}));var o={};return n.forEach((function(n){o[n]=Array.from(i[n].keys()).reduce((function(a,o){var s={map:n,id:o},u=ca[n](t,i[n].get(o),s,null,r);return u&&!e[n].includes(u.id)&&a.set(o,u.id),a}),new Map)})),o}};function pa(t,e,n){return t.molecule.atoms.get(e)[n]}function ma(t,e){return t.atoms.get(e).a.neighbors.length}function ga(t,e){return Array.from(t.atoms.get(e).a.sgs)}function va(t,e){return t.molecule.atoms.get(e).pp}function ya(t,e){return e.filter((function(e){return null!==t.atoms.get(e).stereoLabel}))}function ba(t){return["atoms","bonds","frags","sgroups","rgroups","rxnArrows","rxnPluses","simpleObjects","texts"].reduce((function(e,n){return e[n]=Array.from(t[n].keys()),e}),{})}function wa(t,e,n){var r,i,a=[],o=va(t,e),s=t.molecule.atomGetNeighbors(e),u=t.molecule.findBondId(e,s.length?null===(r=s[0])||void 0===r?void 0:r.aid:void 0),l=t.molecule.bonds.get(u),c=l?l.type:n?n.type:1;t.molecule.atomGetNeighbors(e).forEach((function(e){var n=va(t,e.aid);_.dist(o,n)<.1||a.push({id:e.aid,v:_.diff(n,o)})})),a.sort((function(t,e){return Math.atan2(t.v.y,t.v.x)-Math.atan2(e.v.y,e.v.x)}));var d,h=0,f=0;for(i=0;i<a.length;i++)(d=_.angle(a[i].v,a[(i+1)%a.length].v))<0&&(d+=2*Math.PI),d>f&&(h=i,f=d);var p=new _(1,0);if(a.length>0){if(1===a.length){f=-4*Math.PI/3;var m=t.molecule.atomGetNeighbors(e)[0];if(ma(t,m.aid)>1){var g=[],v=va(t,m.aid),y=_.diff(o,v),b=Math.atan2(y.y,y.x);t.molecule.atomGetNeighbors(m.aid).forEach((function(e){var n=va(t,e.aid);if(!(e.bid===m.bid||_.dist(v,n)<.1)){var r=_.diff(n,v),i=Math.atan2(r.y,r.x)-b;i<0&&(i+=2*Math.PI),g.push(i)}})),g.sort((function(t,e){return t-e})),g[0]<=1.01*Math.PI&&g[g.length-1]<=1.01*Math.PI&&(f*=-1)}}if(1===a.length&&c===(null==n?void 0:n.type)&&((null==n?void 0:n.type)===q.PATTERN.TYPE.DOUBLE||(null==n?void 0:n.type)===q.PATTERN.TYPE.TRIPLE)||c===q.PATTERN.TYPE.SINGLE&&(null==n?void 0:n.type)===q.PATTERN.TYPE.TRIPLE||c===q.PATTERN.TYPE.TRIPLE&&(null==n?void 0:n.type)===q.PATTERN.TYPE.SINGLE){var w=t.molecule.bonds.get(u).angle;d=w>-90&&w<90&&a[0].v.x>0?w*Math.PI/180+Math.PI:w*Math.PI/180}else d=f/2+Math.atan2(a[h].v.y,a[h].v.x);p=p.rotate(d)}p.add_(o);var x=fa.atom(t,p,null,.1);return{atom:x=null===x?{label:"C"}:x.id,pos:p}}function xa(t,e){return t.molecule.sgroups.filter((function(t,n){return!n.data.attached&&!n.data.absolute&&0===(0,b.difference)(n.atoms,e).length}))}function Ea(t,e){var n=t.begin,r=t.end;if(!e.atoms)return!1;var i=e.atoms.includes(n)&&!e.atoms.includes(r),a=e.atoms.includes(r)&&!e.atoms.includes(n);return i||a}function Oa(t,e,n){var r=new oa;return Object.keys(n).forEach((function(t){r.addOp(new Ri(e,t,n[t]))})),r.perform(t)}function Aa(t,e,n){var r=new oa;return r.addOp(new Pi(e,n)),r.perform(t)}function Sa(t,e,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],i=new oa;return t.molecule.rgroups.get(n)||i.addOp(new mi(e,n,r)),i.perform(t)}function Ra(t,e,n,r){var i=r.fieldValue;return"string"==typeof i||"DAT"!==e?Ba(t,e,n,r,t.molecule.sgroups.newId()):i.reduce((function(i,a){var o=Object.assign({},r);return o.fieldValue=a,i.mergeWith(Ba(t,e,n,o,t.molecule.sgroups.newId()))}),new oa)}function Pa(t,e,n){var r=new oa;Object.keys(n).forEach((function(t){r.addOp(new Yi(e,t,n[t]))}));var i=t.molecule.sgroups.get(e);return i.firstSgroupAtom&&delete i.firstSgroupAtom,st.getAtoms(t,i).forEach((function(e){r.mergeWith(Ua(t,e,t.atoms.get(e).a,!1))})),r.perform(t)}function Ta(t,e){var n=new oa;return Object.keys(e).forEach((function(r){n.addOp(new Yi(t,r,e[r]))})),n}function ka(t,e){var n=new oa,r=t.molecule,i=t.sgroups.get(e).item;"SRU"===i.type&&(r.sGroupsRecalcCrossBonds(),i.neiAtoms.forEach((function(e){"*"===pa(t,e,"label")&&n.addOp(new Qr(e,"label","C"))})));var a=r.sgroups.get(e),o=st.getAtoms(r,a),s=a.getAttrs();return n.addOp(new Ki(e)),o.forEach((function(t){n.addOp(new Wi(e,t))})),n.addOp(new ta(e)),(n=n.perform(t)).mergeWith(Ta(e,s)),n}function Ba(t,e,n,r,i,a,o,s){var u=new oa;if(i=i-0===i?i:t.molecule.sgroups.newId(),"SUP"===e?u.addOp(new Qi(i,e,a,o,s)):u.addOp(new Qi(i,e,a)),n.forEach((function(t){u.addOp(new Vi(i,t))})),u.addOp("DAT"!==e?new Xi(i):new Xi(i,-1,[])),u=u.perform(t),"SRU"===e){t.molecule.sGroupsRecalcCrossBonds();var l=new oa;t.sgroups.get(i).item.neiAtoms.forEach((function(e){var n=t.atoms.get(e).a.isPlainCarbon();1===ma(t,e)&&n&&l.addOp(new Qr(e,"label","*"))})),(l=l.perform(t)).mergeWith(u),u=l}return function(t,e,n){var r=new oa;return Object.keys(n).forEach((function(t){r.addOp(new Yi(e,t,n[t]))})),r.perform(t)}(t,i,r).mergeWith(u)}function Ca(t,e,n,r,i){if(t===Fo.Bond)return function(t,e,n,r){var i=t.molecule,a=Ia(i,n);return r.bonds&&(a=(0,B.uniq)(a.concat(r.bonds))),a.reduce((function(n,r){var a=i.bonds.get(r);return n.action=n.action.mergeWith(Ra(t,e.type,[a.begin,a.end],e.attrs)),n.selection.bonds.push(r),n}),{action:new oa,selection:{atoms:n,bonds:[]}})}(e,n,r,i);var a,o=(a=e.molecule,(i.bonds||[]).reduce((function(t,e){var n=a.bonds.get(e);return t.concat([n.begin,n.end])}),[])),s=(0,B.uniq)(r.concat(o));return t===Fo.Fragment?Ma(e,n,s,Array.from(e.atoms.keys())):t===Fo.Multifragment?function(t,e,n){var r=Ia(t.molecule,n);return{action:Ra(t,e.type,n,e.attrs),selection:{atoms:n,bonds:r}}}(e,n,s):t===Fo.Group?Ma(e,n,s,s):t===Fo.Atom?function(t,e,n){return n.reduce((function(n,r){return n.action=n.action.mergeWith(Ra(t,e.type,[r],e.attrs)),n}),{action:new oa,selection:{atoms:n,bonds:[]}})}(e,n,s):{action:Ra(e,n.type,r,n.attrs)}}function Ma(t,e,n,r){var i=new H(n.map((function(e){return t.atoms.get(e).a.fragment})));return Array.from(i).reduce((function(n,i){var a=r.reduce((function(e,n){var r=t.atoms.get(n).a;return i===r.fragment&&e.push(n),e}),[]),o=Ia(t.molecule,a);return n.action=n.action.mergeWith(Ra(t,e.type,a,e.attrs)),n.selection.atoms=n.selection.atoms.concat(a),n.selection.bonds=n.selection.bonds.concat(o),n}),{action:new oa,selection:{atoms:[],bonds:[]}})}function Za(t,e,n){var r=ga(e,n);return r.length>0&&(r.forEach((function(e){t.addOp(new Wi(e,n))})),!0)}function Na(t,e,n){var r=e.molecule,i=new Map;n.forEach((function(t){ga(e,t).forEach((function(t){i.set(t,i.has(t)?i.get(t)+1:1)}))})),i.forEach((function(n,i){var a=e.sgroups.get(i).item;if(st.getAtoms(e.molecule,a).length===n){var o=r.sgroups.get(i);t.mergeWith(Ta(i,o.getAttrs())),t.addOp(new Ki(i)),t.addOp(new ta(i))}}))}function Ia(t,e){var n=new H(e);return Array.from(t.bonds.keys()).filter((function(e){var r=t.bonds.get(e);return n.has(r.begin)&&n.has(r.end)}))}function La(t,e,n,r,i,a){var o;if(void 0===r){var s=wa(t,n,e);r=s.atom,i=s.pos}var u=new oa,l=t.molecule,c=!1,d=null;"number"!=typeof n?"number"==typeof r&&(d=pa(t,r,"fragment")):(d=pa(t,n,"fragment"),"number"==typeof r&&(c=!0)),null==d&&(d=u.addOp((new yi).perform(t)).frid),"number"!=typeof n?(n.fragment=d,n=u.addOp(new ni(n,i).perform(t)).data.aid,"number"==typeof r&&qa(u,t,[n],r),i=a):"*"===pa(t,n,"label")&&u.addOp(new Qr(n,"label","C").perform(t)),"number"!=typeof r?(r.fragment=d,r=u.addOp(new ni(r,i).perform(t)).data.aid,"number"==typeof n&&qa(u,t,[r],n)):"*"===pa(t,r,"label")&&u.addOp(new Qr(r,"label","C").perform(t));var h=u.addOp(new si(n,r,e).perform(t)).data.bid,f=l.bonds.get(h);return f&&(u.addOp(new Ai([f.begin,f.end]).perform(t)),u.mergeWith(_a(t,f))),u.operations.reverse(),c&&Ya(u,t,n,r),null!==(o=l.frags.get(d||0))&&void 0!==o&&o.stereoAtoms&&!e.stereo&&u.addOp(new Oi(d||0).perform(t)),[u,n,r,h]}function Da(t,e,n,r){var i=t.molecule,a=new oa;return(Array.isArray(e)?e:[e]).forEach((function(e){Object.keys(q.attrlist).forEach((function(o){if(o in n||r){var s=o in n?n[o]:q.attrGetDefault(o);if(a.addOp(new ii(e,o,s).perform(t)),"stereo"===o&&o in n){var u=i.bonds.get(e);u&&(a.addOp(new Ai([u.begin,u.end]).perform(t)),a.mergeWith(_a(t,u)))}}}))})),a}function _a(t,e,n){var r,i,a=new oa,o=t.molecule,s=null===(r=o.atoms.get(null==e?void 0:e.begin))||void 0===r?void 0:r.fragment,u=null===(i=o.atoms.get(null==e?void 0:e.end))||void 0===i?void 0:i.fragment,l=[];return o.bonds.forEach((function(t){var e,n;(null===(e=o.atoms.get(t.begin))||void 0===e?void 0:e.fragment)===s&&l.push(t),s!==u&&(null===(n=o.atoms.get(t.begin))||void 0===n?void 0:n.fragment)===u&&l.push(t)})),ja(o,l,e).forEach((function(e,r){var i;(null===(i=o.atoms.get(r))||void 0===i?void 0:i.stereoLabel)!==e.stereoLabel&&a.mergeWith(function(t,e,n,r){var i=new oa,a=t.molecule.atoms.get(e);if(a){var o=a.fragment;"stereoParity"in n&&i.addOp(new Qr(e,"stereoParity",n.stereoParity).perform(t)),"stereoLabel"in n&&(i.addOp(new Qr(e,"stereoLabel",n.stereoLabel).perform(t)),null===n.stereoLabel?i.addOp(new Ei(o,e).perform(t)):i.addOp(new xi(o,e).perform(t))),r&&i.operations.reverse()}return i}(t,r,e,n))})),a}function ja(t,e,n){var r=new Map,i=[];return e.forEach((function(e){if(e){var n=t.atomGetNeighbors(e.begin),a=t.atomGetNeighbors(e.end);if(et.isCorrectStereoCenter(e,n,a,t)){var o,s,u=null===(o=t.atoms.get(e.begin))||void 0===o?void 0:o.stereoLabel;null!=u&&null!=(null===(s=r.get(e.begin))||void 0===s?void 0:s.stereoLabel)||r.set(e.begin,{stereoParity:Ga(e.stereo),stereoLabel:u||"".concat(F.Abs)}),i.push(e.begin)}else i.includes(e.begin)||r.set(e.begin,{stereoParity:W.PATTERN.STEREO_PARITY.NONE,stereoLabel:null}),i.includes(e.end)||r.set(e.end,{stereoParity:W.PATTERN.STEREO_PARITY.NONE,stereoLabel:null})}})),n&&(i.includes(n.begin)||r.set(n.begin,{stereoParity:W.PATTERN.STEREO_PARITY.NONE,stereoLabel:null}),i.includes(n.end)||r.set(n.end,{stereoParity:W.PATTERN.STEREO_PARITY.NONE,stereoLabel:null})),r}function Ga(t){var e=null;switch(t){case q.PATTERN.STEREO.UP:e=W.PATTERN.STEREO_PARITY.ODD;break;case q.PATTERN.STEREO.EITHER:e=W.PATTERN.STEREO_PARITY.EITHER;break;case q.PATTERN.STEREO.DOWN:e=W.PATTERN.STEREO_PARITY.EVEN}return e}function Fa(t,e,n,r){var i=new oa,a=e;(r.stereo!==q.PATTERN.STEREO.NONE&&r.type===q.PATTERN.TYPE.SINGLE||n.type===q.PATTERN.TYPE.DATIVE)&&n.type===r.type&&n.stereo===r.stereo&&(i.mergeWith(function(t,e){var n=t.molecule.bonds.get(e),r=new oa;return r.addOp(new ui(e).perform(t)),Number.isInteger(null==n?void 0:n.end)&&Number.isInteger(null==n?void 0:n.begin)&&r.addOp(new si(null==n?void 0:n.end,null==n?void 0:n.begin,n).perform(t)),r}(t,e)),a=i.operations[1].data.bid);var o=Ha.includes(r.type)?Ha:null;return r.stereo===q.PATTERN.STEREO.NONE&&r.type===q.PATTERN.TYPE.SINGLE&&n.stereo===q.PATTERN.STEREO.NONE&&o&&(r.type=o[(o.indexOf(n.type)+1)%o.length]),Da(t,a,r).mergeWith(i)}var Ha=[q.PATTERN.TYPE.SINGLE,q.PATTERN.TYPE.DOUBLE,q.PATTERN.TYPE.TRIPLE];function za(t,e,n){n=Object.assign({},n);var r=new oa;n.fragment=r.addOp((new yi).perform(t)).frid;var i=r.addOp(new ni(n,e).perform(t)).data.aid;return r.addOp(new Ai([i]).perform(t)),r}function Ua(t,e,n,r){var i=new oa;return(Array.isArray(e)?e:[e]).forEach((function(e){var a;Object.keys(W.attrlist).forEach((function(a){if(("attpnt"!==a||a in n)&&(a in n||r)){var o=a in n?n[a]:W.attrGetDefault(a);switch(a){case"stereoLabel":case"stereoParity":a in n&&o&&i.addOp(new Qr(e,a,o).perform(t));break;default:i.addOp(new Qr(e,a,o).perform(t))}}})),r||!("label"in n)||null===n.label||"L#"===n.label||"atomList"in n||i.addOp(new Qr(e,"atomList",null).perform(t)),i.addOp(new Ai([e]).perform(t));var o=t.molecule.atomGetNeighbors(e),s=t.molecule.bonds.get(null===(a=o[0])||void 0===a?void 0:a.bid);s&&i.mergeWith(_a(t,s))})),i}function Va(t,e,n){var r=new oa;return e.forEach((function(e){var i=t.molecule.atoms.get(e),a=i.fragment;r.addOp(new Qr(e,"fragment",n)),null!==i.stereoLabel&&(r.addOp(new xi(n,e)),r.addOp(new Ei(a,e)))})),r.perform(t)}function Wa(t,e,n){var r,i;if(e===n)return new oa;var a=new oa;Ya(a,t,e,n);var o=new oa,s=t.molecule.atomGetNeighbors(e);s.forEach((function(e){var r=t.molecule.bonds.get(e.bid);if(n!==r.begin&&n!==r.end){var i=r.begin===e.aid?e.aid:n,a=r.begin===e.aid?n:e.aid,s=t.molecule.findBondId(i,a);if(null===s)o.addOp(new si(i,a,r));else{var u=q.getAttrHash(r);Object.keys(u).forEach((function(t){o.addOp(new ii(s,t,u[t]))}))}o.addOp(new ui(e.bid))}else o.addOp(new ui(e.bid))}));var u=W.getAttrHash(t.molecule.atoms.get(e));1===ma(t,e)&&"*"===u.label&&(u.label="C"),Object.keys(u).forEach((function(t){"stereoLabel"!==t&&"stereoParity"!==t&&o.addOp(new Qr(n,t,u[t]))})),Za(o,t,e)&&Na(o,t,[e]),o.addOp(new ri(e));var l=t.molecule.atomGetNeighbors(n),c=t.molecule.bonds.get((null===(r=l[0])||void 0===r?void 0:r.bid)||(null===(i=s[0])||void 0===i?void 0:i.bid));return o.perform(t).mergeWith(a).mergeWith(_a(t,c))}function Ya(t,e,n,r){var i=pa(e,n,"fragment"),a=pa(e,r,"fragment");if(a!==i&&"number"==typeof a){var o=e.molecule,s=gt.findRGroupByFragment(o.rgroups,a);void 0!==s&&t.mergeWith(Aa(e,null,a)).mergeWith(Sa(e,0,s));var u=o.getFragmentIds(i),l=[];o.atoms.forEach((function(t,e){t.fragment===a&&l.push(e)}));var c=Va(e,l,i);qa(t,e,u,r),t.addOp(new bi(a).perform(e)),t.mergeWith(c)}}function qa(t,e,n,r){ga(e,r).forEach((function(r){var i=e.molecule.sgroups.get(r);"DAT"===i.type&&["Atom","Bond","Group"].includes(i.data.context)||(0,B.without)(i.atoms,n).forEach((function(n){return t.addOp(new Vi(r,n).perform(e))}))}))}function $a(t,e){var n=new oa;return n.addOp(new li(e)),n.perform(t)}function Xa(t){var e=new oa;return e.addOp(new di),e.perform(t)}function Ka(t,e,n,r,i){var a=Math.cos(Math.PI/6),o=Math.sin(Math.PI/6),s=new oa,u=null!==i?pa(t,i,"fragment"):s.addOp((new yi).perform(t)).frid,l={atoms:[],bonds:[]},c=null!==i?i:s.addOp(new ni({label:"C",fragment:u},e).perform(t)).data.aid;l.atoms.push(c),s.operations.reverse();for(var d=0;d<r;d++){var h=La(t,{},c,{},new _(a*(d+1),1&d?0:o).rotate(n).add(e));s=h[0].mergeWith(s),c=h[2],l.bonds.push(h[3]),l.atoms.push(c)}return[s,l]}function Ja(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Qa(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Qa(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function Qa(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function to(t,e){var n=new oa;if(!e)return n;var r=new Set,i=function(t,e,n){var r,i=new Set(e),a=new Set,o=Ja(n);try{for(o.s();!(r=o.n()).done;){var s=r.value,l=t.bonds.get(s);if(l){var c=l.b,d=c.begin,h=c.end;i.add(d).add(h)}}}catch(t){o.e(t)}finally{o.f()}var f,p=Ja(i);try{var m=function(){var e=f.value;if(a.has(e))return"continue";var n=(0,u.Z)(t.connectedComponents.values()).find((function(t){return t.has(e)}));n&&n.forEach((function(t){return a.add(t)}))};for(p.s();!(f=p.n()).done;)m()}catch(t){p.e(t)}finally{p.f()}return a}(t,ro(e.atoms),ro(e.bonds));return e.atoms.forEach((function(e,i){r.has(e)||r.has(i)||(n=Wa(t,i,e).mergeWith(n),r.add(e).add(i))})),n=function(t,e){var n=t.molecule,r=new Map,i=new oa;return e.forEach((function(t,e){var i=n.bonds.get(e),a=n.bonds.get(t);if(i&&a){var o=Yr.mergeBondsParams(n,i,n,a);o.merged&&(r.set(i.begin,o.cross?a.end:a.begin),r.set(i.end,o.cross?a.begin:a.end))}})),r.forEach((function(e,n){i=Wa(t,n,e).mergeWith(i)})),i}(t,e.bonds).mergeWith(n),n=function(t,e){var n=new oa;if(!e)return n;var r=new Set;return e.forEach((function(e){r.has(e)||(n=function(t,e){var n=new oa;return t.atoms.has(e)?(n.addOp(new Ai([e])),n.perform(t)):n}(t,e).mergeWith(n),r.add(e))})),n}(t,i).mergeWith(n),n}function eo(t,e){var n=t.render.ctab.molecule,r=e||{atoms:Array.from(n.atoms.keys()),bonds:Array.from(n.bonds.keys())};return function(t,e){var n={atoms:new Map(e.atoms),bonds:new Map(e.bonds)};return e.bonds.forEach((function(e,r){var i=t.bonds.get(r),a=t.bonds.get(e);Yr.mergeBondsParams(t,i,t,a).merged?(n.atoms.delete(i.begin),n.atoms.delete(i.end)):n.bonds.delete(r)})),0===n.atoms.size&&0===n.bonds.size?null:n}(n,t.findMerge(r,["atoms","bonds"]))}function no(t){if(!t)return null;var e={atoms:Array.from(t.atoms.values()),bonds:Array.from(t.bonds.values())};return{map:"merge",id:+Date.now(),items:e}}function ro(t){var e=new Set;return t.forEach((function(t,n){e.add(t).add(n)})),e}function io(t,e,n){n=new _(n);var r=new oa,i=t.molecule,a=new H,o=new H;if(e.atoms){var s=new H(e.atoms),u=[];t.bonds.forEach((function(t,e){if(s.has(t.b.begin)&&s.has(t.b.end))return u.push(e),void["hb1","hb2"].forEach((function(e){var n=i.halfBonds.get(t.b[e]).loop;n>=0&&a.add(n)}));s.has(t.b.begin)?o.add(t.b.begin):s.has(t.b.end)&&o.add(t.b.end)})),u.forEach((function(t){r.addOp(new ai(t,n))})),a.forEach((function(e){t.reloops.get(e)&&t.reloops.get(e).visel&&r.addOp(new Si(e,n))})),e.atoms.forEach((function(t){r.addOp(new ti(t,n,!o.has(t)))})),e.sgroupData&&0===e.sgroupData.length&&xa(t,e.atoms).forEach((function(t){r.addOp(new qi(t.id,n))}))}return e.rxnArrows&&e.rxnArrows.forEach((function(t){r.addOp(new Ti(t,n,!0))})),e.rxnPluses&&e.rxnPluses.forEach((function(t){r.addOp(new Bi(t,n,!0))})),e.simpleObjects&&e.simpleObjects.forEach((function(t){r.addOp(new Gi(t,n,!0))})),e.sgroupData&&e.sgroupData.forEach((function(t){r.addOp(new qi(t,n))})),e.enhancedFlags&&e.enhancedFlags.forEach((function(t){r.addOp(new fi(t,n))})),e.texts&&e.texts.forEach((function(t){r.addOp(new aa(t,n,!0))})),r.perform(t)}function ao(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=new oa;if(!n){var i=t.molecule;t.molecule.frags.get(e).stereoAtoms.forEach((function(t){null===i.atoms.get(t).stereoLabel&&r.addOp(new Ei(e,t))}))}return r.addOp(new Oi(e)),r.perform(t)}function oo(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=new oa,i=gt.findRGroupByFragment(t.molecule.rgroups,e);return t.molecule.atoms.forEach((function(n,a){if(n.fragment===e){var o=r.addOp((new yi).perform(t)).frid;r.mergeWith(function(t,e,n,r){for(var i=[e],a=new H(i);i.length>0;){var o=i.shift();t.molecule.atomGetNeighbors(o).forEach((function(e){t.molecule.atoms.get(e.aid).fragment!==n||a.has(e.aid)||(a.add(e.aid),i.push(e.aid))}))}return Va(t,a,r)}(t,a,e,o)),i&&r.mergeWith(Aa(t,i,o))}})),-1!==e&&(r.mergeWith(Aa(t,0,e)),r.addOp(new bi(e).perform(t)),r.mergeWith(Sa(t,0,i,n))),r.operations.reverse(),r}function so(t,e){return co(t,{atoms:[e]})}function uo(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=new oa,i=t.molecule.bonds.get(e),a=[];return r.addOp(new ui(e)),n.includes(i.begin)||0!==ma(t,i.begin)||(Za(r,t,i.begin)&&a.push(i.begin),r.addOp(new ri(i.begin))),n.includes(i.end)||0!==ma(t,i.end)||(Za(r,t,i.end)&&a.push(i.end),r.addOp(new ri(i.end))),Na(r,t,a),(r=r.perform(t)).addOp(new Ai([i.begin,i.end]).perform(t)),r.mergeWith(_a(t,i,!1)),r.operations.reverse(),r}function lo(t,e){var n=t.molecule.getBondFragment(e),r=uo(t,e);return oo(t,n).mergeWith(r)}function co(t,e){s()(null!=!!e);var n=new oa,r=[],i=[];(e={atoms:e.atoms||[],bonds:e.bonds||[],rxnPluses:e.rxnPluses||[],rxnArrows:e.rxnArrows||[],sgroupData:e.sgroupData||[],simpleObjects:e.simpleObjects||[],texts:e.texts||[]}).atoms.forEach((function(n){t.molecule.atomGetNeighbors(n).forEach((function(t){-1===e.bonds.indexOf(t.bid)&&(e.bonds=e.bonds.concat([t.bid]))}))}));var a=new oa;e.bonds.forEach((function(n){var r=t.molecule.getBondFragment(n);i.indexOf(r)<0&&i.push(r),a.mergeWith(uo(t,n,e.atoms))})),e.atoms.forEach((function(e){var a=t.molecule.atoms.get(e).fragment;i.indexOf(a)<0&&i.push(a),Za(n,t,e)&&r.push(e),n.addOp(new ri(e))})),Na(n,t,r),e.rxnArrows.forEach((function(t){n.addOp(new Li(t))})),e.rxnPluses.forEach((function(t){n.addOp(new Zi(t))})),e.simpleObjects.forEach((function(t){n.addOp(new ji(t))})),e.texts.forEach((function(t){n.addOp(new ra(t))})),(n=n.perform(t)).mergeWith(a);for(var o=i.map((function(e){return gt.findRGroupByFragment(t.molecule.rgroups,e)}));i.length>0;)n=oo(t,i.pop(),o).mergeWith(n);return n}function ho(t,e,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,i=function(t){var e=t.sgroups.keys().next().value;if(1===t.sgroups.size&&!t.sgroups.get(e).data.expanded)return t.atoms.get(0).pp;if(t.atoms.size>0){var n=1e50,r=n,i=-n,a=-r;return t.atoms.forEach((function(t){n=Math.min(n,t.pp.x),r=Math.min(r,t.pp.y),i=Math.max(i,t.pp.x),a=Math.max(a,t.pp.y)})),new _((n+i)/2,(r+a)/2)}return t.rxnArrows.size>0?t.rxnArrows.get(0).center():t.rxnPluses.size>0?t.rxnPluses.get(0).pp:t.simpleObjects.size>0?t.simpleObjects.get(0).center():t.texts.size>0?t.texts.get(0).position:null}(e),a=_.diff(n,i),o=new oa,s=new Map,u=new Map,l={atoms:[],bonds:[]};return e.atoms.forEach((function(e,a){u.has(e.fragment)||u.set(e.fragment,o.addOp((new yi).perform(t)).frid);var c=Object.assign(e.clone(),{fragment:u.get(e.fragment)}),d=new ni(c,_.diff(e.pp,i).rotate(r).add(n)).perform(t);o.addOp(d),s.set(a,d.data.aid),l.atoms.push(d.data.aid)})),e.frags.forEach((function(e,n){e&&e.stereoAtoms.forEach((function(e){return o.addOp(new xi(u.get(n),s.get(e)).perform(t))}))})),e.bonds.forEach((function(e){var n=new si(s.get(e.begin),s.get(e.end),e).perform(t);o.addOp(n),l.bonds.push(n.data.bid)})),l.atoms.forEach((function(e){o.addOp(new Ai([e]).perform(t))})),e.sgroups.forEach((function(e){var n=t.molecule.sgroups.newId(),r=e.atoms.map((function(t){return s.get(t)}));Ba(t,e.type,r,e.data,n,e.pp?e.pp.add(a):null,"SUP"===e.type?e.data.expanded:null,e.data.name).operations.reverse().forEach((function(t){o.addOp(t)}))})),e.rxnArrows.forEach((function(e){o.addOp(new Ii(e.pos.map((function(t){return t.add(a)})),e.mode).perform(t))})),e.rxnPluses.forEach((function(e){o.addOp(new Mi(e.pp.add(a)).perform(t))})),e.simpleObjects.forEach((function(e){o.addOp(new _i(e.pos.map((function(t){return t.add(a)})),e.mode).perform(t))})),e.texts.forEach((function(e){o.addOp(new na(e.content,e.position.add(a),e.pos.map((function(t){return t.add(a)}))).perform(t))})),e.rgroups.forEach((function(n,r){n.frags.forEach((function(e,n){o.addOp(new Pi(r,u.get(n)).perform(t))}));var i=e.rgroups.get(r).ifthen,a=e.rgroups.get(i)?i:0;o.mergeWith(Oa(t,r,n.getAttrs())).mergeWith(Sa(t,a,n.ifthen))})),o.operations.reverse(),[o,l]}function fo(t,e,n){var r=new oa;return r.addOp(new Ii(e,n)),r.perform(t)}function po(t,e,n,r,i){var a=new oa;return a.addOp(new ki(e,n,r,i,!1)),a.perform(t)}function mo(t,e){var n=new oa;return n.addOp(new Li(e)),n.perform(t)}function go(t,e){var n=new oa;return n.addOp(new Mi(e).perform(t)),n}function vo(t,e){var n=new oa;return n.addOp(new Zi(e)),n.perform(t)}function yo(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function bo(t,e,n,r){var i=t.molecule,a=new oa;if(e||(e=ba(i)),!e.atoms)return a.perform(t);var o=e.atoms.reduce((function(t,e){var n=i.atoms.get(e);return t[n.fragment]||(t[n.fragment]=[]),t[n.fragment].push(e),t}),{});return"number"==typeof Object.keys(o).map((function(t){return parseInt(t,10)})).find((function(t){var e=i.getFragmentIds(t),n=new H(o[t]);return!e.equals(n)}))?function(t){var e=t.fids,n=t.struct,r=t.restruct,i=t.dir,a=t.action,o=t.selection,s=function(t,e){var n=t.bonds,r=function(t){return e.atoms.includes(t)},i=function(){var t,r=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return yo(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?yo(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}(n.entries());try{for(r.s();!(t=r.n()).done;){var i=(0,m.Z)(t.value,2),a=i[0],o=i[1];if(Ea(o,e))return[a,o]}}catch(t){r.e(t)}finally{r.f()}return[null,null]}(),a=(0,m.Z)(i,2),o=function(t,n){return e.bonds.includes(t)?[n.begin,n.end].find((function(t){return!r(t)})):[n.begin,n.end].find(r)}(a[0],a[1]);return t.atoms.get(o).pp}(n,o);return Object.keys(e).forEach((function(t){var o=new H(e[t]);o.forEach((function(t){var e=xo(n.atoms.get(t),s,i);a.addOp(new ti(t,e))})),xa(r,Array.from(o)).forEach((function(t){var e=xo(t,s,i);a.addOp(new qi(t.id,e))}))})),wo(o,n,a),a.perform(r)}({fids:o,struct:i,restruct:t,dir:n,action:a,selection:e}):function(t){var e=t.fids,n=t.struct,r=t.restruct,i=t.center,a=t.dir,o=t.action,s=t.selection;return Object.keys(e).forEach((function(t){var s=new H(e[t]),u=n.getCoordBoundingBox(s),l=i||new _((u.max.x+u.min.x)/2,(u.max.y+u.min.y)/2);s.forEach((function(t){var e=xo(n.atoms.get(t),l,a);o.addOp(new ti(t,e))})),xa(r,Array.from(s)).forEach((function(t){var e=xo(t,l,a);o.addOp(new qi(t.id,e))}))})),wo(s,n,o),o.perform(r)}({fids:o,struct:i,restruct:t,center:r,dir:n,action:a,selection:e})}function wo(t,e,n){t.bonds&&t.bonds.forEach((function(t){var r=e.bonds.get(t);r.type===q.PATTERN.TYPE.SINGLE&&(r.stereo!==q.PATTERN.STEREO.UP?r.stereo===q.PATTERN.STEREO.DOWN&&n.addOp(new ii(t,"stereo",q.PATTERN.STEREO.UP)):n.addOp(new ii(t,"stereo",q.PATTERN.STEREO.DOWN)))}))}function xo(t,e,n){var r=new _;return"horizontal"===n?r.x=e.x>t.pp.x?2*(e.x-t.pp.x):-2*(t.pp.x-e.x):r.y=e.y>t.pp.y?2*(e.y-t.pp.y):-2*(t.pp.y-e.y),r}function Eo(t,e,n,r){var i=t.molecule,a=new oa;e||(e=ba(i)),e.atoms&&(e.atoms.forEach((function(t){var e=i.atoms.get(t);a.addOp(new ti(t,Ao(e.pp,n,r)))})),e.sgroupData||xa(t,e.atoms).forEach((function(t){a.addOp(new qi(t.id,Ao(t.pp,n,r)))}))),e.rxnArrows&&e.rxnArrows.forEach((function(t){var e=i.rxnArrows.get(t);a.addOp(new Ti(t,Ao(e.center(),n,r)))})),e.rxnPluses&&e.rxnPluses.forEach((function(t){var e=i.rxnPluses.get(t);a.addOp(new Bi(t,Ao(e.pp,n,r)))})),e.sgroupData&&e.sgroupData.forEach((function(t){var e=i.sgroups.get(t);a.addOp(new qi(t,Ao(e.pp,n,r)))}));var o=e.enhancedFlags||Array.from(t.enhancedFlags.keys());return o&&o.forEach((function(e){var i=e,o=t.molecule.frags.get(i);a.addOp(new fi(e,Ao(o.stereoFlagPosition||Q.getDefaultStereoFlagPosition(t.molecule,i),n,r)))})),a.perform(t)}function Oo(t,e,n){var r=t.molecule,i=r.bonds.get(e),a=r.atoms.get(i.begin),o=r.atoms.get(i.end),s=a.pp.add(o.pp).scaled(.5),u=Yr.calcAngle(a.pp,o.pp),l=Array.from(r.getFragmentIds(a.fragment));return 0==(u="horizontal"===n?-u:Math.PI/2-u)||Math.abs(u)===Math.PI?bo(t,{atoms:l},n,s):Eo(t,{atoms:l},s,u)}function Ao(t,e,n){var r=t.sub(e);return(r=r.rotate(n)).add_(e),r.sub(t)}function So(t,e){var n=new oa;return n.addOp(new ji(e)),n.perform(t)}function Ro(t,e,n,r){var i=new oa;return i.addOp(new _i(e,n,r)),i.perform(t)}function Po(t,e,n,r,i,a){var o=new oa;return o.addOp(new Hi(e,n,r,i,!1,a)),o.perform(t)}function To(t,e,n,r){var i=ho(t,e.molecule,n,r),a=(0,m.Z)(i,2),o=a[0],s=a[1];return o.addOp(new Ai(s.atoms).perform(t)),[o,s]}function ko(t,e,n,r,i){var a=new oa,o=e.molecule,s=t.molecule,l=s.atoms.get(n),c=n,d=null;if(i){var h=function(t,e,n){var r=new oa,i=pa(t,e,"fragment"),a=null;if(null===n){var o=wa(t,e),s=La(t,{type:1},e,o.atom,o.pos.get_xy0());(r=s[0]).operations.reverse(),a=s[2]}else{var u=new ni({label:"C",fragment:i},new _(1,0).rotate(n).add(t.molecule.atoms.get(e).pp).get_xy0()).perform(t);r.addOp(u),r.addOp(new si(e,u.data.aid,{type:1}).perform(t)),a=u.data.aid}return{action:r,aid1:a}}(t,n,r);a=h.action,c=h.aid1,l=s.atoms.get(c),d=Yr.calcAngle(s.atoms.get(n).pp,l.pp)-e.angle0}else null===r&&(r=Yr.calcAngle(l.pp,wa(t,n).pos)),d=r-e.angle0;var f=new Map,p=o.atoms.get(e.aid).pp,m=pa(t,n,"fragment"),g={atoms:[],bonds:[]};return o.atoms.forEach((function(n,r){var i=W.getAttrHash(n);if(i.fragment=m,r===e.aid)a.mergeWith(Ua(t,c,i,!0)),f.set(r,c),g.atoms.push(c);else{var o=_.diff(n.pp,p).rotate(d).add(l.pp),s=new ni(i,o.get_xy0()).perform(t);a.addOp(s),f.set(r,s.data.aid),g.atoms.push(s.data.aid)}})),qa(a,t,g.atoms,n),o.bonds.forEach((function(e){var n=new si(f.get(e.begin),f.get(e.end),e).perform(t);a.addOp(n),g.bonds.push(n.data.bid)})),o.sgroups.forEach((function(e){var n=t.molecule.sgroups.newId(),r=e.atoms.map((function(t){return f.get(t)}));Ba(t,e.type,r,e.data,n,l.pp,"SUP"===e.type?e.expanded:null,e.data.name).operations.reverse().forEach((function(t){a.addOp(t)}))})),a.operations.reverse(),a.addOp(new Ai([].concat((0,u.Z)(g.atoms),[n])).perform(t)),a.mergeWith(_a(t,t.molecule.bonds.get(g.bonds[0]))),[a,g]}function Bo(t,e,n,r,i,a){return a?function(t,e,n,r,i){e.molecule;var a=t.molecule,o=a.getBondFragment(n);!function(t,e){var n=t.getFragmentIds(e),r=Array.from(n),i=t.clone(n),a=new Map;i.bonds.forEach((function(e,n){a.set(n,t.findBondId(r[e.begin],r[e.end]))}))}(a,o);var s=new oa;return s=i(t,e,n),Promise.resolve(s)}(t,e,n,0,(function(t,e,n){return Co(t,e,n,i)})):Co(t,e,n,i)}function Co(t,e,n,r){var i=new oa,a=e.molecule,o=t.molecule,s=o.bonds.get(n),l=a.bonds.get(e.bid),c=a.atoms.get(r?l.end:l.begin),d=new Map([[l.begin,r?s.end:s.begin],[l.end,r?s.begin:s.end]]),h={begin:r?l.end:l.begin,end:r?l.begin:l.end},f=Yr.mergeBondsParams(o,s,a,h),p=f.angle,m=f.scale,g=o.getBondFragment(n),v={atoms:[],bonds:[]};return a.atoms.forEach((function(e,n){var r=W.getAttrHash(e);if(r.fragment=g,n!==l.begin&&n!==l.end){var a=_.diff(e.pp,c.pp).rotate(p).scaled(m).add(o.atoms.get(s.begin).pp),u=fa.atom(t,a,null,.1);if(null===u){var h=new ni(r,a).perform(t);i.addOp(h),d.set(n,h.data.aid),v.atoms.push(h.data.aid)}else d.set(n,u.id),i.mergeWith(Ua(t,d.get(n),r,!0))}else i.mergeWith(Ua(t,d.get(n),r,!0))})),qa(i,t,v.atoms,s.begin),a.bonds.forEach((function(e){var n=o.findBondId(d.get(e.begin),d.get(e.end));if(null===n){var r=new si(d.get(e.begin),d.get(e.end),e).perform(t);i.addOp(r),v.bonds.push(r.data.bid)}else{var a=s.type>l.type?s:l;i.mergeWith(Da(t,n,a,!0))}})),v.atoms.length&&i.addOp(new Ai([s.begin,s.end].concat((0,u.Z)(v.atoms))).perform(t)),v.bonds.length&&i.mergeWith(_a(t,t.molecule.bonds.get(v.bonds[0]))),i.operations.reverse(),[i,v]}function Mo(t,e,n,r){var i=new oa;return i.addOp(new na(e,n,r)),i.perform(t)}function Zo(t,e,n){var r=new oa;return r.addOp(new ia(e,n)),r.perform(t)}function No(t,e){var n=new oa;return n.addOp(new ra(e)),n.perform(t)}function Io(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,d.Z)(t);if(e){var i=(0,d.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var Lo=function(t){(0,l.Z)(n,t);var e=Io(n);function n(t,i,a,o){var s;return(0,r.Z)(this,n),(s=e.call(this,Jr.ADD_HIGHLIGHT)).data={atoms:t,bonds:i,color:a,highlightId:o},s}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.atoms,r=e.bonds,i=e.color;if(i){var a=t.molecule,o=new Ct({atoms:n,bonds:r,color:i});"number"!=typeof this.data.highlightId?this.data.highlightId=a.highlights.add(o):a.highlights.set(this.data.highlightId,o),_o(t,n,r)}}},{key:"invert",value:function(){var t=this.data,e=t.atoms,n=t.bonds,r=t.color,i=t.highlightId;return new Do(i,e,n,r)}}]),n}(Kr),Do=function(t){(0,l.Z)(n,t);var e=Io(n);function n(t,i,a,o){var s;return(0,r.Z)(this,n),(s=e.call(this,Jr.REMOVE_HIGHLIGHT,5)).data={highlightId:t,atoms:i||[],bonds:a||[],color:o||"white"},s}return(0,i.Z)(n,[{key:"execute",value:function(t){if("number"==typeof this.data.highlightId){var e=t.molecule,n=e.highlights.get(this.data.highlightId);if(void 0===n)return;var r=n.atoms,i=n.bonds,a=n.color;this.data.atoms=r,this.data.bonds=i,this.data.color=a,e.highlights.delete(this.data.highlightId),_o(t,r,i)}}},{key:"invert",value:function(){var t=this.data,e=t.atoms,n=t.bonds,r=t.color,i=t.highlightId,a=new Lo(e,n,r,i);return a.data=this.data,a}}]),n}(Kr);function _o(t,e,n){var r=t.atoms,i=t.bonds;e&&e.forEach((function(e){void 0!==r.get(e)&&t.markAtom(e,1)})),n&&n.forEach((function(e){void 0!==i.get(e)&&t.markBond(e,1)}))}function jo(t,e){var n=new oa;return e.forEach((function(t){var e=t.atoms,r=t.bonds,i=t.color;n.addOp(new Lo(e,r,i))})),n.perform(t)}function Go(t){var e=new oa;return t.molecule.highlights.forEach((function(t,n){e.addOp(new Do(n))})),e.perform(t)}!function(t){(0,l.Z)(n,t);var e=Io(n);function n(t,i,a,o){var s;return(0,r.Z)(this,n),(s=e.call(this,Jr.UPDATE_HIGHLIGHT)).newData={atoms:i,bonds:a,color:o,highlightId:t},s.oldData={atoms:i,bonds:a,color:o,highlightId:t},s}(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.newData,n=e.atoms,r=e.bonds,i=e.color;if(i){var a=this.newData.highlightId,o=t.molecule,s=o.highlights.get(a);if(s){var l=s.atoms,c=s.bonds,d=s.color;this.oldData={atoms:l,bonds:c,color:d,highlightId:a};var h=new Ct({atoms:n,bonds:r,color:i});o.highlights.set(this.newData.highlightId,h),_o(t,[].concat((0,u.Z)(n),(0,u.Z)(l)),[].concat((0,u.Z)(r),(0,u.Z)(c)))}}}},{key:"invert",value:function(){var t=this.oldData,e=t.atoms,r=t.bonds,i=t.color;return new n(this.newData.highlightId,e,r,i)}}])}(Kr);var Fo={Fragment:"Fragment",Multifragment:"Multifragment",Bond:"Bond",Atom:"Atom",Group:"Group"},Ho=Yr.fracAngle;function zo(t,e,n){!function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t,e),e.set(t,n)}var Uo=["radicals","pseudoatoms","stereo","query","overlapping_atoms","overlapping_bonds","rgroups","chiral","3d"],Vo=["molecular-weight","most-abundant-mass","monoisotopic-mass","gross","mass-composition"];function Wo(t,e){if("string"!=typeof t){var n=new Map,r=t.clone(null,null,!1,n);return e.serialize(r)}return t}var Yo,qo=new WeakMap,$o=new WeakMap,Xo=function(){function t(e){(0,r.Z)(this,t),zo(this,qo,{writable:!0,value:void 0}),zo(this,$o,{writable:!0,value:void 0}),(0,f.Z)(this,qo,e),(0,f.Z)(this,$o,new Xt)}return(0,i.Z)(t,[{key:"info",value:function(){return(0,p.Z)(this,qo).info()}},{key:"convert",value:function(t,e){var n=(null==e?void 0:e.outputFormat)||on.KET;return(0,p.Z)(this,qo).convert({struct:Wo(t,(0,p.Z)(this,$o)),output_format:n})}},{key:"layout",value:function(t){var e=this;return(0,p.Z)(this,qo).layout({struct:Wo(t,(0,p.Z)(this,$o)),output_format:on.KET}).then((function(t){return(0,p.Z)(e,$o).deserialize(t.struct)}))}},{key:"clean",value:function(t){var e=this;return(0,p.Z)(this,qo).clean({struct:Wo(t,(0,p.Z)(this,$o)),output_format:on.KET}).then((function(t){return(0,p.Z)(e,$o).deserialize(t.struct)}))}},{key:"aromatize",value:function(t){var e=this;return(0,p.Z)(this,qo).aromatize({struct:Wo(t,(0,p.Z)(this,$o)),output_format:on.KET}).then((function(t){return(0,p.Z)(e,$o).deserialize(t.struct)}))}},{key:"dearomatize",value:function(t){var e=this;return(0,p.Z)(this,qo).dearomatize({struct:Wo(t,(0,p.Z)(this,$o)),output_format:on.KET}).then((function(t){return(0,p.Z)(e,$o).deserialize(t.struct)}))}},{key:"calculateCip",value:function(t){var e=this;return(0,p.Z)(this,qo).calculateCip({struct:Wo(t,(0,p.Z)(this,$o)),output_format:on.KET}).then((function(t){return(0,p.Z)(e,$o).deserialize(t.struct)}))}},{key:"automap",value:function(t,e){var n=this,r=(null==e?void 0:e.mode)||"discard";return(0,p.Z)(this,qo).automap({struct:Wo(t,(0,p.Z)(this,$o)),output_format:on.KET,mode:r}).then((function(t){return(0,p.Z)(n,$o).deserialize(t.struct)}))}},{key:"check",value:function(t,e){var n=(null==e?void 0:e.types)||Uo;return(0,p.Z)(this,qo).check({struct:Wo(t,(0,p.Z)(this,$o)),types:n})}},{key:"calculate",value:function(t,e){var n=(null==e?void 0:e.properties)||Vo;return(0,p.Z)(this,qo).calculate({struct:Wo(t,(0,p.Z)(this,$o)),properties:n})}},{key:"recognize",value:function(t,e){var n=this,r=(null==e?void 0:e.version)||"";return(0,p.Z)(this,qo).recognize(t,r).then((function(t){return(0,p.Z)(n,$o).deserialize(t.struct)}))}},{key:"generateImageAsBase64",value:function(t,e){var n=(null==e?void 0:e.outputFormat)||"png",r=(null==e?void 0:e.backgroundColor)||"";return(0,p.Z)(this,qo).generateImageAsBase64(Wo(t,(0,p.Z)(this,$o)),{outputFormat:n,backgroundColor:r})}}]),t}(),Ko="object"==typeof Reflect?Reflect:null,Jo=Ko&&"function"==typeof Ko.apply?Ko.apply:function(t,e,n){return Function.prototype.apply.call(t,e,n)};Yo=Ko&&"function"==typeof Ko.ownKeys?Ko.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var Qo=Number.isNaN||function(t){return t!=t};function ts(){ts.init.call(this)}var es=ts;ts.EventEmitter=ts,ts.prototype._events=void 0,ts.prototype._eventsCount=0,ts.prototype._maxListeners=void 0;var ns=10;function rs(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function is(t){return void 0===t._maxListeners?ts.defaultMaxListeners:t._maxListeners}function as(t,e,n,r){var i,a,o,s;if(rs(n),void 0===(a=t._events)?(a=t._events=Object.create(null),t._eventsCount=0):(void 0!==a.newListener&&(t.emit("newListener",e,n.listener?n.listener:n),a=t._events),o=a[e]),void 0===o)o=a[e]=n,++t._eventsCount;else if("function"==typeof o?o=a[e]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),(i=is(t))>0&&o.length>i&&!o.warned){o.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=t,u.type=e,u.count=o.length,s=u,console&&console.warn&&console.warn(s)}return t}function os(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function ss(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=os.bind(r);return i.listener=n,r.wrapFn=i,i}function us(t,e,n){var r=t._events;if(void 0===r)return[];var i=r[e];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}(i):cs(i,i.length)}function ls(t){var e=this._events;if(void 0!==e){var n=e[t];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function cs(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function ds(t,e,n,r){if("function"==typeof t.on)r.once?t.once(e,n):t.on(e,n);else{if("function"!=typeof t.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t);t.addEventListener(e,(function i(a){r.once&&t.removeEventListener(e,i),n(a)}))}}function hs(t,e,n){!function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t,e),e.set(t,n)}function fs(t,e,n){return ps.apply(this,arguments)}function ps(){return(ps=(0,w.Z)(E().mark((function t(e,n,r){var i;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,ms(e,n,r);case 2:return(i=t.sent).initHalfBonds(),i.initNeighbors(),i.setImplicitHydrogen(),i.markFragments(),t.abrupt("return",i);case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ms(t,e,n){var r=jn(t),i=new _n(e),a=n.editor.options();return i.create(r,{"dearomatize-on-load":a["dearomatize-on-load"]}).getStructureFromStringAsync(t)}function gs(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:hn.rxn,e=arguments.length>2?arguments[2]:void 0;return(arguments.length>1?arguments[1]:void 0).create(t).getStructureFromStructAsync(e)}Object.defineProperty(ts,"defaultMaxListeners",{enumerable:!0,get:function(){return ns},set:function(t){if("number"!=typeof t||t<0||Qo(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");ns=t}}),ts.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},ts.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||Qo(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},ts.prototype.getMaxListeners=function(){return is(this)},ts.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e.push(arguments[n]);var r="error"===t,i=this._events;if(void 0!==i)r=r&&void 0===i.error;else if(!r)return!1;if(r){var a;if(e.length>0&&(a=e[0]),a instanceof Error)throw a;var o=new Error("Unhandled error."+(a?" ("+a.message+")":""));throw o.context=a,o}var s=i[t];if(void 0===s)return!1;if("function"==typeof s)Jo(s,this,e);else{var u=s.length,l=cs(s,u);for(n=0;n<u;++n)Jo(l[n],this,e)}return!0},ts.prototype.addListener=function(t,e){return as(this,t,e,!1)},ts.prototype.on=ts.prototype.addListener,ts.prototype.prependListener=function(t,e){return as(this,t,e,!0)},ts.prototype.once=function(t,e){return rs(e),this.on(t,ss(this,t,e)),this},ts.prototype.prependOnceListener=function(t,e){return rs(e),this.prependListener(t,ss(this,t,e)),this},ts.prototype.removeListener=function(t,e){var n,r,i,a,o;if(rs(e),void 0===(r=this._events))return this;if(void 0===(n=r[t]))return this;if(n===e||n.listener===e)0==--this._eventsCount?this._events=Object.create(null):(delete r[t],r.removeListener&&this.emit("removeListener",t,n.listener||e));else if("function"!=typeof n){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===e||n[a].listener===e){o=n[a].listener,i=a;break}if(i<0)return this;0===i?n.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(n,i),1===n.length&&(r[t]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",t,o||e)}return this},ts.prototype.off=ts.prototype.removeListener,ts.prototype.removeAllListeners=function(t){var e,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[t]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[t]),this;if(0===arguments.length){var i,a=Object.keys(n);for(r=0;r<a.length;++r)"removeListener"!==(i=a[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(e=n[t]))this.removeListener(t,e);else if(void 0!==e)for(r=e.length-1;r>=0;r--)this.removeListener(t,e[r]);return this},ts.prototype.listeners=function(t){return us(this,t,!0)},ts.prototype.rawListeners=function(t){return us(this,t,!1)},ts.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):ls.call(t,e)},ts.prototype.listenerCount=ls,ts.prototype.eventNames=function(){return this._eventsCount>0?Yo(this._events):[]},es.once=function(t,e){return new Promise((function(n,r){function i(n){t.removeListener(e,a),r(n)}function a(){"function"==typeof t.removeListener&&t.removeListener("error",i),n([].slice.call(arguments))}ds(t,e,a,{once:!0}),"error"!==e&&function(t,e,n){"function"==typeof t.on&&ds(t,"error",e,{once:!0})}(t,i)}))};var vs=new WeakMap,ys=new WeakMap,bs=new WeakMap,ws=new WeakMap,xs=new WeakMap,Es=function(){function t(e,n,i){(0,r.Z)(this,t),hs(this,vs,{writable:!0,value:void 0}),hs(this,ys,{writable:!0,value:void 0}),hs(this,bs,{writable:!0,value:void 0}),hs(this,ws,{writable:!0,value:void 0}),hs(this,xs,{writable:!0,value:void 0}),s()(null!=e),s()(null!=n),s()(null!=i),(0,f.Z)(this,bs,e),(0,f.Z)(this,vs,n),(0,f.Z)(this,ys,i),(0,f.Z)(this,ws,new Xo((0,p.Z)(this,vs))),(0,f.Z)(this,xs,new es.EventEmitter)}var e,n,a,o,u,l,c;return(0,i.Z)(t,[{key:"editor",get:function(){return(0,p.Z)(this,bs)}},{key:"eventBus",get:function(){return(0,p.Z)(this,xs)}},{key:"indigo",get:function(){return(0,p.Z)(this,ws)}},{key:"settings",get:function(){var t=(0,p.Z)(this,bs).options();if("dearomatize-on-load"in t)return{"general.dearomatize-on-load":t["dearomatize-on-load"]};throw new Error("dearomatize-on-load option is not provided!")}},{key:"setSettings",value:function(t){if(!t)throw new Error("Please provide settings");var e={};return"general.dearomatize-on-load"in t&&(e["dearomatize-on-load"]=t["general.dearomatize-on-load"]),(0,p.Z)(this,bs).setOptions(JSON.stringify(e))}},{key:"getSmiles",value:function(){return gs(arguments.length>0&&void 0!==arguments[0]&&arguments[0]?hn.smilesExt:hn.smiles,(0,p.Z)(this,ys),this.editor.struct())}},{key:"getMolfile",value:(c=(0,w.Z)(E().mark((function t(e){var n,r,i;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.containsReaction()){t.next=2;break}throw Error("The structure cannot be saved as *.MOL due to reaction arrrows.");case 2:return n="v3000"===e?hn.molV3000:hn.mol,r=e?n:hn.molAuto,t.next=6,gs(r,(0,p.Z)(this,ys),(0,p.Z)(this,bs).struct());case 6:return i=t.sent,t.abrupt("return",i);case 8:case"end":return t.stop()}}),t,this)}))),function(t){return c.apply(this,arguments)})},{key:"getRxn",value:(l=(0,w.Z)(E().mark((function t(){var e,n,r,i=arguments;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e=i.length>0&&void 0!==i[0]?i[0]:"v2000",this.containsReaction()){t.next=3;break}throw Error("The structure cannot be saved as *.RXN: there is no reaction arrows.");case 3:return n="v3000"===e?hn.rxnV3000:hn.rxn,t.next=6,gs(n,(0,p.Z)(this,ys),(0,p.Z)(this,bs).struct());case 6:return r=t.sent,t.abrupt("return",r);case 8:case"end":return t.stop()}}),t,this)}))),function(){return l.apply(this,arguments)})},{key:"getKet",value:function(){return gs(hn.ket,(0,p.Z)(this,ys),(0,p.Z)(this,bs).struct())}},{key:"getSmarts",value:function(){return gs(hn.smarts,(0,p.Z)(this,ys),(0,p.Z)(this,bs).struct())}},{key:"getCml",value:function(){return gs(hn.cml,(0,p.Z)(this,ys),(0,p.Z)(this,bs).struct())}},{key:"getInchi",value:function(){return gs(arguments.length>0&&void 0!==arguments[0]&&arguments[0]?hn.inChIAuxInfo:hn.inChI,(0,p.Z)(this,ys),(0,p.Z)(this,bs).struct())}},{key:"generateInchIKey",value:(u=(0,w.Z)(E().mark((function t(){var e;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,gs(hn.ket,(0,p.Z)(this,ys),(0,p.Z)(this,bs).struct());case 2:return e=t.sent,t.abrupt("return",(0,p.Z)(this,vs).generateInchIKey(e));case 4:case"end":return t.stop()}}),t,this)}))),function(){return u.apply(this,arguments)})},{key:"containsReaction",value:function(){return this.editor.struct().hasRxnArrow()}},{key:"setMolecule",value:(o=(0,w.Z)(E().mark((function t(e){var n=this;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:Dt((0,w.Z)(E().mark((function t(){var r;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return s()("string"==typeof e),t.next=3,fs(e,(0,p.Z)(n,vs),n);case 3:r=t.sent,(0,p.Z)(n,bs).struct(r);case 5:case"end":return t.stop()}}),t)}))),this.eventBus);case 1:case"end":return t.stop()}}),t,this)}))),function(t){return o.apply(this,arguments)})},{key:"addFragment",value:(a=(0,w.Z)(E().mark((function t(e){var n=this;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:Dt((0,w.Z)(E().mark((function t(){var r;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return s()("string"==typeof e),t.next=3,fs(e,(0,p.Z)(n,vs),n);case 3:r=t.sent,(0,p.Z)(n,bs).structToAddFragment(r);case 5:case"end":return t.stop()}}),t)}))),this.eventBus);case 1:case"end":return t.stop()}}),t,this)}))),function(t){return a.apply(this,arguments)})},{key:"layout",value:(n=(0,w.Z)(E().mark((function t(){var e=this;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:Dt((0,w.Z)(E().mark((function t(){var n,r;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,(0,p.Z)(e,ws).layout((0,p.Z)(e,bs).struct());case 2:n=t.sent,r=new Xt,e.setMolecule(r.serialize(n));case 5:case"end":return t.stop()}}),t)}))),this.eventBus);case 1:case"end":return t.stop()}}),t,this)}))),function(){return n.apply(this,arguments)})},{key:"recognize",value:function(t,e){return(0,p.Z)(this,ws).recognize(t,{version:e})}},{key:"generateImage",value:(e=(0,w.Z)(E().mark((function t(e){var n,r,i,a,o,s,u,l,c=arguments;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:n=c.length>1&&void 0!==c[1]?c[1]:{outputFormat:"png"},r="",t.t0=n.outputFormat,t.next="svg"===t.t0?5:(t.t0,7);break;case 5:return r="image/svg+xml",t.abrupt("break",9);case 7:r="image/png",n.outputFormat="png";case 9:return t.next=11,(0,p.Z)(this,vs).generateImageAsBase64(e,n);case 11:for(i=t.sent,a=atob(i),o=new Array(a.length),s=0;s<a.length;s++)o[s]=a.charCodeAt(s);return u=new Uint8Array(o),l=new Blob([u],{type:r}),t.abrupt("return",l);case 18:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})}]),t}();function Os(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function As(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Os(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Os(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var Ss={"smart-layout":!0,"ignore-stereochemistry-errors":!0,"mass-skip-error-on-pseudoatoms":!1,"gross-formula-add-rsites":!0,"aromatize-skip-superatoms":!0,"dearomatize-on-load":!1},Rs=new WeakMap;(0,i.Z)((function t(){var e,n,i;(0,r.Z)(this,t),i={writable:!0,value:void 0},function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e=this,n=Rs),n.set(e,i)}),[{key:"withStructServiceProvider",value:function(t){return(0,f.Z)(this,Rs,t),this}},{key:"build",value:function(t,e){s()(null!=t),s()(null!=(0,p.Z)(this,Rs));var n=As(As({},Ss),e),r=(0,p.Z)(this,Rs).createStructService(n),i=new Es(t,r,new _n(r));return i[(0,p.Z)(this,Rs).mode]=!0,i}}])}}]);
|