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,641 +1,840 @@
1
- <script lang="ts">import { normalize_show_controls } from '../controls';
2
- import EmptyState from '../EmptyState.svelte';
3
- import Spinner from '../feedback/Spinner.svelte';
4
- import Icon from '../Icon.svelte';
5
- import { handle_url_drop, load_from_url } from '../io';
6
- import { format_num, trajectory_property_config } from '../labels';
7
- import { toggle_fullscreen } from '../layout';
8
- import { Histogram, ScatterPlot } from '../plot';
9
- import { toggle_series_visibility } from '../plot/utils/series-visibility';
10
- import { DEFAULTS } from '../settings';
11
- import Structure from '../structure/Structure.svelte';
12
- import { scaleLinear } from 'd3-scale';
13
- import { untrack } from 'svelte';
14
- import { tooltip } from 'svelte-multiselect/attachments';
15
- import { full_data_extractor } from './extract';
16
- import { TrajectoryError, TrajectoryExportPane, TrajectoryInfoPane } from './index';
17
- import { create_frame_loader, get_unsupported_format_message, MAX_BIN_FILE_SIZE, MAX_TEXT_FILE_SIZE, parse_trajectory_async, } from './parse';
18
- import { generate_axis_labels, generate_plot_series, generate_streaming_plot_series, should_hide_plot, } from './plotting';
19
- let { trajectory = $bindable(), data_url, current_step_idx = $bindable(0), data_extractor = full_data_extractor, allow_file_drop = true, layout = `auto`, structure_props = {}, scatter_props = {}, histogram_props = {}, spinner_props = {}, trajectory_controls, error_snippet, show_controls, fullscreen_toggle = DEFAULTS.trajectory.fullscreen_toggle, auto_play = false, display_mode = $bindable(`structure+scatter`), step_labels = 5, visible_properties = $bindable(), ELEM_PROPERTY_LABELS, on_play, on_pause, on_step_change, on_end, on_loop, on_frame_rate_change, on_display_mode_change, on_fullscreen_change, on_file_load, on_error, fps_range = DEFAULTS.trajectory.fps_range, fps = $bindable(5), loading_options = {}, atom_type_mapping, plot_skimming = true, ...rest } = $props();
20
- let dragover = $state(false);
21
- let loading = $state(false);
22
- let error_msg = $state(null);
23
- let is_playing = $state(false);
24
- let play_interval = $state(undefined);
25
- // Ensure fps is within the allowed range
26
- $effect(() => {
1
+ <script lang="ts">
2
+ import type { ShowControlsProp } from '../controls'
3
+ import { normalize_show_controls } from '../controls'
4
+ import type { ElementSymbol } from '../element'
5
+ import EmptyState from '../EmptyState.svelte'
6
+ import Spinner from '../feedback/Spinner.svelte'
7
+ import Icon from '../Icon.svelte'
8
+ import { handle_url_drop, load_from_url } from '../io'
9
+ import { format_num, trajectory_property_config } from '../labels'
10
+ import { sanitize_html } from '../sanitize'
11
+ import { toggle_fullscreen } from '../layout'
12
+ import type { ControlsConfig, DataSeries, Orientation, Point } from '../plot'
13
+ import { Histogram, ScatterPlot } from '../plot'
14
+ import { toggle_series_visibility } from '../plot/utils/series-visibility'
15
+ import { DEFAULTS } from '../settings'
16
+ import Structure from '../structure/Structure.svelte'
17
+ import { scaleLinear } from 'd3-scale'
18
+ import type { ComponentProps, Snippet } from 'svelte'
19
+ import { untrack } from 'svelte'
20
+ import { tooltip } from 'svelte-multiselect/attachments'
21
+ import type { HTMLAttributes } from 'svelte/elements'
22
+ import { full_data_extractor } from './extract'
23
+ import type {
24
+ ParseProgress,
25
+ TrajectoryDataExtractor,
26
+ TrajectoryFrame,
27
+ TrajectoryType,
28
+ TrajHandlerData,
29
+ } from './index'
30
+ import { TrajectoryError, TrajectoryExportPane, TrajectoryInfoPane } from './index'
31
+ import type { AtomTypeMapping, LoadingOptions } from './parse'
32
+ import {
33
+ create_frame_loader,
34
+ get_unsupported_format_message,
35
+ MAX_BIN_FILE_SIZE,
36
+ MAX_TEXT_FILE_SIZE,
37
+ parse_trajectory_async,
38
+ } from './parse'
39
+ import {
40
+ generate_axis_labels,
41
+ generate_plot_series,
42
+ generate_streaming_plot_series,
43
+ should_hide_plot,
44
+ } from './plotting'
45
+
46
+ type EventHandlers = {
47
+ on_play?: (data: TrajHandlerData) => void
48
+ on_pause?: (data: TrajHandlerData) => void
49
+ on_step_change?: (data: TrajHandlerData) => void
50
+ on_end?: (data: TrajHandlerData) => void
51
+ on_loop?: (data: TrajHandlerData) => void
52
+ on_frame_rate_change?: (data: TrajHandlerData) => void
53
+ on_display_mode_change?: (data: TrajHandlerData) => void
54
+ on_fullscreen_change?: (data: TrajHandlerData) => void
55
+ on_file_load?: (data: TrajHandlerData) => void
56
+ on_error?: (data: TrajHandlerData) => void
57
+ }
58
+ type ControlsProps = {
59
+ trajectory: TrajectoryType
60
+ current_step_idx: number
61
+ total_frames: number
62
+ on_step_change: (idx: number) => void
63
+ }
64
+
65
+ let {
66
+ trajectory = $bindable(),
67
+ data_url,
68
+ current_step_idx = $bindable(0),
69
+ data_extractor = full_data_extractor,
70
+ allow_file_drop = true,
71
+ layout = `auto`,
72
+ structure_props = {},
73
+ scatter_props = {},
74
+ histogram_props = {},
75
+ spinner_props = {},
76
+ trajectory_controls,
77
+ error_snippet,
78
+ show_controls,
79
+ fullscreen_toggle = DEFAULTS.trajectory.fullscreen_toggle,
80
+ auto_play = false,
81
+ display_mode = $bindable(`structure+scatter`),
82
+ step_labels = 5,
83
+ visible_properties = $bindable(),
84
+ ELEM_PROPERTY_LABELS,
85
+ on_play,
86
+ on_pause,
87
+ on_step_change,
88
+ on_end,
89
+ on_loop,
90
+ on_frame_rate_change,
91
+ on_display_mode_change,
92
+ on_fullscreen_change,
93
+ on_file_load,
94
+ on_error,
95
+ fps_range = DEFAULTS.trajectory.fps_range,
96
+ fps = $bindable(5),
97
+ loading_options = {},
98
+ atom_type_mapping,
99
+ plot_skimming = true,
100
+ ...rest
101
+ }: EventHandlers & HTMLAttributes<HTMLDivElement> & {
102
+ // trajectory data - can be provided directly or loaded from file
103
+ trajectory?: TrajectoryType
104
+ // URL to load trajectory from (alternative to providing trajectory directly)
105
+ data_url?: string
106
+ // current step index being displayed
107
+ current_step_idx?: number
108
+ // custom function to extract plot data from trajectory frames
109
+ data_extractor?: TrajectoryDataExtractor
110
+
111
+ // file drop handlers
112
+ allow_file_drop?: boolean
113
+ // layout configuration - 'auto' (default) adapts to element size, 'horizontal'/'vertical' forces layout
114
+ layout?: `auto` | Orientation
115
+ // structure viewer props (passed to Structure component)
116
+ structure_props?: ComponentProps<typeof Structure>
117
+ // plot props (passed to ScatterPlot component)
118
+ scatter_props?: ComponentProps<typeof ScatterPlot>
119
+ // histogram props (passed to Histogram component, excluding series which is handled separately)
120
+ histogram_props?: Omit<ComponentProps<typeof Histogram>, `series`>
121
+ // spinner props (passed to Spinner component)
122
+ spinner_props?: ComponentProps<typeof Spinner>
123
+ // custom snippets for additional UI elements
124
+ trajectory_controls?: Snippet<[ControlsProps]>
125
+ // Custom error snippet for advanced error handling
126
+ error_snippet?: Snippet<[{ error_msg: string; on_dismiss: () => void }]>
127
+ // Controls visibility configuration.
128
+ // - 'always': controls always visible
129
+ // - 'hover': controls visible on component hover (default)
130
+ // - 'never': controls never visible
131
+ // - object: { mode, hidden, style } for fine-grained control
132
+ // Control names: 'filename', 'nav', 'step', 'fps', 'info-pane', 'export-pane', 'view-mode', 'fullscreen'
133
+ show_controls?: ShowControlsProp
134
+ // show/hide the fullscreen button
135
+ fullscreen_toggle?: Snippet<[{ fullscreen: boolean }]> | boolean
136
+ // automatically start playing when trajectory data is loaded
137
+ auto_play?: boolean
138
+ // display mode: 'structure+scatter' (default), 'structure' (only structure), 'scatter' (only scatter), 'histogram' (only histogram), 'structure+histogram' (structure with histogram)
139
+ display_mode?:
140
+ | `structure+scatter`
141
+ | `structure`
142
+ | `scatter`
143
+ | `histogram`
144
+ | `structure+histogram`
145
+ // step labels configuration for slider
146
+ // - positive number: number of evenly spaced ticks
147
+ // - negative number: spacing between ticks (e.g. -10 = every 10th step)
148
+ // - array: exact step indices to label
149
+ // - undefined: no labels
150
+ step_labels?: number | number[]
151
+ // visible properties - bindable array of property keys currently shown in the plot
152
+ // - controls which trajectory properties are plotted (e.g. ['energy', 'volume', 'force_max'])
153
+ // - bindable: reflects current visibility state and can be used for external control
154
+ // - if not provided, uses default visible properties (energy, force_max, stress_frobenius)
155
+ // - if specified properties don't exist in data, falls back to automatic selection
156
+ visible_properties?: string[]
157
+ // custom labels for trajectory properties - maps property keys to display labels
158
+ // - e.g. {energy: 'Total Energy', volume: 'Cell Volume', force_max: 'Max Force'}
159
+ // - merged with built-in trajectory_property_config
160
+ ELEM_PROPERTY_LABELS?: Record<string, string>
161
+ // units configuration - developers can override these (deprecated - use ELEM_PROPERTY_LABELS instead)
162
+ units?: {
163
+ energy?: string
164
+ energy_per_atom?: string
165
+ force_max?: string
166
+ force_norm?: string
167
+ stress_max?: string
168
+ volume?: string
169
+ density?: string
170
+ temperature?: string
171
+ pressure?: string
172
+ length?: string
173
+ a?: string
174
+ b?: string
175
+ c?: string
176
+ [key: string]: string | undefined
177
+ }
178
+ fps_range?: [number, number] // allowed FPS range [min_fps, max_fps]
179
+ fps?: number // frame rate for playback
180
+ // Loading options for large files
181
+ loading_options?: LoadingOptions
182
+ // Map LAMMPS atom types to element symbols (e.g. {1: 'Na', 2: 'Cl'})
183
+ atom_type_mapping?: AtomTypeMapping
184
+ // Disable plot skimming (mouse over plot doesn't update structure/step slider)
185
+ plot_skimming?: boolean
186
+ } = $props()
187
+
188
+ let dragover = $state(false)
189
+ let loading = $state(false)
190
+ let error_msg = $state<string | null>(null)
191
+ let is_playing = $state(false)
192
+ let play_interval: ReturnType<typeof setInterval> | undefined = $state(undefined)
193
+
194
+ // Ensure fps is within the allowed range
195
+ $effect(() => {
27
196
  if (fps < fps_range[0]) {
28
- fps = fps_range[0];
29
- }
30
- else if (fps > fps_range[1]) {
31
- fps = fps_range[1];
32
- }
33
- });
34
- let current_filename = $state(undefined);
35
- let current_file_path = $state(null);
36
- let file_size = $state(undefined);
37
- let file_object = $state(null);
38
- let wrapper = $state(undefined);
39
- let info_pane_open = $state(false);
40
- let parsing_progress = $state(null);
41
- let element_size = $state({ width: 0, height: 0 });
42
- let filename_copied = $state(false);
43
- let orig_data = $state(null);
44
- let controls_config = $derived(normalize_show_controls(show_controls));
45
- // Reactive layout based on element aspect ratio (for auto mode)
46
- let actual_layout = $derived.by(() => {
47
- if (layout === `horizontal` || layout === `vertical`)
48
- return layout;
197
+ fps = fps_range[0]
198
+ } else if (fps > fps_range[1]) {
199
+ fps = fps_range[1]
200
+ }
201
+ })
202
+ let current_filename = $state<string | undefined>(undefined)
203
+ let current_file_path = $state<string | null>(null)
204
+ let file_size = $state<number | undefined>(undefined)
205
+ let file_object = $state<File | null>(null)
206
+ let wrapper = $state<HTMLDivElement | undefined>(undefined)
207
+ let info_pane_open = $state(false)
208
+ let parsing_progress = $state<ParseProgress | null>(null)
209
+ let element_size = $state({ width: 0, height: 0 })
210
+ let filename_copied = $state(false)
211
+ let orig_data = $state<string | ArrayBuffer | null>(null)
212
+
213
+ let controls_config = $derived(normalize_show_controls(show_controls))
214
+
215
+ // Reactive layout based on element aspect ratio (for auto mode)
216
+ let actual_layout = $derived.by(() => {
217
+ if (layout === `horizontal` || layout === `vertical`) return layout
49
218
  // For auto layout, use element dimensions to determine orientation
50
219
  if (element_size.width > 0 && element_size.height > 0) {
51
- return element_size.width > element_size.height ? `horizontal` : `vertical`;
220
+ return element_size.width > element_size.height ? `horizontal` : `vertical`
52
221
  }
53
- return `horizontal`; // Fallback to horizontal if dimensions not available yet
54
- });
55
- // Get total frame count (supports both regular and indexed trajectories)
56
- let total_frames = $derived(trajectory?.total_frames || trajectory?.frames.length || 0);
57
- // Current frame - load on demand for indexed trajectories
58
- let current_frame = $state(null);
59
- // Auto-play when trajectory changes (handles both props and file loading)
60
- $effect(() => {
222
+ return `horizontal` // Fallback to horizontal if dimensions not available yet
223
+ })
224
+
225
+ // Get total frame count (supports both regular and indexed trajectories)
226
+ let total_frames = $derived(
227
+ trajectory?.total_frames || trajectory?.frames.length || 0,
228
+ )
229
+
230
+ // Current frame - load on demand for indexed trajectories
231
+ let current_frame = $state<TrajectoryFrame | null>(null)
232
+
233
+ // Auto-play when trajectory changes (handles both props and file loading)
234
+ $effect(() => {
61
235
  if (auto_play && trajectory && !untrack(() => is_playing) && total_frames > 1) {
62
- start_playback();
236
+ start_playback()
63
237
  }
64
- });
65
- // Update current frame when step changes
66
- $effect(() => {
238
+ })
239
+
240
+ // Update current frame when step changes
241
+ $effect(() => {
67
242
  if (trajectory && current_step_idx >= 0 && current_step_idx < total_frames) {
68
- if (trajectory.frame_loader) {
69
- // Load frame on demand (works for both indexed files and external streaming)
70
- load_frame_on_demand(current_step_idx);
71
- }
72
- else {
73
- // Use in-memory frame for regular trajectories
74
- current_frame = trajectory.frames[current_step_idx] || null;
75
- }
76
- }
77
- else {
78
- current_frame = null;
243
+ if (trajectory.frame_loader) {
244
+ // Load frame on demand (works for both indexed files and external streaming)
245
+ load_frame_on_demand(current_step_idx)
246
+ } else {
247
+ // Use in-memory frame for regular trajectories
248
+ current_frame = trajectory.frames[current_step_idx] || null
249
+ }
250
+ } else {
251
+ current_frame = null
79
252
  }
80
- });
81
- // Load frame on demand - works for both indexed files and external streaming
82
- async function load_frame_on_demand(frame_idx) {
83
- if (!trajectory?.frame_loader)
84
- return;
253
+ })
254
+
255
+ // Load frame on demand - works for both indexed files and external streaming
256
+ async function load_frame_on_demand(frame_idx: number) {
257
+ if (!trajectory?.frame_loader) return
258
+
85
259
  try {
86
- const frame = await trajectory.frame_loader.load_frame(orig_data || ``, // Use original_data for indexed files, empty string for external streaming
87
- frame_idx);
88
- current_frame = frame;
89
- }
90
- catch (error) {
91
- console.error(`Failed to load frame ${frame_idx}:`, error);
92
- current_frame = null;
93
- on_error?.({
94
- error_msg: `Failed to load frame ${frame_idx}: ${error}`,
95
- filename: current_filename,
96
- file_size,
97
- step_idx: frame_idx,
98
- frame_count: total_frames,
99
- });
260
+ const frame = await trajectory.frame_loader.load_frame(
261
+ orig_data || ``, // Use original_data for indexed files, empty string for external streaming
262
+ frame_idx,
263
+ )
264
+ current_frame = frame
265
+ } catch (error) {
266
+ console.error(`Failed to load frame ${frame_idx}:`, error)
267
+ current_frame = null
268
+ on_error?.({
269
+ error_msg: `Failed to load frame ${frame_idx}: ${error}`,
270
+ filename: current_filename,
271
+ file_size,
272
+ step_idx: frame_idx,
273
+ frame_count: total_frames,
274
+ })
100
275
  }
101
- }
102
- // Current frame structure for display
103
- let current_structure = $derived(current_frame?.structure);
104
- // Track hidden elements (persists across frame changes)
105
- let hidden_elements = $state(new Set());
106
- let step_label_positions = $derived.by(() => {
107
- if (!step_labels || total_frames <= 1)
108
- return [];
276
+ }
277
+
278
+ // Current frame structure for display
279
+ let current_structure = $derived(current_frame?.structure)
280
+
281
+ // Track hidden elements (persists across frame changes)
282
+ let hidden_elements = $state(new Set<ElementSymbol>())
283
+
284
+ let step_label_positions = $derived.by((): number[] => {
285
+ if (!step_labels || total_frames <= 1) return []
286
+
109
287
  if (Array.isArray(step_labels)) {
110
- return step_labels.filter((idx) => idx >= 0 && idx < total_frames);
288
+ return step_labels.filter((idx) => idx >= 0 && idx < total_frames)
111
289
  }
290
+
112
291
  if (typeof step_labels === `number`) {
113
- if (step_labels > 0) {
114
- return scaleLinear().domain([0, total_frames - 1]).nice()
115
- .ticks(Math.min(step_labels, total_frames))
116
- .map((t) => Math.round(t))
117
- .filter((t, i, arr) => t >= 0 && t < total_frames && arr.indexOf(t) === i);
118
- }
119
- if (step_labels < 0) {
120
- const spacing = Math.abs(step_labels);
121
- const positions = Array.from({ length: Math.ceil(total_frames / spacing) }, (_, idx) => idx * spacing);
122
- return positions.at(-1) === total_frames - 1
123
- ? positions
124
- : [...positions, total_frames - 1];
125
- }
292
+ if (step_labels > 0) {
293
+ return scaleLinear().domain([0, total_frames - 1]).nice()
294
+ .ticks(Math.min(step_labels, total_frames))
295
+ .map((t) => Math.round(t))
296
+ .filter((t, i, arr) => t >= 0 && t < total_frames && arr.indexOf(t) === i)
297
+ }
298
+ if (step_labels < 0) {
299
+ const spacing = Math.abs(step_labels)
300
+ const positions = Array.from(
301
+ { length: Math.ceil(total_frames / spacing) },
302
+ (_, idx) => idx * spacing,
303
+ )
304
+ return positions.at(-1) === total_frames - 1
305
+ ? positions
306
+ : [...positions, total_frames - 1]
307
+ }
126
308
  }
127
- return [];
128
- });
129
- // Build extended property config with custom labels if provided
130
- let extended_config = $derived.by(() => {
131
- if (!ELEM_PROPERTY_LABELS)
132
- return trajectory_property_config;
133
- const custom_config = {};
309
+ return []
310
+ })
311
+
312
+ // Build extended property config with custom labels if provided
313
+ let extended_config = $derived.by(() => {
314
+ if (!ELEM_PROPERTY_LABELS) return trajectory_property_config
315
+
316
+ const custom_config: Record<string, { label: string; unit: string }> = {}
134
317
  for (const [key, label] of Object.entries(ELEM_PROPERTY_LABELS)) {
135
- const existing = trajectory_property_config[key] ||
136
- trajectory_property_config[key.toLowerCase()];
137
- custom_config[key] = { label, unit: existing?.unit || `` };
318
+ const existing = trajectory_property_config[key] ||
319
+ trajectory_property_config[key.toLowerCase()]
320
+ custom_config[key] = { label, unit: existing?.unit || `` }
138
321
  }
139
- return { ...trajectory_property_config, ...custom_config };
140
- });
141
- // Plot series state (not derived so we can update on legend toggle)
142
- let plot_series = $state([]);
143
- // Prevent circular updates when syncing legend toggles back to bindable visible_properties.
144
- let syncing_visible_properties = false;
145
- // Regenerate plot series when trajectory, config, or visible_properties change
146
- $effect(() => {
147
- if (syncing_visible_properties)
148
- return;
149
- const keys_set = visible_properties ? new Set(visible_properties) : undefined;
322
+ return { ...trajectory_property_config, ...custom_config }
323
+ })
324
+
325
+ // Plot series state (not derived so we can update on legend toggle)
326
+ let plot_series = $state<DataSeries[]>([])
327
+ // Prevent circular updates when syncing legend toggles back to bindable visible_properties.
328
+ let syncing_visible_properties = false
329
+
330
+ // Regenerate plot series when trajectory, config, or visible_properties change
331
+ $effect(() => {
332
+ if (syncing_visible_properties) return
333
+ const keys_set = visible_properties ? new Set(visible_properties) : undefined
334
+
150
335
  if (trajectory?.plot_metadata) {
151
- plot_series = generate_streaming_plot_series(trajectory.plot_metadata, {
152
- property_config: extended_config,
153
- default_visible_properties: keys_set,
154
- });
155
- }
156
- else if (trajectory) {
157
- plot_series = generate_plot_series(trajectory, data_extractor, {
158
- property_config: extended_config,
159
- default_visible_properties: keys_set,
160
- });
161
- }
162
- else {
163
- plot_series = [];
164
- }
165
- });
166
- // Update visible_properties binding when user toggles series visibility in legend
167
- $effect(() => {
168
- if (!plot_series.length)
169
- return;
336
+ plot_series = generate_streaming_plot_series(trajectory.plot_metadata, {
337
+ property_config: extended_config,
338
+ default_visible_properties: keys_set,
339
+ })
340
+ } else if (trajectory) {
341
+ plot_series = generate_plot_series(trajectory, data_extractor, {
342
+ property_config: extended_config,
343
+ default_visible_properties: keys_set,
344
+ })
345
+ } else {
346
+ plot_series = []
347
+ }
348
+ })
349
+
350
+ // Update visible_properties binding when user toggles series visibility in legend
351
+ $effect(() => {
352
+ if (!plot_series.length) return
353
+
170
354
  // Extract property keys from visible series metadata
171
355
  const visible_keys = plot_series.flatMap((srs) => {
172
- if (!srs.visible)
173
- return [];
174
- const metadata = Array.isArray(srs.metadata) ? srs.metadata[0] : srs.metadata;
175
- const key = metadata?.property_key;
176
- return key ? [key] : [];
177
- });
356
+ if (!srs.visible) return []
357
+ const metadata = Array.isArray(srs.metadata) ? srs.metadata[0] : srs.metadata
358
+ const key = metadata?.property_key
359
+ return key ? [key as string] : []
360
+ })
361
+
178
362
  // Only update if changed (use untrack to avoid circular dependency)
