react-cheminfo 0.76.0 → 0.78.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 (389) 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/host/core/connectHost.js +1 -1
  71. package/lib/host/core/connectHost.js.map +1 -1
  72. package/lib/host/core/connectTool.d.ts +103 -0
  73. package/lib/host/core/connectTool.d.ts.map +1 -0
  74. package/lib/host/core/connectTool.js +169 -0
  75. package/lib/host/core/connectTool.js.map +1 -0
  76. package/lib/host/core/hostOutputs.d.ts +16 -3
  77. package/lib/host/core/hostOutputs.d.ts.map +1 -1
  78. package/lib/host/core/hostOutputs.js +38 -4
  79. package/lib/host/core/hostOutputs.js.map +1 -1
  80. package/lib/host/core/index.d.ts +8 -2
  81. package/lib/host/core/index.d.ts.map +1 -1
  82. package/lib/host/core/index.js +4 -1
  83. package/lib/host/core/index.js.map +1 -1
  84. package/lib/host/core/kinds.d.ts +31 -3
  85. package/lib/host/core/kinds.d.ts.map +1 -1
  86. package/lib/host/core/kinds.js +35 -4
  87. package/lib/host/core/kinds.js.map +1 -1
  88. package/lib/host/core/messageValues.d.ts +29 -0
  89. package/lib/host/core/messageValues.d.ts.map +1 -0
  90. package/lib/host/core/messageValues.js +57 -0
  91. package/lib/host/core/messageValues.js.map +1 -0
  92. package/lib/host/core/protocol.d.ts +2 -5
  93. package/lib/host/core/protocol.d.ts.map +1 -1
  94. package/lib/host/core/protocol.js +3 -37
  95. package/lib/host/core/protocol.js.map +1 -1
  96. package/lib/host/core/resultKinds.d.ts +74 -0
  97. package/lib/host/core/resultKinds.d.ts.map +1 -0
  98. package/lib/host/core/resultKinds.js +40 -0
  99. package/lib/host/core/resultKinds.js.map +1 -0
  100. package/lib/host/core/toolMessages.d.ts +24 -0
  101. package/lib/host/core/toolMessages.d.ts.map +1 -0
  102. package/lib/host/core/toolMessages.js +136 -0
  103. package/lib/host/core/toolMessages.js.map +1 -0
  104. package/lib/host/ui/index.d.ts +2 -0
  105. package/lib/host/ui/index.d.ts.map +1 -1
  106. package/lib/host/ui/index.js +1 -0
  107. package/lib/host/ui/index.js.map +1 -1
  108. package/lib/host/ui/useFramedTool.d.ts +74 -0
  109. package/lib/host/ui/useFramedTool.d.ts.map +1 -0
  110. package/lib/host/ui/useFramedTool.js +125 -0
  111. package/lib/host/ui/useFramedTool.js.map +1 -0
  112. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  113. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  114. package/lib/locales/de.json +30 -1
  115. package/lib/locales/en.json +30 -1
  116. package/lib/locales/es.json +30 -1
  117. package/lib/locales/fr.json +30 -1
  118. package/lib/locales/it.json +30 -1
  119. package/lib/molecule3d/ui/Molecule3DStage.d.ts +4 -33
  120. package/lib/molecule3d/ui/Molecule3DStage.d.ts.map +1 -1
  121. package/lib/molecule3d/ui/Molecule3DStage.js +3 -37
  122. package/lib/molecule3d/ui/Molecule3DStage.js.map +1 -1
  123. package/lib/molecule3d/ui/MoleculeCanvas3D.d.ts.map +1 -1
  124. package/lib/molecule3d/ui/MoleculeCanvas3D.js +10 -2
  125. package/lib/molecule3d/ui/MoleculeCanvas3D.js.map +1 -1
  126. package/lib/molecule3d/ui/exportMoleculeImage.d.ts +10 -0
  127. package/lib/molecule3d/ui/exportMoleculeImage.d.ts.map +1 -1
  128. package/lib/molecule3d/ui/exportMoleculeImage.js +17 -0
  129. package/lib/molecule3d/ui/exportMoleculeImage.js.map +1 -1
  130. package/lib/molecule3d/ui/index.d.ts +1 -1
  131. package/lib/molecule3d/ui/index.d.ts.map +1 -1
  132. package/lib/molecule3d/ui/moleculeViewer3DProps.d.ts +23 -0
  133. package/lib/molecule3d/ui/moleculeViewer3DProps.d.ts.map +1 -1
  134. package/lib/molecule3d/ui/useImageExport.d.ts +3 -0
  135. package/lib/molecule3d/ui/useImageExport.d.ts.map +1 -1
  136. package/lib/molecule3d/ui/useImageExport.js +21 -3
  137. package/lib/molecule3d/ui/useImageExport.js.map +1 -1
  138. package/lib/osiris/core/barGeometry.d.ts +42 -0
  139. package/lib/osiris/core/barGeometry.d.ts.map +1 -0
  140. package/lib/osiris/core/barGeometry.js +46 -0
  141. package/lib/osiris/core/barGeometry.js.map +1 -0
  142. package/lib/osiris/core/computeProperties.d.ts +42 -0
  143. package/lib/osiris/core/computeProperties.d.ts.map +1 -0
  144. package/lib/osiris/core/computeProperties.js +115 -0
  145. package/lib/osiris/core/computeProperties.js.map +1 -0
  146. package/lib/osiris/core/constants.d.ts +70 -0
  147. package/lib/osiris/core/constants.d.ts.map +1 -0
  148. package/lib/osiris/core/constants.js +99 -0
  149. package/lib/osiris/core/constants.js.map +1 -0
  150. package/lib/osiris/core/fitness.d.ts +32 -0
  151. package/lib/osiris/core/fitness.d.ts.map +1 -0
  152. package/lib/osiris/core/fitness.js +48 -0
  153. package/lib/osiris/core/fitness.js.map +1 -0
  154. package/lib/osiris/core/index.d.ts +29 -0
  155. package/lib/osiris/core/index.d.ts.map +1 -0
  156. package/lib/osiris/core/index.js +19 -0
  157. package/lib/osiris/core/index.js.map +1 -0
  158. package/lib/osiris/core/poolSize.d.ts +17 -0
  159. package/lib/osiris/core/poolSize.d.ts.map +1 -0
  160. package/lib/osiris/core/poolSize.js +22 -0
  161. package/lib/osiris/core/poolSize.js.map +1 -0
  162. package/lib/osiris/core/poolTypes.d.ts +140 -0
  163. package/lib/osiris/core/poolTypes.d.ts.map +1 -0
  164. package/lib/osiris/core/poolTypes.js +12 -0
  165. package/lib/osiris/core/poolTypes.js.map +1 -0
  166. package/lib/osiris/core/predictIdCode.d.ts +39 -0
  167. package/lib/osiris/core/predictIdCode.d.ts.map +1 -0
  168. package/lib/osiris/core/predictIdCode.js +54 -0
  169. package/lib/osiris/core/predictIdCode.js.map +1 -0
  170. package/lib/osiris/core/predictProtocol.d.ts +67 -0
  171. package/lib/osiris/core/predictProtocol.d.ts.map +1 -0
  172. package/lib/osiris/core/predictProtocol.js +29 -0
  173. package/lib/osiris/core/predictProtocol.js.map +1 -0
  174. package/lib/osiris/core/predictionPool.d.ts +23 -0
  175. package/lib/osiris/core/predictionPool.d.ts.map +1 -0
  176. package/lib/osiris/core/predictionPool.js +186 -0
  177. package/lib/osiris/core/predictionPool.js.map +1 -0
  178. package/lib/osiris/core/predictionQueue.d.ts +46 -0
  179. package/lib/osiris/core/predictionQueue.d.ts.map +1 -0
  180. package/lib/osiris/core/predictionQueue.js +57 -0
  181. package/lib/osiris/core/predictionQueue.js.map +1 -0
  182. package/lib/osiris/core/predictors.d.ts +62 -0
  183. package/lib/osiris/core/predictors.d.ts.map +1 -0
  184. package/lib/osiris/core/predictors.js +100 -0
  185. package/lib/osiris/core/predictors.js.map +1 -0
  186. package/lib/osiris/core/propertyKeys.d.ts +32 -0
  187. package/lib/osiris/core/propertyKeys.d.ts.map +1 -0
  188. package/lib/osiris/core/propertyKeys.js +44 -0
  189. package/lib/osiris/core/propertyKeys.js.map +1 -0
  190. package/lib/osiris/core/riskAppearance.d.ts +60 -0
  191. package/lib/osiris/core/riskAppearance.d.ts.map +1 -0
  192. package/lib/osiris/core/riskAppearance.js +59 -0
  193. package/lib/osiris/core/riskAppearance.js.map +1 -0
  194. package/lib/osiris/core/riskDetail.d.ts +22 -0
  195. package/lib/osiris/core/riskDetail.d.ts.map +1 -0
  196. package/lib/osiris/core/riskDetail.js +86 -0
  197. package/lib/osiris/core/riskDetail.js.map +1 -0
  198. package/lib/osiris/core/riskDetailRequest.d.ts +31 -0
  199. package/lib/osiris/core/riskDetailRequest.d.ts.map +1 -0
  200. package/lib/osiris/core/riskDetailRequest.js +49 -0
  201. package/lib/osiris/core/riskDetailRequest.js.map +1 -0
  202. package/lib/osiris/core/riskFindings.d.ts +26 -0
  203. package/lib/osiris/core/riskFindings.d.ts.map +1 -0
  204. package/lib/osiris/core/riskFindings.js +79 -0
  205. package/lib/osiris/core/riskFindings.js.map +1 -0
  206. package/lib/osiris/core/runPredictionJob.d.ts +20 -0
  207. package/lib/osiris/core/runPredictionJob.d.ts.map +1 -0
  208. package/lib/osiris/core/runPredictionJob.js +43 -0
  209. package/lib/osiris/core/runPredictionJob.js.map +1 -0
  210. package/lib/osiris/core/scales.d.ts +70 -0
  211. package/lib/osiris/core/scales.d.ts.map +1 -0
  212. package/lib/osiris/core/scales.js +185 -0
  213. package/lib/osiris/core/scales.js.map +1 -0
  214. package/lib/osiris/core/types.d.ts +91 -0
  215. package/lib/osiris/core/types.d.ts.map +1 -0
  216. package/lib/osiris/core/types.js +19 -0
  217. package/lib/osiris/core/types.js.map +1 -0
  218. package/lib/osiris/core/valuation.d.ts +28 -0
  219. package/lib/osiris/core/valuation.d.ts.map +1 -0
  220. package/lib/osiris/core/valuation.js +39 -0
  221. package/lib/osiris/core/valuation.js.map +1 -0
  222. package/lib/osiris/ui/PropertyBar.d.ts +27 -0
  223. package/lib/osiris/ui/PropertyBar.d.ts.map +1 -0
  224. package/lib/osiris/ui/PropertyBar.js +27 -0
  225. package/lib/osiris/ui/PropertyBar.js.map +1 -0
  226. package/lib/osiris/ui/PropertyPanel.d.ts +91 -0
  227. package/lib/osiris/ui/PropertyPanel.d.ts.map +1 -0
  228. package/lib/osiris/ui/PropertyPanel.js +77 -0
  229. package/lib/osiris/ui/PropertyPanel.js.map +1 -0
  230. package/lib/osiris/ui/PropertyRows.d.ts +40 -0
  231. package/lib/osiris/ui/PropertyRows.d.ts.map +1 -0
  232. package/lib/osiris/ui/PropertyRows.js +23 -0
  233. package/lib/osiris/ui/PropertyRows.js.map +1 -0
  234. package/lib/osiris/ui/RiskFindings.d.ts +43 -0
  235. package/lib/osiris/ui/RiskFindings.d.ts.map +1 -0
  236. package/lib/osiris/ui/RiskFindings.js +51 -0
  237. package/lib/osiris/ui/RiskFindings.js.map +1 -0
  238. package/lib/osiris/ui/RiskPanel.d.ts +46 -0
  239. package/lib/osiris/ui/RiskPanel.d.ts.map +1 -0
  240. package/lib/osiris/ui/RiskPanel.js +32 -0
  241. package/lib/osiris/ui/RiskPanel.js.map +1 -0
  242. package/lib/osiris/ui/RiskSquare.d.ts +51 -0
  243. package/lib/osiris/ui/RiskSquare.d.ts.map +1 -0
  244. package/lib/osiris/ui/RiskSquare.js +23 -0
  245. package/lib/osiris/ui/RiskSquare.js.map +1 -0
  246. package/lib/osiris/ui/index.d.ts +15 -0
  247. package/lib/osiris/ui/index.d.ts.map +1 -0
  248. package/lib/osiris/ui/index.js +8 -0
  249. package/lib/osiris/ui/index.js.map +1 -0
  250. package/lib/osiris/ui/usePredictions.d.ts +81 -0
  251. package/lib/osiris/ui/usePredictions.d.ts.map +1 -0
  252. package/lib/osiris/ui/usePredictions.js +102 -0
  253. package/lib/osiris/ui/usePredictions.js.map +1 -0
  254. package/lib/osiris-ui.d.ts +11 -0
  255. package/lib/osiris-ui.d.ts.map +1 -0
  256. package/lib/osiris-ui.js +11 -0
  257. package/lib/osiris-ui.js.map +1 -0
  258. package/lib/osiris.d.ts +17 -0
  259. package/lib/osiris.d.ts.map +1 -0
  260. package/lib/osiris.js +17 -0
  261. package/lib/osiris.js.map +1 -0
  262. package/lib/panel/ui/FilterInput.d.ts.map +1 -1
  263. package/lib/panel/ui/FilterInput.js +3 -1
  264. package/lib/panel/ui/FilterInput.js.map +1 -1
  265. package/lib/panel/ui/SidePanelItem.d.ts +39 -0
  266. package/lib/panel/ui/SidePanelItem.d.ts.map +1 -0
  267. package/lib/panel/ui/SidePanelItem.js +63 -0
  268. package/lib/panel/ui/SidePanelItem.js.map +1 -0
  269. package/lib/panel/ui/SidePanelStack.d.ts +11 -10
  270. package/lib/panel/ui/SidePanelStack.d.ts.map +1 -1
  271. package/lib/panel/ui/SidePanelStack.js +22 -15
  272. package/lib/panel/ui/SidePanelStack.js.map +1 -1
  273. package/lib/panel/ui/SpectrumColorSwatch.d.ts.map +1 -1
  274. package/lib/panel/ui/SpectrumColorSwatch.js +4 -2
  275. package/lib/panel/ui/SpectrumColorSwatch.js.map +1 -1
  276. package/lib/panel/ui/usePanelFolds.d.ts +35 -0
  277. package/lib/panel/ui/usePanelFolds.d.ts.map +1 -0
  278. package/lib/panel/ui/usePanelFolds.js +73 -0
  279. package/lib/panel/ui/usePanelFolds.js.map +1 -0
  280. package/lib/shared/ui/FullscreenStage.d.ts +43 -0
  281. package/lib/shared/ui/FullscreenStage.d.ts.map +1 -0
  282. package/lib/shared/ui/FullscreenStage.js +38 -0
  283. package/lib/shared/ui/FullscreenStage.js.map +1 -0
  284. package/lib/shared/ui/canFillScreen.d.ts +7 -0
  285. package/lib/shared/ui/canFillScreen.d.ts.map +1 -0
  286. package/lib/shared/ui/canFillScreen.js +9 -0
  287. package/lib/shared/ui/canFillScreen.js.map +1 -0
  288. package/lib/shared/ui/index.d.ts +3 -0
  289. package/lib/shared/ui/index.d.ts.map +1 -1
  290. package/lib/shared/ui/index.js +2 -0
  291. package/lib/shared/ui/index.js.map +1 -1
  292. package/lib/split/ui/splitPanes.d.ts +3 -3
  293. package/lib/split/ui/splitPanes.js +1 -1
  294. package/lib/structure/core/structureNotations.d.ts +8 -1
  295. package/lib/structure/core/structureNotations.d.ts.map +1 -1
  296. package/lib/structure/core/structureNotations.js +14 -8
  297. package/lib/structure/core/structureNotations.js.map +1 -1
  298. package/lib/structure/ui/StructureExportPanel.d.ts +8 -0
  299. package/lib/structure/ui/StructureExportPanel.d.ts.map +1 -1
  300. package/lib/structure/ui/StructureExportPanel.js +9 -4
  301. package/lib/structure/ui/StructureExportPanel.js.map +1 -1
  302. package/lib/structure/ui/index.d.ts +1 -0
  303. package/lib/structure/ui/index.d.ts.map +1 -1
  304. package/lib/structure/ui/index.js.map +1 -1
  305. package/package.json +4 -1
  306. package/src/card/core/cardAddress.ts +39 -3
  307. package/src/card/core/cardPageUrl.ts +10 -3
  308. package/src/card/core/index.ts +7 -1
  309. package/src/credits/core/credits.ts +40 -0
  310. package/src/download/core/downloadFigure.ts +26 -1
  311. package/src/download/core/figureDpi.ts +94 -0
  312. package/src/download/core/figurePng.ts +11 -2
  313. package/src/download/core/index.ts +13 -1
  314. package/src/download/core/pngDpi.ts +84 -0
  315. package/src/download/ui/FigureDownloadPanel.tsx +41 -51
  316. package/src/download/ui/figureDownloadHint.ts +13 -0
  317. package/src/download/ui/figureDownloadOptions.ts +85 -0
  318. package/src/download/ui/resolutionChoices.ts +67 -0
  319. package/src/download/ui/useFigureActions.ts +24 -9
  320. package/src/download/ui/useFigureDownload.tsx +57 -71
  321. package/src/ecosystem/core/sites.ts +14 -0
  322. package/src/ecosystem/core/types.ts +2 -1
  323. package/src/ecosystem/ui/glyphs.tsx +20 -0
  324. package/src/host/core/connectHost.ts +1 -1
  325. package/src/host/core/connectTool.ts +285 -0
  326. package/src/host/core/hostOutputs.ts +47 -5
  327. package/src/host/core/index.ts +20 -1
  328. package/src/host/core/kinds.ts +53 -8
  329. package/src/host/core/messageValues.ts +58 -0
  330. package/src/host/core/protocol.ts +5 -37
  331. package/src/host/core/resultKinds.ts +65 -0
  332. package/src/host/core/toolMessages.ts +160 -0
  333. package/src/host/ui/index.ts +6 -0
  334. package/src/host/ui/useFramedTool.ts +213 -0
  335. package/src/locales/de.json +30 -1
  336. package/src/locales/en.json +30 -1
  337. package/src/locales/es.json +30 -1
  338. package/src/locales/fr.json +30 -1
  339. package/src/locales/it.json +30 -1
  340. package/src/molecule3d/ui/Molecule3DStage.tsx +4 -88
  341. package/src/molecule3d/ui/MoleculeCanvas3D.tsx +10 -1
  342. package/src/molecule3d/ui/exportMoleculeImage.ts +22 -0
  343. package/src/molecule3d/ui/index.ts +4 -1
  344. package/src/molecule3d/ui/moleculeViewer3DProps.ts +24 -0
  345. package/src/molecule3d/ui/useImageExport.ts +28 -2
  346. package/src/osiris/core/barGeometry.ts +74 -0
  347. package/src/osiris/core/computeProperties.ts +175 -0
  348. package/src/osiris/core/constants.ts +110 -0
  349. package/src/osiris/core/fitness.ts +59 -0
  350. package/src/osiris/core/index.ts +78 -0
  351. package/src/osiris/core/poolSize.ts +24 -0
  352. package/src/osiris/core/poolTypes.ts +140 -0
  353. package/src/osiris/core/predictIdCode.ts +69 -0
  354. package/src/osiris/core/predictProtocol.ts +78 -0
  355. package/src/osiris/core/predictionPool.ts +237 -0
  356. package/src/osiris/core/predictionQueue.ts +89 -0
  357. package/src/osiris/core/predictors.ts +142 -0
  358. package/src/osiris/core/propertyKeys.ts +54 -0
  359. package/src/osiris/core/riskAppearance.ts +86 -0
  360. package/src/osiris/core/riskDetail.ts +120 -0
  361. package/src/osiris/core/riskDetailRequest.ts +64 -0
  362. package/src/osiris/core/riskFindings.ts +92 -0
  363. package/src/osiris/core/runPredictionJob.ts +49 -0
  364. package/src/osiris/core/scales.ts +236 -0
  365. package/src/osiris/core/types.ts +103 -0
  366. package/src/osiris/core/valuation.ts +44 -0
  367. package/src/osiris/ui/PropertyBar.tsx +77 -0
  368. package/src/osiris/ui/PropertyPanel.tsx +227 -0
  369. package/src/osiris/ui/PropertyRows.tsx +92 -0
  370. package/src/osiris/ui/RiskFindings.tsx +137 -0
  371. package/src/osiris/ui/RiskPanel.tsx +81 -0
  372. package/src/osiris/ui/RiskSquare.tsx +108 -0
  373. package/src/osiris/ui/index.ts +17 -0
  374. package/src/osiris/ui/usePredictions.ts +194 -0
  375. package/src/osiris-ui.ts +11 -0
  376. package/src/osiris.ts +17 -0
  377. package/src/panel/ui/FilterInput.tsx +4 -1
  378. package/src/panel/ui/SidePanelItem.tsx +162 -0
  379. package/src/panel/ui/SidePanelStack.tsx +29 -36
  380. package/src/panel/ui/SpectrumColorSwatch.tsx +5 -3
  381. package/src/panel/ui/usePanelFolds.ts +103 -0
  382. package/src/shared/ui/FullscreenStage.tsx +96 -0
  383. package/src/shared/ui/canFillScreen.ts +8 -0
  384. package/src/shared/ui/index.ts +6 -0
  385. package/src/split/ui/splitPanes.tsx +4 -4
  386. package/src/structure/core/structureNotations.ts +25 -8
  387. package/src/structure/ui/StructureExportPanel.tsx +23 -4
  388. package/src/structure/ui/index.ts +4 -0
  389. package/styles/osiris.css +339 -0
