react-cheminfo 0.135.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/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 +81 -0
- package/lib/crystal3d/core/crystalView.d.ts.map +1 -0
- package/lib/crystal3d/core/crystalView.js +55 -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 +250 -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 +79 -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 +29 -0
- package/lib/crystal3d/ui/CrystalViewControls.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalViewControls.js +24 -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 +97 -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 +80 -0
- package/lib/crystal3d/viewer/renderStructure.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderStructure.js +143 -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 +119 -0
- package/lib/crystal3d/viewer/viewer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/viewer.js +172 -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/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 +26 -1
- package/lib/locales/en.json +26 -1
- package/lib/locales/es.json +26 -1
- package/lib/locales/fr.json +26 -1
- package/lib/locales/it.json +26 -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 +131 -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 +134 -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 +393 -0
- package/src/crystal3d/ui/CrystalStructureView.tsx +153 -0
- package/src/crystal3d/ui/CrystalStructureViewer.tsx +39 -0
- package/src/crystal3d/ui/CrystalViewControls.tsx +129 -0
- package/src/crystal3d/ui/CrystalViewer3D.tsx +183 -0
- package/src/crystal3d/ui/crystalScene.ts +106 -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 +209 -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 +223 -0
- package/src/crystal3d.ts +12 -0
- 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 +26 -1
- package/src/locales/en.json +26 -1
- package/src/locales/es.json +26 -1
- package/src/locales/fr.json +26 -1
- package/src/locales/it.json +26 -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,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a crystal is drawn: whole molecules or the atoms the cell cuts, whether
|
|
3
|
+
* the box of the cell is drawn, which bonds, and how many cells along each
|
|
4
|
+
* axis.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ReactElement } from 'react';
|
|
8
|
+
|
|
9
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
10
|
+
import type { CrystalBonds, CrystalPacking } from '../core/crystalView.ts';
|
|
11
|
+
import {
|
|
12
|
+
CELL_COUNT_RANGE,
|
|
13
|
+
CRYSTAL_BONDS,
|
|
14
|
+
CRYSTAL_PACKINGS,
|
|
15
|
+
} from '../core/crystalView.ts';
|
|
16
|
+
|
|
17
|
+
/** Props of {@link CrystalViewControls}. */
|
|
18
|
+
export interface CrystalViewControlsProps {
|
|
19
|
+
/** How the cell is drawn. */
|
|
20
|
+
packing: CrystalPacking;
|
|
21
|
+
onPackingChange: (packing: CrystalPacking) => void;
|
|
22
|
+
/** Whether the box of the unit cell is drawn. */
|
|
23
|
+
unitCell: boolean;
|
|
24
|
+
onUnitCellChange: (unitCell: boolean) => void;
|
|
25
|
+
/** Which bonds are drawn. */
|
|
26
|
+
bonds: CrystalBonds;
|
|
27
|
+
onBondsChange: (bonds: CrystalBonds) => void;
|
|
28
|
+
/** Cells along each axis. */
|
|
29
|
+
cells: number;
|
|
30
|
+
onCellsChange: (cells: number) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The rows of chips under a crystal.
|
|
35
|
+
* @param props - See {@link CrystalViewControlsProps}.
|
|
36
|
+
* @returns The chip bar.
|
|
37
|
+
*/
|
|
38
|
+
export function CrystalViewControls(
|
|
39
|
+
props: CrystalViewControlsProps,
|
|
40
|
+
): ReactElement {
|
|
41
|
+
const {
|
|
42
|
+
packing,
|
|
43
|
+
onPackingChange,
|
|
44
|
+
unitCell,
|
|
45
|
+
onUnitCellChange,
|
|
46
|
+
bonds,
|
|
47
|
+
onBondsChange,
|
|
48
|
+
cells,
|
|
49
|
+
onCellsChange,
|
|
50
|
+
} = props;
|
|
51
|
+
const t = useChromeT();
|
|
52
|
+
return (
|
|
53
|
+
<div className="chip-bar no-print">
|
|
54
|
+
<div className="chip-row">
|
|
55
|
+
<div className="chip-row__label">{t('crystal3d.draw')}</div>
|
|
56
|
+
<div className="chip-row__chips">
|
|
57
|
+
{CRYSTAL_PACKINGS.map((value) => (
|
|
58
|
+
<button
|
|
59
|
+
key={value}
|
|
60
|
+
type="button"
|
|
61
|
+
className="chip"
|
|
62
|
+
aria-pressed={packing === value}
|
|
63
|
+
title={t(`crystal3d.packing.${value}Help`)}
|
|
64
|
+
onClick={() => {
|
|
65
|
+
onPackingChange(value);
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
{t(`crystal3d.packing.${value}`)}
|
|
69
|
+
</button>
|
|
70
|
+
))}
|
|
71
|
+
<button
|
|
72
|
+
type="button"
|
|
73
|
+
className="chip"
|
|
74
|
+
aria-pressed={unitCell}
|
|
75
|
+
title={t('crystal3d.unitCellHelp')}
|
|
76
|
+
onClick={() => {
|
|
77
|
+
onUnitCellChange(!unitCell);
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
{t('crystal3d.unitCell')}
|
|
81
|
+
</button>
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
<div className="chip-row">
|
|
85
|
+
<div className="chip-row__label">{t('crystal3d.bonds')}</div>
|
|
86
|
+
<div className="chip-row__chips">
|
|
87
|
+
{CRYSTAL_BONDS.map((value) => (
|
|
88
|
+
<button
|
|
89
|
+
key={value}
|
|
90
|
+
type="button"
|
|
91
|
+
className="chip"
|
|
92
|
+
aria-pressed={bonds === value}
|
|
93
|
+
title={t(`crystal3d.bonds.${value}Help`)}
|
|
94
|
+
onClick={() => {
|
|
95
|
+
onBondsChange(value);
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
{t(`crystal3d.bonds.${value}`)}
|
|
99
|
+
</button>
|
|
100
|
+
))}
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
<div className="chip-row">
|
|
104
|
+
<div className="chip-row__label">{t('crystal3d.cells')}</div>
|
|
105
|
+
<div className="chip-row__chips">
|
|
106
|
+
{CELL_COUNTS.map((count) => (
|
|
107
|
+
<button
|
|
108
|
+
key={count}
|
|
109
|
+
type="button"
|
|
110
|
+
className="chip"
|
|
111
|
+
aria-pressed={cells === count}
|
|
112
|
+
onClick={() => {
|
|
113
|
+
onCellsChange(count);
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
{`${count}×${count}×${count}`}
|
|
117
|
+
</button>
|
|
118
|
+
))}
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** One to four cells along each axis, which is what a shared link may ask for. */
|
|
126
|
+
const CELL_COUNTS: readonly number[] = Array.from(
|
|
127
|
+
{ length: CELL_COUNT_RANGE.maximum - CELL_COUNT_RANGE.minimum + 1 },
|
|
128
|
+
(_, index) => CELL_COUNT_RANGE.minimum + index,
|
|
129
|
+
);
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The crystal in 3D: what surrounds the canvas, and what to say when there
|
|
3
|
+
* cannot be one.
|
|
4
|
+
*
|
|
5
|
+
* Two things are settled before molstar is touched. The WebGL probe runs first,
|
|
6
|
+
* because molstar ships no canvas or SVG fallback and a locked-down school
|
|
7
|
+
* machine would otherwise get a blank rectangle with no explanation. And the
|
|
8
|
+
* canvas is a `React.lazy` boundary, so a page that never shows a crystal
|
|
9
|
+
* never downloads it.
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { CrystalViewer3D } from 'react-cheminfo/crystal3d';
|
|
13
|
+
*
|
|
14
|
+
* <CrystalViewer3D scene={{ atoms, cell, repeat: [2, 2, 2] }} height={480} />;
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { Callout, Spinner, SpinnerSize } from '@blueprintjs/core';
|
|
19
|
+
import type { CSSProperties, ReactElement, ReactNode } from 'react';
|
|
20
|
+
import { Suspense, lazy, useState } from 'react';
|
|
21
|
+
|
|
22
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
23
|
+
import type { Molecule3DTools } from '../../molecule3d/core/settings.ts';
|
|
24
|
+
// Deep import on purpose: the probe imports nothing, while a barrel would pull
|
|
25
|
+
// molstar in — which is exactly what asking first exists to avoid.
|
|
26
|
+
import { probeViewerCapability } from '../../orbital/ui/capability.ts';
|
|
27
|
+
import { TOKEN } from '../../tokens/core/familyTokens.ts';
|
|
28
|
+
|
|
29
|
+
import type { CrystalScene, CrystalViewHandle } from './crystalScene.ts';
|
|
30
|
+
|
|
31
|
+
const CrystalCanvas3D = lazy(async () => {
|
|
32
|
+
const module = await import('./CrystalCanvas3D.tsx');
|
|
33
|
+
return { default: module.CrystalCanvas3D };
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** Props of {@link CrystalViewer3D}. */
|
|
37
|
+
export interface CrystalViewer3DProps {
|
|
38
|
+
/** What to show. */
|
|
39
|
+
scene: CrystalScene;
|
|
40
|
+
/**
|
|
41
|
+
* How tall the canvas is: pixels, or any CSS length.
|
|
42
|
+
* @default 420
|
|
43
|
+
*/
|
|
44
|
+
height?: number | string;
|
|
45
|
+
/**
|
|
46
|
+
* Scene background, `#rrggbb`.
|
|
47
|
+
* @default '#ffffff'
|
|
48
|
+
*/
|
|
49
|
+
background?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Which tools the toolbars offer; every one it does not name is on.
|
|
52
|
+
* @default every tool but the display options and the surface
|
|
53
|
+
*/
|
|
54
|
+
tools?: Partial<Molecule3DTools>;
|
|
55
|
+
/**
|
|
56
|
+
* Base name of a picture saved from the toolbar, extension excluded.
|
|
57
|
+
* @default 'crystal'
|
|
58
|
+
*/
|
|
59
|
+
fileName?: string;
|
|
60
|
+
/**
|
|
61
|
+
* One line under the canvas — what is on screen, or where it came from.
|
|
62
|
+
* @default undefined
|
|
63
|
+
*/
|
|
64
|
+
caption?: ReactNode;
|
|
65
|
+
/**
|
|
66
|
+
* What to say instead of a canvas when the scene holds no atoms.
|
|
67
|
+
* @default undefined — the frame stays empty
|
|
68
|
+
*/
|
|
69
|
+
emptyMessage?: ReactNode;
|
|
70
|
+
/**
|
|
71
|
+
* What to say on a machine that cannot draw in 3D, after the reason.
|
|
72
|
+
* @default undefined
|
|
73
|
+
*/
|
|
74
|
+
unsupportedNote?: ReactNode;
|
|
75
|
+
/**
|
|
76
|
+
* Called with the means to picture the scene once the canvas exists, and with
|
|
77
|
+
* `null` once it is gone.
|
|
78
|
+
* @default undefined
|
|
79
|
+
*/
|
|
80
|
+
onHandle?: (handle: CrystalViewHandle | null) => void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The 3D crystal, with its failure and no-WebGL messages.
|
|
85
|
+
* @param props - See {@link CrystalViewer3DProps}.
|
|
86
|
+
* @returns The viewer, or an explanation of why this machine cannot show one.
|
|
87
|
+
*/
|
|
88
|
+
export function CrystalViewer3D(props: CrystalViewer3DProps): ReactElement {
|
|
89
|
+
const {
|
|
90
|
+
scene,
|
|
91
|
+
height = 420,
|
|
92
|
+
background,
|
|
93
|
+
tools,
|
|
94
|
+
fileName,
|
|
95
|
+
caption,
|
|
96
|
+
emptyMessage,
|
|
97
|
+
unsupportedNote,
|
|
98
|
+
onHandle,
|
|
99
|
+
} = props;
|
|
100
|
+
const t = useChromeT();
|
|
101
|
+
const [capability] = useState(probeViewerCapability);
|
|
102
|
+
const [failure, setFailure] = useState<string | null>(null);
|
|
103
|
+
|
|
104
|
+
if (!capability.supported) {
|
|
105
|
+
return (
|
|
106
|
+
<Callout
|
|
107
|
+
intent="warning"
|
|
108
|
+
icon="desktop"
|
|
109
|
+
title={t('crystal3d.unsupported')}
|
|
110
|
+
compact
|
|
111
|
+
>
|
|
112
|
+
{t.or(`viewer.capability.${capability.reason}`, capability.message)}{' '}
|
|
113
|
+
{unsupportedNote}
|
|
114
|
+
</Callout>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<div style={ROOT_STYLE}>
|
|
120
|
+
<div style={{ ...FRAME_STYLE, height }}>
|
|
121
|
+
{scene.atoms.length === 0 ? (
|
|
122
|
+
<div style={NOTICE_STYLE}>{emptyMessage}</div>
|
|
123
|
+
) : (
|
|
124
|
+
<Suspense
|
|
125
|
+
fallback={
|
|
126
|
+
<div style={NOTICE_STYLE}>
|
|
127
|
+
<Spinner size={SpinnerSize.STANDARD} />
|
|
128
|
+
<span>{t('molecule3d.loadingViewer')}</span>
|
|
129
|
+
</div>
|
|
130
|
+
}
|
|
131
|
+
>
|
|
132
|
+
<CrystalCanvas3D
|
|
133
|
+
scene={scene}
|
|
134
|
+
background={background}
|
|
135
|
+
tools={tools}
|
|
136
|
+
fileName={fileName}
|
|
137
|
+
onFailure={setFailure}
|
|
138
|
+
onHandle={onHandle}
|
|
139
|
+
/>
|
|
140
|
+
</Suspense>
|
|
141
|
+
)}
|
|
142
|
+
</div>
|
|
143
|
+
{caption === undefined ? null : (
|
|
144
|
+
<div style={CAPTION_STYLE}>{caption}</div>
|
|
145
|
+
)}
|
|
146
|
+
{failure !== null && (
|
|
147
|
+
<Callout intent="danger" title={t('molecule3d.couldNotDraw')} compact>
|
|
148
|
+
{failure}
|
|
149
|
+
</Callout>
|
|
150
|
+
)}
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const ROOT_STYLE: CSSProperties = {
|
|
156
|
+
display: 'flex',
|
|
157
|
+
flexDirection: 'column',
|
|
158
|
+
gap: 6,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const FRAME_STYLE: CSSProperties = {
|
|
162
|
+
position: 'relative',
|
|
163
|
+
overflow: 'hidden',
|
|
164
|
+
borderRadius: TOKEN.radius,
|
|
165
|
+
border: `1px solid ${TOKEN.border}`,
|
|
166
|
+
background: TOKEN.surface,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const NOTICE_STYLE: CSSProperties = {
|
|
170
|
+
display: 'flex',
|
|
171
|
+
height: '100%',
|
|
172
|
+
flexDirection: 'column',
|
|
173
|
+
alignItems: 'center',
|
|
174
|
+
justifyContent: 'center',
|
|
175
|
+
gap: 10,
|
|
176
|
+
color: TOKEN.textMuted,
|
|
177
|
+
fontSize: 13,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const CAPTION_STYLE: CSSProperties = {
|
|
181
|
+
color: TOKEN.textMuted,
|
|
182
|
+
fontSize: 12,
|
|
183
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a page asks the crystal view to show.
|
|
3
|
+
*
|
|
4
|
+
* It is a plain description — atoms, a cell, a set of elements, an operation to
|
|
5
|
+
* play — so a page can build one without importing anything that pulls molstar
|
|
6
|
+
* in. The canvas that reads it is behind a `React.lazy` boundary, and this type
|
|
7
|
+
* is on the near side of it.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Molecule3DCamera } from '../../molecule3d/core/camera.ts';
|
|
11
|
+
import type { Molecule3DCapture } from '../../molecule3d/ui/moleculeViewer3DProps.ts';
|
|
12
|
+
import type { CrystalBonds } from '../core/crystalView.ts';
|
|
13
|
+
import type { ElementStyle } from '../core/primitives.ts';
|
|
14
|
+
import type {
|
|
15
|
+
CellRepeat,
|
|
16
|
+
SymmetryDrawing,
|
|
17
|
+
UnitCell,
|
|
18
|
+
ViewerAtom,
|
|
19
|
+
ViewerOperation,
|
|
20
|
+
} from '../core/types.ts';
|
|
21
|
+
|
|
22
|
+
/** An operation to apply, and the cue that applies it again. */
|
|
23
|
+
export interface OperationPlayback {
|
|
24
|
+
/**
|
|
25
|
+
* Changing this number replays the operation; keeping it leaves the structure
|
|
26
|
+
* where it is. It is a cue rather than a flag so that pressing *Apply* twice
|
|
27
|
+
* plays it twice.
|
|
28
|
+
*/
|
|
29
|
+
readonly nonce: number;
|
|
30
|
+
/** What to apply. */
|
|
31
|
+
readonly operation: ViewerOperation;
|
|
32
|
+
/**
|
|
33
|
+
* How long one application takes, milliseconds.
|
|
34
|
+
* @default 900
|
|
35
|
+
*/
|
|
36
|
+
readonly durationMs?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Everything on screen at once. */
|
|
40
|
+
export interface CrystalScene {
|
|
41
|
+
/**
|
|
42
|
+
* The atoms, expanded and repeated already, in Cartesian ångström. An empty
|
|
43
|
+
* list draws no structure, which is what an empty workbench shows.
|
|
44
|
+
*/
|
|
45
|
+
readonly atoms: readonly ViewerAtom[];
|
|
46
|
+
/**
|
|
47
|
+
* The cell the atoms sit in, when there is one.
|
|
48
|
+
* @default null
|
|
49
|
+
*/
|
|
50
|
+
readonly cell?: UnitCell | null;
|
|
51
|
+
/**
|
|
52
|
+
* How many cells the box is drawn around. It does not repeat the atoms —
|
|
53
|
+
* `supercellAtoms` does that, and the page has already called it.
|
|
54
|
+
* @default [1, 1, 1]
|
|
55
|
+
*/
|
|
56
|
+
readonly repeat?: CellRepeat;
|
|
57
|
+
/**
|
|
58
|
+
* The symmetry elements drawn over the structure.
|
|
59
|
+
* @default []
|
|
60
|
+
*/
|
|
61
|
+
readonly elements?: readonly SymmetryDrawing[];
|
|
62
|
+
/**
|
|
63
|
+
* Whether each element's name floats beside it.
|
|
64
|
+
* @default true
|
|
65
|
+
*/
|
|
66
|
+
readonly labels?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* How thick and how large those elements are drawn. A cell scales it to its
|
|
69
|
+
* own edges, so the same figure reads the same on a 3.9 Å perovskite and a
|
|
70
|
+
* 24 Å zeolite.
|
|
71
|
+
* @default the defaults of `primitives.ts`
|
|
72
|
+
*/
|
|
73
|
+
readonly elementStyle?: ElementStyle;
|
|
74
|
+
/**
|
|
75
|
+
* How the atoms are drawn.
|
|
76
|
+
* @default 'ball-and-stick'
|
|
77
|
+
*/
|
|
78
|
+
readonly representation?: 'ball-and-stick' | 'spacefill';
|
|
79
|
+
/**
|
|
80
|
+
* Which bonds are drawn; changing it leaves the camera where it is.
|
|
81
|
+
* @default 'all'
|
|
82
|
+
*/
|
|
83
|
+
readonly bonds?: CrystalBonds;
|
|
84
|
+
/**
|
|
85
|
+
* An operation waiting to be applied.
|
|
86
|
+
* @default null
|
|
87
|
+
*/
|
|
88
|
+
readonly play?: OperationPlayback | null;
|
|
89
|
+
/**
|
|
90
|
+
* Where the camera stands when this structure is drawn — the view a figure
|
|
91
|
+
* carried — instead of the framing every new structure gets. It is put back
|
|
92
|
+
* once; a later redraw frames the scene again.
|
|
93
|
+
* @default null
|
|
94
|
+
*/
|
|
95
|
+
readonly camera?: Molecule3DCamera | null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** What the canvas hands a page that pictures it. */
|
|
99
|
+
export interface CrystalViewHandle {
|
|
100
|
+
/** Render the scene as a figure. */
|
|
101
|
+
readonly capture: Molecule3DCapture;
|
|
102
|
+
/** Where the camera stands, against what is drawn; `null` before anything is. */
|
|
103
|
+
readonly readCamera: () => Promise<Molecule3DCamera | null>;
|
|
104
|
+
/** Resolves once the structure asked for last is drawn. */
|
|
105
|
+
readonly whenDrawn: () => Promise<void>;
|
|
106
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Molecule3DTools } from '../../molecule3d/core/settings.ts';
|
|
2
|
+
import type { CrystalViewSettings } from '../core/crystalView.ts';
|
|
3
|
+
|
|
4
|
+
import type { CrystalViewHandle } from './crystalScene.ts';
|
|
5
|
+
|
|
6
|
+
/** Props of `CrystalStructureViewer`. */
|
|
7
|
+
export interface CrystalStructureViewerProps {
|
|
8
|
+
/** The CIF, as text. */
|
|
9
|
+
cif: string;
|
|
10
|
+
/**
|
|
11
|
+
* What the crystal is called, at the head of the caption.
|
|
12
|
+
* @default ''
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
15
|
+
/**
|
|
16
|
+
* How the crystal is drawn, when the page owns it — to keep it in the
|
|
17
|
+
* address, for one.
|
|
18
|
+
* @default undefined
|
|
19
|
+
*/
|
|
20
|
+
settings?: CrystalViewSettings;
|
|
21
|
+
/**
|
|
22
|
+
* How the crystal is drawn at first, when the viewer owns it.
|
|
23
|
+
* @default DEFAULT_CRYSTAL_VIEW_SETTINGS
|
|
24
|
+
*/
|
|
25
|
+
defaultSettings?: CrystalViewSettings;
|
|
26
|
+
/**
|
|
27
|
+
* Called with every change a chip makes.
|
|
28
|
+
* @default undefined
|
|
29
|
+
*/
|
|
30
|
+
onSettingsChange?: (settings: CrystalViewSettings) => void;
|
|
31
|
+
/**
|
|
32
|
+
* How tall the canvas is: pixels, or any CSS length.
|
|
33
|
+
* @default 420
|
|
34
|
+
*/
|
|
35
|
+
height?: number | string;
|
|
36
|
+
/**
|
|
37
|
+
* Which tools the toolbars offer; every one it does not name is on.
|
|
38
|
+
* @default every tool but the display options and the surface
|
|
39
|
+
*/
|
|
40
|
+
tools?: Partial<Molecule3DTools>;
|
|
41
|
+
/**
|
|
42
|
+
* Base name of a picture saved from the toolbar, extension excluded.
|
|
43
|
+
* @default 'crystal'
|
|
44
|
+
*/
|
|
45
|
+
fileName?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Called with the means to picture the scene once the canvas exists, and with
|
|
48
|
+
* `null` once it is gone.
|
|
49
|
+
* @default undefined
|
|
50
|
+
*/
|
|
51
|
+
onHandle?: (handle: CrystalViewHandle | null) => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { DEFAULT_CRYSTAL_VIEW_SETTINGS as DEFAULT_SETTINGS } from '../core/crystalView.ts';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a page imports to show a crystal in 3D.
|
|
3
|
+
*
|
|
4
|
+
* **Nothing exported here may pull molstar in statically.** The canvas, the
|
|
5
|
+
* viewer class and the bond rule are reached through `React.lazy` only;
|
|
6
|
+
* type-only re-exports are erased and so are safe.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type {
|
|
10
|
+
CrystalScene,
|
|
11
|
+
CrystalViewHandle,
|
|
12
|
+
OperationPlayback,
|
|
13
|
+
} from './crystalScene.ts';
|
|
14
|
+
export type { CrystalStructureViewerProps } from './crystalStructureViewerProps.ts';
|
|
15
|
+
export { CrystalStructureViewer } from './CrystalStructureViewer.tsx';
|
|
16
|
+
export type { CrystalViewControlsProps } from './CrystalViewControls.tsx';
|
|
17
|
+
export { CrystalViewControls } from './CrystalViewControls.tsx';
|
|
18
|
+
export type { CrystalViewer3DProps } from './CrystalViewer3D.tsx';
|
|
19
|
+
export { CrystalViewer3D } from './CrystalViewer3D.tsx';
|
|
20
|
+
export { useCrystalCaption } from './useCrystalCaption.ts';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One line under a crystal saying what is on it: its name, what one cell
|
|
3
|
+
* holds, and how many cells are drawn.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
7
|
+
import type { CrystalView } from '../core/crystalView.ts';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The caption of a crystal view.
|
|
11
|
+
* @param name - What the crystal is called; left out when empty.
|
|
12
|
+
* @param view - What `crystalView` found.
|
|
13
|
+
* @param asked - Cells along each axis asked for.
|
|
14
|
+
* @returns e.g. `Aspirin · 4 molecules per cell · 2×2×2 cells`.
|
|
15
|
+
*/
|
|
16
|
+
export function useCrystalCaption(
|
|
17
|
+
name: string,
|
|
18
|
+
view: Pick<CrystalView, 'molecules' | 'atomsPerCell' | 'cells'>,
|
|
19
|
+
asked: number,
|
|
20
|
+
): string {
|
|
21
|
+
const t = useChromeT();
|
|
22
|
+
const parts = [
|
|
23
|
+
name,
|
|
24
|
+
view.molecules > 0
|
|
25
|
+
? view.molecules === 1
|
|
26
|
+
? t('crystal3d.caption.molecules.one')
|
|
27
|
+
: t('crystal3d.caption.molecules.other', { count: view.molecules })
|
|
28
|
+
: view.atomsPerCell === 1
|
|
29
|
+
? t('crystal3d.caption.atoms.one')
|
|
30
|
+
: t('crystal3d.caption.atoms.other', { count: view.atomsPerCell }),
|
|
31
|
+
view.cells < asked
|
|
32
|
+
? t('crystal3d.caption.cellsCapped', { count: view.cells, asked })
|
|
33
|
+
: view.cells === 1
|
|
34
|
+
? t('crystal3d.caption.cells.one')
|
|
35
|
+
: t('crystal3d.caption.cells.other', { count: view.cells }),
|
|
36
|
+
];
|
|
37
|
+
return parts.filter((part) => part !== '').join(' · ');
|
|
38
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applying an operation to the structure, so a student watches it land back on
|
|
3
|
+
* itself.
|
|
4
|
+
*
|
|
5
|
+
* The structure moves and the symmetry elements do not: an axis that turned with
|
|
6
|
+
* the molecule would prove nothing. Moving it costs one GPU uniform per frame —
|
|
7
|
+
* `Representation.State.transform` is written straight into the renderable — so
|
|
8
|
+
* nothing is rebuilt and nothing is re-uploaded while the animation runs.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Mat4 } from 'molstar/lib/mol-math/linear-algebra.js';
|
|
12
|
+
import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
13
|
+
|
|
14
|
+
import type { Matrix4 } from '../core/operationMatrix.ts';
|
|
15
|
+
import { IDENTITY_MATRIX4, operationAt } from '../core/operationMatrix.ts';
|
|
16
|
+
import type { ViewerOperation } from '../core/types.ts';
|
|
17
|
+
|
|
18
|
+
import { structureRepresentation } from './renderStructure.ts';
|
|
19
|
+
|
|
20
|
+
/** How an operation is played. */
|
|
21
|
+
export interface PlayOptions {
|
|
22
|
+
/**
|
|
23
|
+
* How long one application takes, milliseconds.
|
|
24
|
+
* @default 900
|
|
25
|
+
*/
|
|
26
|
+
durationMs?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Called with the fraction played, 0 to 1, on every frame.
|
|
29
|
+
* @default undefined
|
|
30
|
+
*/
|
|
31
|
+
onProgress?: (fraction: number) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Play one application of an operation, and leave the structure where it lands.
|
|
36
|
+
*
|
|
37
|
+
* A second call cancels the first, so a student hammering the button never sees
|
|
38
|
+
* two animations fight.
|
|
39
|
+
* @param plugin - The molstar context.
|
|
40
|
+
* @param operation - What to apply.
|
|
41
|
+
* @param options - See {@link PlayOptions}.
|
|
42
|
+
* @returns Resolves when the operation has been applied in full, or as soon as
|
|
43
|
+
* a later call has taken over.
|
|
44
|
+
*/
|
|
45
|
+
export function playOperation(
|
|
46
|
+
plugin: PluginContext,
|
|
47
|
+
operation: ViewerOperation,
|
|
48
|
+
options: PlayOptions = {},
|
|
49
|
+
): Promise<void> {
|
|
50
|
+
const { durationMs = 900, onProgress } = options;
|
|
51
|
+
const token = (tokens.get(plugin) ?? 0) + 1;
|
|
52
|
+
tokens.set(plugin, token);
|
|
53
|
+
if (durationMs <= 0) {
|
|
54
|
+
setOperationFraction(plugin, operation, 1);
|
|
55
|
+
onProgress?.(1);
|
|
56
|
+
return Promise.resolve();
|
|
57
|
+
}
|
|
58
|
+
const started = now();
|
|
59
|
+
return new Promise<void>((resolve) => {
|
|
60
|
+
const step = (): void => {
|
|
61
|
+
if (tokens.get(plugin) !== token) {
|
|
62
|
+
resolve();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const fraction = Math.min(1, (now() - started) / durationMs);
|
|
66
|
+
setOperationFraction(plugin, operation, fraction);
|
|
67
|
+
onProgress?.(fraction);
|
|
68
|
+
if (fraction < 1) globalThis.requestAnimationFrame(step);
|
|
69
|
+
else resolve();
|
|
70
|
+
};
|
|
71
|
+
globalThis.requestAnimationFrame(step);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Hold the structure part-way through an operation, for a slider.
|
|
77
|
+
* @param plugin - The molstar context.
|
|
78
|
+
* @param operation - What is being applied.
|
|
79
|
+
* @param fraction - How far through, 0 to 1.
|
|
80
|
+
*/
|
|
81
|
+
export function setOperationFraction(
|
|
82
|
+
plugin: PluginContext,
|
|
83
|
+
operation: ViewerOperation,
|
|
84
|
+
fraction: number,
|
|
85
|
+
): void {
|
|
86
|
+
applyTransform(plugin, operationAt(operation, fraction));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Put the structure back where it started, and stop any animation in flight.
|
|
91
|
+
* @param plugin - The molstar context.
|
|
92
|
+
*/
|
|
93
|
+
export function resetOperation(plugin: PluginContext): void {
|
|
94
|
+
tokens.set(plugin, (tokens.get(plugin) ?? 0) + 1);
|
|
95
|
+
applyTransform(plugin, IDENTITY_MATRIX4);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function applyTransform(plugin: PluginContext, matrix: Matrix4): void {
|
|
99
|
+
const representation = structureRepresentation(plugin);
|
|
100
|
+
if (representation === undefined) return;
|
|
101
|
+
representation.setState({
|
|
102
|
+
transform: Mat4.fromArray(Mat4.identity(), matrix as number[], 0),
|
|
103
|
+
});
|
|
104
|
+
plugin.canvas3d?.update(representation);
|
|
105
|
+
plugin.canvas3d?.requestDraw();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function now(): number {
|
|
109
|
+
return globalThis.performance.now();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The animation in flight per plugin; a new one invalidates the old. */
|
|
113
|
+
const tokens = new WeakMap<PluginContext, number>();
|