matterviz 0.3.2 → 0.3.4

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 (281) hide show
  1. package/dist/EmptyState.svelte +10 -2
  2. package/dist/FilePicker.svelte +123 -82
  3. package/dist/Icon.svelte +18 -12
  4. package/dist/MillerIndexInput.svelte +27 -21
  5. package/dist/api/optimade.js +6 -6
  6. package/dist/app.css +216 -207
  7. package/dist/brillouin/BrillouinZone.svelte +292 -149
  8. package/dist/brillouin/BrillouinZone.svelte.d.ts +1 -1
  9. package/dist/brillouin/BrillouinZoneControls.svelte +32 -5
  10. package/dist/brillouin/BrillouinZoneExportPane.svelte +69 -42
  11. package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +1 -1
  12. package/dist/brillouin/BrillouinZoneInfoPane.svelte +99 -68
  13. package/dist/brillouin/BrillouinZoneScene.svelte +275 -163
  14. package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +1 -1
  15. package/dist/brillouin/BrillouinZoneTooltip.svelte +17 -7
  16. package/dist/brillouin/compute.js +11 -6
  17. package/dist/chempot-diagram/ChemPotDiagram.svelte +162 -27
  18. package/dist/chempot-diagram/ChemPotDiagram2D.svelte +451 -281
  19. package/dist/chempot-diagram/ChemPotDiagram3D.svelte +2148 -1642
  20. package/dist/chempot-diagram/ChemPotScene3D.svelte +8 -5
  21. package/dist/chempot-diagram/async-compute.svelte.d.ts +3 -0
  22. package/dist/chempot-diagram/async-compute.svelte.js +77 -0
  23. package/dist/chempot-diagram/chempot-worker.d.ts +1 -0
  24. package/dist/chempot-diagram/chempot-worker.js +11 -0
  25. package/dist/chempot-diagram/color.js +1 -2
  26. package/dist/chempot-diagram/compute.d.ts +10 -0
  27. package/dist/chempot-diagram/compute.js +250 -88
  28. package/dist/chempot-diagram/index.d.ts +2 -1
  29. package/dist/chempot-diagram/index.js +2 -1
  30. package/dist/chempot-diagram/temperature.js +8 -9
  31. package/dist/chempot-diagram/types.d.ts +3 -0
  32. package/dist/chempot-diagram/types.js +1 -0
  33. package/dist/colors/index.d.ts +1 -1
  34. package/dist/colors/index.js +5 -3
  35. package/dist/composition/BarChart.svelte +128 -55
  36. package/dist/composition/BubbleChart.svelte +102 -49
  37. package/dist/composition/Composition.svelte +100 -79
  38. package/dist/composition/Formula.svelte +108 -62
  39. package/dist/composition/FormulaFilter.svelte +665 -537
  40. package/dist/composition/PieChart.svelte +183 -108
  41. package/dist/composition/format.d.ts +5 -0
  42. package/dist/composition/format.js +20 -3
  43. package/dist/composition/parse.js +14 -9
  44. package/dist/convex-hull/ConvexHull.svelte +93 -40
  45. package/dist/convex-hull/ConvexHull.svelte.d.ts +1 -1
  46. package/dist/convex-hull/ConvexHull2D.svelte +549 -360
  47. package/dist/convex-hull/ConvexHull2D.svelte.d.ts +1 -1
  48. package/dist/convex-hull/ConvexHull3D.svelte +1296 -827
  49. package/dist/convex-hull/ConvexHull3D.svelte.d.ts +1 -1
  50. package/dist/convex-hull/ConvexHull4D.svelte +1004 -688
  51. package/dist/convex-hull/ConvexHull4D.svelte.d.ts +1 -1
  52. package/dist/convex-hull/ConvexHullControls.svelte +115 -28
  53. package/dist/convex-hull/ConvexHullControls.svelte.d.ts +1 -1
  54. package/dist/convex-hull/ConvexHullInfoPane.svelte +29 -3
  55. package/dist/convex-hull/ConvexHullStats.svelte +425 -328
  56. package/dist/convex-hull/ConvexHullTooltip.svelte +40 -16
  57. package/dist/convex-hull/GasPressureControls.svelte +104 -61
  58. package/dist/convex-hull/StructurePopup.svelte +25 -4
  59. package/dist/convex-hull/TemperatureSlider.svelte +45 -25
  60. package/dist/convex-hull/barycentric-coords.js +13 -7
  61. package/dist/convex-hull/demo-temperature.js +8 -4
  62. package/dist/convex-hull/gas-thermodynamics.js +17 -12
  63. package/dist/convex-hull/helpers.d.ts +9 -0
  64. package/dist/convex-hull/helpers.js +77 -34
  65. package/dist/convex-hull/thermodynamics.js +61 -56
  66. package/dist/convex-hull/types.d.ts +9 -14
  67. package/dist/convex-hull/types.js +0 -17
  68. package/dist/coordination/CoordinationBarPlot.svelte +227 -154
  69. package/dist/element/BohrAtom.svelte +55 -12
  70. package/dist/element/ElementHeading.svelte +7 -2
  71. package/dist/element/ElementPhoto.svelte +15 -9
  72. package/dist/element/ElementStats.svelte +10 -4
  73. package/dist/element/ElementTile.svelte +137 -73
  74. package/dist/element/Nucleus.svelte +39 -11
  75. package/dist/element/data.js +1 -1
  76. package/dist/feedback/ClickFeedback.svelte +16 -5
  77. package/dist/feedback/DragOverlay.svelte +10 -2
  78. package/dist/feedback/Spinner.svelte +4 -2
  79. package/dist/feedback/StatusMessage.svelte +8 -2
  80. package/dist/fermi-surface/FermiSlice.svelte +118 -88
  81. package/dist/fermi-surface/FermiSurface.svelte +328 -187
  82. package/dist/fermi-surface/FermiSurface.svelte.d.ts +1 -1
  83. package/dist/fermi-surface/FermiSurfaceControls.svelte +113 -46
  84. package/dist/fermi-surface/FermiSurfaceControls.svelte.d.ts +1 -1
  85. package/dist/fermi-surface/FermiSurfaceScene.svelte +535 -342
  86. package/dist/fermi-surface/FermiSurfaceScene.svelte.d.ts +1 -1
  87. package/dist/fermi-surface/FermiSurfaceTooltip.svelte +14 -5
  88. package/dist/fermi-surface/compute.js +16 -20
  89. package/dist/fermi-surface/parse.js +24 -14
  90. package/dist/fermi-surface/symmetry.js +2 -7
  91. package/dist/fermi-surface/types.d.ts +3 -5
  92. package/dist/heatmap-matrix/HeatmapMatrix.svelte +1019 -765
  93. package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +1 -1
  94. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +76 -22
  95. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +2 -3
  96. package/dist/icons.js +47 -0
  97. package/dist/index.d.ts +2 -1
  98. package/dist/index.js +2 -1
  99. package/dist/io/decompress.js +1 -1
  100. package/dist/io/export.d.ts +3 -0
  101. package/dist/io/export.js +129 -143
  102. package/dist/io/is-binary.js +2 -3
  103. package/dist/io/url-drop.js +1 -2
  104. package/dist/isosurface/Isosurface.svelte +202 -148
  105. package/dist/isosurface/IsosurfaceControls.svelte +46 -28
  106. package/dist/isosurface/parse.js +34 -29
  107. package/dist/isosurface/slice.js +5 -10
  108. package/dist/isosurface/types.d.ts +2 -1
  109. package/dist/isosurface/types.js +61 -12
  110. package/dist/labels.js +11 -8
  111. package/dist/layout/FullscreenToggle.svelte +11 -2
  112. package/dist/layout/InfoCard.svelte +38 -6
  113. package/dist/layout/InfoTag.svelte +63 -32
  114. package/dist/layout/PropertyFilter.svelte +82 -37
  115. package/dist/layout/SettingsSection.svelte +85 -55
  116. package/dist/layout/SubpageGrid.svelte +10 -2
  117. package/dist/layout/json-tree/JsonNode.svelte +183 -138
  118. package/dist/layout/json-tree/JsonTree.svelte +499 -413
  119. package/dist/layout/json-tree/JsonValue.svelte +127 -99
  120. package/dist/layout/json-tree/utils.js +4 -2
  121. package/dist/marching-cubes.js +25 -2
  122. package/dist/math.d.ts +13 -17
  123. package/dist/math.js +133 -67
  124. package/dist/overlays/ContextMenu.svelte +65 -40
  125. package/dist/overlays/DraggablePane.svelte +211 -139
  126. package/dist/periodic-table/PeriodicTable.svelte +278 -145
  127. package/dist/periodic-table/PeriodicTableControls.svelte +178 -128
  128. package/dist/periodic-table/PropertySelect.svelte +25 -7
  129. package/dist/periodic-table/TableInset.svelte +8 -3
  130. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +446 -309
  131. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +1 -1
  132. package/dist/phase-diagram/PhaseDiagramControls.svelte +102 -43
  133. package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +1 -1
  134. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +63 -40
  135. package/dist/phase-diagram/PhaseDiagramExportPane.svelte +71 -28
  136. package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +1 -1
  137. package/dist/phase-diagram/PhaseDiagramTooltip.svelte +158 -101
  138. package/dist/phase-diagram/TdbInfoPanel.svelte +28 -4
  139. package/dist/phase-diagram/build-diagram.js +9 -9
  140. package/dist/phase-diagram/colors.js +1 -3
  141. package/dist/phase-diagram/parse.js +10 -9
  142. package/dist/phase-diagram/svg-to-diagram.js +53 -49
  143. package/dist/phase-diagram/utils.d.ts +1 -0
  144. package/dist/phase-diagram/utils.js +80 -25
  145. package/dist/plot/AxisLabel.svelte +28 -3
  146. package/dist/plot/BarPlot.svelte +1182 -734
  147. package/dist/plot/BarPlot.svelte.d.ts +2 -2
  148. package/dist/plot/BarPlotControls.svelte +31 -5
  149. package/dist/plot/BarPlotControls.svelte.d.ts +1 -1
  150. package/dist/plot/ColorBar.svelte +479 -329
  151. package/dist/plot/ColorScaleSelect.svelte +27 -6
  152. package/dist/plot/ElementScatter.svelte +36 -15
  153. package/dist/plot/FillArea.svelte +152 -95
  154. package/dist/plot/Histogram.svelte +934 -571
  155. package/dist/plot/Histogram.svelte.d.ts +1 -1
  156. package/dist/plot/HistogramControls.svelte +53 -9
  157. package/dist/plot/HistogramControls.svelte.d.ts +1 -1
  158. package/dist/plot/InteractiveAxisLabel.svelte +34 -11
  159. package/dist/plot/InteractiveAxisLabel.svelte.d.ts +1 -1
  160. package/dist/plot/Line.svelte +63 -28
  161. package/dist/plot/PlotControls.svelte +157 -114
  162. package/dist/plot/PlotControls.svelte.d.ts +1 -1
  163. package/dist/plot/PlotLegend.svelte +174 -91
  164. package/dist/plot/PlotTooltip.svelte +45 -6
  165. package/dist/plot/PortalSelect.svelte +175 -147
  166. package/dist/plot/ReferenceLine.svelte +76 -22
  167. package/dist/plot/ReferenceLine3D.svelte +132 -107
  168. package/dist/plot/ReferencePlane.svelte +146 -121
  169. package/dist/plot/ScatterPlot.svelte +1681 -1091
  170. package/dist/plot/ScatterPlot.svelte.d.ts +2 -2
  171. package/dist/plot/ScatterPlot3D.svelte +256 -131
  172. package/dist/plot/ScatterPlot3D.svelte.d.ts +2 -2
  173. package/dist/plot/ScatterPlot3DControls.svelte +113 -63
  174. package/dist/plot/ScatterPlot3DControls.svelte.d.ts +2 -1
  175. package/dist/plot/ScatterPlot3DScene.svelte +608 -403
  176. package/dist/plot/ScatterPlot3DScene.svelte.d.ts +2 -2
  177. package/dist/plot/ScatterPlotControls.svelte +65 -25
  178. package/dist/plot/ScatterPlotControls.svelte.d.ts +1 -1
  179. package/dist/plot/ScatterPoint.svelte +98 -26
  180. package/dist/plot/ScatterPoint.svelte.d.ts +1 -0
  181. package/dist/plot/SpacegroupBarPlot.svelte +142 -85
  182. package/dist/plot/Surface3D.svelte +159 -108
  183. package/dist/plot/ZeroLines.svelte +55 -3
  184. package/dist/plot/ZoomRect.svelte +4 -2
  185. package/dist/plot/axis-utils.js +1 -3
  186. package/dist/plot/data-cleaning.js +12 -28
  187. package/dist/plot/data-transform.js +2 -1
  188. package/dist/plot/fill-utils.js +2 -0
  189. package/dist/plot/layout.d.ts +4 -1
  190. package/dist/plot/layout.js +33 -14
  191. package/dist/plot/reference-line.d.ts +2 -2
  192. package/dist/plot/reference-line.js +7 -5
  193. package/dist/plot/scales.js +24 -36
  194. package/dist/plot/types.d.ts +11 -23
  195. package/dist/plot/types.js +6 -11
  196. package/dist/plot/utils/label-placement.d.ts +32 -15
  197. package/dist/plot/utils/label-placement.js +227 -66
  198. package/dist/plot/utils/series-visibility.js +2 -3
  199. package/dist/rdf/RdfPlot.svelte +143 -91
  200. package/dist/rdf/calc-rdf.js +4 -5
  201. package/dist/sanitize.d.ts +4 -0
  202. package/dist/sanitize.js +107 -0
  203. package/dist/settings.d.ts +18 -6
  204. package/dist/settings.js +46 -16
  205. package/dist/spectral/Bands.svelte +632 -453
  206. package/dist/spectral/BandsAndDos.svelte +90 -49
  207. package/dist/spectral/BrillouinBandsDos.svelte +151 -93
  208. package/dist/spectral/Dos.svelte +389 -258
  209. package/dist/spectral/helpers.js +55 -43
  210. package/dist/state.svelte.d.ts +1 -1
  211. package/dist/state.svelte.js +3 -2
  212. package/dist/structure/Arrow.svelte +59 -20
  213. package/dist/structure/AtomLegend.svelte +215 -134
  214. package/dist/structure/Bond.svelte +73 -47
  215. package/dist/structure/CanvasTooltip.svelte +10 -2
  216. package/dist/structure/CellSelect.svelte +72 -45
  217. package/dist/structure/Cylinder.svelte +33 -17
  218. package/dist/structure/Lattice.svelte +88 -33
  219. package/dist/structure/Structure.svelte +1063 -797
  220. package/dist/structure/Structure.svelte.d.ts +1 -1
  221. package/dist/structure/StructureControls.svelte +349 -118
  222. package/dist/structure/StructureExportPane.svelte +124 -89
  223. package/dist/structure/StructureExportPane.svelte.d.ts +1 -1
  224. package/dist/structure/StructureInfoPane.svelte +304 -237
  225. package/dist/structure/StructureScene.svelte +879 -443
  226. package/dist/structure/StructureScene.svelte.d.ts +15 -7
  227. package/dist/structure/atom-properties.js +8 -8
  228. package/dist/structure/bonding.js +6 -7
  229. package/dist/structure/export.js +14 -29
  230. package/dist/structure/ferrox-wasm.js +1 -1
  231. package/dist/structure/index.d.ts +13 -3
  232. package/dist/structure/index.js +83 -23
  233. package/dist/structure/measure.d.ts +2 -2
  234. package/dist/structure/measure.js +4 -44
  235. package/dist/structure/parse.js +113 -141
  236. package/dist/structure/partial-occupancy.js +7 -10
  237. package/dist/structure/pbc.d.ts +1 -0
  238. package/dist/structure/pbc.js +16 -6
  239. package/dist/structure/supercell.d.ts +2 -2
  240. package/dist/structure/supercell.js +12 -22
  241. package/dist/structure/validation.js +1 -2
  242. package/dist/symmetry/SymmetryStats.svelte +84 -41
  243. package/dist/symmetry/WyckoffTable.svelte +26 -6
  244. package/dist/symmetry/cell-transform.js +5 -3
  245. package/dist/symmetry/index.js +8 -7
  246. package/dist/symmetry/spacegroups.js +148 -148
  247. package/dist/table/HeatmapTable.svelte +790 -554
  248. package/dist/table/HeatmapTable.svelte.d.ts +1 -1
  249. package/dist/table/ToggleMenu.svelte +125 -92
  250. package/dist/table/index.js +2 -4
  251. package/dist/theme/ThemeControl.svelte +21 -12
  252. package/dist/time.js +4 -1
  253. package/dist/tooltip/TooltipContent.svelte +33 -8
  254. package/dist/trajectory/Trajectory.svelte +758 -558
  255. package/dist/trajectory/TrajectoryError.svelte +14 -3
  256. package/dist/trajectory/TrajectoryExportPane.svelte +137 -83
  257. package/dist/trajectory/TrajectoryInfoPane.svelte +272 -143
  258. package/dist/trajectory/extract.js +10 -26
  259. package/dist/trajectory/format-detect.js +5 -5
  260. package/dist/trajectory/frame-reader.d.ts +1 -1
  261. package/dist/trajectory/frame-reader.js +5 -12
  262. package/dist/trajectory/helpers.d.ts +0 -1
  263. package/dist/trajectory/helpers.js +2 -17
  264. package/dist/trajectory/index.js +14 -12
  265. package/dist/trajectory/parse/ase.js +5 -4
  266. package/dist/trajectory/parse/hdf5.js +26 -18
  267. package/dist/trajectory/parse/index.js +13 -18
  268. package/dist/trajectory/parse/lammps.js +17 -7
  269. package/dist/trajectory/parse/vasp.js +5 -2
  270. package/dist/trajectory/parse/xyz.js +8 -7
  271. package/dist/trajectory/plotting.js +13 -8
  272. package/dist/utils.d.ts +1 -0
  273. package/dist/utils.js +13 -0
  274. package/dist/xrd/XrdPlot.svelte +337 -247
  275. package/dist/xrd/broadening.js +14 -9
  276. package/dist/xrd/calc-xrd.js +12 -18
  277. package/dist/xrd/parse.d.ts +1 -1
  278. package/dist/xrd/parse.js +17 -17
  279. package/package.json +99 -103
  280. package/readme.md +1 -1
  281. /package/dist/theme/{themes.js → themes.mjs} +0 -0
