react-cheminfo 0.46.0 → 0.48.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 (229) hide show
  1. package/README.md +69 -0
  2. package/lib/chart/core/chartDomain.d.ts +14 -0
  3. package/lib/chart/core/chartDomain.d.ts.map +1 -1
  4. package/lib/chart/core/chartDomain.js +1 -0
  5. package/lib/chart/core/chartDomain.js.map +1 -1
  6. package/lib/chart/core/selectionGeometry.d.ts +4 -2
  7. package/lib/chart/core/selectionGeometry.d.ts.map +1 -1
  8. package/lib/chart/core/selectionGeometry.js +4 -2
  9. package/lib/chart/core/selectionGeometry.js.map +1 -1
  10. package/lib/chart/core/zoomDomain.d.ts +11 -1
  11. package/lib/chart/core/zoomDomain.d.ts.map +1 -1
  12. package/lib/chart/core/zoomDomain.js +25 -5
  13. package/lib/chart/core/zoomDomain.js.map +1 -1
  14. package/lib/chart/ui/chartGestures.d.ts +26 -1
  15. package/lib/chart/ui/chartGestures.d.ts.map +1 -1
  16. package/lib/chart/ui/chartGestures.js +21 -0
  17. package/lib/chart/ui/chartGestures.js.map +1 -1
  18. package/lib/chart/ui/index.d.ts +1 -1
  19. package/lib/chart/ui/index.d.ts.map +1 -1
  20. package/lib/chart/ui/index.js +1 -1
  21. package/lib/chart/ui/index.js.map +1 -1
  22. package/lib/chart/ui/useChartZoom.d.ts.map +1 -1
  23. package/lib/chart/ui/useChartZoom.js +17 -1
  24. package/lib/chart/ui/useChartZoom.js.map +1 -1
  25. package/lib/core.d.ts +1 -0
  26. package/lib/core.d.ts.map +1 -1
  27. package/lib/core.js +1 -0
  28. package/lib/core.js.map +1 -1
  29. package/lib/download/core/cssPaint.d.ts +27 -0
  30. package/lib/download/core/cssPaint.d.ts.map +1 -0
  31. package/lib/download/core/cssPaint.js +63 -0
  32. package/lib/download/core/cssPaint.js.map +1 -0
  33. package/lib/download/core/drawingMarkup.d.ts +11 -0
  34. package/lib/download/core/drawingMarkup.d.ts.map +1 -0
  35. package/lib/download/core/drawingMarkup.js +32 -0
  36. package/lib/download/core/drawingMarkup.js.map +1 -0
  37. package/lib/download/core/figureHtml.d.ts +25 -0
  38. package/lib/download/core/figureHtml.d.ts.map +1 -0
  39. package/lib/download/core/figureHtml.js +174 -0
  40. package/lib/download/core/figureHtml.js.map +1 -0
  41. package/lib/download/core/figureHtmlMarkup.d.ts +107 -0
  42. package/lib/download/core/figureHtmlMarkup.d.ts.map +1 -0
  43. package/lib/download/core/figureHtmlMarkup.js +75 -0
  44. package/lib/download/core/figureHtmlMarkup.js.map +1 -0
  45. package/lib/download/core/figureSvg.d.ts.map +1 -1
  46. package/lib/download/core/figureSvg.js +16 -35
  47. package/lib/download/core/figureSvg.js.map +1 -1
  48. package/lib/download/core/figureSvgDocument.d.ts +3 -3
  49. package/lib/download/core/figureSvgDocument.d.ts.map +1 -1
  50. package/lib/download/core/figureTarget.d.ts +14 -3
  51. package/lib/download/core/figureTarget.d.ts.map +1 -1
  52. package/lib/download/core/figureTarget.js +42 -3
  53. package/lib/download/core/figureTarget.js.map +1 -1
  54. package/lib/download/core/index.d.ts +1 -1
  55. package/lib/download/core/index.d.ts.map +1 -1
  56. package/lib/download/core/index.js +1 -1
  57. package/lib/download/core/index.js.map +1 -1
  58. package/lib/download/core/textLines.d.ts +27 -0
  59. package/lib/download/core/textLines.d.ts.map +1 -0
  60. package/lib/download/core/textLines.js +51 -0
  61. package/lib/download/core/textLines.js.map +1 -0
  62. package/lib/ecosystem/core/lookup.d.ts +2 -1
  63. package/lib/ecosystem/core/lookup.d.ts.map +1 -1
  64. package/lib/ecosystem/core/lookup.js +10 -3
  65. package/lib/ecosystem/core/lookup.js.map +1 -1
  66. package/lib/ecosystem/core/types.d.ts +2 -2
  67. package/lib/ecosystem/core/types.d.ts.map +1 -1
  68. package/lib/ecosystem/core/unlistedSites.d.ts +9 -0
  69. package/lib/ecosystem/core/unlistedSites.d.ts.map +1 -0
  70. package/lib/ecosystem/core/unlistedSites.js +35 -0
  71. package/lib/ecosystem/core/unlistedSites.js.map +1 -0
  72. package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
  73. package/lib/ecosystem/ui/glyphs.js +7 -0
  74. package/lib/ecosystem/ui/glyphs.js.map +1 -1
  75. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  76. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  77. package/lib/ir/core/irMode.d.ts.map +1 -1
  78. package/lib/ir/core/irMode.js +6 -1
  79. package/lib/ir/core/irMode.js.map +1 -1
  80. package/lib/locales/de.json +56 -1
  81. package/lib/locales/en.json +56 -1
  82. package/lib/locales/es.json +56 -1
  83. package/lib/locales/fr.json +56 -1
  84. package/lib/locales/it.json +56 -1
  85. package/lib/periodic/core/index.d.ts +1 -1
  86. package/lib/periodic/core/index.d.ts.map +1 -1
  87. package/lib/periodic/core/layout.d.ts +11 -0
  88. package/lib/periodic/core/layout.d.ts.map +1 -1
  89. package/lib/periodic/core/layout.js.map +1 -1
  90. package/lib/periodic/ui/ElementCell.d.ts +6 -2
  91. package/lib/periodic/ui/ElementCell.d.ts.map +1 -1
  92. package/lib/periodic/ui/ElementCell.js +2 -2
  93. package/lib/periodic/ui/ElementCell.js.map +1 -1
  94. package/lib/periodic/ui/PeriodicTable.d.ts +3 -98
  95. package/lib/periodic/ui/PeriodicTable.d.ts.map +1 -1
  96. package/lib/periodic/ui/PeriodicTable.js +9 -84
  97. package/lib/periodic/ui/PeriodicTable.js.map +1 -1
  98. package/lib/periodic/ui/PeriodicTableChrome.d.ts +13 -3
  99. package/lib/periodic/ui/PeriodicTableChrome.d.ts.map +1 -1
  100. package/lib/periodic/ui/PeriodicTableChrome.js +10 -20
  101. package/lib/periodic/ui/PeriodicTableChrome.js.map +1 -1
  102. package/lib/periodic/ui/SelectAllCorner.d.ts +23 -0
  103. package/lib/periodic/ui/SelectAllCorner.d.ts.map +1 -0
  104. package/lib/periodic/ui/SelectAllCorner.js +40 -0
  105. package/lib/periodic/ui/SelectAllCorner.js.map +1 -0
  106. package/lib/periodic/ui/headerStyles.d.ts +17 -0
  107. package/lib/periodic/ui/headerStyles.d.ts.map +1 -0
  108. package/lib/periodic/ui/headerStyles.js +19 -0
  109. package/lib/periodic/ui/headerStyles.js.map +1 -0
  110. package/lib/periodic/ui/periodicTableProps.d.ts +115 -0
  111. package/lib/periodic/ui/periodicTableProps.d.ts.map +1 -0
  112. package/lib/periodic/ui/periodicTableProps.js +8 -0
  113. package/lib/periodic/ui/periodicTableProps.js.map +1 -0
  114. package/lib/periodic/ui/tableLayout.d.ts +26 -0
  115. package/lib/periodic/ui/tableLayout.d.ts.map +1 -0
  116. package/lib/periodic/ui/tableLayout.js +86 -0
  117. package/lib/periodic/ui/tableLayout.js.map +1 -0
  118. package/lib/split/ui/SplitColumn.d.ts +29 -0
  119. package/lib/split/ui/SplitColumn.d.ts.map +1 -0
  120. package/lib/split/ui/SplitColumn.js +19 -0
  121. package/lib/split/ui/SplitColumn.js.map +1 -0
  122. package/lib/split/ui/SplitRow.d.ts +14 -53
  123. package/lib/split/ui/SplitRow.d.ts.map +1 -1
  124. package/lib/split/ui/SplitRow.js +8 -90
  125. package/lib/split/ui/SplitRow.js.map +1 -1
  126. package/lib/split/ui/index.d.ts +3 -0
  127. package/lib/split/ui/index.d.ts.map +1 -1
  128. package/lib/split/ui/index.js +1 -0
  129. package/lib/split/ui/index.js.map +1 -1
  130. package/lib/split/ui/splitPanes.d.ts +84 -0
  131. package/lib/split/ui/splitPanes.d.ts.map +1 -0
  132. package/lib/split/ui/splitPanes.js +125 -0
  133. package/lib/split/ui/splitPanes.js.map +1 -0
  134. package/lib/taxonomy/core/index.d.ts +8 -0
  135. package/lib/taxonomy/core/index.d.ts.map +1 -0
  136. package/lib/taxonomy/core/index.js +5 -0
  137. package/lib/taxonomy/core/index.js.map +1 -0
  138. package/lib/taxonomy/core/lineage.d.ts +83 -0
  139. package/lib/taxonomy/core/lineage.d.ts.map +1 -0
  140. package/lib/taxonomy/core/lineage.js +126 -0
  141. package/lib/taxonomy/core/lineage.js.map +1 -0
  142. package/lib/taxonomy/core/ncbi.d.ts +8 -0
  143. package/lib/taxonomy/core/ncbi.d.ts.map +1 -0
  144. package/lib/taxonomy/core/ncbi.js +10 -0
  145. package/lib/taxonomy/core/ncbi.js.map +1 -0
  146. package/lib/taxonomy/core/organismName.d.ts +28 -0
  147. package/lib/taxonomy/core/organismName.d.ts.map +1 -0
  148. package/lib/taxonomy/core/organismName.js +188 -0
  149. package/lib/taxonomy/core/organismName.js.map +1 -0
  150. package/lib/taxonomy/core/organismWords.d.ts +20 -0
  151. package/lib/taxonomy/core/organismWords.d.ts.map +1 -0
  152. package/lib/taxonomy/core/organismWords.js +86 -0
  153. package/lib/taxonomy/core/organismWords.js.map +1 -0
  154. package/lib/taxonomy/core/ranks.d.ts +51 -0
  155. package/lib/taxonomy/core/ranks.d.ts.map +1 -0
  156. package/lib/taxonomy/core/ranks.js +123 -0
  157. package/lib/taxonomy/core/ranks.js.map +1 -0
  158. package/lib/taxonomy/ui/OrganismName.d.ts +28 -0
  159. package/lib/taxonomy/ui/OrganismName.d.ts.map +1 -0
  160. package/lib/taxonomy/ui/OrganismName.js +28 -0
  161. package/lib/taxonomy/ui/OrganismName.js.map +1 -0
  162. package/lib/taxonomy/ui/TaxonLineage.d.ts +67 -0
  163. package/lib/taxonomy/ui/TaxonLineage.d.ts.map +1 -0
  164. package/lib/taxonomy/ui/TaxonLineage.js +45 -0
  165. package/lib/taxonomy/ui/TaxonLineage.js.map +1 -0
  166. package/lib/taxonomy/ui/index.d.ts +6 -0
  167. package/lib/taxonomy/ui/index.d.ts.map +1 -0
  168. package/lib/taxonomy/ui/index.js +4 -0
  169. package/lib/taxonomy/ui/index.js.map +1 -0
  170. package/lib/taxonomy/ui/rankLabel.d.ts +17 -0
  171. package/lib/taxonomy/ui/rankLabel.d.ts.map +1 -0
  172. package/lib/taxonomy/ui/rankLabel.js +77 -0
  173. package/lib/taxonomy/ui/rankLabel.js.map +1 -0
  174. package/lib/ui.d.ts +1 -0
  175. package/lib/ui.d.ts.map +1 -1
  176. package/lib/ui.js +1 -0
  177. package/lib/ui.js.map +1 -1
  178. package/package.json +1 -1
  179. package/src/chart/core/chartDomain.ts +15 -0
  180. package/src/chart/core/selectionGeometry.ts +4 -2
  181. package/src/chart/core/zoomDomain.ts +37 -5
  182. package/src/chart/ui/chartGestures.ts +41 -1
  183. package/src/chart/ui/index.ts +1 -1
  184. package/src/chart/ui/useChartZoom.ts +25 -1
  185. package/src/core.ts +1 -0
  186. package/src/download/core/cssPaint.ts +71 -0
  187. package/src/download/core/drawingMarkup.ts +35 -0
  188. package/src/download/core/figureHtml.ts +214 -0
  189. package/src/download/core/figureHtmlMarkup.ts +187 -0
  190. package/src/download/core/figureSvg.ts +17 -38
  191. package/src/download/core/figureSvgDocument.ts +3 -3
  192. package/src/download/core/figureTarget.ts +41 -8
  193. package/src/download/core/index.ts +1 -0
  194. package/src/download/core/textLines.ts +67 -0
  195. package/src/ecosystem/core/lookup.ts +11 -3
  196. package/src/ecosystem/core/types.ts +4 -2
  197. package/src/ecosystem/core/unlistedSites.ts +37 -0
  198. package/src/ecosystem/ui/glyphs.tsx +44 -0
  199. package/src/ir/core/irMode.ts +6 -1
  200. package/src/locales/de.json +56 -1
  201. package/src/locales/en.json +56 -1
  202. package/src/locales/es.json +56 -1
  203. package/src/locales/fr.json +56 -1
  204. package/src/locales/it.json +56 -1
  205. package/src/periodic/core/index.ts +1 -1
  206. package/src/periodic/core/layout.ts +12 -0
  207. package/src/periodic/ui/ElementCell.tsx +8 -4
  208. package/src/periodic/ui/PeriodicTable.tsx +27 -197
  209. package/src/periodic/ui/PeriodicTableChrome.tsx +23 -20
  210. package/src/periodic/ui/SelectAllCorner.tsx +65 -0
  211. package/src/periodic/ui/headerStyles.ts +23 -0
  212. package/src/periodic/ui/periodicTableProps.ts +117 -0
  213. package/src/periodic/ui/tableLayout.ts +96 -0
  214. package/src/split/ui/SplitColumn.tsx +35 -0
  215. package/src/split/ui/SplitRow.tsx +16 -208
  216. package/src/split/ui/index.ts +3 -0
  217. package/src/split/ui/splitPanes.tsx +283 -0
  218. package/src/taxonomy/core/index.ts +20 -0
  219. package/src/taxonomy/core/lineage.ts +161 -0
  220. package/src/taxonomy/core/ncbi.ts +9 -0
  221. package/src/taxonomy/core/organismName.ts +217 -0
  222. package/src/taxonomy/core/organismWords.ts +86 -0
  223. package/src/taxonomy/core/ranks.ts +134 -0
  224. package/src/taxonomy/ui/OrganismName.tsx +59 -0
  225. package/src/taxonomy/ui/TaxonLineage.tsx +183 -0
  226. package/src/taxonomy/ui/index.ts +5 -0
  227. package/src/taxonomy/ui/rankLabel.ts +81 -0
  228. package/src/ui.ts +1 -0
  229. package/styles/chrome.css +135 -6
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Two figures one above the other, with a splitter between them and the share
3
+ * each takes written into the address.
4
+ *
5
+ * The body is `splitPanes.tsx`, which `<SplitRow>` shares; its header is where
6
+ * the design is written down.
7
+ */
8
+
9
+ import type { ReactElement } from 'react';
10
+
11
+ import type { SplitPanesProps } from './splitPanes.tsx';
12
+ import { SplitPanes } from './splitPanes.tsx';
13
+
14
+ /**
15
+ * Props of {@link SplitColumn}. `start` is the top pane, `end` the bottom one,
16
+ * and `stackBelow` a height.
17
+ */
18
+ export type SplitColumnProps = SplitPanesProps;
19
+
20
+ /**
21
+ * Two panes sharing a column, divided where the address says.
22
+ *
23
+ * **A share needs a height to be a share of.** Put this inside a box that has
24
+ * one — a workbench pane, a page that fills the viewport — not inside an
25
+ * ordinary page column, whose height is whatever its content comes to. Given
26
+ * no height to divide, it measures nothing, says nothing about it, and simply
27
+ * stacks the two panes with no splitter, which is what an ordinary page wanted
28
+ * anyway.
29
+ * @param props - See {@link SplitColumnProps}.
30
+ * @returns The two panes with the splitter between them, the two stacked where
31
+ * there is no height to divide, or whichever one a link left, alone.
32
+ */
33
+ export function SplitColumn(props: SplitColumnProps): ReactElement | null {
34
+ return <SplitPanes direction="vertical" {...props} />;
35
+ }
@@ -2,224 +2,32 @@
2
2
  * Two figures side by side, with a splitter between them and the share each
