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