matterviz 0.4.0 → 0.4.2

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.
Files changed (527) hide show
  1. package/dist/EmptyState.svelte +10 -4
  2. package/dist/FilePicker.svelte +12 -14
  3. package/dist/Icon.svelte +7 -4
  4. package/dist/MillerIndexInput.svelte +2 -2
  5. package/dist/app.css +53 -0
  6. package/dist/brillouin/BrillouinZone.svelte +132 -219
  7. package/dist/brillouin/BrillouinZone.svelte.d.ts +9 -20
  8. package/dist/brillouin/BrillouinZoneControls.svelte +3 -6
  9. package/dist/brillouin/BrillouinZoneExportPane.svelte +47 -96
  10. package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +1 -1
  11. package/dist/brillouin/BrillouinZoneInfoPane.svelte +15 -42
  12. package/dist/brillouin/BrillouinZoneInfoPane.svelte.d.ts +2 -3
  13. package/dist/brillouin/BrillouinZoneScene.svelte +63 -230
  14. package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +3 -23
  15. package/dist/brillouin/ReciprocalVectors.svelte +39 -0
  16. package/dist/brillouin/ReciprocalVectors.svelte.d.ts +9 -0
  17. package/dist/brillouin/compute.d.ts +2 -0
  18. package/dist/brillouin/compute.js +80 -77
  19. package/dist/brillouin/geometry.d.ts +8 -0
  20. package/dist/brillouin/geometry.js +57 -0
  21. package/dist/brillouin/index.d.ts +2 -0
  22. package/dist/brillouin/index.js +2 -0
  23. package/dist/brillouin/types.d.ts +2 -2
  24. package/dist/chempot-diagram/ChemPotDiagram.svelte +33 -38
  25. package/dist/chempot-diagram/ChemPotDiagram.svelte.d.ts +1 -1
  26. package/dist/chempot-diagram/ChemPotDiagram2D.svelte +143 -246
  27. package/dist/chempot-diagram/ChemPotDiagram2D.svelte.d.ts +4 -1
  28. package/dist/chempot-diagram/ChemPotDiagram3D.svelte +652 -976
  29. package/dist/chempot-diagram/ChemPotDiagram3D.svelte.d.ts +7 -1
  30. package/dist/chempot-diagram/async-compute.svelte.js +1 -1
  31. package/dist/chempot-diagram/color.d.ts +3 -6
  32. package/dist/chempot-diagram/color.js +5 -5
  33. package/dist/chempot-diagram/compute.d.ts +3 -3
  34. package/dist/chempot-diagram/compute.js +3 -1
  35. package/dist/chempot-diagram/controls-state.svelte.d.ts +10 -0
  36. package/dist/chempot-diagram/controls-state.svelte.js +42 -0
  37. package/dist/chempot-diagram/export.d.ts +47 -0
  38. package/dist/chempot-diagram/export.js +133 -0
  39. package/dist/chempot-diagram/index.d.ts +1 -0
  40. package/dist/chempot-diagram/index.js +1 -0
  41. package/dist/chempot-diagram/pointer.d.ts +0 -10
  42. package/dist/chempot-diagram/pointer.js +4 -4
  43. package/dist/chempot-diagram/types.d.ts +3 -3
  44. package/dist/colors/index.d.ts +0 -4
  45. package/dist/colors/index.js +21 -22
  46. package/dist/composition/BarChart.svelte +37 -31
  47. package/dist/composition/BubbleChart.svelte +17 -17
  48. package/dist/composition/Composition.svelte +7 -11
  49. package/dist/composition/Formula.svelte +18 -25
  50. package/dist/composition/FormulaFilter.svelte +96 -98
  51. package/dist/composition/PieChart.svelte +60 -46
  52. package/dist/composition/chem-sys.js +3 -2
  53. package/dist/composition/format.js +4 -3
  54. package/dist/composition/index.d.ts +2 -0
  55. package/dist/composition/index.js +14 -0
  56. package/dist/composition/parse.d.ts +2 -3
  57. package/dist/composition/parse.js +27 -28
  58. package/dist/constants.js +11 -9
  59. package/dist/controls.d.ts +1 -0
  60. package/dist/controls.js +0 -1
  61. package/dist/convex-hull/ConvexHull.svelte +20 -25
  62. package/dist/convex-hull/ConvexHull.svelte.d.ts +1 -4
  63. package/dist/convex-hull/ConvexHull2D.svelte +176 -256
  64. package/dist/convex-hull/ConvexHull2D.svelte.d.ts +1 -1
  65. package/dist/convex-hull/ConvexHull3D.svelte +269 -804
  66. package/dist/convex-hull/ConvexHull3D.svelte.d.ts +1 -1
  67. package/dist/convex-hull/ConvexHull4D.svelte +236 -755
  68. package/dist/convex-hull/ConvexHull4D.svelte.d.ts +1 -1
  69. package/dist/convex-hull/ConvexHullChrome.svelte +264 -0
  70. package/dist/convex-hull/ConvexHullChrome.svelte.d.ts +30 -0
  71. package/dist/convex-hull/ConvexHullControls.svelte +128 -49
  72. package/dist/convex-hull/ConvexHullControls.svelte.d.ts +7 -6
  73. package/dist/convex-hull/ConvexHullInfoPane.svelte +18 -5
  74. package/dist/convex-hull/ConvexHullInfoPane.svelte.d.ts +6 -5
  75. package/dist/convex-hull/ConvexHullStats.svelte +210 -351
  76. package/dist/convex-hull/ConvexHullStats.svelte.d.ts +3 -1
  77. package/dist/convex-hull/ConvexHullTooltip.svelte +16 -14
  78. package/dist/convex-hull/ConvexHullTooltip.svelte.d.ts +2 -1
  79. package/dist/convex-hull/GasPressureControls.svelte +5 -12
  80. package/dist/convex-hull/StructurePopup.svelte +17 -21
  81. package/dist/convex-hull/StructurePopup.svelte.d.ts +2 -0
  82. package/dist/convex-hull/TemperatureSlider.svelte +4 -10
  83. package/dist/convex-hull/barycentric-coords.d.ts +2 -4
  84. package/dist/convex-hull/barycentric-coords.js +6 -33
  85. package/dist/convex-hull/canvas-interactions.svelte.d.ts +79 -0
  86. package/dist/convex-hull/canvas-interactions.svelte.js +279 -0
  87. package/dist/convex-hull/helpers.d.ts +47 -17
  88. package/dist/convex-hull/helpers.js +186 -101
  89. package/dist/convex-hull/hull-state.svelte.d.ts +44 -0
  90. package/dist/convex-hull/hull-state.svelte.js +124 -0
  91. package/dist/convex-hull/index.d.ts +9 -7
  92. package/dist/convex-hull/index.js +7 -2
  93. package/dist/convex-hull/thermodynamics.js +109 -937
  94. package/dist/convex-hull/types.d.ts +12 -4
  95. package/dist/convex-hull/types.js +12 -0
  96. package/dist/coordination/CoordinationBarPlot.svelte +41 -43
  97. package/dist/coordination/CoordinationBarPlot.svelte.d.ts +1 -1
  98. package/dist/coordination/calc-coordination.d.ts +1 -1
  99. package/dist/coordination/calc-coordination.js +28 -25
  100. package/dist/element/BohrAtom.svelte +6 -8
  101. package/dist/element/ElementHeading.svelte +4 -1
  102. package/dist/element/ElementPhoto.svelte +11 -9
  103. package/dist/element/ElementStats.svelte +12 -10
  104. package/dist/element/ElementTile.svelte +24 -29
  105. package/dist/element/ElementTile.svelte.d.ts +1 -1
  106. package/dist/element/Nucleus.svelte +4 -2
  107. package/dist/element/data.d.ts +1 -2
  108. package/dist/element/helpers.d.ts +4 -0
  109. package/dist/element/helpers.js +18 -0
  110. package/dist/element/index.d.ts +1 -0
  111. package/dist/element/index.js +3 -0
  112. package/dist/feedback/DragOverlay.svelte +5 -3
  113. package/dist/feedback/DragOverlay.svelte.d.ts +2 -1
  114. package/dist/feedback/StatusMessage.svelte +20 -7
  115. package/dist/fermi-surface/FermiSlice.svelte +21 -18
  116. package/dist/fermi-surface/FermiSurface.svelte +78 -165
  117. package/dist/fermi-surface/FermiSurface.svelte.d.ts +9 -20
  118. package/dist/fermi-surface/FermiSurfaceControls.svelte +6 -20
  119. package/dist/fermi-surface/FermiSurfaceScene.svelte +93 -272
  120. package/dist/fermi-surface/FermiSurfaceScene.svelte.d.ts +3 -23
  121. package/dist/fermi-surface/FermiSurfaceTooltip.svelte +9 -6
  122. package/dist/fermi-surface/compute.js +14 -13
  123. package/dist/fermi-surface/export.js +4 -15
  124. package/dist/fermi-surface/index.d.ts +0 -1
  125. package/dist/fermi-surface/index.js +0 -1
  126. package/dist/fermi-surface/parse.d.ts +1 -1
  127. package/dist/fermi-surface/parse.js +84 -97
  128. package/dist/fermi-surface/types.d.ts +2 -2
  129. package/dist/heatmap-matrix/HeatmapMatrix.svelte +161 -185
  130. package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +6 -5
  131. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +12 -9
  132. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +5 -5
  133. package/dist/heatmap-matrix/index.d.ts +8 -2
  134. package/dist/icons.d.ts +4 -0
  135. package/dist/icons.js +4 -0
  136. package/dist/index.d.ts +1 -0
  137. package/dist/index.js +1 -0
  138. package/dist/io/ExportPane.svelte +170 -0
  139. package/dist/io/ExportPane.svelte.d.ts +17 -0
  140. package/dist/io/decompress.d.ts +2 -1
  141. package/dist/io/decompress.js +22 -36
  142. package/dist/io/export.d.ts +9 -1
  143. package/dist/io/export.js +37 -29
  144. package/dist/io/fetch.d.ts +2 -4
  145. package/dist/io/fetch.js +0 -11
  146. package/dist/io/file-drop.d.ts +7 -0
  147. package/dist/io/file-drop.js +13 -0
  148. package/dist/io/index.d.ts +1 -0
  149. package/dist/io/index.js +3 -0
  150. package/dist/io/is-binary.d.ts +9 -0
  151. package/dist/io/is-binary.js +45 -1
  152. package/dist/io/types.d.ts +13 -0
  153. package/dist/io/url-drop.js +13 -25
  154. package/dist/isosurface/Isosurface.svelte +17 -23
  155. package/dist/isosurface/IsosurfaceControls.svelte +37 -42
  156. package/dist/isosurface/parse-vaspwave.d.ts +3 -0
  157. package/dist/isosurface/parse-vaspwave.js +138 -0
  158. package/dist/isosurface/parse.js +50 -48
  159. package/dist/labels.d.ts +6 -2
  160. package/dist/labels.js +44 -14
  161. package/dist/layout/FullscreenButton.svelte +34 -0
  162. package/dist/layout/FullscreenButton.svelte.d.ts +10 -0
  163. package/dist/layout/FullscreenToggle.svelte +12 -12
  164. package/dist/layout/InfoCard.svelte +7 -18
  165. package/dist/layout/InfoTag.svelte +1 -3
  166. package/dist/layout/NumberRangeInput.svelte +46 -0
  167. package/dist/layout/NumberRangeInput.svelte.d.ts +12 -0
  168. package/dist/layout/PropertyFilter.svelte +2 -6
  169. package/dist/layout/SettingsSection.svelte +21 -17
  170. package/dist/layout/SubpageGrid.svelte +3 -1
  171. package/dist/layout/ViewerChrome.svelte +115 -0
  172. package/dist/layout/ViewerChrome.svelte.d.ts +18 -0
  173. package/dist/layout/fullscreen.d.ts +4 -0
  174. package/dist/layout/fullscreen.js +3 -5
  175. package/dist/layout/fullscreen.svelte.d.ts +8 -0
  176. package/dist/layout/fullscreen.svelte.js +36 -0
  177. package/dist/layout/index.d.ts +4 -0
  178. package/dist/layout/index.js +4 -0
  179. package/dist/layout/json-tree/JsonNode.svelte +8 -11
  180. package/dist/layout/json-tree/JsonTree.svelte +53 -77
  181. package/dist/layout/json-tree/JsonValue.svelte +7 -15
  182. package/dist/layout/json-tree/utils.js +14 -23
  183. package/dist/math.d.ts +9 -3
  184. package/dist/math.js +37 -21
  185. package/dist/overlays/ContextMenu.svelte +4 -2
  186. package/dist/overlays/CopyButton.svelte +11 -5
  187. package/dist/overlays/DragControlTab.svelte +6 -1
  188. package/dist/overlays/DraggablePane.svelte +81 -26
  189. package/dist/overlays/DraggablePane.svelte.d.ts +1 -0
  190. package/dist/overlays/GlassChip.svelte +30 -0
  191. package/dist/overlays/GlassChip.svelte.d.ts +8 -0
  192. package/dist/overlays/InfoPaneCards.svelte +11 -23
  193. package/dist/overlays/index.d.ts +11 -0
  194. package/dist/overlays/index.js +26 -0
  195. package/dist/overlays/portal.d.ts +2 -0
  196. package/dist/overlays/portal.js +14 -0
  197. package/dist/periodic-table/PeriodicTable.svelte +115 -146
  198. package/dist/periodic-table/PeriodicTable.svelte.d.ts +5 -3
  199. package/dist/periodic-table/PeriodicTableControls.svelte +11 -63
  200. package/dist/periodic-table/TableInset.svelte +9 -4
  201. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +50 -71
  202. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +6 -8
  203. package/dist/phase-diagram/PhaseDiagramControls.svelte +73 -96
  204. package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +4 -3
  205. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +4 -2
  206. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte.d.ts +2 -3
  207. package/dist/phase-diagram/PhaseDiagramExportPane.svelte +49 -134
  208. package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +3 -4
  209. package/dist/phase-diagram/PhaseDiagramTooltip.svelte +54 -58
  210. package/dist/phase-diagram/TdbInfoPanel.svelte +21 -15
  211. package/dist/phase-diagram/build-diagram.js +3 -3
  212. package/dist/phase-diagram/colors.js +1 -1
  213. package/dist/phase-diagram/diagram-input.d.ts +1 -2
  214. package/dist/phase-diagram/parse.d.ts +2 -1
  215. package/dist/phase-diagram/parse.js +15 -15
  216. package/dist/phase-diagram/svg-to-diagram.js +21 -15
  217. package/dist/phase-diagram/utils.js +2 -3
  218. package/dist/plot/bar/BarPlot.svelte +494 -692
  219. package/dist/plot/bar/BarPlot.svelte.d.ts +9 -15
  220. package/dist/plot/bar/BarPlotControls.svelte +1 -3
  221. package/dist/plot/bar/BarPlotControls.svelte.d.ts +5 -7
  222. package/dist/plot/bar/SpacegroupBarPlot.svelte +31 -37
  223. package/dist/plot/bar/data.d.ts +5 -4
  224. package/dist/plot/bar/data.js +2 -1
  225. package/dist/plot/box/BoxPlot.svelte +361 -439
  226. package/dist/plot/box/BoxPlot.svelte.d.ts +6 -3
  227. package/dist/plot/box/BoxPlotControls.svelte.d.ts +1 -1
  228. package/dist/plot/box/Violin.svelte.d.ts +2 -1
  229. package/dist/plot/box/box-plot.d.ts +3 -2
  230. package/dist/plot/box/box-plot.js +6 -3
  231. package/dist/plot/box/kde.d.ts +2 -1
  232. package/dist/plot/box/kde.js +4 -4
  233. package/dist/plot/core/auto-place.d.ts +1 -1
  234. package/dist/plot/core/auto-place.js +5 -2
  235. package/dist/plot/core/axis-utils.d.ts +12 -7
  236. package/dist/plot/core/axis-utils.js +48 -48
  237. package/dist/plot/core/components/AxisLabel.svelte +82 -20
  238. package/dist/plot/core/components/AxisLabel.svelte.d.ts +1 -0
  239. package/dist/plot/core/components/ColorBar.svelte +106 -111
  240. package/dist/plot/core/components/ColorBar.svelte.d.ts +5 -4
  241. package/dist/plot/core/components/ColorScaleSelect.svelte +1 -1
  242. package/dist/plot/core/components/FillArea.svelte +10 -17
  243. package/dist/plot/core/components/HierarchyControls.svelte +249 -0
  244. package/dist/plot/{sunburst/SunburstControls.svelte.d.ts → core/components/HierarchyControls.svelte.d.ts} +12 -8
  245. package/dist/plot/core/components/InteractiveAxisLabel.svelte +1 -1
  246. package/dist/plot/core/components/InteractiveAxisLabel.svelte.d.ts +1 -1
  247. package/dist/plot/core/components/Line.svelte +21 -11
  248. package/dist/plot/core/components/Line.svelte.d.ts +5 -2
  249. package/dist/plot/core/components/PlotAxis.svelte +42 -18
  250. package/dist/plot/core/components/PlotAxis.svelte.d.ts +2 -1
  251. package/dist/plot/core/components/PlotControls.svelte +65 -41
  252. package/dist/plot/core/components/PlotControls.svelte.d.ts +1 -1
  253. package/dist/plot/core/components/PlotLegend.svelte +31 -35
  254. package/dist/plot/core/components/PlotMarginals.svelte +616 -0
  255. package/dist/plot/core/components/PlotMarginals.svelte.d.ts +15 -0
  256. package/dist/plot/core/components/PlotTooltip.svelte +1 -1
  257. package/dist/plot/core/components/PortalSelect.svelte +4 -8
  258. package/dist/plot/core/components/ReferenceLine.svelte +27 -24
  259. package/dist/plot/core/components/ReferenceLine3D.svelte +56 -59
  260. package/dist/plot/core/components/ReferenceLine3D.svelte.d.ts +4 -4
  261. package/dist/plot/core/components/ReferencePlane.svelte +9 -10
  262. package/dist/plot/core/components/ReferencePlane.svelte.d.ts +4 -4
  263. package/dist/plot/core/components/ZeroLines.svelte +4 -8
  264. package/dist/plot/core/components/ZoomRect.svelte +1 -2
  265. package/dist/plot/core/components/index.d.ts +1 -0
  266. package/dist/plot/core/components/index.js +1 -0
  267. package/dist/plot/core/data-cleaning-signal.d.ts +46 -0
  268. package/dist/plot/core/data-cleaning-signal.js +467 -0
  269. package/dist/plot/core/data-cleaning.d.ts +2 -42
  270. package/dist/plot/core/data-cleaning.js +29 -476
  271. package/dist/plot/core/data-transform.js +9 -5
  272. package/dist/plot/core/fill-utils.d.ts +7 -4
  273. package/dist/plot/core/fill-utils.js +34 -9
  274. package/dist/plot/core/index.d.ts +1 -0
  275. package/dist/plot/core/index.js +1 -0
  276. package/dist/plot/core/interactions.d.ts +5 -1
  277. package/dist/plot/core/interactions.js +14 -2
  278. package/dist/plot/core/layout.d.ts +3 -1
  279. package/dist/plot/core/layout.js +22 -13
  280. package/dist/plot/core/marginals.d.ts +170 -0
  281. package/dist/plot/core/marginals.js +436 -0
  282. package/dist/plot/core/pan-zoom.svelte.d.ts +35 -0
  283. package/dist/plot/core/pan-zoom.svelte.js +221 -0
  284. package/dist/plot/core/placed-tween.svelte.d.ts +21 -0
  285. package/dist/plot/core/placed-tween.svelte.js +68 -0
  286. package/dist/plot/core/reference-line.d.ts +10 -10
  287. package/dist/plot/core/reference-line.js +7 -7
  288. package/dist/plot/core/scales.d.ts +40 -25
  289. package/dist/plot/core/scales.js +49 -21
  290. package/dist/plot/core/svg.d.ts +2 -1
  291. package/dist/plot/core/types/fills.d.ts +101 -0
  292. package/dist/plot/core/types/fills.js +15 -0
  293. package/dist/plot/core/types/plot-3d.d.ts +87 -0
  294. package/dist/plot/core/types/plot-3d.js +4 -0
  295. package/dist/plot/core/types/reference-lines.d.ts +140 -0
  296. package/dist/plot/core/types/reference-lines.js +9 -0
  297. package/dist/plot/core/types.d.ts +47 -331
  298. package/dist/plot/core/types.js +23 -20
  299. package/dist/plot/core/utils/hierarchy-chart.d.ts +51 -0
  300. package/dist/plot/core/utils/hierarchy-chart.js +179 -0
  301. package/dist/plot/core/utils/hierarchy-labels.d.ts +20 -0
  302. package/dist/plot/core/utils/hierarchy-labels.js +99 -0
  303. package/dist/plot/core/utils/label-placement.d.ts +1 -1
  304. package/dist/plot/core/utils/label-placement.js +5 -5
  305. package/dist/plot/core/utils.d.ts +2 -1
  306. package/dist/plot/histogram/Histogram.svelte +373 -631
  307. package/dist/plot/histogram/Histogram.svelte.d.ts +7 -7
  308. package/dist/plot/histogram/HistogramControls.svelte +30 -28
  309. package/dist/plot/histogram/HistogramControls.svelte.d.ts +1 -1
  310. package/dist/plot/histogram/histogram.d.ts +31 -0
  311. package/dist/plot/histogram/histogram.js +70 -0
  312. package/dist/plot/histogram/index.d.ts +1 -0
  313. package/dist/plot/histogram/index.js +1 -0
  314. package/dist/plot/index.d.ts +1 -0
  315. package/dist/plot/index.js +1 -0
  316. package/dist/plot/sankey/Sankey.svelte +79 -73
  317. package/dist/plot/sankey/Sankey.svelte.d.ts +3 -3
  318. package/dist/plot/sankey/SankeyControls.svelte +22 -16
  319. package/dist/plot/sankey/sankey.js +3 -1
  320. package/dist/plot/scatter/BinnedScatterPlot.svelte +264 -112
  321. package/dist/plot/scatter/BinnedScatterPlot.svelte.d.ts +11 -4
  322. package/dist/plot/scatter/ElementScatter.svelte +4 -1
  323. package/dist/plot/scatter/ScatterPlot.svelte +623 -821
  324. package/dist/plot/scatter/ScatterPlot.svelte.d.ts +9 -15
  325. package/dist/plot/scatter/ScatterPlotControls.svelte +18 -19
  326. package/dist/plot/scatter/ScatterPlotControls.svelte.d.ts +1 -1
  327. package/dist/plot/scatter/ScatterPoint.svelte +16 -9
  328. package/dist/plot/scatter/binned-scatter-types.d.ts +6 -12
  329. package/dist/plot/scatter/binned-scatter-types.js +6 -1
  330. package/dist/plot/scatter/index.d.ts +1 -1
  331. package/dist/plot/scatter/scatter-data.d.ts +1 -1
  332. package/dist/plot/scatter/scatter-data.js +8 -7
  333. package/dist/plot/scatter-3d/ScatterPlot3D.svelte +40 -60
  334. package/dist/plot/scatter-3d/ScatterPlot3D.svelte.d.ts +6 -14
  335. package/dist/plot/scatter-3d/ScatterPlot3DControls.svelte +17 -15
  336. package/dist/plot/scatter-3d/ScatterPlot3DControls.svelte.d.ts +5 -5
  337. package/dist/plot/scatter-3d/ScatterPlot3DScene.svelte +232 -234
  338. package/dist/plot/scatter-3d/ScatterPlot3DScene.svelte.d.ts +5 -14
  339. package/dist/plot/scatter-3d/Surface3D.svelte +9 -17
  340. package/dist/plot/scatter-3d/Surface3D.svelte.d.ts +4 -3
  341. package/dist/plot/sunburst/Sunburst.svelte +256 -338
  342. package/dist/plot/sunburst/Sunburst.svelte.d.ts +4 -3
  343. package/dist/plot/sunburst/index.d.ts +1 -1
  344. package/dist/plot/sunburst/index.js +2 -1
  345. package/dist/plot/sunburst/render.d.ts +2 -2
  346. package/dist/plot/sunburst/render.js +47 -22
  347. package/dist/plot/sunburst/sunburst.d.ts +5 -1
  348. package/dist/plot/sunburst/sunburst.js +14 -4
  349. package/dist/plot/treemap/Treemap.svelte +907 -0
  350. package/dist/plot/treemap/Treemap.svelte.d.ts +84 -0
  351. package/dist/plot/treemap/index.d.ts +3 -0
  352. package/dist/plot/treemap/index.js +4 -0
  353. package/dist/plot/treemap/treemap.d.ts +26 -0
  354. package/dist/plot/treemap/treemap.js +99 -0
  355. package/dist/rdf/RdfPlot.svelte +22 -26
  356. package/dist/rdf/RdfPlot.svelte.d.ts +1 -1
  357. package/dist/rdf/calc-rdf.js +4 -8
  358. package/dist/sanitize.js +14 -3
  359. package/dist/scene/SceneCamera.svelte +62 -0
  360. package/dist/scene/SceneCamera.svelte.d.ts +19 -0
  361. package/dist/scene/bind-renderer.svelte.d.ts +2 -0
  362. package/dist/scene/bind-renderer.svelte.js +22 -0
  363. package/dist/scene/index.d.ts +4 -0
  364. package/dist/scene/index.js +5 -0
  365. package/dist/scene/props.js +52 -0
  366. package/dist/scene/types.d.ts +26 -0
  367. package/dist/scene/types.js +1 -0
  368. package/dist/settings.d.ts +33 -11
  369. package/dist/settings.js +136 -51
  370. package/dist/spectral/Bands.svelte +231 -237
  371. package/dist/spectral/Bands.svelte.d.ts +3 -2
  372. package/dist/spectral/BandsAndDos.svelte +29 -29
  373. package/dist/spectral/BrillouinBandsDos.svelte +21 -29
  374. package/dist/spectral/Dos.svelte +75 -77
  375. package/dist/spectral/Dos.svelte.d.ts +2 -1
  376. package/dist/spectral/helpers.d.ts +9 -9
  377. package/dist/spectral/helpers.js +66 -70
  378. package/dist/state.svelte.d.ts +0 -7
  379. package/dist/state.svelte.js +5 -24
  380. package/dist/structure/Arrow.svelte +6 -21
  381. package/dist/structure/ArrowInstances.svelte +160 -0
  382. package/dist/structure/ArrowInstances.svelte.d.ts +16 -0
  383. package/dist/structure/AtomLegend.svelte +115 -75
  384. package/dist/structure/AtomLegend.svelte.d.ts +1 -1
  385. package/dist/structure/Bond.svelte +31 -23
  386. package/dist/structure/CanvasTooltip.svelte +16 -3
  387. package/dist/structure/CellSelect.svelte +22 -29
  388. package/dist/structure/CellSelect.svelte.d.ts +2 -1
  389. package/dist/structure/Cylinder.svelte +24 -40
  390. package/dist/structure/InstancedAtoms.svelte +114 -0
  391. package/dist/structure/InstancedAtoms.svelte.d.ts +15 -0
  392. package/dist/structure/Lattice.svelte +85 -149
  393. package/dist/structure/SiteLabels.svelte +122 -0
  394. package/dist/structure/SiteLabels.svelte.d.ts +18 -0
  395. package/dist/structure/Structure.svelte +725 -735
  396. package/dist/structure/Structure.svelte.d.ts +8 -16
  397. package/dist/structure/StructureCarousel.svelte +630 -0
  398. package/dist/structure/StructureCarousel.svelte.d.ts +19 -0
  399. package/dist/structure/StructureControls.svelte +298 -325
  400. package/dist/structure/StructureControls.svelte.d.ts +5 -3
  401. package/dist/structure/StructureExportPane.svelte +62 -168
  402. package/dist/structure/StructureExportPane.svelte.d.ts +4 -5
  403. package/dist/structure/StructureInfoPane.svelte +77 -69
  404. package/dist/structure/StructureInfoPane.svelte.d.ts +6 -6
  405. package/dist/structure/StructureScene.svelte +758 -600
  406. package/dist/structure/StructureScene.svelte.d.ts +24 -20
  407. package/dist/structure/StructureViewport.svelte +386 -0
  408. package/dist/structure/StructureViewport.svelte.d.ts +63 -0
  409. package/dist/structure/atom-label-placement.d.ts +18 -0
  410. package/dist/structure/atom-label-placement.js +115 -0
  411. package/dist/structure/atom-properties.d.ts +3 -1
  412. package/dist/structure/atom-properties.js +115 -54
  413. package/dist/structure/bond-order-perception.js +2 -4
  414. package/dist/structure/bonding.d.ts +12 -2
  415. package/dist/structure/bonding.js +172 -73
  416. package/dist/structure/edit-history.d.ts +6 -0
  417. package/dist/structure/edit-history.js +27 -0
  418. package/dist/structure/export.d.ts +25 -4
  419. package/dist/structure/export.js +103 -153
  420. package/dist/structure/format-detect.d.ts +1 -0
  421. package/dist/structure/format-detect.js +22 -0
  422. package/dist/structure/geometry.d.ts +9 -0
  423. package/dist/structure/geometry.js +27 -0
  424. package/dist/structure/index.d.ts +18 -1
  425. package/dist/structure/index.js +15 -2
  426. package/dist/structure/measure.d.ts +1 -1
  427. package/dist/structure/measure.js +6 -12
  428. package/dist/structure/parse.d.ts +5 -3
  429. package/dist/structure/parse.js +551 -567
  430. package/dist/structure/partial-occupancy.d.ts +0 -1
  431. package/dist/structure/partial-occupancy.js +5 -3
  432. package/dist/structure/pbc.d.ts +1 -1
  433. package/dist/structure/pbc.js +204 -51
  434. package/dist/structure/polyhedra.d.ts +40 -0
  435. package/dist/structure/polyhedra.js +587 -0
  436. package/dist/structure/site.d.ts +4 -0
  437. package/dist/structure/site.js +1 -0
  438. package/dist/structure/supercell.d.ts +1 -2
  439. package/dist/structure/supercell.js +10 -15
  440. package/dist/structure/validation.js +5 -6
  441. package/dist/symmetry/SymmetryElementControls.svelte +69 -0
  442. package/dist/symmetry/SymmetryElementControls.svelte.d.ts +9 -0
  443. package/dist/symmetry/SymmetryElements.svelte +350 -0
  444. package/dist/symmetry/SymmetryElements.svelte.d.ts +24 -0
  445. package/dist/symmetry/SymmetryStats.svelte +142 -49
  446. package/dist/symmetry/WyckoffTable.svelte +58 -16
  447. package/dist/symmetry/WyckoffTable.svelte.d.ts +3 -0
  448. package/dist/symmetry/cell-transform.js +8 -14
  449. package/dist/symmetry/index.d.ts +15 -4
  450. package/dist/symmetry/index.js +308 -81
  451. package/dist/symmetry/spacegroups.d.ts +5 -1
  452. package/dist/symmetry/spacegroups.js +18 -3
  453. package/dist/symmetry/symmetry-elements.d.ts +33 -0
  454. package/dist/symmetry/symmetry-elements.js +521 -0
  455. package/dist/symmetry/wyckoff-db.d.ts +9 -0
  456. package/dist/symmetry/wyckoff-db.js +87 -0
  457. package/dist/table/HeatmapTable.svelte +1104 -378
  458. package/dist/table/HeatmapTable.svelte.d.ts +12 -2
  459. package/dist/table/ToggleMenu.svelte +5 -12
  460. package/dist/table/index.d.ts +21 -6
  461. package/dist/table/index.js +34 -21
  462. package/dist/theme/ThemeControl.svelte +16 -8
  463. package/dist/theme/index.d.ts +1 -5
  464. package/dist/theme/index.js +4 -10
  465. package/dist/theme/themes.mjs +14 -7
  466. package/dist/tooltip/KCoords.svelte +4 -1
  467. package/dist/tooltip/TooltipContent.svelte +2 -5
  468. package/dist/trajectory/Trajectory.svelte +556 -352
  469. package/dist/trajectory/Trajectory.svelte.d.ts +10 -22
  470. package/dist/trajectory/TrajectoryError.svelte +11 -8
  471. package/dist/trajectory/TrajectoryExportPane.svelte +28 -54
  472. package/dist/trajectory/TrajectoryExportPane.svelte.d.ts +4 -5
  473. package/dist/trajectory/TrajectoryInfoPane.svelte +88 -99
  474. package/dist/trajectory/TrajectoryInfoPane.svelte.d.ts +3 -2
  475. package/dist/trajectory/constants.js +6 -2
  476. package/dist/trajectory/extract.js +73 -71
  477. package/dist/trajectory/format-detect.d.ts +0 -1
  478. package/dist/trajectory/format-detect.js +13 -17
  479. package/dist/trajectory/frame-reader.d.ts +2 -1
  480. package/dist/trajectory/frame-reader.js +74 -136
  481. package/dist/trajectory/helpers.d.ts +12 -2
  482. package/dist/trajectory/helpers.js +68 -37
  483. package/dist/trajectory/index.d.ts +1 -0
  484. package/dist/trajectory/index.js +3 -0
  485. package/dist/trajectory/parse/ase.d.ts +9 -1
  486. package/dist/trajectory/parse/ase.js +47 -32
  487. package/dist/trajectory/parse/diagnostics.d.ts +3 -0
  488. package/dist/trajectory/parse/diagnostics.js +14 -0
  489. package/dist/trajectory/parse/h5-utils.d.ts +13 -0
  490. package/dist/trajectory/parse/h5-utils.js +109 -0
  491. package/dist/trajectory/parse/hdf5.d.ts +1 -1
  492. package/dist/trajectory/parse/hdf5.js +116 -106
  493. package/dist/trajectory/parse/index.d.ts +3 -4
  494. package/dist/trajectory/parse/index.js +68 -119
  495. package/dist/trajectory/parse/lammps.d.ts +0 -2
  496. package/dist/trajectory/parse/lammps.js +14 -16
  497. package/dist/trajectory/parse/pymatgen.d.ts +2 -0
  498. package/dist/trajectory/parse/pymatgen.js +74 -0
  499. package/dist/trajectory/parse/vasp.js +13 -9
  500. package/dist/trajectory/parse/vaspout-electronic.d.ts +13 -0
  501. package/dist/trajectory/parse/vaspout-electronic.js +207 -0
  502. package/dist/trajectory/parse/vaspout-h5.d.ts +5 -0
  503. package/dist/trajectory/parse/vaspout-h5.js +284 -0
  504. package/dist/trajectory/parse/xyz.d.ts +9 -21
  505. package/dist/trajectory/parse/xyz.js +38 -39
  506. package/dist/trajectory/plotting.d.ts +8 -10
  507. package/dist/trajectory/plotting.js +102 -127
  508. package/dist/utils.d.ts +4 -0
  509. package/dist/utils.js +8 -1
  510. package/dist/xrd/XrdPlot.svelte +56 -85
  511. package/dist/xrd/broadening.d.ts +2 -1
  512. package/dist/xrd/broadening.js +2 -1
  513. package/dist/xrd/calc-xrd.js +8 -15
  514. package/dist/xrd/index.d.ts +2 -2
  515. package/dist/xrd/parse.d.ts +0 -1
  516. package/dist/xrd/parse.js +56 -73
  517. package/package.json +77 -36
  518. package/dist/api/mp.d.ts +0 -6
  519. package/dist/api/mp.js +0 -22
  520. package/dist/element/data.json +0 -11864
  521. package/dist/fermi-surface/marching-cubes.d.ts +0 -2
  522. package/dist/fermi-surface/marching-cubes.js +0 -2
  523. package/dist/plot/core/hover-lock.svelte.d.ts +0 -14
  524. package/dist/plot/core/hover-lock.svelte.js +0 -45
  525. package/dist/plot/sunburst/SunburstControls.svelte +0 -200
  526. package/dist/structure/label-placement.d.ts +0 -14
  527. package/dist/structure/label-placement.js +0 -72
