react-cheminfo 0.41.0 → 0.43.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 (88) hide show
  1. package/bin/check-deploy.mjs +3 -1
  2. package/lib/chrome/ui/AboutButton.d.ts +59 -0
  3. package/lib/chrome/ui/AboutButton.d.ts.map +1 -0
  4. package/lib/chrome/ui/AboutButton.js +29 -0
  5. package/lib/chrome/ui/AboutButton.js.map +1 -0
  6. package/lib/chrome/ui/index.d.ts +2 -0
  7. package/lib/chrome/ui/index.d.ts.map +1 -1
  8. package/lib/chrome/ui/index.js +1 -0
  9. package/lib/chrome/ui/index.js.map +1 -1
  10. package/lib/deploy/core/buildGate.d.ts.map +1 -1
  11. package/lib/deploy/core/buildGate.js +4 -34
  12. package/lib/deploy/core/buildGate.js.map +1 -1
  13. package/lib/deploy/core/checkDeploy.d.ts.map +1 -1
  14. package/lib/deploy/core/checkDeploy.js +2 -0
  15. package/lib/deploy/core/checkDeploy.js.map +1 -1
  16. package/lib/deploy/core/index.d.ts +1 -0
  17. package/lib/deploy/core/index.d.ts.map +1 -1
  18. package/lib/deploy/core/index.js +1 -0
  19. package/lib/deploy/core/index.js.map +1 -1
  20. package/lib/deploy/core/json.d.ts +27 -0
  21. package/lib/deploy/core/json.d.ts.map +1 -0
  22. package/lib/deploy/core/json.js +56 -0
  23. package/lib/deploy/core/json.js.map +1 -0
  24. package/lib/deploy/core/reactCopies.d.ts +32 -0
  25. package/lib/deploy/core/reactCopies.d.ts.map +1 -0
  26. package/lib/deploy/core/reactCopies.js +212 -0
  27. package/lib/deploy/core/reactCopies.js.map +1 -0
  28. package/lib/deploy/core/types.d.ts +1 -1
  29. package/lib/deploy/core/types.d.ts.map +1 -1
  30. package/lib/deploy/core/types.js.map +1 -1
  31. package/lib/ecosystem/core/sites.d.ts.map +1 -1
  32. package/lib/ecosystem/core/sites.js +12 -0
  33. package/lib/ecosystem/core/sites.js.map +1 -1
  34. package/lib/ecosystem/core/types.d.ts +1 -1
  35. package/lib/ecosystem/core/types.d.ts.map +1 -1
  36. package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
  37. package/lib/ecosystem/ui/glyphs.js +4 -0
  38. package/lib/ecosystem/ui/glyphs.js.map +1 -1
  39. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  40. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  41. package/lib/locales/de.json +2 -0
  42. package/lib/locales/en.json +2 -0
  43. package/lib/locales/es.json +2 -0
  44. package/lib/locales/fr.json +2 -0
  45. package/lib/locales/it.json +2 -0
  46. package/lib/periodic/ui/ElementCell.d.ts +22 -2
  47. package/lib/periodic/ui/ElementCell.d.ts.map +1 -1
  48. package/lib/periodic/ui/ElementCell.js +20 -145
  49. package/lib/periodic/ui/ElementCell.js.map +1 -1
  50. package/lib/periodic/ui/PeriodicTable.d.ts +7 -0
  51. package/lib/periodic/ui/PeriodicTable.d.ts.map +1 -1
  52. package/lib/periodic/ui/PeriodicTable.js +21 -3
  53. package/lib/periodic/ui/PeriodicTable.js.map +1 -1
  54. package/lib/periodic/ui/cellStyles.d.ts +79 -0
  55. package/lib/periodic/ui/cellStyles.d.ts.map +1 -0
  56. package/lib/periodic/ui/cellStyles.js +90 -0
  57. package/lib/periodic/ui/cellStyles.js.map +1 -0
  58. package/lib/periodic/ui/cellType.d.ts +106 -0
  59. package/lib/periodic/ui/cellType.d.ts.map +1 -0
  60. package/lib/periodic/ui/cellType.js +181 -0
  61. package/lib/periodic/ui/cellType.js.map +1 -0
  62. package/lib/periodic/ui/glyphWidths.d.ts +11 -0
  63. package/lib/periodic/ui/glyphWidths.d.ts.map +1 -0
  64. package/lib/periodic/ui/glyphWidths.js +69 -0
  65. package/lib/periodic/ui/glyphWidths.js.map +1 -0
  66. package/package.json +9 -1
  67. package/src/chrome/ui/AboutButton.tsx +90 -0
  68. package/src/chrome/ui/index.ts +2 -0
  69. package/src/deploy/core/buildGate.ts +4 -35
  70. package/src/deploy/core/checkDeploy.ts +7 -0
  71. package/src/deploy/core/index.ts +1 -0
  72. package/src/deploy/core/json.ts +53 -0
  73. package/src/deploy/core/reactCopies.ts +243 -0
  74. package/src/deploy/core/types.ts +5 -1
  75. package/src/ecosystem/core/sites.ts +13 -0
  76. package/src/ecosystem/core/types.ts +2 -1
  77. package/src/ecosystem/ui/glyphs.tsx +16 -0
  78. package/src/locales/de.json +2 -0
  79. package/src/locales/en.json +2 -0
  80. package/src/locales/es.json +2 -0
  81. package/src/locales/fr.json +2 -0
  82. package/src/locales/it.json +2 -0
  83. package/src/periodic/ui/ElementCell.tsx +69 -160
  84. package/src/periodic/ui/PeriodicTable.tsx +37 -2
  85. package/src/periodic/ui/cellStyles.ts +100 -0
  86. package/src/periodic/ui/cellType.ts +223 -0
  87. package/src/periodic/ui/glyphWidths.ts +68 -0
  88. package/styles/chrome.css +10 -2
