aldehyde 0.2.31 → 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.
Files changed (150) hide show
  1. package/dist/bundle.022b9d9e54b55ad6267e.js +1 -0
  2. package/dist/bundle.022b9d9e54b55ad6267e.js.gz +0 -0
  3. package/dist/bundle.03c8826fed3306e7bca7.js +1 -0
  4. package/dist/bundle.17695fcdfc4d8b13d695.js +2 -0
  5. package/dist/bundle.17695fcdfc4d8b13d695.js.LICENSE.txt +8 -0
  6. package/dist/bundle.17695fcdfc4d8b13d695.js.gz +0 -0
  7. package/dist/bundle.1bc3fad9b6dda01db2dc.js +1 -0
  8. package/dist/bundle.1bc3fad9b6dda01db2dc.js.gz +0 -0
  9. package/dist/bundle.26e8ea213610dd77dfc5.js +2 -0
  10. package/dist/bundle.26e8ea213610dd77dfc5.js.LICENSE.txt +22 -0
  11. package/dist/bundle.26e8ea213610dd77dfc5.js.gz +0 -0
  12. package/dist/bundle.2e0aa3d0288f29cd9bdb.js +1 -0
  13. package/dist/bundle.2e0aa3d0288f29cd9bdb.js.gz +0 -0
  14. package/dist/bundle.3afd92d0051920d083b8.js +1 -0
  15. package/dist/bundle.3afd92d0051920d083b8.js.gz +0 -0
  16. package/dist/bundle.3b47a72a98819ce207b4.js +2 -0
  17. package/dist/bundle.3b47a72a98819ce207b4.js.LICENSE.txt +14 -0
  18. package/dist/bundle.3b47a72a98819ce207b4.js.gz +0 -0
  19. package/dist/bundle.4d91709f680596b4b0ac.js +2 -0
  20. package/dist/bundle.4d91709f680596b4b0ac.js.LICENSE.txt +9 -0
  21. package/dist/bundle.4d91709f680596b4b0ac.js.gz +0 -0
  22. package/dist/bundle.4e6573855d62c2c61293.js +1 -0
  23. package/dist/bundle.4e6573855d62c2c61293.js.gz +0 -0
  24. package/dist/bundle.51344a730efffedb67a3.js +2 -0
  25. package/dist/bundle.51344a730efffedb67a3.js.LICENSE.txt +8 -0
  26. package/dist/bundle.51344a730efffedb67a3.js.gz +0 -0
  27. package/dist/bundle.59446aa1a6e81028b0f3.js +1 -0
  28. package/dist/bundle.59446aa1a6e81028b0f3.js.gz +0 -0
  29. package/dist/bundle.5c631f42a0bc32bcee42.js +1 -0
  30. package/dist/bundle.5cc46bd3e80bed3462d0.js +2 -0
  31. package/dist/bundle.5cc46bd3e80bed3462d0.js.LICENSE.txt +1 -0
  32. package/dist/bundle.5cc46bd3e80bed3462d0.js.gz +0 -0
  33. package/dist/bundle.5fc1d01501a8fadd2680.js +2 -0
  34. package/dist/bundle.5fc1d01501a8fadd2680.js.LICENSE.txt +7 -0
  35. package/dist/bundle.5fc1d01501a8fadd2680.js.gz +0 -0
  36. package/dist/bundle.6bf28a6aa5ba025b9cbe.js +2 -0
  37. package/dist/bundle.6bf28a6aa5ba025b9cbe.js.LICENSE.txt +18 -0
  38. package/dist/bundle.6bf28a6aa5ba025b9cbe.js.gz +0 -0
  39. package/dist/bundle.6c63d1f8fd32a2e9ca6c.js +75 -0
  40. package/dist/bundle.6c63d1f8fd32a2e9ca6c.js.LICENSE.txt +17 -0
  41. package/dist/bundle.6c63d1f8fd32a2e9ca6c.js.gz +0 -0
  42. package/dist/bundle.75ca758485013fe73c8a.js +1 -0
  43. package/dist/bundle.75ca758485013fe73c8a.js.gz +0 -0
  44. package/dist/bundle.79c75972bdb84e2526a0.js +1 -0
  45. package/dist/bundle.79c75972bdb84e2526a0.js.gz +0 -0
  46. package/dist/bundle.7c07c768d6aa85f8cb7f.js +1 -0
  47. package/dist/bundle.7c07c768d6aa85f8cb7f.js.gz +0 -0
  48. package/dist/bundle.7e85c36e04f1428d40ae.js +2 -0
  49. package/dist/bundle.7e85c36e04f1428d40ae.js.LICENSE.txt +17 -0
  50. package/dist/bundle.7e85c36e04f1428d40ae.js.gz +0 -0
  51. package/dist/bundle.7fe4c9d6d1fad1b785b4.js +1 -0
  52. package/dist/bundle.7fe4c9d6d1fad1b785b4.js.gz +0 -0
  53. package/dist/bundle.8a46aaa80505db8f0a31.js +1 -0
  54. package/dist/bundle.8a46aaa80505db8f0a31.js.gz +0 -0
  55. package/dist/bundle.8a6c3026f7b0ad7bdc84.js +2 -0
  56. package/dist/bundle.8a6c3026f7b0ad7bdc84.js.LICENSE.txt +25 -0
  57. package/dist/bundle.8a6c3026f7b0ad7bdc84.js.gz +0 -0
  58. package/dist/bundle.9a888a685a8dc8795cb1.js +1 -0
  59. package/dist/bundle.9d12b63336a9c8d44a9d.js +1 -0
  60. package/dist/bundle.9d12b63336a9c8d44a9d.js.gz +0 -0
  61. package/dist/bundle.a7dfe1231cfa8ef5b0d3.js +2 -0
  62. package/dist/bundle.a7dfe1231cfa8ef5b0d3.js.LICENSE.txt +5 -0
  63. package/dist/bundle.a7dfe1231cfa8ef5b0d3.js.gz +0 -0
  64. package/dist/bundle.be6aaf07219b3f9a361f.js +1 -0
  65. package/dist/bundle.be6aaf07219b3f9a361f.js.gz +0 -0
  66. package/dist/bundle.c015ad492469b8a18b36.js +1 -0
  67. package/dist/bundle.c015ad492469b8a18b36.js.gz +0 -0
  68. package/dist/bundle.c31ad04e1e30564fea70.js +1 -0
  69. package/dist/bundle.c560447b006cce1238b6.js +2 -0
  70. package/dist/bundle.c560447b006cce1238b6.js.LICENSE.txt +1 -0
  71. package/dist/bundle.c560447b006cce1238b6.js.gz +0 -0
  72. package/dist/bundle.cad48ecfb6c9304f8477.js +2 -0
  73. package/dist/bundle.cad48ecfb6c9304f8477.js.LICENSE.txt +5 -0
  74. package/dist/bundle.cad48ecfb6c9304f8477.js.gz +0 -0
  75. package/dist/bundle.d7eaee8d9bcfcf8b0bd0.js +1 -0
  76. package/dist/bundle.d7eaee8d9bcfcf8b0bd0.js.gz +0 -0
  77. package/dist/bundle.d8256eaa6fe575fb9d01.js +8 -0
  78. package/dist/bundle.d8256eaa6fe575fb9d01.js.LICENSE.txt +8 -0
  79. package/dist/bundle.d8256eaa6fe575fb9d01.js.gz +0 -0
  80. package/dist/bundle.dbb253f3029c97475380.js +1 -0
  81. package/dist/bundle.dbb253f3029c97475380.js.gz +0 -0
  82. package/dist/bundle.df7845990c0fed52fca8.js +2 -0
  83. package/dist/bundle.df7845990c0fed52fca8.js.LICENSE.txt +29 -0
  84. package/dist/bundle.df7845990c0fed52fca8.js.gz +0 -0
  85. package/dist/bundle.e1ac7a74c5a25a07424c.js +1 -0
  86. package/dist/bundle.e1ac7a74c5a25a07424c.js.gz +0 -0
  87. package/dist/bundle.e9b7939a81971b04ce61.js +1 -0
  88. package/dist/bundle.e9b7939a81971b04ce61.js.gz +0 -0
  89. package/dist/bundle.eb8b12c34556f700f59a.js +2 -0
  90. package/dist/bundle.eb8b12c34556f700f59a.js.LICENSE.txt +30 -0
  91. package/dist/bundle.eb8b12c34556f700f59a.js.gz +0 -0
  92. package/dist/bundle.f4f8e071565f4dff4698.js +2 -0
  93. package/dist/bundle.f4f8e071565f4dff4698.js.LICENSE.txt +5 -0
  94. package/dist/bundle.f4f8e071565f4dff4698.js.gz +0 -0
  95. package/dist/css/chemstruc-graph-15d5053934e613f20d2b.css +11 -0
  96. package/dist/css/chemstruc-graph-15d5053934e613f20d2b.css.gz +0 -0
  97. package/dist/css/common-131a1a93b3a3dde25f8f.css +90 -0
  98. package/dist/css/html-editor-draft-5e8e152675ab7d201c00.css +886 -0
  99. package/dist/css/html-editor-draft-5e8e152675ab7d201c00.css.gz +0 -0
  100. package/dist/css/main-4bd110a5b2a4a3fbef88.css +803 -0
  101. package/dist/css/main-4bd110a5b2a4a3fbef88.css.gz +0 -0
  102. package/dist/images/development-30de07a0.png +0 -0
  103. package/dist/images/pain-point-8f02421e.png +0 -0
  104. package/dist/images/target-13a5b4b9.png +0 -0
  105. package/dist/images/time-cost-cb40d2c2.png +0 -0
  106. package/dist/images/time-prograss-44b86b36.png +0 -0
  107. package/dist/index.html +4 -0
  108. package/lib/controls/code-editor/sql-code-editor.d.ts.map +1 -1
  109. package/lib/controls/code-editor/sql-code-editor.js.map +1 -1
  110. package/lib/controls/date-picker/index.d.ts +2 -2
  111. package/lib/controls/entry-control.d.ts.map +1 -1
  112. package/lib/controls/entry-control.js +2 -2
  113. package/lib/controls/entry-control.js.map +1 -1
  114. package/lib/controls/view-control.d.ts.map +1 -1
  115. package/lib/controls/view-control.js +3 -3
  116. package/lib/controls/view-control.js.map +1 -1
  117. package/lib/index.d.ts +2 -2
  118. package/lib/index.d.ts.map +1 -1
  119. package/lib/index.js +2 -2
  120. package/lib/index.js.map +1 -1
  121. package/lib/layout/MainPage.js +1 -1
  122. package/lib/layout/MainPage.js.map +1 -1
  123. package/lib/layout/header/index.d.ts.map +1 -1
  124. package/lib/layout/header/index.js.map +1 -1
  125. package/lib/layout/menu/user-bar.d.ts.map +1 -1
  126. package/lib/layout/menu/user-bar.js +8 -3
  127. package/lib/layout/menu/user-bar.js.map +1 -1
  128. package/lib/login/login.js +2 -3
  129. package/lib/login/login.js.map +1 -1
  130. package/lib/tmpl/superagent.d.ts.map +1 -1
  131. package/lib/tmpl/superagent.js +5 -2
  132. package/lib/tmpl/superagent.js.map +1 -1
  133. package/lib/welcome/HCWelcome.d.ts +2 -17
  134. package/lib/welcome/HCWelcome.d.ts.map +1 -1
  135. package/lib/welcome/HCWelcome.js +15 -23
  136. package/lib/welcome/HCWelcome.js.map +1 -1
  137. package/lib/welcome/workbench.js.map +1 -1
  138. package/package.json +2 -3
  139. package/src/aldehyde/controls/code-editor/sql-code-editor.tsx +1 -2
  140. package/src/aldehyde/controls/date-picker/index.tsx +2 -2
  141. package/src/aldehyde/controls/entry-control.tsx +4 -2
  142. package/src/aldehyde/controls/view-control.tsx +7 -6
  143. package/src/aldehyde/index.tsx +5 -2
  144. package/src/aldehyde/layout/MainPage.tsx +1 -1
  145. package/src/aldehyde/layout/header/index.tsx +0 -1
  146. package/src/aldehyde/layout/menu/user-bar.tsx +6 -3
  147. package/src/aldehyde/login/login.js +3 -4
  148. package/src/aldehyde/tmpl/superagent.js +6 -2
  149. package/src/aldehyde/welcome/HCWelcome.js +7 -13
  150. package/src/aldehyde/welcome/workbench.tsx +1 -1
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunkaldehyde=self.webpackChunkaldehyde||[]).push([[66],{89066:function(t,e,n){n.d(e,{YlQ:function(){return ln}});var r=n(15671),i=n(43144),a=n(4942),o=n(69282),s=n.n(o),l=n(60136),c=n(82963),u=n(61120),h=n(98737),d=n(93433),f=n(13092),p=n(86033),m=n(29439),v=n(97326),g=n(11752),y=n(71002),b=n(96486),x=n(15861),w=n(64687),E=n.n(w),S=n(1581),R=n.n(S),A=n(45987),O=n(67079),P=n.n(O),k=n(66721),T=n.n(k),B=n(78230),Z={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"},C=[{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}],M=C.reduce((function(t,e){return t.set(e.label,e),t.set(e.number,e),t}),new Map),L={get:function(t){return M.get(t)},filter:function(t){return C.filter(t)}};function I(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 N=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 I(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)?I(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=L.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}(),D=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 _(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 j(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)?j(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 j(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)(D,"ZERO",new D(0,0)),(0,a.Z)(D,"UNIT",new D(1,1));var G,F=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,u.Z)(e);if(n){var i=(0,u.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=_(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=_(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=_(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}}]),o}((0,h.Z)(Set));function z(t,e){return void 0!==t?t:e}function H(t){return!L.get(t)&&"L"!==t&&"L#"!==t&&"R#"!==t}function U(t){return(t-=0)===V.PATTERN.RADICAL.DOUPLET?1:t===V.PATTERN.RADICAL.SINGLET||t===V.PATTERN.RADICAL.TRIPLET?2:0}!function(t){t.Abs="abs",t.And="&",t.Or="or"}(G||(G={}));var V=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 D(e.pp):new D,this.sgs=new F,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 N(e.atomList):null,this.neighbors=[],this.badConn=!1,Object.defineProperty(this,"pseudo",{enumerable:!0,get:function(){return H(t=this.label)?t:"";var t},set:function(t){H(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&&!L.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=L.get(e);if(!r)return this.implicitH=0,!0;var i=r.group,a=U(this.radical),o=t,s=0,l=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-l):2===i?t+a+l===2||t+a+l===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-l):"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+l<=1?(o=1,s=1-a-t-l):(o=3,s=3-a-t-l)):4===i?"C"===e||"Si"===e||"Ge"===e?(o=4,s=4-a-t-l):"Sn"!==e&&"Pb"!==e||(t+a+l<=2?(o=2,s=2-a-t-l):(o=4,s=4-a-t-l)):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+l<=3?(o=3,s=3-a-t-l):(o=5,s=5-a-t-l):"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-l):(o=5,s=5-a-t-l)):6===i?"O"===e?n>=1?(o=3,s=3-a-t):(o=2,s=2-a-t-l):"S"===e||"Se"===e||"Po"===e?1===n?t<=3?(o=3,s=3-a-t):(o=5,s=5-a-t):t+a+l<=2?(o=2,s=2-a-t-l):t+a+l<=4?(o=4,s=4-a-t-l):(o=6,s=6-a-t-l):"Te"===e&&(-1===n?t<=2&&(o=2,s=2-a-t-l):0!==n&&2!==n||(t<=2?(o=2,s=2-a-t-l):t<=4?(o=4,s=4-a-t-l):0===n&&t<=6?(o=6,s=6-a-t-l):s=-1)):7===i?"F"===e?(o=1,s=1-a-t-l):"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+l===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=L.get(this.label);if(!r)return this.implicitH=0,0;var i=r.group,a=U(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)(V,"PATTERN",{RADICAL:{NONE:0,SINGLET:1,DOUPLET:2,TRIPLET:3},STEREO_PARITY:{NONE:0,ODD:1,EVEN:2,EITHER:3}}),(0,a.Z)(V,"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 W,Y=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 D}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 D.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 q(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 $(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=W.Mixed;else{var a,o=null===(a=i.match(/\D+/g))||void 0===a?void 0:a[0];switch(o){case G.Abs:r=W.Abs;break;case G.And:r=W.And;break;case G.Or:r=W.Or;break;default:throw new Error("Unsupported stereo label: ".concat(o,"."))}}return r}}}(0,a.Z)(Y,"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)(Y,"attrlist",{type:Y.PATTERN.TYPE.SINGLE,stereo:Y.PATTERN.STEREO.NONE,topology:Y.PATTERN.TOPOLOGY.EITHER,reactingCenterStatus:Y.PATTERN.REACTING_CENTER.UNMARKED}),function(t){t.Mixed="MIXED",t.Abs="ABS",t.And="AND",t.Or="OR"}(W||(W={}));var X=new WeakMap,K=new WeakMap,J=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),q(this,X,{writable:!0,value:void 0}),q(this,K,{writable:!0,value:void 0}),n&&(this.stereoFlagPosition=new D(n)),(0,f.Z)(this,K,e)}return(0,i.Z)(t,[{key:"stereoAtoms",get:function(){return(0,d.Z)((0,p.Z)(this,K))}},{key:"enhancedStereoFlag",get:function(){return(0,p.Z)(this,X)}},{key:"clone",value:function(e){var n=new t((0,p.Z)(this,K).map((function(t){return e.get(t)})),this.stereoFlagPosition);return(0,f.Z)(n,X,(0,p.Z)(this,X)),n}},{key:"updateStereoFlag",value:function(t){return(0,f.Z)(this,X,$(t,this.stereoAtoms)),(0,p.Z)(this,X)}},{key:"updateStereoAtom",value:function(t,e,n,r){var i;r&&!(0,p.Z)(this,K).includes(e)&&(0,p.Z)(this,K).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!==Y.PATTERN.TYPE.DOUBLE})).some((function(t){return t.begin===e}))||(0,f.Z)(this,K,this.stereoAtoms.filter((function(t){return t!==e}))),(0,f.Z)(this,X,$(t,this.stereoAtoms))}},{key:"addStereoAtom",value:function(t){return!(0,p.Z)(this,K).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!==Y.PATTERN.TYPE.DOUBLE})).some((function(t){return t.begin===n}))||((0,f.Z)(this,K,(0,p.Z)(this,K).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 D(r.max.x,r.min.y-1)}}}]),t}(),Q={scaled2obj:function(t,e){return t.scaled(1/e.scale)},obj2scaled:function(t,e){return t.scaled(e.scale)}},tt=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,d.Z)(this.functionalGroupsList),(0,d.Z)(t))}}],[{key:"getInstance",value:function(){return t.instance||(t.instance=new t),t.instance}}]),t}(),et=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}(),nt=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 D(n[0],n[1]),this.p1=new D(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 D,this.p1=new D}}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 D.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(D.min(e.p0,n.p0),D.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}(),rt=(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})),it=function(){function t(e){(0,r.Z)(this,t),this.type=e,this.id=-1,this.label=-1,this.bracketBox=null,this.bracketDir=new D(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=D.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 D(1,0);this.atoms.forEach((function(t){var n=e.atoms.get(t),i=new D(n.pp),a=new D(.05*3,.05*3),o=new nt(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 D(n,t),i=new D(D.dot(r,a),D.dot(r,a.rotateSC(1,0)));e=e?e.include(i):new nt(i,i)}))})),i=i?nt.union(i,e):e})),n=i.p0}else n=this.bracketBox.p1.add(new D(.5,.5));for(var o=Array.from(e.sgroups.values()),s=0;s<e.sgroups.size&&at(o,n);++s)n=n.add(new D(0,.5));if("INDIGO_CIP_DESC"===this.data.fieldName)if(1===this.atoms.length){var l,c=this.atoms[0],u=null===(l=e.atoms.get(c))||void 0===l?void 0:l.pp;u&&(n=u)}else n=t.getMassCentre(e,this.atoms);this.pp=n}}],[{key:"getOffset",value:function(t){return null!=t&&t.pp?D.diff(t.pp,t.bracketBox.p1):null}},{key:"isSaltOrSolvent",value:function(t){return et.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){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=D.diff(o,a).normalized()}else t.bracketDir=new D(1,0);var s=t.bracketDir,l=null,c=[];r.forEach((function(t){var n=e.atoms.get(t),r=new D(n.pp),i=new D(.05*3,.05*3),a=new nt(r,r).extend(i,i);c.push(a)})),c.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 D(n,t),i=new D(D.dot(r,s),D.dot(r,s.rotateSC(1,0)));e=e?e.include(i):new nt(i,i)}))})),l=l?nt.union(l,e):e}));var u=new D(.2,.4);l&&(l=l.extend(u,u)),t.bracketBox=l}},{key:"getBracketParameters",value:function(t,e,n,r,i,a){var o,s,l,c,u,h,d=[],f=Object.values(e),p=f.flat();return p.length<2?function(){i=i||new D(1,0),a=a||i.rotateSC(1,0);var t=Math.min(.25,.3*r.sz().x),e=D.lc2(i,r.p0.x,a,.5*(r.p0.y+r.p1.y)),n=D.lc2(i,r.p1.x,a,.5*(r.p0.y+r.p1.y)),o=r.sz().y;d.push(new rt(e,i.negated(),t,o),new rt(n,i,t,o))}():2===p.length&&2===f.length?(o=t.bonds.get(p[0]),s=t.bonds.get(p[1]),l=o.getCenter(t),c=s.getCenter(t),h=(u=D.diff(c,l).normalized()).negated(),d.push(new rt(l.addScaled(h,0),h,.25,1.5),new rt(c.addScaled(u,0),u,.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();d.push(new rt(i,a,.2,1))}}(),d}},{key:"getObjBBox",value:function(t,e){for(var n=e.atoms.get(t[0]).pp,r=new nt(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 F(t.atoms),t.parentAtomSet=new F(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 l=e.bonds.get(r[1]);a=t.parentAtomSet.has(l.begin)?l.begin:l.end,o=l}for(var c=a,u=[],h=function(r){var s={};if(t.atoms.forEach((function(n){var r=e.atoms.get(n),i=e.atoms.add(new V(r));u.push(i),t.atomSet.add(i),s[n]=i})),n.forEach((function(t){var n=e.bonds.get(t),r=new Y(n);r.begin=s[r.begin],r.end=s[r.end],e.bonds.add(r)})),null!==o){var l=new Y(o);l.begin=c,l.end=s[i],e.bonds.add(l),c=s[a]}},d=0;d<t.data.mul-1;d++)h();if(c>=0){var f=e.bonds.get(r[1]);f.begin===a?f.begin=c:f.end=c}t.bonds=r,u.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 D,r=0;r<e.length;++r)n=n.addScaled(t.atoms.get(e[r]).pp,1/e.length);return n}}]),t}();function at(t,e){return t.some((function(t){if(!t.pp)return!1;var n=t.pp.add(new D(.5,.5)),r=e.add(new D(.5,.5));return nt.segmentIntersection(t.pp,n,e,r)}))}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 st(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)?st(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 st(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)(it,"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 lt,ct=new WeakMap,ut=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=ct),i.set(n,a),s()(null!=e),(0,f.Z)(this,ct,e)}return(0,i.Z)(t,[{key:"name",get:function(){return(0,p.Z)(this,ct).data.name}},{key:"relatedSGroupId",get:function(){return(0,p.Z)(this,ct).id}},{key:"isExpanded",get:function(){return(0,p.Z)(this,ct).data.expanded}},{key:"relatedSGroup",get:function(){return(0,p.Z)(this,ct)}}],[{key:"isFunctionalGroup",value:function(t){var e=tt.getInstance().getFunctionalGroupsList(),n=t.data.name;return"SUP"===t.type&&(e.some((function(t){return t.name===n}))||it.isSaltOrSolvent(n))}},{key:"getFunctionalGroupByName",value:function(t){return tt.getInstance().getFunctionalGroupsList().find((function(e){var n=e.name,r=e.abbreviation;return n===t||r===t}))||null}},{key:"atomsInFunctionalGroup",value:function(t,e){if(0===t.size)return null;var n,r=ot(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=ot(e.values());try{for(i.s();!(r=i.n()).done;){var a=r.value;if(it.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=ot(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=ot(e.values());try{for(i.s();!(r=i.n()).done;){var a=r.value;if(it.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,ct))}},{key:"isAttachedSGroup",value:function(t,e){var n,r,i,a,o=ot(e.bonds.values());try{for(o.s();!(n=o.n()).done;){var s=n.value;if(void 0,void 0,i=(r=s).begin,a=r.end,t.atoms.includes(i)&&!t.atoms.includes(a)||t.atoms.includes(a)&&!t.atoms.includes(i))return!0}}catch(t){o.e(t)}finally{o.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=ot(i.values());try{for(s.s();!(r=s.n()).done;){var l=r.value,c=t.isFunctionalGroup(l),u=l.atoms.includes(e);if(c&&u){var h,d=ot(a.values());try{for(d.s();!(h=d.n()).done;){var f=h.value,p=f.begin===e&&!o(f.end,l),m=f.end===e&&!o(f.begin,l);if(p||m)return!0}}catch(t){d.e(t)}finally{d.f()}if(!this.isAttachedSGroup(l,n))return l.atoms[0]===e}}}catch(t){s.e(t)}finally{s.f()}return!1}},{key:"isFirstAtomInFunctionalGroup",value:function(e,n){var r,i=ot(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,i){var a=[];return i?n.forEach((function(e){t.isContractedFunctionalGroup(e.item.id,r)&&a.push.apply(a,(0,d.Z)(e.item.atoms))})):n.forEach((function(e){t.isContractedFunctionalGroup(e.id,r)&&a.push.apply(a,(0,d.Z)(e.atoms))})),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}(),ht=(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 D,this.norm=new D,this.ang=0,this.p=new D,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})),dt=(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!==Y.PATTERN.TYPE.AROMATIC&&(a.aromatic=!1),e.type===Y.PATTERN.TYPE.DOUBLE&&a.dblBonds++}))})),ft=function(){function t(e){(0,r.Z)(this,t),this.frags=new F,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"}(lt||(lt={}));var pt,mt=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 D(e.pos[n]):new D}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 D.centre(this.pos[0],this.pos[1])}}],[{key:"isElliptical",value:function(t){return[lt.EllipticalArcFilledBow,lt.EllipticalArcFilledTriangle,lt.EllipticalArcOpenHalfAngle,lt.EllipticalArcOpenAngle].includes(t.mode)}}]),t}(),vt=function(){function t(e){(0,r.Z)(this,t),this.pp=null!=e&&e.pp?new D(e.pp):new D}return(0,i.Z)(t,[{key:"clone",value:function(){return new t(this)}}]),t}(),gt=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 l=this.getAtomSetRelations(a,new F(o));e=l.parent,n=l.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 F(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;s()(this.parent.has(t),"sgid is not in the forest"),s()(this.children.has(t),"sgid is not in the forest");var r=this.parent.get(t),i=this.children.get(r);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(t){t.ellipse="ellipse",t.rectangle="rectangle",t.line="line"}(pt||(pt={}));var yt=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 D(e.pos[n]):new D}this.mode=(null==e?void 0:e.mode)||pt.line}return(0,i.Z)(t,[{key:"clone",value:function(){return new t(this)}},{key:"center",value:function(){return this.mode===pt.rectangle?D.centre(this.pos[0],this.pos[1]):this.pos[0]}}]),t}();function bt(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 xt(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)?xt(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 xt(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 wt=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,u.Z)(e);if(n){var i=(0,u.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,v.Z)(t),"nextId",0),t}return(0,i.Z)(s,[{key:"add",value:function(t){var e=this.nextId++;return(0,g.Z)((0,u.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=bt(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=bt(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=bt(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 Et(t,e){for(var n=0;n<t.length;++n)if(t[n]===e)return!1;return t.push(e),!0}var St,Rt=function(){function t(){(0,r.Z)(this,t),this.atoms=new wt,this.bonds=new wt,this.sgroups=new wt,this.halfBonds=new wt,this.loops=new wt,this.isReaction=!1,this.rxnArrows=new wt,this.rxnPluses=new wt,this.frags=new wt,this.rgroups=new wt,this.name="",this.abbreviation="",this.sGroupForest=new gt,this.simpleObjects=new wt,this.texts=new wt,this.functionalGroups=new wt,this.highlights=new wt}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 F;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 F;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 l=this;e=e||new F(this.atoms.keys()),n=n||new F(this.bonds.keys()),o=o||new F(this.simpleObjects.keys()),s=s||new F(this.texts.keys()),a=a||new Map,n=n.filter((function(t){var n=l.bonds.get(t);return e.has(n.begin)&&e.has(n.end)}));var c=new F;this.atoms.forEach((function(t,n){e.has(n)&&c.add(t.fragment)}));var u=new Map;this.frags.forEach((function(e,n){c.has(n)&&u.set(n,t.frags.add(null))}));var h=[];this.rgroups.forEach((function(e,n){var r=i;if(r||(e.frags.forEach((function(t,e){h.push(e),c.has(e)&&(r=!0)})),r)){var a=t.rgroups.get(n);a?e.frags.forEach((function(t,e){h.push(e),c.has(e)&&a.frags.add(u.get(e))})):t.rgroups.set(n,e.clone(u))}})),this.atoms.forEach((function(n,r){e.has(r)&&-1===h.indexOf(n.fragment)&&a.set(r,t.atoms.add(n.clone(u)))})),this.atoms.forEach((function(n,r){e.has(r)&&-1!==h.indexOf(n.fragment)&&a.set(r,t.atoms.add(n.clone(u)))})),u.forEach((function(e,n){var r=l.frags.get(n);r&&r instanceof J&&t.frags.set(e,l.frags.get(n).clone(a))}));var d=new Map;return this.bonds.forEach((function(e,r){n.has(r)&&d.set(r,t.bonds.add(e.clone(a)))})),this.sgroups.forEach((function(n){if(!n.atoms.some((function(t){return!e.has(t)}))){n=it.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=ut.clone(e),t.functionalGroups.add(e)})),o.forEach((function(e){t.simpleObjects.add(l.simpleObjects.get(e).clone())})),s.forEach((function(e){t.texts.add(l.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){it.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 Y.PATTERN.TYPE.SINGLE:e+=1;break;case Y.PATTERN.TYPE.DOUBLE:e+=2;break;case Y.PATTERN.TYPE.TRIPLE:e+=3;break;case Y.PATTERN.TYPE.DATIVE:case Y.PATTERN.TYPE.HYDROGEN:break;case Y.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 ht(e.begin,e.end,t)),this.halfBonds.set(e.hb2,new ht(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=D.diff(r,n).normalized();e.dir=D.dist(r,n)>1e-4?i:new D(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=D.dot(r.dir,n.dir),n.leftCos=D.dot(r.dir,n.dir),r.rightSin=D.cross(r.dir,n.dir),n.leftSin=D.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),Et(a.neiAtoms,e.end)}})),i.sgs.forEach((function(i){if(!r.sgs.has(i)){var a=t.sgroups.get(i);a.xBonds.push(n),Et(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=D.min(e.min,t),e.max=D.max(e.max,t)})):(e.min=D.min(e.min,t),e.max=D.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 D(0,0),max:new D(1,1)}),e}},{key:"getCoordBoundingBoxObj",value:function(){var t=null;return this.atoms.forEach((function(e){var n;n=e.pp,t?(t.min=D.min(t.min,n),t.max=D.max(t.max,n)):t={min:new D(n),max:new D(n)}})),t}},{key:"getBondLengthData",value:function(){var t=this,e=0,n=0;return this.bonds.forEach((function(r){e+=D.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=D.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 F;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 F,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 J,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 F([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 l=this.atoms.get(s.begin).pp,c=this.atoms.get(s.end).pp;if(nt.segmentIntersection(r,i,l,c))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 l=r[s],c=t.slice(l,i+1);e.push(c),i<t.length&&t.splice(l,i-l+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(D.cross(n.dir,r.dir),D.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 F;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,d.Z)(t)),r.loops.set(e,new dt(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=-U(e.radical));if(2===i)return void(e.implicitH=1-U(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=L.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=D.lc2(r.min,.5,r.max,.5),o=0;a.x>n[o];)++o;i[o]=i[o]||new F,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 D.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){ut.isFunctionalGroup(e)&&t.functionalGroups.add(new ut(e))}))}}]),t}();!function(t){t.Bold="BOLD",t.Italic="ITALIC",t.Subscript="SUBSCRIPT",t.Superscript="SUPERSCRIPT",t.FontSize="CUSTOM_FONT_SIZE"}(St||(St={}));var At,Ot=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 D(t)})):[new D,new D,new D,new D],this.content=(null==e?void 0:e.content)||"",this.position=null!=e&&e.position?new D(e.position):new D}return(0,i.Z)(t,[{key:"setPos",value:function(t){this.pos=t||[]}},{key:"clone",value:function(){return new t(this)}}]),t}(),Pt=(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})),kt=function(t){if("object"===(0,y.Z)(t)&&t.y){var e=(0,b.cloneDeep)(t);return e.y=-e.y,e}},Tt=function(t){return(0,b.cloneDeepWith)(t,kt)};function Bt(t,e,n,r){null==n||n===r||Array.isArray(n)&&0===n.length||(t[e]=n)}function Zt(t){return("number"==typeof t?t:parseFloat(t)).toFixed(8)}!function(t){t.LOADING="LOADING",t.SUCCESS="SUCCESS",t.FAILURE="FAILURE"}(At||(At={}));var Ct,Mt=(Ct=(0,x.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(At.LOADING),t.prev=1,t.next=4,e();case 4:return r=t.sent,n.emit(At.SUCCESS),t.abrupt("return",r);case 9:return t.prev=9,t.t0=t.catch(1),n.emit(At.FAILURE),t.abrupt("return",void 0);case 13:case"end":return t.stop()}}),t,null,[[1,9]])}))),function(t,e){return Ct.apply(this,arguments)});function Lt(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 It(t){var e={atoms:Array.from(t.atoms.values()).map((function(t){return"R#"===t.label?function(t){var e={type:"rg-label"};return Bt(e,"location",[t.pp.x,-t.pp.y,t.pp.z]),Bt(e,"attachmentPoints",t.attpnt,0),Bt(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?(Bt(n={type:"atom-list"},"location",[(e=t).pp.x,-e.pp.y,e.pp.z]),Bt(n,"attachmentPoints",e.attpnt,0),Bt(n,"elements",e.atomList.labelList()),Bt(n,"notList",e.atomList.notList,!1),n):function(t){var e={};return Bt(e,"label",t.label),Bt(e,"alias",t.alias),Bt(e,"location",[t.pp.x,-t.pp.y,t.pp.z]),Bt(e,"charge",t.charge,0),Bt(e,"explicitValence",t.explicitValence,-1),Bt(e,"isotope",t.isotope,0),Bt(e,"radical",t.radical,0),Bt(e,"attachmentPoints",t.attpnt,0),Bt(e,"stereoLabel",t.stereoLabel,null),Bt(e,"stereoParity",t.stereoCare,0),Bt(e,"weight",t.weight,0),Bt(e,"ringBondCount",t.ringBondCount,0),Bt(e,"substitutionCount",t.substitutionCount,0),Bt(e,"unsaturatedAtom",!!t.unsaturatedAtom,!1),Bt(e,"hCount",t.hCount,0),Bt(e,"mapping",parseInt(t.aam),0),Bt(e,"invRet",t.invRet,0),Bt(e,"exactChangeFlag",!!t.exactChangeFlag,!1),e}(t);var e,n}))};0!==t.bonds.size&&(e.bonds=Array.from(t.bonds.values()).map(Nt)),0!==t.sgroups.size&&(e.sgroups=Array.from(t.sgroups.values()).map((function(e){return function(t,e){var n={};switch(Bt(n,"type",e.type),Bt(n,"atoms",e.atoms),e.type){case"GEN":break;case"MUL":Bt(n,"mul",e.data.mul||1);break;case"SRU":Bt(n,"subscript",e.data.subscript||"n"),Bt(n,"connectivity",e.data.connectivity.toUpperCase()||"ht");break;case"SUP":Bt(n,"name",e.data.name||""),Bt(n,"expanded",e.data.expanded),Bt(n,"id",e.id);break;case"DAT":var r=e.data;Bt(n,"placement",r.absolute,!0),Bt(n,"display",r.attached,!1),Bt(n,"context",r.context),Bt(n,"fieldName",r.fieldName),Bt(n,"fieldData",r.fieldValue),Bt(n,"bonds",it.getBonds(t,e))}return n}(t,e)})));var n=t.frags.get(0);return n&&Bt(e,"stereoFlagPosition",n.stereoFlagPosition,null),function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Lt(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Lt(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}({type:"molecule"},e)}function Nt(t){var e={};return Bt(e,"type",t.type),Bt(e,"atoms",[t.begin,t.end]),Bt(e,"stereo",t.stereo,0),Bt(e,"topology",t.topology,0),Bt(e,"center",t.reactingCenterStatus,0),e}function Dt(t){var e=new Rt;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 Bt(r,"pp",{x:t.location[0],y:-t.location[1],z:t.location[2]||0}),Bt(r,"attpnt",t.attachmentPoints),Bt(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 V(r)}(t)),"atom-list"===t.type&&e.atoms.add(function(t){var e={label:"L#"};return Bt(e,"pp",{x:t.location[0],y:-t.location[1],z:t.location[2]||0}),Bt(e,"attpnt",t.attachmentPoints),Bt(e,"atomList",{ids:t.elements.map((function(t){var e;return null===(e=L.get(t))||void 0===e?void 0:e.number})).filter((function(t){return t})),notList:t.notList}),new V(e)}(t)),t.type||e.atoms.add((Bt(r={},"label",(n=t).label),Bt(r,"alias",n.alias),Bt(r,"pp",{x:n.location[0],y:-n.location[1],z:n.location[2]||0}),Bt(r,"charge",n.charge),Bt(r,"explicitValence",n.explicitValence),Bt(r,"isotope",n.isotope),Bt(r,"radical",n.radical),Bt(r,"attpnt",n.attachmentPoints),Bt(r,"stereoLabel",n.stereoLabel),Bt(r,"stereoParity",n.stereoParity),Bt(r,"weight",n.weight),Bt(r,"ringBondCount",n.ringBondCount),Bt(r,"substitutionCount",n.substitutionCount),Bt(r,"unsaturatedAtom",Number(Boolean(n.unsaturatedAtom))),Bt(r,"hCount",n.hCount),Bt(r,"aam",n.mapping),Bt(r,"invRet",n.invRet),Bt(r,"exactChangeFlag",Number(Boolean(n.exactChangeFlag))),new V(r)))})),t.bonds&&t.bonds.forEach((function(t){return e.bonds.add((Bt(r={},"type",(n=t).type),Bt(r,"topology",n.topology),Bt(r,"reactingCenterStatus",n.center),Bt(r,"stereo",n.stereo),Bt(r,"begin",n.atoms[0]),Bt(r,"end",n.atoms[1]),new Y(r)));var n,r})),t.sgroups&&t.sgroups.forEach((function(t){return e.sgroups.add(function(t){var e=new it(t.type);switch(Bt(e,"atoms",t.atoms),t.type){case"GEN":break;case"MUL":Bt(e.data,"mul",t.mul);break;case"SRU":Bt(e.data,"subscript",t.subscript),Bt(e.data,"connectivity",t.connectivity.toLowerCase());break;case"SUP":Bt(e.data,"name",t.name),Bt(e.data,"expanded",t.expanded),Bt(e,"id",t.id);break;case"DAT":Bt(e.data,"absolute",t.placement),Bt(e.data,"attached",t.display),Bt(e.data,"context",t.context),Bt(e.data,"fieldName",t.fieldName),Bt(e.data,"fieldValue",t.fieldData)}return e}(t))})),e.initHalfBonds(),e.initNeighbors(),e.markFragments(),e.bindSGroupsToFunctionalGroups(),e}function _t(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 jt(t,e){var n=t.getCoordBoundingBox(e);return D.centre(n.min,n.max)}function Gt(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 Ft(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Gt(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Gt(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function zt(t,e){var n={};return Bt(n,"number",t),Bt(n,"range",e.range,""),Bt(n,"resth",e.resth,!1),Bt(n,"ifthen",e.ifthen,0),n}var Ht={$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 Ut(t,e){switch(t.type){case"arrow":case"plus":!function(t,e){"arrow"===t.type?e.rxnArrows.add(new mt(Tt(t.data))):e.rxnPluses.add(new vt({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=D.dist(t.data.pos[1],t.data.pos[0]),n=t.data.pos[0];return{mode:pt.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 yt(Tt(n)))}(t,e);break;case"molecule":var n=Dt(t);t.stereoFlagPosition&&(n.frags.get(0).stereoFlagPosition=new D(t.stereoFlagPosition)),n.mergeInto(e);break;case"rgroup":(function(t){var e,n,r=Dt(t),i=(Bt(n={},"range",(e=t.rlogic).range),Bt(n,"resth",e.resth),Bt(n,"ifthen",e.ifthen),new ft(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=Tt(t.data);e.texts.add(new Ot(n))}(t,e)}}var Vt=function(){function t(){(0,r.Z)(this,t)}return(0,i.Z)(t,[{key:"deserialize",value:function(t){var e=new Rt,n=JSON.parse(t);if(!function(t){return(new(R())).compile(Ht)(t)}(n))throw new Error("Cannot deserialize input JSON.");var r=n.root.nodes;return Object.keys(r).forEach((function(t){r[t].type?Ut(r[t],e):r[t].$ref&&Ut(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 Bt(e,"moleculeName",t.name,""),Bt(e,"creatorProgram",null,""),Bt(e,"comment",null,""),0!==Object.keys(e).length?e:null}(t);n&&(e.header=n);var r=function(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 _t(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)?_t(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 l=Array.from(s.frags.values()).reduce((function(e,n){return e.union(t.getFragmentIds(n))}),new F);n.push({type:"rgroup",fragment:t.clone(l),center:jt(t,l),data:{rgnumber:o,rgroup:s}})}}catch(t){i.e(t)}finally{i.f()}return Array.from(t.frags.keys()).filter((function(t){return!r.has(t)})).forEach((function(e){var r=t.getFragmentIds(e);n.push({type:"molecule",fragment:t.clone(r),center:jt(t,r)})})),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 Map;e.forEach((function(t,e){n.set(e,t)})),t.fragment.sgroups=n}})),n}(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++)]=It(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=Ft({rlogic:zt(e.rgnumber,e.rgroup)},It(t));return Ft(Ft({},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:Tt(t.data)});break;case"simpleObject":e.root.nodes.push({type:"simpleObject",data:Tt(t.data)});break;case"text":e.root.nodes.push({type:"text",data:Tt(t.data)})}var n,r})),JSON.stringify(e,null,4)}}]),t}(),Wt={bondTypeMap:{1:Y.PATTERN.TYPE.SINGLE,2:Y.PATTERN.TYPE.DOUBLE,3:Y.PATTERN.TYPE.TRIPLE,4:Y.PATTERN.TYPE.AROMATIC,5:Y.PATTERN.TYPE.SINGLE_OR_DOUBLE,6:Y.PATTERN.TYPE.SINGLE_OR_AROMATIC,7:Y.PATTERN.TYPE.DOUBLE_OR_AROMATIC,8:Y.PATTERN.TYPE.ANY,9:Y.PATTERN.TYPE.DATIVE,10:Y.PATTERN.TYPE.HYDROGEN},bondStereoMap:{0:Y.PATTERN.STEREO.NONE,1:Y.PATTERN.STEREO.UP,4:Y.PATTERN.STEREO.EITHER,6:Y.PATTERN.STEREO.DOWN,3:Y.PATTERN.STEREO.CIS_TRANS},v30bondStereoMap:{0:Y.PATTERN.STEREO.NONE,1:Y.PATTERN.STEREO.UP,2:Y.PATTERN.STEREO.EITHER,3:Y.PATTERN.STEREO.DOWN},bondTopologyMap:{0:Y.PATTERN.TOPOLOGY.EITHER,1:Y.PATTERN.TOPOLOGY.RING,2:Y.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]},Yt={fmtInfo:Wt,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 Rt,s=[],l=[],c=[],u=[],h=[],d=[],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 v,g,y,b,x=1/(0===f.cnt?1:f.totalLength/f.cnt);for(a=0;a<t.length;++a)(p=t[a]).scale(x);for(a=0;a<t.length;++a){var w=(p=t[a]).getCoordBoundingBoxObj();if(w){var E=a<e?1:a<e+n?2:3;1===E?(s.push(w),u.push(p)):3===E?(l.push(w),h.push(p)):2===E&&(c.push(w),d.push(p)),p.atoms.forEach((function(t){t.rxnFragmentType=E}))}}function S(t,e,n,r,i){var a=new D(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 R=0;for(a=0;a<u.length;++a)R+=S(o,u[a],s[a],R,!1)+2;for(R+=2,a=0;a<h.length;++a)R+=S(o,h[a],l[a],R,!0)+2;for(R+=2,a=0;a<d.length;++a)R+=S(o,d[a],c[a],R,!1)+2}else{for(a=0;a<u.length;++a)u[a].mergeInto(o);for(a=0;a<h.length;++a)h[a].mergeInto(o);for(a=0;a<d.length;++a)d[a].mergeInto(o)}var A=null,O=null;for(a=0;a<s.length-1;++a)v=s[a],g=s[a+1],y=(v.max.x+g.min.x)/2,b=(v.max.y+v.min.y+g.max.y+g.min.y)/4,o.rxnPluses.add(new vt({pp:new D(y,b)}));for(a=0;a<s.length;++a)0===a?((A={}).max=new D(s[a].max),A.min=new D(s[a].min)):(A.max=D.max(A.max,s[a].max),A.min=D.min(A.min,s[a].min));for(a=0;a<c.length-1;++a)v=c[a],g=c[a+1],y=(v.max.x+g.min.x)/2,b=(v.max.y+v.min.y+g.max.y+g.min.y)/4,o.rxnPluses.add(new vt({pp:new D(y,b)}));for(a=0;a<c.length;++a)0===a?((O={}).max=new D(c[a].max),O.min=new D(c[a].min)):(O.max=D.max(O.max,c[a].max),O.min=D.min(O.min,c[a].min));if(g=O,(v=A)||g){var P=v?new D(v.max.x,(v.max.y+v.min.y)/2):null,k=g?new D(g.min.x,(g.max.y+g.min.y)/2):null;P||(P=new D(k.x-3,k.y)),k||(k=new D(P.x+3,P.y));var T=D.lc2(P,.5,k,.5),B=new D(T.x-1,T.y,T.z),Z=new D(T.x+1,T.y,T.z);o.rxnArrows.add(new mt({mode:"open-angle",pos:[B,Z]}))}else o.rxnArrows.add(new mt({mode:"open-angle",pos:[new D(0,0),new D(2,0)]}));return o.isReaction=!0,o},rgMerge:function(t,e){var n=new Rt;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 ft);var a=new J,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 $t(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)?$t(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 $t(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 Xt(t,e){for(var n=new wt,r=Yt.partitionLineFixed(t,3,!0),i=Yt.parseDecimalInt(r[0]),a=0;a<i;++a){var o=Yt.parseDecimalInt(r[2*a+1])-1,s=e?r[2*a+2].trim():Yt.parseDecimalInt(r[2*a+2]);n.set(o,s)}return n}function Kt(t,e,n){t.data.mul=t.data.subscript-0;var r={};t.atoms=it.filterAtoms(t.atoms,n),t.patoms=it.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=it.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),l=[];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?l.push(e):n?t.begin=r[t.begin]:i&&(t.end=r[t.end])}),t);for(var c=0;c<l.length;++c)e.bonds.delete(l[c]);for(var u in r)e.atoms.delete(+u),n[u]=-1;t.atoms=t.patoms,t.patoms=null}function Jt(t){t.data.connectivity=(t.data.connectivity||"EU").trim().toLowerCase()}function Qt(t){t.data.name=(t.data.subscript||"").trim(),t.data.subscript=""}function te(t,e,n){}function ee(t,e){t.data.absolute||(t.pp=t.pp.add(it.getMassCentre(e,t.atoms)))}function ne(t){}function re(t){}function ie(t){}function ae(t){}function oe(t){}function se(t){}function le(t){}function ce(t){}function ue(t){}function he(t){}function de(t,e){var n=Yt.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(),l=n[7].trim();l="ALL"===l?-1:Yt.parseDecimalInt(l);var c=n[10].trim(),u=Yt.parseDecimalInt(n[11].trim());t.pp=new D(r,-i),t.data.attached=a,t.data.absolute=o,t.data.showUnits=s,t.data.nCharsToDisplay=l,t.data.tagChar=c,t.data.daspPos=u}function fe(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 pe={readKeyValuePairs:Xt,readKeyMultiValuePairs:function(t,e){for(var n=[],r=Yt.partitionLineFixed(t,3,!0),i=Yt.parseDecimalInt(r[0]),a=0;a<i;++a)n.push([Yt.parseDecimalInt(r[2*a+1])-1,e?r[2*a+2].trim():Yt.parseDecimalInt(r[2*a+2])]);return n},loadSGroup:function(t,e,n){var r={SUP:Qt,MUL:Kt,SRU:Jt,MON:ne,MER:re,COP:ie,CRO:ae,MOD:oe,GRA:se,COM:le,MIX:ce,FOR:ue,DAT:ee,ANY:he,GEN:te};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(Xt(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 it(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=Xt(n,!r),s=qt(o.keys());try{for(s.s();!(a=s.n()).done;){var l=a.value;(i?t[l]:t[l].data)[e]=o.get(l)}}catch(t){s.e(t)}finally{s.f()}},applySGroupArrayProp:function(t,e,n,r){var i=Yt.parseDecimalInt(n.slice(1,4))-1,a=Yt.parseDecimalInt(n.slice(4,8)),o=function(t){for(var e=[],n=0;n<t.length;++n)e[n]=Yt.parseDecimalInt(t[n]);return e}(Yt.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=Yt.partitionLine(e,[4,31,2,20,2,3],!1),r=Yt.parseDecimalInt(n[0])-1,i=n[1].trim(),a=n[2].trim(),o=n[3].trim(),s=n[4].trim(),l=n[5].trim(),c=t[r];c.data.fieldType=a,c.data.fieldName=i,c.data.units=o,c.data.query=s,c.data.queryOp=l},applyDataSGroupInfo:de,applyDataSGroupData:fe,applyDataSGroupInfoLine:function(t,e){de(t[Yt.parseDecimalInt(e.substr(0,4))-1],e.substr(5))},applyDataSGroupDataLine:function(t,e,n){var r=Yt.parseDecimalInt(e.substr(0,5))-1,i=e.substr(5);fe(t[r],i,n)},applyDataSGroupExpand:function(t,e){t.data.expanded=e}};function me(t){var e=Yt.partitionLine(t,Yt.fmtInfo.atomLinePartition),n={pp:new D(parseFloat(e[0]),-parseFloat(e[1]),parseFloat(e[2])),label:e[4].trim(),explicitValence:Yt.fmtInfo.valenceMap[Yt.parseDecimalInt(e[10])],massDifference:Yt.parseDecimalInt(e[5]),charge:Yt.fmtInfo.chargeMap[Yt.parseDecimalInt(e[6])],hCount:Yt.parseDecimalInt(Yt.parseDecimalInt(e[8])),stereoCare:0!==Yt.parseDecimalInt(e[9]),aam:Yt.parseDecimalInt(e[14]),invRet:Yt.parseDecimalInt(e[15]),exactChangeFlag:Yt.parseDecimalInt(e[16])};return new V(n)}function ve(t){var e=Yt.partitionLine(t,Yt.fmtInfo.bondLinePartition),n={begin:Yt.parseDecimalInt(e[0])-1,end:Yt.parseDecimalInt(e[1])-1,type:Yt.fmtInfo.bondTypeMap[Yt.parseDecimalInt(e[2])],stereo:Yt.fmtInfo.bondStereoMap[Yt.parseDecimalInt(e[3])],xxx:e[4],topology:Yt.fmtInfo.bondTopologyMap[Yt.parseDecimalInt(e[5])],reactingCenterStatus:Yt.parseDecimalInt(e[6])};return new Y(n)}function ge(t){for(var e=Yt.partitionLine(t,Yt.fmtInfo.atomListHeaderPartition),n=Yt.parseDecimalInt(e[0])-1,r="T"===e[2].trim(),i=Yt.parseDecimalInt(e[4].trim()),a=t.slice(Yt.fmtInfo.atomListHeaderLength),o=[],s=Yt.fmtInfo.atomListHeaderItemLength,l=0;l<i;++l)o[l]=Yt.parseDecimalInt(a.slice(l*s,(l+1)*s-1));return{aid:n,atomList:new N({notList:r,ids:o})}}function ye(t,e){var n,r=new Rt,i=Yt.parseDecimalInt(e[0]),a=Yt.parseDecimalInt(e[1]),o=Yt.parseDecimalInt(e[2]),s=1===Yt.parseDecimalInt(e[4]),l=0===Yt.parseDecimalInt(e[4]),c=Yt.parseDecimalInt(e[5]),u=Yt.parseDecimalInt(e[10]),h=0,d=t.slice(h,h+i);h+=i;var f=t.slice(h,h+a);h+=a;var p=t.slice(h,h+o);h+=o+c,d.map(me).forEach((function(t){return r.atoms.add(t)})),f.map(ve).forEach((function(t){t.stereo&&s&&(r.atoms.get(t.begin).stereoLabel=G.Abs),t.stereo&&l&&(r.atoms.get(t.begin).stereoLabel="".concat(G.And,"1")),r.bonds.add(t)})),p.map(ge).forEach((function(t){r.atoms.get(t.aid).atomList=t.atomList,r.atoms.get(t.aid).label="L#"}));var m={},v={},g=function(t,e,n,r,i,a){for(var o=new wt;n<r;){var s=e[n];if("A"===s.charAt(0)){var l=e[++n],c=/'.+'/.test(l);c&&!o.get("pseudo")&&o.set("pseudo",new wt),c||o.get("alias")||o.set("alias",new wt),o.get(c?"pseudo":"alias").set(Yt.parseDecimalInt(s.slice(3))-1,l)}else if("M"===s.charAt(0)){var u=s.slice(3,6),h=s.slice(6);if("END"===u)break;if("CHG"===u)o.get("charge")||o.set("charge",pe.readKeyValuePairs(h));else if("RAD"===u)o.get("radical")||o.set("radical",pe.readKeyValuePairs(h));else if("ISO"===u)o.get("isotope")||o.set("isotope",pe.readKeyValuePairs(h));else if("RBC"===u)o.get("ringBondCount")||o.set("ringBondCount",pe.readKeyValuePairs(h));else if("SUB"===u)o.get("substitutionCount")||o.set("substitutionCount",pe.readKeyValuePairs(h));else if("UNS"===u)o.get("unsaturatedAtom")||o.set("unsaturatedAtom",pe.readKeyValuePairs(h));else if("RGP"===u){o.get("rglabel")||o.set("rglabel",new wt);for(var d=o.get("rglabel"),f=pe.readKeyMultiValuePairs(h),p=0;p<f.length;p++){var m=f[p];d.set(m[0],(d.get(m[0])||0)|1<<m[1]-1)}}else if("LOG"===u){h=h.slice(4);var v=Yt.parseDecimalInt(h.slice(0,3).trim()),g=Yt.parseDecimalInt(h.slice(4,7).trim()),y=Yt.parseDecimalInt(h.slice(8,11).trim()),b=h.slice(12).trim(),x={};g>0&&(x.ifthen=g),x.resth=1===y,x.range=b,a[v]=x}else if("APO"===u)o.get("attpnt")||o.set("attpnt",pe.readKeyValuePairs(h));else if("ALS"===u){var w=(S=Yt.partitionLine(h,[1,3,3,1,1,1]),R=Yt.partitionLineFixed(h.slice(10),4,!1),A=void 0,O=void 0,P=void 0,k=void 0,T=void 0,A=Yt.parseDecimalInt(S[1])-1,O=Yt.parseDecimalInt(S[2]),P="T"===S[4].trim(),k=function(t){for(var e=[],n=0;n<t.length;++n){var r=L.get(t[n].trim());r&&e.push(r.number)}return e}(R.slice(0,O)),(T=new wt).set(A,new N({notList:P,ids:k})),T);o.get("atomList")||o.set("atomList",new wt),o.get("label")||o.set("label",new wt),w.forEach((function(t,e){o.get("label").set(e,"L#"),o.get("atomList").set(e,t)}))}else if("STY"===u)pe.initSGroup(i,h);else if("SST"===u)pe.applySGroupProp(i,"subtype",h);else if("SLB"===u)pe.applySGroupProp(i,"label",h,!0);else if("SPL"===u)pe.applySGroupProp(i,"parent",h,!0,!0);else if("SCN"===u)pe.applySGroupProp(i,"connectivity",h);else if("SAL"===u)pe.applySGroupArrayProp(i,"atoms",h,-1);else if("SBL"===u)pe.applySGroupArrayProp(i,"bonds",h,-1);else if("SPA"===u)pe.applySGroupArrayProp(i,"patoms",h,-1);else if("SMT"===u){var E=Yt.parseDecimalInt(h.slice(0,4))-1;i[E].data.subscript=h.slice(4).trim()}else"SDT"===u?pe.applyDataSGroupDesc(i,h):"SDD"===u?pe.applyDataSGroupInfoLine(i,h):"SCD"===u?pe.applyDataSGroupDataLine(i,h,!1):"SED"===u?pe.applyDataSGroupDataLine(i,h,!0):"SDS"===u&&h.slice(7).trim().split(" ").forEach((function(t){var e=Number(t)-1;i[e].data.expanded=!0}))}++n}var S,R,A,O,P,k,T;return o}(0,t,h,Math.min(t.length,h+u),m,v);g.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 x=m[y];if("DAT"===x.type&&0===x.atoms.length){var w=m[y].parent;if(w>=0){var E=m[w-1];"GEN"===E.type&&(x.atoms=[].slice.call(E.atoms))}}}for(y in m)pe.loadSGroup(r,m[y],b);var S=[];for(y in m)it.filter(r,m[y],b),0!==m[y].atoms.length||m[y].allAtoms||S.push(+y);for(n=0;n<S.length;++n)r.sGroupForest.remove(S[n]),r.sgroups.delete(S[n]);for(var R in v){var A=parseInt(R,10);r.rgroups.set(A,new ft(v[A]))}return r}function be(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=xe(n),s={};for(var l in r){var c=parseInt(l,10);s[c]=[];for(var u=0;u<r[c].length;++u)s[c].push(xe(r[c][u]))}return Yt.rgMerge(o,s)}function xe(t){var e=Yt.partitionLine(t[0],Yt.fmtInfo.countsLinePartition);return ye(t=t.slice(1),e)}var we={parseCTabV2000:ye,parseRg2000:be,parseRxn2000:function(t,e){t=t.slice(4);var n=Yt.partitionLine(t[0],Yt.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 l,c=t.slice(0,s);0===c[0].search("\\$MDL")?l=be(c):(l=xe(c.slice(3))).name=c[0].trim(),o.push(l),t=t.slice(s)}return Yt.rxnMerge(o,r,i,a,e)}};function Ee(t){var e,n,r,i,a=ke(t),o={pp:new D(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 l={notList:!1},c=(s=s.substr(0,s.length-1)).match(/NOT ?\[/);if(c){l.notList=!0;var u=(0,m.Z)(c,1)[0];s=s.substr(u.length)}else{if("["!==s.charAt(0))throw new Error("Error: atom list expected, found '"+s+"'");s=s.substr(1)}l.ids=function(t){for(var e=[],n=0;n<t.length;++n){var r=L.get(t[n].trim());r&&e.push(r.number)}return e}(s.split(",")),o.atomList=new N(l),o.label="L#"}else o.label=s;for(a.splice(0,6),i=0;i<a.length;++i)if(n=(e=Te(a[i],"="))[0],r=e[1],n in Yt.fmtInfo.v30atomPropMap){var h=Yt.parseDecimalInt(r);if("VAL"===n){if(0===h)continue;-1===h&&(h=0)}o[Yt.fmtInfo.v30atomPropMap[n]]=h}else if("RGROUPS"===n){var d=(r=r.trim().substr(1,r.length-2)).split(" ").slice(1);o.rglabel=0;for(var f=0;f<d.length;++f)o.rglabel|=1<<d[f]-1}else"ATTCHPT"===n&&(o.attpnt=r.trim()-0);return new V(o)}function Se(t){var e,n,r,i,a=ke(t),o={begin:Yt.parseDecimalInt(a[2])-1,end:Yt.parseDecimalInt(a[3])-1,type:Yt.fmtInfo.bondTypeMap[Yt.parseDecimalInt(a[1])]};for(a.splice(0,4),i=0;i<a.length;++i)n=(e=Te(a[i],"="))[0],r=e[1],"CFG"===n?(o.stereo=Yt.fmtInfo.v30bondStereoMap[Yt.parseDecimalInt(r)],o.type===Y.PATTERN.TYPE.DOUBLE&&o.stereo===Y.PATTERN.STEREO.EITHER&&(o.stereo=Y.PATTERN.STEREO.CIS_TRANS)):"TOPO"===n?o.topology=Yt.fmtInfo.bondTopologyMap[Yt.parseDecimalInt(r)]:"RXCTR"===n?o.reactingCenterStatus=Yt.parseDecimalInt(r):"STBOX"===n&&(o.stereoCare=Yt.parseDecimalInt(r));return new Y(o)}function Re(t,e,n){for(n++;"M V30 END COLLECTION"!==e[n].trim();)n++;return++n}function Ae(t,e,n,r,i){var a,o="";for(i++;i<e.length;){if("END SGROUP"===(o=Ce(e[i++]).trim()).trim())return i;for(;"-"===o.charAt(o.length-1);)o=(o.substr(0,o.length-1)+Ce(e[i++])).trim();var s=Be(o),l=s[1],c=new it(l);c.number=s[0]-0,c.type=l,c.label=s[2]-0,n[c.number]=c;for(var u={},h=3;h<s.length;++h){var d=Te(s[h],"=");if(2!==d.length)throw new Error("A record of form AAA=BBB or AAA=(...) expected, got '"+s[h]+"'");var f=d[0];f in u||(u[f]=[]),u[f].push(d[1])}c.atoms=Ze(u.ATOMS[0],-1),u.PATOMS&&(c.patoms=Ze(u.PATOMS[0],-1)),c.bonds=u.BONDS?Ze(u.BONDS[0],-1):[];var p=u.BRKXYZ;if(c.brkxyz=[],p)for(var m=0;m<p.length;++m)c.brkxyz.push(Ze(p[m]));u.MULT&&(c.data.subscript=u.MULT[0]-0),u.LABEL&&(c.data.subscript=u.LABEL[0].trim()),u.CONNECT&&(c.data.connectivity=u.CONNECT[0].toLowerCase()),u.FIELDDISP&&pe.applyDataSGroupInfo(c,'"'===(a=u.FIELDDISP[0])[0]&&'"'===a[a.length-1]?a.substr(1,a.length-2):a),u.FIELDDATA&&pe.applyDataSGroupData(c,u.FIELDDATA[0],!0),u.FIELDNAME&&pe.applyDataSGroupName(c,u.FIELDNAME[0]),u.QUERYTYPE&&pe.applyDataSGroupQuery(c,u.QUERYTYPE[0]),u.QUERYOP&&pe.applyDataSGroupQueryOp(c,u.QUERYOP[0]),pe.loadSGroup(t,c,r),u.ESTATE&&pe.applyDataSGroupExpand(c,u.ESTATE[0])}throw new Error("S-group declaration incomplete.")}function Oe(t,e){var n=new Rt,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===Yt.parseDecimalInt(i[4]);if("M V30 BEGIN ATOM"===t[++r].trim()){var o;for(r++;r<t.length&&"END ATOM"!==(o=Ce(t[r++]).trim());){for(;"-"===o.charAt(o.length-1);)o=(o.substring(0,o.length-1)+Ce(t[r++])).trim();n.atoms.add(Ee(o))}if("M V30 BEGIN BOND"===t[r].trim())for(r++;r<t.length&&"END BOND"!==(o=Ce(t[r++]).trim());){for(;"-"===o.charAt(o.length-1);)o=(o.substring(0,o.length-1)+Ce(t[r++])).trim();var s=Se(o);s.stereo&&a&&(n.atoms.get(s.begin).stereoLabel="abs"),n.bonds.add(s)}for(var l={},c={};"M V30 END CTAB"!==t[r].trim();)if("M V30 BEGIN COLLECTION"===t[r].trim())r=Re(0,t,r);else{if("M V30 BEGIN SGROUP"!==t[r].trim())throw Error("CTAB V3000 invalid");r=Ae(n,t,l,c,r)}}if("M V30 END CTAB"!==t[r++].trim())throw Error("CTAB V3000 invalid");return e||Pe(n,t.slice(r)),n}function Pe(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 l=Oe(e.slice(i,i+s+1),!0);if(n[a].push(l),"M V30 END RGROUP"===e[i=i+s+1].trim()){i++;break}}else{var c=(o=o.slice(13)).trim().split(/\s+/g),u=Yt.parseDecimalInt(c[0]),h=Yt.parseDecimalInt(c[1]),d=c.slice(2).join(" "),f={};u>0&&(f.ifthen=u),f.resth=1===h,f.range=d,r[a]=f,i++}}}Object.keys(n).forEach((function(e){n[e].forEach((function(n){n.rgroups.set(e,new ft(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 ke(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 Te(t,e){var n=t.indexOf(e);return[t.slice(0,n),t.slice(n+1)]}function Be(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 Ze(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 Ce(t){if("M V30 "!==t.slice(0,7))throw new Error("Prefix invalid");return t.slice(7)}var Me={parseCTabV3000:Oe,readRGroups3000:Pe,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 l=[],c=[],u=null,h=[],d=0;d<t.length;++d){var f,p=t[d].trim();if(p.startsWith("M V30 COUNTS"));else{if("M END"===p)break;if("M V30 BEGIN PRODUCT"===p)u=c;else if("M V30 END PRODUCT"===p)u=null;else if("M V30 BEGIN REACTANT"===p)u=l;else if("M V30 END REACTANT"===p)u=null;else if(p.startsWith("M V30 BEGIN RGROUP"))f=s(d),h.push(t.slice(d,f+1)),d=f;else{if("M V30 BEGIN CTAB"!==p)throw new Error("line unrecognized: "+p);f=o(d),u.push(t.slice(d,f+1)),d=f}}}var m=[],v=l.concat(c);for(f=0;f<v.length;++f){var g=Oe(v[f],n);m.push(g)}var y=Yt.rxnMerge(m,r,i,a,e);return Pe(y,function(t){for(var e=[],n=0;n<t.length;++n)e=e.concat(t[n]);return e}(h)),y}};function Le(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],Yt.fmtInfo.countsLinePartition),n=e[11].trim();if(t=t.slice(1),"V2000"===n)return we.parseCTabV2000(t,e);if("V3000"===n)return Me.parseCTabV3000(t,!1);throw new Error("Molfile version unknown: "+n)}var Ie={MUL:it.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=it.getAtoms(e,t)},GEN:function(t,e){}},Ne={MUL:function(t,e,n,r,i){var a=(n[t.id]+"").padStart(3),o=[];o=(o=(o=o.concat(De("SAL",a,Array.from(t.atomSet.values()),r))).concat(De("SPA",a,Array.from(t.parentAtomSet.values()),r))).concat(De("SBL",a,t.bonds,i));var s="M SMT "+a+" "+t.data.mul;return o.push(s),(o=o.concat(_e(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(De("SAL",a,t.atoms,r))).concat(De("SBL",a,t.bonds,i))).concat(_e(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(De("SAL",a,t.atoms,r))).concat(De("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(it.getMassCentre(e,t.atoms)));var s=[];s=s.concat(De("SAL",i,t.atoms,r));var l="M SDT "+i+" "+(a.fieldName||"").padEnd(30)+(a.fieldType||"").padStart(2)+(a.units||"").padEnd(20)+(a.query||"").padStart(2);a.queryOp&&(l+=a.queryOp.padEnd(15)),s.push(l);var c,u="M SDD "+i+" "+Yt.paddedNum(o.x,10,4)+Yt.paddedNum(-o.y,10,4)+" "+(a.attached?"A":"D")+(a.absolute?"A":"R")+(a.showUnits?"U":" ")+" "+(a.nCharnCharsToDisplay>=0?Yt.paddedNum(a.nCharnCharsToDisplay,3):"ALL")+" 1 "+(a.tagChar||" ")+" "+Yt.paddedNum(a.daspPos,1)+" ";return s.push(u),(c=a.fieldValue,c.replace(je,"\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(De("SAL",a,t.atoms,r))).concat(De("SBL",a,t.bonds,i))).concat(_e(e,t,a))).join("\n")}};function De(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+" "+Yt.paddedNum(o,2),l=0;l<o;++l)s+=" "+Yt.paddedNum(r[n[15*a+l]],3);i.push(s)}return i}function _e(t,e,n){var r=new F(e.atoms),i=it.getCrossBonds(t,r);it.bracketPos(e,t,i);for(var a=e.bracketBox,o=e.bracketDir,s=o.rotateSC(1,0),l=it.getBracketParameters(t,i,r,a,o,s),c=[],u=0;u<l.length;++u){for(var h=l[u],d=h.c.addScaled(h.n,-.5*h.h).yComplement(),f=h.c.addScaled(h.n,.5*h.h).yComplement(),p="M SDI "+n+Yt.paddedNum(4,3),m=[d.x,d.y,f.x,f.y],v=0;v<m.length;++v)p+=Yt.paddedNum(m[v],10,4);c.push(p)}return c}var je=/\r\n|[\n\r]/g,Ge={parseCTab:Le,parseMol:function(t){if(0===t[0].search("\\$MDL")){var e=we.parseRg2000(t);return e.name=t[3].trim(),e}var n=Le(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 Me.parseRxn3000(t,e);var r=we.parseRxn2000(t,e);return r.name=t[1].trim(),r},prepareForSaving:Ie,saveToMolfile:Ne},Fe=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")?Ge.parseRxn(t,e):Ge.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{Ge.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,l=o.products,c=s.concat(l);this.molfile="$RXN\n"+e.name+"\n\n\n"+Yt.paddedNum(s.length,3)+Yt.paddedNum(l.length,3)+Yt.paddedNum(0,3)+"\n";for(var u=0;u<c.length;++u){var h=new t,d=e.clone(c[u],null,!0),f=h.saveMolecule(d,!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(Yt.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===W.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}):L.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=[],l=[],c=[],u=[],h=[],d=[],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&&l.push([e,n+1]);null!=t.attpnt&&u.push([e,t.attpnt]),0!==t.ringBondCount&&h.push([e,t.ringBondCount]),0!==t.substitutionCount&&f.push([e,t.substitutionCount]),0!==t.unsaturatedAtom&&d.push([e,t.unsaturatedAtom])})),t&&t.forEach((function(t,e){if(t.resth||t.ifthen>0||t.range.length>0){var n=" 1 "+Yt.paddedNum(e,3)+" "+Yt.paddedNum(t.ifthen,3)+" "+Yt.paddedNum(t.resth?1:0,3)+" "+t.range;c.push(n)}})),this.writeAtomPropList("M CHG",a),this.writeAtomPropList("M ISO",o),this.writeAtomPropList("M RAD",s),this.writeAtomPropList("M RGP",l);for(var p=0;p<c.length;++p)this.write("M LOG"+c[p]+"\n");if(this.writeAtomPropList("M APO",u),this.writeAtomPropList("M RBC",h),this.writeAtomPropList("M SUB",f),this.writeAtomPropList("M UNS",d),r.length>0)for(var m=0;m<r.length;++m){var v=r[m],g=this.molecule.atoms.get(v).atomList;this.write("M ALS"),this.writePaddedNumber(v+1,4),this.writePaddedNumber(g.ids.length,3),this.writeWhiteSpace(),this.write(g.notList?"T":"F");for(var y=g.labelList(),b=0;b<y.length;++b)this.writeWhiteSpace(),this.writePadded(y[b],3);this.writeCR()}var x={},w=1,E={};this.molecule.sGroupForest.getSGroupsBFS().forEach((function(t){E[w]=t,x[t]=w++}));for(var S=1;S<w;++S){var R=E[S],A=this.molecule.sgroups.get(R);this.write("M STY"),this.writePaddedNumber(1,3),this.writeWhiteSpace(1),this.writePaddedNumber(S,3),this.writeWhiteSpace(1),this.writePadded(A.type,3),this.writeCR(),this.write("M SLB"),this.writePaddedNumber(1,3),this.writeWhiteSpace(1),this.writePaddedNumber(S,3),this.writeWhiteSpace(1),this.writePaddedNumber(S,3),this.writeCR();var O=this.molecule.sGroupForest.parent.get(R);if(O>=0&&(this.write("M SPL"),this.writePaddedNumber(1,3),this.writeWhiteSpace(1),this.writePaddedNumber(S,3),this.writeWhiteSpace(1),this.writePaddedNumber(x[O],3),this.writeCR()),"SRU"===A.type&&A.data.connectivity){var P=" ".concat(S.toString().padStart(3)," ").concat((A.data.connectivity||"").padEnd(3));this.write("M SCN"),this.writePaddedNumber(1,3),this.write(P.toUpperCase()),this.writeCR()}"SRU"===A.type&&(this.write("M SMT "),this.writePaddedNumber(S,3),this.writeWhiteSpace(),this.write(A.data.subscript||"n"),this.writeCR()),this.writeCR(Ge.saveToMolfile[A.type](A,this.molecule,x,this.mapping,this.bondMapping))}var k=[];if(this.molecule.sgroups.forEach((function(t){t.data.expanded&&k.push(t.id+1)})),k.length){var T="M SDS EXP ".concat(k.length," ").concat(k.join(" "));this.writeCR(T)}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 ze(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 He(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ze(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ze(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var Ue=function(){function t(e){(0,r.Z)(this,t),this.options=He(He({},t.DefaultOptions),e)}return(0,i.Z)(t,[{key:"deserialize",value:function(t){var e=new Fe,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 Fe).saveMolecule(t,this.options.ignoreErrors,this.options.noRgroups,this.options.preserveIndigoDesc)}}]),t}();function Ve(t,e,n){this.molecule=t,this.bonds=new wt,this.getNeighbors=e,this.context=n}function We(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function Ye(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 Ye.VertexDesc}),this),this.edges=new Array(this.molecule.bonds.size),this.molecule.bonds.forEach((function(t,e){i.edges[e]=new Ye.EdgeDesc}),this),this.v_seq=[]}function qe(t,e,n){this.molecule=t,this.atoms=new wt,this.getNeighbors=e,this.context=n}function $e(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function Xe(){this.smiles="",this.writtenAtoms=[],this.writtenComponents=0,this.ignoreErrors=!1}function Ke(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 Je(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Ke(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ke(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}(0,a.Z)(Ue,"DefaultOptions",{badHeaderRecover:!1,ignoreErrors:!1,noRgroups:!1,preserveIndigoDesc:!1,reactionRelayout:!1}),Ve.PARITY={NONE:0,CIS:1,TRANS:2},Ve.prototype.each=function(t){this.bonds.forEach(t)},Ve.prototype.getParity=function(t){return this.bonds.get(t).parity},Ve.prototype.getSubstituents=function(t){return this.bonds.get(t).substituents},Ve.prototype.sameside=function(t,e,n,r){var i=D.diff(t,e),a=new D(-i.y,i.x);if(!a.normalize())return 0;var o=D.diff(n,t),s=D.diff(r,e);if(!o.normalize())return 0;if(!s.normalize())return 0;var l=D.dot(o,a),c=D.dot(s,a);return Math.abs(l)<.001||Math.abs(c)<.001?0:l*c>0?1:-1},Ve.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)},Ve.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]&&We(t,0,1),i?t[3]=-1:r?(t[2]=t[3],t[3]=-1):t[2]>t[3]&&We(t,2,3),0))},Ve.prototype.isGeomStereoBond=function(t,e){var n=this.molecule.bonds.get(t);if(n.type!==Y.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),l=this.getNeighbors.call(this.context,n.end);if(s.length<2||s.length>3||l.length<2||l.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!==Y.PATTERN.TYPE.SINGLE)return!1;-1===e[0]?e[0]=o.aid:e[1]=o.aid}for(a=0;a<l.length;a++)if((o=l[a]).bid!==t){if(this.molecule.bonds.get(o.bid).type!==Y.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]))},Ve.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=Ve.PARITY.CIS:-1===a&&(i.parity=Ve.PARITY.TRANS)}}))},Ye.VertexDesc=function(){this.dfs_state=0,this.parent_vertex=0,this.parent_edge=0,this.branches=0},Ye.EdgeDesc=function(){this.opening_cycles=0,this.closing_cycle=0},Ye.SeqElem=function(t,e,n){this.idx=t,this.parent_vertex=e,this.parent_edge=n},Ye.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(),l=this.vertices[s].parent_vertex,c=new Ye.SeqElem(s,l,this.vertices[s].parent_edge);this.v_seq.push(c),this.vertices[s].dfs_state=2;var u=this.atom_data[s];for(t=0;t<u.neighbours.length;t++){var h=u.neighbours[t].aid,d=u.neighbours[t].bid;if(h!==l)if(2===this.vertices[h].dfs_state){for(this.edges[d].closing_cycle=1,e=s;-1!==e&&this.vertices[e].parent_vertex!==h;)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++,c=new Ye.SeqElem(h,s,d),this.v_seq.push(c)}else{if(1===this.vertices[h].dfs_state){if(-1===(e=r.indexOf(h)))throw new Error("internal: removing vertex from stack");r.splice(e,1);var f=this.vertices[h].parent_vertex;f>=0&&this.vertices[f].branches--}this.vertices[s].branches++,this.vertices[h].parent_vertex=s,this.vertices[h].parent_edge=d,this.vertices[h].dfs_state=1,r.push(h)}}}},Ye.prototype.edgeClosingCycle=function(t){return 0!==this.edges[t].closing_cycle},Ye.prototype.numBranches=function(t){return this.vertices[t].branches},Ye.prototype.numOpeningCycles=function(t){return this.edges[t].opening_cycles},Ye.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 F;n.forEach((function(t,a){var o=e.getNeighbors.call(e.context,a);if(2!==o.length)return!1;var s=o[0],l=o[1];if([a,s.aid,l.aid].findIndex((function(t){return["C","Si"].indexOf(n.get(t).label)<0}),e)>=0)return!1;if([s.bid,l.bid].findIndex((function(t){return r.get(t).type!==Y.PATTERN.TYPE.DOUBLE}),e)>=0)return!1;var c=e.getNeighbors.call(e.context,s.aid).filter((function(t){return t.aid!==a})),u=e.getNeighbors.call(e.context,l.aid).filter((function(t){return t.aid!==a}));return!(c.length<1||c.length>2||u.length<1||u.length>2||c.concat(u).findIndex((function(t){return r.get(t.bid).type!==Y.PATTERN.TYPE.SINGLE}),e)>=0||c.concat(u).findIndex((function(t){return r.get(t.bid).stereo===Y.PATTERN.STEREO.EITHER}),e)>=0||(i.add(s.aid).add(l.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===Y.PATTERN.TYPE.SINGLE&&e.begin===n&&(e.stereo===Y.PATTERN.STEREO.UP||e.stereo===Y.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=[],l=0,c=0;o.pyramid[0]=-1,o.pyramid[1]=-1,o.pyramid[2]=-1,o.pyramid[3]=-1;var u=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:D.diff(i.pp,n.pp).yComplement()},i.pureHydrogen()?(u++,s[r].rank=1e4):"H"===i.label&&(s[r].rank=5e3),!s[r].vec.normalize())throw new Error("zero bond length");if(a.type===Y.PATTERN.TYPE.TRIPLE)throw new Error("non-single bonds not allowed near stereocenter");if(a.type===Y.PATTERN.TYPE.AROMATIC)throw new Error("aromatic bonds not allowed near stereocenter");a.type===Y.PATTERN.TYPE.DOUBLE&&c++})),qe.allowed_stereocenters.find((function(t){return t.elem===n.label&&t.charge===n.charge&&t.degree===i&&t.n_double_bonds===c&&(a=t.implicit_degree,!0)})),-1===a)throw new Error("unknown stereocenter configuration: "+n.label+", charge "+n.charge+", "+i+" bonds ("+c+" double)");if(4===i&&u>1)throw new Error(u+" hydrogens near stereocenter");if(3===i&&4===a&&u>0)throw new Error("have hydrogen(s) besides implicit hydrogen near stereocenter");if(4===i){s[0].rank>s[1].rank&&$e(s,0,1),s[1].rank>s[2].rank&&$e(s,1,2),s[2].rank>s[3].rank&&$e(s,2,3),s[1].rank>s[2].rank&&$e(s,1,2),s[0].rank>s[1].rank&&$e(s,0,1),s[1].rank>s[2].rank&&$e(s,1,2);for(var h,d,f=-1,p=-1,m=-1,v=-1,g=0,y=0;y<4;y++){var b=this.getBondStereo(t,s[y].edge_idx);if(b===Y.PATTERN.STEREO.UP||b===Y.PATTERN.STEREO.DOWN){f=y,g=b;break}}if(-1===f)throw new Error("none of 4 bonds going from stereocenter is stereobond");if(-1===p&&((h=qe.xyzzy(s[f].vec,s[(f+1)%4].vec,s[(f+2)%4].vec))+(d=qe.xyzzy(s[f].vec,s[(f+1)%4].vec,s[(f+3)%4].vec))!==3&&h+d!==12||(p=(f+1)%4,m=(f+2)%4,v=(f+3)%4)),-1===p&&((h=qe.xyzzy(s[f].vec,s[(f+2)%4].vec,s[(f+1)%4].vec))+(d=qe.xyzzy(s[f].vec,s[(f+2)%4].vec,s[(f+3)%4].vec))!==3&&h+d!==12||(p=(f+2)%4,m=(f+1)%4,v=(f+3)%4)),-1===p&&((h=qe.xyzzy(s[f].vec,s[(f+3)%4].vec,s[(f+1)%4].vec))+(d=qe.xyzzy(s[f].vec,s[(f+3)%4].vec,s[(f+2)%4].vec))!==3&&h+d!==12||(p=(f+3)%4,m=(f+2)%4,v=(f+1)%4)),-1===p)throw new Error("internal error: can not find opposite bond");if(g===Y.PATTERN.STEREO.UP&&this.getBondStereo(t,s[p].edge_idx)===Y.PATTERN.STEREO.DOWN)throw new Error("stereo types of the opposite bonds mismatch");if(g===Y.PATTERN.STEREO.DOWN&&this.getBondStereo(t,s[p].edge_idx)===Y.PATTERN.STEREO.UP)throw new Error("stereo types of the opposite bonds mismatch");if(g===this.getBondStereo(t,s[m].edge_idx))throw new Error("stereo types of non-opposite bonds match");if(g===this.getBondStereo(t,s[v].edge_idx))throw new Error("stereo types of non-opposite bonds match");l=3===f||3===p?g:g===Y.PATTERN.STEREO.UP?Y.PATTERN.STEREO.DOWN:Y.PATTERN.STEREO.UP;var x=qe.sign(s[0].vec,s[1].vec,s[2].vec);l===Y.PATTERN.STEREO.UP&&x>0||l===Y.PATTERN.STEREO.DOWN&&x<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&&$e(s,0,1),s[1].rank>s[2].rank&&$e(s,1,2),s[0].rank>s[1].rank&&$e(s,0,1);var w=this.getBondStereo(t,s[0].edge_idx),E=this.getBondStereo(t,s[1].edge_idx),S=this.getBondStereo(t,s[2].edge_idx),R=0,A=0;if(R+=w===Y.PATTERN.STEREO.UP?1:0,R+=E===Y.PATTERN.STEREO.UP?1:0,R+=S===Y.PATTERN.STEREO.UP?1:0,A+=w===Y.PATTERN.STEREO.DOWN?1:0,A+=E===Y.PATTERN.STEREO.DOWN?1:0,A+=S===Y.PATTERN.STEREO.DOWN?1:0,4===a){if(3===R)throw new Error("all 3 bonds up near stereoatom");if(3===A)throw new Error("all 3 bonds down near stereoatom");if(0===R&&0===A)throw new Error("no up/down bonds near stereoatom -- indefinite case");if(1===R&&1===A)throw new Error("one bond up, one bond down -- indefinite case");if(g=0,2===R)l=Y.PATTERN.STEREO.DOWN;else if(2===A)l=Y.PATTERN.STEREO.UP;else{for(f=-1,m=-1,v=-1,y=0;y<3;y++){var O=this.getBondStereo(t,s[y].edge_idx);if(O===Y.PATTERN.STEREO.UP||O===Y.PATTERN.STEREO.DOWN){f=y,g=O,m=(y+1)%3,v=(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[v].vec,s[f].vec);if(3===P||4===P)throw new Error("degenerate case for 3 bonds near stereoatom");l=1===P?g:g===Y.PATTERN.STEREO.UP?Y.PATTERN.STEREO.DOWN:Y.PATTERN.STEREO.UP}var k=qe.sign(s[0].vec,s[1].vec,s[2].vec);l===Y.PATTERN.STEREO.UP&&k>0||l===Y.PATTERN.STEREO.DOWN&&k<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 T;if(A>0&&R>0)throw new Error("one bond up, one bond down -- indefinite case");if(0===A&&0===R)throw new Error("no up-down bonds attached to stereocenter");T=R>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)||(T=-T),qe.sign(s[0].vec,s[1].vec,s[2].vec)===T?(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=D.cross(t,e),a=D.dot(t,e),o=D.cross(t,n),s=D.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]&&($e(e,0,1),n=!n),e[1]>e[2]&&($e(e,1,2),n=!n),e[2]>e[3]&&($e(e,2,3),n=!n),e[1]>e[2]&&($e(e,1,2),n=!n),e[0]>e[1]&&($e(e,0,1),n=!n),e[1]>e[2]&&($e(e,1,2),n=!n),n},Xe._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},Xe.prototype.isBondInRing=function(t){return this.inLoop[t]},Xe.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{it.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 Xe._Atom(t.implicitH)}));var o=["B","C","N","O","P","S","Se","As"];t.bonds.forEach((function(e,n){e.type===Y.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 F;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 F(r))}}));var n={};return e.forEach((function(t){n[t]=1})),n}(),this.touchedCistransbonds=0,this.markCisTrans(t);var s=t.getComponents(),l=s.reactants.concat(s.products),c=new Ye(t,this.atoms,l,s.reactants.length);for(c.walk(),this.atoms.forEach((function(t){t.neighbours=[]})),n=0;n<c.v_seq.length;n++){var u=c.v_seq[n],h=u.idx,d=u.parent_edge,f=u.parent_vertex;if(d>=0){var p=this.atoms[h],m=c.numOpeningCycles(d);for(r=0;r<m;r++)this.atoms[f].neighbours.push({aid:-1,bid:-1});if(c.edgeClosingCycle(d)){for(i=0;i<p.neighbours.length;i++)if(-1===p.neighbours[i].aid){p.neighbours[i].aid=f,p.neighbours[i].bid=d;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:d}),p.parent=f;this.atoms[f].neighbours.push({aid:h,bid:d})}}try{var v=new qe(t,(function(t){return this.atoms[t].neighbours}),this);v.buildFromBonds(this.ignoreErrors),v.each((function(t,e){var n=-1;-1===t.pyramid[3]&&(n=3);var o=[],s=0,l=a.atoms[e];if(-1!==l.parent)for(i=0;i<4;i++)if(t.pyramid[i]===l.parent){o[s++]=i;break}for(-1!==n&&(o[s++]=n),r=0;r!==l.neighbours.length;r++)if(l.neighbours[r].aid!==l.parent)for(i=0;i<4;i++)if(l.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 g=[];g.push(0);var y=!0;for(n=0;n<c.v_seq.length;n++){h=(u=c.v_seq[n]).idx,d=u.parent_edge;var b=!0;if((f=u.parent_vertex)>=0){for(c.numBranches(f)>1&&this.atoms[f].branch_cnt>0&&this.atoms[f].paren_written&&(this.smiles+=")"),m=c.numOpeningCycles(d),r=0;r<m;r++){for(i=1;i<g.length&&-1!==g[i];i++);i===g.length?g.push(f):g[i]=f,this.writeCycleNumber(i)}if(f>=0){var x=c.numBranches(f);if(x>1&&this.atoms[f].branch_cnt<x-1&&(c.edgeClosingCycle(d)?this.atoms[f].paren_written=!1:(this.smiles+="(",this.atoms[f].paren_written=!0)),this.atoms[f].branch_cnt++,this.atoms[f].branch_cnt>x)throw new Error("unexpected branch")}var w=t.bonds.get(d),E=0;if(w.type===Y.PATTERN.TYPE.SINGLE&&(E=this.calcBondDirection(t,d,f)),1===E&&h===w.end||2===E&&h===w.begin?this.smiles+="/":2===E&&h===w.end||1===E&&h===w.begin?this.smiles+="\\":w.type===Y.PATTERN.TYPE.ANY?this.smiles+="~":w.type===Y.PATTERN.TYPE.DOUBLE?this.smiles+="=":w.type===Y.PATTERN.TYPE.TRIPLE?this.smiles+="#":w.type===Y.PATTERN.TYPE.SINGLE_OR_AROMATIC?this.smiles+="-,:":w.type===Y.PATTERN.TYPE.DOUBLE_OR_AROMATIC?this.smiles+="=,:":w.type===Y.PATTERN.TYPE.SINGLE_OR_DOUBLE?this.smiles+="-,=":w.type!==Y.PATTERN.TYPE.AROMATIC||this.atoms[w.begin].lowercase&&this.atoms[w.end].lowercase&&this.isBondInRing(d)?w.type===Y.PATTERN.TYPE.SINGLE&&this.atoms[w.begin].aromatic&&this.atoms[w.end].aromatic&&(this.smiles+="-"):this.smiles+=":",c.edgeClosingCycle(d)){for(r=1;r<g.length&&g[r]!==h;r++);if(r===g.length)throw new Error("cycle number not found");this.writeCycleNumber(r),g[r]=-1,b=!1}}else y||(this.smiles+=this.writtenComponents===c.nComponentsInReactants&&0!==c.nReactants?">>":"."),y=!1,this.writtenComponents++;b&&(this.writeAtom(t,h,this.atoms[h].aromatic,this.atoms[h].lowercase,this.atoms[h].chirality),this.writtenAtoms.push(u.idx))}return this.comma=!1,this.writeRadicals(t),this.comma&&(this.smiles+="|"),this.smiles},Xe.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}},Xe.prototype.writeAtom=function(t,e,n,r,i){var a,o=t.atoms.get(e),s=!1,l=-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)&&(l=this.atoms[e].h_count);var c=o.label;if(o.atomList&&!o.atomList.notList?(c=o.atomList.label(),s=!1):o.isPseudo()||o.atomList&&o.atomList.notList?(c="*",s=!1):(i||0!==o.charge||o.isotope>0||l>=0||a>0)&&(s=!0),s&&(-1===l&&(l=this.atoms[e].h_count),this.smiles+="["),o.isotope>0&&(this.smiles+=o.isotope),this.smiles+=r?c.toLowerCase():c,i>0&&(this.smiles+=1===i?"@":"@@",o.implicitH>1))throw new Error(o.implicitH+" implicit H near stereocenter");"H"!==o.label&&(l>1||0===l&&!s?this.smiles+="H"+l:1===l&&(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+="*"},Xe.prototype.markCisTrans=function(t){var e=this;this.cis_trans=new Ve(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,l=!0;if(a.forEach((function(e){e.bid!==r&&t.bonds.get(e.bid).type===Y.PATTERN.TYPE.SINGLE&&(s=!1)})),o.forEach((function(e){e.bid!==r&&t.bonds.get(e.bid).type===Y.PATTERN.TYPE.SINGLE&&(l=!1)})),s||l)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)}))}}))},Xe.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,l=0,c=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?l++:c++),-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?l++:c++),i===Ve.PARITY.CIS?(o+=l,s+=c):(o+=c,s+=l),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===Ve.PARITY.CIS)?1:2,-1!==a[3]&&(this.dbonds[a[3]].saved=t.bonds.get(a[3]).begin===n.end==(i===Ve.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===Ve.PARITY.CIS)?2:1,-1!==a[3]&&(this.dbonds[a[3]].saved=t.bonds.get(a[3]).begin===n.end==(i===Ve.PARITY.CIS)?1:2)),!0)},Xe.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!==Y.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},Xe.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===V.PATTERN.RADICAL.SINGLET?this.smiles+="^3:":i===V.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 Qe=function(){function t(e){(0,r.Z)(this,t),this.options=Je(Je({},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 Xe).saveMolecule(t,this.options.ignoreErrors)}}]),t}();(0,a.Z)(Qe,"DefaultOptions",{ignoreErrors:!1});var tn,en=/^[^]+?\$\$\$\$$/gm;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,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 an(t,e,n,r,i){return function(o,s,l){var c=Object.assign({},o);return c.options=Object.assign(c.options||{},r,s),rn(t,n+e,JSON.stringify(c),function(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}({"Content-Type":"application/json"},i),l)}}(0,i.Z)((function t(){(0,r.Z)(this,t)}),[{key:"deserialize",value:function(t){for(var e,n=[],r=new Ue;null!==(e=en.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)),l=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:l})}}return n}},{key:"serialize",value:function(t){var e=new Ue;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")}),"")}}]),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"}(tn||(tn={}));var on,sn=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 an("POST","indigo/convert",this.apiPath,this.defaultOptions,this.customHeaders)({struct:t,output_format:"chemical/x-inchi"},{})}},{key:"info",value:(e=(0,x.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,rn("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 an("POST","indigo/convert",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"layout",value:function(t,e){return an("POST","indigo/layout",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"clean",value:function(t,e){return an("POST","indigo/clean",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"aromatize",value:function(t,e){return an("POST","indigo/aromatize",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"dearomatize",value:function(t,e){return an("POST","indigo/dearomatize",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"calculateCip",value:function(t,e){return an("POST","indigo/calculate_cip",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"automap",value:function(t,e){return an("POST","indigo/automap",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"check",value:function(t,e){return an("POST","indigo/check",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"calculate",value:function(t,e){return an("POST","indigo/calculate",this.apiPath,this.defaultOptions,this.customHeaders)(t,e)}},{key:"recognize",value:function(t,e){var n=e?"?version=".concat(e):"",r=rn("POST",this.apiPath+"imago/uploads".concat(n),t,{"Content-Type":t.type||"application/octet-stream"}),i=rn.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 an("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}(),ln=function(){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+"/"}return(0,i.Z)(t,[{key:"createStructService",value:function(t){return new sn(this.apiPath,t,this.customHeaders)}}]),t}(),cn=(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||{}})),un={molAuto:new cn("MDL Molfile Auto Format detect",tn.Mol,[".mol"],!0,{"molfile-saving-mode":"auto"}),mol:new cn("MDL Molfile V2000",tn.Mol,[".mol"],!0),molV3000:new cn("MDL Molfile V3000",tn.Mol,[".mol"],!0,{"molfile-saving-mode":"3000"}),rxn:new cn("MDL Rxnfile V2000",tn.Rxn,[".rxn"],!0),rxnV3000:new cn("MDL Rxnfile V3000",tn.Rxn,[".rxn"],!0,{"molfile-saving-mode":"3000"}),smiles:new cn("Daylight SMILES",tn.DaylightSmiles,[".smi",".smiles"]),smilesExt:new cn("Extended SMILES",tn.ExtendedSmiles,[".cxsmi",".cxsmiles"]),smarts:new cn("Daylight SMARTS",tn.DaylightSmarts,[".smarts"]),inChI:new cn("InChI",tn.InChI,[".inchi"]),inChIAuxInfo:new cn("InChI AuxInfo",tn.InChIAuxInfo,[".inchi"]),cml:new cn("CML",tn.CML,[".cml",".mrv"],!0),ket:new cn("Ket Format",tn.KET,[".ket"]),cdxml:new cn("CDXML",tn.CDXML,[".cdxml"],!0),cdx:new cn("Base64 CDX",tn.CDX,[".cdx"],!0),unknown:new cn("Unknown",tn.UNKNOWN,["."],!0)};function hn(t){return un[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"}(on||(on={}));var dn=new WeakMap,fn=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)}var e,n;return(0,i.Z)(t,[{key:"getStructureFromStructAsync",value:(n=(0,x.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,dn).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,x.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,dn).deserialize(e));case 1:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})}]),t}();var pn=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=pn),i.set(n,a),(0,f.Z)(this,pn,e)}var e,n;return(0,i.Z)(t,[{key:"getStructureFromStructAsync",value:(n=(0,x.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,pn).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,x.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,pn).deserialize(e),t.abrupt("return",n);case 2:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})}]),t}();function vn(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 gn(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?vn(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):vn(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function yn(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 bn=new WeakMap,xn=new WeakMap,wn=new WeakMap,En=new WeakMap,Sn=function(){function t(e,n,i,a){(0,r.Z)(this,t),yn(this,bn,{writable:!0,value:void 0}),yn(this,xn,{writable:!0,value:void 0}),yn(this,wn,{writable:!0,value:void 0}),yn(this,En,{writable:!0,value:void 0}),(0,f.Z)(this,bn,e),(0,f.Z)(this,xn,n),(0,f.Z)(this,wn,i),(0,f.Z)(this,En,a)}var e,n;return(0,i.Z)(t,[{key:"getStructureFromStructAsync",value:(n=(0,x.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=hn((0,p.Z)(this,wn)),t.prev=1,r=(0,p.Z)(this,xn).serialize(e),t.next=5,(0,p.Z)(this,bn).convert({struct:r,output_format:n.mime},gn(gn({},(0,p.Z)(this,En)),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,x.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:hn(on.ket).mime},(i=hn((0,p.Z)(this,wn)).supportsCoords)?(n=(0,p.Z)(this,bn).convert,r.struct=e):(n=(0,p.Z)(this,bn).layout,r.struct=e.trim()),t.prev=3,t.next=6,n(r,(0,p.Z)(this,En));case 6:return a=t.sent,o=(0,p.Z)(this,xn).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,wn)?"".concat(hn(on.smilesExt).name," and opening of ").concat(hn(on.smiles).name):hn((0,p.Z)(this,wn)).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 Rn=new WeakMap,An=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=Rn),i.set(n,a),(0,f.Z)(this,Rn,e)}var e,n;return(0,i.Z)(t,[{key:"getStructureFromStructAsync",value:(n=(0,x.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,Rn).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,x.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,Rn).deserialize(e),t.abrupt("return",n);case 2:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})}]),t}(),On=["reactionRelayout","badHeaderRecover"];var Pn,kn,Tn,Bn=new WeakMap,Zn=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)}return(0,i.Z)(t,[{key:"separateOptions",value:function(t){if(!t)return[{},{}];var e=t.reactionRelayout,n=t.badHeaderRecover,r=(0,A.Z)(t,On),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 on.ket:n=new fn(new Vt);break;case on.rxn:n=new mn(new Ue(a));break;case on.mol:n=new An(new Ue(a));break;case on.cml:case on.inChIAuxInfo:case on.inChI:case on.molV3000:case on.smiles:case on.rxnV3000:case on.smilesExt:case on.smarts:case on.cdxml:case on.cdx:case on.unknown:default:n=new Sn((0,p.Z)(this,Bn),new Vt,t,o)}return n}}]),t}();P().el.translateAbs=function(t,e){this.delta=this.delta||new D,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"}(Pn||(Pn={})),function(t){t.LabelsOnly="LabelsOnly",t.BondsOnly="BondsOnly",t.LabelsAndBonds="LabelsAndBonds",t.Off="Off"}(kn||(kn={})),function(t){t.IUPAC="Iupac",t.Classic="Classic",t.On="On",t.Off="Off"}(Tn||(Tn={}));var Cn=function(){function t(e){(0,r.Z)(this,t),this.type=e,this.paths=[],this.boxes=[],this.boundingBox=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:nt.union(this.boundingBox,e)),n&&this.exts.push(n)}},{key:"clear",value:function(){this.paths=[],this.boxes=[],this.exts=[],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 D(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}(),Mn=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 Cn(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(Q.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}(),Ln={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 D(n.p1.x,n.p0.y),n.p1,new D(n.p0.x,n.p1.y)].map((function(e){return e.sub(t)}));e=e.normalized();for(var i=r.map((function(t){return D.cross(t,e)})),a=r.map((function(t){return D.dot(t,e)})),o=-1,l=-1,c=0;c<4;++c)i[c]>0?(o<0||a[o]<a[c])&&(o=c):(l<0||a[l]<a[c])&&(l=c);if(l<0||o<0)return 0;var u=a[o]>a[l]?l:o,h=a[o]>a[l]?o:l;return a[u]+Math.abs(i[u])*(a[h]-a[u])/(Math.abs(i[u])+Math.abs(i[h]))},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,l=s*s-4*o*(a*a-n*n*i.x*i.x);l>0&&(r.pos1={x:0,y:0},r.pos2={x:0,y:0},r.pos1.y=(-s+Math.sqrt(l))/(2*o),r.pos2.y=(-s-Math.sqrt(l))/(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 In(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 Nn(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?In(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):In(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var Dn=Ln.tfx;function _n(t,e){return"M"+Dn(t.x)+","+Dn(t.y)+"L"+Dn(e.x)+","+Dn(e.y)+"\t"}function jn(t,e,n){for(var r=0,i=D.dist(t,e),a=D.diff(e,t).normalized(),o=!0,s="",l=0;r<i;){var c=n[l%n.length],u=r+Math.min(c,i-r);o&&(s+="M "+t.addScaled(a,r).coordStr()+" L "+t.addScaled(a,u).coordStr()),r+=c,o=!o,l++}return s}function Gn(t,e){if(P().vml){var n=.16*e.height;t.translateAbs(0,n),e.y+=n}}var Fn,zn={recenterText:Gn,arrow:function(t,e,n,r,i){switch(e.mode){case lt.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,l="M".concat(Dn(o.x),",").concat(Dn(o.y))+"L".concat(Dn(s),",").concat(Dn(o.y))+"L".concat(Dn(s-7),",").concat(Dn(o.y-5))+"M".concat(Dn(s),",").concat(Dn(o.y))+"L".concat(Dn(s-7),", ").concat(Dn(o.y+5)),c=T()(l).rotate(r,o.x,o.y).toString();return t.path(c).attr(i.lineattr)}(t,e,n,r,i);case lt.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,l="M".concat(Dn(o.x),",").concat(Dn(o.y))+"L".concat(Dn(s),",").concat(Dn(o.y))+"L".concat(Dn(s-10),",").concat(Dn(o.y+5))+"L".concat(Dn(s-10),",").concat(Dn(o.y-5))+"L".concat(Dn(s),",").concat(Dn(o.y),"Z"),c=T()(l).rotate(r,o.x,o.y).toString();return t.path(c).attr(Nn(Nn({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case lt.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,l="M".concat(Dn(o.x),",").concat(Dn(o.y))+"L".concat(Dn(s),",").concat(Dn(o.y))+"L".concat(Dn(s-10),",").concat(Dn(o.y+5))+"L".concat(Dn(s-10+4),",").concat(Dn(o.y))+"L".concat(Dn(s-10),",").concat(Dn(o.y-5))+"L".concat(Dn(s),",").concat(Dn(o.y),"Z"),c=T()(l).rotate(r,o.x,o.y).toString();return t.path(c).attr(Nn(Nn({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case lt.DashedOpenAngle:return function(t,e,n,r,i){var a=(0,m.Z)(e.pos,2),o=a[0];a[1];for(var s=[],l=o.x+n,c=0;c<n/3.5;c++)c%2?s.push("L".concat(Dn(o.x+3.5*c),",").concat(Dn(o.y))):s.push("M".concat(Dn(o.x+3.5*c),",").concat(Dn(o.y)));s.push("M".concat(Dn(l),",").concat(Dn(o.y))+"L".concat(Dn(l-10),",").concat(Dn(o.y+5))+"M".concat(Dn(l),",").concat(Dn(o.y))+"L".concat(Dn(l-10),",").concat(Dn(o.y-5)));var u=T()(s.join("")).rotate(r,o.x,o.y).toString();return t.path(u).attr(Nn(Nn({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case lt.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,l=s-(s-o.x)/2,c=[];c.push("M".concat(Dn(o.x),",").concat(Dn(o.y))+"L".concat(Dn(s),",").concat(Dn(o.y))+"L".concat(Dn(s-10),",").concat(Dn(o.y+5))+"L".concat(Dn(s-10+4),",").concat(Dn(o.y))+"L".concat(Dn(s-10),",").concat(Dn(o.y-5))+"L".concat(Dn(s),",").concat(Dn(o.y),"Z")),c.push("M".concat(Dn(l+8),",").concat(Dn(o.y+8))+"L".concat(Dn(l-8),",").concat(Dn(o.y-8))),c.push("M".concat(Dn(l+8),",").concat(Dn(o.y-8))+"L".concat(Dn(l-8),",").concat(Dn(o.y+8)));var u=T()(c.join("")).rotate(r,o.x,o.y).toString();return t.path(u).attr(Nn(Nn({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case lt.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,l="M".concat(Dn(o.x),",").concat(Dn(o.y))+"L".concat(Dn(s),",").concat(Dn(o.y))+"L".concat(Dn(s-10),",").concat(Dn(o.y+5))+"L".concat(Dn(s-10),",").concat(Dn(o.y-5))+"L".concat(Dn(s),",").concat(Dn(o.y))+"M".concat(Dn(o.x),",").concat(Dn(o.y))+"L".concat(Dn(o.x+10),",").concat(Dn(o.y-5))+"L".concat(Dn(o.x+10),",").concat(Dn(o.y+5))+"L".concat(Dn(o.x),",").concat(Dn(o.y)),c=T()(l).rotate(r,o.x,o.y).toString();return t.path(c).attr(Nn(Nn({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case lt.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,l=o.x+n,c=[];c.push("M".concat(Dn(o.x),",").concat(Dn(o.y-s))+"L".concat(Dn(l),",").concat(Dn(o.y-s))+"L".concat(Dn(l-9),",").concat(Dn(o.y-7))+"L".concat(Dn(l-9+2),",").concat(Dn(o.y-s),"Z")),c.push("M".concat(Dn(l),",").concat(Dn(o.y+s))+"L".concat(Dn(o.x),",").concat(Dn(o.y+s))+"L".concat(Dn(o.x+9),",").concat(Dn(o.y+7))+"L".concat(Dn(o.x+9-2),",").concat(o.y+s,"Z"));var u=T()(c.join("")).rotate(r,o.x,o.y).toString();return t.path(u).attr(Nn(Nn({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case lt.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,l=o.x+n,c=[];c.push("M".concat(Dn(o.x),",").concat(Dn(o.y-s))+"L".concat(Dn(l),",").concat(Dn(o.y-s))+"L".concat(Dn(l-9),",").concat(Dn(o.y-7))+"L".concat(Dn(l-9),",").concat(Dn(o.y-s))+"L".concat(Dn(l-9),",").concat(Dn(o.y))+"L".concat(Dn(l),",").concat(Dn(o.y-s),"Z")),c.push("M".concat(Dn(o.x),",").concat(Dn(o.y+s))+"L".concat(Dn(l),",").concat(Dn(o.y+s))+"M".concat(Dn(o.x),",").concat(Dn(o.y+s))+"L".concat(Dn(o.x+9),",").concat(Dn(o.y+7))+"L".concat(Dn(o.x+9),",").concat(o.y+s,"Z")+"L".concat(Dn(o.x+9),",").concat(Dn(o.y))+"L".concat(Dn(o.x+9),",").concat(o.y+s,"Z"));var u=T()(c.join("")).rotate(r,o.x,o.y).toString();return t.path(u).attr(Nn(Nn({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case lt.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,l=o.x+n,c=[];c.push("M".concat(Dn(o.x),",").concat(Dn(o.y-s))+"L".concat(Dn(l),",").concat(Dn(o.y-s))+"L".concat(Dn(l-7),",").concat(Dn(o.y-5-s))),c.push("M".concat(Dn(o.x),",").concat(Dn(o.y+s))+"L".concat(Dn(l),",").concat(Dn(o.y+s))+"M".concat(Dn(o.x),",").concat(Dn(o.y+s))+"L".concat(Dn(o.x+9),",").concat(Dn(o.y+s+5)));var u=T()(c.join("")).rotate(r,o.x,o.y).toString();return t.path(u).attr(i.lineattr)}(t,e,n,r,i);case lt.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,l=o.x+n,c=[];c.push("M".concat(Dn(o.x),",").concat(Dn(o.y-s))+"L".concat(Dn(l),",").concat(Dn(o.y-s))+"L".concat(Dn(l-9),",").concat(Dn(o.y-7))+"L".concat(Dn(l-9+2),",").concat(Dn(o.y-s),"Z")),c.push("M".concat(Dn(o.x+15),",").concat(Dn(o.y+s))+"L".concat(Dn(l-15),",").concat(Dn(o.y+s))+"M".concat(Dn(o.x+15),",").concat(Dn(o.y+s))+"L".concat(Dn(o.x+9+15),",").concat(Dn(o.y+7))+"L".concat(Dn(o.x+9-2+15),",").concat(o.y+s,"Z"));var u=T()(c.join("")).rotate(r,o.x,o.y).toString();return t.path(u).attr(Nn(Nn({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case lt.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,l=o.x+n,c=[];c.push("M".concat(Dn(o.x),",").concat(Dn(o.y-s))+"L".concat(Dn(l),",").concat(Dn(o.y-s))+"L".concat(Dn(l-7),",").concat(Dn(o.y-5-s))),c.push("M".concat(Dn(o.x+15),",").concat(Dn(o.y+s))+"L".concat(Dn(l-15),",").concat(Dn(o.y+s))+"M".concat(Dn(o.x+15),",").concat(Dn(o.y+s))+"L".concat(Dn(o.x+9+15),",").concat(Dn(o.y+s+5)));var u=T()(c.join("")).rotate(r,o.x,o.y).toString();return t.path(u).attr(i.lineattr)}(t,e,n,r,i);case lt.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,l=o.x+n,c=[];c.push("M".concat(Dn(o.x),",").concat(Dn(o.y-s))+"L".concat(Dn(l),",").concat(Dn(o.y-s))+"L".concat(Dn(l-9),",").concat(Dn(o.y-10))+"L".concat(Dn(l-9+2),",").concat(Dn(o.y-s),"Z")),c.push("M".concat(Dn(o.x+15),",").concat(Dn(o.y+s))+"L".concat(Dn(l-15),",").concat(Dn(o.y+s))+"M".concat(Dn(o.x+15),",").concat(Dn(o.y+s))+"L".concat(Dn(o.x+9+15),",").concat(Dn(o.y+10))+"L".concat(Dn(o.x+9-2+15),",").concat(o.y+s,"Z"));var u=T()(c.join("")).rotate(r,o.x,o.y).toString();return t.path(u).attr(Nn(Nn({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case lt.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,l=o.x+n,c=[];c.push("M".concat(Dn(o.x),",").concat(Dn(o.y-s))+"L".concat(Dn(l),",").concat(Dn(o.y-s))+"L".concat(Dn(l-9),",").concat(Dn(o.y-7))+"L".concat(Dn(l-9),",").concat(Dn(o.y-s),"Z")),c.push("M".concat(Dn(o.x+15),",").concat(Dn(o.y+s))+"L".concat(Dn(l-15),",").concat(Dn(o.y+s))+"M".concat(Dn(o.x+15),",").concat(Dn(o.y+s))+"L".concat(Dn(o.x+9+15),",").concat(Dn(o.y+7))+"L".concat(Dn(o.x+9+15),",").concat(o.y+s,"Z"));var u=T()(c.join("")).rotate(r,o.x,o.y).toString();return t.path(u).attr(Nn(Nn({},i.lineattr),{},{fill:"#000"}))}(t,e,n,r,i);case lt.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,l=s>=0?1:-1,c=10*l,u=5*l,h=4*l,d=o.x+n,f="M".concat(Dn(o.x),",").concat(Dn(o.y))+"A".concat(n/2,",").concat(s,",",0,",",0,",").concat(l>0?1:0,",").concat(Dn(d),",").concat(Dn(o.y))+"L".concat(Dn(d-u),",").concat(Dn(o.y-c))+"l".concat(Dn(u),",").concat(Dn(h))+"l".concat(Dn(u),",").concat(Dn(-h))+"l".concat(Dn(-u),",").concat(c),p=T()(f).rotate(r,o.x,o.y).toString();return t.path(p).attr(Nn({},i.lineattr))}(t,e,n,r,i);case lt.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,l=s>=0?1:-1,c=10*l,u=5*l,h=o.x+n,d="M".concat(Dn(o.x),",").concat(Dn(o.y))+"A".concat(n/2,",").concat(s,",",0,",",0,",").concat(l>0?1:0,",").concat(Dn(h),",").concat(Dn(o.y))+"L".concat(Dn(h-u),",").concat(Dn(o.y-c))+"l".concat(Dn(c),",").concat(Dn(0))+"l".concat(Dn(-u),",").concat(Dn(c)),f=T()(d).rotate(r,o.x,o.y).toString();return t.path(f).attr(Nn({},i.lineattr))}(t,e,n,r,i);case lt.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,l=s>=0?1:-1,c=5*l,u=7*l,h=o.x+n,d="M".concat(Dn(o.x),",").concat(Dn(o.y))+"A".concat(n/2,",").concat(s,",",0,",",0,",").concat(l>0?1:0,",").concat(Dn(h),",").concat(Dn(o.y))+"L".concat(Dn(h-c),",").concat(Dn(o.y-u))+"M".concat(Dn(h),",").concat(Dn(o.y))+"L".concat(Dn(h+c),", ").concat(Dn(o.y-u)),f=T()(d).rotate(r,o.x,o.y).toString();return t.path(f).attr(i.lineattr)}(t,e,n,r,i);case lt.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,l=s>=0?1:-1,c=5*l,u=7*l,h=o.x+n,d="M".concat(Dn(o.x),",").concat(Dn(o.y))+"A".concat(n/2,",").concat(s,",",0,",",0,",").concat(l>0?1:0,", ").concat(Dn(h),",").concat(Dn(o.y))+"L".concat(Dn(h+c),", ").concat(Dn(o.y-u)),f=T()(d).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}",Dn(e.x),Dn(e.y),Dn(e.x-r),Dn(e.x+r),Dn(e.y-r),Dn(e.y+r)).attr(n.lineattr)},aromaticBondPaths:function(t,e,n,r,i,a){return[a&&1&i?jn(t,n,a):_n(t,n),a&&2&i?jn(e,r,a):_n(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(_n(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",Dn(e.x),Dn(e.y),Dn(n.x),Dn(n.y),Dn(r.x),Dn(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",Dn(e.x),Dn(e.y),Dn(n.x),Dn(n.y),Dn(r.x),Dn(r.y),Dn(i.x),Dn(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}",Dn(n.x),Dn(n.y),Dn(r.x),Dn(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",l=e.p,c=e.norm,u=.7*a.stereoBond,h="",d=0;d<r;++d)h+=_n((o=l.addScaled(n,i*d)).addScaled(c,u*(d+.5)/(r-.5)),o.addScaled(c,-u*(d+.5)/(r-.5)));return t.path(h).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,l=e.norm,c=.7*a.stereoBond,u="M"+Dn(s.x)+","+Dn(s.y),h=s,d=0;d<r;++d)h=s.addScaled(n,i*(d+.5)).addScaled(l,(1&d?-1:1)*c*(d+.5)/(r-.5)),u+="L"+Dn(h.x)+","+Dn(h.y);return t.path(u).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}",Dn(e.x),Dn(e.y),Dn(r.x),Dn(r.y),Dn(n.x),Dn(n.y),Dn(i.x),Dn(i.y)).attr(o.lineattr)},bondSingleOrDouble:function(t,e,n,r,i){for(var a,o=e.p,s=n.p,l=e.norm,c=i.bondSpace/2,u="",h=o,d=1;d<=r;++d)a=D.lc2(o,(r-d)/r,s,d/r),1&d?u+=_n(h,a):(u+=_n(h.addScaled(l,c),a.addScaled(l,c)),u+=_n(h.addScaled(l,-c),a.addScaled(l,-c))),h=a;return t.path(u).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,l=a.addScaled(s,r.bondSpace),c=o.addScaled(s,r.bondSpace),u=a.addScaled(s,-r.bondSpace),h=o.addScaled(s,-r.bondSpace);return t.path(_n(a,o)+_n(l,c)+_n(u,h)).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(_n(i,a)).attr(r.lineattr).attr({"stroke-dasharray":"- "})},bondHydrogen:function(t,e,n,r){var i=e.p,a=n.p;return t.path(_n(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(_n(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+=_n(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=Ln.relBox(i.getBBox());return Gn(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}",Dn(e.x-i),Dn(e.y+a),Dn(e.x),Dn(e.y),Dn(e.x+i),Dn(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(Dn(e.x),Dn(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),l=r.addScaled(n,.5*a),c=s.addScaled(e,-i),u=l.addScaled(e,-i);return t.path("M{0},{1}L{2},{3}L{4},{5}L{6},{7}",Dn(c.x),Dn(c.y),Dn(s.x),Dn(s.y),Dn(l.x),Dn(l.y),Dn(u.x),Dn(u.y)).attr(o.sgroupBracketStyle)},selectionRectangle:function(t,e,n,r){return t.rect(Dn(Math.min(e.x,n.x)),Dn(Math.min(e.y,n.y)),Dn(Math.abs(n.x-e.x)),Dn(Math.abs(n.y-e.y))).attr(r.lassoStyle)},selectionPolygon:function(t,e,n){for(var r=e[e.length-1],i="M"+Dn(r.x)+","+Dn(r.y),a=0;a<e.length;++a)i+="L"+Dn(e[a].x)+","+Dn(e[a].y);return t.path(i).attr(n.lassoStyle)},selectionLine:function(t,e,n,r){return t.path(_n(e,n)).attr(r.lassoStyle)},ellipse:function(t,e,n){var r=D.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(Dn(Math.min(e[0].x,e[1].x)),Dn(Math.min(e[0].y,e[1].y)),Dn(Math.abs(e[1].x-e[0].x)),Dn(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),l=s[0];s[1];var c=l.x+n,u=o||8,h="M".concat(Dn(l.x-5),",").concat(Dn(l.y))+"L".concat(Dn(l.x-5),",").concat(Dn(l.y-u))+"L".concat(Dn(c+5),",").concat(Dn(l.y-u))+"L".concat(Dn(c+5),",").concat(Dn(l.y+(!o&&u)))+"L".concat(Dn(l.x-5),",").concat(Dn(l.y+(!o&&u)),"Z");return T()(h).rotate(r,l.x,l.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 Hn(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"}(Fn||(Fn={}));var Un=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,u.Z)(e);if(n){var i=(0,u.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?Mn.prototype.getVBoxObj.call(this,t):new nt(this.a.pp,this.a.pp)}},{key:"drawHover",value:function(t){var e=this.makeHoverPlate(t);return t.ctab.addReObjectPath(Pn.hovering,this.visel,e),e}},{key:"makeHoverPlate",value:function(t){var e=t.paper,n=t.options,r=Q.obj2scaled(this.a.pp,n),i=this.a,a=t.ctab.sgroups,o=t.ctab.molecule.functionalGroups;return ut.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(ut.isAtomInContractedFunctionalGroup(r,i,a,!0))return null;var o=Q.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,l=Q.obj2scaled(this.a.pp,s.options);if(ut.isAtomInContractedFunctionalGroup(i,a,o,!1)){if(ut.isAttachmentPointAtom(e,t.molecule)){var c,u,h=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 Hn(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)?Hn(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(h.s();!(u=h.n()).done;){var d=u.value;d.atoms.includes(e)&&(c=d.data.name)}}catch(t){h.e(t)}finally{h.f()}var f=s.paper.text(l.x,l.y,c).attr({"font-weight":700,"font-size":14});t.addReObjectPath(Pn.data,this.visel,f,l,!0)}}else{var p,m,v,g,y,b;this.hydrogenOnTheLeft=function(t,e){if(0===e.a.neighbors.length){var n=L.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!==Fn.Off&&e.showHydrogenLabels!==Fn.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),l=t.bonds.get(o.bid),c=t.bonds.get(s.bid);if(l.b.type===c.b.type&&l.b.stereo===Y.PATTERN.STEREO.NONE&&c.b.stereo===Y.PATTERN.STEREO.NONE&&Math.abs(D.cross(o.dir,s.dir))<.2)return!0}return!1}(t,s.options,this),this.color="black";var x=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=L.get(i.text);r.atomColoring&&a&&(t.color=Z[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=Ln.relBox(i.path.getBBox()),zn.recenterText(i.path,i.rbb),null!==t.a.atomList&&Wn(i.path,i.rbb,(t.hydrogenOnTheLeft?-1:1)*(i.rbb.width-i.rbb.height)/2,0),t.label=i,i}(this,s.paper,l,n),p=.5*n.lineWidth,m=b.rbb.width/2*(n.zoom>1?1:n.zoom),v=-b.rbb.width/2*(n.zoom>1?1:n.zoom),g=Math.floor(this.a.implicitH),y="H"===b.text,t.addReObjectPath(Pn.data,this.visel,b.path,l,!0)),n.showAtomIds){(x={}).text=e.toString();var w=this.hydrogenOnTheLeft?D.lc(l,1,new D({x:-2,y:0,z:0}),6):D.lc(l,1,new D({x:2,y:0,z:0}),6);this.showLabel&&(w=D.lc(w,1,new D({x:1,y:-3,z:0}),6)),x.path=s.paper.text(w.x,w.y,x.text).attr({font:n.font,"font-size":n.fontszsub,fill:"#070"}),x.rbb=Ln.relBox(x.path.getBBox()),zn.recenterText(x.path,x.rbb),t.addReObjectPath(Pn.indices,this.visel,x.path,l)}if(this.setHover(this.hover,s),this.showLabel&&!this.a.pseudo){var E=null;if(y&&g>0&&(E=function(t,e,n,r){var i=Q.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=Ln.relBox(s.path.getBBox()),zn.recenterText(s.path,s.rbb),Wn(s.path,s.rbb,r+.5*s.rbb.width+o,.2*t.label.rbb.height),s}(this,s,g,m),m+=E.rbb.width+p,t.addReObjectPath(Pn.data,this.visel,E.path,l,!0)),0!==this.a.radical){var S=function(t,e){var n,r=Q.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(zn.radicalBullet(a,r.add(new D(-n,0)),i),zn.radicalBullet(a,r.add(new D(n,0)),i)),o.path.attr("fill",t.color);break;case 2:o.path=a.set(),o.path.push(zn.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(zn.radicalCap(a,r.add(new D(-n,0)),i),zn.radicalCap(a,r.add(new D(n,0)),i)),o.path.attr("stroke",t.color)}o.rbb=Ln.relBox(o.path.getBBox());var s=-.5*(t.label.rbb.height+o.rbb.height);return 3===t.a.radical&&(s-=i.lineWidth/2),Wn(o.path,o.rbb,0,s),o}(this,s);t.addReObjectPath(Pn.data,this.visel,S.path,l,!0)}if(0!==this.a.isotope){var R=function(t,e,n){var r=Q.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=Ln.relBox(o.path.getBBox()),zn.recenterText(o.path,o.rbb),Wn(o.path,o.rbb,n-.5*o.rbb.width-a,-.3*t.label.rbb.height),o}(this,s,v);v-=R.rbb.width+p,t.addReObjectPath(Pn.data,this.visel,R.path,l,!0)}if(!y&&!this.a.alias&&g>0&&function(t,e){return t===Fn.On||t===Fn.Terminal&&e.a.neighbors.length<2||t===Fn.Hetero&&"c"!==e.label.text.toLowerCase()||t===Fn.TerminalAndHetero&&(e.a.neighbors.length<2||"c"!==e.label.text.toLowerCase())}(n.showHydrogenLabels,this)){var A=function(t,e,n,r){var i=r.hydroIndex,a=t.hydrogenOnTheLeft,o=Q.obj2scaled(t.a.pp,e.options),s=e.options,l=.5*s.lineWidth,c=r.hydrogen;return c.text="H",c.path=e.paper.text(o.x,o.y,c.text).attr({font:s.font,"font-size":s.fontsz,fill:t.color}),c.rbb=Ln.relBox(c.path.getBBox()),zn.recenterText(c.path,c.rbb),a||(Wn(c.path,c.rbb,r.rightMargin+.5*c.rbb.width+l,0),r.rightMargin+=c.rbb.width+l),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=Ln.relBox(i.path.getBBox()),zn.recenterText(i.path,i.rbb),a||(Wn(i.path,i.rbb,r.rightMargin+.5*i.rbb.width*(s.zoom>1?1:s.zoom)+l,.2*t.label.rbb.height),r.rightMargin+=i.rbb.width+l)),a&&(null!=i&&(Wn(i.path,i.rbb,r.leftMargin-.5*i.rbb.width-l,.2*t.label.rbb.height),r.leftMargin-=i.rbb.width+l),Wn(c.path,c.rbb,r.leftMargin-.5*c.rbb.width*(n>1&&s.zoom<1?s.zoom:1)-l,0),r.leftMargin-=c.rbb.width+l),Object.assign(r,{hydrogen:c,hydroIndex:i})}(this,s,g,{hydrogen:{},hydroIndex:E,rightMargin:m,leftMargin:v}),O=A.hydrogen;E=A.hydroIndex,m=A.rightMargin,v=A.leftMargin,t.addReObjectPath(Pn.data,this.visel,O.path,l,!0),null!=E&&t.addReObjectPath(Pn.data,this.visel,E.path,l,!0)}if(0!==this.a.charge&&n.showCharge){var P=function(t,e,n){var r=Q.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=Ln.relBox(o.path.getBBox()),zn.recenterText(o.path,o.rbb),Wn(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(Pn.data,this.visel,P.path,l,!0)}if(this.a.explicitValence>=0&&n.showValence){var k=function(t,e,n){var r=Q.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=Ln.relBox(o.path.getBBox()),zn.recenterText(o.path,o.rbb),Wn(o.path,o.rbb,n+.5*o.rbb.width+a,-.3*t.label.rbb.height),o}(this,s,m);m+=k.rbb.width+p,t.addReObjectPath(Pn.data,this.visel,k.path,l,!0)}if(this.a.badConn&&n.showValenceWarnings){var T=function(t,e,n,r){var i=Q.obj2scaled(t.a.pp,e.options),a=.5*e.options.lineWidth,o=Ln.tfx,s={},l=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(l),o(i.x+r),o(l)).attr(e.options.lineattr).attr({stroke:"#F00"}),s.rbb=Ln.relBox(s.path.getBBox()),s}(this,s,v,m);t.addReObjectPath(Pn.warnings,this.visel,T.path,l,!0)}x&&Wn(x.path,x.rbb,-.5*b.rbb.width-.5*x.rbb.width-p,.3*b.rbb.height)}this.a.attpnt&&function(t,e,n,r){var i,a,o=Q.obj2scaled(t.a.pp,e.options),s=e.options,l=Ln.tfx;for(i=0;i<4;++i){var c="";if(t.a.attpnt&1<<i){for(c.length>0&&(c+=" "),c+="∗",a=0;a<(0===i?0:i+1);++a)c+="'";var u=new D(o),h=o.addScaled(n,.7*s.scale),d=e.paper.text(h.x,h.y,c).attr({font:s.font,"font-size":s.fontsz,fill:t.color}),f=Ln.relBox(d.getBBox());zn.recenterText(d,f);var p=n.negated();h=h.addScaled(p,Ln.shiftRayBox(h,p,nt.fromRelBox(f))+s.lineWidth/2),u=qn(t,u,n,s.lineWidth);var m=n.rotateSC(1,0),v=h.addScaled(m,.05*s.scale).addScaled(p,.09*s.scale),g=h.addScaled(m,-.05*s.scale).addScaled(p,.09*s.scale),y=e.paper.set();y.push(d,e.paper.path("M{0},{1}L{2},{3}M{4},{5}L{2},{3}L{6},{7}",l(u.x),l(u.y),l(h.x),l(h.y),l(v.x),l(v.y),l(g.x),l(g.y)).attr(e.options.lineattr).attr({"stroke-width":s.lineWidth/2})),r(Pn.indices,t.visel,y,o),n=n.rotate(Math.PI/6)}}}(this,s,Yn(this,t.molecule),t.addReObjectPath.bind(t));var B=this.a.stereoLabel,C=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),M=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),N=t.molecule.frags.get(I),_=(function(t,e,n){if(!t)return!1;var r=t.match(/\D+/g)[0];switch(e){case Tn.Off:return!1;case Tn.On:return!0;case Tn.Classic:return!(n!==W.Mixed&&r!==G.Or);case Tn.IUPAC:return!(n!==W.Mixed||r===G.Abs);default:return!0}}(B,n.stereoLabelStyle,null==N?void 0:N.enhancedStereoFlag)?"".concat(B,"\n"):"")+(M.length>0?"".concat(M,"\n"):"")+(C.length>0?".".concat(C,"."):"");if(_.length>0){var j=L.get(this.a.label),F=s.paper.text(l.x,l.y,_).attr({font:n.font,"font-size":n.fontszsub,fill:n.atomColoring&&j?Z[this.a.label]:"#000"});if(B){var z=function(t,e){return e&&t.colorStereogenicCenters!==kn.Off&&t.colorStereogenicCenters!==kn.BondsOnly?Vn(t,e):"#000"}(s.options,B);F.node.childNodes[0].setAttribute("fill",z);var H=function(t,e){var n=e.match(/\D+/g)[0],r=+e.replace(n,"");return t.autoFadeOfStereoLabels&&n!==G.Abs&&t.colorStereogenicCenters!==kn.Off&&t.colorStereogenicCenters!==kn.BondsOnly?Math.max(1-(r-1)/10,.3):1}(s.options,B);F.node.childNodes[0].setAttribute("fill-opacity",H)}var U=Ln.relBox(F.getBBox());zn.recenterText(F,U);for(var V=this.visel,q=3,$=Yn(this,t.molecule),X=0;X<V.exts.length;++X)q=Math.max(q,Ln.shiftRayBox(l,$,V.exts[X].translate(l)));q+=Ln.shiftRayBox(l,$.negated(),nt.fromRelBox(U)),Wn(F,U,($=$.scaled(8+q)).x,$.y),t.addReObjectPath(Pn.data,this.visel,F,l,!0)}var K=t.molecule.highlights,J=!1,tt="";if(K.forEach((function(t){var n,r=null===(n=t.atoms)||void 0===n?void 0:n.includes(e);J=J||r,r&&(tt=t.color)})),J){var et={fill:tt,stroke:"none"},rt=Q.obj2scaled(this.a.pp,t.render.options),it=s.paper.circle(rt.x,rt.y,.8*n.atomSelectionPlateRadius).attr(et);t.addReObjectPath(Pn.hovering,this.visel,it)}}}}],[{key:"isSelectable",value:function(){return!0}}]),o}(Mn);function Vn(t,e){switch(e.match(/\D+/g)[0]){case G.And:return t.colorOfAndCenters;case G.Or:return t.colorOfOrCenters;case G.Abs:return t.colorOfAbsoluteCenters;default:return"#000"}}function Wn(t,e,n,r){t.translateAbs(n,r),e.x+=n,e.y+=r}function Yn(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 D(Math.cos(o),Math.sin(o))}function qn(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,Ln.shiftRayBox(e,n,s))}return i>0&&(e=e.addScaled(n,i+r)),e}var $n=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,u.Z)(e);if(n){var i=(0,u.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,v.Z)(e),"neihbid1",-1),(0,a.Z)((0,v.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(Pn.hovering,this.visel,e),e}},{key:"makeHoverPlate",value:function(t){var e=t.options;ir(this,t.ctab,e);var n=this.b,r=t.ctab.sgroups,i=t.ctab.molecule.functionalGroups;if(ut.isBondInContractedFunctionalGroup(n,r,i,!0))return null;var a=Q.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){ir(this,t,n);var r=this.b,i=t.render.ctab.sgroups,a=t.render.ctab.molecule.functionalGroups;if(ut.isBondInContractedFunctionalGroup(r,i,a,!0))return null;var o=Q.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(!ut.isBondInContractedFunctionalGroup(a,o,s,!1)){var l=r.paper,c=void 0!==this.b.hb1?i.halfBonds.get(this.b.hb1):null,u=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=Xn(r,t,!1,n);return i<0?-1:r.neighbors[i]}));e.boldStereo=r[0]>=0&&r[1]>=0}(e,this,t),ir(this,t,n),function(t,e){var n=t.b.hb1,r=t.b.hb2;if(!n&&0!==n||!r&&0!==r)t.doubleBondShift=or(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,l=e.loops.get(i).hbs.length,c=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}(l,c,o,s)}else t.doubleBondShift=i>=0?-1:a>=0?1:or(e,t)}}(this,i),c&&u){this.path=function(t,e,n,r){var i,a,o=null,s=t.render,l=t.molecule,c=!(null!==(i=t.atoms.get(n.begin))&&void 0!==i&&i.showLabel),u=!(null!==(a=t.atoms.get(r.begin))&&void 0!==a&&a.showLabel);switch(e.b.type){case Y.PATTERN.TYPE.SINGLE:switch(e.b.stereo){case Y.PATTERN.STEREO.UP:Kn(n.bid,e,t),o=e.boldStereo&&e.neihbid1>=0&&e.neihbid2>=0?Qn(s,n,r,e,l):function(t,e,n,r,i){var a=e.p,o=n.p,s=e.norm,l=t.options,c=.7*l.stereoBond,u=o.addScaled(s,c),h=o.addScaled(s,-c);if(r.neihbid2>=0){var d=er(n,r.neihbid2,l.stereoBond,i);u=d[0],h=d[1]}return zn.bondSingleUp(t.paper,a,u,h,l,Jn(l,r,i))}(s,n,r,e,l);break;case Y.PATTERN.STEREO.DOWN:o=function(t,e,n,r,i){var a=e.p,o=n.p,s=t.options,l=o.sub(a),c=l.length()+.2;l=l.normalized();var u=1.2*s.lineWidth,h=Math.max(Math.floor((c-s.lineWidth)/(s.lineWidth+u)),0)+2,d=c/(h-1);return zn.bondSingleDown(t.paper,e,l,h,d,s,Jn(s,r,i))}(s,n,r,e,l);break;case Y.PATTERN.STEREO.EITHER:o=function(t,e,n,r,i){var a=e.p,o=n.p,s=t.options,l=o.sub(a),c=l.length();l=l.normalized();var u=.6*s.lineWidth,h=Math.max(Math.floor((c-s.lineWidth)/(s.lineWidth+u)),0)+2,d=c/(h-.5);return zn.bondSingleEither(t.paper,e,l,h,d,s,Jn(s,r,i))}(s,n,r,e,l);break;default:o=zn.bondSingle(s.paper,n,r,s.options,Jn(s.options,e,l))}break;case Y.PATTERN.TYPE.DOUBLE:Kn(n.bid,e,t),o=e.b.stereo===Y.PATTERN.STEREO.NONE&&e.boldStereo&&e.neihbid1>=0&&e.neihbid2>=0?function(t,e,n,r,i,a,o){var s=e.p,l=n.p,c=e.norm,u=r.doubleBondShift,h=1.5*t.options.stereoBond,d=s.addScaled(c,h*u),f=l.addScaled(c,h*u);u>0?(a&&(d=d.addScaled(e.dir,h*tr(e.rightCos,e.rightSin))),o&&(f=f.addScaled(e.dir,-h*tr(n.leftCos,n.leftSin)))):u<0&&(a&&(d=d.addScaled(e.dir,h*tr(e.leftCos,e.leftSin))),o&&(f=f.addScaled(e.dir,-h*tr(n.rightCos,n.rightSin))));var p=Qn(t,e,n,r,i);return zn.bondDoubleStereoBold(t.paper,p,d,f,t.options,Jn(t.options,r,i))}(s,n,r,e,l,c,u):function(t,e,n,r,i,a){var o=r.b.stereo===Y.PATTERN.STEREO.CIS_TRANS,s=e.p,l=n.p,c=e.norm,u=o?0:r.doubleBondShift,h=t.options,d=h.bondSpace/2,f=d+u*d,p=u*d-d,m=s.addScaled(c,f),v=l.addScaled(c,f),g=s.addScaled(c,p),y=l.addScaled(c,p);return u>0?(i&&(m=m.addScaled(e.dir,h.bondSpace*tr(e.rightCos,e.rightSin))),a&&(v=v.addScaled(e.dir,-h.bondSpace*tr(n.leftCos,n.leftSin)))):u<0&&(i&&(g=g.addScaled(e.dir,h.bondSpace*tr(e.leftCos,e.leftSin))),a&&(y=y.addScaled(e.dir,-h.bondSpace*tr(n.rightCos,n.rightSin)))),zn.bondDouble(t.paper,m,g,v,y,o,h)}(s,n,r,e,c,u);break;case Y.PATTERN.TYPE.TRIPLE:o=zn.bondTriple(s.paper,n,r,s.options);break;case Y.PATTERN.TYPE.AROMATIC:var h,d;o=n.loop>=0&&(null===(h=l.loops.get(n.loop))||void 0===h?void 0:h.aromatic)||r.loop>=0&&(null===(d=l.loops.get(r.loop))||void 0===d?void 0:d.aromatic)?zn.bondSingle(s.paper,n,r,s.options):nr(s,n,r,e,c,u);break;case Y.PATTERN.TYPE.SINGLE_OR_DOUBLE:o=function(t,e,n){var r=e.p,i=n.p,a=t.options,o=D.dist(r,i)/Number((a.bondSpace+a.lineWidth).toFixed());return 1&o||(o+=1),zn.bondSingleOrDouble(t.paper,e,n,o,a)}(s,n,r);break;case Y.PATTERN.TYPE.SINGLE_OR_AROMATIC:case Y.PATTERN.TYPE.DOUBLE_OR_AROMATIC:o=nr(s,n,r,e,c,u);break;case Y.PATTERN.TYPE.ANY:o=zn.bondAny(s.paper,n,r,s.options);break;case Y.PATTERN.TYPE.HYDROGEN:o=zn.bondHydrogen(s.paper,n,r,s.options);break;case Y.PATTERN.TYPE.DATIVE:o=zn.bondDative(s.paper,n,r,s.options);break;default:throw new Error("Bond type "+e.b.type+" not supported")}return o}(t,this,c,u),this.rbb=Ln.relBox(this.path.getBBox()),t.addReObjectPath(Pn.data,this.visel,this.path,null,!0);var h={};h.path=function(t,e,n,r){var i=n.p,a=r.p,o=a.add(i).scaled(.5),s=a.sub(i).normalized(),l=s.rotateSC(1,0),c=[],u=t.options.lineWidth,h=t.options.bondSpace/2,d=u,f=2*u,p=1.5*h,m=1.5*h,v=3*h,g=.2;switch(e.b.reactingCenterStatus){case Y.PATTERN.REACTING_CENTER.NOT_CENTER:c.push(o.addScaled(l,v).addScaled(s,g*v)),c.push(o.addScaled(l,-v).addScaled(s,-.2*v)),c.push(o.addScaled(l,v).addScaled(s,-.2*v)),c.push(o.addScaled(l,-v).addScaled(s,g*v));break;case Y.PATTERN.REACTING_CENTER.CENTER:c.push(o.addScaled(l,v).addScaled(s,g*v).addScaled(s,d)),c.push(o.addScaled(l,-v).addScaled(s,-.2*v).addScaled(s,d)),c.push(o.addScaled(l,v).addScaled(s,g*v).addScaled(s,-d)),c.push(o.addScaled(l,-v).addScaled(s,-.2*v).addScaled(s,-d)),c.push(o.addScaled(s,p).addScaled(l,m)),c.push(o.addScaled(s,-p).addScaled(l,m)),c.push(o.addScaled(s,p).addScaled(l,-m)),c.push(o.addScaled(s,-p).addScaled(l,-m));break;case Y.PATTERN.REACTING_CENTER.MADE_OR_BROKEN:c.push(o.addScaled(l,v).addScaled(s,f)),c.push(o.addScaled(l,-v).addScaled(s,f)),c.push(o.addScaled(l,v).addScaled(s,-f)),c.push(o.addScaled(l,-v).addScaled(s,-f));break;case Y.PATTERN.REACTING_CENTER.ORDER_CHANGED:c.push(o.addScaled(l,v)),c.push(o.addScaled(l,-v));break;case Y.PATTERN.REACTING_CENTER.MADE_OR_BROKEN_AND_CHANGED:c.push(o.addScaled(l,v).addScaled(s,f)),c.push(o.addScaled(l,-v).addScaled(s,f)),c.push(o.addScaled(l,v).addScaled(s,-f)),c.push(o.addScaled(l,-v).addScaled(s,-f)),c.push(o.addScaled(l,v)),c.push(o.addScaled(l,-v));break;default:return null}return zn.reactingCenter(t.paper,c,t.options)}(r,this,c,u),h.path&&(h.rbb=Ln.relBox(h.path.getBBox()),t.addReObjectPath(Pn.data,this.visel,h.path,null,!0));var d={};d.path=function(t,e,n,r){var i=t.options,a=null;if(e.b.topology===Y.PATTERN.TOPOLOGY.RING)a="rng";else{if(e.b.topology!==Y.PATTERN.TOPOLOGY.CHAIN)return null;a="chn"}var o=n.p,s=r.p,l=s.add(o).scaled(.5),c=s.sub(o).normalized().rotateSC(1,0),u=i.lineWidth;e.doubleBondShift>0?c=c.scaled(-e.doubleBondShift):0===e.doubleBondShift&&(u+=i.bondSpace/2);var h=new D(2,1).scaled(i.bondSpace);e.b.type===Y.PATTERN.TYPE.TRIPLE&&(u+=i.bondSpace);var d=l.add(new D(c.x*(h.x+u),c.y*(h.y+u)));return zn.topologyMark(t.paper,d,a,i)}(r,this,c,u),d.path&&(d.rbb=Ln.relBox(d.path.getBBox()),t.addReObjectPath(Pn.data,this.visel,d.path,null,!0)),this.setHover(this.hover,r);var f=null,p=.6*n.subFontSize;n.showBondIds&&(f=rr(e,l,c,u,p,.5,.5,c.norm),t.addReObjectPath(Pn.indices,this.visel,f)),n.showHalfBondIds&&(f=rr(this.b.hb1,l,c,u,p,.8,.2,c.norm),t.addReObjectPath(Pn.indices,this.visel,f),f=rr(this.b.hb2,l,c,u,p,.2,.8,u.norm),t.addReObjectPath(Pn.indices,this.visel,f)),n.showLoopIds&&!n.showBondIds&&(f=rr(c.loop,l,c,u,p,.5,.5,u.norm),t.addReObjectPath(Pn.indices,this.visel,f),f=rr(u.loop,l,c,u,p,.5,.5,c.norm),t.addReObjectPath(Pn.indices,this.visel,f));var m=t.molecule.highlights,v=!1,g="";if(m.forEach((function(t){var n,r=null===(n=t.bonds)||void 0===n?void 0:n.includes(e);v=v||r,r&&(g=t.color)})),v){var y={fill:g,stroke:g,"stroke-width":7*n.lineattr["stroke-width"],"stroke-linecap":"round"},b=Q.obj2scaled(this.b.center,t.render.options),x=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,c,u);x.attr(y),t.addReObjectPath(Pn.hovering,this.visel,x,b,!0)}}}}}],[{key:"isSelectable",value:function(){return!0}}]),s}(Mn);function Xn(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===Y.PATTERN.TYPE.SINGLE&&a.b.stereo===Y.PATTERN.STEREO.UP?a.b.end===i.begin||a.boldStereo&&n:!(a.b.type!==Y.PATTERN.TYPE.DOUBLE||a.b.stereo!==Y.PATTERN.STEREO.NONE||!n||!a.boldStereo))}))}function Kn(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=Xn(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 Jn(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,l="";return o&&!s?l=o:!o&&s&&(l=s),l&&t.colorStereogenicCenters!==kn.Off&&t.colorStereogenicCenters!==kn.LabelsOnly?Vn(t,l):a}function Qn(t,e,n,r,i){var a=t.options,o=er(e,r.neihbid1,a.stereoBond,i),s=er(n,r.neihbid2,a.stereoBond,i),l=o[0],c=o[1],u=s[0],h=s[1];return zn.bondSingleStereoBold(t.paper,l,c,u,h,a,Jn(a,r,i))}function tr(t,e){return e<0||Math.abs(t)>.9?0:e/(1-t)}function er(t,e,n,r){var i=r.halfBonds.get(e),a=D.dot(t.dir,i.dir),o=D.cross(t.dir,i.dir),s=Math.sqrt(.5*(1-a)),l=i.dir.rotateSC((o>=0?-1:1)*s,Math.sqrt(.5*(1+a))),c=t.p.addScaled(l,.7*n/(s+.3)),u=t.p.addScaled(l.negated(),.7*n/(s+.3));return o>0?[c,u]:[u,c]}function nr(t,e,n,r,i,a){var o=[.125,.125,.005,.125],s=null,l=null,c=t.options,u=r.doubleBondShift;r.b.type===Y.PATTERN.TYPE.SINGLE_OR_AROMATIC&&(s=u>0?1:2,l=o.map((function(t){return t*c.scale}))),r.b.type===Y.PATTERN.TYPE.DOUBLE_OR_AROMATIC&&(s=3,l=o.map((function(t){return t*c.scale})));var h=function(t,e,n,r,i,a,o,s){var l=t.p,c=e.p,u=t.norm,h=a/2,d=h+n*h,f=n*h-h,p=l.addScaled(u,d),m=c.addScaled(u,d),v=l.addScaled(u,f),g=c.addScaled(u,f);return n>0?(r&&(p=p.addScaled(t.dir,a*tr(t.rightCos,t.rightSin))),i&&(m=m.addScaled(t.dir,-a*tr(e.leftCos,e.leftSin)))):n<0&&(r&&(v=v.addScaled(t.dir,a*tr(t.leftCos,t.leftSin))),i&&(g=g.addScaled(t.dir,-a*tr(e.rightCos,e.rightSin)))),zn.aromaticBondPaths(p,v,m,g,o,s)}(e,n,u,i,a,c.bondSpace,s,l);return zn.bondAromatic(t.paper,h,u,c)}function rr(t,e,n,r,i,a,o,s){var l=D.lc(n.p,a,r.p,o,s,i),c=e.text(l.x,l.y,t.toString()),u=Ln.relBox(c.getBBox());return zn.recenterText(c,u),c}function ir(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=Q.obj2scaled(i.a.pp,r.options),s=Q.obj2scaled(a.a.pp,r.options),l=e.molecule.halfBonds.get(t.b.hb1),c=e.molecule.halfBonds.get(t.b.hb2);null!=l&&l.dir&&null!=c&&c.dir&&(l.p=ar(i,o,l.dir,2*n.lineWidth),c.p=ar(a,s,c.dir,2*n.lineWidth),t.b.center=D.lc2(i.a.pp,.5,a.a.pp,.5),t.b.len=D.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(l.dir.y,l.dir.x)/Math.PI)}}function ar(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,Ln.shiftRayBox(e,n,s))}return i>0&&(e=e.addScaled(n,i+r)),e}function or(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 sr=new WeakMap,lr=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,u.Z)(e);if(n){var i=(0,u.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,v.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=sr),n.set(e,i),t}return(0,i.Z)(s,[{key:"hoverPath",value:function(t){var e=nt.fromRelBox((0,p.Z)(this,sr).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,sr))||void 0===e||!e.attrs)return null;var n=this.hoverPath(t).attr(t.options.hoverStyle);return t.ctab.addReObjectPath(Pn.hovering,this.visel,n),n}},{key:"makeSelectionPlate",value:function(t,e,n){var r;return null!==(r=(0,p.Z)(this,sr))&&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:J.getDefaultStereoFlagPosition(t.molecule,e),l=i.paper,c=Q.obj2scaled(s,n),u=(r={},(0,a.Z)(r,W.Abs,n.absFlagLabel),(0,a.Z)(r,W.And,n.andFlagLabel),(0,a.Z)(r,W.Mixed,n.mixedFlagLabel),(0,a.Z)(r,W.Or,n.orFlagLabel),r);n.showStereoFlags&&(0,f.Z)(this,sr,l.text(c.x,c.y,o.enhancedStereoFlag?u[o.enhancedStereoFlag]:"").attr({font:n.font,"font-size":n.fontsz,fill:"#000"})),i.ctab.addReObjectPath(Pn.data,this.visel,(0,p.Z)(this,sr),null,!0)}}}],[{key:"isSelectable",value:function(){return!0}}]),s}(Mn);var cr=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,u.Z)(e);if(a){var r=(0,u.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 D).negated()).transform(Q.scaled2obj,r.options);else{a=new nt(t.a.pp,t.a.pp);var o=new D(.05*3,.05*3);a=a.extend(o,o)}i=i?nt.union(i,a):a}})),i}},{key:"_draw",value:function(t,e,n){var r=this.calcBBox(t.ctab,e,t);if(r){var i=Q.obj2scaled(new D(r.p0.x,r.p0.y),t.options),a=Q.obj2scaled(new D(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}(Mn);var ur=new D(.05*3,.05*3),hr=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,u.Z)(e);if(n){var i=(0,u.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?nt.union(e,r):r)})),e&&(e=e.extend(ur,ur)),e}},{key:"draw",value:function(t,e){var n=this.calcBBox(t);if(!n)return{};var r={data:[]},i=Q.obj2scaled(n.p0,e),a=Q.obj2scaled(n.p1,e),o=t.paper.set();(function(t,e,n,r){r=Q.obj2scaled(r||new D(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=zn.bracket(e.paper,r.negated(),r.negated().rotateSC(1,0),Q.obj2scaled(new D(n.p0.x,o),e.options),i,a,e.options),l=zn.bracket(e.paper,r,r.rotateSC(1,0),Q.obj2scaled(new D(n.p1.x,o),e.options),i,a,e.options);t.push(s,l)})(o,t,n),r.data.push(o);var s=t.ctab.rgroups.keyOf(this),l=t.paper.set(),c=t.paper.text(i.x,(i.y+a.y)/2,"R"+s+"=").attr({font:e.font,"font-size":e.fontRLabel,fill:"black"}),u=Ln.relBox(c.getBBox());c.translateAbs(-u.width/2-e.lineWidth,0),l.push(c);for(var h={font:e.font,"font-size":e.fontRLogic,fill:"black"},d=[dr(s,this.item)],f=u.height/2+e.lineWidth/2,p=0;p<d.length;++p){var m=t.paper.text(i.x,(i.y+a.y)/2,d[p]).attr(h),v=Ln.relBox(m.getBBox());f+=v.height/2,m.translateAbs(-v.width/2-6*e.lineWidth,f),f+=v.height/2+e.lineWidth/2,r.data.push(m),l.push(m)}return r.data.push(c),this.labelBox=nt.fromRelBox(l.getBBox()).transform(Q.scaled2obj,t.options),r}},{key:"_draw",value:function(t,e,n){if(!this.getVBoxObj(t))return null;var r=this.getVBoxObj(t).extend(ur,ur);if(!r)return null;var i=Q.obj2scaled(r.p0,t.options),a=Q.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(Pn.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(Pn.data,r.visel,i[e].shift(),null,!0)}))}}],[{key:"isSelectable",value:function(){return!1}}]),o}(Mn);function dr(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 fr(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 pr(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?fr(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):fr(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var 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,u.Z)(e);if(n){var i=(0,u.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 D(t.x,t.y),r=this.getReferencePointDistance(t),i=this.item,a=vr(i.pos,n);if(mt.isElliptical(i)){var o=this.getReferencePoints(),s=(0,m.Z)(o,3),l=s[0],c=s[1],u=s[2];a=Math.min(a,vr([l,u],n),vr([u,c],n))}var h=r.minDist<=8/e?r.refPoint:null;return{minDist:a=Math.min(r.minDist,a),refPoint:h}}},{key:"getReferencePointDistance",value:function(t){var e=[];return this.getReferencePoints().forEach((function(n){e.push({minDist:Math.abs(D.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(Pn.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 D(r.x,r.y)),t.push(new D(i.x,i.y)),mt.isElliptical(e)){var o=function(t,e,n){if(0==+Ln.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 D(a,o)}var s=Math.hypot(n.x-e.x,n.y-e.y),l=Math.hypot(s/2,t),c=Ln.calcCoordinates(e,n,l).pos1,u=Ln.calcCoordinates(e,n,l).pos2;if(t>0){if(n.x<e.x)return new D(null==c?void 0:c.x,null==c?void 0:c.y);if(n.x>e.x)return new D(null==u?void 0:u.x,null==u?void 0:u.y);if(n.x===e.x){if(n.y>e.y)return new D(null==u?void 0:u.x,null==u?void 0:u.y);if(n.y<e.y)return new D(null==c?void 0:c.x,null==c?void 0:c.y);if(n.y===e.y)return new D(e.x,e.y)}}else{if(n.x>e.x)return new D(null==c?void 0:c.x,null==c?void 0:c.y);if(n.x<e.x)return new D(null==u?void 0:u.x,null==u?void 0:u.y);if(n.x===e.x){if(n.y>e.y)return new D(null==c?void 0:c.x,null==c?void 0:c.y);if(n.y<e.y)return new D(null==u?void 0:u.x,null==u?void 0:u.y);if(n.y===e.y)return new D(e.x,e.y)}}return new D(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=Q.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=mt.isElliptical(i)&&i.height*e.scale,o=i.pos.map((function(t){return Q.obj2scaled(t,e)||new D})),s=this.getArrowParams(o[0].x,o[0].y,o[1].x,o[1].y),l=s.length,c=s.angle;switch(n){case"selection":r=zn.rectangleArrowHighlightAndSelection(t.paper,{pos:o,height:a},l,c,e);break;case"arrow":r=zn.arrow(t.paper,pr(pr({},i),{},{pos:o,height:a}),l,c,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,nt.fromRelBox(Ln.relBox(r.getBBox())))}}],[{key:"isSelectable",value:function(){return!0}}]),o}(Mn);function vr(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(D.dist(t[0],e),D.dist(t[1],e));else{var r=D.dist(t[0],t[1]),i=D.dist(t[0],e),a=D.dist(t[1],e),o=(r+i+a)/2;n=2/r*Math.sqrt(o*(o-r)*(o-i)*(o-a))}return n}var gr=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,u.Z)(e);if(n){var i=(0,u.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=Q.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(Pn.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=Q.obj2scaled(this.item.pp,n),a=zn.plus(r.paper,i,n),o=n.offset;null!=o&&a.translateAbs(o.x,o.y),this.visel.add(a,nt.fromRelBox(Ln.relBox(a.getBBox())))}}],[{key:"isSelectable",value:function(){return!0}}]),o}(Mn);var yr=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,u.Z)(e);if(n){var i=(0,u.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=Q.obj2scaled(e.p0,t.options),r=Q.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(Pn.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}(Mn);var br=Ln.tfx,xr=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,u.Z)(e);if(n){var i=(0,u.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 F(e.atoms),i=it.getCrossBonds(t.molecule,r);it.bracketPos(e,t.molecule,i);var a=e.bracketBox,o=e.bracketDir;e.areas=[a];var s=t.molecule.functionalGroups;if(ut.isContractedFunctionalGroup(e.id,s))e.atoms.forEach((function(n){ut.isAttachmentPointAtom(n,t.molecule)&&(e.firstSgroupAtom=t.molecule.atoms.get(n),e.functionalGroup=!0)}));else switch(e.type){case"MUL":wr(n,this.render,e,i,r,a,o,e.data.mul);break;case"SRU":var l=e.data.connectivity||"eu";"ht"===l&&(l="");var c=e.data.subscript||"n";wr(n,this.render,e,i,r,a,o,c,l);break;case"SUP":wr(n,this.render,e,i,r,a,o,e.data.name,null,{"font-style":"italic"});break;case"GEN":wr(n,this.render,e,i,r,a,o);break;case"DAT":n=function(t,e){return it.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 it.getAtoms(t,e).forEach((function(o){var s=t.atoms.get(o),l=Q.obj2scaled(s.a.pp,r),c=s.visel.boundingBox;null!==c&&(l.x=Math.max(l.x,c.p1.x)),l.x+=r.lineWidth;var u=Er(i,l,e,r),h=Ln.relBox(u.getBBox());u.translateAbs(.5*h.width,-.3*h.height),a.push(u);var d=nt.fromRelBox(Ln.relBox(u.getBBox()));d=d.transform(Q.scaled2obj,n.options),e.areas.push(d)})),a}(t,e):function(t,e){var n=t.render,r=n.options,i=n.paper,a=i.set(),o=Er(i,e.pp.scaled(r.scale),e,r),s=Ln.relBox(o.getBBox());o.translateAbs(.5*s.width,-.5*s.height),a.push(o);var l=nt.fromRelBox(Ln.relBox(o.getBBox()));return e.dataArea=l.transform(Q.scaled2obj,n.options),t.sgroupData.has(e.id)||t.sgroupData.set(e.id,new yr(e)),a}(t,e)}(t,e)}return n}},{key:"makeSelectionPlate",value:function(t,e,n){var r=this.item,i=Sr(r,n),a=i.startX,o=i.startY,s=i.size,l=t.molecule.functionalGroups;if(ut.isContractedFunctionalGroup(r.id,l))return e.rect(a,o,s,s).attr(n.selectionStyle)}},{key:"drawHover",value:function(t){var e=t.options,n=t.paper,r=this.item,i=Sr(r,e),a=i.a0,o=i.a1,s=i.b0,l=i.b1,c=t.ctab.molecule.functionalGroups,u=n.set();if(ut.isContractedFunctionalGroup(r.id,c)){var h=Sr(r,e),d=h.startX,f=h.startY,p=h.size;r.hovering=n.rect(d,f,p,p).attr(e.hoverStyle)}else r.hovering=n.path("M{0},{1}L{2},{3}L{4},{5}L{6},{7}L{0},{1}",br(a.x),br(a.y),br(o.x),br(o.y),br(l.x),br(l.y),br(s.x),br(s.y)).attr(e.hoverStyle);u.push(r.hovering),it.getAtoms(t.ctab.molecule,r).forEach((function(e){u.push(t.ctab.atoms.get(e).makeHoverPlate(t))}),this),it.getBonds(t.ctab.molecule,r).forEach((function(e){u.push(t.ctab.bonds.get(e).makeHoverPlate(t))}),this),t.ctab.addReObjectPath(Pn.hovering,this.visel,u)}},{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(Pn.data,this.visel,i,null,!0),this.setHover(this.hover,e)}}}],[{key:"isSelectable",value:function(){return!1}}]),o}(Mn);function wr(t,e,n,r,i,a,o,s,l,c){for(var u=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 l=[],c=i.rotateSC(1,0),u=Object.values(e),h=u.flat();return h.length<2?function(){i=i||new D(1,0),c=c||i.rotateSC(1,0);var t=Math.min(.25,.3*r.sz().x),e=D.lc2(i,r.p0.x,c,.5*(r.p0.y+r.p1.y)),n=D.lc2(i,r.p1.x,c,.5*(r.p0.y+r.p1.y)),a=r.sz().y;l.push(new s(e,i.negated(),t,a),new s(n,i,t,a))}():2===h.length&&2===u.length?function(){var e=t.bonds.get(h[0]),n=t.bonds.get(h[1]),r=e.getCenter(t),i=n.getCenter(t),c=-1,u=-1,d=-1,f=-1,p=D.centre(r,i),m=D.diff(i,r).normalized(),v=m.negated(),g=m.rotateSC(1,0),y=g.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 D).negated()).transform(Q.scaled2obj,a.options),c=Math.max(c,Ln.shiftRayBox(r,v,e)),u=Math.max(u,Ln.shiftRayBox(i,m,e)),d=Math.max(d,Ln.shiftRayBox(p,g,e)),f=Math.max(f,Ln.shiftRayBox(p,y,e))}),this),c=Math.max(c+.2,0),u=Math.max(u+.2,0);var b=1.5+(d=Math.max(Math.max(d,f)+.1,0));l.push(new s(r.addScaled(v,c),v,.25,b),new s(i.addScaled(m,u),m,.25,b))}():function(){for(var e=0;e<h.length;++e){var r=t.bonds.get(h[e]),i=r.getCenter(t),a=n.has(r.begin)?r.getDir(t):r.getDir(t).negated();l.push(new s(i,a,.2,1))}}(),l}(e.ctab.molecule,r,i,a,o,e,n.id),h=-1,d=0;d<u.length;++d){var f=u[d],p=zn.bracket(e.paper,Q.obj2scaled(f.d,e.options),Q.obj2scaled(f.n,e.options),Q.obj2scaled(f.c,e.options),f.w,f.h,e.options);t.push(p),(h<0||u[h].d.x<f.d.x||u[h].d.x===f.d.x&&u[h].d.y>f.d.y)&&(h=d)}var m=u[h];function v(n,r){var i=Q.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});c&&a.attr(c);var o=nt.fromRelBox(Ln.relBox(a.getBBox())),s=Math.max(Ln.shiftRayBox(i,m.d.negated(),o),3)+2;a.translateAbs(s*m.d.x,s*m.d.y),t.push(a)}s&&v(s,.5),l&&v(l,-.5)}function Er(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}function Sr(t,e){var n=t.bracketBox.transform(Q.obj2scaled,e),r=e.lineWidth,i=new D(4*r,6*r);n=n.extend(i,i);var a=t.bracketDir,o=a.rotateSC(1,0),s=D.lc2(a,n.p0.x,o,n.p0.y),l=D.lc2(a,n.p0.x,o,n.p1.y),c=D.lc2(a,n.p1.x,o,n.p0.y),u=D.lc2(a,n.p1.x,o,n.p1.y),h=e.contractedFunctionalGroupSize,d=(c.x+s.x)/2-h/2,f=(l.y+s.y)/2-h/2;if(t.firstSgroupAtom){var p=new D(h/2,h/2,0),m=D.diff(t.firstSgroupAtom.pp.scaled(40),p);d=m.x,f=m.y}return{a0:s,a1:l,b0:c,b1:u,startX:d,startY:f,size:h}}var Rr=Ln.tfx,Ar=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,u.Z)(e);if(n){var i=(0,u.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 D(t.x,t.y),i=this.getReferencePointDistance(t),a=this.item,o=a.mode,s=a.pos;switch(o){case pt.ellipse:var l=D.diff(s[1],s[0]),c=l.x/2,u=l.y/2,h=D.sum(s[0],new D(c,u)),d=D.diff(r,h);n=0!==c&&0!==u?Math.abs(1-d.x*d.x/(c*c)-d.y*d.y/(u*u)):Or(s,r);break;case pt.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),v=Math.max(s[0].y,s[1].y),g=[];r.x>=f&&r.x<=m&&(r.y<p?g.push(p-r.y):r.y>v?g.push(r.y-v):g.push(r.y-p,v-r.y)),r.x<f&&r.y<p&&g.push(D.dist(new D(f,p),r)),r.x>m&&r.y>v&&g.push(D.dist(new D(m,v),r)),r.x<f&&r.y>v&&g.push(D.dist(new D(f,v),r)),r.x>m&&r.y<p&&g.push(D.dist(new D(m,p),r)),r.y>=p&&r.y<=v&&(r.x<f?g.push(f-r.x):r.x>m?g.push(r.x-m):g.push(r.x-f,m-r.x)),n=Math.min.apply(Math,g);break;case pt.line:n=Or(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(D.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 pt.ellipse:case pt.rectangle:var n=new D(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(D.diff(this.item.pos[0],this.item.pos[1]).x),i=Math.abs(D.diff(this.item.pos[0],this.item.pos[1]).y);e.push(new D(n.x+.5*r,n.y),new D(n.x+r,n.y+.5*i),new D(n.x+.5*r,n.y+i),new D(n.x,n.y+.5*i)),t&&this.item.mode!==pt.rectangle||e.push(n,new D(n.x,n.y+i),new D(n.x+r,n.y+i),new D(n.x+r,n.y));break;case pt.line:this.item.pos.forEach((function(t){return e.push(new D(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]=Q.obj2scaled(n,t.options)}));var n=t.options.scale,r=[];switch(this.item.mode){case pt.ellipse:var i=D.diff(e[1],e[0]),a=i.x/2,o=i.y/2;r.push(t.paper.ellipse(Rr(e[0].x+a),Rr(e[0].y+o),Rr(Math.abs(a)+n/8),Rr(Math.abs(o)+n/8))),Math.abs(a)-n/8>0&&Math.abs(o)-n/8>0&&r.push(t.paper.ellipse(Rr(e[0].x+a),Rr(e[0].y+o),Rr(Math.abs(a)-n/8),Rr(Math.abs(o)-n/8)));break;case pt.rectangle:r.push(t.paper.rect(Rr(Math.min(e[0].x,e[1].x)-n/8),Rr(Math.min(e[0].y,e[1].y)-n/8),Rr(Math.max(e[0].x,e[1].x)-Math.min(e[0].x,e[1].x)+n/4),Rr(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(Rr(Math.min(e[0].x,e[1].x)+n/8),Rr(Math.min(e[0].y,e[1].y)+n/8),Rr(Math.max(e[0].x,e[1].x)-Math.min(e[0].x,e[1].x)-n/4),Rr(Math.max(e[0].y,e[1].y)-Math.min(e[0].y,e[1].y)-n/4)));break;case pt.line:var s=[],l=Math.atan((e[1].y-e[0].y)/(e[1].x-e[0].x)),c={x:0,y:0},u={x:0,y:0},h=e[0].x>e[1].x?-1:1;c.x=e[0].x-h*(n/8*Math.cos(l)),c.y=e[0].y-h*(n/8*Math.sin(l)),u.x=e[1].x+h*(n/8*Math.cos(l)),u.y=e[1].y+h*(n/8*Math.sin(l)),s.push("M",c.x+h*n/8*Math.sin(l),c.y-h*n/8*Math.cos(l)),s.push("L",u.x+h*n/8*Math.sin(l),u.y-h*n/8*Math.cos(l)),s.push("L",u.x-h*n/8*Math.sin(l),u.y+h*n/8*Math.cos(l)),s.push("L",c.x-h*n/8*Math.sin(l),c.y+h*n/8*Math.cos(l)),s.push("L",c.x+h*n/8*Math.sin(l),c.y-h*n/8*Math.cos(l)),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(Pn.hovering,this.visel,e),e}},{key:"makeSelectionPlate",value:function(t,e,n){var r=this.item.pos.map((function(e){return Q.obj2scaled(e,t.render.options)||new D})),i=this.getReferencePoints(),a=t.render.options.scale,o=t.render.paper.set();return o.push(Pr(this.item.mode,e,r).attr(n.hoverStyleSimpleObject)),i.forEach((function(e){var n=Q.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 Q.obj2scaled(t,e)||new D})),i=Pr(this.item.mode,n.paper,r,e),a=e.offset;null!=a&&i.translateAbs(a.x,a.y),this.visel.add(i,nt.fromRelBox(Ln.relBox(i.getBBox())))}}],[{key:"isSelectable",value:function(){return!0}}]),o}(Mn);function Or(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(D.dist(t[0],e),D.dist(t[1],e));else{var r=D.dist(t[0],t[1]),i=D.dist(t[0],e),a=D.dist(t[1],e),o=(r+i+a)/2;n=2/r*Math.sqrt(o*(o-r)*(o-i)*(o-a))}return n}function Pr(t,e,n,r){var i;switch(t){case pt.ellipse:i=zn.ellipse(e,n,r);break;case pt.rectangle:i=zn.rectangle(e,n,r);break;case pt.line:i=zn.line(e,n,r);break;default:throw new Error("Unsupported shape type")}return i}var kr=Ln.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,u.Z)(e);if(n){var i=(0,u.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 D,e.radius=new D,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 D,o.hbs.forEach((function(e){var i=a.halfBonds.get(e),s=t.bonds.get(i.bid),l=Q.obj2scaled(t.atoms.get(i.begin).a.pp,n);s.b.type!==Y.PATTERN.TYPE.AROMATIC&&(o.aromatic=!1),r.centre.add_(l)})),o.convex=!0;for(var s=0;s<this.loop.hbs.length;++s){var l=a.halfBonds.get(o.hbs[s]),c=a.halfBonds.get(o.hbs[(s+1)%o.hbs.length]);Math.atan2(D.cross(l.dir,c.dir),D.dot(l.dir,c.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=Q.obj2scaled(t.atoms.get(i.begin).a.pp,n),s=Q.obj2scaled(t.atoms.get(i.end).a.pp,n),l=D.diff(s,o).rotateSC(1,0).normalized(),c=D.dot(D.diff(o,r.centre),l);r.radius=r.radius<0?c:Math.min(r.radius,c)})),this.radius*=.7,o.aromatic){var u=null;if(o.convex&&n.aromaticCircle)u=i.circle(this.centre.x,this.centre.y,this.radius).attr({stroke:"#000","stroke-width":n.lineattr["stroke-width"]});else{for(var h="",d=0;d<o.hbs.length;++d){var f=a.halfBonds.get(o.hbs[d]),p=a.halfBonds.get(o.hbs[(d+1)%o.hbs.length]),m=Math.atan2(D.cross(f.dir,p.dir),D.dot(f.dir,p.dir)),v=(Math.PI-m)/2,g=p.dir.rotate(v),y=Q.obj2scaled(t.atoms.get(p.begin).a.pp,n),b=Math.sin(v);Math.abs(b)<.1&&(b=.1*b/Math.abs(b));var x=n.bondSpace/b,w=y.addScaled(g,-x);h+=0===d?"M":"L",h+=kr(w.x)+","+kr(w.y)}h+="Z",u=i.path(h).attr({stroke:"#000","stroke-width":n.lineattr["stroke-width"],"stroke-dasharray":"- "})}t.addReObjectPath(Pn.data,this.visel,u,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}(Mn);function Br(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 Zr=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,u.Z)(e);if(n){var i=(0,u.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,v.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(D.diff(e,n).x)/40,a=Math.abs(D.diff(e,n).y)/40,o=[];return o.push(this.item.position,new D(r.x,r.y+a),new D(r.x+i,r.y+a),new D(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,d.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,d.Z)(l.map((function(t){return t.getBBox().y+t.getBBox().height}))));return{p0:new D(n,i),p1:new D(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(Pn.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=Q.obj2scaled(this.item.position,n),l=0;this.paths=[];var c=this.item.content?JSON.parse(this.item.content):null;c&&(c.blocks.forEach((function(t){var e=r.getRanges(t,n),i=0,c=[];e.forEach((function(e){var r=(0,m.Z)(e,3),u=r[0],h=r[1],d=r[2];t.text=t.text.replace(/[^\S\r\n]/g," ");var f=o.text(s.x,s.y,t.text.substring(u,h+1)||" ").attr(function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Br(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Br(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"},d));f.translateAbs(i,l+(d.shiftY||0)),c.push(f),i+=f.getBBox().width})),r.paths.push(c);var u=r.getRelBox([c]),h=u.p0,d=u.p1;l+=Math.abs(D.diff(h,d).y)})),this.item.setPos(this.getReferencePoints()),i.ctab.addReObjectPath(Pn.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(St.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 St.Bold:t["font-weight"]="bold";break;case St.Italic:t["font-style"]="italic";break;case St.Subscript:t["font-size"]=a+"px",t.shiftY=r/3;break;case St.Superscript:t["font-size"]=a+"px",t.shiftY=-r/3;break;case"".concat(St.FontSize,"_").concat(i,"px"):t["font-size"]=i+"px"}return t}),{})}}],[{key:"isSelectable",value:function(){return!0}}]),s}(Mn);function Cr(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 Mr=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 wt),(0,a.Z)(this,"rgroups",new wt),(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 wt),(0,a.Z)(this,"ccFragmentType",new wt),(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 Rt,this.initLayers(),this.clearMarks(),e.atoms.forEach((function(t,e){i.atoms.set(e,new Un(t))})),e.bonds.forEach((function(t,e){i.bonds.set(e,new $n(t))})),e.loops.forEach((function(t,e){i.reloops.set(e,new Tr(t))})),e.rxnPluses.forEach((function(t,e){i.rxnPluses.set(e,new gr(t))})),e.rxnArrows.forEach((function(t,e){i.rxnArrows.set(e,new mr(t))})),e.simpleObjects.forEach((function(t,e){i.simpleObjects.set(e,new Ar(t))})),e.texts.forEach((function(t,e){i.texts.set(e,new Zr(t))})),e.frags.forEach((function(t,e){i.frags.set(e,new cr(t)),t&&i.enhancedFlags.set(e,new lr)})),e.rgroups.forEach((function(t,e){i.rgroups.set(e,new hr(t))})),e.sgroups.forEach((function(t,e){i.sgroups.set(e,new xr(t)),"DAT"!==t.type||t.data.attached||i.sgroupData.set(e,new yr(t)),ut.isFunctionalGroup(t)&&i.molecule.functionalGroups.set(e,new ut(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 F;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 F,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 F,i=t.getConnectedComponent(n,r);r.forEach((function(e){t.removeConnectedComponent(e)})),t.addConnectedComponent(i)}}))}},{key:"initLayers",value:function(){for(var t in Pn)this.layers[Pn[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?nt.fromRelBox(Ln.relBox(n.getBBox())):null,l=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,l),n.insertBefore(r.layers[Pn[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;Lr(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?nt.union(r,i):i.clone())}))})),r=r||new nt(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)Ir(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 Tr(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(Pn.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 xr)&&n[i].forEach((function(t,a){if(t instanceof Un){var o,s,l=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 Cr(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)?Cr(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(l.s();!(s=l.n()).done;)o=s.value}catch(t){l.e(t)}finally{l.f()}r.push({selected:t.selected,sgroup:o})}if(t instanceof xr&&ut.isContractedFunctionalGroup(t.item.id,n.molecule.functionalGroups)){var c=r.filter((function(e){return e.sgroup===t.item.id}));t.selected=c.length>0&&c[0].selected}var u=null!=e&&e[i]?e[i].indexOf(a)>-1:t.selected;null===e&&(u=!1),n.showItemSelection(t,u)}))}))}},{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 yr&&(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(Pn.selectionPlate,t.visel,t.selectionPlate)}t.selectionPlate&&t.selectionPlate.show()}else n&&t.selectionPlate&&t.selectionPlate.hide()}}]),t}();function Lr(t){return!t||!Object.keys(Mr.maps).some((function(e){return t[e]&&t[e].length>0}))}function Ir(t,e){if("set"===t.type)for(var n=0;n<t.length;++n)Ir(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)(Mr,"maps",{atoms:Un,bonds:$n,rxnPluses:gr,rxnArrows:mr,frags:cr,rgroups:hr,sgroupData:yr,enhancedFlags:lr,sgroups:xr,reloops:Tr,simpleObjects:Ar,texts:Zr});var Nr=Math.PI/12;function Dr(t,e){var n=D.diff(e,t);return Math.atan2(n.y,n.x)}function _r(t,e){return e&&(t=Dr(t,e)),Math.round(t/Nr)*Nr}function jr(t){var e=Math.round(t/Math.PI*180);return e>180?e-=360:e<=-180&&(e+=360),e}var Gr={calcAngle:Dr,fracAngle:_r,calcNewAtomPos:function(t,e,n){var r=new D(1,0).rotate(n?Dr(t,e):_r(t,e));return r.add_(t),r},degrees:jr,setFracAngle:function(t){Nr=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),l=Dr(i.pp,o.pp)-Dr(a.pp,s.pp),c=Math.abs(jr(l)%180),u=D.dist(i.pp,o.pp)/D.dist(a.pp,s.pp);return{merged:!(0,b.inRange)(c,10,170)&&(0,b.inRange)(u,.8,1.2),angle:l,scale:u,cross:Math.abs(jr(l))>90}}};function Fr(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 zr(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Fr(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Fr(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function Hr(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=D.ZERO,this.ctab=new Mr(new Rt,this),this.options=function(t){var e=t.scale||100;t.rotationStep&&Gr.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 D,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)}Hr.prototype.updateOptions=function(t){try{var e=JSON.parse(t);if(e&&"object"===(0,y.Z)(e))return this.options=zr(zr({},this.options),e),this.options}catch(t){}return!1},Hr.prototype.selectionPolygon=function(t){return zn.selectionPolygon(this.paper,t,this.options)},Hr.prototype.selectionLine=function(t,e){return zn.selectionLine(this.paper,t,e,this.options)},Hr.prototype.selectionRectangle=function(t,e){return zn.selectionRectangle(this.paper,t,e,this.options)},Hr.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),Q.scaled2obj(t,this.options)},Hr.prototype.obj2view=function(t,e){var n=Q.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},Hr.prototype.scrollPos=function(){return new D(this.clientArea.scrollLeft,this.clientArea.scrollTop)},Hr.prototype.page2obj=function(t){var e=this.clientArea.getBoundingClientRect(),n=e.top,r=e.left,i=new D(t.clientX-r,t.clientY-n);return this.view2obj(i)},Hr.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)},Hr.prototype.setOffset=function(t){var e=new D(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},Hr.prototype.setZoom=function(t){this.options.zoom=t,this.paper.setSize(this.sz.x*t,this.sz.y*t),this.setViewBox(t)},Hr.prototype.setScrollOffset=function(t,e){var n,r,i,a,o,s,l,c=this.clientArea,u=c.clientWidth,h=c.clientHeight,d=(n=this.sz.scaled(this.options.zoom),r=t,i=e,a=u+t,o=h+e,s=r<0?-r:0,l=i<0?-i:0,n.x<a&&(s+=a-n.x),n.y<o&&(l+=o-n.y),new D(s,l)).scaled(1/this.options.zoom);if(d.x>0||d.y>0){this.setPaperSize(this.sz.add(d));var f=new D(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)))}c.scrollLeft=t*this.options.scale,c.scrollTop=e*this.options.scale,this.update(!1)},Hr.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)},Hr.prototype.setViewBox=function(t){this.useOldZoom?this.setScale(t):this.paper.canvas.setAttribute("viewBox","0 0 "+this.sz.x+" "+this.sz.y)},Hr.prototype.setMolecule=function(t){this.paper.clear(),this.ctab=new Mr(t,this),this.options.offset=new D,this.update(!1)},Hr.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 D(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(Q.obj2scaled,this.options).translate(this.options.offset||new D);if(this.options.autoScale){var a=i.sz(),o=this.options.autoScaleMargin,s=new D(o,o),l=e;if(o&&(l.x<2*o+1||l.y<2*o+1))throw new Error("View box too small for the given margin");var c=this.options.rescaleAmount||Math.max(a.x/(l.x-2*o),a.y/(l.y-2*o));this.options.maxBondLength/c>1&&(c=1);var u=a.add(s.scaled(2*c));this.paper.setViewBox(i.pos().x-o*c-(l.x*c-u.x)/2,i.pos().y-o*c-(l.y*c-u.y)/2,l.x*c,l.y*c)}else{var h=D.UNIT.scaled(r),d=i.sz().length()>0?i.extend(h,h):i,f=new nt(this.scrollPos(),e.scaled(1/this.options.zoom).sub(D.UNIT.scaled(20))),p=nt.union(f,d);this.oldCb||(this.oldCb=new nt);var m=p.sz().floor(),v=this.oldCb.p0.sub(p.p0).ceil();this.oldBb=i,this.sz&&m.x===this.sz.x&&m.y===this.sz.y||this.setPaperSize(m),this.options.offset=this.options.offset||new D,0===v.x&&0===v.y||(this.setOffset(this.options.offset.add(v)),this.ctab.translate(v))}}};var Ur=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!==Tn.IUPAC&&s!==Tn.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}(),Vr=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"});function Wr(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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}!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,u.Z)(e);if(n){var i=(0,u.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,Vr.ATOM_ATTR,1)).data={aid:t,attribute:e,value:n},i.data2=null,i}(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,Ur.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)}}])}(Ur),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,u.Z)(e);if(n){var i=(0,u.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,Vr.ATOM_MOVE,2)).data={aid:t,d:e,noinvalidate:n},i}(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=Q.obj2scaled(i,t.render.options);o.visel.translate(s)}this.data.d=i.negated(),this.data.noinvalidate||Ur.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}}])}(Ur);var Yr=function(t){(0,l.Z)(n,t);var e=Wr(n);function n(t,i){var a;return(0,r.Z)(this,n),(a=e.call(this,Vr.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 V(a)):i.atoms.set(this.data.aid,new V(a));var o=this.data.aid,s=new Un(i.atoms.get(o));s.component=t.connectedComponents.add(new F([o])),t.atoms.set(o,s),t.markAtom(o,1),i.atomSetPos(o,new D(r));var l=i.rxnArrows.get(0);l&&(i.atoms.get(o).rxnFragmentType=i.defineRxnFragmentTypeForAtomset(new F([o]),l.pos[0].x))}},{key:"invert",value:function(){var t=new qr;return t.data=this.data,t}}]),n}(Ur),qr=function(t){(0,l.Z)(n,t);var e=Wr(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Vr.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 Yr;return t.data=this.data,t}}]),n}(Ur);function $r(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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}!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,u.Z)(e);if(n){var i=(0,u.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,Vr.BOND_ATTR,2)).data={bid:t,attribute:e,value:n},i.data2=null,i}(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,Ur.invalidateBond(t,r),"type"===n&&Ur.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}}])}(Ur),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,u.Z)(e);if(n){var i=(0,u.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,Vr.BOND_MOVE,2)).data={bid:t,d:e},n}(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=Q.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}}])}(Ur);var Xr=function(t){(0,l.Z)(n,t);var e=$r(n);function n(t,i,a){var o;return(0,r.Z)(this,n),(o=e.call(this,Vr.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");Ur.invalidateAtom(t,n,1),Ur.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||Y.PATTERN.TYPE.SINGLE,o.begin=n,o.end=i;var s=new Y(o);"number"==typeof this.data.bid?a.bonds.set(this.data.bid,s):this.data.bid=a.bonds.add(s);var l=this.data.bid,c=a.bonds.get(l);a.bondInitHalfBonds(l),a.atomAddNeighbor(c.hb1),a.atomAddNeighbor(c.hb2),t.bonds.set(l,new $n(c)),t.markBond(l,1)}},{key:"invert",value:function(){var t=new Kr;return t.data=this.data,t}}]),n}(Ur),Kr=function(t){(0,l.Z)(n,t);var e=$r(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Vr.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),Ur.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 Xr;return t.data=this.data,t}}]),n}(Ur);function Jr(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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}!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,u.Z)(e);if(n){var i=(0,u.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,Vr.CANVAS_LOAD)).data={struct:t},e}(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}}])}(Ur);var Qr=function(t){(0,l.Z)(n,t);var e=Jr(n);function n(){var t;return(0,r.Z)(this,n),(t=e.call(this,Vr.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 D(i.max.x,i.min.y).add(new D(2,-1));r.forEach((function(r){e.history[r.id]=new D(r.pp),a=a.add(new D(0,.5)),r.pp=a,n.sgroups.set(r.id,r),Ur.invalidateItem(t,"sgroupData",r.id,1)}))}},{key:"invert",value:function(){return new ti(this.history)}}]),n}(Ur),ti=function(t){(0,l.Z)(n,t);var e=Jr(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Vr.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),Ur.invalidateItem(t,"sgroupData",r.id,1)}))}},{key:"invert",value:function(){return new Qr}}]),n}(Ur);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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}!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,u.Z)(e);if(n){var i=(0,u.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,Vr.ENHANCED_FLAG_MOVE)).data={frid:t,p:e},n}(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 D(r.stereoFlagPosition.x,r.stereoFlagPosition.y):J.getDefaultStereoFlagPosition(t.molecule,e),a=D.sum(i,n);r.stereoFlagPosition=a,this.data.p=n.negated(),Ur.invalidateItem(t,"enhancedFlags",e,1)}}},{key:"invert",value:function(){var t=new o;return t.data=this.data,t}}])}(Ur);var ni=function(t){(0,l.Z)(n,t);var e=ei(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,Vr.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 ri(this.rgid_new,this.rgid_old,this.ifThenHistory)}}]),n}(Ur),ri=function(t){(0,l.Z)(n,t);var e=ei(n);function n(t,i,a){var o;return(0,r.Z)(this,n),(o=e.call(this,Vr.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 ni(this.rgid_old,this.rgid_new)}}]),n}(Ur);function ii(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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var ai=function(t){(0,l.Z)(n,t);var e=ii(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Vr.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 J;null===this.frid?this.frid=e.frags.add(n):e.frags.set(this.frid,n),t.frags.set(this.frid,new cr(n)),t.enhancedFlags.set(this.frid,new lr)}},{key:"invert",value:function(){return new oi(this.frid)}}]),n}(Ur),oi=function(t){(0,l.Z)(n,t);var e=ii(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Vr.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)){Ur.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 ai(this.frid)}}]),n}(Ur);function si(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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var li=function(t){(0,l.Z)(n,t);var e=si(n);function n(t,i){var a;return(0,r.Z)(this,n),(a=e.call(this,Vr.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),Ur.invalidateEnhancedFlag(t,r))}},{key:"invert",value:function(){return new ci(this.data.frid,this.data.aid)}}]),n}(Ur),ci=function(t){(0,l.Z)(n,t);var e=si(n);function n(t,i){var a;return(0,r.Z)(this,n),(a=e.call(this,Vr.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),Ur.invalidateEnhancedFlag(t,r))}},{key:"invert",value:function(){var t=this.data,e=t.aid,n=t.frid;return new li(n,e)}}]),n}(Ur);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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}!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,u.Z)(e);if(n){var i=(0,u.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,Vr.FRAGMENT_STEREO_FLAG,6)).frid=t,e}(0,i.Z)(o,[{key:"execute",value:function(t){var e=t.molecule;e.frags.get(this.frid).updateStereoFlag(e),Ur.invalidateEnhancedFlag(t,this.frid)}},{key:"invert",value:function(){return new o(this.frid)}}])}(Ur),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,u.Z)(e);if(n){var i=(0,u.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,Vr.CALC_IMPLICIT_H,10)).atomIds=t,e}(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)}}])}(Ur),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,u.Z)(e);if(n){var i=(0,u.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,Vr.LOOP_MOVE)).data={id:t,d:e},n}(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=Q.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}}])}(Ur),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,u.Z)(e);if(n){var i=(0,u.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,Vr.R_GROUP_ATTR)).data={rgid:t,attribute:e,value:n},i.data2=null,i}(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,Ur.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}}])}(Ur),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,u.Z)(e);if(n){var i=(0,u.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,Vr.R_GROUP_FRAGMENT)).rgid_new=t,i.rg_new=n,i.rgid_old=null,i.rg_old=null,i.frid=e,i}(0,i.Z)(o,[{key:"execute",value:function(t){var e=t.molecule;this.rgid_old=this.rgid_old||ft.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 ft,t.rgroups.set(this.rgid_new,n),e.rgroups.set(this.rgid_new,new hr(n))),n.frags.add(this.frid)}}},{key:"invert",value:function(){return new o(this.rgid_old,this.frid,this.rg_old)}}])}(Ur),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,u.Z)(e);if(n){var i=(0,u.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,Vr.RXN_ARROW_MOVE)).data={id:t,d:e,noinvalidate:n},i}(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(Q.obj2scaled(r,t.render.options)),this.data.d=r.negated(),this.data.noinvalidate||Ur.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}}])}(Ur),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,u.Z)(e);if(n){var i=(0,u.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 l;return(0,r.Z)(this,o),(l=a.call(this,Vr.RXN_ARROW_RESIZE)).data={id:t,d:e,current:n,anchor:i,noinvalidate:s},l}(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,l,c,u,h=a.pos[0].get_xy0(),d=a.pos[1].get_xy0();if(mt.isElliptical(a)){var f=(u=t.rxnArrows.get(n)).getReferencePoints();c=(0,m.Z)(f,3)[2]}if(Zt(o.x)===Zt(a.pos[1].x)&&Zt(o.y)===Zt(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),Zt(o.x)===Zt(a.pos[0].x)&&Zt(o.y)===Zt(a.pos[0].y)&&(a.pos[0].x=o.x=i.x,i.x=h.x,a.pos[0].y=o.y=i.y,i.y=h.y),Zt(o.x)===Zt(null===(s=c)||void 0===s?void 0:s.x)&&Zt(o.y)===Zt(null===(l=c)||void 0===l?void 0:l.y)){var p=u.getArrowParams(a.pos[0].x,a.pos[0].y,a.pos[1].x,a.pos[1].y).angle*Math.PI/180,v=Math.cos(p),g=Math.sin(p),y=i.x-o.x,b=(i.y-o.y)*v-y*g;a.height-=b;var x=u.getReferencePoints(),w=(0,m.Z)(x,3)[2];o.y=w.y,o.x=w.x}}else a.pos[1].add_(r);t.rxnArrows.get(n).visel.translate(Q.obj2scaled(r,t.render.options)),this.data.d=r.negated(),this.data.noinvalidate||Ur.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)}}])}(Ur),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,u.Z)(e);if(n){var i=(0,u.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,Vr.RXN_PLUS_MOVE)).data={id:t,d:e,noinvalidate:n},i}(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=Q.obj2scaled(r,t.render.options);a.visel.translate(o),this.data.d=r.negated(),i||Ur.invalidateItem(t,"rxnPluses",n,1)}},{key:"invert",value:function(){var t=new o;return t.data=this.data,t}}])}(Ur);var hi=function(t){(0,l.Z)(n,t);var e=ui(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Vr.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 vt;"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 gr(o)),e.rxnPlusSetPos(a,new D(i)),Ur.invalidateItem(t,"rxnPluses",a,1)}},{key:"invert",value:function(){var t=new di;return t.data=this.data,t}}]),n}(Ur),di=function(t){(0,l.Z)(n,t);var e=ui(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Vr.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 hi;return t.data=this.data,t}}]),n}(Ur);function fi(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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var pi=function(t){(0,l.Z)(n,t);var e=fi(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]:lt.OpenAngle,o=arguments.length>2?arguments[2]:void 0;return(0,r.Z)(this,n),(t=e.call(this,Vr.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 mt({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 mr(n));var a=(0,d.Z)(this.data.pos);e.rxnArrowSetPos(i,a.map((function(t){return new D(t)}))),Ur.invalidateItem(t,"rxnArrows",i,1)}},{key:"invert",value:function(){return new mi(this.data.id)}}]),n}(Ur),mi=function(t){(0,l.Z)(n,t);var e=fi(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Vr.RXN_ARROW_DELETE)).data={id:t,pos:[],mode:lt.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 pi(this.data.pos,this.data.mode,this.data.id)}}]),n}(Ur);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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var gi=function(t){(0,l.Z)(n,t);var e=vi(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]:pt.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,Vr.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 yt({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 Ar(n));var a=(0,d.Z)(this.data.pos);this.data.toCircle&&(a[1]=xi(a[0],a[1])),e.simpleObjectSetPos(i,a.map((function(t){return new D(t)}))),Ur.invalidateItem(t,"simpleObjects",i,1)}},{key:"invert",value:function(){return new yi(this.data.id)}}]),n}(Ur),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,Vr.SIMPLE_OBJECT_DELETE)).data={id:t,pos:[],mode:pt.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 gi(this.data.pos,this.data.mode,this.data.toCircle,this.data.id)}}]),n}(Ur);function bi(t,e,n){var r=t.pos[0].get_xy0(),i=t.pos[1].get_xy0();Zt(e.x)===Zt(t.pos[1].x)&&(t.pos[1].x=e.x=n.x,n.x=i.x),Zt(e.y)===Zt(t.pos[1].y)&&(t.pos[1].y=e.y=n.y,n.y=i.y),Zt(e.x)===Zt(t.pos[0].x)&&(t.pos[0].x=e.x=n.x,n.x=r.x),Zt(e.y)===Zt(t.pos[0].y)&&(t.pos[0].y=e.y=n.y,n.y=r.y)}function xi(t,e){var n=D.diff(e,t),r=Math.abs(n.x)<Math.abs(n.y)?n.x:n.y;return new D(t.x+(n.x>0?1:-1)*Math.abs(r),t.y+(n.y>0?1:-1)*Math.abs(r),0)}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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}!function(t){(0,l.Z)(n,t);var e=vi(n);function n(t,i,a){var o;return(0,r.Z)(this,n),(o=e.call(this,Vr.SIMPLE_OBJECT_MOVE)).data={id:t,d:i,noinvalidate:a},o}(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(Q.obj2scaled(r,t.render.options)),this.data.d=r.negated(),this.data.noinvalidate||Ur.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}}])}(Ur),function(t){(0,l.Z)(n,t);var e=vi(n);function n(t,i,a,o,s,l){var c;return(0,r.Z)(this,n),(c=e.call(this,Vr.SIMPLE_OBJECT_RESIZE)).data={id:t,d:i,current:a,anchor:o,noinvalidate:s,toCircle:l},c}(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===pt.ellipse)if(o)bi(a,o,i);else if(this.data.toCircle){var s=a.pos[1].get_xy0(),l=xi(a.pos[0],i);a.pos[1].x=l.x,a.pos[1].y=l.y,this.data.current=s}else{var c=a.pos[1].get_xy0();a.pos[1].x=i.x,a.pos[1].y=i.y,this.data.current=c}else if(a.mode===pt.line&&o){var u=a.pos[0].get_xy0(),h=a.pos[1].get_xy0();Zt(o.x)===Zt(a.pos[1].x)&&Zt(o.y)===Zt(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),Zt(o.x)===Zt(a.pos[0].x)&&Zt(o.y)===Zt(a.pos[0].y)&&(a.pos[0].x=o.x=i.x,i.x=u.x,a.pos[0].y=o.y=i.y,i.y=u.y)}else a.mode===pt.rectangle&&o?bi(a,o,i):a.pos[1].add_(r);t.simpleObjects.get(n).visel.translate(Q.obj2scaled(r,t.render.options)),this.data.d=r.negated(),this.data.noinvalidate||Ur.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)}}])}(Ur);var 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,Vr.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),Ur.invalidateAtom(t,n)}},{key:"invert",value:function(){var t=new Si;return t.data=this.data,t}}]),n}(Ur),Si=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,Vr.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);it.removeAtom(o,n),a.sgs.delete(r),Ur.invalidateAtom(t,n)}},{key:"invert",value:function(){var t=new Ei;return t.data=this.data,t}}]),n}(Ur);function Ri(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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}!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,u.Z)(e);if(n){var i=(0,u.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,Vr.S_GROUP_ATTR,4)).data={sgid:t,attr:e,value:n},i}(0,i.Z)(o,[{key:"execute",value:function(t){var e=t.molecule,n=this.data.sgid,r=e.sgroups.get(n),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}}])}(Ur),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,u.Z)(e);if(n){var i=(0,u.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,Vr.S_GROUP_DATA_MOVE)).data={id:t,d:e},n}(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(),Ur.invalidateItem(t,"sgroupData",i,1)}},{key:"invert",value:function(){var t=new o;return t.data=this.data,t}}])}(Ur);var Ai=function(t){(0,l.Z)(n,t);var e=Ri(n);function n(t,i,a){var o;return(0,r.Z)(this,n),(o=e.call(this,Vr.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 Oi;return t.data=this.data,t}}]),n}(Ur),Oi=function(t){(0,l.Z)(n,t);var e=Ri(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Vr.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 Ai;return t.data=this.data,t}}]),n}(Ur);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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var ki=function(t){(0,l.Z)(n,t);var e=Pi(n);function n(t,i,a,o,s){var l;return(0,r.Z)(this,n),(l=e.call(this,Vr.S_GROUP_CREATE)).data={sgid:t,type:i,pp:a,expanded:o,name:s},l}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=new it(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 D(a)),o&&(n.data.expanded=o),s&&(n.data.name=s),t.sgroups.set(i,new xr(e.sgroups.get(i))),ut.isFunctionalGroup(n)&&t.molecule.functionalGroups.add(new ut(n)),this.data.sgid=i}},{key:"invert",value:function(){var t=new Ti;return t.data=this.data,t}}]),n}(Ur),Ti=function(t){(0,l.Z)(n,t);var e=Pi(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Vr.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;ut.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 ki;return t.data=this.data,t}}]),n}(Ur);function Bi(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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}var Zi=function(t){(0,l.Z)(n,t);var e=Bi(n);function n(t,i,a,o){var s;return(0,r.Z)(this,n),(s=e.call(this,Vr.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 Ot(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 Zr(e)),t.molecule.textSetPosition(r,new D(this.data.position)),Ur.invalidateItem(t,"texts",r,1)}},{key:"invert",value:function(){return new Ci(this.data.id)}}]),n}(Ur),Ci=function(t){(0,l.Z)(n,t);var e=Bi(n);function n(t){var i;return(0,r.Z)(this,n),(i=e.call(this,Vr.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 Zi(this.data.content,this.data.position,this.data.pos,this.data.id)}}]),n}(Ur);function Mi(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,u.Z)(t);if(e){var i=(0,u.Z)(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return(0,c.Z)(this,n)}}!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,u.Z)(e);if(n){var i=(0,u.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,Vr.TEXT_UPDATE)).data={id:t,content:e},n}(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),Ur.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}}])}(Ur),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,u.Z)(e);if(n){var i=(0,u.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,Vr.TEXT_MOVE)).data={id:t,d:e,noinvalidate:n},i}(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(Q.obj2scaled(a,t.render.options)),this.data.d=a.negated(),this.data.noinvalidate||Ur.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}}])}(Ur),function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];(0,r.Z)(this,t),this.operations=e}(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,d.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)}))}}])}(),Y.PATTERN.TYPE.SINGLE,Y.PATTERN.TYPE.DOUBLE,Y.PATTERN.TYPE.TRIPLE;var Li=function(t){(0,l.Z)(n,t);var e=Mi(n);function n(t,i,a,o){var s;return(0,r.Z)(this,n),(s=e.call(this,Vr.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 Pt({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),Ni(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 Ii(i,e,n,r)}}]),n}(Ur),Ii=function(t){(0,l.Z)(n,t);var e=Mi(n);function n(t,i,a,o){var s;return(0,r.Z)(this,n),(s=e.call(this,Vr.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),Ni(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 Li(e,n,r,i);return a.data=this.data,a}}]),n}(Ur);function Ni(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 Di(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(t){(0,l.Z)(n,t);var e=Mi(n);function n(t,i,a,o){var s;return(0,r.Z)(this,n),(s=e.call(this,Vr.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,u=s.color;this.oldData={atoms:l,bonds:c,color:u,highlightId:a};var h=new Pt({atoms:n,bonds:r,color:i});o.highlights.set(this.newData.highlightId,h),Ni(t,[].concat((0,d.Z)(n),(0,d.Z)(l)),[].concat((0,d.Z)(r),(0,d.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)}}])}(Ur),Gr.fracAngle;var _i=["radicals","pseudoatoms","stereo","query","overlapping_atoms","overlapping_bonds","rgroups","chiral","3d"],ji=["molecular-weight","most-abundant-mass","monoisotopic-mass","gross","mass-composition"];function Gi(t,e){if("string"!=typeof t){var n=new Map,r=t.clone(null,null,!1,n);return e.serialize(r)}return t}var Fi,zi=new WeakMap,Hi=new WeakMap,Ui=function(){function t(e){(0,r.Z)(this,t),Di(this,zi,{writable:!0,value:void 0}),Di(this,Hi,{writable:!0,value:void 0}),(0,f.Z)(this,zi,e),(0,f.Z)(this,Hi,new Vt)}return(0,i.Z)(t,[{key:"info",value:function(){return(0,p.Z)(this,zi).info()}},{key:"convert",value:function(t,e){var n=(null==e?void 0:e.outputFormat)||tn.KET;return(0,p.Z)(this,zi).convert({struct:Gi(t,(0,p.Z)(this,Hi)),output_format:n})}},{key:"layout",value:function(t){var e=this;return(0,p.Z)(this,zi).layout({struct:Gi(t,(0,p.Z)(this,Hi)),output_format:tn.KET}).then((function(t){return(0,p.Z)(e,Hi).deserialize(t.struct)}))}},{key:"clean",value:function(t){var e=this;return(0,p.Z)(this,zi).clean({struct:Gi(t,(0,p.Z)(this,Hi)),output_format:tn.KET}).then((function(t){return(0,p.Z)(e,Hi).deserialize(t.struct)}))}},{key:"aromatize",value:function(t){var e=this;return(0,p.Z)(this,zi).aromatize({struct:Gi(t,(0,p.Z)(this,Hi)),output_format:tn.KET}).then((function(t){return(0,p.Z)(e,Hi).deserialize(t.struct)}))}},{key:"dearomatize",value:function(t){var e=this;return(0,p.Z)(this,zi).dearomatize({struct:Gi(t,(0,p.Z)(this,Hi)),output_format:tn.KET}).then((function(t){return(0,p.Z)(e,Hi).deserialize(t.struct)}))}},{key:"calculateCip",value:function(t){var e=this;return(0,p.Z)(this,zi).calculateCip({struct:Gi(t,(0,p.Z)(this,Hi)),output_format:tn.KET}).then((function(t){return(0,p.Z)(e,Hi).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,zi).automap({struct:Gi(t,(0,p.Z)(this,Hi)),output_format:tn.KET,mode:r}).then((function(t){return(0,p.Z)(n,Hi).deserialize(t.struct)}))}},{key:"check",value:function(t,e){var n=(null==e?void 0:e.types)||_i;return(0,p.Z)(this,zi).check({struct:Gi(t,(0,p.Z)(this,Hi)),types:n})}},{key:"calculate",value:function(t,e){var n=(null==e?void 0:e.properties)||ji;return(0,p.Z)(this,zi).calculate({struct:Gi(t,(0,p.Z)(this,Hi)),properties:n})}},{key:"recognize",value:function(t,e){var n=this,r=(null==e?void 0:e.version)||"";return(0,p.Z)(this,zi).recognize(t,r).then((function(t){return(0,p.Z)(n,Hi).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,zi).generateImageAsBase64(Gi(t,(0,p.Z)(this,Hi)),{outputFormat:n,backgroundColor:r})}}]),t}(),Vi="object"==typeof Reflect?Reflect:null,Wi=Vi&&"function"==typeof Vi.apply?Vi.apply:function(t,e,n){return Function.prototype.apply.call(t,e,n)};Fi=Vi&&"function"==typeof Vi.ownKeys?Vi.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var Yi=Number.isNaN||function(t){return t!=t};function qi(){qi.init.call(this)}var $i=qi;qi.EventEmitter=qi,qi.prototype._events=void 0,qi.prototype._eventsCount=0,qi.prototype._maxListeners=void 0;var Xi=10;function Ki(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function Ji(t){return void 0===t._maxListeners?qi.defaultMaxListeners:t._maxListeners}function Qi(t,e,n,r){var i,a,o,s;if(Ki(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=Ji(t))>0&&o.length>i&&!o.warned){o.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=t,l.type=e,l.count=o.length,s=l,console&&console.warn&&console.warn(s)}return t}function ta(){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 ea(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=ta.bind(r);return i.listener=n,r.wrapFn=i,i}function na(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):ia(i,i.length)}function ra(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 ia(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function aa(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 oa(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 sa(t,e,n){return la.apply(this,arguments)}function la(){return(la=(0,x.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,ca(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 ca(t,e,n){var r=function(t){var e=t.trim();try{if(JSON.parse(e))return on.ket}catch(t){}if(-1!==e.indexOf("$RXN"))return on.rxn;if(-1!==e.indexOf("V2000"))return on.mol;if(-1!==e.indexOf("V3000"))return on.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 on.mol}if("<"===e[0]&&-1!==e.indexOf("<molecule"))return on.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")?on.cdx:"InChI"===e.slice(0,5)?on.inChI:-1===e.indexOf("\n")?on.smiles:-1!==e.indexOf("<CDXML")?on.cdxml:on.unknown}(t),i=new Zn(e),a=n.editor.options();return i.create(r,{"dearomatize-on-load":a["dearomatize-on-load"]}).getStructureFromStringAsync(t)}function ua(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:on.rxn,e=arguments.length>2?arguments[2]:void 0;return(arguments.length>1?arguments[1]:void 0).create(t).getStructureFromStructAsync(e)}Object.defineProperty(qi,"defaultMaxListeners",{enumerable:!0,get:function(){return Xi},set:function(t){if("number"!=typeof t||t<0||Yi(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Xi=t}}),qi.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},qi.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||Yi(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},qi.prototype.getMaxListeners=function(){return Ji(this)},qi.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)Wi(s,this,e);else{var l=s.length,c=ia(s,l);for(n=0;n<l;++n)Wi(c[n],this,e)}return!0},qi.prototype.addListener=function(t,e){return Qi(this,t,e,!1)},qi.prototype.on=qi.prototype.addListener,qi.prototype.prependListener=function(t,e){return Qi(this,t,e,!0)},qi.prototype.once=function(t,e){return Ki(e),this.on(t,ea(this,t,e)),this},qi.prototype.prependOnceListener=function(t,e){return Ki(e),this.prependListener(t,ea(this,t,e)),this},qi.prototype.removeListener=function(t,e){var n,r,i,a,o;if(Ki(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},qi.prototype.off=qi.prototype.removeListener,qi.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},qi.prototype.listeners=function(t){return na(this,t,!0)},qi.prototype.rawListeners=function(t){return na(this,t,!1)},qi.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):ra.call(t,e)},qi.prototype.listenerCount=ra,qi.prototype.eventNames=function(){return this._eventsCount>0?Fi(this._events):[]},$i.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))}aa(t,e,a,{once:!0}),"error"!==e&&function(t,e,n){"function"==typeof t.on&&aa(t,"error",e,{once:!0})}(t,i)}))};var ha=new WeakMap,da=new WeakMap,fa=new WeakMap,pa=new WeakMap,ma=new WeakMap,va=function(){function t(e,n,i){(0,r.Z)(this,t),oa(this,ha,{writable:!0,value:void 0}),oa(this,da,{writable:!0,value:void 0}),oa(this,fa,{writable:!0,value:void 0}),oa(this,pa,{writable:!0,value:void 0}),oa(this,ma,{writable:!0,value:void 0}),s()(null!=e),s()(null!=n),s()(null!=i),(0,f.Z)(this,fa,e),(0,f.Z)(this,ha,n),(0,f.Z)(this,da,i),(0,f.Z)(this,pa,new Ui((0,p.Z)(this,ha))),(0,f.Z)(this,ma,new $i.EventEmitter)}var e,n,a,o,l,c,u;return(0,i.Z)(t,[{key:"editor",get:function(){return(0,p.Z)(this,fa)}},{key:"eventBus",get:function(){return(0,p.Z)(this,ma)}},{key:"indigo",get:function(){return(0,p.Z)(this,pa)}},{key:"settings",get:function(){var t=(0,p.Z)(this,fa).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,fa).setOptions(JSON.stringify(e))}},{key:"getSmiles",value:function(){return ua(arguments.length>0&&void 0!==arguments[0]&&arguments[0]?on.smilesExt:on.smiles,(0,p.Z)(this,da),this.editor.struct())}},{key:"getMolfile",value:(u=(0,x.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?on.molV3000:on.mol,r=e?n:on.molAuto,t.next=6,ua(r,(0,p.Z)(this,da),(0,p.Z)(this,fa).struct());case 6:return i=t.sent,t.abrupt("return",i);case 8:case"end":return t.stop()}}),t,this)}))),function(t){return u.apply(this,arguments)})},{key:"getRxn",value:(c=(0,x.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?on.rxnV3000:on.rxn,t.next=6,ua(n,(0,p.Z)(this,da),(0,p.Z)(this,fa).struct());case 6:return r=t.sent,t.abrupt("return",r);case 8:case"end":return t.stop()}}),t,this)}))),function(){return c.apply(this,arguments)})},{key:"getKet",value:function(){return ua(on.ket,(0,p.Z)(this,da),(0,p.Z)(this,fa).struct())}},{key:"getSmarts",value:function(){return ua(on.smarts,(0,p.Z)(this,da),(0,p.Z)(this,fa).struct())}},{key:"getCml",value:function(){return ua(on.cml,(0,p.Z)(this,da),(0,p.Z)(this,fa).struct())}},{key:"getInchi",value:function(){return ua(arguments.length>0&&void 0!==arguments[0]&&arguments[0]?on.inChIAuxInfo:on.inChI,(0,p.Z)(this,da),(0,p.Z)(this,fa).struct())}},{key:"generateInchIKey",value:(l=(0,x.Z)(E().mark((function t(){var e;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,ua(on.ket,(0,p.Z)(this,da),(0,p.Z)(this,fa).struct());case 2:return e=t.sent,t.abrupt("return",(0,p.Z)(this,ha).generateInchIKey(e));case 4:case"end":return t.stop()}}),t,this)}))),function(){return l.apply(this,arguments)})},{key:"containsReaction",value:function(){return this.editor.struct().hasRxnArrow()}},{key:"setMolecule",value:(o=(0,x.Z)(E().mark((function t(e){var n=this;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:Mt((0,x.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,sa(e,(0,p.Z)(n,ha),n);case 3:r=t.sent,(0,p.Z)(n,fa).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,x.Z)(E().mark((function t(e){var n=this;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:Mt((0,x.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,sa(e,(0,p.Z)(n,ha),n);case 3:r=t.sent,(0,p.Z)(n,fa).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,x.Z)(E().mark((function t(){var e=this;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:Mt((0,x.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,pa).layout((0,p.Z)(e,fa).struct());case 2:n=t.sent,r=new Vt,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,pa).recognize(t,{version:e})}},{key:"generateImage",value:(e=(0,x.Z)(E().mark((function t(e){var n,r,i,a,o,s,l,c,u=arguments;return E().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:n=u.length>1&&void 0!==u[1]?u[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,ha).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 l=new Uint8Array(o),c=new Blob([l],{type:r}),t.abrupt("return",c);case 18:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})}]),t}();function ga(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 ya(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ga(Object(n),!0).forEach((function(e){(0,a.Z)(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ga(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var ba={"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},xa=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=xa),n.set(e,i)}),[{key:"withStructServiceProvider",value:function(t){return(0,f.Z)(this,xa,t),this}},{key:"build",value:function(t,e){s()(null!=t),s()(null!=(0,p.Z)(this,xa));var n=ya(ya({},ba),e),r=(0,p.Z)(this,xa).createStructService(n),i=new va(t,r,new Zn(r));return i[(0,p.Z)(this,xa).mode]=!0,i}}])}}]);