@2112-lab/central-plant 0.1.4 → 0.1.6

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 (88) hide show
  1. package/dist/bundle/index.js +33146 -1
  2. package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +432 -1
  3. package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1448 -1
  4. package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1853 -1
  5. package/dist/cjs/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3537 -1
  6. package/dist/cjs/node_modules/three/examples/jsm/exporters/OBJExporter.js +305 -1
  7. package/dist/cjs/node_modules/three/examples/jsm/exporters/PLYExporter.js +542 -1
  8. package/dist/cjs/node_modules/three/examples/jsm/exporters/STLExporter.js +218 -1
  9. package/dist/cjs/node_modules/three/examples/jsm/loaders/DRACOLoader.js +683 -1
  10. package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4811 -1
  11. package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +480 -1
  12. package/dist/cjs/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +309 -1
  13. package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +120 -1
  14. package/dist/cjs/src/analysis/analysis.js +560 -1
  15. package/dist/cjs/src/analysis/testing.js +958 -1
  16. package/dist/cjs/src/core/centralPlant.js +1149 -1
  17. package/dist/cjs/src/core/debugLogger.js +175 -1
  18. package/dist/cjs/src/core/mathUtils.js +574 -1
  19. package/dist/cjs/src/core/nameUtils.js +93 -1
  20. package/dist/cjs/src/data/export.js +716 -1
  21. package/dist/cjs/src/data/import.js +380 -1
  22. package/dist/cjs/src/data/numerics.js +522 -1
  23. package/dist/cjs/src/helpers/sceneHelper.js +572 -1
  24. package/dist/cjs/src/index.js +69 -1
  25. package/dist/cjs/src/managers/components/animationManager.js +123 -1
  26. package/dist/cjs/src/managers/components/componentManager.js +332 -1
  27. package/dist/cjs/src/managers/components/pathfindingManager.js +1441 -1
  28. package/dist/cjs/src/managers/controls/TransformControls.js +1063 -1
  29. package/dist/cjs/src/managers/controls/cameraControlsManager.js +79 -1
  30. package/dist/cjs/src/managers/controls/dragDropManager.js +1026 -1
  31. package/dist/cjs/src/managers/controls/keyboardControlsManager.js +395 -1
  32. package/dist/cjs/src/managers/controls/transformControlsManager.js +1807 -1
  33. package/dist/cjs/src/managers/environment/environmentManager.js +714 -1
  34. package/dist/cjs/src/managers/environment/textureConfig.js +229 -1
  35. package/dist/cjs/src/managers/scene/sceneExportManager.js +264 -1
  36. package/dist/cjs/src/managers/scene/sceneInitializationManager.js +346 -1
  37. package/dist/cjs/src/managers/scene/sceneOperationsManager.js +1509 -1
  38. package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +661 -1
  39. package/dist/cjs/src/managers/system/disposalManager.js +444 -1
  40. package/dist/cjs/src/managers/system/hotReloadManager.js +291 -1
  41. package/dist/cjs/src/managers/system/performanceMonitor.js +863 -1
  42. package/dist/cjs/src/rendering/modelPreloader.js +369 -1
  43. package/dist/cjs/src/rendering/rendering2D.js +631 -1
  44. package/dist/cjs/src/rendering/rendering3D.js +685 -1
  45. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +396 -1
  46. package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1444 -1
  47. package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1849 -1
  48. package/dist/esm/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3533 -1
  49. package/dist/esm/node_modules/three/examples/jsm/exporters/OBJExporter.js +301 -1
  50. package/dist/esm/node_modules/three/examples/jsm/exporters/PLYExporter.js +538 -1
  51. package/dist/esm/node_modules/three/examples/jsm/exporters/STLExporter.js +214 -1
  52. package/dist/esm/node_modules/three/examples/jsm/loaders/DRACOLoader.js +679 -1
  53. package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4807 -1
  54. package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +476 -1
  55. package/dist/esm/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +304 -1
  56. package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +116 -1
  57. package/dist/esm/src/analysis/analysis.js +536 -1
  58. package/dist/esm/src/analysis/testing.js +954 -1
  59. package/dist/esm/src/core/centralPlant.js +1144 -1
  60. package/dist/esm/src/core/debugLogger.js +167 -1
  61. package/dist/esm/src/core/mathUtils.js +570 -1
  62. package/dist/esm/src/core/nameUtils.js +87 -1
  63. package/dist/esm/src/data/export.js +712 -1
  64. package/dist/esm/src/data/import.js +356 -1
  65. package/dist/esm/src/data/numerics.js +518 -1
  66. package/dist/esm/src/helpers/sceneHelper.js +547 -1
  67. package/dist/esm/src/index.js +35 -1
  68. package/dist/esm/src/managers/components/animationManager.js +119 -1
  69. package/dist/esm/src/managers/components/componentManager.js +328 -1
  70. package/dist/esm/src/managers/components/pathfindingManager.js +1417 -1
  71. package/dist/esm/src/managers/controls/TransformControls.js +1057 -1
  72. package/dist/esm/src/managers/controls/cameraControlsManager.js +75 -1
  73. package/dist/esm/src/managers/controls/dragDropManager.js +1002 -1
  74. package/dist/esm/src/managers/controls/keyboardControlsManager.js +371 -1
  75. package/dist/esm/src/managers/controls/transformControlsManager.js +1782 -1
  76. package/dist/esm/src/managers/environment/environmentManager.js +690 -1
  77. package/dist/esm/src/managers/environment/textureConfig.js +202 -1
  78. package/dist/esm/src/managers/scene/sceneExportManager.js +260 -1
  79. package/dist/esm/src/managers/scene/sceneInitializationManager.js +322 -1
  80. package/dist/esm/src/managers/scene/sceneOperationsManager.js +1485 -1
  81. package/dist/esm/src/managers/scene/sceneTooltipsManager.js +637 -1
  82. package/dist/esm/src/managers/system/disposalManager.js +440 -1
  83. package/dist/esm/src/managers/system/hotReloadManager.js +287 -1
  84. package/dist/esm/src/managers/system/performanceMonitor.js +858 -1
  85. package/dist/esm/src/rendering/modelPreloader.js +364 -1
  86. package/dist/esm/src/rendering/rendering2D.js +627 -1
  87. package/dist/esm/src/rendering/rendering3D.js +661 -1
  88. package/package.json +1 -1