@@ -1,6 +1,7 @@
1
1
  // Helper utilities for band structure and DOS data processing
2
2
  import { SUBSCRIPT_MAP } from '../labels';
3
- import { euclidean_dist } from '../math';
3
+ import { is_plain_object } from '../utils';
4
+ import { euclidean_dist, is_square_matrix } from '../math';
4
5
  const is_subscript_key = (key) => key in SUBSCRIPT_MAP;
5
6
  // Check if range is a valid [min, max] tuple (strict 2-element array of finite numbers)
6
7
  export const is_valid_range = (range) => Array.isArray(range) &&
@@ -91,7 +92,7 @@ export function pretty_sym_point(symbol) {
91
92
  .replaceAll(/\\?DELTA/gi, `Δ`)
92
93
  .replaceAll(/\\?SIGMA/gi, `Σ`)
93
94
  .replaceAll(/\\?LAMBDA/gi, `Λ`)
94
- .replaceAll(/(\p{L})(\d+)/gu, (_, letter, num) => letter +
95
+ .replaceAll(/(?<letter>\p{L})(?<num>\d+)/gu, (_, letter, num) => letter +
95
96
  num
96
97
  .split(``)
97
98
  .map((digit) => (is_subscript_key(digit) ? SUBSCRIPT_MAP[digit] : digit))
@@ -194,33 +195,24 @@ export function convert_frequencies(frequencies, unit = `THz`) {
194
195
  }
195
196
  // Normalize DOS densities according to specified mode.
196
197
  export function normalize_densities(densities, freqs_or_energies, mode) {
197
- if (!mode)
198
- return densities;
199
- const normalized = [...densities];
200
198
  if (mode === `max`) {
201
- const max_val = Math.max(...normalized);
202
- if (max_val === 0)
203
- return normalized;
204
- return normalized.map((dens) => dens / max_val);
199
+ const max_val = Math.max(...densities);
200
+ return max_val === 0 ? densities : densities.map((dens) => dens / max_val);
205
201
  }
206
- else if (mode === `sum`) {
207
- const sum = normalized.reduce((acc, d) => acc + d, 0);
208
- if (sum === 0)
209
- return normalized;
210
- return normalized.map((dens) => dens / sum);
202
+ if (mode === `sum`) {
203
+ const sum = densities.reduce((acc, dens) => acc + dens, 0);
204
+ return sum === 0 ? densities : densities.map((dens) => dens / sum);
211
205
  }
212
- else if (mode === `integral`) {
206
+ if (mode === `integral`) {
213
207
  if (freqs_or_energies.length < 2)
214
- return normalized;
208
+ return densities;
215
209
  const bin_width = freqs_or_energies[1] - freqs_or_energies[0];
216
- if (bin_width === 0)
217
- return normalized;
218
- const sum = normalized.reduce((acc, d) => acc + d, 0);
219
- if (sum === 0)
220
- return normalized;
221
- return normalized.map((dens) => dens / (sum * bin_width));
210
+ const sum = densities.reduce((acc, dens) => acc + dens, 0);
211
+ if (bin_width === 0 || sum === 0)
212
+ return densities;
213
+ return densities.map((dens) => dens / (sum * bin_width));
222
214
  }
223
- return normalized;
215
+ return densities;
224
216
  }
225
217
  // Simple LRU cache for Gaussian smearing results
226
218
  // Key: hash of (frequencies, densities, sigma), Value: smeared densities
@@ -250,26 +242,24 @@ function generate_smearing_cache_key(freqs_or_energies, densities, sigma) {
250
242
  }
251
243
  // Core Gaussian smearing computation (unmemoized)
252
244
  function apply_gaussian_smearing_core(freqs_or_energies, densities, sigma) {
253
- const orig_sum = densities.reduce((acc, d) => acc + d, 0);
245
+ const orig_sum = densities.reduce((acc, dens) => acc + dens, 0);
254
246
  if (sigma <= 0 || orig_sum === 0)
255
247
  return densities;
256
248
  const smeared = Array(densities.length).fill(0);
257
- const truncation_width = 4; // Truncate Gaussian at ±4σ (contribution < 0.01%)
249
+ const cutoff = 4 * sigma; // Truncate Gaussian at ±4σ (contribution < 0.01%)
250
+ const inv_two_sigma_sq = 1 / (2 * sigma ** 2);
258
251
  for (let idx = 0; idx < freqs_or_energies.length; idx++) {
259
252
  const energy = freqs_or_energies[idx];
260
- const cutoff = truncation_width * sigma;
261
253
  for (let jdx = 0; jdx < freqs_or_energies.length; jdx++) {
262
- const e_j = freqs_or_energies[jdx];
263
- const delta = Math.abs(energy - e_j);
254
+ const delta = energy - freqs_or_energies[jdx];
264
255
  // Skip points beyond truncation width
265
- if (delta > cutoff)
256
+ if (Math.abs(delta) > cutoff)
266
257
  continue;
267
- const gaussian = Math.exp(-((energy - e_j) ** 2) / (2 * sigma ** 2));
268
- smeared[idx] += densities[jdx] * gaussian;
258
+ smeared[idx] += densities[jdx] * Math.exp(-(delta ** 2) * inv_two_sigma_sq);
269
259
  }
270
260
  }
271
261
  // Normalize to preserve integral
272
- const smeared_sum = smeared.reduce((acc, d) => acc + d, 0);
262
+ const smeared_sum = smeared.reduce((acc, dens) => acc + dens, 0);
273
263
  if (smeared_sum === 0)
274
264
  return densities;
275
265
  const normalization = orig_sum / smeared_sum;
@@ -491,10 +481,9 @@ function convert_pymatgen_band_structure(pmg) {
491
481
  },
492
482
  };
493
483
  }
494
- export function normalize_band_structure(bs) {
495
- if (!bs || typeof bs !== `object`)
484
+ export function normalize_band_structure(band_struct) {
485
+ if (!is_plain_object(band_struct))
496
486
  return null;
497
- const band_struct = bs;
498
487
  // Check if this is pymatgen format and convert if so
499
488
  if (is_pymatgen_format(band_struct)) {
500
489
  return convert_pymatgen_band_structure(band_struct);
@@ -516,27 +505,42 @@ export function normalize_band_structure(bs) {
516
505
  branch.end_index >= n_qpts ||
517
506
  branch.start_index > branch.end_index))
518
507
  return null;
519
- return band_struct;
508
+ // Fill required defaults (recip_lattice/labels_dict/nb_bands) not covered above so the cast below is sound
509
+ const recip_lattice = band_struct.recip_lattice;
510
+ const normalized = {
511
+ ...band_struct,
512
+ nb_bands: typeof band_struct.nb_bands === `number` ? band_struct.nb_bands : bands.length,
513
+ labels_dict: band_struct.labels_dict ?? {},
514
+ recip_lattice: is_square_matrix(recip_lattice?.matrix, 3)
515
+ ? recip_lattice
516
+ : {
517
+ matrix: [
518
+ [1, 0, 0],
519
+ [0, 1, 0],
520
+ [0, 0, 1],
521
+ ],
522
+ },
523
+ };
524
+ return normalized;
520
525
  }
521
526
  // Validate and normalize a DOS object.
522
527
  // Supports both matterviz and pymatgen formats.
523
528
  // Also auto-detects and converts cm⁻¹ to THz for legacy data (disable with auto_convert_units: false).
524
529
  export function normalize_dos(dos, options = {}) {
525
530
  const { auto_convert_units = true } = options;
526
- if (!dos || typeof dos !== `object`)
531
+ if (!is_plain_object(dos))
527
532
  return null;
528
- const dos_obj = dos;
529
533
  // Check for pymatgen format (has @class or @module)
530
- const is_pymatgen = typeof dos_obj[`@class`] === `string` || typeof dos_obj[`@module`] === `string`;
531
- const { frequencies, energies, spin_polarized } = dos_obj;
534
+ const is_pymatgen = typeof dos[`@class`] === `string` || typeof dos[`@module`] === `string`;
535
+ const { frequencies, energies, spin_polarized } = dos;
532
536
  // Handle densities as either array or dict with spin keys (pymatgen format)
533
537
  // Pymatgen stores densities as {1: [...], -1: [...]} or {"Spin.up": [...], ...}
534
- const spin_channels = extract_spin_channels(dos_obj.densities);
538
+ const spin_channels = extract_spin_channels(dos.densities);
535
539
  if (!spin_channels)
536
540
  return null;
537
541
  const densities = spin_channels.up;
538
542
  // Use extracted spin-down or fallback to explicit field (for already-normalized DosData)
539
- const spin_down_densities = spin_channels.down ?? dos_obj.spin_down_densities ?? null;
543
+ const spin_down_densities = spin_channels.down ?? dos.spin_down_densities ?? null;
540
544
  if (!Array.isArray(densities))
541
545
  return null;
542
546
  // Phonon DOS: has frequencies
@@ -743,13 +747,12 @@ export function find_qpoint_at_rescaled_x(band_struct, rescaled_x, x_positions)
743
747
  // Returns a dict of label → DosData for each atom or orbital.
744
748
  // filter_keys: optional list of keys to include (e.g., ["Fe", "O"] for atoms or ["s", "p", "d"] for orbitals)
745
749
  export function extract_pdos(dos, pdos_type, filter_keys) {
746
- if (!dos || typeof dos !== `object`)
750
+ if (!is_plain_object(dos))
747
751
  return null;
748
- const dos_obj = dos;
749
752
  // Get the appropriate projected DOS dict
750
753
  const pdos_dict = pdos_type === `atom`
751
- ? dos_obj.atom_dos
752
- : dos_obj.spd_dos;
754
+ ? dos.atom_dos
755
+ : dos.spd_dos;
753
756
  if (!pdos_dict || typeof pdos_dict !== `object`)
754
757
  return null;
755
758
  const result = {};
@@ -852,21 +855,15 @@ export function generate_ribbon_path(x_values, y_values, width_values, x_scale_f
852
855
  // Handles both single objects with an efermi field and dicts of objects.
853
856
  // Returns undefined if no valid efermi is found or if the source is empty.
854
857
  export function extract_efermi(data) {
855
- if (!data || typeof data !== `object`)
858
+ if (!is_plain_object(data))
856
859
  return undefined;
857
- const obj = data;
858
860
  // Direct efermi field on the object
859
- if (`efermi` in obj && typeof obj.efermi === `number`)
860
- return obj.efermi;
861
+ if (typeof data.efermi === `number`)
862
+ return data.efermi;
861
863
  // Dict of objects - try to get efermi from first value
862
- const values = Object.values(obj);
863
- if (values.length === 0)
864
- return undefined;
865
- const first_val = values[0];
866
- if (first_val && typeof first_val === `object`) {
867
- const efermi = first_val.efermi;
868
- if (typeof efermi === `number`)
869
- return efermi;
864
+ const first_val = Object.values(data)[0];
865
+ if (is_plain_object(first_val) && typeof first_val.efermi === `number`) {
866
+ return first_val.efermi;
870
867
  }
871
868
  return undefined;
872
869
  }
@@ -886,18 +883,16 @@ export function negative_fraction(values) {
886
883
  // Check if raw band structure input has electronic markers (efermi, kpoints, or electronic @class).
887
884
  // Must be called on raw input before normalization since these fields aren't preserved.
888
885
  function is_electronic_band_struct(bs) {
889
- if (!bs || typeof bs !== `object`)
886
+ if (!is_plain_object(bs))
890
887
  return false;
891
- const obj = bs;
892
888
  // Electronic band structures have efermi field
893
- if (`efermi` in obj && typeof obj.efermi === `number`)
889
+ if (typeof bs.efermi === `number`)
894
890
  return true;
895
891
  // Pymatgen electronic format uses kpoints (not qpoints)
896
- if (`kpoints` in obj && Array.isArray(obj.kpoints) && obj.kpoints.length > 0) {
892
+ if (Array.isArray(bs.kpoints) && bs.kpoints.length > 0)
897
893
  return true;
898
- }
899
894
  // Pymatgen @class: BandStructure* but not Phonon*
900
- const raw_class = obj[`@class`];
895
+ const raw_class = bs[`@class`];
901
896
  const py_class_name = typeof raw_class === `string` ? raw_class : ``;
902
897
  if (py_class_name.startsWith(`BandStructure`) && !py_class_name.includes(`Phonon`)) {
903
898
  return true;
@@ -952,7 +947,7 @@ export function compute_frequency_range(band_structs, doses, padding_factor = 0.
952
947
  }
953
948
  }
954
949
  }
955
- const dos_list = doses
950
+ const dos_list = doses && typeof doses === `object`
956
951
  ? `densities` in doses
957
952
  ? [normalize_dos(doses)]
958
953
  : Object.values(doses).map((dos) => normalize_dos(dos))
@@ -975,18 +970,19 @@ export function compute_frequency_range(band_structs, doses, padding_factor = 0.
975
970
  }
976
971
  if (!Number.isFinite(min_val) || !Number.isFinite(max_val))
977
972
  return undefined;
978
- const clamp_min = is_phonon &&
979
- min_val < 0 && // clamp phonon noise to 0
980
- negative_fraction(all_freqs) < IMAGINARY_MODE_NOISE_THRESHOLD;
981
- if (clamp_min)
973
+ // clamp phonon noise to 0
974
+ if (is_phonon &&
975
+ min_val < 0 &&
976
+ negative_fraction(all_freqs) < IMAGINARY_MODE_NOISE_THRESHOLD) {
982
977
  min_val = 0;
978
+ }
983
979
  // Calculate padding from (possibly clamped) range for consistency with Bands.svelte
984
980
  const padding = (max_val - min_val) * padding_factor;
985
981
  return [min_val === 0 ? 0 : min_val - padding, max_val + padding];
986
982
  }
987
983
  // Parse axis label: "Frequency (THz)" → { name: "Frequency", unit: "THz" }
988
984
  function parse_axis_label(label) {
989
- const match = /^(.+?)\s*\(([^)]+)\)$/.exec(label);
985
+ const match = /^(?<name>.+?)\s*\((?<unit>[^)]+)\)$/.exec(label);
990
986
  return match ? { name: match[1], unit: match[2] } : { name: label };
991
987
  }
992
988
  const format_tooltip_line = (name, value, unit) => `${name}: ${value}${unit ? ` ${unit}` : ``}`;
@@ -1,6 +1,5 @@
1
1
  import type { ChemicalElement, ElementCategory } from './element/types';
2
2
  import { DEFAULT_CATEGORY_COLORS, default_element_colors } from './colors';
3
- import type { Tooltip } from './plot';
4
3
  import { type ThemeMode, type ThemeType } from './theme';
5
4
  export declare const selected: {
6
5
  category: ElementCategory | null;
@@ -12,12 +11,6 @@ export declare const colors: {
12
11
  category: typeof DEFAULT_CATEGORY_COLORS;
13
12
  element: typeof default_element_colors;
14
13
  };
15
- export declare const tooltip: Tooltip;
16
- export declare const periodic_table_state: {
17
- show_bonding_info: boolean;
18
- show_oxidation_state: boolean;
19
- highlighted_elements: string[];
20
- };
21
14
  export declare const theme_state: {
22
15
  mode: ThemeMode;
23
16
  system_mode: ThemeType;
@@ -1,6 +1,6 @@
1
1
  import { AUTO_THEME, COLOR_THEMES, THEME_TYPE } from './theme/index';
2
2
  import { DEFAULT_CATEGORY_COLORS, default_element_colors } from './colors';
3
- import { is_valid_theme_mode } from './theme';
3
+ import { get_theme_preference } from './theme';
4
4
  export const selected = $state({
5
5
  category: null,
6
6
  element: null,
@@ -11,29 +11,10 @@ export const colors = $state({
11
11
  category: { ...DEFAULT_CATEGORY_COLORS },
12
12
  element: { ...default_element_colors },
13
13
  });
14
- export const tooltip = $state({ show: false, x: 0, y: 0, title: ``, items: [] });
15
- export const periodic_table_state = $state({
16
- show_bonding_info: false,
17
- show_oxidation_state: false,
18
- highlighted_elements: [],
19
- });
20
- // Theme state with safe initialization
21
- let initial_theme_mode = AUTO_THEME;
22
- let initial_system_mode = COLOR_THEMES.light;
23
- // Safe theme initialization for test environments
24
- try {
25
- if (typeof window !== `undefined` && globalThis.localStorage) {
26
- const saved_theme = localStorage.getItem(`matterviz-theme`) ?? ``;
27
- initial_theme_mode = is_valid_theme_mode(saved_theme) ? saved_theme : AUTO_THEME;
28
- }
29
- else {
30
- initial_theme_mode = AUTO_THEME;
31
- initial_system_mode = COLOR_THEMES.light;
32
- }
33
- }
34
- catch {
35
- // Fallback for test environments or when localStorage is not available
36
- }
14
+ // Theme state with safe initialization (get_theme_preference handles SSR +
15
+ // missing/invalid localStorage, falling back to AUTO_THEME)
16
+ const initial_theme_mode = get_theme_preference();
17
+ const initial_system_mode = COLOR_THEMES.light;
37
18
  export const theme_state = $state({
38
19
  mode: initial_theme_mode,
39
20
  system_mode: initial_system_mode,
@@ -4,7 +4,7 @@
4
4
  import { DEFAULTS } from '../settings'
5
5
  import { T } from '@threlte/core'
6
6
  import type { ComponentProps } from 'svelte'
7
- import { Euler, Quaternion, Vector3 } from 'three'
7
+ import { rotation_from_direction } from './geometry'
8
8
 
9
9
  let {
10
10
  position,
@@ -26,37 +26,22 @@
26
26
  } = $props()
27
27
 
28
28
  const mag = $derived(Math.hypot(...vector))
29
- const dir = $derived(
30
- mag > math.EPS ? math.scale(vector, 1 / mag) : ([0, 1, 0] as Vec3),
31
- )
29
+ const dir = $derived(mag > math.EPS ? math.scale(vector, 1 / mag) : ([0, 1, 0] as Vec3))
32
30
  const vec_len = $derived(mag * scale)
33
31
 
34
32
  const head_len = $derived(
35
33
  arrow_head_length < 0 ? vec_len * -arrow_head_length : arrow_head_length,
36
34
  )
37
35
  const shaft_len = $derived(Math.max(0, vec_len - head_len * 0.5))
38
- const shaft_r = $derived(
39
- shaft_radius < 0 ? shaft_len * -shaft_radius : shaft_radius,
40
- )
36
+ const shaft_r = $derived(shaft_radius < 0 ? shaft_len * -shaft_radius : shaft_radius)
41
37
  const head_r = $derived(
42
38
  arrow_head_radius < 0 ? shaft_len * -arrow_head_radius : arrow_head_radius,
43
39
  )
44
40
 
45
- const shaft_pos = $derived(
46
- math.add(position, math.scale(dir, shaft_len * 0.5)) as Vec3,
47
- )
48
- const head_pos = $derived(
49
- math.add(position, math.scale(dir, shaft_len + head_len * 0.5)) as Vec3,
50
- )
41
+ const shaft_pos = $derived(math.add(position, math.scale(dir, shaft_len * 0.5)))
42
+ const head_pos = $derived(math.add(position, math.scale(dir, shaft_len + head_len * 0.5)))
51
43
 
52
- const rotation = $derived.by((): Vec3 => {
53
- if (mag < math.EPS) return [0, 0, 0]
54
- const quat = new Quaternion().setFromUnitVectors(
55
- new Vector3(0, 1, 0),
56
- new Vector3(...dir),
57
- )
58
- return new Euler().setFromQuaternion(quat).toArray().slice(0, 3) as Vec3
59
- })
44
+ const rotation = $derived(rotation_from_direction(vector))
60
45
  </script>
61
46
 
62
47
  {#if shaft_len > 0.01}
@@ -0,0 +1,160 @@
1
+ <script lang="ts">
2
+ // Instanced arrows (shaft cylinders + head cones) for per-site vector layers
3
+ // (forces, magnetic moments, ...). Replaces one <Arrow> component per site
4
+ // (2 meshes + 2 geometries + 2 materials each) with 2 draw calls per layer.
5
+ // Sizing math mirrors Arrow.svelte so the two render identically.
6
+ import type { Vec3 } from '../math'
7
+ import { EPS } from '../math'
8
+ import { T, useThrelte } from '@threlte/core'
9
+ import { untrack } from 'svelte'
10
+ import type { BufferGeometry } from 'three'
11
+ import {
12
+ Color,
13
+ ConeGeometry,
14
+ CylinderGeometry,
15
+ InstancedMesh,
16
+ Matrix4,
17
+ MeshStandardMaterial,
18
+ Quaternion,
19
+ Vector3,
20
+ } from 'three'
21
+
22
+ type ArrowInstance = {
23
+ position: Vec3
24
+ vector: Vec3
25
+ scale: number
26
+ color: string
27
+ }
28
+
29
+ let {
30
+ arrows,
31
+ shaft_radius,
32
+ arrow_head_radius,
33
+ arrow_head_length,
34
+ }: {
35
+ arrows: ArrowInstance[]
36
+ shaft_radius: number // negative = relative to shaft length
37
+ arrow_head_radius: number // negative = relative to shaft length
38
+ arrow_head_length: number // negative = relative to arrow length
39
+ } = $props()
40
+
41
+ const { invalidate } = useThrelte()
42
+
43
+ // Unit primitives scaled per instance: cylinder radius/length via (x=r, y=len, z=r)
44
+ const shaft_geometry = new CylinderGeometry(1, 1, 1, 12)
45
+ const head_geometry = new ConeGeometry(1, 1, 12)
46
+ const shaft_material = new MeshStandardMaterial()
47
+ const head_material = new MeshStandardMaterial()
48
+ $effect(() => () => {
49
+ shaft_geometry.dispose()
50
+ head_geometry.dispose()
51
+ shaft_material.dispose()
52
+ head_material.dispose()
53
+ })
54
+
55
+ const make_mesh = (
56
+ geometry: BufferGeometry,
57
+ material: MeshStandardMaterial,
58
+ count: number,
59
+ ): InstancedMesh => {
60
+ const mesh = new InstancedMesh(geometry, material, count)
61
+ mesh.frustumCulled = false
62
+ mesh.raycast = () => undefined // arrows are display-only
63
+ mesh.userData.per_instance_color = true
64
+ return mesh
65
+ }
66
+
67
+ // Recreate meshes only when the arrow count changes (fixed buffer capacity)
68
+ let shaft_mesh = $state.raw<InstancedMesh | null>(null)
69
+ let head_mesh = $state.raw<InstancedMesh | null>(null)
70
+ $effect(() => {
71
+ const count = arrows.length
72
+ const prev = untrack(() => shaft_mesh)
73
+ if (prev && prev.count === count) return
74
+ prev?.dispose()
75
+ untrack(() => head_mesh)?.dispose()
76
+ if (count === 0) {
77
+ shaft_mesh = null
78
+ head_mesh = null
79
+ return
80
+ }
81
+ shaft_mesh = make_mesh(shaft_geometry, shaft_material, count)
82
+ head_mesh = make_mesh(head_geometry, head_material, count)
83
+ })
84
+ // Unmount-only cleanup (a cleanup on the effect above would dispose meshes
85
+ // on every re-run, including runs that keep them; cleanups run untracked)
86
+ $effect(() => () => {
87
+ shaft_mesh?.dispose()
88
+ head_mesh?.dispose()
89
+ })
90
+
91
+ const up_axis = new Vector3(0, 1, 0)
92
+ const scratch_dir = new Vector3()
93
+ const scratch_quat = new Quaternion()
94
+ const scratch_pos = new Vector3()
95
+ const scratch_scale = new Vector3()
96
+ const scratch_matrix = new Matrix4()
97
+ const scratch_color = new Color()
98
+
99
+ $effect(() => {
100
+ const shafts = shaft_mesh
101
+ const heads = head_mesh
102
+ if (!shafts || !heads) return
103
+ const limit = Math.min(arrows.length, shafts.count)
104
+ for (let idx = 0; idx < limit; idx++) {
105
+ const { position, vector, scale, color } = arrows[idx]
106
+ const mag = Math.hypot(vector[0], vector[1], vector[2])
107
+ if (mag > EPS) {
108
+ scratch_dir.set(vector[0] / mag, vector[1] / mag, vector[2] / mag)
109
+ scratch_quat.setFromUnitVectors(up_axis, scratch_dir)
110
+ } else {
111
+ scratch_dir.set(0, 1, 0)
112
+ scratch_quat.identity()
113
+ }
114
+ const vec_len = mag * scale
115
+ const head_len = arrow_head_length < 0 ? vec_len * -arrow_head_length : arrow_head_length
116
+ const shaft_len = Math.max(0, vec_len - head_len * 0.5)
117
+ const shaft_r = shaft_radius < 0 ? shaft_len * -shaft_radius : shaft_radius
118
+ const head_r = arrow_head_radius < 0 ? shaft_len * -arrow_head_radius : arrow_head_radius
119
+
120
+ // Shafts shorter than Arrow.svelte's 0.01 render threshold collapse to zero scale
121
+ const draw_shaft = shaft_len > 0.01
122
+ scratch_pos.set(
123
+ position[0] + scratch_dir.x * shaft_len * 0.5,
124
+ position[1] + scratch_dir.y * shaft_len * 0.5,
125
+ position[2] + scratch_dir.z * shaft_len * 0.5,
126
+ )
127
+ scratch_scale.set(
128
+ draw_shaft ? shaft_r : 0,
129
+ draw_shaft ? shaft_len : 0,
130
+ draw_shaft ? shaft_r : 0,
131
+ )
132
+ shafts.setMatrixAt(idx, scratch_matrix.compose(scratch_pos, scratch_quat, scratch_scale))
133
+
134
+ const head_offset = shaft_len + head_len * 0.5
135
+ scratch_pos.set(
136
+ position[0] + scratch_dir.x * head_offset,
137
+ position[1] + scratch_dir.y * head_offset,
138
+ position[2] + scratch_dir.z * head_offset,
139
+ )
140
+ scratch_scale.set(head_r, head_len, head_r)
141
+ heads.setMatrixAt(idx, scratch_matrix.compose(scratch_pos, scratch_quat, scratch_scale))
142
+
143
+ scratch_color.set(color)
144
+ shafts.setColorAt(idx, scratch_color)
145
+ heads.setColorAt(idx, scratch_color)
146
+ }
147
+ for (const mesh of [shafts, heads]) {
148
+ mesh.instanceMatrix.needsUpdate = true
149
+ if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true
150
+ }
151
+ invalidate()
152
+ })
153
+ </script>
154
+
155
+ {#if shaft_mesh}
156
+ <T is={shaft_mesh} />
157
+ {/if}
158
+ {#if head_mesh}
159
+ <T is={head_mesh} />
160
+ {/if}
@@ -0,0 +1,16 @@
1
+ import type { Vec3 } from '../math';
2
+ type ArrowInstance = {
3
+ position: Vec3;
4
+ vector: Vec3;
5
+ scale: number;
6
+ color: string;
7
+ };
8
+ type $$ComponentProps = {
9
+ arrows: ArrowInstance[];
10
+ shaft_radius: number;
11
+ arrow_head_radius: number;
12
+ arrow_head_length: number;
13
+ };
14
+ declare const ArrowInstances: import("svelte").Component<$$ComponentProps, {}, "">;
15
+ type ArrowInstances = ReturnType<typeof ArrowInstances>;
16
+ export default ArrowInstances;