simview 3.2__py3-none-any.whl

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 (163) hide show
  1. simview/__init__.py +69 -0
  2. simview/__main__.py +174 -0
  3. simview/launcher.py +109 -0
  4. simview/live.py +204 -0
  5. simview/merge.py +593 -0
  6. simview/model.py +690 -0
  7. simview/py.typed +0 -0
  8. simview/scene.py +603 -0
  9. simview/server.py +739 -0
  10. simview/state.py +190 -0
  11. simview/static/css/controls.css +36 -0
  12. simview/static/js/SimView.js +601 -0
  13. simview/static/js/components/AnimationController.js +654 -0
  14. simview/static/js/components/BatchManager.js +198 -0
  15. simview/static/js/components/InteractionController.js +446 -0
  16. simview/static/js/components/InteractionControls.js +116 -0
  17. simview/static/js/components/Scene.js +166 -0
  18. simview/static/js/components/StateStore.js +188 -0
  19. simview/static/js/config.js +233 -0
  20. simview/static/js/main.js +3 -0
  21. simview/static/js/objects/Body.js +616 -0
  22. simview/static/js/objects/StaticObject.js +181 -0
  23. simview/static/js/objects/Terrain.js +514 -0
  24. simview/static/js/objects/utils.js +378 -0
  25. simview/static/js/ui/AnalysisPanel.js +233 -0
  26. simview/static/js/ui/BatchLegend.js +207 -0
  27. simview/static/js/ui/BodyStateWindow.js +521 -0
  28. simview/static/js/ui/Controls.js +586 -0
  29. simview/static/js/ui/ErrorMetrics.js +664 -0
  30. simview/static/js/ui/Legend.js +87 -0
  31. simview/static/js/ui/PlaybackControls.js +314 -0
  32. simview/static/js/ui/ScalarPlotter.js +575 -0
  33. simview/static/js/utils/blobCodec.js +73 -0
  34. simview/static/js/utils/bodyTransforms.js +151 -0
  35. simview/static/js/utils/csv.js +46 -0
  36. simview/static/js/utils/errorMath.js +69 -0
  37. simview/static/js/utils/injectStyles.js +16 -0
  38. simview/static/js/utils/interpolate.js +65 -0
  39. simview/static/js/utils/liveFollow.js +17 -0
  40. simview/static/js/utils/loadRecordingLibs.js +34 -0
  41. simview/static/js/utils/viewState.js +226 -0
  42. simview/static/lib/chroma-js-3.1.2/index.min.js +8 -0
  43. simview/static/lib/chroma-js-3.1.2/src/Color.js +49 -0
  44. simview/static/lib/chroma-js-3.1.2/src/chroma.js +10 -0
  45. simview/static/lib/chroma-js-3.1.2/src/colors/colorbrewer.js +81 -0
  46. simview/static/lib/chroma-js-3.1.2/src/colors/w3cx11.js +164 -0
  47. simview/static/lib/chroma-js-3.1.2/src/generator/average.js +88 -0
  48. simview/static/lib/chroma-js-3.1.2/src/generator/bezier.js +86 -0
  49. simview/static/lib/chroma-js-3.1.2/src/generator/blend.js +57 -0
  50. simview/static/lib/chroma-js-3.1.2/src/generator/cubehelix.js +87 -0
  51. simview/static/lib/chroma-js-3.1.2/src/generator/mix.js +19 -0
  52. simview/static/lib/chroma-js-3.1.2/src/generator/random.js +12 -0
  53. simview/static/lib/chroma-js-3.1.2/src/generator/scale.js +394 -0
  54. simview/static/lib/chroma-js-3.1.2/src/interpolator/_hsx.js +59 -0
  55. simview/static/lib/chroma-js-3.1.2/src/interpolator/hcg.js +12 -0
  56. simview/static/lib/chroma-js-3.1.2/src/interpolator/hsi.js +12 -0
  57. simview/static/lib/chroma-js-3.1.2/src/interpolator/hsl.js +12 -0
  58. simview/static/lib/chroma-js-3.1.2/src/interpolator/hsv.js +12 -0
  59. simview/static/lib/chroma-js-3.1.2/src/interpolator/index.js +1 -0
  60. simview/static/lib/chroma-js-3.1.2/src/interpolator/lab.js +19 -0
  61. simview/static/lib/chroma-js-3.1.2/src/interpolator/lch.js +13 -0
  62. simview/static/lib/chroma-js-3.1.2/src/interpolator/lrgb.js +19 -0
  63. simview/static/lib/chroma-js-3.1.2/src/interpolator/num.js +15 -0
  64. simview/static/lib/chroma-js-3.1.2/src/interpolator/oklab.js +19 -0
  65. simview/static/lib/chroma-js-3.1.2/src/interpolator/oklch.js +12 -0
  66. simview/static/lib/chroma-js-3.1.2/src/interpolator/rgb.js +18 -0
  67. simview/static/lib/chroma-js-3.1.2/src/io/cmyk/cmyk2rgb.js +16 -0
  68. simview/static/lib/chroma-js-3.1.2/src/io/cmyk/index.js +27 -0
  69. simview/static/lib/chroma-js-3.1.2/src/io/cmyk/rgb2cmyk.js +17 -0
  70. simview/static/lib/chroma-js-3.1.2/src/io/css/css2rgb.js +238 -0
  71. simview/static/lib/chroma-js-3.1.2/src/io/css/hsl2css.js +26 -0
  72. simview/static/lib/chroma-js-3.1.2/src/io/css/index.js +27 -0
  73. simview/static/lib/chroma-js-3.1.2/src/io/css/lab2css.js +24 -0
  74. simview/static/lib/chroma-js-3.1.2/src/io/css/lch2css.js +24 -0
  75. simview/static/lib/chroma-js-3.1.2/src/io/css/oklab2css.js +16 -0
  76. simview/static/lib/chroma-js-3.1.2/src/io/css/oklch2css.js +16 -0
  77. simview/static/lib/chroma-js-3.1.2/src/io/css/rgb2css.js +61 -0
  78. simview/static/lib/chroma-js-3.1.2/src/io/gl/index.js +22 -0
  79. simview/static/lib/chroma-js-3.1.2/src/io/hcg/hcg2rgb.js +55 -0
  80. simview/static/lib/chroma-js-3.1.2/src/io/hcg/index.js +27 -0
  81. simview/static/lib/chroma-js-3.1.2/src/io/hcg/rgb2hcg.js +23 -0
  82. simview/static/lib/chroma-js-3.1.2/src/io/hex/hex2rgb.js +56 -0
  83. simview/static/lib/chroma-js-3.1.2/src/io/hex/index.js +29 -0
  84. simview/static/lib/chroma-js-3.1.2/src/io/hex/rgb2hex.js +29 -0
  85. simview/static/lib/chroma-js-3.1.2/src/io/hsi/hsi2rgb.js +45 -0
  86. simview/static/lib/chroma-js-3.1.2/src/io/hsi/index.js +27 -0
  87. simview/static/lib/chroma-js-3.1.2/src/io/hsi/rgb2hsi.js +31 -0
  88. simview/static/lib/chroma-js-3.1.2/src/io/hsl/hsl2rgb.js +35 -0
  89. simview/static/lib/chroma-js-3.1.2/src/io/hsl/index.js +27 -0
  90. simview/static/lib/chroma-js-3.1.2/src/io/hsl/rgb2hsl.js +45 -0
  91. simview/static/lib/chroma-js-3.1.2/src/io/hsv/hsv2rgb.js +47 -0
  92. simview/static/lib/chroma-js-3.1.2/src/io/hsv/index.js +27 -0
  93. simview/static/lib/chroma-js-3.1.2/src/io/hsv/rgb2hsv.js +32 -0
  94. simview/static/lib/chroma-js-3.1.2/src/io/input.js +4 -0
  95. simview/static/lib/chroma-js-3.1.2/src/io/lab/index.js +28 -0
  96. simview/static/lib/chroma-js-3.1.2/src/io/lab/lab-constants.js +120 -0
  97. simview/static/lib/chroma-js-3.1.2/src/io/lab/lab2rgb.js +101 -0
  98. simview/static/lib/chroma-js-3.1.2/src/io/lab/rgb2lab.js +67 -0
  99. simview/static/lib/chroma-js-3.1.2/src/io/lch/hcl2rgb.js +9 -0
  100. simview/static/lib/chroma-js-3.1.2/src/io/lch/index.js +35 -0
  101. simview/static/lib/chroma-js-3.1.2/src/io/lch/lab2lch.js +12 -0
  102. simview/static/lib/chroma-js-3.1.2/src/io/lch/lch2lab.js +18 -0
  103. simview/static/lib/chroma-js-3.1.2/src/io/lch/lch2rgb.js +13 -0
  104. simview/static/lib/chroma-js-3.1.2/src/io/lch/rgb2lch.js +12 -0
  105. simview/static/lib/chroma-js-3.1.2/src/io/named/index.js +30 -0
  106. simview/static/lib/chroma-js-3.1.2/src/io/num/index.js +32 -0
  107. simview/static/lib/chroma-js-3.1.2/src/io/num/num2rgb.js +13 -0
  108. simview/static/lib/chroma-js-3.1.2/src/io/num/rgb2num.js +8 -0
  109. simview/static/lib/chroma-js-3.1.2/src/io/oklab/index.js +27 -0
  110. simview/static/lib/chroma-js-3.1.2/src/io/oklab/oklab2rgb.js +34 -0
  111. simview/static/lib/chroma-js-3.1.2/src/io/oklab/rgb2oklab.js +37 -0
  112. simview/static/lib/chroma-js-3.1.2/src/io/oklch/index.js +27 -0
  113. simview/static/lib/chroma-js-3.1.2/src/io/oklch/oklch2rgb.js +13 -0
  114. simview/static/lib/chroma-js-3.1.2/src/io/oklch/rgb2oklch.js +12 -0
  115. simview/static/lib/chroma-js-3.1.2/src/io/rgb/index.js +44 -0
  116. simview/static/lib/chroma-js-3.1.2/src/io/temp/index.js +22 -0
  117. simview/static/lib/chroma-js-3.1.2/src/io/temp/rgb2temperature.js +30 -0
  118. simview/static/lib/chroma-js-3.1.2/src/io/temp/temperature2rgb.js +39 -0
  119. simview/static/lib/chroma-js-3.1.2/src/ops/alpha.js +13 -0
  120. simview/static/lib/chroma-js-3.1.2/src/ops/clipped.js +5 -0
  121. simview/static/lib/chroma-js-3.1.2/src/ops/darken.js +17 -0
  122. simview/static/lib/chroma-js-3.1.2/src/ops/get.js +13 -0
  123. simview/static/lib/chroma-js-3.1.2/src/ops/luminance.js +54 -0
  124. simview/static/lib/chroma-js-3.1.2/src/ops/mix.js +10 -0
  125. simview/static/lib/chroma-js-3.1.2/src/ops/premultiply.js +12 -0
  126. simview/static/lib/chroma-js-3.1.2/src/ops/saturate.js +15 -0
  127. simview/static/lib/chroma-js-3.1.2/src/ops/set.js +43 -0
  128. simview/static/lib/chroma-js-3.1.2/src/ops/shade.js +11 -0
  129. simview/static/lib/chroma-js-3.1.2/src/utils/analyze.js +191 -0
  130. simview/static/lib/chroma-js-3.1.2/src/utils/clip_rgb.js +15 -0
  131. simview/static/lib/chroma-js-3.1.2/src/utils/contrast.js +12 -0
  132. simview/static/lib/chroma-js-3.1.2/src/utils/contrastAPCA.js +68 -0
  133. simview/static/lib/chroma-js-3.1.2/src/utils/delta-e.js +62 -0
  134. simview/static/lib/chroma-js-3.1.2/src/utils/distance.js +17 -0
  135. simview/static/lib/chroma-js-3.1.2/src/utils/index.js +27 -0
  136. simview/static/lib/chroma-js-3.1.2/src/utils/last.js +8 -0
  137. simview/static/lib/chroma-js-3.1.2/src/utils/limit.js +5 -0
  138. simview/static/lib/chroma-js-3.1.2/src/utils/multiply-matrices.js +36 -0
  139. simview/static/lib/chroma-js-3.1.2/src/utils/scales.js +15 -0
  140. simview/static/lib/chroma-js-3.1.2/src/utils/type.js +18 -0
  141. simview/static/lib/chroma-js-3.1.2/src/utils/unpack.js +17 -0
  142. simview/static/lib/chroma-js-3.1.2/src/utils/valid.js +11 -0
  143. simview/static/lib/chroma-js-3.1.2/src/version.js +2 -0
  144. simview/static/lib/download.js +132 -0
  145. simview/static/lib/js-colormaps.js +19335 -0
  146. simview/static/lib/tar.js +334 -0
  147. simview/static/lib/three-0.174.0/addons/controls/OrbitControls.js +1556 -0
  148. simview/static/lib/three-0.174.0/addons/libs/lil-gui.module.min.js +8 -0
  149. simview/static/lib/three-0.174.0/three.core.js +48830 -0
  150. simview/static/lib/three-0.174.0/three.module.js +17313 -0
  151. simview/static/lib/uPlot.esm.js +6140 -0
  152. simview/static/lib/uPlot.min.css +2 -0
  153. simview/static/textures/contacts/red-cross0.png +0 -0
  154. simview/static/textures/points/ball0.png +0 -0
  155. simview/static/textures/points/ball1.png +0 -0
  156. simview/templates/index.html +81 -0
  157. simview/utils.py +41 -0
  158. simview-3.2.dist-info/METADATA +552 -0
  159. simview-3.2.dist-info/RECORD +163 -0
  160. simview-3.2.dist-info/WHEEL +5 -0
  161. simview-3.2.dist-info/entry_points.txt +2 -0
  162. simview-3.2.dist-info/licenses/LICENSE +28 -0
  163. simview-3.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,87 @@
