react-cheminfo 0.132.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 (198) hide show
  1. package/lib/drawing/captionEditor/CaptionEditor.d.ts +3 -3
  2. package/lib/drawing/captionEditor/CaptionEditor.d.ts.map +1 -1
  3. package/lib/drawing/captionEditor/CaptionEditor.js +8 -4
  4. package/lib/drawing/captionEditor/CaptionEditor.js.map +1 -1
  5. package/lib/drawing/captionEditor/CaptionToolbar.d.ts +4 -2
  6. package/lib/drawing/captionEditor/CaptionToolbar.d.ts.map +1 -1
  7. package/lib/drawing/captionEditor/CaptionToolbar.js +6 -4
  8. package/lib/drawing/captionEditor/CaptionToolbar.js.map +1 -1
  9. package/lib/drawing/captionEditor/index.d.ts +2 -0
  10. package/lib/drawing/captionEditor/index.d.ts.map +1 -1
  11. package/lib/drawing/captionEditor/index.js +1 -0
  12. package/lib/drawing/captionEditor/index.js.map +1 -1
  13. package/lib/drawing/captionEditor/toolbarInView.d.ts +40 -0
  14. package/lib/drawing/captionEditor/toolbarInView.d.ts.map +1 -0
  15. package/lib/drawing/captionEditor/toolbarInView.js +53 -0
  16. package/lib/drawing/captionEditor/toolbarInView.js.map +1 -0
  17. package/lib/drawing/core/camera.d.ts +2 -0
  18. package/lib/drawing/core/camera.d.ts.map +1 -1
  19. package/lib/drawing/core/camera.js +2 -0
  20. package/lib/drawing/core/camera.js.map +1 -1
  21. package/lib/drawing/core/index.d.ts +1 -1
  22. package/lib/drawing/core/index.d.ts.map +1 -1
  23. package/lib/drawing/core/index.js +1 -1
  24. package/lib/drawing/core/index.js.map +1 -1
  25. package/lib/drawing/render/index.d.ts +1 -1
  26. package/lib/drawing/render/index.d.ts.map +1 -1
  27. package/lib/drawing/render/index.js +1 -1
  28. package/lib/drawing/render/index.js.map +1 -1
  29. package/lib/drawing/render/pageGrid.d.ts +16 -0
  30. package/lib/drawing/render/pageGrid.d.ts.map +1 -1
  31. package/lib/drawing/render/pageGrid.js +28 -10
  32. package/lib/drawing/render/pageGrid.js.map +1 -1
  33. package/lib/drawing/ui/PageField.d.ts +29 -0
  34. package/lib/drawing/ui/PageField.d.ts.map +1 -0
  35. package/lib/drawing/ui/PageField.js +38 -0
  36. package/lib/drawing/ui/PageField.js.map +1 -0
  37. package/lib/drawing/ui/PageGrid.d.ts +20 -0
  38. package/lib/drawing/ui/PageGrid.d.ts.map +1 -0
  39. package/lib/drawing/ui/PageGrid.js +26 -0
  40. package/lib/drawing/ui/PageGrid.js.map +1 -0
  41. package/lib/drawing/ui/PageSideInput.d.ts +28 -0
  42. package/lib/drawing/ui/PageSideInput.d.ts.map +1 -0
  43. package/lib/drawing/ui/PageSideInput.js +47 -0
  44. package/lib/drawing/ui/PageSideInput.js.map +1 -0
  45. package/lib/drawing/ui/PageToolbar.d.ts +16 -0
  46. package/lib/drawing/ui/PageToolbar.d.ts.map +1 -0
  47. package/lib/drawing/ui/PageToolbar.js +16 -0
  48. package/lib/drawing/ui/PageToolbar.js.map +1 -0
  49. package/lib/drawing/ui/PrintSheets.d.ts +32 -0
  50. package/lib/drawing/ui/PrintSheets.d.ts.map +1 -0
  51. package/lib/drawing/ui/PrintSheets.js +17 -0
  52. package/lib/drawing/ui/PrintSheets.js.map +1 -0
  53. package/lib/drawing/ui/TextToolIcon.d.ts +19 -0
  54. package/lib/drawing/ui/TextToolIcon.d.ts.map +1 -0
  55. package/lib/drawing/ui/TextToolIcon.js +21 -0
  56. package/lib/drawing/ui/TextToolIcon.js.map +1 -0
  57. package/lib/drawing/ui/ZoomControl.d.ts +25 -0
  58. package/lib/drawing/ui/ZoomControl.d.ts.map +1 -0
  59. package/lib/drawing/ui/ZoomControl.js +27 -0
  60. package/lib/drawing/ui/ZoomControl.js.map +1 -0
  61. package/lib/drawing/ui/index.d.ts +10 -0
  62. package/lib/drawing/ui/index.d.ts.map +1 -1
  63. package/lib/drawing/ui/index.js +7 -0
  64. package/lib/drawing/ui/index.js.map +1 -1
  65. package/lib/guide/ui/EmptyGuide.d.ts +5 -2
  66. package/lib/guide/ui/EmptyGuide.d.ts.map +1 -1
  67. package/lib/guide/ui/EmptyGuide.js +8 -3
  68. package/lib/guide/ui/EmptyGuide.js.map +1 -1
  69. package/lib/guide/ui/GuideFigures.d.ts +6 -0
  70. package/lib/guide/ui/GuideFigures.d.ts.map +1 -1
  71. package/lib/guide/ui/GuideFigures.js +5 -5
  72. package/lib/guide/ui/GuideFigures.js.map +1 -1
  73. package/lib/mass/core/index.d.ts +1 -0
  74. package/lib/mass/core/index.d.ts.map +1 -1
  75. package/lib/mass/core/index.js +1 -0
  76. package/lib/mass/core/index.js.map +1 -1
  77. package/lib/mass/core/massDomain.d.ts.map +1 -1
  78. package/lib/mass/core/massDomain.js +9 -5
  79. package/lib/mass/core/massDomain.js.map +1 -1
  80. package/lib/mass/core/massSpectrum.d.ts +9 -0
  81. package/lib/mass/core/massSpectrum.d.ts.map +1 -1
  82. package/lib/mass/core/massSpectrum.js.map +1 -1
  83. package/lib/mass/core/verticalScale.d.ts +30 -0
  84. package/lib/mass/core/verticalScale.d.ts.map +1 -0
  85. package/lib/mass/core/verticalScale.js +40 -0
  86. package/lib/mass/core/verticalScale.js.map +1 -0
  87. package/lib/mass/ui/MassChart.d.ts.map +1 -1
  88. package/lib/mass/ui/MassChart.js +4 -38
  89. package/lib/mass/ui/MassChart.js.map +1 -1
  90. package/lib/mass/ui/massChartLayers.d.ts +31 -0
  91. package/lib/mass/ui/massChartLayers.d.ts.map +1 -0
  92. package/lib/mass/ui/massChartLayers.js +57 -0
  93. package/lib/mass/ui/massChartLayers.js.map +1 -0
  94. package/lib/structure/core/index.d.ts +1 -1
  95. package/lib/structure/core/index.d.ts.map +1 -1
  96. package/lib/structure/core/index.js.map +1 -1
  97. package/lib/structure/core/structurePicture.d.ts +32 -1
  98. package/lib/structure/core/structurePicture.d.ts.map +1 -1
  99. package/lib/structure/core/structurePicture.js +29 -2
  100. package/lib/structure/core/structurePicture.js.map +1 -1
  101. package/lib/structure/ui/StructureEditor.d.ts +2 -1
  102. package/lib/structure/ui/StructureEditor.d.ts.map +1 -1
  103. package/lib/structure/ui/StructureEditor.js +9 -3
  104. package/lib/structure/ui/StructureEditor.js.map +1 -1
  105. package/lib/structure/ui/StructureEditorGuide.d.ts +15 -0
  106. package/lib/structure/ui/StructureEditorGuide.d.ts.map +1 -0
  107. package/lib/structure/ui/StructureEditorGuide.js +26 -0
  108. package/lib/structure/ui/StructureEditorGuide.js.map +1 -0
  109. package/lib/structure/ui/structureEditorProps.d.ts +11 -1
  110. package/lib/structure/ui/structureEditorProps.d.ts.map +1 -1
  111. package/lib/structure/ui/useCanvasPress.d.ts +23 -0
  112. package/lib/structure/ui/useCanvasPress.d.ts.map +1 -0
  113. package/lib/structure/ui/useCanvasPress.js +53 -0
  114. package/lib/structure/ui/useCanvasPress.js.map +1 -0
  115. package/lib/xps/core/detectFormat.d.ts +6 -0
  116. package/lib/xps/core/detectFormat.d.ts.map +1 -1
  117. package/lib/xps/core/detectFormat.js +8 -0
  118. package/lib/xps/core/detectFormat.js.map +1 -1
  119. package/lib/xps/core/xpsEditorApi.d.ts +16 -0
  120. package/lib/xps/core/xpsEditorApi.d.ts.map +1 -1
  121. package/lib/xps/ui/XpsCanvas.d.ts +10 -1
  122. package/lib/xps/ui/XpsCanvas.d.ts.map +1 -1
  123. package/lib/xps/ui/XpsCanvas.js +14 -3
  124. package/lib/xps/ui/XpsCanvas.js.map +1 -1
  125. package/lib/xps/ui/XpsChart.d.ts.map +1 -1
  126. package/lib/xps/ui/XpsChart.js +12 -43
  127. package/lib/xps/ui/XpsChart.js.map +1 -1
  128. package/lib/xps/ui/XpsEditor.d.ts +8 -0
  129. package/lib/xps/ui/XpsEditor.d.ts.map +1 -1
  130. package/lib/xps/ui/XpsEditor.js +2 -2
  131. package/lib/xps/ui/XpsEditor.js.map +1 -1
  132. package/lib/xps/ui/XpsShell.d.ts +5 -0
  133. package/lib/xps/ui/XpsShell.d.ts.map +1 -1
  134. package/lib/xps/ui/XpsShell.js +18 -4
  135. package/lib/xps/ui/XpsShell.js.map +1 -1
  136. package/lib/xps/ui/dropEvents.d.ts +8 -1
  137. package/lib/xps/ui/dropEvents.d.ts.map +1 -1
  138. package/lib/xps/ui/dropEvents.js +15 -1
  139. package/lib/xps/ui/dropEvents.js.map +1 -1
  140. package/lib/xps/ui/useSpectrumDrop.d.ts +6 -0
  141. package/lib/xps/ui/useSpectrumDrop.d.ts.map +1 -1
  142. package/lib/xps/ui/useSpectrumDrop.js +1 -1
  143. package/lib/xps/ui/useSpectrumDrop.js.map +1 -1
  144. package/lib/xps/ui/useXpsEditorHandle.d.ts +4 -1
  145. package/lib/xps/ui/useXpsEditorHandle.d.ts.map +1 -1
  146. package/lib/xps/ui/useXpsEditorHandle.js +6 -2
  147. package/lib/xps/ui/useXpsEditorHandle.js.map +1 -1
  148. package/lib/xps/ui/useXpsReadout.d.ts +43 -0
  149. package/lib/xps/ui/useXpsReadout.d.ts.map +1 -0
  150. package/lib/xps/ui/useXpsReadout.js +59 -0
  151. package/lib/xps/ui/useXpsReadout.js.map +1 -0
  152. package/lib/xps/ui/xpsChartProps.d.ts +9 -0
  153. package/lib/xps/ui/xpsChartProps.d.ts.map +1 -1
  154. package/package.json +1 -1
  155. package/src/drawing/captionEditor/CaptionEditor.tsx +8 -3
  156. package/src/drawing/captionEditor/CaptionToolbar.tsx +18 -2
  157. package/src/drawing/captionEditor/index.ts +2 -0
  158. package/src/drawing/captionEditor/toolbarInView.ts +73 -0
  159. package/src/drawing/core/camera.ts +3 -0
  160. package/src/drawing/core/index.ts +1 -0
  161. package/src/drawing/render/index.ts +2 -0
  162. package/src/drawing/render/pageGrid.ts +29 -11
  163. package/src/drawing/ui/PageField.tsx +104 -0
  164. package/src/drawing/ui/PageGrid.tsx +48 -0
  165. package/src/drawing/ui/PageSideInput.tsx +81 -0
  166. package/src/drawing/ui/PageToolbar.tsx +45 -0
  167. package/src/drawing/ui/PrintSheets.tsx +57 -0
  168. package/src/drawing/ui/TextToolIcon.tsx +48 -0
  169. package/src/drawing/ui/ZoomControl.tsx +112 -0
  170. package/src/drawing/ui/index.ts +10 -0
  171. package/src/guide/ui/EmptyGuide.tsx +20 -13
  172. package/src/guide/ui/GuideFigures.tsx +15 -4
  173. package/src/mass/core/index.ts +1 -0
  174. package/src/mass/core/massDomain.ts +9 -3
  175. package/src/mass/core/massSpectrum.ts +9 -0
  176. package/src/mass/core/verticalScale.ts +48 -0
  177. package/src/mass/ui/MassChart.tsx +12 -43
  178. package/src/mass/ui/massChartLayers.ts +66 -0
  179. package/src/structure/core/index.ts +1 -0
  180. package/src/structure/core/structurePicture.ts +78 -4
  181. package/src/structure/ui/StructureEditor.tsx +13 -2
  182. package/src/structure/ui/StructureEditorGuide.tsx +35 -0
  183. package/src/structure/ui/structureEditorProps.ts +11 -1
  184. package/src/structure/ui/useCanvasPress.ts +69 -0
  185. package/src/xps/core/detectFormat.ts +9 -0
  186. package/src/xps/core/xpsEditorApi.ts +16 -0
  187. package/src/xps/ui/XpsCanvas.tsx +26 -3
  188. package/src/xps/ui/XpsChart.tsx +12 -56
  189. package/src/xps/ui/XpsEditor.tsx +10 -0
  190. package/src/xps/ui/XpsShell.tsx +37 -7
  191. package/src/xps/ui/dropEvents.ts +16 -1
  192. package/src/xps/ui/useSpectrumDrop.ts +7 -1
  193. package/src/xps/ui/useXpsEditorHandle.ts +12 -2
  194. package/src/xps/ui/useXpsReadout.ts +104 -0
  195. package/src/xps/ui/xpsChartProps.ts +9 -0
  196. package/styles/caption-editor.css +15 -1
  197. package/styles/chrome.css +130 -9
  198. package/styles/drawing.css +100 -0
