react-cheminfo 0.131.0 → 0.133.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 (293) hide show
  1. package/README.md +29 -0
  2. package/lib/core.d.ts +1 -0
  3. package/lib/core.d.ts.map +1 -1
  4. package/lib/core.js +1 -0
  5. package/lib/core.js.map +1 -1
  6. package/lib/drawing/captionEditor/CaptionEditor.d.ts +3 -3
  7. package/lib/drawing/captionEditor/CaptionEditor.d.ts.map +1 -1
  8. package/lib/drawing/captionEditor/CaptionEditor.js +8 -4
  9. package/lib/drawing/captionEditor/CaptionEditor.js.map +1 -1
  10. package/lib/drawing/captionEditor/CaptionToolbar.d.ts +4 -2
  11. package/lib/drawing/captionEditor/CaptionToolbar.d.ts.map +1 -1
  12. package/lib/drawing/captionEditor/CaptionToolbar.js +6 -4
  13. package/lib/drawing/captionEditor/CaptionToolbar.js.map +1 -1
  14. package/lib/drawing/captionEditor/index.d.ts +2 -0
  15. package/lib/drawing/captionEditor/index.d.ts.map +1 -1
  16. package/lib/drawing/captionEditor/index.js +1 -0
  17. package/lib/drawing/captionEditor/index.js.map +1 -1
  18. package/lib/drawing/captionEditor/toolbarInView.d.ts +40 -0
  19. package/lib/drawing/captionEditor/toolbarInView.d.ts.map +1 -0
  20. package/lib/drawing/captionEditor/toolbarInView.js +53 -0
  21. package/lib/drawing/captionEditor/toolbarInView.js.map +1 -0
  22. package/lib/drawing/core/camera.d.ts +2 -0
  23. package/lib/drawing/core/camera.d.ts.map +1 -1
  24. package/lib/drawing/core/camera.js +2 -0
  25. package/lib/drawing/core/camera.js.map +1 -1
  26. package/lib/drawing/core/index.d.ts +1 -1
  27. package/lib/drawing/core/index.d.ts.map +1 -1
  28. package/lib/drawing/core/index.js +1 -1
  29. package/lib/drawing/core/index.js.map +1 -1
  30. package/lib/drawing/render/index.d.ts +1 -1
  31. package/lib/drawing/render/index.d.ts.map +1 -1
  32. package/lib/drawing/render/index.js +1 -1
  33. package/lib/drawing/render/index.js.map +1 -1
  34. package/lib/drawing/render/pageGrid.d.ts +16 -0
  35. package/lib/drawing/render/pageGrid.d.ts.map +1 -1
  36. package/lib/drawing/render/pageGrid.js +28 -10
  37. package/lib/drawing/render/pageGrid.js.map +1 -1
  38. package/lib/drawing/ui/PageField.d.ts +29 -0
  39. package/lib/drawing/ui/PageField.d.ts.map +1 -0
  40. package/lib/drawing/ui/PageField.js +38 -0
  41. package/lib/drawing/ui/PageField.js.map +1 -0
  42. package/lib/drawing/ui/PageGrid.d.ts +20 -0
  43. package/lib/drawing/ui/PageGrid.d.ts.map +1 -0
  44. package/lib/drawing/ui/PageGrid.js +26 -0
  45. package/lib/drawing/ui/PageGrid.js.map +1 -0
  46. package/lib/drawing/ui/PageSideInput.d.ts +28 -0
  47. package/lib/drawing/ui/PageSideInput.d.ts.map +1 -0
  48. package/lib/drawing/ui/PageSideInput.js +47 -0
  49. package/lib/drawing/ui/PageSideInput.js.map +1 -0
  50. package/lib/drawing/ui/PageToolbar.d.ts +16 -0
  51. package/lib/drawing/ui/PageToolbar.d.ts.map +1 -0
  52. package/lib/drawing/ui/PageToolbar.js +16 -0
  53. package/lib/drawing/ui/PageToolbar.js.map +1 -0
  54. package/lib/drawing/ui/PrintSheets.d.ts +32 -0
  55. package/lib/drawing/ui/PrintSheets.d.ts.map +1 -0
  56. package/lib/drawing/ui/PrintSheets.js +17 -0
  57. package/lib/drawing/ui/PrintSheets.js.map +1 -0
  58. package/lib/drawing/ui/TextToolIcon.d.ts +19 -0
  59. package/lib/drawing/ui/TextToolIcon.d.ts.map +1 -0
  60. package/lib/drawing/ui/TextToolIcon.js +21 -0
  61. package/lib/drawing/ui/TextToolIcon.js.map +1 -0
  62. package/lib/drawing/ui/ZoomControl.d.ts +25 -0
  63. package/lib/drawing/ui/ZoomControl.d.ts.map +1 -0
  64. package/lib/drawing/ui/ZoomControl.js +27 -0
  65. package/lib/drawing/ui/ZoomControl.js.map +1 -0
  66. package/lib/drawing/ui/index.d.ts +10 -0
  67. package/lib/drawing/ui/index.d.ts.map +1 -1
  68. package/lib/drawing/ui/index.js +7 -0
  69. package/lib/drawing/ui/index.js.map +1 -1
  70. package/lib/guide/ui/EmptyGuide.d.ts +5 -2
  71. package/lib/guide/ui/EmptyGuide.d.ts.map +1 -1
  72. package/lib/guide/ui/EmptyGuide.js +8 -3
  73. package/lib/guide/ui/EmptyGuide.js.map +1 -1
  74. package/lib/guide/ui/GuideFigures.d.ts +6 -0
  75. package/lib/guide/ui/GuideFigures.d.ts.map +1 -1
  76. package/lib/guide/ui/GuideFigures.js +5 -5
  77. package/lib/guide/ui/GuideFigures.js.map +1 -1
  78. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  79. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  80. package/lib/locales/de.json +4 -0
  81. package/lib/locales/en.json +4 -0
  82. package/lib/locales/es.json +4 -0
  83. package/lib/locales/fr.json +4 -0
  84. package/lib/locales/it.json +4 -0
  85. package/lib/log/core/index.d.ts +4 -0
  86. package/lib/log/core/index.d.ts.map +1 -0
  87. package/lib/log/core/index.js +3 -0
  88. package/lib/log/core/index.js.map +1 -0
  89. package/lib/log/core/logGroups.d.ts +87 -0
  90. package/lib/log/core/logGroups.d.ts.map +1 -0
  91. package/lib/log/core/logGroups.js +85 -0
  92. package/lib/log/core/logGroups.js.map +1 -0
  93. package/lib/log/core/logLines.d.ts +19 -0
  94. package/lib/log/core/logLines.d.ts.map +1 -0
  95. package/lib/log/core/logLines.js +36 -0
  96. package/lib/log/core/logLines.js.map +1 -0
  97. package/lib/log/ui/LogBadge.d.ts +39 -0
  98. package/lib/log/ui/LogBadge.d.ts.map +1 -0
  99. package/lib/log/ui/LogBadge.js +28 -0
  100. package/lib/log/ui/LogBadge.js.map +1 -0
  101. package/lib/log/ui/LogCallouts.d.ts +55 -0
  102. package/lib/log/ui/LogCallouts.d.ts.map +1 -0
  103. package/lib/log/ui/LogCallouts.js +38 -0
  104. package/lib/log/ui/LogCallouts.js.map +1 -0
  105. package/lib/log/ui/index.d.ts +7 -0
  106. package/lib/log/ui/index.d.ts.map +1 -0
  107. package/lib/log/ui/index.js +5 -0
  108. package/lib/log/ui/index.js.map +1 -0
  109. package/lib/log/ui/logIcon.d.ts +9 -0
  110. package/lib/log/ui/logIcon.d.ts.map +1 -0
  111. package/lib/log/ui/logIcon.js +17 -0
  112. package/lib/log/ui/logIcon.js.map +1 -0
  113. package/lib/log/ui/useLogEntries.d.ts +15 -0
  114. package/lib/log/ui/useLogEntries.d.ts.map +1 -0
  115. package/lib/log/ui/useLogEntries.js +47 -0
  116. package/lib/log/ui/useLogEntries.js.map +1 -0
  117. package/lib/mass/core/index.d.ts +1 -0
  118. package/lib/mass/core/index.d.ts.map +1 -1
  119. package/lib/mass/core/index.js +1 -0
  120. package/lib/mass/core/index.js.map +1 -1
  121. package/lib/mass/core/massDomain.d.ts.map +1 -1
  122. package/lib/mass/core/massDomain.js +9 -5
  123. package/lib/mass/core/massDomain.js.map +1 -1
  124. package/lib/mass/core/massSpectrum.d.ts +9 -0
  125. package/lib/mass/core/massSpectrum.d.ts.map +1 -1
  126. package/lib/mass/core/massSpectrum.js.map +1 -1
  127. package/lib/mass/core/verticalScale.d.ts +30 -0
  128. package/lib/mass/core/verticalScale.d.ts.map +1 -0
  129. package/lib/mass/core/verticalScale.js +40 -0
  130. package/lib/mass/core/verticalScale.js.map +1 -0
  131. package/lib/mass/ui/MassChart.d.ts.map +1 -1
  132. package/lib/mass/ui/MassChart.js +4 -38
  133. package/lib/mass/ui/MassChart.js.map +1 -1
  134. package/lib/mass/ui/massChartLayers.d.ts +31 -0
  135. package/lib/mass/ui/massChartLayers.d.ts.map +1 -0
  136. package/lib/mass/ui/massChartLayers.js +57 -0
  137. package/lib/mass/ui/massChartLayers.js.map +1 -0
  138. package/lib/structure/core/conformerMinimise.d.ts +13 -4
  139. package/lib/structure/core/conformerMinimise.d.ts.map +1 -1
  140. package/lib/structure/core/conformerMinimise.js +23 -6
  141. package/lib/structure/core/conformerMinimise.js.map +1 -1
  142. package/lib/structure/core/conformerRefine.d.ts +2 -2
  143. package/lib/structure/core/conformerRefine.d.ts.map +1 -1
  144. package/lib/structure/core/conformerRefine.js +23 -7
  145. package/lib/structure/core/conformerRefine.js.map +1 -1
  146. package/lib/structure/core/conformers.d.ts +8 -3
  147. package/lib/structure/core/conformers.d.ts.map +1 -1
  148. package/lib/structure/core/conformers.js +10 -7
  149. package/lib/structure/core/conformers.js.map +1 -1
  150. package/lib/structure/core/geometryRelaxer.d.ts +10 -3
  151. package/lib/structure/core/geometryRelaxer.d.ts.map +1 -1
  152. package/lib/structure/core/index.d.ts +1 -1
  153. package/lib/structure/core/index.d.ts.map +1 -1
  154. package/lib/structure/core/index.js.map +1 -1
  155. package/lib/structure/core/relaxerLogLines.d.ts +16 -0
  156. package/lib/structure/core/relaxerLogLines.d.ts.map +1 -0
  157. package/lib/structure/core/relaxerLogLines.js +33 -0
  158. package/lib/structure/core/relaxerLogLines.js.map +1 -0
  159. package/lib/structure/core/structurePicture.d.ts +32 -1
  160. package/lib/structure/core/structurePicture.d.ts.map +1 -1
  161. package/lib/structure/core/structurePicture.js +29 -2
  162. package/lib/structure/core/structurePicture.js.map +1 -1
  163. package/lib/structure/ui/StructureEditor.d.ts +2 -1
  164. package/lib/structure/ui/StructureEditor.d.ts.map +1 -1
  165. package/lib/structure/ui/StructureEditor.js +9 -3
  166. package/lib/structure/ui/StructureEditor.js.map +1 -1
  167. package/lib/structure/ui/StructureEditorGuide.d.ts +15 -0
  168. package/lib/structure/ui/StructureEditorGuide.d.ts.map +1 -0
  169. package/lib/structure/ui/StructureEditorGuide.js +26 -0
  170. package/lib/structure/ui/StructureEditorGuide.js.map +1 -0
  171. package/lib/structure/ui/structureEditorProps.d.ts +11 -1
  172. package/lib/structure/ui/structureEditorProps.d.ts.map +1 -1
  173. package/lib/structure/ui/useCanvasPress.d.ts +23 -0
  174. package/lib/structure/ui/useCanvasPress.d.ts.map +1 -0
  175. package/lib/structure/ui/useCanvasPress.js +53 -0
  176. package/lib/structure/ui/useCanvasPress.js.map +1 -0
  177. package/lib/ui.d.ts +1 -0
  178. package/lib/ui.d.ts.map +1 -1
  179. package/lib/ui.js +1 -0
  180. package/lib/ui.js.map +1 -1
  181. package/lib/xps/core/detectFormat.d.ts +6 -0
  182. package/lib/xps/core/detectFormat.d.ts.map +1 -1
  183. package/lib/xps/core/detectFormat.js +8 -0
  184. package/lib/xps/core/detectFormat.js.map +1 -1
  185. package/lib/xps/core/xpsEditorApi.d.ts +16 -0
  186. package/lib/xps/core/xpsEditorApi.d.ts.map +1 -1
  187. package/lib/xps/ui/XpsCanvas.d.ts +10 -1
  188. package/lib/xps/ui/XpsCanvas.d.ts.map +1 -1
  189. package/lib/xps/ui/XpsCanvas.js +14 -3
  190. package/lib/xps/ui/XpsCanvas.js.map +1 -1
  191. package/lib/xps/ui/XpsChart.d.ts.map +1 -1
  192. package/lib/xps/ui/XpsChart.js +12 -43
  193. package/lib/xps/ui/XpsChart.js.map +1 -1
  194. package/lib/xps/ui/XpsEditor.d.ts +8 -0
  195. package/lib/xps/ui/XpsEditor.d.ts.map +1 -1
  196. package/lib/xps/ui/XpsEditor.js +2 -2
  197. package/lib/xps/ui/XpsEditor.js.map +1 -1
  198. package/lib/xps/ui/XpsShell.d.ts +5 -0
  199. package/lib/xps/ui/XpsShell.d.ts.map +1 -1
  200. package/lib/xps/ui/XpsShell.js +18 -4
  201. package/lib/xps/ui/XpsShell.js.map +1 -1
  202. package/lib/xps/ui/dropEvents.d.ts +8 -1
  203. package/lib/xps/ui/dropEvents.d.ts.map +1 -1
  204. package/lib/xps/ui/dropEvents.js +15 -1
  205. package/lib/xps/ui/dropEvents.js.map +1 -1
  206. package/lib/xps/ui/useSpectrumDrop.d.ts +6 -0
  207. package/lib/xps/ui/useSpectrumDrop.d.ts.map +1 -1
  208. package/lib/xps/ui/useSpectrumDrop.js +1 -1
  209. package/lib/xps/ui/useSpectrumDrop.js.map +1 -1
  210. package/lib/xps/ui/useXpsEditorHandle.d.ts +4 -1
  211. package/lib/xps/ui/useXpsEditorHandle.d.ts.map +1 -1
  212. package/lib/xps/ui/useXpsEditorHandle.js +6 -2
  213. package/lib/xps/ui/useXpsEditorHandle.js.map +1 -1
  214. package/lib/xps/ui/useXpsReadout.d.ts +43 -0
  215. package/lib/xps/ui/useXpsReadout.d.ts.map +1 -0
  216. package/lib/xps/ui/useXpsReadout.js +59 -0
  217. package/lib/xps/ui/useXpsReadout.js.map +1 -0
  218. package/lib/xps/ui/xpsChartProps.d.ts +9 -0
  219. package/lib/xps/ui/xpsChartProps.d.ts.map +1 -1
  220. package/lib/xtb/core/taggedLogger.d.ts +11 -0
  221. package/lib/xtb/core/taggedLogger.d.ts.map +1 -0
  222. package/lib/xtb/core/taggedLogger.js +31 -0
  223. package/lib/xtb/core/taggedLogger.js.map +1 -0
  224. package/lib/xtb/core/xtbRelaxer.d.ts.map +1 -1
  225. package/lib/xtb/core/xtbRelaxer.js +13 -5
  226. package/lib/xtb/core/xtbRelaxer.js.map +1 -1
  227. package/package.json +4 -3
  228. package/src/core.ts +1 -0
  229. package/src/drawing/captionEditor/CaptionEditor.tsx +8 -3
  230. package/src/drawing/captionEditor/CaptionToolbar.tsx +18 -2
  231. package/src/drawing/captionEditor/index.ts +2 -0
  232. package/src/drawing/captionEditor/toolbarInView.ts +73 -0
  233. package/src/drawing/core/camera.ts +3 -0
  234. package/src/drawing/core/index.ts +1 -0
  235. package/src/drawing/render/index.ts +2 -0
  236. package/src/drawing/render/pageGrid.ts +29 -11
  237. package/src/drawing/ui/PageField.tsx +104 -0
  238. package/src/drawing/ui/PageGrid.tsx +48 -0
  239. package/src/drawing/ui/PageSideInput.tsx +81 -0
  240. package/src/drawing/ui/PageToolbar.tsx +45 -0
  241. package/src/drawing/ui/PrintSheets.tsx +57 -0
  242. package/src/drawing/ui/TextToolIcon.tsx +48 -0
  243. package/src/drawing/ui/ZoomControl.tsx +112 -0
  244. package/src/drawing/ui/index.ts +10 -0
  245. package/src/guide/ui/EmptyGuide.tsx +20 -13
  246. package/src/guide/ui/GuideFigures.tsx +15 -4
  247. package/src/locales/de.json +4 -0
  248. package/src/locales/en.json +4 -0
  249. package/src/locales/es.json +4 -0
  250. package/src/locales/fr.json +4 -0
  251. package/src/locales/it.json +4 -0
  252. package/src/log/core/index.ts +9 -0
  253. package/src/log/core/logGroups.ts +159 -0
  254. package/src/log/core/logLines.ts +44 -0
  255. package/src/log/ui/LogBadge.tsx +89 -0
  256. package/src/log/ui/LogCallouts.tsx +103 -0
  257. package/src/log/ui/index.ts +6 -0
  258. package/src/log/ui/logIcon.ts +21 -0
  259. package/src/log/ui/useLogEntries.ts +57 -0
  260. package/src/mass/core/index.ts +1 -0
  261. package/src/mass/core/massDomain.ts +9 -3
  262. package/src/mass/core/massSpectrum.ts +9 -0
  263. package/src/mass/core/verticalScale.ts +48 -0
  264. package/src/mass/ui/MassChart.tsx +12 -43
  265. package/src/mass/ui/massChartLayers.ts +66 -0
  266. package/src/structure/core/conformerMinimise.ts +34 -8
  267. package/src/structure/core/conformerRefine.ts +29 -13
  268. package/src/structure/core/conformers.ts +23 -12
  269. package/src/structure/core/geometryRelaxer.ts +11 -3
  270. package/src/structure/core/index.ts +1 -0
  271. package/src/structure/core/relaxerLogLines.ts +39 -0
  272. package/src/structure/core/structurePicture.ts +78 -4
  273. package/src/structure/ui/StructureEditor.tsx +13 -2
  274. package/src/structure/ui/StructureEditorGuide.tsx +35 -0
  275. package/src/structure/ui/structureEditorProps.ts +11 -1
  276. package/src/structure/ui/useCanvasPress.ts +69 -0
  277. package/src/ui.ts +1 -0
  278. package/src/xps/core/detectFormat.ts +9 -0
  279. package/src/xps/core/xpsEditorApi.ts +16 -0
  280. package/src/xps/ui/XpsCanvas.tsx +26 -3
  281. package/src/xps/ui/XpsChart.tsx +12 -56
  282. package/src/xps/ui/XpsEditor.tsx +10 -0
  283. package/src/xps/ui/XpsShell.tsx +37 -7
  284. package/src/xps/ui/dropEvents.ts +16 -1
  285. package/src/xps/ui/useSpectrumDrop.ts +7 -1
  286. package/src/xps/ui/useXpsEditorHandle.ts +12 -2
  287. package/src/xps/ui/useXpsReadout.ts +104 -0
  288. package/src/xps/ui/xpsChartProps.ts +9 -0
  289. package/src/xtb/core/taggedLogger.ts +35 -0
  290. package/src/xtb/core/xtbRelaxer.ts +15 -5
  291. package/styles/caption-editor.css +15 -1
  292. package/styles/chrome.css +164 -9
  293. package/styles/drawing.css +100 -0
