react-cheminfo 0.34.0 → 0.35.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 (171) hide show
  1. package/README.md +28 -28
  2. package/lib/about/core/about.d.ts +1 -30
  3. package/lib/about/core/about.d.ts.map +1 -1
  4. package/lib/about/core/about.js +0 -16
  5. package/lib/about/core/about.js.map +1 -1
  6. package/lib/about/core/index.d.ts +0 -1
  7. package/lib/about/core/index.d.ts.map +1 -1
  8. package/lib/about/core/index.js +0 -1
  9. package/lib/about/core/index.js.map +1 -1
  10. package/lib/about/ui/AboutBuild.d.ts +2 -5
  11. package/lib/about/ui/AboutBuild.d.ts.map +1 -1
  12. package/lib/about/ui/AboutBuild.js +7 -19
  13. package/lib/about/ui/AboutBuild.js.map +1 -1
  14. package/lib/about/ui/AboutPage.d.ts +2 -2
  15. package/lib/about/ui/AboutPage.d.ts.map +1 -1
  16. package/lib/about/ui/AboutPage.js +3 -14
  17. package/lib/about/ui/AboutPage.js.map +1 -1
  18. package/lib/about/ui/AboutVersion.d.ts +0 -4
  19. package/lib/about/ui/AboutVersion.d.ts.map +1 -1
  20. package/lib/about/ui/AboutVersion.js +3 -31
  21. package/lib/about/ui/AboutVersion.js.map +1 -1
  22. package/lib/download/core/index.d.ts +0 -5
  23. package/lib/download/core/index.d.ts.map +1 -1
  24. package/lib/download/core/index.js +0 -3
  25. package/lib/download/core/index.js.map +1 -1
  26. package/lib/download/ui/FigureDownload.d.ts +4 -55
  27. package/lib/download/ui/FigureDownload.d.ts.map +1 -1
  28. package/lib/download/ui/FigureDownload.js +6 -66
  29. package/lib/download/ui/FigureDownload.js.map +1 -1
  30. package/lib/download/ui/FigureDownloadPanel.d.ts +16 -2
  31. package/lib/download/ui/FigureDownloadPanel.d.ts.map +1 -1
  32. package/lib/download/ui/FigureDownloadPanel.js +11 -30
  33. package/lib/download/ui/FigureDownloadPanel.js.map +1 -1
  34. package/lib/download/ui/figureDownloadHint.d.ts +30 -0
  35. package/lib/download/ui/figureDownloadHint.d.ts.map +1 -0
  36. package/lib/download/ui/figureDownloadHint.js +33 -0
  37. package/lib/download/ui/figureDownloadHint.js.map +1 -0
  38. package/lib/download/ui/index.d.ts +3 -10
  39. package/lib/download/ui/index.d.ts.map +1 -1
  40. package/lib/download/ui/index.js +1 -5
  41. package/lib/download/ui/index.js.map +1 -1
  42. package/lib/download/ui/useFigureActions.d.ts +50 -0
  43. package/lib/download/ui/useFigureActions.d.ts.map +1 -0
  44. package/lib/download/ui/useFigureActions.js +58 -0
  45. package/lib/download/ui/useFigureActions.js.map +1 -0
  46. package/lib/download/ui/useFigureDownload.d.ts +85 -0
  47. package/lib/download/ui/useFigureDownload.d.ts.map +1 -0
  48. package/lib/download/ui/useFigureDownload.js +75 -0
  49. package/lib/download/ui/useFigureDownload.js.map +1 -0
  50. package/lib/ecosystem/core/sites.d.ts.map +1 -1
  51. package/lib/ecosystem/core/sites.js +0 -40
  52. package/lib/ecosystem/core/sites.js.map +1 -1
  53. package/lib/ecosystem/core/types.d.ts +0 -10
  54. package/lib/ecosystem/core/types.d.ts.map +1 -1
  55. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  56. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  57. package/lib/ir/core/irCommands.d.ts +2 -2
  58. package/lib/ir/core/irCommands.js +2 -2
  59. package/lib/ir/core/irCommands.js.map +1 -1
  60. package/lib/ir/ui/IrAboutDialog.d.ts.map +1 -1
  61. package/lib/ir/ui/IrAboutDialog.js +1 -1
  62. package/lib/ir/ui/IrAboutDialog.js.map +1 -1
  63. package/lib/ir/ui/IrCanvas.d.ts +6 -0
  64. package/lib/ir/ui/IrCanvas.d.ts.map +1 -1
  65. package/lib/ir/ui/IrCanvas.js +2 -2
  66. package/lib/ir/ui/IrCanvas.js.map +1 -1
  67. package/lib/ir/ui/IrShell.d.ts.map +1 -1
  68. package/lib/ir/ui/IrShell.js +16 -11
  69. package/lib/ir/ui/IrShell.js.map +1 -1
  70. package/lib/ir/ui/IrToolbar.d.ts +11 -1
  71. package/lib/ir/ui/IrToolbar.d.ts.map +1 -1
  72. package/lib/ir/ui/IrToolbar.js +12 -2
  73. package/lib/ir/ui/IrToolbar.js.map +1 -1
  74. package/lib/ir/ui/index.d.ts +1 -0
  75. package/lib/ir/ui/index.d.ts.map +1 -1
  76. package/lib/ir/ui/index.js.map +1 -1
  77. package/lib/locales/de.json +2 -4
  78. package/lib/locales/en.json +2 -4
  79. package/lib/locales/es.json +2 -4
  80. package/lib/locales/fr.json +2 -4
  81. package/lib/locales/it.json +2 -4
  82. package/lib/overlay/ui/OverlayPanel.d.ts +6 -0
  83. package/lib/overlay/ui/OverlayPanel.d.ts.map +1 -1
  84. package/lib/overlay/ui/OverlayPanel.js +2 -2
  85. package/lib/overlay/ui/OverlayPanel.js.map +1 -1
  86. package/lib/overlay/ui/overlayPanelStyles.d.ts +2 -1
  87. package/lib/overlay/ui/overlayPanelStyles.d.ts.map +1 -1
  88. package/lib/overlay/ui/overlayPanelStyles.js +3 -1
  89. package/lib/overlay/ui/overlayPanelStyles.js.map +1 -1
  90. package/lib/periodic/ui/ElementCell.d.ts +0 -6
  91. package/lib/periodic/ui/ElementCell.d.ts.map +1 -1
  92. package/lib/periodic/ui/ElementCell.js +34 -30
  93. package/lib/periodic/ui/ElementCell.js.map +1 -1
  94. package/lib/periodic/ui/PeriodicTable.d.ts.map +1 -1
  95. package/lib/periodic/ui/PeriodicTable.js +12 -15
  96. package/lib/periodic/ui/PeriodicTable.js.map +1 -1
  97. package/package.json +1 -1
  98. package/src/about/core/about.ts +1 -51
  99. package/src/about/core/index.ts +0 -1
  100. package/src/about/ui/AboutBuild.tsx +8 -37
  101. package/src/about/ui/AboutPage.tsx +8 -64
  102. package/src/about/ui/AboutVersion.tsx +5 -45
  103. package/src/download/core/index.ts +0 -25
  104. package/src/download/ui/FigureDownload.tsx +11 -148
  105. package/src/download/ui/FigureDownloadPanel.tsx +46 -45
  106. package/src/download/ui/figureDownloadHint.ts +52 -0
  107. package/src/download/ui/index.ts +6 -10
  108. package/src/download/ui/useFigureActions.ts +113 -0
  109. package/src/download/ui/useFigureDownload.tsx +191 -0
  110. package/src/ecosystem/core/sites.ts +0 -40
  111. package/src/ecosystem/core/types.ts +0 -10
  112. package/src/ir/core/irCommands.ts +2 -2
  113. package/src/ir/ui/IrAboutDialog.tsx +0 -13
  114. package/src/ir/ui/IrCanvas.tsx +8 -2
  115. package/src/ir/ui/IrShell.tsx +23 -25
  116. package/src/ir/ui/IrToolbar.tsx +36 -6
  117. package/src/ir/ui/index.ts +1 -0
  118. package/src/locales/de.json +2 -4
  119. package/src/locales/en.json +2 -4
  120. package/src/locales/es.json +2 -4
  121. package/src/locales/fr.json +2 -4
  122. package/src/locales/it.json +2 -4
  123. package/src/overlay/ui/OverlayPanel.tsx +8 -2
  124. package/src/overlay/ui/overlayPanelStyles.ts +3 -0
  125. package/src/periodic/ui/ElementCell.tsx +34 -37
  126. package/src/periodic/ui/PeriodicTable.tsx +12 -17
  127. package/lib/about/core/repository.d.ts +0 -14
  128. package/lib/about/core/repository.d.ts.map +0 -1
  129. package/lib/about/core/repository.js +0 -21
  130. package/lib/about/core/repository.js.map +0 -1
  131. package/lib/download/core/exportStyles.d.ts +0 -22
  132. package/lib/download/core/exportStyles.d.ts.map +0 -1
  133. package/lib/download/core/exportStyles.js +0 -19
  134. package/lib/download/core/exportStyles.js.map +0 -1
  135. package/lib/download/core/imageResolution.d.ts +0 -88
  136. package/lib/download/core/imageResolution.d.ts.map +0 -1
  137. package/lib/download/core/imageResolution.js +0 -77
  138. package/lib/download/core/imageResolution.js.map +0 -1
  139. package/lib/download/core/pictureExport.d.ts +0 -93
  140. package/lib/download/core/pictureExport.d.ts.map +0 -1
  141. package/lib/download/core/pictureExport.js +0 -116
  142. package/lib/download/core/pictureExport.js.map +0 -1
  143. package/lib/download/ui/ExportDialogFrame.d.ts +0 -46
  144. package/lib/download/ui/ExportDialogFrame.d.ts.map +0 -1
  145. package/lib/download/ui/ExportDialogFrame.js +0 -24
  146. package/lib/download/ui/ExportDialogFrame.js.map +0 -1
  147. package/lib/download/ui/ExportImageDialog.d.ts +0 -47
  148. package/lib/download/ui/ExportImageDialog.d.ts.map +0 -1
  149. package/lib/download/ui/ExportImageDialog.js +0 -25
  150. package/lib/download/ui/ExportImageDialog.js.map +0 -1
  151. package/lib/download/ui/ExportNameField.d.ts +0 -29
  152. package/lib/download/ui/ExportNameField.d.ts.map +0 -1
  153. package/lib/download/ui/ExportNameField.js +0 -99
  154. package/lib/download/ui/ExportNameField.js.map +0 -1
  155. package/lib/download/ui/ExportPictureSection.d.ts +0 -38
  156. package/lib/download/ui/ExportPictureSection.d.ts.map +0 -1
  157. package/lib/download/ui/ExportPictureSection.js +0 -48
  158. package/lib/download/ui/ExportPictureSection.js.map +0 -1
  159. package/lib/download/ui/useDrawingBox.d.ts +0 -23
  160. package/lib/download/ui/useDrawingBox.d.ts.map +0 -1
  161. package/lib/download/ui/useDrawingBox.js +0 -21
  162. package/lib/download/ui/useDrawingBox.js.map +0 -1
  163. package/src/about/core/repository.ts +0 -22
  164. package/src/download/core/exportStyles.ts +0 -20
  165. package/src/download/core/imageResolution.ts +0 -118
  166. package/src/download/core/pictureExport.ts +0 -207
  167. package/src/download/ui/ExportDialogFrame.tsx +0 -86
  168. package/src/download/ui/ExportImageDialog.tsx +0 -91
  169. package/src/download/ui/ExportNameField.tsx +0 -148
  170. package/src/download/ui/ExportPictureSection.tsx +0 -142
  171. package/src/download/ui/useDrawingBox.ts +0 -37
