claude-live 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,14 +46,7 @@ With the plugin installed, manage the server from inside Claude Code:
46
46
 
47
47
  The server watches Claude Code's session transcript files (`~/.claude/projects/`) and tails them in real time. No hooks or additional configuration required.
48
48
 
49
- Each Claude Code session appears as an orbiting star system. Every tool call creates a node — the more events a session generates, the larger it grows. Tool calls trigger visual effects:
50
-
51
- - **Read / Grep / Glob** — scan effect radiates from the node
52
- - **Edit / Write** — energy beam fires from core to node
53
- - **Bash** — spark burst at the node
54
- - **Subagents** — child systems orbit their parent session
55
-
56
- Multiple Claude sessions show as separate star systems. Prompts pulse outward, context compaction triggers an implosion/rebirth effect.
49
+ Each Claude Code session appears as an orbiting star system. Every tool call creates a node — the more events a session generates, the larger it grows. Multiple sessions show as separate star systems. Prompts pulse outward, context compaction triggers an implosion/rebirth effect.
57
50
 
58
51
  ## Server Endpoints
59
52
 
@@ -1,4 +1,4 @@
1
- import{C as W,G as p,a as b,W as z,S as M,P as A,O as S,B as k,b as C,M as F,A as u,d as h,E as j,R,U as L,V,g as E,L as _,h as G,Q as I,k as g,D as f,I as P,r as v,l as o}from"./index-D3vltDuF.js";class D{constructor(e){this.clock=new W,this.elapsed=0,this.agentGroup=new p,this.currentVisual=null,this.currentVariation=null,this.agentTetherLine=null,this.wanderOffsets=new b(Math.random()*100,Math.random()*100,Math.random()*100),this.pulseTimer=0,this.pulseInterval=2,this._onResize=()=>{const d=this.renderer.domElement.parentElement;if(!d)return;const y=Math.max(1,d.clientWidth),l=Math.max(1,d.clientHeight);this.camera.aspect=y/l,this.camera.updateProjectionMatrix(),this.renderer.setSize(y,l),this.composer.setSize(y,l)},this.renderer=new z({antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.renderer.setSize(e.clientWidth,e.clientHeight),this.renderer.setClearColor(197384),e.appendChild(this.renderer.domElement),this.scene=new M;const t=Math.max(1,e.clientWidth),r=Math.max(1,e.clientHeight);this.camera=new A(55,t/r,1,2e3),this.camera.position.set(0,30,110),this.controls=new S(this.camera,this.renderer.domElement),this.controls.enableDamping=!0,this.controls.dampingFactor=.06,this.controls.autoRotate=!0,this.controls.autoRotateSpeed=.5,this.controls.target.set(0,15,0),this.controls.minDistance=20,this.controls.maxDistance=300,this.background=new k,this.scene.add(this.background.group);const n=new C(3,16,16),a=new F({color:4491519,transparent:!0,opacity:.5,blending:u}),i=new h(n,a);this.scene.add(i),this.scene.add(this.agentGroup),this.composer=new j(this.renderer),this.composer.addPass(new R(this.scene,this.camera));const c=new L(new V(e.clientWidth,e.clientHeight),1.2,.4,.15);this.composer.addPass(c),this.scene.updateMatrixWorld(!0),this.resizeObserver=new ResizeObserver(this._onResize),this.resizeObserver.observe(e),window.addEventListener("resize",this._onResize),this._onResize()}setVariation(e){if(this.currentVariation=e,this._clearVisual(),this.currentVisual=e.build(this.agentGroup),!this.agentTetherLine){const t=new E().setFromPoints(new Array(21).fill(new b)),r=new _({color:4500223,transparent:!0,opacity:.2,blending:u});this.agentTetherLine=new G(t,r),this.scene.add(this.agentTetherLine)}this.pulseTimer=0}triggerPulse(){var e,t;(t=(e=this.currentVisual)==null?void 0:e.pulse)==null||t.call(e)}_clearVisual(){this.currentVisual&&(this.currentVisual.dispose(),this.currentVisual=null)}tick(){const e=Math.min(this.clock.getDelta(),.05);if(this.elapsed+=e,this.controls.update(),this.background.tick(e),this.currentVisual){this.currentVisual.tick(e,this.elapsed);const t=.25;this.wanderOffsets.x+=e*t*.8,this.wanderOffsets.y+=e*t*1.1,this.wanderOffsets.z+=e*t*.9;const r=50;if(this.agentGroup.position.set(Math.sin(this.wanderOffsets.x)*r,25+Math.sin(this.wanderOffsets.y)*15,Math.cos(this.wanderOffsets.z)*r*Math.cos(this.wanderOffsets.x*.5)),this.agentTetherLine){const n=new b(0,0,0),a=this.agentGroup.position.clone(),i=n.clone().lerp(a,.5);i.y-=10+Math.sin(this.elapsed*2)*4;const c=new I(n,i,a);this.agentTetherLine.geometry.setFromPoints(c.getPoints(20))}this.pulseTimer+=e,this.pulseTimer>=this.pulseInterval&&(this.pulseTimer=0,this.pulseInterval=1.5+Math.random()*3)}try{this.composer.render()}catch{}}destroy(){this.resizeObserver.disconnect(),window.removeEventListener("resize",this._onResize),this.renderer.dispose(),this.renderer.domElement.remove(),this._clearVisual(),this.agentTetherLine&&(this.scene.remove(this.agentTetherLine),this.agentTetherLine.geometry.dispose(),this.agentTetherLine.material.dispose())}}const w=new P(3.5,128),T=new P(3.5,32).toNonIndexed();function O(s){const e=new p;s.add(e);const t=new g({uniforms:{uTime:{value:0},uActivity:{value:0}},vertexShader:`
1
+ import{C as W,G as p,a as b,W as z,S as M,P as A,O as S,B as k,b as C,M as F,A as u,d as h,E as j,R,U as L,V,g as E,L as _,h as G,Q as I,k as g,D as f,I as P,r as v,l as o}from"./index-cWLk4rCz.js";class D{constructor(e){this.clock=new W,this.elapsed=0,this.agentGroup=new p,this.currentVisual=null,this.currentVariation=null,this.agentTetherLine=null,this.wanderOffsets=new b(Math.random()*100,Math.random()*100,Math.random()*100),this.pulseTimer=0,this.pulseInterval=2,this._onResize=()=>{const d=this.renderer.domElement.parentElement;if(!d)return;const y=Math.max(1,d.clientWidth),l=Math.max(1,d.clientHeight);this.camera.aspect=y/l,this.camera.updateProjectionMatrix(),this.renderer.setSize(y,l),this.composer.setSize(y,l)},this.renderer=new z({antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.renderer.setSize(e.clientWidth,e.clientHeight),this.renderer.setClearColor(197384),e.appendChild(this.renderer.domElement),this.scene=new M;const t=Math.max(1,e.clientWidth),r=Math.max(1,e.clientHeight);this.camera=new A(55,t/r,1,2e3),this.camera.position.set(0,30,110),this.controls=new S(this.camera,this.renderer.domElement),this.controls.enableDamping=!0,this.controls.dampingFactor=.06,this.controls.autoRotate=!0,this.controls.autoRotateSpeed=.5,this.controls.target.set(0,15,0),this.controls.minDistance=20,this.controls.maxDistance=300,this.background=new k,this.scene.add(this.background.group);const n=new C(3,16,16),a=new F({color:4491519,transparent:!0,opacity:.5,blending:u}),i=new h(n,a);this.scene.add(i),this.scene.add(this.agentGroup),this.composer=new j(this.renderer),this.composer.addPass(new R(this.scene,this.camera));const c=new L(new V(e.clientWidth,e.clientHeight),1.2,.4,.15);this.composer.addPass(c),this.scene.updateMatrixWorld(!0),this.resizeObserver=new ResizeObserver(this._onResize),this.resizeObserver.observe(e),window.addEventListener("resize",this._onResize),this._onResize()}setVariation(e){if(this.currentVariation=e,this._clearVisual(),this.currentVisual=e.build(this.agentGroup),!this.agentTetherLine){const t=new E().setFromPoints(new Array(21).fill(new b)),r=new _({color:4500223,transparent:!0,opacity:.2,blending:u});this.agentTetherLine=new G(t,r),this.scene.add(this.agentTetherLine)}this.pulseTimer=0}triggerPulse(){var e,t;(t=(e=this.currentVisual)==null?void 0:e.pulse)==null||t.call(e)}_clearVisual(){this.currentVisual&&(this.currentVisual.dispose(),this.currentVisual=null)}tick(){const e=Math.min(this.clock.getDelta(),.05);if(this.elapsed+=e,this.controls.update(),this.background.tick(e),this.currentVisual){this.currentVisual.tick(e,this.elapsed);const t=.25;this.wanderOffsets.x+=e*t*.8,this.wanderOffsets.y+=e*t*1.1,this.wanderOffsets.z+=e*t*.9;const r=50;if(this.agentGroup.position.set(Math.sin(this.wanderOffsets.x)*r,25+Math.sin(this.wanderOffsets.y)*15,Math.cos(this.wanderOffsets.z)*r*Math.cos(this.wanderOffsets.x*.5)),this.agentTetherLine){const n=new b(0,0,0),a=this.agentGroup.position.clone(),i=n.clone().lerp(a,.5);i.y-=10+Math.sin(this.elapsed*2)*4;const c=new I(n,i,a);this.agentTetherLine.geometry.setFromPoints(c.getPoints(20))}this.pulseTimer+=e,this.pulseTimer>=this.pulseInterval&&(this.pulseTimer=0,this.pulseInterval=1.5+Math.random()*3)}try{this.composer.render()}catch{}}destroy(){this.resizeObserver.disconnect(),window.removeEventListener("resize",this._onResize),this.renderer.dispose(),this.renderer.domElement.remove(),this._clearVisual(),this.agentTetherLine&&(this.scene.remove(this.agentTetherLine),this.agentTetherLine.geometry.dispose(),this.agentTetherLine.material.dispose())}}const w=new P(3.5,128),T=new P(3.5,32).toNonIndexed();function O(s){const e=new p;s.add(e);const t=new g({uniforms:{uTime:{value:0},uActivity:{value:0}},vertexShader:`
2
2
  uniform float uTime; uniform float uActivity;
3
3
  varying vec3 vWorldPos;
4
4
 
@@ -0,0 +1 @@
1
+ import{C as U,G as O,c as x,W as $,a6 as _,aj as Y,S as X,P as Z,O as J,B as K,a9 as Q,ab as B,d as N,I as W,ak as ee,al as q,M as T,ac as te,E as se,R as ne,U as ie,V as oe,a as p,am as re,A as j,an as ae,ao as ce,Y as G,X as E,v as le,$ as he,a5 as de,_ as pe,r as w,l as h}from"./index-cWLk4rCz.js";class ue{constructor(e){this.clock=new U,this.elapsed=0,this.visualGroup=new O,this.currentVisual=null,this.pulseTimer=0,this.pulseInterval=2.6,this.coreActivity=0,this.accent=new x("#7ec8ff"),this.coreGroup=new O,this.onResize=()=>{const a=this.renderer.domElement.parentElement;if(!a)return;const l=Math.max(1,a.clientWidth),c=Math.max(1,a.clientHeight);this.camera.aspect=l/c,this.camera.updateProjectionMatrix(),this.renderer.setSize(l,c),this.composer.setSize(l,c)},this.renderer=new $({antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.renderer.setSize(e.clientWidth,e.clientHeight),this.renderer.setClearColor(263435),this.renderer.outputColorSpace=_,this.renderer.toneMapping=Y,this.renderer.toneMappingExposure=1.08,e.appendChild(this.renderer.domElement),this.scene=new X;const t=Math.max(1,e.clientWidth),s=Math.max(1,e.clientHeight);this.camera=new Z(44,t/s,1,3e3),this.camera.position.set(0,60,164),this.controls=new J(this.camera,this.renderer.domElement),this.controls.enableDamping=!0,this.controls.dampingFactor=.06,this.controls.autoRotate=!0,this.controls.autoRotateSpeed=.18,this.controls.target.set(0,18,0),this.controls.minDistance=58,this.controls.maxDistance=320,this.background=new K,this.scene.add(this.background.group),this.scene.add(new Q(13424639,1.2));const n=new B(16777215,.75);n.position.set(90,120,100),this.scene.add(n);const i=new B(8959999,.42);i.position.set(-100,40,-80),this.scene.add(i),this.coreShell=new N(new W(6.4,1),new ee({color:new x("#0b1120"),emissive:this.accent.clone().multiplyScalar(.28),emissiveIntensity:1,specular:new x("#ffffff"),shininess:90,transparent:!0,opacity:.94})),this.coreRing=new N(new q(11.5,.18,12,80),new T({color:this.accent,transparent:!0,opacity:.24})),this.coreRing.rotation.x=Math.PI*.5,this.coreOuterRing=new N(new q(16.5,.12,12,96),new T({color:this.accent.clone().lerp(new x("#ffffff"),.2),transparent:!0,opacity:.12})),this.coreOuterRing.rotation.set(Math.PI*.5,.24,0),this.coreLight=new te(this.accent.getHex(),18,260,2),this.coreGroup.add(this.coreShell,this.coreRing,this.coreOuterRing,this.coreLight),this.coreGroup.position.set(0,12,0),this.scene.add(this.coreGroup),this.scene.add(this.visualGroup),this.composer=new se(this.renderer),this.composer.addPass(new ne(this.scene,this.camera)),this.composer.addPass(new ie(new oe(t,s),.48,.24,.4)),this.resizeObserver=new ResizeObserver(this.onResize),this.resizeObserver.observe(e),window.addEventListener("resize",this.onResize),this.onResize()}setVariation(e){this.clearVisual(),this.applyAccent(e.accent),this.currentVisual=e.build(this.visualGroup,this.camera),this.triggerPulse()}triggerPulse(){var e;this.coreActivity=1,(e=this.currentVisual)==null||e.pulse()}tick(){var t;const e=Math.min(this.clock.getDelta(),.05);this.elapsed+=e,this.pulseTimer+=e,this.coreActivity=Math.max(0,this.coreActivity-e*.62),this.pulseTimer>=this.pulseInterval&&(this.pulseTimer=0,this.pulseInterval=2.3+Math.random()*1.5,this.triggerPulse()),this.controls.update(),this.background.tick(e),(t=this.currentVisual)==null||t.tick(e,this.elapsed),this.tickCore();try{this.composer.render()}catch{}}destroy(){this.resizeObserver.disconnect(),window.removeEventListener("resize",this.onResize),this.clearVisual(),this.background.dispose(),this.controls.dispose(),this.renderer.dispose(),this.renderer.domElement.remove(),this.coreShell.geometry.dispose(),this.coreShell.material.dispose(),this.coreRing.geometry.dispose(),this.coreRing.material.dispose(),this.coreOuterRing.geometry.dispose(),this.coreOuterRing.material.dispose()}applyAccent(e){this.accent.set(e);const t=this.coreShell.material,s=this.coreRing.material,n=this.coreOuterRing.material;t.emissive.copy(this.accent).multiplyScalar(.28),s.color.copy(this.accent),n.color.copy(this.accent).lerp(new x("#ffffff"),.2),this.coreLight.color.copy(this.accent)}tickCore(){const e=1+Math.sin(this.elapsed*.7)*.03,t=1+this.coreActivity*.18,s=this.coreShell.material,n=this.coreRing.material,i=this.coreOuterRing.material;this.coreShell.rotation.y+=.0024,this.coreShell.rotation.x=Math.sin(this.elapsed*.18)*.08,this.coreShell.scale.setScalar(e*t),this.coreRing.rotation.z+=.003+this.coreActivity*.01,this.coreRing.scale.setScalar(1+this.coreActivity*.1),this.coreOuterRing.rotation.y-=.0022,this.coreOuterRing.rotation.z=Math.sin(this.elapsed*.42)*.18,this.coreOuterRing.scale.setScalar(1+this.coreActivity*.16),s.emissiveIntensity=.96+this.coreActivity*.36,n.opacity=.18+this.coreActivity*.14,i.opacity=.08+this.coreActivity*.1,this.coreLight.intensity=14+this.coreActivity*12+Math.sin(this.elapsed*.55)*2}clearVisual(){this.currentVisual&&(this.currentVisual.dispose(),this.currentVisual=null)}}const d=new p(0,12,0),ge=new p(0,1,0),P=new x("#ffffff"),me=new x("#121a2d"),b=new he,f=new p,L=new p,I=new p,M=new x;function fe(o){return o-Math.floor(o)}function g(o){return fe(Math.sin(o*127.1+311.7)*43758.5453123)}function y(o){return g(o)*2-1}function H(o,e){const t=Math.atan2(Math.sin(o-e),Math.cos(o-e));return Math.abs(t)}function D(o,e,t=0,s=Math.PI*2){const n=[],i=o>1?s/(o-1):0,a=t-s*.5;for(let l=0;l<o;l++){const c=s>=Math.PI*2?t+l/o*Math.PI*2:a+i*l;n.push(new p(Math.cos(c),e,Math.sin(c)).normalize())}return n}function A(o,e,t,s=1){const n=o.clone().sub(d);return n.lengthSq()<1e-4?n.set(0,1,0):n.normalize(),{home:o.clone(),position:o.clone(),normal:n,state:"dormant",energy:0,carrierNode:null,meta:e,phase:g(t*3+1)*Math.PI*2,driftAmplitude:s*(.45+g(t*3+2)*.55),driftFrequency:.6+g(t*3+3)*.8}}function S(o,e,t){const s=[];for(let n=0;n<o.length;n++){const i=o[n];i.state==="dormant"&&s.push({index:n,score:t(i)})}return s.sort((n,i)=>n.score-i.score),s.slice(0,e).map(n=>n.index)}function v(o,e){return S(o,e,t=>t.home.distanceToSquared(d))}function ye(){const o=[];for(let e=0;e<84;e++){const t=g(e*13+1)*Math.PI*2,s=16+g(e*13+2)*18,n=.7+g(e*13+3)*.35,i=Math.cos(t)*s*n,a=6+Math.pow(g(e*13+4),.72)*22,l=Math.sin(t)*s*n;o.push(A(new p(d.x+i,d.y+a,d.z+l),{angle:t},e,1))}return o}function be(){const o=[];for(let e=0;e<76;e++){const t=-1+e/75*2+y(e*17+1)*.04,s=14+g(e*17+2)*26,n=t*38,i=6+(1-Math.abs(t)*.7)*14+y(e*17+3)*5,a=y(e*17+4)*(4+s*.12);o.push(A(new p(d.x+n,d.y+i,d.z+a),{sweep:t},e+100,.85))}return o}function xe(){const o=[];for(let e=0;e<82;e++){const t=e%2,s=t===0?-26:26,n=t===0?-7:7,i=s+y(e*19+1)*14,a=7+g(e*19+2)*20,l=n+y(e*19+3)*12;o.push(A(new p(d.x+i,d.y+a,d.z+l),{lobe:t},e+200,.95))}return o}function we(){const o=[];for(let e=0;e<88;e++){const t=e/88*Math.PI*2+y(e*23+1)*.08,s=28+y(e*23+2)*4.8,n=Math.cos(t)*s,i=10+Math.sin(t*2.2)*4+y(e*23+3)*2.4,a=Math.sin(t)*s;o.push(A(new p(d.x+n,d.y+i,d.z+a),{angle:t},e+300,.9))}return o}function Me(){const o=[];for(let t=0;t<80;t++){const s=t%4,n=g(t*29+1)*Math.PI*2,i=8+s*3.8+g(t*29+2)*6,a=Math.cos(n)*i,l=6+s*8.5+y(t*29+3)*2.4,c=Math.sin(n)*i*.82;o.push(A(new p(d.x+a,d.y+l,d.z+c),{angle:n,layer:s},t+400,1.05))}return o}function Se(o,e){const t=g(e*31+1)*Math.PI*2,s=18+g(e*31+2)*10,n=10+g(e*31+3)*18;I.set(d.x+Math.cos(t)*s,d.y+n,d.z+Math.sin(t)*s);const i=S(o,12,a=>a.home.distanceToSquared(I));return i.length?i:v(o,12)}function ve(o,e){const t=-1+e%7/6*2,s=S(o,11,n=>Math.abs((n.meta.sweep??0)-t)*100+Math.abs(n.home.y-(d.y+16)));return s.length?s:v(o,11)}function Pe(o,e){const t=e%2;I.set(d.x+(t===0?-28:28)+y(e*37+1)*6,d.y+10+g(e*37+2)*18,d.z+(t===0?-7:7)+y(e*37+3)*4);const s=S(o,12,n=>((n.meta.lobe??-1)===t?0:1e4)+n.home.distanceToSquared(I));return s.length?s:v(o,12)}function Re(o,e){const t=e*.72,s=S(o,14,n=>H(n.meta.angle??0,t)*180);return s.length?s:v(o,14)}function Ae(o,e){const t=e%4,s=g(e*41+1)*Math.PI*2,n=S(o,10,i=>{const a=(i.meta.layer??-1)===t?0:1e4,l=H(i.meta.angle??0,s)*90;return a+l});return n.length?n:v(o,10)}class ke{constructor(e,t){this.blueprint=t,this.group=new O,this.branchGeometry=new re(1,1,1,6,1,!0),this.branchMaterial=new T({transparent:!0,opacity:.88,depthWrite:!1,blending:j}),this.nodeGeometry=new W(1,1),this.nodeMaterial=new T({transparent:!0,opacity:.96,depthWrite:!1,blending:j}),this.nodes=[],this.segments=[],this.segmentIndexByNode=[],this.pulses=[],this.pulseIndex=0,this.activity=0,this.pendingSteps=0,this.stepAccumulator=0,this.completionDelay=0,this.pulse=()=>{(!this.hasDormantAttractors()&&!this.hasArmedAttractors()||this.segments.length>=this.blueprint.maxSegments-this.blueprint.maxNewPerStep)&&this.reset();const a=this.blueprint.selectTargets(this.attractors,this.pulseIndex).filter(c=>{var r;return((r=this.attractors[c])==null?void 0:r.state)==="dormant"}),l=a.length?a:v(this.attractors,8);for(const c of l){const r=this.attractors[c];r.state==="dormant"&&(r.state="armed",r.energy=1.2)}this.pendingSteps=Math.min(this.pendingSteps+this.blueprint.stepsPerPulse,this.blueprint.stepsPerPulse*4),this.activity=1,this.completionDelay=0,this.pulseIndex+=1,this.spawnPulseBursts(Math.min(3,1+Math.floor(l.length/4)))},this.tick=(a,l)=>{this.activity=Math.max(0,this.activity-a*.46),this.updateAttractors(l,a),this.advanceGrowth(a),this.updatePulses(a,l),this.updateBranchInstances(),this.updateNodeInstances(l),!this.hasDormantAttractors()&&!this.hasArmedAttractors()?(this.completionDelay+=a,this.completionDelay>2.6&&(this.reset(),this.pulse())):this.completionDelay=0},this.dispose=()=>{this.clearPulses(),this.group.removeFromParent(),this.branchGeometry.dispose(),this.branchMaterial.dispose(),this.nodeGeometry.dispose(),this.nodeMaterial.dispose(),this.glowTexture.dispose()},this.accentColor=new x(t.accent),this.branchBaseColor=this.accentColor.clone().lerp(P,.14),this.dormantColor=this.accentColor.clone().lerp(me,.78);const[s,n,i]=ae(t.accent);this.glowTexture=ce(s,n,i,96),this.branchMesh=new G(this.branchGeometry,this.branchMaterial,t.maxSegments),this.branchMesh.instanceMatrix.setUsage(E),this.branchMesh.frustumCulled=!1,this.branchMesh.count=0,this.attractors=t.createAttractors(),this.nodeMesh=new G(this.nodeGeometry,this.nodeMaterial,this.attractors.length),this.nodeMesh.instanceMatrix.setUsage(E),this.nodeMesh.frustumCulled=!1,this.group.add(this.branchMesh,this.nodeMesh),e.add(this.group),this.reset()}reset(){this.clearPulses(),this.nodes=[],this.segments=[],this.segmentIndexByNode=[],this.activity=0,this.pendingSteps=0,this.stepAccumulator=0,this.completionDelay=0,this.pulseIndex=0;for(const e of this.attractors)e.position.copy(e.home),e.state="dormant",e.energy=0,e.carrierNode=null;this.nodes.push({position:d.clone(),parent:null,depth:0,radius:this.blueprint.rootRadius}),this.segmentIndexByNode[0]=-1;for(const e of this.blueprint.seedDirections){f.copy(e).normalize();const t=this.blueprint.stepLength*1.05,s=d.clone().addScaledVector(f,t);this.addNode(0,s,1)}this.updateBranchInstances(),this.updateNodeInstances(0)}updateAttractors(e,t){for(const s of this.attractors){s.energy=Math.max(0,s.energy-t*.72);const n=s.state==="captured"?.18:s.state==="armed"?.42:.1,i=Math.sin(e*s.driftFrequency+s.phase)*s.driftAmplitude*this.blueprint.drift*(n+s.energy*.3);s.position.copy(s.home).addScaledVector(s.normal,i)}}advanceGrowth(e){const s=this.hasArmedAttractors()?3.2:0,n=this.pendingSteps>0?18:s;if(!(n<=0))for(this.stepAccumulator+=e*n;this.stepAccumulator>=1;){this.stepAccumulator-=1;const i=this.growOneStep();if(this.pendingSteps>0&&(this.pendingSteps-=1),!i){this.pendingSteps=0,this.stepAccumulator=0;break}}}growOneStep(){const e=this.blueprint.influenceDistance*this.blueprint.influenceDistance,t=this.blueprint.killDistance*this.blueprint.killDistance,s=new Map,n=new Map;for(const c of this.attractors){if(c.state!=="armed")continue;let r=-1,u=e;for(let z=0;z<this.nodes.length;z++){const V=this.nodes[z].position.distanceToSquared(c.position);V<u&&(u=V,r=z)}if(r<0)continue;const m=this.nodes[r];if(f.copy(c.position).sub(m.position),f.lengthSq()<1e-4)continue;f.normalize();let k=s.get(r);k||(k=new p,s.set(r,k)),k.add(f),n.set(r,(n.get(r)??0)+1)}if(!s.size)return!1;const i=[...s.keys()].sort((c,r)=>(n.get(r)??0)-(n.get(c)??0)),a=[];for(const c of i.slice(0,this.blueprint.maxNewPerStep)){if(this.segments.length>=this.blueprint.maxSegments)break;const r=this.nodes[c],u=s.get(c);if(!u||(f.copy(u).add(this.blueprint.bias),f.lengthSq()<1e-4)||(f.normalize(),L.copy(r.position).addScaledVector(f,this.blueprint.stepLength),!this.isPositionAvailable(L)))continue;const m=this.addNode(c,L,r.depth+1);a.push(m)}if(!a.length)return!1;const l=[];for(const c of this.attractors)if(c.state==="armed"){for(const r of a)if(!(this.nodes[r].position.distanceToSquared(c.position)>t)){c.state="captured",c.energy=1.35,c.carrierNode=r,l.push(r);break}}return l.length&&this.spawnPulseTo(l[l.length-1]),!0}isPositionAvailable(e){const t=this.blueprint.stepLength*.58*(this.blueprint.stepLength*.58);for(const s of this.nodes)if(s.position.distanceToSquared(e)<t)return!1;return!0}addNode(e,t,s){const n=this.nodes[e],i=this.nodes.length,a=Math.max(this.blueprint.tipRadius,n.radius*.9);return this.nodes.push({position:t.clone(),parent:e,depth:s,radius:a}),this.segments.push({startNode:e,endNode:i,radius:Math.max(this.blueprint.tipRadius,a*.92),glow:1.18}),this.segmentIndexByNode[i]=this.segments.length-1,i}updatePulses(e,t){for(const s of this.segments)s.glow=Math.max(0,s.glow-e*.82);for(let s=this.pulses.length-1;s>=0;s--){const n=this.pulses[s];if(n.distance+=e*n.speed,n.distance>=n.totalDistance){this.removePulse(s);continue}let i=0;for(;i<n.distances.length-1&&n.distances[i+1]<n.distance;)i+=1;const a=n.distances[i],l=n.distances[i+1],c=le.clamp((n.distance-a)/Math.max(1e-4,l-a),0,1),r=this.nodes[n.path[i]],u=this.nodes[n.path[i+1]];n.sprite.position.lerpVectors(r.position,u.position,c),n.sprite.scale.setScalar(2.2+Math.sin(t*8+i)*.25+this.activity*.4),n.material.opacity=.8+this.activity*.18;const m=this.segmentIndexByNode[n.path[i+1]];m>=0&&(this.segments[m].glow=Math.max(this.segments[m].glow,1.25))}}updateBranchInstances(){this.branchMesh.count=this.segments.length;for(let e=0;e<this.segments.length;e++){const t=this.segments[e],s=this.nodes[t.startNode].position,n=this.nodes[t.endNode].position;f.copy(n).sub(s);const i=f.length();if(i<1e-4)continue;f.normalize(),b.position.copy(s).lerp(n,.5),b.quaternion.setFromUnitVectors(ge,f);const a=t.radius*(1+t.glow*.3);b.scale.set(a,i,a),b.updateMatrix(),this.branchMesh.setMatrixAt(e,b.matrix),M.copy(this.branchBaseColor).lerp(P,.08+Math.min(t.glow,1.4)*.34),this.branchMesh.setColorAt(e,M)}this.branchMesh.instanceMatrix.needsUpdate=!0,this.branchMesh.instanceColor&&(this.branchMesh.instanceColor.needsUpdate=!0)}updateNodeInstances(e){for(let t=0;t<this.attractors.length;t++){const s=this.attractors[t],n=s.state==="captured"?1.12:s.state==="armed"?.96:.72,i=1+s.energy*.4+Math.sin(e*s.driftFrequency+s.phase)*.04,a=this.blueprint.nodeScale*n*i;b.position.copy(s.position),b.quaternion.identity(),b.scale.setScalar(a),b.updateMatrix(),this.nodeMesh.setMatrixAt(t,b.matrix),s.state==="captured"?M.copy(this.accentColor).lerp(P,.32+s.energy*.14):s.state==="armed"?M.copy(this.accentColor).lerp(P,.16+s.energy*.1):M.copy(this.dormantColor).lerp(this.accentColor,.08),this.nodeMesh.setColorAt(t,M)}this.nodeMesh.instanceMatrix.needsUpdate=!0,this.nodeMesh.instanceColor&&(this.nodeMesh.instanceColor.needsUpdate=!0)}spawnPulseBursts(e){const t=this.attractors.filter(s=>s.state==="captured"&&s.carrierNode!==null);if(t.length)for(let s=0;s<e;s++){const n=t[Math.floor(Math.random()*t.length)];n.carrierNode!==null&&this.spawnPulseTo(n.carrierNode)}}spawnPulseTo(e){if(e<=0||this.pulses.length>=8)return;const t=[];let s=e;for(;s!==null;)t.unshift(s),s=this.nodes[s].parent;if(t.length<2)return;const n=[0];let i=0;for(let c=1;c<t.length;c++){const r=this.nodes[t[c-1]].position,u=this.nodes[t[c]].position;i+=r.distanceTo(u),n.push(i)}const a=new de({map:this.glowTexture,color:P,transparent:!0,opacity:.92,depthWrite:!1,blending:j}),l=new pe(a);l.frustumCulled=!1,l.position.copy(this.nodes[t[0]].position),l.scale.setScalar(2.4),this.group.add(l),this.pulses.push({path:t,distances:n,totalDistance:i,distance:0,speed:24+Math.random()*10,sprite:l,material:a})}removePulse(e){const t=this.pulses[e];t&&(t.sprite.removeFromParent(),t.material.dispose(),this.pulses.splice(e,1))}clearPulses(){for(let e=this.pulses.length-1;e>=0;e--)this.removePulse(e)}hasDormantAttractors(){return this.attractors.some(e=>e.state==="dormant")}hasArmedAttractors(){return this.attractors.some(e=>e.state==="armed")}}function R(o){return{name:o.name,accent:o.accent,layout:o.layout,eventModel:o.eventModel,useCase:o.useCase,description:o.description,build(e){return new ke(e,o)}}}const C=[R({name:"Pocket Canopy",accent:"#7ec8ff",layout:"dome cluster",eventModel:"arm a local neighborhood per event",useCase:"compact session burst around a selected cluster",description:"Closest to the live-node use case: each event wakes a nearby pocket of nodes, and the scaffold grows the smallest readable canopy that still feels organic.",influenceDistance:24,killDistance:4.8,stepLength:3.3,stepsPerPulse:12,maxNewPerStep:5,maxSegments:320,rootRadius:1.18,tipRadius:.22,nodeScale:.92,drift:1.05,bias:new p(0,.18,0),seedDirections:D(5,.9,.15),createAttractors:ye,selectTargets:Se}),R({name:"Ribbon Fan",accent:"#67ddff",layout:"flattened 2.5D fan",eventModel:"events paint narrow sweep bands",useCase:"sidebar card, minimap, or inspector-scale activity view",description:"Same SCA core, but flattened into a shallow fan so you get branching legibility without spending much screen depth.",influenceDistance:22,killDistance:4.4,stepLength:3.2,stepsPerPulse:11,maxNewPerStep:4,maxSegments:280,rootRadius:1.08,tipRadius:.2,nodeScale:.84,drift:.82,bias:new p(0,.1,0),seedDirections:D(5,.55,0,Math.PI*1.05),createAttractors:be,selectTargets:ve}),R({name:"Split Relay",accent:"#a9a0ff",layout:"dual semantic lobes",eventModel:"alternate between left and right node groups",useCase:"tool-vs-agent, request-vs-response, or two-channel routing",description:"Useful when your node field already has two semantic camps. Each event pulls the scaffold into one side, so the branching itself explains the grouping.",influenceDistance:25,killDistance:4.7,stepLength:3.4,stepsPerPulse:12,maxNewPerStep:5,maxSegments:320,rootRadius:1.14,tipRadius:.22,nodeScale:.88,drift:.95,bias:new p(0,.14,0),seedDirections:D(6,.5,Math.PI*.2),createAttractors:xe,selectTargets:Pe}),R({name:"Halo Wreath",accent:"#7cf3e2",layout:"orbital ring",eventModel:"wake a moving arc around a focus target",useCase:"selection halo, focus ring, or surround-state animation",description:"A good fit when the animation should stay compact around one node or cluster. Events wake only one arc, so the ring reads like intent instead of noise.",influenceDistance:27,killDistance:4.5,stepLength:3.25,stepsPerPulse:13,maxNewPerStep:5,maxSegments:340,rootRadius:1.12,tipRadius:.2,nodeScale:.86,drift:.9,bias:new p(0,.04,0),seedDirections:D(7,.22),createAttractors:we,selectTargets:Re}),R({name:"Signal Stack",accent:"#ffb48e",layout:"layered vertical tiers",eventModel:"events climb through stacked bands",useCase:"compact timeline or event ladder with branching memory",description:"This keeps the same attractor logic but turns it into a vertical meter. The result reads more like a time stack than a cloud, while still branching naturally.",influenceDistance:21,killDistance:4.2,stepLength:3.15,stepsPerPulse:10,maxNewPerStep:4,maxSegments:280,rootRadius:1.12,tipRadius:.2,nodeScale:.82,drift:1.08,bias:new p(0,.26,0),seedDirections:[new p(0,1,0).normalize(),new p(.28,.96,.08).normalize(),new p(-.28,.96,-.08).normalize(),new p(.18,.92,-.22).normalize()],createAttractors:Me,selectTargets:Ae})];function F(){return window.innerWidth<920}function Ce(){const o=w.useRef(null),e=w.useRef(null),t=w.useRef(0),[s,n]=w.useState(0),[i,a]=w.useState(()=>F());w.useEffect(()=>{const r=()=>a(F());return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[]),w.useEffect(()=>{if(!o.current)return;const r=new ue(o.current);e.current=r,r.setVariation(C[0]);function u(){r.tick(),t.current=requestAnimationFrame(u)}return t.current=requestAnimationFrame(u),()=>{cancelAnimationFrame(t.current),r.destroy(),e.current=null}},[]);function l(r){var u;n(r),(u=e.current)==null||u.setVariation(C[r])}const c=C[s];return h.jsxs("div",{style:{width:"100vw",height:"100vh",background:"#04050b",position:"relative",overflow:"hidden"},children:[h.jsx("div",{ref:o,style:{position:"absolute",inset:0}}),h.jsxs("div",{style:{position:"absolute",top:i?"auto":0,right:0,bottom:0,width:i?"100%":392,height:i?"48vh":"100%",maxHeight:i?420:"100%",background:"linear-gradient(180deg, rgba(6,8,18,0.97) 0%, rgba(5,7,16,0.9) 100%)",borderLeft:i?"none":"1px solid rgba(255,255,255,0.07)",borderTop:i?"1px solid rgba(255,255,255,0.07)":"none",display:"flex",flexDirection:"column",fontFamily:"'Inter', 'SF Pro Display', system-ui, sans-serif",color:"#c8d1df",overflowY:"auto",backdropFilter:"blur(20px)"},children:[h.jsxs("div",{style:{padding:"20px 20px 16px",borderBottom:"1px solid rgba(255,255,255,0.06)",background:`linear-gradient(180deg, ${c.accent}18 0%, rgba(255,255,255,0) 100%)`},children:[h.jsx("div",{style:{fontSize:10,letterSpacing:"0.18em",color:"#6f7b90",textTransform:"uppercase",marginBottom:8},children:"Space Colonization Lab"}),h.jsx("div",{style:{fontSize:22,fontWeight:680,letterSpacing:"-0.03em",color:"#eef4ff"},children:"5 compact event-animation mappings"}),h.jsx("div",{style:{fontSize:12,lineHeight:1.65,color:"#96a4bc",marginTop:10},children:"Treat nodes as attractors. Each event arms a small pocket of them, the scaffold grows from the core, and pulses travel back through the new branch path."}),h.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",marginTop:14},children:[h.jsx("span",{style:{padding:"4px 8px",borderRadius:999,fontSize:10,letterSpacing:"0.08em",textTransform:"uppercase",color:c.accent,border:`1px solid ${c.accent}44`,background:`${c.accent}16`},children:c.layout}),h.jsx("span",{style:{fontSize:11,color:"#7f8ca4",alignSelf:"center"},children:c.eventModel})]})]}),h.jsx("div",{style:{padding:"14px 14px 8px",display:"flex",flexDirection:"column",gap:10,flex:1},children:C.map((r,u)=>{const m=u===s;return h.jsxs("button",{onClick:()=>l(u),style:{textAlign:"left",borderRadius:12,border:`1px solid ${m?r.accent:"rgba(255,255,255,0.07)"}`,background:m?`linear-gradient(135deg, ${r.accent}18 0%, rgba(255,255,255,0.03) 100%)`:"rgba(255,255,255,0.025)",padding:"14px 15px",color:"inherit",cursor:"pointer",transition:"border-color 0.2s ease, background 0.2s ease"},children:[h.jsx("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12},children:h.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:10},children:[h.jsx("div",{style:{width:28,height:28,borderRadius:8,display:"grid",placeItems:"center",fontSize:12,fontWeight:700,color:m?r.accent:"#7d889d",background:m?`${r.accent}18`:"rgba(255,255,255,0.03)",border:`1px solid ${m?`${r.accent}33`:"rgba(255,255,255,0.06)"}`,flexShrink:0},children:u+1}),h.jsxs("div",{children:[h.jsx("div",{style:{fontSize:14,fontWeight:650,color:m?"#eff4ff":"#cbd5e5"},children:r.name}),h.jsx("div",{style:{fontSize:10,letterSpacing:"0.08em",textTransform:"uppercase",color:m?r.accent:"#6d7890",marginTop:4},children:r.useCase})]})]})}),h.jsx("div",{style:{fontSize:11,color:"#7f8aa0",lineHeight:1.55,marginTop:10},children:r.description})]},r.name)})}),h.jsxs("div",{style:{padding:"14px 18px 16px",borderTop:"1px solid rgba(255,255,255,0.06)"},children:[h.jsx("button",{onClick:()=>{var r;return(r=e.current)==null?void 0:r.triggerPulse()},style:{width:"100%",padding:"11px 0",borderRadius:10,border:`1px solid ${c.accent}44`,background:`linear-gradient(135deg, ${c.accent}22 0%, rgba(255,255,255,0.03) 100%)`,color:"#eef4ff",fontSize:12,fontWeight:650,letterSpacing:"0.08em",textTransform:"uppercase",cursor:"pointer"},children:"Trigger event pulse"}),h.jsxs("div",{style:{display:"grid",gap:6,marginTop:12},children:[h.jsxs("div",{style:{fontSize:10,color:"#5f6980",lineHeight:1.5},children:["Drag to orbit, scroll to zoom. Route: ",h.jsx("code",{children:"#/colonization-demo"})]}),h.jsx("div",{style:{fontSize:10,color:"#5f6980",lineHeight:1.5},children:"Suggested product mapping: keep the node field fixed, arm only event-relevant attractors, and let the scaffold persist as a compact memory of recent flow."})]})]})]}),h.jsx("a",{href:"#/three",style:{position:"absolute",top:16,left:16,padding:"7px 12px",borderRadius:999,border:"1px solid rgba(255,255,255,0.08)",background:"rgba(8,10,18,0.55)",color:"#a8b3c8",textDecoration:"none",fontFamily:"'Inter', system-ui, sans-serif",fontSize:11,letterSpacing:"0.04em",backdropFilter:"blur(12px)"},children:"← back to live view"})]})}export{Ce as ColonizationDemoScene};
@@ -1,4 +1,4 @@
1
- import{C as K,G as L,W as X,S as Y,P as J,O as Q,B as Z,E as ee,R as te,U as oe,V as ae,L as W,a as u,b as H,M as F,A as M,c as S,d as B,e as re,D as ne,T as ie,f as U,g as N,h as E,i as z,j as se,s as le,k as R,r as _,l as g}from"./index-D3vltDuF.js";const j=new Map;let $=U;function ce(r,t){j.set(r,t),$=(o,i,s)=>{const d=j.get(o);return d?d(i,s):U(o,i,s)}}class ue{constructor(t){this.clock=new K,this.nodeGroup=new L,this.currentNode=null,this.respawnTimer=0,this.currentVariation=null,this.axisGroup=new L,this._onResize=()=>{const i=this.renderer.domElement.parentElement;if(!i)return;const s=i.clientWidth,d=i.clientHeight;this.camera.aspect=s/d,this.camera.updateProjectionMatrix(),this.renderer.setSize(s,d),this.composer.setSize(s,d)},this.renderer=new X({antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.setClearColor(197384),t.appendChild(this.renderer.domElement),this.scene=new Y,this.camera=new J(55,t.clientWidth/t.clientHeight,1,2e3),this.camera.position.set(0,60,200),this.controls=new Q(this.camera,this.renderer.domElement),this.controls.enableDamping=!0,this.controls.dampingFactor=.06,this.controls.autoRotate=!1,this.controls.target.set(-40,5,-15),this.controls.minDistance=50,this.controls.maxDistance=600,this.background=new Z,this.scene.add(this.background.group),this.scene.add(this.nodeGroup),this.scene.add(this.axisGroup),this._buildAxis(),this._buildCoreGlow(),this.composer=new ee(this.renderer),this.composer.addPass(new te(this.scene,this.camera));const o=new oe(new ae(t.clientWidth,t.clientHeight),.7,.4,.75);this.composer.addPass(o),window.addEventListener("resize",this._onResize),this._onResize()}_buildAxis(){const t=new W({color:2236996,transparent:!0,opacity:.4}),o=(i,s)=>{const d=new N().setFromPoints([i,s]);return new E(d,t)};this.axisGroup.add(o(new u(-120,0,0),new u(20,0,0))),this.axisGroup.add(o(new u(0,-20,0),new u(0,30,0))),this.axisGroup.add(o(new u(0,0,-60),new u(0,0,20)))}_buildCoreGlow(){const t=new H(3,16,16),o=new F({color:new S("#22ff88"),transparent:!0,opacity:.15,blending:M});this.scene.add(new B(t,o));const i=new re(5,6,32),s=new F({color:new S("#4ade80"),transparent:!0,opacity:.2,blending:M,side:ne});this.scene.add(new B(i,s));const d=new u(-80,10,-30),v=new H(2,12,12),h=new F({color:new S("#4ade80"),transparent:!0,opacity:.3,blending:M}),m=new B(v,h);m.position.copy(d),this.scene.add(m)}setVariation(t){if(this.currentVariation=t,t.buildCustomEffect){const o=t.spawnParams()._tool??"";ce(o,t.buildCustomEffect)}this._clearNode(),this._spawnNode()}_clearNode(){this.currentNode&&(this.nodeGroup.remove(this.currentNode.group),this.currentNode.dispose(),this.currentNode=null)}_spawnNode(){if(!this.currentVariation)return;const t=this.currentVariation.spawnParams(this.camera.position),o=new ie(t,$);this.nodeGroup.add(o.group),this.currentNode=o,this.respawnTimer=0}tick(){const t=Math.min(this.clock.getDelta(),.05);this.controls.update(),this.background.tick(t),this.currentNode?(this.currentNode.tick(t),this.currentNode.done&&(this._clearNode(),this.respawnTimer=0)):(this.respawnTimer+=t,this.respawnTimer>1&&this.currentVariation&&this._spawnNode()),this.composer.render()}destroy(){window.removeEventListener("resize",this._onResize),this.renderer.dispose(),this._clearNode(),j.clear()}}const q=new u(0,0,0);function x(r,t){return Math.random()*(t-r)+r}function de(){return{origin:new u(-120,15,-60),target:q.clone().add(new u(x(-2,2),x(-2,2),x(-2,2))),color:new S("#b0c8f0"),colorEnd:new S("#ffffff"),travelTime:3,trailLength:0,trailBrightness:0,trailFadeTime:4,headSize:0,pathConfig:{type:"linear",easing:"easeInCubic"},_tool:"prompt:custom"}}function pe(){const r=Math.random()*Math.PI*2,t=Math.acos(x(-1,1)),o=x(250,400);return new u(Math.sin(t)*Math.cos(r)*o,Math.sin(t)*Math.sin(r)*o,Math.cos(t)*o)}function O(r){const t=de();t._tool=r,t.origin=pe(),t.travelTime=x(4,5.5),t.trailFadeTime=1.8;const o=t.origin.clone().add(q).multiplyScalar(.5);return t.pathConfig={type:"quadratic",easing:"easeInOut",c1:new u(o.x+x(-40,40),o.y+x(20,60),o.z+x(-30,30))},t}function he(r,t){return{f1:1.2+Math.random()*1.5,f2:3.5+Math.random()*3,ph1:Math.random()*Math.PI*2,ph2:Math.random()*Math.PI*2,amp:4+Math.random()*6,perp:new u(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),scatter:new u((Math.random()-.5)*400,(Math.random()-.5)*400,(Math.random()-.5)*400),windowStart:-(r/t)*3.5-Math.random()*.2,rollSpeed:.8+Math.random()*.6}}function fe(r,t,o,i,s){const d=se(t.pathConfig.easing,o),v=le(t.pathConfig,t.origin,t.target,d),h=Math.max(0,1-o/.5),m=Math.min(1,o/.5),l=1-Math.pow(o,8),e=(Math.sin(o*r.f1*Math.PI*2+r.ph1+i*s)*r.amp+Math.sin(o*r.f2*Math.PI*2+r.ph2+i*s*1.4)*r.amp*.3)*m*l;return new u(v.x+r.scatter.x*h+r.perp.x*e,v.y+r.scatter.y*h+r.perp.y*e,v.z+r.scatter.z*h+r.perp.z*e)}function P(r,t,o,i,s){const d=Array.from({length:i},(h,m)=>{const l=he(m,i),e=new Float32Array(o*3),n=new N;n.setAttribute("position",new z(e,3));const c=new Float32Array(o);for(let T=0;T<o;T++)c[T]=T/(o-1);n.setAttribute("aT",new z(c,1));const{mat:a,setOpacity:p,setTime:w}=s(m,n);return r.add(new E(n,a)),{...l,posArr:e,geo:n,mat:a,window:l.windowStart,setOpacity:p,setTime:w}}),v={entries:d.map(h=>({obj:new E(h.geo,h.mat),mat:h.mat,meta:{}})),suppressDefaultTrail:!0,trailTick(h,m,l){var c;const e=2.5+l*.1;let n=!0;for(const a of d){const p=a.window>=1?1/(1.5*a.rollSpeed):(1-a.windowStart)/t.travelTime;a.window=Math.min(2,a.window+m*p);const w=a.window;if(w<=0){a.geo.setDrawRange(0,0),n=!1;continue}if(w>=2){a.setOpacity(0),a.geo.setDrawRange(0,0);continue}n=!1;const T=Math.round(Math.min(1,w)*(o-1)),y=Math.round(Math.max(0,w-1)*(o-1)),A=T-y;if(A<1){a.geo.setDrawRange(0,0);continue}for(let b=y;b<=T;b++){const C=fe(a,t,b/(o-1),l,e);a.posArr[b*3]=C.x,a.posArr[b*3+1]=C.y,a.posArr[b*3+2]=C.z}a.geo.attributes.position.needsUpdate=!0,a.geo.setDrawRange(y,A),a.setOpacity(.7),(c=a.setTime)==null||c.call(a,l)}n&&(v.shouldMarkDone=!0)},tick(){},onLand(){},applyFade(h){},shouldMarkDone:!1};return v}function ge(r,t){return P(r,t,120,8,o=>{const i=new W({color:new S().setHSL(.55+o/8*.15,.9,.6+o%2*.2),transparent:!0,opacity:0,blending:M,depthWrite:!1});return{mat:i,setOpacity:s=>{i.opacity=s}}})}const me=`
1
+ import{C as K,G as L,W as X,S as Y,P as J,O as Q,B as Z,E as ee,R as te,U as oe,V as ae,L as W,a as u,b as H,M as F,A as M,c as S,d as B,e as re,D as ne,T as ie,f as U,g as N,h as E,i as z,j as se,s as le,k as R,r as _,l as g}from"./index-cWLk4rCz.js";const j=new Map;let $=U;function ce(r,t){j.set(r,t),$=(o,i,s)=>{const d=j.get(o);return d?d(i,s):U(o,i,s)}}class ue{constructor(t){this.clock=new K,this.nodeGroup=new L,this.currentNode=null,this.respawnTimer=0,this.currentVariation=null,this.axisGroup=new L,this._onResize=()=>{const i=this.renderer.domElement.parentElement;if(!i)return;const s=i.clientWidth,d=i.clientHeight;this.camera.aspect=s/d,this.camera.updateProjectionMatrix(),this.renderer.setSize(s,d),this.composer.setSize(s,d)},this.renderer=new X({antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.setClearColor(197384),t.appendChild(this.renderer.domElement),this.scene=new Y,this.camera=new J(55,t.clientWidth/t.clientHeight,1,2e3),this.camera.position.set(0,60,200),this.controls=new Q(this.camera,this.renderer.domElement),this.controls.enableDamping=!0,this.controls.dampingFactor=.06,this.controls.autoRotate=!1,this.controls.target.set(-40,5,-15),this.controls.minDistance=50,this.controls.maxDistance=600,this.background=new Z,this.scene.add(this.background.group),this.scene.add(this.nodeGroup),this.scene.add(this.axisGroup),this._buildAxis(),this._buildCoreGlow(),this.composer=new ee(this.renderer),this.composer.addPass(new te(this.scene,this.camera));const o=new oe(new ae(t.clientWidth,t.clientHeight),.7,.4,.75);this.composer.addPass(o),window.addEventListener("resize",this._onResize),this._onResize()}_buildAxis(){const t=new W({color:2236996,transparent:!0,opacity:.4}),o=(i,s)=>{const d=new N().setFromPoints([i,s]);return new E(d,t)};this.axisGroup.add(o(new u(-120,0,0),new u(20,0,0))),this.axisGroup.add(o(new u(0,-20,0),new u(0,30,0))),this.axisGroup.add(o(new u(0,0,-60),new u(0,0,20)))}_buildCoreGlow(){const t=new H(3,16,16),o=new F({color:new S("#22ff88"),transparent:!0,opacity:.15,blending:M});this.scene.add(new B(t,o));const i=new re(5,6,32),s=new F({color:new S("#4ade80"),transparent:!0,opacity:.2,blending:M,side:ne});this.scene.add(new B(i,s));const d=new u(-80,10,-30),v=new H(2,12,12),h=new F({color:new S("#4ade80"),transparent:!0,opacity:.3,blending:M}),m=new B(v,h);m.position.copy(d),this.scene.add(m)}setVariation(t){if(this.currentVariation=t,t.buildCustomEffect){const o=t.spawnParams()._tool??"";ce(o,t.buildCustomEffect)}this._clearNode(),this._spawnNode()}_clearNode(){this.currentNode&&(this.nodeGroup.remove(this.currentNode.group),this.currentNode.dispose(),this.currentNode=null)}_spawnNode(){if(!this.currentVariation)return;const t=this.currentVariation.spawnParams(this.camera.position),o=new ie(t,$);this.nodeGroup.add(o.group),this.currentNode=o,this.respawnTimer=0}tick(){const t=Math.min(this.clock.getDelta(),.05);this.controls.update(),this.background.tick(t),this.currentNode?(this.currentNode.tick(t),this.currentNode.done&&(this._clearNode(),this.respawnTimer=0)):(this.respawnTimer+=t,this.respawnTimer>1&&this.currentVariation&&this._spawnNode()),this.composer.render()}destroy(){window.removeEventListener("resize",this._onResize),this.renderer.dispose(),this._clearNode(),j.clear()}}const q=new u(0,0,0);function x(r,t){return Math.random()*(t-r)+r}function de(){return{origin:new u(-120,15,-60),target:q.clone().add(new u(x(-2,2),x(-2,2),x(-2,2))),color:new S("#b0c8f0"),colorEnd:new S("#ffffff"),travelTime:3,trailLength:0,trailBrightness:0,trailFadeTime:4,headSize:0,pathConfig:{type:"linear",easing:"easeInCubic"},_tool:"prompt:custom"}}function pe(){const r=Math.random()*Math.PI*2,t=Math.acos(x(-1,1)),o=x(250,400);return new u(Math.sin(t)*Math.cos(r)*o,Math.sin(t)*Math.sin(r)*o,Math.cos(t)*o)}function O(r){const t=de();t._tool=r,t.origin=pe(),t.travelTime=x(4,5.5),t.trailFadeTime=1.8;const o=t.origin.clone().add(q).multiplyScalar(.5);return t.pathConfig={type:"quadratic",easing:"easeInOut",c1:new u(o.x+x(-40,40),o.y+x(20,60),o.z+x(-30,30))},t}function he(r,t){return{f1:1.2+Math.random()*1.5,f2:3.5+Math.random()*3,ph1:Math.random()*Math.PI*2,ph2:Math.random()*Math.PI*2,amp:4+Math.random()*6,perp:new u(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),scatter:new u((Math.random()-.5)*400,(Math.random()-.5)*400,(Math.random()-.5)*400),windowStart:-(r/t)*3.5-Math.random()*.2,rollSpeed:.8+Math.random()*.6}}function fe(r,t,o,i,s){const d=se(t.pathConfig.easing,o),v=le(t.pathConfig,t.origin,t.target,d),h=Math.max(0,1-o/.5),m=Math.min(1,o/.5),l=1-Math.pow(o,8),e=(Math.sin(o*r.f1*Math.PI*2+r.ph1+i*s)*r.amp+Math.sin(o*r.f2*Math.PI*2+r.ph2+i*s*1.4)*r.amp*.3)*m*l;return new u(v.x+r.scatter.x*h+r.perp.x*e,v.y+r.scatter.y*h+r.perp.y*e,v.z+r.scatter.z*h+r.perp.z*e)}function P(r,t,o,i,s){const d=Array.from({length:i},(h,m)=>{const l=he(m,i),e=new Float32Array(o*3),n=new N;n.setAttribute("position",new z(e,3));const c=new Float32Array(o);for(let T=0;T<o;T++)c[T]=T/(o-1);n.setAttribute("aT",new z(c,1));const{mat:a,setOpacity:p,setTime:w}=s(m,n);return r.add(new E(n,a)),{...l,posArr:e,geo:n,mat:a,window:l.windowStart,setOpacity:p,setTime:w}}),v={entries:d.map(h=>({obj:new E(h.geo,h.mat),mat:h.mat,meta:{}})),suppressDefaultTrail:!0,trailTick(h,m,l){var c;const e=2.5+l*.1;let n=!0;for(const a of d){const p=a.window>=1?1/(1.5*a.rollSpeed):(1-a.windowStart)/t.travelTime;a.window=Math.min(2,a.window+m*p);const w=a.window;if(w<=0){a.geo.setDrawRange(0,0),n=!1;continue}if(w>=2){a.setOpacity(0),a.geo.setDrawRange(0,0);continue}n=!1;const T=Math.round(Math.min(1,w)*(o-1)),y=Math.round(Math.max(0,w-1)*(o-1)),A=T-y;if(A<1){a.geo.setDrawRange(0,0);continue}for(let b=y;b<=T;b++){const C=fe(a,t,b/(o-1),l,e);a.posArr[b*3]=C.x,a.posArr[b*3+1]=C.y,a.posArr[b*3+2]=C.z}a.geo.attributes.position.needsUpdate=!0,a.geo.setDrawRange(y,A),a.setOpacity(.7),(c=a.setTime)==null||c.call(a,l)}n&&(v.shouldMarkDone=!0)},tick(){},onLand(){},applyFade(h){},shouldMarkDone:!1};return v}function ge(r,t){return P(r,t,120,8,o=>{const i=new W({color:new S().setHSL(.55+o/8*.15,.9,.6+o%2*.2),transparent:!0,opacity:0,blending:M,depthWrite:!1});return{mat:i,setOpacity:s=>{i.opacity=s}}})}const me=`
2
2
  attribute float aT;
3
3
  varying float vT;
4
4
  void main() { vT = aT; gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0); }
@@ -1,4 +1,4 @@
1
- import{m as We,n as Ge,H as Oe,N as Ht,o as Le,p as Ve,q as He,t as qe,k as mt,F as Ze,c as H,u as At,a as w,v as It,w as gt,x as st,g as ct,i as q,d as at,y as Me,z as Ce,D as vt,J as it,K as zt,X as bt,Y as Pe,G as $t,Z as qt,_ as Ot,$ as Xe,a0 as De,a1 as Lt,a2 as Qe,a3 as _e,A as kt,a4 as Te,a5 as ze,I as Ye,L as Ke,h as Je,W as to,a6 as eo,a7 as oo,S as no,a8 as so,P as io,O as ro,E as ao,R as lo,U as co,V as ho,a9 as uo,aa as po,ab as fo,ac as Rt,ad as mo,b as go,ae as vo,M as yo,r as P,l as S}from"./index-D3vltDuF.js";const wt={defines:{DEPTH_PACKING:1,PERSPECTIVE_CAMERA:1},uniforms:{tColor:{value:null},tDepth:{value:null},focus:{value:1},aspect:{value:1},aperture:{value:.025},maxblur:{value:.01},nearClip:{value:1},farClip:{value:1e3}},vertexShader:`
1
+ import{m as Oe,n as Le,H as Ve,N as qt,o as He,p as qe,q as Ze,t as Xe,k as mt,F as Qe,c as H,u as kt,a as w,v as Rt,w as gt,x as st,g as ct,i as q,d as at,y as Pe,z as De,D as vt,J as it,K as At,X as bt,Y as _e,G as Bt,Z as Zt,_ as Lt,$ as Ye,a0 as Te,a1 as Vt,a2 as Ke,a3 as ze,A as It,a4 as Ae,a5 as ke,I as Je,L as to,h as eo,W as oo,a6 as no,a7 as so,S as io,a8 as ro,P as ao,O as lo,E as co,R as ho,U as uo,V as po,a9 as fo,aa as mo,ab as go,ac as Ut,ad as vo,b as yo,ae as xo,M as bo,r as P,l as S,af as wt,ag as wo,ah as Xt,ai as So}from"./index-cWLk4rCz.js";const St={defines:{DEPTH_PACKING:1,PERSPECTIVE_CAMERA:1},uniforms:{tColor:{value:null},tDepth:{value:null},focus:{value:1},aspect:{value:1},aperture:{value:.025},maxblur:{value:.01},nearClip:{value:1},farClip:{value:1e3}},vertexShader:`
2
2
 
3
3
  varying vec2 vUv;
4
4
 
@@ -108,7 +108,7 @@ import{m as We,n as Ge,H as Oe,N as Ht,o as Le,p as Ve,q as He,t as qe,k as mt,F
108
108
  gl_FragColor = col / 41.0;
109
109
  gl_FragColor.a = 1.0;
110
110
 
111
- }`};class xo extends We{constructor(t,e,o){super(),this.scene=t,this.camera=e;const n=o.focus!==void 0?o.focus:1,i=o.aperture!==void 0?o.aperture:.025,a=o.maxblur!==void 0?o.maxblur:1;this._renderTargetDepth=new Ge(1,1,{minFilter:Ht,magFilter:Ht,type:Oe}),this._renderTargetDepth.texture.name="BokehPass.depth",this._materialDepth=new Le,this._materialDepth.depthPacking=Ve,this._materialDepth.blending=He;const l=qe.clone(wt.uniforms);l.tDepth.value=this._renderTargetDepth.texture,l.focus.value=n,l.aspect.value=e.aspect,l.aperture.value=i,l.maxblur.value=a,l.nearClip.value=e.near,l.farClip.value=e.far,this.materialBokeh=new mt({defines:Object.assign({},wt.defines),uniforms:l,vertexShader:wt.vertexShader,fragmentShader:wt.fragmentShader}),this.uniforms=l,this._fsQuad=new Ze(this.materialBokeh),this._oldClearColor=new H}render(t,e,o){this.scene.overrideMaterial=this._materialDepth,t.getClearColor(this._oldClearColor);const n=t.getClearAlpha(),i=t.autoClear;t.autoClear=!1,t.setClearColor(16777215),t.setClearAlpha(1),t.setRenderTarget(this._renderTargetDepth),t.clear(),t.render(this.scene,this.camera),this.uniforms.tColor.value=o.texture,this.uniforms.nearClip.value=this.camera.near,this.uniforms.farClip.value=this.camera.far,this.renderToScreen?(t.setRenderTarget(null),this._fsQuad.render(t)):(t.setRenderTarget(e),t.clear(),this._fsQuad.render(t)),this.scene.overrideMaterial=null,t.setClearColor(this._oldClearColor),t.setClearAlpha(n),t.autoClear=i}setSize(t,e){this.materialBokeh.uniforms.aspect.value=t/e,this._renderTargetDepth.setSize(t,e)}dispose(){this._renderTargetDepth.dispose(),this._materialDepth.dispose(),this.materialBokeh.dispose(),this._fsQuad.dispose()}}const bo={uniforms:{tDiffuse:{value:null},uVignetteStrength:{value:.25},uSaturation:{value:1.12},uWarmth:{value:.06}},vertexShader:`
111
+ }`};class Mo extends Oe{constructor(t,e,o){super(),this.scene=t,this.camera=e;const n=o.focus!==void 0?o.focus:1,i=o.aperture!==void 0?o.aperture:.025,a=o.maxblur!==void 0?o.maxblur:1;this._renderTargetDepth=new Le(1,1,{minFilter:qt,magFilter:qt,type:Ve}),this._renderTargetDepth.texture.name="BokehPass.depth",this._materialDepth=new He,this._materialDepth.depthPacking=qe,this._materialDepth.blending=Ze;const l=Xe.clone(St.uniforms);l.tDepth.value=this._renderTargetDepth.texture,l.focus.value=n,l.aspect.value=e.aspect,l.aperture.value=i,l.maxblur.value=a,l.nearClip.value=e.near,l.farClip.value=e.far,this.materialBokeh=new mt({defines:Object.assign({},St.defines),uniforms:l,vertexShader:St.vertexShader,fragmentShader:St.fragmentShader}),this.uniforms=l,this._fsQuad=new Qe(this.materialBokeh),this._oldClearColor=new H}render(t,e,o){this.scene.overrideMaterial=this._materialDepth,t.getClearColor(this._oldClearColor);const n=t.getClearAlpha(),i=t.autoClear;t.autoClear=!1,t.setClearColor(16777215),t.setClearAlpha(1),t.setRenderTarget(this._renderTargetDepth),t.clear(),t.render(this.scene,this.camera),this.uniforms.tColor.value=o.texture,this.uniforms.nearClip.value=this.camera.near,this.uniforms.farClip.value=this.camera.far,this.renderToScreen?(t.setRenderTarget(null),this._fsQuad.render(t)):(t.setRenderTarget(e),t.clear(),this._fsQuad.render(t)),this.scene.overrideMaterial=null,t.setClearColor(this._oldClearColor),t.setClearAlpha(n),t.autoClear=i}setSize(t,e){this.materialBokeh.uniforms.aspect.value=t/e,this._renderTargetDepth.setSize(t,e)}dispose(){this._renderTargetDepth.dispose(),this._materialDepth.dispose(),this.materialBokeh.dispose(),this._fsQuad.dispose()}}const Co={uniforms:{tDiffuse:{value:null},uVignetteStrength:{value:.25},uSaturation:{value:1.12},uWarmth:{value:.06}},vertexShader:`
112
112
  varying vec2 vUv;
113
113
  void main() {
114
114
  vUv = uv;
@@ -158,7 +158,7 @@ import{m as We,n as Ge,H as Oe,N as Ht,o as Le,p as Ve,q as He,t as qe,k as mt,F
158
158
 
159
159
  gl_FragColor = vec4(color, 1.0);
160
160
  }
161
- `};function wo(){return new At(bo)}const So={uniforms:{tDiffuse:{value:null},uTime:{value:0},uIntensity:{value:.025}},vertexShader:`
161
+ `};function Po(){return new kt(Co)}const Do={uniforms:{tDiffuse:{value:null},uTime:{value:0},uIntensity:{value:.025}},vertexShader:`
162
162
  varying vec2 vUv;
163
163
  void main() {
164
164
  vUv = uv;
@@ -180,7 +180,7 @@ import{m as We,n as Ge,H as Oe,N as Ht,o as Le,p as Ve,q as He,t as qe,k as mt,F
180
180
  color += grain * uIntensity;
181
181
  gl_FragColor = vec4(color, 1.0);
182
182
  }
183
- `};function Mo(){return new At(So)}function Co(s,t){s.uniforms.uTime.value=t}const Po={uniforms:{tDiffuse:{value:null},uLightPos:{value:[.3,.8]},uExposure:{value:.04},uDecay:{value:.95},uDensity:{value:.4},uWeight:{value:.04},uSamples:{value:60}},vertexShader:`
183
+ `};function _o(){return new kt(Do)}function To(s,t){s.uniforms.uTime.value=t}const zo={uniforms:{tDiffuse:{value:null},uLightPos:{value:[.3,.8]},uExposure:{value:.04},uDecay:{value:.95},uDensity:{value:.4},uWeight:{value:.04},uSamples:{value:60}},vertexShader:`
184
184
  varying vec2 vUv;
185
185
  void main() {
186
186
  vUv = uv;
@@ -213,7 +213,7 @@ import{m as We,n as Ge,H as Oe,N as Ht,o as Le,p as Ve,q as He,t as qe,k as mt,F
213
213
  vec3 original = texture2D(tDiffuse, vUv).rgb;
214
214
  gl_FragColor = vec4(original + color * uExposure, 1.0);
215
215
  }
216
- `};function Do(){return new At(Po)}const _o={uniforms:{tDiffuse:{value:null},uOffset:{value:.002}},vertexShader:`
216
+ `};function Ao(){return new kt(zo)}const ko={uniforms:{tDiffuse:{value:null},uOffset:{value:.002}},vertexShader:`
217
217
  varying vec2 vUv;
218
218
  void main() {
219
219
  vUv = uv;
@@ -235,7 +235,7 @@ import{m as We,n as Ge,H as Oe,N as Ht,o as Le,p as Ve,q as He,t as qe,k as mt,F
235
235
 
236
236
  gl_FragColor = vec4(r, g, b, 1.0);
237
237
  }
238
- `};function To(){return new At(_o)}const Zt="__ground__";function Bt(s){let t=2166136261;for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t=Math.imul(t,16777619);return t>>>0}function _t(s){let t=Bt(s)||1;return()=>{t|=0,t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}function lt(s,t,e){return t+(e-t)*s()}function X(s,t,e){return Math.min(e,Math.max(t,s))}function zo(s){const t=Math.abs(s.y)>.92?new w(1,0,0):new w(0,1,0),e=new w().crossVectors(s,t).normalize(),o=new w().crossVectors(e,s).normalize();return{u:e,v:o}}function Ae(s,t){if(s.type==="file")return t.set(s.path,1),1;const e=s.children??[];let o=1;for(const i of e)o+=Ae(i,t);const n=Math.max(1.4,o);return t.set(s.path,n),n}function Ao(s,t){return[...s].sort((e,o)=>e.type!==o.type?e.type==="folder"?-1:1:Bt(`${t}:${e.path}`)-Bt(`${t}:${o.path}`))}function Xt(s,t,e,o,n=!1){if(n||t==="root")return X(3.6+Math.log1p(o)*.42,3.8,6.8);const i=Math.pow(e/Math.max(o,1),.42);return t==="folder"?X(.34+i*3.3*Math.pow(.86,s),.32,3.6):X(.1+i*.95*Math.pow(.78,s),.18,.46)}function Qt(s,t,e,o,n,i=!1){if(i||t==="root")return X(28+Math.log1p(o)*2.8+lt(n,0,3.5),28,42);const a=Math.pow(e/Math.max(o,1),.36);return t==="folder"?X(16*Math.pow(.9,s)+a*18+lt(n,1,5),9,36):X(7*Math.pow(.88,s)+a*4.8+lt(n,.8,2.2),4,12)}function ko(s,t){const e=new Map,o=Ae(s,e),n=new Map,i=[],a=[],l=new Map;let r=0;const c=_t(`${t}:lean`),h=lt(c,0,Math.PI*2),m=lt(c,.07,.18),d=new w(Math.cos(h)*m,0,Math.sin(h)*m),p=new w(d.x,1,d.z).normalize(),f=_t(`${t}:trunk`),y=Qt(0,"root",o,o,f,!0),g=new w(0,0,0),v=g.clone().add(p.clone().multiplyScalar(y)),M=`${Zt}->${s.path}`,u=g.clone().lerp(v,.32).add(new w(d.x*12,4.5,d.z*12)),C=g.clone().lerp(v,.74).add(new w(d.x*18,2.2,d.z*18));i.push({id:M,fromPath:Zt,toPath:s.path,curvePoints:[g.clone(),u,C,v.clone()],depth:0,radius:Xt(0,"root",o,o,!0),subtreeWeight:o,branchType:"root",isSyntheticRoot:!0});function b(D,F,E,j,I,O){r=Math.max(r,I);const k=e.get(D.path)??1,N=[];if(n.set(D.path,{id:D.id,path:D.path,type:D.type,depth:I,position:E.clone(),parentPath:F,children:N,branchId:O,subtreeWeight:k}),D.type==="file"){a.push(D.path),l.set(D.path,{path:D.path,position:E.clone(),direction:j.clone().normalize(),depth:I,scale:X(1.02-I*.05,.42,1.02)});return}const et=Ao(D.children??[],`${t}:${D.path}`);if(!et.length)return;const W=zo(j),$=X((I+1)/6,0,1);et.forEach((L,Z)=>{const ot=_t(`${t}:${L.path}`),x=e.get(L.path)??1,A=Math.pow(x/Math.max(o,1),.34),B=Z/Math.max(et.length,1)*Math.PI*2,V=lt(ot,-.4,.4),_=B+V,T=It.lerp(.4,1.6,$)+A*.3,R=Math.cos(_)*T,z=Math.sin(_)*T,U=L.type==="folder"?It.lerp(.85,.1,$):It.lerp(.4,-.15,$),G=I===0?.92:I<2?.65:.4,rt=L.type==="folder"?X((I-1)*.06,0,.22):X(.1+I*.07,.1,.45),yt=j.clone().multiplyScalar(G+A*.28).add(new w(0,1,0).multiplyScalar(U)).add(W.u.clone().multiplyScalar(R)).add(W.v.clone().multiplyScalar(z)).add(d.clone().multiplyScalar(.12+$*.18)).add(new w(0,-1,0).multiplyScalar(rt)).normalize(),ht=L.type==="folder"?"folder":"file",Ne=Qt(I+1,ht,x,o,ot),xt=E.clone().add(yt.clone().multiplyScalar(Ne)),J=(ht==="folder"?5.2:2.7)*(.94+$*.55),$e=E.clone().lerp(xt,.28).add(new w(0,U*J*.68,0)).add(W.u.clone().multiplyScalar(R*J*.3)).add(W.v.clone().multiplyScalar(z*J*.3)).add(d.clone().multiplyScalar(J*.3)),Be=E.clone().lerp(xt,.74).add(W.u.clone().multiplyScalar(R*J*.15)).add(W.v.clone().multiplyScalar(z*J*.15)).add(new w(0,ht==="folder"?J*.16:-J*.08,0)),Vt=`${D.path}->${L.path}`;N.push(L.path),i.push({id:Vt,fromPath:D.path,toPath:L.path,curvePoints:[E.clone(),$e,Be,xt.clone()],depth:I+1,radius:Xt(I+1,ht,x,o),subtreeWeight:x,branchType:ht}),b(L,D.path,xt,yt,I+1,Vt)})}return b(s,null,v,p,0,M),{nodes:n,branches:i,tipPaths:a,maxDepth:r,blossomAnchors:l}}function Yt(s){const t=[];for(const e of s.replace(/\\/g,"/").split("/"))if(!(!e||e===".")){if(e===".."){if(!t.length)return null;t.pop();continue}t.push(e)}return t.join("/")}function Kt(s,t){if(typeof t!="string"||!t.trim())return null;const e=s.replace(/\\/g,"/").replace(/\/+$/,""),o=t.replace(/\\/g,"/");return o===e?".":o.startsWith(`${e}/`)?Yt(o.slice(e.length+1))||".":o.startsWith("/")?null:Yt(o.replace(/^\.\//,""))||"."}function Jt(s,t){const e=[];let o=s.nodes.get(t);for(;o&&o.branchId;)e.push(o.branchId),o=o.parentPath?s.nodes.get(o.parentPath):void 0;return e.reverse()}function Io(s,t,e=12){const o=s.nodes.get(t);if(!o)return[];if(o.type==="file")return[o.path];const n=[...o.children],i=[];for(;n.length>0&&i.length<e;){const a=n.shift(),l=s.nodes.get(a);l&&(l.type==="file"?i.push(l.path):n.push(...l.children))}return i}function te(s,t,e){if(s.tipPaths.length<=e)return[...s.tipPaths];const o=_t(t),n=[...s.tipPaths],i=[];for(;n.length>0&&i.length<e;){const a=Math.floor(o()*n.length);i.push(n.splice(a,1)[0])}return i}function Ro(s){var t;return((t=s.branches.find(e=>e.isSyntheticRoot))==null?void 0:t.toPath)??"."}function Uo(s,t){if(t===null)return null;const e=Ro(s),o=t.replace(/\\/g,"/").split("/");for(let n=o.length;n>0;n--){const i=o.slice(0,n).join("/");if(s.nodes.has(i))return i}return s.nodes.has(e)?e:null}const ke=`uniform float uTime;
238
+ `};function Io(){return new kt(ko)}const Qt="__ground__";function Wt(s){let t=2166136261;for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t=Math.imul(t,16777619);return t>>>0}function Tt(s){let t=Wt(s)||1;return()=>{t|=0,t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}function lt(s,t,e){return t+(e-t)*s()}function X(s,t,e){return Math.min(e,Math.max(t,s))}function Ro(s){const t=Math.abs(s.y)>.92?new w(1,0,0):new w(0,1,0),e=new w().crossVectors(s,t).normalize(),o=new w().crossVectors(e,s).normalize();return{u:e,v:o}}function Ie(s,t){if(s.type==="file")return t.set(s.path,1),1;const e=s.children??[];let o=1;for(const i of e)o+=Ie(i,t);const n=Math.max(1.4,o);return t.set(s.path,n),n}function Uo(s,t){return[...s].sort((e,o)=>e.type!==o.type?e.type==="folder"?-1:1:Wt(`${t}:${e.path}`)-Wt(`${t}:${o.path}`))}function Yt(s,t,e,o,n=!1){if(n||t==="root")return X(3.6+Math.log1p(o)*.42,3.8,6.8);const i=Math.pow(e/Math.max(o,1),.42);return t==="folder"?X(.34+i*3.3*Math.pow(.86,s),.32,3.6):X(.1+i*.95*Math.pow(.78,s),.18,.46)}function Kt(s,t,e,o,n,i=!1){if(i||t==="root")return X(28+Math.log1p(o)*2.8+lt(n,0,3.5),28,42);const a=Math.pow(e/Math.max(o,1),.36);return t==="folder"?X(16*Math.pow(.9,s)+a*18+lt(n,1,5),9,36):X(7*Math.pow(.88,s)+a*4.8+lt(n,.8,2.2),4,12)}function Fo(s,t){const e=new Map,o=Ie(s,e),n=new Map,i=[],a=[],l=new Map;let r=0;const c=Tt(`${t}:lean`),h=lt(c,0,Math.PI*2),m=lt(c,.07,.18),d=new w(Math.cos(h)*m,0,Math.sin(h)*m),p=new w(d.x,1,d.z).normalize(),f=Tt(`${t}:trunk`),y=Kt(0,"root",o,o,f,!0),g=new w(0,0,0),v=g.clone().add(p.clone().multiplyScalar(y)),M=`${Qt}->${s.path}`,u=g.clone().lerp(v,.32).add(new w(d.x*12,4.5,d.z*12)),C=g.clone().lerp(v,.74).add(new w(d.x*18,2.2,d.z*18));i.push({id:M,fromPath:Qt,toPath:s.path,curvePoints:[g.clone(),u,C,v.clone()],depth:0,radius:Yt(0,"root",o,o,!0),subtreeWeight:o,branchType:"root",isSyntheticRoot:!0});function b(D,F,E,j,k,L){r=Math.max(r,k);const z=e.get(D.path)??1,N=[];if(n.set(D.path,{id:D.id,path:D.path,type:D.type,depth:k,position:E.clone(),parentPath:F,children:N,branchId:L,subtreeWeight:z}),D.type==="file"){a.push(D.path),l.set(D.path,{path:D.path,position:E.clone(),direction:j.clone().normalize(),depth:k,scale:X(1.02-k*.05,.42,1.02)});return}const et=Uo(D.children??[],`${t}:${D.path}`);if(!et.length)return;const G=Ro(j),B=X((k+1)/6,0,1);et.forEach((V,Z)=>{const ot=Tt(`${t}:${V.path}`),x=e.get(V.path)??1,_=Math.pow(x/Math.max(o,1),.34),W=Z/Math.max(et.length,1)*Math.PI*2,R=lt(ot,-.4,.4),T=W+R,A=Rt.lerp(.4,1.6,B)+_*.3,U=Math.cos(T)*A,I=Math.sin(T)*A,$=V.type==="folder"?Rt.lerp(.85,.1,B):Rt.lerp(.4,-.15,B),O=k===0?.92:k<2?.65:.4,rt=V.type==="folder"?X((k-1)*.06,0,.22):X(.1+k*.07,.1,.45),yt=j.clone().multiplyScalar(O+_*.28).add(new w(0,1,0).multiplyScalar($)).add(G.u.clone().multiplyScalar(U)).add(G.v.clone().multiplyScalar(I)).add(d.clone().multiplyScalar(.12+B*.18)).add(new w(0,-1,0).multiplyScalar(rt)).normalize(),ht=V.type==="folder"?"folder":"file",Be=Kt(k+1,ht,x,o,ot),xt=E.clone().add(yt.clone().multiplyScalar(Be)),J=(ht==="folder"?5.2:2.7)*(.94+B*.55),We=E.clone().lerp(xt,.28).add(new w(0,$*J*.68,0)).add(G.u.clone().multiplyScalar(U*J*.3)).add(G.v.clone().multiplyScalar(I*J*.3)).add(d.clone().multiplyScalar(J*.3)),Ge=E.clone().lerp(xt,.74).add(G.u.clone().multiplyScalar(U*J*.15)).add(G.v.clone().multiplyScalar(I*J*.15)).add(new w(0,ht==="folder"?J*.16:-J*.08,0)),Ht=`${D.path}->${V.path}`;N.push(V.path),i.push({id:Ht,fromPath:D.path,toPath:V.path,curvePoints:[E.clone(),We,Ge,xt.clone()],depth:k+1,radius:Yt(k+1,ht,x,o),subtreeWeight:x,branchType:ht}),b(V,D.path,xt,yt,k+1,Ht)})}return b(s,null,v,p,0,M),{nodes:n,branches:i,tipPaths:a,maxDepth:r,blossomAnchors:l}}function Jt(s){const t=[];for(const e of s.replace(/\\/g,"/").split("/"))if(!(!e||e===".")){if(e===".."){if(!t.length)return null;t.pop();continue}t.push(e)}return t.join("/")}function te(s,t){if(typeof t!="string"||!t.trim())return null;const e=s.replace(/\\/g,"/").replace(/\/+$/,""),o=t.replace(/\\/g,"/");return o===e?".":o.startsWith(`${e}/`)?Jt(o.slice(e.length+1))||".":o.startsWith("/")?null:Jt(o.replace(/^\.\//,""))||"."}function ee(s,t){const e=[];let o=s.nodes.get(t);for(;o&&o.branchId;)e.push(o.branchId),o=o.parentPath?s.nodes.get(o.parentPath):void 0;return e.reverse()}function Eo(s,t,e=12){const o=s.nodes.get(t);if(!o)return[];if(o.type==="file")return[o.path];const n=[...o.children],i=[];for(;n.length>0&&i.length<e;){const a=n.shift(),l=s.nodes.get(a);l&&(l.type==="file"?i.push(l.path):n.push(...l.children))}return i}function oe(s,t,e){if(s.tipPaths.length<=e)return[...s.tipPaths];const o=Tt(t),n=[...s.tipPaths],i=[];for(;n.length>0&&i.length<e;){const a=Math.floor(o()*n.length);i.push(n.splice(a,1)[0])}return i}function jo(s){var t;return((t=s.branches.find(e=>e.isSyntheticRoot))==null?void 0:t.toPath)??"."}function No(s,t){if(t===null)return null;const e=jo(s),o=t.replace(/\\/g,"/").split("/");for(let n=o.length;n>0;n--){const i=o.slice(0,n).join("/");if(s.nodes.has(i))return i}return s.nodes.has(e)?e:null}const Re=`uniform float uTime;
239
239
  uniform float uHeat;
240
240
  uniform float uPulse;
241
241
  uniform float uFlowOffset;
@@ -301,7 +301,7 @@ void main() {
301
301
  vWorldNormal = normalize(mat3(modelMatrix) * normal);
302
302
  gl_Position = projectionMatrix * viewMatrix * world;
303
303
  }
304
- `,Ie=`uniform float uTime;
304
+ `,Ue=`uniform float uTime;
305
305
  uniform float uHeat;
306
306
  uniform float uPulse;
307
307
  uniform float uContam;
@@ -433,7 +433,7 @@ void main() {
433
433
 
434
434
  gl_FragColor = vec4(color, 1.0);
435
435
  }
436
- `;function Fo(s){let t=2166136261;for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t=Math.imul(t,16777619);return t>>>0}function Eo(s){let t=Fo(s)||1;return()=>{t|=0,t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}function jo(s){const{curve:t,baseRadius:e,taper:o,gnarliness:n,twist:i,sections:a,segments:l,seedKey:r,parentRadius:c}=s,h=Eo(`branch:${r}`),m=(k,N)=>k+(N-k)*h(),d=(a+1)*(l+1)+2,p=new Float32Array(d*3),f=new Float32Array(d*3),y=new Float32Array(d*2),g=[],v=new gt(0,0,0),M=new st;let u=0;for(let k=0;k<=a;k++){const N=k/a,et=t.getPointAt(N),W=t.getTangentAt(N).normalize();let $;if(k===a?$=e*.02:($=e*(1-o*N),c&&k===0&&($=Math.min($,c*.85))),k>2){const T=n*Math.max(.5,1/Math.sqrt(Math.max($,.2)));v.x+=m(-T,T),v.z+=m(-T,T)}M.setFromEuler(v);const L=Math.abs(W.y)>.99?new w(1,0,0):new w(0,1,0),Z=new w().crossVectors(W,L).normalize(),ot=new w().crossVectors(Z,W).normalize(),x=i*N,A=Math.cos(x),B=Math.sin(x),V=Z.clone().multiplyScalar(A).add(ot.clone().multiplyScalar(B)),_=Z.clone().multiplyScalar(-B).add(ot.clone().multiplyScalar(A));for(let T=0;T<=l;T++){const R=T/l*Math.PI*2,z=V.clone().multiplyScalar(Math.cos(R)*$).add(_.clone().multiplyScalar(Math.sin(R)*$));z.applyQuaternion(M);const U=et.clone().add(z),G=z.clone().normalize();p[u*3]=U.x,p[u*3+1]=U.y,p[u*3+2]=U.z,f[u*3]=G.x,f[u*3+1]=G.y,f[u*3+2]=G.z,y[u*2]=N,y[u*2+1]=T/l,u++}if(k<a){const T=k*(l+1),R=(k+1)*(l+1);for(let z=0;z<l;z++){const U=T+z,G=T+z+1,rt=R+z+1,yt=R+z;g.push(U,G,rt),g.push(U,rt,yt)}}}const C=u,b=t.getPointAt(0);p[u*3]=b.x,p[u*3+1]=b.y,p[u*3+2]=b.z;const D=t.getTangentAt(0).normalize();f[u*3]=-D.x,f[u*3+1]=-D.y,f[u*3+2]=-D.z,y[u*2]=0,y[u*2+1]=.5,u++;for(let k=0;k<l;k++)g.push(C,k+1,k);const F=u,E=t.getPointAt(1);p[u*3]=E.x,p[u*3+1]=E.y,p[u*3+2]=E.z;const j=t.getTangentAt(1).normalize();f[u*3]=j.x,f[u*3+1]=j.y,f[u*3+2]=j.z,y[u*2]=1,y[u*2+1]=.5,u++;const I=a*(l+1);for(let k=0;k<l;k++)g.push(F,I+k,I+k+1);const O=new ct;return O.setAttribute("position",new q(p,3)),O.setAttribute("normal",new q(f,3)),O.setAttribute("uv",new q(y,2)),O.setIndex(g),O.computeBoundingSphere(),O}function No(){const t=document.createElement("canvas");t.width=256,t.height=256;const e=t.getContext("2d");e.fillStyle="rgb(128,128,255)",e.fillRect(0,0,256,256);const o=e.getImageData(0,0,256,256),n=o.data;for(let r=0;r<256;r++)for(let c=0;c<256;c++){const h=(r*256+c)*4,m=Math.sin(c/256*Math.PI*24)*.5+Math.sin(c/256*Math.PI*7+.8)*.25;n[h]=Math.round(128+m*30),n[h+1]=128,n[h+2]=255,n[h+3]=255}const a=(r=>{let c=r;return()=>(c=c*1664525+1013904223>>>0,c/4294967295)})(42);for(let r=0;r<12;r++){const c=Math.floor(a()*256),h=Math.floor(a()*256),m=Math.floor(20+a()*30),d=Math.floor(3+a()*5);for(let p=-d;p<=d;p++)for(let f=-m;f<=m;f++){const y=(c+f+256)%256,g=(h+p+256)%256,v=1-Math.sqrt((f/m)**2+(p/d)**2);if(v<=0)continue;const M=(g*256+y)*4,u=Math.sin(v*Math.PI)*40;n[M+1]=Math.min(255,Math.round(n[M+1]+u))}}e.putImageData(o,0,0);const l=new it(t);return l.wrapS=zt,l.wrapT=zt,l.repeat.set(2,4),l.needsUpdate=!0,l}let Ut=null;function $o(){return Ut||(Ut=No()),Ut}function Tt(s){let t=2166136261;for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t=Math.imul(t,16777619);return(t>>>0)/4294967296}function St(s,t,e){return Math.min(e,Math.max(t,s))}function Bo(s){return new mt({uniforms:{uTime:{value:0},uHeat:{value:0},uPulse:{value:0},uContam:{value:0},uPulseColor:{value:new H("#e8a88a")},uFlowOffset:{value:s},uWindStrength:{value:0},uWindPhase:{value:0},uSignalPos:{value:-1},uSignalIntensity:{value:0},uSignalColor:{value:new H("#ffffff")},uDepth:{value:0},uGrowth:{value:1},uNormalMap:{value:$o()},uNormalScale:{value:.3}},vertexShader:ke,fragmentShader:Ie,transparent:!1,depthWrite:!0,side:vt,blending:Ce})}function Wo(s){return new Me(s.map(t=>t.clone()),!1,"catmullrom",.45)}function Go(s,t){const e=new Map;for(const n of s.branches){if(n.branchType==="file")continue;const i=Wo(n.curvePoints),a=Math.max(12,Math.min(32,28-n.depth*2)),l=n.depth<=1?12:n.depth<=3?10:8,r=Tt(`taper:${n.id}`)*.15,c=n.branchType==="root"?.5:n.branchType==="folder"?.6+r:.75+r,h=n.branchType==="root"?.008:.012+n.depth*.006,m=Tt(n.id)*1+.3,d=s.branches.find(u=>u.toPath===n.fromPath),p=d?d.branchType==="root"?.5:d.branchType==="folder"?.65:.8:.5,f=d?d.radius*(1-p*.7):n.radius,y=Math.min(n.radius,f*.9),g=jo({curve:i,baseRadius:n.isSyntheticRoot?n.radius:y,taper:c,gnarliness:h,twist:m,sections:a,segments:l,seedKey:n.id,parentRadius:f}),v=Bo(Tt(n.id));v.uniforms.uDepth.value=n.depth;const M=new at(g,v);M.renderOrder=2,M.castShadow=!0,t.add(M),e.set(n.id,{spec:n,mesh:M,material:v,curve:i,pulse:0,contamination:0,pulseColor:new H("#e8a88a"),growthProgress:1,growthTarget:1,growthStartTime:0,growthDuration:2.5})}return{branches:e,junctions:[]}}function Oo(s,t,e,o,n,i,a,l){for(const r of s.values()){r.pulse=Math.max(0,r.pulse-l*1.65),r.contamination=Math.max(0,r.contamination-l*.08);const c=St(o*(r.spec.branchType==="root"?1.1:1.04-r.spec.depth*.06),.05,1),h=r.material.uniforms;h.uTime.value=e,h.uHeat.value=c,h.uPulse.value=r.pulse,h.uContam.value=St(n*.45+r.contamination,0,1),h.uPulseColor.value.copy(r.pulseColor),h.uWindStrength.value=i*Math.min(2,r.spec.depth*.3),h.uWindPhase.value=a}for(const r of t){let c=0,h=0;const m=new H("#e8a88a");for(const p of r.branchIds){const f=s.get(p);f&&(f.pulse>=c&&(c=f.pulse,m.copy(f.pulseColor)),h=Math.max(h,f.contamination))}const d=r.material.uniforms;d.uTime.value=e+Tt(r.path),d.uHeat.value=St(o*1.04+c*.16,.08,1),d.uPulse.value=c*.88,d.uContam.value=St(n*.4+h*.85,0,1),d.uPulseColor.value.copy(m),d.uWindStrength.value=i*.2,d.uWindPhase.value=a}}function Lo(s,t){for(const e of s.values())e.mesh.geometry.dispose(),e.material.dispose();for(const e of t)e.mesh.geometry.dispose(),e.material.dispose()}const nt=6e5,ee=18e5,K=8,ut=K+1,Mt=22,oe=5,Ft=2,Vo=50,Ho=.04,ne=38,se=48,ie=28,qo=2e3,re=200,ae=800,le=2,ce=.05,Zo=3.5,he=2,Xo=.06,Et=2,Qo=1.2,Yo=1,ue=30;class de{constructor(t){this.w=t|0||1,this.z=t*1664525+1013904223|0||1}random(t=1,e=0){this.z=36969*(this.z&65535)+(this.z>>16)|0,this.w=18e3*(this.w&65535)+(this.w>>16)|0;let o=(this.z<<16)+this.w|0;return o=(o>>>0)/4294967296,e+o*(t-e)}}class Ko{constructor(t){this.cells=new Map,this.cellSize=t}key(t,e,o){const n=Math.floor(t/this.cellSize),i=Math.floor(e/this.cellSize),a=Math.floor(o/this.cellSize);return`${n},${i},${a}`}clear(){this.cells.clear()}insert(t,e){const o=this.key(e.x,e.y,e.z),n=this.cells.get(o);n?n.push(t):this.cells.set(o,[t])}queryRadius(t,e){const o=[],n=e,i=this.cellSize,a=Math.floor((t.x-n)/i),l=Math.floor((t.x+n)/i),r=Math.floor((t.y-n)/i),c=Math.floor((t.y+n)/i),h=Math.floor((t.z-n)/i),m=Math.floor((t.z+n)/i);for(let d=a;d<=l;d++)for(let p=r;p<=c;p++)for(let f=h;f<=m;f++){const y=this.cells.get(`${d},${p},${f}`);if(y)for(const g of y)o.push(g)}return o}}class Jo{constructor(t=23399){this.nodes=[],this.nodeMap=new Map,this.nextNodeId=0,this.attractors=[],this.envelopeScale=1,this.eventCounter=0,this.activeAttractors=0,this.vertexCount=0,this.indexCount=0,this.seed=t,this.rng=new de(t),this.nodeGrid=new Ko(Mt),this.positions=new Float32Array(nt*3),this.normalsArr=new Float32Array(nt*3),this.uvsArr=new Float32Array(nt*2),this.indicesArr=new Uint32Array(ee),this.geometry=new ct;const e=new q(this.positions,3);e.setUsage(bt);const o=new q(this.normalsArr,3);o.setUsage(bt);const n=new q(this.uvsArr,2);n.setUsage(bt);const i=new q(this.indicesArr,1);i.setUsage(bt),this.geometry.setAttribute("position",e),this.geometry.setAttribute("normal",o),this.geometry.setAttribute("uv",n),this.geometry.setIndex(i),this.geometry.setDrawRange(0,0),this.init()}onEvent(){const t=[],e=[];for(let o=0;o<Yo;o++){const{flowers:n,newNodeIds:i}=this.growOneStep(!0);t.push(...n),e.push(...i)}return{flowers:t,newNodeIds:e}}reset(){this.nodes=[],this.nodeMap.clear(),this.nextNodeId=0,this.attractors=[],this.activeAttractors=0,this.vertexCount=0,this.indexCount=0,this.eventCounter=0,this.envelopeScale=1,this.rng=new de(this.seed),this.init(),this.commitGeometry()}traceToRoot(t){const e=[];let o=this.nodeMap.get(t);for(;o;)e.unshift(o.id),o=o.parentId!==null?this.nodeMap.get(o.parentId):void 0;return e}getNode(t){return this.nodeMap.get(t)}get nodeCount(){return this.nodes.length}get totalEvents(){return this.eventCounter}get isCapped(){return this.vertexCount+ut*60>=nt}getRandomLeafPath(){const t=this.nodes.filter(o=>o.childIds.length===0);if(t.length===0)return null;const e=t[Math.floor(Math.random()*t.length)];return this.traceToRoot(e.id).map(o=>this.nodeMap.get(o)).filter(o=>o!==void 0).map(o=>o.position.clone())}get activeAttractorCount(){return this.activeAttractors}getTipFlowerPositions(){const t=[];for(const e of this.nodes){if(e.depth<Et)continue;const o=e.childIds.length===0;(o||e.depth>=5)&&t.push({pos:e.position.clone(),dir:e.direction.clone(),isTip:o})}return t}init(){this.personality=this.derivePersonality(),this.scatterAttractors(qo);const t=.052+this.personality.leanAngle*.15,e=new w(Math.sin(t)*Math.cos(this.personality.leanDirection),Math.cos(t),Math.sin(t)*Math.sin(this.personality.leanDirection)).normalize(),o={id:this.nextNodeId++,position:new w(0,0,0),parentId:null,childIds:[],radius:Qo,depth:0,distFromRoot:0,direction:e,segmentVertexStart:-1,createdAtEvent:0,lastPerturbation:new w};this.nodes.push(o),this.nodeMap.set(o.id,o)}gaussRng(){const t=Math.max(1e-10,this.rng.random()),e=this.rng.random();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e)}gnarlForDepth(t){const e=this.personality.gnarliness;return t<=5?(.35+Math.min(t,5)*.02)*e:t<=12?.18*e:.1*e}derivePersonality(){const t=this.rng.random(.18,.03),e=this.rng.random(Math.PI*2,0),o=this.rng.random(.9,.3),n=(this.rng.random()-.5)*.04,i=(this.rng.random()-.5)*.04,a=2+Math.floor(this.rng.random()*3),l=[],r=se,c=ie,h=ne;for(let m=0;m<a;m++){let d=0,p=0,f=0,y=0;do d=(this.rng.random()*2-1)*r,p=(this.rng.random()*2-1)*c+h,f=(this.rng.random()*2-1)*r,y++;while((d*d/(r*r)+(p-h)*(p-h)/(c*c)+f*f/(r*r)>1||p<15)&&y<50);l.push(new w(d,p,f))}return{leanAngle:t,leanDirection:e,gnarliness:o,windDriftX:n,windDriftZ:i,hotspots:l}}scatterAttractors(t){const e=this.envelopeScale,o=se*e,n=ie*e,i=ne*e,a=Math.sin(this.personality.leanAngle)*Math.cos(this.personality.leanDirection),l=Math.sin(this.personality.leanAngle)*Math.sin(this.personality.leanDirection),r=Math.floor(t*.6),c=t-r;let h=0,m=0;const d=o*.3;for(;h<r&&m<r*30;){m++;const f=this.personality.hotspots[Math.floor(this.rng.random()*this.personality.hotspots.length)],y=f.x*e,g=f.y*e,v=f.z*e,M=y+this.gaussRng()*d,u=g+this.gaussRng()*d*.5,C=v+this.gaussRng()*d,b=M/o,D=(u-i)/n,F=C/o;if(b*b+D*D+F*F>1||u<12)continue;const E=M+(u-i)*a,j=C+(u-i)*l;this.attractors.push({position:new w(E,u,j),active:!0}),h++}let p=0;for(;p<c;){const f=(this.rng.random()*2-1)*o,y=(this.rng.random()*2-1)*n+i,g=(this.rng.random()*2-1)*o,v=f/o,M=(y-i)/n,u=g/o;if(v*v+M*M+u*u>1||y<12)continue;const C=f+(y-i)*a,b=g+(y-i)*l;this.attractors.push({position:new w(C,y,b),active:!0}),p++}this.activeAttractors+=h+p}growOneStep(t){this.eventCounter++,this.eventCounter%Vo===0&&(this.envelopeScale+=Ho);const e=[],o=[],n={flowers:e,newNodeIds:o};if(this.vertexCount+ut*60>=nt)return console.warn(`[SCA] vertex cap reached: ${this.vertexCount}/${nt} (${this.nodes.length} nodes, event ${this.eventCounter})`),n;this.nodeGrid.clear();for(const b of this.nodes)this.nodeGrid.insert(b.id,b.position);const i=new Map,a=Mt*Mt;for(const b of this.attractors){if(!b.active)continue;const D=this.nodeGrid.queryRadius(b.position,Mt);let F=-1,E=a;for(const j of D){const O=this.nodeMap.get(j).position.distanceToSquared(b.position);O<E&&(E=O,F=j)}if(F>=0){const j=i.get(F)??[];j.push(b.position),i.set(F,j)}}if(i.size===0){const b=this.growTrunkUpward();return o.push(b.id),t&&b.depth>=Et&&e.push({pos:b.position.clone(),dir:b.direction.clone()}),this.activeAttractors<re&&(this.envelopeScale+=.12,this.scatterAttractors(ae)),this.commitGeometry(),n}let l=-1,r=0,c=-1;for(const[b,D]of i.entries()){const F=this.nodeMap.get(b);(D.length>r||D.length===r&&F.depth>c)&&(l=b,r=D.length,c=F.depth)}if(l<0)return this.commitGeometry(),n;const h=this.nodeMap.get(l),m=i.get(l),d=new w;for(const b of m)d.add(new w().subVectors(b,h.position).normalize());d.divideScalar(m.length).normalize();const p=this.gnarlForDepth(h.depth),f=(this.rng.random()-.5)*p,y=(this.rng.random()-.5)*p*.5,g=(this.rng.random()-.5)*p,v=h.lastPerturbation;if(d.x+=f+v.x*.2,d.y+=y+v.y*.2,d.z+=g+v.z*.2,h.depth>he){const b=Math.min(1,(h.depth-he)/10);d.y-=Xo*b,d.x+=this.personality.windDriftX*b,d.z+=this.personality.windDriftZ*b}d.normalize();const M=h.position.clone().addScaledVector(d,Ft),u=this.createNode(M,d,h);u.lastPerturbation=new w(f+v.x*.2,y+v.y*.2,g+v.z*.2),o.push(u.id);const C=oe*oe;for(const b of this.attractors)b.active&&u.position.distanceToSquared(b.position)<C&&(b.active=!1,this.activeAttractors--);return this.updateRadiiToRoot(u),this.writeSegment(u),this.updateAncestorGeometry(u),t&&u.depth>=Et&&e.push({pos:u.position.clone(),dir:u.direction.clone()}),this.activeAttractors<re&&(this.envelopeScale+=.12,this.scatterAttractors(ae)),this.commitGeometry(),n}createNode(t,e,o){const n={id:this.nextNodeId++,position:t.clone(),parentId:o.id,childIds:[],radius:ce,depth:o.depth+1,distFromRoot:o.distFromRoot+Ft,direction:e.clone(),segmentVertexStart:-1,createdAtEvent:this.eventCounter,lastPerturbation:new w};return o.childIds.push(n.id),this.nodes.push(n),this.nodeMap.set(n.id,n),n}growTrunkUpward(){let t=this.nodes[this.nodes.length-1];for(const i of this.nodes)i.childIds.length===0&&i.position.y>t.position.y&&(t=i);const e=new w((this.rng.random()-.5)*.06,1,(this.rng.random()-.5)*.06).normalize(),o=t.position.clone().addScaledVector(e,Ft),n=this.createNode(o,e,t);return n.lastPerturbation=new w,this.updateRadiiToRoot(n),this.writeSegment(n),this.updateAncestorGeometry(n),n}updateRadiiToRoot(t){t.radius=ce;let e=t.parentId!==null?this.nodeMap.get(t.parentId):void 0;for(;e;){let o=0;for(const i of e.childIds){const a=this.nodeMap.get(i);o+=Math.pow(a.radius,le)}const n=Math.min(Zo,Math.pow(o,1/le));if(Math.abs(n-e.radius)<.001)break;e.radius=n,e=e.parentId!==null?this.nodeMap.get(e.parentId):void 0}}writeSegment(t){if(t.parentId===null)return;const e=this.nodeMap.get(t.parentId);if(this.vertexCount+ut*2>=nt||this.indexCount+K*6>=ee)return;t.segmentVertexStart=this.vertexCount;const o=t.direction,n=e.radius,i=t.radius,a=e.distFromRoot/ue,l=t.distFromRoot/ue,r=this.vertexCount;this.writeRing(e.position,o,n,a);const c=this.vertexCount;this.writeRing(t.position,o,i,l);for(let h=0;h<K;h++){const m=r+h,d=r+h+1,p=c+h+1,f=c+h;this.indicesArr[this.indexCount++]=m,this.indicesArr[this.indexCount++]=f,this.indicesArr[this.indexCount++]=d,this.indicesArr[this.indexCount++]=d,this.indicesArr[this.indexCount++]=f,this.indicesArr[this.indexCount++]=p}}writeRing(t,e,o,n){const i=new w(0,1,0),a=new st;Math.abs(e.dot(i))>.999?a.setFromUnitVectors(i,e.y>0?i:new w(0,-1,0)):a.setFromUnitVectors(i,e);const l=new gt().setFromQuaternion(a);let r=0,c=0,h=0,m=0,d=0,p=0;for(let y=0;y<K;y++){const g=2*Math.PI*y/K,v=Math.cos(g),M=Math.sin(g),u=new w(v*o,0,M*o).applyEuler(l).add(t),C=new w(v,0,M).applyEuler(l).normalize(),b=this.vertexCount;this.positions[b*3]=u.x,this.positions[b*3+1]=u.y,this.positions[b*3+2]=u.z,this.normalsArr[b*3]=C.x,this.normalsArr[b*3+1]=C.y,this.normalsArr[b*3+2]=C.z,this.uvsArr[b*2]=y/K,this.uvsArr[b*2+1]=n,this.vertexCount++,y===0&&(r=u.x,c=u.y,h=u.z,m=C.x,d=C.y,p=C.z)}const f=this.vertexCount;this.positions[f*3]=r,this.positions[f*3+1]=c,this.positions[f*3+2]=h,this.normalsArr[f*3]=m,this.normalsArr[f*3+1]=d,this.normalsArr[f*3+2]=p,this.uvsArr[f*2]=1,this.uvsArr[f*2+1]=n,this.vertexCount++}updateAncestorGeometry(t){let e=t.parentId!==null?this.nodeMap.get(t.parentId):void 0;for(;e;){for(const o of e.childIds){const n=this.nodeMap.get(o);if(n.segmentVertexStart<0)continue;const i=n.segmentVertexStart;this.updateRingRadius(i,e.position,n.direction,e.radius);const a=i+ut;a+ut<=this.vertexCount&&this.updateRingRadius(a,n.position,n.direction,n.radius)}e=e.parentId!==null?this.nodeMap.get(e.parentId):void 0}}updateRingRadius(t,e,o,n){const i=new w(0,1,0),a=new st;Math.abs(o.dot(i))>.999?a.setFromUnitVectors(i,o.y>0?i:new w(0,-1,0)):a.setFromUnitVectors(i,o);const l=new gt().setFromQuaternion(a);for(let r=0;r<=K;r++){const c=2*Math.PI*(r%K)/K,h=Math.cos(c),m=Math.sin(c),d=new w(h*n,0,m*n).applyEuler(l).add(e),p=t+r;if(p>=this.vertexCount)break;this.positions[p*3]=d.x,this.positions[p*3+1]=d.y,this.positions[p*3+2]=d.z}}commitGeometry(){this.geometry.setDrawRange(0,this.indexCount),this.geometry.getAttribute("position").needsUpdate=!0,this.geometry.getAttribute("normal").needsUpdate=!0,this.geometry.getAttribute("uv").needsUpdate=!0;const t=this.geometry.getIndex();t&&(t.needsUpdate=!0),this.geometry.computeBoundingSphere()}}const tn=8e3,en=-9.8,pe=-2,Ct=0,on=1;function Y(s){let t=2166136261;for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t=Math.imul(t,16777619);return(t>>>0)/4294967296}function nn(){const t=document.createElement("canvas");t.width=128,t.height=128;const e=t.getContext("2d"),o=128/2,n=128/2;e.beginPath(),e.moveTo(o,n*.15),e.bezierCurveTo(o+44,n*.28,o+50,n*1.05,o+2,n*1.75),e.bezierCurveTo(o-46,n*1.12,o-40,n*.32,o,n*.15),e.closePath();const i=e.createRadialGradient(o,n*.8,0,o,n*.8,128*.45);i.addColorStop(0,"rgba(255, 230, 240, 1)"),i.addColorStop(.3,"rgba(255, 200, 220, 1)"),i.addColorStop(.6,"rgba(245, 170, 200, 1)"),i.addColorStop(1,"rgba(230, 140, 175, 1)"),e.fillStyle=i,e.fill(),e.strokeStyle="rgba(220, 170, 190, 0.35)",e.lineWidth=1.2,e.beginPath(),e.moveTo(o,n*.25),e.quadraticCurveTo(o+1,n,o,n*1.55),e.stroke(),e.strokeStyle="rgba(220, 170, 190, 0.2)",e.lineWidth=.7;for(let l=0;l<4;l++){const r=.3+l*.15,c=n*(.4+r*1.1),h=18+l*6;e.beginPath(),e.moveTo(o,c),e.quadraticCurveTo(o-h*.6,c-4,o-h,c+3),e.stroke(),e.beginPath(),e.moveTo(o,c),e.quadraticCurveTo(o+h*.6,c-4,o+h,c+3),e.stroke()}const a=new it(t);return a.needsUpdate=!0,a}function sn(){const t=document.createElement("canvas");t.width=128,t.height=128;const e=t.getContext("2d"),o=128/2,n=128/2;e.beginPath(),e.moveTo(o,n*.15),e.bezierCurveTo(o+44,n*.28,o+50,n*1.05,o+2,n*1.75),e.bezierCurveTo(o-46,n*1.12,o-40,n*.32,o,n*.15),e.closePath();const i=e.createRadialGradient(o,n*.8,0,o,n*.8,128*.46);i.addColorStop(0,"rgba(255, 255, 255, 1)"),i.addColorStop(.85,"rgba(255, 255, 255, 1)"),i.addColorStop(.95,"rgba(255, 255, 255, 0.5)"),i.addColorStop(1,"rgba(255, 255, 255, 0)"),e.fillStyle=i,e.fill();const a=new it(t);return a.needsUpdate=!0,a}function rn(s,t){const e=s/2,o=t/2,n=new Float32Array([-e,-o,0,e,-o,0,e,o,0,-e,o,0,0,-o,-e,0,-o,e,0,o,e,0,o,-e]),i=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0]),a=new Float32Array([0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1]),l=[0,1,2,0,2,3,0,2,1,0,3,2,4,5,6,4,6,7,4,6,5,4,7,6],r=new ct;return r.setAttribute("position",new q(n,3)),r.setAttribute("normal",new q(i,3)),r.setAttribute("uv",new q(a,2)),r.setIndex(l),r}class an{constructor(){this.count=0,this.driftTimer=0,this.driftInterval=1.5,this.capacity=tn;const t=rn(2.8,3.4),e=nn(),o=sn();this.material=new mt({uniforms:{uMap:{value:e},uAlphaMap:{value:o},uLightDir:{value:new w(-.3,.8,.4).normalize()},uSSS:{value:.45},uSSSColor:{value:new H("#ff8aaa")}},vertexShader:`
436
+ `;function $o(s){let t=2166136261;for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t=Math.imul(t,16777619);return t>>>0}function Bo(s){let t=$o(s)||1;return()=>{t|=0,t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}function Wo(s){const{curve:t,baseRadius:e,taper:o,gnarliness:n,twist:i,sections:a,segments:l,seedKey:r,parentRadius:c}=s,h=Bo(`branch:${r}`),m=(z,N)=>z+(N-z)*h(),d=(a+1)*(l+1)+2,p=new Float32Array(d*3),f=new Float32Array(d*3),y=new Float32Array(d*2),g=[],v=new gt(0,0,0),M=new st;let u=0;for(let z=0;z<=a;z++){const N=z/a,et=t.getPointAt(N),G=t.getTangentAt(N).normalize();let B;if(z===a?B=e*.02:(B=e*(1-o*N),c&&z===0&&(B=Math.min(B,c*.85))),z>2){const A=n*Math.max(.5,1/Math.sqrt(Math.max(B,.2)));v.x+=m(-A,A),v.z+=m(-A,A)}M.setFromEuler(v);const V=Math.abs(G.y)>.99?new w(1,0,0):new w(0,1,0),Z=new w().crossVectors(G,V).normalize(),ot=new w().crossVectors(Z,G).normalize(),x=i*N,_=Math.cos(x),W=Math.sin(x),R=Z.clone().multiplyScalar(_).add(ot.clone().multiplyScalar(W)),T=Z.clone().multiplyScalar(-W).add(ot.clone().multiplyScalar(_));for(let A=0;A<=l;A++){const U=A/l*Math.PI*2,I=R.clone().multiplyScalar(Math.cos(U)*B).add(T.clone().multiplyScalar(Math.sin(U)*B));I.applyQuaternion(M);const $=et.clone().add(I),O=I.clone().normalize();p[u*3]=$.x,p[u*3+1]=$.y,p[u*3+2]=$.z,f[u*3]=O.x,f[u*3+1]=O.y,f[u*3+2]=O.z,y[u*2]=N,y[u*2+1]=A/l,u++}if(z<a){const A=z*(l+1),U=(z+1)*(l+1);for(let I=0;I<l;I++){const $=A+I,O=A+I+1,rt=U+I+1,yt=U+I;g.push($,O,rt),g.push($,rt,yt)}}}const C=u,b=t.getPointAt(0);p[u*3]=b.x,p[u*3+1]=b.y,p[u*3+2]=b.z;const D=t.getTangentAt(0).normalize();f[u*3]=-D.x,f[u*3+1]=-D.y,f[u*3+2]=-D.z,y[u*2]=0,y[u*2+1]=.5,u++;for(let z=0;z<l;z++)g.push(C,z+1,z);const F=u,E=t.getPointAt(1);p[u*3]=E.x,p[u*3+1]=E.y,p[u*3+2]=E.z;const j=t.getTangentAt(1).normalize();f[u*3]=j.x,f[u*3+1]=j.y,f[u*3+2]=j.z,y[u*2]=1,y[u*2+1]=.5,u++;const k=a*(l+1);for(let z=0;z<l;z++)g.push(F,k+z,k+z+1);const L=new ct;return L.setAttribute("position",new q(p,3)),L.setAttribute("normal",new q(f,3)),L.setAttribute("uv",new q(y,2)),L.setIndex(g),L.computeBoundingSphere(),L}function Go(){const t=document.createElement("canvas");t.width=256,t.height=256;const e=t.getContext("2d");e.fillStyle="rgb(128,128,255)",e.fillRect(0,0,256,256);const o=e.getImageData(0,0,256,256),n=o.data;for(let r=0;r<256;r++)for(let c=0;c<256;c++){const h=(r*256+c)*4,m=Math.sin(c/256*Math.PI*24)*.5+Math.sin(c/256*Math.PI*7+.8)*.25;n[h]=Math.round(128+m*30),n[h+1]=128,n[h+2]=255,n[h+3]=255}const a=(r=>{let c=r;return()=>(c=c*1664525+1013904223>>>0,c/4294967295)})(42);for(let r=0;r<12;r++){const c=Math.floor(a()*256),h=Math.floor(a()*256),m=Math.floor(20+a()*30),d=Math.floor(3+a()*5);for(let p=-d;p<=d;p++)for(let f=-m;f<=m;f++){const y=(c+f+256)%256,g=(h+p+256)%256,v=1-Math.sqrt((f/m)**2+(p/d)**2);if(v<=0)continue;const M=(g*256+y)*4,u=Math.sin(v*Math.PI)*40;n[M+1]=Math.min(255,Math.round(n[M+1]+u))}}e.putImageData(o,0,0);const l=new it(t);return l.wrapS=At,l.wrapT=At,l.repeat.set(2,4),l.needsUpdate=!0,l}let Ft=null;function Oo(){return Ft||(Ft=Go()),Ft}function zt(s){let t=2166136261;for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t=Math.imul(t,16777619);return(t>>>0)/4294967296}function Mt(s,t,e){return Math.min(e,Math.max(t,s))}function Lo(s){return new mt({uniforms:{uTime:{value:0},uHeat:{value:0},uPulse:{value:0},uContam:{value:0},uPulseColor:{value:new H("#e8a88a")},uFlowOffset:{value:s},uWindStrength:{value:0},uWindPhase:{value:0},uSignalPos:{value:-1},uSignalIntensity:{value:0},uSignalColor:{value:new H("#ffffff")},uDepth:{value:0},uGrowth:{value:1},uNormalMap:{value:Oo()},uNormalScale:{value:.3}},vertexShader:Re,fragmentShader:Ue,transparent:!1,depthWrite:!0,side:vt,blending:De})}function Vo(s){return new Pe(s.map(t=>t.clone()),!1,"catmullrom",.45)}function Ho(s,t){const e=new Map;for(const n of s.branches){if(n.branchType==="file")continue;const i=Vo(n.curvePoints),a=Math.max(12,Math.min(32,28-n.depth*2)),l=n.depth<=1?12:n.depth<=3?10:8,r=zt(`taper:${n.id}`)*.15,c=n.branchType==="root"?.5:n.branchType==="folder"?.6+r:.75+r,h=n.branchType==="root"?.008:.012+n.depth*.006,m=zt(n.id)*1+.3,d=s.branches.find(u=>u.toPath===n.fromPath),p=d?d.branchType==="root"?.5:d.branchType==="folder"?.65:.8:.5,f=d?d.radius*(1-p*.7):n.radius,y=Math.min(n.radius,f*.9),g=Wo({curve:i,baseRadius:n.isSyntheticRoot?n.radius:y,taper:c,gnarliness:h,twist:m,sections:a,segments:l,seedKey:n.id,parentRadius:f}),v=Lo(zt(n.id));v.uniforms.uDepth.value=n.depth;const M=new at(g,v);M.renderOrder=2,M.castShadow=!0,t.add(M),e.set(n.id,{spec:n,mesh:M,material:v,curve:i,pulse:0,contamination:0,pulseColor:new H("#e8a88a"),growthProgress:1,growthTarget:1,growthStartTime:0,growthDuration:2.5})}return{branches:e,junctions:[]}}function qo(s,t,e,o,n,i,a,l){for(const r of s.values()){r.pulse=Math.max(0,r.pulse-l*1.65),r.contamination=Math.max(0,r.contamination-l*.08);const c=Mt(o*(r.spec.branchType==="root"?1.1:1.04-r.spec.depth*.06),.05,1),h=r.material.uniforms;h.uTime.value=e,h.uHeat.value=c,h.uPulse.value=r.pulse,h.uContam.value=Mt(n*.45+r.contamination,0,1),h.uPulseColor.value.copy(r.pulseColor),h.uWindStrength.value=i*Math.min(2,r.spec.depth*.3),h.uWindPhase.value=a}for(const r of t){let c=0,h=0;const m=new H("#e8a88a");for(const p of r.branchIds){const f=s.get(p);f&&(f.pulse>=c&&(c=f.pulse,m.copy(f.pulseColor)),h=Math.max(h,f.contamination))}const d=r.material.uniforms;d.uTime.value=e+zt(r.path),d.uHeat.value=Mt(o*1.04+c*.16,.08,1),d.uPulse.value=c*.88,d.uContam.value=Mt(n*.4+h*.85,0,1),d.uPulseColor.value.copy(m),d.uWindStrength.value=i*.2,d.uWindPhase.value=a}}function Zo(s,t){for(const e of s.values())e.mesh.geometry.dispose(),e.material.dispose();for(const e of t)e.mesh.geometry.dispose(),e.material.dispose()}const nt=6e5,ne=18e5,K=8,ut=K+1,Ct=22,se=5,Et=2,Xo=50,Qo=.04,ie=38,re=48,ae=28,Yo=2e3,le=200,ce=800,he=2,ue=.05,Ko=3.5,de=2,Jo=.06,jt=2,tn=1.2,en=1,pe=30;class fe{constructor(t){this.w=t|0||1,this.z=t*1664525+1013904223|0||1}random(t=1,e=0){this.z=36969*(this.z&65535)+(this.z>>16)|0,this.w=18e3*(this.w&65535)+(this.w>>16)|0;let o=(this.z<<16)+this.w|0;return o=(o>>>0)/4294967296,e+o*(t-e)}}class on{constructor(t){this.cells=new Map,this.cellSize=t}key(t,e,o){const n=Math.floor(t/this.cellSize),i=Math.floor(e/this.cellSize),a=Math.floor(o/this.cellSize);return`${n},${i},${a}`}clear(){this.cells.clear()}insert(t,e){const o=this.key(e.x,e.y,e.z),n=this.cells.get(o);n?n.push(t):this.cells.set(o,[t])}queryRadius(t,e){const o=[],n=e,i=this.cellSize,a=Math.floor((t.x-n)/i),l=Math.floor((t.x+n)/i),r=Math.floor((t.y-n)/i),c=Math.floor((t.y+n)/i),h=Math.floor((t.z-n)/i),m=Math.floor((t.z+n)/i);for(let d=a;d<=l;d++)for(let p=r;p<=c;p++)for(let f=h;f<=m;f++){const y=this.cells.get(`${d},${p},${f}`);if(y)for(const g of y)o.push(g)}return o}}class nn{constructor(t=23399){this.nodes=[],this.nodeMap=new Map,this.nextNodeId=0,this.attractors=[],this.envelopeScale=1,this.eventCounter=0,this.activeAttractors=0,this.vertexCount=0,this.indexCount=0,this.seed=t,this.rng=new fe(t),this.nodeGrid=new on(Ct),this.positions=new Float32Array(nt*3),this.normalsArr=new Float32Array(nt*3),this.uvsArr=new Float32Array(nt*2),this.indicesArr=new Uint32Array(ne),this.geometry=new ct;const e=new q(this.positions,3);e.setUsage(bt);const o=new q(this.normalsArr,3);o.setUsage(bt);const n=new q(this.uvsArr,2);n.setUsage(bt);const i=new q(this.indicesArr,1);i.setUsage(bt),this.geometry.setAttribute("position",e),this.geometry.setAttribute("normal",o),this.geometry.setAttribute("uv",n),this.geometry.setIndex(i),this.geometry.setDrawRange(0,0),this.init()}onEvent(){const t=[],e=[];for(let o=0;o<en;o++){const{flowers:n,newNodeIds:i}=this.growOneStep(!0);t.push(...n),e.push(...i)}return{flowers:t,newNodeIds:e}}reset(){this.nodes=[],this.nodeMap.clear(),this.nextNodeId=0,this.attractors=[],this.activeAttractors=0,this.vertexCount=0,this.indexCount=0,this.eventCounter=0,this.envelopeScale=1,this.rng=new fe(this.seed),this.init(),this.commitGeometry()}traceToRoot(t){const e=[];let o=this.nodeMap.get(t);for(;o;)e.unshift(o.id),o=o.parentId!==null?this.nodeMap.get(o.parentId):void 0;return e}getNode(t){return this.nodeMap.get(t)}get nodeCount(){return this.nodes.length}get totalEvents(){return this.eventCounter}get isCapped(){return this.vertexCount+ut*60>=nt}getRandomLeafPath(){const t=this.nodes.filter(o=>o.childIds.length===0);if(t.length===0)return null;const e=t[Math.floor(Math.random()*t.length)];return this.traceToRoot(e.id).map(o=>this.nodeMap.get(o)).filter(o=>o!==void 0).map(o=>o.position.clone())}get activeAttractorCount(){return this.activeAttractors}getTipFlowerPositions(){const t=[];for(const e of this.nodes){if(e.depth<jt)continue;const o=e.childIds.length===0;(o||e.depth>=5)&&t.push({pos:e.position.clone(),dir:e.direction.clone(),isTip:o})}return t}init(){this.personality=this.derivePersonality(),this.scatterAttractors(Yo);const t=.052+this.personality.leanAngle*.15,e=new w(Math.sin(t)*Math.cos(this.personality.leanDirection),Math.cos(t),Math.sin(t)*Math.sin(this.personality.leanDirection)).normalize(),o={id:this.nextNodeId++,position:new w(0,0,0),parentId:null,childIds:[],radius:tn,depth:0,distFromRoot:0,direction:e,segmentVertexStart:-1,createdAtEvent:0,lastPerturbation:new w};this.nodes.push(o),this.nodeMap.set(o.id,o)}gaussRng(){const t=Math.max(1e-10,this.rng.random()),e=this.rng.random();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e)}gnarlForDepth(t){const e=this.personality.gnarliness;return t<=5?(.35+Math.min(t,5)*.02)*e:t<=12?.18*e:.1*e}derivePersonality(){const t=this.rng.random(.18,.03),e=this.rng.random(Math.PI*2,0),o=this.rng.random(.9,.3),n=(this.rng.random()-.5)*.04,i=(this.rng.random()-.5)*.04,a=2+Math.floor(this.rng.random()*3),l=[],r=re,c=ae,h=ie;for(let m=0;m<a;m++){let d=0,p=0,f=0,y=0;do d=(this.rng.random()*2-1)*r,p=(this.rng.random()*2-1)*c+h,f=(this.rng.random()*2-1)*r,y++;while((d*d/(r*r)+(p-h)*(p-h)/(c*c)+f*f/(r*r)>1||p<15)&&y<50);l.push(new w(d,p,f))}return{leanAngle:t,leanDirection:e,gnarliness:o,windDriftX:n,windDriftZ:i,hotspots:l}}scatterAttractors(t){const e=this.envelopeScale,o=re*e,n=ae*e,i=ie*e,a=Math.sin(this.personality.leanAngle)*Math.cos(this.personality.leanDirection),l=Math.sin(this.personality.leanAngle)*Math.sin(this.personality.leanDirection),r=Math.floor(t*.6),c=t-r;let h=0,m=0;const d=o*.3;for(;h<r&&m<r*30;){m++;const f=this.personality.hotspots[Math.floor(this.rng.random()*this.personality.hotspots.length)],y=f.x*e,g=f.y*e,v=f.z*e,M=y+this.gaussRng()*d,u=g+this.gaussRng()*d*.5,C=v+this.gaussRng()*d,b=M/o,D=(u-i)/n,F=C/o;if(b*b+D*D+F*F>1||u<12)continue;const E=M+(u-i)*a,j=C+(u-i)*l;this.attractors.push({position:new w(E,u,j),active:!0}),h++}let p=0;for(;p<c;){const f=(this.rng.random()*2-1)*o,y=(this.rng.random()*2-1)*n+i,g=(this.rng.random()*2-1)*o,v=f/o,M=(y-i)/n,u=g/o;if(v*v+M*M+u*u>1||y<12)continue;const C=f+(y-i)*a,b=g+(y-i)*l;this.attractors.push({position:new w(C,y,b),active:!0}),p++}this.activeAttractors+=h+p}growOneStep(t){this.eventCounter++,this.eventCounter%Xo===0&&(this.envelopeScale+=Qo);const e=[],o=[],n={flowers:e,newNodeIds:o};if(this.vertexCount+ut*60>=nt)return console.warn(`[SCA] vertex cap reached: ${this.vertexCount}/${nt} (${this.nodes.length} nodes, event ${this.eventCounter})`),n;this.nodeGrid.clear();for(const b of this.nodes)this.nodeGrid.insert(b.id,b.position);const i=new Map,a=Ct*Ct;for(const b of this.attractors){if(!b.active)continue;const D=this.nodeGrid.queryRadius(b.position,Ct);let F=-1,E=a;for(const j of D){const L=this.nodeMap.get(j).position.distanceToSquared(b.position);L<E&&(E=L,F=j)}if(F>=0){const j=i.get(F)??[];j.push(b.position),i.set(F,j)}}if(i.size===0){const b=this.growTrunkUpward();return o.push(b.id),t&&b.depth>=jt&&e.push({pos:b.position.clone(),dir:b.direction.clone()}),this.activeAttractors<le&&(this.envelopeScale+=.12,this.scatterAttractors(ce)),this.commitGeometry(),n}let l=-1,r=0,c=-1;for(const[b,D]of i.entries()){const F=this.nodeMap.get(b);(D.length>r||D.length===r&&F.depth>c)&&(l=b,r=D.length,c=F.depth)}if(l<0)return this.commitGeometry(),n;const h=this.nodeMap.get(l),m=i.get(l),d=new w;for(const b of m)d.add(new w().subVectors(b,h.position).normalize());d.divideScalar(m.length).normalize();const p=this.gnarlForDepth(h.depth),f=(this.rng.random()-.5)*p,y=(this.rng.random()-.5)*p*.5,g=(this.rng.random()-.5)*p,v=h.lastPerturbation;if(d.x+=f+v.x*.2,d.y+=y+v.y*.2,d.z+=g+v.z*.2,h.depth>de){const b=Math.min(1,(h.depth-de)/10);d.y-=Jo*b,d.x+=this.personality.windDriftX*b,d.z+=this.personality.windDriftZ*b}d.normalize();const M=h.position.clone().addScaledVector(d,Et),u=this.createNode(M,d,h);u.lastPerturbation=new w(f+v.x*.2,y+v.y*.2,g+v.z*.2),o.push(u.id);const C=se*se;for(const b of this.attractors)b.active&&u.position.distanceToSquared(b.position)<C&&(b.active=!1,this.activeAttractors--);return this.updateRadiiToRoot(u),this.writeSegment(u),this.updateAncestorGeometry(u),t&&u.depth>=jt&&e.push({pos:u.position.clone(),dir:u.direction.clone()}),this.activeAttractors<le&&(this.envelopeScale+=.12,this.scatterAttractors(ce)),this.commitGeometry(),n}createNode(t,e,o){const n={id:this.nextNodeId++,position:t.clone(),parentId:o.id,childIds:[],radius:ue,depth:o.depth+1,distFromRoot:o.distFromRoot+Et,direction:e.clone(),segmentVertexStart:-1,createdAtEvent:this.eventCounter,lastPerturbation:new w};return o.childIds.push(n.id),this.nodes.push(n),this.nodeMap.set(n.id,n),n}growTrunkUpward(){let t=this.nodes[this.nodes.length-1];for(const i of this.nodes)i.childIds.length===0&&i.position.y>t.position.y&&(t=i);const e=new w((this.rng.random()-.5)*.06,1,(this.rng.random()-.5)*.06).normalize(),o=t.position.clone().addScaledVector(e,Et),n=this.createNode(o,e,t);return n.lastPerturbation=new w,this.updateRadiiToRoot(n),this.writeSegment(n),this.updateAncestorGeometry(n),n}updateRadiiToRoot(t){t.radius=ue;let e=t.parentId!==null?this.nodeMap.get(t.parentId):void 0;for(;e;){let o=0;for(const i of e.childIds){const a=this.nodeMap.get(i);o+=Math.pow(a.radius,he)}const n=Math.min(Ko,Math.pow(o,1/he));if(Math.abs(n-e.radius)<.001)break;e.radius=n,e=e.parentId!==null?this.nodeMap.get(e.parentId):void 0}}writeSegment(t){if(t.parentId===null)return;const e=this.nodeMap.get(t.parentId);if(this.vertexCount+ut*2>=nt||this.indexCount+K*6>=ne)return;t.segmentVertexStart=this.vertexCount;const o=t.direction,n=e.radius,i=t.radius,a=e.distFromRoot/pe,l=t.distFromRoot/pe,r=this.vertexCount;this.writeRing(e.position,o,n,a);const c=this.vertexCount;this.writeRing(t.position,o,i,l);for(let h=0;h<K;h++){const m=r+h,d=r+h+1,p=c+h+1,f=c+h;this.indicesArr[this.indexCount++]=m,this.indicesArr[this.indexCount++]=f,this.indicesArr[this.indexCount++]=d,this.indicesArr[this.indexCount++]=d,this.indicesArr[this.indexCount++]=f,this.indicesArr[this.indexCount++]=p}}writeRing(t,e,o,n){const i=new w(0,1,0),a=new st;Math.abs(e.dot(i))>.999?a.setFromUnitVectors(i,e.y>0?i:new w(0,-1,0)):a.setFromUnitVectors(i,e);const l=new gt().setFromQuaternion(a);let r=0,c=0,h=0,m=0,d=0,p=0;for(let y=0;y<K;y++){const g=2*Math.PI*y/K,v=Math.cos(g),M=Math.sin(g),u=new w(v*o,0,M*o).applyEuler(l).add(t),C=new w(v,0,M).applyEuler(l).normalize(),b=this.vertexCount;this.positions[b*3]=u.x,this.positions[b*3+1]=u.y,this.positions[b*3+2]=u.z,this.normalsArr[b*3]=C.x,this.normalsArr[b*3+1]=C.y,this.normalsArr[b*3+2]=C.z,this.uvsArr[b*2]=y/K,this.uvsArr[b*2+1]=n,this.vertexCount++,y===0&&(r=u.x,c=u.y,h=u.z,m=C.x,d=C.y,p=C.z)}const f=this.vertexCount;this.positions[f*3]=r,this.positions[f*3+1]=c,this.positions[f*3+2]=h,this.normalsArr[f*3]=m,this.normalsArr[f*3+1]=d,this.normalsArr[f*3+2]=p,this.uvsArr[f*2]=1,this.uvsArr[f*2+1]=n,this.vertexCount++}updateAncestorGeometry(t){let e=t.parentId!==null?this.nodeMap.get(t.parentId):void 0;for(;e;){for(const o of e.childIds){const n=this.nodeMap.get(o);if(n.segmentVertexStart<0)continue;const i=n.segmentVertexStart;this.updateRingRadius(i,e.position,n.direction,e.radius);const a=i+ut;a+ut<=this.vertexCount&&this.updateRingRadius(a,n.position,n.direction,n.radius)}e=e.parentId!==null?this.nodeMap.get(e.parentId):void 0}}updateRingRadius(t,e,o,n){const i=new w(0,1,0),a=new st;Math.abs(o.dot(i))>.999?a.setFromUnitVectors(i,o.y>0?i:new w(0,-1,0)):a.setFromUnitVectors(i,o);const l=new gt().setFromQuaternion(a);for(let r=0;r<=K;r++){const c=2*Math.PI*(r%K)/K,h=Math.cos(c),m=Math.sin(c),d=new w(h*n,0,m*n).applyEuler(l).add(e),p=t+r;if(p>=this.vertexCount)break;this.positions[p*3]=d.x,this.positions[p*3+1]=d.y,this.positions[p*3+2]=d.z}}commitGeometry(){this.geometry.setDrawRange(0,this.indexCount),this.geometry.getAttribute("position").needsUpdate=!0,this.geometry.getAttribute("normal").needsUpdate=!0,this.geometry.getAttribute("uv").needsUpdate=!0;const t=this.geometry.getIndex();t&&(t.needsUpdate=!0),this.geometry.computeBoundingSphere()}}const sn=8e3,rn=-9.8,me=-2,Pt=0,an=1;function Y(s){let t=2166136261;for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t=Math.imul(t,16777619);return(t>>>0)/4294967296}function ln(){const t=document.createElement("canvas");t.width=128,t.height=128;const e=t.getContext("2d"),o=128/2,n=128/2;e.beginPath(),e.moveTo(o,n*.15),e.bezierCurveTo(o+44,n*.28,o+50,n*1.05,o+2,n*1.75),e.bezierCurveTo(o-46,n*1.12,o-40,n*.32,o,n*.15),e.closePath();const i=e.createRadialGradient(o,n*.8,0,o,n*.8,128*.45);i.addColorStop(0,"rgba(255, 230, 240, 1)"),i.addColorStop(.3,"rgba(255, 200, 220, 1)"),i.addColorStop(.6,"rgba(245, 170, 200, 1)"),i.addColorStop(1,"rgba(230, 140, 175, 1)"),e.fillStyle=i,e.fill(),e.strokeStyle="rgba(220, 170, 190, 0.35)",e.lineWidth=1.2,e.beginPath(),e.moveTo(o,n*.25),e.quadraticCurveTo(o+1,n,o,n*1.55),e.stroke(),e.strokeStyle="rgba(220, 170, 190, 0.2)",e.lineWidth=.7;for(let l=0;l<4;l++){const r=.3+l*.15,c=n*(.4+r*1.1),h=18+l*6;e.beginPath(),e.moveTo(o,c),e.quadraticCurveTo(o-h*.6,c-4,o-h,c+3),e.stroke(),e.beginPath(),e.moveTo(o,c),e.quadraticCurveTo(o+h*.6,c-4,o+h,c+3),e.stroke()}const a=new it(t);return a.needsUpdate=!0,a}function cn(){const t=document.createElement("canvas");t.width=128,t.height=128;const e=t.getContext("2d"),o=128/2,n=128/2;e.beginPath(),e.moveTo(o,n*.15),e.bezierCurveTo(o+44,n*.28,o+50,n*1.05,o+2,n*1.75),e.bezierCurveTo(o-46,n*1.12,o-40,n*.32,o,n*.15),e.closePath();const i=e.createRadialGradient(o,n*.8,0,o,n*.8,128*.46);i.addColorStop(0,"rgba(255, 255, 255, 1)"),i.addColorStop(.85,"rgba(255, 255, 255, 1)"),i.addColorStop(.95,"rgba(255, 255, 255, 0.5)"),i.addColorStop(1,"rgba(255, 255, 255, 0)"),e.fillStyle=i,e.fill();const a=new it(t);return a.needsUpdate=!0,a}function hn(s,t){const e=s/2,o=t/2,n=new Float32Array([-e,-o,0,e,-o,0,e,o,0,-e,o,0,0,-o,-e,0,-o,e,0,o,e,0,o,-e]),i=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0]),a=new Float32Array([0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1]),l=[0,1,2,0,2,3,0,2,1,0,3,2,4,5,6,4,6,7,4,6,5,4,7,6],r=new ct;return r.setAttribute("position",new q(n,3)),r.setAttribute("normal",new q(i,3)),r.setAttribute("uv",new q(a,2)),r.setIndex(l),r}class un{constructor(){this.count=0,this.driftTimer=0,this.driftInterval=1.5,this.capacity=sn;const t=hn(2.8,3.4),e=ln(),o=cn();this.material=new mt({uniforms:{uMap:{value:e},uAlphaMap:{value:o},uLightDir:{value:new w(-.3,.8,.4).normalize()},uSSS:{value:.45},uSSSColor:{value:new H("#ff8aaa")}},vertexShader:`
437
437
  varying vec2 vUv;
438
438
  varying vec3 vWorldNormal;
439
439
  varying vec3 vWorldPos;
@@ -478,7 +478,7 @@ void main() {
478
478
 
479
479
  gl_FragColor = vec4(color, 1.0);
480
480
  }
481
- `,side:vt,depthWrite:!0,transparent:!1}),this.mesh=new Pe(t,this.material,this.capacity),this.mesh.count=0,this.mesh.renderOrder=6,this.mesh.frustumCulled=!1,this.states=new Float32Array(this.capacity),this.velocities=new Float32Array(this.capacity*3),this.positions=new Float32Array(this.capacity*3),this.anchorPositions=new Float32Array(this.capacity*3),this.phases=new Float32Array(this.capacity),this.groundTimers=new Float32Array(this.capacity),this.glowGroup=new $t,this.glowGroup.renderOrder=7}allocateCluster(t){const e=16+Math.floor(Y(`count:${t.path}`)*12),o=[],n=t.direction.clone().normalize(),i=Math.abs(n.y)>.9?new w(1,0,0):new w(0,1,0),a=new w().crossVectors(n,i).normalize(),l=new w().crossVectors(a,n).normalize();for(let r=0;r<e&&!(this.count>=this.capacity);r++){const c=this.count++;o.push(c);const h=r/e*Math.PI*2+Y(`${t.path}:a:${r}`)*.7,m=t.scale*(.6+Y(`${t.path}:r:${r}`)*1.2),d=Math.cos(h)*m,p=Math.sin(h)*m,f=(Y(`${t.path}:y:${r}`)-.5)*t.scale*.6,y=t.position.clone().add(a.clone().multiplyScalar(d)).add(l.clone().multiplyScalar(p)).add(n.clone().multiplyScalar(f));this.anchorPositions[c*3]=y.x,this.anchorPositions[c*3+1]=y.y,this.anchorPositions[c*3+2]=y.z,this.positions[c*3]=y.x,this.positions[c*3+1]=y.y,this.positions[c*3+2]=y.z,this.phases[c]=Y(`${t.path}:phase:${r}`),this.states[c]=Ct,this.groundTimers[c]=0;const g=t.scale*(.8+Y(`${t.path}:s:${r}`)*.7),v=new qt,M=(Y(`${t.path}:rx:${r}`)-.5)*Math.PI*.9,u=Y(`${t.path}:ry:${r}`)*Math.PI*2,C=(Y(`${t.path}:rz:${r}`)-.5)*Math.PI*.7,b=new st().setFromEuler(new gt(M,u,C));v.makeRotationFromQuaternion(b),v.scale(new w(g,g,g)),v.setPosition(y),this.mesh.setMatrixAt(c,v)}return this.mesh.instanceMatrix.needsUpdate=!0,o}detach(t,e){for(const o of t)o>=this.count||(this.states[o]=on,this.velocities[o*3]=e.x+(Math.random()-.5)*2,this.velocities[o*3+1]=e.y+Math.random()*3,this.velocities[o*3+2]=e.z+(Math.random()-.5)*2,this.groundTimers[o]=0)}setWilt(t,e){}update(t,e,o){const n=new qt,i=new st,a=new gt;let l=!1;for(let r=0;r<this.count;r++){if(this.states[r]===Ct){const h=this.phases[r],m=Math.sin(e*1.4+h*6.28)*o.effectiveStrength*.6,d=Math.sin(e*2.1+h*3.14)*o.effectiveStrength*.15,p=Math.cos(e*.9+h*4.71)*o.effectiveStrength*.4,f=this.anchorPositions[r*3],y=this.anchorPositions[r*3+1],g=this.anchorPositions[r*3+2];o.effectiveStrength>.05&&(this.mesh.getMatrixAt(r,n),n.setPosition(f+m,y+d,g+p),this.mesh.setMatrixAt(r,n),l=!0);continue}this.velocities[r*3]=this.velocities[r*3]*.98+o.directionX*o.effectiveStrength*t*3,this.velocities[r*3+1]=Math.max(this.velocities[r*3+1]+en*t*.3,-4),this.velocities[r*3+2]=this.velocities[r*3+2]*.98+o.directionZ*o.effectiveStrength*t*3,this.positions[r*3]+=this.velocities[r*3]*t,this.positions[r*3+1]+=this.velocities[r*3+1]*t,this.positions[r*3+2]+=this.velocities[r*3+2]*t,this.positions[r*3+1]<pe&&(this.positions[r*3+1]=pe,this.velocities[r*3]=0,this.velocities[r*3+1]=0,this.velocities[r*3+2]=0,this.groundTimers[r]+=t,this.groundTimers[r]>5&&(this.states[r]=Ct,this.positions[r*3]=this.anchorPositions[r*3],this.positions[r*3+1]=this.anchorPositions[r*3+1],this.positions[r*3+2]=this.anchorPositions[r*3+2],this.groundTimers[r]=0));const c=e*2+this.phases[r]*10;a.set(c*.7,c,c*.3),i.setFromEuler(a),n.makeRotationFromQuaternion(i),n.scale(new w(.5,.5,.5)),n.setPosition(this.positions[r*3],this.positions[r*3+1],this.positions[r*3+2]),this.mesh.setMatrixAt(r,n),l=!0}l&&(this.mesh.instanceMatrix.needsUpdate=!0),this.mesh.count=this.count}ambientDrift(t){if(this.driftTimer+=t,this.driftTimer<this.driftInterval||this.count===0)return;this.driftTimer=0,this.driftInterval=.8+Math.random()*2;const e=1+Math.floor(Math.random()*4),o=[];for(let i=0;i<this.count&&o.length<e*5;i++)this.states[i]===Ct&&o.push(i);if(o.length===0)return;const n=[];for(let i=0;i<e&&o.length>0;i++){const a=Math.floor(Math.random()*o.length);n.push(o.splice(a,1)[0])}this.detach(n,new w(0,.5,0))}reset(){for(this.count=0,this.mesh.count=0;this.glowGroup.children.length;){const t=this.glowGroup.children[0];this.glowGroup.remove(t),t instanceof Ot&&t.material.dispose()}}dispose(){var t,e,o,n;this.mesh.geometry.dispose(),(e=(t=this.material.uniforms.uMap)==null?void 0:t.value)==null||e.dispose(),(n=(o=this.material.uniforms.uAlphaMap)==null?void 0:o.value)==null||n.dispose(),this.material.dispose(),this.reset()}}function ln(){let s=0,t=0;for(;s===0;)s=Math.random();for(;t===0;)t=Math.random();return Math.sqrt(-2*Math.log(s))*Math.cos(2*Math.PI*t)}function fe(s,t,e,o){const n=s+ln()*t;return Math.max(e,Math.min(o,n))}function cn(){const t=document.createElement("canvas");t.width=64,t.height=64;const e=t.getContext("2d");e.clearRect(0,0,64,64);const o=64/2,n=64/2,i=11;for(let r=0;r<5;r++){const c=(r*72-90)*Math.PI/180;e.save(),e.translate(o,n),e.rotate(c),e.beginPath(),e.moveTo(0,0),e.bezierCurveTo(-i*.5,-19*.3,-i,-19*.7,-2.5,-19),e.quadraticCurveTo(0,-19+3.5,2.5,-19),e.bezierCurveTo(i,-19*.7,i*.5,-19*.3,0,0),e.closePath();const h=e.createLinearGradient(0,0,0,-19);h.addColorStop(0,"rgba(252, 175, 195, 1)"),h.addColorStop(.4,"rgba(255, 205, 215, 1)"),h.addColorStop(1,"rgba(255, 238, 242, 1)"),e.fillStyle=h,e.fill(),e.beginPath(),e.moveTo(0,-3),e.lineTo(0,-14),e.strokeStyle="rgba(240, 150, 175, 0.25)",e.lineWidth=.6,e.stroke(),e.restore()}e.beginPath(),e.arc(o,n,4.5,0,Math.PI*2);const a=e.createRadialGradient(o,n,0,o,n,4.5);a.addColorStop(0,"rgba(255, 240, 160, 1)"),a.addColorStop(1,"rgba(230, 210, 120, 1)"),e.fillStyle=a,e.fill();for(let r=0;r<7;r++){const c=r/7*Math.PI*2,h=6;e.beginPath(),e.arc(o+Math.cos(c)*h,n+Math.sin(c)*h,.9,0,Math.PI*2),e.fillStyle="rgba(210, 180, 80, 0.7)",e.fill()}const l=new it(t);return l.needsUpdate=!0,l}const pt=[{r:1,g:.9,b:.92,weight:35},{r:1,g:.88,b:.89,weight:20},{r:.96,g:.78,b:.83,weight:15},{r:.92,g:.65,b:.72,weight:8},{r:.88,g:.55,b:.65,weight:3},{r:1,g:.82,b:.78,weight:8},{r:1,g:.78,b:.72,weight:4},{r:1,g:.98,b:.98,weight:5},{r:1,g:.96,b:.93,weight:2}],hn=pt.reduce((s,t)=>s+t.weight,0),Wt=[];{let s=0;for(const t of pt)s+=t.weight,Wt.push(s)}function un(){const s=Math.random()*hn;for(let t=0;t<Wt.length;t++)if(s<Wt[t])return pt[t];return pt[pt.length-1]}const ft=[{lo:.3,hi:.5,weight:15},{lo:.6,hi:1,weight:35},{lo:1,hi:1.5,weight:30},{lo:1.5,hi:2,weight:14},{lo:2,hi:2.5,weight:6}],dn=ft.reduce((s,t)=>s+t.weight,0),Gt=[];{let s=0;for(const t of ft)s+=t.weight,Gt.push(s)}function pn(){const s=Math.random()*dn;for(let e=0;e<Gt.length;e++)if(s<Gt[e]){const o=ft[e];return o.lo+Math.random()*(o.hi-o.lo)}const t=ft[ft.length-1];return t.lo+Math.random()*(t.hi-t.lo)}const Pt=5e4;class fn{constructor(){this.count=0,this.dummy=new Xe,this._tempDir=new w;const t=new De(1,1),e=cn(),o=new Lt({map:e,alphaTest:.15,transparent:!0,side:vt,roughness:.55,metalness:0,depthWrite:!0});this.mesh=new Pe(t,o,Pt),this.mesh.count=0,this.mesh.castShadow=!0,this.mesh.receiveShadow=!0,this.mesh.frustumCulled=!1;const n=new Float32Array(Pt*3);for(let i=0;i<Pt;i++)n[i*3]=1,n[i*3+1]=1,n[i*3+2]=1;this.mesh.instanceColor=new Qe(n,3)}addCluster(t,e,o){let n=0;for(let i=0;i<o&&!(this.count>=Pt);i++){const a=Math.abs(fe(0,.55,-3.5,3.5)),l=Math.random()*Math.PI*2,r=Math.cos(l)*a,c=Math.sin(l)*a,h=fe(0,.35,-2,2);this.dummy.position.set(t.x+r,t.y+h,t.z+c),this._tempDir.copy(e),this._tempDir.x+=(Math.random()-.5)*1.6,this._tempDir.y+=(Math.random()-.5)*1.4,this._tempDir.z+=(Math.random()-.5)*1.6,this._tempDir.normalize(),this.dummy.quaternion.setFromUnitVectors(new w(0,0,1),this._tempDir);const m=new st().setFromAxisAngle(this._tempDir,Math.random()*Math.PI*2);this.dummy.quaternion.premultiply(m);const d=new w(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),p=(Math.random()-.5)*Math.PI*.5,f=new st().setFromAxisAngle(d,p);this.dummy.quaternion.premultiply(f);const y=pn();this.dummy.scale.setScalar(y),this.dummy.updateMatrix(),this.mesh.setMatrixAt(this.count,this.dummy.matrix);const g=un(),v=.04;let M=g.r+(Math.random()-.5)*v,u=g.g+(Math.random()-.5)*v,C=g.b+(Math.random()-.5)*v;const b=Math.random()<.25?.6+Math.random()*.2:.85+Math.random()*.15;M*=b,u*=b,C*=b,M=Math.max(0,Math.min(1,M)),u=Math.max(0,Math.min(1,u)),C=Math.max(0,Math.min(1,C)),this.mesh.setColorAt(this.count,new H(M,u,C)),this.count++,n++}return this.mesh.count=this.count,this.mesh.instanceMatrix.needsUpdate=!0,this.mesh.instanceColor&&(this.mesh.instanceColor.needsUpdate=!0),n}reset(){this.count=0,this.mesh.count=0,this.mesh.instanceMatrix.needsUpdate=!0,this.mesh.instanceColor&&(this.mesh.instanceColor.needsUpdate=!0)}get flowerCount(){return this.count}dispose(){this.mesh.geometry.dispose();const t=this.mesh.material;t.map&&t.map.dispose(),t.dispose()}}function Q(s,t,e){return Math.min(e,Math.max(t,s))}function Re(s){return 1-Math.pow(1-s,3)}function Ue(s,t){if(s.length===0)return null;const e=[],o=t==="outward"?s:[...s].reverse();for(const n of o){const i=t==="outward"?n.spec.curvePoints:[...n.spec.curvePoints].reverse();for(const a of i){const l=e[e.length-1];(!l||l.distanceToSquared(a)>.01)&&e.push(a.clone())}}return e.length<2?null:new Me(e,!1,"catmullrom",.45)}function Fe(s,t=20){const e=new Float32Array(t*3),o=new ct;o.setAttribute("position",new q(e,3));const n=new _e({color:s,size:1.2,transparent:!0,opacity:.7,blending:kt,depthWrite:!1,sizeAttenuation:!0}),i=new Te(o,n);return i.renderOrder=8,{points:i,material:n,positions:e}}function tt(s,t,e=!1){for(const o of s)o.pulse=Math.max(o.pulse,1),o.pulseColor.copy(t),e&&(o.contamination=Math.min(1,o.contamination+.6))}function Ee(s,t){const e=s.length;if(e===0)return{branchIndex:0,localT:0};const o=t*e,n=Math.min(Math.floor(o),e-1),i=Q(o-n,0,1);return{branchIndex:n,localT:i}}const mn=1.2,gn=(s,t)=>{const{branchChain:e,color:o}=s,n=Ue(e,"inward");if(!n)return{tick:()=>!1,dispose:()=>{}};tt(e,o);const i=Fe(o,20);t.add(i.points);let a=0,l=!1;const r={tick(c){var f,y;a+=c;const h=Q(a/mn,0,1),m=Re(h),{branchIndex:d,localT:p}=Ee(e,m);for(let g=0;g<e.length;g++){const v=e[g];g===d?(v.material.uniforms.uSignalPos.value=1-p,v.material.uniforms.uSignalIntensity.value=(1-h)*s.intensity,v.material.uniforms.uSignalColor.value.copy(o)):g<d?v.material.uniforms.uSignalIntensity.value*=.9:v.material.uniforms.uSignalIntensity.value=0}for(let g=0;g<20;g++){const v=Math.max(0,m-g*.015),M=n.getPointAt(v);i.positions[g*3]=M.x,i.positions[g*3+1]=M.y,i.positions[g*3+2]=M.z}return i.points.geometry.attributes.position.needsUpdate=!0,i.material.opacity=.7*(1-h*.7),h>.85&&!l&&(l=!0,(f=r.onReachTarget)==null||f.call(r)),h>=1?((y=r.onComplete)==null||y.call(r),!1):!0},onReachTarget(){},dispose(){t.remove(i.points),i.points.geometry.dispose(),i.material.dispose();for(const c of e)c.material.uniforms.uSignalPos.value=-1,c.material.uniforms.uSignalIntensity.value=0}};return r},vn=1,me=(s,t)=>{const{branchChain:e,color:o}=s,n=Ue(e,"outward");if(!n)return{tick:()=>!1,dispose:()=>{}};tt(e,o);const i=Fe(o,20);t.add(i.points);let a=0,l=!1;const r={tick(c){var f,y;a+=c;const h=Q(a/vn,0,1),m=Re(h),{branchIndex:d,localT:p}=Ee(e,m);for(let g=0;g<e.length;g++){const v=e[g];g===d?(v.material.uniforms.uSignalPos.value=p,v.material.uniforms.uSignalIntensity.value=(1-h)*s.intensity,v.material.uniforms.uSignalColor.value.copy(o)):g<d?v.material.uniforms.uSignalIntensity.value*=.9:v.material.uniforms.uSignalIntensity.value=0}for(let g=0;g<20;g++){const v=Math.max(0,m-g*.015),M=n.getPointAt(v);i.positions[g*3]=M.x,i.positions[g*3+1]=M.y,i.positions[g*3+2]=M.z}return i.points.geometry.attributes.position.needsUpdate=!0,i.material.opacity=.7*(1-h*.7),h>.85&&!l&&(l=!0,(f=r.onReachTarget)==null||f.call(r)),h>=1?((y=r.onComplete)==null||y.call(r),!1):!0},onReachTarget(){},dispose(){t.remove(i.points),i.points.geometry.dispose(),i.material.dispose();for(const c of e)c.material.uniforms.uSignalPos.value=-1,c.material.uniforms.uSignalIntensity.value=0}};return r},yn=1.5,xn=(s,t,e,o)=>{const{branchChain:n,color:i,targetPetalIds:a}=s;if(tt(n,i),o.spike(1,.8),a.length>0){const c=Math.min(3,a.length),h=a.slice(0,c);e.detach(h,{x:0,y:5,z:0})}let l=0;return{tick(c){l+=c;const h=Q(l/yn,0,1),m=Math.sin(l*30)*(1-h)*.3;for(const d of n)d.pulse=Math.max(d.pulse,(1-h)*.8+m);return h<1},dispose(){}}},bn=.8,ge=(s,t)=>{const{branchChain:e,color:o,targetBlossom:n}=s;tt(e,o);let i=null,a=null;n&&(a=new ze({color:o.clone(),transparent:!0,opacity:.8,blending:kt,depthWrite:!1}),i=new Ot(a),i.position.copy(n.position),i.scale.setScalar(3),t.add(i));let l=0;return{tick(r){l+=r;const c=Q(l/bn,0,1);return i&&a&&(i.scale.setScalar(3+Math.sin(l*20)*1.5*(1-c)),a.opacity=.8*(1-c)),c<1},dispose(){i&&(t.remove(i),a==null||a.dispose())}}},wn=3,Sn=(s,t,e)=>{const{branchChain:o,color:n,targetPetalIds:i}=s;tt(o,n,!0),i.length>0&&e.setWilt(i,.5);let a=0;return{tick(l){a+=l;const r=Q(a/wn,0,1);for(const c of o)c.contamination=Math.max(c.contamination,(1-r)*.6);return r<1},dispose(){}}},Mn=2,Cn=s=>{const{branchChain:t,color:e}=s;tt(t,e);let o=0;return{tick(n){o+=n;const i=Q(o/Mn,0,1);for(const a of t)a.pulse=Math.max(a.pulse,(1-i)*.9);return i<1},dispose(){}}},Pn=2.5,Dn=(s,t,e)=>{const{branchChain:o,color:n,targetPetalIds:i}=s;if(tt(o,n),i.length>0){const l=new w((Math.random()-.5)*6,8+Math.random()*4,(Math.random()-.5)*6);e.detach(i,l)}let a=0;return{tick(l){a+=l;const r=Q(a/Pn,0,1);for(const c of o)c.pulse=Math.max(c.pulse,(1-r)*.7),c.contamination=Math.max(c.contamination,(1-r)*.4);return r<1},dispose(){}}},_n=10,Tn=(s,t)=>{const{color:e}=s,o=new Lt({color:e.clone(),emissive:e.clone(),emissiveIntensity:.6,roughness:.2,transparent:!0,opacity:.8}),n=new at(new Ye(1.5,2),o);t.add(n);const i=new Ke({color:e.clone(),transparent:!0,opacity:.25,blending:kt,depthWrite:!1}),a=new ct().setFromPoints([new w,new w]),l=new Je(a,i);t.add(l);let r=0;const c=14+Math.random()*8,h=.8+Math.random()*.6;let m=Math.random()*Math.PI*2;return{tick(d){r+=d;const p=Q(r/_n,0,1),f=1-p;m+=d*h;const y=Math.cos(m)*c,g=10+Math.sin(m*1.6)*4,v=Math.sin(m)*c;return n.position.set(y,g,v),n.scale.setScalar(.8+f*.8),o.opacity=.8*f,o.emissiveIntensity=.3+f*.5,a.setFromPoints([new w(0,0,0),new w(y,g,v)]),i.opacity=.2*f,p<1},dispose(){t.remove(n),t.remove(l),n.geometry.dispose(),o.dispose(),a.dispose(),i.dispose()}}},zn=2,An=s=>{const{branchChain:t,color:e}=s;tt(t,e);let o=0;return{tick(n){o+=n;const i=Q(o/zn,0,1);for(const a of t)a.pulse=Math.max(a.pulse,(1-i)*.7);return i<1},dispose(){}}},ve={Read:gn,Edit:me,Write:me,Bash:xn,Grep:ge,Glob:ge,WebFetch:Sn,UserPromptSubmit:Cn,PostToolUseFailure:Dn,SubagentStart:Tn,SessionStart:An};function ye(s,...t){const e=ve[s]??ve.Read;return e?e(...t):{tick:()=>!1,dispose:()=>{}}}const kn={Read:"#d4a574",Edit:"#7ec8e3",Write:"#7dd3fc",Bash:"#f59e0b",Grep:"#c084fc",Glob:"#a78bfa",WebFetch:"#fb7185",Notification:"#34d399",PermissionRequest:"#fbbf24",UserPromptSubmit:"#ffd4a8",SessionStart:"#e8c4a0",SubagentStart:"#d8b4fe",PostToolUseFailure:"#f87171"},In=new Set(["Read","Grep","Glob"]);function Rn(s){return kn[s.tool_name||s.hook_event_name||""]||"#e8c4a0"}function Un(s){return s.hook_event_name==="PreToolUse"||s.hook_event_name==="PostToolUseFailure"||s.hook_event_name==="UserPromptSubmit"||s.hook_event_name==="SessionStart"||s.hook_event_name==="SubagentStart"||s.hook_event_name==="Notification"||s.hook_event_name==="PermissionRequest"}class Fn{constructor(t,e){this.petalSystem=t,this.windField=e,this.activeEffects=[]}route(t,e){if(!Un(t))return;const o=t.tool_name||"",n=new H(Rn(t));if(t.hook_event_name==="UserPromptSubmit"||t.hook_event_name==="SessionStart"){e.boost=Math.min(1.8,e.boost+.45),this.routeFullTree(e,n,o||t.hook_event_name||"SessionStart");return}if(t.hook_event_name==="SubagentStart"){e.boost=Math.min(1.4,e.boost+.25),this.routeFullTree(e,n,"SubagentStart");return}if(t.hook_event_name==="Notification"||t.hook_event_name==="PermissionRequest"){e.boost=Math.min(1.2,e.boost+.15);return}e.boost=Math.min(1.4,e.boost+.25);const i=t.tool_input??{},a=Kt(e.rootPath,i.file_path)||Kt(e.rootPath,i.path);let l=Uo(e.layout,a);if(l||(l=te(e.layout,`${t.id}:fallback`,1)[0]||null),!l)return;const r=e.layout.nodes.get(l),c=(r==null?void 0:r.type)==="folder"?Io(e.layout,l,3):[l],h=In.has(o)?"inward":"outward";for(const m of c){const p=Jt(e.layout,m).map(u=>e.branches.get(u)).filter(u=>u!==void 0);if(p.length===0)continue;const f=e.layout.blossomAnchors.get(m)??null,y=e.petalInstanceIds,g={branchChain:p,targetBlossom:f,targetPetalIds:y,direction:h,color:n,intensity:1},v=t.hook_event_name==="PostToolUseFailure"?"PostToolUseFailure":o,M=ye(v,g,e.group,this.petalSystem,this.windField);this.activeEffects.push(M)}}routeFullTree(t,e,o){const n=te(t.layout,`${t.id}:${Date.now()}`,4);for(const i of n){const l=Jt(t.layout,i).map(m=>t.branches.get(m)).filter(m=>m!==void 0);if(l.length===0)continue;const r=t.layout.blossomAnchors.get(i)??null,h=ye(o,{branchChain:l,targetBlossom:r,targetPetalIds:[],direction:"outward",color:e,intensity:.8},t.group,this.petalSystem,this.windField);this.activeEffects.push(h)}}update(t,e){this.activeEffects=this.activeEffects.filter(o=>{const n=o.tick(t,e);return n||o.dispose(),n})}dispose(){for(const t of this.activeEffects)t.dispose();this.activeEffects=[]}}class En{constructor(t){}createPulse(t,e){}tick(t){}dispose(){}}class jn{constructor(){this.directionX=1,this.directionZ=0,this.strength=.2,this.gustStrength=0,this.gustTimer=8,this.turbulence=0,this.phase=0,this.baseAngle=0,this.gustRamp=0,this.gustHold=0,this.gustDecay=0,this.gustActive=!1}update(t){this.baseAngle+=t*(Math.PI*2/30),this.directionX=Math.cos(this.baseAngle),this.directionZ=Math.sin(this.baseAngle),this.strength=.2+.25*(.5+.5*Math.sin(this.phase*(Math.PI*2/8))),this.phase+=t,this.turbulence=.5+.5*Math.sin(this.phase*7.3+Math.cos(this.phase*3.1)*2),this.turbulence*=.15,this.gustActive||(this.gustTimer-=t,this.gustTimer<=0&&(this.gustActive=!0,this.gustRamp=.5,this.gustHold=1+Math.random(),this.gustDecay=1.5,this.gustStrength=0)),this.gustActive&&(this.gustRamp>0?(this.gustRamp-=t,this.gustStrength=Math.min(1,this.gustStrength+t*2)):this.gustHold>0?(this.gustHold-=t,this.gustStrength=.7+.3*Math.sin(this.phase*4)):this.gustDecay>0?(this.gustDecay-=t,this.gustStrength=Math.max(0,this.gustStrength-t*.67)):(this.gustActive=!1,this.gustStrength=0,this.gustTimer=5+Math.random()*10))}get effectiveStrength(){return Math.min(1,this.strength+this.gustStrength*.6+this.turbulence*.1)}spike(t,e){this.gustStrength=Math.max(this.gustStrength,t),this.turbulence=Math.max(this.turbulence,e),this.gustActive=!0,this.gustRamp=0,this.gustHold=0,this.gustDecay=2}}function Nn(s){let t=2166136261;for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t=Math.imul(t,16777619);return(t>>>0)/4294967296}function jt(s,t,e){return Math.min(e,Math.max(t,s))}const $n={Read:"#d4a574",Edit:"#7ec8e3",Write:"#7dd3fc",Bash:"#f59e0b",Grep:"#c084fc",Glob:"#a78bfa",WebFetch:"#fb7185"};function Bn(s){return $n[s.tool_name||""]||"#e8a060"}function Wn(s,t){const e=[...s];for(let o=e.length-1;o>0;o--){const n=Math.floor(Math.random()*(o+1));[e[o],e[n]]=[e[n],e[o]]}return e.slice(0,t)}function Gn(){const t=document.createElement("canvas");t.width=256,t.height=256;const e=t.getContext("2d");e.fillStyle="rgb(128,128,255)",e.fillRect(0,0,256,256);const o=e.getImageData(0,0,256,256),n=o.data;for(let r=0;r<256;r++)for(let c=0;c<256;c++){const h=(r*256+c)*4,m=Math.sin(c/256*Math.PI*24)*.5+Math.sin(c/256*Math.PI*7+.8)*.25;n[h]=Math.round(128+m*30),n[h+1]=128,n[h+2]=255,n[h+3]=255}const a=(r=>{let c=r;return()=>(c=c*1664525+1013904223>>>0,c/4294967295)})(42);for(let r=0;r<12;r++){const c=Math.floor(a()*256),h=Math.floor(a()*256),m=Math.floor(20+a()*30),d=Math.floor(3+a()*5);for(let p=-d;p<=d;p++)for(let f=-m;f<=m;f++){const y=(c+f+256)%256,g=(h+p+256)%256,v=1-Math.sqrt((f/m)**2+(p/d)**2);if(v<=0)continue;const M=(g*256+y)*4,u=Math.sin(v*Math.PI)*40;n[M+1]=Math.min(255,Math.round(n[M+1]+u))}}e.putImageData(o,0,0);const l=new it(t);return l.wrapS=zt,l.wrapT=zt,l.repeat.set(2,4),l.needsUpdate=!0,l}let Nt=null;function On(){return Nt||(Nt=Gn()),Nt}function Ln(s,t=Date.now()){const e=Math.max(0,t-s.lastEventTime),o=jt(1-e/9e4,0,1),n=jt(Math.log1p(s.eventCount)/Math.log(24),0,1);return jt(.12+o*.56+n*.3,.08,1)}function Vn(s){return`${s.projectId}:${s.stats.totalNodes}:${s.stats.maxDepthReached}:${s.stats.truncated?"t":"f"}`}class Hn{constructor(t){this.container=t,this.colonies=new Map,this.windField=new jn,this.petalSystem=new an,this.flowerSystem=new fn,this.elapsed=0;const e=t.clientWidth,o=t.clientHeight;this.renderer=new to({antialias:!0,alpha:!1}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.renderer.setSize(e,o),this.renderer.outputColorSpace=eo,this.renderer.setClearColor("#0e0a08"),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=oo,t.appendChild(this.renderer.domElement),this.scene=new no,this.scene.fog=new so("#0e0a08",.003),this.camera=new io(38,e/o,.1,1600),this.camera.position.set(40,80,200),this.controls=new ro(this.camera,this.renderer.domElement),this.controls.enableDamping=!0,this.controls.dampingFactor=.06,this.controls.autoRotate=!0,this.controls.autoRotateSpeed=.15,this.controls.minDistance=60,this.controls.maxDistance=500,this.controls.target.set(0,40,0),this.composer=new ao(this.renderer),this.composer.addPass(new lo(this.scene,this.camera)),this.composer.addPass(new co(new ho(e,o),.4,.3,.75));const n=new xo(this.scene,this.camera,{focus:160,aperture:.001,maxblur:.002});this.composer.addPass(n),this.composer.addPass(Do()),this.composer.addPass(To()),this.composer.addPass(wo()),this.filmGrainPass=Mo(),this.composer.addPass(this.filmGrainPass),this.scene.add(new uo("#fff5f0",1));const i=new po("#ffeef5","#0a0606",1.8);i.position.set(0,200,0),this.scene.add(i);const a=new fo("#fff0e0",.8);a.position.set(-80,160,100),a.castShadow=!0,a.shadow.mapSize.width=1024,a.shadow.mapSize.height=1024,a.shadow.camera.near=10,a.shadow.camera.far=400,a.shadow.camera.left=-120,a.shadow.camera.right=120,a.shadow.camera.top=120,a.shadow.camera.bottom=-40,a.shadow.bias=-.002,a.shadow.radius=4,this.scene.add(a);const l=new Rt("#ffd0e0",.9,500,1.5);l.position.set(0,180,-80),this.scene.add(l);const r=new Rt("#ffb78e",.35,300,2);r.position.set(-100,20,60),this.scene.add(r);const c=new Rt("#ff8ab0",.3,250,2);c.position.set(90,60,-40),this.scene.add(c),this.skyMaterial=new mt({uniforms:{uTime:{value:0},uHeat:{value:0}},vertexShader:`
481
+ `,side:vt,depthWrite:!0,transparent:!1}),this.mesh=new _e(t,this.material,this.capacity),this.mesh.count=0,this.mesh.renderOrder=6,this.mesh.frustumCulled=!1,this.states=new Float32Array(this.capacity),this.velocities=new Float32Array(this.capacity*3),this.positions=new Float32Array(this.capacity*3),this.anchorPositions=new Float32Array(this.capacity*3),this.phases=new Float32Array(this.capacity),this.groundTimers=new Float32Array(this.capacity),this.glowGroup=new Bt,this.glowGroup.renderOrder=7}allocateCluster(t){const e=16+Math.floor(Y(`count:${t.path}`)*12),o=[],n=t.direction.clone().normalize(),i=Math.abs(n.y)>.9?new w(1,0,0):new w(0,1,0),a=new w().crossVectors(n,i).normalize(),l=new w().crossVectors(a,n).normalize();for(let r=0;r<e&&!(this.count>=this.capacity);r++){const c=this.count++;o.push(c);const h=r/e*Math.PI*2+Y(`${t.path}:a:${r}`)*.7,m=t.scale*(.6+Y(`${t.path}:r:${r}`)*1.2),d=Math.cos(h)*m,p=Math.sin(h)*m,f=(Y(`${t.path}:y:${r}`)-.5)*t.scale*.6,y=t.position.clone().add(a.clone().multiplyScalar(d)).add(l.clone().multiplyScalar(p)).add(n.clone().multiplyScalar(f));this.anchorPositions[c*3]=y.x,this.anchorPositions[c*3+1]=y.y,this.anchorPositions[c*3+2]=y.z,this.positions[c*3]=y.x,this.positions[c*3+1]=y.y,this.positions[c*3+2]=y.z,this.phases[c]=Y(`${t.path}:phase:${r}`),this.states[c]=Pt,this.groundTimers[c]=0;const g=t.scale*(.8+Y(`${t.path}:s:${r}`)*.7),v=new Zt,M=(Y(`${t.path}:rx:${r}`)-.5)*Math.PI*.9,u=Y(`${t.path}:ry:${r}`)*Math.PI*2,C=(Y(`${t.path}:rz:${r}`)-.5)*Math.PI*.7,b=new st().setFromEuler(new gt(M,u,C));v.makeRotationFromQuaternion(b),v.scale(new w(g,g,g)),v.setPosition(y),this.mesh.setMatrixAt(c,v)}return this.mesh.instanceMatrix.needsUpdate=!0,o}detach(t,e){for(const o of t)o>=this.count||(this.states[o]=an,this.velocities[o*3]=e.x+(Math.random()-.5)*2,this.velocities[o*3+1]=e.y+Math.random()*3,this.velocities[o*3+2]=e.z+(Math.random()-.5)*2,this.groundTimers[o]=0)}setWilt(t,e){}update(t,e,o){const n=new Zt,i=new st,a=new gt;let l=!1;for(let r=0;r<this.count;r++){if(this.states[r]===Pt){const h=this.phases[r],m=Math.sin(e*1.4+h*6.28)*o.effectiveStrength*.6,d=Math.sin(e*2.1+h*3.14)*o.effectiveStrength*.15,p=Math.cos(e*.9+h*4.71)*o.effectiveStrength*.4,f=this.anchorPositions[r*3],y=this.anchorPositions[r*3+1],g=this.anchorPositions[r*3+2];o.effectiveStrength>.05&&(this.mesh.getMatrixAt(r,n),n.setPosition(f+m,y+d,g+p),this.mesh.setMatrixAt(r,n),l=!0);continue}this.velocities[r*3]=this.velocities[r*3]*.98+o.directionX*o.effectiveStrength*t*3,this.velocities[r*3+1]=Math.max(this.velocities[r*3+1]+rn*t*.3,-4),this.velocities[r*3+2]=this.velocities[r*3+2]*.98+o.directionZ*o.effectiveStrength*t*3,this.positions[r*3]+=this.velocities[r*3]*t,this.positions[r*3+1]+=this.velocities[r*3+1]*t,this.positions[r*3+2]+=this.velocities[r*3+2]*t,this.positions[r*3+1]<me&&(this.positions[r*3+1]=me,this.velocities[r*3]=0,this.velocities[r*3+1]=0,this.velocities[r*3+2]=0,this.groundTimers[r]+=t,this.groundTimers[r]>5&&(this.states[r]=Pt,this.positions[r*3]=this.anchorPositions[r*3],this.positions[r*3+1]=this.anchorPositions[r*3+1],this.positions[r*3+2]=this.anchorPositions[r*3+2],this.groundTimers[r]=0));const c=e*2+this.phases[r]*10;a.set(c*.7,c,c*.3),i.setFromEuler(a),n.makeRotationFromQuaternion(i),n.scale(new w(.5,.5,.5)),n.setPosition(this.positions[r*3],this.positions[r*3+1],this.positions[r*3+2]),this.mesh.setMatrixAt(r,n),l=!0}l&&(this.mesh.instanceMatrix.needsUpdate=!0),this.mesh.count=this.count}ambientDrift(t){if(this.driftTimer+=t,this.driftTimer<this.driftInterval||this.count===0)return;this.driftTimer=0,this.driftInterval=.8+Math.random()*2;const e=1+Math.floor(Math.random()*4),o=[];for(let i=0;i<this.count&&o.length<e*5;i++)this.states[i]===Pt&&o.push(i);if(o.length===0)return;const n=[];for(let i=0;i<e&&o.length>0;i++){const a=Math.floor(Math.random()*o.length);n.push(o.splice(a,1)[0])}this.detach(n,new w(0,.5,0))}reset(){for(this.count=0,this.mesh.count=0;this.glowGroup.children.length;){const t=this.glowGroup.children[0];this.glowGroup.remove(t),t instanceof Lt&&t.material.dispose()}}dispose(){var t,e,o,n;this.mesh.geometry.dispose(),(e=(t=this.material.uniforms.uMap)==null?void 0:t.value)==null||e.dispose(),(n=(o=this.material.uniforms.uAlphaMap)==null?void 0:o.value)==null||n.dispose(),this.material.dispose(),this.reset()}}function dn(){let s=0,t=0;for(;s===0;)s=Math.random();for(;t===0;)t=Math.random();return Math.sqrt(-2*Math.log(s))*Math.cos(2*Math.PI*t)}function ge(s,t,e,o){const n=s+dn()*t;return Math.max(e,Math.min(o,n))}function pn(){const t=document.createElement("canvas");t.width=64,t.height=64;const e=t.getContext("2d");e.clearRect(0,0,64,64);const o=64/2,n=64/2,i=11;for(let r=0;r<5;r++){const c=(r*72-90)*Math.PI/180;e.save(),e.translate(o,n),e.rotate(c),e.beginPath(),e.moveTo(0,0),e.bezierCurveTo(-i*.5,-19*.3,-i,-19*.7,-2.5,-19),e.quadraticCurveTo(0,-19+3.5,2.5,-19),e.bezierCurveTo(i,-19*.7,i*.5,-19*.3,0,0),e.closePath();const h=e.createLinearGradient(0,0,0,-19);h.addColorStop(0,"rgba(252, 175, 195, 1)"),h.addColorStop(.4,"rgba(255, 205, 215, 1)"),h.addColorStop(1,"rgba(255, 238, 242, 1)"),e.fillStyle=h,e.fill(),e.beginPath(),e.moveTo(0,-3),e.lineTo(0,-14),e.strokeStyle="rgba(240, 150, 175, 0.25)",e.lineWidth=.6,e.stroke(),e.restore()}e.beginPath(),e.arc(o,n,4.5,0,Math.PI*2);const a=e.createRadialGradient(o,n,0,o,n,4.5);a.addColorStop(0,"rgba(255, 240, 160, 1)"),a.addColorStop(1,"rgba(230, 210, 120, 1)"),e.fillStyle=a,e.fill();for(let r=0;r<7;r++){const c=r/7*Math.PI*2,h=6;e.beginPath(),e.arc(o+Math.cos(c)*h,n+Math.sin(c)*h,.9,0,Math.PI*2),e.fillStyle="rgba(210, 180, 80, 0.7)",e.fill()}const l=new it(t);return l.needsUpdate=!0,l}const pt=[{r:1,g:.9,b:.92,weight:35},{r:1,g:.88,b:.89,weight:20},{r:.96,g:.78,b:.83,weight:15},{r:.92,g:.65,b:.72,weight:8},{r:.88,g:.55,b:.65,weight:3},{r:1,g:.82,b:.78,weight:8},{r:1,g:.78,b:.72,weight:4},{r:1,g:.98,b:.98,weight:5},{r:1,g:.96,b:.93,weight:2}],fn=pt.reduce((s,t)=>s+t.weight,0),Gt=[];{let s=0;for(const t of pt)s+=t.weight,Gt.push(s)}function mn(){const s=Math.random()*fn;for(let t=0;t<Gt.length;t++)if(s<Gt[t])return pt[t];return pt[pt.length-1]}const ft=[{lo:.3,hi:.5,weight:15},{lo:.6,hi:1,weight:35},{lo:1,hi:1.5,weight:30},{lo:1.5,hi:2,weight:14},{lo:2,hi:2.5,weight:6}],gn=ft.reduce((s,t)=>s+t.weight,0),Ot=[];{let s=0;for(const t of ft)s+=t.weight,Ot.push(s)}function vn(){const s=Math.random()*gn;for(let e=0;e<Ot.length;e++)if(s<Ot[e]){const o=ft[e];return o.lo+Math.random()*(o.hi-o.lo)}const t=ft[ft.length-1];return t.lo+Math.random()*(t.hi-t.lo)}const Dt=5e4;class yn{constructor(){this.count=0,this.dummy=new Ye,this._tempDir=new w;const t=new Te(1,1),e=pn(),o=new Vt({map:e,alphaTest:.15,transparent:!0,side:vt,roughness:.55,metalness:0,depthWrite:!0});this.mesh=new _e(t,o,Dt),this.mesh.count=0,this.mesh.castShadow=!0,this.mesh.receiveShadow=!0,this.mesh.frustumCulled=!1;const n=new Float32Array(Dt*3);for(let i=0;i<Dt;i++)n[i*3]=1,n[i*3+1]=1,n[i*3+2]=1;this.mesh.instanceColor=new Ke(n,3)}addCluster(t,e,o){let n=0;for(let i=0;i<o&&!(this.count>=Dt);i++){const a=Math.abs(ge(0,.55,-3.5,3.5)),l=Math.random()*Math.PI*2,r=Math.cos(l)*a,c=Math.sin(l)*a,h=ge(0,.35,-2,2);this.dummy.position.set(t.x+r,t.y+h,t.z+c),this._tempDir.copy(e),this._tempDir.x+=(Math.random()-.5)*1.6,this._tempDir.y+=(Math.random()-.5)*1.4,this._tempDir.z+=(Math.random()-.5)*1.6,this._tempDir.normalize(),this.dummy.quaternion.setFromUnitVectors(new w(0,0,1),this._tempDir);const m=new st().setFromAxisAngle(this._tempDir,Math.random()*Math.PI*2);this.dummy.quaternion.premultiply(m);const d=new w(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),p=(Math.random()-.5)*Math.PI*.5,f=new st().setFromAxisAngle(d,p);this.dummy.quaternion.premultiply(f);const y=vn();this.dummy.scale.setScalar(y),this.dummy.updateMatrix(),this.mesh.setMatrixAt(this.count,this.dummy.matrix);const g=mn(),v=.04;let M=g.r+(Math.random()-.5)*v,u=g.g+(Math.random()-.5)*v,C=g.b+(Math.random()-.5)*v;const b=Math.random()<.25?.6+Math.random()*.2:.85+Math.random()*.15;M*=b,u*=b,C*=b,M=Math.max(0,Math.min(1,M)),u=Math.max(0,Math.min(1,u)),C=Math.max(0,Math.min(1,C)),this.mesh.setColorAt(this.count,new H(M,u,C)),this.count++,n++}return this.mesh.count=this.count,this.mesh.instanceMatrix.needsUpdate=!0,this.mesh.instanceColor&&(this.mesh.instanceColor.needsUpdate=!0),n}reset(){this.count=0,this.mesh.count=0,this.mesh.instanceMatrix.needsUpdate=!0,this.mesh.instanceColor&&(this.mesh.instanceColor.needsUpdate=!0)}get flowerCount(){return this.count}dispose(){this.mesh.geometry.dispose();const t=this.mesh.material;t.map&&t.map.dispose(),t.dispose()}}function Q(s,t,e){return Math.min(e,Math.max(t,s))}function Fe(s){return 1-Math.pow(1-s,3)}function Ee(s,t){if(s.length===0)return null;const e=[],o=t==="outward"?s:[...s].reverse();for(const n of o){const i=t==="outward"?n.spec.curvePoints:[...n.spec.curvePoints].reverse();for(const a of i){const l=e[e.length-1];(!l||l.distanceToSquared(a)>.01)&&e.push(a.clone())}}return e.length<2?null:new Pe(e,!1,"catmullrom",.45)}function je(s,t=20){const e=new Float32Array(t*3),o=new ct;o.setAttribute("position",new q(e,3));const n=new ze({color:s,size:1.2,transparent:!0,opacity:.7,blending:It,depthWrite:!1,sizeAttenuation:!0}),i=new Ae(o,n);return i.renderOrder=8,{points:i,material:n,positions:e}}function tt(s,t,e=!1){for(const o of s)o.pulse=Math.max(o.pulse,1),o.pulseColor.copy(t),e&&(o.contamination=Math.min(1,o.contamination+.6))}function Ne(s,t){const e=s.length;if(e===0)return{branchIndex:0,localT:0};const o=t*e,n=Math.min(Math.floor(o),e-1),i=Q(o-n,0,1);return{branchIndex:n,localT:i}}const xn=1.2,bn=(s,t)=>{const{branchChain:e,color:o}=s,n=Ee(e,"inward");if(!n)return{tick:()=>!1,dispose:()=>{}};tt(e,o);const i=je(o,20);t.add(i.points);let a=0,l=!1;const r={tick(c){var f,y;a+=c;const h=Q(a/xn,0,1),m=Fe(h),{branchIndex:d,localT:p}=Ne(e,m);for(let g=0;g<e.length;g++){const v=e[g];g===d?(v.material.uniforms.uSignalPos.value=1-p,v.material.uniforms.uSignalIntensity.value=(1-h)*s.intensity,v.material.uniforms.uSignalColor.value.copy(o)):g<d?v.material.uniforms.uSignalIntensity.value*=.9:v.material.uniforms.uSignalIntensity.value=0}for(let g=0;g<20;g++){const v=Math.max(0,m-g*.015),M=n.getPointAt(v);i.positions[g*3]=M.x,i.positions[g*3+1]=M.y,i.positions[g*3+2]=M.z}return i.points.geometry.attributes.position.needsUpdate=!0,i.material.opacity=.7*(1-h*.7),h>.85&&!l&&(l=!0,(f=r.onReachTarget)==null||f.call(r)),h>=1?((y=r.onComplete)==null||y.call(r),!1):!0},onReachTarget(){},dispose(){t.remove(i.points),i.points.geometry.dispose(),i.material.dispose();for(const c of e)c.material.uniforms.uSignalPos.value=-1,c.material.uniforms.uSignalIntensity.value=0}};return r},wn=1,ve=(s,t)=>{const{branchChain:e,color:o}=s,n=Ee(e,"outward");if(!n)return{tick:()=>!1,dispose:()=>{}};tt(e,o);const i=je(o,20);t.add(i.points);let a=0,l=!1;const r={tick(c){var f,y;a+=c;const h=Q(a/wn,0,1),m=Fe(h),{branchIndex:d,localT:p}=Ne(e,m);for(let g=0;g<e.length;g++){const v=e[g];g===d?(v.material.uniforms.uSignalPos.value=p,v.material.uniforms.uSignalIntensity.value=(1-h)*s.intensity,v.material.uniforms.uSignalColor.value.copy(o)):g<d?v.material.uniforms.uSignalIntensity.value*=.9:v.material.uniforms.uSignalIntensity.value=0}for(let g=0;g<20;g++){const v=Math.max(0,m-g*.015),M=n.getPointAt(v);i.positions[g*3]=M.x,i.positions[g*3+1]=M.y,i.positions[g*3+2]=M.z}return i.points.geometry.attributes.position.needsUpdate=!0,i.material.opacity=.7*(1-h*.7),h>.85&&!l&&(l=!0,(f=r.onReachTarget)==null||f.call(r)),h>=1?((y=r.onComplete)==null||y.call(r),!1):!0},onReachTarget(){},dispose(){t.remove(i.points),i.points.geometry.dispose(),i.material.dispose();for(const c of e)c.material.uniforms.uSignalPos.value=-1,c.material.uniforms.uSignalIntensity.value=0}};return r},Sn=1.5,Mn=(s,t,e,o)=>{const{branchChain:n,color:i,targetPetalIds:a}=s;if(tt(n,i),o.spike(1,.8),a.length>0){const c=Math.min(3,a.length),h=a.slice(0,c);e.detach(h,{x:0,y:5,z:0})}let l=0;return{tick(c){l+=c;const h=Q(l/Sn,0,1),m=Math.sin(l*30)*(1-h)*.3;for(const d of n)d.pulse=Math.max(d.pulse,(1-h)*.8+m);return h<1},dispose(){}}},Cn=.8,ye=(s,t)=>{const{branchChain:e,color:o,targetBlossom:n}=s;tt(e,o);let i=null,a=null;n&&(a=new ke({color:o.clone(),transparent:!0,opacity:.8,blending:It,depthWrite:!1}),i=new Lt(a),i.position.copy(n.position),i.scale.setScalar(3),t.add(i));let l=0;return{tick(r){l+=r;const c=Q(l/Cn,0,1);return i&&a&&(i.scale.setScalar(3+Math.sin(l*20)*1.5*(1-c)),a.opacity=.8*(1-c)),c<1},dispose(){i&&(t.remove(i),a==null||a.dispose())}}},Pn=3,Dn=(s,t,e)=>{const{branchChain:o,color:n,targetPetalIds:i}=s;tt(o,n,!0),i.length>0&&e.setWilt(i,.5);let a=0;return{tick(l){a+=l;const r=Q(a/Pn,0,1);for(const c of o)c.contamination=Math.max(c.contamination,(1-r)*.6);return r<1},dispose(){}}},_n=2,Tn=s=>{const{branchChain:t,color:e}=s;tt(t,e);let o=0;return{tick(n){o+=n;const i=Q(o/_n,0,1);for(const a of t)a.pulse=Math.max(a.pulse,(1-i)*.9);return i<1},dispose(){}}},zn=2.5,An=(s,t,e)=>{const{branchChain:o,color:n,targetPetalIds:i}=s;if(tt(o,n),i.length>0){const l=new w((Math.random()-.5)*6,8+Math.random()*4,(Math.random()-.5)*6);e.detach(i,l)}let a=0;return{tick(l){a+=l;const r=Q(a/zn,0,1);for(const c of o)c.pulse=Math.max(c.pulse,(1-r)*.7),c.contamination=Math.max(c.contamination,(1-r)*.4);return r<1},dispose(){}}},kn=10,In=(s,t)=>{const{color:e}=s,o=new Vt({color:e.clone(),emissive:e.clone(),emissiveIntensity:.6,roughness:.2,transparent:!0,opacity:.8}),n=new at(new Je(1.5,2),o);t.add(n);const i=new to({color:e.clone(),transparent:!0,opacity:.25,blending:It,depthWrite:!1}),a=new ct().setFromPoints([new w,new w]),l=new eo(a,i);t.add(l);let r=0;const c=14+Math.random()*8,h=.8+Math.random()*.6;let m=Math.random()*Math.PI*2;return{tick(d){r+=d;const p=Q(r/kn,0,1),f=1-p;m+=d*h;const y=Math.cos(m)*c,g=10+Math.sin(m*1.6)*4,v=Math.sin(m)*c;return n.position.set(y,g,v),n.scale.setScalar(.8+f*.8),o.opacity=.8*f,o.emissiveIntensity=.3+f*.5,a.setFromPoints([new w(0,0,0),new w(y,g,v)]),i.opacity=.2*f,p<1},dispose(){t.remove(n),t.remove(l),n.geometry.dispose(),o.dispose(),a.dispose(),i.dispose()}}},Rn=2,Un=s=>{const{branchChain:t,color:e}=s;tt(t,e);let o=0;return{tick(n){o+=n;const i=Q(o/Rn,0,1);for(const a of t)a.pulse=Math.max(a.pulse,(1-i)*.7);return i<1},dispose(){}}},xe={Read:bn,Edit:ve,Write:ve,Bash:Mn,Grep:ye,Glob:ye,WebFetch:Dn,UserPromptSubmit:Tn,PostToolUseFailure:An,SubagentStart:In,SessionStart:Un};function be(s,...t){const e=xe[s]??xe.Read;return e?e(...t):{tick:()=>!1,dispose:()=>{}}}const Fn={Read:"#d4a574",Edit:"#7ec8e3",Write:"#7dd3fc",Bash:"#f59e0b",Grep:"#c084fc",Glob:"#a78bfa",WebFetch:"#fb7185",Notification:"#34d399",PermissionRequest:"#fbbf24",UserPromptSubmit:"#ffd4a8",SessionStart:"#e8c4a0",SubagentStart:"#d8b4fe",PostToolUseFailure:"#f87171"},En=new Set(["Read","Grep","Glob"]);function jn(s){return Fn[s.tool_name||s.hook_event_name||""]||"#e8c4a0"}function Nn(s){return s.hook_event_name==="PreToolUse"||s.hook_event_name==="PostToolUseFailure"||s.hook_event_name==="UserPromptSubmit"||s.hook_event_name==="SessionStart"||s.hook_event_name==="SubagentStart"||s.hook_event_name==="Notification"||s.hook_event_name==="PermissionRequest"}class $n{constructor(t,e){this.petalSystem=t,this.windField=e,this.activeEffects=[]}route(t,e){if(!Nn(t))return;const o=t.tool_name||"",n=new H(jn(t));if(t.hook_event_name==="UserPromptSubmit"||t.hook_event_name==="SessionStart"){e.boost=Math.min(1.8,e.boost+.45),this.routeFullTree(e,n,o||t.hook_event_name||"SessionStart");return}if(t.hook_event_name==="SubagentStart"){e.boost=Math.min(1.4,e.boost+.25),this.routeFullTree(e,n,"SubagentStart");return}if(t.hook_event_name==="Notification"||t.hook_event_name==="PermissionRequest"){e.boost=Math.min(1.2,e.boost+.15);return}e.boost=Math.min(1.4,e.boost+.25);const i=t.tool_input??{},a=te(e.rootPath,i.file_path)||te(e.rootPath,i.path);let l=No(e.layout,a);if(l||(l=oe(e.layout,`${t.id}:fallback`,1)[0]||null),!l)return;const r=e.layout.nodes.get(l),c=(r==null?void 0:r.type)==="folder"?Eo(e.layout,l,3):[l],h=En.has(o)?"inward":"outward";for(const m of c){const p=ee(e.layout,m).map(u=>e.branches.get(u)).filter(u=>u!==void 0);if(p.length===0)continue;const f=e.layout.blossomAnchors.get(m)??null,y=e.petalInstanceIds,g={branchChain:p,targetBlossom:f,targetPetalIds:y,direction:h,color:n,intensity:1},v=t.hook_event_name==="PostToolUseFailure"?"PostToolUseFailure":o,M=be(v,g,e.group,this.petalSystem,this.windField);this.activeEffects.push(M)}}routeFullTree(t,e,o){const n=oe(t.layout,`${t.id}:${Date.now()}`,4);for(const i of n){const l=ee(t.layout,i).map(m=>t.branches.get(m)).filter(m=>m!==void 0);if(l.length===0)continue;const r=t.layout.blossomAnchors.get(i)??null,h=be(o,{branchChain:l,targetBlossom:r,targetPetalIds:[],direction:"outward",color:e,intensity:.8},t.group,this.petalSystem,this.windField);this.activeEffects.push(h)}}update(t,e){this.activeEffects=this.activeEffects.filter(o=>{const n=o.tick(t,e);return n||o.dispose(),n})}dispose(){for(const t of this.activeEffects)t.dispose();this.activeEffects=[]}}class Bn{constructor(t){}createPulse(t,e){}tick(t){}dispose(){}}class Wn{constructor(){this.directionX=1,this.directionZ=0,this.strength=.2,this.gustStrength=0,this.gustTimer=8,this.turbulence=0,this.phase=0,this.baseAngle=0,this.gustRamp=0,this.gustHold=0,this.gustDecay=0,this.gustActive=!1}update(t){this.baseAngle+=t*(Math.PI*2/30),this.directionX=Math.cos(this.baseAngle),this.directionZ=Math.sin(this.baseAngle),this.strength=.2+.25*(.5+.5*Math.sin(this.phase*(Math.PI*2/8))),this.phase+=t,this.turbulence=.5+.5*Math.sin(this.phase*7.3+Math.cos(this.phase*3.1)*2),this.turbulence*=.15,this.gustActive||(this.gustTimer-=t,this.gustTimer<=0&&(this.gustActive=!0,this.gustRamp=.5,this.gustHold=1+Math.random(),this.gustDecay=1.5,this.gustStrength=0)),this.gustActive&&(this.gustRamp>0?(this.gustRamp-=t,this.gustStrength=Math.min(1,this.gustStrength+t*2)):this.gustHold>0?(this.gustHold-=t,this.gustStrength=.7+.3*Math.sin(this.phase*4)):this.gustDecay>0?(this.gustDecay-=t,this.gustStrength=Math.max(0,this.gustStrength-t*.67)):(this.gustActive=!1,this.gustStrength=0,this.gustTimer=5+Math.random()*10))}get effectiveStrength(){return Math.min(1,this.strength+this.gustStrength*.6+this.turbulence*.1)}spike(t,e){this.gustStrength=Math.max(this.gustStrength,t),this.turbulence=Math.max(this.turbulence,e),this.gustActive=!0,this.gustRamp=0,this.gustHold=0,this.gustDecay=2}}function Gn(s){let t=2166136261;for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t=Math.imul(t,16777619);return(t>>>0)/4294967296}function Nt(s,t,e){return Math.min(e,Math.max(t,s))}const On={Read:"#d4a574",Edit:"#7ec8e3",Write:"#7dd3fc",Bash:"#f59e0b",Grep:"#c084fc",Glob:"#a78bfa",WebFetch:"#fb7185"};function Ln(s){return On[s.tool_name||""]||"#e8a060"}function Vn(s,t){const e=[...s];for(let o=e.length-1;o>0;o--){const n=Math.floor(Math.random()*(o+1));[e[o],e[n]]=[e[n],e[o]]}return e.slice(0,t)}function Hn(){const t=document.createElement("canvas");t.width=256,t.height=256;const e=t.getContext("2d");e.fillStyle="rgb(128,128,255)",e.fillRect(0,0,256,256);const o=e.getImageData(0,0,256,256),n=o.data;for(let r=0;r<256;r++)for(let c=0;c<256;c++){const h=(r*256+c)*4,m=Math.sin(c/256*Math.PI*24)*.5+Math.sin(c/256*Math.PI*7+.8)*.25;n[h]=Math.round(128+m*30),n[h+1]=128,n[h+2]=255,n[h+3]=255}const a=(r=>{let c=r;return()=>(c=c*1664525+1013904223>>>0,c/4294967295)})(42);for(let r=0;r<12;r++){const c=Math.floor(a()*256),h=Math.floor(a()*256),m=Math.floor(20+a()*30),d=Math.floor(3+a()*5);for(let p=-d;p<=d;p++)for(let f=-m;f<=m;f++){const y=(c+f+256)%256,g=(h+p+256)%256,v=1-Math.sqrt((f/m)**2+(p/d)**2);if(v<=0)continue;const M=(g*256+y)*4,u=Math.sin(v*Math.PI)*40;n[M+1]=Math.min(255,Math.round(n[M+1]+u))}}e.putImageData(o,0,0);const l=new it(t);return l.wrapS=At,l.wrapT=At,l.repeat.set(2,4),l.needsUpdate=!0,l}let $t=null;function qn(){return $t||($t=Hn()),$t}function Zn(s,t=Date.now()){const e=Math.max(0,t-s.lastEventTime),o=Nt(1-e/9e4,0,1),n=Nt(Math.log1p(s.eventCount)/Math.log(24),0,1);return Nt(.12+o*.56+n*.3,.08,1)}function Xn(s){return`${s.projectId}:${s.stats.totalNodes}:${s.stats.maxDepthReached}:${s.stats.truncated?"t":"f"}`}class Qn{constructor(t){this.container=t,this.colonies=new Map,this.windField=new Wn,this.petalSystem=new un,this.flowerSystem=new yn,this.elapsed=0;const e=t.clientWidth,o=t.clientHeight;this.renderer=new oo({antialias:!0,alpha:!1}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.renderer.setSize(e,o),this.renderer.outputColorSpace=no,this.renderer.setClearColor("#0e0a08"),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=so,t.appendChild(this.renderer.domElement),this.scene=new io,this.scene.fog=new ro("#0e0a08",.003),this.camera=new ao(38,e/o,.1,1600),this.camera.position.set(40,80,200),this.controls=new lo(this.camera,this.renderer.domElement),this.controls.enableDamping=!0,this.controls.dampingFactor=.06,this.controls.autoRotate=!0,this.controls.autoRotateSpeed=.15,this.controls.minDistance=60,this.controls.maxDistance=500,this.controls.target.set(0,40,0),this.composer=new co(this.renderer),this.composer.addPass(new ho(this.scene,this.camera)),this.composer.addPass(new uo(new po(e,o),.4,.3,.75));const n=new Mo(this.scene,this.camera,{focus:160,aperture:.001,maxblur:.002});this.composer.addPass(n),this.composer.addPass(Ao()),this.composer.addPass(Io()),this.composer.addPass(Po()),this.filmGrainPass=_o(),this.composer.addPass(this.filmGrainPass),this.scene.add(new fo("#fff5f0",1));const i=new mo("#ffeef5","#0a0606",1.8);i.position.set(0,200,0),this.scene.add(i);const a=new go("#fff0e0",.8);a.position.set(-80,160,100),a.castShadow=!0,a.shadow.mapSize.width=1024,a.shadow.mapSize.height=1024,a.shadow.camera.near=10,a.shadow.camera.far=400,a.shadow.camera.left=-120,a.shadow.camera.right=120,a.shadow.camera.top=120,a.shadow.camera.bottom=-40,a.shadow.bias=-.002,a.shadow.radius=4,this.scene.add(a);const l=new Ut("#ffd0e0",.9,500,1.5);l.position.set(0,180,-80),this.scene.add(l);const r=new Ut("#ffb78e",.35,300,2);r.position.set(-100,20,60),this.scene.add(r);const c=new Ut("#ff8ab0",.3,250,2);c.position.set(90,60,-40),this.scene.add(c),this.skyMaterial=new mt({uniforms:{uTime:{value:0},uHeat:{value:0}},vertexShader:`
482
482
  varying vec3 vWorldPos;
483
483
  void main() {
484
484
  vec4 world = modelMatrix * vec4(position, 1.0);
@@ -515,4 +515,4 @@ void main() {
515
515
  color += vec3(0.3, 0.15, 0.2) * streaks * 0.08;
516
516
  gl_FragColor = vec4(color, 1.0);
517
517
  }
518
- `,side:mo,depthWrite:!1}),this.sky=new at(new go(900,32,24),this.skyMaterial),this.sky.scale.set(1,.72,1),this.scene.add(this.sky),this.ground=new at(new vo(800,72),new Lt({color:"#0f0a08",emissive:"#0a0705",emissiveIntensity:.3,roughness:.95,metalness:0})),this.ground.rotation.x=-Math.PI/2,this.ground.position.y=-4,this.ground.receiveShadow=!0,this.scene.add(this.ground),this.createGroundPetals(),this.atmosphere=this.createAtmosphere(),this.scene.add(this.atmosphere);for(let h=0;h<3;h++){const m=-2+h*30,d=new yo({color:new H("#1a1015"),transparent:!0,opacity:.04-h*.01,depthWrite:!1,side:vt}),p=new at(new De(600,600),d);p.rotation.x=-Math.PI/2,p.position.y=m,this.scene.add(p)}this.scene.add(this.petalSystem.mesh),this.scene.add(this.petalSystem.glowGroup),this.signalSystem=new Fn(this.petalSystem,this.windField),this.sapPulseSystem=new En(this.scene),this.tree=new Jo(23399),this.barkMaterial=new mt({uniforms:{uTime:{value:0},uHeat:{value:.12},uPulse:{value:0},uContam:{value:0},uPulseColor:{value:new H("#e8a88a")},uFlowOffset:{value:0},uWindStrength:{value:0},uWindPhase:{value:0},uSignalPos:{value:-1},uSignalIntensity:{value:0},uSignalColor:{value:new H("#ffffff")},uDepth:{value:0},uNormalMap:{value:On()},uNormalScale:{value:.3}},vertexShader:ke,fragmentShader:Ie,transparent:!1,depthWrite:!0,side:vt,blending:Ce}),this.treeMesh=new at(this.tree.geometry,this.barkMaterial),this.treeMesh.castShadow=!0,this.scene.add(this.treeMesh),this.scene.add(this.flowerSystem.mesh),this.resizeHandler=()=>this.onResize(),window.addEventListener("resize",this.resizeHandler)}createAtmosphere(){const e=new Float32Array(600),o=new Float32Array(200);for(let c=0;c<200;c++){const h=20+Math.random()*200,m=Math.random()*Math.PI*2,d=-5+Math.random()*140;e[c*3]=Math.cos(m)*h,e[c*3+1]=d,e[c*3+2]=Math.sin(m)*h,o[c]=2+Math.random()*5}const n=new ct;n.setAttribute("position",new q(e,3)),n.setAttribute("size",new q(o,1));const i=document.createElement("canvas");i.width=64,i.height=64;const a=i.getContext("2d"),l=a.createRadialGradient(32,32,0,32,32,30);l.addColorStop(0,"rgba(255,255,255,1)"),l.addColorStop(.3,"rgba(255,255,255,0.5)"),l.addColorStop(1,"rgba(255,255,255,0)"),a.fillStyle=l,a.fillRect(0,0,64,64);const r=new it(i);return new Te(n,new _e({map:r,color:"#ffe8d0",transparent:!0,opacity:.25,size:4,sizeAttenuation:!0,blending:kt,depthWrite:!1}))}createGroundPetals(){const t=document.createElement("canvas");t.width=32,t.height=32;const e=t.getContext("2d"),o=e.createRadialGradient(16,16,0,16,16,14);o.addColorStop(0,"rgba(255,255,255,1)"),o.addColorStop(.5,"rgba(255,255,255,0.6)"),o.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=o,e.fillRect(0,0,32,32);const n=new it(t),i=80;for(let a=0;a<i;a++){const l=Math.random()*Math.PI*2,r=4+Math.random()*50,c=Math.cos(l)*r,h=Math.sin(l)*r,m=.3+Math.random()*.5,d=new ze({map:n,color:new H(1,.75+(1-m)*.25,.82+(1-m)*.18),transparent:!0,opacity:.2+Math.random()*.2,depthWrite:!1}),p=new Ot(d);p.position.set(c,-3.5+Math.random()*.3,h),p.scale.setScalar(.5+Math.random()*.8),this.scene.add(p)}}syncProjects(t){const e=t.filter(n=>{var i;return(i=n.tree)==null?void 0:i.tree}),o=new Set;for(const n of e){const i=n.tree,a=Vn(i);let l=this.colonies.get(n.project.id);(!l||l.signature!==a)&&(l&&this.disposeColony(l),l=this.createColony(n,a),this.colonies.set(n.project.id,l)),l.activity=n.activity,l.rootPath=i.rootPath,o.add(n.project.id)}for(const[n,i]of this.colonies)o.has(n)||(this.disposeColony(i),this.colonies.delete(n))}createColony(t,e){const o=t.tree,n=ko(o.tree,t.project.id),i=new $t,{branches:a,junctions:l}=Go(n,new $t);return{id:t.project.id,rootPath:o.rootPath,signature:e,group:i,activity:t.activity,layout:n,branches:a,junctions:l,petalInstanceIds:[],heat:.12,contamination:0,boost:0,idleOffset:Nn(t.project.id)*Math.PI*2}}applyEvent(t){const{flowers:e,newNodeIds:o}=this.tree.onEvent();for(const a of e)this.flowerSystem.addCluster(a.pos,a.dir,5+Math.floor(Math.random()*6));const n=new H(Bn(t)),i=o.length>5?Wn(o,5):o;if(i.length>0)for(const a of i){const l=this.tree.traceToRoot(a);if(l.length<2)continue;const r=l.map(c=>this.tree.getNode(c)).filter(c=>c!==void 0).map(c=>c.position.clone());r.length>=2&&this.sapPulseSystem.createPulse(r,n)}else{const a=this.tree.getRandomLeafPath();a&&a.length>=2&&this.sapPulseSystem.createPulse(a,n)}if(t.cwd){const a=this.colonies.get(t.cwd);a&&(a.boost=Math.min(1.4,a.boost+.25),this.signalSystem.route(t,a))}}getTreeStats(){return{nodeCount:this.tree.nodeCount,segmentCount:Math.max(0,this.tree.nodeCount-1),activeAttractors:this.tree.activeAttractorCount,totalEvents:this.tree.totalEvents,isCapped:this.tree.isCapped}}resetGrowth(){this.tree.reset(),this.flowerSystem.reset(),this.sapPulseSystem.dispose()}tick(t){this.elapsed+=t,this.controls.update(),this.windField.update(t),this.barkMaterial.uniforms.uTime.value=this.elapsed,this.barkMaterial.uniforms.uWindStrength.value=this.windField.effectiveStrength,this.barkMaterial.uniforms.uWindPhase.value=this.windField.phase,this.atmosphere.rotation.y+=t*.001,this.skyMaterial.uniforms.uTime.value=this.elapsed;const e=Date.now();for(const o of this.colonies.values()){const n=Ln(o.activity,e);o.heat=n,o.boost=Math.max(0,o.boost-t*.35),o.contamination=Math.max(0,o.contamination-t*.03),Oo(o.branches,o.junctions,this.elapsed+o.idleOffset,n,o.contamination,this.windField.effectiveStrength,this.windField.phase,t)}this.petalSystem.update(t,this.elapsed,this.windField),this.petalSystem.ambientDrift(t),this.sapPulseSystem.tick(t),this.signalSystem.update(t,this.elapsed),Co(this.filmGrainPass,this.elapsed),this.composer.render()}onResize(){const{clientWidth:t,clientHeight:e}=this.container;this.camera.aspect=t/e,this.camera.updateProjectionMatrix(),this.renderer.setSize(t,e),this.composer.setSize(t,e)}disposeColony(t){Lo(t.branches,t.junctions)}destroy(){window.removeEventListener("resize",this.resizeHandler);for(const t of this.colonies.values())this.disposeColony(t);this.colonies.clear(),this.sapPulseSystem.dispose(),this.signalSystem.dispose(),this.petalSystem.dispose(),this.scene.remove(this.petalSystem.mesh),this.scene.remove(this.petalSystem.glowGroup),this.scene.remove(this.treeMesh),this.scene.remove(this.flowerSystem.mesh),this.flowerSystem.dispose(),this.tree.geometry.dispose(),this.barkMaterial.dispose(),this.atmosphere.geometry.dispose(),this.atmosphere.material.dispose(),this.sky.geometry.dispose(),this.skyMaterial.dispose(),this.ground.geometry.dispose(),this.ground.material.dispose(),this.controls.dispose(),this.composer.dispose(),this.renderer.dispose(),this.container.removeChild(this.renderer.domElement)}}function qn({projects:s,latestSignal:t,resetSignal:e}){const o=P.useRef(null),n=P.useRef(null),i=P.useRef(null),a=P.useRef(s);return a.current=s,P.useEffect(()=>{const l=o.current;if(!l)return;let r=performance.now();const c=new Hn(l);n.current=c,c.syncProjects(a.current);const h=()=>{const m=performance.now(),d=(m-r)/1e3;r=m,c.tick(Math.min(d,.05)),i.current=requestAnimationFrame(h)};return i.current=requestAnimationFrame(h),()=>{i.current!==null&&cancelAnimationFrame(i.current),c.destroy(),n.current=null}},[]),P.useEffect(()=>{var l;(l=n.current)==null||l.syncProjects(s)},[s]),P.useEffect(()=>{var l;t&&((l=n.current)==null||l.applyEvent(t.event))},[t==null?void 0:t.sequence]),P.useEffect(()=>{var l;e&&((l=n.current)==null||l.resetGrowth())},[e]),S.jsx("div",{ref:o,style:{width:"100vw",height:"100vh",background:"#0e0a08"}})}const xe={width:"100%",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",color:"#e8d4c0",padding:"6px 8px",fontFamily:"IBM Plex Mono, monospace",fontSize:10},dt={background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.1)",color:"#e8d4c0",padding:"5px 8px",cursor:"pointer",fontFamily:"IBM Plex Mono, monospace",fontSize:10};function Zn({isOpen:s,onToggle:t,projects:e,selectedProjectId:o,replayStatus:n,onSelectProject:i,onReplayProject:a,onStopReplay:l,onInjectEvent:r}){const[c,h]=P.useState("client/src/sakura/SakuraApp.ts"),[m,d]=P.useState(null),p=P.useMemo(()=>e.find(u=>u.project.id===o)??e[0]??null,[e,o]),f=P.useMemo(()=>{if(!p)return c;const u=c.replace(/^\/+/,"");return u?`${p.project.root}/${u}`:p.project.root},[c,p]);async function y(u,C){d(u);try{await r(C)}finally{d(null)}}function g(u){if(!p)return null;const C={session_id:"sakura-debug",cwd:p.project.root};return u==="Read"?{...C,hook_event_name:"PreToolUse",tool_name:"Read",tool_input:{file_path:f}}:u==="Edit"?{...C,hook_event_name:"PreToolUse",tool_name:"Edit",tool_input:{file_path:f}}:u==="Bash"?{...C,hook_event_name:"PreToolUse",tool_name:"Bash",tool_input:{command:"npm run build"}}:u==="Grep"?{...C,hook_event_name:"PreToolUse",tool_name:"Grep",tool_input:{pattern:"*.tsx",path:p.project.root}}:u==="Fetch"?{...C,hook_event_name:"PreToolUse",tool_name:"WebFetch",tool_input:{url:"https://example.com"}}:u==="Prompt"?{...C,hook_event_name:"UserPromptSubmit",prompt:"test prompt"}:u==="Error"?{...C,hook_event_name:"PostToolUseFailure",tool_name:"Read",tool_input:{file_path:f},error:"test error"}:u==="Agent"?{...C,hook_event_name:"SubagentStart",agent_id:`agent-${Date.now().toString(36)}`,agent_type:"general"}:u==="Session"?{...C,hook_event_name:"SessionStart"}:null}const v=[{label:"Read",color:"#d4a574"},{label:"Edit",color:"#7ec8e3"},{label:"Bash",color:"#f59e0b"},{label:"Grep",color:"#c084fc"},{label:"Fetch",color:"#fb7185"}],M=[{label:"Prompt",color:"#ffd4a8"},{label:"Error",color:"#f87171"},{label:"Agent",color:"#d8b4fe"},{label:"Session",color:"#e8c4a0"}];return S.jsxs(S.Fragment,{children:[S.jsx("button",{onClick:t,style:{position:"absolute",left:18,bottom:18,zIndex:24,padding:"7px 10px",border:"1px solid rgba(196,149,106,0.28)",background:"rgba(14,10,8,0.7)",color:"#c4956a",fontFamily:"IBM Plex Mono, monospace",fontSize:10,letterSpacing:"0.1em",textTransform:"uppercase",cursor:"pointer",backdropFilter:"blur(16px)"},children:s?"close":"sakura"}),s&&S.jsxs("div",{style:{position:"absolute",left:18,bottom:52,zIndex:25,width:320,maxHeight:"calc(100vh - 80px)",overflowY:"auto",padding:12,border:"1px solid rgba(255,255,255,0.08)",background:"linear-gradient(180deg, rgba(14,10,8,0.94), rgba(10,7,5,0.98))",boxShadow:"0 20px 60px rgba(0,0,0,0.5)",backdropFilter:"blur(22px)",color:"#e8d4c0",fontFamily:"IBM Plex Mono, monospace"},children:[S.jsxs("div",{style:{marginBottom:10},children:[S.jsx("select",{value:(p==null?void 0:p.project.id)??"",onChange:u=>i(u.target.value),style:{...xe,marginBottom:6},children:e.map(u=>S.jsx("option",{value:u.project.id,children:u.project.label},u.project.id))}),S.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:4},children:[S.jsx("button",{onClick:async()=>{if(p){d("buf");try{await a(p.project.id,!1)}finally{d(null)}}},style:dt,disabled:m!==null,children:"replay buf"}),S.jsx("button",{onClick:async()=>{if(p){d("saved");try{await a(p.project.id,!0)}finally{d(null)}}},style:dt,disabled:m!==null,children:"replay saved"}),S.jsx("button",{onClick:l,style:dt,children:"stop"})]}),n!=="idle"&&S.jsx("div",{style:{fontSize:9,color:"#8a7a6a",marginTop:4},children:n})]}),S.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:8},children:v.map(u=>S.jsx("button",{onClick:()=>{const C=g(u.label);C&&y(u.label,C)},style:{...dt,color:u.color,borderColor:`${u.color}33`,flex:"1 0 auto"},children:u.label},u.label))}),S.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:8},children:M.map(u=>S.jsx("button",{onClick:()=>{const C=g(u.label);C&&y(u.label,C)},style:{...dt,color:u.color,borderColor:`${u.color}33`,flex:"1 0 auto"},children:u.label},u.label))}),S.jsx("input",{value:c,onChange:u=>h(u.target.value),placeholder:"relative path",style:{...xe,marginBottom:4}}),S.jsx("div",{style:{fontSize:9,color:"#6a5a4a",wordBreak:"break-all"},children:f})]})]})}const je={eventCount:0,sessionCount:0,lastEventTime:0,lastTool:null};function be(s){const t=s.split("/").filter(Boolean);return t[t.length-1]||s}function Dt(s,t){const e=new Map(s.map(o=>[o.id,o]));for(const o of t){const n=e.get(o.id);e.set(o.id,n?{...n,...o}:o)}return[...e.values()].sort((o,n)=>n.lastEventTime-o.lastEventTime||o.label.localeCompare(n.label))}function Xn(s){return s.tool_use_id?`${s.session_id}:${s.hook_event_name}:${s.tool_use_id}`:s.hook_event_name==="UserPromptSubmit"&&s.prompt?`${s.session_id}:prompt:${s.prompt.slice(0,80)}`:s.hook_event_name==="SessionStart"?`${s.session_id}:start`:s.id}function we(s){return s.hook_event_name==="PreToolUse"||s.hook_event_name==="PostToolUseFailure"||s.hook_event_name==="UserPromptSubmit"||s.hook_event_name==="SessionStart"||s.hook_event_name==="SubagentStart"||s.hook_event_name==="Notification"||s.hook_event_name==="PermissionRequest"}function Se(s,t){if(!t.cwd)return s;const e=s[t.cwd]??je;return{...s,[t.cwd]:{eventCount:e.eventCount+1,sessionCount:t.session_id?Math.max(e.sessionCount,1):e.sessionCount,lastEventTime:Math.max(e.lastEventTime,t.timestamp||Date.now()),lastTool:t.tool_name||t.hook_event_name||e.lastTool}}}function Yn(){const[s,t]=P.useState([]),[e,o]=P.useState({}),[n,i]=P.useState({}),[a,l]=P.useState(null),[r,c]=P.useState("connecting"),[h,m]=P.useState(!0),[d,p]=P.useState(0),[f,y]=P.useState("waiting"),g=P.useRef(new Set),v=P.useRef(0),M=P.useRef(new Map),[u,C]=P.useState(null),[b,D]=P.useState(!1),[F,E]=P.useState(!1),[j,I]=P.useState("idle"),[O,k]=P.useState(0),N=P.useRef(null);async function et(x,A=!1){if(!(!A&&(e[x]||g.current.has(x)))){g.current.add(x);try{const B=await fetch(`/api/project-tree?project=${encodeURIComponent(x)}`);if(!B.ok)return;const V=await B.json();o(_=>({..._,[V.projectId]:V}))}finally{g.current.delete(x)}}}P.useEffect(()=>{let x=!1;async function A(){try{const[V,_]=await Promise.all([fetch("/api/projects"),fetch("/api/history")]),T=await V.json(),R=await _.json();if(x)return;t(Dt([],T.projects??[])),p(R.length),i(R.reduce((z,U)=>Se(z,U),{}))}catch{}finally{x||m(!1)}}A();const B=setInterval(async()=>{try{const _=await(await fetch("/api/projects")).json();x||t(T=>Dt(T,_.projects??[]))}catch{}},15e3);return()=>{x=!0,clearInterval(B)}},[]),P.useEffect(()=>{for(const x of s)e[x.id]||g.current.has(x.id)||et(x.id)},[s,e]),P.useEffect(()=>{const x=M.current,A=new EventSource("/events");return A.onopen=()=>c("connected"),A.onerror=()=>c("disconnected"),A.onmessage=B=>{try{const V=JSON.parse(B.data);if(V.type!=="event")return;const _=V.data;if(_.hook_event_name==="Diagnostic")return;const T=Xn(_),R=Date.now();if(x.has(T)&&R-x.get(T)<5e3)return;if(x.set(T,R),x.size>500)for(const[z,U]of x)R-U>5e3&&x.delete(z);if(_.cwd){const z=_.cwd;t(U=>{const G=U.find(rt=>rt.id===z);return Dt(U,[{id:z,root:z,label:be(z),eventCount:((G==null?void 0:G.eventCount)??0)+1,sessionCount:Math.max((G==null?void 0:G.sessionCount)??0,1),lastEventTime:_.timestamp||Date.now()}])}),i(U=>Se(U,_))}y(_.tool_name||_.hook_event_name||"event"),we(_)&&(v.current+=1,l({sequence:v.current,event:_}))}catch{}},()=>A.close()},[]);function W(){N.current!==null&&(clearTimeout(N.current),N.current=null),I("idle")}async function $(x,A){W(),k(z=>z+1),I("loading...");const _=(await(await fetch(`/api/history?project=${encodeURIComponent(x)}${A?"&persisted=1":""}`)).json()).filter(we).slice(-220);if(!_.length)return I("no events"),0;let T=0;const R=()=>{const z=_[T];v.current+=1,l({sequence:v.current,event:z}),T++,I(`${T}/${_.length}`),T<_.length?N.current=window.setTimeout(R,z.tool_name==="Bash"?160:90):(N.current=null,I(`done (${_.length})`))};return R(),_.length}async function L(x){const A={id:`hook-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,7)}`,session_id:"sakura-debug",timestamp:Date.now(),hook_event_name:"Notification",tool_name:null,tool_input:null,tool_response:null,agent_id:null,agent_type:null,cwd:null,error:null,tool_use_id:null,prompt:null,model:null,source:"hook",reason:null,permission_mode:null,is_interrupt:null,trigger:null,compact_summary:null,last_assistant_message:null,notification_type:null,title:null,agent_transcript_path:null,memory_type:null,...x};await fetch("/hook",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(A)})}P.useEffect(()=>{var x;!u&&((x=s[0])!=null&&x.id)&&C(s[0].id)},[s,u]),P.useEffect(()=>()=>W(),[]);const Z=Dt(s,Object.entries(n).filter(([x])=>!s.some(A=>A.id===x)).map(([x,A])=>({id:x,root:x,label:be(x),eventCount:A.eventCount,sessionCount:A.sessionCount,lastEventTime:A.lastEventTime}))).map(x=>({project:x,tree:e[x.id]??null,activity:n[x.id]??je})),ot=Z.filter(x=>x.tree).length;return S.jsxs("div",{style:{position:"relative",width:"100vw",height:"100vh",overflow:"hidden",background:"#0e0a08"},children:[S.jsx(qn,{projects:Z,latestSignal:a,resetSignal:O}),S.jsx("a",{href:"#/three",style:{position:"absolute",top:18,left:18,zIndex:20,padding:"10px 14px",border:"1px solid rgba(232,196,160,0.18)",background:"rgba(14,10,8,0.52)",color:"#e8c4a0",textDecoration:"none",fontFamily:"IBM Plex Mono, monospace",fontSize:11,letterSpacing:"0.08em",textTransform:"uppercase",backdropFilter:"blur(16px)"},children:"back to three"}),S.jsx("button",{onClick:()=>E(x=>!x),style:{position:"absolute",top:18,right:18,zIndex:21,padding:"8px 12px",border:"1px solid rgba(196,149,106,0.28)",background:"rgba(14,10,8,0.7)",color:"#c4956a",fontFamily:"IBM Plex Mono, monospace",fontSize:10,letterSpacing:"0.1em",textTransform:"uppercase",cursor:"pointer",backdropFilter:"blur(16px)"},children:F?"hide":"info"}),F&&S.jsxs("div",{style:{position:"absolute",top:52,right:18,zIndex:20,width:300,padding:"14px 16px",border:"1px solid rgba(255,255,255,0.08)",background:"linear-gradient(180deg, rgba(14,10,8,0.76), rgba(10,7,5,0.9))",backdropFilter:"blur(18px)",boxShadow:"0 18px 60px rgba(0,0,0,0.35)",color:"#e8d4c0",fontFamily:"IBM Plex Mono, monospace"},children:[S.jsx("div",{style:{fontSize:10,letterSpacing:"0.18em",textTransform:"uppercase",color:"#c4956a",marginBottom:6},children:"sakura"}),S.jsx("div",{style:{fontFamily:"Oxanium, sans-serif",fontSize:24,lineHeight:1,marginBottom:10},children:"live project tree"}),S.jsx("div",{style:{color:"#9a8070",fontSize:11,lineHeight:1.6,marginBottom:12},children:"Filesystem branches grow as a living sakura tree. Tool events flow as sap through branch ancestry."}),S.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:8,marginBottom:12},children:[S.jsxs("div",{children:[S.jsx("div",{style:{fontSize:10,color:"#786050",marginBottom:3},children:"link"}),S.jsx("div",{style:{fontSize:12},children:r})]}),S.jsxs("div",{children:[S.jsx("div",{style:{fontSize:10,color:"#786050",marginBottom:3},children:"trees"}),S.jsxs("div",{style:{fontSize:12},children:[ot,"/",Z.length]})]}),S.jsxs("div",{children:[S.jsx("div",{style:{fontSize:10,color:"#786050",marginBottom:3},children:"history"}),S.jsx("div",{style:{fontSize:12},children:d})]})]}),S.jsx("div",{style:{fontSize:10,color:"#786050",marginBottom:4},children:"last pulse"}),S.jsx("div",{style:{fontSize:12,marginBottom:12},children:f}),S.jsx("div",{style:{fontSize:10,color:"#786050",marginBottom:6},children:"active roots"}),S.jsx("div",{style:{display:"grid",gap:6,maxHeight:200,overflowY:"auto"},children:Z.slice(0,6).map(({project:x,tree:A,activity:B})=>S.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.03)",border:"1px solid rgba(255,255,255,0.05)"},children:[S.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8,marginBottom:3},children:[S.jsx("span",{style:{fontSize:11},children:x.label}),S.jsx("span",{style:{color:"#c4956a",fontSize:10},children:A?`${A.stats.totalNodes} nodes`:"loading"})]}),S.jsx("div",{style:{color:"#6a5a4a",fontSize:10,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:x.root}),S.jsxs("div",{style:{display:"flex",gap:8,marginTop:4,fontSize:10,color:"#8a7a6a"},children:[S.jsxs("span",{children:[B.eventCount," ev"]}),S.jsxs("span",{children:[x.sessionCount," ses"]}),S.jsx("span",{children:B.lastTool||"idle"})]})]},x.id))})]}),S.jsx(Zn,{isOpen:b,onToggle:()=>D(x=>!x),projects:Z,selectedProjectId:u,replayStatus:j,onSelectProject:C,onReplayProject:$,onStopReplay:W,onInjectEvent:L})]})}export{Yn as SakuraPage};
518
+ `,side:vo,depthWrite:!1}),this.sky=new at(new yo(900,32,24),this.skyMaterial),this.sky.scale.set(1,.72,1),this.scene.add(this.sky),this.ground=new at(new xo(800,72),new Vt({color:"#0f0a08",emissive:"#0a0705",emissiveIntensity:.3,roughness:.95,metalness:0})),this.ground.rotation.x=-Math.PI/2,this.ground.position.y=-4,this.ground.receiveShadow=!0,this.scene.add(this.ground),this.createGroundPetals(),this.atmosphere=this.createAtmosphere(),this.scene.add(this.atmosphere);for(let h=0;h<3;h++){const m=-2+h*30,d=new bo({color:new H("#1a1015"),transparent:!0,opacity:.04-h*.01,depthWrite:!1,side:vt}),p=new at(new Te(600,600),d);p.rotation.x=-Math.PI/2,p.position.y=m,this.scene.add(p)}this.scene.add(this.petalSystem.mesh),this.scene.add(this.petalSystem.glowGroup),this.signalSystem=new $n(this.petalSystem,this.windField),this.sapPulseSystem=new Bn(this.scene),this.tree=new nn(23399),this.barkMaterial=new mt({uniforms:{uTime:{value:0},uHeat:{value:.12},uPulse:{value:0},uContam:{value:0},uPulseColor:{value:new H("#e8a88a")},uFlowOffset:{value:0},uWindStrength:{value:0},uWindPhase:{value:0},uSignalPos:{value:-1},uSignalIntensity:{value:0},uSignalColor:{value:new H("#ffffff")},uDepth:{value:0},uNormalMap:{value:qn()},uNormalScale:{value:.3}},vertexShader:Re,fragmentShader:Ue,transparent:!1,depthWrite:!0,side:vt,blending:De}),this.treeMesh=new at(this.tree.geometry,this.barkMaterial),this.treeMesh.castShadow=!0,this.scene.add(this.treeMesh),this.scene.add(this.flowerSystem.mesh),this.resizeHandler=()=>this.onResize(),window.addEventListener("resize",this.resizeHandler)}createAtmosphere(){const e=new Float32Array(600),o=new Float32Array(200);for(let c=0;c<200;c++){const h=20+Math.random()*200,m=Math.random()*Math.PI*2,d=-5+Math.random()*140;e[c*3]=Math.cos(m)*h,e[c*3+1]=d,e[c*3+2]=Math.sin(m)*h,o[c]=2+Math.random()*5}const n=new ct;n.setAttribute("position",new q(e,3)),n.setAttribute("size",new q(o,1));const i=document.createElement("canvas");i.width=64,i.height=64;const a=i.getContext("2d"),l=a.createRadialGradient(32,32,0,32,32,30);l.addColorStop(0,"rgba(255,255,255,1)"),l.addColorStop(.3,"rgba(255,255,255,0.5)"),l.addColorStop(1,"rgba(255,255,255,0)"),a.fillStyle=l,a.fillRect(0,0,64,64);const r=new it(i);return new Ae(n,new ze({map:r,color:"#ffe8d0",transparent:!0,opacity:.25,size:4,sizeAttenuation:!0,blending:It,depthWrite:!1}))}createGroundPetals(){const t=document.createElement("canvas");t.width=32,t.height=32;const e=t.getContext("2d"),o=e.createRadialGradient(16,16,0,16,16,14);o.addColorStop(0,"rgba(255,255,255,1)"),o.addColorStop(.5,"rgba(255,255,255,0.6)"),o.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=o,e.fillRect(0,0,32,32);const n=new it(t),i=80;for(let a=0;a<i;a++){const l=Math.random()*Math.PI*2,r=4+Math.random()*50,c=Math.cos(l)*r,h=Math.sin(l)*r,m=.3+Math.random()*.5,d=new ke({map:n,color:new H(1,.75+(1-m)*.25,.82+(1-m)*.18),transparent:!0,opacity:.2+Math.random()*.2,depthWrite:!1}),p=new Lt(d);p.position.set(c,-3.5+Math.random()*.3,h),p.scale.setScalar(.5+Math.random()*.8),this.scene.add(p)}}syncProjects(t){const e=t.filter(n=>{var i;return(i=n.tree)==null?void 0:i.tree}),o=new Set;for(const n of e){const i=n.tree,a=Xn(i);let l=this.colonies.get(n.project.id);(!l||l.signature!==a)&&(l&&this.disposeColony(l),l=this.createColony(n,a),this.colonies.set(n.project.id,l)),l.activity=n.activity,l.rootPath=i.rootPath,o.add(n.project.id)}for(const[n,i]of this.colonies)o.has(n)||(this.disposeColony(i),this.colonies.delete(n))}createColony(t,e){const o=t.tree,n=Fo(o.tree,t.project.id),i=new Bt,{branches:a,junctions:l}=Ho(n,new Bt);return{id:t.project.id,rootPath:o.rootPath,signature:e,group:i,activity:t.activity,layout:n,branches:a,junctions:l,petalInstanceIds:[],heat:.12,contamination:0,boost:0,idleOffset:Gn(t.project.id)*Math.PI*2}}applyEvent(t){const{flowers:e,newNodeIds:o}=this.tree.onEvent();for(const a of e)this.flowerSystem.addCluster(a.pos,a.dir,5+Math.floor(Math.random()*6));const n=new H(Ln(t)),i=o.length>5?Vn(o,5):o;if(i.length>0)for(const a of i){const l=this.tree.traceToRoot(a);if(l.length<2)continue;const r=l.map(c=>this.tree.getNode(c)).filter(c=>c!==void 0).map(c=>c.position.clone());r.length>=2&&this.sapPulseSystem.createPulse(r,n)}else{const a=this.tree.getRandomLeafPath();a&&a.length>=2&&this.sapPulseSystem.createPulse(a,n)}if(t.cwd){const a=this.colonies.get(t.cwd);a&&(a.boost=Math.min(1.4,a.boost+.25),this.signalSystem.route(t,a))}}getTreeStats(){return{nodeCount:this.tree.nodeCount,segmentCount:Math.max(0,this.tree.nodeCount-1),activeAttractors:this.tree.activeAttractorCount,totalEvents:this.tree.totalEvents,isCapped:this.tree.isCapped}}resetGrowth(){this.tree.reset(),this.flowerSystem.reset(),this.sapPulseSystem.dispose()}tick(t){this.elapsed+=t,this.controls.update(),this.windField.update(t),this.barkMaterial.uniforms.uTime.value=this.elapsed,this.barkMaterial.uniforms.uWindStrength.value=this.windField.effectiveStrength,this.barkMaterial.uniforms.uWindPhase.value=this.windField.phase,this.atmosphere.rotation.y+=t*.001,this.skyMaterial.uniforms.uTime.value=this.elapsed;const e=Date.now();for(const o of this.colonies.values()){const n=Zn(o.activity,e);o.heat=n,o.boost=Math.max(0,o.boost-t*.35),o.contamination=Math.max(0,o.contamination-t*.03),qo(o.branches,o.junctions,this.elapsed+o.idleOffset,n,o.contamination,this.windField.effectiveStrength,this.windField.phase,t)}this.petalSystem.update(t,this.elapsed,this.windField),this.petalSystem.ambientDrift(t),this.sapPulseSystem.tick(t),this.signalSystem.update(t,this.elapsed),To(this.filmGrainPass,this.elapsed),this.composer.render()}onResize(){const{clientWidth:t,clientHeight:e}=this.container;this.camera.aspect=t/e,this.camera.updateProjectionMatrix(),this.renderer.setSize(t,e),this.composer.setSize(t,e)}disposeColony(t){Zo(t.branches,t.junctions)}destroy(){window.removeEventListener("resize",this.resizeHandler);for(const t of this.colonies.values())this.disposeColony(t);this.colonies.clear(),this.sapPulseSystem.dispose(),this.signalSystem.dispose(),this.petalSystem.dispose(),this.scene.remove(this.petalSystem.mesh),this.scene.remove(this.petalSystem.glowGroup),this.scene.remove(this.treeMesh),this.scene.remove(this.flowerSystem.mesh),this.flowerSystem.dispose(),this.tree.geometry.dispose(),this.barkMaterial.dispose(),this.atmosphere.geometry.dispose(),this.atmosphere.material.dispose(),this.sky.geometry.dispose(),this.skyMaterial.dispose(),this.ground.geometry.dispose(),this.ground.material.dispose(),this.controls.dispose(),this.composer.dispose(),this.renderer.dispose(),this.container.removeChild(this.renderer.domElement)}}function Yn({projects:s,latestSignal:t,resetSignal:e}){const o=P.useRef(null),n=P.useRef(null),i=P.useRef(null),a=P.useRef(s);return a.current=s,P.useEffect(()=>{const l=o.current;if(!l)return;let r=performance.now();const c=new Qn(l);n.current=c,c.syncProjects(a.current);const h=()=>{document.hidden||(r=performance.now())};document.addEventListener("visibilitychange",h);const m=()=>{const d=performance.now(),p=(d-r)/1e3;r=d,c.tick(Math.min(p,.05)),i.current=requestAnimationFrame(m)};return i.current=requestAnimationFrame(m),()=>{document.removeEventListener("visibilitychange",h),i.current!==null&&cancelAnimationFrame(i.current),c.destroy(),n.current=null}},[]),P.useEffect(()=>{var l;(l=n.current)==null||l.syncProjects(s)},[s]),P.useEffect(()=>{var l;t&&((l=n.current)==null||l.applyEvent(t.event))},[t==null?void 0:t.sequence]),P.useEffect(()=>{var l;e&&((l=n.current)==null||l.resetGrowth())},[e]),S.jsx("div",{ref:o,style:{width:"100vw",height:"100vh",background:"#0e0a08"}})}const we={width:"100%",background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",color:"#e8d4c0",padding:"6px 8px",fontFamily:"IBM Plex Mono, monospace",fontSize:10},dt={background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.1)",color:"#e8d4c0",padding:"5px 8px",cursor:"pointer",fontFamily:"IBM Plex Mono, monospace",fontSize:10};function Kn({isOpen:s,onToggle:t,projects:e,selectedProjectId:o,replayStatus:n,onSelectProject:i,onReplayProject:a,onStopReplay:l,onInjectEvent:r}){const[c,h]=P.useState("client/src/sakura/SakuraApp.ts"),[m,d]=P.useState(null),p=P.useMemo(()=>e.find(u=>u.project.id===o)??e[0]??null,[e,o]),f=P.useMemo(()=>{if(!p)return c;const u=c.replace(/^\/+/,"");return u?`${p.project.root}/${u}`:p.project.root},[c,p]);async function y(u,C){d(u);try{await r(C)}finally{d(null)}}function g(u){if(!p)return null;const C={session_id:"sakura-debug",cwd:p.project.root};return u==="Read"?{...C,hook_event_name:"PreToolUse",tool_name:"Read",tool_input:{file_path:f}}:u==="Edit"?{...C,hook_event_name:"PreToolUse",tool_name:"Edit",tool_input:{file_path:f}}:u==="Bash"?{...C,hook_event_name:"PreToolUse",tool_name:"Bash",tool_input:{command:"npm run build"}}:u==="Grep"?{...C,hook_event_name:"PreToolUse",tool_name:"Grep",tool_input:{pattern:"*.tsx",path:p.project.root}}:u==="Fetch"?{...C,hook_event_name:"PreToolUse",tool_name:"WebFetch",tool_input:{url:"https://example.com"}}:u==="Prompt"?{...C,hook_event_name:"UserPromptSubmit",prompt:"test prompt"}:u==="Error"?{...C,hook_event_name:"PostToolUseFailure",tool_name:"Read",tool_input:{file_path:f},error:"test error"}:u==="Agent"?{...C,hook_event_name:"SubagentStart",agent_id:`agent-${Date.now().toString(36)}`,agent_type:"general"}:u==="Session"?{...C,hook_event_name:"SessionStart"}:null}const v=[{label:"Read",color:"#d4a574"},{label:"Edit",color:"#7ec8e3"},{label:"Bash",color:"#f59e0b"},{label:"Grep",color:"#c084fc"},{label:"Fetch",color:"#fb7185"}],M=[{label:"Prompt",color:"#ffd4a8"},{label:"Error",color:"#f87171"},{label:"Agent",color:"#d8b4fe"},{label:"Session",color:"#e8c4a0"}];return S.jsxs(S.Fragment,{children:[S.jsx("button",{onClick:t,style:{position:"absolute",left:18,bottom:18,zIndex:24,padding:"7px 10px",border:"1px solid rgba(196,149,106,0.28)",background:"rgba(14,10,8,0.7)",color:"#c4956a",fontFamily:"IBM Plex Mono, monospace",fontSize:10,letterSpacing:"0.1em",textTransform:"uppercase",cursor:"pointer",backdropFilter:"blur(16px)"},children:s?"close":"sakura"}),s&&S.jsxs("div",{style:{position:"absolute",left:18,bottom:52,zIndex:25,width:320,maxHeight:"calc(100vh - 80px)",overflowY:"auto",padding:12,border:"1px solid rgba(255,255,255,0.08)",background:"linear-gradient(180deg, rgba(14,10,8,0.94), rgba(10,7,5,0.98))",boxShadow:"0 20px 60px rgba(0,0,0,0.5)",backdropFilter:"blur(22px)",color:"#e8d4c0",fontFamily:"IBM Plex Mono, monospace"},children:[S.jsxs("div",{style:{marginBottom:10},children:[S.jsx("select",{value:(p==null?void 0:p.project.id)??"",onChange:u=>i(u.target.value),style:{...we,marginBottom:6},children:e.map(u=>S.jsx("option",{value:u.project.id,children:u.project.label},u.project.id))}),S.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:4},children:[S.jsx("button",{onClick:async()=>{if(p){d("buf");try{await a(p.project.id,!1)}finally{d(null)}}},style:dt,disabled:m!==null,children:"replay buf"}),S.jsx("button",{onClick:async()=>{if(p){d("saved");try{await a(p.project.id,!0)}finally{d(null)}}},style:dt,disabled:m!==null,children:"replay saved"}),S.jsx("button",{onClick:l,style:dt,children:"stop"})]}),n!=="idle"&&S.jsx("div",{style:{fontSize:9,color:"#8a7a6a",marginTop:4},children:n})]}),S.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:8},children:v.map(u=>S.jsx("button",{onClick:()=>{const C=g(u.label);C&&y(u.label,C)},style:{...dt,color:u.color,borderColor:`${u.color}33`,flex:"1 0 auto"},children:u.label},u.label))}),S.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:8},children:M.map(u=>S.jsx("button",{onClick:()=>{const C=g(u.label);C&&y(u.label,C)},style:{...dt,color:u.color,borderColor:`${u.color}33`,flex:"1 0 auto"},children:u.label},u.label))}),S.jsx("input",{value:c,onChange:u=>h(u.target.value),placeholder:"relative path",style:{...we,marginBottom:4}}),S.jsx("div",{style:{fontSize:9,color:"#6a5a4a",wordBreak:"break-all"},children:f})]})]})}const $e={eventCount:0,sessionCount:0,lastEventTime:0,lastTool:null};function Se(s){const t=s.split("/").filter(Boolean);return t[t.length-1]||s}function _t(s,t){const e=new Map(s.map(o=>[o.id,o]));for(const o of t){const n=e.get(o.id);e.set(o.id,n?{...n,...o}:o)}return[...e.values()].sort((o,n)=>n.lastEventTime-o.lastEventTime||o.label.localeCompare(n.label))}function Jn(s){return s.tool_use_id?`${s.session_id}:${s.hook_event_name}:${s.tool_use_id}`:s.hook_event_name==="UserPromptSubmit"&&s.prompt?`${s.session_id}:prompt:${s.prompt.slice(0,80)}`:s.hook_event_name==="SessionStart"?`${s.session_id}:start`:s.id}function Me(s){return s.hook_event_name==="PreToolUse"||s.hook_event_name==="PostToolUseFailure"||s.hook_event_name==="UserPromptSubmit"||s.hook_event_name==="SessionStart"||s.hook_event_name==="SubagentStart"||s.hook_event_name==="Notification"||s.hook_event_name==="PermissionRequest"}function Ce(s,t){if(!t.cwd)return s;const e=s[t.cwd]??$e;return{...s,[t.cwd]:{eventCount:e.eventCount+1,sessionCount:t.session_id?Math.max(e.sessionCount,1):e.sessionCount,lastEventTime:Math.max(e.lastEventTime,t.timestamp||Date.now()),lastTool:t.tool_name||t.hook_event_name||e.lastTool}}}function es(){const[s,t]=P.useState([]),[e,o]=P.useState({}),[n,i]=P.useState({}),[a,l]=P.useState(null),[r,c]=P.useState("connecting"),[h,m]=P.useState(!0),[d,p]=P.useState(0),[f,y]=P.useState("waiting"),g=P.useRef(new Set),v=P.useRef(0),M=P.useRef(new Map),[u,C]=P.useState(null),[b,D]=P.useState(!1),[F,E]=P.useState(!1),[j,k]=P.useState("idle"),[L,z]=P.useState(0),N=P.useRef(null);async function et(x,_=!1){if(!(!_&&(e[x]||g.current.has(x)))){g.current.add(x);try{const W=await Xt(`/api/project-tree?project=${encodeURIComponent(x)}`);if(!W.ok)return;const R=await So(W);o(T=>({...T,[R.projectId]:R}))}finally{g.current.delete(x)}}}P.useEffect(()=>{let x=!1;async function _(){try{const[R,T]=await Promise.all([wt("/api/projects"),wt("/api/history")]);if(x)return;t(_t([],R.projects??[])),p(T.length),i(T.reduce((A,U)=>Ce(A,U),{}))}catch{}finally{x||m(!1)}}_();const W=setInterval(async()=>{try{const R=await wt("/api/projects");x||t(T=>_t(T,R.projects??[]))}catch{}},15e3);return()=>{x=!0,clearInterval(W)}},[]),P.useEffect(()=>{for(const x of s)e[x.id]||g.current.has(x.id)||et(x.id)},[s,e]),P.useEffect(()=>{const x=M.current,_=wo("/events");return _.onopen=()=>c("connected"),_.onerror=()=>c("disconnected"),_.onmessage=W=>{try{const R=JSON.parse(W.data);if(R.type!=="event")return;const T=R.data;if(T.hook_event_name==="Diagnostic")return;const A=Jn(T),U=Date.now();if(x.has(A)&&U-x.get(A)<5e3)return;if(x.set(A,U),x.size>500)for(const[I,$]of x)U-$>5e3&&x.delete(I);if(T.cwd){const I=T.cwd;t($=>{const O=$.find(rt=>rt.id===I);return _t($,[{id:I,root:I,label:Se(I),eventCount:((O==null?void 0:O.eventCount)??0)+1,sessionCount:Math.max((O==null?void 0:O.sessionCount)??0,1),lastEventTime:T.timestamp||Date.now()}])}),i($=>Ce($,T))}y(T.tool_name||T.hook_event_name||"event"),Me(T)&&(v.current+=1,l({sequence:v.current,event:T}))}catch{}},()=>_.close()},[]);function G(){N.current!==null&&(clearTimeout(N.current),N.current=null),k("idle")}async function B(x,_){G(),z(U=>U+1),k("loading...");const R=(await wt(`/api/history?project=${encodeURIComponent(x)}${_?"&persisted=1":""}`)).filter(Me).slice(-220);if(!R.length)return k("no events"),0;let T=0;const A=()=>{const U=R[T];v.current+=1,l({sequence:v.current,event:U}),T++,k(`${T}/${R.length}`),T<R.length?N.current=window.setTimeout(A,U.tool_name==="Bash"?160:90):(N.current=null,k(`done (${R.length})`))};return A(),R.length}async function V(x){const _={id:`hook-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,7)}`,session_id:"sakura-debug",timestamp:Date.now(),hook_event_name:"Notification",tool_name:null,tool_input:null,tool_response:null,agent_id:null,agent_type:null,cwd:null,error:null,tool_use_id:null,prompt:null,model:null,source:"hook",reason:null,permission_mode:null,is_interrupt:null,trigger:null,compact_summary:null,last_assistant_message:null,notification_type:null,title:null,agent_transcript_path:null,memory_type:null,...x};await Xt("/hook",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)})}P.useEffect(()=>{var x;!u&&((x=s[0])!=null&&x.id)&&C(s[0].id)},[s,u]),P.useEffect(()=>()=>G(),[]);const Z=_t(s,Object.entries(n).filter(([x])=>!s.some(_=>_.id===x)).map(([x,_])=>({id:x,root:x,label:Se(x),eventCount:_.eventCount,sessionCount:_.sessionCount,lastEventTime:_.lastEventTime}))).map(x=>({project:x,tree:e[x.id]??null,activity:n[x.id]??$e})),ot=Z.filter(x=>x.tree).length;return S.jsxs("div",{style:{position:"relative",width:"100vw",height:"100vh",overflow:"hidden",background:"#0e0a08"},children:[S.jsx(Yn,{projects:Z,latestSignal:a,resetSignal:L}),S.jsx("a",{href:"#/three",style:{position:"absolute",top:18,left:18,zIndex:20,padding:"10px 14px",border:"1px solid rgba(232,196,160,0.18)",background:"rgba(14,10,8,0.52)",color:"#e8c4a0",textDecoration:"none",fontFamily:"IBM Plex Mono, monospace",fontSize:11,letterSpacing:"0.08em",textTransform:"uppercase",backdropFilter:"blur(16px)"},children:"back to three"}),S.jsx("button",{onClick:()=>E(x=>!x),style:{position:"absolute",top:18,right:18,zIndex:21,padding:"8px 12px",border:"1px solid rgba(196,149,106,0.28)",background:"rgba(14,10,8,0.7)",color:"#c4956a",fontFamily:"IBM Plex Mono, monospace",fontSize:10,letterSpacing:"0.1em",textTransform:"uppercase",cursor:"pointer",backdropFilter:"blur(16px)"},children:F?"hide":"info"}),F&&S.jsxs("div",{style:{position:"absolute",top:52,right:18,zIndex:20,width:300,padding:"14px 16px",border:"1px solid rgba(255,255,255,0.08)",background:"linear-gradient(180deg, rgba(14,10,8,0.76), rgba(10,7,5,0.9))",backdropFilter:"blur(18px)",boxShadow:"0 18px 60px rgba(0,0,0,0.35)",color:"#e8d4c0",fontFamily:"IBM Plex Mono, monospace"},children:[S.jsx("div",{style:{fontSize:10,letterSpacing:"0.18em",textTransform:"uppercase",color:"#c4956a",marginBottom:6},children:"sakura"}),S.jsx("div",{style:{fontFamily:"Oxanium, sans-serif",fontSize:24,lineHeight:1,marginBottom:10},children:"live project tree"}),S.jsx("div",{style:{color:"#9a8070",fontSize:11,lineHeight:1.6,marginBottom:12},children:"Filesystem branches grow as a living sakura tree. Tool events flow as sap through branch ancestry."}),S.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:8,marginBottom:12},children:[S.jsxs("div",{children:[S.jsx("div",{style:{fontSize:10,color:"#786050",marginBottom:3},children:"link"}),S.jsx("div",{style:{fontSize:12},children:r})]}),S.jsxs("div",{children:[S.jsx("div",{style:{fontSize:10,color:"#786050",marginBottom:3},children:"trees"}),S.jsxs("div",{style:{fontSize:12},children:[ot,"/",Z.length]})]}),S.jsxs("div",{children:[S.jsx("div",{style:{fontSize:10,color:"#786050",marginBottom:3},children:"history"}),S.jsx("div",{style:{fontSize:12},children:d})]})]}),S.jsx("div",{style:{fontSize:10,color:"#786050",marginBottom:4},children:"last pulse"}),S.jsx("div",{style:{fontSize:12,marginBottom:12},children:f}),S.jsx("div",{style:{fontSize:10,color:"#786050",marginBottom:6},children:"active roots"}),S.jsx("div",{style:{display:"grid",gap:6,maxHeight:200,overflowY:"auto"},children:Z.slice(0,6).map(({project:x,tree:_,activity:W})=>S.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.03)",border:"1px solid rgba(255,255,255,0.05)"},children:[S.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8,marginBottom:3},children:[S.jsx("span",{style:{fontSize:11},children:x.label}),S.jsx("span",{style:{color:"#c4956a",fontSize:10},children:_?`${_.stats.totalNodes} nodes`:"loading"})]}),S.jsx("div",{style:{color:"#6a5a4a",fontSize:10,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:x.root}),S.jsxs("div",{style:{display:"flex",gap:8,marginTop:4,fontSize:10,color:"#8a7a6a"},children:[S.jsxs("span",{children:[W.eventCount," ev"]}),S.jsxs("span",{children:[x.sessionCount," ses"]}),S.jsx("span",{children:W.lastTool||"idle"})]})]},x.id))})]}),S.jsx(Kn,{isOpen:b,onToggle:()=>D(x=>!x),projects:Z,selectedProjectId:u,replayStatus:j,onSelectProject:C,onReplayProject:B,onStopReplay:G,onInjectEvent:V})]})}export{es as SakuraPage};