@@ -48,13 +48,23 @@ export {
48
48
  useFigureMoves,
49
49
  useMovingFigureSource,
50
50
  } from './movingFigure.ts';
51
+ export type { PageChange, PageFieldProps } from './PageField.tsx';
52
+ export { PageField } from './PageField.tsx';
53
+ export { PageGrid } from './PageGrid.tsx';
51
54
  export { PageMask } from './PageMask.tsx';
55
+ export { FigureSideInput, PageSideInput } from './PageSideInput.tsx';
56
+ export { PageToolbar } from './PageToolbar.tsx';
52
57
  export type { LineWidthStyle } from './pathProps.ts';
53
58
  export { fillProps, strokeProps } from './pathProps.ts';
54
59
  export { PathView } from './PathView.tsx';
60
+ export type { PrintSheetsProps } from './PrintSheets.tsx';
61
+ export { PrintSheets } from './PrintSheets.tsx';
55
62
  export { releaseFocusOnPress } from './releaseFocusOnPress.ts';
56
63
  export { svgMarkup } from './svgMarkup.ts';
57
64
  export type { CustomColorButtonProps, SwatchRowProps } from './SwatchRow.tsx';
58
65
  export { CustomColorButton, SwatchRow } from './SwatchRow.tsx';
66
+ export { TextToolGlyph, TextToolIcon } from './TextToolIcon.tsx';
59
67
  export { usePrinting } from './usePrinting.ts';