3
3
  * takes written into the address.
4
4
  *
5
- * How much room the tool deserves beside the figure it feeds is not ours to
6
- * decide: somebody embedding the chart wants it nearly whole, somebody
7
- * teaching off the picker wants the picker nearly whole, and both want the
8
- * link they hand out to open the way they left it. So the splitter is dragged,
9
- * the share it comes to rest at goes into `?split=`, and the address is the
10
- * figure.
11
- *
12
- * Two things it cannot do, and must not pretend to: on a narrow screen there
13
- * is no room for two columns at all, so the panes stack and no splitter is
14
- * drawn; and a link that hid everything one pane holds leaves the other the
15
- * whole width rather than a share of it.
16
- *
17
- * The bar itself is react-science's `SplitPane`, and it keeps react-science's
18
- * look — barely visible on purpose, found by the pointer that changes over it
19
- * rather than by the eye. All `chrome.css` says about it is that eleven pixels
20
- * is more gutter than two figures need.
5
+ * The body is `splitPanes.tsx`, which `<SplitColumn>` shares; its header is
6
+ * where the design is written down.
21
7
  */
22
8
 
23
- import type { CSSProperties, ReactElement, ReactNode } from 'react';
24
- import { useRef, useState } from 'react';
25
- import type { SplitPaneSize } from 'react-science/ui';
26
- import { SplitPane } from 'react-science/ui';
9
+ import type { ReactElement } from 'react';
27
10
 