@@ -0,0 +1,223 @@
1
+ /**
2
+ * How large the writing in a cell is.
3
+ *
4
+ * Everything a cell holds is sized against the table's own width, so the same
5
+ * drawing reads at 280px beside a chart and across a lecture-hall screen.
6
+ *
7
+ * Nothing is ever trimmed: a value cut short by an ellipsis is a wrong value —
8
+ * `0.0899` read as `0.0…` is worse than not writing it at all. A line that is
9
+ * still too wide at the size its table writes is condensed instead, which keeps
10
+ * its height, its weight and its colour — the thing a reader compares two cells
11
+ * on — while giving back the width it was missing.
12
+ */
13
+
14
+ import { ADVANCE } from './glyphWidths.ts';
15
+ import { ofWidth } from './unit.ts';
16
+
17
+ /**
18
+ * How wide one line of text is, in per cent of the table's width.
19
+ *
20
+ * A column of the grid is 4.85% of it; this is what a cell leaves of that once
21
+ * its border and its padding are allowed for. One share rather than a share
22
+ * less a few pixels, because the size a line is written at and the width it
23
+ * then has are then the same arithmetic — which is what lets the scale that
24
+ * condenses an over-wide line be a plain number rather than a length only the
25
+ * engine can resolve.
26
+ */
27
+ const TEXT_SHARE = 4.5;
28
+
29
+ /** The column the electron counts stand in, as a share of the table's width. */
30
+ export const SHELLS_SHARE = 1.2;
31
+
32
+ /**
33
+ * The air between the symbol and that column, as a share of the table's width.
34
+ *
35
+ * Without it the widest symbols — `Md`, `Tm`, `Cm`, anything carrying an `M` or
36
+ * an `m` — are written at the cap and end a pixel from the first electron, and
37
+ * the cell reads as two things that collided rather than as two columns.
38
+ */
39
+ export const SHELLS_GAP = 0.5;
40
+
41
+ /** What the counts and their air together take off the width of a cell. */
42
+ export const SHELLS_RESERVED = SHELLS_SHARE + SHELLS_GAP;
43
+
44
+ /** Largest the third line is written, as a share of the table's width. */
45
+ const DETAIL_CAP = 1.5;
46
+
47
+ /**
48
+ * Smallest it is written, as a share of the table's width.
49
+ *
50
+ * Under this a name stops being readable at any table size, so the few names
51
+ * that do not fit are condensed rather than written smaller — the table keeps
52
+ * one size for all 118, which is what makes a column of them readable at a
53
+ * glance.
54
+ */
55
+ const DETAIL_FLOOR = 0.95;
56
+
57
+ /** What one tabular glyph advances, as a share of its own size. */
58
+ const TABULAR_EM = 0.6;
59
+
60
+ /** A string of digits, a decimal point, a sign, an exponent and nothing else. */
61
+ const NUMERIC = /^[\d\s.,+\-−×^eE]+$/u;
62
+
63
+ /** How the third line of a whole table is written. */
64
+ export interface DetailType {
65
+ /** Size every cell writes it at, as a CSS length. */
66
+ size: string;
67
+ /** How wide one em of it is, in shares of the table's width. */
68
+ sizeShare: number;
69
+ }
70
+
71
+ /**
72
+ * The one size a table writes its third line at.
73
+ *
74
+ * The largest at which the widest of them fits, between a floor and a cap: a
75
+ * table whose values are short writes them large, and one writing names writes
76
+ * every name at the size the longest needs.
77
+ * @param widths - How wide each line is, in ems of its own size.
78
+ * @param reservedShare - Width taken by the electron counts, as a share of the
79
+ * table's width; zero when none are written.
80
+ * @returns The size, as a CSS length and as the share it was computed from.
81
+ */
82
+ export function detailType(
83
+ widths: readonly number[],
84
+ reservedShare: number,
85
+ ): DetailType {
86
+ let widest = 1;
87
+ for (const width of widths) {
88
+ if (width > widest) widest = width;
89
+ }
90
+ const room = TEXT_SHARE - reservedShare;
91
+ const share = rounded(
92
+ Math.min(DETAIL_CAP, Math.max(DETAIL_FLOOR, room / widest)),
93
+ );
94
+ // A floor under which the type is not readable whatever the table is sized
95
+ // to, which is the one case the share alone does not cover.
96
+ return { size: `max(0.4rem, ${ofWidth(share)})`, sizeShare: share };
97
+ }
98
+
99
+ /**
100
+ * How much a line has to be condensed to fit its cell.
101
+ * @param widthInEm - How wide the line is, in ems of its own size.
102
+ * @param type - What the table writes its third line at.
103
+ * @param reservedShare - Width taken by the electron counts, as a share of the
104
+ * table's width; zero when none are written.
105
+ * @returns A horizontal scale, never above 1.
106
+ */
107
+ export function condensedScale(
108
+ widthInEm: number,
109
+ type: DetailType,
110
+ reservedShare: number,
111
+ ): number {
112
+ const room = TEXT_SHARE - reservedShare;
113
+ return Math.min(1, room / (widthInEm * type.sizeShare));
114
+ }
115
+
116
+ /**
117
+ * The size the symbol is written at.
118
+ *
119
+ * Every symbol is written at the same size, except the widest of them — the
120
+ * ones whose second letter is an `m` — which are written a tenth smaller rather
121
+ * than run into the edges of their cell.
122
+ * @param symbol - The chemical symbol.
123
+ * @param cap - Largest it is written, as a share of the table's width.
124
+ * @param reservedShare - Width taken by the electron counts, as a share of the
125
+ * table's width; zero when none are written.
126
+ * @returns A CSS length.
127
+ */
128
+ export function symbolFontSize(
129
+ symbol: string,
130
+ cap: number,
131
+ reservedShare: number,
132
+ ): string {
133
+ const room = TEXT_SHARE - reservedShare;
134
+ const share = rounded(Math.min(cap, room / (textWidthInEm(symbol) * BOLD)));
135
+ return `max(0.5rem, ${ofWidth(share)})`;
136
+ }
137
+
138
+ /**
139
+ * A share, at the precision a length is written to.
140
+ * @param share - The share, in per cent of the table's width.
141
+ * @returns The same share, rounded.
142
+ */
143
+ export function rounded(share: number): number {
144
+ return Number(share.toFixed(3));
145
+ }
146
+
147
+ /**
148
+ * How wide a string is, in ems of its own size.
149
+ *
150
+ * A value is written with tabular figures, where every glyph — the decimal
151
+ * point and the minus of an exponent included — advances the same width, so
152
+ * counting its characters is the measurement. A name is proportional, and is
153
+ * measured letter by letter: measured as figures, every name in the table would
154
+ * be sized for a width it does not have.
155
+ * @param text - The string.
156
+ * @returns Its width, never zero.
157
+ */
158
+ export function textWidthInEm(text: string): number {
159
+ if (NUMERIC.test(text)) return Math.max(text.length, 1) * TABULAR_EM * SAFETY;
160
+ let width = 0;
161
+ for (const character of text) {
162
+ width += glyphWidth(character);
163
+ }
164
+ return Math.max(width * SAFETY, TABULAR_EM);
165
+ }
166
+
167
+ /**
168
+ * How wide one glyph is, in ems.
169
+ *
170
+ * Measured in the family's own type rather than guessed at by class: the four
171
+ * classes a glyph can be sorted into put `Tm` an eighth wider than it is, which
172
+ * is a symbol written an eighth smaller than its cell can take.
173
+ * @param character - The glyph.
174
+ * @returns Its advance.
175
+ */
176
+ function glyphWidth(character: string): number {
177
+ const measured = ADVANCE[character];
178
+ if (measured !== undefined) return measured;
179
+ return character >= 'a' && character <= 'z' ? 0.54 : 0.65;
180
+ }
181
+
182
+ /** What is added to every measurement, for the faces this one stands in for. */
183
+ const SAFETY = 1.04;
184
+
185
+ /** How much wider the same string is when it is set bold, as the symbol is. */
186
+ const BOLD = 1.08;
187
+
188
+ /**
189
+ * The size a stack of electron counts is written at.
190
+ *
191
+ * Seven shells have to stand in the height of one cell, so the size is what
192
+ * the deepest stack of the table leaves — francium's seven, wherever the table
193
+ * writes any.
194
+ * @param count - How many shells stand in the tallest stack.
195
+ * @returns A CSS length.
196
+ */
197
+ export function shellFontSize(count: number): string {
198
+ const share = rounded(
199
+ Math.min(SHELL_CAP, ROW_SHARE / (Math.max(count, 1) * SHELL_LEADING)),
200
+ );
201
+ return `max(0.3rem, ${ofWidth(share)})`;
202
+ }
203
+
204
+ /**
205
+ * A horizontal scale, written as a transform.
206
+ * @param scale - The scale, from {@link condensedScale}.
207
+ * @returns The transform, or nothing at all when the line fits as it is.
208
+ */
209
+ export function scaleX(scale: number): string | undefined {
210
+ return scale >= 1 ? undefined : `scaleX(${scale.toFixed(3)})`;
211
+ }
212
+
213
+ /** The size the symbol is written at wherever it fits, as a share of the table. */
214
+ export const SYMBOL_CAP = 2.1;
215
+
216
+ /** How tall one row of the table is, as a share of its width. */
217
+ export const ROW_SHARE = 6.8;
218
+
219
+ /** The size the electron counts are written at where they have the room. */
220
+ const SHELL_CAP = 1.1;
221
+
222
+ /** The height one of them takes, in ems of its own size. */
223
+ export const SHELL_LEADING = 1.2;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * What each letter advances, in ems, in the family's type.
3
+ *
4
+ * Read off the rendered page at 100px, rounded up, because sorting a glyph into
5
+ * one of four width classes puts `Tm` an eighth wider than it is — which is a
6
+ * symbol written an eighth smaller than its cell can take. A platform
7
+ * substituting another face moves these by a few per cent, which the safety
8
+ * margin of `cellType` covers.
9
+ */
10
+ export const ADVANCE: Record<string, number> = {
11
+ a: 0.5,
12
+ b: 0.57,
13
+ c: 0.52,
14
+ d: 0.57,
15
+ e: 0.52,
16
+ f: 0.33,
17
+ g: 0.56,
18
+ h: 0.54,
19
+ i: 0.22,
20
+ j: 0.22,
21
+ k: 0.5,
22
+ l: 0.23,
23
+ m: 0.8,
24
+ n: 0.54,
25
+ o: 0.54,
26
+ p: 0.56,
27
+ q: 0.56,
28
+ r: 0.35,
29
+ s: 0.47,
30
+ t: 0.33,
31
+ u: 0.54,
32
+ v: 0.5,
33
+ w: 0.72,
34
+ x: 0.48,
35
+ y: 0.5,
36
+ z: 0.5,
37
+ A: 0.62,
38
+ B: 0.6,
39
+ C: 0.66,
40
+ D: 0.67,
41
+ E: 0.55,
42
+ F: 0.53,
43
+ G: 0.69,
44
+ H: 0.69,
45
+ I: 0.24,
46
+ J: 0.49,
47
+ K: 0.6,
48
+ L: 0.52,
49
+ M: 0.81,
50
+ N: 0.69,
51
+ O: 0.71,
52
+ P: 0.59,
53
+ Q: 0.71,
54
+ R: 0.6,
55
+ S: 0.59,
56
+ T: 0.59,
57
+ U: 0.68,
58
+ V: 0.62,
59
+ W: 0.9,
60
+ X: 0.62,
61
+ Y: 0.6,
62
+ Z: 0.61,
63
+ ' ': 0.27,
64
+ '-': 0.33,
65
+ '–': 0.54,
66
+ '.': 0.25,
67
+ ',': 0.25,
68
+ };
package/styles/chrome.css CHANGED
@@ -374,8 +374,12 @@ button {
374
374
  nothing to push them there. */
375
375
  .share-linkbar {
376
376
  display: flex;
377
+ /* They keep the right edge while there is room, and wrap under each other
378
+ rather than off the dialog once there is not. */
379
+ flex: 0 1 auto;
380
+ flex-wrap: wrap;
377
381
  align-items: center;
378
- flex: 0 0 auto;
382
+ justify-content: flex-end;
379
383
  margin-left: auto;
380
384
  gap: 8px;
381
385
  }
@@ -588,7 +592,11 @@ button {
588
592
  frames at 1920 is one they check at 1920. */
589
593
  .share-dialog.bp6-dialog {
590
594
  overflow: hidden;
591
- min-width: 480px;
595
+ /* The floor is what a drag may shrink the dialog to, so it must not also
596
+ apply to a screen narrower than it: at 480px the dialog stopped shrinking
597
+ and was clipped on both sides, with no horizontal scroll to reach what was
598
+ cut — the iframe snippet and the part checkboxes, on every phone. */
599
+ min-width: min(480px, 96vw);
592
600
  min-height: 420px;
593
601
  max-width: 98vw;
594
602
  max-height: 96dvh;