68
+ export type { ZoomControlProps } from './ZoomControl.tsx';
69
+ export { ZoomControl } from './ZoomControl.tsx';
60
70
  export { useSeen } from '../../hooks/ui/useSeen.ts';
@@ -93,10 +93,13 @@ export interface EmptyGuideProps {
93
93
  /**
94
94
  * What a tool shows while it holds nothing: the space that is empty anyway says
95
95
  * how to start. It comes in grey over the tool, lets the pointer through to it
96
- * everywhere but on a button, a link or a figure that can be clicked, and the
97
- * site stops rendering it at the first stroke.
96
+ * everywhere but on what can be clicked or typed in — a button, a link, a
97
+ * figure that can be clicked, a capsule, a field — and the site stops
98
+ * rendering it at the first stroke.
98
99
  *
99
100
  * Fill the absolute box of the tool's view with it: the parent is positioned.
101
+ * A small box keeps the figures and says each section's title and first line;
102
+ * a phone-sized one drops the figures.
100
103
  * @param props - See {@link EmptyGuideProps}.
101
104
  * @returns The guide.
102
105
  */
@@ -111,19 +114,23 @@ export function EmptyGuide(props: EmptyGuideProps): ReactElement {
111
114
  figures = [],
112
115
  figuresTitle,
113
116
  } = props;
117
+ // The body is what the guide's size is asked about: an element cannot query
118
+ // its own container, so the outer box measures and the body is laid out.
114
119
  return (
115
120
  <div className="empty-guide no-print" data-testid="empty-guide">
116
- {help ? <div className="empty-guide__help">{help}</div> : null}
117
- {links && links.length > 0 ? (
118
- <GuideLinks links={links} title={linksTitle} />
119
- ) : null}
120
- {actions.length > 0 || figuresTitle ? (
121
- <GuideStart actions={actions} figuresTitle={figuresTitle} />
122
- ) : null}
123
- <GuideFigures figures={figures} />
124
- {hints.length > 0 ? (
125
- <GuideHint hints={hints} interval={hintInterval} />
126
- ) : null}
121
+ <div className="empty-guide__body">
122
+ {help ? <div className="empty-guide__help">{help}</div> : null}
123
+ {links && links.length > 0 ? (
124
+ <GuideLinks links={links} title={linksTitle} />
125
+ ) : null}
126
+ {actions.length > 0 || figuresTitle ? (
127
+ <GuideStart actions={actions} figuresTitle={figuresTitle} />
128
+ ) : null}
129
+ <GuideFigures figures={figures} />
130
+ {hints.length > 0 ? (
131
+ <GuideHint hints={hints} interval={hintInterval} />
132
+ ) : null}
133
+ </div>
127
134
  </div>
128
135
  );
129
136
  }