28
- import { useResizeObserver } from '../../hooks/ui/useResizeObserver.ts';
29
- import type { SplitRange } from '../core/split.ts';
30
- import { clampSplit } from '../core/split.ts';
11
+ import type { SplitPanesProps } from './splitPanes.tsx';
12
+ import { SplitPanes } from './splitPanes.tsx';
31
13
 
32
- /** Props of {@link SplitRow}. */
33
- export interface SplitRowProps extends SplitRange {
34
- /**
35
- * Share of the row the first pane takes, as a whole percentage, or `null`
36
- * while the page sits at {@link SplitRowProps.defaultRatio}.
37
- */
38
- ratio: number | null;
39
- /** The share the row opens at when the address names none. */
40
- defaultRatio: number;
41
- /**
42
- * Take the share a drag came to rest at, or `null` when the splitter was
43
- * double-clicked back to the default.
44
- */
45
- onRatio: (ratio: number | null) => void;
46
- /** The left-hand pane, or `null` when a link left nothing in it. */
47
- start: ReactNode;
48
- /** The right-hand pane, or `null` when a link left nothing in it. */
49
- end: ReactNode;
50
- /**
51
- * The narrowest row that is still split; under it the two panes stack.
52
- * @default 860
53
- */
54
- stackBelow?: number;
55
- /**
56
- * The gutter each pane keeps beside the splitter, in pixels, so neither
57
- * figure is read against its edge.
58
- * @default 6
59
- */
60
- gutter?: number;
61
- /**
62
- * The gap between the two panes once they have stacked, in pixels.
63
- * @default 16
64
- */
65
- stackedGap?: number;
66
- }
14
+ /**
15
+ * Props of {@link SplitRow}. `start` is the left-hand pane, `end` the
16
+ * right-hand one, and `stackBelow` a width.
17
+ */
18
+ export type SplitRowProps = SplitPanesProps;
67
19
 
