@fundamental-engine/vanilla 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  /*! @fundamental-engine/vanilla — single-file build (no bundler, no import map). See README "Vendor / CDN (single file)". MIT. */
2
- var Bs=Object.defineProperty;var Ws=(n,t,e)=>t in n?Bs(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var V=(n,t,e)=>Ws(n,typeof t!="symbol"?t+"":t,e);var ze="0.9.2";var mn=[{id:"attract",name:"Attract",color:"#4da3ff",does:"Pulls matter into a well",discipline:"Product strategy",verb:"gives direction",body:"attract",attrs:{"data-strength":"1","data-range":"300"},law:"a soft gravity-like well, bent into a spiral"},{id:"jet",name:"Jet",color:"#a78bfa",does:"Draws matter in, jets it out",discipline:"AI systems",verb:"adapts response",body:"jet",attrs:{"data-angle":"0","data-strength":"1","data-range":"300"},law:"recycles the field into a stream"},{id:"tether",name:"Tether",color:"#86e57f",does:"Tethers matter to a radius",discipline:"Software architecture",verb:"gives structure",body:"tether",attrs:{"data-strength":"1","data-range":"260"},law:"a rest length \u2014 a leash, not a drain"},{id:"wall",name:"Wall",color:"#c4b5fd",does:"A surface that bounces \u2014 throws sparks",discipline:"Experience design",verb:"the human surface",body:"wall",attrs:{},law:"elastic bounce off the bounding box"},{id:"stream",name:"Stream",color:"#7dd3fc",does:"Blows a directional current",discipline:"Motion",verb:"reveals motion",body:"stream",attrs:{"data-angle":"0","data-strength":"1","data-range":"340"},law:"constant force along a heading"},{id:"repel",name:"Repel",color:"#ff9d5c",does:"Pushes matter away",discipline:"Commerce",verb:"market pressure",body:"repel",attrs:{"data-strength":"1.1","data-range":"300"},law:"inverted well \u2014 carves a clean void"},{id:"viscosity",name:"Viscosity",color:"#8da2c0",does:"Thickens the medium",discipline:"Physical production",verb:"adds constraint",body:"viscosity",attrs:{"data-strength":"1","data-range":"300"},law:"viscosity \u2014 bleeds momentum off"},{id:"swirl",name:"Swirl",color:"#2dd4bf",does:"Spins matter into a swirl",discipline:"Creative technology",verb:"spins it together",body:"swirl",attrs:{"data-spin":"1","data-strength":"1","data-range":"320"},law:"tangential force \u2014 circles, never collapses"},{id:"sink",name:"Sink",color:"#ff6e9c",does:"Swallows matter, then pops",discipline:"Attention",verb:"holds, then releases",body:"sink attract",attrs:{"data-absorb":"64","data-max":"30","data-strength":"0.8","data-range":"360"},law:"accretion, then supernova"}],vo=Object.fromEntries(mn.map(n=>[n.id,n])),pn=mn.map(n=>n.color),ae=["#4da3ff","#2dd4bf","#a78bfa","#ff6e9c","#ff9d5c"],yn=["spotlight","screen","resonate"],qs=["spawn"],gn=300,xn=120;function Hs(n){return yn.includes(n)?"modifier":qs.includes(n)?"source":"force"}function Fe(n){let t=[],e=[],r=[];for(let s of n){let i=Hs(s);i==="modifier"?t.push(s):i==="source"?r.push(s):e.push(s)}return t.length>1&&t.sort((s,i)=>yn.indexOf(s)-yn.indexOf(i)),{modifiers:t,forces:e,sources:r}}var wo=[{id:"ambient",name:"Ambient",section:"Hero",color:"#4da3ff",cue:"resting drift",preset:{driftX:0,wander:1,orbit:.1,spread:0,conv:0}},{id:"wells",name:"Wells",section:"Work",color:"#2dd4bf",cue:"matter pools",preset:{driftX:0,wander:.7,orbit:.85,spread:0,conv:0}},{id:"lanes",name:"Lanes",section:"Writing",color:"#ff9d5c",cue:"a current carries",preset:{driftX:.55,wander:.5,orbit:0,spread:0,conv:0}},{id:"scatter",name:"Scatter",section:"Practice",color:"#a78bfa",cue:"energy dispersed",preset:{driftX:0,wander:1.7,orbit:0,spread:.6,conv:0}},{id:"accretion",name:"Accretion",section:"Contact",color:"#ffce6b",cue:"everything gathers",preset:{driftX:0,wander:.6,orbit:.4,spread:0,conv:.6}}],Te=Object.fromEntries(wo.map(n=>[n.id,n]));var bo=[{id:"",name:"Always",desc:"Acts on every particle, every frame.",selective:!1},{id:"active",name:"Active",desc:"Only while the body is engaged.",selective:!1},{id:"fast",name:"Fast",desc:"Only on fast-moving matter (v\xB2 > 0.9).",selective:!0},{id:"slow",name:"Slow",desc:"Only on calm matter (v\xB2 < 0.22).",selective:!0},{id:"hot",name:"Hot",desc:"Only on energized matter (heat > 0.3).",selective:!0},{id:"cool",name:"Cool",desc:"Only on calm, un-energized matter (heat < 0.08).",selective:!0},{id:"scrolling",name:"Scrolling",desc:"Only while the page is scrolling.",selective:!1}],Fa=Object.fromEntries(bo.map(n=>[n.id,n]));var js={ours:ae,heatmap:["#2b3a8c","#2d8fd4","#3fd07a","#ffe14d","#ff8a3d","#e23b3b"],infrared:["#2a0a4a","#8e24aa","#e53935","#ff8f00","#ffd54f","#fffde7"],spectrum:["#ff3b30","#ff9500","#ffcc00","#34c759","#00c7be","#007aff","#af52de"]};function Ae(n){return Array.isArray(n)?n.length>0?n:ae:typeof n=="string"?js[n]??ae:ae}var vn={warm:{cool:[255,224,200],warm:[255,110,80],wave:["#ff8a5c","#f0628e","#ffc46b"]},cool:{cool:[206,226,255],warm:[74,132,255],wave:["#5c8aff","#62a0f0","#6bc4ff"]},mono:{cool:[232,232,238],warm:[148,148,158],wave:["#8a8a96","#b0b0bc","#9a9aa6"]}},wn="warm";var bt=(n,t,e)=>n<t?t:n>e?e:n;function gt(n){let t=n.replace("#",""),e=t.length===3?t.replace(/./g,s=>s+s):t,r=Number.parseInt(e.slice(0,6),16);return Number.isNaN(r)?[77,163,255]:[r>>16&255,r>>8&255,r&255]}var Ys=[255,224,200],Us=[255,110,80];function Mo(n,t,e,r,s=Ys,i=Us){let a=s[0]+(i[0]-s[0])*t,h=s[1]+(i[1]-s[1])*t,m=s[2]+(i[2]-s[2])*t;return a+=(r[0]-a)*e,h+=(r[1]-h)*e,m+=(r[2]-m)*e,n[0]=a,n[1]=h,n[2]=m,n}function bn([n,t,e]){let r=s=>bt(Math.round(s),0,255).toString(16).padStart(2,"0");return`#${r(n)}${r(t)}${r(e)}`}function ko(n,t,e){let[r,s,i]=gt(n),[a,h,m]=gt(t),p=e<0?0:e>1?1:e;return bn([r+(a-r)*p,s+(h-s)*p,i+(m-i)*p])}function Mn(n,t){if(n.length===0)return[77,163,255];if(n.length===1)return n[0];let e=bt(t,0,1)*(n.length-1),r=Math.min(n.length-2,Math.floor(e)),s=e-r,i=n[r],a=n[r+1];return[i[0]+(a[0]-i[0])*s,i[1]+(a[1]-i[1])*s,i[2]+(a[2]-i[2])*s]}function Eo(n,t,e,r=0){if(!(t>0))return 1;let s=Math.max(0,1-n/t),i=1-e*s*s,a=Math.min(Math.max(r,0),1);return i<a?a:i>1?1:i}var Ce=1;function Oe(n){let t=n.ux!==0?n.hw/Math.abs(n.ux):1/0,e=n.uy!==0?n.hh/Math.abs(n.uy):1/0,r=Math.min(t,e),s=n.ux*r,i=n.uy*r,a=n.spin<0?-1:1;return[{x:n.cx+s,y:n.cy+i,q:a},{x:n.cx-s,y:n.cy-i,q:-a}]}function So(n,t,e){let r=0,s=0;for(let i of n){let a=t-i.x,h=e-i.y,m=Math.max(Ce,Math.hypot(a,h)),p=i.q/(m*m);r+=a/m*p,s+=h/m*p}return{x:r,y:s}}function zo(n,t){let e=n/20+(t?.45:0);return e<0?0:e>1?1:e}function Fo(n,t,e){return Math.round(n+(t-n)*e)}function To(n,t={}){let e=t.beta??2,r=t.lo??.25,s=t.hi??3,i=n.length,a=new Array(i).fill(1);if(i===0)return a;let h=0,m=0;for(let y of n){let b=y.strength>0?y.strength:0;h+=b,m+=b*(1+(y.on?e:0))}if(h<=0||m<=0)return a;let p=h/m;for(let y=0;y<i;y++){let E=(1+(n[y].on?e:0))*p;E<r?E=r:E>s&&(E=s),a[y]=E}return a}function Ao(n,t={}){let e=t.threshold??.55,r=t.kappa??.6,s=t.falloff??320,i=n.length,a=new Array(i).fill(0);if(i<2)return a;let h=new Array(i).fill(0);for(let m=0;m<i;m++){let p=n[m],y=p.d-e;if(y<=0)continue;let b=0;for(let M=0;M<i;M++){if(M===m){h[M]=0;continue}let S=n[M],A=Math.hypot(p.cx-S.cx,p.cy-S.cy),N=A<s?1-A/s:0;h[M]=N,b+=N}if(b<=0)continue;let E=r*y;for(let M=0;M<i;M++){let S=h[M];if(S<=0)continue;let A=E*S/b;a[M]+=A,a[m]-=A}}return a}var Co=n=>`${n.from}\0${n.to}\0${n.type}`;function kn(n,t){let e=[],r=new Map(n.bodies.map(M=>[M.id,M])),s=new Map(t.bodies.map(M=>[M.id,M]));for(let[M,S]of r){let A=s.get(M);if(!A){e.push({id:M,kind:"removed"});continue}let N={},C=!1,H=new Set([...Object.keys(S.metrics),...Object.keys(A.metrics)]);for(let u of H){let K=S.metrics[u]??0,Z=A.metrics[u]??0;K!==Z&&(N[u]={from:K,to:Z},C=!0)}C&&e.push({id:M,kind:"changed",metrics:N})}for(let M of s.keys())r.has(M)||e.push({id:M,kind:"added"});let i=[],a=new Map(n.relationships.map(M=>[Co(M),M])),h=new Map(t.relationships.map(M=>[Co(M),M]));for(let[M,S]of a){let A=h.get(M);if(!A){i.push({from:S.from,to:S.to,type:S.type,kind:"removed"});continue}let N={from:S.from,to:S.to,type:S.type,kind:"changed"},C=!1;S.strength!==A.strength&&(N.strength={from:S.strength,to:A.strength},C=!0),S.active!==A.active&&(N.active={from:S.active,to:A.active},C=!0),C&&i.push(N)}for(let[M,S]of h)a.has(M)||i.push({from:S.from,to:S.to,type:S.type,kind:"added"});let m=[],p=new Set([...Object.keys(n.metrics),...Object.keys(t.metrics)]);for(let M of p){let S=n.metrics[M]??0,A=t.metrics[M]??0;S!==A&&m.push({key:M,from:S,to:A})}let y=[],b=new Set(n.formations),E=new Set(t.formations);for(let M of E)b.has(M)||y.push({id:M,kind:"activated"});for(let M of b)E.has(M)||y.push({id:M,kind:"deactivated"});return{from:n.id,to:t.id,bodyChanges:e,relationshipChanges:i,metricChanges:m,formationChanges:y}}function Oo(n,t,e={}){let r=y=>Math.round(y*1e3)/1e3,s=kn(n,t),i=t.frame,a=t.createdAt,h=[],m=(y,b,E={})=>{h.push({frame:i,time:a,cause:y,description:b,...E})};for(let y of s.formationChanges)m("formation",`Formation '${y.id}' ${y.kind}`,{source:y.id});for(let y of s.relationshipChanges){let b;if(y.kind==="added")b="formed";else if(y.kind==="removed")b="dissolved";else{let E=[];if(y.active&&E.push(y.active.to?"became active":"went idle"),y.strength){let M=y.strength.to>=y.strength.from?"strengthened":"weakened";E.push(`${M} ${r(y.strength.from)}\u2192${r(y.strength.to)}`)}b=E.join(", ")||"changed"}m("relationship",`Relationship ${y.from}\u2192${y.to} (${y.type}) ${b}`,{source:y.from,target:y.to,contribution:y.strength})}for(let y of s.bodyChanges)if(y.kind==="added")m("measurement",`Body ${y.id} entered the field`,{source:y.id});else if(y.kind==="removed")m("measurement",`Body ${y.id} left the field`,{source:y.id});else if(y.metrics)for(let[b,E]of Object.entries(y.metrics)){let M=E.to>E.from?"rose":"fell";m("metric",`Body ${y.id} ${b} ${M} ${r(E.from)}\u2192${r(E.to)}`,{source:y.id,contribution:E})}if(n.influences&&t.influences){let y=S=>typeof S=="number"?Math.abs(S):Math.hypot(S.x,S.y,S.z??0),b=S=>`${S.source} ${S.force} ${S.channel??"linear"}`,E=new Map(n.influences.map(S=>[b(S),S])),M=new Map(t.influences.map(S=>[b(S),S]));for(let S of new Set([...E.keys(),...M.keys()])){let A=E.get(S),N=M.get(S),C=A?y(A.contribution):0,H=N?y(N.contribution):0;if(Math.abs(H-C)<1e-9)continue;let u=N??A,K=H>C?C===0?"engaged":"grew":H===0?"released":"weakened",Z=(u.channel??"linear")==="thermal"?" (thermal)":"";m("force",`Force ${u.force} on ${u.source}${Z} ${K} ${r(C)}\u2192${r(H)}`,{source:u.source,contribution:{from:C,to:H}})}}let p=e.focus?h.filter(y=>y.source===e.focus||y.target===e.focus):h;return{from:n.id,to:t.id,focus:e.focus,steps:p}}var Pe=class{constructor(t=64){V(this,"cell");V(this,"bins",new Map);this.cell=t>0?t:64}key(t,e){return(t+32768)*65536+(e+32768)}clear(){this.bins.clear()}insert(t){let e=this.key(Math.floor(t.x/this.cell),Math.floor(t.y/this.cell)),r=this.bins.get(e);r?r.push(t):this.bins.set(e,[t])}rebuild(t){this.clear();for(let e of t)this.insert(e)}near(t,e,r,s=0){let i=[],a=r*r,h=Math.floor((t-r)/this.cell),m=Math.floor((t+r)/this.cell),p=Math.floor((e-r)/this.cell),y=Math.floor((e+r)/this.cell);for(let b=h;b<=m;b++)for(let E=p;E<=y;E++){let M=this.bins.get(this.key(b,E));if(M)for(let S of M){let A=S.x-t,N=S.y-e,C=(S.z??0)-s;A*A+N*N+C*C<=a&&i.push(S)}}return i}};var Re=class{constructor(t=64){V(this,"particles",[]);V(this,"hash");this.hash=new Pe(t)}get size(){return this.particles.length}add(t){return this.particles.push(t),t}remove(t){let e=this.particles.indexOf(t);if(e<0)return;let r=this.particles.pop();r&&e<this.particles.length&&(this.particles[e]=r)}clear(){this.particles.length=0,this.hash.clear()}reindex(){this.hash.rebuild(this.particles)}neighbors(t,e){let r=this.hash.near(t.x,t.y,e,t.z??0),s=[];for(let i of r)i!==t&&s.push(i);return s}near(t,e,r){return this.hash.near(t,e,r)}};function Po(n,t,e=.03){n.driftX+=(t.driftX-n.driftX)*e,n.wander+=(t.wander-n.wander)*e,n.orbit+=(t.orbit-n.orbit)*e,n.spread+=(t.spread-n.spread)*e,n.conv+=(t.conv-n.conv)*e}function Ro(n){for(let t of n)if(t.vis&&t.tokens.indexOf("sink")>=0)return t;return null}var Gs=[.24,.4,.55,.7,.85];function $o(n){let t=[];for(let e=0;e<5;e++)t.push({baseFrac:Gs[e]??.5,amp:22+e*15,freq:.0012+e*8e-4,phase:e*1.7%6.28,speed:13e-5+e*9e-5,color:n[e%n.length]??[77,163,255],depth:e/4,dir:e%2?-1:1,offsetY:0});return t}function Io(n,t,e){let r=Math.round(16*t),s=[];for(let i=0;i<n;i++)for(let a=0;a<r;a++)s.push({wi:i,progress:e(),phase:(e()-.5)*.22*Math.PI,size:.7+e()*1.5,glow:e()<.3,speed:(35e-5+e()*9e-4)*(e()<.5?1:-1)});return s}function Et(n,t,e,r,s=1,i=1,a){let h=n.baseFrac*r+n.offsetY+Math.sin(t*n.freq+n.phase+e*n.speed*1e3*s)*n.amp*i;if(a&&a.k>.001){let m=t-a.x,p=260,y=Math.exp(-(m*m)/(2*p*p));h+=(a.y-h)*.42*y*a.k*(.45+n.depth*.55)}return h}function No(n,t,e,r=1,s=1){return Math.cos(t*n.freq+n.phase+e*n.speed*1e3*r)*n.amp*n.freq*s}function ce(n,t,e,r,s=1,i=1){let a=n.baseFrac*r+n.offsetY,h=Math.max(1,Math.round(n.freq*2500));return a+Math.sin(h*t+n.phase+e*n.speed*1e3*s)*n.amp*i}function Do(n,t,e,r,s,i,a,h,m=1,p=1,y){if(a==="circular"){let b=t-h.x,E=e-h.y,M=Math.sqrt(b*b+E*E)||.001,S=Math.atan2(E,b),A=Math.min(s,i)*.48,N=ce(n,S,r,A,m,p);return{dist:Math.abs(M-N),rWave:N,r:M,theta:S}}else{let b=Et(n,t,r,i,m,p,y);return{dist:Math.abs(e-b),rWave:b,r:e,theta:0}}}var Ut={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null};function Vt(n,t,e,r,s){Ut.x=r,Ut.y=s,Ut.vx=0,Ut.vy=0,Ut.heat=0;let i=0,a=0;for(let h of n){if(!h.vis||h.tokens.length===0)continue;let m,p;if(h.shaped){let E=h.cx-h.hw,M=h.cx+h.hw,S=h.cy-h.hh,A=h.cy+h.hh;m=(r<E?E:r>M?M:r)-r,p=(s<S?S:s>A?A:s)-s}else m=h.cx-r,p=h.cy-s;let y=m*m+p*p;if(h.range>0&&y>=h.range*h.range*2.56)continue;let b=Math.sqrt(y);e.dx=m,e.dy=p,e.dist=b<1?1:b;for(let E of h.tokens){let M=t[E];if(!(!M||M.modify))if(M.field){let S=M.field(h,r,s);i+=S.x,a+=S.y}else M.apply(h,Ut,e)}}return{fx:Ut.vx+i,fy:Ut.vy+a}}function $e(n,t,e,r){let s=0,i=0;for(let a of n)if(!(!a.vis||a.tokens.length===0)){if(a.range>0){let h=a.cx-e,m=a.cy-r;if(h*h+m*m>=a.range*a.range*2.56)continue}for(let h of a.tokens){let m=t[h];if(m?.field){let p=m.field(a,e,r);s+=p.x,i+=p.y}}}return{x:s,y:i}}var Lo=.95,_o=.972,Ft=10;function Vs(n,t,e,r){if(!t.when)return!0;let s=n[t.when];return s?s(t,e,r):!0}function Bo(n){return n.classified??(n.classified=Fe(n.tokens))}function Sn(n,t,e,r,s=1){let i=e.vx,a=e.vy,h=e.vz??0,m=e.heat,p=e.spin??0,y=e.age;n.apply(t,e,r),s===1||n.kinematic||(e.vx=i+(e.vx-i)*s,e.vy=a+(e.vy-a)*s,e.vz!==void 0&&(e.vz=h+(e.vz-h)*s));let b=r.accum;if(b!==void 0){let E=e.vx-i,M=e.vy-a,S=(e.vz??0)-h;(E!==0||M!==0||S!==0)&&(b.linear.x+=E,b.linear.y+=M,b.linear.z+=S,b.attribution.push({force:n.token,channel:"linear",contribution:{x:E,y:M,z:S}}));let A=e.heat-m;A!==0&&(b.thermal=(b.thermal??0)+A,b.attribution.push({force:n.token,channel:"thermal",contribution:A}));let N=(e.spin??0)-p;if(N!==0){let C=b.angular??(b.angular={x:0,y:0,z:0});C.z+=N,b.attribution.push({force:n.token,channel:"angular",contribution:N})}if(y!==void 0&&e.age!==void 0){let C=e.age-y;if(C!==0){let H=b.temporal??(b.temporal={});H.decay=(H.decay??0)+C,b.attribution.push({force:n.token,channel:"temporal",contribution:C})}}t.attn!==void 0&&t.attn!==1&&((b.semantic??(b.semantic={})).attention=t.attn,b.attribution.push({force:n.token,channel:"semantic",contribution:t.attn}))}}function En(n,t,e,r,s){if(r.accum===void 0){if(s===1||n.kinematic){n.apply(t,e,r);return}let i=e.vx,a=e.vy,h=e.vz??0;n.apply(t,e,r),e.vx=i+(e.vx-i)*s,e.vy=a+(e.vy-a)*s,e.vz!==void 0&&(e.vz=h+(e.vz-h)*s);return}Sn(n,t,e,r,s)}function Wo(){return{linear:{x:0,y:0,z:0},attribution:[]}}function qo(n){let{store:t,bodies:e,env:r,forces:s,conditions:i,waves:a,separation:h}=n,m=r.dt;if(m===0)return;let{W:p,H:y,form:b}=r;r.fieldAt=(u,K)=>$e(e,s,u,K);for(let u of e){u.count=0;let K=u.thermo;K&&(K.n=0,K.sx=0,K.sy=0,K.ss=0,K.ss2=0,K.sh=0)}let E=null;for(let u of e)u.vis&&u.tokens.length>0&&Bo(u).modifiers.indexOf("screen")>=0&&(E??(E=[])).push(u);let M=E?new Array(E.length):null,S=!!a&&a.length>0,A=e.length>0,N=null,C=b.conv>.02?Ro(e):null,H=r.D??0;for(let u of t.particles){if(u.cap){u.x+=(u.cap.cx-u.x)*.18,u.y+=(u.cap.cy-u.y)*.18,u.z&&(u.z+=-u.z*.18);continue}u.z===void 0&&(u.z=0),u.vz===void 0&&(u.vz=0);let K=u.z;if(S)if(n.waveStyle==="circular"){let Y=null,P=1e9,U=0,Q=0,B=0,ft=n.waveCenter||{x:p/2,y:y/2};for(let rt of a){let vt=Do(rt,u.x,u.y,r.t,p,y,"circular",ft);vt.dist<P&&(P=vt.dist,Y=rt,U=vt.r,Q=vt.rWave,B=vt.theta)}if(Y&&P<70){let rt=1-P/70,vt=-Math.sin(B)*Y.dir,$=Math.cos(B)*Y.dir;u.vx+=vt*.035*rt,u.vy+=$*.035*rt;let tt=Math.cos(B)*Math.sign(Q-U),L=Math.sin(B)*Math.sign(Q-U);u.vx+=tt*.05*rt,u.vy+=L*.05*rt}}else{let Y=null,P=1e9;for(let U of a){let Q=Math.abs(Et(U,u.x,r.t,y)-u.y);Q<P&&(P=Q,Y=U)}Y&&P<70&&(u.vx+=Y.dir*.035*(1-P/70),u.vy+=No(Y,u.x,r.t)*.1*(1-P/70))}if(b.driftX&&(u.vx+=b.driftX*.02),b.spread>.02){let Y=u.gx??.5,P=u.gy??.5,U=(Y+r.frameN*4e-5)%1*p,Q=P*y;u.vx+=(U-u.x)*6e-4*b.spread,u.vy+=(Q-u.y)*6e-4*b.spread,H>0&&(u.vz+=((u.gz??.5)*H-K)*6e-4*b.spread)}if(C){let Y=C.cx-u.x,P=C.cy-u.y,U=-K,Q=Math.hypot(Y,P,U)||1;u.vx+=Y/Q*b.conv*.06,u.vy+=P/Q*b.conv*.06,u.vz+=U/Q*b.conv*.06}if(A){if(E)for(let P=0;P<E.length;P++){let U=E[P],Q=U.cx-u.x,B=U.cy-u.y;M[P]=Eo(Math.sqrt(Q*Q+B*B),U.range,U.strength,U.screenMin??0)}let Y=u.m!==1&&u.m>0?1/u.m:1;for(let P of e){if(!P.vis||P.tokens.length===0||P.affects!==void 0&&!P.affects.has(u.species??0))continue;let U,Q;if(P.shaped){let G=P.cx-P.hw,st=P.cx+P.hw,dt=P.cy-P.hh,Xt=P.cy+P.hh,ue=u.x<G?G:u.x>st?st:u.x,It=u.y<dt?dt:u.y>Xt?Xt:u.y;U=ue-u.x,Q=It-u.y}else U=P.cx-u.x,Q=P.cy-u.y;let B=-u.z,ft=U*U+Q*Q+B*B;if(P.range>0&&ft>=P.range*P.range*2.56)continue;let rt=Math.sqrt(ft);if(P.feedback&&rt<P.range*.5){P.count+=1-rt/(P.range*.5);let G=P.thermo??(P.thermo={n:0,sx:0,sy:0,ss:0,ss2:0,sh:0}),st=u.vx*u.vx+u.vy*u.vy;G.n++,G.sx+=u.vx,G.sy+=u.vy,G.ss+=Math.sqrt(st),G.ss2+=st,G.sh+=u.heat}if(P.when&&!Vs(i,P,u,r))continue;r.dx=U,r.dy=Q,r.dz=B,r.dist=rt<1?1:rt;let vt=Bo(P),$=1,tt=!1,L=!1;for(let G of vt.modifiers){let st=s[G]?.modify;if(!st)continue;L=!0;let dt=st(P,u,r);dt.strength!=null&&($*=dt.strength),dt.gate&&(tt=!0)}for(let G of vt.forces){let st=s[G]?.modify;if(!st)continue;L=!0;let dt=st(P,u,r);dt.strength!=null&&($*=dt.strength),dt.gate&&(tt=!0)}if(tt)continue;let _=1;if(E)for(let G=0;G<E.length;G++)E[G]!==P&&(_*=M[G]);let D=P.attn??1,St=$*D*_;if(!L&&St===1)for(let G of P.tokens){let st=s[G];st&&En(st,P,u,r,Y)}else if(L){let G=P.strength;P.strength=G*St;for(let st of P.tokens){let dt=s[st];dt&&!dt.modify&&En(dt,P,u,r,Y)}P.strength=G}else{let G=P.strength;P.strength=G*St;for(let st of P.tokens){let dt=s[st];dt&&En(dt,P,u,r,Y)}P.strength=G}}}if(h&&h>0){let Y=r.neighbors(u,12);for(let P of Y){let U=u.x-P.x,Q=u.y-P.y,B=(u.z??0)-(P.z??0),ft=Math.hypot(U,Q,B)||.1;if(ft<12){let rt=(12-ft)/12*h*.12;u.vx+=U/ft*rt,u.vy+=Q/ft*rt,u.vz!==void 0&&(u.vz+=B/ft*rt)}}}let Z=r.c,lt=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(lt>Z*Z){let Y=Z/Math.sqrt(lt);u.vx*=Y,u.vy*=Y,u.vz*=Y}if(u.maxSpeed!==void 0){let Y=u.maxSpeed*u.maxSpeed,P=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(P>Y){let U=u.maxSpeed/Math.sqrt(P);u.vx*=U,u.vy*=U,u.vz*=U}}u.x+=u.vx*m,u.y+=u.vy*m,u.z+=u.vz*m;let mt=r.integrator==="fixed"?Math.pow(Lo,m):Lo;if(u.vx*=mt,u.vy*=mt,u.vz*=mt,u.spin!==void 0&&(u.orient=(u.orient??0)+u.spin*m,u.spin*=mt),u.report===void 0){if(r.frameN%40===0&&b.wander>0){let Y=.05*b.wander;u.vx+=((r.rng??Math.random)()-.5)*Y,u.vy+=((r.rng??Math.random)()-.5)*Y,H>0&&(u.vz+=((r.rng??Math.random)()-.5)*Y)}if(b.wander>.05){let Y=(Math.sin(u.x*.0032+r.t*.12)+Math.cos(u.y*.0034-r.t*.15))*Math.PI;u.vx+=Math.cos(Y)*.013*b.wander,u.vy+=Math.sin(Y)*.013*b.wander}}u.heat*=r.integrator==="fixed"?Math.pow(_o,m):_o,u.age!=null&&(u.age-=m,u.age<=0&&(N??(N=[])).push(u)),u.report===void 0?(u.x<-Ft?u.x=p+Ft:u.x>p+Ft&&(u.x=-Ft),u.y<-Ft?u.y=y+Ft:u.y>y+Ft&&(u.y=-Ft),H>0&&(u.z<-Ft?u.z=H+Ft:u.z>H+Ft&&(u.z=-Ft))):(u.x<0?(u.x=0,u.vx=Math.abs(u.vx)):u.x>p&&(u.x=p,u.vx=-Math.abs(u.vx)),u.y<0?(u.y=0,u.vy=Math.abs(u.vy)):u.y>y&&(u.y=y,u.vy=-Math.abs(u.vy)),H>0&&(u.z<0?(u.z=0,u.vz=Math.abs(u.vz)):u.z>H&&(u.z=H,u.vz=-Math.abs(u.vz))),u.report(u))}if(A){for(let u of e)if(!(!u.vis||u.tokens.length===0))for(let K of u.tokens)s[K]?.source?.(u,r)}if(N)for(let u of N)t.remove(u)}var oe=class{constructor(t,e,r="diffuse",s=32){V(this,"mode");V(this,"cell");V(this,"W");V(this,"H");V(this,"cols");V(this,"rows");V(this,"cur");V(this,"nxt");V(this,"prev");this.W=t,this.H=e,this.mode=r,this.cell=s,this.cols=Math.max(2,Math.ceil(t/s)+1),this.rows=Math.max(2,Math.ceil(e/s)+1);let i=this.cols*this.rows;this.cur=new Float32Array(i),this.nxt=new Float32Array(i),this.prev=new Float32Array(i)}clampCol(t){return t<0?0:t>=this.cols?this.cols-1:t}clampRow(t){return t<0?0:t>=this.rows?this.rows-1:t}at(t,e){return this.cur[this.clampRow(e)*this.cols+this.clampCol(t)]}sample(t,e){let r=t/this.cell,s=e/this.cell,i=Math.floor(r),a=Math.floor(s),h=r-i,m=s-a,p=this.at(i,a)*(1-h)+this.at(i+1,a)*h,y=this.at(i,a+1)*(1-h)+this.at(i+1,a+1)*h;return p*(1-m)+y*m}deposit(t,e,r){let s=this.clampCol(Math.round(t/this.cell)),i=this.clampRow(Math.round(e/this.cell));this.cur[i*this.cols+s]+=r}max(){let t=0;for(let e=0;e<this.cur.length;e++)this.cur[e]>t&&(t=this.cur[e]);return t}gradient(t,e){let r=this.cell;return{x:(this.sample(t+r,e)-this.sample(t-r,e))/(2*r),y:(this.sample(t,e+r)-this.sample(t,e-r))/(2*r)}}step(){this.mode==="wave"?this.stepWave():this.mode==="memory"?this.stepDiffuse(.03,.004):this.stepDiffuse()}stepDiffuse(t=.18,e=.01){let r=t<0?0:t>.24?.24:t,s=1-e,{cols:i,rows:a,cur:h,nxt:m}=this;for(let p=0;p<a;p++)for(let y=0;y<i;y++){let b=p*i+y,E=this.at(y-1,p)+this.at(y+1,p)+this.at(y,p-1)+this.at(y,p+1)-4*h[b];m[b]=(h[b]+r*E)*s}this.cur=m,this.nxt=h}stepWave(t=.25,e=.002){let r=t<0?0:t>.5?.5:t,s=1-e,{cols:i,rows:a,cur:h,prev:m,nxt:p}=this;for(let y=0;y<a;y++)for(let b=0;b<i;b++){let E=y*i+b,M=this.at(b-1,y)+this.at(b+1,y)+this.at(b,y-1)+this.at(b,y+1)-4*h[E];p[E]=(2*h[E]-m[E]+r*M)*s}this.prev=h,this.cur=p,this.nxt=m}decay(t){let e=t<=0?1:t>=1?0:1-t;if(e!==1)for(let r=0;r<this.cur.length;r++)this.cur[r]*=e}clear(){this.cur.fill(0),this.nxt.fill(0),this.prev.fill(0)}resize(t,e){if(t===this.W&&e===this.H)return;this.W=t,this.H=e,this.cols=Math.max(2,Math.ceil(t/this.cell)+1),this.rows=Math.max(2,Math.ceil(e/this.cell)+1);let r=this.cols*this.rows;this.cur=new Float32Array(r),this.nxt=new Float32Array(r),this.prev=new Float32Array(r)}};var Ho={active:n=>n.on,fast:(n,t)=>t.vx*t.vx+t.vy*t.vy+(t.vz??0)*(t.vz??0)>.9,slow:(n,t)=>t.vx*t.vx+t.vy*t.vy+(t.vz??0)*(t.vz??0)<.22,hot:(n,t)=>t.heat>.3,cool:(n,t)=>t.heat<.08,scrolling:(n,t,e)=>(e?.scrollV??0)>.25};function jo(){let n={},t={...Ho};return{forces:n,conditions:t,force(e){n[e.token]=e},condition(e,r){t[e]=r}}}var Xs={token:"attract",label:"Attract",apply(n,t,e){let r=n.range*(n.on?1.5:1),s=n.strength*(n.on?3:1);if(e.dist>=r)return;let i=(1-e.dist/r)**2*s*.5,a=e.dx/e.dist,h=e.dy/e.dist;t.vx+=a*i,t.vy+=h*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i),e.form.orbit&&(t.vx+=-h*i*e.form.orbit,t.vy+=a*i*e.form.orbit),n.on&&(t.heat=Math.max(t.heat,(1-e.dist/r)*.9))},meta:{desc:"a soft gravity-like well, bent into a spiral"}},Js={token:"repel",label:"Repel",apply(n,t,e){let r=n.range*(n.on?1.4:1),s=n.strength*(n.on?2:1);if(e.dist>=r)return;let i=(1-e.dist/r)**2*s*.5;t.vx-=e.dx/e.dist*i,t.vy-=e.dy/e.dist*i,e.dz&&(t.vz=(t.vz??0)-e.dz/e.dist*i)},meta:{desc:"inverse-square outward push"}},Ks={token:"swirl",label:"Swirl",apply(n,t,e){let r=n.range*(n.on?1.4:1),s=n.strength*(n.on?2:1);if(e.dist>=r)return;let i=(1-e.dist/r)**1.4*s*.45,a=n.spin,h=e.dx/e.dist,m=e.dy/e.dist;t.vx+=m*i*a+h*i*.12,t.vy+=-h*i*a+m*i*.12,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i*.12),n.on&&(t.heat=Math.max(t.heat,(1-e.dist/r)*.6))},meta:{desc:"tangential swirl with light inward retention"}},Qs={token:"stream",label:"Stream",apply(n,t,e){let r=n.range*(n.on?1.4:1),s=n.strength*(n.on?2:1);if(e.dist>=r)return;let i=(1-e.dist/r)**1.1*s*.5;t.vx+=n.ux*i,t.vy+=n.uy*i,n.on&&(t.heat=Math.max(t.heat,(1-e.dist/r)*.5))},meta:{desc:"directional current along a heading"}},Zs={token:"viscosity",label:"Viscosity",apply(n,t,e){let r=n.range*(n.on?1.4:1);if(e.dist>=r)return;let s=(1-e.dist/r)*(.05+n.strength*.07)*(n.on?1.6:1);t.vx-=t.vx*s,t.vy-=t.vy*s,t.vz&&(t.vz-=t.vz*s)},meta:{desc:"thickens the medium \u2014 bleeds momentum"}},ti={token:"jet",label:"Jet",kinematic:!0,apply(n,t,e){let r=n.range*(n.on?1.4:1);if(!(e.dist>=r))if(e.dist<24){let s=((e.rng??Math.random)()-.5)*.8,i=Math.cos(s),a=Math.sin(s),h=n.ux*i-n.uy*a,m=n.ux*a+n.uy*i,p=2.4+n.strength*2.6;t.vx=h*p,t.vy=m*p,t.x=n.cx+h*26,t.y=n.cy+m*26,t.z&&(t.z=0),t.vz&&(t.vz=0),t.heat=Math.max(t.heat,.9)}else{let s=(1-e.dist/r)**2*(.25+n.strength*.15);t.vx+=e.dx/e.dist*s,t.vy+=e.dy/e.dist*s,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*s)}},meta:{desc:"a fountain \u2014 draws matter in, jets it out along a heading"}},ei={token:"tether",label:"Tether",apply(n,t,e){let r=n.range*.6*(n.on?1.25:1),s=r*2.1;if(e.dist>=s)return;let i=(.006+n.strength*.012)*(n.on?1.7:1),a=e.dist-r,h=e.dx/e.dist,m=e.dy/e.dist;t.vx+=h*a*i,t.vy+=m*a*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*a*i),t.vx*=.985,t.vy*=.985,t.vz&&(t.vz*=.985),n.on&&(t.heat=Math.max(t.heat,(1-Math.min(1,Math.abs(a)/r))*.5))},meta:{desc:"a tether with a rest length \u2014 holds matter at a fixed radius"}},ni={token:"wall",label:"Wall",kinematic:!0,apply(n,t,e){let s=Math.abs(t.x-n.cx),i=Math.abs(t.y-n.cy);if(s>=n.hw+6||i>=n.hh+6)return;let a=Math.hypot(t.vx,t.vy),h=n.hw+6-s,m=n.hh+6-i;h<m?(t.x=t.x<n.cx?n.cx-n.hw-6:n.cx+n.hw+6,t.vx=-t.vx*.85):(t.y=t.y<n.cy?n.cy-n.hh-6:n.cy+n.hh+6,t.vy=-t.vy*.85),a>.7&&(e.spark(t.x,t.y,Math.min(2.4,a),n.tint??vo.wall.color),t.heat=Math.max(t.heat,Math.min(.85,a*.4)))},meta:{desc:"axis-aligned bouncing wall \u2014 sparks on impact"}},oi={token:"sink",label:"Sink",apply(n,t,e){t.cap||e.dist>=n.absorbR||(t.cap=n,n.accreted+=1,n.accreted>=n.capacity&&e.supernova(n))},meta:{desc:"captures matter, then releases it"}},ri=[Xs,ti,ei,ni,Qs,Js,Zs,Ks,oi];function Yo(n){for(let t of ri)n.force(t)}var Fn=1.5,si=8,ii=60;function ai(n,t,e,r){let s=Oe(n);if(Math.hypot(s[0].x-s[1].x,s[0].y-s[1].y)<Math.max(n.range*.06,si)){let m=Math.max(n.range*.18,ii),p=n.spin<0?-1:1;s=[{x:n.cx+n.ux*m,y:n.cy+n.uy*m,q:p},{x:n.cx-n.ux*m,y:n.cy-n.uy*m,q:-p}]}let a=r*(1+Fn*(n.d??0)),h=So(s,t,e);return{x:h.x*a,y:h.y*a}}function ci(n,t,e,r){let s=t-n.cx,i=e-n.cy,a=Math.max(Math.hypot(s,i),Ce),m=(n.spin<0?-1:1)*r*(1+Fn*(n.d??0))/(a*a);return{x:s/a*m,y:i/a*m}}function Uo(n,t,e,r){if(e.dist>=n.range)return;let s=2*e.G*n.M/(e.c*e.c),i=r/(e.dist*e.dist+s*s);t.vx+=e.dx/e.dist*i,t.vy+=e.dy/e.dist*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i),Tn(t,e.c)}function Tn(n,t){let e=n.vz??0,r=Math.hypot(n.vx,n.vy,e);r>t&&(n.vx=n.vx/r*t,n.vy=n.vy/r*t,e&&(n.vz=e/r*t))}function li(n,t,e){let r=n.cx-t,s=n.cy-e,i=Math.max(Math.hypot(r,s),Ce),a=n.M*(1+Fn*(n.d??0))/(i*i);return{x:r/i*a,y:s/i*a}}var di={token:"gravity",label:"Gravity",apply(n,t,e){Uo(n,t,e,e.G*n.M)},field:(n,t,e)=>li(n,t,e),meta:{desc:"true softened inverse-square gravity (a real 1/d\xB2 law)"}},fi={token:"charge",label:"Charge",apply(n,t,e){let r=t.charge??0;r!==0&&Uo(n,t,e,-(n.spin*r*e.G*n.M))},field:(n,t,e)=>ci(n,t,e,n.M),meta:{desc:"signed inverse-square \u2014 like repels, opposite attracts"}},hi={token:"magnetism",label:"Magnetism",apply(n,t,e){if(e.dist>=n.range)return;let r=t.charge??0;if(r===0)return;let s=1-e.dist/n.range,i=r*n.spin*n.strength*s,a=Math.cos(i),h=Math.sin(i),m=t.vx;t.vx=m*a-t.vy*h,t.vy=m*h+t.vy*a},field:(n,t,e)=>ai(n,t,e,n.strength),meta:{desc:"Lorentz force \u2014 curves a moving charge perpendicular to its velocity"}};function ui(n){return Math.sqrt(2*Math.max(0,n))}var yi={token:"thermal",label:"Thermal",apply(n,t,e){if(e.dist>=n.range)return;let r=1-e.dist/n.range,s=ui(n.strength*r);if(s===0)return;let i=Math.random()||1e-9,a=s*Math.sqrt(-2*Math.log(i)),h=2*Math.PI*Math.random();if(t.vx+=a*Math.cos(h),t.vy+=a*Math.sin(h),e.D){let m=Math.random()||1e-9;t.vz=(t.vz??0)+s*Math.sqrt(-2*Math.log(m))*Math.cos(2*Math.PI*Math.random())}n.on&&(t.heat=Math.max(t.heat,r*.4)),Tn(t,e.c)},meta:{desc:"Langevin/Brownian agitation \u2014 a real temperature in the medium"}},mi={token:"collide",label:"Collide",apply(n,t,e){if(e.dist>=n.range)return;let r=Math.max(0,Math.min(1,n.strength)),s=Math.max(1,t.size);for(let i of e.neighbors(t,s*4)){let a=Math.max(1,i.size),h=t.x-i.x,m=t.y-i.y,p=(t.z??0)-(i.z??0),y=Math.hypot(h,m,p);if(y>=s+a||y<1e-6)continue;let b=h/y,E=m/y,M=p/y,S=(t.vx-i.vx)*b+(t.vy-i.vy)*E+((t.vz??0)-(i.vz??0))*M;if(S>=0)continue;let A=(1+r)*.5*S;t.vx-=A*b,t.vy-=A*E,i.vx+=A*b,i.vy+=A*E,p&&(t.vz=(t.vz??0)-A*M,i.vz=(i.vz??0)+A*M)}},meta:{desc:"elastic pairwise collision \u2014 the hard-sphere billiard force"}},pi={token:"diffuse",label:"Diffuse",apply(n,t,e){if(e.dist>=n.range)return;let r=e.grid("diffuse");r.deposit(t.x,t.y,n.strength);let s=r.gradient(t.x,t.y);t.vx+=s.x*n.strength,t.vy+=s.y*n.strength},meta:{desc:"pheromone field \u2014 deposit a mark and follow the diffused gradient"}},gi=12,zn=7,xi={token:"propagate",label:"Propagate",source(n,t){n.on&&t.frameN%gi===0&&t.grid("wave-propagate").deposit(n.cx,n.cy,n.strength)},apply(n,t,e){if(e.dist>=n.range)return;let s=e.grid("wave-propagate").gradient(t.x,t.y),i=Math.hypot(s.x,s.y);if(i<1e-6)return;let a=-e.dx/e.dist,h=-e.dy/e.dist;t.vx+=a*i*n.strength*zn,t.vy+=h*i*n.strength*zn,e.dz&&(t.vz=(t.vz??0)+-e.dz/e.dist*i*n.strength*zn),Tn(t,e.c)},meta:{desc:"a travelling wave \u2014 a shock train expands from the source, sweeping matter out"}},vi={token:"memory",label:"Memory",apply(n,t,e){if(e.dist>=n.range)return;let r=e.grid("memory");r.deposit(t.x,t.y,n.strength*.15);let s=1+.5*r.sample(t.x,t.y),i=(1-e.dist/n.range)**2*n.strength*.5*s;t.vx+=e.dx/e.dist*i,t.vy+=e.dy/e.dist*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i)},meta:{desc:"the field remembers \u2014 occupancy wears in paths that pull harder"}},wi=[di,fi,hi,yi,mi,pi,xi,vi];function Go(n){for(let t of wi)n.force(t)}var bi={token:"lens",label:"Lens",kinematic:!0,apply(n,t,e){if(e.dist>=n.range)return;let r=n.strength*(1-e.dist/n.range)*n.spin,s=Math.cos(r),i=Math.sin(r),a=t.vx,h=t.vy;t.vx=a*s-h*i,t.vy=a*i+h*s},meta:{desc:"rotates velocity, preserving speed \u2014 bends paths without adding energy"}},Mi={token:"gate",label:"Gate",kinematic:!0,apply(n,t,e){if(Math.abs(t.x-n.cx)>=n.hw+6||Math.abs(t.y-n.cy)>=n.hh+6)return;let s=t.vx*n.ux+t.vy*n.uy;s<0&&(t.vx-=2*s*n.ux,t.vy-=2*s*n.uy)},meta:{desc:"a one-way membrane \u2014 passes matter along its heading, reflects the reverse"}},ki=1,Ei=1,Si={token:"buoyancy",label:"Buoyancy",apply(n,t,e){if(n.range>0&&e.dist>=n.range)return;let r=ki/(t.size*(1+t.heat));t.vy-=(Ei-r)*n.strength},meta:{desc:"a constant lift/sink by density difference \u2014 light matter rises, dense settles"}},zi={token:"shear",label:"Shear",apply(n,t,e){if(e.dist>=n.range)return;let r=(t.x-n.cx)*-n.uy+(t.y-n.cy)*n.ux,s=n.strength*(r/n.range)*(1-e.dist/n.range);t.vx+=n.ux*s,t.vy+=n.uy*s},meta:{desc:"a laminar shear gradient \u2014 flow speed grows with perpendicular offset"}},Ie=32,Fi=.5,Ti={token:"crystallize",label:"Crystallize",apply(n,t,e){if(e.dist>=n.range||t.heat>=Fi)return;let r=n.cx+Math.round((t.x-n.cx)/Ie)*Ie,s=n.cy+Math.round((t.y-n.cy)/Ie)*Ie;t.vx+=(r-t.x)*n.strength,t.vy+=(s-t.y)*n.strength,t.vx*=.9,t.vy*=.9},meta:{desc:"snaps cool matter onto a lattice; melts and frees it when hot"}},Ai={token:"align",label:"Align",apply(n,t,e){if(e.dist>=n.range)return;let r=t.vz??0,s=Math.hypot(t.vx,t.vy,r),i=n.strength,a=n.ux,h=n.uy,m=0,p=0,y=0,b=0;for(let M of e.neighbors(t,n.range)){let S=M.vz??0,A=Math.hypot(M.vx,M.vy,S);A>1e-6&&(p+=M.vx/A,y+=M.vy/A,b+=S/A)}let E=Math.hypot(p,y,b);E>1e-6&&(a=p/E,h=y/E,m=b/E),t.vx+=(a*s-t.vx)*i,t.vy+=(h*s-t.vy)*i,(m||r)&&(t.vz=r+(m*s-r)*i)},meta:{desc:"steers toward the neighbour-mean heading (or the body heading when alone)"}};function Ci(n,t,e,r){let s=n*r+e*.2,i=t*r-e*.2;return{x:-r*Math.sin(s)*Math.sin(i),y:-r*Math.cos(s)*Math.cos(i)}}var Oi=.01,Pi={token:"wind",label:"Wind",apply(n,t,e){if(n.range>0&&e.dist>=n.range)return;let r=Ci(t.x,t.y,e.t,Oi);t.vx+=r.x*n.strength,t.vy+=r.y*n.strength},meta:{desc:"divergence-free curl-noise turbulence"}},Ri=.5,$i={token:"cohesion",label:"Cohesion",apply(n,t,e){if(e.dist>=n.range)return;let r=n.range,s=r*Ri,i=n.strength;for(let a of e.neighbors(t,r)){let h=a.x-t.x,m=a.y-t.y,p=(a.z??0)-(t.z??0),y=Math.hypot(h,m,p);if(y<1e-6)continue;let b=h/y,E=m/y,M=p/y;if(y<s){let S=i*(s-y)/s;t.vx-=S*b,t.vy-=S*E,p&&(t.vz=(t.vz??0)-S*M)}else{let S=i*(y-s)/(r-s);t.vx+=S*b,t.vy+=S*E,p&&(t.vz=(t.vz??0)+S*M)}}},meta:{desc:"short-range pressure + mid-range cohesion \u2014 surface tension over neighbours"}},Ii=.5,Ni={token:"pressure",label:"Pressure",apply(n,t,e){if(e.dist>=n.range)return;let r=n.range,s=n.strength,i=0,a=e.neighbors(t,r);for(let m of a){let p=Math.hypot(m.x-t.x,m.y-t.y,(m.z??0)-(t.z??0));p<r&&(i+=(1-p/r)**2)}let h=i-Ii;if(!(h<=0))for(let m of a){let p=t.x-m.x,y=t.y-m.y,b=(t.z??0)-(m.z??0),E=Math.hypot(p,y,b);if(E<1e-6||E>=r)continue;let M=s*h*(1-E/r)/E;t.vx+=M*p,t.vy+=M*y,b&&(t.vz=(t.vz??0)+M*b)}},meta:{desc:"SPH density relaxation \u2014 incompressible even-fill via mutual repulsion"}},Di={token:"hunt",label:"Hunt",apply(n,t,e){if(e.dist>=n.range)return;let r=t.species??0,s=null,i=1/0;for(let b of e.neighbors(t,n.range)){if((b.species??0)===r)continue;let E=b.x-t.x,M=b.y-t.y,S=(b.z??0)-(t.z??0),A=E*E+M*M+S*S;A<i&&(i=A,s=b)}if(!s)return;let a=s.x-t.x,h=s.y-t.y,m=(s.z??0)-(t.z??0),p=Math.hypot(a,h,m)||1,y=r===0?1:-1;t.vx+=a/p*n.strength*y,t.vy+=h/p*n.strength*y,m&&(t.vz=(t.vz??0)+m/p*n.strength*y)},meta:{desc:"two-species pursuit \u2014 predators seek prey, prey flee predators"}},Li=.35,_i={token:"link",label:"Link",apply(n,t,e){if(e.dist>=n.range)return;let r=n.range,s=r*Li,i=n.strength;for(let a of e.neighbors(t,r)){let h=a.x-t.x,m=a.y-t.y,p=(a.z??0)-(t.z??0),y=Math.hypot(h,m,p);if(y<1e-6)continue;let b=y-s,E=.5*i*(b/s);t.vx+=E*(h/y),t.vy+=E*(m/y),p&&(t.vz=(t.vz??0)+E*(p/y))}},meta:{desc:"a Verlet distance constraint \u2014 holds a rest length, so matter ropes and drapes"}},Vo=40,Bi={token:"morph",label:"Morph",apply(n,t,e){let r=n.targets;if(!r||r.length===0)return;let s=Math.min(r.length-1,Math.floor((t.gx??0)*r.length)),i=r[s],a=i.x-t.x,h=i.y-t.y,m=Math.hypot(a,h),p=n.strength;t.vx+=a*p*.02,t.vy+=h*p*.02,t.z&&(t.vz=(t.vz??0)-t.z*p*.02);let b=(1-(m<Vo?1-m/Vo:0))*p*.3;b>0&&(t.vx+=((e.rng??Math.random)()-.5)*b,t.vy+=((e.rng??Math.random)()-.5)*b)},meta:{desc:"matter assembles into a mark/chart/logo \u2014 never words (\xA711)"}},Wi=90,qi={token:"spawn",label:"Spawn",apply(){},source(n,t){let e=n.life??Wi,r=Math.max(1,Math.round(n.strength*2));n.cap!=null&&n.cap>0&&e>0&&(r=Math.min(r,n.cap/e)),n.emitAcc=(n.emitAcc??0)+r;let s=Math.floor(n.emitAcc);for(n.emitAcc-=s;s>0;s--){let i=((t.rng??Math.random)()-.5)*.6,a=Math.cos(i),h=Math.sin(i),m=n.ux*a-n.uy*h,p=n.ux*h+n.uy*a,y=2+(t.rng??Math.random)()*2;t.spawn({x:n.cx,y:n.cy,vx:m*y,vy:p*y,age:e,heat:.6,...n.species!=null?{species:n.species}:{}})}},meta:{desc:"a source \u2014 emits matter along the heading, budgeted by a lifespan"}},Hi=3,ji={token:"resonate",label:"Resonate",apply(){},modify(n,t,e){return{strength:1+Math.sin(e.t*Hi*n.spin)}},meta:{desc:"pulses sibling forces with a time-varying strength S(t)=S\u2080(1+sin \u03C9t)"}},Yi=.5,Ui={token:"spotlight",label:"Spotlight",apply(){},modify(n,t,e){let r=-e.dx/e.dist,s=-e.dy/e.dist;return{gate:r*n.ux+s*n.uy<Yi}},meta:{desc:"gates sibling forces to an angular cone of the heading"}},Gi={token:"screen",label:"Screen",apply(){},meta:{desc:"a quiet zone \u2014 attenuates other bodies' forces on matter inside its radius"}},Vi={token:"pigment",label:"Pigment",apply(n,t,e){let r=n.tint;!r||e.dist>=n.range*.6||(t.color=t.color?ko(t.color,r,.08):r)},meta:{desc:"conserved color transport \u2014 matter takes on and carries a tint"}},Xi=.5,Xo=.12,Ji={token:"fieldflow",label:"Field Flow",apply(n,t,e){if(n.range>0&&e.dist>=n.range)return;let r=e.fieldAt?.(t.x,t.y);if(!r)return;let s=Math.hypot(r.x,r.y);if(!(s>1e-9))return;let i=r.x/s,a=r.y/s,h=n.range>0?1-e.dist/n.range:1,m=n.strength*h,p=t.vz??0,y=Math.hypot(t.vx,t.vy,p);if(y>1e-6){let M=Math.min(1,m*Xi);t.vx+=(i*y-t.vx)*M,t.vy+=(a*y-t.vy)*M,p&&(t.vz=p+(0-p)*M)}t.vx+=i*m*Xo,t.vy+=a*m*Xo;let b=t.vz??0,E=t.vx*t.vx+t.vy*t.vy+b*b;if(E>e.c*e.c){let M=e.c/Math.sqrt(E);t.vx*=M,t.vy*=M,b&&(t.vz=b*M)}n.on&&(t.heat=Math.max(t.heat,h*.4))},meta:{desc:"follow the field lines \u2014 steer onto and stream down the net field a body radiates"}},Ki={token:"warp",label:"Warp",kinematic:!0,apply(n,t,e){if(!n.warpHas||t.cap)return;let r=n.absorbR;if(e.dist>=r)return;let s=Math.cos(n.twist??0),i=Math.sin(n.twist??0),a=n.warpScale??1,h=-e.dx/e.dist,m=-e.dy/e.dist,p=h*s-m*i,y=h*i+m*s,b=r*a+6;t.x=n.warpX+p*b,t.y=n.warpY+y*b,t.z&&(t.z=-e.dz/e.dist*b);let E=t.vx,M=t.vy;t.vx=E*s-M*i,t.vy=E*i+M*s,t.heat=Math.max(t.heat,.6)},meta:{desc:"a wormhole throat \u2014 relocates matter to its paired body, conserved"}},Qi=[bi,Mi,Si,zi,Ti,Ai,Pi,$i,Ni,_i,Di,Bi,qi,ji,Ui,Gi,Vi,Ji,Ki];function Jo(n){for(let t of Qi)n.force(t)}var Ko=new Set(["css","canvas","svg","typography","spatial","native"]);function Qo(n){let t=[];for(let e of n)e.surfaces.some(s=>Ko.has(s))&&!e.reducedMotionEquivalent&&t.push({rule:"field/reduced-motion-equivalent-required",severity:"error",subject:e.id,message:`Projection "${e.id}" can express motion (${e.surfaces.filter(s=>Ko.has(s)).join(", ")}) but declares no reducedMotionEquivalent. Reduced motion must translate the behavior, not remove it.`}),e.accessibilityEquivalent||t.push({rule:"field/accessibility-equivalent-required",severity:"warning",subject:e.id,message:`Projection "${e.id}" declares no accessibilityEquivalent. Accessibility is an alternate projection of the same field state, not a fallback.`});return t}var An=(n,t)=>t?Object.fromEntries(Object.entries(n).filter(([e])=>t.has(e))):n;function Zo(n,t){let e=t.metrics?new Set(t.metrics):null,r=t.channels?new Set(t.channels):null,s=t.tokens?new Set(t.tokens):null;return{...n,metrics:An(n.metrics,e),bodies:n.bodies.filter(i=>!s||i.tokens.some(a=>s.has(a))).map(i=>({...i,metrics:An(i.metrics,e),dimensions:An(i.dimensions,e)})),influences:r?n.influences.filter(i=>r.has(i.channel??"linear")):n.influences,lens:t.id}}function tr(n,t,e={}){return{x:n,y:t,strength:e.strength??1,radius:e.radius&&e.radius>0?e.radius:360}}function le(n,t,e,r,s=.6){let i=r.x-t,a=r.y-e,h=Math.hypot(i,a);if(h===0||h>=r.radius)return n.x=0,n.y=0,n;let m=(1-h/r.radius)*r.strength*s;return n.x=i/h*m,n.y=a/h*m,n}var Zi={step:6,maxSteps:400,minStrength:1e-9,loopDist:6,maxTurns:1/0};function er(n,t,e,r,s){let i=[{x:t,y:e}],a=t,h=e,m=s.step,p=s.maxTurns*2*Math.PI,y=0,b=0,E=0;for(let M=0;M<s.maxSteps;M++){let S=n(a,h),A=Math.hypot(S.x,S.y);if(!(A>=s.minStrength))break;let N=S.x/A*r,C=S.y/A*r;if(Number.isFinite(p)){if(y!==0||b!==0){let H=Math.max(-1,Math.min(1,N*y+C*b));if(E+=Math.acos(H),E>p)break}y=N,b=C}if(a+=N*s.step,h+=C*s.step,s.bounds&&(a<-m||h<-m||a>s.bounds.w+m||h>s.bounds.h+m))break;if(M>4&&Math.hypot(a-t,h-e)<s.loopDist){i.push({x:a,y:h});break}i.push({x:a,y:h})}return i}function ta(n,t,e,r={}){let s={...Zi,bounds:r.bounds,...r},i=er(n,t,e,-1,s),a=er(n,t,e,1,s);return i.reverse(),i.pop(),i.concat(a)}function nr(n,t,e={}){return t.map(r=>ta(n,r.x,r.y,e)).filter(r=>r.length>1)}var ea=8,na=60;function or(n,t=8){let e={cx:n.cx,cy:n.cy,hw:n.hw,hh:n.hh,ux:n.ux,uy:n.uy,spin:n.spin},r=Oe(e),s=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y);if(s<Math.max(n.range*.06,ea)){let p=Math.max(n.range*.18,na),y=n.spin<0?-1:1;r=[{x:n.cx+n.ux*p,y:n.cy+n.uy*p,q:y},{x:n.cx-n.ux*p,y:n.cy-n.uy*p,q:-y}],s=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y)}let i=-n.uy,a=n.ux,h=Math.max(s*.13,18),m=[{x:n.cx,y:n.cy}];for(let p=1;p<=t;p++){let y=p*h;m.push({x:n.cx+i*y,y:n.cy+a*y}),m.push({x:n.cx-i*y,y:n.cy-a*y})}return m}function rr(n,t=18){let e=Math.max(Math.min(n.hw,n.hh)*.8,24),r=[];for(let s=0;s<t;s++){let i=s/t*Math.PI*2;r.push({x:n.cx+Math.cos(i)*e,y:n.cy+Math.sin(i)*e})}return r}function sr(n,t=8){let e=[];for(let r of n)!r.vis||r.tokens.length===0||(r.tokens.includes("magnetism")?e.push(...or(r,t)):(r.tokens.includes("charge")||r.tokens.includes("gravity"))&&e.push(...rr(r)));return e}function ir(n,t=Math.random){return 3+Math.floor(t()*(n>0?n:1)*3)}function ar(n,t,e,r=6,s=0){let i=Math.hypot(n,t,s)||1;if(i>=e)return{vx:0,vy:0,vz:0,heat:0};let a=1-i/e,h=a*r;return{vx:n/i*h,vy:t/i*h,vz:s/i*h,heat:a*.9}}function cr(n,t,e,r,s=.9,i=80){let a=r>0?r:1;n.vx=(n.vx+t/a)*s,n.vy=(n.vy+e/a)*s,n.x+=n.vx,n.y+=n.vy;let h=Math.hypot(n.x,n.y);h>i&&(n.x=n.x/h*i,n.y=n.y/h*i)}function lr(n,t=.02){return{x:-n.x*t,y:-n.y*t}}function dr(n){let t=n/3e4;return t<.6?.6:t>6?6:t}function fr(n,t,e=-1,r=1600,s=26){let i=0,a=0,h=s*s;for(let m=0;m<t.length;m++){if(m===e)continue;let p=t[m],y=n.x-p.x,b=n.y-p.y,E=y*y+b*b+h;i+=r*y/E,a+=r*b/E}return{x:i,y:a}}function hr(n,t,e,r=16,s=1){let i=(n(t+r,e)-n(t-r,e))/(2*r),a=(n(t,e+r)-n(t,e-r))/(2*r);return{x:-i*s,y:-a*s}}function ur(n,t,e,r,s,i,a,h){if(r.length===0)return;let m=n.particles;for(let p=m.length-1;p>=0&&!(t.length>=e);p--){let y=m[p];if(!y||y.cap||y.heat>=.12)continue;let b=-1,E=1e9,M=0;for(let A=0;A<r.length;A++){let N=Et(r[A],y.x,a,i),C=Math.abs(N-y.y);C<E&&(E=C,b=A,M=N)}if(b<0||E>=64)continue;let S=Math.min(.012,E*4e-4)*(1-y.heat/.12);y.vy+=M>y.y?S:-S,E<20&&y.vx*y.vx+y.vy*y.vy<.3&&h()<.03&&(t.push({wi:b,progress:y.x/s,phase:(h()-.5)*.22*Math.PI,size:y.size,glow:h()<.3,speed:(35e-5+h()*9e-4)*(h()<.5?1:-1)}),n.remove(y))}}function Cn(n,t,e,r,s,i,a,h,m){for(let p=n.length-1;p>=0;p--){let y=n[p];if(!y)continue;let b=t[y.wi];if(!b)continue;let E=y.progress*i,M=Et(b,E,h,a)+y.phase*32,S=E-e,A=M-r,N=Math.hypot(S,A);if(N<s&&N>.5){let C=(1-N/s)*4;m({x:E,y:M,vx:S/N*C,vy:A/N*C,size:y.size,heat:.9});let H=n.pop();H&&p<n.length&&(n[p]=H)}}}function yr(n,t,e,r,s,i,a,h){let m=p=>p.tokens.some(y=>{let b=r[y];return!!b&&!b.modify&&!b.source});for(let p=n.length-1;p>=0;p--){let y=n[p];if(!y)continue;let b=t[y.wi];if(!b)continue;let E=y.progress*s,M=Et(b,E,a,i)+y.phase*32,S=!1,A=0,N=0;for(let C of e){if(!C.vis||C.when==="active"&&!C.on||C.when&&C.when!=="active")continue;let H=C.tokens,u=C.cx-E,K=C.cy-M,Z=Math.hypot(u,K)||1,lt=C.range*(C.on?1.4:1);if(H.indexOf("wall")>=0&&Math.abs(E-C.cx)<C.hw+6&&Math.abs(M-C.cy)<C.hh+6&&(A=(E<C.cx?-1:1)*1.6,N=(M<C.cy?-1:1)*.8,S=!0),!S&&(H.indexOf("attract")>=0||H.indexOf("sink")>=0||H.indexOf("jet")>=0)&&Z<lt*.8){let mt=1.2+(C.on?1.6:0);A=u/Z*mt,N=K/Z*mt,S=!0}if(!S&&H.indexOf("repel")>=0&&Z<lt*.8){let mt=1.2+(C.on?1.2:0);A=-(u/Z)*mt,N=-(K/Z)*mt,S=!0}if(!S&&H.indexOf("swirl")>=0&&Z<lt*.75&&(A=K/Z*1.2,N=-(u/Z)*1.2,S=!0),!S&&H.indexOf("stream")>=0&&Z<lt*.75&&(A=C.ux*1.3,N=C.uy*1.3,S=!0),!S&&Z<lt*.8&&m(C)){let mt=.8+(C.on?.8:0);A=u/Z*mt,N=K/Z*mt,S=!0}if(S)break}if(S){h({x:E,y:M,vx:A,vy:N,size:y.size,heat:.5});let C=n.pop();C&&p<n.length&&(n[p]=C)}}}function mr(n,t){for(let e of n){if(!e.vis||e.tokens.indexOf("charge")<0&&e.tokens.indexOf("magnetism")<0||e.range<=0)continue;let r=e.range*e.range;for(let s of t){if(s.charge)continue;let i=e.cx-s.x,a=e.cy-s.y;i*i+a*a>=r||(s.charge=i>=0?1:-1)}}}var pr=n=>n<0?0:n>1?1:n;function gr(n){if(!n||n.n===0)return{entropy:0,coherence:1,temperature:0};let t=n.sh/n.n,e=n.ss/n.n,r=n.ss2/n.n,s=pr(.5*t+.5*Math.min(1,r/9)),i=n.ss>1e-9?Math.hypot(n.sx,n.sy)/n.ss:1,a=pr((1-i)*Math.min(1,e/1.5));return{entropy:a,coherence:1-a,temperature:s}}var Ne=class{constructor(){V(this,"pending",new Map);V(this,"ids",new WeakMap);V(this,"seq",0)}idOf(t){let e=this.ids.get(t);return e===void 0&&this.ids.set(t,e=++this.seq),e}keyOf(t,e){if(t==="met"){let s=e,[i,a]=[this.idOf(s.a.el??s.a),this.idOf(s.b.el??s.b)].sort((h,m)=>h-m);return`${i}:${a}`}if(t==="enter"||t==="exit"){let s=e;return`${this.idOf(s.body.el??s.body)}:${this.idOf(s.other.el??s.other)}`}let r=e;return String(this.idOf(r.body.el??r.body))}record(t,e){let r=this.pending.get(t);r||this.pending.set(t,r=new Map),r.set(this.keyOf(t,e),e)}flush(t){if(this.pending.size!==0){for(let[e,r]of this.pending)for(let s of r.values())t(e,s);this.pending.clear()}}};function On(n){return n.split(",").map(t=>t.trim()).filter(Boolean).map(t=>{let e=t.indexOf(":");return{trigger:t.slice(0,e).trim(),event:t.slice(e+1).trim(),armed:!1}}).filter(t=>t.trigger&&t.event)}function Pn(n,t){switch(n){case"dense":return t.d>.6;case"sparse":return t.d<.2;case"engaged":return t.on;case"captured":return t.accreted>0;default:return!1}}var xr={blackhole:[{body:"attract",strength:1.4,range:340},{body:"swirl",strength:1,range:300,spin:1},{body:"sink",absorb:42,max:60},{body:"lens",strength:.5,range:380}],whitehole:[{body:"repel",strength:1.4,range:340},{body:"stream",strength:.6,range:300,angle:0}],star:[{body:"gravity",strength:300,range:320},{body:"thermal",strength:1,range:220}],quasar:[{body:"attract",strength:.7,range:340},{body:"swirl",strength:1.2,range:300,spin:1},{body:"sink",absorb:40,max:60},{body:"lens",strength:.5,range:380},{body:"jet",strength:2.5,range:280,angle:-90},{body:"jet",strength:2.5,range:280,angle:90}],galaxy:[{body:"attract",strength:.6,range:400},{body:"swirl",strength:1.3,range:380,spin:1},{body:"viscosity",strength:.4,range:400},{body:"lens",strength:.3,range:420}],nebula:[{body:"thermal",strength:.8,range:320},{body:"viscosity",strength:.5,range:320},{body:"buoyancy",strength:.3,range:0}],tornado:[{body:"swirl",strength:1.6,range:300,spin:1},{body:"stream",strength:.8,range:280,angle:-90},{body:"viscosity",strength:.3,range:300}],fountain:[{body:"spawn",strength:1.2,angle:-90,life:90},{body:"gravity",strength:60,range:0}]};function oa(){return globalThis.process?.env?.NODE_ENV!=="production"}var wr=oa();function br(){return wr}var vr=new Set;function Rn(n,t){if(!wr)return;let e=`${n}:${t}`;vr.has(e)||(vr.add(e),console.warn(`[Fundamental:${n}] ${t}`))}var ra={"draw-focus":{body:["attract"],range:280,feedback:!0},"clear-space":{body:["repel"],range:240},"show-motion":{body:["stream"],render:["trails"]},"show-relationship":{body:["memory"],render:["links"]},"contain-energy":{body:["viscosity","wall"]},ignite:{body:["thermal","fieldflow"],render:["heatmap","particles"]},stabilize:{body:["viscosity","cohesion"]},warn:{body:["repel","thermal"],feedback:!0}};function Mr(n,t={}){let e=ra[n];if(!e)return null;let r=[...e.body];t.risk==="high"&&!r.includes("thermal")&&r.push("thermal");let s={"data-body":r.join(" ")};return t.intensity!=null&&(s["data-strength"]=String(t.intensity)),e.range!=null&&(s["data-range"]=String(e.range)),e.feedback&&(s["data-feedback"]=""),e.render?.length&&(s["data-render"]=e.render.join(" ")),{body:r.join(" "),strength:t.intensity,range:e.range,feedback:e.feedback??!1,render:e.render??["particles"],attributes:s}}function Er(n){let t=(A,N)=>{let C=Number.parseFloat(n.get(A)??"");return Number.isFinite(C)?C:N},e=t("strength",.5),r=t("angle",0)*Math.PI/180,s=n.get("spin"),i=s==null?1:Number.isFinite(Number.parseFloat(s))?Number.parseFloat(s):0,a=(n.get("body")??"").split(/\s+/).filter(Boolean),h=Fe(a),m=n.get("life"),p=n.get("cap"),y=Number.parseFloat(m??""),b=Number.parseFloat(p??""),E=m!=null||p!=null||n.has("budget")||n.has("sink"),M=n.get("authority");return{tokens:a,authority:M==="kinematic"||M==="dynamic"?M:"anchored",classified:h,...Number.isFinite(y)&&y>0?{life:y}:{},...Number.isFinite(b)&&b>0?{cap:b}:{},budgeted:E,strength:e,range:t("range",280),absorbR:t("absorb",64),capacity:t("max",60),spin:i,angle:r,ux:Math.cos(r),uy:Math.sin(r),when:n.get("when")??"",feedback:n.has("feedback"),shaped:n.has("shaped"),...n.get("species")!=null&&Number.isFinite(Number.parseFloat(n.get("species")))?{species:Number.parseFloat(n.get("species"))}:{},...(()=>{let A=n.get("affects");if(A==null)return{};let N=A.split(",").map(C=>Number.parseFloat(C.trim())).filter(C=>Number.isFinite(C));return N.length?{affects:new Set(N)}:{}})(),fmin:t("fmin",0),fmax:t("fmax",0),opsz:n.get("opsz")??"",pair:n.get("pair")||void 0,twist:t("twist",0)*Math.PI/180,warpScale:t("scale",1),screenMin:t("screen-min",0),M:e}}function sa(n){let t={body:n.body};return n.strength!=null&&(t.strength=String(n.strength)),n.range!=null&&(t.range=String(n.range)),n.spin!=null&&(t.spin=String(n.spin)),n.angle!=null&&(t.angle=String(n.angle)),n.absorb!=null&&(t.absorb=String(n.absorb)),n.max!=null&&(t.max=String(n.max)),n.life!=null&&(t.life=String(n.life)),n.cap!=null&&(t.cap=String(n.cap)),{get:e=>t[e]??null,has:e=>e in t}}function ia(n){let t=xr[n];return t?t.map(e=>Er(sa(e))):[]}function aa(n){let t=(n.tagName??"element").toLowerCase(),e=n.id?`#${n.id}`:"",r=typeof n.className=="string"&&n.className?`.${n.className.split(/\s+/)[0]}`:"";return`<${t}${e}${r}>`}function ca(n,t="<body>"){!n.classified||n.classified.sources.length===0||n.budgeted||(n.life=gn,n.cap=xn,br()&&console.warn(`[Fundamental:UNBUDGETED_SOURCE] ${t} runs the source force "${n.classified.sources.join(" ")}" with none of data-life / data-cap / data-budget / data-sink. Applying the safe default budget (data-life="${gn}", data-cap="${xn}") \u2014 declare one to make the source's budget explicit (workover v0.3 source rules).`))}function Sr(n,t){return ca(t,aa(n)),{el:n,...t,tint:n.dataset.color,cx:0,cy:0,hw:0,hh:0,on:!1,vis:!0,accreted:0,count:0,d:0,attn:1}}function la(n){return{get:t=>n.getAttribute("data-"+t),has:t=>n.hasAttribute("data-"+t)}}function de(n,t){return Sr(n,Er(t??la(n)))}var kr={source:"jet",sink:"sink",anchor:"tether",boundary:"wall",sensor:"",display:""};function da(n){let t=null,e=n.getAttribute("data-intent");if(e){let s=n.getAttribute("data-intensity"),i=Mr(e,{intensity:s!=null?Number(s):void 0,risk:n.getAttribute("data-risk")??void 0});i&&(t={body:i.body},i.strength!=null&&(t.strength=String(i.strength)),i.range!=null&&(t.range=String(i.range)),i.feedback&&(t.feedback=""))}if(!t){let s=n.getAttribute("data-field-role");s!=null&&s in kr&&(t={body:kr[s],feedback:""})}if(!t)return null;let r=t;return{get:s=>n.getAttribute("data-"+s)??r[s]??null,has:s=>n.hasAttribute("data-"+s)||s in r}}function zr(n){let t=[];return n.querySelectorAll("[data-body]").forEach(e=>{t.push(de(e))}),n.querySelectorAll("[data-preset]").forEach(e=>{let r=e;for(let s of ia(r.dataset.preset??""))t.push(Sr(r,s))}),n.querySelectorAll("[data-intent]:not([data-body]), [data-field-role]:not([data-body]):not([data-intent])").forEach(e=>{let r=da(e);r&&t.push(de(e,r))}),t}function fa(n){let t=n.el;if(typeof t.getAttribute!="function")return;let e=t.getAttribute("data-strength");if(e!=null){let a=Number.parseFloat(e);Number.isFinite(a)&&(n.strength=a,n.M=a)}let r=t.getAttribute("data-range");if(r!=null){let a=Number.parseFloat(r);Number.isFinite(a)&&(n.range=a)}let s=t.getAttribute("data-spin");if(s!=null){let a=Number.parseFloat(s);Number.isFinite(a)&&(n.spin=a)}let i=t.getAttribute("data-angle");if(i!=null){let a=Number.parseFloat(i);Number.isFinite(a)&&(n.angle=a*Math.PI/180,n.ux=Math.cos(n.angle),n.uy=Math.sin(n.angle))}}function De(n,t,e,r=0,s=0){let i=e*.15;for(let a of n){let h=a.rect?a.rect():a.el.getBoundingClientRect(),m=h.left-r,p=h.top-s;a.cx=m+h.width/2,a.cy=p+h.height/2,a.hw=h.width/2,a.hh=h.height/2,a.on=a.el.dataset.active==="1",a.vis=p+h.height>-i&&p<e+i&&m+h.width>-i&&m<t+i,fa(a)}}var Fr="field:register-body",Tr="field:unregister-body",Ar="field:update-body";var Le=class{constructor(){V(this,"hosts",new Map)}register(t){this.hosts.set(t.element,t)}unregister(t){this.hosts.delete(t)}get size(){return this.hosts.size}bodies(t){let e=[];for(let[r,s]of this.hosts){if(!r.isConnected){this.hosts.delete(r);continue}let i=s.attrs?ha(s.attrs,r):void 0,a=t(r,i);s.getRect&&(a.rect=s.getRect),s.writeTarget&&(a.writeTarget=s.writeTarget),e.push(a)}return e}};function ha(n,t){return{get:e=>n[e]??t.getAttribute("data-"+e),has:e=>e in n||t.hasAttribute("data-"+e)}}function Or(n,t,e=.12){return n>=t?0:(1-n/t)*e}function _e(n,t,e){if(n===t)return .5;let r=(e-n)/(t-n);return r<0?0:r>1?1:r}var Cr=Object.freeze([]);function $n(n,t,e,r,s){let i={x:_e(n,t,s),y:0},a={x:1,y:_e(t,e,s)},h={x:_e(r,e,s),y:1},m={x:0,y:_e(n,r,s)},p=(b,E)=>({x1:b.x,y1:b.y,x2:E.x,y2:E.y});switch((n>s?8:0)|(t>s?4:0)|(e>s?2:0)|(r>s?1:0)){case 0:case 15:return Cr;case 1:case 14:return[p(m,h)];case 2:case 13:return[p(h,a)];case 3:case 12:return[p(m,a)];case 4:case 11:return[p(i,a)];case 6:case 9:return[p(i,h)];case 7:case 8:return[p(m,i)];case 5:return[p(m,i),p(h,a)];case 10:return[p(m,h),p(i,a)];default:return Cr}}function In(n,t,e,r,s,i,a,h=1){if(a<=0)return;let m=Math.max(0,Math.floor((s-a)/r)),p=Math.min(t-1,Math.ceil((s+a)/r)),y=Math.max(0,Math.floor((i-a)/r)),b=Math.min(e-1,Math.ceil((i+a)/r)),E=a*a;for(let M=y;M<=b;M++)for(let S=m;S<=p;S++){let A=S*r-s,N=M*r-i,C=A*A+N*N;if(C>=E)continue;let H=1-Math.sqrt(C)/a,u=M*t+S;n[u]=n[u]+h*H*H}}function Pr(n,t,e){let r=-1,s=1/0;for(let i=0;i<e.length;i++){let a=e[i],h=a.x-n,m=a.y-t,p=h*h+m*m;p<s&&(s=p,r=i)}return r}function Rr(n,t,e){let r=[];for(let s=0;s<e;s++)for(let i=0;i<t;i++){let a=n[s*t+i];i+1<t&&n[s*t+i+1]!==a&&r.push({x1:i+.5,y1:s-.5,x2:i+.5,y2:s+.5}),s+1<e&&n[(s+1)*t+i]!==a&&r.push({x1:i-.5,y1:s+.5,x2:i+.5,y2:s+.5})}return r}var $r=24,ua=.12,ya=.22,fe=class{constructor(t,e){V(this,"grid");V(this,"peak",.001);V(this,"cell",$r);this.grid=new oe(Math.max(1,t),Math.max(1,e),"diffuse",$r)}resize(t,e){this.grid.resize(t,e)}clear(){this.grid.clear(),this.peak=.001}update(t){for(let s of t)this.grid.deposit(s.x,s.y,1);this.grid.stepDiffuse(ya,ua);let e=this.grid.max(),r=e>this.peak?.25:.03;this.peak+=(Math.max(e,.001)-this.peak)*r}norm(t,e){return bt(this.grid.sample(t,e)/this.peak,0,1)}gradient(t,e){if(this.peak<=0)return{x:0,y:0};let r=this.grid.gradient(t,e);return{x:r.x/this.peak,y:r.y/this.peak}}};var ma={position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"0",pointerEvents:"none",display:"block"},Ir=Object.entries(ma).map(([n,t])=>`${n.replace(/[A-Z]/g,e=>"-"+e.toLowerCase())}:${t}`).join(";");function pa(n){let t=n.width,e=n.height,r=null,s=0;return{root:{querySelectorAll:()=>[],querySelector:()=>null,contains:()=>!1},viewport:()=>({width:t,height:e,dpr:1}),scrollY:()=>0,scrollHeight:()=>e,reducedMotion:()=>!1,hidden:()=>!1,raf:a=>(r=a,1),cancelRaf:()=>{r=null},createCanvas:()=>{throw new Error("headlessHost does not render \u2014 use render:'none' and the signal read-outs (onFeedback / sampleScalar / readParticles).")},onResize:()=>()=>{},onScroll:()=>()=>{},onVisibility:()=>()=>{},onInput:()=>()=>{},onBodyEvent:()=>()=>{},tick(a){s=a??s+1e3/60;let h=r;r=null,h?.(s)},resize(a,h){t=a,e=h}}}var Nr="10px ui-monospace, SFMono-Regular, Menlo, monospace";function Nn(n,t){let e=0,r=0;return{size(s,i,a){e=s,r=i,n.width=Math.floor(s*a),n.height=Math.floor(i*a),t.setTransform(a,0,0,a,0,0)},clear(){t.clearRect(0,0,e,r)},segments(s,i){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath();for(let a=0;a+3<s.length;a+=4)t.moveTo(s[a],s[a+1]),t.lineTo(s[a+2],s[a+3]);t.stroke()},polyline(s,i){if(!(s.length<4)){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath(),t.moveTo(s[0],s[1]);for(let a=2;a+1<s.length;a+=2)t.lineTo(s[a],s[a+1]);t.stroke()}},rect(s,i,a,h,m,p,y,b){t.fillStyle=`rgba(${m},${p},${y},${b})`,t.fillRect(s,i,a,h)},text(s,i,a,h,m,p,y){t.font=Nr,t.textBaseline="middle",t.fillStyle=`rgba(${h},${m},${p},${y})`,t.fillText(s,i,a)},measureText(s){return t.font=Nr,t.measureText(s).width}}}var Dn=(n,t)=>{if(t.density!==void 0){let e=t.density.toFixed(3);n.style.setProperty("--d",e),n.style.setProperty("--field-density",e)}if(t.heatmapDensity!==void 0){let e=t.heatmapDensity.toFixed(3);n.style.setProperty("--field-heatmap-density",e)}if(t.load!==void 0){let e=t.load.toFixed(3);n.style.setProperty("--load",e),n.style.setProperty("--mass",e)}if(t.entropy!==void 0&&n.style.setProperty("--entropy",t.entropy.toFixed(3)),t.coherence!==void 0&&n.style.setProperty("--coherence",t.coherence.toFixed(3)),t.temperature!==void 0&&n.style.setProperty("--temperature",t.temperature.toFixed(3)),t.lit!==void 0){let e=t.lit;n.style.setProperty("--lit",e.toFixed(3));let r=n.dataset.fxLit==="1";e>.5&&!r?(n.dataset.fxLit="1",n.dispatchEvent(new CustomEvent("field:lit",{detail:{value:e}}))):e<.4&&r&&(n.dataset.fxLit="0",n.dispatchEvent(new CustomEvent("field:dim",{detail:{value:e}})))}},Dr=Dn;var Be=class{constructor(t){V(this,"lit",!1);V(this,"lastEdgeMs",-1/0);V(this,"cfg");this.cfg=t}update(t,e){let r=e-this.lastEdgeMs>=this.cfg.debounceMs;return!this.lit&&t>=this.cfg.enter&&r?(this.lit=!0,this.lastEdgeMs=e,"entered"):this.lit&&t<=this.cfg.exit&&r?(this.lit=!1,this.lastEdgeMs=e,"exited"):null}get isLit(){return this.lit}reset(){this.lit=!1,this.lastEdgeMs=-1/0}};var ga={strengthen:1.5,decay:.3,remember:.2},Ln=n=>n<0?0:n>1?1:n;function Lr(n,t,e,r,s=ga){n.active=t,n.tension=Ln(e),n.strength=Ln(n.strength+(t?s.strengthen:-s.decay)*r),n.memory=Ln(n.memory+(t?s.remember:-s.remember*.5)*r)}function _r(n,t,e=Math.random){let r=[],s=t.absorbR+6;for(let i of n){if(i.cap!==t)continue;let a=e()*Math.PI*2,h=4+e()*3;i.cap=null,i.x=t.cx+Math.cos(a)*s,i.y=t.cy+Math.sin(a)*s,i.vx=Math.cos(a)*h,i.vy=Math.sin(a)*h,i.z&&(i.z=0),i.vz&&(i.vz=0),i.heat=1,i.age=void 0,r.push(i)}return t.accreted=0,r}function _n(n){if(n.capacity<=0)return 0;let t=n.accreted/n.capacity;return t<0?0:t>1?1:t}function Br(n,t){return t&&!n?{fire:"captured",armed:!0}:!t&&n?{fire:"released",armed:!1}:{fire:null,armed:n}}function Wr(n,t){let e=[];for(let r of n)r.when!=="active"||!r.tokens.includes("sink")||(r.wasOn&&!r.on&&r.accreted>0&&(t(r),e.push(r)),r.wasOn=r.on);return e}function Bn(n,t){let e=t.cx-n.x,r=t.cy-n.y;return e*e+r*r<t.absorbR*t.absorbR}function qr(n,t,e=.14){let r=n+(t-n)*e;return r<.001?0:r>.999?1:r}function Hr(n,t,e,r){let s=n.x+t.x,i=n.y+t.y,a=t.x+(e.x-s)*r,h=t.y+(e.y-i)*r,m=1-r;return{tx:a,ty:h,scale:m,opacity:m}}function xa(n){let t=0;for(let e of n)t+=.5*(e.m||1)*(e.vx*e.vx+e.vy*e.vy+(e.vz??0)*(e.vz??0));return t}function va(n){let t=0;for(let e of n)t+=e.heat;return t}function jr(n){let t=xa(n),e=va(n);return{kinetic:t,thermal:e,total:t+e,count:n.length}}var wa={neutral:{vx:0,vy:0,charge:0,m:1,heat:0},positive:{vx:1,vy:0,charge:1,m:1,heat:0},negative:{vx:1,vy:0,charge:-1,m:1,heat:0},still:{vx:0,vy:0,charge:1,m:1,heat:0},fast:{vx:6,vy:0,charge:1,m:1,heat:0},hot:{vx:0,vy:0,charge:0,m:1,heat:1},massive:{vx:0,vy:0,charge:0,m:6,heat:0}};function ba(n,t,e){let r=n.cx-t,s=n.cy-e;return{dx:r,dy:s,dist:Math.max(Math.hypot(r,s),1),form:{},c:12,G:1,t:0}}function Wn(n,t,e,r,s,i=wa.neutral){let a=Wo(),h=ba(e,r,s);h.accum=a;for(let m of t){let p=n[m];if(!p)continue;let y={x:r,y:s,vx:i.vx,vy:i.vy,charge:i.charge,m:i.m,heat:i.heat,size:1,cap:null};try{Sn(p,e,y,h)}catch{}}return a}var We={x:0,y:0},qe=[0,0,0];function He(n,t={}){let e=null;if((t.render??"none")!=="none"&&(e=n.getContext("2d"),!e))throw new Error("Fundamental: 2D canvas context unavailable");let r=t.overlayCanvas??null,s=e?r?.getContext("2d")??null:null,i=t.overlayBackend??(r&&s?Nn(r,s):null),a=new Re,h=1,m=new Map,p=jo(),y=new Map,b=o=>(y.get(o)?.size??0)>0;function E(o,c){let l=y.get(o);if(l)for(let x of l)x(c)}let M=new Ne;function S(o,c){b(o)&&M.record(o,c)}function A(){M.flush(E)}let N=new WeakMap,C=new Map,H=new Map;function u(o){let c=b("enter")||b("exit"),l=b("met");if(!c&&!l)return;for(let f=0;f<o.length;f++){let v=o[f];if(c){let g=C.get(v);g||C.set(v,g=new Set);let d=v.range*v.range;for(let w=0;w<o.length;w++){if(f===w)continue;let k=o[w],z=k.cx-v.cx,T=k.cy-v.cy,F=z*z+T*T<d;F&&!g.has(k)?(g.add(k),b("enter")&&S("enter",{body:v,other:k})):!F&&g.has(k)&&(g.delete(k),b("exit")&&S("exit",{body:v,other:k}))}}if(l){let g=H.get(v);g||H.set(v,g=new Set);for(let d=f+1;d<o.length;d++){let w=o[d],k=Math.abs(w.cx-v.cx)<v.hw+w.hw&&Math.abs(w.cy-v.cy)<v.hh+w.hh;k&&!g.has(w)?(g.add(w),S("met",{a:v,b:w})):!k&&g.has(w)&&g.delete(w)}}}let x=new Set(o);for(let f of[C,H])for(let v of f.keys())x.has(v)||f.delete(v)}let K=[],Z=new WeakMap,lt=[],mt=0,Y=new WeakMap,P=new WeakMap,U=new Map,Q=new Map;if(Yo(p),Go(p),Jo(p),!t.host)throw new Error("Fundamental: createField requires opts.host. Use @fundamental-engine/vanilla (createField/mountField) or @fundamental-engine/elements / @fundamental-engine/react, or pass browserHost() from @fundamental-engine/dom.");let B=t.host,ft=[],rt=B.reducedMotion(),vt=vn[t.theme??wn]??vn[wn],$={accent:t.accent??Ae(t.palette)[0]??pn[0]??"#4da3ff",density:t.density&&t.density>0?t.density:1,render:t.render??"none",waves:t.waves??!0,waveStyle:t.waveStyle??"linear",waveCenter:t.waveCenter??null,background:t.background??"opaque",mass:t.mass??!1,separation:t.separation!=null&&t.separation>=0?t.separation:0,attention:t.attention??!1,causality:t.causality??!1,heatmap:t.heatmap??!1,overlay:t.overlay??"off",gridWarp:t.gridWarp!=null&&t.gridWarp>=0?t.gridWarp:1,gridIntensity:t.gridIntensity!=null&&t.gridIntensity>=0?Math.min(t.gridIntensity,1):.16,gradientCool:t.gradientCool?gt(t.gradientCool):vt.cool,gradientWarm:t.gradientWarm?gt(t.gradientWarm):vt.warm,waveBaseline:(t.waveBaseline??vt.wave).map(gt),dprCap:t.dprCap&&t.dprCap>0?t.dprCap:2,depth:t.depth&&t.depth>0?t.depth:0,integrator:t.integrator==="fixed"?"fixed":"legacy",feedbackSink:t.feedbackSink??Dn},tt=null,L=[],_=0,D=0,St=0,G=0,st=!1,dt=1,Xt=0,ue=new WeakMap,It=0,Nt=0,Yn=!0,Un={...Te.ambient.preset},Ve="ambient",Gn=new WeakMap,Qr=0,Bt=o=>{if(o.el&&o.el.id)return o.el.id;let c=Gn.get(o);return c===void 0&&(c=`body-${Qr++}`,Gn.set(o,c)),c},Vn=o=>{let c={density:o.d,count:o.count,engaged:o.on?1:0};o.attn!==void 0&&(c.attention=o.attn),o.capacity>0&&(c.load=o.accreted/o.capacity);let l=o.metrics?{entropy:o.metrics.entropy,coherence:o.metrics.coherence,temperature:o.metrics.temperature}:{};return{metrics:c,dimensions:l}},Zr=0,Wt=new Map,ts=o=>({id:o.id,label:o.label,channels:o.channels.slice(),surfaces:o.surfaces.slice(),...o.reducedMotionEquivalent!==void 0?{reducedMotionEquivalent:o.reducedMotionEquivalent}:{},...o.accessibilityEquivalent!==void 0?{accessibilityEquivalent:o.accessibilityEquivalent}:{}}),ye=()=>[...Wt.values()].map(ts),me=[];function es(){for(let o of me)Wt.get(o.id)?.apply?.(o.source(),o.target)}let ns={register(o){return Wt.set(o.id,o),()=>{Wt.get(o.id)===o&&Wt.delete(o.id)}},unregister(o){Wt.delete(o)},get(o){return Wt.get(o)},list:ye,apply(o,c,l){Wt.get(o)?.apply?.(c,l)},bind(o,c,l){let x={id:o,target:c,source:l};return me.push(x),()=>{let f=me.indexOf(x);f>=0&&me.splice(f,1)}},lint:()=>Qo(ye())},Xn=.9,Jn=8;function os(){for(let o of L){if(o.authority!=="dynamic"||!o.vis)continue;o.bx===void 0&&(o.bx=o.cx,o.by=o.cy,o.bvx=0,o.bvy=0);let c=o.bx??o.cx,l=o.by??o.cy,x=L.filter(z=>z!==o&&z.vis&&z.tokens.length>0),{fx:f,fy:v}=Vt(x,p.forces,W,c,l),g=1/Math.max(o.M,1e-4),d=(o.bvx??0)+f*g*W.dt,w=(o.bvy??0)+v*g*W.dt;d*=Xn,w*=Xn;let k=Math.hypot(d,w);if(k>Jn){let z=Jn/k;d*=z,w*=z}o.bvx=d,o.bvy=w,o.bx=c+d*W.dt,o.by=l+w*W.dt,o.cx=o.bx,o.cy=o.by}}let Kn=globalThis.structuredClone,rs=o=>{if(o==null)return o;try{return Kn?Kn(o):JSON.parse(JSON.stringify(o))}catch{try{return JSON.parse(JSON.stringify(o))}catch{return o}}},wt=[],qt=[],Qn=0,Gt=null,ut=t.rng??Math.random,Xe=t.now??(()=>performance.now()),ht=rt?1:0,Je=NaN,Dt=null,re=null,Ht=0,Lt=0,pe=null,Ke=[],Qe=null,ge=null,ss=Math.round(130*$.density)*4,xt={x:0,y:0,k:0},yt=null,_t=null,Zn=0,to=0,eo=Ae(t.palette).map(gt),it=gt($.accent),xe=null,Ze=[],jt=[],Jt=[],Kt=[],tn=[],en=[],Qt=[],ve=new Le,nn=!1,on=()=>{nn||(nn=!0,queueMicrotask(()=>{nn=!1,be()}))},is=o=>{for(let c of["--d","--field-density","--load","--mass","--entropy","--coherence","--temperature"])o.style.removeProperty(c)},as=o=>{let c=o.detail;c?.element&&(ve.register(c),on())},cs=o=>{let c=o.detail;c?.element&&(ve.unregister(c.element),is(c.writeTarget??c.element),on())},ls=on,At={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null},no=Xe(),W={dx:0,dy:0,dz:0,dist:1,form:{...Te.ambient.preset},W:0,H:0,D:$.depth,integrator:$.integrator,t:0,frameN:0,dt:rt?0:1,c:12,G:1,scrollV:0,rng:ut,spark:(o,c,l,x)=>oo(o,c,l,x),supernova:o=>{let c=_r(a.particles,o,ut),l=new Set(c);for(let x of a.particles){if(l.has(x))continue;let f=x.x-o.cx,v=x.y-o.cy,g=Math.hypot(f,v)||1;if(g<320){let d=(1-g/320)*4;x.vx+=f/g*d,x.vy+=v/g*d,x.heat=Math.max(x.heat,.8)}}Cn(qt,wt,o.cx,o.cy,320,_,D,W.t,x=>void a.add(Zt(x))),vs(o),rn(o.el,"field:saturated",{peak:c.length}),o.el.dataset.fxCap==="1"&&(o.el.dataset.fxCap="0",te(o.el,"released",{accreted:0,load:0}),b("release")&&S("release",{body:o,count:c.length}),N.delete(o))},spawn:o=>{a.size>=ss||a.add(Zt(o))},neighbors:(o,c)=>a.neighbors(o,c),grid:o=>{let c=m.get(o);if(!c){let l=o.startsWith("wave")?"wave":o.startsWith("memory")?"memory":"diffuse";c=new oe(_,D,l),m.set(o,c)}return c}};function oo(o,c,l,x){if(rt||Kt.length>260)return;let f=x?gt(x):[255,122,69],v=ir(l);for(let g=0;g<v;g++){let d=ut()*6.28318,w=.8+ut()*(l>0?l:1)*1.7;Kt.push({x:o,y:c,vx:Math.cos(d)*w,vy:Math.sin(d)*w,life:1,c:f})}}function Zt(o={}){let c=o.size??.7+ut()*1.8;return{id:o.id??h++,x:o.x??ut()*_,y:o.y??ut()*D,vx:o.vx??(ut()-.5)*.25,vy:o.vy??(ut()-.5)*.18,z:o.z??($.depth>0?ut()*$.depth:0),vz:o.vz??($.depth>0?(ut()-.5)*.18:0),m:o.m??($.mass?c:1),heat:o.heat??0,size:c,gx:o.gx??ut(),gy:o.gy??ut(),gz:o.gz??ut(),cap:null,...o.age!=null?{age:o.age}:{},...o.color!=null?{color:o.color}:{},...o.species!=null?{species:o.species}:{}}}let we=[];function ds(){if(!we.length)return;let o=a.particles;for(let c=0;c<o.length;c++){let l=we[c%we.length];o[c].atom=l;let x=typeof l.weight=="number"?Math.max(0,Math.min(1,l.weight)):.5;o[c].size*=.6+x*.9,o[c].m*=.6+x*1.2}}function ro(){a.clear();let o=Math.round(130*$.density);for(let c=0;c<o;c++)a.add(Zt());ds(),wt=$.waves?$o($.waveBaseline):[],qt=$.waves?Io(wt.length,$.density,ut):[],Qn=qt.length}function be(){let o=zr(B.root);if(ve.size>0){let x=new Set(o.map(f=>f.el));L=o.concat(ve.bodies(de).filter(f=>!x.has(f.el)))}else L=o;K.length>0&&(L=L.concat(K)),De(L,_,D,St,G),bs();let c=new Map(jt.map(x=>[x.el,x]));jt=[...B.root.querySelectorAll("[data-move]")].map(x=>{let f=x,v=f.getBoundingClientRect(),g=Number.parseFloat(f.dataset.mass??""),d=Number.isFinite(g)?g:dr(v.width*v.height),w=(f.dataset.move??"").trim()==="layout",k=f.hasAttribute("data-dock"),z=f.hasAttribute("data-warp"),T=c.get(f);return T?{el:f,o:T.o,mEl:d,layout:w,dockable:k,dock:T.dock,docked:T.docked,warpable:z,warpCool:T.warpCool}:{el:f,o:{x:0,y:0,vx:0,vy:0},mEl:d,layout:w,dockable:k,dock:{dock:0},docked:null,warpable:z,warpCool:0}}),tn=[...B.root.querySelectorAll("[data-on]")].map(x=>{let f=x;return{el:f,body:L.find(v=>v.el===f)??null,bindings:On(f.dataset.on??"")}}),en=[...B.root.querySelectorAll("[data-class]")].map(x=>{let f=x;return{el:f,body:L.find(v=>v.el===f)??null,bindings:On(f.dataset.class??"")}});for(let x of L){if(!x.pair)continue;let f=null;try{f=B.root.querySelector(x.pair)}catch{f=null}x.pairBody=f?L.find(v=>v.el===f):void 0}let l=new Map(Jt.map(x=>[x.el,x]));for(let[x,f]of l)if(!B.root.contains(x))for(let v of f.emitted)v.remove();Jt=[...B.root.querySelectorAll("[data-emit]")].map(x=>{let f=x,v=f.dataset.emit??"",g=null;try{g=v?B.root.querySelector(v):null}catch{g=null}let d=Math.max(0,Math.round(Number.parseFloat(f.dataset.max??"")||8)),w=l.get(f);if(w){let k=w.emitted.filter(z=>z.isConnected);for(;k.length>d;)k.pop().remove();return{el:f,tmpl:g,cap:d,emitted:k}}return{el:f,tmpl:g,cap:d,emitted:[]}})}function fs(){for(let o of L)if(o.pairBody){if(!o.pairBody.el.isConnected){o.warpHas=!1,o.pairBody=void 0;continue}o.pairBody.vis?(o.warpX=o.pairBody.cx,o.warpY=o.pairBody.cy,o.warpHas=!0):o.warpHas=!1}else o.pair&&(o.warpHas=!1)}function hs(){if(!(Jt.length===0||W.frameN%30!==0))for(let o of Jt){if(!o.tmpl||o.emitted.length>=o.cap)continue;let c=o.tmpl.cloneNode(!0);c.removeAttribute("id"),c.setAttribute("aria-hidden","true"),c.setAttribute("inert",""),c.dataset.fieldEmitted="",o.el.appendChild(c),o.emitted.push(c)}}function us(){if(tn.length!==0)for(let o of tn){let c=o.body?{d:o.body.d,on:o.body.on,accreted:o.body.accreted}:{d:0,on:o.el.dataset.active==="1",accreted:0};for(let l of o.bindings){let x=Pn(l.trigger,c);x&&!l.armed?(l.armed=!0,o.el.dispatchEvent(new CustomEvent(l.event,{bubbles:!0,detail:{trigger:l.trigger,d:c.d,on:c.on,accreted:c.accreted}}))):x||(l.armed=!1)}}}function ys(){if(en.length!==0)for(let o of en){let c=o.body?{d:o.body.d,on:o.body.on,accreted:o.body.accreted}:{d:0,on:o.el.dataset.active==="1",accreted:0};for(let l of o.bindings){let x=Pn(l.trigger,c);x&&!l.armed?(l.armed=!0,o.el.classList.add(l.event)):!x&&l.armed&&(l.armed=!1,o.el.classList.remove(l.event))}}}function te(o,c,l){o.dispatchEvent(new CustomEvent("field:"+c,{bubbles:!0,composed:!0,detail:l})),o.dispatchEvent(new CustomEvent("forces:"+c,{bubbles:!0,composed:!0,detail:l}))}function ms(){for(let o of L){if(!o.vis||o.tokens.indexOf("sink")<0)continue;let c=o.el.dataset.fxCap==="1",l=Br(c,o.accreted>0);l.fire==="captured"?(o.el.dataset.fxCap="1",te(o.el,"captured",{accreted:o.accreted,load:_n(o)}),b("absorb")&&S("absorb",{body:o,count:o.accreted}),N.set(o,o.accreted)):l.fire==="released"&&(o.el.dataset.fxCap="0",te(o.el,"released",{accreted:0,load:0}),b("release")&&S("release",{body:o,count:N.get(o)??0}),N.delete(o))}}let ps=[{metric:"density",enter:.6,exit:.2,rise:"field:entered",fall:"field:exited"},{metric:"attention",enter:1.5,exit:1.1,rise:"field:attention-shifted",fall:"field:attention-settled"},{metric:"entropy",enter:.7,exit:.4,rise:"field:entropy-warning",fall:"field:entropy-cleared"}],gs=120;function rn(o,c,l){o.dispatchEvent(new CustomEvent(c,{bubbles:!0,composed:!0,detail:l}))}function so(o,c,l,x,f,v){let g=o.get(c);g||o.set(c,g=new Map);let d=g.get(x.metric);d||g.set(x.metric,d=new Be({enter:x.enter,exit:x.exit,debounceMs:gs}));let w=d.update(f,v);w==="entered"?rn(l,x.rise,{metric:x.metric,value:f}):w==="exited"&&rn(l,x.fall,{metric:x.metric,value:f})}function xs(o){for(let c of L)if(!(!c.vis||c.tokens.length===0))for(let l of ps){let x;switch(l.metric){case"density":x=c.d;break;case"attention":$.attention&&(x=c.attn??1);break;case"entropy":x=c.metrics?.entropy;break}x!==void 0&&so(Y,c,c.el,l,x,o)}for(let c of lt)so(P,c.agent,c.from.el,{metric:"memory",enter:.6,exit:.3,rise:"field:memory-threshold",fall:"field:memory-faded"},c.agent.memory,o)}function vs(o){for(let c of jt)c.docked===o&&(c.docked=null,c.dock.dock=0,c.el.getAttribute("aria-hidden")==="true"&&c.el.removeAttribute("aria-hidden"),c.el.removeAttribute("inert"),c.el.style.opacity="",te(c.el,"released",{}))}function ws(){if(jt.length===0)return;let o=jt.map(c=>{let l=c.el.getBoundingClientRect();return{x:l.left-St+l.width/2,y:l.top-G+l.height/2}});for(let c=0;c<jt.length;c++){let l=jt[c];if(!l.el.isConnected){l.docked&&(l.docked=null,l.dock.dock=0);continue}let x=o[c].x,f=o[c].y;if(l.docked){let k={x:x-l.o.x,y:f-l.o.y};l.dock.dock=qr(l.dock.dock,1);let z=Hr(k,l.o,{x:l.docked.cx,y:l.docked.cy},l.dock.dock);l.el.style.transform=`translate(${z.tx.toFixed(2)}px, ${z.ty.toFixed(2)}px) scale(${z.scale.toFixed(3)})`,l.el.style.opacity=z.opacity.toFixed(3),l.dock.dock>=1&&l.el.getAttribute("aria-hidden")!=="true"&&(l.el.setAttribute("aria-hidden","true"),l.el.setAttribute("inert",""));continue}At.x=x,At.y=f,At.vx=0,At.vy=0,At.heat=0,At.cap=null;for(let k of L){if(!k.vis||k.tokens.length===0||k.el===l.el)continue;let z=k.cx-x,T=k.cy-f,F=Math.hypot(z,T);W.dx=z,W.dy=T,W.dist=F<1?1:F;for(let O of k.tokens)p.forces[O]?.apply(k,At,W)}At.cap=null;let v=lr(l.o),g=At.vx+v.x,d=At.vy+v.y;if(l.layout){let k=fr({x,y:f},o,c),z=hr((T,F)=>a.near(T,F,40).length,x,f,16,6);g+=k.x+z.x,d+=k.y+z.y}let w={x:x-l.o.x,y:f-l.o.y};if(cr(l.o,g,d,l.mEl,.9),l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.dockable){let k={x:w.x+l.o.x,y:w.y+l.o.y},z=L.find(T=>T.vis&&T.el!==l.el&&T.tokens.indexOf("sink")>=0&&Bn(k,T));z&&(l.docked=z,te(l.el,"captured",{sink:z.el}))}if(l.warpCool>0&&(l.warpCool-=1),l.warpable&&l.warpCool===0){let k={x:w.x+l.o.x,y:w.y+l.o.y},z=L.find(T=>T.vis&&T.el!==l.el&&T.warpHas&&T.tokens.indexOf("warp")>=0&&Bn(k,T));z&&(l.o.x=z.warpX-w.x,l.o.y=z.warpY-w.y,l.o.vx=0,l.o.vy=0,l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.warpCool=45,te(l.el,"relocated",{from:z.el}))}}}function bs(){Qt.length&&(Qt=Qt.filter(o=>o.el.isConnected?!0:(o.el.removeEventListener("pointerenter",o.enter),o.el.removeEventListener("pointerleave",o.leave),o.el.removeEventListener("focus",o.enter),o.el.removeEventListener("blur",o.leave),delete o.el.dataset.fxEngaged,!1))),B.root.querySelectorAll("[data-hot]").forEach(o=>{let c=o;if(c.dataset.fxEngaged==="1")return;c.dataset.fxEngaged="1";let l=()=>{c.dataset.active="1",xe=c.dataset.color??null;let f=c.closest("[data-index][data-threads]");if(f){let v=[...f.querySelectorAll("[data-hot]")].filter(g=>g!==c);sn(v.map(g=>({a:c,b:g,color:c.dataset.color??void 0})))}},x=()=>{c.dataset.active="0",xe=null,sn(null)};c.addEventListener("pointerenter",l),c.addEventListener("pointerleave",x),c.addEventListener("focus",l),c.addEventListener("blur",x),Qt.push({el:c,enter:l,leave:x})})}function sn(o){Ze=(o??[]).map(c=>({a:c.a,b:c.b,c:gt(c.color??$.accent),seed:ut()*6.28}))}function Ms(){if(Ze.length===0)return;let o=W.t;e.globalCompositeOperation="lighter";for(let c of Ze){let l=c.a.getBoundingClientRect(),x=c.b.getBoundingClientRect(),f=l.left-St+l.width/2,v=l.top-G+l.height/2,g=x.left-St+x.width/2,d=x.top-G+x.height/2,[w,k,z]=c.c;e.strokeStyle=`rgba(${w},${k},${z},0.22)`,e.lineWidth=1,e.beginPath(),e.moveTo(f,v),e.lineTo(g,d),e.stroke();for(let T=0;T<3;T++){let F=(o*.6+c.seed+T/3)%1,O=f+(g-f)*F,q=v+(d-v)*F;e.fillStyle=`rgba(${w},${k},${z},${(1-F)*.9})`,e.beginPath(),e.arc(O,q,2.2,0,6.28318),e.fill()}}e.globalCompositeOperation="source-over"}let Me=0,ks=[1/0,1.5,1.25,1];function ke(o){if(!e)return;let c=Math.min(o||1,$.dprCap,ks[Me]??1/0);n.width=Math.floor(_*c),n.height=Math.floor(D*c),n.style.width=_+"px",n.style.height=D+"px",e.setTransform(c,0,0,c,0,0),i?.size(_,D,c)}function io(){let o=B.viewport();_=o.width,D=o.height,St=o.originX??0,G=o.originY??0,st=o.originX!=null||o.originY!=null,ke(o.dpr),W.W=_,W.H=D,dt=B.scrollHeight()-D||1;for(let c of m.values())c.resize(_,D);$.heatmap&&(tt?tt.resize(_,D):tt=new fe(_,D)),ro(),be()}function Es(){let o=W.t,c=16;if($.waveStyle==="circular"){let l=Gt||{x:_/2,y:D/2},x=Math.min(_,D)*.48;for(let f of wt){let[v,g,d]=f.color;e.beginPath();let w=.08,k=!0;for(let F=0;F<=2*Math.PI+.01;F+=w){let O=ce(f,F,o,x),q=l.x+Math.cos(F)*O,R=l.y+Math.sin(F)*O;k?(e.moveTo(q,R),k=!1):e.lineTo(q,R)}e.closePath();let z=f.baseFrac*x+f.offsetY,T=e.createRadialGradient(l.x,l.y,Math.max(0,z-f.amp),l.x,l.y,z+f.amp+80);T.addColorStop(0,`rgba(${v},${g},${d},${(.08+f.depth*.04)*ht})`),T.addColorStop(1,`rgba(${v},${g},${d},0)`),e.fillStyle=T,e.fill()}e.globalCompositeOperation="lighter";for(let f of wt){let[v,g,d]=f.color;e.beginPath();let w=.08,k=!0;for(let z=0;z<=2*Math.PI+.01;z+=w){let T=ce(f,z,o,x),F=l.x+Math.cos(z)*T,O=l.y+Math.sin(z)*T;k?(e.moveTo(F,O),k=!1):e.lineTo(F,O)}e.closePath(),e.lineWidth=5,e.strokeStyle=`rgba(${v},${g},${d},${(.05+f.depth*.04)*ht})`,e.stroke(),e.lineWidth=1.2,e.strokeStyle=`rgba(${v},${g},${d},${(.3+f.depth*.22)*ht})`,e.stroke()}e.globalCompositeOperation="source-over"}else{for(let l of wt){let[x,f,v]=l.color;e.beginPath(),e.moveTo(0,Et(l,0,o,D,1,1,xt));for(let w=0;w<=_;w+=c)e.lineTo(w,Et(l,w,o,D,1,1,xt));e.lineTo(_,D),e.lineTo(0,D),e.closePath();let g=l.baseFrac*D+l.offsetY-l.amp,d=e.createLinearGradient(0,g,0,g+320);d.addColorStop(0,`rgba(${x},${f},${v},${(.11+l.depth*.05)*ht})`),d.addColorStop(1,`rgba(${x},${f},${v},0)`),e.fillStyle=d,e.fill()}e.globalCompositeOperation="lighter";for(let l of wt){let[x,f,v]=l.color;e.beginPath(),e.moveTo(0,Et(l,0,o,D,1,1,xt));for(let g=0;g<=_;g+=c)e.lineTo(g,Et(l,g,o,D,1,1,xt));e.lineWidth=5,e.strokeStyle=`rgba(${x},${f},${v},${(.05+l.depth*.04)*ht})`,e.stroke(),e.lineWidth=1.2,e.strokeStyle=`rgba(${x},${f},${v},${(.3+l.depth*.22)*ht})`,e.stroke()}e.globalCompositeOperation="source-over"}}function Ss(){e.globalCompositeOperation="lighter";let o=W.t,c=0;if($.waveStyle==="circular"){let l=Gt||{x:_/2,y:D/2},x=Math.min(_,D)*.48;for(let f of qt){let v=wt[f.wi];if(!v){c++;continue}W.dt&&(f.progress+=f.speed,f.progress>1?f.progress-=1:f.progress<0&&(f.progress+=1));let g=f.progress*2*Math.PI,d=ce(v,g,o,x)+f.phase*32,w=l.x+Math.cos(g)*d,k=l.y+Math.sin(g)*d,[z,T,F]=v.color,O=f.glow?.6+.4*Math.sin(o*2.2+c):.85;f.glow&&(e.fillStyle=`rgba(${z},${T},${F},${.16*O*ht})`,e.beginPath(),e.arc(w,k,f.size+2.5,0,6.28318),e.fill()),e.fillStyle=`rgba(${z},${T},${F},${O*ht})`,e.beginPath(),e.arc(w,k,f.size,0,6.28318),e.fill(),c++}}else for(let l of qt){let x=wt[l.wi];if(!x){c++;continue}W.dt&&(l.progress+=l.speed,l.progress>1?l.progress-=1:l.progress<0&&(l.progress+=1));let f=l.progress*_,v=Et(x,f,o,D,1,1,xt)+l.phase*32,[g,d,w]=x.color,k=l.glow?.6+.4*Math.sin(o*2.2+c):.85;l.glow&&(e.fillStyle=`rgba(${g},${d},${w},${.16*k*ht})`,e.beginPath(),e.arc(f,v,l.size+2.5,0,6.28318),e.fill()),e.fillStyle=`rgba(${g},${d},${w},${k*ht})`,e.beginPath(),e.arc(f,v,l.size,0,6.28318),e.fill(),c++}e.globalCompositeOperation="source-over"}function zs(){if(!$.attention)return;for(let l of L)l.attn=1;let o=L.filter(l=>l.vis&&l.tokens.length>0);if(o.length===0)return;let c=To(o);for(let l=0;l<o.length;l++)o[l].attn=c[l]}function Fs(){if(!$.causality)return;let o=L.filter(l=>l.vis&&l.tokens.length>0);if(o.length===0)return;if(o.length===1){ao(o[0],o[0].d);return}let c=Ao(o.map(l=>({d:l.d,cx:l.cx,cy:l.cy})));for(let l=0;l<o.length;l++)ao(o[l],bt(o[l].d+c[l],0,1))}function ao(o,c){$.feedbackSink(o.el,{lit:c})}function Ts(){for(let o of L){if(!o.feedback)continue;let c=zo(o.count,o.on);o.d+=(c-o.d)*.08;let l=o.writeTarget??o.el;if(o.fmax){let w=Fo(o.fmin,o.fmax,o.d);ue.get(l)!==w&&(ue.set(l,w),l.style.fontVariationSettings=`"wght" ${w}`+(o.opsz?`, "opsz" ${o.opsz}`:""))}let x=tt?tt.norm(o.cx,o.cy):void 0,f=o.tokens.indexOf("sink")>=0&&o.capacity>0?_n(o):void 0,v=gr(o.thermo),g=o.metrics??(o.metrics={entropy:0,coherence:1,temperature:0});g.entropy+=(v.entropy-g.entropy)*.08,g.coherence+=(v.coherence-g.coherence)*.08,g.temperature+=(v.temperature-g.temperature)*.08;let d={density:o.d,heatmapDensity:x,load:f,entropy:g.entropy,coherence:g.coherence,temperature:g.temperature};$.feedbackSink(l,d),o.onFeedback?.(d)}}function As(){if(Kt.length!==0){e.globalCompositeOperation="lighter";for(let o=Kt.length-1;o>=0;o--){let c=Kt[o];if(!c)continue;if(c.x+=c.vx,c.y+=c.vy,c.vx*=.9,c.vy*=.9,c.life*=.85,c.life<.05){Kt.splice(o,1);continue}let[l,x,f]=c.c;e.fillStyle=`rgba(${l},${x},${f},${.18*c.life})`,e.beginPath(),e.arc(c.x,c.y,2+c.life*4,0,6.28318),e.fill(),e.fillStyle=`rgba(${l},${x},${f},${c.life})`,e.beginPath(),e.arc(c.x,c.y,.6+c.life*1.5,0,6.28318),e.fill()}e.globalCompositeOperation="source-over"}}let Yt=null,Ee=null,ee=null;function Cs(){if(!tt)return;let o=D>0?bt((1.15-Xt/D)/.85,0,1):1;if(o<=.01)return;let c=tt.cell,l=Math.max(1,Math.ceil(_/c)),x=Math.max(1,Math.ceil(D/c));if(Yt||(Yt=B.createCanvas(),Ee=Yt.getContext("2d")),!!Ee){if((Yt.width!==l||Yt.height!==x)&&(Yt.width=l,Yt.height=x,ee=null),ee===null||Nt%3===0){ee===null&&(ee=Ee.createImageData(l,x));let f=it,v=ee.data;for(let g=0;g<x;g++)for(let d=0;d<l;d++){let w=tt.norm(d*c+c/2,g*c+c/2),k=(g*l+d)*4;v[k]=f[0],v[k+1]=f[1],v[k+2]=f[2],v[k+3]=Math.round(bt(w*.5*ht,0,1)*255)}Ee.putImageData(ee,0,0)}e.globalCompositeOperation="lighter",e.imageSmoothingEnabled=!0,e.globalAlpha=o,e.drawImage(Yt,0,0,_,D),e.globalAlpha=1,e.globalCompositeOperation="source-over"}}function Os(){$.background==="transparent"?$.render==="trails"?(e.globalCompositeOperation="destination-out",e.fillStyle="rgba(0,0,0,0.22)",e.fillRect(0,0,_,D),e.globalCompositeOperation="source-over"):e.clearRect(0,0,_,D):($.render==="trails"?e.fillStyle="rgba(5,6,11,0.22)":e.fillStyle="rgb(5,6,11)",e.fillRect(0,0,_,D)),Es(),tt&&Me<2&&Cs(),Ss();let o=$.render!=="metaballs"&&$.render!=="streamlines";e.globalCompositeOperation="lighter";let c=it,l=_/2,x=D*.4,f=Math.hypot(Math.max(l,_-l),Math.max(x,D-x))||1;if(ge===null||Nt%6===0){ge=[];for(let g of L){if(!g.tint)continue;let d=(g.range||200)*1.4;ge.push({b:g,r2:d*d,rgb:gt(g.tint)})}}let v=ge;if(o)for(let g of a.particles){if(g.cap){e.fillStyle=`rgba(${c[0]},${c[1]},${c[2]},${.55*ht})`,e.beginPath(),e.arc(g.x,g.y,1.3,0,6.28318),e.fill();continue}let d=Math.min(1,Math.hypot(g.x-l,g.y-x)/f),w=d*d,k=g.heat;Mo(qe,w,k,c,$.gradientCool,$.gradientWarm);let z=qe[0],T=qe[1],F=qe[2];if(v.length){let pt=0,nt=null;for(let ct of v){let Ct=g.x-ct.b.cx,Ot=g.y-ct.b.cy,se=Ct*Ct+Ot*Ot;if(se>=ct.r2)continue;let I=1-Math.sqrt(se/ct.r2);I>pt&&(pt=I,nt=ct.rgb)}if(nt){let ct=pt*.7;z+=(nt[0]-z)*ct,T+=(nt[1]-T)*ct,F+=(nt[2]-F)*ct}}if(g.color){let[pt,nt,ct]=gt(g.color);z+=(pt-z)*.75,T+=(nt-T)*.75,F+=(ct-F)*.75}let O=$.depth>0?1-Math.min(Math.abs(g.z??0)/$.depth,1)*.55:1,q=(g.size*(1-.4*w)+k*2)*O,R=bt((.5-.3*w+k*.5)*ht*O,0,1),X=z|0,at=T|0,Mt=F|0;e.fillStyle=`rgba(${X},${at},${Mt},${.12*R})`,e.beginPath(),e.arc(g.x,g.y,q+1.2,0,6.28318),e.fill(),e.fillStyle=`rgba(${X},${at},${Mt},${R})`,e.beginPath(),e.arc(g.x,g.y,q,0,6.28318),e.fill()}if(As(),Ms(),e.globalCompositeOperation="source-over",$.render==="links"){e.globalCompositeOperation="lighter";let g=it,d=90;e.lineWidth=.6;for(let w of a.particles)if(!w.cap)for(let k of a.neighbors(w,d)){if(k.x<w.x||k.x===w.x&&k.y<w.y)continue;let z=Or(Math.hypot(k.x-w.x,k.y-w.y),d);z<=0||(e.strokeStyle=`rgba(${g[0]},${g[1]},${g[2]},${z})`,e.beginPath(),e.moveTo(w.x,w.y),e.lineTo(k.x,k.y),e.stroke())}e.globalCompositeOperation="source-over"}if($.render==="metaballs"){let k=Math.ceil(_/16)+1,z=Math.ceil(D/16)+1;!Dt||Dt.length!==k*z?Dt=new Float32Array(k*z):Dt.fill(0);for(let F of a.particles)F.cap||In(Dt,k,z,16,F.x,F.y,34,1);let T=it;e.globalCompositeOperation="lighter",e.strokeStyle=`rgba(${T[0]},${T[1]},${T[2]},${.5*ht})`,e.lineWidth=1.4,e.lineCap="round",e.beginPath();for(let F=0;F<z-1;F++)for(let O=0;O<k-1;O++){let q=Dt[F*k+O],R=Dt[F*k+O+1],X=Dt[(F+1)*k+O+1],at=Dt[(F+1)*k+O],Mt=$n(q,R,X,at,.9);if(!Mt.length)continue;let pt=O*16,nt=F*16;for(let ct of Mt)e.moveTo(pt+ct.x1*16,nt+ct.y1*16),e.lineTo(pt+ct.x2*16,nt+ct.y2*16)}e.stroke(),e.globalCompositeOperation="source-over"}if($.render==="voronoi"){let w=Math.ceil(_/18)+1,k=Math.ceil(D/18)+1;(!re||re.length!==w*k)&&(re=new Int32Array(w*k));let z=a.particles,T=new Map;for(let O=0;O<z.length;O++)T.set(z[O],O);for(let O=0;O<k;O++)for(let q=0;q<w;q++){let R=q*18,X=O*18,at=a.near(R,X,54),Mt=-1;if(at.length){let pt=Pr(R,X,at);pt>=0&&(Mt=T.get(at[pt])??-1)}re[O*w+q]=Mt}let F=it;e.globalCompositeOperation="lighter",e.strokeStyle=`rgba(${F[0]},${F[1]},${F[2]},${.32*ht})`,e.lineWidth=1,e.beginPath();for(let O of Rr(re,w,k))e.moveTo(O.x1*18,O.y1*18),e.lineTo(O.x2*18,O.y2*18);e.stroke(),e.globalCompositeOperation="source-over"}if($.render==="streamlines"||$.render==="flow"){let d=it;if(e.lineWidth=1,e.lineCap="round",pe===null||yt||Nt%3===0){let w=[],k=[],z=0;for(let T=46/2;T<_;T+=46)for(let F=46/2;F<D;F+=46){let{fx:O,fy:q}=Vt(L,p.forces,W,T,F);if(yt){let X=le(We,T,F,yt,.04);O+=X.x,q+=X.y}let R=Math.hypot(O,q);if(!(R>1e-9)){k.push({gx:T,gy:F});continue}w.push({gx:T,gy:F,ux:O/R,uy:q/R,mag:R}),R>z&&(z=R)}Ht===0?Ht=z:Ht=z>Ht?Ht*.7+z*.3:Ht*.9+z*.1,pe=w,Ke=k}if(Ke.length){e.fillStyle=`rgba(${d[0]},${d[1]},${d[2]},0.05)`;for(let w of Ke)e.fillRect(w.gx-.5,w.gy-.5,1,1)}if(Ht>0&&pe)for(let w of pe){let k=Math.sqrt(w.mag/Ht),z=46*.46*(.28+.72*k),T=w.gx+w.ux*z,F=w.gy+w.uy*z;e.strokeStyle=`rgba(${d[0]},${d[1]},${d[2]},${bt(.1+k*.5,0,.72)})`,e.beginPath(),e.moveTo(w.gx,w.gy),e.lineTo(T,F);let O=3.4;e.moveTo(T,F),e.lineTo(T-w.ux*O-w.uy*O*.6,F-w.uy*O+w.ux*O*.6),e.moveTo(T,F),e.lineTo(T-w.ux*O+w.uy*O*.6,F-w.uy*O-w.ux*O*.6),e.stroke()}}}function co(o){return(o===void 0?[]:Array.isArray(o)?o:[o]).filter(l=>l!=="off")}function lo(o,c,l){let f=it;if(Qe===null||yt||Nt%3===0){let d=[],w=0;for(let k=44/2;k<_;k+=44)for(let z=44/2;z<D;z+=44){let{fx:T,fy:F}=Vt(L,p.forces,W,k,z);if(yt){let q=le(We,k,z,yt,.04);T+=q.x,F+=q.y}let O=Math.hypot(T,F);O>1e-9&&(d.push({gx:k,gy:z,ux:T/O,uy:F/O,mag:O}),O>w&&(w=O))}Lt===0?Lt=w:Lt=w>Lt?Lt*.7+w*.3:Lt*.9+w*.1,Qe=d}if(Lt<=0)return;let v={r:f[0],g:f[1],b:f[2],alpha:0,width:1.2},g=new Float64Array(12);for(let d of Qe){let w=l?bt(d.mag/Lt,0,1):Math.sqrt(d.mag/Lt),k=44*.5*(.25+.75*w),z=d.gx+d.ux*k,T=d.gy+d.uy*k,F=3.6;g[0]=d.gx,g[1]=d.gy,g[2]=z,g[3]=T,g[4]=z,g[5]=T,g[6]=z-d.ux*F-d.uy*F*.6,g[7]=T-d.uy*F+d.ux*F*.6,g[8]=z,g[9]=T,g[10]=z-d.ux*F+d.uy*F*.6,g[11]=T-d.uy*F-d.ux*F*.6,v.alpha=bt(.12+w*.55,0,.8),o.segments(g,v)}}function Ps(o){let c=sr(L);if(!c.length)return;let l=nr((v,g)=>$e(L,p.forces,v,g),c,{step:6,maxSteps:200,bounds:{w:_,h:D},loopDist:8}),x=it,f={r:x[0],g:x[1],b:x[2],alpha:.42,width:1.1};for(let v of l){if(v.length<2)continue;let g=new Float32Array(v.length*2);for(let d=0;d<v.length;d++)g[d*2]=v[d].x,g[d*2+1]=v[d].y;o.polyline(g,f)}}function Rs(o){let l=22*$.gridWarp,x=48*.46,f=Math.floor(_/48)+2,v=Math.floor(D/48)+2,g=new Float32Array(f*v),d=new Float32Array(f*v),w=0,k=new Float32Array(f*v);for(let I=0;I<v;I++)for(let j=0;j<f;j++){let{fx:et,fy:J}=Vt(L,p.forces,W,j*48,I*48),ot=Math.hypot(et,J),kt=I*f+j;ot>1e-9&&(g[kt]=et/ot,d[kt]=J/ot,k[kt]=ot,ot>w&&(w=ot))}let z=[it,[120,110,255],[240,70,255],[255,50,130]],T=8,F=I=>w>0?Math.sqrt(k[I]/w):0,O=I=>Math.round(F(I)*T),q=I=>{let j=I/T,et=Mn(z,j);return{r:et[0],g:et[1],b:et[2],alpha:Math.min(1,$.gridIntensity*(.3+.85*j)),width:j>.55?1.4:1}},R=new Float32Array(f*v),X=new Float32Array(f*v);for(let I=0;I<f*v;I++){let j=F(I);R[I]=g[I]*j*l,X[I]=d[I]*j*l}let at=new Float32Array(f*v),Mt=new Float32Array(f*v);for(let I=0;I<v;I++)for(let j=0;j<f;j++){let et=0,J=0,ot=0;for(let Pt=-1;Pt<=1;Pt++)for(let Rt=-1;Rt<=1;Rt++){let Tt=j+Rt,$t=I+Pt;if(Tt<0||$t<0||Tt>=f||$t>=v)continue;let ne=$t*f+Tt;et+=R[ne],J+=X[ne],ot++}let kt=I*f+j;at[kt]=et/ot,Mt[kt]=J/ot}let pt=48*1.5,nt=(I,j)=>{let et=j*f+I,J=at[et],ot=Mt[et],kt=Math.hypot(J,ot);kt>x&&(J=J/kt*x,ot=ot/kt*x);let Pt=I*48,Rt=j*48,Tt=Math.min(Pt,_-Pt,Rt,D-Rt),$t=Tt<=0?0:Tt<pt?Tt/pt:1;return[Pt+J*$t,Rt+ot*$t]},ct=4,Ct=I=>{let j=I.length>>1;if(j<3)return I;let et=[I[0],I[1]];for(let J=0;J<j-1;J++){let ot=(J>0?J-1:0)<<1,kt=J<<1,Pt=J+1<<1,Rt=(J+2<j?J+2:j-1)<<1,Tt=I[ot],$t=I[ot+1],ne=I[kt],ln=I[kt+1],dn=I[Pt],fn=I[Pt+1],po=I[Rt],go=I[Rt+1];for(let hn=1;hn<=ct;hn++){let ie=hn/ct,un=ie*ie,xo=un*ie;et.push(.5*(2*ne+(-Tt+dn)*ie+(2*Tt-5*ne+4*dn-po)*un+(-Tt+3*ne-3*dn+po)*xo),.5*(2*ln+(-$t+fn)*ie+(2*$t-5*ln+4*fn-go)*un+(-$t+3*ln-3*fn+go)*xo))}}return et},Ot=(I,j)=>Math.max(O(I*f+j),O(I*f+j+1)),se=(I,j)=>Math.max(O(j*f+I),O((j+1)*f+I));for(let I=0;I<v;I++){let j=Ot(I,0),et=[...nt(0,I),...nt(1,I)];for(let J=1;J<f-1;J++){let ot=Ot(I,J);ot===j?et.push(...nt(J+1,I)):(o.polyline(Ct(et),q(j)),et=[...nt(J,I),...nt(J+1,I)],j=ot)}o.polyline(Ct(et),q(j))}for(let I=0;I<f;I++){let j=se(I,0),et=[...nt(I,0),...nt(I,1)];for(let J=1;J<v-1;J++){let ot=se(I,J);ot===j?et.push(...nt(I,J+1)):(o.polyline(Ct(et),q(j)),et=[...nt(I,J),...nt(I,J+1)],j=ot)}o.polyline(Ct(et),q(j))}}let zt=null;function fo(o,c,l){let v=Math.ceil(_/24)+1,g=Math.ceil(D/24)+1;!zt||zt.length!==v*g?zt=new Float32Array(v*g):zt.fill(0);let d=!1;for(let F of a.particles){if(F.cap)continue;let O=c(F);O<=0||(d=!0,In(zt,v,g,24,F.x,F.y,42,O))}if(!d)return;let w=0;for(let F=0;F<zt.length;F++)zt[F]>w&&(w=zt[F]);if(w<=0)return;let k=it,z=[.25,.5,.78],T=[];for(let F=0;F<z.length;F++){let O=z[F]*w;T.length=0;for(let q=0;q<g-1;q++)for(let R=0;R<v-1;R++){let X=zt[q*v+R],at=zt[q*v+R+1],Mt=zt[(q+1)*v+R+1],pt=zt[(q+1)*v+R],nt=$n(X,at,Mt,pt,O);if(!nt.length)continue;let ct=R*24,Ct=q*24;for(let Ot of nt)T.push(ct+Ot.x1*24,Ct+Ot.y1*24,ct+Ot.x2*24,Ct+Ot.y2*24)}T.length&&o.segments(T,{r:k[0],g:k[1],b:k[2],alpha:l*(.45+.55*(F/(z.length-1))),width:1+F*.3})}}function $s(o){let f=it,v={r:f[0],g:f[1],b:f[2],alpha:0,width:1.1},g=new Float64Array(4);for(let d=104/2;d<_;d+=104)for(let w=104/2;w<D;w+=104){let k=d,z=w;for(let T=0;T<24;T++){let{fx:F,fy:O}=Vt(L,p.forces,W,k,z);if(yt){let at=le(We,k,z,yt,.04);F+=at.x,O+=at.y}let q=Math.hypot(F,O);if(!(q>1e-9))break;let R=k+F/q*9,X=z+O/q*9;if(R<0||X<0||R>_||X>D)break;g[0]=k,g[1]=z,g[2]=R,g[3]=X,v.alpha=.34*(1-T/24),o.segments(g,v),k=R,z=X}}}function Is(o){let c=it;for(let l of L){if(!l.vis||!l.feedback)continue;let x=`d ${l.d.toFixed(2)}`,f=l.cx+l.hw+8,v=l.cy;o.rect(f-3,v-7,o.measureText(x)+6,14,c[0],c[1],c[2],bt(.3+l.d*.55,0,.85)),o.text(x,f,v+.5,5,6,11,.92)}}function Ns(o,c){if(o.clear(),!(!c.length||_===0||D===0))for(let l of c){l==="streamlines"?lo(o,!1,!1):l==="force-vectors"?lo(o,!1,!0):l==="field-lines"?Ps(o):l==="grid"?Rs(o):l==="temperature"?fo(o,f=>f.heat,.5):l==="energy"?fo(o,f=>.5*f.m*(f.vx*f.vx+f.vy*f.vy),.42):l==="path"?$s(o):l==="data"&&Is(o);let x=Q.get(l);x&&x(o,W,_,D)}}function an(o){Nt++,W.t=(o-no)/1e3,W.frameN=Nt;let c=Number.isFinite(Je)?(o-Je)/16.6667:1;if(Je=o,W.dt=rt?0:bt(c,.2,2),ht<1&&(ht=Math.min(1,ht+.012)),Po(W.form,Un,.03),st){let d=B.viewport();St=d.originX??0,G=d.originY??0}let l=B.scrollY(),x=l-Xt;if(W.scrollV=(W.scrollV??0)*.7+Math.abs(x)*.3,Xt=l,x!==0&&!st)for(let d of L)d.cy-=x;for(let d of wt){let w=l*(.025+d.depth*.08);d.offsetY+=(w-d.offsetY)*.04}if(L.length&&Nt%6===0&&(De(L,_,D,St,G),u(L),Wr(L,W.supernova)),W.dt!==0&&os(),lt.length&&W.dt){let d=W.dt/60;for(let w of lt)Lr(w.agent,w.from.d>.08,0,d)}let f=null;for(let d of L)if(d.on&&d.vis){f=d;break}let v=yt??f;if(xt.k+=((v?1:0)-xt.k)*.07,v){let d=yt?yt.x:f.cx,w=yt?yt.y:f.cy;xt.x=xt.x?xt.x+(d-xt.x)*.16:d,xt.y=xt.y?xt.y+(w-xt.y)*.16:w}Nt%30===0&&(dt=B.scrollHeight()-D||1);let g=xe?gt(xe):Mn(eo,l/dt);if(it=[it[0]+(g[0]-it[0])*.08,it[1]+(g[1]-it[1])*.08,it[2]+(g[2]-it[2])*.08],$.accent=bn(it),a.reindex(),zs(),W.dt&&mr(L,a.particles),yt&&W.dt)for(let d of a.particles){if(d.cap)continue;let w=le(We,d.x,d.y,yt,.6);d.vx+=w.x,d.vy+=w.y}if($.waveStyle==="circular")if($.waveCenter)Gt=typeof $.waveCenter=="function"?$.waveCenter():$.waveCenter;else{let d=L.find(w=>w.tokens.includes("star")||w.tokens.includes("vortex"));d?Gt={x:d.cx,y:d.cy}:Gt={x:_/2,y:D/2}}else Gt=null;if(fs(),qo({store:a,bodies:L,env:W,forces:p.forces,conditions:p.conditions,waves:wt,waveStyle:$.waveStyle,waveCenter:Gt,separation:$.separation}),_t&&(_t.x=Zn,_t.y=to,_t.vx=0,_t.vy=0,_t.heat=Math.min(1,_t.heat+.2)),W.dt){for(let d of m.values())d.step();tt&&tt.update(a.particles),ur(a,qt,Qn,wt,_,D,W.t,ut),yr(qt,wt,L,p.forces,_,D,W.t,d=>void a.add(Zt(d))),ws(),hs()}if(Ts(),es(),Fs(),us(),ys(),ms(),xs(o),A(),e&&$.render!=="none"&&Yn&&(!rt||Nt%4===0)&&(Os(),i)){let d=co($.overlay);d.length&&Ns(i,d)}It=B.raf(an)}function cn(o){let c=Te[o];c&&(Un={...c.preset},Ve=o)}let Se="",ho=no;function uo(){let o=B.viewport().height*.5,c="";B.root.querySelectorAll("[data-formation]").forEach(l=>{let x=l.getBoundingClientRect();x.top<=o&&x.bottom>=o&&(c=l.dataset.formation??"")}),c&&c!==Se&&(Se=c,cn(c))}let yo=()=>void(ho=Xe()),Ds=()=>{yo(),uo()},mo=setInterval(()=>{Xe()-ho>6e3&&Se!=="ambient"&&(Se="ambient",cn("ambient"))},1200);mo.unref?.();let Ls=()=>io();io();let _s=()=>{B.hidden()?(B.cancelRaf(It),It=0):It||(It=B.raf(an))};return ft.push(B.onResize(Ls)),ft.push(B.onScroll(Ds)),ft.push(B.onVisibility(_s)),ft.push(B.onInput(yo)),ft.push(B.onBodyEvent(Fr,as)),ft.push(B.onBodyEvent(Tr,cs)),ft.push(B.onBodyEvent(Ar,ls)),uo(),It=B.raf(an),{projections:ns,scan:be,rescan:be,setAccent:o=>{$.accent=o,it=gt(o)},setPalette:o=>{let c=Ae(o);eo=c.map(gt);let l=c[0];l&&($.accent=l,it=gt(l))},setFormation:cn,setWaveStyle:o=>{$.waveStyle=o},setWaveCenter:o=>{$.waveCenter=o},setSeparation:o=>{$.separation=o>=0?o:0},setAttention:o=>{if($.attention=o,!o)for(let c of L)c.attn=1},setCausality:o=>{if($.causality=o,!o)for(let c of L)c.el.style.removeProperty("--lit"),c.el.dataset.fxLit="0"},setRender:o=>{if(o!=="none"&&!e){if(e=n.getContext("2d"),!e){console.warn(`Fundamental: setRender('${o}') could not acquire a 2d context; staying in render 'none'`);return}r&&!s&&(s=r.getContext("2d"),s&&!i&&(i=t.overlayBackend??Nn(r,s))),ke(B.viewport().dpr)}$.render=o},setOverlay:o=>{$.overlay=o,co(o).length||i?.clear()},setHeatmap:o=>{if($.heatmap=o,o)!tt&&_>0&&(tt=new fe(_,D));else if(tt){tt.clear(),tt=null;for(let c of L)(c.writeTarget??c.el).style.removeProperty("--field-heatmap-density")}},setDprCap:o=>{$.dprCap=o>0?o:2,e&&ke(B.viewport().dpr)},setQualityTier:o=>{let c=Math.max(0,Math.min(3,Math.floor(o||0)));c!==Me&&(Me=c,e&&ke(B.viewport().dpr))},threads:sn,burst:(o,c,l)=>{for(let f of a.particles){let v=ar(f.x-o,f.y-c,160,6,f.z??0);v.heat!==0&&(f.vx+=v.vx,f.vy+=v.vy,v.vz&&(f.vz=(f.vz??0)+v.vz),f.heat=Math.max(f.heat,v.heat),l&&(f.color=l))}Cn(qt,wt,o,c,160,_,D,W.t,f=>void a.add(Zt(f))),oo(o,c,2,l)},flowTo:(o,c,l)=>{yt=tr(o,c,l)},clearFlow:()=>{yt=null},seed:o=>{we=o,ro()},atomAt:(o,c)=>{let l=null,x=1/0;for(let f of a.near(o,c,24)){if(f.atom==null)continue;let v=(f.x-o)**2+(f.y-c)**2+(f.z??0)**2;v<x&&(x=v,l=f.atom)}return l},focusAt:(o,c)=>{let l=null,x=1/0;for(let f of a.near(o,c,24)){if(f.atom==null)continue;let v=(f.x-o)**2+(f.y-c)**2+(f.z??0)**2;v<x&&(x=v,l=f)}return _t=l,l?(Zn=l.x,to=l.y,l.atom??null):null},clearFocus:()=>{_t=null},particleCount:()=>a.size,readParticles:o=>{let c=a.particles,l=Math.floor(o.length/5),x=0;for(let f=0;f<c.length&&x<l;f++){let v=c[f];if(v.report!==void 0)continue;let g=x*5;o[g]=v.x,o[g+1]=v.y,o[g+2]=v.z??0,o[g+3]=v.heat,o[g+4]=v.size,x++}return x},readParticleIds:o=>{let c=a.particles,l=0;for(let x=0;x<c.length&&l<o.length;x++){let f=c[x];f.report===void 0&&(o[l++]=f.id??0)}return l},readParticleChannels:(o,c)=>{let l=a.particles,x=0;for(let f=0;f<l.length;f++){let v=l[f];if(!("report"in v&&v.report!==void 0)){if(x>=Math.min(...c.map(g=>g.length)))break;for(let g=0;g<o.length&&!(g>=c.length);g++){let d=o[g];c[g][x]=d==="x"?v.x:d==="y"?v.y:d==="z"?v.z??0:d==="vx"?v.vx:d==="vy"?v.vy:d==="heat"?v.heat:d==="size"?v.size:d==="m"?v.m:d==="id"?v.id??0:d==="age"?v.age??0:d==="charge"?v.charge??0:0}x++}}return x},registerOverlay:(o,c)=>(Q.set(o,c),()=>{Q.delete(o)}),addAgent:o=>{let c=Zt({x:o.x,y:o.y,z:o.z,species:o.species});return c.vx=0,c.vy=0,o.z===void 0&&$.depth<=0&&(c.z=0),o.mass!==void 0&&(c.m=o.mass),c.maxSpeed=o.maxSpeed,c.report=o.report,a.add(c),{particle:c,remove:()=>a.remove(c)}},addBody:o=>{let c={"data-body":Array.isArray(o.tokens)?o.tokens.join(" "):String(o.tokens)};o.strength!=null&&(c["data-strength"]=String(o.strength)),o.range!=null&&(c["data-range"]=String(o.range)),o.spin!=null&&(c["data-spin"]=String(o.spin)),o.angle!=null&&(c["data-angle"]=String(o.angle)),o.color!=null&&(c["data-color"]=o.color);let l=()=>{let d=o.rect();return{left:d.left,top:d.top,right:d.left+d.width,bottom:d.top+d.height,width:d.width,height:d.height,x:d.left,y:d.top,toJSON:()=>({})}},x={tagName:"DIV",id:"",className:"",dataset:o.color!=null?{color:o.color}:{},getAttribute:d=>c[d]??null,hasAttribute:d=>d in c,getBoundingClientRect:l,dispatchEvent:()=>!0,setAttribute:()=>{},removeAttribute:()=>{},style:{setProperty:()=>{},removeProperty:()=>{},getPropertyValue:()=>""}},f=de(x);f.rect=l,f.data=o.data,o.authority&&(f.authority=o.authority),f.feedback=!0;let v={};f.onFeedback=d=>{Object.assign(v,d),o.onFeedback?.(d)},K.push(f),L=L.concat(f),De([f],_,D,St,G);let g={data:o.data,get channels(){return v},set:d=>{d.strength!=null&&(c["data-strength"]=String(d.strength)),d.range!=null&&(c["data-range"]=String(d.range)),d.spin!=null&&(c["data-spin"]=String(d.spin)),d.angle!=null&&(c["data-angle"]=String(d.angle)),d.color!=null&&(c["data-color"]=d.color,x.dataset.color=d.color,f.tint=d.color)},remove:()=>{let d=K.indexOf(f);d>=0&&K.splice(d,1),L=L.filter(w=>w!==f);for(let w=lt.length-1;w>=0;w--){let k=lt[w];(k.from===f||k.to===f)&&lt.splice(w,1)}}};return Z.set(g,f),g},addEdge:(o,c,l)=>{let x=Z.get(o),f=Z.get(c);if(!x||!f)throw new Error("addEdge: both arguments must be handles returned by addBody on this field.");let v={id:`e${mt++}`,from:"",to:"",type:l?.type??"related",strength:l?.strength??.5,tension:0,memory:0,active:!1},g={agent:v,from:x,to:f,fromData:o.data,toData:c.data};return lt.push(g),{set:d=>{d.strength!=null&&(v.strength=d.strength<0?0:d.strength>1?1:d.strength),d.type!=null&&(v.type=d.type)},remove:()=>{let d=lt.indexOf(g);d>=0&&lt.splice(d,1)}}},readEdges:()=>lt.map(o=>({from:o.fromData,to:o.toData,type:o.agent.type,strength:o.agent.strength,memory:o.agent.memory,active:o.agent.active})),query:(o={})=>{let c=o.at,l,x=0,f=0,v=0,g=!1;c&&("width"in c?(l={x:c.x,y:c.y,width:c.width,height:c.height},x=c.x+c.width/2,f=c.y+c.height/2,v=Math.max(c.width,c.height)/2):(v=o.radius??240,x=c.x,f=c.y,l={x:x-v,y:f-v,width:v*2,height:v*2}),g=!0);let d=new Set(o.include??(g?["bodies","metrics","relationships","influences"]:["bodies","metrics","relationships"])),w=R=>{if(!R.vis)return!1;if(!g)return!0;if("width"in c){let X=l;return R.cx>=X.x&&R.cx<=X.x+X.width&&R.cy>=X.y&&R.cy<=X.y+X.height}return Math.hypot(R.cx-x,R.cy-f)<=v},k=L.filter(w),z=d.has("bodies")?k.map(R=>{let{metrics:X,dimensions:at}=Vn(R);return{id:Bt(R),rect:{x:R.cx-R.hw,y:R.cy-R.hh,width:R.hw*2,height:R.hh*2},tokens:R.tokens.slice(),metrics:X,dimensions:at,activeFormations:[Ve],authority:R.authority??"anchored"}}):[],T={};if(d.has("metrics")&&(T.particles=a.size,T.bodies=k.length,k.length>0)){let R=0;for(let X of k)R+=X.d;T.meanDensity=R/k.length}let F=d.has("relationships")?lt.filter(R=>!g||w(R.from)||w(R.to)).map(R=>({from:Bt(R.from),to:Bt(R.to),type:R.agent.type,strength:R.agent.strength,memory:R.agent.memory,active:R.agent.active,causal:R.agent.active})):[],O=[];if(d.has("influences")&&g)for(let R of k){if(R.tokens.length===0)continue;let X=Wn(p.forces,R.tokens,R,x,f);for(let at of X.attribution)O.push({source:Bt(R),force:at.force,channel:at.channel,contribution:at.contribution})}let q={query:o,frame:W.frameN,time:W.t,region:l,bodies:z,metrics:T,relationships:F,influences:O,projections:ye()};return o.lens?Zo(q,o.lens):q},snapshot:(o={})=>{let c=o.includeRelationships!==!1,l=L.filter(d=>d.vis),x=l.map(d=>{let{metrics:w,dimensions:k}=Vn(d),z={id:Bt(d),authority:d.authority??"anchored",rect:{x:d.cx-d.hw,y:d.cy-d.hh,width:d.hw*2,height:d.hh*2},position:{x:d.cx,y:d.cy,z:0},tokens:d.tokens.slice(),metrics:w,dimensions:k};return o.includeData&&(z.data=rs(d.data)),z}),f=c?lt.map(d=>({from:Bt(d.from),to:Bt(d.to),type:d.agent.type,strength:d.agent.strength,memory:d.agent.memory,active:d.agent.active,causal:d.agent.active})):[],v={particles:a.size,bodies:l.length};if(l.length>0){let d=0;for(let w of l)d+=w.d;v.meanDensity=d/l.length}let g={id:`snap-${W.frameN}-${Zr++}`,createdAt:W.t,frame:W.frameN,version:ze,formations:[Ve],bodies:x,relationships:f,metrics:v,projections:ye()};if(o.includeParticles){let d=[];for(let w of a.particles)w.cap||d.push({x:w.x,y:w.y,z:w.z??0,heat:w.heat,size:w.size});g.particles=d}if(o.includeInfluences){let d=[];for(let w of l){if(w.tokens.length===0)continue;let k=Wn(p.forces,w.tokens,w,w.cx+8,w.cy);for(let z of k.attribution)d.push({source:Bt(w),force:z.force,channel:z.channel,contribution:z.contribution})}g.influences=d}return g},diff:(o,c)=>kn(o,c),replay:(o,c,l)=>Oo(o,c,l),addField:(o,c)=>(U.set(o,c),{name:o,set:l=>{U.set(o,l)},remove:()=>{U.delete(o)}}),sampleField:(o,c,l)=>{let x=U.get(o);return x?x(c,l):0},energy:()=>jr(a.particles),sample:(o,c)=>{let{fx:l,fy:x}=Vt(L,p.forces,W,o,c);return{x:l,y:x}},sampleScalar:(o,c)=>tt?tt.norm(o,c):(Rn("NOOP_NO_HEATMAP","sampleScalar() returned 0 because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),0),sampleGradient:(o,c)=>tt?tt.gradient(o,c):(Rn("NOOP_NO_HEATMAP","sampleGradient() returned { x: 0, y: 0 } because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),{x:0,y:0}),grid:o=>W.grid(o),on:(o,c)=>{let l=y.get(o);return l||(l=new Set,y.set(o,l)),l.add(c),()=>void l.delete(c)},version:ze,scrollV:()=>W.scrollV??0,setVisible:o=>{Yn=o},setBackground:o=>{$.background=o,o==="transparent"&&e&&e.clearRect(0,0,_,D)},destroy:()=>{B.cancelRaf(It),clearInterval(mo);for(let o of ft)o();for(let o of Qt)o.el.removeEventListener("pointerenter",o.enter),o.el.removeEventListener("pointerleave",o.leave),o.el.removeEventListener("focus",o.enter),o.el.removeEventListener("blur",o.leave),delete o.el.dataset.fxEngaged;Qt=[];for(let o of jt)(o.docked||o.dock.dock>0)&&(o.docked=null,o.dock.dock=0,o.el.style.opacity="",o.el.getAttribute("aria-hidden")==="true"&&o.el.removeAttribute("aria-hidden"),o.el.removeAttribute("inert"));for(let o of Jt)for(let c of o.emitted)c.remove();Jt=[],a.clear()}}}var je={};function Ye(){return je.reducedMotion!==void 0?je.reducedMotion:typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function Ue(){return je.hidden!==void 0?je.hidden:typeof document<"u"&&document.hidden}var Ma=["--field-density","--d"],Yr=!1;function Ur(){if(Yr)return[];Yr=!0;let n=globalThis.CSS;if(!n||typeof n.registerProperty!="function")return[];let t=[];for(let e of Ma)try{n.registerProperty({name:e,syntax:"<number>",inherits:!0,initialValue:"0"}),t.push(e)}catch{}return t}var Gr=["pointerdown","wheel","keydown","touchstart"];function he(){return Ur(),{root:document,viewport:()=>({width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio||1}),scrollY:()=>window.scrollY||0,scrollHeight:()=>document.documentElement.scrollHeight,reducedMotion:()=>Ye(),hidden:()=>Ue(),raf:n=>requestAnimationFrame(n),cancelRaf:n=>cancelAnimationFrame(n),createCanvas:()=>document.createElement("canvas"),onResize:n=>(window.addEventListener("resize",n,{passive:!0}),()=>window.removeEventListener("resize",n)),onScroll:n=>(window.addEventListener("scroll",n,{passive:!0}),()=>window.removeEventListener("scroll",n)),onVisibility:n=>(document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)),onInput:n=>{for(let t of Gr)window.addEventListener(t,n,{passive:!0});return()=>{for(let t of Gr)window.removeEventListener(t,n)}},onBodyEvent:(n,t)=>(document.addEventListener(n,t),()=>document.removeEventListener(n,t))}}var Vr=["pointerdown","wheel","keydown","touchstart"];function Xr(n){return{root:n,viewport:()=>{let t=n.getBoundingClientRect();return{width:t.width,height:t.height,dpr:window.devicePixelRatio||1,originX:t.left,originY:t.top}},scrollY:()=>n.scrollTop,scrollHeight:()=>n.scrollHeight,reducedMotion:()=>Ye(),hidden:()=>Ue(),raf:t=>requestAnimationFrame(t),cancelRaf:t=>cancelAnimationFrame(t),createCanvas:()=>document.createElement("canvas"),onResize:t=>{let e=new ResizeObserver(t);return e.observe(n),window.addEventListener("resize",t,{passive:!0}),()=>{e.disconnect(),window.removeEventListener("resize",t)}},onScroll:t=>(n.addEventListener("scroll",t,{passive:!0}),window.addEventListener("scroll",t,{passive:!0}),()=>{n.removeEventListener("scroll",t),window.removeEventListener("scroll",t)}),onVisibility:t=>(document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)),onInput:t=>{for(let e of Vr)n.addEventListener(e,t,{passive:!0});return()=>{for(let e of Vr)n.removeEventListener(e,t)}},onBodyEvent:(t,e)=>(n.addEventListener(t,e),()=>n.removeEventListener(t,e))}}function Jr(n,t={}){return He(n,{...t,host:he()})}function qn(n,t={}){let{host:e,bounds:r,...s}=t,i=e??(r?Xr(r):he());return He(n,{...s,host:i})}function Hn(){if(typeof document>"u"||typeof window>"u")throw new Error('Fundamental: the field runs in the browser only. Create it on the client (inside useEffect / onMount / a "client only" boundary), not during server-side rendering.')}function Ge(n=document.body){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText=Ir,n.appendChild(t),t}function Kr(n){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText="position:absolute;inset:0;width:100%;height:100%;pointer-events:none;",getComputedStyle(n).position==="static"&&(n.style.position="relative"),n.appendChild(t),t}function ka(n={}){Hn();let{target:t=document.body,...e}=n,r=Ge(t),s=Jr(r,e);return{...s,destroy:()=>{s.destroy(),r.remove()}}}var jn=class{constructor(t={}){V(this,"canvas");V(this,"field");V(this,"managed");Hn();let{canvas:e,target:r,bounds:s,...i}=t;this.managed=!e,this.canvas=e??(s?Kr(s):Ge(r)),this.field=qn(this.canvas,s?{...i,bounds:s}:i)}scan(){this.field.scan()}rescan(){this.field.rescan()}setAccent(t){this.field.setAccent(t)}setPalette(t){this.field.setPalette(t)}setFormation(t){this.field.setFormation(t)}setWaveStyle(t){this.field.setWaveStyle(t)}setWaveCenter(t){this.field.setWaveCenter(t)}setSeparation(t){this.field.setSeparation(t)}setAttention(t){this.field.setAttention(t)}setCausality(t){this.field.setCausality(t)}setHeatmap(t){this.field.setHeatmap(t)}setDprCap(t){this.field.setDprCap(t)}setQualityTier(t){this.field.setQualityTier(t)}setRender(t){this.field.setRender(t)}setOverlay(t){this.field.setOverlay(t)}threads(t){this.field.threads(t)}burst(t,e,r){this.field.burst(t,e,r)}flowTo(t,e,r){this.field.flowTo(t,e,r)}clearFlow(){this.field.clearFlow()}seed(t){this.field.seed(t)}addAgent(t){return this.field.addAgent(t)}addBody(t){return this.field.addBody(t)}addEdge(t,e,r){return this.field.addEdge(t,e,r)}readEdges(){return this.field.readEdges()}query(t){return this.field.query(t)}snapshot(t){return this.field.snapshot(t)}diff(t,e){return this.field.diff(t,e)}replay(t,e,r){return this.field.replay(t,e,r)}get projections(){return this.field.projections}addField(t,e){return this.field.addField(t,e)}sampleField(t,e,r){return this.field.sampleField(t,e,r)}atomAt(t,e){return this.field.atomAt(t,e)}focusAt(t,e){return this.field.focusAt(t,e)}clearFocus(){this.field.clearFocus()}particleCount(){return this.field.particleCount()}readParticles(t){return this.field.readParticles(t)}readParticleIds(t){return this.field.readParticleIds(t)}readParticleChannels(t,e){return this.field.readParticleChannels(t,e)}registerOverlay(t,e){return this.field.registerOverlay(t,e)}energy(){return this.field.energy()}sample(t,e){return this.field.sample(t,e)}sampleScalar(t,e){return this.field.sampleScalar(t,e)}sampleGradient(t,e){return this.field.sampleGradient(t,e)}grid(t){return this.field.grid(t)}on(t,e){return this.field.on(t,e)}get version(){return this.field.version}scrollV(){return this.field.scrollV()}setVisible(t){this.field.setVisible(t)}setBackground(t){this.field.setBackground(t)}destroy(){this.field.destroy(),this.managed&&this.canvas.remove()}};export{bo as CONDITIONS,ze as FIELD_VERSION,mn as FORCES,wo as FORMATIONS,jn as FieldField,pn as PALETTE,he as browserHost,qn as createField,Dr as cssFeedbackSink,pa as headlessHost,Ge as makeFieldCanvas,ka as mountField};
2
+ var vi=Object.defineProperty;var bi=(n,t,e)=>t in n?vi(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var U=(n,t,e)=>bi(n,typeof t!="symbol"?t+"":t,e);var De="0.9.3";var Tn=[{id:"attract",name:"Attract",color:"#4da3ff",does:"Pulls matter into a well",discipline:"Product strategy",verb:"gives direction",body:"attract",attrs:{"data-strength":"1","data-range":"300"},law:"a soft gravity-like well, bent into a spiral"},{id:"jet",name:"Jet",color:"#a78bfa",does:"Draws matter in, jets it out",discipline:"AI systems",verb:"adapts response",body:"jet",attrs:{"data-angle":"0","data-strength":"1","data-range":"300"},law:"recycles the field into a stream"},{id:"tether",name:"Tether",color:"#86e57f",does:"Tethers matter to a radius",discipline:"Software architecture",verb:"gives structure",body:"tether",attrs:{"data-strength":"1","data-range":"260"},law:"a rest length \u2014 a leash, not a drain"},{id:"wall",name:"Wall",color:"#c4b5fd",does:"A surface that bounces \u2014 throws sparks",discipline:"Experience design",verb:"the human surface",body:"wall",attrs:{},law:"elastic bounce off the bounding box"},{id:"stream",name:"Stream",color:"#7dd3fc",does:"Blows a directional current",discipline:"Motion",verb:"reveals motion",body:"stream",attrs:{"data-angle":"0","data-strength":"1","data-range":"340"},law:"constant force along a heading"},{id:"repel",name:"Repel",color:"#ff9d5c",does:"Pushes matter away",discipline:"Commerce",verb:"market pressure",body:"repel",attrs:{"data-strength":"1.1","data-range":"300"},law:"inverted well \u2014 carves a clean void"},{id:"viscosity",name:"Viscosity",color:"#8da2c0",does:"Thickens the medium",discipline:"Physical production",verb:"adds constraint",body:"viscosity",attrs:{"data-strength":"1","data-range":"300"},law:"viscosity \u2014 bleeds momentum off"},{id:"swirl",name:"Swirl",color:"#2dd4bf",does:"Spins matter into a swirl",discipline:"Creative technology",verb:"spins it together",body:"swirl",attrs:{"data-spin":"1","data-strength":"1","data-range":"320"},law:"tangential force \u2014 circles, never collapses"},{id:"sink",name:"Sink",color:"#ff6e9c",does:"Swallows matter, then pops",discipline:"Attention",verb:"holds, then releases",body:"sink attract",attrs:{"data-absorb":"64","data-max":"30","data-strength":"0.8","data-range":"360"},law:"accretion, then supernova"}],No=Object.fromEntries(Tn.map(n=>[n.id,n])),An=Tn.map(n=>n.color),ye=["#4da3ff","#2dd4bf","#a78bfa","#ff6e9c","#ff9d5c"],Fn=["spotlight","screen","resonate"],wi=["spawn"],Cn=300,On=120;function Mi(n){return Fn.includes(n)?"modifier":wi.includes(n)?"source":"force"}function Ne(n){let t=[],e=[],r=[];for(let s of n){let i=Mi(s);i==="modifier"?t.push(s):i==="source"?r.push(s):e.push(s)}return t.length>1&&t.sort((s,i)=>Fn.indexOf(s)-Fn.indexOf(i)),{modifiers:t,forces:e,sources:r}}var Bo=[{id:"ambient",name:"Ambient",section:"Hero",color:"#4da3ff",cue:"resting drift",preset:{driftX:0,wander:1,orbit:.1,spread:0,conv:0}},{id:"wells",name:"Wells",section:"Work",color:"#2dd4bf",cue:"matter pools",preset:{driftX:0,wander:.7,orbit:.85,spread:0,conv:0}},{id:"lanes",name:"Lanes",section:"Writing",color:"#ff9d5c",cue:"a current carries",preset:{driftX:.55,wander:.5,orbit:0,spread:0,conv:0}},{id:"scatter",name:"Scatter",section:"Practice",color:"#a78bfa",cue:"energy dispersed",preset:{driftX:0,wander:1.7,orbit:0,spread:.6,conv:0}},{id:"accretion",name:"Accretion",section:"Contact",color:"#ffce6b",cue:"everything gathers",preset:{driftX:0,wander:.6,orbit:.4,spread:0,conv:.6}}],pe=Object.fromEntries(Bo.map(n=>[n.id,n]));var Lo=[{id:"",name:"Always",desc:"Acts on every particle, every frame.",selective:!1},{id:"active",name:"Active",desc:"Only while the body is engaged.",selective:!1},{id:"fast",name:"Fast",desc:"Only on fast-moving matter (v\xB2 > 0.9).",selective:!0},{id:"slow",name:"Slow",desc:"Only on calm matter (v\xB2 < 0.22).",selective:!0},{id:"hot",name:"Hot",desc:"Only on energized matter (heat > 0.3).",selective:!0},{id:"cool",name:"Cool",desc:"Only on calm, un-energized matter (heat < 0.08).",selective:!0},{id:"scrolling",name:"Scrolling",desc:"Only while the page is scrolling.",selective:!1}],lc=Object.fromEntries(Lo.map(n=>[n.id,n]));var ki={ours:ye,heatmap:["#2b3a8c","#2d8fd4","#3fd07a","#ffe14d","#ff8a3d","#e23b3b"],infrared:["#2a0a4a","#8e24aa","#e53935","#ff8f00","#ffd54f","#fffde7"],spectrum:["#ff3b30","#ff9500","#ffcc00","#34c759","#00c7be","#007aff","#af52de"]};function Be(n){return Array.isArray(n)?n.length>0?n:ye:typeof n=="string"?ki[n]??ye:ye}var Rn={warm:{cool:[255,224,200],warm:[255,110,80],wave:["#ff8a5c","#f0628e","#ffc46b"]},cool:{cool:[206,226,255],warm:[74,132,255],wave:["#5c8aff","#62a0f0","#6bc4ff"]},mono:{cool:[232,232,238],warm:[148,148,158],wave:["#8a8a96","#b0b0bc","#9a9aa6"]}},Pn="warm";var pt=(n,t,e)=>n<t?t:n>e?e:n;function mt(n){let t=n.replace("#",""),e=t.length===3?t.replace(/./g,s=>s+s):t,r=Number.parseInt(e.slice(0,6),16);return Number.isNaN(r)?[77,163,255]:[r>>16&255,r>>8&255,r&255]}var Si=[255,224,200],Ei=[255,110,80];function $n(n,t,e,r,s=Si,i=Ei){let l=s[0]+(i[0]-s[0])*t,d=s[1]+(i[1]-s[1])*t,m=s[2]+(i[2]-s[2])*t;return l+=(r[0]-l)*e,d+=(r[1]-d)*e,m+=(r[2]-m)*e,n[0]=l,n[1]=d,n[2]=m,n}function In([n,t,e]){let r=s=>pt(Math.round(s),0,255).toString(16).padStart(2,"0");return`#${r(n)}${r(t)}${r(e)}`}function _o(n,t,e){let[r,s,i]=mt(n),[l,d,m]=mt(t),b=e<0?0:e>1?1:e;return In([r+(l-r)*b,s+(d-s)*b,i+(m-i)*b])}function Dn(n,t){if(n.length===0)return[77,163,255];if(n.length===1)return n[0];let e=pt(t,0,1)*(n.length-1),r=Math.min(n.length-2,Math.floor(e)),s=e-r,i=n[r],l=n[r+1];return[i[0]+(l[0]-i[0])*s,i[1]+(l[1]-i[1])*s,i[2]+(l[2]-i[2])*s]}function Wo(n,t,e,r=0){if(!(t>0))return 1;let s=Math.max(0,1-n/t),i=1-e*s*s,l=Math.min(Math.max(r,0),1);return i<l?l:i>1?1:i}var Le=1;function _e(n){let t=n.ux!==0?n.hw/Math.abs(n.ux):1/0,e=n.uy!==0?n.hh/Math.abs(n.uy):1/0,r=Math.min(t,e),s=n.ux*r,i=n.uy*r,l=n.spin<0?-1:1;return[{x:n.cx+s,y:n.cy+i,q:l},{x:n.cx-s,y:n.cy-i,q:-l}]}function qo(n,t,e){let r=0,s=0;for(let i of n){let l=t-i.x,d=e-i.y,m=Math.max(Le,Math.hypot(l,d)),b=i.q/(m*m);r+=l/m*b,s+=d/m*b}return{x:r,y:s}}function jo(n,t,e,r,s,i){let l=s-n,d=i-t,m=Math.max(Le,Math.hypot(l,d)),p=(e<0?-1:1)*r/(m*m);return{x:l/m*p,y:d/m*p}}function Ho(n,t){let e=n/20+(t?.45:0);return e<0?0:e>1?1:e}function Yo(n,t,e){return Math.round(n+(t-n)*e)}function Uo(n,t={}){let e=t.beta??2,r=t.lo??.25,s=t.hi??3,i=n.length,l=new Array(i).fill(1);if(i===0)return l;let d=0,m=0;for(let p of n){let M=p.strength>0?p.strength:0;d+=M,m+=M*(1+(p.on?e:0))}if(d<=0||m<=0)return l;let b=d/m;for(let p=0;p<i;p++){let z=(1+(n[p].on?e:0))*b;z<r?z=r:z>s&&(z=s),l[p]=z}return l}function Go(n,t={}){let e=t.threshold??.55,r=t.kappa??.6,s=t.falloff??320,i=n.length,l=new Array(i).fill(0);if(i<2)return l;let d=new Array(i).fill(0);for(let m=0;m<i;m++){let b=n[m],p=b.d-e;if(p<=0)continue;let M=0;for(let E=0;E<i;E++){if(E===m){d[E]=0;continue}let A=n[E],P=Math.hypot(b.cx-A.cx,b.cy-A.cy),B=P<s?1-P/s:0;d[E]=B,M+=B}if(M<=0)continue;let z=r*p;for(let E=0;E<i;E++){let A=d[E];if(A<=0)continue;let P=z*A/M;l[E]+=P,l[m]-=P}}return l}var Vo=n=>`${n.from}\0${n.to}\0${n.type}`;function Nn(n,t){let e=[],r=new Map(n.bodies.map(E=>[E.id,E])),s=new Map(t.bodies.map(E=>[E.id,E]));for(let[E,A]of r){let P=s.get(E);if(!P){e.push({id:E,kind:"removed"});continue}let B={},I=!1,G=new Set([...Object.keys(A.metrics),...Object.keys(P.metrics)]);for(let J of G){let h=A.metrics[J]??0,X=P.metrics[J]??0;h!==X&&(B[J]={from:h,to:X},I=!0)}I&&e.push({id:E,kind:"changed",metrics:B})}for(let E of s.keys())r.has(E)||e.push({id:E,kind:"added"});let i=[],l=new Map(n.relationships.map(E=>[Vo(E),E])),d=new Map(t.relationships.map(E=>[Vo(E),E]));for(let[E,A]of l){let P=d.get(E);if(!P){i.push({from:A.from,to:A.to,type:A.type,kind:"removed"});continue}let B={from:A.from,to:A.to,type:A.type,kind:"changed"},I=!1;A.strength!==P.strength&&(B.strength={from:A.strength,to:P.strength},I=!0),A.active!==P.active&&(B.active={from:A.active,to:P.active},I=!0),I&&i.push(B)}for(let[E,A]of d)l.has(E)||i.push({from:A.from,to:A.to,type:A.type,kind:"added"});let m=[],b=new Set([...Object.keys(n.metrics),...Object.keys(t.metrics)]);for(let E of b){let A=n.metrics[E]??0,P=t.metrics[E]??0;A!==P&&m.push({key:E,from:A,to:P})}let p=[],M=new Set(n.formations),z=new Set(t.formations);for(let E of z)M.has(E)||p.push({id:E,kind:"activated"});for(let E of M)z.has(E)||p.push({id:E,kind:"deactivated"});return{from:n.id,to:t.id,bodyChanges:e,relationshipChanges:i,metricChanges:m,formationChanges:p}}function Xo(n,t,e={}){let r=p=>Math.round(p*1e3)/1e3,s=Nn(n,t),i=t.frame,l=t.createdAt,d=[],m=(p,M,z={})=>{d.push({frame:i,time:l,cause:p,description:M,...z})};for(let p of s.formationChanges)m("formation",`Formation '${p.id}' ${p.kind}`,{source:p.id});for(let p of s.relationshipChanges){let M;if(p.kind==="added")M="formed";else if(p.kind==="removed")M="dissolved";else{let z=[];if(p.active&&z.push(p.active.to?"became active":"went idle"),p.strength){let E=p.strength.to>=p.strength.from?"strengthened":"weakened";z.push(`${E} ${r(p.strength.from)}\u2192${r(p.strength.to)}`)}M=z.join(", ")||"changed"}m("relationship",`Relationship ${p.from}\u2192${p.to} (${p.type}) ${M}`,{source:p.from,target:p.to,contribution:p.strength})}for(let p of s.bodyChanges)if(p.kind==="added")m("measurement",`Body ${p.id} entered the field`,{source:p.id});else if(p.kind==="removed")m("measurement",`Body ${p.id} left the field`,{source:p.id});else if(p.metrics)for(let[M,z]of Object.entries(p.metrics)){let E=z.to>z.from?"rose":"fell";m("metric",`Body ${p.id} ${M} ${E} ${r(z.from)}\u2192${r(z.to)}`,{source:p.id,contribution:z})}if(n.influences&&t.influences){let p=A=>typeof A=="number"?Math.abs(A):Math.hypot(A.x,A.y,A.z??0),M=A=>`${A.source} ${A.force} ${A.channel??"linear"}`,z=new Map(n.influences.map(A=>[M(A),A])),E=new Map(t.influences.map(A=>[M(A),A]));for(let A of new Set([...z.keys(),...E.keys()])){let P=z.get(A),B=E.get(A),I=P?p(P.contribution):0,G=B?p(B.contribution):0;if(Math.abs(G-I)<1e-9)continue;let J=B??P,h=G>I?I===0?"engaged":"grew":G===0?"released":"weakened",X=(J.channel??"linear")==="thermal"?" (thermal)":"";m("force",`Force ${J.force} on ${J.source}${X} ${h} ${r(I)}\u2192${r(G)}`,{source:J.source,contribution:{from:I,to:G}})}}let b=e.focus?d.filter(p=>p.source===e.focus||p.target===e.focus):d;return{from:n.id,to:t.id,focus:e.focus,steps:b}}var We=class{constructor(t=64){U(this,"cell");U(this,"bins",new Map);U(this,"freeBins",[]);this.cell=t>0?t:64}key(t,e){return(t+32768)*65536+(e+32768)}clear(){for(let t of this.bins.values())t.length=0,this.freeBins.push(t);this.bins.clear()}insert(t){let e=this.key(Math.floor(t.x/this.cell),Math.floor(t.y/this.cell)),r=this.bins.get(e);if(r)r.push(t);else{let s=this.freeBins.pop();s?(s.push(t),this.bins.set(e,s)):this.bins.set(e,[t])}}rebuild(t){this.clear();for(let e of t)this.insert(e)}near(t,e,r,s=0){let i=[],l=r*r,d=Math.floor((t-r)/this.cell),m=Math.floor((t+r)/this.cell),b=Math.floor((e-r)/this.cell),p=Math.floor((e+r)/this.cell);for(let M=d;M<=m;M++)for(let z=b;z<=p;z++){let E=this.bins.get(this.key(M,z));if(E)for(let A of E){let P=A.x-t,B=A.y-e,I=(A.z??0)-s;P*P+B*B+I*I<=l&&i.push(A)}}return i}};var qe=class{constructor(t=64){U(this,"particles",[]);U(this,"hash");this.hash=new We(t)}get size(){return this.particles.length}add(t){return this.particles.push(t),t}remove(t){let e=this.particles.indexOf(t);if(e<0)return;let r=this.particles.pop();r&&e<this.particles.length&&(this.particles[e]=r)}clear(){this.particles.length=0,this.hash.clear()}reindex(){this.hash.rebuild(this.particles)}neighbors(t,e){let r=this.hash.near(t.x,t.y,e,t.z??0),s=[];for(let i of r)i!==t&&s.push(i);return s}near(t,e,r){return this.hash.near(t,e,r)}};function Ko(n,t,e=.03){n.driftX+=(t.driftX-n.driftX)*e,n.wander+=(t.wander-n.wander)*e,n.orbit+=(t.orbit-n.orbit)*e,n.spread+=(t.spread-n.spread)*e,n.conv+=(t.conv-n.conv)*e}function Jo(n){for(let t of n)if(t.vis&&t.tokens.indexOf("sink")>=0)return t;return null}var zi=[.24,.4,.55,.7,.85];function Qo(n){let t=[];for(let e=0;e<5;e++)t.push({baseFrac:zi[e]??.5,amp:22+e*15,freq:.0012+e*8e-4,phase:e*1.7%6.28,speed:13e-5+e*9e-5,color:n[e%n.length]??[77,163,255],depth:e/4,dir:e%2?-1:1,offsetY:0});return t}function Zo(n,t,e){let r=Math.round(16*t),s=[];for(let i=0;i<n;i++)for(let l=0;l<r;l++)s.push({wi:i,progress:e(),phase:(e()-.5)*.22*Math.PI,size:.7+e()*1.5,glow:e()<.3,speed:(35e-5+e()*9e-4)*(e()<.5?1:-1)});return s}function Et(n,t,e,r,s=1,i=1,l){let d=n.baseFrac*r+n.offsetY+Math.sin(t*n.freq+n.phase+e*n.speed*1e3*s)*n.amp*i;if(l&&l.k>.001){let m=t-l.x,b=260,p=Math.exp(-(m*m)/(2*b*b));d+=(l.y-d)*.42*p*l.k*(.45+n.depth*.55)}return d}function tr(n,t,e,r=1,s=1){return Math.cos(t*n.freq+n.phase+e*n.speed*1e3*r)*n.amp*n.freq*s}function me(n,t,e,r,s=1,i=1){let l=n.baseFrac*r+n.offsetY,d=Math.max(1,Math.round(n.freq*2500));return l+Math.sin(d*t+n.phase+e*n.speed*1e3*s)*n.amp*i}function er(n,t,e,r,s,i,l,d,m=1,b=1,p){if(l==="circular"){let M=t-d.x,z=e-d.y,E=Math.sqrt(M*M+z*z)||.001,A=Math.atan2(z,M),P=Math.min(s,i)*.48,B=me(n,A,r,P,m,b);return{dist:Math.abs(E-B),rWave:B,r:E,theta:A}}else{let M=Et(n,t,r,i,m,b,p);return{dist:Math.abs(e-M),rWave:M,r:e,theta:0}}}var Ut={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null};function Gt(n,t,e,r,s){Ut.x=r,Ut.y=s,Ut.vx=0,Ut.vy=0,Ut.heat=0;let i=0,l=0;for(let d of n){if(!d.vis||d.tokens.length===0)continue;let m,b;if(d.shaped){let z=d.cx-d.hw,E=d.cx+d.hw,A=d.cy-d.hh,P=d.cy+d.hh;m=(r<z?z:r>E?E:r)-r,b=(s<A?A:s>P?P:s)-s}else m=d.cx-r,b=d.cy-s;let p=m*m+b*b;if(d.range>0&&p>=d.range*d.range*2.56)continue;let M=Math.sqrt(p);e.dx=m,e.dy=b,e.dist=M<1?1:M;for(let z of d.tokens){let E=t[z];if(!(!E||E.modify))if(E.field){let A=E.field(d,r,s);i+=A.x,l+=A.y}else E.apply(d,Ut,e)}}return{fx:Ut.vx+i,fy:Ut.vy+l}}function je(n,t,e,r){let s=0,i=0;for(let l of n)if(!(!l.vis||l.tokens.length===0)){if(l.range>0){let d=l.cx-e,m=l.cy-r;if(d*d+m*m>=l.range*l.range*2.56)continue}for(let d of l.tokens){let m=t[d];if(m?.field){let b=m.field(l,e,r);s+=b.x,i+=b.y}}}return{x:s,y:i}}var nr=.95,or=.972,Tt=10;function Fi(n,t,e,r){if(!t.when)return!0;let s=n[t.when];return s?s(t,e,r):!0}function rr(n){return n.classified??(n.classified=Ne(n.tokens))}function Ln(n,t,e,r,s=1){let i=e.vx,l=e.vy,d=e.vz??0,m=e.heat,b=e.spin??0,p=e.age;n.apply(t,e,r),s===1||n.kinematic||(e.vx=i+(e.vx-i)*s,e.vy=l+(e.vy-l)*s,e.vz!==void 0&&(e.vz=d+(e.vz-d)*s)),n.kinematic&&r.integrator==="velocity-verlet"&&(e.vx!==i||e.vy!==l||(e.vz??0)!==d)&&(r.kinTouch=!0);let M=r.accum;if(M!==void 0){let z=e.vx-i,E=e.vy-l,A=(e.vz??0)-d;(z!==0||E!==0||A!==0)&&(M.linear.x+=z,M.linear.y+=E,M.linear.z+=A,M.attribution.push({force:n.token,channel:"linear",contribution:{x:z,y:E,z:A}}));let P=e.heat-m;P!==0&&(M.thermal=(M.thermal??0)+P,M.attribution.push({force:n.token,channel:"thermal",contribution:P}));let B=(e.spin??0)-b;if(B!==0){let I=M.angular??(M.angular={x:0,y:0,z:0});I.z+=B,M.attribution.push({force:n.token,channel:"angular",contribution:B})}if(p!==void 0&&e.age!==void 0){let I=e.age-p;if(I!==0){let G=M.temporal??(M.temporal={});G.decay=(G.decay??0)+I,M.attribution.push({force:n.token,channel:"temporal",contribution:I})}}t.attn!==void 0&&t.attn!==1&&((M.semantic??(M.semantic={})).attention=t.attn,M.attribution.push({force:n.token,channel:"semantic",contribution:t.attn}))}}function Bn(n,t,e,r,s){if(r.accum===void 0){if(s===1||n.kinematic){if(n.kinematic&&r.integrator==="velocity-verlet"){let m=e.vx,b=e.vy,p=e.vz??0;n.apply(t,e,r),(e.vx!==m||e.vy!==b||(e.vz??0)!==p)&&(r.kinTouch=!0);return}n.apply(t,e,r);return}let i=e.vx,l=e.vy,d=e.vz??0;n.apply(t,e,r),e.vx=i+(e.vx-i)*s,e.vy=l+(e.vy-l)*s,e.vz!==void 0&&(e.vz=d+(e.vz-d)*s);return}Ln(n,t,e,r,s)}function ir(){return{linear:{x:0,y:0,z:0},attribution:[]}}function sr(n){for(let t of n){t.count=0;let e=t.thermo;e&&(e.n=0,e.sx=0,e.sy=0,e.ss=0,e.ss2=0,e.sh=0)}}function ar(n){let{store:t,bodies:e,env:r,forces:s,conditions:i,waves:l,separation:d}=n,m=r.dt;if(m===0){sr(e);return}let b=r.integrator==="velocity-verlet",{W:p,H:M,form:z}=r;r.fieldAt=(h,X)=>je(e,s,h,X),sr(e);let E=null;for(let h of e)h.vis&&h.tokens.length>0&&rr(h).modifiers.indexOf("screen")>=0&&(E??(E=[])).push(h);let A=E?new Array(E.length):null,P=!!l&&l.length>0,B=e.length>0,I=null,G=z.conv>.02?Jo(e):null,J=r.D??0;for(let h of t.particles){if(h.cap){h.x+=(h.cap.cx-h.x)*.18,h.y+=(h.cap.cy-h.y)*.18,h.z&&(h.z+=-h.z*.18),h.ax!==void 0&&(h.ax=h.ay=h.az=0);continue}h.z===void 0&&(h.z=0),h.vz===void 0&&(h.vz=0);let X=0,bt=0,tt=0;if(b){let q=.5*m*m;h.x+=h.vx*m+(h.ax??0)*q,h.y+=h.vy*m+(h.ay??0)*q,h.z+=h.vz*m+(h.az??0)*q,X=h.vx,bt=h.vy,tt=h.vz,r.kinTouch=!1}let we=h.z;if(P)if(n.waveStyle==="circular"){let q=null,T=1e9,H=0,et=0,nt=0,wt=n.waveCenter||{x:p/2,y:M/2};for(let ut of l){let zt=er(ut,h.x,h.y,r.t,p,M,"circular",wt);zt.dist<T&&(T=zt.dist,q=ut,H=zt.r,et=zt.rWave,nt=zt.theta)}if(q&&T<70){let ut=1-T/70,zt=-Math.sin(nt)*q.dir,Xt=Math.cos(nt)*q.dir;h.vx+=zt*.035*ut,h.vy+=Xt*.035*ut;let It=Math.cos(nt)*Math.sign(et-H),C=Math.sin(nt)*Math.sign(et-H);h.vx+=It*.05*ut,h.vy+=C*.05*ut}}else{let q=null,T=1e9;for(let H of l){let et=Math.abs(Et(H,h.x,r.t,M)-h.y);et<T&&(T=et,q=H)}q&&T<70&&(h.vx+=q.dir*.035*(1-T/70),h.vy+=tr(q,h.x,r.t)*.1*(1-T/70))}if(z.driftX&&(h.vx+=z.driftX*.02),z.spread>.02){let q=h.gx??.5,T=h.gy??.5,H=(q+r.frameN*4e-5)%1*p,et=T*M;h.vx+=(H-h.x)*6e-4*z.spread,h.vy+=(et-h.y)*6e-4*z.spread,J>0&&(h.vz+=((h.gz??.5)*J-we)*6e-4*z.spread)}if(G){let q=G.cx-h.x,T=G.cy-h.y,H=-we,et=Math.hypot(q,T,H)||1;h.vx+=q/et*z.conv*.06,h.vy+=T/et*z.conv*.06,h.vz+=H/et*z.conv*.06}if(B){if(E)for(let T=0;T<E.length;T++){let H=E[T],et=H.cx-h.x,nt=H.cy-h.y;A[T]=Wo(Math.sqrt(et*et+nt*nt),H.range,H.strength,H.screenMin??0)}let q=h.m!==1&&h.m>0?1/h.m:1;for(let T of e){if(!T.vis||T.tokens.length===0||T.affects!==void 0&&!T.affects.has(h.species??0))continue;let H,et;if(T.shaped){let R=T.cx-T.hw,Z=T.cx+T.hw,ot=T.cy-T.hh,Qt=T.cy+T.hh,de=h.x<R?R:h.x>Z?Z:h.x,fe=h.y<ot?ot:h.y>Qt?Qt:h.y;H=de-h.x,et=fe-h.y}else H=T.cx-h.x,et=T.cy-h.y;let nt=-h.z,wt=H*H+et*et+nt*nt;if(T.range>0&&wt>=T.range*T.range*2.56)continue;let ut=Math.sqrt(wt);if(T.feedback&&ut<T.range*.5){T.count+=1-ut/(T.range*.5);let R=T.thermo??(T.thermo={n:0,sx:0,sy:0,ss:0,ss2:0,sh:0}),Z=h.vx*h.vx+h.vy*h.vy;R.n++,R.sx+=h.vx,R.sy+=h.vy,R.ss+=Math.sqrt(Z),R.ss2+=Z,R.sh+=h.heat}if(T.when&&!Fi(i,T,h,r))continue;r.dx=H,r.dy=et,r.dz=nt,r.dist=ut<1?1:ut;let zt=rr(T),Xt=1,It=!1,C=!1;for(let R of zt.modifiers){let Z=s[R]?.modify;if(!Z)continue;C=!0;let ot=Z(T,h,r);ot.strength!=null&&(Xt*=ot.strength),ot.gate&&(It=!0)}for(let R of zt.forces){let Z=s[R]?.modify;if(!Z)continue;C=!0;let ot=Z(T,h,r);ot.strength!=null&&(Xt*=ot.strength),ot.gate&&(It=!0)}if(It)continue;let ct=1;if(E)for(let R=0;R<E.length;R++)E[R]!==T&&(ct*=A[R]);let _=T.attn??1,L=Xt*_*ct;if(!C&&L===1)for(let R of T.tokens){let Z=s[R];Z&&Bn(Z,T,h,r,q)}else if(C){let R=T.strength;T.strength=R*L;for(let Z of T.tokens){let ot=s[Z];ot&&!ot.modify&&Bn(ot,T,h,r,q)}T.strength=R}else{let R=T.strength;T.strength=R*L;for(let Z of T.tokens){let ot=s[Z];ot&&Bn(ot,T,h,r,q)}T.strength=R}}}if(d&&d>0){let q=r.neighbors(h,12);for(let T of q){let H=h.x-T.x,et=h.y-T.y,nt=(h.z??0)-(T.z??0),wt=Math.hypot(H,et,nt)||.1;if(wt<12){let ut=(12-wt)/12*d*.12;h.vx+=H/wt*ut,h.vy+=et/wt*ut,h.vz!==void 0&&(h.vz+=nt/wt*ut)}}}if(b){let q=h.vx-X,T=h.vy-bt,H=h.vz-tt;r.kinTouch?h.ax=h.ay=h.az=0:(h.vx=X+.5*((h.ax??0)*m+q),h.vy=bt+.5*((h.ay??0)*m+T),h.vz=tt+.5*((h.az??0)*m+H),h.ax=q/m,h.ay=T/m,h.az=H/m)}let Vt=r.c,Me=h.vx*h.vx+h.vy*h.vy+h.vz*h.vz;if(Me>Vt*Vt){let q=Vt/Math.sqrt(Me);h.vx*=q,h.vy*=q,h.vz*=q}if(h.maxSpeed!==void 0){let q=h.maxSpeed*h.maxSpeed,T=h.vx*h.vx+h.vy*h.vy+h.vz*h.vz;if(T>q){let H=h.maxSpeed/Math.sqrt(T);h.vx*=H,h.vy*=H,h.vz*=H}}b||(h.x+=h.vx*m,h.y+=h.vy*m,h.z+=h.vz*m);let $t=r.integrator==="fixed"||b?Math.pow(nr,m):nr;if(h.vx*=$t,h.vy*=$t,h.vz*=$t,h.spin!==void 0&&(h.orient=(h.orient??0)+h.spin*m,h.spin*=$t),h.report===void 0){if(r.frameN%40===0&&z.wander>0){let q=.05*z.wander;h.vx+=((r.rng??Math.random)()-.5)*q,h.vy+=((r.rng??Math.random)()-.5)*q,J>0&&(h.vz+=((r.rng??Math.random)()-.5)*q)}if(z.wander>.05){let q=(Math.sin(h.x*.0032+r.t*.12)+Math.cos(h.y*.0034-r.t*.15))*Math.PI;h.vx+=Math.cos(q)*.013*z.wander,h.vy+=Math.sin(q)*.013*z.wander}}h.heat*=r.integrator==="fixed"||b?Math.pow(or,m):or,h.age!=null&&(h.age-=m,h.age<=0&&(I??(I=[])).push(h)),h.report===void 0?(h.x<-Tt?h.x=p+Tt:h.x>p+Tt&&(h.x=-Tt),h.y<-Tt?h.y=M+Tt:h.y>M+Tt&&(h.y=-Tt),J>0&&(h.z<-Tt?h.z=J+Tt:h.z>J+Tt&&(h.z=-Tt))):(h.x<0?(h.x=0,h.vx=Math.abs(h.vx)):h.x>p&&(h.x=p,h.vx=-Math.abs(h.vx)),h.y<0?(h.y=0,h.vy=Math.abs(h.vy)):h.y>M&&(h.y=M,h.vy=-Math.abs(h.vy)),J>0&&(h.z<0?(h.z=0,h.vz=Math.abs(h.vz)):h.z>J&&(h.z=J,h.vz=-Math.abs(h.vz))),h.report(h))}if(B){for(let h of e)if(!(!h.vis||h.tokens.length===0))for(let X of h.tokens)s[X]?.source?.(h,r)}if(I)for(let h of I)t.remove(h)}var le=class{constructor(t,e,r="diffuse",s=32){U(this,"mode");U(this,"cell");U(this,"W");U(this,"H");U(this,"cols");U(this,"rows");U(this,"cur");U(this,"nxt");U(this,"prev");this.W=t,this.H=e,this.mode=r,this.cell=s,this.cols=Math.max(2,Math.ceil(t/s)+1),this.rows=Math.max(2,Math.ceil(e/s)+1);let i=this.cols*this.rows;this.cur=new Float32Array(i),this.nxt=new Float32Array(i),this.prev=new Float32Array(i)}clampCol(t){return t<0?0:t>=this.cols?this.cols-1:t}clampRow(t){return t<0?0:t>=this.rows?this.rows-1:t}at(t,e){return this.cur[this.clampRow(e)*this.cols+this.clampCol(t)]}sample(t,e){let r=t/this.cell,s=e/this.cell,i=Math.floor(r),l=Math.floor(s),d=r-i,m=s-l,b=this.at(i,l)*(1-d)+this.at(i+1,l)*d,p=this.at(i,l+1)*(1-d)+this.at(i+1,l+1)*d;return b*(1-m)+p*m}deposit(t,e,r){let s=this.clampCol(Math.round(t/this.cell)),i=this.clampRow(Math.round(e/this.cell));this.cur[i*this.cols+s]+=r}max(){let t=0;for(let e=0;e<this.cur.length;e++)this.cur[e]>t&&(t=this.cur[e]);return t}gradient(t,e){let r=this.cell;return{x:(this.sample(t+r,e)-this.sample(t-r,e))/(2*r),y:(this.sample(t,e+r)-this.sample(t,e-r))/(2*r)}}step(){this.mode==="wave"?this.stepWave():this.mode==="memory"?this.stepDiffuse(.03,.004):this.stepDiffuse()}stepDiffuse(t=.18,e=.01){let r=t<0?0:t>.24?.24:t,s=1-e,{cols:i,rows:l,cur:d,nxt:m}=this;for(let b=0;b<l;b++)for(let p=0;p<i;p++){let M=b*i+p,z=this.at(p-1,b)+this.at(p+1,b)+this.at(p,b-1)+this.at(p,b+1)-4*d[M];m[M]=(d[M]+r*z)*s}this.cur=m,this.nxt=d}stepWave(t=.25,e=.002){let r=t<0?0:t>.5?.5:t,s=1-e,{cols:i,rows:l,cur:d,prev:m,nxt:b}=this;for(let p=0;p<l;p++)for(let M=0;M<i;M++){let z=p*i+M,E=this.at(M-1,p)+this.at(M+1,p)+this.at(M,p-1)+this.at(M,p+1)-4*d[z];b[z]=(2*d[z]-m[z]+r*E)*s}this.prev=d,this.cur=b,this.nxt=m}decay(t){let e=t<=0?1:t>=1?0:1-t;if(e!==1)for(let r=0;r<this.cur.length;r++)this.cur[r]*=e}clear(){this.cur.fill(0),this.nxt.fill(0),this.prev.fill(0)}resize(t,e){if(t===this.W&&e===this.H)return;this.W=t,this.H=e,this.cols=Math.max(2,Math.ceil(t/this.cell)+1),this.rows=Math.max(2,Math.ceil(e/this.cell)+1);let r=this.cols*this.rows;this.cur=new Float32Array(r),this.nxt=new Float32Array(r),this.prev=new Float32Array(r)}};var cr={active:n=>n.on,fast:(n,t)=>t.vx*t.vx+t.vy*t.vy+(t.vz??0)*(t.vz??0)>.9,slow:(n,t)=>t.vx*t.vx+t.vy*t.vy+(t.vz??0)*(t.vz??0)<.22,hot:(n,t)=>t.heat>.3,cool:(n,t)=>t.heat<.08,scrolling:(n,t,e)=>(e?.scrollV??0)>.25};function lr(){let n={},t={...cr};return{forces:n,conditions:t,force(e){n[e.token]=e},condition(e,r){t[e]=r}}}var Ti={token:"attract",label:"Attract",apply(n,t,e){let r=n.range*(n.on?1.5:1),s=n.strength*(n.on?3:1);if(e.dist>=r)return;let i=(1-e.dist/r)**2*s*.5,l=e.dx/e.dist,d=e.dy/e.dist;t.vx+=l*i,t.vy+=d*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i),e.form.orbit&&(t.vx+=-d*i*e.form.orbit,t.vy+=l*i*e.form.orbit),n.on&&(t.heat=Math.max(t.heat,(1-e.dist/r)*.9))},meta:{desc:"a soft gravity-like well, bent into a spiral"}},Ai={token:"repel",label:"Repel",apply(n,t,e){let r=n.range*(n.on?1.4:1),s=n.strength*(n.on?2:1);if(e.dist>=r)return;let i=(1-e.dist/r)**2*s*.5;t.vx-=e.dx/e.dist*i,t.vy-=e.dy/e.dist*i,e.dz&&(t.vz=(t.vz??0)-e.dz/e.dist*i)},meta:{desc:"inverse-square outward push"}},Ci={token:"swirl",label:"Swirl",apply(n,t,e){let r=n.range*(n.on?1.4:1),s=n.strength*(n.on?2:1);if(e.dist>=r)return;let i=(1-e.dist/r)**1.4*s*.45,l=n.spin,d=e.dx/e.dist,m=e.dy/e.dist;t.vx+=m*i*l+d*i*.12,t.vy+=-d*i*l+m*i*.12,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i*.12),n.on&&(t.heat=Math.max(t.heat,(1-e.dist/r)*.6))},meta:{desc:"tangential swirl with light inward retention"}},Oi={token:"stream",label:"Stream",apply(n,t,e){let r=n.range*(n.on?1.4:1),s=n.strength*(n.on?2:1);if(e.dist>=r)return;let i=(1-e.dist/r)**1.1*s*.5;t.vx+=n.ux*i,t.vy+=n.uy*i,n.on&&(t.heat=Math.max(t.heat,(1-e.dist/r)*.5))},meta:{desc:"directional current along a heading"}},Ri={token:"viscosity",label:"Viscosity",apply(n,t,e){let r=n.range*(n.on?1.4:1);if(e.dist>=r)return;let s=(1-e.dist/r)*(.05+n.strength*.07)*(n.on?1.6:1);t.vx-=t.vx*s,t.vy-=t.vy*s,t.vz&&(t.vz-=t.vz*s)},meta:{desc:"thickens the medium \u2014 bleeds momentum"}},Pi={token:"jet",label:"Jet",kinematic:!0,apply(n,t,e){let r=n.range*(n.on?1.4:1);if(!(e.dist>=r))if(e.dist<24){let s=((e.rng??Math.random)()-.5)*.8,i=Math.cos(s),l=Math.sin(s),d=n.ux*i-n.uy*l,m=n.ux*l+n.uy*i,b=2.4+n.strength*2.6;t.vx=d*b,t.vy=m*b,t.x=n.cx+d*26,t.y=n.cy+m*26,t.z&&(t.z=0),t.vz&&(t.vz=0),t.heat=Math.max(t.heat,.9)}else{let s=(1-e.dist/r)**2*(.25+n.strength*.15);t.vx+=e.dx/e.dist*s,t.vy+=e.dy/e.dist*s,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*s)}},meta:{desc:"a fountain \u2014 draws matter in, jets it out along a heading"}},$i={token:"tether",label:"Tether",apply(n,t,e){let r=n.range*.6*(n.on?1.25:1),s=r*2.1;if(e.dist>=s)return;let i=(.006+n.strength*.012)*(n.on?1.7:1),l=e.dist-r,d=e.dx/e.dist,m=e.dy/e.dist;t.vx+=d*l*i,t.vy+=m*l*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*l*i),t.vx*=.985,t.vy*=.985,t.vz&&(t.vz*=.985),n.on&&(t.heat=Math.max(t.heat,(1-Math.min(1,Math.abs(l)/r))*.5))},meta:{desc:"a tether with a rest length \u2014 holds matter at a fixed radius"}},Ii={token:"wall",label:"Wall",kinematic:!0,apply(n,t,e){let s=Math.abs(t.x-n.cx),i=Math.abs(t.y-n.cy);if(s>=n.hw+6||i>=n.hh+6)return;let l=Math.hypot(t.vx,t.vy),d=n.hw+6-s,m=n.hh+6-i;d<m?(t.x=t.x<n.cx?n.cx-n.hw-6:n.cx+n.hw+6,t.vx=-t.vx*.85):(t.y=t.y<n.cy?n.cy-n.hh-6:n.cy+n.hh+6,t.vy=-t.vy*.85),l>.7&&(e.spark(t.x,t.y,Math.min(2.4,l),n.tint??No.wall.color),t.heat=Math.max(t.heat,Math.min(.85,l*.4)))},meta:{desc:"axis-aligned bouncing wall \u2014 sparks on impact"}},Di={token:"sink",label:"Sink",apply(n,t,e){t.cap||e.dist>=n.absorbR||(t.cap=n,n.accreted+=1,n.accreted>=n.capacity&&e.supernova(n))},meta:{desc:"captures matter, then releases it"}},Ni=[Ti,Pi,$i,Ii,Oi,Ai,Ri,Ci,Di];function dr(n){for(let t of Ni)n.force(t)}var Wn=1.5,Bi=8,Li=60;function _i(n,t,e,r){let s=_e(n);if(Math.hypot(s[0].x-s[1].x,s[0].y-s[1].y)<Math.max(n.range*.06,Bi)){let m=Math.max(n.range*.18,Li),b=n.spin<0?-1:1;s=[{x:n.cx+n.ux*m,y:n.cy+n.uy*m,q:b},{x:n.cx-n.ux*m,y:n.cy-n.uy*m,q:-b}]}let l=r*(1+Wn*(n.d??0)),d=qo(s,t,e);return{x:d.x*l,y:d.y*l}}function Wi(n,t,e,r){return jo(n.cx,n.cy,n.spin,r*(1+Wn*(n.d??0)),t,e)}function fr(n,t,e,r){if(e.dist>=n.range)return;let s=2*e.G*n.M/(e.c*e.c),i=r/(e.dist*e.dist+s*s);t.vx+=e.dx/e.dist*i,t.vy+=e.dy/e.dist*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i),qn(t,e.c)}function qn(n,t){let e=n.vz??0,r=Math.hypot(n.vx,n.vy,e);r>t&&(n.vx=n.vx/r*t,n.vy=n.vy/r*t,e&&(n.vz=e/r*t))}function qi(n,t,e){let r=n.cx-t,s=n.cy-e,i=Math.max(Math.hypot(r,s),Le),l=n.M*(1+Wn*(n.d??0))/(i*i);return{x:r/i*l,y:s/i*l}}var ji={token:"gravity",label:"Gravity",apply(n,t,e){fr(n,t,e,e.G*n.M)},field:(n,t,e)=>qi(n,t,e),meta:{desc:"true softened inverse-square gravity (a real 1/d\xB2 law)"}},Hi={token:"charge",label:"Charge",apply(n,t,e){let r=t.charge??0;r!==0&&fr(n,t,e,-(n.spin*r*e.G*n.M))},field:(n,t,e)=>Wi(n,t,e,n.M),meta:{desc:"signed inverse-square \u2014 like repels, opposite attracts"}},Yi={token:"magnetism",label:"Magnetism",apply(n,t,e){if(e.dist>=n.range)return;let r=t.charge??0;if(r===0)return;let s=1-e.dist/n.range,i=r*n.spin*n.strength*s,l=Math.cos(i),d=Math.sin(i),m=t.vx;t.vx=m*l-t.vy*d,t.vy=m*d+t.vy*l},field:(n,t,e)=>_i(n,t,e,n.strength),meta:{desc:"Lorentz force \u2014 curves a moving charge perpendicular to its velocity"}};function Ui(n){return Math.sqrt(2*Math.max(0,n))}var Gi={token:"thermal",label:"Thermal",apply(n,t,e){if(e.dist>=n.range)return;let r=1-e.dist/n.range,s=Ui(n.strength*r);if(s===0)return;let i=(e.rng??Math.random)()||1e-9,l=s*Math.sqrt(-2*Math.log(i)),d=2*Math.PI*(e.rng??Math.random)();if(t.vx+=l*Math.cos(d),t.vy+=l*Math.sin(d),e.D){let m=(e.rng??Math.random)()||1e-9;t.vz=(t.vz??0)+s*Math.sqrt(-2*Math.log(m))*Math.cos(2*Math.PI*(e.rng??Math.random)())}n.on&&(t.heat=Math.max(t.heat,r*.4)),qn(t,e.c)},meta:{desc:"Langevin/Brownian agitation \u2014 a real temperature in the medium"}},Vi={token:"collide",label:"Collide",apply(n,t,e){if(e.dist>=n.range)return;let r=Math.max(0,Math.min(1,n.strength)),s=Math.max(1,t.size);for(let i of e.neighbors(t,s*4)){let l=Math.max(1,i.size),d=t.x-i.x,m=t.y-i.y,b=(t.z??0)-(i.z??0),p=Math.hypot(d,m,b);if(p>=s+l||p<1e-6)continue;let M=d/p,z=m/p,E=b/p,A=(t.vx-i.vx)*M+(t.vy-i.vy)*z+((t.vz??0)-(i.vz??0))*E;if(A>=0)continue;let P=(1+r)*.5*A;t.vx-=P*M,t.vy-=P*z,i.vx+=P*M,i.vy+=P*z,b&&(t.vz=(t.vz??0)-P*E,i.vz=(i.vz??0)+P*E)}},meta:{desc:"elastic pairwise collision \u2014 the hard-sphere billiard force"}},Xi={token:"diffuse",label:"Diffuse",apply(n,t,e){if(e.dist>=n.range)return;let r=e.grid("diffuse");r.deposit(t.x,t.y,n.strength);let s=r.gradient(t.x,t.y);t.vx+=s.x*n.strength,t.vy+=s.y*n.strength},meta:{desc:"pheromone field \u2014 deposit a mark and follow the diffused gradient"}},Ki=12,_n=7,Ji={token:"propagate",label:"Propagate",source(n,t){n.on&&t.frameN%Ki===0&&t.grid("wave-propagate").deposit(n.cx,n.cy,n.strength)},apply(n,t,e){if(e.dist>=n.range)return;let s=e.grid("wave-propagate").gradient(t.x,t.y),i=Math.hypot(s.x,s.y);if(i<1e-6)return;let l=-e.dx/e.dist,d=-e.dy/e.dist;t.vx+=l*i*n.strength*_n,t.vy+=d*i*n.strength*_n,e.dz&&(t.vz=(t.vz??0)+-e.dz/e.dist*i*n.strength*_n),qn(t,e.c)},meta:{desc:"a travelling wave \u2014 a shock train expands from the source, sweeping matter out"}},Qi={token:"memory",label:"Memory",apply(n,t,e){if(e.dist>=n.range)return;let r=e.grid("memory");r.deposit(t.x,t.y,n.strength*.15);let s=1+.5*r.sample(t.x,t.y),i=(1-e.dist/n.range)**2*n.strength*.5*s;t.vx+=e.dx/e.dist*i,t.vy+=e.dy/e.dist*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i)},meta:{desc:"the field remembers \u2014 occupancy wears in paths that pull harder"}},Zi=[ji,Hi,Yi,Gi,Vi,Xi,Ji,Qi];function ur(n){for(let t of Zi)n.force(t)}var ta={token:"lens",label:"Lens",kinematic:!0,apply(n,t,e){if(e.dist>=n.range)return;let r=n.strength*(1-e.dist/n.range)*n.spin,s=Math.cos(r),i=Math.sin(r),l=t.vx,d=t.vy;t.vx=l*s-d*i,t.vy=l*i+d*s},meta:{desc:"rotates velocity, preserving speed \u2014 bends paths without adding energy"}},ea={token:"gate",label:"Gate",kinematic:!0,apply(n,t,e){if(Math.abs(t.x-n.cx)>=n.hw+6||Math.abs(t.y-n.cy)>=n.hh+6)return;let s=t.vx*n.ux+t.vy*n.uy;s<0&&(t.vx-=2*s*n.ux,t.vy-=2*s*n.uy)},meta:{desc:"a one-way membrane \u2014 passes matter along its heading, reflects the reverse"}},na=1,oa=1,ra={token:"buoyancy",label:"Buoyancy",apply(n,t,e){if(n.range>0&&e.dist>=n.range)return;let r=na/(t.size*(1+t.heat));t.vy-=(oa-r)*n.strength},meta:{desc:"a constant lift/sink by density difference \u2014 light matter rises, dense settles"}},sa={token:"shear",label:"Shear",apply(n,t,e){if(e.dist>=n.range)return;let r=(t.x-n.cx)*-n.uy+(t.y-n.cy)*n.ux,s=n.strength*(r/n.range)*(1-e.dist/n.range);t.vx+=n.ux*s,t.vy+=n.uy*s},meta:{desc:"a laminar shear gradient \u2014 flow speed grows with perpendicular offset"}},He=32,ia=.5,aa={token:"crystallize",label:"Crystallize",apply(n,t,e){if(e.dist>=n.range||t.heat>=ia)return;let r=n.cx+Math.round((t.x-n.cx)/He)*He,s=n.cy+Math.round((t.y-n.cy)/He)*He;t.vx+=(r-t.x)*n.strength,t.vy+=(s-t.y)*n.strength,t.vx*=.9,t.vy*=.9},meta:{desc:"snaps cool matter onto a lattice; melts and frees it when hot"}},ca={token:"align",label:"Align",apply(n,t,e){if(e.dist>=n.range)return;let r=t.vz??0,s=Math.hypot(t.vx,t.vy,r),i=n.strength,l=n.ux,d=n.uy,m=0,b=0,p=0,M=0;for(let E of e.neighbors(t,n.range)){let A=E.vz??0,P=Math.hypot(E.vx,E.vy,A);P>1e-6&&(b+=E.vx/P,p+=E.vy/P,M+=A/P)}let z=Math.hypot(b,p,M);z>1e-6&&(l=b/z,d=p/z,m=M/z),t.vx+=(l*s-t.vx)*i,t.vy+=(d*s-t.vy)*i,(m||r)&&(t.vz=r+(m*s-r)*i)},meta:{desc:"steers toward the neighbour-mean heading (or the body heading when alone)"}};function la(n,t,e,r){let s=n*r+e*.2,i=t*r-e*.2;return{x:-r*Math.sin(s)*Math.sin(i),y:-r*Math.cos(s)*Math.cos(i)}}var da=.01,fa={token:"wind",label:"Wind",apply(n,t,e){if(n.range>0&&e.dist>=n.range)return;let r=la(t.x,t.y,e.t,da);t.vx+=r.x*n.strength,t.vy+=r.y*n.strength},meta:{desc:"divergence-free curl-noise turbulence"}},ua=.5,ha={token:"cohesion",label:"Cohesion",apply(n,t,e){if(e.dist>=n.range)return;let r=n.range,s=r*ua,i=n.strength;for(let l of e.neighbors(t,r)){let d=l.x-t.x,m=l.y-t.y,b=(l.z??0)-(t.z??0),p=Math.hypot(d,m,b);if(p<1e-6)continue;let M=d/p,z=m/p,E=b/p;if(p<s){let A=i*(s-p)/s;t.vx-=A*M,t.vy-=A*z,b&&(t.vz=(t.vz??0)-A*E)}else{let A=i*(p-s)/(r-s);t.vx+=A*M,t.vy+=A*z,b&&(t.vz=(t.vz??0)+A*E)}}},meta:{desc:"short-range pressure + mid-range cohesion \u2014 surface tension over neighbours"}},ya=.5,pa={token:"pressure",label:"Pressure",apply(n,t,e){if(e.dist>=n.range)return;let r=n.range,s=n.strength,i=0,l=e.neighbors(t,r);for(let m of l){let b=Math.hypot(m.x-t.x,m.y-t.y,(m.z??0)-(t.z??0));b<r&&(i+=(1-b/r)**2)}let d=i-ya;if(!(d<=0))for(let m of l){let b=t.x-m.x,p=t.y-m.y,M=(t.z??0)-(m.z??0),z=Math.hypot(b,p,M);if(z<1e-6||z>=r)continue;let E=s*d*(1-z/r)/z;t.vx+=E*b,t.vy+=E*p,M&&(t.vz=(t.vz??0)+E*M)}},meta:{desc:"SPH density relaxation \u2014 incompressible even-fill via mutual repulsion"}},ma={token:"hunt",label:"Hunt",apply(n,t,e){if(e.dist>=n.range)return;let r=t.species??0,s=null,i=1/0;for(let M of e.neighbors(t,n.range)){if((M.species??0)===r)continue;let z=M.x-t.x,E=M.y-t.y,A=(M.z??0)-(t.z??0),P=z*z+E*E+A*A;P<i&&(i=P,s=M)}if(!s)return;let l=s.x-t.x,d=s.y-t.y,m=(s.z??0)-(t.z??0),b=Math.hypot(l,d,m)||1,p=r===0?1:-1;t.vx+=l/b*n.strength*p,t.vy+=d/b*n.strength*p,m&&(t.vz=(t.vz??0)+m/b*n.strength*p)},meta:{desc:"two-species pursuit \u2014 predators seek prey, prey flee predators"}},ga=.35,xa={token:"link",label:"Link",apply(n,t,e){if(e.dist>=n.range)return;let r=n.range,s=r*ga,i=n.strength;for(let l of e.neighbors(t,r)){let d=l.x-t.x,m=l.y-t.y,b=(l.z??0)-(t.z??0),p=Math.hypot(d,m,b);if(p<1e-6)continue;let M=p-s,z=.5*i*(M/s);t.vx+=z*(d/p),t.vy+=z*(m/p),b&&(t.vz=(t.vz??0)+z*(b/p))}},meta:{desc:"a Verlet distance constraint \u2014 holds a rest length, so matter ropes and drapes"}},hr=40,va={token:"morph",label:"Morph",apply(n,t,e){let r=n.targets;if(!r||r.length===0)return;let s=Math.min(r.length-1,Math.floor((t.gx??0)*r.length)),i=r[s],l=i.x-t.x,d=i.y-t.y,m=Math.hypot(l,d),b=n.strength;t.vx+=l*b*.02,t.vy+=d*b*.02,t.z&&(t.vz=(t.vz??0)-t.z*b*.02);let M=(1-(m<hr?1-m/hr:0))*b*.3;M>0&&(t.vx+=((e.rng??Math.random)()-.5)*M,t.vy+=((e.rng??Math.random)()-.5)*M)},meta:{desc:"matter assembles into a mark/chart/logo \u2014 never words (\xA711)"}},ba=90,wa={token:"spawn",label:"Spawn",apply(){},source(n,t){let e=n.life??ba,r=Math.max(1,Math.round(n.strength*2));n.cap!=null&&n.cap>0&&e>0&&(r=Math.min(r,n.cap/e)),n.emitAcc=(n.emitAcc??0)+r;let s=Math.floor(n.emitAcc);for(n.emitAcc-=s;s>0;s--){let i=((t.rng??Math.random)()-.5)*.6,l=Math.cos(i),d=Math.sin(i),m=n.ux*l-n.uy*d,b=n.ux*d+n.uy*l,p=2+(t.rng??Math.random)()*2;t.spawn({x:n.cx,y:n.cy,vx:m*p,vy:b*p,age:e,heat:.6,...n.species!=null?{species:n.species}:{}})}},meta:{desc:"a source \u2014 emits matter along the heading, budgeted by a lifespan"}},Ma=3,ka={token:"resonate",label:"Resonate",apply(){},modify(n,t,e){return{strength:1+Math.sin(e.t*Ma*n.spin)}},meta:{desc:"pulses sibling forces with a time-varying strength S(t)=S\u2080(1+sin \u03C9t)"}},Sa=.5,Ea={token:"spotlight",label:"Spotlight",apply(){},modify(n,t,e){let r=-e.dx/e.dist,s=-e.dy/e.dist;return{gate:r*n.ux+s*n.uy<Sa}},meta:{desc:"gates sibling forces to an angular cone of the heading"}},za={token:"screen",label:"Screen",apply(){},meta:{desc:"a quiet zone \u2014 attenuates other bodies' forces on matter inside its radius"}},Fa={token:"pigment",label:"Pigment",apply(n,t,e){let r=n.tint;!r||e.dist>=n.range*.6||(t.color=t.color?_o(t.color,r,.08):r)},meta:{desc:"conserved color transport \u2014 matter takes on and carries a tint"}},Ta=.5,yr=.12,Aa={token:"fieldflow",label:"Field Flow",apply(n,t,e){if(n.range>0&&e.dist>=n.range||n.chargeGated&&(t.charge??0)===0)return;let r=e.fieldAt?.(t.x,t.y);if(!r)return;let s=Math.hypot(r.x,r.y);if(!(s>1e-9))return;let i=r.x/s,l=r.y/s,d=n.range>0?1-e.dist/n.range:1,m=n.strength*d,b=t.vz??0,p=Math.hypot(t.vx,t.vy,b);if(p>1e-6){let E=Math.min(1,m*Ta);t.vx+=(i*p-t.vx)*E,t.vy+=(l*p-t.vy)*E,b&&(t.vz=b+(0-b)*E)}t.vx+=i*m*yr,t.vy+=l*m*yr;let M=t.vz??0,z=t.vx*t.vx+t.vy*t.vy+M*M;if(z>e.c*e.c){let E=e.c/Math.sqrt(z);t.vx*=E,t.vy*=E,M&&(t.vz=M*E)}n.on&&(t.heat=Math.max(t.heat,d*.4))},meta:{desc:"follow the field lines \u2014 steer onto and stream down the net field a body radiates"}},Ca={token:"warp",label:"Warp",kinematic:!0,apply(n,t,e){if(!n.warpHas||t.cap)return;let r=n.absorbR;if(e.dist>=r)return;let s=Math.cos(n.twist??0),i=Math.sin(n.twist??0),l=n.warpScale??1,d=-e.dx/e.dist,m=-e.dy/e.dist,b=d*s-m*i,p=d*i+m*s,M=r*l+6;t.x=n.warpX+b*M,t.y=n.warpY+p*M,t.z&&(t.z=-e.dz/e.dist*M);let z=t.vx,E=t.vy;t.vx=z*s-E*i,t.vy=z*i+E*s,t.heat=Math.max(t.heat,.6)},meta:{desc:"a wormhole throat \u2014 relocates matter to its paired body, conserved"}},Oa=[ta,ea,ra,sa,aa,ca,fa,ha,pa,xa,ma,va,wa,ka,Ea,za,Fa,Aa,Ca];function pr(n){for(let t of Oa)n.force(t)}var mr=new Set(["css","canvas","svg","typography","spatial","native"]);function gr(n){let t=[];for(let e of n)e.surfaces.some(s=>mr.has(s))&&!e.reducedMotionEquivalent&&t.push({rule:"field/reduced-motion-equivalent-required",severity:"error",subject:e.id,message:`Projection "${e.id}" can express motion (${e.surfaces.filter(s=>mr.has(s)).join(", ")}) but declares no reducedMotionEquivalent. Reduced motion must translate the behavior, not remove it.`}),e.accessibilityEquivalent||t.push({rule:"field/accessibility-equivalent-required",severity:"warning",subject:e.id,message:`Projection "${e.id}" declares no accessibilityEquivalent. Accessibility is an alternate projection of the same field state, not a fallback.`});return t}var jn=(n,t)=>t?Object.fromEntries(Object.entries(n).filter(([e])=>t.has(e))):n;function xr(n,t){let e=t.metrics?new Set(t.metrics):null,r=t.channels?new Set(t.channels):null,s=t.tokens?new Set(t.tokens):null;return{...n,metrics:jn(n.metrics,e),bodies:n.bodies.filter(i=>!s||i.tokens.some(l=>s.has(l))).map(i=>({...i,metrics:jn(i.metrics,e),dimensions:jn(i.dimensions,e)})),influences:r?n.influences.filter(i=>r.has(i.channel??"linear")):n.influences,lens:t.id}}function vr(n,t,e={}){return{x:n,y:t,strength:e.strength??1,radius:e.radius&&e.radius>0?e.radius:360}}function ge(n,t,e,r,s=.6){let i=r.x-t,l=r.y-e,d=Math.hypot(i,l);if(d===0||d>=r.radius)return n.x=0,n.y=0,n;let m=(1-d/r.radius)*r.strength*s;return n.x=i/d*m,n.y=l/d*m,n}var Ra={step:6,maxSteps:400,minStrength:1e-9,loopDist:6,maxTurns:1/0};function br(n,t,e,r,s){let i=[{x:t,y:e}],l=t,d=e,m=s.step,b=s.maxTurns*2*Math.PI,p=0,M=0,z=0;for(let E=0;E<s.maxSteps;E++){let A=n(l,d),P=Math.hypot(A.x,A.y);if(!(P>=s.minStrength))break;let B=A.x/P*r,I=A.y/P*r;if(Number.isFinite(b)){if(p!==0||M!==0){let G=Math.max(-1,Math.min(1,B*p+I*M));if(z+=Math.acos(G),z>b)break}p=B,M=I}if(l+=B*s.step,d+=I*s.step,s.bounds&&(l<-m||d<-m||l>s.bounds.w+m||d>s.bounds.h+m))break;if(E>4&&Math.hypot(l-t,d-e)<s.loopDist){i.push({x:l,y:d});break}i.push({x:l,y:d})}return i}function Pa(n,t,e,r={}){let s={...Ra,bounds:r.bounds,...r},i=br(n,t,e,-1,s),l=br(n,t,e,1,s);return i.reverse(),i.pop(),i.concat(l)}function wr(n,t,e={}){return t.map(r=>Pa(n,r.x,r.y,e)).filter(r=>r.length>1)}var $a=8,Ia=60;function Mr(n,t=8){let e={cx:n.cx,cy:n.cy,hw:n.hw,hh:n.hh,ux:n.ux,uy:n.uy,spin:n.spin},r=_e(e),s=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y);if(s<Math.max(n.range*.06,$a)){let b=Math.max(n.range*.18,Ia),p=n.spin<0?-1:1;r=[{x:n.cx+n.ux*b,y:n.cy+n.uy*b,q:p},{x:n.cx-n.ux*b,y:n.cy-n.uy*b,q:-p}],s=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y)}let i=-n.uy,l=n.ux,d=Math.max(s*.13,18),m=[{x:n.cx,y:n.cy}];for(let b=1;b<=t;b++){let p=b*d;m.push({x:n.cx+i*p,y:n.cy+l*p}),m.push({x:n.cx-i*p,y:n.cy-l*p})}return m}function kr(n,t=18){let e=Math.max(Math.min(n.hw,n.hh)*.8,24),r=[];for(let s=0;s<t;s++){let i=s/t*Math.PI*2;r.push({x:n.cx+Math.cos(i)*e,y:n.cy+Math.sin(i)*e})}return r}function Sr(n,t=8){let e=[];for(let r of n)!r.vis||r.tokens.length===0||(r.tokens.includes("magnetism")?e.push(...Mr(r,t)):(r.tokens.includes("charge")||r.tokens.includes("gravity"))&&e.push(...kr(r)));return e}function Er(n,t=Math.random){return 3+Math.floor(t()*(n>0?n:1)*3)}var zr=160;function Fr(n,t,e,r=6,s=0){let i=Math.hypot(n,t,s)||1;if(i>=e)return{vx:0,vy:0,vz:0,heat:0};let l=1-i/e,d=l*r;return{vx:n/i*d,vy:t/i*d,vz:s/i*d,heat:l*.9}}function Tr(n,t,e,r,s=.9,i=80){let l=r>0?r:1;n.vx=(n.vx+t/l)*s,n.vy=(n.vy+e/l)*s,n.x+=n.vx,n.y+=n.vy;let d=Math.hypot(n.x,n.y);d>i&&(n.x=n.x/d*i,n.y=n.y/d*i)}function Ar(n,t=.02){return{x:-n.x*t,y:-n.y*t}}function Cr(n){let t=n/3e4;return t<.6?.6:t>6?6:t}function Or(n,t,e=-1,r=1600,s=26){let i=0,l=0,d=s*s;for(let m=0;m<t.length;m++){if(m===e)continue;let b=t[m],p=n.x-b.x,M=n.y-b.y,z=p*p+M*M+d;i+=r*p/z,l+=r*M/z}return{x:i,y:l}}function Rr(n,t,e,r=16,s=1){let i=(n(t+r,e)-n(t-r,e))/(2*r),l=(n(t,e+r)-n(t,e-r))/(2*r);return{x:-i*s,y:-l*s}}function Pr(n,t,e,r,s,i,l,d){if(r.length===0)return;let m=n.particles;for(let b=m.length-1;b>=0&&!(t.length>=e);b--){let p=m[b];if(!p||p.cap||p.heat>=.12)continue;let M=-1,z=1e9,E=0;for(let P=0;P<r.length;P++){let B=Et(r[P],p.x,l,i),I=Math.abs(B-p.y);I<z&&(z=I,M=P,E=B)}if(M<0||z>=64)continue;let A=Math.min(.012,z*4e-4)*(1-p.heat/.12);p.vy+=E>p.y?A:-A,z<20&&p.vx*p.vx+p.vy*p.vy<.3&&d()<.03&&(t.push({wi:M,progress:p.x/s,phase:(d()-.5)*.22*Math.PI,size:p.size,glow:d()<.3,speed:(35e-5+d()*9e-4)*(d()<.5?1:-1)}),n.remove(p))}}function Hn(n,t,e,r,s,i,l,d,m){for(let b=n.length-1;b>=0;b--){let p=n[b];if(!p)continue;let M=t[p.wi];if(!M)continue;let z=p.progress*i,E=Et(M,z,d,l)+p.phase*32,A=z-e,P=E-r,B=Math.hypot(A,P);if(B<s&&B>.5){let I=(1-B/s)*4;m({x:z,y:E,vx:A/B*I,vy:P/B*I,size:p.size,heat:.9});let G=n.pop();G&&b<n.length&&(n[b]=G)}}}function $r(n,t,e,r,s,i,l,d){let m=b=>b.tokens.some(p=>{let M=r[p];return!!M&&!M.modify&&!M.source});for(let b=n.length-1;b>=0;b--){let p=n[b];if(!p)continue;let M=t[p.wi];if(!M)continue;let z=p.progress*s,E=Et(M,z,l,i)+p.phase*32,A=!1,P=0,B=0;for(let I of e){if(!I.vis||I.when==="active"&&!I.on||I.when&&I.when!=="active")continue;let G=I.tokens,J=I.cx-z,h=I.cy-E,X=Math.hypot(J,h)||1,bt=I.range*(I.on?1.4:1);if(G.indexOf("wall")>=0&&Math.abs(z-I.cx)<I.hw+6&&Math.abs(E-I.cy)<I.hh+6&&(P=(z<I.cx?-1:1)*1.6,B=(E<I.cy?-1:1)*.8,A=!0),!A&&(G.indexOf("attract")>=0||G.indexOf("sink")>=0||G.indexOf("jet")>=0)&&X<bt*.8){let tt=1.2+(I.on?1.6:0);P=J/X*tt,B=h/X*tt,A=!0}if(!A&&G.indexOf("repel")>=0&&X<bt*.8){let tt=1.2+(I.on?1.2:0);P=-(J/X)*tt,B=-(h/X)*tt,A=!0}if(!A&&G.indexOf("swirl")>=0&&X<bt*.75&&(P=h/X*1.2,B=-(J/X)*1.2,A=!0),!A&&G.indexOf("stream")>=0&&X<bt*.75&&(P=I.ux*1.3,B=I.uy*1.3,A=!0),!A&&X<bt*.8&&m(I)){let tt=.8+(I.on?.8:0);P=J/X*tt,B=h/X*tt,A=!0}if(A)break}if(A){d({x:z,y:E,vx:P,vy:B,size:p.size,heat:.5});let I=n.pop();I&&b<n.length&&(n[b]=I)}}}function Ir(n,t){for(let e of n){if(!e.vis||e.tokens.indexOf("charge")<0&&e.tokens.indexOf("magnetism")<0||e.range<=0)continue;let r=e.range*e.range;for(let s of t){if(s.charge)continue;let i=e.cx-s.x,l=e.cy-s.y;i*i+l*l>=r||(s.charge=i>=0?1:-1)}}}var Dr=n=>n<0?0:n>1?1:n;function Nr(n){if(!n||n.n===0)return{entropy:0,coherence:1,temperature:0};let t=n.sh/n.n,e=n.ss/n.n,r=n.ss2/n.n,s=Dr(.5*t+.5*Math.min(1,r/9)),i=n.ss>1e-9?Math.hypot(n.sx,n.sy)/n.ss:1,l=Dr((1-i)*Math.min(1,e/1.5));return{entropy:l,coherence:1-l,temperature:s}}var Ye=class{constructor(){U(this,"pending",new Map);U(this,"ids",new WeakMap);U(this,"seq",0)}idOf(t){let e=this.ids.get(t);return e===void 0&&this.ids.set(t,e=++this.seq),e}keyOf(t,e){if(t==="met"){let s=e,[i,l]=[this.idOf(s.a.el??s.a),this.idOf(s.b.el??s.b)].sort((d,m)=>d-m);return`${i}:${l}`}if(t==="enter"||t==="exit"){let s=e;return`${this.idOf(s.body.el??s.body)}:${this.idOf(s.other.el??s.other)}`}let r=e;return String(this.idOf(r.body.el??r.body))}record(t,e){let r=this.pending.get(t);r||this.pending.set(t,r=new Map),r.set(this.keyOf(t,e),e)}flush(t){if(this.pending.size!==0){for(let[e,r]of this.pending)for(let s of r.values())t(e,s);this.pending.clear()}}};function Yn(n){return n.split(",").map(t=>t.trim()).filter(Boolean).map(t=>{let e=t.indexOf(":");return{trigger:t.slice(0,e).trim(),event:t.slice(e+1).trim(),armed:!1}}).filter(t=>t.trigger&&t.event)}function Un(n,t){switch(n){case"dense":return t.d>.6;case"sparse":return t.d<.2;case"engaged":return t.on;case"captured":return t.accreted>0;default:return!1}}var Br={blackhole:[{body:"attract",strength:1.4,range:340},{body:"swirl",strength:1,range:300,spin:1},{body:"sink",absorb:42,max:60},{body:"lens",strength:.5,range:380}],whitehole:[{body:"repel",strength:1.4,range:340},{body:"stream",strength:.6,range:300,angle:0}],star:[{body:"gravity",strength:300,range:320},{body:"thermal",strength:1,range:220}],quasar:[{body:"attract",strength:.7,range:340},{body:"swirl",strength:1.2,range:300,spin:1},{body:"sink",absorb:40,max:60},{body:"lens",strength:.5,range:380},{body:"jet",strength:2.5,range:280,angle:-90},{body:"jet",strength:2.5,range:280,angle:90}],galaxy:[{body:"attract",strength:.6,range:400},{body:"swirl",strength:1.3,range:380,spin:1},{body:"viscosity",strength:.4,range:400},{body:"lens",strength:.3,range:420}],nebula:[{body:"thermal",strength:.8,range:320},{body:"viscosity",strength:.5,range:320},{body:"buoyancy",strength:.3,range:0}],tornado:[{body:"swirl",strength:1.6,range:300,spin:1},{body:"stream",strength:.8,range:280,angle:-90},{body:"viscosity",strength:.3,range:300}],fountain:[{body:"spawn",strength:1.2,angle:-90,life:90},{body:"gravity",strength:60,range:0}]};function Da(){return globalThis.process?.env?.NODE_ENV!=="production"}var _r=Da();function Wr(){return _r}var Lr=new Set;function Gn(n,t){if(!_r)return;let e=`${n}:${t}`;Lr.has(e)||(Lr.add(e),console.warn(`[Fundamental:${n}] ${t}`))}var Na={"draw-focus":{body:["attract"],range:280,feedback:!0},"clear-space":{body:["repel"],range:240},"show-motion":{body:["stream"],render:["trails"]},"show-relationship":{body:["memory"],render:["links"]},"contain-energy":{body:["viscosity","wall"]},ignite:{body:["thermal","fieldflow"],render:["heatmap","particles"]},stabilize:{body:["viscosity","cohesion"]},warn:{body:["repel","thermal"],feedback:!0}};function qr(n,t={}){let e=Na[n];if(!e)return null;let r=[...e.body];t.risk==="high"&&!r.includes("thermal")&&r.push("thermal");let s={"data-body":r.join(" ")};return t.intensity!=null&&(s["data-strength"]=String(t.intensity)),e.range!=null&&(s["data-range"]=String(e.range)),e.feedback&&(s["data-feedback"]=""),e.render?.length&&(s["data-render"]=e.render.join(" ")),{body:r.join(" "),strength:t.intensity,range:e.range,feedback:e.feedback??!1,render:e.render??["particles"],attributes:s}}function Hr(n){let t=(P,B)=>{let I=Number.parseFloat(n.get(P)??"");return Number.isFinite(I)?I:B},e=t("strength",.5),r=t("angle",0)*Math.PI/180,s=n.get("spin"),i=s==null?1:Number.isFinite(Number.parseFloat(s))?Number.parseFloat(s):0,l=(n.get("body")??"").split(/\s+/).filter(Boolean),d=Ne(l),m=n.get("life"),b=n.get("cap"),p=Number.parseFloat(m??""),M=Number.parseFloat(b??""),z=m!=null||b!=null||n.has("budget")||n.has("sink"),E=n.get("authority");return{tokens:l,authority:E==="kinematic"||E==="dynamic"?E:"anchored",classified:d,...Number.isFinite(p)&&p>0?{life:p}:{},...Number.isFinite(M)&&M>0?{cap:M}:{},budgeted:z,strength:e,range:t("range",280),absorbR:t("absorb",64),capacity:t("max",60),spin:i,angle:r,ux:Math.cos(r),uy:Math.sin(r),when:n.get("when")??"",feedback:n.has("feedback"),shaped:n.has("shaped"),chargeGated:n.has("charge-gated"),...n.get("species")!=null&&Number.isFinite(Number.parseFloat(n.get("species")))?{species:Number.parseFloat(n.get("species"))}:{},...(()=>{let P=n.get("affects");if(P==null)return{};let B=P.split(",").map(I=>Number.parseFloat(I.trim())).filter(I=>Number.isFinite(I));return B.length?{affects:new Set(B)}:{}})(),fmin:t("fmin",0),fmax:t("fmax",0),opsz:n.get("opsz")??"",pair:n.get("pair")||void 0,twist:t("twist",0)*Math.PI/180,warpScale:t("scale",1),screenMin:t("screen-min",0),M:e}}function Ba(n){let t={body:n.body};return n.strength!=null&&(t.strength=String(n.strength)),n.range!=null&&(t.range=String(n.range)),n.spin!=null&&(t.spin=String(n.spin)),n.angle!=null&&(t.angle=String(n.angle)),n.absorb!=null&&(t.absorb=String(n.absorb)),n.max!=null&&(t.max=String(n.max)),n.life!=null&&(t.life=String(n.life)),n.cap!=null&&(t.cap=String(n.cap)),{get:e=>t[e]??null,has:e=>e in t}}function La(n){let t=Br[n];return t?t.map(e=>Hr(Ba(e))):[]}function _a(n){let t=(n.tagName??"element").toLowerCase(),e=n.id?`#${n.id}`:"",r=typeof n.className=="string"&&n.className?`.${n.className.split(/\s+/)[0]}`:"";return`<${t}${e}${r}>`}function Wa(n,t="<body>"){!n.classified||n.classified.sources.length===0||n.budgeted||(n.life=Cn,n.cap=On,Wr()&&console.warn(`[Fundamental:UNBUDGETED_SOURCE] ${t} runs the source force "${n.classified.sources.join(" ")}" with none of data-life / data-cap / data-budget / data-sink. Applying the safe default budget (data-life="${Cn}", data-cap="${On}") \u2014 declare one to make the source's budget explicit (workover v0.3 source rules).`))}function Yr(n,t){return Wa(t,_a(n)),{el:n,...t,tint:n.dataset.color,cx:0,cy:0,hw:0,hh:0,on:!1,vis:!0,accreted:0,count:0,d:0,attn:1}}function qa(n){return{get:t=>n.getAttribute("data-"+t),has:t=>n.hasAttribute("data-"+t)}}function xe(n,t){return Yr(n,Hr(t??qa(n)))}var jr={source:"jet",sink:"sink",anchor:"tether",boundary:"wall",sensor:"",display:""};function ja(n){let t=null,e=n.getAttribute("data-intent");if(e){let s=n.getAttribute("data-intensity"),i=qr(e,{intensity:s!=null?Number(s):void 0,risk:n.getAttribute("data-risk")??void 0});i&&(t={body:i.body},i.strength!=null&&(t.strength=String(i.strength)),i.range!=null&&(t.range=String(i.range)),i.feedback&&(t.feedback=""))}if(!t){let s=n.getAttribute("data-field-role");s!=null&&s in jr&&(t={body:jr[s],feedback:""})}if(!t)return null;let r=t;return{get:s=>n.getAttribute("data-"+s)??r[s]??null,has:s=>n.hasAttribute("data-"+s)||s in r}}var Ue="data-field-boundary",Ha=`[${Ue}]`;function Vn(n,t){if(typeof n.closest!="function")return!0;let e=n.closest(Ha);return e===null||e===t}function Ur(n){let t=[];return n.querySelectorAll("[data-body]").forEach(e=>{Vn(e,n)&&t.push(xe(e))}),n.querySelectorAll("[data-preset]").forEach(e=>{if(!Vn(e,n))return;let r=e;for(let s of La(r.dataset.preset??""))t.push(Yr(r,s))}),n.querySelectorAll("[data-intent]:not([data-body]), [data-field-role]:not([data-body]):not([data-intent])").forEach(e=>{if(!Vn(e,n))return;let r=ja(e);r&&t.push(xe(e,r))}),t}function Ya(n){let t=n.el;if(typeof t.getAttribute!="function")return;let e=t.getAttribute("data-strength");if(e!=null){let l=Number.parseFloat(e);Number.isFinite(l)&&(n.strength=l,n.M=l)}let r=t.getAttribute("data-range");if(r!=null){let l=Number.parseFloat(r);Number.isFinite(l)&&(n.range=l)}let s=t.getAttribute("data-spin");if(s!=null){let l=Number.parseFloat(s);Number.isFinite(l)&&(n.spin=l)}let i=t.getAttribute("data-angle");if(i!=null){let l=Number.parseFloat(i);Number.isFinite(l)&&(n.angle=l*Math.PI/180,n.ux=Math.cos(n.angle),n.uy=Math.sin(n.angle))}}function Ge(n,t,e,r=0,s=0){let i=e*.15;for(let l of n){let d=l.rect?l.rect():l.el.getBoundingClientRect(),m=d.left-r,b=d.top-s;l.cx=m+d.width/2,l.cy=b+d.height/2,l.hw=d.width/2,l.hh=d.height/2,l.on=l.el.dataset.active==="1",l.vis=b+d.height>-i&&b<e+i&&m+d.width>-i&&m<t+i,Ya(l)}}var Gr="field:register-body",Vr="field:unregister-body",Xr="field:update-body";var Ve=class{constructor(){U(this,"hosts",new Map)}register(t){this.hosts.set(t.element,t)}unregister(t){this.hosts.delete(t)}get size(){return this.hosts.size}bodies(t){let e=[];for(let[r,s]of this.hosts){if(!r.isConnected){this.hosts.delete(r);continue}let i=s.attrs?Ua(s.attrs,r):void 0,l=t(r,i);s.getRect&&(l.rect=s.getRect),s.writeTarget&&(l.writeTarget=s.writeTarget),e.push(l)}return e}};function Ua(n,t){return{get:e=>n[e]??t.getAttribute("data-"+e),has:e=>e in n||t.hasAttribute("data-"+e)}}function Qr(n,t,e=.12){return n>=t?0:(1-n/t)*e}function Xe(n,t,e){if(n===t)return .5;let r=(e-n)/(t-n);return r<0?0:r>1?1:r}var Kr=Object.freeze([]);function Xn(n,t,e,r,s){let i={x:Xe(n,t,s),y:0},l={x:1,y:Xe(t,e,s)},d={x:Xe(r,e,s),y:1},m={x:0,y:Xe(n,r,s)},b=(M,z)=>({x1:M.x,y1:M.y,x2:z.x,y2:z.y});switch((n>s?8:0)|(t>s?4:0)|(e>s?2:0)|(r>s?1:0)){case 0:case 15:return Kr;case 1:case 14:return[b(m,d)];case 2:case 13:return[b(d,l)];case 3:case 12:return[b(m,l)];case 4:case 11:return[b(i,l)];case 6:case 9:return[b(i,d)];case 7:case 8:return[b(m,i)];case 5:return[b(m,i),b(d,l)];case 10:return[b(m,d),b(i,l)];default:return Kr}}function Kn(n,t,e,r,s,i,l,d=1){if(l<=0)return;let m=Math.max(0,Math.floor((s-l)/r)),b=Math.min(t-1,Math.ceil((s+l)/r)),p=Math.max(0,Math.floor((i-l)/r)),M=Math.min(e-1,Math.ceil((i+l)/r)),z=l*l;for(let E=p;E<=M;E++)for(let A=m;A<=b;A++){let P=A*r-s,B=E*r-i,I=P*P+B*B;if(I>=z)continue;let G=1-Math.sqrt(I)/l,J=E*t+A;n[J]=n[J]+d*G*G}}function Zr(n,t,e){let r=-1,s=1/0;for(let i=0;i<e.length;i++){let l=e[i],d=l.x-n,m=l.y-t,b=d*d+m*m;b<s&&(s=b,r=i)}return r}function ts(n,t,e=1){let r=(n*2.6+t*2.5)*e;return r<2?2:r}function es(n,t,e,r,s,i){let l=n-s,d=t-i,m=Math.hypot(l,d);return m<1e-6?0:(l*e+d*r)/m}function ns(n,t){if(t<=0)return 0;let e=n/(.35*t);return e<-1?-1:e>1?1:e}function os(n,t){return t<=0||n>=t?0:1-Math.sqrt(n/t)}function rs(n,t){let e=n+t*.6;return e<-1?-1:e>1?1:e}var Ga=[96,160,255],Jr=[226,230,240],Va=[255,72,48];function ss(n,t){let e=t<-1?-1:t>1?1:t,r=e<0?Ga:Jr,s=e<0?Jr:Va,i=e<0?e+1:e;return n[0]=r[0]+(s[0]-r[0])*i,n[1]=r[1]+(s[1]-r[1])*i,n[2]=r[2]+(s[2]-r[2])*i,n}function is(n,t,e,r){let s=.3*r,i=s>0?(n*n+t*t)/(s*s):0,l=.55*e+.55*(i>1?1:i);return l<0?0:l>1?1:l}var Ke=[[12,2,0],[130,24,2],[235,100,10],[255,180,90],[255,236,200],[201,218,255]];function as(n,t){let r=(t<0?0:t>1?1:t)*(Ke.length-1),s=Math.min(Math.floor(r),Ke.length-2),i=r-s,l=Ke[s],d=Ke[s+1];return n[0]=l[0]+(d[0]-l[0])*i,n[1]=l[1]+(d[1]-l[1])*i,n[2]=l[2]+(d[2]-l[2])*i,n}function cs(n,t){let e=n<0?-n:n;return t/(t+e)}function Jn(n,t,e){return t+(n-t)*e}function ls(n){return 1-.55*(n<0?0:n>1?1:n)}function ds(n){return 4.5*(n<0?0:n>1?1:n)}function fs(n,t,e){let r=[];for(let s=0;s<e;s++)for(let i=0;i<t;i++){let l=n[s*t+i];i+1<t&&n[s*t+i+1]!==l&&r.push({x1:i+.5,y1:s-.5,x2:i+.5,y2:s+.5}),s+1<e&&n[(s+1)*t+i]!==l&&r.push({x1:i-.5,y1:s+.5,x2:i+.5,y2:s+.5})}return r}var us=24,Xa=.12,Ka=.22,ve=class{constructor(t,e){U(this,"grid");U(this,"peak",.001);U(this,"cell",us);this.grid=new le(Math.max(1,t),Math.max(1,e),"diffuse",us)}resize(t,e){this.grid.resize(t,e)}clear(){this.grid.clear(),this.peak=.001}update(t){for(let s of t)this.grid.deposit(s.x,s.y,1);this.grid.stepDiffuse(Ka,Xa);let e=this.grid.max(),r=e>this.peak?.25:.03;this.peak+=(Math.max(e,.001)-this.peak)*r}norm(t,e){return pt(this.grid.sample(t,e)/this.peak,0,1)}gradient(t,e){if(this.peak<=0)return{x:0,y:0};let r=this.grid.gradient(t,e);return{x:r.x/this.peak,y:r.y/this.peak}}};var Ja={position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"0",pointerEvents:"none",display:"block"},hs=Object.entries(Ja).map(([n,t])=>`${n.replace(/[A-Z]/g,e=>"-"+e.toLowerCase())}:${t}`).join(";");function Qa(n){let t=n.width,e=n.height,r=null,s=0;return{root:{querySelectorAll:()=>[],querySelector:()=>null,contains:()=>!1},viewport:()=>({width:t,height:e,dpr:1}),scrollY:()=>0,scrollHeight:()=>e,reducedMotion:()=>!1,hidden:()=>!1,raf:l=>(r=l,1),cancelRaf:()=>{r=null},createCanvas:()=>{throw new Error("headlessHost does not render \u2014 use render:'none' and the signal read-outs (onFeedback / sampleScalar / readParticles).")},onResize:()=>()=>{},onScroll:()=>()=>{},onVisibility:()=>()=>{},onInput:()=>()=>{},onBodyEvent:()=>()=>{},tick(l){s=l??s+1e3/60;let d=r;r=null,d?.(s)},resize(l,d){t=l,e=d}}}var ys="10px ui-monospace, SFMono-Regular, Menlo, monospace";function Qn(n,t){let e=0,r=0;return{size(s,i,l){e=s,r=i,n.width=Math.floor(s*l),n.height=Math.floor(i*l),t.setTransform(l,0,0,l,0,0)},clear(){t.clearRect(0,0,e,r)},segments(s,i){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath();for(let l=0;l+3<s.length;l+=4)t.moveTo(s[l],s[l+1]),t.lineTo(s[l+2],s[l+3]);t.stroke()},polyline(s,i){if(!(s.length<4)){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath(),t.moveTo(s[0],s[1]);for(let l=2;l+1<s.length;l+=2)t.lineTo(s[l],s[l+1]);t.stroke()}},rect(s,i,l,d,m,b,p,M){t.fillStyle=`rgba(${m},${b},${p},${M})`,t.fillRect(s,i,l,d)},text(s,i,l,d,m,b,p){t.font=ys,t.textBaseline="middle",t.fillStyle=`rgba(${d},${m},${b},${p})`,t.fillText(s,i,l)},measureText(s){return t.font=ys,t.measureText(s).width}}}var Zn=(n,t)=>{if(t.density!==void 0){let e=t.density.toFixed(3);n.style.setProperty("--d",e),n.style.setProperty("--field-density",e)}if(t.heatmapDensity!==void 0){let e=t.heatmapDensity.toFixed(3);n.style.setProperty("--field-heatmap-density",e)}if(t.load!==void 0){let e=t.load.toFixed(3);n.style.setProperty("--load",e)}if(t.entropy!==void 0&&n.style.setProperty("--entropy",t.entropy.toFixed(3)),t.coherence!==void 0&&n.style.setProperty("--coherence",t.coherence.toFixed(3)),t.temperature!==void 0&&n.style.setProperty("--temperature",t.temperature.toFixed(3)),t.lit!==void 0){let e=t.lit;n.style.setProperty("--lit",e.toFixed(3));let r=n.dataset.fxLit==="1";e>.5&&!r?(n.dataset.fxLit="1",n.dispatchEvent(new CustomEvent("field:lit",{detail:{value:e}}))):e<.4&&r&&(n.dataset.fxLit="0",n.dispatchEvent(new CustomEvent("field:dim",{detail:{value:e}})))}},ps=Zn;var Je=class{constructor(t){U(this,"lit",!1);U(this,"lastEdgeMs",-1/0);U(this,"cfg");this.cfg=t}update(t,e){let r=e-this.lastEdgeMs>=this.cfg.debounceMs;return!this.lit&&t>=this.cfg.enter&&r?(this.lit=!0,this.lastEdgeMs=e,"entered"):this.lit&&t<=this.cfg.exit&&r?(this.lit=!1,this.lastEdgeMs=e,"exited"):null}get isLit(){return this.lit}reset(){this.lit=!1,this.lastEdgeMs=-1/0}};var Za={strengthen:1.5,decay:.3,remember:.2},to=n=>n<0?0:n>1?1:n;function ms(n,t,e,r,s=Za){n.active=t,n.tension=to(e),n.strength=to(n.strength+(t?s.strengthen:-s.decay)*r),n.memory=to(n.memory+(t?s.remember:-s.remember*.5)*r)}function gs(n,t,e=Math.random){let r=[],s=t.absorbR+6;for(let i of n){if(i.cap!==t)continue;let l=e()*Math.PI*2,d=4+e()*3;i.cap=null,i.x=t.cx+Math.cos(l)*s,i.y=t.cy+Math.sin(l)*s,i.vx=Math.cos(l)*d,i.vy=Math.sin(l)*d,i.z&&(i.z=0),i.vz&&(i.vz=0),i.heat=1,i.age=void 0,r.push(i)}return t.accreted=0,r}function eo(n){if(n.capacity<=0)return 0;let t=n.accreted/n.capacity;return t<0?0:t>1?1:t}function xs(n,t){return t&&!n?{fire:"captured",armed:!0}:!t&&n?{fire:"released",armed:!1}:{fire:null,armed:n}}function vs(n,t){let e=[];for(let r of n)r.when!=="active"||!r.tokens.includes("sink")||(r.wasOn&&!r.on&&r.accreted>0&&(t(r),e.push(r)),r.wasOn=r.on);return e}function no(n,t){let e=t.cx-n.x,r=t.cy-n.y;return e*e+r*r<t.absorbR*t.absorbR}function bs(n,t,e=.14){let r=n+(t-n)*e;return r<.001?0:r>.999?1:r}function ws(n,t,e,r){let s=n.x+t.x,i=n.y+t.y,l=t.x+(e.x-s)*r,d=t.y+(e.y-i)*r,m=1-r;return{tx:l,ty:d,scale:m,opacity:m}}function tc(n){let t=0;for(let e of n)t+=.5*(e.m||1)*(e.vx*e.vx+e.vy*e.vy+(e.vz??0)*(e.vz??0));return t}function ec(n){let t=0;for(let e of n)t+=e.heat;return t}function Ms(n){let t=tc(n),e=ec(n);return{kinetic:t,thermal:e,total:t+e,count:n.length}}var nc={neutral:{vx:0,vy:0,charge:0,m:1,heat:0},positive:{vx:1,vy:0,charge:1,m:1,heat:0},negative:{vx:1,vy:0,charge:-1,m:1,heat:0},still:{vx:0,vy:0,charge:1,m:1,heat:0},fast:{vx:6,vy:0,charge:1,m:1,heat:0},hot:{vx:0,vy:0,charge:0,m:1,heat:1},massive:{vx:0,vy:0,charge:0,m:6,heat:0}};function oc(n,t,e){let r=n.cx-t,s=n.cy-e;return{dx:r,dy:s,dist:Math.max(Math.hypot(r,s),1),form:{},c:12,G:1,t:0}}function oo(n,t,e,r,s,i=nc.neutral){let l=ir(),d=oc(e,r,s);d.accum=l;for(let m of t){let b=n[m];if(!b)continue;let p={x:r,y:s,vx:i.vx,vy:i.vy,charge:i.charge,m:i.m,heat:i.heat,size:1,cap:null};try{Ln(b,e,p,d)}catch{}}return l}var Qe={x:0,y:0},gt=[0,0,0];function ro(n){if(!n)return{};let t={};return n.allowBodyDataInSnapshots!=null&&(t.allowBodyDataInSnapshots=n.allowBodyDataInSnapshots),n.allowMotionProjection!=null&&(t.allowMotionProjection=n.allowMotionProjection),n.maxMotionBudget!=null&&(t.maxMotionBudget=n.maxMotionBudget),n.budgets&&(t.budgets={...n.budgets}),t}function rc(n){let t={debug:{includeParticles:!0,includeRelationships:!0,includeData:!0,includeInfluences:!0},agent:{includeParticles:!1,includeRelationships:!0,includeData:!1,includeInfluences:!0},"bug-report":{includeParticles:!1,includeRelationships:!0,includeData:!1,includeInfluences:!0},public:{includeParticles:!1,includeRelationships:!1,includeData:!1,includeInfluences:!1}},e=n.profile;if(!e)return{includeParticles:n.includeParticles===!0,includeRelationships:n.includeRelationships!==!1,includeData:n.includeData===!0,includeInfluences:n.includeInfluences===!0};let r=t[e];return{includeParticles:r.includeParticles&&n.includeParticles!==!1,includeRelationships:r.includeRelationships&&n.includeRelationships!==!1,includeData:r.includeData&&n.includeData!==!1,includeInfluences:r.includeInfluences&&n.includeInfluences!==!1}}function Ze(n,t){let e={body:"bodies",relationship:"relationships",influence:"influences",projection:"projections"};for(let r of t){let s=r.indexOf(".");if(s<0){delete n[r];continue}let i=r.slice(0,s),l=r.slice(s+1),d=e[i];if(d&&Array.isArray(n[d]))for(let m of n[d])m&&typeof m=="object"&&delete m[l];else if(i==="metrics"&&n.metrics&&typeof n.metrics=="object")delete n.metrics[l];else{let m=n[i];m&&typeof m=="object"&&delete m[l]}}return n}function tn(n,t={}){let e=null;if((t.render??"none")!=="none"&&(e=n.getContext("2d"),!e))throw new Error("Fundamental: 2D canvas context unavailable");let r=t.overlayCanvas??null,s=e?r?.getContext("2d")??null:null,i=t.overlayBackend??(r&&s?Qn(r,s):null);function l(){i||(!r&&t.overlayCanvasProvider&&(r=t.overlayCanvasProvider()??null),!(!r||!e)&&(s??(s=r.getContext("2d")),s&&(i=t.overlayBackend??Qn(r,s),i.size(L,R,T.viewport().dpr))))}let d=new qe,m=1,b=new Map,p=lr(),M=new Map,z=o=>(M.get(o)?.size??0)>0;function E(o,a){let c=M.get(o);if(c)for(let v of c)v(a)}let A=new Ye;function P(o,a){z(o)&&A.record(o,a)}function B(){A.flush(E)}let I=new WeakMap,G=new Map,J=new Map;function h(o){let a=z("enter")||z("exit"),c=z("met");if(!a&&!c)return;for(let g=0;g<o.length;g++){let w=o[g];if(a){let y=G.get(w);y||G.set(w,y=new Set);let u=w.range*w.range;for(let f=0;f<o.length;f++){if(g===f)continue;let x=o[f],F=x.cx-w.cx,k=x.cy-w.cy,S=F*F+k*k<u;S&&!y.has(x)?(y.add(x),z("enter")&&P("enter",{body:w,other:x})):!S&&y.has(x)&&(y.delete(x),z("exit")&&P("exit",{body:w,other:x}))}}if(c){let y=J.get(w);y||J.set(w,y=new Set);for(let u=g+1;u<o.length;u++){let f=o[u],x=Math.abs(f.cx-w.cx)<w.hw+f.hw&&Math.abs(f.cy-w.cy)<w.hh+f.hh;x&&!y.has(f)?(y.add(f),P("met",{a:w,b:f})):!x&&y.has(f)&&y.delete(f)}}}let v=new Set(o);for(let g of[G,J])for(let w of g.keys())v.has(w)||g.delete(w)}let X=[],bt=new WeakMap,tt=[],we=0,Vt=new WeakMap,Me=new WeakMap,$t=new Map,q=new Map;if(dr(p),ur(p),pr(p),!t.host)throw new Error("Fundamental: createField requires opts.host. Use @fundamental-engine/vanilla (createField/mountField) or @fundamental-engine/elements / @fundamental-engine/react, or pass browserHost() from @fundamental-engine/dom.");let T=t.host,H=[],et=()=>T.reducedMotion?.()??!1,nt=ro(t.policy),wt=()=>{if(et())return 0;let o=1;return nt.allowMotionProjection===!1?0:(nt.maxMotionBudget!=null&&(o=Math.min(o,nt.maxMotionBudget)),nt.budgets?.motion!=null&&(o=Math.min(o,nt.budgets.motion)),Math.max(0,Math.min(1,o)))},ut=wt()<=0,zt=.5,Xt=()=>{if(nt.allowBodyDataInSnapshots===!1)return!1;let o=nt.budgets?.privacy;return!(o!=null&&o<zt)},It=Rn[t.theme??Pn]??Rn[Pn],C={accent:t.accent??Be(t.palette)[0]??An[0]??"#4da3ff",density:t.density&&t.density>0?t.density:1,render:t.render??"none",waves:t.waves??!1,waveStyle:t.waveStyle??"linear",waveCenter:t.waveCenter??null,background:t.background??"opaque",mass:t.mass??!1,reaction:t.reaction??!1,separation:t.separation!=null&&t.separation>=0?t.separation:0,ambientOrbit:t.ambientOrbit!=null&&t.ambientOrbit>=0?t.ambientOrbit:pe.ambient.preset.orbit,ambientWander:t.ambientWander!=null&&t.ambientWander>=0?t.ambientWander:pe.ambient.preset.wander,attention:t.attention??!1,causality:t.causality??!1,heatmap:t.heatmap??!1,overlay:t.overlay??"off",gridWarp:t.gridWarp!=null&&t.gridWarp>=0?t.gridWarp:1,gridIntensity:t.gridIntensity!=null&&t.gridIntensity>=0?Math.min(t.gridIntensity,1):.16,gradientCool:t.gradientCool?mt(t.gradientCool):It.cool,gradientWarm:t.gradientWarm?mt(t.gradientWarm):It.warm,waveBaseline:(t.waveBaseline??It.wave).map(mt),dprCap:t.dprCap&&t.dprCap>0?t.dprCap:2,depth:t.depth&&t.depth>0?t.depth:0,heatCenterX:t.heatCenter&&Number.isFinite(t.heatCenter.x)?t.heatCenter.x:.5,heatCenterY:t.heatCenter&&Number.isFinite(t.heatCenter.y)?t.heatCenter.y:.4,redshiftObserverX:t.redshiftObserver&&Number.isFinite(t.redshiftObserver.x)?t.redshiftObserver.x:.5,redshiftObserverY:t.redshiftObserver&&Number.isFinite(t.redshiftObserver.y)?t.redshiftObserver.y:.5,depthFocal:t.depthFocal!=null&&t.depthFocal>0?t.depthFocal:480,heatmapFadeStart:t.heatmapFade&&Number.isFinite(t.heatmapFade.start)?t.heatmapFade.start:.3,heatmapFadeSpan:t.heatmapFade&&Number.isFinite(t.heatmapFade.span)&&t.heatmapFade.span>0?t.heatmapFade.span:.85,integrator:t.integrator==="fixed"||t.integrator==="velocity-verlet"?t.integrator:"legacy",feedbackSink:t.feedbackSink??Zn},ct=null,_=[],L=0,R=0,Z=0,ot=0,Qt=!1,de=1,fe=0,co=new WeakMap,Kt=0,Dt=0,lo=!0,sn={...pe.ambient.preset,orbit:C.ambientOrbit,wander:C.ambientWander},fo={...sn},an="ambient",Cs=0,uo=t.identify,cn=o=>{if(o.identity)return o.identity;let a;return uo&&o.el&&(a=uo(o.el)),a||(a={id:(o.el&&o.el.id?o.el.id:void 0)??`body-${Cs++}`}),o.identity=a,a},Zt=o=>cn(o).id,ho=o=>{let a={density:o.d,count:o.count,engaged:o.on?1:0};o.attn!==void 0&&(a.attention=o.attn),o.capacity>0&&(a.load=o.accreted/o.capacity);let c=o.metrics?{entropy:o.metrics.entropy,coherence:o.metrics.coherence,temperature:o.metrics.temperature}:{};return{metrics:a,dimensions:c}},Os=0,_t=new Map,Rs=o=>({id:o.id,label:o.label,channels:o.channels.slice(),surfaces:o.surfaces.slice(),...o.reducedMotionEquivalent!==void 0?{reducedMotionEquivalent:o.reducedMotionEquivalent}:{},...o.accessibilityEquivalent!==void 0?{accessibilityEquivalent:o.accessibilityEquivalent}:{}}),ke=()=>[..._t.values()].map(Rs),Se=[];function Ps(){for(let o of Se)_t.get(o.id)?.apply?.(o.source(),o.target)}let $s={register(o){return _t.set(o.id,o),()=>{_t.get(o.id)===o&&_t.delete(o.id)}},unregister(o){_t.delete(o)},get(o){return _t.get(o)},list:ke,apply(o,a,c){_t.get(o)?.apply?.(a,c)},bind(o,a,c){let v={id:o,target:a,source:c};return Se.push(v),()=>{let g=Se.indexOf(v);g>=0&&Se.splice(g,1)}},lint:()=>gr(ke())},yo=.9,po=8,Is=4800,mo=.02;function Ds(){for(let o of _){if(o.authority!=="dynamic"||!o.vis)continue;o.bx===void 0&&(o.bx=o.cx,o.by=o.cy,o.bvx=0,o.bvy=0);let a=o.bx??o.cx,c=o.by??o.cy,v=_.filter(S=>S!==o&&S.vis&&S.tokens.length>0),{fx:g,fy:w}=Gt(v,p.forces,W,a,c);if(C.mass){let S=o.hw*2*(o.hh*2);o.inertia=Math.min(4,Math.max(.4,Math.sqrt(S/Is)))}let y=1/Math.max(o.inertia??o.M,1e-4),u=0,f=0;if(C.reaction&&o.tokens.length>0){let S=o.range*o.range,O=[o];for(let N of d.particles){if(N.cap)continue;let $=N.x-a,j=N.y-c;if($*$+j*j>S)continue;let K=Gt(O,p.forces,W,N.x,N.y);u-=K.fx,f-=K.fy}}let x=(o.bvx??0)+(g+u*mo)*y*W.dt,F=(o.bvy??0)+(w+f*mo)*y*W.dt;x*=yo,F*=yo;let k=Math.hypot(x,F);if(k>po){let S=po/k;x*=S,F*=S}o.bvx=x,o.bvy=F,o.bx=a+x*W.dt,o.by=c+F*W.dt,o.cx=o.bx,o.cy=o.by}}let go=globalThis.structuredClone,Ns=o=>{if(o==null)return o;try{return go?go(o):JSON.parse(JSON.stringify(o))}catch{try{return JSON.parse(JSON.stringify(o))}catch{return o}}},vt=[],Wt=[],xo=0,Jt=null,ht=t.rng??Math.random,ln=t.now??(()=>performance.now()),it=ut?1:0,dn=NaN,Nt=null,ue=null,te=null,qt=0,Bt=0,Ee=null,fn=[],un=null,ze=null,Bs=Math.round(130*C.density)*4,xt={x:0,y:0,k:0},yt=null,Lt=null,vo=0,bo=0,wo=Be(t.palette).map(mt),lt=mt(C.accent),Fe=null,hn=[],jt=[],ee=[],ne=[],yn=[],pn=[],oe=[],Te=new Ve,mn=!1,gn=()=>{mn||(mn=!0,queueMicrotask(()=>{mn=!1,Ce()}))},Ls=o=>{for(let a of["--d","--field-density","--load","--entropy","--coherence","--temperature"])o.style.removeProperty(a)},_s=o=>{let a=o.detail;a?.element&&(Te.register(a),gn())},Ws=o=>{let a=o.detail;a?.element&&(Te.unregister(a.element),Ls(a.writeTarget??a.element),gn())},qs=gn,Ct={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null},Mo=ln(),W={dx:0,dy:0,dz:0,dist:1,form:{...sn},W:0,H:0,D:C.depth,integrator:C.integrator,t:0,frameN:0,dt:ut?0:1,c:12,G:1,scrollV:0,rng:ht,spark:(o,a,c,v)=>ko(o,a,c,v),supernova:o=>{let a=gs(d.particles,o,ht),c=new Set(a);for(let v of d.particles){if(c.has(v))continue;let g=v.x-o.cx,w=v.y-o.cy,y=Math.hypot(g,w)||1;if(y<320){let u=(1-y/320)*4;v.vx+=g/y*u,v.vy+=w/y*u,v.heat=Math.max(v.heat,.8)}}Hn(Wt,vt,o.cx,o.cy,320,L,R,W.t,v=>void d.add(re(v))),Qs(o),xn(o.el,"field:saturated",{peak:a.length}),o.el.dataset.fxCap==="1"&&(o.el.dataset.fxCap="0",se(o.el,"released",{accreted:0,load:0}),z("released")&&P("released",{body:o,count:a.length}),I.delete(o))},spawn:o=>{d.size>=Bs||d.add(re(o))},neighbors:(o,a)=>d.neighbors(o,a),grid:o=>{let a=b.get(o);if(!a){let c=o.startsWith("wave")?"wave":o.startsWith("memory")?"memory":"diffuse";a=new le(L,R,c),b.set(o,a)}return a}};function ko(o,a,c,v){if(ut||ne.length>260)return;let g=v?mt(v):[255,122,69],w=Er(c,ht);for(let y=0;y<w;y++){let u=ht()*6.28318,f=.8+ht()*(c>0?c:1)*1.7;ne.push({x:o,y:a,vx:Math.cos(u)*f,vy:Math.sin(u)*f,life:1,c:g})}}function re(o={}){let a=o.size??.7+ht()*1.8;return{id:o.id??m++,x:o.x??ht()*L,y:o.y??ht()*R,vx:o.vx??(ht()-.5)*.25,vy:o.vy??(ht()-.5)*.18,z:o.z??(C.depth>0?ht()*C.depth:0),vz:o.vz??(C.depth>0?(ht()-.5)*.18:0),m:o.m??(C.mass?a:1),heat:o.heat??0,size:a,gx:o.gx??ht(),gy:o.gy??ht(),gz:o.gz??ht(),cap:null,...o.age!=null?{age:o.age}:{},...o.color!=null?{color:o.color}:{},...o.species!=null?{species:o.species}:{}}}let Ae=[];function js(){if(!Ae.length)return;let o=d.particles;for(let a=0;a<o.length;a++){let c=Ae[a%Ae.length];o[a].atom=c;let v=typeof c.weight=="number"?Math.max(0,Math.min(1,c.weight)):.5;o[a].size*=.6+v*.9,o[a].m*=.6+v*1.2}}function So(){d.clear();let o=Math.round(130*C.density);for(let a=0;a<o;a++)d.add(re());js(),vt=C.waves?Qo(C.waveBaseline):[],Wt=C.waves?Zo(vt.length,C.density,ht):[],xo=Wt.length}function Ce(){let o=_,a=Ur(T.root);if(Te.size>0){let y=new Set(a.map(u=>u.el));_=a.concat(Te.bodies(xe).filter(u=>!y.has(u.el)))}else _=a;X.length>0&&(_=_.concat(X));let c=null,v=!1;if(o.length>0){let y=new Map;for(let f of o){let x=y.get(f.el);x?x.push(f):y.set(f.el,[f])}let u=new Map;for(let f of _){let x=y.get(f.el);if(!x)continue;let F=u.get(f.el)??0;u.set(f.el,F+1);let k=x[F];if(!k||k===f)continue;k.identity!==void 0&&(f.identity=k.identity),k.bx!==void 0&&(f.bx=k.bx,f.by=k.by,f.bvx=k.bvx,f.bvy=k.bvy),f.d=k.d,k.attn!==void 0&&(f.attn=k.attn),f.accreted=k.accreted,f.count=k.count,k.wasOn!==void 0&&(f.wasOn=k.wasOn);let S=Vt.get(k);S&&Vt.set(f,S);let O=I.get(k);O!==void 0&&I.set(f,O),(c??(c=new Map)).set(k,f),k.accreted>0&&(v=!0)}if(v)for(let f of d.particles){if(!f.cap)continue;let x=c.get(f.cap);x&&(f.cap=x)}}Ge(_,L,R,Z,ot),ti();let g=new Map(jt.map(y=>[y.el,y]));jt=[...T.root.querySelectorAll("[data-move]")].map(y=>{let u=y,f=u.getBoundingClientRect(),x=Number.parseFloat(u.dataset.mass??""),F=Number.isFinite(x)?x:Cr(f.width*f.height),k=(u.dataset.move??"").trim()==="layout",S=u.hasAttribute("data-dock"),O=u.hasAttribute("data-warp"),N=g.get(u);if(N){let $=N.docked?c?.get(N.docked)??N.docked:null;return{el:u,o:N.o,mEl:F,layout:k,dockable:S,dock:N.dock,docked:$,warpable:O,warpCool:N.warpCool}}return{el:u,o:{x:0,y:0,vx:0,vy:0},mEl:F,layout:k,dockable:S,dock:{dock:0},docked:null,warpable:O,warpCool:0}}),yn=[...T.root.querySelectorAll("[data-on]")].map(y=>{let u=y;return{el:u,body:_.find(f=>f.el===u)??null,bindings:Yn(u.dataset.on??"")}}),pn=[...T.root.querySelectorAll("[data-class]")].map(y=>{let u=y;return{el:u,body:_.find(f=>f.el===u)??null,bindings:Yn(u.dataset.class??"")}});for(let y of _){if(!y.pair)continue;let u=null;try{u=T.root.querySelector(y.pair)}catch{u=null}y.pairBody=u?_.find(f=>f.el===u):void 0}let w=new Map(ee.map(y=>[y.el,y]));for(let[y,u]of w)if(!T.root.contains(y))for(let f of u.emitted)f.remove();ee=[...T.root.querySelectorAll("[data-emit]")].map(y=>{let u=y,f=u.dataset.emit??"",x=null;try{x=f?T.root.querySelector(f):null}catch{x=null}let F=Math.max(0,Math.round(Number.parseFloat(u.dataset.max??"")||8)),k=w.get(u);if(k){let S=k.emitted.filter(O=>O.isConnected);for(;S.length>F;)S.pop().remove();return{el:u,tmpl:x,cap:F,emitted:S}}return{el:u,tmpl:x,cap:F,emitted:[]}})}function Hs(){for(let o of _)if(o.pairBody){if(!o.pairBody.el.isConnected){o.warpHas=!1,o.pairBody=void 0;continue}o.pairBody.vis?(o.warpX=o.pairBody.cx,o.warpY=o.pairBody.cy,o.warpHas=!0):o.warpHas=!1}else o.pair&&(o.warpHas=!1)}function Ys(){if(!(ee.length===0||W.frameN%30!==0))for(let o of ee){if(!o.tmpl||o.emitted.length>=o.cap)continue;let a=o.tmpl.cloneNode(!0);a.removeAttribute("id"),a.setAttribute("aria-hidden","true"),a.setAttribute("inert",""),a.dataset.fieldEmitted="",o.el.appendChild(a),o.emitted.push(a)}}function Us(){if(yn.length!==0)for(let o of yn){let a=o.body?{d:o.body.d,on:o.body.on,accreted:o.body.accreted}:{d:0,on:o.el.dataset.active==="1",accreted:0};for(let c of o.bindings){let v=Un(c.trigger,a);v&&!c.armed?(c.armed=!0,o.el.dispatchEvent(new CustomEvent(c.event,{bubbles:!0,detail:{trigger:c.trigger,d:a.d,on:a.on,accreted:a.accreted}}))):v||(c.armed=!1)}}}function Gs(){if(pn.length!==0)for(let o of pn){let a=o.body?{d:o.body.d,on:o.body.on,accreted:o.body.accreted}:{d:0,on:o.el.dataset.active==="1",accreted:0};for(let c of o.bindings){let v=Un(c.trigger,a);v&&!c.armed?(c.armed=!0,o.el.classList.add(c.event)):!v&&c.armed&&(c.armed=!1,o.el.classList.remove(c.event))}}}function se(o,a,c){o.dispatchEvent(new CustomEvent("field:"+a,{bubbles:!0,composed:!0,detail:c}))}function Vs(){for(let o of _){if(!o.vis||o.tokens.indexOf("sink")<0)continue;let a=o.el.dataset.fxCap==="1",c=xs(a,o.accreted>0);c.fire==="captured"?(o.el.dataset.fxCap="1",se(o.el,"captured",{accreted:o.accreted,load:eo(o)}),z("captured")&&P("captured",{body:o,count:o.accreted}),I.set(o,o.accreted)):c.fire==="released"&&(o.el.dataset.fxCap="0",se(o.el,"released",{accreted:0,load:0}),z("released")&&P("released",{body:o,count:I.get(o)??0}),I.delete(o))}}let Xs=[{metric:"density",enter:.6,exit:.2,rise:"field:entered",fall:"field:exited"},{metric:"attention",enter:1.5,exit:1.1,rise:"field:attention-shifted",fall:"field:attention-settled"},{metric:"entropy",enter:.7,exit:.4,rise:"field:entropy-warning",fall:"field:entropy-cleared"}],Ks=120;function xn(o,a,c){o.dispatchEvent(new CustomEvent(a,{bubbles:!0,composed:!0,detail:c}))}function Eo(o,a,c,v,g,w){let y=o.get(a);y||o.set(a,y=new Map);let u=y.get(v.metric);u||y.set(v.metric,u=new Je({enter:v.enter,exit:v.exit,debounceMs:Ks}));let f=u.update(g,w);f==="entered"?xn(c,v.rise,{metric:v.metric,value:g}):f==="exited"&&xn(c,v.fall,{metric:v.metric,value:g})}function Js(o){for(let a of _)if(!(!a.vis||a.tokens.length===0))for(let c of Xs){let v;switch(c.metric){case"density":v=a.d;break;case"attention":C.attention&&(v=a.attn??1);break;case"entropy":v=a.metrics?.entropy;break}v!==void 0&&Eo(Vt,a,a.el,c,v,o)}for(let a of tt)Eo(Me,a.agent,a.from.el,{metric:"memory",enter:.6,exit:.3,rise:"field:memory-threshold",fall:"field:memory-faded"},a.agent.memory,o)}function Qs(o){for(let a of jt)a.docked===o&&(a.docked=null,a.dock.dock=0,a.el.getAttribute("aria-hidden")==="true"&&a.el.removeAttribute("aria-hidden"),a.el.removeAttribute("inert"),a.el.style.opacity="",se(a.el,"released",{}))}function Zs(){if(jt.length===0)return;let o=jt.map(a=>{let c=a.el.getBoundingClientRect();return{x:c.left-Z+c.width/2,y:c.top-ot+c.height/2}});for(let a=0;a<jt.length;a++){let c=jt[a];if(!c.el.isConnected){c.docked&&(c.docked=null,c.dock.dock=0);continue}let v=o[a].x,g=o[a].y;if(c.docked){let x={x:v-c.o.x,y:g-c.o.y};c.dock.dock=bs(c.dock.dock,1);let F=ws(x,c.o,{x:c.docked.cx,y:c.docked.cy},c.dock.dock);c.el.style.transform=`translate(${F.tx.toFixed(2)}px, ${F.ty.toFixed(2)}px) scale(${F.scale.toFixed(3)})`,c.el.style.opacity=F.opacity.toFixed(3),c.dock.dock>=1&&c.el.getAttribute("aria-hidden")!=="true"&&(c.el.setAttribute("aria-hidden","true"),c.el.setAttribute("inert",""));continue}Ct.x=v,Ct.y=g,Ct.vx=0,Ct.vy=0,Ct.heat=0,Ct.cap=null;for(let x of _){if(!x.vis||x.tokens.length===0||x.el===c.el)continue;let F=x.cx-v,k=x.cy-g,S=Math.hypot(F,k);W.dx=F,W.dy=k,W.dist=S<1?1:S;for(let O of x.tokens)p.forces[O]?.apply(x,Ct,W)}Ct.cap=null;let w=Ar(c.o),y=Ct.vx+w.x,u=Ct.vy+w.y;if(c.layout){let x=Or({x:v,y:g},o,a),F=Rr((k,S)=>d.near(k,S,40).length,v,g,16,6);y+=x.x+F.x,u+=x.y+F.y}let f={x:v-c.o.x,y:g-c.o.y};if(Tr(c.o,y,u,c.mEl,.9),c.el.style.transform=`translate(${c.o.x.toFixed(2)}px, ${c.o.y.toFixed(2)}px)`,c.dockable){let x={x:f.x+c.o.x,y:f.y+c.o.y},F=_.find(k=>k.vis&&k.el!==c.el&&k.tokens.indexOf("sink")>=0&&no(x,k));F&&(c.docked=F,se(c.el,"captured",{sink:F.el}))}if(c.warpCool>0&&(c.warpCool-=1),c.warpable&&c.warpCool===0){let x={x:f.x+c.o.x,y:f.y+c.o.y},F=_.find(k=>k.vis&&k.el!==c.el&&k.warpHas&&k.tokens.indexOf("warp")>=0&&no(x,k));F&&(c.o.x=F.warpX-f.x,c.o.y=F.warpY-f.y,c.o.vx=0,c.o.vy=0,c.el.style.transform=`translate(${c.o.x.toFixed(2)}px, ${c.o.y.toFixed(2)}px)`,c.warpCool=45,se(c.el,"relocated",{from:F.el}))}}}function ti(){oe.length&&(oe=oe.filter(o=>o.el.isConnected?!0:(o.el.removeEventListener("pointerenter",o.enter),o.el.removeEventListener("pointerleave",o.leave),o.el.removeEventListener("focusin",o.enter),o.el.removeEventListener("focusout",o.leave),delete o.el.dataset.fxEngaged,!1))),T.root.querySelectorAll("[data-hot]").forEach(o=>{let a=o;if(a.dataset.fxEngaged==="1")return;a.dataset.fxEngaged="1";let c=()=>{a.dataset.active="1",Fe=a.dataset.color??null;let g=a.closest("[data-index][data-threads]");if(g){let w=[...g.querySelectorAll("[data-hot]")].filter(y=>y!==a);vn(w.map(y=>({a,b:y,color:a.dataset.color??void 0})))}},v=()=>{a.dataset.active="0",Fe=null,vn(null)};a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",v),a.addEventListener("focusin",c),a.addEventListener("focusout",v),oe.push({el:a,enter:c,leave:v})})}function vn(o){hn=(o??[]).map(a=>({a:a.a,b:a.b,c:mt(a.color??C.accent),seed:ht()*6.28}))}function ei(){if(hn.length===0)return;let o=W.t;e.globalCompositeOperation="lighter";for(let a of hn){let c=a.a.getBoundingClientRect(),v=a.b.getBoundingClientRect(),g=c.left-Z+c.width/2,w=c.top-ot+c.height/2,y=v.left-Z+v.width/2,u=v.top-ot+v.height/2,[f,x,F]=a.c;e.strokeStyle=`rgba(${f},${x},${F},0.22)`,e.lineWidth=1,e.beginPath(),e.moveTo(g,w),e.lineTo(y,u),e.stroke();for(let k=0;k<3;k++){let S=(o*.6+a.seed+k/3)%1,O=g+(y-g)*S,N=w+(u-w)*S;e.fillStyle=`rgba(${f},${x},${F},${(1-S)*.9})`,e.beginPath(),e.arc(O,N,2.2,0,6.28318),e.fill()}}e.globalCompositeOperation="source-over"}let Oe=0,ni=[1/0,1.5,1.25,1];function Re(o){if(!e)return;let a=Math.min(o||1,C.dprCap,ni[Oe]??1/0);n.width=Math.floor(L*a),n.height=Math.floor(R*a),n.style.width=L+"px",n.style.height=R+"px",e.setTransform(a,0,0,a,0,0),i?.size(L,R,a)}function zo(){let o=T.viewport();L=o.width,R=o.height,Z=o.originX??0,ot=o.originY??0,Qt=o.originX!=null||o.originY!=null,Re(o.dpr),W.W=L,W.H=R,de=(T.scrollHeight?.()??R)-R||1;for(let a of b.values())a.resize(L,R);C.heatmap&&(ct?ct.resize(L,R):ct=new ve(L,R)),So(),Ce()}function oi(){let o=W.t,a=16;if(C.waveStyle==="circular"){let c=Jt||{x:L/2,y:R/2},v=Math.min(L,R)*.48;for(let g of vt){let[w,y,u]=g.color;e.beginPath();let f=.08,x=!0;for(let S=0;S<=2*Math.PI+.01;S+=f){let O=me(g,S,o,v),N=c.x+Math.cos(S)*O,$=c.y+Math.sin(S)*O;x?(e.moveTo(N,$),x=!1):e.lineTo(N,$)}e.closePath();let F=g.baseFrac*v+g.offsetY,k=e.createRadialGradient(c.x,c.y,Math.max(0,F-g.amp),c.x,c.y,F+g.amp+80);k.addColorStop(0,`rgba(${w},${y},${u},${(.08+g.depth*.04)*it})`),k.addColorStop(1,`rgba(${w},${y},${u},0)`),e.fillStyle=k,e.fill()}e.globalCompositeOperation="lighter";for(let g of vt){let[w,y,u]=g.color;e.beginPath();let f=.08,x=!0;for(let F=0;F<=2*Math.PI+.01;F+=f){let k=me(g,F,o,v),S=c.x+Math.cos(F)*k,O=c.y+Math.sin(F)*k;x?(e.moveTo(S,O),x=!1):e.lineTo(S,O)}e.closePath(),e.lineWidth=5,e.strokeStyle=`rgba(${w},${y},${u},${(.05+g.depth*.04)*it})`,e.stroke(),e.lineWidth=1.2,e.strokeStyle=`rgba(${w},${y},${u},${(.3+g.depth*.22)*it})`,e.stroke()}e.globalCompositeOperation="source-over"}else{for(let c of vt){let[v,g,w]=c.color;e.beginPath(),e.moveTo(0,Et(c,0,o,R,1,1,xt));for(let f=0;f<=L;f+=a)e.lineTo(f,Et(c,f,o,R,1,1,xt));e.lineTo(L,R),e.lineTo(0,R),e.closePath();let y=c.baseFrac*R+c.offsetY-c.amp,u=e.createLinearGradient(0,y,0,y+320);u.addColorStop(0,`rgba(${v},${g},${w},${(.11+c.depth*.05)*it})`),u.addColorStop(1,`rgba(${v},${g},${w},0)`),e.fillStyle=u,e.fill()}e.globalCompositeOperation="lighter";for(let c of vt){let[v,g,w]=c.color;e.beginPath(),e.moveTo(0,Et(c,0,o,R,1,1,xt));for(let y=0;y<=L;y+=a)e.lineTo(y,Et(c,y,o,R,1,1,xt));e.lineWidth=5,e.strokeStyle=`rgba(${v},${g},${w},${(.05+c.depth*.04)*it})`,e.stroke(),e.lineWidth=1.2,e.strokeStyle=`rgba(${v},${g},${w},${(.3+c.depth*.22)*it})`,e.stroke()}e.globalCompositeOperation="source-over"}}function ri(){e.globalCompositeOperation="lighter";let o=W.t,a=0;if(C.waveStyle==="circular"){let c=Jt||{x:L/2,y:R/2},v=Math.min(L,R)*.48;for(let g of Wt){let w=vt[g.wi];if(!w){a++;continue}W.dt&&(g.progress+=g.speed,g.progress>1?g.progress-=1:g.progress<0&&(g.progress+=1));let y=g.progress*2*Math.PI,u=me(w,y,o,v)+g.phase*32,f=c.x+Math.cos(y)*u,x=c.y+Math.sin(y)*u,[F,k,S]=w.color,O=g.glow?.6+.4*Math.sin(o*2.2+a):.85;g.glow&&(e.fillStyle=`rgba(${F},${k},${S},${.16*O*it})`,e.beginPath(),e.arc(f,x,g.size+2.5,0,6.28318),e.fill()),e.fillStyle=`rgba(${F},${k},${S},${O*it})`,e.beginPath(),e.arc(f,x,g.size,0,6.28318),e.fill(),a++}}else for(let c of Wt){let v=vt[c.wi];if(!v){a++;continue}W.dt&&(c.progress+=c.speed,c.progress>1?c.progress-=1:c.progress<0&&(c.progress+=1));let g=c.progress*L,w=Et(v,g,o,R,1,1,xt)+c.phase*32,[y,u,f]=v.color,x=c.glow?.6+.4*Math.sin(o*2.2+a):.85;c.glow&&(e.fillStyle=`rgba(${y},${u},${f},${.16*x*it})`,e.beginPath(),e.arc(g,w,c.size+2.5,0,6.28318),e.fill()),e.fillStyle=`rgba(${y},${u},${f},${x*it})`,e.beginPath(),e.arc(g,w,c.size,0,6.28318),e.fill(),a++}e.globalCompositeOperation="source-over"}function si(){if(!C.attention)return;for(let c of _)c.attn=1;let o=_.filter(c=>c.vis&&c.tokens.length>0);if(o.length===0)return;let a=Uo(o);for(let c=0;c<o.length;c++)o[c].attn=a[c]}function ii(){if(!C.causality)return;let o=_.filter(c=>c.vis&&c.tokens.length>0);if(o.length===0)return;if(o.length===1){Fo(o[0],o[0].d);return}let a=Go(o.map(c=>({d:c.d,cx:c.cx,cy:c.cy})));for(let c=0;c<o.length;c++)Fo(o[c],pt(o[c].d+a[c],0,1))}function Fo(o,a){C.feedbackSink(o.el,{lit:a})}function ai(){for(let o of _){if(!o.feedback)continue;let a=Ho(o.count,o.on);o.d+=(a-o.d)*.08;let c=o.writeTarget??o.el;if(o.fmax){let f=Yo(o.fmin,o.fmax,o.d);co.get(c)!==f&&(co.set(c,f),c.style.fontVariationSettings=`"wght" ${f}`+(o.opsz?`, "opsz" ${o.opsz}`:""))}let v=ct?ct.norm(o.cx,o.cy):void 0,g=o.tokens.indexOf("sink")>=0&&o.capacity>0?eo(o):void 0,w=Nr(o.thermo),y=o.metrics??(o.metrics={entropy:0,coherence:1,temperature:0});y.entropy+=(w.entropy-y.entropy)*.08,y.coherence+=(w.coherence-y.coherence)*.08,y.temperature+=(w.temperature-y.temperature)*.08;let u={density:o.d,heatmapDensity:v,load:g,entropy:y.entropy,coherence:y.coherence,temperature:y.temperature};C.feedbackSink(c,u),o.onFeedback?.(u)}}function ci(){if(ne.length!==0){e.globalCompositeOperation="lighter";for(let o=ne.length-1;o>=0;o--){let a=ne[o];if(!a)continue;if(a.x+=a.vx,a.y+=a.vy,a.vx*=.9,a.vy*=.9,a.life*=.85,a.life<.05){ne.splice(o,1);continue}let[c,v,g]=a.c;e.fillStyle=`rgba(${c},${v},${g},${.18*a.life})`,e.beginPath(),e.arc(a.x,a.y,2+a.life*4,0,6.28318),e.fill(),e.fillStyle=`rgba(${c},${v},${g},${a.life})`,e.beginPath(),e.arc(a.x,a.y,.6+a.life*1.5,0,6.28318),e.fill()}e.globalCompositeOperation="source-over"}}let Ht=null,Pe=null,ie=null;function li(){if(!ct)return;let o=R>0?pt((C.heatmapFadeStart+C.heatmapFadeSpan-fe/R)/C.heatmapFadeSpan,0,1):1;if(o<=.01)return;let a=ct.cell,c=Math.max(1,Math.ceil(L/a)),v=Math.max(1,Math.ceil(R/a));if(!Ht){if(!T.createCanvas)throw new Error("Fundamental: this FieldHost provides no createCanvas() \u2014 the heatmap layer needs one. Use render:'none' (signals-first) or supply a host with a createCanvas capability.");Ht=T.createCanvas(),Pe=Ht.getContext("2d")}if(Pe){if((Ht.width!==c||Ht.height!==v)&&(Ht.width=c,Ht.height=v,ie=null),ie===null||Dt%3===0){ie===null&&(ie=Pe.createImageData(c,v));let g=lt,w=ie.data;for(let y=0;y<v;y++)for(let u=0;u<c;u++){let f=ct.norm(u*a+a/2,y*a+a/2),x=(y*c+u)*4;w[x]=g[0],w[x+1]=g[1],w[x+2]=g[2],w[x+3]=Math.round(pt(f*.5*it,0,1)*255)}Pe.putImageData(ie,0,0)}e.globalCompositeOperation="lighter",e.imageSmoothingEnabled=!0,e.globalAlpha=o,e.drawImage(Ht,0,0,L,R),e.globalAlpha=1,e.globalCompositeOperation="source-over"}}function di(){C.background==="transparent"?C.render==="trails"?(e.globalCompositeOperation="destination-out",e.fillStyle="rgba(0,0,0,0.22)",e.fillRect(0,0,L,R),e.globalCompositeOperation="source-over"):e.clearRect(0,0,L,R):(C.render==="trails"?e.fillStyle="rgba(5,6,11,0.22)":e.fillStyle="rgb(5,6,11)",e.fillRect(0,0,L,R)),oi(),ct&&Oe<2&&li(),ri();let o=C.render!=="metaballs"&&C.render!=="streamlines"&&C.render!=="knockout"&&C.render!=="redshift"&&C.render!=="blackbody"&&C.render!=="depth";e.globalCompositeOperation="lighter";let a=lt,c=L*C.heatCenterX,v=R*C.heatCenterY,g=Math.hypot(Math.max(c,L-c),Math.max(v,R-v))||1;if(ze===null||Dt%6===0){ze=[];for(let y of _){if(!y.tint)continue;let u=(y.range||200)*1.4;ze.push({b:y,r2:u*u,rgb:mt(y.tint)})}}let w=ze;if(o)for(let y of d.particles){if(y.cap){e.fillStyle=`rgba(${a[0]},${a[1]},${a[2]},${.55*it})`,e.beginPath(),e.arc(y.x,y.y,1.3,0,6.28318),e.fill();continue}let u=Math.min(1,Math.hypot(y.x-c,y.y-v)/g),f=u*u,x=y.heat;$n(gt,f,x,a,C.gradientCool,C.gradientWarm);let F=gt[0],k=gt[1],S=gt[2];if(w.length){let dt=0,Q=null;for(let rt of w){let Mt=y.x-rt.b.cx,kt=y.y-rt.b.cy,Yt=Mt*Mt+kt*kt;if(Yt>=rt.r2)continue;let D=1-Math.sqrt(Yt/rt.r2);D>dt&&(dt=D,Q=rt.rgb)}if(Q){let rt=dt*.7;F+=(Q[0]-F)*rt,k+=(Q[1]-k)*rt,S+=(Q[2]-S)*rt}}if(y.color){let[dt,Q,rt]=mt(y.color);F+=(dt-F)*.75,k+=(Q-k)*.75,S+=(rt-S)*.75}let O=C.depth>0?1-Math.min(Math.abs(y.z??0)/C.depth,1)*.55:1,N=(y.size*(1-.4*f)+x*2)*O,$=pt((.5-.3*f+x*.5)*it*O,0,1),j=F|0,K=k|0,ft=S|0;e.fillStyle=`rgba(${j},${K},${ft},${.12*$})`,e.beginPath(),e.arc(y.x,y.y,N+1.2,0,6.28318),e.fill(),e.fillStyle=`rgba(${j},${K},${ft},${$})`,e.beginPath(),e.arc(y.x,y.y,N,0,6.28318),e.fill()}if(ci(),ei(),e.globalCompositeOperation="source-over",C.render==="links"){e.globalCompositeOperation="lighter";let y=lt,u=90;e.lineWidth=.6;for(let f of d.particles)if(!f.cap)for(let x of d.neighbors(f,u)){if(x.x<f.x||x.x===f.x&&x.y<f.y)continue;let F=Qr(Math.hypot(x.x-f.x,x.y-f.y),u);F<=0||(e.strokeStyle=`rgba(${y[0]},${y[1]},${y[2]},${F})`,e.beginPath(),e.moveTo(f.x,f.y),e.lineTo(x.x,x.y),e.stroke())}e.globalCompositeOperation="source-over"}if(C.render==="metaballs"){let x=Math.ceil(L/16)+1,F=Math.ceil(R/16)+1;!Nt||Nt.length!==x*F?Nt=new Float32Array(x*F):Nt.fill(0);for(let S of d.particles)S.cap||Kn(Nt,x,F,16,S.x,S.y,34,1);let k=lt;e.globalCompositeOperation="lighter",e.strokeStyle=`rgba(${k[0]},${k[1]},${k[2]},${.5*it})`,e.lineWidth=1.4,e.lineCap="round",e.beginPath();for(let S=0;S<F-1;S++)for(let O=0;O<x-1;O++){let N=Nt[S*x+O],$=Nt[S*x+O+1],j=Nt[(S+1)*x+O+1],K=Nt[(S+1)*x+O],ft=Xn(N,$,j,K,.9);if(!ft.length)continue;let dt=O*16,Q=S*16;for(let rt of ft)e.moveTo(dt+rt.x1*16,Q+rt.y1*16),e.lineTo(dt+rt.x2*16,Q+rt.y2*16)}e.stroke(),e.globalCompositeOperation="source-over"}if(C.render==="voronoi"){let f=Math.ceil(L/18)+1,x=Math.ceil(R/18)+1;(!ue||ue.length!==f*x)&&(ue=new Int32Array(f*x));let F=d.particles,k=new Map;for(let O=0;O<F.length;O++)k.set(F[O],O);for(let O=0;O<x;O++)for(let N=0;N<f;N++){let $=N*18,j=O*18,K=d.near($,j,54),ft=-1;if(K.length){let dt=Zr($,j,K);dt>=0&&(ft=k.get(K[dt])??-1)}ue[O*f+N]=ft}let S=lt;e.globalCompositeOperation="lighter",e.strokeStyle=`rgba(${S[0]},${S[1]},${S[2]},${.32*it})`,e.lineWidth=1,e.beginPath();for(let O of fs(ue,f,x))e.moveTo(O.x1*18,O.y1*18),e.lineTo(O.x2*18,O.y2*18);e.stroke(),e.globalCompositeOperation="source-over"}if(C.render==="knockout"){let y=lt;e.fillStyle=`rgba(${y[0]},${y[1]},${y[2]},${.22*it})`,e.fillRect(0,0,L,R),e.globalCompositeOperation="destination-out";for(let u of d.particles){if(u.cap)continue;let f=C.depth>0?1-Math.min(Math.abs(u.z??0)/C.depth,1)*.55:1,x=ts(u.size,u.heat,f);e.fillStyle=`rgba(0,0,0,${.38*it})`,e.beginPath(),e.arc(u.x,u.y,x+2.2,0,6.28318),e.fill(),e.fillStyle=`rgba(0,0,0,${it})`,e.beginPath(),e.arc(u.x,u.y,x,0,6.28318),e.fill()}e.globalCompositeOperation="source-over"}if(C.render==="redshift"){e.globalCompositeOperation="lighter";let y=L*C.redshiftObserverX,u=R*C.redshiftObserverY;for(let f of d.particles){if(f.cap)continue;let x=0;for(let $ of _){let j=$.range||200,K=f.x-$.cx,ft=f.y-$.cy,dt=os(K*K+ft*ft,j*j);dt>x&&(x=dt)}let F=rs(ns(es(f.x,f.y,f.vx,f.vy,y,u),W.c),x);ss(gt,F);let k=C.depth>0?1-Math.min(Math.abs(f.z??0)/C.depth,1)*.55:1,S=F<0?-F:F,O=(f.size+S*1.6)*k,N=pt((.4+.45*S)*it*k,0,1);e.fillStyle=`rgba(${gt[0]|0},${gt[1]|0},${gt[2]|0},${N})`,e.beginPath(),e.arc(f.x,f.y,O,0,6.28318),e.fill()}e.globalCompositeOperation="source-over"}if(C.render==="blackbody"){e.globalCompositeOperation="lighter";for(let y of d.particles){if(y.cap)continue;let u=is(y.vx,y.vy,y.heat,W.c);as(gt,u);let f=C.depth>0?1-Math.min(Math.abs(y.z??0)/C.depth,1)*.55:1,x=(y.size+u*2.2)*f,F=pt((.16+.84*u)*it*f,0,1),k=gt[0]|0,S=gt[1]|0,O=gt[2]|0;e.fillStyle=`rgba(${k},${S},${O},${.14*F})`,e.beginPath(),e.arc(y.x,y.y,x+1.4+u*2,0,6.28318),e.fill(),e.fillStyle=`rgba(${k},${S},${O},${F})`,e.beginPath(),e.arc(y.x,y.y,x,0,6.28318),e.fill()}e.globalCompositeOperation="source-over"}if(C.render==="depth"){let y=d.particles,u=y.length;(!te||te.length!==u)&&(te=new Array(u));for(let k=0;k<u;k++)te[k]=k;te.sort((k,S)=>Math.abs(y[S].z??0)-Math.abs(y[k].z??0));let f=C.depthFocal,x=L/2,F=R/2;for(let k=0;k<u;k++){let S=y[te[k]];if(S.cap)continue;let O=S.z??0,N=C.depth>0?Math.min(Math.abs(O)/C.depth,1):0,$=cs(O,f),j=Jn(S.x,x,$),K=Jn(S.y,F,$),ft=Math.min(1,Math.hypot(j-c,K-v)/g),dt=ft*ft,Q=S.heat;$n(gt,dt,Q,a,C.gradientCool,C.gradientWarm);let rt=(S.size*(1-.4*dt)+Q*2)*$,Mt=pt((.5-.3*dt+Q*.5)*it*ls(N),0,1),kt=gt[0]|0,Yt=gt[1]|0,D=gt[2]|0;e.fillStyle=`rgba(${kt},${Yt},${D},${.12*Mt})`,e.beginPath(),e.arc(j,K,rt+1.2+ds(N),0,6.28318),e.fill(),e.fillStyle=`rgba(${kt},${Yt},${D},${Mt})`,e.beginPath(),e.arc(j,K,rt,0,6.28318),e.fill()}}if(C.render==="streamlines"||C.render==="flow"){let u=lt;if(e.lineWidth=1,e.lineCap="round",Ee===null||yt||Dt%3===0){let f=[],x=[],F=0;for(let k=46/2;k<L;k+=46)for(let S=46/2;S<R;S+=46){let{fx:O,fy:N}=Gt(_,p.forces,W,k,S);if(yt){let j=ge(Qe,k,S,yt,.04);O+=j.x,N+=j.y}let $=Math.hypot(O,N);if(!($>1e-9)){x.push({gx:k,gy:S});continue}f.push({gx:k,gy:S,ux:O/$,uy:N/$,mag:$}),$>F&&(F=$)}qt===0?qt=F:qt=F>qt?qt*.7+F*.3:qt*.9+F*.1,Ee=f,fn=x}if(fn.length){e.fillStyle=`rgba(${u[0]},${u[1]},${u[2]},0.05)`;for(let f of fn)e.fillRect(f.gx-.5,f.gy-.5,1,1)}if(qt>0&&Ee)for(let f of Ee){let x=Math.sqrt(f.mag/qt),F=46*.46*(.28+.72*x),k=f.gx+f.ux*F,S=f.gy+f.uy*F;e.strokeStyle=`rgba(${u[0]},${u[1]},${u[2]},${pt(.1+x*.5,0,.72)})`,e.beginPath(),e.moveTo(f.gx,f.gy),e.lineTo(k,S);let O=3.4;e.moveTo(k,S),e.lineTo(k-f.ux*O-f.uy*O*.6,S-f.uy*O+f.ux*O*.6),e.moveTo(k,S),e.lineTo(k-f.ux*O+f.uy*O*.6,S-f.uy*O-f.ux*O*.6),e.stroke()}}}function $e(o){return(o===void 0?[]:Array.isArray(o)?o:[o]).filter(c=>c!=="off")}function To(o,a,c){let g=lt;if(un===null||yt||Dt%3===0){let u=[],f=0;for(let x=44/2;x<L;x+=44)for(let F=44/2;F<R;F+=44){let{fx:k,fy:S}=Gt(_,p.forces,W,x,F);if(yt){let N=ge(Qe,x,F,yt,.04);k+=N.x,S+=N.y}let O=Math.hypot(k,S);O>1e-9&&(u.push({gx:x,gy:F,ux:k/O,uy:S/O,mag:O}),O>f&&(f=O))}Bt===0?Bt=f:Bt=f>Bt?Bt*.7+f*.3:Bt*.9+f*.1,un=u}if(Bt<=0)return;let w={r:g[0],g:g[1],b:g[2],alpha:0,width:1.2},y=new Float64Array(12);for(let u of un){let f=c?pt(u.mag/Bt,0,1):Math.sqrt(u.mag/Bt),x=44*.5*(.25+.75*f),F=u.gx+u.ux*x,k=u.gy+u.uy*x,S=3.6;y[0]=u.gx,y[1]=u.gy,y[2]=F,y[3]=k,y[4]=F,y[5]=k,y[6]=F-u.ux*S-u.uy*S*.6,y[7]=k-u.uy*S+u.ux*S*.6,y[8]=F,y[9]=k,y[10]=F-u.ux*S+u.uy*S*.6,y[11]=k-u.uy*S-u.ux*S*.6,w.alpha=pt(.12+f*.55,0,.8),o.segments(y,w)}}function fi(o){let a=Sr(_);if(!a.length)return;let c=wr((w,y)=>je(_,p.forces,w,y),a,{step:6,maxSteps:200,bounds:{w:L,h:R},loopDist:8}),v=lt,g={r:v[0],g:v[1],b:v[2],alpha:.42,width:1.1};for(let w of c){if(w.length<2)continue;let y=new Float32Array(w.length*2);for(let u=0;u<w.length;u++)y[u*2]=w[u].x,y[u*2+1]=w[u].y;o.polyline(y,g)}}function ui(o){let c=22*C.gridWarp,v=48*.46,g=Math.floor(L/48)+2,w=Math.floor(R/48)+2,y=new Float32Array(g*w),u=new Float32Array(g*w),f=0,x=new Float32Array(g*w);for(let D=0;D<w;D++)for(let Y=0;Y<g;Y++){let{fx:st,fy:V}=Gt(_,p.forces,W,Y*48,D*48),at=Math.hypot(st,V),St=D*g+Y;at>1e-9&&(y[St]=st/at,u[St]=V/at,x[St]=at,at>f&&(f=at))}let F=[lt,[120,110,255],[240,70,255],[255,50,130]],k=8,S=D=>f>0?Math.sqrt(x[D]/f):0,O=D=>Math.round(S(D)*k),N=D=>{let Y=D/k,st=Dn(F,Y);return{r:st[0],g:st[1],b:st[2],alpha:Math.min(1,C.gridIntensity*(.3+.85*Y)),width:Y>.55?1.4:1}},$=new Float32Array(g*w),j=new Float32Array(g*w);for(let D=0;D<g*w;D++){let Y=S(D);$[D]=y[D]*Y*c,j[D]=u[D]*Y*c}let K=new Float32Array(g*w),ft=new Float32Array(g*w);for(let D=0;D<w;D++)for(let Y=0;Y<g;Y++){let st=0,V=0,at=0;for(let Ot=-1;Ot<=1;Ot++)for(let Rt=-1;Rt<=1;Rt++){let At=Y+Rt,Pt=D+Ot;if(At<0||Pt<0||At>=g||Pt>=w)continue;let ce=Pt*g+At;st+=$[ce],V+=j[ce],at++}let St=D*g+Y;K[St]=st/at,ft[St]=V/at}let dt=48*1.5,Q=(D,Y)=>{let st=Y*g+D,V=K[st],at=ft[st],St=Math.hypot(V,at);St>v&&(V=V/St*v,at=at/St*v);let Ot=D*48,Rt=Y*48,At=Math.min(Ot,L-Ot,Rt,R-Rt),Pt=At<=0?0:At<dt?At/dt:1;return[Ot+V*Pt,Rt+at*Pt]},rt=4,Mt=D=>{let Y=D.length>>1;if(Y<3)return D;let st=[D[0],D[1]];for(let V=0;V<Y-1;V++){let at=(V>0?V-1:0)<<1,St=V<<1,Ot=V+1<<1,Rt=(V+2<Y?V+2:Y-1)<<1,At=D[at],Pt=D[at+1],ce=D[St],Mn=D[St+1],kn=D[Ot],Sn=D[Ot+1],$o=D[Rt],Io=D[Rt+1];for(let En=1;En<=rt;En++){let he=En/rt,zn=he*he,Do=zn*he;st.push(.5*(2*ce+(-At+kn)*he+(2*At-5*ce+4*kn-$o)*zn+(-At+3*ce-3*kn+$o)*Do),.5*(2*Mn+(-Pt+Sn)*he+(2*Pt-5*Mn+4*Sn-Io)*zn+(-Pt+3*Mn-3*Sn+Io)*Do))}}return st},kt=(D,Y)=>Math.max(O(D*g+Y),O(D*g+Y+1)),Yt=(D,Y)=>Math.max(O(Y*g+D),O((Y+1)*g+D));for(let D=0;D<w;D++){let Y=kt(D,0),st=[...Q(0,D),...Q(1,D)];for(let V=1;V<g-1;V++){let at=kt(D,V);at===Y?st.push(...Q(V+1,D)):(o.polyline(Mt(st),N(Y)),st=[...Q(V,D),...Q(V+1,D)],Y=at)}o.polyline(Mt(st),N(Y))}for(let D=0;D<g;D++){let Y=Yt(D,0),st=[...Q(D,0),...Q(D,1)];for(let V=1;V<w-1;V++){let at=Yt(D,V);at===Y?st.push(...Q(D,V+1)):(o.polyline(Mt(st),N(Y)),st=[...Q(D,V),...Q(D,V+1)],Y=at)}o.polyline(Mt(st),N(Y))}}let Ft=null;function Ao(o,a,c){let w=Math.ceil(L/24)+1,y=Math.ceil(R/24)+1;!Ft||Ft.length!==w*y?Ft=new Float32Array(w*y):Ft.fill(0);let u=!1;for(let S of d.particles){if(S.cap)continue;let O=a(S);O<=0||(u=!0,Kn(Ft,w,y,24,S.x,S.y,42,O))}if(!u)return;let f=0;for(let S=0;S<Ft.length;S++)Ft[S]>f&&(f=Ft[S]);if(f<=0)return;let x=lt,F=[.25,.5,.78],k=[];for(let S=0;S<F.length;S++){let O=F[S]*f;k.length=0;for(let N=0;N<y-1;N++)for(let $=0;$<w-1;$++){let j=Ft[N*w+$],K=Ft[N*w+$+1],ft=Ft[(N+1)*w+$+1],dt=Ft[(N+1)*w+$],Q=Xn(j,K,ft,dt,O);if(!Q.length)continue;let rt=$*24,Mt=N*24;for(let kt of Q)k.push(rt+kt.x1*24,Mt+kt.y1*24,rt+kt.x2*24,Mt+kt.y2*24)}k.length&&o.segments(k,{r:x[0],g:x[1],b:x[2],alpha:c*(.45+.55*(S/(F.length-1))),width:1+S*.3})}}function hi(o){let g=lt,w={r:g[0],g:g[1],b:g[2],alpha:0,width:1.1},y=new Float64Array(4);for(let u=104/2;u<L;u+=104)for(let f=104/2;f<R;f+=104){let x=u,F=f;for(let k=0;k<24;k++){let{fx:S,fy:O}=Gt(_,p.forces,W,x,F);if(yt){let K=ge(Qe,x,F,yt,.04);S+=K.x,O+=K.y}let N=Math.hypot(S,O);if(!(N>1e-9))break;let $=x+S/N*9,j=F+O/N*9;if($<0||j<0||$>L||j>R)break;y[0]=x,y[1]=F,y[2]=$,y[3]=j,w.alpha=.34*(1-k/24),o.segments(y,w),x=$,F=j}}}function yi(o){let a=lt;for(let c of _){if(!c.vis||!c.feedback)continue;let v=`d ${c.d.toFixed(2)}`,g=c.cx+c.hw+8,w=c.cy;o.rect(g-3,w-7,o.measureText(v)+6,14,a[0],a[1],a[2],pt(.3+c.d*.55,0,.85)),o.text(v,g,w+.5,5,6,11,.92)}}function pi(o,a){if(o.clear(),!(!a.length||L===0||R===0))for(let c of a){c==="streamlines"?To(o,!1,!1):c==="force-vectors"?To(o,!1,!0):c==="field-lines"?fi(o):c==="grid"?ui(o):c==="temperature"?Ao(o,g=>g.heat,.5):c==="energy"?Ao(o,g=>.5*g.m*(g.vx*g.vx+g.vy*g.vy),.42):c==="path"?hi(o):c==="data"&&yi(o);let v=q.get(c);v&&v(o,W,L,R)}}function bn(o){Dt++,W.t=(o-Mo)/1e3,W.frameN=Dt;let a=Number.isFinite(dn)?(o-dn)/16.6667:1;dn=o;let c=wt();if(W.dt=c<=0?0:pt(a,.2,2)*c,it<1&&(it=Math.min(1,it+.012)),Ko(W.form,fo,.03),Qt){let f=T.viewport();Z=f.originX??0,ot=f.originY??0}let v=T.scrollY?.()??0,g=v-fe;if(W.scrollV=(W.scrollV??0)*.7+Math.abs(g)*.3,fe=v,g!==0&&!Qt)for(let f of _)f.cy-=g;for(let f of vt){let x=v*(.025+f.depth*.08);f.offsetY+=(x-f.offsetY)*.04}if(_.length&&Dt%6===0&&(Ge(_,L,R,Z,ot),h(_),vs(_,W.supernova)),W.dt!==0&&Ds(),tt.length&&W.dt){let f=W.dt/60;for(let x of tt)ms(x.agent,x.from.d>.08,0,f)}let w=null;for(let f of _)if(f.on&&f.vis){w=f;break}let y=yt??w;if(xt.k+=((y?1:0)-xt.k)*.07,y){let f=yt?yt.x:w.cx,x=yt?yt.y:w.cy;xt.x=xt.x?xt.x+(f-xt.x)*.16:f,xt.y=xt.y?xt.y+(x-xt.y)*.16:x}Dt%30===0&&(de=(T.scrollHeight?.()??R)-R||1);let u=Fe?mt(Fe):Dn(wo,v/de);if(lt=[lt[0]+(u[0]-lt[0])*.08,lt[1]+(u[1]-lt[1])*.08,lt[2]+(u[2]-lt[2])*.08],C.accent=In(lt),d.reindex(),si(),W.dt&&Ir(_,d.particles),yt&&W.dt)for(let f of d.particles){if(f.cap)continue;let x=ge(Qe,f.x,f.y,yt,.6);f.vx+=x.x,f.vy+=x.y}if(C.waveStyle==="circular")if(C.waveCenter)Jt=typeof C.waveCenter=="function"?C.waveCenter():C.waveCenter;else{let f=_.find(x=>x.tokens.includes("star")||x.tokens.includes("vortex"));f?Jt={x:f.cx,y:f.cy}:Jt={x:L/2,y:R/2}}else Jt=null;if(Hs(),ar({store:d,bodies:_,env:W,forces:p.forces,conditions:p.conditions,waves:vt,waveStyle:C.waveStyle,waveCenter:Jt,separation:C.separation}),Lt&&(Lt.x=vo,Lt.y=bo,Lt.vx=0,Lt.vy=0,Lt.heat=Math.min(1,Lt.heat+.2)),W.dt){for(let f of b.values())f.step();ct&&ct.update(d.particles),Pr(d,Wt,xo,vt,L,R,W.t,ht),$r(Wt,vt,_,p.forces,L,R,W.t,f=>void d.add(re(f))),Zs(),Ys()}if(ai(),Ps(),ii(),Us(),Gs(),Vs(),Js(o),B(),e&&C.render!=="none"&&lo&&(c>0||Dt%4===0)&&(di(),i)){let f=$e(C.overlay);f.length&&pi(i,f)}Kt=T.raf(bn)}function wn(o){let a=pe[o];a&&(fo=o==="ambient"?{...sn}:{...a.preset},an=o)}let Ie="",Co=Mo;function Oo(){let o=T.viewport().height*.5,a="";T.root.querySelectorAll("[data-formation]").forEach(c=>{let v=c.getBoundingClientRect();v.top<=o&&v.bottom>=o&&(a=c.dataset.formation??"")}),a&&a!==Ie&&(Ie=a,wn(a))}let Ro=()=>void(Co=ln()),mi=()=>{Ro(),Oo()},Po=setInterval(()=>{ln()-Co>6e3&&Ie!=="ambient"&&(Ie="ambient",wn("ambient"))},1200);Po.unref?.();let gi=()=>zo();zo(),$e(C.overlay).length&&l();let xi=()=>{T.hidden?.()??!1?(T.cancelRaf(Kt),Kt=0):Kt||(Kt=T.raf(bn))};T.onResize&&H.push(T.onResize(gi)),T.onScroll&&H.push(T.onScroll(mi)),T.onVisibility&&H.push(T.onVisibility(xi)),T.onInput&&H.push(T.onInput(Ro)),T.onBodyEvent&&(H.push(T.onBodyEvent(Gr,_s)),H.push(T.onBodyEvent(Vr,Ws)),H.push(T.onBodyEvent(Xr,qs))),Oo(),Kt=T.raf(bn);let ae={projections:$s,scan:Ce,rescan:Ce,setAccent:o=>{C.accent=o,lt=mt(o)},setPalette:o=>{let a=Be(o);wo=a.map(mt);let c=a[0];c&&(C.accent=c,lt=mt(c))},setFormation:wn,setWaveStyle:o=>{C.waveStyle=o},setWaveCenter:o=>{C.waveCenter=o},setSeparation:o=>{C.separation=o>=0?o:0},setAttention:o=>{if(C.attention=o,!o)for(let a of _)a.attn=1},setCausality:o=>{if(C.causality=o,!o)for(let a of _)a.el.style.removeProperty("--lit"),a.el.dataset.fxLit="0"},setRender:o=>{if(o!=="none"&&!e){if(e=n.getContext("2d"),!e){console.warn(`Fundamental: setRender('${o}') could not acquire a 2d context; staying in render 'none'`);return}$e(C.overlay).length&&l(),Re(T.viewport().dpr)}C.render=o},setOverlay:o=>{C.overlay=o,$e(o).length?l():i?.clear()},setHeatmap:o=>{if(C.heatmap=o,o)!ct&&L>0&&(ct=new ve(L,R));else if(ct){ct.clear(),ct=null;for(let a of _)(a.writeTarget??a.el).style.removeProperty("--field-heatmap-density")}},setDprCap:o=>{C.dprCap=o>0?o:2,e&&Re(T.viewport().dpr)},setQualityTier:o=>{let a=Math.max(0,Math.min(3,Math.floor(o||0)));a!==Oe&&(Oe=a,e&&Re(T.viewport().dpr))},get policy(){return ro(nt)},setPolicy:o=>{nt=ro(o)},forAgent:o=>{let a=new Set(o.capabilities??[]),c=(o.redactions??[]).slice(),v=f=>a.has(f),g=()=>{let f=nt.budgets?.agentRead;return f==null||f>0},u={get capabilities(){return Object.freeze([...a])},get redactions(){return Object.freeze([...c])},query:(f={})=>{if(!g()){let O=ae.query({...f,include:["bodies"]});return O.metrics={},O.relationships=[],O.influences=[],v("read:projections")||(O.projections=[]),Ze(O,c)}let x=new Set(["bodies"]);v("read:metrics")&&x.add("metrics"),v("read:relationships")&&x.add("relationships"),v("read:influences")&&x.add("influences");let F=f.include?new Set(f.include):null,k=[...x].filter(O=>!F||F.has(O)),S=ae.query({...f,include:k});return v("read:metrics")||(S.metrics={}),v("read:relationships")||(S.relationships=[]),v("read:influences")||(S.influences=[]),v("read:projections")||(S.projections=[]),Ze(S,c)},snapshot:(f={})=>{if(!g()){let k=ae.snapshot({profile:"public"});return Ze(k,c)}let x={...f};v("read:body-data")||(x.includeData=!1),v("read:relationships")||(x.includeRelationships=!1),v("read:influences")||(x.includeInfluences=!1);let F=ae.snapshot(x);return v("read:projections")||(F.projections=[]),Ze(F,c)}};return v("read:replay")&&(u.replay=(f,x,F)=>ae.replay(f,x,F)),Object.freeze(u)},threads:vn,burst:(o,a,c)=>{let v=zr;for(let g of d.particles){let w=Fr(g.x-o,g.y-a,v,6,g.z??0);w.heat!==0&&(g.vx+=w.vx,g.vy+=w.vy,w.vz&&(g.vz=(g.vz??0)+w.vz),g.heat=Math.max(g.heat,w.heat),c&&(g.color=c))}Hn(Wt,vt,o,a,v,L,R,W.t,g=>void d.add(re(g))),ko(o,a,2,c)},flowTo:(o,a,c)=>{yt=vr(o,a,c)},clearFlow:()=>{yt=null},seed:o=>{Ae=o,So()},atomAt:(o,a)=>{let c=null,v=1/0;for(let g of d.near(o,a,24)){if(g.atom==null)continue;let w=(g.x-o)**2+(g.y-a)**2+(g.z??0)**2;w<v&&(v=w,c=g.atom)}return c},focusAt:(o,a)=>{let c=null,v=1/0;for(let g of d.near(o,a,24)){if(g.atom==null)continue;let w=(g.x-o)**2+(g.y-a)**2+(g.z??0)**2;w<v&&(v=w,c=g)}return Lt=c,c?(vo=c.x,bo=c.y,c.atom??null):null},clearFocus:()=>{Lt=null},particleCount:()=>d.size,readParticles:o=>{let a=d.particles,c=Math.floor(o.length/5),v=0;for(let g=0;g<a.length&&v<c;g++){let w=a[g];if(w.report!==void 0)continue;let y=v*5;o[y]=w.x,o[y+1]=w.y,o[y+2]=w.z??0,o[y+3]=w.heat,o[y+4]=w.size,v++}return v},readParticleIds:o=>{let a=d.particles,c=0;for(let v=0;v<a.length&&c<o.length;v++){let g=a[v];g.report===void 0&&(o[c++]=g.id??0)}return c},readParticleChannels:(o,a)=>{let c=d.particles,v=0;for(let g=0;g<c.length;g++){let w=c[g];if(!("report"in w&&w.report!==void 0)){if(v>=Math.min(...a.map(y=>y.length)))break;for(let y=0;y<o.length&&!(y>=a.length);y++){let u=o[y];a[y][v]=u==="x"?w.x:u==="y"?w.y:u==="z"?w.z??0:u==="vx"?w.vx:u==="vy"?w.vy:u==="heat"?w.heat:u==="size"?w.size:u==="m"?w.m:u==="id"?w.id??0:u==="age"?w.age??0:u==="charge"?w.charge??0:0}v++}}return v},registerOverlay:(o,a)=>(q.set(o,a),()=>{q.delete(o)}),addAgent:o=>{let a=re({x:o.x,y:o.y,z:o.z,species:o.species});return a.vx=0,a.vy=0,o.z===void 0&&C.depth<=0&&(a.z=0),o.mass!==void 0&&(a.m=o.mass),a.maxSpeed=o.maxSpeed,a.report=o.report,d.add(a),{particle:a,remove:()=>d.remove(a)}},addBody:o=>{let a={"data-body":Array.isArray(o.tokens)?o.tokens.join(" "):String(o.tokens)};o.strength!=null&&(a["data-strength"]=String(o.strength)),o.range!=null&&(a["data-range"]=String(o.range)),o.spin!=null&&(a["data-spin"]=String(o.spin)),o.angle!=null&&(a["data-angle"]=String(o.angle)),o.color!=null&&(a["data-color"]=o.color);let c=()=>{let u=o.rect();return{left:u.left,top:u.top,right:u.left+u.width,bottom:u.top+u.height,width:u.width,height:u.height,x:u.left,y:u.top,toJSON:()=>({})}},v={tagName:"DIV",id:"",className:"",dataset:o.color!=null?{color:o.color}:{},getAttribute:u=>a[u]??null,hasAttribute:u=>u in a,getBoundingClientRect:c,dispatchEvent:()=>!0,setAttribute:()=>{},removeAttribute:()=>{},style:{setProperty:()=>{},removeProperty:()=>{},getPropertyValue:()=>""}},g=xe(v);g.rect=c,g.data=o.data,o.identity!=null&&(g.identity=typeof o.identity=="string"?{id:o.identity}:o.identity),o.authority&&(g.authority=o.authority),g.feedback=!0;let w={};g.onFeedback=u=>{Object.assign(w,u),o.onFeedback?.(u)},X.push(g),_=_.concat(g),Ge([g],L,R,Z,ot);let y={data:o.data,get channels(){return w},set:u=>{u.strength!=null&&(a["data-strength"]=String(u.strength)),u.range!=null&&(a["data-range"]=String(u.range)),u.spin!=null&&(a["data-spin"]=String(u.spin)),u.angle!=null&&(a["data-angle"]=String(u.angle)),u.color!=null&&(a["data-color"]=u.color,v.dataset.color=u.color,g.tint=u.color)},remove:()=>{let u=X.indexOf(g);u>=0&&X.splice(u,1),_=_.filter(f=>f!==g);for(let f=tt.length-1;f>=0;f--){let x=tt[f];(x.from===g||x.to===g)&&tt.splice(f,1)}}};return bt.set(y,g),y},addEdge:(o,a,c)=>{let v=bt.get(o),g=bt.get(a);if(!v||!g)throw new Error("addEdge: both arguments must be handles returned by addBody on this field.");let w={id:`e${we++}`,from:"",to:"",type:c?.type??"related",strength:c?.strength??.5,tension:0,memory:0,active:!1},y={agent:w,from:v,to:g,fromData:o.data,toData:a.data};return tt.push(y),{set:u=>{u.strength!=null&&(w.strength=u.strength<0?0:u.strength>1?1:u.strength),u.type!=null&&(w.type=u.type)},remove:()=>{let u=tt.indexOf(y);u>=0&&tt.splice(u,1)}}},readEdges:()=>tt.map(o=>({from:o.fromData,to:o.toData,type:o.agent.type,strength:o.agent.strength,memory:o.agent.memory,active:o.agent.active})),query:(o={})=>{let a=o.at,c,v=0,g=0,w=0,y=!1;a&&("width"in a?(c={x:a.x,y:a.y,width:a.width,height:a.height},v=a.x+a.width/2,g=a.y+a.height/2,w=Math.max(a.width,a.height)/2):(w=o.radius??240,v=a.x,g=a.y,c={x:v-w,y:g-w,width:w*2,height:w*2}),y=!0);let u=new Set(o.include??(y?["bodies","metrics","relationships","influences"]:["bodies","metrics","relationships"])),f=$=>{if(!$.vis)return!1;if(!y)return!0;if("width"in a){let j=c;return $.cx>=j.x&&$.cx<=j.x+j.width&&$.cy>=j.y&&$.cy<=j.y+j.height}return Math.hypot($.cx-v,$.cy-g)<=w},x=_.filter(f),F=u.has("bodies")?x.map($=>{let{metrics:j,dimensions:K}=ho($),ft=cn($);return{id:ft.id,identity:ft,rect:{x:$.cx-$.hw,y:$.cy-$.hh,width:$.hw*2,height:$.hh*2},tokens:$.tokens.slice(),metrics:j,dimensions:K,activeFormations:[an],authority:$.authority??"anchored"}}):[],k={};if(u.has("metrics")&&(k.particles=d.size,k.bodies=x.length,x.length>0)){let $=0;for(let j of x)$+=j.d;k.meanDensity=$/x.length}let S=u.has("relationships")?tt.filter($=>!y||f($.from)||f($.to)).map($=>({from:Zt($.from),to:Zt($.to),type:$.agent.type,strength:$.agent.strength,memory:$.agent.memory,active:$.agent.active,causal:$.agent.active})):[],O=[];if(u.has("influences")&&y)for(let $ of x){if($.tokens.length===0)continue;let j=oo(p.forces,$.tokens,$,v,g);for(let K of j.attribution)O.push({source:Zt($),force:K.force,channel:K.channel,contribution:K.contribution})}let N={query:o,frame:W.frameN,time:W.t,region:c,bodies:F,metrics:k,relationships:S,influences:O,projections:ke()};return o.lens?xr(N,o.lens):N},snapshot:(o={})=>{let a=rc(o),c=a.includeRelationships,v=_.filter(f=>f.vis),g=v.map(f=>{let{metrics:x,dimensions:F}=ho(f),k=cn(f),S={id:k.id,identity:k,authority:f.authority??"anchored",rect:{x:f.cx-f.hw,y:f.cy-f.hh,width:f.hw*2,height:f.hh*2},position:{x:f.cx,y:f.cy,z:0},tokens:f.tokens.slice(),metrics:x,dimensions:F};return a.includeData&&Xt()&&(S.data=Ns(f.data)),S}),w=c?tt.map(f=>({from:Zt(f.from),to:Zt(f.to),type:f.agent.type,strength:f.agent.strength,memory:f.agent.memory,active:f.agent.active,causal:f.agent.active})):[],y={particles:d.size,bodies:v.length};if(v.length>0){let f=0;for(let x of v)f+=x.d;y.meanDensity=f/v.length}let u={id:`snap-${W.frameN}-${Os++}`,createdAt:W.t,frame:W.frameN,version:De,formations:[an],bodies:g,relationships:w,metrics:y,projections:ke()};if(a.includeParticles){let f=[];for(let x of d.particles)x.cap||f.push({x:x.x,y:x.y,z:x.z??0,heat:x.heat,size:x.size});u.particles=f}if(a.includeInfluences){let f=[];for(let x of v){if(x.tokens.length===0)continue;let F=oo(p.forces,x.tokens,x,x.cx+8,x.cy);for(let k of F.attribution)f.push({source:Zt(x),force:k.force,channel:k.channel,contribution:k.contribution})}u.influences=f}return u},diff:(o,a)=>Nn(o,a),replay:(o,a,c)=>Xo(o,a,c),addField:(o,a)=>($t.set(o,a),{name:o,set:c=>{$t.set(o,c)},remove:()=>{$t.delete(o)}}),sampleField:(o,a,c)=>{let v=$t.get(o);return v?v(a,c):0},energy:()=>Ms(d.particles),sample:(o,a)=>{let{fx:c,fy:v}=Gt(_,p.forces,W,o,a);return{x:c,y:v}},sampleScalar:(o,a)=>ct?ct.norm(o,a):(Gn("NOOP_NO_HEATMAP","sampleScalar() returned 0 because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),0),sampleGradient:(o,a)=>ct?ct.gradient(o,a):(Gn("NOOP_NO_HEATMAP","sampleGradient() returned { x: 0, y: 0 } because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),{x:0,y:0}),grid:o=>W.grid(o),on:(o,a)=>{let c=M.get(o);return c||(c=new Set,M.set(o,c)),c.add(a),()=>void c.delete(a)},version:De,scrollV:()=>W.scrollV??0,setVisible:o=>{lo=o},setBackground:o=>{C.background=o,o==="transparent"&&e&&e.clearRect(0,0,L,R)},destroy:()=>{T.cancelRaf(Kt),clearInterval(Po);for(let o of H)o();for(let o of oe)o.el.removeEventListener("pointerenter",o.enter),o.el.removeEventListener("pointerleave",o.leave),o.el.removeEventListener("focusin",o.enter),o.el.removeEventListener("focusout",o.leave),delete o.el.dataset.fxEngaged;oe=[];for(let o of jt)(o.docked||o.dock.dock>0)&&(o.docked=null,o.dock.dock=0,o.el.style.opacity="",o.el.getAttribute("aria-hidden")==="true"&&o.el.removeAttribute("aria-hidden"),o.el.removeAttribute("inert"));for(let o of ee)for(let a of o.emitted)a.remove();ee=[],d.clear(),T.detach?.()}};return ae}var en={};function nn(){return en.reducedMotion!==void 0?en.reducedMotion:typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function on(){return en.hidden!==void 0?en.hidden:typeof document<"u"&&document.hidden}var sc=["--field-density","--d"],ks=!1;function Ss(){if(ks)return[];ks=!0;let n=globalThis.CSS;if(!n||typeof n.registerProperty!="function")return[];let t=[];for(let e of sc)try{n.registerProperty({name:e,syntax:"<number>",inherits:!0,initialValue:"0"}),t.push(e)}catch{}return t}var Es=["pointerdown","wheel","keydown","touchstart"];function be(){return Ss(),{root:document,viewport:()=>({width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio||1}),scrollY:()=>window.scrollY||0,scrollHeight:()=>document.documentElement.scrollHeight,reducedMotion:()=>nn(),hidden:()=>on(),raf:n=>requestAnimationFrame(n),cancelRaf:n=>cancelAnimationFrame(n),createCanvas:()=>document.createElement("canvas"),onResize:n=>(window.addEventListener("resize",n,{passive:!0}),()=>window.removeEventListener("resize",n)),onScroll:n=>(window.addEventListener("scroll",n,{passive:!0}),()=>window.removeEventListener("scroll",n)),onVisibility:n=>(document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)),onInput:n=>{for(let t of Es)window.addEventListener(t,n,{passive:!0});return()=>{for(let t of Es)window.removeEventListener(t,n)}},onBodyEvent:(n,t)=>(document.addEventListener(n,t),()=>document.removeEventListener(n,t))}}var zs=["pointerdown","wheel","keydown","touchstart"];function Fs(n){return n.setAttribute(Ue,""),{root:n,detach:()=>n.removeAttribute(Ue),viewport:()=>{let t=n.getBoundingClientRect();return{width:t.width,height:t.height,dpr:window.devicePixelRatio||1,originX:t.left,originY:t.top}},scrollY:()=>n.scrollTop,scrollHeight:()=>n.scrollHeight,reducedMotion:()=>nn(),hidden:()=>on(),raf:t=>requestAnimationFrame(t),cancelRaf:t=>cancelAnimationFrame(t),createCanvas:()=>document.createElement("canvas"),onResize:t=>{let e=new ResizeObserver(t);return e.observe(n),window.addEventListener("resize",t,{passive:!0}),()=>{e.disconnect(),window.removeEventListener("resize",t)}},onScroll:t=>(n.addEventListener("scroll",t,{passive:!0}),window.addEventListener("scroll",t,{passive:!0}),()=>{n.removeEventListener("scroll",t),window.removeEventListener("scroll",t)}),onVisibility:t=>(document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)),onInput:t=>{for(let e of zs)n.addEventListener(e,t,{passive:!0});return()=>{for(let e of zs)n.removeEventListener(e,t)}},onBodyEvent:(t,e)=>(n.addEventListener(t,e),()=>n.removeEventListener(t,e))}}function Ts(n,t={}){return tn(n,{...t,host:be()})}function so(n,t={}){let{host:e,bounds:r,...s}=t,i=e??(r?Fs(r):be());return tn(n,{...s,host:i})}function io(){if(typeof document>"u"||typeof window>"u")throw new Error('Fundamental: the field runs in the browser only. Create it on the client (inside useEffect / onMount / a "client only" boundary), not during server-side rendering.')}function rn(n=document.body){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText=hs,n.appendChild(t),t}function As(n){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText="position:absolute;inset:0;width:100%;height:100%;pointer-events:none;",getComputedStyle(n).position==="static"&&(n.style.position="relative"),n.appendChild(t),t}function ic(n={}){io();let{target:t=document.body,...e}=n,r=rn(t),s=Ts(r,e);return{...s,destroy:()=>{s.destroy(),r.remove()}}}var ao=class{constructor(t={}){U(this,"canvas");U(this,"field");U(this,"managed");io();let{canvas:e,target:r,bounds:s,...i}=t;this.managed=!e,this.canvas=e??(s?As(s):rn(r)),this.field=so(this.canvas,s?{...i,bounds:s}:i)}scan(){this.field.scan()}rescan(){this.field.rescan()}setAccent(t){this.field.setAccent(t)}setPalette(t){this.field.setPalette(t)}setFormation(t){this.field.setFormation(t)}setWaveStyle(t){this.field.setWaveStyle(t)}setWaveCenter(t){this.field.setWaveCenter(t)}setSeparation(t){this.field.setSeparation(t)}setAttention(t){this.field.setAttention(t)}setCausality(t){this.field.setCausality(t)}setHeatmap(t){this.field.setHeatmap(t)}setDprCap(t){this.field.setDprCap(t)}setQualityTier(t){this.field.setQualityTier(t)}get policy(){return this.field.policy}setPolicy(t){this.field.setPolicy(t)}forAgent(t){return this.field.forAgent(t)}setRender(t){this.field.setRender(t)}setOverlay(t){this.field.setOverlay(t)}threads(t){this.field.threads(t)}burst(t,e,r){this.field.burst(t,e,r)}flowTo(t,e,r){this.field.flowTo(t,e,r)}clearFlow(){this.field.clearFlow()}seed(t){this.field.seed(t)}addAgent(t){return this.field.addAgent(t)}addBody(t){return this.field.addBody(t)}addEdge(t,e,r){return this.field.addEdge(t,e,r)}readEdges(){return this.field.readEdges()}query(t){return this.field.query(t)}snapshot(t){return this.field.snapshot(t)}diff(t,e){return this.field.diff(t,e)}replay(t,e,r){return this.field.replay(t,e,r)}get projections(){return this.field.projections}addField(t,e){return this.field.addField(t,e)}sampleField(t,e,r){return this.field.sampleField(t,e,r)}atomAt(t,e){return this.field.atomAt(t,e)}focusAt(t,e){return this.field.focusAt(t,e)}clearFocus(){this.field.clearFocus()}particleCount(){return this.field.particleCount()}readParticles(t){return this.field.readParticles(t)}readParticleIds(t){return this.field.readParticleIds(t)}readParticleChannels(t,e){return this.field.readParticleChannels(t,e)}registerOverlay(t,e){return this.field.registerOverlay(t,e)}energy(){return this.field.energy()}sample(t,e){return this.field.sample(t,e)}sampleScalar(t,e){return this.field.sampleScalar(t,e)}sampleGradient(t,e){return this.field.sampleGradient(t,e)}grid(t){return this.field.grid(t)}on(t,e){return this.field.on(t,e)}get version(){return this.field.version}scrollV(){return this.field.scrollV()}setVisible(t){this.field.setVisible(t)}setBackground(t){this.field.setBackground(t)}destroy(){this.field.destroy(),this.managed&&this.canvas.remove()}};export{Lo as CONDITIONS,De as FIELD_VERSION,Tn as FORCES,Bo as FORMATIONS,ao as FieldField,An as PALETTE,be as browserHost,so as createField,ps as cssFeedbackSink,Qa as headlessHost,rn as makeFieldCanvas,ic as mountField};