@@ -21,6 +21,12 @@ export interface EmptyGuideFigure {
21
21
  * @default undefined — no tooltip
22
22
  */
23
23
  title?: string;
24
+ /**
25
+ * Its name, a short line under it: a reader picks an example by what it is
26
+ * called as much as by how it looks.
27
+ * @default undefined — no line
28
+ */
29
+ label?: string;
24
30
  }
25
31
 
26
32
  /** Figures one above the other, taking one place in the row between them. */
@@ -72,12 +78,17 @@ function stackKey(entry: EmptyGuideFigureStack): string {
72
78
  }
73
79
 
74
80
  function GuideFigure(props: { figure: EmptyGuideFigure }): ReactElement {
75
- const { src, alt, share = 1, onSelect, title } = props.figure;
76
- const image = <img src={src} alt={alt} draggable={false} />;
81
+ const { src, alt, share = 1, onSelect, title, label } = props.figure;
82
+ const content = (
83
+ <>
84
+ <img src={src} alt={alt} draggable={false} />
85
+ {label ? <span className="empty-guide__label">{label}</span> : null}
86
+ </>
87
+ );
77
88
  if (!onSelect) {
78
89
  return (
79
90
  <figure className="empty-guide__figure" style={{ flexGrow: share }}>
80
- {image}
91
+ {content}
81
92
  </figure>
82
93
  );
83
94
  }
@@ -89,7 +100,7 @@ function GuideFigure(props: { figure: EmptyGuideFigure }): ReactElement {
89
100
  title={title}
90
101
  onClick={onSelect}
91
102
  >
92
- {image}
103
+ {content}
93
104
  </button>
94
105
  );
95
106
  }
@@ -112,6 +112,7 @@ export type {
112
112
  MassTrace,
113
113
  } from './massSpectrum.ts';
114
114
  export { isSpectrumDrawn } from './massSpectrum.ts';