@@ -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' };
@@ -1,6 +1,9 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type { ActivityBarItemProps } from 'react-science/ui';
3
- import { Accordion, AccordionProvider, Button } from 'react-science/ui';
3
+ import { Accordion, AccordionProvider } from 'react-science/ui';
4
+
5
+ import { SidePanelItem } from './SidePanelItem.tsx';
6
+ import { usePanelFolds } from './usePanelFolds.ts';
4
7
 
5
8
  /** What a rail reads about one panel, wherever that rail is drawn. */
6
9
  export interface PanelDescriptor {
@@ -44,21 +47,22 @@ export interface SidePanelStackProps<TPanel extends PanelDescriptor> {
44
47
  * They are drawn in the order the rail stacks their icons rather than the order
45
48
  * they were switched on, so a panel always comes back where it was.
46
49
  *
47
- * The header carries the shell's own two gestures and nothing about what the
48
- * panel holds: the chevron that folds it away and the cross that closes it.
49
- * What a panel switches on and off is a toolbar at the top of its own body, so
50
- * it travels with the panel when it is folded, reordered or lent to another
51
- * editor, and every header in every editor reads the same — which is the reason
52
- * this is one component rather than one per editor.
50
+ * The header carries the shell's own gestures and nothing about what the panel
51
+ * holds: focus, which folds every other panel away and unfolds them again;
52
+ * filling the screen with the panel, where the browser can; the chevron that
53
+ * folds it away; and the cross that closes it. What a panel switches on and off
54
+ * is a toolbar at the top of its own body, so it travels with the panel when it
55
+ * is folded, reordered or lent to another editor, and every header in every
56
+ * editor reads the same — which is the reason this is one component rather
57
+ * than one per editor.
53
58
  *
54
59
  * The chevron is there because nothing else says which panels are folded. The
55
60
  * accordion draws every header identically and hides only the body, so a side
56
61
  * of four closed panels and a side of four open ones differ by white space, and
57
62
  * a reader looking for a panel that is already open reaches for its icon and
58
- * closes it. It is a real button rather than a glyph because the header's own
59
- * click never reaches the toolbar — clicks there are stopped so the close cross
60
- * does not also fold the panel — so a chevron that did nothing when pressed
61
- * would be an affordance that lies.
63
+ * closes it. Focus is a button as well as a shift-click because a modifier on a
64
+ * header is a gesture nobody finds, and it undoes itself, which a shift-click
65
+ * does not.
62
66
  * @param props - Component props.
63
67
  * @returns The stack.
64
68
  */
@@ -67,41 +71,30 @@ export function SidePanelStack<TPanel extends PanelDescriptor>(
67
71
  ) {
68
72
  const { panels, openPanelIds, onClose, children } = props;
69
73
  const open = panels.filter((panel) => openPanelIds.includes(panel.id));
74
+ const folds = usePanelFolds(open.map((panel) => panel.id));
70
75
 
71
76
  return (
72
77
  <AccordionProvider>
73
78
  <Accordion>
74
79
  {open.map((panel) => (
75
- <Accordion.Item
80
+ <SidePanelItem
76
81
  key={panel.id}
77
82
  id={panel.id}
78
83
  title={panel.title}
79
- defaultOpen
80
- renderToolbar={({ isOpen, controls }) => (
81
- <>
82
- <Button
83
- variant="minimal"
84
- icon={isOpen ? 'chevron-down' : 'chevron-right'}
85
- data-panel-open={isOpen}
86
- aria-expanded={isOpen}
87
- aria-label={`${isOpen ? 'Fold' : 'Unfold'} the ${panel.title.toLowerCase()} panel`}
88
- tooltipProps={{
89
- content: isOpen ? 'Fold this panel away' : 'Unfold it',
90
- }}
91
- onClick={() => controls.toggle()}
92
- />
93
- <Button
94
- variant="minimal"
95
- icon="cross"
96
- tooltipProps={{ content: 'Close this panel' }}
97
- aria-label={`Close the ${panel.title.toLowerCase()} panel`}
98
- onClick={() => onClose(panel.id)}
99
- />
100
- </>
101
- )}
84
+ isOpen={folds.isOpen(panel.id)}
85
+ onOpenChange={(isOpen) => folds.setOpen(panel.id, isOpen)}
86
+ focus={
87
+ open.length > 1
88
+ ? {
89
+ active: folds.focused === panel.id,
90
+ toggle: () => folds.toggleFocus(panel.id),
91
+ }
92
+ : undefined
93
+ }
94
+ onClose={() => onClose(panel.id)}
102
95
  >
103
96
  {children(panel)}
104
- </Accordion.Item>
97
+ </SidePanelItem>
105
98
  ))}
106
99
  </Accordion>
107
100
  </AccordionProvider>
@@ -5,6 +5,7 @@ import {
5
5
  EXTRA_SPECTRUM_COLORS,
6
6
  SPECTRUM_COLORS,
7
7
  } from '../../chart/core/spectrumColor.ts';
8
+ import { useChromeT } from '../../i18n/ui/useT.ts';
8
9
 
9
10
  export interface SpectrumColorSwatchProps {
10
11
  /** The colour the spectrum is drawn in. */
@@ -41,6 +42,7 @@ export interface SpectrumColorSwatchProps {
41
42
  export function SpectrumColorSwatch(props: SpectrumColorSwatchProps) {
42
43
  const { color, name, onPick } = props;
43
44
  const [isOpen, setIsOpen] = useState(false);
45
+ const t = useChromeT();
44
46
 
45
47
  function offer(offered: string) {
46
48
  return (
@@ -48,7 +50,7 @@ export function SpectrumColorSwatch(props: SpectrumColorSwatchProps) {
48
50
  key={offered}
49
51
  type="button"
50
52
  title={offered}
51
- aria-label={`Draw ${name} in ${offered}`}
53
+ aria-label={t('panel.drawIn', { name, color: offered })}
52
54
  style={{
53
55
  ...(offered === color ? activeSwatchStyle : swatchStyle),
54
56
  background: offered,
@@ -78,8 +80,8 @@ export function SpectrumColorSwatch(props: SpectrumColorSwatchProps) {
78
80
  >
79
81
  <button
80
82
  type="button"
81
- title="Draw this spectrum in another colour"
82
- aria-label={`Colour of ${name}`}
83
+ title={t('panel.changeColour')}
84
+ aria-label={t('panel.colourOf', { name })}
83
85
  style={{ ...swatchStyle, background: color }}
84
86
  />
85
87
  </PopoverNext>
@@ -0,0 +1,103 @@
1
+ import { useState } from 'react';
2
+
3
+ /** Which panels of a stack are folded, and the gestures that change that. */
4
+ export interface PanelFolds {
5
+ /**
6
+ * Whether a panel shows its body.
7
+ * @param id - The panel.
8
+ * @returns False while it is folded away.
9
+ */
10
+ isOpen: (id: string) => boolean;
11
+ /**
12
+ * Fold a panel away, or unfold it.
13
+ * @param id - The panel.
14
+ * @param open - Whether it shows its body.
15
+ */
16
+ setOpen: (id: string, open: boolean) => void;
17
+ /** The one panel left unfolded among several, or null. */
18
+ focused: string | null;
19
+ /**
20
+ * Focus on a panel: unfold it and fold every other one, or, when it is
21
+ * already in focus, unfold them all again.
22
+ * @param id - The panel.
23
+ */
24
+ toggleFocus: (id: string) => void;
25
+ }
26
+
27
+ const NOTHING_FOLDED: ReadonlySet<string> = new Set();
28
+
29
+ /**
30
+ * The folds of a stack of panels, kept by the stack rather than by each panel
31
+ * so that one panel can be focused — every other one folded — and the focus
32
+ * undone.
33
+ *
34
+ * A panel closed while folded comes back unfolded when it is opened again: a
35
+ * reader reopening a panel from the rail is asking to see it.
36
+ * @param openIds - The panels in the stack, in the order they are drawn.
37
+ * @returns The folds.
38
+ */
39
+ export function usePanelFolds(openIds: readonly string[]): PanelFolds {
40
+ const [folded, setFolded] = useState(NOTHING_FOLDED);
41
+
42
+ const kept = keepOnly(folded, openIds);
43
+ if (kept !== folded) setFolded(kept);
44
+
45
+ return {
46
+ isOpen: (id) => !kept.has(id),
47
+ setOpen: (id, open) => {
48
+ setFolded((previous) => {
49
+ if (previous.has(id) !== open) return previous;
50
+ const next = new Set(previous);
51
+ if (open) next.delete(id);
52
+ else next.add(id);
53
+ return next;
54
+ });
55
+ },
56
+ focused: focusedPanel(openIds, kept),
57
+ toggleFocus: (id) => {
58
+ setFolded(
59
+ focusedPanel(openIds, kept) === id
60
+ ? NOTHING_FOLDED
61
+ : new Set(openIds.filter((other) => other !== id)),
62
+ );
63
+ },
64
+ };
65
+ }
66
+
67
+ /**
68
+ * The folds of the panels still in the stack.
69
+ * @param folded - The panels folded.
70
+ * @param openIds - The panels in the stack.
71
+ * @returns `folded` itself when every one of them is still in the stack.
72
+ */
73
+ function keepOnly(
74
+ folded: ReadonlySet<string>,
75
+ openIds: readonly string[],
76
+ ): ReadonlySet<string> {
77
+ for (const id of folded) {
78
+ if (!openIds.includes(id)) {
79
+ return new Set(openIds.filter((open) => folded.has(open)));
80
+ }
81
+ }
82
+ return folded;
83
+ }
84
+
85
+ /**
86
+ * The panel in focus: the only one unfolded, when there is another to fold.
87
+ * @param openIds - The panels in the stack.
88
+ * @param folded - The panels folded.
89
+ * @returns The panel, or null.
90
+ */
91
+ function focusedPanel(
92
+ openIds: readonly string[],
93
+ folded: ReadonlySet<string>,
94
+ ): string | null {
95
+ if (openIds.length < 2) return null;
96
+ let unfolded: string | null = null;
97
+ for (const id of openIds) {
98
+ if (folded.has(id)) continue;
99
+ if (unfolded !== null) return null;
100
+ unfolded = id;
101
+ }
102
+ return unfolded;
103
+ }