react-cheminfo 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/README.md +39 -26
  2. package/lib/chrome/ui/HeaderToggle.d.ts +52 -0
  3. package/lib/chrome/ui/HeaderToggle.d.ts.map +1 -0
  4. package/lib/chrome/ui/HeaderToggle.js +31 -0
  5. package/lib/chrome/ui/HeaderToggle.js.map +1 -0
  6. package/lib/chrome/ui/index.d.ts +2 -0
  7. package/lib/chrome/ui/index.d.ts.map +1 -1
  8. package/lib/chrome/ui/index.js +1 -0
  9. package/lib/chrome/ui/index.js.map +1 -1
  10. package/lib/citation/core/gfn2Paper.d.ts +10 -0
  11. package/lib/citation/core/gfn2Paper.d.ts.map +1 -0
  12. package/lib/citation/core/gfn2Paper.js +28 -0
  13. package/lib/citation/core/gfn2Paper.js.map +1 -0
  14. package/lib/citation/core/index.d.ts +1 -0
  15. package/lib/citation/core/index.d.ts.map +1 -1
  16. package/lib/citation/core/index.js +1 -0
  17. package/lib/citation/core/index.js.map +1 -1
  18. package/lib/clipboard/ui/ClickToCopy.d.ts +8 -7
  19. package/lib/clipboard/ui/ClickToCopy.d.ts.map +1 -1
  20. package/lib/clipboard/ui/ClickToCopy.js +3 -3
  21. package/lib/clipboard/ui/ClickToCopy.js.map +1 -1
  22. package/lib/conformers.d.ts +27 -0
  23. package/lib/conformers.d.ts.map +1 -0
  24. package/lib/conformers.js +19 -0
  25. package/lib/conformers.js.map +1 -0
  26. package/lib/core.d.ts +1 -0
  27. package/lib/core.d.ts.map +1 -1
  28. package/lib/core.js +1 -0
  29. package/lib/core.js.map +1 -1
  30. package/lib/credits/core/credits.d.ts +12 -0
  31. package/lib/credits/core/credits.d.ts.map +1 -1
  32. package/lib/credits/core/credits.js +14 -0
  33. package/lib/credits/core/credits.js.map +1 -1
  34. package/lib/ecosystem/core/index.d.ts +1 -1
  35. package/lib/ecosystem/core/index.d.ts.map +1 -1
  36. package/lib/ecosystem/core/index.js.map +1 -1
  37. package/lib/ecosystem/core/sites.d.ts +11 -1
  38. package/lib/ecosystem/core/sites.d.ts.map +1 -1
  39. package/lib/ecosystem/core/sites.js +11 -4
  40. package/lib/ecosystem/core/sites.js.map +1 -1
  41. package/lib/ecosystem/ui/EcosystemLinks.d.ts.map +1 -1
  42. package/lib/ecosystem/ui/EcosystemLinks.js +3 -1
  43. package/lib/ecosystem/ui/EcosystemLinks.js.map +1 -1
  44. package/lib/ecosystem/ui/SiteTile.d.ts.map +1 -1
  45. package/lib/ecosystem/ui/SiteTile.js +3 -1
  46. package/lib/ecosystem/ui/SiteTile.js.map +1 -1
  47. package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
  48. package/lib/ecosystem/ui/glyphs.js +6 -5
  49. package/lib/ecosystem/ui/glyphs.js.map +1 -1
  50. package/lib/format/core/index.d.ts +1 -1
  51. package/lib/format/core/index.d.ts.map +1 -1
  52. package/lib/format/core/index.js +1 -1
  53. package/lib/format/core/index.js.map +1 -1
  54. package/lib/format/core/words.d.ts +9 -0
  55. package/lib/format/core/words.d.ts.map +1 -1
  56. package/lib/format/core/words.js +16 -0
  57. package/lib/format/core/words.js.map +1 -1
  58. package/lib/language/core/index.d.ts +3 -0
  59. package/lib/language/core/index.d.ts.map +1 -0
  60. package/lib/language/core/index.js +3 -0
  61. package/lib/language/core/index.js.map +1 -0
  62. package/lib/language/core/languageName.d.ts +8 -0
  63. package/lib/language/core/languageName.d.ts.map +1 -0
  64. package/lib/language/core/languageName.js +16 -0
  65. package/lib/language/core/languageName.js.map +1 -0
  66. package/lib/language/core/languageParam.d.ts +35 -0
  67. package/lib/language/core/languageParam.d.ts.map +1 -0
  68. package/lib/language/core/languageParam.js +67 -0
  69. package/lib/language/core/languageParam.js.map +1 -0
  70. package/lib/language/ui/SiteLanguage.d.ts +20 -0
  71. package/lib/language/ui/SiteLanguage.d.ts.map +1 -0
  72. package/lib/language/ui/SiteLanguage.js +14 -0
  73. package/lib/language/ui/SiteLanguage.js.map +1 -0
  74. package/lib/language/ui/index.d.ts +4 -0
  75. package/lib/language/ui/index.d.ts.map +1 -0
  76. package/lib/language/ui/index.js +3 -0
  77. package/lib/language/ui/index.js.map +1 -0
  78. package/lib/language/ui/siteLanguageContext.d.ts +12 -0
  79. package/lib/language/ui/siteLanguageContext.d.ts.map +1 -0
  80. package/lib/language/ui/siteLanguageContext.js +19 -0
  81. package/lib/language/ui/siteLanguageContext.js.map +1 -0
  82. package/lib/orbital/core/atomicOrbitals.d.ts +9 -1
  83. package/lib/orbital/core/atomicOrbitals.d.ts.map +1 -1
  84. package/lib/orbital/core/atomicOrbitals.js +7 -0
  85. package/lib/orbital/core/atomicOrbitals.js.map +1 -1
  86. package/lib/orbital/core/hydrogenic.d.ts +2 -1
  87. package/lib/orbital/core/hydrogenic.d.ts.map +1 -1
  88. package/lib/orbital/core/hydrogenic.js +2 -1
  89. package/lib/orbital/core/hydrogenic.js.map +1 -1
  90. package/lib/orbital/core/index.d.ts +1 -0
  91. package/lib/orbital/core/index.d.ts.map +1 -1
  92. package/lib/orbital/core/index.js +1 -0
  93. package/lib/orbital/core/index.js.map +1 -1
  94. package/lib/orbital/core/slaterEnergy.d.ts +35 -0
  95. package/lib/orbital/core/slaterEnergy.d.ts.map +1 -0
  96. package/lib/orbital/core/slaterEnergy.js +66 -0
  97. package/lib/orbital/core/slaterEnergy.js.map +1 -0
  98. package/lib/shared/ui/MenuButton.d.ts +3 -2
  99. package/lib/shared/ui/MenuButton.d.ts.map +1 -1
  100. package/lib/shared/ui/MenuButton.js +1 -1
  101. package/lib/shared/ui/MenuButton.js.map +1 -1
  102. package/lib/structure/core/conformerMinimise.d.ts +36 -0
  103. package/lib/structure/core/conformerMinimise.d.ts.map +1 -0
  104. package/lib/structure/core/conformerMinimise.js +81 -0
  105. package/lib/structure/core/conformerMinimise.js.map +1 -0
  106. package/lib/structure/core/conformerMinimum.d.ts +62 -0
  107. package/lib/structure/core/conformerMinimum.d.ts.map +1 -0
  108. package/lib/structure/core/conformerMinimum.js +90 -0
  109. package/lib/structure/core/conformerMinimum.js.map +1 -0
  110. package/lib/structure/core/conformerOptions.d.ts +62 -0
  111. package/lib/structure/core/conformerOptions.d.ts.map +1 -0
  112. package/lib/structure/core/conformerOptions.js +83 -0
  113. package/lib/structure/core/conformerOptions.js.map +1 -0
  114. package/lib/structure/core/conformerRefine.d.ts +104 -0
  115. package/lib/structure/core/conformerRefine.d.ts.map +1 -0
  116. package/lib/structure/core/conformerRefine.js +130 -0
  117. package/lib/structure/core/conformerRefine.js.map +1 -0
  118. package/lib/structure/core/conformerRefineRank.d.ts +36 -0
  119. package/lib/structure/core/conformerRefineRank.d.ts.map +1 -0
  120. package/lib/structure/core/conformerRefineRank.js +69 -0
  121. package/lib/structure/core/conformerRefineRank.js.map +1 -0
  122. package/lib/structure/core/conformerSession.d.ts +50 -0
  123. package/lib/structure/core/conformerSession.d.ts.map +1 -0
  124. package/lib/structure/core/conformerSession.js +88 -0
  125. package/lib/structure/core/conformerSession.js.map +1 -0
  126. package/lib/structure/core/conformerShape.d.ts +36 -0
  127. package/lib/structure/core/conformerShape.d.ts.map +1 -0
  128. package/lib/structure/core/conformerShape.js +150 -0
  129. package/lib/structure/core/conformerShape.js.map +1 -0
  130. package/lib/structure/core/conformers.d.ts +107 -0
  131. package/lib/structure/core/conformers.d.ts.map +1 -0
  132. package/lib/structure/core/conformers.js +149 -0
  133. package/lib/structure/core/conformers.js.map +1 -0
  134. package/lib/structure/core/geometryRelaxer.d.ts +66 -0
  135. package/lib/structure/core/geometryRelaxer.d.ts.map +1 -0
  136. package/lib/structure/core/geometryRelaxer.js +2 -0
  137. package/lib/structure/core/geometryRelaxer.js.map +1 -0
  138. package/lib/structure/core/index.d.ts +4 -0
  139. package/lib/structure/core/index.d.ts.map +1 -1
  140. package/lib/structure/core/index.js +2 -0
  141. package/lib/structure/core/index.js.map +1 -1
  142. package/lib/structure/core/moleculeCoordinates.d.ts +31 -0
  143. package/lib/structure/core/moleculeCoordinates.d.ts.map +1 -0
  144. package/lib/structure/core/moleculeCoordinates.js +80 -0
  145. package/lib/structure/core/moleculeCoordinates.js.map +1 -0
  146. package/lib/structure/core/molfileExport.d.ts +42 -0
  147. package/lib/structure/core/molfileExport.d.ts.map +1 -0
  148. package/lib/structure/core/molfileExport.js +47 -0
  149. package/lib/structure/core/molfileExport.js.map +1 -0
  150. package/lib/structure/core/oclResources.d.ts +12 -0
  151. package/lib/structure/core/oclResources.d.ts.map +1 -0
  152. package/lib/structure/core/oclResources.js +35 -0
  153. package/lib/structure/core/oclResources.js.map +1 -0
  154. package/lib/translate/core/catalog.d.ts +61 -0
  155. package/lib/translate/core/catalog.d.ts.map +1 -0
  156. package/lib/translate/core/catalog.js +49 -0
  157. package/lib/translate/core/catalog.js.map +1 -0
  158. package/lib/translate/core/checkTranslation.d.ts +32 -0
  159. package/lib/translate/core/checkTranslation.d.ts.map +1 -0
  160. package/lib/translate/core/checkTranslation.js +98 -0
  161. package/lib/translate/core/checkTranslation.js.map +1 -0
  162. package/lib/translate/core/contribution.d.ts +88 -0
  163. package/lib/translate/core/contribution.d.ts.map +1 -0
  164. package/lib/translate/core/contribution.js +14 -0
  165. package/lib/translate/core/contribution.js.map +1 -0
  166. package/lib/translate/core/index.d.ts +19 -0
  167. package/lib/translate/core/index.d.ts.map +1 -0
  168. package/lib/translate/core/index.js +15 -0
  169. package/lib/translate/core/index.js.map +1 -0
  170. package/lib/translate/core/marker.d.ts +45 -0
  171. package/lib/translate/core/marker.d.ts.map +1 -0
  172. package/lib/translate/core/marker.js +79 -0
  173. package/lib/translate/core/marker.js.map +1 -0
  174. package/lib/translate/core/mergeMessages.d.ts +35 -0
  175. package/lib/translate/core/mergeMessages.d.ts.map +1 -0
  176. package/lib/translate/core/mergeMessages.js +69 -0
  177. package/lib/translate/core/mergeMessages.js.map +1 -0
  178. package/lib/translate/core/session.d.ts +102 -0
  179. package/lib/translate/core/session.d.ts.map +1 -0
  180. package/lib/translate/core/session.js +162 -0
  181. package/lib/translate/core/session.js.map +1 -0
  182. package/lib/translate/core/start.d.ts +103 -0
  183. package/lib/translate/core/start.d.ts.map +1 -0
  184. package/lib/translate/core/start.js +92 -0
  185. package/lib/translate/core/start.js.map +1 -0
  186. package/lib/translate/core/suggestions.d.ts +77 -0
  187. package/lib/translate/core/suggestions.d.ts.map +1 -0
  188. package/lib/translate/core/suggestions.js +143 -0
  189. package/lib/translate/core/suggestions.js.map +1 -0
  190. package/lib/translate/core/tables.d.ts +100 -0
  191. package/lib/translate/core/tables.d.ts.map +1 -0
  192. package/lib/translate/core/tables.js +51 -0
  193. package/lib/translate/core/tables.js.map +1 -0
  194. package/lib/translate.d.ts +2 -0
  195. package/lib/translate.d.ts.map +1 -0
  196. package/lib/translate.js +6 -0
  197. package/lib/translate.js.map +1 -0
  198. package/lib/ui.d.ts +1 -0
  199. package/lib/ui.d.ts.map +1 -1
  200. package/lib/ui.js +1 -0
  201. package/lib/ui.js.map +1 -1
  202. package/lib/xtb/core/xtbRelaxer.d.ts +61 -0
  203. package/lib/xtb/core/xtbRelaxer.d.ts.map +1 -0
  204. package/lib/xtb/core/xtbRelaxer.js +108 -0
  205. package/lib/xtb/core/xtbRelaxer.js.map +1 -0
  206. package/lib/xtb.d.ts +11 -0
  207. package/lib/xtb.d.ts.map +1 -0
  208. package/lib/xtb.js +10 -0
  209. package/lib/xtb.js.map +1 -0
  210. package/package.json +18 -11
  211. package/src/chrome/ui/HeaderToggle.tsx +100 -0
  212. package/src/chrome/ui/index.ts +2 -0
  213. package/src/citation/core/gfn2Paper.ts +32 -0
  214. package/src/citation/core/index.ts +1 -0
  215. package/src/clipboard/ui/ClickToCopy.tsx +8 -7
  216. package/src/conformers.ts +87 -0
  217. package/src/core.ts +1 -0
  218. package/src/credits/core/credits.ts +16 -0
  219. package/src/ecosystem/core/index.ts +1 -0
  220. package/src/ecosystem/core/sites.ts +24 -4
  221. package/src/ecosystem/ui/EcosystemLinks.tsx +3 -1
  222. package/src/ecosystem/ui/SiteTile.tsx +3 -1
  223. package/src/ecosystem/ui/glyphs.tsx +16 -22
  224. package/src/format/core/index.ts +1 -1
  225. package/src/format/core/words.ts +19 -0
  226. package/src/language/core/index.ts +7 -0
  227. package/src/language/core/languageName.ts +16 -0
  228. package/src/language/core/languageParam.ts +70 -0
  229. package/src/language/ui/SiteLanguage.tsx +26 -0
  230. package/src/language/ui/index.ts +3 -0
  231. package/src/language/ui/siteLanguageContext.ts +20 -0
  232. package/src/orbital/core/atomicOrbitals.ts +17 -1
  233. package/src/orbital/core/hydrogenic.ts +2 -1
  234. package/src/orbital/core/index.ts +1 -0
  235. package/src/orbital/core/slaterEnergy.ts +83 -0
  236. package/src/shared/ui/MenuButton.tsx +4 -3
  237. package/src/structure/core/conformerMinimise.ts +99 -0
  238. package/src/structure/core/conformerMinimum.ts +125 -0
  239. package/src/structure/core/conformerOptions.ts +125 -0
  240. package/src/structure/core/conformerRefine.ts +234 -0
  241. package/src/structure/core/conformerRefineRank.ts +89 -0
  242. package/src/structure/core/conformerSession.ts +123 -0
  243. package/src/structure/core/conformerShape.ts +181 -0
  244. package/src/structure/core/conformers.ts +282 -0
  245. package/src/structure/core/geometryRelaxer.ts +71 -0
  246. package/src/structure/core/index.ts +13 -0
  247. package/src/structure/core/moleculeCoordinates.ts +93 -0
  248. package/src/structure/core/molfileExport.ts +62 -0
  249. package/src/structure/core/oclResources.ts +41 -0
  250. package/src/translate/core/catalog.ts +83 -0
  251. package/src/translate/core/checkTranslation.ts +128 -0
  252. package/src/translate/core/contribution.ts +99 -0
  253. package/src/translate/core/index.ts +72 -0
  254. package/src/translate/core/marker.ts +85 -0
  255. package/src/translate/core/mergeMessages.ts +74 -0
  256. package/src/translate/core/session.ts +250 -0
  257. package/src/translate/core/start.ts +183 -0
  258. package/src/translate/core/suggestions.ts +211 -0
  259. package/src/translate/core/tables.ts +120 -0
  260. package/src/translate.ts +5 -0
  261. package/src/ui.ts +1 -0
  262. package/src/xtb/core/xtbRelaxer.ts +160 -0
  263. package/src/xtb.ts +16 -0
  264. package/styles/chrome.css +61 -30