@@ -1 +1,858 @@
1
- import{createClass as t,createForOfIteratorHelper as e,classCallCheck as i}from"../../../_virtual/_rollupPluginBabelHelpers.js";var s=function(){return t(function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;i(this,t),this.renderer=e,this.stats={fps:{current:0,average:0,min:1/0,max:0,history:[]},frameTime:{current:0,average:0,min:1/0,max:0,history:[]},memory:{geometries:0,textures:0,programs:0,heapUsed:0,heapTotal:0},drawCalls:{current:0,average:0,triangles:0,points:0,lines:0},gpu:{memoryUsage:0,extensions:[]},scene:{objects:0,lights:0,meshes:0,materials:0,visible:0}},this.frameCount=0,this.lastTime=performance.now(),this.updateInterval=100,this.maxHistoryLength=300,this.thresholds={fps:{good:55,warning:45,critical:30},frameTime:{good:16.67,warning:22.22,critical:33.33},memory:{warning:200,critical:300},drawCalls:{warning:500,critical:1e3}},this.callbacks=new Map,this.isMonitoring=!1,this.update=this.update.bind(this),this.getGPUInfo=this.getGPUInfo.bind(this)},[{key:"start",value:function(){this.isMonitoring=!0,this.lastTime=performance.now(),this.getGPUInfo()}},{key:"stop",value:function(){this.isMonitoring=!1}},{key:"update",value:function(){if(this.isMonitoring){var t=performance.now(),e=t-this.lastTime;this.frameCount++;var i=1e3/e,s=e;this.stats.fps.current=i,this.stats.frameTime.current=s,this.addToHistory(this.stats.fps,i),this.addToHistory(this.stats.frameTime,s),this.frameCount%this.updateInterval===0&&(this.updateAverages(),this.updateMemoryStats(),this.updateDrawCallStats(),this.updateSceneStats(),this.checkThresholds()),this.lastTime=t}}},{key:"addToHistory",value:function(t,e){t.history.push(e),t.history.length>this.maxHistoryLength&&t.history.shift(),t.min=Math.min(t.min,e),t.max=Math.max(t.max,e)}},{key:"updateAverages",value:function(){this.stats.fps.history.length>0&&(this.stats.fps.average=this.stats.fps.history.reduce(function(t,e){return t+e},0)/this.stats.fps.history.length),this.stats.frameTime.history.length>0&&(this.stats.frameTime.average=this.stats.frameTime.history.reduce(function(t,e){return t+e},0)/this.stats.frameTime.history.length)}},{key:"updateMemoryStats",value:function(){var t;if(this.renderer){var e=this.renderer.info;this.stats.memory.geometries=e.memory.geometries,this.stats.memory.textures=e.memory.textures,this.stats.memory.programs=(null===(t=e.programs)||void 0===t?void 0:t.length)||0,performance.memory&&(this.stats.memory.heapUsed=Math.round(performance.memory.usedJSHeapSize/1024/1024),this.stats.memory.heapTotal=Math.round(performance.memory.totalJSHeapSize/1024/1024))}}},{key:"updateDrawCallStats",value:function(){if(this.renderer){var t=this.renderer.info.render;this.stats.drawCalls.current=t.calls,this.stats.drawCalls.triangles=t.triangles,this.stats.drawCalls.points=t.points,this.stats.drawCalls.lines=t.lines,this.stats.drawCalls.history||(this.stats.drawCalls.history=[]),this.addToHistory(this.stats.drawCalls,t.calls),this.stats.drawCalls.history.length>0&&(this.stats.drawCalls.average=this.stats.drawCalls.history.reduce(function(t,e){return t+e},0)/this.stats.drawCalls.history.length)}}},{key:"updateSceneStats",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(t){var i,s=0,n=0,a=0,r=new Set,o=0,l=e(t.children);try{for(l.s();!(i=l.n()).done;){var h=i.value;s++,h.visible&&o++,h.isLight&&n++,h.isMesh&&(a++,h.material&&(Array.isArray(h.material)?h.material.forEach(function(t){return r.add(t.uuid)}):r.add(h.material.uuid)))}}catch(t){l.e(t)}finally{l.f()}this.stats.scene={objects:s,lights:n,meshes:a,materials:r.size,visible:o}}}},{key:"getGPUInfo",value:function(){if(this.renderer){var t=this.renderer.getContext();this.stats.gpu.extensions=t.getSupportedExtensions()||[];var e=t.getExtension("WEBGL_debug_renderer_info");e&&(this.stats.gpu.renderer=t.getParameter(e.UNMASKED_RENDERER_WEBGL),this.stats.gpu.vendor=t.getParameter(e.UNMASKED_VENDOR_WEBGL))}}},{key:"checkThresholds",value:function(){var t=[];this.stats.fps.average<this.thresholds.fps.critical?t.push({type:"critical",category:"FPS",value:this.stats.fps.average.toFixed(1),threshold:this.thresholds.fps.critical}):this.stats.fps.average<this.thresholds.fps.warning&&t.push({type:"warning",category:"FPS",value:this.stats.fps.average.toFixed(1),threshold:this.thresholds.fps.warning}),this.stats.frameTime.average>this.thresholds.frameTime.critical?t.push({type:"critical",category:"Frame Time",value:this.stats.frameTime.average.toFixed(2)+"ms",threshold:this.thresholds.frameTime.critical+"ms"}):this.stats.frameTime.average>this.thresholds.frameTime.warning&&t.push({type:"warning",category:"Frame Time",value:this.stats.frameTime.average.toFixed(2)+"ms",threshold:this.thresholds.frameTime.warning+"ms"}),this.stats.memory.heapUsed>this.thresholds.memory.critical?t.push({type:"critical",category:"Memory",value:this.stats.memory.heapUsed+"MB",threshold:this.thresholds.memory.critical+"MB"}):this.stats.memory.heapUsed>this.thresholds.memory.warning&&t.push({type:"warning",category:"Memory",value:this.stats.memory.heapUsed+"MB",threshold:this.thresholds.memory.warning+"MB"}),this.stats.drawCalls.average>this.thresholds.drawCalls.critical?t.push({type:"critical",category:"Draw Calls",value:Math.round(this.stats.drawCalls.average),threshold:this.thresholds.drawCalls.critical}):this.stats.drawCalls.average>this.thresholds.drawCalls.warning&&t.push({type:"warning",category:"Draw Calls",value:Math.round(this.stats.drawCalls.average),threshold:this.thresholds.drawCalls.warning}),t.length>0&&this.triggerCallback("warning",t)}},{key:"on",value:function(t,e){this.callbacks.has(t)||this.callbacks.set(t,[]),this.callbacks.get(t).push(e)}},{key:"off",value:function(t,e){if(this.callbacks.has(t)){var i=this.callbacks.get(t),s=i.indexOf(e);s>-1&&i.splice(s,1)}}},{key:"triggerCallback",value:function(t,e){this.callbacks.has(t)&&this.callbacks.get(t).forEach(function(t){return t(e)})}},{key:"getSummary",value:function(){return{fps:{current:Math.round(this.stats.fps.current),average:Math.round(this.stats.fps.average),min:Math.round(this.stats.fps.min),max:Math.round(this.stats.fps.max)},frameTime:{current:this.stats.frameTime.current.toFixed(2)+"ms",average:this.stats.frameTime.average.toFixed(2)+"ms"},memory:{geometries:this.stats.memory.geometries,textures:this.stats.memory.textures,heapUsed:this.stats.memory.heapUsed+"MB",heapTotal:this.stats.memory.heapTotal+"MB"},drawCalls:{current:this.stats.drawCalls.current,average:Math.round(this.stats.drawCalls.average),triangles:this.stats.drawCalls.triangles.toLocaleString()},scene:this.stats.scene}}},{key:"logSummary",value:function(){this.getSummary()}},{key:"reset",value:function(){var t=this;Object.keys(this.stats).forEach(function(e){t.stats[e].history&&(t.stats[e].history=[]),void 0!==t.stats[e].min&&(t.stats[e].min=1/0,t.stats[e].max=0,t.stats[e].average=0)}),this.frameCount=0}},{key:"exportData",value:function(){return{timestamp:(new Date).toISOString(),stats:JSON.parse(JSON.stringify(this.stats)),thresholds:this.thresholds,frameCount:this.frameCount}}}])}(),n=function(){return t(function t(e){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document.body,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"dark";i(this,t),this.monitor=e,this.container=s,this.element=null,this.isVisible=!1,this.updateInterval=null,this.theme=n},[{key:"show",value:function(){var t=this;this.cleanupExistingElements(),this.element&&this.hide(),this.element=document.createElement("div"),this.element.id="performance-monitor-ui",this.element.innerHTML=this.getHTML(),this.addStyles(),this.container.appendChild(this.element),this.isVisible=!0,this.startUpdating(),this.element.querySelector("#perf-toggle").addEventListener("click",function(){return t.toggleDetails()}),this.toggleDetails()}},{key:"cleanupExistingElements",value:function(){document.querySelectorAll("#performance-monitor-ui").forEach(function(t){try{t.parentNode&&t.parentNode.removeChild(t)}catch(t){}})}},{key:"hide",value:function(){this.stopUpdating(),this.removeDOMElement(),this.isVisible=!1}},{key:"dispose",value:function(){this.hide(),this.cleanupExistingElements(),this.monitor=null,this.container=null,this.element=null}},{key:"stopUpdating",value:function(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null)}},{key:"removeDOMElement",value:function(){if(this.element){try{this.element.parentNode&&this.container&&this.container.contains(this.element)?this.container.removeChild(this.element):this.element.parentNode&&this.element.parentNode.removeChild(this.element)}catch(t){try{this.element.remove&&this.element.remove()}catch(t){}}this.element=null}}},{key:"toggleDetails",value:function(){var t=this.element.querySelector("#perf-details"),e="none"===t.style.display;t.style.display=e?"block":"none",this.element.querySelector("#perf-toggle").textContent=e?"▼":"▲"}},{key:"startUpdating",value:function(){var t=this;this.updateInterval=setInterval(function(){t.isVisible&&t.element&&t.updateContent()},500)}},{key:"updateContent",value:function(){var t=this.monitor.getSummary();this.updateElement("#fps-value",t.fps.current),this.updateElement("#frametime-value",t.frameTime.current),this.updateElement("#memory-value",t.memory.heapUsed),this.updateElement("#drawcalls-value",t.drawCalls.current),this.updateElement("#fps-avg",t.fps.average),this.updateElement("#fps-min",t.fps.min),this.updateElement("#fps-max",t.fps.max),this.updateElement("#geometries-value",t.memory.geometries),this.updateElement("#textures-value",t.memory.textures),this.updateElement("#triangles-value",t.drawCalls.triangles),this.updateElement("#objects-value",t.scene.objects),this.updateElement("#meshes-value",t.scene.meshes),this.updatePerformanceIndicators(t)}},{key:"updateElement",value:function(t,e){var i=this.element.querySelector(t);i&&(i.textContent=e)}},{key:"updatePerformanceIndicators",value:function(t){var e=this.element.querySelector("#fps-value"),i=this.element.querySelector("#frametime-value");if(e){var s=t.fps.current;e.className=this.getPerformanceClass("fps",s)}if(i){var n=parseFloat(t.frameTime.current);i.className=this.getPerformanceClass("frameTime",n)}}},{key:"getPerformanceClass",value:function(t,e){var i=this.monitor.thresholds[t];return"fps"===t?e>=i.good?"perf-good":e>=i.warning?"perf-warning":"perf-critical":"frameTime"===t?e<=i.good?"perf-good":e<=i.warning?"perf-warning":"perf-critical":""}},{key:"getHTML",value:function(){return'\n <div class="perf-header">\n <span class="perf-title">Performance</span>\n <button id="perf-toggle">▼</button>\n </div>\n <div class="perf-main">\n <div class="perf-stat">\n <span class="perf-label">FPS:</span>\n <span id="fps-value" class="perf-value">0</span>\n </div>\n <div class="perf-stat">\n <span class="perf-label">Frame:</span>\n <span id="frametime-value" class="perf-value">0ms</span>\n </div>\n <div class="perf-stat">\n <span class="perf-label">Memory:</span>\n <span id="memory-value" class="perf-value">0MB</span>\n </div>\n <div class="perf-stat">\n <span class="perf-label">Calls:</span>\n <span id="drawcalls-value" class="perf-value">0</span>\n </div>\n </div>\n <div id="perf-details" class="perf-details">\n <div class="perf-section">\n <div class="perf-section-title">FPS Stats</div>\n <div class="perf-detail">Avg: <span id="fps-avg">0</span></div>\n <div class="perf-detail">Min: <span id="fps-min">0</span></div>\n <div class="perf-detail">Max: <span id="fps-max">0</span></div>\n </div>\n <div class="perf-section">\n <div class="perf-section-title">Memory</div>\n <div class="perf-detail">Geometries: <span id="geometries-value">0</span></div>\n <div class="perf-detail">Textures: <span id="textures-value">0</span></div>\n </div>\n <div class="perf-section">\n <div class="perf-section-title">Rendering</div>\n <div class="perf-detail">Triangles: <span id="triangles-value">0</span></div>\n <div class="perf-detail">Objects: <span id="objects-value">0</span></div>\n <div class="perf-detail">Meshes: <span id="meshes-value">0</span></div>\n </div>\n </div>\n '}},{key:"addStyles",value:function(){if(!document.getElementById("performance-monitor-styles")){var t=document.createElement("style");t.id="performance-monitor-styles";var e={dark:{background:"rgba(0, 0, 0, 0.8)",color:"white",borderColor:"rgba(255, 255, 255, 0.1)",separatorColor:"rgba(255, 255, 255, 0.2)",sectionTitleColor:"#FFC107",goodColor:"#4CAF50",warningColor:"#FF9800",criticalColor:"#F44336"},light:{background:"rgba(255, 255, 255, 0.95)",color:"#333333",borderColor:"rgba(0, 0, 0, 0.15)",separatorColor:"rgba(0, 0, 0, 0.1)",sectionTitleColor:"#1565C0",goodColor:"#2E7D32",warningColor:"#E65100",criticalColor:"#C62828"}},i=e[this.theme]||e.dark;t.textContent=" #performance-monitor-ui {\n position: fixed;\n bottom: 10px;\n right: 10px;\n background: ".concat(i.background,";\n color: ").concat(i.color,";\n font-family: 'Consolas', 'Monaco', 'Courier New', monospace;\n font-size: 12px;\n padding: 10px;\n border-radius: 5px;\n z-index: 10000;\n min-width: 150px;\n backdrop-filter: blur(5px);\n border: 1px solid ").concat(i.borderColor,";\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n }\n\n .perf-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 8px;\n border-bottom: 1px solid ").concat(i.separatorColor,";\n padding-bottom: 5px;\n }\n\n .perf-title {\n font-weight: bold;\n font-size: 14px;\n }\n\n #perf-toggle {\n background: none;\n border: none;\n color: ").concat(i.color,";\n cursor: pointer;\n font-size: 12px;\n padding: 0;\n width: 20px;\n height: 20px;\n }\n\n .perf-main {\n display: grid;\n grid-template-columns: 1fr;\n gap: 4px;\n }\n\n .perf-stat {\n display: flex;\n justify-content: space-between;\n align-items: center;\n }\n\n .perf-label {\n opacity: 0.8;\n }\n\n .perf-value {\n font-weight: bold;\n text-align: right;\n min-width: 50px;\n } .perf-good {\n color: ").concat(i.goodColor,";\n }\n\n .perf-warning {\n color: ").concat(i.warningColor,";\n }\n\n .perf-critical {\n color: ").concat(i.criticalColor,";\n }\n\n .perf-details {\n margin-top: 10px;\n padding-top: 8px;\n border-top: 1px solid ").concat(i.separatorColor,";\n }\n\n .perf-section {\n margin-bottom: 8px;\n }\n\n .perf-section-title {\n font-weight: bold;\n font-size: 11px;\n margin-bottom: 3px;\n color: ").concat(i.sectionTitleColor,";\n }\n\n .perf-detail {\n font-size: 10px;\n display: flex;\n justify-content: space-between;\n margin-bottom: 2px;\n opacity: 0.9;\n }\n "),document.head.appendChild(t)}}},{key:"setTheme",value:function(t){if("light"===t||"dark"===t){this.theme=t;var e=document.getElementById("performance-monitor-styles");e&&e.remove(),this.addStyles()}}}],[{key:"cleanupAllInstances",value:function(){var t=document.querySelectorAll("#performance-monitor-ui"),e=0;if(t.forEach(function(t){try{t.parentNode&&(t.parentNode.removeChild(t),e++)}catch(t){}}),0===document.querySelectorAll("#performance-monitor-ui").length){var i=document.getElementById("performance-monitor-styles");i&&i.remove()}return e}}])}();export{s as PerformanceMonitor,n as PerformanceUI};
1
+ import { createClass as _createClass, createForOfIteratorHelper as _createForOfIteratorHelper, classCallCheck as _classCallCheck } from '../../../_virtual/_rollupPluginBabelHelpers.js';
2
+
3
+ /**
4
+ * Performance Monitor for Three.js Applications
5
+ * Tracks rendering performance across multiple categories
6
+ */
7
+
8
+ var PerformanceMonitor = /*#__PURE__*/function () {
9
+ function PerformanceMonitor() {
10
+ var renderer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
11
+ _classCallCheck(this, PerformanceMonitor);
12
+ this.renderer = renderer;
13
+ this.stats = {
14
+ fps: {
15
+ current: 0,
16
+ average: 0,
17
+ min: Infinity,
18
+ max: 0,
19
+ history: []
20
+ },
21
+ frameTime: {
22
+ current: 0,
23
+ average: 0,
24
+ min: Infinity,
25
+ max: 0,
26
+ history: []
27
+ },
28
+ memory: {
29
+ geometries: 0,
30
+ textures: 0,
31
+ programs: 0,
32
+ heapUsed: 0,
33
+ heapTotal: 0
34
+ },
35
+ drawCalls: {
36
+ current: 0,
37
+ average: 0,
38
+ triangles: 0,
39
+ points: 0,
40
+ lines: 0
41
+ },
42
+ gpu: {
43
+ memoryUsage: 0,
44
+ extensions: []
45
+ },
46
+ scene: {
47
+ objects: 0,
48
+ lights: 0,
49
+ meshes: 0,
50
+ materials: 0,
51
+ visible: 0
52
+ }
53
+ };
54
+ this.frameCount = 0;
55
+ this.lastTime = performance.now();
56
+ this.updateInterval = 100; // Update stats every 100 frames
57
+ this.maxHistoryLength = 300; // Keep 5 seconds of history at 60fps
58
+
59
+ // Performance thresholds
60
+ this.thresholds = {
61
+ fps: {
62
+ good: 55,
63
+ warning: 45,
64
+ critical: 30
65
+ },
66
+ frameTime: {
67
+ good: 16.67,
68
+ warning: 22.22,
69
+ critical: 33.33
70
+ },
71
+ // ms
72
+ memory: {
73
+ warning: 200,
74
+ critical: 300
75
+ },
76
+ // MB
77
+ drawCalls: {
78
+ warning: 500,
79
+ critical: 1000
80
+ }
81
+ };
82
+ this.callbacks = new Map();
83
+ this.isMonitoring = false;
84
+
85
+ // Bind methods
86
+ this.update = this.update.bind(this);
87
+ this.getGPUInfo = this.getGPUInfo.bind(this);
88
+ }
89
+
90
+ /**
91
+ * Start monitoring performance
92
+ */
93
+ return _createClass(PerformanceMonitor, [{
94
+ key: "start",
95
+ value: function start() {
96
+ this.isMonitoring = true;
97
+ this.lastTime = performance.now();
98
+ console.log('🔍 Performance monitoring started');
99
+
100
+ // Get initial GPU info
101
+ this.getGPUInfo();
102
+ }
103
+
104
+ /**
105
+ * Stop monitoring performance
106
+ */
107
+ }, {
108
+ key: "stop",
109
+ value: function stop() {
110
+ this.isMonitoring = false;
111
+ console.log('⏹️ Performance monitoring stopped');
112
+ }
113
+
114
+ /**
115
+ * Update performance stats - call this in your animation loop
116
+ */
117
+ }, {
118
+ key: "update",
119
+ value: function update() {
120
+ if (!this.isMonitoring) return;
121
+ var currentTime = performance.now();
122
+ var deltaTime = currentTime - this.lastTime;
123
+ this.frameCount++;
124
+
125
+ // Update FPS and frame time
126
+ var fps = 1000 / deltaTime;
127
+ var frameTime = deltaTime;
128
+ this.stats.fps.current = fps;
129
+ this.stats.frameTime.current = frameTime;
130
+
131
+ // Update history
132
+ this.addToHistory(this.stats.fps, fps);
133
+ this.addToHistory(this.stats.frameTime, frameTime);
134
+
135
+ // Update averages and min/max every updateInterval frames
136
+ if (this.frameCount % this.updateInterval === 0) {
137
+ this.updateAverages();
138
+ this.updateMemoryStats();
139
+ this.updateDrawCallStats();
140
+ this.updateSceneStats();
141
+ this.checkThresholds();
142
+ }
143
+ this.lastTime = currentTime;
144
+ }
145
+
146
+ /**
147
+ * Add value to history and update min/max
148
+ */
149
+ }, {
150
+ key: "addToHistory",
151
+ value: function addToHistory(statObject, value) {
152
+ statObject.history.push(value);
153
+ if (statObject.history.length > this.maxHistoryLength) {
154
+ statObject.history.shift();
155
+ }
156
+ statObject.min = Math.min(statObject.min, value);
157
+ statObject.max = Math.max(statObject.max, value);
158
+ }
159
+
160
+ /**
161
+ * Update average values
162
+ */
163
+ }, {
164
+ key: "updateAverages",
165
+ value: function updateAverages() {
166
+ // FPS average
167
+ if (this.stats.fps.history.length > 0) {
168
+ this.stats.fps.average = this.stats.fps.history.reduce(function (a, b) {
169
+ return a + b;
170
+ }, 0) / this.stats.fps.history.length;
171
+ }
172
+
173
+ // Frame time average
174
+ if (this.stats.frameTime.history.length > 0) {
175
+ this.stats.frameTime.average = this.stats.frameTime.history.reduce(function (a, b) {
176
+ return a + b;
177
+ }, 0) / this.stats.frameTime.history.length;
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Update memory statistics
183
+ */
184
+ }, {
185
+ key: "updateMemoryStats",
186
+ value: function updateMemoryStats() {
187
+ var _info$programs;
188
+ if (!this.renderer) return;
189
+ var info = this.renderer.info;
190
+ this.stats.memory.geometries = info.memory.geometries;
191
+ this.stats.memory.textures = info.memory.textures;
192
+ this.stats.memory.programs = ((_info$programs = info.programs) === null || _info$programs === void 0 ? void 0 : _info$programs.length) || 0;
193
+
194
+ // Get JavaScript heap usage if available
195
+ if (performance.memory) {
196
+ this.stats.memory.heapUsed = Math.round(performance.memory.usedJSHeapSize / 1024 / 1024);
197
+ this.stats.memory.heapTotal = Math.round(performance.memory.totalJSHeapSize / 1024 / 1024);
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Update draw call statistics
203
+ */
204
+ }, {
205
+ key: "updateDrawCallStats",
206
+ value: function updateDrawCallStats() {
207
+ if (!this.renderer) return;
208
+ var info = this.renderer.info.render;
209
+ this.stats.drawCalls.current = info.calls;
210
+ this.stats.drawCalls.triangles = info.triangles;
211
+ this.stats.drawCalls.points = info.points;
212
+ this.stats.drawCalls.lines = info.lines;
213
+
214
+ // Calculate draw calls average
215
+ if (!this.stats.drawCalls.history) {
216
+ this.stats.drawCalls.history = [];
217
+ }
218
+ this.addToHistory(this.stats.drawCalls, info.calls);
219
+ if (this.stats.drawCalls.history.length > 0) {
220
+ this.stats.drawCalls.average = this.stats.drawCalls.history.reduce(function (a, b) {
221
+ return a + b;
222
+ }, 0) / this.stats.drawCalls.history.length;
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Update scene statistics
228
+ */
229
+ }, {
230
+ key: "updateSceneStats",
231
+ value: function updateSceneStats() {
232
+ var scene = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
233
+ if (!scene) return;
234
+ var objects = 0;
235
+ var lights = 0;
236
+ var meshes = 0;
237
+ var materials = new Set();
238
+ var visible = 0;
239
+ var _iterator = _createForOfIteratorHelper(scene.children),
240
+ _step;
241
+ try {
242
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
243
+ var child = _step.value;
244
+ objects++;
245
+ if (child.visible) {
246
+ visible++;
247
+ }
248
+ if (child.isLight) {
249
+ lights++;
250
+ }
251
+ if (child.isMesh) {
252
+ meshes++;
253
+ if (child.material) {
254
+ if (Array.isArray(child.material)) {
255
+ child.material.forEach(function (mat) {
256
+ return materials.add(mat.uuid);
257
+ });
258
+ } else {
259
+ materials.add(child.material.uuid);
260
+ }
261
+ }
262
+ }
263
+ }
264
+ } catch (err) {
265
+ _iterator.e(err);
266
+ } finally {
267
+ _iterator.f();
268
+ }
269
+ this.stats.scene = {
270
+ objects: objects,
271
+ lights: lights,
272
+ meshes: meshes,
273
+ materials: materials.size,
274
+ visible: visible
275
+ };
276
+ }
277
+
278
+ /**
279
+ * Get GPU information
280
+ */
281
+ }, {
282
+ key: "getGPUInfo",
283
+ value: function getGPUInfo() {
284
+ if (!this.renderer) return;
285
+ var gl = this.renderer.getContext();
286
+
287
+ // Get GPU extensions
288
+ this.stats.gpu.extensions = gl.getSupportedExtensions() || [];
289
+
290
+ // Try to get GPU memory info (Chrome only)
291
+ var memInfo = gl.getExtension('WEBGL_debug_renderer_info');
292
+ if (memInfo) {
293
+ this.stats.gpu.renderer = gl.getParameter(memInfo.UNMASKED_RENDERER_WEBGL);
294
+ this.stats.gpu.vendor = gl.getParameter(memInfo.UNMASKED_VENDOR_WEBGL);
295
+ }
296
+ console.log('🎮 GPU Info:', {
297
+ renderer: this.stats.gpu.renderer,
298
+ vendor: this.stats.gpu.vendor,
299
+ extensions: this.stats.gpu.extensions.length
300
+ });
301
+ }
302
+
303
+ /**
304
+ * Check performance thresholds and trigger warnings
305
+ */
306
+ }, {
307
+ key: "checkThresholds",
308
+ value: function checkThresholds() {
309
+ var warnings = [];
310
+
311
+ // Check FPS
312
+ if (this.stats.fps.average < this.thresholds.fps.critical) {
313
+ warnings.push({
314
+ type: 'critical',
315
+ category: 'FPS',
316
+ value: this.stats.fps.average.toFixed(1),
317
+ threshold: this.thresholds.fps.critical
318
+ });
319
+ } else if (this.stats.fps.average < this.thresholds.fps.warning) {
320
+ warnings.push({
321
+ type: 'warning',
322
+ category: 'FPS',
323
+ value: this.stats.fps.average.toFixed(1),
324
+ threshold: this.thresholds.fps.warning
325
+ });
326
+ }
327
+
328
+ // Check frame time
329
+ if (this.stats.frameTime.average > this.thresholds.frameTime.critical) {
330
+ warnings.push({
331
+ type: 'critical',
332
+ category: 'Frame Time',
333
+ value: this.stats.frameTime.average.toFixed(2) + 'ms',
334
+ threshold: this.thresholds.frameTime.critical + 'ms'
335
+ });
336
+ } else if (this.stats.frameTime.average > this.thresholds.frameTime.warning) {
337
+ warnings.push({
338
+ type: 'warning',
339
+ category: 'Frame Time',
340
+ value: this.stats.frameTime.average.toFixed(2) + 'ms',
341
+ threshold: this.thresholds.frameTime.warning + 'ms'
342
+ });
343
+ }
344
+
345
+ // Check memory
346
+ if (this.stats.memory.heapUsed > this.thresholds.memory.critical) {
347
+ warnings.push({
348
+ type: 'critical',
349
+ category: 'Memory',
350
+ value: this.stats.memory.heapUsed + 'MB',
351
+ threshold: this.thresholds.memory.critical + 'MB'
352
+ });
353
+ } else if (this.stats.memory.heapUsed > this.thresholds.memory.warning) {
354
+ warnings.push({
355
+ type: 'warning',
356
+ category: 'Memory',
357
+ value: this.stats.memory.heapUsed + 'MB',
358
+ threshold: this.thresholds.memory.warning + 'MB'
359
+ });
360
+ }
361
+
362
+ // Check draw calls
363
+ if (this.stats.drawCalls.average > this.thresholds.drawCalls.critical) {
364
+ warnings.push({
365
+ type: 'critical',
366
+ category: 'Draw Calls',
367
+ value: Math.round(this.stats.drawCalls.average),
368
+ threshold: this.thresholds.drawCalls.critical
369
+ });
370
+ } else if (this.stats.drawCalls.average > this.thresholds.drawCalls.warning) {
371
+ warnings.push({
372
+ type: 'warning',
373
+ category: 'Draw Calls',
374
+ value: Math.round(this.stats.drawCalls.average),
375
+ threshold: this.thresholds.drawCalls.warning
376
+ });
377
+ }
378
+
379
+ // Trigger callbacks for warnings
380
+ if (warnings.length > 0) {
381
+ this.triggerCallback('warning', warnings);
382
+ }
383
+ }
384
+
385
+ /**
386
+ * Add callback for specific events
387
+ */
388
+ }, {
389
+ key: "on",
390
+ value: function on(event, callback) {
391
+ if (!this.callbacks.has(event)) {
392
+ this.callbacks.set(event, []);
393
+ }
394
+ this.callbacks.get(event).push(callback);
395
+ }
396
+
397
+ /**
398
+ * Remove callback
399
+ */
400
+ }, {
401
+ key: "off",
402
+ value: function off(event, callback) {
403
+ if (this.callbacks.has(event)) {
404
+ var callbacks = this.callbacks.get(event);
405
+ var index = callbacks.indexOf(callback);
406
+ if (index > -1) {
407
+ callbacks.splice(index, 1);
408
+ }
409
+ }
410
+ }
411
+
412
+ /**
413
+ * Trigger callbacks
414
+ */
415
+ }, {
416
+ key: "triggerCallback",
417
+ value: function triggerCallback(event, data) {
418
+ if (this.callbacks.has(event)) {
419
+ this.callbacks.get(event).forEach(function (callback) {
420
+ return callback(data);
421
+ });
422
+ }
423
+ }
424
+
425
+ /**
426
+ * Get performance summary
427
+ */
428
+ }, {
429
+ key: "getSummary",
430
+ value: function getSummary() {
431
+ return {
432
+ fps: {
433
+ current: Math.round(this.stats.fps.current),
434
+ average: Math.round(this.stats.fps.average),
435
+ min: Math.round(this.stats.fps.min),
436
+ max: Math.round(this.stats.fps.max)
437
+ },
438
+ frameTime: {
439
+ current: this.stats.frameTime.current.toFixed(2) + 'ms',
440
+ average: this.stats.frameTime.average.toFixed(2) + 'ms'
441
+ },
442
+ memory: {
443
+ geometries: this.stats.memory.geometries,
444
+ textures: this.stats.memory.textures,
445
+ heapUsed: this.stats.memory.heapUsed + 'MB',
446
+ heapTotal: this.stats.memory.heapTotal + 'MB'
447
+ },
448
+ drawCalls: {
449
+ current: this.stats.drawCalls.current,
450
+ average: Math.round(this.stats.drawCalls.average),
451
+ triangles: this.stats.drawCalls.triangles.toLocaleString()
452
+ },
453
+ scene: this.stats.scene
454
+ };
455
+ }
456
+
457
+ /**
458
+ * Log performance summary to console
459
+ */
460
+ }, {
461
+ key: "logSummary",
462
+ value: function logSummary() {
463
+ var summary = this.getSummary();
464
+ console.group('📊 Performance Summary');
465
+ console.log('🎯 FPS:', summary.fps);
466
+ console.log('⏱️ Frame Time:', summary.frameTime);
467
+ console.log('💾 Memory:', summary.memory);
468
+ console.log('🎨 Draw Calls:', summary.drawCalls);
469
+ console.log('🏗️ Scene:', summary.scene);
470
+ console.groupEnd();
471
+ }
472
+
473
+ /**
474
+ * Reset all statistics
475
+ */
476
+ }, {
477
+ key: "reset",
478
+ value: function reset() {
479
+ var _this = this;
480
+ Object.keys(this.stats).forEach(function (category) {
481
+ if (_this.stats[category].history) {
482
+ _this.stats[category].history = [];
483
+ }
484
+ if (_this.stats[category].min !== undefined) {
485
+ _this.stats[category].min = Infinity;
486
+ _this.stats[category].max = 0;
487
+ _this.stats[category].average = 0;
488
+ }
489
+ });
490
+ this.frameCount = 0;
491
+ console.log('🔄 Performance stats reset');
492
+ }
493
+
494
+ /**
495
+ * Export performance data for analysis
496
+ */
497
+ }, {
498
+ key: "exportData",
499
+ value: function exportData() {
500
+ return {
501
+ timestamp: new Date().toISOString(),
502
+ stats: JSON.parse(JSON.stringify(this.stats)),
503
+ thresholds: this.thresholds,
504
+ frameCount: this.frameCount
505
+ };
506
+ }
507
+ }]);
508
+ }();
509
+
510
+ /**
511
+ * Performance UI overlay for real-time monitoring
512
+ */
513
+ var PerformanceUI = /*#__PURE__*/function () {
514
+ function PerformanceUI(monitor) {
515
+ var container = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body;
516
+ var theme = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'dark';
517
+ _classCallCheck(this, PerformanceUI);
518
+ this.monitor = monitor;
519
+ this.container = container;
520
+ this.element = null;
521
+ this.isVisible = false;
522
+ this.updateInterval = null;
523
+ this.theme = theme;
524
+ }
525
+ /**
526
+ * Create and show the performance UI overlay
527
+ */
528
+ return _createClass(PerformanceUI, [{
529
+ key: "show",
530
+ value: function show() {
531
+ var _this2 = this;
532
+ // First, clean up any existing performance monitor UI elements globally
533
+ this.cleanupExistingElements();
534
+ if (this.element) {
535
+ this.hide();
536
+ }
537
+ this.element = document.createElement('div');
538
+ this.element.id = 'performance-monitor-ui';
539
+ this.element.innerHTML = this.getHTML();
540
+ this.addStyles();
541
+ this.container.appendChild(this.element);
542
+ this.isVisible = true;
543
+ this.startUpdating();
544
+
545
+ // Add toggle functionality
546
+ var toggleBtn = this.element.querySelector('#perf-toggle');
547
+ toggleBtn.addEventListener('click', function () {
548
+ return _this2.toggleDetails();
549
+ });
550
+
551
+ // Start in collapsed state
552
+ this.toggleDetails();
553
+ }
554
+
555
+ /**
556
+ * Clean up any existing performance monitor UI elements in the document
557
+ */
558
+ }, {
559
+ key: "cleanupExistingElements",
560
+ value: function cleanupExistingElements() {
561
+ // Remove all existing performance monitor UI elements
562
+ var existingElements = document.querySelectorAll('#performance-monitor-ui');
563
+ existingElements.forEach(function (element) {
564
+ try {
565
+ if (element.parentNode) {
566
+ element.parentNode.removeChild(element);
567
+ }
568
+ } catch (error) {
569
+ console.warn('⚠️ Error removing existing performance monitor element:', error);
570
+ }
571
+ });
572
+ console.log("\uD83E\uDDF9 Cleaned up ".concat(existingElements.length, " existing performance monitor elements"));
573
+ }
574
+
575
+ /**
576
+ * Hide the performance UI overlay
577
+ */
578
+ }, {
579
+ key: "hide",
580
+ value: function hide() {
581
+ this.stopUpdating();
582
+ this.removeDOMElement();
583
+ this.isVisible = false;
584
+ }
585
+
586
+ /**
587
+ * Proper disposal method for complete cleanup
588
+ */
589
+ }, {
590
+ key: "dispose",
591
+ value: function dispose() {
592
+ console.log('🧹 Disposing PerformanceUI...');
593
+ this.hide();
594
+
595
+ // Clean up any remaining elements globally
596
+ this.cleanupExistingElements();
597
+
598
+ // Clean up all references
599
+ this.monitor = null;
600
+ this.container = null;
601
+ this.element = null;
602
+ console.log('✅ PerformanceUI disposed');
603
+ }
604
+
605
+ /**
606
+ * Stop the update interval
607
+ */
608
+ }, {
609
+ key: "stopUpdating",
610
+ value: function stopUpdating() {
611
+ if (this.updateInterval) {
612
+ clearInterval(this.updateInterval);
613
+ this.updateInterval = null;
614
+ }
615
+ }
616
+
617
+ /**
618
+ * Safely remove DOM element
619
+ */
620
+ }, {
621
+ key: "removeDOMElement",
622
+ value: function removeDOMElement() {
623
+ if (this.element) {
624
+ try {
625
+ // Check if element is still in the DOM and container exists
626
+ if (this.element.parentNode && this.container && this.container.contains(this.element)) {
627
+ this.container.removeChild(this.element);
628
+ } else if (this.element.parentNode) {
629
+ // Element exists but container reference is stale, remove from current parent
630
+ this.element.parentNode.removeChild(this.element);
631
+ }
632
+ } catch (error) {
633
+ console.warn('⚠️ Error removing performance UI element:', error);
634
+ // Try alternative removal method
635
+ try {
636
+ if (this.element.remove) {
637
+ this.element.remove();
638
+ }
639
+ } catch (fallbackError) {
640
+ console.warn('⚠️ Fallback removal also failed:', fallbackError);
641
+ }
642
+ }
643
+ this.element = null;
644
+ }
645
+ }
646
+
647
+ /**
648
+ * Toggle visibility of detailed stats
649
+ */
650
+ }, {
651
+ key: "toggleDetails",
652
+ value: function toggleDetails() {
653
+ var details = this.element.querySelector('#perf-details');
654
+ var isHidden = details.style.display === 'none';
655
+ details.style.display = isHidden ? 'block' : 'none';
656
+ var toggleBtn = this.element.querySelector('#perf-toggle');
657
+ toggleBtn.textContent = isHidden ? '▼' : '▲';
658
+ }
659
+
660
+ /**
661
+ * Start updating the UI
662
+ */
663
+ }, {
664
+ key: "startUpdating",
665
+ value: function startUpdating() {
666
+ var _this3 = this;
667
+ this.updateInterval = setInterval(function () {
668
+ if (_this3.isVisible && _this3.element) {
669
+ _this3.updateContent();
670
+ }
671
+ }, 500); // Update every 500ms
672
+ }
673
+
674
+ /**
675
+ * Update the UI content
676
+ */
677
+ }, {
678
+ key: "updateContent",
679
+ value: function updateContent() {
680
+ var summary = this.monitor.getSummary();
681
+
682
+ // Update main stats
683
+ this.updateElement('#fps-value', summary.fps.current);
684
+ this.updateElement('#frametime-value', summary.frameTime.current);
685
+ this.updateElement('#memory-value', summary.memory.heapUsed);
686
+ this.updateElement('#drawcalls-value', summary.drawCalls.current);
687
+
688
+ // Update detailed stats
689
+ this.updateElement('#fps-avg', summary.fps.average);
690
+ this.updateElement('#fps-min', summary.fps.min);
691
+ this.updateElement('#fps-max', summary.fps.max);
692
+ this.updateElement('#geometries-value', summary.memory.geometries);
693
+ this.updateElement('#textures-value', summary.memory.textures);
694
+ this.updateElement('#triangles-value', summary.drawCalls.triangles);
695
+ this.updateElement('#objects-value', summary.scene.objects);
696
+ this.updateElement('#meshes-value', summary.scene.meshes);
697
+
698
+ // Update performance indicators
699
+ this.updatePerformanceIndicators(summary);
700
+ }
701
+
702
+ /**
703
+ * Update individual element
704
+ */
705
+ }, {
706
+ key: "updateElement",
707
+ value: function updateElement(selector, value) {
708
+ var element = this.element.querySelector(selector);
709
+ if (element) {
710
+ element.textContent = value;
711
+ }
712
+ }
713
+
714
+ /**
715
+ * Update performance indicators (colors)
716
+ */
717
+ }, {
718
+ key: "updatePerformanceIndicators",
719
+ value: function updatePerformanceIndicators(summary) {
720
+ var fpsElement = this.element.querySelector('#fps-value');
721
+ var frameTimeElement = this.element.querySelector('#frametime-value');
722
+
723
+ // FPS indicator
724
+ if (fpsElement) {
725
+ var fps = summary.fps.current;
726
+ fpsElement.className = this.getPerformanceClass('fps', fps);
727
+ }
728
+
729
+ // Frame time indicator
730
+ if (frameTimeElement) {
731
+ var frameTime = parseFloat(summary.frameTime.current);
732
+ frameTimeElement.className = this.getPerformanceClass('frameTime', frameTime);
733
+ }
734
+ }
735
+
736
+ /**
737
+ * Get CSS class based on performance thresholds
738
+ */
739
+ }, {
740
+ key: "getPerformanceClass",
741
+ value: function getPerformanceClass(metric, value) {
742
+ var thresholds = this.monitor.thresholds[metric];
743
+ if (metric === 'fps') {
744
+ if (value >= thresholds.good) return 'perf-good';
745
+ if (value >= thresholds.warning) return 'perf-warning';
746
+ return 'perf-critical';
747
+ } else if (metric === 'frameTime') {
748
+ if (value <= thresholds.good) return 'perf-good';
749
+ if (value <= thresholds.warning) return 'perf-warning';
750
+ return 'perf-critical';
751
+ }
752
+ return '';
753
+ }
754
+ /**
755
+ * Get HTML for the UI
756
+ */
757
+ }, {
758
+ key: "getHTML",
759
+ value: function getHTML() {
760
+ return "\n <div class=\"perf-header\">\n <span class=\"perf-title\">Performance</span>\n <button id=\"perf-toggle\">\u25BC</button>\n </div>\n <div class=\"perf-main\">\n <div class=\"perf-stat\">\n <span class=\"perf-label\">FPS:</span>\n <span id=\"fps-value\" class=\"perf-value\">0</span>\n </div>\n <div class=\"perf-stat\">\n <span class=\"perf-label\">Frame:</span>\n <span id=\"frametime-value\" class=\"perf-value\">0ms</span>\n </div>\n <div class=\"perf-stat\">\n <span class=\"perf-label\">Memory:</span>\n <span id=\"memory-value\" class=\"perf-value\">0MB</span>\n </div>\n <div class=\"perf-stat\">\n <span class=\"perf-label\">Calls:</span>\n <span id=\"drawcalls-value\" class=\"perf-value\">0</span>\n </div>\n </div>\n <div id=\"perf-details\" class=\"perf-details\">\n <div class=\"perf-section\">\n <div class=\"perf-section-title\">FPS Stats</div>\n <div class=\"perf-detail\">Avg: <span id=\"fps-avg\">0</span></div>\n <div class=\"perf-detail\">Min: <span id=\"fps-min\">0</span></div>\n <div class=\"perf-detail\">Max: <span id=\"fps-max\">0</span></div>\n </div>\n <div class=\"perf-section\">\n <div class=\"perf-section-title\">Memory</div>\n <div class=\"perf-detail\">Geometries: <span id=\"geometries-value\">0</span></div>\n <div class=\"perf-detail\">Textures: <span id=\"textures-value\">0</span></div>\n </div>\n <div class=\"perf-section\">\n <div class=\"perf-section-title\">Rendering</div>\n <div class=\"perf-detail\">Triangles: <span id=\"triangles-value\">0</span></div>\n <div class=\"perf-detail\">Objects: <span id=\"objects-value\">0</span></div>\n <div class=\"perf-detail\">Meshes: <span id=\"meshes-value\">0</span></div>\n </div>\n </div>\n ";
761
+ }
762
+ /**
763
+ * Add CSS styles for the UI
764
+ */
765
+ }, {
766
+ key: "addStyles",
767
+ value: function addStyles() {
768
+ if (document.getElementById('performance-monitor-styles')) return;
769
+ var style = document.createElement('style');
770
+ style.id = 'performance-monitor-styles';
771
+ // Define theme-specific colors
772
+ var themes = {
773
+ dark: {
774
+ background: 'rgba(0, 0, 0, 0.8)',
775
+ color: 'white',
776
+ borderColor: 'rgba(255, 255, 255, 0.1)',
777
+ separatorColor: 'rgba(255, 255, 255, 0.2)',
778
+ sectionTitleColor: '#FFC107',
779
+ goodColor: '#4CAF50',
780
+ warningColor: '#FF9800',
781
+ criticalColor: '#F44336'
782
+ },
783
+ light: {
784
+ background: 'rgba(255, 255, 255, 0.95)',
785
+ color: '#333333',
786
+ borderColor: 'rgba(0, 0, 0, 0.15)',
787
+ separatorColor: 'rgba(0, 0, 0, 0.1)',
788
+ sectionTitleColor: '#1565C0',
789
+ goodColor: '#2E7D32',
790
+ warningColor: '#E65100',
791
+ criticalColor: '#C62828'
792
+ }
793
+ };
794
+ var currentTheme = themes[this.theme] || themes.dark;
795
+ style.textContent = " #performance-monitor-ui {\n position: fixed;\n bottom: 10px;\n right: 10px;\n background: ".concat(currentTheme.background, ";\n color: ").concat(currentTheme.color, ";\n font-family: 'Consolas', 'Monaco', 'Courier New', monospace;\n font-size: 12px;\n padding: 10px;\n border-radius: 5px;\n z-index: 10000;\n min-width: 150px;\n backdrop-filter: blur(5px);\n border: 1px solid ").concat(currentTheme.borderColor, ";\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n }\n\n .perf-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 8px;\n border-bottom: 1px solid ").concat(currentTheme.separatorColor, ";\n padding-bottom: 5px;\n }\n\n .perf-title {\n font-weight: bold;\n font-size: 14px;\n }\n\n #perf-toggle {\n background: none;\n border: none;\n color: ").concat(currentTheme.color, ";\n cursor: pointer;\n font-size: 12px;\n padding: 0;\n width: 20px;\n height: 20px;\n }\n\n .perf-main {\n display: grid;\n grid-template-columns: 1fr;\n gap: 4px;\n }\n\n .perf-stat {\n display: flex;\n justify-content: space-between;\n align-items: center;\n }\n\n .perf-label {\n opacity: 0.8;\n }\n\n .perf-value {\n font-weight: bold;\n text-align: right;\n min-width: 50px;\n } .perf-good {\n color: ").concat(currentTheme.goodColor, ";\n }\n\n .perf-warning {\n color: ").concat(currentTheme.warningColor, ";\n }\n\n .perf-critical {\n color: ").concat(currentTheme.criticalColor, ";\n }\n\n .perf-details {\n margin-top: 10px;\n padding-top: 8px;\n border-top: 1px solid ").concat(currentTheme.separatorColor, ";\n }\n\n .perf-section {\n margin-bottom: 8px;\n }\n\n .perf-section-title {\n font-weight: bold;\n font-size: 11px;\n margin-bottom: 3px;\n color: ").concat(currentTheme.sectionTitleColor, ";\n }\n\n .perf-detail {\n font-size: 10px;\n display: flex;\n justify-content: space-between;\n margin-bottom: 2px;\n opacity: 0.9;\n }\n ");
796
+ document.head.appendChild(style);
797
+ }
798
+
799
+ /**
800
+ * Change the theme of the performance UI
801
+ * @param {string} theme - 'light' or 'dark'
802
+ */
803
+ }, {
804
+ key: "setTheme",
805
+ value: function setTheme(theme) {
806
+ if (theme !== 'light' && theme !== 'dark') {
807
+ console.warn('Invalid theme. Use "light" or "dark"');
808
+ return;
809
+ }
810
+ this.theme = theme;
811
+
812
+ // Remove existing styles and reapply with new theme
813
+ var existingStyle = document.getElementById('performance-monitor-styles');
814
+ if (existingStyle) {
815
+ existingStyle.remove();
816
+ }
817
+ this.addStyles();
818
+ }
819
+
820
+ /**
821
+ * Static method to clean up all performance monitor UI elements globally
822
+ * Useful for hot-reload cleanup
823
+ */
824
+ }], [{
825
+ key: "cleanupAllInstances",
826
+ value: function cleanupAllInstances() {
827
+ console.log('🧹 PerformanceUI: Global cleanup of all instances...');
828
+
829
+ // Remove all performance monitor UI elements
830
+ var allElements = document.querySelectorAll('#performance-monitor-ui');
831
+ var cleanedCount = 0;
832
+ allElements.forEach(function (element) {
833
+ try {
834
+ if (element.parentNode) {
835
+ element.parentNode.removeChild(element);
836
+ cleanedCount++;
837
+ }
838
+ } catch (error) {
839
+ console.warn('⚠️ Error during global cleanup:', error);
840
+ }
841
+ });
842
+
843
+ // Remove global styles if no elements remain
844
+ var remainingElements = document.querySelectorAll('#performance-monitor-ui');
845
+ if (remainingElements.length === 0) {
846
+ var existingStyle = document.getElementById('performance-monitor-styles');
847
+ if (existingStyle) {
848
+ existingStyle.remove();
849
+ console.log('🧹 Performance monitor global styles removed');
850
+ }
851
+ }
852
+ console.log("\u2705 PerformanceUI: Global cleanup completed - removed ".concat(cleanedCount, " elements"));
853
+ return cleanedCount;
854
+ }
855
+ }]);
856
+ }();
857
+
858
+ export { PerformanceMonitor, PerformanceUI };