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,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framing the scene.
|
|
3
|
+
*
|
|
4
|
+
* What is on screen is measured here rather than read off molstar, for the
|
|
5
|
+
* reason `framing.ts` gives: a representation's own bounding sphere is padded by
|
|
6
|
+
* the largest ball it could ever draw. Each part of the scene registers its
|
|
7
|
+
* extent as it is drawn, and the camera frames the union — the framing itself,
|
|
8
|
+
* and the union, are `react-cheminfo`'s.
|
|
9
|
+
*/
|
|
10
|
+
import { Sphere3D } from 'molstar/lib/mol-math/geometry.js';
|
|
11
|
+
import { Vec3 } from 'molstar/lib/mol-math/linear-algebra.js';
|
|
12
|
+
import { DEFAULT_CAMERA_DURATION, cameraToPose, framedRadius, poseToCamera, resetCamera as frameScene, unionSphere, } from "../../molstar/core/index.js";
|
|
13
|
+
/**
|
|
14
|
+
* The scene is measured as the ball through its furthest corners, and a camera
|
|
15
|
+
* fitting that ball to the window leaves a cell filling barely half of it: a
|
|
16
|
+
* cube touches its own circumscribed sphere only at eight corners, and uses
|
|
17
|
+
* about 82% of its diameter even seen square-on. So the ball handed to the
|
|
18
|
+
* camera is **smaller** than the one measured, by about the slack that costs.
|
|
19
|
+
* Nothing is cut at the orientations a cell is read at, and the reader can
|
|
20
|
+
* always pull back.
|
|
21
|
+
*/
|
|
22
|
+
const SCENE_MARGIN = -0.12;
|
|
23
|
+
/**
|
|
24
|
+
* Record how far one part of the scene reaches.
|
|
25
|
+
* @param plugin - The molstar context.
|
|
26
|
+
* @param key - Which part: the atoms, the cell, the elements.
|
|
27
|
+
* @param sphere - Its extent, or `null` once it is no longer drawn.
|
|
28
|
+
*/
|
|
29
|
+
export function setSceneExtent(plugin, key, sphere) {
|
|
30
|
+
let parts = extents.get(plugin);
|
|
31
|
+
if (parts === undefined) {
|
|
32
|
+
parts = new Map();
|
|
33
|
+
extents.set(plugin, parts);
|
|
34
|
+
}
|
|
35
|
+
if (sphere === null) {
|
|
36
|
+
parts.delete(key);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const [x, y, z] = sphere.centre;
|
|
40
|
+
parts.set(key, Sphere3D.create(Vec3.create(x, y, z), sphere.radius));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Frame everything on screen.
|
|
44
|
+
* @param plugin - The molstar context.
|
|
45
|
+
* @param durationMs - Transition length; 0 jumps.
|
|
46
|
+
* @param orientation - Where to look from, from `sceneOrientation`. Left out,
|
|
47
|
+
* the camera keeps the direction it is already pointing, which is what a
|
|
48
|
+
* reframe after a reader has turned the scene should do.
|
|
49
|
+
*/
|
|
50
|
+
export function resetCamera(plugin, durationMs = DEFAULT_CAMERA_DURATION, orientation) {
|
|
51
|
+
frameScene(plugin, {
|
|
52
|
+
spheres: [...(extents.get(plugin)?.values() ?? [])],
|
|
53
|
+
margin: SCENE_MARGIN,
|
|
54
|
+
durationMs,
|
|
55
|
+
orientation,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Where the camera stands, measured against what is drawn rather than in
|
|
60
|
+
* ångström, so a figure opens on the same view in a frame of another size.
|
|
61
|
+
* @param plugin - The molstar context.
|
|
62
|
+
* @returns The camera, or `null` while nothing is drawn to measure it against.
|
|
63
|
+
*/
|
|
64
|
+
export function readCamera(plugin) {
|
|
65
|
+
const canvas = plugin.canvas3d;
|
|
66
|
+
const reference = sceneReference(plugin);
|
|
67
|
+
if (canvas === undefined || reference === null)
|
|
68
|
+
return null;
|
|
69
|
+
return poseToCamera(canvas.camera.getSnapshot(), reference, canvas.camera.getTargetDistance(reference.radius));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Put the camera where {@link readCamera} found it, against what is drawn now.
|
|
73
|
+
* @param plugin - The molstar context.
|
|
74
|
+
* @param camera - Where to stand.
|
|
75
|
+
*/
|
|
76
|
+
export function applyCamera(plugin, camera) {
|
|
77
|
+
const canvas = plugin.canvas3d;
|
|
78
|
+
if (canvas === undefined)
|
|
79
|
+
return;
|
|
80
|
+
// Resolves a reframe molstar has queued, which would otherwise land after
|
|
81
|
+
// this move and undo it.
|
|
82
|
+
canvas.commit(true);
|
|
83
|
+
const reference = sceneReference(plugin);
|
|
84
|
+
if (reference === null)
|
|
85
|
+
return;
|
|
86
|
+
const pose = cameraToPose(camera, reference, canvas.camera.getTargetDistance(reference.radius));
|
|
87
|
+
canvas.camera.setState({ ...pose, radius: reference.radius }, 0);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The sphere a camera is measured against: every part drawn, framed.
|
|
91
|
+
* @param plugin - The molstar context whose scene is measured.
|
|
92
|
+
* @returns The centre and framed radius, or `null` while nothing is drawn.
|
|
93
|
+
*/
|
|
94
|
+
function sceneReference(plugin) {
|
|
95
|
+
const union = unionSphere([...(extents.get(plugin)?.values() ?? [])]);
|
|
96
|
+
if (union === null || !(union.radius > 0))
|
|
97
|
+
return null;
|
|
98
|
+
return { center: union.center, radius: framedRadius(union.radius) };
|
|
99
|
+
}
|
|
100
|
+
/** What each part of the scene reaches, per plugin. */
|
|
101
|
+
const extents = new WeakMap();
|
|
102
|
+
export { DEFAULT_CAMERA_DURATION } from "../../molstar/core/index.js";
|
|
103
|
+
//# sourceMappingURL=camera.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera.js","sourceRoot":"","sources":["../../../src/crystal3d/viewer/camera.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,wCAAwC,CAAC;AAK9D,OAAO,EACL,uBAAuB,EACvB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,IAAI,UAAU,EACzB,WAAW,GACZ,MAAM,6BAA6B,CAAC;AAIrC;;;;;;;;GAQG;AACH,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC;AAE3B;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAqB,EACrB,GAAW,EACX,MAA0B;IAE1B,IAAI,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAChC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClB,OAAO;IACT,CAAC;IACD,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,M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K,IAAI;QAAE,OAAO;IAC/B,MAAM,IAAI,GAAG,YAAY,CACvB,MAAM,EACN,SAAS,EACT,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,CAClD,CAAC;IACF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;AACnE,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,MAAqB;IAC3C,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACtE,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACvD,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;AACtE,CAAC;AAED,uDAAuD;AACvD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAwC,CAAC;AAEpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The molstar half of the crystal viewer: the canvas, and everything drawn on
|
|
3
|
+
* it. Reaching it pulls molstar in, so only the lazy canvas imports it.
|
|
4
|
+
*/
|
|
5
|
+
export type { PlayOptions } from './animate.ts';
|
|
6
|
+
export { DEFAULT_CAMERA_DURATION } from './camera.ts';
|
|
7
|
+
export type { CrystalViewerOptions } from './plugin.ts';
|
|
8
|
+
export { CrystalViewerPlugin } from './plugin.ts';
|
|
9
|
+
export type { CellStyle } from './renderCell.ts';
|
|
10
|
+
export type { ElementLayerStyle } from './renderElements.ts';
|
|
11
|
+
export type { StructureStyle } from './renderStructure.ts';
|
|
12
|
+
export { CrystalViewer, createCrystalViewer } from './viewer.ts';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crystal3d/viewer/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The molstar half of the crystal viewer: the canvas, and everything drawn on
|
|
3
|
+
* it. Reaching it pulls molstar in, so only the lazy canvas imports it.
|
|
4
|
+
*/
|
|
5
|
+
export { DEFAULT_CAMERA_DURATION } from "./camera.js";
|
|
6
|
+
export { CrystalViewerPlugin } from "./plugin.js";
|
|
7
|
+
export { CrystalViewer, createCrystalViewer } from "./viewer.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/crystal3d/viewer/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAIlD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which drawn layers a canvas is carrying.
|
|
3
|
+
*
|
|
4
|
+
* A layer lives outside the state tree, keyed by name on the plugin, the way
|
|
5
|
+
* `lcao`'s lobes and nodal surfaces do: it is rebuilt whole on every toggle, and
|
|
6
|
+
* the state tree has nothing to add to that. Keeping the register here lets the
|
|
7
|
+
* mesh layers and the text layers share one place to be removed from.
|
|
8
|
+
*/
|
|
9
|
+
import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
10
|
+
import type { Representation } from 'molstar/lib/mol-repr/representation.js';
|
|
11
|
+
/**
|
|
12
|
+
* Remember a layer, so a later call can take it off again.
|
|
13
|
+
* @param plugin - The molstar context.
|
|
14
|
+
* @param key - Which layer.
|
|
15
|
+
* @param representation - What was added to the canvas.
|
|
16
|
+
*/
|
|
17
|
+
export declare function storeLayer(plugin: PluginContext, key: string, representation: Representation.Any): void;
|
|
18
|
+
/**
|
|
19
|
+
* Remove one layer, leaving every other in place.
|
|
20
|
+
* @param plugin - The molstar context.
|
|
21
|
+
* @param key - Which layer; an unknown one is ignored.
|
|
22
|
+
*/
|
|
23
|
+
export declare function clearShapeLayer(plugin: PluginContext, key: string): void;
|
|
24
|
+
//# sourceMappingURL=layerRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layerRegistry.d.ts","sourceRoot":"","sources":["../../../src/crystal3d/viewer/layerRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAE7E;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,cAAc,CAAC,GAAG,GACjC,IAAI,CAON;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAOxE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which drawn layers a canvas is carrying.
|
|
3
|
+
*
|
|
4
|
+
* A layer lives outside the state tree, keyed by name on the plugin, the way
|
|
5
|
+
* `lcao`'s lobes and nodal surfaces do: it is rebuilt whole on every toggle, and
|
|
6
|
+
* the state tree has nothing to add to that. Keeping the register here lets the
|
|
7
|
+
* mesh layers and the text layers share one place to be removed from.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Remember a layer, so a later call can take it off again.
|
|
11
|
+
* @param plugin - The molstar context.
|
|
12
|
+
* @param key - Which layer.
|
|
13
|
+
* @param representation - What was added to the canvas.
|
|
14
|
+
*/
|
|
15
|
+
export function storeLayer(plugin, key, representation) {
|
|
16
|
+
let layers = registry.get(plugin);
|
|
17
|
+
if (layers === undefined) {
|
|
18
|
+
layers = new Map();
|
|
19
|
+
registry.set(plugin, layers);
|
|
20
|
+
}
|
|
21
|
+
layers.set(key, representation);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Remove one layer, leaving every other in place.
|
|
25
|
+
* @param plugin - The molstar context.
|
|
26
|
+
* @param key - Which layer; an unknown one is ignored.
|
|
27
|
+
*/
|
|
28
|
+
export function clearShapeLayer(plugin, key) {
|
|
29
|
+
const layers = registry.get(plugin);
|
|
30
|
+
const previous = layers?.get(key);
|
|
31
|
+
if (layers === undefined || previous === undefined)
|
|
32
|
+
return;
|
|
33
|
+
layers.delete(key);
|
|
34
|
+
plugin.canvas3d?.remove(previous);
|
|
35
|
+
plugin.canvas3d?.commit();
|
|
36
|
+
}
|
|
37
|
+
/** Every layer drawn on a plugin, so each can be removed on its own. */
|
|
38
|
+
const registry = new WeakMap();
|
|
39
|
+
//# sourceMappingURL=layerRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layerRegistry.js","sourceRoot":"","sources":["../../../src/crystal3d/viewer/layerRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CACxB,MAAqB,EACrB,GAAW,EACX,cAAkC;IAElC,IAAI,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAClC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,GAAG,IAAI,GAAG,EAA8B,CAAC;QAC/C,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC;IACD,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAqB,EAAE,GAAW;IAChE,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,MAAM,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO;IAC3D,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACnB,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC5B,CAAC;AAED,wEAAwE;AACxE,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAkD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place a shape worked out in `primitives.ts` becomes molstar geometry.
|
|
3
|
+
*/
|
|
4
|
+
import { MeshBuilder } from 'molstar/lib/mol-geo/geometry/mesh/mesh-builder.js';
|
|
5
|
+
import type { MeshPrimitive } from '../core/primitives.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Add one shape to a mesh under construction.
|
|
8
|
+
* @param state - The builder; its `currentGroup` decides which item the
|
|
9
|
+
* triangles belong to, and so what colour and label they take.
|
|
10
|
+
* @param primitive - The shape.
|
|
11
|
+
*/
|
|
12
|
+
export declare function addMeshPrimitive(state: MeshBuilder.State, primitive: MeshPrimitive): void;
|
|
13
|
+
//# sourceMappingURL=meshPrimitives.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meshPrimitives.d.ts","sourceRoot":"","sources":["../../../src/crystal3d/viewer/meshPrimitives.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAC;AAGhF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,WAAW,CAAC,KAAK,EACxB,SAAS,EAAE,aAAa,GACvB,IAAI,CAoEN"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place a shape worked out in `primitives.ts` becomes molstar geometry.
|
|
3
|
+
*/
|
|
4
|
+
import { addFixedCountDashedCylinder, addSimpleCylinder, } from 'molstar/lib/mol-geo/geometry/mesh/builder/cylinder.js';
|
|
5
|
+
import { addPlane } from 'molstar/lib/mol-geo/geometry/mesh/builder/plane.js';
|
|
6
|
+
import { addSphere } from 'molstar/lib/mol-geo/geometry/mesh/builder/sphere.js';
|
|
7
|
+
import { MeshBuilder } from 'molstar/lib/mol-geo/geometry/mesh/mesh-builder.js';
|
|
8
|
+
import { Vec3 } from 'molstar/lib/mol-math/linear-algebra.js';
|
|
9
|
+
/**
|
|
10
|
+
* Add one shape to a mesh under construction.
|
|
11
|
+
* @param state - The builder; its `currentGroup` decides which item the
|
|
12
|
+
* triangles belong to, and so what colour and label they take.
|
|
13
|
+
* @param primitive - The shape.
|
|
14
|
+
*/
|
|
15
|
+
export function addMeshPrimitive(state, primitive) {
|
|
16
|
+
switch (primitive.shape) {
|
|
17
|
+
case 'rod': {
|
|
18
|
+
addSimpleCylinder(state, vec(primitive.start), vec(primitive.end), {
|
|
19
|
+
radiusTop: primitive.radius,
|
|
20
|
+
radiusBottom: primitive.radius,
|
|
21
|
+
radialSegments: ROD_SEGMENTS,
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
case 'dashes': {
|
|
26
|
+
addFixedCountDashedCylinder(state, vec(primitive.start), vec(primitive.end), 1, primitive.segments, true, {
|
|
27
|
+
radiusTop: primitive.radius,
|
|
28
|
+
radiusBottom: primitive.radius,
|
|
29
|
+
radialSegments: ROD_SEGMENTS,
|
|
30
|
+
});
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
case 'cone': {
|
|
34
|
+
addSimpleCylinder(state, vec(primitive.base), vec(primitive.tip), {
|
|
35
|
+
radiusTop: 0,
|
|
36
|
+
radiusBottom: primitive.radius,
|
|
37
|
+
radialSegments: CONE_SEGMENTS,
|
|
38
|
+
bottomCap: true,
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
case 'sphere': {
|
|
43
|
+
addSphere(state, vec(primitive.centre), primitive.radius, SPHERE_DETAIL);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
case 'face': {
|
|
47
|
+
// A fan from the first corner; the corners come round the plane in
|
|
48
|
+
// order, so the face is convex and the fan covers it exactly.
|
|
49
|
+
const { points } = primitive;
|
|
50
|
+
const first = points[0];
|
|
51
|
+
if (first === undefined)
|
|
52
|
+
return;
|
|
53
|
+
for (let index = 1; index + 1 < points.length; index++) {
|
|
54
|
+
const second = points[index];
|
|
55
|
+
const third = points[index + 1];
|
|
56
|
+
if (second === undefined || third === undefined)
|
|
57
|
+
continue;
|
|
58
|
+
MeshBuilder.addTriangle(state, vec(first), vec(second), vec(third));
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
case 'plate': {
|
|
63
|
+
// The unit plane is ±0.5, so the scale is the side of the square; the
|
|
64
|
+
// third component is the (zero-thickness) normal direction.
|
|
65
|
+
addPlane(state, vec(primitive.centre), vec(primitive.major), vec(primitive.minor), Vec3.create(primitive.size, primitive.size, 1), 1, 1);
|
|
66
|
+
}
|
|
67
|
+
// no default
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function vec(point) {
|
|
71
|
+
return Vec3.create(point[0], point[1], point[2]);
|
|
72
|
+
}
|
|
73
|
+
const ROD_SEGMENTS = 12;
|
|
74
|
+
const CONE_SEGMENTS = 16;
|
|
75
|
+
const SPHERE_DETAIL = 2;
|
|
76
|
+
//# sourceMappingURL=meshPrimitives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meshPrimitives.js","sourceRoot":"","sources":["../../../src/crystal3d/viewer/meshPrimitives.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,2BAA2B,EAC3B,iBAAiB,GAClB,MAAM,uDAAuD,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,oDAAoD,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,qDAAqD,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,MAAM,wCAAwC,CAAC;AAK9D;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAwB,EACxB,SAAwB;IAExB,QAAQ,SAAS,CAAC,KAAK,EAAE,CAAC;QACxB,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;gBACjE,SAAS,EAAE,SAAS,CAAC,MAAM;gBAC3B,YAAY,EAAE,SAAS,CAAC,MAAM;gBA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,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;gBAChC,IAAI,MAAM,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS;oBAAE,SAAS;gBAC1D,WAAW,CAAC,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YACtE,CAAC;YACD,OAAO;QACT,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,sEAAsE;YACtE,4DAA4D;YAC5D,QAAQ,CACN,KAAK,EACL,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,EACrB,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,EACpB,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,EACpB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,EAC9C,CAAC,EACD,CAAC,CACF,CAAC;QACJ,CAAC;QACD,aAAa;IACf,CAAC;AACH,CAAC;AAED,SAAS,GAAG,CAAC,KAAa;IACxB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,aAAa,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lifecycle of one molstar canvas: created now, disposed whenever, every call
|
|
3
|
+
* queued behind initialisation.
|
|
4
|
+
*
|
|
5
|
+
* The constructor is **synchronous** on purpose. React 19 runs an effect, its
|
|
6
|
+
* cleanup and the effect again on every mount in development, so an `await`ed
|
|
7
|
+
* constructor hands the cleanup nothing to dispose and leaks a WebGL context per
|
|
8
|
+
* mount — browsers drop the oldest after about sixteen, and the viewer silently
|
|
9
|
+
* goes blank. Returning the handle immediately means `dispose()` can always be
|
|
10
|
+
* called, even before initialisation has finished.
|
|
11
|
+
*
|
|
12
|
+
* molstar's own UI is never mounted: every control is the page's.
|
|
13
|
+
*/
|
|
14
|
+
import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
15
|
+
import type { Molecule3DCamera } from '../../molecule3d/core/camera.ts';
|
|
16
|
+
import type { ImageSize } from '../../molecule3d/core/exportImage.ts';
|
|
17
|
+
import type { RenderedFigure } from '../../molecule3d/core/figureFrame.ts';
|
|
18
|
+
import type { Measurement, MeasurementKind } from '../../molecule3d/core/measurement.ts';
|
|
19
|
+
import type { SceneCapture } from '../../molecule3d/ui/exportMoleculeImage.ts';
|
|
20
|
+
import type { ViewOrientation } from '../core/orientation.ts';
|
|
21
|
+
import type { Point3 } from '../core/types.ts';
|
|
22
|
+
/** Settings fixed for the life of a viewer. */
|
|
23
|
+
export interface CrystalViewerOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Scene background, as `#rrggbb`.
|
|
26
|
+
* @default '#ffffff'
|
|
27
|
+
*/
|
|
28
|
+
background?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Called with each measurement once its atoms are picked; measuring is off
|
|
31
|
+
* without it.
|
|
32
|
+
* @default undefined
|
|
33
|
+
*/
|
|
34
|
+
onMeasure?: (measurement: Measurement) => void;
|
|
35
|
+
}
|
|
36
|
+
/** One molstar canvas, and the queue everything drawn on it goes through. */
|
|
37
|
+
export declare class CrystalViewerPlugin implements SceneCapture {
|
|
38
|
+
#private;
|
|
39
|
+
/** Resolves once the canvas exists; every call awaits it internally. */
|
|
40
|
+
readonly ready: Promise<void>;
|
|
41
|
+
constructor(container: HTMLElement, options?: CrystalViewerOptions);
|
|
42
|
+
/**
|
|
43
|
+
* Whether {@link dispose} has been called.
|
|
44
|
+
* @returns True once the viewer is disposed.
|
|
45
|
+
*/
|
|
46
|
+
get disposed(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Wait for initialisation, then run `action` on the plugin.
|
|
49
|
+
* @param action - What to do with the molstar context.
|
|
50
|
+
* @returns Nothing once the viewer has been disposed — before the call or
|
|
51
|
+
* while `action` was still running. An initialisation failure, and any
|
|
52
|
+
* error `action` throws while the viewer is alive, still reach the caller.
|
|
53
|
+
*/
|
|
54
|
+
run(action: (plugin: PluginContext) => void | Promise<void>): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Frame everything on screen.
|
|
57
|
+
* @param durationMs - Transition length; 0 jumps.
|
|
58
|
+
* @param orientation - Where to look from, from `sceneOrientation`. Left out,
|
|
59
|
+
* the camera keeps the direction it is already pointing.
|
|
60
|
+
* @returns Resolves once the camera has been told where to go.
|
|
61
|
+
*/
|
|
62
|
+
resetCamera(durationMs?: number, orientation?: ViewOrientation): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Where the camera stands, against what is drawn.
|
|
65
|
+
* @returns The camera, or `null` while nothing is drawn.
|
|
66
|
+
*/
|
|
67
|
+
readCamera(): Promise<Molecule3DCamera | null>;
|
|
68
|
+
/**
|
|
69
|
+
* Put the camera back where {@link readCamera} found it.
|
|
70
|
+
* @param camera - Where to stand.
|
|
71
|
+
* @returns Resolves once the camera stands there.
|
|
72
|
+
*/
|
|
73
|
+
applyCamera(camera: Molecule3DCamera): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Render the scene off screen at a size of its own, for a picture to save.
|
|
76
|
+
* @param size - Pixel size of the picture.
|
|
77
|
+
* @returns The PNG as a data URI; `undefined` once the viewer is disposed.
|
|
78
|
+
*/
|
|
79
|
+
captureImage(size: ImageSize): Promise<string | undefined>;
|
|
80
|
+
/**
|
|
81
|
+
* Render the part of the scene holding the crystal, for a figure handed on.
|
|
82
|
+
* @param size - Pixel size of the frame the crystal is cut from.
|
|
83
|
+
* @param longest - Longest side of the figure, in pixels.
|
|
84
|
+
* @returns The figure; `undefined` once the viewer is disposed.
|
|
85
|
+
*/
|
|
86
|
+
captureFigure(size: ImageSize, longest: number): Promise<RenderedFigure | undefined>;
|
|
87
|
+
/**
|
|
88
|
+
* Zoom onto one point of the scene.
|
|
89
|
+
* @param centre - What to frame, Cartesian ångström.
|
|
90
|
+
* @param radius - Radius of the ball to fit, ångström.
|
|
91
|
+
* @param durationMs - Transition length; 0 jumps.
|
|
92
|
+
* @param orientation - Where to look from; the current direction when absent.
|
|
93
|
+
* @returns Resolves once the camera has been told where to go.
|
|
94
|
+
*/
|
|
95
|
+
focus(centre: Point3, radius: number, durationMs?: number, orientation?: ViewOrientation): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Turn the automatic spin on or off. It moves the camera, never the object:
|
|
98
|
+
* showing that a molecule maps onto itself is a different button.
|
|
99
|
+
* @param spinning - Whether the scene should keep turning.
|
|
100
|
+
* @param speed - molstar's own spin unit.
|
|
101
|
+
* @returns Resolves once the spin is set.
|
|
102
|
+
*/
|
|
103
|
+
setSpin(spinning: boolean, speed?: number): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Report what the pointer rests on, by the label its drawing carries. Every
|
|
106
|
+
* axis, plane and centre is drawn with a label already — `C3 along [111]`,
|
|
107
|
+
* `n glide at x = ¼` — and an atom is named `O 1`, never by the row molstar
|
|
108
|
+
* parsed it from.
|
|
109
|
+
* @param listener - Called with the label, or `null` over nothing.
|
|
110
|
+
* @returns A function that stops the reporting; safe to call at any time.
|
|
111
|
+
*/
|
|
112
|
+
onHover(listener: (label: string | null) => void): () => void;
|
|
113
|
+
/**
|
|
114
|
+
* Make clicks on atoms build a measurement, or give them back to the camera.
|
|
115
|
+
* @param kind - The measurement to build, or `null`.
|
|
116
|
+
* @returns Resolves once clicks build that measurement.
|
|
117
|
+
*/
|
|
118
|
+
setMeasureKind(kind: MeasurementKind | null): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Draw exactly these measurements over the atoms on screen.
|
|
121
|
+
* @param measurements - Replaces whatever is drawn; empty clears them.
|
|
122
|
+
* @returns Resolves once they are drawn.
|
|
123
|
+
*/
|
|
124
|
+
showMeasurements(measurements: readonly Measurement[]): Promise<void>;
|
|
125
|
+
/** Re-read the container's size. Call from a `ResizeObserver`. */
|
|
126
|
+
handleResize(): void;
|
|
127
|
+
/**
|
|
128
|
+
* Tear the canvas down and release its WebGL context. Idempotent, and safe to
|
|
129
|
+
* call before initialisation has finished.
|
|
130
|
+
*/
|
|
131
|
+
dispose(): void;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/crystal3d/viewer/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAEvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EAChB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAY/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAU/C,+CAA+C;AAC/C,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAC;CAChD;AAED,6EAA6E;AAC7E,qBAAa,mBAAoB,YAAW,YAAY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G,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3D;;;;OAIG;IACH,gBAAgB,CAAC,YAAY,EAAE,SAAS,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrE,kEAAkE;IAClE,YAAY,IAAI,IAAI;IAIpB;;;OAGG;IACH,OAAO,IAAI,IAAI;CAIhB"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lifecycle of one molstar canvas: created now, disposed whenever, every call
|
|
3
|
+
* queued behind initialisation.
|
|
4
|
+
*
|
|
5
|
+
* The constructor is **synchronous** on purpose. React 19 runs an effect, its
|
|
6
|
+
* cleanup and the effect again on every mount in development, so an `await`ed
|
|
7
|
+
* constructor hands the cleanup nothing to dispose and leaks a WebGL context per
|
|
8
|
+
* mount — browsers drop the oldest after about sixteen, and the viewer silently
|
|
9
|
+
* goes blank. Returning the handle immediately means `dispose()` can always be
|
|
10
|
+
* called, even before initialisation has finished.
|
|
11
|
+
*
|
|
12
|
+
* molstar's own UI is never mounted: every control is the page's.
|
|
13
|
+
*/
|
|
14
|
+
import { MeasurementPicker, MolstarPlugin, captureFigure, captureScene, clearMeasurements, focusPoint, renderMeasurements, setSpin, subscribeHoverLabel, } from "../../molstar/core/index.js";
|
|
15
|
+
import { DEFAULT_CAMERA_DURATION, applyCamera, readCamera, resetCamera, } from "./camera.js";
|
|
16
|
+
import { crystalStructure } from "./renderStructure.js";
|
|
17
|
+
/** One molstar canvas, and the queue everything drawn on it goes through. */
|
|
18
|
+
export class CrystalViewerPlugin {
|
|
19
|
+
#plugin;
|
|
20
|
+
#picker;
|
|
21
|
+
/** Resolves once the canvas exists; every call awaits it internally. */
|
|
22
|
+
ready;
|
|
23
|
+
constructor(container, options = {}) {
|
|
24
|
+
this.#plugin = new MolstarPlugin(container, {
|
|
25
|
+
background: options.background,
|
|
26
|
+
// Replacing a scene commits several times, and molstar's own default
|
|
27
|
+
// glides the camera on each, so the structure appears to drift into
|
|
28
|
+
// place. Reframing is right; animating it between two unrelated
|
|
29
|
+
// structures is not.
|
|
30
|
+
cameraResetDurationMilliseconds: 0,
|
|
31
|
+
});
|
|
32
|
+
this.ready = this.#plugin.ready;
|
|
33
|
+
const { onMeasure } = options;
|
|
34
|
+
if (onMeasure !== undefined) {
|
|
35
|
+
// A failed initialisation is reported by the next call the page makes.
|
|
36
|
+
void this.#plugin
|
|
37
|
+
.run((plugin) => {
|
|
38
|
+
this.#picker = new MeasurementPicker(plugin, onMeasure, crystalStructure);
|
|
39
|
+
})
|
|
40
|
+
.catch(() => undefined);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Whether {@link dispose} has been called.
|
|
45
|
+
* @returns True once the viewer is disposed.
|
|
46
|
+
*/
|
|
47
|
+
get disposed() {
|
|
48
|
+
return this.#plugin.disposed;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Wait for initialisation, then run `action` on the plugin.
|
|
52
|
+
* @param action - What to do with the molstar context.
|
|
53
|
+
* @returns Nothing once the viewer has been disposed — before the call or
|
|
54
|
+
* while `action` was still running. An initialisation failure, and any
|
|
55
|
+
* error `action` throws while the viewer is alive, still reach the caller.
|
|
56
|
+
*/
|
|
57
|
+
run(action) {
|
|
58
|
+
return this.#plugin.run(action).then(() => undefined);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Frame everything on screen.
|
|
62
|
+
* @param durationMs - Transition length; 0 jumps.
|
|
63
|
+
* @param orientation - Where to look from, from `sceneOrientation`. Left out,
|
|
64
|
+
* the camera keeps the direction it is already pointing.
|
|
65
|
+
* @returns Resolves once the camera has been told where to go.
|
|
66
|
+
*/
|
|
67
|
+
resetCamera(durationMs = DEFAULT_CAMERA_DURATION, orientation) {
|
|
68
|
+
return this.run((plugin) => {
|
|
69
|
+
resetCamera(plugin, durationMs, orientation);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Where the camera stands, against what is drawn.
|
|
74
|
+
* @returns The camera, or `null` while nothing is drawn.
|
|
75
|
+
*/
|
|
76
|
+
async readCamera() {
|
|
77
|
+
return (await this.#plugin.run(readCamera)) ?? null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Put the camera back where {@link readCamera} found it.
|
|
81
|
+
* @param camera - Where to stand.
|
|
82
|
+
* @returns Resolves once the camera stands there.
|
|
83
|
+
*/
|
|
84
|
+
applyCamera(camera) {
|
|
85
|
+
return this.run((plugin) => {
|
|
86
|
+
applyCamera(plugin, camera);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Render the scene off screen at a size of its own, for a picture to save.
|
|
91
|
+
* @param size - Pixel size of the picture.
|
|
92
|
+
* @returns The PNG as a data URI; `undefined` once the viewer is disposed.
|
|
93
|
+
*/
|
|
94
|
+
captureImage(size) {
|
|
95
|
+
return this.#plugin.run((plugin) => captureScene(plugin, size));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Render the part of the scene holding the crystal, for a figure handed on.
|
|
99
|
+
* @param size - Pixel size of the frame the crystal is cut from.
|
|
100
|
+
* @param longest - Longest side of the figure, in pixels.
|
|
101
|
+
* @returns The figure; `undefined` once the viewer is disposed.
|
|
102
|
+
*/
|
|
103
|
+
captureFigure(size, longest) {
|
|
104
|
+
return this.#plugin.run((plugin) => captureFigure(plugin, size, longest));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Zoom onto one point of the scene.
|
|
108
|
+
* @param centre - What to frame, Cartesian ångström.
|
|
109
|
+
* @param radius - Radius of the ball to fit, ångström.
|
|
110
|
+
* @param durationMs - Transition length; 0 jumps.
|
|
111
|
+
* @param orientation - Where to look from; the current direction when absent.
|
|
112
|
+
* @returns Resolves once the camera has been told where to go.
|
|
113
|
+
*/
|
|
114
|
+
focus(centre, radius, durationMs = DEFAULT_CAMERA_DURATION, orientation) {
|
|
115
|
+
return this.run((plugin) => {
|
|
116
|
+
focusPoint(plugin, centre, radius, { durationMs, orientation });
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Turn the automatic spin on or off. It moves the camera, never the object:
|
|
121
|
+
* showing that a molecule maps onto itself is a different button.
|
|
122
|
+
* @param spinning - Whether the scene should keep turning.
|
|
123
|
+
* @param speed - molstar's own spin unit.
|
|
124
|
+
* @returns Resolves once the spin is set.
|
|
125
|
+
*/
|
|
126
|
+
setSpin(spinning, speed = 1) {
|
|
127
|
+
return this.run((plugin) => {
|
|
128
|
+
setSpin(plugin, spinning, speed);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Report what the pointer rests on, by the label its drawing carries. Every
|
|
133
|
+
* axis, plane and centre is drawn with a label already — `C3 along [111]`,
|
|
134
|
+
* `n glide at x = ¼` — and an atom is named `O 1`, never by the row molstar
|
|
135
|
+
* parsed it from.
|
|
136
|
+
* @param listener - Called with the label, or `null` over nothing.
|
|
137
|
+
* @returns A function that stops the reporting; safe to call at any time.
|
|
138
|
+
*/
|
|
139
|
+
onHover(listener) {
|
|
140
|
+
return this.#plugin.subscribe((plugin) => subscribeHoverLabel(plugin, (hover) => {
|
|
141
|
+
listener(hover === null ? null : hover.label);
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Make clicks on atoms build a measurement, or give them back to the camera.
|
|
146
|
+
* @param kind - The measurement to build, or `null`.
|
|
147
|
+
* @returns Resolves once clicks build that measurement.
|
|
148
|
+
*/
|
|
149
|
+
setMeasureKind(kind) {
|
|
150
|
+
return this.run(() => {
|
|
151
|
+
this.#picker?.setKind(kind);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Draw exactly these measurements over the atoms on screen.
|
|
156
|
+
* @param measurements - Replaces whatever is drawn; empty clears them.
|
|
157
|
+
* @returns Resolves once they are drawn.
|
|
158
|
+
*/
|
|
159
|
+
showMeasurements(measurements) {
|
|
160
|
+
return this.run(async (plugin) => {
|
|
161
|
+
if (measurements.length === 0) {
|
|
162
|
+
await clearMeasurements(plugin);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
await renderMeasurements(plugin, measurements, crystalStructure);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/** Re-read the container's size. Call from a `ResizeObserver`. */
|
|
169
|
+
handleResize() {
|
|
170
|
+
this.#plugin.handleResize();
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Tear the canvas down and release its WebGL context. Idempotent, and safe to
|
|
174
|
+
* call before initialisation has finished.
|
|
175
|
+
*/
|
|
176
|
+
dispose() {
|
|
177
|
+
this.#picker?.dispose();
|
|
178
|
+
this.#plugin.dispose();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/crystal3d/viewer/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,OAAO,EACP,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EACL,uBAAuB,EACvB,WAAW,EACX,UAAU,EACV,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAiBxD,6EAA6E;AAC7E,MAAM,OAAO,mBAAmB;IACrB,OAAO,CAAgB;IAChC,OAAO,CAAgC;IAEvC,wEAAwE;IAC/D,KAAK,CAAgB;IAE9B,YAAY,SAAsB,EAAE,UAAgC,EAAE;QACpE,IAAI,CAAC,OAAO,GAAG,IAAI,aAAa,CAAC,SAAS,EAAE;YAC1C,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B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