68
20
  /**
69
21
  * Two panes sharing a row, divided where the address says.
22
+ *
23
+ * **Set `max` where the first pane stops being able to use the room.** A pane
24
+ * of forms dragged past about half the row does not grow: the labels stay put
25
+ * and the fields stretch to a width nobody types into, so the room becomes
26
+ * empty card. The figure beside it is what the drag exists to enlarge.
70
27
  * @param props - See {@link SplitRowProps}.
71
28
  * @returns The two panes with the splitter between them, the two stacked on a
72
29
  * narrow screen, or whichever one a link left on the page, alone.
73
30
  */
74
31
  export function SplitRow(props: SplitRowProps): ReactElement | null {
75
- const {
76
- ratio,
77
- defaultRatio,
78
- onRatio,
79
- start,
80
- end,
81
- min,
82
- max,
83
- stackBelow = STACK_BELOW,
84
- gutter = GUTTER,
85
- stackedGap = STACKED_GAP,
86
- } = props;
87
- const row = useRef<HTMLDivElement>(null);
88
- const [width, setWidth] = useState(windowWidth);
89
- // The share under the pointer, which is not the one in the address: a drag
90
- // reports every pixel it crosses, and the address is rewritten once, where
91
- // the splitter is let go.
92
- const [dragged, setDragged] = useState<number | null>(null);
93
-
94
- useResizeObserver(row, (size) => {
95
- setWidth(size.width);
96
- });
97
-
98
- if (start === null && end === null) return null;
99
-
100
- const stacked = start === null || end === null || width < stackBelow;
101
- const startPane =
102
- start === null ? null : (
103
- <div
104
- data-testid="split-start"
105
- style={stacked ? STACKED_PANE : paneStyle('start', gutter)}
106
- >
107
- {start}
108
- </div>
109
- );
110
- const endPane =
111
- end === null ? null : (
112
- <div
113
- data-testid="split-end"
114
- style={stacked ? STACKED_PANE : paneStyle('end', gutter)}
115
- >
116
- {end}
117
- </div>
118
- );
119
-
120
- if (stacked) {
121
- return (
122
- <div ref={row} style={{ ...STACK, gap: stackedGap }}>
123
- {startPane}
124
- {endPane}
125
- </div>
126
- );
127
- }
128
-
129
- const share = clampSplit(dragged ?? ratio ?? defaultRatio, { min, max });
130
-
131
- return (
132
- // `split-row` is what `chrome.css` reaches the bar through: it is
133
- // react-science's own element and carries no class of ours.
134
- <div ref={row} className="split-row">
135
- <SplitPane
136
- direction="horizontal"
137
- controlledSide="start"
138
- size={`${share}%`}
139
- // Held open, so the only layout a visitor can reach is one the address
140
- // describes: left to itself a double click collapses a pane, and a link
141
- // shared from there would open with the pane back. The double click is
142
- // answered here instead, by returning to the page's own share.
143
- open
144
- onOpenChange={() => {
145
- setDragged(null);
146
- onRatio(null);
147
- }}
148
- onSizeChange={(asked) => {
149
- setDragged(shareOf(asked, share, { min, max }));
150
- }}
151
- onResize={(asked) => {
152
- const rested = shareOf(asked, share, { min, max });
153
- setDragged(null);
154
- onRatio(rested);
155
- }}
156
- >
157
- {startPane}
158
- {endPane}
159
- </SplitPane>
160
- </div>
161
- );
162
- }
163
-
164
- /**
165
- * The share a splitter asked for.
166
- * @param asked - What it reported, a percentage because that is what it was
167
- * given.
168
- * @param current - The share in force, kept when the report is not a number.
169
- * @param range - The range this row is divided in.
170
- * @returns A whole percentage inside it.
171
- */
172
- function shareOf(
173
- asked: SplitPaneSize,
174
- current: number,
175
- range: SplitRange,
176
- ): number {
177
- const value = Number.parseFloat(asked);
178
- return Number.isFinite(value) ? clampSplit(value, range) : current;
179
- }
180
-
181
- /**
182
- * How wide the window is, which is what the row is taken to be until it has
183
- * been measured. Reading it rather than starting at zero is what keeps a wide
184
- * page from laying itself out stacked and splitting a frame later, which would
185
- * build both figures twice on every load.
186
- * @returns The width in pixels, or the threshold itself where there is no
187
- * window to read — a test, or a page rendered to a string — which is the
188
- * narrowest a row is still split at.
189
- */
190
- function windowWidth(): number {
191
- const { innerWidth } = globalThis;
192
- return typeof innerWidth === 'number' && innerWidth > 0
193
- ? innerWidth
194
- : STACK_BELOW;
195
- }
196
-
197
- /** The narrowest row that is still split, in pixels. */
198
- const STACK_BELOW = 860;
199
-
200
- /** The gutter a pane keeps beside the splitter, in pixels. */
201
- const GUTTER = 6;
202
-
203
- /** The gap between the panes once they have stacked, in pixels. */
204
- const STACKED_GAP = 16;
205
-
206
- const STACK = {
207
- display: 'flex',
208
- flexDirection: 'column',
209
- } as const satisfies CSSProperties;
210
-
211
- const STACKED_PANE = {
212
- display: 'flex',
213
- flexDirection: 'column',
214
- minWidth: 0,
215
- } as const satisfies CSSProperties;
216
-
217
- function paneStyle(side: 'start' | 'end', gutter: number): CSSProperties {
218
- return {
219
- display: 'flex',
220
- flex: '1 1 0%',
221
- flexDirection: 'column',
222
- minWidth: 0,
223
- [side === 'start' ? 'paddingRight' : 'paddingLeft']: gutter,
224
- };
32
+ return <SplitPanes direction="horizontal" {...props} />;
225
33
  }