@@ -0,0 +1,59 @@
1
+ /**
2
+ * What the pointer reads off the XPS chart, and what of it the rest of the
3
+ * viewer hears: the crosshair follows every pixel, the viewer only the peak.
4
+ */
5
+ import { useCallback, useRef } from 'react';
6
+ import { chartValue } from "../../chart/core/chartScale.js";
7
+ import { useChartPointer } from "../../chart/ui/useChartPointer.js";
8
+ import { nearestPeakEnergy, sameNearestPeak } from "../core/nearestPeak.js";
9
+ import { NO_HIGHLIGHT } from "../core/xpsHighlight.js";
10
+ /**
11
+ * Follow the pointer over the chart, and tell the viewer which peak it is on.
12
+ *
13
+ * Only a change of peak is reported, starting from none: the pointer coming
14
+ * onto the plot over no peak says nothing, so a guide a panel put on the chart
15
+ * stays until the pointer actually reaches a peak.
16
+ * @param options - See {@link XpsReadoutOptions}.
17
+ * @returns Where the pointer is and what it reads.
18
+ */
19
+ export function useXpsReadout(options) {
20
+ const { svgRef, plot, spectra, axis, xScale, yScale, onHighlightChange } = options;
21
+ const read = useCallback((point) => ({
22
+ energy: chartValue(xScale, point.x),
23
+ counts: chartValue(yScale, point.y),
24
+ peak: nearestPeakEnergy(spectra, axis, xScale, point.x),
25
+ }), [xScale, yScale, spectra, axis]);
26
+ const reportedPeak = useRef(null);
27
+ const onReadout = useCallback((readout) => {
28
+ const found = readout?.peak ?? null;
29
+ if (sameNearestPeak(reportedPeak.current, found))
30
+ return;
31
+ reportedPeak.current = found;
32
+ onHighlightChange?.(found === null
33
+ ? NO_HIGHLIGHT
34
+ : {
35
+ spectrumId: found.spectrumId,
36
+ peakId: found.peak.id,
37
+ componentId: null,
38
+ bindingEnergy: found.peak.bindingEnergy,
39
+ });
40
+ }, [onHighlightChange]);
41
+ return useChartPointer({
42
+ svgRef,
43
+ plot,
44
+ read,
45
+ sameReadout: samePeakReadout,
46
+ onReadout,
47
+ });
48
+ }
49
+ /**
50
+ * Whether two readings are about the same peak, which is all the rest of the
51
+ * viewer hears about: the energy under the crosshair changes on every pixel.
52
+ * @param current - The reading last reported.
53
+ * @param next - The reading now.
54
+ * @returns Whether nothing needs reporting.
55
+ */
56
+ function samePeakReadout(current, next) {
57
+ return sameNearestPeak(current.peak, next.peak);
58
+ }
59
+ //# sourceMappingURL=useXpsReadout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useXpsReadout.js","sourceRoot":"","sources":["../../../src/xps/ui/useXpsReadout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAI5C,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AA2BvD;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC3B,OAA0B;IAE1B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,GACtE,OAAO,CAAC;IACV,MAAM,IAAI,GAAG,WAAW,CACtB,CAAC,KAAiB,EAAc,EAAE,CAAC,CAAC;QAClC,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QACnC,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QACnC,IAAI,EAAE,iBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;KACxD,CAAC,EACF,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAChC,CAAC;IACF,MAAM,YAAY,GAAG,MAAM,CAAqB,IAAI,CAAC,CAAC;IACtD,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,OAA0B,EAAE,EAAE;QAC7B,MAAM,KAAK,GAAG,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC;QACpC,IAAI,eAAe,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC;YAAE,OAAO;QACzD,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;QAC7B,iBAAiB,EAAE,CACjB,KAAK,KAAK,IAAI;YACZ,CAAC,CAAC,YAAY;YACd,CAAC,CAAC;gBACE,UAAU,EAAE,KAAK,CAAC,UAAU;gBAC5B,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE;gBACrB,WAAW,EAAE,IAAI;gBACjB,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,aAAa;aACxC,CACN,CAAC;IACJ,CAAC,EACD,CAAC,iBAAiB,CAAC,CACpB,CAAC;IACF,OAAO,eAAe,CAAa;QACjC,MAAM;QACN,IAAI;QACJ,IAAI;QACJ,WAAW,EAAE,eAAe;QAC5B,SAAS;KACV,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,OAAmB,EAAE,IAAgB;IAC5D,OAAO,eAAe,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC"}
@@ -11,6 +11,7 @@
11
11
  * serves the editor, a report page that only ever draws one spectrum, and a
