react-cheminfo 0.136.0 → 0.137.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.
- package/README.md +1 -1
- package/lib/crystal3d/core/crystalView.d.ts +10 -0
- package/lib/crystal3d/core/crystalView.d.ts.map +1 -1
- package/lib/crystal3d/core/crystalView.js +7 -0
- package/lib/crystal3d/core/crystalView.js.map +1 -1
- package/lib/crystal3d/core/index.d.ts +2 -2
- package/lib/crystal3d/core/index.d.ts.map +1 -1
- package/lib/crystal3d/core/index.js +1 -1
- package/lib/crystal3d/core/index.js.map +1 -1
- package/lib/crystal3d/ui/CrystalCanvas3D.d.ts.map +1 -1
- package/lib/crystal3d/ui/CrystalCanvas3D.js +9 -1
- package/lib/crystal3d/ui/CrystalCanvas3D.js.map +1 -1
- package/lib/crystal3d/ui/CrystalStructureView.js +5 -2
- package/lib/crystal3d/ui/CrystalStructureView.js.map +1 -1
- package/lib/crystal3d/ui/CrystalViewControls.d.ts +7 -3
- package/lib/crystal3d/ui/CrystalViewControls.d.ts.map +1 -1
- package/lib/crystal3d/ui/CrystalViewControls.js +6 -4
- package/lib/crystal3d/ui/CrystalViewControls.js.map +1 -1
- package/lib/crystal3d/ui/crystalScene.d.ts +6 -0
- package/lib/crystal3d/ui/crystalScene.d.ts.map +1 -1
- package/lib/crystal3d/viewer/renderStructure.d.ts +25 -0
- package/lib/crystal3d/viewer/renderStructure.d.ts.map +1 -1
- package/lib/crystal3d/viewer/renderStructure.js +41 -1
- package/lib/crystal3d/viewer/renderStructure.js.map +1 -1
- package/lib/crystal3d/viewer/viewer.d.ts +11 -2
- package/lib/crystal3d/viewer/viewer.d.ts.map +1 -1
- package/lib/crystal3d/viewer/viewer.js +17 -2
- package/lib/crystal3d/viewer/viewer.js.map +1 -1
- package/lib/download/core/croppedMarkup.d.ts.map +1 -1
- package/lib/download/core/croppedMarkup.js +16 -40
- package/lib/download/core/croppedMarkup.js.map +1 -1
- package/lib/download/core/dataUrl.d.ts +27 -0
- package/lib/download/core/dataUrl.d.ts.map +1 -0
- package/lib/download/core/dataUrl.js +54 -0
- package/lib/download/core/dataUrl.js.map +1 -0
- package/lib/download/core/index.d.ts +3 -0
- package/lib/download/core/index.d.ts.map +1 -1
- package/lib/download/core/index.js +2 -0
- package/lib/download/core/index.js.map +1 -1
- package/lib/download/core/svgMarkup.d.ts +39 -0
- package/lib/download/core/svgMarkup.d.ts.map +1 -0
- package/lib/download/core/svgMarkup.js +100 -0
- package/lib/download/core/svgMarkup.js.map +1 -0
- package/lib/drawing/ui/movingFigure.d.ts.map +1 -1
- package/lib/drawing/ui/movingFigure.js +4 -30
- package/lib/drawing/ui/movingFigure.js.map +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +7 -0
- package/lib/locales/en.json +7 -0
- package/lib/locales/es.json +7 -0
- package/lib/locales/fr.json +7 -0
- package/lib/locales/it.json +7 -0
- package/package.json +1 -1
- package/src/crystal3d/core/crystalView.ts +17 -0
- package/src/crystal3d/core/index.ts +2 -0
- package/src/crystal3d/ui/CrystalCanvas3D.tsx +9 -0
- package/src/crystal3d/ui/CrystalStructureView.tsx +7 -2
- package/src/crystal3d/ui/CrystalViewControls.tsx +33 -4
- package/src/crystal3d/ui/crystalScene.ts +6 -0
- package/src/crystal3d/viewer/renderStructure.ts +66 -1
- package/src/crystal3d/viewer/viewer.ts +19 -3
- package/src/download/core/croppedMarkup.ts +16 -42
- package/src/download/core/dataUrl.ts +59 -0
- package/src/download/core/index.ts +3 -0
- package/src/download/core/svgMarkup.ts +113 -0
- package/src/drawing/ui/movingFigure.ts +4 -28
- package/src/locales/de.json +7 -0
- package/src/locales/en.json +7 -0
- package/src/locales/es.json +7 -0
- package/src/locales/fr.json +7 -0
- package/src/locales/it.json +7 -0
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { clearMeasurements } from '../../molstar/core/index.ts';
|
|
12
|
+
import type { CrystalBonds } from '../core/crystalView.ts';
|
|
12
13
|
import { mergeDrawings, withoutDrawings } from '../core/drawingSet.ts';
|
|
13
14
|
import type {
|
|
14
15
|
CellRepeat,
|
|
@@ -29,6 +30,7 @@ import { CrystalViewerPlugin } from './plugin.ts';
|
|
|
29
30
|
import type { CellStyle } from './renderCell.ts';
|
|
30
31
|
import type { ElementLayerStyle } from './renderElements.ts';
|
|
31
32
|
import type { StructureStyle } from './renderStructure.ts';
|
|
33
|
+
import { setStructureBonds } from './renderStructure.ts';
|
|
32
34
|
import { drawCell, drawElements, drawStructure } from './sceneParts.ts';
|
|
33
35
|
|
|
34
36
|
/**
|
|
@@ -53,6 +55,7 @@ export function createCrystalViewer(
|
|
|
53
55
|
export class CrystalViewer extends CrystalViewerPlugin {
|
|
54
56
|
#drawings: readonly SymmetryDrawing[] = [];
|
|
55
57
|
#elementStyle: ElementLayerStyle = {};
|
|
58
|
+
#bonds: CrystalBonds = 'all';
|
|
56
59
|
|
|
57
60
|
/**
|
|
58
61
|
* The symmetry elements drawn right now, in drawing order.
|
|
@@ -66,20 +69,33 @@ export class CrystalViewer extends CrystalViewerPlugin {
|
|
|
66
69
|
* Replace the atoms on screen.
|
|
67
70
|
* @param atoms - The whole scene, expanded and repeated already, in Cartesian
|
|
68
71
|
* ångström. An empty list clears them.
|
|
69
|
-
* @param style - See {@link StructureStyle}
|
|
72
|
+
* @param style - See {@link StructureStyle}; its bonds are the ones last
|
|
73
|
+
* set by {@link CrystalViewer.setBonds}.
|
|
70
74
|
* @returns Resolves once the atoms are drawn.
|
|
71
75
|
*/
|
|
72
76
|
showStructure(
|
|
73
77
|
atoms: readonly ViewerAtom[],
|
|
74
|
-
style?: StructureStyle,
|
|
78
|
+
style?: Omit<StructureStyle, 'bonds'>,
|
|
75
79
|
): Promise<void> {
|
|
76
80
|
// A measurement names atoms of the structure it was taken on.
|
|
77
81
|
return this.run(async (plugin) => {
|
|
78
82
|
await clearMeasurements(plugin);
|
|
79
|
-
await drawStructure(plugin, atoms, style);
|
|
83
|
+
await drawStructure(plugin, atoms, { ...style, bonds: this.#bonds });
|
|
80
84
|
});
|
|
81
85
|
}
|
|
82
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Draw other bonds, on the atoms on screen and on every later structure. The
|
|
89
|
+
* atoms are not drawn again, so the camera stays where it is.
|
|
90
|
+
* @param bonds - Which bonds are drawn.
|
|
91
|
+
* @returns Resolves once they are drawn.
|
|
92
|
+
*/
|
|
93
|
+
setBonds(bonds: CrystalBonds): Promise<void> {
|
|
94
|
+
if (bonds === this.#bonds) return Promise.resolve();
|
|
95
|
+
this.#bonds = bonds;
|
|
96
|
+
return this.run((plugin) => setStructureBonds(plugin, bonds));
|
|
97
|
+
}
|
|
98
|
+
|
|
83
99
|
/**
|
|
84
100
|
* Remove the atoms, leaving the cell and the elements in place.
|
|
85
101
|
* @returns Resolves once the atoms are gone.
|
|
@@ -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 =
|
|
40
|
-
const width = Number(
|
|
41
|
-
const height = Number(
|
|
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(
|
|
45
|
-
Number(
|
|
46
|
-
const view =
|
|
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
|
-
|
|
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 =
|
|
72
|
-
const view =
|
|
73
|
-
const width = pixels(
|
|
74
|
-
const height = pixels(
|
|
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 =
|
|
93
|
-
const view =
|
|
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 =
|
|
137
|
-
const view =
|
|
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
|
+
}
|
|
@@ -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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
}
|
package/src/locales/de.json
CHANGED
|
@@ -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",
|
package/src/locales/en.json
CHANGED
|
@@ -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",
|
package/src/locales/es.json
CHANGED
|
@@ -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",
|
package/src/locales/fr.json
CHANGED
|
@@ -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",
|
package/src/locales/it.json
CHANGED
|
@@ -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",
|