react-cheminfo 0.135.0 → 0.136.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/lib/crystal/core/cellAtoms.d.ts +43 -0
- package/lib/crystal/core/cellAtoms.d.ts.map +1 -0
- package/lib/crystal/core/cellAtoms.js +70 -0
- package/lib/crystal/core/cellAtoms.js.map +1 -0
- package/lib/crystal/core/index.d.ts +2 -0
- package/lib/crystal/core/index.d.ts.map +1 -1
- package/lib/crystal/core/index.js +1 -0
- package/lib/crystal/core/index.js.map +1 -1
- package/lib/crystal/core/molecules.d.ts.map +1 -1
- package/lib/crystal/core/molecules.js +6 -40
- package/lib/crystal/core/molecules.js.map +1 -1
- package/lib/crystal3d/core/cellClip.d.ts +46 -0
- package/lib/crystal3d/core/cellClip.d.ts.map +1 -0
- package/lib/crystal3d/core/cellClip.js +198 -0
- package/lib/crystal3d/core/cellClip.js.map +1 -0
- package/lib/crystal3d/core/cellGeometry.d.ts +63 -0
- package/lib/crystal3d/core/cellGeometry.d.ts.map +1 -0
- package/lib/crystal3d/core/cellGeometry.js +153 -0
- package/lib/crystal3d/core/cellGeometry.js.map +1 -0
- package/lib/crystal3d/core/cellStack.d.ts +51 -0
- package/lib/crystal3d/core/cellStack.d.ts.map +1 -0
- package/lib/crystal3d/core/cellStack.js +79 -0
- package/lib/crystal3d/core/cellStack.js.map +1 -0
- package/lib/crystal3d/core/crystalView.d.ts +71 -0
- package/lib/crystal3d/core/crystalView.d.ts.map +1 -0
- package/lib/crystal3d/core/crystalView.js +48 -0
- package/lib/crystal3d/core/crystalView.js.map +1 -0
- package/lib/crystal3d/core/drawingSet.d.ts +31 -0
- package/lib/crystal3d/core/drawingSet.d.ts.map +1 -0
- package/lib/crystal3d/core/drawingSet.js +63 -0
- package/lib/crystal3d/core/drawingSet.js.map +1 -0
- package/lib/crystal3d/core/elementDrawing.d.ts +50 -0
- package/lib/crystal3d/core/elementDrawing.d.ts.map +1 -0
- package/lib/crystal3d/core/elementDrawing.js +100 -0
- package/lib/crystal3d/core/elementDrawing.js.map +1 -0
- package/lib/crystal3d/core/elementExtent.d.ts +42 -0
- package/lib/crystal3d/core/elementExtent.d.ts.map +1 -0
- package/lib/crystal3d/core/elementExtent.js +56 -0
- package/lib/crystal3d/core/elementExtent.js.map +1 -0
- package/lib/crystal3d/core/elementLabels.d.ts +31 -0
- package/lib/crystal3d/core/elementLabels.d.ts.map +1 -0
- package/lib/crystal3d/core/elementLabels.js +99 -0
- package/lib/crystal3d/core/elementLabels.js.map +1 -0
- package/lib/crystal3d/core/elementShapes.d.ts +43 -0
- package/lib/crystal3d/core/elementShapes.d.ts.map +1 -0
- package/lib/crystal3d/core/elementShapes.js +115 -0
- package/lib/crystal3d/core/elementShapes.js.map +1 -0
- package/lib/crystal3d/core/frame.d.ts +36 -0
- package/lib/crystal3d/core/frame.d.ts.map +1 -0
- package/lib/crystal3d/core/frame.js +35 -0
- package/lib/crystal3d/core/frame.js.map +1 -0
- package/lib/crystal3d/core/framing.d.ts +41 -0
- package/lib/crystal3d/core/framing.d.ts.map +1 -0
- package/lib/crystal3d/core/framing.js +79 -0
- package/lib/crystal3d/core/framing.js.map +1 -0
- package/lib/crystal3d/core/index.d.ts +42 -0
- package/lib/crystal3d/core/index.d.ts.map +1 -0
- package/lib/crystal3d/core/index.js +29 -0
- package/lib/crystal3d/core/index.js.map +1 -0
- package/lib/crystal3d/core/labelText.d.ts +19 -0
- package/lib/crystal3d/core/labelText.d.ts.map +1 -0
- package/lib/crystal3d/core/labelText.js +42 -0
- package/lib/crystal3d/core/labelText.js.map +1 -0
- package/lib/crystal3d/core/latticeBasis.d.ts +49 -0
- package/lib/crystal3d/core/latticeBasis.d.ts.map +1 -0
- package/lib/crystal3d/core/latticeBasis.js +89 -0
- package/lib/crystal3d/core/latticeBasis.js.map +1 -0
- package/lib/crystal3d/core/mat3.d.ts +68 -0
- package/lib/crystal3d/core/mat3.d.ts.map +1 -0
- package/lib/crystal3d/core/mat3.js +146 -0
- package/lib/crystal3d/core/mat3.js.map +1 -0
- package/lib/crystal3d/core/operationMatrix.d.ts +44 -0
- package/lib/crystal3d/core/operationMatrix.d.ts.map +1 -0
- package/lib/crystal3d/core/operationMatrix.js +172 -0
- package/lib/crystal3d/core/operationMatrix.js.map +1 -0
- package/lib/crystal3d/core/orientation.d.ts +62 -0
- package/lib/crystal3d/core/orientation.d.ts.map +1 -0
- package/lib/crystal3d/core/orientation.js +166 -0
- package/lib/crystal3d/core/orientation.js.map +1 -0
- package/lib/crystal3d/core/palette.d.ts +24 -0
- package/lib/crystal3d/core/palette.d.ts.map +1 -0
- package/lib/crystal3d/core/palette.js +34 -0
- package/lib/crystal3d/core/palette.js.map +1 -0
- package/lib/crystal3d/core/primitives.d.ts +133 -0
- package/lib/crystal3d/core/primitives.d.ts.map +1 -0
- package/lib/crystal3d/core/primitives.js +80 -0
- package/lib/crystal3d/core/primitives.js.map +1 -0
- package/lib/crystal3d/core/structureText.d.ts +20 -0
- package/lib/crystal3d/core/structureText.d.ts.map +1 -0
- package/lib/crystal3d/core/structureText.js +37 -0
- package/lib/crystal3d/core/structureText.js.map +1 -0
- package/lib/crystal3d/core/supercell.d.ts +20 -0
- package/lib/crystal3d/core/supercell.d.ts.map +1 -0
- package/lib/crystal3d/core/supercell.js +35 -0
- package/lib/crystal3d/core/supercell.js.map +1 -0
- package/lib/crystal3d/core/types.d.ts +166 -0
- package/lib/crystal3d/core/types.d.ts.map +1 -0
- package/lib/crystal3d/core/types.js +10 -0
- package/lib/crystal3d/core/types.js.map +1 -0
- package/lib/crystal3d/core/vec3.d.ts +75 -0
- package/lib/crystal3d/core/vec3.d.ts.map +1 -0
- package/lib/crystal3d/core/vec3.js +119 -0
- package/lib/crystal3d/core/vec3.js.map +1 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.d.ts +52 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.js +242 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.js.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureView.d.ts +17 -0
- package/lib/crystal3d/ui/CrystalStructureView.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureView.js +76 -0
- package/lib/crystal3d/ui/CrystalStructureView.js.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.d.ts +22 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.js +29 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.js.map +1 -0
- package/lib/crystal3d/ui/CrystalViewControls.d.ts +25 -0
- package/lib/crystal3d/ui/CrystalViewControls.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalViewControls.js +22 -0
- package/lib/crystal3d/ui/CrystalViewControls.js.map +1 -0
- package/lib/crystal3d/ui/CrystalViewer3D.d.ts +72 -0
- package/lib/crystal3d/ui/CrystalViewer3D.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalViewer3D.js +70 -0
- package/lib/crystal3d/ui/CrystalViewer3D.js.map +1 -0
- package/lib/crystal3d/ui/crystalScene.d.ts +91 -0
- package/lib/crystal3d/ui/crystalScene.d.ts.map +1 -0
- package/lib/crystal3d/ui/crystalScene.js +10 -0
- package/lib/crystal3d/ui/crystalScene.js.map +1 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts +52 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts.map +1 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.js +2 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.js.map +1 -0
- package/lib/crystal3d/ui/index.d.ts +16 -0
- package/lib/crystal3d/ui/index.d.ts.map +1 -0
- package/lib/crystal3d/ui/index.js +12 -0
- package/lib/crystal3d/ui/index.js.map +1 -0
- package/lib/crystal3d/ui/useCrystalCaption.d.ts +14 -0
- package/lib/crystal3d/ui/useCrystalCaption.d.ts.map +1 -0
- package/lib/crystal3d/ui/useCrystalCaption.js +32 -0
- package/lib/crystal3d/ui/useCrystalCaption.js.map +1 -0
- package/lib/crystal3d/viewer/animate.d.ts +49 -0
- package/lib/crystal3d/viewer/animate.d.ts.map +1 -0
- package/lib/crystal3d/viewer/animate.js +83 -0
- package/lib/crystal3d/viewer/animate.js.map +1 -0
- package/lib/crystal3d/viewer/camera.d.ts +44 -0
- package/lib/crystal3d/viewer/camera.d.ts.map +1 -0
- package/lib/crystal3d/viewer/camera.js +103 -0
- package/lib/crystal3d/viewer/camera.js.map +1 -0
- package/lib/crystal3d/viewer/index.d.ts +13 -0
- package/lib/crystal3d/viewer/index.d.ts.map +1 -0
- package/lib/crystal3d/viewer/index.js +8 -0
- package/lib/crystal3d/viewer/index.js.map +1 -0
- package/lib/crystal3d/viewer/layerRegistry.d.ts +24 -0
- package/lib/crystal3d/viewer/layerRegistry.d.ts.map +1 -0
- package/lib/crystal3d/viewer/layerRegistry.js +39 -0
- package/lib/crystal3d/viewer/layerRegistry.js.map +1 -0
- package/lib/crystal3d/viewer/meshPrimitives.d.ts +13 -0
- package/lib/crystal3d/viewer/meshPrimitives.d.ts.map +1 -0
- package/lib/crystal3d/viewer/meshPrimitives.js +76 -0
- package/lib/crystal3d/viewer/meshPrimitives.js.map +1 -0
- package/lib/crystal3d/viewer/plugin.d.ts +133 -0
- package/lib/crystal3d/viewer/plugin.d.ts.map +1 -0
- package/lib/crystal3d/viewer/plugin.js +181 -0
- package/lib/crystal3d/viewer/plugin.js.map +1 -0
- package/lib/crystal3d/viewer/renderCell.d.ts +43 -0
- package/lib/crystal3d/viewer/renderCell.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderCell.js +53 -0
- package/lib/crystal3d/viewer/renderCell.js.map +1 -0
- package/lib/crystal3d/viewer/renderElements.d.ts +54 -0
- package/lib/crystal3d/viewer/renderElements.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderElements.js +77 -0
- package/lib/crystal3d/viewer/renderElements.js.map +1 -0
- package/lib/crystal3d/viewer/renderStructure.d.ts +55 -0
- package/lib/crystal3d/viewer/renderStructure.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderStructure.js +103 -0
- package/lib/crystal3d/viewer/renderStructure.js.map +1 -0
- package/lib/crystal3d/viewer/sceneParts.d.ts +32 -0
- package/lib/crystal3d/viewer/sceneParts.d.ts.map +1 -0
- package/lib/crystal3d/viewer/sceneParts.js +77 -0
- package/lib/crystal3d/viewer/sceneParts.js.map +1 -0
- package/lib/crystal3d/viewer/shapeLayer.d.ts +41 -0
- package/lib/crystal3d/viewer/shapeLayer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/shapeLayer.js +57 -0
- package/lib/crystal3d/viewer/shapeLayer.js.map +1 -0
- package/lib/crystal3d/viewer/textLayer.d.ts +21 -0
- package/lib/crystal3d/viewer/textLayer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/textLayer.js +59 -0
- package/lib/crystal3d/viewer/textLayer.js.map +1 -0
- package/lib/crystal3d/viewer/viewer.d.ts +110 -0
- package/lib/crystal3d/viewer/viewer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/viewer.js +157 -0
- package/lib/crystal3d/viewer/viewer.js.map +1 -0
- package/lib/crystal3d.d.ts +12 -0
- package/lib/crystal3d.d.ts.map +1 -0
- package/lib/crystal3d.js +12 -0
- package/lib/crystal3d.js.map +1 -0
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +19 -1
- package/lib/locales/en.json +19 -1
- package/lib/locales/es.json +19 -1
- package/lib/locales/fr.json +19 -1
- package/lib/locales/it.json +19 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.d.ts.map +1 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.js +16 -27
- package/lib/molecule3d/ui/MoleculeCanvas3D.js.map +1 -1
- package/lib/molstar/bonds/bondRule.d.ts +16 -0
- package/lib/molstar/bonds/bondRule.d.ts.map +1 -0
- package/lib/molstar/bonds/bondRule.js +23 -0
- package/lib/molstar/bonds/bondRule.js.map +1 -0
- package/lib/molstar/bonds/index.d.ts +9 -0
- package/lib/molstar/bonds/index.d.ts.map +1 -0
- package/lib/molstar/bonds/index.js +9 -0
- package/lib/molstar/bonds/index.js.map +1 -0
- package/lib/molstar/ui/MolstarToolbar.d.ts +47 -0
- package/lib/molstar/ui/MolstarToolbar.d.ts.map +1 -0
- package/lib/molstar/ui/MolstarToolbar.js +28 -0
- package/lib/molstar/ui/MolstarToolbar.js.map +1 -0
- package/lib/molstar/ui/index.d.ts +10 -0
- package/lib/molstar/ui/index.d.ts.map +1 -0
- package/lib/molstar/ui/index.js +8 -0
- package/lib/molstar/ui/index.js.map +1 -0
- package/lib/molstar/ui/useMolstarTools.d.ts +63 -0
- package/lib/molstar/ui/useMolstarTools.d.ts.map +1 -0
- package/lib/molstar/ui/useMolstarTools.js +36 -0
- package/lib/molstar/ui/useMolstarTools.js.map +1 -0
- package/package.json +2 -1
- package/src/crystal/core/cellAtoms.ts +106 -0
- package/src/crystal/core/index.ts +2 -0
- package/src/crystal/core/molecules.ts +7 -44
- package/src/crystal3d/core/cellClip.ts +229 -0
- package/src/crystal3d/core/cellGeometry.ts +193 -0
- package/src/crystal3d/core/cellStack.ts +87 -0
- package/src/crystal3d/core/crystalView.ts +114 -0
- package/src/crystal3d/core/drawingSet.ts +71 -0
- package/src/crystal3d/core/elementDrawing.ts +147 -0
- package/src/crystal3d/core/elementExtent.ts +81 -0
- package/src/crystal3d/core/elementLabels.ts +130 -0
- package/src/crystal3d/core/elementShapes.ts +141 -0
- package/src/crystal3d/core/frame.ts +56 -0
- package/src/crystal3d/core/framing.ts +101 -0
- package/src/crystal3d/core/index.ts +132 -0
- package/src/crystal3d/core/labelText.ts +44 -0
- package/src/crystal3d/core/latticeBasis.ts +110 -0
- package/src/crystal3d/core/mat3.ts +163 -0
- package/src/crystal3d/core/operationMatrix.ts +255 -0
- package/src/crystal3d/core/orientation.ts +229 -0
- package/src/crystal3d/core/palette.ts +43 -0
- package/src/crystal3d/core/primitives.ts +183 -0
- package/src/crystal3d/core/structureText.ts +43 -0
- package/src/crystal3d/core/supercell.ts +40 -0
- package/src/crystal3d/core/types.ts +186 -0
- package/src/crystal3d/core/vec3.ts +127 -0
- package/src/crystal3d/ui/CrystalCanvas3D.tsx +384 -0
- package/src/crystal3d/ui/CrystalStructureView.tsx +148 -0
- package/src/crystal3d/ui/CrystalStructureViewer.tsx +39 -0
- package/src/crystal3d/ui/CrystalViewControls.tsx +100 -0
- package/src/crystal3d/ui/CrystalViewer3D.tsx +183 -0
- package/src/crystal3d/ui/crystalScene.ts +100 -0
- package/src/crystal3d/ui/crystalStructureViewerProps.ts +54 -0
- package/src/crystal3d/ui/index.ts +20 -0
- package/src/crystal3d/ui/useCrystalCaption.ts +38 -0
- package/src/crystal3d/viewer/animate.ts +113 -0
- package/src/crystal3d/viewer/camera.ts +139 -0
- package/src/crystal3d/viewer/index.ts +13 -0
- package/src/crystal3d/viewer/layerRegistry.ts +47 -0
- package/src/crystal3d/viewer/meshPrimitives.ts +102 -0
- package/src/crystal3d/viewer/plugin.ts +258 -0
- package/src/crystal3d/viewer/renderCell.ts +98 -0
- package/src/crystal3d/viewer/renderElements.ts +121 -0
- package/src/crystal3d/viewer/renderStructure.ts +144 -0
- package/src/crystal3d/viewer/sceneParts.ts +119 -0
- package/src/crystal3d/viewer/shapeLayer.ts +108 -0
- package/src/crystal3d/viewer/textLayer.ts +85 -0
- package/src/crystal3d/viewer/viewer.ts +207 -0
- package/src/crystal3d.ts +12 -0
- package/src/locales/de.json +19 -1
- package/src/locales/en.json +19 -1
- package/src/locales/es.json +19 -1
- package/src/locales/fr.json +19 -1
- package/src/locales/it.json +19 -1
- package/src/molecule3d/ui/MoleculeCanvas3D.tsx +45 -71
- package/src/molstar/bonds/bondRule.ts +34 -0
- package/src/molstar/bonds/index.ts +9 -0
- package/src/molstar/ui/MolstarToolbar.tsx +103 -0
- package/src/molstar/ui/index.ts +14 -0
- package/src/molstar/ui/useMolstarTools.ts +98 -0
- package/styles/chrome.css +90 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The molstar canvas of the crystal view, with the family's toolbars over it,
|
|
3
|
+
* in a box that can fill the screen.
|
|
4
|
+
*
|
|
5
|
+
* `CrystalViewer3D` reaches this module through `React.lazy`, so a page that
|
|
6
|
+
* never shows a crystal never downloads molstar. Every effect below lists
|
|
7
|
+
* exactly what it reads, so a page that keeps its scene stable redraws only the
|
|
8
|
+
* part that changed: toggling one mirror does not rebuild the structure, and
|
|
9
|
+
* moving the pointer does not redraw anything.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { CSSProperties, ReactElement } from 'react';
|
|
13
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
14
|
+
|
|
15
|
+
import type { Molecule3DCamera } from '../../molecule3d/core/camera.ts';
|
|
16
|
+
import type { Measurement } from '../../molecule3d/core/measurement.ts';
|
|
17
|
+
import type { Molecule3DTools } from '../../molecule3d/core/settings.ts';
|
|
18
|
+
import { Molecule3DStage } from '../../molecule3d/ui/Molecule3DStage.tsx';
|
|
19
|
+
import { useImageExport } from '../../molecule3d/ui/useImageExport.ts';
|
|
20
|
+
import { MolstarToolbar } from '../../molstar/ui/MolstarToolbar.tsx';
|
|
21
|
+
import { useMolstarTools } from '../../molstar/ui/useMolstarTools.ts';
|
|
22
|
+
import { TOKEN } from '../../tokens/core/familyTokens.ts';
|
|
23
|
+
import { sceneOrientation } from '../core/orientation.ts';
|
|
24
|
+
import type { ViewerAtom } from '../core/types.ts';
|
|
25
|
+
import type { CrystalViewer } from '../viewer/index.ts';
|
|
26
|
+
import {
|
|
27
|
+
DEFAULT_CAMERA_DURATION,
|
|
28
|
+
createCrystalViewer,
|
|
29
|
+
} from '../viewer/index.ts';
|
|
30
|
+
|
|
31
|
+
import type { CrystalScene, CrystalViewHandle } from './crystalScene.ts';
|
|
32
|
+
|
|
33
|
+
/** Props of {@link CrystalCanvas3D}. */
|
|
34
|
+
export interface CrystalCanvas3DProps {
|
|
35
|
+
/** What to show. */
|
|
36
|
+
scene: CrystalScene;
|
|
37
|
+
/**
|
|
38
|
+
* Scene background, `#rrggbb`.
|
|
39
|
+
* @default '#ffffff'
|
|
40
|
+
*/
|
|
41
|
+
background?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Which tools the toolbars offer; every one it does not name is on.
|
|
44
|
+
* @default every tool but the display options and the surface
|
|
45
|
+
*/
|
|
46
|
+
tools?: Partial<Molecule3DTools>;
|
|
47
|
+
/**
|
|
48
|
+
* Base name of a picture saved from the toolbar, extension excluded.
|
|
49
|
+
* @default 'crystal'
|
|
50
|
+
*/
|
|
51
|
+
fileName?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Called whenever drawing fails, with one sentence, or `null` once it works
|
|
54
|
+
* again.
|
|
55
|
+
* @default undefined
|
|
56
|
+
*/
|
|
57
|
+
onFailure?: (message: string | null) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Called with the means to picture the scene once the canvas exists, and with
|
|
60
|
+
* `null` once it is gone.
|
|
61
|
+
* @default undefined
|
|
62
|
+
*/
|
|
63
|
+
onHandle?: (handle: CrystalViewHandle | null) => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Draw the scene, say what the pointer rests on, and float the toolbars.
|
|
68
|
+
* @param props - See {@link CrystalCanvas3DProps}.
|
|
69
|
+
* @returns The stage holding the canvas, its toolbars and its readout.
|
|
70
|
+
*/
|
|
71
|
+
export function CrystalCanvas3D(props: CrystalCanvas3DProps): ReactElement {
|
|
72
|
+
const {
|
|
73
|
+
scene,
|
|
74
|
+
background,
|
|
75
|
+
tools,
|
|
76
|
+
fileName = 'crystal',
|
|
77
|
+
onFailure,
|
|
78
|
+
onHandle,
|
|
79
|
+
} = props;
|
|
80
|
+
const {
|
|
81
|
+
atoms,
|
|
82
|
+
camera = null,
|
|
83
|
+
cell = null,
|
|
84
|
+
repeat,
|
|
85
|
+
representation,
|
|
86
|
+
elements,
|
|
87
|
+
labels,
|
|
88
|
+
elementStyle,
|
|
89
|
+
play = null,
|
|
90
|
+
} = scene;
|
|
91
|
+
const [container, setContainer] = useState<HTMLDivElement | null>(null);
|
|
92
|
+
const [hovered, setHovered] = useState<string | null>(null);
|
|
93
|
+
|
|
94
|
+
// The viewer is not React state: it is an external resource the effects below
|
|
95
|
+
// reach through this handle. Putting it in state would set state inside an
|
|
96
|
+
// effect, and every draw would then cost an extra render.
|
|
97
|
+
const held = useRef<CrystalViewer | null>(null);
|
|
98
|
+
|
|
99
|
+
// Which way the scene is opened on: measured from its own principal axis, so
|
|
100
|
+
// a molecule built about z and one built about x both open on a view where a
|
|
101
|
+
// plane reads as a plane and an axis reads as a rod.
|
|
102
|
+
const orientation = useMemo(
|
|
103
|
+
() => sceneOrientation({ cell, elements }),
|
|
104
|
+
[cell, elements],
|
|
105
|
+
);
|
|
106
|
+
// Held in a ref rather than read as a dependency, because only a new
|
|
107
|
+
// structure reframes: switching a layer off changes which elements are drawn,
|
|
108
|
+
// and a camera that swung round at that moment would look like the chip had
|
|
109
|
+
// moved the molecule.
|
|
110
|
+
const framing = useRef(orientation);
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
framing.current = orientation;
|
|
113
|
+
}, [orientation]);
|
|
114
|
+
|
|
115
|
+
// A camera a figure carried is put back once, on the structure it came
|
|
116
|
+
// with; every later redraw frames the scene as any other does.
|
|
117
|
+
const opening = useRef<Molecule3DCamera | null>(camera);
|
|
118
|
+
const applied = useRef<Molecule3DCamera | null>(null);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
opening.current = camera;
|
|
121
|
+
}, [camera]);
|
|
122
|
+
|
|
123
|
+
// Kept in a ref as well, so a page passing an inline callback does not redraw
|
|
124
|
+
// the whole scene on every render.
|
|
125
|
+
const failure = useRef(onFailure);
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
failure.current = onFailure;
|
|
128
|
+
}, [onFailure]);
|
|
129
|
+
|
|
130
|
+
// The draw in flight, so a picture or a measurement asked for meanwhile
|
|
131
|
+
// waits for it.
|
|
132
|
+
const drawing = useRef<Promise<void> | null>(null);
|
|
133
|
+
|
|
134
|
+
const { measurements, addMeasurement, clearMeasurements } =
|
|
135
|
+
useMeasurementsOf(atoms);
|
|
136
|
+
|
|
137
|
+
const imageExport = useImageExport(container, held, fileName);
|
|
138
|
+
const { capture } = imageExport;
|
|
139
|
+
const handing = useRef(onHandle);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
handing.current = onHandle;
|
|
142
|
+
}, [onHandle]);
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
const listener = handing.current;
|
|
145
|
+
if (listener === undefined || container === null) return;
|
|
146
|
+
listener({
|
|
147
|
+
capture,
|
|
148
|
+
readCamera: () => held.current?.readCamera() ?? Promise.resolve(null),
|
|
149
|
+
whenDrawn: () => drawing.current ?? Promise.resolve(),
|
|
150
|
+
});
|
|
151
|
+
return () => {
|
|
152
|
+
listener(null);
|
|
153
|
+
};
|
|
154
|
+
}, [capture, container]);
|
|
155
|
+
|
|
156
|
+
// A callback ref, so the viewer is created by the element arriving; the
|
|
157
|
+
// effects that draw are declared after this one and so run after it, and
|
|
158
|
+
// every one of them lists `container` so a remount redraws.
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (container === null) return;
|
|
161
|
+
const created = createCrystalViewer(container, {
|
|
162
|
+
background,
|
|
163
|
+
onMeasure: addMeasurement,
|
|
164
|
+
});
|
|
165
|
+
held.current = created;
|
|
166
|
+
const observer = new ResizeObserver(() => {
|
|
167
|
+
created.handleResize();
|
|
168
|
+
});
|
|
169
|
+
observer.observe(container);
|
|
170
|
+
return () => {
|
|
171
|
+
held.current = null;
|
|
172
|
+
observer.disconnect();
|
|
173
|
+
created.dispose();
|
|
174
|
+
};
|
|
175
|
+
}, [container, background, addMeasurement]);
|
|
176
|
+
|
|
177
|
+
const controls = useMolstarTools(held, container);
|
|
178
|
+
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
const viewer = held.current;
|
|
181
|
+
if (viewer === null) return;
|
|
182
|
+
return viewer.onHover(setHovered);
|
|
183
|
+
}, [container, background]);
|
|
184
|
+
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
const viewer = held.current;
|
|
187
|
+
if (viewer === null) return;
|
|
188
|
+
container?.setAttribute('data-drawn', 'false');
|
|
189
|
+
const work = (async () => {
|
|
190
|
+
await viewer.showStructure(atoms, { representation });
|
|
191
|
+
await viewer.showCell(cell, repeat);
|
|
192
|
+
const wanted = opening.current;
|
|
193
|
+
if (wanted !== null && wanted !== applied.current) {
|
|
194
|
+
applied.current = wanted;
|
|
195
|
+
await viewer.applyCamera(wanted);
|
|
196
|
+
} else {
|
|
197
|
+
await viewer.resetCamera(0, framing.current);
|
|
198
|
+
}
|
|
199
|
+
container?.setAttribute('data-drawn', 'true');
|
|
200
|
+
})();
|
|
201
|
+
drawing.current = work.catch(() => undefined);
|
|
202
|
+
void report(failure, work);
|
|
203
|
+
}, [container, background, atoms, cell, repeat, representation]);
|
|
204
|
+
|
|
205
|
+
// Once the structure above is on screen, so they are drawn on the atoms they
|
|
206
|
+
// name.
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
const viewer = held.current;
|
|
209
|
+
if (viewer === null) return;
|
|
210
|
+
let cancelled = false;
|
|
211
|
+
void (drawing.current ?? Promise.resolve()).then(() => {
|
|
212
|
+
if (!cancelled) void viewer.showMeasurements(measurements);
|
|
213
|
+
});
|
|
214
|
+
return () => {
|
|
215
|
+
cancelled = true;
|
|
216
|
+
};
|
|
217
|
+
}, [container, background, measurements]);
|
|
218
|
+
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
const viewer = held.current;
|
|
221
|
+
if (viewer === null) return;
|
|
222
|
+
void report(
|
|
223
|
+
failure,
|
|
224
|
+
viewer.showElements(elements ?? [], { labels, style: elementStyle }),
|
|
225
|
+
);
|
|
226
|
+
}, [container, background, elements, labels, elementStyle]);
|
|
227
|
+
|
|
228
|
+
// The nonce is the cue that replays the same operation; the operation itself
|
|
229
|
+
// is in the list so that changing it applies the new one.
|
|
230
|
+
const operation = play?.operation ?? null;
|
|
231
|
+
const duration = play?.durationMs;
|
|
232
|
+
const nonce = play?.nonce ?? null;
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
const viewer = held.current;
|
|
235
|
+
if (viewer === null) return;
|
|
236
|
+
if (operation === null || nonce === null) {
|
|
237
|
+
void report(failure, viewer.resetOperation());
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
void report(
|
|
241
|
+
failure,
|
|
242
|
+
viewer.playOperation(operation, { durationMs: duration }),
|
|
243
|
+
);
|
|
244
|
+
}, [container, background, operation, duration, nonce]);
|
|
245
|
+
|
|
246
|
+
return (
|
|
247
|
+
<Molecule3DStage style={STAGE_STYLE}>
|
|
248
|
+
{(fullscreen) => (
|
|
249
|
+
<>
|
|
250
|
+
<div
|
|
251
|
+
ref={setContainer}
|
|
252
|
+
style={CANVAS_STYLE}
|
|
253
|
+
data-testid="crystal-3d"
|
|
254
|
+
/>
|
|
255
|
+
{atoms.length > 0 && (
|
|
256
|
+
<MolstarToolbar
|
|
257
|
+
controls={controls}
|
|
258
|
+
tools={{ ...DEFAULT_TOOLS, ...tools }}
|
|
259
|
+
fullscreen={fullscreen}
|
|
260
|
+
measurementCount={measurements.length}
|
|
261
|
+
onClearMeasurements={clearMeasurements}
|
|
262
|
+
onResetView={() => {
|
|
263
|
+
void held.current?.resetCamera(
|
|
264
|
+
DEFAULT_CAMERA_DURATION,
|
|
265
|
+
framing.current,
|
|
266
|
+
);
|
|
267
|
+
}}
|
|
268
|
+
imageExport={imageExport}
|
|
269
|
+
fileName={fileName}
|
|
270
|
+
/>
|
|
271
|
+
)}
|
|
272
|
+
{hovered !== null && (
|
|
273
|
+
<div style={READOUT_STYLE} data-testid="crystal-3d-readout">
|
|
274
|
+
{hovered}
|
|
275
|
+
</div>
|
|
276
|
+
)}
|
|
277
|
+
</>
|
|
278
|
+
)}
|
|
279
|
+
</Molecule3DStage>
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** What was measured, and on which atoms. */
|
|
284
|
+
interface TakenMeasurements {
|
|
285
|
+
readonly atoms: readonly ViewerAtom[];
|
|
286
|
+
readonly list: readonly Measurement[];
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* The measurements taken on the atoms on screen. A new set of atoms is a new
|
|
291
|
+
* structure, whose atoms no measurement names, so the list starts empty again.
|
|
292
|
+
* @param atoms - The atoms on screen.
|
|
293
|
+
* @returns The list, and stable callbacks that change it.
|
|
294
|
+
*/
|
|
295
|
+
function useMeasurementsOf(atoms: readonly ViewerAtom[]): {
|
|
296
|
+
measurements: readonly Measurement[];
|
|
297
|
+
addMeasurement: (measurement: Measurement) => void;
|
|
298
|
+
clearMeasurements: () => void;
|
|
299
|
+
} {
|
|
300
|
+
const latest = useRef(atoms);
|
|
301
|
+
useEffect(() => {
|
|
302
|
+
latest.current = atoms;
|
|
303
|
+
}, [atoms]);
|
|
304
|
+
const [taken, setTaken] = useState<TakenMeasurements>(() => ({
|
|
305
|
+
atoms,
|
|
306
|
+
list: NO_MEASUREMENTS,
|
|
307
|
+
}));
|
|
308
|
+
const addMeasurement = useCallback((measurement: Measurement) => {
|
|
309
|
+
setTaken((previous) => ({
|
|
310
|
+
atoms: latest.current,
|
|
311
|
+
list:
|
|
312
|
+
previous.atoms === latest.current
|
|
313
|
+
? [...previous.list, measurement]
|
|
314
|
+
: [measurement],
|
|
315
|
+
}));
|
|
316
|
+
}, []);
|
|
317
|
+
const clearMeasurements = useCallback(() => {
|
|
318
|
+
setTaken({ atoms: latest.current, list: NO_MEASUREMENTS });
|
|
319
|
+
}, []);
|
|
320
|
+
const measurements = taken.atoms === atoms ? taken.list : NO_MEASUREMENTS;
|
|
321
|
+
return { measurements, addMeasurement, clearMeasurements };
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Report a failure as one sentence, and clear it once the next draw works.
|
|
326
|
+
* @param listener - The ref holding the page's failure callback.
|
|
327
|
+
* @param listener.current - The callback, given the message or `null`.
|
|
328
|
+
* @param work - The draw whose outcome is reported.
|
|
329
|
+
*/
|
|
330
|
+
async function report(
|
|
331
|
+
listener: { current?: (message: string | null) => void },
|
|
332
|
+
work: Promise<void>,
|
|
333
|
+
): Promise<void> {
|
|
334
|
+
try {
|
|
335
|
+
await work;
|
|
336
|
+
listener.current?.(null);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
listener.current?.(
|
|
339
|
+
error instanceof Error ? error.message : 'The scene could not be drawn.',
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const NO_MEASUREMENTS: readonly Measurement[] = [];
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* A crystal is not a molecule: its look is the page's to set — the elements,
|
|
348
|
+
* the labels, the representation — so the display options and the molecular
|
|
349
|
+
* surface are not offered.
|
|
350
|
+
*/
|
|
351
|
+
const DEFAULT_TOOLS: Partial<Molecule3DTools> = {
|
|
352
|
+
options: false,
|
|
353
|
+
surface: false,
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
const STAGE_STYLE: CSSProperties = {
|
|
357
|
+
position: 'relative',
|
|
358
|
+
width: '100%',
|
|
359
|
+
height: '100%',
|
|
360
|
+
minHeight: 0,
|
|
361
|
+
background: TOKEN.surface,
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
/** molstar inserts its canvas here, which therefore has a size of its own. */
|
|
365
|
+
const CANVAS_STYLE: CSSProperties = { position: 'absolute', inset: 0 };
|
|
366
|
+
|
|
367
|
+
/*
|
|
368
|
+
* The readout sits over the canvas rather than beside it, so naming an axis does
|
|
369
|
+
* not reflow the page while the pointer moves.
|
|
370
|
+
*/
|
|
371
|
+
const READOUT_STYLE: CSSProperties = {
|
|
372
|
+
position: 'absolute',
|
|
373
|
+
right: 8,
|
|
374
|
+
bottom: 8,
|
|
375
|
+
left: 8,
|
|
376
|
+
padding: '3px 8px',
|
|
377
|
+
borderRadius: 6,
|
|
378
|
+
background: TOKEN.surface,
|
|
379
|
+
color: TOKEN.text,
|
|
380
|
+
fontSize: 12,
|
|
381
|
+
opacity: 0.92,
|
|
382
|
+
pointerEvents: 'none',
|
|
383
|
+
textAlign: 'right',
|
|
384
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A crystal from its CIF: read, its cell filled by the space group, drawn in
|
|
3
|
+
* 3D with the chips that say how, and a line saying what is on screen.
|
|
4
|
+
*
|
|
5
|
+
* Reached through `React.lazy` from `CrystalStructureViewer`: it bonds
|
|
6
|
+
* atoms by the rule molstar draws bonds with, so what the packing completes is
|
|
7
|
+
* what the viewer joins, and that rule is a molstar module.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Callout } from '@blueprintjs/core';
|
|
11
|
+
import type { CSSProperties, ReactElement } from 'react';
|
|
12
|
+
import { useMemo } from 'react';
|
|
13
|
+
|
|
14
|
+
import type { CellAtoms } from '../../crystal/core/cellAtoms.ts';
|
|
15
|
+
import { crystalCellAtoms } from '../../crystal/core/cellAtoms.ts';
|
|
16
|
+
import { readCif } from '../../crystal/core/cif/read.ts';
|
|
17
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
18
|
+
import { useControlledState } from '../../molecule3d/ui/useControlledState.ts';
|
|
19
|
+
import { bondLimit } from '../../molstar/bonds/index.ts';
|
|
20
|
+
import { crystalView } from '../core/crystalView.ts';
|
|
21
|
+
|
|
22
|
+
import { CrystalViewControls } from './CrystalViewControls.tsx';
|
|
23
|
+
import { CrystalViewer3D } from './CrystalViewer3D.tsx';
|
|
24
|
+
import type { CrystalScene } from './crystalScene.ts';
|
|
25
|
+
import type { CrystalStructureViewerProps } from './crystalStructureViewerProps.ts';
|
|
26
|
+
import { DEFAULT_SETTINGS } from './crystalStructureViewerProps.ts';
|
|
27
|
+
import { useCrystalCaption } from './useCrystalCaption.ts';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The crystal, or why its file could not be drawn.
|
|
31
|
+
* @param props - See {@link CrystalStructureViewerProps}.
|
|
32
|
+
* @returns The view, its chips and its caption.
|
|
33
|
+
*/
|
|
34
|
+
export function CrystalStructureView(
|
|
35
|
+
props: CrystalStructureViewerProps,
|
|
36
|
+
): ReactElement {
|
|
37
|
+
const {
|
|
38
|
+
cif,
|
|
39
|
+
name = '',
|
|
40
|
+
settings: settingsProp,
|
|
41
|
+
defaultSettings = DEFAULT_SETTINGS,
|
|
42
|
+
onSettingsChange,
|
|
43
|
+
height,
|
|
44
|
+
tools,
|
|
45
|
+
fileName,
|
|
46
|
+
onHandle,
|
|
47
|
+
} = props;
|
|
48
|
+
const t = useChromeT();
|
|
49
|
+
const [settings, setSettings] = useControlledState(
|
|
50
|
+
settingsProp,
|
|
51
|
+
defaultSettings,
|
|
52
|
+
onSettingsChange,
|
|
53
|
+
);
|
|
54
|
+
const cell = useMemo(() => readCell(cif), [cif]);
|
|
55
|
+
|
|
56
|
+
if (typeof cell === 'string') {
|
|
57
|
+
return (
|
|
58
|
+
<Callout intent="danger" title={t('crystal3d.unreadable')} compact>
|
|
59
|
+
{cell}
|
|
60
|
+
</Callout>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
if (cell.tooLarge) {
|
|
64
|
+
return (
|
|
65
|
+
<Callout intent="warning" compact>
|
|
66
|
+
{t('crystal3d.tooLarge', { count: cell.count })}
|
|
67
|
+
</Callout>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return (
|
|
71
|
+
<CrystalDrawing
|
|
72
|
+
cell={cell}
|
|
73
|
+
name={name}
|
|
74
|
+
settings={settings}
|
|
75
|
+
onSettingsChange={setSettings}
|
|
76
|
+
height={height}
|
|
77
|
+
tools={tools}
|
|
78
|
+
fileName={fileName}
|
|
79
|
+
onHandle={onHandle}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
type CrystalDrawingProps = Required<
|
|
85
|
+
Pick<CrystalStructureViewerProps, 'name' | 'settings' | 'onSettingsChange'>
|
|
86
|
+
> &
|
|
87
|
+
Pick<
|
|
88
|
+
CrystalStructureViewerProps,
|
|
89
|
+
'height' | 'tools' | 'fileName' | 'onHandle'
|
|
90
|
+
> & {
|
|
91
|
+
cell: CellAtoms;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
function CrystalDrawing(props: CrystalDrawingProps): ReactElement {
|
|
95
|
+
const { cell, name, settings, onSettingsChange, ...viewer } = props;
|
|
96
|
+
const { packing, cells, unitCell } = settings;
|
|
97
|
+
const view = useMemo(
|
|
98
|
+
() => crystalView(cell.atoms, cell.lattice, { packing, cells, bondLimit }),
|
|
99
|
+
[cell, packing, cells],
|
|
100
|
+
);
|
|
101
|
+
const scene = useMemo(
|
|
102
|
+
(): CrystalScene => ({
|
|
103
|
+
atoms: view.atoms,
|
|
104
|
+
cell: unitCell ? cell.lattice.cell : null,
|
|
105
|
+
repeat: [view.cells, view.cells, view.cells],
|
|
106
|
+
}),
|
|
107
|
+
[view, unitCell, cell],
|
|
108
|
+
);
|
|
109
|
+
const caption = useCrystalCaption(name, view, cells);
|
|
110
|
+
return (
|
|
111
|
+
<div style={COLUMN_STYLE}>
|
|
112
|
+
<CrystalViewer3D {...viewer} scene={scene} caption={caption} />
|
|
113
|
+
<CrystalViewControls
|
|
114
|
+
packing={packing}
|
|
115
|
+
onPackingChange={(next) => {
|
|
116
|
+
onSettingsChange({ ...settings, packing: next });
|
|
117
|
+
}}
|
|
118
|
+
unitCell={unitCell}
|
|
119
|
+
onUnitCellChange={(next) => {
|
|
120
|
+
onSettingsChange({ ...settings, unitCell: next });
|
|
121
|
+
}}
|
|
122
|
+
cells={cells}
|
|
123
|
+
onCellsChange={(next) => {
|
|
124
|
+
onSettingsChange({ ...settings, cells: next });
|
|
125
|
+
}}
|
|
126
|
+
/>
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The atoms of one cell, or the sentence saying why the file gives none.
|
|
133
|
+
* @param cif - The file's text.
|
|
134
|
+
* @returns The cell, or the sentence.
|
|
135
|
+
*/
|
|
136
|
+
function readCell(cif: string): CellAtoms | string {
|
|
137
|
+
try {
|
|
138
|
+
return crystalCellAtoms(readCif(cif));
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return error instanceof Error ? error.message : String(error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const COLUMN_STYLE: CSSProperties = {
|
|
145
|
+
display: 'flex',
|
|
146
|
+
flexDirection: 'column',
|
|
147
|
+
gap: 10,
|
|
148
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A crystal from its CIF, in 3D, with the chips that say how it is drawn.
|
|
3
|
+
*
|
|
4
|
+
* ```tsx
|
|
5
|
+
* import { CrystalStructureViewer } from 'react-cheminfo/crystal3d';
|
|
6
|
+
*
|
|
7
|
+
* <CrystalStructureViewer cif={text} name="Aspirin" />;
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Reading the file, filling the cell and drawing it all happen behind a
|
|
11
|
+
* `React.lazy` boundary, so a page that never shows a crystal downloads
|
|
12
|
+
* neither the space groups nor molstar.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { Spinner, SpinnerSize } from '@blueprintjs/core';
|
|
16
|
+
import type { ReactElement } from 'react';
|
|
17
|
+
import { Suspense, lazy } from 'react';
|
|
18
|
+
|
|
19
|
+
import type { CrystalStructureViewerProps } from './crystalStructureViewerProps.ts';
|
|
20
|
+
|
|
21
|
+
const CrystalStructureView = lazy(async () => {
|
|
22
|
+
const module = await import('./CrystalStructureView.tsx');
|
|
23
|
+
return { default: module.CrystalStructureView };
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The crystal, its chips and its caption.
|
|
28
|
+
* @param props - See {@link CrystalStructureViewerProps}.
|
|
29
|
+
* @returns The view, once its code has arrived.
|
|
30
|
+
*/
|
|
31
|
+
export function CrystalStructureViewer(
|
|
32
|
+
props: CrystalStructureViewerProps,
|
|
33
|
+
): ReactElement {
|
|
34
|
+
return (
|
|
35
|
+
<Suspense fallback={<Spinner size={SpinnerSize.STANDARD} />}>
|
|
36
|
+
<CrystalStructureView {...props} />
|
|
37
|
+
</Suspense>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a crystal is drawn: whole molecules or the atoms the cell cuts, whether
|
|
3
|
+
* the box of the cell is drawn, and how many cells along each axis.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ReactElement } from 'react';
|
|
7
|
+
|
|
8
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
9
|
+
import type { CrystalPacking } from '../core/crystalView.ts';
|
|
10
|
+
import { CELL_COUNT_RANGE, CRYSTAL_PACKINGS } from '../core/crystalView.ts';
|
|
11
|
+
|
|
12
|
+
/** Props of {@link CrystalViewControls}. */
|
|
13
|
+
export interface CrystalViewControlsProps {
|
|
14
|
+
/** How the cell is drawn. */
|
|
15
|
+
packing: CrystalPacking;
|
|
16
|
+
onPackingChange: (packing: CrystalPacking) => void;
|
|
17
|
+
/** Whether the box of the unit cell is drawn. */
|
|
18
|
+
unitCell: boolean;
|
|
19
|
+
onUnitCellChange: (unitCell: boolean) => void;
|
|
20
|
+
/** Cells along each axis. */
|
|
21
|
+
cells: number;
|
|
22
|
+
onCellsChange: (cells: number) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The two rows of chips under a crystal.
|
|
27
|
+
* @param props - See {@link CrystalViewControlsProps}.
|
|
28
|
+
* @returns The chip bar.
|
|
29
|
+
*/
|
|
30
|
+
export function CrystalViewControls(
|
|
31
|
+
props: CrystalViewControlsProps,
|
|
32
|
+
): ReactElement {
|
|
33
|
+
const {
|
|
34
|
+
packing,
|
|
35
|
+
onPackingChange,
|
|
36
|
+
unitCell,
|
|
37
|
+
onUnitCellChange,
|
|
38
|
+
cells,
|
|
39
|
+
onCellsChange,
|
|
40
|
+
} = props;
|
|
41
|
+
const t = useChromeT();
|
|
42
|
+
return (
|
|
43
|
+
<div className="chip-bar no-print">
|
|
44
|
+
<div className="chip-row">
|
|
45
|
+
<div className="chip-row__label">{t('crystal3d.draw')}</div>
|
|
46
|
+
<div className="chip-row__chips">
|
|
47
|
+
{CRYSTAL_PACKINGS.map((value) => (
|
|
48
|
+
<button
|
|
49
|
+
key={value}
|
|
50
|
+
type="button"
|
|
51
|
+
className="chip"
|
|
52
|
+
aria-pressed={packing === value}
|
|
53
|
+
title={t(`crystal3d.packing.${value}Help`)}
|
|
54
|
+
onClick={() => {
|
|
55
|
+
onPackingChange(value);
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
{t(`crystal3d.packing.${value}`)}
|
|
59
|
+
</button>
|
|
60
|
+
))}
|
|
61
|
+
<button
|
|
62
|
+
type="button"
|
|
63
|
+
className="chip"
|
|
64
|
+
aria-pressed={unitCell}
|
|
65
|
+
title={t('crystal3d.unitCellHelp')}
|
|
66
|
+
onClick={() => {
|
|
67
|
+
onUnitCellChange(!unitCell);
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
{t('crystal3d.unitCell')}
|
|
71
|
+
</button>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
<div className="chip-row">
|
|
75
|
+
<div className="chip-row__label">{t('crystal3d.cells')}</div>
|
|
76
|
+
<div className="chip-row__chips">
|
|
77
|
+
{CELL_COUNTS.map((count) => (
|
|
78
|
+
<button
|
|
79
|
+
key={count}
|
|
80
|
+
type="button"
|
|
81
|
+
className="chip"
|
|
82
|
+
aria-pressed={cells === count}
|
|
83
|
+
onClick={() => {
|
|
84
|
+
onCellsChange(count);
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
{`${count}×${count}×${count}`}
|
|
88
|
+
</button>
|
|
89
|
+
))}
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** One to four cells along each axis, which is what a shared link may ask for. */
|
|
97
|
+
const CELL_COUNTS: readonly number[] = Array.from(
|
|
98
|
+
{ length: CELL_COUNT_RANGE.maximum - CELL_COUNT_RANGE.minimum + 1 },
|
|
99
|
+
(_, index) => CELL_COUNT_RANGE.minimum + index,
|
|
100
|
+
);
|