@@ -0,0 +1,66 @@
1
+ /**
2
+ * A geometry a relaxer is handed: element symbols plus flat Cartesian
3
+ * coordinates in ångström, `x,y,z` per atom.
4
+ */
5
+ export interface RelaxableGeometry {
6
+ /** Element symbol per atom, explicit hydrogens included. */
7
+ elements: string[];
8
+ /** Flat `x,y,z` per atom in ångström, length `3 · elements.length`. */
9
+ coordinates: Float64Array;
10
+ }
11
+ /** What a relaxer reports for one structure. */
12
+ export interface RelaxedGeometry {
13
+ /**
14
+ * The relaxed coordinates, in the input's atom order. Translated freely;
15
+ * never rotated, which is what lets {@link RelaxedGeometry} be compared with
16
+ * the geometry it came from by removing both centroids.
17
+ */
18
+ coordinates: Float64Array;
19
+ /**
20
+ * Total energy at `coordinates`, **in kcal/mol**, so it can be read against a
21
+ * force-field energy without a second unit in the UI.
22
+ */
23
+ energy: number;
24
+ /**
25
+ * The dispersion term of `energy`, kcal/mol, or `null` from a method that has
26
+ * none. It is the part a force field of the MMFF94 era does not model at all,
27
+ * and a large part of why conformers re-rank.
28
+ * @default null
29
+ */
30
+ dispersionEnergy: number | null;
31
+ /** Optimizer cycles spent. `0` when there was nothing to relax. */
32
+ cycles: number;
33
+ /** Whether the optimizer met its convergence criteria. */
34
+ converged: boolean;
35
+ /** Plain sentences about anything the caller should know. */
36
+ warnings: string[];
37
+ }
38
+ /** How a relaxation run is watched and cancelled. */
39
+ export interface RelaxerOptions {
40
+ /**
41
+ * Called as each structure finishes, so a caller can show progress over a
42
+ * batch that runs for seconds.
43
+ * @default undefined
44
+ */
45
+ onSettled?: (done: number, total: number) => void;
46
+ /**
47
+ * Gives the run up. A relaxer is not obliged to be able to interrupt a
48
+ * structure already in flight.
49
+ * @default undefined
50
+ */
51
+ signal?: AbortSignal;
52
+ }
53
+ /**
54
+ * Something that relaxes geometries with a real electronic structure behind it,
55
+ * and reports the energy **at the geometry it returns**.
56
+ *
57
+ * This is the seam between a site and the semi-empirical engine: nothing in
58
+ * `react-cheminfo/core` imports one, so a site that never refines a geometry
59
+ * downloads no WebAssembly. `xtbRelaxer` from `react-cheminfo/xtb` is the
60
+ * implementation, GFN2-xTB through `xtb-wasm`.
61
+ *
62
+ * An implementation must return one result per request, in request order, and
63
+ * must keep each structure's atom order.
64
+ */
65
+ export type GeometryRelaxer = (geometries: readonly RelaxableGeometry[], options?: RelaxerOptions) => Promise<RelaxedGeometry[]>;
66
+ //# sourceMappingURL=geometryRelaxer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometryRelaxer.d.ts","sourceRoot":"","sources":["../../../src/structure/core/geometryRelaxer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,uEAAuE;IACvE,WAAW,EAAE,YAAY,CAAC;CAC3B;AAED,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,WAAW,EAAE,YAAY,CAAC;IAC1B;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,SAAS,EAAE,OAAO,CAAC;IACnB,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,qDAAqD;AACrD,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD;;;;OAIG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,UAAU,EAAE,SAAS,iBAAiB,EAAE,EACxC,OAAO,CAAC,EAAE,cAAc,KACrB,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=geometryRelaxer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometryRelaxer.js","sourceRoot":"","sources":["../../../src/structure/core/geometryRelaxer.ts"],"names":[],"mappings":""}
@@ -11,8 +11,12 @@ export type { IdCodeValue } from './editorValue.ts';
11
11
  export { isEmptyIdCode, splitEditorValue, splitIdCode } from './editorValue.ts';
