react-cheminfo 0.136.0 → 0.138.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 (107) hide show
  1. package/README.md +1 -1
  2. package/lib/crystal3d/core/crystalView.d.ts +10 -0
  3. package/lib/crystal3d/core/crystalView.d.ts.map +1 -1
  4. package/lib/crystal3d/core/crystalView.js +7 -0
  5. package/lib/crystal3d/core/crystalView.js.map +1 -1
  6. package/lib/crystal3d/core/index.d.ts +2 -2
  7. package/lib/crystal3d/core/index.d.ts.map +1 -1
  8. package/lib/crystal3d/core/index.js +1 -1
  9. package/lib/crystal3d/core/index.js.map +1 -1
  10. package/lib/crystal3d/ui/CrystalCanvas3D.d.ts.map +1 -1
  11. package/lib/crystal3d/ui/CrystalCanvas3D.js +9 -1
  12. package/lib/crystal3d/ui/CrystalCanvas3D.js.map +1 -1
  13. package/lib/crystal3d/ui/CrystalStructureView.js +5 -2
  14. package/lib/crystal3d/ui/CrystalStructureView.js.map +1 -1
  15. package/lib/crystal3d/ui/CrystalViewControls.d.ts +7 -3
  16. package/lib/crystal3d/ui/CrystalViewControls.d.ts.map +1 -1
  17. package/lib/crystal3d/ui/CrystalViewControls.js +6 -4
  18. package/lib/crystal3d/ui/CrystalViewControls.js.map +1 -1
  19. package/lib/crystal3d/ui/crystalScene.d.ts +6 -0
  20. package/lib/crystal3d/ui/crystalScene.d.ts.map +1 -1
  21. package/lib/crystal3d/viewer/renderStructure.d.ts +25 -0
  22. package/lib/crystal3d/viewer/renderStructure.d.ts.map +1 -1
  23. package/lib/crystal3d/viewer/renderStructure.js +41 -1
  24. package/lib/crystal3d/viewer/renderStructure.js.map +1 -1
  25. package/lib/crystal3d/viewer/viewer.d.ts +11 -2
  26. package/lib/crystal3d/viewer/viewer.d.ts.map +1 -1
  27. package/lib/crystal3d/viewer/viewer.js +17 -2
  28. package/lib/crystal3d/viewer/viewer.js.map +1 -1
  29. package/lib/download/core/croppedMarkup.d.ts.map +1 -1
  30. package/lib/download/core/croppedMarkup.js +16 -40
  31. package/lib/download/core/croppedMarkup.js.map +1 -1
  32. package/lib/download/core/dataUrl.d.ts +27 -0
  33. package/lib/download/core/dataUrl.d.ts.map +1 -0
  34. package/lib/download/core/dataUrl.js +54 -0
  35. package/lib/download/core/dataUrl.js.map +1 -0
  36. package/lib/download/core/index.d.ts +3 -0
  37. package/lib/download/core/index.d.ts.map +1 -1
  38. package/lib/download/core/index.js +2 -0
  39. package/lib/download/core/index.js.map +1 -1
  40. package/lib/download/core/svgMarkup.d.ts +39 -0
  41. package/lib/download/core/svgMarkup.d.ts.map +1 -0
  42. package/lib/download/core/svgMarkup.js +100 -0
  43. package/lib/download/core/svgMarkup.js.map +1 -0
  44. package/lib/drawing/render/motion.d.ts +2 -2
  45. package/lib/drawing/render/motion.d.ts.map +1 -1
  46. package/lib/drawing/render/motion.js +23 -4
  47. package/lib/drawing/render/motion.js.map +1 -1
  48. package/lib/drawing/render/primitives.d.ts +14 -0
  49. package/lib/drawing/render/primitives.d.ts.map +1 -1
  50. package/lib/drawing/render/svg.d.ts.map +1 -1
  51. package/lib/drawing/render/svg.js +27 -7
  52. package/lib/drawing/render/svg.js.map +1 -1
  53. package/lib/drawing/ui/movingFigure.d.ts.map +1 -1
  54. package/lib/drawing/ui/movingFigure.js +4 -30
  55. package/lib/drawing/ui/movingFigure.js.map +1 -1
  56. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  57. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  58. package/lib/locales/de.json +7 -0
  59. package/lib/locales/en.json +7 -0
  60. package/lib/locales/es.json +7 -0
  61. package/lib/locales/fr.json +7 -0
  62. package/lib/locales/it.json +7 -0
  63. package/lib/referents/core/figureReferents.d.ts +3 -2
  64. package/lib/referents/core/figureReferents.d.ts.map +1 -1
  65. package/lib/referents/core/figureReferents.js +6 -3
  66. package/lib/referents/core/figureReferents.js.map +1 -1
  67. package/lib/referents/core/index.d.ts +1 -0
  68. package/lib/referents/core/index.d.ts.map +1 -1
  69. package/lib/referents/core/index.js +1 -0
  70. package/lib/referents/core/index.js.map +1 -1
  71. package/lib/referents/core/quoteParts.d.ts +21 -0
  72. package/lib/referents/core/quoteParts.d.ts.map +1 -0
  73. package/lib/referents/core/quoteParts.js +71 -0
  74. package/lib/referents/core/quoteParts.js.map +1 -0
  75. package/lib/referents/core/readReferents.d.ts +2 -1
  76. package/lib/referents/core/readReferents.d.ts.map +1 -1
  77. package/lib/referents/core/readReferents.js +28 -2
  78. package/lib/referents/core/readReferents.js.map +1 -1
  79. package/lib/referents/core/types.d.ts +44 -0
  80. package/lib/referents/core/types.d.ts.map +1 -1
  81. package/package.json +1 -1
  82. package/src/crystal3d/core/crystalView.ts +17 -0
  83. package/src/crystal3d/core/index.ts +2 -0
  84. package/src/crystal3d/ui/CrystalCanvas3D.tsx +9 -0
  85. package/src/crystal3d/ui/CrystalStructureView.tsx +7 -2
  86. package/src/crystal3d/ui/CrystalViewControls.tsx +33 -4
  87. package/src/crystal3d/ui/crystalScene.ts +6 -0
  88. package/src/crystal3d/viewer/renderStructure.ts +66 -1
  89. package/src/crystal3d/viewer/viewer.ts +19 -3
  90. package/src/download/core/croppedMarkup.ts +16 -42
  91. package/src/download/core/dataUrl.ts +59 -0
  92. package/src/download/core/index.ts +3 -0
  93. package/src/download/core/svgMarkup.ts +113 -0
  94. package/src/drawing/render/motion.ts +23 -4
  95. package/src/drawing/render/primitives.ts +14 -0
  96. package/src/drawing/render/svg.ts +34 -7
  97. package/src/drawing/ui/movingFigure.ts +4 -28
  98. package/src/locales/de.json +7 -0
  99. package/src/locales/en.json +7 -0
  100. package/src/locales/es.json +7 -0
  101. package/src/locales/fr.json +7 -0
  102. package/src/locales/it.json +7 -0
  103. package/src/referents/core/figureReferents.ts +8 -3
  104. package/src/referents/core/index.ts +1 -0
  105. package/src/referents/core/quoteParts.ts +82 -0
  106. package/src/referents/core/readReferents.ts +27 -2
  107. package/src/referents/core/types.ts +45 -0