1
+ export class Legend {
2
+ constructor(app) {
3
+ this.app = app;
4
+ this.container = this.createContainer();
5
+ document.body.appendChild(this.container);
6
+ this.update();
7
+ }
8
+
9
+ createContainer() {
10
+ const container = document.createElement("div");
11
+ container.id = "terrain-legend";
12
+ container.style.position = "absolute";
13
+ container.style.bottom = "20px";
14
+ container.style.left = "20px";
15
+ container.style.backgroundColor = "rgba(0, 0, 0, 0.7)";
16
+ container.style.color = "white";
17
+ container.style.padding = "10px";
18
+ container.style.borderRadius = "5px";
19
+ container.style.fontFamily = "sans-serif";
20
+ container.style.fontSize = "12px";
21
+ container.style.pointerEvents = "none";
22
+ container.style.zIndex = "1000";
23
+ container.style.display = "flex";
24
+ container.style.flexDirection = "column";
25
+ container.style.minWidth = "150px";
26
+ container.style.border = "1px solid rgba(255, 255, 255, 0.2)";
27
+ return container;
28
+ }
29
+
30
+ update() {
31
+ if (!this.app.terrain) {
32
+ this.container.style.display = "none";
33
+ return;
34
+ }
35
+
36
+ this.container.style.display = "flex";
37
+ const mode = this.app.uiState.terrainColorMode || "height";
38
+ const cmapName = this.app.uiState.terrainColorMap || "viridis";
39
+
40
+ let minVal, maxVal, unit, title;
41
+
42
+ if (mode === "height") {
43
+ minVal = this.app.terrain.bounds.minZ;
44
+ maxVal = this.app.terrain.bounds.maxZ;
45
+ unit = "m";
46
+ title = "Height";
47
+ } else if (mode === "friction") {
48
+ minVal = this.app.terrain.bounds.minFriction ?? 0.0;
49
+ maxVal = this.app.terrain.bounds.maxFriction ?? 1.0;
50
+ unit = "";
51
+ title = "Friction";
52
+ } else if (mode === "stiffness") {
53
+ minVal = this.app.terrain.bounds.minStiffness ?? 100000.0;
54
+ maxVal = this.app.terrain.bounds.maxStiffness ?? 500000.0;
55
+ unit = "N/m";
56
+ title = "Stiffness";
57
+ }
58
+
59
+ const decimals = (mode === "stiffness" && maxVal > 1000) ? 0 : 2;
60
+ this.container.innerHTML = `
61
+ <div style="font-weight: bold; margin-bottom: 5px; text-align: center;">${title} ${unit ? `(${unit})` : ""}</div>
62
+ <div id="legend-gradient" style="height: 20px; width: 100%; margin-bottom: 5px; border: 1px solid white;"></div>
63
+ <div style="display: flex; justify-content: space-between;">
64
+ <span>${minVal.toFixed(decimals)}</span>
65
+ <span>${maxVal.toFixed(decimals)}</span>
66
+ </div>
67
+ `;
68
+
69
+ const gradientDiv = this.container.querySelector("#legend-gradient");
70
+ const callableColormap = this.app.terrain.getCallableFromColorMapName(cmapName);
71
+
72
+ // Generate CSS gradient
73
+ const steps = 10;
74
+ const colors = [];
75
+ for (let i = 0; i <= steps; i++) {
76
+ const color = callableColormap(i / steps);
77
+ colors.push(`rgb(${Math.round(color.r * 255)}, ${Math.round(color.g * 255)}, ${Math.round(color.b * 255)})`);
78
+ }
79
+ gradientDiv.style.background = `linear-gradient(to right, ${colors.join(", ")})`;
80
+ }
81
+
82
+ dispose() {
83
+ if (this.container && this.container.parentElement) {
84
+ this.container.parentElement.removeChild(this.container);
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,314 @@
1
+ import { FREQ_CONFIG } from "../config.js";
2
+ import { isMp4RecordingSupported } from "../components/AnimationController.js";
3
+
4
+ const buttonHeight = 25;
5
+ export class PlaybackControls {
6
+ constructor(animationController) {
7
+ this.animationController = animationController;
8
+ this.minRenderDelay = 1000 / FREQ_CONFIG.playbackControls;
9
+ this.lastRenderTime = Number.NEGATIVE_INFINITY;
10
+ this.container = document.createElement("div");
11
+ Object.assign(this.container.style, {
12
+ position: "absolute",
13
+ bottom: "20px",
14
+ left: "50%",
15
+ transform: "translateX(-50%)",
16
+ display: "flex",
17
+ flexDirection: "column",
18
+ alignItems: "center",
19
+ gap: "5px",
20
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
21
+ padding: "10px 20px",
22
+ borderRadius: "5px",
23
+ });
24
+
25
+ this.controlsRow = document.createElement("div");
26
+ Object.assign(this.controlsRow.style, {
27
+ display: "flex",
28
+ alignItems: "center",
29
+ flexDirection: "row",
30
+ gap: "15px",
31
+ });
32
+
33
+ // **Cache listener functions**
34
+ this.recordButtonClick = () => {
35
+ if (this.animationController.isRecording) {
36
+ this.animationController.stopRecording();
37
+ this.recordButton.textContent = "⚫ REC";
38
+ this.recordButton.style.backgroundColor = "#444";
39
+ } else {
40
+ this.animationController.startRecording();
41
+ this.recordButton.textContent = "⬛ STOP";
42
+ this.recordButton.style.backgroundColor = "#aa0000";
43
+ }
44
+ };
45
+
46
+ this.formatSelectChange = (e) => {
47
+ this.animationController.setRecordingFormat(e.target.value);
48
+ };
49
+
50
+ this.screenshotButtonClick = () => {
51
+ this.animationController.captureScreenshot();
52
+ };
53
+
54
+ this.playButtonClick = () => {
55
+ if (this.animationController.isPlaying) {
56
+ this.animationController.pause();
57
+ this.playButton.textContent = "Play";
58
+ } else {
59
+ this.animationController.play();
60
+ this.playButton.textContent = "Pause";
61
+ }
62
+ };
63
+
64
+ this.stepBackButtonClick = () => {
65
+ this.animationController.pause();
66
+ this.animationController.stepBackward();
67
+ this.playButton.textContent = "Play";
68
+ };
69
+
70
+ this.stepForwardButtonClick = () => {
71
+ this.animationController.pause();
72
+ this.animationController.stepForward();
73
+ this.playButton.textContent = "Play";
74
+ };
75
+
76
+ this.speedSelectChange = (e) => {
77
+ console.debug("Speed changed to", e.target.value);
78
+ this.animationController.setSpeed(parseFloat(e.target.value));
79
+ };
80
+
81
+ this.progressBarContainerClick = (event) => {
82
+ const rect = this.progressBarContainer.getBoundingClientRect();
83
+ const x = event.clientX - rect.left;
84
+ const progress = x / rect.width;
85
+ const targetTime = progress * this.animationController.getTotalTime();
86
+
87
+ if (event.altKey) {
88
+ this.animationController.pause();
89
+ this.playButton.textContent = "Play";
90
+ }
91
+ this.animationController.goToTime(targetTime);
92
+ };
93
+
94
+ this.keydownListener = (event) => {
95
+ const key = event.key;
96
+
97
+ // Handle arrow keys with Alt modifier for timeline stepping
98
+ if (event.altKey) {
99
+ if (key === "ArrowRight") {
100
+ event.stopPropagation();
101
+ event.preventDefault();
102
+ this.animationController.stepForward();
103
+ return;
104
+ }
105
+ if (key === "ArrowLeft") {
106
+ event.stopPropagation();
107
+ event.preventDefault();
108
+ this.animationController.stepBackward();
109
+ return;
110
+ }
111
+ }
112
+
113
+ // Other keys (only if no modifiers are pressed)
114
+ if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey)
115
+ return;
116
+
117
+ switch (key) {
118
+ case "r":
119
+ this.recordButton.click();
120
+ break;
121
+ case "s":
122
+ this.screenshotButton.click();
123
+ break;
124
+ case " ":
125
+ this.playButton.click();
126
+ event.target.blur();
127
+ break;
128
+ }
129
+ };
130
+
131
+ // **Create elements and attach cached listeners**
132
+ this.recordButton = this.#createButton(
133
+ "⚫ REC",
134
+ this.recordButtonClick,
135
+ "100px"
136
+ );
137
+
138
+ this.screenshotButton = this.#createButton(
139
+ "📷",
140
+ this.screenshotButtonClick,
141
+ "40px"
142
+ );
143
+ this.screenshotButton.title = "Screenshot (S)";
144
+
145
+ this.formatSelect = document.createElement("select");
146
+ // "mp4" is only offered when this browser's MediaRecorder can
147
+ // actually produce it (see isMp4RecordingSupported) -- webm is
148
+ // always available wherever MediaRecorder is, so it's the
149
+ // unconditional default/fallback.
150
+ const formats = isMp4RecordingSupported() ? ["webm", "mp4", "png"] : ["webm", "png"];
151
+ const formatLabels = { webm: "WEBM", mp4: "MP4", png: "PNG" };
152
+ formats.forEach((format) => {
153
+ const option = document.createElement("option");
154
+ option.value = format;
155
+ option.text = formatLabels[format];
156
+ this.formatSelect.appendChild(option);
157
+ });
158
+ Object.assign(this.formatSelect.style, {
159
+ width: "100px",
160
+ textAlign: "center",
161
+ height: buttonHeight + "px",
162
+ });
163
+ this.formatSelect.addEventListener("change", this.formatSelectChange);
164
+
165
+ this.playButton = this.#createButton("Play", this.playButtonClick, "70px");
166
+
167
+ this.stepBackButton = this.#createButton(
168
+ "←",
169
+ this.stepBackButtonClick,
170
+ "40px"
171
+ );
172
+
173
+ this.stepForwardButton = this.#createButton(
174
+ "→",
175
+ this.stepForwardButtonClick,
176
+ "40px"
177
+ );
178
+
179
+ this.speedSelect = document.createElement("select");
180
+ [0.1, 0.25, 0.5, 1, 2, 5].forEach((speed) => {
181
+ const option = document.createElement("option");
182
+ option.value = speed;
183
+ option.text = `${speed}x`;
184
+ if (speed === 1) option.selected = true;
185
+ this.speedSelect.appendChild(option);
186
+ });
187
+ Object.assign(this.speedSelect.style, {
188
+ width: "80px",
189
+ textAlign: "center",
190
+ height: buttonHeight + "px",
191
+ });
192
+ this.speedSelect.addEventListener("change", this.speedSelectChange);
193
+
194
+ this.frameCounter = document.createElement("span");
195
+ Object.assign(this.frameCounter.style, {
196
+ color: "white",
197
+ display: "flex",
198
+ alignItems: "center",
199
+ height: "30px",
200
+ marginLeft: "5px",
201
+ fontFamily: "monospace",
202
+ });
203
+
204
+ this.progressBarContainer = document.createElement("div");
205
+ Object.assign(this.progressBarContainer.style, {
206
+ width: "100%",
207
+ marginLeft: "15px",
208
+ marginRight: "15px",
209
+ display: "flex",
210
+ height: "8px",
211
+ backgroundColor: "#222",
212
+ borderRadius: "4px",
213
+ cursor: "pointer",
214
+ marginTop: "5px",
215
+ });
216
+
217
+ this.progressBar = document.createElement("div");
218
+ Object.assign(this.progressBar.style, {
219
+ width: "0%",
220
+ height: "100%",
221
+ backgroundColor: "#888",
222
+ borderRadius: "4px",
223
+ });
224
+ this.progressBarContainer.appendChild(this.progressBar);
225
+ this.progressBarContainer.addEventListener(
226
+ "click",
227
+ this.progressBarContainerClick
228
+ );
229
+
230
+ // Assemble controls row
231
+ [
232
+ this.recordButton,
233
+ this.formatSelect,
234
+ this.screenshotButton,
235
+ this.stepBackButton,
236
+ this.playButton,
237
+ this.stepForwardButton,
238
+ this.speedSelect,
239
+ this.frameCounter,
240
+ ].forEach((element) => this.controlsRow.appendChild(element));
241
+
242
+ this.container.appendChild(this.controlsRow);
243
+ this.container.appendChild(this.progressBarContainer);
244
+ document.body.appendChild(this.container);
245
+
246
+ // Attach document-level listener
247
+ document.addEventListener("keydown", this.keydownListener);
248
+
249
+ this.updateElements();
250
+ }
251
+
252
+ updateElements() {
253
+ const currentTime = this.animationController.getCurrentTime().toFixed(3);
254
+ const totalTime = this.animationController.getTotalTime().toFixed(3);
255
+ this.frameCounter.textContent = `time: ${currentTime} / ${totalTime}`;
256
+ const progress = currentTime / totalTime;
257
+ this.progressBar.style.width = `${(progress * 100).toFixed(1)}%`;
258
+ this.lastRenderTime = Number.NEGATIVE_INFINITY;
259
+ }
260
+
261
+ forceRedraw() {
262
+ this.updateElements();
263
+ this.lastRenderTime = Number.NEGATIVE_INFINITY;
264
+ }
265
+
266
+ animate(now) {
267
+ if (now - this.lastRenderTime < this.minRenderDelay) return;
268
+ this.updateElements();
269
+ this.lastRenderTime = now;
270
+ }
271
+
272
+ dispose() {
273
+ // Remove the container from the DOM
274
+ this.container.remove();
275
+
276
+ // Remove all event listeners using cached functions
277
+ this.recordButton.removeEventListener("click", this.recordButtonClick);
278
+ this.formatSelect.removeEventListener("change", this.formatSelectChange);
279
+ this.screenshotButton.removeEventListener("click", this.screenshotButtonClick);
280
+ this.playButton.removeEventListener("click", this.playButtonClick);
281
+ this.stepBackButton.removeEventListener("click", this.stepBackButtonClick);
282
+ this.stepForwardButton.removeEventListener(
283
+ "click",
284
+ this.stepForwardButtonClick
285
+ );
286
+ this.speedSelect.removeEventListener("change", this.speedSelectChange);
287
+ this.progressBarContainer.removeEventListener(
288
+ "click",
289
+ this.progressBarContainerClick
290
+ );
291
+ document.removeEventListener("keydown", this.keydownListener);
292
+ }
293
+
294
+ #createButton(text, onClick, width = "auto") {
295
+ const button = document.createElement("button");
296
+ Object.assign(button.style, {
297
+ padding: "5px 5px",
298
+ backgroundColor: "#444",
299
+ color: "white",
300
+ border: "none",
301
+ borderRadius: "4px",
302
+ cursor: "pointer",
303
+ width: width,
304
+ minWidth: "40px",
305
+ height: buttonHeight + "px",
306
+ display: "inline-flex",
307
+ justifyContent: "center",
308
+ alignItems: "center",
309
+ });
310
+ button.textContent = text;
311
+ button.addEventListener("click", onClick);
312
+ return button;
313
+ }
314
+ }