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,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The viewer a crystal page drives: a structure, a cell, a set of symmetry
|
|
3
|
+
* elements, and an operation applied to the first of them.
|
|
4
|
+
*
|
|
5
|
+
* Nothing here parses a space group or expands an orbit. The atoms arrive in
|
|
6
|
+
* their final places, because molstar's own expansion neither wraps into the
|
|
7
|
+
* cell nor deduplicates a special position, and falls back to `P 1` without a
|
|
8
|
+
* word on several common settings.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { clearMeasurements } from '../../molstar/core/index.ts';
|
|
12
|
+
import type { CrystalBonds } from '../core/crystalView.ts';
|
|
13
|
+
import { mergeDrawings, withoutDrawings } from '../core/drawingSet.ts';
|
|
14
|
+
import type {
|
|
15
|
+
CellRepeat,
|
|
16
|
+
SymmetryDrawing,
|
|
17
|
+
UnitCell,
|
|
18
|
+
ViewerAtom,
|
|
19
|
+
ViewerOperation,
|
|
20
|
+
} from '../core/types.ts';
|
|
21
|
+
|
|
22
|
+
import type { PlayOptions } from './animate.ts';
|
|
23
|
+
import {
|
|
24
|
+
playOperation,
|
|
25
|
+
resetOperation,
|
|
26
|
+
setOperationFraction,
|
|
27
|
+
} from './animate.ts';
|
|
28
|
+
import type { CrystalViewerOptions } from './plugin.ts';
|
|
29
|
+
import { CrystalViewerPlugin } from './plugin.ts';
|
|
30
|
+
import type { CellStyle } from './renderCell.ts';
|
|
31
|
+
import type { ElementLayerStyle } from './renderElements.ts';
|
|
32
|
+
import type { StructureStyle } from './renderStructure.ts';
|
|
33
|
+
import { setStructureBonds } from './renderStructure.ts';
|
|
34
|
+
import { drawCell, drawElements, drawStructure } from './sceneParts.ts';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create a crystal viewer inside `container` and start initialising it.
|
|
38
|
+
* @param container - An element with `position: relative`; molstar inserts its
|
|
39
|
+
* own canvas into it.
|
|
40
|
+
* @param options - See {@link CrystalViewerOptions}.
|
|
41
|
+
* @returns A handle that is safe to dispose immediately.
|
|
42
|
+
*/
|
|
43
|
+
export function createCrystalViewer(
|
|
44
|
+
container: HTMLElement,
|
|
45
|
+
options: CrystalViewerOptions = {},
|
|
46
|
+
): CrystalViewer {
|
|
47
|
+
return new CrystalViewer(container, options);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Everything a crystal page draws, on one canvas: the lifecycle, the camera,
|
|
52
|
+
* the measurements and the hover readout come from {@link CrystalViewerPlugin},
|
|
53
|
+
* the scene is here.
|
|
54
|
+
*/
|
|
55
|
+
export class CrystalViewer extends CrystalViewerPlugin {
|
|
56
|
+
#drawings: readonly SymmetryDrawing[] = [];
|
|
57
|
+
#elementStyle: ElementLayerStyle = {};
|
|
58
|
+
#bonds: CrystalBonds = 'all';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The symmetry elements drawn right now, in drawing order.
|
|
62
|
+
* @returns The drawings on screen.
|
|
63
|
+
*/
|
|
64
|
+
get elements(): readonly SymmetryDrawing[] {
|
|
65
|
+
return this.#drawings;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Replace the atoms on screen.
|
|
70
|
+
* @param atoms - The whole scene, expanded and repeated already, in Cartesian
|
|
71
|
+
* ångström. An empty list clears them.
|
|
72
|
+
* @param style - See {@link StructureStyle}; its bonds are the ones last
|
|
73
|
+
* set by {@link CrystalViewer.setBonds}.
|
|
74
|
+
* @returns Resolves once the atoms are drawn.
|
|
75
|
+
*/
|
|
76
|
+
showStructure(
|
|
77
|
+
atoms: readonly ViewerAtom[],
|
|
78
|
+
style?: Omit<StructureStyle, 'bonds'>,
|
|
79
|
+
): Promise<void> {
|
|
80
|
+
// A measurement names atoms of the structure it was taken on.
|
|
81
|
+
return this.run(async (plugin) => {
|
|
82
|
+
await clearMeasurements(plugin);
|
|
83
|
+
await drawStructure(plugin, atoms, { ...style, bonds: this.#bonds });
|
|
84
|
+
});
|
|
85
|
+
}
|
|
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
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Remove the atoms, leaving the cell and the elements in place.
|
|
101
|
+
* @returns Resolves once the atoms are gone.
|
|
102
|
+
*/
|
|
103
|
+
hideStructure(): Promise<void> {
|
|
104
|
+
return this.run(async (plugin) => {
|
|
105
|
+
await clearMeasurements(plugin);
|
|
106
|
+
await drawStructure(plugin, []);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Replace the unit cell box, and the stack of cells around it.
|
|
112
|
+
* @param cell - The six cell parameters, or `null` to draw none.
|
|
113
|
+
* @param repeat - Cells along a, b and c.
|
|
114
|
+
* @param style - See {@link CellStyle}.
|
|
115
|
+
* @returns Resolves once the cell is drawn.
|
|
116
|
+
*/
|
|
117
|
+
showCell(
|
|
118
|
+
cell: UnitCell | null,
|
|
119
|
+
repeat: CellRepeat = [1, 1, 1],
|
|
120
|
+
style?: CellStyle,
|
|
121
|
+
): Promise<void> {
|
|
122
|
+
return this.run((plugin) => drawCell(plugin, cell, repeat, style));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Remove the cell.
|
|
127
|
+
* @returns Resolves once the cell is gone.
|
|
128
|
+
*/
|
|
129
|
+
hideCell(): Promise<void> {
|
|
130
|
+
return this.run((plugin) => drawCell(plugin, null));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Replace every drawn symmetry element.
|
|
135
|
+
* @param drawings - The elements; an empty list clears them.
|
|
136
|
+
* @param style - See {@link ElementLayerStyle}; kept for later edits.
|
|
137
|
+
* @returns Resolves once the elements are drawn.
|
|
138
|
+
*/
|
|
139
|
+
showElements(
|
|
140
|
+
drawings: readonly SymmetryDrawing[],
|
|
141
|
+
style?: ElementLayerStyle,
|
|
142
|
+
): Promise<void> {
|
|
143
|
+
if (style !== undefined) this.#elementStyle = style;
|
|
144
|
+
this.#drawings = [...drawings];
|
|
145
|
+
return this.#redrawElements();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Draw these elements as well, replacing any already drawn under the same id.
|
|
150
|
+
* @param drawings - What to add.
|
|
151
|
+
* @returns Resolves once the elements are drawn.
|
|
152
|
+
*/
|
|
153
|
+
addElements(drawings: readonly SymmetryDrawing[]): Promise<void> {
|
|
154
|
+
this.#drawings = mergeDrawings(this.#drawings, drawings);
|
|
155
|
+
return this.#redrawElements();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Stop drawing these elements, leaving the rest alone.
|
|
160
|
+
* @param ids - The ids to remove; an id that is not drawn is ignored.
|
|
161
|
+
* @returns Resolves once the rest are redrawn.
|
|
162
|
+
*/
|
|
163
|
+
removeElements(ids: readonly string[]): Promise<void> {
|
|
164
|
+
this.#drawings = withoutDrawings(this.#drawings, ids);
|
|
165
|
+
return this.#redrawElements();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Remove every symmetry element.
|
|
170
|
+
* @returns Resolves once they are gone.
|
|
171
|
+
*/
|
|
172
|
+
hideElements(): Promise<void> {
|
|
173
|
+
this.#drawings = [];
|
|
174
|
+
return this.#redrawElements();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Apply an operation to the structure, once, and leave it where it lands.
|
|
179
|
+
*
|
|
180
|
+
* The elements stay where they are: an axis that turned with the molecule
|
|
181
|
+
* would prove nothing.
|
|
182
|
+
* @param operation - What to apply.
|
|
183
|
+
* @param options - See {@link PlayOptions}.
|
|
184
|
+
* @returns Resolves once the operation has been applied in full.
|
|
185
|
+
*/
|
|
186
|
+
playOperation(
|
|
187
|
+
operation: ViewerOperation,
|
|
188
|
+
options?: PlayOptions,
|
|
189
|
+
): Promise<void> {
|
|
190
|
+
return this.run((plugin) => playOperation(plugin, operation, options));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Hold the structure part-way through an operation, for a slider.
|
|
195
|
+
* @param operation - What is being applied.
|
|
196
|
+
* @param fraction - How far through, 0 to 1.
|
|
197
|
+
* @returns Resolves once the structure is held there.
|
|
198
|
+
*/
|
|
199
|
+
setOperationFraction(
|
|
200
|
+
operation: ViewerOperation,
|
|
201
|
+
fraction: number,
|
|
202
|
+
): Promise<void> {
|
|
203
|
+
return this.run((plugin) => {
|
|
204
|
+
setOperationFraction(plugin, operation, fraction);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Put the structure back where it started.
|
|
210
|
+
* @returns Resolves once the structure is back.
|
|
211
|
+
*/
|
|
212
|
+
resetOperation(): Promise<void> {
|
|
213
|
+
return this.run((plugin) => {
|
|
214
|
+
resetOperation(plugin);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
#redrawElements(): Promise<void> {
|
|
219
|
+
const drawings = this.#drawings;
|
|
220
|
+
const style = this.#elementStyle;
|
|
221
|
+
return this.run((plugin) => drawElements(plugin, drawings, style));
|
|
222
|
+
}
|
|
223
|
+
}
|
package/src/crystal3d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crystals in 3D: the atoms of a cell, the box around it, the symmetry
|
|
3
|
+
* elements over it and an operation applied to it, drawn by molstar.
|
|
4
|
+
*
|
|
5
|
+
* An entry point of its own because molstar is several megabytes: the canvas
|
|
6
|
+
* sits behind `React.lazy`, so importing this costs a page the drawing
|
|
7
|
+
* geometry and the components, never the viewer. The geometry needs neither
|
|
8
|
+
* React nor molstar and is exported beside the components.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export * from './crystal3d/core/index.ts';
|
|
12
|
+
export * from './crystal3d/ui/index.ts';
|
|
@@ -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
|
@@ -1085,5 +1085,30 @@
|
|
|
1085
1085
|
"send.label": "Senden an",
|
|
1086
1086
|
"send.heading": "{what} senden an",
|
|
1087
1087
|
"send.none": "Von dieser Seite lässt sich noch nichts an ein anderes Werkzeug senden.",
|
|
1088
|
-
"send.blocked": "Der Browser hat den neuen Tab blockiert: Pop-ups für diese Seite erlauben, dann erneut senden."
|
|
1088
|
+
"send.blocked": "Der Browser hat den neuen Tab blockiert: Pop-ups für diese Seite erlauben, dann erneut senden.",
|
|
1089
|
+
"crystal3d.draw": "Zeichnen",
|
|
1090
|
+
"crystal3d.cells": "Zellen",
|
|
1091
|
+
"crystal3d.packing.molecules": "Ganze Moleküle",
|
|
1092
|
+
"crystal3d.packing.moleculesHelp": "Jedes Molekül ganz, in der Zelle, in die sein Zentrum fällt.",
|
|
1093
|
+
"crystal3d.packing.cell": "Atome der Zelle",
|
|
1094
|
+
"crystal3d.packing.cellHelp": "Jedes Atom innerhalb der Zelle, dort geschnitten, wo ihre Wände es schneiden.",
|
|
1095
|
+
"crystal3d.unitCell": "Elementarzelle",
|
|
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.",
|
|
1104
|
+
"crystal3d.caption.molecules.one": "1 Molekül pro Zelle",
|
|
1105
|
+
"crystal3d.caption.molecules.other": "{count} Moleküle pro Zelle",
|
|
1106
|
+
"crystal3d.caption.atoms.one": "1 Atom pro Zelle",
|
|
1107
|
+
"crystal3d.caption.atoms.other": "{count} Atome pro Zelle",
|
|
1108
|
+
"crystal3d.caption.cells.one": "1×1×1 Zelle",
|
|
1109
|
+
"crystal3d.caption.cells.other": "{count}×{count}×{count} Zellen",
|
|
1110
|
+
"crystal3d.caption.cellsCapped": "{count}×{count}×{count} Zellen, da {asked}×{asked}×{asked} zu viele Atome enthielten",
|
|
1111
|
+
"crystal3d.unreadable": "Diese Datei konnte nicht gelesen werden",
|
|
1112
|
+
"crystal3d.tooLarge": "Diese Zelle enthält {count} Atome, mehr als der Betrachter zeichnet.",
|
|
1113
|
+
"crystal3d.unsupported": "Kein 3D auf diesem Rechner"
|
|
1089
1114
|
}
|
package/src/locales/en.json
CHANGED
|
@@ -1085,5 +1085,30 @@
|
|
|
1085
1085
|
"send.label": "Send to",
|
|
1086
1086
|
"send.heading": "Send {what} to",
|
|
1087
1087
|
"send.none": "Nothing on this page can be sent to another tool yet.",
|
|
1088
|
-
"send.blocked": "The browser blocked the new tab: allow pop-ups for this site, then send again."
|
|
1088
|
+
"send.blocked": "The browser blocked the new tab: allow pop-ups for this site, then send again.",
|
|
1089
|
+
"crystal3d.draw": "Draw",
|
|
1090
|
+
"crystal3d.cells": "Cells",
|
|
1091
|
+
"crystal3d.packing.molecules": "Whole molecules",
|
|
1092
|
+
"crystal3d.packing.moleculesHelp": "Each molecule whole, in the cell its centre falls in.",
|
|
1093
|
+
"crystal3d.packing.cell": "Atoms in the cell",
|
|
1094
|
+
"crystal3d.packing.cellHelp": "Every atom inside the cell, cut where its walls cut it.",
|
|
1095
|
+
"crystal3d.unitCell": "Unit cell",
|
|
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.",
|
|
1104
|
+
"crystal3d.caption.molecules.one": "1 molecule per cell",
|
|
1105
|
+
"crystal3d.caption.molecules.other": "{count} molecules per cell",
|
|
1106
|
+
"crystal3d.caption.atoms.one": "1 atom per cell",
|
|
1107
|
+
"crystal3d.caption.atoms.other": "{count} atoms per cell",
|
|
1108
|
+
"crystal3d.caption.cells.one": "1×1×1 cell",
|
|
1109
|
+
"crystal3d.caption.cells.other": "{count}×{count}×{count} cells",
|
|
1110
|
+
"crystal3d.caption.cellsCapped": "{count}×{count}×{count} cells, as {asked}×{asked}×{asked} would hold too many atoms",
|
|
1111
|
+
"crystal3d.unreadable": "That file could not be read",
|
|
1112
|
+
"crystal3d.tooLarge": "This cell holds {count} atoms, more than the viewer draws.",
|
|
1113
|
+
"crystal3d.unsupported": "No 3D on this machine"
|
|
1089
1114
|
}
|
package/src/locales/es.json
CHANGED
|
@@ -1085,5 +1085,30 @@
|
|
|
1085
1085
|
"send.label": "Enviar a",
|
|
1086
1086
|
"send.heading": "Enviar {what} a",
|
|
1087
1087
|
"send.none": "Nada de esta página puede enviarse todavía a otra herramienta.",
|
|
1088
|
-
"send.blocked": "El navegador bloqueó la nueva pestaña: permita las ventanas emergentes para este sitio y vuelva a enviar."
|
|
1088
|
+
"send.blocked": "El navegador bloqueó la nueva pestaña: permita las ventanas emergentes para este sitio y vuelva a enviar.",
|
|
1089
|
+
"crystal3d.draw": "Dibujar",
|
|
1090
|
+
"crystal3d.cells": "Celdas",
|
|
1091
|
+
"crystal3d.packing.molecules": "Moléculas enteras",
|
|
1092
|
+
"crystal3d.packing.moleculesHelp": "Cada molécula entera, en la celda donde cae su centro.",
|
|
1093
|
+
"crystal3d.packing.cell": "Átomos de la celda",
|
|
1094
|
+
"crystal3d.packing.cellHelp": "Cada átomo dentro de la celda, cortado donde lo cortan sus caras.",
|
|
1095
|
+
"crystal3d.unitCell": "Celda unidad",
|
|
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.",
|
|
1104
|
+
"crystal3d.caption.molecules.one": "1 molécula por celda",
|
|
1105
|
+
"crystal3d.caption.molecules.other": "{count} moléculas por celda",
|
|
1106
|
+
"crystal3d.caption.atoms.one": "1 átomo por celda",
|
|
1107
|
+
"crystal3d.caption.atoms.other": "{count} átomos por celda",
|
|
1108
|
+
"crystal3d.caption.cells.one": "1×1×1 celda",
|
|
1109
|
+
"crystal3d.caption.cells.other": "{count}×{count}×{count} celdas",
|
|
1110
|
+
"crystal3d.caption.cellsCapped": "{count}×{count}×{count} celdas, ya que {asked}×{asked}×{asked} contendrían demasiados átomos",
|
|
1111
|
+
"crystal3d.unreadable": "Ese archivo no se ha podido leer",
|
|
1112
|
+
"crystal3d.tooLarge": "Esta celda contiene {count} átomos, más de los que dibuja el visor.",
|
|
1113
|
+
"crystal3d.unsupported": "Sin 3D en este equipo"
|
|
1089
1114
|
}
|