aldehyde 0.2.100 → 0.2.102

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 (128) hide show
  1. package/lib/controls/action/index.d.ts.map +1 -1
  2. package/lib/controls/action/index.js +6 -5
  3. package/lib/controls/action/index.js.map +1 -1
  4. package/lib/controls/file-view/index.d.ts.map +1 -1
  5. package/lib/controls/file-view/index.js +2 -1
  6. package/lib/controls/file-view/index.js.map +1 -1
  7. package/lib/controls/rfield/index.d.ts +1 -0
  8. package/lib/controls/rfield/index.d.ts.map +1 -1
  9. package/lib/controls/rfield/index.js +16 -2
  10. package/lib/controls/rfield/index.js.map +1 -1
  11. package/{src/aldehyde/layout/menu/block.less → lib/layout/menu/block.css} +1 -1
  12. package/lib/layout/menu/block.d.ts +1 -1
  13. package/lib/layout/menu/block.d.ts.map +1 -1
  14. package/lib/layout/menu/block.js +1 -1
  15. package/lib/layout/menu/block.js.map +1 -1
  16. package/lib/tree/tmpl-tree.d.ts.map +1 -1
  17. package/lib/tree/tmpl-tree.js +23 -8
  18. package/lib/tree/tmpl-tree.js.map +1 -1
  19. package/package.json +1 -1
  20. package/src/aldehyde/controls/file-view/index.tsx +3 -1
  21. package/src/aldehyde/controls/rfield/index.tsx +19 -3
  22. package/src/aldehyde/layout/menu/block.css +11 -0
  23. package/src/aldehyde/layout/menu/block.tsx +1 -1
  24. package/dist/bundle.021f784b1c84781461d2.js +0 -1
  25. package/dist/bundle.03c542ca824e205fe307.js +0 -2
  26. package/dist/bundle.03c542ca824e205fe307.js.LICENSE.txt +0 -27
  27. package/dist/bundle.03c542ca824e205fe307.js.gz +0 -0
  28. package/dist/bundle.15cb660c34802f6cccf5.js +0 -1
  29. package/dist/bundle.15cb660c34802f6cccf5.js.gz +0 -0
  30. package/dist/bundle.2f9c2d692fe0277a37aa.js +0 -2
  31. package/dist/bundle.2f9c2d692fe0277a37aa.js.LICENSE.txt +0 -1
  32. package/dist/bundle.2f9c2d692fe0277a37aa.js.gz +0 -0
  33. package/dist/bundle.320c02187dd135005102.js +0 -2
  34. package/dist/bundle.320c02187dd135005102.js.LICENSE.txt +0 -6
  35. package/dist/bundle.320c02187dd135005102.js.gz +0 -0
  36. package/dist/bundle.35a4af7e2d0da1942d79.js +0 -10
  37. package/dist/bundle.35a4af7e2d0da1942d79.js.gz +0 -0
  38. package/dist/bundle.3f9072b1629cdb384b46.js +0 -2
  39. package/dist/bundle.3f9072b1629cdb384b46.js.LICENSE.txt +0 -5
  40. package/dist/bundle.3f9072b1629cdb384b46.js.gz +0 -0
  41. package/dist/bundle.46e2295b5360a725bcd5.js +0 -1
  42. package/dist/bundle.46e2295b5360a725bcd5.js.gz +0 -0
  43. package/dist/bundle.4c3c988531c3cf360b87.js +0 -1
  44. package/dist/bundle.4c3c988531c3cf360b87.js.gz +0 -0
  45. package/dist/bundle.4df89546fd2e9d665dfb.js +0 -2
  46. package/dist/bundle.4df89546fd2e9d665dfb.js.LICENSE.txt +0 -5
  47. package/dist/bundle.4df89546fd2e9d665dfb.js.gz +0 -0
  48. package/dist/bundle.5a9afb9ee6cceca506fa.js +0 -5
  49. package/dist/bundle.5a9afb9ee6cceca506fa.js.LICENSE.txt +0 -10
  50. package/dist/bundle.5a9afb9ee6cceca506fa.js.gz +0 -0
  51. package/dist/bundle.5e6cccd06b34a0e3a2ff.js +0 -1
  52. package/dist/bundle.5e6cccd06b34a0e3a2ff.js.gz +0 -0
  53. package/dist/bundle.62c62e6aaa7f3c20761e.js +0 -2
  54. package/dist/bundle.62c62e6aaa7f3c20761e.js.LICENSE.txt +0 -17
  55. package/dist/bundle.62c62e6aaa7f3c20761e.js.gz +0 -0
  56. package/dist/bundle.6fd2dadd29083268c5a6.js +0 -2
  57. package/dist/bundle.6fd2dadd29083268c5a6.js.LICENSE.txt +0 -17
  58. package/dist/bundle.6fd2dadd29083268c5a6.js.gz +0 -0
  59. package/dist/bundle.8241d8d05e35988dd480.js +0 -1
  60. package/dist/bundle.8241d8d05e35988dd480.js.gz +0 -0
  61. package/dist/bundle.829683dfa6a98c78c58e.js +0 -2
  62. package/dist/bundle.829683dfa6a98c78c58e.js.LICENSE.txt +0 -14
  63. package/dist/bundle.829683dfa6a98c78c58e.js.gz +0 -0
  64. package/dist/bundle.840e28984e710e12f467.js +0 -75
  65. package/dist/bundle.840e28984e710e12f467.js.LICENSE.txt +0 -8
  66. package/dist/bundle.840e28984e710e12f467.js.gz +0 -0
  67. package/dist/bundle.85ce5221fe6ab1d91f7d.js +0 -2
  68. package/dist/bundle.85ce5221fe6ab1d91f7d.js.LICENSE.txt +0 -1
  69. package/dist/bundle.85ce5221fe6ab1d91f7d.js.gz +0 -0
  70. package/dist/bundle.9cfd99a04bde7f781c30.js +0 -1
  71. package/dist/bundle.9cfd99a04bde7f781c30.js.gz +0 -0
  72. package/dist/bundle.a049dc8814bbbf59160f.js +0 -1
  73. package/dist/bundle.a049dc8814bbbf59160f.js.gz +0 -0
  74. package/dist/bundle.a94f7811fac19aa9d6a3.js +0 -2
  75. package/dist/bundle.a94f7811fac19aa9d6a3.js.LICENSE.txt +0 -1
  76. package/dist/bundle.a94f7811fac19aa9d6a3.js.gz +0 -0
  77. package/dist/bundle.abdde6e82ee9f60d1bf3.js +0 -2
  78. package/dist/bundle.abdde6e82ee9f60d1bf3.js.LICENSE.txt +0 -30
  79. package/dist/bundle.abdde6e82ee9f60d1bf3.js.gz +0 -0
  80. package/dist/bundle.b207a66d5902f39d0c5a.js +0 -1
  81. package/dist/bundle.b207a66d5902f39d0c5a.js.gz +0 -0
  82. package/dist/bundle.b7b86a025aa95dea0e19.js +0 -2
  83. package/dist/bundle.b7b86a025aa95dea0e19.js.LICENSE.txt +0 -8
  84. package/dist/bundle.b7b86a025aa95dea0e19.js.gz +0 -0
  85. package/dist/bundle.b7e3eb480b649b3de67b.js +0 -2
  86. package/dist/bundle.b7e3eb480b649b3de67b.js.LICENSE.txt +0 -5
  87. package/dist/bundle.b7e3eb480b649b3de67b.js.gz +0 -0
  88. package/dist/bundle.c1c6028fd703ebf78c2e.js +0 -2
  89. package/dist/bundle.c1c6028fd703ebf78c2e.js.LICENSE.txt +0 -5
  90. package/dist/bundle.c1c6028fd703ebf78c2e.js.gz +0 -0
  91. package/dist/bundle.cd10ae07e0e0c36d0dee.js +0 -2
  92. package/dist/bundle.cd10ae07e0e0c36d0dee.js.LICENSE.txt +0 -22
  93. package/dist/bundle.cd10ae07e0e0c36d0dee.js.gz +0 -0
  94. package/dist/bundle.cf6a1933769c2aee4e6e.js +0 -1
  95. package/dist/bundle.cf6a1933769c2aee4e6e.js.gz +0 -0
  96. package/dist/bundle.d158d417d1d7a8acb2a1.js +0 -1
  97. package/dist/bundle.d158d417d1d7a8acb2a1.js.gz +0 -0
  98. package/dist/bundle.db40aa107272f4303ece.js +0 -1
  99. package/dist/bundle.db40aa107272f4303ece.js.gz +0 -0
  100. package/dist/bundle.ddefe6d8f235ef95d470.js +0 -1
  101. package/dist/bundle.ddefe6d8f235ef95d470.js.gz +0 -0
  102. package/dist/bundle.e02a7a16b4a6b3bb412f.js +0 -2
  103. package/dist/bundle.e02a7a16b4a6b3bb412f.js.LICENSE.txt +0 -16
  104. package/dist/bundle.e02a7a16b4a6b3bb412f.js.gz +0 -0
  105. package/dist/bundle.e760a70171cf0ae4567b.js +0 -1
  106. package/dist/bundle.e760a70171cf0ae4567b.js.gz +0 -0
  107. package/dist/bundle.f3ce062a620fe456c152.js +0 -1
  108. package/dist/bundle.f6e1c4fda58154810fe2.js +0 -2
  109. package/dist/bundle.f6e1c4fda58154810fe2.js.LICENSE.txt +0 -41
  110. package/dist/bundle.f6e1c4fda58154810fe2.js.gz +0 -0
  111. package/dist/bundle.fe9c09b8ace9c3117b0a.js +0 -1
  112. package/dist/bundle.fe9c09b8ace9c3117b0a.js.gz +0 -0
  113. package/dist/bundle.feaa17bec2057a4ee54f.js +0 -1
  114. package/dist/bundle.feaa17bec2057a4ee54f.js.gz +0 -0
  115. package/dist/css/chemstruc-graph-6437e59640f8b99b774f.css +0 -12
  116. package/dist/css/chemstruc-graph-6437e59640f8b99b774f.css.gz +0 -0
  117. package/dist/css/common-901df6b21f13391f2a53.css +0 -56
  118. package/dist/css/html-editor-draft-5e8e152675ab7d201c00.css +0 -886
  119. package/dist/css/html-editor-draft-5e8e152675ab7d201c00.css.gz +0 -0
  120. package/dist/css/main-f3c8fdebab315e61e7be.css +0 -865
  121. package/dist/css/main-f3c8fdebab315e61e7be.css.gz +0 -0
  122. package/dist/images/development-30de07a0.png +0 -0
  123. package/dist/images/logo-54b328b7.png +0 -0
  124. package/dist/images/pain-point-8f02421e.png +0 -0
  125. package/dist/images/target-13a5b4b9.png +0 -0
  126. package/dist/images/time-cost-cb40d2c2.png +0 -0
  127. package/dist/images/time-prograss-44b86b36.png +0 -0
  128. package/dist/index.html +0 -4
@@ -1 +0,0 @@
1
- "use strict";(self.webpackChunkaldehyde=self.webpackChunkaldehyde||[]).push([[469],{19469:function(e,t,n){n.d(t,{$71:function(){return wc},$yr:function(){return q},AP3:function(){return et},AjN:function(){return gu},AnZ:function(){return Tf},BBJ:function(){return Vu},BTd:function(){return H},Bdo:function(){return Pm},Bmp:function(){return $m},CHV:function(){return Nm},CTK:function(){return Ut},CtW:function(){return fi},DOc:function(){return sp},Da0:function(){return mu},DiP:function(){return at},DoR:function(){return Xc},E0U:function(){return me},ERw:function(){return z},Egz:function(){return ve},FE9:function(){return Ze},FK:function(){return Ke},FQl:function(){return gm},GCY:function(){return ip},GCv:function(){return tm},GzZ:function(){return _f},Haq:function(){return F},IaQ:function(){return $a},J$M:function(){return id},JAY:function(){return ke},K65:function(){return xm},KW0:function(){return xc},KYj:function(){return ti},LZj:function(){return sm},M9T:function(){return Pf},MxE:function(){return Ae},Nsb:function(){return Ti},OD2:function(){return um},ONT:function(){return ee},PgD:function(){return qt},Q7z:function(){return Mf},RBE:function(){return rp},RP_:function(){return Df},Raq:function(){return Us},Rtt:function(){return gt},S5n:function(){return qc},S6r:function(){return Rs},S8X:function(){return _},TQv:function(){return ut},TTf:function(){return kf},Td8:function(){return em},U7V:function(){return ym},UFo:function(){return yu},Vc5:function(){return _a},Vku:function(){return X},Vru:function(){return te},Vx2:function(){return Pt},WRG:function(){return lm},XHR:function(){return Re},XXz:function(){return Tm},X_E:function(){return bf},Xc$:function(){return Km},ZY9:function(){return we},_6U:function(){return Zm},_Vd:function(){return It},_c2:function(){return Bm},_kM:function(){return Yt},c0S:function(){return bm},cf:function(){return $p},dRT:function(){return hi},dfg:function(){return Ym},dkG:function(){return fe},dw_:function(){return xs},e51:function(){return Fm},eem:function(){return Hm},epf:function(){return qm},f8e:function(){return Ue},fKH:function(){return Tt},fMh:function(){return xi},fkd:function(){return Lf},gXN:function(){return $},gcH:function(){return Rm},gnl:function(){return At},gnt:function(){return We},hHf:function(){return Hf},i0C:function(){return W},iEz:function(){return $f},i_A:function(){return rn},iaA:function(){return Qm},jH:function(){return ht},jQc:function(){return nm},jkc:function(){return jm},k0_:function(){return N},knP:function(){return hp},ll9:function(){return Gf},lpJ:function(){return km},mvq:function(){return Pi},n4Z:function(){return zl},nKs:function(){return vm},nfW:function(){return Cm},nwr:function(){return Ec},oJU:function(){return Jl},qEu:function(){return Rf},qHi:function(){return K},qd$:function(){return Pc},qmz:function(){return Mm},rL0:function(){return vu},rcZ:function(){return Im},rcl:function(){return df},s60:function(){return ye},sxq:function(){return Om},szz:function(){return Fe},t1S:function(){return Xf},uVT:function(){return Lm},vR$:function(){return pm},vfB:function(){return Je},w8P:function(){return mm},w8U:function(){return en},wI5:function(){return hu},wbU:function(){return wm},xRM:function(){return Zf},xhd:function(){return ni},zkf:function(){return Wp}});var o=n(60436),r=n(5544),i=n(23029),a=n(92901),s=n(56822),u=n(53954),l=n(9417),c=n(85501),d=n(64467),h=n(94148),f=n.n(h),m=n(10467),p=n(54756),v=n.n(p),g=n(82284),y=n(10159),b=n(73437),A=n(53167),w=n(64137),E=n(90991),P=n(65225),x=n(2543),S=n.n(x),O=n(85261),k=n.n(O),M=n(23230),R=n.n(M),T=n(44480),B=n(80045),C=n(9686),I=n.n(C),N={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"},D=[{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}],L=D.reduce((function(e,t){return e.set(t.label,t),e.set(t.number,t),e}),new Map),_={get:function(e){return L.get(e)},filter:function(e){return D.filter(e)},getAll:function(){return[].concat(D)}},F={"atoms-gen":{title:"Atom Generics",itemSets:[{displayName:"any atom",items:[{label:"A",description:"Any atom except hydrogen"},{label:"AH",description:"Any atom, including hydrogen"}]},{displayName:"except C or H",items:[{label:"Q",description:"Any heteroatom (any atom except C or H)"},{label:"QH",description:"Any atom except C"}]},{displayName:"any metal",items:[{label:"M",description:"Any metal"},{label:"MH",description:"Any metal or hydrogen"}]},{displayName:"any halogen",items:[{label:"X",description:"Any halogen"},{label:"XH",description:"Any halogen or hydrogen"}]}]},"special-nodes":{title:"Special Nodes",itemSets:[{items:[{label:"H+",description:"Proton"},{label:"D",description:"Deuterium"},{label:"T",description:"Tritium"},{label:"R",description:"Pseudoatom"},{label:"Pol",description:"Polymer Bead"}]}]},"group-gen":{title:"Group Generics",itemSets:[{items:[{label:"G",description:"Any group"},{label:"GH",description:"Any group or hydrogen"}]},{items:[{label:"G*",description:"Any group with a ring closure"},{label:"GH*",description:"Any group with a ring closure or hydrogen"}]}],subGroups:{"group-acyclic":{title:"Acyclic",itemSets:[{items:[{label:"ACY",description:"Acyclic group"},{label:"ACH",description:"Acyclic group or hydrogen"}]}],subGroups:{"acyclic-carbo":{title:"Acyclic Carbo",itemSets:[{items:[{label:"ABC",description:"Carbocyclic"},{label:"ABH",description:"Carbocyclic of hydrogen"}]},{displayName:"alkynyl",items:[{label:"AYL",description:"Alkynyl"},{label:"AYH",description:"Alkynyl or hydrogen"}]},{displayName:"alkyl",items:[{label:"ALK",description:"Alkyl"},{label:"ALH",description:"Alkyl or hydrogen"}]},{displayName:"alkenyl",items:[{label:"AEL",description:"Alkenyl"},{label:"AEH",description:"Alkenyl or hydrogen"}]}]},"acyclic-hetero":{title:"Acyclic Hetero",itemSets:[{items:[{label:"AHC",description:"Heteroacyclic"},{label:"AHH",description:"Heterocyclic or hydrogen"}]},{items:[{label:"AOX",description:"Alkoxy"},{label:"AOH",description:"Alkoxy or hydrogen"}]}]}}},"group-cyclic":{title:"Cyclic",itemSets:[{items:[{label:"CYC",description:"Cyclic group"},{label:"CYH",description:"Cyclic group or hydrogen"}]},{displayName:"no carbon",items:[{label:"CXX",description:"Cyclic group with no Carbon atoms"},{label:"CXH",description:"Cyclic group with no Carbon atoms or hydrogen"}]}],subGroups:{"cyclic-carbo":{title:"Cyclic Carbo",itemSets:[{items:[{label:"CBC",description:"Carbocyclic derivatives"},{label:"CBH",description:"Carbocyclic derivatives or hydrogen"}]},{displayName:"aryl",items:[{label:"ARY",description:"Any aryl group"},{label:"ARH",description:"Any aryl group or hydrogen"}]},{displayName:"cycloalkyl",items:[{label:"CAL",description:"Any cycloalkyl group"},{label:"CAH",description:"Any cycloalkyl group or hydrogen"}]},{displayName:"cycloalkenyl",items:[{label:"CEL",description:"Any cyloalkenyl group"},{label:"CEH",description:"Any cyloalkenyl group or hydrogen"}]}]},"cyclic-hetero":{title:"Cyclic Hetero",itemSets:[{items:[{label:"CHC",description:"Heterocyclic group"},{label:"CHH",description:"Heterocyclic group or hydrogen"}]},{displayName:"hetero aryl",items:[{label:"HAR",description:"Heteroaryl group"},{label:"HAH",description:"Heteroaryl group or hydrogen"}]}]}}}}}},H=function e(t){var n;if(!Array.isArray(t)||null!==(n=t[0])&&void 0!==n&&n.items){for(var r=[],i=0,a=Object.values(t);i<a.length;i++){var s=a[i];"string"!=typeof t&&(r=[].concat((0,o.A)(r),(0,o.A)(e(s))))}return r}return t.map((function(e){return e.label}))}(F);function j(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}var G,z=function(){function e(t){(0,i.A)(this,e),this.notList=t.notList,this.ids=t.ids}return(0,a.A)(e,[{key:"labelList",value:function(){var e,t=[],n=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return j(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?j(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}(this.ids);try{for(n.s();!(e=n.n()).done;){var o=e.value,r=_.get(o);r&&t.push(r.label)}}catch(e){n.e(e)}finally{n.f()}return t}},{key:"label",value:function(){var e="["+this.labelList().join(",")+"]";return this.notList&&(e="!"+e),e}},{key:"equals",value:function(e){return this.notList===e.notList&&(this.ids||[]).sort().toString()===(e.ids||[]).sort().toString()}}]),e}();function V(e,t,n,o){null==n||n===o||Array.isArray(n)&&0===n.length||(e[t]=n)}function U(e){return("number"==typeof e?e:parseFloat(e)).toFixed(8)}!function(e){e[e.ERROR=0]="ERROR",e[e.WARN=1]="WARN",e[e.INFO=2]="INFO",e[e.LOG=3]="LOG"}(G||(G={}));var W,q=function(){function e(){(0,i.A)(this,e)}return(0,a.A)(e,null,[{key:"settings",get:function(){var e;if(null===(e=window)||void 0===e||!e.ketcher)throw new Error("Ketcher needs to be initialized before KetcherLogger is used");return window.ketcher.logging},set:function(e){for(var t=0,n=Object.entries(e);t<n.length;t++){var o=(0,r.A)(n[t],2),i=o[0],a=o[1];this.settings[i]=a}}},{key:"log",value:function(){if(this.isMinimumLogLevel(G.LOG)){for(var e=this.settings.showTrace,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];e?window.console.trace(n):window.console.log(n)}}},{key:"info",value:function(){if(this.isMinimumLogLevel(G.INFO)){for(var e=this.settings.showTrace,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];e?window.console.trace(n):window.console.info(n)}}},{key:"warn",value:function(){if(this.isMinimumLogLevel(G.WARN)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];window.console.warn(t)}}},{key:"error",value:function(){if(this.isMinimumLogLevel(G.ERROR)){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];window.console.error(t)}}},{key:"isMinimumLogLevel",value:function(e){var t=this.settings,n=t.enabled,o=t.level;return!(!n||null==o)&&o>=e}}]),e}();!function(e){e.LOADING="LOADING",e.SUCCESS="SUCCESS",e.FAILURE="FAILURE"}(W||(W={}));var Y,$=(Y=(0,m.A)(v().mark((function e(t,n){var o;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n.emit(W.LOADING),e.prev=1,e.next=4,t();case 4:return o=e.sent,n.emit(W.SUCCESS),e.abrupt("return",o);case 9:return e.prev=9,e.t0=e.catch(1),q.error("runAsyncAction.ts::runAsyncAction",e.t0),n.emit(W.FAILURE),e.abrupt("return",void 0);case 14:case"end":return e.stop()}}),e,null,[[1,9]])}))),function(e,t){return Y.apply(this,arguments)});function X(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:512,o=window.atob(e),r=[],i=0;i<o.length;i+=n){for(var a=o.slice(i,i+n),s=new Array(a.length),u=0;u<a.length;u++)s[u]=a.charCodeAt(u);var l=new Uint8Array(s);r.push(l)}return new Blob(r,{type:t})}function K(){var e=new Event("requestCompleted");window.dispatchEvent(e)}function Z(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Q(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Z(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Z(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}for(var J="ketcher_editor_saved_settings",ee="ketcher-opts",te=function(){function e(){(0,i.A)(this,e)}return(0,a.A)(e,null,[{key:"getSettings",value:function(){try{return JSON.parse(localStorage.getItem(J)||"{}")}catch(e){return q.error("settingsManager.ts::SettingsManager::getSettings",e),{}}}},{key:"saveSettings",value:function(e){e&&localStorage.setItem(J,JSON.stringify(e))}},{key:"getOptions",value:function(){try{return JSON.parse(localStorage.getItem(ee)||"{}")}catch(e){return q.error("SettingsManager.ts::SettingsManager::getOptions",e),{}}}},{key:"saveOptions",value:function(e){e&&localStorage.setItem(ee,JSON.stringify(e))}},{key:"selectionTool",get:function(){return this.getSettings().selectionTool},set:function(e){var t=this.getSettings();this.saveSettings(Q(Q({},t),{},{selectionTool:e}))}},{key:"disableCustomQuery",get:function(){return this._disableCustomQuery},set:function(e){this._disableCustomQuery=e}},{key:"ignoreChiralFlag",get:function(){return this.getOptions().ignoreChiralFlag},set:function(e){var t=this.getOptions();this.saveOptions(Q(Q({},t),{},{ignoreChiralFlag:e}))}}]),e}(),ne={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},oe={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},re="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),ie="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),ae=0;ae<10;ae++)ne[48+ae]=ne[96+ae]=String(ae);for(ae=1;ae<=24;ae++)ne[ae+111]="F"+ae;for(ae=65;ae<=90;ae++)ne[ae]=String.fromCharCode(ae+32),oe[ae]=String.fromCharCode(ae);for(var se in ne)oe.hasOwnProperty(se)||(oe[se]=ne[se]);function ue(e){var t=!(re&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||ie&&e.shiftKey&&e.key&&1==e.key.length||"Unidentified"==e.key)&&e.key||(e.shiftKey?oe:ne)[e.keyCode]||e.key||"Unidentified";return"Esc"==t&&(t="Escape"),"Del"==t&&(t="Delete"),"Left"==t&&(t="ArrowLeft"),"Up"==t&&(t="ArrowUp"),"Right"==t&&(t="ArrowRight"),"Down"==t&&(t="ArrowDown"),t}var le="undefined"!=typeof navigator&&/Mac/.test(navigator.platform);function ce(e){var t,n,o,r,i=e.split(/\+(?!$)/),a=i[i.length-1];"Space"===a&&(a=" ");for(var s=0;s<i.length-1;s++){var u=i[s];if(/^(cmd|meta|m)$/i.test(u))r=!0;else if(/^a(lt)?$/i.test(u))t=!0;else if(/^(c|ctrl|control)$/i.test(u))n=!0;else if(/^s(hift)?$/i.test(u))o=!0;else{if(!/^mod$/i.test(u))throw new Error("Unrecognized modifier name: "+u);le?r=!0:n=!0}}return t&&(a="Alt+"+a),n&&(a="Ctrl+"+a),r&&(a="Meta+"+a),o&&(a="Shift+"+a),a}function de(e,t,n){return t.altKey&&(e="Alt+"+e),t.ctrlKey&&(e="Ctrl+"+e),t.metaKey&&(e="Meta+"+e),!1!==n&&t.shiftKey&&(e="Shift+"+e),e}function he(e,t){return e.replace(/[а-я]/,ne[t.keyCode]).replace(/[А-Я]/,oe[t.keyCode])}function fe(e){return le?e.metaKey:e.ctrlKey}function me(e){return e instanceof KeyboardEvent?function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=he(ue(e),e),o=1===n.length&&" "!==n;return o&&!t?de(n,e,!o):de(ne[e.keyCode],e,!0)}(e):"object"===(0,g.A)(e)?(t=e,n=Object.create(null),Object.keys(t).forEach((function(e){n[ce(e)]=t[e]})),n):ce(e);var t,n}function pe(e,t,n){Array.isArray(n[e])?n[e].push(t):n[e]=[t]}function ve(e){var t,n={};return Object.keys(e).forEach((function(o){(t=e[o]).shortcut&&(Array.isArray(t.shortcut)?t.shortcut.forEach((function(e){pe(e,o,n)})):pe(t.shortcut,o,n))})),me(n)}me.lookup=function(e,t){var n=he(ue(t),t);"Add"===n&&(n="+"),"Subtract"===n&&(n="-");var o,r=1===n.length&&" "!==n,i=e[de(n,t,!r)];return t.shiftKey&&r&&(o=ne[t.keyCode])&&(i=e[de(o,t,!0)]||i),i};var ge={Escape:"Esc",Delete:"Del",Mod:y.Ue?"⌘":"Ctrl"};function ye(e){return e?(Array.isArray(e)?e[0]:e).replace(/(\b[a-z]\b$|Mod|Escape|Delete)/g,(function(e){return ge[e]||e.toUpperCase()})):""}var be,Ae=function(e){return Object.keys(e).reduce((function(t,n){var o;if(null!==(o=e[n])&&void 0!==o&&o.shortcut){var r=ye(e[n].shortcut);t[n]=r}return t}),{})},we=function(){function e(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];if((0,i.A)(this,e),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,a.A)(e,[{key:"length",value:function(){return Math.sqrt(this.x*this.x+this.y*this.y)}},{key:"equals",value:function(e){return this.x===e.x&&this.y===e.y&&this.z===e.z}},{key:"add",value:function(t){return new e(this.x+t.x,this.y+t.y,this.z+t.z)}},{key:"add_",value:function(e){this.x+=e.x,this.y+=e.y,this.z+=e.z}},{key:"get_xy0",value:function(){return new e(this.x,this.y)}},{key:"sub",value:function(t){return new e(this.x-t.x,this.y-t.y,this.z-t.z)}},{key:"scaled",value:function(t){return new e(this.x*t,this.y*t,this.z*t)}},{key:"negated",value:function(){return new e(-this.x,-this.y,-this.z)}},{key:"yComplement",value:function(t){return t=t||0,new e(this.x,t-this.y,this.z)}},{key:"addScaled",value:function(t,n){return new e(this.x+t.x*n,this.y+t.y*n,this.z+t.z*n)}},{key:"normalized",value:function(){return this.scaled(1/this.length())}},{key:"normalize",value:function(){var e=this.length();return!(e<1e-6||(this.x/=e,this.y/=e,0))}},{key:"turnLeft",value:function(){return new e(-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(t){return f()(null!=t),e.max(this,t)}},{key:"min",value:function(t){return e.min(this,t)}},{key:"ceil",value:function(){return new e(Math.ceil(this.x),Math.ceil(this.y),Math.ceil(this.z))}},{key:"floor",value:function(){return new e(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))}},{key:"rotate",value:function(e){var t=Math.sin(e),n=Math.cos(e);return this.rotateSC(t,n)}},{key:"rotateSC",value:function(t,n){return f()(0===t||!!t),f()(0===n||!!n),new e(this.x*n-this.y*t,this.x*t+this.y*n,this.z)}},{key:"rotateAroundOrigin",value:function(t,n){var o=t*Math.PI/180,r=this.x-n.x,i=this.y-n.y,a=Math.cos(o)*r-Math.sin(o)*i,s=Math.sin(o)*r+Math.cos(o)*i,u=a+n.x,l=s+n.y;return new e(Number(U(u)),Number(U(l)),this.z||0)}},{key:"isInsidePolygon",value:function(e){for(var t=this.x,n=this.y,o=!1,r=0,i=e.length-1;r<e.length;i=r++){var a=e[r].x||0,s=e[r].y||0,u=e[i].x||0,l=e[i].y||0;s>n!=l>n&&t<(u-a)*(n-s)/(l-s)+a&&(o=!o)}return o}},{key:"oxAngle",value:function(){return Math.atan2(this.y,this.x)}}],[{key:"dist",value:function(t,n){return e.diff(t,n).length()}},{key:"max",value:function(t,n){return new e(Math.max(t.x,n.x),Math.max(t.y,n.y),Math.max(t.z,n.z))}},{key:"min",value:function(t,n){return new e(Math.min(t.x,n.x),Math.min(t.y,n.y),Math.min(t.z,n.z))}},{key:"sum",value:function(t,n){return new e(t.x+n.x,t.y+n.y,t.z+n.z)}},{key:"dot",value:function(e,t){return e.x*t.x+e.y*t.y}},{key:"cross",value:function(e,t){return e.x*t.y-e.y*t.x}},{key:"angle",value:function(t,n){return Math.atan2(e.cross(t,n),e.dot(t,n))}},{key:"diff",value:function(t,n){return new e(t.x-n.x,t.y-n.y,t.z-n.z)}},{key:"lc",value:function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];for(var r=new e,i=0;i<arguments.length/2;++i)r=r.addScaled(n[2*i],n[2*i+1]);return r}},{key:"lc2",value:function(t,n,o,r){return new e(t.x*n+o.x*r,t.y*n+o.y*r,t.z*n+o.z*r)}},{key:"centre",value:function(t,n){return e.lc2(t,.5,n,.5)}},{key:"getLinePoint",value:function(t,n,o){var r=t.sub(n),i=o/r.length();return new e(t.x+r.x*i,t.y+r.y*i)}},{key:"crossProduct",value:function(e,t){return e.x*t.y-e.y*t.x}},{key:"radiansToDegrees",value:function(e){return e*(180/Math.PI)}},{key:"degrees_to_radians",value:function(e){return e*Math.PI/180}},{key:"oxAngleForVector",value:function(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}},{key:"findSecondPoint",value:function(e,t,n){var o=t*Math.cos(n),r=t*Math.sin(n);return{x:e.x+o,y:e.y+r}}}]),e}();function Ee(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return Pe(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Pe(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function Pe(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function xe(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Se()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Se(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Se=function(){return!!e})()}be=we,(0,d.A)(we,"ZERO",new be(0,0)),(0,d.A)(we,"UNIT",new be(1,1));var Oe,ke,Me,Re=function(e){function t(){return(0,i.A)(this,t),xe(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t,[{key:"find",value:function(e){var t,n=Ee(this);try{for(n.s();!(t=n.n()).done;){var o=t.value;if(e(o))return o}}catch(e){n.e(e)}finally{n.f()}return null}},{key:"equals",value:function(e){return this.isSuperset(e)&&e.isSuperset(this)}},{key:"isSuperset",value:function(e){var t,n=Ee(e);try{for(n.s();!(t=n.n()).done;){var o=t.value;if(!this.has(o))return!1}}catch(e){n.e(e)}finally{n.f()}return!0}},{key:"filter",value:function(e){return new t(Array.from(this).filter(e))}},{key:"union",value:function(e){var n,o=new t(this),r=Ee(e);try{for(r.s();!(n=r.n()).done;){var i=n.value;o.add(i)}}catch(e){r.e(e)}finally{r.f()}return o}},{key:"intersection",value:function(e){var n=new t(this);return new t((0,o.A)(n).filter((function(t){return e.has(t)})))}}],[{key:"unionIntersections",value:function(e){var n=!1,o=e.reduce((function(e,t){var o=!1,r=e.map((function(e){return e.intersection(t).size>0?(n=!0,o=!0,e.union(t)):e}));return o||r.push(t),r}),new Array);return n?t.unionIntersections(o):o}}]),t}((0,b.A)(Set)),Te="invalid",Be=function(){function e(t){(0,i.A)(this,e),this.initiallySelected=t}return(0,a.A)(e,[{key:"getInitiallySelected",value:function(){if(this.initiallySelected===Te)throw new Error("this field is used only for serialization/deserialization");return this.initiallySelected}},{key:"setInitiallySelected",value:function(e){if(this.initiallySelected===Te)throw new Error("this field is used only for serialization/deserialization");this.initiallySelected=e}},{key:"resetInitiallySelected",value:function(e){this.initiallySelected=e?Te:void 0}}]),e}();function Ce(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return Ie(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ie(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function Ie(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function Ne(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,De()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function De(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(De=function(){return!!e})()}!function(e){e[e.None=0]="None",e[e.FirstSideOnly=1]="FirstSideOnly",e[e.SecondSideOnly=2]="SecondSideOnly",e[e.BothSides=3]="BothSides"}(Oe||(Oe={})),function(e){e.Abs="abs",e.And="&",e.Or="or"}(ke||(ke={})),function(e){e.S="S",e.R="R",e.s="s",e.r="r"}(Me||(Me={}));var Le,_e,Fe=function(e){function t(e){var n;for(var o in(0,i.A)(this,t),(n=Ne(this,t,[null==e?void 0:e.initiallySelected])).label=e.label,n.fragment=je(e.fragment,-1),n.alias=je(e.alias,t.attrlist.alias),n.isotope=je(e.isotope,t.attrlist.isotope),n.radical=je(e.radical,t.attrlist.radical),n.cip=je(e.cip,t.attrlist.cip),n.charge=je(e.charge,t.attrlist.charge),n.rglabel=je(e.rglabel,t.attrlist.rglabel),n.attachmentPoints=je(e.attachmentPoints,t.attrlist.attachmentPoints),n.implicitHCount=je(e.implicitHCount,null),n.explicitValence=je(e.explicitValence,t.attrlist.explicitValence),n.isPreview=je(e.isPreview,t.attrlist.isPreview),n.valence=0,n.implicitH=e.implicitHCount||e.implicitH||0,n.pp=e.pp?new we(e.pp):new we,n.sgs=new Re,n.ringBondCount=je(e.ringBondCount,t.attrlist.ringBondCount),n.substitutionCount=je(e.substitutionCount,t.attrlist.substitutionCount),n.unsaturatedAtom=je(e.unsaturatedAtom,t.attrlist.unsaturatedAtom),n.hCount=je(e.hCount,t.attrlist.hCount),n.queryProperties={},t.attrlist.queryProperties){var r;n.queryProperties[o]=je(null===(r=e.queryProperties)||void 0===r?void 0:r[o],t.attrlist.queryProperties[o])}return n.aam=je(e.aam,t.attrlist.aam),n.invRet=je(e.invRet,t.attrlist.invRet),n.exactChangeFlag=je(e.exactChangeFlag,t.attrlist.exactChangeFlag),n.rxnFragmentType=je(e.rxnFragmentType,-1),n.stereoLabel=je(e.stereoLabel,t.attrlist.stereoLabel),n.stereoParity=je(e.stereoParity,t.attrlist.stereoParity),n.atomList=e.atomList?new z(e.atomList):null,n.neighbors=[],n.badConn=!1,Object.defineProperty((0,l.A)(n),"pseudo",{enumerable:!0,get:function(){return Ge(e=this.label)?e:"";var e},set:function(e){Ge(e)&&(this.label=e)}}),n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"attpnt",get:function(){return this.attachmentPoints}},{key:"isRGroupAttachmentPointEditDisabled",get:function(){return"R#"===this.label&&null!==this.rglabel}},{key:"setRGAttachmentPointForDisplayPurpose",value:function(){this.attachmentPoints=Oe.FirstSideOnly}},{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(){var e=this.queryProperties,t="A"===this.label,n="M"===this.label||"MH"===this.label,o="X"===this.label||"XH"===this.label,r="G"===this.label||"G*"===this.label||"GH"===this.label||"GH*"===this.label;return Boolean(0!==this.substitutionCount||0!==this.unsaturatedAtom||0!==this.ringBondCount||t||n||o||r||0!==this.hCount||null!==this.atomList||Object.values(e).some((function(e){return e})))}},{key:"pureHydrogen",value:function(){return"H"===this.label&&0===this.isotope}},{key:"isPlainCarbon",value:function(){return"C"===this.label&&null===this.isotope&&0===this.radical&&null===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&&!_.get(this.label)}},{key:"hasRxnProps",value:function(){return!!(this.invRet||this.exactChangeFlag||null!==this.attachmentPoints||this.aam)}},{key:"calcValence",value:function(e){var n=this.label,o=this.charge||0;if(this.isQuery()||this.attachmentPoints)return this.implicitH=0,!0;var r=_.get(n),i=null==r?void 0:r.group,a=He(this.radical),s=e,u=0,l=Math.abs(o);if(void 0===i){if("D"!==n&&"T"!==n)return this.implicitH=0,!0;s=1,u=1-a-e-l}else 1===i?"H"!==n&&"Li"!==n&&"Na"!==n&&"K"!==n&&"Rb"!==n&&"Cs"!==n&&"Fr"!==n||(s=1,u=1-a-e-l):2===i?e+a+l===2||e+a+l===0?s=2:u=-1:3===i?"B"===n||"Al"===n||"Ga"===n||"In"===n?-1===o?(s=4,u=4-a-e):(s=3,u=3-a-e-l):"Tl"===n&&(-1===o?a+e<=2?(s=2,u=2-a-e):(s=4,u=4-a-e):-2===o?a+e<=3?(s=3,u=3-a-e):(s=5,u=5-a-e):a+e+l<=1?(s=1,u=1-a-e-l):(s=3,u=3-a-e-l)):4===i?"C"===n||"Si"===n||"Ge"===n?(s=4,u=4-a-e-l):"Sn"!==n&&"Pb"!==n||(e+a+l<=2?(s=2,u=2-a-e-l):(s=4,u=4-a-e-l)):5===i?"N"===n||"P"===n?1===o?(s=4,u=4-a-e):2===o?(s=3,u=3-a-e):"N"===n||a+e+l<=3?(s=3,u=3-a-e-l):(s=5,u=5-a-e-l):"Bi"!==n&&"Sb"!==n&&"As"!==n||(1===o?a+e<=2&&"As"!==n?(s=2,u=2-a-e):(s=4,u=4-a-e):2===o?(s=3,u=3-a-e):a+e<=3?(s=3,u=3-a-e-l):(s=5,u=5-a-e-l)):6===i?"O"===n?o>=1?(s=3,u=3-a-e):(s=2,u=2-a-e-l):"S"===n||"Se"===n||"Po"===n?1===o?e<=3?(s=3,u=3-a-e):(s=5,u=5-a-e):e+a+l<=2?(s=2,u=2-a-e-l):e+a+l<=4?(s=4,u=4-a-e-l):(s=6,u=6-a-e-l):"Te"===n&&(-1===o?e<=2&&(s=2,u=2-a-e-l):0!==o&&2!==o||(e<=2?(s=2,u=2-a-e-l):e<=4?(s=4,u=4-a-e-l):0===o&&e<=6?(s=6,u=6-a-e-l):u=-1)):7===i?"F"===n?(s=1,u=1-a-e-l):"Cl"!==n&&"Br"!==n&&"I"!==n&&"At"!==n||(1===o?e<=2?(s=2,u=2-a-e):(3===e||5===e||e>=7)&&(u=-1):0===o&&(e<=1?(s=1,u=1-a-e):2===e||4===e||6===e?1===a?(s=e,u=0):u=-1:e>7&&(u=-1))):8===i&&(e+a+l===0?s=1:u=-1);return t.isHeteroAtom(n)&&null!==this.implicitHCount&&(u=this.implicitHCount),this.valence=s,this.implicitH=u,!(this.implicitH<0&&(this.valence=e,this.implicitH=0,this.badConn=!0,1))}},{key:"calcValenceMinusHyd",value:function(e){var t=this.charge||0,n=this.label,o=_.get(this.label);if(!o)return this.implicitH=0,0;var r=o.group,i=He(this.radical);if(3===r){if(("B"===n||"Al"===n||"Ga"===n||"In"===n)&&-1===t&&i+e<=4)return i+e}else if(5===r){if("N"===n||"P"===n){if(1===t)return i+e;if(2===t)return i+e}else if("Sb"===n||"Bi"===n||"As"===n){if(1===t)return i+e;if(2===t)return i+e}}else if(6===r){if("O"===n){if(t>=1)return i+e}else if(("S"===n||"Se"===n||"Po"===n)&&1===t)return i+e}else if(7===r&&("Cl"===n||"Br"===n||"I"===n||"At"===n)&&1===t)return i+e;return i+e+Math.abs(t)}}],[{key:"getConnectedBondIds",value:function(e,t){var n,o=[],i=Ce(e.bonds.entries());try{for(i.s();!(n=i.n()).done;){var a=(0,r.A)(n.value,2),s=a[0],u=a[1];u.begin!==t&&u.end!==t||o.push(s)}}catch(e){i.e(e)}finally{i.f()}return o}},{key:"getAttrHash",value:function(e){var n={};for(var o in t.attrlist)void 0!==e[o]&&(n[o]=e[o]);return n}},{key:"attrGetDefault",value:function(e){if(e in t.attrlist)return t.attrlist[e]}},{key:"isHeteroAtom",value:function(e){return"C"!==e&&"H"!==e}},{key:"isInAromatizedRing",value:function(e,n){var o=e.atoms.get(n);if(o&&t.isHeteroAtom(o.label)){var i,a=Ce(e.loops);try{for(a.s();!(i=a.n()).done;){var s=(0,r.A)(i.value,2),u=(s[0],s[1]),l=u.hbs;if(u.aromatic){var c,d=Ce(l);try{for(d.s();!(c=d.n()).done;){var h=c.value,f=e.halfBonds.get(h);if(!f)return!1;var m=f.begin,p=f.end;if(m===n||p===n)return!0}}catch(e){d.e(e)}finally{d.f()}}}}catch(e){a.e(e)}finally{a.f()}}return!1}}]),t}(Be);function He(e){return(e-=0)===Fe.PATTERN.RADICAL.DOUPLET?1:e===Fe.PATTERN.RADICAL.SINGLET||e===Fe.PATTERN.RADICAL.TRIPLET?2:0}function je(e,t){return void 0!==e?e:t}function Ge(e){return!_.get(e)&&"L"!==e&&"L#"!==e&&"R#"!==e}function ze(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Ve()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Ve(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Ve=function(){return!!e})()}(0,d.A)(Fe,"PATTERN",{RADICAL:{NONE:0,SINGLET:1,DOUPLET:2,TRIPLET:3},STEREO_PARITY:{NONE:0,ODD:1,EVEN:2,EITHER:3}}),(0,d.A)(Fe,"attrlist",{alias:null,label:"C",isotope:null,radical:0,cip:null,charge:null,explicitValence:-1,ringBondCount:0,substitutionCount:0,unsaturatedAtom:0,hCount:0,queryProperties:{aromaticity:null,ringMembership:null,ringSize:null,connectivity:null,chirality:null,customQuery:null},atomList:null,invRet:0,exactChangeFlag:0,rglabel:null,attachmentPoints:null,aam:0,isPreview:!1,stereoLabel:null,stereoParity:0,implicitHCount:null}),function(e){e.E="E",e.Z="Z",e.M="M",e.P="P"}(_e||(_e={}));var Ue,We=function(e){function t(e){var n,o;return(0,i.A)(this,t),(o=ze(this,t,[e.initiallySelected])).begin=e.begin,o.end=e.end,o.type=e.type,o.xxx=e.xxx||"",o.stereo=t.PATTERN.STEREO.NONE,o.topology=t.PATTERN.TOPOLOGY.EITHER,o.customQuery=null,o.reactingCenterStatus=0,o.cip=null!==(n=e.cip)&&void 0!==n?n:null,o.len=0,o.sb=0,o.sa=0,o.angle=0,o.isPreview=!1,e.stereo&&(o.stereo=e.stereo),e.topology&&(o.topology=e.topology),e.customQuery&&(o.customQuery=e.customQuery,o.type=t.PATTERN.TYPE.ANY,o.reactingCenterStatus=null,o.topology=null),e.reactingCenterStatus&&(o.reactingCenterStatus=e.reactingCenterStatus),o.center=new we,o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"isQuery",value:function(){var e=t.PATTERN.TYPE,n=[e.ANY,e.SINGLE_OR_DOUBLE,e.SINGLE_OR_AROMATIC,e.DOUBLE_OR_AROMATIC,e.AROMATIC];return null!==this.customQuery||n.includes(this.type)||e.SINGLE===this.type&&this.stereo===t.PATTERN.STEREO.EITHER}},{key:"hasRxnProps",value:function(){return!!this.reactingCenterStatus}},{key:"getCenter",value:function(e){var t=e.atoms.get(this.begin).pp,n=e.atoms.get(this.end).pp;return we.lc2(t,.5,n,.5)}},{key:"getDir",value:function(e){var t=e.atoms.get(this.begin).pp;return e.atoms.get(this.end).pp.sub(t).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:"getAttachedSGroups",value:function(e){var t,n,o=(null===(t=e.atoms.get(this.begin))||void 0===t?void 0:t.sgs)||new Re,r=(null===(n=e.atoms.get(this.end))||void 0===n?void 0:n.sgs)||new Re;return null==o?void 0:o.intersection(r)}}],[{key:"getAttrHash",value:function(e){var n={};for(var o in t.attrlist)(e[o]||"stereo"===o)&&(n[o]=e[o]);return n}},{key:"getBondNeighbourIds",value:function(e,t){var n=e.bonds.get(t),o=n.begin,r=n.end,i=Fe.getConnectedBondIds(e,o).filter((function(e){return e!==t})),a=Fe.getConnectedBondIds(e,r).filter((function(e){return e!==t}));return{beginBondIds:i,endBondIds:a}}},{key:"getFusingConditions",value:function(e,t,n){var o=this.PATTERN.TYPE,r=o.DOUBLE,i=o.SINGLE,a=t.type===i&&e.type===r&&n.type===i;return{isFusingToSingleBond:t.type===r&&e.type===i&&n.type===r,isFusingToDoubleBond:a,isFusingDoubleSingleSingle:t.type===r&&e.type===i&&n.type===i,isFusingSingleSingleDouble:t.type===i&&e.type===i&&n.type===r,isAllSingle:t.type===i&&e.type===i&&n.type===i}}},{key:"getBenzeneConnectingBondType",value:function(e,n,o){var r=this.PATTERN.TYPE,i=r.DOUBLE,a=r.SINGLE,s=t.getFusingConditions(e,n,o),u=s.isFusingToSingleBond;return s.isFusingToDoubleBond?i:u?a:null}},{key:"getCyclopentadieneFusingBondType",value:function(e,n,o){var r=this.PATTERN.TYPE,i=r.DOUBLE,a=r.SINGLE,s=t.getFusingConditions(e,n,o),u=s.isFusingToSingleBond,l=s.isFusingToDoubleBond,c=s.isFusingDoubleSingleSingle,d=s.isAllSingle;return l?i:u||d||c?a:null}},{key:"getCyclopentadieneDoubleBondIndexes",value:function(e,n,o){var r=t.getFusingConditions(e,n,o),i=r.isFusingToSingleBond,a=r.isFusingToDoubleBond,s=r.isFusingDoubleSingleSingle;return i||a?[3]:s?[2,4]:[1,3]}},{key:"attrGetDefault",value:function(e){if(e in t.attrlist)return t.attrlist[e]}}]),t}(Be);function qe(e,t,n){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.set(e,n)}function Ye(e,t){if(t&&0!==t.length){var n=t.map((function(t){return e.atoms.get(t)})).filter((function(e){return null==e?void 0:e.stereoLabel}));if(n.length){var o,r=n[0].stereoLabel;if(n.some((function(e){return(null==e?void 0:e.stereoLabel)!==r})))o=Ue.Mixed;else{var i,a=null===(i=r.match(/\D+/g))||void 0===i?void 0:i[0];switch(a){case ke.Abs:o=Ue.Abs;break;case ke.And:o=Ue.And;break;case ke.Or:o=Ue.Or;break;default:throw new Error("Unsupported stereo label: ".concat(a,"."))}}return o}}}Le=We,(0,d.A)(We,"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,d.A)(We,"attrlist",{type:Le.PATTERN.TYPE.SINGLE,stereo:Le.PATTERN.STEREO.NONE,topology:Le.PATTERN.TOPOLOGY.EITHER,reactingCenterStatus:Le.PATTERN.REACTING_CENTER.UNMARKED,cip:null,customQuery:null}),function(e){e.Mixed="MIXED",e.Abs="ABS",e.And="AND",e.Or="OR"}(Ue||(Ue={}));var $e=new WeakMap,Xe=new WeakMap,Ke=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1?arguments[1]:void 0,o=arguments.length>2?arguments[2]:void 0;(0,i.A)(this,e),qe(this,$e,{writable:!0,value:void 0}),qe(this,Xe,{writable:!0,value:void 0}),n&&(this.stereoFlagPosition=new we(n)),o&&(this.properties=o),(0,A.A)(this,Xe,t)}return(0,a.A)(e,[{key:"stereoAtoms",get:function(){return(0,o.A)((0,w.A)(this,Xe))}},{key:"enhancedStereoFlag",get:function(){return(0,w.A)(this,$e)}},{key:"clone",value:function(t){var n=new e((0,w.A)(this,Xe).map((function(e){return t.get(e)})),this.stereoFlagPosition,this.properties);return(0,A.A)(n,$e,(0,w.A)(this,$e)),n}},{key:"updateStereoFlag",value:function(e){return(0,A.A)(this,$e,Ye(e,this.stereoAtoms)),(0,w.A)(this,$e)}},{key:"updateStereoAtom",value:function(e,t,n,o){var r;o&&!(0,w.A)(this,Xe).includes(t)&&(0,w.A)(this,Xe).push(t),o||(null===(r=e.atoms.get(t))||void 0===r?void 0:r.fragment)===n&&Array.from(e.bonds.values()).filter((function(e){return e.stereo&&e.type!==We.PATTERN.TYPE.DOUBLE})).some((function(e){return e.begin===t}))||(0,A.A)(this,Xe,this.stereoAtoms.filter((function(e){return e!==t}))),(0,A.A)(this,$e,Ye(e,this.stereoAtoms))}},{key:"addStereoAtom",value:function(e){return!(0,w.A)(this,Xe).includes(e)&&(this.stereoAtoms.push(e),!0)}},{key:"deleteStereoAtom",value:function(e,t,n){var o;return!((null===(o=e.atoms.get(n))||void 0===o?void 0:o.fragment)===t&&Array.from(e.bonds.values()).filter((function(e){return e.stereo&&e.type!==We.PATTERN.TYPE.DOUBLE})).some((function(e){return e.begin===n}))||((0,A.A)(this,Xe,(0,w.A)(this,Xe).filter((function(e){return e!==n}))),0))}}],[{key:"getDefaultStereoFlagPosition",value:function(e,t){var n=e.getFragment(t);if(n){var o=n.getCoordBoundingBox();return new we(o.max.x,o.min.y-1)}}}]),e}(),Ze={canvasToModel:function(e,t){return e.scaled(1/t.microModeScale)},modelToCanvas:function(e,t){return e.scaled(t.microModeScale)}},Qe={isCorrectStereoCenter:function(e,t,n,o){var r,i=o.atoms.get(e.begin),a=NaN;return 2===(null==n?void 0:n.length)&&(a=n[0].aid===e.begin?n[1].aid:n[0].aid),e.stereo>0&&(1!==(null==n?void 0:n.length)||2!==(null==t?void 0:t.length)||Number(null==i?void 0:i.implicitH)%2!=0)&&(2!==(null==n?void 0:n.length)||2!==(null==t?void 0:t.length)||Number(null==i?void 0:i.implicitH)%2!=0||1!==(null===(r=o.atomGetNeighbors(a))||void 0===r?void 0:r.length))&&1!==(null==t?void 0:t.length)}},Je=function(){function e(){(0,i.A)(this,e),this.functionalGroupsList=[]}return(0,a.A)(e,[{key:"getFunctionalGroupsList",value:function(){return this.functionalGroupsList}},{key:"setFunctionalGroupsList",value:function(e){this.functionalGroupsList=e}},{key:"addToFunctionalGroupsList",value:function(e){this.functionalGroupsList=[].concat((0,o.A)(this.functionalGroupsList),(0,o.A)(e))}}],[{key:"getInstance",value:function(){return e.instance||(e.instance=new e),e.instance}}]),e}(),et=function(){function e(){(0,i.A)(this,e),this.saltsAndSolventsList=[]}return(0,a.A)(e,[{key:"getSaltsAndSolventsList",value:function(){return this.saltsAndSolventsList}},{key:"setSaltsAndSolventsList",value:function(e){this.saltsAndSolventsList=e}}],[{key:"getInstance",value:function(){return e.instance||(e.instance=new e),e.instance}}]),e}();function tt(e,t,n){return function(e,t){if(e!==t)throw new TypeError("Private static access of wrong provenance")}(e,t),n}var nt=function(){function e(){(0,i.A)(this,e);for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];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 we(n[0],n[1]),this.p1=new we(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 we,this.p1=new we}}return(0,a.A)(e,[{key:"toString",value:function(){return this.p0.toString()+" "+this.p1.toString()}},{key:"clone",value:function(){return new e(this.p0,this.p1)}},{key:"extend",value:function(t,n){return n=n||t,new e(this.p0.sub(t),this.p1.add(n))}},{key:"include",value:function(t){return f()(null!=t),new e(this.p0.min(t),this.p1.max(t))}},{key:"contains",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return f()(null!=e),e.x>=this.p0.x-t&&e.x<=this.p1.x+t&&e.y>=this.p0.y-t&&e.y<=this.p1.y+t}},{key:"translate",value:function(t){return new e(this.p0.add(t),this.p1.add(t))}},{key:"transform",value:function(t,n){return f()("function"==typeof t),new e(t(this.p0,n),t(this.p1,n))}},{key:"sz",value:function(){return this.p1.sub(this.p0)}},{key:"centre",value:function(){return we.centre(this.p0,this.p1)}},{key:"pos",value:function(){return this.p0}},{key:"hasZeroArea",value:function(){var e=this.sz();return 0===e.x&&0===e.y}}],[{key:"fromRelBox",value:function(t){return new e(t.x,t.y,t.x+t.width,t.y+t.height)}},{key:"union",value:function(t,n){return new e(we.min(t.p0,n.p0),we.max(t.p1,n.p1))}},{key:"segmentIntersection",value:function(t,n,o,r){var i=(t.x-o.x)*(n.y-o.y)-(t.y-o.y)*(n.x-o.x),a=(t.x-r.x)*(n.y-r.y)-(t.y-r.y)*(n.x-r.x),s=(o.x-t.x)*(r.y-t.y)-(o.y-t.y)*(r.x-t.x),u=(o.x-n.x)*(r.y-n.y)-(o.y-n.y)*(r.x-n.x);return 0===i&&0===a&&0===s&&0===u?tt(e,e,ot).call(e,t,n,o)||tt(e,e,ot).call(e,t,n,r)||tt(e,e,ot).call(e,o,r,t)||tt(e,e,ot).call(e,o,r,n):i*a<0&&s*u<0}}]),e}();function ot(e,t,n){var o=Math.min(e.x,t.x),r=Math.max(e.x,t.x),i=Math.min(e.y,t.y),a=Math.max(e.y,t.y);return n.x>=o&&n.x<=r&&n.y>=i&&n.y<=a}var rt,it,at={Fragment:"Fragment",Multifragment:"Multifragment",Bond:"Bond",Atom:"Atom",Group:"Group"},st=["atoms","bonds","frags","sgroups","rgroups","rgroupAttachmentPoints","rxnArrows","rxnPluses","simpleObjects","texts"],ut=2;function lt(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return ct(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?ct(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function ct(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}!function(e){e.SUGARS="Sugars",e.BASES="Bases",e.PHOSPHATES="Phosphates"}(rt||(rt={})),function(e){e.R="R",e.A="A",e.C="C",e.G="G",e.T="T",e.U="U",e.X="X",e.P="P"}(it||(it={})),rt.SUGARS,rt.BASES,rt.BASES,rt.BASES,rt.BASES,rt.BASES,rt.BASES,rt.PHOSPHATES;var dt=(0,a.A)((function e(t,n,o,r){(0,i.A)(this,e),this.c=t,this.d=n,this.n=n.rotateSC(1,0),this.w=o,this.h=r})),ht=function(){function e(t){(0,i.A)(this,e),this.type=t,this.id=-1,this.label=-1,this.bracketBox=null,this.bracketDirection=new we(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.attachmentPoints=[],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,a.A)(e,[{key:"getAttr",value:function(e){return this.data[e]}},{key:"setFunctionalGroup",value:function(e){this.functionalGroup=e}},{key:"getAttrs",value:function(){var e=this,t={};return Object.keys(this.data).forEach((function(n){t[n]=e.data[n]})),t}},{key:"setAttr",value:function(e,t){var n=this.data[e];return this.data[e]=t,n}},{key:"checkAttr",value:function(e,t){return this.data[e]===t}},{key:"updateOffset",value:function(e){this.pp=we.sum(this.bracketBox.p1,e)}},{key:"isExpanded",value:function(){return!e.isSuperAtom(this)||Boolean(this.data.expanded)}},{key:"isContracted",value:function(){return!this.isExpanded()}},{key:"calculatePP",value:function(t){var n,o=this.data.context===at.Atom,r=this.data.context===at.Bond;if(o||r){var i=[],a=null;this.atoms.forEach((function(e){var n=t.atoms.get(e),o=new we(n.pp),r=new we(.05*3,.05*3),a=new nt(o,o).extend(r,r);i.push(a)})),i.forEach((function(e){var t=null;[e.p0.x,e.p1.x].forEach((function(n){[e.p0.y,e.p1.y].forEach((function(e){var o=new we(n,e);t=t?t.include(o):new nt(o,o)}))})),a=a?nt.union(a,t):t})),n=r?a.centre():a.p0}else n=this.bracketBox.p1.add(new we(.5,.5));for(var s=Array.from(t.sgroups.values()),u=0;u<t.sgroups.size&&ft(s,n);++u)n=n.add(new we(0,.5));if("INDIGO_CIP_DESC"===this.data.fieldName)if(1===this.atoms.length){var l,c=this.atoms[0],d=null===(l=t.atoms.get(c))||void 0===l?void 0:l.pp;d&&(n=d)}else n=e.getMassCentre(t,this.atoms);this.pp=n}},{key:"isGroupAttached",value:function(e){return this.getConnectionPointsCount(e)>=1}},{key:"addAttachmentPoint",value:function(e){var t=this.attachmentPoints.some((function(t){var n=t.atomId;return e.atomId===n}));if(t)throw new Error("The same attachment point cannot be added to an S-group more than once");this.attachmentPoints.push(e)}},{key:"addAttachmentPoints",value:function(e){var t,n=lt(e);try{for(n.s();!(t=n.n()).done;){var o=t.value;this.addAttachmentPoint(o)}}catch(e){n.e(e)}finally{n.f()}}},{key:"removeAttachmentPoint",value:function(e){var t=this.attachmentPoints.findIndex((function(t){var n=t.atomId;return e===n}));return-1!==t&&(this.attachmentPoints.splice(t,1),!0)}},{key:"getAttachmentPoints",value:function(){return this.attachmentPoints}},{key:"getConnectionPointsCount",value:function(e){var t,n=new Set,o=lt(this.atoms);try{for(o.s();!(t=o.n()).done;){var r,i,a=t.value,s=lt(null!==(r=e.atomGetNeighbors(a))&&void 0!==r?r:[]);try{for(s.s();!(i=s.n()).done;){var u=i.value.aid;if(!this.atoms.includes(u)){n.add(a);break}}}catch(e){s.e(e)}finally{s.f()}}}catch(e){o.e(e)}finally{o.f()}return n.size}},{key:"isNotContractible",value:function(e){return this.getConnectionPointsCount(e)>1}},{key:"getAttachmentAtomId",value:function(){var e;return null===(e=this.attachmentPoints[0])||void 0===e?void 0:e.atomId}},{key:"getContractedPosition",value:function(e){var t,n=null===(t=this.attachmentPoints[0])||void 0===t?void 0:t.atomId,o=e.atoms.get(n);return o||(n=this.atoms[0],o=e.atoms.get(this.atoms[0])),f()(null!=o),{atomId:n,position:o.pp}}},{key:"cloneAttachmentPoints",value:function(e){return this.attachmentPoints.map((function(t){return t.clone(e)}))}}],[{key:"getOffset",value:function(e){return null!=e&&e.pp&&e.bracketBox?we.diff(e.pp,e.bracketBox.p1):null}},{key:"isSaltOrSolvent",value:function(e){return et.getInstance().getSaltsAndSolventsList().some((function(t){var n=t.name,o=t.abbreviation;return n===e||e===o}))}},{key:"isAtomInSaltOrSolvent",value:function(e,t){var n=this;return t.filter((function(e){return n.isSaltOrSolvent(e.data.name)})).some((function(t){return t.atoms.some((function(t){return t===e}))}))}},{key:"isBondInSaltOrSolvent",value:function(e,t){var n=this;return t.filter((function(e){return n.isSaltOrSolvent(e.data.name)})).some((function(t){return t.bonds.some((function(t){return t===e}))}))}},{key:"filterAtoms",value:function(e,t){for(var n=[],o=0;o<e.length;++o){var r=e[o];"number"!=typeof t[r]?n.push(r):t[r]>=0?n.push(t[r]):n.push(-1)}return n}},{key:"removeNegative",value:function(e){for(var t=[],n=0;n<e.length;++n)e[n]>=0&&t.push(e[n]);return t}},{key:"filter",value:function(t,n,o){n.atoms=e.removeNegative(e.filterAtoms(n.atoms,o))}},{key:"clone",value:function(t,n){var o=new e(t.type);return Object.keys(t.data).forEach((function(e){o.data[e]=t.data[e]})),o.atoms=t.atoms.map((function(e){return n.get(e)})),o.pp=t.pp,o.bracketBox=t.bracketBox,o.patoms=null,o.bonds=null,o.allAtoms=t.allAtoms,o.data.expanded=t.data.expanded,o.addAttachmentPoints(t.cloneAttachmentPoints(n)),o}},{key:"addAtom",value:function(e,t,n){e.atoms.push(t),e.isNotContractible(n)&&e.setAttr("expanded",!0)}},{key:"removeAtom",value:function(e,t){if(e)for(var n=0;n<e.atoms.length;++n)if(e.atoms[n]===t)return void e.atoms.splice(n,1)}},{key:"getCrossBonds",value:function(e,t){var n={};return e.bonds.forEach((function(e,o){t.has(e.begin)&&!t.has(e.end)?(n[e.begin]||(n[e.begin]=[]),n[e.begin].push(o)):t.has(e.end)&&!t.has(e.begin)&&(n[e.end]||(n[e.end]=[]),n[e.end].push(o))})),n}},{key:"bracketPos",value:function(e,t,n,o,r){var i=new we(.05*3,.05*3),a=new we(.2,.4),s=e.atoms,u=n?Object.values(n).flat():null;if(u&&2===u.length){var l=t.bonds.get(u[0]).getCenter(t),c=t.bonds.get(u[1]).getCenter(t);e.bracketDirection=we.diff(c,l).normalized()}else e.bracketDirection=new we(1,0);var d=e.bracketDirection,h=null,f=[];s.forEach((function(e){var n,a,s=function(e){return o&&r?o.atoms.get(e):t.atoms.get(e)}(e);"getVBoxObj"in s&&r?a=s.getVBoxObj(r):(n=new we(s.pp),a=new nt(n,n)),f.push(a.extend(i,i))})),f.forEach((function(e){var t=null;[e.p0.x,e.p1.x].forEach((function(n){[e.p0.y,e.p1.y].forEach((function(e){var o=new we(n,e),r=new we(we.dot(o,d),we.dot(o,d.rotateSC(1,0)));t=t?t.include(r):new nt(r,r)}))})),h=h?nt.union(h,t):t})),r||(r=window.ketcher.editor.render);var m=r.ctab.getRGroupAttachmentPointsVBoxByAtomIds(s);m=m?m.extend(i,i):m,(h=m&&h?nt.union(h,m):h)&&(h=h.extend(a,a)),e.bracketBox=h}},{key:"getBracketParameters",value:function(e,t,n,o,r,i){var a,s,u,l,c,d,h=[],f=Object.values(t),m=f.flat();return m.length<2?function(){r=r||new we(1,0),i=i||r.rotateSC(1,0);var e=Math.min(.25,.3*o.sz().x),t=we.lc2(r,o.p0.x,i,.5*(o.p0.y+o.p1.y)),n=we.lc2(r,o.p1.x,i,.5*(o.p0.y+o.p1.y)),a=o.sz().y;h.push(new dt(t,r.negated(),e,a),new dt(n,r,e,a))}():2===m.length&&2===f.length?(a=e.bonds.get(m[0]),s=e.bonds.get(m[1]),u=a.getCenter(e),l=s.getCenter(e),d=(c=we.diff(l,u).normalized()).negated(),h.push(new dt(u.addScaled(d,0),d,.25,1.5),new dt(l.addScaled(c,0),c,.25,1.5))):function(){for(var t=0;t<m.length;++t){var o=e.bonds.get(m[t]),r=o.getCenter(e),i=n.has(o.begin)?o.getDir(e):o.getDir(e).negated();h.push(new dt(r,i,.2,1))}}(),h}},{key:"getObjBBox",value:function(e,t){for(var n=t.atoms.get(e[0]).pp,o=new nt(n,n),r=1;r<e.length;++r){var i=e[r],a=t.atoms.get(i).pp;o=o.include(a)}return o}},{key:"getAtoms",value:function(e,t){if(!t.allAtoms)return t.atoms;var n=[];return e.atoms.forEach((function(e,t){n.push(t)})),n}},{key:"getBonds",value:function(t,n){var o=e.getAtoms(t,n),r=[];return t.bonds.forEach((function(e,t){o.indexOf(e.begin)>=0&&o.indexOf(e.end)>=0&&r.push(t)})),r}},{key:"prepareMulForSaving",value:function(e,t){e.atoms.sort((function(e,t){return e-t})),e.atomSet=new Re(e.atoms),e.parentAtomSet=new Re(e.atomSet);var n=[],o=[];if(t.bonds.forEach((function(t,r){e.parentAtomSet.has(t.begin)&&e.parentAtomSet.has(t.end)?n.push(r):(e.parentAtomSet.has(t.begin)||e.parentAtomSet.has(t.end))&&o.push(r)})),0!==o.length&&2!==o.length)throw Error("Unsupported cross-bonds number");var r=-1,i=-1,a=null;if(2===o.length){var s=t.bonds.get(o[0]);r=e.parentAtomSet.has(s.begin)?s.begin:s.end;var u=t.bonds.get(o[1]);i=e.parentAtomSet.has(u.begin)?u.begin:u.end,a=u}for(var l=i,c=[],d=function(){var o={};if(e.atoms.forEach((function(n){var r=t.atoms.get(n),i=t.atoms.add(new Fe(r));c.push(i),e.atomSet.add(i),o[n]=i})),n.forEach((function(e){var n=t.bonds.get(e),r=new We(n);r.begin=o[r.begin],r.end=o[r.end],t.bonds.add(r)})),null!==a){var s=new We(a);s.begin=l,s.end=o[r],t.bonds.add(s),l=o[i]}},h=0;h<e.data.mul-1;h++)d();if(l>=0){var f=t.bonds.get(o[1]);f.begin===i?f.begin=l:f.end=l}e.bonds=o,c.forEach((function(n){t.sGroupForest.getPathToRoot(e.id).reverse().forEach((function(e){t.atomAddToSGroup(e,n)}))}))}},{key:"getMassCentre",value:function(e,t){for(var n=new we,o=0;o<t.length;++o)n=n.addScaled(e.atoms.get(t[o]).pp,1/t.length);return n}},{key:"isBondInContractedSGroup",value:function(e,t){return(0,o.A)(t.values()).some((function(t){var n="item"in t?t.item:t,o=null==n?void 0:n.atoms;return(null==n?void 0:n.isContracted())&&o.includes(null==e?void 0:e.begin)&&o.includes(null==e?void 0:e.end)}))}},{key:"isSuperAtom",value:function(t){return!!t&&(null==t?void 0:t.type)===e.TYPES.SUP}},{key:"isDataSGroup",value:function(t){return t.type===e.TYPES.DAT}},{key:"isQuerySGroup",value:function(t){return t.type===e.TYPES.queryComponent}},{key:"isSRUSGroup",value:function(t){return t.type===e.TYPES.SRU}},{key:"isMulSGroup",value:function(t){return t.type===e.TYPES.MUL}}]),e}();function ft(e,t){return e.some((function(e){if(!e.pp)return!1;var n=e.pp.add(new we(.5,.5)),o=t.add(new we(.5,.5));return nt.segmentIntersection(e.pp,n,t,o)}))}function mt(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return pt(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?pt(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function pt(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}(0,d.A)(ht,"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",queryComponent:"queryComponent"}),(0,d.A)(ht,"isAtomInContractedSGroup",(function(e,t){var n=[];return t.forEach((function(e){var t="item"in e?e.item:e;t.isContracted()&&n.push(t.id)})),n.some((function(t){return e.sgs.has(t)}))}));var vt=new WeakMap,gt=function(){function e(t){var n,o,r;(0,i.A)(this,e),r={writable:!0,value:void 0},function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(n=this,o=vt),o.set(n,r),f()(null!=t),(0,A.A)(this,vt,t),t.setFunctionalGroup(this)}return(0,a.A)(e,[{key:"name",get:function(){return(0,w.A)(this,vt).data.name}},{key:"relatedSGroupId",get:function(){return(0,w.A)(this,vt).id}},{key:"isExpanded",get:function(){return(0,w.A)(this,vt).data.expanded}},{key:"relatedSGroup",get:function(){return(0,w.A)(this,vt)}}],[{key:"isFunctionalGroup",value:function(e){var t=Je.getInstance().getFunctionalGroupsList(),n=e.data.name;return"SUP"===e.type&&(t.some((function(e){return e.name===n}))||ht.isSaltOrSolvent(n))}},{key:"atomsInFunctionalGroup",value:function(e,t){if(0===e.size)return null;var n,o=mt(e.values());try{for(o.s();!(n=o.n()).done;)if(n.value.relatedSGroup.atoms.includes(t))return t}catch(e){o.e(e)}finally{o.f()}return null}},{key:"bondsInFunctionalGroup",value:function(e,t,n){if(0===t.size)return null;var o,r=mt(t.values());try{for(r.s();!(o=r.n()).done;){var i=o.value;if(ht.getBonds(e,i.relatedSGroup).includes(n))return n}}catch(e){r.e(e)}finally{r.f()}return null}},{key:"isRGroupAttachmentPointInsideFunctionalGroup",value:function(t,n){var o=t.rgroupAttachmentPoints.get(n);f()(null!=o);var r=o.atomId;return e.atomsInFunctionalGroup(t.functionalGroups,r)}},{key:"findFunctionalGroupByAtom",value:function(e,t,n){var o,r=mt(e.values());try{for(r.s();!(o=r.n()).done;){var i=o.value;if(i.relatedSGroup.atoms.includes(t))return n?i:i.relatedSGroupId}}catch(e){r.e(e)}finally{r.f()}return null}},{key:"findFunctionalGroupByBond",value:function(e,t,n,o){var r,i=mt(t.values());try{for(i.s();!(r=i.n()).done;){var a=r.value;if(ht.getBonds(e,a.relatedSGroup).includes(n))return o?a:a.relatedSGroupId}}catch(e){i.e(e)}finally{i.f()}return null}},{key:"findFunctionalGroupBySGroup",value:function(e,t){var n=e.find((function(e,n){return n.relatedSGroupId===(null==t?void 0:t.id)}));return null!==n?e.get(n):void 0}},{key:"clone",value:function(t){return new e((0,w.A)(t,vt))}},{key:"isAtomInContractedFunctionalGroup",value:function(t,n,o,r){var i=[];return r?n.forEach((function(t){e.isContractedFunctionalGroup(t.item,o)&&i.push(t.item.id)})):n.forEach((function(t){e.isContractedFunctionalGroup(t,o)&&i.push(t.id)})),i.some((function(e){return t.sgs.has(e)}))}},{key:"isBondInContractedFunctionalGroup",value:function(t,n,r){return(0,o.A)(n.values()).some((function(n){var o="item"in n?null==n?void 0:n.item:n,i=null==o?void 0:o.atoms;return e.isContractedFunctionalGroup(o,r)&&i.includes(t.begin)&&i.includes(t.end)}))}},{key:"isHalfBondInContractedFunctionalGroup",value:function(e,t){var n=t.bonds.get(e.bid);return f()(null!=n),this.isBondInContractedFunctionalGroup(n,t.sgroups,t.functionalGroups)}},{key:"isContractedFunctionalGroup",value:function(e,t){var n=!1,o=!1;return e instanceof ht?e.functionalGroup&&(n=!0,o=e.functionalGroup.isExpanded):t.forEach((function(t){t.relatedSGroupId===e&&(n=!0,o=t.isExpanded)})),!o&&n}}]),e}(),yt=(0,a.A)((function e(t,n,o){(0,i.A)(this,e),f()(3===arguments.length,"Invalid parameter number."),this.begin=t,this.end=n,this.bid=o,this.dir=new we,this.norm=new we,this.ang=0,this.p=new we,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})),bt=(0,a.A)((function e(t,n,o){var r=this;(0,i.A)(this,e),this.hbs=t,this.dblBonds=0,this.aromatic=!0,this.convex=o||!1,t.forEach((function(e){var t=n.bonds.get(n.halfBonds.get(e).bid);t.type!==We.PATTERN.TYPE.AROMATIC&&(r.aromatic=!1),t.type===We.PATTERN.TYPE.DOUBLE&&r.dblBonds++}))})),At=function(){function e(t){(0,i.A)(this,e),this.frags=new Re,this.resth=(null==t?void 0:t.resth)||!1,this.range=(null==t?void 0:t.range)||"",this.ifthen=(null==t?void 0:t.ifthen)||0,this.index=(null==t?void 0:t.index)||-1}return(0,a.A)(e,[{key:"getAttrs",value:function(){return{resth:this.resth,range:this.range,ifthen:this.ifthen,index:this.index}}},{key:"clone",value:function(t){var n=new e(this);return this.frags.forEach((function(e){t&&!t.has(e)||n.frags.add(t?t.get(e):e)})),n}}],[{key:"findRGroupByFragment",value:function(e,t){return e.find((function(e,n){return n.frags.has(t)}))}}]),e}();function wt(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Et()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Et(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Et=function(){return!!e})()}var Pt,xt=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=wt(this,t,[o])).atomId=e,r.type=n,r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"clone",value:function(e){var n=null==e?void 0:e.get(this.atomId);return new t(null!=n?n:this.atomId,this.type,this.initiallySelected)}}]),t}(Be);function St(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Ot()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Ot(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Ot=function(){return!!e})()}!function(e){e.OpenAngle="open-angle",e.FilledTriangle="filled-triangle",e.FilledBow="filled-bow",e.DashedOpenAngle="dashed-open-angle",e.Failed="failed",e.BothEndsFilledTriangle="both-ends-filled-triangle",e.EquilibriumFilledTriangle="equilibrium-filled-triangle",e.EquilibriumFilledHalfBow="equilibrium-filled-half-bow",e.EquilibriumOpenAngle="equilibrium-open-angle",e.UnbalancedEquilibriumFilledHalfBow="unbalanced-equilibrium-filled-half-bow",e.UnbalancedEquilibriumOpenHalfAngle="unbalanced-equilibrium-open-half-angle",e.UnbalancedEquilibriumLargeFilledHalfBow="unbalanced-equilibrium-large-filled-half-bow",e.UnbalancedEquilibriumFilledHalfTriangle="unbalanced-equilibrium-filled-half-triangle",e.EllipticalArcFilledBow="elliptical-arc-arrow-filled-bow",e.EllipticalArcFilledTriangle="elliptical-arc-arrow-filled-triangle",e.EllipticalArcOpenAngle="elliptical-arc-arrow-open-angle",e.EllipticalArcOpenHalfAngle="elliptical-arc-arrow-open-half-angle"}(Pt||(Pt={}));var kt=function(e){function t(e){var n,o;if((0,i.A)(this,t),(n=St(this,t,[null==e?void 0:e.initiallySelected])).pos=[],e.pos)for(var r=0;r<e.pos.length;r++){var a=e.pos[r];n.pos[r]=a?new we(e.pos[r]):new we}return n.mode=e.mode,t.isElliptical((0,l.A)(n))&&(n.height=null!==(o=e.height)&&void 0!==o?o:2),n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"clone",value:function(){return new t(this)}},{key:"center",value:function(){return we.centre(this.pos[0],this.pos[1])}}],[{key:"isElliptical",value:function(e){return[Pt.EllipticalArcFilledBow,Pt.EllipticalArcFilledTriangle,Pt.EllipticalArcOpenHalfAngle,Pt.EllipticalArcOpenAngle].includes(e.mode)}}]),t}(Be);function Mt(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Rt()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Rt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Rt=function(){return!!e})()}var Tt,Bt=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Mt(this,t,[null==e?void 0:e.initiallySelected])).pp=null!=e&&e.pp?new we(e.pp):new we,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"clone",value:function(){return new t(this)}}]),t}(Be),Ct=function(){function e(){(0,i.A)(this,e),this.parent=new Map,this.children=new Map,this.children.set(-1,[]),this.atomSets=new Map}return(0,a.A)(e,[{key:"getSGroupsBFS",value:function(){for(var e=[],t=Array.from(this.children.get(-1));t.length>0;){var n=t.shift();if("number"!=typeof n)break;var o=this.children.get(n);if(void 0===o)break;o.forEach((function(e){t.push(e)})),e.push(n)}return e}},{key:"getAtomSetRelations",value:function(e,t){var n=this,o=new Map,r=new Map;this.atomSets.delete(e),this.atomSets.forEach((function(e,n){r.set(n,e.isSuperset(t)),o.set(n,t.isSuperset(e)&&!e.equals(t))}));var i=Array.from(this.atomSets.keys()).filter((function(e){if(!r.get(e))return!1;var t=n.children.get(e);return t&&t.findIndex((function(e){return r.get(e)}))<0})),a=Array.from(this.atomSets.keys()).filter((function(e){return o.get(e)&&!o.get(n.parent.get(e))}));return{children:a,parent:0===i.length?-1:i[0]}}},{key:"getPathToRoot",value:function(e){for(var t=[],n=e;n>=0;n=this.parent.get(n))t.push(n);return t}},{key:"insert",value:function(e,t,n){var o,r=this,i=e.id,a=e.atoms;if(f()(!this.parent.has(i),"sgid already present in the forest"),f()(!this.children.has(i),"sgid already present in the forest"),!t||!n){var s=this.getAtomSetRelations(i,new Re(a));t=s.parent,n=s.children}return n.forEach((function(e){r.resetParentLink(e,i)})),this.children.set(i,n.filter((function(e){return r.parent.get(e)}))),this.parent.set(i,t),null===(o=this.children.get(t))||void 0===o||o.push(i),this.atomSets.set(i,new Re(a)),{parent:t,children:n}}},{key:"resetParentLink",value:function(e,t){var n=this.parent.get(e);if(void 0!==n){var o=this.children.get(n);if(o){var r=o.indexOf(e);o.splice(r,1),this.parent.set(e,t)}}}},{key:"remove",value:function(e){var t,n=this;try{f()(this.parent.has(e),"sgid is not in the forest"),f()(this.children.has(e),"sgid is not in the forest")}catch(e){q.error("sgroupForest.ts::SGroupForest::remove",e)}var o=this.parent.get(e),r=this.children.get(o);if(o&&r){null===(t=this.children.get(e))||void 0===t||t.forEach((function(e){var t;n.parent.set(e,o),null===(t=n.children.get(o))||void 0===t||t.push(e)}));var i=r.indexOf(e);r.splice(i,1),this.children.delete(e),this.parent.delete(e),this.atomSets.delete(e)}}}]),e}();function It(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2?arguments[2]:void 0,o={common:function(n){var o=e.sgroups.get(n);if("DAT"===(null==o?void 0:o.type))return!1;var r=ht.getAtoms(e,o);return r.length<t.length?r.findIndex((function(e){return-1===t.indexOf(e)}))>=0:t.findIndex((function(e){return-1===r.indexOf(e)}))>=0},queryComponent:function(n){var o=e.sgroups.get(n);if("queryComponent"!==(null==o?void 0:o.type))return!1;var r=ht.getAtoms(e,o);return t.some((function(e){return r.includes(e)}))}},r=t.reduce((function(t,n){var o=e.atoms.get(n);return o?t.union(o.sgs):t}),new Re);return Array.from(r).some(o[n])}function Nt(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Dt()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Dt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Dt=function(){return!!e})()}!function(e){e.ellipse="ellipse",e.rectangle="rectangle",e.line="line"}(Tt||(Tt={}));var Lt=function(e){function t(e){var n;if((0,i.A)(this,t),(n=Nt(this,t,[null==e?void 0:e.initiallySelected])).pos=[],null!=e&&e.pos)for(var o=0;o<e.pos.length;o++){var r=e.pos[o];n.pos[o]=r?new we(e.pos[o]):new we}return n.mode=(null==e?void 0:e.mode)||Tt.line,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"clone",value:function(){return new t(this)}},{key:"center",value:function(){return this.mode===Tt.rectangle?we.centre(this.pos[0],this.pos[1]):this.pos[0]}}]),t}(Be);function _t(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return Ft(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ft(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function Ft(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function Ht(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,jt()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function jt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(jt=function(){return!!e})()}var Gt=function(e){function t(){var e;(0,i.A)(this,t);for(var n=arguments.length,o=new Array(n),r=0;r<n;r++)o[r]=arguments[r];return e=Ht(this,t,[].concat(o)),(0,d.A)((0,l.A)(e),"nextId",0),e}return(0,c.A)(t,e),(0,a.A)(t,[{key:"add",value:function(e){var n=this.nextId++;return(0,E.A)((0,u.A)(t.prototype),"set",this).call(this,n,e),n}},{key:"newId",value:function(){return this.nextId++}},{key:"keyOf",value:function(e){var t,n=_t(this.entries());try{for(n.s();!(t=n.n()).done;){var o=(0,r.A)(t.value,2),i=o[0];if(o[1]===e)return i}}catch(e){n.e(e)}finally{n.f()}return null}},{key:"find",value:function(e){var t,n=_t(this.entries());try{for(n.s();!(t=n.n()).done;){var o=(0,r.A)(t.value,2),i=o[0];if(e(i,o[1]))return i}}catch(e){n.e(e)}finally{n.f()}return null}},{key:"filter",value:function(e){return new t(Array.from(this).filter((function(t){var n=(0,r.A)(t,2),o=n[0],i=n[1];return e(o,i)})))}},{key:"some",value:function(e){var t,n=_t(this.values());try{for(n.s();!(t=n.n()).done;)if(e(t.value))return!0}catch(e){n.e(e)}finally{n.f()}return!1}},{key:"changeInitiallySelectedPropertiesForPool",value:function(e){var t=this;this.forEach((function(n,o){"function"==typeof n.resetInitiallySelected&&(n.resetInitiallySelected(e),t.set(o,n))}))}}]),t}((0,b.A)(Map));function zt(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Vt()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Vt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Vt=function(){return!!e})()}var Ut=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=zt(this,t,[e])).monomer=n,o.data.absolute=!1,o.data.attached=!1,o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"getContractedPosition",value:function(e){f()(this.pp);var n=(0,E.A)((0,u.A)(t.prototype),"getContractedPosition",this).call(this,e);return{position:this.pp,atomId:n.atomId}}}],[{key:"clone",value:function(e){var n=new t(e.type,e.monomer);return n.pp=e.pp,n.atoms=e.atoms,n}}]),t}(ht);function Wt(e,t){for(var n=0;n<e.length;++n)if(e[n]===t)return!1;return e.push(t),!0}var qt,Yt=function(){function e(){(0,i.A)(this,e),this.atoms=new Gt,this.bonds=new Gt,this.sgroups=new Gt,this.halfBonds=new Gt,this.loops=new Gt,this.isReaction=!1,this.rxnArrows=new Gt,this.rxnPluses=new Gt,this.frags=new Gt,this.rgroups=new Gt,this.rgroupAttachmentPoints=new Gt,this.name="",this.abbreviation="",this.sGroupForest=new Ct,this.simpleObjects=new Gt,this.texts=new Gt,this.functionalGroups=new Gt,this.highlights=new Gt}return(0,a.A)(e,[{key:"hasRxnProps",value:function(){return!(!this.atoms.find((function(e,t){return t.hasRxnProps()}))&&!this.bonds.find((function(e,t){return t.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:"isSingleGroup",value:function(){if(!this.sgroups.size||this.sgroups.size>1)return!1;var e=this.sgroups.values().next().value;return this.atoms.size===e.atoms.length}},{key:"clone",value:function(t,n,o,r,i,a,s,u){return this.mergeInto(new e,t,n,o,!1,r,i,a,s,u)}},{key:"getScaffold",value:function(){var e=this,t=new Re;return this.atoms.forEach((function(e,n){t.add(n)})),this.rgroups.forEach((function(n){n.frags.forEach((function(n,o){e.atoms.forEach((function(e,n){e.fragment===o&&t.delete(n)}))}))})),this.clone(t)}},{key:"getFragmentIds",value:function(e){var t=new Re,n=Array.isArray(e)?e:[e];return this.atoms.forEach((function(e,o){n.includes(e.fragment)&&t.add(o)})),t}},{key:"getFragment",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return this.clone(this.getFragmentIds(e),null,!0,void 0,t?void 0:new Re,t?void 0:new Re,t?void 0:new Re)}},{key:"mergeInto",value:function(e,t,n,o,r,i,a,s,u,l){var c=this;t=t||new Re(this.atoms.keys()),n=n||new Re(this.bonds.keys()),a=a||new Re(this.simpleObjects.keys()),s=s||new Re(this.texts.keys()),u=u||new Re(this.rgroupAttachmentPoints.keys()),i=i||new Map;var d=l||new Map;n=n.filter((function(e){var n=c.bonds.get(e);return t.has(n.begin)&&t.has(n.end)}));var h=new Re;this.atoms.forEach((function(e,n){t.has(n)&&h.add(e.fragment)}));var m=new Map;this.frags.forEach((function(t,n){h.has(n)&&m.set(n,e.frags.add(null))}));var p=[];this.rgroups.forEach((function(t,n){var o=r;if(o||(t.frags.forEach((function(e,t){p.push(t),h.has(t)&&(o=!0)})),o)){var i=e.rgroups.get(n);i?t.frags.forEach((function(e,t){p.push(t),h.has(t)&&i.frags.add(m.get(t))})):e.rgroups.set(n,t.clone(m))}})),this.atoms.forEach((function(n,o){t.has(o)&&-1===p.indexOf(n.fragment)&&i.set(o,e.atoms.add(n.clone(m)))})),this.atoms.forEach((function(n,o){t.has(o)&&-1!==p.indexOf(n.fragment)&&i.set(o,e.atoms.add(n.clone(m)))})),m.forEach((function(t,n){var o=c.frags.get(n);o&&o instanceof Ke&&e.frags.set(t,c.frags.get(n).clone(i))})),this.bonds.forEach((function(t,o){n.has(o)&&d.set(o,e.bonds.add(t.clone(i)))}));var v={};return this.sgroups.forEach((function(n,o){if(!n.atoms.some((function(e){return!t.has(e)}))){var r=n;n=r instanceof Ut?Ut.clone(r):ht.clone(n,i);var a=e.sgroups.add(n);n.id=a,v[o]=a,n.atoms.forEach((function(t){var n=e.atoms.get(t);n&&n.sgs.add(a)})),"DAT"===n.type?e.sGroupForest.insert(n,-1,[]):e.sGroupForest.insert(n)}})),this.functionalGroups.forEach((function(n){if(!n.relatedSGroup.atoms.some((function(e){return!t.has(e)}))){var o=e.sgroups.get(v[n.relatedSGroupId]);n=o?new gt(o):gt.clone(n),e.functionalGroups.add(n)}})),a.forEach((function(t){e.simpleObjects.add(c.simpleObjects.get(t).clone())})),s.forEach((function(t){e.texts.add(c.texts.get(t).clone())})),u.forEach((function(t){var n=c.rgroupAttachmentPoints.get(t);f()(null!=n),e.rgroupAttachmentPoints.add(n.clone(i))})),o||(e.isReaction=this.isReaction,this.rxnArrows.forEach((function(t){e.rxnArrows.add(t.clone())})),this.rxnPluses.forEach((function(t){e.rxnPluses.add(t.clone())}))),e.name=this.name,e}},{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(e,t){ht.addAtom(this.sgroups.get(e),t,this),this.atoms.get(t).sgs.add(e)}},{key:"calcConn",value:function(e){for(var t=0,n=0;n<e.neighbors.length;++n){var o=this.halfBonds.get(e.neighbors[n]);switch(this.bonds.get(o.bid).type){case We.PATTERN.TYPE.SINGLE:t+=1;break;case We.PATTERN.TYPE.DOUBLE:t+=2;break;case We.PATTERN.TYPE.TRIPLE:t+=3;break;case We.PATTERN.TYPE.DATIVE:case We.PATTERN.TYPE.HYDROGEN:break;case We.PATTERN.TYPE.AROMATIC:return 1===e.neighbors.length?[-1,!0]:[e.neighbors.length,!0];default:return[-1,!1]}}return[t,!1]}},{key:"findBondId",value:function(e,t){return this.bonds.find((function(n,o){return o.begin===e&&o.end===t||o.begin===t&&o.end===e}))}},{key:"initNeighbors",value:function(){var e=this;this.atoms.forEach((function(e){e.neighbors=[]})),this.bonds.forEach((function(t){var n=e.atoms.get(t.begin),o=e.atoms.get(t.end);n.neighbors.push(t.hb1),o.neighbors.push(t.hb2)}))}},{key:"bondInitHalfBonds",value:function(e,t){(t=t||this.bonds.get(e)).hb1=2*e,t.hb2=2*e+1,this.halfBonds.set(t.hb1,new yt(t.begin,t.end,e)),this.halfBonds.set(t.hb2,new yt(t.end,t.begin,e));var n=this.halfBonds.get(t.hb1),o=this.halfBonds.get(t.hb2);n.contra=t.hb2,o.contra=t.hb1}},{key:"halfBondUpdate",value:function(e){var t=this.halfBonds.get(e),n=this.getGroupFromAtomId(t.begin),o=this.getGroupFromAtomId(t.end),r=n instanceof Ut?n.pp:this.atoms.get(t.begin).pp,i=o instanceof Ut?o.pp:this.atoms.get(t.end).pp,a=we.diff(i,r).normalized();t.dir=we.dist(i,r)>1e-4?a:new we(1,0),t.norm=t.dir.turnLeft(),t.ang=t.dir.oxAngle(),t.loop<0&&(t.loop=-1)}},{key:"initHalfBonds",value:function(){var e=this;this.halfBonds.clear(),this.bonds.forEach((function(t,n){e.bondInitHalfBonds(n,t)}))}},{key:"setHbNext",value:function(e,t){this.halfBonds.get(this.halfBonds.get(e).contra).next=t}},{key:"halfBondSetAngle",value:function(e,t){var n=this.halfBonds.get(e),o=this.halfBonds.get(t);o.rightCos=we.dot(o.dir,n.dir),n.leftCos=we.dot(o.dir,n.dir),o.rightSin=we.cross(o.dir,n.dir),n.leftSin=we.cross(o.dir,n.dir),n.leftNeighbor=t,o.rightNeighbor=e}},{key:"atomAddNeighbor",value:function(e){var t,n=this.halfBonds.get(e),o=this.atoms.get(n.begin);for(t=0;t<o.neighbors.length&&!(this.halfBonds.get(o.neighbors[t]).ang>n.ang);++t);o.neighbors.splice(t,0,e);var r=o.neighbors[(t+1)%o.neighbors.length],i=o.neighbors[(t+o.neighbors.length-1)%o.neighbors.length];this.setHbNext(i,e),this.setHbNext(e,r),this.halfBondSetAngle(e,i),this.halfBondSetAngle(r,e)}},{key:"atomSortNeighbors",value:function(e){var t=this,n=this.atoms.get(e),o=this.halfBonds;n.neighbors.sort((function(e,t){return o.get(e).ang-o.get(t).ang})).forEach((function(e,o){var r=n.neighbors[(o+1)%n.neighbors.length];t.halfBonds.get(t.halfBonds.get(e).contra).next=r,t.halfBondSetAngle(r,e)}))}},{key:"sortNeighbors",value:function(e){var t=this;e?e.forEach((function(e){t.atomSortNeighbors(e)})):this.atoms.forEach((function(e,n){t.atomSortNeighbors(n)}))}},{key:"atomUpdateHalfBonds",value:function(e){var t=this;this.atoms.get(e).neighbors.forEach((function(e){t.halfBondUpdate(e),t.halfBondUpdate(t.halfBonds.get(e).contra)}))}},{key:"updateHalfBonds",value:function(e){var t=this;e?e.forEach((function(e){t.atomUpdateHalfBonds(e)})):this.atoms.forEach((function(e,n){t.atomUpdateHalfBonds(n)}))}},{key:"sGroupsRecalcCrossBonds",value:function(){var e=this;this.sgroups.forEach((function(e){e.xBonds=[],e.neiAtoms=[]})),this.bonds.forEach((function(t,n){var o=e.atoms.get(t.begin),r=e.atoms.get(t.end);o.sgs.forEach((function(o){if(!r.sgs.has(o)){var i=e.sgroups.get(o);i.xBonds.push(n),Wt(i.neiAtoms,t.end)}})),r.sgs.forEach((function(r){if(!o.sgs.has(r)){var i=e.sgroups.get(r);i.xBonds.push(n),Wt(i.neiAtoms,t.begin)}}))}))}},{key:"sGroupDelete",value:function(e){var t=this;this.sgroups.get(e).atoms.forEach((function(n){t.atoms.get(n).sgs.delete(e)})),this.sGroupForest.remove(e),this.sgroups.delete(e)}},{key:"atomSetPos",value:function(e,t){this.atoms.get(e).pp=t}},{key:"rxnPlusSetPos",value:function(e,t){this.rxnPluses.get(e).pp=t}},{key:"rxnArrowSetPos",value:function(e,t){var n=this.rxnArrows.get(e);n&&(n.pos=t)}},{key:"simpleObjectSetPos",value:function(e,t){this.simpleObjects.get(e).pos=t}},{key:"textSetPosition",value:function(e,t){var n=this.texts.get(e);n&&(n.position=t)}},{key:"getCoordBoundingBox",value:function(e){var t=null;function n(e){t?e instanceof Array?e.forEach((function(e){t.min=we.min(t.min,e),t.max=we.max(t.max,e)})):(t.min=we.min(t.min,e),t.max=we.max(t.max,e)):t={min:e,max:e}}var o=!e||0===e.size;return this.atoms.forEach((function(t,r){(o||e.has(r))&&n(t.pp)})),o&&(this.rxnPluses.forEach((function(e){n(e.pp)})),this.rxnArrows.forEach((function(e){n(e.pos)})),this.simpleObjects.forEach((function(e){n(e.pos)})),this.texts.forEach((function(e){n(e.position)}))),!t&&o&&(t={min:new we(0,0),max:new we(1,1)}),t}},{key:"getCoordBoundingBoxObj",value:function(){var e=null;return this.atoms.forEach((function(t){var n;n=t.pp,e?(e.min=we.min(e.min,n),e.max=we.max(e.max,n)):e={min:new we(n),max:new we(n)}})),e}},{key:"getBondLengthData",value:function(){var e=this,t=0,n=0;return this.bonds.forEach((function(o){t+=we.dist(e.atoms.get(o.begin).pp,e.atoms.get(o.end).pp),n++})),{cnt:n,totalLength:t}}},{key:"getAvgBondLength",value:function(){var e=this.getBondLengthData();return e.cnt>0?e.totalLength/e.cnt:-1}},{key:"getAvgClosestAtomDistance",value:function(){var e,t,n,o=0,r=0,i=Array.from(this.atoms.keys());for(t=0;t<i.length;++t){for(e=-1,n=0;n<i.length;++n)n!==t&&(r=we.dist(this.atoms.get(i[n]).pp,this.atoms.get(i[t]).pp),(e<0||e>r)&&(e=r));o+=e}return i.length>0?o/i.length:-1}},{key:"checkBondExists",value:function(e,t){return void 0!==this.bonds.find((function(n,o){return o.begin===e&&o.end===t||o.end===e&&o.begin===t}))}},{key:"findConnectedComponent",value:function(e){for(var t=this,n=[e],o=new Re;n.length>0;){var r=n.pop();o.add(r),this.atoms.get(r).neighbors.forEach((function(e){var r=t.halfBonds.get(e).end;o.has(r)||n.push(r)}))}return o}},{key:"findConnectedComponents",value:function(e){var t=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 Re,o=[];return this.atoms.forEach((function(r,i){if((e||r.fragment<0)&&!n.has(i)){var a=t.findConnectedComponent(i);o.push(a),n=n.union(a)}})),o}},{key:"markFragment",value:function(e,t){var n=this,o=new Ke([],void 0,t),r=this.frags.add(o);e.forEach((function(e){var t=n.atoms.get(e);t.stereoLabel&&o.updateStereoAtom(n,e,r,!0),t.fragment=r}))}},{key:"markFragments",value:function(e){var t=this;this.findConnectedComponents().forEach((function(n){var o=(0,r.A)(n,1)[0];t.getGroupFromAtomId(o)instanceof Ut||t.markFragment(n,e)}))}},{key:"scale",value:function(e){1!==e&&(this.atoms.forEach((function(t){t.pp=t.pp.scaled(e)})),this.rxnPluses.forEach((function(t){t.pp=t.pp.scaled(e)})),this.rxnArrows.forEach((function(t){t.pos=t.pos.map((function(t){return t.scaled(e)}))})),this.sgroups.forEach((function(t){t instanceof Ut||(t.pp=t.pp?t.pp.scaled(e):null)})),this.texts.forEach((function(t){t.pos=t.pos.map((function(t){return t.scaled(e)})),t.position=t.position.scaled(e)})),this.simpleObjects.forEach((function(t){t.pos=t.pos.map((function(t){return t.scaled(e)}))})))}},{key:"rescale",value:function(){var e=this.getAvgBondLength();if(!(e<=0)){e<.001&&(e=1);var t=1/e;this.scale(t)}}},{key:"loopHasSelfIntersections",value:function(e){for(var t=0;t<e.length;++t)for(var n=this.halfBonds.get(e[t]),o=this.atoms.get(n.begin).pp,r=this.atoms.get(n.end).pp,i=new Re([n.begin,n.end]),a=t+2;a<e.length;++a){var s=this.halfBonds.get(e[a]);if(!i.has(s.begin)&&!i.has(s.end)){var u=this.atoms.get(s.begin).pp,l=this.atoms.get(s.end).pp;if(nt.segmentIntersection(o,r,u,l))return!0}}return!1}},{key:"partitionLoop",value:function(e){for(var t=[],n=!0;n;){var o={};n=!1;for(var r=0;r<e.length;++r){var i=e[r],a=this.halfBonds.get(i).begin,s=this.halfBonds.get(i).end;if(s in o){var u=o[s],l=e.slice(u,r+1);t.push(l),r<e.length&&e.splice(u,r-u+1),n=!0;break}o[a]=r}n||t.push(e)}return t}},{key:"halfBondAngle",value:function(e,t){var n=this.halfBonds.get(e),o=this.halfBonds.get(t);return Math.atan2(we.cross(n.dir,o.dir),we.dot(n.dir,o.dir))}},{key:"loopIsConvex",value:function(e){var t=this;return e.every((function(e,n,o){return t.halfBondAngle(e,o[(n+1)%o.length])<=0}))}},{key:"loopIsInner",value:function(e){var t=this,n=2*Math.PI;return e.forEach((function(e,o,r){var i=r[(o+1)%r.length],a=t.halfBonds.get(i),s=t.halfBondAngle(e,i);n+=a.contra===e?Math.PI:s})),Math.abs(n)<Math.PI}},{key:"findLoops",value:function(){var e,t,n,r=this,i=[],a=new Re;return this.halfBonds.forEach((function(s,u){if(-1===s.loop)for(e=u,t=0,n=[];t<=r.halfBonds.size;e=r.halfBonds.get(e).next,++t){if(t>0&&e===u){r.partitionLoop(n).forEach((function(e){var t;r.loopIsInner(e)&&!r.loopHasSelfIntersections(e)?(t=Math.min.apply(Math,(0,o.A)(e)),r.loops.set(t,new bt(e,r,r.loopIsConvex(e)))):t=-2,e.forEach((function(e){r.halfBonds.get(e).loop=t,a.add(r.halfBonds.get(e).bid)})),t>=0&&i.push(t)}));break}n.push(e)}})),{newLoops:i,bondsToMark:Array.from(a)}}},{key:"calcImplicitHydrogen",value:function(e){var t=this.atoms.get(e),n=t.charge||0,o=this.calcConn(t),i=(0,r.A)(o,2),a=i[0],s=i[1],u=a;if(t.badConn=!1,s)if("C"===t.label&&0===n){if(3===a)return void(t.implicitH=-He(t.radical));if(2===a)return void(t.implicitH=1-He(t.radical))}else{if("O"===t.label&&0===n||"N"===t.label&&0===n&&3===a||"N"===t.label&&1===n&&3===a||"S"===t.label&&0===n&&3===a||!t.implicitH)return void(t.implicitH=0);t.hasImplicitH||u++}if(u<0||t.isQuery()||t.attachmentPoints)t.implicitH=0;else if(t.explicitValence>=0){var l=_.get(t.label);t.implicitH=l?t.explicitValence-t.calcValenceMinusHyd(u):0,t.implicitH<0&&(t.implicitH=0,t.badConn=!0)}else t.calcValence(u)}},{key:"setImplicitHydrogen",value:function(e){var t=this;this.sgroups.forEach((function(e){"MRV_IMPLICIT_H"===e.data.fieldName&&(t.atoms.get(e.atoms[0]).hasImplicitH=!0)})),e?e.forEach((function(e){t.atoms.get(e)&&t.calcImplicitHydrogen(e)})):this.atoms.forEach((function(e,n){t.calcImplicitHydrogen(n)}))}},{key:"atomGetNeighbors",value:function(e){var t,n=this;return null===(t=this.atoms.get(e))||void 0===t?void 0:t.neighbors.map((function(e){var t=n.halfBonds.get(e);return{aid:t.end,bid:t.bid}}))}},{key:"getComponents",value:function(){var e=this,t=this.findConnectedComponents(!0),n=[],o=null;this.rxnArrows.forEach((function(e){o=e.center().x})),this.rxnPluses.forEach((function(e){n.push(e.pp.x)})),null!==o&&n.push(o),n.sort((function(e,t){return e-t}));var r=[];t.forEach((function(t){for(var o=e.getCoordBoundingBox(t),i=we.lc2(o.min,.5,o.max,.5),a=0;i.x>n[a];)++a;r[a]=r[a]||new Re,r[a]=r[a].union(t)}));var i=[],a=[];return r.forEach((function(t){t&&(1===e.defineRxnFragmentTypeForAtomset(t,o||0)?i.push(t):a.push(t))})),{reactants:i,products:a}}},{key:"defineRxnFragmentTypeForAtomset",value:function(e,t){var n=this.getCoordBoundingBox(e);return we.lc2(n.min,.5,n.max,.5).x<t?1:2}},{key:"getBondFragment",value:function(e){var t,n,o=null===(t=this.bonds.get(e))||void 0===t?void 0:t.begin;return o&&(null===(n=this.atoms.get(o))||void 0===n?void 0:n.fragment)}},{key:"bindSGroupsToFunctionalGroups",value:function(){var e=this;this.sgroups.forEach((function(t){(gt.isFunctionalGroup(t)||ht.isSuperAtom(t))&&e.functionalGroups.add(new gt(t))}))}},{key:"getGroupIdFromAtomId",value:function(e){for(var t=0,n=Array.from(this.sgroups);t<n.length;t++){var o=(0,r.A)(n[t],2),i=o[0];if(o[1].atoms.includes(e))return i}return null}},{key:"getGroupFromAtomId",value:function(e){var t,n=this.getGroupIdFromAtomId(e);return null===(t=this.sgroups)||void 0===t?void 0:t.get(n)}},{key:"getGroupIdFromBondId",value:function(e){var t=this.bonds.get(e);if(!t)return null;for(var n=0,o=Array.from(this.sgroups);n<o.length;n++){var i=(0,r.A)(o[n],2),a=i[0],s=i[1];if(s.atoms.includes(t.begin)||s.atoms.includes(t.end))return a}return null}},{key:"getGroupsIdsFromBondId",value:function(e){var t=this.bonds.get(e);if(!t)return[];for(var n=[],o=0,i=Array.from(this.sgroups);o<i.length;o++){var a=(0,r.A)(i[o],2),s=a[0],u=a[1];(u.atoms.includes(t.begin)||u.atoms.includes(t.end))&&n.push(s)}return n}},{key:"getBondIdByHalfBond",value:function(e){var t=this.halfBonds.get(e);if(t)return t.bid}},{key:"getSelectedVisibleAtoms",value:function(e){var t,n=this;return(null==e||null===(t=e.atoms)||void 0===t?void 0:t.filter((function(e){var t=n.atoms.get(e);if(!t)return!1;if(!gt.isAtomInContractedFunctionalGroup(t,n.sgroups,n.functionalGroups,!1))return!0;var o=n.getGroupIdFromAtomId(e),r=n.sgroups.get(o);return(null==r?void 0:r.getAttachmentAtomId())===e})))||[]}},{key:"getRGroupAttachmentPointsByAtomId",value:function(e){var t=this.rgroupAttachmentPoints.filter((function(t,n){return n.atomId===e}));return(0,o.A)(t.keys())}},{key:"isAtomFromMacromolecule",value:function(e){return this.getGroupFromAtomId(e)instanceof Ut}},{key:"isBondFromMacromolecule",value:function(e){var t=this.bonds.get(e);return f()(t),this.isAtomFromMacromolecule(t.begin)||this.isAtomFromMacromolecule(t.end)}},{key:"isFunctionalGroupFromMacromolecule",value:function(e){var t=this.functionalGroups.get(e);return(null==t?void 0:t.relatedSGroup)instanceof Ut}},{key:"isTargetFromMacromolecule",value:function(e){return e&&("functionalGroups"===e.map&&this.isFunctionalGroupFromMacromolecule(e.id)||"atoms"===e.map&&this.isAtomFromMacromolecule(e.id)||"bonds"===e.map&&this.isBondFromMacromolecule(e.id))}},{key:"disableInitiallySelected",value:function(){this.atoms.changeInitiallySelectedPropertiesForPool(!0),this.bonds.changeInitiallySelectedPropertiesForPool(!0),this.rxnPluses.changeInitiallySelectedPropertiesForPool(!0),this.rxnArrows.changeInitiallySelectedPropertiesForPool(!0),this.texts.changeInitiallySelectedPropertiesForPool(!0)}},{key:"enableInitiallySelected",value:function(){this.atoms.changeInitiallySelectedPropertiesForPool(),this.bonds.changeInitiallySelectedPropertiesForPool(),this.rxnPluses.changeInitiallySelectedPropertiesForPool(),this.rxnArrows.changeInitiallySelectedPropertiesForPool(),this.texts.changeInitiallySelectedPropertiesForPool()}}]),e}();function $t(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Xt()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Xt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Xt=function(){return!!e})()}!function(e){e.Bold="BOLD",e.Italic="ITALIC",e.Subscript="SUBSCRIPT",e.Superscript="SUPERSCRIPT",e.FontSize="CUSTOM_FONT_SIZE"}(qt||(qt={}));var Kt=function(e){function t(e){var n,o;return(0,i.A)(this,t),(n=$t(this,t,[null==e?void 0:e.initiallySelected])).pos=(o=null==e?void 0:e.pos)&&o.length?o.map((function(e){return new we(e)})):[new we,new we,new we,new we],n.content=(null==e?void 0:e.content)||"",n.position=null!=e&&e.position?new we(e.position):new we,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"setPos",value:function(e){this.pos=e||[]}},{key:"clone",value:function(){return new t(this)}}]),t}(Be),Zt=(0,a.A)((function e(t){(0,i.A)(this,e);var n=t.atoms,o=t.bonds,r=t.color;this.color=r,this.atoms=n,this.bonds=o})),Qt=function(){function e(t,n,o){(0,i.A)(this,e),this.atomId=t,this.leaveAtomId=n,this.attachmentId=o}return(0,a.A)(e,[{key:"clone",value:function(t){var n=t.get(this.atomId);return f()(null!=n),new e(n,t.get(this.leaveAtomId),this.attachmentId)}},{key:"convertToRGroupAttachmentPointForDisplayPurpose",value:function(e){return new xt(e,"primary")}}]),e}(),Jt={microModeScale:40,macroModeScale:40};function en(){return Jt}var tn="#polymer-editor-canvas",nn=".drawn-structures",on=S().debounce((function(){var e=new Event("renderComplete");window.dispatchEvent(e)}),750),rn=function(){var e=new Event("itemsToMergeInitializationComplete");window.dispatchEvent(e)},an=function(){function e(t){var n=this;(0,i.A)(this,e),(0,d.A)(this,"resizeObserver",null),(0,d.A)(this,"zoomEventHandlers",[]),(0,d.A)(this,"COLOR","#a5afb9"),(0,d.A)(this,"MIN_LENGTH",40),(0,d.A)(this,"RADIUS",2),(0,d.A)(this,"MARGIN",5),(0,d.A)(this,"HORIZONTAL_DIST_TO_EDGE",16),(0,d.A)(this,"VERTICAL_DIST_TO_EDGE",4),(0,d.A)(this,"WIDTH",4),(0,d.A)(this,"MINZOOMSCALE",.2),(0,d.A)(this,"MAXZOOMSCALE",4),(0,d.A)(this,"dragged",(function(e){return function(t){var o,r;"horizontal"===e?null===(o=n.zoom)||void 0===o||o.translateBy(n.canvasWrapper,-t.dx,0):null===(r=n.zoom)||void 0===r||r.translateBy(n.canvasWrapper,0,-t.dy)}})),(0,d.A)(this,"observeCanvasResize",(function(){n.resizeObserver=new ResizeObserver((function(){n.drawScrollBars()})),n.resizeObserver.observe(n.canvasWrapper.node())})),this.canvasWrapper=(0,P.Ltv)(tn),this.canvas=(0,P.Ltv)(nn),this.zoomLevel=1,this.zoomTransform=new P.uVw(1,0,0),this.drawingEntitiesManager=t,this.initActions()}return(0,a.A)(e,[{key:"initActions",value:function(){var e=this;this.zoom=(0,P.s_O)().scaleExtent([this.MINZOOMSCALE,this.MAXZOOMSCALE]).wheelDelta(this.defaultWheelDelta).filter((function(e){return e.preventDefault(),!(!e.ctrlKey||"wheel"!==e.type)})).on("zoom",this.zoomAction.bind(this)).on("end",(function(){on()})),this.canvasWrapper.call(this.zoom),this.canvasWrapper.on("wheel",(function(t){t.ctrlKey?t.preventDefault():e.mouseWheeled(t)})),this.initMenuZoom()}},{key:"setZoom",value:function(e){this.zoomLevel=e}},{key:"getZoomLevel",value:function(){return this.zoomLevel}},{key:"setZoomTransform",value:function(e){this.zoomTransform=e}},{key:"zoomAction",value:function(e){var t=this,n=e.transform;this.canvas.attr("transform",n),this.zoomLevel=n.k,this.zoomTransform=n,this.drawScrollBars(),requestAnimationFrame((function(){t.dispatchZoomEventHandlers(n)}))}},{key:"subscribeOnZoomEvent",value:function(e){this.zoomEventHandlers.push(e)}},{key:"dispatchZoomEventHandlers",value:function(e){this.zoomEventHandlers.forEach((function(t){t(e)}))}},{key:"drawScrollBars",value:function(){this.canvas.node()&&this.canvasWrapper.node()&&(this.initScrollBars(),this.renderScrollBar(this.scrollBars.horizontal),this.renderScrollBar(this.scrollBars.vertical))}},{key:"renderScrollBar",value:function(e){var t;e.offsetStart<0||e.offsetEnd<0?e.bar?this.updateScrollBarAttrs(e):this.drawScrollBar(e):(null===(t=e.bar)||void 0===t||t.remove(),e.bar=void 0)}},{key:"drawScrollBar",value:function(e){var t;e.bar=this.canvasWrapper.append("rect");var n=(0,P.$Er)().on("drag",this.dragged(e.name).bind(this));null===(t=e.bar)||void 0===t||t.call(n),this.updateScrollBarAttrs(e)}},{key:"updateScrollBarAttrs",value:function(e){var t,n,o,r=this.calculateDynamicAttr(e),i=r.start,a=r.length;"horizontal"===e.name?null===(n=e.bar)||void 0===n||n.attr("x",i).attr("y",e.maxHeight-this.HORIZONTAL_DIST_TO_EDGE).attr("width",a).attr("height",this.WIDTH):null===(o=e.bar)||void 0===o||o.attr("x",e.maxHeight-this.VERTICAL_DIST_TO_EDGE).attr("y",i).attr("width",this.WIDTH).attr("height",a),null===(t=e.bar)||void 0===t||t.attr("rx",this.RADIUS).attr("draggable",!0).attr("cursor","pointer").attr("stroke",this.COLOR).attr("fill",this.COLOR).attr("data-testid",e.name+"-bar")}},{key:"calculateDynamicAttr",value:function(e){var t=(0,x.clamp)(-e.offsetStart,this.MARGIN,e.maxWidth-this.MIN_LENGTH-this.MARGIN),n=e.maxWidth-(0,x.clamp)(-e.offsetEnd,this.MARGIN,e.maxWidth);return{start:t,length:Math.max(n-t,this.MIN_LENGTH)}}},{key:"scrollTo",value:function(e){var t,n,o,r=(null===(t=this.canvasWrapper.node())||void 0===t?void 0:t.height.baseVal.value)||0,i=(null===(n=this.canvasWrapper.node())||void 0===n?void 0:n.width.baseVal.value)||0;null===(o=this.zoom)||void 0===o||o.translateTo(this.canvasWrapper,e.x+i/2-10*i/100,e.y+r/2-10*r/100)}},{key:"mouseWheeled",value:function(e){var t=e.shiftKey;if(this.canvasWrapper.node()&&(e.deltaX||e.deltaY)){var n,o,r=-e.deltaX/this.zoomLevel,i=-e.deltaY/this.zoomLevel;t?null===(n=this.zoom)||void 0===n||n.translateBy(this.canvasWrapper,r-i,0):null===(o=this.zoom)||void 0===o||o.translateBy(this.canvasWrapper,r,i)}}},{key:"initScrollBars",value:function(){var e,t,n,o,r,i,a=null===(e=this.canvas.node())||void 0===e?void 0:e.getBoundingClientRect(),s=null===(t=this.canvasWrapper.node())||void 0===t?void 0:t.getBoundingClientRect(),u=(null===(n=this.canvasWrapper.node())||void 0===n?void 0:n.height.baseVal.value)||0,l=(null===(o=this.canvasWrapper.node())||void 0===o?void 0:o.width.baseVal.value)||0;this.scrollBars={horizontal:{name:"horizontal",offsetStart:a.left-s.left,offsetEnd:s.width-a.right,maxWidth:l,maxHeight:u,bar:null===(r=this.scrollBars)||void 0===r||null===(r=r.horizontal)||void 0===r?void 0:r.bar},vertical:{name:"vertical",offsetStart:a.top-s.top,offsetEnd:s.height-a.bottom,maxWidth:u,maxHeight:l,bar:null===(i=this.scrollBars)||void 0===i||null===(i=i.vertical)||void 0===i?void 0:i.bar}}}},{key:"zoomStep",get:function(){return.1}},{key:"zoomIn",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.zoomStep;null===(e=this.zoom)||void 0===e||e.scaleTo(this.canvasWrapper,this.zoomLevel+t)}},{key:"zoomOut",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.zoomStep;null===(e=this.zoom)||void 0===e||e.scaleTo(this.canvasWrapper,this.zoomLevel-t)}},{key:"resetZoom",value:function(){var e;null===(e=this.zoom)||void 0===e||e.transform(this.canvasWrapper,new P.uVw(1,0,0))}},{key:"initMenuZoom",value:function(){var e=this;(0,P.Ltv)(".zoom-in").on("click",(function(){e.zoomIn()})),(0,P.Ltv)(".zoom-out").on("click",(function(){e.zoomOut()})),(0,P.Ltv)(".zoom-reset").on("click",(function(){e.resetZoom()}))}},{key:"defaultWheelDelta",value:function(e){return-e.deltaY*(1===e.deltaMode?.05:e.deltaMode?1:.002)}},{key:"scaleCoordinates",value:function(e){var t=this.zoomTransform.applyX(e.x),n=this.zoomTransform.applyY(e.y);return new we(t,n)}},{key:"invertZoom",value:function(e){var t=this.zoomTransform.invertX(e.x),n=this.zoomTransform.invertY(e.y);return new we(t,n)}},{key:"unzoomValue",value:function(e){return e/this.zoomLevel}},{key:"destroy",value:function(){var e,t,n;null===(e=this.scrollBars.horizontal)||void 0===e||null===(e=e.bar)||void 0===e||e.remove(),null===(t=this.scrollBars.vertical)||void 0===t||null===(t=t.bar)||void 0===t||t.remove(),null===(n=this.resizeObserver)||void 0===n||n.unobserve(this.canvasWrapper.node()),this.zoom=null,this.zoomEventHandlers=[]}}],[{key:"instance",get:function(){return e._instance}},{key:"initInstance",value:function(t){return e._instance=new e(t),e._instance}}]),e}(),sn=function(){function e(){(0,i.A)(this,e)}return(0,a.A)(e,null,[{key:"canvasToModel",value:function(e){var t=en();return e.scaled(1/t.macroModeScale)}},{key:"viewToModel",value:function(e){var t=en();return an.instance.invertZoom(e).scaled(1/t.macroModeScale)}},{key:"modelToView",value:function(e){var t=en();return an.instance.scaleCoordinates(e.scaled(t.macroModeScale))}},{key:"modelToCanvas",value:function(e){var t=en();return e.scaled(t.macroModeScale)}},{key:"canvasToView",value:function(e){return an.instance.scaleCoordinates(e)}},{key:"viewToCanvas",value:function(e){return an.instance.invertZoom(e)}}]),e}(),un=function(){function e(t){var n,o;(0,i.A)(this,e),this.drawingEntity=t,this.canvasWrapper=(null===(n=an.instance)||void 0===n?void 0:n.canvasWrapper)||(0,P.Ltv)(tn),this.canvas=(null===(o=an.instance)||void 0===o?void 0:o.canvas)||(0,P.Ltv)(nn)}return(0,a.A)(e,[{key:"editorSettings",get:function(){return en()}},{key:"rootBBox",get:function(){var e,t=null===(e=this.rootElement)||void 0===e?void 0:e.node();if(t)return t.getBBox()}},{key:"width",get:function(){var e;return(null===(e=this.rootBBox)||void 0===e?void 0:e.width)||0}},{key:"height",get:function(){var e;return(null===(e=this.rootBBox)||void 0===e?void 0:e.height)||0}},{key:"x",get:function(){var e;return(null===(e=this.rootBBox)||void 0===e?void 0:e.x)||0}},{key:"y",get:function(){var e;return(null===(e=this.rootBBox)||void 0===e?void 0:e.y)||0}},{key:"remove",value:function(){var e;null===(e=this.rootElement)||void 0===e||e.remove(),this.rootElement=void 0}},{key:"redrawHover",value:function(){if(this.drawingEntity.hovered){var e=this.appendHover(this.hoverAreaElement);e&&(this.hoverElement=e)}else this.removeHover(),this.hoverElement=void 0}},{key:"move",value:function(){}}]),e}();function ln(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,cn()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function cn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(cn=function(){return!!e})()}var dn,hn=function(e){function t(){return(0,i.A)(this,t),ln(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t,[{key:"appendHover",value:function(e){}},{key:"appendHoverAreaElement",value:function(){}},{key:"drawSelection",value:function(){}},{key:"moveSelection",value:function(){}},{key:"removeHover",value:function(){}},{key:"show",value:function(e){}},{key:"center",get:function(){return new we(0,0,0)}}]),t}(un),fn=0,mn=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new we(0,0);(0,i.A)(this,e),(0,d.A)(this,"selected",!1),(0,d.A)(this,"hovered",!1),(0,d.A)(this,"id",0),this._position=t,this._position=t||new we(0,0),this.id=fn,fn++}return(0,a.A)(e,[{key:"moveRelative",value:function(e){this._position.x+=e.x,this._position.y+=e.y}},{key:"moveAbsolute",value:function(e){this._position=e}},{key:"position",get:function(){return this._position}},{key:"turnOnHover",value:function(){this.hovered=!0}},{key:"turnOffHover",value:function(){this.hovered=!1}},{key:"turnOnSelection",value:function(){this.selected=!0}},{key:"turnOffSelection",value:function(){this.selected=!1}},{key:"selectIfLocatedInRectangle",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=arguments.length>3&&void 0!==arguments[3]&&arguments[3];f()(this.baseRenderer);var r=this.selected,i=sn.modelToCanvas(this.center);this.baseRenderer instanceof hn&&(i=this.baseRenderer.center);var a=t.x>i.x&&t.y>i.y&&e.x<i.x&&e.y<i.y;return(o&&!n||!o)&&(a?this.turnOnSelection():this.turnOffSelection()),r!==this.selected}},{key:"setBaseRenderer",value:function(e){this.baseRenderer=e}},{key:"isPartOfRna",get:function(){return!1}}]),e}();!function(e){e.R1="R1",e.R2="R2",e.R3="R3",e.R4="R4",e.R5="R5",e.R6="R6",e.R7="R7",e.R8="R8"}(dn||(dn={}));var pn=["R1","R2","R3","R4","R5","R6","R7","R8"];function vn(e,t,n,o){var r=t.x-n/2,i=t.y-o/2;return{x:e.x-r,y:e.y-i}}var gn,yn={45:{min:23,max:68,center:45},90:{min:68,max:113,center:90},135:{min:113,max:148,center:135},180:{min:148,max:203,center:180},225:{min:203,max:248,center:225},270:{min:248,max:293,center:270},315:{min:293,max:228,center:315},360:{min:338,max:360,center:360},0:{min:0,max:23,center:0}};!function(e){e[e.R1=0]="R1",e[e.R2=180]="R2",e[e.R3=90]="R3",e[e.R4=270]="R4",e[e.R5=45]="R5",e[e.R6=135]="R6",e[e.R7=315]="R7",e[e.R8=225]="R8"}(gn||(gn={}));var bn=[45,90,135,180,225,270,315,0,360];function An(e){return!e.includes(0)&&e.includes(360)?e.filter((function(e){return 360!==e})):!e.includes(360)&&e.includes(0)?e.filter((function(e){return 0!==e})):e}function wn(e){for(var t="",n=0;n<32;n++)e&1<<n&&(t="R"+(n+1).toString());return t}function En(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Pn(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,xn()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function xn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(xn=function(){return!!e})()}var Sn=function(e){function t(e,n){var o;return(0,i.A)(this,t),o=Pn(this,t,[n]),(0,d.A)((0,l.A)(o),"renderer",void 0),(0,d.A)((0,l.A)(o),"attachmentPointsToBonds",{}),(0,d.A)((0,l.A)(o),"potentialAttachmentPointsToBonds",{}),(0,d.A)((0,l.A)(o),"attachmentPointsVisible",!1),(0,d.A)((0,l.A)(o),"isMonomerInRnaChainRow",!1),o.monomerItem=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?En(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):En(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},e),o.monomerItem.props.isMicromoleculeFragment||(o.attachmentPointsToBonds=o.getAttachmentPointDict(),o.potentialAttachmentPointsToBonds=o.getAttachmentPointDict(),o.monomerItem.attachmentPoints=o.monomerItem.attachmentPoints||o.getMonomerDefinitionAttachmentPoints()),o.chosenFirstAttachmentPointForBond=null,o.potentialSecondAttachmentPointForBond=null,o.chosenSecondAttachmentPointForBond=null,o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"label",get:function(){return this.monomerItem.label}},{key:"center",get:function(){return this.position}},{key:"listOfAttachmentPoints",get:function(){for(var e=this.getMaxAttachmentPointNumber(),t=[],n=1;n<=e;n++)void 0!==this.attachmentPointsToBonds["R".concat(n)]&&t.push("R".concat(n));return t}},{key:"turnOnAttachmentPointsVisibility",value:function(){this.attachmentPointsVisible=!0}},{key:"turnOffAttachmentPointsVisibility",value:function(){this.attachmentPointsVisible=!1}},{key:"setChosenFirstAttachmentPoint",value:function(e){this.chosenFirstAttachmentPointForBond=e}},{key:"setChosenSecondAttachmentPoint",value:function(e){this.chosenSecondAttachmentPointForBond=e}},{key:"setPotentialSecondAttachmentPoint",value:function(e){this.potentialSecondAttachmentPointForBond=e}},{key:"setPotentialBond",value:function(e,t){void 0!==e&&(this.potentialAttachmentPointsToBonds[e]=t)}},{key:"getAttachmentPointByBond",value:function(e){for(var t in this.attachmentPointsToBonds)if(this.attachmentPointsToBonds[t]===e)return t}},{key:"getPotentialAttachmentPointByBond",value:function(e){for(var t in this.potentialAttachmentPointsToBonds)if(this.potentialAttachmentPointsToBonds[t]===e)return t}},{key:"firstFreeAttachmentPoint",get:function(){for(var e=this.getMaxAttachmentPointNumber(),t=1;t<=e;t++){var n="R".concat(t);if(this.hasAttachmentPoint(n)&&null===this.attachmentPointsToBonds[n])return n}}},{key:"getMaxAttachmentPointNumber",value:function(){var e=1;for(var t in this.attachmentPointsToBonds){var n=t.match(/R(\d+)/);if(n){var o=parseInt(n[1]);!isNaN(o)&&o>e&&(e=o)}}return e}},{key:"R1AttachmentPoint",get:function(){if(null===this.attachmentPointsToBonds.R1)return dn.R1}},{key:"R2AttachmentPoint",get:function(){if(null===this.attachmentPointsToBonds.R2)return dn.R2}},{key:"hasFreeAttachmentPoint",get:function(){return Boolean(this.firstFreeAttachmentPoint)}},{key:"isAttachmentPointExistAndFree",value:function(e){return this.hasAttachmentPoint(e)&&!this.isAttachmentPointUsed(e)}},{key:"setRenderer",value:function(e){(0,E.A)((0,u.A)(t.prototype),"setBaseRenderer",this).call(this,e),this.renderer=e}},{key:"forEachBond",value:function(e){for(var t in this.attachmentPointsToBonds)this.attachmentPointsToBonds[t]&&e(this.attachmentPointsToBonds[t],t)}},{key:"setBond",value:function(e,t){this.attachmentPointsToBonds[e]=t}},{key:"unsetBond",value:function(e){this.attachmentPointsToBonds[e]=null}},{key:"hasBonds",get:function(){var e=!1;for(var t in this.attachmentPointsToBonds)this.attachmentPointsToBonds[t]&&(e=!0);return e}},{key:"hasPotentialBonds",value:function(){return Object.values(this.potentialAttachmentPointsToBonds).some((function(e){return!!e}))}},{key:"getPotentialBond",value:function(e){return this.potentialAttachmentPointsToBonds[e]}},{key:"removeBond",value:function(e){var t=this.getAttachmentPointByBond(e);t&&this.unsetBond(t)}},{key:"removePotentialBonds",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];for(var t in e&&(this.chosenFirstAttachmentPointForBond=null,this.chosenSecondAttachmentPointForBond=null,this.potentialSecondAttachmentPointForBond=null),this.potentialAttachmentPointsToBonds)this.potentialAttachmentPointsToBonds[t]=null}},{key:"availableAttachmentPointForBondEnd",get:function(){return this.chosenSecondAttachmentPointForBond?this.chosenSecondAttachmentPointForBond:this.firstFreeAttachmentPoint}},{key:"hasAttachmentPoint",value:function(e){return void 0!==this.attachmentPointsToBonds[e]}},{key:"usedAttachmentPointsNamesList",get:function(){var e=[];for(var t in this.attachmentPointsToBonds)this.isAttachmentPointUsed(t)&&e.push(t);return e}},{key:"unUsedAttachmentPointsNamesList",get:function(){var e=[];for(var t in this.attachmentPointsToBonds)this.isAttachmentPointUsed(t)||e.push(t);return e}},{key:"getBondByAttachmentPoint",value:function(e){return this.attachmentPointsToBonds[e]}},{key:"getPotentialBondByAttachmentPoint",value:function(e){return this.potentialAttachmentPointsToBonds[e]}},{key:"isAttachmentPointUsed",value:function(e){return Boolean(this.getBondByAttachmentPoint(e))}},{key:"isAttachmentPointPotentiallyUsed",value:function(e){return Boolean(this.getPotentialBondByAttachmentPoint(e))}},{key:"getAttachmentPointDict",value:function(){return this.monomerItem.attachmentPoints?t.getAttachmentPointDictFromMonomerDefinition(this.monomerItem.attachmentPoints).attachmentPointDictionary:this.getAttachmentPointDictFromAtoms()}},{key:"attachmentPointNumberToType",get:function(){return{1:"left",2:"right",moreThanTwo:"side"}}},{key:"getMonomerDefinitionAttachmentPoints",value:function(){var e=this,t=[];return this.leavingGroupsAtoms.forEach((function(n){var o,r,i=e.monomerItem.struct.bonds.find((function(e,t){return t.begin===n.id||t.end===n.id}));if((0,x.isNumber)(i)){var a=e.monomerItem.struct.bonds.get(i);o=a.begin===n.id?a.end:a.begin,r=n.id}else o=n.id;t.push({attachmentAtom:o,leavingGroup:{atoms:r?[r]:[]},type:e.attachmentPointNumberToType[n.rglabel]||e.attachmentPointNumberToType.moreThanTwo})})),t}},{key:"leavingGroupsAtoms",get:function(){var e=this.monomerItem.struct.atoms.filter((function(e,t){return Boolean(t.rglabel)})),t=[];return e.forEach((function(e,n){t.push({id:n,rglabel:Number(e.rglabel)})})),t.sort((function(e,t){return Number(e.rglabel)>Number(t.rglabel)?1:-1})),t}},{key:"getAttachmentPointDictFromAtoms",value:function(){var e={};return this.leavingGroupsAtoms.forEach((function(t,n){var o=t.rglabel,r=wn(Number(o));e[r]=null})),e}},{key:"startBondAttachmentPoint",get:function(){return this.chosenFirstAttachmentPointForBond?this.chosenFirstAttachmentPointForBond:null===this.attachmentPointsToBonds.R2?"R2":null===this.attachmentPointsToBonds.R1?"R1":this.firstFreeAttachmentPoint}},{key:"isMonomerTypeDifferentForChaining",value:function(e){return this.SubChainConstructor!==e.SubChainConstructor}},{key:"isPartOfRna",get:function(){return!1}}],[{key:"getAttachmentPointDictFromMonomerDefinition",value:function(e){var t={},n=[],o={left:function(){return 1},right:function(){return 2},side:function(e){return f()(e),e+Number(!("R1"in t))+Number(!("R2"in t))}};return e.forEach((function(e,r){var i,a=r+1;i=e.type&&"function"==typeof o[e.type]?o[e.type](a):a;var s=e.label||"R".concat(i);t[s]=null,n.push(s)})),{attachmentPointDictionary:t,attachmentPointsList:n}}}]),t}(mn),On=function(){function e(){(0,i.A)(this,e),(0,d.A)(this,"nodes",[]),(0,d.A)(this,"bonds",[])}return(0,a.A)(e,[{key:"lastNode",get:function(){return this.nodes[this.nodes.length-1]}},{key:"firstNode",get:function(){return this.nodes[0]}},{key:"add",value:function(e){this.nodes.push(e)}},{key:"length",get:function(){return this.nodes.length}}]),e}();function kn(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Mn()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Mn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Mn=function(){return!!e})()}var Rn=function(e){function t(){return(0,i.A)(this,t),kn(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t)}(On);function Tn(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Bn()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Bn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Bn=function(){return!!e})()}var Cn=function(e){function t(){return(0,i.A)(this,t),Tn(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t)}(On);function In(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Nn()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Nn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Nn=function(){return!!e})()}var Dn=function(e){function t(){return(0,i.A)(this,t),In(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t,[{key:"getValidSourcePoint",value:function(e){return this.chosenFirstAttachmentPointForBond?this.chosenFirstAttachmentPointForBond:1===this.unUsedAttachmentPointsNamesList.length?this.unUsedAttachmentPointsNamesList[0]:null!=e&&e.potentialSecondAttachmentPointForBond?(null==e?void 0:e.potentialSecondAttachmentPointForBond)===dn.R1&&this.isAttachmentPointExistAndFree(dn.R2)?dn.R2:(null==e?void 0:e.potentialSecondAttachmentPointForBond)===dn.R2&&this.isAttachmentPointExistAndFree(dn.R1)?dn.R1:void 0:e&&!e.isAttachmentPointExistAndFree(dn.R1)||!this.isAttachmentPointExistAndFree(dn.R2)?this.isAttachmentPointExistAndFree(dn.R1)&&null!=e&&e.isAttachmentPointExistAndFree(dn.R2)?dn.R1:void 0:dn.R2}},{key:"getValidTargetPoint",value:function(e){return this.potentialSecondAttachmentPointForBond?this.potentialSecondAttachmentPointForBond:1===this.unUsedAttachmentPointsNamesList.length?this.unUsedAttachmentPointsNamesList[0]:null!=e&&e.chosenFirstAttachmentPointForBond?(null==e?void 0:e.chosenFirstAttachmentPointForBond)===dn.R1&&this.isAttachmentPointExistAndFree(dn.R2)?dn.R2:(null==e?void 0:e.chosenFirstAttachmentPointForBond)===dn.R2&&this.isAttachmentPointExistAndFree(dn.R1)?dn.R1:void 0:this.isAttachmentPointExistAndFree(dn.R1)&&e.isAttachmentPointExistAndFree(dn.R2)?dn.R1:e.isAttachmentPointExistAndFree(dn.R1)&&this.isAttachmentPointExistAndFree(dn.R2)?dn.R2:void 0}},{key:"SubChainConstructor",get:function(){return Rn}},{key:"isMonomerTypeDifferentForChaining",value:function(e){return![Rn,Cn].includes(e.SubChainConstructor)}}]),t}(Sn);function Ln(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,_n()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function _n(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(_n=function(){return!!e})()}var Fn=function(e){function t(){return(0,i.A)(this,t),Ln(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t,[{key:"getValidSourcePoint",value:function(e){return Dn.prototype.getValidSourcePoint.call(this,e)}},{key:"getValidTargetPoint",value:function(e){return Dn.prototype.getValidTargetPoint.call(this,e)}},{key:"SubChainConstructor",get:function(){return Cn}},{key:"isMonomerTypeDifferentForChaining",value:function(e){return![Rn,Cn].includes(e.SubChainConstructor)}}]),t}(Sn);function Hn(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,jn()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function jn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(jn=function(){return!!e})()}var Gn=function(e){function t(){return(0,i.A)(this,t),Hn(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t,[{key:"getValidSourcePoint",value:function(){return this.chosenFirstAttachmentPointForBond?this.chosenFirstAttachmentPointForBond:this.firstFreeAttachmentPoint}},{key:"getValidTargetPoint",value:function(){return this.potentialSecondAttachmentPointForBond?this.potentialSecondAttachmentPointForBond:this.firstFreeAttachmentPoint}},{key:"SubChainConstructor",get:function(){return Cn}},{key:"isPartOfRna",get:function(){var e;return(null===(e=this.attachmentPointsToBonds.R1)||void 0===e?void 0:e.getAnotherMonomer(this))instanceof eo}}]),t}(Sn);function zn(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Vn()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Vn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Vn=function(){return!!e})()}var Un=function(e){function t(){return(0,i.A)(this,t),zn(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t)}(On);function Wn(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,qn()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function qn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(qn=function(){return!!e})()}var Yn=function(e){function t(){return(0,i.A)(this,t),Wn(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t)}(On);function $n(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Xn()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Xn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Xn=function(){return!!e})()}var Kn=function(e){function t(e,n){return(0,i.A)(this,t),$n(this,t,[e,n])}return(0,c.A)(t,e),(0,a.A)(t,[{key:"getValidSourcePoint",value:function(e){return this.getValidPoint(e,e.potentialSecondAttachmentPointForBond)}},{key:"getValidTargetPoint",value:function(e){return this.getValidPoint(e,e.chosenFirstAttachmentPointForBond)}},{key:"getValidPoint",value:function(e,t){return this.chosenFirstAttachmentPointForBond?this.chosenFirstAttachmentPointForBond:this.potentialSecondAttachmentPointForBond?this.potentialSecondAttachmentPointForBond:1===this.unUsedAttachmentPointsNamesList.length?this.unUsedAttachmentPointsNamesList[0]:e instanceof eo?t?t===dn.R2&&this.isAttachmentPointExistAndFree(dn.R1)?dn.R1:t!==dn.R2&&this.isAttachmentPointExistAndFree(dn.R2)?dn.R2:void 0:e.isAttachmentPointExistAndFree(dn.R2)&&this.isAttachmentPointExistAndFree(dn.R1)?dn.R1:!e.isAttachmentPointExistAndFree(dn.R2)&&this.isAttachmentPointExistAndFree(dn.R2)?dn.R2:void 0:void 0}},{key:"isMonomerTypeDifferentForChaining",value:function(e){return![Un,Yn].includes(e.SubChainConstructor)}},{key:"SubChainConstructor",get:function(){return Un}},{key:"isPartOfRna",get:function(){var e,t,n,o=null===(e=this.attachmentPointsToBonds.R1)||void 0===e?void 0:e.getAnotherMonomer(this),r=o instanceof eo,i=(null==o||null===(t=o.attachmentPointsToBonds.R3)||void 0===t?void 0:t.getAnotherMonomer(o))instanceof Gn,a=null===(n=this.attachmentPointsToBonds.R2)||void 0===n?void 0:n.getAnotherMonomer(this),s=null==a?void 0:a.isPartOfRna;return r&&i&&s}}]),t}(Sn);function Zn(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Qn()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Qn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Qn=function(){return!!e})()}var Jn,eo=function(e){function t(){return(0,i.A)(this,t),Zn(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t,[{key:"getValidSourcePoint",value:function(e){return this.getValidPoint(e,e.potentialSecondAttachmentPointForBond)}},{key:"getValidTargetPoint",value:function(e){return this.getValidPoint(e,e.chosenFirstAttachmentPointForBond)}},{key:"getValidPoint",value:function(e,t){return this.chosenFirstAttachmentPointForBond?this.chosenFirstAttachmentPointForBond:this.potentialSecondAttachmentPointForBond?this.potentialSecondAttachmentPointForBond:1===this.unUsedAttachmentPointsNamesList.length?this.unUsedAttachmentPointsNamesList[0]:e instanceof Kn||e instanceof Gn?e instanceof Gn?this.isAttachmentPointExistAndFree(dn.R3)?dn.R3:void 0:t?t===dn.R1&&this.isAttachmentPointExistAndFree(dn.R2)?dn.R2:t!==dn.R1&&this.isAttachmentPointExistAndFree(dn.R1)?dn.R1:void 0:e.isAttachmentPointExistAndFree(dn.R1)&&this.isAttachmentPointExistAndFree(dn.R2)?dn.R2:e.isAttachmentPointExistAndFree(dn.R2)&&this.isAttachmentPointExistAndFree(dn.R1)||!e.isAttachmentPointExistAndFree(dn.R1)&&this.isAttachmentPointExistAndFree(dn.R1)?dn.R1:void 0:void 0}},{key:"SubChainConstructor",get:function(){return Yn}},{key:"isMonomerTypeDifferentForChaining",value:function(e){return![Un,Yn].includes(e.SubChainConstructor)}},{key:"isPartOfRna",get:function(){var e;return(null===(e=this.attachmentPointsToBonds.R3)||void 0===e?void 0:e.getAnotherMonomer(this))instanceof Gn}}]),t}(Sn);function to(e,t){var n;return(null===(n=t.attachmentPointsToBonds.R1)||void 0===n?void 0:n.getAnotherMonomer(t))===e}function no(e,t){if(e){var n=e.attachmentPointsToBonds.R2,o=null==n?void 0:n.getAnotherMonomer(e);if(o!==t||!n)return n&&(null==o?void 0:o.getAttachmentPointByBond(n))===dn.R1?o:void 0}}function oo(e){if(e){var t=e.attachmentPointsToBonds.R3,n=null==t?void 0:t.getAnotherMonomer(e);return n instanceof Gn?n:void 0}}function ro(e){if(e){var t=no(e);return t instanceof Kn?t:void 0}}function io(e,t){var n=e.attachmentPointsToBonds.R1,o=null==n?void 0:n.getAnotherMonomer(e),r=o&&!t.some((function(e){return o instanceof e})),i=n&&"R2"!==(null==o?void 0:o.getAttachmentPointByBond(n));return(e.isAttachmentPointExistAndFree(dn.R1)||!e.hasAttachmentPoint(dn.R1))&&e.hasBonds||i||r}function ao(e){var t=no(ro(e));return Boolean(oo(e)&&ro(e)&&t instanceof eo&&oo(t))}function so(e){var t=ro(e),n=no(t);return oo(e)&&(!t||!(n instanceof eo&&oo(n)))}function uo(e,t,n){this.f=e,this.once=t,this.priority=n}function lo(){this.handlers=[]}!function(e){e.x="x",e.y="y",e.z="z"}(Jn||(Jn={}));var co=lo;function ho(e,t){for(var n=0;n<e.handlers.length&&!(e.handlers[n].priority<t.priority);n++);e.handlers=e.handlers.slice(0,n).concat(t).concat(e.handlers.slice(n))}function fo(){lo.call(this)}function mo(){lo.call(this)}function po(){lo.call(this)}lo.prototype.handlersForDispatch=function(){for(var e=this.handlers,t=null,n=e.length-1;n>=0;n--)e[n].once&&(t||(t=e.slice()),t.splice(n,1));return t&&(this.handlers=t),e},lo.prototype.add=function(e,t){ho(this,new uo(e,!1,t||0))},lo.prototype.addOnce=function(e,t){ho(this,new uo(e,!0,t||0))},lo.prototype.remove=function(e){for(var t=0;t<this.handlers.length;t++)if(this.handlers[t].f==e)return void(this.handlers=this.handlers.slice(0,t).concat(this.handlers.slice(t+1)))},lo.prototype.hasHandler=function(){return this.handlers.length>0},lo.prototype.dispatch=function(){for(var e=this.handlersForDispatch(),t=0;t<e.length;t++)e[t].f.apply(null,arguments)},fo.prototype=new lo,fo.prototype.dispatch=function(e){for(var t=this.handlersForDispatch(),n=0;n<t.length;n++)e=t[n].f(e);return e},mo.prototype=new lo,mo.prototype.dispatch=function(){for(var e=this.handlersForDispatch(),t=0;t<e.length;t++){var n=e[t].f.apply(null,arguments);if(n)return n}};var vo,go=po;function yo(){vo={selectMonomer:new co,selectPreset:new co,selectTool:new co,createBondViaModal:new co,cancelBondCreationViaModal:new co,selectMode:new co,layoutModeChange:new co,selectHistory:new co,error:new co,openMonomerConnectionModal:new co,mouseOverPolymerBond:new co,mouseLeavePolymerBond:new co,mouseOverMonomer:new co,mouseOnMoveMonomer:new co,mouseLeaveMonomer:new co,mouseOverAttachmentPoint:new co,mouseLeaveAttachmentPoint:new co,mouseUpAttachmentPoint:new co,mouseDownAttachmentPoint:new co,mouseOverDrawingEntity:new co,mouseLeaveDrawingEntity:new co,mouseUpMonomer:new co,rightClickSequence:new co,rightClickCanvas:new co,editSequence:new co,startNewSequence:new co,mouseOverSequenceItem:new co,mouseOnMoveSequenceItem:new co,mouseLeaveSequenceItem:new co,changeSequenceTypeEnterMode:new co,toggleSequenceEditMode:new co}}po.prototype=new lo,po.prototype.dispatch=function(e){for(var t=this.handlersForDispatch(),n=0;n<t.length;n++)if(t[n].f(e)||e.defaultPrevented)return!0;return!1},yo();var bo,Ao=["mouseOverPolymerBond","mouseLeavePolymerBond","mouseOverMonomer","mouseOnMoveMonomer","mouseOverAttachmentPoint","mouseLeaveAttachmentPoint","mouseUpAttachmentPoint","mouseDownAttachmentPoint","mouseLeaveMonomer","mouseOverDrawingEntity","mouseLeaveDrawingEntity","mouseUpMonomer","rightClickSequence","rightClickCanvas","editSequence","startNewSequence","mouseOverSequenceItem","mouseOnMoveSequenceItem","mouseLeaveSequenceItem","changeSequenceTypeEnterMode","toggleSequenceEditMode"],wo={exit:{shortcut:["Shift+Tab","Escape"],handler:function(e){e.events.selectTool.dispatch("select-rectangle")}},undo:{shortcut:"Mod+z",handler:function(e){e.onSelectHistory("undo")}},redo:{shortcut:["Mod+Shift+z","Mod+y"],handler:function(e){e.onSelectHistory("redo")}},erase:{shortcut:["Delete","Backspace"],handler:function(e){e.isSequenceEditMode||(e.events.selectTool.dispatch("erase"),e.events.selectTool.dispatch("select-rectangle"))}},clear:{shortcut:["Mod+Delete","Mod+Backspace"],handler:function(e){e.events.selectTool.dispatch("clear"),e.events.selectTool.dispatch("select-rectangle")}},"zoom-plus":{shortcut:"Mod+=",handler:function(){an.instance.zoomIn()}},"zoom-minus":{shortcut:"Mod+-",handler:function(){an.instance.zoomOut()}},"zoom-reset":{shortcut:"Mod+0",handler:function(){an.instance.resetZoom()}},"select-all":{shortcut:"Mod+a",handler:function(e){var t=e.drawingEntitiesManager.selectAllDrawingEntities();e.renderersContainer.update(t)}}},Eo=function(){function e(t){var n,o;(0,i.A)(this,e),(0,d.A)(this,"initialAngle",0),this.rootElement=t.rootElement,this.monomer=t.monomer,this.bodyWidth=t.bodyWidth,this.bodyHeight=t.bodyHeight,this.canvasOffset=(null===(n=t.canvas.node())||void 0===n?void 0:n.getBoundingClientRect())||new DOMRect(0,0,0,0),this.attachmentPointName=t.attachmentPointName,this.centerOfMonomer=(null===(o=t.monomer.renderer)||void 0===o?void 0:o.center)||new we(0,0,0),this.isSnake=t.isSnake,this.isUsed=t.isUsed,this.initialAngle=t.angle,this.editorEvents=vo,this.attachmentPoint=null,t.isPotentiallyUsed?(this.fill=e.colors.fillPotentially,this.stroke=e.colors.strokePotentially):t.isUsed?(this.fill=e.colors.fillUsed,this.stroke=e.colors.strokeUsed):(this.fill=e.colors.fill,this.stroke=e.colors.stroke),this.appendAttachmentPoint()}return(0,a.A)(e,[{key:"removeAttachmentPoint",value:function(){var e=this;setTimeout((function(){var t;null===(t=e.element)||void 0===t||t.remove()}),1)}},{key:"renderAttachmentPointByCoordinates",value:function(t,n,o){var r=this.fill,i=this.stroke;this.attachmentPoint=this.rootElement.insert("g",":first-child");var a=this.attachmentPoint.append("g");return a.append("line").attr("x1",t.x).attr("y1",t.y).attr("x2",n.x).attr("y2",n.y).attr("stroke",i).attr("stroke-linecap","round").attr("stroke-width","1px"),a.append("circle").attr("r",e.radius).attr("cx",n.x).attr("cy",n.y).attr("stroke","white"===r?"#0097A8":"white").attr("stroke-width","1px").attr("fill",r),this.attachmentPoint.append("text").text(this.attachmentPointName).attr("x",o.x).attr("y",o.y).style("font-size","6px").style("fill","#585858").style("user-select","none"),this.attachmentPoint}},{key:"renderHoverableArea",value:function(t,n,o){var r=this;if(this.element){var i=o+90,a=Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2)),s=[{x:-e.radius,y:e.radius},{x:e.radius,y:e.radius},{x:20,y:10-a},{x:-20,y:10-a},{x:-e.radius,y:e.radius}],u=(0,P.n8j)().x((function(e){return e.x})).y((function(e){return e.y})),l=this.element.append("g");return l.append("path").attr("d",u(s)+"z").attr("stroke","black").attr("stroke-width","1px").attr("fill","#0097A8").style("opacity","0").attr("transform","translate(".concat(n.x,",").concat(n.y,")rotate(").concat(i,")")),l.on("mouseover",(function(e){e.attachmentPointName=r.attachmentPointName,r.editorEvents.mouseOverAttachmentPoint.dispatch(e)})).on("mouseleave",(function(e){r.editorEvents.mouseLeaveAttachmentPoint.dispatch(e)})).on("mousedown",(function(e){e.attachmentPointName=r.attachmentPointName,r.editorEvents.mouseDownAttachmentPoint.dispatch(e)})).on("mouseup",(function(e){e.attachmentPointName=r.attachmentPointName,r.editorEvents.mouseUpAttachmentPoint.dispatch(e)})),l}}},{key:"appendAttachmentPoint",value:function(){var e,t,n,o,i=this.monomer.id===(null===(e=this.monomer.attachmentPointsToBonds[this.attachmentPointName])||void 0===e||null===(e=e.firstMonomer)||void 0===e?void 0:e.id),a="R1"===this.attachmentPointName;this.isUsed?!this.isSnake||null!==(t=this.monomer.attachmentPointsToBonds[this.attachmentPointName])&&void 0!==t&&t.renderer.isMonomersOnSameHorizontalLine()?(o=this.rotateToAngle(this.monomer.attachmentPointsToBonds[this.attachmentPointName],i),n=we.radiansToDegrees(o)):(o=a?0:Math.PI,n=we.radiansToDegrees(o)):n=this.initialAngle;var s=this.getCoordinates(n),u=(0,r.A)(s,3),l=u[0],c=u[1],d=u[2],h=vn(this.centerOfMonomer,this.centerOfMonomer,this.bodyWidth,this.bodyHeight),f=this.renderAttachmentPointByCoordinates(l,c,d);this.element=f;var m=this.renderHoverableArea(h,c,n);return this.hoverableArea=m,f}},{key:"updateAttachmentPointStyleForHover",value:function(){var t,n;this.monomer.isAttachmentPointUsed(this.attachmentPointName)&&(null===(t=this.attachmentPoint)||void 0===t||t.select("line").style("stroke",e.colors.fillUsed),null===(n=this.attachmentPoint)||void 0===n||n.select("circle").style("fill",e.colors.fillUsed).attr("stroke","white"))}},{key:"rotateToAngle",value:function(e){return arguments.length>1&&void 0!==arguments[1]&&arguments[1]?we.oxAngleForVector(e.endPosition,e.position):we.oxAngleForVector(e.position,e.endPosition)}},{key:"getCoordinates",value:function(e){var t=this.catchThePoint(e),n=(0,r.A)(t,3),o=n[0],i=n[1],a=n[2];return[vn(o,this.centerOfMonomer,this.bodyWidth,this.bodyHeight),vn(i,this.centerOfMonomer,this.bodyWidth,this.bodyHeight),vn(a,this.centerOfMonomer,this.bodyWidth,this.bodyHeight)]}},{key:"updateCoords",value:function(){var t,n,o,i,a=this.monomer.id===(null===(t=this.monomer.attachmentPointsToBonds[this.attachmentPointName])||void 0===t||null===(t=t.firstMonomer)||void 0===t?void 0:t.id),s=this.rotateToAngle(this.monomer.attachmentPointsToBonds[this.attachmentPointName],a),u=we.radiansToDegrees(s),l=this.getCoordinates(u),c=(0,r.A)(l,3),d=c[0],h=c[1],f=c[2];null===(n=this.attachmentPoint)||void 0===n||n.select("line").attr("x1",d.x).attr("y1",d.y).attr("x2",h.x).attr("y2",h.y),null===(o=this.attachmentPoint)||void 0===o||o.select("circle").attr("cx",h.x).attr("cy",h.y).attr("stroke","white").attr("fill",e.colors.fillPotentially),null===(i=this.attachmentPoint)||void 0===i||i.select("text").attr("x",f.x).attr("y",f.y)}},{key:"catchThePoint",value:function(t){f()(this.monomer.renderer);var n={x:this.monomer.renderer.center.x,y:this.monomer.renderer.center.y};this.initialAngle=t;var o,i,a,s=(o=this.initialAngle-180,i=this.canvasOffset,a=this.monomer,function e(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o,s=we.degrees_to_radians(r),u=we.findSecondPoint(t,n,s),l=we.diff(new we(t.x,t.y),new we(u.x,u.y));if(l.length()<1.01)return u;var c=Math.round(l.length()/1.4),d={x:u.x,y:u.y},h=sn.canvasToView(new we(u)),f={x:Math.round(h.x)+i.x,y:Math.round(h.y)+i.y};return e(d,c,document.elementsFromPoint(f.x,f.y).some((function(e){var t;return e===(null===(t=a.renderer)||void 0===t||null===(t=t.bodyElement)||void 0===t?void 0:t.node())}))?o:o-180)}),u=s(n,(this.bodyWidth+this.bodyHeight)/2),l=function(e,t,n,o,r,i){var a=we.degrees_to_radians(t),s=we.findSecondPoint(e,n,a),u=s.x-e.x,l=s.y-e.y,c=-l/n,d=u/n,h=u/n,f=l/n,m=0,p=o+Math.max(r.x,r.y)+1;i&&(t>=-270&&t<=0?m=5:t>=-360&&t<-270&&(m=-5));var v=c*m,g=d*m,y=h*p,b=f*p;return[{x:s.x+v+y-r.x,y:s.y+g+b+r.y},s]}(u,this.initialAngle-180,e.attachmentPointLength,e.labelOffset,e.labelSize,this.isUsed),c=(0,r.A)(l,2),d=c[0];return[u,c[1],d]}},{key:"getElement",value:function(){return this.element}},{key:"getAttachmentPointName",value:function(){return this.attachmentPointName}},{key:"getHoverableArea",value:function(){return this.hoverableArea}},{key:"getAngle",value:function(){return this.initialAngle<0&&this.isUsed?this.initialAngle+360:this.initialAngle}}]),e}();function Po(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,xo()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function xo(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(xo=function(){return!!e})()}bo=Eo,(0,d.A)(Eo,"attachmentPointVector",6),(0,d.A)(Eo,"attachmentPointLength",Math.hypot(bo.attachmentPointVector,bo.attachmentPointVector)),(0,d.A)(Eo,"labelOffset",3.5),(0,d.A)(Eo,"radius",3),(0,d.A)(Eo,"labelSize",{x:3.5,y:2.5}),(0,d.A)(Eo,"colors",{fillUsed:"#0097A8",fill:"white",fillPotentially:"#167782",strokeUsed:"#0097A8",stroke:"#167782",strokePotentially:"#167782"});var So={},Oo=function(e){function t(e,n,o,r,a){var s,u,c;return(0,i.A)(this,t),c=Po(this,t,[e]),(0,d.A)((0,l.A)(c),"freeSectorsList",bn),(0,d.A)((0,l.A)(c),"attachmentPoints",[]),(0,d.A)((0,l.A)(c),"hoveredAttachmenPoint",null),(0,d.A)((0,l.A)(c),"enumeration",null),(0,d.A)((0,l.A)(c),"beginning",null),c.monomer=e,c.monomerSelectedElementId=n,c.monomerHoveredElementId=o,c.scale=a,c.monomer.setRenderer((0,l.A)(c)),c.editorEvents=vo,c.monomerSymbolElement=document.querySelector("".concat(r," .monomer-body")),c.monomerSize={width:+((null===(s=c.monomerSymbolElement)||void 0===s?void 0:s.getAttribute("data-actual-width"))||0),height:+((null===(u=c.monomerSymbolElement)||void 0===u?void 0:u.getAttribute("data-actual-height"))||0)},c}return(0,c.A)(t,e),(0,a.A)(t,[{key:"isSnakeBondForAttachmentPoint",value:function(e){var t,n;return(null===(t=this.monomer.attachmentPointsToBonds[e])||void 0===t||null===(t=t.renderer)||void 0===t?void 0:t.isSnake)&&!(null!==(n=this.monomer.attachmentPointsToBonds[e])&&void 0!==n&&null!==(n=n.renderer)&&void 0!==n&&n.isMonomersOnSameHorizontalLine())}},{key:"center",get:function(){return new we(this.scaledMonomerPosition.x+this.monomerSize.width/2,this.scaledMonomerPosition.y+this.monomerSize.height/2)}},{key:"textColor",get:function(){var e="white";return{D:e,F:e,K:e,Q:e,R:e,W:e,Y:e}[this.monomer.monomerItem.props.MonomerNaturalAnalogCode]||"black"}},{key:"getMonomerColor",value:function(e){var t;return(null===(t=e.monomer.color[this.monomer.monomerItem.props.MonomerNaturalAnalogCode])||void 0===t?void 0:t.regular)||e.monomer.color.default.regular}},{key:"redrawAttachmentPoints",value:function(){this.hoveredAttachmenPoint=null,this.rootElement&&(this.monomer.attachmentPointsVisible?(this.removeAttachmentPoints(),this.drawAttachmentPoints()):this.removeAttachmentPoints())}},{key:"updateAttachmentPoints",value:function(){this.hoveredAttachmenPoint=null,this.rootElement&&(this.attachmentPoints.length>0?this.attachmentPoints.forEach((function(e){e.updateAttachmentPointStyleForHover()})):this.drawAttachmentPoints())}},{key:"redrawAttachmentPointsCoordinates",value:function(){var e=this.monomer.chosenFirstAttachmentPointForBond,t=this.attachmentPoints.find((function(t){return t.getAttachmentPointName()===e})),n=null==t?void 0:t.getAngle();if(this.attachmentPoints.map((function(e){return e.getAngle()})).some((function(e){return n!==e&&"number"==typeof n&&(Math.abs(n-e)<20||Math.abs(n-e)>340)})))this.redrawAttachmentPoints();else{var o=this.attachmentPoints.find((function(t){return t.getAttachmentPointName()===e}));f()(o),o.updateCoords()}}},{key:"drawAttachmentPoints",value:function(){var e=this;if(!this.attachmentPoints.length){this.monomer.usedAttachmentPointsNamesList.forEach((function(t){var n=e.appendAttachmentPoint(t),o=n.getAngle();if(e.attachmentPoints.push(n),"number"==typeof o){var r=e.freeSectorsList.filter((function(e){return yn[e].min>o||yn[e].max<=o}));e.freeSectorsList=An(r)}}));var t=[];this.monomer.unUsedAttachmentPointsNamesList.forEach((function(n){var o=gn[n];if(e.freeSectorsList.includes(o)){var r=e.appendAttachmentPoint(n,o);e.attachmentPoints.push(r);var i=e.freeSectorsList.filter((function(e){return e!==o}));e.freeSectorsList=An(i)}else t.push(n)})),t.forEach((function(t){var n=e.freeSectorsList.shift(),o=e.appendAttachmentPoint(t,n);e.attachmentPoints.push(o)}))}}},{key:"appendAttachmentPoint",value:function(e,t){var n;this.monomer.isAttachmentPointUsed(e)||(n=gn[e]);var o={rootElement:this.rootElement,monomer:this.monomer,bodyWidth:this.monomerSize.width,bodyHeight:this.monomerSize.height,canvas:this.canvasWrapper,attachmentPointName:e,isUsed:this.monomer.isAttachmentPointUsed(e),isPotentiallyUsed:this.monomer.isAttachmentPointPotentiallyUsed(e)||this.hoveredAttachmenPoint===e,angle:t||n,isSnake:!!this.isSnakeBondForAttachmentPoint(e)};return new Eo(o)}},{key:"removeAttachmentPoints",value:function(){this.attachmentPoints.forEach((function(e){e.removeAttachmentPoint()})),this.attachmentPoints=[],this.freeSectorsList=bn}},{key:"hoverAttachmenPoint",value:function(e){this.hoveredAttachmenPoint=e}},{key:"appendRootElement",value:function(e){return e.append("g").data([this]).attr("transition","transform 0.2s").attr("transform","translate(".concat(this.scaledMonomerPosition.x,", ").concat(this.scaledMonomerPosition.y,") scale(").concat(this.scale||1,")"))}},{key:"appendLabel",value:function(e){var t,n,o=e.append("text").text(this.monomer.label).attr("fill",this.textColor).attr("font-size","".concat(6,"px")).attr("line-height","".concat(6,"px")).attr("font-weight","700").style("cursor","pointer").style("user-select","none").attr("pointer-events","none"),r=this.monomer.label+this.monomer.monomerItem.props.MonomerType;if(!So[r]){var i=o.node().getBBox();So[r]={x:this.width/2-i.width/2,y:this.height/2}}o.attr("x",(null===(t=So[r])||void 0===t?void 0:t.x)||0).attr("y",(null===(n=So[r])||void 0===n?void 0:n.y)||0),this.scale&&1!==this.scale&&(So[r]=void 0)}},{key:"appendHover",value:function(e){return this.hoverElement&&this.hoverElement.remove(),e.append("use").attr("href",this.monomerHoveredElementId).attr("pointer-events","none")}},{key:"removeHover",value:function(){this.hoverElement&&this.hoverElement.remove()}},{key:"scaledMonomerPosition",get:function(){return t.getScaledMonomerPosition(this.monomer.position,this.monomerSize)}},{key:"appendSelection",value:function(){var e,t;this.selectionCircle?this.selectionCircle.attr("cx",this.center.x).attr("cy",this.center.y):(this.selectionBorder=null===(e=this.rootElement)||void 0===e?void 0:e.append("use").attr("href",this.monomerSelectedElementId).attr("stroke","#57FF8F").attr("pointer-events","none"),this.selectionCircle=null===(t=this.canvas)||void 0===t?void 0:t.insert("circle",":first-child").attr("r","21px").attr("opacity","0.7").attr("cx",this.center.x).attr("cy",this.center.y).attr("fill","#57FF8F"))}},{key:"removeSelection",value:function(){var e,t;null===(e=this.selectionCircle)||void 0===e||e.remove(),null===(t=this.selectionBorder)||void 0===t||t.remove(),this.selectionCircle=void 0,this.selectionBorder=void 0}},{key:"appendHoverAreaElement",value:function(){this.hoverAreaElement=this.rootElement}},{key:"appendEvents",value:function(){var e=this;f()(this.bodyElement),this.bodyElement.on("mouseover",(function(t){e.editorEvents.mouseOverDrawingEntity.dispatch(t),e.editorEvents.mouseOverMonomer.dispatch(t)})).on("mousemove",(function(t){e.editorEvents.mouseOnMoveMonomer.dispatch(t)})).on("mouseleave",(function(t){e.editorEvents.mouseLeaveDrawingEntity.dispatch(t),e.editorEvents.mouseLeaveMonomer.dispatch(t)})).on("mouseup",(function(t){e.editorEvents.mouseUpMonomer.dispatch(t)}))}},{key:"setEnumeration",value:function(e){this.enumeration=e}},{key:"appendEnumeration",value:function(){f()(this.rootElement),f()(this.enumerationElementPosition),this.enumerationElement=this.rootElement.append("text").attr("direction","rtl").attr("fill","#7C7C7F").attr("font-size","6px").attr("line-height","7px").attr("font-weight","500").attr("text-align","right").attr("x",this.enumerationElementPosition.x).attr("y",this.enumerationElementPosition.y).text(this.enumeration)}},{key:"redrawEnumeration",value:function(){f()(this.enumerationElement),this.enumerationElement.text(this.enumeration)}},{key:"setBeginning",value:function(e){this.beginning=e}},{key:"appendChainBeginning",value:function(){f()(this.rootElement),f()(this.beginningElementPosition),this.beginningElement=this.rootElement.append("text").attr("direction","rtl").attr("fill","#0097A8").attr("font-size","6px").attr("line-height","7px").attr("font-weight","700").attr("text-align","right").attr("x",this.beginningElementPosition.x).attr("y",this.beginningElementPosition.y).text(this.beginning)}},{key:"reDrawChainBeginning",value:function(){f()(this.beginningElement),f()(this.beginningElementPosition),this.beginningElement.attr("x",this.beginningElementPosition.x).attr("y",this.beginningElementPosition.y).text(this.beginning)}},{key:"show",value:function(e){this.rootElement=this.rootElement||this.appendRootElement(this.scale?this.canvasWrapper:this.canvas),this.bodyElement=this.appendBody(this.rootElement,e),this.appendEvents(),this.appendLabel(this.rootElement),this.appendHoverAreaElement(),this.monomer.selected&&this.drawSelection(),this.redrawAttachmentPoints()}},{key:"drawSelection",value:function(){this.rootElement&&(this.monomer.selected?(this.appendSelection(),this.raiseElement()):this.removeSelection())}},{key:"raiseElement",value:function(){var e,t;null===(e=this.selectionCircle)||void 0===e||e.raise(),null===(t=this.rootElement)||void 0===t||t.raise()}},{key:"moveSelection",value:function(){f()(this.rootElement),this.appendSelection(),this.move()}},{key:"move",value:function(){var e;null===(e=this.rootElement)||void 0===e||e.attr("transform","translate(".concat(this.scaledMonomerPosition.x,", ").concat(this.scaledMonomerPosition.y,") scale(").concat(this.scale||1,")"))}},{key:"remove",value:function(){var e;null===(e=this.rootElement)||void 0===e||e.remove(),this.rootElement=void 0,this.removeSelection(),this.monomer.hovered&&this.editorEvents.mouseLeaveMonomer.dispatch()}}],[{key:"isSelectable",value:function(){return!0}},{key:"getScaledMonomerPosition",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{width:0,height:0},n=sn.modelToCanvas(e);return new we(n.x-t.width/2,n.y-t.height/2)}}]),t}(un);function ko(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Mo()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Mo(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Mo=function(){return!!e})()}var Ro="#chem-selection",To="#chem",Bo=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=ko(this,t,[e,Ro,Ro,To,n])).monomer=e,o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"appendBody",value:function(e,t){return e.append("use").data([this]).attr("href",To).style("cursor","pointer").attr("stroke",t.monomer.color.CHEM.regular)}},{key:"enumerationElementPosition",get:function(){}},{key:"beginningElementPosition",get:function(){}}]),t}(Oo);function Co(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Io()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Io(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Io=function(){return!!e})()}var No="#peptide",Do=function(e){function t(e,n){var o;return(0,i.A)(this,t),o=Co(this,t,[e,"#peptide-selection","#peptide-hover",No,n]),(0,d.A)((0,l.A)(o),"CHAIN_BEGINNING","N"),o.monomer=e,o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"appendBody",value:function(e,t){return e.append("use").data([this]).attr("href",No).style("cursor","pointer").attr("fill",this.getMonomerColor(t))}},{key:"show",value:function(e){(0,E.A)((0,u.A)(t.prototype),"show",this).call(this,e),this.appendEnumeration(),this.appendChainBeginning()}},{key:"enumerationElementPosition",get:function(){return{x:10,y:-1}}},{key:"beginningElementPosition",get:function(){return{x:-6,y:10}}}]),t}(Oo);function Lo(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,_o()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function _o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(_o=function(){return!!e})()}var Fo="#phosphate-selection",Ho="#phosphate",jo=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=Lo(this,t,[e,Fo,Fo,Ho,n])).monomer=e,o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"appendBody",value:function(e,t){return e.append("use").data([this]).attr("href",Ho).style("cursor","pointer").attr("fill",this.getMonomerColor(t))}},{key:"enumerationElementPosition",get:function(){}},{key:"beginningElementPosition",get:function(){}}]),t}(Oo);function Go(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,zo()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function zo(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(zo=function(){return!!e})()}var Vo="#sugar-selection",Uo="#sugar",Wo=function(e){function t(e,n){var o;return(0,i.A)(this,t),o=Go(this,t,[e,Vo,Vo,Uo,n]),(0,d.A)((0,l.A)(o),"CHAIN_BEGINNING","’5"),o.monomer=e,o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"appendBody",value:function(e,t){return e.append("use").data([this]).attr("href",Uo).style("cursor","pointer").attr("fill",this.getMonomerColor(t))}},{key:"show",value:function(e){(0,E.A)((0,u.A)(t.prototype),"show",this).call(this,e),this.appendChainBeginning()}},{key:"enumerationElementPosition",get:function(){}},{key:"beginningElementPosition",get:function(){return{x:-5,y:7}}}]),t}(Oo);function qo(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Yo()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Yo(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Yo=function(){return!!e})()}var $o="#rna-base-selection",Xo="#rna-base",Ko=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=qo(this,t,[e,$o,$o,Xo,n])).monomer=e,o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"appendBody",value:function(e,t){return e.append("use").data([this]).attr("href",Xo).style("cursor","pointer").attr("fill",this.getMonomerColor(t))}},{key:"show",value:function(e){(0,E.A)((0,u.A)(t.prototype),"show",this).call(this,e),this.appendEnumeration()}},{key:"enumerationElementPosition",get:function(){return{x:11,y:5}}},{key:"beginningElementPosition",get:function(){}}]),t}(Oo),Zo=function(){function e(){(0,i.A)(this,e),(0,d.A)(this,"operations",[]),(0,d.A)(this,"undoOperationReverse",!1)}return(0,a.A)(e,[{key:"addOperation",value:function(e){this.operations.push(e)}},{key:"merge",value:function(e){this.operations=[].concat((0,o.A)(this.operations),(0,o.A)(e.operations))}},{key:"setUndoOperationReverse",value:function(){this.undoOperationReverse=!0}},{key:"invert",value:function(e){(this.undoOperationReverse?this.operations.slice().reverse():this.operations).forEach((function(t){return t.invert(e)})),e.runPostRenderMethods()}},{key:"execute",value:function(e){this.operations.forEach((function(t){return t.execute(e)})),e.runPostRenderMethods()}}]),e}(),Qo=function(){function e(t,n){(0,i.A)(this,e),this.addPolymerBondChangeModel=t,this.deletePolymerBondChangeModel=n,this.polymerBond=this.addPolymerBondChangeModel()}return(0,a.A)(e,[{key:"execute",value:function(e){this.polymerBond=this.addPolymerBondChangeModel(this.polymerBond),e.addPolymerBond(this.polymerBond)}},{key:"invert",value:function(e){this.deletePolymerBondChangeModel(this.polymerBond),e.deletePolymerBond(this.polymerBond)}}]),e}(),Jo=function(){function e(t,n,o){(0,i.A)(this,e),this.polymerBond=t,this.deletePolymerBondChangeModel=n,this.finishPolymerBondCreationModelChange=o}return(0,a.A)(e,[{key:"execute",value:function(e){this.deletePolymerBondChangeModel(),e.deletePolymerBond(this.polymerBond)}},{key:"invert",value:function(e){this.polymerBond=this.finishPolymerBondCreationModelChange(this.polymerBond),e.addPolymerBond(this.polymerBond)}}]),e}(),er=function(){function e(t){(0,i.A)(this,e),this.polymerBond=t}return(0,a.A)(e,[{key:"execute",value:function(e){e.movePolymerBond(this.polymerBond)}},{key:"invert",value:function(){}}]),e}(),tr=function(){function e(t){(0,i.A)(this,e),this.polymerBond=t}return(0,a.A)(e,[{key:"execute",value:function(e){e.showPolymerBondInformation(this.polymerBond)}},{key:"invert",value:function(){}}]),e}(),nr=function(){function e(t,n){(0,i.A)(this,e),this.polymerBond=t,this.secondMonomer=n}return(0,a.A)(e,[{key:"execute",value:function(e){e.cancelPolymerBondCreation(this.polymerBond,this.secondMonomer)}},{key:"invert",value:function(){}}]),e}(),or=function(){function e(t,n){(0,i.A)(this,e),this.finishPolymerBondCreationModelChange=t,this.deletePolymerBondCreationModelChange=n,this.polymerBond=this.finishPolymerBondCreationModelChange()}return(0,a.A)(e,[{key:"execute",value:function(e){this.polymerBond=this.finishPolymerBondCreationModelChange(this.polymerBond),e.finishPolymerBondCreation(this.polymerBond)}},{key:"invert",value:function(e){this.deletePolymerBondCreationModelChange(this.polymerBond),e.deletePolymerBond(this.polymerBond)}}]),e}(),rr=function(){function e(t,n,o,r){(0,i.A)(this,e),this._onExecute=t,this._onInvert=n,this.mode=o,this.prevMode=r,this.onExecute=t,this.onInvert=n}return(0,a.A)(e,[{key:"execute",value:function(){this.onExecute()}},{key:"invert",value:function(){this.onInvert()}}]),e}(),ir=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"flex-layout-mode";(0,i.A)(this,e),this.modeName=t,this.previousMode=n}return(0,a.A)(e,[{key:"changeMode",value:function(e,t){e.events.layoutModeChange.dispatch(t);var n=Hs[t];e.setMode(new n),e.mode.initialize()}},{key:"initialize",value:function(){var e=new Zo,t=zc.provideEditorInstance();return e.addOperation(new rr(this.changeMode.bind(this,t,this.modeName),this.changeMode.bind(this,t,this.previousMode),this.modeName,this.previousMode)),t.events.selectTool.dispatch("select-rectangle"),e}},{key:"destroy",value:function(){}}]),e}();function ar(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,sr()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function sr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(sr=function(){return!!e})()}var ur=function(e){function t(e){return(0,i.A)(this,t),ar(this,t,["flex-layout-mode",e])}return(0,c.A)(t,e),(0,a.A)(t,[{key:"initialize",value:function(){var e=(0,E.A)((0,u.A)(t.prototype),"initialize",this).call(this),n=zc.provideEditorInstance(),o=n.drawingEntitiesManager.applyFlexLayoutMode(!0);return n.renderersContainer.update(o),e}},{key:"onKeyDown",value:function(e){}}]),t}(ir);function lr(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,cr()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function cr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(cr=function(){return!!e})()}var dr=function(e){function t(){return(0,i.A)(this,t),lr(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t)}(On);function hr(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,fr()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function fr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(fr=function(){return!!e})()}var mr=function(e){function t(){return(0,i.A)(this,t),hr(this,t,[{label:"",struct:new Yt,props:{MonomerNaturalAnalogCode:"",MonomerName:"",Name:""}}])}return(0,c.A)(t,e),(0,a.A)(t,[{key:"getValidSourcePoint",value:function(){}},{key:"getValidTargetPoint",value:function(){}},{key:"SubChainConstructor",get:function(){return dr}},{key:"isMonomerTypeDifferentForChaining",value:function(){return!0}}]),t}(Sn),pr=function(){function e(){(0,i.A)(this,e),(0,d.A)(this,"renderer",void 0),(0,d.A)(this,"monomer",new mr)}return(0,a.A)(e,[{key:"SubChainConstructor",get:function(){return dr}},{key:"firstMonomerInNode",get:function(){return this.monomer}},{key:"lastMonomerInNode",get:function(){return this.monomer}},{key:"hovered",get:function(){return!1}},{key:"selected",get:function(){return!1}},{key:"monomerItem",get:function(){return{props:{MonomerNaturalAnalogCode:null}}}},{key:"monomers",get:function(){return[]}},{key:"setRenderer",value:function(e){this.renderer=e,this.monomer.setRenderer(e)}},{key:"modified",get:function(){return!1}}]),e}();function vr(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,gr()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function gr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(gr=function(){return!!e})()}var yr=function(e){function t(e,n,o,r,a,s,u,l){var c;return(0,i.A)(this,t),(c=vr(this,t,[e.monomer])).node=e,c.firstNodeInChainPosition=n,c.monomerIndexInChain=o,c.isLastMonomerInChain=r,c.subChain=a,c._isEditingSymbol=s,c.monomerSize=u,c.scaledMonomerPosition=l,c.editorEvents=vo,c}return(0,c.A)(t,e),(0,a.A)(t,[{key:"isEditingSymbol",get:function(){return this._isEditingSymbol},set:function(e){this._isEditingSymbol=e}},{key:"appendHover",value:function(){}},{key:"appendHoverAreaElement",value:function(){}},{key:"moveSelection",value:function(){}},{key:"currentSubChain",get:function(){return this.subChain}},{key:"scaledMonomerPositionForSequence",get:function(){var e=this.monomerIndexInChain%this.symbolsInRow,t=Math.floor(this.monomerIndexInChain/this.symbolsInRow);return new we(this.firstNodeInChainPosition.x+20*e+10*Math.floor(e/this.nthSeparationInRow),this.firstNodeInChainPosition.y+47*t)}},{key:"center",get:function(){return this.scaledMonomerPositionForSequence.add(new we(4.5,0,0))}},{key:"isSequenceEditModeTurnedOn",get:function(){var e=zc.provideEditorInstance();return e.mode instanceof Ds&&e.mode.isEditMode}},{key:"appendRootElement",value:function(){return this.canvas.append("g").data([this]).attr("transition","transform 0.2s").attr("transform","translate(".concat(this.scaledMonomerPositionForSequence.x,", ").concat(this.scaledMonomerPositionForSequence.y,")"))}},{key:"appendBackgroundElement",value:function(){var e,t=null===(e=this.rootElement)||void 0===e?void 0:e.append("rect").attr("width",16).attr("height",20).attr("y",-16).attr("x",-2).attr("rx",2).attr("cursor","text");return this.node.modified&&(null==t||t.attr("stroke","#585858").attr("stroke-width","1px")),null==t||t.attr("fill",this.isSequenceEditModeTurnedOn?"#FF7A001A":"transparent"),t}},{key:"appendSpacerElement",value:function(){var e,t=null===(e=this.rootElement)||void 0===e?void 0:e.append("g").attr("transform","translate(14, -16)");return null==t||t.append("rect").attr("width",4).attr("height",20).attr("cursor","text").attr("fill","transparent"),t}},{key:"nthSeparationInRow",get:function(){return 10}},{key:"symbolsInRow",get:function(){return 30}},{key:"appendCounterElement",value:function(e){return e.append("text").attr("x","-2").attr("y","-24").text(this.monomerIndexInChain+1).attr("font-family","Courier New").attr("font-size","12px").attr("font-weight","700").attr("fill","#7C7C7F")}},{key:"needDisplayCounter",get:function(){return((this.monomerIndexInChain+1)%this.nthSeparationInRow==0||this.isLastMonomerInChain)&&!(this.node instanceof pr)}},{key:"isBeginningOfChain",get:function(){return 0===this.monomerIndexInChain}},{key:"appendCaretElement",value:function(){var e;null===(e=this.spacerElement)||void 0===e||e.append("line").attr("x1",-16).attr("y1",-1).attr("x2",-16).attr("y2",21).attr("stroke","#333").attr("class","blinking")}},{key:"drawHover",value:function(){var e;null===(e=this.backgroundElement)||void 0===e||e.attr("fill",this.isSequenceEditModeTurnedOn?"#FF7A0033":"#EFF2F5")}},{key:"removeHover",value:function(){var e;null===(e=this.backgroundElement)||void 0===e||e.attr("fill",this.isSequenceEditModeTurnedOn?"#FF7A001A":"transparent")}},{key:"appendChainStartArrow",value:function(){var e;null===(e=this.rootElement)||void 0===e||e.append("use").attr("x",-17).attr("y",-27).attr("href","#".concat("sequence-start-arrow"))}},{key:"show",value:function(){var e=this;this.rootElement=this.appendRootElement(),this.isBeginningOfChain&&this.isSequenceEditModeTurnedOn&&this.appendChainStartArrow(),this.spacerElement=this.appendSpacerElement(),this.backgroundElement=this.appendBackgroundElement(),this.isSequenceEditModeTurnedOn&&(this.isEditingSymbol&&this.appendCaretElement(),this.drawSelection()),this.textElement=this.rootElement.append("text").text(this.symbolToDisplay).attr("font-family","Courier New").attr("font-size","20px").attr("font-weight","700").attr("fill","#333333"),this.appendEvents(),this.needDisplayCounter&&(this.counterElement=this.appendCounterElement(this.rootElement)),this.rootElement.on("mouseover",(function(){e.node.monomer.selected||e.drawHover()})),this.rootElement.on("mouseleave",(function(){e.removeHover()}))}},{key:"drawSelection",value:function(){this.rootElement&&(this.node.monomer.selected?(this.appendSelection(),this.removeHover(),this.raiseElement()):this.removeSelection())}},{key:"appendSelection",value:function(){var e,t;this.selectionRectangle?this.selectionRectangle.attr("x",this.scaledMonomerPositionForSequence.x-4).attr("y",this.scaledMonomerPositionForSequence.y-16).attr("width",20).attr("height",20):(this.selectionBorder=null===(e=this.rootElement)||void 0===e?void 0:e.append("use").attr("href",this.monomerIndexInChain).attr("stroke","#57FF8F").attr("pointer-events","none"),this.selectionRectangle=null===(t=this.canvas)||void 0===t?void 0:t.insert("rect",":first-child").attr("opacity","0.7").attr("fill","#57FF8F").attr("x",this.scaledMonomerPositionForSequence.x-4).attr("y",this.scaledMonomerPositionForSequence.y-16).attr("width",20).attr("height",20))}},{key:"removeSelection",value:function(){var e,t;null===(e=this.selectionRectangle)||void 0===e||e.remove(),null===(t=this.selectionBorder)||void 0===t||t.remove(),this.selectionRectangle=void 0,this.selectionBorder=void 0}},{key:"raiseElement",value:function(){var e,t;null===(e=this.selectionRectangle)||void 0===e||e.raise(),null===(t=this.rootElement)||void 0===t||t.raise()}},{key:"remove",value:function(){var e;null===(e=this.rootElement)||void 0===e||e.remove(),this.rootElement=void 0,this.removeSelection()}},{key:"setEnumeration",value:function(){}},{key:"redrawEnumeration",value:function(){}},{key:"redrawAttachmentPoints",value:function(){}},{key:"redrawAttachmentPointsCoordinates",value:function(){}},{key:"enumeration",get:function(){return null}},{key:"hoverAttachmenPoint",value:function(){}},{key:"updateAttachmentPoints",value:function(){}},{key:"appendEvents",value:function(){var e=this;f()(this.textElement),this.textElement.on("mouseover",(function(t){e.editorEvents.mouseOverSequenceItem.dispatch(t)})),this.textElement.on("mousemove",(function(t){e.editorEvents.mouseOnMoveSequenceItem.dispatch(t)})),this.textElement.on("mouseleave",(function(t){e.editorEvents.mouseLeaveSequenceItem.dispatch(t)}))}}]),t}(hn);function br(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Ar()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Ar(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Ar=function(){return!!e})()}var wr=function(e){function t(){return(0,i.A)(this,t),br(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t,[{key:"symbolToDisplay",get:function(){return this.node.monomer.monomerItem.props.MonomerNaturalAnalogCode||"@"}}]),t}(yr);function Er(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Pr()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Pr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Pr=function(){return!!e})()}var xr=function(e){function t(){return(0,i.A)(this,t),Er(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t,[{key:"symbolToDisplay",get:function(){return"@"}}]),t}(yr);function Sr(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Or()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Or(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Or=function(){return!!e})()}var kr=function(e){function t(){return(0,i.A)(this,t),Sr(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t,[{key:"symbolToDisplay",get:function(){return"p"}}]),t}(yr);function Mr(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Rr()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Rr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Rr=function(){return!!e})()}var Tr,Br=function(e){function t(){return(0,i.A)(this,t),Mr(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t,[{key:"symbolToDisplay",get:function(){var e;return(null===(e=this.node.monomer.attachmentPointsToBonds.R3)||void 0===e||null===(e=e.getAnotherMonomer(this.node.monomer))||void 0===e||null===(e=e.monomerItem)||void 0===e?void 0:e.props.MonomerNaturalAnalogCode)||"@"}}]),t}(yr);!function(e){e.SUGAR_RNA="R",e.SUGAR_DNA="dR",e.PHOSPHATE="P"}(Tr||(Tr={}));var Cr=["A","T","G","C","U"],Ir=["A","C","D","E","F","G","H","I","K","L","M","N","P","Q","R","S","T","V","W","Y"];function Nr(e,t){return e.monomersLibrary.RNA.find((function(e){return e.props.MonomerName===t}))}function Dr(e){switch(e){case jc.DNA:return Tr.SUGAR_DNA;case jc.RNA:return Tr.SUGAR_RNA;default:return}}var Lr=function(){function e(t,n,o){(0,i.A)(this,e),this.sugar=t,this.rnaBase=n,this.phosphate=o}return(0,a.A)(e,[{key:"isMonomerTypeDifferentForChaining",value:function(e){return this.sugar.isMonomerTypeDifferentForChaining(e)}},{key:"SubChainConstructor",get:function(){return this.sugar.SubChainConstructor}},{key:"monomer",get:function(){return this.sugar}},{key:"monomers",get:function(){return[this.sugar,this.rnaBase,this.phosphate]}},{key:"firstMonomerInNode",get:function(){return this.sugar}},{key:"lastMonomerInNode",get:function(){return this.phosphate}},{key:"renderer",get:function(){return this.monomer.renderer}},{key:"modified",get:function(){return this.sugar.label!==Tr.SUGAR_RNA}}],[{key:"fromSugar",value:function(t){if(!(arguments.length>1&&void 0!==arguments[1])||arguments[1]){f()(ao(t),"Nucleotide is not valid. Please check nucleotide parts connections.");var n=so(t);f()(!n,"Nucleotide is nucleoside because it is a last sugar+base of rna chain")}return new e(t,oo(t),ro(t))}},{key:"createOnCanvas",value:function(t,n){var o=zc.provideEditorInstance(),r=Nr(o,t),i=Nr(o,Tr.PHOSPHATE),a=Dr(o.sequenceTypeEnterMode);f()(a);var s=Nr(o,a);f()(s),f()(r),f()(i);var u=o.drawingEntitiesManager.addRnaPreset({sugar:s,sugarPosition:n,rnaBase:r,rnaBasePosition:n,phosphate:i,phosphatePosition:n}),l=u.command,c=u.monomers.find((function(e){return e instanceof eo}));return{modelChanges:l,node:e.fromSugar(c,!1)}}}]),e}();function _r(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Fr()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Fr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Fr=function(){return!!e})()}var Hr=function(e){function t(){return(0,i.A)(this,t),_r(this,t,arguments)}return(0,c.A)(t,e),(0,a.A)(t,[{key:"symbolToDisplay",get:function(){return""}}]),t}(yr),jr=function(){function e(){(0,i.A)(this,e)}return(0,a.A)(e,null,[{key:"fromNode",value:function(e,t,n,o,r,i,a){var s;switch(e.constructor){case Lr:case Vc:s=Br;break;case pr:s=Hr;break;default:switch(e.monomer.constructor){case Kn:s=kr;break;case Dn:s=wr;break;default:s=xr}}return new s(e,t,n,o,r,i,null==a?void 0:a.monomerSize,null==a?void 0:a.scaledMonomerPosition)}}]),e}();function Gr(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,zr()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function zr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(zr=function(){return!!e})()}var Vr=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=Gr(this,t,[e])).polymerBond=e,r.firstNode=n,r.secondNode=o,r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"firstMonomer",get:function(){var e;return(null===(e=this.firstNode)||void 0===e?void 0:e.monomer)||this.polymerBond.firstMonomer}},{key:"secondMonomer",get:function(){var e;return(null===(e=this.secondNode)||void 0===e?void 0:e.monomer)||this.polymerBond.secondMonomer}},{key:"areMonomersOnSameRow",get:function(){var e,t,n;return f()(this.firstMonomer.renderer instanceof yr),f()((null===(e=this.secondMonomer)||void 0===e?void 0:e.renderer)instanceof yr),(null===(t=this.firstMonomer.renderer)||void 0===t?void 0:t.scaledMonomerPositionForSequence.y)===(null===(n=this.secondMonomer)||void 0===n||null===(n=n.renderer)||void 0===n?void 0:n.scaledMonomerPositionForSequence.y)}},{key:"scaledPosition",get:function(){var e;f()(this.firstMonomer.renderer instanceof yr),f()((null===(e=this.secondMonomer)||void 0===e?void 0:e.renderer)instanceof yr);var t=this.firstMonomer.renderer.scaledMonomerPositionForSequence.y,n=this.firstMonomer.renderer.scaledMonomerPositionForSequence.x,o=this.secondMonomer.renderer.scaledMonomerPositionForSequence.y,r=this.secondMonomer.renderer.scaledMonomerPositionForSequence.x;return{startPosition:new we(n,t),endPosition:new we(r,o)}}},{key:"center",get:function(){return we.centre(new we(this.scaledPosition.startPosition.x+6,this.mainLineY.mainLineY1),new we(this.scaledPosition.startPosition.x+6,this.mainLineY.mainLineY2))}},{key:"mainLineY",get:function(){return{mainLineY1:this.scaledPosition.startPosition.y-(this.scaledPosition.startPosition.y>this.scaledPosition.endPosition.y?15:-3)+(this.areMonomersOnSameRow?-25:0),mainLineY2:this.scaledPosition.endPosition.y-(this.scaledPosition.endPosition.y>this.scaledPosition.startPosition.y?15:-3)+(this.areMonomersOnSameRow?-25:0)}}},{key:"show",value:function(){var e;this.rootElement=this.canvas.insert("g",":first-child").data([this]),null===(e=this.rootElement)||void 0===e||e.append("path").attr("stroke","black").attr("fill","none").attr("d",this.getBondPath())}},{key:"drawSelection",value:function(){var e,t,n;f()(this.rootElement),this.polymerBond.selected?(null===(e=this.selectionElement)||void 0===e||e.remove(),this.selectionElement=null===(t=this.rootElement)||void 0===t?void 0:t.insert("path",":first-child").attr("stroke","#57FF8F").attr("stroke-width","6").attr("fill","none"),this.selectionElement.attr("d",this.getBondPath())):null===(n=this.selectionElement)||void 0===n||n.remove()}},{key:"getBondPath",value:function(){return this.areMonomersOnSameRow?"M ".concat(this.scaledPosition.startPosition.x+6,",\n ").concat(this.mainLineY.mainLineY1+5," \n L ").concat(this.scaledPosition.startPosition.x+6,", ").concat(this.mainLineY.mainLineY1," \n L ").concat(this.scaledPosition.endPosition.x+6,", ").concat(this.mainLineY.mainLineY2,"\n L ").concat(this.scaledPosition.endPosition.x+6,", ").concat(this.mainLineY.mainLineY2+5):"M ".concat(this.scaledPosition.startPosition.x+6,", ").concat(this.mainLineY.mainLineY1," L ").concat(this.scaledPosition.endPosition.x+6,", ").concat(this.mainLineY.mainLineY2)}},{key:"moveStart",value:function(){}},{key:"moveEnd",value:function(){}},{key:"isSnake",get:function(){return!1}},{key:"isMonomersOnSameHorizontalLine",value:function(){return!1}}]),t}(hn);function Ur(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Wr()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Wr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Wr=function(){return!!e})()}var qr=function(e){function t(e){return(0,i.A)(this,t),Ur(this,t,[e])}return(0,c.A)(t,e),(0,a.A)(t,[{key:"isSnake",get:function(){return!1}},{key:"isMonomersOnSameHorizontalLine",value:function(){return!1}},{key:"moveStart",value:function(){}},{key:"moveEnd",value:function(){}}]),t}(hn);function Yr(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,$r()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function $r(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return($r=function(){return!!e})()}var Xr=function(e){function t(e,n){var o;return(0,i.A)(this,t),o=Yr(this,t),(0,d.A)((0,l.A)(o),"renderer",void 0),(0,d.A)((0,l.A)(o),"endPosition",new we),o.firstMonomer=e,o.firstMonomer=e,o.secondMonomer=n,o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"setFirstMonomer",value:function(e){this.firstMonomer=e}},{key:"setSecondMonomer",value:function(e){this.secondMonomer=e}},{key:"setRenderer",value:function(e){(0,E.A)((0,u.A)(t.prototype),"setBaseRenderer",this).call(this,e),this.renderer=e}},{key:"finished",get:function(){return Boolean(this.firstMonomer&&this.secondMonomer)}},{key:"center",get:function(){return we.centre(this.startPosition,this.endPosition)}},{key:"moveToLinkedMonomers",value:function(){var e,t=this.firstMonomer.position,n=null===(e=this.secondMonomer)||void 0===e?void 0:e.position;this.moveBondStartAbsolute(t.x,t.y),n&&this.moveBondEndAbsolute(n.x,n.y)}},{key:"moveBondStartAbsolute",value:function(e,t){this.moveAbsolute(new we(e,t))}},{key:"moveBondEndAbsolute",value:function(e,t){this.endPosition=new we(e,t)}},{key:"startPosition",get:function(){return this.position}},{key:"getAnotherMonomer",value:function(e){return this.firstMonomer===e?this.secondMonomer:this.firstMonomer}},{key:"isBackBoneChainConnection",get:function(){return!this.isSideChainConnection}},{key:"isSideChainConnection",get:function(){var e,n=this.firstMonomer.getAttachmentPointByBond(this),o=null===(e=this.secondMonomer)||void 0===e?void 0:e.getAttachmentPointByBond(this);return!(!n||!o||t.backBoneChainAttachmentPoints.includes(n)&&t.backBoneChainAttachmentPoints.includes(o)&&n!==o)}}],[{key:"backBoneChainAttachmentPoints",get:function(){return[dn.R1,dn.R2]}}]),t}(mn),Kr=function(){function e(t){(0,i.A)(this,e),this.monomer=t}return(0,a.A)(e,[{key:"SubChainConstructor",get:function(){return this.monomer.SubChainConstructor}},{key:"firstMonomerInNode",get:function(){return this.monomer}},{key:"lastMonomerInNode",get:function(){return this.monomer}},{key:"monomers",get:function(){return[this.monomer]}},{key:"renderer",get:function(){return this.monomer.renderer}},{key:"modified",get:function(){return!1}}]),e}(),Zr=function(){function e(t,n){(0,i.A)(this,e),(0,d.A)(this,"subChains",[]),(0,d.A)(this,"isCyclic",!1),this.firstMonomer=null,t&&(this.firstMonomer=t,this.fillSubChains(t)),n&&(this.isCyclic=n)}return(0,a.A)(e,[{key:"add",value:function(e){var t;(!(null!==(t=this.lastNode)&&void 0!==t&&t.monomer)||e.isMonomerTypeDifferentForChaining(this.lastNode.monomer))&&this.subChains.push(new e.SubChainConstructor),e instanceof eo?so(e)?this.lastSubChain.add(Vc.fromSugar(e)):ao(e)?this.lastSubChain.add(Lr.fromSugar(e)):this.lastSubChain.add(new Kr(e)):this.lastSubChain.add(new Kr(e))}},{key:"fillSubChains",value:function(e){e&&(this.add(e),this.lastNode instanceof Lr?this.fillSubChains(no(ro(e),this.firstMonomer)):this.fillSubChains(no(e,this.firstMonomer)))}},{key:"lastSubChain",get:function(){return this.subChains[this.subChains.length-1]}},{key:"lastNode",get:function(){var e;return null===(e=this.lastSubChain)||void 0===e?void 0:e.lastNode}},{key:"firstSubChain",get:function(){return this.subChains[0]}},{key:"firstNode",get:function(){var e;return null===(e=this.firstSubChain)||void 0===e?void 0:e.firstNode}},{key:"length",get:function(){var e=0;return this.subChains.forEach((function(t){e+=t.length})),e}},{key:"isEmpty",get:function(){return 1===this.subChains.length&&1===this.subChains[0].nodes.length&&this.subChains[0].nodes[0]instanceof pr}},{key:"forEachNode",value:function(e){this.subChains.forEach((function(t){t.nodes.forEach((function(n){e({node:n,subChain:t})}))}))}}]),e}(),Qr=function(){function e(){(0,i.A)(this,e)}return(0,a.A)(e,[{key:"execute",value:function(e){var t=zc.provideEditorInstance();f()(t.mode instanceof Ds),t.mode.initialize(!1)}},{key:"invert",value:function(e){var t=zc.provideEditorInstance();f()(t.mode instanceof Ds),t.mode.initialize(!1)}}]),e}(),Jr=function(){function e(t,n){(0,i.A)(this,e),this.previousPosition=t,this.nextPosition=n,this.execute()}return(0,a.A)(e,[{key:"execute",value:function(){Ts.setCaretPosition(this.nextPosition)}},{key:"invert",value:function(e){Ts.setCaretPosition(this.previousPosition)}}]),e}();k().el.translateAbs=function(e,t){this.delta=this.delta||new we,this.delta.x+=e-0,this.delta.y+=t-0,this.transform("t"+this.delta.x.toString()+","+this.delta.y.toString())},k().st.translateAbs=function(e,t){this.forEach((function(n){n.translateAbs(e,t)}))};var ei,ti,ni,oi=function(){function e(t){(0,i.A)(this,e),this.type=t,this.paths=[],this.boxes=[],this.boundingBox=null,this.oldBoundingBox=null,this.exts=[]}return(0,a.A)(e,[{key:"add",value:function(e,t,n){this.paths.push(e),t&&(this.boxes.push(t),this.boundingBox=null==this.boundingBox?t:nt.union(this.boundingBox,t)),n&&this.exts.push(n)}},{key:"clear",value:function(){this.paths=[],this.boxes=[],this.exts=[],null!==this.boundingBox&&(this.oldBoundingBox=this.boundingBox.clone()),this.boundingBox=null}},{key:"translate",value:function(){if(arguments.length>2)throw new Error("One vector or two scalar arguments expected");if(1===arguments.length){var e=arguments.length<=0?void 0:arguments[0];this.translate(e.x,e.y)}else{for(var t=arguments.length<=0?void 0:arguments[0],n=arguments.length<=1?void 0:arguments[1],o=new we(t,n),r=0;r<this.paths.length;++r)this.paths[r].translateAbs(t,n);for(var i=0;i<this.boxes.length;++i)this.boxes[i]=this.boxes[i].translate(o);null!==this.boundingBox&&(this.boundingBox=this.boundingBox.translate(o))}}},{key:"rotate",value:function(e,t){for(var n=0;n<this.paths.length;++n)this.paths[n].rotate(e,t.x,t.y);for(var o=0;o<this.boxes.length;++o)this.boxes[o]=this.boxes[o].transform((function(n){return n.rotateAroundOrigin(e,t)}));null!==this.boundingBox&&(this.boundingBox=this.boundingBox.transform((function(n){return n.rotateAroundOrigin(e,t)})))}}]),e}(),ri=function(){function e(t){(0,i.A)(this,e),(0,d.A)(this,"hover",!1),(0,d.A)(this,"hovering",null),(0,d.A)(this,"selected",!1),(0,d.A)(this,"selectionPlate",null),this.visel=new oi(t)}return(0,a.A)(e,[{key:"changeSelectionStyle",value:function(e){var t,n,o=e.hoverStyle;"simpleObject"===this.visel.type?null===(t=this.hovering)||void 0===t||t.attr({"fill-opacity":this.selected?1:0}):null===(n=this.hovering)||void 0===n||n.attr({fill:o.fill,"fill-opacity":this.selected?1:0})}},{key:"getVBoxObj",value:function(e){var t=this.visel.boundingBox;return null===t?null:(e.options.offset&&(t=t.translate(e.options.offset.negated())),t.transform(Ze.canvasToModel,e.options))}},{key:"setHover",value:function(e,t){var n=t.options;if(e){var o="hovering"in this&&null!==this.hovering;if(o)if("set"===this.hovering.type){if(!this.hovering[0])return;o=!this.hovering[0].removed}else o=!this.hovering.removed;o?(this.changeSelectionStyle(n),this.hovering.show()):(t.paper.setStart(),this.drawHover(t),this.hovering=t.paper.setFinish())}else this.hovering&&(this.changeSelectionStyle(n),this.hovering.hide());this.hover=e}},{key:"drawHover",value:function(e){throw new Error("ReObject.drawHover is not overridden.")}},{key:"makeSelectionPlate",value:function(e,t,n){throw new Error("ReObject.makeSelectionPlate is not overridden")}}]),e}();function ii(e){return{x:e.x,y:e.y,width:e.width,height:e.height}}!function(e){e.background="background",e.selectionPlate="selectionPlate",e.hovering="hovering",e.atom="atom",e.bondSkeleton="bondSkeleton",e.warnings="warnings",e.data="data",e.additionalInfo="additionalInfo",e.indices="indices"}(ei||(ei={})),function(e){e.LabelsOnly="LabelsOnly",e.BondsOnly="BondsOnly",e.LabelsAndBonds="LabelsAndBonds",e.Off="Off"}(ti||(ti={})),function(e){e.IUPAC="Iupac",e.Classic="Classic",e.On="On",e.Off="Off"}(ni||(ni={}));var ai={relBox:ii,shiftRayBox:function(e,t,n){f()(!!e),f()(!!t),f()(!!n);var o=[n.p0,new we(n.p1.x,n.p0.y),n.p1,new we(n.p0.x,n.p1.y)].map((function(t){return t.sub(e)}));t=t.normalized();for(var r=o.map((function(e){return we.cross(e,t)})),i=o.map((function(e){return we.dot(e,t)})),a=-1,s=-1,u=0;u<4;++u)r[u]>0?(a<0||i[a]<i[u])&&(a=u):(s<0||i[s]<i[u])&&(s=u);if(s<0||a<0)return 0;var l=i[a]>i[s]?s:a,c=i[a]>i[s]?a:s;return i[l]+Math.abs(r[l])*(i[c]-i[l])/(Math.abs(r[l])+Math.abs(r[c]))},calcCoordinates:function(e,t,n){var o={pos1:null,pos2:null},r={x:t.x-e.x,y:t.y-e.y},i=(Math.pow(n,2)-r.x*r.x-r.y*r.y-Math.pow(n,2))/-2,a=r.x*r.x+r.y*r.y;if(0!==r.x){var s=-2*r.y*i,u=s*s-4*a*(i*i-n*n*r.x*r.x);u>0&&(o.pos1={x:0,y:0},o.pos2={x:0,y:0},o.pos1.y=(-s+Math.sqrt(u))/(2*a),o.pos2.y=(-s-Math.sqrt(u))/(2*a),o.pos1.x=(i-o.pos1.y*r.y)/r.x,o.pos2.x=(i-o.pos2.y*r.y)/r.x)}else o.pos1={x:0,y:0},o.pos2={x:0,y:0},o.pos1.y=i/r.y,o.pos2.y=i/r.y,o.pos1.x=-Math.sqrt(Math.pow(n,2)-Math.pow(i,2)/Math.pow(r.y,2)),o.pos2.x=Math.sqrt(Math.pow(n,2)-Math.pow(i,2)/Math.pow(r.y,2));return null!==o.pos1&&(o.pos1.x+=e.x,o.pos1.y+=e.y),null!==o.pos2&&(o.pos2.x+=e.x,o.pos2.y+=e.y),o},drawCIPLabel:function(e){var t=e.atomOrBond,n=e.position,o=e.restruct,r=e.visel,i=o.render,a=i.options,s=i.paper,u=s.set(),l=function(e){var t=e.paper,n=e.cipLabelPosition,o=e.atomOrBond,r=e.options,i=t.text(n.x,n.y,"(".concat(o.cip,")")).attr({font:r.font,"font-size":r.fontsz}),a=i.getBBox(),s=t.set(),u=t.rect(a.x-1,a.y-1,a.width+2,a.height+2,3,3).attr({fill:"#fff",stroke:"#fff"});return s.push(u.toFront(),i.toFront()),{path:s,text:i,rectangle:u}}({paper:s,cipLabelPosition:n.scaled(a.microModeScale),atomOrBond:t,options:a}),c=ii(l.path.getBBox());return l.path.translateAbs(.5*c.width,-.5*c.height),u.push(l.path.toFront()),o.addReObjectPath(ei.additionalInfo,r,u,null,!0),l},updateHalfBondCoordinates:function(e,t,n){return e.p.y!==t.p.y||(e.p.x<t.p.x&&e.p.y===t.p.y?e.p.x=e.p.x+n:e.p.x>t.p.x&&(e.p.x=e.p.x-n)),[e,t]}};function si(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function ui(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?si(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):si(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function li(e,t){return"M"+U(e.x)+","+U(e.y)+"L"+U(t.x)+","+U(t.y)+"\t"}function ci(e,t,n){for(var o=0,r=we.dist(e,t),i=we.diff(t,e).normalized(),a=!0,s="",u=0;o<r;){var l=n[u%n.length],c=o+Math.min(l,r-o);a&&(s+="M "+e.addScaled(i,o).coordStr()+" L "+e.addScaled(i,c).coordStr()),o+=l,a=!a,u++}return s}function di(e,t){if(k().vml){var n=.16*t.height;e.translateAbs(0,n),t.y+=n}}var hi,fi,mi={recenterText:di,arrow:function(e,t,n,o,i,a){var s=a&&["0","-0","90","-90","180","-180"].includes(o.toFixed());switch(t.mode){case Pt.OpenAngle:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=s.x+n,l="M".concat(U(s.x),",").concat(U(s.y))+"L".concat(U(u),",").concat(U(s.y))+"L".concat(U(u-7),",").concat(U(s.y-5))+"M".concat(U(u),",").concat(U(s.y))+"L".concat(U(u-7),", ").concat(U(s.y+5)),c=R()(l).rotate(o,s.x,s.y).toString();return e.path(c).attr(ui(ui({},i.lineattr),a&&{stroke:i.arrowSnappingStyle.stroke}))}(e,t,n,o,i,s);case Pt.FilledTriangle:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=s.x+n,l="M".concat(U(s.x),",").concat(U(s.y))+"L".concat(U(u),",").concat(U(s.y))+"L".concat(U(u-10),",").concat(U(s.y+5))+"L".concat(U(u-10),",").concat(U(s.y-5))+"L".concat(U(u),",").concat(U(s.y),"Z"),c=R()(l).rotate(o,s.x,s.y).toString();return e.path(c).attr(ui(ui({},i.lineattr),{},{fill:"#000"},a&&i.arrowSnappingStyle))}(e,t,n,o,i,s);case Pt.FilledBow:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=s.x+n,l="M".concat(U(s.x),",").concat(U(s.y))+"L".concat(U(u),",").concat(U(s.y))+"L".concat(U(u-10),",").concat(U(s.y+5))+"L".concat(U(u-10+4),",").concat(U(s.y))+"L".concat(U(u-10),",").concat(U(s.y-5))+"L".concat(U(u),",").concat(U(s.y),"Z"),c=R()(l).rotate(o,s.x,s.y).toString();return e.path(c).attr(ui(ui({},i.lineattr),{},{fill:"#000"},a&&i.arrowSnappingStyle))}(e,t,n,o,i,s);case Pt.DashedOpenAngle:return function(e,t,n,o,i,a){for(var s=(0,r.A)(t.pos,1)[0],u=[],l=s.x+n,c=0;c<n/3.5;c++)c%2?u.push("L".concat(U(s.x+3.5*c),",").concat(U(s.y))):u.push("M".concat(U(s.x+3.5*c),",").concat(U(s.y)));u.push("M".concat(U(l),",").concat(U(s.y))+"L".concat(U(l-10),",").concat(U(s.y+5))+"M".concat(U(l),",").concat(U(s.y))+"L".concat(U(l-10),",").concat(U(s.y-5)));var d=R()(u.join("")).rotate(o,s.x,s.y).toString();return e.path(d).attr(ui(ui({},i.lineattr),{},{fill:"#000"},a&&i.arrowSnappingStyle))}(e,t,n,o,i,s);case Pt.Failed:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=s.x+n,l=u-(u-s.x)/2,c=[];c.push("M".concat(U(s.x),",").concat(U(s.y))+"L".concat(U(u),",").concat(U(s.y))+"L".concat(U(u-10),",").concat(U(s.y+5))+"L".concat(U(u-10+4),",").concat(U(s.y))+"L".concat(U(u-10),",").concat(U(s.y-5))+"L".concat(U(u),",").concat(U(s.y),"Z")),c.push("M".concat(U(l+8),",").concat(U(s.y+8))+"L".concat(U(l-8),",").concat(U(s.y-8))),c.push("M".concat(U(l+8),",").concat(U(s.y-8))+"L".concat(U(l-8),",").concat(U(s.y+8)));var d=R()(c.join("")).rotate(o,s.x,s.y).toString();return e.path(d).attr(ui(ui({},i.lineattr),{},{fill:"#000"},a&&i.arrowSnappingStyle))}(e,t,n,o,i,s);case Pt.BothEndsFilledTriangle:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=s.x+n,l="M".concat(U(s.x),",").concat(U(s.y))+"L".concat(U(u),",").concat(U(s.y))+"L".concat(U(u-10),",").concat(U(s.y+5))+"L".concat(U(u-10),",").concat(U(s.y-5))+"L".concat(U(u),",").concat(U(s.y))+"M".concat(U(s.x),",").concat(U(s.y))+"L".concat(U(s.x+10),",").concat(U(s.y-5))+"L".concat(U(s.x+10),",").concat(U(s.y+5))+"L".concat(U(s.x),",").concat(U(s.y)),c=R()(l).rotate(o,s.x,s.y).toString();return e.path(c).attr(ui(ui({},i.lineattr),{},{fill:"#000"},a&&i.arrowSnappingStyle))}(e,t,n,o,i,s);case Pt.EquilibriumFilledHalfBow:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=3.5,l=s.x+n,c=[];c.push("M".concat(U(s.x),",").concat(U(s.y-u))+"L".concat(U(l),",").concat(U(s.y-u))+"L".concat(U(l-9),",").concat(U(s.y-7))+"L".concat(U(l-9+2),",").concat(U(s.y-u),"Z")),c.push("M".concat(U(l),",").concat(U(s.y+u))+"L".concat(U(s.x),",").concat(U(s.y+u))+"L".concat(U(s.x+9),",").concat(U(s.y+7))+"L".concat(U(s.x+9-2),",").concat(s.y+u,"Z"));var d=R()(c.join("")).rotate(o,s.x,s.y).toString();return e.path(d).attr(ui(ui({},i.lineattr),{},{fill:"#000"},a&&i.arrowSnappingStyle))}(e,t,n,o,i,s);case Pt.EquilibriumFilledTriangle:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=3.5,l=s.x+n,c=[];c.push("M".concat(U(s.x),",").concat(U(s.y-u))+"L".concat(U(l),",").concat(U(s.y-u))+"L".concat(U(l-9),",").concat(U(s.y-7))+"L".concat(U(l-9),",").concat(U(s.y-u))+"L".concat(U(l-9),",").concat(U(s.y))+"L".concat(U(l),",").concat(U(s.y-u),"Z")),c.push("M".concat(U(s.x),",").concat(U(s.y+u))+"L".concat(U(l),",").concat(U(s.y+u))+"M".concat(U(s.x),",").concat(U(s.y+u))+"L".concat(U(s.x+9),",").concat(U(s.y+7))+"L".concat(U(s.x+9),",").concat(s.y+u,"Z")+"L".concat(U(s.x+9),",").concat(U(s.y))+"L".concat(U(s.x+9),",").concat(s.y+u,"Z"));var d=R()(c.join("")).rotate(o,s.x,s.y).toString();return e.path(d).attr(ui(ui({},i.lineattr),{},{fill:"#000"},a&&i.arrowSnappingStyle))}(e,t,n,o,i,s);case Pt.EquilibriumOpenAngle:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=3.5,l=s.x+n,c=[];c.push("M".concat(U(s.x),",").concat(U(s.y-u))+"L".concat(U(l),",").concat(U(s.y-u))+"L".concat(U(l-7),",").concat(U(s.y-5-u))),c.push("M".concat(U(s.x),",").concat(U(s.y+u))+"L".concat(U(l),",").concat(U(s.y+u))+"M".concat(U(s.x),",").concat(U(s.y+u))+"L".concat(U(s.x+9),",").concat(U(s.y+u+5)));var d=R()(c.join("")).rotate(o,s.x,s.y).toString();return e.path(d).attr(ui(ui({},i.lineattr),a&&{stroke:i.arrowSnappingStyle.stroke}))}(e,t,n,o,i,s);case Pt.UnbalancedEquilibriumFilledHalfBow:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=3.5,l=s.x+n,c=[];c.push("M".concat(U(s.x),",").concat(U(s.y-u))+"L".concat(U(l),",").concat(U(s.y-u))+"L".concat(U(l-9),",").concat(U(s.y-7))+"L".concat(U(l-9+2),",").concat(U(s.y-u),"Z")),c.push("M".concat(U(s.x+15),",").concat(U(s.y+u))+"L".concat(U(l-15),",").concat(U(s.y+u))+"M".concat(U(s.x+15),",").concat(U(s.y+u))+"L".concat(U(s.x+9+15),",").concat(U(s.y+7))+"L".concat(U(s.x+9-2+15),",").concat(s.y+u,"Z"));var d=R()(c.join("")).rotate(o,s.x,s.y).toString();return e.path(d).attr(ui(ui({},i.lineattr),{},{fill:"#000"},a&&i.arrowSnappingStyle))}(e,t,n,o,i,s);case Pt.UnbalancedEquilibriumOpenHalfAngle:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=3.5,l=s.x+n,c=[];c.push("M".concat(U(s.x),",").concat(U(s.y-u))+"L".concat(U(l),",").concat(U(s.y-u))+"L".concat(U(l-7),",").concat(U(s.y-5-u))),c.push("M".concat(U(s.x+15),",").concat(U(s.y+u))+"L".concat(U(l-15),",").concat(U(s.y+u))+"M".concat(U(s.x+15),",").concat(U(s.y+u))+"L".concat(U(s.x+9+15),",").concat(U(s.y+u+5)));var d=R()(c.join("")).rotate(o,s.x,s.y).toString();return e.path(d).attr(ui(ui({},i.lineattr),a&&{stroke:i.arrowSnappingStyle.stroke}))}(e,t,n,o,i,s);case Pt.UnbalancedEquilibriumLargeFilledHalfBow:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=3.5,l=s.x+n,c=[];c.push("M".concat(U(s.x),",").concat(U(s.y-u))+"L".concat(U(l),",").concat(U(s.y-u))+"L".concat(U(l-9),",").concat(U(s.y-10))+"L".concat(U(l-9+2),",").concat(U(s.y-u),"Z")),c.push("M".concat(U(s.x+15),",").concat(U(s.y+u))+"L".concat(U(l-15),",").concat(U(s.y+u))+"M".concat(U(s.x+15),",").concat(U(s.y+u))+"L".concat(U(s.x+9+15),",").concat(U(s.y+10))+"L".concat(U(s.x+9-2+15),",").concat(s.y+u,"Z"));var d=R()(c.join("")).rotate(o,s.x,s.y).toString();return e.path(d).attr(ui(ui({},i.lineattr),{},{fill:"#000"},a&&i.arrowSnappingStyle))}(e,t,n,o,i,s);case Pt.UnbalancedEquilibriumFilledHalfTriangle:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=3.5,l=s.x+n,c=[];c.push("M".concat(U(s.x),",").concat(U(s.y-u))+"L".concat(U(l),",").concat(U(s.y-u))+"L".concat(U(l-9),",").concat(U(s.y-7))+"L".concat(U(l-9),",").concat(U(s.y-u),"Z")),c.push("M".concat(U(s.x+15),",").concat(U(s.y+u))+"L".concat(U(l-15),",").concat(U(s.y+u))+"M".concat(U(s.x+15),",").concat(U(s.y+u))+"L".concat(U(s.x+9+15),",").concat(U(s.y+7))+"L".concat(U(s.x+9+15),",").concat(s.y+u,"Z"));var d=R()(c.join("")).rotate(o,s.x,s.y).toString();return e.path(d).attr(ui(ui({},i.lineattr),{},{fill:"#000"},a&&i.arrowSnappingStyle))}(e,t,n,o,i,s);case Pt.EllipticalArcFilledBow:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=t.height,l=u>=0?1:-1,c=10*l,d=5*l,h=4*l,f=s.x+n,m="M".concat(U(s.x),",").concat(U(s.y))+"A".concat(n/2,",").concat(u,",",0,",",0,",").concat(l>0?1:0,",").concat(U(f),",").concat(U(s.y))+"L".concat(U(f-d),",").concat(U(s.y-c))+"l".concat(U(d),",").concat(U(h))+"l".concat(U(d),",").concat(U(-h))+"l".concat(U(-d),",").concat(c),p=R()(m).rotate(o,s.x,s.y).toString();return e.path(p).attr(ui(ui({},i.lineattr),a&&{stroke:i.arrowSnappingStyle.stroke}))}(e,t,n,o,i,s);case Pt.EllipticalArcFilledTriangle:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=t.height,l=u>=0?1:-1,c=10*l,d=5*l,h=s.x+n,f="M".concat(U(s.x),",").concat(U(s.y))+"A".concat(n/2,",").concat(u,",",0,",",0,",").concat(l>0?1:0,",").concat(U(h),",").concat(U(s.y))+"L".concat(U(h-d),",").concat(U(s.y-c))+"l".concat(U(c),",").concat(U(0))+"l".concat(U(-d),",").concat(U(c)),m=R()(f).rotate(o,s.x,s.y).toString();return e.path(m).attr(ui(ui({},i.lineattr),a&&{stroke:i.arrowSnappingStyle.stroke}))}(e,t,n,o,i,s);case Pt.EllipticalArcOpenAngle:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=t.height,l=u>=0?1:-1,c=5*l,d=7*l,h=s.x+n,f="M".concat(U(s.x),",").concat(U(s.y))+"A".concat(n/2,",").concat(u,",",0,",",0,",").concat(l>0?1:0,",").concat(U(h),",").concat(U(s.y))+"L".concat(U(h-c),",").concat(U(s.y-d))+"M".concat(U(h),",").concat(U(s.y))+"L".concat(U(h+c),", ").concat(U(s.y-d)),m=R()(f).rotate(o,s.x,s.y).toString();return e.path(m).attr(ui(ui({},i.lineattr),a&&{stroke:i.arrowSnappingStyle.stroke}))}(e,t,n,o,i,s);case Pt.EllipticalArcOpenHalfAngle:return function(e,t,n,o,i,a){var s=(0,r.A)(t.pos,1)[0],u=t.height,l=u>=0?1:-1,c=5*l,d=7*l,h=s.x+n,f="M".concat(U(s.x),",").concat(U(s.y))+"A".concat(n/2,",").concat(u,",",0,",",0,",").concat(l>0?1:0,", ").concat(U(h),",").concat(U(s.y))+"L".concat(U(h+c),", ").concat(U(s.y-d)),m=R()(f).rotate(o,s.x,s.y).toString();return e.path(m).attr(ui(ui({},i.lineattr),a&&{stroke:i.arrowSnappingStyle.stroke}))}(e,t,n,o,i,s)}},plus:function(e,t,n){var o=n.microModeScale/5;return e.path("M{0},{4}L{0},{5}M{2},{1}L{3},{1}",U(t.x),U(t.y),U(t.x-o),U(t.x+o),U(t.y-o),U(t.y+o)).attr(n.lineattr)},aromaticBondPaths:function(e,t,n,o,r,i){return[i&&1&r?ci(e,n,i):li(e,n),i&&2&r?ci(t,o,i):li(t,o)]},bondSingle:function(e,t,n,o,r){var i=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"#000",a=t.p,s=n.p;return e.path(li(a,s)).attr(o.lineattr).attr({fill:i,stroke:i}).attr(r?o.bondSnappingStyle:{})},bondSingleUp:function(e,t,n,o,r,i){var a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"#000";return e.path("M{0},{1}L{2},{3}L{4},{5}Z",U(t.x),U(t.y),U(n.x),U(n.y),U(o.x),U(o.y)).attr(r.lineattr).attr({fill:a,stroke:a}).attr(i?r.bondSnappingStyle:{})},bondSingleStereoBold:function(e,t,n,o,r,i,a){var s=arguments.length>7&&void 0!==arguments[7]?arguments[7]:"#000";return e.path("M{0},{1}L{2},{3}L{4},{5}L{6},{7}Z",U(t.x),U(t.y),U(n.x),U(n.y),U(o.x),U(o.y),U(r.x),U(r.y)).attr(i.lineattr).attr({stroke:s,fill:s}).attr(a?i.bondSnappingStyle:{})},bondDoubleStereoBold:function(e,t,n,o,r,i){var a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"#000";return e.set([t,e.path("M{0},{1}L{2},{3}",U(n.x),U(n.y),U(o.x),U(o.y)).attr(r.lineattr).attr({stroke:a,fill:a}).attr(i?r.bondSnappingStyle:{})])},bondSingleDown:function(e,t,n,o,r,i,a){for(var s,u=arguments.length>7&&void 0!==arguments[7]?arguments[7]:"#000",l=t.p,c=t.norm,d=.7*i.stereoBond,h="",f=0;f<o;++f)h+=li((s=l.addScaled(n,r*f)).addScaled(c,d*(f+.5)/(o-.5)),s.addScaled(c,-d*(f+.5)/(o-.5)));return e.path(h).attr(i.lineattr).attr({fill:u,stroke:u}).attr(a?i.bondSnappingStyle:{})},bondSingleEither:function(e,t,n,o,r,i,a){for(var s=arguments.length>7&&void 0!==arguments[7]?arguments[7]:"#000",u=t.p,l=t.norm,c=.7*i.stereoBond,d="M"+U(u.x)+","+U(u.y),h=u,f=0;f<o;++f)d+="L"+U((h=u.addScaled(n,r*(f+.5)).addScaled(l,(1&f?-1:1)*c*(f+.5)/(o-.5))).x)+","+U(h.y);return e.path(d).attr(i.lineattr).attr({fill:s,stroke:s}).attr(a?i.bondSnappingStyle:{})},bondDouble:function(e,t,n,o,r,i,a,s){return e.path(i?"M{0},{1}L{6},{7}M{4},{5}L{2},{3}":"M{0},{1}L{2},{3}M{4},{5}L{6},{7}",U(t.x),U(t.y),U(o.x),U(o.y),U(n.x),U(n.y),U(r.x),U(r.y)).attr(a.lineattr).attr(s?a.bondSnappingStyle:{})},bondSingleOrDouble:function(e,t,n,o,r,i){for(var a,s=t.p,u=n.p,l=t.norm,c=r.bondSpace/2,d="",h=s,f=1;f<=o;++f)a=we.lc2(s,(o-f)/o,u,f/o),1&f?d+=li(h,a):(d+=li(h.addScaled(l,c),a.addScaled(l,c)),d+=li(h.addScaled(l,-c),a.addScaled(l,-c))),h=a;return e.path(d).attr(r.lineattr).attr(i?r.bondSnappingStyle:{})},bondTriple:function(e,t,n,o,r){var i=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"#000",a=t.p,s=n.p,u=t.norm,l=a.addScaled(u,o.bondSpace),c=s.addScaled(u,o.bondSpace),d=a.addScaled(u,-o.bondSpace),h=s.addScaled(u,-o.bondSpace);return e.path(li(a,s)+li(l,c)+li(d,h)).attr(o.lineattr).attr({fill:i,stroke:i}).attr(r?o.bondSnappingStyle:{})},bondAromatic:function(e,t,n,o,r){var i=e.path(t[0]).attr(o.lineattr).attr(r?o.bondSnappingStyle:{}),a=e.path(t[1]).attr(o.lineattr).attr(r?o.bondSnappingStyle:{});return null!=n&&(n>0?i:a).attr({"stroke-dasharray":"- "}),e.set([i,a])},bondAny:function(e,t,n,o,r){var i=t.p,a=n.p;return e.path(li(i,a)).attr(o.lineattr).attr({"stroke-dasharray":"- "}).attr(r?o.bondSnappingStyle:{})},bondHydrogen:function(e,t,n,o,r){var i=t.p,a=n.p;return e.path(li(i,a)).attr(o.lineattr).attr({"stroke-dasharray":".","stroke-linecap":"square"}).attr(r?o.bondSnappingStyle:{})},bondDative:function(e,t,n,o,r){var i=t.p,a=n.p;return e.path(li(i,a)).attr(o.lineattr).attr({"arrow-end":"block-midium-long"}).attr(r?o.bondSnappingStyle:{})},reactingCenter:function(e,t,n){for(var o="",r=0;r<t.length/2;++r)o+=li(t[2*r],t[2*r+1]);return e.path(o).attr(n.lineattr)},bondMark:function(e,t,n,o){var r=e.text(t.x,t.y,n).attr({font:o.font,"font-size":o.fontszsub,fill:"#000"}),i=ai.relBox(r.getBBox());return di(r,i),r},radicalCap:function(e,t,n){var o=.9*n.lineWidth,r=o,i=2*o;return e.path("M{0},{1}L{2},{3}L{4},{5}",U(t.x-r),U(t.y+i),U(t.x),U(t.y),U(t.x+r),U(t.y+i)).attr({stroke:"#000","stroke-width":.7*n.lineWidth,"stroke-linecap":"square","stroke-linejoin":"miter"})},radicalBullet:function(e,t,n){return e.circle(U(t.x),U(t.y),n.lineWidth).attr({stroke:null,fill:"#000"})},bracket:function(e,t,n,o,r,i,a){var s,u;r=r||.25,i=i||1,arguments.length>7&&void 0!==arguments[7]&&arguments[7]?(s=o.addScaled(n,.2*i),u=o.addScaled(n,-.8*i)):(s=o.addScaled(n,-.5*i),u=o.addScaled(n,.5*i));var l=s.addScaled(t,-r),c=u.addScaled(t,-r);return e.path("M{0},{1}L{2},{3}L{4},{5}L{6},{7}",U(l.x),U(l.y),U(s.x),U(s.y),U(u.x),U(u.y),U(c.x),U(c.y)).attr(a.sgroupBracketStyle)},selectionRectangle:function(e,t,n,o){return e.rect(U(Math.min(t.x,n.x)),U(Math.min(t.y,n.y)),U(Math.abs(n.x-t.x)),U(Math.abs(n.y-t.y))).attr(o.lassoStyle)},selectionPolygon:function(e,t,n){for(var o=t[t.length-1],r="M"+U(o.x)+","+U(o.y),i=0;i<t.length;++i)r+="L"+U(t[i].x)+","+U(t[i].y);return e.path(r).attr(n.lassoStyle)},selectionLine:function(e,t,n,o){return e.path(li(t,n)).attr(o.lassoStyle)},ellipse:function(e,t){var n=we.diff(t[1],t[0]),o=n.x/2,r=n.y/2;return e.ellipse(t[0].x+o,t[0].y+r,Math.abs(o),Math.abs(r))},rectangle:function(e,t){return e.rect(U(Math.min(t[0].x,t[1].x)),U(Math.min(t[0].y,t[1].y)),U(Math.abs(t[1].x-t[0].x)),U(Math.abs(t[1].y-t[0].y)))},rectangleArrowHighlightAndSelection:function(e,t,n,o){var i=(0,r.A)(t.pos,1)[0],a=t.height,s=i.x+n,u=a||8,l="M".concat(U(i.x-5),",").concat(U(i.y))+"L".concat(U(i.x-5),",").concat(U(i.y-u))+"L".concat(U(s+5),",").concat(U(i.y-u))+"L".concat(U(s+5),",").concat(U(i.y+(a?0:u)))+"L".concat(U(i.x-5),",").concat(U(i.y+(a?0:u)),"Z");return R()(l).rotate(o,i.x,i.y).toString()},polyline:function(e,t){for(var n=["M",t[0].x,t[0].y],o=1;o<t.length;o++)n.push("L",t[o].x,t[o].y);return e.path(n)},line:function(e,t){var n=["M",t[0].x,t[0].y];return n.push("L",t[1].x,t[1].y),e.path(n)},rgroupAttachmentPoint:function(e,t,n,o,r){var i=e.path("M{0},{1}L{2},{3}",U(t.x),U(t.y),U(n.x),U(n.y)),a=e.path(function(e,t,n){var o=n/39.8,r=180*Math.atan2(t.y,t.x)/Math.PI-90;return R()("M13 1.5l-1.5 3.7c-0.3 0.8-1.5 0.8-1.9 0l-1.7-4.4c-0.3-0.8-1.5-0.8-1.9 0l-1.7 4.4c-0.3 0.8-1.5 0.8-1.8 0l-1.8-4.4c-0.3-0.8-1.5-0.8-1.8 0l-1.7 4.4c-0.3 0.8-1.5 0.8-1.9 0l-1.7-4.4c-0.3-0.8-1.5-0.8-1.9 0l-1.6 4.2c-0.3 0.9-1.6 0.8-1.9 0l-1.2-3.5").rotate(r).scale(o).translate(e.x,e.y).toString()}(n,o,r.microModeScale));return e.set([a,i]).attr(r.lineattr).attr({"stroke-width":r.lineWidth})},rgroupAttachmentPointLabel:function(e,t,n,o,r){return e.text(t.x,t.y,n).attr({font:o.font,"font-size":.9*o.fontsz,fill:r})}};function pi(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function vi(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?pi(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):pi(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function gi(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,yi()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function yi(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(yi=function(){return!!e})()}!function(e){e.Off="off",e.Hetero="Hetero",e.Terminal="Terminal",e.TerminalAndHetero="Terminal and Hetero",e.On="all"}(hi||(hi={})),function(e){e.Off="Off",e.Hetero="Hetero",e.Terminal="Terminal",e.TerminalAndHetero="Terminal and Hetero",e.On="On"}(fi||(fi={}));var bi=function(e){function t(e){var n;return(0,i.A)(this,t),(n=gi(this,t,["atom"])).a=e,n.showLabel=!1,n.hydrogenOnTheLeft=!1,n.color="#000000",n.component=-1,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"getVBoxObj",value:function(e){return this.visel.boundingBox?ri.prototype.getVBoxObj.call(this,e):new nt(this.a.pp,this.a.pp)}},{key:"drawHover",value:function(e){var t=this.makeHoverPlate(e);return e.ctab.addReObjectPath(ei.atom,this.visel,t),t}},{key:"getLabeledSelectionContour",value:function(e){var t=e.paper,n=e.ctab,o=e.options,r=o.fontsz,i=o.radiusScaleFactor,a=r*i,s=r*i*2,u=this.getVBoxObj(n.render),l=Ze.modelToCanvas(u.p0,n.render.options),c=Ze.modelToCanvas(u.p1,n.render.options).x-l.x,d=1.23*r;return t.rect(l.x-a,l.y-a,c+2*a,d+2*a,s)}},{key:"getUnlabeledSelectionContour",value:function(e){var t=e.paper,n=e.options,o=n.atomSelectionPlateRadius,r=Ze.modelToCanvas(this.a.pp,n);return t.circle(r.x,r.y,o)}},{key:"getSelectionContour",value:function(e){return this.a.pseudo&&this.a.pseudo.length>1&&!Si(this)||this.showLabel&&0!==this.a.implicitH?this.getLabeledSelectionContour(e):this.getUnlabeledSelectionContour(e)}},{key:"makeHoverPlate",value:function(e){var t=this.a,n=e.options,o=e.ctab.sgroups,r=e.ctab.molecule.functionalGroups;return gt.isAtomInContractedFunctionalGroup(t,o,r,!0)?null:this.getSelectionContour(e).attr(n.hoverStyle)}},{key:"makeSelectionPlate",value:function(e){var t=this.a,n=e.render,o=n.options,r=n.ctab.sgroups,i=n.ctab.molecule.functionalGroups;return gt.isAtomInContractedFunctionalGroup(t,r,i,!0)?null:this.getSelectionContour(n).attr(o.selectionStyle)}},{key:"getShiftedSegmentPosition",value:function(e,t,n){for(var o=Ze.modelToCanvas(n||this.a.pp,e),r=0,i=this.visel.exts,a=0;a<i.length;++a){var s=i[a].translate(o);r=Math.max(r,ai.shiftRayBox(o,t,s))}return r>0?o.addScaled(t,r+3*e.lineWidth):o}},{key:"hasAttachmentPoint",value:function(){return Boolean(this.a.attachmentPoints)}},{key:"show",value:function(e,t,n){var o,r=e.molecule.atoms.get(t),i=e.molecule.sgroups,a=e.molecule.functionalGroups,s=e.render,u=Ze.modelToCanvas(this.a.pp,s.options);if(gt.isAtomInContractedFunctionalGroup(r,i,a,!1)){var l=e.molecule.getGroupFromAtomId(t);if((null==l?void 0:l.getContractedPosition(e.molecule).atomId)===t){var c=Ze.modelToCanvas(l instanceof Ut?l.pp:this.a.pp,s.options),d=s.paper.text(c.x,c.y,l.data.name).attr({"font-weight":700,"font-size":14});e.addReObjectPath(ei.data,this.visel,d,c,!0)}}else{var h,f,m,p,v,g;this.hydrogenOnTheLeft=function(e,t){if(0===t.a.neighbors.length){if("D"===t.a.label||"T"===t.a.label)return!1;var n=_.get(t.a.label);return!n||Boolean(n.leftH)}if(1===t.a.neighbors.length){var o=t.a.neighbors[0];return e.halfBonds.get(o).dir.x>0}return!1}(e.molecule,this),this.showLabel=function(e,t,n){var o=Boolean(n.a.attachmentPoints),r="c"===n.a.label.toLowerCase(),i=t.showHydrogenLabels!==hi.Off&&t.showHydrogenLabels!==hi.Hetero,a=0===n.a.neighbors.length||n.a.neighbors.length<2&&i;if(o&&r)return!1;if(a||t.carbonExplicitly||t.showHydrogenLabels===hi.On||n.a.alias||null!==n.a.isotope||0!==n.a.radical||null!==n.a.charge||n.a.explicitValence>=0||null!==n.a.atomList||null!==n.a.rglabel||n.a.badConn&&t.showValenceWarnings||"c"!==n.a.label.toLowerCase())return!0;if(2===n.a.neighbors.length){var s=n.a.neighbors[0],u=n.a.neighbors[1],l=e.molecule.halfBonds.get(s),c=e.molecule.halfBonds.get(u),d=e.bonds.get(l.bid),h=e.bonds.get(c.bid);if(d.b.type===h.b.type&&d.b.stereo===We.PATTERN.STEREO.NONE&&h.b.stereo===We.PATTERN.STEREO.NONE&&Math.abs(we.cross(l.dir,c.dir))<.2)return!0}return!1}(e,s.options,this),this.color="black";var y=null;if(this.showLabel){var b=function(e,t,n,o){var r,i,a={text:Ei(e.a)},s=null;if(a.text||(a.text="R#"),a.text===e.a.label){var u=_.get(a.text);o.atomColoring&&u&&(e.color=N[a.text]||"#000")}var l,c=pn.includes(a.text),d=o.currentlySelectedMonomerAttachmentPoint===a.text,h=null===(r=o.connectedMonomerAttachmentPoints)||void 0===r?void 0:r.includes(a.text);(c&&o.labelInMonomerConnectionsModal&&(e.color=d?"#FFF":h?"#B4B9D6":"#585858"),(null===(i=a.text)||void 0===i?void 0:i.length)>8)&&(s=a.text,a.text="".concat(null===(l=a.text)||void 0===l?void 0:l.substring(0,8),"..."));var f=o.previewOpacity;if(a.path=t.text(n.x,n.y,a.text).attr({font:o.font,"font-size":o.fontsz,fill:e.color,"font-style":e.a.pseudo?"italic":"","fill-opacity":e.a.isPreview?f:1}),c&&o.labelInMonomerConnectionsModal){var m=d?"#167782":h?"#E1E5EA":"#FFF",p=2*o.fontsz;a.background=t.rect(n.x-p/2,n.y-p/2,p,p,10).attr({fill:m}).attr({stroke:h?"#B4B9D6":"#7C7C7F"})}s&&wi(a.path.node,s),a.rbb=ai.relBox(a.path.getBBox()),mi.recenterText(a.path,a.rbb);var v=a.rbb.width/2*(o.zoom>1?1:o.zoom),g=-a.rbb.width/2*(o.zoom>1?1:o.zoom);if(null!==e.a.atomList){var y=(e.hydrogenOnTheLeft?-1:1)*(a.rbb.width-a.rbb.height)/2;Oi(a.path,a.rbb,y,0),v+=y,g+=y}return e.label=a,{label:a,rightMargin:v,leftMargin:g}}(this,s.paper,u,n);h=.5*n.lineWidth,g=b.label,f=b.rightMargin,m=b.leftMargin,p=Math.floor(this.a.implicitH),v="H"===g.text,g.background&&e.addReObjectPath(ei.data,this.visel,g.background,u,!0),e.addReObjectPath(ei.data,this.visel,g.path,u,!0)}if(n.showAtomIds){(y={}).text=t.toString();var A=this.hydrogenOnTheLeft?we.lc(u,1,new we({x:-2,y:0,z:0}),6):we.lc(u,1,new we({x:2,y:0,z:0}),6);this.showLabel&&(A=we.lc(A,1,new we({x:1,y:-3,z:0}),6)),y.path=s.paper.text(A.x,A.y,y.text).attr({font:n.font,"font-size":n.fontszsub,fill:"#070"}),y.rbb=ai.relBox(y.path.getBBox()),mi.recenterText(y.path,y.rbb),e.addReObjectPath(ei.indices,this.visel,y.path,u)}if(this.showLabel){var w=null;if(v&&p>0&&(w=function(e,t,n,o){var r=Ze.modelToCanvas(e.a.pp,t.options),i=t.options,a=.5*i.lineWidth,s={};return s.text=(n+1).toString(),s.path=t.paper.text(r.x,r.y,s.text).attr({font:i.font,"font-size":i.fontszsub,fill:e.color}),s.rbb=ai.relBox(s.path.getBBox()),mi.recenterText(s.path,s.rbb),Oi(s.path,s.rbb,o+.5*s.rbb.width+a,.2*e.label.rbb.height),s}(this,s,p,f),f+=w.rbb.width+h,e.addReObjectPath(ei.data,this.visel,w.path,u,!0)),0!==this.a.radical){var E=function(e,t){var n,o=Ze.modelToCanvas(e.a.pp,t.options),r=t.options,i=t.paper,a={};switch(e.a.radical){case 1:a.path=i.set(),n=1.6*r.lineWidth,a.path.push(mi.radicalBullet(i,o.add(new we(-n,0)),r),mi.radicalBullet(i,o.add(new we(n,0)),r)),a.path.attr("fill",e.color);break;case 2:a.path=i.set(),a.path.push(mi.radicalBullet(i,o,r)),a.path.attr("fill",e.color);break;case 3:a.path=i.set(),n=1.6*r.lineWidth,a.path.push(mi.radicalCap(i,o.add(new we(-n,0)),r),mi.radicalCap(i,o.add(new we(n,0)),r)),a.path.attr("stroke",e.color)}a.rbb=ai.relBox(a.path.getBBox());var s=-.5*(e.label.rbb.height+a.rbb.height);return 3===e.a.radical&&(s-=r.lineWidth/2),Oi(a.path,a.rbb,0,s),a}(this,s);e.addReObjectPath(ei.data,this.visel,E.path,u,!0)}if(null!==this.a.isotope){var P=function(e,t,n){var o=Ze.modelToCanvas(e.a.pp,t.options),r=t.options,i=.5*r.lineWidth,a={};return a.text=null===e.a.isotope?"":e.a.isotope.toString(),a.path=t.paper.text(o.x,o.y,a.text).attr({font:r.font,"font-size":r.fontszsub,fill:e.color}),a.rbb=ai.relBox(a.path.getBBox()),mi.recenterText(a.path,a.rbb),Oi(a.path,a.rbb,n-.5*a.rbb.width-i,-.3*e.label.rbb.height),a}(this,s,m);m-=P.rbb.width+h,e.addReObjectPath(ei.data,this.visel,P.path,u,!0)}if(!v&&!this.a.alias&&p>0&&function(e,t){var n,o;return t===hi.On||t===hi.Terminal&&e.a.neighbors.length<2||t===hi.Hetero&&"c"!==(null===(n=e.label)||void 0===n?void 0:n.text.toLowerCase())||t===hi.TerminalAndHetero&&(e.a.neighbors.length<2||"c"!==(null===(o=e.label)||void 0===o?void 0:o.text.toLowerCase()))}(this,n.showHydrogenLabels)){var x=function(e,t,n,o){var r=o.hydroIndex,i=e.hydrogenOnTheLeft,a=Ze.modelToCanvas(e.a.pp,t.options),s=t.options,u=.5*s.lineWidth,l=o.hydrogen;return l.text="H",l.path=t.paper.text(a.x,a.y,l.text).attr({font:s.font,"font-size":s.fontsz,fill:e.color}),l.rbb=ai.relBox(l.path.getBBox()),mi.recenterText(l.path,l.rbb),i||(Oi(l.path,l.rbb,o.rightMargin+.5*l.rbb.width+u,0),o.rightMargin+=l.rbb.width+u),n>1&&((r={}).text=n.toString(),r.path=t.paper.text(a.x,a.y,r.text).attr({font:s.font,"font-size":s.fontszsub,fill:e.color}),r.rbb=ai.relBox(r.path.getBBox()),mi.recenterText(r.path,r.rbb),i||(Oi(r.path,r.rbb,o.rightMargin+.5*r.rbb.width*(s.zoom>1?1:s.zoom)+u,.2*e.label.rbb.height),o.rightMargin+=r.rbb.width+u)),i&&(null!=r&&(Oi(r.path,r.rbb,o.leftMargin-.5*r.rbb.width-u,.2*e.label.rbb.height),o.leftMargin-=r.rbb.width+u),Oi(l.path,l.rbb,o.leftMargin-.5*l.rbb.width*(n>1&&s.zoom<1?s.zoom:1)-u,0),o.leftMargin-=l.rbb.width+u),Object.assign(o,{hydrogen:l,hydroIndex:r})}(this,s,p,{hydrogen:{},hydroIndex:w,rightMargin:f,leftMargin:m}),S=x.hydrogen;w=x.hydroIndex,f=x.rightMargin,m=x.leftMargin,e.addReObjectPath(ei.data,this.visel,S.path,u,!0),null!=w&&e.addReObjectPath(ei.data,this.visel,w.path,u,!0)}if(null!==this.a.charge&&n.showCharge){var O=function(e,t,n){var o=Ze.modelToCanvas(e.a.pp,t.options),r=t.options,i=.5*r.lineWidth,a={text:""};if(null!==e.a.charge){var s=Math.abs(e.a.charge);1!==s&&(a.text=s.toString()),e.a.charge<0?a.text+="–":a.text+="+"}else a.text="";return a.path=t.paper.text(o.x,o.y,a.text).attr({font:r.font,"font-size":r.fontszsub,fill:e.color}),a.rbb=ai.relBox(a.path.getBBox()),mi.recenterText(a.path,a.rbb),Oi(a.path,a.rbb,n+.5*a.rbb.width+i,-.3*e.label.rbb.height),a}(this,s,f);f+=O.rbb.width+h,e.addReObjectPath(ei.data,this.visel,O.path,u,!0)}if(this.a.explicitValence>=0&&n.showValence){var k=function(e,t,n){var o=Ze.modelToCanvas(e.a.pp,t.options),r=t.options,i=.5*r.lineWidth,a={};if(a.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"}[e.a.explicitValence],!a.text)throw new Error("invalid valence "+e.a.explicitValence.toString());return a.text="("+a.text+")",a.path=t.paper.text(o.x,o.y,a.text).attr({font:r.font,"font-size":r.fontszsub,fill:e.color}),a.rbb=ai.relBox(a.path.getBBox()),mi.recenterText(a.path,a.rbb),Oi(a.path,a.rbb,n+.5*a.rbb.width+i,-.3*e.label.rbb.height),a}(this,s,f);f+=k.rbb.width+h,e.addReObjectPath(ei.data,this.visel,k.path,u,!0)}if(this.a.badConn&&n.showValenceWarnings){var M=function(e,t,n,o){var r=Ze.modelToCanvas(e.a.pp,t.options),i=.5*t.options.lineWidth,a={},s=r.y+e.label.rbb.height/2+i;return a.path=t.paper.path("M{0},{1}L{2},{3}",U(r.x+n),U(s),U(r.x+o),U(s)).attr(t.options.lineattr).attr({stroke:"#F00"}),a.rbb=ai.relBox(a.path.getBBox()),a}(this,s,m,f);e.addReObjectPath(ei.warnings,this.visel,M.path,u,!0)}y&&Oi(y.path,y.rbb,-.5*g.rbb.width-.5*y.rbb.width-h,.3*g.rbb.height)}this.setHover(this.hover,s);var R,T=this.a.stereoLabel,B=function(e){var t="";if(e.a.aam>0&&(t+=e.a.aam),e.a.invRet>0)if(t.length>0&&(t+=","),1===e.a.invRet)t+="Inv";else{if(2!==e.a.invRet)throw new Error("Invalid value for the invert/retain flag");t+="Ret"}if(e.a.exactChangeFlag>0){if(t.length>0&&(t+=","),1!==e.a.exactChangeFlag)throw new Error("Invalid value for the exact change flag");t+="ext"}return t}(this),C=function(e){return["ringMembership","ringSize","connectivity","chirality","aromaticity","customQuery"].some((function(t){var n;return null===(n=e.queryProperties)||void 0===n?void 0:n[t]}))}(this.a)?function(e){return e.queryProperties.customQuery||xi(vi(vi({},e),e.queryProperties),!0)}(this.a):Si(this),I=C;I.length>8&&(R=I,I="".concat(I.substring(0,8),"..."));var D=Number(null===(o=e.atoms.get(t))||void 0===o?void 0:o.a.fragment),L=e.molecule.frags.get(D),F=function(e,t,n,o){if(!e)return!1;var r=e.match(/\D+/g)[0];if(n&&r===ke.Abs)return!1;if(n&&r!==ke.Abs)return!0;switch(t){case ni.Off:return!1;case ni.On:return!0;case ni.Classic:return!(o!==Ue.Mixed&&r!==ke.Or);case ni.IUPAC:return!(o!==Ue.Mixed||r===ke.Abs);default:return!0}}(T,n.stereoLabelStyle,n.ignoreChiralFlag,null==L?void 0:L.enhancedStereoFlag),H="";if(F&&(H="".concat(T,"\n")),I.length>0&&(H+="".concat(I,"\n")),B.length>0&&(H+=".".concat(B,".")),H.length>0){var j=_.get(this.a.label),G=s.paper.text(u.x,u.y,H).attr({font:n.font,"font-size":n.fontszsub,fill:n.atomColoring&&j?N[this.a.label]:"#000"});if(T){var z=function(e,t){return t&&e.colorStereogenicCenters!==ti.Off&&e.colorStereogenicCenters!==ti.BondsOnly?Ai(e,t):"#000"}(s.options,T);G.node.childNodes[0].setAttribute("fill",z);var V=function(e,t){var n=t.match(/\D+/g)[0],o=+t.replace(n,"");return e.autoFadeOfStereoLabels&&n!==ke.Abs&&e.colorStereogenicCenters!==ti.Off&&e.colorStereogenicCenters!==ti.BondsOnly?Math.max(1-(o-1)/10,.3):1}(s.options,T);G.node.childNodes[0].setAttribute("fill-opacity",V)}var W=ai.relBox(G.getBBox());mi.recenterText(G,W);for(var q=this.visel,Y=3,$=this.bisectLargestSector(e.molecule),X=0;X<q.exts.length;++X)Y=Math.max(Y,ai.shiftRayBox(u,$,q.exts[X].translate(u)));Y+=ai.shiftRayBox(u,$.negated(),nt.fromRelBox(W)),Oi(G,W,($=$.scaled(8+Y)).x,$.y),e.addReObjectPath(ei.data,this.visel,G,u,!0),R&&wi(G.node,R)}var K=e.molecule.highlights,Z=!1,Q="";if(K.forEach((function(e){var n,o=null===(n=e.atoms)||void 0===n?void 0:n.includes(t);Z=Z||o,o&&(Q=e.color)})),Z){var J={fill:Q,stroke:"none"},ee=Ze.modelToCanvas(this.a.pp,e.render.options),te=s.paper.circle(ee.x,ee.y,.8*n.atomSelectionPlateRadius).attr(J);e.addReObjectPath(ei.hovering,this.visel,te)}r.cip&&(this.cip=ai.drawCIPLabel({atomOrBond:r,position:r.pp,restruct:s.ctab,visel:this.visel}))}}},{key:"getLargestSectorFromNeighbors",value:function(e){var t=[];this.a.neighbors.forEach((function(n){var o=e.halfBonds.get(n);o&&t.push(o.ang)})),t=t.sort((function(e,t){return e-t}));for(var n=[],o=0;o<t.length-1;++o)n.push(t[(o+1)%t.length]-t[o]);n.push(t[0]-t[t.length-1]+2*Math.PI);for(var r=0,i=-Math.PI/2,a=0;a<t.length;++a)n[a]>r&&(r=n[a],i=t[a]);return{neighborAngle:i,largestAngle:r}}},{key:"bisectLargestSector",value:function(e){var t,n=this.getLargestSectorFromNeighbors(e),o=n.largestAngle;return t=n.neighborAngle+o/2,new we(Math.cos(t),Math.sin(t))}}],[{key:"isSelectable",value:function(){return!0}}]),t}(ri);function Ai(e,t){switch(t.match(/\D+/g)[0]){case ke.And:return e.colorOfAndCenters;case ke.Or:return e.colorOfOrCenters;case ke.Abs:return e.colorOfAbsoluteCenters;default:return"#000"}}function wi(e,t){var n="<p>".concat(t.split(/(?<=[;,])/).join(" "),"</p>");e.childNodes[0].setAttribute("data-tooltip",n)}function Ei(e){if(null!==e.atomList)return e.atomList.label();if(e.pseudo)return e.pseudo;if(e.alias)return e.alias;if("R#"===e.label&&null!==e.rglabel){for(var t="",n=0;n<32;n++)e.rglabel&1<<n&&(t+="R"+(n+1).toString());return t}return e.label}function Pi(e){return e.atomList?"list":e.pseudo===e.label?"pseudo":"single"}function xi(e,t){var n="",o=["charge","explicitValence","isotope"],r={isotope:function(e){return e},aromaticity:function(e){return"aromatic"===e?"a":"A"},charge:function(e){if(""===e)return e;var t=/^([+-]?)([0-9]{1,3}|1000)([+-]?)$/.exec(e),n=t?parseInt(t[1]+t[3]+t[2]).toString():e;return"-"!==n[0]?"+".concat(n):n},unsaturatedAtom:function(e){return 1===Number(e)?"u":""},explicitValence:function(e){return-1!==Number(e)?"v".concat(e):""},ringBondCount:function(e){return function(e){return e>0?"x"+e.toString():-1===e||-2===e?"x0":""}(Number(e))},substitutionCount:function(e){return function(e){return e>0?"D"+e.toString():-1===e||-2===e?"D0":""}(Number(e))},hCount:function(e){return Number(e)>0?"H"+(Number(e)-1).toString():""},implicitHCount:function(e){return"h".concat(e)},ringMembership:function(e){return"R".concat(e)},ringSize:function(e){return"r".concat(e)},connectivity:function(e){return"X".concat(e)},chirality:function(e){return"clockwise"===e?"@@":"@"}};for(var i in r)if(!t||!o.includes(i)){var a=e[i];if(i in e&&null!==a){var s=r[i](a,e);s&&n.length>0&&(n+=";"),n+=s}}return n}function Si(e){var t="",n=function(){t.length>0&&(t+=";")},o=e.a,r=o.ringBondCount,i=o.substitutionCount,a=o.unsaturatedAtom,s=o.hCount;if(0!==r&&(t+=function(e){var t;if(e>0)t="rb"+e.toString();else if(-1===e)t="rb0";else{if(-2!==e)throw new Error("Ring bond count invalid");t="rb*"}return t}(r)),0!==i&&(n(),t+=function(e){var t;if(e>0)t="s"+e.toString();else if(-1===e)t="s0";else{if(-2!==e)throw new Error("Substitution count invalid");t="s*"}return t}(i)),a>0){if(n(),1!==a)throw new Error("Unsaturated atom invalid value");t+="u"}return s>0&&(n(),t+="H"+(s-1).toString()),t}function Oi(e,t,n,o){e.translateAbs(n,o),t.x+=n,t.y+=o}function ki(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Mi(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Ri()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Ri(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Ri=function(){return!!e})()}var Ti=function(e){function t(e){var n;return(0,i.A)(this,t),n=Mi(this,t,["bond"]),(0,d.A)((0,l.A)(n),"neihbid1",-1),(0,d.A)((0,l.A)(n),"neihbid2",-1),n.b=e,n.doubleBondShift=0,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"drawHover",value:function(e){var t=this.makeHoverPlate(e);return e.ctab.addReObjectPath(ei.hovering,this.visel,t),t}},{key:"getSelectionPoints",value:function(e){var t=this.b,n=e.ctab,o=e.options,r=o.bondThickness,i=o.doubleBondWidth,a=o.stereoBondWidth,s=i+r,u=n.molecule.halfBonds.get(t.hb1).p,l=n.molecule.halfBonds.get(t.hb2).p,c=t.stereo!==We.PATTERN.STEREO.NONE&&t.stereo!==We.PATTERN.STEREO.CIS_TRANS,d=c?0:-2,h=we.getLinePoint(l,u,d),f=we.getLinePoint(u,l,d),m=c?.5*a:s+.5,p=c?a+1*s/a:s+.5,v=we.getLinePoint(h,f,p),g=we.getLinePoint(f,h,m),y=h.add(new we(p,0)),b=f.add(new we(m,0)),A=v.add(new we(p,0)),w=g.add(new we(m,0)),E=t.angle,P=y.rotateAroundOrigin(E+90,new we(h.x,h.y)),x=y.rotateAroundOrigin(E-90,new we(h.x,h.y)),S=A.rotateAroundOrigin(E+90,v),O=A.rotateAroundOrigin(E-90,v),k=b.rotateAroundOrigin(E+90,f),M=b.rotateAroundOrigin(E-90,f);return[S,P,k,w.rotateAroundOrigin(E+90,g),w.rotateAroundOrigin(E-90,g),M,O,x]}},{key:"getSelectionContour",value:function(e){var t=e.paper,n=this.getSelectionPoints(e),o=(0,r.A)(n,8),i=o[0],a=o[1],s=o[2],u=o[3],l=o[4],c=o[5],d=o[6],h=o[7],f="\n M ".concat(a.x," ").concat(a.y,"\n L ").concat(s.x," ").concat(s.y,"\n C ").concat(u.x," ").concat(u.y,", ").concat(l.x," ").concat(l.y,", ").concat(c.x," ").concat(c.y,"\n L ").concat(h.x," ").concat(h.y,"\n C ").concat(d.x," ").concat(d.y,", ").concat(i.x," ").concat(i.y,", ").concat(a.x," ").concat(a.y,"\n ");return t.path(f)}},{key:"makeHoverPlate",value:function(e){var n=e.ctab,o=e.options;t.bondRecalc(this,n,o);var r=this.b,i=n.sgroups,a=n.molecule.functionalGroups;return gt.isBondInContractedFunctionalGroup(r,i,a)?null:this.getSelectionContour(e).attr(function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ki(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ki(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},o.hoverStyle))}},{key:"makeSelectionPlate",value:function(e,n,o){t.bondRecalc(this,e,o);var r=this.b,i=e.render.ctab.sgroups,a=e.render.ctab.molecule.functionalGroups;return gt.isBondInContractedFunctionalGroup(r,i,a)?null:this.getSelectionContour(e.render).attr(o.selectionStyle)}},{key:"show",value:function(e,n,o){var r=e.render,i=e.molecule,a=e.molecule.bonds.get(n),s=e.molecule.sgroups,u=e.molecule.functionalGroups;if(!a||!gt.isBondInContractedFunctionalGroup(a,s,u)){var l=r.paper,c=void 0!==this.b.hb1?i.halfBonds.get(this.b.hb1):null,d=void 0!==this.b.hb2?i.halfBonds.get(this.b.hb2):null;if(function(e,t,n){var o=[t.b.begin,t.b.end].map((function(t){var o=n.molecule.atoms.get(t),r=Bi(o,e,!1,n);return r<0?-1:o.neighbors[r]}));t.boldStereo=o[0]>=0&&o[1]>=0}(n,this,e),t.bondRecalc(this,e,o),function(e,t){var n=e.b.hb1,o=e.b.hb2;if(!n&&0!==n||!o&&0!==o)e.doubleBondShift=Hi(t,e);else{var r=t.halfBonds.get(n).loop,i=t.halfBonds.get(o).loop;if(r>=0&&i>=0){var a=t.loops.get(r).dblBonds,s=t.loops.get(i).dblBonds,u=t.loops.get(r).hbs.length,l=t.loops.get(i).hbs.length;e.doubleBondShift=function(e,t,n,o){return 6===e&&6!==t&&(n>1||1===o)?-1:6===t&&6!==e&&(o>1||1===n)?1:t*n>e*o?-1:t*n<e*o?1:t>e?-1:1}(u,l,a,s)}else e.doubleBondShift=r>=0?-1:i>=0?1:Hi(t,e)}}(this,i),c&&d){var h=e.isSnappingBond(n);this.path=function(e,t,n,o,r){var i,a,s,u=null,l=e.render,c=e.molecule,d=!(null!==(i=e.atoms.get(n.begin))&&void 0!==i&&i.showLabel),h=!(null!==(a=e.atoms.get(o.begin))&&void 0!==a&&a.showLabel);switch(t.b.type){case We.PATTERN.TYPE.SINGLE:switch(t.b.stereo){case We.PATTERN.STEREO.UP:Ci(n.bid,t,e),u=t.boldStereo&&t.neihbid1>=0&&t.neihbid2>=0?Ni(l,n,o,t,c,r):function(e,t,n,o,r,i){var a=t.p,s=n.p,u=t.norm,l=e.options,c=.7*l.stereoBond,d=s.addScaled(u,c),h=s.addScaled(u,-c);if(o.neihbid2>=0){var f=Li(n,o.neihbid2,l.stereoBond,r);d=f[0],h=f[1]}return mi.bondSingleUp(e.paper,a,d,h,l,i,Ii(l,o,r))}(l,n,o,t,c,r);break;case We.PATTERN.STEREO.DOWN:u=function(e,t,n,o,r,i){var a=t.p,s=n.p,u=e.options,l=s.sub(a),c=l.length()+.2;l=l.normalized();var d=1.2*u.lineWidth,h=Math.max(Math.floor((c-u.lineWidth)/(u.lineWidth+d)),0)+2,f=c/(h-1);return mi.bondSingleDown(e.paper,t,l,h,f,u,i,Ii(u,o,r))}(l,n,o,t,c,r);break;case We.PATTERN.STEREO.EITHER:u=function(e,t,n,o,r,i){var a=t.p,s=n.p,u=e.options,l=s.sub(a),c=l.length();l=l.normalized();var d=.6*u.lineWidth,h=Math.max(Math.floor((c-u.lineWidth)/(u.lineWidth+d)),0)+2,f=c/(h-.5);return mi.bondSingleEither(e.paper,t,l,h,f,u,i,Ii(u,o,r))}(l,n,o,t,c,r);break;default:u=mi.bondSingle(l.paper,n,o,l.options,r,Ii(l.options,t,c))}break;case We.PATTERN.TYPE.DOUBLE:Ci(n.bid,t,e),u=t.b.stereo===We.PATTERN.STEREO.NONE&&t.boldStereo&&t.neihbid1>=0&&t.neihbid2>=0?function(e,t,n,o,r,i,a,s){var u=t.p,l=n.p,c=t.norm,d=o.doubleBondShift,h=1.5*e.options.stereoBond,f=u.addScaled(c,h*d),m=l.addScaled(c,h*d);d>0?(i&&(f=f.addScaled(t.dir,h*Di(t.rightCos,t.rightSin))),a&&(m=m.addScaled(t.dir,-h*Di(n.leftCos,n.leftSin)))):d<0&&(i&&(f=f.addScaled(t.dir,h*Di(t.leftCos,t.leftSin))),a&&(m=m.addScaled(t.dir,-h*Di(n.rightCos,n.rightSin))));var p=Ni(e,t,n,o,r,s);return mi.bondDoubleStereoBold(e.paper,p,f,m,e.options,s,Ii(e.options,o,r))}(l,n,o,t,c,d,h,r):function(e,t,n,o,r,i,a){var s=o.b.stereo===We.PATTERN.STEREO.CIS_TRANS,u=t.p,l=n.p,c=t.norm,d=s?0:o.doubleBondShift,h=e.options,f=h.bondSpace/2,m=f+d*f,p=d*f-f,v=u.addScaled(c,m),g=l.addScaled(c,m),y=u.addScaled(c,p),b=l.addScaled(c,p);return d>0?(r&&(v=v.addScaled(t.dir,h.bondSpace*Di(t.rightCos,t.rightSin))),i&&(g=g.addScaled(t.dir,-h.bondSpace*Di(n.leftCos,n.leftSin)))):d<0&&(r&&(y=y.addScaled(t.dir,h.bondSpace*Di(t.leftCos,t.leftSin))),i&&(b=b.addScaled(t.dir,-h.bondSpace*Di(n.rightCos,n.rightSin)))),mi.bondDouble(e.paper,v,y,g,b,s,h,a)}(l,n,o,t,d,h,r);break;case We.PATTERN.TYPE.TRIPLE:u=mi.bondTriple(l.paper,n,o,l.options,r);break;case We.PATTERN.TYPE.AROMATIC:var f,m;u=n.loop>=0&&(null===(f=c.loops.get(n.loop))||void 0===f?void 0:f.aromatic)||o.loop>=0&&(null===(m=c.loops.get(o.loop))||void 0===m?void 0:m.aromatic)?mi.bondSingle(l.paper,n,o,l.options,r):_i(l,n,o,t,d,h,r);break;case We.PATTERN.TYPE.SINGLE_OR_DOUBLE:u=function(e,t,n,o){var r=t.p,i=n.p,a=e.options,s=we.dist(r,i)/Number((a.bondSpace+a.lineWidth).toFixed());return 1&s||(s+=1),mi.bondSingleOrDouble(e.paper,t,n,s,a,o)}(l,(s=ai.updateHalfBondCoordinates(n,o,1))[0],s[1],r);break;case We.PATTERN.TYPE.SINGLE_OR_AROMATIC:u=_i(l,n,o,t,d,h,r);break;case We.PATTERN.TYPE.DOUBLE_OR_AROMATIC:u=_i(l,(s=ai.updateHalfBondCoordinates(n,o,-1))[0],s[1],t,d,h,r);break;case We.PATTERN.TYPE.ANY:s=ai.updateHalfBondCoordinates(n,o,-1),u=mi.bondAny(l.paper,s[0],s[1],l.options,r);break;case We.PATTERN.TYPE.HYDROGEN:s=ai.updateHalfBondCoordinates(n,o,1),u=mi.bondHydrogen(l.paper,s[0],s[1],l.options,r);break;case We.PATTERN.TYPE.DATIVE:u=mi.bondDative(l.paper,n,o,l.options,r);break;default:throw new Error("Bond type "+t.b.type+" not supported")}if(u){var p=l.options.previewOpacity;u.attr({opacity:t.b.isPreview?p:1})}return u}(e,this,c,d,h),this.rbb=ai.relBox(this.path.getBBox()),e.addReObjectPath(ei.bondSkeleton,this.visel,this.path,null,!0);var f={};f.path=function(e,t,n,o){var r=n.p,i=o.p,a=i.add(r).scaled(.5),s=i.sub(r).normalized(),u=s.rotateSC(1,0),l=[],c=e.options.lineWidth,d=e.options.bondSpace/2,h=c,f=2*c,m=1.5*d,p=1.5*d,v=3*d,g=.2;switch(t.b.reactingCenterStatus){case We.PATTERN.REACTING_CENTER.NOT_CENTER:l.push(a.addScaled(u,v).addScaled(s,g*v)),l.push(a.addScaled(u,-v).addScaled(s,-.2*v)),l.push(a.addScaled(u,v).addScaled(s,-.2*v)),l.push(a.addScaled(u,-v).addScaled(s,g*v));break;case We.PATTERN.REACTING_CENTER.CENTER:l.push(a.addScaled(u,v).addScaled(s,g*v).addScaled(s,h)),l.push(a.addScaled(u,-v).addScaled(s,-.2*v).addScaled(s,h)),l.push(a.addScaled(u,v).addScaled(s,g*v).addScaled(s,-h)),l.push(a.addScaled(u,-v).addScaled(s,-.2*v).addScaled(s,-h)),l.push(a.addScaled(s,m).addScaled(u,p)),l.push(a.addScaled(s,-m).addScaled(u,p)),l.push(a.addScaled(s,m).addScaled(u,-p)),l.push(a.addScaled(s,-m).addScaled(u,-p));break;case We.PATTERN.REACTING_CENTER.MADE_OR_BROKEN:l.push(a.addScaled(u,v).addScaled(s,f)),l.push(a.addScaled(u,-v).addScaled(s,f)),l.push(a.addScaled(u,v).addScaled(s,-f)),l.push(a.addScaled(u,-v).addScaled(s,-f));break;case We.PATTERN.REACTING_CENTER.ORDER_CHANGED:l.push(a.addScaled(u,v)),l.push(a.addScaled(u,-v));break;case We.PATTERN.REACTING_CENTER.MADE_OR_BROKEN_AND_CHANGED:l.push(a.addScaled(u,v).addScaled(s,f)),l.push(a.addScaled(u,-v).addScaled(s,f)),l.push(a.addScaled(u,v).addScaled(s,-f)),l.push(a.addScaled(u,-v).addScaled(s,-f)),l.push(a.addScaled(u,v)),l.push(a.addScaled(u,-v));break;default:return null}return mi.reactingCenter(e.paper,l,e.options)}(r,this,c,d),f.path&&(f.rbb=ai.relBox(f.path.getBBox()),e.addReObjectPath(ei.data,this.visel,f.path,null,!0));var m={};m.path=function(e,t,n,o){var r=e.options,i=null,a=null;if(t.b.customQuery)i=t.b.customQuery,t.b.customQuery.length>8&&(a=t.b.customQuery,i="".concat(t.b.customQuery.substring(0,8),"..."));else if(t.b.topology===We.PATTERN.TOPOLOGY.RING)i="rng";else{if(t.b.topology!==We.PATTERN.TOPOLOGY.CHAIN)return null;i="chn"}var s=n.p,u=o.p,l=u.add(s).scaled(.5),c=u.sub(s).normalized().rotateSC(1,0),d=r.lineWidth;t.doubleBondShift>0?c=c.scaled(-t.doubleBondShift):0===t.doubleBondShift&&(d+=r.bondSpace/2);var h=new we(2,1).scaled(r.bondSpace);t.b.type===We.PATTERN.TYPE.TRIPLE&&(d+=r.bondSpace);var f=l.add(new we(c.x*(h.x+d),c.y*(h.y+d))),m=mi.bondMark(e.paper,f,i,r);return a&&m.node.childNodes[0].setAttribute("data-tooltip",a),m}(r,this,c,d),m.path&&(m.rbb=ai.relBox(m.path.getBBox()),e.addReObjectPath(ei.data,this.visel,m.path,null,!0)),this.setHover(this.hover,r);var p=null,v=.6*o.subFontSize;o.showBondIds&&(p=Fi(n,l,c,d,v,.5,.5,c.norm),e.addReObjectPath(ei.indices,this.visel,p)),o.showHalfBondIds&&(p=Fi(this.b.hb1,l,c,d,v,.8,.2,c.norm),e.addReObjectPath(ei.indices,this.visel,p),p=Fi(this.b.hb2,l,c,d,v,.2,.8,d.norm),e.addReObjectPath(ei.indices,this.visel,p)),o.showLoopIds&&!o.showBondIds&&(p=Fi(c.loop,l,c,d,v,.5,.5,d.norm),e.addReObjectPath(ei.indices,this.visel,p),p=Fi(d.loop,l,c,d,v,.5,.5,c.norm),e.addReObjectPath(ei.indices,this.visel,p));var g=e.molecule.highlights,y=!1,b="";if(g.forEach((function(e){var t,o=null===(t=e.bonds)||void 0===t?void 0:t.includes(n);y=y||o,o&&(b=e.color)})),y){var A={fill:b,stroke:b,"stroke-width":7*o.lineattr["stroke-width"],"stroke-linecap":"round"},w=Ze.modelToCanvas(this.b.center,e.render.options),E=function(e,t,n){var o={x:t.p.x,y:t.p.y},r={x:n.p.x,y:n.p.y},i=e.render.paper,a="M".concat(o.x,",").concat(o.y," L").concat(r.x,",").concat(r.y);return i.path(a)}(e,c,d);E.attr(A),e.addReObjectPath(ei.hovering,this.visel,E,w,!0)}a.cip&&(this.cip=ai.drawCIPLabel({atomOrBond:a,position:a.center,restruct:r.ctab,visel:this.visel}))}}}}],[{key:"isSelectable",value:function(){return!0}},{key:"bondRecalc",value:function(e,t,n){var o=t.render,r=t.molecule.getGroupFromAtomId(e.b.begin),i=t.molecule.getGroupFromAtomId(e.b.end),a=t.atoms.get(r instanceof Ut?r.getAttachmentAtomId():e.b.begin),s=t.atoms.get(i instanceof Ut?i.getAttachmentAtomId():e.b.end);if(a&&s&&void 0!==e.b.hb1&&void 0!==e.b.hb2){var u=r instanceof Ut?r.pp:a.a.pp,l=i instanceof Ut?i.pp:s.a.pp,c=t.molecule.halfBonds.get(e.b.hb1),d=t.molecule.halfBonds.get(e.b.hb2);null!=c&&c.dir&&null!=d&&d.dir&&(c.p=a.getShiftedSegmentPosition(n,c.dir,u),d.p=s.getShiftedSegmentPosition(n,d.dir,l),e.b.center=we.lc2(u,.5,l,.5),e.b.len=we.dist(Ze.modelToCanvas(u,o.options),Ze.modelToCanvas(l,o.options)),e.b.sb=5*n.lineWidth,e.b.sa=Math.max(e.b.sb,e.b.len/2-2*n.lineWidth),e.b.angle=180*Math.atan2(c.dir.y,c.dir.x)/Math.PI)}}}]),t}(ri);function Bi(e,t,n,o){return e.neighbors.findIndex((function(e){var r=o.molecule.halfBonds.get(e);if(!r||r.bid===t)return!1;var i=o.bonds.get(r.bid);return!!i&&(i.b.type===We.PATTERN.TYPE.SINGLE&&i.b.stereo===We.PATTERN.STEREO.UP?i.b.end===r.begin||i.boldStereo&&n:!(i.b.type!==We.PATTERN.TYPE.DOUBLE||i.b.stereo!==We.PATTERN.STEREO.NONE||!n||!i.boldStereo))}))}function Ci(e,t,n){var o,r,i=[t.b.begin,t.b.end].map((function(t){var o=n.molecule.atoms.get(t);if(!o)return-1;var r=Bi(o,e,!0,n);return r<0?-1:o.neighbors[r]}));t.neihbid1=null!==(o=n.atoms.get(t.b.begin))&&void 0!==o&&o.showLabel?-1:i[0],t.neihbid2=null!==(r=n.atoms.get(t.b.end))&&void 0!==r&&r.showLabel?-1:i[1]}function Ii(e,t,n){var o,r,i="#000";if(0===t.b.stereo)return i;var a=null===(o=n.atoms.get(t.b.begin))||void 0===o?void 0:o.stereoLabel,s=null===(r=n.atoms.get(t.b.end))||void 0===r?void 0:r.stereoLabel,u="";return a&&!s?u=a:!a&&s&&(u=s),u&&e.colorStereogenicCenters!==ti.Off&&e.colorStereogenicCenters!==ti.LabelsOnly?Ai(e,u):i}function Ni(e,t,n,o,r,i){var a=e.options,s=Li(t,o.neihbid1,a.stereoBond,r),u=Li(n,o.neihbid2,a.stereoBond,r),l=s[0],c=s[1],d=u[0],h=u[1];return mi.bondSingleStereoBold(e.paper,l,c,d,h,a,i,Ii(a,o,r))}function Di(e,t){return t<0||Math.abs(e)>.9?0:t/(1-e)}function Li(e,t,n,o){var r=o.halfBonds.get(t),i=we.dot(e.dir,r.dir),a=we.cross(e.dir,r.dir),s=Math.sqrt(.5*(1-i)),u=r.dir.rotateSC((a>=0?-1:1)*s,Math.sqrt(.5*(1+i))),l=e.p.addScaled(u,.7*n/(s+.3)),c=e.p.addScaled(u.negated(),.7*n/(s+.3));return a>0?[l,c]:[c,l]}function _i(e,t,n,o,r,i,a){var s=[.125,.125,.005,.125],u=0,l=null,c=e.options,d=o.doubleBondShift;o.b.type===We.PATTERN.TYPE.SINGLE_OR_AROMATIC&&(u=d>0?1:2,l=s.map((function(e){return e*c.microModeScale}))),o.b.type===We.PATTERN.TYPE.DOUBLE_OR_AROMATIC&&(u=3,l=s.map((function(e){return e*c.microModeScale})));var h=function(e,t,n,o,r,i,a,s){var u=e.p,l=t.p,c=e.norm,d=i/2,h=d+n*d,f=n*d-d,m=u.addScaled(c,h),p=l.addScaled(c,h),v=u.addScaled(c,f),g=l.addScaled(c,f);return n>0?(o&&(m=m.addScaled(e.dir,i*Di(e.rightCos,e.rightSin))),r&&(p=p.addScaled(e.dir,-i*Di(t.leftCos,t.leftSin)))):n<0&&(o&&(v=v.addScaled(e.dir,i*Di(e.leftCos,e.leftSin))),r&&(g=g.addScaled(e.dir,-i*Di(t.rightCos,t.rightSin)))),mi.aromaticBondPaths(m,v,p,g,a,s)}(t,n,d,r,i,c.bondSpace,u,l);return mi.bondAromatic(e.paper,h,d,c,a)}function Fi(e,t,n,o,r,i,a,s){var u=we.lc(n.p,i,o.p,a,s,r),l=t.text(u.x,u.y,e.toString()),c=ai.relBox(l.getBBox());return mi.recenterText(l,c),l}function Hi(e,t){if(!t.b.hb1&&0!==t.b.hb1||!t.b.hb2&&0!==t.b.hb2)return 0;var n=e.halfBonds.get(t.b.hb1),o=e.halfBonds.get(t.b.hb2);if(!n||!o)return 0;var r=(n.leftSin>.3?1:0)+(o.rightSin>.3?1:0),i=(o.leftSin>.3?1:0)+(n.rightSin>.3?1:0);return r>i?-1:r<i||(n.leftSin>.3?1:0)+(n.rightSin>.3?1:0)==1?1:0}function ji(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Gi()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Gi(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Gi=function(){return!!e})()}var zi=new WeakMap,Vi=function(e){function t(){var e,n,o,r;return(0,i.A)(this,t),e=ji(this,t,["enhancedFlag"]),n=(0,l.A)(e),r={writable:!0,value:void 0},function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(n,o=zi),o.set(n,r),e}return(0,c.A)(t,e),(0,a.A)(t,[{key:"hoverPath",value:function(e){var t=nt.fromRelBox((0,w.A)(this,zi).getBBox()),n=t.p1.sub(t.p0),o=t.p0.sub(e.options.offset);return e.paper.rect(o.x,o.y,n.x,n.y)}},{key:"drawHover",value:function(e){var t;if(null===(t=(0,w.A)(this,zi))||void 0===t||!t.attrs)return null;var n=this.hoverPath(e).attr(e.options.hoverStyle);return e.ctab.addReObjectPath(ei.hovering,this.visel,n),n}},{key:"makeSelectionPlate",value:function(e,t,n){var o;return null!==(o=(0,w.A)(this,zi))&&void 0!==o&&o.attrs?this.hoverPath(e.render).attr(n.selectionStyle):null}},{key:"show",value:function(e,t,n){var o=e.render,r=e.molecule.frags.get(t);if(null!=r&&r.enhancedStereoFlag){var i=r.stereoFlagPosition?r.stereoFlagPosition:Ke.getDefaultStereoFlagPosition(e.molecule,t),a=o.paper,s=Ze.modelToCanvas(i,n),u=(0,d.A)((0,d.A)((0,d.A)((0,d.A)({},Ue.Abs,n.absFlagLabel),Ue.And,n.andFlagLabel),Ue.Mixed,n.mixedFlagLabel),Ue.Or,n.orFlagLabel);n.showStereoFlags&&!n.ignoreChiralFlag&&(0,A.A)(this,zi,a.text(s.x,s.y,r.enhancedStereoFlag?u[r.enhancedStereoFlag]:"").attr({font:n.font,"font-size":n.fontsz,fill:"#000"})),o.ctab.addReObjectPath(ei.data,this.visel,(0,w.A)(this,zi),null,!0)}}}],[{key:"isSelectable",value:function(){return!0}}]),t}(ri);function Ui(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Wi()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Wi(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Wi=function(){return!!e})()}var qi=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Ui(this,t,["frag"])).item=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"fragGetAtoms",value:function(e,t){return Array.from(e.atoms.keys()).filter((function(n){return e.atoms.get(n).a.fragment===t}))}},{key:"fragGetBonds",value:function(e,t){return Array.from(e.bonds.keys()).filter((function(n){var o=e.bonds.get(n).b,r=e.atoms.get(o.begin).a.fragment,i=e.atoms.get(o.end).a.fragment;return r===t&&i===t}))}},{key:"calcBBox",value:function(e,t,o){var r;return e.atoms.forEach((function(e){if(e.a.fragment===t){var i=e.visel.boundingBox;if(i)o||(o=n.g._ui_editor.render),i=i.translate((o.options.offset||new we).negated()).transform(Ze.canvasToModel,o.options);else{i=new nt(e.a.pp,e.a.pp);var a=new we(.05*3,.05*3);i=i.extend(a,a)}r=r?nt.union(r,i):i}})),r}},{key:"_draw",value:function(e,t,n){var o=this.calcBBox(e.ctab,t,e);if(o){var r=Ze.modelToCanvas(new we(o.p0.x,o.p0.y),e.options),i=Ze.modelToCanvas(new we(o.p1.x,o.p1.y),e.options);return e.paper.rect(r.x,r.y,i.x-r.x,i.y-r.y,0).attr(n)}}},{key:"draw",value:function(e){return null}},{key:"drawHover",value:function(e){}},{key:"setHover",value:function(e,t){var n=t.ctab.frags.keyOf(this);(n||0===n)&&(n=parseInt(n,10),t.ctab.atoms.forEach((function(o){o.a.fragment===n&&o.setHover(e,t)})),t.ctab.bonds.forEach((function(o){t.ctab.atoms.get(o.b.begin).a.fragment===n&&o.setHover(e,t)})))}}],[{key:"isSelectable",value:function(){return!1}}]),t}(ri);function Yi(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,$i()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function $i(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return($i=function(){return!!e})()}var Xi=new we(.05*3,.05*3),Ki=new we(.2,.4),Zi=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Yi(this,t,["rgroup"])).labelBox=null,n.item=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"getAtoms",value:function(e){var t=[];return this.item.frags.forEach((function(n){t=t.concat(e.ctab.frags.get(n).fragGetAtoms(e.ctab,n))})),t}},{key:"getBonds",value:function(e){var t=[];return this.item.frags.forEach((function(n){t=t.concat(e.ctab.frags.get(n).fragGetBonds(e.ctab,n))})),t}},{key:"calcBBox",value:function(e){var t=null;this.item.frags.forEach((function(n){var o=e.ctab.frags.get(n).calcBBox(e.ctab,n,e);o&&(t=t?nt.union(t,o):o)}));var n=e.ctab.getRGroupAttachmentPointsVBoxByAtomIds(this.getAtoms(e));return t&&n&&(t=nt.union(t,n)),t=t?t.extend(Xi,Xi):t}},{key:"draw",value:function(e,t){var n=this.calcBBox(e);if(!n)return{};n=n.extend(Ki,Ki);var o={data:[]},r=Ze.modelToCanvas(n.p0,t),i=Ze.modelToCanvas(n.p1,t),a=e.paper.set();(function(e,t,n,o){o=Ze.modelToCanvas(o||new we(1,0),t.options);var r=Math.min(.25,.3*n.sz().x),i=n.p1.y-n.p0.y,a=.5*(n.p1.y+n.p0.y),s=mi.bracket(t.paper,o.negated(),o.negated().rotateSC(1,0),Ze.modelToCanvas(new we(n.p0.x,a),t.options),r,i,t.options),u=mi.bracket(t.paper,o,o.rotateSC(1,0),Ze.modelToCanvas(new we(n.p1.x,a),t.options),r,i,t.options);e.push(s,u)})(a,e,n),o.data.push(a);var s=e.ctab.rgroups.keyOf(this),u=e.paper.set(),l=e.paper.text(r.x,(r.y+i.y)/2,"R"+s+"=").attr({font:t.font,"font-size":t.fontRLabel,fill:"black"}),c=ai.relBox(l.getBBox());l.translateAbs(-c.width/2-t.lineWidth,0),u.push(l);for(var d={font:t.font,"font-size":t.fontRLogic,fill:"black"},h=[Qi(s,this.item)],f=c.height/2+t.lineWidth/2,m=0;m<h.length;++m){var p=e.paper.text(r.x,(r.y+i.y)/2,h[m]).attr(d),v=ai.relBox(p.getBBox());f+=v.height/2,p.translateAbs(-v.width/2-6*t.lineWidth,f),f+=v.height/2+t.lineWidth/2,o.data.push(p),u.push(p)}return o.data.push(l),this.labelBox=nt.fromRelBox(u.getBBox()).transform(Ze.canvasToModel,e.options),o}},{key:"_draw",value:function(e,t,n){if(!this.getVBoxObj(e))return null;var o=this.getVBoxObj(e).extend(Xi,Xi);if(!o)return null;var r=Ze.modelToCanvas(o.p0,e.options),i=Ze.modelToCanvas(o.p1,e.options);return e.paper.rect(r.x,r.y,i.x-r.x,i.y-r.y,0).attr(n)}},{key:"drawHover",value:function(e){var t=e.ctab.rgroups.keyOf(this);if(!t)return null;var n=this._draw(e,t,e.options.hoverStyle);return e.ctab.addReObjectPath(ei.hovering,this.visel,n),this.item.frags.forEach((function(t,n){e.ctab.frags.get(n).drawHover(e)})),n}},{key:"show",value:function(e,t,n){var o=this,r=this.draw(e.render,n);Object.keys(r).forEach((function(t){for(;r[t].length>0;)e.addReObjectPath(ei.data,o.visel,r[t].shift(),null,!0)}))}}],[{key:"isSelectable",value:function(){return!1}}]),t}(ri);function Qi(e,t){var n,o=t.ifthen>0?"IF ":"",r=t.range.startsWith(">")||t.range.startsWith("<")||t.range.startsWith("=");n=t.range.length>0?r?t.range:"="+t.range:">0";var i=t.resth?" (RestH)":"",a=t.ifthen>0?"\nTHEN R"+t.ifthen.toString():"";return"".concat(o,"R").concat(e.toString()).concat(n).concat(i).concat(a)}function Ji(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function ea(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ji(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ji(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function ta(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,na()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function na(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(na=function(){return!!e})()}var oa=function(e){function t(e){var n;return(0,i.A)(this,t),n=ta(this,t,["rxnArrow"]),(0,d.A)((0,l.A)(n),"isResizing",!1),n.item=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"calcDistance",value:function(e,t){var n=new we(e.x,e.y),o=this.getReferencePointDistance(e),i=this.item,a=ra(i.pos,n);if(kt.isElliptical(i)){var s=this.getReferencePoints(),u=(0,r.A)(s,3),l=u[0],c=u[1],d=u[2];a=Math.min(a,ra([l,d],n),ra([d,c],n))}var h=o.minDist<=8/t?o.refPoint:null;return{minDist:a=Math.min(o.minDist,a),refPoint:h}}},{key:"getReferencePointDistance",value:function(e){var t=[];return this.getReferencePoints().forEach((function(n){t.push({minDist:Math.abs(we.dist(e,n)),refPoint:n})})),t.reduce((function(e,t){return e&&e.minDist<t.minDist?e:t}),null)}},{key:"hoverPath",value:function(e){var t=this.generatePath(e,e.options,"selection");return e.paper.path(t)}},{key:"drawHover",value:function(e){var t=this.hoverPath(e).attr(e.options.hoverStyle);return e.ctab.addReObjectPath(ei.hovering,this.visel,t),t}},{key:"getReferencePoints",value:function(){var e=[],t=this.item,n=(0,r.A)(t.pos,2),o=n[0],i=n[1],a=t.height;if(e.push(new we(o.x,o.y)),e.push(new we(i.x,i.y)),kt.isElliptical(t)){var s=function(e,t,n){if(0==+U(e)){var o=Math.min(t.x,n.x),r=Math.min(t.y,n.y),i=o+Math.abs(t.x-n.x)/2,a=r+Math.abs(t.y-n.y)/2;return new we(i,a)}var s=Math.hypot(n.x-t.x,n.y-t.y),u=Math.hypot(s/2,e),l=ai.calcCoordinates(t,n,u).pos1,c=ai.calcCoordinates(t,n,u).pos2;if(e>0){if(n.x<t.x)return new we(null==l?void 0:l.x,null==l?void 0:l.y);if(n.x>t.x)return new we(null==c?void 0:c.x,null==c?void 0:c.y);if(n.x===t.x){if(n.y>t.y)return new we(null==c?void 0:c.x,null==c?void 0:c.y);if(n.y<t.y)return new we(null==l?void 0:l.x,null==l?void 0:l.y);if(n.y===t.y)return new we(t.x,t.y)}}else{if(n.x>t.x)return new we(null==l?void 0:l.x,null==l?void 0:l.y);if(n.x<t.x)return new we(null==c?void 0:c.x,null==c?void 0:c.y);if(n.x===t.x){if(n.y>t.y)return new we(null==l?void 0:l.x,null==l?void 0:l.y);if(n.y<t.y)return new we(null==c?void 0:c.x,null==c?void 0:c.y);if(n.y===t.y)return new we(t.x,t.y)}}return new we(t.x,t.y)}(a,o,i);e.push(s)}return e}},{key:"makeAdditionalInfo",value:function(e){var t=e.render.options.microModeScale,n=this.getReferencePoints(),o=e.render.paper.set();return n.forEach((function(n){var r=Ze.modelToCanvas(n,e.render.options);o.push(e.render.paper.circle(r.x,r.y,t/8).attr({fill:"black"}))})),o}},{key:"makeSelectionPlate",value:function(e,t,n){var o=e.render,r=e.render.options,i=e.render.paper.set();return i.push(o.paper.path(this.generatePath(o,r,"selection")).attr(n.selectionStyle)),i}},{key:"generatePath",value:function(e,t,n){var o,r=this.item,i=kt.isElliptical(r)&&r.height?r.height*t.microModeScale:0,a=r.pos.map((function(e){return Ze.modelToCanvas(e,t)||new we})),s=this.getArrowParams(a[0].x,a[0].y,a[1].x,a[1].y),u=s.length,l=s.angle;switch(n){case"selection":o=mi.rectangleArrowHighlightAndSelection(e.paper,{pos:a,height:i},u,l);break;case"arrow":o=mi.arrow(e.paper,ea(ea({},r),{},{pos:a,height:i}),u,l,t,this.isResizing)}return o}},{key:"getArrowParams",value:function(e,t,n,o){return{length:Math.hypot(n-e,o-t),angle:k().angle(e,t,n,o)-180}}},{key:"show",value:function(e,t,n){var o=this.generatePath(e.render,n,"arrow"),r=n.offset;null!=r&&o.translateAbs(r.x,r.y),this.visel.add(o,nt.fromRelBox(ai.relBox(o.getBBox())))}}],[{key:"isSelectable",value:function(){return!0}}]),t}(ri);function ra(e,t){var n;if((t.x<Math.min(e[0].x,e[1].x)||t.x>Math.max(e[0].x,e[1].x))&&(t.y<Math.min(e[0].y,e[1].y)||t.y>Math.max(e[0].y,e[1].y)))n=Math.min(we.dist(e[0],t),we.dist(e[1],t));else{var o=we.dist(e[0],e[1]),r=we.dist(e[0],t),i=we.dist(e[1],t),a=(o+r+i)/2;n=2/o*Math.sqrt(a*(a-o)*(a-r)*(a-i))}return n}function ia(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,aa()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function aa(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(aa=function(){return!!e})()}var sa=function(e){function t(e){var n;return(0,i.A)(this,t),(n=ia(this,t,["rxnPlus"])).item=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"hoverPath",value:function(e){var t=Ze.modelToCanvas(this.item.pp,e.options),n=e.options.microModeScale;return e.paper.rect(t.x-n/4,t.y-n/4,n/2,n/2,n/8)}},{key:"drawHover",value:function(e){var t=this.hoverPath(e).attr(e.options.hoverStyle);return e.ctab.addReObjectPath(ei.hovering,this.visel,t),t}},{key:"makeSelectionPlate",value:function(e,t,n){return this.hoverPath(e.render).attr(n.selectionStyle)}},{key:"show",value:function(e,t,n){var o=e.render,r=Ze.modelToCanvas(this.item.pp,n),i=mi.plus(o.paper,r,n),a=n.offset;null!=a&&i.translateAbs(a.x,a.y),this.visel.add(i,nt.fromRelBox(ai.relBox(i.getBBox())))}}],[{key:"isSelectable",value:function(){return!0}}]),t}(ri);function ua(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,la()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function la(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(la=function(){return!!e})()}var ca=function(e){function t(e){var n;return(0,i.A)(this,t),(n=ua(this,t,["sgroupData"])).sgroup=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"hoverPath",value:function(e){var t=this.sgroup.dataArea,n=Ze.modelToCanvas(t.p0,e.options),o=Ze.modelToCanvas(t.p1,e.options).sub(n);return e.paper.rect(n.x,n.y,o.x,o.y)}},{key:"drawHover",value:function(e){var t=this.hoverPath(e).attr(e.options.hoverStyle);return e.ctab.addReObjectPath(ei.hovering,this.visel,t),t}},{key:"makeSelectionPlate",value:function(e,t,n){return this.hoverPath(e.render).attr(n.selectionStyle)}}],[{key:"isSelectable",value:function(){return!0}}]),t}(ri),da=(0,a.A)((function e(t,n,o,r,a){(0,i.A)(this,e),this.center=t,this.bracketAngleDirection=n,this.bracketDirection=a||n.rotateSC(1,0),this.width=o,this.height=r}));function ha(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,fa()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function fa(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(fa=function(){return!!e})()}var ma=function(e){function t(e){var n;return(0,i.A)(this,t),(n=ha(this,t,["sgroup"])).item=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"draw",value:function(e,t){this.render=e.render;var n=this.render.paper.set(),r=new Re(t.atoms),i=ht.getCrossBonds(e.molecule,r);ht.bracketPos(t,e.molecule,i,e,this.render);var a=t.bracketBox,s=t.bracketDirection;if(t.areas=[a],t.isExpanded()){var u={set:n,render:this.render,sgroup:t,crossBonds:i,atomSet:r,bracketBox:a,direction:s};switch(t.type){case"MUL":u.lowerIndexText=t.data.mul;break;case"queryComponent":case"GEN":break;case"SRU":var l=t.data.connectivity||"eu";"ht"===l&&(l="");var c=t.data.subscript||"n";u.lowerIndexText=c,u.upperIndexText=l;break;case"SUP":u.lowerIndexText=t.data.name,u.upperIndexText=null,u.indexAttribute={"font-style":"italic"};break;case"DAT":n=function(e,t){return ht.bracketPos(t,e.molecule),t.areas=t.bracketBox?[t.bracketBox]:[],null===t.pp&&t.calculatePP(e.molecule),t.data.attached?function(e,t){var n=e.render,o=n.options,r=n.paper,i=r.set();return ht.getAtoms(e,t).forEach((function(a){var s=e.atoms.get(a);if(s){var u=Ze.modelToCanvas(s.a.pp,o),l=s.visel.boundingBox;null!==l&&(u.x=Math.max(u.x,l.p1.x)),u.x+=o.lineWidth;var c=pa(r,u,t,o),d=ai.relBox(c.getBBox());c.translateAbs(.5*d.width,-.3*d.height),i.push(c);var h=nt.fromRelBox(ai.relBox(c.getBBox()));h=h.transform(Ze.canvasToModel,n.options),t.areas.push(h)}})),i}(e,t):function(e,t){var n,o=e.render,r=o.options,i=o.paper,a=i.set(),s=pa(i,null==t||null===(n=t.pp)||void 0===n?void 0:n.scaled(r.microModeScale),t,r);if(t.data.context!==at.Bond){var u=ai.relBox(s.getBBox());s.translateAbs(.5*u.width,-.5*u.height)}a.push(s);var l=nt.fromRelBox(ai.relBox(s.getBBox()));return t.dataArea=l.transform(Ze.canvasToModel,o.options),e.sgroupData.has(t.id)||e.sgroupData.set(t.id,new ca(t)),a}(e,t)}(e,t)}["MUL","SRU","SUP","GEN","queryComponent"].includes(t.type)&&function(e){for(var t=e.set,n=e.render,r=e.sgroup,i=e.crossBonds,a=e.atomSet,s=e.bracketBox,u=e.direction,l=e.lowerIndexText,c=e.upperIndexText,d=e.indexAttribute,h=(0,o.A)(a).reduce((function(e,t){var r=n.ctab.molecule.getRGroupAttachmentPointsByAtomId(t);return[].concat((0,o.A)(e),(0,o.A)(r))}),[]),f=Object.values(i),m=f.flat(),p=function(e,t,n,o,r,i,a,s){var u=a.ctab.molecule,l=[],c=i.rotateSC(1,0);if(n.length<2)!function(e,t,n,o){e=e||new we(1,0),t=t||e.rotateSC(1,0);var r=Math.min(.25,.3*n.sz().x),i=we.lc2(e,n.p0.x,t,.5*(n.p0.y+n.p1.y)),a=we.lc2(e,n.p1.x,t,.5*(n.p0.y+n.p1.y)),s=n.sz().y;o.push(new da(i,e.negated(),r,s),new da(a,e,r,s))}(i,c,r,l);else if(2===n.length&&2===t.length)!function(e,t,n,o,r,i){var a=e.bonds.get(Number(t[0])),s=e.bonds.get(Number(t[1]));if(a&&s){var u,l=a.getCenter(e),c=s.getCenter(e),d=-1,h=-1,f=-1,m=-1,p=we.centre(l,c),v=we.diff(c,l).normalized(),g=v.negated(),y=v.rotateSC(1,0),b=y.negated();null==e||null===(u=e.sGroupForest)||void 0===u||null===(u=u.children)||void 0===u||null===(u=u.get(n))||void 0===u||u.forEach((function(e){var t,n,r=null==o||null===(t=o.ctab)||void 0===t||null===(t=t.sgroups)||void 0===t||null===(t=t.get(e))||void 0===t?void 0:t.visel.boundingBox;r=(null===(n=r)||void 0===n?void 0:n.translate((o.options.offset||new we).negated()).transform(Ze.canvasToModel,o.options))||new nt,d=Math.max(d,ai.shiftRayBox(l,g,r)),h=Math.max(h,ai.shiftRayBox(c,v,r)),f=Math.max(f,ai.shiftRayBox(p,y,r)),m=Math.max(m,ai.shiftRayBox(p,b,r))})),d=Math.max(d+.2,0),h=Math.max(h+.2,0);var A=.25,w=1.5+(f=Math.max(Math.max(f,m)+.1,0));r.length&&(w=2+2*Math.sin(Math.PI/6)+f),i.push(new da(l.addScaled(g,d),g,A,w),new da(c.addScaled(v,h),v,A,w))}}(u,n,s,a,o,l);else if(2===n.length&&1===t.length)!function(e,t,n,o,r){var i=!1,a=e.map((function(e){var n=t.bonds.get(Number(e));return(null==n?void 0:n.getDir(t))||new we})),s=we.crossProduct(a[0],a[1])>0;(i=1===Math.abs(Number(e[0])-Number(e[1])))&&!s&&e.reverse();for(var u=0;u<e.length;++u){var l,c=t.bonds.get(Number(e[u])),d=(null==c?void 0:c.getDir(t))||new we,h=void 0,f=void 0;2!==n.length?(s&&i&&(d=d.negated()),d=0===u?d:d.negated(),h=0===u?d.rotateSC(1,0).negated():d.rotateSC(1,0),f=d):(n=n.sort((function(e,t){return e-t})),h=((null===(l=o.ctab.rgroupAttachmentPoints.get(n[u]))||void 0===l?void 0:l.lineDirectionVector)||new we).negated(),f=0===u?h.rotateSC(1,0):h.rotateSC(1,0).negated()),r.push(new da((null==c?void 0:c.getCenter(t))||new we,f,.2,n.length?1.8:1,h))}}(n,u,o,a,l);else for(var d=0;d<n.length;++d){var h=u.bonds.get(Number(n[d])),f=null==h?void 0:h.getCenter(u),m=e.has(null==h?void 0:h.begin)?null==h?void 0:h.getDir(u):null==h?void 0:h.getDir(u).negated();f&&m&&l.push(new da(f,m,.2,r.sz().y))}return l}(a,f,m,h,s,u,n,r.id),v=-1,g=2===m.length&&1===f.length&&!!h.length,y=0;y<p.length;++y){var b=p[y],A=mi.bracket(n.paper,Ze.modelToCanvas(b.bracketAngleDirection,n.options),Ze.modelToCanvas(b.bracketDirection,n.options),Ze.modelToCanvas(b.center,n.options),b.width,b.height,n.options,g);t.push(A),(v<0||p[v].bracketAngleDirection.x<b.bracketAngleDirection.x||p[v].bracketAngleDirection.x===b.bracketAngleDirection.x&&p[v].bracketAngleDirection.y>b.bracketAngleDirection.y)&&(v=y)}var w=p[v];function E(e){var o,r,i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=new we(t[v].getPath()[1][1],t[v].getPath()[1][2],0),s=new we(t[v].getPath()[2][1],t[v].getPath()[2][2],0);r=s.y===a.y?s.x>a.x?a:s:s.y>a.y?s:a,o=i?r:r.x===a.x&&r.y===a.y?s:a;var u=new we(o.x,o.y),l=n.paper.text(u.x,u.y,e).attr({font:n.options.font,"font-size":n.options.fontszsub});d&&l.attr(d);var c=nt.fromRelBox(ai.relBox(l.getBBox())),h=Math.max(ai.shiftRayBox(u,w.bracketAngleDirection.negated(),c),3)+2;l.translateAbs(h*w.bracketAngleDirection.x,h*w.bracketAngleDirection.y),t.push(l)}l&&E(l,!0),c&&E(c)}(u)}return n}},{key:"getTextHighlightDimensions",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1?arguments[1]:void 0,n=0,o=0,r=0,i=0,a=this.item;if(a){var s=a.getContractedPosition(t.ctab.molecule),u=s.atomId,l=s.position;if(null!=a&&a.isContracted()&&l){var c=t.ctab.atoms.get(u),d=(null==c?void 0:c.visel.boundingBox)||(null==c?void 0:c.visel.oldBoundingBox);if(d){var h=Ze.modelToCanvas(l,t.options),f=h.x,m=h.y,p=d.p0,v=d.p1;n=f-(r=v.x-p.x+2*e)/2,o=m-(i=v.y-p.y+2*e)/2}}}return{startX:n,startY:o,width:r,height:i}}},{key:"getContractedSelectionContour",value:function(e){var t=e.paper,n=e.options,o=n.fontsz,r=o*n.radiusScaleFactor*2,i=this.getTextHighlightDimensions(o/2,e),a=i.startX,s=i.startY,u=i.width,l=i.height;return t.rect(a,s,u,l,r)}},{key:"makeSelectionPlate",value:function(e,t,n){var o=this.item,r=e.molecule.functionalGroups,i=e.render;if(gt.isContractedFunctionalGroup(null==o?void 0:o.id,r))return this.getContractedSelectionContour(i).attr(n.selectionStyle)}},{key:"drawHover",value:function(e){var t=e.options,n=e.paper,o=this.item;if(o){var r=function(e,t){var n=t.options,o=e.bracketBox.transform(Ze.modelToCanvas,n),r=n.lineWidth,i=new we(4*r,6*r);o=o.extend(i,i);var a=e.bracketDirection,s=a.rotateSC(1,0),u=we.lc2(a,o.p0.x,s,o.p0.y),l=we.lc2(a,o.p0.x,s,o.p1.y),c=we.lc2(a,o.p1.x,s,o.p0.y),d=we.lc2(a,o.p1.x,s,o.p1.y),h=n.contractedFunctionalGroupSize,f=(c.x+u.x)/2-h/2,m=(l.y+u.y)/2-h/2,p=e.getContractedPosition(t.ctab.molecule).position;if(p){var v=new we(h/2,h/2,0),g=we.diff(p.scaled(40),v);f=g.x,m=g.y}return{a0:u,a1:l,b0:c,b1:d,startX:f,startY:m,size:h}}(o,e),i=r.a0,a=r.a1,s=r.b0,u=r.b1,l=e.ctab.molecule.functionalGroups,c=n.set();gt.isContractedFunctionalGroup(o.id,l)?o.hovering=this.getContractedSelectionContour(e).attr(t.hoverStyle):this.selected||(o.hovering=n.path("M{0},{1}L{2},{3}L{4},{5}L{6},{7}L{0},{1}",U(i.x),U(i.y),U(a.x),U(a.y),U(u.x),U(u.y),U(s.x),U(s.y)).attr(t.hoverStyle)),c.push(o.hovering),ht.getAtoms(e.ctab.molecule,o).forEach((function(t){var n;c.push(null==e||null===(n=e.ctab)||void 0===n||null===(n=n.atoms)||void 0===n||null===(n=n.get(t))||void 0===n?void 0:n.makeHoverPlate(e))}),this),ht.getBonds(e.ctab.molecule,o).forEach((function(t){var n;c.push(null==e||null===(n=e.ctab)||void 0===n||null===(n=n.bonds)||void 0===n||null===(n=n.get(t))||void 0===n?void 0:n.makeHoverPlate(e))}),this),e.ctab.addReObjectPath(ei.hovering,this.visel,c)}}},{key:"show",value:function(e){var t=e.render,n=this.item;if(n&&"MRV_IMPLICIT_H"!==n.data.fieldName){var o=t.ctab,r=this.draw(o,n);e.addReObjectPath(ei.data,this.visel,r,null,!0),this.setHover(this.hover,t)}}}],[{key:"isSelectable",value:function(){return!1}}]),t}(ri);function pa(e,t,n,o){var r=e.text(null==t?void 0:t.x,null==t?void 0:t.y,n.data.fieldValue).attr({font:o.font,"font-size":o.fontsz}),i=r.getBBox(),a=e.rect(i.x-1,i.y-1,i.width+2,i.height+2,3,3);a=n.selected?a.attr(o.selectionStyle):a.attr({fill:"#fff",stroke:"#fff"});var s=e.set();return s.push(a,r.toFront()),s}function va(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function ga(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?va(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):va(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function ya(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,ba()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function ba(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(ba=function(){return!!e})()}var Aa=function(e){function t(e){var n;return(0,i.A)(this,t),(n=ya(this,t,["simpleObject"])).item=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"calcDistance",value:function(e,t){var n,o=new we(e.x,e.y),r=this.getReferencePointDistance(e),i=this.item,a=i.mode,s=i.pos;switch(a){case Tt.ellipse:var u=we.diff(s[1],s[0]),l=u.x/2,c=u.y/2,d=we.sum(s[0],new we(l,c)),h=we.diff(o,d);n=0!==l&&0!==c?Math.abs(1-h.x*h.x/(l*l)-h.y*h.y/(c*c)):wa(s,o);break;case Tt.rectangle:var f=Math.min(s[0].x,s[1].x),m=Math.min(s[0].y,s[1].y),p=Math.max(s[0].x,s[1].x),v=Math.max(s[0].y,s[1].y),g=[];o.x>=f&&o.x<=p&&(o.y<m?g.push(m-o.y):o.y>v?g.push(o.y-v):g.push(o.y-m,v-o.y)),o.x<f&&o.y<m&&g.push(we.dist(new we(f,m),o)),o.x>p&&o.y>v&&g.push(we.dist(new we(p,v),o)),o.x<f&&o.y>v&&g.push(we.dist(new we(f,v),o)),o.x>p&&o.y<m&&g.push(we.dist(new we(p,m),o)),o.y>=m&&o.y<=v&&(o.x<f?g.push(f-o.x):o.x>p?g.push(o.x-p):g.push(o.x-f,p-o.x)),n=Math.min.apply(Math,g);break;case Tt.line:n=wa(s,o);break;default:throw new Error("Unsupported shape type")}var y=r.minDist<=8/t?r.refPoint:null;return{minDist:n=Math.min(r.minDist,n),refPoint:y}}},{key:"getReferencePointDistance",value:function(e){var t=[];return this.getReferencePoints().forEach((function(n){t.push({minDist:Math.abs(we.dist(e,n)),refPoint:n})})),t.reduce((function(e,t){return e&&e.minDist<t.minDist?e:t}),null)}},{key:"getReferencePoints",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=[];switch(this.item.mode){case Tt.ellipse:case Tt.rectangle:var n=new we(Math.min(this.item.pos[0].x,this.item.pos[1].x),Math.min(this.item.pos[0].y,this.item.pos[1].y)),o=Math.abs(we.diff(this.item.pos[0],this.item.pos[1]).x),r=Math.abs(we.diff(this.item.pos[0],this.item.pos[1]).y);t.push(new we(n.x+.5*o,n.y),new we(n.x+o,n.y+.5*r),new we(n.x+.5*o,n.y+r),new we(n.x,n.y+.5*r)),e&&this.item.mode!==Tt.rectangle||t.push(n,new we(n.x,n.y+r),new we(n.x+o,n.y+r),new we(n.x+o,n.y));break;case Tt.line:this.item.pos.forEach((function(e){return t.push(new we(e.x,e.y,0))}));break;default:throw new Error("Unsupported shape type")}return t}},{key:"getHoverPathStyle",value:function(e,t,n){return n?e.attr(t.options.hoverStyle):e.attr(ga(ga({},t.options.hoverStyle),{},{fill:"#fff"}))}},{key:"hoverPath",value:function(e){var t=[];this.item.pos.forEach((function(n,o){t[o]=Ze.modelToCanvas(n,e.options)}));var n=e.options.microModeScale,o=[];switch(this.item.mode){case Tt.ellipse:var r=we.diff(t[1],t[0]),i=r.x/2,a=r.y/2,s=e.paper.ellipse(U(t[0].x+i),U(t[0].y+a),U(Math.abs(i)+n/8),U(Math.abs(a)+n/8));if(o.push({path:this.getHoverPathStyle(s,e,!0),stylesApplied:!0}),Math.abs(i)-n/8>0&&Math.abs(a)-n/8>0){var u=e.paper.ellipse(U(t[0].x+i),U(t[0].y+a),U(Math.abs(i)-n/8),U(Math.abs(a)-n/8));o.push({path:this.getHoverPathStyle(u,e,!1),stylesApplied:!0})}break;case Tt.rectangle:var l=e.paper.rect(U(Math.min(t[0].x,t[1].x)-n/8),U(Math.min(t[0].y,t[1].y)-n/8),U(Math.max(t[0].x,t[1].x)-Math.min(t[0].x,t[1].x)+n/4),U(Math.max(t[0].y,t[1].y)-Math.min(t[0].y,t[1].y)+n/4));if(o.push({path:this.getHoverPathStyle(l,e,!0),stylesApplied:!0}),Math.max(t[0].x,t[1].x)-Math.min(t[0].x,t[1].x)-n/4>0&&Math.max(t[0].y,t[1].y)-Math.min(t[0].y,t[1].y)-n/4>0){var c=e.paper.rect(U(Math.min(t[0].x,t[1].x)+n/8),U(Math.min(t[0].y,t[1].y)+n/8),U(Math.max(t[0].x,t[1].x)-Math.min(t[0].x,t[1].x)-n/4),U(Math.max(t[0].y,t[1].y)-Math.min(t[0].y,t[1].y)-n/4));o.push({path:this.getHoverPathStyle(c,e,!1),stylesApplied:!0})}break;case Tt.line:var d=[],h=Math.atan((t[1].y-t[0].y)/(t[1].x-t[0].x)),f={x:0,y:0},m={x:0,y:0},p=t[0].x>t[1].x?-1:1;f.x=t[0].x-p*(n/8*Math.cos(h)),f.y=t[0].y-p*(n/8*Math.sin(h)),m.x=t[1].x+p*(n/8*Math.cos(h)),m.y=t[1].y+p*(n/8*Math.sin(h)),d.push("M",f.x+p*n/8*Math.sin(h),f.y-p*n/8*Math.cos(h)),d.push("L",m.x+p*n/8*Math.sin(h),m.y-p*n/8*Math.cos(h)),d.push("L",m.x-p*n/8*Math.sin(h),m.y+p*n/8*Math.cos(h)),d.push("L",f.x-p*n/8*Math.sin(h),f.y+p*n/8*Math.cos(h)),d.push("L",f.x+p*n/8*Math.sin(h),f.y-p*n/8*Math.cos(h)),o.push({path:this.getHoverPathStyle(e.paper.path(d),e,!0),stylesApplied:!0});break;default:throw new Error("Unsupported shape type")}return o}},{key:"drawHover",value:function(e){var t=this.hoverPath(e).map((function(t){return t.stylesApplied?t.path:t.path.attr(e.options.hoverStyle)}));return e.ctab.addReObjectPath(ei.hovering,this.visel,t),t}},{key:"makeSelectionPlate",value:function(e,t,n){var o=this,r=this.item.pos.map((function(t){return Ze.modelToCanvas(t,e.render.options)||new we})),i=this.getReferencePoints(),a=e.render.options.microModeScale;return this.selectionSet=e.render.paper.set(),this.selectionPointsSet=e.render.paper.set(),this.selectionSet.push(Ea(this.item.mode,t,r).attr(n.selectionStyleSimpleObject)),i.forEach((function(t){var n=Ze.modelToCanvas(t,e.render.options);o.selectionPointsSet.push(e.render.paper.circle(n.x,n.y,a/8).attr({fill:"black"}))})),e.addReObjectPath(ei.selectionPlate,this.visel,this.selectionPointsSet),this.selectionSet}},{key:"togglePoints",value:function(e){var t,n;e?null===(t=this.selectionPointsSet)||void 0===t||t.show():null===(n=this.selectionPointsSet)||void 0===n||n.hide()}},{key:"show",value:function(e,t){var n=e.render,o=this.item.pos.map((function(e){return Ze.modelToCanvas(e,t)||new we})),r=Ea(this.item.mode,n.paper,o),i=t.offset;null!=i&&r.translateAbs(i.x,i.y),this.visel.add(r,nt.fromRelBox(ai.relBox(r.getBBox())))}}],[{key:"isSelectable",value:function(){return!0}}]),t}(ri);function wa(e,t){var n;if((t.x<Math.min(e[0].x,e[1].x)||t.x>Math.max(e[0].x,e[1].x))&&(t.y<Math.min(e[0].y,e[1].y)||t.y>Math.max(e[0].y,e[1].y)))n=Math.min(we.dist(e[0],t),we.dist(e[1],t));else{var o=we.dist(e[0],e[1]),r=we.dist(e[0],t),i=we.dist(e[1],t),a=(o+r+i)/2;n=2/o*Math.sqrt(a*(a-o)*(a-r)*(a-i))}return n}function Ea(e,t,n){var o;switch(e){case Tt.ellipse:o=mi.ellipse(t,n);break;case Tt.rectangle:o=mi.rectangle(t,n);break;case Tt.line:o=mi.line(t,n);break;default:throw new Error("Unsupported shape type")}return o}function Pa(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,xa()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function xa(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(xa=function(){return!!e})()}var Sa=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Pa(this,t,["loop"])).loop=e,n.centre=new we,n.radius=new we,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"show",value:function(e,t,n){var o=this,r=e.render.paper,i=e.molecule,a=this.loop;this.centre=new we,a.hbs.forEach((function(t){var r=i.halfBonds.get(t),s=e.bonds.get(r.bid),u=Ze.modelToCanvas(e.atoms.get(r.begin).a.pp,n);s.b.type!==We.PATTERN.TYPE.AROMATIC&&(a.aromatic=!1),o.centre.add_(u)})),a.convex=!0;for(var s=0;s<this.loop.hbs.length;++s){var u=i.halfBonds.get(a.hbs[s]),l=i.halfBonds.get(a.hbs[(s+1)%a.hbs.length]);Math.atan2(we.cross(u.dir,l.dir),we.dot(u.dir,l.dir))>0&&(a.convex=!1)}if(this.centre=this.centre.scaled(1/a.hbs.length),this.radius=-1,a.hbs.forEach((function(t){var r=i.halfBonds.get(t),a=Ze.modelToCanvas(e.atoms.get(r.begin).a.pp,n),s=Ze.modelToCanvas(e.atoms.get(r.end).a.pp,n),u=we.diff(s,a).rotateSC(1,0).normalized(),l=we.dot(we.diff(a,o.centre),u);o.radius=o.radius<0?l:Math.min(o.radius,l)})),this.radius*=.7,a.aromatic){var c=null;if(a.convex&&n.aromaticCircle)c=r.circle(this.centre.x,this.centre.y,this.radius).attr({stroke:"#000","stroke-width":n.lineattr["stroke-width"]});else{for(var d="",h=0;h<a.hbs.length;++h){var f=i.halfBonds.get(a.hbs[h]),m=i.halfBonds.get(a.hbs[(h+1)%a.hbs.length]),p=Math.atan2(we.cross(f.dir,m.dir),we.dot(f.dir,m.dir)),v=(Math.PI-p)/2,g=m.dir.rotate(v),y=Ze.modelToCanvas(e.atoms.get(m.begin).a.pp,n),b=Math.sin(v);Math.abs(b)<.1&&(b=.1*b/Math.abs(b));var A=n.bondSpace/b,w=y.addScaled(g,-A);d+=0===h?"M":"L",d+=U(w.x)+","+U(w.y)}d+="Z",c=r.path(d).attr({stroke:"#000","stroke-width":n.lineattr["stroke-width"],"stroke-dasharray":"- "})}e.addReObjectPath(ei.data,this.visel,c,null,!0)}}},{key:"isValid",value:function(e,t){var n=e.halfBonds;return this.loop.hbs.every((function(e){return n.has(e)&&n.get(e).loop===t}))}}],[{key:"isSelectable",value:function(){return!1}}]),t}(ri);function Oa(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function ka(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Ma()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Ma(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Ma=function(){return!!e})()}var Ra=function(e){function t(e){var n;return(0,i.A)(this,t),n=ka(this,t,["text"]),(0,d.A)((0,l.A)(n),"paths",[]),n.item=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"getReferencePoints",value:function(){if(!this.paths.length)return[];var e=this.getRelBox(this.paths),t=e.p0,n=e.p1,o=this.item.position,r=Math.abs(we.diff(t,n).x)/40,i=Math.abs(we.diff(t,n).y)/40,a=[];return a.push(this.item.position,new we(o.x,o.y+i),new we(o.x+r,o.y+i),new we(o.x+r,o.y)),a}},{key:"getVBoxObj",value:function(){var e=this.getReferencePoints(),t=(0,r.A)(e,3),n=t[0];t[1];var o=t[2];return new nt(n,o)}},{key:"hoverPath",value:function(e){var t=this.getRelBox(this.paths),n=t.p0,o=t.p1,r=n.sub(e.options.offset),i=o.sub(n),a=i.x,s=i.y;return e.paper.rect(r.x,r.y,a,s,5)}},{key:"getRelBox",value:function(e){var t=this,n=e[0][0].getBBox().x,r=e[0],i=Math.min.apply(Math,(0,o.A)(r.map((function(e){return e.getBBox().y})))),a=e.reduce((function(e,n){return t.getRowWidth(n)>t.getRowWidth(e)?n:e}),e[0]),s=a[a.length-1],u=s.getBBox().x+s.getBBox().width,l=e[e.length-1],c=Math.max.apply(Math,(0,o.A)(l.map((function(e){return e.getBBox().y+e.getBBox().height}))));return{p0:new we(n,i),p1:new we(u,c)}}},{key:"getRowWidth",value:function(e){return e.reduce((function(e,t){return e+t.getBBox().width}),0)}},{key:"drawHover",value:function(e){if(!this.paths.length)return null;var t=this.hoverPath(e).attr(e.options.hoverStyle);return e.ctab.addReObjectPath(ei.hovering,this.visel,t),t}},{key:"makeSelectionPlate",value:function(e,t,n){return this.paths.length&&t?this.hoverPath(e.render).attr(n.selectionStyle):null}},{key:"show",value:function(e,t,n){var o=this,i=e.render,a=i.paper,s=Ze.modelToCanvas(this.item.position,n),u=0;this.paths=[];var l=this.item.content?JSON.parse(this.item.content):null;l&&(l.blocks.forEach((function(e){var t=o.getRanges(e,n),i=0,l=[];t.forEach((function(t){var o=(0,r.A)(t,3),c=o[0],h=o[1],f=o[2];e.text=e.text.replace(/[^\S\r\n]/g," ");var m=a.text(s.x,s.y,e.text.substring(c,h+1)||" ").attr(function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Oa(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Oa(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({font:n.font,"font-size":n.fontsz,"text-anchor":"start",fill:"#000000"},f));m.translateAbs(i,u+(f.shiftY||0)),l.push(m),i+=m.getBBox().width})),o.paths.push(l);var c=o.getRelBox([l]),h=c.p0,f=c.p1;u+=Math.abs(we.diff(h,f).y)})),this.item.setPos(this.getReferencePoints()),i.ctab.addReObjectPath(ei.data,this.visel,(0,T.flatten)(this.paths),null,!0))}},{key:"getRanges",value:function(e,t){for(var n=[],o=0,r=this.getStyles(e,o,t),i=1;i<e.text.length;i++){var a=this.getStyles(e,i,t);(0,T.isEqual)(r,a)||(n.push([o,i-1,r]),r=a,o=i)}return n.push([o,e.text.length-1,r]),n}},{key:"getStyles",value:function(e,t,n){var o=e.inlineStyleRanges.filter((function(e){return e.offset<=t&&t<e.offset+e.length})),r=o.reduce((function(e,t){var n;return t.style.includes(qt.FontSize)?null===(n=t.style.match(/\d+/))||void 0===n?void 0:n[0]:e}),null);return o.sort((function(e,t){return t.style.includes(qt.FontSize)?1:-1})),o.reduce((function(e,t){var o=r||n.fontsz,i=.5*(r||n.fontszsub);switch(t.style){case qt.Bold:e["font-weight"]="bold";break;case qt.Italic:e["font-style"]="italic";break;case qt.Subscript:e["font-size"]=i+"px",e.shiftY=o/4;break;case qt.Superscript:e["font-size"]=i+"px",e.shiftY=-o/3;break;case"".concat(qt.FontSize,"_").concat(r,"px"):e["font-size"]=r+"px"}return e}),{})}}],[{key:"isSelectable",value:function(){return!0}}]),t}(ri);function Ta(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Ba()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Ba(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Ba=function(){return!!e})()}var Ca=function(e){function t(e,n){var o;return(0,i.A)(this,t),o=Ta(this,t,["rgroupAttachmentPoint"]),(0,d.A)((0,l.A)(o),"lineDirectionVector",new we),o.item=e,o.reAtom=n,o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"normalizedLineDirectionVector",get:function(){return this.lineDirectionVector.normalized()}},{key:"normalizedCurveDirectionVector",get:function(){return this.lineDirectionVector.rotate(Math.PI/2).normalized()}},{key:"startPoint",get:function(){return this.reAtom.a.pp}},{key:"middlePoint",get:function(){return this.outlineEndPoint.addScaled(this.normalizedLineDirectionVector,-t.CURVE_OUTLINE_HEIGHT)}},{key:"endPoint",get:function(){return this.startPoint.add(this.lineDirectionVector)}},{key:"outlineEndPoint",get:function(){var e=this.lineDirectionVector.length()+t.OUTLINE_PADDING;return this.startPoint.addScaled(this.normalizedLineDirectionVector,e)}},{key:"getOutlinePoints",value:function(){var e=this.outlineEndPoint.addScaled(this.normalizedCurveDirectionVector,-t.CURVE_OUTLINE_WIDTH/2),n=e.addScaled(this.normalizedCurveDirectionVector,t.OUTLINE_PADDING),o=this.outlineEndPoint.addScaled(this.normalizedCurveDirectionVector,t.CURVE_OUTLINE_WIDTH/2),r=o.addScaled(this.normalizedCurveDirectionVector,-t.OUTLINE_PADDING),i=this.middlePoint.addScaled(this.normalizedCurveDirectionVector,-t.CURVE_OUTLINE_WIDTH/2),a=i.addScaled(this.normalizedCurveDirectionVector,t.OUTLINE_PADDING),s=this.middlePoint.addScaled(this.normalizedCurveDirectionVector,t.CURVE_OUTLINE_WIDTH/2),u=s.addScaled(this.normalizedCurveDirectionVector,-t.OUTLINE_PADDING),l=this.middlePoint.addScaled(this.normalizedCurveDirectionVector,-t.LINE_OUTLINE_WIDTH/2),c=this.middlePoint.addScaled(this.normalizedCurveDirectionVector,t.LINE_OUTLINE_WIDTH/2),d=this.startPoint.addScaled(this.normalizedCurveDirectionVector,-t.LINE_OUTLINE_WIDTH/2),h=d.addScaled(this.normalizedLineDirectionVector,t.OUTLINE_PADDING),f=this.startPoint.addScaled(this.normalizedCurveDirectionVector,t.LINE_OUTLINE_WIDTH/2);return[e,n,r,o,s,u,c,f.addScaled(this.normalizedLineDirectionVector,t.OUTLINE_PADDING),f,d,h,l,a,i]}},{key:"getDistanceTo",value:function(e){return we.dist(e,this.middlePoint)}},{key:"show",value:function(e){var t=this.getAttachmentPointDirectionVector(e.molecule);if(t){this.lineDirectionVector=t,function(e,t,n,o,r){var i=t.options,a=t.paper,s=Ze.modelToCanvas(e.a.pp,i),u=e.getShiftedSegmentPosition(i,n),l=s.addScaled(n,.85*i.microModeScale),c=mi.rgroupAttachmentPoint(a,u,l,n,i);o(ei.indices,r,c,s,!0)}(this.reAtom,e.render,t,e.addReObjectPath.bind(e),this.visel);var n=function(e){return e.molecule.atoms.some((function(e){var t=e.attachmentPoints;return t===Oe.SecondSideOnly||t===Oe.BothSides}))}(e);if(n){var o="primary"===this.item.type?"1":"2";!function(e,t,n,o,r,i){var a=t.options,s=t.paper,u=Ze.modelToCanvas(e.a.pp,a),l=function(e,t,n){var o=t.rotateSC(1,0);return e.addScaled(o,.17*n).addScaled(t,.7*n)}(u,n,a.microModeScale),c=mi.rgroupAttachmentPointLabel(s,l,r,a,e.color);o(ei.indices,i,c,u,!0)}(this.reAtom,e.render,t,e.addReObjectPath.bind(e),o,this.visel)}}}},{key:"getHoverPlatePath",value:function(e){var t=this.getOutlinePoints().map((function(t){return Ze.modelToCanvas(t,e)})),n=(0,r.A)(t,14),o=n[0],i=n[1],a=n[2],s=n[3],u=n[4],l=n[5],c=n[6],d=n[7],h=n[8],f=n[9],m=n[10],p=n[11],v=n[12],g=n[13];return"\n M ".concat(i.x," ").concat(i.y,"\n L ").concat(a.x," ").concat(a.y,"\n C ").concat(s.x," ").concat(s.y,", ").concat(u.x," ").concat(u.y,", ").concat(l.x," ").concat(l.y,"\n L ").concat(c.x," ").concat(c.y,"\n L ").concat(d.x," ").concat(d.y,"\n C ").concat(h.x," ").concat(h.y,", ").concat(f.x," ").concat(f.y,", ").concat(m.x," ").concat(m.y,"\n L ").concat(p.x," ").concat(p.y,"\n L ").concat(v.x," ").concat(v.y,"\n C ").concat(g.x," ").concat(g.y,", ").concat(o.x," ").concat(o.y,", ").concat(i.x," ").concat(i.y,"\n ")}},{key:"makeHoverPlate",value:function(e){var t=this.getHoverPlatePath(e.options);return e.paper.path(t).attr(e.options.hoverStyle)}},{key:"makeSelectionPlate",value:function(e,t,n){var o=this.getHoverPlatePath(n);return t.path(o).attr(n.selectionStyle)}},{key:"drawHover",value:function(e){var t=this.makeHoverPlate(e);return e.ctab.addReObjectPath(ei.hovering,this.visel,t),t}},{key:"getAttachmentPointDirectionVector",value:function(e){if(this.reAtom.hasAttachmentPoint()){if(this.isTrisectionAttachmentPoint())return function(e,t,n){var o=e.getLargestSectorFromNeighbors(t),r=o.largestAngle,i=o.neighborAngle;return Ia("primary"===n?i+r/3:i+2*r/3)}(this.reAtom,e,this.item.type);var t=1===this.reAtom.a.neighbors.length?function(e,t){var n,o=2*Math.PI/3,r=Math.PI,i=e.a.neighbors[0],a=t.halfBonds.get(i);return Ia(a.ang+((null===(n=t.bonds.get(a.bid))||void 0===n?void 0:n.type)===We.PATTERN.TYPE.TRIPLE?r:o))}(this.reAtom,e):this.reAtom.bisectLargestSector(e);return t}}},{key:"isTrisectionAttachmentPoint",value:function(){return this.reAtom.a.attachmentPoints===Oe.BothSides}}],[{key:"isSelectable",value:function(){return!0}}]),t}(ri);function Ia(e){return new we(Math.cos(e),Math.sin(e))}function Na(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Da(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return La(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?La(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function La(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}(0,d.A)(Ca,"LINE_OUTLINE_WIDTH",.36),(0,d.A)(Ca,"OUTLINE_PADDING",.15),(0,d.A)(Ca,"CURVE_OUTLINE_WIDTH",1),(0,d.A)(Ca,"CURVE_OUTLINE_HEIGHT",.42);var _a=function(){function e(t,n){var o=this;(0,i.A)(this,e),(0,d.A)(this,"atoms",new Map),(0,d.A)(this,"bonds",new Map),(0,d.A)(this,"reloops",new Map),(0,d.A)(this,"rxnPluses",new Map),(0,d.A)(this,"rxnArrows",new Map),(0,d.A)(this,"frags",new Gt),(0,d.A)(this,"rgroups",new Gt),(0,d.A)(this,"rgroupAttachmentPoints",new Gt),(0,d.A)(this,"sgroups",new Map),(0,d.A)(this,"sgroupData",new Map),(0,d.A)(this,"enhancedFlags",new Map),(0,d.A)(this,"simpleObjects",new Map),(0,d.A)(this,"texts",new Map),(0,d.A)(this,"initialized",!1),(0,d.A)(this,"layers",[]),(0,d.A)(this,"connectedComponents",new Gt),(0,d.A)(this,"ccFragmentType",new Gt),(0,d.A)(this,"structChanged",!1),(0,d.A)(this,"atomsChanged",new Map),(0,d.A)(this,"simpleObjectsChanged",new Map),(0,d.A)(this,"rxnArrowsChanged",new Map),(0,d.A)(this,"rxnPlusesChanged",new Map),(0,d.A)(this,"enhancedFlagsChanged",new Map),(0,d.A)(this,"bondsChanged",new Map),(0,d.A)(this,"textsChanged",new Map),(0,d.A)(this,"snappingBonds",[]),this.render=n,this.molecule=t||new Yt,this.initLayers(),this.clearMarks(),t.atoms.forEach((function(e,t){o.atoms.set(t,new bi(e))})),t.bonds.forEach((function(e,t){o.bonds.set(t,new Ti(e))})),t.loops.forEach((function(e,t){o.reloops.set(t,new Sa(e))})),t.rxnPluses.forEach((function(e,t){o.rxnPluses.set(t,new sa(e))})),t.rxnArrows.forEach((function(e,t){o.rxnArrows.set(t,new oa(e))})),t.simpleObjects.forEach((function(e,t){o.simpleObjects.set(t,new Aa(e))})),t.texts.forEach((function(e,t){o.texts.set(t,new Ra(e))})),t.frags.forEach((function(e,t){o.frags.set(t,new qi(e)),e&&o.enhancedFlags.set(t,new Vi)})),t.rgroups.forEach((function(e,t){o.rgroups.set(t,new Zi(e))})),t.rgroupAttachmentPoints.forEach((function(e,t){var n=o.atoms.get(e.atomId);f()(null!=n),o.rgroupAttachmentPoints.set(t,new Ca(e,n))})),t.sgroups.forEach((function(e,t){o.sgroups.set(t,new ma(e)),"DAT"!==e.type||e.data.attached||o.sgroupData.set(t,new ca(e))}))}return(0,a.A)(e,[{key:"visibleRGroupAttachmentPoints",get:function(){var e=this,t=this.molecule.sgroups,n=this.molecule.functionalGroups;return this.rgroupAttachmentPoints.filter((function(o,r){var i=r.item.atomId,a=e.molecule.atoms.get(i);return f()(null!=a),!gt.isAtomInContractedFunctionalGroup(a,t,n,!1)}))}},{key:"connectedComponentRemoveAtom",value:function(e,t){var n=t||this.atoms.get(e);if(n&&!(n.component<0)){var o=this.connectedComponents.get(n.component);o.delete(e),o.size<1&&this.connectedComponents.delete(n.component),n.component=-1}}},{key:"clearConnectedComponents",value:function(){this.connectedComponents.clear(),this.atoms.forEach((function(e){e.component=-1}))}},{key:"getConnectedComponent",value:function(e,t){for(var n=this,o=Array.isArray(e)?Array.from(e):[e],r=new Re;o.length>0;){var i=o.pop();r.add(i);var a=this.atoms.get(i);a&&(a.component>=0&&t.add(a.component),a.a.neighbors.forEach((function(e){var t=n.molecule.halfBonds.get(e);if(t){var i=t.end;r.has(i)||o.push(i)}})))}return r}},{key:"addConnectedComponent",value:function(e){var t=this,n=this.connectedComponents.add(e),o=new Re,r=this.getConnectedComponent(Array.from(e),o);o.delete(n);var i=-1;return r.forEach((function(e){var o=t.atoms.get(e);o&&(o.component=n,-1!==o.a.rxnFragmentType&&(i=o.a.rxnFragmentType))})),this.ccFragmentType.set(n,i),n}},{key:"removeConnectedComponent",value:function(e){var t=this;return this.connectedComponents.get(e).forEach((function(e){var n=t.atoms.get(e);n&&(n.component=-1)})),this.connectedComponents.delete(e)}},{key:"assignConnectedComponents",value:function(){var e=this;this.atoms.forEach((function(t,n){if(!(t.component>=0)){var o=new Re,r=e.getConnectedComponent(n,o);o.forEach((function(t){e.removeConnectedComponent(t)})),e.addConnectedComponent(r)}}))}},{key:"initLayers",value:function(){for(var e in ei)this.layers[ei[e]]=this.render.paper.rect(0,0,10,10).attr({class:e+"Layer",fill:"#000",opacity:"0.0"}).toFront()}},{key:"addReObjectPath",value:function(e,t,n){var o=this,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];n&&this.layers[e].node.parentNode&&(Array.isArray(n)?n:[n]).forEach((function(n){var a=o.render.options.offset,s=i?nt.fromRelBox(ai.relBox(n.getBBox())):null,u=r&&s?s.translate(r.negated()):null;null!==a&&(n.translateAbs(a.x,a.y),s=s?s.translate(a):null),t.add(n,s,u),n.insertBefore(o.layers[ei[e]])}))}},{key:"clearMarks",value:function(){var t=this;Object.keys(e.maps).forEach((function(e){t[e+"Changed"]=new Map})),this.structChanged=!1}},{key:"markItemRemoved",value:function(){this.structChanged=!0}},{key:"markBond",value:function(e,t){this.markItem("bonds",e,t)}},{key:"markAtom",value:function(e,t){this.markItem("atoms",e,t)}},{key:"markItem",value:function(e,t,n){var o=this[e+"Changed"],r=o.has(t)?Math.max(n,o.get(t)):n;o.set(t,r),this[e].has(t)&&this.clearVisel(this[e].get(t).visel)}},{key:"clearVisel",value:function(e){e.paths.forEach((function(e){e.remove()})),e.clear()}},{key:"eachItem",value:function(t){var n=this;Object.keys(e.maps).forEach((function(e){n[e].forEach(t)}))}},{key:"getSelectionBoxCenter",value:function(e){var t,n,o,r=null,i=Da(null!==(n=e.atoms)&&void 0!==n?n:[]);try{for(i.s();!(o=i.n()).done;){var a=o.value,s=this.atoms.get(a).a.pp,u=new nt(s,s);r=null==r?u:nt.union(r,u)}}catch(e){i.e(e)}finally{i.f()}var l=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Na(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Na(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},e);delete l.atoms;var c=this.getBoundingBoxForSelection(l);return c&&(r=r?nt.union(r,c):c),null===(t=r)||void 0===t?void 0:t.centre()}},{key:"getVBoxObj",value:function(e){Fa(e)&&(e=this.getAllElementsAsSelectionMap());var t=this.getBoundingBoxForSelection(e);return t||new nt(0,0,0,0)}},{key:"getAllElementsAsSelectionMap",value:function(){var t=this,n={};return Object.keys(e.maps).forEach((function(e){n[e]=Array.from(t[e].keys())})),n}},{key:"getBoundingBoxForSelection",value:function(t){var n=this,o=null;return Object.keys(e.maps).forEach((function(e){var r;null===(r=t[e])||void 0===r||r.forEach((function(t){var r=n[e].get(t).getVBoxObj(n.render);r&&(o=o?nt.union(o,r):r.clone())}))})),o}},{key:"translate",value:function(e){this.eachItem((function(t){return t.visel.translate(e)}))}},{key:"scale",value:function(e){this.eachItem((function(t){return function(e,t){for(var n=0;n<e.paths.length;++n)Ha(e.paths[n],t)}(t.visel,e)}))}},{key:"clearVisels",value:function(){var e=this;this.eachItem((function(t){return e.clearVisel(t.visel)}))}},{key:"update",value:function(t){var n=this;t=t||!this.initialized,Object.keys(e.maps).forEach((function(e){var o=n[e+"Changed"];t?n[e].forEach((function(e,t){return o.set(t,1)})):o.forEach((function(t,r){n[e].has(r)||o.delete(r)}))})),this.atomsChanged.forEach((function(e,t){return n.connectedComponentRemoveAtom(t)})),this.frags.filter((function(e,t){return!t.calcBBox(n.render.ctab,e,n.render)})).forEach((function(e,t){n.clearVisel(e.visel),n.frags.delete(t),n.molecule.frags.delete(t)})),Object.keys(e.maps).forEach((function(e){var t=n[e+"Changed"];t.forEach((function(o,r){n[e].get(r).visel&&n.clearVisel(n[e].get(r).visel),n.structChanged=n.structChanged||t.get(r)>0}))})),this.sgroups.forEach((function(e){n.clearVisel(e.visel),e.hovering=null,e.selectionPlate=null})),this.frags.forEach((function(e){n.clearVisel(e.visel)})),this.rgroups.forEach((function(e){n.clearVisel(e.visel)})),t&&(this.clearConnectedComponents(),this.molecule.initHalfBonds(),this.molecule.initNeighbors());var o=Array.from(this.atomsChanged.keys());this.molecule.updateHalfBonds(o),this.molecule.sortNeighbors(o),this.assignConnectedComponents(),this.initialized=!0,this.verifyLoops();var r=t||this.structChanged;return r&&this.updateLoops(),this.showAtoms(),this.showBonds(),this.showRgroupAttachmentPoints(),r&&this.showLoops(),this.showReactionSymbols(),this.showSGroups(),this.showFragments(),this.showRGroups(),this.showEnhancedFlags(),this.showSimpleObjects(),this.showTexts(),this.clearMarks(),!0}},{key:"updateLoops",value:function(){var e=this;this.reloops.forEach((function(t){e.clearVisel(t.visel)}));var t=this.molecule.findLoops();t.bondsToMark.forEach((function(t){e.markBond(t,1)})),t.newLoops.forEach((function(t){e.reloops.set(t,new Sa(e.molecule.loops.get(t)))}))}},{key:"showLoops",value:function(){var e=this,t=this.render.options;this.reloops.forEach((function(n,o){n.show(e,o,t)}))}},{key:"showSimpleObjects",value:function(){var e=this,t=this.render.options;this.simpleObjectsChanged.forEach((function(n,o){var r=e.simpleObjects.get(o);r&&r.show(e,t)}))}},{key:"showTexts",value:function(){var e=this,t=this.render.options;this.textsChanged.forEach((function(n,o){var r=e.texts.get(o);r&&r.show(e,o,t)}))}},{key:"showReactionSymbols",value:function(){var e=this,t=this.render.options;this.rxnArrowsChanged.forEach((function(n,o){var r=e.rxnArrows.get(o);r&&r.show(e,o,t)})),this.rxnPlusesChanged.forEach((function(n,o){var r=e.rxnPluses.get(o);r&&r.show(e,o,t)}))}},{key:"showSGroups",value:function(){var e=this;this.molecule.sGroupForest.getSGroupsBFS().reverse().forEach((function(t){var n=e.sgroups.get(t);n&&n.show(e)}))}},{key:"showFragments",value:function(){var e=this;this.frags.forEach((function(t,n){var o=t.draw(e.render,n);o&&e.addReObjectPath(ei.data,t.visel,o,null,!0)}))}},{key:"showRGroups",value:function(){var e=this,t=this.render.options;this.rgroups.forEach((function(n,o){n.show(e,o,t)}))}},{key:"loopRemove",value:function(e){var t=this,n=this.reloops.get(e);if(n){this.clearVisel(n.visel);var o=[];n.loop.hbs.forEach((function(e){var n=t.molecule.halfBonds.get(e);n&&(n.loop=-1,t.markBond(n.bid,1),t.markAtom(n.begin,1),o.push(n.bid))})),this.reloops.delete(e),this.molecule.loops.delete(e)}}},{key:"verifyLoops",value:function(){var e=this;this.reloops.forEach((function(t,n){t.isValid(e.molecule,n)||e.loopRemove(n)}))}},{key:"getRGroupAttachmentPointsVBoxByAtomIds",value:function(e){var t=this,n=null;return e.forEach((function(e){var o,r=t.molecule.getRGroupAttachmentPointsByAtomId(e).reduce((function(e,n){var o=t.rgroupAttachmentPoints.get(n);f()(null!=o);var r=o.getVBoxObj(t.render);return e&&r?nt.union(e,r):r}),null);n=n&&r?nt.union(n,r):null!==(o=n)&&void 0!==o?o:r})),n}},{key:"showRgroupAttachmentPoints",value:function(){var e=this;this.rgroupAttachmentPoints.forEach((function(t,n){var o=e.rgroupAttachmentPoints.get(n);null!=o&&o.visel&&e.clearVisel(o.visel);var r=null==o?void 0:o.item.atomId,i=e.molecule.getGroupFromAtomId(r);Boolean(null==i?void 0:i.isContracted())||null==o||o.show(e)}))}},{key:"showAtoms",value:function(){var e=this,t=this.render.options;this.atomsChanged.forEach((function(n,o){var r=e.atoms.get(o);r&&r.show(e,o,t)}))}},{key:"showEnhancedFlags",value:function(){var e=this,t=this.render.options;this.enhancedFlagsChanged.forEach((function(n,o){var r=e.enhancedFlags.get(o);r&&r.show(e,o,t)}))}},{key:"showBonds",value:function(){var e=this,t=this.render.options;this.bondsChanged.forEach((function(n,o){var r=e.bonds.get(o);r&&r.show(e,o,t)}))}},{key:"setSelection",value:function(t){var n=this,o=[];Object.keys(e.maps).forEach((function(i){var a=n[i].values(),s=(0,r.A)(a,1)[0];(e.maps[i].isSelectable()||s instanceof ma)&&n[i].forEach((function(e,r){var a,s;if(e instanceof bi){var u,l,c=Da(e.a.sgs.values());try{for(c.s();!(l=c.n()).done;)u=l.value}catch(e){c.e(e)}finally{c.f()}o.push({selected:e.selected,sgroup:u})}if(e instanceof ma&&gt.isContractedFunctionalGroup(null==e||null===(a=e.item)||void 0===a?void 0:a.id,n.molecule.functionalGroups)){var d=o.filter((function(t){var n;return t.sgroup===(null==e||null===(n=e.item)||void 0===n?void 0:n.id)}));e.selected=d.length>0&&d[0].selected}var h=null!=t&&t[i]?t[i].indexOf(r)>-1:e.selected;null===t&&(h=!1),n.showItemSelection(e,h),null===(s=e.selectionPlate)||void 0===s||s.toBack()}))}))}},{key:"showItemSelection",value:function(e,t){var n=function(e){var t,n,o,r;return e&&null!==e.selectionPlate&&(!(null!==(t=e.selectionPlate)&&void 0!==t&&t.items)&&!(null!==(n=e.selectionPlate)&&void 0!==n&&n.removed)||Array.isArray(null===(o=e.selectionPlate)||void 0===o?void 0:o.items)&&!(null!==(r=e.selectionPlate[0])&&void 0!==r&&r.removed))}(e);if(e.selected=t,e instanceof ca&&(e.sgroup.selected=t),t){if(!n){var o=this.render,r=o.options,i=o.paper;e.selectionPlate=e.makeSelectionPlate(this,i,r),this.addReObjectPath(ei.selectionPlate,e.visel,e.selectionPlate),"function"==typeof e.makeAdditionalInfo&&(e.additionalInfo=e.makeAdditionalInfo(this),this.addReObjectPath(ei.additionalInfo,e.visel,e.additionalInfo))}var a,s;e.selectionPlate&&(e.selectionPlate.show(),null===(a=e.additionalInfo)||void 0===a||a.show(),null===(s=e.cip)||void 0===s||s.rectangle.attr({fill:"#7f7",stroke:"#7f7"}),e.togglePoints&&e.togglePoints(!0))}else if(n&&e.selectionPlate){var u,l;e.selectionPlate.hide(),e.togglePoints&&e.togglePoints(!1),null===(u=e.additionalInfo)||void 0===u||u.hide(),null===(l=e.cip)||void 0===l||l.rectangle.attr({fill:"#fff",stroke:"#fff"})}}},{key:"addSnappingBonds",value:function(e){this.snappingBonds.push(e)}},{key:"clearSnappingBonds",value:function(){this.snappingBonds=[]}},{key:"isSnappingBond",value:function(e){return this.snappingBonds.includes(e)}}]),e}();function Fa(e){return!e||!Object.keys(_a.maps).some((function(t){return e[t]&&e[t].length>0}))}function Ha(e,t){if("set"===e.type)for(var n=0;n<e.length;++n)Ha(e[n],t);else void 0!==e.attrs&&("font-size"in e.attrs?e.attr("font-size",e.attrs["font-size"]*t):"stroke-width"in e.attrs&&e.attr("stroke-width",e.attrs["stroke-width"]*t)),e.scale(t,t,0,0)}(0,d.A)(_a,"maps",{atoms:bi,bonds:Ti,rxnPluses:sa,rxnArrows:oa,frags:qi,rgroups:Zi,rgroupAttachmentPoints:Ca,sgroupData:ca,enhancedFlags:Vi,sgroups:ma,reloops:Sa,simpleObjects:Aa,texts:Ra});var ja=Math.PI/12;function Ga(e,t){var n=we.diff(t,e);return Math.atan2(n.y,n.x)}function za(e,t){return t&&(e=Ga(e,t)),Math.round(e/ja)*ja}function Va(e){var t=Math.round(e/Math.PI*180);return t>180?t-=360:t<=-180&&(t+=360),t}var Ua={calcAngle:Ga,fracAngle:za,degrees:Va,setFracAngle:function(e){ja=Math.PI/180*e},mergeBondsParams:function(e,t,n,o){var r=e.atoms.get(t.begin),i=n.atoms.get(o.begin),a=e.atoms.get(t.end),s=n.atoms.get(o.end),u=Ga(r.pp,a.pp)-Ga(i.pp,s.pp),l=Math.abs(Va(u)%180),c=we.dist(r.pp,a.pp)/we.dist(i.pp,s.pp);return{merged:!(0,x.inRange)(l,10,170)&&(0,x.inRange)(c,.8,1.2),angle:u,scale:c,cross:Math.abs(Va(u))>90}},calcNewAtomPos:function(e,t,n){var o=new we(1,0).rotate(n?Ga(e,t):za(e,t));return o.add_(e),o}},Wa=function(e,t){var n=new we(t.viewBox.minX,t.viewBox.minY);return e.sub(n).scaled(t.options.zoom)},qa=function(e,t){var n=new we(t.viewBox.minX,t.viewBox.minY);return e.scaled(1/t.options.zoom).add(n)},Ya=function(e,t){var n=function(e,t){var n=t.getBoundingClientRect(),o=n.top,r=n.left;return new we(e.clientX-r,e.clientY-o)}(e,t.clientArea);return qa(n,t)},$a={modelToView:function(e,t){var n=Ze.modelToCanvas(e,t.options);return Wa(n,t)},canvasToView:Wa,viewToCanvas:qa,pageToCanvas:Ya,pageToModel:function(e,t){var n=Ya(e,t);return Ze.canvasToModel(n,t.options)}};function Xa(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}var Ka=new WeakMap,Za=new WeakSet,Qa=function(){function e(t){var n;(0,i.A)(this,e),Xa(this,n=Za),n.add(this),function(e,t,n){Xa(e,t),t.set(e,{writable:!0,value:void 0})}(this,Ka),(0,d.A)(this,"up",0),(0,d.A)(this,"down",0),(0,d.A)(this,"left",0),(0,d.A)(this,"right",0),(0,A.A)(this,Ka,t)}return(0,a.A)(e,[{key:"getAbsViewBox",value:function(){var e=(0,w.A)(this,Ka).viewBox,t=new we(e.minX,e.minY),n=new we(e.minX+e.width,e.minY+e.height);return new nt(t,n)}},{key:"getAbsBoundingBox",value:function(){var e=(0,w.A)(this,Ka).ctab.getVBoxObj(),t=Ze.modelToCanvas(e.p0,(0,w.A)(this,Ka).options),n=Ze.modelToCanvas(e.p1,(0,w.A)(this,Ka).options);return new nt(t,n)}},{key:"update",value:function(){(function(e,t,n){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return n})(this,Za,Ja).call(this)}},{key:"hasVerticalOffset",value:function(){return this.up>0||this.down>0}},{key:"hasHorizontalOffset",value:function(){return this.left>0||this.right>0}}]),e}();function Ja(){var e=this.getAbsBoundingBox();if(e.hasZeroArea())this.up=0,this.down=0,this.left=0,this.right=0;else{var t=this.getAbsViewBox();this.up=t.p0.y-e.p0.y,this.down=e.p1.y-t.p1.y,this.left=t.p0.x-e.p0.x,this.right=e.p1.x-t.p1.x}}function es(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}var ts=function(){function e(t){(0,i.A)(this,e),(0,d.A)(this,"bar",null),(0,d.A)(this,"viewBoxBeforeDrag",null),(0,d.A)(this,"MIN_LENGTH",40),(0,d.A)(this,"RADIUS",2),(0,d.A)(this,"MARGIN",5),(0,d.A)(this,"WIDTH",4),(0,d.A)(this,"DIST_TO_EDGE",5),(0,d.A)(this,"COLOR","#b2bbc3"),this.render=t}return(0,a.A)(e,[{key:"update",value:function(){this.bar=this.hasOffset()?this.redraw():this.hide()}},{key:"redraw",value:function(){return this.bar?this.updateAttr():this.draw()}},{key:"updateAttr",value:function(){var e,t=this.getDynamicAttr();return null===(e=this.bar)||void 0===e?void 0:e.attr(t)}},{key:"hide",value:function(){var e,t;return null===(e=this.bar)||void 0===e||e.undrag(),null===(t=this.bar)||void 0===t||t.remove(),null}},{key:"draw",value:function(){var e=this.getDynamicAttr(),t=e.x,n=e.y,o=e.width,r=e.height,i=e.r,a=this.render.paper.rect(t,n,o,r,i).attr({stroke:this.COLOR,fill:this.COLOR});return a.drag(this.onDragMove,this.onDragStart,this.onDragEnd,this,this,this),a}},{key:"onDragStart",value:function(e,t,n){this.viewBoxBeforeDrag=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?es(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):es(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},this.render.viewBox),n.stopPropagation()}},{key:"onDragEnd",value:function(e){e.stopPropagation()}}]),e}(),ns=function(e){return.5*e},os=function(e){return e/.5},rs=function(e,t){return e/t.zoom};function is(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function as(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?is(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):is(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function ss(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,us()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function us(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(us=function(){return!!e})()}var ls=new WeakMap,cs=function(e){function t(e,n){var o,r,a,s;return(0,i.A)(this,t),o=ss(this,t,[e]),r=(0,l.A)(o),s={writable:!0,value:void 0},function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(r,a=ls),a.set(r,s),(0,A.A)((0,l.A)(o),ls,n),o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"hasOffset",value:function(){return(0,w.A)(this,ls).hasVerticalOffset()}},{key:"getDynamicAttr",value:function(){var e=this.render.viewBox.minX+this.render.viewBox.width-rs(this.DIST_TO_EDGE,this.render.options),t=this.render.viewBox.minY+(0,x.clamp)(ns((0,w.A)(this,ls).up),rs(this.MARGIN,this.render.options),this.render.viewBox.height-rs(this.MIN_LENGTH+this.MARGIN,this.render.options)),n=this.render.viewBox.minY+this.render.viewBox.height-(0,x.clamp)(ns((0,w.A)(this,ls).down),rs(this.MARGIN,this.render.options),this.render.viewBox.height),o=Math.max(n-t,rs(this.MIN_LENGTH,this.render.options));return{x:e,y:t,width:rs(this.WIDTH,this.render.options),height:o,r:rs(this.RADIUS,this.render.options)}}},{key:"onDragMove",value:function(e,t,n,o,r){this.viewBoxBeforeDrag&&this.render.setViewBox(as(as({},this.viewBoxBeforeDrag),{},{minY:this.viewBoxBeforeDrag.minY+os(t)}))}}]),t}(ts);function ds(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function hs(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ds(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ds(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function fs(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,ms()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function ms(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(ms=function(){return!!e})()}var ps=new WeakMap,vs=function(e){function t(e,n){var o,r,a,s;return(0,i.A)(this,t),o=fs(this,t,[e]),r=(0,l.A)(o),s={writable:!0,value:void 0},function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(r,a=ps),a.set(r,s),(0,A.A)((0,l.A)(o),ps,n),o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"hasOffset",value:function(){return(0,w.A)(this,ps).hasHorizontalOffset()}},{key:"getDynamicAttr",value:function(){var e=this.render.viewBox.minX+(0,x.clamp)(ns((0,w.A)(this,ps).left),rs(this.MARGIN,this.render.options),this.render.viewBox.width-rs(this.MIN_LENGTH+this.MARGIN,this.render.options)),t=this.render.viewBox.minY+this.render.viewBox.height-rs(this.DIST_TO_EDGE,this.render.options),n=this.render.viewBox.minX+this.render.viewBox.width-(0,x.clamp)(ns((0,w.A)(this,ps).right),rs(this.MARGIN,this.render.options),this.render.viewBox.width);return{x:e,y:t,width:Math.max(n-e,rs(this.MIN_LENGTH,this.render.options)),height:rs(this.WIDTH,this.render.options),r:rs(this.RADIUS,this.render.options)}}},{key:"onDragMove",value:function(e,t,n,o,r){this.viewBoxBeforeDrag&&this.render.setViewBox(hs(hs({},this.viewBoxBeforeDrag),{},{minX:this.viewBoxBeforeDrag.minX+os(e)}))}}]),t}(ts);function gs(e,t,n){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.set(e,n)}var ys=new WeakMap,bs=new WeakMap,As=new WeakMap,ws=function(){function e(t){(0,i.A)(this,e),gs(this,ys,{writable:!0,value:void 0}),gs(this,bs,{writable:!0,value:null}),gs(this,As,{writable:!0,value:null}),(0,A.A)(this,ys,new Qa(t)),(0,A.A)(this,bs,new cs(t,(0,w.A)(this,ys))),(0,A.A)(this,As,new vs(t,(0,w.A)(this,ys)))}return(0,a.A)(e,[{key:"update",value:function(){var e,t;(0,w.A)(this,ys).update(),null===(e=(0,w.A)(this,bs))||void 0===e||e.update(),null===(t=(0,w.A)(this,As))||void 0===t||t.update()}}]),e}();function Es(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Ps(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Es(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Es(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var xs=function(){function e(t,o,r){var a,s,u=this;(0,i.A)(this,e),(0,d.A)(this,"skipRaphaelInitialization",!1),(0,d.A)(this,"oldCb",null),(0,d.A)(this,"resizeObserver",null),(0,d.A)(this,"observeCanvasResize",(function(){u.resizeObserver=new ResizeObserver((function(){u.sz=new we(u.clientArea.clientWidth,u.clientArea.clientHeight),u.resizeViewBox()})),u.resizeObserver.observe(u.paper.canvas)})),(0,d.A)(this,"unobserveCanvasResize",(function(){var e;null===(e=u.resizeObserver)||void 0===e||e.unobserve(u.paper.canvas)})),this.userOpts=o,this.clientArea=t,this.paper=new(k())(t,o.width||"100%",o.height||"100%"),this.sz=this.getCanvasSizeVector(),this.options=function(e){var t=e.microModeScale||100,n=e.macroModeScale||200;e.rotationStep&&Ua.setFracAngle(e.rotationStep);var o=Math.ceil(t/6*1.9),r=Math.ceil(.5*o),i={"dearomatize-on-load":!1,ignoreChiralFlag:!1,disableQueryElements:null,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:hi.TerminalAndHetero,showValence:!0,aromaticCircle:!0,microModeScale:t,macroModeScale:n,zoom:1,offset:new we,lineWidth:t/20,bondSpace:e.doubleBondWidth||t/7,stereoBond:e.stereoBondWidth||t/7,subFontSize:r,font:"30px Arial",fontsz:o,fontszsub:r,fontRLabel:1.2*o,fontRLogic:.7*o,radiusScaleFactor:.38,lineattr:{stroke:"#000","stroke-width":e.bondThickness||t/20,"stroke-linecap":"round","stroke-linejoin":"round"},arrowSnappingStyle:{fill:"#365CFF",stroke:"#365CFF"},bondSnappingStyle:{fill:"#365CFF",stroke:"#365CFF","stroke-width":1.5*e.bondThickness},selectionStyle:{fill:"#57FF8F",stroke:"#57FF8F"},hoverStyle:{stroke:"#0097A8",fill:"#CCFFDD","stroke-width":.6*t/20},sgroupBracketStyle:{stroke:"darkgray","stroke-width":.5*t/20},lassoStyle:{stroke:"gray","stroke-width":"1px"},selectionStyleSimpleObject:{stroke:"#57FF8F","stroke-width":t/4,"stroke-linecap":"round"},movingStyle:{cursor:"all-scroll"},atomSelectionPlateRadius:o,contractedFunctionalGroupSize:50,previewOpacity:.5};return Object.assign({},i,e)}(this.userOpts),r&&null!==(a=n.g.ketcher)&&void 0!==a&&null!==(a=a.editor)&&void 0!==a&&null!==(a=a.render)&&void 0!==a&&a.ctab?(this.ctab=null===(s=n.g.ketcher)||void 0===s||null===(s=s.editor)||void 0===s||null===(s=s.render)||void 0===s?void 0:s.ctab,this.ctab.render=this,this.ctab.initLayers(),this.ctab.update(!0)):this.ctab=new _a(new Yt,this),this.scrollbar=new ws(this),this.setViewBox({minX:0,minY:0,width:this.sz.x,height:this.sz.y})}return(0,a.A)(e,[{key:"updateOptions",value:function(e){try{var t=JSON.parse(e);if(t&&"object"===(0,g.A)(t))return this.options=Ps(Ps({},this.options),t),this.options}catch(e){q.error("raphaelRenderer.ts::updateOptions",e)}return!1}},{key:"selectionPolygon",value:function(e){return mi.selectionPolygon(this.paper,e,this.options)}},{key:"selectionLine",value:function(e,t){return mi.selectionLine(this.paper,e,t,this.options)}},{key:"selectionRectangle",value:function(e,t){return mi.selectionRectangle(this.paper,e,t,this.options)}},{key:"page2obj",value:function(e){return $a.pageToModel(e,this)}},{key:"setZoom",value:function(e,t){var n=this.sz.x/e,o=this.sz.y/e,i=t?this.zoomOnMouse(t,n,o):this.zoomOnCanvasCenter(n,o),a=(0,r.A)(i,2),s=a[0],u=a[1];this.setViewBox({minX:s,minY:u,width:n,height:o}),this.options.zoom=e}},{key:"getCanvasSizeVector",value:function(){return new we(this.clientArea.clientWidth,this.clientArea.clientHeight)}},{key:"resizeViewBox",value:function(){this.sz=this.getCanvasSizeVector();var e=this.sz.x/this.options.zoom,t=this.sz.y/this.options.zoom;this.setViewBox((function(n){return Ps(Ps({},n),{},{width:e,height:t})}))}},{key:"zoomOnCanvasCenter",value:function(e,t){var n=new we(this.viewBox.minX+this.viewBox.width/2,this.viewBox.minY+this.viewBox.height/2);return[n.x-e/2,n.y-t/2]}},{key:"zoomOnMouse",value:function(e,t,n){var o=$a.pageToCanvas(e,this),r=(o.x-this.viewBox.minX)/this.viewBox.width,i=(o.y-this.viewBox.minY)/this.viewBox.height;return[o.x-t*r,o.y-n*i]}},{key:"setViewBox",value:function(e){var t="function"==typeof e?e(this.viewBox):e;this.viewBox=t,this.paper.canvas.setAttribute("viewBox","".concat(t.minX," ").concat(t.minY," ").concat(t.width," ").concat(t.height)),this.scrollbar.update()}},{key:"setMolecule",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.paper.clear(),this.ctab=new _a(e,this),this.options.offset=new we,n?setTimeout((function(){t.update(!0)}),0):this.update(!1)}},{key:"update",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;t=t||new we(this.clientArea.clientWidth||100,this.clientArea.clientHeight||100);var n=this.ctab.update(e);if(this.ctab.setSelection(),n){var o=this.ctab.getVBoxObj().transform(Ze.modelToCanvas,this.options).translate(this.options.offset||new we);if(this.options.downScale&&this.ctab.molecule.rescale(),this.options.autoScale||this.options.downScale){var r=o.sz(),i=this.options.autoScaleMargin,a=new we(i,i),s=t;if(i&&(s.x<2*i+1||s.y<2*i+1))throw new Error("View box too small for the given margin");var u=this.options.rescaleAmount||Math.max(r.x/(s.x-2*i),r.y/(s.y-2*i)),l=this.options.downScale&&u<1;(this.options.maxBondLength/u>1||l)&&(u=1);var c=r.add(a.scaled(2*u));this.paper.setViewBox(o.pos().x-i*u-(s.x*u-c.x)/2,o.pos().y-i*u-(s.y*u-c.y)/2,s.x*u,s.y*u)}else this.oldCb||(this.oldCb=new nt),this.scrollbar.update(),this.options.offset=this.options.offset||new we;on()}}}]),e}();function Ss(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}var Os,ks=new Map,Ms=/^R[1-8]$/,Rs=function(){function e(){(0,i.A)(this,e)}return(0,a.A)(e,null,[{key:"prepareStruct",value:function(e){if(e.sgroups.size>0){var t=e.clone();return function(e){e.sgroups.forEach((function(t){t.getAttachmentPoints().forEach((function(t){e.atoms.get(t.atomId).setRGAttachmentPointForDisplayPurpose();var n=t.convertToRGroupAttachmentPointForDisplayPurpose(t.atomId);e.rgroupAttachmentPoints.add(n)}))}))}(t),t.sgroups.delete(0),t}return e}},{key:"removeSmallAttachmentPointLabelsInModal",value:function(e){(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).labelInMonomerConnectionsModal&&e.ctab.atoms.forEach((function(e){e.label&&Ms.test(e.label.text)&&e.label.path.node.getBoundingClientRect().width<8&&e.label.path.node.remove()}))}},{key:"render",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e&&t){var o=n.cachePrefix,r=void 0===o?"":o,i=n.needCache,a=void 0===i||i,s="".concat(r).concat(t.name);if((0,x.isEqual)(Os,n)||(ks.clear(),Os=n),ks.has(s)&&a)return void(e.innerHTML=ks.get(s));var u=this.prepareStruct(t);u.initHalfBonds(),u.initNeighbors(),u.setImplicitHydrogen(),u.markFragments();var l=new xs(e,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ss(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ss(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({autoScale:!0},n));u.rescale(),l.setMolecule(u),this.removeSmallAttachmentPointLabelsInModal(l,n),a&&ks.set(s,l.clientArea.innerHTML)}}}]),e}(),Ts=function(){function e(){(0,i.A)(this,e)}return(0,a.A)(e,null,[{key:"show",value:function(t){e.chainsCollection=t,this.removeEmptyNodes(),this.showNodes(e.chainsCollection),this.showBonds(e.chainsCollection)}},{key:"removeEmptyNodes",value:function(){e.emptySequenceItemRenderers.forEach((function(t){t.remove(),e.emptySequenceItemRenderers=[]}))}},{key:"showNodes",value:function(t){var n,o=t.firstNode,r=o?Oo.getScaledMonomerPosition(o.monomer.position,null===(n=o.monomer.renderer)||void 0===n?void 0:n.monomerSize):new we(41.5,41.5),i=0,a=0,s=zc.provideEditorInstance(),u=s.mode instanceof Ds&&s.mode.isEditMode;u&&t.chains.forEach((function(e){var t=new pr,n=new dr;n.add(t),e.subChains.push(n)})),t.chains.forEach((function(t){i=0,t.subChains.forEach((function(n){n.nodes.forEach((function(o){var s,l=jr.fromNode(o,r,i,i+1+(u?1:0)===t.subChains.reduce((function(e,t){return e+t.nodes.length}),0),n,a===e.caretPosition,o.monomer.renderer);l.show(),null===(s=o.monomer)||void 0===s||s.setRenderer(l),i++,a++,o instanceof pr&&(e.emptySequenceItemRenderers.push(l),o.setRenderer(l))}))})),r=e.getNextChainPosition(r,t)})),this.caretPosition>a&&this.setCaretPosition(a),this.lastChainStartPosition=r}},{key:"getNextChainPosition",value:function(e,t){return new we(e.x,e.y+75+47*Math.floor((t.length-1)/30))}},{key:"showBonds",value:function(e){var t=new Map;e.chains.forEach((function(e){if(e.forEachNode((function(e){var n=e.node,o=e.subChain;n instanceof pr||(t.has(n.monomer)||t.set(n.monomer,new Set),n.monomer.forEachBond((function(e,r){if(!e.isSideChainConnection)return e.setRenderer(new qr(e)),void o.bonds.push(e);var i=t.get(n.monomer);if(!i.has(r)){var a=e.getAnotherMonomer(n.monomer);if(!(n.monomer instanceof eo&&oo(n.monomer)===a||a instanceof eo&&oo(a)===n.monomer)){var s;if(a instanceof Gn){var u=function(e){if(e){var t=e.attachmentPointsToBonds.R1,n=null==t?void 0:t.getAnotherMonomer(e);return n instanceof eo?n:void 0}}(a);s=new Vr(new Xr(n.monomer,u))}else s=new Vr(e);s.show(),e.setRenderer(s),o.bonds.push(e),i.add(r),t.get(a)||t.set(a,new Set),t.get(a).add(null==a?void 0:a.getAttachmentPointByBond(e))}}})))})),e.isCyclic){var n,o=null===(n=e.firstMonomer)||void 0===n?void 0:n.attachmentPointsToBonds.R1,r=new Vr(o,e.firstNode,e.lastNode);r.show(),o.setRenderer(r)}}))}},{key:"setCaretPosition",value:function(t){var n,o,r,i,a=e.currentEdittingNode;a&&(f()(a.renderer instanceof yr),a.renderer.isEditingSymbol=!1,null===(r=a.renderer)||void 0===r||r.remove(),null===(i=a.renderer)||void 0===i||i.show()),e.caretPosition=t;var s=e.currentEdittingNode;s&&(f()(s.renderer instanceof yr),s.renderer.isEditingSymbol=!0,null===(n=s.renderer)||void 0===n||n.remove(),null===(o=s.renderer)||void 0===o||o.show())}},{key:"forEachNode",value:function(e){var t=0;this.chainsCollection.chains.forEach((function(n,o){n.subChains.forEach((function(r,i){r.nodes.forEach((function(a,s){e({chainIndex:o,subChainIndex:i,nodeIndex:s,nodeIndexOverall:t,node:a,subChain:r,chain:n}),t++}))}))}))}},{key:"setCaretPositionBySequenceItemRenderer",value:function(t){var n=-1;e.forEachNode((function(e){var o=e.node,r=e.nodeIndexOverall;o.renderer===t&&(n=r)})),this.setCaretPosition(n)}},{key:"setCaretPositionByMonomer",value:function(t){var n=-1;e.forEachNode((function(e){var o=e.node,r=e.nodeIndexOverall;o.monomer===t&&(n=r)})),this.setCaretPosition(n)}},{key:"getMonomersByCaretPositionRange",value:function(t,n){var o=this,r=[];return e.forEachNode((function(e){var i=e.node,a=e.nodeIndexOverall;t<=a&&a<(n||o.caretPosition)&&r.push(i.monomer)})),r}},{key:"moveCaretForward",value:function(){return new Jr(this.caretPosition,this.nextCaretPosition||this.caretPosition)}},{key:"moveCaretBack",value:function(){return new Jr(this.caretPosition,void 0===this.previousCaretPosition?this.caretPosition:this.previousCaretPosition)}},{key:"hasNewChain",get:function(){return void 0!==e.newChainCaretPosition}},{key:"moveCaretToNewChain",value:function(){this.setCaretPosition(void 0===e.newChainCaretPosition?-1:e.newChainCaretPosition)}},{key:"currentChainIndex",get:function(){var t=this,n=-1;return e.forEachNode((function(e){var o=e.nodeIndexOverall,r=e.chainIndex;o===t.caretPosition&&(n=r)})),n}},{key:"newChainCaretPosition",get:function(){var t=e.lastNodeCaretPosition;if(void 0!==t)return e.getChainByPointer(t).isEmpty?t:void 0}},{key:"lastNodeCaretPosition",get:function(){if(0!==e.chainsCollection.chains.length){var t=-1;return e.forEachNode((function(){t++})),-1===t?void 0:t}}},{key:"getNodeByPointer",value:function(t){var n;if(void 0!==t)return e.forEachNode((function(e){var o=e.node;e.nodeIndexOverall===t&&(n=o)})),n}},{key:"getChainByPointer",value:function(t){var n;return e.forEachNode((function(e){var o=e.chain;e.nodeIndexOverall===t&&(n=o)})),n}},{key:"currentEdittingNode",get:function(){return e.getNodeByPointer(this.caretPosition)}},{key:"previousFromCurrentEdittingMonomer",get:function(){return e.getNodeByPointer(e.previousCaretPosition)}},{key:"currentChain",get:function(){return e.chainsCollection.chains[e.currentChainIndex]}},{key:"previousChain",get:function(){return e.chainsCollection.chains[e.currentChainIndex-1]}},{key:"getLastNonEmptyNode",value:function(e){var t=e.subChains[e.subChains.length-2];return t.nodes[t.nodes.length-1]}},{key:"getLastNode",value:function(e){var t=e.subChains[e.subChains.length-1];return t.nodes[t.nodes.length-1]}},{key:"nextNode",get:function(){return e.getNodeByPointer(e.nextCaretPosition)}},{key:"previousNode",get:function(){return e.getNodeByPointer(e.previousCaretPosition)}},{key:"nextNodeInSameChain",get:function(){if(e.nextCaretPosition===e.caretPosition)return e.getNodeByPointer(e.nextCaretPosition)}},{key:"previousNodeInSameChain",get:function(){return e.getPreviousNodeInSameChain(e.currentEdittingNode)}},{key:"nextCaretPosition",get:function(){return e.getNodeByPointer(this.caretPosition+1)?this.caretPosition+1:void 0}},{key:"previousCaretPosition",get:function(){return e.getNodeByPointer(this.caretPosition-1)?this.caretPosition-1:void 0}},{key:"lastChain",get:function(){return e.chainsCollection.chains[e.chainsCollection.chains.length-1]}},{key:"startNewSequence",value:function(){var t=new Zr,n=new pr,o=new dr;o.add(n),t.subChains.push(o);var r=jr.fromNode(n,this.lastChainStartPosition,0,!1,o,!0);r.show(),n.setRenderer(r),e.emptySequenceItemRenderers.push(r),e.chainsCollection.chains.push(t)}},{key:"getPreviousNodeInSameChain",value:function(t){var n,o,r=-1;return e.forEachNode((function(e){var i=e.node,a=e.chainIndex;t===i&&a===r&&(o=n),r=a,n=i})),o}},{key:"getNextNodeInSameChain",value:function(t){var n,o,r=-1;return e.forEachNode((function(e){var i=e.node,a=e.chainIndex;t===n&&a===r&&(o=i),r=a,n=i})),o}},{key:"getPreviousNode",value:function(t){var n,o;return e.forEachNode((function(e){var r=e.node;t===r&&(o=n),n=r})),o}},{key:"getNextNode",value:function(t){var n,o;return e.forEachNode((function(e){var r=e.node;n===t&&(o=r),n=r})),o}},{key:"shiftArrowSelectionInEditMode",value:function(t){var n=zc.provideEditorInstance(),o=function(e){var t=n.drawingEntitiesManager.getAllSelectedEntities(e.monomer);return n.drawingEntitiesManager.addDrawingEntitiesToSelection(t)},r=new Zo,i=t.code;if("ArrowRight"===i)o(this.currentEdittingNode).addOperation(this.moveCaretForward());else if("ArrowLeft"===i){var a;this.previousNodeInSameChain?a=o(this.previousNodeInSameChain):e.previousChain&&(a=o(e.getLastNode(e.previousChain))),a.addOperation(this.moveCaretBack())}n.renderersContainer.update(r)}},{key:"unselectEmptySequenceNodes",value:function(){var t=new Zo,n=zc.provideEditorInstance();return e.forEachNode((function(e){var o=e.node;o instanceof pr&&t.merge(n.drawingEntitiesManager.unselectDrawingEntity(o.monomer))})),t}},{key:"selections",get:function(){var t,n=[],o=-1;return e.forEachNode((function(e){var r,i=e.node,a=e.nodeIndexOverall;i.monomer.selected&&(null!==(r=t)&&void 0!==r&&r.monomer.selected||(o=n.push([])-1),n[o].push({node:i,nodeIndexOverall:a})),t=i})),n}}]),e}();function Bs(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Cs()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Cs(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Cs=function(){return!!e})()}(0,d.A)(Ts,"caretPosition",-1),(0,d.A)(Ts,"emptySequenceItemRenderers",[]);var Is,Ns=(0,x.uniq)([].concat((0,o.A)(Cr),(0,o.A)(Ir)));!function(e){e.Left="left",e.Right="right"}(Is||(Is={}));var Ds=function(e){function t(e){var n;return(0,i.A)(this,t),n=Bs(this,t,["sequence-layout-mode",e]),(0,d.A)((0,l.A)(n),"_isEditMode",!1),(0,d.A)((0,l.A)(n),"selectionStarted",!1),(0,d.A)((0,l.A)(n),"selectionStartCaretPosition",-1),n}var n;return(0,c.A)(t,e),(0,a.A)(t,[{key:"isEditMode",get:function(){return this._isEditMode},set:function(e){this._isEditMode=e}},{key:"initialize",value:function(){var e,n=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],o=(0,E.A)((0,u.A)(t.prototype),"initialize",this).call(this),r=zc.provideEditorInstance();r.drawingEntitiesManager.clearCanvas();var i=r.drawingEntitiesManager.reArrangeChains(r.canvas.width.baseVal.value,!0,!1),a=an.instance;r.renderersContainer.update(i);var s=null===(e=r.drawingEntitiesManager.applyMonomersSequenceLayout().firstNode)||void 0===e||null===(e=e.monomer.renderer)||void 0===e?void 0:e.scaledMonomerPosition;return s&&n&&a.scrollTo(s),i.merge(o),i}},{key:"turnOnEditMode",value:function(e){var t=zc.provideEditorInstance();this.isEditMode=!0,this.initialize(!1),e&&(Ts.setCaretPositionByMonomer(e.node.monomer),Ts.moveCaretForward()),t.events.toggleSequenceEditMode.dispatch(!0)}},{key:"turnOffEditMode",value:function(){if(this.isEditMode){var e=zc.provideEditorInstance();this.isEditMode=!1,this.initialize(!1),e.events.toggleSequenceEditMode.dispatch(!1)}}},{key:"onKeyDown",value:(n=(0,m.A)(v().mark((function e(t){var n=this;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isEditMode){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,new Promise((function(e){setTimeout((function(){var o,r=ve(n.keyboardEventHandlers),i=me.lookup(r,t),a=zc.provideEditorInstance();null===(o=n.keyboardEventHandlers[i])||void 0===o||o.handler(t),a.events.mouseLeaveSequenceItem.dispatch(),e()}),0)}));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"startNewSequence",value:function(){this.isEditMode||this.turnOnEditMode(),Ts.hasNewChain||Ts.startNewSequence(),Ts.moveCaretToNewChain()}},{key:"click",value:function(e){var t,n=null===(t=e.target)||void 0===t?void 0:t.__data__,o=n instanceof yr;!(n instanceof un)&&this.turnOffEditMode(),this.isEditMode&&o&&(Ts.setCaretPositionBySequenceItemRenderer(n),this.unselectAllEntities())}},{key:"mousedown",value:function(e){var t,n=null===(t=e.target)||void 0===t?void 0:t.__data__,o=n instanceof yr;this.isEditMode&&o&&!e.shiftKey&&(Ts.setCaretPositionBySequenceItemRenderer(n),this.unselectAllEntities(),this.selectionStarted=!0,this.selectionStartCaretPosition=Ts.caretPosition)}},{key:"mousemove",value:function(e){var t,n=null===(t=e.target)||void 0===t?void 0:t.__data__,o=n instanceof yr;if(this.isEditMode&&o&&this.selectionStarted){var r=new Zo,i=zc.provideEditorInstance();Ts.setCaretPositionBySequenceItemRenderer(n);var a=this.selectionStartCaretPosition,s=Ts.caretPosition;this.selectionStartCaretPosition>Ts.caretPosition&&(a=Ts.caretPosition,s=this.selectionStartCaretPosition);var u=Ts.getMonomersByCaretPositionRange(a,s).reduce((function(e,t){return e.concat(i.drawingEntitiesManager.getAllSelectedEntities(t))}),[]);r.merge(i.drawingEntitiesManager.selectDrawingEntities(u));var l=new Jr(this.selectionStartCaretPosition,Ts.caretPosition);r.addOperation(l),i.renderersContainer.update(r)}}},{key:"mouseup",value:function(){this.selectionStarted&&(this.selectionStarted=!1)}},{key:"bondNodesThroughNewPhosphate",value:function(e,t,n){var o=zc.provideEditorInstance(),r=Nr(o,Tr.PHOSPHATE);f()(r);var i=o.drawingEntitiesManager.addMonomer(r,e),a=i.operations[0].monomer;return i.merge(o.drawingEntitiesManager.createPolymerBond(t.lastMonomerInNode,a,dn.R2,dn.R1)),i.merge(o.drawingEntitiesManager.createPolymerBond(a,n.firstMonomerInNode,dn.R2,dn.R1)),i}},{key:"handlePeptideNodeAddition",value:function(e,t,n,o){if(Ir.includes(e)){var r=new Zo,i=zc.provideEditorInstance(),a=function(e,t){return e.monomersLibrary.PEPTIDE.find((function(e){return e.props.MonomerName===t}))}(i,e);f()(a);var s=i.drawingEntitiesManager.addMonomer(a,o),u=s.operations[0].monomer;if(r.merge(s),!(t instanceof pr)){if(n){var l=null==n?void 0:n.lastMonomerInNode.attachmentPointsToBonds.R2;f()(l),r.merge(i.drawingEntitiesManager.deletePolymerBond(l))}r.merge(i.drawingEntitiesManager.createPolymerBond(u,null==t?void 0:t.firstMonomerInNode,dn.R2,dn.R1))}return n&&r.merge(i.drawingEntitiesManager.createPolymerBond(n.lastMonomerInNode,u,dn.R2,dn.R1)),r}}},{key:"handleRnaDnaNodeAddition",value:function(e,t,n,o){if(Cr.includes(e)){var r=new Zo,i=zc.provideEditorInstance(),a=t instanceof Lr||t instanceof Vc?Lr.createOnCanvas(e,o):Vc.createOnCanvas(e,o),s=a.modelChanges,u=a.node;if(r.merge(s),!(t instanceof pr)){if(n){var l=null==n?void 0:n.lastMonomerInNode.attachmentPointsToBonds.R2;f()(l),r.merge(i.drawingEntitiesManager.deletePolymerBond(l))}r.merge(i.drawingEntitiesManager.createPolymerBond(u.lastMonomerInNode,null==t?void 0:t.firstMonomerInNode,dn.R2,dn.R1))}return n instanceof Vc?r.merge(this.bondNodesThroughNewPhosphate(o,n,u)):n&&r.merge(i.drawingEntitiesManager.createPolymerBond(n.lastMonomerInNode,u.firstMonomerInNode,dn.R2,dn.R1)),r}}},{key:"finishNodesDeletion",value:function(e,t,n){var o=zc.provideEditorInstance(),r=new _c(o),i=new Jr(t,(0,x.isNumber)(n)?n:Ts.caretPosition);e.addOperation(new Qr),o.renderersContainer.update(e),e.addOperation(i),r.update(e),this.selectionStartCaretPosition=-1}},{key:"handleNodesDeletion",value:function(e){var t=this,n=zc.provideEditorInstance(),o=new Zo;return e.forEach((function(e){var r=e[0].node,i=e[e.length-1].node,a=!1,s=Ts.getPreviousNode(r),u=Ts.getNextNode(i);!Ts.getPreviousNodeInSameChain(r)&&u&&o.merge(n.drawingEntitiesManager.moveMonomer(u.monomer,r.monomer.position)),!s||s instanceof pr||(!(s instanceof Lr)||u instanceof Lr||u instanceof Vc||(o.merge(n.drawingEntitiesManager.deleteMonomer(s.lastMonomerInNode)),a=!0),!u||u instanceof pr||(s instanceof Vc&&(u instanceof Lr||u instanceof Vc)?o.merge(t.bondNodesThroughNewPhosphate(t.getNewSequenceItemPosition(s),s,u)):o.merge(n.drawingEntitiesManager.createPolymerBond(a?s.firstMonomerInNode:s.lastMonomerInNode,u.firstMonomerInNode,dn.R2,dn.R1))))})),o}},{key:"keyboardEventHandlers",get:function(){var e=this,t=function(t){var n,o=zc.provideEditorInstance(),r=t===Is.Left?Ts.previousNode:Ts.getNodeByPointer(Ts.caretPosition),i=t===Is.Left?Ts.previousCaretPosition:Ts.caretPosition,a=Ts.selections,s=new Zo;if(a.length)s.merge(e.deleteSelectedDrawingEntities()),n=a;else{if(!r)return;r.monomers.forEach((function(e){s.merge(o.drawingEntitiesManager.deleteMonomer(e))})),n=[[{node:r,nodeIndexOverall:i}]]}s.merge(e.handleNodesDeletion(n)),e.finishNodesDeletion(s,n[0][0].nodeIndexOverall,n[0][0].nodeIndexOverall),0===Ts.caretPosition&&0===Ts.chainsCollection.chains.length&&e.startNewSequence()};return{delete:{shortcut:["Delete"],handler:function(){return t(Is.Right)}},backspace:{shortcut:["Backspace"],handler:function(){return t(Is.Left)}},"turn-off-edit-mode":{shortcut:["Escape"],handler:function(){e.turnOffEditMode()}},"start-new-sequence":{shortcut:["Enter"],handler:function(){e.unselectAllEntities(),e.startNewSequence()}},"move-caret-forward":{shortcut:["ArrowRight"],handler:function(){Ts.moveCaretForward()}},"move-caret-back":{shortcut:["ArrowLeft"],handler:function(){Ts.moveCaretBack()}},"add-sequence-item":{shortcut:[].concat((0,o.A)(Ns),(0,o.A)(Ns.map((function(e){return e.toLowerCase()})))),handler:function(t){var n=Ts.selections;if(!(n.length>1)){if(1===n.length){var o=e.deleteSelectedDrawingEntities();o.merge(e.handleNodesDeletion(n)),e.finishNodesDeletion(o,Ts.caretPosition,n[0][0].nodeIndexOverall)}var r,i=t.code.replace("Key",""),a=zc.provideEditorInstance(),s=new _c(a),u=Ts.currentEdittingNode,l=Ts.previousFromCurrentEdittingMonomer,c=l?Ts.getPreviousNodeInSameChain(l):void 0,d=Ts.previousNodeInSameChain,h=e.getNewSequenceItemPosition(l,c);(r=a.sequenceTypeEnterMode===jc.PEPTIDE?e.handlePeptideNodeAddition(i,u,d,h):e.handleRnaDnaNodeAddition(i,u,d,h))&&(r.addOperation(new Qr),a.renderersContainer.update(r),r.addOperation(Ts.moveCaretForward()),s.update(r))}}},"sequence-edit-select":{shortcut:["Shift+ArrowLeft","Shift+ArrowRight"],handler:function(t){var n=t.key;0===Ts.caretPosition&&"ArrowLeft"===n||(e.selectionStartCaretPosition=-1!==e.selectionStartCaretPosition?e.selectionStartCaretPosition:Ts.caretPosition,Ts.shiftArrowSelectionInEditMode(t))}}}}},{key:"deleteSelectedDrawingEntities",value:function(){var e=zc.provideEditorInstance(),t=new Zo;return e.drawingEntitiesManager.selectedEntities.forEach((function(n){var o=(0,r.A)(n,2)[1];t.merge(e.drawingEntitiesManager.deleteDrawingEntity(o))})),t}},{key:"getNewSequenceItemPosition",value:function(e,t){var n=new we(1,1);return!e||e instanceof pr?t?t.lastMonomerInNode.position.add(n):new we(0,0):e.lastMonomerInNode.position.add(n)}},{key:"unselectAllEntities",value:function(){var e=zc.provideEditorInstance(),t=e.drawingEntitiesManager.unselectAllDrawingEntities();t.merge(Ts.unselectEmptySequenceNodes()),e.renderersContainer.update(t)}},{key:"destroy",value:function(){this.turnOffEditMode()}}]),t}(ir);function Ls(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,_s()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function _s(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(_s=function(){return!!e})()}var Fs=function(e){function t(e){return(0,i.A)(this,t),Ls(this,t,["snake-layout-mode",e])}return(0,c.A)(t,e),(0,a.A)(t,[{key:"initialize",value:function(){var e=(0,E.A)((0,u.A)(t.prototype),"initialize",this).call(this),n=zc.provideEditorInstance(),o=n.drawingEntitiesManager.reArrangeChains(n.canvas.width.baseVal.value,!0);return n.drawingEntitiesManager.applyFlexLayoutMode(),e.merge(o),n.renderersContainer.update(o),e.setUndoOperationReverse(),e}},{key:"onKeyDown",value:function(e){}}]),t}(ir),Hs={"flex-layout-mode":ur,"snake-layout-mode":Fs,"sequence-layout-mode":Ds};function js(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Gs()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Gs(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Gs=function(){return!!e})()}var zs,Vs=15;!function(e){e.Horizontal="Horizontal",e.Vertical="Vertical"}(zs||(zs={}));var Us,Ws=function(e){function t(e){var n;return(0,i.A)(this,t),n=js(this,t,[e]),(0,d.A)((0,l.A)(n),"path",""),(0,d.A)((0,l.A)(n),"previousStateOfIsMonomersOnSameHorisontalLine",!1),n.polymerBond=e,n.polymerBond.setRenderer((0,l.A)(n)),n.editorEvents=vo,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"attachmentPointsForSnakeBond",get:function(){return["R1","R2"]}},{key:"isSnakeBondAvailableForMonomer",value:function(e){return e instanceof Dn||e instanceof Fn||e instanceof eo||e instanceof Kn}},{key:"isSnake",get:function(){var e;if(!this.isSnakeBondAvailableForMonomer(this.polymerBond.firstMonomer)||this.polymerBond.secondMonomer&&!this.isSnakeBondAvailableForMonomer(this.polymerBond.secondMonomer)||this.polymerBond.secondMonomer&&this.polymerBond.firstMonomer.isMonomerTypeDifferentForChaining(this.polymerBond.secondMonomer))return!1;var t=this.polymerBond.firstMonomer.getAttachmentPointByBond(this.polymerBond),n=null===(e=this.polymerBond.secondMonomer)||void 0===e?void 0:e.getAttachmentPointByBond(this.polymerBond),o=this.polymerBond.firstMonomer.getPotentialAttachmentPointByBond(this.polymerBond),r=this.attachmentPointsForSnakeBond.includes(t)&&this.attachmentPointsForSnakeBond.includes(n)||this.attachmentPointsForSnakeBond.includes(o),i=t===n,a=zc.provideEditorInstance();return(null==a?void 0:a.mode)instanceof Fs&&r&&!i}},{key:"rootBBox",get:function(){var e,t=null===(e=this.rootElement)||void 0===e?void 0:e.node();if(t)return t.getBBox()}},{key:"width",get:function(){var e;return(null===(e=this.rootBBox)||void 0===e?void 0:e.width)||0}},{key:"height",get:function(){var e;return(null===(e=this.rootBBox)||void 0===e?void 0:e.height)||0}},{key:"scaledPosition",get:function(){return{startPosition:sn.modelToCanvas(this.polymerBond.startPosition),endPosition:sn.modelToCanvas(this.polymerBond.endPosition)}}},{key:"moveSelection",value:function(){this.previousStateOfIsMonomersOnSameHorisontalLine!==this.isMonomersOnSameHorizontalLine()?(this.remove(),this.show()):(f()(this.rootElement),this.moveStart(),this.moveEnd()),this.previousStateOfIsMonomersOnSameHorisontalLine=this.isMonomersOnSameHorizontalLine()}},{key:"appendBond",value:function(e){return this.isSnake&&!this.isMonomersOnSameHorizontalLine()?this.appendSnakeBond(e):this.appendBondGraph(e),this.bodyElement}},{key:"appendSnakeBond",value:function(e){var t=this.scaledPosition.startPosition,n=this.scaledPosition.endPosition;return this.updateSnakeBondPath(t,n),this.bodyElement=e.append("path").attr("stroke",this.polymerBond.finished?"#333333":"#0097A8").attr("stroke-width",1).attr("class","selection-area").attr("d",this.path).attr("fill-opacity",0).attr("pointer-events","stroke"),this.bodyElement}},{key:"getMonomerWidth",value:function(){var e,t;return null!==(e=null===(t=this.polymerBond.firstMonomer.renderer)||void 0===t?void 0:t.monomerSize.width)&&void 0!==e?e:0}},{key:"getMonomerHeight",value:function(){var e,t;return null!==(e=null===(t=this.polymerBond.firstMonomer.renderer)||void 0===t?void 0:t.monomerSize.height)&&void 0!==e?e:0}},{key:"isMonomersOnSameHorizontalLine",value:function(){return Boolean(this.polymerBond.secondMonomer&&this.polymerBond.firstMonomer.position.y-this.polymerBond.secondMonomer.position.y<.5&&this.polymerBond.firstMonomer.position.y-this.polymerBond.secondMonomer.position.y>-.5)}},{key:"updateSnakeBondPath",value:function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],o="R1"===this.polymerBond.firstMonomer.getAttachmentPointByBond(this.polymerBond)||"R1"===this.polymerBond.firstMonomer.getPotentialAttachmentPointByBond(this.polymerBond),r=this.polymerBond.firstMonomer.isMonomerInRnaChainRow?74:21;if(this.isSecondMonomerBottomRight(e,t)){if(o&&n)return void this.updateSnakeBondPath(t,e,!1);this.addLine(zs.Horizontal,Vs+this.getMonomerWidth()/2,e),this.addLineFromLeftToBottom(),this.addLine(zs.Vertical,t.y-e.y-8),this.addLineFromTopToRight(),this.addLine(zs.Horizontal,t.x-e.x-8-Vs-this.getMonomerWidth()/2)}else if(this.isSecondMonomerTopRight(e,t)){if(o&&n)return void this.updateSnakeBondPath(t,e,!1);this.addLine(zs.Horizontal,Vs+this.getMonomerWidth()/2,e),this.addLineFromLeftToTop(),this.addLine(zs.Vertical,t.y-e.y-8+this.getMonomerHeight()/2),this.addLineFromBottomToRight(),this.addLine(zs.Horizontal,t.x-e.x-8-Vs-this.getMonomerWidth()/2)}else if(this.isSecondMonomerBottomLeft(e,t)){if(o&&n)return void this.updateSnakeBondPath(t,e,!1);this.addLine(zs.Horizontal,Vs+this.getMonomerWidth()/2,e),this.addLineFromLeftToBottom(),this.addLine(zs.Vertical,r),this.addLineFromTopToLeft(),this.addLine(zs.Horizontal,-(e.x-t.x+30+this.getMonomerWidth())),this.addLineFromRightToBottom(),this.addLine(zs.Vertical,t.y-e.y-16-r),this.addLineFromTopToRight(),this.addLine(zs.Horizontal,Vs+this.getMonomerWidth()/2)}else if(this.isSecondMonomerTopLeft(e,t)){if(o&&n)return void this.updateSnakeBondPath(t,e,!1);this.addLine(zs.Horizontal,Vs+this.getMonomerWidth()/2,e),this.addLineFromLeftToBottom(),this.addLine(zs.Vertical,this.getMonomerHeight()),this.addLineFromTopToLeft(),this.addLine(zs.Horizontal,-(e.x-t.x+30+this.getMonomerWidth())),this.addLineFromRightToUp(),this.addLine(zs.Vertical,t.y-e.y-this.getMonomerHeight()),this.addLineFromBottomToRight(),this.addLine(zs.Horizontal,Vs+this.getMonomerWidth()/2)}else if(this.isSecondMonomerLeft(e,t)){if(o&&n)return void this.updateSnakeBondPath(t,e,!1);this.addLine(zs.Horizontal,Vs+this.getMonomerWidth()/2,e),this.addLineFromLeftToBottom(),this.addLine(zs.Vertical,t.y-e.y+this.getMonomerHeight()),this.addLineFromTopToLeft(),this.addLine(zs.Horizontal,-(e.x-t.x+30+this.getMonomerWidth())),this.addLineFromRightToUp(),this.addLine(zs.Vertical,-this.getMonomerHeight()),this.addLineFromBottomToRight(),this.addLine(zs.Horizontal,Vs+this.getMonomerWidth()/2)}else this.addRandomLine(e,t)}},{key:"isSecondMonomerTopRight",value:function(e,t){return e.y-t.y>8&&t.x-e.x>23+this.getMonomerWidth()}},{key:"isSecondMonomerBottomRight",value:function(e,t){return t.y-e.y>8&&t.x-e.x>23+this.getMonomerWidth()}},{key:"isSecondMonomerBottomLeft",value:function(e,t){return t.y-e.y>=58&&t.x-e.x<=23+this.getMonomerWidth()}},{key:"isSecondMonomerTopLeft",value:function(e,t){return e.y-t.y>0&&t.x-e.x<=23+this.getMonomerWidth()}},{key:"isSecondMonomerLeft",value:function(e,t){return e.y-t.y<0&&e.y-t.y>-58&&t.x-e.x<=23+this.getMonomerWidth()}},{key:"addLineFromTopToRight",value:function(){this.path="".concat(this.path," c 0,4.418 3.582,").concat(4," ").concat(4,",").concat(4)}},{key:"addLineFromLeftToTop",value:function(){this.path="".concat(this.path," c 4.418,0 ").concat(4,",-3.582 ").concat(4,",-").concat(4)}},{key:"addLineFromBottomToRight",value:function(){this.path="".concat(this.path," c 0,-4.418 3.582,-").concat(4," ").concat(4,",-").concat(4)}},{key:"addLineFromLeftToBottom",value:function(){this.path="".concat(this.path," c 4.418,0 ").concat(4,",3.582 ").concat(4,",").concat(4)}},{key:"addLineFromTopToLeft",value:function(){this.path="".concat(this.path," c 0,4.418 -3.582,").concat(4," -").concat(4,",").concat(4)}},{key:"addLineFromRightToUp",value:function(){this.path="".concat(this.path," c -4.418,0 -").concat(4,",-3.582 -").concat(4,",-").concat(4)}},{key:"addLineFromRightToBottom",value:function(){this.path="".concat(this.path," c -4.418,0 -").concat(4,",3.582 -").concat(4,",").concat(4)}},{key:"addLine",value:function(e,t,n){var o=n?"M ".concat(Math.round(n.x),",").concat(Math.round(n.y)):this.path,r=e===zs.Horizontal?"l".concat(t,", 0"):"l 0, ".concat(t);this.path="".concat(o," ").concat(r)}},{key:"addRandomLine",value:function(e,t){var n="M ".concat(Math.round(e.x),",").concat(Math.round(e.y)),o="L ".concat(Math.round(t.x),",").concat(Math.round(t.y));this.path="".concat(n," ").concat(o)}},{key:"appendBondGraph",value:function(e){return this.bodyElement=e.append("line").attr("stroke",this.polymerBond.finished?"#333333":"#0097A8").attr("stroke-width",1).attr("class","selection-area").attr("x1",this.scaledPosition.startPosition.x).attr("y1",this.scaledPosition.startPosition.y).attr("x2",this.scaledPosition.endPosition.x).attr("y2",this.scaledPosition.endPosition.y).attr("pointer-events","stroke"),this.bodyElement}},{key:"appendRootElement",value:function(){var e=this;return this.canvas.insert("g",":first-child").data([this]).on("mouseover",(function(t){e.editorEvents.mouseOverPolymerBond.dispatch(t),e.editorEvents.mouseOverDrawingEntity.dispatch(t)})).on("mouseout",(function(t){e.editorEvents.mouseLeavePolymerBond.dispatch(t),e.editorEvents.mouseLeaveDrawingEntity.dispatch(t)})).attr("pointer-events","stroke")}},{key:"show",value:function(){this.rootElement=this.rootElement||this.appendRootElement(),this.appendBond(this.rootElement),this.appendHoverAreaElement(),this.drawSelection()}},{key:"drawSelection",value:function(){var e,t,n,o;this.polymerBond.selected?(null===(e=this.selectionElement)||void 0===e||e.remove(),this.isSnake&&!this.isMonomersOnSameHorizontalLine()?this.selectionElement=null===(t=this.rootElement)||void 0===t?void 0:t.insert("path",":first-child").attr("stroke","#57FF8F").attr("stroke-width",10).attr("fill-opacity",0).attr("d",this.path):this.selectionElement=null===(n=this.rootElement)||void 0===n?void 0:n.insert("line",":first-child").attr("stroke","#57FF8F").attr("x1",this.scaledPosition.startPosition.x).attr("y1",this.scaledPosition.startPosition.y).attr("x2",this.scaledPosition.endPosition.x).attr("y2",this.scaledPosition.endPosition.y).attr("stroke-width","5")):null===(o=this.selectionElement)||void 0===o||o.remove()}},{key:"moveEnd",value:function(){this.isSnake&&!this.isMonomersOnSameHorizontalLine()?this.moveSnakeBondEnd():this.moveGraphBondEnd()}},{key:"moveSnakeBondEnd",value:function(){var e,t=this.scaledPosition.startPosition,n=this.scaledPosition.endPosition;this.updateSnakeBondPath(t,n),f()(this.bodyElement),f()(this.hoverAreaElement),this.bodyElement.attr("d",this.path),this.hoverAreaElement.attr("d",this.path),null===(e=this.selectionElement)||void 0===e||e.attr("d",this.path)}},{key:"moveGraphBondEnd",value:function(){var e;f()(this.bodyElement),f()(this.hoverAreaElement),this.bodyElement.attr("x2",this.scaledPosition.endPosition.x).attr("y2",this.scaledPosition.endPosition.y),this.hoverAreaElement.attr("x2",this.scaledPosition.endPosition.x).attr("y2",this.scaledPosition.endPosition.y),null===(e=this.selectionElement)||void 0===e||null===(e=e.attr("x2",this.scaledPosition.endPosition.x))||void 0===e||e.attr("y2",this.scaledPosition.endPosition.y)}},{key:"moveStart",value:function(){this.isSnake&&!this.isMonomersOnSameHorizontalLine()?this.moveSnakeBondStart():this.moveGraphBondStart()}},{key:"moveSnakeBondStart",value:function(){var e,t=this.scaledPosition.startPosition,n=this.scaledPosition.endPosition;this.updateSnakeBondPath(t,n),f()(this.bodyElement),f()(this.hoverAreaElement),this.bodyElement.attr("d",this.path),this.hoverAreaElement.attr("d",this.path),null===(e=this.selectionElement)||void 0===e||e.attr("d",this.path)}},{key:"moveGraphBondStart",value:function(){var e;f()(this.bodyElement),f()(this.hoverAreaElement),this.bodyElement.attr("x1",this.scaledPosition.startPosition.x).attr("y1",this.scaledPosition.startPosition.y),this.hoverAreaElement.attr("x1",this.scaledPosition.startPosition.x).attr("y1",this.scaledPosition.startPosition.y),null===(e=this.selectionElement)||void 0===e||null===(e=e.attr("x1",this.scaledPosition.startPosition.x))||void 0===e||e.attr("y1",this.scaledPosition.startPosition.y)}},{key:"appendHoverAreaElement",value:function(){var e,t;this.isSnake&&!this.isMonomersOnSameHorizontalLine()?this.hoverAreaElement=null===(e=this.rootElement)||void 0===e?void 0:e.append("path").attr("stroke","transparent").attr("d",this.path).attr("fill-opacity",0).attr("stroke-width","10"):this.hoverAreaElement=null===(t=this.rootElement)||void 0===t?void 0:t.append("line").attr("stroke","transparent").attr("x1",this.scaledPosition.startPosition.x).attr("y1",this.scaledPosition.startPosition.y).attr("x2",this.scaledPosition.endPosition.x).attr("y2",this.scaledPosition.endPosition.y).attr("stroke-width","10")}},{key:"appendHover",value:function(){f()(this.bodyElement),this.bodyElement.attr("stroke","#0097A8").attr("pointer-events","none"),this.polymerBond.selected&&(f()(this.hoverAreaElement),this.hoverAreaElement.attr("stroke","#CCFFDD"))}},{key:"removeHover",value:function(){return f()(this.bodyElement),f()(this.hoverAreaElement),this.bodyElement.attr("stroke","#333333").attr("pointer-events","stroke"),this.hoverAreaElement.attr("stroke","transparent")}}]),t}(un),qs=function(){function e(t){var n=this;(0,i.A)(this,e),(0,d.A)(this,"isBondConnectionModalOpen",!1),(0,d.A)(this,"handleBondCreation",(function(e){f()(n.bondRenderer);var t=e.secondMonomer,o=e.firstSelectedAttachmentPoint,r=e.secondSelectedAttachmentPoint,i=n.editor.drawingEntitiesManager.finishPolymerBondCreation(n.bondRenderer.polymerBond,t,o,r);n.history.update(i),n.editor.renderersContainer.update(i),o===r&&n.editor.events.error.dispatch("You have connected monomers with attachment points of the same group"),n.isBondConnectionModalOpen=!1,n.editor.renderersContainer.deletePolymerBond(n.bondRenderer.polymerBond,!1,!1),n.bondRenderer=void 0})),(0,d.A)(this,"handleBondCreationCancellation",(function(e){if(n.bondRenderer){var t=n.editor.drawingEntitiesManager.cancelPolymerBondCreation(n.bondRenderer.polymerBond,e);n.editor.renderersContainer.update(t),n.isBondConnectionModalOpen=!1,n.bondRenderer=void 0}})),this.editor=t,this.editor=t,this.history=new _c(this.editor)}return(0,a.A)(e,[{key:"mouseDownAttachmentPoint",value:function(e){var t=e.target.__data__;t instanceof Oo&&!t.monomer.isAttachmentPointUsed(e.attachmentPointName)&&t.monomer.setChosenFirstAttachmentPoint(e.attachmentPointName)}},{key:"removeBond",value:function(){if(this.bondRenderer){var e=this.editor.drawingEntitiesManager.cancelPolymerBondCreation(this.bondRenderer.polymerBond);this.editor.renderersContainer.update(e),this.bondRenderer=void 0}}},{key:"mousedown",value:function(e){var t=e.target.__data__;if(t instanceof Oo){if(!t.monomer.startBondAttachmentPoint)return void this.editor.events.error.dispatch("Selected monomer doesn't have any free attachment points");var n=this.editor.drawingEntitiesManager.startPolymerBondCreation(t.monomer,t.monomer.position,sn.canvasToModel(this.editor.lastCursorPositionOfCanvas)),o=n.polymerBond,r=n.command;this.editor.renderersContainer.update(r),this.bondRenderer=o.renderer}}},{key:"mousemove",value:function(){if(this.bondRenderer){var e=this.editor.drawingEntitiesManager.movePolymerBond(this.bondRenderer.polymerBond,sn.canvasToModel(this.editor.lastCursorPositionOfCanvas));this.editor.renderersContainer.update(e)}}},{key:"mouseLeavePolymerBond",value:function(e){var t=e.target.__data__;if(!this.bondRenderer&&t.polymerBond){var n=this.editor.drawingEntitiesManager.hidePolymerBondInformation(t.polymerBond);this.editor.renderersContainer.markForRecalculateBegin(),this.editor.renderersContainer.update(n)}}},{key:"mouseOverPolymerBond",value:function(e){if(!this.bondRenderer){var t=e.target.__data__,n=this.editor.drawingEntitiesManager.showPolymerBondInformation(t.polymerBond);this.editor.renderersContainer.markForRecalculateBegin(),this.editor.renderersContainer.update(n)}}},{key:"mouseOverMonomer",value:function(e){var t,n=e.target.__data__;if(this.bondRenderer){var o,r,i;if((null===(o=this.bondRenderer)||void 0===o?void 0:o.polymerBond.firstMonomer)===n.monomer)return;var a=!this.shouldInvokeModal(null===(r=this.bondRenderer)||void 0===r?void 0:r.polymerBond.firstMonomer,n.monomer,!1);t=this.editor.drawingEntitiesManager.intendToFinishBondCreation(n.monomer,null===(i=this.bondRenderer)||void 0===i?void 0:i.polymerBond,a)}else t=this.editor.drawingEntitiesManager.intendToStartBondCreation(n.monomer);this.editor.renderersContainer.markForRecalculateBegin(),this.editor.renderersContainer.update(t)}},{key:"mouseOverAttachmentPoint",value:function(e){var t,n=e.target.__data__;if(this.bondRenderer){var o,r,i;if((null===(o=this.bondRenderer)||void 0===o?void 0:o.polymerBond.firstMonomer)===n.monomer)return;var a=!this.shouldInvokeModal(null===(r=this.bondRenderer)||void 0===r?void 0:r.polymerBond.firstMonomer,n.monomer,!1);t=this.editor.drawingEntitiesManager.intendToFinishAttachmenPointBondCreation(n.monomer,null===(i=this.bondRenderer)||void 0===i?void 0:i.polymerBond,e.attachmentPointName,a)}else t=this.editor.drawingEntitiesManager.intendToStartAttachmenPointBondCreation(n.monomer,e.attachmentPointName);this.editor.renderersContainer.markForRecalculateBegin(),this.editor.renderersContainer.update(t)}},{key:"mouseLeaveMonomer",value:function(e){var t,n=e.target.__data__;if(n!==(null===(t=this.bondRenderer)||void 0===t||null===(t=t.polymerBond)||void 0===t||null===(t=t.firstMonomer)||void 0===t?void 0:t.renderer)&&!this.isBondConnectionModalOpen){var o,r=this.editor.drawingEntitiesManager.cancelIntentionToFinishBondCreation(n.monomer,null===(o=this.bondRenderer)||void 0===o?void 0:o.polymerBond);this.editor.renderersContainer.markForRecalculateBegin(),this.editor.renderersContainer.update(r)}}},{key:"mouseLeaveAttachmentPoint",value:function(e){var t;if(!this.isBondConnectionModalOpen){var n=e.target.__data__;if(n!==(null===(t=this.bondRenderer)||void 0===t||null===(t=t.polymerBond)||void 0===t||null===(t=t.firstMonomer)||void 0===t?void 0:t.renderer)){var o,r=this.editor.drawingEntitiesManager.cancelIntentionToFinishBondCreation(n.monomer,null===(o=this.bondRenderer)||void 0===o?void 0:o.polymerBond);this.editor.renderersContainer.markForRecalculateBegin(),this.editor.renderersContainer.update(r)}}}},{key:"mouseUpAttachmentPoint",value:function(e){var t,n=e.target.__data__,o=n===(null===(t=this.bondRenderer)||void 0===t||null===(t=t.polymerBond)||void 0===t||null===(t=t.firstMonomer)||void 0===t?void 0:t.renderer);if(this.bondRenderer&&!o){var r,i=null===(r=this.bondRenderer)||void 0===r||null===(r=r.polymerBond)||void 0===r?void 0:r.firstMonomer,a=n.monomer;if(a.isAttachmentPointUsed(e.attachmentPointName))return void this.mouseup();for(var s in a.attachmentPointsToBonds){var u=a.attachmentPointsToBonds[s];if(u&&(u.firstMonomer===i&&u.secondMonomer===a||u.firstMonomer===a&&u.secondMonomer===i))return void this.editor.events.error.dispatch("There can't be more than 1 bond between the first and the second monomer")}if(a.setChosenSecondAttachmentPoint(e.attachmentPointName),this.shouldInvokeModal(i,a))return this.isBondConnectionModalOpen=!0,void this.editor.events.openMonomerConnectionModal.dispatch({firstMonomer:i,secondMonomer:a});var l=this.finishBondCreation(n.monomer);this.history.update(l),this.editor.renderersContainer.update(l),this.editor.renderersContainer.deletePolymerBond(this.bondRenderer.polymerBond,!1,!1),this.bondRenderer=void 0,e.stopPropagation()}}},{key:"finishBondCreation",value:function(e){if(f()(this.bondRenderer),!e.hasFreeAttachmentPoint)return this.editor.events.error.dispatch("Monomers don't have any connection point available"),this.editor.drawingEntitiesManager.cancelPolymerBondCreation(this.bondRenderer.polymerBond);var t=this.bondRenderer.polymerBond.firstMonomer.getPotentialAttachmentPointByBond(this.bondRenderer.polymerBond),n=e.getPotentialAttachmentPointByBond(this.bondRenderer.polymerBond);return f()(t),f()(n),t===n&&this.editor.events.error.dispatch("You have connected monomers with attachment points of the same group"),this.editor.drawingEntitiesManager.finishPolymerBondCreation(this.bondRenderer.polymerBond,e,t,n)}},{key:"mouseup",value:function(){this.isBondConnectionModalOpen||this.removeBond()}},{key:"mouseUpMonomer",value:function(e){var t,n=e.target.__data__,o=n===(null===(t=this.bondRenderer)||void 0===t||null===(t=t.polymerBond)||void 0===t||null===(t=t.firstMonomer)||void 0===t?void 0:t.renderer);if(this.bondRenderer&&!o){var r,i=null===(r=this.bondRenderer)||void 0===r||null===(r=r.polymerBond)||void 0===r?void 0:r.firstMonomer,a=n.monomer;for(var s in a.attachmentPointsToBonds){var u=a.attachmentPointsToBonds[s];if(u&&(u.firstMonomer===i&&u.secondMonomer===a||u.firstMonomer===a&&u.secondMonomer===i))return void this.editor.events.error.dispatch("There can't be more than 1 bond between the first and the second monomer")}if(this.shouldInvokeModal(i,a))return this.isBondConnectionModalOpen=!0,void this.editor.events.openMonomerConnectionModal.dispatch({firstMonomer:i,secondMonomer:a});var l=this.finishBondCreation(n.monomer);this.editor.renderersContainer.update(l),this.editor.renderersContainer.deletePolymerBond(this.bondRenderer.polymerBond,!1,!1),this.bondRenderer=void 0,this.history.update(l),e.stopPropagation()}}},{key:"destroy",value:function(){this.removeBond()}},{key:"shouldInvokeModal",value:function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!t.hasFreeAttachmentPoint)return!1;if(null!==e.chosenFirstAttachmentPointForBond&&null!==t.chosenSecondAttachmentPointForBond)return!1;if(n&&(!e.hasPotentialBonds()||!t.hasPotentialBonds()))return!0;if(1===e.unUsedAttachmentPointsNamesList.length&&1===t.unUsedAttachmentPointsNamesList.length)return!1;if(e instanceof Fn||t instanceof Fn)return!0;var o=[eo,Gn,Kn],r=o.find((function(t){return e instanceof t})),i=o.find((function(e){return t instanceof e}));if(r&&t instanceof Dn||i&&e instanceof Dn)return!0;if(t instanceof Dn&&e instanceof Dn){var a=e.listOfAttachmentPoints.length>2||t.listOfAttachmentPoints.length>2,s=e.unUsedAttachmentPointsNamesList.length>1||t.unUsedAttachmentPointsNamesList.length>1,u=e.isAttachmentPointUsed(dn.R1)&&t.isAttachmentPointUsed(dn.R1),l=e.isAttachmentPointUsed(dn.R2)&&t.isAttachmentPointUsed(dn.R2),c=e.isAttachmentPointUsed(dn.R2)&&e.isAttachmentPointUsed(dn.R1)||t.isAttachmentPointUsed(dn.R2)&&t.isAttachmentPointUsed(dn.R1);if(a&&s&&(u||l||c))return!0}return!1}}]),e}(),Ys="CHEM",$s=function(e){var t,n,o;return e.props.MonomerType===Ys||"RNA"===e.props.MonomerType&&("MODDNA"===e.props.MonomerClass||"DNA"===e.props.MonomerClass)?(t=Fn,n=Bo,o="CHEM"):"PEPTIDE"===e.props.MonomerType?(t=Dn,n=Do,o="AminoAcid"):"R"===e.props.MonomerNaturalAnalogCode?(t=eo,n=Wo,o="Sugar"):"P"===e.props.MonomerNaturalAnalogCode?(t=Kn,n=jo,o="Phosphate"):(t=Gn,n=Ko,o="Base"),[t,n,o]},Xs=function(){function e(t,n){(0,i.A)(this,e),(0,d.A)(this,"MONOMER_PREVIEW_SCALE_FACTOR",.8),(0,d.A)(this,"MONOMER_PREVIEW_OFFSET_X",30),(0,d.A)(this,"MONOMER_PREVIEW_OFFSET_Y",30),this.editor=t,this.monomer=n,this.editor=t,this.monomer=n,this.history=new _c(this.editor)}return(0,a.A)(e,[{key:"mousedown",value:function(){f()(this.monomerPreviewRenderer);var e=sn.canvasToModel(new we(this.editor.lastCursorPositionOfCanvas.x,this.editor.lastCursorPositionOfCanvas.y)),t=this.editor.drawingEntitiesManager.addMonomer(this.monomer,e);this.history.update(t),this.editor.renderersContainer.update(t)}},{key:"mousemove",value:function(){var e,t,n=sn.canvasToModel(new we(this.editor.lastCursorPosition.x+this.MONOMER_PREVIEW_OFFSET_X,this.editor.lastCursorPosition.y+this.MONOMER_PREVIEW_OFFSET_Y));null===(e=this.monomerPreview)||void 0===e||e.moveAbsolute(n),null===(t=this.monomerPreviewRenderer)||void 0===t||t.move()}},{key:"mouseLeaveClientArea",value:function(){this.hidePreview()}},{key:"mouseover",value:function(){if(!this.monomerPreview){var e,t=$s(this.monomer),n=(0,r.A)(t,2),o=n[0],i=n[1];this.monomerPreview=new o(this.monomer),this.monomerPreviewRenderer=new i(this.monomerPreview,this.MONOMER_PREVIEW_SCALE_FACTOR,!1),null===(e=this.monomerPreviewRenderer)||void 0===e||e.show(this.editor.theme)}}},{key:"hidePreview",value:function(){var e;null===(e=this.monomerPreviewRenderer)||void 0===e||e.remove(),this.monomerPreviewRenderer=void 0,this.monomerPreview=void 0}},{key:"destroy",value:function(){this.hidePreview()}}]),e}(),Ks=22.5,Zs=function(){function e(t,n){(0,i.A)(this,e),(0,d.A)(this,"MONOMER_PREVIEW_SCALE_FACTOR",.5),(0,d.A)(this,"MONOMER_PREVIEW_OFFSET_X",30),(0,d.A)(this,"MONOMER_PREVIEW_OFFSET_Y",30),(0,d.A)(this,"RNA_BASE_PREVIEW_OFFSET_X",1),(0,d.A)(this,"RNA_BASE_PREVIEW_OFFSET_Y",20),(0,d.A)(this,"PHOSPHATE_PREVIEW_OFFSET_X",18),this.editor=t,this.editor=t,null!=n&&n.base&&(this.rnaBase=null==n?void 0:n.base),null!=n&&n.phosphate&&(this.phosphate=null==n?void 0:n.phosphate),null!=n&&n.sugar&&(this.sugar=null==n?void 0:n.sugar),this.history=new _c(this.editor)}return(0,a.A)(e,[{key:"mousedown",value:function(){var e;if(this.sugar&&this.sugarPreviewRenderer){var t=this.editor.drawingEntitiesManager.addRnaPreset({sugar:this.sugar,sugarPosition:sn.canvasToModel(new we(this.editor.lastCursorPositionOfCanvas.x,this.editor.lastCursorPositionOfCanvas.y)),phosphate:this.phosphate,phosphatePosition:this.phosphatePreviewRenderer?sn.canvasToModel(new we(this.editor.lastCursorPositionOfCanvas.x+(null===(e=this.sugarPreviewRenderer)||void 0===e?void 0:e.width)+Ks,this.editor.lastCursorPositionOfCanvas.y)):void 0,rnaBase:this.rnaBase,rnaBasePosition:this.rnaBasePreviewRenderer?sn.canvasToModel(new we(this.editor.lastCursorPositionOfCanvas.x,this.editor.lastCursorPositionOfCanvas.y+this.sugarPreviewRenderer.height+Ks)):void 0}).command;this.history.update(t),this.editor.renderersContainer.update(t)}else this.editor.events.error.dispatch("No sugar in RNA preset found")}},{key:"mousemove",value:function(){var e,t,n,o,r,i;null===(e=this.sugarPreview)||void 0===e||e.moveAbsolute(sn.canvasToModel(new we(this.editor.lastCursorPosition.x+this.MONOMER_PREVIEW_OFFSET_X,this.editor.lastCursorPosition.y+this.MONOMER_PREVIEW_OFFSET_Y))),null===(t=this.rnaBasePreview)||void 0===t||t.moveAbsolute(sn.canvasToModel(new we(this.editor.lastCursorPosition.x+this.MONOMER_PREVIEW_OFFSET_X+this.RNA_BASE_PREVIEW_OFFSET_X,this.editor.lastCursorPosition.y+this.MONOMER_PREVIEW_OFFSET_Y+this.RNA_BASE_PREVIEW_OFFSET_Y))),null===(n=this.phosphatePreview)||void 0===n||n.moveAbsolute(sn.canvasToModel(new we(this.editor.lastCursorPosition.x+this.MONOMER_PREVIEW_OFFSET_X+this.PHOSPHATE_PREVIEW_OFFSET_X,this.editor.lastCursorPosition.y+this.MONOMER_PREVIEW_OFFSET_Y))),null===(o=this.rnaBasePreviewRenderer)||void 0===o||o.move(),null===(r=this.phosphatePreviewRenderer)||void 0===r||r.move(),null===(i=this.sugarPreviewRenderer)||void 0===i||i.move()}},{key:"mouseLeaveClientArea",value:function(){var e,t,n;null===(e=this.sugarPreviewRenderer)||void 0===e||e.remove(),this.sugarPreviewRenderer=void 0,this.sugarPreview=void 0,null===(t=this.phosphatePreviewRenderer)||void 0===t||t.remove(),this.phosphatePreviewRenderer=void 0,this.phosphatePreview=void 0,null===(n=this.rnaBasePreviewRenderer)||void 0===n||n.remove(),this.rnaBasePreviewRenderer=void 0,this.rnaBasePreview=void 0}},{key:"mouseover",value:function(){var e;if(this.sugar){if(!this.sugarPreview){var t=$s(this.sugar),n=(0,r.A)(t,2),o=n[0],i=n[1];if(this.sugarPreview=new o(this.sugar),this.sugarPreviewRenderer=new i(this.sugarPreview,this.MONOMER_PREVIEW_SCALE_FACTOR),null===(e=this.sugarPreviewRenderer)||void 0===e||e.show(this.editor.theme),this.rnaBase){var a,s=$s(this.rnaBase),u=(0,r.A)(s,2),l=u[0],c=u[1];this.rnaBasePreview=new l(this.rnaBase),this.rnaBasePreviewRenderer=new c(this.rnaBasePreview,this.MONOMER_PREVIEW_SCALE_FACTOR),null===(a=this.rnaBasePreviewRenderer)||void 0===a||a.show(this.editor.theme)}if(this.phosphate){var d,h=$s(this.phosphate),f=(0,r.A)(h,2),m=f[0],p=f[1];this.phosphatePreview=new m(this.phosphate),this.phosphatePreviewRenderer=new p(this.phosphatePreview,this.MONOMER_PREVIEW_SCALE_FACTOR),null===(d=this.phosphatePreviewRenderer)||void 0===d||d.show(this.editor.theme)}}}else this.editor.events.error.dispatch("No sugar in RNA preset found")}}]),e}(),Qs=function(){function e(t){if((0,i.A)(this,e),this.editor=t,this.editor=t,this.history=new _c(t),this.editor.drawingEntitiesManager.selectedEntities.length&&!(this.editor.mode instanceof Ds)){var n=this.editor.drawingEntitiesManager.deleteSelectedEntities();this.history.update(n),this.editor.renderersContainer.update(n)}}return(0,a.A)(e,[{key:"mousedown",value:function(e){var t=e.target.__data__;if(!(t instanceof hn)&&t instanceof un){var n=this.editor.drawingEntitiesManager.deleteDrawingEntity(t.drawingEntity);this.history.update(n),this.editor.renderersContainer.update(n)}}},{key:"mouseOverDrawingEntity",value:function(e){var t=e.target.__data__,n=this.editor.drawingEntitiesManager.intendToSelectDrawingEntity(t.drawingEntity);this.editor.renderersContainer.update(n)}},{key:"mouseLeaveDrawingEntity",value:function(e){var t=e.target.__data__,n=this.editor.drawingEntitiesManager.cancelIntentionToSelectDrawingEntity(t.drawingEntity);this.editor.renderersContainer.update(n)}},{key:"destroy",value:function(){}}]),e}(),Js=function(){function e(t){(0,i.A)(this,e),(0,d.A)(this,"mousePositionAfterMove",new we(0,0,0)),(0,d.A)(this,"mousePositionBeforeMove",new we(0,0,0)),(0,d.A)(this,"previousSelectedEntities",[]),this.editor=t,this.editor=t,this.history=new _c(this.editor),this.destroy(),this.createBrush()}return(0,a.A)(e,[{key:"createBrush",value:function(){var e=this;this.brushArea=(0,P.Ltv)(this.editor.canvas).insert("g",":first-child").attr("id","rectangle-selection-area"),this.brush=(0,P.V$7)(),this.brush.on("brush",(function(t){var n=t.selection,o=zc.provideEditorInstance();n&&!o.isSequenceEditMode&&requestAnimationFrame((function(){var o=sn.viewToCanvas(new we(n[0][0],n[0][1])),r=sn.viewToCanvas(new we(n[1][0],n[1][1])),i=e.editor.drawingEntitiesManager.selectIfLocatedInRectangle(o,r,e.previousSelectedEntities,t.sourceEvent.shiftKey);e.editor.renderersContainer.update(i)}))})),this.brush.on("end",(function(t){var n;e.setSelectedEntities(),t.selection&&e.brushArea.call(null===(n=e.brush)||void 0===n?void 0:n.clear)})),this.brushArea.call(this.brush),this.brushArea.select("rect.selection").style("fill","transparent").style("stroke","darkgrey");var t=this.editor.canvas;t&&(this.canvasResizeObserver=new ResizeObserver((function(){var t=e.editor.canvas;0!==t.clientWidth&&0!==t.clientHeight&&(e.brush.extent([[0,0],[t.width.baseVal.value,t.height.baseVal.value]]).keyModifiers(!1).filter((function(e){return e.preventDefault(),e.shiftKey&&e.stopPropagation(),!0})),e.brushArea.call(e.brush))})),this.canvasResizeObserver.observe(t))}},{key:"mousedown",value:function(e){var t=zc.provideEditorInstance();if(!(t.mode instanceof Ds&&t.mode.isEditMode)){var n=e.target.__data__;this.mousePositionAfterMove=this.editor.lastCursorPositionOfCanvas,this.mousePositionBeforeMove=this.editor.lastCursorPositionOfCanvas;var o,r=y.Ue?e.metaKey:e.ctrlKey;if(n instanceof un&&!e.shiftKey&&!r){if(this.moveStarted=!0,n.drawingEntity.selected&&!(this.editor.mode instanceof Ds))return;var i=this.editor.drawingEntitiesManager.getAllSelectedEntities(n.drawingEntity,!1);o=this.editor.drawingEntitiesManager.selectDrawingEntities(i)}else if(n instanceof un&&e.shiftKey){if(n.drawingEntity.selected)return;var a=this.editor.drawingEntitiesManager.getAllSelectedEntities(n.drawingEntity);o=this.editor.drawingEntitiesManager.addDrawingEntitiesToSelection(a)}else if(n instanceof yr&&r){var s=n.currentSubChain.nodes.map((function(e){return e instanceof Vc?[e.sugar,e.rnaBase]:e instanceof Lr?[e.sugar,e.rnaBase,e.phosphate]:e.monomer})).flat();s=s.concat(n.currentSubChain.bonds),o=this.editor.drawingEntitiesManager.selectDrawingEntities(s)}else o=this.editor.drawingEntitiesManager.unselectAllDrawingEntities();this.editor.renderersContainer.update(o),this.setSelectedEntities()}}},{key:"mousemove",value:function(){var e=this;if(!(this.editor.mode instanceof Ds)&&this.moveStarted){var t=this.editor.drawingEntitiesManager.moveSelectedDrawingEntities(sn.canvasToModel(new we(this.editor.lastCursorPositionOfCanvas.x-this.mousePositionAfterMove.x,this.editor.lastCursorPositionOfCanvas.y-this.mousePositionAfterMove.y)));this.mousePositionAfterMove=this.editor.lastCursorPositionOfCanvas,requestAnimationFrame((function(){e.editor.renderersContainer.update(t)}))}}},{key:"mouseup",value:function(e){var t,n=e.target.__data__;if(this.moveStarted&&null!==(t=n.drawingEntity)&&void 0!==t&&t.selected){if(this.moveStarted=!1,0===we.diff(this.mousePositionAfterMove,this.mousePositionBeforeMove).length())return;var o=this.editor.drawingEntitiesManager.moveSelectedDrawingEntities(new we(0,0),sn.canvasToModel(new we(this.mousePositionAfterMove.x-this.mousePositionBeforeMove.x,this.mousePositionAfterMove.y-this.mousePositionBeforeMove.y)));this.history.update(o)}}},{key:"mouseOverDrawingEntity",value:function(e){var t=e.target.__data__,n=this.editor.drawingEntitiesManager.intendToSelectDrawingEntity(t.drawingEntity);this.editor.renderersContainer.update(n)}},{key:"mouseLeaveDrawingEntity",value:function(e){var t=e.target.__data__,n=this.editor.drawingEntitiesManager.cancelIntentionToSelectDrawingEntity(t.drawingEntity);this.editor.renderersContainer.update(n)}},{key:"setSelectedEntities",value:function(){this.previousSelectedEntities=this.editor.drawingEntitiesManager.allEntities.filter((function(e){return(0,r.A)(e,2)[1].selected}))}},{key:"destroy",value:function(){var e;if(this.brush&&(this.brushArea.remove(),this.brush=null,this.brushArea=null),null===(e=this.canvasResizeObserver)||void 0===e||e.disconnect(),!(this.editor.selectedTool instanceof Qs)){var t=this.editor.drawingEntitiesManager.unselectAllDrawingEntities();this.editor.renderersContainer.update(t)}}}]),e}(),eu=function(){function e(t){(0,i.A)(this,e),this.editor=t,this.editor=t,this.history=new _c(t);var n=this.editor.drawingEntitiesManager.deleteAllEntities();this.editor.renderersContainer.update(n),t.mode instanceof Ds&&n.addOperation(new Qr),this.history.update(n)}return(0,a.A)(e,[{key:"destroy",value:function(){}}]),e}(),tu={monomer:Xs,preset:Zs,"select-rectangle":Js,"bond-single":qs,erase:Qs,clear:eu},nu=function(){function e(t){var n=t.theme;(0,i.A)(this,e),(0,d.A)(this,"monomers",new Map),(0,d.A)(this,"polymerBonds",new Map),(0,d.A)(this,"needRecalculateMonomersEnumeration",!1),(0,d.A)(this,"needRecalculateMonomersBeginning",!1),this.theme=n}return(0,a.A)(e,[{key:"hoverDrawingEntity",value:function(e){f()(e.baseRenderer),e.baseRenderer.redrawHover()}},{key:"selectDrawingEntity",value:function(e){f()(e.baseRenderer),e.baseRenderer.drawSelection()}},{key:"moveDrawingEntity",value:function(e){f()(e.baseRenderer),e.baseRenderer.moveSelection(),e.baseRenderer.drawSelection()}},{key:"markForReEnumeration",value:function(){this.needRecalculateMonomersEnumeration=!0}},{key:"markForRecalculateBegin",value:function(){this.needRecalculateMonomersBeginning=!0}},{key:"addMonomer",value:function(e,t){var n=$s(e.monomerItem),o=new(0,(0,r.A)(n,2)[1])(e);this.monomers.set(e.id,o),o.show(this.theme),this.markForReEnumeration(),this.markForRecalculateBegin(),t&&t()}},{key:"moveMonomer",value:function(e){var t,n;null===(t=e.renderer)||void 0===t||t.move(),null===(n=e.renderer)||void 0===n||n.drawSelection()}},{key:"redrawDrawingEntity",value:function(e){var t,n;null===(t=e.baseRenderer)||void 0===t||t.remove(),null===(n=e.baseRenderer)||void 0===n||n.show(this.theme)}},{key:"deleteAllDrawingEntities",value:function(){this.monomers.forEach((function(e){e.remove()})),this.polymerBonds.forEach((function(e){e.remove()}))}},{key:"deleteMonomer",value:function(e){var t;null===(t=e.renderer)||void 0===t||t.remove(),this.monomers.delete(e.id),this.markForReEnumeration(),this.markForRecalculateBegin()}},{key:"addPolymerBond",value:function(e){var t,n=new Ws(e);this.polymerBonds.set(e.id,n),n.show(),null===(t=n.polymerBond.firstMonomer.renderer)||void 0===t||t.redrawAttachmentPoints(),this.markForReEnumeration(),this.markForRecalculateBegin()}},{key:"movePolymerBond",value:function(e){var t,n,o,r;null===(t=e.renderer)||void 0===t||t.moveStart(),null===(n=e.renderer)||void 0===n||n.moveEnd(),null===(o=e.renderer)||void 0===o||o.drawSelection(),e.firstMonomer.chosenFirstAttachmentPointForBond&&(null===(r=e.firstMonomer.renderer)||void 0===r||r.redrawAttachmentPointsCoordinates())}},{key:"showPolymerBondInformation",value:function(e){var t,n,o,r,i;null===(t=e.renderer)||void 0===t||t.redrawHover(),null===(n=e.firstMonomer.renderer)||void 0===n||n.redrawAttachmentPoints(),null===(o=e.firstMonomer.renderer)||void 0===o||o.redrawHover(),null===(r=e.secondMonomer)||void 0===r||null===(r=r.renderer)||void 0===r||r.redrawAttachmentPoints(),null===(i=e.secondMonomer)||void 0===i||null===(i=i.renderer)||void 0===i||i.redrawHover()}},{key:"deletePolymerBond",value:function(e){var t,n,o,r,i,a=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];null===(t=e.renderer)||void 0===t||t.remove(),null==e||null===(n=e.firstMonomer)||void 0===n||null===(n=n.renderer)||void 0===n||null===(o=n.redrawAttachmentPoints)||void 0===o||o.call(n),null==e||null===(r=e.secondMonomer)||void 0===r||null===(r=r.renderer)||void 0===r||null===(i=r.redrawAttachmentPoints)||void 0===i||i.call(r),this.polymerBonds.delete(e.id),a&&this.markForReEnumeration(),s&&this.markForRecalculateBegin()}},{key:"recalculatePeptideChainEnumeration",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=[{monomerRenderer:e}];n.length>0;){var o=n.pop();f()(o);var r=o.monomerRenderer;r.setEnumeration(t),r.redrawEnumeration();var i=no(r.monomer);if(!(i instanceof Dn))return;if(!to(r.monomer,i))return;f()(i.renderer),n.push({monomerRenderer:i.renderer}),t++}}},{key:"recalculateRnaChainEnumeration",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=[{monomerRenderer:e}];n.length>0;){var o=n.pop();f()(o);var r=o.monomerRenderer;if(r instanceof Wo){var i,a,s=oo(r.monomer);s instanceof Gn&&(null===(i=s.renderer)||void 0===i||i.setEnumeration(t),null===(a=s.renderer)||void 0===a||a.redrawEnumeration(),t++)}var u=no(r.monomer);if(!(u instanceof eo||u instanceof Kn))return;if(!(to(r.monomer,u)&&u.renderer instanceof Oo))return;n.push({monomerRenderer:u.renderer})}}},{key:"recalculatePeptideEnumeration",value:function(e){e.monomer.hasBonds||(e.setEnumeration(null),e.redrawEnumeration()),io(e.monomer,[Dn])&&this.recalculatePeptideChainEnumeration(e)}},{key:"recalculateRnaEnumeration",value:function(e){io(e.monomer,[Kn,eo])&&this.recalculateRnaChainEnumeration(e)}},{key:"recalculateMonomersEnumeration",value:function(){var e=this;this.monomers.forEach((function(t){t instanceof Do&&e.recalculatePeptideEnumeration(t),(t instanceof jo||t instanceof Wo)&&e.recalculateRnaEnumeration(t),t instanceof Ko&&!t.monomer.isAttachmentPointUsed(dn.R1)&&(t.setEnumeration(null),t.redrawEnumeration())})),this.needRecalculateMonomersEnumeration=!1}},{key:"isOnlyPartOfRnaChain",value:function(e){var t=no(e),n=no(t);return!e.attachmentPointsToBonds.R1&&!n}},{key:"recalculateMonomersBeginning",value:function(){var e=this;this.monomers.forEach((function(t){if(t instanceof Do&&(1===t.enumeration?t.setBeginning(t.CHAIN_BEGINNING):t.setBeginning(null),t.reDrawChainBeginning()),t instanceof Wo){var n,o=oo(t.monomer);o instanceof Gn&&1===(null===(n=o.renderer)||void 0===n?void 0:n.enumeration)&&!e.isOnlyPartOfRnaChain(t.monomer)?t.setBeginning(t.CHAIN_BEGINNING):t.setBeginning(null),t.reDrawChainBeginning()}})),this.needRecalculateMonomersBeginning=!1}},{key:"finishPolymerBondCreation",value:function(e){var t,n,o,r,i,a,s;f()(e.secondMonomer);var u=new Ws(e);this.polymerBonds.set(e.id,u),this.markForReEnumeration(),this.markForRecalculateBegin(),null===(t=e.firstMonomer.renderer)||void 0===t||t.redrawAttachmentPoints(),null===(n=e.firstMonomer.renderer)||void 0===n||n.drawSelection(),null===(o=e.firstMonomer.renderer)||void 0===o||o.redrawHover(),null===(r=e.secondMonomer.renderer)||void 0===r||r.redrawAttachmentPoints(),null===(i=e.secondMonomer.renderer)||void 0===i||i.drawSelection(),null===(a=e.secondMonomer.renderer)||void 0===a||a.redrawHover(),null===(s=e.renderer)||void 0===s||s.show()}},{key:"cancelPolymerBondCreation",value:function(e,t){var n,o,r,i,a,s;this.deletePolymerBond(e),null===(n=e.firstMonomer.renderer)||void 0===n||n.redrawAttachmentPoints(),null===(o=e.firstMonomer.renderer)||void 0===o||o.drawSelection(),null===(r=e.firstMonomer.renderer)||void 0===r||r.redrawHover(),null==t||null===(i=t.renderer)||void 0===i||i.redrawAttachmentPoints(),null==t||null===(a=t.renderer)||void 0===a||a.drawSelection(),null==t||null===(s=t.renderer)||void 0===s||s.redrawHover()}},{key:"hoverMonomer",value:function(e,t){var n;this.hoverDrawingEntity(e),t&&(null===(n=e.renderer)||void 0===n||n.redrawAttachmentPoints())}},{key:"hoverAttachmentPoint",value:function(e,t){var n,o;this.hoverDrawingEntity(e),null===(n=e.renderer)||void 0===n||n.hoverAttachmenPoint(t),null===(o=e.renderer)||void 0===o||o.updateAttachmentPoints()}},{key:"update",value:function(e){null==e||e.execute(this),this.runPostRenderMethods(),on()}},{key:"runPostRenderMethods",value:function(){this.needRecalculateMonomersEnumeration&&this.recalculateMonomersEnumeration(),this.needRecalculateMonomersBeginning&&this.recalculateMonomersBeginning()}}]),e}(),ou=function(){function e(t,n,o){(0,i.A)(this,e),this.addMonomerChangeModel=t,this.deleteMonomerChangeModel=n,this.callback=o,this.monomer=this.addMonomerChangeModel()}return(0,a.A)(e,[{key:"execute",value:function(e){this.monomer=this.addMonomerChangeModel(this.monomer),e.addMonomer(this.monomer,this.callback)}},{key:"invert",value:function(e){this.monomer&&(this.deleteMonomerChangeModel(this.monomer),e.deleteMonomer(this.monomer))}}]),e}(),ru=function(){function e(t,n){(0,i.A)(this,e),this.monomerMoveModelChange=t,this.invertMonomerMoveModelChange=n,this.monomer=this.monomerMoveModelChange()}return(0,a.A)(e,[{key:"execute",value:function(e){this.monomer=this.monomerMoveModelChange(),e.moveMonomer(this.monomer)}},{key:"invert",value:function(e){this.monomer=this.invertMonomerMoveModelChange(),e.moveMonomer(this.monomer)}}]),e}(),iu=function(){function e(t,n){(0,i.A)(this,e),this.peptide=t,this.needRedrawAttachmentPoints=n}return(0,a.A)(e,[{key:"execute",value:function(e){e.hoverMonomer(this.peptide,this.needRedrawAttachmentPoints)}},{key:"invert",value:function(){}}]),e}(),au=function(){function e(t,n){(0,i.A)(this,e),this.peptide=t,this.attachmentPointName=n}return(0,a.A)(e,[{key:"execute",value:function(e){e.hoverAttachmentPoint(this.peptide,this.attachmentPointName)}},{key:"invert",value:function(){}}]),e}(),su=function(){function e(t,n,o,r){(0,i.A)(this,e),this.addMonomerChangeModel=n,this.deleteMonomerChangeModel=o,this.callback=r,this.monomer=t}return(0,a.A)(e,[{key:"execute",value:function(e){this.deleteMonomerChangeModel(this.monomer),e.deleteMonomer(this.monomer)}},{key:"invert",value:function(e){this.monomer=this.addMonomerChangeModel(this.monomer),e.addMonomer(this.monomer,this.callback)}}]),e}(),uu=function(){function e(t){(0,i.A)(this,e),this.drawingEntity=t}return(0,a.A)(e,[{key:"execute",value:function(e){e.hoverDrawingEntity(this.drawingEntity)}},{key:"invert",value:function(){}}]),e}(),lu=function(){function e(t){(0,i.A)(this,e),this.drawingEntity=t}return(0,a.A)(e,[{key:"execute",value:function(e){e.selectDrawingEntity(this.drawingEntity)}},{key:"invert",value:function(){}}]),e}(),cu=function(){function e(t,n,o,r){(0,i.A)(this,e),(0,d.A)(this,"wasInverted",!1),this.moveDrawingEntityChangeModel=t,this.invertMoveDrawingEntityChangeModel=n,this.redoDrawingEntityChangeModel=o,this.drawingEntity=r}return(0,a.A)(e,[{key:"execute",value:function(e){this.wasInverted?this.redoDrawingEntityChangeModel():this.moveDrawingEntityChangeModel(),e.moveDrawingEntity(this.drawingEntity)}},{key:"invert",value:function(e){this.invertMoveDrawingEntityChangeModel(),e.moveDrawingEntity(this.drawingEntity),this.wasInverted=!0}}]),e}(),du=function(){function e(t,n){(0,i.A)(this,e),this.drawingEntityRedrawModelChange=t,this.invertDrawingEntityRedrawModelChange=n}return(0,a.A)(e,[{key:"execute",value:function(e){var t=this.drawingEntityRedrawModelChange();e.redrawDrawingEntity(t)}},{key:"invert",value:function(e){var t=this.invertDrawingEntityRedrawModelChange();e.redrawDrawingEntity(t)}}]),e}();!function(e){e.Mol="chemical/x-mdl-molfile",e.Rxn="chemical/x-mdl-rxnfile",e.DaylightSmiles="chemical/x-daylight-smiles",e.ExtendedSmiles="chemical/x-chemaxon-cxsmiles",e.DaylightSmarts="chemical/x-daylight-smarts",e.InChI="chemical/x-inchi",e.InChIAuxInfo="chemical/x-inchi-aux",e.InChIKey="chemical/x-inchi-key",e.CDX="chemical/x-cdx",e.CDXML="chemical/x-cdxml",e.CML="chemical/x-cml",e.KET="chemical/x-indigo-ket",e.UNKNOWN="chemical/x-unknown",e.SDF="chemical/x-sdf",e.FASTA="chemical/x-fasta",e.SEQUENCE="chemical/x-sequence"}(Us||(Us={}));var hu,fu=(0,a.A)((function e(t,n,o,r,a){(0,i.A)(this,e),this.name=t,this.mime=n,this.extensions=o,this.supportsCoords=r||!1,this.options=a||{}})),mu={molAuto:new fu("MDL Molfile Auto Format detect",Us.Mol,[".mol"],!0,{"molfile-saving-mode":"auto"}),mol:new fu("MDL Molfile V2000",Us.Mol,[".mol"],!0),molV3000:new fu("MDL Molfile V3000",Us.Mol,[".mol"],!0,{"molfile-saving-mode":"3000"}),rxn:new fu("MDL Rxnfile V2000",Us.Rxn,[".rxn"],!0),rxnV3000:new fu("MDL Rxnfile V3000",Us.Rxn,[".rxn"],!0,{"molfile-saving-mode":"3000"}),smiles:new fu("Daylight SMILES",Us.DaylightSmiles,[".smi",".smiles"],!0),smilesExt:new fu("Extended SMILES",Us.ExtendedSmiles,[".cxsmi",".cxsmiles"]),smarts:new fu("Daylight SMARTS",Us.DaylightSmarts,[".smarts"]),inChI:new fu("InChI",Us.InChI,[".inchi"]),inChIAuxInfo:new fu("InChI AuxInfo",Us.InChIAuxInfo,[".inchi"]),inChIKey:new fu("InChIKey",Us.InChIKey,[".inchikey"]),cml:new fu("CML",Us.CML,[".cml",".mrv"],!0),ket:new fu("Ket Format",Us.KET,[".ket"]),cdxml:new fu("CDXML",Us.CDXML,[".cdxml"],!0),cdx:new fu("Base64 CDX",Us.CDX,[".b64cdx"],!0),binaryCdx:new fu("CDX",Us.CDX,[".cdx"],!0),sdf:new fu("SDF V2000",Us.SDF,[".sdf"],!0),sdfV3000:new fu("SDF V3000",Us.SDF,[".sdf"],!0,{"molfile-saving-mode":"3000"}),fasta:new fu("FASTA",Us.FASTA,[".fasta"],!0),sequence:new fu("SEQUENCE",Us.SEQUENCE,[".seq"],!1,{}),unknown:new fu("Unknown",Us.UNKNOWN,["."],!0)},pu={svg:{extension:".svg",name:"SVG Document"},png:{extension:".png",name:"PNG Image"}};function vu(e){return pu[e]}function gu(e){return mu[e]}function yu(e){var t="."+e.split(".").pop(),n=Object.values(mu).find((function(e){return e.extensions.includes(t)}));return null==n?void 0:n.mime}!function(e){e.mol="mol",e.molV3000="molV3000",e.molAuto="molAuto",e.rxn="rxn",e.rxnV3000="rxnV3000",e.smiles="smiles",e.smilesExt="smilesExt",e.smarts="smarts",e.inChI="inChI",e.inChIAuxInfo="inChIAuxInfo",e.inChIKey="inChIKey",e.cml="cml",e.ket="ket",e.cdxml="cdxml",e.cdx="cdx",e.binaryCdx="binaryCdx",e.sdf="sdf",e.sdfV3000="sdfV3000",e.fasta="fasta",e.sequence="sequence",e.unknown="unknown"}(hu||(hu={}));var bu=function(e){if("object"===(0,g.A)(e)&&e.y){var t=(0,x.cloneDeep)(e);return t.y=-t.y,t}},Au=function(e){return(0,x.cloneDeepWith)(e,bu)},wu=function(e){return"monomerTemplate-".concat(e)},Eu=function(e){return"monomer".concat(e)},Pu=function(e){return{$ref:e}},xu=function(e){return function(e,t){var n={x:e.x,y:e.y};return n[t]=-n[t],new we(n.x,n.y)}(e,Jn.y)};function Su(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Ou(e,t){var n={atoms:Array.from(e.atoms.values()).map((function(e){return"R#"!==e.label||t?function(e,t){var n,o={};"L#"!==e.label?(V(o,"label","R#"===e.label&&t?null===(n=t.monomerItem.props.MonomerCaps)||void 0===n?void 0:n[wn(e.rglabel)]:e.label),V(o,"mapping",parseInt(e.aam),0)):e.atomList&&(o.type="atom-list",V(o,"elements",e.atomList.labelList()),V(o,"notList",e.atomList.notList,!1));V(o,"alias",e.alias);var r=xu(new we(e.pp.x,e.pp.y,e.pp.z));return V(o,"location",[r.x,r.y,r.z]),V(o,"charge",e.charge),V(o,"explicitValence",e.explicitValence,-1),V(o,"isotope",e.isotope),V(o,"radical",e.radical,0),V(o,"attachmentPoints",e.attachmentPoints,0),V(o,"cip",e.cip,""),V(o,"selected",e.getInitiallySelected()),V(o,"stereoLabel",e.stereoLabel,null),V(o,"stereoParity",e.stereoCare,0),V(o,"weight",e.weight,0),V(o,"ringBondCount",e.ringBondCount,0),V(o,"substitutionCount",e.substitutionCount,0),V(o,"unsaturatedAtom",!!e.unsaturatedAtom,!1),V(o,"hCount",e.hCount,0),Object.values(e.queryProperties).some((function(e){return null!==e}))&&(o.queryProperties={},Object.keys(e.queryProperties).forEach((function(t){V(o.queryProperties,t,e.queryProperties[t])}))),V(o,"invRet",e.invRet,0),V(o,"exactChangeFlag",!!e.exactChangeFlag,!1),V(o,"implicitHCount",e.implicitHCount),o}(e,t):(o={type:"rg-label"},r=xu(new we((n=e).pp.x,n.pp.y,n.pp.z)),V(o,"location",[r.x,r.y,r.z]),V(o,"attachmentPoints",n.attachmentPoints,0),V(o,"$refs",function(e){var t,n,o=[];for(t=0;t<32;t++)e&1<<t&&(n=t+1,o.push(n));return o}(n.rglabel).map((function(e){return"rg-".concat(e)}))),V(o,"selected",n.getInitiallySelected()),o);var n,o,r}))};0!==e.bonds.size&&(n.bonds=Array.from(e.bonds.values()).map(ku)),0!==e.sgroups.size&&(n.sgroups=Array.from(e.sgroups.values()).map((function(t){return function(e,t){var n={};switch(V(n,"type",t.type),V(n,"atoms",t.atoms),t.type){case"GEN":case"queryComponent":break;case"MUL":V(n,"mul",t.data.mul||1);break;case"SRU":V(n,"subscript",t.data.subscript||"n"),V(n,"connectivity",t.data.connectivity.toUpperCase()||"ht");break;case"SUP":V(n,"name",t.data.name||""),V(n,"expanded",t.data.expanded),V(n,"id",t.id),V(n,"attachmentPoints",t.getAttachmentPoints().map(Mu),[]);break;case"DAT":var o=t.data;V(n,"placement",o.absolute,!0),V(n,"display",o.attached,!1),V(n,"context",o.context),V(n,"fieldName",o.fieldName),V(n,"fieldData",o.fieldValue),V(n,"bonds",ht.getBonds(e,t))}return n}(e,t)})));var o=e.frags.get(0);return o&&(V(n,"stereoFlagPosition",o.stereoFlagPosition,null),o.properties&&(n.properties=o.properties)),function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Su(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Su(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({type:"molecule"},n)}function ku(e){var t={};return e.customQuery?(V(t,"atoms",[e.begin,e.end]),V(t,"customQuery",e.customQuery)):(V(t,"type",e.type),V(t,"atoms",[e.begin,e.end]),V(t,"stereo",e.stereo,0),V(t,"topology",e.topology,0),V(t,"center",e.reactingCenterStatus,0),V(t,"cip",e.cip,"")),V(t,"selected",e.getInitiallySelected()),t}function Mu(e){var t={};return V(t,"attachmentAtom",e.atomId),V(t,"leavingAtom",e.leaveAtomId),V(t,"attachmentId",e.attachmentId),t}function Ru(e){var t=function(e,t){var n=0;return e.fragments&&e.fragments.forEach((function(e){var o,r,i;null===(o=e.atoms)||void 0===o||o.forEach((function(e){return t.atoms.add(Tu(e))})),null===(r=e.bonds)||void 0===r||r.forEach((function(e){return t.bonds.add(Bu(e,n))})),n+=(null===(i=e.atoms)||void 0===i?void 0:i.length)||0})),t}(e,new Yt);return e.atoms&&e.atoms.forEach((function(e){var n=null;"rg-label"===e.type&&(n=t.atoms.add(function(e){var t,n,o={label:"R#"};V(o,"pp",{x:e.location[0],y:-e.location[1],z:e.location[2]||0}),V(o,"attachmentPoints",e.attachmentPoints),V(o,"rglabel",(t=e.$refs.map((function(e){return parseInt(e.slice(3))})),n=0,t.forEach((function(e){n|=1<<e-1})),n));var r=new Fe(o);return r.setInitiallySelected(e.selected),r}(e))),e.type&&"atom-list"!==e.type||(n=t.atoms.add(Tu(e))),null!==n&&function(e,t,n,o){var r=[];n===Oe.FirstSideOnly?r.push(new xt(t,"primary",o)):n===Oe.SecondSideOnly?r.push(new xt(t,"secondary",o)):n===Oe.BothSides&&(r.push(new xt(t,"primary",o)),r.push(new xt(t,"secondary",o))),r.forEach((function(t){e.rgroupAttachmentPoints.add(t)}))}(t,n,e.attachmentPoints,e.selected)})),e.bonds&&e.bonds.forEach((function(e){return t.bonds.add(Bu(e))})),e.sgroups&&e.sgroups.forEach((function(e){var n=function(e){var t=new ht(e.type);switch(V(t,"atoms",e.atoms),e.type){case"GEN":break;case"MUL":V(t.data,"mul",e.mul);break;case"SRU":V(t.data,"subscript",e.subscript),V(t.data,"connectivity",e.connectivity.toLowerCase());break;case"SUP":var n;V(t.data,"name",e.name),V(t.data,"expanded",e.expanded),V(t,"id",e.id),null===(n=e.attachmentPoints)||void 0===n||n.forEach((function(e){t.addAttachmentPoint(function(e){var t=e.attachmentAtom,n=e.leavingAtom,o=e.attachmentId;return new Qt(t,n,o)}(e))}));break;case"DAT":V(t.data,"absolute",e.placement),V(t.data,"attached",e.display),V(t.data,"context",e.context),V(t.data,"fieldName",e.fieldName),V(t.data,"fieldValue",e.fieldData)}return t}(e),o=t.sgroups.add(n);n.id=o})),t.initHalfBonds(),t.initNeighbors(),t.markFragments(e.properties),t.bindSGroupsToFunctionalGroups(),t}function Tu(e){var t={};if("atom-list"===e.type){t.label="L#";var n=e.elements.map((function(e){var t;return null===(t=_.get(e))||void 0===t?void 0:t.number})).filter((function(e){return e}));V(t,"atomList",{ids:n,notList:e.notList})}else V(t,"label",e.label),V(t,"aam",e.mapping);V(t,"alias",e.alias),V(t,"pp",{x:e.location[0],y:-e.location[1],z:e.location[2]||0}),V(t,"charge",e.charge),V(t,"explicitValence",e.explicitValence),V(t,"isotope",e.isotope),V(t,"radical",e.radical),V(t,"cip",e.cip),V(t,"attachmentPoints",e.attachmentPoints),V(t,"stereoLabel",e.stereoLabel),V(t,"stereoParity",e.stereoParity),V(t,"weight",e.weight),V(t,"ringBondCount",e.ringBondCount),V(t,"substitutionCount",e.substitutionCount),V(t,"unsaturatedAtom",Number(Boolean(e.unsaturatedAtom))),V(t,"hCount",e.hCount),e.queryProperties&&Object.values(e.queryProperties).some((function(e){return null!==e}))&&(t.queryProperties={},["aromaticity","ringMembership","connectivity","ringSize","chirality","customQuery"].forEach((function(n){V(t.queryProperties,n,e.queryProperties[n])}))),V(t,"invRet",e.invRet),V(t,"exactChangeFlag",Number(Boolean(e.exactChangeFlag))),V(t,"implicitHCount",e.implicitHCount);var o=new Fe(t);return o.setInitiallySelected(e.selected),o}function Bu(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n={};V(n,"type",e.type),V(n,"topology",e.topology),V(n,"reactingCenterStatus",e.center),V(n,"stereo",e.stereo),V(n,"cip",e.cip),V(n,"customQuery",e.customQuery),V(n,"begin",e.atoms[0]+t),V(n,"end",e.atoms[1]+t),V(n,"initiallySelected",e.selected);var o=new We(n);return o.setInitiallySelected(e.selected),o}function Cu(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function Iu(e){var t,n=[],o=new Set,i=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return Cu(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Cu(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}(e.rgroups.entries());try{for(i.s();!(t=i.n()).done;){var a=(0,r.A)(t.value,2),s=a[0],u=a[1];u.frags.forEach((function(e){return o.add(e)}));var l=Array.from(u.frags.values()).reduce((function(t,n){return t.union(e.getFragmentIds(n))}),new Re);n.push({type:"rgroup",fragment:e.clone(l),center:Nu(e,l),data:{rgnumber:s,rgroup:u}})}}catch(e){i.e(e)}finally{i.f()}var c=Array.from(e.frags.keys()).filter((function(e){return!o.has(e)}));return function(e,t,n){var o=function(e,t,n){var o=new Map;return t.forEach((function(t){var r=n.getFragmentIds(t),i=!1;r.forEach((function(e){var r;null===(r=n.atoms.get(e))||void 0===r||r.sgs.forEach((function(e){i=!0;var n=o.get(e);n?n.add(t):o.set(e,new Re([t]))}))})),i||e.push({type:"molecule",fragment:n.clone(r),center:Nu(n,r)})})),o}(e,t,n);Re.unionIntersections(Array.from(o.values())).forEach((function(t){var o=new Re;t.forEach((function(e){o=o.union(n.getFragmentIds(e))})),e.push({type:"molecule",fragment:n.clone(o),center:Nu(n,o)})}))}(n,c,e),e.rxnArrows.forEach((function(e){n.push({type:"arrow",center:e.pos[0],data:{mode:e.mode,pos:e.pos,height:e.height},selected:e.getInitiallySelected()})})),e.rxnPluses.forEach((function(e){n.push({type:"plus",center:e.pp,data:{},selected:e.getInitiallySelected()})})),e.simpleObjects.forEach((function(e){n.push({type:"simpleObject",center:e.pos[0],data:{mode:e.mode,pos:e.pos},selected:e.getInitiallySelected()})})),e.texts.forEach((function(e){n.push({type:"text",center:e.position,data:{content:e.content,position:e.position,pos:e.pos},selected:e.getInitiallySelected()})})),n.forEach((function(e){if(e.fragment){var t=Array.from(e.fragment.sgroups.values()).filter((function(e){return e.atoms.every((function(e){return void 0!==e}))})),n=new Gt;t.forEach((function(e,t){n.set(t,e)})),e.fragment.sgroups=n}})),n}function Nu(e,t){var n=e.getCoordBoundingBox(t);return we.centre(n.min,n.max)}function Du(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Lu(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Du(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Du(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _u(e,t){var n={};return V(n,"number",e),V(n,"range",t.range,""),V(n,"resth",t.resth,!1),V(n,"ifthen",t.ifthen,0),n}var Fu={$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"},alias:{type:"string"},location:{type:"array",minItems:2,maxItems:3,items:{type:"number"}},selected:{type:"boolean"},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,5,6,7,8,9]},substitutionCount:{type:"integer",enum:[0,-2,-1,1,2,3,4,5,6,7,8,9]},unsaturatedAtom:{type:"boolean"},hCount:{type:"integer",enum:[-1,0,1,2,3,4,5,6,7,8,9,10]},implicitHCount:{type:"integer",enum:[0,1,2,3,4,5,6,7,8,9]},mapping:{type:"integer",minimum:0},invRet:{type:"integer",enum:[0,1,2]},exactChangeFlag:{type:"boolean"},cip:{type:"string",enum:["R","S","r","s"]},queryProperties:{type:"object",properties:{aromaticity:{type:"string",enum:["aromatic","aliphatic"]},ringMembership:{type:"integer",minimum:0,maximum:9},ringSize:{type:"integer",minimum:0,maximum:9},connectivity:{type:"integer",minimum:0,maximum:9},chirality:{type:"string",enum:["clockwise","anticlockwise"]},customQuery:{type:"string"}}}},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"],properties:{atoms:{type:"array",minItems:2,maxItems:2,uniqueItems:!0,items:{type:"integer",minimum:0}},selected:{type:"boolean"},stereobox:{type:"integer",enum:[0,1]},cip:{type:"string",enum:["Z","E"]}},oneOf:[{required:["type"],properties:{type:{type:"integer",enum:[1,2,3,4,5,6,7,8,9,10,11,12]},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]}}},{required:["customQuery"],properties:{customQuery:{type:"string"}}}]},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}}},fragments:{type:"array",items:{$ref:"#/definitions/structure"}}},anyOf:[{required:["fragments"]},{$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"}}},properties:{type:"array",items:{type:"object",properties:{key:{type:"string"},value:{type:"string"}}}},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","queryComponent"]}},if:{properties:{type:{const:"DAT"}}},then:{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"}},selected:{type:"boolean"}}},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"}}},selected:{type:"boolean"}}},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"}}}}}}},selected:{type:"boolean"}}},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"}}}}}},selected:{type:"boolean"}}}}},Hu=function(){function e(){(0,i.A)(this,e)}return(0,a.A)(e,null,[{key:"convertMonomerToMonomerMicromolecule",value:function(e,t){var n=new Ut(ht.TYPES.SUP,e),o=t.sgroups.add(n);return n.data.name=e.monomerItem.label,n.data.expanded=!1,n.id=o,n.pp=e.position,n}},{key:"addMonomerAtomToStruct",value:function(e,t,n,o){var r=e.clone();r.pp=t.position.add(e.pp),r.sgs=new Re([n.id]),r.fragment=-1;var i=o.atoms.add(r);return n.atoms.push(i),e.rglabel&&n.addAttachmentPoint(new Qt(i,void 0,void 0)),{atomId:i,atom:r}}},{key:"convertAttachmentPointNameToNumber",value:function(e){return 1<<Number(null==e?void 0:e.replace("R",""))-1}},{key:"findAttachmentPointAtom",value:function(t,n,o,r,i){var a=n.getAttachmentPointByBond(t);f()(a);var s=e.convertAttachmentPointNameToNumber(a);return r?r.atoms.find((function(e){var t;return Number(null===(t=o.atoms.get(e))||void 0===t?void 0:t.rglabel)===s})):o.atoms.find((function(e){var t=o.atoms.get(e);return t.fragment===i&&Number(t.rglabel)===s}))}},{key:"convertDrawingEntitiesToStruct",value:function(e,t,n){var o=this,r=new Map,i=new Map;e.micromoleculesHiddenEntities.mergeInto(t),e.clearMicromoleculesHiddenEntities(),e.monomers.forEach((function(e){if(e.monomerItem.props.isMicromoleculeFragment)e.monomerItem.struct.mergeInto(t),i.set(e,t.frags.size-1);else{var a={},s=o.convertMonomerToMonomerMicromolecule(e,t);r.set(e,s),null==n||n.sgroups.set(s.id,new ma(s)),e.monomerItem.struct.atoms.forEach((function(r,i){var u=o.addMonomerAtomToStruct(r,e,s,t),l=u.atom,c=u.atomId;a[i]=c,null==n||n.atoms.set(c,new bi(l))})),t.sGroupForest.insert(s),e.monomerItem.struct.bonds.forEach((function(e){var o=e.clone();o.begin=a[o.begin],o.end=a[o.end];var r=t.bonds.add(o);null==n||n.bonds.set(r,new Ti(o))})),t.functionalGroups.add(new gt(s))}}));var a="";return e.polymerBonds.forEach((function(e){f()(e.secondMonomer);var s=o.findAttachmentPointAtom(e,e.firstMonomer,t,r.get(e.firstMonomer),i.get(e.firstMonomer)),u=o.findAttachmentPointAtom(e,e.secondMonomer,t,r.get(e.secondMonomer),i.get(e.secondMonomer));if(s&&u){var l=new We({type:We.PATTERN.TYPE.SINGLE,begin:s,end:u}),c=t.bonds.add(l);null==n||n.bonds.set(c,new Ti(l))}else a="There is no atom for provided attachment point. Bond between monomers was not created."})),{struct:t,reStruct:n,conversionErrorMessage:a}}},{key:"convertMonomerMicromoleculeToMonomer",value:function(e,t,n){var o=new Zo,r=t.addMonomer(e.monomer.monomerItem,e.pp);return o.merge(r),n.set(e,r.operations[0].monomer),o}},{key:"convertFragmentToChem",value:function(e,t,n){var o=t.getCoordBoundingBox();return n.addMonomer({struct:t,label:"F"+e,colorScheme:void 0,favorite:!1,props:{Name:"F"+e,MonomerNaturalAnalogCode:"",MonomerName:"F"+e,MonomerType:Ys,isMicromoleculeFragment:!0}},new we(o.max.x-(o.max.x-o.min.x)/2,o.max.y-(o.max.y-o.min.y)/2))}},{key:"getAttachmentPointLabel",value:function(e){var t="",n=Number(e.rglabel);f()(Number.isInteger(n));for(var o=0;o<32;o++)n&1<<o&&(t="R"+(o+1).toString());return t}},{key:"getFragmentsGroupedBySgroup",value:function(e){var t=[];return e.frags.forEach((function(n,o){if(!t.find((function(e){return e.includes(o)}))){var r=new Set;e.atoms.forEach((function(t,n){if(t.fragment===o){var i=e.getGroupFromAtomId(n);i&&r.add(i)}}));var i=t.push([o])-1;r.forEach((function(n){n.atoms.forEach((function(n){var o,r=null===(o=e.atoms.get(n))||void 0===o?void 0:o.fragment;r&&!t[i].includes(r)&&t[i].push(r)}))}))}})),t}},{key:"convertStructToDrawingEntities",value:function(t,n){var o=this,r=new Map,i=new Map,a=new Zo;t.sgroups.forEach((function(e){e instanceof Ut&&a.merge(o.convertMonomerMicromoleculeToMonomer(e,n,r))}));var s=this.getFragmentsGroupedBySgroup(t),u=1;return s.forEach((function(e,r){var s=t.getFragment(e,!1),l=o.convertFragmentToChem(u,s,n);i.set(r,l.operations[0].monomer),a.merge(l),u++})),t.bonds.forEach((function(o){var s=t.atoms.get(o.begin),u=t.atoms.get(o.end),l=t.getGroupFromAtomId(o.begin),c=t.getGroupFromAtomId(o.end),d=e.getAttachmentPointLabel(s),h=e.getAttachmentPointLabel(u);if(d&&h&&(l||c)){var m=l instanceof Ut?r.get(l):i.get(s.fragment),p=c instanceof Ut?r.get(c):i.get(u.fragment);f()(m),f()(p),a.merge(n.createPolymerBond(m,p,d,h))}})),n.setMicromoleculesHiddenEntities(t),{drawingEntitiesManager:n,modelChanges:a}}}]),e}();function ju(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Gu(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ju(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ju(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function zu(e,t){switch(e.type){case"arrow":case"plus":!function(e,t){if("arrow"===e.type){var n=new kt(Au(e.data));n.setInitiallySelected(e.selected),t.rxnArrows.add(n)}else{var o=new Bt({pp:{x:e.location[0],y:-e.location[1],z:e.location[2]}});o.setInitiallySelected(e.selected),t.rxnPluses.add(o)}}(e,t);break;case"simpleObject":!function(e,t){var n="circle"===e.data.mode?function(e){var t=we.dist(e.data.pos[1],e.data.pos[0]),n=e.data.pos[0];return{mode:Tt.ellipse,pos:[{x:n.x-Math.abs(t),y:n.y-Math.abs(t),z:n.z-Math.abs(t)},{x:n.x+Math.abs(t),y:n.y+Math.abs(t),z:n.z+Math.abs(t)}]}}(e):e.data,o=new Lt(Au(n));o.setInitiallySelected(e.selected),t.simpleObjects.add(o)}(e,t);break;case"molecule":var n=Ru(e);e.stereoFlagPosition&&(n.frags.get(0).stereoFlagPosition=new we(e.stereoFlagPosition)),n.mergeInto(t);break;case"rgroup":(function(e){var t,n,o=Ru(e),r=(V(n={},"range",(t=e.rlogic).range),V(n,"resth",t.resth),V(n,"ifthen",t.ifthen),new At(n));return o.frags.forEach((function(e,t){r.frags.add(t)})),e.rlogic&&o.rgroups.set(e.rlogic.number,r),o})(e).mergeInto(t);break;case"text":!function(e,t){var n=new Kt(Au(e.data));n.setInitiallySelected(e.selected),t.texts.add(n)}(e,t)}}var Vu=function(){function e(){(0,i.A)(this,e)}return(0,a.A)(e,[{key:"deserializeMicromolecules",value:function(e){var t=JSON.parse(e);if(!function(e){return(new(I())).compile(Fu)(e)}(t))throw new Error("Cannot deserialize input JSON.");return this.fillStruct(t)}},{key:"fillStruct",value:function(e){var t=new Yt,n=e.root.nodes;return Object.keys(n).forEach((function(o){n[o].type?zu(n[o],t):n[o].$ref&&zu(e[n[o].$ref],t)})),t.name=e.header?e.header.moleculeName:null,t}},{key:"serializeMicromolecules",value:function(e,t){var n={root:{nodes:[]}},o=function(e){var t={};return V(t,"moleculeName",e.name,""),V(t,"creatorProgram",null,""),V(t,"comment",null,""),0!==Object.keys(t).length?t:null}(e);o&&(n.header=o);var r=Iu(e),i=0;return r.forEach((function(e){switch(e.type){case"molecule":n.root.nodes.push({$ref:"mol".concat(i)}),n["mol".concat(i++)]=Ou(e.fragment,t);break;case"rgroup":n.root.nodes.push({$ref:"rg".concat(e.data.rgnumber)}),n["rg".concat(e.data.rgnumber)]=function(e,t){var n=Lu({rlogic:_u(t.rgnumber,t.rgroup)},Ou(e));return Lu(Lu({},n),{},{type:"rgroup"})}(e.fragment,e.data);break;case"plus":n.root.nodes.push({type:"plus",location:[(u=(s=e).center).x,-u.y,u.z],prop:s.data,selected:s.selected});break;case"arrow":n.root.nodes.push({type:"arrow",data:Au((a=e).data),selected:a.selected});break;case"simpleObject":n.root.nodes.push({type:"simpleObject",data:Au((r=e).data),selected:r.selected});break;case"text":n.root.nodes.push({type:"text",data:Au((o=e).data),selected:o.selected})}var o,r,a,s,u})),JSON.stringify(n,null,4)}},{key:"validateMonomerNodeTemplate",value:function(e,t,n){return!t[wu(e.templateId)]&&(n.events.error.dispatch("Error during file parsing"),!0)}},{key:"validateConnectionTypeAndEndpoints",value:function(e,t){return!("single"===e.connectionType&&e.endpoint1.monomerId&&e.endpoint2.monomerId&&e.endpoint1.attachmentPointId&&e.endpoint2.attachmentPointId||(t.events.error.dispatch("Error during file parsing"),0))}},{key:"parseAndValidateMacromolecules",value:function(e){var t,n,o=this,r=zc.provideEditorInstance();try{n=JSON.parse(e)}catch(e){return q.error("ketSerializer.ts::KetSerializer::parseAndValidateMacromolecules",e),{error:!0}}var i=!1;return n.root.nodes.forEach((function(e){var t=n[e.$ref];"monomer"===(null==t?void 0:t.type)&&(i=o.validateMonomerNodeTemplate(t,n,r))})),i?{error:!0}:(null===(t=n.root.connections)||void 0===t||t.forEach((function(e){o.validateConnectionTypeAndEndpoints(e,r)})),{error:i,parsedFileContent:n})}},{key:"deserializeToStruct",value:function(e){var t=new Yt,n=this.deserializeToDrawingEntities(e);return f()(n),Hu.convertDrawingEntitiesToStruct(null==n?void 0:n.drawingEntitiesManager,t),t}},{key:"filterMacromoleculesContent",value:function(e){var t,n=Gu(Gu({},e),{},{root:{nodes:e.root.nodes.filter((function(t){var n=e[t.$ref];return"monomer"!==(null==n?void 0:n.type)&&"group"!==(null==n?void 0:n.type)}))}});return e.root.nodes.forEach((function(t){var o=e[t.$ref];"monomer"!==(null==o?void 0:o.type)&&"group"!==(null==o?void 0:o.type)||(n[t.$ref]=void 0)})),null===(t=e.root.templates)||void 0===t||t.forEach((function(e){n[e.$ref]=void 0})),n}},{key:"deserializeToDrawingEntities",value:function(e){var t,n=this,o=this.parseAndValidateMacromolecules(e),r=o.error,i=o.parsedFileContent;if(!r&&i){var a=new Zo,s=new Ic,u={};i.root.nodes.forEach((function(e){var t=i[e.$ref];if("monomer"===(null==t?void 0:t.type)){var o,r=i[wu(t.templateId)];f()(r);var l=function(e,t,n,o){var r=xu(new we(e.position.x,e.position.y));return o.addMonomer({struct:n,label:t.alias||t.id,colorScheme:void 0,favorite:!1,props:{id:t.id,Name:t.fullName||t.name||t.alias||t.id,MonomerNaturalAnalogCode:t.naturalAnalogShort,MonomerName:t.fullName||t.name||t.alias||t.id,MonomerFullName:t.fullName,MonomerType:t.classHELM,MonomerClass:t.class,MonomerCaps:{}},attachmentPoints:t.attachmentPoints,seqId:e.seqid},r)}(t,r,n.fillStruct({root:{nodes:[{$ref:"mol0"}]},mol0:Gu(Gu({},r),{},{type:"molecule"}),header:{moleculeName:r.fullName}}),s),c=l.operations[0].monomer;u[e.$ref]=null==c?void 0:c.id;var d=Sn.getAttachmentPointDictFromMonomerDefinition(r.attachmentPoints||[]).attachmentPointsList;null===(o=r.attachmentPoints)||void 0===o||o.forEach((function(e,t){var n,o=null===(n=e.leavingGroup)||void 0===n?void 0:n.atoms[0],r=c.monomerItem.struct.atoms.get((0,x.isNumber)(o)?o:e.attachmentAtom);f()(r),r.rglabel=(1<<Number((e.label?e.label:d[t]).replace("R",""))-1).toString(),f()(c.monomerItem.props.MonomerCaps),c.monomerItem.props.MonomerCaps[wn(Number(r.rglabel))]=r.label,r.label="R#"})),a.merge(l)}}));var l=this.filterMacromoleculesContent(i),c=this.deserializeMicromolecules(JSON.stringify(l)),d=1;return Hu.getFragmentsGroupedBySgroup(c).forEach((function(e){var t=c.getFragment(e,!1),n=t.getCoordBoundingBox(),o=s.addMonomer({struct:t,label:"F"+d,colorScheme:void 0,favorite:!1,props:{Name:"F"+d,MonomerNaturalAnalogCode:"",MonomerName:"F"+d,MonomerType:Ys,isMicromoleculeFragment:!0}},new we(n.max.x-(n.max.x-n.min.x)/2,n.max.y-(n.max.y-n.min.y)/2));a.merge(o),d++})),null===(t=i.root.connections)||void 0===t||t.forEach((function(e){if("single"===e.connectionType){var t=function(e,t,n){var o=new Zo;f()(e.endpoint1.monomerId),f()(e.endpoint2.monomerId);var r=t.monomers.get(Number(n[e.endpoint1.monomerId])),i=t.monomers.get(Number(n[e.endpoint2.monomerId]));return f()(r),f()(i),f()(e.endpoint1.attachmentPointId),f()(e.endpoint2.attachmentPointId),o.merge(t.createPolymerBond(r,i,e.endpoint1.attachmentPointId,e.endpoint2.attachmentPointId)),o}(e,s,u);a.merge(t)}})),s.setMicromoleculesHiddenEntities(c),{modelChanges:a,drawingEntitiesManager:s}}}},{key:"deserialize",value:function(e){return this.deserializeToStruct(e)}},{key:"serializeMacromolecules",value:function(e,t){var n=this,o={root:{nodes:[],connections:[],templates:[]}};return t.monomers.forEach((function(t){if(t instanceof Fn&&t.monomerItem.props.isMicromoleculeFragment)t.monomerItem.struct.mergeInto(e);else{var i=t.monomerItem.props.id||function(e){return"".concat(e.props.MonomerName,"___").concat(e.props.Name)}(t.monomerItem),a=Eu(t.id),s=xu(new we(t.position.x,t.position.y));o[a]={type:"monomer",id:t.id.toString(),position:{x:s.x,y:s.y},alias:t.label,templateId:i,seqid:t.monomerItem.seqId},o.root.nodes.push(Pu(a));var u=$s(t.monomerItem),l=(0,r.A)(u,3)[2],c=wu(i);o[c]||(o[c]=Gu(Gu({},JSON.parse(n.serializeMicromolecules(t.monomerItem.struct,t)).mol0),{},{type:"monomerTemplate",class:t.monomerItem.props.MonomerClass||l,classHELM:t.monomerItem.props.MonomerType,id:i,fullName:t.monomerItem.props.Name,alias:t.monomerItem.label,attachmentPoints:t.monomerItem.attachmentPoints}),"CHEM"!==t.monomerItem.props.MonomerType&&(o[c].naturalAnalogShort=t.monomerItem.props.MonomerNaturalAnalogCode),o.root.templates.push(Pu(c)))}})),t.polymerBonds.forEach((function(e){var t;f()(e.secondMonomer),e.firstMonomer.monomerItem.props.isMicromoleculeFragment||e.secondMonomer.monomerItem.props.isMicromoleculeFragment||o.root.connections.push({connectionType:"single",endpoint1:{monomerId:Eu(e.firstMonomer.id),attachmentPointId:e.firstMonomer.getAttachmentPointByBond(e)},endpoint2:{monomerId:Eu(e.secondMonomer.id),attachmentPointId:null===(t=e.secondMonomer)||void 0===t?void 0:t.getAttachmentPointByBond(e)}})})),t.micromoleculesHiddenEntities.mergeInto(e),{serializedMacromolecules:o,micromoleculesStruct:e}}},{key:"serialize",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Ic,n=arguments.length>2?arguments[2]:void 0;e.enableInitiallySelected();var r=function(e,t){return t?(Object.keys(t).forEach((function(n){var o,r=t[n];null===(o=e[n])||void 0===o||o.forEach((function(e,t){"function"==typeof e.setInitiallySelected&&e.setInitiallySelected(r.includes(t)||void 0)}))})),e):e}(e,n);Hu.convertStructToDrawingEntities(r,t);var i=this.serializeMacromolecules(new Yt,t),a=i.serializedMacromolecules,s=i.micromoleculesStruct,u=JSON.parse(this.serializeMicromolecules(s));s.disableInitiallySelected();var l=Gu(Gu({},u),a);return l.root.nodes=[].concat((0,o.A)(a.root.nodes),(0,o.A)(u.root.nodes)),JSON.stringify(l,null,4)}}]),e}(),Uu={bondTypeMap:{1:We.PATTERN.TYPE.SINGLE,2:We.PATTERN.TYPE.DOUBLE,3:We.PATTERN.TYPE.TRIPLE,4:We.PATTERN.TYPE.AROMATIC,5:We.PATTERN.TYPE.SINGLE_OR_DOUBLE,6:We.PATTERN.TYPE.SINGLE_OR_AROMATIC,7:We.PATTERN.TYPE.DOUBLE_OR_AROMATIC,8:We.PATTERN.TYPE.ANY,9:We.PATTERN.TYPE.DATIVE,10:We.PATTERN.TYPE.HYDROGEN},bondStereoMap:{0:We.PATTERN.STEREO.NONE,1:We.PATTERN.STEREO.UP,4:We.PATTERN.STEREO.EITHER,6:We.PATTERN.STEREO.DOWN,3:We.PATTERN.STEREO.CIS_TRANS},v30bondStereoMap:{0:We.PATTERN.STEREO.NONE,1:We.PATTERN.STEREO.UP,2:We.PATTERN.STEREO.EITHER,3:We.PATTERN.STEREO.DOWN},bondTopologyMap:{0:We.PATTERN.TOPOLOGY.EITHER,1:We.PATTERN.TOPOLOGY.RING,2:We.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:[null,3,2,1,null,-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]},Wu={fmtInfo:Uu,paddedNum:function(e,t,n){var o=(e=parseFloat(e)).toFixed(n||0).replace(",",".");if(o.length>t)throw new Error("number does not fit");return o.padStart(t)},parseDecimalInt:function(e){var t=parseInt(e,10);return isNaN(t)?0:t},partitionLine:function(e,t,n){for(var o=[],r=0,i=0;r<t.length;++r)o.push(e.slice(i,i+t[r])),n&&i++,i+=t[r];return o},partitionLineFixed:function(e,t,n){for(var o=[],r=0;r<e.length;r+=t)o.push(e.slice(r,r+t)),n&&r++;return o},rxnMerge:function(e,t,n,o,r){var i,a=new Yt,s=[],u=[],l=[],c=[],d=[],h=[],f={cnt:0,totalLength:0};for(i=0;i<e.length;++i){var m=e[i],p=m.getBondLengthData();f.cnt+=p.cnt,f.totalLength+=p.totalLength}var v,g,y,b,A=1/(0===f.cnt?1:f.totalLength/f.cnt);for(i=0;i<e.length;++i)(m=e[i]).scale(A);for(i=0;i<e.length;++i){var w=(m=e[i]).getCoordBoundingBoxObj();if(w){var E=i<t?1:i<t+n?2:3;1===E?(s.push(w),c.push(m)):3===E?(u.push(w),d.push(m)):2===E&&(l.push(w),h.push(m)),m.atoms.forEach((function(e){e.rxnFragmentType=E}))}}function P(e,t,n,o,r){var i=new we(o-n.min.x,r?1-n.min.y:-(n.min.y+n.max.y)/2);return t.atoms.forEach((function(e){e.pp.add_(i)})),t.sgroups.forEach((function(e){e.pp&&e.pp.add_(i)})),n.min.add_(i),n.max.add_(i),t.mergeInto(e),n.max.x-n.min.x}if(r){var x=0;for(i=0;i<c.length;++i)x+=P(a,c[i],s[i],x,!1)+2;for(x+=2,i=0;i<d.length;++i)x+=P(a,d[i],u[i],x,!0)+2;for(x+=2,i=0;i<h.length;++i)x+=P(a,h[i],l[i],x,!1)+2}else{for(i=0;i<c.length;++i)c[i].mergeInto(a);for(i=0;i<d.length;++i)d[i].mergeInto(a);for(i=0;i<h.length;++i)h[i].mergeInto(a)}var S=null,O=null;for(i=0;i<s.length-1;++i)v=s[i],g=s[i+1],y=(v.max.x+g.min.x)/2,b=(v.max.y+v.min.y+g.max.y+g.min.y)/4,a.rxnPluses.add(new Bt({pp:new we(y,b)}));for(i=0;i<s.length;++i)0===i?((S={}).max=new we(s[i].max),S.min=new we(s[i].min)):(S.max=we.max(S.max,s[i].max),S.min=we.min(S.min,s[i].min));for(i=0;i<l.length-1;++i)v=l[i],g=l[i+1],y=(v.max.x+g.min.x)/2,b=(v.max.y+v.min.y+g.max.y+g.min.y)/4,a.rxnPluses.add(new Bt({pp:new we(y,b)}));for(i=0;i<l.length;++i)0===i?((O={}).max=new we(l[i].max),O.min=new we(l[i].min)):(O.max=we.max(O.max,l[i].max),O.min=we.min(O.min,l[i].min));if(g=O,(v=S)||g){var k=v?new we(v.max.x,(v.max.y+v.min.y)/2):null,M=g?new we(g.min.x,(g.max.y+g.min.y)/2):null;k||(k=new we(M.x-3,M.y)),M||(M=new we(k.x+3,k.y));var R=we.lc2(k,.5,M,.5),T=new we(R.x-1,R.y,R.z),B=new we(R.x+1,R.y,R.z);a.rxnArrows.add(new kt({mode:"open-angle",pos:[T,B]}))}else a.rxnArrows.add(new kt({mode:"open-angle",pos:[new we(0,0),new we(2,0)]}));return a.isReaction=!0,a},rgMerge:function(e,t){var n=new Yt;return e.mergeInto(n,null,null,!1,!0),Object.keys(t).forEach((function(e){for(var o=parseInt(e,10),r=function(){var e=t[o][i];e.rgroups.set(o,new At);var r=new Ke,a=e.frags.add(r);e.rgroups.get(o).frags.add(a),e.atoms.forEach((function(e){e.fragment=a})),e.mergeInto(n)},i=0;i<t[o].length;++i)r()})),n}};function qu(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return Yu(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Yu(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function Yu(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function $u(e,t){for(var n=new Gt,o=Wu.partitionLineFixed(e,3,!0),r=Wu.parseDecimalInt(o[0]),i=0;i<r;++i){var a=Wu.parseDecimalInt(o[2*i+1])-1,s=t?o[2*i+2].trim():Wu.parseDecimalInt(o[2*i+2]);n.set(a,s)}return n}function Xu(e,t,n){e.data.mul=e.data.subscript-0;var o={};e.atoms=ht.filterAtoms(e.atoms,n),e.patoms=ht.filterAtoms(e.patoms,n);for(var r=1;r<e.data.mul;++r)for(var i=0;i<e.patoms.length;++i){var a=e.atoms[r*e.patoms.length+i];if(!(a<0)){if(e.patoms[i]<0)throw new Error("parent atom missing");o[a]=e.patoms[i]}}e.patoms=ht.removeNegative(e.patoms);var s=function(e){for(var t={},n=0;n<e.length;++n)t[e[n]]=e[n];return t}(e.patoms),u=[];t.bonds.forEach((function(e,t){var n=e.begin in o,r=e.end in o;n&&r||n&&e.end in s||r&&e.begin in s?u.push(t):n?e.begin=o[e.begin]:r&&(e.end=o[e.end])}),e);for(var l=0;l<u.length;++l)t.bonds.delete(u[l]);for(var c in o)t.atoms.delete(+c),n[c]=-1;e.atoms=e.patoms,e.patoms=null}function Ku(e){e.data.connectivity=(e.data.connectivity||"EU").trim().toLowerCase()}function Zu(e){e.data.name=(e.data.subscript||"").trim(),e.data.subscript=""}function Qu(e,t,n){}function Ju(e,t){e.data.absolute||(e.pp=e.pp.add(ht.getMassCentre(t,e.atoms)))}function el(e){}function tl(e){}function nl(e){}function ol(e){}function rl(e){}function il(e){}function al(e){}function sl(e){}function ul(e){}function ll(e){}function cl(e,t){var n=Wu.partitionLine(t,[10,10,4,1,1,1,3,3,3,3,2,3,2],!1),o=parseFloat(n[0]),r=parseFloat(n[1]),i="A"===n[3].trim(),a="A"===n[4].trim(),s="U"===n[5].trim(),u=n[7].trim();u="ALL"===u?-1:Wu.parseDecimalInt(u);var l=n[10].trim(),c=Wu.parseDecimalInt(n[11].trim());e.pp=new we(o,-r),e.data.attached=i,e.data.absolute=a,e.data.showUnits=s,e.data.nCharsToDisplay=u,e.data.tagChar=l,e.data.daspPos=c}function dl(e,t,n){e.data.fieldValue=(e.data.fieldValue||"")+t,n&&(e.data.fieldValue=e.data.fieldValue.replace(/\s+$/,""),e.data.fieldValue.startsWith('"')&&e.data.fieldValue.endsWith('"')&&(e.data.fieldValue=e.data.fieldValue.substr(1,e.data.fieldValue.length-2)))}var hl={readKeyValuePairs:$u,readKeyMultiValuePairs:function(e,t){for(var n=[],o=Wu.partitionLineFixed(e,3,!0),r=Wu.parseDecimalInt(o[0]),i=0;i<r;++i)n.push([Wu.parseDecimalInt(o[2*i+1])-1,t?o[2*i+2].trim():Wu.parseDecimalInt(o[2*i+2])]);return n},loadSGroup:function(e,t,n){var o={SUP:Zu,MUL:Xu,SRU:Ku,MON:el,MER:tl,COP:nl,CRO:ol,MOD:rl,GRA:il,COM:al,MIX:sl,FOR:ul,DAT:Ju,ANY:ll,GEN:Qu};t.id=e.sgroups.add(t),o[t.type](t,e,n);for(var r=0;r<t.atoms.length;++r)e.atoms.has(t.atoms[r])&&e.atoms.get(t.atoms[r]).sgs.add(t.id);return"DAT"===t.type?e.sGroupForest.insert(t,-1,[]):e.sGroupForest.insert(t),t.id},initSGroup:function(e,t){var n,o=qu($u(t,!0));try{for(o.s();!(n=o.n()).done;){var i=(0,r.A)(n.value,2),a=i[0],s=i[1],u=new ht(s);u.number=a,e[a]=u}}catch(e){o.e(e)}finally{o.f()}},applySGroupProp:function(e,t,n,o,r){var i,a=$u(n,!o),s=qu(a.keys());try{for(s.s();!(i=s.n()).done;){var u=i.value;(r?e[u]:e[u].data)[t]=a.get(u)}}catch(e){s.e(e)}finally{s.f()}},applySGroupArrayProp:function(e,t,n,o){var r=Wu.parseDecimalInt(n.slice(1,4))-1,i=Wu.parseDecimalInt(n.slice(4,8)),a=function(e){for(var t=[],n=0;n<e.length;++n)t[n]=Wu.parseDecimalInt(e[n]);return t}(Wu.partitionLineFixed(n.slice(8),3,!0));if(a.length!==i)throw new Error("File format invalid");o&&(a=a.map((function(e){return e+o}))),e[r][t]=e[r][t].concat(a)},applyDataSGroupName:function(e,t){e.data.fieldName=t},applyDataSGroupQuery:function(e,t){e.data.query=t},applyDataSGroupQueryOp:function(e,t){e.data.queryOp=t},applyDataSGroupDesc:function(e,t){var n=Wu.partitionLine(t,[4,31,2,20,2,3],!1),o=Wu.parseDecimalInt(n[0])-1,r=n[1].trim(),i=n[2].trim(),a=n[3].trim(),s=n[4].trim(),u=n[5].trim(),l=e[o];l.data.fieldType=i,l.data.fieldName=r,l.data.units=a,l.data.query=s,l.data.queryOp=u},applyDataSGroupInfo:cl,applyDataSGroupData:dl,applyDataSGroupInfoLine:function(e,t){cl(e[Wu.parseDecimalInt(t.substr(0,4))-1],t.substr(5))},applyDataSGroupDataLine:function(e,t,n){var o=Wu.parseDecimalInt(t.substr(0,5))-1,r=t.substr(5);dl(e[o],r,n)},applyDataSGroupExpand:function(e,t){e.data.expanded=t},parseSGroupSAPLineV2000:function(e){var t=Wu.partitionLine(e.slice(0,7),[1,3,3],!1),n=(0,r.A)(t,3),o=n[1],i=n[2],a=Wu.parseDecimalInt(i);f()(a<=6);for(var s=Wu.parseDecimalInt(o)-1,u=e.slice(7),l=[],c=0;c<a;c++){var d=u.slice(11*c),h=Wu.partitionLine(d,[1,3,1,3,1,2],!1),m=(0,r.A)(h,6),p=m[1],v=m[3],g=m[5],y=Wu.parseDecimalInt(p)-1;f()(y>=0);var b=Wu.parseDecimalInt(v),A=b>0?b-1:void 0;l.push(new Qt(y,A,g))}return{sGroupId:s,attachmentPoints:l}}};function fl(e){var t=Wu.partitionLine(e,Wu.fmtInfo.atomLinePartition),n={pp:new we(parseFloat(t[0]),-parseFloat(t[1]),parseFloat(t[2])),label:t[4].trim(),explicitValence:Wu.fmtInfo.valenceMap[Wu.parseDecimalInt(t[10])],massDifference:Wu.parseDecimalInt(t[5]),charge:Wu.fmtInfo.chargeMap[Wu.parseDecimalInt(t[6])],hCount:Wu.parseDecimalInt(Wu.parseDecimalInt(t[8])),stereoCare:0!==Wu.parseDecimalInt(t[9]),aam:Wu.parseDecimalInt(t[14]),invRet:Wu.parseDecimalInt(t[15]),exactChangeFlag:Wu.parseDecimalInt(t[16])};return new Fe(n)}function ml(e){var t=Wu.partitionLine(e,Wu.fmtInfo.bondLinePartition),n={begin:Wu.parseDecimalInt(t[0])-1,end:Wu.parseDecimalInt(t[1])-1,type:Wu.fmtInfo.bondTypeMap[Wu.parseDecimalInt(t[2])],stereo:Wu.fmtInfo.bondStereoMap[Wu.parseDecimalInt(t[3])],xxx:t[4],topology:Wu.fmtInfo.bondTopologyMap[Wu.parseDecimalInt(t[5])],reactingCenterStatus:Wu.parseDecimalInt(t[6])};return new We(n)}function pl(e){for(var t=Wu.partitionLine(e,Wu.fmtInfo.atomListHeaderPartition),n=Wu.parseDecimalInt(t[0])-1,o="T"===t[2].trim(),r=Wu.parseDecimalInt(t[4].trim()),i=e.slice(Wu.fmtInfo.atomListHeaderLength),a=[],s=Wu.fmtInfo.atomListHeaderItemLength,u=0;u<r;++u)a[u]=Wu.parseDecimalInt(i.slice(u*s,(u+1)*s-1));return{aid:n,atomList:new z({notList:o,ids:a})}}function vl(e,t,n){var o,r=new Yt,i=Wu.parseDecimalInt(t[0]),a=Wu.parseDecimalInt(t[1]),s=Wu.parseDecimalInt(t[2]),u=1===Wu.parseDecimalInt(t[4])||n,l=0===Wu.parseDecimalInt(t[4])&&!n,c=Wu.parseDecimalInt(t[5]),d=Wu.parseDecimalInt(t[10]),h=0,f=e.slice(h,h+i);h+=i;var m=e.slice(h,h+a);h+=a;var p=e.slice(h,h+s);h+=s+c,f.map(fl).forEach((function(e){return r.atoms.add(e)})),m.map(ml).forEach((function(e){e.stereo&&u&&(r.atoms.get(e.begin).stereoLabel=ke.Abs),e.stereo&&l&&(r.atoms.get(e.begin).stereoLabel="".concat(ke.And,"1")),r.bonds.add(e)})),p.map(pl).forEach((function(e){r.atoms.get(e.aid).atomList=e.atomList,r.atoms.get(e.aid).label="L#"}));var v={},g={};(function(e,t,n,o,r,i){for(var a=new Gt,s=function(){var e,o,s,u,l,c,d,h=t[n];if("A"===h.charAt(0)){var f=t[++n],m=/'.+'/.test(f);m&&!a.get("pseudo")&&a.set("pseudo",new Gt),m||a.get("alias")||a.set("alias",new Gt),a.get(m?"pseudo":"alias").set(Wu.parseDecimalInt(h.slice(3))-1,f)}else if("M"===h.charAt(0)){var p=h.slice(3,6),v=h.slice(6);if("END"===p)return 1;if("CHG"===p)a.get("charge")||a.set("charge",hl.readKeyValuePairs(v));else if("RAD"===p)a.get("radical")||a.set("radical",hl.readKeyValuePairs(v));else if("ISO"===p)a.get("isotope")||a.set("isotope",hl.readKeyValuePairs(v));else if("RBC"===p)a.get("ringBondCount")||a.set("ringBondCount",hl.readKeyValuePairs(v));else if("SUB"===p)a.get("substitutionCount")||a.set("substitutionCount",hl.readKeyValuePairs(v));else if("UNS"===p)a.get("unsaturatedAtom")||a.set("unsaturatedAtom",hl.readKeyValuePairs(v));else if("RGP"===p){a.get("rglabel")||a.set("rglabel",new Gt);for(var g=a.get("rglabel"),y=hl.readKeyMultiValuePairs(v),b=0;b<y.length;b++){var A=y[b];g.set(A[0],(g.get(A[0])||0)|1<<A[1]-1)}}else if("LOG"===p){v=v.slice(4);var w=Wu.parseDecimalInt(v.slice(0,3).trim()),E=Wu.parseDecimalInt(v.slice(4,7).trim()),P=Wu.parseDecimalInt(v.slice(8,11).trim()),x=v.slice(12).trim(),S={};E>0&&(S.ifthen=E),S.resth=1===P,S.range=x,i[w]=S}else if("APO"===p)a.get("attachmentPoints")||a.set("attachmentPoints",hl.readKeyValuePairs(v));else if("ALS"===p){var O=(e=Wu.partitionLine(v,[1,3,3,1,1,1]),o=Wu.partitionLineFixed(v.slice(10),4,!1),s=Wu.parseDecimalInt(e[1])-1,u=Wu.parseDecimalInt(e[2]),l="T"===e[4].trim(),c=function(e){for(var t=[],n=0;n<e.length;++n){var o=_.get(e[n].trim());o&&t.push(o.number)}return t}(o.slice(0,u)),(d=new Gt).set(s,new z({notList:l,ids:c})),d);a.get("atomList")||a.set("atomList",new Gt),a.get("label")||a.set("label",new Gt),O.forEach((function(e,t){a.get("label").set(t,"L#"),a.get("atomList").set(t,e)}))}else if("STY"===p)hl.initSGroup(r,v);else if("SST"===p)hl.applySGroupProp(r,"subtype",v);else if("SLB"===p)hl.applySGroupProp(r,"label",v,!0);else if("SPL"===p)hl.applySGroupProp(r,"parent",v,!0,!0);else if("SCN"===p)hl.applySGroupProp(r,"connectivity",v);else if("SAL"===p)hl.applySGroupArrayProp(r,"atoms",v,-1);else if("SBL"===p)hl.applySGroupArrayProp(r,"bonds",v,-1);else if("SPA"===p)hl.applySGroupArrayProp(r,"patoms",v,-1);else if("SMT"===p){var k=Wu.parseDecimalInt(v.slice(0,4))-1;r[k].data.subscript=v.slice(4).trim()}else if("SDT"===p)hl.applyDataSGroupDesc(r,v);else if("SDD"===p)hl.applyDataSGroupInfoLine(r,v);else if("SCD"===p)hl.applyDataSGroupDataLine(r,v,!1);else if("SED"===p)hl.applyDataSGroupDataLine(r,v,!0);else if("SDS"===p)v.slice(7).trim().split(" ").forEach((function(e){var t=Number(e)-1;r[t].data.expanded=!0}));else if("SAP"===p){var M=hl.parseSGroupSAPLineV2000(v),R=M.sGroupId;M.attachmentPoints.forEach((function(e){r[R].addAttachmentPoint(e)}))}}++n};n<o&&!s(););return a})(0,e,h,Math.min(e.length,h+d),v,g).forEach((function(e,t){!function(e,t,n){t.forEach((function(t,o){e.get(o)[n]=t}))}(r.atoms,e,t)}));var y,b={};for(y in v){var A=v[y];if("DAT"===A.type&&0===A.atoms.length){var w=v[y].parent;if(w>=0){var E=v[w-1];"GEN"===E.type&&(A.atoms=[].slice.call(E.atoms))}}}for(y in v)hl.loadSGroup(r,v[y],b);var P=[];for(y in v)ht.filter(r,v[y],b),0!==v[y].atoms.length||v[y].allAtoms||P.push(+y);for(o=0;o<P.length;++o)r.sGroupForest.remove(P[o]),r.sgroups.delete(P[o]);for(var x in g){var S=parseInt(x,10);r.rgroups.set(S,new At(g[S]))}return r}function gl(e,t){if("$CTAB"!==(e=e.slice(7))[0].trim())throw new Error("RGFile format invalid");for(var n=1;"$"!==e[n].charAt(0);)n++;if("$END CTAB"!==e[n].trim())throw new Error("RGFile format invalid");var o=e.slice(1,n);e=e.slice(n+1);for(var r={};;){if(0===e.length)throw new Error("Unexpected end of file");var i=e[0].trim();if("$END MOL"===i){e=e.slice(1);break}if("$RGP"!==i)throw new Error("RGFile format invalid");var a=parseInt(e[1].trim(),10);for(r[a]=[],e=e.slice(2);;){if(0===e.length)throw new Error("Unexpected end of file");if("$END RGP"===(i=e[0].trim())){e=e.slice(1);break}if("$CTAB"!==i)throw new Error("RGFile format invalid");for(n=1;"$"!==e[n].charAt(0);)n++;if("$END CTAB"!==e[n].trim())throw new Error("RGFile format invalid");r[a].push(e.slice(1,n)),e=e.slice(n+1)}}var s=yl(o,t),u={};for(var l in r){var c=parseInt(l,10);u[c]=[];for(var d=0;d<r[c].length;++d)u[c].push(yl(r[c][d],t))}return Wu.rgMerge(s,u)}function yl(e,t){var n=Wu.partitionLine(e[0],Wu.fmtInfo.countsLinePartition);return vl(e=e.slice(1),n,t)}var bl={parseCTabV2000:vl,parseRg2000:gl,parseRxn2000:function(e,t,n){e=e.slice(4);var o=Wu.partitionLine(e[0],Wu.fmtInfo.rxnItemsPartition),r=o[0]-0,i=o[1]-0,a=o[2]-0;e=e.slice(1);for(var s=[];e.length>0&&"$MOL"===e[0].substr(0,4);){e=e.slice(1);for(var u=0;u<e.length&&"$MOL"!==e[u].substr(0,4);)u++;var l,c=e.slice(0,u);0===c[0].search("\\$MDL")?l=gl(c,n):(l=yl(c.slice(3),n)).name=c[0].trim(),s.push(l),e=e.slice(u)}return Wu.rxnMerge(s,r,i,a,t)}};function Al(e){var t,n,o,i,a=Ol(e),s={pp:new we(parseFloat(a[2]),-parseFloat(a[3]),parseFloat(a[4])),aam:a[5].trim()},u=a[1].trim();if('"'===u.charAt(0)&&'"'===u.charAt(u.length-1)&&(u=u.substr(1,u.length-2)),"]"===u.charAt(u.length-1)){var l={notList:!1},c=(u=u.substr(0,u.length-1)).match(/NOT ?\[/);if(c){l.notList=!0;var d=(0,r.A)(c,1)[0];u=u.substr(d.length)}else{if("["!==u.charAt(0))throw new Error("Error: atom list expected, found '"+u+"'");u=u.substr(1)}l.ids=function(e){for(var t=[],n=0;n<e.length;++n){var o=_.get(e[n].trim());o&&t.push(o.number)}return t}(u.split(",")),s.atomList=new z(l),s.label="L#"}else s.label=u;for(a.splice(0,6),i=0;i<a.length;++i)if(n=(t=kl(a[i],"="))[0],o=t[1],n in Wu.fmtInfo.v30atomPropMap){var h=Wu.parseDecimalInt(o);if("VAL"===n){if(0===h)continue;-1===h&&(h=0)}s[Wu.fmtInfo.v30atomPropMap[n]]=h}else if("RGROUPS"===n){var f=(o=o.trim().substr(1,o.length-2)).split(" ").slice(1);s.rglabel=0;for(var m=0;m<f.length;++m)s.rglabel|=1<<f[m]-1}else"ATTCHPT"===n&&(s.attpnt=o.trim()-0);return new Fe(s)}function wl(e){var t,n,o,r,i=Ol(e),a={begin:Wu.parseDecimalInt(i[2])-1,end:Wu.parseDecimalInt(i[3])-1,type:Wu.fmtInfo.bondTypeMap[Wu.parseDecimalInt(i[1])]};for(i.splice(0,4),r=0;r<i.length;++r)n=(t=kl(i[r],"="))[0],o=t[1],"CFG"===n?(a.stereo=Wu.fmtInfo.v30bondStereoMap[Wu.parseDecimalInt(o)],a.type===We.PATTERN.TYPE.DOUBLE&&a.stereo===We.PATTERN.STEREO.EITHER&&(a.stereo=We.PATTERN.STEREO.CIS_TRANS)):"TOPO"===n?a.topology=Wu.fmtInfo.bondTopologyMap[Wu.parseDecimalInt(o)]:"RXCTR"===n?a.reactingCenterStatus=Wu.parseDecimalInt(o):"STBOX"===n&&(a.stereoCare=Wu.parseDecimalInt(o));return new We(a)}function El(e,t,n){for(n++;"M V30 END COLLECTION"!==t[n].trim();)n++;return++n}function Pl(e,t,n,o,r){var i,a="";for(r++;r<t.length;){if("END SGROUP"===(a=Tl(t[r++]).trim()).trim())return r;for(;"-"===a.charAt(a.length-1);)a=(a.substr(0,a.length-1)+Tl(t[r++])).trim();var s=Ml(a),u=s[1],l=new ht(u);l.number=s[0]-0,l.type=u,l.label=s[2]-0,n[l.number]=l;for(var c={},d=3;d<s.length;++d){var h=kl(s[d],"=");if(2!==h.length)throw new Error("A record of form AAA=BBB or AAA=(...) expected, got '"+s[d]+"'");var f=h[0];f in c||(c[f]=[]),c[f].push(h[1])}l.atoms=Rl(c.ATOMS[0],-1),c.PATOMS&&(l.patoms=Rl(c.PATOMS[0],-1)),l.bonds=c.BONDS?Rl(c.BONDS[0],-1):[];var m=c.BRKXYZ;if(l.brkxyz=[],m)for(var p=0;p<m.length;++p)l.brkxyz.push(Rl(m[p]));c.MULT&&(l.data.subscript=c.MULT[0]-0),c.LABEL&&(l.data.subscript=c.LABEL[0].trim()),c.CONNECT&&(l.data.connectivity=c.CONNECT[0].toLowerCase()),c.FIELDDISP&&hl.applyDataSGroupInfo(l,'"'===(i=c.FIELDDISP[0])[0]&&'"'===i[i.length-1]?i.substr(1,i.length-2):i),c.FIELDDATA&&hl.applyDataSGroupData(l,c.FIELDDATA[0],!0),c.FIELDNAME&&hl.applyDataSGroupName(l,c.FIELDNAME[0]),c.QUERYTYPE&&hl.applyDataSGroupQuery(l,c.QUERYTYPE[0]),c.QUERYOP&&hl.applyDataSGroupQueryOp(l,c.QUERYOP[0]),hl.loadSGroup(e,l,o),c.ESTATE&&hl.applyDataSGroupExpand(l,c.ESTATE[0])}throw new Error("S-group declaration incomplete.")}function xl(e,t){var n=new Yt,o=0;if("M V30 BEGIN CTAB"!==e[o++].trim())throw Error("CTAB V3000 invalid");if("M V30 COUNTS"!==e[o].slice(0,13))throw Error("CTAB V3000 invalid");var r=e[o].slice(14).split(" "),i=1===Wu.parseDecimalInt(r[4]);if("M V30 BEGIN ATOM"===e[++o].trim()){var a;for(o++;o<e.length&&"END ATOM"!==(a=Tl(e[o++]).trim());){for(;"-"===a.charAt(a.length-1);)a=(a.substring(0,a.length-1)+Tl(e[o++])).trim();n.atoms.add(Al(a))}if("M V30 BEGIN BOND"===e[o].trim())for(o++;o<e.length&&"END BOND"!==(a=Tl(e[o++]).trim());){for(;"-"===a.charAt(a.length-1);)a=(a.substring(0,a.length-1)+Tl(e[o++])).trim();var s=wl(a);s.stereo&&i&&(n.atoms.get(s.begin).stereoLabel="abs"),n.bonds.add(s)}for(var u={},l={};"M V30 END CTAB"!==e[o].trim();)if("M V30 BEGIN COLLECTION"===e[o].trim())o=El(0,e,o);else{if("M V30 BEGIN SGROUP"!==e[o].trim())throw Error("CTAB V3000 invalid");o=Pl(n,e,u,l,o)}}if("M V30 END CTAB"!==e[o++].trim())throw Error("CTAB V3000 invalid");return t||Sl(n,e.slice(o)),n}function Sl(e,t){for(var n={},o={},r=0;r<t.length&&0===t[r].search("M V30 BEGIN RGROUP");){var i=t[r++].split(" ").pop();for(n[i]=[],o[i]={};;){var a=t[r].trim();if(0!==a.search("M V30 RLOGIC")){if("M V30 BEGIN CTAB"!==a)throw Error("CTAB V3000 invalid");for(var s=0;s<t.length&&"M V30 END CTAB"!==t[r+s].trim();++s);var u=xl(t.slice(r,r+s+1),!0);if(n[i].push(u),"M V30 END RGROUP"===t[r=r+s+1].trim()){r++;break}}else{var l=(a=a.slice(13)).trim().split(/\s+/g),c=Wu.parseDecimalInt(l[0]),d=Wu.parseDecimalInt(l[1]),h=l.slice(2).join(" "),f={};c>0&&(f.ifthen=c),f.resth=1===d,f.range=h,o[i]=f,r++}}}Object.keys(n).forEach((function(t){n[t].forEach((function(n){n.rgroups.set(t,new At(o[t]));var r=n.frags.add({});n.rgroups.get(t).frags.add(r),n.atoms.forEach((function(e){e.fragment=r})),n.mergeInto(e)}))}))}function Ol(e){for(var t=[],n=0,o=0,r=-1,i=!1;o<e.length;o+=1){var a=e[o];if("NOT"===e.substr(o,3)){var s=e.indexOf("]");t.push(e.slice(o,s+1)),r=o=s+1}else"("===a?n+=1:")"===a?n-=1:'"'===a?i=!i:i||" "!==e[o]||0!==n||(o>r+1&&t.push(e.slice(r+1,o)),r=o)}return o>r+1&&t.push(e.slice(r+1,o)),t}function kl(e,t){var n=e.indexOf(t);return[e.slice(0,n),e.slice(n+1)]}function Ml(e){for(var t=[],n=0,o=!1,r=0;r<e.length;++r){var i=e.charAt(r);'"'===i?o=!o:o||("("===i?n++:")"===i?n--:" "===i&&0===n&&(t.push(e.slice(0,r)),e=e.slice(r+1).trim(),r=0))}if(0!==n)throw new Error("Brace balance broken. S-group properies invalid!");return e.length>0&&t.push(e.trim()),t}function Rl(e,t){if(!e)return null;var n=[],o=(e=(e=e.trim()).substr(1,e.length-2)).split(" ");t=t||0;for(var r=1;r<o.length;++r){var i=parseInt(o[r]);isNaN(i)||n.push(i+t)}return n}function Tl(e){if("M V30 "!==e.slice(0,7))throw new Error("Prefix invalid");return e.slice(7)}var Bl={parseCTabV3000:xl,readRGroups3000:Sl,parseRxn3000:function(e,t){var n=(e=e.slice(4))[0].split(/\s+/g).slice(3),o=n[0]-0,r=n[1]-0,i=n.length>2?n[2]-0:0;function a(t){for(var n=t;n<e.length;++n)if("M V30 END CTAB"===e[n].trim())return n}function s(t){for(var n=t;n<e.length;++n)if("M V30 END RGROUP"===e[n].trim())return n}for(var u=[],l=[],c=[],d=null,h=[],f=0;f<e.length;++f){var m,p=e[f].trim();if(p.startsWith("M V30 COUNTS"));else{if("M END"===p)break;if("M V30 BEGIN PRODUCT"===p)d=l;else if("M V30 END PRODUCT"===p)d=null;else if("M V30 BEGIN REACTANT"===p)d=u;else if("M V30 END REACTANT"===p)d=null;else if("M V30 BEGIN AGENT"===p)d=c;else if("M V30 END AGENT"===p)d=null;else if(p.startsWith("M V30 BEGIN RGROUP"))m=s(f),h.push(e.slice(f,m+1)),f=m;else{if("M V30 BEGIN CTAB"!==p)throw new Error("line unrecognized: "+p);m=a(f),d.push(e.slice(f,m+1)),f=m}}}var v=[],g=u.concat(l).concat(c);for(m=0;m<g.length;++m){var y=xl(g[m],n);v.push(y)}var b=Wu.rxnMerge(v,o,r,i,t);return Sl(b,function(e){for(var t=[],n=0;n<e.length;++n)t=t.concat(e[n]);return t}(h)),b}};function Cl(e,t){var n=function(e,t,n){for(var o=[],r=0,i=0;r<t.length;++r)o.push(e.slice(i,i+t[r])),i+=t[r];return o}(e[0],Wu.fmtInfo.countsLinePartition),o=n[11].trim();if(e=e.slice(1),"V2000"===o)return bl.parseCTabV2000(e,n,t);if("V3000"===o)return Bl.parseCTabV3000(e,!1);throw new Error("Molfile version unknown: "+o)}var Il={MUL:ht.prepareMulForSaving,SRU:function(e,t){var n=[];if(t.bonds.forEach((function(o,r){var i=t.atoms.get(o.begin),a=t.atoms.get(o.end);(i.sgs.has(e.id)&&!a.sgs.has(e.id)||a.sgs.has(e.id)&&!i.sgs.has(e.id))&&n.push(r)}),e),0!==n.length&&2!==n.length)throw{id:e.id,"error-type":"cross-bond-number",message:"Unsupported cross-bonds number"};e.bonds=n},SUP:function(e,t){var n=[];t.bonds.forEach((function(o,r){var i=t.atoms.get(o.begin),a=t.atoms.get(o.end);(i.sgs.has(e.id)&&!a.sgs.has(e.id)||a.sgs.has(e.id)&&!i.sgs.has(e.id))&&n.push(r)}),e),e.bonds=n},DAT:function(e,t){e.atoms=ht.getAtoms(t,e)},GEN:function(e,t){},queryComponent:function(e,t){}},Nl={MUL:function(e,t,n,o,r){var i=(n[e.id]+"").padStart(3),a=[];a=(a=(a=a.concat(Dl("SAL",i,Array.from(e.atomSet.values()),o))).concat(Dl("SPA",i,Array.from(e.parentAtomSet.values()),o))).concat(Dl("SBL",i,e.bonds,r));var s="M SMT "+i+" "+e.data.mul;return a.push(s),(a=a.concat(Ll(t,e,i))).join("\n")},SRU:function(e,t,n,o,r){var i=(n[e.id]+"").padStart(3),a=[];return(a=(a=(a=a.concat(Dl("SAL",i,e.atoms,o))).concat(Dl("SBL",i,e.bonds,r))).concat(Ll(t,e,i))).join("\n")},SUP:function(e,t,n,o,r){var i=(n[e.id]+"").padStart(3),a=[];return a=(a=a.concat(Dl("SAL",i,e.atoms,o))).concat(Dl("SBL",i,e.bonds,r)),e.data.name&&""!==e.data.name&&a.push("M SMT "+i+" "+e.data.name),a.join("\n")},DAT:function(e,t,n,o){var r=(n[e.id]+"").padStart(3),i=e.data,a=e.pp;i.absolute||(a=a.sub(ht.getMassCentre(t,e.atoms)));var s=[];s=s.concat(Dl("SAL",r,e.atoms,o));var u="M SDT "+r+" "+(i.fieldName||"").padEnd(30)+(i.fieldType||"").padStart(2)+(i.units||"").padEnd(20)+(i.query||"").padStart(2);i.queryOp&&(u+=i.queryOp.padEnd(15)),s.push(u);var l,c="M SDD "+r+" "+Wu.paddedNum(a.x,10,4)+Wu.paddedNum(-a.y,10,4)+" "+(i.attached?"A":"D")+(i.absolute?"A":"R")+(i.showUnits?"U":" ")+" "+(i.nCharnCharsToDisplay>=0?Wu.paddedNum(i.nCharnCharsToDisplay,3):"ALL")+" 1 "+(i.tagChar||" ")+" "+Wu.paddedNum(i.daspPos,1)+" ";return s.push(c),(l=i.fieldValue,l.replace(_l,"\n")).replace(/\n*$/,"").split("\n").forEach((function(e){for(;e.length>69;)s.push("M SCD "+r+" "+e.slice(0,69)),e=e.slice(69);s.push("M SED "+r+" "+e)})),s.join("\n")},GEN:function(e,t,n,o,r){var i=(n[e.id]+"").padStart(3),a=[];return(a=(a=(a=a.concat(Dl("SAL",i,e.atoms,o))).concat(Dl("SBL",i,e.bonds,r))).concat(Ll(t,e,i))).join("\n")}};function Dl(e,t,n,o){if(!n)return[];for(var r=[],i=0;i<Math.floor((n.length+14)/15);++i){for(var a=Math.min(n.length-15*i,15),s="M "+e+" "+t+" "+Wu.paddedNum(a,2),u=0;u<a;++u)s+=" "+Wu.paddedNum(o[n[15*i+u]],3);r.push(s)}return r}function Ll(e,t,n){var o=new Re(t.atoms),r=ht.getCrossBonds(e,o);ht.bracketPos(t,e,r);for(var i=t.bracketBox,a=t.bracketDirection,s=a.rotateSC(1,0),u=ht.getBracketParameters(e,r,o,i,a,s),l=[],c=0;c<u.length;++c){for(var d=u[c],h=d.c.addScaled(d.n,-.5*d.h).yComplement(),f=d.c.addScaled(d.n,.5*d.h).yComplement(),m="M SDI "+n+Wu.paddedNum(4,3),p=[h.x,h.y,f.x,f.y],v=0;v<p.length;++v)m+=Wu.paddedNum(p[v],10,4);l.push(m)}return l}var _l=/\r\n|[\n\r]/g,Fl={parseCTab:Cl,parseMol:function(e,t){if(0===e[0].search("\\$MDL")){var n=bl.parseRg2000(e,t);return n.name=e[3].trim(),n}var o=Cl(e.slice(3),t);return o.name=e[0].trim(),o},parseRxn:function(e,t,n){var o=e[0].trim().split(" ");if(o.length>1&&"V3000"===o[1])return Bl.parseRxn3000(e,t);var r=bl.parseRxn2000(e,t,n);return r.name=e[1].trim(),r},prepareForSaving:Il,saveToMolfile:Nl},Hl=function(){function e(){(0,i.A)(this,e),this.molecule=null,this.molfile=null,this.reaction=!1,this.mapping={},this.bondMapping={}}return(0,a.A)(e,[{key:"parseCTFile",value:function(e){var t,n=e.molfileLines,o=e.shouldReactionRelayout,r=e.ignoreChiralFlag;return(t=0===n[0].search("\\$RXN")?Fl.parseRxn(n,o,r):Fl.parseMol(n,r)).initHalfBonds(),t.initNeighbors(),t.bindSGroupsToFunctionalGroups(),t.markFragments(),t}},{key:"prepareSGroups",value:function(e,t){var n,o=this.molecule,r=[],i=0;if(null===(n=this.molecule)||void 0===n||n.sGroupForest.getSGroupsBFS().reverse().forEach((function(n){var a=o.sgroups.get(n),s=!1;try{Fl.prepareForSaving[a.type](a,o)}catch(t){if(q.error("molfile.ts::Molfile::prepareSGroups",t),!e||"number"!=typeof t.id)throw new Error("Error: ".concat(t.message));s=!0}(s||!t&&/^INDIGO_.+_DESC$/i.test(a.data.fieldName))&&(i+=+s,r.push(a.id))}),this),i)throw new Error("Warning: "+i+" invalid S-groups were detected. They will be omitted.");for(var a=0;a<r.length;++a)null==o||o.sGroupDelete(r[a])}},{key:"getCTab",value:function(e,t){return this.molecule=e.clone(),this.prepareSGroups(!1,!1),this.molfile="",this.writeCTab2000(t),this.molfile}},{key:"saveMolecule",value:function(t,n,o,r,i){var a=this;if(this.reaction=t.hasRxnArrow(),this.molfile=""+t.name,this.reaction){if(t.rgroups.size>0)throw new Error("Reactions with r-groups are not supported at the moment");var s=t.getComponents(),u=s.reactants,l=s.products,c=u.concat(l);this.molfile="$RXN\n"+t.name+"\n\n\n"+Wu.paddedNum(u.length,3)+Wu.paddedNum(l.length,3)+Wu.paddedNum(0,3)+"\n";for(var d=0;d<c.length;++d){var h=new e,f=t.clone(c[d],null,!0),m=h.saveMolecule(f,!1,!0);this.molfile+="$MOL\n"+m}return this.molfile}if(t.rgroups.size>0){if(!o){var p=(new e).getCTab(t.getScaffold(),t.rgroups);return this.molfile="$MDL REV 1\n$MOL\n$HDR\n"+t.name+"\n\n\n$END HDR\n",this.molfile+="$CTAB\n"+p+"$END CTAB\n",t.rgroups.forEach((function(n,o){a.molfile+="$RGP\n",a.writePaddedNumber(o,3),a.molfile+="\n",n.frags.forEach((function(n){var o=(new e).getCTab(t.getFragment(n));a.molfile+="$CTAB\n"+o+"$END CTAB\n"})),a.molfile+="$END RGP\n"})),this.molfile+="$END MOL\n",this.molfile}t=t.getScaffold()}return this.molecule=t.clone(),this.prepareSGroups(n,r),this.writeHeader(),this.writeCTab2000(void 0,i),this.molfile}},{key:"writeHeader",value:function(){var e=new Date;this.writeCR(),this.writeWhiteSpace(2),this.write("Ketcher"),this.writeWhiteSpace(),this.writeCR((e.getMonth()+1+"").padStart(2)+(e.getDate()+"").padStart(2)+(e.getFullYear()%100+"").padStart(2)+(e.getHours()+"").padStart(2)+(e.getMinutes()+"").padStart(2)+"2D 1 1.00000 0.00000 0"),this.writeCR()}},{key:"write",value:function(e){this.molfile+=e}},{key:"writeCR",value:function(e){0===arguments.length&&(e=""),this.molfile+=e+"\n"}},{key:"writeWhiteSpace",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;0===arguments.length&&(e=1),this.write(" ".repeat(Math.max(e,0)))}},{key:"writePadded",value:function(e,t){this.write(e),this.writeWhiteSpace(t-e.length)}},{key:"writePaddedNumber",value:function(e,t){var n=(e-0).toString();this.writeWhiteSpace(t-n.length),this.write(n)}},{key:"writePaddedFloat",value:function(e,t,n){this.write(Wu.paddedNum(e,t,n))}},{key:"writeCTab2000Header",value:function(e){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(e){return!!e&&e.enhancedStereoFlag===Ue.Abs}));this.writePaddedNumber(t||e?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(e,t){var n=this;this.writeCTab2000Header(t),this.mapping={};var o=1,r=[],i=[];for(this.molecule.atoms.forEach((function(e,t){var a=e.label;null!=e.atomList?(a="L",r.push(t)):e.pseudo?e.pseudo.length>3&&(a="A",i.push({id:t,value:"'".concat(e.pseudo,"'")})):e.alias?i.push({id:t,value:e.alias}):_.get(e.label)||-1!==["A","Q","X","*","R#"].indexOf(e.label)||(a="C",i.push({id:t,value:e.label})),n.writeAtom(e,a),n.mapping[t]=o++}),this),this.bondMapping={},o=1,this.molecule.bonds.forEach((function(e,t){n.bondMapping[t]=o++,n.writeBond(e)}),this);i.length>0;)this.writeAtomProps(i[0]),i.splice(0,1);var a=[],s=[],u=[],l=[],c=[],d=[],h=[],f=[],m=[];this.molecule.atoms.forEach((function(e,t){if(0!==e.charge&&null!==e.charge&&a.push([t,e.charge]),0!==e.isotope&&null!==e.isotope&&s.push([t,e.isotope]),0!==e.radical&&u.push([t,e.radical]),null!=e.rglabel&&"R#"===e.label)for(var n=0;n<32;n++)e.rglabel&1<<n&&l.push([t,n+1]);null!=e.attachmentPoints&&d.push([t,e.attachmentPoints]),0!==e.ringBondCount&&h.push([t,e.ringBondCount]),0!==e.substitutionCount&&m.push([t,e.substitutionCount]),0!==e.unsaturatedAtom&&f.push([t,e.unsaturatedAtom])})),e&&e.forEach((function(e,t){if(e.resth||e.ifthen>0||e.range.length>0){var n=" 1 "+Wu.paddedNum(t,3)+" "+Wu.paddedNum(e.ifthen,3)+" "+Wu.paddedNum(e.resth?1:0,3)+" "+e.range;c.push(n)}})),this.writeAtomPropList("M CHG",a),this.writeAtomPropList("M ISO",s),this.writeAtomPropList("M RAD",u),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",d),this.writeAtomPropList("M RBC",h),this.writeAtomPropList("M SUB",m),this.writeAtomPropList("M UNS",f),r.length>0)for(var v=0;v<r.length;++v){var g=r[v],y=this.molecule.atoms.get(g).atomList;this.write("M ALS"),this.writePaddedNumber(g+1,4),this.writePaddedNumber(y.ids.length,3),this.writeWhiteSpace(),this.write(y.notList?"T":"F");for(var b=y.labelList(),A=0;A<b.length;++A)this.writeWhiteSpace(),this.writePadded(b[A],3);this.writeWhiteSpace(),this.writeCR()}var w={},E=1,P={};this.molecule.sGroupForest.getSGroupsBFS().forEach((function(e){P[E]=e,w[e]=E++}));for(var x=function(e){var t=P[e],o=n.molecule.sgroups.get(t);if(ht.isQuerySGroup(o))return 1;n.write("M STY"),n.writePaddedNumber(1,3),n.writeWhiteSpace(1),n.writePaddedNumber(e,3),n.writeWhiteSpace(1),n.writePadded(o.type,3),n.writeCR(),n.write("M SLB"),n.writePaddedNumber(1,3),n.writeWhiteSpace(1),n.writePaddedNumber(e,3),n.writeWhiteSpace(1),n.writePaddedNumber(e,3),n.writeCR();var r=n.molecule.sGroupForest.parent.get(t);if(r>=0&&(n.write("M SPL"),n.writePaddedNumber(1,3),n.writeWhiteSpace(1),n.writePaddedNumber(e,3),n.writeWhiteSpace(1),n.writePaddedNumber(w[r],3),n.writeCR()),"SRU"===o.type&&o.data.connectivity){var i=" ".concat(e.toString().padStart(3)," ").concat((o.data.connectivity||"").padEnd(3));n.write("M SCN"),n.writePaddedNumber(1,3),n.write(i.toUpperCase()),n.writeCR()}"SRU"===o.type&&(n.write("M SMT "),n.writePaddedNumber(e,3),n.writeWhiteSpace(),n.write(o.data.subscript||"n"),n.writeCR()),o.getAttachmentPoints().forEach((function(t){n.writeSGroupAttachmentPointLine(e,t)})),n.writeCR(Fl.saveToMolfile[o.type](o,n.molecule,w,n.mapping,n.bondMapping))},S=1;S<E;++S)x(S);var O=[];if(this.molecule.sgroups.forEach((function(e){e.isExpanded()&&!ht.isQuerySGroup(e)&&O.push(e.id+1)})),O.length){var k="M SDS EXP ".concat(O.length," ").concat(O.join(" "));this.writeCR(k)}this.writeCR("M END")}},{key:"writeAtom",value:function(e,t){var n;this.writePaddedFloat(e.pp.x,10,4),this.writePaddedFloat(-e.pp.y,10,4),this.writePaddedFloat(e.pp.z,10,4),this.writeWhiteSpace(),this.writePadded(t,3),this.writePaddedNumber(0,2),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),void 0===e.hCount&&(e.hCount=0),this.writePaddedNumber(e.hCount,3),void 0===e.stereoCare&&(e.stereoCare=0),this.writePaddedNumber(e.stereoCare,3),n=e.explicitValence<0?0:0===e.explicitValence?15:e.explicitValence,this.writePaddedNumber(n,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),void 0===e.aam&&(e.aam=0),this.writePaddedNumber(e.aam,3),void 0===e.invRet&&(e.invRet=0),this.writePaddedNumber(e.invRet,3),void 0===e.exactChangeFlag&&(e.exactChangeFlag=0),this.writePaddedNumber(e.exactChangeFlag,3),this.writeCR()}},{key:"writeBond",value:function(e){this.writePaddedNumber(this.mapping[e.begin],3),this.writePaddedNumber(this.mapping[e.end],3),this.writePaddedNumber(e.type,3),void 0===e.stereo&&(e.stereo=0),this.writePaddedNumber(e.stereo,3),this.writePadded(e.xxx,3),void 0===e.topology&&(e.topology=0),this.writePaddedNumber(e.topology,3),void 0===e.reactingCenterStatus&&(e.reactingCenterStatus=0),this.writePaddedNumber(e.reactingCenterStatus,3),this.writeCR()}},{key:"writeAtomProps",value:function(e){this.write("A "),this.writePaddedNumber(e.id+1,3),this.writeCR(),this.writeCR(e.value)}},{key:"writeAtomPropList",value:function(e,t){for(var n=this;t.length>0;){for(var o=[];t.length>0&&o.length<8;)o.push(t[0]),t.splice(0,1);this.write(e),this.writePaddedNumber(o.length,3),o.forEach((function(e){n.writeWhiteSpace(),n.writePaddedNumber(n.mapping[e[0]],3),n.writeWhiteSpace(),n.writePaddedNumber(e[1],3)})),this.writeCR()}}},{key:"writeSGroupAttachmentPointLine",value:function(e,t){var n;this.write("M SAP"),this.writeWhiteSpace(1),this.writePaddedNumber(e,3),this.writePaddedNumber(1,3),this.writeWhiteSpace(1);var o=this.mapping[t.atomId];this.writePaddedNumber(o,3),this.writeWhiteSpace(1);var r=null!==(n=this.mapping[t.leaveAtomId])&&void 0!==n?n:0;this.writePaddedNumber(r,3),this.writeWhiteSpace(1);var i=t.attachmentId?t.attachmentId.slice(0,2):" ";this.writePadded(i,2),this.writeCR()}}]),e}();function jl(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Gl(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?jl(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):jl(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var zl=function(){function e(t){(0,i.A)(this,e),this.options=Gl(Gl({},e.DefaultOptions),t)}return(0,a.A)(e,[{key:"deserialize",value:function(e){var t=new Hl,n=null==e?void 0:e.split(/\r\n|[\n\r]/g),o={molfileLines:n,shouldReactionRelayout:this.options.reactionRelayout,ignoreChiralFlag:this.options.ignoreChiralFlag};try{return t.parseCTFile(o)}catch(e){if(q.error("molSerializer::MolSerializer::deserialize",e),this.options.badHeaderRecover){try{return t.parseCTFile(Gl(Gl({},o),{},{molfileLines:n.slice(1)}))}catch(e){q.error("molSerializer::MolSerializer::deserialize",e)}try{return t.parseCTFile(Gl(Gl({},o),{},{molfileLines:[""].concat(n)}))}catch(e){q.error("molSerializer::MolSerializer::deserialize",e)}}throw e}}},{key:"serialize",value:function(e){return(new Hl).saveMolecule(e,this.options.ignoreErrors,this.options.noRgroups,this.options.preserveIndigoDesc,this.options.ignoreChiralFlag)}}]),e}();function Vl(e,t,n){this.molecule=e,this.bonds=new Gt,this.getNeighbors=t,this.context=n}function Ul(e,t,n){var o=e[t];e[t]=e[n],e[n]=o}function Wl(e,t,n,o){var r=this;this.molecule=e,this.atom_data=t,this.components=n,this.nComponentsInReactants=-1,this.nReactants=o,this.vertices=new Array(this.molecule.atoms.size),this.molecule.atoms.forEach((function(e,t){r.vertices[t]=new Wl.VertexDesc}),this),this.edges=new Array(this.molecule.bonds.size),this.molecule.bonds.forEach((function(e,t){r.edges[t]=new Wl.EdgeDesc}),this),this.v_seq=[]}function ql(e,t,n){this.molecule=e,this.atoms=new Gt,this.getNeighbors=t,this.context=n}function Yl(e,t,n){var o=e[t];e[t]=e[n],e[n]=o}function $l(){this.smiles="",this.writtenAtoms=[],this.writtenComponents=0,this.ignoreErrors=!1}function Xl(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Kl(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Xl(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Xl(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}(0,d.A)(zl,"DefaultOptions",{badHeaderRecover:!1,ignoreErrors:!1,noRgroups:!1,preserveIndigoDesc:!1,reactionRelayout:!1}),Vl.PARITY={NONE:0,CIS:1,TRANS:2},Vl.prototype.each=function(e){this.bonds.forEach(e)},Vl.prototype.getParity=function(e){return this.bonds.get(e).parity},Vl.prototype.getSubstituents=function(e){return this.bonds.get(e).substituents},Vl.prototype.sameside=function(e,t,n,o){var r=we.diff(e,t),i=new we(-r.y,r.x);if(!i.normalize())return 0;var a=we.diff(n,e),s=we.diff(o,t);if(!a.normalize())return 0;if(!s.normalize())return 0;var u=we.dot(a,i),l=we.dot(s,i);return Math.abs(u)<.001||Math.abs(l)<.001?0:u*l>0?1:-1},Vl.prototype.samesides=function(e,t,n,o){return this.sameside(this.molecule.atoms.get(e).pp,this.molecule.atoms.get(t).pp,this.molecule.atoms.get(n).pp,this.molecule.atoms.get(o).pp)},Vl.prototype.sortSubstituents=function(e){var t=this.molecule.atoms.get(e[0]).pureHydrogen(),n=e[1]<0||this.molecule.atoms.get(e[1]).pureHydrogen(),o=this.molecule.atoms.get(e[2]).pureHydrogen(),r=e[3]<0||this.molecule.atoms.get(e[3]).pureHydrogen();return!(t&&n||o&&r||(n?e[1]=-1:t?(e[0]=e[1],e[1]=-1):e[0]>e[1]&&Ul(e,0,1),r?e[3]=-1:o?(e[2]=e[3],e[3]=-1):e[2]>e[3]&&Ul(e,2,3),0))},Vl.prototype.isGeomStereoBond=function(e,t){var n=this.molecule.bonds.get(e);if(n.type!==We.PATTERN.TYPE.DOUBLE)return!1;var o=this.molecule.atoms.get(n.begin).label,r=this.molecule.atoms.get(n.end).label;if("C"!==o&&"N"!==o&&"Si"!==o&&"Ge"!==o)return!1;if("C"!==r&&"N"!==r&&"Si"!==r&&"Ge"!==r)return!1;var i,a,s=this.getNeighbors.call(this.context,n.begin),u=this.getNeighbors.call(this.context,n.end);if(s.length<2||s.length>3||u.length<2||u.length>3)return!1;for(t[0]=-1,t[1]=-1,t[2]=-1,t[3]=-1,i=0;i<s.length;i++)if((a=s[i]).bid!==e){if(this.molecule.bonds.get(a.bid).type!==We.PATTERN.TYPE.SINGLE)return!1;-1===t[0]?t[0]=a.aid:t[1]=a.aid}for(i=0;i<u.length;i++)if((a=u[i]).bid!==e){if(this.molecule.bonds.get(a.bid).type!==We.PATTERN.TYPE.SINGLE)return!1;-1===t[2]?t[2]=a.aid:t[3]=a.aid}return!(-1!==t[1]&&-1!==this.samesides(n.begin,n.end,t[0],t[1])||-1!==t[3]&&-1!==this.samesides(n.begin,n.end,t[2],t[3]))},Vl.prototype.build=function(e){var t=this;this.molecule.bonds.forEach((function(n,o){var r={parity:0,substituents:[]};if(t.bonds.set(o,r),(!Array.isArray(e)||!e[o])&&t.isGeomStereoBond(o,r.substituents)&&t.sortSubstituents(r.substituents)){var i=t.samesides(n.begin,n.end,r.substituents[0],r.substituents[2]);1===i?r.parity=Vl.PARITY.CIS:-1===i&&(r.parity=Vl.PARITY.TRANS)}}))},Wl.VertexDesc=function(){this.dfs_state=0,this.parent_vertex=0,this.parent_edge=0,this.branches=0},Wl.EdgeDesc=function(){this.opening_cycles=0,this.closing_cycle=0},Wl.SeqElem=function(e,t,n){this.idx=e,this.parent_vertex=t,this.parent_edge=n},Wl.prototype.walk=function(){for(var e,t,n=this,o=[],r=0,i=0,a=function(){if(o.length<1){for(var a=-1;r<n.components.length&&-1===a;)null===(a=n.components[r].find((function(e){return 0===n.vertices[e].dfs_state&&(a=e,!0)})))&&(a=-1,r++),r===n.nReactants&&(n.nComponentsInReactants=i);if(a<-1&&n.molecule.atoms.find((function(e){return 0===n.vertices[e].dfs_state&&(a=e,!0)})),-1===a)return 1;n.vertices[a].parent_vertex=-1,n.vertices[a].parent_edge=-1,o.push(a),i++}var s=o.pop(),u=n.vertices[s].parent_vertex,l=new Wl.SeqElem(s,u,n.vertices[s].parent_edge);n.v_seq.push(l),n.vertices[s].dfs_state=2;var c=n.atom_data[s];for(e=0;e<c.neighbours.length;e++){var d=c.neighbours[e].aid,h=c.neighbours[e].bid;if(d!==u)if(2===n.vertices[d].dfs_state){for(n.edges[h].closing_cycle=1,t=s;-1!==t&&n.vertices[t].parent_vertex!==d;)t=n.vertices[t].parent_vertex;if(-1===t)throw new Error("cycle unwind error");n.edges[n.vertices[t].parent_edge].opening_cycles++,n.vertices[s].branches++,l=new Wl.SeqElem(d,s,h),n.v_seq.push(l)}else{if(1===n.vertices[d].dfs_state){if(-1===(t=o.indexOf(d)))throw new Error("internal: removing vertex from stack");o.splice(t,1);var f=n.vertices[d].parent_vertex;f>=0&&n.vertices[f].branches--}n.vertices[s].branches++,n.vertices[d].parent_vertex=s,n.vertices[d].parent_edge=h,n.vertices[d].dfs_state=1,o.push(d)}}};!a(););},Wl.prototype.edgeClosingCycle=function(e){return 0!==this.edges[e].closing_cycle},Wl.prototype.numBranches=function(e){return this.vertices[e].branches},Wl.prototype.numOpeningCycles=function(e){return this.edges[e].opening_cycles},Wl.prototype.toString=function(){var e="";return this.v_seq.forEach((function(t){e+=t.idx+" -> "})),e+="*"},ql.prototype.each=function(e,t){this.atoms.forEach(e,t)},ql.prototype.buildFromBonds=function(e){var t=this,n=this.molecule.atoms,o=this.molecule.bonds,r=new Re;n.forEach((function(e,i){var a=t.getNeighbors.call(t.context,i);if(2!==a.length)return!1;var s=a[0],u=a[1];if([i,s.aid,u.aid].findIndex((function(e){return["C","Si"].indexOf(n.get(e).label)<0}),t)>=0)return!1;if([s.bid,u.bid].findIndex((function(e){return o.get(e).type!==We.PATTERN.TYPE.DOUBLE}),t)>=0)return!1;var l=t.getNeighbors.call(t.context,s.aid).filter((function(e){return e.aid!==i})),c=t.getNeighbors.call(t.context,u.aid).filter((function(e){return e.aid!==i}));return!(l.length<1||l.length>2||c.length<1||c.length>2||l.concat(c).findIndex((function(e){return o.get(e.bid).type!==We.PATTERN.TYPE.SINGLE}),t)>=0||l.concat(c).findIndex((function(e){return o.get(e.bid).stereo===We.PATTERN.STEREO.EITHER}),t)>=0||(r.add(s.aid).add(u.aid),0))})),r.size>0&&n.forEach((function(e,n){if(!r.has(n)){var o=t.getNeighbors.call(t.context,n),i=!1;o.find((function(e){var t=this.molecule.bonds.get(e.bid);return t.type===We.PATTERN.TYPE.SINGLE&&t.begin===n&&(t.stereo===We.PATTERN.STEREO.UP||t.stereo===We.PATTERN.STEREO.DOWN)&&(i=!0,!0)}),t),i&&t.buildOneCenter(n)}}))},ql.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}],ql.prototype.buildOneCenter=function(e){var t=this,n=this.molecule.atoms.get(e),o=this.getNeighbors.call(this.context,e),r=o.length,i=-1,a={group:0,type:0,pyramid:[]},s=[],u=0,l=0;a.pyramid[0]=-1,a.pyramid[1]=-1,a.pyramid[2]=-1,a.pyramid[3]=-1;var c=0;if(r>4)throw new Error("stereocenter with %d bonds are not supported"+r);if(o.forEach((function(e,o){var r=t.molecule.atoms.get(e.aid),i=t.molecule.bonds.get(e.bid);if(s[o]={edge_idx:e.bid,nei_idx:e.aid,rank:e.aid,vec:we.diff(r.pp,n.pp).yComplement()},r.pureHydrogen()?(c++,s[o].rank=1e4):"H"===r.label&&(s[o].rank=5e3),!s[o].vec.normalize())throw new Error("zero bond length");if(i.type===We.PATTERN.TYPE.TRIPLE)throw new Error("non-single bonds not allowed near stereocenter");if(i.type===We.PATTERN.TYPE.AROMATIC)throw new Error("aromatic bonds not allowed near stereocenter");i.type===We.PATTERN.TYPE.DOUBLE&&l++})),ql.allowed_stereocenters.find((function(e){return e.elem===n.label&&e.charge===n.charge&&e.degree===r&&e.n_double_bonds===l&&(i=e.implicit_degree,!0)})),-1===i)throw new Error("unknown stereocenter configuration: "+n.label+", charge "+n.charge+", "+r+" bonds ("+l+" double)");if(4===r&&c>1)throw new Error(c+" hydrogens near stereocenter");if(3===r&&4===i&&c>0)throw new Error("have hydrogen(s) besides implicit hydrogen near stereocenter");if(4===r){s[0].rank>s[1].rank&&Yl(s,0,1),s[1].rank>s[2].rank&&Yl(s,1,2),s[2].rank>s[3].rank&&Yl(s,2,3),s[1].rank>s[2].rank&&Yl(s,1,2),s[0].rank>s[1].rank&&Yl(s,0,1),s[1].rank>s[2].rank&&Yl(s,1,2);for(var d,h,f=-1,m=-1,p=-1,v=-1,g=0,y=0;y<4;y++){var b=this.getBondStereo(e,s[y].edge_idx);if(b===We.PATTERN.STEREO.UP||b===We.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===m&&((d=ql.xyzzy(s[f].vec,s[(f+1)%4].vec,s[(f+2)%4].vec))+(h=ql.xyzzy(s[f].vec,s[(f+1)%4].vec,s[(f+3)%4].vec))!==3&&d+h!==12||(m=(f+1)%4,p=(f+2)%4,v=(f+3)%4)),-1===m&&((d=ql.xyzzy(s[f].vec,s[(f+2)%4].vec,s[(f+1)%4].vec))+(h=ql.xyzzy(s[f].vec,s[(f+2)%4].vec,s[(f+3)%4].vec))!==3&&d+h!==12||(m=(f+2)%4,p=(f+1)%4,v=(f+3)%4)),-1===m&&((d=ql.xyzzy(s[f].vec,s[(f+3)%4].vec,s[(f+1)%4].vec))+(h=ql.xyzzy(s[f].vec,s[(f+3)%4].vec,s[(f+2)%4].vec))!==3&&d+h!==12||(m=(f+3)%4,p=(f+2)%4,v=(f+1)%4)),-1===m)throw new Error("internal error: can not find opposite bond");if(g===We.PATTERN.STEREO.UP&&this.getBondStereo(e,s[m].edge_idx)===We.PATTERN.STEREO.DOWN)throw new Error("stereo types of the opposite bonds mismatch");if(g===We.PATTERN.STEREO.DOWN&&this.getBondStereo(e,s[m].edge_idx)===We.PATTERN.STEREO.UP)throw new Error("stereo types of the opposite bonds mismatch");if(g===this.getBondStereo(e,s[p].edge_idx))throw new Error("stereo types of non-opposite bonds match");if(g===this.getBondStereo(e,s[v].edge_idx))throw new Error("stereo types of non-opposite bonds match");u=3===f||3===m?g:g===We.PATTERN.STEREO.UP?We.PATTERN.STEREO.DOWN:We.PATTERN.STEREO.UP;var A=ql.sign(s[0].vec,s[1].vec,s[2].vec);u===We.PATTERN.STEREO.UP&&A>0||u===We.PATTERN.STEREO.DOWN&&A<0?(a.pyramid[0]=s[0].nei_idx,a.pyramid[1]=s[1].nei_idx,a.pyramid[2]=s[2].nei_idx):(a.pyramid[0]=s[0].nei_idx,a.pyramid[1]=s[2].nei_idx,a.pyramid[2]=s[1].nei_idx),a.pyramid[3]=s[3].nei_idx}else if(3===r){s[0].rank>s[1].rank&&Yl(s,0,1),s[1].rank>s[2].rank&&Yl(s,1,2),s[0].rank>s[1].rank&&Yl(s,0,1);var w=this.getBondStereo(e,s[0].edge_idx),E=this.getBondStereo(e,s[1].edge_idx),P=this.getBondStereo(e,s[2].edge_idx),x=0,S=0;if(x+=w===We.PATTERN.STEREO.UP?1:0,x+=E===We.PATTERN.STEREO.UP?1:0,x+=P===We.PATTERN.STEREO.UP?1:0,S+=w===We.PATTERN.STEREO.DOWN?1:0,S+=E===We.PATTERN.STEREO.DOWN?1:0,S+=P===We.PATTERN.STEREO.DOWN?1:0,4===i){if(3===x)throw new Error("all 3 bonds up near stereoatom");if(3===S)throw new Error("all 3 bonds down near stereoatom");if(0===x&&0===S)throw new Error("no up/down bonds near stereoatom -- indefinite case");if(1===x&&1===S)throw new Error("one bond up, one bond down -- indefinite case");if(g=0,2===x)u=We.PATTERN.STEREO.DOWN;else if(2===S)u=We.PATTERN.STEREO.UP;else{for(f=-1,p=-1,v=-1,y=0;y<3;y++){var O=this.getBondStereo(e,s[y].edge_idx);if(O===We.PATTERN.STEREO.UP||O===We.PATTERN.STEREO.DOWN){f=y,g=O,p=(y+1)%3,v=(y+2)%3;break}}if(-1===f)throw new Error("internal error: can not find up or down bond");var k=ql.xyzzy(s[p].vec,s[v].vec,s[f].vec);if(3===k||4===k)throw new Error("degenerate case for 3 bonds near stereoatom");u=1===k?g:g===We.PATTERN.STEREO.UP?We.PATTERN.STEREO.DOWN:We.PATTERN.STEREO.UP}var M=ql.sign(s[0].vec,s[1].vec,s[2].vec);u===We.PATTERN.STEREO.UP&&M>0||u===We.PATTERN.STEREO.DOWN&&M<0?(a.pyramid[0]=s[0].nei_idx,a.pyramid[1]=s[1].nei_idx,a.pyramid[2]=s[2].nei_idx):(a.pyramid[0]=s[0].nei_idx,a.pyramid[1]=s[2].nei_idx,a.pyramid[2]=s[1].nei_idx),a.pyramid[3]=-1}else{var R;if(S>0&&x>0)throw new Error("one bond up, one bond down -- indefinite case");if(0===S&&0===x)throw new Error("no up-down bonds attached to stereocenter");R=x>0?1:-1,1!==ql.xyzzy(s[0].vec,s[1].vec,s[2].vec)&&1!==ql.xyzzy(s[0].vec,s[2].vec,s[1].vec)&&1!==ql.xyzzy(s[2].vec,s[1].vec,s[0].vec)||(R=-R),ql.sign(s[0].vec,s[1].vec,s[2].vec)===R?(a.pyramid[0]=s[0].nei_idx,a.pyramid[1]=s[2].nei_idx,a.pyramid[2]=s[1].nei_idx):(a.pyramid[0]=s[0].nei_idx,a.pyramid[1]=s[1].nei_idx,a.pyramid[2]=s[2].nei_idx),a.pyramid[3]=-1}}this.atoms.set(e,a)},ql.prototype.getBondStereo=function(e,t){var n=this.molecule.bonds.get(t);return e!==n.begin?0:n.stereo},ql.xyzzy=function(e,t,n){var o=.001,r=we.cross(e,t),i=we.dot(e,t),a=we.cross(e,n),s=we.dot(e,n);if(Math.abs(r)<o){if(Math.abs(a)<o)throw new Error("degenerate case -- bonds overlap");return a>0?4:8}return r*a<-o*o||s<i?2:1},ql.sign=function(e,t,n){var o=(e.x-n.x)*(t.y-n.y)-(e.y-n.y)*(t.x-n.x);if(o>.001)return 1;if(o<-.001)return-1;throw new Error("degenerate triangle")},ql.isPyramidMappingRigid=function(e){var t=e.slice(),n=!0;return t[0]>t[1]&&(Yl(t,0,1),n=!n),t[1]>t[2]&&(Yl(t,1,2),n=!n),t[2]>t[3]&&(Yl(t,2,3),n=!n),t[1]>t[2]&&(Yl(t,1,2),n=!n),t[0]>t[1]&&(Yl(t,0,1),n=!n),t[1]>t[2]&&(Yl(t,1,2),n=!n),n},$l._Atom=function(e){this.neighbours=[],this.aromatic=!1,this.lowercase=!1,this.chirality=0,this.branch_cnt=0,this.paren_written=!1,this.h_count=e,this.parent=-1},$l.prototype.isBondInRing=function(e){return this.inLoop[e]},$l.prototype.saveMolecule=function(e,t){var n,o,r,i=this;t||(this.ignoreErrors=t),(e=e.clone(void 0,void 0,!e.hasRxnArrow(),void 0,void 0,void 0)).initHalfBonds(),e.initNeighbors(),e.sortNeighbors(),e.setImplicitHydrogen(),e.sgroups.forEach((function(t){if("MUL"===t.type)try{ht.prepareMulForSaving(t,e)}catch(e){throw q.error("smiles.js::Smiles.prototype.saveMolecule",e),Error("Bad s-group ("+e.message+")")}})),this.atoms=new Array(e.atoms.size),e.atoms.forEach((function(e,t){i.atoms[t]=new $l._Atom(e.implicitH)}));var a=["B","C","N","O","P","S","Se","As"];e.bonds.forEach((function(t,n){t.type===We.PATTERN.TYPE.AROMATIC&&(i.atoms[t.begin].aromatic=!0,-1!==a.indexOf(e.atoms.get(t.begin).label)&&(i.atoms[t.begin].lowercase=!0),i.atoms[t.end].aromatic=!0,-1!==a.indexOf(e.atoms.get(t.end).label)&&(i.atoms[t.end].lowercase=!0)),i.atoms[t.begin].neighbours.push({aid:t.end,bid:n}),i.atoms[t.end].neighbours.push({aid:t.begin,bid:n})})),this.inLoop=function(){e.prepareLoopStructure();var t=new Re;e.loops.forEach((function(n){if(n.hbs.length<=6){var o=n.hbs.map((function(t){return e.halfBonds.get(t).bid}));t=t.union(new Re(o))}}));var n={};return t.forEach((function(e){n[e]=1})),n}(),this.touchedCistransbonds=0,this.markCisTrans(e);var s=e.getComponents(),u=s.reactants.concat(s.products),l=new Wl(e,this.atoms,u,s.reactants.length);for(l.walk(),this.atoms.forEach((function(e){e.neighbours=[]})),n=0;n<l.v_seq.length;n++){var c=l.v_seq[n],d=c.idx,h=c.parent_edge,f=c.parent_vertex;if(h>=0){var m=this.atoms[d],p=l.numOpeningCycles(h);for(o=0;o<p;o++)this.atoms[f].neighbours.push({aid:-1,bid:-1});if(l.edgeClosingCycle(h)){for(r=0;r<m.neighbours.length;r++)if(-1===m.neighbours[r].aid){m.neighbours[r].aid=f,m.neighbours[r].bid=h;break}if(r===m.neighbours.length)throw new Error("internal: can not put closing bond to its place")}else m.neighbours.push({aid:f,bid:h}),m.parent=f;this.atoms[f].neighbours.push({aid:d,bid:h})}}try{var v=new ql(e,(function(e){return this.atoms[e].neighbours}),this);v.buildFromBonds(this.ignoreErrors),v.each((function(e,t){var n=-1;-1===e.pyramid[3]&&(n=3);var a=[],s=0,u=i.atoms[t];if(-1!==u.parent)for(r=0;r<4;r++)if(e.pyramid[r]===u.parent){a[s++]=r;break}for(-1!==n&&(a[s++]=n),o=0;o!==u.neighbours.length;o++)if(u.neighbours[o].aid!==u.parent)for(r=0;r<4;r++)if(u.neighbours[o].aid===e.pyramid[r]){if(s>=4)throw new Error("internal: pyramid overflow");a[s++]=r;break}if(4===s)s=a[0],a[0]=a[1],a[1]=a[2],a[2]=a[3],a[3]=s;else if(3!==s)throw new Error("cannot calculate chirality");ql.isPyramidMappingRigid(a)?i.atoms[t].chirality=1:i.atoms[t].chirality=2}))}catch(e){q.error("smiles.js::Smiles.prototype.saveMolecule",e)}var g=[];g.push(0);var y=!0;for(n=0;n<l.v_seq.length;n++){d=(c=l.v_seq[n]).idx,h=c.parent_edge;var b=!0;if((f=c.parent_vertex)>=0){for(l.numBranches(f)>1&&this.atoms[f].branch_cnt>0&&this.atoms[f].paren_written&&(this.smiles+=")"),p=l.numOpeningCycles(h),o=0;o<p;o++){for(r=1;r<g.length&&-1!==g[r];r++);r===g.length?g.push(f):g[r]=f,this.writeCycleNumber(r)}if(f>=0){var A=l.numBranches(f);if(A>1&&this.atoms[f].branch_cnt<A-1&&(l.edgeClosingCycle(h)?this.atoms[f].paren_written=!1:(this.smiles+="(",this.atoms[f].paren_written=!0)),this.atoms[f].branch_cnt++,this.atoms[f].branch_cnt>A)throw new Error("unexpected branch")}var w=e.bonds.get(h),E=0;if(w.type===We.PATTERN.TYPE.SINGLE&&(E=this.calcBondDirection(e,h,f)),1===E&&d===w.end||2===E&&d===w.begin?this.smiles+="/":2===E&&d===w.end||1===E&&d===w.begin?this.smiles+="\\":w.type===We.PATTERN.TYPE.ANY?this.smiles+="~":w.type===We.PATTERN.TYPE.DOUBLE?this.smiles+="=":w.type===We.PATTERN.TYPE.TRIPLE?this.smiles+="#":w.type===We.PATTERN.TYPE.SINGLE_OR_AROMATIC?this.smiles+="-,:":w.type===We.PATTERN.TYPE.DOUBLE_OR_AROMATIC?this.smiles+="=,:":w.type===We.PATTERN.TYPE.SINGLE_OR_DOUBLE?this.smiles+="-,=":w.type!==We.PATTERN.TYPE.AROMATIC||this.atoms[w.begin].lowercase&&this.atoms[w.end].lowercase&&this.isBondInRing(h)?w.type===We.PATTERN.TYPE.SINGLE&&this.atoms[w.begin].aromatic&&this.atoms[w.end].aromatic&&(this.smiles+="-"):this.smiles+=":",l.edgeClosingCycle(h)){for(o=1;o<g.length&&g[o]!==d;o++);if(o===g.length)throw new Error("cycle number not found");this.writeCycleNumber(o),g[o]=-1,b=!1}}else y||(this.smiles+=this.writtenComponents===l.nComponentsInReactants&&0!==l.nReactants?">>":"."),y=!1,this.writtenComponents++;b&&(this.writeAtom(e,d,this.atoms[d].aromatic,this.atoms[d].lowercase,this.atoms[d].chirality),this.writtenAtoms.push(c.idx))}return this.comma=!1,this.writeRadicals(e),this.comma&&(this.smiles+="|"),this.smiles},$l.prototype.writeCycleNumber=function(e){if(e>0&&e<10)this.smiles+=e;else if(e>=10&&e<100)this.smiles+="%"+e;else{if(!(e>=100&&e<1e3))throw new Error("bad cycle number: "+e);this.smiles+="%%"+e}},$l.prototype.writeAtom=function(e,t,n,o,r){var i,a=e.atoms.get(t),s=!1,u=-1;if("A"!==a.label)if("R"!==a.label&&"R#"!==a.label){i=a.aam,"C"!==a.label&&"P"!==a.label&&"N"!==a.label&&"S"!==a.label&&"O"!==a.label&&"Cl"!==a.label&&"F"!==a.label&&"Br"!==a.label&&"B"!==a.label&&"I"!==a.label&&(s=!0),(a.explicitValence>=0||0!==a.radical||r>0||n&&"C"!==a.label&&"O"!==a.label||n&&"C"===a.label&&this.atoms[t].neighbours.length<3&&0===this.atoms[t].h_count)&&(u=this.atoms[t].h_count);var l=a.label;if(a.atomList&&!a.atomList.notList?(l=a.atomList.label(),s=!1):a.isPseudo()||a.atomList&&a.atomList.notList?(l="*",s=!1):(r||0!==a.charge&&null!==a.charge||a.isotope>0||u>=0||i>0)&&(s=!0),s&&(-1===u&&(u=this.atoms[t].h_count),this.smiles+="["),a.isotope>0&&(this.smiles+=a.isotope),this.smiles+=o?l.toLowerCase():l,r>0&&(this.smiles+=1===r?"@":"@@",a.implicitH>1))throw new Error(a.implicitH+" implicit H near stereocenter");"H"!==a.label&&(u>1||0===u&&!s?this.smiles+="H"+u:1===u&&(this.smiles+="H")),a.charge>1?this.smiles+="+"+a.charge:a.charge<-1?this.smiles+=a.charge:1===a.charge?this.smiles+="+":-1===a.charge&&(this.smiles+="-"),i>0&&(this.smiles+=":"+i),s&&(this.smiles+="]")}else this.smiles+="[*]";else this.smiles+="*"},$l.prototype.markCisTrans=function(e){var t=this;this.cis_trans=new Vl(e,(function(e){return this.atoms[e].neighbours}),this),this.cis_trans.build(),this.dbonds=new Array(e.bonds.size),e.bonds.forEach((function(e,n){t.dbonds[n]={ctbond_beg:-1,ctbond_end:-1,saved:0}})),this.cis_trans.each((function(n,o){var r=e.bonds.get(o);if(0!==n.parity&&!t.isBondInRing(o)){var i=t.atoms[r.begin].neighbours,a=t.atoms[r.end].neighbours,s=!0,u=!0;if(i.forEach((function(t){t.bid!==o&&e.bonds.get(t.bid).type===We.PATTERN.TYPE.SINGLE&&(s=!1)})),a.forEach((function(t){t.bid!==o&&e.bonds.get(t.bid).type===We.PATTERN.TYPE.SINGLE&&(u=!1)})),s||u)return;i.forEach((function(n){n.bid!==o&&(e.bonds.get(n.bid).begin===r.begin?t.dbonds[n.bid].ctbond_beg=o:t.dbonds[n.bid].ctbond_end=o)})),a.forEach((function(n){n.bid!==o&&(e.bonds.get(n.bid).begin===r.end?t.dbonds[n.bid].ctbond_beg=o:t.dbonds[n.bid].ctbond_end=o)}))}}))},$l.prototype.updateSideBonds=function(e,t){var n=e.bonds.get(t),o=this.cis_trans.getSubstituents(t),r=this.cis_trans.getParity(t),i=[-1,-1,-1,-1];i[0]=e.findBondId(o[0],n.begin),-1!==o[1]&&(i[1]=e.findBondId(o[1],n.begin)),i[2]=e.findBondId(o[2],n.end),-1!==o[3]&&(i[3]=e.findBondId(o[3],n.end));var a=0,s=0,u=0,l=0;if(0!==this.dbonds[i[0]].saved&&(1===this.dbonds[i[0]].saved&&e.bonds.get(i[0]).begin===n.begin||2===this.dbonds[i[0]].saved&&e.bonds.get(i[0]).end===n.begin?a++:s++),-1!==i[1]&&0!==this.dbonds[i[1]].saved&&(2===this.dbonds[i[1]].saved&&e.bonds.get(i[1]).begin===n.begin||1===this.dbonds[i[1]].saved&&e.bonds.get(i[1]).end===n.begin?a++:s++),0!==this.dbonds[i[2]].saved&&(1===this.dbonds[i[2]].saved&&e.bonds.get(i[2]).begin===n.end||2===this.dbonds[i[2]].saved&&e.bonds.get(i[2]).end===n.end?u++:l++),-1!==i[3]&&0!==this.dbonds[i[3]].saved&&(2===this.dbonds[i[3]].saved&&e.bonds.get(i[3]).begin===n.end||1===this.dbonds[i[3]].saved&&e.bonds.get(i[3]).end===n.end?u++:l++),r===Vl.PARITY.CIS?(a+=u,s+=l):(a+=l,s+=u),a>0&&s>0)throw new Error("incompatible cis-trans configuration");return(0!==a||0!==s)&&(a>0&&(this.dbonds[i[0]].saved=e.bonds.get(i[0]).begin===n.begin?1:2,-1!==i[1]&&(this.dbonds[i[1]].saved=e.bonds.get(i[1]).begin===n.begin?2:1),this.dbonds[i[2]].saved=e.bonds.get(i[2]).begin===n.end==(r===Vl.PARITY.CIS)?1:2,-1!==i[3]&&(this.dbonds[i[3]].saved=e.bonds.get(i[3]).begin===n.end==(r===Vl.PARITY.CIS)?2:1)),s>0&&(this.dbonds[i[0]].saved=e.bonds.get(i[0]).begin===n.begin?2:1,-1!==i[1]&&(this.dbonds[i[1]].saved=e.bonds.get(i[1]).begin===n.begin?1:2),this.dbonds[i[2]].saved=e.bonds.get(i[2]).begin===n.end==(r===Vl.PARITY.CIS)?2:1,-1!==i[3]&&(this.dbonds[i[3]].saved=e.bonds.get(i[3]).begin===n.end==(r===Vl.PARITY.CIS)?1:2)),!0)},$l.prototype.calcBondDirection=function(e,t,n){var o,r=this;if(-1===this.dbonds[t].ctbond_beg&&-1===this.dbonds[t].ctbond_end)return 0;if(e.bonds.get(t).type!==We.PATTERN.TYPE.SINGLE)throw new Error("internal: directed bond type "+e.bonds.get(t).type);for(;o=0,this.cis_trans.each((function(t,n){0===t.parity||r.isBondInRing(n)||r.updateSideBonds(e,n)&&o++})),o!==this.touchedCistransbonds;)this.touchedCistransbonds=o;return 0===this.dbonds[t].saved&&(n===e.bonds.get(t).begin?this.dbonds[t].saved=1:this.dbonds[t].saved=2),this.dbonds[t].saved},$l.prototype.writeRadicals=function(e){var t,n,o=new Array(this.writtenAtoms.length);for(t=0;t<this.writtenAtoms.length;t++)if(!o[t]){var r=e.atoms.get(this.writtenAtoms[t]).radical;if(0!==r)for(this.comma?this.smiles+=",":(this.smiles+=" |",this.comma=!0),r===Fe.PATTERN.RADICAL.SINGLET?this.smiles+="^3:":r===Fe.PATTERN.RADICAL.DOUPLET?this.smiles+="^1:":this.smiles+="^4:",this.smiles+=t,n=t+1;n<this.writtenAtoms.length;n++)e.atoms.get(this.writtenAtoms[n]).radical===r&&(o[n]=!0,this.smiles+=","+n)}};var Zl=function(){function e(t){(0,i.A)(this,e),this.options=Kl(Kl({},e.DefaultOptions),t)}return(0,a.A)(e,[{key:"deserialize",value:function(e){throw new Error("Not implemented yet.")}},{key:"serialize",value:function(e){return(new $l).saveMolecule(e,this.options.ignoreErrors)}}]),e}();(0,d.A)(Zl,"DefaultOptions",{ignoreErrors:!1});var Ql=/^[^]+?\$\$\$\$$/gm,Jl=function(){function e(t){(0,i.A)(this,e),this.molSerializerOptions=t}return(0,a.A)(e,[{key:"deserialize",value:function(e){for(var t,n=[],o=new zl(this.molSerializerOptions);null!==(t=Ql.exec(e));){var r=t[0].replace(/\r/g,"").trim(),i=r.indexOf("M END");if(-1!==i){var a=r.substr(i+7).trim().split(/^$\n?/m),s=o.deserialize(r.substring(0,i+6)),u=a.reduce((function(e,t){var n=t.match(/^> [ \d]*<(\S+)>/);if(n){var o=n[1],r=t.split("\n").slice(1,-1),i="";i=r.length>1?r.join(","):t.split("\n")[1].trim(),e[o]=Number.isFinite(i)?+i:i.toString()}return e}),{});n.push({struct:s,props:u})}}return n}},{key:"serialize",value:function(e){var t=new zl(this.molSerializerOptions);return e.reduce((function(e,n){return e+=t.serialize(n.struct),Object.keys(n.props).forEach((function(t){e+="> <".concat(t,">\n"),e+="".concat(n.props[t],"\n\n")})),"".concat(e,"$$$$\n")}),"")}}]),e}();var ec=new WeakMap,tc=function(){function e(t){var n,o,r;(0,i.A)(this,e),r={writable:!0,value:void 0},function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(n=this,o=ec),o.set(n,r),(0,A.A)(this,ec,t)}var t,n;return(0,a.A)(e,[{key:"getStructureFromStructAsync",value:(n=(0,m.A)(v().mark((function e(t,n,o){var r;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=(0,w.A)(this,ec).serialize(t,n,o),e.abrupt("return",r);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,o){return n.apply(this,arguments)})},{key:"getStructureFromStringAsync",value:(t=(0,m.A)(v().mark((function e(t){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",(0,w.A)(this,ec).deserialize(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"parseMacromoleculeString",value:function(e){(0,w.A)(this,ec).deserializeMicromolecules(e)}}]),e}();function nc(e,t,n){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.set(e,n)}var oc=new WeakMap,rc=new WeakMap,ic=new WeakMap,ac=new WeakMap,sc=new WeakMap,uc=function(){function e(t,n,o,r,a){(0,i.A)(this,e),nc(this,oc,{writable:!0,value:void 0}),nc(this,rc,{writable:!0,value:void 0}),nc(this,ic,{writable:!0,value:void 0}),nc(this,ac,{writable:!0,value:void 0}),nc(this,sc,{writable:!0,value:void 0}),(0,A.A)(this,oc,t),(0,A.A)(this,ic,o),(0,A.A)(this,rc,n),(0,A.A)(this,ac,r),(0,A.A)(this,sc,a)}var t;return(0,a.A)(e,[{key:"getStructureFromStructAsync",value:(t=(0,m.A)(v().mark((function e(t){var n;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=(0,w.A)(this,oc).serialize(t),e.abrupt("return",n);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"getStructureFromStringAsync",value:function(e){return new vc((0,w.A)(this,rc),(0,w.A)(this,ic),(0,w.A)(this,ac),(0,w.A)(this,sc)).getStructureFromStringAsync(e)}}],[{key:"isContainsCoordinates",value:function(e){return/\([\d.,;-]+\)/.test(e)}}]),e}();function lc(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function cc(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?lc(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):lc(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function dc(e,t,n){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.set(e,n)}var hc=new WeakMap,fc=new WeakMap,mc=new WeakMap,pc=new WeakMap,vc=function(){function e(t,n,o,r){(0,i.A)(this,e),dc(this,hc,{writable:!0,value:void 0}),dc(this,fc,{writable:!0,value:void 0}),dc(this,mc,{writable:!0,value:void 0}),dc(this,pc,{writable:!0,value:void 0}),(0,A.A)(this,hc,t),(0,A.A)(this,fc,n),(0,A.A)(this,mc,o),(0,A.A)(this,pc,r)}var t,n;return(0,a.A)(e,[{key:"getStructureFromStructAsync",value:(n=(0,m.A)(v().mark((function e(t,n){var o,r,i,a;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=gu((0,w.A)(this,mc)),e.prev=1,r=(0,w.A)(this,fc).serialize(t,n),e.next=5,(0,w.A)(this,hc).convert({struct:r,output_format:o.mime},cc(cc({},(0,w.A)(this,pc)),o.options));case 5:return i=e.sent,e.abrupt("return",i.struct);case 9:throw e.prev=9,e.t0=e.catch(1),a="Server is not compatible"===e.t0.message?"".concat(o.name," is not supported."):"Convert error!\n".concat(e.t0.message||e.t0),q.error("serverFormatter.ts::getStructureFromStructAsync",e.t0),new Error(a);case 14:case"end":return e.stop()}}),e,this,[[1,9]])}))),function(e,t){return n.apply(this,arguments)})},{key:"getCallingMethod",value:function(e,t){return(0,w.A)(this,mc)===hu.smiles?{method:uc.isContainsCoordinates(e)?(0,w.A)(this,hc).convert:(0,w.A)(this,hc).layout,struct:e}:gu(t).supportsCoords?{method:(0,w.A)(this,hc).convert,struct:e}:{method:(0,w.A)(this,hc).layout,struct:e.trim()}}},{key:"getStructureFromStringAsync",value:(t=(0,m.A)(v().mark((function e(t){var n,o,r,i,a,s,u;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n={struct:void 0,output_format:gu(hu.ket).mime},o=this.getCallingMethod(t,(0,w.A)(this,mc)),r=o.method,i=o.struct,n.struct=i,e.prev=3,e.next=6,r(n,(0,w.A)(this,pc));case 6:return a=e.sent,s=(0,w.A)(this,fc).deserialize(a.struct),r===(0,w.A)(this,hc).layout&&s.rescale(),e.abrupt("return",s);case 12:if(e.prev=12,e.t0=e.catch(3),"Server is not compatible"===e.t0.message){e.next=17;break}throw q.error("serverFormatter.ts::getStructureFromStringAsync",e.t0),Error("Convert error!\n".concat(e.t0.message||e.t0));case 17:throw u="smiles"===(0,w.A)(this,mc)?"".concat(gu(hu.smilesExt).name," and opening of ").concat(gu(hu.smiles).name):gu((0,w.A)(this,mc)).name,Error("".concat(u," is not supported in standalone mode."));case 19:case"end":return e.stop()}}),e,this,[[3,12]])}))),function(e){return t.apply(this,arguments)})}]),e}();var gc=new WeakMap,yc=function(){function e(t){var n,o,r;(0,i.A)(this,e),r={writable:!0,value:void 0},function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(n=this,o=gc),o.set(n,r),(0,A.A)(this,gc,t)}var t,n;return(0,a.A)(e,[{key:"getStructureFromStructAsync",value:(n=(0,m.A)(v().mark((function e(t){var n;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=(0,w.A)(this,gc).serialize(t),e.abrupt("return",n);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"getStructureFromStringAsync",value:(t=(0,m.A)(v().mark((function e(t){var n;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=(0,w.A)(this,gc).deserialize(t),e.abrupt("return",n);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),e}(),bc=["reactionRelayout","badHeaderRecover","ignoreChiralFlag"];var Ac=new WeakMap,wc=function(){function e(t){var n,o,r;(0,i.A)(this,e),r={writable:!0,value:void 0},function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(n=this,o=Ac),o.set(n,r),(0,A.A)(this,Ac,t)}return(0,a.A)(e,[{key:"separateOptions",value:function(e){if(!e)return[{},{}];var t=e.reactionRelayout,n=e.badHeaderRecover,o=e.ignoreChiralFlag,r=(0,B.A)(e,bc),i={};return"boolean"==typeof t&&(i.reactionRelayout=t),"boolean"==typeof n&&(i.badHeaderRecover=n),"boolean"==typeof o&&(i.ignoreChiralFlag=o,r["ignore-no-chiral-flag"]=o),[i,r]}},{key:"create",value:function(e,t,n){var o,i=this.separateOptions(t),a=(0,r.A)(i,2),s=a[0],u=a[1];switch(e){case hu.ket:o=new tc(new Vu);break;case hu.mol:o=n?new vc((0,w.A)(this,Ac),new Vu,e,u):new yc(new zl(s));break;case hu.cml:case hu.inChIAuxInfo:case hu.inChI:case hu.inChIKey:case hu.molV3000:case hu.smiles:case hu.rxnV3000:case hu.smilesExt:case hu.smarts:case hu.cdxml:case hu.cdx:case hu.binaryCdx:case hu.unknown:case hu.rxn:default:o=new vc((0,w.A)(this,Ac),new Vu,e,u)}return o}}]),e}();function Ec(e){var t=e.trim();try{if(JSON.parse(t))return hu.ket}catch(e){q.error("identifyStructFormat.ts::identifyStructFromat",e)}var n=t.includes("$RXN"),o=t.includes("\n$$$$"),r=t.includes("V2000"),i=t.includes("V3000");if(n)return hu.rxn;if(o)return r?hu.sdf:hu.sdfV3000;if(r)return hu.mol;if(i)return hu.molV3000;var a=t.match(/^(M {2}END|\$END MOL)$/m);if(a){var s=(a.index||0)+a[0].length;if(s===t.length||-1!==t.slice(s,s+20).search(/^\$(MOL|END CTAB)$/m))return hu.mol}if("<"===t[0]&&-1!==t.indexOf("<molecule"))return hu.cml;var u=t.replace(/\s/g,"").replace(/(\\r)|(\\n)/g,"");return u.length%4==0&&/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/.test(u)&&window.atob(u).startsWith("VjCD0100")?hu.cdx:"InChI"===t.slice(0,5)?hu.inChI:-1===t.indexOf("\n")?hu.smiles:-1!==t.indexOf("<CDXML")?hu.cdxml:hu.unknown}var Pc=new(function(){function e(){(0,i.A)(this,e)}return(0,a.A)(e,[{key:"setKetcherInstance",value:function(e){this.ketcherInstance=e}},{key:"getKetcher",value:function(){return this.ketcherInstance}}]),e}());function xc(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:hu.rxn,t=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;return(arguments.length>1?arguments[1]:void 0).create(e).getStructureFromStructAsync(t,n)}function Sc(e,t,n){return Oc.apply(this,arguments)}function Oc(){return(Oc=(0,m.A)(v().mark((function e(t,n,o){var r;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,kc(t,n,o);case 2:return(r=e.sent).initHalfBonds(),r.initNeighbors(),r.setImplicitHydrogen(),r.markFragments(),e.abrupt("return",r);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function kc(e,t,n){var o=Ec(e),r=new wc(t),i=n.editor.options();return r.create(o,{"dearomatize-on-load":i["dearomatize-on-load"],"ignore-no-chiral-flag":i.ignoreChiralFlag}).getStructureFromStringAsync(e)}function Mc(){var e=zc.provideEditorInstance(),t=e.drawingEntitiesManager.deleteAllEntities();e.renderersContainer.update(t)}function Rc(e,t){return Tc.apply(this,arguments)}function Tc(){return Tc=(0,m.A)(v().mark((function e(t,n){var o,r,i,a,s,u;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=zc.provideEditorInstance(),r=new Vu,i=Ec(t),a=t,i===hu.ket){e.next=8;break}return e.next=7,n.convert({struct:t,output_format:Us.KET});case 7:a=e.sent.struct;case 8:s=r.deserializeToDrawingEntities(a),f()(s),u=s.drawingEntitiesManager.mergeInto(o.drawingEntitiesManager),new _c(o).update(u),o.renderersContainer.update(u);case 13:case"end":return e.stop()}}),e)}))),Tc.apply(this,arguments)}var Bc=function(){function e(){(0,i.A)(this,e),(0,d.A)(this,"chains",[])}return(0,a.A)(e,[{key:"rearrange",value:function(){this.chains.sort((function(e,t){var n,o,r,i;return(null===(n=t.firstNode)||void 0===n?void 0:n.monomer.position.x)+(null===(o=t.firstNode)||void 0===o?void 0:o.monomer.position.y)>(null===(r=e.firstNode)||void 0===r?void 0:r.monomer.position.x)+(null===(i=e.firstNode)||void 0===i?void 0:i.monomer.position.y)?-1:1}))}},{key:"add",value:function(e){this.chains.push(e)}},{key:"firstNode",get:function(){var e;return null===(e=this.chains[0])||void 0===e||null===(e=e.subChains[0])||void 0===e?void 0:e.nodes[0]}}],[{key:"fromMonomers",value:function(t){var n=new e,o=this.getFirstMonomersInChains(t),i=(0,r.A)(o,2),a=i[0],s=i[1];return a.forEach((function(e){n.add(new Zr(e))})),s.forEach((function(e){n.add(new Zr(e,!!Gc.CYCLED))})),n}},{key:"getFirstMonomersInChains",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[Dn,Fn,Kn,eo,Gn],n=e.filter((function(e){return t.some((function(t){return e instanceof t}))})),o=[],r=this.getFirstMonomersInRegularChains(n),i=this.getFirstMonomersInCycledChains(n);return o.push(r,i),o}},{key:"getFirstMonomersInRegularChains",value:function(e){return e.filter((function(e){var t,n=e.attachmentPointsToBonds.R1,o=!n||n.isSideChainConnection,r=null==n?void 0:n.getAnotherMonomer(e),i=e instanceof Gn&&r instanceof eo&&oo(r)===e,a=e instanceof eo&&r instanceof Gn&&oo(e)&&(null===(t=r.attachmentPointsToBonds.R2)||void 0===t?void 0:t.getAnotherMonomer(r))===e;return(o||a)&&!i}))}},{key:"getFirstMonomersInCycledChains",value:function(e){var t=this,n=new Set,o=[];return e.forEach((function(e){if(!n.has(e)){var t=new Set;t.add(e),n.add(e);for(var r=no(e);r&&!n.has(r);)t.add(r),n.add(r),r=no(r);e===r&&o.push(Array.from(t))}})),o.map((function(e){return t.getMonomerWithLowerCoordsFromMonomerList(e)}))}},{key:"getMonomerWithLowerCoordsFromMonomerList",value:function(e){var t=e.slice();return t.sort((function(e,t){return t.position.x+t.position.y>e.position.x+e.position.y?-1:1})),t[0]}}]),e}();function Cc(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}var Ic=function(){function e(){(0,i.A)(this,e),(0,d.A)(this,"monomers",new Map),(0,d.A)(this,"polymerBonds",new Map),(0,d.A)(this,"micromoleculesHiddenEntities",new Yt)}return(0,a.A)(e,[{key:"selectedEntities",get:function(){return this.allEntities.filter((function(e){return(0,r.A)(e,2)[1].selected}))}},{key:"allEntities",get:function(){return[].concat((0,o.A)(this.monomers),(0,o.A)(this.polymerBonds))}},{key:"deleteSelectedEntities",value:function(){var e=this,t=new Zo;return this.selectedEntities.forEach((function(n){var o=(0,r.A)(n,2)[1],i=e.deleteDrawingEntity(o);t.merge(i)})),t}},{key:"deleteAllEntities",value:function(){var e=this,t=new Zo;return this.allEntities.forEach((function(n){var o=(0,r.A)(n,2)[1],i=e.deleteDrawingEntity(o,!1);t.merge(i)})),t}},{key:"addMonomerChangeModel",value:function(e,t,n){if(n)return this.monomers.set(n.id,n),n;var o=$s(e),i=new(0,(0,r.A)(o,1)[0])(e,t);return i.moveAbsolute(t),this.monomers.set(i.id,i),i}},{key:"addMonomer",value:function(e,t){var n=new Zo,o=new ou(this.addMonomerChangeModel.bind(this,e,t),this.deleteMonomerChangeModel.bind(this));return n.addOperation(o),n}},{key:"deleteDrawingEntity",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return e instanceof Sn?this.deleteMonomer(e,t):e instanceof Xr?this.deletePolymerBond(e):new Zo}},{key:"selectDrawingEntity",value:function(e){var t=this.unselectAllDrawingEntities();return e.turnOnSelection(),t.merge(this.createDrawingEntitySelectionCommand(e)),t}},{key:"selectDrawingEntities",value:function(e){var t=this.unselectAllDrawingEntities();return e.forEach((function(e){e.turnOnSelection();var n=new lu(e);t.addOperation(n)})),t}},{key:"createDrawingEntitySelectionCommand",value:function(e){var t=new Zo,n=new lu(e);return t.addOperation(n),t}},{key:"unselectAllDrawingEntities",value:function(){var e=this,t=new Zo;return this.allEntities.forEach((function(n){var o=(0,r.A)(n,2)[1];o.selected&&t.merge(e.unselectDrawingEntity(o))})),t}},{key:"unselectDrawingEntity",value:function(e){var t=new Zo;return e.turnOffSelection(),t.addOperation(new lu(e)),t}},{key:"selectAllDrawingEntities",value:function(){var e=new Zo;return this.allEntities.forEach((function(t){var n=(0,r.A)(t,2)[1];if(!n.selected){n.turnOnSelection();var o=new lu(n);e.addOperation(o)}})),e}},{key:"addDrawingEntitiesToSelection",value:function(e){var t=new Zo;return e.forEach((function(e){e.selected?e.turnOffSelection():e.turnOnSelection(),t.addOperation(new lu(e))})),t}},{key:"moveDrawingEntityModelChange",value:function(e,t){return e instanceof Xr?e.moveToLinkedMonomers():(f()(t),e.moveRelative(t)),e}},{key:"moveSelectedDrawingEntities",value:function(e,t){var n=this,o=new Zo;return this.monomers.forEach((function(r){r.selected&&o.merge(n.createDrawingEntityMovingCommand(r,e,t))})),this.polymerBonds.forEach((function(r){var i;(r.selected||r.firstMonomer.selected||null!==(i=r.secondMonomer)&&void 0!==i&&i.selected)&&o.merge(n.createDrawingEntityMovingCommand(r,e,t))})),o}},{key:"createDrawingEntityMovingCommand",value:function(e,t,n){var o=new Zo,r=new cu(this.moveDrawingEntityModelChange.bind(this,e,t),this.moveDrawingEntityModelChange.bind(this,e,n?n.negated():t.negated()),this.moveDrawingEntityModelChange.bind(this,e,n||t),e);return o.addOperation(r),o}},{key:"createDrawingEntityRedrawCommand",value:function(e,t){var n=new Zo,o=new du(e,t);return n.addOperation(o),n}},{key:"deleteMonomerChangeModel",value:function(e){this.monomers.delete(e.id)}},{key:"deleteMonomer",value:function(e){var t=this,n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],o=new Zo,r=new su(e,this.addMonomerChangeModel.bind(this,e.monomerItem,e.position),this.deleteMonomerChangeModel.bind(this));return o.addOperation(r),n&&e.hasBonds&&e.forEachBond((function(e){e.selected||(e.turnOnSelection(),o.merge(t.deletePolymerBond(e)))})),o}},{key:"selectIfLocatedInRectangle",value:function(e,t,n){var o=this,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=new Zo;return this.allEntities.forEach((function(s){var u=(0,r.A)(s,2)[1],l=n.find((function(e){return(0,r.A)(e,2)[1]===u}));if(u.selectIfLocatedInRectangle(e,t,!!l,i)){var c=o.createDrawingEntitySelectionCommand(u);a.merge(c)}})),a}},{key:"startPolymerBondCreationChangeModel",value:function(e,t,n,o){if(o)return this.polymerBonds.set(o.id,o),o;var r=new Xr(e);if(this.polymerBonds.set(r.id,r),e.chosenFirstAttachmentPointForBond){var i=e.startBondAttachmentPoint;e.setBond(i,r),e.setPotentialBond(i,r)}return r.moveBondStartAbsolute(t.x,t.y),r.moveBondEndAbsolute(n.x,n.y),r}},{key:"startPolymerBondCreation",value:function(e,t,n){var o=new Zo,r=new Qo(this.startPolymerBondCreationChangeModel.bind(this,e,t,n),this.deletePolymerBondChangeModel.bind(this));return o.addOperation(r),{command:o,polymerBond:r.polymerBond}}},{key:"deletePolymerBondChangeModel",value:function(e){var t,n,o;this.polymerBonds.delete(e.id);var r,i=e.firstMonomer.getAttachmentPointByBond(e),a=null===(t=e.secondMonomer)||void 0===t?void 0:t.getAttachmentPointByBond(e);e.firstMonomer.removePotentialBonds(),null===(n=e.secondMonomer)||void 0===n||n.removePotentialBonds(),e.firstMonomer.turnOffSelection(),null===(o=e.secondMonomer)||void 0===o||o.turnOffSelection(),i&&e.firstMonomer.unsetBond(i),a&&(null===(r=e.secondMonomer)||void 0===r||r.unsetBond(a))}},{key:"deletePolymerBond",value:function(e){var t,n=new Zo,o=new Jo(e,this.deletePolymerBondChangeModel.bind(this,e),this.finishPolymerBondCreationModelChange.bind(this,e.firstMonomer,e.secondMonomer,e.firstMonomer.getAttachmentPointByBond(e),null===(t=e.secondMonomer)||void 0===t?void 0:t.getAttachmentPointByBond(e)));return n.addOperation(o),n}},{key:"cancelPolymerBondCreation",value:function(e,t){this.polymerBonds.delete(e.id);var n=new Zo;e.firstMonomer.removeBond(e),e.firstMonomer.removePotentialBonds(!0),e.firstMonomer.turnOffSelection(),e.firstMonomer.turnOffHover(),e.firstMonomer.turnOffAttachmentPointsVisibility(),null==t||t.turnOffSelection(),null==t||t.turnOffHover(),null==t||t.turnOffAttachmentPointsVisibility();var o=new nr(e,t);return n.addOperation(o),n}},{key:"movePolymerBond",value:function(e,t){var n=new Zo;e.moveBondEndAbsolute(t.x,t.y);var o=new er(e);return n.addOperation(o),n}},{key:"finishPolymerBondCreationModelChange",value:function(e,t,n,o,r){var i;if(r)return this.polymerBonds.set(r.id,r),e.setBond(n,r),t.setBond(o,r),r;var a=new Xr(e);return this.polymerBonds.set(a.id,a),a.setSecondMonomer(t),a.firstMonomer.setBond(n,a),f()(a.secondMonomer),a.secondMonomer.setBond(o,a),a.firstMonomer.removePotentialBonds(!0),a.secondMonomer.removePotentialBonds(!0),a.firstMonomer.setChosenFirstAttachmentPoint(null),null===(i=a.secondMonomer)||void 0===i||i.setChosenSecondAttachmentPoint(null),a.moveToLinkedMonomers(),a.firstMonomer.turnOffSelection(),a.firstMonomer.turnOffHover(),a.firstMonomer.turnOffAttachmentPointsVisibility(),a.secondMonomer.turnOffSelection(),a.secondMonomer.turnOffHover(),a.secondMonomer.turnOffAttachmentPointsVisibility(),a.turnOffHover(),a}},{key:"finishPolymerBondCreation",value:function(e,t,n,o){var r=new Zo,i=e.firstMonomer;this.polymerBonds.delete(e.id);var a=new or(this.finishPolymerBondCreationModelChange.bind(this,i,t,n,o),this.deletePolymerBondChangeModel.bind(this));return r.addOperation(a),r}},{key:"createPolymerBond",value:function(e,t,n,o){var r=new Zo,i=new or(this.finishPolymerBondCreationModelChange.bind(this,e,t,n,o),this.deletePolymerBondChangeModel.bind(this));return r.addOperation(i),r}},{key:"intendToStartBondCreation",value:function(e){var t=new Zo;e.turnOnHover(),e.turnOnAttachmentPointsVisibility();var n=new iu(e,!0);return t.addOperation(n),t}},{key:"intendToStartAttachmenPointBondCreation",value:function(e,t){var n=new Zo;e.turnOnHover(),e.turnOnAttachmentPointsVisibility();var o=new au(e,t);return n.addOperation(o),n}},{key:"intendToFinishBondCreation",value:function(e,t,n){var o=new Zo;if(e.turnOnHover(),e.turnOnAttachmentPointsVisibility(),n){t.firstMonomer.removePotentialBonds(),e.removePotentialBonds();var r=t.firstMonomer.getValidSourcePoint(e),i=e.getValidTargetPoint(t.firstMonomer);t.firstMonomer.setPotentialBond(r,t),e.setPotentialBond(i,t)}var a=new iu(t.firstMonomer,!0),s=new iu(e,!0);return o.addOperation(a),o.addOperation(s),o}},{key:"intendToFinishAttachmenPointBondCreation",value:function(e,t,n,o){var r=new Zo;if(e.turnOnHover(),e.turnOnAttachmentPointsVisibility(),e.isAttachmentPointUsed(n)){var i=new iu(e,!0);return r.addOperation(i),r}if(n&&(e.setPotentialSecondAttachmentPoint(n),e.setPotentialBond(n,t)),o){t.firstMonomer.removePotentialBonds(),e.removePotentialBonds();var a=t.firstMonomer.getValidSourcePoint(e),s=e.getValidTargetPoint(t.firstMonomer);t.firstMonomer.setPotentialBond(a,t),e.setPotentialBond(s,t)}var u=new iu(t.firstMonomer,!0),l=new au(e,n);return r.addOperation(u),r.addOperation(l),r}},{key:"cancelIntentionToFinishBondCreation",value:function(e,t){var n=new Zo;e.turnOffHover(),e.turnOffAttachmentPointsVisibility(),e.setPotentialSecondAttachmentPoint(null),e.removePotentialBonds();var o=new iu(e,!0);if(n.addOperation(o),t&&!t.firstMonomer.chosenFirstAttachmentPointForBond){t.firstMonomer.removePotentialBonds();var r=new iu(t.firstMonomer,!0);n.addOperation(r)}return n}},{key:"intendToSelectDrawingEntity",value:function(e){var t=new Zo;e.turnOnHover();var n=new uu(e);return t.addOperation(n),t}},{key:"cancelIntentionToSelectDrawingEntity",value:function(e){var t=new Zo;e.turnOffHover();var n=new uu(e);return t.addOperation(n),t}},{key:"showPolymerBondInformation",value:function(e){var t=new Zo;e.turnOnHover(),e.firstMonomer.turnOnHover(),e.firstMonomer.turnOnAttachmentPointsVisibility(),f()(e.secondMonomer),e.secondMonomer.turnOnHover(),e.secondMonomer.turnOnAttachmentPointsVisibility();var n=new tr(e);return t.addOperation(n),t}},{key:"hidePolymerBondInformation",value:function(e){var t=new Zo;e.turnOffHover(),e.firstMonomer.turnOffHover(),e.firstMonomer.turnOffAttachmentPointsVisibility(),f()(e.secondMonomer),e.secondMonomer.turnOffHover(),e.secondMonomer.turnOffAttachmentPointsVisibility();var n=new tr(e);return t.addOperation(n),t}},{key:"addRnaPreset",value:function(e){var t,n=this,o=e.sugar,i=e.sugarPosition,a=e.phosphate,s=e.phosphatePosition,u=e.rnaBase,l=e.rnaBasePosition,c=new Zo,d=[];u&&l&&d.push([u,l]),d.push([o,i]),a&&s&&d.push([a,s]);var h=[];return d.forEach((function(e){var o=(0,r.A)(e,2),i=o[0],a=o[1],s=new ou(n.addMonomerChangeModel.bind(n,i,a),n.deleteMonomerChangeModel.bind(n)),u=s.monomer;if(h.push(u),c.addOperation(s),t){var l=t.getValidSourcePoint(u),d=u.getValidSourcePoint(t);f()(l),f()(d);var m=new or(n.finishPolymerBondCreationModelChange.bind(n,t,u,l,d),n.deletePolymerBondChangeModel.bind(n));c.addOperation(m)}t=u})),{command:c,monomers:h}}},{key:"findChainByMonomer",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Set;for(var o in t.push(e),n.add(e.id),e.attachmentPointsToBonds){var r=e.attachmentPointsToBonds[o];if(r){var i=e===r.firstMonomer?r.secondMonomer:r.firstMonomer;n.has(i.id)||this.findChainByMonomer(i,t,n)}}return t}},{key:"rearrangeChainModelChange",value:function(e,t){return e.moveAbsolute(t),e}},{key:"getNucleotideSize",value:function(e){var t,n,o,r;return{width:((null===(t=e.sugar.renderer)||void 0===t||null===(t=t.monomerSize)||void 0===t?void 0:t.width)||0)+((null===(n=e.phosphate)||void 0===n||null===(n=n.renderer)||void 0===n||null===(n=n.monomerSize)||void 0===n?void 0:n.width)||0)+(e.phosphate?Ks:0),height:((null===(o=e.sugar.renderer)||void 0===o||null===(o=o.monomerSize)||void 0===o?void 0:o.height)||0)+((null===(r=e.rnaBase.renderer)||void 0===r||null===(r=r.monomerSize)||void 0===r?void 0:r.height)||0)+Ks}}},{key:"reArrangeChain",value:function(e,t,n,o,r,i,a){var s,u,l,c,d=new Zo,h=null!==(s=null===(u=e.renderer)||void 0===u||null===(u=u.monomerSize)||void 0===u?void 0:u.width)&&void 0!==s?s:0,f=(null!==(l=null===(c=e.renderer)||void 0===c||null===(c=c.monomerSize)||void 0===c?void 0:c.height)&&void 0!==l?l:0)+30;i=Math.max(i,f),e.isMonomerInRnaChainRow=i>f;var m=e.position,p=new ru(this.rearrangeChainModelChange.bind(this,e,sn.canvasToModel(t)),this.rearrangeChainModelChange.bind(this,e,m));d.addOperation(p),o.add(e.id);var v=this.getNextMonomerPositionForSnakeLayout(e,h,t,n,o,r,i);return{lastPosition:(null==v?void 0:v.lastPosition)||t,maxVerticalDistance:(null==v?void 0:v.maxVerticalDistance)||i,nextMonomer:no(e,a),command:d}}},{key:"reArrangeRnaChain",value:function(e,t,n,o,r,i,a){var s,u,l,c,d,h,f=new Zo,m=this.getNucleotideSize(e),p=m.height,v=m.width,g=p+30;i=Math.max(i,g),e.sugar.isMonomerInRnaChainRow=!0,e.rnaBase.isMonomerInRnaChainRow=!0;var y=e.sugar.position,b=new we(t.x,t.y+(null!==(s=null===(u=e.sugar.renderer)||void 0===u||null===(u=u.monomerSize)||void 0===u?void 0:u.height)&&void 0!==s?s:0)/2+(null!==(l=null===(c=e.rnaBase.renderer)||void 0===c||null===(c=c.monomerSize)||void 0===c?void 0:c.height)&&void 0!==l?l:0)/2+Ks);if(this.addRnaOperations(f,y,t,e.sugar),this.addRnaOperations(f,null===(d=e.rnaBase)||void 0===d?void 0:d.position,b,e.rnaBase),o.add(e.sugar.id),o.add(null===(h=e.rnaBase)||void 0===h?void 0:h.id),e.phosphate){var A,w,E,P,x,S;e.phosphate.isMonomerInRnaChainRow=!0;var O=new we(t.x+(null!==(A=null===(w=e.sugar.renderer)||void 0===w||null===(w=w.monomerSize)||void 0===w?void 0:w.width)&&void 0!==A?A:0)/2+(null!==(E=null===(P=e.phosphate)||void 0===P||null===(P=P.renderer)||void 0===P||null===(P=P.monomerSize)||void 0===P?void 0:P.width)&&void 0!==E?E:0)/2+Ks,t.y);this.addRnaOperations(f,null===(x=e.phosphate)||void 0===x?void 0:x.position,O,e.phosphate),o.add(null===(S=e.phosphate)||void 0===S?void 0:S.id)}var k=e.baseMonomer===e.sugar&&e.phosphate?e.phosphate:e.sugar,M=this.getNextMonomerPositionForSnakeLayout(k,v,t,n,o,r,i);this.setRnaBaseSideChainMonomers(e.rnaBase,o,r);var R=no(k,a);return{command:f,lastPosition:(null==M?void 0:M.lastPosition)||t,maxVerticalDistance:(null==M?void 0:M.maxVerticalDistance)||i,nextMonomer:R}}},{key:"getNextMonomerPositionForSnakeLayout",value:function(e,t,n,o,r,i,a){var s;for(var u in e.attachmentPointsToBonds){var l=e.attachmentPointsToBonds[u],c=null==l?void 0:l.getAnotherMonomer(e);l&&!r.has(c.id)&&("R2"===u&&"R1"===c.getAttachmentPointByBond(l)||"R1"===u&&"R2"===c.getAttachmentPointByBond(l)?s=this.getNextPositionAndDistance(n,t,a,o):i.push(c))}return s}},{key:"setRnaBaseSideChainMonomers",value:function(e,t,n){var o,r=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return Cc(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Cc(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}(Object.keys(e.attachmentPointsToBonds).reverse());try{for(r.s();!(o=r.n()).done;){var i=o.value,a=e.attachmentPointsToBonds[i],s=null==a?void 0:a.getAnotherMonomer(e);a&&s&&!t.has(s.id)&&n.push(s)}}catch(e){r.e(e)}finally{r.f()}}},{key:"addRnaOperations",value:function(e,t,n,o){if(o&&t&&n){var r=new ru(this.rearrangeChainModelChange.bind(this,o,sn.canvasToModel(n)),this.rearrangeChainModelChange.bind(this,o,t));e.addOperation(r)}}},{key:"reArrangeChains",value:function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=new Zo;if(t){var i=new Set,a=new we({x:50,y:50}),s=this.getFirstMonomersInChains([Dn,Fn,eo,Kn],(0,o.A)(this.monomers.values())),u=this.reArrangeMonomers(e,s,i,a);r.merge(u.command)}return n&&r.merge(this.redrawBonds()),r}},{key:"redrawBondsModelChange",value:function(e,t,n){return t&&n?(e.moveBondStartAbsolute(t.x,t.y),e.moveBondEndAbsolute(n.x,n.y)):e.moveToLinkedMonomers(),e}},{key:"redrawBonds",value:function(){var e=this,t=new Zo;return this.polymerBonds.forEach((function(n){t.merge(e.createDrawingEntityRedrawCommand(e.redrawBondsModelChange.bind(e,n),e.redrawBondsModelChange.bind(e,n,n.startPosition,n.endPosition)))})),t}},{key:"getFirstMonomersInChains",value:function(e,t){var n=t.filter((function(t){return e.some((function(e){return t instanceof e}))})),i=n.filter((function(e){var t=e.getBondByAttachmentPoint(dn.R2),n=(!e.attachmentPointsToBonds.R1||e.attachmentPointsToBonds.R1.isSideChainConnection)&&(null==t?void 0:t.isBackBoneChainConnection),o=!e.attachmentPointsToBonds.R1&&!e.attachmentPointsToBonds.R2;return n||o})),a=Bc.getFirstMonomersInChains(n),s=(0,r.A)(a,2);s[0];var u=s[1];return i.push.apply(i,(0,o.A)(u)),i.sort((function(e,t){return t.position.x+t.position.y>e.position.x+e.position.y?-1:1})),i}},{key:"reArrangeChainInRecursive",value:function(e,t,n,o,r,i){for(var a=e,s=new Zo,u=[{monomer:e,lastPosition:t,maxVerticalDistance:i}],l={lastPosition:t,maxVerticalDistance:i};u.length>0;){var c=u.pop();f()(c);var d=c.lastPosition,h=c.maxVerticalDistance,m=c.monomer,p=void 0,v=void 0;if(m instanceof eo||m instanceof Kn){var g=Dc(m);g?(p=this.reArrangeRnaChain,v=g):(p=this.reArrangeChain,v=m)}else p=this.reArrangeChain,v=m;var y=p.call(this,v,d,n,o,r,h,a);s.merge(y.command),null!=y&&y.lastPosition&&(l=y),null!=y&&y.nextMonomer&&u.push({monomer:y.nextMonomer,lastPosition:y.lastPosition,maxVerticalDistance:y.maxVerticalDistance})}return{command:s,lastPosition:l.lastPosition,maxVerticalDistance:l.maxVerticalDistance}}},{key:"getNextPositionAndDistance",value:function(e,t,n,o){return e.x+t+15+25+55<o?{maxVerticalDistance:n,lastPosition:new we({x:e.x+t+25,y:e.y})}:{maxVerticalDistance:0,lastPosition:Nc(n,e)}}},{key:"isPartOfR2R1Chain",value:function(e){var t,n,o=e.attachmentPointsToBonds.R1,r=e.attachmentPointsToBonds.R2;return"R2"===(null==o||null===(t=o.getAnotherMonomer(e))||void 0===t?void 0:t.getAttachmentPointByBond(o))||"R1"===(null==r||null===(n=r.getAnotherMonomer(e))||void 0===n?void 0:n.getAttachmentPointByBond(r))}},{key:"getFirstMonomerInR2R1Chain",value:function(e){var t,n=e.attachmentPointsToBonds.R1;return n&&"R2"===(null===(t=n.getAnotherMonomer(e))||void 0===t?void 0:t.getAttachmentPointByBond(n))?this.getFirstMonomerInR2R1Chain(n.getAnotherMonomer(e)):e}},{key:"reArrangeMonomers",value:function(e,t,n,r){var i=this,a=new Zo;return t.forEach((function(t){if(!n.has(t.id)){var s=[],u=i.reArrangeChainInRecursive(t,r,e,n,s,0);a.merge(u.command),r=u.lastPosition,r=Nc(u.maxVerticalDistance,r),s.length>0&&s.reverse().forEach((function(t){var s=i.findChainByMonomer(t,void 0,new Set((0,o.A)(n))),u=i.getFirstMonomersInChains([Dn,Fn,eo,Kn],s);if(!n.has(t.id)){if(u.length)if(i.isPartOfR2R1Chain(t))u=[i.getFirstMonomerInR2R1Chain(t)];else{var l,c,d=t.position,h=new ru(i.rearrangeChainModelChange.bind(i,t,sn.canvasToModel(r)),i.rearrangeChainModelChange.bind(i,t,d));n.add(t.id),a.addOperation(h);var f=(null!==(l=null===(c=t.renderer)||void 0===c||null===(c=c.monomerSize)||void 0===c?void 0:c.height)&&void 0!==l?l:0)+30;r=Nc(f,r)}else u=[t];var m=i.reArrangeMonomers(e,u,n,r);a.merge(m.command),r=m.lastPosition}}))}})),{command:a,lastPosition:r}}},{key:"setMicromoleculesHiddenEntities",value:function(e){e.mergeInto(this.micromoleculesHiddenEntities),this.micromoleculesHiddenEntities.atoms=new Gt,this.micromoleculesHiddenEntities.bonds=new Gt,this.micromoleculesHiddenEntities.halfBonds=new Gt,this.micromoleculesHiddenEntities.sgroups=new Gt,this.micromoleculesHiddenEntities.functionalGroups=new Gt,this.micromoleculesHiddenEntities.sGroupForest=new Ct,this.micromoleculesHiddenEntities.frags=new Gt}},{key:"clearMicromoleculesHiddenEntities",value:function(){this.micromoleculesHiddenEntities=new Yt}},{key:"mergeInto",value:function(e){var t=new Zo,n=new Map;return this.monomers.forEach((function(o){var r=e.addMonomer(o.monomerItem,o.position);n.set(o,r.operations[0].monomer),t.merge(r)})),this.polymerBonds.forEach((function(o){f()(o.secondMonomer);var r=e.createPolymerBond(n.get(o.firstMonomer),n.get(o.secondMonomer),o.firstMonomer.getAttachmentPointByBond(o),o.secondMonomer.getAttachmentPointByBond(o));t.merge(r)})),this.micromoleculesHiddenEntities.mergeInto(e.micromoleculesHiddenEntities),t}},{key:"centerMacroStructure",value:function(){var e=sn.canvasToModel(function(){var e=zc.provideEditorInstance(),t=new we(e.canvasOffset.width/2,e.canvasOffset.height/2);return sn.viewToCanvas(t)}()),t=this.getMacroStructureCenter(),n=we.diff(e,t);this.monomers.forEach((function(e){e.moveAbsolute(new we(e.position).add(n))})),this.polymerBonds.forEach((function(e){var t=new we(e.position).add(n),o=t.x,r=t.y;e.moveBondStartAbsolute(o,r);var i=new we(e.endPosition).add(n),a=i.x,s=i.y;e.moveBondEndAbsolute(a,s)}))}},{key:"getMacroStructureCenter",value:function(){var e=1e50,t=e,n=-e,o=-t;return this.monomers.forEach((function(r){e=Math.min(e,r.position.x),t=Math.min(t,r.position.y),n=Math.max(n,r.position.x),o=Math.max(o,r.position.y)})),this.polymerBonds.forEach((function(r){e=Math.min(e,r.position.x),t=Math.min(t,r.position.y),n=Math.max(n,r.position.x),o=Math.max(o,r.position.y)})),new we((e+n)/2,(t+o)/2)}},{key:"applyMonomersSequenceLayout",value:function(){var e=Bc.fromMonomers((0,o.A)(this.monomers.values()));return e.rearrange(),Ts.show(e),e}},{key:"clearCanvas",value:function(){var e=zc.provideEditorInstance();this.monomers.forEach((function(t){e.renderersContainer.deleteMonomer(t)})),this.polymerBonds.forEach((function(t){e.renderersContainer.deletePolymerBond(t)})),Ts.removeEmptyNodes()}},{key:"applyFlexLayoutMode",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=zc.provideEditorInstance(),n=new Zo;return e&&n.merge(this.redrawBonds()),this.monomers.forEach((function(e){t.renderersContainer.deleteMonomer(e),t.renderersContainer.addMonomer(e)})),this.polymerBonds.forEach((function(e){t.renderersContainer.deletePolymerBond(e),t.renderersContainer.addPolymerBond(e)})),Ts.removeEmptyNodes(),n}},{key:"getAllSelectedEntities",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!(zc.provideEditorInstance().mode instanceof Ds)||e instanceof Xr)return[e];var n=[e];if(e.isPartOfRna&&e instanceof eo){var o=e;if(so(o)){var r=Vc.fromSugar(o);n.push(r.rnaBase),t&&r.rnaBase.hasBonds&&r.rnaBase.forEachBond((function(e){n.push(e)}))}else if(ao(o)){var i=Lr.fromSugar(o);n.push(i.rnaBase),n.push(i.phosphate),t&&i.rnaBase.hasBonds&&i.rnaBase.forEachBond((function(e){n.push(e)})),t&&i.phosphate.hasBonds&&i.phosphate.forEachBond((function(e){n.push(e)}))}}var a=e;return t&&a.hasBonds&&a.forEachBond((function(e){n.includes(e)||n.push(e)})),n}},{key:"validateIfApplicableForFasta",value:function(){var e=new Set,t=!0;return this.monomers.forEach((function(n){var o=n.monomerItem.props.MonomerType;e.add(o),(o===Ys||e.size>1)&&(t=!1)})),t}},{key:"moveMonomer",value:function(e,t){var n=e.position,o=new Zo,r=new ru(this.rearrangeChainModelChange.bind(this,e,t),this.rearrangeChainModelChange.bind(this,e,n));return o.addOperation(r),o}}]),e}();function Nc(e,t){return new we(50,t.y+e)}function Dc(e){if(e instanceof eo){var t=no(e),n=oo(e);if(t&&t instanceof Kn&&n instanceof Gn)return{sugar:e,phosphate:t,rnaBase:n,baseMonomer:e};if(!(t instanceof Kn)&&n instanceof Gn)return{sugar:e,rnaBase:n,baseMonomer:e}}if(e instanceof Kn){var o=e.attachmentPointsToBonds.R1,r=null==o?void 0:o.getAnotherMonomer(e),i=oo(r);if(r&&r instanceof eo&&i instanceof Gn)return{sugar:r,phosphate:e,rnaBase:i,baseMonomer:e}}}var Lc,_c=function(){function e(t){return(0,i.A)(this,e),(0,d.A)(this,"historyStack",[]),(0,d.A)(this,"historyPointer",0),e._instance?e._instance:(this.editor=t,this.historyPointer=0,e._instance=this,this)}return(0,a.A)(e,[{key:"update",value:function(e,t){var n=this.historyStack[this.historyStack.length-1];t&&n?n.merge(e):(this.historyStack.splice(this.historyPointer,33,e),this.historyStack.length>32&&this.historyStack.shift(),this.historyPointer=this.historyStack.length)}},{key:"undo",value:function(){var e,t;if(0!==this.historyPointer){f()(this.editor),this.historyPointer--,this.historyStack[this.historyPointer].invert(this.editor.renderersContainer);var n=null===(e=this.editor)||void 0===e?void 0:e.drawingEntitiesManager.unselectAllDrawingEntities();null===(t=this.editor)||void 0===t||t.renderersContainer.update(n)}}},{key:"redo",value:function(){this.historyPointer!==this.historyStack.length&&(f()(this.editor),this.historyStack[this.historyPointer].execute(this.editor.renderersContainer),this.historyPointer++)}},{key:"destroy",value:function(){e._instance=null}}]),e}();function Fc(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Hc(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Fc(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Fc(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var jc,Gc,zc=function(){function e(t){var n=t.theme,o=t.canvas;(0,i.A)(this,e),(0,d.A)(this,"lastCursorPosition",new we(0,0)),(0,d.A)(this,"lastCursorPositionOfCanvas",new we(0,0)),(0,d.A)(this,"_monomersLibrary",[]),(0,d.A)(this,"mode",new ur),(0,d.A)(this,"sequenceTypeEnterMode",jc.RNA),(0,d.A)(this,"hotKeyEventHandler",(function(){})),this.theme=n,this.canvas=o,yo(),this.events=vo,this.subscribeEvents(),this.renderersContainer=new nu({theme:n}),this.drawingEntitiesManager=new Ic,this.domEventSetup(),this.setupContextMenuEvents(),this.setupKeyboardEvents(),this.canvasOffset=this.canvas.getBoundingClientRect(),this.zoomTool=an.initInstance(this.drawingEntitiesManager),Lc=this;var r=Pc.getKetcher();this.micromoleculesEditor=null==r?void 0:r.editor,this.switchToMacromolecules()}return(0,a.A)(e,[{key:"selectedTool",get:function(){return this.tool}},{key:"setMonomersLibrary",value:function(e){this._monomersLibrary=e}},{key:"monomersLibrary",get:function(){return(0,x.groupBy)(this._monomersLibrary.map((function(e){return Hc(Hc({},e),{},{label:e.props.MonomerName})})),(function(e){return e.props.MonomerType}))}},{key:"handleHotKeyEvents",value:function(e){var t,n=wo,o=ve(n),r=me.lookup(o,e),i="INPUT"===e.target.nodeName||"TEXTAREA"===e.target.nodeName;null!==(t=n[r])&&void 0!==t&&t.handler&&!i&&(n[r].handler(this),e.preventDefault())}},{key:"setupKeyboardEvents",value:function(){var e,t=this;this.setupHotKeysEvents(),document.addEventListener("keydown",(e=(0,m.A)(v().mark((function e(n){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.mode.onKeyDown(n);case 2:case"end":return e.stop()}}),e)}))),function(t){return e.apply(this,arguments)}))}},{key:"setupHotKeysEvents",value:function(){var e=this;this.hotKeyEventHandler=function(t){return e.handleHotKeyEvents(t)},document.addEventListener("keydown",this.hotKeyEventHandler)}},{key:"setupContextMenuEvents",value:function(){var e=this;document.addEventListener("contextmenu",(function(t){var n;return t.preventDefault(),e.mode instanceof Ds&&!e.mode.isEditMode&&((null===(n=t.target)||void 0===n?void 0:n.__data__)instanceof yr?e.events.rightClickSequence.dispatch(t):e.events.rightClickCanvas.dispatch(t),!1)}))}},{key:"subscribeEvents",value:function(){var e=this;this.events.selectMonomer.add((function(t){return e.onSelectMonomer(t)})),this.events.selectPreset.add((function(t){return e.onSelectRNAPreset(t)})),this.events.selectTool.add((function(t){return e.onSelectTool(t)})),this.events.createBondViaModal.add((function(t){return e.onCreateBond(t)})),this.events.cancelBondCreationViaModal.add((function(t){return e.onCancelBondCreation(t)})),this.events.selectMode.add((function(t){return e.onSelectMode(t)})),this.events.selectHistory.add((function(t){return e.onSelectHistory(t)})),Ao.forEach((function(t){e.events[t].add((function(n){return e.useToolIfNeeded(t,n)}))})),this.events.editSequence.add((function(t){return e.onEditSequence(t)})),this.events.startNewSequence.add((function(){return e.onStartNewSequence()})),this.events.changeSequenceTypeEnterMode.add((function(t){return e.onChangeSequenceTypeEnterMode(t)}))}},{key:"onEditSequence",value:function(e){this.mode instanceof Ds&&this.mode.turnOnEditMode(e)}},{key:"onStartNewSequence",value:function(){this.mode instanceof Ds&&this.mode.startNewSequence()}},{key:"onChangeSequenceTypeEnterMode",value:function(e){this.sequenceTypeEnterMode=e}},{key:"onSelectMonomer",value:function(e){this.selectTool("monomer",e)}},{key:"onSelectRNAPreset",value:function(e){e?this.selectTool("preset",e):this.tool=void 0}},{key:"onSelectTool",value:function(e){this.selectTool(e)}},{key:"onCreateBond",value:function(e){this.tool instanceof qs&&this.tool.handleBondCreation(e)}},{key:"onCancelBondCreation",value:function(e){this.tool instanceof qs&&this.tool.handleBondCreationCancellation(e)}},{key:"onSelectMode",value:function(e){var t="object"===(0,g.A)(e)?e.mode:e,n=Hs[t];f()(n);var o=new _c(this);this.mode.destroy(),this.mode=new n(this.mode.modeName);var r=this.mode.initialize();o.update(r,"object"===(0,g.A)(e)&&(null==e?void 0:e.mergeWithLatestHistoryCommand))}},{key:"setMode",value:function(e){this.mode=e}},{key:"isSequenceEditMode",get:function(){return this.mode instanceof Ds&&this.mode.isEditMode}},{key:"onSelectHistory",value:function(e){var t=new _c(this);"undo"===e?t.undo():"redo"===e&&t.redo()}},{key:"selectTool",value:function(e,t){var n,o=tu[e],r=this.tool;this.tool=new o(this,t),void 0!==(null==(n=r)?void 0:n.destroy)&&(null==r||r.destroy())}},{key:"unsubscribeEvents",value:function(){for(var e in this.events)this.events[e].handlers=[];document.removeEventListener("keydown",this.hotKeyEventHandler)}},{key:"trackedDomEvents",get:function(){return[{target:this.canvas,eventName:"click",toolEventHandler:"click"},{target:this.canvas,eventName:"dblclick",toolEventHandler:"dblclick"},{target:this.canvas,eventName:"mousedown",toolEventHandler:"mousedown"},{target:document,eventName:"mousemove",toolEventHandler:"mousemove"},{target:document,eventName:"mouseup",toolEventHandler:"mouseup"},{target:document,eventName:"mouseleave",toolEventHandler:"mouseleave"},{target:this.canvas,eventName:"mouseleave",toolEventHandler:"mouseLeaveClientArea"},{target:this.canvas,eventName:"mouseover",toolEventHandler:"mouseover"}]}},{key:"domEventSetup",value:function(){var e=this;this.trackedDomEvents.forEach((function(t){var n=t.target,o=t.eventName,r=t.toolEventHandler;e.events[o]=new go;var i=e.events[o];n.addEventListener(o,i.dispatch.bind(i)),i.add((function(t){return e.updateLastCursorPosition(t),["mouseup","mousedown","click","dbclick"].includes(t.type)&&!function(e){return 0===e.button}(t)||(e.useModeIfNeeded(r,t),e.useToolIfNeeded(r,t)),!0}),-1)}))}},{key:"updateLastCursorPosition",value:function(e){if(["mousemove","click","mousedown","mouseup","mouseover"].includes(e.type)){var t=this.canvasOffset;this.lastCursorPosition=new we({x:e.pageX-t.x,y:e.pageY-t.y}),this.lastCursorPositionOfCanvas=sn.viewToCanvas(this.lastCursorPosition)}}},{key:"useToolIfNeeded",value:function(e,t){var n,o,r=this.tool;return!!r&&!![e in r,this.canvas.contains(null==t?void 0:t.target)||(null===(n=r.isSelectionRunning)||void 0===n?void 0:n.call(r))].every((function(e){return e}))&&(null===(o=r[e])||void 0===o||o.call(r,t),!0)}},{key:"useModeIfNeeded",value:function(e,t){var n,o;null===(n=this.mode)||void 0===n||null===(o=n[e])||void 0===o||o.call(n,t)}},{key:"switchToMicromolecules",value:function(){this.unsubscribeEvents(),new _c(this).destroy();var e=this.micromoleculesEditor.struct(),t=this.micromoleculesEditor.render.ctab,n=Hu.convertDrawingEntitiesToStruct(this.drawingEntitiesManager,e,t).conversionErrorMessage;t.render.setMolecule(e),n&&Pc.getKetcher().editor.setMacromoleculeConvertionError(n)}},{key:"switchToMacromolecules",value:function(){var e,t=(null===(e=this.micromoleculesEditor)||void 0===e?void 0:e.struct())||new Yt,n=Pc.getKetcher(),o=Hu.convertStructToDrawingEntities(t,this.drawingEntitiesManager).modelChanges;this.renderersContainer.update(o),null==n||n.editor.clear()}}],[{key:"provideEditorInstance",value:function(){return Lc}}]),e}(),Vc=function(){function e(t,n){(0,i.A)(this,e),this.sugar=t,this.rnaBase=n}return(0,a.A)(e,[{key:"isMonomerTypeDifferentForChaining",value:function(e){return this.sugar.isMonomerTypeDifferentForChaining(e)}},{key:"SubChainConstructor",get:function(){return this.sugar.SubChainConstructor}},{key:"monomer",get:function(){return this.sugar}},{key:"monomers",get:function(){return[this.sugar,this.rnaBase]}},{key:"firstMonomerInNode",get:function(){return this.sugar}},{key:"lastMonomerInNode",get:function(){return this.sugar}},{key:"renderer",get:function(){return this.monomer.renderer}},{key:"modified",get:function(){return this.sugar.label!==Tr.SUGAR_RNA}}],[{key:"fromSugar",value:function(t){if(!(arguments.length>1&&void 0!==arguments[1])||arguments[1]){f()(so(t),"Created nucleoside is not valid. Please check nucleotide parts connections.");var n=ao(t);f()(!n,"Created nucleoside is nucleotide.")}return new e(t,oo(t))}},{key:"createOnCanvas",value:function(t,n){var o=zc.provideEditorInstance(),r=Nr(o,t),i=Dr(o.sequenceTypeEnterMode);f()(i);var a=Nr(o,i);f()(a),f()(r);var s=new Zo;s.merge(o.drawingEntitiesManager.addMonomer(a,n)),s.merge(o.drawingEntitiesManager.addMonomer(r,n));var u=s.operations[0].monomer,l=s.operations[1].monomer;return s.merge(o.drawingEntitiesManager.createPolymerBond(u,l,dn.R3,dn.R1)),{modelChanges:s,node:e.fromSugar(u,!1)}}}]),e}();!function(e){e.RNA="RNA",e.DNA="DNA",e.PEPTIDE="PEPTIDE"}(jc||(jc={})),function(e){e[e.NOT_CYCLED=0]="NOT_CYCLED",e[e.CYCLED=1]="CYCLED"}(Gc||(Gc={}));var Uc,Wc=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;(0,i.A)(this,e),this.type=t,this.priority=n}return(0,a.A)(e,[{key:"execute",value:function(e){throw new Error("Operation.execute() is not implemented")}},{key:"perform",value:function(e){return this.execute(e),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(e){return!1}}],[{key:"invalidateAtom",value:function(t,n,o){var r=t.atoms.get(n);if(r){t.markAtom(n,o?1:0);var i=t.molecule.halfBonds;r.a.neighbors.forEach((function(n){if(i.has(n)){var r=i.get(n);r&&(t.markBond(r.bid,1),t.markAtom(r.end,0),o&&e.invalidateLoop(t,r.bid))}}));var a=r.a.fragment,s=t.render.options.stereoLabelStyle;t.atoms.forEach((function(e,n){s!==ni.IUPAC&&s!==ni.Classic||e.a.fragment===a&&t.markAtom(n,0)}))}}},{key:"invalidateLoop",value:function(e,t){var n=e.bonds.get(t);if(n&&n.b.hb1&&n.b.hb2){var o=e.molecule.halfBonds.get(n.b.hb1),r=e.molecule.halfBonds.get(n.b.hb2);o&&o.loop>=0&&e.loopRemove(o.loop),r&&r.loop>=0&&e.loopRemove(r.loop)}}},{key:"invalidateBond",value:function(t,n){e.invalidateLoop(t,n);var o=t.bonds.get(n);o&&(e.invalidateAtom(t,o.b.begin,0),e.invalidateAtom(t,o.b.end,0))}},{key:"invalidateItem",value:function(t,n,o,r){if("atoms"!==n)return"bonds"===n?(e.invalidateBond(t,o),void(r>0&&e.invalidateLoop(t,o))):void t.markItem(n,o,r);e.invalidateAtom(t,o,r)}},{key:"invalidateEnhancedFlag",value:function(t,n){e.invalidateItem(t,"enhancedFlags",n,1)}}]),e}(),qc=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_ATTACHMENT_POINT_ADD:"Add attachment point to s-group",S_GROUP_ATTACHMENT_POINT_REMOVE:"Remove attachment point from s-group",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",R_GROUP_ATTACHMENT_POINT_ADD:"Add R-group attachment point",R_GROUP_ATTACHMENT_POINT_REMOVE:"Remove R-group attachment point",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_ROTATE:"Rotate 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_SET_PROPERTIES:"Set fragment properties",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",POLYMER_BOND_ADD:"Add polymer bond",POLYMER_BOND_DELETE:"Remove polymer bond",POLYMER_BOND_MOVE:"Move polymer bond",POLYMER_BOND_FINISH_CREATION:"Finish polymer bond creation",POLYMER_BOND_CANCEL_CREATION:"Cancel polymer bond creation",PEPTIDE_ADD:"Add peptide",PEPTIDE_REMOVE:"Remove peptide",PEPTIDE_MOVE:"Move peptide",PEPTIDE_HOVER:"Hover peptide",DRAWING_ENTITY_SELECT:"Select drawing entity",DRAWING_ENTITY_HOVER:"Hover drawing entity",SHOW_POLYMER_BOND_INFORMATION:"Show polymer bond information"});function Yc(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,$c()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function $c(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return($c=function(){return!!e})()}!function(e){e[e.ATOM_ATTR=1]="ATOM_ATTR",e[e.BOND_ADD=1]="BOND_ADD",e[e.R_GROUP_ATTACHMENT_POINT_REMOVE=1]="R_GROUP_ATTACHMENT_POINT_REMOVE",e[e.ATOM_MOVE=2]="ATOM_MOVE",e[e.BOND_ATTR=2]="BOND_ATTR",e[e.BOND_MOVE=2]="BOND_MOVE",e[e.BOND_DELETE=3]="BOND_DELETE",e[e.S_GROUP_ATOM_ADD=3]="S_GROUP_ATOM_ADD",e[e.S_GROUP_ATTACHMENT_POINT_ADD=3]="S_GROUP_ATTACHMENT_POINT_ADD",e[e.R_GROUP_ATTACHMENT_POINT_ADD=3]="R_GROUP_ATTACHMENT_POINT_ADD",e[e.S_GROUP_ATTR=4]="S_GROUP_ATTR",e[e.ATOM_DELETE=5]="ATOM_DELETE",e[e.FRAGMENT_STEREO_FLAG=6]="FRAGMENT_STEREO_FLAG",e[e.CALC_IMPLICIT_H=10]="CALC_IMPLICIT_H",e[e.FRAGMENT_DELETE_STEREO_ATOM=90]="FRAGMENT_DELETE_STEREO_ATOM",e[e.S_GROUP_DELETE=95]="S_GROUP_DELETE",e[e.S_GROUP_ADD_TO_HIERACHY=100]="S_GROUP_ADD_TO_HIERACHY",e[e.FRAGMENT_ADD_STEREO_ATOM=100]="FRAGMENT_ADD_STEREO_ATOM"}(Uc||(Uc={}));var Xc=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=Yc(this,t,[qc.ATOM_ATTR,Uc.ATOM_ATTR])).data={aid:e,attribute:n,value:o},r.data2=null,r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){if(this.data){var t=this.data,n=t.aid,o=t.attribute,r=t.value,i=e.molecule.atoms.get(n);this.data2||(this.data2={aid:n,attribute:o,value:i[o]}),i[o]=r,Wc.invalidateAtom(e,n)}}},{key:"invert",value:function(){var e=new t;return e.data=this.data2,e.data2=this.data,e}},{key:"isDummy",value:function(e){var t,n,o;return e.molecule.atoms.get(null===(t=this.data)||void 0===t?void 0:t.aid)[null===(n=this.data)||void 0===n?void 0:n.attribute]===(null===(o=this.data)||void 0===o?void 0:o.value)}}]),t}(Wc);function Kc(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Zc()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Zc(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Zc=function(){return!!e})()}var Qc=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=Kc(this,t,[qc.ATOM_MOVE,Uc.ATOM_MOVE])).data={aid:e,d:n,noinvalidate:o},r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=this.data,o=n.aid,r=n.d,i=t.atoms.get(o);if(i){i.pp.add_(r);var a=e.atoms.get(o);if(a){var s=Ze.modelToCanvas(r,e.render.options);a.visel.translate(s)}this.data.d=r.negated(),this.data.noinvalidate||Wc.invalidateAtom(e,o,1)}}},{key:"invert",value:function(){var e=new t;return e.data=this.data,e}},{key:"isDummy",value:function(){var e=this.data.d;return 0===e.x&&0===e.y}}]),t}(Wc);function Jc(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,ed()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function ed(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(ed=function(){return!!e})()}var td=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=Jc(this,t,[qc.ATOM_ADD])).data={atom:e,pos:n,aid:null},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.atom,o=t.pos,r=e.molecule,i={label:""};n&&Object.keys(n).forEach((function(e){i[e]=n[e]})),i.label=i.label||"C","number"!=typeof this.data.aid?this.data.aid=r.atoms.add(new Fe(i)):r.atoms.set(this.data.aid,new Fe(i));var a=this.data.aid,s=new bi(r.atoms.get(a));s.component=e.connectedComponents.add(new Re([a])),e.atoms.set(a,s),e.markAtom(a,1),r.atomSetPos(a,new we(o));var u=r.rxnArrows.get(0);u&&(r.atoms.get(a).rxnFragmentType=r.defineRxnFragmentTypeForAtomset(new Re([a]),u.pos[0].x))}},{key:"invert",value:function(){var e=new nd;return e.data=this.data,e}}]),t}(Wc),nd=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Jc(this,t,[qc.ATOM_DELETE,Uc.ATOM_DELETE])).data={aid:e,atom:null,pos:null},n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data.aid,n=e.molecule;this.data.atom||(this.data.atom=n.atoms.get(t),this.data.pos=this.data.atom.pp);var o=e.atoms.get(t);if(o){var r=e.connectedComponents.get(o.component);r.delete(t),0===r.size&&e.connectedComponents.delete(o.component),e.clearVisel(o.visel),e.atoms.delete(t),e.markItemRemoved(),n.atoms.delete(t)}}},{key:"invert",value:function(){var e=new td;return e.data=this.data,e}}]),t}(Wc);function od(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,rd()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function rd(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(rd=function(){return!!e})()}var id=function(e){function t(e,n,o){var r,a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return(0,i.A)(this,t),(r=od(this,t,[qc.BOND_ATTR,Uc.BOND_ATTR])).data={bid:e,attribute:n,value:o,needInvalidateBond:a},r.data2=null,r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){if(this.data){var t=this.data,n=t.attribute,o=t.bid,r=t.value,i=e.molecule.bonds.get(o);this.data2||(this.data2={bid:o,attribute:n,value:i[n]}),i[n]=r,this.data.needInvalidateBond&&Wc.invalidateBond(e,o),"type"===n&&Wc.invalidateLoop(e,o)}}},{key:"isDummy",value:function(e){if(this.data){var t=this.data,n=t.attribute,o=t.bid,r=t.value;return e.molecule.bonds.get(o)[n]===r}return!1}},{key:"invert",value:function(){var e=new t;return e.data=this.data2,e.data2=this.data,e}}]),t}(Wc);function ad(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,sd()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function sd(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(sd=function(){return!!e})()}var ud=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=ad(this,t,[qc.BOND_MOVE,Uc.BOND_MOVE])).data={bid:e,d:n},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.bid,o=t.d,r=e.bonds.get(n);if(r){var i=Ze.modelToCanvas(o,e.render.options);r.visel.translate(i),this.data.d=o.negated()}}},{key:"invert",value:function(){var e=new t;return e.data=this.data,e}}]),t}(Wc);function ld(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,cd()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function cd(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(cd=function(){return!!e})()}var dd=function(e){function t(e,n,o){var r,a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return(0,i.A)(this,t),(r=ld(this,t,[qc.BOND_ADD,Uc.BOND_ADD])).data={bond:o,begin:e,end:n,bid:null,needInvalidateAtoms:a},r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.begin,o=t.bond,r=t.end,i=e.molecule;if(n===r)throw new Error("Distinct atoms expected");this.data.needInvalidateAtoms&&(Wc.invalidateAtom(e,n,1),Wc.invalidateAtom(e,r,1));var a={type:0,begin:0,end:0};o&&Object.keys(o).forEach((function(e){a[e]=o[e]})),a.type=a.type||We.PATTERN.TYPE.SINGLE,a.begin=n,a.end=r;var s=new We(a);"number"==typeof this.data.bid?i.bonds.set(this.data.bid,s):this.data.bid=i.bonds.add(s);var u=this.data.bid,l=i.bonds.get(u);i.bondInitHalfBonds(u),i.atomAddNeighbor(l.hb1),i.atomAddNeighbor(l.hb2),e.bonds.set(u,new Ti(l)),e.markBond(u,1)}},{key:"invert",value:function(){var e=new hd;return e.data=this.data,e}}]),t}(Wc),hd=function(e){function t(e){var n;return(0,i.A)(this,t),(n=ld(this,t,[qc.BOND_DELETE,Uc.BOND_DELETE])).data={bid:e,bond:null,begin:null,end:null},n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data.bid,n=e.molecule;this.data.bond||(this.data.bond=n.bonds.get(t),this.data.begin=this.data.bond.begin,this.data.end=this.data.bond.end),Wc.invalidateBond(e,t);var o=e.bonds.get(t);if(o){[o.b.hb1,o.b.hb2].forEach((function(t){if(void 0!==t){var n=e.molecule.halfBonds.get(t);n&&n.loop>=0&&e.loopRemove(n.loop)}}),e),e.clearVisel(o.visel),e.bonds.delete(t),e.markItemRemoved();var r=n.bonds.get(t);[r.hb1,r.hb2].forEach((function(e){var t=n.halfBonds.get(e);if(t){var o=n.atoms.get(t.begin),r=o.neighbors.indexOf(e),i=(r+o.neighbors.length-1)%o.neighbors.length,a=(r+1)%o.neighbors.length;n.setHbNext(o.neighbors[i],o.neighbors[a]),o.neighbors.splice(r,1)}})),n.halfBonds.delete(r.hb1),n.halfBonds.delete(r.hb2),n.bonds.delete(t)}}},{key:"invert",value:function(){var e=new dd;return e.data=this.data,e}}]),t}(Wc);function fd(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,md()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function md(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(md=function(){return!!e})()}var pd=function(e){function t(e){var n;return(0,i.A)(this,t),(n=fd(this,t,[qc.CANVAS_LOAD])).data={struct:e},n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule;e.clearVisels(),this.data.struct&&e.render.setMolecule(this.data.struct,!0),this.data.struct=t}},{key:"invert",value:function(){var e=new t;return e.data=this.data,e}}]),t}(Wc);function vd(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,gd()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function gd(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(gd=function(){return!!e})()}var yd=function(e){function t(){var e;return(0,i.A)(this,t),(e=vd(this,t,[qc.ALIGN_DESCRIPTORS])).history={},e}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this,n=e.molecule,o=Array.from(n.sgroups.values()).reverse(),r=n.getCoordBoundingBoxObj(),i=new we(r.max.x,r.min.y).add(new we(2,-1));o.forEach((function(o){t.history[o.id]=new we(o.pp),i=i.add(new we(0,.5)),o.pp=i,n.sgroups.set(o.id,o),Wc.invalidateItem(e,"sgroupData",o.id,1)}))}},{key:"invert",value:function(){return new bd(this.history)}}]),t}(Wc),bd=function(e){function t(e){var n;return(0,i.A)(this,t),(n=vd(this,t,[qc.RESTORE_DESCRIPTORS_POSITION])).history=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this,n=e.molecule;Array.from(n.sgroups.values()).forEach((function(o){o.pp=t.history[o.id],n.sgroups.set(o.id,o),Wc.invalidateItem(e,"sgroupData",o.id,1)}))}},{key:"invert",value:function(){return new yd}}]),t}(Wc);function Ad(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,wd()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function wd(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(wd=function(){return!!e})()}var Ed=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=Ad(this,t,[qc.ENHANCED_FLAG_MOVE])).data={frid:e,p:n},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data.frid,n=this.data.p,o=e.molecule.frags.get(t);if(o){var r=o.stereoFlagPosition?new we(o.stereoFlagPosition.x,o.stereoFlagPosition.y):Ke.getDefaultStereoFlagPosition(e.molecule,t),i=we.sum(r,n);o.stereoFlagPosition=i,this.data.p=n.negated(),Wc.invalidateItem(e,"enhancedFlags",t,1)}}},{key:"invert",value:function(){var e=new t;return e.data=this.data,e}}]),t}(Wc);function Pd(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,xd()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function xd(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(xd=function(){return!!e})()}var Sd=function(e){function t(e,n){var o,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return(0,i.A)(this,t),(o=Pd(this,t,[qc.UPDATE_IF_THEN])).rgid_new=e,o.rgid_old=n,o.ifThenHistory=new Map,o.skipRgids=r||[],o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this,n=e.molecule;n.rgroups.forEach((function(e,o){e.ifthen!==t.rgid_old||t.skipRgids.includes(o)||(e.ifthen=t.rgid_new,t.ifThenHistory.set(o,t.rgid_old),n.rgroups.set(o,e))}))}},{key:"invert",value:function(){return new Od(this.rgid_new,this.rgid_old,this.ifThenHistory)}}]),t}(Wc),Od=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=Pd(this,t,[qc.RESTORE_IF_THEN])).rgid_new=e,r.rgid_old=n,r.ifThenHistory=o||new Map,r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule;this.ifThenHistory.forEach((function(e,n){var o=t.rgroups.get(n);o.ifthen=e,t.rgroups.set(n,o)}))}},{key:"invert",value:function(){return new Sd(this.rgid_old,this.rgid_new)}}]),t}(Wc);function kd(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Md()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Md(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Md=function(){return!!e})()}var Rd=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=kd(this,t,[qc.FRAGMENT_ADD])).frid=void 0===e?null:e,n&&(o.properties=n),o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=new Ke([],null,this.properties);null===this.frid?this.frid=t.frags.add(n):t.frags.set(this.frid,n),e.frags.set(this.frid,new qi(n)),e.enhancedFlags.set(this.frid,new Vi)}},{key:"invert",value:function(){return new Bd(this.frid)}}]),t}(Wc),Td=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=kd(this,t,[qc.FRAGMENT_SET_PROPERTIES])).frid=e,o.properties=n,o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule.frags.get(this.frid);t&&(this.properties?t.properties=this.properties:null==t||delete t.properties)}},{key:"invert",value:function(){return new t(this.frid,void 0)}}]),t}(Wc),Bd=function(e){function t(e){var n;return(0,i.A)(this,t),(n=kd(this,t,[qc.FRAGMENT_DELETE,100])).frid=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule;if(t.frags.get(this.frid)){Wc.invalidateItem(e,"frags",this.frid,1),e.frags.delete(this.frid),t.frags.delete(this.frid);var n=e.enhancedFlags.get(this.frid);n&&(e.clearVisel(n.visel),e.enhancedFlags.delete(this.frid))}}},{key:"invert",value:function(){return new Rd(this.frid)}}]),t}(Wc);function Cd(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Id()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Id(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Id=function(){return!!e})()}var Nd=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=Cd(this,t,[qc.FRAGMENT_ADD_STEREO_ATOM,Uc.FRAGMENT_ADD_STEREO_ATOM])).data={frid:e,aid:n},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.aid,o=t.frid,r=e.molecule.frags.get(o);r&&(r.updateStereoAtom(e.molecule,n,o,!0),Wc.invalidateEnhancedFlag(e,o))}},{key:"invert",value:function(){return new Dd(this.data.frid,this.data.aid)}}]),t}(Wc),Dd=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=Cd(this,t,[qc.FRAGMENT_DELETE_STEREO_ATOM,Uc.FRAGMENT_DELETE_STEREO_ATOM])).data={frid:e,aid:n},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.aid,o=t.frid,r=e.molecule.frags.get(o);r&&(r.updateStereoAtom(e.molecule,n,o,!1),Wc.invalidateEnhancedFlag(e,o))}},{key:"invert",value:function(){var e=this.data,t=e.aid,n=e.frid;return new Nd(n,t)}}]),t}(Wc);function Ld(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,_d()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function _d(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(_d=function(){return!!e})()}var Fd=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Ld(this,t,[qc.FRAGMENT_STEREO_FLAG,Uc.FRAGMENT_STEREO_FLAG])).frid=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule;t.frags.get(this.frid).updateStereoFlag(t),Wc.invalidateEnhancedFlag(e,this.frid)}},{key:"invert",value:function(){return new t(this.frid)}}]),t}(Wc);function Hd(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,jd()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function jd(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(jd=function(){return!!e})()}var Gd=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Hd(this,t,[qc.CALC_IMPLICIT_H,Uc.CALC_IMPLICIT_H])).atomIds=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.atomIds;e.molecule.setImplicitHydrogen(t)}},{key:"invert",value:function(){return new t(this.atomIds)}}]),t}(Wc);function zd(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Vd()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Vd(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Vd=function(){return!!e})()}var Ud=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=zd(this,t,[qc.LOOP_MOVE])).data={id:e,d:n},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.id,o=t.d,r=e.reloops.get(n);if(r&&r.visel){var i=Ze.modelToCanvas(o,e.render.options);r.visel.translate(i)}this.data.d=o.negated()}},{key:"invert",value:function(){var e=new t;return e.data=this.data,e}}]),t}(Wc);function Wd(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,qd()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function qd(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(qd=function(){return!!e})()}var Yd=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=Wd(this,t,[qc.R_GROUP_ATTR])).data={rgid:e,attribute:n,value:o},r.data2=null,r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){if(this.data){var t=this.data,n=t.rgid,o=t.attribute,r=t.value,i=e.molecule.rgroups.get(n);if(!i)return;this.data2||(this.data2={rgid:n,attribute:o,value:i[o]}),i[o]=r,Wc.invalidateItem(e,"rgroups",n)}}},{key:"invert",value:function(){var e=new t;return e.data=this.data2,e.data2=this.data,e}},{key:"isDummy",value:function(e){if(this.data){var t=this.data,n=t.rgid,o=t.attribute,r=t.value;return e.molecule.rgroups.get(n)[o]===r}return!1}}]),t}(Wc);function $d(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Xd()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Xd(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Xd=function(){return!!e})()}var Kd=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=$d(this,t,[qc.R_GROUP_FRAGMENT])).rgid_new=e,r.rg_new=o,r.rgid_old=null,r.rg_old=null,r.frid=n,r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule;this.rgid_old=this.rgid_old||At.findRGroupByFragment(t.rgroups,this.frid),this.rg_old=this.rgid_old?t.rgroups.get(this.rgid_old):null,this.removeOld(t,e),this.setNew(t,e)}},{key:"removeOld",value:function(e,t){this.rg_old&&(this.rg_old.frags.delete(this.frid),t.clearVisel(t.rgroups.get(this.rgid_old).visel),0===this.rg_old.frags.size?(t.rgroups.delete(this.rgid_old),e.rgroups.delete(this.rgid_old),t.markItemRemoved()):t.markItem("rgroups",this.rgid_old,1))}},{key:"setNew",value:function(e,t){if(this.rgid_new){var n=e.rgroups.get(this.rgid_new);n?t.markItem("rgroups",this.rgid_new,1):(n=this.rg_new||new At,e.rgroups.set(this.rgid_new,n),t.rgroups.set(this.rgid_new,new Zi(n))),n.frags.add(this.frid)}}},{key:"invert",value:function(){return new t(this.rgid_old,this.frid,this.rg_old)}}]),t}(Wc);function Zd(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Qd()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Qd(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Qd=function(){return!!e})()}var Jd=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Zd(this,t,[qc.R_GROUP_ATTACHMENT_POINT_ADD,Uc.R_GROUP_ATTACHMENT_POINT_ADD])).data=e,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.atomId,o=t.attachmentPointType,r=new xt(n,o),i=e.molecule,a=this.data.attachmentPointId,s=0;void 0===a?s=i.rgroupAttachmentPoints.add(r):(i.rgroupAttachmentPoints.set(a,r),s=a),this.data.attachmentPointId=s;var u=e.atoms.get(n);f()(null!=u),e.rgroupAttachmentPoints.set(s,new Ca(r,u))}},{key:"invert",value:function(){if(void 0===this.data.attachmentPointId)throw Error("Inverted attachmentPointId doesn't exist");return new ih(this.data.attachmentPointId)}}]),t}(Wc);function eh(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function th(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?eh(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eh(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function nh(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,oh()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function oh(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(oh=function(){return!!e})()}var rh={atomId:0,attachmentPointType:1,attachmentPointId:0},ih=function(e){function t(e){var n;return(0,i.A)(this,t),(n=nh(this,t,[qc.R_GROUP_ATTACHMENT_POINT_REMOVE,Uc.R_GROUP_ATTACHMENT_POINT_REMOVE])).data=th(th({},rh),{},{attachmentPointId:e}),n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data.attachmentPointId,n=e.molecule,o=n.rgroupAttachmentPoints.get(t),r=e.rgroupAttachmentPoints.get(t);f()(null!=o&&null!=r),this.data.atomId=o.atomId,this.data.attachmentPointType=o.type,e.markItemRemoved(),e.clearVisel(r.visel),e.rgroupAttachmentPoints.delete(t),n.rgroupAttachmentPoints.delete(t)}},{key:"invert",value:function(){return new Jd(this.data)}}]),t}(Wc);function ah(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,sh()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function sh(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(sh=function(){return!!e})()}var uh=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=ah(this,t,[qc.RXN_ARROW_MOVE])).data={id:e,d:n,noinvalidate:o},r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=this.data.id,o=this.data.d;t.rxnArrows.get(n).pos.forEach((function(e){return e.add_(o)})),e.rxnArrows.get(n).visel.translate(Ze.modelToCanvas(o,e.render.options)),this.data.d=o.negated(),this.data.noinvalidate||Wc.invalidateItem(e,"rxnArrows",n,1)}},{key:"invert",value:function(){var e=new t(this.data.id,this.data.d,this.data.noinvalidate);return e.data=this.data,e}}]),t}(Wc);function lh(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,ch()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function ch(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(ch=function(){return!!e})()}var dh=function(e){function t(e,n,o,r){var a;return(0,i.A)(this,t),(a=lh(this,t,[qc.RXN_ARROW_ROTATE])).data={id:e,angle:n,center:o,noinvalidate:r},a}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t,n=this,o=Ua.degrees(this.data.angle),r=this.data.id,i=e.molecule.rxnArrows.get(r);i&&(i.pos=i.pos.map((function(e){return e.rotateAroundOrigin(o,n.data.center)})));var a=e.render.options,s=this.data.center.scaled(a.microModeScale).add(a.offset);null===(t=e.rxnArrows.get(r))||void 0===t||t.visel.rotate(o,s),this.data.noinvalidate||Wc.invalidateItem(e,"rxnArrows",r,1)}},{key:"invert",value:function(){return new t(this.data.id,-this.data.angle,this.data.center,this.data.noinvalidate)}}]),t}(Wc);function hh(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,fh()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function fh(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(fh=function(){return!!e})()}var mh=Math.PI/12,ph=function(e){function t(e,n,o,r,a,s){var u;return(0,i.A)(this,t),(u=hh(this,t,[qc.RXN_ARROW_RESIZE])).data={id:e,d:n,current:o,anchor:r,noinvalidate:a},u.isSnappingEnabled=s,u}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=this.data.id,o=this.data.d,i=this.data.current,a=t.rxnArrows.get(n),s=e.rxnArrows.get(n);f()(null!=a&&null!=s);var u=this.data.anchor;if(u){var l,c,d,h=a.pos[0].get_xy0(),m=a.pos[1].get_xy0();if(kt.isElliptical(a)){var p=s.getReferencePoints();d=(0,r.A)(p,3)[2]}if(U(u.x)===U(a.pos[1].x)&&U(u.y)===U(a.pos[1].y)){if(this.isSnappingEnabled){var v=vh(i.sub(a.pos[0])),g=a.pos[0].add(v);i.x=g.x,i.y=g.y}a.pos[1].x=u.x=i.x,i.x=m.x,a.pos[1].y=u.y=i.y,i.y=m.y}if(U(u.x)===U(a.pos[0].x)&&U(u.y)===U(a.pos[0].y)){if(this.isSnappingEnabled){var y=vh(i.sub(a.pos[1])),b=a.pos[1].add(y);i.x=b.x,i.y=b.y}a.pos[0].x=u.x=i.x,i.x=h.x,a.pos[0].y=u.y=i.y,i.y=h.y}if(U(u.x)===U(null===(l=d)||void 0===l?void 0:l.x)&&U(u.y)===U(null===(c=d)||void 0===c?void 0:c.y)){var A=s.getArrowParams(a.pos[0].x,a.pos[0].y,a.pos[1].x,a.pos[1].y).angle*Math.PI/180,w=Math.cos(A),E=Math.sin(A),P=i.x-u.x,x=(i.y-u.y)*w-P*E;void 0!==a.height&&(a.height-=x);var S=s.getReferencePoints(),O=(0,r.A)(S,3)[2];u.y=O.y,u.x=O.x}}else this.isSnappingEnabled&&(o=vh(o)),a.pos[1].add_(o);s.visel.translate(Ze.modelToCanvas(o,e.render.options)),this.data.d=o.negated(),this.data.noinvalidate||Wc.invalidateItem(e,"rxnArrows",n,1)}},{key:"invert",value:function(){return new t(this.data.id,this.data.d,this.data.current,this.data.anchor,this.data.noinvalidate,this.isSnappingEnabled)}}]),t}(Wc);function vh(e){var t=Math.PI/2,n=[Math.PI,-Math.PI],o=-Math.PI/2,r=e.oxAngle(),i=e.length();return Math.abs(r-0)<=mh?new we(i,0):Math.abs(r-t)<=mh?new we(0,i):Math.abs(r-n[0])<=mh||Math.abs(r-n[1])<=mh?new we(-i,0):Math.abs(r-o)<=mh?new we(0,-i):e}function gh(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,yh()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function yh(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(yh=function(){return!!e})()}var bh=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=gh(this,t,[qc.RXN_PLUS_MOVE])).data={id:e,d:n,noinvalidate:o},r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.id,o=t.d,r=t.noinvalidate;e.molecule.rxnPluses.get(n).pp.add_(o);var i=e.rxnPluses.get(n),a=Ze.modelToCanvas(o,e.render.options);i.visel.translate(a),this.data.d=o.negated(),r||Wc.invalidateItem(e,"rxnPluses",n,1)}},{key:"invert",value:function(){var e=new t;return e.data=this.data,e}}]),t}(Wc);function Ah(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,wh()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function wh(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(wh=function(){return!!e})()}var Eh=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Ah(this,t,[qc.RXN_PLUS_ADD])).data={plid:null,pos:e},n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=new Bt;"number"==typeof this.data.plid?t.rxnPluses.set(this.data.plid,n):this.data.plid=t.rxnPluses.add(n);var o=this.data,r=o.pos,i=o.plid,a=t.rxnPluses.get(i);e.rxnPluses.set(i,new sa(a)),t.rxnPlusSetPos(i,new we(r)),Wc.invalidateItem(e,"rxnPluses",i,1)}},{key:"invert",value:function(){var e=new Ph;return e.data=this.data,e}}]),t}(Wc),Ph=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Ah(this,t,[qc.RXN_PLUS_DELETE])).data={plid:e,pos:null},n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data.plid,n=e.molecule;this.data.pos||(this.data.pos=n.rxnPluses.get(t).pp),e.markItemRemoved();var o=e.rxnPluses.get(t);o&&(e.clearVisel(o.visel),e.rxnPluses.delete(t),n.rxnPluses.delete(t))}},{key:"invert",value:function(){var e=new Eh;return e.data=this.data,e}}]),t}(Wc);function xh(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Sh()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Sh(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Sh=function(){return!!e})()}var Oh=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Pt.OpenAngle,r=arguments.length>2?arguments[2]:void 0;return(0,i.A)(this,t),(e=xh(this,t,[qc.RXN_ARROW_ADD])).data={pos:n,mode:o,id:r},e}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=new kt({mode:this.data.mode});if(null==this.data.id){var r=t.rxnArrows.add(n);this.data.id=r}else t.rxnArrows.set(this.data.id,n);var i=this.data.id;e.rxnArrows.set(i,new oa(n));var a=(0,o.A)(this.data.pos);t.rxnArrowSetPos(i,a.map((function(e){return new we(e)}))),Wc.invalidateItem(e,"rxnArrows",i,1)}},{key:"invert",value:function(){return new kh(this.data.id)}}]),t}(Wc),kh=function(e){function t(e){var n;return(0,i.A)(this,t),(n=xh(this,t,[qc.RXN_ARROW_DELETE])).data={id:e,pos:[],mode:Pt.OpenAngle},n.performed=!1,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=t.rxnArrows.get(this.data.id);this.data.pos=n.pos,this.data.mode=n.mode,this.performed=!0,e.markItemRemoved(),e.clearVisel(e.rxnArrows.get(this.data.id).visel),e.rxnArrows.delete(this.data.id),t.rxnArrows.delete(this.data.id)}},{key:"invert",value:function(){return new Oh(this.data.pos,this.data.mode,this.data.id)}}]),t}(Wc);function Mh(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Rh()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Rh(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Rh=function(){return!!e})()}var Th=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Tt.line,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a=arguments.length>3?arguments[3]:void 0;return(0,i.A)(this,t),(e=Mh(this,t,[qc.SIMPLE_OBJECT_ADD])).data={pos:n,mode:o,toCircle:r,id:a},e}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=new Lt({mode:this.data.mode});if(null==this.data.id){var r=t.simpleObjects.add(n);this.data.id=r}else t.simpleObjects.set(this.data.id,n);var i=this.data.id;e.simpleObjects.set(i,new Aa(n));var a=(0,o.A)(this.data.pos);this.data.toCircle&&(a[1]=Dh(a[0],a[1])),t.simpleObjectSetPos(i,a.map((function(e){return new we(e)}))),Wc.invalidateItem(e,"simpleObjects",i,1)}},{key:"invert",value:function(){return new Bh(this.data.id)}}]),t}(Wc),Bh=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Mh(this,t,[qc.SIMPLE_OBJECT_DELETE])).data={id:e,pos:[],mode:Tt.line,toCircle:!1},n.performed=!1,n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=t.simpleObjects.get(this.data.id);this.data.pos=n.pos,this.data.mode=n.mode,this.data.toCircle=n.toCircle,this.performed=!0,e.markItemRemoved(),e.clearVisel(e.simpleObjects.get(this.data.id).visel),e.simpleObjects.delete(this.data.id),t.simpleObjects.delete(this.data.id)}},{key:"invert",value:function(){return new Th(this.data.pos,this.data.mode,this.data.toCircle,this.data.id)}}]),t}(Wc),Ch=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=Mh(this,t,[qc.SIMPLE_OBJECT_MOVE])).data={id:e,d:n,noinvalidate:o},r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=this.data.id,o=this.data.d;t.simpleObjects.get(n).pos.forEach((function(e){return e.add_(o)})),e.simpleObjects.get(n).visel.translate(Ze.modelToCanvas(o,e.render.options)),this.data.d=o.negated(),this.data.noinvalidate||Wc.invalidateItem(e,"simpleObjects",n,1)}},{key:"invert",value:function(){var e=new t(this.data.id,this.data.d,this.data.noinvalidate);return e.data=this.data,e}}]),t}(Wc);function Ih(e,t,n){var o=e.pos[0].get_xy0(),r=e.pos[1].get_xy0();U(t.x)===U(e.pos[1].x)&&(e.pos[1].x=t.x=n.x,n.x=r.x),U(t.y)===U(e.pos[1].y)&&(e.pos[1].y=t.y=n.y,n.y=r.y),U(t.x)===U(e.pos[0].x)&&(e.pos[0].x=t.x=n.x,n.x=o.x),U(t.y)===U(e.pos[0].y)&&(e.pos[0].y=t.y=n.y,n.y=o.y)}var Nh=function(e){function t(e,n,o,r,a,s){var u;return(0,i.A)(this,t),(u=Mh(this,t,[qc.SIMPLE_OBJECT_RESIZE])).data={id:e,d:n,current:o,anchor:r,noinvalidate:a,toCircle:s},u}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=this.data.id,o=this.data.d,r=this.data.current,i=t.simpleObjects.get(n),a=this.data.anchor;if(i.mode===Tt.ellipse)if(a)Ih(i,a,r);else if(this.data.toCircle){var s=i.pos[1].get_xy0(),u=Dh(i.pos[0],r);i.pos[1].x=u.x,i.pos[1].y=u.y,this.data.current=s}else{var l=i.pos[1].get_xy0();i.pos[1].x=r.x,i.pos[1].y=r.y,this.data.current=l}else if(i.mode===Tt.line&&a){var c=i.pos[0].get_xy0(),d=i.pos[1].get_xy0();U(a.x)===U(i.pos[1].x)&&U(a.y)===U(i.pos[1].y)&&(i.pos[1].x=a.x=r.x,r.x=d.x,i.pos[1].y=a.y=r.y,r.y=d.y),U(a.x)===U(i.pos[0].x)&&U(a.y)===U(i.pos[0].y)&&(i.pos[0].x=a.x=r.x,r.x=c.x,i.pos[0].y=a.y=r.y,r.y=c.y)}else i.mode===Tt.rectangle&&a?Ih(i,a,r):i.pos[1].add_(o);e.simpleObjects.get(n).visel.translate(Ze.modelToCanvas(o,e.render.options)),this.data.d=o.negated(),this.data.noinvalidate||Wc.invalidateItem(e,"simpleObjects",n,1)}},{key:"invert",value:function(){return new t(this.data.id,this.data.d,this.data.current,this.data.anchor,this.data.noinvalidate,this.data.toCircle)}}]),t}(Wc);function Dh(e,t){var n=we.diff(t,e),o=Math.abs(n.x)<Math.abs(n.y)?n.x:n.y;return new we(e.x+(n.x>0?1:-1)*Math.abs(o),e.y+(n.y>0?1:-1)*Math.abs(o),0)}function Lh(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,_h()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function _h(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(_h=function(){return!!e})()}var Fh=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=Lh(this,t,[qc.S_GROUP_ATOM_ADD,Uc.S_GROUP_ATOM_ADD])).data={sgid:e,aid:n},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.aid,o=t.sgid,r=e.molecule,i=r.atoms.get(n);if(r.sgroups.get(o).atoms.indexOf(n)>=0)throw new Error("The same atom cannot be added to an S-group more than once");if(!i)throw new Error("OpSGroupAtomAdd: Atom "+n+" not found");r.atomAddToSGroup(o,n),Wc.invalidateAtom(e,n)}},{key:"invert",value:function(){var e=new Hh;return e.data=this.data,e}}]),t}(Wc),Hh=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=Lh(this,t,[qc.S_GROUP_ATOM_REMOVE,4])).data={sgid:e,aid:n},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.aid,o=t.sgid,r=e.molecule,i=r.atoms.get(n),a=r.sgroups.get(o);i&&a&&(ht.removeAtom(a,n),i.sgs.delete(o),Wc.invalidateAtom(e,n))}},{key:"invert",value:function(){var e=new Fh;return e.data=this.data,e}}]),t}(Wc);function jh(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Gh()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Gh(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Gh=function(){return!!e})()}var zh=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=jh(this,t,[qc.S_GROUP_ATTR,Uc.S_GROUP_ATTR])).data={sgid:e,attr:n,value:o},r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=this.data.sgid,o=t.sgroups.get(n);if(o){var r=e.sgroupData.get(n);"DAT"===o.type&&r&&(e.clearVisel(r.visel),e.sgroupData.delete(n)),this.data.value=o.setAttr(this.data.attr,this.data.value)}}},{key:"invert",value:function(){var e=new t;return e.data=this.data,e}}]),t}(Wc);function Vh(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Uh()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Uh(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Uh=function(){return!!e})()}var Wh=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=Vh(this,t,[qc.S_GROUP_DATA_MOVE])).data={id:e,d:n},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t,n=this.data,o=n.d,r=n.id;null===(t=e.molecule.sgroups.get(r).pp)||void 0===t||t.add_(o),this.data.d=o.negated(),Wc.invalidateItem(e,"sgroupData",r,1)}},{key:"invert",value:function(){var e=new t;return e.data=this.data,e}}]),t}(Wc);function qh(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Yh()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Yh(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Yh=function(){return!!e})()}var $h=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=qh(this,t,[qc.S_GROUP_ADD_TO_HIERACHY,Uc.S_GROUP_ADD_TO_HIERACHY])).data={sgid:e,parent:n,children:o},r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.sgid,o=t.parent,r=t.children,i=e.molecule,a=i.sgroups.get(n),s=i.sGroupForest.insert(a,o,r);this.data.parent=s.parent,this.data.children=s.children}},{key:"invert",value:function(){var e=new Xh;return e.data=this.data,e}}]),t}(Wc),Xh=function(e){function t(e){var n;return(0,i.A)(this,t),(n=qh(this,t,[qc.S_GROUP_REMOVE_FROM_HIERACHY,110])).data={sgid:e},n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data.sgid,n=e.molecule;this.data.parent=n.sGroupForest.parent.get(t),this.data.children=n.sGroupForest.children.get(t),n.sGroupForest.remove(t)}},{key:"invert",value:function(){var e=new $h;return e.data=this.data,e}}]),t}(Wc);function Kh(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Zh()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Zh(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Zh=function(){return!!e})()}var Qh=function(e){function t(e,n,o,r,a,s){var u;return(0,i.A)(this,t),(u=Kh(this,t,[qc.S_GROUP_CREATE])).data={sgid:e,type:n,pp:o,expanded:r,name:a,oldSgroup:s},u}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=this.data,o=n.sgid,r=n.pp,i=n.expanded,a=n.name,s=n.oldSgroup,u=s instanceof Ut?new Ut(ht.TYPES.SUP,s.monomer):new ht(this.data.type);u.id=o,t.sgroups.set(o,u),r&&(u.pp=new we(r)),i&&(u.data.expanded=i),a&&(u.data.name=a);var l=t.sgroups.get(o);l&&(e.sgroups.set(o,new ma(l)),(gt.isFunctionalGroup(u)||ht.isSuperAtom(u))&&e.molecule.functionalGroups.add(new gt(u))),this.data.sgid=o}},{key:"invert",value:function(){var e=new Jh;return e.data=this.data,e}}]),t}(Wc),Jh=function(e){function t(e){var n;return(0,i.A)(this,t),(n=Kh(this,t,[qc.S_GROUP_DELETE,Uc.S_GROUP_DELETE])).data={sgid:e},n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t,n,o,r,i=e.molecule,a=this.data.sgid,s=e.sgroups.get(a),u=e.sgroupData.get(a);if(s){if(this.data.type=null==s||null===(t=s.item)||void 0===t?void 0:t.type,this.data.pp=null==s||null===(n=s.item)||void 0===n?void 0:n.pp,"DAT"===(null==s||null===(o=s.item)||void 0===o?void 0:o.type)&&u&&(e.clearVisel(u.visel),e.sgroupData.delete(a)),e.clearVisel(s.visel),0!==(null==s||null===(r=s.item)||void 0===r||null===(r=r.atoms)||void 0===r?void 0:r.length))throw new Error("S-Group not empty!");var l;(gt.isFunctionalGroup(s.item)||ht.isSuperAtom(s.item))&&(this.data.name=s.item.data.name,this.data.expanded=s.item.isExpanded(),e.molecule.functionalGroups.forEach((function(e,t){e.relatedSGroupId===a&&(l=t)})),e.molecule.functionalGroups.delete(l)),e.sgroups.delete(a),i.sgroups.delete(a)}}},{key:"invert",value:function(){var e=new Qh;return e.data=this.data,e}}]),t}(Wc);function ef(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,tf()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function tf(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(tf=function(){return!!e})()}var nf=function(e){function t(e,n,o,r){var a;return(0,i.A)(this,t),(a=ef(this,t,[qc.TEXT_CREATE])).data={content:e,position:n,pos:o,id:r},a}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=new Kt(this.data);if(null==this.data.id){var n=e.molecule.texts.add(t);this.data.id=n}else e.molecule.texts.set(this.data.id,t);var o=this.data.id;e.texts.set(o,new Ra(t)),e.molecule.textSetPosition(o,new we(this.data.position)),Wc.invalidateItem(e,"texts",o,1)}},{key:"invert",value:function(){return new of(this.data.id)}}]),t}(Wc),of=function(e){function t(e){var n;return(0,i.A)(this,t),(n=ef(this,t,[qc.TEXT_DELETE])).data={id:e},n}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=t.texts.get(this.data.id);n&&(this.data.content=n.content,this.data.position=n.position,e.markItemRemoved(),e.clearVisel(e.texts.get(this.data.id).visel),e.texts.delete(this.data.id),t.texts.delete(this.data.id))}},{key:"invert",value:function(){return new nf(this.data.content,this.data.position,this.data.pos,this.data.id)}}]),t}(Wc);function rf(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,af()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function af(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(af=function(){return!!e})()}var sf=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=rf(this,t,[qc.TEXT_UPDATE])).data={id:e,content:n},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.id,o=t.content,r=e.molecule.texts.get(n);r&&(this.data.previousContent=r.content,r.content=o),Wc.invalidateItem(e,"texts",n,1)}},{key:"invert",value:function(){var e=new t(this.data.id,this.data.previousContent);return e.data.previousContent=this.data.content,e}}]),t}(Wc);function uf(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,lf()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function lf(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(lf=function(){return!!e})()}var cf=function(e){function t(e,n,o){var r;return(0,i.A)(this,t),(r=uf(this,t,[qc.TEXT_MOVE])).data={id:e,d:n,noinvalidate:o},r}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=this.data.id,o=this.data.d,r=t.texts.get(n),i=e.texts.get(n);r&&i&&(r.position.add_(o),r.setPos(i.getReferencePoints()),i.visel.translate(Ze.modelToCanvas(o,e.render.options)),this.data.d=o.negated(),this.data.noinvalidate||Wc.invalidateItem(e,"texts",n,1))}},{key:"invert",value:function(){var e=new t(this.data.id,this.data.d,this.data.noinvalidate);return e.data=this.data,e}}]),t}(Wc),df=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];(0,i.A)(this,e),this.operations=t}return(0,a.A)(e,[{key:"addOp",value:function(e,t){return t&&e.isDummy(t)||this.operations.push(e),e}},{key:"mergeWith",value:function(e){return this.operations=this.operations.concat(e.operations),this}},{key:"perform",value:function(t){var n=new e;return(0,o.A)(this.operations).sort((function(e,t){return e.priority-t.priority})).forEach((function(e){var o=e.perform(t);n.addOp(o)})),n}},{key:"isDummy",value:function(e){return void 0===this.operations.find((function(t){return!e||!t.isDummy(e)}))}}]),e}(),hf=["id","dist"];function ff(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}var mf=.4,pf={atoms:vf,bonds:gf,enhancedFlags:function(e,t,n,o,r){var i,a=null;return e.enhancedFlags.forEach((function(n,o){var s=e.molecule.frags.get(o);if(s&&s.enhancedStereoFlag&&r.showStereoFlags){var u=s.stereoFlagPosition?new we(s.stereoFlagPosition.x,s.stereoFlagPosition.y):Ke.getDefaultStereoFlagPosition(e.molecule,o);if(u&&!(Math.abs(t.x-u.x)>=1)){var l=Math.abs(t.y-u.y);l<.3&&(!a||l<i)&&(a={id:o,dist:i=l})}}})),a},sgroupData:function(e,t){var n=null,o=null;return e.sgroupData.forEach((function(e,r){if("DAT"!==e.sgroup.type)throw new Error("Data group expected");if("MRV_IMPLICIT_H"!==e.sgroup.data.fieldName){var i=e.sgroup.dataArea,a=i.p0.y<t.y&&i.p1.y>t.y&&i.p0.x<t.x&&i.p1.x>t.x,s=Math.min(Math.abs(i.p0.x-t.x),Math.abs(i.p1.x-t.x));a&&(null===o||s<n)&&(o={id:r,dist:s},n=s)}})),o},sgroups:function(e,t){var n=null,o=mf;return e.molecule.sgroups.forEach((function(r,i){if(r.isContracted()){var a=r.getContractedPosition(e.molecule).position,s=r.bracketDirection,u=s.rotateSC(1,0),l=new we(we.dot(t,s),we.dot(t,u)),c=new we(.625,.625),d={p0:we.diff(a,c),p1:we.sum(a,c)},h=d.p0.y<l.y&&d.p1.y>l.y&&d.p0.x<l.x&&d.p1.x>l.x,f=Math.min(Math.abs(d.p0.x-l.x),Math.abs(d.p1.x-l.x));h&&(null===n||f<o)&&(n=i,o=f)}else{var m=r.bracketDirection,p=m.rotateSC(1,0),v=new we(we.dot(t,m),we.dot(t,p));r.areas.forEach((function(e){var t=e.p0.y<v.y&&e.p1.y>v.y&&e.p0.x<v.x&&e.p1.x>v.x,r=Math.min(Math.abs(e.p0.x-v.x),Math.abs(e.p1.x-v.x));t&&(null===n||r<o)&&(n=i,o=r)}))}})),null!==n?{id:n,dist:o}:null},rxnArrows:function(e,t){var n=null,o=null,r=null;return e.rxnArrows.forEach((function(i,a){var s=i.calcDistance(t,e.render.options.microModeScale);s.minDist<.3&&(!r||s.minDist<n)&&(n=s.minDist,o=s.refPoint,r={id:a,dist:n,ref:o})})),r},rxnPluses:function(e,t){var n=null,o=null;return e.rxnPluses.forEach((function(e,r){var i=e.item.pp,a=Math.max(Math.abs(t.x-i.x),Math.abs(t.y-i.y));a<.3&&(!o||a<n)&&(o={id:r,dist:n=a})})),o},frags:function(e,t,n,o,r){o=Math.min(o||mf,mf);var i=e.molecule,a=vf(e,t,n,o);if(a)return{id:i.atoms.get(a.id).fragment,dist:a.dist};var s=gf(e,t,n,o,r);if(s){var u=i.bonds.get(s.id).begin;return{id:i.atoms.get(u).fragment,dist:s.dist}}return null},rgroups:function(e,t,n,o){o=Math.min(o||mf,mf);var r=null;return e.rgroups.forEach((function(e,i){if(i!==n&&e.labelBox&&e.labelBox.contains(t,.5)){var a=we.dist(e.labelBox.centre(),t);(!r||a<o)&&(r={id:i,dist:o=a})}})),r},simpleObjects:function(e,t){var n=null,o=null,r=null;return e.simpleObjects.forEach((function(i,a){var s=i.calcDistance(t,e.render.options.microModeScale);s.minDist<.3&&(!r||s.minDist<n)&&(n=s.minDist,o=s.refPoint,r={id:a,dist:n,ref:o})})),r},texts:function(e,t){var n=null,o=null;return e.texts.forEach((function(r,i){var a=r.getReferencePoints(e),s=a[0].x,u=a[0].y,l=a[2].x,c=a[2].y,d=[];t.x>=s&&t.x<=l&&(t.y<u?d.push(u-t.y):t.y>c?d.push(t.y-c):d.push(t.y-u,c-t.y)),t.x<s&&t.y<u&&d.push(we.dist(new we(s,u),t)),t.x>l&&t.y>c&&d.push(we.dist(new we(l,c),t)),t.x<s&&t.y>c&&d.push(we.dist(new we(s,c),t)),t.x>l&&t.y<u&&d.push(we.dist(new we(l,u),t)),t.y>=u&&t.y<=c&&(t.x<s?d.push(s-t.x):t.x>l?d.push(t.x-l):d.push(0));var h=Math.min.apply(Math,d);h<mf&&(!o||h<n)&&(o={id:i,dist:n=h})})),o}};function vf(e,t,n,o){var r=null,i=n&&"atoms"===n.map?n.id:null;return o=o||.4,o=Math.min(o,.4),e.atoms.forEach((function(e,n){if(n!==i){var a=we.dist(t,e.a.pp);a<o&&(r=n,o=a)}})),null!==r?{id:r,dist:o}:null}function gf(e,t,n,o,r){var i=null,a=null,s=.32000000000000006,u=n&&"bonds"===n.map?n.id:null;o=o||s;var l=o=Math.min(o,s);return e.bonds.forEach((function(n,o){if(o!==u){var r=e.atoms.get(n.b.begin).a.pp,i=e.atoms.get(n.b.end).a.pp,s=we.lc2(r,.5,i,.5),c=we.dist(t,s);c<l&&(l=c,a=o)}})),e.bonds.forEach((function(n,r){if(r!==u){var a=e.molecule.halfBonds.get(n.b.hb1),s=a.dir,l=a.norm,c=e.atoms.get(n.b.begin).a.pp,d=e.atoms.get(n.b.end).a.pp;if(we.dot(t.sub(c),s)*we.dot(t.sub(d),s)<0){var h=Math.abs(we.dot(t.sub(c),l));h<o&&(i=r,o=h)}}})),null!==a?{id:a,dist:l}:null!==i&&o>mf*r?{id:i,dist:o}:null}var yf={atom:vf,item:function(e,t,n,o,r){return(n=n||Object.keys(pf)).reduce((function(n,i){var a=n?n.dist:null,s=pf[i](e,t,o,a,r);return null!==s&&(null===n||s.dist<n.dist)?function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ff(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ff(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({map:i,id:s.id,dist:s.dist},(0,B.A)(s,hf)):n}),null)},merge:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:["atoms","bonds"],o=arguments.length>3?arguments[3]:void 0,r={atoms:new Map,bonds:new Map},i=e.molecule;t.atoms.forEach((function(e){r.atoms.set(e,i.atoms.get(e).pp)})),t.bonds.forEach((function(e){var t=i.bonds.get(e);r.bonds.set(e,we.lc2(i.atoms.get(t.begin).pp,.5,i.atoms.get(t.end).pp,.5))}));var a={};return n.forEach((function(n){a[n]=Array.from(r[n].keys()).reduce((function(i,a){var s={map:n,id:a},u=pf[n](e,r[n].get(a),s,null,o);return u&&!t[n].includes(u.id)&&i.set(a,u.id),i}),new Map)})),a}};function bf(e,t,n){var o=e.molecule.atoms.get(t);return o?o[n]:null}function Af(e,t){return e.atoms.get(t).a.neighbors.length}function wf(e,t){return Array.from(e.atoms.get(t).a.sgs)}function Ef(e,t){return e.molecule.atoms.get(t).pp}function Pf(e,t){return t?t.filter((function(t){var n=e.atoms.get(t);return null!==(null==n?void 0:n.stereoLabel)||Fe.getConnectedBondIds(e,t).some((function(n){var o=e.bonds.get(n);return(null==o?void 0:o.begin)===t&&(null==o?void 0:o.stereo)}))})):[]}function xf(e){return st.reduce((function(t,n){return t[n]=Array.from(e[n].keys()),t}),{})}function Sf(e,t,n){var o,r,i=[],a=Ef(e,t),s=e.molecule.atomGetNeighbors(t),u=e.molecule.findBondId(t,s.length?null===(o=s[0])||void 0===o?void 0:o.aid:void 0),l=e.molecule.bonds.get(u),c=l?l.type:n?n.type:1;e.molecule.atomGetNeighbors(t).forEach((function(t){var n=Ef(e,t.aid);we.dist(a,n)<.1||i.push({id:t.aid,v:we.diff(n,a)})})),i.sort((function(e,t){return Math.atan2(e.v.y,e.v.x)-Math.atan2(t.v.y,t.v.x)}));var d,h=0,f=0;for(r=0;r<i.length;r++)(d=we.angle(i[r].v,i[(r+1)%i.length].v))<0&&(d+=2*Math.PI),d>f&&(h=r,f=d);var m=new we(1,0);if(i.length>0){if(1===i.length){f=-4*Math.PI/3;var p=e.molecule.atomGetNeighbors(t)[0];if(Af(e,p.aid)>1){var v=[],g=Ef(e,p.aid),y=we.diff(a,g),b=Math.atan2(y.y,y.x);e.molecule.atomGetNeighbors(p.aid).forEach((function(t){var n=Ef(e,t.aid);if(!(t.bid===p.bid||we.dist(g,n)<.1)){var o=we.diff(n,g),r=Math.atan2(o.y,o.x)-b;r<0&&(r+=2*Math.PI),v.push(r)}})),v.sort((function(e,t){return e-t})),v[0]<=1.01*Math.PI&&v[v.length-1]<=1.01*Math.PI&&(f*=-1)}}if(1===i.length&&c===(null==n?void 0:n.type)&&((null==n?void 0:n.type)===We.PATTERN.TYPE.DOUBLE||(null==n?void 0:n.type)===We.PATTERN.TYPE.TRIPLE)||c===We.PATTERN.TYPE.SINGLE&&(null==n?void 0:n.type)===We.PATTERN.TYPE.TRIPLE||c===We.PATTERN.TYPE.TRIPLE&&(null==n?void 0:n.type)===We.PATTERN.TYPE.SINGLE){var A=e.molecule.bonds.get(u).angle;d=A>-90&&A<90&&i[0].v.x>0?A*Math.PI/180+Math.PI:A*Math.PI/180}else d=f/2+Math.atan2(i[h].v.y,i[h].v.x);m=m.rotate(d)}m.add_(a);var w=yf.atom(e,m,null,.1);return{atom:w=null===w?{label:"C"}:w.id,pos:m}}function Of(e,t){return e.sgroups.filter((function(e,n){return!n.data.attached&&!n.data.absolute&&0===(0,x.difference)(n.atoms,t).length}))}function kf(e,t){var n=e.begin,o=e.end;if(!t.atoms)return!1;var r=t.atoms.includes(n)&&!t.atoms.includes(o),i=t.atoms.includes(o)&&!t.atoms.includes(n);return r||i}function Mf(e,t,n){var o=new df;return Object.keys(n).forEach((function(e){o.addOp(new Yd(t,e,n[e]))})),o.perform(e)}function Rf(e,t,n){var o=new df;return o.addOp(new Kd(t,n)),o.perform(e)}function Tf(e,t,n){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],r=new df;return e.molecule.rgroups.get(n)||r.addOp(new Sd(t,n,o)),r.perform(e)}function Bf(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,Cf()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function Cf(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(Cf=function(){return!!e})()}var If=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=Bf(this,t,[qc.S_GROUP_ATTACHMENT_POINT_ADD,Uc.S_GROUP_ATTACHMENT_POINT_ADD])).data={sGroupId:e,attachmentPoint:n},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=e.molecule,n=t.sgroups.get(this.data.sGroupId);f()(null!=n);var o=this.data.attachmentPoint;if(!t.atoms.get(o.atomId))throw new Error('attachmentPoint for Atom with id "'.concat(o.atomId,'" is not found'));n.addAttachmentPoint(o)}},{key:"invert",value:function(){return new Nf(this.data.sGroupId,this.data.attachmentPoint)}}]),t}(Wc),Nf=function(e){function t(e,n){var o;return(0,i.A)(this,t),(o=Bf(this,t,[qc.S_GROUP_ATTACHMENT_POINT_REMOVE,4])).data={sGroupId:e,attachmentPoint:n},o}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.sGroupId,o=t.attachmentPoint,r=e.molecule.sgroups.get(n);null==r||r.removeAttachmentPoint(o.atomId)}},{key:"invert",value:function(){return new If(this.data.sGroupId,this.data.attachmentPoint)}}]),t}(Wc);function Df(e,t,n,o){var r=o.fieldValue;return"string"==typeof r||"DAT"!==t?jf(e,t,n,o,e.molecule.sgroups.newId(),[]):r.reduce((function(r,i){var a=Object.assign({},o);return a.fieldValue=i,r.mergeWith(jf(e,t,n,a,e.molecule.sgroups.newId(),[]))}),new df)}function Lf(e,t,n){var o=new df;Object.keys(n).forEach((function(e){o.addOp(new zh(t,e,n[e]))}));var r=e.molecule.sgroups.get(t);return f()(null!=r),ht.getAtoms(e,r).forEach((function(t){var n;o.mergeWith(nm(e,t,null===(n=e.atoms.get(t))||void 0===n?void 0:n.a,!1))})),o.perform(e)}function _f(e){var t=new df,n=e.molecule;return n.sgroups.forEach((function(o){!o.isNotContractible(n)||o instanceof Ut||t.mergeWith(Lf(e,o.id,{expanded:!0}))})),t}function Ff(e,t){var n=new df;return Object.keys(t).forEach((function(o){n.addOp(new zh(e,o,t[o]))})),n}function Hf(e,t){var n=new df,o=e.molecule,r=e.sgroups.get(t).item;"SRU"===r.type&&(o.sGroupsRecalcCrossBonds(),r.neiAtoms.forEach((function(t){"*"===bf(e,t,"label")&&n.addOp(new Xc(t,"label","C"))})));var i=o.sgroups.get(t),a=ht.getAtoms(o,i),s=i.getAttrs();return n.addOp(new Xh(t)),a.forEach((function(e){n.addOp(new Hh(t,e))})),i.getAttachmentPoints().forEach((function(e){n.addOp(new Nf(t,e))})),n.addOp(new Jh(t)),(n=n.perform(e)).mergeWith(Ff(t,s)),n}function jf(e,t,n,o,r,i,a,s,u,l){var c=new df;if(r=r-0===r?r:e.molecule.sgroups.newId(),"SUP"===t?c.addOp(new Qh(r,t,a,s,u,l)):c.addOp(new Qh(r,t,a)),n.forEach((function(e){c.addOp(new Fh(r,e))})),"SUP"===t&&i.forEach((function(e){c.addOp(new If(r,e))})),c.addOp("DAT"!==t?new $h(r):new $h(r,-1,[])),c=c.perform(e),"SRU"===t){e.molecule.sGroupsRecalcCrossBonds();var d=new df;e.sgroups.get(r).item.neiAtoms.forEach((function(t){var n=e.atoms.get(t).a.isPlainCarbon();1===Af(e,t)&&n&&d.addOp(new Xc(t,"label","*"))})),(d=d.perform(e)).mergeWith(c),c=d}return function(e,t,n){var o=new df;return Object.keys(n).forEach((function(e){o.addOp(new zh(t,e,n[e]))})),o.perform(e)}(e,r,o).mergeWith(c)}function Gf(e,t,n,o,r){if(e===at.Bond)return function(e,t,n,o){var r=e.molecule,i=Wf(r,n);return o.bonds&&(i=(0,T.uniq)(i.concat(o.bonds))),i.reduce((function(n,o){var i=r.bonds.get(o);return n.action=n.action.mergeWith(Df(e,t.type,[i.begin,i.end],t.attrs)),n.selection.bonds.push(o),n}),{action:new df,selection:{atoms:n,bonds:[]}})}(t,n,o,r);var i,a=(i=t.molecule,(r.bonds||[]).reduce((function(e,t){var n=i.bonds.get(t);return e.concat([n.begin,n.end])}),[])),s=(0,T.uniq)(o.concat(a));return e===at.Fragment?zf(t,n,s,Array.from(t.atoms.keys())):e===at.Multifragment?function(e,t,n){var o=Wf(e.molecule,n);return{action:Df(e,t.type,n,t.attrs),selection:{atoms:n,bonds:o}}}(t,n,s):e===at.Group?zf(t,n,s,s):e===at.Atom?function(e,t,n){return n.reduce((function(n,o){return n.action=n.action.mergeWith(Df(e,t.type,[o],t.attrs)),n}),{action:new df,selection:{atoms:n,bonds:[]}})}(t,n,s):ht.isQuerySGroup(n)?function(e,t,n,o){var r={atoms:[],bonds:[]},i=new Re(n.map((function(t){var n;return null===(n=e.atoms.get(t))||void 0===n?void 0:n.a.fragment})));return Array.from(i).forEach((function(t){var n=o.reduce((function(n,o){var r,i=null===(r=e.atoms.get(o))||void 0===r?void 0:r.a;return t===(null==i?void 0:i.fragment)&&n.push(o),n}),[]),i=Wf(e.molecule,n);r.atoms=r.atoms.concat(n),r.bonds=r.bonds.concat(i)})),{action:Df(e,t.type,r.atoms,t.attrs),selection:r}}(t,n,s,Array.from(t.atoms.keys())):{action:Df(t,n.type,s,n.attrs)}}function zf(e,t,n,o){var r=new Re(n.map((function(t){return e.atoms.get(t).a.fragment})));return Array.from(r).reduce((function(n,r){var i=o.reduce((function(t,n){var o=e.atoms.get(n).a;return r===o.fragment&&t.push(n),t}),[]),a=Wf(e.molecule,i);return n.action=n.action.mergeWith(Df(e,t.type,i,t.attrs)),n.selection.atoms=n.selection.atoms.concat(i),n.selection.bonds=n.selection.bonds.concat(a),n}),{action:new df,selection:{atoms:[],bonds:[]}})}function Vf(e,t,n){var o=wf(t,n);return o.length>0&&(o.forEach((function(t){e.addOp(new Hh(t,n))})),!0)}function Uf(e,t,n){var o=t.molecule,r=new Map;n.forEach((function(e){wf(t,e).forEach((function(e){r.set(e,r.has(e)?r.get(e)+1:1)}))})),r.forEach((function(n,r){var i=t.sgroups.get(r).item;if(ht.getAtoms(t.molecule,i).length===n){var a=o.sgroups.get(r);e.mergeWith(Ff(r,a.getAttrs())),e.addOp(new Xh(r)),a.getAttachmentPoints().forEach((function(t){e.addOp(new Nf(r,t))})),e.addOp(new Jh(r))}}))}function Wf(e,t){var n=new Re(t);return Array.from(e.bonds.keys()).filter((function(t){var o=e.bonds.get(t);return n.has(o.begin)&&n.has(o.end)}))}function qf(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Yf(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?qf(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):qf(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function $f(e,t,n,o,i,a){var s,u,l,c,d,h,f=new df,m=e.molecule,p="number"==typeof n,v="number"==typeof o;if(p||v)if(!p&&v){var g=function(t,n){var o=bf(e,n,"fragment"),r=f.addOp(new td(Yf(Yf({},t),{},{fragment:o}),i).perform(e)).data.aid,a=m.atoms.get(n);return a&&!gt.isAtomInContractedFunctionalGroup(a,m.sgroups,m.functionalGroups,!1)&&am(f,e,[r],n),[r,n]}(n,o),y=(0,r.A)(g,2);u=y[0],l=y[1]}else if(p&&!v){var b=function(o,r){var i=bf(e,o,"fragment"),s=f.addOp(new td(Yf(Yf({},r),{},{fragment:i}),null!=a?a:Sf(e,n,t).pos).perform(e)).data.aid,u=m.atoms.get(o);return u&&!gt.isAtomInContractedFunctionalGroup(u,m.sgroups,m.functionalGroups,!1)&&am(f,e,[s],o),[o,s]}(n,o),A=(0,r.A)(b,2);u=A[0],l=A[1]}else u=n,l=o;else{var w=(c=n,d=o,h=f.addOp((new Rd).perform(e)).frid,[f.addOp(new td(Yf(Yf({},c),{},{fragment:h}),i).perform(e)).data.aid,f.addOp(new td(Yf(Yf({},d),{},{fragment:h}),a).perform(e)).data.aid]),E=(0,r.A)(w,2);u=E[0],l=E[1]}"*"===bf(e,u,"label")&&f.addOp(new Xc(u,"label","C").perform(e)),"*"===bf(e,l,"label")&&f.addOp(new Xc(l,"label","C").perform(e));var P=f.addOp(new dd(u,l,t).perform(e)).data.bid,x=m.bonds.get(P);x&&(f.addOp(new Gd([x.begin,x.end]).perform(e)),f.mergeWith(Kf(e,x))),f.operations.reverse();var S=im(f,e,u,l);return null!==(s=m.frags.get(S||0))&&void 0!==s&&s.stereoAtoms&&!t.stereo&&f.addOp(new Fd(S||0).perform(e)),[f,u,l,P]}function Xf(e,t,n,o){var r=e.molecule,i=new df;return(Array.isArray(t)?t:[t]).forEach((function(t){Object.keys(We.attrlist).forEach((function(a){if(a in n||o){var s=a in n?n[a]:We.attrGetDefault(a);if(i.addOp(new id(t,a,s).perform(e)),"stereo"===a&&a in n){var u=r.bonds.get(t);u&&(i.addOp(new Gd([u.begin,u.end]).perform(e)),i.mergeWith(Kf(e,u)))}}}))})),i}function Kf(e,t,n){var o,r,i=new df,a=e.molecule,s=null===(o=a.atoms.get(null==t?void 0:t.begin))||void 0===o?void 0:o.fragment,u=null===(r=a.atoms.get(null==t?void 0:t.end))||void 0===r?void 0:r.fragment,l=[];return a.bonds.forEach((function(e){var t,n;(null===(t=a.atoms.get(e.begin))||void 0===t?void 0:t.fragment)===s&&l.push(e),s!==u&&(null===(n=a.atoms.get(e.begin))||void 0===n?void 0:n.fragment)===u&&l.push(e)})),Zf(a,l,t).forEach((function(t,o){var r;(null===(r=a.atoms.get(o))||void 0===r?void 0:r.stereoLabel)!==t.stereoLabel&&i.mergeWith(function(e,t,n,o){var r=new df,i=e.molecule.atoms.get(t);if(i){var a=i.fragment;"stereoParity"in n&&r.addOp(new Xc(t,"stereoParity",n.stereoParity).perform(e)),"stereoLabel"in n&&(r.addOp(new Xc(t,"stereoLabel",n.stereoLabel).perform(e)),null===n.stereoLabel?r.addOp(new Dd(a,t).perform(e)):r.addOp(new Nd(a,t).perform(e))),o&&r.operations.reverse()}return r}(e,o,t,n))})),i}function Zf(e,t,n){var o=new Map,r=[];return t.forEach((function(t){if(t){var n=e.atomGetNeighbors(t.begin),i=e.atomGetNeighbors(t.end);if(Qe.isCorrectStereoCenter(t,n,i,e)){var a,s,u=null===(a=e.atoms.get(t.begin))||void 0===a?void 0:a.stereoLabel;null!=u&&null!=(null===(s=o.get(t.begin))||void 0===s?void 0:s.stereoLabel)||o.set(t.begin,{stereoParity:Qf(t.stereo),stereoLabel:u||"".concat(ke.Abs)}),r.push(t.begin)}else r.includes(t.begin)||o.set(t.begin,{stereoParity:Fe.PATTERN.STEREO_PARITY.NONE,stereoLabel:null}),r.includes(t.end)||o.set(t.end,{stereoParity:Fe.PATTERN.STEREO_PARITY.NONE,stereoLabel:null})}})),n&&(r.includes(n.begin)||o.set(n.begin,{stereoParity:Fe.PATTERN.STEREO_PARITY.NONE,stereoLabel:null}),r.includes(n.end)||o.set(n.end,{stereoParity:Fe.PATTERN.STEREO_PARITY.NONE,stereoLabel:null})),o}function Qf(e){var t=null;switch(e){case We.PATTERN.STEREO.UP:t=Fe.PATTERN.STEREO_PARITY.ODD;break;case We.PATTERN.STEREO.EITHER:t=Fe.PATTERN.STEREO_PARITY.EITHER;break;case We.PATTERN.STEREO.DOWN:t=Fe.PATTERN.STEREO_PARITY.EVEN}return t}var Jf=[We.PATTERN.TYPE.SINGLE,We.PATTERN.TYPE.DOUBLE,We.PATTERN.TYPE.TRIPLE];function em(e,t,n,o){var r=new df,i=t;(o.stereo!==We.PATTERN.STEREO.NONE&&o.type===We.PATTERN.TYPE.SINGLE||n.type===We.PATTERN.TYPE.DATIVE)&&n.type===o.type&&n.stereo===o.stereo&&(r.mergeWith(function(e,t){var n=e.molecule.bonds.get(t),o=new df;return o.addOp(new hd(t).perform(e)),Number.isInteger(null==n?void 0:n.end)&&Number.isInteger(null==n?void 0:n.begin)&&o.addOp(new dd(null==n?void 0:n.end,null==n?void 0:n.begin,n).perform(e)),o}(e,t)),i=r.operations[1].data.bid);var a=Jf.includes(o.type)?Jf:null;return o.stereo===We.PATTERN.STEREO.NONE&&o.type===We.PATTERN.TYPE.SINGLE&&n.stereo===We.PATTERN.STEREO.NONE&&a&&(o.type=a[(a.indexOf(n.type)+1)%a.length]),Xf(e,i,o).mergeWith(r)}function tm(e,t,n){n=Object.assign({},n);var o=new df;n.fragment=o.addOp((new Rd).perform(e)).frid;var r=o.addOp(new td(n,t).perform(e)).data.aid;return o.addOp(new Gd([r]).perform(e)),o}function nm(e,t,n,o){var r=new df;return(Array.isArray(t)?t:[t]).forEach((function(t){var i;Object.keys(Fe.attrlist).forEach((function(i){if(("attachmentPoints"!==i||i in n)&&(i in n||o)){var a=i in n?n[i]:Fe.attrGetDefault(i);switch(i){case"stereoLabel":case"stereoParity":i in n&&a&&r.addOp(new Xc(t,i,a).perform(e));break;default:r.addOp(new Xc(t,i,a).perform(e))}}})),o||!("label"in n)||null===n.label||"L#"===n.label||"atomList"in n||r.addOp(new Xc(t,"atomList",null).perform(e)),r.addOp(new Gd([t]).perform(e));var a=e.molecule.atomGetNeighbors(t),s=e.molecule.bonds.get(null==a||null===(i=a[0])||void 0===i?void 0:i.bid);s&&r.mergeWith(Kf(e,s));var u=e.molecule.atoms.get(t);f()(null!=u),Fe.isInAromatizedRing(e.molecule,t)&&r.addOp(new Xc(t,"implicitHCount",u.implicitH).perform(e))})),r}function om(e,t,n){var o=new df;return t.forEach((function(t){var r=e.molecule.atoms.get(t),i=r.fragment;o.addOp(new Xc(t,"fragment",n)),null!==r.stereoLabel&&(o.addOp(new Nd(n,t)),o.addOp(new Dd(i,t)))})),o.perform(e)}function rm(e,t,n){var o,r;if(t===n)return new df;var i=new df;im(i,e,t,n);var a=new df,s=e.molecule.atomGetNeighbors(t);s.forEach((function(t){var o=e.molecule.bonds.get(t.bid);if(n!==o.begin&&n!==o.end){var r=o.begin===t.aid?t.aid:n,i=o.begin===t.aid?n:t.aid,s=e.molecule.findBondId(r,i);if(null===s)a.addOp(new dd(r,i,o));else{var u=We.getAttrHash(o);Object.keys(u).forEach((function(e){a.addOp(new id(s,e,u[e]))}))}a.addOp(new hd(t.bid))}else a.addOp(new hd(t.bid))}));var u=Fe.getAttrHash(e.molecule.atoms.get(t));1===Af(e,t)&&"*"===u.label&&(u.label="C"),Object.keys(u).forEach((function(e){"stereoLabel"!==e&&"stereoParity"!==e&&a.addOp(new Xc(n,e,u[e]))})),Vf(a,e,t)&&Uf(a,e,[t]),wf(e,t).forEach((function(n){for(var o=e.sgroups.get(n).item,r=0;r<o.attachmentPoints.length;++r)if(o.attachmentPoints[r].atomId===t)return void a.addOp(new Nf(n,new Qt(t,void 0,void 0)))})),a.addOp(new nd(t));var l=e.molecule.atomGetNeighbors(n),c=e.molecule.bonds.get((null===(o=l[0])||void 0===o?void 0:o.bid)||(null===(r=s[0])||void 0===r?void 0:r.bid));return a.perform(e).mergeWith(i).mergeWith(Kf(e,c))}function im(e,t,n,o){var r=bf(t,n,"fragment"),i=bf(t,o,"fragment");if(i===r||"number"!=typeof r||"number"!=typeof i)return r;var a=t.molecule,s=At.findRGroupByFragment(a.rgroups,i);void 0!==s&&e.mergeWith(Rf(t,null,i)).mergeWith(Tf(t,0,s));var u=a.getFragmentIds(r),l=[];a.atoms.forEach((function(e,t){e.fragment===i&&l.push(t)}));var c=om(t,l,r);return am(e,t,u,o),e.addOp(new Bd(i).perform(t)),e.mergeWith(c),r}function am(e,t,n,o){wf(t,o).forEach((function(o){var r=t.molecule.sgroups.get(o);"DAT"===r.type&&["Atom","Bond","Group"].includes(r.data.context)||(0,T.without)(r.atoms,n).forEach((function(n){return e.addOp(new Fh(o,n).perform(t))}))}))}function sm(e,t){var n=new df;return n.addOp(new pd(t)),n.perform(e)}function um(e){var t=new df;return t.addOp(new yd),t.perform(e)}function lm(e,t,n,o,r){var i=Math.cos(Math.PI/6),a=Math.sin(Math.PI/6),s=new df,u=null!==r?bf(e,r,"fragment"):s.addOp((new Rd).perform(e)).frid,l={atoms:[],bonds:[]},c=null!==r?r:s.addOp(new td({label:"C",fragment:u},t).perform(e)).data.aid;l.atoms.push(c),s.operations.reverse();for(var d=0;d<o;d++){var h=$f(e,{},c,{label:"C"},void 0,new we(i*(d+1),1&d?0:a).rotate(n).add(t));s=h[0].mergeWith(s),c=h[2],l.bonds.push(h[3]),l.atoms.push(c)}return[s,l]}function cm(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return dm(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?dm(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function dm(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function hm(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function fm(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?hm(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):hm(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function mm(e,t){var n=new df;if(!t)return n;var r=new Set,i=function(e,t,n){var r,i=new Set(t),a=new Set,s=cm(n);try{for(s.s();!(r=s.n()).done;){var u=r.value,l=e.bonds.get(u);if(l){var c=l.b,d=c.begin,h=c.end;i.add(d).add(h)}}}catch(e){s.e(e)}finally{s.f()}var f,m=cm(i);try{var p=function(){var t=f.value;if(a.has(t))return 1;var n=(0,o.A)(e.connectedComponents.values()).find((function(e){return e.has(t)}));n&&n.forEach((function(e){return a.add(e)}))};for(m.s();!(f=m.n()).done;)p()}catch(e){m.e(e)}finally{m.f()}return a}(e,gm(t.atoms),gm(t.bonds));return t.atoms.forEach((function(t,o){r.has(t)||r.has(o)||(n=rm(e,o,t).mergeWith(n),r.add(t).add(o))})),n=function(e,t){var n=e.molecule,o=new Map,r=new df;return t.forEach((function(e,t){var r=n.bonds.get(t),i=n.bonds.get(e);if(r&&i){var a=Ua.mergeBondsParams(n,r,n,i);a.merged&&(o.set(r.begin,a.cross?i.end:i.begin),o.set(r.end,a.cross?i.begin:i.end))}})),o.forEach((function(t,n){r=rm(e,n,t).mergeWith(r)})),r}(e,t.bonds).mergeWith(n),n=function(e,t){var n=new df;if(!t)return n;var o=new Set;return t.forEach((function(t){o.has(t)||(n=function(e,t){var n=new df;return e.atoms.has(t)?(n.addOp(new Gd([t])),n.perform(e)):n}(e,t).mergeWith(n),o.add(t))})),n}(e,i).mergeWith(n),n}function pm(e,t){var n=e.render.ctab.molecule,o=t||{atoms:Array.from(n.atoms.keys()),bonds:Array.from(n.bonds.keys())};return function(e,t){var n={atoms:new Map(t.atoms),bonds:new Map(t.bonds),atomToFunctionalGroup:new Map(t.atomToFunctionalGroup)};return t.bonds.forEach((function(t,o){var r=e.bonds.get(o),i=e.bonds.get(t);Ua.mergeBondsParams(e,r,e,i).merged?(n.atoms.delete(r.begin),n.atoms.delete(r.end)):n.bonds.delete(o)})),0===n.atoms.size&&0===n.bonds.size&&0===n.atomToFunctionalGroup.size?null:n}(n,e.findMerge(o,["atoms","bonds"]))}function vm(e){if(!e)return null;var t=fm(fm({atoms:Array.from(e.atoms.values()),bonds:Array.from(e.bonds.values())},e.functionalGroups&&{functionalGroups:Array.from(e.functionalGroups.values())}),e.atomToFunctionalGroup&&{sgroups:Array.from(e.atomToFunctionalGroup.values())});return{map:"merge",id:+Date.now(),items:t}}function gm(e){var t=new Set;return e.forEach((function(e,n){t.add(e).add(n)})),t}function ym(e,t,n){n=new we(n);var o=new df,r=e.molecule,i=new Re,a=new Re;if(t.atoms){var s=new Re(t.atoms),u=[];e.bonds.forEach((function(e,t){if(s.has(e.b.begin)&&s.has(e.b.end))return u.push(t),void["hb1","hb2"].forEach((function(t){var n=r.halfBonds.get(e.b[t]).loop;n>=0&&i.add(n)}));s.has(e.b.begin)?a.add(e.b.begin):s.has(e.b.end)&&a.add(e.b.end)})),u.forEach((function(e){o.addOp(new ud(e,n))})),i.forEach((function(t){e.reloops.get(t)&&e.reloops.get(t).visel&&o.addOp(new Ud(t,n))})),t.atoms.forEach((function(e){o.addOp(new Qc(e,n,!a.has(e)))})),t.sgroupData&&0===t.sgroupData.length&&Of(r,t.atoms).forEach((function(e){o.addOp(new Wh(e.id,n))}))}return t.rxnArrows&&t.rxnArrows.forEach((function(e){o.addOp(new uh(e,n,!0))})),t.rxnPluses&&t.rxnPluses.forEach((function(e){o.addOp(new bh(e,n,!0))})),t.simpleObjects&&t.simpleObjects.forEach((function(e){o.addOp(new Ch(e,n,!0))})),t.sgroupData&&t.sgroupData.forEach((function(e){o.addOp(new Wh(e,n))})),t.enhancedFlags&&t.enhancedFlags.forEach((function(e){o.addOp(new Ed(e,n))})),t.texts&&t.texts.forEach((function(e){o.addOp(new cf(e,n,!0))})),o.perform(e)}function bm(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,o=new df;if(!n){var r=e.molecule;e.molecule.frags.get(t).stereoAtoms.forEach((function(e){null===r.atoms.get(e).stereoLabel&&o.addOp(new Dd(t,e))}))}return o.addOp(new Fd(t)),o.perform(e)}function Am(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=new df,r=At.findRGroupByFragment(e.molecule.rgroups,t);return e.molecule.atoms.forEach((function(n,i){if(n.fragment===t){var a=o.addOp((new Rd).perform(e)).frid;o.mergeWith(function(e,t,n,o){for(var r=[t],i=new Re(r);r.length>0;){var a=r.shift();e.molecule.atomGetNeighbors(a).forEach((function(t){e.molecule.atoms.get(t.aid).fragment!==n||i.has(t.aid)||(i.add(t.aid),r.push(t.aid))}))}return om(e,i,o)}(e,i,t,a)),r&&o.mergeWith(Rf(e,r,a))}})),-1!==t&&(o.mergeWith(Rf(e,0,t)),o.addOp(new Bd(t).perform(e)),o.mergeWith(Tf(e,0,r,n))),o.operations.reverse(),o}function wm(e,t,n){var o=new df;return o.mergeWith(function(e,t){var n=new df;return e.molecule.getRGroupAttachmentPointsByAtomId(t).forEach((function(e){n.addOp(new ih(e))})),n.perform(e)}(e,t)),o.mergeWith(Em(e,n,t)),o}function Em(e,t,n){var o=new df;switch(t){case Oe.FirstSideOnly:o.addOp(new Jd({atomId:n,attachmentPointType:"primary"}));break;case Oe.SecondSideOnly:o.addOp(new Jd({atomId:n,attachmentPointType:"secondary"}));break;case Oe.BothSides:o.addOp(new Jd({atomId:n,attachmentPointType:"primary"})),o.addOp(new Jd({atomId:n,attachmentPointType:"secondary"}))}return o.perform(e)}function Pm(e,t){var n=function(e,t){var n=e.rgroupAttachmentPoints.get(t);f()(null!=n);var o=n.atomId,r=e.atoms.get(o),i=null==r?void 0:r.attachmentPoints,a=Oe.None;if(i===Oe.BothSides){var s=n.type;"primary"===s?a=Oe.SecondSideOnly:"secondary"===s&&(a=Oe.FirstSideOnly)}return{atomId:o,newAttachmentPoints:a}}(e.molecule,t),o=nm(e,n.atomId,{attachmentPoints:n.newAttachmentPoints},null),r=new df;return r.addOp(new ih(t)),r.perform(e).mergeWith(o)}function xm(e,t){return km(e,{atoms:[t]})}function Sm(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=new df,r=e.molecule.bonds.get(t),i=[];return o.addOp(new hd(t)),n.includes(r.begin)||0!==Af(e,r.begin)||(Vf(o,e,r.begin)&&i.push(r.begin),o.addOp(new nd(r.begin))),n.includes(r.end)||0!==Af(e,r.end)||(Vf(o,e,r.end)&&i.push(r.end),o.addOp(new nd(r.end))),Uf(o,e,i),(o=o.perform(e)).addOp(new Gd([r.begin,r.end]).perform(e)),o.mergeWith(Kf(e,r,!1)),o.operations.reverse(),o}function Om(e,t){var n=e.molecule.getBondFragment(t),o=Sm(e,t);return Am(e,n).mergeWith(o)}function km(e,t){f()(null!=!!t);var n=new df,o=[],r=[],i=function(e){return st.reduce((function(t,n){return t[n]=e[n]||[],t}),{})}(t);i.sgroups.forEach((function(t){var n=e.sgroups.get(t).item.atoms;i.atoms=i.atoms.concat(n),e.molecule.bonds.forEach((function(e,t){n.indexOf(e.begin)>=0&&n.indexOf(e.end)>=0&&i.bonds.push(t)}))})),i.atoms=Array.from(new Set(i.atoms)),i.bonds=Array.from(new Set(i.bonds)),i.atoms.forEach((function(t){e.molecule.atomGetNeighbors(t).forEach((function(e){-1===i.bonds.indexOf(e.bid)&&(i.bonds=i.bonds.concat([e.bid]))}))}));var a=new df;i.bonds.forEach((function(t){var n=e.molecule.getBondFragment(t);r.indexOf(n)<0&&r.push(n),a.mergeWith(Sm(e,t,i.atoms))}));var s=[];i.atoms.forEach((function(t){var i=e.molecule.atoms.get(t).fragment;r.indexOf(i)<0&&r.push(i),Vf(n,e,t)&&o.push(t),n.addOp(new nd(t)),e.molecule.getRGroupAttachmentPointsByAtomId(t).forEach((function(e){n.addOp(new ih(e)),s.push(e)}))})),Uf(n,e,o),i.rxnArrows.forEach((function(e){n.addOp(new kh(e))})),i.rxnPluses.forEach((function(e){n.addOp(new Ph(e))})),i.simpleObjects.forEach((function(e){n.addOp(new Bh(e))})),i.texts.forEach((function(e){n.addOp(new of(e))}));var u=new df;i.rgroupAttachmentPoints.forEach((function(t){s.includes(t)||u.mergeWith(Pm(e,t))})),(n=n.perform(e)).mergeWith(a).mergeWith(u);for(var l=r.map((function(t){return At.findRGroupByFragment(e.molecule.rgroups,t)}));r.length>0;)n=Am(e,r.pop(),l).mergeWith(n);return n}function Mm(e,t,n){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,r=arguments.length>4&&void 0!==arguments[4]&&arguments[4],i=function(e){if(1===e.sgroups.size){var t=e.sgroups.keys().next().value,n=e.sgroups.get(t);if(n.isContracted())return n.getContractedPosition(e).position}if(e.atoms.size>0){var o=1e50,r=o,i=-o,a=-r;return e.atoms.forEach((function(e){o=Math.min(o,e.pp.x),r=Math.min(r,e.pp.y),i=Math.max(i,e.pp.x),a=Math.max(a,e.pp.y)})),new we((o+i)/2,(r+a)/2)}return e.rxnArrows.size>0?e.rxnArrows.get(0).center():e.rxnPluses.size>0?e.rxnPluses.get(0).pp:e.simpleObjects.size>0?e.simpleObjects.get(0).center():e.texts.size>0?e.texts.get(0).position:new we(0,0)}(t),a=we.diff(n,i),s=new df,u=new Map,l=new Map,c={atoms:[],bonds:[]};return t.atoms.forEach((function(r,a){l.has(r.fragment)||t.isAtomFromMacromolecule(a)||l.set(r.fragment,s.addOp(new Rd(null,r.fragment.properties).perform(e)).frid);var d=Object.assign(r.clone(),{fragment:l.get(r.fragment)}),h=new td(d,we.diff(r.pp,i).rotate(o).add(n)).perform(e);s.addOp(h),u.set(a,h.data.aid),c.atoms.push(h.data.aid),s.mergeWith(Em(e,d.attachmentPoints,h.data.aid))})),t.frags.forEach((function(t,n){t&&(t.properties&&s.addOp(new Td(l.get(n),t.properties).perform(e)),t.stereoAtoms.forEach((function(t){return s.addOp(new Nd(l.get(n),u.get(t)).perform(e))})))})),t.bonds.forEach((function(t){var n=new dd(u.get(t.begin),u.get(t.end),t,!1).perform(e);s.addOp(n),c.bonds.push(n.data.bid),new id(n.data.bid,"isPreview",r,!1).perform(e)})),c.atoms.forEach((function(t){s.addOp(new Gd([t]).perform(e)),new Xc(t,"isPreview",r).perform(e)})),t.sgroups.forEach((function(n){var o=e.molecule.sgroups.newId(),r=n.atoms.map((function(e){return u.get(e)})),i=n.cloneAttachmentPoints(u);!n.isNotContractible(t)||n instanceof Ut||n.setAttr("expanded",!0),jf(e,n.type,r,n.data,o,i,n.pp?n.pp.add(a):null,"SUP"===n.type?n.isExpanded():null,n.data.name,n).operations.reverse().forEach((function(e){s.addOp(e)}))})),t.rxnArrows.forEach((function(t){s.addOp(new Oh(t.pos.map((function(e){return e.add(a)})),t.mode).perform(e))})),t.rxnPluses.forEach((function(t){s.addOp(new Eh(t.pp.add(a)).perform(e))})),t.simpleObjects.forEach((function(t){s.addOp(new Th(t.pos.map((function(e){return e.add(a)})),t.mode).perform(e))})),t.texts.forEach((function(t){s.addOp(new nf(t.content,t.position.add(a),t.pos.map((function(e){return e.add(a)}))).perform(e))})),t.rgroups.forEach((function(n,o){n.frags.forEach((function(t,n){s.addOp(new Kd(o,l.get(n)).perform(e))}));var r=t.rgroups.get(o).ifthen,i=t.rgroups.get(r)?r:0;s.mergeWith(Mf(e,o,n.getAttrs())).mergeWith(Tf(e,i,n.ifthen))})),s.operations.reverse(),[s,c]}function Rm(e,t,n){var o=new df;return o.addOp(new Oh(t,n)),o.perform(e)}function Tm(e,t,n,o,r,i){var a=new df;return a.addOp(new ph(t,n,o,r,!1,i)),a.perform(e)}function Bm(e,t){var n=new df;return n.addOp(new kh(t)),n.perform(e)}function Cm(e,t){var n=new df;return n.addOp(new Eh(t).perform(e)),n}function Im(e,t){var n=new df;return n.addOp(new Ph(t)),n.perform(e)}function Nm(e,t,n,o){var i=new df,a=t||xf(e.molecule);return i.mergeWith(function(e,t,n,o){var r,i=e.molecule,a=new df;return null==t||null===(r=t.atoms)||void 0===r||r.forEach((function(e){var t=i.atoms.get(e);if(t){var r=Dm(t.pp,o,n);a.addOp(new Qc(e,r))}})),Of(i,(null==t?void 0:t.atoms)||[]).forEach((function(e){if(e.pp){var t=Dm(e.pp,o,n);a.addOp(new Wh(e.id,t))}})),null!=t&&t.bonds&&function(e,t,n){e.forEach((function(e){var o=t.bonds.get(e);o&&o.type===We.PATTERN.TYPE.SINGLE&&(o.stereo!==We.PATTERN.STEREO.UP?o.stereo===We.PATTERN.STEREO.DOWN&&n.addOp(new id(e,"stereo",We.PATTERN.STEREO.UP)):n.addOp(new id(e,"stereo",We.PATTERN.STEREO.DOWN)))}))}(t.bonds,i,a),a.perform(e)}(e,a,n,o)),a.rxnArrows&&i.mergeWith(function(e,t,n,o){var i=new df;return t.forEach((function(t){var a=e.molecule.rxnArrows.get(t);if(a){var s=(0,r.A)(a.pos,2),u=s[0],l=s[1].sub(u).oxAngle(),c=l-Math.PI/2,d="vertical"===n?-2*l:-2*c;i.addOp(new dh(t,d,a.center()));var h=Dm(a.center(),o,n);i.addOp(new uh(t,h))}})),i.perform(e)}(e,a.rxnArrows,n,o)),a.rxnPluses&&i.mergeWith(function(e,t,n,o){var r=new df;return t.forEach((function(t){var i=e.molecule.rxnPluses.get(t);if(i){var a=Dm(i.pp,o,n);r.addOp(new bh(t,a))}})),r.perform(e)}(e,a.rxnPluses,n,o)),a.texts&&i.mergeWith(function(e,t,n,o){var r=new df;return t.forEach((function(t){var i=e.molecule.texts.get(t);if(i){var a=i.pos[0],s=i.pos[2],u=Dm(we.centre(a,s),o,n);r.addOp(new cf(t,u))}})),r.perform(e)}(e,a.texts,n,o)),i}function Dm(e,t,n){var o=new we;return"horizontal"===n?o.x=t.x>e.x?2*(t.x-e.x):-2*(e.x-t.x):o.y=t.y>e.y?2*(t.y-e.y):-2*(e.y-t.y),o}function Lm(e,t,n,o){var r=e.molecule,i=new df;return t||(t=xf(r)),t.atoms&&(t.atoms.forEach((function(e){var t=r.atoms.get(e);i.addOp(new Qc(e,_m(t.pp,n,o)))})),t.sgroupData||Of(r,t.atoms).forEach((function(e){i.addOp(new Wh(e.id,_m(e.pp,n,o)))}))),t.rxnArrows&&t.rxnArrows.forEach((function(e){i.addOp(new dh(e,o,n))})),t.rxnPluses&&t.rxnPluses.forEach((function(e){var t=r.rxnPluses.get(e);i.addOp(new bh(e,_m(t.pp,n,o)))})),t.texts&&t.texts.forEach((function(e){var t=r.texts.get(e);i.addOp(new cf(e,_m(t.position,n,o)))})),t.sgroupData&&t.sgroupData.forEach((function(e){var t=r.sgroups.get(e);i.addOp(new Wh(e,_m(t.pp,n,o)))})),t.enhancedFlags&&t.enhancedFlags.forEach((function(t){var r=t,a=e.molecule.frags.get(r);i.addOp(new Ed(t,_m(a.stereoFlagPosition||Ke.getDefaultStereoFlagPosition(e.molecule,r),n,o)))})),i.perform(e)}function _m(e,t,n){var o=e.sub(t);return(o=o.rotate(n)).add_(t),o.sub(e)}function Fm(e,t){var n=new df;return n.addOp(new Bh(t)),n.perform(e)}function Hm(e,t,n,o){var r=new df;return r.addOp(new Th(t,n,o)),r.perform(e)}function jm(e,t,n,o,r,i){var a=new df;return a.addOp(new Nh(t,n,o,r,!1,i)),a.perform(e)}function Gm(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function zm(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Gm(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Gm(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var Vm="Benzene",Um="Cyclopentadiene",Wm=[2,4];function qm(e,t,n){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,i=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=Mm(e,t.molecule,n,o,i),s=(0,r.A)(a,2),u=s[0],l=s[1];return u.addOp(new Gd(l.atoms).perform(e)),[u,l]}function Ym(e,t,n,r,i){var a=arguments.length>5&&void 0!==arguments[5]&&arguments[5],s=new df,u=t.molecule,l=e.molecule,c=t.molecule.isSingleGroup(),d=l.atoms.get(n),h=n,f=null;if(i){var m=function(e,t,n){var o=new df,r=bf(e,t,"fragment"),i=null;if(null===n){var a=Sf(e,t),s=$f(e,{type:1},t,a.atom,void 0,a.pos.get_xy0());(o=s[0]).operations.reverse(),i=s[2]}else{var u=new td({label:"C",fragment:r},new we(1,0).rotate(n).add(e.molecule.atoms.get(t).pp).get_xy0()).perform(e);o.addOp(u),o.addOp(new dd(t,u.data.aid,{type:1}).perform(e)),i=u.data.aid}return{action:o,aid1:i}}(e,n,r);s=m.action,h=m.aid1,d=l.atoms.get(h),f=Ua.calcAngle(l.atoms.get(n).pp,d.pp)-t.angle0}else null===r&&(r=Ua.calcAngle(d.pp,Sf(e,n).pos)),f=r-t.angle0;var p=new Map,v=u.atoms.get(t.aid).pp,g=bf(e,n,"fragment"),y={atoms:[],bonds:[]};return u.atoms.forEach((function(n,o){var r=Fe.getAttrHash(n);if(r.fragment=g,o===t.aid)s.mergeWith(nm(e,h,r,!0)),p.set(o,h),y.atoms.push(h);else{var i=we.diff(n.pp,v).rotate(f).add(d.pp),a=new td(r,i.get_xy0()).perform(e);s.addOp(a),p.set(o,a.data.aid),y.atoms.push(a.data.aid)}})),c||am(s,e,y.atoms,n),u.bonds.forEach((function(t){var n=new dd(p.get(t.begin),p.get(t.end),t).perform(e);s.addOp(n),new id(n.data.bid,"isPreview",a).perform(e),y.bonds.push(n.data.bid)})),u.sgroups.forEach((function(t){var n=e.molecule.sgroups.newId(),o=t.atoms.map((function(e){return p.get(e)})),r=t.cloneAttachmentPoints(p);jf(e,t.type,o,zm(zm({},t.data),{},{expanded:!!a||t.data.expanded}),n,r,d.pp,"SUP"===t.type?t.isExpanded():null,t.data.name).operations.reverse().forEach((function(e){s.addOp(e)}))})),s.operations.reverse(),s.addOp(new Gd([].concat((0,o.A)(y.atoms),[n])).perform(e)),s.mergeWith(Kf(e,e.molecule.bonds.get(y.bonds[0]))),[s,y]}function $m(e,t,n,o,r,i){var a=arguments.length>6&&void 0!==arguments[6]&&arguments[6];return i?function(e,t,n,o,i){var s=function(e,t,n){return Xm(e,t,n,r,a)}(e,t,n);return Promise.resolve(s)}(e,t,n):Xm(e,t,n,r)}function Xm(e,t,n,r){var i=arguments.length>4&&void 0!==arguments[4]&&arguments[4],a=new df,s=t.molecule,u=e.molecule,l=u.bonds.get(n),c=s.bonds.get(t.bid),d=s.atoms.get(r?c.end:c.begin),h=new Map([[c.begin,r?l.end:l.begin],[c.end,r?l.begin:l.end]]),f={begin:r?c.end:c.begin,end:r?c.begin:c.end},m=Ua.mergeBondsParams(u,l,s,f),p=m.angle,v=m.scale,g=u.getBondFragment(n),y={atoms:[],bonds:[]};s.atoms.forEach((function(t,n){var o=Fe.getAttrHash(t);if(o.fragment=g,n!==c.begin&&n!==c.end){var r=we.diff(t.pp,d.pp).rotate(p).scaled(v).add(u.atoms.get(l.begin).pp),i=yf.atom(e,r,null,.1);if(null===i){var s=new td(o,r).perform(e);a.addOp(s),h.set(n,s.data.aid),y.atoms.push(s.data.aid)}else h.set(n,i.id),a.mergeWith(nm(e,h.get(n),o,!0))}else a.mergeWith(nm(e,h.get(n),o,!0))})),am(a,e,y.atoms,l.begin);var b=function(e,t,n,o){var r=e.name===Vm,i=e.name===Um;if(e.bonds.size&&(r||i)){var a=We.getBondNeighbourIds(t,n),s=a.beginBondIds,u=a.endBondIds;if(1!==s.length||1!==u.length)return null;var l=t.bonds.get(s[0]),c=t.bonds.get(u[0]);if(!l||!c)throw new Error("Incorrect bond id was provided");if(r)return We.getBenzeneConnectingBondType(o,l,c);if(i)return We.getCyclopentadieneFusingBondType(o,l,c)}return null}(s,u,n,l),A=null!==b;return s.bonds.forEach((function(t,o){var r=u.findBondId(h.get(t.begin),h.get(t.end)),d=null;if(null===r){var f=new dd(h.get(t.begin),h.get(t.end),t).perform(e);a.addOp(f);var m=f.data.bid;if(d=m,A){var p=s.name===Vm,v=s.name===Um;if(p){var g=Wm.includes(o)?We.PATTERN.TYPE.DOUBLE:We.PATTERN.TYPE.SINGLE;a.addOp(new id(m,"type",g).perform(e))}if(v){var w=We.getBondNeighbourIds(u,n),E=w.beginBondIds,P=w.endBondIds,x=u.bonds.get(E[0]),S=u.bonds.get(P[0]),O=We.getCyclopentadieneDoubleBondIndexes(l,x,S).includes(o)?We.PATTERN.TYPE.DOUBLE:We.PATTERN.TYPE.SINGLE;a.addOp(new id(m,"type",O).perform(e))}}y.bonds.push(m)}else{var k=l.type>c.type?l:c;a.mergeWith(Xf(e,r,k,!0)),A&&b&&a.addOp(new id(n,"type",b).perform(e)),d=n}a.addOp(new id(d,"isPreview",i).perform(e))})),y.atoms.length&&a.addOp(new Gd([l.begin,l.end].concat((0,o.A)(y.atoms))).perform(e)),y.bonds.length&&a.mergeWith(Kf(e,e.molecule.bonds.get(y.bonds[0]))),a.operations.reverse(),[a,y]}function Km(e,t,n,o){var r=new df;return r.addOp(new nf(t,n,o)),r.perform(e)}function Zm(e,t,n){var o=new df;return o.addOp(new sf(t,n)),o.perform(e)}function Qm(e,t){var n=new df;return n.addOp(new of(t)),n.perform(e)}function Jm(e,t,n){return t=(0,u.A)(t),(0,s.A)(e,ep()?Reflect.construct(t,n||[],(0,u.A)(e).constructor):t.apply(e,n))}function ep(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(ep=function(){return!!e})()}var tp=function(e){function t(e,n,o,r){var a;return(0,i.A)(this,t),(a=Jm(this,t,[qc.ADD_HIGHLIGHT])).data={atoms:e,bonds:n,color:o,highlightId:r},a}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.data,n=t.atoms,o=t.bonds,r=t.color;if(r){var i=e.molecule,a=new Zt({atoms:n,bonds:o,color:r});"number"!=typeof this.data.highlightId?this.data.highlightId=i.highlights.add(a):i.highlights.set(this.data.highlightId,a),op(e,n,o)}}},{key:"invert",value:function(){var e=this.data,t=e.atoms,n=e.bonds,o=e.color,r=e.highlightId;return new np(r,t,n,o)}}]),t}(Wc),np=function(e){function t(e,n,o,r){var a;return(0,i.A)(this,t),(a=Jm(this,t,[qc.REMOVE_HIGHLIGHT,5])).data={highlightId:e,atoms:n||[],bonds:o||[],color:r||"white"},a}return(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){if("number"==typeof this.data.highlightId){var t=e.molecule,n=t.highlights.get(this.data.highlightId);if(void 0===n)return;var o=n.atoms,r=n.bonds,i=n.color;this.data.atoms=o,this.data.bonds=r,this.data.color=i,t.highlights.delete(this.data.highlightId),op(e,o,r)}}},{key:"invert",value:function(){var e=this.data,t=e.atoms,n=e.bonds,o=e.color,r=e.highlightId,i=new tp(t,n,o,r);return i.data=this.data,i}}]),t}(Wc);function op(e,t,n){var o=e.atoms,r=e.bonds;t&&t.forEach((function(t){void 0!==o.get(t)&&e.markAtom(t,1)})),n&&n.forEach((function(t){void 0!==r.get(t)&&e.markBond(t,1)}))}function rp(e,t){var n=new df;return t.forEach((function(e){var t=e.atoms,o=e.bonds,r=e.color;n.addOp(new tp(t,o,r))})),n.perform(e)}function ip(e){var t=new df;return e.molecule.highlights.forEach((function(e,n){t.addOp(new np(n))})),t.perform(e)}!function(e){function t(e,n,o,r){var a;return(0,i.A)(this,t),(a=Jm(this,t,[qc.UPDATE_HIGHLIGHT])).newData={atoms:n,bonds:o,color:r,highlightId:e},a.oldData={atoms:n,bonds:o,color:r,highlightId:e},a}(0,c.A)(t,e),(0,a.A)(t,[{key:"execute",value:function(e){var t=this.newData,n=t.atoms,r=t.bonds,i=t.color;if(i){var a=this.newData.highlightId,s=e.molecule,u=s.highlights.get(a);if(u){var l=u.atoms,c=u.bonds,d=u.color;this.oldData={atoms:l,bonds:c,color:d,highlightId:a};var h=new Zt({atoms:n,bonds:r,color:i});s.highlights.set(this.newData.highlightId,h),op(e,[].concat((0,o.A)(n),(0,o.A)(l)),[].concat((0,o.A)(r),(0,o.A)(c)))}}}},{key:"invert",value:function(){var e=this.oldData,n=e.atoms,o=e.bonds,r=e.color;return new t(this.newData.highlightId,n,o,r)}}])}(Wc);var ap,sp={fracAngle:Ua.fracAngle,calcAngle:Ua.calcAngle,degrees:Ua.degrees,calcNewAtomPos:Ua.calcNewAtomPos};function up(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function lp(e,t,n,o,r){var i=t;n&&"GET"===e&&(i=function(e,t){return e.replace(/:(\w+)/g,(function(e,n){return t[n]}))}(t,n));var a=fetch(i,{method:e,headers:Object.assign({Accept:"application/json"},o),body:"GET"!==e?n:void 0,credentials:"same-origin"});return r?r(a):a.then((function(e){return e.json().then((function(t){return e.ok?t:Promise.reject(t.error)}))}))}function cp(e,t,n,o,r){return function(i,a,s){var u=Object.assign({},i);return u.options=Object.assign(u.options||{},o,a),lp(e,n+t,JSON.stringify(u),function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?up(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):up(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({"Content-Type":"application/json"},r),s)}}!function(e){e.OFF="none",e.HETERO="hetero",e.TERMINAL_HETERO="terminal-hetero",e.ALL="all"}(ap||(ap={}));var dp=function(){function e(t,n,o){(0,i.A)(this,e),this.apiPath=t,this.defaultOptions=n,this.customHeaders=o}var t;return(0,a.A)(e,[{key:"getInChIKey",value:function(e){return cp("POST","indigo/convert",this.apiPath,this.defaultOptions,this.customHeaders)({struct:e,output_format:"chemical/x-inchi"},{})}},{key:"info",value:(t=(0,m.A)(v().mark((function e(){var t,n,o,r;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=!1,e.prev=1,e.next=4,lp("GET",this.apiPath+"info");case 4:r=e.sent,t=r.indigo_version,n=r.imago_versions,o=!0,e.next=16;break;case 10:e.prev=10,e.t0=e.catch(1),q.error("remoteStructService.ts::RemoteStructService::info",e.t0),t="",n=[],o=!1;case 16:return e.abrupt("return",{indigoVersion:t,imagoVersions:n,isAvailable:o});case 17:case"end":return e.stop()}}),e,this,[[1,10]])}))),function(){return t.apply(this,arguments)})},{key:"convert",value:function(e,t){return cp("POST","indigo/convert",this.apiPath,this.defaultOptions,this.customHeaders)(e,t)}},{key:"layout",value:function(e,t){return cp("POST","indigo/layout",this.apiPath,this.defaultOptions,this.customHeaders)(e,t)}},{key:"clean",value:function(e,t){return cp("POST","indigo/clean",this.apiPath,this.defaultOptions,this.customHeaders)(e,t)}},{key:"aromatize",value:function(e,t){return cp("POST","indigo/aromatize",this.apiPath,this.defaultOptions,this.customHeaders)(e,t)}},{key:"dearomatize",value:function(e,t){return cp("POST","indigo/dearomatize",this.apiPath,this.defaultOptions,this.customHeaders)(e,t)}},{key:"calculateCip",value:function(e,t){return cp("POST","indigo/calculate_cip",this.apiPath,this.defaultOptions,this.customHeaders)(e,t)}},{key:"automap",value:function(e,t){return cp("POST","indigo/automap",this.apiPath,this.defaultOptions,this.customHeaders)(e,t)}},{key:"check",value:function(e,t){return cp("POST","indigo/check",this.apiPath,this.defaultOptions,this.customHeaders)(e,t)}},{key:"calculate",value:function(e,t){return cp("POST","indigo/calculate",this.apiPath,this.defaultOptions,this.customHeaders)(e,t)}},{key:"recognize",value:function(e,t){var n=t?"?version=".concat(t):"",o=lp("POST",this.apiPath+"imago/uploads".concat(n),e,{"Content-Type":e.type||"application/octet-stream"}),r=lp.bind(null,"GET",this.apiPath+"imago/uploads/:id");return o.then((function(e){return t=r.bind(null,{id:e.upload_id}),n=function(e){if("FAILURE"===e.state)throw e;return"SUCCESS"===e.state},500,300,new Promise((function(e,o){setTimeout((function r(){t().then((function(t){try{n(t)?e(t):setTimeout(r,500)}catch(e){q.error("remoteStructService.ts::pollDeferred",e),o(e)}}),(function(e){return o(e)}))}),300)}));var t,n})).then((function(e){return{struct:e.metadata.mol_str}}))}},{key:"generateImageAsBase64",value:function(e,t){var n=(null==t?void 0:t.outputFormat)||"png",o=(null==t?void 0:t.bondThickness)||ut;return cp("POST","indigo/render",this.apiPath,this.defaultOptions,this.customHeaders)({struct:e},{"render-output-format":n,"render-bond-line-width":o,"render-label-mode":(0,d.A)((0,d.A)((0,d.A)((0,d.A)((0,d.A)({},hi.Off,ap.HETERO),hi.Hetero,ap.HETERO),hi.Terminal,ap.TERMINAL_HETERO),hi.TerminalAndHetero,ap.TERMINAL_HETERO),hi.On,ap.ALL)[Pc.getKetcher().editor.options().showHydrogenLabels]||ap.OFF},(function(e){return e.then((function(e){return e.text()}))}))}},{key:"toggleExplicitHydrogens",value:function(e,t){return cp("POST","indigo/convert_explicit_hydrogens",this.apiPath,this.defaultOptions,this.customHeaders)(e,t)}}]),e}(),hp=function(){function e(t,n){(0,i.A)(this,e),(0,d.A)(this,"mode","remote");var o=t;this.customHeaders=n;var r=new URLSearchParams(document.location.search);r.has("api_path")&&(o=r.get("api_path")),this.apiPath=!o||/\/$/.test(o)?o:o+"/"}return(0,a.A)(e,[{key:"createStructService",value:function(e){return new dp(this.apiPath,e,this.customHeaders)}}]),e}();function fp(e,t,n){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.set(e,n)}var mp=["radicals","pseudoatoms","stereo","query","overlapping_atoms","overlapping_bonds","rgroups","chiral","3d"],pp=["molecular-weight","most-abundant-mass","monoisotopic-mass","gross","mass-composition"];function vp(e,t){if("string"!=typeof e){var n=new Map,o=e.clone(null,null,!1,n);return t.serialize(o)}return e}var gp,yp=new WeakMap,bp=new WeakMap,Ap=function(){function e(t){(0,i.A)(this,e),fp(this,yp,{writable:!0,value:void 0}),fp(this,bp,{writable:!0,value:void 0}),(0,A.A)(this,yp,t),(0,A.A)(this,bp,new Vu)}return(0,a.A)(e,[{key:"info",value:function(){return(0,w.A)(this,yp).info()}},{key:"convert",value:function(e,t){var n=(null==t?void 0:t.outputFormat)||Us.KET;return(0,w.A)(this,yp).convert({struct:vp(e,(0,w.A)(this,bp)),output_format:n})}},{key:"layout",value:function(e){var t=this;return(0,w.A)(this,yp).layout({struct:vp(e,(0,w.A)(this,bp)),output_format:Us.KET}).then((function(e){return(0,w.A)(t,bp).deserialize(e.struct)}))}},{key:"clean",value:function(e){var t=this;return(0,w.A)(this,yp).clean({struct:vp(e,(0,w.A)(this,bp)),output_format:Us.KET}).then((function(e){return(0,w.A)(t,bp).deserialize(e.struct)}))}},{key:"aromatize",value:function(e){var t=this;return(0,w.A)(this,yp).aromatize({struct:vp(e,(0,w.A)(this,bp)),output_format:Us.KET}).then((function(e){return(0,w.A)(t,bp).deserialize(e.struct)}))}},{key:"dearomatize",value:function(e){var t=this;return(0,w.A)(this,yp).dearomatize({struct:vp(e,(0,w.A)(this,bp)),output_format:Us.KET}).then((function(e){return(0,w.A)(t,bp).deserialize(e.struct)}))}},{key:"calculateCip",value:function(e){var t=this;return(0,w.A)(this,yp).calculateCip({struct:vp(e,(0,w.A)(this,bp)),output_format:Us.KET}).then((function(e){return(0,w.A)(t,bp).deserialize(e.struct)}))}},{key:"automap",value:function(e,t){var n=this,o=(null==t?void 0:t.mode)||"discard";return(0,w.A)(this,yp).automap({struct:vp(e,(0,w.A)(this,bp)),output_format:Us.KET,mode:o}).then((function(e){return(0,w.A)(n,bp).deserialize(e.struct)}))}},{key:"check",value:function(e,t){var n=(null==t?void 0:t.types)||mp;return(0,w.A)(this,yp).check({struct:vp(e,(0,w.A)(this,bp)),types:n})}},{key:"calculate",value:function(e,t){var n=(null==t?void 0:t.properties)||pp;return(0,w.A)(this,yp).calculate({struct:vp(e,(0,w.A)(this,bp)),properties:n})}},{key:"recognize",value:function(e,t){var n=this,o=(null==t?void 0:t.version)||"";return(0,w.A)(this,yp).recognize(e,o).then((function(e){return(0,w.A)(n,bp).deserialize(e.struct)}))}},{key:"generateImageAsBase64",value:function(e,t){var n=(null==t?void 0:t.outputFormat)||"png",o=(null==t?void 0:t.backgroundColor)||"",r=(null==t?void 0:t.bondThickness)||ut;return(0,w.A)(this,yp).generateImageAsBase64(vp(e,(0,w.A)(this,bp)),{outputFormat:n,backgroundColor:o,bondThickness:r})}},{key:"toggleExplicitHydrogens",value:function(e){var t=this;return(0,w.A)(this,yp).toggleExplicitHydrogens({struct:vp(e,(0,w.A)(this,bp)),output_format:Us.KET}).then((function(e){return(0,w.A)(t,bp).deserialize(e.struct)}))}}]),e}(),wp="object"==typeof Reflect?Reflect:null,Ep=wp&&"function"==typeof wp.apply?wp.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};gp=wp&&"function"==typeof wp.ownKeys?wp.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var Pp=Number.isNaN||function(e){return e!=e};function xp(){xp.init.call(this)}var Sp=xp;xp.EventEmitter=xp,xp.prototype._events=void 0,xp.prototype._eventsCount=0,xp.prototype._maxListeners=void 0;var Op=10;function kp(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function Mp(e){return void 0===e._maxListeners?xp.defaultMaxListeners:e._maxListeners}function Rp(e,t,n,o){var r,i,a,s;if(kp(n),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),i=e._events),a=i[t]),void 0===a)a=i[t]=n,++e._eventsCount;else if("function"==typeof a?a=i[t]=o?[n,a]:[a,n]:o?a.unshift(n):a.push(n),(r=Mp(e))>0&&a.length>r&&!a.warned){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,console&&console.warn&&console.warn(s)}return e}function Tp(){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 Bp(e,t,n){var o={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=Tp.bind(o);return r.listener=n,o.wrapFn=r,r}function Cp(e,t,n){var o=e._events;if(void 0===o)return[];var r=o[t];return void 0===r?[]:"function"==typeof r?n?[r.listener||r]:[r]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(r):Np(r,r.length)}function Ip(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function Np(e,t){for(var n=new Array(t),o=0;o<t;++o)n[o]=e[o];return n}function Dp(e,t,n,o){if("function"==typeof e.on)o.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function r(i){o.once&&e.removeEventListener(t,r),n(i)}))}}function Lp(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function _p(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Lp(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Lp(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Fp(e,t,n){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.set(e,n)}Object.defineProperty(xp,"defaultMaxListeners",{enumerable:!0,get:function(){return Op},set:function(e){if("number"!=typeof e||e<0||Pp(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Op=e}}),xp.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},xp.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||Pp(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},xp.prototype.getMaxListeners=function(){return Mp(this)},xp.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var o="error"===e,r=this._events;if(void 0!==r)o=o&&void 0===r.error;else if(!o)return!1;if(o){var i;if(t.length>0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var s=r[e];if(void 0===s)return!1;if("function"==typeof s)Ep(s,this,t);else{var u=s.length,l=Np(s,u);for(n=0;n<u;++n)Ep(l[n],this,t)}return!0},xp.prototype.addListener=function(e,t){return Rp(this,e,t,!1)},xp.prototype.on=xp.prototype.addListener,xp.prototype.prependListener=function(e,t){return Rp(this,e,t,!0)},xp.prototype.once=function(e,t){return kp(t),this.on(e,Bp(this,e,t)),this},xp.prototype.prependOnceListener=function(e,t){return kp(t),this.prependListener(e,Bp(this,e,t)),this},xp.prototype.removeListener=function(e,t){var n,o,r,i,a;if(kp(t),void 0===(o=this._events))return this;if(void 0===(n=o[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(r=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){a=n[i].listener,r=i;break}if(r<0)return this;0===r?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,r),1===n.length&&(o[e]=n[0]),void 0!==o.removeListener&&this.emit("removeListener",e,a||t)}return this},xp.prototype.off=xp.prototype.removeListener,xp.prototype.removeAllListeners=function(e){var t,n,o;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[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var r,i=Object.keys(n);for(o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(o=t.length-1;o>=0;o--)this.removeListener(e,t[o]);return this},xp.prototype.listeners=function(e){return Cp(this,e,!0)},xp.prototype.rawListeners=function(e){return Cp(this,e,!1)},xp.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):Ip.call(e,t)},xp.prototype.listenerCount=Ip,xp.prototype.eventNames=function(){return this._eventsCount>0?gp(this._events):[]},Sp.once=function(e,t){return new Promise((function(n,o){function r(n){e.removeListener(t,i),o(n)}function i(){"function"==typeof e.removeListener&&e.removeListener("error",r),n([].slice.call(arguments))}Dp(e,t,i,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&Dp(e,"error",t,{once:!0})}(e,r)}))};var Hp={"general.dearomatize-on-load":"dearomatize-on-load",ignoreChiralFlag:"ignoreChiralFlag",disableQueryElements:"disableQueryElements",bondThickness:"bondThickness"},jp=new WeakMap,Gp=new WeakMap,zp=new WeakMap,Vp=new WeakMap,Up=new WeakMap,Wp=function(){function e(t,n,o){(0,i.A)(this,e),Fp(this,jp,{writable:!0,value:void 0}),Fp(this,Gp,{writable:!0,value:void 0}),Fp(this,zp,{writable:!0,value:void 0}),Fp(this,Vp,{writable:!0,value:void 0}),Fp(this,Up,{writable:!0,value:void 0}),f()(null!=t),f()(null!=n),f()(null!=o),(0,A.A)(this,zp,t),(0,A.A)(this,jp,n),(0,A.A)(this,Gp,o),(0,A.A)(this,Vp,new Ap((0,w.A)(this,jp))),(0,A.A)(this,Up,new Sp.EventEmitter),this.logging={enabled:!1,level:G.ERROR,showTrace:!1}}var t,n,o,s,u,l,c;return(0,a.A)(e,[{key:"editor",get:function(){return(0,w.A)(this,zp)}},{key:"eventBus",get:function(){return(0,w.A)(this,Up)}},{key:"formatterFactory",get:function(){return(0,w.A)(this,Gp)}},{key:"indigo",get:function(){return(0,w.A)(this,Vp)}},{key:"settings",get:function(){var e=(0,w.A)(this,zp).options(),t=Object.entries(Hp).reduce((function(t,n){var o=(0,r.A)(n,2),i=o[0],a=o[1];return a in e?_p(_p({},t),{},(0,d.A)({},i,a)):t}),{});if(!Object.keys(t).length)throw new Error("Allowed options are not provided");return t}},{key:"setSettings",value:function(e){if(!e)throw new Error("Please provide settings");for(var t={},n=0,o=Object.entries(Hp);n<o.length;n++){var i=(0,r.A)(o[n],2),a=i[0];t[i[1]]=e[a]}return Object.hasOwn(e,"disableCustomQuery")&&(te.disableCustomQuery=!!e.disableCustomQuery),(0,w.A)(this,zp).setOptions(JSON.stringify(t))}},{key:"getSmiles",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(window.isPolymerEditorTurnedOn)throw new Error("SMILES format is not available in macro mode");return xc(e?hu.smilesExt:hu.smiles,(0,w.A)(this,Gp),this.editor.struct())}},{key:"getMolfile",value:(c=(0,m.A)(v().mark((function e(t){var n,o,r,i;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.containsReaction()){e.next=2;break}throw Error("The structure cannot be saved as *.MOL due to reaction arrows.");case 2:return o="v3000"===t?hu.molV3000:hu.mol,r=t?o:hu.molAuto,e.next=6,xc(r,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct(),null===(n=zc.provideEditorInstance())||void 0===n?void 0:n.drawingEntitiesManager);case 6:return i=e.sent,e.abrupt("return",i);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"getRxn",value:(l=(0,m.A)(v().mark((function e(){var t,n,o,r=arguments;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.length>0&&void 0!==r[0]?r[0]:"v2000",!window.isPolymerEditorTurnedOn){e.next=3;break}throw new Error("RXN format is not available in macro mode");case 3:if(this.containsReaction()){e.next=5;break}throw Error("The structure cannot be saved as *.RXN: there is no reaction arrows.");case 5:return n="v3000"===t?hu.rxnV3000:hu.rxn,e.next=8,xc(n,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct());case 8:return o=e.sent,e.abrupt("return",o);case 10:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"getKet",value:function(){var e;return xc(hu.ket,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct(),null===(e=zc.provideEditorInstance())||void 0===e?void 0:e.drawingEntitiesManager)}},{key:"getFasta",value:function(){var e;return xc(hu.fasta,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct(),null===(e=zc.provideEditorInstance())||void 0===e?void 0:e.drawingEntitiesManager)}},{key:"getSequence",value:function(){var e;return xc(hu.sequence,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct(),null===(e=zc.provideEditorInstance())||void 0===e?void 0:e.drawingEntitiesManager)}},{key:"getSmarts",value:function(){if(window.isPolymerEditorTurnedOn)throw new Error("SMARTS format is not available in macro mode");return xc(hu.smarts,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct())}},{key:"getCml",value:function(){if(window.isPolymerEditorTurnedOn)throw new Error("CML format is not available in macro mode");return xc(hu.cml,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct())}},{key:"getSdf",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"v2000";if(window.isPolymerEditorTurnedOn)throw new Error("SDF format is not available in macro mode");return xc("v2000"===e?hu.sdf:hu.sdfV3000,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct())}},{key:"getCDXml",value:function(){if(window.isPolymerEditorTurnedOn)throw new Error("CDXML format is not available in macro mode");return xc(hu.cdxml,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct())}},{key:"getCDX",value:function(){if(window.isPolymerEditorTurnedOn)throw new Error("CDX format is not available in macro mode");return xc(hu.cdx,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct())}},{key:"getInchi",value:function(){return xc(arguments.length>0&&void 0!==arguments[0]&&arguments[0]?hu.inChIAuxInfo:hu.inChI,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct())}},{key:"getInChIKey",value:(u=(0,m.A)(v().mark((function e(){var t;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,xc(hu.ket,(0,w.A)(this,Gp),(0,w.A)(this,zp).struct());case 2:return t=e.sent,e.abrupt("return",(0,w.A)(this,jp).getInChIKey(t));case 4:case"end":return e.stop()}}),e,this)}))),function(){return u.apply(this,arguments)})},{key:"containsReaction",value:function(){var e,t=zc.provideEditorInstance();return this.editor.struct().hasRxnArrow()||(null==t||null===(e=t.drawingEntitiesManager)||void 0===e?void 0:e.micromoleculesHiddenEntities.hasRxnArrow())}},{key:"isQueryStructureSelected",value:function(){var e=this.editor.struct(),t=this.editor.selection();if(!t)return!1;var n=!1;t.atoms&&(n=t.atoms.some((function(t){var n=e.atoms.get(t);f()(n);var o=Array.from(n.sgs.values()).some((function(t){var n=e.sgroups.get(t);return f()(n),ht.isQuerySGroup(n)}));return n.isQuery()||o})));var o=!1;return t.bonds&&(o=t.bonds.some((function(t){var n=e.bonds.get(t);return f()(n),n.isQuery()}))),n||o}},{key:"setMolecule",value:(s=(0,m.A)(v().mark((function e(t){var n=this;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:$((0,m.A)(v().mark((function e(){var o;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(f()("string"==typeof t),!window.isPolymerEditorTurnedOn){e.next=7;break}return Mc(),e.next=5,Rc(t,(0,w.A)(n,jp));case 5:e.next=14;break;case 7:return e.next=9,Sc(t,(0,w.A)(n,jp),n);case 9:(o=e.sent).rescale(),(0,w.A)(n,zp).struct(o),(0,w.A)(n,zp).zoomAccordingContent(o),(0,w.A)(n,zp).centerStruct();case 14:case"end":return e.stop()}}),e)}))),this.eventBus);case 1:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"addFragment",value:(o=(0,m.A)(v().mark((function e(t){var n=this;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:$((0,m.A)(v().mark((function e(){var o;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(f()("string"==typeof t),!window.isPolymerEditorTurnedOn){e.next=6;break}return e.next=4,Rc(t,(0,w.A)(n,jp));case 4:e.next=11;break;case 6:return e.next=8,Sc(t,(0,w.A)(n,jp),n);case 8:(o=e.sent).rescale(),(0,w.A)(n,zp).structToAddFragment(o);case 11:case"end":return e.stop()}}),e)}))),this.eventBus);case 1:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"layout",value:(n=(0,m.A)(v().mark((function e(){var t=this;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!window.isPolymerEditorTurnedOn){e.next=2;break}throw new Error("Layout is not available in macro mode");case 2:$((0,m.A)(v().mark((function e(){var n,o;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,w.A)(t,Vp).layout((0,w.A)(t,zp).struct());case 2:n=e.sent,o=new Vu,t.setMolecule(o.serialize(n));case 5:case"end":return e.stop()}}),e)}))),this.eventBus);case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"recognize",value:function(e,t){if(window.isPolymerEditorTurnedOn)throw new Error("Recognize is not available in macro mode");return(0,w.A)(this,Vp).recognize(e,{version:t})}},{key:"generateImage",value:(t=(0,m.A)(v().mark((function e(t){var n,o,r,i,a,s,u,l,c=arguments;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=c.length>1&&void 0!==c[1]?c[1]:{outputFormat:"png",bondThickness:ut},o="",e.t0=n.outputFormat,e.next="svg"===e.t0?5:(e.t0,7);break;case 5:return o="image/svg+xml",e.abrupt("break",9);case 7:o="image/png",n.outputFormat="png";case 9:return e.next=11,(0,w.A)(this,jp).generateImageAsBase64(t,n);case 11:for(r=e.sent,i=atob(r),a=new Array(i.length),s=0;s<i.length;s++)a[s]=i.charCodeAt(s);return u=new Uint8Array(a),l=new Blob([u],{type:o}),e.abrupt("return",l);case 18:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),e}();function qp(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function Yp(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?qp(Object(n),!0).forEach((function(t){(0,d.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):qp(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var $p={"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,"ignore-no-chiral-flag":!1},Xp=new WeakMap;(0,a.A)((function e(){var t,n,o;(0,i.A)(this,e),o={writable:!0,value:void 0},function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t=this,n=Xp),n.set(t,o)}),[{key:"withStructServiceProvider",value:function(e){return(0,A.A)(this,Xp,e),this}},{key:"build",value:function(e,t){f()(null!=e),f()(null!=(0,w.A)(this,Xp));var n=Yp(Yp({},$p),t),o=(0,w.A)(this,Xp).createStructService(n),r=new Wp(e,o,new wc(o));return r[(0,w.A)(this,Xp).mode]=!0,Pc.setKetcherInstance(r),r}}])}}]);