static.kuangkie.hydrogen.bundle.908845ef105919970172.js Maven / Gradle / Ivy
"use strict";(self.webpackChunkhydrogen_react=self.webpackChunkhydrogen_react||[]).push([[5518],{55518:function(t,e,n){n.d(e,{$Tq:function(){return xs},AUF:function(){return te},BFU:function(){return ul},B_f:function(){return Tt},C8:function(){return wo},Ciz:function(){return gt},CnU:function(){return sl},Cv7:function(){return Jt},D34:function(){return su},DEm:function(){return j},DYm:function(){return za},Dps:function(){return na},Eps:function(){return Ua},F_l:function(){return xe},GoV:function(){return ea},HYg:function(){return vt},Hlm:function(){return is},Hrh:function(){return no},Hwe:function(){return ha},I6H:function(){return Rt},Ilx:function(){return F},IzQ:function(){return vo},J3L:function(){return Wa},J41:function(){return Lt},Jj2:function(){return ct},KEI:function(){return Xr},Ksv:function(){return ks},MZv:function(){return qa},MfV:function(){return ru},Mih:function(){return V},Mqr:function(){return Aa},NER:function(){return ao},NZY:function(){return Ia},NmG:function(){return Ps},OAk:function(){return ns},OnW:function(){return ts},QOv:function(){return Ga},QXZ:function(){return ba},QpJ:function(){return ua},QqH:function(){return os},RZd:function(){return Ha},RmL:function(){return $a},Ruh:function(){return In},SZr:function(){return Fn},Sgu:function(){return $},TPF:function(){return ss},U9$:function(){return ca},UE_:function(){return et},V4S:function(){return aa},VA:function(){return xl},VT4:function(){return Qn},Wa4:function(){return wa},X3r:function(){return U},X6G:function(){return D},YkY:function(){return J},YlQ:function(){return lu},Yyn:function(){return _u},aUM:function(){return Di},atm:function(){return Ts},azF:function(){return or},bDx:function(){return Ma},cMT:function(){return ds},dBq:function(){return Sa},dmV:function(){return ta},e9t:function(){return bs},eKO:function(){return _},f0f:function(){return $i},f8s:function(){return Ra},fYe:function(){return dt},g5D:function(){return cs},gHo:function(){return es},gN2:function(){return zt},ghY:function(){return ja},hgN:function(){return at},hxV:function(){return Cn},j1n:function(){return Zt},jWx:function(){return xn},jgo:function(){return q},jnZ:function(){return Ea},k03:function(){return go},k_5:function(){return Ka},ksM:function(){return ys},lI3:function(){return Ja},ltA:function(){return ls},lv1:function(){return Du},m81:function(){return gs},mWk:function(){return _t},nHA:function(){return Qa},o2T:function(){return wt},oEw:function(){return Za},on4:function(){return po},pq6:function(){return Vi},qeV:function(){return Ji},rzF:function(){return Es},sNV:function(){return fo},t5M:function(){return Kn},tIy:function(){return Yt},toQ:function(){return mo},uMq:function(){return bt},v$W:function(){return rs},vfe:function(){return Gt},voO:function(){return fu},wSe:function(){return sa},wql:function(){return I},xKj:function(){return Gn},xiC:function(){return Ol},xz_:function(){return du},ymK:function(){return pu},z8H:function(){return Fa}});var r=n(55043),o=n(4913),i=n(64296),a=n(8270),s=n(80967),u=n.n(s),l=n(54390),c=n(1117),d=n.n(c),h=n(25206),f=n(81928),p=n(88503),m=n(93311),v=n(10246),g=n(65980),y=n(85804),b=n(76464),w=n(10327),x=n(31311),E=n(13974),P=n.n(E),O=n(29550),A=n.n(O),R=n(38181),S=n.n(R),T=n(88094),k=n.n(T),B=n(26858),C=n(3153),Z=n(17253),I={H:"#000000",He:"#89a1a1",Li:"#bd77ed",Be:"#8fbc00",B:"#c18989",C:"#000000",N:"#304ff7",O:"#ff0d0d",F:"#78bc42",Ne:"#80a2af",Na:"#ab5cf2",Mg:"#6fcd00",Al:"#a99393",Si:"#b29478",P:"#ff8000",S:"#c99a19",Cl:"#1fd01f",Ar:"#69acba",K:"#8f40d4",Ca:"#38e900",Sc:"#999999",Ti:"#979a9e",V:"#99999e",Cr:"#8a99c7",Mn:"#9c7ac7",Fe:"#e06633",Co:"#d37e8e",Ni:"#4ece4e",Cu:"#c78033",Zn:"#7d80b0",Ga:"#bc8b8b",Ge:"#668f8f",As:"#b87ddd",Se:"#e59100",Br:"#a62929",Kr:"#59b1c9",Rb:"#702eb0",Sr:"#00ff00",Y:"#66afaf",Zr:"#71abab",Nb:"#67aeb4",Mo:"#54b5b5",Tc:"#3b9e9e",Ru:"#248f8f",Rh:"#0a7d8c",Pd:"#006985",Ag:"#9a9a9a",Cd:"#b29764",In:"#a67573",Sn:"#668080",Sb:"#9e63b5",Te:"#d47a00",I:"#940094",Xe:"#429eb0",Cs:"#57178f",Ba:"#00c900",La:"#5caed1",Ce:"#9d9d7b",Pr:"#8ca581",Nd:"#84a984",Pm:"#71b18a",Sm:"#66b68e",Eu:"#4ac298",Gd:"#37cb9e",Tb:"#28d1a4",Dy:"#1bd7a8",Ho:"#00e98f",Er:"#00e675",Tm:"#00d452",Yb:"#00bf38",Lu:"#00ab24",Hf:"#47b3ec",Ta:"#4da6ff",W:"#2194d6",Re:"#267dab",Os:"#266696",Ir:"#175487",Pt:"#9898a3",Au:"#c19e1c",Hg:"#9797ac",Tl:"#a6544d",Pb:"#575961",Bi:"#9e4fb5",Po:"#ab5c00",At:"#754f45",Rn:"#428296",Fr:"#420066",Ra:"#007d00",Ac:"#6aa2ec",Th:"#00baff",Pa:"#00a1ff",U:"#008fff",Np:"#0080ff",Pu:"#006bff",Am:"#545cf2",Cm:"#785ce3",Bk:"#8a4fe3",Cf:"#a136d4",Es:"#b31fd4",Fm:"#000000",Md:"#000000",No:"#000000",Lr:"#000000",Rf:"#47b3ec",Db:"#4da6ff",Sg:"#2194d6",Bh:"#267dab",Hs:"#266696",Mt:"#175487",Ds:"#9898a3",Rg:"#c19e1c",Cn:"#9797ac",Nh:"#000000",Fl:"#000000",Mc:"#000000",Lv:"#000000",Ts:"#000000",Og:"#000000"},M=[{number:1,label:"H",period:1,group:1,title:"Hydrogen",state:"gas",origin:"primordial",type:"other-nonmetal",mass:1.00794},{number:2,label:"He",period:1,group:8,title:"Helium",state:"gas",origin:"primordial",type:"noble",mass:4.0026022},{number:3,label:"Li",period:2,group:1,title:"Lithium",state:"solid",origin:"primordial",type:"alkali",mass:6.94},{number:4,label:"Be",period:2,group:2,title:"Beryllium",state:"solid",origin:"primordial",type:"alkaline-earth",mass:9.01218315},{number:5,label:"B",period:2,group:3,title:"Boron",state:"solid",origin:"primordial",type:"metalloid",mass:10.81},{number:6,label:"C",period:2,group:4,title:"Carbon",state:"solid",origin:"primordial",type:"other-nonmetal",mass:12.011},{number:7,label:"N",period:2,group:5,title:"Nitrogen",state:"gas",origin:"primordial",type:"other-nonmetal",mass:14.007},{number:8,label:"O",period:2,group:6,leftH:!0,title:"Oxygen",state:"gas",origin:"primordial",type:"other-nonmetal",mass:15.999},{number:9,label:"F",period:2,group:7,leftH:!0,title:"Fluorine",state:"gas",origin:"primordial",type:"halogen",mass:18.9984031636},{number:10,label:"Ne",period:2,group:8,title:"Neon",state:"gas",origin:"primordial",type:"noble",mass:20.17976},{number:11,label:"Na",period:3,group:1,title:"Sodium",state:"solid",origin:"primordial",type:"alkali",mass:22.989769282},{number:12,label:"Mg",period:3,group:2,title:"Magnesium",state:"solid",origin:"primordial",type:"alkaline-earth",mass:24.305},{number:13,label:"Al",period:3,group:3,title:"Aluminium",state:"solid",origin:"primordial",type:"post-transition",mass:26.98153857},{number:14,label:"Si",period:3,group:4,title:"Silicon",state:"solid",origin:"primordial",type:"metalloid",mass:28.085},{number:15,label:"P",period:3,group:5,title:"Phosphorus",state:"solid",origin:"primordial",type:"other-nonmetal",mass:30.9737619985},{number:16,label:"S",period:3,group:6,leftH:!0,title:"Sulfur",state:"solid",origin:"primordial",type:"other-nonmetal",mass:32.06},{number:17,label:"Cl",period:3,group:7,leftH:!0,title:"Chlorine",state:"gas",origin:"primordial",type:"halogen",mass:35.45},{number:18,label:"Ar",period:3,group:8,title:"Argon",state:"gas",origin:"primordial",type:"noble",mass:39.9481},{number:19,label:"K",period:4,group:1,title:"Potassium",state:"solid",origin:"primordial",type:"alkali",mass:39.09831},{number:20,label:"Ca",period:4,group:2,title:"Calcium",state:"solid",origin:"primordial",type:"alkaline-earth",mass:40.0784},{number:21,label:"Sc",period:4,group:3,title:"Scandium",state:"solid",origin:"primordial",type:"transition",mass:44.9559085},{number:22,label:"Ti",period:4,group:4,title:"Titanium",state:"solid",origin:"primordial",type:"transition",mass:47.8671},{number:23,label:"V",period:4,group:5,title:"Vanadium",state:"solid",origin:"primordial",type:"transition",mass:50.94151},{number:24,label:"Cr",period:4,group:6,title:"Chromium",state:"solid",origin:"primordial",type:"transition",mass:51.99616},{number:25,label:"Mn",period:4,group:7,title:"Manganese",state:"solid",origin:"primordial",type:"transition",mass:54.9380443},{number:26,label:"Fe",period:4,group:8,title:"Iron",state:"solid",origin:"primordial",type:"transition",mass:55.8452},{number:27,label:"Co",period:4,group:8,title:"Cobalt",state:"solid",origin:"primordial",type:"transition",mass:58.9331944},{number:28,label:"Ni",period:4,group:8,title:"Nickel",state:"solid",origin:"primordial",type:"transition",mass:58.69344},{number:29,label:"Cu",period:4,group:1,title:"Copper",state:"solid",origin:"primordial",type:"transition",mass:63.5463},{number:30,label:"Zn",period:4,group:2,title:"Zinc",state:"solid",origin:"primordial",type:"transition",mass:65.382},{number:31,label:"Ga",period:4,group:3,title:"Gallium",state:"solid",origin:"primordial",type:"post-transition",mass:69.7231},{number:32,label:"Ge",period:4,group:4,title:"Germanium",state:"solid",origin:"primordial",type:"metalloid",mass:72.6308},{number:33,label:"As",period:4,group:5,title:"Arsenic",state:"solid",origin:"primordial",type:"metalloid",mass:74.9215956},{number:34,label:"Se",period:4,group:6,leftH:!0,title:"Selenium",state:"solid",origin:"primordial",type:"other-nonmetal",mass:78.9718},{number:35,label:"Br",period:4,group:7,leftH:!0,title:"Bromine",state:"liquid",origin:"primordial",type:"halogen",mass:79.904},{number:36,label:"Kr",period:4,group:8,title:"Krypton",state:"gas",origin:"primordial",type:"noble",mass:83.7982},{number:37,label:"Rb",period:5,group:1,title:"Rubidium",state:"solid",origin:"primordial",type:"alkali",mass:85.46783},{number:38,label:"Sr",period:5,group:2,title:"Strontium",state:"solid",origin:"primordial",type:"alkaline-earth",mass:87.621},{number:39,label:"Y",period:5,group:3,title:"Yttrium",state:"solid",origin:"primordial",type:"transition",mass:88.905842},{number:40,label:"Zr",period:5,group:4,title:"Zirconium",state:"solid",origin:"primordial",type:"transition",mass:91.2242},{number:41,label:"Nb",period:5,group:5,title:"Niobium",state:"solid",origin:"primordial",type:"transition",mass:92.906372},{number:42,label:"Mo",period:5,group:6,title:"Molybdenum",state:"solid",origin:"primordial",type:"transition",mass:95.951},{number:43,label:"Tc",period:5,group:7,title:"Technetium",state:"solid",origin:"decay",type:"transition",mass:98},{number:44,label:"Ru",period:5,group:8,title:"Ruthenium",state:"solid",origin:"primordial",type:"transition",mass:101.072},{number:45,label:"Rh",period:5,group:8,title:"Rhodium",state:"solid",origin:"primordial",type:"transition",mass:102.905502},{number:46,label:"Pd",period:5,group:8,title:"Palladium",state:"solid",origin:"primordial",type:"transition",mass:106.421},{number:47,label:"Ag",period:5,group:1,title:"Silver",state:"solid",origin:"primordial",type:"transition",mass:107.86822},{number:48,label:"Cd",period:5,group:2,title:"Cadmium",state:"solid",origin:"primordial",type:"transition",mass:112.4144},{number:49,label:"In",period:5,group:3,title:"Indium",state:"solid",origin:"primordial",type:"post-transition",mass:114.8181},{number:50,label:"Sn",period:5,group:4,title:"Tin",state:"solid",origin:"primordial",type:"post-transition",mass:118.7107},{number:51,label:"Sb",period:5,group:5,title:"Antimony",state:"solid",origin:"primordial",type:"metalloid",mass:121.7601},{number:52,label:"Te",period:5,group:6,title:"Tellurium",state:"solid",origin:"primordial",type:"metalloid",mass:127.603},{number:53,label:"I",period:5,group:7,leftH:!0,title:"Iodine",state:"solid",origin:"primordial",type:"halogen",mass:126.904473},{number:54,label:"Xe",period:5,group:8,title:"Xenon",state:"gas",origin:"primordial",type:"noble",mass:131.2936},{number:55,label:"Cs",period:6,group:1,title:"Caesium",state:"solid",origin:"primordial",type:"alkali",mass:132.905451966},{number:56,label:"Ba",period:6,group:2,title:"Barium",state:"solid",origin:"primordial",type:"alkaline-earth",mass:137.3277},{number:57,label:"La",period:6,group:3,title:"Lanthanum",state:"solid",origin:"primordial",type:"transition",mass:138.905477},{number:58,label:"Ce",period:6,group:3,title:"Cerium",state:"solid",origin:"primordial",type:"lanthanide",mass:140.1161},{number:59,label:"Pr",period:6,group:3,title:"Praseodymium",state:"solid",origin:"primordial",type:"lanthanide",mass:140.907662},{number:60,label:"Nd",period:6,group:3,title:"Neodymium",state:"solid",origin:"primordial",type:"lanthanide",mass:144.2423},{number:61,label:"Pm",period:6,group:3,title:"Promethium",state:"solid",origin:"decay",type:"lanthanide",mass:145},{number:62,label:"Sm",period:6,group:3,title:"Samarium",state:"solid",origin:"primordial",type:"lanthanide",mass:150.362},{number:63,label:"Eu",period:6,group:3,title:"Europium",state:"solid",origin:"primordial",type:"lanthanide",mass:151.9641},{number:64,label:"Gd",period:6,group:3,title:"Gadolinium",state:"solid",origin:"primordial",type:"lanthanide",mass:157.253},{number:65,label:"Tb",period:6,group:3,title:"Terbium",state:"solid",origin:"primordial",type:"lanthanide",mass:158.925352},{number:66,label:"Dy",period:6,group:3,title:"Dysprosium",state:"solid",origin:"primordial",type:"lanthanide",mass:162.5001},{number:67,label:"Ho",period:6,group:3,title:"Holmium",state:"solid",origin:"primordial",type:"lanthanide",mass:164.930332},{number:68,label:"Er",period:6,group:3,title:"Erbium",state:"solid",origin:"primordial",type:"lanthanide",mass:167.2593},{number:69,label:"Tm",period:6,group:3,title:"Thulium",state:"solid",origin:"primordial",type:"lanthanide",mass:168.934222},{number:70,label:"Yb",period:6,group:3,title:"Ytterbium",state:"solid",origin:"primordial",type:"lanthanide",mass:173.0451},{number:71,label:"Lu",period:6,group:3,title:"Lutetium",state:"solid",origin:"primordial",type:"lanthanide",mass:174.96681},{number:72,label:"Hf",period:6,group:4,title:"Hafnium",state:"solid",origin:"primordial",type:"transition",mass:178.492},{number:73,label:"Ta",period:6,group:5,title:"Tantalum",state:"solid",origin:"primordial",type:"transition",mass:180.947882},{number:74,label:"W",period:6,group:6,title:"Tungsten",state:"solid",origin:"primordial",type:"transition",mass:183.841},{number:75,label:"Re",period:6,group:7,title:"Rhenium",state:"solid",origin:"primordial",type:"transition",mass:186.2071},{number:76,label:"Os",period:6,group:8,title:"Osmium",state:"solid",origin:"primordial",type:"transition",mass:190.233},{number:77,label:"Ir",period:6,group:8,title:"Iridium",state:"solid",origin:"primordial",type:"transition",mass:192.2173},{number:78,label:"Pt",period:6,group:8,title:"Platinum",state:"solid",origin:"primordial",type:"transition",mass:195.0849},{number:79,label:"Au",period:6,group:1,title:"Gold",state:"solid",origin:"primordial",type:"transition",mass:196.9665695},{number:80,label:"Hg",period:6,group:2,title:"Mercury",state:"liquid",origin:"primordial",type:"transition",mass:200.5923},{number:81,label:"Tl",period:6,group:3,title:"Thallium",state:"solid",origin:"primordial",type:"post-transition",mass:204.38},{number:82,label:"Pb",period:6,group:4,title:"Lead",state:"solid",origin:"primordial",type:"post-transition",mass:207.21},{number:83,label:"Bi",period:6,group:5,title:"Bismuth",state:"solid",origin:"primordial",type:"post-transition",mass:208.980401},{number:84,label:"Po",period:6,group:6,title:"Polonium",state:"solid",origin:"decay",type:"metalloid",mass:209},{number:85,label:"At",period:6,group:7,title:"Astatine",state:"solid",origin:"decay",type:"halogen",mass:210},{number:86,label:"Rn",period:6,group:8,title:"Radon",state:"gas",origin:"decay",type:"noble",mass:222},{number:87,label:"Fr",period:7,group:1,title:"Francium",state:"solid",origin:"decay",type:"alkali",mass:223},{number:88,label:"Ra",period:7,group:2,title:"Radium",state:"solid",origin:"decay",type:"alkaline-earth",mass:226},{number:89,label:"Ac",period:7,group:3,title:"Actinium",state:"solid",origin:"decay",type:"transition",mass:227},{number:90,label:"Th",period:7,group:3,title:"Thorium",state:"solid",origin:"primordial",type:"actinide",mass:232.03774},{number:91,label:"Pa",period:7,group:3,title:"Protactinium",state:"solid",origin:"decay",type:"actinide",mass:231.035882},{number:92,label:"U",period:7,group:3,title:"Uranium",state:"solid",origin:"primordial",type:"actinide",mass:238.028913},{number:93,label:"Np",period:7,group:3,title:"Neptunium",state:"solid",origin:"decay",type:"actinide",mass:237},{number:94,label:"Pu",period:7,group:3,title:"Plutonium",state:"solid",origin:"decay",type:"actinide",mass:244},{number:95,label:"Am",period:7,group:3,title:"Americium",state:"solid",origin:"synthetic",type:"actinide",mass:243},{number:96,label:"Cm",period:7,group:3,title:"Curium",state:"solid",origin:"synthetic",type:"actinide",mass:247},{number:97,label:"Bk",period:7,group:3,title:"Berkelium",state:"solid",origin:"synthetic",type:"actinide",mass:247},{number:98,label:"Cf",period:7,group:3,title:"Californium",state:"solid",origin:"synthetic",type:"actinide",mass:251},{number:99,label:"Es",period:7,group:3,title:"Einsteinium",state:"solid",origin:"synthetic",type:"actinide",mass:252},{number:100,label:"Fm",period:7,group:3,title:"Fermium",origin:"synthetic",type:"actinide",mass:257},{number:101,label:"Md",period:7,group:3,title:"Mendelevium",origin:"synthetic",type:"actinide",mass:258},{number:102,label:"No",period:7,group:3,title:"Nobelium",origin:"synthetic",type:"actinide",mass:259},{number:103,label:"Lr",period:7,group:3,title:"Lawrencium",origin:"synthetic",type:"actinide",mass:266},{number:104,label:"Rf",period:7,group:4,title:"Rutherfordium",origin:"synthetic",type:"transition",mass:267},{number:105,label:"Db",period:7,group:5,title:"Dubnium",origin:"synthetic",type:"transition",mass:268},{number:106,label:"Sg",period:7,group:6,title:"Seaborgium",origin:"synthetic",type:"transition",mass:269},{number:107,label:"Bh",period:7,group:7,title:"Bohrium",origin:"synthetic",type:"transition",mass:270},{number:108,label:"Hs",period:7,group:8,title:"Hassium",origin:"synthetic",type:"transition",mass:269},{number:109,label:"Mt",period:7,group:8,title:"Meitnerium",origin:"synthetic",type:"transition",mass:278},{number:110,label:"Ds",period:7,group:8,title:"Darmstadtium",origin:"synthetic",type:"transition",mass:281},{number:111,label:"Rg",period:7,group:1,title:"Roentgenium",origin:"synthetic",type:"transition",mass:282},{number:112,label:"Cn",period:7,group:2,title:"Copernicium",origin:"synthetic",type:"transition",mass:285},{number:113,label:"Nh",period:7,group:3,title:"Nihonium",origin:"synthetic",type:"post-transition",mass:286},{number:114,label:"Fl",period:7,group:4,title:"Flerovium",origin:"synthetic",type:"post-transition",mass:289},{number:115,label:"Mc",period:7,group:5,title:"Moscovium",origin:"synthetic",type:"post-transition",mass:289},{number:116,label:"Lv",period:7,group:6,title:"Livermorium",origin:"synthetic",type:"post-transition",mass:293},{number:117,label:"Ts",period:7,group:7,title:"Tennessine",origin:"synthetic",type:"halogen",mass:294},{number:118,label:"Og",period:7,group:8,title:"Oganesson",origin:"synthetic",type:"noble",mass:294}],N=M.reduce((function(t,e){return t.set(e.label,e),t.set(e.number,e),t}),new Map),_={get:function(t){return N.get(t)},filter:function(t){return M.filter(t)},getAll:function(){return[].concat(M)}},D={"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"}]}]}}}}}};function L(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}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(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}(this.ids);try{for(n.s();!(t=n.n()).done;){var r=t.value,o=_.get(r);o&&e.push(o.label)}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"label",value:function(){var t="["+this.labelList().join(",")+"]";return this.notList&&(t="!"+t),t}},{key:"equals",value:function(t){return this.notList===t.notList&&(this.ids||[]).sort().toString()===(t.ids||[]).sort().toString()}}]),t}();function G(t,e,n,r){null==n||n===r||Array.isArray(n)&&0===n.length||(t[e]=n)}function H(t){return("number"==typeof t?t:parseFloat(t)).toFixed(8)}!function(t){t.LOADING="LOADING",t.SUCCESS="SUCCESS",t.FAILURE="FAILURE"}(j||(j={}));var z,U=(z=(0,l.Z)(d().mark((function t(e,n){var r;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n.emit(j.LOADING),t.prev=1,t.next=4,e();case 4:return r=t.sent,n.emit(j.SUCCESS),t.abrupt("return",r);case 9:return t.prev=9,t.t0=t.catch(1),n.emit(j.FAILURE),t.abrupt("return",void 0);case 14:case"end":return t.stop()}}),t,null,[[1,9]])}))),function(t,e){return z.apply(this,arguments)});function V(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:512,r=window.atob(t),o=[],i=0;in!=l>n&&e<(u-a)*(n-s)/(l-s)+a&&(r=!r)}return r}},{key:"oxAngle",value:function(){return Math.atan2(this.y,this.x)}}],[{key:"dist",value:function(e,n){return t.diff(e,n).length()}},{key:"max",value:function(e,n){return new t(Math.max(e.x,n.x),Math.max(e.y,n.y),Math.max(e.z,n.z))}},{key:"min",value:function(e,n){return new t(Math.min(e.x,n.x),Math.min(e.y,n.y),Math.min(e.z,n.z))}},{key:"sum",value:function(e,n){return new t(e.x+n.x,e.y+n.y,e.z+n.z)}},{key:"dot",value:function(t,e){return t.x*e.x+t.y*e.y}},{key:"cross",value:function(t,e){return t.x*e.y-t.y*e.x}},{key:"angle",value:function(e,n){return Math.atan2(t.cross(e,n),t.dot(e,n))}},{key:"diff",value:function(e,n){return new t(e.x-n.x,e.y-n.y,e.z-n.z)}},{key:"lc",value:function(){for(var e=arguments.length,n=new Array(e),r=0;r=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}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(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function K(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n0?(e=!0,r=!0,t.union(n)):t}));return r||o.push(n),o}),new Array);return e?a.unionIntersections(n):n}}]),a}((0,v.Z)(Set));function nt(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return rt(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?rt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}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(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function rt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n=1?(s=3,u=3-a-e):(s=2,u=2-a-e-l):"S"===n||"Se"===n||"Po"===n?1===r?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===r?e<=2&&(s=2,u=2-a-e-l):0!==r&&2!==r||(e<=2?(s=2,u=2-a-e-l):e<=4?(s=4,u=4-a-e-l):0===r&&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===r?e<=2?(s=2,u=2-a-e):(3===e||5===e||e>=7)&&(u=-1):0===r&&(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(t){var e=this.charge,n=this.label,r=_.get(this.label);if(!r)return this.implicitH=0,0;var o=r.group,i=st(this.radical);if(3===o){if(("B"===n||"Al"===n||"Ga"===n||"In"===n)&&-1===e&&i+t<=4)return i+t}else if(5===o){if("N"===n||"P"===n){if(1===e)return i+t;if(2===e)return i+t}else if("Sb"===n||"Bi"===n||"As"===n){if(1===e)return i+t;if(2===e)return i+t}}else if(6===o){if("O"===n){if(e>=1)return i+t}else if(("S"===n||"Se"===n||"Po"===n)&&1===e)return i+t}else if(7===o&&("Cl"===n||"Br"===n||"I"===n||"At"===n)&&1===e)return i+t;return i+t+Math.abs(e)}}],[{key:"getConnectedBondIds",value:function(t,e){var n,o=[],i=nt(t.bonds.entries());try{for(i.s();!(n=i.n()).done;){var a=(0,r.Z)(n.value,2),s=a[0],u=a[1];u.begin!==e&&u.end!==e||o.push(s)}}catch(t){i.e(t)}finally{i.f()}return o}},{key:"getAttrHash",value:function(e){var n={};for(var r in t.attrlist)void 0!==e[r]&&(n[r]=e[r]);return n}},{key:"attrGetDefault",value:function(e){if(e in t.attrlist)return t.attrlist[e]}},{key:"isHeteroAtom",value:function(t){return"C"!==t&&"H"!==t}},{key:"isInAromatizedRing",value:function(e,n){var o=e.atoms.get(n);if(o&&t.isHeteroAtom(o.label)){var i,a=nt(e.loops);try{for(a.s();!(i=a.n()).done;){var s=(0,r.Z)(i.value,2),u=(s[0],s[1]),l=u.hbs;if(u.aromatic){var c,d=nt(l);try{for(d.s();!(c=d.n()).done;){var h=c.value,f=e.halfBonds.get(h);if(!f)return!1;var p=f.begin,m=f.end;if(p===n||m===n)return!0}}catch(t){d.e(t)}finally{d.f()}}}}catch(t){a.e(t)}finally{a.f()}}return!1}}]),t}();function st(t){return(t-=0)===at.PATTERN.RADICAL.DOUPLET?1:t===at.PATTERN.RADICAL.SINGLET||t===at.PATTERN.RADICAL.TRIPLET?2:0}function ut(t,e){return void 0!==t?t:e}function lt(t){return!_.get(t)&&"L"!==t&&"L#"!==t&&"R#"!==t}(0,a.Z)(at,"PATTERN",{RADICAL:{NONE:0,SINGLET:1,DOUPLET:2,TRIPLET:3},STEREO_PARITY:{NONE:0,ODD:1,EVEN:2,EITHER:3}}),(0,a.Z)(at,"attrlist",{alias:null,label:"C",isotope:0,radical:0,cip:null,charge:0,explicitValence:-1,ringBondCount:0,substitutionCount:0,unsaturatedAtom:0,hCount:0,atomList:null,invRet:0,exactChangeFlag:0,rglabel:null,attachmentPoints:null,aam:0,isPreview:!1,stereoLabel:null,stereoParity:0,implicitHCount:null}),function(t){t.E="E",t.Z="Z",t.M="M",t.P="P"}(it||(it={}));var ct,dt=function(){function t(e){var n;(0,o.Z)(this,t),this.begin=e.begin,this.end=e.end,this.type=e.type,this.xxx=e.xxx||"",this.stereo=t.PATTERN.STEREO.NONE,this.topology=t.PATTERN.TOPOLOGY.EITHER,this.reactingCenterStatus=0,this.cip=null!==(n=e.cip)&&void 0!==n?n:null,this.len=0,this.sb=0,this.sa=0,this.angle=0,this.isPreview=!1,e.stereo&&(this.stereo=e.stereo),e.topology&&(this.topology=e.topology),e.reactingCenterStatus&&(this.reactingCenterStatus=e.reactingCenterStatus),this.center=new $}return(0,i.Z)(t,[{key:"hasRxnProps",value:function(){return!!this.reactingCenterStatus}},{key:"getCenter",value:function(t){var e=t.atoms.get(this.begin).pp,n=t.atoms.get(this.end).pp;return $.lc2(e,.5,n,.5)}},{key:"getDir",value:function(t){var e=t.atoms.get(this.begin).pp;return t.atoms.get(this.end).pp.sub(e).normalized()}},{key:"clone",value:function(e){var n=new t(this);return e&&(n.begin=e.get(n.begin),n.end=e.get(n.end)),n}},{key:"getAttachedSGroups",value:function(t){var e,n,r=(null===(e=t.atoms.get(this.begin))||void 0===e?void 0:e.sgs)||new et,o=(null===(n=t.atoms.get(this.end))||void 0===n?void 0:n.sgs)||new et;return null==r?void 0:r.intersection(o)}}],[{key:"getAttrHash",value:function(e){var n={};for(var r in t.attrlist)(e[r]||"stereo"===r)&&(n[r]=e[r]);return n}},{key:"getBondNeighbourIds",value:function(t,e){var n=t.bonds.get(e),r=n.begin,o=n.end,i=at.getConnectedBondIds(t,r).filter((function(t){return t!==e})),a=at.getConnectedBondIds(t,o).filter((function(t){return t!==e}));return{beginBondIds:i,endBondIds:a}}},{key:"getFusingConditions",value:function(t,e,n){var r=this.PATTERN.TYPE,o=r.DOUBLE,i=r.SINGLE,a=e.type===i&&t.type===o&&n.type===i;return{isFusingToSingleBond:e.type===o&&t.type===i&&n.type===o,isFusingToDoubleBond:a,isFusingDoubleSingleSingle:e.type===o&&t.type===i&&n.type===i,isFusingSingleSingleDouble:e.type===i&&t.type===i&&n.type===o,isAllSingle:e.type===i&&t.type===i&&n.type===i}}},{key:"getBenzeneConnectingBondType",value:function(e,n,r){var o=this.PATTERN.TYPE,i=o.DOUBLE,a=o.SINGLE,s=t.getFusingConditions(e,n,r),u=s.isFusingToSingleBond;return s.isFusingToDoubleBond?i:u?a:null}},{key:"getCyclopentadieneFusingBondType",value:function(e,n,r){var o=this.PATTERN.TYPE,i=o.DOUBLE,a=o.SINGLE,s=t.getFusingConditions(e,n,r),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,r){var o=t.getFusingConditions(e,n,r),i=o.isFusingToSingleBond,a=o.isFusingToDoubleBond,s=o.isFusingDoubleSingleSingle;return i||a?[1]:s?[2,3]:[1,4]}},{key:"attrGetDefault",value:function(e){if(e in t.attrlist)return t.attrlist[e]}}]),t}();function ht(t,e,n){!function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t,e),e.set(t,n)}function ft(t,e){if(e&&0!==e.length){var n=e.map((function(e){return t.atoms.get(e)})).filter((function(t){return null==t?void 0:t.stereoLabel}));if(n.length){var r,o=n[0].stereoLabel;if(n.some((function(t){return(null==t?void 0:t.stereoLabel)!==o})))r=ct.Mixed;else{var i,a=null===(i=o.match(/\D+/g))||void 0===i?void 0:i[0];switch(a){case J.Abs:r=ct.Abs;break;case J.And:r=ct.And;break;case J.Or:r=ct.Or;break;default:throw new Error("Unsupported stereo label: ".concat(a,"."))}}return r}}}ot=dt,(0,a.Z)(dt,"PATTERN",{TYPE:{SINGLE:1,DOUBLE:2,TRIPLE:3,AROMATIC:4,SINGLE_OR_DOUBLE:5,SINGLE_OR_AROMATIC:6,DOUBLE_OR_AROMATIC:7,ANY:8,DATIVE:9,HYDROGEN:10},STEREO:{NONE:0,UP:1,EITHER:4,DOWN:6,CIS_TRANS:3},TOPOLOGY:{EITHER:0,RING:1,CHAIN:2},REACTING_CENTER:{NOT_CENTER:-1,UNMARKED:0,CENTER:1,UNCHANGED:2,MADE_OR_BROKEN:4,ORDER_CHANGED:8,MADE_OR_BROKEN_AND_CHANGED:12}}),(0,a.Z)(dt,"attrlist",{type:ot.PATTERN.TYPE.SINGLE,stereo:ot.PATTERN.STEREO.NONE,topology:ot.PATTERN.TOPOLOGY.EITHER,reactingCenterStatus:ot.PATTERN.REACTING_CENTER.UNMARKED,cip:null}),function(t){t.Mixed="MIXED",t.Abs="ABS",t.And="AND",t.Or="OR"}(ct||(ct={}));var pt=new WeakMap,mt=new WeakMap,vt=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0;(0,o.Z)(this,t),ht(this,pt,{writable:!0,value:void 0}),ht(this,mt,{writable:!0,value:void 0}),n&&(this.stereoFlagPosition=new $(n)),r&&(this.properties=r),(0,g.Z)(this,mt,e)}return(0,i.Z)(t,[{key:"stereoAtoms",get:function(){return(0,h.Z)((0,y.Z)(this,mt))}},{key:"enhancedStereoFlag",get:function(){return(0,y.Z)(this,pt)}},{key:"clone",value:function(e){var n=new t((0,y.Z)(this,mt).map((function(t){return e.get(t)})),this.stereoFlagPosition,this.properties);return(0,g.Z)(n,pt,(0,y.Z)(this,pt)),n}},{key:"updateStereoFlag",value:function(t){return(0,g.Z)(this,pt,ft(t,this.stereoAtoms)),(0,y.Z)(this,pt)}},{key:"updateStereoAtom",value:function(t,e,n,r){var o;r&&!(0,y.Z)(this,mt).includes(e)&&(0,y.Z)(this,mt).push(e),r||(null===(o=t.atoms.get(e))||void 0===o?void 0:o.fragment)===n&&Array.from(t.bonds.values()).filter((function(t){return t.stereo&&t.type!==dt.PATTERN.TYPE.DOUBLE})).some((function(t){return t.begin===e}))||(0,g.Z)(this,mt,this.stereoAtoms.filter((function(t){return t!==e}))),(0,g.Z)(this,pt,ft(t,this.stereoAtoms))}},{key:"addStereoAtom",value:function(t){return!(0,y.Z)(this,mt).includes(t)&&(this.stereoAtoms.push(t),!0)}},{key:"deleteStereoAtom",value:function(t,e,n){var r;return!((null===(r=t.atoms.get(n))||void 0===r?void 0:r.fragment)===e&&Array.from(t.bonds.values()).filter((function(t){return t.stereo&&t.type!==dt.PATTERN.TYPE.DOUBLE})).some((function(t){return t.begin===n}))||((0,g.Z)(this,mt,(0,y.Z)(this,mt).filter((function(t){return t!==n}))),0))}}],[{key:"getDefaultStereoFlagPosition",value:function(t,e){var n=t.getFragment(e);if(n){var r=n.getCoordBoundingBox();return new $(r.max.x,r.min.y-1)}}}]),t}(),gt={scaled2obj:function(t,e){return t.scaled(1/e.scale)},obj2scaled:function(t,e){return t.scaled(e.scale)}},yt={isCorrectStereoCenter:function(t,e,n,r){var o,i=r.atoms.get(t.begin),a=NaN;return 2===(null==n?void 0:n.length)&&(a=n[0].aid===t.begin?n[1].aid:n[0].aid),t.stereo>0&&(1!==(null==n?void 0:n.length)||2!==(null==e?void 0:e.length)||Number(null==i?void 0:i.implicitH)%2!=0)&&(2!==(null==n?void 0:n.length)||2!==(null==e?void 0:e.length)||Number(null==i?void 0:i.implicitH)%2!=0||1!==(null===(o=r.atomGetNeighbors(a))||void 0===o?void 0:o.length))&&1!==(null==e?void 0:e.length)}},bt=function(){function t(){(0,o.Z)(this,t),this.functionalGroupsList=[]}return(0,i.Z)(t,[{key:"getFunctionalGroupsList",value:function(){return this.functionalGroupsList}},{key:"setFunctionalGroupsList",value:function(t){this.functionalGroupsList=t}},{key:"addToFunctionalGroupsList",value:function(t){this.functionalGroupsList=[].concat((0,h.Z)(this.functionalGroupsList),(0,h.Z)(t))}}],[{key:"getInstance",value:function(){return t.instance||(t.instance=new t),t.instance}}]),t}(),wt=function(){function t(){(0,o.Z)(this,t),this.saltsAndSolventsList=[]}return(0,i.Z)(t,[{key:"getSaltsAndSolventsList",value:function(){return this.saltsAndSolventsList}},{key:"setSaltsAndSolventsList",value:function(t){this.saltsAndSolventsList=t}}],[{key:"getInstance",value:function(){return t.instance||(t.instance=new t),t.instance}}]),t}();function xt(t,e,n){return function(t,e){if(t!==e)throw new TypeError("Private static access of wrong provenance")}(t,e),n}var Et=function(){function t(){(0,o.Z)(this,t);for(var e=arguments.length,n=new Array(e),r=0;r1&&void 0!==arguments[1]?arguments[1]:0;return u()(null!=t),t.x>=this.p0.x-e&&t.x<=this.p1.x+e&&t.y>=this.p0.y-e&&t.y<=this.p1.y+e}},{key:"translate",value:function(e){return new t(this.p0.add(e),this.p1.add(e))}},{key:"transform",value:function(e,n){return u()("function"==typeof e),new t(e(this.p0,n),e(this.p1,n))}},{key:"sz",value:function(){return this.p1.sub(this.p0)}},{key:"centre",value:function(){return $.centre(this.p0,this.p1)}},{key:"pos",value:function(){return this.p0}}],[{key:"fromRelBox",value:function(e){return new t(e.x,e.y,e.x+e.width,e.y+e.height)}},{key:"union",value:function(e,n){return new t($.min(e.p0,n.p0),$.max(e.p1,n.p1))}},{key:"segmentIntersection",value:function(e,n,r,o){var i=(e.x-r.x)*(n.y-r.y)-(e.y-r.y)*(n.x-r.x),a=(e.x-o.x)*(n.y-o.y)-(e.y-o.y)*(n.x-o.x),s=(r.x-e.x)*(o.y-e.y)-(r.y-e.y)*(o.x-e.x),u=(r.x-n.x)*(o.y-n.y)-(r.y-n.y)*(o.x-n.x);return 0===i&&0===a&&0===s&&0===u?xt(t,t,Pt).call(t,e,n,r)||xt(t,t,Pt).call(t,e,n,o)||xt(t,t,Pt).call(t,r,o,e)||xt(t,t,Pt).call(t,r,o,n):i*a<0&&s*u<0}}]),t}();function Pt(t,e,n){var r=Math.min(t.x,e.x),o=Math.max(t.x,e.x),i=Math.min(t.y,e.y),a=Math.max(t.y,e.y);return n.x>=r&&n.x<=o&&n.y>=i&&n.y<=a}var Ot,At,Rt={Fragment:"Fragment",Multifragment:"Multifragment",Bond:"Bond",Atom:"Atom",Group:"Group"},St=["atoms","bonds","frags","sgroups","rgroups","rgroupAttachmentPoints","rxnArrows","rxnPluses","simpleObjects","texts"],Tt=2;function kt(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return Bt(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Bt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}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(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function Bt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n=1}},{key:"addAttachmentPoint",value:function(t){var e=this.attachmentPoints.some((function(e){var n=e.atomId;return t.atomId===n}));if(e)throw new Error("The same attachment point cannot be added to an S-group more than once");this.attachmentPoints.push(t)}},{key:"addAttachmentPoints",value:function(t){var e,n=kt(t);try{for(n.s();!(e=n.n()).done;){var r=e.value;this.addAttachmentPoint(r)}}catch(t){n.e(t)}finally{n.f()}}},{key:"removeAttachmentPoint",value:function(t){var e=this.attachmentPoints.findIndex((function(e){var n=e.atomId;return t===n}));return-1!==e&&(this.attachmentPoints.splice(e,1),!0)}},{key:"getAttachmentPoints",value:function(){return this.attachmentPoints}},{key:"getConnectionPointsCount",value:function(t){var e,n=new Set,r=kt(this.atoms);try{for(r.s();!(e=r.n()).done;){var o,i,a=e.value,s=kt(null!==(o=t.atomGetNeighbors(a))&&void 0!==o?o:[]);try{for(s.s();!(i=s.n()).done;){var u=i.value.aid;if(!this.atoms.includes(u)){n.add(a);break}}}catch(t){s.e(t)}finally{s.f()}}}catch(t){r.e(t)}finally{r.f()}return n.size}},{key:"isNotContractible",value:function(t){return this.getConnectionPointsCount(t)>1}},{key:"getAttachmentAtomId",value:function(){var t;return null===(t=this.attachmentPoints[0])||void 0===t?void 0:t.atomId}},{key:"getContractedPosition",value:function(t){var e,n=null===(e=this.attachmentPoints[0])||void 0===e?void 0:e.atomId,r=t.atoms.get(n);return r||(n=this.atoms[0],r=t.atoms.get(this.atoms[0])),u()(null!=r),{atomId:n,position:r.pp}}},{key:"cloneAttachmentPoints",value:function(t){return this.attachmentPoints.map((function(e){return e.clone(t)}))}}],[{key:"getOffset",value:function(t){return null!=t&&t.pp?$.diff(t.pp,t.bracketBox.p1):null}},{key:"isSaltOrSolvent",value:function(t){return wt.getInstance().getSaltsAndSolventsList().some((function(e){var n=e.name,r=e.abbreviation;return n===t||t===r}))}},{key:"isAtomInSaltOrSolvent",value:function(t,e){var n=this;return e.filter((function(t){return n.isSaltOrSolvent(t.data.name)})).some((function(e){return e.atoms.some((function(e){return e===t}))}))}},{key:"isBondInSaltOrSolvent",value:function(t,e){var n=this;return e.filter((function(t){return n.isSaltOrSolvent(t.data.name)})).some((function(e){return e.bonds.some((function(e){return e===t}))}))}},{key:"filterAtoms",value:function(t,e){for(var n=[],r=0;r=0?n.push(e[o]):n.push(-1)}return n}},{key:"removeNegative",value:function(t){for(var e=[],n=0;n=0&&e.push(t[n]);return e}},{key:"filter",value:function(e,n,r){n.atoms=t.removeNegative(t.filterAtoms(n.atoms,r))}},{key:"clone",value:function(e,n){var r=new t(e.type);return Object.keys(e.data).forEach((function(t){r.data[t]=e.data[t]})),r.atoms=e.atoms.map((function(t){return n.get(t)})),r.pp=e.pp,r.bracketBox=e.bracketBox,r.patoms=null,r.bonds=null,r.allAtoms=e.allAtoms,r.data.expanded=e.data.expanded,r.addAttachmentPoints(e.cloneAttachmentPoints(n)),r}},{key:"addAtom",value:function(t,e,n){t.atoms.push(e),t.isNotContractible(n)&&t.setAttr("expanded",!0)}},{key:"removeAtom",value:function(t,e){if(t)for(var n=0;n=0&&r.indexOf(t.end)>=0&&o.push(e)})),o}},{key:"prepareMulForSaving",value:function(t,e){t.atoms.sort((function(t,e){return t-e})),t.atomSet=new et(t.atoms),t.parentAtomSet=new et(t.atomSet);var n=[],r=[];if(e.bonds.forEach((function(e,o){t.parentAtomSet.has(e.begin)&&t.parentAtomSet.has(e.end)?n.push(o):(t.parentAtomSet.has(e.begin)||t.parentAtomSet.has(e.end))&&r.push(o)})),0!==r.length&&2!==r.length)throw Error("Unsupported cross-bonds number");var o=-1,i=-1,a=null;if(2===r.length){var s=e.bonds.get(r[0]);o=t.parentAtomSet.has(s.begin)?s.begin:s.end;var u=e.bonds.get(r[1]);i=t.parentAtomSet.has(u.begin)?u.begin:u.end,a=u}for(var l=i,c=[],d=function(){var r={};if(t.atoms.forEach((function(n){var o=e.atoms.get(n),i=e.atoms.add(new at(o));c.push(i),t.atomSet.add(i),r[n]=i})),n.forEach((function(t){var n=e.bonds.get(t),o=new dt(n);o.begin=r[o.begin],o.end=r[o.end],e.bonds.add(o)})),null!==a){var s=new dt(a);s.begin=l,s.end=r[o],e.bonds.add(s),l=r[i]}},h=0;h=0){var f=e.bonds.get(r[1]);f.begin===i?f.begin=l:f.end=l}t.bonds=r,c.forEach((function(n){e.sGroupForest.getPathToRoot(t.id).reverse().forEach((function(t){e.atomAddToSGroup(t,n)}))}))}},{key:"getMassCentre",value:function(t,e){for(var n=new $,r=0;r=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}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(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function Nt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n0;){var n=e.shift();if("number"!=typeof n)break;var r=this.children.get(n);if(void 0===r)break;r.forEach((function(t){e.push(t)})),t.push(n)}return t}},{key:"getAtomSetRelations",value:function(t,e){var n=this,r=new Map,o=new Map;this.atomSets.delete(t),this.atomSets.forEach((function(t,n){o.set(n,t.isSuperset(e)),r.set(n,e.isSuperset(t)&&!t.equals(e))}));var i=Array.from(this.atomSets.keys()).filter((function(t){if(!o.get(t))return!1;var e=n.children.get(t);return e&&e.findIndex((function(t){return o.get(t)}))<0})),a=Array.from(this.atomSets.keys()).filter((function(t){return r.get(t)&&!r.get(n.parent.get(t))}));return{children:a,parent:0===i.length?-1:i[0]}}},{key:"getPathToRoot",value:function(t){for(var e=[],n=t;n>=0;n=this.parent.get(n))e.push(n);return e}},{key:"insert",value:function(t,e,n){var r,o=this,i=t.id,a=t.atoms;if(u()(!this.parent.has(i),"sgid already present in the forest"),u()(!this.children.has(i),"sgid already present in the forest"),!e||!n){var s=this.getAtomSetRelations(i,new et(a));e=s.parent,n=s.children}return n.forEach((function(t){o.resetParentLink(t,i)})),this.children.set(i,n.filter((function(t){return o.parent.get(t)}))),this.parent.set(i,e),null===(r=this.children.get(e))||void 0===r||r.push(i),this.atomSets.set(i,new et(a)),{parent:e,children:n}}},{key:"resetParentLink",value:function(t,e){var n=this.parent.get(t);if(void 0!==n){var r=this.children.get(n);if(r){var o=r.indexOf(t);r.splice(o,1),this.parent.set(t,e)}}}},{key:"remove",value:function(t){var e,n=this;try{u()(this.parent.has(t),"sgid is not in the forest"),u()(this.children.has(t),"sgid is not in the forest")}catch(t){}var r=this.parent.get(t),o=this.children.get(r);if(r&&o){null===(e=this.children.get(t))||void 0===e||e.forEach((function(t){var e;n.parent.set(t,r),null===(e=n.children.get(r))||void 0===e||e.push(t)}));var i=o.indexOf(t);o.splice(i,1),this.children.delete(t),this.parent.delete(t),this.atomSets.delete(t)}}}]),t}();function Yt(t,e){var n=e.reduce((function(e,n){var r=t.atoms.get(n);return e.union(r.sgs)}),new et);return Array.from(n).some((function(n){var r=t.sgroups.get(n);if("DAT"===r.type)return!1;var o=Zt.getAtoms(t,r);return o.length=0:e.findIndex((function(t){return-1===o.indexOf(t)}))>=0}))}!function(t){t.ellipse="ellipse",t.rectangle="rectangle",t.line="line"}(zt||(zt={}));var qt=function(){function t(e){if((0,o.Z)(this,t),this.pos=[],null!=e&&e.pos)for(var n=0;n=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}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(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function Xt(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n=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 t=this.sgroups.values().next().value;return this.atoms.size===t.atoms.length}},{key:"clone",value:function(e,n,r,o,i,a,s){return this.mergeInto(new t,e,n,r,!1,o,i,a,s)}},{key:"getScaffold",value:function(){var t=this,e=new et;return this.atoms.forEach((function(t,n){e.add(n)})),this.rgroups.forEach((function(n){n.frags.forEach((function(n,r){t.atoms.forEach((function(t,n){t.fragment===r&&e.delete(n)}))}))})),this.clone(e)}},{key:"getFragmentIds",value:function(t){var e=new et;return this.atoms.forEach((function(n,r){n.fragment===t&&e.add(r)})),e}},{key:"getFragment",value:function(t){return this.clone(this.getFragmentIds(t),null,!0)}},{key:"mergeInto",value:function(t,e,n,r,o,i,a,s,l){var c=this;e=e||new et(this.atoms.keys()),n=n||new et(this.bonds.keys()),a=a||new et(this.simpleObjects.keys()),s=s||new et(this.texts.keys()),l=l||new et(this.rgroupAttachmentPoints.keys()),i=i||new Map,n=n.filter((function(t){var n=c.bonds.get(t);return e.has(n.begin)&&e.has(n.end)}));var d=new et;this.atoms.forEach((function(t,n){e.has(n)&&d.add(t.fragment)}));var h=new Map;this.frags.forEach((function(e,n){d.has(n)&&h.set(n,t.frags.add(null))}));var f=[];this.rgroups.forEach((function(e,n){var r=o;if(r||(e.frags.forEach((function(t,e){f.push(e),d.has(e)&&(r=!0)})),r)){var i=t.rgroups.get(n);i?e.frags.forEach((function(t,e){f.push(e),d.has(e)&&i.frags.add(h.get(e))})):t.rgroups.set(n,e.clone(h))}})),this.atoms.forEach((function(n,r){e.has(r)&&-1===f.indexOf(n.fragment)&&i.set(r,t.atoms.add(n.clone(h)))})),this.atoms.forEach((function(n,r){e.has(r)&&-1!==f.indexOf(n.fragment)&&i.set(r,t.atoms.add(n.clone(h)))})),h.forEach((function(e,n){var r=c.frags.get(n);r&&r instanceof vt&&t.frags.set(e,c.frags.get(n).clone(i))}));var p=new Map;return this.bonds.forEach((function(e,r){n.has(r)&&p.set(r,t.bonds.add(e.clone(i)))})),this.sgroups.forEach((function(n){if(!n.atoms.some((function(t){return!e.has(t)}))){n=Zt.clone(n,i);var r=t.sgroups.add(n);n.id=r,n.atoms.forEach((function(e){var n=t.atoms.get(e);n&&n.sgs.add(r)})),"DAT"===n.type?t.sGroupForest.insert(n,-1,[]):t.sGroupForest.insert(n)}})),this.functionalGroups.forEach((function(e){e=Lt.clone(e),t.functionalGroups.add(e)})),a.forEach((function(e){t.simpleObjects.add(c.simpleObjects.get(e).clone())})),s.forEach((function(e){t.texts.add(c.texts.get(e).clone())})),l.forEach((function(e){var n=c.rgroupAttachmentPoints.get(e);u()(null!=n),t.rgroupAttachmentPoints.add(n.clone(i))})),r||(t.isReaction=this.isReaction,this.rxnArrows.forEach((function(e){t.rxnArrows.add(e.clone())})),this.rxnPluses.forEach((function(e){t.rxnPluses.add(e.clone())}))),t.name=this.name,t}},{key:"prepareLoopStructure",value:function(){this.initHalfBonds(),this.initNeighbors(),this.updateHalfBonds(Array.from(this.atoms.keys())),this.sortNeighbors(Array.from(this.atoms.keys())),this.findLoops()}},{key:"atomAddToSGroup",value:function(t,e){Zt.addAtom(this.sgroups.get(t),e,this),this.atoms.get(e).sgs.add(t)}},{key:"calcConn",value:function(t){for(var e=0,n=0;n1e-4?o:new $(1,0),e.norm=e.dir.turnLeft(),e.ang=e.dir.oxAngle(),e.loop<0&&(e.loop=-1)}},{key:"initHalfBonds",value:function(){var t=this;this.halfBonds.clear(),this.bonds.forEach((function(e,n){t.bondInitHalfBonds(n,e)}))}},{key:"setHbNext",value:function(t,e){this.halfBonds.get(this.halfBonds.get(t).contra).next=e}},{key:"halfBondSetAngle",value:function(t,e){var n=this.halfBonds.get(t),r=this.halfBonds.get(e);r.rightCos=$.dot(r.dir,n.dir),n.leftCos=$.dot(r.dir,n.dir),r.rightSin=$.cross(r.dir,n.dir),n.leftSin=$.cross(r.dir,n.dir),n.leftNeighbor=e,r.rightNeighbor=t}},{key:"atomAddNeighbor",value:function(t){var e,n=this.halfBonds.get(t),r=this.atoms.get(n.begin);for(e=0;en.ang);++e);r.neighbors.splice(e,0,t);var o=r.neighbors[(e+1)%r.neighbors.length],i=r.neighbors[(e+r.neighbors.length-1)%r.neighbors.length];this.setHbNext(i,t),this.setHbNext(t,o),this.halfBondSetAngle(t,i),this.halfBondSetAngle(o,t)}},{key:"atomSortNeighbors",value:function(t){var e=this,n=this.atoms.get(t),r=this.halfBonds;n.neighbors.sort((function(t,e){return r.get(t).ang-r.get(e).ang})).forEach((function(t,r){var o=n.neighbors[(r+1)%n.neighbors.length];e.halfBonds.get(e.halfBonds.get(t).contra).next=o,e.halfBondSetAngle(o,t)}))}},{key:"sortNeighbors",value:function(t){var e=this;t?t.forEach((function(t){e.atomSortNeighbors(t)})):this.atoms.forEach((function(t,n){e.atomSortNeighbors(n)}))}},{key:"atomUpdateHalfBonds",value:function(t){var e=this;this.atoms.get(t).neighbors.forEach((function(t){e.halfBondUpdate(t),e.halfBondUpdate(e.halfBonds.get(t).contra)}))}},{key:"updateHalfBonds",value:function(t){var e=this;t?t.forEach((function(t){e.atomUpdateHalfBonds(t)})):this.atoms.forEach((function(t,n){e.atomUpdateHalfBonds(n)}))}},{key:"sGroupsRecalcCrossBonds",value:function(){var t=this;this.sgroups.forEach((function(t){t.xBonds=[],t.neiAtoms=[]})),this.bonds.forEach((function(e,n){var r=t.atoms.get(e.begin),o=t.atoms.get(e.end);r.sgs.forEach((function(r){if(!o.sgs.has(r)){var i=t.sgroups.get(r);i.xBonds.push(n),Qt(i.neiAtoms,e.end)}})),o.sgs.forEach((function(o){if(!r.sgs.has(o)){var i=t.sgroups.get(o);i.xBonds.push(n),Qt(i.neiAtoms,e.begin)}}))}))}},{key:"sGroupDelete",value:function(t){var e=this;this.sgroups.get(t).atoms.forEach((function(n){e.atoms.get(n).sgs.delete(t)})),this.sGroupForest.remove(t),this.sgroups.delete(t)}},{key:"atomSetPos",value:function(t,e){this.atoms.get(t).pp=e}},{key:"rxnPlusSetPos",value:function(t,e){this.rxnPluses.get(t).pp=e}},{key:"rxnArrowSetPos",value:function(t,e){var n=this.rxnArrows.get(t);n&&(n.pos=e)}},{key:"simpleObjectSetPos",value:function(t,e){this.simpleObjects.get(t).pos=e}},{key:"textSetPosition",value:function(t,e){var n=this.texts.get(t);n&&(n.position=e)}},{key:"getCoordBoundingBox",value:function(t){var e=null;function n(t){e?t instanceof Array?t.forEach((function(t){e.min=$.min(e.min,t),e.max=$.max(e.max,t)})):(e.min=$.min(e.min,t),e.max=$.max(e.max,t)):e={min:t,max:t}}var r=!t||0===t.size;return this.atoms.forEach((function(e,o){(r||t.has(o))&&n(e.pp)})),r&&(this.rxnPluses.forEach((function(t){n(t.pp)})),this.rxnArrows.forEach((function(t){n(t.pos)})),this.simpleObjects.forEach((function(t){n(t.pos)})),this.texts.forEach((function(t){n(t.position)}))),!e&&r&&(e={min:new $(0,0),max:new $(1,1)}),e}},{key:"getCoordBoundingBoxObj",value:function(){var t=null;return this.atoms.forEach((function(e){var n;n=e.pp,t?(t.min=$.min(t.min,n),t.max=$.max(t.max,n)):t={min:new $(n),max:new $(n)}})),t}},{key:"getBondLengthData",value:function(){var t=this,e=0,n=0;return this.bonds.forEach((function(r){e+=$.dist(t.atoms.get(r.begin).pp,t.atoms.get(r.end).pp),n++})),{cnt:n,totalLength:e}}},{key:"getAvgBondLength",value:function(){var t=this.getBondLengthData();return t.cnt>0?t.totalLength/t.cnt:-1}},{key:"getAvgClosestAtomDistance",value:function(){var t,e,n,r=0,o=0,i=Array.from(this.atoms.keys());for(e=0;eo)&&(t=o));r+=t}return i.length>0?r/i.length:-1}},{key:"checkBondExists",value:function(t,e){return void 0!==this.bonds.find((function(n,r){return r.begin===t&&r.end===e||r.end===t&&r.begin===e}))}},{key:"findConnectedComponent",value:function(t){for(var e=this,n=[t],r=new et;n.length>0;){var o=n.pop();r.add(o),this.atoms.get(o).neighbors.forEach((function(t){var o=e.halfBonds.get(t).end;r.has(o)||n.push(o)}))}return r}},{key:"findConnectedComponents",value:function(t){var e=this;this.halfBonds.size||(this.initHalfBonds(),this.initNeighbors(),this.updateHalfBonds(Array.from(this.atoms.keys())),this.sortNeighbors(Array.from(this.atoms.keys())));var n=new et,r=[];return this.atoms.forEach((function(o,i){if((t||o.fragment<0)&&!n.has(i)){var a=e.findConnectedComponent(i);r.push(a),n=n.union(a)}})),r}},{key:"markFragment",value:function(t,e){var n=this,r=new vt([],void 0,e),o=this.frags.add(r);t.forEach((function(t){var e=n.atoms.get(t);e.stereoLabel&&r.updateStereoAtom(n,t,o,!0),e.fragment=o}))}},{key:"markFragments",value:function(t){var e=this;this.findConnectedComponents().forEach((function(n){e.markFragment(n,t)}))}},{key:"scale",value:function(t){var e=this;1!==t&&(this.atoms.forEach((function(e){e.pp=e.pp.scaled(t)})),this.rxnPluses.forEach((function(e){e.pp=e.pp.scaled(t)})),this.rxnArrows.forEach((function(e){e.pos=e.pos.map((function(e){return e.scaled(t)}))})),this.sgroups.forEach((function(e){e.pp=e.pp?e.pp.scaled(t):null})),this.texts.forEach((function(n){e.rxnArrows.size&&(n.pos=n.pos.map((function(e){return e.scaled(t)})),n.position=n.position.scaled(t))})))}},{key:"rescale",value:function(){var t=this.getAvgBondLength();t<0&&!this.isReaction&&(t=this.getAvgClosestAtomDistance()),t<.001&&(t=1);var e=1/t;this.scale(e)}},{key:"loopHasSelfIntersections",value:function(t){for(var e=0;e0&&t===s){r.partitionLoop(n).forEach((function(t){var e;r.loopIsInner(t)&&!r.loopHasSelfIntersections(t)?(e=Math.min.apply(Math,(0,h.Z)(t)),r.loops.set(e,new Ft(t,r,r.loopIsConvex(t)))):e=-2,t.forEach((function(t){r.halfBonds.get(t).loop=e,i.add(r.halfBonds.get(t).bid)})),e>=0&&o.push(e)}));break}n.push(t)}})),{newLoops:o,bondsToMark:Array.from(i)}}},{key:"calcImplicitHydrogen",value:function(t){var e=this.atoms.get(t),n=this.calcConn(e),o=(0,r.Z)(n,2),i=o[0],a=o[1],s=i;if(e.badConn=!1,a)if("C"===e.label&&0===e.charge){if(3===i)return void(e.implicitH=-st(e.radical));if(2===i)return void(e.implicitH=1-st(e.radical))}else{if("O"===e.label&&0===e.charge||"N"===e.label&&0===e.charge&&3===i||"N"===e.label&&1===e.charge&&3===i||"S"===e.label&&0===e.charge&&3===i)return void(e.implicitH=0);e.hasImplicitH||s++}if(s<0||e.isQuery())e.implicitH=0;else if(e.explicitValence>=0){var u=_.get(e.label);e.implicitH=u?e.explicitValence-e.calcValenceMinusHyd(s):0,e.implicitH<0&&(e.implicitH=0,e.badConn=!0)}else e.calcValence(s)}},{key:"setImplicitHydrogen",value:function(t){var e=this;this.sgroups.forEach((function(t){"MRV_IMPLICIT_H"===t.data.fieldName&&(e.atoms.get(t.atoms[0]).hasImplicitH=!0)})),t?t.forEach((function(t){e.atoms.get(t)&&e.calcImplicitHydrogen(t)})):this.atoms.forEach((function(t,n){e.calcImplicitHydrogen(n)}))}},{key:"atomGetNeighbors",value:function(t){var e,n=this;return null===(e=this.atoms.get(t))||void 0===e?void 0:e.neighbors.map((function(t){var e=n.halfBonds.get(t);return{aid:e.end,bid:e.bid}}))}},{key:"getComponents",value:function(){var t=this,e=this.findConnectedComponents(!0),n=[],r=null;this.rxnArrows.forEach((function(t){r=t.center().x})),this.rxnPluses.forEach((function(t){n.push(t.pp.x)})),null!==r&&n.push(r),n.sort((function(t,e){return t-e}));var o=[];e.forEach((function(e){for(var r=t.getCoordBoundingBox(e),i=$.lc2(r.min,.5,r.max,.5),a=0;i.x>n[a];)++a;o[a]=o[a]||new et,o[a]=o[a].union(e)}));var i=[],a=[];return o.forEach((function(e){e&&(1===t.defineRxnFragmentTypeForAtomset(e,r||0)?i.push(e):a.push(e))})),{reactants:i,products:a}}},{key:"defineRxnFragmentTypeForAtomset",value:function(t,e){var n=this.getCoordBoundingBox(t);return $.lc2(n.min,.5,n.max,.5).x1&&void 0!==arguments[1]?arguments[1]:0,n={};return G(n,"type",t.type),G(n,"topology",t.topology),G(n,"reactingCenterStatus",t.center),G(n,"stereo",t.stereo),G(n,"cip",t.cip),G(n,"begin",t.atoms[0]+e),G(n,"end",t.atoms[1]+e),new dt(n)}function fe(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}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(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}(t.rgroups.entries());try{for(i.s();!(e=i.n()).done;){var a=(0,r.Z)(e.value,2),s=a[0],u=a[1];u.frags.forEach((function(t){return o.add(t)}));var l=Array.from(u.frags.values()).reduce((function(e,n){return e.union(t.getFragmentIds(n))}),new et);n.push({type:"rgroup",fragment:t.clone(l),center:me(t,l),data:{rgnumber:s,rgroup:u}})}}catch(t){i.e(t)}finally{i.f()}var c=Array.from(t.frags.keys()).filter((function(t){return!o.has(t)}));return function(t,e,n){var r=function(t,e,n){var r=new Map;return e.forEach((function(e){var o=n.getFragmentIds(e),i=!1;o.forEach((function(t){var o;null===(o=n.atoms.get(t))||void 0===o||o.sgs.forEach((function(t){i=!0;var n=r.get(t);n?n.add(e):r.set(t,new et([e]))}))})),i||t.push({type:"molecule",fragment:n.clone(o),center:me(n,o)})})),r}(t,e,n);et.unionIntersections(Array.from(r.values())).forEach((function(e){var r=new et;e.forEach((function(t){r=r.union(n.getFragmentIds(t))})),t.push({type:"molecule",fragment:n.clone(r),center:me(n,r)})}))}(n,c,t),t.rxnArrows.forEach((function(t){n.push({type:"arrow",center:t.pos[0],data:{mode:t.mode,pos:t.pos,height:t.height}})})),t.rxnPluses.forEach((function(t){n.push({type:"plus",center:t.pp,data:{}})})),t.simpleObjects.forEach((function(t){n.push({type:"simpleObject",center:t.pos[0],data:{mode:t.mode,pos:t.pos}})})),t.texts.forEach((function(t){n.push({type:"text",center:t.position,data:{content:t.content,position:t.position,pos:t.pos}})})),n.forEach((function(t){if(t.fragment){var e=Array.from(t.fragment.sgroups.values()).filter((function(t){return t.atoms.every((function(t){return void 0!==t}))})),n=new Kt;e.forEach((function(t,e){n.set(e,t)})),t.fragment.sgroups=n}})),n}function me(t,e){var n=t.getCoordBoundingBox(e);return $.centre(n.min,n.max)}function ve(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function ge(t){for(var e=1;ee)throw new Error("number does not fit");return r.padStart(e)},parseDecimalInt:function(t){var e=parseInt(t,10);return isNaN(e)?0:e},partitionLine:function(t,e,n){for(var r=[],o=0,i=0;o=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}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(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function Ae(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n=0);var b=Pe.parseDecimalInt(v),w=b>0?b-1:void 0;c.push(new re(y,w,g))}return{sGroupId:s,attachmentPoints:c}}};function Ve(t){var e=Pe.partitionLine(t,Pe.fmtInfo.atomLinePartition),n={pp:new $(parseFloat(e[0]),-parseFloat(e[1]),parseFloat(e[2])),label:e[4].trim(),explicitValence:Pe.fmtInfo.valenceMap[Pe.parseDecimalInt(e[10])],massDifference:Pe.parseDecimalInt(e[5]),charge:Pe.fmtInfo.chargeMap[Pe.parseDecimalInt(e[6])],hCount:Pe.parseDecimalInt(Pe.parseDecimalInt(e[8])),stereoCare:0!==Pe.parseDecimalInt(e[9]),aam:Pe.parseDecimalInt(e[14]),invRet:Pe.parseDecimalInt(e[15]),exactChangeFlag:Pe.parseDecimalInt(e[16])};return new at(n)}function We(t){var e=Pe.partitionLine(t,Pe.fmtInfo.bondLinePartition),n={begin:Pe.parseDecimalInt(e[0])-1,end:Pe.parseDecimalInt(e[1])-1,type:Pe.fmtInfo.bondTypeMap[Pe.parseDecimalInt(e[2])],stereo:Pe.fmtInfo.bondStereoMap[Pe.parseDecimalInt(e[3])],xxx:e[4],topology:Pe.fmtInfo.bondTopologyMap[Pe.parseDecimalInt(e[5])],reactingCenterStatus:Pe.parseDecimalInt(e[6])};return new dt(n)}function Ye(t){for(var e=Pe.partitionLine(t,Pe.fmtInfo.atomListHeaderPartition),n=Pe.parseDecimalInt(e[0])-1,r="T"===e[2].trim(),o=Pe.parseDecimalInt(e[4].trim()),i=t.slice(Pe.fmtInfo.atomListHeaderLength),a=[],s=Pe.fmtInfo.atomListHeaderItemLength,u=0;u0&&(A.ifthen=E),A.resth=1===P,A.range=O,i[x]=A}else if("APO"===m)a.get("attachmentPoints")||a.set("attachmentPoints",Ue.readKeyValuePairs(v));else if("ALS"===m){var R=(t=Pe.partitionLine(v,[1,3,3,1,1,1]),r=Pe.partitionLineFixed(v.slice(10),4,!1),s=Pe.parseDecimalInt(t[1])-1,u=Pe.parseDecimalInt(t[2]),l="T"===t[4].trim(),c=function(t){for(var e=[],n=0;n=0){var E=v[x-1];"GEN"===E.type&&(w.atoms=[].slice.call(E.atoms))}}}for(y in v)Ue.loadSGroup(o,v[y],b);var P=[];for(y in v)Zt.filter(o,v[y],b),0!==v[y].atoms.length||v[y].allAtoms||P.push(+y);for(r=0;r0&&"$MOL"===t[0].substr(0,4);){t=t.slice(1);for(var u=0;u0&&(f.ifthen=c),f.resth=1===d,f.range=h,r[i]=f,o++}}}Object.keys(n).forEach((function(e){n[e].forEach((function(n){n.rgroups.set(e,new Gt(r[e]));var o=n.frags.add({});n.rgroups.get(e).frags.add(o),n.atoms.forEach((function(t){t.fragment=o})),n.mergeInto(t)}))}))}function on(t){for(var e=[],n=0,r=0,o=-1,i=!1;ro+1&&e.push(t.slice(o+1,r)),o=r)}return r>o+1&&e.push(t.slice(o+1,r)),e}function an(t,e){var n=t.indexOf(e);return[t.slice(0,n),t.slice(n+1)]}function sn(t){for(var e=[],n=0,r=!1,o=0;o0&&e.push(t.trim()),e}function un(t,e){if(!t)return null;var n=[],r=(t=(t=t.trim()).substr(1,t.length-2)).split(" ");e=e||0;for(var o=1;o2?n[2]-0:0;function a(e){for(var n=e;n=0?Pe.paddedNum(i.nCharnCharsToDisplay,3):"ALL")+" 1 "+(i.tagChar||" ")+" "+Pe.paddedNum(i.daspPos,1)+" ";return s.push(c),(l=i.fieldValue,l.replace(vn,"\n")).replace(/\n*$/,"").split("\n").forEach((function(t){for(;t.length>69;)s.push("M SCD "+o+" "+t.slice(0,69)),t=t.slice(69);s.push("M SED "+o+" "+t)})),s.join("\n")},GEN:function(t,e,n,r,o){var i=(n[t.id]+"").padStart(3),a=[];return(a=(a=(a=a.concat(pn("SAL",i,t.atoms,r))).concat(pn("SBL",i,t.bonds,o))).concat(mn(e,t,i))).join("\n")}};function pn(t,e,n,r){if(!n)return[];for(var o=[],i=0;i1&&"V3000"===r[1])return cn.parseRxn3000(t,e);var o=Ke.parseRxn2000(t,e,n);return o.name=t[1].trim(),o},prepareForSaving:hn,saveToMolfile:fn},yn=function(){function t(){(0,o.Z)(this,t),this.molecule=null,this.molfile=null,this.reaction=!1,this.mapping={},this.bondMapping={}}return(0,i.Z)(t,[{key:"parseCTFile",value:function(t){var e,n=t.molfileLines,r=t.shouldReactionRelayout,o=t.ignoreChiralFlag;return(e=0===n[0].search("\\$RXN")?gn.parseRxn(n,r,o):gn.parseMol(n,o)).initHalfBonds(),e.initNeighbors(),e.bindSGroupsToFunctionalGroups(),e}},{key:"prepareSGroups",value:function(t,e){var n,r=this.molecule,o=[],i=0;if(null===(n=this.molecule)||void 0===n||n.sGroupForest.getSGroupsBFS().reverse().forEach((function(n){var a=r.sgroups.get(n),s=!1;try{gn.prepareForSaving[a.type](a,r)}catch(e){if(!t||"number"!=typeof e.id)throw new Error("Error: ".concat(e.message));s=!0}(s||!e&&/^INDIGO_.+_DESC$/i.test(a.data.fieldName))&&(i+=+s,o.push(a.id))}),this),i)throw new Error("Warning: "+i+" invalid S-groups were detected. They will be omitted.");for(var a=0;a0)throw new Error("Reactions with r-groups are not supported at the moment");var s=e.getComponents(),u=s.reactants,l=s.products,c=u.concat(l);this.molfile="$RXN\n"+e.name+"\n\n\n"+Pe.paddedNum(u.length,3)+Pe.paddedNum(l.length,3)+Pe.paddedNum(0,3)+"\n";for(var d=0;d0){if(!r){var m=(new t).getCTab(e.getScaffold(),e.rgroups);return this.molfile="$MDL REV 1\n$MOL\n$HDR\n"+e.name+"\n\n\n$END HDR\n",this.molfile+="$CTAB\n"+m+"$END CTAB\n",e.rgroups.forEach((function(n,r){a.molfile+="$RGP\n",a.writePaddedNumber(r,3),a.molfile+="\n",n.frags.forEach((function(n){var r=(new t).getCTab(e.getFragment(n));a.molfile+="$CTAB\n"+r+"$END CTAB\n"})),a.molfile+="$END RGP\n"})),this.molfile+="$END MOL\n",this.molfile}e=e.getScaffold()}return this.molecule=e.clone(),this.prepareSGroups(n,o),this.writeHeader(),this.writeCTab2000(void 0,i),this.molfile}},{key:"writeHeader",value:function(){var t=new Date;this.writeCR(),this.writeWhiteSpace(2),this.write("Ketcher"),this.writeWhiteSpace(),this.writeCR((t.getMonth()+1+"").padStart(2)+(t.getDate()+"").padStart(2)+(t.getFullYear()%100+"").padStart(2)+(t.getHours()+"").padStart(2)+(t.getMinutes()+"").padStart(2)+"2D 1 1.00000 0.00000 0"),this.writeCR()}},{key:"write",value:function(t){this.molfile+=t}},{key:"writeCR",value:function(t){0===arguments.length&&(t=""),this.molfile+=t+"\n"}},{key:"writeWhiteSpace",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;0===arguments.length&&(t=1),this.write(" ".repeat(Math.max(t,0)))}},{key:"writePadded",value:function(t,e){this.write(t),this.writeWhiteSpace(e-t.length)}},{key:"writePaddedNumber",value:function(t,e){var n=(t-0).toString();this.writeWhiteSpace(e-n.length),this.write(n)}},{key:"writePaddedFloat",value:function(t,e,n){this.write(Pe.paddedNum(t,e,n))}},{key:"writeCTab2000Header",value:function(t){this.writePaddedNumber(this.molecule.atoms.size,3),this.writePaddedNumber(this.molecule.bonds.size,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3);var e=Array.from(this.molecule.frags.values()).some((function(t){return!!t&&t.enhancedStereoFlag===ct.Abs}));this.writePaddedNumber(e||t?1:0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(0,3),this.writePaddedNumber(999,3),this.writeCR(" V2000")}},{key:"writeCTab2000",value:function(t,e){var n=this;this.writeCTab2000Header(e),this.mapping={};var r=1,o=[],i=[];for(this.molecule.atoms.forEach((function(t,e){var a=t.label;null!=t.atomList?(a="L",o.push(e)):t.pseudo?t.pseudo.length>3&&(a="A",i.push({id:e,value:"'".concat(t.pseudo,"'")})):t.alias?i.push({id:e,value:t.alias}):_.get(t.label)||-1!==["A","Q","X","*","R#"].indexOf(t.label)||(a="C",i.push({id:e,value:t.label})),n.writeAtom(t,a),n.mapping[e]=r++}),this),this.bondMapping={},r=1,this.molecule.bonds.forEach((function(t,e){n.bondMapping[e]=r++,n.writeBond(t)}),this);i.length>0;)this.writeAtomProps(i[0]),i.splice(0,1);var a=[],s=[],u=[],l=[],c=[],d=[],h=[],f=[],p=[];this.molecule.atoms.forEach((function(t,e){if(0!==t.charge&&a.push([e,t.charge]),0!==t.isotope&&s.push([e,t.isotope]),0!==t.radical&&u.push([e,t.radical]),null!=t.rglabel&&"R#"===t.label)for(var n=0;n<32;n++)t.rglabel&1<0||t.range.length>0){var n=" 1 "+Pe.paddedNum(e,3)+" "+Pe.paddedNum(t.ifthen,3)+" "+Pe.paddedNum(t.resth?1:0,3)+" "+t.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 m=0;m0)for(var v=0;v=0&&(n.write("M SPL"),n.writePaddedNumber(1,3),n.writeWhiteSpace(1),n.writePaddedNumber(t,3),n.writeWhiteSpace(1),n.writePaddedNumber(x[o],3),n.writeCR()),"SRU"===r.type&&r.data.connectivity){var i=" ".concat(t.toString().padStart(3)," ").concat((r.data.connectivity||"").padEnd(3));n.write("M SCN"),n.writePaddedNumber(1,3),n.write(i.toUpperCase()),n.writeCR()}"SRU"===r.type&&(n.write("M SMT "),n.writePaddedNumber(t,3),n.writeWhiteSpace(),n.write(r.data.subscript||"n"),n.writeCR()),r.getAttachmentPoints().forEach((function(e){n.writeSGroupAttachmentPointLine(t,e)})),n.writeCR(gn.saveToMolfile[r.type](r,n.molecule,x,n.mapping,n.bondMapping))},A=1;A0;){for(var r=[];e.length>0&&r.length<8;)r.push(e[0]),e.splice(0,1);this.write(t),this.writePaddedNumber(r.length,3),r.forEach((function(t){n.writeWhiteSpace(),n.writePaddedNumber(n.mapping[t[0]],3),n.writeWhiteSpace(),n.writePaddedNumber(t[1],3)})),this.writeCR()}}},{key:"writeSGroupAttachmentPointLine",value:function(t,e){var n;this.write("M SAP"),this.writeWhiteSpace(1),this.writePaddedNumber(t,3),this.writePaddedNumber(1,3),this.writeWhiteSpace(1);var r=this.mapping[e.atomId];this.writePaddedNumber(r,3),this.writeWhiteSpace(1);var o=null!==(n=this.mapping[e.leaveAtomId])&&void 0!==n?n:0;this.writePaddedNumber(o,3),this.writeWhiteSpace(1);var i=e.attachmentId?e.attachmentId.slice(0,2):" ";this.writePadded(i,2),this.writeCR()}}]),t}();function bn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function wn(t){for(var e=1;e0?1:-1},En.prototype.samesides=function(t,e,n,r){return this.sameside(this.molecule.atoms.get(t).pp,this.molecule.atoms.get(e).pp,this.molecule.atoms.get(n).pp,this.molecule.atoms.get(r).pp)},En.prototype.sortSubstituents=function(t){var e=this.molecule.atoms.get(t[0]).pureHydrogen(),n=t[1]<0||this.molecule.atoms.get(t[1]).pureHydrogen(),r=this.molecule.atoms.get(t[2]).pureHydrogen(),o=t[3]<0||this.molecule.atoms.get(t[3]).pureHydrogen();return!(e&&n||r&&o||(n?t[1]=-1:e?(t[0]=t[1],t[1]=-1):t[0]>t[1]&&Pn(t,0,1),o?t[3]=-1:r?(t[2]=t[3],t[3]=-1):t[2]>t[3]&&Pn(t,2,3),0))},En.prototype.isGeomStereoBond=function(t,e){var n=this.molecule.bonds.get(t);if(n.type!==dt.PATTERN.TYPE.DOUBLE)return!1;var r=this.molecule.atoms.get(n.begin).label,o=this.molecule.atoms.get(n.end).label;if("C"!==r&&"N"!==r&&"Si"!==r&&"Ge"!==r)return!1;if("C"!==o&&"N"!==o&&"Si"!==o&&"Ge"!==o)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(e[0]=-1,e[1]=-1,e[2]=-1,e[3]=-1,i=0;i=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,r.push(d)}}};!a(););},On.prototype.edgeClosingCycle=function(t){return 0!==this.edges[t].closing_cycle},On.prototype.numBranches=function(t){return this.vertices[t].branches},On.prototype.numOpeningCycles=function(t){return this.edges[t].opening_cycles},On.prototype.toString=function(){var t="";return this.v_seq.forEach((function(e){t+=e.idx+" -> "})),t+="*"},An.prototype.each=function(t,e){this.atoms.forEach(t,e)},An.prototype.buildFromBonds=function(t){var e=this,n=this.molecule.atoms,r=this.molecule.bonds,o=new et;n.forEach((function(t,i){var a=e.getNeighbors.call(e.context,i);if(2!==a.length)return!1;var s=a[0],u=a[1];if([i,s.aid,u.aid].findIndex((function(t){return["C","Si"].indexOf(n.get(t).label)<0}),e)>=0)return!1;if([s.bid,u.bid].findIndex((function(t){return r.get(t).type!==dt.PATTERN.TYPE.DOUBLE}),e)>=0)return!1;var l=e.getNeighbors.call(e.context,s.aid).filter((function(t){return t.aid!==i})),c=e.getNeighbors.call(e.context,u.aid).filter((function(t){return t.aid!==i}));return!(l.length<1||l.length>2||c.length<1||c.length>2||l.concat(c).findIndex((function(t){return r.get(t.bid).type!==dt.PATTERN.TYPE.SINGLE}),e)>=0||l.concat(c).findIndex((function(t){return r.get(t.bid).stereo===dt.PATTERN.STEREO.EITHER}),e)>=0||(o.add(s.aid).add(u.aid),0))})),o.size>0&&n.forEach((function(t,n){if(!o.has(n)){var r=e.getNeighbors.call(e.context,n),i=!1;r.find((function(t){var e=this.molecule.bonds.get(t.bid);return e.type===dt.PATTERN.TYPE.SINGLE&&e.begin===n&&(e.stereo===dt.PATTERN.STEREO.UP||e.stereo===dt.PATTERN.STEREO.DOWN)&&(i=!0,!0)}),e),i&&e.buildOneCenter(n)}}))},An.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}],An.prototype.buildOneCenter=function(t){var e=this,n=this.molecule.atoms.get(t),r=this.getNeighbors.call(this.context,t),o=r.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(o>4)throw new Error("stereocenter with %d bonds are not supported"+o);if(r.forEach((function(t,r){var o=e.molecule.atoms.get(t.aid),i=e.molecule.bonds.get(t.bid);if(s[r]={edge_idx:t.bid,nei_idx:t.aid,rank:t.aid,vec:$.diff(o.pp,n.pp).yComplement()},o.pureHydrogen()?(c++,s[r].rank=1e4):"H"===o.label&&(s[r].rank=5e3),!s[r].vec.normalize())throw new Error("zero bond length");if(i.type===dt.PATTERN.TYPE.TRIPLE)throw new Error("non-single bonds not allowed near stereocenter");if(i.type===dt.PATTERN.TYPE.AROMATIC)throw new Error("aromatic bonds not allowed near stereocenter");i.type===dt.PATTERN.TYPE.DOUBLE&&l++})),An.allowed_stereocenters.find((function(t){return t.elem===n.label&&t.charge===n.charge&&t.degree===o&&t.n_double_bonds===l&&(i=t.implicit_degree,!0)})),-1===i)throw new Error("unknown stereocenter configuration: "+n.label+", charge "+n.charge+", "+o+" bonds ("+l+" double)");if(4===o&&c>1)throw new Error(c+" hydrogens near stereocenter");if(3===o&&4===i&&c>0)throw new Error("have hydrogen(s) besides implicit hydrogen near stereocenter");if(4===o){s[0].rank>s[1].rank&&Rn(s,0,1),s[1].rank>s[2].rank&&Rn(s,1,2),s[2].rank>s[3].rank&&Rn(s,2,3),s[1].rank>s[2].rank&&Rn(s,1,2),s[0].rank>s[1].rank&&Rn(s,0,1),s[1].rank>s[2].rank&&Rn(s,1,2);for(var d,h,f=-1,p=-1,m=-1,v=-1,g=0,y=0;y<4;y++){var b=this.getBondStereo(t,s[y].edge_idx);if(b===dt.PATTERN.STEREO.UP||b===dt.PATTERN.STEREO.DOWN){f=y,g=b;break}}if(-1===f)throw new Error("none of 4 bonds going from stereocenter is stereobond");if(-1===p&&((d=An.xyzzy(s[f].vec,s[(f+1)%4].vec,s[(f+2)%4].vec))+(h=An.xyzzy(s[f].vec,s[(f+1)%4].vec,s[(f+3)%4].vec))!==3&&d+h!==12||(p=(f+1)%4,m=(f+2)%4,v=(f+3)%4)),-1===p&&((d=An.xyzzy(s[f].vec,s[(f+2)%4].vec,s[(f+1)%4].vec))+(h=An.xyzzy(s[f].vec,s[(f+2)%4].vec,s[(f+3)%4].vec))!==3&&d+h!==12||(p=(f+2)%4,m=(f+1)%4,v=(f+3)%4)),-1===p&&((d=An.xyzzy(s[f].vec,s[(f+3)%4].vec,s[(f+1)%4].vec))+(h=An.xyzzy(s[f].vec,s[(f+3)%4].vec,s[(f+2)%4].vec))!==3&&d+h!==12||(p=(f+3)%4,m=(f+2)%4,v=(f+1)%4)),-1===p)throw new Error("internal error: can not find opposite bond");if(g===dt.PATTERN.STEREO.UP&&this.getBondStereo(t,s[p].edge_idx)===dt.PATTERN.STEREO.DOWN)throw new Error("stereo types of the opposite bonds mismatch");if(g===dt.PATTERN.STEREO.DOWN&&this.getBondStereo(t,s[p].edge_idx)===dt.PATTERN.STEREO.UP)throw new Error("stereo types of the opposite bonds mismatch");if(g===this.getBondStereo(t,s[m].edge_idx))throw new Error("stereo types of non-opposite bonds match");if(g===this.getBondStereo(t,s[v].edge_idx))throw new Error("stereo types of non-opposite bonds match");u=3===f||3===p?g:g===dt.PATTERN.STEREO.UP?dt.PATTERN.STEREO.DOWN:dt.PATTERN.STEREO.UP;var w=An.sign(s[0].vec,s[1].vec,s[2].vec);u===dt.PATTERN.STEREO.UP&&w>0||u===dt.PATTERN.STEREO.DOWN&&w<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===o){s[0].rank>s[1].rank&&Rn(s,0,1),s[1].rank>s[2].rank&&Rn(s,1,2),s[0].rank>s[1].rank&&Rn(s,0,1);var x=this.getBondStereo(t,s[0].edge_idx),E=this.getBondStereo(t,s[1].edge_idx),P=this.getBondStereo(t,s[2].edge_idx),O=0,A=0;if(O+=x===dt.PATTERN.STEREO.UP?1:0,O+=E===dt.PATTERN.STEREO.UP?1:0,O+=P===dt.PATTERN.STEREO.UP?1:0,A+=x===dt.PATTERN.STEREO.DOWN?1:0,A+=E===dt.PATTERN.STEREO.DOWN?1:0,A+=P===dt.PATTERN.STEREO.DOWN?1:0,4===i){if(3===O)throw new Error("all 3 bonds up near stereoatom");if(3===A)throw new Error("all 3 bonds down near stereoatom");if(0===O&&0===A)throw new Error("no up/down bonds near stereoatom -- indefinite case");if(1===O&&1===A)throw new Error("one bond up, one bond down -- indefinite case");if(g=0,2===O)u=dt.PATTERN.STEREO.DOWN;else if(2===A)u=dt.PATTERN.STEREO.UP;else{for(f=-1,m=-1,v=-1,y=0;y<3;y++){var R=this.getBondStereo(t,s[y].edge_idx);if(R===dt.PATTERN.STEREO.UP||R===dt.PATTERN.STEREO.DOWN){f=y,g=R,m=(y+1)%3,v=(y+2)%3;break}}if(-1===f)throw new Error("internal error: can not find up or down bond");var S=An.xyzzy(s[m].vec,s[v].vec,s[f].vec);if(3===S||4===S)throw new Error("degenerate case for 3 bonds near stereoatom");u=1===S?g:g===dt.PATTERN.STEREO.UP?dt.PATTERN.STEREO.DOWN:dt.PATTERN.STEREO.UP}var T=An.sign(s[0].vec,s[1].vec,s[2].vec);u===dt.PATTERN.STEREO.UP&&T>0||u===dt.PATTERN.STEREO.DOWN&&T<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 k;if(A>0&&O>0)throw new Error("one bond up, one bond down -- indefinite case");if(0===A&&0===O)throw new Error("no up-down bonds attached to stereocenter");k=O>0?1:-1,1!==An.xyzzy(s[0].vec,s[1].vec,s[2].vec)&&1!==An.xyzzy(s[0].vec,s[2].vec,s[1].vec)&&1!==An.xyzzy(s[2].vec,s[1].vec,s[0].vec)||(k=-k),An.sign(s[0].vec,s[1].vec,s[2].vec)===k?(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(t,a)},An.prototype.getBondStereo=function(t,e){var n=this.molecule.bonds.get(e);return t!==n.begin?0:n.stereo},An.xyzzy=function(t,e,n){var r=.001,o=$.cross(t,e),i=$.dot(t,e),a=$.cross(t,n),s=$.dot(t,n);if(Math.abs(o)0?4:8}return o*a<-r*r||s.001)return 1;if(r<-.001)return-1;throw new Error("degenerate triangle")},An.isPyramidMappingRigid=function(t){var e=t.slice(),n=!0;return e[0]>e[1]&&(Rn(e,0,1),n=!n),e[1]>e[2]&&(Rn(e,1,2),n=!n),e[2]>e[3]&&(Rn(e,2,3),n=!n),e[1]>e[2]&&(Rn(e,1,2),n=!n),e[0]>e[1]&&(Rn(e,0,1),n=!n),e[1]>e[2]&&(Rn(e,1,2),n=!n),n},Sn._Atom=function(t){this.neighbours=[],this.aromatic=!1,this.lowercase=!1,this.chirality=0,this.branch_cnt=0,this.paren_written=!1,this.h_count=t,this.parent=-1},Sn.prototype.isBondInRing=function(t){return this.inLoop[t]},Sn.prototype.saveMolecule=function(t,e){var n,r,o,i=this;e||(this.ignoreErrors=e),(t=t.clone(void 0,void 0,!t.hasRxnArrow(),void 0,void 0,void 0)).initHalfBonds(),t.initNeighbors(),t.sortNeighbors(),t.setImplicitHydrogen(),t.sgroups.forEach((function(e){if("MUL"===e.type)try{Zt.prepareMulForSaving(e,t)}catch(t){throw Error("Bad s-group ("+t.message+")")}})),this.atoms=new Array(t.atoms.size),t.atoms.forEach((function(t,e){i.atoms[e]=new Sn._Atom(t.implicitH)}));var a=["B","C","N","O","P","S","Se","As"];t.bonds.forEach((function(e,n){e.type===dt.PATTERN.TYPE.AROMATIC&&(i.atoms[e.begin].aromatic=!0,-1!==a.indexOf(t.atoms.get(e.begin).label)&&(i.atoms[e.begin].lowercase=!0),i.atoms[e.end].aromatic=!0,-1!==a.indexOf(t.atoms.get(e.end).label)&&(i.atoms[e.end].lowercase=!0)),i.atoms[e.begin].neighbours.push({aid:e.end,bid:n}),i.atoms[e.end].neighbours.push({aid:e.begin,bid:n})})),this.inLoop=function(){t.prepareLoopStructure();var e=new et;t.loops.forEach((function(n){if(n.hbs.length<=6){var r=n.hbs.map((function(e){return t.halfBonds.get(e).bid}));e=e.union(new et(r))}}));var n={};return e.forEach((function(t){n[t]=1})),n}(),this.touchedCistransbonds=0,this.markCisTrans(t);var s=t.getComponents(),u=s.reactants.concat(s.products),l=new On(t,this.atoms,u,s.reactants.length);for(l.walk(),this.atoms.forEach((function(t){t.neighbours=[]})),n=0;n=0){var p=this.atoms[d],m=l.numOpeningCycles(h);for(r=0;r=4)throw new Error("internal: pyramid overflow");a[s++]=o;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");An.isPyramidMappingRigid(a)?i.atoms[e].chirality=1:i.atoms[e].chirality=2}))}catch(t){}var g=[];g.push(0);var y=!0;for(n=0;n=0){for(l.numBranches(f)>1&&this.atoms[f].branch_cnt>0&&this.atoms[f].paren_written&&(this.smiles+=")"),m=l.numOpeningCycles(h),r=0;r=0){var w=l.numBranches(f);if(w>1&&this.atoms[f].branch_cntw)throw new Error("unexpected branch")}var x=t.bonds.get(h),E=0;if(x.type===dt.PATTERN.TYPE.SINGLE&&(E=this.calcBondDirection(t,h,f)),1===E&&d===x.end||2===E&&d===x.begin?this.smiles+="/":2===E&&d===x.end||1===E&&d===x.begin?this.smiles+="\\":x.type===dt.PATTERN.TYPE.ANY?this.smiles+="~":x.type===dt.PATTERN.TYPE.DOUBLE?this.smiles+="=":x.type===dt.PATTERN.TYPE.TRIPLE?this.smiles+="#":x.type===dt.PATTERN.TYPE.SINGLE_OR_AROMATIC?this.smiles+="-,:":x.type===dt.PATTERN.TYPE.DOUBLE_OR_AROMATIC?this.smiles+="=,:":x.type===dt.PATTERN.TYPE.SINGLE_OR_DOUBLE?this.smiles+="-,=":x.type!==dt.PATTERN.TYPE.AROMATIC||this.atoms[x.begin].lowercase&&this.atoms[x.end].lowercase&&this.isBondInRing(h)?x.type===dt.PATTERN.TYPE.SINGLE&&this.atoms[x.begin].aromatic&&this.atoms[x.end].aromatic&&(this.smiles+="-"):this.smiles+=":",l.edgeClosingCycle(h)){for(r=1;r>":"."),y=!1,this.writtenComponents++;b&&(this.writeAtom(t,d,this.atoms[d].aromatic,this.atoms[d].lowercase,this.atoms[d].chirality),this.writtenAtoms.push(c.idx))}return this.comma=!1,this.writeRadicals(t),this.comma&&(this.smiles+="|"),this.smiles},Sn.prototype.writeCycleNumber=function(t){if(t>0&&t<10)this.smiles+=t;else if(t>=10&&t<100)this.smiles+="%"+t;else{if(!(t>=100&&t<1e3))throw new Error("bad cycle number: "+t);this.smiles+="%%"+t}},Sn.prototype.writeAtom=function(t,e,n,r,o){var i,a=t.atoms.get(e),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||o>0||n&&"C"!==a.label&&"O"!==a.label||n&&"C"===a.label&&this.atoms[e].neighbours.length<3&&0===this.atoms[e].h_count)&&(u=this.atoms[e].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):(o||0!==a.charge||a.isotope>0||u>=0||i>0)&&(s=!0),s&&(-1===u&&(u=this.atoms[e].h_count),this.smiles+="["),a.isotope>0&&(this.smiles+=a.isotope),this.smiles+=r?l.toLowerCase():l,o>0&&(this.smiles+=1===o?"@":"@@",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+="*"},Sn.prototype.markCisTrans=function(t){var e=this;this.cis_trans=new En(t,(function(t){return this.atoms[t].neighbours}),this),this.cis_trans.build(),this.dbonds=new Array(t.bonds.size),t.bonds.forEach((function(t,n){e.dbonds[n]={ctbond_beg:-1,ctbond_end:-1,saved:0}})),this.cis_trans.each((function(n,r){var o=t.bonds.get(r);if(0!==n.parity&&!e.isBondInRing(r)){var i=e.atoms[o.begin].neighbours,a=e.atoms[o.end].neighbours,s=!0,u=!0;if(i.forEach((function(e){e.bid!==r&&t.bonds.get(e.bid).type===dt.PATTERN.TYPE.SINGLE&&(s=!1)})),a.forEach((function(e){e.bid!==r&&t.bonds.get(e.bid).type===dt.PATTERN.TYPE.SINGLE&&(u=!1)})),s||u)return;i.forEach((function(n){n.bid!==r&&(t.bonds.get(n.bid).begin===o.begin?e.dbonds[n.bid].ctbond_beg=r:e.dbonds[n.bid].ctbond_end=r)})),a.forEach((function(n){n.bid!==r&&(t.bonds.get(n.bid).begin===o.end?e.dbonds[n.bid].ctbond_beg=r:e.dbonds[n.bid].ctbond_end=r)}))}}))},Sn.prototype.updateSideBonds=function(t,e){var n=t.bonds.get(e),r=this.cis_trans.getSubstituents(e),o=this.cis_trans.getParity(e),i=[-1,-1,-1,-1];i[0]=t.findBondId(r[0],n.begin),-1!==r[1]&&(i[1]=t.findBondId(r[1],n.begin)),i[2]=t.findBondId(r[2],n.end),-1!==r[3]&&(i[3]=t.findBondId(r[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&&t.bonds.get(i[0]).begin===n.begin||2===this.dbonds[i[0]].saved&&t.bonds.get(i[0]).end===n.begin?a++:s++),-1!==i[1]&&0!==this.dbonds[i[1]].saved&&(2===this.dbonds[i[1]].saved&&t.bonds.get(i[1]).begin===n.begin||1===this.dbonds[i[1]].saved&&t.bonds.get(i[1]).end===n.begin?a++:s++),0!==this.dbonds[i[2]].saved&&(1===this.dbonds[i[2]].saved&&t.bonds.get(i[2]).begin===n.end||2===this.dbonds[i[2]].saved&&t.bonds.get(i[2]).end===n.end?u++:l++),-1!==i[3]&&0!==this.dbonds[i[3]].saved&&(2===this.dbonds[i[3]].saved&&t.bonds.get(i[3]).begin===n.end||1===this.dbonds[i[3]].saved&&t.bonds.get(i[3]).end===n.end?u++:l++),o===En.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=t.bonds.get(i[0]).begin===n.begin?1:2,-1!==i[1]&&(this.dbonds[i[1]].saved=t.bonds.get(i[1]).begin===n.begin?2:1),this.dbonds[i[2]].saved=t.bonds.get(i[2]).begin===n.end==(o===En.PARITY.CIS)?1:2,-1!==i[3]&&(this.dbonds[i[3]].saved=t.bonds.get(i[3]).begin===n.end==(o===En.PARITY.CIS)?2:1)),s>0&&(this.dbonds[i[0]].saved=t.bonds.get(i[0]).begin===n.begin?2:1,-1!==i[1]&&(this.dbonds[i[1]].saved=t.bonds.get(i[1]).begin===n.begin?1:2),this.dbonds[i[2]].saved=t.bonds.get(i[2]).begin===n.end==(o===En.PARITY.CIS)?2:1,-1!==i[3]&&(this.dbonds[i[3]].saved=t.bonds.get(i[3]).begin===n.end==(o===En.PARITY.CIS)?1:2)),!0)},Sn.prototype.calcBondDirection=function(t,e,n){var r,o=this;if(-1===this.dbonds[e].ctbond_beg&&-1===this.dbonds[e].ctbond_end)return 0;if(t.bonds.get(e).type!==dt.PATTERN.TYPE.SINGLE)throw new Error("internal: directed bond type "+t.bonds.get(e).type);for(;r=0,this.cis_trans.each((function(e,n){0===e.parity||o.isBondInRing(n)||o.updateSideBonds(t,n)&&r++})),r!==this.touchedCistransbonds;)this.touchedCistransbonds=r;return 0===this.dbonds[e].saved&&(n===t.bonds.get(e).begin?this.dbonds[e].saved=1:this.dbonds[e].saved=2),this.dbonds[e].saved},Sn.prototype.writeRadicals=function(t){var e,n,r=new Array(this.writtenAtoms.length);for(e=0;e [ \d]*<(\S+)>/);if(n){var r=n[1],o=e.split("\n")[1].trim();t[r]=Number.isFinite(o)?+o:o.toString()}return t}),{});n.push({struct:s,props:u})}}return n}},{key:"serialize",value:function(t){var e=new xn(this.molSerializerOptions);return t.reduce((function(t,n){return t+=e.serialize(n.struct),Object.keys(n.props).forEach((function(e){t+="> <".concat(e,">\n"),t+="".concat(n.props[e],"\n\n")})),"".concat(t,"$$$$\n")}),"")}}]),t}();!function(t){t.Mol="chemical/x-mdl-molfile",t.Rxn="chemical/x-mdl-rxnfile",t.DaylightSmiles="chemical/x-daylight-smiles",t.ExtendedSmiles="chemical/x-chemaxon-cxsmiles",t.DaylightSmarts="chemical/x-daylight-smarts",t.InChI="chemical/x-inchi",t.InChIAuxInfo="chemical/x-inchi-aux",t.InChIKey="chemical/x-inchi-key",t.CDX="chemical/x-cdx",t.CDXML="chemical/x-cdxml",t.CML="chemical/x-cml",t.KET="chemical/x-indigo-ket",t.UNKNOWN="chemical/x-unknown",t.SDF="chemical/x-sdf"}(Cn||(Cn={}));var Mn=Math.PI/12;function Nn(t,e){var n=$.diff(e,t);return Math.atan2(n.y,n.x)}function _n(t,e){return e&&(t=Nn(t,e)),Math.round(t/Mn)*Mn}function Dn(t){var e=Math.round(t/Math.PI*180);return e>180?e-=360:e<=-180&&(e+=360),e}var Ln={calcAngle:Nn,fracAngle:_n,degrees:Dn,setFracAngle:function(t){Mn=Math.PI/180*t},mergeBondsParams:function(t,e,n,r){var o=t.atoms.get(e.begin),i=n.atoms.get(r.begin),a=t.atoms.get(e.end),s=n.atoms.get(r.end),u=Nn(o.pp,a.pp)-Nn(i.pp,s.pp),l=Math.abs(Dn(u)%180),c=$.dist(o.pp,a.pp)/$.dist(i.pp,s.pp);return{merged:!(0,E.inRange)(l,10,170)&&(0,E.inRange)(c,.8,1.2),angle:u,scale:c,cross:Math.abs(Dn(u))>90}},calcNewAtomPos:function(t,e,n){var r=new $(1,0).rotate(n?Nn(t,e):_n(t,e));return r.add_(t),r}};S().el.translateAbs=function(t,e){this.delta=this.delta||new $,this.delta.x+=t-0,this.delta.y+=e-0,this.transform("t"+this.delta.x.toString()+","+this.delta.y.toString())},S().st.translateAbs=function(t,e){this.forEach((function(n){n.translateAbs(t,e)}))};var jn,Fn,Gn,Hn=function(){function t(e){(0,o.Z)(this,t),this.type=e,this.paths=[],this.boxes=[],this.boundingBox=null,this.oldBoundingBox=null,this.exts=[]}return(0,i.Z)(t,[{key:"add",value:function(t,e,n){this.paths.push(t),e&&(this.boxes.push(e),this.boundingBox=null==this.boundingBox?e:Et.union(this.boundingBox,e)),n&&this.exts.push(n)}},{key:"clear",value:function(){this.paths=[],this.boxes=[],this.exts=[],null!==this.boundingBox&&(this.oldBoundingBox=this.boundingBox.clone()),this.boundingBox=null}},{key:"translate",value:function(){if(arguments.length>2)throw new Error("One vector or two scalar arguments expected");if(1===arguments.length){var t=arguments.length<=0?void 0:arguments[0];this.translate(t.x,t.y)}else{for(var e=arguments.length<=0?void 0:arguments[0],n=arguments.length<=1?void 0:arguments[1],r=new $(e,n),o=0;o0?(a<0||i[a]i[s]?s:a,d=i[a]>i[s]?a:s;return i[c]+Math.abs(o[c])*(i[d]-i[c])/(Math.abs(o[c])+Math.abs(o[d]))},calcCoordinates:function(t,e,n){var r={pos1:null,pos2:null},o={x:e.x-t.x,y:e.y-t.y},i=(Math.pow(n,2)-o.x*o.x-o.y*o.y-Math.pow(n,2))/-2,a=o.x*o.x+o.y*o.y;if(0!==o.x){var s=-2*o.y*i,u=s*s-4*a*(i*i-n*n*o.x*o.x);u>0&&(r.pos1={x:0,y:0},r.pos2={x:0,y:0},r.pos1.y=(-s+Math.sqrt(u))/(2*a),r.pos2.y=(-s-Math.sqrt(u))/(2*a),r.pos1.x=(i-r.pos1.y*o.y)/o.x,r.pos2.x=(i-r.pos2.y*o.y)/o.x)}else r.pos1={x:0,y:0},r.pos2={x:0,y:0},r.pos1.y=i/o.y,r.pos2.y=i/o.y,r.pos1.x=-Math.sqrt(Math.pow(n,2)-Math.pow(i,2)/Math.pow(o.y,2)),r.pos2.x=Math.sqrt(Math.pow(n,2)-Math.pow(i,2)/Math.pow(o.y,2));return null!==r.pos1&&(r.pos1.x+=t.x,r.pos1.y+=t.y),null!==r.pos2&&(r.pos2.x+=t.x,r.pos2.y+=t.y),r},drawCIPLabel:function(t){var e=t.atomOrBond,n=t.position,r=t.restruct,o=t.visel,i=r.render,a=i.options,s=i.paper,u=s.set(),l=function(t){var e=t.paper,n=t.cipLabelPosition,r=t.atomOrBond,o=t.options,i=e.text(n.x,n.y,"(".concat(r.cip,")")).attr({font:o.font,"font-size":o.fontsz}),a=i.getBBox(),s=e.set(),u=e.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.scale),atomOrBond:e,options:a}),c=Un(l.path.getBBox());return l.path.translateAbs(.5*c.width,-.5*c.height),u.push(l.path.toFront()),r.addReObjectPath(jn.additionalInfo,o,u,null,!0),l},updateHalfBondCoordinates:function(t,e,n){return t.p.y!==e.p.y||(t.p.xe.p.x&&(t.p.x=t.p.x-n)),[t,e]}};function Wn(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Yn(t){for(var e=1;e=0?1:-1,c=10*l,d=5*l,h=4*l,f=s.x+n,p="M".concat(H(s.x),",").concat(H(s.y))+"A".concat(n/2,",").concat(u,",",0,",",0,",").concat(l>0?1:0,",").concat(H(f),",").concat(H(s.y))+"L".concat(H(f-d),",").concat(H(s.y-c))+"l".concat(H(d),",").concat(H(h))+"l".concat(H(d),",").concat(H(-h))+"l".concat(H(-d),",").concat(c),m=k()(p).rotate(o,s.x,s.y).toString();return t.path(m).attr(Yn(Yn({},i.lineattr),a&&{stroke:i.arrowSnappingStyle.stroke}))}(t,e,n,o,i,s);case _t.EllipticalArcFilledTriangle:return function(t,e,n,o,i,a){var s=(0,r.Z)(e.pos,1)[0],u=e.height,l=u>=0?1:-1,c=10*l,d=5*l,h=s.x+n,f="M".concat(H(s.x),",").concat(H(s.y))+"A".concat(n/2,",").concat(u,",",0,",",0,",").concat(l>0?1:0,",").concat(H(h),",").concat(H(s.y))+"L".concat(H(h-d),",").concat(H(s.y-c))+"l".concat(H(c),",").concat(H(0))+"l".concat(H(-d),",").concat(H(c)),p=k()(f).rotate(o,s.x,s.y).toString();return t.path(p).attr(Yn(Yn({},i.lineattr),a&&{stroke:i.arrowSnappingStyle.stroke}))}(t,e,n,o,i,s);case _t.EllipticalArcOpenAngle:return function(t,e,n,o,i,a){var s=(0,r.Z)(e.pos,1)[0],u=e.height,l=u>=0?1:-1,c=5*l,d=7*l,h=s.x+n,f="M".concat(H(s.x),",").concat(H(s.y))+"A".concat(n/2,",").concat(u,",",0,",",0,",").concat(l>0?1:0,",").concat(H(h),",").concat(H(s.y))+"L".concat(H(h-c),",").concat(H(s.y-d))+"M".concat(H(h),",").concat(H(s.y))+"L".concat(H(h+c),", ").concat(H(s.y-d)),p=k()(f).rotate(o,s.x,s.y).toString();return t.path(p).attr(Yn(Yn({},i.lineattr),a&&{stroke:i.arrowSnappingStyle.stroke}))}(t,e,n,o,i,s);case _t.EllipticalArcOpenHalfAngle:return function(t,e,n,o,i,a){var s=(0,r.Z)(e.pos,1)[0],u=e.height,l=u>=0?1:-1,c=5*l,d=7*l,h=s.x+n,f="M".concat(H(s.x),",").concat(H(s.y))+"A".concat(n/2,",").concat(u,",",0,",",0,",").concat(l>0?1:0,", ").concat(H(h),",").concat(H(s.y))+"L".concat(H(h+c),", ").concat(H(s.y-d)),p=k()(f).rotate(o,s.x,s.y).toString();return t.path(p).attr(Yn(Yn({},i.lineattr),a&&{stroke:i.arrowSnappingStyle.stroke}))}(t,e,n,o,i,s)}},plus:function(t,e,n){var r=n.scale/5;return t.path("M{0},{4}L{0},{5}M{2},{1}L{3},{1}",H(e.x),H(e.y),H(e.x-r),H(e.x+r),H(e.y-r),H(e.y+r)).attr(n.lineattr)},aromaticBondPaths:function(t,e,n,r,o,i){return[i&&1&o?$n(t,n,i):qn(t,n),i&&2&o?$n(e,r,i):qn(e,r)]},bondSingle:function(t,e,n,r,o){var i=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"#000",a=e.p,s=n.p;return t.path(qn(a,s)).attr(r.lineattr).attr({fill:i,stroke:i}).attr(o?r.bondSnappingStyle:{})},bondSingleUp:function(t,e,n,r,o,i){var a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"#000";return t.path("M{0},{1}L{2},{3}L{4},{5}Z",H(e.x),H(e.y),H(n.x),H(n.y),H(r.x),H(r.y)).attr(o.lineattr).attr({fill:a,stroke:a}).attr(i?o.bondSnappingStyle:{})},bondSingleStereoBold:function(t,e,n,r,o,i,a){var s=arguments.length>7&&void 0!==arguments[7]?arguments[7]:"#000";return t.path("M{0},{1}L{2},{3}L{4},{5}L{6},{7}Z",H(e.x),H(e.y),H(n.x),H(n.y),H(r.x),H(r.y),H(o.x),H(o.y)).attr(i.lineattr).attr({stroke:s,fill:s}).attr(a?i.bondSnappingStyle:{})},bondDoubleStereoBold:function(t,e,n,r,o,i){var a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"#000";return t.set([e,t.path("M{0},{1}L{2},{3}",H(n.x),H(n.y),H(r.x),H(r.y)).attr(o.lineattr).attr({stroke:a,fill:a}).attr(i?o.bondSnappingStyle:{})])},bondSingleDown:function(t,e,n,r,o,i,a){for(var s,u=arguments.length>7&&void 0!==arguments[7]?arguments[7]:"#000",l=e.p,c=e.norm,d=.7*i.stereoBond,h="",f=0;f7&&void 0!==arguments[7]?arguments[7]:"#000",u=e.p,l=e.norm,c=.7*i.stereoBond,d="M"+H(u.x)+","+H(u.y),h=u,f=0;f5&&void 0!==arguments[5]?arguments[5]:"#000",a=e.p,s=n.p,u=e.norm,l=a.addScaled(u,r.bondSpace),c=s.addScaled(u,r.bondSpace),d=a.addScaled(u,-r.bondSpace),h=s.addScaled(u,-r.bondSpace);return t.path(qn(a,s)+qn(l,c)+qn(d,h)).attr(r.lineattr).attr({fill:i,stroke:i}).attr(o?r.bondSnappingStyle:{})},bondAromatic:function(t,e,n,r,o){var i=t.path(e[0]).attr(r.lineattr).attr(o?r.bondSnappingStyle:{}),a=t.path(e[1]).attr(r.lineattr).attr(o?r.bondSnappingStyle:{});return null!=n&&(n>0?i:a).attr({"stroke-dasharray":"- "}),t.set([i,a])},bondAny:function(t,e,n,r,o){var i=e.p,a=n.p;return t.path(qn(i,a)).attr(r.lineattr).attr({"stroke-dasharray":"- "}).attr(o?r.bondSnappingStyle:{})},bondHydrogen:function(t,e,n,r,o){var i=e.p,a=n.p;return t.path(qn(i,a)).attr(r.lineattr).attr({"stroke-dasharray":".","stroke-linecap":"square"}).attr(o?r.bondSnappingStyle:{})},bondDative:function(t,e,n,r,o){var i=e.p,a=n.p;return t.path(qn(i,a)).attr(r.lineattr).attr({"arrow-end":"block-midium-long"}).attr(o?r.bondSnappingStyle:{})},reactingCenter:function(t,e,n){for(var r="",o=0;o1||this.showLabel&&0!==this.a.implicitH?this.getLabeledSelectionContour(t):this.getUnlabeledSelectionContour(t)}},{key:"makeHoverPlate",value:function(t){var e=this.a,n=t.options,r=t.ctab.sgroups,o=t.ctab.molecule.functionalGroups;return Lt.isAtomInContractedFunctionalGroup(e,r,o,!0)?null:this.getSelectionContour(t).attr(n.hoverStyle)}},{key:"makeSelectionPlate",value:function(t){var e=this.a,n=t.render,r=n.options,o=n.ctab.sgroups,i=n.ctab.molecule.functionalGroups;return Lt.isAtomInContractedFunctionalGroup(e,o,i,!0)?null:this.getSelectionContour(n).attr(r.selectionStyle)}},{key:"getShiftedSegmentPosition",value:function(t,e){for(var n=gt.obj2scaled(this.a.pp,t),r=0,o=this.visel.exts,i=0;i0?n.addScaled(e,r+3*t.lineWidth):n}},{key:"hasAttachmentPoint",value:function(){return Boolean(this.a.attachmentPoints)}},{key:"show",value:function(t,e,n){var r,o=t.molecule.atoms.get(e),i=t.molecule.sgroups,a=t.molecule.functionalGroups,s=t.render,u=gt.obj2scaled(this.a.pp,s.options);if(Lt.isAtomInContractedFunctionalGroup(o,i,a,!1)){var l=t.molecule.getGroupFromAtomId(e);if((null==l?void 0:l.getContractedPosition(t.molecule).atomId)===e){var c=s.paper.text(u.x,u.y,l.data.name).attr({"font-weight":700,"font-size":14});t.addReObjectPath(jn.data,this.visel,c,u,!0)}}else{var d,h,f,p,m,v,g;this.hydrogenOnTheLeft=function(t,e){if(0===e.a.neighbors.length){if("D"===e.a.label||"T"===e.a.label)return!1;var n=_.get(e.a.label);return!n||Boolean(n.leftH)}if(1===e.a.neighbors.length){var r=e.a.neighbors[0];return t.halfBonds.get(r).dir.x>0}return!1}(t.molecule,this),this.showLabel=function(t,e,n){var r=Boolean(n.a.attachmentPoints),o="c"===n.a.label.toLowerCase(),i=e.showHydrogenLabels!==Kn.Off&&e.showHydrogenLabels!==Kn.Hetero,a=0===n.a.neighbors.length||n.a.neighbors.length<2&&i;if(r&&o)return!1;if(a||e.carbonExplicitly||e.showHydrogenLabels===Kn.On||n.a.alias||0!==n.a.isotope||0!==n.a.radical||0!==n.a.charge||n.a.explicitValence>=0||null!==n.a.atomList||null!==n.a.rglabel||n.a.badConn&&e.showValenceWarnings||"c"!==n.a.label.toLowerCase())return!0;if(2===n.a.neighbors.length){var s=n.a.neighbors[0],u=n.a.neighbors[1],l=t.molecule.halfBonds.get(s),c=t.molecule.halfBonds.get(u),d=t.bonds.get(l.bid),h=t.bonds.get(c.bid);if(d.b.type===h.b.type&&d.b.stereo===dt.PATTERN.STEREO.NONE&&h.b.stereo===dt.PATTERN.STEREO.NONE&&Math.abs($.cross(l.dir,c.dir))<.2)return!0}return!1}(t,s.options,this),this.color="black";var y=null;if(this.showLabel&&(g=function(t,e,n,r){var o={};if(o.text=function(t){if(null!==t.atomList)return t.atomList.label();if(t.pseudo)return t.pseudo;if(t.alias)return t.alias;if("R#"===t.label&&null!==t.rglabel){for(var e="",n=0;n<32;n++)t.rglabel&1<1?1:n.zoom),f=-g.rbb.width/2*(n.zoom>1?1:n.zoom),p=Math.floor(this.a.implicitH),m="H"===g.text,v="D"===g.text||"T"===g.text,t.addReObjectPath(jn.data,this.visel,g.path,u,!0)),n.showAtomIds){(y={}).text=e.toString();var b=this.hydrogenOnTheLeft?$.lc(u,1,new $({x:-2,y:0,z:0}),6):$.lc(u,1,new $({x:2,y:0,z:0}),6);this.showLabel&&(b=$.lc(b,1,new $({x:1,y:-3,z:0}),6)),y.path=s.paper.text(b.x,b.y,y.text).attr({font:n.font,"font-size":n.fontszsub,fill:"#070"}),y.rbb=Vn.relBox(y.path.getBBox()),Jn.recenterText(y.path,y.rbb),t.addReObjectPath(jn.indices,this.visel,y.path,u)}if(this.showLabel&&(!this.a.pseudo||v)){var w=null;if(m&&p>0&&(w=function(t,e,n,r){var o=gt.obj2scaled(t.a.pp,e.options),i=e.options,a=.5*i.lineWidth,s={};return s.text=(n+1).toString(),s.path=e.paper.text(o.x,o.y,s.text).attr({font:i.font,"font-size":i.fontszsub,fill:t.color}),s.rbb=Vn.relBox(s.path.getBBox()),Jn.recenterText(s.path,s.rbb),nr(s.path,s.rbb,r+.5*s.rbb.width+a,.2*t.label.rbb.height),s}(this,s,p,h),h+=w.rbb.width+d,t.addReObjectPath(jn.data,this.visel,w.path,u,!0)),0!==this.a.radical){var x=function(t,e){var n,r=gt.obj2scaled(t.a.pp,e.options),o=e.options,i=e.paper,a={};switch(t.a.radical){case 1:a.path=i.set(),n=1.6*o.lineWidth,a.path.push(Jn.radicalBullet(i,r.add(new $(-n,0)),o),Jn.radicalBullet(i,r.add(new $(n,0)),o)),a.path.attr("fill",t.color);break;case 2:a.path=i.set(),a.path.push(Jn.radicalBullet(i,r,o)),a.path.attr("fill",t.color);break;case 3:a.path=i.set(),n=1.6*o.lineWidth,a.path.push(Jn.radicalCap(i,r.add(new $(-n,0)),o),Jn.radicalCap(i,r.add(new $(n,0)),o)),a.path.attr("stroke",t.color)}a.rbb=Vn.relBox(a.path.getBBox());var s=-.5*(t.label.rbb.height+a.rbb.height);return 3===t.a.radical&&(s-=o.lineWidth/2),nr(a.path,a.rbb,0,s),a}(this,s);t.addReObjectPath(jn.data,this.visel,x.path,u,!0)}if(0!==this.a.isotope){var E=function(t,e,n){var r=gt.obj2scaled(t.a.pp,e.options),o=e.options,i=.5*o.lineWidth,a={};return a.text=t.a.isotope.toString(),a.path=e.paper.text(r.x,r.y,a.text).attr({font:o.font,"font-size":o.fontszsub,fill:t.color}),a.rbb=Vn.relBox(a.path.getBBox()),Jn.recenterText(a.path,a.rbb),nr(a.path,a.rbb,n-.5*a.rbb.width-i,-.3*t.label.rbb.height),a}(this,s,f);f-=E.rbb.width+d,t.addReObjectPath(jn.data,this.visel,E.path,u,!0)}if(!m&&!this.a.alias&&p>0&&function(t,e){var n,r;return t===Kn.On||t===Kn.Terminal&&e.a.neighbors.length<2||t===Kn.Hetero&&"c"!==(null===(n=e.label)||void 0===n?void 0:n.text.toLowerCase())||t===Kn.TerminalAndHetero&&(e.a.neighbors.length<2||"c"!==(null===(r=e.label)||void 0===r?void 0:r.text.toLowerCase()))}(n.showHydrogenLabels,this)){var P=function(t,e,n,r){var o=r.hydroIndex,i=t.hydrogenOnTheLeft,a=gt.obj2scaled(t.a.pp,e.options),s=e.options,u=.5*s.lineWidth,l=r.hydrogen;return l.text="H",l.path=e.paper.text(a.x,a.y,l.text).attr({font:s.font,"font-size":s.fontsz,fill:t.color}),l.rbb=Vn.relBox(l.path.getBBox()),Jn.recenterText(l.path,l.rbb),i||(nr(l.path,l.rbb,r.rightMargin+.5*l.rbb.width+u,0),r.rightMargin+=l.rbb.width+u),n>1&&((o={}).text=n.toString(),o.path=e.paper.text(a.x,a.y,o.text).attr({font:s.font,"font-size":s.fontszsub,fill:t.color}),o.rbb=Vn.relBox(o.path.getBBox()),Jn.recenterText(o.path,o.rbb),i||(nr(o.path,o.rbb,r.rightMargin+.5*o.rbb.width*(s.zoom>1?1:s.zoom)+u,.2*t.label.rbb.height),r.rightMargin+=o.rbb.width+u)),i&&(null!=o&&(nr(o.path,o.rbb,r.leftMargin-.5*o.rbb.width-u,.2*t.label.rbb.height),r.leftMargin-=o.rbb.width+u),nr(l.path,l.rbb,r.leftMargin-.5*l.rbb.width*(n>1&&s.zoom<1?s.zoom:1)-u,0),r.leftMargin-=l.rbb.width+u),Object.assign(r,{hydrogen:l,hydroIndex:o})}(this,s,p,{hydrogen:{},hydroIndex:w,rightMargin:h,leftMargin:f}),O=P.hydrogen;w=P.hydroIndex,h=P.rightMargin,f=P.leftMargin,t.addReObjectPath(jn.data,this.visel,O.path,u,!0),null!=w&&t.addReObjectPath(jn.data,this.visel,w.path,u,!0)}if(0!==this.a.charge&&n.showCharge){var A=function(t,e,n){var r=gt.obj2scaled(t.a.pp,e.options),o=e.options,i=.5*o.lineWidth,a={text:""},s=Math.abs(t.a.charge);return 1!==s&&(a.text=s.toString()),t.a.charge<0?a.text+="–":a.text+="+",a.path=e.paper.text(r.x,r.y,a.text).attr({font:o.font,"font-size":o.fontszsub,fill:t.color}),a.rbb=Vn.relBox(a.path.getBBox()),Jn.recenterText(a.path,a.rbb),nr(a.path,a.rbb,n+.5*a.rbb.width+i,-.3*t.label.rbb.height),a}(this,s,h);h+=A.rbb.width+d,t.addReObjectPath(jn.data,this.visel,A.path,u,!0)}if(this.a.explicitValence>=0&&n.showValence){var R=function(t,e,n){var r=gt.obj2scaled(t.a.pp,e.options),o=e.options,i=.5*o.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"}[t.a.explicitValence],!a.text)throw new Error("invalid valence "+t.a.explicitValence.toString());return a.text="("+a.text+")",a.path=e.paper.text(r.x,r.y,a.text).attr({font:o.font,"font-size":o.fontszsub,fill:t.color}),a.rbb=Vn.relBox(a.path.getBBox()),Jn.recenterText(a.path,a.rbb),nr(a.path,a.rbb,n+.5*a.rbb.width+i,-.3*t.label.rbb.height),a}(this,s,h);h+=R.rbb.width+d,t.addReObjectPath(jn.data,this.visel,R.path,u,!0)}if(this.a.badConn&&n.showValenceWarnings){var S=function(t,e,n,r){var o=gt.obj2scaled(t.a.pp,e.options),i=.5*e.options.lineWidth,a={},s=o.y+t.label.rbb.height/2+i;return a.path=e.paper.path("M{0},{1}L{2},{3}",H(o.x+n),H(s),H(o.x+r),H(s)).attr(e.options.lineattr).attr({stroke:"#F00"}),a.rbb=Vn.relBox(a.path.getBBox()),a}(this,s,f,h);t.addReObjectPath(jn.warnings,this.visel,S.path,u,!0)}y&&nr(y.path,y.rbb,-.5*g.rbb.width-.5*y.rbb.width-d,.3*g.rbb.height)}this.setHover(this.hover,s);var T=this.a.stereoLabel,k=function(t){var e="";if(t.a.aam>0&&(e+=t.a.aam),t.a.invRet>0)if(e.length>0&&(e+=","),1===t.a.invRet)e+="Inv";else{if(2!==t.a.invRet)throw new Error("Invalid value for the invert/retain flag");e+="Ret"}if(t.a.exactChangeFlag>0){if(e.length>0&&(e+=","),1!==t.a.exactChangeFlag)throw new Error("Invalid value for the exact change flag");e+="ext"}return e}(this),B=this.a.pseudo?"":function(t){var e="";if(0!==t.a.ringBondCount)if(t.a.ringBondCount>0)e+="rb"+t.a.ringBondCount.toString();else if(-1===t.a.ringBondCount)e+="rb0";else{if(-2!==t.a.ringBondCount)throw new Error("Ring bond count invalid");e+="rb*"}if(0!==t.a.substitutionCount)if(e.length>0&&(e+=","),t.a.substitutionCount>0)e+="s"+t.a.substitutionCount.toString();else if(-1===t.a.substitutionCount)e+="s0";else{if(-2!==t.a.substitutionCount)throw new Error("Substitution count invalid");e+="s*"}if(t.a.unsaturatedAtom>0){if(e.length>0&&(e+=","),1!==t.a.unsaturatedAtom)throw new Error("Unsaturated atom invalid value");e+="u"}return t.a.hCount>0&&(e.length>0&&(e+=","),e+="H"+(t.a.hCount-1).toString()),e}(this),C=Number(null===(r=t.atoms.get(e))||void 0===r?void 0:r.a.fragment),Z=t.molecule.frags.get(C),M=function(t,e,n,r){if(!t)return!1;var o=t.match(/\D+/g)[0];if(n&&o===J.Abs)return!1;if(n&&o!==J.Abs)return!0;switch(e){case Gn.Off:return!1;case Gn.On:return!0;case Gn.Classic:return!(r!==ct.Mixed&&o!==J.Or);case Gn.IUPAC:return!(r!==ct.Mixed||o===J.Abs);default:return!0}}(T,n.stereoLabelStyle,n.ignoreChiralFlag,null==Z?void 0:Z.enhancedStereoFlag),N="";if(M&&(N="".concat(T,"\n")),B.length>0&&(N+="".concat(B,"\n")),k.length>0&&(N+=".".concat(k,".")),N.length>0){var D=_.get(this.a.label),L=s.paper.text(u.x,u.y,N).attr({font:n.font,"font-size":n.fontszsub,fill:n.atomColoring&&D?I[this.a.label]:"#000"});if(T){var j=function(t,e){return e&&t.colorStereogenicCenters!==Fn.Off&&t.colorStereogenicCenters!==Fn.BondsOnly?er(t,e):"#000"}(s.options,T);L.node.childNodes[0].setAttribute("fill",j);var F=function(t,e){var n=e.match(/\D+/g)[0],r=+e.replace(n,"");return t.autoFadeOfStereoLabels&&n!==J.Abs&&t.colorStereogenicCenters!==Fn.Off&&t.colorStereogenicCenters!==Fn.BondsOnly?Math.max(1-(r-1)/10,.3):1}(s.options,T);L.node.childNodes[0].setAttribute("fill-opacity",F)}var G=Vn.relBox(L.getBBox());Jn.recenterText(L,G);for(var z=this.visel,U=3,V=this.bisectLargestSector(t.molecule),W=0;Wo&&(o=n[a],i=e[a]);return{neighborAngle:i,largestAngle:o}}},{key:"bisectLargestSector",value:function(t){var e,n=this.getLargestSectorFromNeighbors(t),r=n.largestAngle;return e=n.neighborAngle+r/2,new $(Math.cos(e),Math.sin(e))}}],[{key:"isSelectable",value:function(){return!0}}]),a}(zn);function er(t,e){switch(e.match(/\D+/g)[0]){case J.And:return t.colorOfAndCenters;case J.Or:return t.colorOfOrCenters;case J.Abs:return t.colorOfAbsoluteCenters;default:return"#000"}}function nr(t,e,n,r){t.translateAbs(n,r),e.x+=n,e.y+=r}function rr(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}var or=function(t){(0,f.Z)(u,t);var e,n,s=(e=u,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function u(t){var e;return(0,o.Z)(this,u),e=s.call(this,"bond"),(0,a.Z)((0,b.Z)(e),"neihbid1",-1),(0,a.Z)((0,b.Z)(e),"neihbid2",-1),e.b=t,e.doubleBondShift=0,e}return(0,i.Z)(u,[{key:"drawHover",value:function(t){var e=this.makeHoverPlate(t);return t.ctab.addReObjectPath(jn.hovering,this.visel,e),e}},{key:"getSelectionPoints",value:function(t){var e=this.b,n=t.ctab,r=t.options,o=r.bondThickness,i=r.doubleBondWidth,a=r.stereoBondWidth,s=i+o,u=n.molecule.halfBonds.get(e.hb1).p,l=n.molecule.halfBonds.get(e.hb2).p,c=e.stereo!==dt.PATTERN.STEREO.NONE&&e.stereo!==dt.PATTERN.STEREO.CIS_TRANS,d=c?0:-2,h=$.getLinePoint(l,u,d),f=$.getLinePoint(u,l,d),p=c?.5*a:s+.5,m=c?a+1*s/a:s+.5,v=$.getLinePoint(h,f,m),g=$.getLinePoint(f,h,p),y=h.add(new $(m,0)),b=f.add(new $(p,0)),w=v.add(new $(m,0)),x=g.add(new $(p,0)),E=e.angle,P=y.rotateAroundOrigin(E+90,new $(h.x,h.y)),O=y.rotateAroundOrigin(E-90,new $(h.x,h.y)),A=w.rotateAroundOrigin(E+90,v),R=w.rotateAroundOrigin(E-90,v),S=b.rotateAroundOrigin(E+90,f),T=b.rotateAroundOrigin(E-90,f);return[A,P,S,x.rotateAroundOrigin(E+90,g),x.rotateAroundOrigin(E-90,g),T,R,O]}},{key:"getSelectionContour",value:function(t){var e=t.paper,n=this.getSelectionPoints(t),o=(0,r.Z)(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 e.path(f)}},{key:"makeHoverPlate",value:function(t){var e=t.ctab,n=t.options;u.bondRecalc(this,e,n);var r=this.b,o=e.sgroups,i=e.molecule.functionalGroups;return Lt.isBondInContractedFunctionalGroup(r,o,i)?null:this.getSelectionContour(t).attr(function(t){for(var e=1;e=0&&r[1]>=0}(e,this,t),u.bondRecalc(this,t,n),function(t,e){var n=t.b.hb1,r=t.b.hb2;if(!n&&0!==n||!r&&0!==r)t.doubleBondShift=fr(e,t);else{var o=e.halfBonds.get(n).loop,i=e.halfBonds.get(r).loop;if(o>=0&&i>=0){var a=e.loops.get(o).dblBonds,s=e.loops.get(i).dblBonds,u=e.loops.get(o).hbs.length,l=e.loops.get(i).hbs.length;t.doubleBondShift=function(t,e,n,r){return 6===t&&6!==e&&(n>1||1===r)?-1:6===e&&6!==t&&(r>1||1===n)?1:e*n>t*r?-1:e*nt?-1:1}(u,l,a,s)}else t.doubleBondShift=o>=0?-1:i>=0?1:fr(e,t)}}(this,o),c&&d){var h=t.isSnappingBond(e);this.path=function(t,e,n,r,o){var i,a,s,u=null,l=t.render,c=t.molecule,d=!(null!==(i=t.atoms.get(n.begin))&&void 0!==i&&i.showLabel),h=!(null!==(a=t.atoms.get(r.begin))&&void 0!==a&&a.showLabel);switch(e.b.type){case dt.PATTERN.TYPE.SINGLE:switch(e.b.stereo){case dt.PATTERN.STEREO.UP:ar(n.bid,e,t),u=e.boldStereo&&e.neihbid1>=0&&e.neihbid2>=0?ur(l,n,r,e,c,o):function(t,e,n,r,o,i){var a=e.p,s=n.p,u=e.norm,l=t.options,c=.7*l.stereoBond,d=s.addScaled(u,c),h=s.addScaled(u,-c);if(r.neihbid2>=0){var f=cr(n,r.neihbid2,l.stereoBond,o);d=f[0],h=f[1]}return Jn.bondSingleUp(t.paper,a,d,h,l,i,sr(l,r,o))}(l,n,r,e,c,o);break;case dt.PATTERN.STEREO.DOWN:u=function(t,e,n,r,o,i){var a=e.p,s=n.p,u=t.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 Jn.bondSingleDown(t.paper,e,l,h,f,u,i,sr(u,r,o))}(l,n,r,e,c,o);break;case dt.PATTERN.STEREO.EITHER:u=function(t,e,n,r,o,i){var a=e.p,s=n.p,u=t.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 Jn.bondSingleEither(t.paper,e,l,h,f,u,i,sr(u,r,o))}(l,n,r,e,c,o);break;default:u=Jn.bondSingle(l.paper,n,r,l.options,o,sr(l.options,e,c))}break;case dt.PATTERN.TYPE.DOUBLE:ar(n.bid,e,t),u=e.b.stereo===dt.PATTERN.STEREO.NONE&&e.boldStereo&&e.neihbid1>=0&&e.neihbid2>=0?function(t,e,n,r,o,i,a,s){var u=e.p,l=n.p,c=e.norm,d=r.doubleBondShift,h=1.5*t.options.stereoBond,f=u.addScaled(c,h*d),p=l.addScaled(c,h*d);d>0?(i&&(f=f.addScaled(e.dir,h*lr(e.rightCos,e.rightSin))),a&&(p=p.addScaled(e.dir,-h*lr(n.leftCos,n.leftSin)))):d<0&&(i&&(f=f.addScaled(e.dir,h*lr(e.leftCos,e.leftSin))),a&&(p=p.addScaled(e.dir,-h*lr(n.rightCos,n.rightSin))));var m=ur(t,e,n,r,o,s);return Jn.bondDoubleStereoBold(t.paper,m,f,p,t.options,s,sr(t.options,r,o))}(l,n,r,e,c,d,h,o):function(t,e,n,r,o,i,a){var s=r.b.stereo===dt.PATTERN.STEREO.CIS_TRANS,u=e.p,l=n.p,c=e.norm,d=s?0:r.doubleBondShift,h=t.options,f=h.bondSpace/2,p=f+d*f,m=d*f-f,v=u.addScaled(c,p),g=l.addScaled(c,p),y=u.addScaled(c,m),b=l.addScaled(c,m);return d>0?(o&&(v=v.addScaled(e.dir,h.bondSpace*lr(e.rightCos,e.rightSin))),i&&(g=g.addScaled(e.dir,-h.bondSpace*lr(n.leftCos,n.leftSin)))):d<0&&(o&&(y=y.addScaled(e.dir,h.bondSpace*lr(e.leftCos,e.leftSin))),i&&(b=b.addScaled(e.dir,-h.bondSpace*lr(n.rightCos,n.rightSin)))),Jn.bondDouble(t.paper,v,y,g,b,s,h,a)}(l,n,r,e,d,h,o);break;case dt.PATTERN.TYPE.TRIPLE:u=Jn.bondTriple(l.paper,n,r,l.options,o);break;case dt.PATTERN.TYPE.AROMATIC:var f,p;u=n.loop>=0&&(null===(f=c.loops.get(n.loop))||void 0===f?void 0:f.aromatic)||r.loop>=0&&(null===(p=c.loops.get(r.loop))||void 0===p?void 0:p.aromatic)?Jn.bondSingle(l.paper,n,r,l.options,o):dr(l,n,r,e,d,h,o);break;case dt.PATTERN.TYPE.SINGLE_OR_DOUBLE:u=function(t,e,n,r){var o=e.p,i=n.p,a=t.options,s=$.dist(o,i)/Number((a.bondSpace+a.lineWidth).toFixed());return 1&s||(s+=1),Jn.bondSingleOrDouble(t.paper,e,n,s,a,r)}(l,(s=Vn.updateHalfBondCoordinates(n,r,1))[0],s[1],o);break;case dt.PATTERN.TYPE.SINGLE_OR_AROMATIC:u=dr(l,n,r,e,d,h,o);break;case dt.PATTERN.TYPE.DOUBLE_OR_AROMATIC:u=dr(l,(s=Vn.updateHalfBondCoordinates(n,r,-1))[0],s[1],e,d,h,o);break;case dt.PATTERN.TYPE.ANY:s=Vn.updateHalfBondCoordinates(n,r,-1),u=Jn.bondAny(l.paper,s[0],s[1],l.options,o);break;case dt.PATTERN.TYPE.HYDROGEN:s=Vn.updateHalfBondCoordinates(n,r,1),u=Jn.bondHydrogen(l.paper,s[0],s[1],l.options,o);break;case dt.PATTERN.TYPE.DATIVE:u=Jn.bondDative(l.paper,n,r,l.options,o);break;default:throw new Error("Bond type "+e.b.type+" not supported")}if(u){var m=l.options.previewOpacity;u.attr({opacity:e.b.isPreview?m:1})}return u}(t,this,c,d,h),this.rbb=Vn.relBox(this.path.getBBox()),t.addReObjectPath(jn.bondSkeleton,this.visel,this.path,null,!0);var f={};f.path=function(t,e,n,r){var o=n.p,i=r.p,a=i.add(o).scaled(.5),s=i.sub(o).normalized(),u=s.rotateSC(1,0),l=[],c=t.options.lineWidth,d=t.options.bondSpace/2,h=c,f=2*c,p=1.5*d,m=1.5*d,v=3*d,g=.2;switch(e.b.reactingCenterStatus){case dt.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 dt.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,p).addScaled(u,m)),l.push(a.addScaled(s,-p).addScaled(u,m)),l.push(a.addScaled(s,p).addScaled(u,-m)),l.push(a.addScaled(s,-p).addScaled(u,-m));break;case dt.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 dt.PATTERN.REACTING_CENTER.ORDER_CHANGED:l.push(a.addScaled(u,v)),l.push(a.addScaled(u,-v));break;case dt.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 Jn.reactingCenter(t.paper,l,t.options)}(r,this,c,d),f.path&&(f.rbb=Vn.relBox(f.path.getBBox()),t.addReObjectPath(jn.data,this.visel,f.path,null,!0));var p={};p.path=function(t,e,n,r){var o=t.options,i=null;if(e.b.topology===dt.PATTERN.TOPOLOGY.RING)i="rng";else{if(e.b.topology!==dt.PATTERN.TOPOLOGY.CHAIN)return null;i="chn"}var a=n.p,s=r.p,u=s.add(a).scaled(.5),l=s.sub(a).normalized().rotateSC(1,0),c=o.lineWidth;e.doubleBondShift>0?l=l.scaled(-e.doubleBondShift):0===e.doubleBondShift&&(c+=o.bondSpace/2);var d=new $(2,1).scaled(o.bondSpace);e.b.type===dt.PATTERN.TYPE.TRIPLE&&(c+=o.bondSpace);var h=u.add(new $(l.x*(d.x+c),l.y*(d.y+c)));return Jn.topologyMark(t.paper,h,i,o)}(r,this,c,d),p.path&&(p.rbb=Vn.relBox(p.path.getBBox()),t.addReObjectPath(jn.data,this.visel,p.path,null,!0)),this.setHover(this.hover,r);var m=null,v=.6*n.subFontSize;n.showBondIds&&(m=hr(e,l,c,d,v,.5,.5,c.norm),t.addReObjectPath(jn.indices,this.visel,m)),n.showHalfBondIds&&(m=hr(this.b.hb1,l,c,d,v,.8,.2,c.norm),t.addReObjectPath(jn.indices,this.visel,m),m=hr(this.b.hb2,l,c,d,v,.2,.8,d.norm),t.addReObjectPath(jn.indices,this.visel,m)),n.showLoopIds&&!n.showBondIds&&(m=hr(c.loop,l,c,d,v,.5,.5,d.norm),t.addReObjectPath(jn.indices,this.visel,m),m=hr(d.loop,l,c,d,v,.5,.5,c.norm),t.addReObjectPath(jn.indices,this.visel,m));var g=t.molecule.highlights,y=!1,b="";if(g.forEach((function(t){var n,r=null===(n=t.bonds)||void 0===n?void 0:n.includes(e);y=y||r,r&&(b=t.color)})),y){var w={fill:b,stroke:b,"stroke-width":7*n.lineattr["stroke-width"],"stroke-linecap":"round"},x=gt.obj2scaled(this.b.center,t.render.options),E=function(t,e,n){var r={x:e.p.x,y:e.p.y},o={x:n.p.x,y:n.p.y},i=t.render.paper,a="M".concat(r.x,",").concat(r.y," L").concat(o.x,",").concat(o.y);return i.path(a)}(t,c,d);E.attr(w),t.addReObjectPath(jn.hovering,this.visel,E,x,!0)}i.cip&&(this.cip=Vn.drawCIPLabel({atomOrBond:i,position:i.center,restruct:r.ctab,visel:this.visel}))}}}}],[{key:"isSelectable",value:function(){return!0}},{key:"bondRecalc",value:function(t,e,n){var r=e.render,o=e.atoms.get(t.b.begin),i=e.atoms.get(t.b.end);if(o&&i&&void 0!==t.b.hb1&&void 0!==t.b.hb2){var a=gt.obj2scaled(o.a.pp,r.options),s=gt.obj2scaled(i.a.pp,r.options),u=e.molecule.halfBonds.get(t.b.hb1),l=e.molecule.halfBonds.get(t.b.hb2);null!=u&&u.dir&&null!=l&&l.dir&&(u.p=o.getShiftedSegmentPosition(n,u.dir),l.p=i.getShiftedSegmentPosition(n,l.dir),t.b.center=$.lc2(o.a.pp,.5,i.a.pp,.5),t.b.len=$.dist(a,s),t.b.sb=5*n.lineWidth,t.b.sa=Math.max(t.b.sb,t.b.len/2-2*n.lineWidth),t.b.angle=180*Math.atan2(u.dir.y,u.dir.x)/Math.PI)}}}]),u}(zn);function ir(t,e,n,r){return t.neighbors.findIndex((function(t){var o=r.molecule.halfBonds.get(t);if(!o||o.bid===e)return!1;var i=r.bonds.get(o.bid);return!!i&&(i.b.type===dt.PATTERN.TYPE.SINGLE&&i.b.stereo===dt.PATTERN.STEREO.UP?i.b.end===o.begin||i.boldStereo&&n:!(i.b.type!==dt.PATTERN.TYPE.DOUBLE||i.b.stereo!==dt.PATTERN.STEREO.NONE||!n||!i.boldStereo))}))}function ar(t,e,n){var r,o,i=[e.b.begin,e.b.end].map((function(e){var r=n.molecule.atoms.get(e);if(!r)return-1;var o=ir(r,t,!0,n);return o<0?-1:r.neighbors[o]}));e.neihbid1=null!==(r=n.atoms.get(e.b.begin))&&void 0!==r&&r.showLabel?-1:i[0],e.neihbid2=null!==(o=n.atoms.get(e.b.end))&&void 0!==o&&o.showLabel?-1:i[1]}function sr(t,e,n){var r,o,i="#000";if(0===e.b.stereo)return i;var a=null===(r=n.atoms.get(e.b.begin))||void 0===r?void 0:r.stereoLabel,s=null===(o=n.atoms.get(e.b.end))||void 0===o?void 0:o.stereoLabel,u="";return a&&!s?u=a:!a&&s&&(u=s),u&&t.colorStereogenicCenters!==Fn.Off&&t.colorStereogenicCenters!==Fn.LabelsOnly?er(t,u):i}function ur(t,e,n,r,o,i){var a=t.options,s=cr(e,r.neihbid1,a.stereoBond,o),u=cr(n,r.neihbid2,a.stereoBond,o),l=s[0],c=s[1],d=u[0],h=u[1];return Jn.bondSingleStereoBold(t.paper,l,c,d,h,a,i,sr(a,r,o))}function lr(t,e){return e<0||Math.abs(t)>.9?0:e/(1-t)}function cr(t,e,n,r){var o=r.halfBonds.get(e),i=$.dot(t.dir,o.dir),a=$.cross(t.dir,o.dir),s=Math.sqrt(.5*(1-i)),u=o.dir.rotateSC((a>=0?-1:1)*s,Math.sqrt(.5*(1+i))),l=t.p.addScaled(u,.7*n/(s+.3)),c=t.p.addScaled(u.negated(),.7*n/(s+.3));return a>0?[l,c]:[c,l]}function dr(t,e,n,r,o,i,a){var s=[.125,.125,.005,.125],u=0,l=null,c=t.options,d=r.doubleBondShift;r.b.type===dt.PATTERN.TYPE.SINGLE_OR_AROMATIC&&(u=d>0?1:2,l=s.map((function(t){return t*c.scale}))),r.b.type===dt.PATTERN.TYPE.DOUBLE_OR_AROMATIC&&(u=3,l=s.map((function(t){return t*c.scale})));var h=function(t,e,n,r,o,i,a,s){var u=t.p,l=e.p,c=t.norm,d=i/2,h=d+n*d,f=n*d-d,p=u.addScaled(c,h),m=l.addScaled(c,h),v=u.addScaled(c,f),g=l.addScaled(c,f);return n>0?(r&&(p=p.addScaled(t.dir,i*lr(t.rightCos,t.rightSin))),o&&(m=m.addScaled(t.dir,-i*lr(e.leftCos,e.leftSin)))):n<0&&(r&&(v=v.addScaled(t.dir,i*lr(t.leftCos,t.leftSin))),o&&(g=g.addScaled(t.dir,-i*lr(e.rightCos,e.rightSin)))),Jn.aromaticBondPaths(p,v,m,g,a,s)}(e,n,d,o,i,c.bondSpace,u,l);return Jn.bondAromatic(t.paper,h,d,c,a)}function hr(t,e,n,r,o,i,a,s){var u=$.lc(n.p,i,r.p,a,s,o),l=e.text(u.x,u.y,t.toString()),c=Vn.relBox(l.getBBox());return Jn.recenterText(l,c),l}function fr(t,e){if(!e.b.hb1&&0!==e.b.hb1||!e.b.hb2&&0!==e.b.hb2)return 0;var n=t.halfBonds.get(e.b.hb1),r=t.halfBonds.get(e.b.hb2);if(!n||!r)return 0;var o=(n.leftSin>.3?1:0)+(r.rightSin>.3?1:0),i=(r.leftSin>.3?1:0)+(n.rightSin>.3?1:0);return o>i?-1:o.3?1:0)+(n.rightSin>.3?1:0)==1?1:0}var pr=new WeakMap,mr=function(t){(0,f.Z)(s,t);var e,n,r=(e=s,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function s(){var t,e,n,i;return(0,o.Z)(this,s),t=r.call(this,"enhancedFlag"),e=(0,b.Z)(t),i={writable:!0,value:void 0},function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,n=pr),n.set(e,i),t}return(0,i.Z)(s,[{key:"hoverPath",value:function(t){var e=Et.fromRelBox((0,y.Z)(this,pr).getBBox()),n=e.p1.sub(e.p0),r=e.p0.sub(t.options.offset);return t.paper.rect(r.x,r.y,n.x,n.y)}},{key:"drawHover",value:function(t){var e;if(null===(e=(0,y.Z)(this,pr))||void 0===e||!e.attrs)return null;var n=this.hoverPath(t).attr(t.options.hoverStyle);return t.ctab.addReObjectPath(jn.hovering,this.visel,n),n}},{key:"makeSelectionPlate",value:function(t,e,n){var r;return null!==(r=(0,y.Z)(this,pr))&&void 0!==r&&r.attrs?this.hoverPath(t.render).attr(n.selectionStyle):null}},{key:"show",value:function(t,e,n){var r,o=t.render,i=t.molecule.frags.get(e);if(null!=i&&i.enhancedStereoFlag){var s=i.stereoFlagPosition?i.stereoFlagPosition:vt.getDefaultStereoFlagPosition(t.molecule,e),u=o.paper,l=gt.obj2scaled(s,n),c=(r={},(0,a.Z)(r,ct.Abs,n.absFlagLabel),(0,a.Z)(r,ct.And,n.andFlagLabel),(0,a.Z)(r,ct.Mixed,n.mixedFlagLabel),(0,a.Z)(r,ct.Or,n.orFlagLabel),r);n.showStereoFlags&&!n.ignoreChiralFlag&&(0,g.Z)(this,pr,u.text(l.x,l.y,i.enhancedStereoFlag?c[i.enhancedStereoFlag]:"").attr({font:n.font,"font-size":n.fontsz,fill:"#000"})),o.ctab.addReObjectPath(jn.data,this.visel,(0,y.Z)(this,pr),null,!0)}}}],[{key:"isSelectable",value:function(){return!0}}]),s}(zn);var vr=function(t){(0,f.Z)(s,t);var e,r,a=(e=s,r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,n=(0,m.Z)(e);if(r){var o=(0,m.Z)(this).constructor;t=Reflect.construct(n,arguments,o)}else t=n.apply(this,arguments);return(0,p.Z)(this,t)});function s(t){var e;return(0,o.Z)(this,s),(e=a.call(this,"frag")).item=t,e}return(0,i.Z)(s,[{key:"fragGetAtoms",value:function(t,e){return Array.from(t.atoms.keys()).filter((function(n){return t.atoms.get(n).a.fragment===e}))}},{key:"fragGetBonds",value:function(t,e){return Array.from(t.bonds.keys()).filter((function(n){var r=t.bonds.get(n).b,o=t.atoms.get(r.begin).a.fragment,i=t.atoms.get(r.end).a.fragment;return o===e&&i===e}))}},{key:"calcBBox",value:function(t,e,r){var o;return t.atoms.forEach((function(t){if(t.a.fragment===e){var i=t.visel.boundingBox;if(i)r||(r=n.g._ui_editor.render),i=i.translate((r.options.offset||new $).negated()).transform(gt.scaled2obj,r.options);else{i=new Et(t.a.pp,t.a.pp);var a=new $(.05*3,.05*3);i=i.extend(a,a)}o=o?Et.union(o,i):i}})),o}},{key:"_draw",value:function(t,e,n){var r=this.calcBBox(t.ctab,e,t);if(r){var o=gt.obj2scaled(new $(r.p0.x,r.p0.y),t.options),i=gt.obj2scaled(new $(r.p1.x,r.p1.y),t.options);return t.paper.rect(o.x,o.y,i.x-o.x,i.y-o.y,0).attr(n)}}},{key:"draw",value:function(t){return null}},{key:"drawHover",value:function(t){}},{key:"setHover",value:function(t,e){var n=e.ctab.frags.keyOf(this);(n||0===n)&&(n=parseInt(n,10),e.ctab.atoms.forEach((function(r){r.a.fragment===n&&r.setHover(t,e)})),e.ctab.bonds.forEach((function(r){e.ctab.atoms.get(r.b.begin).a.fragment===n&&r.setHover(t,e)})))}}],[{key:"isSelectable",value:function(){return!1}}]),s}(zn);var gr=new $(.05*3,.05*3),yr=new $(.2,.4),br=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t){var e;return(0,o.Z)(this,a),(e=r.call(this,"rgroup")).labelBox=null,e.item=t,e}return(0,i.Z)(a,[{key:"getAtoms",value:function(t){var e=[];return this.item.frags.forEach((function(n){e=e.concat(t.ctab.frags.get(n).fragGetAtoms(t.ctab,n))})),e}},{key:"getBonds",value:function(t){var e=[];return this.item.frags.forEach((function(n){e=e.concat(t.ctab.frags.get(n).fragGetBonds(t.ctab,n))})),e}},{key:"calcBBox",value:function(t){var e=null;this.item.frags.forEach((function(n){var r=t.ctab.frags.get(n).calcBBox(t.ctab,n,t);r&&(e=e?Et.union(e,r):r)}));var n=t.ctab.getRGroupAttachmentPointsVBoxByAtomIds(this.getAtoms(t));return e&&n&&(e=Et.union(e,n)),e=e?e.extend(gr,gr):e}},{key:"draw",value:function(t,e){var n=this.calcBBox(t);if(!n)return{};n=n.extend(yr,yr);var r={data:[]},o=gt.obj2scaled(n.p0,e),i=gt.obj2scaled(n.p1,e),a=t.paper.set();(function(t,e,n,r){r=gt.obj2scaled(r||new $(1,0),e.options);var o=Math.min(.25,.3*n.sz().x),i=n.p1.y-n.p0.y,a=.5*(n.p1.y+n.p0.y),s=Jn.bracket(e.paper,r.negated(),r.negated().rotateSC(1,0),gt.obj2scaled(new $(n.p0.x,a),e.options),o,i,e.options),u=Jn.bracket(e.paper,r,r.rotateSC(1,0),gt.obj2scaled(new $(n.p1.x,a),e.options),o,i,e.options);t.push(s,u)})(a,t,n),r.data.push(a);var s=t.ctab.rgroups.keyOf(this),u=t.paper.set(),l=t.paper.text(o.x,(o.y+i.y)/2,"R"+s+"=").attr({font:e.font,"font-size":e.fontRLabel,fill:"black"}),c=Vn.relBox(l.getBBox());l.translateAbs(-c.width/2-e.lineWidth,0),u.push(l);for(var d={font:e.font,"font-size":e.fontRLogic,fill:"black"},h=[wr(s,this.item)],f=c.height/2+e.lineWidth/2,p=0;p0;)t.addReObjectPath(jn.data,r.visel,o[e].shift(),null,!0)}))}}],[{key:"isSelectable",value:function(){return!1}}]),a}(zn);function wr(t,e){var n,r=e.ifthen>0?"IF ":"",o=e.range.startsWith(">")||e.range.startsWith("<")||e.range.startsWith("=");n=e.range.length>0?o?e.range:"="+e.range:">0";var i=e.resth?" (RestH)":"",a=e.ifthen>0?"\nTHEN R"+e.ifthen.toString():"";return"".concat(r,"R").concat(t.toString()).concat(n).concat(i).concat(a)}function xr(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Er(t){for(var e=1;e0){if(n.xe.x)return new $(null==c?void 0:c.x,null==c?void 0:c.y);if(n.x===e.x){if(n.y>e.y)return new $(null==c?void 0:c.x,null==c?void 0:c.y);if(n.ye.x)return new $(null==l?void 0:l.x,null==l?void 0:l.y);if(n.xe.y)return new $(null==l?void 0:l.x,null==l?void 0:l.y);if(n.yMath.max(t[0].x,t[1].x))&&(e.yMath.max(t[0].y,t[1].y)))n=Math.min($.dist(t[0],e),$.dist(t[1],e));else{var r=$.dist(t[0],t[1]),o=$.dist(t[0],e),i=$.dist(t[1],e),a=(r+o+i)/2;n=2/r*Math.sqrt(a*(a-r)*(a-o)*(a-i))}return n}var Ar=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t){var e;return(0,o.Z)(this,a),(e=r.call(this,"rxnPlus")).item=t,e}return(0,i.Z)(a,[{key:"hoverPath",value:function(t){var e=gt.obj2scaled(this.item.pp,t.options),n=t.options.scale;return t.paper.rect(e.x-n/4,e.y-n/4,n/2,n/2,n/8)}},{key:"drawHover",value:function(t){var e=this.hoverPath(t).attr(t.options.hoverStyle);return t.ctab.addReObjectPath(jn.hovering,this.visel,e),e}},{key:"makeSelectionPlate",value:function(t,e,n){return this.hoverPath(t.render).attr(n.selectionStyle)}},{key:"show",value:function(t,e,n){var r=t.render,o=gt.obj2scaled(this.item.pp,n),i=Jn.plus(r.paper,o,n),a=n.offset;null!=a&&i.translateAbs(a.x,a.y),this.visel.add(i,Et.fromRelBox(Vn.relBox(i.getBBox())))}}],[{key:"isSelectable",value:function(){return!0}}]),a}(zn);var Rr=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t){var e;return(0,o.Z)(this,a),(e=r.call(this,"sgroupData")).sgroup=t,e}return(0,i.Z)(a,[{key:"hoverPath",value:function(t){var e=this.sgroup.dataArea,n=gt.obj2scaled(e.p0,t.options),r=gt.obj2scaled(e.p1,t.options).sub(n);return t.paper.rect(n.x,n.y,r.x,r.y)}},{key:"drawHover",value:function(t){var e=this.hoverPath(t).attr(t.options.hoverStyle);return t.ctab.addReObjectPath(jn.hovering,this.visel,e),e}},{key:"makeSelectionPlate",value:function(t,e,n){return this.hoverPath(t.render).attr(n.selectionStyle)}}],[{key:"isSelectable",value:function(){return!0}}]),a}(zn);var Sr=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t){var e;return(0,o.Z)(this,a),(e=r.call(this,"sgroup")).item=t,e}return(0,i.Z)(a,[{key:"draw",value:function(t,e){this.render=t.render;var n=this.render.paper.set(),r=new et(e.atoms),o=Zt.getCrossBonds(t.molecule,r);Zt.bracketPos(e,t.molecule,o,t,this.render);var i=e.bracketBox,a=e.bracketDirection;if(e.areas=[i],e.isExpanded()){var s={set:n,render:this.render,sgroup:e,crossBonds:o,atomSet:r,bracketBox:i,d:a};switch(e.type){case"MUL":s.lowerIndexText=e.data.mul;break;case"SRU":var u=e.data.connectivity||"eu";"ht"===u&&(u="");var l=e.data.subscript||"n";s.lowerIndexText=l,s.upperIndexText=u;break;case"SUP":s.lowerIndexText=e.data.name,s.upperIndexText=null,s.indexAttribute={"font-style":"italic"};break;case"GEN":break;case"DAT":n=function(t,e){return Zt.bracketPos(e,t.molecule),e.areas=e.bracketBox?[e.bracketBox]:[],null===e.pp&&e.calculatePP(t.molecule),e.data.attached?function(t,e){var n=t.render,r=n.options,o=n.paper,i=o.set();return Zt.getAtoms(t,e).forEach((function(a){var s=t.atoms.get(a);if(s){var u=gt.obj2scaled(s.a.pp,r),l=s.visel.boundingBox;null!==l&&(u.x=Math.max(u.x,l.p1.x)),u.x+=r.lineWidth;var c=Tr(o,u,e,r),d=Vn.relBox(c.getBBox());c.translateAbs(.5*d.width,-.3*d.height),i.push(c);var h=Et.fromRelBox(Vn.relBox(c.getBBox()));h=h.transform(gt.scaled2obj,n.options),e.areas.push(h)}})),i}(t,e):function(t,e){var n,r=t.render,o=r.options,i=r.paper,a=i.set(),s=Tr(i,null==e||null===(n=e.pp)||void 0===n?void 0:n.scaled(o.scale),e,o);if(e.data.context!==Rt.Bond){var u=Vn.relBox(s.getBBox());s.translateAbs(.5*u.width,-.5*u.height)}a.push(s);var l=Et.fromRelBox(Vn.relBox(s.getBBox()));return e.dataArea=l.transform(gt.scaled2obj,r.options),t.sgroupData.has(e.id)||t.sgroupData.set(e.id,new Rr(e)),a}(t,e)}(t,e)}["MUL","SRU","SUP","GEN"].includes(e.type)&&function(t){for(var e=t.set,n=t.render,r=t.sgroup,o=t.crossBonds,i=t.atomSet,a=t.bracketBox,s=t.d,u=t.lowerIndexText,l=t.upperIndexText,c=t.indexAttribute,d=function(t,e,n,r,o,i,a){var s=function(t,e,n,r){return{c:t,d:e,h:r,n:e.rotateSC(1,0),w:n}},u=[],l=o.rotateSC(1,0),c=Object.values(e),d=c.flat();return d.length<2?function(){o=o||new $(1,0),l=l||o.rotateSC(1,0);var t=Math.min(.25,.3*r.sz().x),e=$.lc2(o,r.p0.x,l,.5*(r.p0.y+r.p1.y)),n=$.lc2(o,r.p1.x,l,.5*(r.p0.y+r.p1.y)),i=r.sz().y;u.push(s(e,o.negated(),t,i),s(n,o,t,i))}():2===d.length&&2===c.length?function(){var e=t.bonds.get(Number(d[0])),n=t.bonds.get(Number(d[1]));if(e&&n){var r,o=e.getCenter(t),l=n.getCenter(t),c=-1,h=-1,f=-1,p=-1,m=$.centre(o,l),v=$.diff(l,o).normalized(),g=v.negated(),y=v.rotateSC(1,0),b=y.negated();null==t||null===(r=t.sGroupForest)||void 0===r||null===(r=r.children)||void 0===r||null===(r=r.get(a))||void 0===r||r.forEach((function(t){var e,n,r=null==i||null===(e=i.ctab)||void 0===e||null===(e=e.sgroups)||void 0===e||null===(e=e.get(t))||void 0===e?void 0:e.visel.boundingBox;r=(null===(n=r)||void 0===n?void 0:n.translate((i.options.offset||new $).negated()).transform(gt.scaled2obj,i.options))||new Et,c=Math.max(c,Vn.shiftRayBox(o,g,r)),h=Math.max(h,Vn.shiftRayBox(l,v,r)),f=Math.max(f,Vn.shiftRayBox(m,y,r)),p=Math.max(p,Vn.shiftRayBox(m,b,r))})),c=Math.max(c+.2,0),h=Math.max(h+.2,0);var w=.25,x=1.5+(f=Math.max(Math.max(f,p)+.1,0));u.push(s(o.addScaled(g,c),g,w,x),s(l.addScaled(v,h),v,w,x))}}():function(){for(var e=0;ep.d.y)&&(h=f)}var v=d[h];function g(t,r){var o=gt.obj2scaled(v.c.addScaled(v.n,r*v.h),n.options),i=n.paper.text(o.x,o.y,t).attr({font:n.options.font,"font-size":n.options.fontszsub});c&&i.attr(c);var a=Et.fromRelBox(Vn.relBox(i.getBBox())),s=Math.max(Vn.shiftRayBox(o,v.d.negated(),a),3)+2;i.translateAbs(s*v.d.x,s*v.d.y),e.push(i)}u&&g(u,.5),l&&g(l,-.5)}(s)}return n}},{key:"getTextHighlightDimensions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1?arguments[1]:void 0,n=0,r=0,o=0,i=0,a=this.item;if(a){var s=a.getContractedPosition(e.ctab.molecule),u=s.atomId,l=s.position;if(null!=a&&a.isContracted()&&l){var c=e.ctab.atoms.get(u),d=(null==c?void 0:c.visel.boundingBox)||(null==c?void 0:c.visel.oldBoundingBox);if(d){var h=gt.obj2scaled(l,e.options),f=h.x,p=h.y,m=d.p0,v=d.p1;n=f-(o=v.x-m.x+2*t)/2,r=p-(i=v.y-m.y+2*t)/2}}}return{startX:n,startY:r,width:o,height:i}}},{key:"getContractedSelectionContour",value:function(t){var e=t.paper,n=t.options,r=n.fontsz,o=r*n.radiusScaleFactor*2,i=this.getTextHighlightDimensions(r/2,t),a=i.startX,s=i.startY,u=i.width,l=i.height;return e.rect(a,s,u,l,o)}},{key:"makeSelectionPlate",value:function(t,e,n){var r=this.item,o=t.molecule.functionalGroups,i=t.render;if(Lt.isContractedFunctionalGroup(null==r?void 0:r.id,o))return this.getContractedSelectionContour(i).attr(n.selectionStyle)}},{key:"drawHover",value:function(t){var e=t.options,n=t.paper,r=this.item;if(r){var o=function(t,e){var n=e.options,r=t.bracketBox.transform(gt.obj2scaled,n),o=n.lineWidth,i=new $(4*o,6*o);r=r.extend(i,i);var a=t.bracketDirection,s=a.rotateSC(1,0),u=$.lc2(a,r.p0.x,s,r.p0.y),l=$.lc2(a,r.p0.x,s,r.p1.y),c=$.lc2(a,r.p1.x,s,r.p0.y),d=$.lc2(a,r.p1.x,s,r.p1.y),h=n.contractedFunctionalGroupSize,f=(c.x+u.x)/2-h/2,p=(l.y+u.y)/2-h/2,m=t.getContractedPosition(e.ctab.molecule).position;if(m){var v=new $(h/2,h/2,0),g=$.diff(m.scaled(40),v);f=g.x,p=g.y}return{a0:u,a1:l,b0:c,b1:d,startX:f,startY:p,size:h}}(r,t),i=o.a0,a=o.a1,s=o.b0,u=o.b1,l=t.ctab.molecule.functionalGroups,c=n.set();Lt.isContractedFunctionalGroup(r.id,l)?r.hovering=this.getContractedSelectionContour(t).attr(e.hoverStyle):this.selected||(r.hovering=n.path("M{0},{1}L{2},{3}L{4},{5}L{6},{7}L{0},{1}",H(i.x),H(i.y),H(a.x),H(a.y),H(u.x),H(u.y),H(s.x),H(s.y)).attr(e.hoverStyle)),c.push(r.hovering),Zt.getAtoms(t.ctab.molecule,r).forEach((function(e){var n;c.push(null==t||null===(n=t.ctab)||void 0===n||null===(n=n.atoms)||void 0===n||null===(n=n.get(e))||void 0===n?void 0:n.makeHoverPlate(t))}),this),Zt.getBonds(t.ctab.molecule,r).forEach((function(e){var n;c.push(null==t||null===(n=t.ctab)||void 0===n||null===(n=n.bonds)||void 0===n||null===(n=n.get(e))||void 0===n?void 0:n.makeHoverPlate(t))}),this),t.ctab.addReObjectPath(jn.hovering,this.visel,c)}}},{key:"show",value:function(t){var e=t.render,n=this.item;if(n&&"MRV_IMPLICIT_H"!==n.data.fieldName){var r=e.ctab,o=this.draw(r,n);t.addReObjectPath(jn.data,this.visel,o,null,!0),this.setHover(this.hover,e)}}}],[{key:"isSelectable",value:function(){return!1}}]),a}(zn);function Tr(t,e,n,r){var o=t.text(null==e?void 0:e.x,null==e?void 0:e.y,n.data.fieldValue).attr({font:r.font,"font-size":r.fontsz}),i=o.getBBox(),a=t.rect(i.x-1,i.y-1,i.width+2,i.height+2,3,3);a=n.selected?a.attr(r.selectionStyle):a.attr({fill:"#fff",stroke:"#fff"});var s=t.set();return s.push(a,o.toFront()),s}function kr(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Br(t){for(var e=1;e=f&&r.x<=m&&(r.yv?g.push(r.y-v):g.push(r.y-p,v-r.y)),r.xm&&r.y>v&&g.push($.dist(new $(m,v),r)),r.xv&&g.push($.dist(new $(f,v),r)),r.x>m&&r.y=p&&r.y<=v&&(r.xm?g.push(r.x-m):g.push(r.x-f,m-r.x)),n=Math.min.apply(Math,g);break;case zt.line:n=Zr(s,r);break;default:throw new Error("Unsupported shape type")}var y=o.minDist<=8/e?o.refPoint:null;return{minDist:n=Math.min(o.minDist,n),refPoint:y}}},{key:"getReferencePointDistance",value:function(t){var e=[];return this.getReferencePoints().forEach((function(n){e.push({minDist:Math.abs($.dist(t,n)),refPoint:n})})),e.reduce((function(t,e){return t&&t.minDist0&&void 0!==arguments[0]&&arguments[0],e=[];switch(this.item.mode){case zt.ellipse:case zt.rectangle:var n=new $(Math.min(this.item.pos[0].x,this.item.pos[1].x),Math.min(this.item.pos[0].y,this.item.pos[1].y)),r=Math.abs($.diff(this.item.pos[0],this.item.pos[1]).x),o=Math.abs($.diff(this.item.pos[0],this.item.pos[1]).y);e.push(new $(n.x+.5*r,n.y),new $(n.x+r,n.y+.5*o),new $(n.x+.5*r,n.y+o),new $(n.x,n.y+.5*o)),t&&this.item.mode!==zt.rectangle||e.push(n,new $(n.x,n.y+o),new $(n.x+r,n.y+o),new $(n.x+r,n.y));break;case zt.line:this.item.pos.forEach((function(t){return e.push(new $(t.x,t.y,0))}));break;default:throw new Error("Unsupported shape type")}return e}},{key:"getHoverPathStyle",value:function(t,e,n){return n?t.attr(e.options.hoverStyle):t.attr(Br(Br({},e.options.hoverStyle),{},{fill:"#fff"}))}},{key:"hoverPath",value:function(t){var e=[];this.item.pos.forEach((function(n,r){e[r]=gt.obj2scaled(n,t.options)}));var n=t.options.scale,r=[];switch(this.item.mode){case zt.ellipse:var o=$.diff(e[1],e[0]),i=o.x/2,a=o.y/2,s=t.paper.ellipse(H(e[0].x+i),H(e[0].y+a),H(Math.abs(i)+n/8),H(Math.abs(a)+n/8));if(r.push({path:this.getHoverPathStyle(s,t,!0),stylesApplied:!0}),Math.abs(i)-n/8>0&&Math.abs(a)-n/8>0){var u=t.paper.ellipse(H(e[0].x+i),H(e[0].y+a),H(Math.abs(i)-n/8),H(Math.abs(a)-n/8));r.push({path:this.getHoverPathStyle(u,t,!1),stylesApplied:!0})}break;case zt.rectangle:var l=t.paper.rect(H(Math.min(e[0].x,e[1].x)-n/8),H(Math.min(e[0].y,e[1].y)-n/8),H(Math.max(e[0].x,e[1].x)-Math.min(e[0].x,e[1].x)+n/4),H(Math.max(e[0].y,e[1].y)-Math.min(e[0].y,e[1].y)+n/4));if(r.push({path:this.getHoverPathStyle(l,t,!0),stylesApplied:!0}),Math.max(e[0].x,e[1].x)-Math.min(e[0].x,e[1].x)-n/4>0&&Math.max(e[0].y,e[1].y)-Math.min(e[0].y,e[1].y)-n/4>0){var c=t.paper.rect(H(Math.min(e[0].x,e[1].x)+n/8),H(Math.min(e[0].y,e[1].y)+n/8),H(Math.max(e[0].x,e[1].x)-Math.min(e[0].x,e[1].x)-n/4),H(Math.max(e[0].y,e[1].y)-Math.min(e[0].y,e[1].y)-n/4));r.push({path:this.getHoverPathStyle(c,t,!1),stylesApplied:!0})}break;case zt.line:var d=[],h=Math.atan((e[1].y-e[0].y)/(e[1].x-e[0].x)),f={x:0,y:0},p={x:0,y:0},m=e[0].x>e[1].x?-1:1;f.x=e[0].x-m*(n/8*Math.cos(h)),f.y=e[0].y-m*(n/8*Math.sin(h)),p.x=e[1].x+m*(n/8*Math.cos(h)),p.y=e[1].y+m*(n/8*Math.sin(h)),d.push("M",f.x+m*n/8*Math.sin(h),f.y-m*n/8*Math.cos(h)),d.push("L",p.x+m*n/8*Math.sin(h),p.y-m*n/8*Math.cos(h)),d.push("L",p.x-m*n/8*Math.sin(h),p.y+m*n/8*Math.cos(h)),d.push("L",f.x-m*n/8*Math.sin(h),f.y+m*n/8*Math.cos(h)),d.push("L",f.x+m*n/8*Math.sin(h),f.y-m*n/8*Math.cos(h)),r.push({path:this.getHoverPathStyle(t.paper.path(d),t,!0),stylesApplied:!0});break;default:throw new Error("Unsupported shape type")}return r}},{key:"drawHover",value:function(t){var e=this.hoverPath(t).map((function(e){return e.stylesApplied?e.path:e.path.attr(t.options.hoverStyle)}));return t.ctab.addReObjectPath(jn.hovering,this.visel,e),e}},{key:"makeSelectionPlate",value:function(t,e,n){var r=this,o=this.item.pos.map((function(e){return gt.obj2scaled(e,t.render.options)||new $})),i=this.getReferencePoints(),a=t.render.options.scale;return this.selectionSet=t.render.paper.set(),this.selectionPointsSet=t.render.paper.set(),this.selectionSet.push(Ir(this.item.mode,e,o).attr(n.selectionStyleSimpleObject)),i.forEach((function(e){var n=gt.obj2scaled(e,t.render.options);r.selectionPointsSet.push(t.render.paper.circle(n.x,n.y,a/8).attr({fill:"black"}))})),t.addReObjectPath(jn.selectionPlate,this.visel,this.selectionPointsSet),this.selectionSet}},{key:"togglePoints",value:function(t){var e,n;t?null===(e=this.selectionPointsSet)||void 0===e||e.show():null===(n=this.selectionPointsSet)||void 0===n||n.hide()}},{key:"show",value:function(t,e){var n=t.render,r=this.item.pos.map((function(t){return gt.obj2scaled(t,e)||new $})),o=Ir(this.item.mode,n.paper,r),i=e.offset;null!=i&&o.translateAbs(i.x,i.y),this.visel.add(o,Et.fromRelBox(Vn.relBox(o.getBBox())))}}],[{key:"isSelectable",value:function(){return!0}}]),a}(zn);function Zr(t,e){var n;if((e.xMath.max(t[0].x,t[1].x))&&(e.yMath.max(t[0].y,t[1].y)))n=Math.min($.dist(t[0],e),$.dist(t[1],e));else{var r=$.dist(t[0],t[1]),o=$.dist(t[0],e),i=$.dist(t[1],e),a=(r+o+i)/2;n=2/r*Math.sqrt(a*(a-r)*(a-o)*(a-i))}return n}function Ir(t,e,n){var r;switch(t){case zt.ellipse:r=Jn.ellipse(e,n);break;case zt.rectangle:r=Jn.rectangle(e,n);break;case zt.line:r=Jn.line(e,n);break;default:throw new Error("Unsupported shape type")}return r}var Mr=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t){var e;return(0,o.Z)(this,a),(e=r.call(this,"loop")).loop=t,e.centre=new $,e.radius=new $,e}return(0,i.Z)(a,[{key:"show",value:function(t,e,n){var r=this,o=t.render.paper,i=t.molecule,a=this.loop;this.centre=new $,a.hbs.forEach((function(e){var o=i.halfBonds.get(e),s=t.bonds.get(o.bid),u=gt.obj2scaled(t.atoms.get(o.begin).a.pp,n);s.b.type!==dt.PATTERN.TYPE.AROMATIC&&(a.aromatic=!1),r.centre.add_(u)})),a.convex=!0;for(var s=0;s0&&(a.convex=!1)}if(this.centre=this.centre.scaled(1/a.hbs.length),this.radius=-1,a.hbs.forEach((function(e){var o=i.halfBonds.get(e),a=gt.obj2scaled(t.atoms.get(o.begin).a.pp,n),s=gt.obj2scaled(t.atoms.get(o.end).a.pp,n),u=$.diff(s,a).rotateSC(1,0).normalized(),l=$.dot($.diff(a,r.centre),u);r.radius=r.radius<0?l:Math.min(r.radius,l)})),this.radius*=.7,a.aromatic){var c=null;if(a.convex&&n.aromaticCircle)c=o.circle(this.centre.x,this.centre.y,this.radius).attr({stroke:"#000","stroke-width":n.lineattr["stroke-width"]});else{for(var d="",h=0;he.getRowWidth(t)?n:t}),t[0]),a=i[i.length-1],s=a.getBBox().x+a.getBBox().width,u=t[t.length-1],l=Math.max.apply(Math,(0,h.Z)(u.map((function(t){return t.getBBox().y+t.getBBox().height}))));return{p0:new $(n,o),p1:new $(s,l)}}},{key:"getRowWidth",value:function(t){return t.reduce((function(t,e){return t+e.getBBox().width}),0)}},{key:"drawHover",value:function(t){if(!this.paths.length)return null;var e=this.hoverPath(t).attr(t.options.hoverStyle);return t.ctab.addReObjectPath(jn.hovering,this.visel,e),e}},{key:"makeSelectionPlate",value:function(t,e,n){return this.paths.length&&e?this.hoverPath(t.render).attr(n.selectionStyle):null}},{key:"show",value:function(t,e,n){var o=this,i=t.render,s=i.paper,u=gt.obj2scaled(this.item.position,n),l=0;this.paths=[];var c=this.item.content?JSON.parse(this.item.content):null;c&&(c.blocks.forEach((function(t){var e=o.getRanges(t,n),i=0,c=[];e.forEach((function(e){var o=(0,r.Z)(e,3),d=o[0],h=o[1],f=o[2];t.text=t.text.replace(/[^\S\r\n]/g," ");var p=s.text(u.x,u.y,t.text.substring(d,h+1)||" ").attr(function(t){for(var e=1;e=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}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(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function $r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n0;){var i=r.pop();o.add(i);var a=this.atoms.get(i);a&&(a.component>=0&&e.add(a.component),a.a.neighbors.forEach((function(t){var e=n.molecule.halfBonds.get(t);if(e){var i=e.end;o.has(i)||r.push(i)}})))}return o}},{key:"addConnectedComponent",value:function(t){var e=this,n=this.connectedComponents.add(t),r=new et,o=this.getConnectedComponent(Array.from(t),r);r.delete(n);var i=-1;return o.forEach((function(t){var r=e.atoms.get(t);r&&(r.component=n,-1!==r.a.rxnFragmentType&&(i=r.a.rxnFragmentType))})),this.ccFragmentType.set(n,i),n}},{key:"removeConnectedComponent",value:function(t){var e=this;return this.connectedComponents.get(t).forEach((function(t){var n=e.atoms.get(t);n&&(n.component=-1)})),this.connectedComponents.delete(t)}},{key:"assignConnectedComponents",value:function(){var t=this;this.atoms.forEach((function(e,n){if(!(e.component>=0)){var r=new et,o=t.getConnectedComponent(n,r);r.forEach((function(e){t.removeConnectedComponent(e)})),t.addConnectedComponent(o)}}))}},{key:"initLayers",value:function(){for(var t in jn)this.layers[jn[t]]=this.render.paper.rect(0,0,10,10).attr({class:t+"Layer",fill:"#000",opacity:"0.0"}).toFront()}},{key:"addReObjectPath",value:function(t,e,n){var r=this,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];n&&this.layers[t].node.parentNode&&(Array.isArray(n)?n:[n]).forEach((function(n){var a=r.render.options.offset,s=i?Et.fromRelBox(Vn.relBox(n.getBBox())):null,u=o&&s?s.translate(o.negated()):null;null!==a&&(n.translateAbs(a.x,a.y),s=s?s.translate(a):null),e.add(n,s,u),n.insertBefore(r.layers[jn[t]])}))}},{key:"clearMarks",value:function(){var e=this;Object.keys(t.maps).forEach((function(t){e[t+"Changed"]=new Map})),this.structChanged=!1}},{key:"markItemRemoved",value:function(){this.structChanged=!0}},{key:"markBond",value:function(t,e){this.markItem("bonds",t,e)}},{key:"markAtom",value:function(t,e){this.markItem("atoms",t,e)}},{key:"markItem",value:function(t,e,n){var r=this[t+"Changed"],o=r.has(e)?Math.max(n,r.get(e)):n;r.set(e,o),this[t].has(e)&&this.clearVisel(this[t].get(e).visel)}},{key:"clearVisel",value:function(t){t.paths.forEach((function(t){t.remove()})),t.clear()}},{key:"eachItem",value:function(e){var n=this;Object.keys(t.maps).forEach((function(t){n[t].forEach(e)}))}},{key:"getSelectionBoxCenter",value:function(t){var e,n,r,o=null,i=qr(null!==(n=t.atoms)&&void 0!==n?n:[]);try{for(i.s();!(r=i.n()).done;){var s=r.value,u=this.atoms.get(s).a.pp,l=new Et(u,u);o=null==o?l:Et.union(o,l)}}catch(t){i.e(t)}finally{i.f()}var c=function(t){for(var e=1;e0}))})),this.sgroups.forEach((function(t){n.clearVisel(t.visel),t.hovering=null,t.selectionPlate=null})),this.frags.forEach((function(t){n.clearVisel(t.visel)})),this.rgroups.forEach((function(t){n.clearVisel(t.visel)})),e&&(this.clearConnectedComponents(),this.molecule.initHalfBonds(),this.molecule.initNeighbors());var r=Array.from(this.atomsChanged.keys());this.molecule.updateHalfBonds(r),this.molecule.sortNeighbors(r),this.assignConnectedComponents(),this.initialized=!0,this.showMonomers(),this.showPolymerBonds(),this.verifyLoops();var o=e||this.structChanged;return o&&this.updateLoops(),this.showAtoms(),this.showBonds(),this.showRgroupAttachmentPoints(),o&&this.showLoops(),this.showReactionSymbols(),this.showSGroups(),this.showFragments(),this.showRGroups(),this.showEnhancedFlags(),this.showSimpleObjects(),this.showTexts(),this.clearMarks(),!0}},{key:"updateLoops",value:function(){var t=this;this.reloops.forEach((function(e){t.clearVisel(e.visel)}));var e=this.molecule.findLoops();e.bondsToMark.forEach((function(e){t.markBond(e,1)})),e.newLoops.forEach((function(e){t.reloops.set(e,new Mr(t.molecule.loops.get(e)))}))}},{key:"showLoops",value:function(){var t=this,e=this.render.options;this.reloops.forEach((function(n,r){n.show(t,r,e)}))}},{key:"showSimpleObjects",value:function(){var t=this,e=this.render.options;this.simpleObjectsChanged.forEach((function(n,r){var o=t.simpleObjects.get(r);o&&o.show(t,e)}))}},{key:"showTexts",value:function(){var t=this,e=this.render.options;this.textsChanged.forEach((function(n,r){var o=t.texts.get(r);o&&o.show(t,r,e)}))}},{key:"showReactionSymbols",value:function(){var t=this,e=this.render.options;this.rxnArrowsChanged.forEach((function(n,r){var o=t.rxnArrows.get(r);o&&o.show(t,r,e)})),this.rxnPlusesChanged.forEach((function(n,r){var o=t.rxnPluses.get(r);o&&o.show(t,r,e)}))}},{key:"showSGroups",value:function(){var t=this;this.molecule.sGroupForest.getSGroupsBFS().reverse().forEach((function(e){var n=t.sgroups.get(e);n&&n.show(t)}))}},{key:"showFragments",value:function(){var t=this;this.frags.forEach((function(e,n){var r=e.draw(t.render,n);r&&t.addReObjectPath(jn.data,e.visel,r,null,!0)}))}},{key:"showRGroups",value:function(){var t=this,e=this.render.options;this.rgroups.forEach((function(n,r){n.show(t,r,e)}))}},{key:"loopRemove",value:function(t){var e=this,n=this.reloops.get(t);if(n){this.clearVisel(n.visel);var r=[];n.loop.hbs.forEach((function(t){var n=e.molecule.halfBonds.get(t);n&&(n.loop=-1,e.markBond(n.bid,1),e.markAtom(n.begin,1),r.push(n.bid))})),this.reloops.delete(t),this.molecule.loops.delete(t)}}},{key:"verifyLoops",value:function(){var t=this;this.reloops.forEach((function(e,n){e.isValid(t.molecule,n)||t.loopRemove(n)}))}},{key:"getRGroupAttachmentPointsVBoxByAtomIds",value:function(t){var e=this,n=null;return t.forEach((function(t){var r,o=e.molecule.getRGroupAttachmentPointsByAtomId(t).reduce((function(t,n){var r=e.rgroupAttachmentPoints.get(n);u()(null!=r);var o=r.getVBoxObj(e.render);return t&&o?Et.union(t,o):o}),null);n=n&&o?Et.union(n,o):null!==(r=n)&&void 0!==r?r:o})),n}},{key:"showRgroupAttachmentPoints",value:function(){var t=this;this.rgroupAttachmentPoints.forEach((function(e,n){var r=t.rgroupAttachmentPoints.get(n);null!=r&&r.visel&&t.clearVisel(r.visel);var o=null==r?void 0:r.item.atomId,i=t.molecule.getGroupFromAtomId(o);Boolean(null==i?void 0:i.isContracted())||null==r||r.show(t)}))}},{key:"showAtoms",value:function(){var t=this,e=this.render.options;this.atomsChanged.forEach((function(n,r){var o=t.atoms.get(r);o&&o.show(t,r,e)}))}},{key:"showMonomers",value:function(){var t=this;this.monomers.forEach((function(e){e.remove(),e.show(t.render.theme)}))}},{key:"showPolymerBonds",value:function(){this.polymerBonds.forEach((function(t){t.remove(),t.show()}))}},{key:"showEnhancedFlags",value:function(){var t=this,e=this.render.options;this.enhancedFlagsChanged.forEach((function(n,r){var o=t.enhancedFlags.get(r);o&&o.show(t,r,e)}))}},{key:"showBonds",value:function(){var t=this,e=this.render.options;this.bondsChanged.forEach((function(n,r){var o=t.bonds.get(r);o&&o.show(t,r,e)}))}},{key:"setSelection",value:function(e){var n=this,o=[];Object.keys(t.maps).forEach((function(i){var a=n[i].values(),s=(0,r.Z)(a,1)[0];(t.maps[i].isSelectable()||s instanceof Sr)&&n[i].forEach((function(t,r){var a,s;if(t instanceof tr){var u,l,c=qr(t.a.sgs.values());try{for(c.s();!(l=c.n()).done;)u=l.value}catch(t){c.e(t)}finally{c.f()}o.push({selected:t.selected,sgroup:u})}if(t instanceof Sr&&Lt.isContractedFunctionalGroup(null==t||null===(a=t.item)||void 0===a?void 0:a.id,n.molecule.functionalGroups)){var d=o.filter((function(e){var n;return e.sgroup===(null==t||null===(n=t.item)||void 0===n?void 0:n.id)}));t.selected=d.length>0&&d[0].selected}var h=null!=e&&e[i]?e[i].indexOf(r)>-1:t.selected;null===e&&(h=!1),n.showItemSelection(t,h),null===(s=t.selectionPlate)||void 0===s||s.toBack()}))}))}},{key:"showItemSelection",value:function(t,e){var n=function(t){var e,n,r,o;return t&&null!==t.selectionPlate&&(!(null!==(e=t.selectionPlate)&&void 0!==e&&e.items)&&!(null!==(n=t.selectionPlate)&&void 0!==n&&n.removed)||Array.isArray(null===(r=t.selectionPlate)||void 0===r?void 0:r.items)&&!(null!==(o=t.selectionPlate[0])&&void 0!==o&&o.removed))}(t);if(t.selected=e,t instanceof Rr&&(t.sgroup.selected=e),e){if(!n){var r=this.render,o=r.options,i=r.paper;t.selectionPlate=t.makeSelectionPlate(this,i,o),this.addReObjectPath(jn.selectionPlate,t.visel,t.selectionPlate),"function"==typeof t.makeAdditionalInfo&&(t.additionalInfo=t.makeAdditionalInfo(this),this.addReObjectPath(jn.additionalInfo,t.visel,t.additionalInfo))}var a,s;t.selectionPlate&&(t.selectionPlate.show(),null===(a=t.additionalInfo)||void 0===a||a.show(),null===(s=t.cip)||void 0===s||s.rectangle.attr({fill:"#7f7",stroke:"#7f7"}),t.togglePoints&&t.togglePoints(!0))}else if(n&&t.selectionPlate){var u,l;t.selectionPlate.hide(),t.togglePoints&&t.togglePoints(!1),null===(u=t.additionalInfo)||void 0===u||u.hide(),null===(l=t.cip)||void 0===l||l.rectangle.attr({fill:"#fff",stroke:"#fff"})}}},{key:"addSnappingBonds",value:function(t){this.snappingBonds.push(t)}},{key:"clearSnappingBonds",value:function(){this.snappingBonds=[]}},{key:"isSnappingBond",value:function(t){return this.snappingBonds.includes(t)}}]),t}();function Kr(t){return!t||!Object.keys(Xr.maps).some((function(e){return t[e]&&t[e].length>0}))}function Qr(t,e){if("set"===t.type)for(var n=0;n0?r:0,i=i>0?i:0,this.userOpts=n,this.clientArea=e,this.paper=new(S())(e,r,i),this.sz=$.ZERO,this.ctab=new Xr(new te,this),this.options=function(t){var e=t.scale||100;t.rotationStep&&Ln.setFracAngle(t.rotationStep);var n=Math.ceil(e/6*1.9),r=Math.ceil(.5*n),o={"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:Kn.TerminalAndHetero,showValence:!0,aromaticCircle:!0,scale:e,zoom:1,offset:new $,lineWidth:e/20,bondSpace:t.doubleBondWidth||e/7,stereoBond:t.stereoBondWidth||e/7,subFontSize:r,font:"30px Arial",fontsz:n,fontszsub:r,fontRLabel:1.2*n,fontRLogic:.7*n,radiusScaleFactor:.38,lineattr:{stroke:"#000","stroke-width":t.bondThickness||e/20,"stroke-linecap":"round","stroke-linejoin":"round"},arrowSnappingStyle:{fill:"#365CFF",stroke:"#365CFF"},bondSnappingStyle:{fill:"#365CFF",stroke:"#365CFF","stroke-width":1.5*t.bondThickness},selectionStyle:{fill:"#57FF8F",stroke:"#57FF8F"},hoverStyle:{stroke:"#0097A8",fill:"#CCFFDD","stroke-width":.6*e/20},sgroupBracketStyle:{stroke:"darkgray","stroke-width":.5*e/20},lassoStyle:{stroke:"gray","stroke-width":"1px"},selectionStyleSimpleObject:{stroke:"#57FF8F","stroke-width":e/4,"stroke-linecap":"round"},movingStyle:{cursor:"all-scroll"},atomSelectionPlateRadius:n,contractedFunctionalGroupSize:50,previewOpacity:.5};return Object.assign({},o,t)}(this.userOpts)}return(0,i.Z)(t,[{key:"updateOptions",value:function(t){try{var e=JSON.parse(t);if(e&&"object"===(0,x.Z)(e))return this.options=to(to({},this.options),e),this.options}catch(t){}return!1}},{key:"selectionPolygon",value:function(t){return Jn.selectionPolygon(this.paper,t,this.options)}},{key:"selectionLine",value:function(t,e){return Jn.selectionLine(this.paper,t,e,this.options)}},{key:"selectionRectangle",value:function(t,e){return Jn.selectionRectangle(this.paper,t,e,this.options)}},{key:"view2obj",value:function(t,e){var n=this.scrollPos();return t=t.scaled(1/this.options.zoom),n=n.scaled(1/this.options.zoom),t=e?t:t.add(n).sub(this.options.offset),gt.scaled2obj(t,this.options)}},{key:"obj2view",value:function(t,e){var n=gt.obj2scaled(t,this.options);return(n=e?n:n.add(this.options.offset).sub(this.scrollPos().scaled(1/this.options.zoom))).scaled(this.options.zoom)}},{key:"scrollPos",value:function(){return new $(this.clientArea.scrollLeft,this.clientArea.scrollTop)}},{key:"page2obj",value:function(t){var e=this.clientArea.getBoundingClientRect(),n=e.top,r=e.left,o=new $(t.clientX-r,t.clientY-n);return this.view2obj(o)}},{key:"setPaperSize",value:function(t){this.sz=t,this.paper.setSize(t.x*this.options.zoom,t.y*this.options.zoom),this.setViewBox()}},{key:"setOffset",value:function(t){var e=new $(t.x-this.options.offset.x,t.y-this.options.offset.y);this.clientArea.scrollLeft+=e.x,this.clientArea.scrollTop+=e.y,this.options.offset=t}},{key:"setZoom",value:function(t){this.options.zoom=t,this.paper.setSize(this.sz.x*t,this.sz.y*t),this.setViewBox()}},{key:"setScrollOffset",value:function(t,e){var n,r,o,i,a,s,u,l=this.clientArea,c=l.clientWidth,d=l.clientHeight,h=(n=this.sz.scaled(this.options.zoom),r=t,o=e,i=c+Math.abs(t),a=d+Math.abs(e),s=r<0?-r:0,u=o<0?-o:0,n.x0||h.y>0){this.setPaperSize(this.sz.add(h));var f=new $(t<0?-t:0,e<0?-e:0).scaled(1/this.options.zoom);(f.x>0||f.y>0)&&(this.ctab.translate(f),this.setOffset(this.options.offset.add(f)))}l.scrollLeft=t*this.options.scale,l.scrollTop=e*this.options.scale,this.update(!1)}},{key:"setViewBox",value:function(){this.paper.canvas.setAttribute("viewBox","0 0 "+this.sz.x+" "+this.sz.y)}},{key:"setMolecule",value:function(t){this.paper.clear(),this.ctab=new Xr(t,this),this.options.offset=new $,this.update(!1)}},{key:"update",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{resizeCanvas:!0};e=e||new $(this.clientArea.clientWidth||100,this.clientArea.clientHeight||100);var r=this.ctab.update(t);if(this.ctab.setSelection(),r){var o=this.options.scale,i=this.ctab.getVBoxObj().transform(gt.obj2scaled,this.options).translate(this.options.offset||new $);if(this.options.downScale&&this.ctab.molecule.rescale(),this.options.autoScale||this.options.downScale){var a=i.sz(),s=this.options.autoScaleMargin,u=new $(s,s),l=e;if(s&&(l.x<2*s+1||l.y<2*s+1))throw new Error("View box too small for the given margin");var c=this.options.rescaleAmount||Math.max(a.x/(l.x-2*s),a.y/(l.y-2*s)),d=this.options.downScale&&c<1;(this.options.maxBondLength/c>1||d)&&(c=1);var h=a.add(u.scaled(2*c));this.paper.setViewBox(i.pos().x-s*c-(l.x*c-h.x)/2,i.pos().y-s*c-(l.y*c-h.y)/2,l.x*c,l.y*c)}else{var f=$.UNIT.scaled(o),p=i.sz().length()>0?i.extend(f,f):i,m=new Et(this.scrollPos(),e.scaled(1/this.options.zoom).sub($.UNIT.scaled(20))),v=Et.union(m,p);this.oldCb||(this.oldCb=new Et);var g=v.sz().floor(),y=this.oldCb.p0.sub(v.p0).ceil();(!this.sz||g.x!==this.sz.x||g.y!==this.sz.y)&&n.resizeCanvas&&this.setPaperSize(g),this.options.offset=this.options.offset||new $,(0!==y.x||0!==y.y)&&n.resizeCanvas&&(this.setOffset(this.options.offset.add(y)),this.ctab.translate(y))}eo()}}}]),t}();function ro(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}var oo,io=new Map,ao=function(){function t(){(0,o.Z)(this,t)}return(0,i.Z)(t,null,[{key:"prepareStruct",value:function(t){if(t.sgroups.size>0){var e=t.clone();return function(t){t.sgroups.forEach((function(e){e.getAttachmentPoints().forEach((function(e){t.atoms.get(e.atomId).setRGAttachmentPointForDisplayPurpose();var n=e.convertToRGroupAttachmentPointForDisplayPurpose(e.atomId);t.rgroupAttachmentPoints.add(n)}))}))}(e),e.sgroups.delete(0),e}return t}},{key:"render",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t&&e){var r=n.cachePrefix,o=void 0===r?"":r,i=n.needCache,s=void 0===i||i,u="".concat(o).concat(e.name);if((0,E.isEqual)(oo,n)||(io.clear(),oo=n),io.has(u)&&s)return void(t.innerHTML=io.get(u));var l=this.prepareStruct(e);l.initHalfBonds(),l.initNeighbors(),l.setImplicitHydrogen(),l.markFragments();var c=new no(t,function(t){for(var e=1;elo,o=co-e>lo,i=ho-n>lo,a=n-ho>lo;return co=e,ho=n,{isMovingRight:r,isMovingLeft:o,isMovingTop:i,isMovingBottom:a}}function po(t){var e=t.clientX,n=t.clientY,r=document.body;return{isCloseToLeftEdgeOfScreen:e<=so,isCloseToTopEdgeOfScreen:n<=so,isCloseToRightEdgeOfScreen:r.clientWidth-e<=so,isCloseToBottomEdgeOfScreen:r.clientHeight-n<=so}}function mo(t,e){var n=t.layerX,r=t.layerY;return{isCloseToLeftEdgeOfCanvas:n<=so,isCloseToTopEdgeOfCanvas:r<=so,isCloseToRightEdgeOfCanvas:e.x-n<=so,isCloseToBottomEdgeOfCanvas:e.y-r<=so}}function vo(t,e){var n=function(t,e,n){var r=t.scrollLeft+n.x,o=t.scrollTop+n.y,i=0,a=0;return r>e.x&&(i=r-e.x),r<0&&(i=Math.abs(r)),o>e.y&&(a=o-e.y),o<0&&(a=Math.abs(o)),new $(i,a,0)}(e.clientArea,e.sz.scaled(e.options.zoom),t).scaled(1/e.options.zoom);(n.x>0||n.y>0)&&(e.setPaperSize(e.sz.add(n)),e.setOffset(e.options.offset.add(t)),e.ctab.translate(t),e.setViewBox(e.options.zoom),co+=n.x,ho+=n.y),go(t,e),e.update(!1)}function go(t,e){var n=e.clientArea;n.scrollLeft+=t.x*e.options.scale/uo,n.scrollTop+=t.y*e.options.scale/uo}var yo,bo=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;(0,o.Z)(this,t),this.type=e,this.priority=n}return(0,i.Z)(t,[{key:"execute",value:function(t){throw new Error("Operation.execute() is not implemented")}},{key:"perform",value:function(t){return this.execute(t),this._inverted||(this._inverted=this.invert(),this._inverted._inverted=this),this._inverted}},{key:"invert",value:function(){throw new Error("Operation.invert() is not implemented")}},{key:"isDummy",value:function(t){return!1}}],[{key:"invalidateAtom",value:function(e,n,r){var o=e.atoms.get(n);if(o){e.markAtom(n,r?1:0);var i=e.molecule.halfBonds;o.a.neighbors.forEach((function(n){if(i.has(n)){var o=i.get(n);o&&(e.markBond(o.bid,1),e.markAtom(o.end,0),r&&t.invalidateLoop(e,o.bid))}}));var a=o.a.fragment,s=e.render.options.stereoLabelStyle;e.atoms.forEach((function(t,n){s!==Gn.IUPAC&&s!==Gn.Classic||t.a.fragment===a&&e.markAtom(n,0)}))}}},{key:"invalidateLoop",value:function(t,e){var n=t.bonds.get(e);if(n&&n.b.hb1&&n.b.hb2){var r=t.molecule.halfBonds.get(n.b.hb1),o=t.molecule.halfBonds.get(n.b.hb2);r&&r.loop>=0&&t.loopRemove(r.loop),o&&o.loop>=0&&t.loopRemove(o.loop)}}},{key:"invalidateBond",value:function(e,n){t.invalidateLoop(e,n);var r=e.bonds.get(n);r&&(t.invalidateAtom(e,r.b.begin,0),t.invalidateAtom(e,r.b.end,0))}},{key:"invalidateItem",value:function(e,n,r,o){if("atoms"!==n)return"bonds"===n?(t.invalidateBond(e,r),void(o>0&&t.invalidateLoop(e,r))):void e.markItem(n,r,o);t.invalidateAtom(e,r,o)}},{key:"invalidateEnhancedFlag",value:function(e,n){t.invalidateItem(e,"enhancedFlags",n,1)}}]),t}(),wo=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"});!function(t){t[t.ATOM_ATTR=1]="ATOM_ATTR",t[t.BOND_ADD=1]="BOND_ADD",t[t.R_GROUP_ATTACHMENT_POINT_REMOVE=1]="R_GROUP_ATTACHMENT_POINT_REMOVE",t[t.ATOM_MOVE=2]="ATOM_MOVE",t[t.BOND_ATTR=2]="BOND_ATTR",t[t.BOND_MOVE=2]="BOND_MOVE",t[t.BOND_DELETE=3]="BOND_DELETE",t[t.S_GROUP_ATOM_ADD=3]="S_GROUP_ATOM_ADD",t[t.S_GROUP_ATTACHMENT_POINT_ADD=3]="S_GROUP_ATTACHMENT_POINT_ADD",t[t.R_GROUP_ATTACHMENT_POINT_ADD=3]="R_GROUP_ATTACHMENT_POINT_ADD",t[t.S_GROUP_ATTR=4]="S_GROUP_ATTR",t[t.ATOM_DELETE=5]="ATOM_DELETE",t[t.FRAGMENT_STEREO_FLAG=6]="FRAGMENT_STEREO_FLAG",t[t.CALC_IMPLICIT_H=10]="CALC_IMPLICIT_H",t[t.FRAGMENT_DELETE_STEREO_ATOM=90]="FRAGMENT_DELETE_STEREO_ATOM",t[t.S_GROUP_DELETE=95]="S_GROUP_DELETE",t[t.S_GROUP_ADD_TO_HIERACHY=100]="S_GROUP_ADD_TO_HIERACHY",t[t.FRAGMENT_ADD_STEREO_ATOM=100]="FRAGMENT_ADD_STEREO_ATOM"}(yo||(yo={}));var xo=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e,n){var i;return(0,o.Z)(this,a),(i=r.call(this,wo.ATOM_ATTR,yo.ATOM_ATTR)).data={aid:t,attribute:e,value:n},i.data2=null,i}return(0,i.Z)(a,[{key:"execute",value:function(t){if(this.data){var e=this.data,n=e.aid,r=e.attribute,o=e.value,i=t.molecule.atoms.get(n);this.data2||(this.data2={aid:n,attribute:r,value:i[r]}),i[r]=o,bo.invalidateAtom(t,n)}}},{key:"invert",value:function(){var t=new a;return t.data=this.data2,t.data2=this.data,t}},{key:"isDummy",value:function(t){var e,n,r;return t.molecule.atoms.get(null===(e=this.data)||void 0===e?void 0:e.aid)[null===(n=this.data)||void 0===n?void 0:n.attribute]===(null===(r=this.data)||void 0===r?void 0:r.value)}}]),a}(bo);var Eo=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e,n){var i;return(0,o.Z)(this,a),(i=r.call(this,wo.ATOM_MOVE,yo.ATOM_MOVE)).data={aid:t,d:e,noinvalidate:n},i}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=t.molecule,n=this.data,r=n.aid,o=n.d,i=e.atoms.get(r);if(i){i.pp.add_(o);var a=t.atoms.get(r);if(a){var s=gt.obj2scaled(o,t.render.options);a.visel.translate(s)}this.data.d=o.negated(),this.data.noinvalidate||bo.invalidateAtom(t,r,1)}}},{key:"invert",value:function(){var t=new a;return t.data=this.data,t}},{key:"isDummy",value:function(){var t=this.data.d;return 0===t.x&&0===t.y}}]),a}(bo);function Po(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var Oo=function(t){(0,f.Z)(n,t);var e=Po(n);function n(t,r){var i;return(0,o.Z)(this,n),(i=e.call(this,wo.ATOM_ADD)).data={atom:t,pos:r,aid:null},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.atom,r=e.pos,o=t.molecule,i={label:""};n&&Object.keys(n).forEach((function(t){i[t]=n[t]})),i.label=i.label||"C","number"!=typeof this.data.aid?this.data.aid=o.atoms.add(new at(i)):o.atoms.set(this.data.aid,new at(i));var a=this.data.aid,s=new tr(o.atoms.get(a));s.component=t.connectedComponents.add(new et([a])),t.atoms.set(a,s),t.markAtom(a,1),o.atomSetPos(a,new $(r));var u=o.rxnArrows.get(0);u&&(o.atoms.get(a).rxnFragmentType=o.defineRxnFragmentTypeForAtomset(new et([a]),u.pos[0].x))}},{key:"invert",value:function(){var t=new Ao;return t.data=this.data,t}}]),n}(bo),Ao=function(t){(0,f.Z)(n,t);var e=Po(n);function n(t){var r;return(0,o.Z)(this,n),(r=e.call(this,wo.ATOM_DELETE,yo.ATOM_DELETE)).data={aid:t,atom:null,pos:null},r}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data.aid,n=t.molecule;this.data.atom||(this.data.atom=n.atoms.get(e),this.data.pos=this.data.atom.pp);var r=t.atoms.get(e);if(r){var o=t.connectedComponents.get(r.component);o.delete(e),0===o.size&&t.connectedComponents.delete(r.component),t.clearVisel(r.visel),t.atoms.delete(e),t.markItemRemoved(),n.atoms.delete(e)}}},{key:"invert",value:function(){var t=new Oo;return t.data=this.data,t}}]),n}(bo);var Ro=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e,n){var i;return(0,o.Z)(this,a),(i=r.call(this,wo.BOND_ATTR,yo.BOND_ATTR)).data={bid:t,attribute:e,value:n},i.data2=null,i}return(0,i.Z)(a,[{key:"execute",value:function(t){if(this.data){var e=this.data,n=e.attribute,r=e.bid,o=e.value,i=t.molecule.bonds.get(r);this.data2||(this.data2={bid:r,attribute:n,value:i[n]}),i[n]=o,bo.invalidateBond(t,r),"type"===n&&bo.invalidateLoop(t,r)}}},{key:"isDummy",value:function(t){if(this.data){var e=this.data,n=e.attribute,r=e.bid,o=e.value;return t.molecule.bonds.get(r)[n]===o}return!1}},{key:"invert",value:function(){var t=new a;return t.data=this.data2,t.data2=this.data,t}}]),a}(bo);var So=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e){var n;return(0,o.Z)(this,a),(n=r.call(this,wo.BOND_MOVE,yo.BOND_MOVE)).data={bid:t,d:e},n}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=this.data,n=e.bid,r=e.d,o=t.bonds.get(n);if(o){var i=gt.obj2scaled(r,t.render.options);o.visel.translate(i),this.data.d=r.negated()}}},{key:"invert",value:function(){var t=new a;return t.data=this.data,t}}]),a}(bo);function To(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var ko=function(t){(0,f.Z)(n,t);var e=To(n);function n(t,r,i){var a;return(0,o.Z)(this,n),(a=e.call(this,wo.BOND_ADD,yo.BOND_ADD)).data={bond:i,begin:t,end:r,bid:null},a}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.begin,r=e.bond,o=e.end,i=t.molecule;if(n===o)throw new Error("Distinct atoms expected");bo.invalidateAtom(t,n,1),bo.invalidateAtom(t,o,1);var a={type:0,begin:0,end:0};r&&Object.keys(r).forEach((function(t){a[t]=r[t]})),a.type=a.type||dt.PATTERN.TYPE.SINGLE,a.begin=n,a.end=o;var s=new dt(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),t.bonds.set(u,new or(l)),t.markBond(u,1)}},{key:"invert",value:function(){var t=new Bo;return t.data=this.data,t}}]),n}(bo),Bo=function(t){(0,f.Z)(n,t);var e=To(n);function n(t){var r;return(0,o.Z)(this,n),(r=e.call(this,wo.BOND_DELETE,yo.BOND_DELETE)).data={bid:t,bond:null,begin:null,end:null},r}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data.bid,n=t.molecule;this.data.bond||(this.data.bond=n.bonds.get(e),this.data.begin=this.data.bond.begin,this.data.end=this.data.bond.end),bo.invalidateBond(t,e);var r=t.bonds.get(e);if(r){[r.b.hb1,r.b.hb2].forEach((function(e){if(void 0!==e){var n=t.molecule.halfBonds.get(e);n&&n.loop>=0&&t.loopRemove(n.loop)}}),t),t.clearVisel(r.visel),t.bonds.delete(e),t.markItemRemoved();var o=n.bonds.get(e);[o.hb1,o.hb2].forEach((function(t){var e=n.halfBonds.get(t);if(e){var r=n.atoms.get(e.begin),o=r.neighbors.indexOf(t),i=(o+r.neighbors.length-1)%r.neighbors.length,a=(o+1)%r.neighbors.length;n.setHbNext(r.neighbors[i],r.neighbors[a]),r.neighbors.splice(o,1)}})),n.halfBonds.delete(o.hb1),n.halfBonds.delete(o.hb2),n.bonds.delete(e)}}},{key:"invert",value:function(){var t=new ko;return t.data=this.data,t}}]),n}(bo);var Co=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t){var e;return(0,o.Z)(this,a),(e=r.call(this,wo.CANVAS_LOAD)).data={struct:t},e}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=t.molecule;t.clearVisels(),this.data.struct&&t.render.setMolecule(this.data.struct),this.data.struct=e}},{key:"invert",value:function(){var t=new a;return t.data=this.data,t}}]),a}(bo);function Zo(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var Io=function(t){(0,f.Z)(n,t);var e=Zo(n);function n(){var t;return(0,o.Z)(this,n),(t=e.call(this,wo.ALIGN_DESCRIPTORS)).history={},t}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this,n=t.molecule,r=Array.from(n.sgroups.values()).reverse(),o=n.getCoordBoundingBoxObj(),i=new $(o.max.x,o.min.y).add(new $(2,-1));r.forEach((function(r){e.history[r.id]=new $(r.pp),i=i.add(new $(0,.5)),r.pp=i,n.sgroups.set(r.id,r),bo.invalidateItem(t,"sgroupData",r.id,1)}))}},{key:"invert",value:function(){return new Mo(this.history)}}]),n}(bo),Mo=function(t){(0,f.Z)(n,t);var e=Zo(n);function n(t){var r;return(0,o.Z)(this,n),(r=e.call(this,wo.RESTORE_DESCRIPTORS_POSITION)).history=t,r}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this,n=t.molecule;Array.from(n.sgroups.values()).forEach((function(r){r.pp=e.history[r.id],n.sgroups.set(r.id,r),bo.invalidateItem(t,"sgroupData",r.id,1)}))}},{key:"invert",value:function(){return new Io}}]),n}(bo);var No=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e){var n;return(0,o.Z)(this,a),(n=r.call(this,wo.ENHANCED_FLAG_MOVE)).data={frid:t,p:e},n}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=this.data.frid,n=this.data.p,r=t.molecule.frags.get(e);if(r){var o=r.stereoFlagPosition?new $(r.stereoFlagPosition.x,r.stereoFlagPosition.y):vt.getDefaultStereoFlagPosition(t.molecule,e),i=$.sum(o,n);r.stereoFlagPosition=i,this.data.p=n.negated(),bo.invalidateItem(t,"enhancedFlags",e,1)}}},{key:"invert",value:function(){var t=new a;return t.data=this.data,t}}]),a}(bo);function _o(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var Do=function(t){(0,f.Z)(n,t);var e=_o(n);function n(t,r){var i,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return(0,o.Z)(this,n),(i=e.call(this,wo.UPDATE_IF_THEN)).rgid_new=t,i.rgid_old=r,i.ifThenHistory=new Map,i.skipRgids=a||[],i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this,n=t.molecule;n.rgroups.forEach((function(t,r){t.ifthen!==e.rgid_old||e.skipRgids.includes(r)||(t.ifthen=e.rgid_new,e.ifThenHistory.set(r,e.rgid_old),n.rgroups.set(r,t))}))}},{key:"invert",value:function(){return new Lo(this.rgid_new,this.rgid_old,this.ifThenHistory)}}]),n}(bo),Lo=function(t){(0,f.Z)(n,t);var e=_o(n);function n(t,r,i){var a;return(0,o.Z)(this,n),(a=e.call(this,wo.RESTORE_IF_THEN)).rgid_new=t,a.rgid_old=r,a.ifThenHistory=i||new Map,a}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule;this.ifThenHistory.forEach((function(t,n){var r=e.rgroups.get(n);r.ifthen=t,e.rgroups.set(n,r)}))}},{key:"invert",value:function(){return new Do(this.rgid_old,this.rgid_new)}}]),n}(bo);function jo(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var Fo=function(t){(0,f.Z)(n,t);var e=jo(n);function n(t,r){var i;return(0,o.Z)(this,n),(i=e.call(this,wo.FRAGMENT_ADD)).frid=void 0===t?null:t,r&&(i.properties=r),i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=new vt([],null,this.properties);null===this.frid?this.frid=e.frags.add(n):e.frags.set(this.frid,n),t.frags.set(this.frid,new vr(n)),t.enhancedFlags.set(this.frid,new mr)}},{key:"invert",value:function(){return new Ho(this.frid)}}]),n}(bo),Go=function(t){(0,f.Z)(n,t);var e=jo(n);function n(t,r){var i;return(0,o.Z)(this,n),(i=e.call(this,wo.FRAGMENT_SET_PROPERTIES)).frid=t,i.properties=r,i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule.frags.get(this.frid);e&&(this.properties?e.properties=this.properties:null==e||delete e.properties)}},{key:"invert",value:function(){return new n(this.frid,void 0)}}]),n}(bo),Ho=function(t){(0,f.Z)(n,t);var e=jo(n);function n(t){var r;return(0,o.Z)(this,n),(r=e.call(this,wo.FRAGMENT_DELETE,100)).frid=t,r}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule;if(e.frags.get(this.frid)){bo.invalidateItem(t,"frags",this.frid,1),t.frags.delete(this.frid),e.frags.delete(this.frid);var n=t.enhancedFlags.get(this.frid);n&&(t.clearVisel(n.visel),t.enhancedFlags.delete(this.frid))}}},{key:"invert",value:function(){return new Fo(this.frid)}}]),n}(bo);function zo(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var Uo=function(t){(0,f.Z)(n,t);var e=zo(n);function n(t,r){var i;return(0,o.Z)(this,n),(i=e.call(this,wo.FRAGMENT_ADD_STEREO_ATOM,yo.FRAGMENT_ADD_STEREO_ATOM)).data={frid:t,aid:r},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.aid,r=e.frid,o=t.molecule.frags.get(r);o&&(o.updateStereoAtom(t.molecule,n,r,!0),bo.invalidateEnhancedFlag(t,r))}},{key:"invert",value:function(){return new Vo(this.data.frid,this.data.aid)}}]),n}(bo),Vo=function(t){(0,f.Z)(n,t);var e=zo(n);function n(t,r){var i;return(0,o.Z)(this,n),(i=e.call(this,wo.FRAGMENT_DELETE_STEREO_ATOM,yo.FRAGMENT_DELETE_STEREO_ATOM)).data={frid:t,aid:r},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.aid,r=e.frid,o=t.molecule.frags.get(r);o&&(o.updateStereoAtom(t.molecule,n,r,!1),bo.invalidateEnhancedFlag(t,r))}},{key:"invert",value:function(){var t=this.data,e=t.aid,n=t.frid;return new Uo(n,e)}}]),n}(bo);var Wo=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t){var e;return(0,o.Z)(this,a),(e=r.call(this,wo.FRAGMENT_STEREO_FLAG,yo.FRAGMENT_STEREO_FLAG)).frid=t,e}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=t.molecule;e.frags.get(this.frid).updateStereoFlag(e),bo.invalidateEnhancedFlag(t,this.frid)}},{key:"invert",value:function(){return new a(this.frid)}}]),a}(bo);var Yo=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t){var e;return(0,o.Z)(this,a),(e=r.call(this,wo.CALC_IMPLICIT_H,yo.CALC_IMPLICIT_H)).atomIds=t,e}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=this.atomIds;t.molecule.setImplicitHydrogen(e)}},{key:"invert",value:function(){return new a(this.atomIds)}}]),a}(bo);var qo=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e){var n;return(0,o.Z)(this,a),(n=r.call(this,wo.LOOP_MOVE)).data={id:t,d:e},n}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=this.data,n=e.id,r=e.d,o=t.reloops.get(n);if(o&&o.visel){var i=gt.obj2scaled(r,t.render.options);o.visel.translate(i)}this.data.d=r.negated()}},{key:"invert",value:function(){var t=new a;return t.data=this.data,t}}]),a}(bo);var $o=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e,n){var i;return(0,o.Z)(this,a),(i=r.call(this,wo.R_GROUP_ATTR)).data={rgid:t,attribute:e,value:n},i.data2=null,i}return(0,i.Z)(a,[{key:"execute",value:function(t){if(this.data){var e=this.data,n=e.rgid,r=e.attribute,o=e.value,i=t.molecule.rgroups.get(n);if(!i)return;this.data2||(this.data2={rgid:n,attribute:r,value:i[r]}),i[r]=o,bo.invalidateItem(t,"rgroups",n)}}},{key:"invert",value:function(){var t=new a;return t.data=this.data2,t.data2=this.data,t}},{key:"isDummy",value:function(t){if(this.data){var e=this.data,n=e.rgid,r=e.attribute,o=e.value;return t.molecule.rgroups.get(n)[r]===o}return!1}}]),a}(bo);var Xo=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e,n){var i;return(0,o.Z)(this,a),(i=r.call(this,wo.R_GROUP_FRAGMENT)).rgid_new=t,i.rg_new=n,i.rgid_old=null,i.rg_old=null,i.frid=e,i}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=t.molecule;this.rgid_old=this.rgid_old||Gt.findRGroupByFragment(e.rgroups,this.frid),this.rg_old=this.rgid_old?e.rgroups.get(this.rgid_old):null,this.removeOld(e,t),this.setNew(e,t)}},{key:"removeOld",value:function(t,e){this.rg_old&&(this.rg_old.frags.delete(this.frid),e.clearVisel(e.rgroups.get(this.rgid_old).visel),0===this.rg_old.frags.size?(e.rgroups.delete(this.rgid_old),t.rgroups.delete(this.rgid_old),e.markItemRemoved()):e.markItem("rgroups",this.rgid_old,1))}},{key:"setNew",value:function(t,e){if(this.rgid_new){var n=t.rgroups.get(this.rgid_new);n?e.markItem("rgroups",this.rgid_new,1):(n=this.rg_new||new Gt,t.rgroups.set(this.rgid_new,n),e.rgroups.set(this.rgid_new,new br(n))),n.frags.add(this.frid)}}},{key:"invert",value:function(){return new a(this.rgid_old,this.frid,this.rg_old)}}]),a}(bo);var Ko=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t){var e;return(0,o.Z)(this,a),(e=r.call(this,wo.R_GROUP_ATTACHMENT_POINT_ADD,yo.R_GROUP_ATTACHMENT_POINT_ADD)).data=t,e}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=this.data,n=e.atomId,r=e.attachmentPointType,o=new Ht(n,r),i=t.molecule,a=this.data.attachmentPointId,s=0;void 0===a?s=i.rgroupAttachmentPoints.add(o):(i.rgroupAttachmentPoints.set(a,o),s=a),this.data.attachmentPointId=s;var l=t.atoms.get(n);u()(null!=l),t.rgroupAttachmentPoints.set(s,new Dr(o,l))}},{key:"invert",value:function(){if(void 0===this.data.attachmentPointId)throw Error("Inverted attachmentPointId doesn't exist");return new ei(this.data.attachmentPointId)}}]),a}(bo);function Qo(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function Jo(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:[],i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:_t.OpenAngle,a=arguments.length>2?arguments[2]:void 0;return(0,o.Z)(this,n),(t=e.call(this,wo.RXN_ARROW_ADD)).data={pos:r,mode:i,id:a},t}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=new Ut({mode:this.data.mode});if(null==this.data.id){var r=e.rxnArrows.add(n);this.data.id=r}else e.rxnArrows.set(this.data.id,n);var o=this.data.id;t.rxnArrows.set(o,new Pr(n));var i=(0,h.Z)(this.data.pos);e.rxnArrowSetPos(o,i.map((function(t){return new $(t)}))),bo.invalidateItem(t,"rxnArrows",o,1)}},{key:"invert",value:function(){return new fi(this.data.id)}}]),n}(bo),fi=function(t){(0,f.Z)(n,t);var e=di(n);function n(t){var r;return(0,o.Z)(this,n),(r=e.call(this,wo.RXN_ARROW_DELETE)).data={id:t,pos:[],mode:_t.OpenAngle},r.performed=!1,r}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=e.rxnArrows.get(this.data.id);this.data.pos=n.pos,this.data.mode=n.mode,this.performed=!0,t.markItemRemoved(),t.clearVisel(t.rxnArrows.get(this.data.id).visel),t.rxnArrows.delete(this.data.id),e.rxnArrows.delete(this.data.id)}},{key:"invert",value:function(){return new hi(this.data.pos,this.data.mode,this.data.id)}}]),n}(bo);function pi(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var mi=function(t){(0,f.Z)(n,t);var e=pi(n);function n(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:zt.line,a=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=arguments.length>3?arguments[3]:void 0;return(0,o.Z)(this,n),(t=e.call(this,wo.SIMPLE_OBJECT_ADD)).data={pos:r,mode:i,toCircle:a,id:s},t}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=new qt({mode:this.data.mode});if(null==this.data.id){var r=e.simpleObjects.add(n);this.data.id=r}else e.simpleObjects.set(this.data.id,n);var o=this.data.id;t.simpleObjects.set(o,new Cr(n));var i=(0,h.Z)(this.data.pos);this.data.toCircle&&(i[1]=wi(i[0],i[1])),e.simpleObjectSetPos(o,i.map((function(t){return new $(t)}))),bo.invalidateItem(t,"simpleObjects",o,1)}},{key:"invert",value:function(){return new vi(this.data.id)}}]),n}(bo),vi=function(t){(0,f.Z)(n,t);var e=pi(n);function n(t){var r;return(0,o.Z)(this,n),(r=e.call(this,wo.SIMPLE_OBJECT_DELETE)).data={id:t,pos:[],mode:zt.line,toCircle:!1},r.performed=!1,r}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=e.simpleObjects.get(this.data.id);this.data.pos=n.pos,this.data.mode=n.mode,this.data.toCircle=n.toCircle,this.performed=!0,t.markItemRemoved(),t.clearVisel(t.simpleObjects.get(this.data.id).visel),t.simpleObjects.delete(this.data.id),e.simpleObjects.delete(this.data.id)}},{key:"invert",value:function(){return new mi(this.data.pos,this.data.mode,this.data.toCircle,this.data.id)}}]),n}(bo),gi=function(t){(0,f.Z)(n,t);var e=pi(n);function n(t,r,i){var a;return(0,o.Z)(this,n),(a=e.call(this,wo.SIMPLE_OBJECT_MOVE)).data={id:t,d:r,noinvalidate:i},a}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=this.data.id,r=this.data.d;e.simpleObjects.get(n).pos.forEach((function(t){return t.add_(r)})),t.simpleObjects.get(n).visel.translate(gt.obj2scaled(r,t.render.options)),this.data.d=r.negated(),this.data.noinvalidate||bo.invalidateItem(t,"simpleObjects",n,1)}},{key:"invert",value:function(){var t=new n(this.data.id,this.data.d,this.data.noinvalidate);return t.data=this.data,t}}]),n}(bo);function yi(t,e,n){var r=t.pos[0].get_xy0(),o=t.pos[1].get_xy0();H(e.x)===H(t.pos[1].x)&&(t.pos[1].x=e.x=n.x,n.x=o.x),H(e.y)===H(t.pos[1].y)&&(t.pos[1].y=e.y=n.y,n.y=o.y),H(e.x)===H(t.pos[0].x)&&(t.pos[0].x=e.x=n.x,n.x=r.x),H(e.y)===H(t.pos[0].y)&&(t.pos[0].y=e.y=n.y,n.y=r.y)}var bi=function(t){(0,f.Z)(n,t);var e=pi(n);function n(t,r,i,a,s,u){var l;return(0,o.Z)(this,n),(l=e.call(this,wo.SIMPLE_OBJECT_RESIZE)).data={id:t,d:r,current:i,anchor:a,noinvalidate:s,toCircle:u},l}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=this.data.id,r=this.data.d,o=this.data.current,i=e.simpleObjects.get(n),a=this.data.anchor;if(i.mode===zt.ellipse)if(a)yi(i,a,o);else if(this.data.toCircle){var s=i.pos[1].get_xy0(),u=wi(i.pos[0],o);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=o.x,i.pos[1].y=o.y,this.data.current=l}else if(i.mode===zt.line&&a){var c=i.pos[0].get_xy0(),d=i.pos[1].get_xy0();H(a.x)===H(i.pos[1].x)&&H(a.y)===H(i.pos[1].y)&&(i.pos[1].x=a.x=o.x,o.x=d.x,i.pos[1].y=a.y=o.y,o.y=d.y),H(a.x)===H(i.pos[0].x)&&H(a.y)===H(i.pos[0].y)&&(i.pos[0].x=a.x=o.x,o.x=c.x,i.pos[0].y=a.y=o.y,o.y=c.y)}else i.mode===zt.rectangle&&a?yi(i,a,o):i.pos[1].add_(r);t.simpleObjects.get(n).visel.translate(gt.obj2scaled(r,t.render.options)),this.data.d=r.negated(),this.data.noinvalidate||bo.invalidateItem(t,"simpleObjects",n,1)}},{key:"invert",value:function(){return new n(this.data.id,this.data.d,this.data.current,this.data.anchor,this.data.noinvalidate,this.data.toCircle)}}]),n}(bo);function wi(t,e){var n=$.diff(e,t),r=Math.abs(n.x)0?1:-1)*Math.abs(r),t.y+(n.y>0?1:-1)*Math.abs(r),0)}function xi(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var Ei=function(t){(0,f.Z)(n,t);var e=xi(n);function n(t,r){var i;return(0,o.Z)(this,n),(i=e.call(this,wo.S_GROUP_ATOM_ADD,yo.S_GROUP_ATOM_ADD)).data={sgid:t,aid:r},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.aid,r=e.sgid,o=t.molecule,i=o.atoms.get(n);if(o.sgroups.get(r).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");o.atomAddToSGroup(r,n),bo.invalidateAtom(t,n)}},{key:"invert",value:function(){var t=new Pi;return t.data=this.data,t}}]),n}(bo),Pi=function(t){(0,f.Z)(n,t);var e=xi(n);function n(t,r){var i;return(0,o.Z)(this,n),(i=e.call(this,wo.S_GROUP_ATOM_REMOVE,4)).data={sgid:t,aid:r},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.aid,r=e.sgid,o=t.molecule,i=o.atoms.get(n),a=o.sgroups.get(r);i&&a&&(Zt.removeAtom(a,n),i.sgs.delete(r),bo.invalidateAtom(t,n))}},{key:"invert",value:function(){var t=new Ei;return t.data=this.data,t}}]),n}(bo);var Oi=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e,n){var i;return(0,o.Z)(this,a),(i=r.call(this,wo.S_GROUP_ATTR,yo.S_GROUP_ATTR)).data={sgid:t,attr:e,value:n},i}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=t.molecule,n=this.data.sgid,r=e.sgroups.get(n);if(r){var o=t.sgroupData.get(n);"DAT"===r.type&&o&&(t.clearVisel(o.visel),t.sgroupData.delete(n)),this.data.value=r.setAttr(this.data.attr,this.data.value)}}},{key:"invert",value:function(){var t=new a;return t.data=this.data,t}}]),a}(bo);var Ai=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e){var n;return(0,o.Z)(this,a),(n=r.call(this,wo.S_GROUP_DATA_MOVE)).data={id:t,d:e},n}return(0,i.Z)(a,[{key:"execute",value:function(t){var e,n=this.data,r=n.d,o=n.id;null===(e=t.molecule.sgroups.get(o).pp)||void 0===e||e.add_(r),this.data.d=r.negated(),bo.invalidateItem(t,"sgroupData",o,1)}},{key:"invert",value:function(){var t=new a;return t.data=this.data,t}}]),a}(bo);function Ri(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var Si=function(t){(0,f.Z)(n,t);var e=Ri(n);function n(t,r,i){var a;return(0,o.Z)(this,n),(a=e.call(this,wo.S_GROUP_ADD_TO_HIERACHY,yo.S_GROUP_ADD_TO_HIERACHY)).data={sgid:t,parent:r,children:i},a}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.sgid,r=e.parent,o=e.children,i=t.molecule,a=i.sgroups.get(n),s=i.sGroupForest.insert(a,r,o);this.data.parent=s.parent,this.data.children=s.children}},{key:"invert",value:function(){var t=new Ti;return t.data=this.data,t}}]),n}(bo),Ti=function(t){(0,f.Z)(n,t);var e=Ri(n);function n(t){var r;return(0,o.Z)(this,n),(r=e.call(this,wo.S_GROUP_REMOVE_FROM_HIERACHY,110)).data={sgid:t},r}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data.sgid,n=t.molecule;this.data.parent=n.sGroupForest.parent.get(e),this.data.children=n.sGroupForest.children.get(e),n.sGroupForest.remove(e)}},{key:"invert",value:function(){var t=new Si;return t.data=this.data,t}}]),n}(bo);function ki(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var Bi=function(t){(0,f.Z)(n,t);var e=ki(n);function n(t,r,i,a,s){var u;return(0,o.Z)(this,n),(u=e.call(this,wo.S_GROUP_CREATE)).data={sgid:t,type:r,pp:i,expanded:a,name:s},u}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=new Zt(this.data.type),r=this.data,o=r.sgid,i=r.pp,a=r.expanded,s=r.name;n.id=o,e.sgroups.set(o,n),i&&(e.sgroups.get(o).pp=new $(i)),a&&(n.data.expanded=a),s&&(n.data.name=s);var u=e.sgroups.get(o);u&&(t.sgroups.set(o,new Sr(u)),(Lt.isFunctionalGroup(n)||Zt.isSuperAtom(n))&&t.molecule.functionalGroups.add(new Lt(n))),this.data.sgid=o}},{key:"invert",value:function(){var t=new Ci;return t.data=this.data,t}}]),n}(bo),Ci=function(t){(0,f.Z)(n,t);var e=ki(n);function n(t){var r;return(0,o.Z)(this,n),(r=e.call(this,wo.S_GROUP_DELETE,yo.S_GROUP_DELETE)).data={sgid:t},r}return(0,i.Z)(n,[{key:"execute",value:function(t){var e,n,r,o,i=t.molecule,a=this.data.sgid,s=t.sgroups.get(a),u=t.sgroupData.get(a);if(s){if(this.data.type=null==s||null===(e=s.item)||void 0===e?void 0:e.type,this.data.pp=null==s||null===(n=s.item)||void 0===n?void 0:n.pp,"DAT"===(null==s||null===(r=s.item)||void 0===r?void 0:r.type)&&u&&(t.clearVisel(u.visel),t.sgroupData.delete(a)),t.clearVisel(s.visel),0!==(null==s||null===(o=s.item)||void 0===o||null===(o=o.atoms)||void 0===o?void 0:o.length))throw new Error("S-Group not empty!");var l;(Lt.isFunctionalGroup(s.item)||Zt.isSuperAtom(s.item))&&(this.data.name=s.item.data.name,this.data.expanded=s.item.isExpanded(),t.molecule.functionalGroups.forEach((function(t,e){t.relatedSGroupId===a&&(l=e)})),t.molecule.functionalGroups.delete(l)),t.sgroups.delete(a),i.sgroups.delete(a)}}},{key:"invert",value:function(){var t=new Bi;return t.data=this.data,t}}]),n}(bo);function Zi(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var Ii=function(t){(0,f.Z)(n,t);var e=Zi(n);function n(t,r,i,a){var s;return(0,o.Z)(this,n),(s=e.call(this,wo.TEXT_CREATE)).data={content:t,position:r,pos:i,id:a},s}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=new ee(this.data);if(null==this.data.id){var n=t.molecule.texts.add(e);this.data.id=n}else t.molecule.texts.set(this.data.id,e);var r=this.data.id;t.texts.set(r,new _r(e)),t.molecule.textSetPosition(r,new $(this.data.position)),bo.invalidateItem(t,"texts",r,1)}},{key:"invert",value:function(){return new Mi(this.data.id)}}]),n}(bo),Mi=function(t){(0,f.Z)(n,t);var e=Zi(n);function n(t){var r;return(0,o.Z)(this,n),(r=e.call(this,wo.TEXT_DELETE)).data={id:t},r}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=e.texts.get(this.data.id);n&&(this.data.content=n.content,this.data.position=n.position,t.markItemRemoved(),t.clearVisel(t.texts.get(this.data.id).visel),t.texts.delete(this.data.id),e.texts.delete(this.data.id))}},{key:"invert",value:function(){return new Ii(this.data.content,this.data.position,this.data.pos,this.data.id)}}]),n}(bo);var Ni=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e){var n;return(0,o.Z)(this,a),(n=r.call(this,wo.TEXT_UPDATE)).data={id:t,content:e},n}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=this.data,n=e.id,r=e.content,o=t.molecule.texts.get(n);o&&(this.data.previousContent=o.content,o.content=r),bo.invalidateItem(t,"texts",n,1)}},{key:"invert",value:function(){var t=new a(this.data.id,this.data.previousContent);return t.data.previousContent=this.data.content,t}}]),a}(bo);var _i=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t,e,n){var i;return(0,o.Z)(this,a),(i=r.call(this,wo.TEXT_MOVE)).data={id:t,d:e,noinvalidate:n},i}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=t.molecule,n=this.data.id,r=this.data.d,o=e.texts.get(n),i=t.texts.get(n);o&&i&&(o.position.add_(r),o.setPos(i.getReferencePoints()),i.visel.translate(gt.obj2scaled(r,t.render.options)),this.data.d=r.negated(),this.data.noinvalidate||bo.invalidateItem(t,"texts",n,1))}},{key:"invert",value:function(){var t=new a(this.data.id,this.data.d,this.data.noinvalidate);return t.data=this.data,t}}]),a}(bo),Di=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];(0,o.Z)(this,t),this.operations=e}return(0,i.Z)(t,[{key:"addOp",value:function(t,e){return e&&t.isDummy(e)||this.operations.push(t),t}},{key:"mergeWith",value:function(t){return this.operations=this.operations.concat(t.operations),this}},{key:"perform",value:function(e){var n=new t;return(0,h.Z)(this.operations).sort((function(t,e){return t.priority-e.priority})).forEach((function(t){var r=t.perform(e);n.addOp(r)})),n}},{key:"isDummy",value:function(t){return void 0===this.operations.find((function(e){return!t||!e.isDummy(t)}))}}]),t}(),Li=["id","dist"];function ji(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}var Fi=.4,Gi={atoms:Hi,bonds:zi,enhancedFlags:function(t,e,n,r,o){var i,a=null;return t.enhancedFlags.forEach((function(n,r){var s=t.molecule.frags.get(r);if(s&&s.enhancedStereoFlag&&o.showStereoFlags){var u=s.stereoFlagPosition?new $(s.stereoFlagPosition.x,s.stereoFlagPosition.y):vt.getDefaultStereoFlagPosition(t.molecule,r);if(u&&!(Math.abs(e.x-u.x)>=1)){var l=Math.abs(e.y-u.y);l<.3&&(!a||le.y&&i.p0.xe.x,s=Math.min(Math.abs(i.p0.x-e.x),Math.abs(i.p1.x-e.x));a&&(null===r||sl.y&&d.p0.xl.x,f=Math.min(Math.abs(d.p0.x-l.x),Math.abs(d.p1.x-l.x));h&&(null===n||fv.y&&t.p0.xv.x,o=Math.min(Math.abs(t.p0.x-v.x),Math.abs(t.p1.x-v.x));e&&(null===n||o=s&&e.x<=l&&(e.yc?d.push(e.y-c):d.push(e.y-u,c-e.y)),e.xl&&e.y>c&&d.push($.dist(new $(l,c),e)),e.xc&&d.push($.dist(new $(s,c),e)),e.x>l&&e.y=u&&e.y<=c&&(e.xl?d.push(e.x-l):d.push(0));var h=Math.min.apply(Math,d);hFi*o?{id:i,dist:r}:null}var Ui={atom:Hi,item:function(t,e,n,r,o){return(n=n||Object.keys(Gi)).reduce((function(n,i){var s=n?n.dist:null,u=Gi[i](t,e,r,s,o);return null!==u&&(null===n||u.dist2&&void 0!==arguments[2]?arguments[2]:["atoms","bonds"],r=arguments.length>3?arguments[3]:void 0,o={atoms:new Map,bonds:new Map},i=t.molecule;e.atoms.forEach((function(t){o.atoms.set(t,i.atoms.get(t).pp)})),e.bonds.forEach((function(t){var e=i.bonds.get(t);o.bonds.set(t,$.lc2(i.atoms.get(e.begin).pp,.5,i.atoms.get(e.end).pp,.5))}));var a={};return n.forEach((function(n){a[n]=Array.from(o[n].keys()).reduce((function(i,a){var s={map:n,id:a},u=Gi[n](t,o[n].get(a),s,null,r);return u&&!e[n].includes(u.id)&&i.set(a,u.id),i}),new Map)})),a}};function Vi(t,e,n){var r=t.molecule.atoms.get(e);return r?r[n]:null}function Wi(t,e){return t.atoms.get(e).a.neighbors.length}function Yi(t,e){return Array.from(t.atoms.get(e).a.sgs)}function qi(t,e){return t.molecule.atoms.get(e).pp}function $i(t,e){return e?e.filter((function(e){var n=t.atoms.get(e);return null!==(null==n?void 0:n.stereoLabel)||at.getConnectedBondIds(t,e).some((function(n){var r=t.bonds.get(n);return(null==r?void 0:r.begin)===e&&(null==r?void 0:r.stereo)}))})):[]}function Xi(t){return St.reduce((function(e,n){return e[n]=Array.from(t[n].keys()),e}),{})}function Ki(t,e,n){var r,o,i=[],a=qi(t,e),s=t.molecule.atomGetNeighbors(e),u=t.molecule.findBondId(e,s.length?null===(r=s[0])||void 0===r?void 0:r.aid:void 0),l=t.molecule.bonds.get(u),c=l?l.type:n?n.type:1;t.molecule.atomGetNeighbors(e).forEach((function(e){var n=qi(t,e.aid);$.dist(a,n)<.1||i.push({id:e.aid,v:$.diff(n,a)})})),i.sort((function(t,e){return Math.atan2(t.v.y,t.v.x)-Math.atan2(e.v.y,e.v.x)}));var d,h=0,f=0;for(o=0;of&&(h=o,f=d);var p=new $(1,0);if(i.length>0){if(1===i.length){f=-4*Math.PI/3;var m=t.molecule.atomGetNeighbors(e)[0];if(Wi(t,m.aid)>1){var v=[],g=qi(t,m.aid),y=$.diff(a,g),b=Math.atan2(y.y,y.x);t.molecule.atomGetNeighbors(m.aid).forEach((function(e){var n=qi(t,e.aid);if(!(e.bid===m.bid||$.dist(g,n)<.1)){var r=$.diff(n,g),o=Math.atan2(r.y,r.x)-b;o<0&&(o+=2*Math.PI),v.push(o)}})),v.sort((function(t,e){return t-e})),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)===dt.PATTERN.TYPE.DOUBLE||(null==n?void 0:n.type)===dt.PATTERN.TYPE.TRIPLE)||c===dt.PATTERN.TYPE.SINGLE&&(null==n?void 0:n.type)===dt.PATTERN.TYPE.TRIPLE||c===dt.PATTERN.TYPE.TRIPLE&&(null==n?void 0:n.type)===dt.PATTERN.TYPE.SINGLE){var w=t.molecule.bonds.get(u).angle;d=w>-90&&w<90&&i[0].v.x>0?w*Math.PI/180+Math.PI:w*Math.PI/180}else d=f/2+Math.atan2(i[h].v.y,i[h].v.x);p=p.rotate(d)}p.add_(a);var x=Ui.atom(t,p,null,.1);return{atom:x=null===x?{label:"C"}:x.id,pos:p}}function Qi(t,e){return t.sgroups.filter((function(t,n){return!n.data.attached&&!n.data.absolute&&0===(0,E.difference)(n.atoms,e).length}))}function Ji(t,e){var n=t.begin,r=t.end;if(!e.atoms)return!1;var o=e.atoms.includes(n)&&!e.atoms.includes(r),i=e.atoms.includes(r)&&!e.atoms.includes(n);return o||i}function ta(t,e,n){var r=new Di;return Object.keys(n).forEach((function(t){r.addOp(new $o(e,t,n[t]))})),r.perform(t)}function ea(t,e,n){var r=new Di;return r.addOp(new Xo(e,n)),r.perform(t)}function na(t,e,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],o=new Di;return t.molecule.rgroups.get(n)||o.addOp(new Do(e,n,r)),o.perform(t)}function ra(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var oa=function(t){(0,f.Z)(n,t);var e=ra(n);function n(t,r){var i;return(0,o.Z)(this,n),(i=e.call(this,wo.S_GROUP_ATTACHMENT_POINT_ADD,yo.S_GROUP_ATTACHMENT_POINT_ADD)).data={sGroupId:t,attachmentPoint:r},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=t.molecule,n=e.sgroups.get(this.data.sGroupId);u()(null!=n);var r=this.data.attachmentPoint;if(!e.atoms.get(r.atomId))throw new Error('attachmentPoint for Atom with id "'.concat(r.atomId,'" is not found'));n.addAttachmentPoint(r)}},{key:"invert",value:function(){return new ia(this.data.sGroupId,this.data.attachmentPoint)}}]),n}(bo),ia=function(t){(0,f.Z)(n,t);var e=ra(n);function n(t,r){var i;return(0,o.Z)(this,n),(i=e.call(this,wo.S_GROUP_ATTACHMENT_POINT_REMOVE,4)).data={sGroupId:t,attachmentPoint:r},i}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.sGroupId,r=e.attachmentPoint,o=t.molecule.sgroups.get(n);null==o||o.removeAttachmentPoint(r.atomId)}},{key:"invert",value:function(){return new oa(this.data.sGroupId,this.data.attachmentPoint)}}]),n}(bo);function aa(t,e,n,r){var o=r.fieldValue;return"string"==typeof o||"DAT"!==e?da(t,e,n,r,t.molecule.sgroups.newId(),[]):o.reduce((function(o,i){var a=Object.assign({},r);return a.fieldValue=i,o.mergeWith(da(t,e,n,a,t.molecule.sgroups.newId(),[]))}),new Di)}function sa(t,e,n){var r=new Di;Object.keys(n).forEach((function(t){r.addOp(new Oi(e,t,n[t]))}));var o=t.molecule.sgroups.get(e);return u()(null!=o),Zt.getAtoms(t,o).forEach((function(e){var n;r.mergeWith(Sa(t,e,null===(n=t.atoms.get(e))||void 0===n?void 0:n.a,!1))})),r.perform(t)}function ua(t){var e=new Di,n=t.molecule;return n.sgroups.forEach((function(r){r.isNotContractible(n)&&e.mergeWith(sa(t,r.id,{expanded:!0}))})),e}function la(t,e){var n=new Di;return Object.keys(e).forEach((function(r){n.addOp(new Oi(t,r,e[r]))})),n}function ca(t,e){var n=new Di,r=t.molecule,o=t.sgroups.get(e).item;"SRU"===o.type&&(r.sGroupsRecalcCrossBonds(),o.neiAtoms.forEach((function(e){"*"===Vi(t,e,"label")&&n.addOp(new xo(e,"label","C"))})));var i=r.sgroups.get(e),a=Zt.getAtoms(r,i),s=i.getAttrs();return n.addOp(new Ti(e)),a.forEach((function(t){n.addOp(new Pi(e,t))})),i.getAttachmentPoints().forEach((function(t){n.addOp(new ia(e,t))})),n.addOp(new Ci(e)),(n=n.perform(t)).mergeWith(la(e,s)),n}function da(t,e,n,r,o,i,a,s,u){var l=new Di;if(o=o-0===o?o:t.molecule.sgroups.newId(),"SUP"===e?l.addOp(new Bi(o,e,a,s,u)):l.addOp(new Bi(o,e,a)),n.forEach((function(t){l.addOp(new Ei(o,t))})),"SUP"===e&&i.forEach((function(t){l.addOp(new oa(o,t))})),l.addOp("DAT"!==e?new Si(o):new Si(o,-1,[])),l=l.perform(t),"SRU"===e){t.molecule.sGroupsRecalcCrossBonds();var c=new Di;t.sgroups.get(o).item.neiAtoms.forEach((function(e){var n=t.atoms.get(e).a.isPlainCarbon();1===Wi(t,e)&&n&&c.addOp(new xo(e,"label","*"))})),(c=c.perform(t)).mergeWith(l),l=c}return function(t,e,n){var r=new Di;return Object.keys(n).forEach((function(t){r.addOp(new Oi(e,t,n[t]))})),r.perform(t)}(t,o,r).mergeWith(l)}function ha(t,e,n,r,o){if(t===Rt.Bond)return function(t,e,n,r){var o=t.molecule,i=va(o,n);return r.bonds&&(i=(0,B.uniq)(i.concat(r.bonds))),i.reduce((function(n,r){var i=o.bonds.get(r);return n.action=n.action.mergeWith(aa(t,e.type,[i.begin,i.end],e.attrs)),n.selection.bonds.push(r),n}),{action:new Di,selection:{atoms:n,bonds:[]}})}(e,n,r,o);var i,a=(i=e.molecule,(o.bonds||[]).reduce((function(t,e){var n=i.bonds.get(e);return t.concat([n.begin,n.end])}),[])),s=(0,B.uniq)(r.concat(a));return t===Rt.Fragment?fa(e,n,s,Array.from(e.atoms.keys())):t===Rt.Multifragment?function(t,e,n){var r=va(t.molecule,n);return{action:aa(t,e.type,n,e.attrs),selection:{atoms:n,bonds:r}}}(e,n,s):t===Rt.Group?fa(e,n,s,s):t===Rt.Atom?function(t,e,n){return n.reduce((function(n,r){return n.action=n.action.mergeWith(aa(t,e.type,[r],e.attrs)),n}),{action:new Di,selection:{atoms:n,bonds:[]}})}(e,n,s):{action:aa(e,n.type,s,n.attrs)}}function fa(t,e,n,r){var o=new et(n.map((function(e){return t.atoms.get(e).a.fragment})));return Array.from(o).reduce((function(n,o){var i=r.reduce((function(e,n){var r=t.atoms.get(n).a;return o===r.fragment&&e.push(n),e}),[]),a=va(t.molecule,i);return n.action=n.action.mergeWith(aa(t,e.type,i,e.attrs)),n.selection.atoms=n.selection.atoms.concat(i),n.selection.bonds=n.selection.bonds.concat(a),n}),{action:new Di,selection:{atoms:[],bonds:[]}})}function pa(t,e,n){var r=Yi(e,n);return r.length>0&&(r.forEach((function(e){t.addOp(new Pi(e,n))})),!0)}function ma(t,e,n){var r=e.molecule,o=new Map;n.forEach((function(t){Yi(e,t).forEach((function(t){o.set(t,o.has(t)?o.get(t)+1:1)}))})),o.forEach((function(n,o){var i=e.sgroups.get(o).item;if(Zt.getAtoms(e.molecule,i).length===n){var a=r.sgroups.get(o);t.mergeWith(la(o,a.getAttrs())),t.addOp(new Ti(o)),a.getAttachmentPoints().forEach((function(e){t.addOp(new ia(o,e))})),t.addOp(new Ci(o))}}))}function va(t,e){var n=new et(e);return Array.from(t.bonds.keys()).filter((function(e){var r=t.bonds.get(e);return n.has(r.begin)&&n.has(r.end)}))}function ga(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function ya(t){for(var e=1;e=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}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(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function _a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n=0&&i.add(n)}));s.has(t.b.begin)?a.add(t.b.begin):s.has(t.b.end)&&a.add(t.b.end)})),u.forEach((function(t){r.addOp(new So(t,n))})),i.forEach((function(e){t.reloops.get(e)&&t.reloops.get(e).visel&&r.addOp(new qo(e,n))})),e.atoms.forEach((function(t){r.addOp(new Eo(t,n,!a.has(t)))})),e.sgroupData&&0===e.sgroupData.length&&Qi(o,e.atoms).forEach((function(t){r.addOp(new Ai(t.id,n))}))}return e.rxnArrows&&e.rxnArrows.forEach((function(t){r.addOp(new ni(t,n,!0))})),e.rxnPluses&&e.rxnPluses.forEach((function(t){r.addOp(new si(t,n,!0))})),e.simpleObjects&&e.simpleObjects.forEach((function(t){r.addOp(new gi(t,n,!0))})),e.sgroupData&&e.sgroupData.forEach((function(t){r.addOp(new Ai(t,n))})),e.enhancedFlags&&e.enhancedFlags.forEach((function(t){r.addOp(new No(t,n))})),e.texts&&e.texts.forEach((function(t){r.addOp(new _i(t,n,!0))})),r.perform(t)}function Ua(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=new Di;if(!n){var o=t.molecule;t.molecule.frags.get(e).stereoAtoms.forEach((function(t){null===o.atoms.get(t).stereoLabel&&r.addOp(new Vo(e,t))}))}return r.addOp(new Wo(e)),r.perform(t)}function Va(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=new Di,o=Gt.findRGroupByFragment(t.molecule.rgroups,e);return t.molecule.atoms.forEach((function(n,i){if(n.fragment===e){var a=r.addOp((new Fo).perform(t)).frid;r.mergeWith(function(t,e,n,r){for(var o=[e],i=new et(o);o.length>0;){var a=o.shift();t.molecule.atomGetNeighbors(a).forEach((function(e){t.molecule.atoms.get(e.aid).fragment!==n||i.has(e.aid)||(i.add(e.aid),o.push(e.aid))}))}return Ta(t,i,r)}(t,i,e,a)),o&&r.mergeWith(ea(t,o,a))}})),-1!==e&&(r.mergeWith(ea(t,0,e)),r.addOp(new Ho(e).perform(t)),r.mergeWith(na(t,0,o,n))),r.operations.reverse(),r}function Wa(t,e,n){var r=new Di;return r.mergeWith(function(t,e){var n=new Di;return t.molecule.getRGroupAttachmentPointsByAtomId(e).forEach((function(t){n.addOp(new ei(t))})),n.perform(t)}(t,e)),r.mergeWith(Ya(t,n,e)),r}function Ya(t,e,n){var r=new Di;switch(e){case Q.FirstSideOnly:r.addOp(new Ko({atomId:n,attachmentPointType:"primary"}));break;case Q.SecondSideOnly:r.addOp(new Ko({atomId:n,attachmentPointType:"secondary"}));break;case Q.BothSides:r.addOp(new Ko({atomId:n,attachmentPointType:"primary"})),r.addOp(new Ko({atomId:n,attachmentPointType:"secondary"}))}return r.perform(t)}function qa(t,e){var n=function(t,e){var n=t.rgroupAttachmentPoints.get(e);u()(null!=n);var r=n.atomId,o=t.atoms.get(r),i=null==o?void 0:o.attachmentPoints,a=Q.None;if(i===Q.BothSides){var s=n.type;"primary"===s?a=Q.SecondSideOnly:"secondary"===s&&(a=Q.FirstSideOnly)}return{atomId:r,newAttachmentPoints:a}}(t.molecule,e),r=Sa(t,n.atomId,{attachmentPoints:n.newAttachmentPoints},null),o=new Di;return o.addOp(new ei(e)),o.perform(t).mergeWith(r)}function $a(t,e){return Qa(t,{atoms:[e]})}function Xa(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=new Di,o=t.molecule.bonds.get(e),i=[];return r.addOp(new Bo(e)),n.includes(o.begin)||0!==Wi(t,o.begin)||(pa(r,t,o.begin)&&i.push(o.begin),r.addOp(new Ao(o.begin))),n.includes(o.end)||0!==Wi(t,o.end)||(pa(r,t,o.end)&&i.push(o.end),r.addOp(new Ao(o.end))),ma(r,t,i),(r=r.perform(t)).addOp(new Yo([o.begin,o.end]).perform(t)),r.mergeWith(xa(t,o,!1)),r.operations.reverse(),r}function Ka(t,e){var n=t.molecule.getBondFragment(e),r=Xa(t,e);return Va(t,n).mergeWith(r)}function Qa(t,e){u()(null!=!!e);var n=new Di,r=[],o=[],i=function(t){return St.reduce((function(e,n){return e[n]=t[n]||[],e}),{})}(e);i.sgroups.forEach((function(e){var n=t.sgroups.get(e).item.atoms;i.atoms=i.atoms.concat(n),t.molecule.bonds.forEach((function(t,e){n.indexOf(t.begin)>=0&&n.indexOf(t.end)>=0&&i.bonds.push(e)}))})),i.atoms=Array.from(new Set(i.atoms)),i.bonds=Array.from(new Set(i.bonds)),i.atoms.forEach((function(e){t.molecule.atomGetNeighbors(e).forEach((function(t){-1===i.bonds.indexOf(t.bid)&&(i.bonds=i.bonds.concat([t.bid]))}))}));var a=new Di;i.bonds.forEach((function(e){var n=t.molecule.getBondFragment(e);o.indexOf(n)<0&&o.push(n),a.mergeWith(Xa(t,e,i.atoms))}));var s=[];i.atoms.forEach((function(e){var i=t.molecule.atoms.get(e).fragment;o.indexOf(i)<0&&o.push(i),pa(n,t,e)&&r.push(e),n.addOp(new Ao(e)),t.molecule.getRGroupAttachmentPointsByAtomId(e).forEach((function(t){n.addOp(new ei(t)),s.push(t)}))})),ma(n,t,r),i.rxnArrows.forEach((function(t){n.addOp(new fi(t))})),i.rxnPluses.forEach((function(t){n.addOp(new ci(t))})),i.simpleObjects.forEach((function(t){n.addOp(new vi(t))})),i.texts.forEach((function(t){n.addOp(new Mi(t))}));var l=new Di;i.rgroupAttachmentPoints.forEach((function(e){s.includes(e)||l.mergeWith(qa(t,e))})),(n=n.perform(t)).mergeWith(a).mergeWith(l);for(var c=o.map((function(e){return Gt.findRGroupByFragment(t.molecule.rgroups,e)}));o.length>0;)n=Va(t,o.pop(),c).mergeWith(n);return n}function Ja(t,e,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,o=function(t){if(1===t.sgroups.size){var e=t.sgroups.keys().next().value,n=t.sgroups.get(e);if(n.isContracted())return n.getContractedPosition(t).position}if(t.atoms.size>0){var r=1e50,o=r,i=-r,a=-o;return t.atoms.forEach((function(t){r=Math.min(r,t.pp.x),o=Math.min(o,t.pp.y),i=Math.max(i,t.pp.x),a=Math.max(a,t.pp.y)})),new $((r+i)/2,(o+a)/2)}return t.rxnArrows.size>0?t.rxnArrows.get(0).center():t.rxnPluses.size>0?t.rxnPluses.get(0).pp:t.simpleObjects.size>0?t.simpleObjects.get(0).center():t.texts.size>0?t.texts.get(0).position:new $(0,0)}(e),i=$.diff(n,o),a=new Di,s=new Map,u=new Map,l={atoms:[],bonds:[]};return e.atoms.forEach((function(e,i){u.has(e.fragment)||u.set(e.fragment,a.addOp(new Fo(null,e.fragment.properties).perform(t)).frid);var c=Object.assign(e.clone(),{fragment:u.get(e.fragment)}),d=new Oo(c,$.diff(e.pp,o).rotate(r).add(n)).perform(t);a.addOp(d),s.set(i,d.data.aid),l.atoms.push(d.data.aid),a.mergeWith(Ya(t,c.attachmentPoints,d.data.aid))})),e.frags.forEach((function(e,n){e&&(e.properties&&a.addOp(new Go(u.get(n),e.properties).perform(t)),e.stereoAtoms.forEach((function(e){return a.addOp(new Uo(u.get(n),s.get(e)).perform(t))})))})),e.bonds.forEach((function(e){var n=new ko(s.get(e.begin),s.get(e.end),e).perform(t);a.addOp(n),l.bonds.push(n.data.bid)})),l.atoms.forEach((function(e){a.addOp(new Yo([e]).perform(t))})),e.sgroups.forEach((function(n){var r=t.molecule.sgroups.newId(),o=n.atoms.map((function(t){return s.get(t)})),u=n.cloneAttachmentPoints(s);n.isNotContractible(e)&&n.setAttr("expanded",!0),da(t,n.type,o,n.data,r,u,n.pp?n.pp.add(i):null,"SUP"===n.type?n.isExpanded():null,n.data.name).operations.reverse().forEach((function(t){a.addOp(t)}))})),e.rxnArrows.forEach((function(e){a.addOp(new hi(e.pos.map((function(t){return t.add(i)})),e.mode).perform(t))})),e.rxnPluses.forEach((function(e){a.addOp(new li(e.pp.add(i)).perform(t))})),e.simpleObjects.forEach((function(e){a.addOp(new mi(e.pos.map((function(t){return t.add(i)})),e.mode).perform(t))})),e.texts.forEach((function(e){a.addOp(new Ii(e.content,e.position.add(i),e.pos.map((function(t){return t.add(i)}))).perform(t))})),e.rgroups.forEach((function(n,r){n.frags.forEach((function(e,n){a.addOp(new Xo(r,u.get(n)).perform(t))}));var o=e.rgroups.get(r).ifthen,i=e.rgroups.get(o)?o:0;a.mergeWith(ta(t,r,n.getAttrs())).mergeWith(na(t,i,n.ifthen))})),a.operations.reverse(),[a,l]}function ts(t,e,n){var r=new Di;return r.addOp(new hi(e,n)),r.perform(t)}function es(t,e,n,r,o,i){var a=new Di;return a.addOp(new ii(e,n,r,o,!1,i)),a.perform(t)}function ns(t,e){var n=new Di;return n.addOp(new fi(e)),n.perform(t)}function rs(t,e){var n=new Di;return n.addOp(new li(e).perform(t)),n}function os(t,e){var n=new Di;return n.addOp(new ci(e)),n.perform(t)}function is(t,e,n,o){var i=new Di,a=e||Xi(t.molecule);return i.mergeWith(function(t,e,n,r){var o,i=t.molecule,a=new Di;return null==e||null===(o=e.atoms)||void 0===o||o.forEach((function(t){var e=i.atoms.get(t);if(e){var o=as(e.pp,r,n);a.addOp(new Eo(t,o))}})),Qi(i,(null==e?void 0:e.atoms)||[]).forEach((function(t){if(t.pp){var e=as(t.pp,r,n);a.addOp(new Ai(t.id,e))}})),null!=e&&e.bonds&&function(t,e,n){t.forEach((function(t){var r=e.bonds.get(t);r&&r.type===dt.PATTERN.TYPE.SINGLE&&(r.stereo!==dt.PATTERN.STEREO.UP?r.stereo===dt.PATTERN.STEREO.DOWN&&n.addOp(new Ro(t,"stereo",dt.PATTERN.STEREO.UP)):n.addOp(new Ro(t,"stereo",dt.PATTERN.STEREO.DOWN)))}))}(e.bonds,i,a),a.perform(t)}(t,a,n,o)),a.rxnArrows&&i.mergeWith(function(t,e,n,o){var i=new Di;return e.forEach((function(e){var a=t.molecule.rxnArrows.get(e);if(a){var s=(0,r.Z)(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 ri(e,d,a.center()));var h=as(a.center(),o,n);i.addOp(new ni(e,h))}})),i.perform(t)}(t,a.rxnArrows,n,o)),a.rxnPluses&&i.mergeWith(function(t,e,n,r){var o=new Di;return e.forEach((function(e){var i=t.molecule.rxnPluses.get(e);if(i){var a=as(i.pp,r,n);o.addOp(new si(e,a))}})),o.perform(t)}(t,a.rxnPluses,n,o)),a.texts&&i.mergeWith(function(t,e,n,r){var o=new Di;return e.forEach((function(e){var i=t.molecule.texts.get(e);if(i){var a=i.pos[0],s=i.pos[2],u=as($.centre(a,s),r,n);o.addOp(new _i(e,u))}})),o.perform(t)}(t,a.texts,n,o)),i}function as(t,e,n){var r=new $;return"horizontal"===n?r.x=e.x>t.x?2*(e.x-t.x):-2*(t.x-e.x):r.y=e.y>t.y?2*(e.y-t.y):-2*(t.y-e.y),r}function ss(t,e,n,r){var o=t.molecule,i=new Di;return e||(e=Xi(o)),e.atoms&&(e.atoms.forEach((function(t){var e=o.atoms.get(t);i.addOp(new Eo(t,us(e.pp,n,r)))})),e.sgroupData||Qi(o,e.atoms).forEach((function(t){i.addOp(new Ai(t.id,us(t.pp,n,r)))}))),e.rxnArrows&&e.rxnArrows.forEach((function(t){i.addOp(new ri(t,r,n))})),e.rxnPluses&&e.rxnPluses.forEach((function(t){var e=o.rxnPluses.get(t);i.addOp(new si(t,us(e.pp,n,r)))})),e.texts&&e.texts.forEach((function(t){var e=o.texts.get(t);i.addOp(new _i(t,us(e.position,n,r)))})),e.sgroupData&&e.sgroupData.forEach((function(t){var e=o.sgroups.get(t);i.addOp(new Ai(t,us(e.pp,n,r)))})),e.enhancedFlags&&e.enhancedFlags.forEach((function(e){var o=e,a=t.molecule.frags.get(o);i.addOp(new No(e,us(a.stereoFlagPosition||vt.getDefaultStereoFlagPosition(t.molecule,o),n,r)))})),i.perform(t)}function us(t,e,n){var r=t.sub(e);return(r=r.rotate(n)).add_(e),r.sub(t)}function ls(t,e){var n=new Di;return n.addOp(new vi(e)),n.perform(t)}function cs(t,e,n,r){var o=new Di;return o.addOp(new mi(e,n,r)),o.perform(t)}function ds(t,e,n,r,o,i){var a=new Di;return a.addOp(new bi(e,n,r,o,!1,i)),a.perform(t)}function hs(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function fs(t){for(var e=1;e5&&void 0!==arguments[5]&&arguments[5],a=new Di,s=e.molecule,u=t.molecule,l=e.molecule.isSingleGroup(),c=u.atoms.get(n),d=n,f=null;if(o){var p=function(t,e,n){var r=new Di,o=Vi(t,e,"fragment"),i=null;if(null===n){var a=Ki(t,e),s=ba(t,{type:1},e,a.atom,void 0,a.pos.get_xy0());(r=s[0]).operations.reverse(),i=s[2]}else{var u=new Oo({label:"C",fragment:o},new $(1,0).rotate(n).add(t.molecule.atoms.get(e).pp).get_xy0()).perform(t);r.addOp(u),r.addOp(new ko(e,u.data.aid,{type:1}).perform(t)),i=u.data.aid}return{action:r,aid1:i}}(t,n,r);a=p.action,d=p.aid1,c=u.atoms.get(d),f=Ln.calcAngle(u.atoms.get(n).pp,c.pp)-e.angle0}else null===r&&(r=Ln.calcAngle(c.pp,Ki(t,n).pos)),f=r-e.angle0;var m=new Map,v=s.atoms.get(e.aid).pp,g=Vi(t,n,"fragment"),y={atoms:[],bonds:[]};return s.atoms.forEach((function(n,r){var o=at.getAttrHash(n);if(o.fragment=g,r===e.aid)a.mergeWith(Sa(t,d,o,!0)),m.set(r,d),y.atoms.push(d);else{var i=$.diff(n.pp,v).rotate(f).add(c.pp),s=new Oo(o,i.get_xy0()).perform(t);a.addOp(s),m.set(r,s.data.aid),y.atoms.push(s.data.aid)}})),l||Ca(a,t,y.atoms,n),s.bonds.forEach((function(e){var n=new ko(m.get(e.begin),m.get(e.end),e).perform(t);a.addOp(n),new Ro(n.data.bid,"isPreview",i).perform(t),y.bonds.push(n.data.bid)})),s.sgroups.forEach((function(e){var n=t.molecule.sgroups.newId(),r=e.atoms.map((function(t){return m.get(t)})),o=e.cloneAttachmentPoints(m);da(t,e.type,r,fs(fs({},e.data),{},{expanded:!!i||e.data.expanded}),n,o,c.pp,"SUP"===e.type?e.isExpanded():null,e.data.name).operations.reverse().forEach((function(t){a.addOp(t)}))})),a.operations.reverse(),a.addOp(new Yo([].concat((0,h.Z)(y.atoms),[n])).perform(t)),a.mergeWith(xa(t,t.molecule.bonds.get(y.bonds[0]))),[a,y]}function bs(t,e,n,r,o,i){var a=arguments.length>6&&void 0!==arguments[6]&&arguments[6];return i?function(t,e,n,r,i){var s=function(t,e,n){return ws(t,e,n,o,a)}(t,e,n);return Promise.resolve(s)}(t,e,n):ws(t,e,n,o)}function ws(t,e,n,r){var o=arguments.length>4&&void 0!==arguments[4]&&arguments[4],i=new Di,a=e.molecule,s=t.molecule,u=s.bonds.get(n),l=a.bonds.get(e.bid),c=a.atoms.get(r?l.end:l.begin),d=new Map([[l.begin,r?u.end:u.begin],[l.end,r?u.begin:u.end]]),f={begin:r?l.end:l.begin,end:r?l.begin:l.end},p=Ln.mergeBondsParams(s,u,a,f),m=p.angle,v=p.scale,g=s.getBondFragment(n),y={atoms:[],bonds:[]};a.atoms.forEach((function(e,n){var r=at.getAttrHash(e);if(r.fragment=g,n!==l.begin&&n!==l.end){var o=$.diff(e.pp,c.pp).rotate(m).scaled(v).add(s.atoms.get(u.begin).pp),a=Ui.atom(t,o,null,.1);if(null===a){var h=new Oo(r,o).perform(t);i.addOp(h),d.set(n,h.data.aid),y.atoms.push(h.data.aid)}else d.set(n,a.id),i.mergeWith(Sa(t,d.get(n),r,!0))}else i.mergeWith(Sa(t,d.get(n),r,!0))})),Ca(i,t,y.atoms,u.begin);var b=function(t,e,n,r){var o=t.name===ps,i=t.name===ms;if(t.bonds.size&&(o||i)){var a=dt.getBondNeighbourIds(e,n),s=a.beginBondIds,u=a.endBondIds;if(1!==s.length||1!==u.length)return null;var l=e.bonds.get(s[0]),c=e.bonds.get(u[0]);if(!l||!c)throw new Error("Incorrect bond id was provided");if(o)return dt.getBenzeneConnectingBondType(r,l,c);if(i)return dt.getCyclopentadieneFusingBondType(r,l,c)}return null}(a,s,n,u),w=null!==b;return a.bonds.forEach((function(e,r){var c=s.findBondId(d.get(e.begin),d.get(e.end)),h=null;if(null===c){var f=new ko(d.get(e.begin),d.get(e.end),e).perform(t);i.addOp(f);var p=f.data.bid;if(h=p,w){var m=a.name===ps,v=a.name===ms;if(m){var g=vs.includes(r)?dt.PATTERN.TYPE.DOUBLE:dt.PATTERN.TYPE.SINGLE;i.addOp(new Ro(p,"type",g).perform(t))}if(v){var x=dt.getBondNeighbourIds(s,n),E=x.beginBondIds,P=x.endBondIds,O=s.bonds.get(E[0]),A=s.bonds.get(P[0]),R=dt.getCyclopentadieneDoubleBondIndexes(u,O,A).includes(r)?dt.PATTERN.TYPE.DOUBLE:dt.PATTERN.TYPE.SINGLE;i.addOp(new Ro(p,"type",R).perform(t))}}y.bonds.push(p)}else{var S=u.type>l.type?u:l;i.mergeWith(wa(t,c,S,!0)),w&&b&&i.addOp(new Ro(n,"type",b).perform(t)),h=n}i.addOp(new Ro(h,"isPreview",o).perform(t))})),y.atoms.length&&i.addOp(new Yo([u.begin,u.end].concat((0,h.Z)(y.atoms))).perform(t)),y.bonds.length&&i.mergeWith(xa(t,t.molecule.bonds.get(y.bonds[0]))),i.operations.reverse(),[i,y]}function xs(t,e,n,r){var o=new Di;return o.addOp(new Ii(e,n,r)),o.perform(t)}function Es(t,e,n){var r=new Di;return r.addOp(new Ni(e,n)),r.perform(t)}function Ps(t,e){var n=new Di;return n.addOp(new Mi(e)),n.perform(t)}function Os(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=(0,m.Z)(t);if(e){var o=(0,m.Z)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return(0,p.Z)(this,n)}}var As=function(t){(0,f.Z)(n,t);var e=Os(n);function n(t,r,i,a){var s;return(0,o.Z)(this,n),(s=e.call(this,wo.ADD_HIGHLIGHT)).data={atoms:t,bonds:r,color:i,highlightId:a},s}return(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.data,n=e.atoms,r=e.bonds,o=e.color;if(o){var i=t.molecule,a=new ne({atoms:n,bonds:r,color:o});"number"!=typeof this.data.highlightId?this.data.highlightId=i.highlights.add(a):i.highlights.set(this.data.highlightId,a),Ss(t,n,r)}}},{key:"invert",value:function(){var t=this.data,e=t.atoms,n=t.bonds,r=t.color,o=t.highlightId;return new Rs(o,e,n,r)}}]),n}(bo),Rs=function(t){(0,f.Z)(n,t);var e=Os(n);function n(t,r,i,a){var s;return(0,o.Z)(this,n),(s=e.call(this,wo.REMOVE_HIGHLIGHT,5)).data={highlightId:t,atoms:r||[],bonds:i||[],color:a||"white"},s}return(0,i.Z)(n,[{key:"execute",value:function(t){if("number"==typeof this.data.highlightId){var e=t.molecule,n=e.highlights.get(this.data.highlightId);if(void 0===n)return;var r=n.atoms,o=n.bonds,i=n.color;this.data.atoms=r,this.data.bonds=o,this.data.color=i,e.highlights.delete(this.data.highlightId),Ss(t,r,o)}}},{key:"invert",value:function(){var t=this.data,e=t.atoms,n=t.bonds,r=t.color,o=t.highlightId,i=new As(e,n,r,o);return i.data=this.data,i}}]),n}(bo);function Ss(t,e,n){var r=t.atoms,o=t.bonds;e&&e.forEach((function(e){void 0!==r.get(e)&&t.markAtom(e,1)})),n&&n.forEach((function(e){void 0!==o.get(e)&&t.markBond(e,1)}))}function Ts(t,e){var n=new Di;return e.forEach((function(t){var e=t.atoms,r=t.bonds,o=t.color;n.addOp(new As(e,r,o))})),n.perform(t)}function ks(t){var e=new Di;return t.molecule.highlights.forEach((function(t,n){e.addOp(new Rs(n))})),e.perform(t)}!function(t){(0,f.Z)(n,t);var e=Os(n);function n(t,r,i,a){var s;return(0,o.Z)(this,n),(s=e.call(this,wo.UPDATE_HIGHLIGHT)).newData={atoms:r,bonds:i,color:a,highlightId:t},s.oldData={atoms:r,bonds:i,color:a,highlightId:t},s}(0,i.Z)(n,[{key:"execute",value:function(t){var e=this.newData,n=e.atoms,r=e.bonds,o=e.color;if(o){var i=this.newData.highlightId,a=t.molecule,s=a.highlights.get(i);if(s){var u=s.atoms,l=s.bonds,c=s.color;this.oldData={atoms:u,bonds:l,color:c,highlightId:i};var d=new ne({atoms:n,bonds:r,color:o});a.highlights.set(this.newData.highlightId,d),Ss(t,[].concat((0,h.Z)(n),(0,h.Z)(u)),[].concat((0,h.Z)(r),(0,h.Z)(l)))}}}},{key:"invert",value:function(){var t=this.oldData,e=t.atoms,r=t.bonds,o=t.color;return new n(this.newData.highlightId,e,r,o)}}])}(bo);var Bs=1,Cs=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new $(0,0);(0,o.Z)(this,t),(0,a.Z)(this,"selected",!1),(0,a.Z)(this,"id",0),this._position=e,this._position=e||new $(0,0),this.id=Bs,Bs++}return(0,i.Z)(t,[{key:"moveRelative",value:function(t){this._position.x+=t.x,this._position.y+=t.y}},{key:"moveAbsolute",value:function(t){this._position=t}},{key:"position",get:function(){return this._position}},{key:"turnOnSelection",value:function(){this.selected=!0}},{key:"turnOffSelection",value:function(){this.selected=!1}}]),t}();var Zs=function(t){(0,f.Z)(s,t);var e,n,r=(e=s,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function s(t,e){var n;return(0,o.Z)(this,s),n=r.call(this,e),(0,a.Z)((0,b.Z)(n),"attachmentPointsToBonds",{R1:null,R2:null}),(0,a.Z)((0,b.Z)(n),"potentialAttachmentPointsToBonds",{R1:null,R2:null}),n._monomerItem=t,n}return(0,i.Z)(s,[{key:"monomerItem",get:function(){return this._monomerItem}},{key:"label",get:function(){return this.monomerItem.label}},{key:"setPotentialBond",value:function(t,e){this.potentialAttachmentPointsToBonds[t]=e}},{key:"getAttachmentPointByBond",value:function(t){for(var e in this.attachmentPointsToBonds)if(this.attachmentPointsToBonds[e]===t)return e}},{key:"getPotentialAttachmentPointByBond",value:function(t){for(var e in this.potentialAttachmentPointsToBonds)if(this.potentialAttachmentPointsToBonds[e]===t)return e}},{key:"firstFreeAttachmentPoint",get:function(){for(var t in this.attachmentPointsToBonds)if(null===this.attachmentPointsToBonds[t])return t}},{key:"R1AttachmentPoint",get:function(){if(null===this.attachmentPointsToBonds.R1)return"R1"}},{key:"R2AttachmentPoint",get:function(){if(null===this.attachmentPointsToBonds.R2)return"R2"}},{key:"hasFreeAttachmentPoint",get:function(){return Boolean(this.firstFreeAttachmentPoint)}},{key:"setRenderer",value:function(t){this.renderer=t}},{key:"forEachBond",value:function(t){for(var e in this.attachmentPointsToBonds)this.attachmentPointsToBonds[e]&&t(this.attachmentPointsToBonds[e])}},{key:"setBond",value:function(t,e){this.attachmentPointsToBonds[t]=e}},{key:"unsetBond",value:function(t){this.attachmentPointsToBonds[t]=null}},{key:"hasBonds",get:function(){var t=!1;for(var e in this.attachmentPointsToBonds)this.attachmentPointsToBonds[e]&&(t=!0);return t}},{key:"getPotentialBond",value:function(t){return this.potentialAttachmentPointsToBonds[t]}},{key:"removePotentialBonds",value:function(){for(var t in this.potentialAttachmentPointsToBonds)this.potentialAttachmentPointsToBonds[t]=null}},{key:"availableAttachmentPointForBondEnd",get:function(){return this.isAttachmentPointUsed("R2")?this.firstFreeAttachmentPoint:"R2"}},{key:"getBondByAttachmentPoint",value:function(t){return this.attachmentPointsToBonds[t]}},{key:"getPotentialBondByAttachmentPoint",value:function(t){return this.potentialAttachmentPointsToBonds[t]}},{key:"isAttachmentPointUsed",value:function(t){return Boolean(this.getBondByAttachmentPoint(t))}},{key:"isAttachmentPointPotentiallyUsed",value:function(t){return Boolean(this.getPotentialBondByAttachmentPoint(t))}}]),s}(Cs);var Is=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(){return(0,o.Z)(this,a),r.apply(this,arguments)}return(0,i.Z)(a)}(Zs);var Ms=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(){return(0,o.Z)(this,a),r.apply(this,arguments)}return(0,i.Z)(a)}(Zs);var Ns=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(){return(0,o.Z)(this,a),r.apply(this,arguments)}return(0,i.Z)(a)}(Zs);var _s=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(){return(0,o.Z)(this,a),r.apply(this,arguments)}return(0,i.Z)(a)}(Zs);var Ds=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(){return(0,o.Z)(this,a),r.apply(this,arguments)}return(0,i.Z)(a)}(Zs),Ls=function(t){var e,n;return"CHEM"===t.props.MonomerType?(e=Ms,n=Hr):"PEPTIDE"===t.props.MonomerType?(e=Is,n=zr):"R"===t.props.MonomerNaturalAnalogCode?(e=Ns,n=Vr):"P"===t.props.MonomerNaturalAnalogCode?(e=_s,n=Ur):(e=Ds,n=Wr),[e,n]};var js=function(t){(0,f.Z)(s,t);var e,n,a=(e=s,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function s(t,e){var n;return(0,o.Z)(this,s),(n=a.call(this,wo.ATOM_ADD)).data={monomer:t,position:e},n}return(0,i.Z)(s,[{key:"execute",value:function(t){var e=this.data,n=e.monomer,o=e.position,i=t.molecule,a=Ls(n),s=(0,r.Z)(a,2),u=s[0],l=s[1],c=new u(n,o),d=new l(c);i.monomers.set(c.id,c),t.monomers.set(c.id,d)}},{key:"invert",value:function(){var t=new s(this.data.monomer,this.data.position);return t.data=this.data,t}}]),s}(bo);var Fs=function(t){(0,f.Z)(s,t);var e,n,r=(e=s,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function s(t){var e;return(0,o.Z)(this,s),e=r.call(this),(0,a.Z)((0,b.Z)(e),"endPosition",new $),e.firstMonomer=t,e.firstMonomer=t,e}return(0,i.Z)(s,[{key:"setFirstMonomer",value:function(t){this.firstMonomer=t}},{key:"setSecondMonomer",value:function(t){this.secondMonomer=t}},{key:"setRenderer",value:function(t){this.renderer=t}},{key:"finished",get:function(){return Boolean(this.firstMonomer&&this.secondMonomer)}},{key:"moveToLinkedMonomers",value:function(){var t,e=this.firstMonomer.renderer.center,n=null===(t=this.secondMonomer)||void 0===t||null===(t=t.renderer)||void 0===t?void 0:t.center;this.moveBondStartAbsolute(e.x,e.y),n&&this.moveBondEndAbsolute(n.x,n.y)}},{key:"moveBondStartAbsolute",value:function(t,e){this.moveAbsolute(new $(t,e))}},{key:"moveBondEndAbsolute",value:function(t,e){this.endPosition=new $(t,e)}},{key:"startPosition",get:function(){return this.position}},{key:"turnOnSelection",value:function(){var t;(0,w.Z)((0,m.Z)(s.prototype),"turnOnSelection",this).call(this),this.firstMonomer.turnOnSelection(),null===(t=this.secondMonomer)||void 0===t||t.turnOnSelection()}},{key:"turnOffSelection",value:function(){var t;(0,w.Z)((0,m.Z)(s.prototype),"turnOffSelection",this).call(this),this.firstMonomer.turnOffSelection(),null===(t=this.secondMonomer)||void 0===t||t.turnOffSelection()}}]),s}(Cs);var Gs=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t){var e;return(0,o.Z)(this,a),(e=r.call(this,wo.POLYMER_BOND_ADD)).data=t,e}return(0,i.Z)(a,[{key:"execute",value:function(t){var e=this.data,n=e.firstMonomer,r=e.startPosition,o=e.endPosition,i=t.molecule,a=new Fs(n),s=new Fr(a);i.polymerBonds.set(a.id,a),t.polymerBonds.set(a.id,s),n.setPotentialBond(n.firstFreeAttachmentPoint,a),a.moveBondStartAbsolute(r.x,r.y),a.moveBondEndAbsolute(o.x,o.y)}},{key:"invert",value:function(){var t=new a(this.data.firstMonomer);return t.data=this.data,t}}]),a}(bo);var Hs=function(t){(0,f.Z)(a,t);var e,n,r=(e=a,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function a(t){var e;return(0,o.Z)(this,a),(e=r.call(this,wo.POLYMER_BOND_DELETE)).data={polymerBond:t},e}return(0,i.Z)(a,[{key:"execute",value:function(t){var e,n,r=this.data.polymerBond,o=t.molecule,i=t.polymerBonds.get(r.id);o.polymerBonds.delete(r.id),r.firstMonomer.turnOffSelection(),r.firstMonomer.removePotentialBonds(),null===(e=r.secondMonomer)||void 0===e||e.turnOffSelection(),null===(n=r.secondMonomer)||void 0===n||n.removePotentialBonds(),null==i||i.remove(),t.polymerBonds.delete(r.id)}},{key:"invert",value:function(){var t=new a(this.data.polymerBond);return t.data=this.data,t}}]),a}(bo);function zs(t,e){var n=new Di;return n.addOp(new Gs(e)).perform(t),n}var Us=function(){function t(){(0,o.Z)(this,t)}return(0,i.Z)(t,null,[{key:"deleteBondWithAllLinks",value:function(t,e,n){var r;!function(t,e){(new Di).addOp(new Hs(e)).perform(t)}(t,e),n?n.removePotentialBonds():null===(r=e.secondMonomer)||void 0===r||r.removePotentialBonds(),e.firstMonomer.removePotentialBonds()}},{key:"finishBondCreation",value:function(t,e,n,r){r.setSecondMonomer(n),r.firstMonomer.setBond(t,r),u()(r.secondMonomer),u()(n.renderer),r.secondMonomer.setBond(e,r),r.firstMonomer.removePotentialBonds(),r.secondMonomer.removePotentialBonds(),r.moveBondEndAbsolute(n.renderer.center.x,n.renderer.center.y),r.firstMonomer.turnOffSelection(),r.secondMonomer.turnOffSelection()}}]),t}();var Vs=function(t){(0,f.Z)(s,t);var e,n,a=(e=s,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,r=(0,m.Z)(e);if(n){var o=(0,m.Z)(this).constructor;t=Reflect.construct(r,arguments,o)}else t=r.apply(this,arguments);return(0,p.Z)(this,t)});function s(t,e){var n;return(0,o.Z)(this,s),(n=a.call(this,wo.ATOM_ADD)).data=e,n.renderersContainer=t,n}return(0,i.Z)(s,[{key:"execute",value:function(t){var e,n,o=this.data,i=o.sugar,a=o.sugarPosition,s=o.phosphate,u=o.phosphatePosition,l=o.rnaBase,c=o.rnaBasePosition,d=t.molecule,h=Ls(i),f=(0,r.Z)(h,2),p=f[0],m=f[1],v=new p(i,a),g=new m(v);if(d.monomers.set(v.id,v),t.monomers.set(v.id,g),l&&c){var y=Ls(l),b=(0,r.Z)(y,2),w=b[0],x=b[1],E=new w(l,c);e=new x(E),d.monomers.set(E.id,E),t.monomers.set(E.id,e)}if(s&&u){var P=Ls(s),O=(0,r.Z)(P,2),A=O[0],R=O[1],S=new A(s,u);n=new R(S),d.monomers.set(S.id,S),t.monomers.set(S.id,n)}this.renderersContainer.update(!1),this.makeBonds({sugarRenderer:g,rnaBaseRenderer:e,phosphateRenderer:n})}},{key:"invert",value:function(){var t=new s(this.renderersContainer,this.data);return t.data=this.data,t}},{key:"makeBonds",value:function(t){var e,n,r=t.sugarRenderer,o=t.rnaBaseRenderer,i=t.phosphateRenderer,a=null==r?void 0:r.monomer.R1AttachmentPoint,s=null==r?void 0:r.monomer.R2AttachmentPoint;a&&o&&(zs(this.renderersContainer,{firstMonomer:r.monomer,startPosition:{x:r.monomer.renderer.center.x,y:r.monomer.renderer.center.y},endPosition:new $(0,0)}),this.bondRenderer=null===(e=r.monomer)||void 0===e||null===(e=e.getPotentialBond(a))||void 0===e?void 0:e.renderer,u()(this.bondRenderer),r.monomer.setPotentialBond(a,this.bondRenderer.polymerBond),o.monomer.setPotentialBond(null==o?void 0:o.monomer.R2AttachmentPoint,this.bondRenderer.polymerBond),this.finishBondCreation(o.monomer),this.bondRenderer=void 0,this.renderersContainer.update(!1)),s&&i&&(zs(this.renderersContainer,{firstMonomer:i.monomer,startPosition:{x:i.monomer.renderer.center.x,y:i.monomer.renderer.center.y},endPosition:new $(0,0)}),this.bondRenderer=null===(n=i.monomer)||void 0===n||null===(n=n.getPotentialBond(a))||void 0===n?void 0:n.renderer,u()(this.bondRenderer),r.monomer.setPotentialBond(s,this.bondRenderer.polymerBond),i.monomer.setPotentialBond(null==i?void 0:i.monomer.R1AttachmentPoint,this.bondRenderer.polymerBond),this.finishBondCreation(r.monomer),this.bondRenderer=void 0)}},{key:"finishBondCreation",value:function(t){u()(this.bondRenderer);var e=this.bondRenderer.polymerBond.firstMonomer.R1AttachmentPoint,n=t.R2AttachmentPoint;u()(e),u()(n),Us.finishBondCreation(e,n,t,this.bondRenderer.polymerBond)}}]),s}(bo);function Ws(t,e,n){this.f=t,this.once=e,this.priority=n}function Ys(){this.handlers=[]}var qs=Ys;function $s(t,e){for(var n=0;n=0;n--)t[n].once&&(e||(e=t.slice()),e.splice(n,1));return e&&(this.handlers=e),t},Ys.prototype.add=function(t,e){$s(this,new Ws(t,!1,e||0))},Ys.prototype.addOnce=function(t,e){$s(this,new Ws(t,!0,e||0))},Ys.prototype.remove=function(t){for(var e=0;e0},Ys.prototype.dispatch=function(){for(var t=this.handlersForDispatch(),e=0;e0&&a.length>o&&!a.warned){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=t,u.type=e,u.count=a.length,s=u,console&&console.warn&&console.warn(s)}return t}function el(){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 nl(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},o=el.bind(r);return o.listener=n,r.wrapFn=o,o}function rl(t,e,n){var r=t._events;if(void 0===r)return[];var o=r[e];return void 0===o?[]:"function"==typeof o?n?[o.listener||o]:[o]:n?function(t){for(var e=new Array(t.length),n=0;n0&&(i=e[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var s=o[t];if(void 0===s)return!1;if("function"==typeof s)Yu(s,this,e);else{var u=s.length,l=il(s,u);for(n=0;n=0;i--)if(n[i]===e||n[i].listener===e){a=n[i].listener,o=i;break}if(o<0)return this;0===o?n.shift():function(t,e){for(;e+1=0;r--)this.removeListener(t,e[r]);return this},$u.prototype.listeners=function(t){return rl(this,t,!0)},$u.prototype.rawListeners=function(t){return rl(this,t,!1)},$u.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):ol.call(t,e)},$u.prototype.listenerCount=ol,$u.prototype.eventNames=function(){return this._eventsCount>0?Hu(this._events):[]},Xu.once=function(t,e){return new Promise((function(n,r){function o(n){t.removeListener(e,i),r(n)}function i(){"function"==typeof t.removeListener&&t.removeListener("error",o),n([].slice.call(arguments))}al(t,e,i,{once:!0}),"error"!==e&&function(t,e,n){"function"==typeof t.on&&al(t,"error",e,{once:!0})}(t,o)}))};var sl=new(function(){function t(){(0,o.Z)(this,t)}return(0,i.Z)(t,[{key:"setKetcherInstance",value:function(t){this.ketcherInstance=t}},{key:"getKetcher",value:function(){return this.ketcherInstance}}]),t}());function ul(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:su.rxn,e=arguments.length>2?arguments[2]:void 0;return(arguments.length>1?arguments[1]:void 0).create(t).getStructureFromStructAsync(e)}function ll(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function cl(t){for(var e=1;e0&&void 0!==arguments[0]&&arguments[0]?su.smilesExt:su.smiles,(0,y.Z)(this,gl),this.editor.struct())}},{key:"getMolfile",value:(p=(0,l.Z)(d().mark((function t(e){var n,r,o;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.containsReaction()){t.next=2;break}throw Error("The structure cannot be saved as *.MOL due to reaction arrrows.");case 2:return n="v3000"===e?su.molV3000:su.mol,r=e?n:su.molAuto,t.next=6,ul(r,(0,y.Z)(this,gl),(0,y.Z)(this,yl).struct());case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t,this)}))),function(t){return p.apply(this,arguments)})},{key:"getRxn",value:(f=(0,l.Z)(d().mark((function t(){var e,n,r,o=arguments;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e=o.length>0&&void 0!==o[0]?o[0]:"v2000",this.containsReaction()){t.next=3;break}throw Error("The structure cannot be saved as *.RXN: there is no reaction arrows.");case 3:return n="v3000"===e?su.rxnV3000:su.rxn,t.next=6,ul(n,(0,y.Z)(this,gl),(0,y.Z)(this,yl).struct());case 6:return r=t.sent,t.abrupt("return",r);case 8:case"end":return t.stop()}}),t,this)}))),function(){return f.apply(this,arguments)})},{key:"getKet",value:function(){return ul(su.ket,(0,y.Z)(this,gl),(0,y.Z)(this,yl).struct())}},{key:"getSmarts",value:function(){return ul(su.smarts,(0,y.Z)(this,gl),(0,y.Z)(this,yl).struct())}},{key:"getCml",value:function(){return ul(su.cml,(0,y.Z)(this,gl),(0,y.Z)(this,yl).struct())}},{key:"getSdf",value:function(){return ul("v2000"===(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"v2000")?su.sdf:su.sdfV3000,(0,y.Z)(this,gl),(0,y.Z)(this,yl).struct())}},{key:"getCDXml",value:function(){return ul(su.cdxml,(0,y.Z)(this,gl),(0,y.Z)(this,yl).struct())}},{key:"getCDX",value:function(){return ul(su.cdx,(0,y.Z)(this,gl),(0,y.Z)(this,yl).struct())}},{key:"getInchi",value:function(){return ul(arguments.length>0&&void 0!==arguments[0]&&arguments[0]?su.inChIAuxInfo:su.inChI,(0,y.Z)(this,gl),(0,y.Z)(this,yl).struct())}},{key:"getInChIKey",value:(h=(0,l.Z)(d().mark((function t(){var e;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,ul(su.ket,(0,y.Z)(this,gl),(0,y.Z)(this,yl).struct());case 2:return e=t.sent,t.abrupt("return",(0,y.Z)(this,vl).getInChIKey(e));case 4:case"end":return t.stop()}}),t,this)}))),function(){return h.apply(this,arguments)})},{key:"containsReaction",value:function(){return this.editor.struct().hasRxnArrow()}},{key:"setMolecule",value:(c=(0,l.Z)(d().mark((function t(e){var n=this;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:U((0,l.Z)(d().mark((function t(){var r;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return u()("string"==typeof e),t.next=3,fl(e,(0,y.Z)(n,vl),n);case 3:r=t.sent,(0,y.Z)(n,yl).struct(r),(0,y.Z)(n,yl).zoomAccordingContent(r),(0,y.Z)(n,yl).centerStruct();case 7:case"end":return t.stop()}}),t)}))),this.eventBus);case 1:case"end":return t.stop()}}),t,this)}))),function(t){return c.apply(this,arguments)})},{key:"addFragment",value:(s=(0,l.Z)(d().mark((function t(e){var n=this;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:U((0,l.Z)(d().mark((function t(){var r;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return u()("string"==typeof e),t.next=3,fl(e,(0,y.Z)(n,vl),n);case 3:r=t.sent,(0,y.Z)(n,yl).structToAddFragment(r);case 5:case"end":return t.stop()}}),t)}))),this.eventBus);case 1:case"end":return t.stop()}}),t,this)}))),function(t){return s.apply(this,arguments)})},{key:"layout",value:(n=(0,l.Z)(d().mark((function t(){var e=this;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:U((0,l.Z)(d().mark((function t(){var n,r;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,(0,y.Z)(e,bl).layout((0,y.Z)(e,yl).struct());case 2:n=t.sent,r=new xe,e.setMolecule(r.serialize(n));case 5:case"end":return t.stop()}}),t)}))),this.eventBus);case 1:case"end":return t.stop()}}),t,this)}))),function(){return n.apply(this,arguments)})},{key:"recognize",value:function(t,e){return(0,y.Z)(this,bl).recognize(t,{version:e})}},{key:"generateImage",value:(e=(0,l.Z)(d().mark((function t(e){var n,r,o,i,a,s,u,l,c=arguments;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:n=c.length>1&&void 0!==c[1]?c[1]:{outputFormat:"png",bondThickness:Tt},r="",t.t0=n.outputFormat,t.next="svg"===t.t0?5:(t.t0,7);break;case 5:return r="image/svg+xml",t.abrupt("break",9);case 7:r="image/png",n.outputFormat="png";case 9:return t.next=11,(0,y.Z)(this,vl).generateImageAsBase64(e,n);case 11:for(o=t.sent,i=atob(o),a=new Array(i.length),s=0;s