r3f-frame-profiler 1.0.2 → 1.0.3
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.
- package/dist/cjs/index.js +1 -61
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +7 -12890
- package/dist/esm/index.js.map +1 -1
- package/dist/index-D_LaF0YP.cjs +2 -0
- package/dist/index-D_LaF0YP.cjs.map +1 -0
- package/dist/index-o5zvhDta.js +4406 -0
- package/dist/index-o5zvhDta.js.map +1 -0
- package/dist/report-generator-BCq_enQo.js +283 -0
- package/dist/report-generator-BCq_enQo.js.map +1 -0
- package/dist/report-generator-BsoP53qp.cjs +61 -0
- package/dist/report-generator-BsoP53qp.cjs.map +1 -0
- package/dist/types/FrameProfiler.d.ts +2 -0
- package/dist/types/FrameProfiler.d.ts.map +1 -0
- package/dist/types/collectors/frame-time-collector.d.ts +41 -0
- package/dist/types/collectors/frame-time-collector.d.ts.map +1 -0
- package/dist/types/collectors/gpu-collector.d.ts +32 -0
- package/dist/types/collectors/gpu-collector.d.ts.map +1 -0
- package/dist/types/collectors/hot-path-detector.d.ts +42 -0
- package/dist/types/collectors/hot-path-detector.d.ts.map +1 -0
- package/dist/types/collectors/index.d.ts +7 -0
- package/dist/types/collectors/index.d.ts.map +1 -0
- package/dist/types/collectors/memory-collector.d.ts +49 -0
- package/dist/types/collectors/memory-collector.d.ts.map +1 -0
- package/dist/types/collectors/scene-collector.d.ts +47 -0
- package/dist/types/collectors/scene-collector.d.ts.map +1 -0
- package/dist/types/components/ReactProfiler.d.ts +12 -0
- package/dist/types/components/ReactProfiler.d.ts.map +1 -0
- package/dist/types/core/alert-system.d.ts +37 -0
- package/dist/types/core/alert-system.d.ts.map +1 -0
- package/dist/types/core/auto-instrumentation.d.ts +33 -0
- package/dist/types/core/auto-instrumentation.d.ts.map +1 -0
- package/dist/types/core/budget-manager.d.ts +78 -0
- package/dist/types/core/budget-manager.d.ts.map +1 -0
- package/dist/types/core/data-export.d.ts +24 -0
- package/dist/types/core/data-export.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +4 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/monitor-state.d.ts +21 -0
- package/dist/types/core/monitor-state.d.ts.map +1 -0
- package/dist/types/core/profiler.d.ts +83 -0
- package/dist/types/core/profiler.d.ts.map +1 -0
- package/dist/types/core/react-monitor.d.ts +51 -0
- package/dist/types/core/react-monitor.d.ts.map +1 -0
- package/dist/types/core/report-generator.d.ts +83 -0
- package/dist/types/core/report-generator.d.ts.map +1 -0
- package/dist/types/hooks/index.d.ts +17 -0
- package/dist/types/hooks/index.d.ts.map +1 -0
- package/dist/types/hooks/useAlerts.d.ts +11 -0
- package/dist/types/hooks/useAlerts.d.ts.map +1 -0
- package/dist/types/hooks/useBudgetChecker.d.ts +6 -0
- package/dist/types/hooks/useBudgetChecker.d.ts.map +1 -0
- package/dist/types/hooks/useFrameHistory.d.ts +2 -0
- package/dist/types/hooks/useFrameHistory.d.ts.map +1 -0
- package/dist/types/hooks/useFrameTime.d.ts +3 -0
- package/dist/types/hooks/useFrameTime.d.ts.map +1 -0
- package/dist/types/hooks/useGPUStats.d.ts +3 -0
- package/dist/types/hooks/useGPUStats.d.ts.map +1 -0
- package/dist/types/hooks/useHotPath.d.ts +3 -0
- package/dist/types/hooks/useHotPath.d.ts.map +1 -0
- package/dist/types/hooks/useMemoryHistory.d.ts +5 -0
- package/dist/types/hooks/useMemoryHistory.d.ts.map +1 -0
- package/dist/types/hooks/useMemoryStats.d.ts +3 -0
- package/dist/types/hooks/useMemoryStats.d.ts.map +1 -0
- package/dist/types/hooks/useMetricsCollector.d.ts +31 -0
- package/dist/types/hooks/useMetricsCollector.d.ts.map +1 -0
- package/dist/types/hooks/usePerformanceBudget.d.ts +20 -0
- package/dist/types/hooks/usePerformanceBudget.d.ts.map +1 -0
- package/dist/types/hooks/useProfiler.d.ts +5 -0
- package/dist/types/hooks/useProfiler.d.ts.map +1 -0
- package/dist/types/hooks/useR3FProfiler.d.ts +2 -0
- package/dist/types/hooks/useR3FProfiler.d.ts.map +1 -0
- package/dist/types/hooks/useR3FProfilerCollector.d.ts +2 -0
- package/dist/types/hooks/useR3FProfilerCollector.d.ts.map +1 -0
- package/dist/types/hooks/useR3FStatsCollector.d.ts +2 -0
- package/dist/types/hooks/useR3FStatsCollector.d.ts.map +1 -0
- package/dist/types/hooks/useReactProfiler.d.ts +3 -0
- package/dist/types/hooks/useReactProfiler.d.ts.map +1 -0
- package/dist/types/hooks/useReportMetric.d.ts +19 -0
- package/dist/types/hooks/useReportMetric.d.ts.map +1 -0
- package/dist/types/hooks/useSceneStats.d.ts +3 -0
- package/dist/types/hooks/useSceneStats.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/ui/PerformanceMonitor.d.ts +7 -0
- package/dist/types/ui/PerformanceMonitor.d.ts.map +1 -0
- package/dist/types/ui/components/AlertBadge.d.ts +9 -0
- package/dist/types/ui/components/AlertBadge.d.ts.map +1 -0
- package/dist/types/ui/components/MetricCard.d.ts +14 -0
- package/dist/types/ui/components/MetricCard.d.ts.map +1 -0
- package/dist/types/ui/components/SimpleChart.d.ts +13 -0
- package/dist/types/ui/components/SimpleChart.d.ts.map +1 -0
- package/dist/types/ui/components/Tabs.d.ts +15 -0
- package/dist/types/ui/components/Tabs.d.ts.map +1 -0
- package/dist/types/ui/components/index.d.ts +5 -0
- package/dist/types/ui/components/index.d.ts.map +1 -0
- package/dist/types/ui/panels/BudgetPanel.d.ts +2 -0
- package/dist/types/ui/panels/BudgetPanel.d.ts.map +1 -0
- package/dist/types/ui/panels/FramePanel.d.ts +2 -0
- package/dist/types/ui/panels/FramePanel.d.ts.map +1 -0
- package/dist/types/ui/panels/FrameTimePanel.d.ts +2 -0
- package/dist/types/ui/panels/FrameTimePanel.d.ts.map +1 -0
- package/dist/types/ui/panels/GPUPanel.d.ts +2 -0
- package/dist/types/ui/panels/GPUPanel.d.ts.map +1 -0
- package/dist/types/ui/panels/HotPathPanel.d.ts +2 -0
- package/dist/types/ui/panels/HotPathPanel.d.ts.map +1 -0
- package/dist/types/ui/panels/MemoryPanel.d.ts +2 -0
- package/dist/types/ui/panels/MemoryPanel.d.ts.map +1 -0
- package/dist/types/ui/panels/ReactPanel.d.ts +2 -0
- package/dist/types/ui/panels/ReactPanel.d.ts.map +1 -0
- package/dist/types/ui/panels/ScenePanel.d.ts +2 -0
- package/dist/types/ui/panels/ScenePanel.d.ts.map +1 -0
- package/dist/types/ui/panels/index.d.ts +9 -0
- package/dist/types/ui/panels/index.d.ts.map +1 -0
- package/dist/types/ui/styles/theme.d.ts +76 -0
- package/dist/types/ui/styles/theme.d.ts.map +1 -0
- package/dist/types/ui/visualizations/FrameGraph.d.ts +10 -0
- package/dist/types/ui/visualizations/FrameGraph.d.ts.map +1 -0
- package/dist/types/ui/visualizations/MemoryChart.d.ts +10 -0
- package/dist/types/ui/visualizations/MemoryChart.d.ts.map +1 -0
- package/dist/types/ui/visualizations/PerformanceChart.d.ts +16 -0
- package/dist/types/ui/visualizations/PerformanceChart.d.ts.map +1 -0
- package/dist/types/ui/visualizations/TimelineView.d.ts +7 -0
- package/dist/types/ui/visualizations/TimelineView.d.ts.map +1 -0
- package/dist/types/ui/visualizations/index.d.ts +5 -0
- package/dist/types/ui/visualizations/index.d.ts.map +1 -0
- package/package.json +12 -7
- package/README.md +0 -60
package/dist/cjs/index.js
CHANGED
|
@@ -1,62 +1,2 @@
|
|
|
1
|
-
"use strict";Object.
|
|
2
|
-
|
|
3
|
-
`;if(e+=`**Generated:** ${new Date(t.timestamp).toLocaleString()}
|
|
4
|
-
`,e+=`**Duration:** ${(t.duration/1e3).toFixed(1)}s
|
|
5
|
-
|
|
6
|
-
`,e+=`## Summary
|
|
7
|
-
|
|
8
|
-
`,e+=`- **FPS:** ${t.summary.avgFps.toFixed(1)} avg (${t.summary.minFps.toFixed(0)} min, ${t.summary.maxFps.toFixed(0)} max)
|
|
9
|
-
`,e+=`- **Frame Time:** ${t.summary.avgFrameTime.toFixed(2)}ms avg
|
|
10
|
-
`,e+=`- **Total Frames:** ${t.summary.totalFrames}
|
|
11
|
-
`,e+=`- **Memory:** ${t.memory.current.toFixed(1)}MB current, ${t.memory.peak.toFixed(1)}MB peak (${t.memory.trend})
|
|
12
|
-
|
|
13
|
-
`,t.issues.length>0){e+=`## 🚨 Issues Detected
|
|
14
|
-
|
|
15
|
-
`;const i=t.issues.filter(a=>a.severity==="critical"),r=t.issues.filter(a=>a.severity==="warning"),n=t.issues.filter(a=>a.severity==="info");i.length>0&&(e+=`### Critical
|
|
16
|
-
|
|
17
|
-
`,i.forEach(a=>{e+=`- **${a.metric}:** ${a.value.toFixed(2)} (threshold: ${a.threshold})
|
|
18
|
-
`,e+=` - 💡 ${a.suggestion}
|
|
19
|
-
`}),e+=`
|
|
20
|
-
`),r.length>0&&(e+=`### Warnings
|
|
21
|
-
|
|
22
|
-
`,r.forEach(a=>{e+=`- **${a.metric}:** ${a.value.toFixed(2)} (threshold: ${a.threshold})
|
|
23
|
-
`,e+=` - 💡 ${a.suggestion}
|
|
24
|
-
`}),e+=`
|
|
25
|
-
`),n.length>0&&(e+=`### Info
|
|
26
|
-
|
|
27
|
-
`,n.forEach(a=>{e+=`- ${a.metric}: ${a.value.toFixed(2)}
|
|
28
|
-
`}),e+=`
|
|
29
|
-
`)}else e+=`## ✅ No Issues Detected
|
|
30
|
-
|
|
31
|
-
`;if(t.hotspots.length>0){e+=`## 🔥 Performance Hotspots
|
|
32
|
-
|
|
33
|
-
`,e+=`Functions consuming the most time:
|
|
34
|
-
|
|
35
|
-
`,e+=`| # | Function | Avg | p95 | p99 | Max | % Frame | Jitter |
|
|
36
|
-
`,e+=`|---|----------|-----|-----|-----|-----|---------|--------|
|
|
37
|
-
`,t.hotspots.slice(0,10).forEach((n,a)=>{const l=n.variance>1?"⚠️ High":n.variance>.1?"~":"✓",o=n.percentOfFrame?.toFixed(1)||"0.0";e+=`| ${a+1} | **${n.name}** | ${n.avgTime.toFixed(2)}ms | ${(n.p95||0).toFixed(2)}ms | ${(n.p99||0).toFixed(2)}ms | ${n.maxTime.toFixed(2)}ms | ${o}% | ${l} |
|
|
38
|
-
`}),e+=`
|
|
39
|
-
`;const i=t.hotspots[0];i&&i.name!=="Frame"&&i.percentOfFrame>30&&(e+=`> [!WARNING]
|
|
40
|
-
`,e+=`> **${i.name}** consumes ${i.percentOfFrame.toFixed(1)}% of frame time. Consider optimizing this function.
|
|
41
|
-
|
|
42
|
-
`);const r=t.hotspots.filter(n=>n.variance>1&&n.name!=="Frame");r.length>0&&(e+=`> [!CAUTION]
|
|
43
|
-
`,e+=`> High jitter detected in: ${r.map(n=>n.name).join(", ")}. These cause frame rate stuttering.
|
|
44
|
-
|
|
45
|
-
`)}Object.keys(t.customMetrics).length>0&&(e+=`## 📈 Custom Metrics
|
|
46
|
-
|
|
47
|
-
`,Object.entries(t.customMetrics).forEach(([i,r])=>{e+=`- **${i}**: ${r.current.toFixed(2)} (min: ${r.min.toFixed(2)}, max: ${r.max.toFixed(2)}, avg: ${r.avg.toFixed(2)})
|
|
48
|
-
`}),e+=`
|
|
49
|
-
`),e+=`## 💡 Recommendations
|
|
50
|
-
|
|
51
|
-
`;const s=[...t.issues].sort((i,r)=>{const n={critical:3,warning:2,info:1};return n[r.severity]-n[i.severity]});return s.length>0?(e+=`Priority actions:
|
|
52
|
-
|
|
53
|
-
`,s.slice(0,5).forEach((i,r)=>{const n=i.severity==="critical"?"🔴":i.severity==="warning"?"⚠️":"ℹ️";e+=`${r+1}. ${n} ${i.suggestion}
|
|
54
|
-
`})):(e+=`✅ Performance looks good! Continue monitoring.
|
|
55
|
-
|
|
56
|
-
`,e+=`> [!TIP]
|
|
57
|
-
`,e+=`> Keep an eye on the "Hotspots" section to prevent future bottlenecks as your scene grows.
|
|
58
|
-
`),e}async copyReportToClipboard(){const t=this.generateMarkdownReport();try{await navigator.clipboard.writeText(t),console.log("✅ Report copied to clipboard!")}catch(e){console.error("Failed to copy report:",e),console.log(`📋 Report:
|
|
59
|
-
|
|
60
|
-
`+t)}}average(t){return t.length===0?0:t.reduce((e,s)=>e+s,0)/t.length}calculateTrend(t){if(t.length<10)return"stable";const e=t.slice(-10),s=t.slice(-20,-10);if(s.length===0)return"stable";const i=this.average(e),r=this.average(s),n=i-r,a=r*.1;return n>a?"increasing":n<-a?"decreasing":"stable"}detectIssues(t,e,s,i,r){const n=[];return t<30?n.push({severity:"critical",metric:"Average FPS",value:t,threshold:30,suggestion:"FPS critically low. Check frame time hotspots, reduce draw calls, optimize physics/collision detection."}):t<50&&n.push({severity:"warning",metric:"Average FPS",value:t,threshold:50,suggestion:"FPS below optimal. Consider reducing shadow quality, LOD distance, or particle count."}),e<t*.5&&n.push({severity:"warning",metric:"FPS Drops",value:e,threshold:t*.5,suggestion:"Severe FPS drops detected. Check for GC pauses, asset loading spikes, or physics explosions."}),s>33?n.push({severity:"critical",metric:"Frame Time",value:s,threshold:33,suggestion:"Frame time exceeds 33ms budget. Profile CPU-heavy operations."}):s>16&&n.push({severity:"warning",metric:"Frame Time",value:s,threshold:16,suggestion:"Frame time exceeds 60 FPS target (16.67ms). Optimize main thread work."}),i>500?n.push({severity:"critical",metric:"Memory Usage",value:i,threshold:500,suggestion:"High memory usage. Check for memory leaks, dispose unused textures/geometries."}):i>300&&n.push({severity:"warning",metric:"Memory Usage",value:i,threshold:300,suggestion:"Elevated memory usage. Consider texture compression, geometry pooling."}),n}extractHotspots(){const t=P.getData(),e=P.getRawData(),s=[],i=["Camera","Ball","Distance","Physics","Opacity","Following","(deg)","(m/s)","(rad/s)","(m)","Speed","Height","Moving","Occluded","Azimuth","Polar","Bodies","Colliders","Joints"];let r=0;if(e){const n=e.get("Frame");n&&n.calls>0&&(r=n.total/n.calls)}return t&&t.entries&&e&&t.entries.forEach(n=>{if(!i.some(l=>n.name.includes(l))){const o=e.get(n.name)?.times||[],d=[...o].sort((y,g)=>y-g),m=d.length>0&&d[Math.floor(d.length*.95)]||0,u=d.length>0&&d[Math.floor(d.length*.99)]||0,p=n.avg||0,f=o.length>1?o.reduce((y,g)=>y+Math.pow(g-p,2),0)/o.length:0,x=r>0?p/r*100:0;s.push({name:n.name,avgTime:p,maxTime:n.max||0,callCount:n.calls||0,p95:m,p99:u,variance:f,percentOfFrame:x})}}),s.sort((n,a)=>a.avgTime-n.avgTime)}analyzeCustomMetrics(){const t={};return this.customMetricHistory.forEach((e,s)=>{e.length>0&&(t[s]={min:Math.min(...e),max:Math.max(...e),avg:this.average(e),current:e[e.length-1]})}),t}reset(){this.startTime=Date.now(),this.frameCount=0,this.fpsSamples=[],this.frameTimeSamples=[],this.memorySamples=[],this.customMetricHistory.clear()}}const Ns=new Vs,Nt=Object.freeze(Object.defineProperty({__proto__:null,ReportGenerator:Vs,reportGenerator:Ns},Symbol.toStringTag,{value:"Module"}));class si{isPaused=!1;listeners=new Set;STORAGE_KEY="r3f-profiler-paused";constructor(){this.loadPauseState()}loadPauseState(){try{const t=localStorage.getItem(this.STORAGE_KEY);t!==null&&(this.isPaused=t==="true")}catch(t){console.warn("Failed to load pause state:",t)}}savePauseState(){try{localStorage.setItem(this.STORAGE_KEY,String(this.isPaused))}catch(t){console.warn("Failed to save pause state:",t)}}pause(){this.isPaused||(this.isPaused=!0,this.savePauseState(),this.notifyListeners())}resume(){this.isPaused&&(this.isPaused=!1,this.savePauseState(),this.notifyListeners())}toggle(){this.isPaused?this.resume():this.pause()}getPaused(){return this.isPaused}subscribe(t){return this.listeners.add(t),()=>{this.listeners.delete(t)}}notifyListeners(){this.listeners.forEach(t=>{try{t(this.isPaused)}catch(e){console.error("Error in monitor state listener:",e)}})}}const E=new si;function ii(c,t){return M.useCallback(P.wrap(c,t),[c,t])}function ri(c,t){return M.useCallback(P.wrapAsync(c,t),[c,t])}function Vt(){const[c,t]=M.useState(null);return M.useEffect(()=>{const e=()=>{if(!E.getPaused()){const n=P.getData();t(n)}},s=P.subscribe(n=>{E.getPaused()||t(n)});e();const i=setInterval(()=>{P.isEnabled()&&!E.getPaused()&&e()},100),r=E.subscribe(n=>{n||e()});return()=>{s(),r(),clearInterval(i)}},[]),c}function ni(c,t){const e=M.useRef(t||"useFrame"),s=M.useRef(void 0),i=M.useRef(c);M.useEffect(()=>{i.current=c,!t&&!s.current?(s.current=oi(),e.current=s.current):t&&(e.current=t)},[t,c]),Ht.useFrame((r,n)=>{if(P.isEnabled()){const a=performance.now();i.current(r,n);const l=performance.now();P.record(e.current,l-a)}else i.current(r,n)})}function oi(){try{const e=(new Error().stack||"").split(`
|
|
61
|
-
`);for(let s=3;s<Math.min(e.length,15);s++){const r=e[s].match(/\s+at\s+(\w+)/);if(r&&r[1]){const n=r[1];if(n!=="useProfiledFrame"&&n!=="useFrame"&&n!=="Object"&&n!=="getComponentName"&&!n.startsWith("_")&&n.length>1)return n}}}catch{}return"Unknown"}const ai=()=>{const c=M.useRef(performance.now());return Ht.useFrame(()=>{if(P.isEnabled()){const t=performance.now(),e=t-c.current;c.current=t,P.record("Frame",e),P.notify()}else c.current=performance.now()}),null};class li{renderer=null;lastStats=null;frameStartTime=0;setRenderer(t){this.renderer=t}getStats(){if(!this.renderer)return null;const t=this.renderer.info,e=t.memory,s=t.render,i="points"in s?s.points:0,r="lines"in s?s.lines:0;let n=0,a=0;if(e.textures&&this.renderer)try{n=e.textures*2*1024*1024}catch{n=e.textures*1024*1024}if(e.geometries&&this.renderer)try{a=(this.renderer.info.render.triangles||0)*100,a+=e.geometries*10*1024}catch{a=e.geometries*100*1024}const l={drawCalls:s.calls||0,triangles:s.triangles||0,points:i||0,lines:r||0,textures:e.textures||0,geometries:e.geometries||0,programs:t.programs?.length||0,memory:{textures:n,geometries:a,programs:0,total:n+a},frameTime:performance.now()-this.frameStartTime,timestamp:performance.now()};return this.lastStats=l,l}startFrame(){this.frameStartTime=performance.now()}endFrame(){}getLastStats(){return this.lastStats}reset(){this.lastStats=null}}const Xt=new li;const qs="182",Ze=0,hi=1,ss=1,is=100,rs=204,ns=205,os=3,ci=0,Us=300,as=1e3,le=1001,ls=1002,di=1006,ui=1008,mi=1009,pi=1015,fi=1023,Gs="",tt="srgb",hs="srgb-linear",cs="linear",_e="srgb",_t=7680,ds=519,us=35044,Zt=2e3,ms=2001;function gi(c){for(let t=c.length-1;t>=0;--t)if(c[t]>=65535)return!0;return!1}function ps(c){return document.createElementNS("http://www.w3.org/1999/xhtml",c)}const fs={};function V(...c){const t="THREE."+c.shift();console.warn(t,...c)}function At(...c){const t="THREE."+c.shift();console.error(t,...c)}function gs(...c){const t=c.join(" ");t in fs||(fs[t]=!0,V(...c))}class Te{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){const s=this._listeners;return s===void 0?!1:s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){const s=this._listeners;if(s===void 0)return;const i=s[t];if(i!==void 0){const r=i.indexOf(e);r!==-1&&i.splice(r,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const s=e[t.type];if(s!==void 0){t.target=this;const i=s.slice(0);for(let r=0,n=i.length;r<n;r++)i[r].call(this,t);t.target=null}}}const O=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];function Qt(){const c=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,s=Math.random()*4294967295|0;return(O[c&255]+O[c>>8&255]+O[c>>16&255]+O[c>>24&255]+"-"+O[t&255]+O[t>>8&255]+"-"+O[t>>16&15|64]+O[t>>24&255]+"-"+O[e&63|128]+O[e>>8&255]+"-"+O[e>>16&255]+O[e>>24&255]+O[s&255]+O[s>>8&255]+O[s>>16&255]+O[s>>24&255]).toLowerCase()}function B(c,t,e){return Math.max(t,Math.min(e,c))}function yi(c,t){return(c%t+t)%t}function Re(c,t,e){return(1-e)*c+e*t}function qt(c,t){switch(t.constructor){case Float32Array:return c;case Uint32Array:return c/4294967295;case Uint16Array:return c/65535;case Uint8Array:return c/255;case Int32Array:return Math.max(c/2147483647,-1);case Int16Array:return Math.max(c/32767,-1);case Int8Array:return Math.max(c/127,-1);default:throw new Error("Invalid component type.")}}function N(c,t){switch(t.constructor){case Float32Array:return c;case Uint32Array:return Math.round(c*4294967295);case Uint16Array:return Math.round(c*65535);case Uint8Array:return Math.round(c*255);case Int32Array:return Math.round(c*2147483647);case Int16Array:return Math.round(c*32767);case Int8Array:return Math.round(c*127);default:throw new Error("Invalid component type.")}}class st{constructor(t=0,e=0){st.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,s=this.y,i=t.elements;return this.x=i[0]*e+i[3]*s+i[6],this.y=i[1]*e+i[4]*s+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=B(this.x,t.x,e.x),this.y=B(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=B(this.x,t,e),this.y=B(this.y,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(B(s,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(B(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y;return e*e+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const s=Math.cos(e),i=Math.sin(e),r=this.x-t.x,n=this.y-t.y;return this.x=r*s-n*i+t.x,this.y=r*i+n*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Kt{constructor(t=0,e=0,s=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=s,this._w=i}static slerpFlat(t,e,s,i,r,n,a){let l=s[i+0],o=s[i+1],d=s[i+2],m=s[i+3],u=r[n+0],p=r[n+1],f=r[n+2],x=r[n+3];if(a<=0){t[e+0]=l,t[e+1]=o,t[e+2]=d,t[e+3]=m;return}if(a>=1){t[e+0]=u,t[e+1]=p,t[e+2]=f,t[e+3]=x;return}if(m!==x||l!==u||o!==p||d!==f){let y=l*u+o*p+d*f+m*x;y<0&&(u=-u,p=-p,f=-f,x=-x,y=-y);let g=1-a;if(y<.9995){const w=Math.acos(y),v=Math.sin(w);g=Math.sin(g*w)/v,a=Math.sin(a*w)/v,l=l*g+u*a,o=o*g+p*a,d=d*g+f*a,m=m*g+x*a}else{l=l*g+u*a,o=o*g+p*a,d=d*g+f*a,m=m*g+x*a;const w=1/Math.sqrt(l*l+o*o+d*d+m*m);l*=w,o*=w,d*=w,m*=w}}t[e]=l,t[e+1]=o,t[e+2]=d,t[e+3]=m}static multiplyQuaternionsFlat(t,e,s,i,r,n){const a=s[i],l=s[i+1],o=s[i+2],d=s[i+3],m=r[n],u=r[n+1],p=r[n+2],f=r[n+3];return t[e]=a*f+d*m+l*p-o*u,t[e+1]=l*f+d*u+o*m-a*p,t[e+2]=o*f+d*p+a*u-l*m,t[e+3]=d*f-a*m-l*u-o*p,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,i){return this._x=t,this._y=e,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const s=t._x,i=t._y,r=t._z,n=t._order,a=Math.cos,l=Math.sin,o=a(s/2),d=a(i/2),m=a(r/2),u=l(s/2),p=l(i/2),f=l(r/2);switch(n){case"XYZ":this._x=u*d*m+o*p*f,this._y=o*p*m-u*d*f,this._z=o*d*f+u*p*m,this._w=o*d*m-u*p*f;break;case"YXZ":this._x=u*d*m+o*p*f,this._y=o*p*m-u*d*f,this._z=o*d*f-u*p*m,this._w=o*d*m+u*p*f;break;case"ZXY":this._x=u*d*m-o*p*f,this._y=o*p*m+u*d*f,this._z=o*d*f+u*p*m,this._w=o*d*m-u*p*f;break;case"ZYX":this._x=u*d*m-o*p*f,this._y=o*p*m+u*d*f,this._z=o*d*f-u*p*m,this._w=o*d*m+u*p*f;break;case"YZX":this._x=u*d*m+o*p*f,this._y=o*p*m+u*d*f,this._z=o*d*f-u*p*m,this._w=o*d*m-u*p*f;break;case"XZY":this._x=u*d*m-o*p*f,this._y=o*p*m-u*d*f,this._z=o*d*f+u*p*m,this._w=o*d*m+u*p*f;break;default:V("Quaternion: .setFromEuler() encountered an unknown order: "+n)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],a=e[5],l=e[9],o=e[2],d=e[6],m=e[10],u=s+a+m;if(u>0){const p=.5/Math.sqrt(u+1);this._w=.25/p,this._x=(d-l)*p,this._y=(r-o)*p,this._z=(n-i)*p}else if(s>a&&s>m){const p=2*Math.sqrt(1+s-a-m);this._w=(d-l)/p,this._x=.25*p,this._y=(i+n)/p,this._z=(r+o)/p}else if(a>m){const p=2*Math.sqrt(1+a-s-m);this._w=(r-o)/p,this._x=(i+n)/p,this._y=.25*p,this._z=(l+d)/p}else{const p=2*Math.sqrt(1+m-s-a);this._w=(n-i)/p,this._x=(r+o)/p,this._y=(l+d)/p,this._z=.25*p}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<1e-8?(s=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(B(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(s===0)return this;const i=Math.min(1,e/s);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,i=t._y,r=t._z,n=t._w,a=e._x,l=e._y,o=e._z,d=e._w;return this._x=s*d+n*a+i*o-r*l,this._y=i*d+n*l+r*a-s*o,this._z=r*d+n*o+s*l-i*a,this._w=n*d-s*a-i*l-r*o,this._onChangeCallback(),this}slerp(t,e){if(e<=0)return this;if(e>=1)return this.copy(t);let s=t._x,i=t._y,r=t._z,n=t._w,a=this.dot(t);a<0&&(s=-s,i=-i,r=-r,n=-n,a=-a);let l=1-e;if(a<.9995){const o=Math.acos(a),d=Math.sin(o);l=Math.sin(l*o)/d,e=Math.sin(e*o)/d,this._x=this._x*l+s*e,this._y=this._y*l+i*e,this._z=this._z*l+r*e,this._w=this._w*l+n*e,this._onChangeCallback()}else this._x=this._x*l+s*e,this._y=this._y*l+i*e,this._z=this._z*l+r*e,this._w=this._w*l+n*e,this.normalize();return this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class S{constructor(t=0,e=0,s=0){S.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return s===void 0&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(ys.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(ys.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,a=t.z,l=t.w,o=2*(n*i-a*s),d=2*(a*e-r*i),m=2*(r*s-n*e);return this.x=e+l*o+n*m-a*d,this.y=s+l*d+a*o-r*m,this.z=i+l*m+r*d-n*o,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=B(this.x,t.x,e.x),this.y=B(this.y,t.y,e.y),this.z=B(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=B(this.x,t,e),this.y=B(this.y,t,e),this.z=B(this.z,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(B(s,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,a=e.y,l=e.z;return this.x=i*l-r*a,this.y=r*n-s*l,this.z=s*a-i*n,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return je.copy(this).projectOnVector(t),this.sub(je)}reflect(t){return this.sub(je.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(B(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const je=new S,ys=new Kt;class wt{constructor(t,e,s,i,r,n,a,l,o){wt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,s,i,r,n,a,l,o)}set(t,e,s,i,r,n,a,l,o){const d=this.elements;return d[0]=t,d[1]=i,d[2]=a,d[3]=e,d[4]=r,d[5]=l,d[6]=s,d[7]=n,d[8]=o,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],this}extractBasis(t,e,s){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),s.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],a=s[3],l=s[6],o=s[1],d=s[4],m=s[7],u=s[2],p=s[5],f=s[8],x=i[0],y=i[3],g=i[6],w=i[1],v=i[4],b=i[7],F=i[2],A=i[5],C=i[8];return r[0]=n*x+a*w+l*F,r[3]=n*y+a*v+l*A,r[6]=n*g+a*b+l*C,r[1]=o*x+d*w+m*F,r[4]=o*y+d*v+m*A,r[7]=o*g+d*b+m*C,r[2]=u*x+p*w+f*F,r[5]=u*y+p*v+f*A,r[8]=u*g+p*b+f*C,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],a=t[5],l=t[6],o=t[7],d=t[8];return e*n*d-e*a*o-s*r*d+s*a*l+i*r*o-i*n*l}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],a=t[5],l=t[6],o=t[7],d=t[8],m=d*n-a*o,u=a*l-d*r,p=o*r-n*l,f=e*m+s*u+i*p;if(f===0)return this.set(0,0,0,0,0,0,0,0,0);const x=1/f;return t[0]=m*x,t[1]=(i*o-d*s)*x,t[2]=(a*s-i*n)*x,t[3]=u*x,t[4]=(d*e-i*l)*x,t[5]=(i*r-a*e)*x,t[6]=p*x,t[7]=(s*l-o*e)*x,t[8]=(n*e-s*r)*x,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,s,i,r,n,a){const l=Math.cos(r),o=Math.sin(r);return this.set(s*l,s*o,-s*(l*n+o*a)+n+t,-i*o,i*l,-i*(-o*n+l*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(ke.makeScale(t,e)),this}rotate(t){return this.premultiply(ke.makeRotation(-t)),this}translate(t,e){return this.premultiply(ke.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,s,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,s=t.elements;for(let i=0;i<9;i++)if(e[i]!==s[i])return!1;return!0}fromArray(t,e=0){for(let s=0;s<9;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const ke=new wt,xs=new wt().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),bs=new wt().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function xi(){const c={enabled:!0,workingColorSpace:hs,spaces:{},convert:function(i,r,n){return this.enabled===!1||r===n||!r||!n||(this.spaces[r].transfer===_e&&(i.r=dt(i.r),i.g=dt(i.g),i.b=dt(i.b)),this.spaces[r].primaries!==this.spaces[n].primaries&&(i.applyMatrix3(this.spaces[r].toXYZ),i.applyMatrix3(this.spaces[n].fromXYZ)),this.spaces[n].transfer===_e&&(i.r=Wt(i.r),i.g=Wt(i.g),i.b=Wt(i.b))),i},workingToColorSpace:function(i,r){return this.convert(i,this.workingColorSpace,r)},colorSpaceToWorking:function(i,r){return this.convert(i,r,this.workingColorSpace)},getPrimaries:function(i){return this.spaces[i].primaries},getTransfer:function(i){return i===Gs?cs:this.spaces[i].transfer},getToneMappingMode:function(i){return this.spaces[i].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(i,r=this.workingColorSpace){return i.fromArray(this.spaces[r].luminanceCoefficients)},define:function(i){Object.assign(this.spaces,i)},_getMatrix:function(i,r,n){return i.copy(this.spaces[r].toXYZ).multiply(this.spaces[n].fromXYZ)},_getDrawingBufferColorSpace:function(i){return this.spaces[i].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(i=this.workingColorSpace){return this.spaces[i].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(i,r){return gs("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),c.workingToColorSpace(i,r)},toWorkingColorSpace:function(i,r){return gs("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),c.colorSpaceToWorking(i,r)}},t=[.64,.33,.3,.6,.15,.06],e=[.2126,.7152,.0722],s=[.3127,.329];return c.define({[hs]:{primaries:t,whitePoint:s,transfer:cs,toXYZ:xs,fromXYZ:bs,luminanceCoefficients:e,workingColorSpaceConfig:{unpackColorSpace:tt},outputColorSpaceConfig:{drawingBufferColorSpace:tt}},[tt]:{primaries:t,whitePoint:s,transfer:_e,toXYZ:xs,fromXYZ:bs,luminanceCoefficients:e,outputColorSpaceConfig:{drawingBufferColorSpace:tt}}}),c}const X=xi();function dt(c){return c<.04045?c*.0773993808:Math.pow(c*.9478672986+.0521327014,2.4)}function Wt(c){return c<.0031308?c*12.92:1.055*Math.pow(c,.41666)-.055}let Rt;class bi{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let s;if(t instanceof HTMLCanvasElement)s=t;else{Rt===void 0&&(Rt=ps("canvas")),Rt.width=t.width,Rt.height=t.height;const i=Rt.getContext("2d");t instanceof ImageData?i.putImageData(t,0,0):i.drawImage(t,0,0,t.width,t.height),s=Rt}return s.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=ps("canvas");e.width=t.width,e.height=t.height;const s=e.getContext("2d");s.drawImage(t,0,0,t.width,t.height);const i=s.getImageData(0,0,t.width,t.height),r=i.data;for(let n=0;n<r.length;n++)r[n]=dt(r[n]/255)*255;return s.putImageData(i,0,0),e}else if(t.data){const e=t.data.slice(0);for(let s=0;s<e.length;s++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[s]=Math.floor(dt(e[s]/255)*255):e[s]=dt(e[s]);return{data:e,width:t.width,height:t.height}}else return V("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let Si=0;class wi{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Si++}),this.uuid=Qt(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayHeight,e.displayWidth,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const s={uuid:this.uuid,url:""},i=this.data;if(i!==null){let r;if(Array.isArray(i)){r=[];for(let n=0,a=i.length;n<a;n++)i[n].isDataTexture?r.push(Be(i[n].image)):r.push(Be(i[n]))}else r=Be(i);s.url=r}return e||(t.images[this.uuid]=s),s}}function Be(c){return typeof HTMLImageElement<"u"&&c instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&c instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&c instanceof ImageBitmap?bi.getDataURL(c):c.data?{data:Array.from(c.data),width:c.width,height:c.height,type:c.data.constructor.name}:(V("Texture: Unable to serialize Texture."),{})}let Mi=0;const Pe=new S;class ut extends Te{constructor(t=ut.DEFAULT_IMAGE,e=ut.DEFAULT_MAPPING,s=le,i=le,r=di,n=ui,a=fi,l=mi,o=ut.DEFAULT_ANISOTROPY,d=Gs){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Mi++}),this.uuid=Qt(),this.name="",this.source=new wi(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=s,this.wrapT=i,this.magFilter=r,this.minFilter=n,this.anisotropy=o,this.format=a,this.internalFormat=null,this.type=l,this.offset=new st(0,0),this.repeat=new st(1,1),this.center=new st(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new wt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=d,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0}get width(){return this.source.getSize(Pe).x}get height(){return this.source.getSize(Pe).y}get depth(){return this.source.getSize(Pe).z}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const s=t[e];if(s===void 0){V(`Texture.setValues(): parameter '${e}' has value of undefined.`);continue}const i=this[e];if(i===void 0){V(`Texture.setValues(): property '${e}' does not exist.`);continue}i&&s&&i.isVector2&&s.isVector2||i&&s&&i.isVector3&&s.isVector3||i&&s&&i.isMatrix3&&s.isMatrix3?i.copy(s):this[e]=s}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const s={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(s.userData=this.userData),e||(t.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==Us)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case as:t.x=t.x-Math.floor(t.x);break;case le:t.x=t.x<0?0:1;break;case ls:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case as:t.y=t.y-Math.floor(t.y);break;case le:t.y=t.y<0?0:1;break;case ls:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}ut.DEFAULT_IMAGE=null;ut.DEFAULT_MAPPING=Us;ut.DEFAULT_ANISOTROPY=1;class te{constructor(t=0,e=0,s=0,i=1){te.prototype.isVector4=!0,this.x=t,this.y=e,this.z=s,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,s,i){return this.x=t,this.y=e,this.z=s,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=this.w,n=t.elements;return this.x=n[0]*e+n[4]*s+n[8]*i+n[12]*r,this.y=n[1]*e+n[5]*s+n[9]*i+n[13]*r,this.z=n[2]*e+n[6]*s+n[10]*i+n[14]*r,this.w=n[3]*e+n[7]*s+n[11]*i+n[15]*r,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,s,i,r;const l=t.elements,o=l[0],d=l[4],m=l[8],u=l[1],p=l[5],f=l[9],x=l[2],y=l[6],g=l[10];if(Math.abs(d-u)<.01&&Math.abs(m-x)<.01&&Math.abs(f-y)<.01){if(Math.abs(d+u)<.1&&Math.abs(m+x)<.1&&Math.abs(f+y)<.1&&Math.abs(o+p+g-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const v=(o+1)/2,b=(p+1)/2,F=(g+1)/2,A=(d+u)/4,C=(m+x)/4,j=(f+y)/4;return v>b&&v>F?v<.01?(s=0,i=.707106781,r=.707106781):(s=Math.sqrt(v),i=A/s,r=C/s):b>F?b<.01?(s=.707106781,i=0,r=.707106781):(i=Math.sqrt(b),s=A/i,r=j/i):F<.01?(s=.707106781,i=.707106781,r=0):(r=Math.sqrt(F),s=C/r,i=j/r),this.set(s,i,r,e),this}let w=Math.sqrt((y-f)*(y-f)+(m-x)*(m-x)+(u-d)*(u-d));return Math.abs(w)<.001&&(w=1),this.x=(y-f)/w,this.y=(m-x)/w,this.z=(u-d)/w,this.w=Math.acos((o+p+g-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=B(this.x,t.x,e.x),this.y=B(this.y,t.y,e.y),this.z=B(this.z,t.z,e.z),this.w=B(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=B(this.x,t,e),this.y=B(this.y,t,e),this.z=B(this.z,t,e),this.w=B(this.w,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(B(s,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this.w=t.w+(e.w-t.w)*s,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class ee{constructor(t=new S(1/0,1/0,1/0),e=new S(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,s=t.length;e<s;e+=3)this.expandByPoint(Z.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,s=t.count;e<s;e++)this.expandByPoint(Z.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,s=t.length;e<s;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const s=Z.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(s),this.max.copy(t).add(s),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return new this.constructor().copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const s=t.geometry;if(s!==void 0){const r=s.getAttribute("position");if(e===!0&&r!==void 0&&t.isInstancedMesh!==!0)for(let n=0,a=r.count;n<a;n++)t.isMesh===!0?t.getVertexPosition(n,Z):Z.fromBufferAttribute(r,n),Z.applyMatrix4(t.matrixWorld),this.expandByPoint(Z);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),he.copy(t.boundingBox)):(s.boundingBox===null&&s.computeBoundingBox(),he.copy(s.boundingBox)),he.applyMatrix4(t.matrixWorld),this.union(he)}const i=t.children;for(let r=0,n=i.length;r<n;r++)this.expandByObject(i[r],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,Z),Z.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,s;return t.normal.x>0?(e=t.normal.x*this.min.x,s=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,s=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,s+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,s+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,s+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,s+=t.normal.z*this.min.z),e<=-t.constant&&s>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Ut),ce.subVectors(this.max,Ut),jt.subVectors(t.a,Ut),kt.subVectors(t.b,Ut),Bt.subVectors(t.c,Ut),ft.subVectors(kt,jt),gt.subVectors(Bt,kt),vt.subVectors(jt,Bt);let e=[0,-ft.z,ft.y,0,-gt.z,gt.y,0,-vt.z,vt.y,ft.z,0,-ft.x,gt.z,0,-gt.x,vt.z,0,-vt.x,-ft.y,ft.x,0,-gt.y,gt.x,0,-vt.y,vt.x,0];return!Ee(e,jt,kt,Bt,ce)||(e=[1,0,0,0,1,0,0,0,1],!Ee(e,jt,kt,Bt,ce))?!1:(de.crossVectors(ft,gt),e=[de.x,de.y,de.z],Ee(e,jt,kt,Bt,ce))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Z).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(Z).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(ot[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),ot[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),ot[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),ot[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),ot[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),ot[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),ot[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),ot[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(ot),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const ot=[new S,new S,new S,new S,new S,new S,new S,new S],Z=new S,he=new ee,jt=new S,kt=new S,Bt=new S,ft=new S,gt=new S,vt=new S,Ut=new S,ce=new S,de=new S,zt=new S;function Ee(c,t,e,s,i){for(let r=0,n=c.length-3;r<=n;r+=3){zt.fromArray(c,r);const a=i.x*Math.abs(zt.x)+i.y*Math.abs(zt.y)+i.z*Math.abs(zt.z),l=t.dot(zt),o=e.dot(zt),d=s.dot(zt);if(Math.max(-Math.max(l,o,d),Math.min(l,o,d))>a)return!1}return!0}const vi=new ee,Gt=new S,De=new S;class Ys{constructor(t=new S,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const s=this.center;e!==void 0?s.copy(e):vi.setFromPoints(t).getCenter(s);let i=0;for(let r=0,n=t.length;r<n;r++)i=Math.max(i,s.distanceToSquared(t[r]));return this.radius=Math.sqrt(i),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const s=this.center.distanceToSquared(t);return e.copy(t),s>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;Gt.subVectors(t,this.center);const e=Gt.lengthSq();if(e>this.radius*this.radius){const s=Math.sqrt(e),i=(s-this.radius)*.5;this.center.addScaledVector(Gt,i/s),this.radius+=i}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(De.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(Gt.copy(t.center).add(De)),this.expandByPoint(Gt.copy(t.center).sub(De))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}const at=new S,Ie=new S,ue=new S,yt=new S,$e=new S,me=new S,Le=new S;class zi{constructor(t=new S,e=new S(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,at)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const s=e.dot(this.direction);return s<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,s)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=at.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(at.copy(this.origin).addScaledVector(this.direction,e),at.distanceToSquared(t))}distanceSqToSegment(t,e,s,i){Ie.copy(t).add(e).multiplyScalar(.5),ue.copy(e).sub(t).normalize(),yt.copy(this.origin).sub(Ie);const r=t.distanceTo(e)*.5,n=-this.direction.dot(ue),a=yt.dot(this.direction),l=-yt.dot(ue),o=yt.lengthSq(),d=Math.abs(1-n*n);let m,u,p,f;if(d>0)if(m=n*l-a,u=n*a-l,f=r*d,m>=0)if(u>=-f)if(u<=f){const x=1/d;m*=x,u*=x,p=m*(m+n*u+2*a)+u*(n*m+u+2*l)+o}else u=r,m=Math.max(0,-(n*u+a)),p=-m*m+u*(u+2*l)+o;else u=-r,m=Math.max(0,-(n*u+a)),p=-m*m+u*(u+2*l)+o;else u<=-f?(m=Math.max(0,-(-n*r+a)),u=m>0?-r:Math.min(Math.max(-r,-l),r),p=-m*m+u*(u+2*l)+o):u<=f?(m=0,u=Math.min(Math.max(-r,-l),r),p=u*(u+2*l)+o):(m=Math.max(0,-(n*r+a)),u=m>0?r:Math.min(Math.max(-r,-l),r),p=-m*m+u*(u+2*l)+o);else u=n>0?-r:r,m=Math.max(0,-(n*u+a)),p=-m*m+u*(u+2*l)+o;return s&&s.copy(this.origin).addScaledVector(this.direction,m),i&&i.copy(Ie).addScaledVector(ue,u),p}intersectSphere(t,e){at.subVectors(t.center,this.origin);const s=at.dot(this.direction),i=at.dot(at)-s*s,r=t.radius*t.radius;if(i>r)return null;const n=Math.sqrt(r-i),a=s-n,l=s+n;return l<0?null:a<0?this.at(l,e):this.at(a,e)}intersectsSphere(t){return t.radius<0?!1:this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const s=-(this.origin.dot(t.normal)+t.constant)/e;return s>=0?s:null}intersectPlane(t,e){const s=this.distanceToPlane(t);return s===null?null:this.at(s,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let s,i,r,n,a,l;const o=1/this.direction.x,d=1/this.direction.y,m=1/this.direction.z,u=this.origin;return o>=0?(s=(t.min.x-u.x)*o,i=(t.max.x-u.x)*o):(s=(t.max.x-u.x)*o,i=(t.min.x-u.x)*o),d>=0?(r=(t.min.y-u.y)*d,n=(t.max.y-u.y)*d):(r=(t.max.y-u.y)*d,n=(t.min.y-u.y)*d),s>n||r>i||((r>s||isNaN(s))&&(s=r),(n<i||isNaN(i))&&(i=n),m>=0?(a=(t.min.z-u.z)*m,l=(t.max.z-u.z)*m):(a=(t.max.z-u.z)*m,l=(t.min.z-u.z)*m),s>l||a>i)||((a>s||s!==s)&&(s=a),(l<i||i!==i)&&(i=l),i<0)?null:this.at(s>=0?s:i,e)}intersectsBox(t){return this.intersectBox(t,at)!==null}intersectTriangle(t,e,s,i,r){$e.subVectors(e,t),me.subVectors(s,t),Le.crossVectors($e,me);let n=this.direction.dot(Le),a;if(n>0){if(i)return null;a=1}else if(n<0)a=-1,n=-n;else return null;yt.subVectors(this.origin,t);const l=a*this.direction.dot(me.crossVectors(yt,me));if(l<0)return null;const o=a*this.direction.dot($e.cross(yt));if(o<0||l+o>n)return null;const d=-a*yt.dot(Le);return d<0?null:this.at(d/n,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class U{constructor(t,e,s,i,r,n,a,l,o,d,m,u,p,f,x,y){U.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,s,i,r,n,a,l,o,d,m,u,p,f,x,y)}set(t,e,s,i,r,n,a,l,o,d,m,u,p,f,x,y){const g=this.elements;return g[0]=t,g[4]=e,g[8]=s,g[12]=i,g[1]=r,g[5]=n,g[9]=a,g[13]=l,g[2]=o,g[6]=d,g[10]=m,g[14]=u,g[3]=p,g[7]=f,g[11]=x,g[15]=y,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new U().fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,s){return this.determinant()===0?(t.set(1,0,0),e.set(0,1,0),s.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this)}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){if(t.determinant()===0)return this.identity();const e=this.elements,s=t.elements,i=1/Pt.setFromMatrixColumn(t,0).length(),r=1/Pt.setFromMatrixColumn(t,1).length(),n=1/Pt.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),a=Math.sin(s),l=Math.cos(i),o=Math.sin(i),d=Math.cos(r),m=Math.sin(r);if(t.order==="XYZ"){const u=n*d,p=n*m,f=a*d,x=a*m;e[0]=l*d,e[4]=-l*m,e[8]=o,e[1]=p+f*o,e[5]=u-x*o,e[9]=-a*l,e[2]=x-u*o,e[6]=f+p*o,e[10]=n*l}else if(t.order==="YXZ"){const u=l*d,p=l*m,f=o*d,x=o*m;e[0]=u+x*a,e[4]=f*a-p,e[8]=n*o,e[1]=n*m,e[5]=n*d,e[9]=-a,e[2]=p*a-f,e[6]=x+u*a,e[10]=n*l}else if(t.order==="ZXY"){const u=l*d,p=l*m,f=o*d,x=o*m;e[0]=u-x*a,e[4]=-n*m,e[8]=f+p*a,e[1]=p+f*a,e[5]=n*d,e[9]=x-u*a,e[2]=-n*o,e[6]=a,e[10]=n*l}else if(t.order==="ZYX"){const u=n*d,p=n*m,f=a*d,x=a*m;e[0]=l*d,e[4]=f*o-p,e[8]=u*o+x,e[1]=l*m,e[5]=x*o+u,e[9]=p*o-f,e[2]=-o,e[6]=a*l,e[10]=n*l}else if(t.order==="YZX"){const u=n*l,p=n*o,f=a*l,x=a*o;e[0]=l*d,e[4]=x-u*m,e[8]=f*m+p,e[1]=m,e[5]=n*d,e[9]=-a*d,e[2]=-o*d,e[6]=p*m+f,e[10]=u-x*m}else if(t.order==="XZY"){const u=n*l,p=n*o,f=a*l,x=a*o;e[0]=l*d,e[4]=-m,e[8]=o*d,e[1]=u*m+x,e[5]=n*d,e[9]=p*m-f,e[2]=f*m-p,e[6]=a*d,e[10]=x*m+u}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Fi,t,Ci)}lookAt(t,e,s){const i=this.elements;return G.subVectors(t,e),G.lengthSq()===0&&(G.z=1),G.normalize(),xt.crossVectors(s,G),xt.lengthSq()===0&&(Math.abs(s.z)===1?G.x+=1e-4:G.z+=1e-4,G.normalize(),xt.crossVectors(s,G)),xt.normalize(),pe.crossVectors(G,xt),i[0]=xt.x,i[4]=pe.x,i[8]=G.x,i[1]=xt.y,i[5]=pe.y,i[9]=G.y,i[2]=xt.z,i[6]=pe.z,i[10]=G.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],a=s[4],l=s[8],o=s[12],d=s[1],m=s[5],u=s[9],p=s[13],f=s[2],x=s[6],y=s[10],g=s[14],w=s[3],v=s[7],b=s[11],F=s[15],A=i[0],C=i[4],j=i[8],z=i[12],T=i[1],k=i[5],W=i[9],I=i[13],rt=i[2],Tt=i[6],mt=i[10],pt=i[14],Mt=i[3],ne=i[7],oe=i[11],ae=i[15];return r[0]=n*A+a*T+l*rt+o*Mt,r[4]=n*C+a*k+l*Tt+o*ne,r[8]=n*j+a*W+l*mt+o*oe,r[12]=n*z+a*I+l*pt+o*ae,r[1]=d*A+m*T+u*rt+p*Mt,r[5]=d*C+m*k+u*Tt+p*ne,r[9]=d*j+m*W+u*mt+p*oe,r[13]=d*z+m*I+u*pt+p*ae,r[2]=f*A+x*T+y*rt+g*Mt,r[6]=f*C+x*k+y*Tt+g*ne,r[10]=f*j+x*W+y*mt+g*oe,r[14]=f*z+x*I+y*pt+g*ae,r[3]=w*A+v*T+b*rt+F*Mt,r[7]=w*C+v*k+b*Tt+F*ne,r[11]=w*j+v*W+b*mt+F*oe,r[15]=w*z+v*I+b*pt+F*ae,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[4],i=t[8],r=t[12],n=t[1],a=t[5],l=t[9],o=t[13],d=t[2],m=t[6],u=t[10],p=t[14],f=t[3],x=t[7],y=t[11],g=t[15],w=l*p-o*u,v=a*p-o*m,b=a*u-l*m,F=n*p-o*d,A=n*u-l*d,C=n*m-a*d;return e*(x*w-y*v+g*b)-s*(f*w-y*F+g*A)+i*(f*v-x*F+g*C)-r*(f*b-x*A+y*C)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,s){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],a=t[5],l=t[6],o=t[7],d=t[8],m=t[9],u=t[10],p=t[11],f=t[12],x=t[13],y=t[14],g=t[15],w=m*y*o-x*u*o+x*l*p-a*y*p-m*l*g+a*u*g,v=f*u*o-d*y*o-f*l*p+n*y*p+d*l*g-n*u*g,b=d*x*o-f*m*o+f*a*p-n*x*p-d*a*g+n*m*g,F=f*m*l-d*x*l-f*a*u+n*x*u+d*a*y-n*m*y,A=e*w+s*v+i*b+r*F;if(A===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const C=1/A;return t[0]=w*C,t[1]=(x*u*r-m*y*r-x*i*p+s*y*p+m*i*g-s*u*g)*C,t[2]=(a*y*r-x*l*r+x*i*o-s*y*o-a*i*g+s*l*g)*C,t[3]=(m*l*r-a*u*r-m*i*o+s*u*o+a*i*p-s*l*p)*C,t[4]=v*C,t[5]=(d*y*r-f*u*r+f*i*p-e*y*p-d*i*g+e*u*g)*C,t[6]=(f*l*r-n*y*r-f*i*o+e*y*o+n*i*g-e*l*g)*C,t[7]=(n*u*r-d*l*r+d*i*o-e*u*o-n*i*p+e*l*p)*C,t[8]=b*C,t[9]=(f*m*r-d*x*r-f*s*p+e*x*p+d*s*g-e*m*g)*C,t[10]=(n*x*r-f*a*r+f*s*o-e*x*o-n*s*g+e*a*g)*C,t[11]=(d*a*r-n*m*r-d*s*o+e*m*o+n*s*p-e*a*p)*C,t[12]=F*C,t[13]=(d*x*i-f*m*i+f*s*u-e*x*u-d*s*y+e*m*y)*C,t[14]=(f*a*i-n*x*i-f*s*l+e*x*l+n*s*y-e*a*y)*C,t[15]=(n*m*i-d*a*i+d*s*l-e*m*l-n*s*u+e*a*u)*C,this}scale(t){const e=this.elements,s=t.x,i=t.y,r=t.z;return e[0]*=s,e[4]*=i,e[8]*=r,e[1]*=s,e[5]*=i,e[9]*=r,e[2]*=s,e[6]*=i,e[10]*=r,e[3]*=s,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,s,i))}makeTranslation(t,e,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,a=t.y,l=t.z,o=r*n,d=r*a;return this.set(o*n+s,o*a-i*l,o*l+i*a,0,o*a+i*l,d*a+s,d*l-i*n,0,o*l-i*a,d*l+i*n,r*l*l+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,a=e._z,l=e._w,o=r+r,d=n+n,m=a+a,u=r*o,p=r*d,f=r*m,x=n*d,y=n*m,g=a*m,w=l*o,v=l*d,b=l*m,F=s.x,A=s.y,C=s.z;return i[0]=(1-(x+g))*F,i[1]=(p+b)*F,i[2]=(f-v)*F,i[3]=0,i[4]=(p-b)*A,i[5]=(1-(u+g))*A,i[6]=(y+w)*A,i[7]=0,i[8]=(f+v)*C,i[9]=(y-w)*C,i[10]=(1-(u+x))*C,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;if(t.x=i[12],t.y=i[13],t.z=i[14],this.determinant()===0)return s.set(1,1,1),e.identity(),this;let r=Pt.set(i[0],i[1],i[2]).length();const n=Pt.set(i[4],i[5],i[6]).length(),a=Pt.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),Q.copy(this);const o=1/r,d=1/n,m=1/a;return Q.elements[0]*=o,Q.elements[1]*=o,Q.elements[2]*=o,Q.elements[4]*=d,Q.elements[5]*=d,Q.elements[6]*=d,Q.elements[8]*=m,Q.elements[9]*=m,Q.elements[10]*=m,e.setFromRotationMatrix(Q),s.x=r,s.y=n,s.z=a,this}makePerspective(t,e,s,i,r,n,a=Zt,l=!1){const o=this.elements,d=2*r/(e-t),m=2*r/(s-i),u=(e+t)/(e-t),p=(s+i)/(s-i);let f,x;if(l)f=r/(n-r),x=n*r/(n-r);else if(a===Zt)f=-(n+r)/(n-r),x=-2*n*r/(n-r);else if(a===ms)f=-n/(n-r),x=-n*r/(n-r);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return o[0]=d,o[4]=0,o[8]=u,o[12]=0,o[1]=0,o[5]=m,o[9]=p,o[13]=0,o[2]=0,o[6]=0,o[10]=f,o[14]=x,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this}makeOrthographic(t,e,s,i,r,n,a=Zt,l=!1){const o=this.elements,d=2/(e-t),m=2/(s-i),u=-(e+t)/(e-t),p=-(s+i)/(s-i);let f,x;if(l)f=1/(n-r),x=n/(n-r);else if(a===Zt)f=-2/(n-r),x=-(n+r)/(n-r);else if(a===ms)f=-1/(n-r),x=-r/(n-r);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return o[0]=d,o[4]=0,o[8]=0,o[12]=u,o[1]=0,o[5]=m,o[9]=0,o[13]=p,o[2]=0,o[6]=0,o[10]=f,o[14]=x,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let i=0;i<16;i++)if(e[i]!==s[i])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const Pt=new S,Q=new U,Fi=new S(0,0,0),Ci=new S(1,1,1),xt=new S,pe=new S,G=new S,Ss=new U,ws=new Kt;class se{constructor(t=0,e=0,s=0,i=se.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,s,i=this._order){return this._x=t,this._y=e,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,s=!0){const i=t.elements,r=i[0],n=i[4],a=i[8],l=i[1],o=i[5],d=i[9],m=i[2],u=i[6],p=i[10];switch(e){case"XYZ":this._y=Math.asin(B(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-d,p),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(u,o),this._z=0);break;case"YXZ":this._x=Math.asin(-B(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(a,p),this._z=Math.atan2(l,o)):(this._y=Math.atan2(-m,r),this._z=0);break;case"ZXY":this._x=Math.asin(B(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-m,p),this._z=Math.atan2(-n,o)):(this._y=0,this._z=Math.atan2(l,r));break;case"ZYX":this._y=Math.asin(-B(m,-1,1)),Math.abs(m)<.9999999?(this._x=Math.atan2(u,p),this._z=Math.atan2(l,r)):(this._x=0,this._z=Math.atan2(-n,o));break;case"YZX":this._z=Math.asin(B(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-d,o),this._y=Math.atan2(-m,r)):(this._x=0,this._y=Math.atan2(a,p));break;case"XZY":this._z=Math.asin(-B(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(u,o),this._y=Math.atan2(a,r)):(this._x=Math.atan2(-d,p),this._y=0);break;default:V("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,s===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return Ss.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Ss,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return ws.setFromEuler(this),this.setFromQuaternion(ws,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}se.DEFAULT_ORDER="XYZ";class Ai{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let Ti=0;const Ms=new S,Et=new Kt,lt=new U,fe=new S,Yt=new S,_i=new S,Ri=new Kt,vs=new S(1,0,0),zs=new S(0,1,0),Fs=new S(0,0,1),Cs={type:"added"},ji={type:"removed"},Dt={type:"childadded",child:null},We={type:"childremoved",child:null};class it extends Te{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:Ti++}),this.uuid=Qt(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=it.DEFAULT_UP.clone();const t=new S,e=new se,s=new Kt,i=new S(1,1,1);function r(){s.setFromEuler(e,!1)}function n(){e.setFromQuaternion(s,void 0,!1)}e._onChange(r),s._onChange(n),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:s},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new U},normalMatrix:{value:new wt}}),this.matrix=new U,this.matrixWorld=new U,this.matrixAutoUpdate=it.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=it.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Ai,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Et.setFromAxisAngle(t,e),this.quaternion.multiply(Et),this}rotateOnWorldAxis(t,e){return Et.setFromAxisAngle(t,e),this.quaternion.premultiply(Et),this}rotateX(t){return this.rotateOnAxis(vs,t)}rotateY(t){return this.rotateOnAxis(zs,t)}rotateZ(t){return this.rotateOnAxis(Fs,t)}translateOnAxis(t,e){return Ms.copy(t).applyQuaternion(this.quaternion),this.position.add(Ms.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(vs,t)}translateY(t){return this.translateOnAxis(zs,t)}translateZ(t){return this.translateOnAxis(Fs,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(lt.copy(this.matrixWorld).invert())}lookAt(t,e,s){t.isVector3?fe.copy(t):fe.set(t,e,s);const i=this.parent;this.updateWorldMatrix(!0,!1),Yt.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?lt.lookAt(Yt,fe,this.up):lt.lookAt(fe,Yt,this.up),this.quaternion.setFromRotationMatrix(lt),i&&(lt.extractRotation(i.matrixWorld),Et.setFromRotationMatrix(lt),this.quaternion.premultiply(Et.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(At("Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(Cs),Dt.child=t,this.dispatchEvent(Dt),Dt.child=null):At("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let s=0;s<arguments.length;s++)this.remove(arguments[s]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(ji),We.child=t,this.dispatchEvent(We),We.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),lt.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),lt.multiply(t.parent.matrixWorld)),t.applyMatrix4(lt),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Cs),Dt.child=t,this.dispatchEvent(Dt),Dt.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let s=0,i=this.children.length;s<i;s++){const n=this.children[s].getObjectByProperty(t,e);if(n!==void 0)return n}}getObjectsByProperty(t,e,s=[]){this[t]===e&&s.push(this);const i=this.children;for(let r=0,n=i.length;r<n;r++)i[r].getObjectsByProperty(t,e,s);return s}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Yt,t,_i),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Yt,Ri,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let s=0,i=e.length;s<i;s++)e[s].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let s=0,i=e.length;s<i;s++)e[s].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let s=0,i=e.length;s<i;s++)e[s].updateMatrixWorld(t)}updateWorldMatrix(t,e){const s=this.parent;if(t===!0&&s!==null&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),e===!0){const i=this.children;for(let r=0,n=i.length;r<n;r++)i[r].updateWorldMatrix(!1,!0)}}toJSON(t){const e=t===void 0||typeof t=="string",s={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},s.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const i={};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.castShadow===!0&&(i.castShadow=!0),this.receiveShadow===!0&&(i.receiveShadow=!0),this.visible===!1&&(i.visible=!1),this.frustumCulled===!1&&(i.frustumCulled=!1),this.renderOrder!==0&&(i.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(a=>({...a})),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(t),i.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(i.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(i.boundingBox=this.boundingBox.toJSON()));function r(a,l){return a[l.uuid]===void 0&&(a[l.uuid]=l.toJSON(t)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=r(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const l=a.shapes;if(Array.isArray(l))for(let o=0,d=l.length;o<d;o++){const m=l[o];r(t.shapes,m)}else r(t.shapes,l)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(r(t.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let l=0,o=this.material.length;l<o;l++)a.push(r(t.materials,this.material[l]));i.material=a}else i.material=r(t.materials,this.material);if(this.children.length>0){i.children=[];for(let a=0;a<this.children.length;a++)i.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){i.animations=[];for(let a=0;a<this.animations.length;a++){const l=this.animations[a];i.animations.push(r(t.animations,l))}}if(e){const a=n(t.geometries),l=n(t.materials),o=n(t.textures),d=n(t.images),m=n(t.shapes),u=n(t.skeletons),p=n(t.animations),f=n(t.nodes);a.length>0&&(s.geometries=a),l.length>0&&(s.materials=l),o.length>0&&(s.textures=o),d.length>0&&(s.images=d),m.length>0&&(s.shapes=m),u.length>0&&(s.skeletons=u),p.length>0&&(s.animations=p),f.length>0&&(s.nodes=f)}return s.object=i,s;function n(a){const l=[];for(const o in a){const d=a[o];delete d.metadata,l.push(d)}return l}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let s=0;s<t.children.length;s++){const i=t.children[s];this.add(i.clone())}return this}}it.DEFAULT_UP=new S(0,1,0);it.DEFAULT_MATRIX_AUTO_UPDATE=!0;it.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const K=new S,ht=new S,Oe=new S,ct=new S,It=new S,$t=new S,As=new S,He=new S,Ve=new S,Ne=new S,qe=new te,Ue=new te,Ge=new te;class et{constructor(t=new S,e=new S,s=new S){this.a=t,this.b=e,this.c=s}static getNormal(t,e,s,i){i.subVectors(s,e),K.subVectors(t,e),i.cross(K);const r=i.lengthSq();return r>0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,s,i,r){K.subVectors(i,e),ht.subVectors(s,e),Oe.subVectors(t,e);const n=K.dot(K),a=K.dot(ht),l=K.dot(Oe),o=ht.dot(ht),d=ht.dot(Oe),m=n*o-a*a;if(m===0)return r.set(0,0,0),null;const u=1/m,p=(o*l-a*d)*u,f=(n*d-a*l)*u;return r.set(1-p-f,f,p)}static containsPoint(t,e,s,i){return this.getBarycoord(t,e,s,i,ct)===null?!1:ct.x>=0&&ct.y>=0&&ct.x+ct.y<=1}static getInterpolation(t,e,s,i,r,n,a,l){return this.getBarycoord(t,e,s,i,ct)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(r,ct.x),l.addScaledVector(n,ct.y),l.addScaledVector(a,ct.z),l)}static getInterpolatedAttribute(t,e,s,i,r,n){return qe.setScalar(0),Ue.setScalar(0),Ge.setScalar(0),qe.fromBufferAttribute(t,e),Ue.fromBufferAttribute(t,s),Ge.fromBufferAttribute(t,i),n.setScalar(0),n.addScaledVector(qe,r.x),n.addScaledVector(Ue,r.y),n.addScaledVector(Ge,r.z),n}static isFrontFacing(t,e,s,i){return K.subVectors(s,e),ht.subVectors(t,e),K.cross(ht).dot(i)<0}set(t,e,s){return this.a.copy(t),this.b.copy(e),this.c.copy(s),this}setFromPointsAndIndices(t,e,s,i){return this.a.copy(t[e]),this.b.copy(t[s]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,s,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,s),this.c.fromBufferAttribute(t,i),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return K.subVectors(this.c,this.b),ht.subVectors(this.a,this.b),K.cross(ht).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return et.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return et.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,i,r){return et.getInterpolation(t,this.a,this.b,this.c,e,s,i,r)}containsPoint(t){return et.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return et.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const s=this.a,i=this.b,r=this.c;let n,a;It.subVectors(i,s),$t.subVectors(r,s),He.subVectors(t,s);const l=It.dot(He),o=$t.dot(He);if(l<=0&&o<=0)return e.copy(s);Ve.subVectors(t,i);const d=It.dot(Ve),m=$t.dot(Ve);if(d>=0&&m<=d)return e.copy(i);const u=l*m-d*o;if(u<=0&&l>=0&&d<=0)return n=l/(l-d),e.copy(s).addScaledVector(It,n);Ne.subVectors(t,r);const p=It.dot(Ne),f=$t.dot(Ne);if(f>=0&&p<=f)return e.copy(r);const x=p*o-l*f;if(x<=0&&o>=0&&f<=0)return a=o/(o-f),e.copy(s).addScaledVector($t,a);const y=d*f-p*m;if(y<=0&&m-d>=0&&p-f>=0)return As.subVectors(r,i),a=(m-d)/(m-d+(p-f)),e.copy(i).addScaledVector(As,a);const g=1/(y+x+u);return n=x*g,a=u*g,e.copy(s).addScaledVector(It,n).addScaledVector($t,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const Js={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},bt={h:0,s:0,l:0},ge={h:0,s:0,l:0};function Ye(c,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?c+(t-c)*6*e:e<1/2?t:e<2/3?c+(t-c)*6*(2/3-e):c}class ie{constructor(t,e,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,s)}set(t,e,s){if(e===void 0&&s===void 0){const i=t;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(t,e,s);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=tt){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,X.colorSpaceToWorking(this,e),this}setRGB(t,e,s,i=X.workingColorSpace){return this.r=t,this.g=e,this.b=s,X.colorSpaceToWorking(this,i),this}setHSL(t,e,s,i=X.workingColorSpace){if(t=yi(t,1),e=B(e,0,1),s=B(s,0,1),e===0)this.r=this.g=this.b=s;else{const r=s<=.5?s*(1+e):s+e-s*e,n=2*s-r;this.r=Ye(n,r,t+1/3),this.g=Ye(n,r,t),this.b=Ye(n,r,t-1/3)}return X.colorSpaceToWorking(this,i),this}setStyle(t,e=tt){function s(r){r!==void 0&&parseFloat(r)<1&&V("Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const n=i[1],a=i[2];switch(n){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:V("Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const r=i[1],n=r.length;if(n===3)return this.setRGB(parseInt(r.charAt(0),16)/15,parseInt(r.charAt(1),16)/15,parseInt(r.charAt(2),16)/15,e);if(n===6)return this.setHex(parseInt(r,16),e);V("Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=tt){const s=Js[t.toLowerCase()];return s!==void 0?this.setHex(s,e):V("Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=dt(t.r),this.g=dt(t.g),this.b=dt(t.b),this}copyLinearToSRGB(t){return this.r=Wt(t.r),this.g=Wt(t.g),this.b=Wt(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=tt){return X.workingToColorSpace(H.copy(this),t),Math.round(B(H.r*255,0,255))*65536+Math.round(B(H.g*255,0,255))*256+Math.round(B(H.b*255,0,255))}getHexString(t=tt){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=X.workingColorSpace){X.workingToColorSpace(H.copy(this),e);const s=H.r,i=H.g,r=H.b,n=Math.max(s,i,r),a=Math.min(s,i,r);let l,o;const d=(a+n)/2;if(a===n)l=0,o=0;else{const m=n-a;switch(o=d<=.5?m/(n+a):m/(2-n-a),n){case s:l=(i-r)/m+(i<r?6:0);break;case i:l=(r-s)/m+2;break;case r:l=(s-i)/m+4;break}l/=6}return t.h=l,t.s=o,t.l=d,t}getRGB(t,e=X.workingColorSpace){return X.workingToColorSpace(H.copy(this),e),t.r=H.r,t.g=H.g,t.b=H.b,t}getStyle(t=tt){X.workingToColorSpace(H.copy(this),t);const e=H.r,s=H.g,i=H.b;return t!==tt?`color(${t} ${e.toFixed(3)} ${s.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(s*255)},${Math.round(i*255)})`}offsetHSL(t,e,s){return this.getHSL(bt),this.setHSL(bt.h+t,bt.s+e,bt.l+s)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,s){return this.r=t.r+(e.r-t.r)*s,this.g=t.g+(e.g-t.g)*s,this.b=t.b+(e.b-t.b)*s,this}lerpHSL(t,e){this.getHSL(bt),t.getHSL(ge);const s=Re(bt.h,ge.h,e),i=Re(bt.s,ge.s,e),r=Re(bt.l,ge.l,e);return this.setHSL(s,i,r),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,s=this.g,i=this.b,r=t.elements;return this.r=r[0]*e+r[3]*s+r[6]*i,this.g=r[1]*e+r[4]*s+r[7]*i,this.b=r[2]*e+r[5]*s+r[8]*i,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const H=new ie;ie.NAMES=Js;let ki=0;class Bi extends Te{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:ki++}),this.uuid=Qt(),this.name="",this.type="Material",this.blending=ss,this.side=Ze,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=rs,this.blendDst=ns,this.blendEquation=is,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new ie(0,0,0),this.blendAlpha=0,this.depthFunc=os,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=ds,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=_t,this.stencilZFail=_t,this.stencilZPass=_t,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(t!==void 0)for(const e in t){const s=t[e];if(s===void 0){V(`Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];if(i===void 0){V(`Material: '${e}' is not a property of THREE.${this.type}.`);continue}i&&i.isColor?i.set(s):i&&i.isVector3&&s&&s.isVector3?i.copy(s):this[e]=s}}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={textures:{},images:{}});const s={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};s.uuid=this.uuid,s.type=this.type,this.name!==""&&(s.name=this.name),this.color&&this.color.isColor&&(s.color=this.color.getHex()),this.roughness!==void 0&&(s.roughness=this.roughness),this.metalness!==void 0&&(s.metalness=this.metalness),this.sheen!==void 0&&(s.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(s.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(s.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(s.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(s.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(s.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(s.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(s.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(s.shininess=this.shininess),this.clearcoat!==void 0&&(s.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(s.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(s.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(s.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(s.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,s.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(s.sheenColorMap=this.sheenColorMap.toJSON(t).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(s.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(t).uuid),this.dispersion!==void 0&&(s.dispersion=this.dispersion),this.iridescence!==void 0&&(s.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(s.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(s.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(s.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(s.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),this.anisotropy!==void 0&&(s.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(s.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(s.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(s.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(s.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(s.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(s.lightMap=this.lightMap.toJSON(t).uuid,s.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(s.aoMap=this.aoMap.toJSON(t).uuid,s.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(s.bumpMap=this.bumpMap.toJSON(t).uuid,s.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(s.normalMap=this.normalMap.toJSON(t).uuid,s.normalMapType=this.normalMapType,s.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(s.displacementMap=this.displacementMap.toJSON(t).uuid,s.displacementScale=this.displacementScale,s.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(s.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(s.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(s.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(s.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(s.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(s.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(s.envMap=this.envMap.toJSON(t).uuid,this.combine!==void 0&&(s.combine=this.combine)),this.envMapRotation!==void 0&&(s.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(s.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(s.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(s.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(s.gradientMap=this.gradientMap.toJSON(t).uuid),this.transmission!==void 0&&(s.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(s.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(s.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(s.thicknessMap=this.thicknessMap.toJSON(t).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(s.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(s.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(s.size=this.size),this.shadowSide!==null&&(s.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(s.sizeAttenuation=this.sizeAttenuation),this.blending!==ss&&(s.blending=this.blending),this.side!==Ze&&(s.side=this.side),this.vertexColors===!0&&(s.vertexColors=!0),this.opacity<1&&(s.opacity=this.opacity),this.transparent===!0&&(s.transparent=!0),this.blendSrc!==rs&&(s.blendSrc=this.blendSrc),this.blendDst!==ns&&(s.blendDst=this.blendDst),this.blendEquation!==is&&(s.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(s.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(s.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(s.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(s.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(s.blendAlpha=this.blendAlpha),this.depthFunc!==os&&(s.depthFunc=this.depthFunc),this.depthTest===!1&&(s.depthTest=this.depthTest),this.depthWrite===!1&&(s.depthWrite=this.depthWrite),this.colorWrite===!1&&(s.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(s.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==ds&&(s.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(s.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==_t&&(s.stencilFail=this.stencilFail),this.stencilZFail!==_t&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==_t&&(s.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(s.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(s.rotation=this.rotation),this.polygonOffset===!0&&(s.polygonOffset=!0),this.polygonOffsetFactor!==0&&(s.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(s.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(s.linewidth=this.linewidth),this.dashSize!==void 0&&(s.dashSize=this.dashSize),this.gapSize!==void 0&&(s.gapSize=this.gapSize),this.scale!==void 0&&(s.scale=this.scale),this.dithering===!0&&(s.dithering=!0),this.alphaTest>0&&(s.alphaTest=this.alphaTest),this.alphaHash===!0&&(s.alphaHash=!0),this.alphaToCoverage===!0&&(s.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(s.premultipliedAlpha=!0),this.forceSinglePass===!0&&(s.forceSinglePass=!0),this.allowOverride===!1&&(s.allowOverride=!1),this.wireframe===!0&&(s.wireframe=!0),this.wireframeLinewidth>1&&(s.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(s.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(s.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(s.flatShading=!0),this.visible===!1&&(s.visible=!1),this.toneMapped===!1&&(s.toneMapped=!1),this.fog===!1&&(s.fog=!1),Object.keys(this.userData).length>0&&(s.userData=this.userData);function i(r){const n=[];for(const a in r){const l=r[a];delete l.metadata,n.push(l)}return n}if(e){const r=i(t.textures),n=i(t.images);r.length>0&&(s.textures=r),n.length>0&&(s.images=n)}return s}clone(){return new this.constructor().copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let s=null;if(e!==null){const i=e.length;s=new Array(i);for(let r=0;r!==i;++r)s[r]=e[r].clone()}return this.clippingPlanes=s,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.allowOverride=t.allowOverride,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){t===!0&&this.version++}}class Pi extends Bi{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new ie(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new se,this.combine=ci,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const D=new S,ye=new st;let Ei=0;class Ot{constructor(t,e,s=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:Ei++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=s,this.usage=us,this.updateRanges=[],this.gpuType=pi,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,s){t*=this.itemSize,s*=e.itemSize;for(let i=0,r=this.itemSize;i<r;i++)this.array[t+i]=e.array[s+i];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,s=this.count;e<s;e++)ye.fromBufferAttribute(this,e),ye.applyMatrix3(t),this.setXY(e,ye.x,ye.y);else if(this.itemSize===3)for(let e=0,s=this.count;e<s;e++)D.fromBufferAttribute(this,e),D.applyMatrix3(t),this.setXYZ(e,D.x,D.y,D.z);return this}applyMatrix4(t){for(let e=0,s=this.count;e<s;e++)D.fromBufferAttribute(this,e),D.applyMatrix4(t),this.setXYZ(e,D.x,D.y,D.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)D.fromBufferAttribute(this,e),D.applyNormalMatrix(t),this.setXYZ(e,D.x,D.y,D.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)D.fromBufferAttribute(this,e),D.transformDirection(t),this.setXYZ(e,D.x,D.y,D.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let s=this.array[t*this.itemSize+e];return this.normalized&&(s=qt(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=N(s,this.array)),this.array[t*this.itemSize+e]=s,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=qt(e,this.array)),e}setX(t,e){return this.normalized&&(e=N(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=qt(e,this.array)),e}setY(t,e){return this.normalized&&(e=N(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=qt(e,this.array)),e}setZ(t,e){return this.normalized&&(e=N(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=qt(e,this.array)),e}setW(t,e){return this.normalized&&(e=N(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,s){return t*=this.itemSize,this.normalized&&(e=N(e,this.array),s=N(s,this.array)),this.array[t+0]=e,this.array[t+1]=s,this}setXYZ(t,e,s,i){return t*=this.itemSize,this.normalized&&(e=N(e,this.array),s=N(s,this.array),i=N(i,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=i,this}setXYZW(t,e,s,i,r){return t*=this.itemSize,this.normalized&&(e=N(e,this.array),s=N(s,this.array),i=N(i,this.array),r=N(r,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=i,this.array[t+3]=r,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(t.name=this.name),this.usage!==us&&(t.usage=this.usage),t}}class Di extends Ot{constructor(t,e,s){super(new Uint16Array(t),e,s)}}class Ii extends Ot{constructor(t,e,s){super(new Uint32Array(t),e,s)}}class $i extends Ot{constructor(t,e,s){super(new Float32Array(t),e,s)}}let Li=0;const J=new U,Je=new it,Lt=new S,Y=new ee,Jt=new ee,L=new S;class Qe extends Te{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:Li++}),this.uuid=Qt(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(gi(t)?Ii:Di)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,s=0){this.groups.push({start:t,count:e,materialIndex:s})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const s=this.attributes.normal;if(s!==void 0){const r=new wt().getNormalMatrix(t);s.applyNormalMatrix(r),s.needsUpdate=!0}const i=this.attributes.tangent;return i!==void 0&&(i.transformDirection(t),i.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(t){return J.makeRotationFromQuaternion(t),this.applyMatrix4(J),this}rotateX(t){return J.makeRotationX(t),this.applyMatrix4(J),this}rotateY(t){return J.makeRotationY(t),this.applyMatrix4(J),this}rotateZ(t){return J.makeRotationZ(t),this.applyMatrix4(J),this}translate(t,e,s){return J.makeTranslation(t,e,s),this.applyMatrix4(J),this}scale(t,e,s){return J.makeScale(t,e,s),this.applyMatrix4(J),this}lookAt(t){return Je.lookAt(t),Je.updateMatrix(),this.applyMatrix4(Je.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Lt).negate(),this.translate(Lt.x,Lt.y,Lt.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const s=[];for(let i=0,r=t.length;i<r;i++){const n=t[i];s.push(n.x,n.y,n.z||0)}this.setAttribute("position",new $i(s,3))}else{const s=Math.min(t.length,e.count);for(let i=0;i<s;i++){const r=t[i];e.setXYZ(i,r.x,r.y,r.z||0)}t.length>e.count&&V("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new ee);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){At("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new S(-1/0,-1/0,-1/0),new S(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let s=0,i=e.length;s<i;s++){const r=e[s];Y.setFromBufferAttribute(r),this.morphTargetsRelative?(L.addVectors(this.boundingBox.min,Y.min),this.boundingBox.expandByPoint(L),L.addVectors(this.boundingBox.max,Y.max),this.boundingBox.expandByPoint(L)):(this.boundingBox.expandByPoint(Y.min),this.boundingBox.expandByPoint(Y.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&At('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new Ys);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){At("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new S,1/0);return}if(t){const s=this.boundingSphere.center;if(Y.setFromBufferAttribute(t),e)for(let r=0,n=e.length;r<n;r++){const a=e[r];Jt.setFromBufferAttribute(a),this.morphTargetsRelative?(L.addVectors(Y.min,Jt.min),Y.expandByPoint(L),L.addVectors(Y.max,Jt.max),Y.expandByPoint(L)):(Y.expandByPoint(Jt.min),Y.expandByPoint(Jt.max))}Y.getCenter(s);let i=0;for(let r=0,n=t.count;r<n;r++)L.fromBufferAttribute(t,r),i=Math.max(i,s.distanceToSquared(L));if(e)for(let r=0,n=e.length;r<n;r++){const a=e[r],l=this.morphTargetsRelative;for(let o=0,d=a.count;o<d;o++)L.fromBufferAttribute(a,o),l&&(Lt.fromBufferAttribute(t,o),L.add(Lt)),i=Math.max(i,s.distanceToSquared(L))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&At('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){At("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const s=e.position,i=e.normal,r=e.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new Ot(new Float32Array(4*s.count),4));const n=this.getAttribute("tangent"),a=[],l=[];for(let j=0;j<s.count;j++)a[j]=new S,l[j]=new S;const o=new S,d=new S,m=new S,u=new st,p=new st,f=new st,x=new S,y=new S;function g(j,z,T){o.fromBufferAttribute(s,j),d.fromBufferAttribute(s,z),m.fromBufferAttribute(s,T),u.fromBufferAttribute(r,j),p.fromBufferAttribute(r,z),f.fromBufferAttribute(r,T),d.sub(o),m.sub(o),p.sub(u),f.sub(u);const k=1/(p.x*f.y-f.x*p.y);isFinite(k)&&(x.copy(d).multiplyScalar(f.y).addScaledVector(m,-p.y).multiplyScalar(k),y.copy(m).multiplyScalar(p.x).addScaledVector(d,-f.x).multiplyScalar(k),a[j].add(x),a[z].add(x),a[T].add(x),l[j].add(y),l[z].add(y),l[T].add(y))}let w=this.groups;w.length===0&&(w=[{start:0,count:t.count}]);for(let j=0,z=w.length;j<z;++j){const T=w[j],k=T.start,W=T.count;for(let I=k,rt=k+W;I<rt;I+=3)g(t.getX(I+0),t.getX(I+1),t.getX(I+2))}const v=new S,b=new S,F=new S,A=new S;function C(j){F.fromBufferAttribute(i,j),A.copy(F);const z=a[j];v.copy(z),v.sub(F.multiplyScalar(F.dot(z))).normalize(),b.crossVectors(A,z);const k=b.dot(l[j])<0?-1:1;n.setXYZW(j,v.x,v.y,v.z,k)}for(let j=0,z=w.length;j<z;++j){const T=w[j],k=T.start,W=T.count;for(let I=k,rt=k+W;I<rt;I+=3)C(t.getX(I+0)),C(t.getX(I+1)),C(t.getX(I+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let s=this.getAttribute("normal");if(s===void 0)s=new Ot(new Float32Array(e.count*3),3),this.setAttribute("normal",s);else for(let u=0,p=s.count;u<p;u++)s.setXYZ(u,0,0,0);const i=new S,r=new S,n=new S,a=new S,l=new S,o=new S,d=new S,m=new S;if(t)for(let u=0,p=t.count;u<p;u+=3){const f=t.getX(u+0),x=t.getX(u+1),y=t.getX(u+2);i.fromBufferAttribute(e,f),r.fromBufferAttribute(e,x),n.fromBufferAttribute(e,y),d.subVectors(n,r),m.subVectors(i,r),d.cross(m),a.fromBufferAttribute(s,f),l.fromBufferAttribute(s,x),o.fromBufferAttribute(s,y),a.add(d),l.add(d),o.add(d),s.setXYZ(f,a.x,a.y,a.z),s.setXYZ(x,l.x,l.y,l.z),s.setXYZ(y,o.x,o.y,o.z)}else for(let u=0,p=e.count;u<p;u+=3)i.fromBufferAttribute(e,u+0),r.fromBufferAttribute(e,u+1),n.fromBufferAttribute(e,u+2),d.subVectors(n,r),m.subVectors(i,r),d.cross(m),s.setXYZ(u+0,d.x,d.y,d.z),s.setXYZ(u+1,d.x,d.y,d.z),s.setXYZ(u+2,d.x,d.y,d.z);this.normalizeNormals(),s.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,s=t.count;e<s;e++)L.fromBufferAttribute(t,e),L.normalize(),t.setXYZ(e,L.x,L.y,L.z)}toNonIndexed(){function t(a,l){const o=a.array,d=a.itemSize,m=a.normalized,u=new o.constructor(l.length*d);let p=0,f=0;for(let x=0,y=l.length;x<y;x++){a.isInterleavedBufferAttribute?p=l[x]*a.data.stride+a.offset:p=l[x]*d;for(let g=0;g<d;g++)u[f++]=o[p++]}return new Ot(u,d,m)}if(this.index===null)return V("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Qe,s=this.index.array,i=this.attributes;for(const a in i){const l=i[a],o=t(l,s);e.setAttribute(a,o)}const r=this.morphAttributes;for(const a in r){const l=[],o=r[a];for(let d=0,m=o.length;d<m;d++){const u=o[d],p=t(u,s);l.push(p)}e.morphAttributes[a]=l}e.morphTargetsRelative=this.morphTargetsRelative;const n=this.groups;for(let a=0,l=n.length;a<l;a++){const o=n[a];e.addGroup(o.start,o.count,o.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0){const l=this.parameters;for(const o in l)l[o]!==void 0&&(t[o]=l[o]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const s=this.attributes;for(const l in s){const o=s[l];t.data.attributes[l]=o.toJSON(t.data)}const i={};let r=!1;for(const l in this.morphAttributes){const o=this.morphAttributes[l],d=[];for(let m=0,u=o.length;m<u;m++){const p=o[m];d.push(p.toJSON(t.data))}d.length>0&&(i[l]=d,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const n=this.groups;n.length>0&&(t.data.groups=JSON.parse(JSON.stringify(n)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere=a.toJSON()),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const s=t.index;s!==null&&this.setIndex(s.clone());const i=t.attributes;for(const o in i){const d=i[o];this.setAttribute(o,d.clone(e))}const r=t.morphAttributes;for(const o in r){const d=[],m=r[o];for(let u=0,p=m.length;u<p;u++)d.push(m[u].clone(e));this.morphAttributes[o]=d}this.morphTargetsRelative=t.morphTargetsRelative;const n=t.groups;for(let o=0,d=n.length;o<d;o++){const m=n[o];this.addGroup(m.start,m.count,m.materialIndex)}const a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());const l=t.boundingSphere;return l!==null&&(this.boundingSphere=l.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Ts=new U,Ft=new zi,xe=new Ys,_s=new S,be=new S,Se=new S,we=new S,Xe=new S,Me=new S,Rs=new S,ve=new S;class js extends it{constructor(t=new Qe,e=new Pi){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),t.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),t.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}updateMorphTargets(){const e=this.geometry.morphAttributes,s=Object.keys(e);if(s.length>0){const i=e[s[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let r=0,n=i.length;r<n;r++){const a=i[r].name||String(r);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=r}}}}getVertexPosition(t,e){const s=this.geometry,i=s.attributes.position,r=s.morphAttributes.position,n=s.morphTargetsRelative;e.fromBufferAttribute(i,t);const a=this.morphTargetInfluences;if(r&&a){Me.set(0,0,0);for(let l=0,o=r.length;l<o;l++){const d=a[l],m=r[l];d!==0&&(Xe.fromBufferAttribute(m,t),n?Me.addScaledVector(Xe,d):Me.addScaledVector(Xe.sub(e),d))}e.add(Me)}return e}raycast(t,e){const s=this.geometry,i=this.material,r=this.matrixWorld;i!==void 0&&(s.boundingSphere===null&&s.computeBoundingSphere(),xe.copy(s.boundingSphere),xe.applyMatrix4(r),Ft.copy(t.ray).recast(t.near),!(xe.containsPoint(Ft.origin)===!1&&(Ft.intersectSphere(xe,_s)===null||Ft.origin.distanceToSquared(_s)>(t.far-t.near)**2))&&(Ts.copy(r).invert(),Ft.copy(t.ray).applyMatrix4(Ts),!(s.boundingBox!==null&&Ft.intersectsBox(s.boundingBox)===!1)&&this._computeIntersections(t,e,Ft)))}_computeIntersections(t,e,s){let i;const r=this.geometry,n=this.material,a=r.index,l=r.attributes.position,o=r.attributes.uv,d=r.attributes.uv1,m=r.attributes.normal,u=r.groups,p=r.drawRange;if(a!==null)if(Array.isArray(n))for(let f=0,x=u.length;f<x;f++){const y=u[f],g=n[y.materialIndex],w=Math.max(y.start,p.start),v=Math.min(a.count,Math.min(y.start+y.count,p.start+p.count));for(let b=w,F=v;b<F;b+=3){const A=a.getX(b),C=a.getX(b+1),j=a.getX(b+2);i=ze(this,g,t,s,o,d,m,A,C,j),i&&(i.faceIndex=Math.floor(b/3),i.face.materialIndex=y.materialIndex,e.push(i))}}else{const f=Math.max(0,p.start),x=Math.min(a.count,p.start+p.count);for(let y=f,g=x;y<g;y+=3){const w=a.getX(y),v=a.getX(y+1),b=a.getX(y+2);i=ze(this,n,t,s,o,d,m,w,v,b),i&&(i.faceIndex=Math.floor(y/3),e.push(i))}}else if(l!==void 0)if(Array.isArray(n))for(let f=0,x=u.length;f<x;f++){const y=u[f],g=n[y.materialIndex],w=Math.max(y.start,p.start),v=Math.min(l.count,Math.min(y.start+y.count,p.start+p.count));for(let b=w,F=v;b<F;b+=3){const A=b,C=b+1,j=b+2;i=ze(this,g,t,s,o,d,m,A,C,j),i&&(i.faceIndex=Math.floor(b/3),i.face.materialIndex=y.materialIndex,e.push(i))}}else{const f=Math.max(0,p.start),x=Math.min(l.count,p.start+p.count);for(let y=f,g=x;y<g;y+=3){const w=y,v=y+1,b=y+2;i=ze(this,n,t,s,o,d,m,w,v,b),i&&(i.faceIndex=Math.floor(y/3),e.push(i))}}}}function Wi(c,t,e,s,i,r,n,a){let l;if(t.side===hi?l=s.intersectTriangle(n,r,i,!0,a):l=s.intersectTriangle(i,r,n,t.side===Ze,a),l===null)return null;ve.copy(a),ve.applyMatrix4(c.matrixWorld);const o=e.ray.origin.distanceTo(ve);return o<e.near||o>e.far?null:{distance:o,point:ve.clone(),object:c}}function ze(c,t,e,s,i,r,n,a,l,o){c.getVertexPosition(a,be),c.getVertexPosition(l,Se),c.getVertexPosition(o,we);const d=Wi(c,t,e,s,be,Se,we,Rs);if(d){const m=new S;et.getBarycoord(Rs,be,Se,we,m),i&&(d.uv=et.getInterpolatedAttribute(i,a,l,o,m,new st)),r&&(d.uv1=et.getInterpolatedAttribute(r,a,l,o,m,new st)),n&&(d.normal=et.getInterpolatedAttribute(n,a,l,o,m,new S),d.normal.dot(s.direction)>0&&d.normal.multiplyScalar(-1));const u={a,b:l,c:o,normal:new S,materialIndex:0};et.getNormal(be,Se,we,u.normal),d.face=u,d.barycoord=m}return d}class Oi extends it{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new U,this.projectionMatrix=new U,this.projectionMatrixInverse=new U,this.coordinateSystem=Zt,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}}class ks extends it{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new ie(t),this.intensity=e}dispose(){this.dispatchEvent({type:"dispose"})}copy(t,e){return super.copy(t,e),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,e}}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:qs}}));typeof window<"u"&&(window.__THREE__?V("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=qs);class Hi{scene=null;setScene(t){this.scene=t}getStats(){if(!this.scene)return null;const t={total:0,meshes:0,lights:0,cameras:0,groups:0,other:0},e={total:0,byType:{}},s={total:0,totalSize:0,byFormat:{},environment:0,system:0},i={total:0,vertices:0,faces:0},r={meshes:0,total:0},n=new Set,a=new Set,l=new Set,o=new Set,d=y=>{if(!y||y.userData&&(y.userData.rapier||y.userData.physics||y.userData.type==="RigidBody"||y.userData.__r3f||y.userData.__reactInternalInstance||y.userData.internal===!0||y.userData.helper===!0))return!0;if(y.name){const g=y.name.toLowerCase();if(g.includes("__rapier")||g.includes("__physics")||g.includes("__r3f")||g.includes("__internal")||g.startsWith("_helper")||g.startsWith("_internal")||g.includes("__internal")||g.startsWith("_")||g.includes("collider")||g.includes("rigidbody")||g.includes("helper")||g.includes("debug"))return!0}return!!(y.type==="RigidBody"||y.isRigidBody||y.type&&y.type.includes("Helper"))},m=y=>{if(!(y instanceof js||y.isMesh))return!1;const g=y;return!(!g.geometry||!g.material||d(y))},u=y=>!(!(y instanceof ks||y.isLight)||d(y)||y.type&&y.type.includes("Helper")),p=(y,g=0,w=!1)=>{if(!y)return;const v=d(y)||w;if(y instanceof js||y.isMesh){const b=y;if(m(y)&&!o.has(b)){if(o.add(b),t.meshes++,y.visible&&r.meshes++,v||(t.total++,y.visible&&r.total++),b.geometry&&!l.has(b.geometry)){l.add(b.geometry),i.total++;const F=b.geometry;if(F.attributes&&F.attributes.position){const A=F.attributes.position.count||0;i.vertices+=A,F.index?i.faces+=Math.floor(F.index.count/3):i.faces+=Math.floor(A/3)}}b.material&&(Array.isArray(b.material)?b.material:[b.material]).forEach(A=>{if(A&&!n.has(A)){n.add(A),e.total++;const C=A.type||A.constructor.name||"Unknown";e.byType[C]=(e.byType[C]||0)+1,["map","normalMap","roughnessMap","metalnessMap","aoMap","emissiveMap","bumpMap","displacementMap","alphaMap","envMap","lightMap","specularMap","clearcoatMap","clearcoatNormalMap","clearcoatRoughnessMap","sheenColorMap","sheenRoughnessMap","transmissionMap","thicknessMap","iridescenceMap","iridescenceThicknessMap"].forEach(z=>{const T=A[z];if(T&&T instanceof ut&&!a.has(T)){a.add(T),s.total++;const k=this.estimateTextureSize(T);s.totalSize+=k;const W=T.format?.toString()||"unknown";s.byFormat[W]=(s.byFormat[W]||0)+1,(z==="envMap"||T.name?.toLowerCase().includes("env")||T.name?.toLowerCase().includes("environment"))&&s.environment++,(z==="lightMap"||T.name?.toLowerCase().includes("lightmap")||T.name?.toLowerCase().includes("system"))&&s.system++}}),Object.keys(A).forEach(z=>{const T=A[z];if(T&&T instanceof ut&&!a.has(T)){a.add(T),s.total++;const k=this.estimateTextureSize(T);s.totalSize+=k;const W=T.format?.toString()||"unknown";s.byFormat[W]=(s.byFormat[W]||0)+1,(z==="envMap"||T.name?.toLowerCase().includes("env")||T.name?.toLowerCase().includes("environment"))&&s.environment++,(z==="lightMap"||T.name?.toLowerCase().includes("lightmap")||T.name?.toLowerCase().includes("system"))&&s.system++}})}})}}else y instanceof ks||y.isLight?u(y)&&t.lights++:y instanceof Oi||y.isCamera?!v&&!y.type?.includes("Helper")&&t.cameras++:y.type==="Group"||y.isGroup?v||t.groups++:v||t.other++;g<20&&y.children&&y.children.length>0&&y.children.forEach(b=>{b&&p(b,g+1,v)})};this.scene.children.forEach(y=>{y&&p(y,0,!1)});const f=t.meshes>0?i.vertices/t.meshes:0,x=t.meshes>0?i.faces/t.meshes:0;return{objects:t,materials:e,textures:s,geometries:i,visible:r,complexity:{averageVerticesPerMesh:f,averageFacesPerMesh:x,totalDrawCalls:t.meshes},timestamp:performance.now()}}estimateTextureSize(t){if(!t.image)return 0;const e=t.image;if(!e)return 0;const s=e.width||1,i=e.height||1;let r=4;try{const n=Number(t.format);isNaN(n)||(n===1022&&(r=3),n===1021&&(r=1),n===1020&&(r=1))}catch{}return s*i*r}reset(){}}const Xs=new Hi;class Vi{renderer=null;lastStats=null;history=[];historySize=60;startTime=0;warmupPeriod=1e4;setRenderer(t){this.renderer=t,this.startTime===0&&(this.startTime=performance.now())}getStats(){const t=this.getJSHeapStats(),e=this.getGPUMemoryStats(),s=this.detectLeaks();if(!t&&!e)return null;const i={jsHeap:t||{used:0,total:0,limit:0,percentage:0},gpuMemory:e||{textures:0,geometries:0,total:0},leaks:s,timestamp:performance.now()};return this.lastStats=i,i}getJSHeapStats(){if(typeof performance>"u"||!performance.memory)return null;const t=performance.memory,e=t.usedJSHeapSize,s=t.totalJSHeapSize,i=t.jsHeapSizeLimit,r=i>0?e/i*100:0;return this.addToHistory(e),{used:e,total:s,limit:i,percentage:Math.min(100,Math.max(0,r))}}getGPUMemoryStats(){if(!this.renderer)return null;const t=this.renderer.info,e=t.memory,s=t.render;let i=0,r=0;if(e.textures&&this.renderer)try{i=e.textures*2*1024*1024}catch{i=e.textures*1024*1024}if(e.geometries&&this.renderer)try{r=(s.triangles||0)*100,r+=e.geometries*10*1024}catch{r=e.geometries*100*1024}return{textures:i,geometries:r,total:i+r}}addToHistory(t){const e=performance.now();this.history.push({timestamp:e,used:t}),this.history.length>this.historySize&&this.history.shift()}detectLeaks(){if(performance.now()-this.startTime<this.warmupPeriod)return{detected:!1,growthRate:0,trend:"stable"};if(this.history.length<20)return{detected:!1,growthRate:0,trend:"stable"};const e=this.history.slice(-10),s=this.history.slice(-30),i=e[0],r=e[e.length-1],n=(r.timestamp-i.timestamp)/1e3,a=r.used-i.used,l=n>0?a/n:0,o=s[0],d=s[s.length-1],m=(d.timestamp-o.timestamp)/1e3,u=d.used-o.used,p=m>0?u/m:0,f=(l+p)/2,x=33*1024,y=l>0&&p>0,g=f>x&&y;let w="stable";return Math.abs(f)<2048?w="stable":f>0?w="increasing":w="decreasing",{detected:g,growthRate:f,trend:w}}getLastStats(){return this.lastStats}reset(){this.lastStats=null,this.history=[],this.startTime=0}}const Ce=new Vi;class Ni{phases=new Map;timeline=[];frameStartTime=0;lastFrameTime=0;currentInterval=0;lastBreakdown=null;maxTimelineEntries=100;startFrame(){const t=performance.now();this.lastFrameTime>0&&(this.currentInterval=t-this.lastFrameTime),this.lastFrameTime=t,this.frameStartTime=t,this.phases.clear(),this.timeline=[]}startPhase(t){const e=performance.now();this.phases.set(t,{start:e})}endPhase(t){const e=this.phases.get(t);if(!e)return;const s=performance.now();e.end=s;const i=s-e.start;this.timeline.push({name:t,start:e.start,end:s,duration:i})}endFrame(){const e=performance.now()-this.frameStartTime,s=this.currentInterval>0?this.currentInterval:e>0?e:16.66,i={react:this.getPhaseDuration("react"),update:this.getPhaseDuration("update"),physics:this.getPhaseDuration("physics"),render:this.getPhaseDuration("render"),postProcess:this.getPhaseDuration("postProcess"),other:0},r=Object.values(i).reduce((a,l)=>a+l,0);i.other=Math.max(0,e-r);const n={total:e,interval:s,phases:i,timeline:[...this.timeline].slice(-this.maxTimelineEntries),timestamp:this.frameStartTime};return this.lastBreakdown=n,n}getPhaseDuration(t){const e=this.phases.get(t);return!e||e.end===void 0?0:e.end-e.start}measure(t,e){this.startPhase(t);try{return e()}finally{this.endPhase(t)}}async measureAsync(t,e){this.startPhase(t);try{return await e()}finally{this.endPhase(t)}}getLastBreakdown(){return this.lastBreakdown}reset(){this.phases.clear(),this.timeline=[],this.lastBreakdown=null}}const q=new Ni;class qi{enabled=!1;reactPhaseStart=0;isReactRendering=!1;isUpdating=!1;isPhysicsRunning=!1;isRendering=!1;mutationObserver=null;enable(){this.enabled||(this.enabled=!0,this.setupReactInstrumentation(),this.setupThreeJSInstrumentation(),this.setupPhysicsInstrumentation())}disable(){this.enabled&&(this.enabled=!1,this.cleanup())}setupReactInstrumentation(){if(typeof window>"u")return;const t=document.getElementById("root")||document.body;if(t&&(this.mutationObserver=new MutationObserver(()=>{this.isReactRendering||this.startReactPhase()}),this.mutationObserver.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!1})),performance.mark){const e=performance.mark;performance.mark=((s,i)=>((s.includes("react")||s.includes("React"))&&(this.isReactRendering||this.startReactPhase()),e.call(performance,s,i)))}}setupThreeJSInstrumentation(){}setupPhysicsInstrumentation(){}startFrame(){this.enabled&&q.startFrame()}startReactPhase(){!this.enabled||this.isReactRendering||(this.isReactRendering=!0,this.reactPhaseStart=performance.now(),q.startPhase("react"))}endReactPhase(){!this.enabled||!this.isReactRendering||(this.isReactRendering=!1,q.endPhase("react"))}onReactRender(t){this.enabled&&(this.isReactRendering||this.startReactPhase(),setTimeout(()=>{this.isReactRendering&&performance.now()-this.reactPhaseStart>t&&this.endReactPhase()},0))}startUpdatePhase(){!this.enabled||this.isUpdating||(this.isUpdating=!0,q.startPhase("update"))}endUpdatePhase(){!this.enabled||!this.isUpdating||(this.isUpdating=!1,q.endPhase("update"))}startPhysicsPhase(){!this.enabled||this.isPhysicsRunning||(this.isPhysicsRunning=!0,q.startPhase("physics"))}endPhysicsPhase(){!this.enabled||!this.isPhysicsRunning||(this.isPhysicsRunning=!1,q.endPhase("physics"))}startRenderPhase(){!this.enabled||this.isRendering||(this.isRendering=!0,q.startPhase("render"))}endRenderPhase(){!this.enabled||!this.isRendering||(this.isRendering=!1,q.endPhase("render"),q.endFrame())}cleanup(){this.isReactRendering=!1,this.isUpdating=!1,this.isPhysicsRunning=!1,this.isRendering=!1,this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null)}isActive(){return this.enabled}}const Ct=new qi,Ui=()=>{const{gl:c,scene:t}=Ht.useThree();return M.useEffect(()=>{c&&(Xt.setRenderer(c),Ce.setRenderer(c))},[c]),M.useEffect(()=>{t&&Xs.setScene(t)},[t]),M.useEffect(()=>(Ct.enable(),()=>{Ct.disable()}),[]),Ht.useFrame((e,s)=>{c&&!E.getPaused()&&(q.startFrame(),Ct.startUpdatePhase(),Ct.endUpdatePhase(),Ct.startRenderPhase(),Xt.startFrame(),requestAnimationFrame(()=>{if(!E.getPaused()){Ct.endRenderPhase();const i=q.endFrame();if(Xt.endFrame(),Xt.getStats(),Ce.getStats(),i){const r=i.interval||i.total,n=Math.max(r,.001),a=1e3/n,l=a>500&&i.total<16?0:a;let o;typeof performance<"u"&&performance.memory&&(o=performance.memory.usedJSHeapSize/(1024*1024)),P.isEnabled()&&P.recordFrameStats(l,n,o)}}}))}),null};function Gi(c={}){const{updateInterval:t=3,debug:e=!1}=c,s=M.useRef(0),i=M.useRef(null),r=n=>{i.current=n};return Ht.useFrame((n,a)=>{if(P.isEnabled()&&(s.current++,s.current%t===0&&i.current))try{const l=i.current();l&&(Object.entries(l).forEach(([o,d])=>{P.recordMetricForReport(o,d)}),P.notify(),e&&console.log("[useMetricsCollector] Recorded metrics:",l))}catch(l){console.error("[useMetricsCollector] Error collecting metrics:",l)}}),r}function Yi(c,t,e={}){const{updateInterval:s=3}=e,i=M.useRef(0),r=M.useRef(t);r.current=t,Ht.useFrame(()=>{if(P.isEnabled()&&(i.current++,i.current%s===0))try{const n=r.current();P.recordMetricForReport(c,n),P.notify()}catch{}})}const Ji={colors:{background:"rgba(15, 15, 15, 0.95)",surface:"rgba(26, 26, 26, 0.98)",surfaceElevated:"rgba(35, 35, 35, 0.98)",text:"#ffffff",textSecondary:"rgba(255, 255, 255, 0.7)",textTertiary:"rgba(255, 255, 255, 0.5)",border:"rgba(255, 255, 255, 0.1)",borderLight:"rgba(255, 255, 255, 0.05)",primary:"#3b82f6",primaryHover:"#2563eb",success:"#10b981",warning:"#f59e0b",error:"#ef4444",info:"#06b6d4",accent:"#8b5cf6"},shadows:{md:"0 4px 6px rgba(0, 0, 0, 0.4)",xl:"0 20px 25px rgba(0, 0, 0, 0.6)"},borderRadius:{sm:"4px",md:"8px",lg:"12px"},spacing:{xs:"4px",sm:"8px",md:"16px",lg:"24px"},typography:{fontFamilyMono:'"SF Mono", "Monaco", "Inconsolata", "Roboto Mono", "Source Code Pro", monospace',fontSize:{xs:"10px",sm:"12px",md:"14px",lg:"16px"}},transitions:{fast:"150ms ease",normal:"250ms ease"},zIndex:{base:1e4}},$=Ji;function Bs(c,t){return c<=t.good?$.colors.success:c<=t.warning?$.colors.warning:$.colors.error}function R(c,t=2){return c.toFixed(t)}const _=({label:c,value:t,unit:e,trend:s,status:i,color:r,icon:n,onClick:a,className:l=""})=>{const o=$;let d=r;!d&&i&&(d=i==="good"?o.colors.success:i==="warning"?o.colors.warning:o.colors.error);const m=typeof t=="number"?t.toLocaleString():t,u=e?` ${e}`:"";return h.jsxs("div",{onClick:a,className:l,style:{backgroundColor:o.colors.surface,border:`1px solid ${o.colors.border}`,borderRadius:o.borderRadius.md,padding:o.spacing.md,cursor:a?"pointer":"default",transition:o.transitions.fast,position:"relative",overflow:"hidden"},onMouseEnter:p=>{a&&(p.currentTarget.style.backgroundColor=o.colors.surfaceElevated,p.currentTarget.style.transform="translateY(-2px)",p.currentTarget.style.boxShadow=o.shadows.md)},onMouseLeave:p=>{a&&(p.currentTarget.style.backgroundColor=o.colors.surface,p.currentTarget.style.transform="translateY(0)",p.currentTarget.style.boxShadow="none")},children:[n&&h.jsx("div",{style:{position:"absolute",top:o.spacing.sm,right:o.spacing.sm,opacity:.3},children:n}),h.jsx("div",{style:{fontSize:o.typography.fontSize.sm,color:o.colors.textSecondary,marginBottom:o.spacing.xs,fontWeight:500},children:c}),h.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:o.spacing.xs},children:[h.jsx("div",{style:{fontSize:o.typography.fontSize.lg,fontWeight:"bold",color:d||o.colors.text,fontFamily:o.typography.fontFamilyMono},children:m}),e&&h.jsx("div",{style:{fontSize:o.typography.fontSize.sm,color:o.colors.textTertiary},children:u}),s&&h.jsx("div",{style:{fontSize:o.typography.fontSize.xs,color:s==="up"?o.colors.error:s==="down"?o.colors.success:o.colors.textTertiary,marginLeft:"auto"},children:s==="up"?"↑":s==="down"?"↓":"→"})]}),d&&h.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,height:"2px",backgroundColor:d}})]})},Xi=({tabs:c,activeTab:t,onTabChange:e,className:s=""})=>{const i=$;return h.jsx("div",{className:s,style:{position:"relative"},children:h.jsx("div",{style:{display:"flex",gap:i.spacing.xs,borderBottom:`1px solid ${i.colors.border}`,paddingBottom:i.spacing.xs},children:c.map(r=>{const n=r.id===t;return h.jsxs("button",{onClick:()=>e(r.id),style:{display:"flex",alignItems:"center",gap:i.spacing.xs,padding:`${i.spacing.sm} ${i.spacing.md}`,backgroundColor:"transparent",border:"none",color:n?i.colors.primary:i.colors.textSecondary,fontSize:i.typography.fontSize.sm,fontWeight:n?600:400,cursor:"pointer",position:"relative",transition:i.transitions.fast,borderRadius:`${i.borderRadius.sm} ${i.borderRadius.sm} 0 0`},onMouseEnter:a=>{n||(a.currentTarget.style.color=i.colors.text,a.currentTarget.style.backgroundColor=i.colors.surfaceElevated)},onMouseLeave:a=>{n||(a.currentTarget.style.color=i.colors.textSecondary,a.currentTarget.style.backgroundColor="transparent")},children:[r.icon&&h.jsx("span",{style:{display:"flex",alignItems:"center"},children:r.icon}),h.jsx("span",{children:r.label}),r.badge!==void 0&&h.jsx("span",{style:{backgroundColor:n?i.colors.primary:i.colors.surfaceElevated,color:n?i.colors.text:i.colors.textSecondary,borderRadius:i.borderRadius.sm,padding:`2px ${i.spacing.xs}`,fontSize:i.typography.fontSize.xs,fontWeight:600,minWidth:"18px",textAlign:"center"},children:r.badge}),n&&h.jsx("div",{style:{position:"absolute",bottom:-1,left:0,right:0,height:"2px",backgroundColor:i.colors.primary}})]},r.id)})})})},St=({severity:c,count:t,children:e,onClick:s})=>{const i=$,n={info:i.colors.info,warning:i.colors.warning,error:i.colors.error}[c];return h.jsxs("div",{onClick:s,style:{display:"inline-flex",alignItems:"center",gap:i.spacing.xs,padding:`${i.spacing.xs} ${i.spacing.sm}`,backgroundColor:`${n}20`,color:n,borderRadius:i.borderRadius.md,fontSize:i.typography.fontSize.xs,fontWeight:600,cursor:s?"pointer":"default",border:`1px solid ${n}40`,transition:i.transitions.fast},onMouseEnter:a=>{s&&(a.currentTarget.style.backgroundColor=`${n}30`)},onMouseLeave:a=>{s&&(a.currentTarget.style.backgroundColor=`${n}20`)},children:[h.jsx("div",{style:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:n}}),t!==void 0&&t>0&&h.jsx("span",{children:t}),e]})},Fe=120;function re(){const c=Vt(),[t,e]=M.useState([]),s=M.useRef(0),i=M.useRef(null);return M.useEffect(()=>{if(!c||c.frames===0){e([]),s.current=0;return}const r=()=>{if(E.getPaused())return;const a=q.getLastBreakdown();if(a&&a.total>0){e(l=>{const o=l.length>0?l[l.length-1]:null;if(o===null||Math.abs(a.total-o)>.1){const d=[...l,a.total];return d.length>Fe?d.slice(-Fe):d}return l});return}if(c&&c.frames>0){const l=c.totalTime/c.frames;if(c.frames>s.current){const o=c.frames-s.current;s.current=c.frames,e(d=>{const m=[...d],u=Math.min(o,10);for(let p=0;p<u;p++)m.push(l);return m.length>Fe?m.slice(-Fe):m})}}};i.current=window.setInterval(r,16);const n=E.subscribe(a=>{!a&&c&&c.frames>0&&r()});return()=>{i.current!==null&&clearInterval(i.current),n()}},[c]),t}function Zs(){const[c,t]=M.useState(null),e=M.useRef(null);return M.useEffect(()=>{const s=()=>{if(!E.getPaused()){const r=q.getLastBreakdown();r&&t(r)}};s(),e.current=window.setInterval(s,100);const i=E.subscribe(r=>{r||s()});return()=>{e.current!==null&&clearInterval(e.current),i()}},[]),c}const Zi=({width:c=600,height:t=200,showGrid:e=!0,showLabels:s=!0,maxValue:i,minValue:r})=>{const n=re(),a=$,l=typeof c=="string"&&c.includes("%"),o=l?"100%":typeof c=="number"?c:600,{normalizedData:d,chartMax:m,chartMin:u}=M.useMemo(()=>{if(n.length===0)return{normalizedData:[],chartMax:0,chartMin:0};const b=i??Math.max(...n),F=r??Math.min(...n),A=b-F||1;return{normalizedData:n.map(j=>{const z=(j-F)/A*t;return Math.max(0,Math.min(t,z))}),chartMax:b,chartMin:F}},[n,i,r,t]);if(n.length===0)return h.jsx("div",{style:{width:o,height:t,display:"flex",alignItems:"center",justifyContent:"center",color:a.colors.textTertiary,fontSize:a.typography.fontSize.sm,border:`1px solid ${a.colors.border}`,borderRadius:a.borderRadius.md},children:"No frame data available"});const p=l?600:typeof o=="number"?o:600,f=p/(n.length-1||1),x=d.map((b,F)=>{const A=F*f;return`${F===0?"M":"L"} ${A} ${t-b}`}).join(" "),y=`${x} L ${p} ${t} L 0 ${t} Z`,w=t-(16.67-u)/(m-u||1)*t,v=l?"100%":o;return h.jsx("div",{style:{position:"relative",width:o},children:h.jsxs("svg",{width:v,height:t,style:{display:"block"},viewBox:l?`0 0 600 ${t}`:void 0,preserveAspectRatio:l?"none":void 0,children:[e&&h.jsx("g",{opacity:.2,children:[0,.25,.5,.75,1].map(b=>{const F=t*b;return h.jsx("line",{x1:0,y1:F,x2:p,y2:F,stroke:a.colors.border,strokeWidth:1},b)})}),w>=0&&w<=t&&h.jsx("line",{x1:0,y1:w,x2:p,y2:w,stroke:a.colors.success,strokeWidth:2,strokeDasharray:"4 4",opacity:.5}),h.jsx("path",{d:y,fill:a.colors.primary,fillOpacity:.2}),h.jsx("path",{d:x,fill:"none",stroke:a.colors.primary,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),d.map((b,F)=>{const C=n[F]>16.67;return h.jsx("circle",{cx:F*f,cy:t-b,r:C?3:2,fill:C?a.colors.error:a.colors.primary},F)}),s&&h.jsxs("g",{children:[h.jsxs("text",{x:p-4,y:12,fill:a.colors.textSecondary,fontSize:a.typography.fontSize.xs,textAnchor:"end",children:[R(m,2),"ms"]}),h.jsxs("text",{x:p-4,y:t-4,fill:a.colors.textSecondary,fontSize:a.typography.fontSize.xs,textAnchor:"end",children:[R(u,2),"ms"]}),w>=0&&w<=t&&h.jsx("text",{x:4,y:w-4,fill:a.colors.success,fontSize:a.typography.fontSize.xs,fontWeight:600,children:"60 FPS"})]})]})})},Qi=({width:c=800,height:t=300,timeWindow:e=10})=>{const s=re(),i=$,r=typeof c=="string"&&c.includes("%"),n=r?"100%":typeof c=="number"?c:800,a=M.useMemo(()=>{const w=performance.now(),v=s.slice(-Math.floor(e*60));return v.map((F,A)=>({timestamp:w-(v.length-A)*16.666666666666668,frameTime:F,fps:F>0?1e3/F:0}))},[s,e]);if(a.length===0)return h.jsx("div",{style:{width:n,height:t,display:"flex",alignItems:"center",justifyContent:"center",color:i.colors.textTertiary,fontSize:i.typography.fontSize.sm,border:`1px solid ${i.colors.border}`,borderRadius:i.borderRadius.md,backgroundColor:i.colors.surface},children:"No timeline data available"});const l=Math.max(...a.map(w=>w.frameTime),50),o=Math.min(...a.map(w=>w.frameTime),0),d=Math.max(...a.map(w=>w.fps),60),m=Math.min(...a.map(w=>w.fps),0),u=t/2,p=r?800:typeof n=="number"?n:800,f=p/(a.length-1||1),x=a.map((w,v)=>{const b=u-(w.frameTime-o)/(l-o||1)*u,F=v*f;return`${v===0?"M":"L"} ${F} ${b}`}).join(" "),y=a.map((w,v)=>{const b=u-(w.fps-m)/(d-m||1)*u,F=v*f;return`${v===0?"M":"L"} ${F} ${b+u}`}).join(" "),g=r?"100%":n;return h.jsxs("div",{style:{width:n,height:t,backgroundColor:"transparent",borderRadius:i.borderRadius.md},children:[h.jsxs("div",{style:{fontSize:i.typography.fontSize.sm,fontWeight:600,color:i.colors.text,marginBottom:i.spacing.sm},children:["Timeline (",e,"s window)"]}),h.jsx("div",{style:{width:"100%",height:t,position:"relative",overflow:"hidden"},children:h.jsxs("svg",{width:g,height:t,style:{display:"block"},viewBox:r?`0 0 800 ${t}`:void 0,preserveAspectRatio:r?"none":void 0,children:[h.jsx("g",{opacity:.1,children:[0,.25,.5,.75,1].map(w=>{const v=t*w;return h.jsx("line",{x1:0,y1:v,x2:p,y2:v,stroke:i.colors.border,strokeWidth:1},w)})}),h.jsx("line",{x1:0,y1:u,x2:p,y2:u,stroke:i.colors.border,strokeWidth:2}),h.jsxs("g",{children:[h.jsx("text",{x:4,y:12,fill:i.colors.textSecondary,fontSize:i.typography.fontSize.xs,fontWeight:600,children:"Frame Time (ms)"}),h.jsx("path",{d:x,fill:"none",stroke:i.colors.error,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),h.jsx("line",{x1:0,y1:u-(16.67-o)/(l-o||1)*u,x2:p,y2:u-(16.67-o)/(l-o||1)*u,stroke:i.colors.success,strokeWidth:1,strokeDasharray:"2 2",opacity:.5})]}),h.jsxs("g",{children:[h.jsx("text",{x:4,y:u+12,fill:i.colors.textSecondary,fontSize:i.typography.fontSize.xs,fontWeight:600,children:"FPS"}),h.jsx("path",{d:y,fill:"none",stroke:i.colors.success,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),h.jsx("line",{x1:0,y1:u+u-(60-m)/(d-m||1)*u,x2:p,y2:u+u-(60-m)/(d-m||1)*u,stroke:i.colors.success,strokeWidth:1,strokeDasharray:"2 2",opacity:.5})]}),h.jsxs("g",{children:[h.jsxs("text",{x:p-4,y:12,fill:i.colors.textTertiary,fontSize:i.typography.fontSize.xs,textAnchor:"end",children:[R(l,1),"ms"]}),h.jsxs("text",{x:p-4,y:u-4,fill:i.colors.textTertiary,fontSize:i.typography.fontSize.xs,textAnchor:"end",children:[R(o,1),"ms"]}),h.jsxs("text",{x:p-4,y:u+12,fill:i.colors.textTertiary,fontSize:i.typography.fontSize.xs,textAnchor:"end",children:[R(d,0)," FPS"]}),h.jsxs("text",{x:p-4,y:t-4,fill:i.colors.textTertiary,fontSize:i.typography.fontSize.xs,textAnchor:"end",children:[R(m,0)," FPS"]})]})]})})]})};function Ki(){const[c,t]=M.useState([]);return M.useEffect(()=>{const e=()=>{if(!E.getPaused()){const r=Ce.getStats();r&&t(n=>[...n,{...r,time:Date.now()}].slice(-120))}};e();const s=setInterval(e,1e3),i=E.subscribe(r=>{r||e()});return()=>{clearInterval(s),i()}},[]),c}const tr=({width:c="100%",height:t=200,showGrid:e=!0,showLabels:s=!0,timeWindow:i=60,metric:r="both"})=>{const n=Ki(),a=$,l=M.useMemo(()=>{const y=Date.now()-i*1e3,g=n.filter(C=>C.time>=y);if(g.length===0)return{jsHeapData:[],gpuMemoryData:[],maxValue:0,minValue:0};const w=g.map(C=>C.jsHeap.used),v=g.map(C=>C.gpuMemory.total),b=[...w,...v].filter(C=>C>0),F=b.length>0?Math.max(...b):0,A=b.length>0?Math.min(...b):0;return{jsHeapData:w,gpuMemoryData:v,maxValue:F||1,minValue:A}},[n,i]);if(l.jsHeapData.length===0&&l.gpuMemoryData.length===0)return h.jsx("div",{style:{width:c,height:t,display:"flex",alignItems:"center",justifyContent:"center",color:a.colors.textTertiary,fontSize:a.typography.fontSize.sm,border:`1px solid ${a.colors.border}`,borderRadius:a.borderRadius.md,backgroundColor:a.colors.surface},children:"No memory data available"});const o=800,d=o/(Math.max(l.jsHeapData.length,l.gpuMemoryData.length)-1||1),m=l.maxValue-l.minValue||1,u=l.jsHeapData.map((x,y)=>{const g=t-(x-l.minValue)/m*t,w=y*d;return`${y===0?"M":"L"} ${w} ${g}`}).join(" "),p=l.gpuMemoryData.map((x,y)=>{const g=t-(x-l.minValue)/m*t,w=y*d;return`${y===0?"M":"L"} ${w} ${g}`}).join(" "),f=x=>x<1024?`${R(x,0)} B`:x<1024*1024?`${R(x/1024,1)} KB`:x<1024*1024*1024?`${R(x/(1024*1024),1)} MB`:`${R(x/(1024*1024*1024),2)} GB`;return h.jsx("div",{style:{position:"relative",width:c,height:t},children:h.jsxs("svg",{width:"100%",height:t,viewBox:`0 0 ${o} ${t}`,preserveAspectRatio:"none",style:{display:"block"},children:[e&&h.jsx("g",{opacity:.2,children:[0,.25,.5,.75,1].map(x=>{const y=t*x;return h.jsx("line",{x1:0,y1:y,x2:o,y2:y,stroke:a.colors.border,strokeWidth:1},x)})}),r==="jsHeap"||r==="both"?h.jsxs(h.Fragment,{children:[h.jsx("path",{d:`${u} L ${o} ${t} L 0 ${t} Z`,fill:a.colors.primary,fillOpacity:.1}),h.jsx("path",{d:u,fill:"none",stroke:a.colors.primary,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})]}):null,r==="gpuMemory"||r==="both"?h.jsxs(h.Fragment,{children:[h.jsx("path",{d:`${p} L ${o} ${t} L 0 ${t} Z`,fill:a.colors.accent,fillOpacity:.1}),h.jsx("path",{d:p,fill:"none",stroke:a.colors.accent,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})]}):null,s&&h.jsxs("g",{children:[h.jsx("text",{x:o-4,y:12,fill:a.colors.textSecondary,fontSize:a.typography.fontSize.xs,textAnchor:"end",children:f(l.maxValue)}),h.jsx("text",{x:o-4,y:t-4,fill:a.colors.textSecondary,fontSize:a.typography.fontSize.xs,textAnchor:"end",children:f(l.minValue)}),r==="both"&&h.jsxs(h.Fragment,{children:[h.jsx("text",{x:4,y:12,fill:a.colors.primary,fontSize:a.typography.fontSize.xs,children:"JS Heap"}),h.jsx("text",{x:4,y:t-4,fill:a.colors.accent,fontSize:a.typography.fontSize.xs,children:"GPU Memory"})]})]})]})})},er=()=>{const c=Vt(),t=re(),e=Zs(),s=$,i=M.useMemo(()=>!c||!c.entries?[]:[...c.entries].sort((m,u)=>u.total-m.total),[c]),r=M.useMemo(()=>e?e.interval||e.total:!c||c.totalTime||c.frames===0?0:c.totalTime/c.frames,[e,c]),n=M.useMemo(()=>e?e.total:!c||c.frames===0?0:c.totalTime/c.frames,[e,c]),a=M.useMemo(()=>r>0?1e3/r:0,[r]),l=M.useMemo(()=>n<=16.67?"good":n<=33.33?"warning":"error",[n]),o=M.useMemo(()=>t.length>0?t:n>0?[n]:[],[t,n]),d=M.useMemo(()=>o.length===0?33:Math.max(...o,20),[o]);return!c||c.entries.length===0?h.jsx("div",{style:{padding:s.spacing.lg,textAlign:"center",color:s.colors.textSecondary,fontSize:s.typography.fontSize.sm},children:"Aucune donnée profilée pour le moment."}):h.jsxs("div",{style:{padding:s.spacing.md},children:[h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(150px, 1fr))",gap:s.spacing.md,marginBottom:s.spacing.lg},children:[h.jsx(_,{label:"FPS",value:R(a,1),status:a>=60?"good":a>=30?"warning":"error"}),h.jsx(_,{label:"Frame Time",value:R(n,2),unit:"ms",status:l}),h.jsx(_,{label:"Total Time",value:R(c.totalTime,2),unit:"ms"}),h.jsx(_,{label:"Frames",value:c.frames})]}),h.jsxs("div",{style:{backgroundColor:s.colors.surface,borderRadius:s.borderRadius.md,padding:s.spacing.md,marginBottom:s.spacing.lg,border:`1px solid ${s.colors.border}`,overflow:"hidden"},children:[h.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:s.spacing.sm},children:[h.jsx("div",{style:{fontSize:s.typography.fontSize.sm,fontWeight:600,color:s.colors.text},children:"Frame Time History"}),h.jsxs("div",{style:{fontSize:s.typography.fontSize.xs,color:s.colors.textSecondary,fontFamily:s.typography.fontFamilyMono},children:[o.length," frames"]})]}),h.jsx(Zi,{width:"100%",height:100,showGrid:!0,showLabels:!0,maxValue:d}),h.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:s.spacing.xs,fontSize:s.typography.fontSize.xs,color:s.colors.textTertiary},children:[h.jsx("div",{children:"Target: <16.67ms (60 FPS)"}),h.jsxs("div",{style:{color:Bs(n,{good:16.67,warning:33.33})},children:["Current: ",R(n,2),"ms (work)"]})]})]}),h.jsx("div",{style:{backgroundColor:s.colors.surface,borderRadius:s.borderRadius.md,padding:s.spacing.md,marginBottom:s.spacing.lg,border:`1px solid ${s.colors.border}`,overflow:"hidden"},children:h.jsx(Qi,{width:"100%",height:200,timeWindow:10})}),h.jsx("div",{style:{backgroundColor:s.colors.surface,borderRadius:s.borderRadius.md,border:`1px solid ${s.colors.border}`,overflow:"hidden"},children:h.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[h.jsx("thead",{children:h.jsxs("tr",{style:{backgroundColor:s.colors.surfaceElevated,borderBottom:`1px solid ${s.colors.border}`},children:[h.jsx("th",{style:{textAlign:"left",padding:s.spacing.md,color:s.colors.textSecondary,fontSize:s.typography.fontSize.sm,fontWeight:600},children:"Hook"}),h.jsx("th",{style:{textAlign:"right",padding:s.spacing.md,color:s.colors.textSecondary,fontSize:s.typography.fontSize.sm,fontWeight:600},children:"Total (ms)"}),h.jsx("th",{style:{textAlign:"right",padding:s.spacing.md,color:s.colors.textSecondary,fontSize:s.typography.fontSize.sm,fontWeight:600},children:"Avg (ms)"}),h.jsx("th",{style:{textAlign:"right",padding:s.spacing.md,color:s.colors.textSecondary,fontSize:s.typography.fontSize.sm,fontWeight:600},children:"Max (ms)"}),h.jsx("th",{style:{textAlign:"right",padding:s.spacing.md,color:s.colors.textSecondary,fontSize:s.typography.fontSize.sm,fontWeight:600},children:"%"})]})}),h.jsx("tbody",{children:i.map((m,u)=>{const p=Bs(m.avg,{good:5,warning:10});return h.jsxs("tr",{style:{borderBottom:u<i.length-1?`1px solid ${s.colors.borderLight}`:"none",transition:s.transitions.fast},onMouseEnter:f=>{f.currentTarget.style.backgroundColor=s.colors.surfaceElevated},onMouseLeave:f=>{f.currentTarget.style.backgroundColor="transparent"},children:[h.jsx("td",{style:{padding:s.spacing.md,color:s.colors.text,fontFamily:s.typography.fontFamilyMono,fontSize:s.typography.fontSize.sm},children:m.name}),h.jsx("td",{style:{textAlign:"right",padding:s.spacing.md,color:s.colors.text,fontFamily:s.typography.fontFamilyMono,fontSize:s.typography.fontSize.sm},children:R(m.total,2)}),h.jsx("td",{style:{textAlign:"right",padding:s.spacing.md,color:p,fontFamily:s.typography.fontFamilyMono,fontSize:s.typography.fontSize.sm,fontWeight:600},children:R(m.avg,3)}),h.jsx("td",{style:{textAlign:"right",padding:s.spacing.md,color:s.colors.text,fontFamily:s.typography.fontFamilyMono,fontSize:s.typography.fontSize.sm},children:R(m.max,3)}),h.jsxs("td",{style:{textAlign:"right",padding:s.spacing.md,color:s.colors.textSecondary,fontFamily:s.typography.fontFamilyMono,fontSize:s.typography.fontSize.sm},children:[R(m.percentage,1),"%"]})]},m.name)})})]})})]})};function Ke(){const[c,t]=M.useState(null),e=M.useRef(null);return M.useEffect(()=>{const s=()=>{if(!E.getPaused()){const r=Xt.getStats();r&&t(r)}};s(),e.current=window.setInterval(s,100);const i=E.subscribe(r=>{r||s()});return()=>{e.current!==null&&clearInterval(e.current),i()}},[]),c}const sr=()=>{const c=Ke(),t=$,e=M.useMemo(()=>c?c.drawCalls<=100?"good":c.drawCalls<=500?"warning":"error":"neutral",[c]),s=M.useMemo(()=>c?c.triangles<=1e5?"good":c.triangles<=5e5?"warning":"error":"neutral",[c]);if(!c)return h.jsx("div",{style:{padding:t.spacing.lg,textAlign:"center",color:t.colors.textSecondary,fontSize:t.typography.fontSize.sm},children:"Aucune donnée GPU disponible. Assurez-vous que le composant est à l'intérieur d'un Canvas R3F."});const i=r=>r===0?"0 B":r<1024?`${R(r,0)} B`:r<1024*1024?`${R(r/1024,2)} KB`:`${R(r/(1024*1024),2)} MB`;return h.jsxs("div",{style:{padding:t.spacing.md},children:[h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(150px, 1fr))",gap:t.spacing.md,marginBottom:t.spacing.lg},children:[h.jsx(_,{label:"Draw Calls",value:c.drawCalls.toLocaleString(),status:e}),h.jsx(_,{label:"Triangles",value:c.triangles.toLocaleString(),status:s}),h.jsx(_,{label:"Points",value:c.points.toLocaleString()}),h.jsx(_,{label:"Lines",value:c.lines.toLocaleString()})]}),h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.md,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.md},children:"GPU Memory"}),h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(120px, 1fr))",gap:t.spacing.md},children:[h.jsx(_,{label:"Textures",value:i(c.memory.textures)}),h.jsx(_,{label:"Geometries",value:i(c.memory.geometries)}),h.jsx(_,{label:"Programs",value:i(c.memory.programs)}),h.jsx(_,{label:"Total",value:i(c.memory.total),color:c.memory.total>100*1024*1024?t.colors.warning:t.colors.success})]})]}),h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.md,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.md},children:"Resources"}),h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(120px, 1fr))",gap:t.spacing.md},children:[h.jsx(_,{label:"Textures",value:c.textures}),h.jsx(_,{label:"Geometries",value:c.geometries}),h.jsx(_,{label:"Programs",value:c.programs})]})]})]})};function ir(){const[c,t]=M.useState(null),e=M.useRef(null);return M.useEffect(()=>{const s=()=>{if(!E.getPaused()){const r=Xs.getStats();r&&t(r)}};s(),e.current=window.setInterval(s,500);const i=E.subscribe(r=>{r||s()});return()=>{e.current!==null&&clearInterval(e.current),i()}},[]),c}const rr=()=>{const c=ir(),t=$;if(!c)return h.jsx("div",{style:{padding:t.spacing.lg,textAlign:"center",color:t.colors.textSecondary,fontSize:t.typography.fontSize.sm},children:"Aucune donnée de scène disponible. Assurez-vous que le composant est à l'intérieur d'un Canvas R3F."});const e=s=>s<1024?`${R(s,0)} B`:s<1024*1024?`${R(s/1024,2)} KB`:`${R(s/(1024*1024),2)} MB`;return h.jsxs("div",{style:{padding:t.spacing.md},children:[h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.md,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.md},children:"Objects"}),h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(120px, 1fr))",gap:t.spacing.md},children:[h.jsx(_,{label:"Total",value:c.objects.total.toLocaleString()}),h.jsx(_,{label:"Meshes",value:c.objects.meshes.toLocaleString()}),h.jsx(_,{label:"Lights",value:c.objects.lights.toLocaleString()}),h.jsx(_,{label:"Cameras",value:c.objects.cameras.toLocaleString()}),h.jsx(_,{label:"Groups",value:c.objects.groups.toLocaleString()}),h.jsx(_,{label:"Visible",value:c.visible.total.toLocaleString(),color:c.visible.total===c.objects.total?t.colors.success:t.colors.warning})]})]}),h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsxs("div",{style:{fontSize:t.typography.fontSize.md,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.md},children:["Materials (",c.materials.total,")"]}),h.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:t.spacing.sm},children:Object.entries(c.materials.byType).map(([s,i])=>h.jsxs("div",{style:{backgroundColor:t.colors.surfaceElevated,padding:`${t.spacing.xs} ${t.spacing.sm}`,borderRadius:t.borderRadius.sm,fontSize:t.typography.fontSize.xs,color:t.colors.textSecondary,fontFamily:t.typography.fontFamilyMono},children:[s,": ",i]},s))})]}),c.textures.total>0&&h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.md,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.md},children:"Textures"}),h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(150px, 1fr))",gap:t.spacing.md},children:[h.jsx(_,{label:"Total",value:c.textures.total.toLocaleString()}),h.jsx(_,{label:"Total Size",value:e(c.textures.totalSize)}),c.textures.environment>0&&h.jsx(_,{label:"Environment",value:c.textures.environment.toLocaleString(),color:t.colors.info}),c.textures.system>0&&h.jsx(_,{label:"System",value:c.textures.system.toLocaleString(),color:t.colors.warning})]})]}),h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.md,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.md},children:"Geometries"}),h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(150px, 1fr))",gap:t.spacing.md},children:[h.jsx(_,{label:"Total",value:c.geometries.total.toLocaleString()}),h.jsx(_,{label:"Vertices",value:c.geometries.vertices.toLocaleString()}),h.jsx(_,{label:"Faces",value:c.geometries.faces.toLocaleString()})]})]}),h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.md,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.md},children:"Complexity"}),h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(150px, 1fr))",gap:t.spacing.md},children:[h.jsx(_,{label:"Avg Vertices/Mesh",value:R(c.complexity.averageVerticesPerMesh,0)}),h.jsx(_,{label:"Avg Faces/Mesh",value:R(c.complexity.averageFacesPerMesh,0)}),h.jsx(_,{label:"Est. Draw Calls",value:c.complexity.totalDrawCalls.toLocaleString()})]})]})]})};function ts(){const[c,t]=M.useState(null),e=M.useRef(null);return M.useEffect(()=>{const s=()=>{if(!E.getPaused()){const r=Ce.getStats();r&&t(r)}};s(),e.current=window.setInterval(s,1e3);const i=E.subscribe(r=>{r||s()});return()=>{e.current!==null&&clearInterval(e.current),i()}},[]),c}const nr=()=>{const c=ts(),t=$,e=r=>r===0?"0 B":r<1024?`${R(r,0)} B`:r<1024*1024?`${R(r/1024,2)} KB`:r<1024*1024*1024?`${R(r/(1024*1024),2)} MB`:`${R(r/(1024*1024*1024),2)} GB`,s=M.useMemo(()=>{if(!c)return"neutral";const r=c.jsHeap.percentage;return r<50?"good":r<80?"warning":"error"},[c]),i=M.useMemo(()=>c?c.leaks.detected?"error":"good":"neutral",[c]);return c?h.jsxs("div",{style:{padding:t.spacing.md},children:[c.jsHeap.limit>0&&h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:"JavaScript Heap Memory"}),h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(150px, 1fr))",gap:t.spacing.md,marginBottom:t.spacing.md},children:[h.jsx(_,{label:"Used",value:e(c.jsHeap.used),status:s}),h.jsx(_,{label:"Total",value:e(c.jsHeap.total)}),h.jsx(_,{label:"Limit",value:e(c.jsHeap.limit)}),h.jsx(_,{label:"Usage",value:`${R(c.jsHeap.percentage,1)}%`,status:s})]}),h.jsx("div",{style:{width:"100%",height:"8px",backgroundColor:t.colors.border,borderRadius:t.borderRadius.sm,overflow:"hidden",marginTop:t.spacing.sm},children:h.jsx("div",{style:{width:`${Math.min(100,c.jsHeap.percentage)}%`,height:"100%",backgroundColor:c.jsHeap.percentage<=50?t.colors.success:c.jsHeap.percentage<=80?t.colors.warning:t.colors.error,transition:t.transitions.normal}})})]}),c.gpuMemory.total>0&&h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:"GPU Memory (Estimated)"}),h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(120px, 1fr))",gap:t.spacing.sm},children:[h.jsx(_,{label:"Textures",value:e(c.gpuMemory.textures)}),h.jsx(_,{label:"Geometries",value:e(c.gpuMemory.geometries)}),h.jsx(_,{label:"Total",value:e(c.gpuMemory.total)})]}),h.jsx("div",{style:{fontSize:t.typography.fontSize.xs,color:t.colors.textTertiary,marginTop:t.spacing.sm},children:"Note: GPU memory is an estimation based on resource counts. Actual usage may vary."})]}),h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`,overflow:"hidden"},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:"Memory Evolution (Last 60s)"}),h.jsx(tr,{width:"100%",height:150,timeWindow:60,metric:"both",showGrid:!0,showLabels:!0})]}),h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:"Memory Leak Detection"}),h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:t.spacing.sm,marginBottom:t.spacing.sm},children:[h.jsx("div",{style:{width:"12px",height:"12px",borderRadius:"50%",backgroundColor:i==="good"?t.colors.success:t.colors.error}}),h.jsx("div",{style:{color:t.colors.text,fontSize:t.typography.fontSize.sm},children:c.leaks.detected?"Potential leak detected":"No leaks detected"})]}),h.jsxs("div",{style:{fontSize:t.typography.fontSize.xs,color:t.colors.textSecondary,fontFamily:t.typography.fontFamilyMono},children:[h.jsxs("div",{children:["Growth Rate: ",e(Math.abs(c.leaks.growthRate)),"/s"]}),h.jsxs("div",{children:["Trend: ",c.leaks.trend]})]})]})]}):h.jsx("div",{style:{padding:t.spacing.lg,textAlign:"center",color:t.colors.textSecondary,fontSize:t.typography.fontSize.sm},children:"Aucune donnée de mémoire disponible. Les stats de mémoire JS nécessitent Chrome."})},or=()=>{const c=Zs(),t=$,e=a=>a<.1?`${R(a*1e3,0)} μs`:a<1?`${R(a,2)} ms`:`${R(a,2)} ms`,s=(a,l)=>l===0?"0%":`${R(a/l*100,1)}%`,i=M.useMemo(()=>c?c.total<=16.67?"good":c.total<=33.33?"warning":"error":"neutral",[c]);if(!c)return h.jsx("div",{style:{padding:t.spacing.lg,textAlign:"center",color:t.colors.textSecondary,fontSize:t.typography.fontSize.sm},children:"Aucune donnée de breakdown de frame disponible. Le frame breakdown nécessite une instrumentation du code."});const r=[{name:"React",value:c.phases.react,color:t.colors.primary},{name:"Update",value:c.phases.update,color:t.colors.info},{name:"Physics",value:c.phases.physics,color:t.colors.warning},{name:"Render",value:c.phases.render,color:t.colors.success},{name:"Post-Process",value:c.phases.postProcess,color:t.colors.accent},{name:"Other",value:c.phases.other,color:t.colors.textSecondary}].filter(a=>a.value>0),n=Math.max(...r.map(a=>a.value),c.total);return h.jsxs("div",{style:{padding:t.spacing.md},children:[h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:"Total Frame Time"}),h.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:t.spacing.sm,marginBottom:t.spacing.sm},children:[h.jsx(_,{label:"Frame Time",value:e(c.total),status:i}),h.jsxs("div",{style:{fontSize:t.typography.fontSize.xs,color:t.colors.textSecondary},children:["(",R(1e3/c.total,1)," FPS)"]})]})]}),h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:"Phase Breakdown"}),h.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(120px, 1fr))",gap:t.spacing.sm,marginBottom:t.spacing.md},children:r.map(a=>h.jsx(_,{label:a.name,value:e(a.value)},a.name))}),h.jsxs("div",{style:{marginTop:t.spacing.md},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.xs,color:t.colors.textSecondary,marginBottom:t.spacing.sm},children:"Timeline (Waterfall)"}),h.jsx("div",{style:{position:"relative",height:"200px",backgroundColor:t.colors.background,borderRadius:t.borderRadius.sm,border:`1px solid ${t.colors.border}`,padding:t.spacing.xs},children:r.map((a,l)=>{const o=a.value/n*100,d=r.slice(0,l).reduce((m,u)=>m+u.value/n*100,0);return h.jsx("div",{style:{position:"absolute",left:`${d}%`,width:`${o}%`,height:"30px",backgroundColor:a.color,borderRadius:t.borderRadius.sm,display:"flex",alignItems:"center",justifyContent:"center",fontSize:t.typography.fontSize.xs,color:t.colors.background,fontWeight:600,marginTop:`${l*35}px`,opacity:.8,border:`1px solid ${t.colors.border}`},title:`${a.name}: ${e(a.value)} (${s(a.value,c.total)})`,children:o>5&&`${a.name}: ${e(a.value)}`},a.name)})})]})]}),c.timeline.length>0&&h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:"Timeline Details"}),h.jsx("div",{style:{maxHeight:"200px",overflowY:"auto",fontSize:t.typography.fontSize.xs,fontFamily:t.typography.fontFamilyMono,color:t.colors.textSecondary},children:c.timeline.slice(-20).reverse().map((a,l)=>h.jsxs("div",{style:{padding:t.spacing.xs,borderBottom:`1px solid ${t.colors.border}`,display:"flex",justifyContent:"space-between"},children:[h.jsx("span",{children:a.name}),h.jsx("span",{children:e(a.duration)})]},l))})]})]})};class ar{budget=null;violations=[];maxHistorySize=100;listeners=new Set;STORAGE_KEY="r3f-profiler-budget";constructor(){this.loadBudget()}loadBudget(){try{const t=localStorage.getItem(this.STORAGE_KEY);if(t){const e=JSON.parse(t);this.isValidBudget(e)&&(this.budget=e)}}catch(t){console.warn("Failed to load saved budget from localStorage:",t)}}saveBudget(){try{this.budget?localStorage.setItem(this.STORAGE_KEY,JSON.stringify(this.budget)):localStorage.removeItem(this.STORAGE_KEY)}catch(t){console.warn("Failed to save budget to localStorage:",t)}}isValidBudget(t){return!t||typeof t!="object"?!1:t.fps&&typeof t.fps.min=="number"||t.frameTime&&typeof t.frameTime.max=="number"||t.memory&&(typeof t.memory.max=="number"||t.memory.jsHeap)||t.gpu&&(t.gpu.drawCalls||t.gpu.triangles)}setBudget(t){!t||!t.fps&&!t.frameTime&&!t.memory&&!t.gpu?this.budget=null:this.budget=t,this.violations=[],this.saveBudget(),this.notifyListeners()}getBudget(){return this.budget}checkBudget(t){if(!this.budget)return[];const e=[];return this.budget.fps?.min!==void 0&&t.fps!==void 0&&t.fps<this.budget.fps.min&&e.push({id:`fps-${Date.now()}-${Math.random()}`,metric:"fps",current:t.fps,budget:this.budget.fps.min,severity:t.fps<this.budget.fps.min*.7?"error":"warning",timestamp:performance.now(),message:`FPS is ${t.fps.toFixed(1)} (budget: ${this.budget.fps.min} FPS)`}),this.budget.frameTime?.max!==void 0&&t.frameTime!==void 0&&t.frameTime>this.budget.frameTime.max&&e.push({id:`frameTime-${Date.now()}-${Math.random()}`,metric:"frameTime",current:t.frameTime,budget:this.budget.frameTime.max,severity:t.frameTime>this.budget.frameTime.max*1.5?"error":"warning",timestamp:performance.now(),message:`Frame time is ${t.frameTime.toFixed(2)}ms (budget: ${this.budget.frameTime.max}ms)`}),this.budget.memory&&(this.budget.memory.max!==void 0&&t.memory?.used!==void 0&&t.memory.used>this.budget.memory.max&&e.push({id:`memory-${Date.now()}-${Math.random()}`,metric:"memory",current:t.memory.used,budget:this.budget.memory.max,severity:t.memory.used>this.budget.memory.max*1.2?"error":"warning",timestamp:performance.now(),message:`Memory usage is ${(t.memory.used/(1024*1024)).toFixed(2)}MB (budget: ${(this.budget.memory.max/(1024*1024)).toFixed(2)}MB)`}),this.budget.memory.jsHeap?.maxPercentage!==void 0&&t.memory?.jsHeapPercentage!==void 0&&t.memory.jsHeapPercentage>this.budget.memory.jsHeap.maxPercentage&&e.push({id:`jsHeap-${Date.now()}-${Math.random()}`,metric:"jsHeap",current:t.memory.jsHeapPercentage,budget:this.budget.memory.jsHeap.maxPercentage,severity:t.memory.jsHeapPercentage>this.budget.memory.jsHeap.maxPercentage*1.1?"error":"warning",timestamp:performance.now(),message:`JS Heap usage is ${t.memory.jsHeapPercentage.toFixed(1)}% (budget: ${this.budget.memory.jsHeap.maxPercentage}%)`})),this.budget.gpu&&(this.budget.gpu.drawCalls?.max!==void 0&&t.gpu?.drawCalls!==void 0&&t.gpu.drawCalls>this.budget.gpu.drawCalls.max&&e.push({id:`drawCalls-${Date.now()}-${Math.random()}`,metric:"drawCalls",current:t.gpu.drawCalls,budget:this.budget.gpu.drawCalls.max,severity:t.gpu.drawCalls>this.budget.gpu.drawCalls.max*1.5?"error":"warning",timestamp:performance.now(),message:`Draw calls: ${t.gpu.drawCalls} (budget: ${this.budget.gpu.drawCalls.max})`}),this.budget.gpu.triangles?.max!==void 0&&t.gpu?.triangles!==void 0&&t.gpu.triangles>this.budget.gpu.triangles.max&&e.push({id:`triangles-${Date.now()}-${Math.random()}`,metric:"triangles",current:t.gpu.triangles,budget:this.budget.gpu.triangles.max,severity:t.gpu.triangles>this.budget.gpu.triangles.max*1.5?"error":"warning",timestamp:performance.now(),message:`Triangles: ${t.gpu.triangles.toLocaleString()} (budget: ${this.budget.gpu.triangles.max.toLocaleString()})`})),e.length>0&&(this.violations.push(...e),this.violations.length>this.maxHistorySize&&(this.violations=this.violations.slice(-this.maxHistorySize)),this.notifyListeners()),e}getViolations(){return[...this.violations]}getRecentViolations(t=60){const e=performance.now()-t*1e3;return this.violations.filter(s=>s.timestamp>=e)}getViolationsByMetric(t){return this.violations.filter(e=>e.metric===t)}clearViolations(){this.violations=[],this.notifyListeners()}getRecommendedBudget(t){const e={};return t.fps!==void 0&&(e.fps={min:Math.max(30,Math.floor(t.fps*.9))}),t.frameTime!==void 0&&(e.frameTime={max:Math.ceil(t.frameTime*1.1)}),t.memory?.used!==void 0&&(e.memory={max:Math.ceil(t.memory.used*1.2),jsHeap:{maxPercentage:80}}),t.gpu&&(e.gpu={},t.gpu.drawCalls!==void 0&&(e.gpu.drawCalls={max:Math.ceil(t.gpu.drawCalls*1.2)}),t.gpu.triangles!==void 0&&(e.gpu.triangles={max:Math.ceil(t.gpu.triangles*1.2)})),e}subscribe(t){return this.listeners.add(t),()=>{this.listeners.delete(t)}}notifyListeners(){const t=this.getRecentViolations(60);this.listeners.forEach(e=>{try{e(t)}catch(s){console.error("Error in budget violation listener:",s)}})}reset(){this.budget=null,this.violations=[],this.listeners.clear(),localStorage.removeItem(this.STORAGE_KEY)}}const nt=new ar;function lr(){const[c,t]=M.useState(null),[e,s]=M.useState([]);return M.useEffect(()=>{t(nt.getBudget()),s(nt.getRecentViolations(60));const l=nt.subscribe(o=>{s(o),t(nt.getBudget())});return()=>{l()}},[]),{budget:c,violations:e,setBudget:l=>{nt.setBudget(l),t(l),s([])},clearViolations:()=>{nt.clearViolations(),s([])},clearBudget:()=>{nt.setBudget({}),t(null),s([])},getRecommendedBudget:l=>nt.getRecommendedBudget(l)}}class hr{alerts=[];maxAlerts=50;listeners=new Set;soundEnabled=!1;createFromViolation(t){return{id:`alert-${t.id}`,type:"budget",severity:t.severity,title:`Budget Violation: ${t.metric}`,message:t.message,timestamp:t.timestamp,dismissed:!1,data:{violation:t}}}createAlert(t,e,s,i,r){const n={id:`alert-${Date.now()}-${Math.random()}`,type:t,severity:e,title:s,message:i,timestamp:performance.now(),dismissed:!1,data:r};return this.addAlert(n),n}addAlert(t){if(t.type==="budget"&&t.data?.violation){const e=t.data.violation;this.alerts=this.alerts.filter(s=>!(s.type==="budget"&&s.data?.violation&&s.data.violation.metric===e.metric))}this.alerts.push(t),this.alerts.length>this.maxAlerts&&(this.alerts=this.alerts.slice(-this.maxAlerts)),this.soundEnabled&&t.severity==="error"&&this.playAlertSound(),this.notifyListeners()}getAlerts(t=!1){return t?[...this.alerts]:this.alerts.filter(e=>!e.dismissed)}getActiveAlerts(){return this.alerts.filter(t=>!t.dismissed)}getAlertsBySeverity(t){return this.alerts.filter(e=>!e.dismissed&&e.severity===t)}getAlertsByType(t){return this.alerts.filter(e=>!e.dismissed&&e.type===t)}dismissAlert(t){const e=this.alerts.find(s=>s.id===t);e&&(e.dismissed=!0,this.notifyListeners())}dismissAll(){this.alerts.forEach(t=>{t.dismissed=!0}),this.notifyListeners()}removeAlert(t){this.alerts=this.alerts.filter(e=>e.id!==t),this.notifyListeners()}clearAlerts(){this.alerts=[],this.notifyListeners()}setSoundEnabled(t){this.soundEnabled=t}isSoundEnabled(){return this.soundEnabled}playAlertSound(){try{const t=new(window.AudioContext||window.webkitAudioContext),e=t.createOscillator(),s=t.createGain();e.connect(s),s.connect(t.destination),e.frequency.value=800,e.type="sine",s.gain.setValueAtTime(.3,t.currentTime),s.gain.exponentialRampToValueAtTime(.01,t.currentTime+.1),e.start(t.currentTime),e.stop(t.currentTime+.1)}catch(t){console.debug("Could not play alert sound:",t)}}subscribe(t){return this.listeners.add(t),()=>{this.listeners.delete(t)}}notifyListeners(){const t=this.getActiveAlerts();this.listeners.forEach(e=>{try{e(t)}catch(s){console.error("Error in alert listener:",s)}})}reset(){this.alerts=[],this.listeners.clear(),this.soundEnabled=!1}}const Ps=new hr;function cr(){const c=re(),t=Vt(),e=Ke(),s=ts(),i=M.useRef(null);M.useEffect(()=>{const r=()=>{if(!nt.getBudget())return;let a=0,l=0;t&&t.totalTime>0&&t.frames>0?(l=t.totalTime/t.frames,a=1e3/l):c.length>0?(l=c.reduce((m,u)=>m+u,0)/c.length,a=l>0?1e3/l:0):e&&e.frameTime>0&&(l=e.frameTime,a=l>0?1e3/l:0);const o={fps:a,frameTime:l,memory:s?{used:s.jsHeap.used,jsHeapPercentage:s.jsHeap.percentage}:void 0,gpu:e?{drawCalls:e.drawCalls,triangles:e.triangles}:void 0};nt.checkBudget(o).forEach(m=>{Ps.getAlerts().find(p=>p.type==="budget"&&p.data?.violation&&p.data.violation.id===m.id)||Ps.createFromViolation(m)})};return i.current=window.setInterval(r,1e3),r(),()=>{i.current!==null&&clearInterval(i.current)}},[c,t,e,s])}const dr=()=>{const{budget:c,violations:t,setBudget:e,clearViolations:s,clearBudget:i,getRecommendedBudget:r}=lr(),n=re(),a=Ke(),l=ts(),o=$;cr();const[d,m]=M.useState(!1),[u,p]=M.useState(c||{}),f=M.useMemo(()=>{const b=n.length>0?n.reduce((A,C)=>A+C,0)/n.length:0;return{fps:b>0?1e3/b:0,frameTime:b,memory:l?{used:l.jsHeap.used,jsHeapPercentage:l.jsHeap.percentage}:void 0,gpu:a?{drawCalls:a.drawCalls,triangles:a.triangles}:void 0}},[n,a,l]),x=b=>b===0?"0 B":b<1024?`${R(b,0)} B`:b<1024*1024?`${R(b/1024,2)} KB`:b<1024*1024*1024?`${R(b/(1024*1024),2)} MB`:`${R(b/(1024*1024*1024),2)} GB`,y=()=>{e(u),m(!1)},g=()=>{const b=r(f);p(b),e(b),m(!1)},w=()=>{p(c||{}),m(!1)},v=M.useMemo(()=>{const b=t.filter(A=>A.severity==="error").length,F=t.filter(A=>A.severity==="warning").length;return{errors:b,warnings:F}},[t]);return h.jsxs("div",{style:{padding:o.spacing.md},children:[h.jsxs("div",{style:{backgroundColor:o.colors.surface,borderRadius:o.borderRadius.md,padding:o.spacing.md,marginBottom:o.spacing.lg,border:`1px solid ${o.colors.border}`},children:[h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:o.spacing.md},children:[h.jsx("div",{style:{fontSize:o.typography.fontSize.sm,fontWeight:600,color:o.colors.text},children:"Budget Status"}),h.jsxs("div",{style:{display:"flex",gap:o.spacing.sm,alignItems:"center"},children:[v.errors>0&&h.jsx(St,{severity:"error",count:v.errors}),v.warnings>0&&h.jsx(St,{severity:"warning",count:v.warnings}),!c&&h.jsx("div",{style:{fontSize:o.typography.fontSize.xs,color:o.colors.textSecondary},children:"No budget configured"})]})]}),c?h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(150px, 1fr))",gap:o.spacing.sm},children:[c.fps&&h.jsx(_,{label:"FPS Min",value:c.fps.min,unit:"FPS"}),c.frameTime&&h.jsx(_,{label:"Frame Time Max",value:`${c.frameTime.max.toFixed(2)}ms`}),c.memory?.max&&h.jsx(_,{label:"Memory Max",value:x(c.memory.max)}),c.gpu?.drawCalls?.max&&h.jsx(_,{label:"Draw Calls Max",value:c.gpu.drawCalls.max.toLocaleString()}),c.gpu?.triangles?.max&&h.jsx(_,{label:"Triangles Max",value:c.gpu.triangles.max.toLocaleString()})]}):h.jsx("div",{style:{padding:o.spacing.md,textAlign:"center",color:o.colors.textSecondary,fontSize:o.typography.fontSize.sm},children:"Configure a budget to start monitoring performance thresholds"})]}),h.jsxs("div",{style:{backgroundColor:o.colors.surface,borderRadius:o.borderRadius.md,padding:o.spacing.md,marginBottom:o.spacing.lg,border:`1px solid ${o.colors.border}`},children:[h.jsx("div",{style:{fontSize:o.typography.fontSize.sm,fontWeight:600,color:o.colors.text,marginBottom:o.spacing.md},children:"Budget Configuration"}),d?h.jsxs("div",{children:[h.jsxs("div",{style:{display:"grid",gap:o.spacing.sm,marginBottom:o.spacing.md},children:[h.jsxs("div",{children:[h.jsx("label",{style:{display:"block",fontSize:o.typography.fontSize.xs,color:o.colors.textSecondary,marginBottom:o.spacing.xs},children:"FPS Minimum"}),h.jsx("input",{type:"number",value:u.fps?.min||"",onChange:b=>p({...u,fps:{min:parseInt(b.target.value)||0}}),placeholder:"60",style:{width:"100%",padding:o.spacing.sm,backgroundColor:o.colors.background,border:`1px solid ${o.colors.border}`,borderRadius:o.borderRadius.sm,color:o.colors.text,fontSize:o.typography.fontSize.sm}})]}),h.jsxs("div",{children:[h.jsx("label",{style:{display:"block",fontSize:o.typography.fontSize.xs,color:o.colors.textSecondary,marginBottom:o.spacing.xs},children:"Frame Time Maximum (ms)"}),h.jsx("input",{type:"number",value:u.frameTime?.max||"",onChange:b=>p({...u,frameTime:{max:parseFloat(b.target.value)||0}}),placeholder:"16.67",step:"0.1",style:{width:"100%",padding:o.spacing.sm,backgroundColor:o.colors.background,border:`1px solid ${o.colors.border}`,borderRadius:o.borderRadius.sm,color:o.colors.text,fontSize:o.typography.fontSize.sm}})]}),h.jsxs("div",{children:[h.jsx("label",{style:{display:"block",fontSize:o.typography.fontSize.xs,color:o.colors.textSecondary,marginBottom:o.spacing.xs},children:"Memory Maximum (MB)"}),h.jsx("input",{type:"number",value:u.memory?.max?u.memory.max/(1024*1024):"",onChange:b=>p({...u,memory:{...u.memory,max:(parseFloat(b.target.value)||0)*1024*1024}}),placeholder:"512",step:"1",style:{width:"100%",padding:o.spacing.sm,backgroundColor:o.colors.background,border:`1px solid ${o.colors.border}`,borderRadius:o.borderRadius.sm,color:o.colors.text,fontSize:o.typography.fontSize.sm}})]}),h.jsxs("div",{children:[h.jsx("label",{style:{display:"block",fontSize:o.typography.fontSize.xs,color:o.colors.textSecondary,marginBottom:o.spacing.xs},children:"Draw Calls Maximum"}),h.jsx("input",{type:"number",value:u.gpu?.drawCalls?.max||"",onChange:b=>p({...u,gpu:{...u.gpu,drawCalls:{max:parseInt(b.target.value)||0}}}),placeholder:"100",style:{width:"100%",padding:o.spacing.sm,backgroundColor:o.colors.background,border:`1px solid ${o.colors.border}`,borderRadius:o.borderRadius.sm,color:o.colors.text,fontSize:o.typography.fontSize.sm}})]}),h.jsxs("div",{children:[h.jsx("label",{style:{display:"block",fontSize:o.typography.fontSize.xs,color:o.colors.textSecondary,marginBottom:o.spacing.xs},children:"Triangles Maximum"}),h.jsx("input",{type:"number",value:u.gpu?.triangles?.max||"",onChange:b=>p({...u,gpu:{...u.gpu,triangles:{max:parseInt(b.target.value)||0}}}),placeholder:"100000",style:{width:"100%",padding:o.spacing.sm,backgroundColor:o.colors.background,border:`1px solid ${o.colors.border}`,borderRadius:o.borderRadius.sm,color:o.colors.text,fontSize:o.typography.fontSize.sm}})]})]}),h.jsxs("div",{style:{display:"flex",gap:o.spacing.sm},children:[h.jsx("button",{onClick:y,style:{padding:`${o.spacing.sm} ${o.spacing.md}`,backgroundColor:o.colors.success,color:o.colors.background,border:"none",borderRadius:o.borderRadius.sm,cursor:"pointer",fontSize:o.typography.fontSize.sm,fontWeight:600},children:"Save"}),h.jsx("button",{onClick:w,style:{padding:`${o.spacing.sm} ${o.spacing.md}`,backgroundColor:"transparent",color:o.colors.textSecondary,border:`1px solid ${o.colors.border}`,borderRadius:o.borderRadius.sm,cursor:"pointer",fontSize:o.typography.fontSize.sm,fontWeight:600},children:"Cancel"})]})]}):h.jsxs("div",{style:{display:"flex",gap:o.spacing.sm,flexWrap:"wrap"},children:[h.jsx("button",{onClick:()=>m(!0),style:{padding:`${o.spacing.sm} ${o.spacing.md}`,backgroundColor:o.colors.primary,color:o.colors.background,border:"none",borderRadius:o.borderRadius.sm,cursor:"pointer",fontSize:o.typography.fontSize.sm,fontWeight:600,transition:o.transitions.fast},onMouseEnter:b=>{b.currentTarget.style.backgroundColor=o.colors.primaryHover},onMouseLeave:b=>{b.currentTarget.style.backgroundColor=o.colors.primary},children:c?"Edit Budget":"Set Budget"}),!c&&h.jsx("button",{onClick:g,style:{padding:`${o.spacing.sm} ${o.spacing.md}`,backgroundColor:"transparent",color:o.colors.primary,border:`1px solid ${o.colors.primary}`,borderRadius:o.borderRadius.sm,cursor:"pointer",fontSize:o.typography.fontSize.sm,fontWeight:600,transition:o.transitions.fast},onMouseEnter:b=>{b.currentTarget.style.backgroundColor=`${o.colors.primary}20`},onMouseLeave:b=>{b.currentTarget.style.backgroundColor="transparent"},children:"Use Recommended"}),c&&h.jsx("button",{onClick:()=>{window.confirm("Are you sure you want to delete the current budget?")&&i()},style:{padding:`${o.spacing.sm} ${o.spacing.md}`,backgroundColor:"transparent",color:o.colors.error,border:`1px solid ${o.colors.error}`,borderRadius:o.borderRadius.sm,cursor:"pointer",fontSize:o.typography.fontSize.sm,fontWeight:600,transition:o.transitions.fast},onMouseEnter:b=>{b.currentTarget.style.backgroundColor=`${o.colors.error}20`},onMouseLeave:b=>{b.currentTarget.style.backgroundColor="transparent"},children:"Delete Budget"})]})]}),t.length>0&&h.jsxs("div",{style:{backgroundColor:o.colors.surface,borderRadius:o.borderRadius.md,padding:o.spacing.md,border:`1px solid ${o.colors.border}`},children:[h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:o.spacing.md},children:[h.jsxs("div",{style:{fontSize:o.typography.fontSize.sm,fontWeight:600,color:o.colors.text},children:["Recent Violations (",t.length,")"]}),h.jsx("button",{onClick:s,style:{padding:`${o.spacing.xs} ${o.spacing.sm}`,backgroundColor:"transparent",color:o.colors.textSecondary,border:"none",cursor:"pointer",fontSize:o.typography.fontSize.xs},children:"Clear"})]}),h.jsx("div",{style:{maxHeight:"200px",overflowY:"auto",fontSize:o.typography.fontSize.xs,fontFamily:o.typography.fontFamilyMono},children:t.slice(-10).reverse().map(b=>h.jsxs("div",{style:{padding:o.spacing.sm,borderBottom:`1px solid ${o.colors.border}`,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[h.jsxs("div",{children:[h.jsx("div",{style:{color:b.severity==="error"?o.colors.error:o.colors.warning,fontWeight:600},children:b.metric}),h.jsx("div",{style:{color:o.colors.textSecondary,marginTop:o.spacing.xs},children:b.message})]}),h.jsx(St,{severity:b.severity})]},b.id))})]})]})};class ur{componentStats=new Map;recentRenders=[];totalRenders=0;maxRecentRenders=100;slowThreshold=16;frequentThreshold=10;onRenderCallback=(t,e,s,i,r,n)=>{const a=this.getComponentName(t),l=performance.now(),o={id:t,name:a,phase:e,actualDuration:s,baseDuration:i,startTime:r,commitTime:n,timestamp:l};this.recentRenders.push(o),this.recentRenders.length>this.maxRecentRenders&&this.recentRenders.shift(),this.updateComponentStats(a,o),Ct.onReactRender(s),this.totalRenders++};getComponentName(t){return t.split(":")[0]||t}updateComponentStats(t,e){let s=this.componentStats.get(t);s||(s={name:t,renderCount:0,totalDuration:0,averageDuration:0,maxDuration:0,minDuration:1/0,lastRenderTime:0,phases:{mount:0,update:0}},this.componentStats.set(t,s)),s.renderCount++,s.totalDuration+=e.actualDuration,s.averageDuration=s.totalDuration/s.renderCount,s.maxDuration=Math.max(s.maxDuration,e.actualDuration),s.minDuration=Math.min(s.minDuration,e.actualDuration),s.lastRenderTime=e.timestamp,e.phase==="mount"?s.phases.mount++:s.phases.update++}getPerformanceData(){const t=new Map(this.componentStats),e=Array.from(t.values()).filter(n=>n.averageDuration>this.slowThreshold).sort((n,a)=>a.averageDuration-n.averageDuration),s=performance.now(),i=1e3,r=Array.from(t.values()).filter(n=>s-n.lastRenderTime>i?!1:n.renderCount/(i/1e3)>this.frequentThreshold).sort((n,a)=>a.renderCount-n.renderCount);return{components:t,recentRenders:[...this.recentRenders],totalRenders:this.totalRenders,slowComponents:e,frequentRenders:r,timestamp:performance.now()}}getComponentStats(t){return this.componentStats.get(t)||null}getSlowComponents(){return this.getPerformanceData().slowComponents}getFrequentRenders(){return this.getPerformanceData().frequentRenders}reset(){this.componentStats.clear(),this.recentRenders=[],this.totalRenders=0}}const Qs=new ur;function mr(){const[c,t]=M.useState(null);return M.useEffect(()=>{const e=()=>{if(!E.getPaused()){const r=Qs.getPerformanceData();t(r)}};e();const s=setInterval(e,500),i=E.subscribe(r=>{r||e()});return()=>{clearInterval(s),i()}},[]),c}const pr=()=>{const c=mr(),t=$,e=i=>i<.1?`${R(i*1e3,0)} μs`:i<1?`${R(i,2)} ms`:`${R(i,2)} ms`,s=M.useMemo(()=>c?Array.from(c.components.values()).sort((i,r)=>r.totalDuration-i.totalDuration):[],[c]);return c?h.jsxs("div",{style:{padding:t.spacing.md},children:[h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:"Overview"}),h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(120px, 1fr))",gap:t.spacing.sm},children:[h.jsx(_,{label:"Total Renders",value:c.totalRenders.toLocaleString()}),h.jsx(_,{label:"Components",value:c.components.size.toLocaleString()}),h.jsx(_,{label:"Slow Components",value:c.slowComponents.length.toLocaleString(),status:c.slowComponents.length>0?"warning":"good"}),h.jsx(_,{label:"Frequent Renders",value:c.frequentRenders.length.toLocaleString(),status:c.frequentRenders.length>0?"warning":"good"})]})]}),c.slowComponents.length>0&&h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.warning}40`},children:[h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:t.spacing.sm,marginBottom:t.spacing.sm},children:[h.jsx(St,{severity:"warning",count:c.slowComponents.length}),h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text},children:"Slow Components (avg > 16ms)"})]}),h.jsx("div",{style:{fontSize:t.typography.fontSize.xs,color:t.colors.textSecondary,fontFamily:t.typography.fontFamilyMono},children:c.slowComponents.slice(0,5).map(i=>h.jsxs("div",{style:{marginBottom:t.spacing.xs},children:[i.name,": ",e(i.averageDuration)," avg (",i.renderCount," renders)"]},i.name))})]}),c.frequentRenders.length>0&&h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.warning}40`},children:[h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:t.spacing.sm,marginBottom:t.spacing.sm},children:[h.jsx(St,{severity:"warning",count:c.frequentRenders.length}),h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text},children:"Frequent Renders (> 10 renders/sec)"})]}),h.jsx("div",{style:{fontSize:t.typography.fontSize.xs,color:t.colors.textSecondary,fontFamily:t.typography.fontFamilyMono},children:c.frequentRenders.slice(0,5).map(i=>h.jsxs("div",{style:{marginBottom:t.spacing.xs},children:[i.name,": ",i.renderCount," renders"]},i.name))})]}),h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,border:`1px solid ${t.colors.border}`},children:[h.jsxs("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:["Components (",s.length,")"]}),h.jsx("div",{style:{maxHeight:"400px",overflowY:"auto"},children:s.length===0?h.jsx("div",{style:{padding:t.spacing.md,textAlign:"center",color:t.colors.textSecondary,fontSize:t.typography.fontSize.sm},children:"No components profiled yet"}):h.jsx(fr,{components:s,formatTime:e})})]})]}):h.jsx("div",{style:{padding:t.spacing.lg,textAlign:"center",color:t.colors.textSecondary,fontSize:t.typography.fontSize.sm},children:"Aucune donnée React disponible. Enveloppez vos composants avec <ReactProfiler> pour commencer le monitoring."})},fr=({components:c,formatTime:t})=>{const e=$;return h.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:e.typography.fontSize.xs,fontFamily:e.typography.fontFamilyMono},children:[h.jsx("thead",{children:h.jsxs("tr",{style:{borderBottom:`1px solid ${e.colors.border}`},children:[h.jsx("th",{style:{textAlign:"left",padding:e.spacing.sm,color:e.colors.textSecondary,fontWeight:600},children:"Component"}),h.jsx("th",{style:{textAlign:"right",padding:e.spacing.sm,color:e.colors.textSecondary,fontWeight:600},children:"Renders"}),h.jsx("th",{style:{textAlign:"right",padding:e.spacing.sm,color:e.colors.textSecondary,fontWeight:600},children:"Avg Time"}),h.jsx("th",{style:{textAlign:"right",padding:e.spacing.sm,color:e.colors.textSecondary,fontWeight:600},children:"Max Time"}),h.jsx("th",{style:{textAlign:"right",padding:e.spacing.sm,color:e.colors.textSecondary,fontWeight:600},children:"Total Time"})]})}),h.jsx("tbody",{children:c.map(s=>{const i=s.averageDuration>16,r=s.renderCount>10;return h.jsxs("tr",{style:{borderBottom:`1px solid ${e.colors.border}`,backgroundColor:i||r?`${e.colors.warning}10`:"transparent"},children:[h.jsx("td",{style:{padding:e.spacing.sm,color:e.colors.text,fontWeight:i||r?600:400},children:s.name}),h.jsx("td",{style:{textAlign:"right",padding:e.spacing.sm,color:e.colors.textSecondary},children:s.renderCount.toLocaleString()}),h.jsx("td",{style:{textAlign:"right",padding:e.spacing.sm,color:i?e.colors.warning:e.colors.textSecondary,fontWeight:i?600:400},children:t(s.averageDuration)}),h.jsx("td",{style:{textAlign:"right",padding:e.spacing.sm,color:e.colors.textSecondary},children:t(s.maxDuration)}),h.jsx("td",{style:{textAlign:"right",padding:e.spacing.sm,color:e.colors.textSecondary},children:t(s.totalDuration)})]},s.name)})})]})};class gr{functionCalls=new Map;callHistory=[];maxHistorySize=1e3;hotPathThreshold=5;frequencyThreshold=10;recordCall(t,e,s){const i=performance.now();let r=this.functionCalls.get(t);r||(r={name:t,duration:0,timestamp:i,callCount:0,averageDuration:0,maxDuration:0,stack:s||[]},this.functionCalls.set(t,r)),r.callCount++,r.duration+=e,r.averageDuration=r.duration/r.callCount,r.maxDuration=Math.max(r.maxDuration,e),r.timestamp=i,this.callHistory.push({name:t,duration:e,timestamp:i}),this.callHistory.length>this.maxHistorySize&&this.callHistory.shift()}analyze(t){const e=performance.now(),s=5e3,i=e-s,r=this.callHistory.filter(u=>u.timestamp>=i),n=new Map;r.forEach(u=>{const p=n.get(u.name)||0;n.set(u.name,p+1)});const a=new Map;n.forEach((u,p)=>{a.set(p,u/s*1e3)});const l=[],o=[],d=[];this.functionCalls.forEach((u,p)=>{const f=a.get(p)||0,x=u.averageDuration>this.hotPathThreshold,y=f>this.frequencyThreshold;if(x||y){const w=u.averageDuration>16?"high":u.averageDuration>8?"medium":"low",v=[];x&&v.push(`Optimize ${p} - average duration: ${u.averageDuration.toFixed(2)}ms`),y&&v.push(`Reduce calls to ${p} - ${f.toFixed(1)} calls/sec`),u.maxDuration>u.averageDuration*2&&v.push(`Investigate performance spikes in ${p} - max: ${u.maxDuration.toFixed(2)}ms`);const b={id:`hotpath-${p}-${Date.now()}`,path:[p],totalDuration:u.duration,averageDuration:u.averageDuration,callCount:u.callCount,frequency:f,impact:w,recommendations:v};l.push(b),x&&d.push(b)}o.push(u)}),o.sort((u,p)=>p.duration-u.duration);const m=[];return d.length>0&&m.push(`Found ${d.length} performance bottlenecks`),l.length>5&&m.push("Consider optimizing multiple hot paths simultaneously"),t&&t.forEach(u=>{u.avg>this.hotPathThreshold&&m.push(`Hook "${u.name}" takes ${u.avg.toFixed(2)}ms on average`)}),{hotPaths:l.sort((u,p)=>p.averageDuration-u.averageDuration),topFunctions:o.slice(0,10),bottlenecks:d.sort((u,p)=>p.averageDuration-u.averageDuration),recommendations:m,timestamp:e}}detectCallChain(t){const e=new Map;this.callHistory.forEach(i=>{const r=i.name;let n=e.get(r);n||(n={path:[i.name],duration:0,count:0},e.set(r,n)),n.duration+=i.duration,n.count++});const s=[];return e.forEach((i,r)=>{const n=i.duration/i.count;n>this.hotPathThreshold&&s.push({id:`chain-${r}-${Date.now()}`,path:i.path,totalDuration:i.duration,averageDuration:n,callCount:i.count,frequency:i.count/5,impact:n>16?"high":n>8?"medium":"low",recommendations:[`Optimize call chain: ${i.path.join(" -> ")}`]})}),s}reset(){this.functionCalls.clear(),this.callHistory=[]}getTopFunctions(t=10){return Array.from(this.functionCalls.values()).sort((e,s)=>s.duration-e.duration).slice(0,t)}}const es=new gr,yr=Object.freeze(Object.defineProperty({__proto__:null,hotPathDetector:es},Symbol.toStringTag,{value:"Module"}));function xr(){const[c,t]=M.useState(null),e=Vt();return M.useEffect(()=>{const s=()=>{if(!E.getPaused()){const n=es.analyze(e?.entries);t(n)}};s();const i=setInterval(s,2e3),r=E.subscribe(n=>{n||s()});return()=>{clearInterval(i),r()}},[e]),c}const br=()=>{const c=xr(),t=$,e=i=>i<.1?`${R(i*1e3,0)} μs`:i<1?`${R(i,2)} ms`:`${R(i,2)} ms`,s={high:t.colors.error,medium:t.colors.warning,low:t.colors.info};return c?h.jsxs("div",{style:{padding:t.spacing.md},children:[h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:"Overview"}),h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(120px, 1fr))",gap:t.spacing.sm},children:[h.jsx(_,{label:"Hot Paths",value:c.hotPaths.length.toLocaleString(),status:c.hotPaths.length>0?"warning":"good"}),h.jsx(_,{label:"Bottlenecks",value:c.bottlenecks.length.toLocaleString(),status:c.bottlenecks.length>0?"error":"good"}),h.jsx(_,{label:"Top Functions",value:c.topFunctions.length.toLocaleString()})]})]}),c.recommendations.length>0&&h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.warning}40`},children:[h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:t.spacing.sm,marginBottom:t.spacing.sm},children:[h.jsx(St,{severity:"warning"}),h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text},children:"Recommendations"})]}),h.jsx("div",{style:{fontSize:t.typography.fontSize.xs,color:t.colors.textSecondary,fontFamily:t.typography.fontFamilyMono},children:c.recommendations.map((i,r)=>h.jsxs("div",{style:{marginBottom:t.spacing.xs},children:["• ",i]},r))})]}),c.bottlenecks.length>0&&h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.error}40`},children:[h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:t.spacing.sm,marginBottom:t.spacing.sm},children:[h.jsx(St,{severity:"error",count:c.bottlenecks.length}),h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text},children:"Performance Bottlenecks"})]}),h.jsx("div",{style:{maxHeight:"300px",overflowY:"auto"},children:c.bottlenecks.map(i=>h.jsxs("div",{style:{padding:t.spacing.sm,borderBottom:`1px solid ${t.colors.border}`,backgroundColor:`${s[i.impact]}10`},children:[h.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:t.spacing.xs},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:s[i.impact],fontFamily:t.typography.fontFamilyMono},children:i.path.join(" -> ")}),h.jsxs("div",{style:{fontSize:t.typography.fontSize.xs,color:t.colors.textSecondary},children:[e(i.averageDuration)," avg"]})]}),h.jsxs("div",{style:{fontSize:t.typography.fontSize.xs,color:t.colors.textSecondary,marginBottom:t.spacing.xs},children:[i.callCount.toLocaleString()," calls • ",i.frequency.toFixed(1)," calls/sec"]}),i.recommendations.length>0&&h.jsx("div",{style:{fontSize:t.typography.fontSize.xs,color:t.colors.textTertiary,fontStyle:"italic"},children:i.recommendations[0]})]},i.id))})]}),c.hotPaths.length>0&&h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,marginBottom:t.spacing.lg,border:`1px solid ${t.colors.border}`},children:[h.jsxs("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:["Hot Paths (",c.hotPaths.length,")"]}),h.jsx("div",{style:{maxHeight:"400px",overflowY:"auto"},children:h.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:t.typography.fontSize.xs,fontFamily:t.typography.fontFamilyMono},children:[h.jsx("thead",{children:h.jsxs("tr",{style:{borderBottom:`1px solid ${t.colors.border}`},children:[h.jsx("th",{style:{textAlign:"left",padding:t.spacing.sm,color:t.colors.textSecondary,fontWeight:600},children:"Path"}),h.jsx("th",{style:{textAlign:"right",padding:t.spacing.sm,color:t.colors.textSecondary,fontWeight:600},children:"Avg Time"}),h.jsx("th",{style:{textAlign:"right",padding:t.spacing.sm,color:t.colors.textSecondary,fontWeight:600},children:"Calls"}),h.jsx("th",{style:{textAlign:"right",padding:t.spacing.sm,color:t.colors.textSecondary,fontWeight:600},children:"Freq/sec"}),h.jsx("th",{style:{textAlign:"center",padding:t.spacing.sm,color:t.colors.textSecondary,fontWeight:600},children:"Impact"})]})}),h.jsx("tbody",{children:c.hotPaths.map(i=>h.jsxs("tr",{style:{borderBottom:`1px solid ${t.colors.border}`,backgroundColor:`${s[i.impact]}10`},children:[h.jsx("td",{style:{padding:t.spacing.sm,color:t.colors.text},children:i.path.join(" -> ")}),h.jsx("td",{style:{textAlign:"right",padding:t.spacing.sm,color:s[i.impact],fontWeight:600},children:e(i.averageDuration)}),h.jsx("td",{style:{textAlign:"right",padding:t.spacing.sm,color:t.colors.textSecondary},children:i.callCount.toLocaleString()}),h.jsx("td",{style:{textAlign:"right",padding:t.spacing.sm,color:t.colors.textSecondary},children:R(i.frequency,1)}),h.jsx("td",{style:{textAlign:"center",padding:t.spacing.sm},children:h.jsx(St,{severity:i.impact==="high"?"error":i.impact==="medium"?"warning":"info"})})]},i.id))})]})})]}),c.topFunctions.length>0&&h.jsxs("div",{style:{backgroundColor:t.colors.surface,borderRadius:t.borderRadius.md,padding:t.spacing.md,border:`1px solid ${t.colors.border}`},children:[h.jsx("div",{style:{fontSize:t.typography.fontSize.sm,fontWeight:600,color:t.colors.text,marginBottom:t.spacing.sm},children:"Top Functions (by total duration)"}),h.jsx("div",{style:{maxHeight:"300px",overflowY:"auto",fontSize:t.typography.fontSize.xs,fontFamily:t.typography.fontFamilyMono,color:t.colors.textSecondary},children:c.topFunctions.map((i,r)=>h.jsxs("div",{style:{padding:t.spacing.sm,borderBottom:`1px solid ${t.colors.border}`,display:"flex",justifyContent:"space-between"},children:[h.jsxs("span",{children:[r+1,". ",i.name]}),h.jsxs("span",{children:[e(i.averageDuration)," avg (",i.callCount.toLocaleString()," calls)"]})]},i.name))})]})]}):h.jsx("div",{style:{padding:t.spacing.lg,textAlign:"center",color:t.colors.textSecondary,fontSize:t.typography.fontSize.sm},children:"Aucune analyse de hot path disponible. Les hot paths sont détectés automatiquement à partir des données du profiler."})},Sr=({position:c="top-right",defaultTab:t="frames",collapsed:e=!1})=>{const[s,i]=M.useState(!1),[r,n]=M.useState(t),[a,l]=M.useState(e),[o,d]=M.useState(E.getPaused()),[m,u]=M.useState(!1),[p,f]=M.useState(null),x=M.useRef(null),y=M.useRef(null),g=$,w="r3f-profiler-state";M.useEffect(()=>{const z=localStorage.getItem(w);if(z)try{const k=JSON.parse(z);k.position&&typeof k.position.x=="number"&&typeof k.position.y=="number"&&f({x:k.position.x,y:k.position.y}),typeof k.collapsed=="boolean"&&l(k.collapsed),typeof k.activeTab=="string"&&k.activeTab&&n(k.activeTab)}catch(k){console.warn("Failed to load saved profiler state:",k)}const T=E.subscribe(k=>{d(k)});return()=>{T()}},[]);const v=M.useCallback(z=>{try{const T=localStorage.getItem(w),W={...T?JSON.parse(T):{},...z};localStorage.setItem(w,JSON.stringify(W))}catch(T){console.warn("Failed to save profiler state:",T)}},[]),b=M.useCallback((z,T)=>{v({position:{x:z,y:T}})},[v]),F=M.useCallback(z=>{if(!z.target.closest("button")&&(u(!0),y.current)){const T=y.current.getBoundingClientRect();x.current={x:z.clientX-T.left,y:z.clientY-T.top}}},[]);if(M.useEffect(()=>{if(!m)return;const z=k=>{if(!x.current||!y.current)return;const I=y.current.getBoundingClientRect(),rt=window.innerWidth,Tt=window.innerHeight;let mt=k.clientX-x.current.x,pt=k.clientY-x.current.y;mt=Math.max(0,Math.min(mt,rt-I.width)),pt=Math.max(0,Math.min(pt,Tt-I.height));const Mt={x:mt,y:pt};f(Mt),v({position:Mt})},T=()=>{u(!1),x.current=null};return window.addEventListener("mousemove",z),window.addEventListener("mouseup",T),()=>{window.removeEventListener("mousemove",z),window.removeEventListener("mouseup",T)}},[m,b]),M.useEffect(()=>{const z=()=>Ae();i(z());const T=()=>{i(z())};return window.addEventListener("storage",T),()=>{window.removeEventListener("storage",T)}},[]),!s)return null;const A=[{id:"frames",label:"Frames"},{id:"gpu",label:"GPU"},{id:"scene",label:"Scene"},{id:"memory",label:"Memory"},{id:"frame-time",label:"Frame Time"},{id:"budget",label:"Budget"},{id:"react",label:"React"},{id:"hot-path",label:"Hot Path"}],j=p?{left:`${p.x}px`,top:`${p.y}px`,right:"auto",bottom:"auto"}:{"top-left":{top:g.spacing.md,left:g.spacing.md,right:"auto",bottom:"auto"},"top-right":{top:g.spacing.md,right:g.spacing.md,left:"auto",bottom:"auto"},"bottom-left":{bottom:g.spacing.md,left:g.spacing.md,right:"auto",top:"auto"},"bottom-right":{bottom:g.spacing.md,right:g.spacing.md,left:"auto",top:"auto"}}[c];return h.jsxs("div",{ref:y,style:{position:"fixed",...j,width:a?"auto":"600px",maxWidth:a?"auto":"90vw",maxHeight:"80vh",backgroundColor:g.colors.background,backdropFilter:"blur(10px)",borderRadius:g.borderRadius.lg,boxShadow:g.shadows.xl,border:`1px solid ${g.colors.border}`,zIndex:g.zIndex.base,display:"flex",flexDirection:"column",overflow:"hidden",transition:m?"none":g.transitions.normal,userSelect:m?"none":"auto"},children:[h.jsxs("div",{onMouseDown:F,style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:g.spacing.md,borderBottom:`1px solid ${g.colors.border}`,backgroundColor:g.colors.surface,cursor:m?"grabbing":"grab",userSelect:"none"},children:[h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:g.spacing.sm,flex:1},children:[h.jsx("div",{style:{display:"flex",alignItems:"center",gap:g.spacing.xs,color:g.colors.textTertiary,fontSize:g.typography.fontSize.xs},children:h.jsx("span",{children:"⋮⋮"})}),h.jsx("div",{style:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:g.colors.success,boxShadow:`0 0 8px ${g.colors.success}`}}),h.jsx("h2",{style:{margin:0,fontSize:g.typography.fontSize.lg,fontWeight:600,color:g.colors.text},children:"Performance Monitor"})]}),h.jsxs("div",{style:{display:"flex",gap:g.spacing.xs,alignItems:"center"},children:[o&&h.jsx("div",{style:{fontSize:g.typography.fontSize.xs,color:g.colors.warning,fontFamily:g.typography.fontFamilyMono,padding:`0 ${g.spacing.xs}`},children:"PAUSED"}),h.jsx("button",{onClick:()=>{E.toggle()},style:{background:"transparent",border:"none",color:o?g.colors.warning:g.colors.textSecondary,cursor:"pointer",padding:g.spacing.xs,borderRadius:g.borderRadius.sm,transition:g.transitions.fast,display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:z=>{z.currentTarget.style.backgroundColor=g.colors.surfaceElevated,z.currentTarget.style.color=o?g.colors.warning:g.colors.text},onMouseLeave:z=>{z.currentTarget.style.backgroundColor="transparent",z.currentTarget.style.color=o?g.colors.warning:g.colors.textSecondary},title:o?"Resume":"Pause",children:o?"▶":"⏸"}),h.jsx("button",{onClick:async()=>{const{profiler:z}=await Promise.resolve().then(()=>ei);await z.copyReportToClipboard(),alert("📊 Performance report copied to clipboard!")},style:{background:"transparent",border:"none",color:g.colors.textSecondary,cursor:"pointer",padding:g.spacing.xs,borderRadius:g.borderRadius.sm,transition:g.transitions.fast,display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:z=>{z.currentTarget.style.backgroundColor=g.colors.surfaceElevated,z.currentTarget.style.color=g.colors.success},onMouseLeave:z=>{z.currentTarget.style.backgroundColor="transparent",z.currentTarget.style.color=g.colors.textSecondary},title:"Copy Performance Report (for AI analysis)",children:"📊"}),h.jsx("button",{onClick:()=>{const z=!a;l(z),v({collapsed:z})},style:{background:"transparent",border:"none",color:g.colors.textSecondary,cursor:"pointer",padding:g.spacing.xs,borderRadius:g.borderRadius.sm,transition:g.transitions.fast,display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:z=>{z.currentTarget.style.backgroundColor=g.colors.surfaceElevated,z.currentTarget.style.color=g.colors.text},onMouseLeave:z=>{z.currentTarget.style.backgroundColor="transparent",z.currentTarget.style.color=g.colors.textSecondary},title:a?"Expand":"Collapse",children:a?"◀":"▼"})]})]}),!a&&h.jsxs(h.Fragment,{children:[h.jsx("div",{style:{padding:`0 ${g.spacing.md}`,backgroundColor:g.colors.surface},children:h.jsx(Xi,{tabs:A,activeTab:r,onTabChange:z=>{n(z),v({activeTab:z})}})}),h.jsxs("div",{style:{flex:1,overflow:"auto",backgroundColor:g.colors.background},children:[r==="frames"&&h.jsx(er,{}),r==="gpu"&&h.jsx(sr,{}),r==="scene"&&h.jsx(rr,{}),r==="memory"&&h.jsx(nr,{}),r==="frame-time"&&h.jsx(or,{}),r==="budget"&&h.jsx(dr,{}),r==="react"&&h.jsx(pr,{}),r==="hot-path"&&h.jsx(br,{})]})]})]})},Ks=()=>{const c=Vt(),[t,e]=M.useState(!1);if(M.useEffect(()=>{const i=()=>Ae();e(i());const r=()=>{e(i())};return window.addEventListener("storage",r),()=>{window.removeEventListener("storage",r)}},[]),t){if(!c||c.entries.length===0)return h.jsxs("div",{style:{position:"fixed",top:"20px",right:"20px",backgroundColor:"#1a1a1a",color:"#ffffff",padding:"16px",borderRadius:"8px",fontFamily:"monospace",fontSize:"12px",zIndex:1e4,boxShadow:"0 4px 6px rgba(0, 0, 0, 0.3)",minWidth:"300px"},children:[h.jsx("div",{style:{fontSize:"14px",fontWeight:"bold",marginBottom:"12px",borderBottom:"1px solid #333",paddingBottom:"8px"},children:"Frame Profiler"}),h.jsx("div",{style:{color:"#aaa",fontSize:"11px"},children:"Aucune donnée profilée pour le moment."})]})}else return null;const s=[...c.entries].sort((i,r)=>r.total-i.total);return h.jsxs("div",{style:{position:"fixed",top:"20px",right:"20px",backgroundColor:"#1a1a1a",color:"#ffffff",padding:"16px",borderRadius:"8px",fontFamily:"monospace",fontSize:"12px",zIndex:1e4,boxShadow:"0 4px 6px rgba(0, 0, 0, 0.3)",minWidth:"400px",maxWidth:"600px"},children:[h.jsx("div",{style:{fontSize:"14px",fontWeight:"bold",marginBottom:"12px",borderBottom:"1px solid #333",paddingBottom:"8px"},children:"Frame Profiler"}),h.jsxs("div",{style:{marginBottom:"12px",color:"#aaa",fontSize:"11px",lineHeight:"1.6"},children:[h.jsxs("div",{children:[h.jsx("strong",{children:"Total:"})," ",c.totalTime.toFixed(2),"ms"]}),h.jsxs("div",{children:[h.jsx("strong",{children:"Calls:"})," ",c.calls]}),h.jsxs("div",{children:[h.jsx("strong",{children:"Frames:"})," ",c.frames]})]}),h.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",marginTop:"12px"},children:[h.jsx("thead",{children:h.jsxs("tr",{style:{borderBottom:"1px solid #333"},children:[h.jsx("th",{style:{textAlign:"left",padding:"4px 8px",color:"#aaa"},children:"Hook"}),h.jsx("th",{style:{textAlign:"right",padding:"4px 8px",color:"#aaa"},children:"Total (ms)"}),h.jsx("th",{style:{textAlign:"right",padding:"4px 8px",color:"#aaa"},children:"Avg (ms)"}),h.jsx("th",{style:{textAlign:"right",padding:"4px 8px",color:"#aaa"},children:"Max (ms)"}),h.jsx("th",{style:{textAlign:"right",padding:"4px 8px",color:"#aaa"},children:"%"})]})}),h.jsx("tbody",{children:s.map(i=>h.jsxs("tr",{style:{borderBottom:"1px solid #222"},children:[h.jsx("td",{style:{padding:"6px 8px",color:"#fff",fontFamily:"monospace"},children:i.name}),h.jsx("td",{style:{textAlign:"right",padding:"6px 8px",color:"#fff",fontFamily:"monospace"},children:i.total.toFixed(2)}),h.jsx("td",{style:{textAlign:"right",padding:"6px 8px",color:"#fff",fontFamily:"monospace"},children:i.avg.toFixed(3)}),h.jsx("td",{style:{textAlign:"right",padding:"6px 8px",color:"#fff",fontFamily:"monospace"},children:i.max.toFixed(3)}),h.jsxs("td",{style:{textAlign:"right",padding:"6px 8px",color:"#fff",fontFamily:"monospace"},children:[i.percentage.toFixed(1),"%"]})]},i.name))})]})]})},wr=({id:c,children:t,onRender:e})=>{const s=(i,r,n,a,l,o)=>{Qs.onRenderCallback(i,r,n,a,l,o),e&&e(i,r,n,a,l,o)};return h.jsx(M.Profiler,{id:c,onRender:s,children:t})};exports.FrameProfiler=Ks;exports.PerformanceMonitor=Sr;exports.ProfilerDataCollector=ai;exports.R3FStatsCollector=Ui;exports.ReactProfiler=wr;exports.default=Ks;exports.getProfilerData=Ws;exports.hotPathDetector=es;exports.isProfilerEnabled=Ae;exports.profile=Es;exports.profileAsync=Ds;exports.profiler=P;exports.record=Is;exports.reportGenerator=Ns;exports.reportMetric=Hs;exports.resetProfiler=Os;exports.useMetricsCollector=Gi;exports.useProfiled=ii;exports.useProfiledAsync=ri;exports.useProfiledFrame=ni;exports.useProfilerData=Vt;exports.useReportMetric=Yi;exports.wrap=$s;exports.wrapAsync=Ls;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../index-D_LaF0YP.cjs");exports.PerformanceMonitor=r.PerformanceMonitor;exports.ProfilerDataCollector=r.ProfilerDataCollector;exports.R3FStatsCollector=r.R3FStatsCollector;exports.isProfilerEnabled=r.isProfilerEnabled;exports.profile=r.profile;exports.reportMetric=r.reportMetric;
|
|
62
2
|
//# sourceMappingURL=index.js.map
|