@2112-lab/central-plant 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +0 -0
  2. package/dist/bundle/index.js +14259 -0
  3. package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +353 -0
  4. package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1292 -0
  5. package/dist/cjs/node_modules/three/examples/jsm/controls/TransformControls.js +1543 -0
  6. package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4374 -0
  7. package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +465 -0
  8. package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +117 -0
  9. package/dist/cjs/src/ConnectionManager.js +114 -0
  10. package/dist/cjs/src/Pathfinder.js +88 -0
  11. package/dist/cjs/src/animationManager.js +121 -0
  12. package/dist/cjs/src/componentManager.js +151 -0
  13. package/dist/cjs/src/debugLogger.js +176 -0
  14. package/dist/cjs/src/disposalManager.js +185 -0
  15. package/dist/cjs/src/environmentManager.js +1015 -0
  16. package/dist/cjs/src/hotReloadManager.js +252 -0
  17. package/dist/cjs/src/index.js +126 -0
  18. package/dist/cjs/src/keyboardControlsManager.js +206 -0
  19. package/dist/cjs/src/modelPreloader.js +360 -0
  20. package/dist/cjs/src/nameUtils.js +106 -0
  21. package/dist/cjs/src/pathfindingManager.js +321 -0
  22. package/dist/cjs/src/performanceMonitor.js +718 -0
  23. package/dist/cjs/src/sceneExportManager.js +292 -0
  24. package/dist/cjs/src/sceneInitializationManager.js +540 -0
  25. package/dist/cjs/src/sceneOperationsManager.js +560 -0
  26. package/dist/cjs/src/textureConfig.js +195 -0
  27. package/dist/cjs/src/transformControlsManager.js +851 -0
  28. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +328 -0
  29. package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1287 -0
  30. package/dist/esm/node_modules/three/examples/jsm/controls/TransformControls.js +1537 -0
  31. package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4370 -0
  32. package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +461 -0
  33. package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +113 -0
  34. package/dist/esm/src/ConnectionManager.js +110 -0
  35. package/dist/esm/src/Pathfinder.js +84 -0
  36. package/dist/esm/src/animationManager.js +112 -0
  37. package/dist/esm/src/componentManager.js +123 -0
  38. package/dist/esm/src/debugLogger.js +167 -0
  39. package/dist/esm/src/disposalManager.js +155 -0
  40. package/dist/esm/src/environmentManager.js +989 -0
  41. package/dist/esm/src/hotReloadManager.js +244 -0
  42. package/dist/esm/src/index.js +117 -0
  43. package/dist/esm/src/keyboardControlsManager.js +196 -0
  44. package/dist/esm/src/modelPreloader.js +337 -0
  45. package/dist/esm/src/nameUtils.js +99 -0
  46. package/dist/esm/src/pathfindingManager.js +295 -0
  47. package/dist/esm/src/performanceMonitor.js +712 -0
  48. package/dist/esm/src/sceneExportManager.js +286 -0
  49. package/dist/esm/src/sceneInitializationManager.js +513 -0
  50. package/dist/esm/src/sceneOperationsManager.js +536 -0
  51. package/dist/esm/src/textureConfig.js +168 -0
  52. package/dist/esm/src/transformControlsManager.js +827 -0
  53. package/dist/index.d.ts +259 -0
  54. package/package.json +53 -0
