@fundamental-engine/vanilla 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/standalone.global.js +1 -1
- package/dist/standalone.js +1 -1
- package/package.json +3 -3
package/dist/standalone.js
CHANGED
|
@@ -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 zi=Object.defineProperty;var Ai=(n,t,e)=>t in n?zi(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var Y=(n,t,e)=>Ai(n,typeof t!="symbol"?t+"":t,e);var Le="0.10.1";var On=[{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"}],Wo=Object.fromEntries(On.map(n=>[n.id,n])),Rn=On.map(n=>n.color),pe=["#4da3ff","#2dd4bf","#a78bfa","#ff6e9c","#ff9d5c"],Cn=["spotlight","screen","resonate"],Ti=["spawn"],Pn=300,$n=120;function Ci(n){return Cn.includes(n)?"modifier":Ti.includes(n)?"source":"force"}function Be(n){let t=[],e=[],r=[];for(let s of n){let i=Ci(s);i==="modifier"?t.push(s):i==="source"?r.push(s):e.push(s)}return t.length>1&&t.sort((s,i)=>Cn.indexOf(s)-Cn.indexOf(i)),{modifiers:t,forces:e,sources:r}}var qo=[{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}}],ge=Object.fromEntries(qo.map(n=>[n.id,n]));var Ho=[{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}],Mc=Object.fromEntries(Ho.map(n=>[n.id,n]));var Oi={ours:pe,heatmap:["#2b3a8c","#2d8fd4","#3fd07a","#ffe14d","#ff8a3d","#e23b3b"],infrared:["#2a0a4a","#8e24aa","#e53935","#ff8f00","#ffd54f","#fffde7"],spectrum:["#ff3b30","#ff9500","#ffcc00","#34c759","#00c7be","#007aff","#af52de"]};function We(n){return Array.isArray(n)?n.length>0?n:pe:typeof n=="string"?Oi[n]??pe:pe}var In={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"]}},Nn="warm";var mt=(n,t,e)=>n<t?t:n>e?e:n;function pt(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 Ri=[255,224,200],Pi=[255,110,80];function Dn(n,t,e,r,s=Ri,i=Pi){let l=s[0]+(i[0]-s[0])*t,d=s[1]+(i[1]-s[1])*t,g=s[2]+(i[2]-s[2])*t;return l+=(r[0]-l)*e,d+=(r[1]-d)*e,g+=(r[2]-g)*e,n[0]=l,n[1]=d,n[2]=g,n}function _n([n,t,e]){let r=s=>mt(Math.round(s),0,255).toString(16).padStart(2,"0");return`#${r(n)}${r(t)}${r(e)}`}function jo(n,t,e){let[r,s,i]=pt(n),[l,d,g]=pt(t),w=e<0?0:e>1?1:e;return _n([r+(l-r)*w,s+(d-s)*w,i+(g-i)*w])}function Ln(n,t){if(n.length===0)return[77,163,255];if(n.length===1)return n[0];let e=mt(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 Uo(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 qe=1;function He(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 Yo(n,t,e){let r=0,s=0;for(let i of n){let l=t-i.x,d=e-i.y,g=Math.max(qe,Math.hypot(l,d)),w=i.q/(g*g);r+=l/g*w,s+=d/g*w}return{x:r,y:s}}function Go(n,t,e,r,s,i){let l=s-n,d=i-t,g=Math.max(qe,Math.hypot(l,d)),m=(e<0?-1:1)*r/(g*g);return{x:l/g*m,y:d/g*m}}function Vo(n,t){let e=n/20+(t?.45:0);return e<0?0:e>1?1:e}function Xo(n,t,e){return Math.round(n+(t-n)*e)}function Ko(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,g=0;for(let m of n){let M=m.strength>0?m.strength:0;d+=M,g+=M*(1+(m.on?e:0))}if(d<=0||g<=0)return l;let w=d/g;for(let m=0;m<i;m++){let z=(1+(n[m].on?e:0))*w;z<r?z=r:z>s&&(z=s),l[m]=z}return l}function Jo(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 g=0;g<i;g++){let w=n[g],m=w.d-e;if(m<=0)continue;let M=0;for(let E=0;E<i;E++){if(E===g){d[E]=0;continue}let T=n[E],P=Math.hypot(w.cx-T.cx,w.cy-T.cy),_=P<s?1-P/s:0;d[E]=_,M+=_}if(M<=0)continue;let z=r*m;for(let E=0;E<i;E++){let T=d[E];if(T<=0)continue;let P=z*T/M;l[E]+=P,l[g]-=P}}return l}var Qo=n=>`${n.from}\0${n.to}\0${n.type}`;function Bn(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,T]of r){let P=s.get(E);if(!P){e.push({id:E,kind:"removed"});continue}let _={},I=!1,G=new Set([...Object.keys(T.metrics),...Object.keys(P.metrics)]);for(let J of G){let y=T.metrics[J]??0,X=P.metrics[J]??0;y!==X&&(_[J]={from:y,to:X},I=!0)}I&&e.push({id:E,kind:"changed",metrics:_})}for(let E of s.keys())r.has(E)||e.push({id:E,kind:"added"});let i=[],l=new Map(n.relationships.map(E=>[Qo(E),E])),d=new Map(t.relationships.map(E=>[Qo(E),E]));for(let[E,T]of l){let P=d.get(E);if(!P){i.push({from:T.from,to:T.to,type:T.type,kind:"removed"});continue}let _={from:T.from,to:T.to,type:T.type,kind:"changed"},I=!1;T.strength!==P.strength&&(_.strength={from:T.strength,to:P.strength},I=!0),T.active!==P.active&&(_.active={from:T.active,to:P.active},I=!0),I&&i.push(_)}for(let[E,T]of d)l.has(E)||i.push({from:T.from,to:T.to,type:T.type,kind:"added"});let g=[],w=new Set([...Object.keys(n.metrics),...Object.keys(t.metrics)]);for(let E of w){let T=n.metrics[E]??0,P=t.metrics[E]??0;T!==P&&g.push({key:E,from:T,to:P})}let m=[],M=new Set(n.formations),z=new Set(t.formations);for(let E of z)M.has(E)||m.push({id:E,kind:"activated"});for(let E of M)z.has(E)||m.push({id:E,kind:"deactivated"});return{from:n.id,to:t.id,bodyChanges:e,relationshipChanges:i,metricChanges:g,formationChanges:m}}function Zo(n,t,e={}){let r=m=>Math.round(m*1e3)/1e3,s=Bn(n,t),i=t.frame,l=t.createdAt,d=[],g=(m,M,z={})=>{d.push({frame:i,time:l,cause:m,description:M,...z})};for(let m of s.formationChanges)g("formation",`Formation '${m.id}' ${m.kind}`,{source:m.id});for(let m of s.relationshipChanges){let M;if(m.kind==="added")M="formed";else if(m.kind==="removed")M="dissolved";else{let z=[];if(m.active&&z.push(m.active.to?"became active":"went idle"),m.strength){let E=m.strength.to>=m.strength.from?"strengthened":"weakened";z.push(`${E} ${r(m.strength.from)}\u2192${r(m.strength.to)}`)}M=z.join(", ")||"changed"}g("relationship",`Relationship ${m.from}\u2192${m.to} (${m.type}) ${M}`,{source:m.from,target:m.to,contribution:m.strength})}for(let m of s.bodyChanges)if(m.kind==="added")g("measurement",`Body ${m.id} entered the field`,{source:m.id});else if(m.kind==="removed")g("measurement",`Body ${m.id} left the field`,{source:m.id});else if(m.metrics)for(let[M,z]of Object.entries(m.metrics)){let E=z.to>z.from?"rose":"fell";g("metric",`Body ${m.id} ${M} ${E} ${r(z.from)}\u2192${r(z.to)}`,{source:m.id,contribution:z})}if(n.influences&&t.influences){let m=T=>typeof T=="number"?Math.abs(T):Math.hypot(T.x,T.y,T.z??0),M=T=>`${T.source} ${T.force} ${T.channel??"linear"}`,z=new Map(n.influences.map(T=>[M(T),T])),E=new Map(t.influences.map(T=>[M(T),T]));for(let T of new Set([...z.keys(),...E.keys()])){let P=z.get(T),_=E.get(T),I=P?m(P.contribution):0,G=_?m(_.contribution):0;if(Math.abs(G-I)<1e-9)continue;let J=_??P,y=G>I?I===0?"engaged":"grew":G===0?"released":"weakened",X=(J.channel??"linear")==="thermal"?" (thermal)":"";g("force",`Force ${J.force} on ${J.source}${X} ${y} ${r(I)}\u2192${r(G)}`,{source:J.source,contribution:{from:I,to:G}})}}let w=e.focus?d.filter(m=>m.source===e.focus||m.target===e.focus):d;return{from:n.id,to:t.id,focus:e.focus,steps:w}}var je=class{constructor(t=64){Y(this,"cell");Y(this,"bins",new Map);Y(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),g=Math.floor((t+r)/this.cell),w=Math.floor((e-r)/this.cell),m=Math.floor((e+r)/this.cell);for(let M=d;M<=g;M++)for(let z=w;z<=m;z++){let E=this.bins.get(this.key(M,z));if(E)for(let T of E){let P=T.x-t,_=T.y-e,I=(T.z??0)-s;P*P+_*_+I*I<=l&&i.push(T)}}return i}};var Ue=class{constructor(t=64){Y(this,"particles",[]);Y(this,"hash");this.hash=new je(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 tr(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 er(n){for(let t of n)if(t.vis&&t.tokens.indexOf("sink")>=0)return t;return null}var $i=[.24,.4,.55,.7,.85];function nr(n){let t=[];for(let e=0;e<5;e++)t.push({baseFrac:$i[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 or(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 g=t-l.x,w=260,m=Math.exp(-(g*g)/(2*w*w));d+=(l.y-d)*.42*m*l.k*(.45+n.depth*.55)}return d}function rr(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 xe(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 sr(n,t,e,r,s,i,l,d,g=1,w=1,m){if(l==="circular"){let M=t-d.x,z=e-d.y,E=Math.sqrt(M*M+z*z)||.001,T=Math.atan2(z,M),P=Math.min(s,i)*.48,_=xe(n,T,r,P,g,w);return{dist:Math.abs(E-_),rWave:_,r:E,theta:T}}else{let M=Et(n,t,r,i,g,w,m);return{dist:Math.abs(e-M),rWave:M,r:e,theta:0}}}var Yt={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null};function Gt(n,t,e,r,s){Yt.x=r,Yt.y=s,Yt.vx=0,Yt.vy=0,Yt.heat=0;let i=0,l=0;for(let d of n){if(!d.vis||d.tokens.length===0)continue;let g,w;if(d.shaped){let z=d.cx-d.hw,E=d.cx+d.hw,T=d.cy-d.hh,P=d.cy+d.hh;g=(r<z?z:r>E?E:r)-r,w=(s<T?T:s>P?P:s)-s}else g=d.cx-r,w=d.cy-s;let m=g*g+w*w;if(d.range>0&&m>=d.range*d.range*2.56)continue;let M=Math.sqrt(m);e.dx=g,e.dy=w,e.dist=M<1?1:M;for(let z of d.tokens){let E=t[z];if(!(!E||E.modify))if(E.field){let T=E.field(d,r,s);i+=T.x,l+=T.y}else E.apply(d,Yt,e)}}return{fx:Yt.vx+i,fy:Yt.vy+l}}function Ye(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,g=l.cy-r;if(d*d+g*g>=l.range*l.range*2.56)continue}for(let d of l.tokens){let g=t[d];if(g?.field){let w=g.field(l,e,r);s+=w.x,i+=w.y}}}return{x:s,y:i}}var ir=.95,ar=.972,At=10;function Ii(n,t,e,r){if(!t.when)return!0;let s=n[t.when];return s?s(t,e,r):!0}function cr(n){return n.classified??(n.classified=Be(n.tokens))}function qn(n,t,e,r,s=1){let i=e.vx,l=e.vy,d=e.vz??0,g=e.heat,w=e.spin??0,m=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,T=(e.vz??0)-d;(z!==0||E!==0||T!==0)&&(M.linear.x+=z,M.linear.y+=E,M.linear.z+=T,M.attribution.push({force:n.token,channel:"linear",contribution:{x:z,y:E,z:T}}));let P=e.heat-g;P!==0&&(M.thermal=(M.thermal??0)+P,M.attribution.push({force:n.token,channel:"thermal",contribution:P}));let _=(e.spin??0)-w;if(_!==0){let I=M.angular??(M.angular={x:0,y:0,z:0});I.z+=_,M.attribution.push({force:n.token,channel:"angular",contribution:_})}if(m!==void 0&&e.age!==void 0){let I=e.age-m;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 Wn(n,t,e,r,s){if(r.accum===void 0){if(s===1||n.kinematic){if(n.kinematic&&r.integrator==="velocity-verlet"){let g=e.vx,w=e.vy,m=e.vz??0;n.apply(t,e,r),(e.vx!==g||e.vy!==w||(e.vz??0)!==m)&&(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}qn(n,t,e,r,s)}function fr(){return{linear:{x:0,y:0,z:0},attribution:[]}}function lr(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 dr(n){let{store:t,bodies:e,env:r,forces:s,conditions:i,waves:l,separation:d}=n,g=r.dt;if(g===0){lr(e);return}let w=r.integrator==="velocity-verlet",{W:m,H:M,form:z}=r;r.fieldAt=(y,X)=>Ye(e,s,y,X),lr(e);let E=null;for(let y of e)y.vis&&y.tokens.length>0&&cr(y).modifiers.indexOf("screen")>=0&&(E??(E=[])).push(y);let T=E?new Array(E.length):null,P=!!l&&l.length>0,_=e.length>0,I=null,G=z.conv>.02?er(e):null,J=r.D??0;for(let y of t.particles){if(y.cap){y.x+=(y.cap.cx-y.x)*.18,y.y+=(y.cap.cy-y.y)*.18,y.z&&(y.z+=-y.z*.18),y.ax!==void 0&&(y.ax=y.ay=y.az=0);continue}y.z===void 0&&(y.z=0),y.vz===void 0&&(y.vz=0);let X=0,bt=0,tt=0;if(w){let q=.5*g*g;y.x+=y.vx*g+(y.ax??0)*q,y.y+=y.vy*g+(y.ay??0)*q,y.z+=y.vz*g+(y.az??0)*q,X=y.vx,bt=y.vy,tt=y.vz,r.kinTouch=!1}let Se=y.z;if(P)if(n.waveStyle==="circular"){let q=null,A=1e9,j=0,et=0,nt=0,wt=n.waveCenter||{x:m/2,y:M/2};for(let ut of l){let Ft=sr(ut,y.x,y.y,r.t,m,M,"circular",wt);Ft.dist<A&&(A=Ft.dist,q=ut,j=Ft.r,et=Ft.rWave,nt=Ft.theta)}if(q&&A<70){let ut=1-A/70,Ft=-Math.sin(nt)*q.dir,Xt=Math.cos(nt)*q.dir;y.vx+=Ft*.035*ut,y.vy+=Xt*.035*ut;let Nt=Math.cos(nt)*Math.sign(et-j),O=Math.sin(nt)*Math.sign(et-j);y.vx+=Nt*.05*ut,y.vy+=O*.05*ut}}else{let q=null,A=1e9;for(let j of l){let et=Math.abs(Et(j,y.x,r.t,M)-y.y);et<A&&(A=et,q=j)}q&&A<70&&(y.vx+=q.dir*.035*(1-A/70),y.vy+=rr(q,y.x,r.t)*.1*(1-A/70))}if(z.driftX&&(y.vx+=z.driftX*.02),z.spread>.02){let q=y.gx??.5,A=y.gy??.5,j=(q+r.frameN*4e-5)%1*m,et=A*M;y.vx+=(j-y.x)*6e-4*z.spread,y.vy+=(et-y.y)*6e-4*z.spread,J>0&&(y.vz+=((y.gz??.5)*J-Se)*6e-4*z.spread)}if(G){let q=G.cx-y.x,A=G.cy-y.y,j=-Se,et=Math.hypot(q,A,j)||1;y.vx+=q/et*z.conv*.06,y.vy+=A/et*z.conv*.06,y.vz+=j/et*z.conv*.06}if(_){if(E)for(let A=0;A<E.length;A++){let j=E[A],et=j.cx-y.x,nt=j.cy-y.y;T[A]=Uo(Math.sqrt(et*et+nt*nt),j.range,j.strength,j.screenMin??0)}let q=y.m!==1&&y.m>0?1/y.m:1;for(let A of e){if(!A.vis||A.tokens.length===0||A.affects!==void 0&&!A.affects.has(y.species??0))continue;let j,et;if(A.shaped){let R=A.cx-A.hw,Z=A.cx+A.hw,ot=A.cy-A.hh,ee=A.cy+A.hh,ue=y.x<R?R:y.x>Z?Z:y.x,he=y.y<ot?ot:y.y>ee?ee:y.y;j=ue-y.x,et=he-y.y}else j=A.cx-y.x,et=A.cy-y.y;let nt=-y.z,wt=j*j+et*et+nt*nt;if(A.range>0&&wt>=A.range*A.range*2.56)continue;let ut=Math.sqrt(wt);if(A.feedback&&ut<A.range*.5){A.count+=1-ut/(A.range*.5);let R=A.thermo??(A.thermo={n:0,sx:0,sy:0,ss:0,ss2:0,sh:0}),Z=y.vx*y.vx+y.vy*y.vy;R.n++,R.sx+=y.vx,R.sy+=y.vy,R.ss+=Math.sqrt(Z),R.ss2+=Z,R.sh+=y.heat}if(A.when&&!Ii(i,A,y,r))continue;r.dx=j,r.dy=et,r.dz=nt,r.dist=ut<1?1:ut;let Ft=cr(A),Xt=1,Nt=!1,O=!1;for(let R of Ft.modifiers){let Z=s[R]?.modify;if(!Z)continue;O=!0;let ot=Z(A,y,r);ot.strength!=null&&(Xt*=ot.strength),ot.gate&&(Nt=!0)}for(let R of Ft.forces){let Z=s[R]?.modify;if(!Z)continue;O=!0;let ot=Z(A,y,r);ot.strength!=null&&(Xt*=ot.strength),ot.gate&&(Nt=!0)}if(Nt)continue;let ct=1;if(E)for(let R=0;R<E.length;R++)E[R]!==A&&(ct*=T[R]);let B=A.attn??1,L=Xt*B*ct*(A.focusMul??1);if(!O&&L===1)for(let R of A.tokens){let Z=s[R];Z&&Wn(Z,A,y,r,q)}else if(O){let R=A.strength;A.strength=R*L;for(let Z of A.tokens){let ot=s[Z];ot&&!ot.modify&&Wn(ot,A,y,r,q)}A.strength=R}else{let R=A.strength;A.strength=R*L;for(let Z of A.tokens){let ot=s[Z];ot&&Wn(ot,A,y,r,q)}A.strength=R}}}if(d&&d>0){let q=r.neighbors(y,12);for(let A of q){let j=y.x-A.x,et=y.y-A.y,nt=(y.z??0)-(A.z??0),wt=Math.hypot(j,et,nt)||.1;if(wt<12){let ut=(12-wt)/12*d*.12;y.vx+=j/wt*ut,y.vy+=et/wt*ut,y.vz!==void 0&&(y.vz+=nt/wt*ut)}}}if(w){let q=y.vx-X,A=y.vy-bt,j=y.vz-tt;r.kinTouch?y.ax=y.ay=y.az=0:(y.vx=X+.5*((y.ax??0)*g+q),y.vy=bt+.5*((y.ay??0)*g+A),y.vz=tt+.5*((y.az??0)*g+j),y.ax=q/g,y.ay=A/g,y.az=j/g)}let Vt=r.c,Ee=y.vx*y.vx+y.vy*y.vy+y.vz*y.vz;if(Ee>Vt*Vt){let q=Vt/Math.sqrt(Ee);y.vx*=q,y.vy*=q,y.vz*=q}if(y.maxSpeed!==void 0){let q=y.maxSpeed*y.maxSpeed,A=y.vx*y.vx+y.vy*y.vy+y.vz*y.vz;if(A>q){let j=y.maxSpeed/Math.sqrt(A);y.vx*=j,y.vy*=j,y.vz*=j}}w||(y.x+=y.vx*g,y.y+=y.vy*g,y.z+=y.vz*g);let It=r.integrator==="fixed"||w?Math.pow(ir,g):ir;if(y.vx*=It,y.vy*=It,y.vz*=It,y.spin!==void 0&&(y.orient=(y.orient??0)+y.spin*g,y.spin*=It),y.report===void 0){if(r.frameN%40===0&&z.wander>0){let q=.05*z.wander;y.vx+=((r.rng??Math.random)()-.5)*q,y.vy+=((r.rng??Math.random)()-.5)*q,J>0&&(y.vz+=((r.rng??Math.random)()-.5)*q)}if(z.wander>.05){let q=(Math.sin(y.x*.0032+r.t*.12)+Math.cos(y.y*.0034-r.t*.15))*Math.PI;y.vx+=Math.cos(q)*.013*z.wander,y.vy+=Math.sin(q)*.013*z.wander}}y.heat*=r.integrator==="fixed"||w?Math.pow(ar,g):ar,y.age!=null&&(y.age-=g,y.age<=0&&(I??(I=[])).push(y)),y.report===void 0?(y.x<-At?y.x=m+At:y.x>m+At&&(y.x=-At),y.y<-At?y.y=M+At:y.y>M+At&&(y.y=-At),J>0&&(y.z<-At?y.z=J+At:y.z>J+At&&(y.z=-At))):(y.x<0?(y.x=0,y.vx=Math.abs(y.vx)):y.x>m&&(y.x=m,y.vx=-Math.abs(y.vx)),y.y<0?(y.y=0,y.vy=Math.abs(y.vy)):y.y>M&&(y.y=M,y.vy=-Math.abs(y.vy)),J>0&&(y.z<0?(y.z=0,y.vz=Math.abs(y.vz)):y.z>J&&(y.z=J,y.vz=-Math.abs(y.vz))),y.report(y))}if(_){for(let y of e)if(!(!y.vis||y.tokens.length===0))for(let X of y.tokens)s[X]?.source?.(y,r)}if(I)for(let y of I)t.remove(y)}var de=class{constructor(t,e,r="diffuse",s=32){Y(this,"mode");Y(this,"cell");Y(this,"W");Y(this,"H");Y(this,"cols");Y(this,"rows");Y(this,"cur");Y(this,"nxt");Y(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,g=s-l,w=this.at(i,l)*(1-d)+this.at(i+1,l)*d,m=this.at(i,l+1)*(1-d)+this.at(i+1,l+1)*d;return w*(1-g)+m*g}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:g}=this;for(let w=0;w<l;w++)for(let m=0;m<i;m++){let M=w*i+m,z=this.at(m-1,w)+this.at(m+1,w)+this.at(m,w-1)+this.at(m,w+1)-4*d[M];g[M]=(d[M]+r*z)*s}this.cur=g,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:g,nxt:w}=this;for(let m=0;m<l;m++)for(let M=0;M<i;M++){let z=m*i+M,E=this.at(M-1,m)+this.at(M+1,m)+this.at(M,m-1)+this.at(M,m+1)-4*d[z];w[z]=(2*d[z]-g[z]+r*E)*s}this.prev=d,this.cur=w,this.nxt=g}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 ur={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 hr(){let n={},t={...ur};return{forces:n,conditions:t,force(e){n[e.token]=e},condition(e,r){t[e]=r}}}var Ni={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"}},Di={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"}},_i={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,g=e.dy/e.dist;t.vx+=g*i*l+d*i*.12,t.vy+=-d*i*l+g*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"}},Li={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"}},Bi={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"}},Wi={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,g=n.ux*l+n.uy*i,w=2.4+n.strength*2.6;t.vx=d*w,t.vy=g*w,t.x=n.cx+d*26,t.y=n.cy+g*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"}},qi={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,g=e.dy/e.dist;t.vx+=d*l*i,t.vy+=g*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"}},Hi={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,g=n.hh+6-i;d<g?(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??Wo.wall.color),t.heat=Math.max(t.heat,Math.min(.85,l*.4)))},meta:{desc:"axis-aligned bouncing wall \u2014 sparks on impact"}},ji={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"}},Ui=[Ni,Wi,qi,Hi,Li,Di,Bi,_i,ji];function yr(n){for(let t of Ui)n.force(t)}var jn=1.5,Yi=8,Gi=60;function Vi(n,t,e,r){let s=He(n);if(Math.hypot(s[0].x-s[1].x,s[0].y-s[1].y)<Math.max(n.range*.06,Yi)){let g=Math.max(n.range*.18,Gi),w=n.spin<0?-1:1;s=[{x:n.cx+n.ux*g,y:n.cy+n.uy*g,q:w},{x:n.cx-n.ux*g,y:n.cy-n.uy*g,q:-w}]}let l=r*(1+jn*(n.d??0)),d=Yo(s,t,e);return{x:d.x*l,y:d.y*l}}function Xi(n,t,e,r){return Go(n.cx,n.cy,n.spin,r*(1+jn*(n.d??0)),t,e)}function mr(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),Un(t,e.c)}function Un(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 Ki(n,t,e){let r=n.cx-t,s=n.cy-e,i=Math.max(Math.hypot(r,s),qe),l=n.M*(1+jn*(n.d??0))/(i*i);return{x:r/i*l,y:s/i*l}}var Ji={token:"gravity",label:"Gravity",apply(n,t,e){mr(n,t,e,e.G*n.M)},field:(n,t,e)=>Ki(n,t,e),meta:{desc:"true softened inverse-square gravity (a real 1/d\xB2 law)"}},Qi={token:"charge",label:"Charge",apply(n,t,e){let r=t.charge??0;r!==0&&mr(n,t,e,-(n.spin*r*e.G*n.M))},field:(n,t,e)=>Xi(n,t,e,n.M),meta:{desc:"signed inverse-square \u2014 like repels, opposite attracts"}},Zi={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),g=t.vx;t.vx=g*l-t.vy*d,t.vy=g*d+t.vy*l},field:(n,t,e)=>Vi(n,t,e,n.strength),meta:{desc:"Lorentz force \u2014 curves a moving charge perpendicular to its velocity"}};function ta(n){return Math.sqrt(2*Math.max(0,n))}var ea={token:"thermal",label:"Thermal",apply(n,t,e){if(e.dist>=n.range)return;let r=1-e.dist/n.range,s=ta(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 g=(e.rng??Math.random)()||1e-9;t.vz=(t.vz??0)+s*Math.sqrt(-2*Math.log(g))*Math.cos(2*Math.PI*(e.rng??Math.random)())}n.on&&(t.heat=Math.max(t.heat,r*.4)),Un(t,e.c)},meta:{desc:"Langevin/Brownian agitation \u2014 a real temperature in the medium"}},na={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,g=t.y-i.y,w=(t.z??0)-(i.z??0),m=Math.hypot(d,g,w);if(m>=s+l||m<1e-6)continue;let M=d/m,z=g/m,E=w/m,T=(t.vx-i.vx)*M+(t.vy-i.vy)*z+((t.vz??0)-(i.vz??0))*E;if(T>=0)continue;let P=(1+r)*.5*T;t.vx-=P*M,t.vy-=P*z,i.vx+=P*M,i.vy+=P*z,w&&(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"}},oa={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"}},ra=12,Hn=7,sa={token:"propagate",label:"Propagate",source(n,t){n.on&&t.frameN%ra===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*Hn,t.vy+=d*i*n.strength*Hn,e.dz&&(t.vz=(t.vz??0)+-e.dz/e.dist*i*n.strength*Hn),Un(t,e.c)},meta:{desc:"a travelling wave \u2014 a shock train expands from the source, sweeping matter out"}},ia={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"}},aa=[Ji,Qi,Zi,ea,na,oa,sa,ia];function pr(n){for(let t of aa)n.force(t)}var ca={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"}},la={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"}},fa=1,da=1,ua={token:"buoyancy",label:"Buoyancy",apply(n,t,e){if(n.range>0&&e.dist>=n.range)return;let r=fa/(t.size*(1+t.heat));t.vy-=(da-r)*n.strength},meta:{desc:"a constant lift/sink by density difference \u2014 light matter rises, dense settles"}},ha={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"}},Ge=32,ya=.5,ma={token:"crystallize",label:"Crystallize",apply(n,t,e){if(e.dist>=n.range||t.heat>=ya)return;let r=n.cx+Math.round((t.x-n.cx)/Ge)*Ge,s=n.cy+Math.round((t.y-n.cy)/Ge)*Ge;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"}},pa={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,g=0,w=0,m=0,M=0;for(let E of e.neighbors(t,n.range)){let T=E.vz??0,P=Math.hypot(E.vx,E.vy,T);P>1e-6&&(w+=E.vx/P,m+=E.vy/P,M+=T/P)}let z=Math.hypot(w,m,M);z>1e-6&&(l=w/z,d=m/z,g=M/z),t.vx+=(l*s-t.vx)*i,t.vy+=(d*s-t.vy)*i,(g||r)&&(t.vz=r+(g*s-r)*i)},meta:{desc:"steers toward the neighbour-mean heading (or the body heading when alone)"}};function ga(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 xa=.01,va={token:"wind",label:"Wind",apply(n,t,e){if(n.range>0&&e.dist>=n.range)return;let r=ga(t.x,t.y,e.t,xa);t.vx+=r.x*n.strength,t.vy+=r.y*n.strength},meta:{desc:"divergence-free curl-noise turbulence"}},ba=.5,wa={token:"cohesion",label:"Cohesion",apply(n,t,e){if(e.dist>=n.range)return;let r=n.range,s=r*ba,i=n.strength;for(let l of e.neighbors(t,r)){let d=l.x-t.x,g=l.y-t.y,w=(l.z??0)-(t.z??0),m=Math.hypot(d,g,w);if(m<1e-6)continue;let M=d/m,z=g/m,E=w/m;if(m<s){let T=i*(s-m)/s;t.vx-=T*M,t.vy-=T*z,w&&(t.vz=(t.vz??0)-T*E)}else{let T=i*(m-s)/(r-s);t.vx+=T*M,t.vy+=T*z,w&&(t.vz=(t.vz??0)+T*E)}}},meta:{desc:"short-range pressure + mid-range cohesion \u2014 surface tension over neighbours"}},Ma=.5,ka={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 g of l){let w=Math.hypot(g.x-t.x,g.y-t.y,(g.z??0)-(t.z??0));w<r&&(i+=(1-w/r)**2)}let d=i-Ma;if(!(d<=0))for(let g of l){let w=t.x-g.x,m=t.y-g.y,M=(t.z??0)-(g.z??0),z=Math.hypot(w,m,M);if(z<1e-6||z>=r)continue;let E=s*d*(1-z/r)/z;t.vx+=E*w,t.vy+=E*m,M&&(t.vz=(t.vz??0)+E*M)}},meta:{desc:"SPH density relaxation \u2014 incompressible even-fill via mutual repulsion"}},Sa={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,T=(M.z??0)-(t.z??0),P=z*z+E*E+T*T;P<i&&(i=P,s=M)}if(!s)return;let l=s.x-t.x,d=s.y-t.y,g=(s.z??0)-(t.z??0),w=Math.hypot(l,d,g)||1,m=r===0?1:-1;t.vx+=l/w*n.strength*m,t.vy+=d/w*n.strength*m,g&&(t.vz=(t.vz??0)+g/w*n.strength*m)},meta:{desc:"two-species pursuit \u2014 predators seek prey, prey flee predators"}},Ea=.35,Fa={token:"link",label:"Link",apply(n,t,e){if(e.dist>=n.range)return;let r=n.range,s=r*Ea,i=n.strength;for(let l of e.neighbors(t,r)){let d=l.x-t.x,g=l.y-t.y,w=(l.z??0)-(t.z??0),m=Math.hypot(d,g,w);if(m<1e-6)continue;let M=m-s,z=.5*i*(M/s);t.vx+=z*(d/m),t.vy+=z*(g/m),w&&(t.vz=(t.vz??0)+z*(w/m))}},meta:{desc:"a Verlet distance constraint \u2014 holds a rest length, so matter ropes and drapes"}},gr=40,za={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,g=Math.hypot(l,d),w=n.strength;t.vx+=l*w*.02,t.vy+=d*w*.02,t.z&&(t.vz=(t.vz??0)-t.z*w*.02);let M=(1-(g<gr?1-g/gr:0))*w*.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)"}},Aa=90,Ta={token:"spawn",label:"Spawn",apply(){},source(n,t){let e=n.life??Aa,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),g=n.ux*l-n.uy*d,w=n.ux*d+n.uy*l,m=2+(t.rng??Math.random)()*2;t.spawn({x:n.cx,y:n.cy,vx:g*m,vy:w*m,age:e,heat:.6,...n.species!=null?{species:n.species}:{}})}},meta:{desc:"a source \u2014 emits matter along the heading, budgeted by a lifespan"}},Ca=3,Oa={token:"resonate",label:"Resonate",apply(){},modify(n,t,e){return{strength:1+Math.sin(e.t*Ca*n.spin)}},meta:{desc:"pulses sibling forces with a time-varying strength S(t)=S\u2080(1+sin \u03C9t)"}},Ra=.5,Pa={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<Ra}},meta:{desc:"gates sibling forces to an angular cone of the heading"}},$a={token:"screen",label:"Screen",apply(){},meta:{desc:"a quiet zone \u2014 attenuates other bodies' forces on matter inside its radius"}},Ia={token:"pigment",label:"Pigment",apply(n,t,e){let r=n.tint;!r||e.dist>=n.range*.6||(t.color=t.color?jo(t.color,r,.08):r)},meta:{desc:"conserved color transport \u2014 matter takes on and carries a tint"}},Na=.5,xr=.12,Da={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,g=n.strength*d,w=t.vz??0,m=Math.hypot(t.vx,t.vy,w);if(m>1e-6){let E=Math.min(1,g*Na);t.vx+=(i*m-t.vx)*E,t.vy+=(l*m-t.vy)*E,w&&(t.vz=w+(0-w)*E)}t.vx+=i*g*xr,t.vy+=l*g*xr;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"}},_a={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,g=-e.dy/e.dist,w=d*s-g*i,m=d*i+g*s,M=r*l+6;t.x=n.warpX+w*M,t.y=n.warpY+m*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"}},La=[ca,la,ua,ha,ma,pa,va,wa,ka,Fa,Sa,za,Ta,Oa,Pa,$a,Ia,Da,_a];function vr(n){for(let t of La)n.force(t)}var br=new Set(["css","canvas","svg","typography","spatial","native"]);function wr(n){let t=[];for(let e of n)e.surfaces.some(s=>br.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=>br.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 Yn=(n,t)=>t?Object.fromEntries(Object.entries(n).filter(([e])=>t.has(e))):n;function Mr(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:Yn(n.metrics,e),bodies:n.bodies.filter(i=>!s||i.tokens.some(l=>s.has(l))).map(i=>({...i,metrics:Yn(i.metrics,e),dimensions:Yn(i.dimensions,e)})),influences:r?n.influences.filter(i=>r.has(i.channel??"linear")):n.influences,lens:t.id}}function kr(n,t,e={}){return{x:n,y:t,strength:e.strength??1,radius:e.radius&&e.radius>0?e.radius:360}}function ve(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 g=(1-d/r.radius)*r.strength*s;return n.x=i/d*g,n.y=l/d*g,n}var Ba={step:6,maxSteps:400,minStrength:1e-9,loopDist:6,maxTurns:1/0};function Sr(n,t,e,r,s){let i=[{x:t,y:e}],l=t,d=e,g=s.step,w=s.maxTurns*2*Math.PI,m=0,M=0,z=0;for(let E=0;E<s.maxSteps;E++){let T=n(l,d),P=Math.hypot(T.x,T.y);if(!(P>=s.minStrength))break;let _=T.x/P*r,I=T.y/P*r;if(Number.isFinite(w)){if(m!==0||M!==0){let G=Math.max(-1,Math.min(1,_*m+I*M));if(z+=Math.acos(G),z>w)break}m=_,M=I}if(l+=_*s.step,d+=I*s.step,s.bounds&&(l<-g||d<-g||l>s.bounds.w+g||d>s.bounds.h+g))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 Wa(n,t,e,r={}){let s={...Ba,bounds:r.bounds,...r},i=Sr(n,t,e,-1,s),l=Sr(n,t,e,1,s);return i.reverse(),i.pop(),i.concat(l)}function Er(n,t,e={}){return t.map(r=>Wa(n,r.x,r.y,e)).filter(r=>r.length>1)}var qa=8,Ha=60;function Fr(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=He(e),s=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y);if(s<Math.max(n.range*.06,qa)){let w=Math.max(n.range*.18,Ha),m=n.spin<0?-1:1;r=[{x:n.cx+n.ux*w,y:n.cy+n.uy*w,q:m},{x:n.cx-n.ux*w,y:n.cy-n.uy*w,q:-m}],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),g=[{x:n.cx,y:n.cy}];for(let w=1;w<=t;w++){let m=w*d;g.push({x:n.cx+i*m,y:n.cy+l*m}),g.push({x:n.cx-i*m,y:n.cy-l*m})}return g}function zr(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 Ar(n,t=8){let e=[];for(let r of n)!r.vis||r.tokens.length===0||(r.tokens.includes("magnetism")?e.push(...Fr(r,t)):(r.tokens.includes("charge")||r.tokens.includes("gravity"))&&e.push(...zr(r)));return e}function Tr(n,t=Math.random){return 3+Math.floor(t()*(n>0?n:1)*3)}var Cr=160;function Or(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 Rr(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 Pr(n,t=.02){return{x:-n.x*t,y:-n.y*t}}function $r(n){let t=n/3e4;return t<.6?.6:t>6?6:t}function Ir(n,t,e=-1,r=1600,s=26){let i=0,l=0,d=s*s;for(let g=0;g<t.length;g++){if(g===e)continue;let w=t[g],m=n.x-w.x,M=n.y-w.y,z=m*m+M*M+d;i+=r*m/z,l+=r*M/z}return{x:i,y:l}}function Nr(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 Dr(n,t,e,r,s,i,l,d){if(r.length===0)return;let g=n.particles;for(let w=g.length-1;w>=0&&!(t.length>=e);w--){let m=g[w];if(!m||m.cap||m.heat>=.12)continue;let M=-1,z=1e9,E=0;for(let P=0;P<r.length;P++){let _=Et(r[P],m.x,l,i),I=Math.abs(_-m.y);I<z&&(z=I,M=P,E=_)}if(M<0||z>=64)continue;let T=Math.min(.012,z*4e-4)*(1-m.heat/.12);m.vy+=E>m.y?T:-T,z<20&&m.vx*m.vx+m.vy*m.vy<.3&&d()<.03&&(t.push({wi:M,progress:m.x/s,phase:(d()-.5)*.22*Math.PI,size:m.size,glow:d()<.3,speed:(35e-5+d()*9e-4)*(d()<.5?1:-1)}),n.remove(m))}}function Gn(n,t,e,r,s,i,l,d,g){for(let w=n.length-1;w>=0;w--){let m=n[w];if(!m)continue;let M=t[m.wi];if(!M)continue;let z=m.progress*i,E=Et(M,z,d,l)+m.phase*32,T=z-e,P=E-r,_=Math.hypot(T,P);if(_<s&&_>.5){let I=(1-_/s)*4;g({x:z,y:E,vx:T/_*I,vy:P/_*I,size:m.size,heat:.9});let G=n.pop();G&&w<n.length&&(n[w]=G)}}}function _r(n,t,e,r,s,i,l,d){let g=w=>w.tokens.some(m=>{let M=r[m];return!!M&&!M.modify&&!M.source});for(let w=n.length-1;w>=0;w--){let m=n[w];if(!m)continue;let M=t[m.wi];if(!M)continue;let z=m.progress*s,E=Et(M,z,l,i)+m.phase*32,T=!1,P=0,_=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,y=I.cy-E,X=Math.hypot(J,y)||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,_=(E<I.cy?-1:1)*.8,T=!0),!T&&(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,_=y/X*tt,T=!0}if(!T&&G.indexOf("repel")>=0&&X<bt*.8){let tt=1.2+(I.on?1.2:0);P=-(J/X)*tt,_=-(y/X)*tt,T=!0}if(!T&&G.indexOf("swirl")>=0&&X<bt*.75&&(P=y/X*1.2,_=-(J/X)*1.2,T=!0),!T&&G.indexOf("stream")>=0&&X<bt*.75&&(P=I.ux*1.3,_=I.uy*1.3,T=!0),!T&&X<bt*.8&&g(I)){let tt=.8+(I.on?.8:0);P=J/X*tt,_=y/X*tt,T=!0}if(T)break}if(T){d({x:z,y:E,vx:P,vy:_,size:m.size,heat:.5});let I=n.pop();I&&w<n.length&&(n[w]=I)}}}function Lr(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)}}}function be(n,t,e){if(!Number.isFinite(n)||!Number.isFinite(t))return 0;let r=t-n;return r<=0?1:!Number.isFinite(e)||e<=0?0:Math.pow(2,-r/e)}var Br=n=>n<0?0:n>1?1:n;function Wr(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=Br(.5*t+.5*Math.min(1,r/9)),i=n.ss>1e-9?Math.hypot(n.sx,n.sy)/n.ss:1,l=Br((1-i)*Math.min(1,e/1.5));return{entropy:l,coherence:1-l,temperature:s}}var Ve=class{constructor(){Y(this,"pending",new Map);Y(this,"ids",new WeakMap);Y(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==="focus"){let s=e;return`focus:${s.target}:${s.source}`}if(t==="met"){let s=e,[i,l]=[this.idOf(s.a.el??s.a),this.idOf(s.b.el??s.b)].sort((d,g)=>d-g);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 Vn(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 Xn(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 qr={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 ja(){return globalThis.process?.env?.NODE_ENV!=="production"}var jr=ja();function Ur(){return jr}var Hr=new Set;function Kn(n,t){if(!jr)return;let e=`${n}:${t}`;Hr.has(e)||(Hr.add(e),console.warn(`[Fundamental:${n}] ${t}`))}var Ua={"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 Yr(n,t={}){let e=Ua[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 Vr(n){let t=(P,_)=>{let I=Number.parseFloat(n.get(P)??"");return Number.isFinite(I)?I:_},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=Be(l),g=n.get("life"),w=n.get("cap"),m=Number.parseFloat(g??""),M=Number.parseFloat(w??""),z=g!=null||w!=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(m)&&m>0?{life:m}:{},...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 _=P.split(",").map(I=>Number.parseFloat(I.trim())).filter(I=>Number.isFinite(I));return _.length?{affects:new Set(_)}:{}})(),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 Ya(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 Ga(n){let t=qr[n];return t?t.map(e=>Vr(Ya(e))):[]}function Va(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 Xa(n,t="<body>"){!n.classified||n.classified.sources.length===0||n.budgeted||(n.life=Pn,n.cap=$n,Ur()&&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="${Pn}", data-cap="${$n}") \u2014 declare one to make the source's budget explicit (workover v0.3 source rules).`))}function Xr(n,t){return Xa(t,Va(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 Ka(n){return{get:t=>n.getAttribute("data-"+t),has:t=>n.hasAttribute("data-"+t)}}function we(n,t){return Xr(n,Vr(t??Ka(n)))}var Gr={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=Yr(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 Gr&&(t={body:Gr[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 Xe="data-field-boundary",Qa=`[${Xe}]`;function Jn(n,t){if(typeof n.closest!="function")return!0;let e=n.closest(Qa);return e===null||e===t}function Kr(n){let t=[];return n.querySelectorAll("[data-body]").forEach(e=>{Jn(e,n)&&t.push(we(e))}),n.querySelectorAll("[data-preset]").forEach(e=>{if(!Jn(e,n))return;let r=e;for(let s of Ga(r.dataset.preset??""))t.push(Xr(r,s))}),n.querySelectorAll("[data-intent]:not([data-body]), [data-field-role]:not([data-body]):not([data-intent])").forEach(e=>{if(!Jn(e,n))return;let r=Ja(e);r&&t.push(we(e,r))}),t}function Za(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 Ke(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(),g=d.left-r,w=d.top-s;l.cx=g+d.width/2,l.cy=w+d.height/2,l.hw=d.width/2,l.hh=d.height/2,l.on=l.el.dataset.active==="1",l.vis=w+d.height>-i&&w<e+i&&g+d.width>-i&&g<t+i,Za(l)}}var Jr="field:register-body",Qr="field:unregister-body",Zr="field:update-body";var Je=class{constructor(){Y(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?tc(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 tc(n,t){return{get:e=>n[e]??t.getAttribute("data-"+e),has:e=>e in n||t.hasAttribute("data-"+e)}}function ns(n,t,e=.12){return n>=t?0:(1-n/t)*e}function Qe(n,t,e){if(n===t)return .5;let r=(e-n)/(t-n);return r<0?0:r>1?1:r}var ts=Object.freeze([]);function Qn(n,t,e,r,s){let i={x:Qe(n,t,s),y:0},l={x:1,y:Qe(t,e,s)},d={x:Qe(r,e,s),y:1},g={x:0,y:Qe(n,r,s)},w=(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 ts;case 1:case 14:return[w(g,d)];case 2:case 13:return[w(d,l)];case 3:case 12:return[w(g,l)];case 4:case 11:return[w(i,l)];case 6:case 9:return[w(i,d)];case 7:case 8:return[w(g,i)];case 5:return[w(g,i),w(d,l)];case 10:return[w(g,d),w(i,l)];default:return ts}}function Zn(n,t,e,r,s,i,l,d=1){if(l<=0)return;let g=Math.max(0,Math.floor((s-l)/r)),w=Math.min(t-1,Math.ceil((s+l)/r)),m=Math.max(0,Math.floor((i-l)/r)),M=Math.min(e-1,Math.ceil((i+l)/r)),z=l*l;for(let E=m;E<=M;E++)for(let T=g;T<=w;T++){let P=T*r-s,_=E*r-i,I=P*P+_*_;if(I>=z)continue;let G=1-Math.sqrt(I)/l,J=E*t+T;n[J]=n[J]+d*G*G}}function os(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,g=l.y-t,w=d*d+g*g;w<s&&(s=w,r=i)}return r}function rs(n,t,e=1){let r=(n*2.6+t*2.5)*e;return r<2?2:r}function ss(n,t,e,r,s,i){let l=n-s,d=t-i,g=Math.hypot(l,d);return g<1e-6?0:(l*e+d*r)/g}function is(n,t){if(t<=0)return 0;let e=n/(.35*t);return e<-1?-1:e>1?1:e}function as(n,t){return t<=0||n>=t?0:1-Math.sqrt(n/t)}function cs(n,t){let e=n+t*.6;return e<-1?-1:e>1?1:e}var ec=[96,160,255],es=[226,230,240],nc=[255,72,48];function ls(n,t){let e=t<-1?-1:t>1?1:t,r=e<0?ec:es,s=e<0?es:nc,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 fs(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 Ze=[[12,2,0],[130,24,2],[235,100,10],[255,180,90],[255,236,200],[201,218,255]];function ds(n,t){let r=(t<0?0:t>1?1:t)*(Ze.length-1),s=Math.min(Math.floor(r),Ze.length-2),i=r-s,l=Ze[s],d=Ze[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 us(n,t){let e=n<0?-n:n;return t/(t+e)}function to(n,t,e){return t+(n-t)*e}function hs(n){return 1-.55*(n<0?0:n>1?1:n)}function ys(n){return 4.5*(n<0?0:n>1?1:n)}function ms(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 ps=24,oc=.12,rc=.22,Me=class{constructor(t,e){Y(this,"grid");Y(this,"peak",.001);Y(this,"cell",ps);this.grid=new de(Math.max(1,t),Math.max(1,e),"diffuse",ps)}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(rc,oc);let e=this.grid.max(),r=e>this.peak?.25:.03;this.peak+=(Math.max(e,.001)-this.peak)*r}norm(t,e){return mt(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 sc={position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"0",pointerEvents:"none",display:"block"},gs=Object.entries(sc).map(([n,t])=>`${n.replace(/[A-Z]/g,e=>"-"+e.toLowerCase())}:${t}`).join(";");function ic(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 xs="10px ui-monospace, SFMono-Regular, Menlo, monospace";function eo(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,g,w,m,M){t.fillStyle=`rgba(${g},${w},${m},${M})`,t.fillRect(s,i,l,d)},text(s,i,l,d,g,w,m){t.font=xs,t.textBaseline="middle",t.fillStyle=`rgba(${d},${g},${w},${m})`,t.fillText(s,i,l)},measureText(s){return t.font=xs,t.measureText(s).width}}}var no=(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}})))}},vs=no;var tn=class{constructor(t){Y(this,"lit",!1);Y(this,"lastEdgeMs",-1/0);Y(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 ac={strengthen:1.5,decay:.3,remember:.2},oo=n=>n<0?0:n>1?1:n;function bs(n,t,e,r,s=ac){n.active=t,n.tension=oo(e),n.strength=oo(n.strength+(t?s.strengthen:-s.decay)*r),n.memory=oo(n.memory+(t?s.remember:-s.remember*.5)*r)}function ws(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 ro(n){if(n.capacity<=0)return 0;let t=n.accreted/n.capacity;return t<0?0:t>1?1:t}function Ms(n,t){return t&&!n?{fire:"captured",armed:!0}:!t&&n?{fire:"released",armed:!1}:{fire:null,armed:n}}function ks(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 so(n,t){let e=t.cx-n.x,r=t.cy-n.y;return e*e+r*r<t.absorbR*t.absorbR}function Ss(n,t,e=.14){let r=n+(t-n)*e;return r<.001?0:r>.999?1:r}function Es(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,g=1-r;return{tx:l,ty:d,scale:g,opacity:g}}function cc(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 lc(n){let t=0;for(let e of n)t+=e.heat;return t}function Fs(n){let t=cc(n),e=lc(n);return{kinetic:t,thermal:e,total:t+e,count:n.length}}var fc={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 dc(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 io(n,t,e,r,s,i=fc.neutral){let l=fr(),d=dc(e,r,s);d.accum=l;for(let g of t){let w=n[g];if(!w)continue;let m={x:r,y:s,vx:i.vx,vy:i.vy,charge:i.charge,m:i.m,heat:i.heat,size:1,cap:null};try{qn(w,e,m,d)}catch{}}return l}var en={x:0,y:0},gt=[0,0,0];function ao(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 uc(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 nn(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 g of n[d])g&&typeof g=="object"&&delete g[l];else if(i==="metrics"&&n.metrics&&typeof n.metrics=="object")delete n.metrics[l];else{let g=n[i];g&&typeof g=="object"&&delete g[l]}}return n}var hc=8,yc=8,mc=.05,zs=.02,pc=1,gc=2;function on(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?eo(r,s):null);function l(){i||(!r&&t.overlayCanvasProvider&&(r=t.overlayCanvasProvider()??null),!(!r||!e)&&(s??(s=r.getContext("2d")),s&&(i=t.overlayBackend??eo(r,s),i.size(L,R,A.viewport().dpr))))}let d=new Ue,g=1,w=new Map,m=hr(),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 T=new Ve;function P(o,a){z(o)&&T.record(o,a)}function _(){T.flush(E)}let I=new WeakMap,G=new Map,J=new Map;function y(o){let a=z("enter")||z("exit"),c=z("met");if(!a&&!c)return;for(let p=0;p<o.length;p++){let b=o[p];if(a){let h=G.get(b);h||G.set(b,h=new Set);let u=b.range*b.range;for(let f=0;f<o.length;f++){if(p===f)continue;let x=o[f],F=x.cx-b.cx,k=x.cy-b.cy,S=F*F+k*k<u;S&&!h.has(x)?(h.add(x),z("enter")&&P("enter",{body:b,other:x})):!S&&h.has(x)&&(h.delete(x),z("exit")&&P("exit",{body:b,other:x}))}}if(c){let h=J.get(b);h||J.set(b,h=new Set);for(let u=p+1;u<o.length;u++){let f=o[u],x=Math.abs(f.cx-b.cx)<b.hw+f.hw&&Math.abs(f.cy-b.cy)<b.hh+f.hh;x&&!h.has(f)?(h.add(f),P("met",{a:b,b:f})):!x&&h.has(f)&&h.delete(f)}}}let v=new Set(o);for(let p of[G,J])for(let b of p.keys())v.has(b)||p.delete(b)}let X=[],bt=new WeakMap,tt=[],Se=0,Vt=new WeakMap,Ee=new WeakMap,It=new Map,q=new Map;if(yr(m),pr(m),vr(m),!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 A=t.host,j=[],et=()=>A.reducedMotion?.()??!1,nt=ao(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,Ft=.5,Xt=()=>{if(nt.allowBodyDataInSnapshots===!1)return!1;let o=nt.budgets?.privacy;return!(o!=null&&o<Ft)},Nt=In[t.theme??Nn]??In[Nn],O={accent:t.accent??We(t.palette)[0]??Rn[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:ge.ambient.preset.orbit,ambientWander:t.ambientWander!=null&&t.ambientWander>=0?t.ambientWander:ge.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?pt(t.gradientCool):Nt.cool,gradientWarm:t.gradientWarm?pt(t.gradientWarm):Nt.warm,waveBaseline:(t.waveBaseline??Nt.wave).map(pt),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??no},ct=null,B=[],L=0,R=0,Z=0,ot=0,ee=!1,ue=1,he=0,uo=new WeakMap,Kt=0,Tt=0,ho=!0,ln={...ge.ambient.preset,orbit:O.ambientOrbit,wander:O.ambientWander},yo={...ln},fn="ambient",Is=0,mo=t.identify,dn=o=>{if(o.identity)return o.identity;let a;return mo&&o.el&&(a=mo(o.el)),a||(a={id:(o.el&&o.el.id?o.el.id:void 0)??`body-${Is++}`}),o.identity=a,a},Jt=o=>dn(o).id,Qt=new Map,ne=new Map,po=(o,a)=>{let c=Qt.get(o);if(!c)return 0;let v=0;for(let p of c.values())v+=p.mass*be(p.at,a,p.halfLife);return v>1?1:v};function Ns(o,a){let c=typeof o=="string"?{id:o}:o,v=c.id;if(!v)return;let p=a?.amount??1,b=a?.source??"system",h=a?.halfLife??hc,u=a?.at??W.t;typeof o!="string"&&(c.namespace||c.kind||c.host)&&ne.set(v,c);let f=Qt.get(v);f||Qt.set(v,f=new Map);let x=f.get(b),k=(x?x.mass*be(x.at,u,x.halfLife):0)+p;f.set(b,{mass:k,at:u,halfLife:h}),P("focus",{target:v,identity:ne.get(v)??c,source:b,amount:p,salience:po(v,u),sourceSalience:k>1?1:k,frame:Tt,time:u})}function Ds(o){let a=W.t,c=o?.limit??yc,v=o?.threshold??mc,p=o?.source,b=u=>u.find(f=>f.source===p)?.weight??0,h=[];for(let[u,f]of Qt){let x=[],F=0,k=0;for(let[S,C]of f){let D=C.mass*be(C.at,a,C.halfLife);D<=0||(F+=D,C.at>k&&(k=C.at),x.push({source:S,weight:D>1?1:D,updatedAt:C.at}))}F>1&&(F=1),!((p?b(x):F)<v)&&(x.sort((S,C)=>C.weight-S.weight),h.push({target:u,identity:ne.get(u)??{id:u},salience:F,sources:x,updatedAt:k}))}return h.sort((u,f)=>p?b(f.sources)-b(u.sources):f.salience-u.salience),{frame:Tt,time:a,entries:h.slice(0,c)}}function _s(){if(Qt.size===0)return;let o=W.t;for(let[a,c]of Qt){for(let[v,p]of c)p.mass*be(p.at,o,p.halfLife)<zs&&c.delete(v);c.size===0&&(Qt.delete(a),ne.delete(a))}for(let a of B){let c=po(Jt(a),o);if(c>zs){a.salience=c;let v=1+pc*c;a.focusMul=v>1?Math.min(gc,v):void 0,a.identity&&!ne.has(a.identity.id)&&ne.set(a.identity.id,a.identity)}else a.salience!==void 0&&(a.salience=void 0),a.focusMul!==void 0&&(a.focusMul=void 0)}}let go=o=>{let a={density:o.d,count:o.count,engaged:o.on?1:0};o.attn!==void 0&&(a.attention=o.attn),o.salience!==void 0&&(a.salience=o.salience),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}},Ls=0,Bt=new Map,Bs=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}:{}}),Fe=()=>[...Bt.values()].map(Bs),ze=[];function Ws(){for(let o of ze)Bt.get(o.id)?.apply?.(o.source(),o.target)}let qs={register(o){return Bt.set(o.id,o),()=>{Bt.get(o.id)===o&&Bt.delete(o.id)}},unregister(o){Bt.delete(o)},get(o){return Bt.get(o)},list:Fe,apply(o,a,c){Bt.get(o)?.apply?.(a,c)},bind(o,a,c){let v={id:o,target:a,source:c};return ze.push(v),()=>{let p=ze.indexOf(v);p>=0&&ze.splice(p,1)}},lint:()=>wr(Fe())},xo=.9,vo=8,Hs=4800,bo=.02;function js(){for(let o of B){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=B.filter(S=>S!==o&&S.vis&&S.tokens.length>0),{fx:p,fy:b}=Gt(v,m.forces,W,a,c);if(O.mass){let S=o.hw*2*(o.hh*2);o.inertia=Math.min(4,Math.max(.4,Math.sqrt(S/Hs)))}let h=1/Math.max(o.inertia??o.M,1e-4),u=0,f=0;if(O.reaction&&o.tokens.length>0){let S=o.range*o.range,C=[o];for(let D of d.particles){if(D.cap)continue;let $=D.x-a,H=D.y-c;if($*$+H*H>S)continue;let K=Gt(C,m.forces,W,D.x,D.y);u-=K.fx,f-=K.fy}}let x=(o.bvx??0)+(p+u*bo)*h*W.dt,F=(o.bvy??0)+(b+f*bo)*h*W.dt;x*=xo,F*=xo;let k=Math.hypot(x,F);if(k>vo){let S=vo/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 wo=globalThis.structuredClone,Us=o=>{if(o==null)return o;try{return wo?wo(o):JSON.parse(JSON.stringify(o))}catch{try{return JSON.parse(JSON.stringify(o))}catch{return o}}},vt=[],Wt=[],Mo=0,Zt=null,ht=t.rng??Math.random,un=t.now??(()=>performance.now()),it=ut?1:0,hn=NaN,Dt=null,ye=null,oe=null,qt=0,_t=0,Ae=null,yn=[],mn=null,Te=null,Ys=Math.round(130*O.density)*4,xt={x:0,y:0,k:0},yt=null,Lt=null,ko=0,So=0,Eo=We(t.palette).map(pt),lt=pt(O.accent),Ce=null,pn=[],Ht=[],re=[],se=[],gn=[],xn=[],ie=[],Oe=new Je,vn=!1,bn=()=>{vn||(vn=!0,queueMicrotask(()=>{vn=!1,Pe()}))},Gs=o=>{for(let a of["--d","--field-density","--load","--entropy","--coherence","--temperature"])o.style.removeProperty(a)},Vs=o=>{let a=o.detail;a?.element&&(Oe.register(a),bn())},Xs=o=>{let a=o.detail;a?.element&&(Oe.unregister(a.element),Gs(a.writeTarget??a.element),bn())},Ks=bn,Ot={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null},Fo=un(),W={dx:0,dy:0,dz:0,dist:1,form:{...ln},W:0,H:0,D:O.depth,integrator:O.integrator,t:0,frameN:0,dt:ut?0:1,c:12,G:1,scrollV:0,rng:ht,spark:(o,a,c,v)=>zo(o,a,c,v),supernova:o=>{let a=ws(d.particles,o,ht),c=new Set(a);for(let v of d.particles){if(c.has(v))continue;let p=v.x-o.cx,b=v.y-o.cy,h=Math.hypot(p,b)||1;if(h<320){let u=(1-h/320)*4;v.vx+=p/h*u,v.vy+=b/h*u,v.heat=Math.max(v.heat,.8)}}Gn(Wt,vt,o.cx,o.cy,320,L,R,W.t,v=>void d.add(ae(v))),ii(o),wn(o.el,"field:saturated",{peak:a.length}),o.el.dataset.fxCap==="1"&&(o.el.dataset.fxCap="0",ce(o.el,"released",{accreted:0,load:0}),z("released")&&P("released",{body:o,count:a.length}),I.delete(o))},spawn:o=>{d.size>=Ys||d.add(ae(o))},neighbors:(o,a)=>d.neighbors(o,a),grid:o=>{let a=w.get(o);if(!a){let c=o.startsWith("wave")?"wave":o.startsWith("memory")?"memory":"diffuse";a=new de(L,R,c),w.set(o,a)}return a}};function zo(o,a,c,v){if(ut||se.length>260)return;let p=v?pt(v):[255,122,69],b=Tr(c,ht);for(let h=0;h<b;h++){let u=ht()*6.28318,f=.8+ht()*(c>0?c:1)*1.7;se.push({x:o,y:a,vx:Math.cos(u)*f,vy:Math.sin(u)*f,life:1,c:p})}}function ae(o={}){let a=o.size??.7+ht()*1.8;return{id:o.id??g++,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??(O.depth>0?ht()*O.depth:0),vz:o.vz??(O.depth>0?(ht()-.5)*.18:0),m:o.m??(O.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 Re=[];function Js(){if(!Re.length)return;let o=d.particles;for(let a=0;a<o.length;a++){let c=Re[a%Re.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 Ao(){d.clear();let o=Math.round(130*O.density);for(let a=0;a<o;a++)d.add(ae());Js(),vt=O.waves?nr(O.waveBaseline):[],Wt=O.waves?or(vt.length,O.density,ht):[],Mo=Wt.length}function Pe(){let o=B,a=Kr(A.root);if(Oe.size>0){let h=new Set(a.map(u=>u.el));B=a.concat(Oe.bodies(we).filter(u=>!h.has(u.el)))}else B=a;X.length>0&&(B=B.concat(X));let c=null,v=!1;if(o.length>0){let h=new Map;for(let f of o){let x=h.get(f.el);x?x.push(f):h.set(f.el,[f])}let u=new Map;for(let f of B){let x=h.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 C=I.get(k);C!==void 0&&I.set(f,C),(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)}}Ke(B,L,R,Z,ot),ci();let p=new Map(Ht.map(h=>[h.el,h]));Ht=[...A.root.querySelectorAll("[data-move]")].map(h=>{let u=h,f=u.getBoundingClientRect(),x=Number.parseFloat(u.dataset.mass??""),F=Number.isFinite(x)?x:$r(f.width*f.height),k=(u.dataset.move??"").trim()==="layout",S=u.hasAttribute("data-dock"),C=u.hasAttribute("data-warp"),D=p.get(u);if(D){let $=D.docked?c?.get(D.docked)??D.docked:null;return{el:u,o:D.o,mEl:F,layout:k,dockable:S,dock:D.dock,docked:$,warpable:C,warpCool:D.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:C,warpCool:0}}),gn=[...A.root.querySelectorAll("[data-on]")].map(h=>{let u=h;return{el:u,body:B.find(f=>f.el===u)??null,bindings:Vn(u.dataset.on??"")}}),xn=[...A.root.querySelectorAll("[data-class]")].map(h=>{let u=h;return{el:u,body:B.find(f=>f.el===u)??null,bindings:Vn(u.dataset.class??"")}});for(let h of B){if(!h.pair)continue;let u=null;try{u=A.root.querySelector(h.pair)}catch{u=null}h.pairBody=u?B.find(f=>f.el===u):void 0}let b=new Map(re.map(h=>[h.el,h]));for(let[h,u]of b)if(!A.root.contains(h))for(let f of u.emitted)f.remove();re=[...A.root.querySelectorAll("[data-emit]")].map(h=>{let u=h,f=u.dataset.emit??"",x=null;try{x=f?A.root.querySelector(f):null}catch{x=null}let F=Math.max(0,Math.round(Number.parseFloat(u.dataset.max??"")||8)),k=b.get(u);if(k){let S=k.emitted.filter(C=>C.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 Qs(){for(let o of B)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 Zs(){if(!(re.length===0||W.frameN%30!==0))for(let o of re){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 ti(){if(gn.length!==0)for(let o of gn){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=Xn(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 ei(){if(xn.length!==0)for(let o of xn){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=Xn(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 ce(o,a,c){o.dispatchEvent(new CustomEvent("field:"+a,{bubbles:!0,composed:!0,detail:c}))}function ni(){for(let o of B){if(!o.vis||o.tokens.indexOf("sink")<0)continue;let a=o.el.dataset.fxCap==="1",c=Ms(a,o.accreted>0);c.fire==="captured"?(o.el.dataset.fxCap="1",ce(o.el,"captured",{accreted:o.accreted,load:ro(o)}),z("captured")&&P("captured",{body:o,count:o.accreted}),I.set(o,o.accreted)):c.fire==="released"&&(o.el.dataset.fxCap="0",ce(o.el,"released",{accreted:0,load:0}),z("released")&&P("released",{body:o,count:I.get(o)??0}),I.delete(o))}}let oi=[{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"}],ri=120;function wn(o,a,c){o.dispatchEvent(new CustomEvent(a,{bubbles:!0,composed:!0,detail:c}))}function To(o,a,c,v,p,b){let h=o.get(a);h||o.set(a,h=new Map);let u=h.get(v.metric);u||h.set(v.metric,u=new tn({enter:v.enter,exit:v.exit,debounceMs:ri}));let f=u.update(p,b);f==="entered"?wn(c,v.rise,{metric:v.metric,value:p}):f==="exited"&&wn(c,v.fall,{metric:v.metric,value:p})}function si(o){for(let a of B)if(!(!a.vis||a.tokens.length===0))for(let c of oi){let v;switch(c.metric){case"density":v=a.d;break;case"attention":O.attention&&(v=a.attn??1);break;case"entropy":v=a.metrics?.entropy;break}v!==void 0&&To(Vt,a,a.el,c,v,o)}for(let a of tt)To(Ee,a.agent,a.from.el,{metric:"memory",enter:.6,exit:.3,rise:"field:memory-threshold",fall:"field:memory-faded"},a.agent.memory,o)}function ii(o){for(let a of Ht)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="",ce(a.el,"released",{}))}function ai(){if(Ht.length===0)return;let o=Ht.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<Ht.length;a++){let c=Ht[a];if(!c.el.isConnected){c.docked&&(c.docked=null,c.dock.dock=0);continue}let v=o[a].x,p=o[a].y;if(c.docked){let x={x:v-c.o.x,y:p-c.o.y};c.dock.dock=Ss(c.dock.dock,1);let F=Es(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}Ot.x=v,Ot.y=p,Ot.vx=0,Ot.vy=0,Ot.heat=0,Ot.cap=null;for(let x of B){if(!x.vis||x.tokens.length===0||x.el===c.el)continue;let F=x.cx-v,k=x.cy-p,S=Math.hypot(F,k);W.dx=F,W.dy=k,W.dist=S<1?1:S;for(let C of x.tokens)m.forces[C]?.apply(x,Ot,W)}Ot.cap=null;let b=Pr(c.o),h=Ot.vx+b.x,u=Ot.vy+b.y;if(c.layout){let x=Ir({x:v,y:p},o,a),F=Nr((k,S)=>d.near(k,S,40).length,v,p,16,6);h+=x.x+F.x,u+=x.y+F.y}let f={x:v-c.o.x,y:p-c.o.y};if(Rr(c.o,h,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=B.find(k=>k.vis&&k.el!==c.el&&k.tokens.indexOf("sink")>=0&&so(x,k));F&&(c.docked=F,ce(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=B.find(k=>k.vis&&k.el!==c.el&&k.warpHas&&k.tokens.indexOf("warp")>=0&&so(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,ce(c.el,"relocated",{from:F.el}))}}}function ci(){ie.length&&(ie=ie.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))),A.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",Ce=a.dataset.color??null;let p=a.closest("[data-index][data-threads]");if(p){let b=[...p.querySelectorAll("[data-hot]")].filter(h=>h!==a);Mn(b.map(h=>({a,b:h,color:a.dataset.color??void 0})))}},v=()=>{a.dataset.active="0",Ce=null,Mn(null)};a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",v),a.addEventListener("focusin",c),a.addEventListener("focusout",v),ie.push({el:a,enter:c,leave:v})})}function Mn(o){pn=(o??[]).map(a=>({a:a.a,b:a.b,c:pt(a.color??O.accent),seed:ht()*6.28}))}function li(){if(pn.length===0)return;let o=W.t;e.globalCompositeOperation="lighter";for(let a of pn){let c=a.a.getBoundingClientRect(),v=a.b.getBoundingClientRect(),p=c.left-Z+c.width/2,b=c.top-ot+c.height/2,h=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(p,b),e.lineTo(h,u),e.stroke();for(let k=0;k<3;k++){let S=(o*.6+a.seed+k/3)%1,C=p+(h-p)*S,D=b+(u-b)*S;e.fillStyle=`rgba(${f},${x},${F},${(1-S)*.9})`,e.beginPath(),e.arc(C,D,2.2,0,6.28318),e.fill()}}e.globalCompositeOperation="source-over"}let $e=0,fi=[1/0,1.5,1.25,1];function Ie(o){if(!e)return;let a=Math.min(o||1,O.dprCap,fi[$e]??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 Co(){let o=A.viewport();L=o.width,R=o.height,Z=o.originX??0,ot=o.originY??0,ee=o.originX!=null||o.originY!=null,Ie(o.dpr),W.W=L,W.H=R,ue=(A.scrollHeight?.()??R)-R||1;for(let a of w.values())a.resize(L,R);O.heatmap&&(ct?ct.resize(L,R):ct=new Me(L,R)),Ao(),Pe()}function di(){let o=W.t,a=16;if(O.waveStyle==="circular"){let c=Zt||{x:L/2,y:R/2},v=Math.min(L,R)*.48;for(let p of vt){let[b,h,u]=p.color;e.beginPath();let f=.08,x=!0;for(let S=0;S<=2*Math.PI+.01;S+=f){let C=xe(p,S,o,v),D=c.x+Math.cos(S)*C,$=c.y+Math.sin(S)*C;x?(e.moveTo(D,$),x=!1):e.lineTo(D,$)}e.closePath();let F=p.baseFrac*v+p.offsetY,k=e.createRadialGradient(c.x,c.y,Math.max(0,F-p.amp),c.x,c.y,F+p.amp+80);k.addColorStop(0,`rgba(${b},${h},${u},${(.08+p.depth*.04)*it})`),k.addColorStop(1,`rgba(${b},${h},${u},0)`),e.fillStyle=k,e.fill()}e.globalCompositeOperation="lighter";for(let p of vt){let[b,h,u]=p.color;e.beginPath();let f=.08,x=!0;for(let F=0;F<=2*Math.PI+.01;F+=f){let k=xe(p,F,o,v),S=c.x+Math.cos(F)*k,C=c.y+Math.sin(F)*k;x?(e.moveTo(S,C),x=!1):e.lineTo(S,C)}e.closePath(),e.lineWidth=5,e.strokeStyle=`rgba(${b},${h},${u},${(.05+p.depth*.04)*it})`,e.stroke(),e.lineWidth=1.2,e.strokeStyle=`rgba(${b},${h},${u},${(.3+p.depth*.22)*it})`,e.stroke()}e.globalCompositeOperation="source-over"}else{for(let c of vt){let[v,p,b]=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 h=c.baseFrac*R+c.offsetY-c.amp,u=e.createLinearGradient(0,h,0,h+320);u.addColorStop(0,`rgba(${v},${p},${b},${(.11+c.depth*.05)*it})`),u.addColorStop(1,`rgba(${v},${p},${b},0)`),e.fillStyle=u,e.fill()}e.globalCompositeOperation="lighter";for(let c of vt){let[v,p,b]=c.color;e.beginPath(),e.moveTo(0,Et(c,0,o,R,1,1,xt));for(let h=0;h<=L;h+=a)e.lineTo(h,Et(c,h,o,R,1,1,xt));e.lineWidth=5,e.strokeStyle=`rgba(${v},${p},${b},${(.05+c.depth*.04)*it})`,e.stroke(),e.lineWidth=1.2,e.strokeStyle=`rgba(${v},${p},${b},${(.3+c.depth*.22)*it})`,e.stroke()}e.globalCompositeOperation="source-over"}}function ui(){e.globalCompositeOperation="lighter";let o=W.t,a=0;if(O.waveStyle==="circular"){let c=Zt||{x:L/2,y:R/2},v=Math.min(L,R)*.48;for(let p of Wt){let b=vt[p.wi];if(!b){a++;continue}W.dt&&(p.progress+=p.speed,p.progress>1?p.progress-=1:p.progress<0&&(p.progress+=1));let h=p.progress*2*Math.PI,u=xe(b,h,o,v)+p.phase*32,f=c.x+Math.cos(h)*u,x=c.y+Math.sin(h)*u,[F,k,S]=b.color,C=p.glow?.6+.4*Math.sin(o*2.2+a):.85;p.glow&&(e.fillStyle=`rgba(${F},${k},${S},${.16*C*it})`,e.beginPath(),e.arc(f,x,p.size+2.5,0,6.28318),e.fill()),e.fillStyle=`rgba(${F},${k},${S},${C*it})`,e.beginPath(),e.arc(f,x,p.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 p=c.progress*L,b=Et(v,p,o,R,1,1,xt)+c.phase*32,[h,u,f]=v.color,x=c.glow?.6+.4*Math.sin(o*2.2+a):.85;c.glow&&(e.fillStyle=`rgba(${h},${u},${f},${.16*x*it})`,e.beginPath(),e.arc(p,b,c.size+2.5,0,6.28318),e.fill()),e.fillStyle=`rgba(${h},${u},${f},${x*it})`,e.beginPath(),e.arc(p,b,c.size,0,6.28318),e.fill(),a++}e.globalCompositeOperation="source-over"}function hi(){if(!O.attention)return;for(let c of B)c.attn=1;let o=B.filter(c=>c.vis&&c.tokens.length>0);if(o.length===0)return;let a=Ko(o);for(let c=0;c<o.length;c++)o[c].attn=a[c]}function yi(){if(!O.causality)return;let o=B.filter(c=>c.vis&&c.tokens.length>0);if(o.length===0)return;if(o.length===1){Oo(o[0],o[0].d);return}let a=Jo(o.map(c=>({d:c.d,cx:c.cx,cy:c.cy})));for(let c=0;c<o.length;c++)Oo(o[c],mt(o[c].d+a[c],0,1))}function Oo(o,a){O.feedbackSink(o.el,{lit:a})}function mi(){for(let o of B){if(!o.feedback)continue;let a=Vo(o.count,o.on);o.d+=(a-o.d)*.08;let c=o.writeTarget??o.el;if(o.fmax){let f=Xo(o.fmin,o.fmax,o.d);uo.get(c)!==f&&(uo.set(c,f),c.style.fontVariationSettings=`"wght" ${f}`+(o.opsz?`, "opsz" ${o.opsz}`:""))}let v=ct?ct.norm(o.cx,o.cy):void 0,p=o.tokens.indexOf("sink")>=0&&o.capacity>0?ro(o):void 0,b=Wr(o.thermo),h=o.metrics??(o.metrics={entropy:0,coherence:1,temperature:0});h.entropy+=(b.entropy-h.entropy)*.08,h.coherence+=(b.coherence-h.coherence)*.08,h.temperature+=(b.temperature-h.temperature)*.08;let u={density:o.d,heatmapDensity:v,load:p,entropy:h.entropy,coherence:h.coherence,temperature:h.temperature};O.feedbackSink(c,u),o.onFeedback?.(u)}}function pi(){if(se.length!==0){e.globalCompositeOperation="lighter";for(let o=se.length-1;o>=0;o--){let a=se[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){se.splice(o,1);continue}let[c,v,p]=a.c;e.fillStyle=`rgba(${c},${v},${p},${.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},${p},${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 jt=null,Ne=null,le=null;function gi(){if(!ct)return;let o=R>0?mt((O.heatmapFadeStart+O.heatmapFadeSpan-he/R)/O.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(!jt){if(!A.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.");jt=A.createCanvas(),Ne=jt.getContext("2d")}if(Ne){if((jt.width!==c||jt.height!==v)&&(jt.width=c,jt.height=v,le=null),le===null||Tt%3===0){le===null&&(le=Ne.createImageData(c,v));let p=lt,b=le.data;for(let h=0;h<v;h++)for(let u=0;u<c;u++){let f=ct.norm(u*a+a/2,h*a+a/2),x=(h*c+u)*4;b[x]=p[0],b[x+1]=p[1],b[x+2]=p[2],b[x+3]=Math.round(mt(f*.5*it,0,1)*255)}Ne.putImageData(le,0,0)}e.globalCompositeOperation="lighter",e.imageSmoothingEnabled=!0,e.globalAlpha=o,e.drawImage(jt,0,0,L,R),e.globalAlpha=1,e.globalCompositeOperation="source-over"}}function xi(){O.background==="transparent"?O.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):(O.render==="trails"?e.fillStyle="rgba(5,6,11,0.22)":e.fillStyle="rgb(5,6,11)",e.fillRect(0,0,L,R)),di(),ct&&$e<2&&gi(),ui();let o=O.render!=="metaballs"&&O.render!=="streamlines"&&O.render!=="knockout"&&O.render!=="redshift"&&O.render!=="blackbody"&&O.render!=="depth";e.globalCompositeOperation="lighter";let a=lt,c=L*O.heatCenterX,v=R*O.heatCenterY,p=Math.hypot(Math.max(c,L-c),Math.max(v,R-v))||1;if(Te===null||Tt%6===0){Te=[];for(let h of B){if(!h.tint)continue;let u=(h.range||200)*1.4;Te.push({b:h,r2:u*u,rgb:pt(h.tint)})}}let b=Te;if(o)for(let h of d.particles){if(h.cap){e.fillStyle=`rgba(${a[0]},${a[1]},${a[2]},${.55*it})`,e.beginPath(),e.arc(h.x,h.y,1.3,0,6.28318),e.fill();continue}let u=Math.min(1,Math.hypot(h.x-c,h.y-v)/p),f=u*u,x=h.heat;Dn(gt,f,x,a,O.gradientCool,O.gradientWarm);let F=gt[0],k=gt[1],S=gt[2];if(b.length){let ft=0,Q=null;for(let rt of b){let Mt=h.x-rt.b.cx,kt=h.y-rt.b.cy,Ut=Mt*Mt+kt*kt;if(Ut>=rt.r2)continue;let N=1-Math.sqrt(Ut/rt.r2);N>ft&&(ft=N,Q=rt.rgb)}if(Q){let rt=ft*.7;F+=(Q[0]-F)*rt,k+=(Q[1]-k)*rt,S+=(Q[2]-S)*rt}}if(h.color){let[ft,Q,rt]=pt(h.color);F+=(ft-F)*.75,k+=(Q-k)*.75,S+=(rt-S)*.75}let C=O.depth>0?1-Math.min(Math.abs(h.z??0)/O.depth,1)*.55:1,D=(h.size*(1-.4*f)+x*2)*C,$=mt((.5-.3*f+x*.5)*it*C,0,1),H=F|0,K=k|0,dt=S|0;e.fillStyle=`rgba(${H},${K},${dt},${.12*$})`,e.beginPath(),e.arc(h.x,h.y,D+1.2,0,6.28318),e.fill(),e.fillStyle=`rgba(${H},${K},${dt},${$})`,e.beginPath(),e.arc(h.x,h.y,D,0,6.28318),e.fill()}if(pi(),li(),e.globalCompositeOperation="source-over",O.render==="links"){e.globalCompositeOperation="lighter";let h=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=ns(Math.hypot(x.x-f.x,x.y-f.y),u);F<=0||(e.strokeStyle=`rgba(${h[0]},${h[1]},${h[2]},${F})`,e.beginPath(),e.moveTo(f.x,f.y),e.lineTo(x.x,x.y),e.stroke())}e.globalCompositeOperation="source-over"}if(O.render==="metaballs"){let x=Math.ceil(L/16)+1,F=Math.ceil(R/16)+1;!Dt||Dt.length!==x*F?Dt=new Float32Array(x*F):Dt.fill(0);for(let S of d.particles)S.cap||Zn(Dt,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 C=0;C<x-1;C++){let D=Dt[S*x+C],$=Dt[S*x+C+1],H=Dt[(S+1)*x+C+1],K=Dt[(S+1)*x+C],dt=Qn(D,$,H,K,.9);if(!dt.length)continue;let ft=C*16,Q=S*16;for(let rt of dt)e.moveTo(ft+rt.x1*16,Q+rt.y1*16),e.lineTo(ft+rt.x2*16,Q+rt.y2*16)}e.stroke(),e.globalCompositeOperation="source-over"}if(O.render==="voronoi"){let f=Math.ceil(L/18)+1,x=Math.ceil(R/18)+1;(!ye||ye.length!==f*x)&&(ye=new Int32Array(f*x));let F=d.particles,k=new Map;for(let C=0;C<F.length;C++)k.set(F[C],C);for(let C=0;C<x;C++)for(let D=0;D<f;D++){let $=D*18,H=C*18,K=d.near($,H,54),dt=-1;if(K.length){let ft=os($,H,K);ft>=0&&(dt=k.get(K[ft])??-1)}ye[C*f+D]=dt}let S=lt;e.globalCompositeOperation="lighter",e.strokeStyle=`rgba(${S[0]},${S[1]},${S[2]},${.32*it})`,e.lineWidth=1,e.beginPath();for(let C of ms(ye,f,x))e.moveTo(C.x1*18,C.y1*18),e.lineTo(C.x2*18,C.y2*18);e.stroke(),e.globalCompositeOperation="source-over"}if(O.render==="knockout"){let h=lt;e.fillStyle=`rgba(${h[0]},${h[1]},${h[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=O.depth>0?1-Math.min(Math.abs(u.z??0)/O.depth,1)*.55:1,x=rs(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(O.render==="redshift"){e.globalCompositeOperation="lighter";let h=L*O.redshiftObserverX,u=R*O.redshiftObserverY;for(let f of d.particles){if(f.cap)continue;let x=0;for(let $ of B){let H=$.range||200,K=f.x-$.cx,dt=f.y-$.cy,ft=as(K*K+dt*dt,H*H);ft>x&&(x=ft)}let F=cs(is(ss(f.x,f.y,f.vx,f.vy,h,u),W.c),x);ls(gt,F);let k=O.depth>0?1-Math.min(Math.abs(f.z??0)/O.depth,1)*.55:1,S=F<0?-F:F,C=(f.size+S*1.6)*k,D=mt((.4+.45*S)*it*k,0,1);e.fillStyle=`rgba(${gt[0]|0},${gt[1]|0},${gt[2]|0},${D})`,e.beginPath(),e.arc(f.x,f.y,C,0,6.28318),e.fill()}e.globalCompositeOperation="source-over"}if(O.render==="blackbody"){e.globalCompositeOperation="lighter";for(let h of d.particles){if(h.cap)continue;let u=fs(h.vx,h.vy,h.heat,W.c);ds(gt,u);let f=O.depth>0?1-Math.min(Math.abs(h.z??0)/O.depth,1)*.55:1,x=(h.size+u*2.2)*f,F=mt((.16+.84*u)*it*f,0,1),k=gt[0]|0,S=gt[1]|0,C=gt[2]|0;e.fillStyle=`rgba(${k},${S},${C},${.14*F})`,e.beginPath(),e.arc(h.x,h.y,x+1.4+u*2,0,6.28318),e.fill(),e.fillStyle=`rgba(${k},${S},${C},${F})`,e.beginPath(),e.arc(h.x,h.y,x,0,6.28318),e.fill()}e.globalCompositeOperation="source-over"}if(O.render==="depth"){let h=d.particles,u=h.length;(!oe||oe.length!==u)&&(oe=new Array(u));for(let k=0;k<u;k++)oe[k]=k;oe.sort((k,S)=>Math.abs(h[S].z??0)-Math.abs(h[k].z??0));let f=O.depthFocal,x=L/2,F=R/2;for(let k=0;k<u;k++){let S=h[oe[k]];if(S.cap)continue;let C=S.z??0,D=O.depth>0?Math.min(Math.abs(C)/O.depth,1):0,$=us(C,f),H=to(S.x,x,$),K=to(S.y,F,$),dt=Math.min(1,Math.hypot(H-c,K-v)/p),ft=dt*dt,Q=S.heat;Dn(gt,ft,Q,a,O.gradientCool,O.gradientWarm);let rt=(S.size*(1-.4*ft)+Q*2)*$,Mt=mt((.5-.3*ft+Q*.5)*it*hs(D),0,1),kt=gt[0]|0,Ut=gt[1]|0,N=gt[2]|0;e.fillStyle=`rgba(${kt},${Ut},${N},${.12*Mt})`,e.beginPath(),e.arc(H,K,rt+1.2+ys(D),0,6.28318),e.fill(),e.fillStyle=`rgba(${kt},${Ut},${N},${Mt})`,e.beginPath(),e.arc(H,K,rt,0,6.28318),e.fill()}}if(O.render==="streamlines"||O.render==="flow"){let u=lt;if(e.lineWidth=1,e.lineCap="round",Ae===null||yt||Tt%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:C,fy:D}=Gt(B,m.forces,W,k,S);if(yt){let H=ve(en,k,S,yt,.04);C+=H.x,D+=H.y}let $=Math.hypot(C,D);if(!($>1e-9)){x.push({gx:k,gy:S});continue}f.push({gx:k,gy:S,ux:C/$,uy:D/$,mag:$}),$>F&&(F=$)}qt===0?qt=F:qt=F>qt?qt*.7+F*.3:qt*.9+F*.1,Ae=f,yn=x}if(yn.length){e.fillStyle=`rgba(${u[0]},${u[1]},${u[2]},0.05)`;for(let f of yn)e.fillRect(f.gx-.5,f.gy-.5,1,1)}if(qt>0&&Ae)for(let f of Ae){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]},${mt(.1+x*.5,0,.72)})`,e.beginPath(),e.moveTo(f.gx,f.gy),e.lineTo(k,S);let C=3.4;e.moveTo(k,S),e.lineTo(k-f.ux*C-f.uy*C*.6,S-f.uy*C+f.ux*C*.6),e.moveTo(k,S),e.lineTo(k-f.ux*C+f.uy*C*.6,S-f.uy*C-f.ux*C*.6),e.stroke()}}}function De(o){return(o===void 0?[]:Array.isArray(o)?o:[o]).filter(c=>c!=="off")}function Ro(o,a,c){let p=lt;if(mn===null||yt||Tt%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(B,m.forces,W,x,F);if(yt){let D=ve(en,x,F,yt,.04);k+=D.x,S+=D.y}let C=Math.hypot(k,S);C>1e-9&&(u.push({gx:x,gy:F,ux:k/C,uy:S/C,mag:C}),C>f&&(f=C))}_t===0?_t=f:_t=f>_t?_t*.7+f*.3:_t*.9+f*.1,mn=u}if(_t<=0)return;let b={r:p[0],g:p[1],b:p[2],alpha:0,width:1.2},h=new Float64Array(12);for(let u of mn){let f=c?mt(u.mag/_t,0,1):Math.sqrt(u.mag/_t),x=44*.5*(.25+.75*f),F=u.gx+u.ux*x,k=u.gy+u.uy*x,S=3.6;h[0]=u.gx,h[1]=u.gy,h[2]=F,h[3]=k,h[4]=F,h[5]=k,h[6]=F-u.ux*S-u.uy*S*.6,h[7]=k-u.uy*S+u.ux*S*.6,h[8]=F,h[9]=k,h[10]=F-u.ux*S+u.uy*S*.6,h[11]=k-u.uy*S-u.ux*S*.6,b.alpha=mt(.12+f*.55,0,.8),o.segments(h,b)}}function vi(o){let a=Ar(B);if(!a.length)return;let c=Er((b,h)=>Ye(B,m.forces,b,h),a,{step:6,maxSteps:200,bounds:{w:L,h:R},loopDist:8}),v=lt,p={r:v[0],g:v[1],b:v[2],alpha:.42,width:1.1};for(let b of c){if(b.length<2)continue;let h=new Float32Array(b.length*2);for(let u=0;u<b.length;u++)h[u*2]=b[u].x,h[u*2+1]=b[u].y;o.polyline(h,p)}}function bi(o){let c=22*O.gridWarp,v=48*.46,p=Math.floor(L/48)+2,b=Math.floor(R/48)+2,h=new Float32Array(p*b),u=new Float32Array(p*b),f=0,x=new Float32Array(p*b);for(let N=0;N<b;N++)for(let U=0;U<p;U++){let{fx:st,fy:V}=Gt(B,m.forces,W,U*48,N*48),at=Math.hypot(st,V),St=N*p+U;at>1e-9&&(h[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=N=>f>0?Math.sqrt(x[N]/f):0,C=N=>Math.round(S(N)*k),D=N=>{let U=N/k,st=Ln(F,U);return{r:st[0],g:st[1],b:st[2],alpha:Math.min(1,O.gridIntensity*(.3+.85*U)),width:U>.55?1.4:1}},$=new Float32Array(p*b),H=new Float32Array(p*b);for(let N=0;N<p*b;N++){let U=S(N);$[N]=h[N]*U*c,H[N]=u[N]*U*c}let K=new Float32Array(p*b),dt=new Float32Array(p*b);for(let N=0;N<b;N++)for(let U=0;U<p;U++){let st=0,V=0,at=0;for(let Rt=-1;Rt<=1;Rt++)for(let Pt=-1;Pt<=1;Pt++){let Ct=U+Pt,$t=N+Rt;if(Ct<0||$t<0||Ct>=p||$t>=b)continue;let fe=$t*p+Ct;st+=$[fe],V+=H[fe],at++}let St=N*p+U;K[St]=st/at,dt[St]=V/at}let ft=48*1.5,Q=(N,U)=>{let st=U*p+N,V=K[st],at=dt[st],St=Math.hypot(V,at);St>v&&(V=V/St*v,at=at/St*v);let Rt=N*48,Pt=U*48,Ct=Math.min(Rt,L-Rt,Pt,R-Pt),$t=Ct<=0?0:Ct<ft?Ct/ft:1;return[Rt+V*$t,Pt+at*$t]},rt=4,Mt=N=>{let U=N.length>>1;if(U<3)return N;let st=[N[0],N[1]];for(let V=0;V<U-1;V++){let at=(V>0?V-1:0)<<1,St=V<<1,Rt=V+1<<1,Pt=(V+2<U?V+2:U-1)<<1,Ct=N[at],$t=N[at+1],fe=N[St],En=N[St+1],Fn=N[Rt],zn=N[Rt+1],_o=N[Pt],Lo=N[Pt+1];for(let An=1;An<=rt;An++){let me=An/rt,Tn=me*me,Bo=Tn*me;st.push(.5*(2*fe+(-Ct+Fn)*me+(2*Ct-5*fe+4*Fn-_o)*Tn+(-Ct+3*fe-3*Fn+_o)*Bo),.5*(2*En+(-$t+zn)*me+(2*$t-5*En+4*zn-Lo)*Tn+(-$t+3*En-3*zn+Lo)*Bo))}}return st},kt=(N,U)=>Math.max(C(N*p+U),C(N*p+U+1)),Ut=(N,U)=>Math.max(C(U*p+N),C((U+1)*p+N));for(let N=0;N<b;N++){let U=kt(N,0),st=[...Q(0,N),...Q(1,N)];for(let V=1;V<p-1;V++){let at=kt(N,V);at===U?st.push(...Q(V+1,N)):(o.polyline(Mt(st),D(U)),st=[...Q(V,N),...Q(V+1,N)],U=at)}o.polyline(Mt(st),D(U))}for(let N=0;N<p;N++){let U=Ut(N,0),st=[...Q(N,0),...Q(N,1)];for(let V=1;V<b-1;V++){let at=Ut(N,V);at===U?st.push(...Q(N,V+1)):(o.polyline(Mt(st),D(U)),st=[...Q(N,V),...Q(N,V+1)],U=at)}o.polyline(Mt(st),D(U))}}let zt=null;function Po(o,a,c){let b=Math.ceil(L/24)+1,h=Math.ceil(R/24)+1;!zt||zt.length!==b*h?zt=new Float32Array(b*h):zt.fill(0);let u=!1;for(let S of d.particles){if(S.cap)continue;let C=a(S);C<=0||(u=!0,Zn(zt,b,h,24,S.x,S.y,42,C))}if(!u)return;let f=0;for(let S=0;S<zt.length;S++)zt[S]>f&&(f=zt[S]);if(f<=0)return;let x=lt,F=[.25,.5,.78],k=[];for(let S=0;S<F.length;S++){let C=F[S]*f;k.length=0;for(let D=0;D<h-1;D++)for(let $=0;$<b-1;$++){let H=zt[D*b+$],K=zt[D*b+$+1],dt=zt[(D+1)*b+$+1],ft=zt[(D+1)*b+$],Q=Qn(H,K,dt,ft,C);if(!Q.length)continue;let rt=$*24,Mt=D*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 wi(o){let p=lt,b={r:p[0],g:p[1],b:p[2],alpha:0,width:1.1},h=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:C}=Gt(B,m.forces,W,x,F);if(yt){let K=ve(en,x,F,yt,.04);S+=K.x,C+=K.y}let D=Math.hypot(S,C);if(!(D>1e-9))break;let $=x+S/D*9,H=F+C/D*9;if($<0||H<0||$>L||H>R)break;h[0]=x,h[1]=F,h[2]=$,h[3]=H,b.alpha=.34*(1-k/24),o.segments(h,b),x=$,F=H}}}function Mi(o){let a=lt;for(let c of B){if(!c.vis||!c.feedback)continue;let v=`d ${c.d.toFixed(2)}`,p=c.cx+c.hw+8,b=c.cy;o.rect(p-3,b-7,o.measureText(v)+6,14,a[0],a[1],a[2],mt(.3+c.d*.55,0,.85)),o.text(v,p,b+.5,5,6,11,.92)}}function ki(o,a){if(o.clear(),!(!a.length||L===0||R===0))for(let c of a){c==="streamlines"?Ro(o,!1,!1):c==="force-vectors"?Ro(o,!1,!0):c==="field-lines"?vi(o):c==="grid"?bi(o):c==="temperature"?Po(o,p=>p.heat,.5):c==="energy"?Po(o,p=>.5*p.m*(p.vx*p.vx+p.vy*p.vy),.42):c==="path"?wi(o):c==="data"&&Mi(o);let v=q.get(c);v&&v(o,W,L,R)}}function kn(o){Tt++,W.t=(o-Fo)/1e3,W.frameN=Tt;let a=Number.isFinite(hn)?(o-hn)/16.6667:1;hn=o;let c=wt();if(W.dt=c<=0?0:mt(a,.2,2)*c,it<1&&(it=Math.min(1,it+.012)),tr(W.form,yo,.03),ee){let f=A.viewport();Z=f.originX??0,ot=f.originY??0}let v=A.scrollY?.()??0,p=v-he;if(W.scrollV=(W.scrollV??0)*.7+Math.abs(p)*.3,he=v,p!==0&&!ee)for(let f of B)f.cy-=p;for(let f of vt){let x=v*(.025+f.depth*.08);f.offsetY+=(x-f.offsetY)*.04}if(B.length&&Tt%6===0&&(Ke(B,L,R,Z,ot),y(B),ks(B,W.supernova)),W.dt!==0&&js(),tt.length&&W.dt){let f=W.dt/60;for(let x of tt)bs(x.agent,x.from.d>.08,0,f)}let b=null;for(let f of B)if(f.on&&f.vis){b=f;break}let h=yt??b;if(xt.k+=((h?1:0)-xt.k)*.07,h){let f=yt?yt.x:b.cx,x=yt?yt.y:b.cy;xt.x=xt.x?xt.x+(f-xt.x)*.16:f,xt.y=xt.y?xt.y+(x-xt.y)*.16:x}Tt%30===0&&(ue=(A.scrollHeight?.()??R)-R||1);let u=Ce?pt(Ce):Ln(Eo,v/ue);if(lt=[lt[0]+(u[0]-lt[0])*.08,lt[1]+(u[1]-lt[1])*.08,lt[2]+(u[2]-lt[2])*.08],O.accent=_n(lt),d.reindex(),hi(),_s(),W.dt&&Lr(B,d.particles),yt&&W.dt)for(let f of d.particles){if(f.cap)continue;let x=ve(en,f.x,f.y,yt,.6);f.vx+=x.x,f.vy+=x.y}if(O.waveStyle==="circular")if(O.waveCenter)Zt=typeof O.waveCenter=="function"?O.waveCenter():O.waveCenter;else{let f=B.find(x=>x.tokens.includes("star")||x.tokens.includes("vortex"));f?Zt={x:f.cx,y:f.cy}:Zt={x:L/2,y:R/2}}else Zt=null;if(Qs(),dr({store:d,bodies:B,env:W,forces:m.forces,conditions:m.conditions,waves:vt,waveStyle:O.waveStyle,waveCenter:Zt,separation:O.separation}),Lt&&(Lt.x=ko,Lt.y=So,Lt.vx=0,Lt.vy=0,Lt.heat=Math.min(1,Lt.heat+.2)),W.dt){for(let f of w.values())f.step();ct&&ct.update(d.particles),Dr(d,Wt,Mo,vt,L,R,W.t,ht),_r(Wt,vt,B,m.forces,L,R,W.t,f=>void d.add(ae(f))),ai(),Zs()}if(mi(),Ws(),yi(),ti(),ei(),ni(),si(o),_(),e&&O.render!=="none"&&ho&&(c>0||Tt%4===0)&&(xi(),i)){let f=De(O.overlay);f.length&&ki(i,f)}Kt=A.raf(kn)}function Sn(o){let a=ge[o];a&&(yo=o==="ambient"?{...ln}:{...a.preset},fn=o)}let _e="",$o=Fo;function Io(){let o=A.viewport().height*.5,a="";A.root.querySelectorAll("[data-formation]").forEach(c=>{let v=c.getBoundingClientRect();v.top<=o&&v.bottom>=o&&(a=c.dataset.formation??"")}),a&&a!==_e&&(_e=a,Sn(a))}let No=()=>void($o=un()),Si=()=>{No(),Io()},Do=setInterval(()=>{un()-$o>6e3&&_e!=="ambient"&&(_e="ambient",Sn("ambient"))},1200);Do.unref?.();let Ei=()=>Co();Co(),De(O.overlay).length&&l();let Fi=()=>{A.hidden?.()??!1?(A.cancelRaf(Kt),Kt=0):Kt||(Kt=A.raf(kn))};A.onResize&&j.push(A.onResize(Ei)),A.onScroll&&j.push(A.onScroll(Si)),A.onVisibility&&j.push(A.onVisibility(Fi)),A.onInput&&j.push(A.onInput(No)),A.onBodyEvent&&(j.push(A.onBodyEvent(Jr,Vs)),j.push(A.onBodyEvent(Qr,Xs)),j.push(A.onBodyEvent(Zr,Ks))),Io(),Kt=A.raf(kn);let te={projections:qs,scan:Pe,rescan:Pe,setAccent:o=>{O.accent=o,lt=pt(o)},setPalette:o=>{let a=We(o);Eo=a.map(pt);let c=a[0];c&&(O.accent=c,lt=pt(c))},setFormation:Sn,setWaveStyle:o=>{O.waveStyle=o},setWaveCenter:o=>{O.waveCenter=o},setSeparation:o=>{O.separation=o>=0?o:0},setAttention:o=>{if(O.attention=o,!o)for(let a of B)a.attn=1},setCausality:o=>{if(O.causality=o,!o)for(let a of B)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}De(O.overlay).length&&l(),Ie(A.viewport().dpr)}O.render=o},setOverlay:o=>{O.overlay=o,De(o).length?l():i?.clear()},setHeatmap:o=>{if(O.heatmap=o,o)!ct&&L>0&&(ct=new Me(L,R));else if(ct){ct.clear(),ct=null;for(let a of B)(a.writeTarget??a.el).style.removeProperty("--field-heatmap-density")}},setDprCap:o=>{O.dprCap=o>0?o:2,e&&Ie(A.viewport().dpr)},setQualityTier:o=>{let a=Math.max(0,Math.min(3,Math.floor(o||0)));a!==$e&&($e=a,e&&Ie(A.viewport().dpr))},get policy(){return ao(nt)},setPolicy:o=>{nt=ao(o)},forAgent:o=>{let a=new Set(o.capabilities??[]),c=(o.redactions??[]).slice(),v=f=>a.has(f),p=()=>{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(!p()){let C=te.query({...f,include:["bodies"]});return C.metrics={},C.relationships=[],C.influences=[],v("read:projections")||(C.projections=[]),nn(C,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(C=>!F||F.has(C)),S=te.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=[]),nn(S,c)},snapshot:(f={})=>{if(!p()){let k=te.snapshot({profile:"public"});return nn(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=te.snapshot(x);return v("read:projections")||(F.projections=[]),nn(F,c)}};return v("read:replay")&&(u.replay=(f,x,F)=>te.replay(f,x,F)),v("read:focus")&&(u.focusState=f=>{let x=te.focusState(f);return p()?x:{frame:x.frame,time:x.time,entries:[]}}),Object.freeze(u)},threads:Mn,burst:(o,a,c)=>{let v=Cr;for(let p of d.particles){let b=Or(p.x-o,p.y-a,v,6,p.z??0);b.heat!==0&&(p.vx+=b.vx,p.vy+=b.vy,b.vz&&(p.vz=(p.vz??0)+b.vz),p.heat=Math.max(p.heat,b.heat),c&&(p.color=c))}Gn(Wt,vt,o,a,v,L,R,W.t,p=>void d.add(ae(p))),zo(o,a,2,c)},flowTo:(o,a,c)=>{yt=kr(o,a,c)},clearFlow:()=>{yt=null},seed:o=>{Re=o,Ao()},atomAt:(o,a)=>{let c=null,v=1/0;for(let p of d.near(o,a,24)){if(p.atom==null)continue;let b=(p.x-o)**2+(p.y-a)**2+(p.z??0)**2;b<v&&(v=b,c=p.atom)}return c},focusAt:(o,a)=>{let c=null,v=1/0;for(let p of d.near(o,a,24)){if(p.atom==null)continue;let b=(p.x-o)**2+(p.y-a)**2+(p.z??0)**2;b<v&&(v=b,c=p)}return Lt=c,c?(ko=c.x,So=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 p=0;p<a.length&&v<c;p++){let b=a[p];if(b.report!==void 0)continue;let h=v*5;o[h]=b.x,o[h+1]=b.y,o[h+2]=b.z??0,o[h+3]=b.heat,o[h+4]=b.size,v++}return v},readParticleIds:o=>{let a=d.particles,c=0;for(let v=0;v<a.length&&c<o.length;v++){let p=a[v];p.report===void 0&&(o[c++]=p.id??0)}return c},readParticleChannels:(o,a)=>{let c=d.particles,v=0;for(let p=0;p<c.length;p++){let b=c[p];if(!("report"in b&&b.report!==void 0)){if(v>=Math.min(...a.map(h=>h.length)))break;for(let h=0;h<o.length&&!(h>=a.length);h++){let u=o[h];a[h][v]=u==="x"?b.x:u==="y"?b.y:u==="z"?b.z??0:u==="vx"?b.vx:u==="vy"?b.vy:u==="heat"?b.heat:u==="size"?b.size:u==="m"?b.m:u==="id"?b.id??0:u==="age"?b.age??0:u==="charge"?b.charge??0:0}v++}}return v},registerOverlay:(o,a)=>(q.set(o,a),()=>{q.delete(o)}),addAgent:o=>{let a=ae({x:o.x,y:o.y,z:o.z,species:o.species});return a.vx=0,a.vy=0,o.z===void 0&&O.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:()=>""}},p=we(v);p.rect=c,p.data=o.data,o.identity!=null&&(p.identity=typeof o.identity=="string"?{id:o.identity}:o.identity),o.authority&&(p.authority=o.authority),p.feedback=!0;let b={};p.onFeedback=u=>{Object.assign(b,u),o.onFeedback?.(u)},X.push(p),B=B.concat(p),Ke([p],L,R,Z,ot);let h={data:o.data,get channels(){return b},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,p.tint=u.color)},remove:()=>{let u=X.indexOf(p);u>=0&&X.splice(u,1),B=B.filter(f=>f!==p);for(let f=tt.length-1;f>=0;f--){let x=tt[f];(x.from===p||x.to===p)&&tt.splice(f,1)}}};return bt.set(h,p),h},addEdge:(o,a,c)=>{let v=bt.get(o),p=bt.get(a);if(!v||!p)throw new Error("addEdge: both arguments must be handles returned by addBody on this field.");let b={id:`e${Se++}`,from:"",to:"",type:c?.type??"related",strength:c?.strength??.5,tension:0,memory:0,active:!1},h={agent:b,from:v,to:p,fromData:o.data,toData:a.data};return tt.push(h),{set:u=>{u.strength!=null&&(b.strength=u.strength<0?0:u.strength>1?1:u.strength),u.type!=null&&(b.type=u.type)},remove:()=>{let u=tt.indexOf(h);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,p=0,b=0,h=!1;a&&("width"in a?(c={x:a.x,y:a.y,width:a.width,height:a.height},v=a.x+a.width/2,p=a.y+a.height/2,b=Math.max(a.width,a.height)/2):(b=o.radius??240,v=a.x,p=a.y,c={x:v-b,y:p-b,width:b*2,height:b*2}),h=!0);let u=new Set(o.include??(h?["bodies","metrics","relationships","influences"]:["bodies","metrics","relationships"])),f=$=>{if(!$.vis)return!1;if(!h)return!0;if("width"in a){let H=c;return $.cx>=H.x&&$.cx<=H.x+H.width&&$.cy>=H.y&&$.cy<=H.y+H.height}return Math.hypot($.cx-v,$.cy-p)<=b},x=B.filter(f),F=u.has("bodies")?x.map($=>{let{metrics:H,dimensions:K}=go($),dt=dn($);return{id:dt.id,identity:dt,rect:{x:$.cx-$.hw,y:$.cy-$.hh,width:$.hw*2,height:$.hh*2},tokens:$.tokens.slice(),metrics:H,dimensions:K,activeFormations:[fn],authority:$.authority??"anchored"}}):[],k={};if(u.has("metrics")&&(k.particles=d.size,k.bodies=x.length,x.length>0)){let $=0;for(let H of x)$+=H.d;k.meanDensity=$/x.length}let S=u.has("relationships")?tt.filter($=>!h||f($.from)||f($.to)).map($=>({from:Jt($.from),to:Jt($.to),type:$.agent.type,strength:$.agent.strength,memory:$.agent.memory,active:$.agent.active,causal:$.agent.active})):[],C=[];if(u.has("influences")&&h)for(let $ of x){if($.tokens.length===0)continue;let H=io(m.forces,$.tokens,$,v,p);for(let K of H.attribution)C.push({source:Jt($),force:K.force,channel:K.channel,contribution:K.contribution})}let D={query:o,frame:W.frameN,time:W.t,region:c,bodies:F,metrics:k,relationships:S,influences:C,projections:Fe()};return o.lens?Mr(D,o.lens):D},snapshot:(o={})=>{let a=uc(o),c=a.includeRelationships,v=B.filter(f=>f.vis),p=v.map(f=>{let{metrics:x,dimensions:F}=go(f),k=dn(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=Us(f.data)),S}),b=c?tt.map(f=>({from:Jt(f.from),to:Jt(f.to),type:f.agent.type,strength:f.agent.strength,memory:f.agent.memory,active:f.agent.active,causal:f.agent.active})):[],h={particles:d.size,bodies:v.length};if(v.length>0){let f=0;for(let x of v)f+=x.d;h.meanDensity=f/v.length}let u={id:`snap-${W.frameN}-${Ls++}`,createdAt:W.t,frame:W.frameN,version:Le,formations:[fn],bodies:p,relationships:b,metrics:h,projections:Fe()};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=io(m.forces,x.tokens,x,x.cx+8,x.cy);for(let k of F.attribution)f.push({source:Jt(x),force:k.force,channel:k.channel,contribution:k.contribution})}u.influences=f}return u},diff:(o,a)=>Bn(o,a),replay:(o,a,c)=>Zo(o,a,c),addField:(o,a)=>(It.set(o,a),{name:o,set:c=>{It.set(o,c)},remove:()=>{It.delete(o)}}),sampleField:(o,a,c)=>{let v=It.get(o);return v?v(a,c):0},energy:()=>Fs(d.particles),sample:(o,a)=>{let{fx:c,fy:v}=Gt(B,m.forces,W,o,a);return{x:c,y:v}},sampleScalar:(o,a)=>ct?ct.norm(o,a):(Kn("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):(Kn("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),focus:(o,a)=>Ns(o,a),focusState:o=>Ds(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:Le,guarantees:{determinism:"conditionally-deterministic",controlledInputs:["injected-rng","clock"],uncontrolledInputs:["host-geometry","body-ordering"],requirements:["inject the rng","dt === 1 for cross-run equivalence","identical host geometry"],crossPlaneTolerance:1e-6},scrollV:()=>W.scrollV??0,setVisible:o=>{ho=o},setBackground:o=>{O.background=o,o==="transparent"&&e&&e.clearRect(0,0,L,R)},destroy:()=>{A.cancelRaf(Kt),clearInterval(Do);for(let o of j)o();for(let o of ie)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;ie=[];for(let o of Ht)(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 re)for(let a of o.emitted)a.remove();re=[],d.clear(),A.detach?.()}};return te}var rn={};function sn(){return rn.reducedMotion!==void 0?rn.reducedMotion:typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function an(){return rn.hidden!==void 0?rn.hidden:typeof document<"u"&&document.hidden}var xc=["--field-density","--d"],As=!1;function Ts(){if(As)return[];As=!0;let n=globalThis.CSS;if(!n||typeof n.registerProperty!="function")return[];let t=[];for(let e of xc)try{n.registerProperty({name:e,syntax:"<number>",inherits:!0,initialValue:"0"}),t.push(e)}catch{}return t}var Cs=["pointerdown","wheel","keydown","touchstart"];function ke(){return Ts(),{root:document,viewport:()=>({width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio||1}),scrollY:()=>window.scrollY||0,scrollHeight:()=>document.documentElement.scrollHeight,reducedMotion:()=>sn(),hidden:()=>an(),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 Cs)window.addEventListener(t,n,{passive:!0});return()=>{for(let t of Cs)window.removeEventListener(t,n)}},onBodyEvent:(n,t)=>(document.addEventListener(n,t),()=>document.removeEventListener(n,t))}}var Os=["pointerdown","wheel","keydown","touchstart"];function Rs(n){return n.setAttribute(Xe,""),{root:n,detach:()=>n.removeAttribute(Xe),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:()=>sn(),hidden:()=>an(),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 Os)n.addEventListener(e,t,{passive:!0});return()=>{for(let e of Os)n.removeEventListener(e,t)}},onBodyEvent:(t,e)=>(n.addEventListener(t,e),()=>n.removeEventListener(t,e))}}function Ps(n,t={}){return on(n,{...t,host:ke()})}function co(n,t={}){let{host:e,bounds:r,...s}=t,i=e??(r?Rs(r):ke());return on(n,{...s,host:i})}function lo(){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 cn(n=document.body){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText=gs,n.appendChild(t),t}function $s(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 vc(n={}){lo();let{target:t=document.body,...e}=n,r=cn(t),s=Ps(r,e);return{...s,destroy:()=>{s.destroy(),r.remove()}}}var fo=class{constructor(t={}){Y(this,"canvas");Y(this,"field");Y(this,"managed");lo();let{canvas:e,target:r,bounds:s,...i}=t;this.managed=!e,this.canvas=e??(s?$s(s):cn(r)),this.field=co(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)}focus(t,e){this.field.focus(t,e)}focusState(t){return this.field.focusState(t)}on(t,e){return this.field.on(t,e)}get version(){return this.field.version}get guarantees(){return this.field.guarantees}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{Ho as CONDITIONS,Le as FIELD_VERSION,On as FORCES,qo as FORMATIONS,fo as FieldField,Rn as PALETTE,ke as browserHost,co as createField,vs as cssFeedbackSink,ic as headlessHost,cn as makeFieldCanvas,vc as mountField};
|
|
2
|
+
var ji=Object.defineProperty;var Ui=(e,t,n)=>t in e?ji(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Y=(e,t,n)=>Ui(e,typeof t!="symbol"?t+"":t,n);var Ve="0.11.0";var Bn=[{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"}],Ko=Object.fromEntries(Bn.map(e=>[e.id,e])),Wn=Bn.map(e=>e.color),ke=["#4da3ff","#2dd4bf","#a78bfa","#ff6e9c","#ff9d5c"],Ln=["spotlight","screen","resonate"],Yi=["spawn"],qn=300,Hn=120;function Gi(e){return Ln.includes(e)?"modifier":Yi.includes(e)?"source":"force"}function Xe(e){let t=[],n=[],r=[];for(let s of e){let i=Gi(s);i==="modifier"?t.push(s):i==="source"?r.push(s):n.push(s)}return t.length>1&&t.sort((s,i)=>Ln.indexOf(s)-Ln.indexOf(i)),{modifiers:t,forces:n,sources:r}}var Jo=[{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}}],Ee=Object.fromEntries(Jo.map(e=>[e.id,e]));var Qo=[{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}],Yc=Object.fromEntries(Qo.map(e=>[e.id,e]));var Vi={ours:ke,heatmap:["#2b3a8c","#2d8fd4","#3fd07a","#ffe14d","#ff8a3d","#e23b3b"],infrared:["#2a0a4a","#8e24aa","#e53935","#ff8f00","#ffd54f","#fffde7"],spectrum:["#ff3b30","#ff9500","#ffcc00","#34c759","#00c7be","#007aff","#af52de"]};function Ke(e){return Array.isArray(e)?e.length>0?e:ke:typeof e=="string"?Vi[e]??ke:ke}var jn={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"]}},Un="warm";var pt=(e,t,n)=>e<t?t:e>n?n:e;function gt(e){let t=e.replace("#",""),n=t.length===3?t.replace(/./g,s=>s+s):t,r=Number.parseInt(n.slice(0,6),16);return Number.isNaN(r)?[77,163,255]:[r>>16&255,r>>8&255,r&255]}var Xi=[255,224,200],Ki=[255,110,80];function Yn(e,t,n,r,s=Xi,i=Ki){let l=s[0]+(i[0]-s[0])*t,d=s[1]+(i[1]-s[1])*t,h=s[2]+(i[2]-s[2])*t;return l+=(r[0]-l)*n,d+=(r[1]-d)*n,h+=(r[2]-h)*n,e[0]=l,e[1]=d,e[2]=h,e}function Gn([e,t,n]){let r=s=>pt(Math.round(s),0,255).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`}function Zo(e,t,n){let[r,s,i]=gt(e),[l,d,h]=gt(t),b=n<0?0:n>1?1:n;return Gn([r+(l-r)*b,s+(d-s)*b,i+(h-i)*b])}function Vn(e,t){if(e.length===0)return[77,163,255];if(e.length===1)return e[0];let n=pt(t,0,1)*(e.length-1),r=Math.min(e.length-2,Math.floor(n)),s=n-r,i=e[r],l=e[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 tr(e,t,n,r=0){if(!(t>0))return 1;let s=Math.max(0,1-e/t),i=1-n*s*s,l=Math.min(Math.max(r,0),1);return i<l?l:i>1?1:i}var Je=1;function Qe(e){let t=e.ux!==0?e.hw/Math.abs(e.ux):1/0,n=e.uy!==0?e.hh/Math.abs(e.uy):1/0,r=Math.min(t,n),s=e.ux*r,i=e.uy*r,l=e.spin<0?-1:1;return[{x:e.cx+s,y:e.cy+i,q:l},{x:e.cx-s,y:e.cy-i,q:-l}]}function er(e,t,n){let r=0,s=0;for(let i of e){let l=t-i.x,d=n-i.y,h=Math.max(Je,Math.hypot(l,d)),b=i.q/(h*h);r+=l/h*b,s+=d/h*b}return{x:r,y:s}}function nr(e,t,n,r,s,i){let l=s-e,d=i-t,h=Math.max(Je,Math.hypot(l,d)),x=(n<0?-1:1)*r/(h*h);return{x:l/h*x,y:d/h*x}}function or(e,t){let n=e/20+(t?.45:0);return n<0?0:n>1?1:n}function rr(e,t,n){return Math.round(e+(t-e)*n)}function sr(e,t={}){let n=t.beta??2,r=t.lo??.25,s=t.hi??3,i=e.length,l=new Array(i).fill(1);if(i===0)return l;let d=0,h=0;for(let x of e){let E=x.strength>0?x.strength:0;d+=E,h+=E*(1+(x.on?n:0))}if(d<=0||h<=0)return l;let b=d/h;for(let x=0;x<i;x++){let z=(1+(e[x].on?n:0))*b;z<r?z=r:z>s&&(z=s),l[x]=z}return l}function ir(e,t={}){let n=t.threshold??.55,r=t.kappa??.6,s=t.falloff??320,i=e.length,l=new Array(i).fill(0);if(i<2)return l;let d=new Array(i).fill(0);for(let h=0;h<i;h++){let b=e[h],x=b.d-n;if(x<=0)continue;let E=0;for(let F=0;F<i;F++){if(F===h){d[F]=0;continue}let T=e[F],R=Math.hypot(b.cx-T.cx,b.cy-T.cy),_=R<s?1-R/s:0;d[F]=_,E+=_}if(E<=0)continue;let z=r*x;for(let F=0;F<i;F++){let T=d[F];if(T<=0)continue;let R=z*T/E;l[F]+=R,l[h]-=R}}return l}var ar=e=>`${e.from}\0${e.to}\0${e.type}`;function Xn(e,t){let n=[],r=new Map(e.bodies.map(F=>[F.id,F])),s=new Map(t.bodies.map(F=>[F.id,F]));for(let[F,T]of r){let R=s.get(F);if(!R){n.push({id:F,kind:"removed"});continue}let _={},I=!1,V=new Set([...Object.keys(T.metrics),...Object.keys(R.metrics)]);for(let ot of V){let ft=T.metrics[ot]??0,it=R.metrics[ot]??0;ft!==it&&(_[ot]={from:ft,to:it},I=!0)}I&&n.push({id:F,kind:"changed",metrics:_})}for(let F of s.keys())r.has(F)||n.push({id:F,kind:"added"});let i=[],l=new Map(e.relationships.map(F=>[ar(F),F])),d=new Map(t.relationships.map(F=>[ar(F),F]));for(let[F,T]of l){let R=d.get(F);if(!R){i.push({from:T.from,to:T.to,type:T.type,kind:"removed"});continue}let _={from:T.from,to:T.to,type:T.type,kind:"changed"},I=!1;T.strength!==R.strength&&(_.strength={from:T.strength,to:R.strength},I=!0),T.active!==R.active&&(_.active={from:T.active,to:R.active},I=!0),I&&i.push(_)}for(let[F,T]of d)l.has(F)||i.push({from:T.from,to:T.to,type:T.type,kind:"added"});let h=[],b=new Set([...Object.keys(e.metrics),...Object.keys(t.metrics)]);for(let F of b){let T=e.metrics[F]??0,R=t.metrics[F]??0;T!==R&&h.push({key:F,from:T,to:R})}let x=[],E=new Set(e.formations),z=new Set(t.formations);for(let F of z)E.has(F)||x.push({id:F,kind:"activated"});for(let F of E)z.has(F)||x.push({id:F,kind:"deactivated"});return{from:e.id,to:t.id,bodyChanges:n,relationshipChanges:i,metricChanges:h,formationChanges:x}}function cr(e,t,n={}){let r=x=>Math.round(x*1e3)/1e3,s=Xn(e,t),i=t.frame,l=t.createdAt,d=[],h=(x,E,z={})=>{d.push({frame:i,time:l,cause:x,description:E,...z})};for(let x of s.formationChanges)h("formation",`Formation '${x.id}' ${x.kind}`,{source:x.id});for(let x of s.relationshipChanges){let E;if(x.kind==="added")E="formed";else if(x.kind==="removed")E="dissolved";else{let z=[];if(x.active&&z.push(x.active.to?"became active":"went idle"),x.strength){let F=x.strength.to>=x.strength.from?"strengthened":"weakened";z.push(`${F} ${r(x.strength.from)}\u2192${r(x.strength.to)}`)}E=z.join(", ")||"changed"}h("relationship",`Relationship ${x.from}\u2192${x.to} (${x.type}) ${E}`,{source:x.from,target:x.to,contribution:x.strength})}for(let x of s.bodyChanges)if(x.kind==="added")h("measurement",`Body ${x.id} entered the field`,{source:x.id});else if(x.kind==="removed")h("measurement",`Body ${x.id} left the field`,{source:x.id});else if(x.metrics)for(let[E,z]of Object.entries(x.metrics)){let F=z.to>z.from?"rose":"fell";h("metric",`Body ${x.id} ${E} ${F} ${r(z.from)}\u2192${r(z.to)}`,{source:x.id,contribution:z})}if(e.influences&&t.influences){let x=T=>typeof T=="number"?Math.abs(T):Math.hypot(T.x,T.y,T.z??0),E=T=>`${T.source} ${T.force} ${T.channel??"linear"}`,z=new Map(e.influences.map(T=>[E(T),T])),F=new Map(t.influences.map(T=>[E(T),T]));for(let T of new Set([...z.keys(),...F.keys()])){let R=z.get(T),_=F.get(T),I=R?x(R.contribution):0,V=_?x(_.contribution):0;if(Math.abs(V-I)<1e-9)continue;let ot=_??R,ft=V>I?I===0?"engaged":"grew":V===0?"released":"weakened",it=(ot.channel??"linear")==="thermal"?" (thermal)":"";h("force",`Force ${ot.force} on ${ot.source}${it} ${ft} ${r(I)}\u2192${r(V)}`,{source:ot.source,contribution:{from:I,to:V}})}}let b=n.focus?d.filter(x=>x.source===n.focus||x.target===n.focus):d;return{from:e.id,to:t.id,focus:n.focus,steps:b}}var Ze=class{constructor(t=64){Y(this,"cell");Y(this,"bins",new Map);Y(this,"freeBins",[]);this.cell=t>0?t:64}key(t,n){return(t+32768)*65536+(n+32768)}clear(){for(let t of this.bins.values())t.length=0,this.freeBins.push(t);this.bins.clear()}insert(t){let n=this.key(Math.floor(t.x/this.cell),Math.floor(t.y/this.cell)),r=this.bins.get(n);if(r)r.push(t);else{let s=this.freeBins.pop();s?(s.push(t),this.bins.set(n,s)):this.bins.set(n,[t])}}rebuild(t){this.clear();for(let n of t)this.insert(n)}near(t,n,r,s=0){let i=[],l=r*r,d=Math.floor((t-r)/this.cell),h=Math.floor((t+r)/this.cell),b=Math.floor((n-r)/this.cell),x=Math.floor((n+r)/this.cell);for(let E=d;E<=h;E++)for(let z=b;z<=x;z++){let F=this.bins.get(this.key(E,z));if(F)for(let T of F){let R=T.x-t,_=T.y-n,I=(T.z??0)-s;R*R+_*_+I*I<=l&&i.push(T)}}return i}};var tn=class{constructor(t=64){Y(this,"particles",[]);Y(this,"hash");this.hash=new Ze(t)}get size(){return this.particles.length}add(t){return this.particles.push(t),t}remove(t){let n=this.particles.indexOf(t);if(n<0)return;let r=this.particles.pop();r&&n<this.particles.length&&(this.particles[n]=r)}clear(){this.particles.length=0,this.hash.clear()}reindex(){this.hash.rebuild(this.particles)}neighbors(t,n){let r=this.hash.near(t.x,t.y,n,t.z??0),s=[];for(let i of r)i!==t&&s.push(i);return s}near(t,n,r){return this.hash.near(t,n,r)}};function lr(e,t,n=.03){e.driftX+=(t.driftX-e.driftX)*n,e.wander+=(t.wander-e.wander)*n,e.orbit+=(t.orbit-e.orbit)*n,e.spread+=(t.spread-e.spread)*n,e.conv+=(t.conv-e.conv)*n}function fr(e){for(let t of e)if(t.vis&&t.tokens.indexOf("sink")>=0)return t;return null}var Ji=[.24,.4,.55,.7,.85];function dr(e){let t=[];for(let n=0;n<5;n++)t.push({baseFrac:Ji[n]??.5,amp:22+n*15,freq:.0012+n*8e-4,phase:n*1.7%6.28,speed:13e-5+n*9e-5,color:e[n%e.length]??[77,163,255],depth:n/4,dir:n%2?-1:1,offsetY:0});return t}function ur(e,t,n){let r=Math.round(16*t),s=[];for(let i=0;i<e;i++)for(let l=0;l<r;l++)s.push({wi:i,progress:n(),phase:(n()-.5)*.22*Math.PI,size:.7+n()*1.5,glow:n()<.3,speed:(35e-5+n()*9e-4)*(n()<.5?1:-1)});return s}function Ct(e,t,n,r,s=1,i=1,l){let d=e.baseFrac*r+e.offsetY+Math.sin(t*e.freq+e.phase+n*e.speed*1e3*s)*e.amp*i;if(l&&l.k>.001){let h=t-l.x,b=260,x=Math.exp(-(h*h)/(2*b*b));d+=(l.y-d)*.42*x*l.k*(.45+e.depth*.55)}return d}function hr(e,t,n,r=1,s=1){return Math.cos(t*e.freq+e.phase+n*e.speed*1e3*r)*e.amp*e.freq*s}function Fe(e,t,n,r,s=1,i=1){let l=e.baseFrac*r+e.offsetY,d=Math.max(1,Math.round(e.freq*2500));return l+Math.sin(d*t+e.phase+n*e.speed*1e3*s)*e.amp*i}function yr(e,t,n,r,s,i,l,d,h=1,b=1,x){if(l==="circular"){let E=t-d.x,z=n-d.y,F=Math.sqrt(E*E+z*z)||.001,T=Math.atan2(z,E),R=Math.min(s,i)*.48,_=Fe(e,T,r,R,h,b);return{dist:Math.abs(F-_),rWave:_,r:F,theta:T}}else{let E=Ct(e,t,r,i,h,b,x);return{dist:Math.abs(n-E),rWave:E,r:n,theta:0}}}var Ut={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null},mr=2654435769,xe=mr;function Qi(){xe=xe+1831565813|0;let e=Math.imul(xe^xe>>>15,1|xe);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}var en=null,pr=new Map;function Zi(e){let t=pr.get(e);return t||(t={sample:(n,r)=>en?.grid(e).sample(n,r)??0,gradient:(n,r)=>en?.grid(e).gradient(n,r)??{x:0,y:0},deposit:()=>{},decay:()=>{},clear:()=>{}},pr.set(e,t)),t}var gr={driftX:0,wander:0,orbit:0,spread:0,conv:0},Mt={dx:0,dy:0,dz:0,dist:1,form:gr,W:0,H:0,t:0,frameN:0,dt:1,c:12,G:1,probe:!0,rng:Qi,spark:()=>{},supernova:()=>{},spawn:()=>{},neighbors:(e,t)=>en?.neighbors(e,t)??[],grid:Zi};function ta(e){return en=e,Mt.W=e.W,Mt.H=e.H,Mt.D=e.D,Mt.t=e.t,Mt.frameN=e.frameN,Mt.dt=e.dt,Mt.c=e.c,Mt.G=e.G,Mt.scrollV=e.scrollV,Mt.integrator=e.integrator,Mt.fieldAt=e.fieldAt,Mt.accum=void 0,Mt.kinTouch=void 0,Mt.dz=0,Object.assign(gr,e.form),xe=mr,Mt}function Qt(e,t,n,r,s){Ut.x=r,Ut.y=s,Ut.vx=0,Ut.vy=0,Ut.heat=0,Ut.cap=null;let i=ta(n),l=0,d=0;for(let h of e){if(!h.vis||h.tokens.length===0)continue;let b,x;if(h.shaped){let F=h.cx-h.hw,T=h.cx+h.hw,R=h.cy-h.hh,_=h.cy+h.hh;b=(r<F?F:r>T?T:r)-r,x=(s<R?R:s>_?_:s)-s}else b=h.cx-r,x=h.cy-s;let E=b*b+x*x;if(h.range>0&&E>=h.range*h.range*2.56)continue;let z=Math.sqrt(E);i.dx=b,i.dy=x,i.dist=z<1?1:z;for(let F of h.tokens){let T=t[F];if(!(!T||T.modify))if(T.field){let R=T.field(h,r,s);l+=R.x,d+=R.y}else T.apply(h,Ut,i)}}return{fx:Ut.vx+l,fy:Ut.vy+d}}function nn(e,t,n,r){let s=0,i=0;for(let l of e)if(!(!l.vis||l.tokens.length===0)){if(l.range>0){let d=l.cx-n,h=l.cy-r;if(d*d+h*h>=l.range*l.range*2.56)continue}for(let d of l.tokens){let h=t[d];if(h?.field){let b=h.field(l,n,r);s+=b.x,i+=b.y}}}return{x:s,y:i}}var xr=.95,vr=.972,Pt=10;function ea(e,t,n,r){if(!t.when)return!0;let s=e[t.when];return s?s(t,n,r):!0}function br(e){return e.classified??(e.classified=Xe(e.tokens))}function Jn(e,t,n,r,s=1){let i=n.vx,l=n.vy,d=n.vz??0,h=n.heat,b=n.spin??0,x=n.age;e.apply(t,n,r),s===1||e.kinematic||(n.vx=i+(n.vx-i)*s,n.vy=l+(n.vy-l)*s,n.vz!==void 0&&(n.vz=d+(n.vz-d)*s)),e.kinematic&&r.integrator==="velocity-verlet"&&(n.vx!==i||n.vy!==l||(n.vz??0)!==d)&&(r.kinTouch=!0);let E=r.accum;if(E!==void 0){let z=n.vx-i,F=n.vy-l,T=(n.vz??0)-d;(z!==0||F!==0||T!==0)&&(E.linear.x+=z,E.linear.y+=F,E.linear.z+=T,E.attribution.push({force:e.token,channel:"linear",contribution:{x:z,y:F,z:T}}));let R=n.heat-h;R!==0&&(E.thermal=(E.thermal??0)+R,E.attribution.push({force:e.token,channel:"thermal",contribution:R}));let _=(n.spin??0)-b;if(_!==0){let I=E.angular??(E.angular={x:0,y:0,z:0});I.z+=_,E.attribution.push({force:e.token,channel:"angular",contribution:_})}if(x!==void 0&&n.age!==void 0){let I=n.age-x;if(I!==0){let V=E.temporal??(E.temporal={});V.decay=(V.decay??0)+I,E.attribution.push({force:e.token,channel:"temporal",contribution:I})}}t.attn!==void 0&&t.attn!==1&&((E.semantic??(E.semantic={})).attention=t.attn,E.attribution.push({force:e.token,channel:"semantic",contribution:t.attn}))}}function Kn(e,t,n,r,s){if(r.accum===void 0){if(s===1||e.kinematic){if(e.kinematic&&r.integrator==="velocity-verlet"){let h=n.vx,b=n.vy,x=n.vz??0;e.apply(t,n,r),(n.vx!==h||n.vy!==b||(n.vz??0)!==x)&&(r.kinTouch=!0);return}e.apply(t,n,r);return}let i=n.vx,l=n.vy,d=n.vz??0;e.apply(t,n,r),n.vx=i+(n.vx-i)*s,n.vy=l+(n.vy-l)*s,n.vz!==void 0&&(n.vz=d+(n.vz-d)*s);return}Jn(e,t,n,r,s)}function Sr(){return{linear:{x:0,y:0,z:0},attribution:[]}}function wr(e){for(let t of e){t.count=0;let n=t.thermo;n&&(n.n=0,n.sx=0,n.sy=0,n.ss=0,n.ss2=0,n.sh=0)}}var Mr=2*Math.PI/400;function na(e,t,n){let r=e*Mr+n,s=t*Mr-n;return{x:Math.sin(r)*Math.cos(s),y:-Math.cos(r)*Math.sin(s)}}function kr(e){let{store:t,bodies:n,env:r,forces:s,conditions:i,waves:l,separation:d}=e,h=r.dt;if(h===0){wr(n);return}let b=r.integrator==="velocity-verlet",{W:x,H:E,form:z}=r;r.fieldAt=(p,Et)=>nn(n,s,p,Et),wr(n);let F=null;for(let p of n)p.vis&&p.tokens.length>0&&br(p).modifiers.indexOf("screen")>=0&&(F??(F=[])).push(p);let T=F?new Array(F.length):null,R=!!l&&l.length>0,_=n.length>0,I=null,V=z.conv>.02?fr(n):null,ot=e.restingMotion,ft=ot?Math.max(0,ot.strength??1):0,it=.06*ft*Math.sqrt(h),vt=.02*ft*h,bt=r.t*.15,St=r.D??0;for(let p of t.particles){if(p.cap){p.x+=(p.cap.cx-p.x)*.18,p.y+=(p.cap.cy-p.y)*.18,p.z&&(p.z+=-p.z*.18),p.ax!==void 0&&(p.ax=p.ay=p.az=0);continue}p.z===void 0&&(p.z=0),p.vz===void 0&&(p.vz=0);let Et=0,Zt=0,mt=0;if(b){let q=.5*h*h;p.x+=p.vx*h+(p.ax??0)*q,p.y+=p.vy*h+(p.ay??0)*q,p.z+=p.vz*h+(p.az??0)*q,Et=p.vx,Zt=p.vy,mt=p.vz,r.kinTouch=!1}let Pe=p.z;if(R)if(e.waveStyle==="circular"){let q=null,A=1e9,H=0,K=0,Q=0,Ft=e.waveCenter||{x:x/2,y:E/2};for(let ut of l){let Ot=yr(ut,p.x,p.y,r.t,x,E,"circular",Ft);Ot.dist<A&&(A=Ot.dist,q=ut,H=Ot.r,K=Ot.rWave,Q=Ot.theta)}if(q&&A<70){let ut=1-A/70,Ot=-Math.sin(Q)*q.dir,ee=Math.cos(Q)*q.dir;p.vx+=Ot*.035*ut,p.vy+=ee*.035*ut;let Wt=Math.cos(Q)*Math.sign(K-H),O=Math.sin(Q)*Math.sign(K-H);p.vx+=Wt*.05*ut,p.vy+=O*.05*ut}}else{let q=null,A=1e9;for(let H of l){let K=Math.abs(Ct(H,p.x,r.t,E)-p.y);K<A&&(A=K,q=H)}q&&A<70&&(p.vx+=q.dir*.035*(1-A/70),p.vy+=hr(q,p.x,r.t)*.1*(1-A/70))}if(z.driftX&&(p.vx+=z.driftX*.02),z.spread>.02){let q=p.gx??.5,A=p.gy??.5,H=(q+r.frameN*4e-5)%1*x,K=A*E;p.vx+=(H-p.x)*6e-4*z.spread,p.vy+=(K-p.y)*6e-4*z.spread,St>0&&(p.vz+=((p.gz??.5)*St-Pe)*6e-4*z.spread)}if(V){let q=V.cx-p.x,A=V.cy-p.y,H=-Pe,K=Math.hypot(q,A,H)||1;p.vx+=q/K*z.conv*.06,p.vy+=A/K*z.conv*.06,p.vz+=H/K*z.conv*.06}if(_){if(F)for(let A=0;A<F.length;A++){let H=F[A],K=H.cx-p.x,Q=H.cy-p.y;T[A]=tr(Math.sqrt(K*K+Q*Q),H.range,H.strength,H.screenMin??0)}let q=p.m!==1&&p.m>0?1/p.m:1;for(let A of n){if(!A.vis||A.tokens.length===0||A.affects!==void 0&&!A.affects.has(p.species??0))continue;let H,K;if(A.shaped){let $=A.cx-A.hw,Z=A.cx+A.hw,tt=A.cy-A.hh,ce=A.cy+A.hh,be=p.x<$?$:p.x>Z?Z:p.x,we=p.y<tt?tt:p.y>ce?ce:p.y;H=be-p.x,K=we-p.y}else H=A.cx-p.x,K=A.cy-p.y;let Q=-p.z,Ft=H*H+K*K+Q*Q;if(A.range>0&&Ft>=A.range*A.range*2.56)continue;let ut=Math.sqrt(Ft);if(A.feedback&&ut<A.range*.5){A.count+=1-ut/(A.range*.5);let $=A.thermo??(A.thermo={n:0,sx:0,sy:0,ss:0,ss2:0,sh:0}),Z=p.vx*p.vx+p.vy*p.vy;$.n++,$.sx+=p.vx,$.sy+=p.vy,$.ss+=Math.sqrt(Z),$.ss2+=Z,$.sh+=p.heat}if(A.when&&!ea(i,A,p,r))continue;r.dx=H,r.dy=K,r.dz=Q,r.dist=ut<1?1:ut;let Ot=br(A),ee=1,Wt=!1,O=!1;for(let $ of Ot.modifiers){let Z=s[$]?.modify;if(!Z)continue;O=!0;let tt=Z(A,p,r);tt.strength!=null&&(ee*=tt.strength),tt.gate&&(Wt=!0)}for(let $ of Ot.forces){let Z=s[$]?.modify;if(!Z)continue;O=!0;let tt=Z(A,p,r);tt.strength!=null&&(ee*=tt.strength),tt.gate&&(Wt=!0)}if(Wt)continue;let at=1;if(F)for(let $=0;$<F.length;$++)F[$]!==A&&(at*=T[$]);let W=A.attn??1,L=ee*W*at*(A.focusMul??1);if(!O&&L===1)for(let $ of A.tokens){let Z=s[$];Z&&Kn(Z,A,p,r,q)}else if(O){let $=A.strength;A.strength=$*L;for(let Z of A.tokens){let tt=s[Z];tt&&!tt.modify&&Kn(tt,A,p,r,q)}A.strength=$}else{let $=A.strength;A.strength=$*L;for(let Z of A.tokens){let tt=s[Z];tt&&Kn(tt,A,p,r,q)}A.strength=$}}}if(d&&d>0){let q=r.neighbors(p,12);for(let A of q){let H=p.x-A.x,K=p.y-A.y,Q=(p.z??0)-(A.z??0),Ft=Math.hypot(H,K,Q)||.1;if(Ft<12){let ut=(12-Ft)/12*d*.12;p.vx+=H/Ft*ut,p.vy+=K/Ft*ut,p.vz!==void 0&&(p.vz+=Q/Ft*ut)}}}if(b){let q=p.vx-Et,A=p.vy-Zt,H=p.vz-mt;r.kinTouch?p.ax=p.ay=p.az=0:(p.vx=Et+.5*((p.ax??0)*h+q),p.vy=Zt+.5*((p.ay??0)*h+A),p.vz=mt+.5*((p.az??0)*h+H),p.ax=q/h,p.ay=A/h,p.az=H/h)}let te=r.c,$e=p.vx*p.vx+p.vy*p.vy+p.vz*p.vz;if($e>te*te){let q=te/Math.sqrt($e);p.vx*=q,p.vy*=q,p.vz*=q}if(p.maxSpeed!==void 0){let q=p.maxSpeed*p.maxSpeed,A=p.vx*p.vx+p.vy*p.vy+p.vz*p.vz;if(A>q){let H=p.maxSpeed/Math.sqrt(A);p.vx*=H,p.vy*=H,p.vz*=H}}b||(p.x+=p.vx*h,p.y+=p.vy*h,p.z+=p.vz*h);let Nt=r.integrator==="fixed"||b?Math.pow(xr,h):xr;if(p.vx*=Nt,p.vy*=Nt,p.vz*=Nt,p.spin!==void 0&&(p.orient=(p.orient??0)+p.spin*h,p.spin*=Nt),p.report===void 0){if(r.frameN%40===0&&z.wander>0){let q=.05*z.wander;p.vx+=((r.rng??Math.random)()-.5)*q,p.vy+=((r.rng??Math.random)()-.5)*q,St>0&&(p.vz+=((r.rng??Math.random)()-.5)*q)}if(z.wander>.05){let q=(Math.sin(p.x*.0032+r.t*.12)+Math.cos(p.y*.0034-r.t*.15))*Math.PI;p.vx+=Math.cos(q)*.013*z.wander,p.vy+=Math.sin(q)*.013*z.wander}if(ft>0)if(ot.mode==="thermal"){let q=(r.rng??Math.random)()||1e-9,A=it*Math.sqrt(-2*Math.log(q)),H=2*Math.PI*(r.rng??Math.random)();if(p.vx+=A*Math.cos(H),p.vy+=A*Math.sin(H),St>0){let K=(r.rng??Math.random)()||1e-9;p.vz+=it*Math.sqrt(-2*Math.log(K))*Math.cos(2*Math.PI*(r.rng??Math.random)())}}else{let q=na(p.x,p.y,bt);p.vx+=q.x*vt,p.vy+=q.y*vt}}p.heat*=r.integrator==="fixed"||b?Math.pow(vr,h):vr,p.age!=null&&(p.age-=h,p.age<=0&&(I??(I=[])).push(p)),p.report===void 0?(p.x<-Pt?p.x=x+Pt:p.x>x+Pt&&(p.x=-Pt),p.y<-Pt?p.y=E+Pt:p.y>E+Pt&&(p.y=-Pt),St>0&&(p.z<-Pt?p.z=St+Pt:p.z>St+Pt&&(p.z=-Pt))):(p.x<0?(p.x=0,p.vx=Math.abs(p.vx)):p.x>x&&(p.x=x,p.vx=-Math.abs(p.vx)),p.y<0?(p.y=0,p.vy=Math.abs(p.vy)):p.y>E&&(p.y=E,p.vy=-Math.abs(p.vy)),St>0&&(p.z<0?(p.z=0,p.vz=Math.abs(p.vz)):p.z>St&&(p.z=St,p.vz=-Math.abs(p.vz))),p.report(p))}if(_){for(let p of n)if(!(!p.vis||p.tokens.length===0))for(let Et of p.tokens)s[Et]?.source?.(p,r)}if(I)for(let p of I)t.remove(p)}var ae=class{constructor(t,n,r="diffuse",s=32){Y(this,"mode");Y(this,"cell");Y(this,"W");Y(this,"H");Y(this,"cols");Y(this,"rows");Y(this,"cur");Y(this,"nxt");Y(this,"prev");this.W=t,this.H=n,this.mode=r,this.cell=s,this.cols=Math.max(2,Math.ceil(t/s)+1),this.rows=Math.max(2,Math.ceil(n/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,n){return this.cur[this.clampRow(n)*this.cols+this.clampCol(t)]}sample(t,n){let r=t/this.cell,s=n/this.cell,i=Math.floor(r),l=Math.floor(s),d=r-i,h=s-l,b=this.at(i,l)*(1-d)+this.at(i+1,l)*d,x=this.at(i,l+1)*(1-d)+this.at(i+1,l+1)*d;return b*(1-h)+x*h}deposit(t,n,r){let s=this.clampCol(Math.round(t/this.cell)),i=this.clampRow(Math.round(n/this.cell));this.cur[i*this.cols+s]+=r}max(){let t=0;for(let n=0;n<this.cur.length;n++)this.cur[n]>t&&(t=this.cur[n]);return t}gradient(t,n){let r=this.cell;return{x:(this.sample(t+r,n)-this.sample(t-r,n))/(2*r),y:(this.sample(t,n+r)-this.sample(t,n-r))/(2*r)}}step(){this.mode!=="held"&&(this.mode==="wave"?this.stepWave():this.mode==="memory"?this.stepDiffuse(.03,.004):this.stepDiffuse())}stepDiffuse(t=.18,n=.01){let r=t<0?0:t>.24?.24:t,s=1-n,{cols:i,rows:l,cur:d,nxt:h}=this;for(let b=0;b<l;b++)for(let x=0;x<i;x++){let E=b*i+x,z=this.at(x-1,b)+this.at(x+1,b)+this.at(x,b-1)+this.at(x,b+1)-4*d[E];h[E]=(d[E]+r*z)*s}this.cur=h,this.nxt=d}stepWave(t=.25,n=.002){let r=t<0?0:t>.5?.5:t,s=1-n,{cols:i,rows:l,cur:d,prev:h,nxt:b}=this;for(let x=0;x<l;x++)for(let E=0;E<i;E++){let z=x*i+E,F=this.at(E-1,x)+this.at(E+1,x)+this.at(E,x-1)+this.at(E,x+1)-4*d[z];b[z]=(2*d[z]-h[z]+r*F)*s}this.prev=d,this.cur=b,this.nxt=h}decay(t){let n=t<=0?1:t>=1?0:1-t;if(n!==1)for(let r=0;r<this.cur.length;r++)this.cur[r]*=n}fillFrom(t){let{cols:n,rows:r,cell:s,cur:i}=this;for(let l=0;l<r;l++)for(let d=0;d<n;d++){let h=t(d*s,l*s);i[l*n+d]=Number.isFinite(h)?h:0}}clear(){this.cur.fill(0),this.nxt.fill(0),this.prev.fill(0)}resize(t,n){if(t===this.W&&n===this.H)return;this.W=t,this.H=n,this.cols=Math.max(2,Math.ceil(t/this.cell)+1),this.rows=Math.max(2,Math.ceil(n/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 Er={active:e=>e.on,fast:(e,t)=>t.vx*t.vx+t.vy*t.vy+(t.vz??0)*(t.vz??0)>.9,slow:(e,t)=>t.vx*t.vx+t.vy*t.vy+(t.vz??0)*(t.vz??0)<.22,hot:(e,t)=>t.heat>.3,cool:(e,t)=>t.heat<.08,scrolling:(e,t,n)=>(n?.scrollV??0)>.25};function Fr(){let e={},t={...Er};return{forces:e,conditions:t,force(n){e[n.token]=n},condition(n,r){t[n]=r}}}var oa={token:"attract",label:"Attract",apply(e,t,n){let r=e.range*(e.on?1.5:1),s=e.strength*(e.on?3:1);if(n.dist>=r)return;let i=(1-n.dist/r)**2*s*.5,l=n.dx/n.dist,d=n.dy/n.dist;t.vx+=l*i,t.vy+=d*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i),n.form.orbit&&(t.vx+=-d*i*n.form.orbit,t.vy+=l*i*n.form.orbit),e.on&&(t.heat=Math.max(t.heat,(1-n.dist/r)*.9))},meta:{desc:"a soft gravity-like well, bent into a spiral"}},ra={token:"repel",label:"Repel",apply(e,t,n){let r=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=r)return;let i=(1-n.dist/r)**2*s*.5;t.vx-=n.dx/n.dist*i,t.vy-=n.dy/n.dist*i,n.dz&&(t.vz=(t.vz??0)-n.dz/n.dist*i)},meta:{desc:"inverse-square outward push"}},sa={token:"swirl",label:"Swirl",apply(e,t,n){let r=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=r)return;let i=(1-n.dist/r)**1.4*s*.45,l=e.spin,d=n.dx/n.dist,h=n.dy/n.dist;t.vx+=h*i*l+d*i*.12,t.vy+=-d*i*l+h*i*.12,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i*.12),e.on&&(t.heat=Math.max(t.heat,(1-n.dist/r)*.6))},meta:{desc:"tangential swirl with light inward retention"}},ia={token:"stream",label:"Stream",apply(e,t,n){let r=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=r)return;let i=(1-n.dist/r)**1.1*s*.5;t.vx+=e.ux*i,t.vy+=e.uy*i,e.on&&(t.heat=Math.max(t.heat,(1-n.dist/r)*.5))},meta:{desc:"directional current along a heading"}},aa={token:"viscosity",label:"Viscosity",apply(e,t,n){let r=e.range*(e.on?1.4:1);if(n.dist>=r)return;let s=(1-n.dist/r)*(.05+e.strength*.07)*(e.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"}},ca={token:"jet",label:"Jet",kinematic:!0,apply(e,t,n){let r=e.range*(e.on?1.4:1);if(!(n.dist>=r))if(n.dist<24){let s=((n.rng??Math.random)()-.5)*.8,i=Math.cos(s),l=Math.sin(s),d=e.ux*i-e.uy*l,h=e.ux*l+e.uy*i,b=2.4+e.strength*2.6;t.vx=d*b,t.vy=h*b,t.x=e.cx+d*26,t.y=e.cy+h*26,t.z&&(t.z=0),t.vz&&(t.vz=0),t.heat=Math.max(t.heat,.9)}else{let s=(1-n.dist/r)**2*(.25+e.strength*.15);t.vx+=n.dx/n.dist*s,t.vy+=n.dy/n.dist*s,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*s)}},meta:{desc:"a fountain \u2014 draws matter in, jets it out along a heading"}},la={token:"tether",label:"Tether",apply(e,t,n){let r=e.range*.6*(e.on?1.25:1),s=r*2.1;if(n.dist>=s)return;let i=(.006+e.strength*.012)*(e.on?1.7:1),l=n.dist-r,d=n.dx/n.dist,h=n.dy/n.dist;t.vx+=d*l*i,t.vy+=h*l*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*l*i),t.vx*=.985,t.vy*=.985,t.vz&&(t.vz*=.985),e.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"}},fa={token:"wall",label:"Wall",kinematic:!0,apply(e,t,n){let s=Math.abs(t.x-e.cx),i=Math.abs(t.y-e.cy);if(s>=e.hw+6||i>=e.hh+6)return;let l=Math.hypot(t.vx,t.vy),d=e.hw+6-s,h=e.hh+6-i;d<h?(t.x=t.x<e.cx?e.cx-e.hw-6:e.cx+e.hw+6,t.vx=-t.vx*.85):(t.y=t.y<e.cy?e.cy-e.hh-6:e.cy+e.hh+6,t.vy=-t.vy*.85),l>.7&&(n.spark(t.x,t.y,Math.min(2.4,l),e.tint??Ko.wall.color),t.heat=Math.max(t.heat,Math.min(.85,l*.4)))},meta:{desc:"axis-aligned bouncing wall \u2014 sparks on impact"}},da={token:"sink",label:"Sink",apply(e,t,n){n.probe||t.cap||n.dist>=e.absorbR||(t.cap=e,e.accreted+=1,e.accreted>=e.capacity&&n.supernova(e))},meta:{desc:"captures matter, then releases it"}},ua=[oa,ca,la,fa,ia,ra,aa,sa,da];function zr(e){for(let t of ua)e.force(t)}var Zn=1.5,ha=8,ya=60;function pa(e,t,n,r){let s=Qe(e);if(Math.hypot(s[0].x-s[1].x,s[0].y-s[1].y)<Math.max(e.range*.06,ha)){let h=Math.max(e.range*.18,ya),b=e.spin<0?-1:1;s=[{x:e.cx+e.ux*h,y:e.cy+e.uy*h,q:b},{x:e.cx-e.ux*h,y:e.cy-e.uy*h,q:-b}]}let l=r*(1+Zn*(e.d??0)),d=er(s,t,n);return{x:d.x*l,y:d.y*l}}function ma(e,t,n,r){return nr(e.cx,e.cy,e.spin,r*(1+Zn*(e.d??0)),t,n)}function Ar(e,t,n,r){if(n.dist>=e.range)return;let s=2*n.G*e.M/(n.c*n.c),i=r/(n.dist*n.dist+s*s);t.vx+=n.dx/n.dist*i,t.vy+=n.dy/n.dist*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i),to(t,n.c)}function to(e,t){let n=e.vz??0,r=Math.hypot(e.vx,e.vy,n);r>t&&(e.vx=e.vx/r*t,e.vy=e.vy/r*t,n&&(e.vz=n/r*t))}function ga(e,t,n){let r=e.cx-t,s=e.cy-n,i=Math.max(Math.hypot(r,s),Je),l=e.M*(1+Zn*(e.d??0))/(i*i);return{x:r/i*l,y:s/i*l}}var xa={token:"gravity",label:"Gravity",apply(e,t,n){Ar(e,t,n,n.G*e.M)},field:(e,t,n)=>ga(e,t,n),meta:{desc:"true softened inverse-square gravity (a real 1/d\xB2 law)"}},va={token:"charge",label:"Charge",apply(e,t,n){let r=t.charge??0;r!==0&&Ar(e,t,n,-(e.spin*r*n.G*e.M))},field:(e,t,n)=>ma(e,t,n,e.M),meta:{desc:"signed inverse-square \u2014 like repels, opposite attracts"}},ba={token:"magnetism",label:"Magnetism",apply(e,t,n){if(n.dist>=e.range)return;let r=t.charge??0;if(r===0)return;let s=1-n.dist/e.range,i=r*e.spin*e.strength*s,l=Math.cos(i),d=Math.sin(i),h=t.vx;t.vx=h*l-t.vy*d,t.vy=h*d+t.vy*l},field:(e,t,n)=>pa(e,t,n,e.strength),meta:{desc:"Lorentz force \u2014 curves a moving charge perpendicular to its velocity"}};function wa(e){return Math.sqrt(2*Math.max(0,e))}var Ma={token:"thermal",label:"Thermal",apply(e,t,n){if(n.dist>=e.range)return;let r=1-n.dist/e.range,s=wa(e.strength*r);if(s===0)return;let i=(n.rng??Math.random)()||1e-9,l=s*Math.sqrt(-2*Math.log(i)),d=2*Math.PI*(n.rng??Math.random)();if(t.vx+=l*Math.cos(d),t.vy+=l*Math.sin(d),n.D){let h=(n.rng??Math.random)()||1e-9;t.vz=(t.vz??0)+s*Math.sqrt(-2*Math.log(h))*Math.cos(2*Math.PI*(n.rng??Math.random)())}e.on&&(t.heat=Math.max(t.heat,r*.4)),to(t,n.c)},meta:{desc:"Langevin/Brownian agitation \u2014 a real temperature in the medium"}},Sa={token:"collide",label:"Collide",apply(e,t,n){if(n.dist>=e.range)return;let r=Math.max(0,Math.min(1,e.strength)),s=Math.max(1,t.size);for(let i of n.neighbors(t,s*4)){let l=Math.max(1,i.size),d=t.x-i.x,h=t.y-i.y,b=(t.z??0)-(i.z??0),x=Math.hypot(d,h,b);if(x>=s+l||x<1e-6)continue;let E=d/x,z=h/x,F=b/x,T=(t.vx-i.vx)*E+(t.vy-i.vy)*z+((t.vz??0)-(i.vz??0))*F;if(T>=0)continue;let R=(1+r)*.5*T;t.vx-=R*E,t.vy-=R*z,i.vx+=R*E,i.vy+=R*z,b&&(t.vz=(t.vz??0)-R*F,i.vz=(i.vz??0)+R*F)}},meta:{desc:"elastic pairwise collision \u2014 the hard-sphere billiard force"}},ka={token:"diffuse",label:"Diffuse",apply(e,t,n){if(n.dist>=e.range)return;let r=n.grid("diffuse");r.deposit(t.x,t.y,e.strength);let s=r.gradient(t.x,t.y);t.vx+=s.x*e.strength,t.vy+=s.y*e.strength},meta:{desc:"pheromone field \u2014 deposit a mark and follow the diffused gradient"}},Ea=12,Qn=7,Fa={token:"propagate",label:"Propagate",source(e,t){e.on&&t.frameN%Ea===0&&t.grid("wave-propagate").deposit(e.cx,e.cy,e.strength)},apply(e,t,n){if(n.dist>=e.range)return;let s=n.grid("wave-propagate").gradient(t.x,t.y),i=Math.hypot(s.x,s.y);if(i<1e-6)return;let l=-n.dx/n.dist,d=-n.dy/n.dist;t.vx+=l*i*e.strength*Qn,t.vy+=d*i*e.strength*Qn,n.dz&&(t.vz=(t.vz??0)+-n.dz/n.dist*i*e.strength*Qn),to(t,n.c)},meta:{desc:"a travelling wave \u2014 a shock train expands from the source, sweeping matter out"}},za={token:"memory",label:"Memory",apply(e,t,n){if(n.dist>=e.range)return;let r=n.grid("memory");r.deposit(t.x,t.y,e.strength*.15);let s=1+.5*r.sample(t.x,t.y),i=(1-n.dist/e.range)**2*e.strength*.5*s;t.vx+=n.dx/n.dist*i,t.vy+=n.dy/n.dist*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i)},meta:{desc:"the field remembers \u2014 occupancy wears in paths that pull harder"}},Aa=[xa,va,ba,Ma,Sa,ka,Fa,za];function Tr(e){for(let t of Aa)e.force(t)}var Ta={token:"lens",label:"Lens",kinematic:!0,apply(e,t,n){if(n.dist>=e.range)return;let r=e.strength*(1-n.dist/e.range)*e.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"}},Ca={token:"gate",label:"Gate",kinematic:!0,apply(e,t,n){if(Math.abs(t.x-e.cx)>=e.hw+6||Math.abs(t.y-e.cy)>=e.hh+6)return;let s=t.vx*e.ux+t.vy*e.uy;s<0&&(t.vx-=2*s*e.ux,t.vy-=2*s*e.uy)},meta:{desc:"a one-way membrane \u2014 passes matter along its heading, reflects the reverse"}},Oa=1,Ra=1,Pa={token:"buoyancy",label:"Buoyancy",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let r=Oa/(t.size*(1+t.heat));t.vy-=(Ra-r)*e.strength},meta:{desc:"a constant lift/sink by density difference \u2014 light matter rises, dense settles"}},$a={token:"shear",label:"Shear",apply(e,t,n){if(n.dist>=e.range)return;let r=(t.x-e.cx)*-e.uy+(t.y-e.cy)*e.ux,s=e.strength*(r/e.range)*(1-n.dist/e.range);t.vx+=e.ux*s,t.vy+=e.uy*s},meta:{desc:"a laminar shear gradient \u2014 flow speed grows with perpendicular offset"}},on=32,Ia=.5,Na={token:"crystallize",label:"Crystallize",apply(e,t,n){if(n.dist>=e.range||t.heat>=Ia)return;let r=e.cx+Math.round((t.x-e.cx)/on)*on,s=e.cy+Math.round((t.y-e.cy)/on)*on;t.vx+=(r-t.x)*e.strength,t.vy+=(s-t.y)*e.strength,t.vx*=.9,t.vy*=.9},meta:{desc:"snaps cool matter onto a lattice; melts and frees it when hot"}},Da={token:"align",label:"Align",apply(e,t,n){if(n.dist>=e.range)return;let r=t.vz??0,s=Math.hypot(t.vx,t.vy,r),i=e.strength,l=e.ux,d=e.uy,h=0,b=0,x=0,E=0;for(let F of n.neighbors(t,e.range)){let T=F.vz??0,R=Math.hypot(F.vx,F.vy,T);R>1e-6&&(b+=F.vx/R,x+=F.vy/R,E+=T/R)}let z=Math.hypot(b,x,E);z>1e-6&&(l=b/z,d=x/z,h=E/z),t.vx+=(l*s-t.vx)*i,t.vy+=(d*s-t.vy)*i,(h||r)&&(t.vz=r+(h*s-r)*i)},meta:{desc:"steers toward the neighbour-mean heading (or the body heading when alone)"}};function _a(e,t,n,r){let s=e*r+n*.2,i=t*r-n*.2;return{x:-r*Math.sin(s)*Math.sin(i),y:-r*Math.cos(s)*Math.cos(i)}}var La=.01,Ba={token:"wind",label:"Wind",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let r=_a(t.x,t.y,n.t,La);t.vx+=r.x*e.strength,t.vy+=r.y*e.strength},meta:{desc:"divergence-free curl-noise turbulence"}},Wa=.5,qa={token:"cohesion",label:"Cohesion",apply(e,t,n){if(n.dist>=e.range)return;let r=e.range,s=r*Wa,i=e.strength;for(let l of n.neighbors(t,r)){let d=l.x-t.x,h=l.y-t.y,b=(l.z??0)-(t.z??0),x=Math.hypot(d,h,b);if(x<1e-6)continue;let E=d/x,z=h/x,F=b/x;if(x<s){let T=i*(s-x)/s;t.vx-=T*E,t.vy-=T*z,b&&(t.vz=(t.vz??0)-T*F)}else{let T=i*(x-s)/(r-s);t.vx+=T*E,t.vy+=T*z,b&&(t.vz=(t.vz??0)+T*F)}}},meta:{desc:"short-range pressure + mid-range cohesion \u2014 surface tension over neighbours"}},Ha=.5,ja={token:"pressure",label:"Pressure",apply(e,t,n){if(n.dist>=e.range)return;let r=e.range,s=e.strength,i=0,l=n.neighbors(t,r);for(let h of l){let b=Math.hypot(h.x-t.x,h.y-t.y,(h.z??0)-(t.z??0));b<r&&(i+=(1-b/r)**2)}let d=i-Ha;if(!(d<=0))for(let h of l){let b=t.x-h.x,x=t.y-h.y,E=(t.z??0)-(h.z??0),z=Math.hypot(b,x,E);if(z<1e-6||z>=r)continue;let F=s*d*(1-z/r)/z;t.vx+=F*b,t.vy+=F*x,E&&(t.vz=(t.vz??0)+F*E)}},meta:{desc:"SPH density relaxation \u2014 incompressible even-fill via mutual repulsion"}},Ua={token:"hunt",label:"Hunt",apply(e,t,n){if(n.dist>=e.range)return;let r=t.species??0,s=null,i=1/0;for(let E of n.neighbors(t,e.range)){if((E.species??0)===r)continue;let z=E.x-t.x,F=E.y-t.y,T=(E.z??0)-(t.z??0),R=z*z+F*F+T*T;R<i&&(i=R,s=E)}if(!s)return;let l=s.x-t.x,d=s.y-t.y,h=(s.z??0)-(t.z??0),b=Math.hypot(l,d,h)||1,x=r===0?1:-1;t.vx+=l/b*e.strength*x,t.vy+=d/b*e.strength*x,h&&(t.vz=(t.vz??0)+h/b*e.strength*x)},meta:{desc:"two-species pursuit \u2014 predators seek prey, prey flee predators"}},Ya=.35,Ga={token:"link",label:"Link",apply(e,t,n){if(n.dist>=e.range)return;let r=e.range,s=r*Ya,i=e.strength;for(let l of n.neighbors(t,r)){let d=l.x-t.x,h=l.y-t.y,b=(l.z??0)-(t.z??0),x=Math.hypot(d,h,b);if(x<1e-6)continue;let E=x-s,z=.5*i*(E/s);t.vx+=z*(d/x),t.vy+=z*(h/x),b&&(t.vz=(t.vz??0)+z*(b/x))}},meta:{desc:"a Verlet distance constraint \u2014 holds a rest length, so matter ropes and drapes"}},Cr=40,Va={token:"morph",label:"Morph",apply(e,t,n){let r=e.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,h=Math.hypot(l,d),b=e.strength;t.vx+=l*b*.02,t.vy+=d*b*.02,t.z&&(t.vz=(t.vz??0)-t.z*b*.02);let E=(1-(h<Cr?1-h/Cr:0))*b*.3;E>0&&(t.vx+=((n.rng??Math.random)()-.5)*E,t.vy+=((n.rng??Math.random)()-.5)*E)},meta:{desc:"matter assembles into a mark/chart/logo \u2014 never words (\xA711)"}},Xa=90,Ka={token:"spawn",label:"Spawn",apply(){},source(e,t){let n=e.life??Xa,r=Math.max(1,Math.round(e.strength*2));e.cap!=null&&e.cap>0&&n>0&&(r=Math.min(r,e.cap/n)),e.emitAcc=(e.emitAcc??0)+r;let s=Math.floor(e.emitAcc);for(e.emitAcc-=s;s>0;s--){let i=((t.rng??Math.random)()-.5)*.6,l=Math.cos(i),d=Math.sin(i),h=e.ux*l-e.uy*d,b=e.ux*d+e.uy*l,x=2+(t.rng??Math.random)()*2;t.spawn({x:e.cx,y:e.cy,vx:h*x,vy:b*x,age:n,heat:.6,...e.species!=null?{species:e.species}:{}})}},meta:{desc:"a source \u2014 emits matter along the heading, budgeted by a lifespan"}},Ja=3,Qa={token:"resonate",label:"Resonate",apply(){},modify(e,t,n){return{strength:1+Math.sin(n.t*Ja*e.spin)}},meta:{desc:"pulses sibling forces with a time-varying strength S(t)=S\u2080(1+sin \u03C9t)"}},Za=.5,tc={token:"spotlight",label:"Spotlight",apply(){},modify(e,t,n){let r=-n.dx/n.dist,s=-n.dy/n.dist;return{gate:r*e.ux+s*e.uy<Za}},meta:{desc:"gates sibling forces to an angular cone of the heading"}},ec={token:"screen",label:"Screen",apply(){},meta:{desc:"a quiet zone \u2014 attenuates other bodies' forces on matter inside its radius"}},nc={token:"pigment",label:"Pigment",apply(e,t,n){let r=e.tint;!r||n.dist>=e.range*.6||(t.color=t.color?Zo(t.color,r,.08):r)},meta:{desc:"conserved color transport \u2014 matter takes on and carries a tint"}},oc=.5,Or=.12,rc={token:"fieldflow",label:"Field Flow",apply(e,t,n){if(e.range>0&&n.dist>=e.range||e.chargeGated&&(t.charge??0)===0)return;let r=n.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=e.range>0?1-n.dist/e.range:1,h=e.strength*d,b=t.vz??0,x=Math.hypot(t.vx,t.vy,b);if(x>1e-6){let F=Math.min(1,h*oc);t.vx+=(i*x-t.vx)*F,t.vy+=(l*x-t.vy)*F,b&&(t.vz=b+(0-b)*F)}t.vx+=i*h*Or,t.vy+=l*h*Or;let E=t.vz??0,z=t.vx*t.vx+t.vy*t.vy+E*E;if(z>n.c*n.c){let F=n.c/Math.sqrt(z);t.vx*=F,t.vy*=F,E&&(t.vz=E*F)}e.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"}},Rr=1e-9,sc={token:"relief",label:"Relief",apply(e,t,n){let r=n.potential?.(e.potential??"height");if(!r||e.range>0&&n.dist>=e.range)return;let s=r.gradient(t.x,t.y);if(!Number.isFinite(s.x)||!Number.isFinite(s.y)||Math.abs(s.x)<Rr&&Math.abs(s.y)<Rr)return;let i=e.range>0?1-n.dist/e.range:1,l=e.spin<0?1:-1,d=e.strength*i*n.G*l;t.vx+=s.x*d,t.vy+=s.y*d;let h=t.vz??0,b=t.vx*t.vx+t.vy*t.vy+h*h;if(b>n.c*n.c){let x=n.c/Math.sqrt(b);t.vx*=x,t.vy*=x,h&&(t.vz=h*x)}},meta:{desc:"transport down a host-declared potential \u2014 downhill flow over terrain height"}},ic={token:"warp",label:"Warp",kinematic:!0,apply(e,t,n){if(!e.warpHas||t.cap)return;let r=e.absorbR;if(n.dist>=r)return;let s=Math.cos(e.twist??0),i=Math.sin(e.twist??0),l=e.warpScale??1,d=-n.dx/n.dist,h=-n.dy/n.dist,b=d*s-h*i,x=d*i+h*s,E=r*l+6;t.x=e.warpX+b*E,t.y=e.warpY+x*E,t.z&&(t.z=-n.dz/n.dist*E);let z=t.vx,F=t.vy;t.vx=z*s-F*i,t.vy=z*i+F*s,t.heat=Math.max(t.heat,.6)},meta:{desc:"a wormhole throat \u2014 relocates matter to its paired body, conserved"}},ac=[Ta,Ca,Pa,$a,Na,Da,Ba,qa,ja,Ga,Ua,Va,Ka,Qa,tc,ec,nc,rc,ic,sc];function Pr(e){for(let t of ac)e.force(t)}var $r=new Set(["css","canvas","svg","typography","spatial","native"]);function Ir(e){let t=[];for(let n of e)n.surfaces.some(s=>$r.has(s))&&!n.reducedMotionEquivalent&&t.push({rule:"field/reduced-motion-equivalent-required",severity:"error",subject:n.id,message:`Projection "${n.id}" can express motion (${n.surfaces.filter(s=>$r.has(s)).join(", ")}) but declares no reducedMotionEquivalent. Reduced motion must translate the behavior, not remove it.`}),n.accessibilityEquivalent||t.push({rule:"field/accessibility-equivalent-required",severity:"warning",subject:n.id,message:`Projection "${n.id}" declares no accessibilityEquivalent. Accessibility is an alternate projection of the same field state, not a fallback.`});return t}var eo=(e,t)=>t?Object.fromEntries(Object.entries(e).filter(([n])=>t.has(n))):e;function Nr(e,t){let n=t.metrics?new Set(t.metrics):null,r=t.channels?new Set(t.channels):null,s=t.tokens?new Set(t.tokens):null;return{...e,metrics:eo(e.metrics,n),bodies:e.bodies.filter(i=>!s||i.tokens.some(l=>s.has(l))).map(i=>({...i,metrics:eo(i.metrics,n),dimensions:eo(i.dimensions,n)})),influences:r?e.influences.filter(i=>r.has(i.channel??"linear")):e.influences,lens:t.id}}function Dr(e,t,n={}){return{x:e,y:t,strength:n.strength??1,radius:n.radius&&n.radius>0?n.radius:360}}function ze(e,t,n,r,s=.6){let i=r.x-t,l=r.y-n,d=Math.hypot(i,l);if(d===0||d>=r.radius)return e.x=0,e.y=0,e;let h=(1-d/r.radius)*r.strength*s;return e.x=i/d*h,e.y=l/d*h,e}var cc={step:6,maxSteps:400,minStrength:1e-9,loopDist:6,maxTurns:1/0};function _r(e,t,n,r,s){let i=[{x:t,y:n}],l=t,d=n,h=s.step,b=s.maxTurns*2*Math.PI,x=0,E=0,z=0;for(let F=0;F<s.maxSteps;F++){let T=e(l,d),R=Math.hypot(T.x,T.y);if(!(R>=s.minStrength))break;let _=T.x/R*r,I=T.y/R*r;if(Number.isFinite(b)){if(x!==0||E!==0){let V=Math.max(-1,Math.min(1,_*x+I*E));if(z+=Math.acos(V),z>b)break}x=_,E=I}if(l+=_*s.step,d+=I*s.step,s.bounds&&(l<-h||d<-h||l>s.bounds.w+h||d>s.bounds.h+h))break;if(F>4&&Math.hypot(l-t,d-n)<s.loopDist){i.push({x:l,y:d});break}i.push({x:l,y:d})}return i}function lc(e,t,n,r={}){let s={...cc,bounds:r.bounds,...r},i=_r(e,t,n,-1,s),l=_r(e,t,n,1,s);return i.reverse(),i.pop(),i.concat(l)}function Lr(e,t,n={}){return t.map(r=>lc(e,r.x,r.y,n)).filter(r=>r.length>1)}var fc=8,dc=60;function Br(e,t=8){let n={cx:e.cx,cy:e.cy,hw:e.hw,hh:e.hh,ux:e.ux,uy:e.uy,spin:e.spin},r=Qe(n),s=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y);if(s<Math.max(e.range*.06,fc)){let b=Math.max(e.range*.18,dc),x=e.spin<0?-1:1;r=[{x:e.cx+e.ux*b,y:e.cy+e.uy*b,q:x},{x:e.cx-e.ux*b,y:e.cy-e.uy*b,q:-x}],s=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y)}let i=-e.uy,l=e.ux,d=Math.max(s*.13,18),h=[{x:e.cx,y:e.cy}];for(let b=1;b<=t;b++){let x=b*d;h.push({x:e.cx+i*x,y:e.cy+l*x}),h.push({x:e.cx-i*x,y:e.cy-l*x})}return h}function Wr(e,t=18){let n=Math.max(Math.min(e.hw,e.hh)*.8,24),r=[];for(let s=0;s<t;s++){let i=s/t*Math.PI*2;r.push({x:e.cx+Math.cos(i)*n,y:e.cy+Math.sin(i)*n})}return r}function qr(e,t=8){let n=[];for(let r of e)!r.vis||r.tokens.length===0||(r.tokens.includes("magnetism")?n.push(...Br(r,t)):(r.tokens.includes("charge")||r.tokens.includes("gravity"))&&n.push(...Wr(r)));return n}function Hr(e,t=Math.random){return 3+Math.floor(t()*(e>0?e:1)*3)}var jr=160;function Ur(e,t,n,r=6,s=0){let i=Math.hypot(e,t,s)||1;if(i>=n)return{vx:0,vy:0,vz:0,heat:0};let l=1-i/n,d=l*r;return{vx:e/i*d,vy:t/i*d,vz:s/i*d,heat:l*.9}}function Yr(e,t,n,r,s=.9,i=80){let l=r>0?r:1;e.vx=(e.vx+t/l)*s,e.vy=(e.vy+n/l)*s,e.x+=e.vx,e.y+=e.vy;let d=Math.hypot(e.x,e.y);d>i&&(e.x=e.x/d*i,e.y=e.y/d*i)}function Gr(e,t=.02){return{x:-e.x*t,y:-e.y*t}}function Vr(e){let t=e/3e4;return t<.6?.6:t>6?6:t}function Xr(e,t,n=-1,r=1600,s=26){let i=0,l=0,d=s*s;for(let h=0;h<t.length;h++){if(h===n)continue;let b=t[h],x=e.x-b.x,E=e.y-b.y,z=x*x+E*E+d;i+=r*x/z,l+=r*E/z}return{x:i,y:l}}function Kr(e,t,n,r=16,s=1){let i=(e(t+r,n)-e(t-r,n))/(2*r),l=(e(t,n+r)-e(t,n-r))/(2*r);return{x:-i*s,y:-l*s}}function Jr(e,t,n,r,s,i,l,d){if(r.length===0)return;let h=e.particles;for(let b=h.length-1;b>=0&&!(t.length>=n);b--){let x=h[b];if(!x||x.cap||x.heat>=.12)continue;let E=-1,z=1e9,F=0;for(let R=0;R<r.length;R++){let _=Ct(r[R],x.x,l,i),I=Math.abs(_-x.y);I<z&&(z=I,E=R,F=_)}if(E<0||z>=64)continue;let T=Math.min(.012,z*4e-4)*(1-x.heat/.12);x.vy+=F>x.y?T:-T,z<20&&x.vx*x.vx+x.vy*x.vy<.3&&d()<.03&&(t.push({wi:E,progress:x.x/s,phase:(d()-.5)*.22*Math.PI,size:x.size,glow:d()<.3,speed:(35e-5+d()*9e-4)*(d()<.5?1:-1)}),e.remove(x))}}function no(e,t,n,r,s,i,l,d,h){for(let b=e.length-1;b>=0;b--){let x=e[b];if(!x)continue;let E=t[x.wi];if(!E)continue;let z=x.progress*i,F=Ct(E,z,d,l)+x.phase*32,T=z-n,R=F-r,_=Math.hypot(T,R);if(_<s&&_>.5){let I=(1-_/s)*4;h({x:z,y:F,vx:T/_*I,vy:R/_*I,size:x.size,heat:.9});let V=e.pop();V&&b<e.length&&(e[b]=V)}}}function Qr(e,t,n,r,s,i,l,d){let h=b=>b.tokens.some(x=>{let E=r[x];return!!E&&!E.modify&&!E.source});for(let b=e.length-1;b>=0;b--){let x=e[b];if(!x)continue;let E=t[x.wi];if(!E)continue;let z=x.progress*s,F=Ct(E,z,l,i)+x.phase*32,T=!1,R=0,_=0;for(let I of n){if(!I.vis||I.when==="active"&&!I.on||I.when&&I.when!=="active")continue;let V=I.tokens,ot=I.cx-z,ft=I.cy-F,it=Math.hypot(ot,ft)||1,vt=I.range*(I.on?1.4:1);if(V.indexOf("wall")>=0&&Math.abs(z-I.cx)<I.hw+6&&Math.abs(F-I.cy)<I.hh+6&&(R=(z<I.cx?-1:1)*1.6,_=(F<I.cy?-1:1)*.8,T=!0),!T&&(V.indexOf("attract")>=0||V.indexOf("sink")>=0||V.indexOf("jet")>=0)&&it<vt*.8){let bt=1.2+(I.on?1.6:0);R=ot/it*bt,_=ft/it*bt,T=!0}if(!T&&V.indexOf("repel")>=0&&it<vt*.8){let bt=1.2+(I.on?1.2:0);R=-(ot/it)*bt,_=-(ft/it)*bt,T=!0}if(!T&&V.indexOf("swirl")>=0&&it<vt*.75&&(R=ft/it*1.2,_=-(ot/it)*1.2,T=!0),!T&&V.indexOf("stream")>=0&&it<vt*.75&&(R=I.ux*1.3,_=I.uy*1.3,T=!0),!T&&it<vt*.8&&h(I)){let bt=.8+(I.on?.8:0);R=ot/it*bt,_=ft/it*bt,T=!0}if(T)break}if(T){d({x:z,y:F,vx:R,vy:_,size:x.size,heat:.5});let I=e.pop();I&&b<e.length&&(e[b]=I)}}}function Zr(e,t){for(let n of e){if(!n.vis||n.tokens.indexOf("charge")<0&&n.tokens.indexOf("magnetism")<0||n.range<=0)continue;let r=n.range*n.range;for(let s of t){if(s.charge)continue;let i=n.cx-s.x,l=n.cy-s.y;i*i+l*l>=r||(s.charge=i>=0?1:-1)}}}function Ae(e,t,n){if(!Number.isFinite(e)||!Number.isFinite(t))return 0;let r=t-e;return r<=0?1:!Number.isFinite(n)||n<=0?0:Math.pow(2,-r/n)}var ts=e=>e<0?0:e>1?1:e;function es(e){if(!e||e.n===0)return{entropy:0,coherence:1,temperature:0};let t=e.sh/e.n,n=e.ss/e.n,r=e.ss2/e.n,s=ts(.5*t+.5*Math.min(1,r/9)),i=e.ss>1e-9?Math.hypot(e.sx,e.sy)/e.ss:1,l=ts((1-i)*Math.min(1,n/1.5));return{entropy:l,coherence:1-l,temperature:s}}var rn=class{constructor(){Y(this,"pending",new Map);Y(this,"ids",new WeakMap);Y(this,"seq",0)}idOf(t){let n=this.ids.get(t);return n===void 0&&this.ids.set(t,n=++this.seq),n}keyOf(t,n){if(t==="focus"){let s=n;return`focus:${s.target}:${s.source}`}if(t==="met"){let s=n,[i,l]=[this.idOf(s.a.el??s.a),this.idOf(s.b.el??s.b)].sort((d,h)=>d-h);return`${i}:${l}`}if(t==="enter"||t==="exit"){let s=n;return`${this.idOf(s.body.el??s.body)}:${this.idOf(s.other.el??s.other)}`}let r=n;return String(this.idOf(r.body.el??r.body))}record(t,n){let r=this.pending.get(t);r||this.pending.set(t,r=new Map),r.set(this.keyOf(t,n),n)}flush(t){if(this.pending.size!==0){for(let[n,r]of this.pending)for(let s of r.values())t(n,s);this.pending.clear()}}};function oo(e){return e.split(",").map(t=>t.trim()).filter(Boolean).map(t=>{let n=t.indexOf(":");return{trigger:t.slice(0,n).trim(),event:t.slice(n+1).trim(),armed:!1}}).filter(t=>t.trigger&&t.event)}function ro(e,t){switch(e){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 ns={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}],wormhole:[{body:"attract",strength:.9,range:300},{body:"warp",absorb:40,pair:"@pair",twist:0,scale:1},{body:"repel",strength:6,range:200,when:"hot"}],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 uc(){return globalThis.process?.env?.NODE_ENV!=="production"}var rs=uc();function ss(){return rs}var os=new Set;function so(e,t){if(!rs)return;let n=`${e}:${t}`;os.has(n)||(os.add(n),console.warn(`[Fundamental:${e}] ${t}`))}var hc={"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 is(e,t={}){let n=hc[e];if(!n)return null;let r=[...n.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)),n.range!=null&&(s["data-range"]=String(n.range)),n.feedback&&(s["data-feedback"]=""),n.render?.length&&(s["data-render"]=n.render.join(" ")),{body:r.join(" "),strength:t.intensity,range:n.range,feedback:n.feedback??!1,render:n.render??["particles"],attributes:s}}function cs(e){let t=(R,_)=>{let I=Number.parseFloat(e.get(R)??"");return Number.isFinite(I)?I:_},n=t("strength",.5),r=t("angle",0)*Math.PI/180,s=e.get("spin"),i=s==null?1:Number.isFinite(Number.parseFloat(s))?Number.parseFloat(s):0,l=(e.get("body")??"").split(/\s+/).filter(Boolean),d=Xe(l),h=e.get("life"),b=e.get("cap"),x=Number.parseFloat(h??""),E=Number.parseFloat(b??""),z=h!=null||b!=null||e.has("budget")||e.has("sink"),F=e.get("authority");return{tokens:l,authority:F==="kinematic"||F==="dynamic"?F:"anchored",classified:d,...Number.isFinite(x)&&x>0?{life:x}:{},...Number.isFinite(E)&&E>0?{cap:E}:{},budgeted:z,strength:n,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:e.get("when")??"",feedback:e.has("feedback"),shaped:e.has("shaped"),chargeGated:e.has("charge-gated"),...e.get("potential")?{potential:e.get("potential")}:{},...e.get("species")!=null&&Number.isFinite(Number.parseFloat(e.get("species")))?{species:Number.parseFloat(e.get("species"))}:{},...(()=>{let R=e.get("affects");if(R==null)return{};let _=R.split(",").map(I=>Number.parseFloat(I.trim())).filter(I=>Number.isFinite(I));return _.length?{affects:new Set(_)}:{}})(),fmin:t("fmin",0),fmax:t("fmax",0),opsz:e.get("opsz")??"",pair:e.get("pair")||void 0,twist:t("twist",0)*Math.PI/180,warpScale:t("scale",1),screenMin:t("screen-min",0),M:n}}function yc(e,t){let n={body:e.body};if(e.strength!=null&&(n.strength=String(e.strength)),e.range!=null&&(n.range=String(e.range)),e.spin!=null&&(n.spin=String(e.spin)),e.angle!=null&&(n.angle=String(e.angle)),e.absorb!=null&&(n.absorb=String(e.absorb)),e.max!=null&&(n.max=String(e.max)),e.life!=null&&(n.life=String(e.life)),e.cap!=null&&(n.cap=String(e.cap)),e.twist!=null&&(n.twist=String(e.twist)),e.scale!=null&&(n.scale=String(e.scale)),e.when!=null&&(n.when=e.when),e.pair!=null){let r=e.pair==="@pair"?t?.get("pair")??null:e.pair;r&&(n.pair=r)}return{get:r=>n[r]??null,has:r=>r in n}}function pc(e,t){let n=ns[e];return n?n.map(r=>cs(yc(r,t))):[]}function mc(e){let t=(e.tagName??"element").toLowerCase(),n=e.id?`#${e.id}`:"",r=typeof e.className=="string"&&e.className?`.${e.className.split(/\s+/)[0]}`:"";return`<${t}${n}${r}>`}function gc(e,t="<body>"){!e.classified||e.classified.sources.length===0||e.budgeted||(e.life=qn,e.cap=Hn,ss()&&console.warn(`[Fundamental:UNBUDGETED_SOURCE] ${t} runs the source force "${e.classified.sources.join(" ")}" with none of data-life / data-cap / data-budget / data-sink. Applying the safe default budget (data-life="${qn}", data-cap="${Hn}") \u2014 declare one to make the source's budget explicit (workover v0.3 source rules).`))}function ls(e,t){return gc(t,mc(e)),{el:e,...t,tint:e.dataset.color,cx:0,cy:0,hw:0,hh:0,on:!1,vis:!0,accreted:0,count:0,d:0,attn:1}}function fs(e){return{get:t=>e.getAttribute("data-"+t),has:t=>e.hasAttribute("data-"+t)}}function Te(e,t){return ls(e,cs(t??fs(e)))}var as={source:"jet",sink:"sink",anchor:"tether",boundary:"wall",sensor:"",display:""};function xc(e){let t=null,n=e.getAttribute("data-intent");if(n){let s=e.getAttribute("data-intensity"),i=is(n,{intensity:s!=null?Number(s):void 0,risk:e.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=e.getAttribute("data-field-role");s!=null&&s in as&&(t={body:as[s],feedback:""})}if(!t)return null;let r=t;return{get:s=>e.getAttribute("data-"+s)??r[s]??null,has:s=>e.hasAttribute("data-"+s)||s in r}}var ve="data-field-boundary",ao=`[${ve}]`;function io(e,t){if(typeof e.closest!="function")return!0;let n=e.closest(ao);return n===null||n===t}function ds(e){let t=[];return e.querySelectorAll("[data-body]").forEach(n=>{io(n,e)&&t.push(Te(n))}),e.querySelectorAll("[data-preset]").forEach(n=>{if(!io(n,e))return;let r=n,s=fs(r);for(let i of pc(r.dataset.preset??"",s))t.push(ls(r,i))}),e.querySelectorAll("[data-intent]:not([data-body]), [data-field-role]:not([data-body]):not([data-intent])").forEach(n=>{if(!io(n,e))return;let r=xc(n);r&&t.push(Te(n,r))}),t}function vc(e){let t=e.el;if(typeof t.getAttribute!="function")return;let n=t.getAttribute("data-strength");if(n!=null){let l=Number.parseFloat(n);Number.isFinite(l)&&(e.strength=l,e.M=l)}let r=t.getAttribute("data-range");if(r!=null){let l=Number.parseFloat(r);Number.isFinite(l)&&(e.range=l)}let s=t.getAttribute("data-spin");if(s!=null){let l=Number.parseFloat(s);Number.isFinite(l)&&(e.spin=l)}let i=t.getAttribute("data-angle");if(i!=null){let l=Number.parseFloat(i);Number.isFinite(l)&&(e.angle=l*Math.PI/180,e.ux=Math.cos(e.angle),e.uy=Math.sin(e.angle))}}function sn(e,t,n,r=0,s=0){let i=n*.15;for(let l of e){let d=l.rect?l.rect():l.el.getBoundingClientRect(),h=d.left-r,b=d.top-s;l.cx=h+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<n+i&&h+d.width>-i&&h<t+i,vc(l)}}var us="field:register-body",hs="field:unregister-body",ys="field:update-body";function bc(e){let t=e;for(;t;){if(typeof t.closest!="function")return null;let n=t.closest(ao);if(n)return n;let r=typeof t.getRootNode=="function"?t.getRootNode():null,s=r?r.host??null:null;t=s&&s!==t?s:null}return null}function wc(e){let t=e.nodeType;if(t===9)return!0;if(t===1){let n=e.ownerDocument;return!!n&&n.documentElement===e}return!1}function Mc(e){let t=e;return typeof t.hasAttribute=="function"&&t.hasAttribute(ve)}function Sc(e,t){let{field:n,scope:r,element:s}=e;if(n!=null&&n!==""){if(n==="root")return wc(t);if(typeof n=="string"){let i=t;return typeof i.matches=="function"&&i.matches(n)}return n===t}if(r==="nearest"){if(typeof s.closest!="function")return!0;let i=bc(s);return i===null?!Mc(t):i===t}return!0}var an=class{constructor(){Y(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,n){let r=[];for(let[s,i]of this.hosts){if(!s.isConnected){this.hosts.delete(s);continue}if(n!==void 0&&!Sc(i,n))continue;let l=i.attrs?kc(i.attrs,s):void 0,d=t(s,l);i.getRect&&(d.rect=i.getRect),i.writeTarget&&(d.writeTarget=i.writeTarget),r.push(d)}return r}};function kc(e,t){return{get:n=>e[n]??t.getAttribute("data-"+n),has:n=>n in e||t.hasAttribute("data-"+n)}}function gs(e,t,n=.12){return e>=t?0:(1-e/t)*n}function cn(e,t,n){if(e===t)return .5;let r=(n-e)/(t-e);return r<0?0:r>1?1:r}var ps=Object.freeze([]);function co(e,t,n,r,s){let i={x:cn(e,t,s),y:0},l={x:1,y:cn(t,n,s)},d={x:cn(r,n,s),y:1},h={x:0,y:cn(e,r,s)},b=(E,z)=>({x1:E.x,y1:E.y,x2:z.x,y2:z.y});switch((e>s?8:0)|(t>s?4:0)|(n>s?2:0)|(r>s?1:0)){case 0:case 15:return ps;case 1:case 14:return[b(h,d)];case 2:case 13:return[b(d,l)];case 3:case 12:return[b(h,l)];case 4:case 11:return[b(i,l)];case 6:case 9:return[b(i,d)];case 7:case 8:return[b(h,i)];case 5:return[b(h,i),b(d,l)];case 10:return[b(h,d),b(i,l)];default:return ps}}function lo(e,t,n,r,s,i,l,d=1){if(l<=0)return;let h=Math.max(0,Math.floor((s-l)/r)),b=Math.min(t-1,Math.ceil((s+l)/r)),x=Math.max(0,Math.floor((i-l)/r)),E=Math.min(n-1,Math.ceil((i+l)/r)),z=l*l;for(let F=x;F<=E;F++)for(let T=h;T<=b;T++){let R=T*r-s,_=F*r-i,I=R*R+_*_;if(I>=z)continue;let V=1-Math.sqrt(I)/l,ot=F*t+T;e[ot]=e[ot]+d*V*V}}function xs(e,t,n){let r=-1,s=1/0;for(let i=0;i<n.length;i++){let l=n[i],d=l.x-e,h=l.y-t,b=d*d+h*h;b<s&&(s=b,r=i)}return r}function vs(e,t,n=1){let r=(e*2.6+t*2.5)*n;return r<2?2:r}function bs(e,t,n,r,s,i){let l=e-s,d=t-i,h=Math.hypot(l,d);return h<1e-6?0:(l*n+d*r)/h}function ws(e,t){if(t<=0)return 0;let n=e/(.35*t);return n<-1?-1:n>1?1:n}function Ms(e,t){return t<=0||e>=t?0:1-Math.sqrt(e/t)}function Ss(e,t){let n=e+t*.6;return n<-1?-1:n>1?1:n}var Ec=[96,160,255],ms=[226,230,240],Fc=[255,72,48];function ks(e,t){let n=t<-1?-1:t>1?1:t,r=n<0?Ec:ms,s=n<0?ms:Fc,i=n<0?n+1:n;return e[0]=r[0]+(s[0]-r[0])*i,e[1]=r[1]+(s[1]-r[1])*i,e[2]=r[2]+(s[2]-r[2])*i,e}function Es(e,t,n,r){let s=.3*r,i=s>0?(e*e+t*t)/(s*s):0,l=.55*n+.55*(i>1?1:i);return l<0?0:l>1?1:l}var ln=[[12,2,0],[130,24,2],[235,100,10],[255,180,90],[255,236,200],[201,218,255]];function Fs(e,t){let r=(t<0?0:t>1?1:t)*(ln.length-1),s=Math.min(Math.floor(r),ln.length-2),i=r-s,l=ln[s],d=ln[s+1];return e[0]=l[0]+(d[0]-l[0])*i,e[1]=l[1]+(d[1]-l[1])*i,e[2]=l[2]+(d[2]-l[2])*i,e}function zs(e,t){let n=e<0?-e:e;return t/(t+n)}function fo(e,t,n){return t+(e-t)*n}function As(e){return 1-.55*(e<0?0:e>1?1:e)}function Ts(e){return 4.5*(e<0?0:e>1?1:e)}function Cs(e,t,n){let r=[];for(let s=0;s<n;s++)for(let i=0;i<t;i++){let l=e[s*t+i];i+1<t&&e[s*t+i+1]!==l&&r.push({x1:i+.5,y1:s-.5,x2:i+.5,y2:s+.5}),s+1<n&&e[(s+1)*t+i]!==l&&r.push({x1:i-.5,y1:s+.5,x2:i+.5,y2:s+.5})}return r}var Os=24,zc=.12,Ac=.22,Ce=class{constructor(t,n){Y(this,"grid");Y(this,"peak",.001);Y(this,"cell",Os);this.grid=new ae(Math.max(1,t),Math.max(1,n),"diffuse",Os)}resize(t,n){this.grid.resize(t,n)}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(Ac,zc);let n=this.grid.max(),r=n>this.peak?.25:.03;this.peak+=(Math.max(n,.001)-this.peak)*r}norm(t,n){return pt(this.grid.sample(t,n)/this.peak,0,1)}gradient(t,n){if(this.peak<=0)return{x:0,y:0};let r=this.grid.gradient(t,n);return{x:r.x/this.peak,y:r.y/this.peak}}};var Tc={position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"0",pointerEvents:"none",display:"block"},Rs=Object.entries(Tc).map(([e,t])=>`${e.replace(/[A-Z]/g,n=>"-"+n.toLowerCase())}:${t}`).join(";");function Cc(e){let t=e.width,n=e.height,r=null,s=0;return{root:{querySelectorAll:()=>[],querySelector:()=>null,contains:()=>!1},viewport:()=>({width:t,height:n,dpr:1}),scrollY:()=>0,scrollHeight:()=>n,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,n=d}}}var Ps="10px ui-monospace, SFMono-Regular, Menlo, monospace";function uo(e,t){let n=0,r=0;return{size(s,i,l){n=s,r=i,e.width=Math.floor(s*l),e.height=Math.floor(i*l),t.setTransform(l,0,0,l,0,0)},clear(){t.clearRect(0,0,n,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,h,b,x,E){t.fillStyle=`rgba(${h},${b},${x},${E})`,t.fillRect(s,i,l,d)},text(s,i,l,d,h,b,x){t.font=Ps,t.textBaseline="middle",t.fillStyle=`rgba(${d},${h},${b},${x})`,t.fillText(s,i,l)},measureText(s){return t.font=Ps,t.measureText(s).width}}}var ho=(e,t)=>{if(t.density!==void 0){let n=t.density.toFixed(3);e.style.setProperty("--d",n),e.style.setProperty("--field-density",n)}if(t.heatmapDensity!==void 0){let n=t.heatmapDensity.toFixed(3);e.style.setProperty("--field-heatmap-density",n)}if(t.load!==void 0){let n=t.load.toFixed(3);e.style.setProperty("--load",n)}if(t.entropy!==void 0&&e.style.setProperty("--entropy",t.entropy.toFixed(3)),t.coherence!==void 0&&e.style.setProperty("--coherence",t.coherence.toFixed(3)),t.temperature!==void 0&&e.style.setProperty("--temperature",t.temperature.toFixed(3)),t.lit!==void 0){let n=t.lit;e.style.setProperty("--lit",n.toFixed(3));let r=e.dataset.fxLit==="1";n>.5&&!r?(e.dataset.fxLit="1",e.dispatchEvent(new CustomEvent("field:lit",{detail:{value:n}}))):n<.4&&r&&(e.dataset.fxLit="0",e.dispatchEvent(new CustomEvent("field:dim",{detail:{value:n}})))}},$s=ho;var fn=class{constructor(t){Y(this,"lit",!1);Y(this,"lastEdgeMs",-1/0);Y(this,"cfg");this.cfg=t}update(t,n){let r=n-this.lastEdgeMs>=this.cfg.debounceMs;return!this.lit&&t>=this.cfg.enter&&r?(this.lit=!0,this.lastEdgeMs=n,"entered"):this.lit&&t<=this.cfg.exit&&r?(this.lit=!1,this.lastEdgeMs=n,"exited"):null}get isLit(){return this.lit}reset(){this.lit=!1,this.lastEdgeMs=-1/0}};var Oc={strengthen:1.5,decay:.3,remember:.2},yo=e=>e<0?0:e>1?1:e;function Is(e,t,n,r,s=Oc){e.active=t,e.tension=yo(n),e.strength=yo(e.strength+(t?s.strengthen:-s.decay)*r),e.memory=yo(e.memory+(t?s.remember:-s.remember*.5)*r)}function Ns(e,t,n=Math.random){let r=[],s=t.absorbR+6;for(let i of e){if(i.cap!==t)continue;let l=n()*Math.PI*2,d=4+n()*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 po(e){if(e.capacity<=0)return 0;let t=e.accreted/e.capacity;return t<0?0:t>1?1:t}function Ds(e,t){return t&&!e?{fire:"captured",armed:!0}:!t&&e?{fire:"released",armed:!1}:{fire:null,armed:e}}function _s(e,t){let n=[];for(let r of e)r.when!=="active"||!r.tokens.includes("sink")||(r.wasOn&&!r.on&&r.accreted>0&&(t(r),n.push(r)),r.wasOn=r.on);return n}function mo(e,t){let n=t.cx-e.x,r=t.cy-e.y;return n*n+r*r<t.absorbR*t.absorbR}function Ls(e,t,n=.14){let r=e+(t-e)*n;return r<.001?0:r>.999?1:r}function Bs(e,t,n,r){let s=e.x+t.x,i=e.y+t.y,l=t.x+(n.x-s)*r,d=t.y+(n.y-i)*r,h=1-r;return{tx:l,ty:d,scale:h,opacity:h}}function Rc(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return t^=t>>>16,t=Math.imul(t,2246822507)>>>0,t^=t>>>13,t=Math.imul(t,3266489909)>>>0,t^=t>>>16,(t>>>0)/4294967296}function Ws(e,t){return t<1?Rc(e)<t:!0}function Pc(e){let t=0;for(let n of e)t+=.5*(n.m||1)*(n.vx*n.vx+n.vy*n.vy+(n.vz??0)*(n.vz??0));return t}function $c(e){let t=0;for(let n of e)t+=n.heat;return t}function qs(e){let t=Pc(e),n=$c(e);return{kinetic:t,thermal:n,total:t+n,count:e.length}}var Ic={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 Nc(e,t,n){let r=e.cx-t,s=e.cy-n;return{dx:r,dy:s,dist:Math.max(Math.hypot(r,s),1),form:{},c:12,G:1,t:0,probe:!0}}function go(e,t,n,r,s,i=Ic.neutral){let l=Sr(),d=Nc(n,r,s);d.accum=l;for(let h of t){let b=e[h];if(!b)continue;let x={x:r,y:s,vx:i.vx,vy:i.vy,charge:i.charge,m:i.m,heat:i.heat,size:1,cap:null};try{Jn(b,n,x,d)}catch{}}return l}function dn(e){if(!e)return{};let t={};return e.allowBodyDataInSnapshots!=null&&(t.allowBodyDataInSnapshots=e.allowBodyDataInSnapshots),e.allowMotionProjection!=null&&(t.allowMotionProjection=e.allowMotionProjection),e.maxMotionBudget!=null&&(t.maxMotionBudget=e.maxMotionBudget),e.budgets&&(t.budgets={...e.budgets}),t}function Hs(e){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}},n=e.profile;if(!n)return{includeParticles:e.includeParticles===!0,includeRelationships:e.includeRelationships!==!1,includeData:e.includeData===!0,includeInfluences:e.includeInfluences===!0};let r=t[n];return{includeParticles:r.includeParticles&&e.includeParticles!==!1,includeRelationships:r.includeRelationships&&e.includeRelationships!==!1,includeData:r.includeData&&e.includeData!==!1,includeInfluences:r.includeInfluences&&e.includeInfluences!==!1}}function Oe(e,t){let n={body:"bodies",relationship:"relationships",influence:"influences",projection:"projections"};for(let r of t){let s=r.indexOf(".");if(s<0){delete e[r];continue}let i=r.slice(0,s),l=r.slice(s+1),d=n[i];if(d&&Array.isArray(e[d]))for(let h of e[d])h&&typeof h=="object"&&delete h[l];else if(i==="metrics"&&e.metrics&&typeof e.metrics=="object")delete e.metrics[l];else{let h=e[i];h&&typeof h=="object"&&delete h[l]}}return e}var un={x:0,y:0},xt=[0,0,0],Dc=8,_c=8,Lc=.05,js=.02,Bc=1,Wc=2;function hn(e,t={}){let n=null;if((t.render??"none")!=="none"&&(n=e.getContext("2d"),!n))throw new Error("Fundamental: 2D canvas context unavailable");let r=t.overlayCanvas??null,s=n?r?.getContext("2d")??null:null,i=t.overlayBackend??(r&&s?uo(r,s):null);function l(){i||(!r&&t.overlayCanvasProvider&&(r=t.overlayCanvasProvider()??null),!(!r||!n)&&(s??(s=r.getContext("2d")),s&&(i=t.overlayBackend??uo(r,s),i.size(L,$,A.viewport().dpr))))}let d=new tn,h=1,b=new Map,x=0,E=new Map,z=o=>`potential:${o}`;function F(){x++}function T(o){let a=Nt.get(o);if(!a)return;let c=z(o),g=b.get(c);return g||(g=new ae(L,$,"held"),b.set(c,g),E.set(c,-1)),E.get(c)!==x&&(g.fillFrom(a),E.set(c,x)),g}let R=Fr(),_=new Map,I=o=>(_.get(o)?.size??0)>0;function V(o,a){let c=_.get(o);if(c)for(let g of c)g(a)}let ot=new rn;function ft(o,a){I(o)&&ot.record(o,a)}function it(){ot.flush(V)}let vt=new WeakMap,bt=new Map,St=new Map;function p(o){let a=I("enter")||I("exit"),c=I("met");if(!a&&!c)return;for(let m=0;m<o.length;m++){let w=o[m];if(a){let y=bt.get(w);y||bt.set(w,y=new Set);let u=w.range*w.range;for(let f=0;f<o.length;f++){if(m===f)continue;let v=o[f],S=v.cx-w.cx,M=v.cy-w.cy,k=S*S+M*M<u;k&&!y.has(v)?(y.add(v),I("enter")&&ft("enter",{body:w,other:v})):!k&&y.has(v)&&(y.delete(v),I("exit")&&ft("exit",{body:w,other:v}))}}if(c){let y=St.get(w);y||St.set(w,y=new Set);for(let u=m+1;u<o.length;u++){let f=o[u],v=Math.abs(f.cx-w.cx)<w.hw+f.hw&&Math.abs(f.cy-w.cy)<w.hh+f.hh;v&&!y.has(f)?(y.add(f),ft("met",{a:w,b:f})):!v&&y.has(f)&&y.delete(f)}}}let g=new Set(o);for(let m of[bt,St])for(let w of m.keys())g.has(w)||m.delete(w)}let Et=[],Zt=new WeakMap,mt=[],Pe=0,te=new WeakMap,$e=new WeakMap,Nt=new Map,q=new Map;if(zr(R),Tr(R),Pr(R),!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 A=t.host,H=[],K=()=>A.reducedMotion?.()??!1,Q=dn(t.policy),Ft=()=>{if(K())return 0;let o=1;return Q.allowMotionProjection===!1?0:(Q.maxMotionBudget!=null&&(o=Math.min(o,Q.maxMotionBudget)),Q.budgets?.motion!=null&&(o=Math.min(o,Q.budgets.motion)),Math.max(0,Math.min(1,o)))},ut=Ft()<=0,Ot=.5,ee=()=>{if(Q.allowBodyDataInSnapshots===!1)return!1;let o=Q.budgets?.privacy;return!(o!=null&&o<Ot)},Wt=jn[t.theme??Un]??jn[Un],O={accent:t.accent??Ke(t.palette)[0]??Wn[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:Ee.ambient.preset.orbit,ambientWander:t.ambientWander!=null&&t.ambientWander>=0?t.ambientWander:Ee.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?gt(t.gradientCool):Wt.cool,gradientWarm:t.gradientWarm?gt(t.gradientWarm):Wt.warm,waveBaseline:(t.waveBaseline??Wt.wave).map(gt),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,restingMotion:t.restingMotion&&(t.restingMotion.mode==="thermal"||t.restingMotion.mode==="flow")?{mode:t.restingMotion.mode,strength:t.restingMotion.strength!=null&&t.restingMotion.strength>=0?t.restingMotion.strength:1}:void 0,integrator:t.integrator==="fixed"||t.integrator==="velocity-verlet"?t.integrator:"legacy",feedbackSink:t.feedbackSink??ho},at=null,W=[],L=0,$=0,Z=0,tt=0,ce=!1,be=1,we=0,wo=new WeakMap,ne=0,$t=0,Mo=!0,xn={...Ee.ambient.preset,orbit:O.ambientOrbit,wander:O.ambientWander},So={...xn},vn="ambient",Qs=0,ko=t.identify,bn=o=>{if(o.identity)return o.identity;let a;return ko&&o.el&&(a=ko(o.el)),a||(a={id:(o.el&&o.el.id?o.el.id:void 0)??`body-${Qs++}`}),o.identity=a,a},oe=o=>bn(o).id,re=new Map,le=new Map,Eo=(o,a)=>{let c=re.get(o);if(!c)return 0;let g=0;for(let m of c.values())g+=m.mass*Ae(m.at,a,m.halfLife);return g>1?1:g};function Zs(o,a){let c=typeof o=="string"?{id:o}:o,g=c.id;if(!g)return;let m=a?.amount??1,w=a?.source??"system",y=a?.halfLife??Dc,u=a?.at??B.t;typeof o!="string"&&(c.namespace||c.kind||c.host)&&le.set(g,c);let f=re.get(g);f||re.set(g,f=new Map);let v=f.get(w),M=(v?v.mass*Ae(v.at,u,v.halfLife):0)+m;f.set(w,{mass:M,at:u,halfLife:y}),ft("focus",{target:g,identity:le.get(g)??c,source:w,amount:m,salience:Eo(g,u),sourceSalience:M>1?1:M,frame:$t,time:u})}function ti(o){let a=B.t,c=o?.limit??_c,g=o?.threshold??Lc,m=o?.source,w=u=>u.find(f=>f.source===m)?.weight??0,y=[];for(let[u,f]of re){let v=[],S=0,M=0;for(let[k,C]of f){let N=C.mass*Ae(C.at,a,C.halfLife);N<=0||(S+=N,C.at>M&&(M=C.at),v.push({source:k,weight:N>1?1:N,updatedAt:C.at}))}S>1&&(S=1),!((m?w(v):S)<g)&&(v.sort((k,C)=>C.weight-k.weight),y.push({target:u,identity:le.get(u)??{id:u},salience:S,sources:v,updatedAt:M}))}return y.sort((u,f)=>m?w(f.sources)-w(u.sources):f.salience-u.salience),{frame:$t,time:a,entries:y.slice(0,c)}}function ei(){if(re.size===0)return;let o=B.t;for(let[a,c]of re){for(let[g,m]of c)m.mass*Ae(m.at,o,m.halfLife)<js&&c.delete(g);c.size===0&&(re.delete(a),le.delete(a))}for(let a of W){let c=Eo(oe(a),o);if(c>js){a.salience=c;let g=1+Bc*c;a.focusMul=g>1?Math.min(Wc,g):void 0,a.identity&&!le.has(a.identity.id)&&le.set(a.identity.id,a.identity)}else a.salience!==void 0&&(a.salience=void 0),a.focusMul!==void 0&&(a.focusMul=void 0)}}let Fo=o=>{let a={density:o.d,count:o.count,engaged:o.on?1:0};o.attn!==void 0&&(a.attention=o.attn),o.salience!==void 0&&(a.salience=o.salience),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}},ni=0,Yt=new Map,oi=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}:{}}),Ie=()=>[...Yt.values()].map(oi),Ne=[];function ri(){for(let o of Ne)Yt.get(o.id)?.apply?.(o.source(),o.target)}let si={register(o){return Yt.set(o.id,o),()=>{Yt.get(o.id)===o&&Yt.delete(o.id)}},unregister(o){Yt.delete(o)},get(o){return Yt.get(o)},list:Ie,apply(o,a,c){Yt.get(o)?.apply?.(a,c)},bind(o,a,c){let g={id:o,target:a,source:c};return Ne.push(g),()=>{let m=Ne.indexOf(g);m>=0&&Ne.splice(m,1)}},lint:()=>Ir(Ie())},zo=.9,Ao=8,ii=4800,To=.02;function ai(){for(let o of W){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,g=W.filter(k=>k!==o&&k.vis&&k.tokens.length>0),{fx:m,fy:w}=Qt(g,R.forces,B,a,c);if(O.mass){let k=o.hw*2*(o.hh*2);o.inertia=Math.min(4,Math.max(.4,Math.sqrt(k/ii)))}let y=1/Math.max(o.inertia??o.M,1e-4),u=0,f=0;if(O.reaction&&o.tokens.length>0){let k=o.range*o.range,C=[o];for(let N of d.particles){if(N.cap)continue;let P=N.x-a,j=N.y-c;if(P*P+j*j>k)continue;let X=Qt(C,R.forces,B,N.x,N.y);u-=X.fx,f-=X.fy}}let v=(o.bvx??0)+(m+u*To)*y*B.dt,S=(o.bvy??0)+(w+f*To)*y*B.dt;v*=zo,S*=zo;let M=Math.hypot(v,S);if(M>Ao){let k=Ao/M;v*=k,S*=k}o.bvx=v,o.bvy=S,o.bx=a+v*B.dt,o.by=c+S*B.dt,o.cx=o.bx,o.cy=o.by}}let Co=globalThis.structuredClone,ci=o=>{if(o==null)return o;try{return Co?Co(o):JSON.parse(JSON.stringify(o))}catch{try{return JSON.parse(JSON.stringify(o))}catch{return o}}},kt=[],Gt=[],Oo=0,se=null,ht=t.rng??Math.random,wn=t.now??(()=>performance.now()),rt=ut?1:0,Mn=NaN,qt=null,Me=null,fe=null,Vt=0,Ht=0,De=null,Sn=[],kn=null,_e=null,li=Math.round(130*O.density)*4,wt={x:0,y:0,k:0},yt=null,jt=null,Ro=0,Po=0,$o=Ke(t.palette).map(gt),ct=gt(O.accent),Le=null,En=[],Xt=[],de=[],ue=[],Fn=[],zn=[],he=[],Be=new an,An=!1,Tn=()=>{An||(An=!0,queueMicrotask(()=>{An=!1,qe()}))},fi=o=>{for(let a of["--d","--field-density","--load","--entropy","--coherence","--temperature"])o.style.removeProperty(a)},di=o=>{let a=o.detail;a?.element&&(Be.register(a),Tn())},ui=o=>{let a=o.detail;a?.element&&(Be.unregister(a.element),fi(a.writeTarget??a.element),Tn())},hi=Tn,Dt={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null},Io=wn(),B={dx:0,dy:0,dz:0,dist:1,form:{...xn},W:0,H:0,D:O.depth,integrator:O.integrator,t:0,frameN:0,dt:ut?0:1,c:12,G:1,scrollV:0,rng:ht,spark:(o,a,c,g)=>No(o,a,c,g),supernova:o=>{let a=Ns(d.particles,o,ht),c=new Set(a);for(let g of d.particles){if(c.has(g))continue;let m=g.x-o.cx,w=g.y-o.cy,y=Math.hypot(m,w)||1;if(y<320){let u=(1-y/320)*4;g.vx+=m/y*u,g.vy+=w/y*u,g.heat=Math.max(g.heat,.8)}}no(Gt,kt,o.cx,o.cy,320,L,$,B.t,g=>void d.add(ye(g))),Si(o),Cn(o.el,"field:saturated",{peak:a.length}),o.el.dataset.fxCap==="1"&&(o.el.dataset.fxCap="0",pe(o.el,"released",{accreted:0,load:0}),I("released")&&ft("released",{body:o,count:a.length}),vt.delete(o))},spawn:o=>{d.size>=li||d.add(ye(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":o.startsWith("potential:")?"held":"diffuse";a=new ae(L,$,c),b.set(o,a)}return a}};function No(o,a,c,g){if(ut||ue.length>260)return;let m=g?gt(g):[255,122,69],w=Hr(c,ht);for(let y=0;y<w;y++){let u=ht()*6.28318,f=.8+ht()*(c>0?c:1)*1.7;ue.push({x:o,y:a,vx:Math.cos(u)*f,vy:Math.sin(u)*f,life:1,c:m})}}function ye(o={}){let a=o.size??.7+ht()*1.8;return{id:o.id??h++,x:o.x??ht()*L,y:o.y??ht()*$,vx:o.vx??(ht()-.5)*.25,vy:o.vy??(ht()-.5)*.18,z:o.z??(O.depth>0?ht()*O.depth:0),vz:o.vz??(O.depth>0?(ht()-.5)*.18:0),m:o.m??(O.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 We=[];function yi(){if(!We.length)return;let o=d.particles;for(let a=0;a<o.length;a++){let c=We[a%We.length];o[a].atom=c;let g=typeof c.weight=="number"?Math.max(0,Math.min(1,c.weight)):.5;o[a].size*=.6+g*.9,o[a].m*=.6+g*1.2}}function Do(){d.clear();let o=Math.round(130*O.density);for(let a=0;a<o;a++)d.add(ye());yi(),kt=O.waves?dr(O.waveBaseline):[],Gt=O.waves?ur(kt.length,O.density,ht):[],Oo=Gt.length}function qe(){let o=W,a=ds(A.root);if(Be.size>0){let y=new Set(a.map(u=>u.el));W=a.concat(Be.bodies(Te,A.root).filter(u=>!y.has(u.el)))}else W=a;Et.length>0&&(W=W.concat(Et));let c=null,g=!1;if(o.length>0){let y=new Map;for(let f of o){let v=y.get(f.el);v?v.push(f):y.set(f.el,[f])}let u=new Map;for(let f of W){let v=y.get(f.el);if(!v)continue;let S=u.get(f.el)??0;u.set(f.el,S+1);let M=v[S];if(!M||M===f)continue;M.identity!==void 0&&(f.identity=M.identity),M.bx!==void 0&&(f.bx=M.bx,f.by=M.by,f.bvx=M.bvx,f.bvy=M.bvy),f.d=M.d,M.attn!==void 0&&(f.attn=M.attn),f.accreted=M.accreted,f.count=M.count,M.wasOn!==void 0&&(f.wasOn=M.wasOn);let k=te.get(M);k&&te.set(f,k);let C=vt.get(M);C!==void 0&&vt.set(f,C),(c??(c=new Map)).set(M,f),M.accreted>0&&(g=!0)}if(g)for(let f of d.particles){if(!f.cap)continue;let v=c.get(f.cap);v&&(f.cap=v)}}sn(W,L,$,Z,tt),Ei();let m=new Map(Xt.map(y=>[y.el,y]));Xt=[...A.root.querySelectorAll("[data-move]")].map(y=>{let u=y,f=u.getBoundingClientRect(),v=Number.parseFloat(u.dataset.mass??""),S=Number.isFinite(v)?v:Vr(f.width*f.height),M=(u.dataset.move??"").trim()==="layout",k=u.hasAttribute("data-dock"),C=u.hasAttribute("data-warp"),N=m.get(u);if(N){let P=N.docked?c?.get(N.docked)??N.docked:null;return{el:u,o:N.o,mEl:S,layout:M,dockable:k,dock:N.dock,docked:P,warpable:C,warpCool:N.warpCool}}return{el:u,o:{x:0,y:0,vx:0,vy:0},mEl:S,layout:M,dockable:k,dock:{dock:0},docked:null,warpable:C,warpCool:0}}),Fn=[...A.root.querySelectorAll("[data-on]")].map(y=>{let u=y;return{el:u,body:W.find(f=>f.el===u)??null,bindings:oo(u.dataset.on??"")}}),zn=[...A.root.querySelectorAll("[data-class]")].map(y=>{let u=y;return{el:u,body:W.find(f=>f.el===u)??null,bindings:oo(u.dataset.class??"")}});for(let y of W){if(!y.pair)continue;let u=null;try{u=A.root.querySelector(y.pair)}catch{u=null}y.pairBody=u?W.find(f=>f.el===u):void 0}let w=new Map(de.map(y=>[y.el,y]));for(let[y,u]of w)if(!A.root.contains(y))for(let f of u.emitted)f.remove();de=[...A.root.querySelectorAll("[data-emit]")].map(y=>{let u=y,f=u.dataset.emit??"",v=null;try{v=f?A.root.querySelector(f):null}catch{v=null}let S=Math.max(0,Math.round(Number.parseFloat(u.dataset.max??"")||8)),M=w.get(u);if(M){let k=M.emitted.filter(C=>C.isConnected);for(;k.length>S;)k.pop().remove();return{el:u,tmpl:v,cap:S,emitted:k}}return{el:u,tmpl:v,cap:S,emitted:[]}})}function pi(){for(let o of W)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 mi(){if(!(de.length===0||B.frameN%30!==0))for(let o of de){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 gi(){if(Fn.length!==0)for(let o of Fn){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 g=ro(c.trigger,a);g&&!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}}))):g||(c.armed=!1)}}}function xi(){if(zn.length!==0)for(let o of zn){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 g=ro(c.trigger,a);g&&!c.armed?(c.armed=!0,o.el.classList.add(c.event)):!g&&c.armed&&(c.armed=!1,o.el.classList.remove(c.event))}}}function pe(o,a,c){o.dispatchEvent(new CustomEvent("field:"+a,{bubbles:!0,composed:!0,detail:c}))}function vi(){for(let o of W){if(!o.vis||o.tokens.indexOf("sink")<0)continue;let a=o.el.dataset.fxCap==="1",c=Ds(a,o.accreted>0);c.fire==="captured"?(o.el.dataset.fxCap="1",pe(o.el,"captured",{accreted:o.accreted,load:po(o)}),I("captured")&&ft("captured",{body:o,count:o.accreted}),vt.set(o,o.accreted)):c.fire==="released"&&(o.el.dataset.fxCap="0",pe(o.el,"released",{accreted:0,load:0}),I("released")&&ft("released",{body:o,count:vt.get(o)??0}),vt.delete(o))}}let bi=[{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"}],wi=120;function Cn(o,a,c){o.dispatchEvent(new CustomEvent(a,{bubbles:!0,composed:!0,detail:c}))}function _o(o,a,c,g,m,w){let y=o.get(a);y||o.set(a,y=new Map);let u=y.get(g.metric);u||y.set(g.metric,u=new fn({enter:g.enter,exit:g.exit,debounceMs:wi}));let f=u.update(m,w);f==="entered"?Cn(c,g.rise,{metric:g.metric,value:m}):f==="exited"&&Cn(c,g.fall,{metric:g.metric,value:m})}function Mi(o){for(let a of W)if(!(!a.vis||a.tokens.length===0))for(let c of bi){let g;switch(c.metric){case"density":g=a.d;break;case"attention":O.attention&&(g=a.attn??1);break;case"entropy":g=a.metrics?.entropy;break}g!==void 0&&_o(te,a,a.el,c,g,o)}for(let a of mt)_o($e,a.agent,a.from.el,{metric:"memory",enter:.6,exit:.3,rise:"field:memory-threshold",fall:"field:memory-faded"},a.agent.memory,o)}function Si(o){for(let a of Xt)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="",pe(a.el,"released",{}))}function ki(){if(Xt.length===0)return;let o=Xt.map(a=>{let c=a.el.getBoundingClientRect();return{x:c.left-Z+c.width/2,y:c.top-tt+c.height/2}});for(let a=0;a<Xt.length;a++){let c=Xt[a];if(!c.el.isConnected){c.docked&&(c.docked=null,c.dock.dock=0);continue}let g=o[a].x,m=o[a].y;if(c.docked){let v={x:g-c.o.x,y:m-c.o.y};c.dock.dock=Ls(c.dock.dock,1);let S=Bs(v,c.o,{x:c.docked.cx,y:c.docked.cy},c.dock.dock);c.el.style.transform=`translate(${S.tx.toFixed(2)}px, ${S.ty.toFixed(2)}px) scale(${S.scale.toFixed(3)})`,c.el.style.opacity=S.opacity.toFixed(3),c.dock.dock>=1&&c.el.getAttribute("aria-hidden")!=="true"&&(c.el.setAttribute("aria-hidden","true"),c.el.setAttribute("inert",""));continue}Dt.x=g,Dt.y=m,Dt.vx=0,Dt.vy=0,Dt.heat=0,Dt.cap=null;for(let v of W){if(!v.vis||v.tokens.length===0||v.el===c.el)continue;let S=v.cx-g,M=v.cy-m,k=Math.hypot(S,M);B.dx=S,B.dy=M,B.dist=k<1?1:k;for(let C of v.tokens)R.forces[C]?.apply(v,Dt,B)}Dt.cap=null;let w=Gr(c.o),y=Dt.vx+w.x,u=Dt.vy+w.y;if(c.layout){let v=Xr({x:g,y:m},o,a),S=Kr((M,k)=>d.near(M,k,40).length,g,m,16,6);y+=v.x+S.x,u+=v.y+S.y}let f={x:g-c.o.x,y:m-c.o.y};if(Yr(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 v={x:f.x+c.o.x,y:f.y+c.o.y},S=W.find(M=>M.vis&&M.el!==c.el&&M.tokens.indexOf("sink")>=0&&mo(v,M));S&&(c.docked=S,pe(c.el,"captured",{sink:S.el}))}if(c.warpCool>0&&(c.warpCool-=1),c.warpable&&c.warpCool===0){let v={x:f.x+c.o.x,y:f.y+c.o.y},S=W.find(M=>M.vis&&M.el!==c.el&&M.warpHas&&M.tokens.indexOf("warp")>=0&&mo(v,M));S&&(c.o.x=S.warpX-f.x,c.o.y=S.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,pe(c.el,"relocated",{from:S.el}))}}}function Ei(){he.length&&(he=he.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))),A.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",Le=a.dataset.color??null;let m=a.closest("[data-index][data-threads]");if(m){let w=[...m.querySelectorAll("[data-hot]")].filter(y=>y!==a);On(w.map(y=>({a,b:y,color:a.dataset.color??void 0})))}},g=()=>{a.dataset.active="0",Le=null,On(null)};a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",g),a.addEventListener("focusin",c),a.addEventListener("focusout",g),he.push({el:a,enter:c,leave:g})})}function On(o){En=(o??[]).map(a=>({a:a.a,b:a.b,c:gt(a.color??O.accent),seed:ht()*6.28}))}function Fi(){if(En.length===0)return;let o=B.t;n.globalCompositeOperation="lighter";for(let a of En){let c=a.a.getBoundingClientRect(),g=a.b.getBoundingClientRect(),m=c.left-Z+c.width/2,w=c.top-tt+c.height/2,y=g.left-Z+g.width/2,u=g.top-tt+g.height/2,[f,v,S]=a.c;n.strokeStyle=`rgba(${f},${v},${S},0.22)`,n.lineWidth=1,n.beginPath(),n.moveTo(m,w),n.lineTo(y,u),n.stroke();for(let M=0;M<3;M++){let k=(o*.6+a.seed+M/3)%1,C=m+(y-m)*k,N=w+(u-w)*k;n.fillStyle=`rgba(${f},${v},${S},${(1-k)*.9})`,n.beginPath(),n.arc(C,N,2.2,0,6.28318),n.fill()}}n.globalCompositeOperation="source-over"}let He=0,zi=[1/0,1.5,1.25,1];function je(o){if(!n)return;let a=Math.min(o||1,O.dprCap,zi[He]??1/0);e.width=Math.floor(L*a),e.height=Math.floor($*a),e.style.width=L+"px",e.style.height=$+"px",n.setTransform(a,0,0,a,0,0),i?.size(L,$,a)}function Lo(){let o=A.viewport();L=o.width,$=o.height,Z=o.originX??0,tt=o.originY??0,ce=o.originX!=null||o.originY!=null,je(o.dpr),B.W=L,B.H=$,be=(A.scrollHeight?.()??$)-$||1;for(let a of b.values())a.resize(L,$);F(),O.heatmap&&(at?at.resize(L,$):at=new Ce(L,$)),Do(),qe()}function Ai(){let o=B.t,a=16;if(O.waveStyle==="circular"){let c=se||{x:L/2,y:$/2},g=Math.min(L,$)*.48;for(let m of kt){let[w,y,u]=m.color;n.beginPath();let f=.08,v=!0;for(let k=0;k<=2*Math.PI+.01;k+=f){let C=Fe(m,k,o,g),N=c.x+Math.cos(k)*C,P=c.y+Math.sin(k)*C;v?(n.moveTo(N,P),v=!1):n.lineTo(N,P)}n.closePath();let S=m.baseFrac*g+m.offsetY,M=n.createRadialGradient(c.x,c.y,Math.max(0,S-m.amp),c.x,c.y,S+m.amp+80);M.addColorStop(0,`rgba(${w},${y},${u},${(.08+m.depth*.04)*rt})`),M.addColorStop(1,`rgba(${w},${y},${u},0)`),n.fillStyle=M,n.fill()}n.globalCompositeOperation="lighter";for(let m of kt){let[w,y,u]=m.color;n.beginPath();let f=.08,v=!0;for(let S=0;S<=2*Math.PI+.01;S+=f){let M=Fe(m,S,o,g),k=c.x+Math.cos(S)*M,C=c.y+Math.sin(S)*M;v?(n.moveTo(k,C),v=!1):n.lineTo(k,C)}n.closePath(),n.lineWidth=5,n.strokeStyle=`rgba(${w},${y},${u},${(.05+m.depth*.04)*rt})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${w},${y},${u},${(.3+m.depth*.22)*rt})`,n.stroke()}n.globalCompositeOperation="source-over"}else{for(let c of kt){let[g,m,w]=c.color;n.beginPath(),n.moveTo(0,Ct(c,0,o,$,1,1,wt));for(let f=0;f<=L;f+=a)n.lineTo(f,Ct(c,f,o,$,1,1,wt));n.lineTo(L,$),n.lineTo(0,$),n.closePath();let y=c.baseFrac*$+c.offsetY-c.amp,u=n.createLinearGradient(0,y,0,y+320);u.addColorStop(0,`rgba(${g},${m},${w},${(.11+c.depth*.05)*rt})`),u.addColorStop(1,`rgba(${g},${m},${w},0)`),n.fillStyle=u,n.fill()}n.globalCompositeOperation="lighter";for(let c of kt){let[g,m,w]=c.color;n.beginPath(),n.moveTo(0,Ct(c,0,o,$,1,1,wt));for(let y=0;y<=L;y+=a)n.lineTo(y,Ct(c,y,o,$,1,1,wt));n.lineWidth=5,n.strokeStyle=`rgba(${g},${m},${w},${(.05+c.depth*.04)*rt})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${g},${m},${w},${(.3+c.depth*.22)*rt})`,n.stroke()}n.globalCompositeOperation="source-over"}}function Ti(){n.globalCompositeOperation="lighter";let o=B.t,a=0;if(O.waveStyle==="circular"){let c=se||{x:L/2,y:$/2},g=Math.min(L,$)*.48;for(let m of Gt){let w=kt[m.wi];if(!w){a++;continue}B.dt&&(m.progress+=m.speed,m.progress>1?m.progress-=1:m.progress<0&&(m.progress+=1));let y=m.progress*2*Math.PI,u=Fe(w,y,o,g)+m.phase*32,f=c.x+Math.cos(y)*u,v=c.y+Math.sin(y)*u,[S,M,k]=w.color,C=m.glow?.6+.4*Math.sin(o*2.2+a):.85;m.glow&&(n.fillStyle=`rgba(${S},${M},${k},${.16*C*rt})`,n.beginPath(),n.arc(f,v,m.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${S},${M},${k},${C*rt})`,n.beginPath(),n.arc(f,v,m.size,0,6.28318),n.fill(),a++}}else for(let c of Gt){let g=kt[c.wi];if(!g){a++;continue}B.dt&&(c.progress+=c.speed,c.progress>1?c.progress-=1:c.progress<0&&(c.progress+=1));let m=c.progress*L,w=Ct(g,m,o,$,1,1,wt)+c.phase*32,[y,u,f]=g.color,v=c.glow?.6+.4*Math.sin(o*2.2+a):.85;c.glow&&(n.fillStyle=`rgba(${y},${u},${f},${.16*v*rt})`,n.beginPath(),n.arc(m,w,c.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${y},${u},${f},${v*rt})`,n.beginPath(),n.arc(m,w,c.size,0,6.28318),n.fill(),a++}n.globalCompositeOperation="source-over"}function Ci(){if(!O.attention)return;for(let c of W)c.attn=1;let o=W.filter(c=>c.vis&&c.tokens.length>0);if(o.length===0)return;let a=sr(o);for(let c=0;c<o.length;c++)o[c].attn=a[c]}function Oi(){if(!O.causality)return;let o=W.filter(c=>c.vis&&c.tokens.length>0);if(o.length===0)return;if(o.length===1){Bo(o[0],o[0].d);return}let a=ir(o.map(c=>({d:c.d,cx:c.cx,cy:c.cy})));for(let c=0;c<o.length;c++)Bo(o[c],pt(o[c].d+a[c],0,1))}function Bo(o,a){O.feedbackSink(o.el,{lit:a})}function Ri(){for(let o of W){if(!o.feedback)continue;let a=or(o.count,o.on);o.d+=(a-o.d)*.08;let c=o.writeTarget??o.el;if(o.fmax){let f=rr(o.fmin,o.fmax,o.d);wo.get(c)!==f&&(wo.set(c,f),c.style.fontVariationSettings=`"wght" ${f}`+(o.opsz?`, "opsz" ${o.opsz}`:""))}let g=at?at.norm(o.cx,o.cy):void 0,m=o.tokens.indexOf("sink")>=0&&o.capacity>0?po(o):void 0,w=es(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:g,load:m,entropy:y.entropy,coherence:y.coherence,temperature:y.temperature};O.feedbackSink(c,u),o.onFeedback?.(u)}}function Pi(){if(ue.length!==0){n.globalCompositeOperation="lighter";for(let o=ue.length-1;o>=0;o--){let a=ue[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){ue.splice(o,1);continue}let[c,g,m]=a.c;n.fillStyle=`rgba(${c},${g},${m},${.18*a.life})`,n.beginPath(),n.arc(a.x,a.y,2+a.life*4,0,6.28318),n.fill(),n.fillStyle=`rgba(${c},${g},${m},${a.life})`,n.beginPath(),n.arc(a.x,a.y,.6+a.life*1.5,0,6.28318),n.fill()}n.globalCompositeOperation="source-over"}}let Kt=null,Ue=null,me=null;function $i(){if(!at)return;let o=$>0?pt((O.heatmapFadeStart+O.heatmapFadeSpan-we/$)/O.heatmapFadeSpan,0,1):1;if(o<=.01)return;let a=at.cell,c=Math.max(1,Math.ceil(L/a)),g=Math.max(1,Math.ceil($/a));if(!Kt){if(!A.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.");Kt=A.createCanvas(),Ue=Kt.getContext("2d")}if(Ue){if((Kt.width!==c||Kt.height!==g)&&(Kt.width=c,Kt.height=g,me=null),me===null||$t%3===0){me===null&&(me=Ue.createImageData(c,g));let m=ct,w=me.data;for(let y=0;y<g;y++)for(let u=0;u<c;u++){let f=at.norm(u*a+a/2,y*a+a/2),v=(y*c+u)*4;w[v]=m[0],w[v+1]=m[1],w[v+2]=m[2],w[v+3]=Math.round(pt(f*.5*rt,0,1)*255)}Ue.putImageData(me,0,0)}n.globalCompositeOperation="lighter",n.imageSmoothingEnabled=!0,n.globalAlpha=o,n.drawImage(Kt,0,0,L,$),n.globalAlpha=1,n.globalCompositeOperation="source-over"}}function Ii(){O.background==="transparent"?O.render==="trails"?(n.globalCompositeOperation="destination-out",n.fillStyle="rgba(0,0,0,0.22)",n.fillRect(0,0,L,$),n.globalCompositeOperation="source-over"):n.clearRect(0,0,L,$):(O.render==="trails"?n.fillStyle="rgba(5,6,11,0.22)":n.fillStyle="rgb(5,6,11)",n.fillRect(0,0,L,$)),Ai(),at&&He<2&&$i(),Ti();let o=O.render!=="metaballs"&&O.render!=="streamlines"&&O.render!=="knockout"&&O.render!=="redshift"&&O.render!=="blackbody"&&O.render!=="depth";n.globalCompositeOperation="lighter";let a=ct,c=L*O.heatCenterX,g=$*O.heatCenterY,m=Math.hypot(Math.max(c,L-c),Math.max(g,$-g))||1;if(_e===null||$t%6===0){_e=[];for(let y of W){if(!y.tint)continue;let u=(y.range||200)*1.4;_e.push({b:y,r2:u*u,rgb:gt(y.tint)})}}let w=_e;if(o)for(let y of d.particles){if(y.cap){n.fillStyle=`rgba(${a[0]},${a[1]},${a[2]},${.55*rt})`,n.beginPath(),n.arc(y.x,y.y,1.3,0,6.28318),n.fill();continue}let u=Math.min(1,Math.hypot(y.x-c,y.y-g)/m),f=u*u,v=y.heat;Yn(xt,f,v,a,O.gradientCool,O.gradientWarm);let S=xt[0],M=xt[1],k=xt[2];if(w.length){let lt=0,J=null;for(let et of w){let zt=y.x-et.b.cx,At=y.y-et.b.cy,Jt=zt*zt+At*At;if(Jt>=et.r2)continue;let D=1-Math.sqrt(Jt/et.r2);D>lt&&(lt=D,J=et.rgb)}if(J){let et=lt*.7;S+=(J[0]-S)*et,M+=(J[1]-M)*et,k+=(J[2]-k)*et}}if(y.color){let[lt,J,et]=gt(y.color);S+=(lt-S)*.75,M+=(J-M)*.75,k+=(et-k)*.75}let C=O.depth>0?1-Math.min(Math.abs(y.z??0)/O.depth,1)*.55:1,N=(y.size*(1-.4*f)+v*2)*C,P=pt((.5-.3*f+v*.5)*rt*C,0,1),j=S|0,X=M|0,dt=k|0;n.fillStyle=`rgba(${j},${X},${dt},${.12*P})`,n.beginPath(),n.arc(y.x,y.y,N+1.2,0,6.28318),n.fill(),n.fillStyle=`rgba(${j},${X},${dt},${P})`,n.beginPath(),n.arc(y.x,y.y,N,0,6.28318),n.fill()}if(Pi(),Fi(),n.globalCompositeOperation="source-over",O.render==="links"){n.globalCompositeOperation="lighter";let y=ct,u=90;n.lineWidth=.6;for(let f of d.particles)if(!f.cap)for(let v of d.neighbors(f,u)){if(v.x<f.x||v.x===f.x&&v.y<f.y)continue;let S=gs(Math.hypot(v.x-f.x,v.y-f.y),u);S<=0||(n.strokeStyle=`rgba(${y[0]},${y[1]},${y[2]},${S})`,n.beginPath(),n.moveTo(f.x,f.y),n.lineTo(v.x,v.y),n.stroke())}n.globalCompositeOperation="source-over"}if(O.render==="metaballs"){let v=Math.ceil(L/16)+1,S=Math.ceil($/16)+1;!qt||qt.length!==v*S?qt=new Float32Array(v*S):qt.fill(0);for(let k of d.particles)k.cap||lo(qt,v,S,16,k.x,k.y,34,1);let M=ct;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${M[0]},${M[1]},${M[2]},${.5*rt})`,n.lineWidth=1.4,n.lineCap="round",n.beginPath();for(let k=0;k<S-1;k++)for(let C=0;C<v-1;C++){let N=qt[k*v+C],P=qt[k*v+C+1],j=qt[(k+1)*v+C+1],X=qt[(k+1)*v+C],dt=co(N,P,j,X,.9);if(!dt.length)continue;let lt=C*16,J=k*16;for(let et of dt)n.moveTo(lt+et.x1*16,J+et.y1*16),n.lineTo(lt+et.x2*16,J+et.y2*16)}n.stroke(),n.globalCompositeOperation="source-over"}if(O.render==="voronoi"){let f=Math.ceil(L/18)+1,v=Math.ceil($/18)+1;(!Me||Me.length!==f*v)&&(Me=new Int32Array(f*v));let S=d.particles,M=new Map;for(let C=0;C<S.length;C++)M.set(S[C],C);for(let C=0;C<v;C++)for(let N=0;N<f;N++){let P=N*18,j=C*18,X=d.near(P,j,54),dt=-1;if(X.length){let lt=xs(P,j,X);lt>=0&&(dt=M.get(X[lt])??-1)}Me[C*f+N]=dt}let k=ct;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${k[0]},${k[1]},${k[2]},${.32*rt})`,n.lineWidth=1,n.beginPath();for(let C of Cs(Me,f,v))n.moveTo(C.x1*18,C.y1*18),n.lineTo(C.x2*18,C.y2*18);n.stroke(),n.globalCompositeOperation="source-over"}if(O.render==="knockout"){let y=ct;n.fillStyle=`rgba(${y[0]},${y[1]},${y[2]},${.22*rt})`,n.fillRect(0,0,L,$),n.globalCompositeOperation="destination-out";for(let u of d.particles){if(u.cap)continue;let f=O.depth>0?1-Math.min(Math.abs(u.z??0)/O.depth,1)*.55:1,v=vs(u.size,u.heat,f);n.fillStyle=`rgba(0,0,0,${.38*rt})`,n.beginPath(),n.arc(u.x,u.y,v+2.2,0,6.28318),n.fill(),n.fillStyle=`rgba(0,0,0,${rt})`,n.beginPath(),n.arc(u.x,u.y,v,0,6.28318),n.fill()}n.globalCompositeOperation="source-over"}if(O.render==="redshift"){n.globalCompositeOperation="lighter";let y=L*O.redshiftObserverX,u=$*O.redshiftObserverY;for(let f of d.particles){if(f.cap)continue;let v=0;for(let P of W){let j=P.range||200,X=f.x-P.cx,dt=f.y-P.cy,lt=Ms(X*X+dt*dt,j*j);lt>v&&(v=lt)}let S=Ss(ws(bs(f.x,f.y,f.vx,f.vy,y,u),B.c),v);ks(xt,S);let M=O.depth>0?1-Math.min(Math.abs(f.z??0)/O.depth,1)*.55:1,k=S<0?-S:S,C=(f.size+k*1.6)*M,N=pt((.4+.45*k)*rt*M,0,1);n.fillStyle=`rgba(${xt[0]|0},${xt[1]|0},${xt[2]|0},${N})`,n.beginPath(),n.arc(f.x,f.y,C,0,6.28318),n.fill()}n.globalCompositeOperation="source-over"}if(O.render==="blackbody"){n.globalCompositeOperation="lighter";for(let y of d.particles){if(y.cap)continue;let u=Es(y.vx,y.vy,y.heat,B.c);Fs(xt,u);let f=O.depth>0?1-Math.min(Math.abs(y.z??0)/O.depth,1)*.55:1,v=(y.size+u*2.2)*f,S=pt((.16+.84*u)*rt*f,0,1),M=xt[0]|0,k=xt[1]|0,C=xt[2]|0;n.fillStyle=`rgba(${M},${k},${C},${.14*S})`,n.beginPath(),n.arc(y.x,y.y,v+1.4+u*2,0,6.28318),n.fill(),n.fillStyle=`rgba(${M},${k},${C},${S})`,n.beginPath(),n.arc(y.x,y.y,v,0,6.28318),n.fill()}n.globalCompositeOperation="source-over"}if(O.render==="depth"){let y=d.particles,u=y.length;(!fe||fe.length!==u)&&(fe=new Array(u));for(let M=0;M<u;M++)fe[M]=M;fe.sort((M,k)=>Math.abs(y[k].z??0)-Math.abs(y[M].z??0));let f=O.depthFocal,v=L/2,S=$/2;for(let M=0;M<u;M++){let k=y[fe[M]];if(k.cap)continue;let C=k.z??0,N=O.depth>0?Math.min(Math.abs(C)/O.depth,1):0,P=zs(C,f),j=fo(k.x,v,P),X=fo(k.y,S,P),dt=Math.min(1,Math.hypot(j-c,X-g)/m),lt=dt*dt,J=k.heat;Yn(xt,lt,J,a,O.gradientCool,O.gradientWarm);let et=(k.size*(1-.4*lt)+J*2)*P,zt=pt((.5-.3*lt+J*.5)*rt*As(N),0,1),At=xt[0]|0,Jt=xt[1]|0,D=xt[2]|0;n.fillStyle=`rgba(${At},${Jt},${D},${.12*zt})`,n.beginPath(),n.arc(j,X,et+1.2+Ts(N),0,6.28318),n.fill(),n.fillStyle=`rgba(${At},${Jt},${D},${zt})`,n.beginPath(),n.arc(j,X,et,0,6.28318),n.fill()}}if(O.render==="streamlines"||O.render==="flow"){let u=ct;if(n.lineWidth=1,n.lineCap="round",De===null||yt||$t%3===0){let f=[],v=[],S=0;for(let M=46/2;M<L;M+=46)for(let k=46/2;k<$;k+=46){let{fx:C,fy:N}=Qt(W,R.forces,B,M,k);if(yt){let j=ze(un,M,k,yt,.04);C+=j.x,N+=j.y}let P=Math.hypot(C,N);if(!(P>1e-9)){v.push({gx:M,gy:k});continue}f.push({gx:M,gy:k,ux:C/P,uy:N/P,mag:P}),P>S&&(S=P)}Vt===0?Vt=S:Vt=S>Vt?Vt*.7+S*.3:Vt*.9+S*.1,De=f,Sn=v}if(Sn.length){n.fillStyle=`rgba(${u[0]},${u[1]},${u[2]},0.05)`;for(let f of Sn)n.fillRect(f.gx-.5,f.gy-.5,1,1)}if(Vt>0&&De)for(let f of De){let v=Math.sqrt(f.mag/Vt),S=46*.46*(.28+.72*v),M=f.gx+f.ux*S,k=f.gy+f.uy*S;n.strokeStyle=`rgba(${u[0]},${u[1]},${u[2]},${pt(.1+v*.5,0,.72)})`,n.beginPath(),n.moveTo(f.gx,f.gy),n.lineTo(M,k);let C=3.4;n.moveTo(M,k),n.lineTo(M-f.ux*C-f.uy*C*.6,k-f.uy*C+f.ux*C*.6),n.moveTo(M,k),n.lineTo(M-f.ux*C+f.uy*C*.6,k-f.uy*C-f.ux*C*.6),n.stroke()}}}function Ye(o){return(o===void 0?[]:Array.isArray(o)?o:[o]).filter(c=>c!=="off")}function Wo(o,a,c){let m=ct;if(kn===null||yt||$t%3===0){let u=[],f=0;for(let v=44/2;v<L;v+=44)for(let S=44/2;S<$;S+=44){let{fx:M,fy:k}=Qt(W,R.forces,B,v,S);if(yt){let N=ze(un,v,S,yt,.04);M+=N.x,k+=N.y}let C=Math.hypot(M,k);C>1e-9&&(u.push({gx:v,gy:S,ux:M/C,uy:k/C,mag:C}),C>f&&(f=C))}Ht===0?Ht=f:Ht=f>Ht?Ht*.7+f*.3:Ht*.9+f*.1,kn=u}if(Ht<=0)return;let w={r:m[0],g:m[1],b:m[2],alpha:0,width:1.2},y=new Float64Array(12);for(let u of kn){let f=c?pt(u.mag/Ht,0,1):Math.sqrt(u.mag/Ht),v=44*.5*(.25+.75*f),S=u.gx+u.ux*v,M=u.gy+u.uy*v,k=3.6;y[0]=u.gx,y[1]=u.gy,y[2]=S,y[3]=M,y[4]=S,y[5]=M,y[6]=S-u.ux*k-u.uy*k*.6,y[7]=M-u.uy*k+u.ux*k*.6,y[8]=S,y[9]=M,y[10]=S-u.ux*k+u.uy*k*.6,y[11]=M-u.uy*k-u.ux*k*.6,w.alpha=pt(.12+f*.55,0,.8),o.segments(y,w)}}function Ni(o){let a=qr(W);if(!a.length)return;let c=Lr((w,y)=>nn(W,R.forces,w,y),a,{step:6,maxSteps:200,bounds:{w:L,h:$},loopDist:8}),g=ct,m={r:g[0],g:g[1],b:g[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,m)}}function Di(o){let c=22*O.gridWarp,g=48*.46,m=Math.floor(L/48)+2,w=Math.floor($/48)+2,y=new Float32Array(m*w),u=new Float32Array(m*w),f=0,v=new Float32Array(m*w);for(let D=0;D<w;D++)for(let U=0;U<m;U++){let{fx:nt,fy:G}=Qt(W,R.forces,B,U*48,D*48),st=Math.hypot(nt,G),Tt=D*m+U;st>1e-9&&(y[Tt]=nt/st,u[Tt]=G/st,v[Tt]=st,st>f&&(f=st))}let S=[ct,[120,110,255],[240,70,255],[255,50,130]],M=8,k=D=>f>0?Math.sqrt(v[D]/f):0,C=D=>Math.round(k(D)*M),N=D=>{let U=D/M,nt=Vn(S,U);return{r:nt[0],g:nt[1],b:nt[2],alpha:Math.min(1,O.gridIntensity*(.3+.85*U)),width:U>.55?1.4:1}},P=new Float32Array(m*w),j=new Float32Array(m*w);for(let D=0;D<m*w;D++){let U=k(D);P[D]=y[D]*U*c,j[D]=u[D]*U*c}let X=new Float32Array(m*w),dt=new Float32Array(m*w);for(let D=0;D<w;D++)for(let U=0;U<m;U++){let nt=0,G=0,st=0;for(let _t=-1;_t<=1;_t++)for(let Lt=-1;Lt<=1;Lt++){let It=U+Lt,Bt=D+_t;if(It<0||Bt<0||It>=m||Bt>=w)continue;let ge=Bt*m+It;nt+=P[ge],G+=j[ge],st++}let Tt=D*m+U;X[Tt]=nt/st,dt[Tt]=G/st}let lt=48*1.5,J=(D,U)=>{let nt=U*m+D,G=X[nt],st=dt[nt],Tt=Math.hypot(G,st);Tt>g&&(G=G/Tt*g,st=st/Tt*g);let _t=D*48,Lt=U*48,It=Math.min(_t,L-_t,Lt,$-Lt),Bt=It<=0?0:It<lt?It/lt:1;return[_t+G*Bt,Lt+st*Bt]},et=4,zt=D=>{let U=D.length>>1;if(U<3)return D;let nt=[D[0],D[1]];for(let G=0;G<U-1;G++){let st=(G>0?G-1:0)<<1,Tt=G<<1,_t=G+1<<1,Lt=(G+2<U?G+2:U-1)<<1,It=D[st],Bt=D[st+1],ge=D[Tt],$n=D[Tt+1],In=D[_t],Nn=D[_t+1],Go=D[Lt],Vo=D[Lt+1];for(let Dn=1;Dn<=et;Dn++){let Se=Dn/et,_n=Se*Se,Xo=_n*Se;nt.push(.5*(2*ge+(-It+In)*Se+(2*It-5*ge+4*In-Go)*_n+(-It+3*ge-3*In+Go)*Xo),.5*(2*$n+(-Bt+Nn)*Se+(2*Bt-5*$n+4*Nn-Vo)*_n+(-Bt+3*$n-3*Nn+Vo)*Xo))}}return nt},At=(D,U)=>Math.max(C(D*m+U),C(D*m+U+1)),Jt=(D,U)=>Math.max(C(U*m+D),C((U+1)*m+D));for(let D=0;D<w;D++){let U=At(D,0),nt=[...J(0,D),...J(1,D)];for(let G=1;G<m-1;G++){let st=At(D,G);st===U?nt.push(...J(G+1,D)):(o.polyline(zt(nt),N(U)),nt=[...J(G,D),...J(G+1,D)],U=st)}o.polyline(zt(nt),N(U))}for(let D=0;D<m;D++){let U=Jt(D,0),nt=[...J(D,0),...J(D,1)];for(let G=1;G<w-1;G++){let st=Jt(D,G);st===U?nt.push(...J(D,G+1)):(o.polyline(zt(nt),N(U)),nt=[...J(D,G),...J(D,G+1)],U=st)}o.polyline(zt(nt),N(U))}}let Rt=null;function qo(o,a,c){let w=Math.ceil(L/24)+1,y=Math.ceil($/24)+1;!Rt||Rt.length!==w*y?Rt=new Float32Array(w*y):Rt.fill(0);let u=!1;for(let k of d.particles){if(k.cap)continue;let C=a(k);C<=0||(u=!0,lo(Rt,w,y,24,k.x,k.y,42,C))}if(!u)return;let f=0;for(let k=0;k<Rt.length;k++)Rt[k]>f&&(f=Rt[k]);if(f<=0)return;let v=ct,S=[.25,.5,.78],M=[];for(let k=0;k<S.length;k++){let C=S[k]*f;M.length=0;for(let N=0;N<y-1;N++)for(let P=0;P<w-1;P++){let j=Rt[N*w+P],X=Rt[N*w+P+1],dt=Rt[(N+1)*w+P+1],lt=Rt[(N+1)*w+P],J=co(j,X,dt,lt,C);if(!J.length)continue;let et=P*24,zt=N*24;for(let At of J)M.push(et+At.x1*24,zt+At.y1*24,et+At.x2*24,zt+At.y2*24)}M.length&&o.segments(M,{r:v[0],g:v[1],b:v[2],alpha:c*(.45+.55*(k/(S.length-1))),width:1+k*.3})}}function _i(o){let m=ct,w={r:m[0],g:m[1],b:m[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<$;f+=104){let v=u,S=f;for(let M=0;M<24;M++){let{fx:k,fy:C}=Qt(W,R.forces,B,v,S);if(yt){let X=ze(un,v,S,yt,.04);k+=X.x,C+=X.y}let N=Math.hypot(k,C);if(!(N>1e-9))break;let P=v+k/N*9,j=S+C/N*9;if(P<0||j<0||P>L||j>$)break;y[0]=v,y[1]=S,y[2]=P,y[3]=j,w.alpha=.34*(1-M/24),o.segments(y,w),v=P,S=j}}}function Li(o){let a=ct;for(let c of W){if(!c.vis||!c.feedback)continue;let g=`d ${c.d.toFixed(2)}`,m=c.cx+c.hw+8,w=c.cy;o.rect(m-3,w-7,o.measureText(g)+6,14,a[0],a[1],a[2],pt(.3+c.d*.55,0,.85)),o.text(g,m,w+.5,5,6,11,.92)}}function Bi(o,a){if(o.clear(),!(!a.length||L===0||$===0))for(let c of a){c==="streamlines"?Wo(o,!1,!1):c==="force-vectors"?Wo(o,!1,!0):c==="field-lines"?Ni(o):c==="grid"?Di(o):c==="temperature"?qo(o,m=>m.heat,.5):c==="energy"?qo(o,m=>.5*m.m*(m.vx*m.vx+m.vy*m.vy),.42):c==="path"?_i(o):c==="data"&&Li(o);let g=q.get(c);g&&g(o,B,L,$)}}function Rn(o){$t++,B.t=(o-Io)/1e3,B.frameN=$t;let a=Number.isFinite(Mn)?(o-Mn)/16.6667:1;Mn=o;let c=Ft();if(B.dt=c<=0?0:pt(a,.2,2)*c,rt<1&&(rt=Math.min(1,rt+.012)),lr(B.form,So,.03),ce){let f=A.viewport();Z=f.originX??0,tt=f.originY??0}let g=A.scrollY?.()??0,m=g-we;if(B.scrollV=(B.scrollV??0)*.7+Math.abs(m)*.3,we=g,m!==0&&!ce)for(let f of W)f.cy-=m;for(let f of kt){let v=g*(.025+f.depth*.08);f.offsetY+=(v-f.offsetY)*.04}if(W.length&&$t%6===0&&(sn(W,L,$,Z,tt),p(W),_s(W,B.supernova)),B.dt!==0&&ai(),mt.length&&B.dt){let f=B.dt/60;for(let v of mt)Is(v.agent,v.from.d>.08,0,f)}let w=null;for(let f of W)if(f.on&&f.vis){w=f;break}let y=yt??w;if(wt.k+=((y?1:0)-wt.k)*.07,y){let f=yt?yt.x:w.cx,v=yt?yt.y:w.cy;wt.x=wt.x?wt.x+(f-wt.x)*.16:f,wt.y=wt.y?wt.y+(v-wt.y)*.16:v}$t%30===0&&(be=(A.scrollHeight?.()??$)-$||1);let u=Le?gt(Le):Vn($o,g/be);if(ct=[ct[0]+(u[0]-ct[0])*.08,ct[1]+(u[1]-ct[1])*.08,ct[2]+(u[2]-ct[2])*.08],O.accent=Gn(ct),d.reindex(),Ci(),ei(),B.dt&&Zr(W,d.particles),yt&&B.dt)for(let f of d.particles){if(f.cap)continue;let v=ze(un,f.x,f.y,yt,.6);f.vx+=v.x,f.vy+=v.y}if(O.waveStyle==="circular")if(O.waveCenter)se=typeof O.waveCenter=="function"?O.waveCenter():O.waveCenter;else{let f=W.find(v=>v.tokens.includes("star")||v.tokens.includes("vortex"));f?se={x:f.cx,y:f.cy}:se={x:L/2,y:$/2}}else se=null;if(pi(),W.some(f=>f.tokens.includes("relief"))?B.potential=T:B.potential&&delete B.potential,kr({store:d,bodies:W,env:B,forces:R.forces,conditions:R.conditions,waves:kt,waveStyle:O.waveStyle,waveCenter:se,separation:O.separation,restingMotion:O.restingMotion}),jt&&(jt.x=Ro,jt.y=Po,jt.vx=0,jt.vy=0,jt.heat=Math.min(1,jt.heat+.2)),B.dt){for(let f of b.values())f.step();at&&at.update(d.particles),Jr(d,Gt,Oo,kt,L,$,B.t,ht),Qr(Gt,kt,W,R.forces,L,$,B.t,f=>void d.add(ye(f))),ki(),mi()}if(Ri(),ri(),Oi(),gi(),xi(),vi(),Mi(o),it(),n&&O.render!=="none"&&Mo&&(c>0||$t%4===0)&&(Ii(),i)){let f=Ye(O.overlay);f.length&&Bi(i,f)}ne=A.raf(Rn)}function Pn(o){let a=Ee[o];a&&(So=o==="ambient"?{...xn}:{...a.preset},vn=o)}let Ge="",Ho=Io;function jo(){let o=A.viewport().height*.5,a="";A.root.querySelectorAll("[data-formation]").forEach(c=>{let g=c.getBoundingClientRect();g.top<=o&&g.bottom>=o&&(a=c.dataset.formation??"")}),a&&a!==Ge&&(Ge=a,Pn(a))}let Uo=()=>void(Ho=wn()),Wi=()=>{Uo(),jo()},Yo=setInterval(()=>{wn()-Ho>6e3&&Ge!=="ambient"&&(Ge="ambient",Pn("ambient"))},1200);Yo.unref?.();let qi=()=>Lo();Lo(),Ye(O.overlay).length&&l();let Hi=()=>{A.hidden?.()??!1?(A.cancelRaf(ne),ne=0):ne||(ne=A.raf(Rn))};A.onResize&&H.push(A.onResize(qi)),A.onScroll&&H.push(A.onScroll(Wi)),A.onVisibility&&H.push(A.onVisibility(Hi)),A.onInput&&H.push(A.onInput(Uo)),A.onBodyEvent&&(H.push(A.onBodyEvent(us,di)),H.push(A.onBodyEvent(hs,ui)),H.push(A.onBodyEvent(ys,hi))),jo(),ne=A.raf(Rn);let ie={projections:si,scan:qe,rescan:qe,setAccent:o=>{O.accent=o,ct=gt(o)},setPalette:o=>{let a=Ke(o);$o=a.map(gt);let c=a[0];c&&(O.accent=c,ct=gt(c))},setFormation:Pn,setWaveStyle:o=>{O.waveStyle=o},setWaveCenter:o=>{O.waveCenter=o},setSeparation:o=>{O.separation=o>=0?o:0},setAttention:o=>{if(O.attention=o,!o)for(let a of W)a.attn=1},setCausality:o=>{if(O.causality=o,!o)for(let a of W)a.el.style.removeProperty("--lit"),a.el.dataset.fxLit="0"},setRender:o=>{if(o!=="none"&&!n){if(n=e.getContext("2d"),!n){console.warn(`Fundamental: setRender('${o}') could not acquire a 2d context; staying in render 'none'`);return}Ye(O.overlay).length&&l(),je(A.viewport().dpr)}O.render=o},setOverlay:o=>{O.overlay=o,Ye(o).length?l():i?.clear()},setHeatmap:o=>{if(O.heatmap=o,o)!at&&L>0&&(at=new Ce(L,$));else if(at){at.clear(),at=null;for(let a of W)(a.writeTarget??a.el).style.removeProperty("--field-heatmap-density")}},setDprCap:o=>{O.dprCap=o>0?o:2,n&&je(A.viewport().dpr)},setQualityTier:o=>{let a=Math.max(0,Math.min(3,Math.floor(o||0)));a!==He&&(He=a,n&&je(A.viewport().dpr))},get policy(){return dn(Q)},setPolicy:o=>{Q=dn(o)},forAgent:o=>{let a=new Set(o.capabilities??[]),c=(o.redactions??[]).slice(),g=S=>a.has(S),m=()=>{let S=Q.budgets?.agentRead;return S==null||S>0},w=()=>{let S=Q.budgets?.agentRead;return S??1},y=(S,M)=>{if(!(M<1))return S;let k=new Set;for(let C of S.bodies)Ws(C.id,M)&&k.add(C.id);return S.bodies=S.bodies.filter(C=>k.has(C.id)),S.relationships&&(S.relationships=S.relationships.filter(C=>k.has(C.from)&&k.has(C.to))),S.influences&&(S.influences=S.influences.filter(C=>k.has(C.source)&&(C.target==null||k.has(C.target)))),S},u=(S={})=>{if(!m()){let P=ie.query({...S,include:["bodies"]});return P.metrics={},P.relationships=[],P.influences=[],g("read:projections")||(P.projections=[]),Oe(P,c)}let M=new Set(["bodies"]);g("read:metrics")&&M.add("metrics"),g("read:relationships")&&M.add("relationships"),g("read:influences")&&M.add("influences");let k=S.include?new Set(S.include):null,C=[...M].filter(P=>!k||k.has(P)),N=ie.query({...S,include:C});return g("read:metrics")||(N.metrics={}),g("read:relationships")||(N.relationships=[]),g("read:influences")||(N.influences=[]),g("read:projections")||(N.projections=[]),y(N,w()),Oe(N,c)},f=(S={})=>{if(!m()){let C=ie.snapshot({profile:"public"});return Oe(C,c)}let M={...S};g("read:body-data")||(M.includeData=!1),g("read:relationships")||(M.includeRelationships=!1),g("read:influences")||(M.includeInfluences=!1),g("read:diagnostics")||(M.includeParticles=!1);let k=ie.snapshot(M);return g("read:projections")||(k.projections=[]),y(k,w()),Oe(k,c)},v={get capabilities(){return Object.freeze([...a])},get redactions(){return Object.freeze([...c])},query:u};return g("read:snapshots")&&(v.snapshot=f),g("read:replay")&&(v.replay=(S,M,k)=>ie.replay(S,M,k)),g("read:focus")&&(v.focusState=S=>{let M=ie.focusState(S);return m()?M:{frame:M.frame,time:M.time,entries:[]}}),Object.freeze(v)},threads:On,burst:(o,a,c)=>{let g=jr;for(let m of d.particles){let w=Ur(m.x-o,m.y-a,g,6,m.z??0);w.heat!==0&&(m.vx+=w.vx,m.vy+=w.vy,w.vz&&(m.vz=(m.vz??0)+w.vz),m.heat=Math.max(m.heat,w.heat),c&&(m.color=c))}no(Gt,kt,o,a,g,L,$,B.t,m=>void d.add(ye(m))),No(o,a,2,c)},flowTo:(o,a,c)=>{yt=Dr(o,a,c)},clearFlow:()=>{yt=null},seed:o=>{We=o,Do()},atomAt:(o,a)=>{let c=null,g=1/0;for(let m of d.near(o,a,24)){if(m.atom==null)continue;let w=(m.x-o)**2+(m.y-a)**2+(m.z??0)**2;w<g&&(g=w,c=m.atom)}return c},focusAt:(o,a)=>{let c=null,g=1/0;for(let m of d.near(o,a,24)){if(m.atom==null)continue;let w=(m.x-o)**2+(m.y-a)**2+(m.z??0)**2;w<g&&(g=w,c=m)}return jt=c,c?(Ro=c.x,Po=c.y,c.atom??null):null},clearFocus:()=>{jt=null},particleCount:()=>d.size,readParticles:o=>{let a=d.particles,c=Math.floor(o.length/5),g=0;for(let m=0;m<a.length&&g<c;m++){let w=a[m];if(w.report!==void 0)continue;let y=g*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,g++}return g},readParticleIds:o=>{let a=d.particles,c=0;for(let g=0;g<a.length&&c<o.length;g++){let m=a[g];m.report===void 0&&(o[c++]=m.id??0)}return c},readParticleChannels:(o,a)=>{let c=d.particles,g=0;for(let m=0;m<c.length;m++){let w=c[m];if(!("report"in w&&w.report!==void 0)){if(g>=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][g]=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}g++}}return g},registerOverlay:(o,a)=>(q.set(o,a),()=>{q.delete(o)}),addAgent:o=>{let a=ye({x:o.x,y:o.y,z:o.z,species:o.species});return a.vx=0,a.vy=0,o.z===void 0&&O.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),o.potential!=null&&(a["data-potential"]=o.potential),o.absorbR!=null&&(a["data-absorb"]=String(o.absorbR));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:()=>({})}},g={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:()=>""}},m=Te(g);m.rect=c,m.data=o.data,o.identity!=null&&(m.identity=typeof o.identity=="string"?{id:o.identity}:o.identity),o.authority&&(m.authority=o.authority),m.feedback=!0;let w={};m.onFeedback=u=>{Object.assign(w,u),o.onFeedback?.(u)},Et.push(m),W=W.concat(m),sn([m],L,$,Z,tt);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,g.dataset.color=u.color,m.tint=u.color)},remove:()=>{let u=Et.indexOf(m);u>=0&&Et.splice(u,1),W=W.filter(f=>f!==m);for(let f=mt.length-1;f>=0;f--){let v=mt[f];(v.from===m||v.to===m)&&mt.splice(f,1)}}};return Zt.set(y,m),y},addEdge:(o,a,c)=>{let g=Zt.get(o),m=Zt.get(a);if(!g||!m)throw new Error("addEdge: both arguments must be handles returned by addBody on this field.");let w={id:`e${Pe++}`,from:"",to:"",type:c?.type??"related",strength:c?.strength??.5,tension:0,memory:0,active:!1},y={agent:w,from:g,to:m,fromData:o.data,toData:a.data};return mt.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=mt.indexOf(y);u>=0&&mt.splice(u,1)}}},readEdges:()=>mt.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,g=0,m=0,w=0,y=!1;a&&("width"in a?(c={x:a.x,y:a.y,width:a.width,height:a.height},g=a.x+a.width/2,m=a.y+a.height/2,w=Math.max(a.width,a.height)/2):(w=o.radius??240,g=a.x,m=a.y,c={x:g-w,y:m-w,width:w*2,height:w*2}),y=!0);let u=new Set(o.include??(y?["bodies","metrics","relationships","influences"]:["bodies","metrics","relationships"])),f=P=>{if(!P.vis)return!1;if(!y)return!0;if("width"in a){let j=c;return P.cx>=j.x&&P.cx<=j.x+j.width&&P.cy>=j.y&&P.cy<=j.y+j.height}return Math.hypot(P.cx-g,P.cy-m)<=w},v=W.filter(f),S=u.has("bodies")?v.map(P=>{let{metrics:j,dimensions:X}=Fo(P),dt=bn(P);return{id:dt.id,identity:dt,rect:{x:P.cx-P.hw,y:P.cy-P.hh,width:P.hw*2,height:P.hh*2},tokens:P.tokens.slice(),metrics:j,dimensions:X,activeFormations:[vn],authority:P.authority??"anchored"}}):[],M={};if(u.has("metrics")&&(M.particles=d.size,M.bodies=v.length,v.length>0)){let P=0;for(let j of v)P+=j.d;M.meanDensity=P/v.length}let k=u.has("relationships")?mt.filter(P=>!y||f(P.from)||f(P.to)).map(P=>({from:oe(P.from),to:oe(P.to),type:P.agent.type,strength:P.agent.strength,memory:P.agent.memory,active:P.agent.active,causal:P.agent.active})):[],C=[];if(u.has("influences")&&y)for(let P of v){if(P.tokens.length===0)continue;let j=go(R.forces,P.tokens,P,g,m);for(let X of j.attribution)C.push({source:oe(P),force:X.force,channel:X.channel,contribution:X.contribution})}let N={query:o,frame:B.frameN,time:B.t,region:c,bodies:S,metrics:M,relationships:k,influences:C,projections:Ie()};return o.lens?Nr(N,o.lens):N},snapshot:(o={})=>{let a=Hs(o),c=a.includeRelationships,g=W.filter(f=>f.vis),m=g.map(f=>{let{metrics:v,dimensions:S}=Fo(f),M=bn(f),k={id:M.id,identity:M,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:v,dimensions:S};return a.includeData&&ee()&&(k.data=ci(f.data)),k}),w=c?mt.map(f=>({from:oe(f.from),to:oe(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:g.length};if(g.length>0){let f=0;for(let v of g)f+=v.d;y.meanDensity=f/g.length}let u={id:`snap-${B.frameN}-${ni++}`,createdAt:B.t,frame:B.frameN,version:Ve,formations:[vn],bodies:m,relationships:w,metrics:y,projections:Ie()};if(a.includeParticles){let f=[];for(let v of d.particles)v.cap||f.push({x:v.x,y:v.y,z:v.z??0,heat:v.heat,size:v.size});u.particles=f}if(a.includeInfluences){let f=[];for(let v of g){if(v.tokens.length===0)continue;let S=go(R.forces,v.tokens,v,v.cx+8,v.cy);for(let M of S.attribution)f.push({source:oe(v),force:M.force,channel:M.channel,contribution:M.contribution})}u.influences=f}return u},diff:(o,a)=>Xn(o,a),replay:(o,a,c)=>cr(o,a,c),addField:(o,a)=>(Nt.set(o,a),F(),{name:o,set:c=>{Nt.set(o,c),F()},remove:()=>{Nt.delete(o),b.delete(z(o)),E.delete(z(o)),F()}}),sampleField:(o,a,c)=>{let g=Nt.get(o);return g?g(a,c):0},energy:()=>qs(d.particles),sample:(o,a)=>{let{fx:c,fy:g}=Qt(W,R.forces,B,o,a);return{x:c,y:g}},sampleScalar:(o,a)=>at?at.norm(o,a):(so("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)=>at?at.gradient(o,a):(so("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=>B.grid(o),focus:(o,a)=>Zs(o,a),focusState:o=>ti(o),on:(o,a)=>{let c=_.get(o);return c||(c=new Set,_.set(o,c)),c.add(a),()=>void c.delete(a)},version:Ve,guarantees:{determinism:"conditionally-deterministic",controlledInputs:["injected-rng","clock"],uncontrolledInputs:["host-geometry","body-ordering"],requirements:["inject the rng","dt === 1 for cross-run equivalence","identical host geometry"],crossPlaneTolerance:1e-6},scrollV:()=>B.scrollV??0,setVisible:o=>{Mo=o},setBackground:o=>{O.background=o,o==="transparent"&&n&&n.clearRect(0,0,L,$)},destroy:()=>{A.cancelRaf(ne),clearInterval(Yo);for(let o of H)o();for(let o of he)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;he=[];for(let o of Xt)(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 de)for(let a of o.emitted)a.remove();de=[],d.clear(),A.detach?.()}};return ie}var yn={};function pn(){return yn.reducedMotion!==void 0?yn.reducedMotion:typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function mn(){return yn.hidden!==void 0?yn.hidden:typeof document<"u"&&document.hidden}var qc=["--field-density","--d"],Us=!1;function Ys(){if(Us)return[];Us=!0;let e=globalThis.CSS;if(!e||typeof e.registerProperty!="function")return[];let t=[];for(let n of qc)try{e.registerProperty({name:n,syntax:"<number>",inherits:!0,initialValue:"0"}),t.push(n)}catch{}return t}var Gs=["pointerdown","wheel","keydown","touchstart"];function Re(){return Ys(),{root:document,viewport:()=>({width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio||1}),scrollY:()=>window.scrollY||0,scrollHeight:()=>document.documentElement.scrollHeight,reducedMotion:()=>pn(),hidden:()=>mn(),raf:e=>requestAnimationFrame(e),cancelRaf:e=>cancelAnimationFrame(e),createCanvas:()=>document.createElement("canvas"),onResize:e=>(window.addEventListener("resize",e,{passive:!0}),()=>window.removeEventListener("resize",e)),onScroll:e=>(window.addEventListener("scroll",e,{passive:!0}),()=>window.removeEventListener("scroll",e)),onVisibility:e=>(document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)),onInput:e=>{for(let t of Gs)window.addEventListener(t,e,{passive:!0});return()=>{for(let t of Gs)window.removeEventListener(t,e)}},onBodyEvent:(e,t)=>(document.addEventListener(e,t),()=>document.removeEventListener(e,t))}}var Vs=["pointerdown","wheel","keydown","touchstart"];function Xs(e){return e.setAttribute(ve,""),{root:e,detach:()=>e.removeAttribute(ve),viewport:()=>{let t=e.getBoundingClientRect();return{width:t.width,height:t.height,dpr:window.devicePixelRatio||1,originX:t.left,originY:t.top}},scrollY:()=>e.scrollTop,scrollHeight:()=>e.scrollHeight,reducedMotion:()=>pn(),hidden:()=>mn(),raf:t=>requestAnimationFrame(t),cancelRaf:t=>cancelAnimationFrame(t),createCanvas:()=>document.createElement("canvas"),onResize:t=>{let n=new ResizeObserver(t);return n.observe(e),window.addEventListener("resize",t,{passive:!0}),()=>{n.disconnect(),window.removeEventListener("resize",t)}},onScroll:t=>(e.addEventListener("scroll",t,{passive:!0}),window.addEventListener("scroll",t,{passive:!0}),()=>{e.removeEventListener("scroll",t),window.removeEventListener("scroll",t)}),onVisibility:t=>(document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)),onInput:t=>{for(let n of Vs)e.addEventListener(n,t,{passive:!0});return()=>{for(let n of Vs)e.removeEventListener(n,t)}},onBodyEvent:(t,n)=>(e.addEventListener(t,n),()=>e.removeEventListener(t,n))}}function Ks(e,t={}){return hn(e,{...t,host:Re()})}function xo(e,t={}){let{host:n,bounds:r,...s}=t,i=n??(r?Xs(r):Re());return hn(e,{...s,host:i})}function vo(){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 gn(e=document.body){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText=Rs,e.appendChild(t),t}function Js(e){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(e).position==="static"&&(e.style.position="relative"),e.appendChild(t),t}function Hc(e={}){vo();let{target:t=document.body,...n}=e,r=gn(t),s=Ks(r,n);return{...s,destroy:()=>{s.destroy(),r.remove()}}}var bo=class{constructor(t={}){Y(this,"canvas");Y(this,"field");Y(this,"managed");vo();let{canvas:n,target:r,bounds:s,...i}=t;this.managed=!n,this.canvas=n??(s?Js(s):gn(r)),this.field=xo(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,n,r){this.field.burst(t,n,r)}flowTo(t,n,r){this.field.flowTo(t,n,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,n,r){return this.field.addEdge(t,n,r)}readEdges(){return this.field.readEdges()}query(t){return this.field.query(t)}snapshot(t){return this.field.snapshot(t)}diff(t,n){return this.field.diff(t,n)}replay(t,n,r){return this.field.replay(t,n,r)}get projections(){return this.field.projections}addField(t,n){return this.field.addField(t,n)}sampleField(t,n,r){return this.field.sampleField(t,n,r)}atomAt(t,n){return this.field.atomAt(t,n)}focusAt(t,n){return this.field.focusAt(t,n)}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,n){return this.field.readParticleChannels(t,n)}registerOverlay(t,n){return this.field.registerOverlay(t,n)}energy(){return this.field.energy()}sample(t,n){return this.field.sample(t,n)}sampleScalar(t,n){return this.field.sampleScalar(t,n)}sampleGradient(t,n){return this.field.sampleGradient(t,n)}grid(t){return this.field.grid(t)}focus(t,n){this.field.focus(t,n)}focusState(t){return this.field.focusState(t)}on(t,n){return this.field.on(t,n)}get version(){return this.field.version}get guarantees(){return this.field.guarantees}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{Qo as CONDITIONS,Ve as FIELD_VERSION,Bn as FORCES,Jo as FORMATIONS,bo as FieldField,Wn as PALETTE,Re as browserHost,xo as createField,$s as cssFeedbackSink,Cc as headlessHost,gn as makeFieldCanvas,Hc as mountField};
|