react-cheminfo 0.76.0 → 0.77.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 (316) hide show
  1. package/README.md +141 -31
  2. package/lib/card/core/cardAddress.d.ts +19 -2
  3. package/lib/card/core/cardAddress.d.ts.map +1 -1
  4. package/lib/card/core/cardAddress.js +35 -2
  5. package/lib/card/core/cardAddress.js.map +1 -1
  6. package/lib/card/core/cardPageUrl.d.ts +7 -1
  7. package/lib/card/core/cardPageUrl.d.ts.map +1 -1
  8. package/lib/card/core/cardPageUrl.js +4 -2
  9. package/lib/card/core/cardPageUrl.js.map +1 -1
  10. package/lib/card/core/index.d.ts +1 -1
  11. package/lib/card/core/index.d.ts.map +1 -1
  12. package/lib/card/core/index.js +1 -1
  13. package/lib/card/core/index.js.map +1 -1
  14. package/lib/credits/core/credits.d.ts +30 -0
  15. package/lib/credits/core/credits.d.ts.map +1 -1
  16. package/lib/credits/core/credits.js +35 -0
  17. package/lib/credits/core/credits.js.map +1 -1
  18. package/lib/download/core/downloadFigure.d.ts +12 -1
  19. package/lib/download/core/downloadFigure.d.ts.map +1 -1
  20. package/lib/download/core/downloadFigure.js +21 -0
  21. package/lib/download/core/downloadFigure.js.map +1 -1
  22. package/lib/download/core/figureDpi.d.ts +59 -0
  23. package/lib/download/core/figureDpi.d.ts.map +1 -0
  24. package/lib/download/core/figureDpi.js +75 -0
  25. package/lib/download/core/figureDpi.js.map +1 -0
  26. package/lib/download/core/figurePng.d.ts +4 -1
  27. package/lib/download/core/figurePng.d.ts.map +1 -1
  28. package/lib/download/core/figurePng.js +11 -2
  29. package/lib/download/core/figurePng.js.map +1 -1
  30. package/lib/download/core/index.d.ts +4 -1
  31. package/lib/download/core/index.d.ts.map +1 -1
  32. package/lib/download/core/index.js +3 -1
  33. package/lib/download/core/index.js.map +1 -1
  34. package/lib/download/core/pngDpi.d.ts +22 -0
  35. package/lib/download/core/pngDpi.d.ts.map +1 -0
  36. package/lib/download/core/pngDpi.js +79 -0
  37. package/lib/download/core/pngDpi.js.map +1 -0
  38. package/lib/download/ui/FigureDownloadPanel.d.ts +13 -0
  39. package/lib/download/ui/FigureDownloadPanel.d.ts.map +1 -1
  40. package/lib/download/ui/FigureDownloadPanel.js +18 -34
  41. package/lib/download/ui/FigureDownloadPanel.js.map +1 -1
  42. package/lib/download/ui/figureDownloadHint.d.ts +5 -0
  43. package/lib/download/ui/figureDownloadHint.d.ts.map +1 -1
  44. package/lib/download/ui/figureDownloadHint.js +8 -0
  45. package/lib/download/ui/figureDownloadHint.js.map +1 -1
  46. package/lib/download/ui/figureDownloadOptions.d.ts +84 -0
  47. package/lib/download/ui/figureDownloadOptions.d.ts.map +1 -0
  48. package/lib/download/ui/figureDownloadOptions.js +2 -0
  49. package/lib/download/ui/figureDownloadOptions.js.map +1 -0
  50. package/lib/download/ui/resolutionChoices.d.ts +27 -0
  51. package/lib/download/ui/resolutionChoices.d.ts.map +1 -0
  52. package/lib/download/ui/resolutionChoices.js +48 -0
  53. package/lib/download/ui/resolutionChoices.js.map +1 -0
  54. package/lib/download/ui/useFigureActions.d.ts +4 -1
  55. package/lib/download/ui/useFigureActions.d.ts.map +1 -1
  56. package/lib/download/ui/useFigureActions.js +17 -8
  57. package/lib/download/ui/useFigureActions.js.map +1 -1
  58. package/lib/download/ui/useFigureDownload.d.ts +2 -55
  59. package/lib/download/ui/useFigureDownload.d.ts.map +1 -1
  60. package/lib/download/ui/useFigureDownload.js +45 -13
  61. package/lib/download/ui/useFigureDownload.js.map +1 -1
  62. package/lib/ecosystem/core/sites.d.ts.map +1 -1
  63. package/lib/ecosystem/core/sites.js +14 -0
  64. package/lib/ecosystem/core/sites.js.map +1 -1
  65. package/lib/ecosystem/core/types.d.ts +1 -1
  66. package/lib/ecosystem/core/types.d.ts.map +1 -1
  67. package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
  68. package/lib/ecosystem/ui/glyphs.js +3 -0
  69. package/lib/ecosystem/ui/glyphs.js.map +1 -1
  70. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  71. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  72. package/lib/locales/de.json +30 -1
  73. package/lib/locales/en.json +30 -1
  74. package/lib/locales/es.json +30 -1
  75. package/lib/locales/fr.json +30 -1
  76. package/lib/locales/it.json +30 -1
  77. package/lib/molecule3d/ui/Molecule3DStage.d.ts +4 -33
  78. package/lib/molecule3d/ui/Molecule3DStage.d.ts.map +1 -1
  79. package/lib/molecule3d/ui/Molecule3DStage.js +3 -37
  80. package/lib/molecule3d/ui/Molecule3DStage.js.map +1 -1
  81. package/lib/osiris/core/barGeometry.d.ts +42 -0
  82. package/lib/osiris/core/barGeometry.d.ts.map +1 -0
  83. package/lib/osiris/core/barGeometry.js +46 -0
  84. package/lib/osiris/core/barGeometry.js.map +1 -0
  85. package/lib/osiris/core/computeProperties.d.ts +42 -0
  86. package/lib/osiris/core/computeProperties.d.ts.map +1 -0
  87. package/lib/osiris/core/computeProperties.js +115 -0
  88. package/lib/osiris/core/computeProperties.js.map +1 -0
  89. package/lib/osiris/core/constants.d.ts +70 -0
  90. package/lib/osiris/core/constants.d.ts.map +1 -0
  91. package/lib/osiris/core/constants.js +99 -0
  92. package/lib/osiris/core/constants.js.map +1 -0
  93. package/lib/osiris/core/fitness.d.ts +32 -0
  94. package/lib/osiris/core/fitness.d.ts.map +1 -0
  95. package/lib/osiris/core/fitness.js +48 -0
  96. package/lib/osiris/core/fitness.js.map +1 -0
  97. package/lib/osiris/core/index.d.ts +29 -0
  98. package/lib/osiris/core/index.d.ts.map +1 -0
  99. package/lib/osiris/core/index.js +19 -0
  100. package/lib/osiris/core/index.js.map +1 -0
  101. package/lib/osiris/core/poolSize.d.ts +17 -0
  102. package/lib/osiris/core/poolSize.d.ts.map +1 -0
  103. package/lib/osiris/core/poolSize.js +22 -0
  104. package/lib/osiris/core/poolSize.js.map +1 -0
  105. package/lib/osiris/core/poolTypes.d.ts +140 -0
  106. package/lib/osiris/core/poolTypes.d.ts.map +1 -0
  107. package/lib/osiris/core/poolTypes.js +12 -0
  108. package/lib/osiris/core/poolTypes.js.map +1 -0
  109. package/lib/osiris/core/predictIdCode.d.ts +39 -0
  110. package/lib/osiris/core/predictIdCode.d.ts.map +1 -0
  111. package/lib/osiris/core/predictIdCode.js +54 -0
  112. package/lib/osiris/core/predictIdCode.js.map +1 -0
  113. package/lib/osiris/core/predictProtocol.d.ts +67 -0
  114. package/lib/osiris/core/predictProtocol.d.ts.map +1 -0
  115. package/lib/osiris/core/predictProtocol.js +29 -0
  116. package/lib/osiris/core/predictProtocol.js.map +1 -0
  117. package/lib/osiris/core/predictionPool.d.ts +23 -0
  118. package/lib/osiris/core/predictionPool.d.ts.map +1 -0
  119. package/lib/osiris/core/predictionPool.js +186 -0
  120. package/lib/osiris/core/predictionPool.js.map +1 -0
  121. package/lib/osiris/core/predictionQueue.d.ts +46 -0
  122. package/lib/osiris/core/predictionQueue.d.ts.map +1 -0
  123. package/lib/osiris/core/predictionQueue.js +57 -0
  124. package/lib/osiris/core/predictionQueue.js.map +1 -0
  125. package/lib/osiris/core/predictors.d.ts +62 -0
  126. package/lib/osiris/core/predictors.d.ts.map +1 -0
  127. package/lib/osiris/core/predictors.js +100 -0
  128. package/lib/osiris/core/predictors.js.map +1 -0
  129. package/lib/osiris/core/propertyKeys.d.ts +32 -0
  130. package/lib/osiris/core/propertyKeys.d.ts.map +1 -0
  131. package/lib/osiris/core/propertyKeys.js +44 -0
  132. package/lib/osiris/core/propertyKeys.js.map +1 -0
  133. package/lib/osiris/core/riskAppearance.d.ts +60 -0
  134. package/lib/osiris/core/riskAppearance.d.ts.map +1 -0
  135. package/lib/osiris/core/riskAppearance.js +59 -0
  136. package/lib/osiris/core/riskAppearance.js.map +1 -0
  137. package/lib/osiris/core/riskDetail.d.ts +22 -0
  138. package/lib/osiris/core/riskDetail.d.ts.map +1 -0
  139. package/lib/osiris/core/riskDetail.js +86 -0
  140. package/lib/osiris/core/riskDetail.js.map +1 -0
  141. package/lib/osiris/core/riskDetailRequest.d.ts +31 -0
  142. package/lib/osiris/core/riskDetailRequest.d.ts.map +1 -0
  143. package/lib/osiris/core/riskDetailRequest.js +49 -0
  144. package/lib/osiris/core/riskDetailRequest.js.map +1 -0
  145. package/lib/osiris/core/riskFindings.d.ts +26 -0
  146. package/lib/osiris/core/riskFindings.d.ts.map +1 -0
  147. package/lib/osiris/core/riskFindings.js +79 -0
  148. package/lib/osiris/core/riskFindings.js.map +1 -0
  149. package/lib/osiris/core/runPredictionJob.d.ts +20 -0
  150. package/lib/osiris/core/runPredictionJob.d.ts.map +1 -0
  151. package/lib/osiris/core/runPredictionJob.js +43 -0
  152. package/lib/osiris/core/runPredictionJob.js.map +1 -0
  153. package/lib/osiris/core/scales.d.ts +70 -0
  154. package/lib/osiris/core/scales.d.ts.map +1 -0
  155. package/lib/osiris/core/scales.js +185 -0
  156. package/lib/osiris/core/scales.js.map +1 -0
  157. package/lib/osiris/core/types.d.ts +91 -0
  158. package/lib/osiris/core/types.d.ts.map +1 -0
  159. package/lib/osiris/core/types.js +19 -0
  160. package/lib/osiris/core/types.js.map +1 -0
  161. package/lib/osiris/core/valuation.d.ts +28 -0
  162. package/lib/osiris/core/valuation.d.ts.map +1 -0
  163. package/lib/osiris/core/valuation.js +39 -0
  164. package/lib/osiris/core/valuation.js.map +1 -0
  165. package/lib/osiris/ui/PropertyBar.d.ts +27 -0
  166. package/lib/osiris/ui/PropertyBar.d.ts.map +1 -0
  167. package/lib/osiris/ui/PropertyBar.js +27 -0
  168. package/lib/osiris/ui/PropertyBar.js.map +1 -0
  169. package/lib/osiris/ui/PropertyPanel.d.ts +91 -0
  170. package/lib/osiris/ui/PropertyPanel.d.ts.map +1 -0
  171. package/lib/osiris/ui/PropertyPanel.js +77 -0
  172. package/lib/osiris/ui/PropertyPanel.js.map +1 -0
  173. package/lib/osiris/ui/PropertyRows.d.ts +40 -0
  174. package/lib/osiris/ui/PropertyRows.d.ts.map +1 -0
  175. package/lib/osiris/ui/PropertyRows.js +23 -0
  176. package/lib/osiris/ui/PropertyRows.js.map +1 -0
  177. package/lib/osiris/ui/RiskFindings.d.ts +43 -0
  178. package/lib/osiris/ui/RiskFindings.d.ts.map +1 -0
  179. package/lib/osiris/ui/RiskFindings.js +51 -0
  180. package/lib/osiris/ui/RiskFindings.js.map +1 -0
  181. package/lib/osiris/ui/RiskPanel.d.ts +46 -0
  182. package/lib/osiris/ui/RiskPanel.d.ts.map +1 -0
  183. package/lib/osiris/ui/RiskPanel.js +32 -0
  184. package/lib/osiris/ui/RiskPanel.js.map +1 -0
  185. package/lib/osiris/ui/RiskSquare.d.ts +51 -0
  186. package/lib/osiris/ui/RiskSquare.d.ts.map +1 -0
  187. package/lib/osiris/ui/RiskSquare.js +23 -0
  188. package/lib/osiris/ui/RiskSquare.js.map +1 -0
  189. package/lib/osiris/ui/index.d.ts +15 -0
  190. package/lib/osiris/ui/index.d.ts.map +1 -0
  191. package/lib/osiris/ui/index.js +8 -0
  192. package/lib/osiris/ui/index.js.map +1 -0
  193. package/lib/osiris/ui/usePredictions.d.ts +81 -0
  194. package/lib/osiris/ui/usePredictions.d.ts.map +1 -0
  195. package/lib/osiris/ui/usePredictions.js +102 -0
  196. package/lib/osiris/ui/usePredictions.js.map +1 -0
  197. package/lib/osiris-ui.d.ts +11 -0
  198. package/lib/osiris-ui.d.ts.map +1 -0
  199. package/lib/osiris-ui.js +11 -0
  200. package/lib/osiris-ui.js.map +1 -0
  201. package/lib/osiris.d.ts +17 -0
  202. package/lib/osiris.d.ts.map +1 -0
  203. package/lib/osiris.js +17 -0
  204. package/lib/osiris.js.map +1 -0
  205. package/lib/panel/ui/FilterInput.d.ts.map +1 -1
  206. package/lib/panel/ui/FilterInput.js +3 -1
  207. package/lib/panel/ui/FilterInput.js.map +1 -1
  208. package/lib/panel/ui/SidePanelItem.d.ts +39 -0
  209. package/lib/panel/ui/SidePanelItem.d.ts.map +1 -0
  210. package/lib/panel/ui/SidePanelItem.js +63 -0
  211. package/lib/panel/ui/SidePanelItem.js.map +1 -0
  212. package/lib/panel/ui/SidePanelStack.d.ts +11 -10
  213. package/lib/panel/ui/SidePanelStack.d.ts.map +1 -1
  214. package/lib/panel/ui/SidePanelStack.js +22 -15
  215. package/lib/panel/ui/SidePanelStack.js.map +1 -1
  216. package/lib/panel/ui/SpectrumColorSwatch.d.ts.map +1 -1
  217. package/lib/panel/ui/SpectrumColorSwatch.js +4 -2
  218. package/lib/panel/ui/SpectrumColorSwatch.js.map +1 -1
  219. package/lib/panel/ui/usePanelFolds.d.ts +35 -0
  220. package/lib/panel/ui/usePanelFolds.d.ts.map +1 -0
  221. package/lib/panel/ui/usePanelFolds.js +73 -0
  222. package/lib/panel/ui/usePanelFolds.js.map +1 -0
  223. package/lib/shared/ui/FullscreenStage.d.ts +43 -0
  224. package/lib/shared/ui/FullscreenStage.d.ts.map +1 -0
  225. package/lib/shared/ui/FullscreenStage.js +38 -0
  226. package/lib/shared/ui/FullscreenStage.js.map +1 -0
  227. package/lib/shared/ui/canFillScreen.d.ts +7 -0
  228. package/lib/shared/ui/canFillScreen.d.ts.map +1 -0
  229. package/lib/shared/ui/canFillScreen.js +9 -0
  230. package/lib/shared/ui/canFillScreen.js.map +1 -0
  231. package/lib/shared/ui/index.d.ts +3 -0
  232. package/lib/shared/ui/index.d.ts.map +1 -1
  233. package/lib/shared/ui/index.js +2 -0
  234. package/lib/shared/ui/index.js.map +1 -1
  235. package/lib/split/ui/splitPanes.d.ts +3 -3
  236. package/lib/split/ui/splitPanes.js +1 -1
  237. package/lib/structure/core/structureNotations.d.ts +8 -1
  238. package/lib/structure/core/structureNotations.d.ts.map +1 -1
  239. package/lib/structure/core/structureNotations.js +14 -8
  240. package/lib/structure/core/structureNotations.js.map +1 -1
  241. package/lib/structure/ui/StructureExportPanel.d.ts +8 -0
  242. package/lib/structure/ui/StructureExportPanel.d.ts.map +1 -1
  243. package/lib/structure/ui/StructureExportPanel.js +9 -4
  244. package/lib/structure/ui/StructureExportPanel.js.map +1 -1
  245. package/lib/structure/ui/index.d.ts +1 -0
  246. package/lib/structure/ui/index.d.ts.map +1 -1
  247. package/lib/structure/ui/index.js.map +1 -1
  248. package/package.json +4 -1
  249. package/src/card/core/cardAddress.ts +39 -3
  250. package/src/card/core/cardPageUrl.ts +10 -3
  251. package/src/card/core/index.ts +7 -1
  252. package/src/credits/core/credits.ts +40 -0
  253. package/src/download/core/downloadFigure.ts +26 -1
  254. package/src/download/core/figureDpi.ts +94 -0
  255. package/src/download/core/figurePng.ts +11 -2
  256. package/src/download/core/index.ts +13 -1
  257. package/src/download/core/pngDpi.ts +84 -0
  258. package/src/download/ui/FigureDownloadPanel.tsx +41 -51
  259. package/src/download/ui/figureDownloadHint.ts +13 -0
  260. package/src/download/ui/figureDownloadOptions.ts +85 -0
  261. package/src/download/ui/resolutionChoices.ts +67 -0
  262. package/src/download/ui/useFigureActions.ts +24 -9
  263. package/src/download/ui/useFigureDownload.tsx +57 -71
  264. package/src/ecosystem/core/sites.ts +14 -0
  265. package/src/ecosystem/core/types.ts +2 -1
  266. package/src/ecosystem/ui/glyphs.tsx +20 -0
  267. package/src/locales/de.json +30 -1
  268. package/src/locales/en.json +30 -1
  269. package/src/locales/es.json +30 -1
  270. package/src/locales/fr.json +30 -1
  271. package/src/locales/it.json +30 -1
  272. package/src/molecule3d/ui/Molecule3DStage.tsx +4 -88
  273. package/src/osiris/core/barGeometry.ts +74 -0
  274. package/src/osiris/core/computeProperties.ts +175 -0
  275. package/src/osiris/core/constants.ts +110 -0
  276. package/src/osiris/core/fitness.ts +59 -0
  277. package/src/osiris/core/index.ts +78 -0
  278. package/src/osiris/core/poolSize.ts +24 -0
  279. package/src/osiris/core/poolTypes.ts +140 -0
  280. package/src/osiris/core/predictIdCode.ts +69 -0
  281. package/src/osiris/core/predictProtocol.ts +78 -0
  282. package/src/osiris/core/predictionPool.ts +237 -0
  283. package/src/osiris/core/predictionQueue.ts +89 -0
  284. package/src/osiris/core/predictors.ts +142 -0
  285. package/src/osiris/core/propertyKeys.ts +54 -0
  286. package/src/osiris/core/riskAppearance.ts +86 -0
  287. package/src/osiris/core/riskDetail.ts +120 -0
  288. package/src/osiris/core/riskDetailRequest.ts +64 -0
  289. package/src/osiris/core/riskFindings.ts +92 -0
  290. package/src/osiris/core/runPredictionJob.ts +49 -0
  291. package/src/osiris/core/scales.ts +236 -0
  292. package/src/osiris/core/types.ts +103 -0
  293. package/src/osiris/core/valuation.ts +44 -0
  294. package/src/osiris/ui/PropertyBar.tsx +77 -0
  295. package/src/osiris/ui/PropertyPanel.tsx +227 -0
  296. package/src/osiris/ui/PropertyRows.tsx +92 -0
  297. package/src/osiris/ui/RiskFindings.tsx +137 -0
  298. package/src/osiris/ui/RiskPanel.tsx +81 -0
  299. package/src/osiris/ui/RiskSquare.tsx +108 -0
  300. package/src/osiris/ui/index.ts +17 -0
  301. package/src/osiris/ui/usePredictions.ts +194 -0
  302. package/src/osiris-ui.ts +11 -0
  303. package/src/osiris.ts +17 -0
  304. package/src/panel/ui/FilterInput.tsx +4 -1
  305. package/src/panel/ui/SidePanelItem.tsx +162 -0
  306. package/src/panel/ui/SidePanelStack.tsx +29 -36
  307. package/src/panel/ui/SpectrumColorSwatch.tsx +5 -3
  308. package/src/panel/ui/usePanelFolds.ts +103 -0
  309. package/src/shared/ui/FullscreenStage.tsx +96 -0
  310. package/src/shared/ui/canFillScreen.ts +8 -0
  311. package/src/shared/ui/index.ts +6 -0
  312. package/src/split/ui/splitPanes.tsx +4 -4
  313. package/src/structure/core/structureNotations.ts +25 -8
  314. package/src/structure/ui/StructureExportPanel.tsx +23 -4
  315. package/src/structure/ui/index.ts +4 -0
  316. package/styles/osiris.css +339 -0
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The four toxicity risks, and the sentence that keeps them honest.
3
+ *
4
+ * OSIRIS assesses mutagenicity, tumorigenicity, irritating effects and
5
+ * reproductive effects, in that order, and answers each with one of three
6
+ * levels — the same three the drug score multiplies by. A red square is very
7
+ * often the known-molecule branch rather than a matched fragment, which is why
8
+ * every assessed square opens its explanation.
9
+ *
10
+ * The caveat under them is the author's own, quoted rather than paraphrased: it
11
+ * is the sentence that stops a red square being read as a verdict, and softening
12
+ * it would be our words over his.
13
+ */
14
+
15
+ import { H5 } from '@blueprintjs/core';
16
+ import type { ReactElement } from 'react';
17
+
18
+ import { RISK_CAVEAT } from '../core/riskAppearance.ts';
19
+ import type { RiskLevel, RiskType } from '../core/types.ts';
20
+ import { RISK_TYPES } from '../core/types.ts';
21
+
22
+ import { RiskSquare } from './RiskSquare.tsx';
23
+
24
+ /** What {@link RiskPanel} needs. */
25
+ export interface RiskPanelProps {
26
+ /**
27
+ * How the four came back, or `null` when none of them has been assessed.
28
+ * @default null
29
+ */
30
+ risks?: Record<RiskType, RiskLevel> | null;
31
+ /**
32
+ * Whether a prediction is running for the molecule the panel is showing.
33
+ * @default false
34
+ */
35
+ pending?: boolean;
36
+ /**
37
+ * Which risk has its explanation open.
38
+ * @default null
39
+ */
40
+ openRisk?: RiskType | null;
41
+ /**
42
+ * Called with the risk to open, or `null` to close the one that is open.
43
+ * Without it the squares are not clickable.
44
+ * @default undefined
45
+ */
46
+ onOpenRisk?: (risk: RiskType | null) => void;
47
+ }
48
+
49
+ /**
50
+ * The four risk squares.
51
+ * @param props - See {@link RiskPanelProps}.
52
+ * @returns The panel, with the caveat under it.
53
+ */
54
+ export function RiskPanel(props: RiskPanelProps): ReactElement {
55
+ const { risks = null, pending = false, openRisk = null, onOpenRisk } = props;
56
+
57
+ return (
58
+ <section className="risk-panel">
59
+ <H5>Predicted toxicity risks</H5>
60
+ <div className="risk-grid">
61
+ {RISK_TYPES.map((risk) => (
62
+ <RiskSquare
63
+ key={risk}
64
+ risk={risk}
65
+ level={risks?.[risk]}
66
+ pending={pending}
67
+ selected={openRisk === risk}
68
+ onSelect={
69
+ onOpenRisk === undefined
70
+ ? undefined
71
+ : (chosen) => {
72
+ onOpenRisk(chosen === openRisk ? null : chosen);
73
+ }
74
+ }
75
+ />
76
+ ))}
77
+ </div>
78
+ <p className="osiris-note">{RISK_CAVEAT}</p>
79
+ </section>
80
+ );
81
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * One toxicity risk, as a coloured square with its name beside it.
3
+ *
4
+ * The square is a button whenever the page can explain it, because the
5
+ * explanation is the honest half of the colour: aspirin, caffeine and
6
+ * paracetamol come back red through the known-molecule branch, not through a
7
+ * toxicophore, and only opening it says so.
8
+ *
9
+ * `compact` drops the words and keeps the square, which is what a cell of the
10
+ * comparison table needs; the name and the level stay on the accessible label,
11
+ * so the cell is still readable to a screen reader and on hover.
12
+ */
13
+
14
+ import type { ReactElement } from 'react';
15
+
16
+ import { RISK_LABELS } from '../core/constants.ts';
17
+ import { riskAppearance } from '../core/riskAppearance.ts';
18
+ import type { RiskLevel, RiskType } from '../core/types.ts';
19
+
20
+ /** What {@link RiskSquare} needs. */
21
+ export interface RiskSquareProps {
22
+ /** Which of the four risks this shows. */
23
+ risk: RiskType;
24
+ /** How it came back, or `undefined` when it has not been assessed. */
25
+ level: RiskLevel | undefined;
26
+ /**
27
+ * Whether a prediction is running for this molecule. It is what tells an
28
+ * unassessed square to say it is working rather than that there is nothing
29
+ * to work on.
30
+ * @default false
31
+ */
32
+ pending?: boolean;
33
+ /**
34
+ * Whether this risk's explanation is the one open.
35
+ * @default false
36
+ */
37
+ selected?: boolean;
38
+ /**
39
+ * Called with the risk when the square is clicked. Without it the square is
40
+ * not a button.
41
+ * @default undefined
42
+ */
43
+ onSelect?: (risk: RiskType) => void;
44
+ /**
45
+ * Draw the square alone, for a cell of a table.
46
+ * @default false
47
+ */
48
+ compact?: boolean;
49
+ }
50
+
51
+ /**
52
+ * One risk's square.
53
+ * @param props - See {@link RiskSquareProps}.
54
+ * @returns The square, as a button when the page can explain it.
55
+ */
56
+ export function RiskSquare(props: RiskSquareProps): ReactElement {
57
+ const {
58
+ risk,
59
+ level,
60
+ pending = false,
61
+ selected = false,
62
+ onSelect,
63
+ compact = false,
64
+ } = props;
65
+ const { tone, label, explainable } = riskAppearance(level, pending);
66
+ const name = RISK_LABELS[risk];
67
+ const description = `${name}: ${label}`;
68
+ const clickable = onSelect !== undefined && explainable;
69
+
70
+ const body = (
71
+ <>
72
+ <span className="risk-square__swatch" data-level={tone} />
73
+ {compact ? null : (
74
+ <span className="risk-square__text">
75
+ <span className="risk-square__name">{name}</span>
76
+ <span className="risk-square__level">{label}</span>
77
+ </span>
78
+ )}
79
+ </>
80
+ );
81
+
82
+ if (!clickable) {
83
+ return (
84
+ <span
85
+ className={compact ? 'risk-square risk-square--compact' : 'risk-square'}
86
+ title={description}
87
+ aria-label={compact ? description : undefined}
88
+ >
89
+ {body}
90
+ </span>
91
+ );
92
+ }
93
+
94
+ return (
95
+ <button
96
+ type="button"
97
+ className={compact ? 'risk-square risk-square--compact' : 'risk-square'}
98
+ title={`${description} — why?`}
99
+ aria-label={compact ? description : undefined}
100
+ aria-pressed={selected}
101
+ onClick={() => {
102
+ onSelect(risk);
103
+ }}
104
+ >
105
+ {body}
106
+ </button>
107
+ );
108
+ }
@@ -0,0 +1,17 @@
1
+ export type { PropertyBarProps } from './PropertyBar.tsx';
2
+ export { PropertyBar } from './PropertyBar.tsx';
3
+ export type { PropertyPanelProps } from './PropertyPanel.tsx';
4
+ export { PropertyPanel } from './PropertyPanel.tsx';
5
+ export type { PropertyRowsProps } from './PropertyRows.tsx';
6
+ export { PropertyRows } from './PropertyRows.tsx';
7
+ export type { RiskFindingsProps } from './RiskFindings.tsx';
8
+ export { RiskFindings } from './RiskFindings.tsx';
9
+ export type { RiskPanelProps } from './RiskPanel.tsx';
10
+ export { RiskPanel } from './RiskPanel.tsx';
11
+ export type { RiskSquareProps } from './RiskSquare.tsx';
12
+ export { RiskSquare } from './RiskSquare.tsx';
13
+ export type {
14
+ UsePredictionsOptions,
15
+ UsePredictionsResult,
16
+ } from './usePredictions.ts';
17
+ export { usePredictions } from './usePredictions.ts';
@@ -0,0 +1,194 @@
1
+ /**
2
+ * The prediction pool, handed to a page.
3
+ *
4
+ * The only React in the domain. Results arrive one at a time and are kept in a
5
+ * map the page reads by row key, so a table draws every row immediately and
6
+ * fills each one in as its worker answers — nothing waits for the set.
7
+ *
8
+ * The two maps are created once and mutated, and a counter beside them changes
9
+ * to say so. Building a new map per answer would copy a growing map once per
10
+ * molecule, which on a set of two thousand costs more than the predictions do.
11
+ */
12
+
13
+ import { useCallback, useEffect, useRef, useState } from 'react';
14
+
15
+ import type { WorkerLike } from '../../worker/core/messages.ts';
16
+ import type {
17
+ PredictionInput,
18
+ PredictionPool,
19
+ PredictionProgress,
20
+ } from '../core/poolTypes.ts';
21
+ import { createPredictionPool } from '../core/predictionPool.ts';
22
+ import type { ResourceSource } from '../core/predictors.ts';
23
+ import type { OsirisProperties, RiskDetail, RiskType } from '../core/types.ts';
24
+
25
+ /** What a page gives the hook. */
26
+ export interface UsePredictionsOptions {
27
+ /**
28
+ * The molecules to predict. One already answered is never asked for again,
29
+ * so a page may pass its whole set on every render — though memoising it
30
+ * saves the filtering pass.
31
+ */
32
+ molecules: readonly PredictionInput[];
33
+ /**
34
+ * The keys of the rows the reader can see, most wanted first. They are
35
+ * answered before the rest.
36
+ * @default undefined — the reading order is kept
37
+ */
38
+ visibleKeys?: readonly string[];
39
+ /**
40
+ * Whether to predict at all. Off while a file is still being read, so the
41
+ * pool is not asked for half a set.
42
+ * @default true
43
+ */
44
+ enabled?: boolean;
45
+ /**
46
+ * Where the workers register OpenChemLib's resources from: the absolute URL
47
+ * of the site's own `openchemlib-resources.json`, resolved on the main thread
48
+ * — a worker has no `document` to read the deployment's mount path off, and
49
+ * a relative address would resolve against its hashed chunk.
50
+ */
51
+ resources: ResourceSource;
52
+ /**
53
+ * Makes one prediction worker: a module worker of the site's own, serving
54
+ * `runPredictionJob` for the requests `isPredictRequest` accepts. It may be
55
+ * a new function on every render — it is read only when a worker is made.
56
+ */
57
+ createWorker: () => WorkerLike;
58
+ /**
59
+ * How many workers to run.
60
+ * @default one fewer than the machine's cores, clamped to 1 to 8
61
+ */
62
+ size?: number;
63
+ }
64
+
65
+ /** What the hook gives a page back. */
66
+ export interface UsePredictionsResult {
67
+ /** What each answered row was predicted to be, by row key. */
68
+ results: ReadonlyMap<string, OsirisProperties>;
69
+ /** Why each refused row was refused, by row key. */
70
+ failures: ReadonlyMap<string, string>;
71
+ /** How far the pool has got. */
72
+ progress: PredictionProgress;
73
+ /** Why no prediction can be made at all, or `null`. */
74
+ error: string | null;
75
+ /** Drop everything still queued. */
76
+ cancel: () => void;
77
+ /**
78
+ * Why one risk came back as it did.
79
+ * @param idCode - The molecule, coordinates included or not.
80
+ * @param risk - Which of the four risks to explain.
81
+ * @returns The findings, with the matched atoms and bonds of every fragment.
82
+ */
83
+ riskDetail: (idCode: string, risk: RiskType) => Promise<RiskDetail>;
84
+ }
85
+
86
+ const IDLE: PredictionProgress = {
87
+ done: 0,
88
+ total: 0,
89
+ pending: 0,
90
+ running: false,
91
+ };
92
+
93
+ interface Answered {
94
+ results: Map<string, OsirisProperties>;
95
+ failures: Map<string, string>;
96
+ }
97
+
98
+ interface PoolView {
99
+ progress: PredictionProgress;
100
+ error: string | null;
101
+ answers: number;
102
+ }
103
+
104
+ /**
105
+ * Predict a set of molecules on a pool of workers, streaming the answers back.
106
+ * @param options - See {@link UsePredictionsOptions}.
107
+ * @returns The answers so far, the progress, and the controls.
108
+ */
109
+ export function usePredictions(
110
+ options: UsePredictionsOptions,
111
+ ): UsePredictionsResult {
112
+ const { molecules, visibleKeys, enabled = true, size } = options;
113
+ const { resources, createWorker } = options;
114
+ // Read when the pool and its workers are made rather than listed as a
115
+ // dependency: a factory written inline is a new function on every render,
116
+ // and the progress the pool reports causes one.
117
+ const source = useRef({ resources, createWorker });
118
+ useEffect(() => {
119
+ source.current = { resources, createWorker };
120
+ }, [resources, createWorker]);
121
+
122
+ const [answered] = useState<Answered>(() => ({
123
+ results: new Map(),
124
+ failures: new Map(),
125
+ }));
126
+ const [view, setView] = useState<PoolView>({
127
+ progress: IDLE,
128
+ error: null,
129
+ answers: 0,
130
+ });
131
+ const pool = useRef<PredictionPool | null>(null);
132
+
133
+ const open = useCallback((): PredictionPool => {
134
+ pool.current ??= createPredictionPool({
135
+ resources: source.current.resources,
136
+ createWorker: () => source.current.createWorker(),
137
+ ...(size === undefined ? {} : { size }),
138
+ onResult(outcome) {
139
+ if (outcome.ok) answered.results.set(outcome.key, outcome.properties);
140
+ else answered.failures.set(outcome.key, outcome.message);
141
+ setView((previous) => ({ ...previous, answers: previous.answers + 1 }));
142
+ },
143
+ onProgress(progress) {
144
+ setView((previous) => ({ ...previous, progress }));
145
+ },
146
+ onUnavailable(message) {
147
+ setView((previous) => ({ ...previous, error: message }));
148
+ },
149
+ });
150
+ return pool.current;
151
+ }, [answered, size]);
152
+
153
+ const unavailable = view.error;
154
+ useEffect(() => {
155
+ if (!enabled || unavailable !== null) return;
156
+ const waiting: PredictionInput[] = [];
157
+ for (const molecule of molecules) {
158
+ if (answered.results.has(molecule.key)) continue;
159
+ if (answered.failures.has(molecule.key)) continue;
160
+ waiting.push(molecule);
161
+ }
162
+ if (waiting.length > 0) open().submit(waiting);
163
+ }, [answered, molecules, enabled, open, unavailable]);
164
+
165
+ useEffect(() => {
166
+ if (visibleKeys !== undefined) pool.current?.prioritize(visibleKeys);
167
+ }, [visibleKeys]);
168
+
169
+ useEffect(
170
+ () => () => {
171
+ pool.current?.terminate();
172
+ pool.current = null;
173
+ },
174
+ [],
175
+ );
176
+
177
+ const cancel = useCallback(() => {
178
+ pool.current?.cancel();
179
+ }, []);
180
+
181
+ const riskDetail = useCallback(
182
+ (idCode: string, risk: RiskType) => open().riskDetail(idCode, risk),
183
+ [open],
184
+ );
185
+
186
+ return {
187
+ results: answered.results,
188
+ failures: answered.failures,
189
+ progress: view.progress,
190
+ error: view.error,
191
+ cancel,
192
+ riskDetail,
193
+ };
194
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The OSIRIS property panel — the four risk squares, the ten bars and the
3
+ * explanation a square opens — and `usePredictions`, which drives a pool of
4
+ * prediction workers from a page.
5
+ *
6
+ * Kept apart from `react-cheminfo/osiris` so the worker that predicts loads no
7
+ * React and no Blueprint; everything the panel draws from is imported from
8
+ * there. The stylesheet is `react-cheminfo/styles/osiris.css`.
9
+ */
10
+
11
+ export * from './osiris/ui/index.ts';
package/src/osiris.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * What OSIRIS predicts about a molecule — the four toxicity risks, cLogP,
3
+ * solubility, drug-likeness and the drug score — and the pool of workers that
4
+ * predicts a whole set of them.
5
+ *
6
+ * Framework-free on purpose, and its own door for two reasons. A prediction
7
+ * worker imports `runPredictionJob` and `isPredictRequest` from here, and a dev
8
+ * server hands a worker its dependencies unbundled, so anything React-shaped
9
+ * behind this door would be evaluated in every worker. And a server answering
10
+ * predictions over an API loads it in Node, where nothing is tree-shaken.
11
+ * `openchemlib` is imported on the first prediction, never on import.
12
+ *
13
+ * The panel that draws the answer, and the hook that drives the pool from a
14
+ * page, are `react-cheminfo/osiris-ui`.
15
+ */
16
+
17
+ export * from './osiris/core/index.ts';
@@ -1,5 +1,7 @@
1
1
  import { InputGroup } from '@blueprintjs/core';
2
2
 
3
+ import { useChromeT } from '../../i18n/ui/useT.ts';
4
+
3
5
  import { ClearButton } from './ClearButton.tsx';
4
6
 
5
7
  export interface FilterInputProps {
@@ -34,6 +36,7 @@ export interface FilterInputProps {
34
36
  */
35
37
  export function FilterInput(props: FilterInputProps) {
36
38
  const { value, onValueChange, placeholder, autoFocus = false } = props;
39
+ const t = useChromeT();
37
40
 
38
41
  return (
39
42
  <InputGroup
@@ -49,7 +52,7 @@ export function FilterInput(props: FilterInputProps) {
49
52
  rightElement={
50
53
  value.length > 0 ? (
51
54
  <ClearButton
52
- label="Clear the filter"
55
+ label={t('panel.clearFilter')}
53
56
  onClick={() => onValueChange('')}
54
57
  />
55
58
  ) : undefined
@@ -0,0 +1,162 @@
1
+ import type { CSSProperties, ReactNode } from 'react';
2
+ import { useCallback, useRef, useState } from 'react';
3
+ import { Accordion, Button } from 'react-science/ui';
4
+
5
+ import type { Language } from '../../i18n/core/languages.ts';
6
+ import { useLanguage } from '../../i18n/ui/useLanguage.ts';
7
+ import { useChromeT } from '../../i18n/ui/useT.ts';
8
+ import { FullscreenStage } from '../../shared/ui/FullscreenStage.tsx';
9
+ import { canFillScreen } from '../../shared/ui/canFillScreen.ts';
10
+ import { TOKEN } from '../../tokens/core/familyTokens.ts';
11
+ import { panelStyle, panelToolbarStyle } from '../core/panelStyles.ts';
12
+
13
+ /** Props of {@link SidePanelItem}. */
14
+ export interface SidePanelItemProps {
15
+ /** Identity of the panel in the stack. */
16
+ id: string;
17
+ /** What the header says. */
18
+ title: string;
19
+ /** Whether the panel shows its body. */
20
+ isOpen: boolean;
21
+ /**
22
+ * Called when the chevron, the header or a shift-click on another header
23
+ * folds or unfolds the panel.
24
+ * @param isOpen - Whether it shows its body.
25
+ */
26
+ onOpenChange: (isOpen: boolean) => void;
27
+ /**
28
+ * Whether the panel is the one in focus, and the toggle; `undefined` while it
29
+ * is alone in the stack, where there is nothing to fold.
30
+ */
31
+ focus: { active: boolean; toggle: () => void } | undefined;
32
+ /** Called when the close cross is pressed. */
33
+ onClose: () => void;
34
+ /** The body. */
35
+ children: ReactNode;
36
+ }
37
+
38
+ /**
39
+ * One panel of the stack: the header with the shell's gestures, and the body,
40
+ * which is also the box that fills the screen.
41
+ *
42
+ * The header is not part of what fills the screen, so a body that does carries
43
+ * a bar of its own with the title and the way back.
44
+ * @param props - See {@link SidePanelItemProps}.
45
+ * @returns The accordion item.
46
+ */
47
+ export function SidePanelItem(props: SidePanelItemProps) {
48
+ const { id, title, isOpen, onOpenChange, focus, onClose, children } = props;
49
+ const t = useChromeT();
50
+ const panel = inSentence(title, useLanguage());
51
+ const [canFill] = useState(canFillScreen);
52
+ const body = useRef<HTMLDivElement | null>(null);
53
+ const onStage = useCallback((element: HTMLDivElement | null) => {
54
+ body.current = element;
55
+ }, []);
56
+
57
+ function fillScreen(): void {
58
+ if (!isOpen) onOpenChange(true);
59
+ void body.current?.requestFullscreen().catch(() => undefined);
60
+ }
61
+
62
+ return (
63
+ <Accordion.Item
64
+ id={id}
65
+ title={title}
66
+ open={isOpen}
67
+ onOpenChange={onOpenChange}
68
+ renderToolbar={() => (
69
+ <>
70
+ {focus !== undefined && (
71
+ <Button
72
+ variant="minimal"
73
+ icon={focus.active ? 'expand-all' : 'collapse-all'}
74
+ aria-pressed={focus.active}
75
+ aria-label={t('panel.focus', { panel })}
76
+ tooltipProps={{
77
+ content: focus.active
78
+ ? t('panel.unfocusTooltip')
79
+ : t('panel.focusTooltip'),
80
+ }}
81
+ onClick={focus.toggle}
82
+ />
83
+ )}
84
+ {canFill && (
85
+ <Button
86
+ variant="minimal"
87
+ icon="fullscreen"
88
+ aria-label={t('panel.fillScreen', { panel })}
89
+ tooltipProps={{ content: t('panel.fillScreenTooltip') }}
90
+ onClick={fillScreen}
91
+ />
92
+ )}
93
+ <Button
94
+ variant="minimal"
95
+ icon={isOpen ? 'chevron-down' : 'chevron-right'}
96
+ data-panel-open={isOpen}
97
+ aria-expanded={isOpen}
98
+ aria-label={t(isOpen ? 'panel.fold' : 'panel.unfold', { panel })}
99
+ tooltipProps={{
100
+ content: t(isOpen ? 'panel.foldTooltip' : 'panel.unfoldTooltip'),
101
+ }}
102
+ onClick={() => onOpenChange(!isOpen)}
103
+ />
104
+ <Button
105
+ variant="minimal"
106
+ icon="cross"
107
+ tooltipProps={{ content: t('panel.closeTooltip') }}
108
+ aria-label={t('panel.close', { panel })}
109
+ onClick={onClose}
110
+ />
111
+ </>
112
+ )}
113
+ >
114
+ <FullscreenStage style={bodyStyle} onStage={onStage}>
115
+ {(fullscreen) => (
116
+ <>
117
+ {fullscreen?.active === true && (
118
+ <div style={fullscreenBarStyle}>
119
+ <span style={fullscreenTitleStyle}>{title}</span>
120
+ <Button
121
+ variant="minimal"
122
+ icon="minimize"
123
+ aria-label={t('panel.leaveFullScreen')}
124
+ tooltipProps={{ content: t('panel.leaveFullScreenTooltip') }}
125
+ onClick={fullscreen.toggle}
126
+ />
127
+ </div>
128
+ )}
129
+ {children}
130
+ </>
131
+ )}
132
+ </FullscreenStage>
133
+ </Accordion.Item>
134
+ );
135
+ }
136
+
137
+ /**
138
+ * The title as it reads inside a sentence: lowercased, except in German, where
139
+ * every noun keeps its capital.
140
+ * @param title - The panel's title.
141
+ * @param language - The language of the sentence.
142
+ * @returns The title to write into it.
143
+ */
144
+ function inSentence(title: string, language: Language): string {
145
+ return language === 'de' ? title : title.toLocaleLowerCase(language);
146
+ }
147
+
148
+ /** A box filling the screen shows the backdrop through it unless painted. */
149
+ const filledStyle: CSSProperties = { ...panelStyle, background: TOKEN.surface };
150
+
151
+ function bodyStyle(fillsScreen: boolean): CSSProperties {
152
+ return fillsScreen ? filledStyle : panelStyle;
153
+ }
154
+
155
+ const fullscreenBarStyle: CSSProperties = {
156
+ ...panelToolbarStyle,
157
+ alignItems: 'center',
158
+ justifyContent: 'space-between',
159
+ paddingLeft: 12,
160
+ };
161
+
162
+ const fullscreenTitleStyle: CSSProperties = { fontWeight: 'bold' };