@@ -0,0 +1,718 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
6
+ require('three');
7
+ var debugLogger = require('./debugLogger.js');
8
+
9
+ var PerformanceMonitor = /*#__PURE__*/function () {
10
+ function PerformanceMonitor() {
11
+ var renderer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
12
+ _rollupPluginBabelHelpers.classCallCheck(this, PerformanceMonitor);
13
+ this.renderer = renderer;
14
+ this.stats = {
15
+ fps: {
16
+ current: 0,
17
+ average: 0,
18
+ min: Infinity,
19
+ max: 0,
20
+ history: []
21
+ },
22
+ frameTime: {
23
+ current: 0,
24
+ average: 0,
25
+ min: Infinity,
26
+ max: 0,
27
+ history: []
28
+ },
29
+ memory: {
30
+ geometries: 0,
31
+ textures: 0,
32
+ programs: 0,
33
+ heapUsed: 0,
34
+ heapTotal: 0
35
+ },
36
+ drawCalls: {
37
+ current: 0,
38
+ average: 0,
39
+ triangles: 0,
40
+ points: 0,
41
+ lines: 0
42
+ },
43
+ gpu: {
44
+ memoryUsage: 0,
45
+ extensions: []
46
+ },
47
+ scene: {
48
+ objects: 0,
49
+ lights: 0,
50
+ meshes: 0,
51
+ materials: 0,
52
+ visible: 0
53
+ }
54
+ };
55
+ this.frameCount = 0;
56
+ this.historySize = 120; // 120 frames = ~2 seconds at 60fps
57
+ this.isRunning = false;
58
+ this.lastUpdateTime = 0;
59
+ this.warningThresholds = {
60
+ fps: 30,
61
+ frameTime: 16,
62
+ // ms (60fps)
63
+ drawCalls: 1000,
64
+ triangles: 1000000,
65
+ geometries: 1000,
66
+ textures: 100
67
+ };
68
+
69
+ // Event callbacks
70
+ this.callbacks = {
71
+ update: [],
72
+ warning: []
73
+ };
74
+
75
+ // Bind methods
76
+ this._update = this._update.bind(this);
77
+ }
78
+
79
+ /**
80
+ * Start the performance monitor
81
+ */
82
+ return _rollupPluginBabelHelpers.createClass(PerformanceMonitor, [{
83
+ key: "start",
84
+ value: function start() {
85
+ if (this.isRunning) return;
86
+ this.isRunning = true;
87
+ this.lastUpdateTime = performance.now();
88
+
89
+ // Get GPU info if available
90
+ this._getGPUInfo();
91
+
92
+ // Start update loop
93
+ requestAnimationFrame(this._update);
94
+ debugLogger.logger.info('Performance monitoring started');
95
+ }
96
+
97
+ /**
98
+ * Stop the performance monitor
99
+ */
100
+ }, {
101
+ key: "stop",
102
+ value: function stop() {
103
+ this.isRunning = false;
104
+ debugLogger.logger.info('Performance monitoring stopped');
105
+ }
106
+
107
+ /**
108
+ * Reset statistics
109
+ */
110
+ }, {
111
+ key: "reset",
112
+ value: function reset() {
113
+ // Reset FPS stats
114
+ this.stats.fps = {
115
+ current: 0,
116
+ average: 0,
117
+ min: Infinity,
118
+ max: 0,
119
+ history: []
120
+ };
121
+
122
+ // Reset frame time stats
123
+ this.stats.frameTime = {
124
+ current: 0,
125
+ average: 0,
126
+ min: Infinity,
127
+ max: 0,
128
+ history: []
129
+ };
130
+
131
+ // Reset frame count
132
+ this.frameCount = 0;
133
+ debugLogger.logger.info('Performance statistics reset');
134
+ }
135
+
136
+ /**
137
+ * Update method called every animation frame
138
+ */
139
+ }, {
140
+ key: "_update",
141
+ value: function _update() {
142
+ if (!this.isRunning) return;
143
+
144
+ // Calculate frame time
145
+ var now = performance.now();
146
+ var frameTime = now - this.lastUpdateTime;
147
+ this.lastUpdateTime = now;
148
+
149
+ // Calculate FPS
150
+ var fps = 1000 / frameTime;
151
+
152
+ // Update frame time stats
153
+ this._updateStat('frameTime', frameTime);
154
+
155
+ // Update FPS stats
156
+ this._updateStat('fps', fps);
157
+
158
+ // Get WebGL info if renderer is available
159
+ if (this.renderer) {
160
+ this._getWebGLInfo();
161
+ }
162
+
163
+ // Get memory info
164
+ this._getMemoryInfo();
165
+
166
+ // Increment frame count
167
+ this.frameCount++;
168
+
169
+ // Check for warnings
170
+ this._checkWarnings();
171
+
172
+ // Trigger update callbacks
173
+ this._triggerCallbacks('update', this.stats);
174
+
175
+ // Continue update loop
176
+ requestAnimationFrame(this._update);
177
+ }
178
+
179
+ /**
180
+ * Update statistics for a specific metric
181
+ */
182
+ }, {
183
+ key: "_updateStat",
184
+ value: function _updateStat(metric, value) {
185
+ if (!this.stats[metric]) return;
186
+ var stats = this.stats[metric];
187
+
188
+ // Update current value
189
+ stats.current = value;
190
+
191
+ // Update min and max
192
+ stats.min = Math.min(stats.min, value);
193
+ stats.max = Math.max(stats.max, value);
194
+
195
+ // Add to history
196
+ stats.history.push(value);
197
+
198
+ // Limit history size
199
+ if (stats.history.length > this.historySize) {
200
+ stats.history.shift();
201
+ }
202
+
203
+ // Calculate average
204
+ stats.average = stats.history.reduce(function (sum, val) {
205
+ return sum + val;
206
+ }, 0) / stats.history.length;
207
+ }
208
+
209
+ /**
210
+ * Get WebGL info from the renderer
211
+ */
212
+ }, {
213
+ key: "_getWebGLInfo",
214
+ value: function _getWebGLInfo() {
215
+ var _info$render, _info$render2, _info$memory, _info$memory2, _info$programs;
216
+ if (!this.renderer) return;
217
+ var info = this.renderer.info;
218
+
219
+ // Update draw calls
220
+ this.stats.drawCalls.current = ((_info$render = info.render) === null || _info$render === void 0 ? void 0 : _info$render.calls) || 0;
221
+ this.stats.drawCalls.triangles = ((_info$render2 = info.render) === null || _info$render2 === void 0 ? void 0 : _info$render2.triangles) || 0;
222
+
223
+ // Add draw calls to history and calculate average
224
+ if (!this.stats.drawCalls.history) {
225
+ this.stats.drawCalls.history = [];
226
+ }
227
+ this.stats.drawCalls.history.push(this.stats.drawCalls.current);
228
+ if (this.stats.drawCalls.history.length > this.historySize) {
229
+ this.stats.drawCalls.history.shift();
230
+ }
231
+ this.stats.drawCalls.average = this.stats.drawCalls.history.reduce(function (sum, val) {
232
+ return sum + val;
233
+ }, 0) / this.stats.drawCalls.history.length;
234
+
235
+ // Update memory stats
236
+ this.stats.memory.geometries = ((_info$memory = info.memory) === null || _info$memory === void 0 ? void 0 : _info$memory.geometries) || 0;
237
+ this.stats.memory.textures = ((_info$memory2 = info.memory) === null || _info$memory2 === void 0 ? void 0 : _info$memory2.textures) || 0;
238
+
239
+ // Update programs count
240
+ this.stats.memory.programs = ((_info$programs = info.programs) === null || _info$programs === void 0 ? void 0 : _info$programs.length) || 0;
241
+ }
242
+
243
+ /**
244
+ * Get system memory info
245
+ */
246
+ }, {
247
+ key: "_getMemoryInfo",
248
+ value: function _getMemoryInfo() {
249
+ if (typeof window !== 'undefined' && window.performance && window.performance.memory) {
250
+ this.stats.memory.heapUsed = window.performance.memory.usedJSHeapSize;
251
+ this.stats.memory.heapTotal = window.performance.memory.totalJSHeapSize;
252
+ } else {
253
+ // Fallback to navigator.deviceMemory if available
254
+ if (typeof navigator !== 'undefined' && navigator.deviceMemory) {
255
+ this.stats.memory.deviceMemory = navigator.deviceMemory;
256
+ }
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Get GPU info if available
262
+ */
263
+ }, {
264
+ key: "_getGPUInfo",
265
+ value: function _getGPUInfo() {
266
+ if (!this.renderer) return;
267
+ var gl = this.renderer.getContext();
268
+
269
+ // Get extensions
270
+ var debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
271
+ if (debugInfo) {
272
+ this.stats.gpu.vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
273
+ this.stats.gpu.renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
274
+ } else {
275
+ this.stats.gpu.vendor = gl.getParameter(gl.VENDOR);
276
+ this.stats.gpu.renderer = gl.getParameter(gl.RENDERER);
277
+ }
278
+
279
+ // Get extensions
280
+ this.stats.gpu.extensions = gl.getSupportedExtensions();
281
+ }
282
+
283
+ /**
284
+ * Check for performance warnings
285
+ */
286
+ }, {
287
+ key: "_checkWarnings",
288
+ value: function _checkWarnings() {
289
+ var warnings = [];
290
+
291
+ // Check FPS
292
+ if (this.stats.fps.average < this.warningThresholds.fps) {
293
+ warnings.push({
294
+ type: 'fps',
295
+ message: "Low FPS: ".concat(this.stats.fps.average.toFixed(1), " (threshold: ").concat(this.warningThresholds.fps, ")"),
296
+ value: this.stats.fps.average,
297
+ threshold: this.warningThresholds.fps
298
+ });
299
+ }
300
+
301
+ // Check frame time
302
+ if (this.stats.frameTime.average > this.warningThresholds.frameTime) {
303
+ warnings.push({
304
+ type: 'frameTime',
305
+ message: "High frame time: ".concat(this.stats.frameTime.average.toFixed(1), "ms (threshold: ").concat(this.warningThresholds.frameTime, "ms)"),
306
+ value: this.stats.frameTime.average,
307
+ threshold: this.warningThresholds.frameTime
308
+ });
309
+ }
310
+
311
+ // Check draw calls
312
+ if (this.stats.drawCalls.average > this.warningThresholds.drawCalls) {
313
+ warnings.push({
314
+ type: 'drawCalls',
315
+ message: "High draw calls: ".concat(this.stats.drawCalls.average.toFixed(0), " (threshold: ").concat(this.warningThresholds.drawCalls, ")"),
316
+ value: this.stats.drawCalls.average,
317
+ threshold: this.warningThresholds.drawCalls
318
+ });
319
+ }
320
+
321
+ // Check triangles
322
+ if (this.stats.drawCalls.triangles > this.warningThresholds.triangles) {
323
+ warnings.push({
324
+ type: 'triangles',
325
+ message: "High triangle count: ".concat(this.stats.drawCalls.triangles.toFixed(0), " (threshold: ").concat(this.warningThresholds.triangles, ")"),
326
+ value: this.stats.drawCalls.triangles,
327
+ threshold: this.warningThresholds.triangles
328
+ });
329
+ }
330
+
331
+ // Check geometries
332
+ if (this.stats.memory.geometries > this.warningThresholds.geometries) {
333
+ warnings.push({
334
+ type: 'geometries',
335
+ message: "High geometry count: ".concat(this.stats.memory.geometries, " (threshold: ").concat(this.warningThresholds.geometries, ")"),
336
+ value: this.stats.memory.geometries,
337
+ threshold: this.warningThresholds.geometries
338
+ });
339
+ }
340
+
341
+ // Check textures
342
+ if (this.stats.memory.textures > this.warningThresholds.textures) {
343
+ warnings.push({
344
+ type: 'textures',
345
+ message: "High texture count: ".concat(this.stats.memory.textures, " (threshold: ").concat(this.warningThresholds.textures, ")"),
346
+ value: this.stats.memory.textures,
347
+ threshold: this.warningThresholds.textures
348
+ });
349
+ }
350
+
351
+ // Trigger warnings if any
352
+ if (warnings.length > 0) {
353
+ this._triggerCallbacks('warning', warnings);
354
+ }
355
+ }
356
+
357
+ /**
358
+ * Register an event callback
359
+ */
360
+ }, {
361
+ key: "on",
362
+ value: function on(event, callback) {
363
+ if (!this.callbacks[event]) return;
364
+ this.callbacks[event].push(callback);
365
+ }
366
+
367
+ /**
368
+ * Remove an event callback
369
+ */
370
+ }, {
371
+ key: "off",
372
+ value: function off(event, callback) {
373
+ if (!this.callbacks[event]) return;
374
+ var index = this.callbacks[event].indexOf(callback);
375
+ if (index !== -1) {
376
+ this.callbacks[event].splice(index, 1);
377
+ }
378
+ }
379
+
380
+ /**
381
+ * Trigger callbacks for an event
382
+ */
383
+ }, {
384
+ key: "_triggerCallbacks",
385
+ value: function _triggerCallbacks(event, data) {
386
+ if (!this.callbacks[event]) return;
387
+ this.callbacks[event].forEach(function (callback) {
388
+ try {
389
+ callback(data);
390
+ } catch (error) {
391
+ console.error("Error in performance monitor ".concat(event, " callback:"), error);
392
+ }
393
+ });
394
+ }
395
+
396
+ /**
397
+ * Log performance summary to console
398
+ */
399
+ }, {
400
+ key: "logSummary",
401
+ value: function logSummary() {
402
+ console.group('📊 Performance Summary');
403
+ console.log("FPS: ".concat(this.stats.fps.current.toFixed(1), " (avg: ").concat(this.stats.fps.average.toFixed(1), ", min: ").concat(this.stats.fps.min.toFixed(1), ", max: ").concat(this.stats.fps.max.toFixed(1), ")"));
404
+ console.log("Frame Time: ".concat(this.stats.frameTime.current.toFixed(1), "ms (avg: ").concat(this.stats.frameTime.average.toFixed(1), "ms)"));
405
+ console.log("Draw Calls: ".concat(this.stats.drawCalls.current, " (avg: ").concat(this.stats.drawCalls.average.toFixed(1), ")"));
406
+ console.log("Triangles: ".concat(this.stats.drawCalls.triangles));
407
+ console.log("Geometries: ".concat(this.stats.memory.geometries));
408
+ console.log("Textures: ".concat(this.stats.memory.textures));
409
+ console.log("Shader Programs: ".concat(this.stats.memory.programs));
410
+ if (this.stats.gpu.renderer) {
411
+ console.log("GPU: ".concat(this.stats.gpu.renderer));
412
+ }
413
+ console.log("Total Frames: ".concat(this.frameCount));
414
+ console.groupEnd();
415
+ return this.stats;
416
+ }
417
+
418
+ /**
419
+ * Export performance data
420
+ */
421
+ }, {
422
+ key: "exportData",
423
+ value: function exportData() {
424
+ return {
425
+ timestamp: new Date().toISOString(),
426
+ frameCount: this.frameCount,
427
+ stats: JSON.parse(JSON.stringify(this.stats)),
428
+ gpu: this.stats.gpu,
429
+ warnings: this._getActiveWarnings()
430
+ };
431
+ }
432
+
433
+ /**
434
+ * Get active warnings
435
+ */
436
+ }, {
437
+ key: "_getActiveWarnings",
438
+ value: function _getActiveWarnings() {
439
+ var warnings = [];
440
+
441
+ // Check all thresholds
442
+ if (this.stats.fps.average < this.warningThresholds.fps) {
443
+ warnings.push({
444
+ type: 'fps',
445
+ value: this.stats.fps.average
446
+ });
447
+ }
448
+ if (this.stats.frameTime.average > this.warningThresholds.frameTime) {
449
+ warnings.push({
450
+ type: 'frameTime',
451
+ value: this.stats.frameTime.average
452
+ });
453
+ }
454
+ if (this.stats.drawCalls.average > this.warningThresholds.drawCalls) {
455
+ warnings.push({
456
+ type: 'drawCalls',
457
+ value: this.stats.drawCalls.average
458
+ });
459
+ }
460
+ if (this.stats.drawCalls.triangles > this.warningThresholds.triangles) {
461
+ warnings.push({
462
+ type: 'triangles',
463
+ value: this.stats.drawCalls.triangles
464
+ });
465
+ }
466
+ if (this.stats.memory.geometries > this.warningThresholds.geometries) {
467
+ warnings.push({
468
+ type: 'geometries',
469
+ value: this.stats.memory.geometries
470
+ });
471
+ }
472
+ if (this.stats.memory.textures > this.warningThresholds.textures) {
473
+ warnings.push({
474
+ type: 'textures',
475
+ value: this.stats.memory.textures
476
+ });
477
+ }
478
+ return warnings;
479
+ }
480
+
481
+ /**
482
+ * Set warning thresholds
483
+ */
484
+ }, {
485
+ key: "setWarningThresholds",
486
+ value: function setWarningThresholds(thresholds) {
487
+ Object.assign(this.warningThresholds, thresholds);
488
+ }
489
+ }]);
490
+ }();
491
+
492
+ /**
493
+ * Performance UI class for displaying performance statistics
494
+ */
495
+ var PerformanceUI = /*#__PURE__*/function () {
496
+ function PerformanceUI(monitor, container) {
497
+ var theme = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'dark';
498
+ _rollupPluginBabelHelpers.classCallCheck(this, PerformanceUI);
499
+ this.monitor = monitor;
500
+ this.container = container;
501
+ this.theme = theme;
502
+ this.isVisible = false;
503
+ this.element = null;
504
+ this.graphs = {};
505
+ this._createUI();
506
+ this._setupUpdateLoop();
507
+ }
508
+
509
+ /**
510
+ * Create the UI element
511
+ */
512
+ return _rollupPluginBabelHelpers.createClass(PerformanceUI, [{
513
+ key: "_createUI",
514
+ value: function _createUI() {
515
+ var _this = this;
516
+ // Create container element
517
+ this.element = document.createElement('div');
518
+ this.element.className = 'performance-monitor';
519
+ this.element.style.position = 'absolute';
520
+ this.element.style.top = '10px';
521
+ this.element.style.right = '10px';
522
+ this.element.style.zIndex = '1000';
523
+ this.element.style.padding = '10px';
524
+ this.element.style.borderRadius = '5px';
525
+ this.element.style.fontFamily = 'monospace';
526
+ this.element.style.fontSize = '12px';
527
+ this.element.style.lineHeight = '1.2';
528
+ this.element.style.transition = 'opacity 0.3s ease';
529
+ this.element.style.userSelect = 'none';
530
+
531
+ // Apply theme
532
+ this.setTheme(this.theme);
533
+
534
+ // Create header with close button
535
+ var header = document.createElement('div');
536
+ header.style.display = 'flex';
537
+ header.style.justifyContent = 'space-between';
538
+ header.style.marginBottom = '5px';
539
+ var title = document.createElement('div');
540
+ title.textContent = 'Performance Monitor';
541
+ title.style.fontWeight = 'bold';
542
+ var closeButton = document.createElement('div');
543
+ closeButton.textContent = '×';
544
+ closeButton.style.cursor = 'pointer';
545
+ closeButton.style.paddingLeft = '10px';
546
+ closeButton.onclick = function () {
547
+ return _this.hide();
548
+ };
549
+ header.appendChild(title);
550
+ header.appendChild(closeButton);
551
+ this.element.appendChild(header);
552
+
553
+ // Create stats container
554
+ var statsContainer = document.createElement('div');
555
+ this.statsElement = statsContainer;
556
+ this.element.appendChild(statsContainer);
557
+
558
+ // Hide initially
559
+ this.element.style.opacity = '0';
560
+ this.element.style.pointerEvents = 'none';
561
+ }
562
+
563
+ /**
564
+ * Set UI theme
565
+ */
566
+ }, {
567
+ key: "setTheme",
568
+ value: function setTheme(theme) {
569
+ this.theme = theme;
570
+ if (theme === 'dark') {
571
+ this.element.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
572
+ this.element.style.color = 'white';
573
+ this.element.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.5)';
574
+ } else {
575
+ this.element.style.backgroundColor = 'rgba(255, 255, 255, 0.85)';
576
+ this.element.style.color = 'black';
577
+ this.element.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
578
+ }
579
+ }
580
+
581
+ /**
582
+ * Setup update loop for refreshing the UI
583
+ */
584
+ }, {
585
+ key: "_setupUpdateLoop",
586
+ value: function _setupUpdateLoop() {
587
+ var _this2 = this;
588
+ var updateStats = function updateStats() {
589
+ if (!_this2.isVisible || !_this2.monitor) return;
590
+
591
+ // Create stats HTML
592
+ var html = '';
593
+
594
+ // FPS
595
+ var fpsColor = _this2._getMetricColor(_this2.monitor.stats.fps.current, 60, 30);
596
+ html += "<div>FPS: <span style=\"color: ".concat(fpsColor, "\">").concat(_this2.monitor.stats.fps.current.toFixed(1), "</span> ");
597
+ html += "(avg: ".concat(_this2.monitor.stats.fps.average.toFixed(1), ")</div>");
598
+
599
+ // Frame time
600
+ var frameTimeColor = _this2._getMetricColor(16 - _this2.monitor.stats.frameTime.current, 0, 16, true);
601
+ html += "<div>Frame: <span style=\"color: ".concat(frameTimeColor, "\">").concat(_this2.monitor.stats.frameTime.current.toFixed(1), "ms</span></div>");
602
+
603
+ // Draw calls
604
+ var drawCallColor = _this2._getMetricColor(1000 - _this2.monitor.stats.drawCalls.current, 0, 1000, true);
605
+ html += "<div>Calls: <span style=\"color: ".concat(drawCallColor, "\">").concat(_this2.monitor.stats.drawCalls.current, "</span> ");
606
+ html += "Tris: ".concat(_this2._formatNumber(_this2.monitor.stats.drawCalls.triangles), "</div>");
607
+
608
+ // Memory
609
+ html += "<div>Geo: ".concat(_this2.monitor.stats.memory.geometries, " ");
610
+ html += "Tex: ".concat(_this2.monitor.stats.memory.textures, "</div>");
611
+
612
+ // Update stats element
613
+ _this2.statsElement.innerHTML = html;
614
+ };
615
+
616
+ // Update every 500ms to avoid performance impact
617
+ setInterval(updateStats, 500);
618
+ }
619
+
620
+ /**
621
+ * Get color for a metric based on its value
622
+ */
623
+ }, {
624
+ key: "_getMetricColor",
625
+ value: function _getMetricColor(value, good, bad) {
626
+ var invert = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
627
+ // Normalize value between 0 and 1
628
+ var normalized = (value - bad) / (good - bad);
629
+
630
+ // Clamp between 0 and 1
631
+ normalized = Math.max(0, Math.min(1, normalized));
632
+ if (invert) {
633
+ normalized = 1 - normalized;
634
+ }
635
+
636
+ // Green to yellow to red
637
+ var r = normalized < 0.5 ? 255 : Math.floor(255 * (1 - normalized) * 2);
638
+ var g = normalized > 0.5 ? 255 : Math.floor(255 * normalized * 2);
639
+ var b = 0;
640
+ return "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")");
641
+ }
642
+
643
+ /**
644
+ * Format number for display
645
+ */
646
+ }, {
647
+ key: "_formatNumber",
648
+ value: function _formatNumber(number) {
649
+ if (number >= 1000000) {
650
+ return (number / 1000000).toFixed(1) + 'M';
651
+ } else if (number >= 1000) {
652
+ return (number / 1000).toFixed(1) + 'K';
653
+ }
654
+ return number.toString();
655
+ }
656
+
657
+ /**
658
+ * Show the UI
659
+ */
660
+ }, {
661
+ key: "show",
662
+ value: function show() {
663
+ if (this.isVisible) return;
664
+ this.isVisible = true;
665
+ this.element.style.opacity = '1';
666
+ this.element.style.pointerEvents = 'auto';
667
+
668
+ // Add to container if not already added
669
+ if (!this.element.parentElement) {
670
+ this.container.appendChild(this.element);
671
+ }
672
+ }
673
+
674
+ /**
675
+ * Hide the UI
676
+ */
677
+ }, {
678
+ key: "hide",
679
+ value: function hide() {
680
+ if (!this.isVisible) return;
681
+ this.isVisible = false;
682
+ this.element.style.opacity = '0';
683
+ this.element.style.pointerEvents = 'none';
684
+ }
685
+
686
+ /**
687
+ * Toggle visibility
688
+ */
689
+ }, {
690
+ key: "toggle",
691
+ value: function toggle() {
692
+ if (this.isVisible) {
693
+ this.hide();
694
+ } else {
695
+ this.show();
696
+ }
697
+ }
698
+
699
+ /**
700
+ * Clean up resources
701
+ */
702
+ }, {
703
+ key: "dispose",
704
+ value: function dispose() {
705
+ if (this.element.parentElement) {
706
+ this.element.parentElement.removeChild(this.element);
707
+ }
708
+ }
709
+ }]);
710
+ }();
711
+ var performanceMonitor = {
712
+ PerformanceMonitor: PerformanceMonitor,
713
+ PerformanceUI: PerformanceUI
714
+ };
715
+
716
+ exports.PerformanceMonitor = PerformanceMonitor;
717
+ exports.PerformanceUI = PerformanceUI;
718
+ exports["default"] = performanceMonitor;