12
12
  export type { FragmentQuery } from './fragmentQuery.ts';
13
13
  export { fragmentQuery, sameFragmentQuery } from './fragmentQuery.ts';
14
+ export type { GeometryRelaxer, RelaxableGeometry, RelaxedGeometry, RelaxerOptions, } from './geometryRelaxer.ts';
15
+ export { centredRmsd, readRelaxableGeometry, writeRelaxedCoordinates, } from './moleculeCoordinates.ts';
14
16
  export type { MolfileClassification, MolfileVersion } from './molfile.ts';
15
17
  export { classifyMolfile, looksLikeMolfile, molfileAtomCount, } from './molfile.ts';
18
+ export type { MolfileExport } from './molfileExport.ts';
19
+ export { readMolfileExport, toMolfileExport } from './molfileExport.ts';
16
20
  export type { ReadStructureResult, StructureKind } from './readStructure.ts';
17
21
  export { looksLikeSmarts, readStructure } from './readStructure.ts';
18
22
  export type { StructureError } from './structureError.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/structure/core/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACnE,YAAY,EACV,aAAa,EACb,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,GACf,MAAM,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AAiB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACxE,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACpE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EACV,eAAe,EACf,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
@@ -4,7 +4,9 @@ export { EDITOR_TOOLBAR_BUTTONS, isEditorToolbarButtonAvailable, } from "./edito
4
4
  export { EDITOR_TOOLBAR_COLUMNS, EDITOR_TOOLBAR_ROWS, editorToolbarButtonAt, editorToolbarButtonBox, } from "./editorToolbarGeometry.js";