@@ -1,116 +1,144 @@
1
- <script lang="ts">import { getContext, tick } from 'svelte';
2
- import { JSON_TREE_CONTEXT_KEY } from './types';
3
- import { format_preview, is_css_color, is_url, parse_edited_value, values_equal, } from './utils';
4
- let { value, value_type, path, } = $props();
5
- const ctx = getContext(JSON_TREE_CONTEXT_KEY);
6
- // Track if value just changed for animation
7
- let just_changed = $state(false);
8
- let change_timeout;
9
- // Expanded state for long strings
10
- let is_expanded = $state(false);
11
- // Extract max_string_length threshold for reuse
12
- let max_len = $derived(ctx?.settings.max_string_length ?? 200);
13
- let is_long_string = $derived(value_type === `string` && value.length > max_len);
14
- // Check for changes on mount and when value changes
15
- $effect(() => {
16
- if (!ctx?.settings.highlight_changes)
17
- return;
18
- const prev = ctx.previous_values.get(path);
1
+ <script lang="ts">
2
+ import { getContext, tick } from 'svelte'
3
+ import type { JsonTreeContext, JsonValueType } from './types'
4
+ import { JSON_TREE_CONTEXT_KEY } from './types'
5
+ import {
6
+ format_preview,
7
+ is_css_color,
8
+ is_url,
9
+ parse_edited_value,
10
+ values_equal,
11
+ } from './utils'
12
+
13
+ let {
14
+ value,
15
+ value_type,
16
+ path,
17
+ }: {
18
+ value: unknown
19
+ value_type: JsonValueType
20
+ path: string
21
+ } = $props()
22
+
23
+ const ctx = getContext<JsonTreeContext>(JSON_TREE_CONTEXT_KEY)
24
+
25
+ // Track if value just changed for animation
26
+ let just_changed = $state(false)
27
+ let change_timeout: ReturnType<typeof setTimeout> | undefined
28
+
29
+ // Expanded state for long strings
30
+ let is_expanded = $state(false)
31
+
32
+ // Extract max_string_length threshold for reuse
33
+ let max_len = $derived(ctx?.settings.max_string_length ?? 200)
34
+ let is_long_string = $derived(
35
+ value_type === `string` && (value as string).length > max_len,
36
+ )
37
+
38
+ // Check for changes on mount and when value changes
39
+ $effect(() => {
40
+ if (!ctx?.settings.highlight_changes) return
41
+
42
+ const prev = ctx.previous_values.get(path)
19
43
  if (prev !== undefined && !values_equal(prev, value)) {
20
- just_changed = true;
21
- if (change_timeout)
22
- clearTimeout(change_timeout);
23
- change_timeout = setTimeout(() => {
24
- just_changed = false;
25
- }, 1000);
44
+ just_changed = true
45
+ if (change_timeout) clearTimeout(change_timeout)
46
+ change_timeout = setTimeout(() => {
47
+ just_changed = false
48
+ }, 1000)
26
49
  }
27
- ctx.previous_values.set(path, value);
50
+ ctx.previous_values.set(path, value)
51
+
28
52
  return () => {
29
- if (change_timeout)
30
- clearTimeout(change_timeout);
31
- };
32
- });
33
- // Trimmed string for URL/color detection (avoids using raw whitespace in href/style)
34
- let trimmed_str = $derived(value_type === `string` ? value.trim() : ``);
35
- // Auto-detect URLs in string values
36
- let url_detected = $derived(value_type === `string` && is_url(trimmed_str));
37
- // Auto-detect CSS colors in string values
38
- let color_detected = $derived(value_type === `string` && is_css_color(trimmed_str) ? trimmed_str : null);
39
- // Handle click to copy (delayed to avoid firing on double-click-to-edit)
40
- let click_timer;
41
- $effect(() => () => {
42
- if (click_timer)
43
- clearTimeout(click_timer);
44
- });
45
- async function handle_click(event) {
46
- event.stopPropagation();
47
- if (!ctx)
48
- return;
53
+ if (change_timeout) clearTimeout(change_timeout)
54
+ }
55
+ })
56
+
57
+ // Trimmed string for URL/color detection (avoids using raw whitespace in href/style)
58
+ let trimmed_str = $derived(value_type === `string` ? (value as string).trim() : ``)
59
+
60
+ // Auto-detect URLs in string values
61
+ let url_detected = $derived(value_type === `string` && is_url(trimmed_str))
62
+
63
+ // Auto-detect CSS colors in string values
64
+ let color_detected = $derived(
65
+ value_type === `string` && is_css_color(trimmed_str) ? trimmed_str : null,
66
+ )
67
+
68
+ // Handle click to copy (delayed to avoid firing on double-click-to-edit)
69
+ let click_timer: ReturnType<typeof setTimeout> | undefined
70
+ $effect(() => () => {
71
+ if (click_timer) clearTimeout(click_timer)
72
+ })
73
+
74
+ async function handle_click(event: MouseEvent) {
75
+ event.stopPropagation()
76
+ if (!ctx) return
49
77
  // When editable, delay copy so double-click can cancel it
50
78
  if (ctx.settings.editable && ctx.onchange) {
51
- if (click_timer)
52
- clearTimeout(click_timer);
53
- const copy_pos = { clientX: event.clientX, clientY: event.clientY };
54
- click_timer = setTimeout(() => ctx.copy_value(path, value, copy_pos), 250);
79
+ if (click_timer) clearTimeout(click_timer)
80
+ const copy_pos = { clientX: event.clientX, clientY: event.clientY }
81
+ click_timer = setTimeout(() => ctx.copy_value(path, value, copy_pos), 250)
82
+ } else {
83
+ await ctx.copy_value(path, value, event)
55
84
  }
56
- else {
57
- await ctx.copy_value(path, value, event);
58
- }
59
- }
60
- // Format display value - strings use custom truncation, others use format_preview
61
- let display_value = $derived.by(() => {
62
- if (value_type === `circular`)
63
- return `[Circular]`;
85
+ }
86
+
87
+ // Format display value - strings use custom truncation, others use format_preview
88
+ let display_value = $derived.by(() => {
89
+ if (value_type === `circular`) return `[Circular]`
64
90
  if (value_type === `string`) {
65
- const str = value;
66
- return is_long_string && !is_expanded
67
- ? `"${str.slice(0, max_len)}..."`
68
- : `"${str}"`;
91
+ const str = value as string
92
+ return is_long_string && !is_expanded
93
+ ? `"${str.slice(0, max_len)}..."`
94
+ : `"${str}"`
69
95
  }
70
- return format_preview(value);
71
- });
72
- // Check if string is truncated
73
- let is_truncated = $derived(is_long_string && !is_expanded);
74
- // Toggle string expansion
75
- function toggle_expand(event) {
76
- event.stopPropagation();
77
- is_expanded = !is_expanded;
78
- }
79
- // === Inline Editing ===
80
- let editing = $state(false);
81
- let edit_text = $state(``);
82
- let edit_input = $state(null);
83
- function start_edit(event) {
84
- if (!ctx?.settings.editable || !ctx.onchange)
85
- return;
86
- event.stopPropagation();
96
+ return format_preview(value)
97
+ })
98
+
99
+ // Check if string is truncated
100
+ let is_truncated = $derived(is_long_string && !is_expanded)
101
+
102
+ // Toggle string expansion
103
+ function toggle_expand(event: MouseEvent) {
104
+ event.stopPropagation()
105
+ is_expanded = !is_expanded
106
+ }
107
+
108
+ // === Inline Editing ===
109
+ let editing = $state(false)
110
+ let edit_text = $state(``)
111
+ let edit_input = $state<HTMLInputElement | null>(null)
112
+
113
+ function start_edit(event: MouseEvent) {
114
+ if (!ctx?.settings.editable || !ctx.onchange) return
115
+ event.stopPropagation()
87
116
  // Cancel pending click-to-copy
88
- if (click_timer)
89
- clearTimeout(click_timer);
117
+ if (click_timer) clearTimeout(click_timer)
90
118
  // Pre-fill with raw value (strings without quotes)
91
- edit_text = value_type === `string` ? value : String(value);
92
- editing = true;
93
- tick().then(() => edit_input?.select());
94
- }
95
- function commit_edit() {
96
- if (!editing)
97
- return;
98
- editing = false;
99
- const new_value = parse_edited_value(edit_text);
119
+ edit_text = value_type === `string` ? (value as string) : String(value)
120
+ editing = true
121
+ tick().then(() => edit_input?.select())
122
+ }
123
+
124
+ function commit_edit() {
125
+ if (!editing) return
126
+ editing = false
127
+ const new_value = parse_edited_value(edit_text)
100
128
  if (!values_equal(new_value, value)) {
101
- ctx?.onchange?.(path, new_value, value);
129
+ ctx?.onchange?.(path, new_value, value)
102
130
  }
103
- }
104
- function handle_edit_keydown(event) {
131
+ }
132
+
133
+ function handle_edit_keydown(event: KeyboardEvent) {
105
134
  if (event.key === `Enter`) {
106
- event.preventDefault();
107
- commit_edit();
108
- }
109
- else if (event.key === `Escape`) {
110
- event.preventDefault();
111
- editing = false;
135
+ event.preventDefault()
136
+ commit_edit()
137
+ } else if (event.key === `Escape`) {
138
+ event.preventDefault()
139
+ editing = false
112
140
  }
113
- }
141
+ }
114
142
  </script>