179
- const current = untrack(() => visible_properties) || [];
363
+ const current = untrack(() => visible_properties) || []
180
364
  const has_changed = visible_keys.length !== current.length ||
181
- !visible_keys.every((key, idx) => key === current[idx]);
365
+ !visible_keys.every((key, idx) => key === current[idx])
366
+
182
367
  if (has_changed) {
183
- syncing_visible_properties = true;
184
- visible_properties = visible_keys;
185
- queueMicrotask(() => (syncing_visible_properties = false));
368
+ syncing_visible_properties = true
369
+ visible_properties = visible_keys
370
+ queueMicrotask(() => (syncing_visible_properties = false))
186
371
  }
187
- });
188
- // Handler for legend toggle - updates plot_series state
189
- function handle_legend_toggle(series_idx) {
190
- plot_series = toggle_series_visibility(plot_series, series_idx);
191
- }
192
- let x_axis = $derived({
372
+ })
373
+
374
+ // Handler for legend toggle - updates plot_series state
375
+ function handle_legend_toggle(series_idx: number) {
376
+ plot_series = toggle_series_visibility(plot_series, series_idx)
377
+ }
378
+
379
+ let x_axis = $derived({
193
380
  label: `Step`,
194
381
  format: `.3~s`,
195
382
  ticks: step_label_positions,
196
- });
197
- // Generate axis labels based on first visible series on each axis
198
- let y_axis_labels = $derived(generate_axis_labels(plot_series));
199
- let y_axis = $derived({
383
+ })
384
+ // Generate axis labels based on first visible series on each axis
385
+ let y_axis_labels = $derived(generate_axis_labels(plot_series))
386
+ let y_axis = $derived({
200
387
  label: y_axis_labels.y1,
201
388
  format: `.2~s`,
202
389
  label_shift: { y: 10 },
203
- });
204
- let y2_axis = $derived({
390
+ })
391
+ let y2_axis = $derived({
205
392
  label: y_axis_labels.y2,
206
393
  format: `.2~s`,
207
394
  label_shift: { y: 80 },
208
- });
209
- // hide plot if all plotted values are constant (no variation)
210
- let show_plot = $derived(display_mode !== `structure` && !should_hide_plot(trajectory, plot_series));
211
- // Determine what to show based on display mode
212
- let show_structure = $derived(![`scatter`, `histogram`].includes(display_mode));
213
- let actual_show_plot = $derived(display_mode !== `structure` && show_plot);
214
- // Check if there are any Y2 series to determine padding
215
- let has_y2_series = $derived(plot_series.some((srs) => srs.y_axis === `y2` && srs.visible));
216
- // Step navigation functions
217
- function next_step() {
395
+ })
396
+
397
+ // hide plot if all plotted values are constant (no variation)
398
+ let show_plot = $derived(
399
+ display_mode !== `structure` && !should_hide_plot(trajectory, plot_series),
400
+ )
401
+
402
+ // Determine what to show based on display mode
403
+ let show_structure = $derived(![`scatter`, `histogram`].includes(display_mode))
404
+ let actual_show_plot = $derived(display_mode !== `structure` && show_plot)
405
+
406
+ // Check if there are any Y2 series to determine padding
407
+ let has_y2_series = $derived(
408
+ plot_series.some((srs) => srs.y_axis === `y2` && srs.visible),
409
+ )
410
+
411
+ // Step navigation functions
412
+ function next_step() {
218
413
  if (current_step_idx < total_frames - 1) {
219
- current_step_idx++;
220
- // Streaming frame loading handled by reactive effect
221
- if (trajectory) {
222
- on_step_change?.({
223
- trajectory,
224
- step_idx: current_step_idx,
225
- frame_count: total_frames,
226
- frame: current_frame || undefined,
227
- });
228
- }
414
+ current_step_idx++
415
+ // Streaming frame loading handled by reactive effect
416
+ if (trajectory) {
417
+ on_step_change?.({
418
+ trajectory,
419
+ step_idx: current_step_idx,
420
+ frame_count: total_frames,
421
+ frame: current_frame || undefined,
422
+ })
423
+ }
229
424
  }
230
- }
231
- function prev_step() {
425
+ }
426
+
427
+ function prev_step() {
232
428
  if (current_step_idx > 0) {
233
- current_step_idx--;
234
- // Streaming frame loading handled by reactive effect
235
- if (trajectory) {
236
- on_step_change?.({
237
- trajectory,
238
- step_idx: current_step_idx,
239
- frame_count: total_frames,
240
- frame: current_frame || undefined,
241
- });
242
- }
429
+ current_step_idx--
430
+ // Streaming frame loading handled by reactive effect
431
+ if (trajectory) {
432
+ on_step_change?.({
433
+ trajectory,
434
+ step_idx: current_step_idx,
435
+ frame_count: total_frames,
436
+ frame: current_frame || undefined,
437
+ })
438
+ }
243
439
  }
244
- }
245
- function go_to_step(idx) {
440
+ }
441
+
442
+ function go_to_step(idx: number) {
246
443
  if (idx >= 0 && idx < total_frames) {
247
- current_step_idx = idx;
248
- // Note: streaming frame loading is handled by reactive effect
249
- // Handle callbacks for both traditional and streaming modes
250
- if (trajectory) {
251
- on_step_change?.({
252
- trajectory,
253
- step_idx: current_step_idx,
254
- frame_count: total_frames,
255
- frame: current_frame || undefined,
256
- });
257
- }
444
+ current_step_idx = idx
445
+ // Note: streaming frame loading is handled by reactive effect
446
+ // Handle callbacks for both traditional and streaming modes
447
+ if (trajectory) {
448
+ on_step_change?.({
449
+ trajectory,
450
+ step_idx: current_step_idx,
451
+ frame_count: total_frames,
452
+ frame: current_frame || undefined,
453
+ })
454
+ }
258
455
  }
259
- }
260
- // Handle plot point clicks to jump to that step
261
- function handle_plot_change(data) {
456
+ }
457
+
458
+ // Handle plot point clicks to jump to that step
459
+ function handle_plot_change(data: (Point & { series: DataSeries }) | null) {
262
460
  if (data?.x !== undefined && typeof data.x === `number`) {
263
- go_to_step(Math.round(data.x));
461
+ go_to_step(Math.round(data.x))
264
462
  }
265
- }
266
- // Helper function to read file content
267
- async function read_file_content(file) {
463
+ }
464
+
465
+ // Helper function to read file content
466
+ async function read_file_content(file: File): Promise<string | ArrayBuffer> {
268
467
  return new Promise((resolve, reject) => {
269
- const reader = new FileReader();
270
- reader.onload = () => resolve(reader.result);
271
- reader.onerror = () => reject(new Error(`Failed to read file`));
272
- // Read as text for text-based formats, binary for others
273
- if (file.name.toLowerCase().match(/\.(xyz|json|extxyz|lammpstrj)$/)) {
274
- reader.readAsText(file);
275
- }
276
- else
277
- reader.readAsArrayBuffer(file);
278
- });
279
- }
280
- // Play/pause functionality
281
- function toggle_play() {
282
- if (is_playing)
283
- pause_playback();
284
- else
285
- start_playback();
286
- }
287
- function start_playback() {
288
- if (total_frames <= 1)
289
- return;
290
- is_playing = true;
468
+ const reader = new FileReader()
469
+ reader.onload = () => resolve(reader.result as string | ArrayBuffer)
470
+ reader.onerror = () => reject(new Error(`Failed to read file`))
471
+
472
+ // Read as text for text-based formats, binary for others
473
+ if (file.name.toLowerCase().match(/\.(xyz|json|extxyz|lammpstrj)$/)) {
474
+ reader.readAsText(file)
475
+ } else reader.readAsArrayBuffer(file)
476
+ })
477
+ }
478
+
479
+ // Play/pause functionality
480
+ function toggle_play() {
481
+ if (is_playing) pause_playback()
482
+ else start_playback()
483
+ }
484
+ function start_playback() {
485
+ if (total_frames <= 1) return
486
+ is_playing = true
291
487
  if (trajectory) {
292
- on_play?.({ trajectory, step_idx: current_step_idx, frame_count: total_frames });
488
+ on_play?.({ trajectory, step_idx: current_step_idx, frame_count: total_frames })
293
489
  }
294
- }
295
- function pause_playback() {
296
- is_playing = false;
490
+ }
491
+ function pause_playback() {
492
+ is_playing = false
297
493
  if (trajectory) {
298
- on_pause?.({
299
- trajectory: trajectory,
300
- step_idx: current_step_idx,
301
- frame_count: total_frames,
302
- });
494
+ on_pause?.({
495
+ trajectory: trajectory,
496
+ step_idx: current_step_idx,
497
+ frame_count: total_frames,
498
+ })
303
499
  }
304
- }
305
- $effect(() => {
500
+ }
501
+ $effect(() => { // Effect to manage playback interval
306
502
  // Only watch is_playing and frame_rate_ms, not play_interval itself
307
- const playing = is_playing;
308
- const rate_ms = 1000 / fps;
503
+ const playing = is_playing
504
+ const rate_ms = 1000 / fps
505
+
309
506
  if (playing) {
310
- // Clear existing interval if it exists - use untrack to avoid circular dependency
311
- const current_interval = untrack(() => play_interval);
312
- if (current_interval !== undefined)
313
- clearInterval(current_interval);
314
- // Create new interval with current frame rate
315
- play_interval = setInterval(() => {
316
- if (current_step_idx >= total_frames - 1) {
317
- if (trajectory) {
318
- on_end?.({
319
- trajectory,
320
- step_idx: current_step_idx,
321
- frame_count: total_frames,
322
- frame: current_frame || undefined,
323
- });
324
- }
325
- go_to_step(0); // Loop back to 1st step
326
- if (trajectory) {
327
- on_loop?.({ trajectory, frame_count: total_frames });
328
- }
329
- }
330
- else
331
- next_step();
332
- }, rate_ms);
333
- }
334
- else {
335
- // Clear interval when not playing - use untrack to avoid circular dependency
336
- const current_interval = untrack(() => play_interval);
337
- if (current_interval !== undefined) {
338
- clearInterval(current_interval);
339
- play_interval = undefined;
340
- }
507
+ // Clear existing interval if it exists - use untrack to avoid circular dependency
508
+ const current_interval = untrack(() => play_interval)
509
+ if (current_interval !== undefined) clearInterval(current_interval)
510
+
511
+ // Create new interval with current frame rate
512
+ play_interval = setInterval(() => {
513
+ if (current_step_idx >= total_frames - 1) {
514
+ if (trajectory) {
515
+ on_end?.({
516
+ trajectory,
517
+ step_idx: current_step_idx,
518
+ frame_count: total_frames,
519
+ frame: current_frame || undefined,
520
+ })
521
+ }
522
+ go_to_step(0) // Loop back to 1st step
523
+ if (trajectory) {
524
+ on_loop?.({ trajectory, frame_count: total_frames })
525
+ }
526
+ } else next_step()
527
+ }, rate_ms)
528
+ } else {
529
+ // Clear interval when not playing - use untrack to avoid circular dependency
530
+ const current_interval = untrack(() => play_interval)
531
+ if (current_interval !== undefined) {
532
+ clearInterval(current_interval)
533
+ play_interval = undefined
534
+ }
341
535
  }
342
- });
343
- // Cleanup interval on component destroy
344
- $effect(() => () => {
345
- if (play_interval !== undefined)
346
- clearInterval(play_interval);
347
- });
348
- // Handle internal file format drops
349
- async function handle_internal_file_drop(internal_data) {
536
+ })
537
+
538
+ // Cleanup interval on component destroy
539
+ $effect(() => () => {
540
+ if (play_interval !== undefined) clearInterval(play_interval)
541
+ })
542
+
543
+ // Handle internal file format drops
544
+ async function handle_internal_file_drop(internal_data: string): Promise<boolean> {
350
545
  try {
351
- const file_info = JSON.parse(internal_data);
352
- // Check if this is a binary file
353
- if (file_info.is_binary) {
354
- if (file_info.content instanceof ArrayBuffer) {
355
- await load_trajectory_data(file_info.content, file_info.name);
356
- }
357
- else if (file_info.content_url) {
358
- const response = await fetch(file_info.content_url);
359
- const array_buffer = await response.arrayBuffer();
360
- await load_trajectory_data(array_buffer, file_info.name);
361
- }
362
- else {
363
- console.warn(`Binary file without ArrayBuffer or blob URL:`, file_info.name);
364
- }
365
- }
366
- else {
367
- await load_trajectory_data(file_info.content, file_info.name);
546
+ const file_info = JSON.parse(internal_data)
547
+
548
+ // Check if this is a binary file
549
+ if (file_info.is_binary) {
550
+ if (file_info.content instanceof ArrayBuffer) {
551
+ await load_trajectory_data(file_info.content, file_info.name)
552
+ } else if (file_info.content_url) {
553
+ const response = await fetch(file_info.content_url)
554
+ const array_buffer = await response.arrayBuffer()
555
+ await load_trajectory_data(array_buffer, file_info.name)
556
+ } else {
557
+ console.warn(
558
+ `Binary file without ArrayBuffer or blob URL:`,
559
+ file_info.name,
560
+ )
368
561
  }
369
- return true;
370
- }
371
- catch (error) {
372
- console.warn(`Failed to parse internal file data:`, error);
373
- return false;
562
+ } else {
563
+ await load_trajectory_data(file_info.content, file_info.name)
564
+ }
565
+ return true
566
+ } catch (error) {
567
+ console.warn(`Failed to parse internal file data:`, error)
568
+ return false
374
569
  }
375
- }
376
- // Handle file drop events with optimized large file support
377
- async function handle_file_drop(event) {
378
- event.preventDefault();
379
- dragover = false;
380
- if (!allow_file_drop)
381
- return;
382
- loading = true;
570
+ }
571
+
572
+ // Handle file drop events with optimized large file support
573
+ async function handle_file_drop(event: DragEvent) {
574
+ event.preventDefault()
575
+ dragover = false
576
+ if (!allow_file_drop) return
577
+
578
+ loading = true
579
+
383
580
  try {
384
- // Check for our custom internal file format first
385
- const internal_data = event.dataTransfer?.getData(`application/x-matterviz-file`);
386
- if (internal_data) {
387
- const handled = await handle_internal_file_drop(internal_data);
388
- if (handled)
389
- return;
390
- }
391
- // Handle URL-based files (e.g. from FilePicker)
392
- const handled = await handle_url_drop(event, async (content, filename) => {
393
- current_filename = filename;
394
- file_size = content instanceof ArrayBuffer
395
- ? content.byteLength
396
- : new Blob([content]).size;
397
- await load_trajectory_data(content, filename);
398
- }).catch(() => false);
399
- if (handled) {
400
- return;
401
- }
402
- // Handle file system drops with optimized large file support
403
- const file = event.dataTransfer?.files[0];
404
- if (file) {
405
- file_size = file.size;
406
- current_file_path = file.webkitRelativePath || file.name;
407
- file_object = file;
408
- // Read file content directly
409
- const content = await read_file_content(file);
410
- await load_trajectory_data(content, file.name);
411
- }
412
- // Check for plain text data (fallback)
413
- const text_data = event.dataTransfer?.getData(`text/plain`);
414
- if (text_data) {
415
- file_size = new Blob([text_data]).size; // Calculate byte size of text data
416
- await load_trajectory_data(text_data, `trajectory.json`);
417
- return;
418
- }
419
- }
420
- catch (error) {
421
- console.error(`File drop failed:`, error);
422
- error_msg = `Failed to load file: ${error}`;
423
- on_error?.({ error_msg, filename: current_filename, file_size });
424
- }
425
- finally {
426
- loading = false;
581
+ // Check for our custom internal file format first
582
+ const internal_data = event.dataTransfer?.getData(
583
+ `application/x-matterviz-file`,
584
+ )
585
+ if (internal_data) {
586
+ const handled = await handle_internal_file_drop(internal_data)
587
+ if (handled) return
588
+ }
589
+
590
+ // Handle URL-based files (e.g. from FilePicker)
591
+ const handled = await handle_url_drop(event, async (content, filename) => {
592
+ current_filename = filename
593
+ file_size = content instanceof ArrayBuffer
594
+ ? content.byteLength
595
+ : new Blob([content]).size
596
+ await load_trajectory_data(content, filename)
597
+ }).catch(() => false)
598
+
599
+ if (handled) {
600
+ return
601
+ }
602
+
603
+ // Handle file system drops with optimized large file support
604
+ const file = event.dataTransfer?.files[0]
605
+ if (file) {
606
+ file_size = file.size
607
+ current_file_path = file.webkitRelativePath || file.name
608
+ file_object = file
609
+
610
+ // Read file content directly
611
+ const content = await read_file_content(file)
612
+ await load_trajectory_data(content, file.name)
613
+ }
614
+
615
+ // Check for plain text data (fallback)
616
+ const text_data = event.dataTransfer?.getData(`text/plain`)
617
+ if (text_data) {
618
+ file_size = new Blob([text_data]).size // Calculate byte size of text data
619
+ await load_trajectory_data(text_data, `trajectory.json`)
620
+ return
621
+ }
622
+ } catch (error) {
623
+ console.error(`File drop failed:`, error)
624
+ error_msg = `Failed to load file: ${error}`
625
+ on_error?.({ error_msg, filename: current_filename, file_size })
626
+ } finally {
627
+ loading = false
427
628
  }
428
- }
429
- $effect(() => {
629
+ }
630
+
631
+ $effect(() => { // Load trajectory from URL when data_url is provided
430
632
  if (data_url && !trajectory) {
431
- loading = true;
432
- error_msg = null;
433
- load_from_url(data_url, async (content, filename) => {
434
- current_filename = filename;
435
- file_size = content instanceof ArrayBuffer
436
- ? content.byteLength
437
- : new Blob([content]).size;
438
- await load_trajectory_data(content, filename);
439
- })
440
- .then(() => {
441
- loading = false;
633
+ loading = true
634
+ error_msg = null
635
+
636
+ load_from_url(data_url, async (content, filename) => {
637
+ current_filename = filename
638
+ file_size = content instanceof ArrayBuffer
639
+ ? content.byteLength
640
+ : new Blob([content]).size
641
+ await load_trajectory_data(content, filename)
642
+ })
643
+ .then(() => {
644
+ loading = false
442
645
  })
443
- .catch((err) => {
444
- console.error(`Failed to load trajectory from URL:`, err);
445
- error_msg = `Failed to load trajectory: ${err.message}`;
446
- current_filename = undefined;
447
- file_size = undefined;
448
- loading = false;
449
- on_error?.({
450
- error_msg,
451
- filename: current_filename || undefined,
452
- file_size: file_size || undefined,
453
- });
454
- });
455
- }
456
- });
457
- // Watch for frame rate changes
458
- $effect(() => {
459
- on_frame_rate_change?.({ trajectory, fps: fps });
460
- });
461
- async function load_trajectory_data(data, filename) {
462
- loading = true;
463
- error_msg = null;
464
- parsing_progress = null;
465
- // Reset previous loading state
466
- orig_data = null;
467
- try {
468
- const data_size = data instanceof ArrayBuffer ? data.byteLength : data.length;
469
- // Determine loading strategy based on file size
470
- const bin_file_threshold = loading_options.bin_file_threshold ??
471
- MAX_BIN_FILE_SIZE;
472
- const text_file_threshold = loading_options.text_file_threshold ??
473
- MAX_TEXT_FILE_SIZE;
474
- if ((data instanceof ArrayBuffer && data_size > bin_file_threshold) ||
475
- (typeof data === `string` && data_size > text_file_threshold)) { // Large files: Use indexed loading
476
- await load_with_indexing(data, filename);
477
- }
478
- else {
479
- // Small files: Use regular loading
480
- const merged_options = { ...loading_options, atom_type_mapping };
481
- trajectory = await parse_trajectory_async(data, filename, (progress) => {
482
- parsing_progress = progress;
483
- }, merged_options);
484
- }
485
- current_step_idx = 0;
486
- current_filename = filename;
487
- const file_size_bytes = data instanceof ArrayBuffer
488
- ? data.byteLength
489
- : new Blob([data]).size;
490
- on_file_load?.({
491
- trajectory,
492
- frame_count: trajectory?.frames.length ?? 0,
493
- total_atoms: trajectory?.frames[0]?.structure.sites.length ?? 0,
494
- filename,
495
- file_size: file_size_bytes,
496
- });
497
- }
498
- catch (err) {
499
- const unsupported_message = get_unsupported_format_message(filename, typeof data === `string` ? data : ``);
500
- error_msg = unsupported_message || `Failed to parse trajectory: ${err}`;
501
- current_filename = undefined;
502
- file_size = undefined;
503
- on_error?.({
646
+ .catch((err: Error) => {
647
+ console.error(`Failed to load trajectory from URL:`, err)
648
+ error_msg = `Failed to load trajectory: ${err.message}`
649
+ current_filename = undefined
650
+ file_size = undefined
651
+ loading = false
652
+ on_error?.({
504
653
  error_msg,
505
654
  filename: current_filename || undefined,
506
655
  file_size: file_size || undefined,
507
- });
508
- }
509
- finally {
510
- parsing_progress = null;
511
- loading = false;
656
+ })
657
+ })
512
658
  }
513
- }
514
- // Load using indexed parsing for large files
515
- async function load_with_indexing(data, filename) {
516
- try { // Use indexed parsing for efficient large file handling
517
- const merged_options = {
518
- use_indexing: true,
519
- ...loading_options,
520
- atom_type_mapping,
521
- };
659
+ })
660
+
661
+ // Watch for frame rate changes
662
+ $effect(() => {
663
+ on_frame_rate_change?.({ trajectory, fps: fps })
664
+ })
665
+
666
+ async function load_trajectory_data(data: string | ArrayBuffer, filename: string) {
667
+ loading = true
668
+ error_msg = null
669
+ parsing_progress = null
670
+
671
+ // Reset previous loading state
672
+ orig_data = null
673
+
674
+ try {
675
+ const data_size = data instanceof ArrayBuffer ? data.byteLength : data.length
676
+
677
+ // Determine loading strategy based on file size
678
+ const bin_file_threshold = loading_options.bin_file_threshold ??
679
+ MAX_BIN_FILE_SIZE
680
+ const text_file_threshold = loading_options.text_file_threshold ??
681
+ MAX_TEXT_FILE_SIZE
682
+ if (
683
+ (data instanceof ArrayBuffer && data_size > bin_file_threshold) ||
684
+ (typeof data === `string` && data_size > text_file_threshold)
685
+ ) { // Large files: Use indexed loading
686
+ await load_with_indexing(data, filename)
687
+ } else {
688
+ // Small files: Use regular loading
689
+ const merged_options = { ...loading_options, atom_type_mapping }
522
690
  trajectory = await parse_trajectory_async(data, filename, (progress) => {
523
- parsing_progress = progress;
524
- }, merged_options);
525
- // Attach frame loader and original data directly to trajectory for unified access
526
- orig_data = data;
527
- trajectory.frame_loader = create_frame_loader(filename);
691
+ parsing_progress = progress
692
+ }, merged_options)
693
+ }
694
+
695
+ current_step_idx = 0
696
+ current_filename = filename
697
+
698
+ const file_size_bytes = data instanceof ArrayBuffer
699
+ ? data.byteLength
700
+ : new Blob([data]).size
701
+ on_file_load?.({ // emit file load event
702
+ trajectory,
703
+ frame_count: trajectory?.frames.length ?? 0,
704
+ total_atoms: trajectory?.frames[0]?.structure.sites.length ?? 0,
705
+ filename,
706
+ file_size: file_size_bytes,
707
+ })
708
+ } catch (err) {
709
+ const unsupported_message = get_unsupported_format_message(
710
+ filename,
711
+ typeof data === `string` ? data : ``,
712
+ )
713
+ error_msg = unsupported_message || `Failed to parse trajectory: ${err}`
714
+ current_filename = undefined
715
+ file_size = undefined
716
+
717
+ on_error?.({ // emit error event
718
+ error_msg,
719
+ filename: current_filename || undefined,
720
+ file_size: file_size || undefined,
721
+ })
722
+ } finally {
723
+ parsing_progress = null
724
+ loading = false
528
725
  }
529
- catch (error) {
530
- console.error(`Indexed loading failed:`, error);
531
- throw error;
726
+ }
727
+
728
+ // Load using indexed parsing for large files
729
+ async function load_with_indexing(data: string | ArrayBuffer, filename: string) {
730
+ try { // Use indexed parsing for efficient large file handling
731
+ const merged_options = {
732
+ use_indexing: true,
733
+ ...loading_options,
734
+ atom_type_mapping,
735
+ }
736
+ trajectory = await parse_trajectory_async(data, filename, (progress) => {
737
+ parsing_progress = progress
738
+ }, merged_options)
739
+
740
+ // Attach frame loader and original data directly to trajectory for unified access
741
+ orig_data = data
742
+ trajectory.frame_loader = create_frame_loader(filename)
743
+ } catch (error) {
744
+ console.error(`Indexed loading failed:`, error)
745
+ throw error
532
746
  }
533
- }
534
- // Get current view mode label
535
- let current_view_label = $derived.by(() => {
536
- if (display_mode === `structure`)
537
- return `Structure Only`;
538
- if (display_mode === `scatter`)
539
- return `Scatter Only`;
540
- if (display_mode === `histogram`)
541
- return `Histogram Only`;
542
- if (display_mode === `structure+histogram`)
543
- return `Structure + Histogram`;
544
- if (display_mode === `structure+scatter`)
545
- return `Structure + Scatter`;
546
- throw new Error(`Unexpected display mode: ${display_mode}`);
547
- });
548
- let view_mode_dropdown_open = $state(false);
549
- // Handle click outside to close dropdowns
550
- function handle_click_outside(event) {
551
- const target = event.target;
747
+ }
748
+
749
+ // Get current view mode label
750
+ let current_view_label = $derived.by(() => {
751
+ if (display_mode === `structure`) return `Structure Only`
752
+ if (display_mode === `scatter`) return `Scatter Only`
753
+ if (display_mode === `histogram`) return `Histogram Only`
754
+ if (display_mode === `structure+histogram`) return `Structure + Histogram`
755
+ if (display_mode === `structure+scatter`) return `Structure + Scatter`
756
+ throw new Error(`Unexpected display mode: ${display_mode}`)
757
+ })
758
+
759
+ let view_mode_dropdown_open = $state(false)
760
+
761
+ // Handle click outside to close dropdowns
762
+ function handle_click_outside(event: MouseEvent) {
763
+ const target = event.target as Element
552
764
  if (view_mode_dropdown_open) {
553
- const dropdown_wrapper = target.closest(`.view-mode-dropdown-wrapper`);
554
- // Don't close if clicking on dropdown wrapper (contains both button and menu)
555
- if (!dropdown_wrapper)
556
- view_mode_dropdown_open = false;
765
+ const dropdown_wrapper = target.closest(`.view-mode-dropdown-wrapper`)
766
+ // Don't close if clicking on dropdown wrapper (contains both button and menu)
767
+ if (!dropdown_wrapper) view_mode_dropdown_open = false
557
768
  }
558
- }
559
- // Handle keyboard shortcuts
560
- function onkeydown(event) {
561
- if (!trajectory)
562
- return;
769
+ }
770
+
771
+ // Handle keyboard shortcuts
772
+ function onkeydown(event: KeyboardEvent) {
773
+ if (!trajectory) return
774
+
563
775
  // Don't handle shortcuts if user is typing in an input field (but allow if it's our step input and not focused)
564
- const target = event.target;
565
- const is_step_input = target.classList.contains(`step-input`);
776
+ const target = event.target as HTMLElement
777
+ const is_step_input = target.classList.contains(`step-input`)
566
778
  const is_input_focused = target.tagName === `INPUT` ||
567
- target.tagName === `TEXTAREA`;
779
+ target.tagName === `TEXTAREA`
780
+
568
781
  // Skip if typing in an input that's not our step input
569
- if (is_input_focused && !is_step_input)
570
- return;
782
+ if (is_input_focused && !is_step_input) return
783
+
571
784
  // If typing in step input, only handle certain navigation keys
572
785
  if (is_step_input && is_input_focused) {
573
- // Allow normal typing, but handle special navigation keys
574
- if ([`Escape`, `Enter`].includes(event.key))
575
- target.blur(); // Remove focus from input
576
- return;
786
+ // Allow normal typing, but handle special navigation keys
787
+ if ([`Escape`, `Enter`].includes(event.key)) target.blur() // Remove focus from input
788
+ return
577
789
  }
578
- const is_cmd_or_ctrl = event.metaKey || event.ctrlKey;
790
+
791
+ const is_cmd_or_ctrl = event.metaKey || event.ctrlKey
792
+
579
793
  // Navigation shortcuts
580
- if (event.key === ` `)
581
- toggle_play();
794
+ if (event.key === ` `) toggle_play()
582
795
  else if (event.key === `ArrowLeft`) {
583
- if (is_cmd_or_ctrl)
584
- go_to_step(0);
585
- else
586
- prev_step();
587
- }
588
- else if (event.key === `ArrowRight`) {
589
- if (is_cmd_or_ctrl)
590
- go_to_step(total_frames - 1);
591
- else
592
- next_step();
593
- }
594
- else if (event.key === `Home`)
595
- go_to_step(0);
596
- else if (event.key === `End`)
597
- go_to_step(total_frames - 1);
796
+ if (is_cmd_or_ctrl) go_to_step(0)
797
+ else prev_step()
798
+ } else if (event.key === `ArrowRight`) {
799
+ if (is_cmd_or_ctrl) go_to_step(total_frames - 1)
800
+ else next_step()
801
+ } else if (event.key === `Home`) go_to_step(0)
802
+ else if (event.key === `End`) go_to_step(total_frames - 1)
598
803
  else if (event.key === `j`) {
599
- go_to_step(Math.max(0, current_step_idx - 10));
600
- }
601
- else if (event.key === `l`) {
602
- go_to_step(Math.min(total_frames - 1, current_step_idx + 10));
603
- }
604
- else if (event.key === `PageUp`) {
605
- go_to_step(Math.max(0, current_step_idx - 25));
606
- }
607
- else if (event.key === `PageDown`) {
608
- go_to_step(Math.min(total_frames - 1, current_step_idx + 25));
804
+ go_to_step(Math.max(0, current_step_idx - 10))
805
+ } else if (event.key === `l`) {
806
+ go_to_step(Math.min(total_frames - 1, current_step_idx + 10))
807
+ } else if (event.key === `PageUp`) {
808
+ go_to_step(Math.max(0, current_step_idx - 25))
809
+ } else if (event.key === `PageDown`) {
810
+ go_to_step(Math.min(total_frames - 1, current_step_idx + 25))
609
811
  } // Interface shortcuts
610
- else if (event.key === `f` && fullscreen_toggle)
611
- toggle_fullscreen(wrapper);
812
+ else if (event.key === `f` && fullscreen_toggle) toggle_fullscreen(wrapper)
612
813
  // 'i' key handled by the TrajectoryInfoPane's built-in toggle
613
814
  // Playback speed shortcuts (only when playing)
614
815
  else if ((event.key === `=` || event.key === `+`) && is_playing) {
615
- fps = Math.min(fps_range[1], fps + 0.2);
616
- on_frame_rate_change?.({ trajectory, fps: fps });
617
- }
618
- else if (event.key === `-` && is_playing) {
619
- fps = Math.max(fps_range[0], fps - 0.2);
620
- on_frame_rate_change?.({ trajectory, fps: fps });
816
+ fps = Math.min(fps_range[1], fps + 0.2)
817
+ on_frame_rate_change?.({ trajectory, fps: fps })
818
+ } else if (event.key === `-` && is_playing) {
819
+ fps = Math.max(fps_range[0], fps - 0.2)
820
+ on_frame_rate_change?.({ trajectory, fps: fps })
621
821
  } // System shortcuts
622
822
  else if (event.key === `Escape`) {
623
- if (document.fullscreenElement)
624
- document.exitFullscreen();
625
- else if (view_mode_dropdown_open)
626
- view_mode_dropdown_open = false;
627
- // Escape key for info pane handled by DraggablePane
823
+ if (document.fullscreenElement) document.exitFullscreen()
824
+ else if (view_mode_dropdown_open) view_mode_dropdown_open = false
825
+ // Escape key for info pane handled by DraggablePane
628
826
  } // Number keys 0-9 - jump to percentage of trajectory
629
827
  else if (event.key >= `0` && event.key <= `9`) {
630
- go_to_step(Math.floor((parseInt(event.key, 10) / 10) * (total_frames - 1)));
828
+ go_to_step(Math.floor((parseInt(event.key, 10) / 10) * (total_frames - 1)))
631
829
  }
632
- }
633
- // Separate state variables for each pane to match component prop types
634
- let structure_info_open = $state(false);
635
- let structure_controls_open = $state(false);
636
- let scatter_controls = $state({ open: false });
637
- let trajectory_export_open = $state(false);
638
- let fullscreen = $state(false);
830
+ }
831
+
832
+ // Separate state variables for each pane to match component prop types
833
+ let structure_info_open = $state(false)
834
+ let structure_controls_open = $state(false)
835
+ let scatter_controls = $state<ControlsConfig>({ open: false })
836
+ let trajectory_export_open = $state(false)
837
+ let fullscreen = $state(false)
639
838
  </script>
640
839
 
641
840
  <svelte:document
@@ -981,7 +1180,7 @@ let fullscreen = $state(false);
981
1180
  {#snippet tooltip({ x, y, metadata, label })}
982
1181
  {@const formatted_y = typeof y === `number` ? format_num(y) : y}
983
1182
  Step: {Math.round(x)}<br />
984
- {@html metadata?.series_label || label || `Value`}: {formatted_y}
1183
+ {@html sanitize_html(metadata?.series_label || label || `Value`)}: {formatted_y}
985
1184
  {/snippet}
986
1185
  </ScatterPlot>
987
1186
  {:else if display_mode === `histogram` || display_mode === `structure+histogram`}
@@ -1084,7 +1283,8 @@ let fullscreen = $state(false);
1084
1283
  border: var(--traj-dragover-border, var(--dragover-border));
1085
1284
  }
1086
1285
  /* Mode: hover - controls visible on component hover */
1087
- &:hover .trajectory-controls.hover-visible {
1286
+ &:hover .trajectory-controls.hover-visible,
1287
+ &:focus-within .trajectory-controls.hover-visible {
1088
1288
  opacity: 1;
1089
1289
  pointer-events: auto;
1090
1290
  }