5
5
  export { isEmptyIdCode, splitEditorValue, splitIdCode } from "./editorValue.js";
6
6
  export { fragmentQuery, sameFragmentQuery } from "./fragmentQuery.js";
7
+ export { centredRmsd, readRelaxableGeometry, writeRelaxedCoordinates, } from "./moleculeCoordinates.js";
7
8
  export { classifyMolfile, looksLikeMolfile, molfileAtomCount, } from "./molfile.js";
9
+ export { readMolfileExport, toMolfileExport } from "./molfileExport.js";
8
10
  export { looksLikeSmarts, readStructure } from "./readStructure.js";
9
11
  export { structureError } from "./structureError.js";
10
12
  export { structureSource } from "./structureSource.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/structure/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AASnE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,GACf,MAAM,kBAAkB,CAAC;AAK1B,OAAO,EACL,sBAAsB,EACtB,8BAA8B,GAC/B,MAAM,oBAAoB,CAAC;AA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C;AAExE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { Molecule } from 'openchemlib';
2
+ import type { RelaxableGeometry } from './geometryRelaxer.ts';
3
+ /**
4
+ * Read the elements and 3D coordinates of a molecule into the flat form an
5
+ * engine takes.
6
+ * @param molecule - A molecule carrying 3D coordinates. Not modified.
7
+ * @returns Its geometry in ångström, one entry per atom of `getAllAtoms()`.
8
+ */
9
+ export declare function readRelaxableGeometry(molecule: Molecule): RelaxableGeometry;
10
+ /**
11
+ * Write flat coordinates back onto a molecule, atom for atom.
12
+ * @param molecule - The molecule to move. Mutated.
13
+ * @param coordinates - Flat `x,y,z` per atom in ångström.
14
+ * @throws {Error} When there is not one position per atom.
15
+ */
16
+ export declare function writeRelaxedCoordinates(molecule: Molecule, coordinates: Float64Array): void;
17
+ /**
18
+ * Root-mean-square displacement between two geometries of the same atoms, each
19
+ * taken about its own centroid, in ångström.
20
+ *
21
+ * Removing the centroids is what makes the number mean "how far the atoms
22
+ * moved" rather than "how far the molecule was translated": a relaxer is free
23
+ * to recentre a molecule, and the `GeometryRelaxer` contract forbids it to
24
+ * rotate one.
25
+ * @param before - Flat coordinates before.
26
+ * @param after - Flat coordinates after.
27
+ * @returns The RMSD in ångström, `0` for an empty geometry.
28
+ * @throws {Error} When the two do not hold the same number of atoms.
29
+ */
30
+ export declare function centredRmsd(before: Float64Array, after: Float64Array): number;
31
+ //# sourceMappingURL=moleculeCoordinates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moleculeCoordinates.d.ts","sourceRoot":"","sources":["../../../src/structure/core/moleculeCoordinates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,iBAAiB,CAW3E;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,YAAY,GACxB,IAAI,CAYN;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,CAqB7E"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Read the elements and 3D coordinates of a molecule into the flat form an
3
+ * engine takes.
4
+ * @param molecule - A molecule carrying 3D coordinates. Not modified.
5
+ * @returns Its geometry in ångström, one entry per atom of `getAllAtoms()`.
6
+ */
7
+ export function readRelaxableGeometry(molecule) {
8
+ const atoms = molecule.getAllAtoms();
9
+ const elements = new Array(atoms);
10
+ const coordinates = new Float64Array(atoms * 3);
11
+ for (let atom = 0; atom < atoms; atom++) {
12
+ elements[atom] = molecule.getAtomLabel(atom);
13
+ coordinates[atom * 3] = molecule.getAtomX(atom);
14
+ coordinates[atom * 3 + 1] = molecule.getAtomY(atom);
15
+ coordinates[atom * 3 + 2] = molecule.getAtomZ(atom);
16
+ }
17
+ return { elements, coordinates };
18
+ }
19
+ /**
20
+ * Write flat coordinates back onto a molecule, atom for atom.
21
+ * @param molecule - The molecule to move. Mutated.
22
+ * @param coordinates - Flat `x,y,z` per atom in ångström.
23
+ * @throws {Error} When there is not one position per atom.
24
+ */
25
+ export function writeRelaxedCoordinates(molecule, coordinates) {
26
+ const atoms = molecule.getAllAtoms();
27
+ if (coordinates.length !== atoms * 3) {
28
+ throw new Error(`The relaxed geometry has ${coordinates.length / 3} positions for ${atoms} atoms.`);
29
+ }
30
+ for (let atom = 0; atom < atoms; atom++) {
31
+ molecule.setAtomX(atom, coordinates[atom * 3]);
32
+ molecule.setAtomY(atom, coordinates[atom * 3 + 1]);
33
+ molecule.setAtomZ(atom, coordinates[atom * 3 + 2]);
34
+ }
35
+ }
36
+ /**
37
+ * Root-mean-square displacement between two geometries of the same atoms, each
38
+ * taken about its own centroid, in ångström.
39
+ *
40
+ * Removing the centroids is what makes the number mean "how far the atoms
41
+ * moved" rather than "how far the molecule was translated": a relaxer is free
42
+ * to recentre a molecule, and the `GeometryRelaxer` contract forbids it to
43
+ * rotate one.
44
+ * @param before - Flat coordinates before.
45
+ * @param after - Flat coordinates after.
46
+ * @returns The RMSD in ångström, `0` for an empty geometry.
47
+ * @throws {Error} When the two do not hold the same number of atoms.
48
+ */
49
+ export function centredRmsd(before, after) {
50
+ if (before.length !== after.length) {
51
+ throw new Error(`Cannot compare ${before.length / 3} positions with ${after.length / 3}.`);
52
+ }
53
+ const atoms = before.length / 3;
54
+ if (atoms === 0)
55
+ return 0;
56
+ const centreBefore = centroid(before, atoms);
57
+ const centreAfter = centroid(after, atoms);
58
+ let total = 0;
59
+ for (let atom = 0; atom < atoms; atom++) {
60
+ for (let axis = 0; axis < 3; axis++) {
61
+ const gap = before[atom * 3 + axis] -
62
+ centreBefore[axis] -
63
+ (after[atom * 3 + axis] - centreAfter[axis]);
64
+ total += gap * gap;
65
+ }
66
+ }
67
+ return Math.sqrt(total / atoms);
68
+ }
69
+ function centroid(coordinates, atoms) {
70
+ let x = 0;
71
+ let y = 0;
72
+ let z = 0;
73
+ for (let atom = 0; atom < atoms; atom++) {
74
+ x += coordinates[atom * 3];
75
+ y += coordinates[atom * 3 + 1];
76
+ z += coordinates[atom * 3 + 2];
77
+ }
78
+ return new Float64Array([x / atoms, y / atoms, z / atoms]);
79
+ }
80
+ //# sourceMappingURL=moleculeCoordinates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moleculeCoordinates.js","sourceRoot":"","sources":["../../../src/structure/core/moleculeCoordinates.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAkB;IACtD,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IACD,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,QAAQ,CAAC,WAAyB,EAAE,KAAa;IACxD,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;QACxC,CAAC,IAAI,WAAW,CAAC,IAAI,GAAG,CAAC,CAAW,CAAC;QACrC,CAAC,IAAI,WAAW,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAW,CAAC;QACzC,CAAC,IAAI,WAAW,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAW,CAAC;IAC3C,CAAC;IACD,OAAO,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { Molecule } from 'openchemlib';
2
+ /** A molfile plus the molstar format id that can actually parse it. */
3
+ export interface MolfileExport {
4
+ /** molstar's format id: `mol` reads V2000, `sdf` reads V2000 and V3000. */
5
+ format: 'mol' | 'sdf';
6
+ /** The molfile text, exactly as OpenChemLib wrote it. */
7
+ data: string;
8
+ }
9
+ /**
10
+ * Serialise a molecule for the 3D viewer and for export.
11
+ *
12
+ * V2000 is written whenever it can be: its counts line holds three digits per
13
+ * field, so above 999 atoms OpenChemLib writes `?` where the count belongs and
14
+ * the file becomes unreadable. V3000 is used from that size on.
15
+ *
16
+ * Coordinates are emitted exactly as OpenChemLib writes them — the whole
17
+ * molecule is negated in y and z relative to `getAtomY/Z`, which is a rigid
18
+ * rotation and therefore invisible to the viewer, to the energies and to any
19
+ * other file consumer.
20
+ *
21
+ * Hydrogens are in the file only if they are explicit atoms, so call this on a
22
+ * conformer, which always carries them.
23
+ * @param molecule - Structure with 3D coordinates already set. Not mutated.
24
+ * @returns The molfile and the format id to hand molstar.
25
+ * @throws {Error} When the molfile carries no atoms.
26
+ */
27
+ export declare function toMolfileExport(molecule: Molecule): MolfileExport;
28
+ /**
29
+ * Pick the molstar format id for a molfile of unknown version, and refuse the
30
+ * ones that would render nothing.
31
+ *
32
+ * molstar's `mol` parser does not understand a V3000 CTAB: it returns zero atoms
33
+ * with `isError: false`, so the viewer shows an empty scene and reports no
34
+ * error. The version is read from the text rather than assumed from whichever
35
+ * writer produced it, because the text is the only thing molstar itself looks
36
+ * at.
37
+ * @param data - A molfile, V2000 or V3000.
38
+ * @returns The format id paired with the unchanged text.
39
+ * @throws {Error} When the molfile carries no atoms — the silent failure this guards.
40
+ */
41
+ export declare function readMolfileExport(data: string): MolfileExport;
42
+ //# sourceMappingURL=molfileExport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"molfileExport.d.ts","sourceRoot":"","sources":["../../../src/structure/core/molfileExport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI5C,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,MAAM,EAAE,KAAK,GAAG,KAAK,CAAC;IACtB,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,aAAa,CAMjE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAQ7D"}
@@ -0,0 +1,47 @@
1
+ import { classifyMolfile } from "./molfile.js";
2
+ /**
3
+ * Serialise a molecule for the 3D viewer and for export.
4
+ *
5
+ * V2000 is written whenever it can be: its counts line holds three digits per
6
+ * field, so above 999 atoms OpenChemLib writes `?` where the count belongs and
7
+ * the file becomes unreadable. V3000 is used from that size on.
8
+ *
9
+ * Coordinates are emitted exactly as OpenChemLib writes them — the whole
10
+ * molecule is negated in y and z relative to `getAtomY/Z`, which is a rigid
11
+ * rotation and therefore invisible to the viewer, to the energies and to any
12
+ * other file consumer.
13
+ *
14
+ * Hydrogens are in the file only if they are explicit atoms, so call this on a
15
+ * conformer, which always carries them.
16
+ * @param molecule - Structure with 3D coordinates already set. Not mutated.
17
+ * @returns The molfile and the format id to hand molstar.
18
+ * @throws {Error} When the molfile carries no atoms.
19
+ */
20
+ export function toMolfileExport(molecule) {
21
+ const data = molecule.getAllAtoms() > V2000_MAX_ATOMS
22
+ ? molecule.toMolfileV3()
23
+ : molecule.toMolfile();
24
+ return readMolfileExport(data);
25
+ }
26
+ /**
27
+ * Pick the molstar format id for a molfile of unknown version, and refuse the
28
+ * ones that would render nothing.
29
+ *
30
+ * molstar's `mol` parser does not understand a V3000 CTAB: it returns zero atoms
31
+ * with `isError: false`, so the viewer shows an empty scene and reports no
32
+ * error. The version is read from the text rather than assumed from whichever
33
+ * writer produced it, because the text is the only thing molstar itself looks
34
+ * at.
35
+ * @param data - A molfile, V2000 or V3000.
36
+ * @returns The format id paired with the unchanged text.
37
+ * @throws {Error} When the molfile carries no atoms — the silent failure this guards.
38
+ */
39
+ export function readMolfileExport(data) {
40
+ const { version, atomCount } = classifyMolfile(data);
41
+ if (atomCount === 0) {
42
+ throw new Error('Molfile has an empty atom block: molstar would render an empty scene without reporting an error.');
43
+ }
44
+ return { format: version === 'v3000' ? 'sdf' : 'mol', data };
45
+ }
46
+ const V2000_MAX_ATOMS = 999;
47
+ //# sourceMappingURL=molfileExport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"molfileExport.js","sourceRoot":"","sources":["../../../src/structure/core/molfileExport.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAU/C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAAC,QAAkB;IAChD,MAAM,IAAI,GACR,QAAQ,CAAC,WAAW,EAAE,GAAG,eAAe;QACtC,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE;QACxB,CAAC,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;IAC3B,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACrD,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,kGAAkG,CACnG,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC;AAC/D,CAAC;AAED,MAAM,eAAe,GAAG,GAAG,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Register OpenChemLib's static resources once, without which
3
+ * `ConformerGenerator` and `ForceFieldMMFF94` throw on construction.
4
+ *
5
+ * Repeated calls share the first call's promise; a failed registration is
6
+ * forgotten so a later call can retry.
7
+ * @param url - Where to fetch `resources.json`. Omit under Node.js to read it
8
+ * from the installed package; in a browser or a worker it is required.
9
+ * @returns A promise that settles once the resources are usable.
10
+ */
11
+ export declare function registerResources(url?: string): Promise<void>;
12
+ //# sourceMappingURL=oclResources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oclResources.d.ts","sourceRoot":"","sources":["../../../src/structure/core/oclResources.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7D"}
@@ -0,0 +1,35 @@
1
+ import { Resources } from 'openchemlib';
2
+ /**
3
+ * Register OpenChemLib's static resources once, without which
4
+ * `ConformerGenerator` and `ForceFieldMMFF94` throw on construction.
5
+ *
6
+ * Repeated calls share the first call's promise; a failed registration is
7
+ * forgotten so a later call can retry.
8
+ * @param url - Where to fetch `resources.json`. Omit under Node.js to read it
9
+ * from the installed package; in a browser or a worker it is required.
10
+ * @returns A promise that settles once the resources are usable.
11
+ */
12
+ export function registerResources(url) {
13
+ registration ??= register(url).catch((error) => {
14
+ registration = null;
15
+ throw error;
16
+ });
17
+ return registration;
18
+ }
19
+ let registration = null;
20
+ async function register(url) {
21
+ if (url !== undefined) {
22
+ await Resources.registerFromUrl(url);
23
+ return;
24
+ }
25
+ const runtime = globalThis;
26
+ if (runtime.process?.versions?.node === undefined) {
27
+ throw new Error('registerResources needs a url outside Node.js: a browser page or worker cannot read resources.json from node_modules');
28
+ }
29
+ const { createRequire } = await import('node:module');
30
+ const require = createRequire(import.meta.url);
31
+ Resources.registerFromNodejs(require
32
+ .resolve('openchemlib')
33
+ .replace(/openchemlib\.js$/, 'resources.json'));
34
+ }
35
+ //# sourceMappingURL=oclResources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oclResources.js","sourceRoot":"","sources":["../../../src/structure/core/oclResources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAY;IAC5C,YAAY,KAAK,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACtD,YAAY,GAAG,IAAI,CAAC;QACpB,MAAM,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,IAAI,YAAY,GAAyB,IAAI,CAAC;AAE9C,KAAK,UAAU,QAAQ,CAAC,GAAY;IAClC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,MAAM,SAAS,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,UAA4D,CAAC;IAC7E,IAAI,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,KAAK,SAAS,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CACb,sHAAsH,CACvH,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,SAAS,CAAC,kBAAkB,CAC1B,OAAO;SACJ,OAAO,CAAC,aAAa,CAAC;SACtB,OAAO,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CACjD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The shape of the messages a site or a library owns, and where they are kept.
3
+ *
4
+ * A catalog is one directory of a repository holding `en.json`, the source of
5
+ * truth, and one flat file per locale beside it. The site registers each of
6
+ * its catalogs with the repository and the directory, so a translation made
7
+ * anywhere on the page can be sent back to the file it belongs to.
8
+ */
9
+ /** Messages by key; every value is an ICU MessageFormat string. */
10
+ export type Messages = Record<string, string>;
11
+ /** The locale every catalog is written in first. */
12
+ export declare const SOURCE_LOCALE = "en";
13
+ /** One catalog a page renders messages from. */
14
+ export interface CatalogSource {
15
+ /**
16
+ * The name the page knows the catalog by, unique on the page, e.g.
17
+ * `translate.cheminfo.org` or `react-cheminfo/share`.
18
+ */
19
+ id: string;
20
+ /** The GitHub repository the files live in, written `owner/repo`. */
21
+ repository: string;
22
+ /**
23
+ * The directory holding `en.json` and the locale files, relative to the
24
+ * repository root, e.g. `frontend/src/locales`.
25
+ */
26
+ directory: string;
27
+ /** The English messages. */
28
+ messages: Messages;
29
+ }
30
+ /** Which message of which catalog. */
31
+ export interface MessageRef {
32
+ /** The catalog, by the id the page registered it under. */
33
+ catalogId: string;
34
+ /** The key of the message in that catalog. */
35
+ key: string;
36
+ }
37
+ /**
38
+ * The message a catalog holds under a key, never one inherited from
39
+ * `Object.prototype`: a key like `constructor` is only a message when the
40
+ * catalog defines it.
41
+ * @param messages - The catalog's messages.
42
+ * @param key - The key asked for.
43
+ * @returns The message, or `undefined` when the catalog has none.
44
+ */
45
+ export declare function ownMessage(messages: Messages, key: string): string | undefined;
46
+ /**
47
+ * Whether a path can name a catalog directory: relative, without `.` or `..`
48
+ * segments, and ending in a directory called `locales`. The server only ever
49
+ * writes inside such a directory.
50
+ * @param value - The candidate path, e.g. `frontend/src/locales`.
51
+ * @returns True when the path is acceptable.
52
+ */
53
+ export declare function isCatalogDirectory(value: string): boolean;
54
+ /**
55
+ * The file a catalog keeps one locale's messages in.
56
+ * @param directory - The catalog directory.
57
+ * @param locale - The locale.
58
+ * @returns The path, relative to the repository root.
59
+ */
60
+ export declare function catalogFile(directory: string, locale: string): string;
61
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../src/translate/core/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,mEAAmE;AACnE,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE9C,oDAAoD;AACpD,eAAO,MAAM,aAAa,OAAO,CAAC;AAElC,gDAAgD;AAChD,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IACX,qEAAqE;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,sCAAsC;AACtC,MAAM,WAAW,UAAU;IACzB,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;CACb;AAID;;;;;;;GAOG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,SAAS,CAEpB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOzD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAErE"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The shape of the messages a site or a library owns, and where they are kept.
3
+ *
4
+ * A catalog is one directory of a repository holding `en.json`, the source of
5
+ * truth, and one flat file per locale beside it. The site registers each of
6
+ * its catalogs with the repository and the directory, so a translation made
7
+ * anywhere on the page can be sent back to the file it belongs to.
8
+ */
9
+ /** The locale every catalog is written in first. */
10
+ export const SOURCE_LOCALE = 'en';
11
+ const DIRECTORY_SEGMENT = /^[\w-][\w.-]*$/;
12
+ /**
13
+ * The message a catalog holds under a key, never one inherited from
14
+ * `Object.prototype`: a key like `constructor` is only a message when the
15
+ * catalog defines it.
16
+ * @param messages - The catalog's messages.
17
+ * @param key - The key asked for.
18
+ * @returns The message, or `undefined` when the catalog has none.
19
+ */
20
+ export function ownMessage(messages, key) {
21
+ return Object.hasOwn(messages, key) ? messages[key] : undefined;
22
+ }
23
+ /**
24
+ * Whether a path can name a catalog directory: relative, without `.` or `..`
25
+ * segments, and ending in a directory called `locales`. The server only ever
26
+ * writes inside such a directory.
27
+ * @param value - The candidate path, e.g. `frontend/src/locales`.
28
+ * @returns True when the path is acceptable.
29
+ */
30
+ export function isCatalogDirectory(value) {
31
+ const segments = value.split('/');
32
+ if (segments.at(-1) !== 'locales')
33
+ return false;
34
+ for (const segment of segments) {
35
+ if (!DIRECTORY_SEGMENT.test(segment))
36
+ return false;
37
+ }
38
+ return true;
39
+ }
40
+ /**
41
+ * The file a catalog keeps one locale's messages in.
42
+ * @param directory - The catalog directory.
43
+ * @param locale - The locale.
44
+ * @returns The path, relative to the repository root.
45
+ */
46
+ export function catalogFile(directory, locale) {
47
+ return `${directory}/${locale}.json`;
48
+ }
49
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../src/translate/core/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,oDAAoD;AACpD,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;AA4BlC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CACxB,QAAkB,EAClB,GAAW;IAEX,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAChD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;IACrD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,MAAc;IAC3D,OAAO,GAAG,SAAS,IAAI,MAAM,OAAO,CAAC;AACvC,CAAC"}
@@ -0,0 +1,32 @@
1
+ /** What can be wrong with one translated message. */
2
+ export type MessageProblemKind = 'empty' | 'syntax' | 'source-syntax' | 'missing-argument' | 'unknown-argument';
3
+ /** One thing wrong with a translated message, worded for the translator. */
4
+ export interface MessageProblem {
5
+ /** What kind of problem it is. */
6
+ kind: MessageProblemKind;
7
+ /** The sentence the translator reads. */
8
+ message: string;
9
+ /**
10
+ * The placeholder or tag the problem is about, written as it appears in a
11
+ * message: `{count}` or `<link>`.
12
+ * @default undefined
13
+ */
14
+ argument?: string;
15
+ }
16
+ /**
17
+ * Check a translation against the English message it translates: it must be
18
+ * a valid ICU message and use exactly the placeholders and tags of the source.
19
+ * @param source - The English message.
20
+ * @param translation - The translated message.
21
+ * @returns Every problem found; empty when the translation can be used.
22
+ */
23
+ export declare function checkTranslation(source: string, translation: string): MessageProblem[];
24
+ /**
25
+ * The placeholders and tags a message uses, each written as it appears in the
26
+ * message: `{count}` for an argument, `<link>` for a tag.
27
+ * @param message - An ICU message.
28
+ * @returns The set of placeholders and tags.
29
+ * @throws {SyntaxError} When the message does not parse.
30
+ */
31
+ export declare function messageArguments(message: string): Set<string>;
32
+ //# sourceMappingURL=checkTranslation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkTranslation.d.ts","sourceRoot":"","sources":["../../../src/translate/core/checkTranslation.ts"],"names":[],"mappings":"AAGA,qDAAqD;AACrD,MAAM,MAAM,kBAAkB,GAC1B,OAAO,GACP,QAAQ,GACR,eAAe,GACf,kBAAkB,GAClB,kBAAkB,CAAC;AAEvB,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,IAAI,EAAE,kBAAkB,CAAC;IACzB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAClB,cAAc,EAAE,CA4ClB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAI7D"}