@@ -1,2 +1,5 @@
1
+ export type { SplitColumnProps } from './SplitColumn.tsx';
2
+ export { SplitColumn } from './SplitColumn.tsx';
1
3
  export type { SplitRowProps } from './SplitRow.tsx';
2
4
  export { SplitRow } from './SplitRow.tsx';
5
+ export type { SplitPanesProps } from './splitPanes.tsx';
@@ -0,0 +1,283 @@
1
+ /**
2
+ * Two figures with a splitter between them, and the share each takes written
3
+ * into the address. The body of `<SplitRow>` and `<SplitColumn>` both.
4
+ *
5
+ * How much room one half deserves beside the other is not ours to decide:
6
+ * somebody embedding the chart wants it nearly whole, somebody teaching off the
7
+ * picker wants the picker nearly whole, and both want the link they hand out to
8
+ * open the way they left it. So the splitter is dragged, the share it comes to
9
+ * rest at goes into `?split=`, and the address is the figure.
10
+ *
11
+ * Two things it cannot do, and must not pretend to: on a screen with no room
12
+ * for two the panes stack and no splitter is drawn; and a link that hid
13
+ * everything one pane holds leaves the other the whole of it rather than a
14
+ * share.
15
+ *
16
+ * **Several bars on one page make a grid, and a grid has to read as one.** Three
17
+ * panes are one of these nested inside the other, and the shares are numbered in
18
+ * reading order — `split` for the first bar a reader meets going left to right
19
+ * and then down, `split2` for the next. Two rules keep that from coming apart:
20
+ * **at most two bars on a page**, because a third is a window manager rather
21
+ * than a tool and every bar is one more thing to understand before the page can
22
+ * be used; and **never a bar across two columns of the same row**, because two
23
+ * of them at independent heights do not read as a grid, they read as a page that
24
+ * has come apart. Divide the column that holds the figures and leave its
25
+ * neighbours whole — or, where both genuinely want the same line, give them one
26
+ * share and one parameter so it runs straight across.
27
+ *
28
+ * The bar itself is react-science's `SplitPane`, and it keeps react-science's
29
+ * look — barely visible on purpose, found by the pointer that changes over it
30
+ * rather than by the eye. All `chrome.css` says about it is that eleven pixels
31
+ * is more gutter than two figures need.
32
+ */
33
+
34
+ import type { CSSProperties, ReactElement, ReactNode } from 'react';
35
+ import { useRef, useState } from 'react';
36
+ import type { SplitPaneSize } from 'react-science/ui';
37
+ import { SplitPane } from 'react-science/ui';
38
+
39
+ import { useResizeObserver } from '../../hooks/ui/useResizeObserver.ts';
40
+ import type { SplitRange } from '../core/split.ts';
41
+ import { clampSplit } from '../core/split.ts';
42
+
43
+ /** What both splitters take. */
44
+ export interface SplitPanesProps extends SplitRange {
45
+ /**
46
+ * Share of the box the first pane takes, as a whole percentage, or `null`
47
+ * while the page sits at {@link SplitPanesProps.defaultRatio}.
48
+ */
49
+ ratio: number | null;
50
+ /** The share it opens at when the address names none. */
51
+ defaultRatio: number;
52
+ /**
53
+ * Take the share a drag came to rest at, or `null` when the splitter was
54
+ * double-clicked back to the default.
55
+ */
56
+ onRatio: (ratio: number | null) => void;
57
+ /** The first pane — left, or top — or `null` when a link left nothing in it. */
58
+ start: ReactNode;
59
+ /** The second pane, or `null` when a link left nothing in it. */
60
+ end: ReactNode;
61
+ /**
62
+ * The smallest box that is still split, in pixels — a width for a row, a
63
+ * height for a column. Under it the two panes stack and no splitter is drawn.
64
+ * @default 860 across, 420 down
65
+ */
66
+ stackBelow?: number;
67
+ /**
68
+ * The gutter each pane keeps beside the splitter, in pixels, so neither
69
+ * figure is read against its edge.
70
+ * @default 6
71
+ */
72
+ gutter?: number;
73
+ /**
74
+ * The gap between the two panes once they have stacked, in pixels.
75
+ * @default 16
76
+ */
77
+ stackedGap?: number;
78
+ }
79
+
80
+ /** What {@link SplitPanes} takes on top of the public props. */
81
+ interface InternalProps extends SplitPanesProps {
82
+ /** Across the box, or down it. */
83
+ direction: 'horizontal' | 'vertical';
84
+ }
85
+
86
+ /**
87
+ * The two panes, divided where the address says.
88
+ * @param props - See {@link SplitPanesProps}.
89
+ * @returns The panes with the splitter between them, the two stacked where
90
+ * there is no room for both, or whichever one a link left, alone.
91
+ */
92
+ export function SplitPanes(props: InternalProps): ReactElement | null {
93
+ const {
94
+ direction,
95
+ ratio,
96
+ defaultRatio,
97
+ onRatio,
98
+ start,
99
+ end,
100
+ min,
101
+ max,
102
+ stackBelow = direction === 'horizontal' ? STACK_ACROSS : STACK_DOWN,
103
+ gutter = GUTTER,
104
+ stackedGap = STACKED_GAP,
105
+ } = props;
106
+ const across = direction === 'horizontal';
107
+ const box = useRef<HTMLDivElement>(null);
108
+ const [size, setSize] = useState(() => viewportSize(across, stackBelow));
109
+ // The share under the pointer, which is not the one in the address: a drag
110
+ // reports every pixel it crosses, and the address is rewritten once, where
111
+ // the splitter is let go.
112
+ const [dragged, setDragged] = useState<number | null>(null);
113
+
114
+ useResizeObserver(box, (measured) => {
115
+ setSize(across ? measured.width : measured.height);
116
+ });
117
+
118
+ if (start === null && end === null) return null;
119
+
120
+ // A column divided by a share needs a box of a definite height to take a
121
+ // share of; in an ordinary page-height one it would measure zero and both
122
+ // panes would collapse, so it stacks instead and says nothing about it.
123
+ const stacked = start === null || end === null || size < stackBelow;
124
+ const startPane =
125
+ start === null ? null : (
126
+ <div
127
+ data-testid="split-start"
128
+ style={stacked ? STACKED_PANE : paneStyle(across, 'start', gutter)}
129
+ >
130
+ {start}
131
+ </div>
132
+ );
133
+ const endPane =
134
+ end === null ? null : (
135
+ <div
136
+ data-testid="split-end"
137
+ style={stacked ? STACKED_PANE : paneStyle(across, 'end', gutter)}
138
+ >
139
+ {end}
140
+ </div>
141
+ );
142
+
143
+ if (stacked) {
144
+ return (
145
+ <div ref={box} style={{ ...STACK, gap: stackedGap }}>
146
+ {startPane}
147
+ {endPane}
148
+ </div>
149
+ );
150
+ }
151
+
152
+ const share = clampSplit(dragged ?? ratio ?? defaultRatio, { min, max });
153
+
154
+ return (
155
+ // `split-row` is what `chrome.css` reaches the bar through: it is
156
+ // react-science's own element and carries no class of ours. A column says
157
+ // which way it divides as well, because its bar is that same line turned a
158
+ // quarter: there it is the height that is narrowed, and the width that is
159
+ // left to run the pane.
160
+ <div
161
+ ref={box}
162
+ className={across ? 'split-row' : 'split-row split-row--down'}
163
+ style={across ? undefined : FILL}
164
+ >
165
+ <SplitPane
166
+ direction={direction}
167
+ controlledSide="start"
168
+ size={`${share}%`}
169
+ // Held open, so the only layout a visitor can reach is one the address
170
+ // describes: left to itself a double click collapses a pane, and a link
171
+ // shared from there would open with the pane back. The double click is
172
+ // answered here instead, by returning to the page's own share.
173
+ open
174
+ onOpenChange={() => {
175
+ setDragged(null);
176
+ onRatio(null);
177
+ }}
178
+ onSizeChange={(asked) => {
179
+ setDragged(shareOf(asked, share, { min, max }));
180
+ }}
181
+ onResize={(asked) => {
182
+ const rested = shareOf(asked, share, { min, max });
183
+ setDragged(null);
184
+ onRatio(rested);
185
+ }}
186
+ >
187
+ {startPane}
188
+ {endPane}
189
+ </SplitPane>
190
+ </div>
191
+ );
192
+ }
193
+
194
+ /**
195
+ * The share a splitter asked for.
196
+ * @param asked - What it reported, a percentage because that is what it was
197
+ * given.
198
+ * @param current - The share in force, kept when the report is not a number.
199
+ * @param range - The range this box is divided in.
200
+ * @returns A whole percentage inside it.
201
+ */
202
+ function shareOf(
203
+ asked: SplitPaneSize,
204
+ current: number,
205
+ range: SplitRange,
206
+ ): number {
207
+ const value = Number.parseFloat(asked);
208
+ return Number.isFinite(value) ? clampSplit(value, range) : current;
209
+ }
210
+
211
+ /**
212
+ * How big the window is, which is what the box is taken to be until it has been
213
+ * measured. Reading it rather than starting at zero is what keeps a wide page
214
+ * from laying itself out stacked and splitting a frame later, which would build
215
+ * both figures twice on every load.
216
+ * @param across - Whether the box is divided across or down.
217
+ * @param fallback - What to answer where there is no window to read — a test,
218
+ * or a page rendered to a string.
219
+ * @returns The size in pixels.
220
+ */
221
+ function viewportSize(across: boolean, fallback: number): number {
222
+ const measure = across ? globalThis.innerWidth : globalThis.innerHeight;
223
+ return typeof measure === 'number' && measure > 0 ? measure : fallback;
224
+ }
225
+
226
+ /** The narrowest box still divided across, in pixels. */
227
+ const STACK_ACROSS = 860;
228
+
229
+ /**
230
+ * The shortest box still divided down, in pixels. Two figures sharing less than
231
+ * this have about two hundred pixels each, which is under what any of them
232
+ * reads at.
233
+ */
234
+ const STACK_DOWN = 420;
235
+
236
+ /** The gutter a pane keeps beside the splitter, in pixels. */
237
+ const GUTTER = 6;
238
+
239
+ /** The gap between the panes once they have stacked, in pixels. */
240
+ const STACKED_GAP = 16;
241
+
242
+ const STACK = {
243
+ display: 'flex',
244
+ flexDirection: 'column',
245
+ minHeight: 0,
246
+ } as const satisfies CSSProperties;
247
+
248
+ const STACKED_PANE = {
249
+ display: 'flex',
250
+ flexDirection: 'column',
251
+ minWidth: 0,
252
+ minHeight: 0,
253
+ } as const satisfies CSSProperties;
254
+
255
+ /** A column takes the height it is given, so its share has something to divide. */
256
+ const FILL = {
257
+ display: 'flex',
258
+ flex: '1 1 0%',
259
+ flexDirection: 'column',
260
+ minHeight: 0,
261
+ } as const satisfies CSSProperties;
262
+
263
+ function paneStyle(
264
+ across: boolean,
265
+ side: 'start' | 'end',
266
+ gutter: number,
267
+ ): CSSProperties {
268
+ const edge = across
269
+ ? side === 'start'
270
+ ? 'paddingRight'
271
+ : 'paddingLeft'
272
+ : side === 'start'
273
+ ? 'paddingBottom'
274
+ : 'paddingTop';
275
+ return {
276
+ display: 'flex',
277
+ flex: '1 1 0%',
278
+ flexDirection: 'column',
279
+ minWidth: 0,
280
+ minHeight: 0,
281
+ [edge]: gutter,
282
+ };
283
+ }
@@ -0,0 +1,20 @@
1
+ export type { Taxon, TaxonLineage, TaxonNode } from './lineage.ts';
2
+ export {
3
+ genusOrBelow,
4
+ isPlaceholderTaxon,
5
+ lineageFromNodes,
6
+ lineageFromRanks,
7
+ principalLineage,
8
+ } from './lineage.ts';
9
+ export { ncbiTaxonomyUrl } from './ncbi.ts';
10
+ export type { OrganismNamePart } from './organismName.ts';
11
+ export { splitOrganismName } from './organismName.ts';
12
+ export type { TaxonRank } from './ranks.ts';
13
+ export {
14
+ PRINCIPAL_RANKS,
15
+ TAXON_RANKS,
16
+ isAboveGenus,
17
+ isGenusOrBelow,
18
+ isPrincipalRank,
19
+ rankOrder,
20
+ } from './ranks.ts';