@@ -1,148 +0,0 @@
1
- import { useLayoutEffect, useRef } from 'react';
2
-
3
- import { TOKEN } from '../../tokens/core/familyTokens.ts';
4
-
5
- export interface ExportNameFieldProps {
6
- /** What is in the box, without an extension. */
7
- name: string;
8
- /**
9
- * The extension the file is about to take, shown after what is typed.
10
- * @default ''
11
- */
12
- extension?: string;
13
- /** Called with what was typed. */
14
- onChange: (name: string) => void;
15
- }
16
-
17
- /**
18
- * What the file about to be written out is called.
19
- *
20
- * It sits at the right of the row of buttons, against the one that writes the
21
- * file, because that is what it is about — copying takes no name, and puts
22
- * itself at the other end of the row. The name the editor came in with is
23
- * offered, since that is what a glycan is usually saved under, but a picture
24
- * for a slide and a molfile for a docking run are rarely wanted under it.
25
- *
26
- * The box grows with what is typed, so the extension sits directly against the
27
- * name and the two read as the one filename they are about to become. Held to a
28
- * fixed width instead, the extension hangs at the far edge with the gap between
29
- * them reading as part of neither.
30
- * @param props - Component props.
31
- * @returns The field.
32
- */
33
- export function ExportNameField(props: ExportNameFieldProps) {
34
- const { name, extension = '', onChange } = props;
35
-
36
- const input = useRef<HTMLInputElement>(null);
37
- const mirror = useRef<HTMLSpanElement>(null);
38
- const ruler = useRef<HTMLSpanElement>(null);
39
-
40
- // Measured off a copy of the text in the same font rather than counted in
41
- // characters, which only holds for a monospace one. The width is set on the
42
- // element instead of kept in state: it is what the browser has just measured,
43
- // so rendering again to store it would measure the same thing twice.
44
- useLayoutEffect(() => {
45
- if (!input.current || !mirror.current || !ruler.current) return;
46
- const measured = mirror.current.offsetWidth + CARET;
47
- const floor = ruler.current.offsetWidth;
48
- input.current.style.width = `${Math.min(Math.max(measured, floor), MAXIMUM)}px`;
49
- });
50
-
51
- return (
52
- <div style={fieldStyle}>
53
- <div className="bp6-input" style={boxStyle}>
54
- <input
55
- ref={input}
56
- value={name}
57
- aria-label="File name"
58
- placeholder={PLACEHOLDER}
59
- spellCheck={false}
60
- autoComplete="off"
61
- style={inputStyle}
62
- onChange={(event) => onChange(event.target.value)}
63
- // The name is in force as it is typed, so Enter has nothing left to
64
- // confirm — and is kept off the dialog, whose answer is to close.
65
- onKeyDown={(event) => {
66
- if (event.key === 'Enter') event.stopPropagation();
67
- }}
68
- />
69
- {extension === '' ? null : (
70
- <span style={extensionStyle}>{extension}</span>
71
- )}
72
- {/* Inside the box rather than beside it, so the copy the width is
73
- measured off is in the font the box gives its own text and not in
74
- whatever the dialog around it happens to use. */}
75
- <span ref={mirror} style={mirrorStyle} aria-hidden="true">
76
- {name === '' ? PLACEHOLDER : name}
77
- </span>
78
- <span ref={ruler} style={mirrorStyle} aria-hidden="true">
79
- {FLOOR_SAMPLE}
80
- </span>
81
- </div>
82
- </div>
83
- );
84
- }
85
-
86
- /** What the box says when nothing has been typed into it. */
87
- const PLACEHOLDER = 'File name';
88
-
89
- /** Room for the caret past the last character, so it is never clipped. */
90
- const CARET = 2;
91
-
92
- /**
93
- * Twenty characters, which the box is never narrower than.
94
- *
95
- * A name is typed into this box as often as it is read out of it, and a box cut
96
- * to `glycan` leaves no room to do that in — so the floor is a name of the
97
- * length one usually is, measured in the box's own font rather than counted at
98
- * some assumed character width. `n` is about the average width of a lowercase
99
- * letter, which is what a filename is mostly made of.
100
- */
101
- const FLOOR_SAMPLE = 'n'.repeat(20);
102
-
103
- /** Past this a name scrolls inside the box rather than pushing the dialog. */
104
- const MAXIMUM = 260;
105
-
106
- // Held against the right of the row beside the button that writes the file, so
107
- // the space in the row falls between copying and saving rather than inside the
108
- // name.
109
- const fieldStyle = { marginLeft: 'auto', flexShrink: 0 } as const;
110
-
111
- // Blueprint's own input chrome, worn by the box rather than by the field inside
112
- // it, so the name and the extension sit within one border. Positioned, so the
113
- // hidden copy the width is measured off can be taken out of the layout without
114
- // leaving the box it takes its font from.
115
- const boxStyle = {
116
- position: 'relative',
117
- display: 'flex',
118
- alignItems: 'center',
119
- width: 'fit-content',
120
- } as const;
121
-
122
- // The field itself brings nothing of its own: the box around it is what is
123
- // seen, and the text has to be in the font the width was measured in.
124
- const inputStyle = {
125
- font: 'inherit',
126
- border: 'none',
127
- outline: 'none',
128
- padding: 0,
129
- margin: 0,
130
- background: 'transparent',
131
- color: 'inherit',
132
- } as const;
133
-
134
- const extensionStyle = {
135
- color: TOKEN.textMuted,
136
- whiteSpace: 'pre',
137
- } as const;
138
-
139
- // A copy of what is typed, in the same font, laid out but never painted.
140
- const mirrorStyle = {
141
- position: 'absolute',
142
- top: 0,
143
- left: 0,
144
- visibility: 'hidden',
145
- pointerEvents: 'none',
146
- whiteSpace: 'pre',
147
- font: 'inherit',
148
- } as const;
@@ -1,142 +0,0 @@
1
- import { Button, HTMLSelect } from '@blueprintjs/core';
2
- import { useState } from 'react';
3
-
4
- import {
5
- exportButtonsStyle,
6
- exportNoteStyle,
7
- exportSectionStyle,
8
- } from '../core/exportStyles.ts';
9
- import {
10
- IMAGE_RESOLUTIONS,
11
- formatImageSize,
12
- imageResolution,
13
- } from '../core/imageResolution.ts';
14
- import type { PictureFrame } from '../core/pictureExport.ts';
15
- import {
16
- copyPicture,
17
- pictureSize,
18
- savePngPicture,
19
- saveSvgPicture,
20
- } from '../core/pictureExport.ts';
21
- import { sanitizeFileName } from '../core/sanitizeFileName.ts';
22
-
23
- import { ExportNameField } from './ExportNameField.tsx';
24
-
25
- export interface ExportPictureSectionProps {
26
- /** The drawing a picture is taken of, as it is rendered. */
27
- getDrawing: () => SVGSVGElement | null;
28
- /** Which of the resolutions is picked. */
29
- resolutionId: string;
30
- /** Called with the resolution that was picked. */
31
- onResolutionChange: (id: string) => void;
32
- /**
33
- * The name the name box opens on, and falls back to when it is cleared,
34
- * without its extension.
35
- */
36
- filename: string;
37
- /** What the picture is read out as in the file it is written to. */
38
- label: string;
39
- /**
40
- * Whether the picture is the drawing inside the element or the element as it
41
- * is laid out.
42
- * @default 'content'
43
- */
44
- frame?: PictureFrame;
45
- /** Called with what became of the last thing written out. */
46
- onStatus: (status: string) => void;
47
- }
48
-
49
- /**
50
- * The drawing as a picture: how big it comes out, and where it goes.
51
- *
52
- * The size the file will be is shown beside the resolution rather than after
53
- * the fact, since that is the number the choice is made on — a figure for a
54
- * paper and a thumbnail for a slide are the same drawing at very different
55
- * sizes. What is measured is what the picture will be of and not whatever is on
56
- * screen, so the answer does not change when the window is resized or the
57
- * drawing panned.
58
- * @param props - Component props.
59
- * @returns The section.
60
- */
61
- export function ExportPictureSection(props: ExportPictureSectionProps) {
62
- const {
63
- getDrawing,
64
- resolutionId,
65
- onResolutionChange,
66
- filename,
67
- label,
68
- frame,
69
- onStatus,
70
- } = props;
71
-
72
- const [name, setName] = useState(filename);
73
-
74
- const savedName = sanitizeFileName(name, filename);
75
- const { scale } = imageResolution(resolutionId);
76
- const size = pictureSize(getDrawing(), scale, { frame });
77
- const options = { scale, filename: savedName, label, frame };
78
-
79
- return (
80
- <section style={exportSectionStyle}>
81
- <div style={resolutionStyle}>
82
- <HTMLSelect
83
- value={resolutionId}
84
- aria-label="Resolution"
85
- onChange={(event) => onResolutionChange(event.currentTarget.value)}
86
- >
87
- {IMAGE_RESOLUTIONS.map((resolution) => (
88
- <option key={resolution.id} value={resolution.id}>
89
- {resolution.label}
90
- </option>
91
- ))}
92
- </HTMLSelect>
93
- <span style={exportNoteStyle}>{formatImageSize(size)}</span>
94
- </div>
95
- <div style={exportButtonsStyle}>
96
- <Button
97
- icon="duplicate"
98
- disabled={size === null}
99
- text="Copy PNG"
100
- onClick={() => {
101
- // The rasterization is started here rather than awaited: Safari
102
- // only allows a clipboard write the click itself started.
103
- void copyPicture(getDrawing(), options).then(
104
- (copied) =>
105
- onStatus(copied ? 'Picture copied.' : 'Nothing was copied.'),
106
- () => onStatus('Nothing was copied.'),
107
- );
108
- }}
109
- />
110
- <ExportNameField name={name} onChange={setName} />
111
- <Button
112
- icon="download"
113
- disabled={size === null}
114
- text="Save PNG"
115
- title={`Save as ${savedName}.png`}
116
- onClick={() => {
117
- void savePngPicture(getDrawing(), options).then((saved) => {
118
- if (saved) onStatus(`Saved as ${savedName}.png.`);
119
- });
120
- }}
121
- />
122
- <Button
123
- icon="download"
124
- disabled={size === null}
125
- text="Save SVG"
126
- title={`Save as ${savedName}.svg`}
127
- onClick={() => {
128
- if (saveSvgPicture(getDrawing(), options)) {
129
- onStatus(`Saved as ${savedName}.svg.`);
130
- }
131
- }}
132
- />
133
- </div>
134
- </section>
135
- );
136
- }
137
-
138
- const resolutionStyle = {
139
- display: 'flex',
140
- alignItems: 'center',
141
- gap: 8,
142
- } as const;
@@ -1,37 +0,0 @@
1
- import { useCallback, useRef } from 'react';
2
-
3
- import { drawingIn } from '../core/stackedDrawing.ts';
4
-
5
- /** The box a picture is taken out of. */
6
- export interface DrawingBox {
7
- /** Put on the box the drawing sits in, so it can be found again. */
8
- attach: (element: HTMLElement | null) => void;
9
- /**
10
- * The drawing a picture is taken of, `null` when the box holds none — which
11
- * is what an editor showing nothing yet, or one whose box has not been
12
- * mounted, hands the export dialog.
13
- */
14
- getDrawing: () => SVGSVGElement | null;
15
- }
16
-
17
- /**
18
- * Find the drawing a picture is to be taken of, when it is asked for.
19
- *
20
- * A drawing is laid out again on every resize, so the element itself is never
21
- * held onto: what is kept is the box it sits in, and the drawing is read out of
22
- * it at the moment a button is pressed. What counts as the drawing in there —
23
- * the one element for an editor showing one, the panes composed for an editor
24
- * showing a stack of charts — is `drawingIn`.
25
- * @returns The box to attach, and the drawing inside it.
26
- */
27
- export function useDrawingBox(): DrawingBox {
28
- const box = useRef<HTMLElement | null>(null);
29
-
30
- const attach = useCallback((element: HTMLElement | null) => {
31
- box.current = element;
32
- }, []);
33
-
34
- const getDrawing = useCallback(() => drawingIn(box.current), []);
35
-
36
- return { attach, getDrawing };
37
- }