@@ -7,6 +7,7 @@
7
7
  import type { FigurePixels } from './figureScale.ts';
8
8
  import type { FigureSvg } from './figureSvg.ts';
9
9
  import type { SvgBox } from './svgBounds.ts';
10
+ import { svgAttribute, svgRootTag, svgViewBox } from './svgMarkup.ts';
10
11
 
11
12
  /** An SVG whose only element is one image. */
12
13
  const ONLY_IMAGE =
@@ -36,14 +37,14 @@ export function rasterFigureSource(markup: string): RasterFigureSource | null {
36
37
  if (image === undefined || /\s(?:x|y|transform)\s*=/.test(image)) {
37
38
  return null;
38
39
  }
39
- const root = rootTag(markup);
40
- const width = Number(attribute(image, 'width'));
41
- const height = Number(attribute(image, 'height'));
40
+ const root = svgRootTag(markup);
41
+ const width = Number(svgAttribute(image, 'width'));
42
+ const height = Number(svgAttribute(image, 'height'));
42
43
  if (!(width > 0 && height > 0)) return null;
43
44
  const sameSize =
44
- Number(attribute(root, 'width')) === width &&
45
- Number(attribute(root, 'height')) === height;
46
- const view = attribute(root, 'viewBox');
45
+ Number(svgAttribute(root, 'width')) === width &&
46
+ Number(svgAttribute(root, 'height')) === height;
47
+ const view = svgAttribute(root, 'viewBox');
47
48
  const sameView =
48
49
  view === undefined ||
49
50
  view
@@ -52,7 +53,7 @@ export function rasterFigureSource(markup: string): RasterFigureSource | null {
52
53
  .map(Number)
53
54
  .join(' ') === `0 0 ${width} ${height}`;
54
55
  const source = (
55
- attribute(image, 'href') ?? attribute(image, 'xlink:href')
56
+ svgAttribute(image, 'href') ?? svgAttribute(image, 'xlink:href')
56
57
  )?.replaceAll('&', '&');
57
58
  if (!sameSize || !sameView || !source?.startsWith('data:image/')) {
58
59
  return null;
@@ -68,10 +69,10 @@ export function rasterFigureSource(markup: string): RasterFigureSource | null {
68
69
  * @returns The figure, or `undefined` when the SVG states no size in pixels.
69
70
  */
70
71
  export function svgFigure(markup: string): FigureSvg | undefined {
71
- const root = rootTag(markup);
72
- const view = viewBoxOf(attribute(root, 'viewBox'));
73
- const width = pixels(attribute(root, 'width')) ?? view?.width;
74
- const height = pixels(attribute(root, 'height')) ?? view?.height;
72
+ const root = svgRootTag(markup);
73
+ const view = svgViewBox(svgAttribute(root, 'viewBox'));
74
+ const width = pixels(svgAttribute(root, 'width')) ?? view?.width;
75
+ const height = pixels(svgAttribute(root, 'height')) ?? view?.height;
75
76
  if (width === undefined || height === undefined) return undefined;
76
77
  return { markup, width: Math.ceil(width), height: Math.ceil(height) };
77
78
  }
@@ -89,8 +90,8 @@ export function croppedSvgMarkup(
89
90
  figure: FigureSvg,
90
91
  box: SvgBox,
91
92
  ): FigureSvg | null {
92
- const root = rootTag(figure.markup);
93
- const view = viewBoxOf(attribute(root, 'viewBox')) ?? {
93
+ const root = svgRootTag(figure.markup);
94
+ const view = svgViewBox(svgAttribute(root, 'viewBox')) ?? {
94
95
  x: 0,
95
96
  y: 0,
96
97
  width: figure.width,
@@ -133,8 +134,8 @@ export function resizedSvgFigure(
133
134
  figure: FigureSvg,
134
135
  size: FigurePixels,
135
136
  ): FigureSvg {
136
- const root = rootTag(figure.markup);
137
- const view = viewBoxOf(attribute(root, 'viewBox')) ?? {
137
+ const root = svgRootTag(figure.markup);
138
+ const view = svgViewBox(svgAttribute(root, 'viewBox')) ?? {
138
139
  x: 0,
139
140
  y: 0,
140
141
  width: figure.width,
@@ -164,33 +165,6 @@ export function rounded(value: number): number {
164
165
  return Object.is(result, -0) ? 0 : result;
165
166
  }
166
167
 
167
- function rootTag(markup: string): string {
168
- return /<svg\b[^>]*>/i.exec(markup)?.[0] ?? '';
169
- }
170
-
171
- function attribute(tag: string, name: string): string | undefined {
172
- const pattern = new RegExp(
173
- String.raw`\s${name}\s*=\s*(?:"(?<double>[^"]*)"|'(?<single>[^']*)')`,
174
- );
175
- const groups = pattern.exec(tag)?.groups;
176
- return groups?.double ?? groups?.single;
177
- }
178
-
179
- function viewBoxOf(value: string | undefined): SvgBox | undefined {
180
- if (value === undefined) return undefined;
181
- const parts = value
182
- .trim()
183
- .split(/[\s,]+/)
184
- .map(Number);
185
- const [x, y, width, height] = parts;
186
- if (parts.length !== 4 || x === undefined || y === undefined) {
187
- return undefined;
188
- }
189
- if (!Number.isFinite(x) || !Number.isFinite(y)) return undefined;
190
- if (!width || !height || !(width > 0) || !(height > 0)) return undefined;
191
- return { x, y, width, height };
192
- }
193
-
194
168
  function pixels(value: string | undefined): number | undefined {
195
169
  const match = /^\s*(?<number>[\d.]+)\s*(?:px)?\s*$/.exec(value ?? '');
196
170
  const number = Number(match?.groups?.number);
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Pictures as `data:` URLs, the way a document holds them: a file read into
3
+ * one, an SVG written into one, and an SVG read back out of one — without a
4
+ * `FileReader` or a `fetch`, so it runs in a worker, under a content security
5
+ * policy forbidding `data:` fetches, and in Node.
6
+ */
7
+
8
+ import { decode, encode } from 'uint8-base64';
9
+
10
+ /** The type of an SVG picture. */
11
+ const SVG_TYPE = 'image/svg+xml';
12
+
13
+ /**
14
+ * A blob as a base64 `data:` URL, as a `FileReader` writes it.
15
+ * @param blob - The blob, its `type` naming what it holds.
16
+ * @returns The URL.
17
+ */
18
+ export async function blobDataUrl(blob: Blob): Promise<string> {
19
+ const type = blob.type || 'application/octet-stream';
20
+ const bytes = new Uint8Array(await blob.arrayBuffer());
21
+ return `data:${type};base64,${base64(bytes)}`;
22
+ }
23
+
24
+ /**
25
+ * An SVG as a base64 `data:` URL: what a document stores for a picture.
26
+ * @param svg - The SVG document.
27
+ * @returns The URL.
28
+ */
29
+ export function svgDataUrl(svg: string): string {
30
+ return `data:${SVG_TYPE};base64,${base64(new TextEncoder().encode(svg))}`;
31
+ }
32
+
33
+ /**
34
+ * The SVG document a `data:` URL holds, whether written in base64 or
35
+ * percent-encoded.
36
+ * @param src - The URL.
37
+ * @returns The SVG's text, or `undefined` for any other picture, or for a URL
38
+ * that cannot be decoded.
39
+ */
40
+ export function svgOfDataUrl(src: string): string | undefined {
41
+ const match = /^data:image\/svg\+xml(?<parameters>[^,]*),(?<data>.*)$/is.exec(
42
+ src,
43
+ );
44
+ if (!match?.groups) return undefined;
45
+ const { parameters = '', data = '' } = match.groups;
46
+ try {
47
+ if (!parameters.toLowerCase().endsWith(';base64')) {
48
+ return decodeURIComponent(data);
49
+ }
50
+ const text = new TextEncoder().encode(data.replaceAll(/\s/g, ''));
51
+ return new TextDecoder().decode(decode(text));
52
+ } catch {
53
+ return undefined;
54
+ }
55
+ }
56
+
57
+ function base64(bytes: Uint8Array): string {
58
+ return new TextDecoder().decode(encode(bytes));
59
+ }
@@ -49,6 +49,8 @@ export {
49
49
  setPageFigureSource,
50
50
  withPageFigureSource,
51
51
  } from './pageFigureSource.ts';
52
+ export type { SvgSize } from './svgMarkup.ts';
53
+ export { svgSizeInPoints } from './svgMarkup.ts';
52
54
  export type { RasterFigureSource } from './croppedMarkup.ts';
53
55
  export {
54
56
  croppedSvgMarkup,
@@ -57,6 +59,7 @@ export {
57
59
  svgFigure,
58
60
  } from './croppedMarkup.ts';
59
61
  export { cssTokenNames, resolveCssTokens } from './cssTokens.ts';
62
+ export { blobDataUrl, svgDataUrl, svgOfDataUrl } from './dataUrl.ts';
60
63
  export type { DocumentFigureRedraw } from './documentFigure.ts';
61
64
  export {
62
65
  DOCUMENT_FIGURE_SIZE,
@@ -0,0 +1,113 @@
1
+ /**
2
+ * What an SVG document says about itself, read from its text without a
3
+ * browser: the size it asks to be drawn at, and the attributes of its root.
4
+ */
5
+
6
+ import type { SvgBox } from './svgBounds.ts';
7
+
8
+ /** A width and a height, in points. */
9
+ export interface SvgSize {
10
+ /** Width, in points. */
11
+ width: number;
12
+ /** Height, in points. */
13
+ height: number;
14
+ }
15
+
16
+ /** Points in a CSS pixel, the unit of a length written without one. */
17
+ const PIXEL = 0.75;
18
+
19
+ /** The size a browser gives an SVG that states none, in CSS pixels. */
20
+ const DEFAULT_SIZE = { width: 300, height: 150 };
21
+
22
+ /** Points in one unit of each length an SVG may state its size in. */
23
+ const POINTS_PER_UNIT: Readonly<Record<string, number>> = {
24
+ '': PIXEL,
25
+ px: PIXEL,
26
+ pt: 1,
27
+ pc: 12,
28
+ in: 72,
29
+ cm: 72 / 2.54,
30
+ mm: 72 / 25.4,
31
+ q: 72 / 101.6,
32
+ em: 12,
33
+ ex: 6,
34
+ };
35
+
36
+ /**
37
+ * The size an SVG asks to be drawn at: its width and height, completed from
38
+ * its view box when one of them is missing, or a browser's 300 × 150 pixels.
39
+ * @param svg - The SVG document.
40
+ * @returns Its size, in points.
41
+ */
42
+ export function svgSizeInPoints(svg: string): SvgSize {
43
+ const root = svgRootTag(svg);
44
+ const width = lengthInPoints(svgAttribute(root, 'width'));
45
+ const height = lengthInPoints(svgAttribute(root, 'height'));
46
+ const box = svgViewBox(svgAttribute(root, 'viewBox'));
47
+ if (width && height) return { width, height };
48
+ if (box) {
49
+ if (width) return { width, height: (width * box.height) / box.width };
50
+ if (height) return { width: (height * box.width) / box.height, height };
51
+ return { width: box.width * PIXEL, height: box.height * PIXEL };
52
+ }
53
+ return {
54
+ width: width ?? DEFAULT_SIZE.width * PIXEL,
55
+ height: height ?? DEFAULT_SIZE.height * PIXEL,
56
+ };
57
+ }
58
+
59
+ /**
60
+ * The opening tag of an SVG's root element.
61
+ * @param svg - The SVG document.
62
+ * @returns The tag, or an empty string when there is none.
63
+ */
64
+ export function svgRootTag(svg: string): string {
65
+ return /<svg\b[^>]*>/i.exec(svg)?.[0] ?? '';
66
+ }
67
+
68
+ /**
69
+ * The value of an attribute written in a tag.
70
+ * @param tag - The tag.
71
+ * @param name - The attribute.
72
+ * @returns Its value, or `undefined` when the tag does not write it.
73
+ */
74
+ export function svgAttribute(tag: string, name: string): string | undefined {
75
+ const pattern = new RegExp(
76
+ String.raw`\s${name}\s*=\s*(?:"(?<double>[^"]*)"|'(?<single>[^']*)')`,
77
+ );
78
+ const groups = pattern.exec(tag)?.groups;
79
+ return groups?.double ?? groups?.single;
80
+ }
81
+
82
+ /**
83
+ * A `viewBox` attribute read as a rectangle.
84
+ * @param value - The attribute's value.
85
+ * @returns The rectangle, or `undefined` when it is missing or draws nothing.
86
+ */
87
+ export function svgViewBox(value: string | undefined): SvgBox | undefined {
88
+ if (value === undefined) return undefined;
89
+ const parts = value
90
+ .trim()
91
+ .split(/[\s,]+/)
92
+ .map(Number);
93
+ const [x, y, width, height] = parts;
94
+ if (parts.length !== 4 || x === undefined || y === undefined) {
95
+ return undefined;
96
+ }
97
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return undefined;
98
+ if (!width || !height || !(width > 0) || !(height > 0)) return undefined;
99
+ return { x, y, width, height };
100
+ }
101
+
102
+ function lengthInPoints(value: string | undefined): number | undefined {
103
+ if (value === undefined) return undefined;
104
+ const match =
105
+ /^\s*(?<amount>[+]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s*(?<unit>[a-z]*)\s*$/i.exec(
106
+ value,
107
+ );
108
+ if (!match?.groups) return undefined;
109
+ const factor = POINTS_PER_UNIT[match.groups.unit?.toLowerCase() ?? ''];
110
+ const amount = Number(match.groups.amount);
111
+ if (factor === undefined || !(amount > 0)) return undefined;
112
+ return amount * factor;
113
+ }
@@ -111,6 +111,23 @@ export const MOTION_CSS = `/* A bubble rises from where it is drawn, three of it
111
111
  }
112
112
  }
113
113
 
114
+ /* A piece an orbital shaker swirls, seen edge on: it sways from one side of
115
+ the orbit to the other and back, a round trip a third of a second long, as
116
+ at 180 rpm. */
117
+ [data-motion='moving'] .glass-swirling {
118
+ animation: glass-swirl 0.167s ease-in-out infinite alternate;
119
+ }
120
+
121
+ @keyframes glass-swirl {
122
+ from {
123
+ transform: translateX(calc(-1 * var(--glass-orbit)));
124
+ }
125
+
126
+ to {
127
+ transform: translateX(var(--glass-orbit));
128
+ }
129
+ }
130
+
114
131
  /* A figure carries each bubble running along water, and each drop falling, as
115
132
  a run that only shows moving (written hidden, for a program that reads no
116
133
  style), and the ones drawn where they stand as a still copy that only shows
@@ -126,7 +143,8 @@ export const MOTION_CSS = `/* A bubble rises from where it is drawn, three of it
126
143
  @media print, (prefers-reduced-motion: reduce) {
127
144
  .glass-bubble,
128
145
  .glass-turning,
129
- .glass-spinning {
146
+ .glass-spinning,
147
+ .glass-swirling {
130
148
  animation: none;
131
149
  }
132
150
 
@@ -175,19 +193,20 @@ export function runTiming(flow: NonNullable<PathPrimitive['flow']>): {
175
193
 
176
194
  /**
177
195
  * Whether a scene has anything that moves: a bubble, a run, a turning piece,
178
- * a spinning rotor.
196
+ * a spinning rotor, a piece an orbital shaker swirls.
179
197
  * @param scene - The scene.
180
198
  * @returns True when a figure of it can be set moving.
181
199
  */
182
200
  export function sceneMoves(scene: Scene): boolean {
183
201
  for (const item of scene.items) {
184
- if (item.turning !== undefined) return true;
202
+ if (item.turning !== undefined || item.swirling !== undefined) return true;
185
203
  for (const primitive of item.primitives) {
186
204
  if (
187
205
  primitive.kind === 'path' &&
188
206
  (primitive.flow !== undefined ||
189
207
  primitive.bubble !== undefined ||
190
- primitive.spins !== undefined)
208
+ primitive.spins !== undefined ||
209
+ primitive.swirls !== undefined)
191
210
  ) {
192
211
  return true;
193
212
  }
@@ -92,6 +92,13 @@ export interface PathPrimitive {
92
92
  * @default undefined — the whole piece turns, as a stir bar does
93
93
  */
94
94
  turns?: true;
95
+ /**
96
+ * Whether it alone swirls while its piece runs, the rest still: the
97
+ * platform of an orbital shaker, over its casing. Set moving it swirls; a
98
+ * file holds it still.
99
+ * @default undefined — the whole piece swirls, as a flask on the platform does
100
+ */
101
+ swirls?: true;
95
102
  /**
96
103
  * The way it spins in its own plane while its piece runs, with the
97
104
  * primitives drawn next to it that spin the same way, about the middle of
@@ -223,6 +230,13 @@ export interface SceneItem<K extends string = string> {
223
230
  * @default undefined — it stays still
224
231
  */
225
232
  turning?: number;
233
+ /**
234
+ * For what an orbital shaker swirls, the radius of its orbit, in points:
235
+ * set moving, it circles the orbit, seen edge on as a sway from one side
236
+ * to the other; a file holds it still.
237
+ * @default undefined — it stays still
238
+ */
239
+ swirling?: number;
226
240
  }
227
241
 
228
242
  /** A whole rendered drawing. */
@@ -181,20 +181,47 @@ function itemMarkup(item: SceneItem, options: SvgOptions): string {
181
181
  : inner.join('');
182
182
  })
183
183
  .join('');
184
- // A piece whose paddle alone turns keeps the rest still.
185
- if (item.turning !== undefined && item.primitives.some(turnsAlone)) {
186
- const still = item.primitives.filter((primitive) => !turnsAlone(primitive));
187
- const paddle = item.primitives.filter(turnsAlone);
188
- return `<g cd:${kind}="${id}"${label}${ink}${faded}>${markup(still)}<g${turningMarkup(item.turning)}>${markup(paddle)}</g></g>`;
184
+ const motion = motionOf(item);
185
+ // A piece whose paddle or platform alone moves keeps the rest still.
186
+ if (motion && item.primitives.some(motion.alone)) {
187
+ const still = item.primitives.filter(
188
+ (primitive) => !motion.alone(primitive),
189
+ );
190
+ const moving = item.primitives.filter(motion.alone);
191
+ return `<g cd:${kind}="${id}"${label}${ink}${faded}>${markup(still)}<g${motion.markup}>${markup(moving)}</g></g>`;
189
192
  }
190
- const turning = item.turning === undefined ? '' : turningMarkup(item.turning);
191
- return `<g cd:${kind}="${id}"${label}${ink}${faded}${turning}>${markup(item.primitives)}</g>`;
193
+ const whole = motion?.markup ?? '';
194
+ return `<g cd:${kind}="${id}"${label}${ink}${faded}${whole}>${markup(item.primitives)}</g>`;
195
+ }
196
+
197
+ // How a piece moves, and which of its primitives move alone when some do: a
198
+ // stir bar turns, a stirrer's paddle under its shaft; a flask on an orbital
199
+ // shaker swirls, the shaker's platform over its casing.
200
+ function motionOf(
201
+ item: SceneItem,
202
+ ): { markup: string; alone: (primitive: Primitive) => boolean } | undefined {
203
+ if (item.turning !== undefined) {
204
+ return { markup: turningMarkup(item.turning), alone: turnsAlone };
205
+ }
206
+ if (item.swirling !== undefined) {
207
+ return { markup: swirlingMarkup(item.swirling), alone: swirlsAlone };
208
+ }
209
+ return undefined;
192
210
  }
193
211
 
194
212
  function turnsAlone(primitive: Primitive): boolean {
195
213
  return primitive.kind === 'path' && primitive.turns === true;
196
214
  }
197
215
 
216
+ function swirlsAlone(primitive: Primitive): boolean {
217
+ return primitive.kind === 'path' && primitive.swirls === true;
218
+ }
219
+
220
+ // What sets a piece swirling on the orbit of an orbital shaker.
221
+ function swirlingMarkup(orbit: number): string {
222
+ return ` class="glass-swirling" style="--glass-orbit: ${number(orbit)}px"`;
223
+ }
224
+
198
225
  // What sets a stir bar turning about the upright, the way it lies.
199
226
  function turningMarkup(lying: number): string {
200
227
  return ` class="glass-turning" style="--glass-lying: ${number(lying)}deg"`;
@@ -7,6 +7,7 @@
7
7
 
8
8
  import { useCallback } from 'react';
9
9
 
10
+ import { svgDataUrl, svgOfDataUrl } from '../../download/core/dataUrl.ts';
10
11
  import { useAsync } from '../../hooks/ui/useAsync.ts';
11
12
  import { figureMoves, movingFigure } from '../render/motion.ts';
12
13
 
@@ -101,32 +102,7 @@ export function movingFigureSource(src: string): Promise<string | undefined> {
101
102
  }
102
103
 
103
104
  async function makeMoving(src: string): Promise<string | undefined> {
104
- if (!src.startsWith('data:image/svg+xml')) return undefined;
105
- try {
106
- const response = await fetch(src);
107
- if (!response.ok) return undefined;
108
- const svg = await response.text();
109
- if (!figureMoves(svg)) return undefined;
110
- return await dataUrl(
111
- new Blob([movingFigure(svg)], { type: 'image/svg+xml' }),
112
- );
113
- } catch {
114
- // A picture that cannot be read is shown as it is, still.
115
- return undefined;
116
- }
117
- }
118
-
119
- function dataUrl(blob: Blob): Promise<string> {
120
- return new Promise((resolve, reject) => {
121
- const reader = new FileReader();
122
- reader.addEventListener('load', () => {
123
- const { result } = reader;
124
- if (typeof result === 'string') resolve(result);
125
- else reject(new Error('The figure could not be read.'));
126
- });
127
- reader.addEventListener('error', () => {
128
- reject(reader.error ?? new Error('The figure could not be read.'));
129
- });
130
- reader.readAsDataURL(blob);
131
- });
105
+ const svg = svgOfDataUrl(src);
106
+ if (svg === undefined || !figureMoves(svg)) return undefined;
107
+ return svgDataUrl(movingFigure(svg));
132
108
  }
@@ -1094,6 +1094,13 @@
1094
1094
  "crystal3d.packing.cellHelp": "Jedes Atom innerhalb der Zelle, dort geschnitten, wo ihre Wände es schneiden.",
1095
1095
  "crystal3d.unitCell": "Elementarzelle",
1096
1096
  "crystal3d.unitCellHelp": "Der Rahmen der Elementarzelle.",
1097
+ "crystal3d.bonds": "Bindungen",
1098
+ "crystal3d.bonds.all": "Alle",
1099
+ "crystal3d.bonds.allHelp": "Jede Bindung zwischen Atomen, die nahe genug beieinander liegen.",
1100
+ "crystal3d.bonds.noMetal": "Ohne Metallbindungen",
1101
+ "crystal3d.bonds.noMetalHelp": "Die gestrichelten Bindungen zu Metallatomen sind ausgeblendet.",
1102
+ "crystal3d.bonds.none": "Keine",
1103
+ "crystal3d.bonds.noneHelp": "Nur die Atome, ohne jede Bindung.",
1097
1104
  "crystal3d.caption.molecules.one": "1 Molekül pro Zelle",
1098
1105
  "crystal3d.caption.molecules.other": "{count} Moleküle pro Zelle",
1099
1106
  "crystal3d.caption.atoms.one": "1 Atom pro Zelle",
@@ -1094,6 +1094,13 @@
1094
1094
  "crystal3d.packing.cellHelp": "Every atom inside the cell, cut where its walls cut it.",
1095
1095
  "crystal3d.unitCell": "Unit cell",
1096
1096
  "crystal3d.unitCellHelp": "The box of the unit cell.",
1097
+ "crystal3d.bonds": "Bonds",
1098
+ "crystal3d.bonds.all": "All",
1099
+ "crystal3d.bonds.allHelp": "Every bond between atoms close enough to be joined.",
1100
+ "crystal3d.bonds.noMetal": "No metal bonds",
1101
+ "crystal3d.bonds.noMetalHelp": "The dashed bonds to metal atoms are hidden.",
1102
+ "crystal3d.bonds.none": "None",
1103
+ "crystal3d.bonds.noneHelp": "The atoms alone, without any bond.",
1097
1104
  "crystal3d.caption.molecules.one": "1 molecule per cell",
1098
1105
  "crystal3d.caption.molecules.other": "{count} molecules per cell",
1099
1106
  "crystal3d.caption.atoms.one": "1 atom per cell",
@@ -1094,6 +1094,13 @@
1094
1094
  "crystal3d.packing.cellHelp": "Cada átomo dentro de la celda, cortado donde lo cortan sus caras.",
1095
1095
  "crystal3d.unitCell": "Celda unidad",
1096
1096
  "crystal3d.unitCellHelp": "El contorno de la celda unidad.",
1097
+ "crystal3d.bonds": "Enlaces",
1098
+ "crystal3d.bonds.all": "Todos",
1099
+ "crystal3d.bonds.allHelp": "Cada enlace entre átomos lo bastante cercanos para unirse.",
1100
+ "crystal3d.bonds.noMetal": "Sin enlaces metálicos",
1101
+ "crystal3d.bonds.noMetalHelp": "Se ocultan los enlaces discontinuos hacia los átomos metálicos.",
1102
+ "crystal3d.bonds.none": "Ninguno",
1103
+ "crystal3d.bonds.noneHelp": "Solo los átomos, sin ningún enlace.",
1097
1104
  "crystal3d.caption.molecules.one": "1 molécula por celda",
1098
1105
  "crystal3d.caption.molecules.other": "{count} moléculas por celda",
1099
1106
  "crystal3d.caption.atoms.one": "1 átomo por celda",
@@ -1094,6 +1094,13 @@
1094
1094
  "crystal3d.packing.cellHelp": "Chaque atome à l'intérieur de la maille, coupé là où ses faces le coupent.",
1095
1095
  "crystal3d.unitCell": "Maille",
1096
1096
  "crystal3d.unitCellHelp": "Le contour de la maille élémentaire.",
1097
+ "crystal3d.bonds": "Liaisons",
1098
+ "crystal3d.bonds.all": "Toutes",
1099
+ "crystal3d.bonds.allHelp": "Chaque liaison entre atomes assez proches pour être liés.",
1100
+ "crystal3d.bonds.noMetal": "Sans liaisons au métal",
1101
+ "crystal3d.bonds.noMetalHelp": "Les liaisons en pointillé vers les atomes métalliques sont masquées.",
1102
+ "crystal3d.bonds.none": "Aucune",
1103
+ "crystal3d.bonds.noneHelp": "Les atomes seuls, sans aucune liaison.",
1097
1104
  "crystal3d.caption.molecules.one": "1 molécule par maille",
1098
1105
  "crystal3d.caption.molecules.other": "{count} molécules par maille",
1099
1106
  "crystal3d.caption.atoms.one": "1 atome par maille",
@@ -1094,6 +1094,13 @@
1094
1094
  "crystal3d.packing.cellHelp": "Ogni atomo dentro la cella, tagliato dove lo tagliano le sue pareti.",
1095
1095
  "crystal3d.unitCell": "Cella elementare",
1096
1096
  "crystal3d.unitCellHelp": "Il contorno della cella elementare.",
1097
+ "crystal3d.bonds": "Legami",
1098
+ "crystal3d.bonds.all": "Tutti",
1099
+ "crystal3d.bonds.allHelp": "Ogni legame tra atomi abbastanza vicini da unirsi.",
1100
+ "crystal3d.bonds.noMetal": "Senza legami metallici",
1101
+ "crystal3d.bonds.noMetalHelp": "I legami tratteggiati verso gli atomi metallici sono nascosti.",
1102
+ "crystal3d.bonds.none": "Nessuno",
1103
+ "crystal3d.bonds.noneHelp": "Solo gli atomi, senza alcun legame.",
1097
1104
  "crystal3d.caption.molecules.one": "1 molecola per cella",
1098
1105
  "crystal3d.caption.molecules.other": "{count} molecole per cella",
1099
1106
  "crystal3d.caption.atoms.one": "1 atomo per cella",
@@ -14,8 +14,9 @@ export const FIGURE_REFERENTS_NAMESPACE =
14
14
  'https://www.cheminfo.org/ns/referents/1';
15
15
 
16
16
  /**
17
- * Write what a figure numbers into its SVG, in place of what it carried. A
18
- * figure numbering nothing is written without any.
17
+ * Write what a figure numbers and lets a document quote into its SVG, in
18
+ * place of what it carried. A figure numbering and quoting nothing is written
19
+ * without any.
19
20
  * @param svg - The figure, as an SVG document.
20
21
  * @param referents - What it numbers.
21
22
  * @returns The figure.
@@ -25,7 +26,11 @@ export function withFigureReferents(
25
26
  referents: FigureReferents,
26
27
  ): string {
27
28
  const text = withoutFigureReferents(svg);
28
- if (referents.referents.length === 0 && referents.series.length === 0) {
29
+ if (
30
+ referents.referents.length === 0 &&
31
+ referents.series.length === 0 &&
32
+ (referents.quotes ?? []).length === 0
33
+ ) {
29
34
  return text;
30
35
  }
31
36
  const element = `<cheminfo:referents xmlns:cheminfo="${FIGURE_REFERENTS_NAMESPACE}">${escapeText(JSON.stringify(referents))}</cheminfo:referents>`;
@@ -3,6 +3,7 @@ export * from './labelList.ts';
3
3
  export * from './labelTokens.ts';
4
4
  export * from './labels.ts';
5
5
  export * from './numbering.ts';
6
+ export * from './quoteParts.ts';
6
7
  export * from './readReferents.ts';
7
8
  export * from './referentPicture.ts';
8
9
  export * from './seriesLetter.ts';