115
143
 
116
144
  {#if editing}
@@ -540,8 +540,10 @@ export function compute_diff(old_val, new_val, current_path = ``, result = new M
540
540
  }
541
541
  // Both primitive: compare values (with NaN === NaN special case)
542
542
  if (is_primitive_type(old_type)) {
543
- const both_nan = typeof old_val === `number` && typeof new_val === `number` &&
544
- Number.isNaN(old_val) && Number.isNaN(new_val);
543
+ const both_nan = typeof old_val === `number` &&
544
+ typeof new_val === `number` &&
545
+ Number.isNaN(old_val) &&
546
+ Number.isNaN(new_val);
545
547
  if (!both_nan && old_val !== new_val) {
546
548
  result.set(current_path, {
547
549
  status: `changed`,
@@ -1,7 +1,30 @@
1
1
  // Edge table: for each cube configuration (256 cases), which edges are intersected
2
2
  // Each bit indicates whether that edge has an intersection
3
- // deno-fmt-ignore
4
- const EDGE_TABLE = [0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00, 0x190, 0x99, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c, 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90, 0x230, 0x339, 0x33, 0x13a, 0x636, 0x73f, 0x435, 0x53c, 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30, 0x3a0, 0x2a9, 0x1a3, 0xaa, 0x7a6, 0x6af, 0x5a5, 0x4ac, 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0, 0x460, 0x569, 0x663, 0x76a, 0x66, 0x16f, 0x265, 0x36c, 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60, 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff, 0x3f5, 0x2fc, 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0, 0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55, 0x15c, 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950, 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc, 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0, 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc, 0xcc, 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0, 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c, 0x15c, 0x55, 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650, 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc, 0x2fc, 0x3f5, 0xff, 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0, 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c, 0x36c, 0x265, 0x16f, 0x66, 0x76a, 0x663, 0x569, 0x460, 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac, 0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa, 0x1a3, 0x2a9, 0x3a0, 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c, 0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33, 0x339, 0x230, 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c, 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99, 0x190, 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c, 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0];
3
+ // oxfmt-ignore
4
+ const EDGE_TABLE = [
5
+ 0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a,
6
+ 0xd03, 0xe09, 0xf00, 0x190, 0x99, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c, 0x99c,
7
+ 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90, 0x230, 0x339, 0x33, 0x13a, 0x636,
8
+ 0x73f, 0x435, 0x53c, 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30, 0x3a0,
9
+ 0x2a9, 0x1a3, 0xaa, 0x7a6, 0x6af, 0x5a5, 0x4ac, 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa,
10
+ 0xea3, 0xda9, 0xca0, 0x460, 0x569, 0x663, 0x76a, 0x66, 0x16f, 0x265, 0x36c, 0xc6c,
11
+ 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60, 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6,
12
+ 0xff, 0x3f5, 0x2fc, 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0, 0x650,
13
+ 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55, 0x15c, 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a,
14
+ 0xb53, 0x859, 0x950, 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc, 0xfcc,
15
+ 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0, 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6,
16
+ 0xdcf, 0xec5, 0xfcc, 0xcc, 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0, 0x950,
17
+ 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c, 0x15c, 0x55, 0x35f, 0x256, 0x55a,
18
+ 0x453, 0x759, 0x650, 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc, 0x2fc,
19
+ 0x3f5, 0xff, 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0, 0xb60, 0xa69, 0x963, 0x86a, 0xf66,
20
+ 0xe6f, 0xd65, 0xc6c, 0x36c, 0x265, 0x16f, 0x66, 0x76a, 0x663, 0x569, 0x460, 0xca0,
21
+ 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac, 0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa,
22
+ 0x1a3, 0x2a9, 0x3a0, 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c, 0x53c,
23
+ 0x435, 0x73f, 0x636, 0x13a, 0x33, 0x339, 0x230, 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96,
24
+ 0xb9f, 0x895, 0x99c, 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99, 0x190, 0xf00,
25
+ 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c, 0x70c, 0x605, 0x50f, 0x406, 0x30a,
26
+ 0x203, 0x109, 0x0,
27
+ ];
5
28
  // Triangle table: for each cube configuration, list of edge triplets forming triangles
6
29
  // -1 marks the end of the triangle list for that configuration
7
30
  const TRI_TABLE = [
package/dist/math.d.ts CHANGED
@@ -2,17 +2,7 @@ import type { LatticeParams, Pbc } from './structure/index';
2
2
  export type Vec2 = [number, number];
3
3
  export type Vec3 = [number, number, number];
4
4
  export type Vec4 = [number, number, number, number];
5
- export type Vec9 = [
6
- number,
7
- number,
8
- number,
9
- number,
10
- number,
11
- number,
12
- number,
13
- number,
14
- number
15
- ];
5
+ export type Vec9 = [number, number, number, number, number, number, number, number, number];
16
6
  export type Matrix3x3 = [Vec3, Vec3, Vec3];
17
7
  export type Matrix4x4 = [Vec4, Vec4, Vec4, Vec4];
18
8
  export type NdVector = number[];
@@ -46,23 +36,29 @@ export declare function calc_lattice_params(matrix: Matrix3x3): LatticeParams &
46
36
  };
47
37
  export declare const scale: <T extends NdVector>(vec: T, factor: number) => T;
48
38
  export declare const euclidean_dist: (vec1: NdVector, vec2: NdVector) => number;
49
- export declare function pbc_dist(pos1: Vec3, // First position vector (Cartesian coordinates)
50
- pos2: Vec3, // Second position vector (Cartesian coordinates)
51
- lattice_matrix: Matrix3x3, // 3x3 lattice matrix where each row is a lattice vector
52
- lattice_inv?: Matrix3x3, // Optional pre-computed inverse matrix for optimization (since lattice is usually constant and repeatedly inverting matrix is expensive)
53
- pbc?: Pbc): number;
39
+ export declare function min_image_displacement(from: Vec3, to: Vec3, lattice_matrix: Matrix3x3, converters?: LatticeConverters, pbc?: Pbc): Vec3;
40
+ export declare function pbc_dist(pos1: Vec3, pos2: Vec3, lattice_matrix: Matrix3x3, converters?: LatticeConverters, pbc?: Pbc): number;
54
41
  export declare function matrix_inverse_3x3(matrix: Matrix3x3): Matrix3x3;
55
42
  export declare function mat3x3_vec3_multiply(matrix: Matrix3x3, vector: Vec3): Vec3;
56
43
  export declare function add<T extends NdVector>(...vecs: T[]): T;
57
44
  export declare function subtract<T extends NdVector>(vec1: T, vec2: T): T;
58
- export declare function dot(vec1: NdVector | NdVector[], vec2: NdVector | NdVector[]): number | number[] | number[][];
45
+ export declare function dot(vec1: NdVector, vec2: NdVector): number;
46
+ export declare function dot(vec1: NdVector[], vec2: NdVector): number[];
47
+ export declare function dot(vec1: NdVector[], vec2: NdVector[]): number[][];
59
48
  export declare function to_voigt(tensor: number[][]): number[];
60
49
  export declare function from_voigt(voigt: number[]): number[][];
61
50
  export declare function vec9_to_mat3x3(flat_array: number[]): number[][];
62
51
  export declare function tensor_to_flat_array(tensor: number[][]): number[];
63
52
  export declare const transpose_3x3_matrix: (matrix: Matrix3x3) => Matrix3x3;
53
+ export declare function scale_lattice_matrix(orig_matrix: Matrix3x3, scaling_factors: Vec3): Matrix3x3;
64
54
  export declare const create_frac_to_cart: (lattice: Matrix3x3) => (frac: Vec3) => Vec3;
65
55
  export declare const create_cart_to_frac: (lattice: Matrix3x3) => (cart: Vec3) => Vec3;
56
+ export type LatticeConverters = {
57
+ cart_to_frac: (v: Vec3) => Vec3;
58
+ frac_to_cart: (v: Vec3) => Vec3;
59
+ reciprocal_axis_norms: Vec3;
60
+ };
61
+ export declare const create_lattice_converters: (lattice: Matrix3x3) => LatticeConverters;
66
62
  export declare function cell_to_lattice_matrix(a: number, b: number, c: number, alpha: number, beta: number, gamma: number): Matrix3x3;
67
63
  export declare function det_3x3(matrix: Matrix3x3): number;
68
64
  export declare function get_coefficient_of_variation(values: number[]): number;