12
12
  * test.
13
13
  */
14
+ import type { ChartSize } from '../../chart/core/chartGeometry.ts';
14
15
  import type { XpsHighlight } from '../core/xpsHighlight.ts';
15
16
  import type { XpsDomain, XpsRegion, XpsSpectrum } from '../core/xpsSpectrum.ts';
16
17
  import type { XpsSettings } from '../core/xpsState.ts';
@@ -64,6 +65,14 @@ export interface XpsChartProps {
64
65
  * @default false
65
66
  */
66
67
  isReading?: boolean;
68
+ /**
69
+ * The size to draw at, in CSS pixels, instead of the box the chart is put in
70
+ * — for a chart drawn where nothing is laid out, as a figure written to a
71
+ * file by `renderToStaticMarkup`, which would otherwise come out at the
72
+ * smallest plot there is.
73
+ * @default undefined — the box the chart is put in, measured
74
+ */
75
+ size?: ChartSize;
67
76
  }
68
77
  /** Windows shaded on the chart for one spectrum, beside the ones its file defines. */
69
78
  export interface XpsChartWindows {
@@ -1 +1 @@
1
- {"version":3,"file":"xpsChartProps.d.ts","sourceRoot":"","sources":["../../../src/xps/ui/xpsChartProps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B,0DAA0D;IAC1D,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;IAChC,0BAA0B;IAC1B,QAAQ,EAAE,WAAW,CAAC;IACtB,+CAA+C;IAC/C,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B;;;OAGG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,uEAAuE;IACvE,cAAc,EAAE,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAC;IACnD;;;OAGG;IACH,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,YAAY,KAAK,IAAI,CAAC;IACtD;;;OAGG;IACH,YAAY,CAA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IACH,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,YAAY,KAAK,IAAI,CAAC;IACtD;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACtD;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC;;;;OAIG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,sFAAsF;AACtF,MAAM,WAAW,eAAe;IAC9B,8EAA8E;IAC9E,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,iEAAiE;IACjE,OAAO,EAAE,SAAS,SAAS,EAAE,CAAC;CAC/B"}
@@ -0,0 +1,11 @@
1
+ import type { LightLogger } from 'cheminfo-types';
2
+ /**
3
+ * A logger that adds some fields to every entry before passing it on — what
4
+ * xtb-wasm's pool does for the structures of a batch, done here for the ones
5
+ * relaxed in turn on this thread.
6
+ * @param logger - Where the entries go.
7
+ * @param context - The fields every entry gains, e.g. `{ structure: 2 }`.
8
+ * @returns The tagging logger.
9
+ */
10
+ export declare function taggedLogger(logger: LightLogger, context: Record<string, unknown>): LightLogger;
11
+ //# sourceMappingURL=taggedLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taggedLogger.d.ts","sourceRoot":"","sources":["../../../src/xtb/core/taggedLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,WAAW,CAmBb"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * A logger that adds some fields to every entry before passing it on — what
3
+ * xtb-wasm's pool does for the structures of a batch, done here for the ones
4
+ * relaxed in turn on this thread.
5
+ * @param logger - Where the entries go.
6
+ * @param context - The fields every entry gains, e.g. `{ structure: 2 }`.
7
+ * @returns The tagging logger.
8
+ */
9
+ export function taggedLogger(logger, context) {
10
+ function forward(level) {
11
+ return (value, message) => {
12
+ if (value instanceof Error) {
13
+ logger[level](context, message ?? value.message);
14
+ }
15
+ else if (typeof value === 'object' && value !== null) {
16
+ logger[level]({ ...context, ...value }, message ?? '');
17
+ }
18
+ else {
19
+ logger[level](context, message ?? String(value));
20
+ }
21
+ };
22
+ }
23
+ return {
24
+ trace: forward('trace'),
25
+ debug: forward('debug'),
26
+ info: forward('info'),
27
+ warn: forward('warn'),
28
+ error: forward('error'),
29
+ };
30
+ }
31
+ //# sourceMappingURL=taggedLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taggedLogger.js","sourceRoot":"","sources":["../../../src/xtb/core/taggedLogger.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAmB,EACnB,OAAgC;IAEhC,SAAS,OAAO,CAAC,KAAY;QAC3B,OAAO,CAAC,KAAc,EAAE,OAAgB,EAAQ,EAAE;YAChD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;gBAC3B,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;YACnD,CAAC;iBAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACvD,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;YACzD,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACnD,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IACD,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;QACvB,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;QACvB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;QACrB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;QACrB,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;KACxB,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"xtbRelaxer.d.ts","sourceRoot":"","sources":["../../../src/xtb/core/xtbRelaxer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,yCAAyC,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,iBAAoB,CAAC;AAE1D,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,eAAe,CAqC3E;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAGvD"}
1
+ {"version":3,"file":"xtbRelaxer.d.ts","sourceRoot":"","sources":["../../../src/xtb/core/xtbRelaxer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,yCAAyC,CAAC;AAIjD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,iBAAoB,CAAC;AAE1D,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,eAAe,CAqC3E;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAGvD"}
@@ -1,4 +1,5 @@
1
1
  import { errorMessage } from "../../error/core/toError.js";
2
+ import { taggedLogger } from "./taggedLogger.js";
2
3
  /**
3
4
  * kcal/mol per hartree, CODATA 2018. Every energy a relaxer reports is in
4
5
  * kcal/mol, so it can be read against a force-field energy without the reader
@@ -35,6 +36,7 @@ export function xtbRelaxer(options = {}) {
35
36
  maxWorkers: options.maxWorkers,
36
37
  onSettled: runOptions.onSettled,
37
38
  signal: runOptions.signal,
39
+ logger: runOptions.logger,
38
40
  })
39
41
  : await relaxHere(xtb, requests, runOptions);
40
42
  const relaxed = [];
@@ -47,7 +49,6 @@ export function xtbRelaxer(options = {}) {
47
49
  : result.energy.dispersion * KCAL_PER_MOL_PER_HARTREE,
48
50
  cycles: result.cycles,
49
51
  converged: result.converged,
50
- warnings: result.warnings,
51
52
  });
52
53
  }
53
54
  return relaxed;
@@ -76,20 +77,27 @@ export async function disposeXtbRelaxer() {
76
77
  * Relax one structure after another on this thread, for want of a pool.
77
78
  * @param xtb - The loaded `xtb-wasm` module.
78
79
  * @param requests - The structures to relax, with their settings.
79
- * @param runOptions - Progress and cancellation.
80
+ * @param runOptions - Progress, cancellation, and the logger each structure's
81
+ * messages go to under its index, as the pool would have logged them.
80
82
  * @returns One `xtb-wasm` result per request, in request order.
81
83
  * @throws {Error} When the run is cancelled, or when occ fails.
82
84
  */
83
85
  async function relaxHere(xtb, requests, runOptions) {
86
+ const { logger, signal, onSettled } = runOptions;
84
87
  const results = [];
85
88
  for (const [index, request] of requests.entries()) {
86
- if (runOptions.signal?.aborted === true) {
89
+ if (signal?.aborted === true) {
87
90
  throw new Error('calculation cancelled');
88
91
  }
92
+ const options = {
93
+ logger: logger === undefined
94
+ ? undefined
95
+ : taggedLogger(logger, { structure: index }),
96
+ };
89
97
  /* eslint-disable-next-line no-await-in-loop -- there is one thread: the
90
98
  whole point of this path is that the structures run in turn. */
91
- results.push(await xtb.relaxGeometryInProcess(request));
92
- runOptions.onSettled?.(index + 1, requests.length);
99
+ results.push(await xtb.relaxGeometryInProcess(request, options));
100
+ onSettled?.(index + 1, requests.length);
93
101
  }
94
102
  return results;
95
103
  }
@@ -1 +1 @@
1
- {"version":3,"file":"xtbRelaxer.js","sourceRoot":"","sources":["../../../src/xtb/core/xtbRelaxer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAQ3D;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,iBAAiB,CAAC;AA2B1D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CAAC,UAA6B,EAAE;IACxD,OAAO,KAAK,EACV,UAAwC,EACxC,aAA6B,EAAE,EACH,EAAE;QAC9B,MAAM,GAAG,GAAG,MAAM,OAAO,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG;YACf,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC;YAC3B,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,CAAC;YACjD,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS;gBACjC,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,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EAAE,CAAC,KAAK,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAID,IAAI,OAAO,GAA8B,IAAI,CAAC;AAE9C,SAAS,OAAO;IACd,OAAO,KAAK,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACtD,uEAAuE;QACvE,OAAO,GAAG,IAAI,CAAC;QACf,2EAA2E;QAC3E,2EAA2E;QAC3E,iEAAiE;QACjE,MAAM,IAAI,KAAK,CACb,kEAAkE,YAAY,CAAC,KAAK,CAAC,EAAE,EACvF,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cheminfo",
3
- "version": "0.131.0",
3
+ "version": "0.133.0",
4
4
  "license": "MIT",
5
5
  "description": "React components, hooks and framework-free helpers shared by the cheminfo sites: site chrome, citations, sharing, routing, pedagogy, charts, and the structure, orbital and 3D molecule viewers",
6
6
  "author": "Luc Patiny",
@@ -91,6 +91,7 @@
91
91
  "countries-and-timezones": "^3.11.0",
92
92
  "crc-32": "^1.2.2",
93
93
  "fast-deep-equal": "^3.1.3",
94
+ "fifo-logger": "^2.0.1",
94
95
  "idb": "^8.0.4",
95
96
  "intl-messageformat": "^11.2.15",
96
97
  "ir-spectrum": "^4.2.0",
@@ -164,7 +165,7 @@
164
165
  "typescript": "^6.0.3",
165
166
  "vite": "^8.2.1",
166
167
  "vitest": "^4.1.12",
167
- "xtb-wasm": "^1.1.1"
168
+ "xtb-wasm": "^2.0.0"
168
169
  },
169
170
  "peerDependencies": {
170
171
  "@blueprintjs/core": "^6.18.0",
@@ -182,7 +183,7 @@
182
183
  "react-science": "^20.6.2 || ^21.0.0 || ^22.0.0 || ^23.0.0 || ^24.0.0",
183
184
  "spectra-processor": "^5.0.0",
184
185
  "vite": "^7.0.0 || ^8.0.0",
185
- "xtb-wasm": "^1.1.1"
186
+ "xtb-wasm": "^2.0.0"
186
187
  },
187
188
  "repository": {
188
189
  "type": "git",
package/src/core.ts CHANGED
@@ -18,6 +18,7 @@ export * from './format/core/index.ts';
18
18
  export * from './highlight/core/index.ts';
19
19
  export * from './i18n/core/index.ts';
20
20
  export * from './language/core/index.ts';
21
+ export * from './log/core/index.ts';
21
22
  export * from './moleculesClient/core/index.ts';
22
23
  export * from './moleculesSources/core/index.ts';
23
24
  export * from './moleculesToken/core/index.ts';
@@ -14,15 +14,16 @@ import { captionKeys, captionSelectionStyle } from './captionCommands.ts';
14
14
  import type { CaptionEditorProps } from './captionEditorProps.ts';
15
15
  import { captionPreview, setCaptionChemical } from './captionPreview.ts';
16
16
  import { captionDocument, captionText } from './captionSchema.ts';
17
+ import { useToolbarInView } from './toolbarInView.ts';
17
18
 
18
19
  /**
19
20
  * The box a caption is typed in, laid over a drawing where the caption goes,
20
21
  * in its font and size, with what it will look like: bold, italic, scripts,
21
22
  * sizes, and the digits and charges the chemical rules set. Its toolbar also
22
23
  * turns those rules off, and sets the font and the alignment. It opens
23
- * focused with everything selected; ⌘Enter or a click elsewhere keeps it,
24
- * Enter starts a line, Escape drops the change. A caption aligned anew keeps
25
- * its place on screen. `react-cheminfo/styles/caption-editor.css` draws it.
24
+ * focused with everything selected; the tick, ⌘Enter or a click elsewhere
25
+ * keeps it, Enter starts a line, Escape drops the change. A caption aligned
26
+ * anew keeps its place on screen. `react-cheminfo/styles/caption-editor.css` draws it.
26
27
  * @param props - The caption, and where it is laid.
27
28
  * @returns The box and its toolbar.
28
29
  */
@@ -40,6 +41,7 @@ export function CaptionEditor(props: CaptionEditorProps): ReactElement {
40
41
  const host = useRef<HTMLDivElement>(null);
41
42
  const view = useRef<EditorView | null>(null);
42
43
  const closed = useRef(false);
44
+ useToolbarInView(frame);
43
45
  // Seeded once: what is typed never comes back into the box as a new state.
44
46
  const [opened] = useState(() => {
45
47
  const plugins = captionKeys(base);
@@ -192,6 +194,9 @@ export function CaptionEditor(props: CaptionEditorProps): ReactElement {
192
194
  onChemical={setChemical}
193
195
  onAlign={realign}
194
196
  onFamily={setFamily}
197
+ onDone={() => {
198
+ close(true);
199
+ }}
195
200
  />
196
201
  <div
197
202
  ref={host}
@@ -83,13 +83,15 @@ export interface CaptionToolbarProps {
83
83
  onAlign: (align: TextAlign) => void;
84
84
  /** Set the caption in another font. */
85
85
  onFamily: (family: string) => void;
86
+ /** Keep the caption and close its box, as ⌘Enter does. */
87
+ onDone: () => void;
86
88
  }
87
89
 
88
90
  /**
89
91
  * The styles of a caption being typed, over the box it is typed in: bold,
90
92
  * italic, subscript, superscript and the size of the selection, then the
91
- * automatic formulas, the font and the alignment of the whole caption. Its
92
- * buttons leave the keys with the text.
93
+ * automatic formulas, the font and the alignment of the whole caption, and
94
+ * last the tick that keeps it. Its buttons leave the keys with the text.
93
95
  * @param props - The styles of the selection, and how to change them.
94
96
  * @returns The toolbar.
95
97
  */
@@ -105,6 +107,7 @@ export function CaptionToolbar(props: CaptionToolbarProps): ReactElement {
105
107
  onChemical,
106
108
  onAlign,
107
109
  onFamily,
110
+ onDone,
108
111
  } = props;
109
112
  return (
110
113
  <div
@@ -207,6 +210,19 @@ export function CaptionToolbar(props: CaptionToolbarProps): ReactElement {
207
210
  />
208
211
  ))}
209
212
  </ButtonGroup>
213
+ <Button
214
+ className="caption-toolbar__done"
215
+ size="small"
216
+ variant="minimal"
217
+ intent="primary"
218
+ icon="tick"
219
+ aria-label="Done"
220
+ title={`Done (${shortcutText([MOD_KEY, 'Enter'])}, or click elsewhere). Escape drops the change.`}
221
+ onMouseDown={(event) => {
222
+ event.preventDefault();
223
+ }}
224
+ onClick={onDone}
225
+ />
210
226
  </div>
211
227
  );
212
228
  }
@@ -20,3 +20,5 @@ export {
20
20
  } from './captionSchema.ts';
21
21
  export type { CaptionToolbarProps } from './CaptionToolbar.tsx';
22
22
  export { CaptionToolbar } from './CaptionToolbar.tsx';
23
+ export type { ToolbarFit } from './toolbarInView.ts';
24
+ export { toolbarFit, useToolbarInView } from './toolbarInView.ts';
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Keeping a caption's toolbar inside the area it is drawn over: the bar is
3
+ * centred over its caption, so a caption near an edge would leave part of the
4
+ * bar — its first buttons, or the tick that keeps the caption — outside a
5
+ * figure that clips what overflows it.
6
+ */
7
+
8
+ import type { RefObject } from 'react';
9
+ import { useLayoutEffect } from 'react';
10
+
11
+ /** How far the bar keeps from the area's edges, in pixels. */
12
+ const TOOLBAR_INSET = 4;
13
+
14
+ /** A box on screen, as `getBoundingClientRect` gives it. */
15
+ interface ScreenBox {
16
+ left: number;
17
+ right: number;
18
+ top: number;
19
+ }
20
+
21
+ /** Where a caption's toolbar is moved to stay in view. */
22
+ export interface ToolbarFit {
23
+ /** How far it is moved sideways, in pixels: positive to the right. */
24
+ shift: number;
25
+ /** Whether it goes under the caption, the area having no room above. */
26
+ below: boolean;
27
+ }
28
+
29
+ /**
30
+ * Where a toolbar centred over its caption goes to stay inside an area: moved
31
+ * sideways no more than it overflows, its left edge kept in view first, and
32
+ * under the caption when it would rise above the area.
33
+ * @param bar - The toolbar where it is centred.
34
+ * @param area - The area it must stay in.
35
+ * @returns The move.
36
+ */
37
+ export function toolbarFit(bar: ScreenBox, area: ScreenBox): ToolbarFit {
38
+ let shift = 0;
39
+ if (bar.right > area.right - TOOLBAR_INSET) {
40
+ shift = area.right - TOOLBAR_INSET - bar.right;
41
+ }
42
+ if (bar.left + shift < area.left + TOOLBAR_INSET) {
43
+ shift = area.left + TOOLBAR_INSET - bar.left;
44
+ }
45
+ return { shift, below: bar.top < area.top + TOOLBAR_INSET };
46
+ }
47
+
48
+ /**
49
+ * Keep the toolbar of a caption being typed inside the box the caption is
50
+ * laid over (its offset parent), after every render: moved sideways through
51
+ * `--caption-toolbar-shift`, and under the caption with `data-below`.
52
+ * `react-cheminfo/styles/caption-editor.css` reads both.
53
+ * @param ref - The caption editor's frame (`.caption-editor`), or any element
54
+ * inside it, such as the box the text is typed in.
55
+ */
56
+ export function useToolbarInView(ref: RefObject<HTMLElement | null>): void {
57
+ useLayoutEffect(() => {
58
+ const frame = ref.current?.closest<HTMLElement>('.caption-editor');
59
+ const toolbar = frame?.querySelector<HTMLElement>('.caption-toolbar');
60
+ const area = frame?.offsetParent;
61
+ if (!toolbar || !area) return;
62
+ toolbar.style.removeProperty('--caption-toolbar-shift');
63
+ delete toolbar.dataset.below;
64
+ const { shift, below } = toolbarFit(
65
+ toolbar.getBoundingClientRect(),
66
+ area.getBoundingClientRect(),
67
+ );
68
+ if (shift !== 0) {
69
+ toolbar.style.setProperty('--caption-toolbar-shift', `${shift}px`);
70
+ }
71
+ if (below) toolbar.dataset.below = '';
72
+ });
73
+ }
@@ -27,6 +27,9 @@ export const ZOOM_PRESETS: readonly number[] = [
27
27
  0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4, 8, 16,
28
28
  ];
29
29
 
30
+ /** How much one press of `+` zooms in, and of `-` zooms out. */
31
+ export const ZOOM_STEP = 1.25;
32
+
30
33
  /** How close the view starts on an empty page: a bond is 36 px long. */
31
34
  export const START_CAMERA: Camera = { x: 0, y: 0, zoom: 2.5 };
32
35
 
@@ -6,6 +6,7 @@ export {
6
6
  START_CAMERA,
7
7
  ZOOM_PRESETS,
8
8
  ZOOM_RANGE,
9
+ ZOOM_STEP,
9
10
  fillCamera,
10
11
  frameCamera,
11
12
  pannedCamera,
@@ -73,10 +73,12 @@ export {
73
73
  } from './motion.ts';
74
74
  export {
75
75
  MAX_SHEETS,
76
+ boxSheets,
76
77
  enclosingBox,
77
78
  figureBox,
78
79
  paddedBox,
79
80
  pageSheets,
81
+ pagesLine,
80
82
  sheetLines,
81
83
  } from './pageGrid.ts';
82
84
  export type { ImagePrimitive } from './pictures.ts';
@@ -8,7 +8,7 @@ import { placedPage } from '../core/pages.ts';
8
8
  import type { Box, DrawPage, FigureSize } from '../core/types.ts';
9
9
 
10
10
  import { primitivesBounds } from './bounds.ts';
11
- import type { Scene, SceneItem } from './primitives.ts';
11
+ import type { Scene } from './primitives.ts';
12
12
 
13
13
  /** The most sheets a drawing goes on: past them, the rest does not print. */
14
14
  export const MAX_SHEETS = 200;
@@ -25,6 +25,20 @@ interface Tile {
25
25
  row: number;
26
26
  }
27
27
 
28
+ /**
29
+ * What the page lines mean for printing, said under the page setup.
30
+ * @param sheets - How many sheets hold something; null when the lines are
31
+ * hidden.
32
+ * @returns The line.
33
+ */
34
+ export function pagesLine(sheets: number | null): string {
35
+ if (sheets === null) return 'The whole drawing prints on one page.';
36
+ if (sheets >= MAX_SHEETS) return `Only the first ${MAX_SHEETS} pages print.`;
37
+ const printed =
38
+ sheets === 1 ? 'One page prints' : `${sheets} pages print, one sheet each`;
39
+ return `Drag objects across the lines. ${printed}.`;
40
+ }
41
+
28
42
  /**
29
43
  * The box a scene is written in: its drawing, and the padding around it.
30
44
  * @param scene - The scene.
@@ -48,7 +62,12 @@ export function paddedBox(scene: Scene, padding = 4) {
48
62
  * @returns The sheets, in points.
49
63
  */
50
64
  export function pageSheets(scene: Scene, page: DrawPage): Box[] {
51
- return sheetsHolding(scene.items, placedPage(page, paddedBox(scene)));
65
+ const boxes: Box[] = [];
66
+ for (const item of scene.items) {
67
+ const box = primitivesBounds(item.primitives);
68
+ if (box) boxes.push(box);
69
+ }
70
+ return boxSheets(boxes, placedPage(page, paddedBox(scene)));
52
71
  }
53
72
 
54
73
  /**
@@ -71,21 +90,20 @@ export function figureBox(scene: Scene, figure?: FigureSize): Box {
71
90
  }
72
91
 
73
92
  /**
74
- * The sheets of a grid that hold something, in reading order; the first sheet
75
- * of the grid when nothing is drawn.
76
- * @param items - What is drawn.
77
- * @param page - The sheet, with its place.
93
+ * The sheets of a paper's grid that hold something, for an editor that knows
94
+ * its drawing as boxes rather than as a scene: the sheets any box reaches into,
95
+ * in reading order, and the first of the grid when there is none.
96
+ * @param boxes - What is drawn, one box per item, in points.
97
+ * @param page - The paper, with its place: `placedPage` over the drawing.
78
98
  * @returns The sheets, in points, at most {@link MAX_SHEETS}.
79
99
  */
80
- function sheetsHolding(
81
- items: readonly SceneItem[],
100
+ export function boxSheets(
101
+ boxes: readonly Box[],
82
102
  page: Required<DrawPage>,
83
103
  ): Box[] {
84
104
  const { x, y, width, height } = page;
85
105
  const tiles = new Map<string, Tile>();
86
- for (const item of items) {
87
- const box = primitivesBounds(item.primitives);
88
- if (!box) continue;
106
+ for (const box of boxes) {
89
107
  const columns = span(box.x, box.width, x, width);
90
108
  const rows = span(box.y, box.height, y, height);
91
109
  for (let row = rows.first; row <= rows.last; row++) {
@@ -0,0 +1,104 @@
1
+ import { FormGroup, HTMLSelect, SegmentedControl } from '@blueprintjs/core';
2
+ import type { ReactElement, ReactNode } from 'react';
3
+
4
+ import type { Orientation } from '../core/pages.ts';
5
+ import {
6
+ PAGE_SIZES,
7
+ orientationOf,
8
+ pickedPage,
9
+ samePaper,
10
+ turnedTo,
11
+ } from '../core/pages.ts';
12
+ import type { DrawPage } from '../core/types.ts';
13
+
14
+ import { PageSideInput } from './PageSideInput.tsx';
15
+
16
+ const CUSTOM = 'custom';
17
+
18
+ /** How a new size of page was asked for. */
19
+ export type PageChange = 'picked' | 'typed';
20
+
21
+ /** What {@link PageField} is given. */
22
+ export interface PageFieldProps {
23
+ /** The paper or the slide the drawing is laid out on. */
24
+ page: DrawPage;
25
+ /**
26
+ * Called with the page asked for, its place left to the editor: `picked`
27
+ * from the menu or turned, after which the whole page is usually framed, or
28
+ * `typed` side by side.
29
+ */
30
+ onChange: (page: DrawPage, how: PageChange) => void;
31
+ /**
32
+ * What is said under the fields, such as `pagesLine`'s count of sheets.
33
+ * @default undefined — nothing
34
+ */
35
+ helperText?: ReactNode;
36
+ }
37
+
38
+ /**
39
+ * The page setup of an editor, the same in every one of the family: the paper
40
+ * or the slide the drawing is laid out on, portrait or landscape, and its two
41
+ * sides in centimetres. `react-cheminfo/styles/drawing.css` lays it out.
42
+ * @param props - See {@link PageFieldProps}.
43
+ * @returns A row of a form.
44
+ */
45
+ export function PageField(props: PageFieldProps): ReactElement {
46
+ const { page, onChange, helperText } = props;
47
+ const matched = PAGE_SIZES.find((paper) => samePaper(paper.size, page));
48
+ return (
49
+ <FormGroup label="Page" helperText={helperText}>
50
+ <HTMLSelect
51
+ iconName="caret-down"
52
+ fill
53
+ value={matched?.id ?? CUSTOM}
54
+ aria-label="Page size"
55
+ options={[
56
+ ...PAGE_SIZES.map((paper) => ({
57
+ value: paper.id,
58
+ label: paper.name,
59
+ })),
60
+ ...(matched ? [] : [{ value: CUSTOM, label: 'Another size' }]),
61
+ ]}
62
+ onChange={(event) => {
63
+ const { value } = event.currentTarget;
64
+ const chosen = PAGE_SIZES.find((paper) => paper.id === value);
65
+ if (chosen) onChange(pickedPage(chosen.size, page), 'picked');
66
+ }}
67
+ />
68
+ {page.width === page.height ? null : (
69
+ <SegmentedControl
70
+ className="page-field__orientation"
71
+ aria-label="Page orientation"
72
+ size="small"
73
+ fill
74
+ value={orientationOf(page)}
75
+ options={[
76
+ { label: 'Portrait', value: 'portrait' },
77
+ { label: 'Landscape', value: 'landscape' },
78
+ ]}
79
+ onValueChange={(orientation) => {
80
+ onChange(turnedTo(page, orientation as Orientation), 'picked');
81
+ }}
82
+ />
83
+ )}
84
+ <div className="page-field__size">
85
+ <PageSideInput
86
+ label="Page width"
87
+ value={page.width}
88
+ onChange={(width) => {
89
+ onChange({ ...page, width }, 'typed');
90
+ }}
91
+ />
92
+ <span aria-hidden="true">×</span>
93
+ <PageSideInput
94
+ label="Page height"
95
+ value={page.height}
96
+ onChange={(height) => {
97
+ onChange({ ...page, height }, 'typed');
98
+ }}
99
+ />
100
+ <span className="page-field__unit">cm</span>
101
+ </div>
102
+ </FormGroup>
103
+ );
104
+ }