115
+ export { spectrumYScale, verticalScaleOf } from './verticalScale.ts';
115
116
  export type {
116
117
  CreateMassStateOptions,
117
118
  MassData,
@@ -11,6 +11,7 @@
11
11
  import { xMaxValue } from 'ml-spectra-processing';
12
12
 
13
13
  import type { MassDomain, MassSpectrum, MassTrace } from './massSpectrum.ts';
14
+ import { verticalScaleOf } from './verticalScale.ts';
14
15
 
15
16
  /**
16
17
  * How much air is left either side of the outermost peak, as a fraction.
@@ -191,10 +192,13 @@ function traceExtent(
191
192
  let extent: TraceExtent | null = null;
192
193
  for (const spectrum of spectra) {
193
194
  if (!includeExcluded && spectrum.excludeFromDomain) continue;
195
+ const scale = verticalScaleOf(spectrum);
194
196
  if (spectrum.showProfile && spectrum.profile !== null) {
195
- extent = widen(extent, spectrum.profile);
197
+ extent = widen(extent, spectrum.profile, scale);
198
+ }
199
+ if (spectrum.showCentroid) {
200
+ extent = widen(extent, spectrum.centroid, scale);
196
201
  }
197
- if (spectrum.showCentroid) extent = widen(extent, spectrum.centroid);
198
202
  }
199
203
  return extent;
200
204
  }
@@ -207,17 +211,19 @@ function traceExtent(
207
211
  * hundred thousand points of a profile to learn what index zero already says.
208
212
  * @param extent - What has been covered so far, `null` for nothing.
209
213
  * @param trace - The trace to cover as well.
214
+ * @param scale - How many times taller than measured it is drawn.
210
215
  * @returns The grown extent, unchanged when the trace holds no point.
211
216
  */
212
217
  function widen(
213
218
  extent: TraceExtent | null,
214
219
  trace: MassTrace,
220
+ scale: number,
215
221
  ): TraceExtent | null {
216
222
  const { x, y } = trace;
217
223
  if (x.length === 0 || y.length === 0) return extent;
218
224
  const first = x[0] as number;
219
225
  const last = x.at(-1) as number;
220
- const tallest = xMaxValue(y);
226
+ const tallest = xMaxValue(y) * scale;
221
227
  if (extent === null) {
222
228
  return { xMinimum: first, xMaximum: last, yMaximum: tallest };
223
229
  }
@@ -180,6 +180,15 @@ export interface MassSpectrum {
180
180
  * @default false
181
181
  */
182
182
  excludeFromDomain?: boolean;
183
+ /**
184
+ * How many times taller than measured the spectrum is drawn, so one spectrum
185
+ * can be brought up against another while the axis stays shared. It scales
186
+ * about the baseline, the fit covers the heights as drawn, and the labels
187
+ * still write the measured intensities. A value that is not a positive
188
+ * number draws it as measured.
189
+ * @default 1
190
+ */
191
+ verticalScale?: number;
183
192
  /**
184
193
  * How finely the spectrum resolves masses, as it was decided when it was read.
185
194
  *
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Drawing one spectrum taller or shorter than the others on a shared axis.
3
+ *
4
+ * The axis stays the measurement's, so a spectrum scaled up is a picture of
5
+ * the measurement and not a new one: every number written on the chart — the
6
+ * labels, the peak under the pointer — is still read off the measured trace.
7
+ * Only where a sample is drawn moves.
8
+ */
9
+
10
+ import type { ChartScale } from '../../chart/core/chartScale.ts';
11
+
12
+ import type { MassSpectrum } from './massSpectrum.ts';
13
+
14
+ /**
15
+ * How many times taller than measured a spectrum is drawn.
16
+ * @param spectrum - The spectrum.
17
+ * @returns Its `verticalScale`, `1` when that is not a positive finite number.
18
+ */
19
+ export function verticalScaleOf(spectrum: MassSpectrum): number {
20
+ const { verticalScale } = spectrum;
21
+ return verticalScale !== undefined &&
22
+ Number.isFinite(verticalScale) &&
23
+ verticalScale > 0
24
+ ? verticalScale
25
+ : 1;
26
+ }
27
+
28
+ /**
29
+ * The intensity axis one spectrum is drawn against: the chart's, stretched by
30
+ * the spectrum's own scale about the baseline, so zero stays where every stick
31
+ * stands.
32
+ *
33
+ * A spectrum drawn as measured gets the chart's scale itself back rather than
34
+ * an equal copy, because the traces memoise their paths on the scale's
35
+ * identity and a copy per render would rebuild every path on every render.
36
+ * @param yScale - The chart's intensity axis.
37
+ * @param spectrum - The spectrum.
38
+ * @returns The axis to draw it against.
39
+ */
40
+ export function spectrumYScale(
41
+ yScale: ChartScale,
42
+ spectrum: MassSpectrum,
43
+ ): ChartScale {
44
+ const scale = verticalScaleOf(spectrum);
45
+ return scale === 1
46
+ ? yScale
47
+ : { offset: yScale.offset, factor: yScale.factor * scale };
48
+ }
@@ -8,13 +8,17 @@ import { AxisGuide } from '../../chart/ui/AxisGuide.tsx';
8
8
  import { SelectionRect } from '../../chart/ui/SelectionRect.tsx';
9
9
  import { chartSurfaceStyle } from '../../chart/ui/chartSurface.ts';
10
10
  import { useChartSize } from '../../chart/ui/useChartSize.ts';
11
- import type { MassSpectrum } from '../core/massSpectrum.ts';
12
11
  import { DEFAULT_LABEL_LIMIT } from '../core/massState.ts';
13
12
  import { mzDecimalsOf } from '../core/resolutionOf.ts';
14
13
 
15
14
  import { MassPointerTracker } from './MassPointerTracker.tsx';
16
15
  import { PeakLabels } from './PeakLabels.tsx';
17
16
  import { SpectrumTrace } from './SpectrumTrace.tsx';
17
+ import {
18
+ emphasisedLast,
19
+ labelledSpectrum,
20
+ spectrumYScales,
21
+ } from './massChartLayers.ts';
18
22
  import type { MassChartProps } from './massChartProps.ts';
19
23
  import { useMassPointer } from './useMassPointer.ts';
20
24
  import { useMassZoom } from './useMassZoom.ts';
@@ -120,6 +124,11 @@ export function MassChart(props: MassChartProps): ReactElement {
120
124
  () => emphasisedLast(spectra, emphasisedId),
121
125
  [spectra, emphasisedId],
122
126
  );
127
+ // Built once per window: the traces memoise their paths on their scale.
128
+ const yScales = useMemo(
129
+ () => spectrumYScales(spectra, yScale),
130
+ [spectra, yScale],
131
+ );
123
132
 
124
133
  // The crosshair reads every drawn spectrum, so it is written to what they
125
134
  // resolve together; the labels are of one spectrum, and written to its own.
@@ -178,7 +187,7 @@ export function MassChart(props: MassChartProps): ReactElement {
178
187
  spectrum={spectrum}
179
188
  plot={plot}
180
189
  xScale={xScale}
181
- yScale={yScale}
190
+ yScale={yScales.get(spectrum.id) ?? yScale}
182
191
  strokeWidth={
183
192
  spectrum.id === emphasisedId ? EMPHASISED_WIDTH : undefined
184
193
  }
@@ -192,7 +201,7 @@ export function MassChart(props: MassChartProps): ReactElement {
192
201
  spectrum={labelled}
193
202
  plot={plot}
194
203
  xScale={xScale}
195
- yScale={yScale}
204
+ yScale={yScales.get(labelled.id) ?? yScale}
196
205
  limit={labelLimit}
197
206
  showCharges={showCharges}
198
207
  mzDecimals={labelDecimals}
@@ -216,46 +225,6 @@ export function MassChart(props: MassChartProps): ReactElement {
216
225
  );
217
226
  }
218
227
 
219
- /**
220
- * The one spectrum whose peaks are labelled.
221
- * @param spectra - What the chart draws.
222
- * @param labelledId - The identity asked for, `null` for none, absent to let the
223
- * chart take the first.
224
- * @returns The spectrum, or `null` when none answers.
225
- */
226
- function labelledSpectrum(
227
- spectra: readonly MassSpectrum[],
228
- labelledId: string | null | undefined,
229
- ): MassSpectrum | null {
230
- if (labelledId === undefined) return spectra[0] ?? null;
231
- if (labelledId === null) return null;
232
- for (const spectrum of spectra) {
233
- if (spectrum.id === labelledId) return spectrum;
234
- }
235
- return null;
236
- }
237
-
238
- /**
239
- * The traces in painting order, with the emphasised one last — last is in
240
- * front, and in front is what lets a trace crossing a dozen others be followed.
241
- * @param spectra - The traces, in the order they were opened.
242
- * @param emphasisedId - Identity of the one to raise, `null` for none.
243
- * @returns The order to paint in — the array itself when nothing moves.
244
- */
245
- function emphasisedLast(
246
- spectra: readonly MassSpectrum[],
247
- emphasisedId: string | null,
248
- ): readonly MassSpectrum[] {
249
- if (emphasisedId === null) return spectra;
250
- const at = spectra.findIndex((spectrum) => spectrum.id === emphasisedId);
251
- if (at === -1 || at === spectra.length - 1) return spectra;
252
- return [
253
- ...spectra.slice(0, at),
254
- ...spectra.slice(at + 1),
255
- spectra[at] as MassSpectrum,
256
- ];
257
- }
258
-
259
228
  /** What the chart is, and what can be done to it, for whoever cannot see it. */
260
229
  const CHART_LABEL =
261
230
  'Mass spectrum. Drag across it to zoom the m/z axis, drag below the baseline to take the intensity axis with it, turn the wheel to scale the intensity, and double click to fit everything again.';
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Which spectrum a mass chart writes its labels on, in what order it paints
3
+ * them, and against which intensity axis each one is drawn.
4
+ */
5
+
6
+ import type { ChartScale } from '../../chart/core/chartScale.ts';
7
+ import type { MassSpectrum } from '../core/massSpectrum.ts';
8
+ import { spectrumYScale } from '../core/verticalScale.ts';
9
+
10
+ /**
11
+ * The one spectrum whose peaks are labelled.
12
+ * @param spectra - What the chart draws.
13
+ * @param labelledId - The identity asked for, `null` for none, absent to let the
14
+ * chart take the first.
15
+ * @returns The spectrum, or `null` when none answers.
16
+ */
17
+ export function labelledSpectrum(
18
+ spectra: readonly MassSpectrum[],
19
+ labelledId: string | null | undefined,
20
+ ): MassSpectrum | null {
21
+ if (labelledId === undefined) return spectra[0] ?? null;
22
+ if (labelledId === null) return null;
23
+ for (const spectrum of spectra) {
24
+ if (spectrum.id === labelledId) return spectrum;
25
+ }
26
+ return null;
27
+ }
28
+
29
+ /**
30
+ * The traces in painting order, with the emphasised one last — last is in
31
+ * front, and in front is what lets a trace crossing a dozen others be followed.
32
+ * @param spectra - The traces, in the order they were opened.
33
+ * @param emphasisedId - Identity of the one to raise, `null` for none.
34
+ * @returns The order to paint in — the array itself when nothing moves.
35
+ */
36
+ export function emphasisedLast(
37
+ spectra: readonly MassSpectrum[],
38
+ emphasisedId: string | null,
39
+ ): readonly MassSpectrum[] {
40
+ if (emphasisedId === null) return spectra;
41
+ const at = spectra.findIndex((spectrum) => spectrum.id === emphasisedId);
42
+ if (at === -1 || at === spectra.length - 1) return spectra;
43
+ return [
44
+ ...spectra.slice(0, at),
45
+ ...spectra.slice(at + 1),
46
+ spectra[at] as MassSpectrum,
47
+ ];
48
+ }
49
+
50
+ /**
51
+ * The intensity axis each spectrum is drawn against, by identity.
52
+ * @param spectra - What the chart draws.
53
+ * @param yScale - The chart's intensity axis as it is currently zoomed.
54
+ * @returns The axis of each spectrum — the chart's own for every spectrum drawn
55
+ * as measured.
56
+ */
57
+ export function spectrumYScales(
58
+ spectra: readonly MassSpectrum[],
59
+ yScale: ChartScale,
60
+ ): Map<string, ChartScale> {
61
+ const scales = new Map<string, ChartScale>();
62
+ for (const spectrum of spectra) {
63
+ scales.set(spectrum.id, spectrumYScale(yScale, spectrum));
64
+ }
65
+ return scales;
66
+ }
@@ -90,6 +90,7 @@ export { looksLikeSmarts, readStructure } from './readStructure.ts';
90
90
  export type { StructureError } from './structureError.ts';
91
91
  export { structureError } from './structureError.ts';
92
92
  export type {
93
+ StructureDepictorOptions,
93
94
  StructurePicture,
94
95
  StructurePictureOptions,
95
96
  } from './structurePicture.ts';
@@ -9,7 +9,7 @@
9
9
  * times the drawing.
10
10
  */
11
11
 
12
- import type { Molecule } from 'openchemlib';
12
+ import type { Molecule, MoleculeToSVGOptions } from 'openchemlib';
13
13
 
14
14
  import type { FigurePixels } from '../../download/core/figureScale.ts';
15
15
 
@@ -28,8 +28,43 @@ export interface StructurePictureOptions {
28
28
  * @default '#ffffff'
29
29
  */
30
30
  background?: string;
31
+ /**
32
+ * The id of the document, which its own style rules are scoped to. Named, the
33
+ * same structure gives the same file on every run, which a figure kept in a
34
+ * repository needs.
35
+ * @default undefined — numbered by OpenChemLib, from a counter of its own
36
+ */
37
+ id?: string;
38
+ /**
39
+ * Whether the stereo text is written: "abs" and the enantiomer note under
40
+ * the structure, the R and S of each centre, E and Z, and the "?" of a centre
41
+ * left undefined. The wedges are drawn either way; a figure read at a glance
42
+ * is clearer without the labels.
43
+ * @default true
44
+ */
45
+ stereoText?: boolean;
46
+ /**
47
+ * The type the atom labels are set in, as a CSS `font-family`. OpenChemLib
48
+ * writes `sans-serif` into the document's own style, which no stylesheet of
49
+ * a page reaches when the file is opened on its own.
50
+ * @default undefined — `sans-serif`, as OpenChemLib writes it
51
+ */
52
+ fontFamily?: string;
53
+ /**
54
+ * More of OpenChemLib's drawing options — atom numbers, grey bonds, no
55
+ * implicit hydrogens. The size and the crop are not among them: they follow
56
+ * `bondLength`.
57
+ * @default {}
58
+ */
59
+ depictor?: StructureDepictorOptions;
31
60
  }
32
61
 
62
+ /** OpenChemLib's drawing options a picture may set; the size is its own. */
63
+ export type StructureDepictorOptions = Omit<
64
+ MoleculeToSVGOptions,
65
+ 'autoCrop' | 'autoCropMargin' | 'maxAVBL'
66
+ >;
67
+
33
68
  /** A structure drawn, and how big it came out. */
34
69
  export interface StructurePicture extends FigurePixels {
35
70
  /** The SVG document, ready to be saved or rasterized. */
@@ -69,17 +104,56 @@ export function structurePicture(
69
104
  molecule: Molecule,
70
105
  options: StructurePictureOptions = {},
71
106
  ): StructurePicture {
72
- const { bondLength = STRUCTURE_BOND_LENGTH, background = '#ffffff' } =
73
- options;
74
- const markup = molecule.toSVG(CANVAS, CANVAS, undefined, {
107
+ const {
108
+ bondLength = STRUCTURE_BOND_LENGTH,
109
+ background = '#ffffff',
110
+ id,
111
+ stereoText = true,
112
+ fontFamily,
113
+ depictor,
114
+ } = options;
115
+ const drawn = molecule.toSVG(CANVAS, CANVAS, id, {
116
+ ...depictor,
117
+ ...(stereoText ? undefined : NO_STEREO_TEXT),
75
118
  autoCrop: true,
76
119
  autoCropMargin: Math.max(2, Math.round(bondLength / 6)),
77
120
  maxAVBL: Math.max(1, Math.round(bondLength)),
78
121
  });
122
+ const markup =
123
+ fontFamily === undefined ? drawn : withFontFamily(drawn, fontFamily);
79
124
 
80
125
  return { markup: painted(markup, background), ...sizeOf(markup) };
81
126
  }
82
127
 
128
+ /** What leaves the stereo text out of a picture, wedges kept. */
129
+ const NO_STEREO_TEXT: StructureDepictorOptions = {
130
+ suppressChiralText: true,
131
+ suppressCIPParity: true,
132
+ suppressESR: true,
133
+ noStereoProblem: true,
134
+ };
135
+
136
+ /** The rule OpenChemLib sets the labels' type with, in the document's style. */
137
+ const FONT_RULE = /(?<rule> text \{font-family: )sans-serif;/u;
138
+
139
+ /**
140
+ * Set the labels in another type than the `sans-serif` OpenChemLib names.
141
+ *
142
+ * The family is written into a style element, so whatever could close the
143
+ * rule or the element is left out of it.
144
+ * @param markup - The document as OpenChemLib wrote it.
145
+ * @param fontFamily - The CSS `font-family`.
146
+ * @returns The document.
147
+ */
148
+ function withFontFamily(markup: string, fontFamily: string): string {
149
+ const family = fontFamily.replaceAll(/[{};<>&]/gu, '').trim();
150
+ if (family === '') return markup;
151
+ return markup.replace(
152
+ FONT_RULE,
153
+ (_match, rule: string) => `${rule}${family};`,
154
+ );
155
+ }
156
+
83
157
  /**
84
158
  * Paint a background into the document, so the file does not open
85
159
  * transparent.
@@ -17,10 +17,12 @@ import { EditorHelpButton } from './EditorHelpButton.tsx';
17
17
  import { EditorImportButton } from './EditorImportButton.tsx';
18
18
  import { EditorImportProblem } from './EditorImportProblem.tsx';
19
19
  import { StructureDropOverlay } from './StructureDropOverlay.tsx';
20
+ import { StructureEditorGuide } from './StructureEditorGuide.tsx';
20
21
  import { StructureEditorSplash } from './StructureEditorSplash.tsx';
21
22
  import { ToolbarTooltip } from './ToolbarTooltip.tsx';
22
23
  import type { StructureEditorChange } from './editorChange.ts';
23
24
  import type { StructureEditorProps } from './structureEditorProps.ts';
25
+ import { useCanvasPress } from './useCanvasPress.ts';
24
26
  import { useDebouncedChange } from './useDebouncedChange.ts';
25
27
  import { useEditorStructure } from './useEditorStructure.ts';
26
28
  import { useStructureDrop } from './useStructureDrop.ts';
@@ -42,7 +44,8 @@ const EditorCanvas = lazy(async () => {
42
44
  /**
43
45
  * The canvas structure editor, sized to fill its container and never to hide
44
46
  * part of its toolbar, with a tooltip on every toolbar button, a guide to the
45
- * keys, and a splash on an empty canvas saying how to start.
47
+ * keys, and a splash on an empty canvas saying how to start — or the site's own
48
+ * guide in its place.
46
49
  * @param props - What to draw, when to reload it, and where to send it.
47
50
  * @returns The editor.
48
51
  */
@@ -61,6 +64,7 @@ export function StructureEditor(props: StructureEditorProps): ReactElement {
61
64
  exportable = true,
62
65
  importable = true,
63
66
  onImport,
67
+ guide,
64
68
  className,
65
69
  style,
66
70
  } = props;
@@ -86,6 +90,9 @@ export function StructureEditor(props: StructureEditorProps): ReactElement {
86
90
  });
87
91
  const takesImports = importable && mode === 'molecule';
88
92
  const drop = useStructureDrop(takesImports ? imports.load : undefined);
93
+ const press = useCanvasPress();
94
+ const empty = mode === 'molecule' && drawing.empty && !drop.over;
95
+ const guided = guide !== undefined && empty;
89
96
 
90
97
  return (
91
98
  <div
@@ -96,6 +103,7 @@ export function StructureEditor(props: StructureEditorProps): ReactElement {
96
103
  : `structure-editor ${className}`
97
104
  }
98
105
  style={{ ...ROOT_STYLE, minHeight, ...style }}
106
+ onPointerDownCapture={guided ? press.onPointerDownCapture : undefined}
99
107
  {...drop.targetProps}
100
108
  >
101
109
  <Suspense
@@ -111,7 +119,10 @@ export function StructureEditor(props: StructureEditorProps): ReactElement {
111
119
  value={imports.idCode ?? value}
112
120
  mode={mode}
113
121
  />
114
- {splash && mode === 'molecule' && drawing.empty && !drop.over ? (
122
+ {guided && !press.pressed ? (
123
+ <StructureEditorGuide>{guide}</StructureEditorGuide>
124
+ ) : null}
125
+ {splash && guide === undefined && empty ? (
115
126
  <StructureEditorSplash importable={takesImports} />
116
127
  ) : null}
117
128
  {help ? (
@@ -0,0 +1,35 @@
1
+ import type { CSSProperties, ReactElement, ReactNode } from 'react';
2
+
3
+ import { EDITOR_TOOLBAR_WIDTH } from '../core/editorToolbarGeometry.ts';
4
+
5
+ /**
6
+ * The box a site's guide is drawn in over an empty canvas: beside the toolbar
7
+ * and under the buttons in the corner, so it never covers either.
8
+ *
9
+ * The box itself lets the pointer through; `<EmptyGuide>` takes it back only on
10
+ * its own buttons, links and figures, so a stroke can start on the words.
11
+ * @param props - What the guide shows.
12
+ * @param props.children - The site's guide.
13
+ * @returns The box and the guide in it.
14
+ */
15
+ export function StructureEditorGuide(props: {
16
+ children: ReactNode;
17
+ }): ReactElement {
18
+ return (
19
+ <div data-testid="structure-editor-guide" style={GUIDE_STYLE}>
20
+ {props.children}
21
+ </div>
22
+ );
23
+ }
24
+
25
+ /**
26
+ * Under the open, export and help buttons in the corner: 4 px from the top, a
27
+ * small button 24 px tall, and 4 px under it.
28
+ */
29
+ const CORNER_CLEARANCE = 32;
30
+
31
+ const GUIDE_STYLE: CSSProperties = {
32
+ position: 'absolute',
33
+ inset: `${CORNER_CLEARANCE}px 0 0 ${EDITOR_TOOLBAR_WIDTH}px`,
34
+ pointerEvents: 'none',
35
+ };
@@ -1,4 +1,4 @@
1
- import type { CSSProperties } from 'react';
1
+ import type { CSSProperties, ReactNode } from 'react';
2
2
  import type { CanvasEditorInputFormat } from 'react-ocl';
3
3
 
4
4
  import type { StructureTransfer } from '../core/structureTransfer.ts';
@@ -74,6 +74,16 @@ export interface StructureEditorProps {
74
74
  * @default true
75
75
  */
76
76
  splash?: boolean;
77
+ /**
78
+ * What an empty canvas shows in place of the splash: the site's
79
+ * `<EmptyGuide>`, drawn beside the toolbar and under the buttons in the
80
+ * corner. The pointer goes through it to the canvas except on its own
81
+ * buttons, links and figures; it goes at the press that starts a stroke, and
82
+ * comes back whenever the canvas is empty again. Shown whatever `splash`
83
+ * says. A reaction canvas shows none.
84
+ * @default undefined — the splash, when `splash` is on
85
+ */
86
+ guide?: ReactNode;
77
87
  /**
78
88
  * Put a button in the corner that opens every notation of the drawing — its
79
89
  * SMILES, its molfiles, its canonical identifiers — and the picture of it,