@fundamental-engine/vanilla 0.9.0 → 0.9.1
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
|
@@ -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
|
-
"use strict";var Fundamental=(()=>{var Ee=Object.defineProperty;var ps=Object.getOwnPropertyDescriptor;var ms=Object.getOwnPropertyNames;var gs=Object.prototype.hasOwnProperty;var xs=(e,t,n)=>t in e?Ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var vs=(e,t)=>{for(var n in t)Ee(e,n,{get:t[n],enumerable:!0})},ws=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ms(t))!gs.call(e,s)&&s!==n&&Ee(e,s,{get:()=>t[s],enumerable:!(o=ps(t,s))||o.enumerable});return e};var bs=e=>ws(Ee({},"__esModule",{value:!0}),e);var U=(e,t,n)=>xs(e,typeof t!="symbol"?t+"":t,n);var ea={};vs(ea,{CONDITIONS:()=>xn,FIELD_VERSION:()=>ke,FORCES:()=>Se,FORMATIONS:()=>gn,FieldField:()=>je,PALETTE:()=>ze,browserHost:()=>ee,createField:()=>Ve,cssFeedbackSink:()=>Rn,headlessHost:()=>fr,makeFieldCanvas:()=>fe,mountField:()=>Rr});var ke="0.9.0";var Se=[{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"}],lo=Object.fromEntries(Se.map(e=>[e.id,e])),ze=Se.map(e=>e.color),ie=["#4da3ff","#2dd4bf","#a78bfa","#ff6e9c","#ff9d5c"],yn=["spotlight","screen","resonate"],Ms=["spawn"],pn=300,mn=120;function Es(e){return yn.includes(e)?"modifier":Ms.includes(e)?"source":"force"}function Te(e){let t=[],n=[],o=[];for(let s of e){let i=Es(s);i==="modifier"?t.push(s):i==="source"?o.push(s):n.push(s)}return t.length>1&&t.sort((s,i)=>yn.indexOf(s)-yn.indexOf(i)),{modifiers:t,forces:n,sources:o}}var gn=[{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}}],Fe=Object.fromEntries(gn.map(e=>[e.id,e]));var xn=[{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}],sa=Object.fromEntries(xn.map(e=>[e.id,e]));var ks={ours:ie,heatmap:["#2b3a8c","#2d8fd4","#3fd07a","#ffe14d","#ff8a3d","#e23b3b"],infrared:["#2a0a4a","#8e24aa","#e53935","#ff8f00","#ffd54f","#fffde7"],spectrum:["#ff3b30","#ff9500","#ffcc00","#34c759","#00c7be","#007aff","#af52de"]};function Ae(e){return Array.isArray(e)?e.length>0?e:ie:typeof e=="string"?ks[e]??ie:ie}var vn={warm:{cool:[255,224,200],warm:[255,110,80],wave:["#ff8a5c","#f0628e","#ffc46b"]},cool:{cool:[206,226,255],warm:[74,132,255],wave:["#5c8aff","#62a0f0","#6bc4ff"]},mono:{cool:[232,232,238],warm:[148,148,158],wave:["#8a8a96","#b0b0bc","#9a9aa6"]}},wn="warm";var wt=(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,o=Number.parseInt(n.slice(0,6),16);return Number.isNaN(o)?[77,163,255]:[o>>16&255,o>>8&255,o&255]}var Ss=[255,224,200],zs=[255,110,80];function fo(e,t,n,o,s=Ss,i=zs){let a=s[0]+(i[0]-s[0])*t,f=s[1]+(i[1]-s[1])*t,y=s[2]+(i[2]-s[2])*t;return a+=(o[0]-a)*n,f+=(o[1]-f)*n,y+=(o[2]-y)*n,e[0]=a,e[1]=f,e[2]=y,e}function bn([e,t,n]){let o=s=>wt(Math.round(s),0,255).toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(n)}`}function ho(e,t,n){let[o,s,i]=gt(e),[a,f,y]=gt(t),p=n<0?0:n>1?1:n;return bn([o+(a-o)*p,s+(f-s)*p,i+(y-i)*p])}function Mn(e,t){if(e.length===0)return[77,163,255];if(e.length===1)return e[0];let n=wt(t,0,1)*(e.length-1),o=Math.min(e.length-2,Math.floor(n)),s=n-o,i=e[o],a=e[o+1];return[i[0]+(a[0]-i[0])*s,i[1]+(a[1]-i[1])*s,i[2]+(a[2]-i[2])*s]}function uo(e,t,n,o=0){if(!(t>0))return 1;let s=Math.max(0,1-e/t),i=1-n*s*s,a=Math.min(Math.max(o,0),1);return i<a?a:i>1?1:i}var Ce=1;function Pe(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,o=Math.min(t,n),s=e.ux*o,i=e.uy*o,a=e.spin<0?-1:1;return[{x:e.cx+s,y:e.cy+i,q:a},{x:e.cx-s,y:e.cy-i,q:-a}]}function yo(e,t,n){let o=0,s=0;for(let i of e){let a=t-i.x,f=n-i.y,y=Math.max(Ce,Math.hypot(a,f)),p=i.q/(y*y);o+=a/y*p,s+=f/y*p}return{x:o,y:s}}function po(e,t){let n=e/20+(t?.45:0);return n<0?0:n>1?1:n}function mo(e,t,n){return Math.round(e+(t-e)*n)}function go(e,t={}){let n=t.beta??2,o=t.lo??.25,s=t.hi??3,i=e.length,a=new Array(i).fill(1);if(i===0)return a;let f=0,y=0;for(let v of e){let b=v.strength>0?v.strength:0;f+=b,y+=b*(1+(v.on?n:0))}if(f<=0||y<=0)return a;let p=f/y;for(let v=0;v<i;v++){let E=(1+(e[v].on?n:0))*p;E<o?E=o:E>s&&(E=s),a[v]=E}return a}function xo(e,t={}){let n=t.threshold??.55,o=t.kappa??.6,s=t.falloff??320,i=e.length,a=new Array(i).fill(0);if(i<2)return a;let f=new Array(i).fill(0);for(let y=0;y<i;y++){let p=e[y],v=p.d-n;if(v<=0)continue;let b=0;for(let z=0;z<i;z++){if(z===y){f[z]=0;continue}let F=e[z],R=Math.hypot(p.cx-F.cx,p.cy-F.cy),B=R<s?1-R/s:0;f[z]=B,b+=B}if(b<=0)continue;let E=o*v;for(let z=0;z<i;z++){let F=f[z];if(F<=0)continue;let R=E*F/b;a[z]+=R,a[y]-=R}}return a}var Ht={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null};function Zt(e,t,n,o,s){Ht.x=o,Ht.y=s,Ht.vx=0,Ht.vy=0,Ht.heat=0;let i=0,a=0;for(let f of e){if(!f.vis||f.tokens.length===0)continue;let y,p;if(f.shaped){let E=f.cx-f.hw,z=f.cx+f.hw,F=f.cy-f.hh,R=f.cy+f.hh;y=(o<E?E:o>z?z:o)-o,p=(s<F?F:s>R?R:s)-s}else y=f.cx-o,p=f.cy-s;let v=y*y+p*p;if(f.range>0&&v>=f.range*f.range*2.56)continue;let b=Math.sqrt(v);n.dx=y,n.dy=p,n.dist=b<1?1:b;for(let E of f.tokens){let z=t[E];if(!(!z||z.modify))if(z.field){let F=z.field(f,o,s);i+=F.x,a+=F.y}else z.apply(f,Ht,n)}}return{fx:Ht.vx+i,fy:Ht.vy+a}}function Oe(e,t,n,o){let s=0,i=0;for(let a of e)if(!(!a.vis||a.tokens.length===0)){if(a.range>0){let f=a.cx-n,y=a.cy-o;if(f*f+y*y>=a.range*a.range*2.56)continue}for(let f of a.tokens){let y=t[f];if(y?.field){let p=y.field(a,n,o);s+=p.x,i+=p.y}}}return{x:s,y:i}}function vo(e,t,n={}){return{x:e,y:t,strength:n.strength??1,radius:n.radius&&n.radius>0?n.radius:360}}function ae(e,t,n,o,s=.6){let i=o.x-t,a=o.y-n,f=Math.hypot(i,a);if(f===0||f>=o.radius)return e.x=0,e.y=0,e;let y=(1-f/o.radius)*o.strength*s;return e.x=i/f*y,e.y=a/f*y,e}var Ts={step:6,maxSteps:400,minStrength:1e-9,loopDist:6,maxTurns:1/0};function wo(e,t,n,o,s){let i=[{x:t,y:n}],a=t,f=n,y=s.step,p=s.maxTurns*2*Math.PI,v=0,b=0,E=0;for(let z=0;z<s.maxSteps;z++){let F=e(a,f),R=Math.hypot(F.x,F.y);if(!(R>=s.minStrength))break;let B=F.x/R*o,N=F.y/R*o;if(Number.isFinite(p)){if(v!==0||b!==0){let X=Math.max(-1,Math.min(1,B*v+N*b));if(E+=Math.acos(X),E>p)break}v=B,b=N}if(a+=B*s.step,f+=N*s.step,s.bounds&&(a<-y||f<-y||a>s.bounds.w+y||f>s.bounds.h+y))break;if(z>4&&Math.hypot(a-t,f-n)<s.loopDist){i.push({x:a,y:f});break}i.push({x:a,y:f})}return i}function Fs(e,t,n,o={}){let s={...Ts,bounds:o.bounds,...o},i=wo(e,t,n,-1,s),a=wo(e,t,n,1,s);return i.reverse(),i.pop(),i.concat(a)}function bo(e,t,n={}){return t.map(o=>Fs(e,o.x,o.y,n)).filter(o=>o.length>1)}var As=8,Cs=60;function Mo(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},o=Pe(n),s=Math.hypot(o[0].x-o[1].x,o[0].y-o[1].y);if(s<Math.max(e.range*.06,As)){let p=Math.max(e.range*.18,Cs),v=e.spin<0?-1:1;o=[{x:e.cx+e.ux*p,y:e.cy+e.uy*p,q:v},{x:e.cx-e.ux*p,y:e.cy-e.uy*p,q:-v}],s=Math.hypot(o[0].x-o[1].x,o[0].y-o[1].y)}let i=-e.uy,a=e.ux,f=Math.max(s*.13,18),y=[{x:e.cx,y:e.cy}];for(let p=1;p<=t;p++){let v=p*f;y.push({x:e.cx+i*v,y:e.cy+a*v}),y.push({x:e.cx-i*v,y:e.cy-a*v})}return y}function Eo(e,t=18){let n=Math.max(Math.min(e.hw,e.hh)*.8,24),o=[];for(let s=0;s<t;s++){let i=s/t*Math.PI*2;o.push({x:e.cx+Math.cos(i)*n,y:e.cy+Math.sin(i)*n})}return o}function ko(e,t=8){let n=[];for(let o of e)!o.vis||o.tokens.length===0||(o.tokens.includes("magnetism")?n.push(...Mo(o,t)):(o.tokens.includes("charge")||o.tokens.includes("gravity"))&&n.push(...Eo(o)));return n}function So(e,t=Math.random){return 3+Math.floor(t()*(e>0?e:1)*3)}function zo(e,t,n,o=6,s=0){let i=Math.hypot(e,t,s)||1;if(i>=n)return{vx:0,vy:0,vz:0,heat:0};let a=1-i/n,f=a*o;return{vx:e/i*f,vy:t/i*f,vz:s/i*f,heat:a*.9}}function To(e,t,n,o,s=.9,i=80){let a=o>0?o:1;e.vx=(e.vx+t/a)*s,e.vy=(e.vy+n/a)*s,e.x+=e.vx,e.y+=e.vy;let f=Math.hypot(e.x,e.y);f>i&&(e.x=e.x/f*i,e.y=e.y/f*i)}function Fo(e,t=.02){return{x:-e.x*t,y:-e.y*t}}function Ao(e){let t=e/3e4;return t<.6?.6:t>6?6:t}function Co(e,t,n=-1,o=1600,s=26){let i=0,a=0,f=s*s;for(let y=0;y<t.length;y++){if(y===n)continue;let p=t[y],v=e.x-p.x,b=e.y-p.y,E=v*v+b*b+f;i+=o*v/E,a+=o*b/E}return{x:i,y:a}}function Po(e,t,n,o=16,s=1){let i=(e(t+o,n)-e(t-o,n))/(2*o),a=(e(t,n+o)-e(t,n-o))/(2*o);return{x:-i*s,y:-a*s}}var Ps=[.24,.4,.55,.7,.85];function Oo(e){let t=[];for(let n=0;n<5;n++)t.push({baseFrac:Ps[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 Ro(e,t,n){let o=Math.round(16*t),s=[];for(let i=0;i<e;i++)for(let a=0;a<o;a++)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 Et(e,t,n,o,s=1,i=1,a){let f=e.baseFrac*o+e.offsetY+Math.sin(t*e.freq+e.phase+n*e.speed*1e3*s)*e.amp*i;if(a&&a.k>.001){let y=t-a.x,p=260,v=Math.exp(-(y*y)/(2*p*p));f+=(a.y-f)*.42*v*a.k*(.45+e.depth*.55)}return f}function $o(e,t,n,o=1,s=1){return Math.cos(t*e.freq+e.phase+n*e.speed*1e3*o)*e.amp*e.freq*s}function ce(e,t,n,o,s=1,i=1){let a=e.baseFrac*o+e.offsetY,f=Math.max(1,Math.round(e.freq*2500));return a+Math.sin(f*t+e.phase+n*e.speed*1e3*s)*e.amp*i}function Io(e,t,n,o,s,i,a,f,y=1,p=1,v){if(a==="circular"){let b=t-f.x,E=n-f.y,z=Math.sqrt(b*b+E*E)||.001,F=Math.atan2(E,b),R=Math.min(s,i)*.48,B=ce(e,F,o,R,y,p);return{dist:Math.abs(z-B),rWave:B,r:z,theta:F}}else{let b=Et(e,t,o,i,y,p,v);return{dist:Math.abs(n-b),rWave:b,r:n,theta:0}}}function No(e,t,n,o,s,i,a,f){if(o.length===0)return;let y=e.particles;for(let p=y.length-1;p>=0&&!(t.length>=n);p--){let v=y[p];if(!v||v.cap||v.heat>=.12)continue;let b=-1,E=1e9,z=0;for(let R=0;R<o.length;R++){let B=Et(o[R],v.x,a,i),N=Math.abs(B-v.y);N<E&&(E=N,b=R,z=B)}if(b<0||E>=64)continue;let F=Math.min(.012,E*4e-4)*(1-v.heat/.12);v.vy+=z>v.y?F:-F,E<20&&v.vx*v.vx+v.vy*v.vy<.3&&f()<.03&&(t.push({wi:b,progress:v.x/s,phase:(f()-.5)*.22*Math.PI,size:v.size,glow:f()<.3,speed:(35e-5+f()*9e-4)*(f()<.5?1:-1)}),e.remove(v))}}function En(e,t,n,o,s,i,a,f,y){for(let p=e.length-1;p>=0;p--){let v=e[p];if(!v)continue;let b=t[v.wi];if(!b)continue;let E=v.progress*i,z=Et(b,E,f,a)+v.phase*32,F=E-n,R=z-o,B=Math.hypot(F,R);if(B<s&&B>.5){let N=(1-B/s)*4;y({x:E,y:z,vx:F/B*N,vy:R/B*N,size:v.size,heat:.9});let X=e.pop();X&&p<e.length&&(e[p]=X)}}}function Lo(e,t,n,o,s,i,a,f){let y=p=>p.tokens.some(v=>{let b=o[v];return!!b&&!b.modify&&!b.source});for(let p=e.length-1;p>=0;p--){let v=e[p];if(!v)continue;let b=t[v.wi];if(!b)continue;let E=v.progress*s,z=Et(b,E,a,i)+v.phase*32,F=!1,R=0,B=0;for(let N of n){if(!N.vis||N.when==="active"&&!N.on||N.when&&N.when!=="active")continue;let X=N.tokens,u=N.cx-E,Z=N.cy-z,it=Math.hypot(u,Z)||1,lt=N.range*(N.on?1.4:1);if(X.indexOf("wall")>=0&&Math.abs(E-N.cx)<N.hw+6&&Math.abs(z-N.cy)<N.hh+6&&(R=(E<N.cx?-1:1)*1.6,B=(z<N.cy?-1:1)*.8,F=!0),!F&&(X.indexOf("attract")>=0||X.indexOf("sink")>=0||X.indexOf("jet")>=0)&&it<lt*.8){let D=1.2+(N.on?1.6:0);R=u/it*D,B=Z/it*D,F=!0}if(!F&&X.indexOf("repel")>=0&&it<lt*.8){let D=1.2+(N.on?1.2:0);R=-(u/it)*D,B=-(Z/it)*D,F=!0}if(!F&&X.indexOf("swirl")>=0&&it<lt*.75&&(R=Z/it*1.2,B=-(u/it)*1.2,F=!0),!F&&X.indexOf("stream")>=0&&it<lt*.75&&(R=N.ux*1.3,B=N.uy*1.3,F=!0),!F&&it<lt*.8&&y(N)){let D=.8+(N.on?.8:0);R=u/it*D,B=Z/it*D,F=!0}if(F)break}if(F){f({x:E,y:z,vx:R,vy:B,size:v.size,heat:.5});let N=e.pop();N&&p<e.length&&(e[p]=N)}}}function Do(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 o=n.range*n.range;for(let s of t){if(s.charge)continue;let i=n.cx-s.x,a=n.cy-s.y;i*i+a*a>=o||(s.charge=i>=0?1:-1)}}}var Re=class{constructor(t=64){U(this,"cell");U(this,"bins",new Map);this.cell=t>0?t:64}key(t,n){return(t+32768)*65536+(n+32768)}clear(){this.bins.clear()}insert(t){let n=this.key(Math.floor(t.x/this.cell),Math.floor(t.y/this.cell)),o=this.bins.get(n);o?o.push(t):this.bins.set(n,[t])}rebuild(t){this.clear();for(let n of t)this.insert(n)}near(t,n,o,s=0){let i=[],a=o*o,f=Math.floor((t-o)/this.cell),y=Math.floor((t+o)/this.cell),p=Math.floor((n-o)/this.cell),v=Math.floor((n+o)/this.cell);for(let b=f;b<=y;b++)for(let E=p;E<=v;E++){let z=this.bins.get(this.key(b,E));if(z)for(let F of z){let R=F.x-t,B=F.y-n,N=(F.z??0)-s;R*R+B*B+N*N<=a&&i.push(F)}}return i}};var _o=e=>e<0?0:e>1?1:e;function Bo(e){if(!e||e.n===0)return{entropy:0,coherence:1,temperature:0};let t=e.sh/e.n,n=e.ss/e.n,o=e.ss2/e.n,s=_o(.5*t+.5*Math.min(1,o/9)),i=e.ss>1e-9?Math.hypot(e.sx,e.sy)/e.ss:1,a=_o((1-i)*Math.min(1,n/1.5));return{entropy:a,coherence:1-a,temperature:s}}var $e=class{constructor(t=64){U(this,"particles",[]);U(this,"hash");this.hash=new Re(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 o=this.particles.pop();o&&n<this.particles.length&&(this.particles[n]=o)}clear(){this.particles.length=0,this.hash.clear()}reindex(){this.hash.rebuild(this.particles)}neighbors(t,n){let o=this.hash.near(t.x,t.y,n,t.z??0),s=[];for(let i of o)i!==t&&s.push(i);return s}near(t,n,o){return this.hash.near(t,n,o)}};var Wo={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};var Ie=class{constructor(){U(this,"pending",new Map);U(this,"ids",new WeakMap);U(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==="met"){let s=n,[i,a]=[this.idOf(s.a.el??s.a),this.idOf(s.b.el??s.b)].sort((f,y)=>f-y);return`${i}:${a}`}if(t==="enter"||t==="exit"){let s=n;return`${this.idOf(s.body.el??s.body)}:${this.idOf(s.other.el??s.other)}`}let o=n;return String(this.idOf(o.body.el??o.body))}record(t,n){let o=this.pending.get(t);o||this.pending.set(t,o=new Map),o.set(this.keyOf(t,n),n)}flush(t){if(this.pending.size!==0){for(let[n,o]of this.pending)for(let s of o.values())t(n,s);this.pending.clear()}}};function kn(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 Sn(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}}function Ho(){let e={},t={...Wo};return{forces:e,conditions:t,force(n){e[n.token]=n},condition(n,o){t[n]=o}}}function qo(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 Yo(e){for(let t of e)if(t.vis&&t.tokens.indexOf("sink")>=0)return t;return null}var zn=.95,Os=.972,St=10;function Rs(e,t,n,o){if(!t.when)return!0;let s=e[t.when];return s?s(t,n,o):!0}function Uo(e){return e.classified??(e.classified=Te(e.tokens))}function Tn(e,t,n,o,s){if(s===1||e.kinematic){e.apply(t,n,o);return}let i=n.vx,a=n.vy,f=n.vz??0;e.apply(t,n,o),n.vx=i+(n.vx-i)*s,n.vy=a+(n.vy-a)*s,n.vz!==void 0&&(n.vz=f+(n.vz-f)*s)}function Go(e){let{store:t,bodies:n,env:o,forces:s,conditions:i,waves:a,separation:f}=e,y=o.dt;if(y===0)return;let{W:p,H:v,form:b}=o;o.fieldAt=(u,Z)=>Oe(n,s,u,Z);for(let u of n){u.count=0;let Z=u.thermo;Z&&(Z.n=0,Z.sx=0,Z.sy=0,Z.ss=0,Z.ss2=0,Z.sh=0)}let E=null;for(let u of n)u.vis&&u.tokens.length>0&&Uo(u).modifiers.indexOf("screen")>=0&&(E??(E=[])).push(u);let z=E?new Array(E.length):null,F=!!a&&a.length>0,R=n.length>0,B=null,N=b.conv>.02?Yo(n):null,X=o.D??0;for(let u of t.particles){if(u.cap){u.x+=(u.cap.cx-u.x)*.18,u.y+=(u.cap.cy-u.y)*.18,u.z&&(u.z+=-u.z*.18);continue}u.z===void 0&&(u.z=0),u.vz===void 0&&(u.vz=0);let Z=u.z;if(F)if(e.waveStyle==="circular"){let D=null,A=1e9,j=0,J=0,dt=0,_=e.waveCenter||{x:p/2,y:v/2};for(let tt of a){let yt=Io(tt,u.x,u.y,o.t,p,v,"circular",_);yt.dist<A&&(A=yt.dist,D=tt,j=yt.r,J=yt.rWave,dt=yt.theta)}if(D&&A<70){let tt=1-A/70,yt=-Math.sin(dt)*D.dir,Rt=Math.cos(dt)*D.dir;u.vx+=yt*.035*tt,u.vy+=Rt*.035*tt;let O=Math.cos(dt)*Math.sign(J-j),K=Math.sin(dt)*Math.sign(J-j);u.vx+=O*.05*tt,u.vy+=K*.05*tt}}else{let D=null,A=1e9;for(let j of a){let J=Math.abs(Et(j,u.x,o.t,v)-u.y);J<A&&(A=J,D=j)}D&&A<70&&(u.vx+=D.dir*.035*(1-A/70),u.vy+=$o(D,u.x,o.t)*.1*(1-A/70))}if(b.driftX&&(u.vx+=b.driftX*.02),b.spread>.02){let D=u.gx??.5,A=u.gy??.5,j=(D+o.frameN*4e-5)%1*p,J=A*v;u.vx+=(j-u.x)*6e-4*b.spread,u.vy+=(J-u.y)*6e-4*b.spread,X>0&&(u.vz+=((u.gz??.5)*X-Z)*6e-4*b.spread)}if(N){let D=N.cx-u.x,A=N.cy-u.y,j=-Z,J=Math.hypot(D,A,j)||1;u.vx+=D/J*b.conv*.06,u.vy+=A/J*b.conv*.06,u.vz+=j/J*b.conv*.06}if(R){if(E)for(let A=0;A<E.length;A++){let j=E[A],J=j.cx-u.x,dt=j.cy-u.y;z[A]=uo(Math.sqrt(J*J+dt*dt),j.range,j.strength,j.screenMin??0)}let D=u.m!==1&&u.m>0?1/u.m:1;for(let A of n){if(!A.vis||A.tokens.length===0||A.affects!==void 0&&!A.affects.has(u.species??0))continue;let j,J;if(A.shaped){let Y=A.cx-A.hw,Q=A.cx+A.hw,at=A.cy-A.hh,Ut=A.cy+A.hh,ne=u.x<Y?Y:u.x>Q?Q:u.x,he=u.y<at?at:u.y>Ut?Ut:u.y;j=ne-u.x,J=he-u.y}else j=A.cx-u.x,J=A.cy-u.y;let dt=-u.z,_=j*j+J*J+dt*dt;if(A.range>0&&_>=A.range*A.range*2.56)continue;let tt=Math.sqrt(_);if(A.feedback&&tt<A.range*.5){A.count+=1-tt/(A.range*.5);let Y=A.thermo??(A.thermo={n:0,sx:0,sy:0,ss:0,ss2:0,sh:0}),Q=u.vx*u.vx+u.vy*u.vy;Y.n++,Y.sx+=u.vx,Y.sy+=u.vy,Y.ss+=Math.sqrt(Q),Y.ss2+=Q,Y.sh+=u.heat}if(A.when&&!Rs(i,A,u,o))continue;o.dx=j,o.dy=J,o.dz=dt,o.dist=tt<1?1:tt;let yt=Uo(A),Rt=1,O=!1,K=!1;for(let Y of yt.modifiers){let Q=s[Y]?.modify;if(!Q)continue;K=!0;let at=Q(A,u,o);at.strength!=null&&(Rt*=at.strength),at.gate&&(O=!0)}for(let Y of yt.forces){let Q=s[Y]?.modify;if(!Q)continue;K=!0;let at=Q(A,u,o);at.strength!=null&&(Rt*=at.strength),at.gate&&(O=!0)}if(O)continue;let L=1;if(E)for(let Y=0;Y<E.length;Y++)E[Y]!==A&&(L*=z[Y]);let I=A.attn??1,$=Rt*I*L;if(!K&&$===1)for(let Y of A.tokens){let Q=s[Y];Q&&Tn(Q,A,u,o,D)}else if(K){let Y=A.strength;A.strength=Y*$;for(let Q of A.tokens){let at=s[Q];at&&!at.modify&&Tn(at,A,u,o,D)}A.strength=Y}else{let Y=A.strength;A.strength=Y*$;for(let Q of A.tokens){let at=s[Q];at&&Tn(at,A,u,o,D)}A.strength=Y}}}if(f&&f>0){let D=o.neighbors(u,12);for(let A of D){let j=u.x-A.x,J=u.y-A.y,dt=(u.z??0)-(A.z??0),_=Math.hypot(j,J,dt)||.1;if(_<12){let tt=(12-_)/12*f*.12;u.vx+=j/_*tt,u.vy+=J/_*tt,u.vz!==void 0&&(u.vz+=dt/_*tt)}}}let it=o.c,lt=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(lt>it*it){let D=it/Math.sqrt(lt);u.vx*=D,u.vy*=D,u.vz*=D}if(u.maxSpeed!==void 0){let D=u.maxSpeed*u.maxSpeed,A=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(A>D){let j=u.maxSpeed/Math.sqrt(A);u.vx*=j,u.vy*=j,u.vz*=j}}if(u.x+=u.vx*y,u.y+=u.vy*y,u.z+=u.vz*y,u.vx*=zn,u.vy*=zn,u.vz*=zn,u.report===void 0){if(o.frameN%40===0&&b.wander>0){let D=.05*b.wander;u.vx+=((o.rng??Math.random)()-.5)*D,u.vy+=((o.rng??Math.random)()-.5)*D,X>0&&(u.vz+=((o.rng??Math.random)()-.5)*D)}if(b.wander>.05){let D=(Math.sin(u.x*.0032+o.t*.12)+Math.cos(u.y*.0034-o.t*.15))*Math.PI;u.vx+=Math.cos(D)*.013*b.wander,u.vy+=Math.sin(D)*.013*b.wander}}u.heat*=Os,u.age!=null&&(u.age-=y,u.age<=0&&(B??(B=[])).push(u)),u.report===void 0?(u.x<-St?u.x=p+St:u.x>p+St&&(u.x=-St),u.y<-St?u.y=v+St:u.y>v+St&&(u.y=-St),X>0&&(u.z<-St?u.z=X+St:u.z>X+St&&(u.z=-St))):(u.x<0?(u.x=0,u.vx=Math.abs(u.vx)):u.x>p&&(u.x=p,u.vx=-Math.abs(u.vx)),u.y<0?(u.y=0,u.vy=Math.abs(u.vy)):u.y>v&&(u.y=v,u.vy=-Math.abs(u.vy)),X>0&&(u.z<0?(u.z=0,u.vz=Math.abs(u.vz)):u.z>X&&(u.z=X,u.vz=-Math.abs(u.vz))),u.report(u))}if(R){for(let u of n)if(!(!u.vis||u.tokens.length===0))for(let Z of u.tokens)s[Z]?.source?.(u,o)}if(B)for(let u of B)t.remove(u)}var Vo={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 $s(){return globalThis.process?.env?.NODE_ENV!=="production"}var Xo=$s();function Jo(){return Xo}var jo=new Set;function Fn(e,t){if(!Xo)return;let n=`${e}:${t}`;jo.has(n)||(jo.add(n),console.warn(`[Fundamental:${e}] ${t}`))}var Is={"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 Ko(e,t={}){let n=Is[e];if(!n)return null;let o=[...n.body];t.risk==="high"&&!o.includes("thermal")&&o.push("thermal");let s={"data-body":o.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:o.join(" "),strength:t.intensity,range:n.range,feedback:n.feedback??!1,render:n.render??["particles"],attributes:s}}function Zo(e){let t=(z,F)=>{let R=Number.parseFloat(e.get(z)??"");return Number.isFinite(R)?R:F},n=t("strength",.5),o=t("angle",0)*Math.PI/180,s=e.get("spin"),i=s==null?1:Number.isFinite(Number.parseFloat(s))?Number.parseFloat(s):0,a=(e.get("body")??"").split(/\s+/).filter(Boolean),f=Te(a),y=e.get("life"),p=e.get("cap"),v=Number.parseFloat(y??""),b=Number.parseFloat(p??""),E=y!=null||p!=null||e.has("budget")||e.has("sink");return{tokens:a,classified:f,...Number.isFinite(v)&&v>0?{life:v}:{},...Number.isFinite(b)&&b>0?{cap:b}:{},budgeted:E,strength:n,range:t("range",280),absorbR:t("absorb",64),capacity:t("max",60),spin:i,angle:o,ux:Math.cos(o),uy:Math.sin(o),when:e.get("when")??"",feedback:e.has("feedback"),shaped:e.has("shaped"),...e.get("species")!=null&&Number.isFinite(Number.parseFloat(e.get("species")))?{species:Number.parseFloat(e.get("species"))}:{},...(()=>{let z=e.get("affects");if(z==null)return{};let F=z.split(",").map(R=>Number.parseFloat(R.trim())).filter(R=>Number.isFinite(R));return F.length?{affects:new Set(F)}:{}})(),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 Ns(e){let t={body:e.body};return e.strength!=null&&(t.strength=String(e.strength)),e.range!=null&&(t.range=String(e.range)),e.spin!=null&&(t.spin=String(e.spin)),e.angle!=null&&(t.angle=String(e.angle)),e.absorb!=null&&(t.absorb=String(e.absorb)),e.max!=null&&(t.max=String(e.max)),e.life!=null&&(t.life=String(e.life)),e.cap!=null&&(t.cap=String(e.cap)),{get:n=>t[n]??null,has:n=>n in t}}function Ls(e){let t=Vo[e];return t?t.map(n=>Zo(Ns(n))):[]}function Ds(e){let t=(e.tagName??"element").toLowerCase(),n=e.id?`#${e.id}`:"",o=typeof e.className=="string"&&e.className?`.${e.className.split(/\s+/)[0]}`:"";return`<${t}${n}${o}>`}function _s(e,t="<body>"){!e.classified||e.classified.sources.length===0||e.budgeted||(e.life=pn,e.cap=mn,Jo()&&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="${pn}", data-cap="${mn}") \u2014 declare one to make the source's budget explicit (workover v0.3 source rules).`))}function tr(e,t){return _s(t,Ds(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 Bs(e){return{get:t=>e.getAttribute("data-"+t),has:t=>e.hasAttribute("data-"+t)}}function le(e,t){return tr(e,Zo(t??Bs(e)))}var Qo={source:"jet",sink:"sink",anchor:"tether",boundary:"wall",sensor:"",display:""};function Ws(e){let t=null,n=e.getAttribute("data-intent");if(n){let s=e.getAttribute("data-intensity"),i=Ko(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 Qo&&(t={body:Qo[s],feedback:""})}if(!t)return null;let o=t;return{get:s=>e.getAttribute("data-"+s)??o[s]??null,has:s=>e.hasAttribute("data-"+s)||s in o}}function er(e){let t=[];return e.querySelectorAll("[data-body]").forEach(n=>{t.push(le(n))}),e.querySelectorAll("[data-preset]").forEach(n=>{let o=n;for(let s of Ls(o.dataset.preset??""))t.push(tr(o,s))}),e.querySelectorAll("[data-intent]:not([data-body]), [data-field-role]:not([data-body]):not([data-intent])").forEach(n=>{let o=Ws(n);o&&t.push(le(n,o))}),t}function Hs(e){let t=e.el;if(typeof t.getAttribute!="function")return;let n=t.getAttribute("data-strength");if(n!=null){let a=Number.parseFloat(n);Number.isFinite(a)&&(e.strength=a,e.M=a)}let o=t.getAttribute("data-range");if(o!=null){let a=Number.parseFloat(o);Number.isFinite(a)&&(e.range=a)}let s=t.getAttribute("data-spin");if(s!=null){let a=Number.parseFloat(s);Number.isFinite(a)&&(e.spin=a)}let i=t.getAttribute("data-angle");if(i!=null){let a=Number.parseFloat(i);Number.isFinite(a)&&(e.angle=a*Math.PI/180,e.ux=Math.cos(e.angle),e.uy=Math.sin(e.angle))}}function Ne(e,t,n,o=0,s=0){let i=n*.15;for(let a of e){let f=a.rect?a.rect():a.el.getBoundingClientRect(),y=f.left-o,p=f.top-s;a.cx=y+f.width/2,a.cy=p+f.height/2,a.hw=f.width/2,a.hh=f.height/2,a.on=a.el.dataset.active==="1",a.vis=p+f.height>-i&&p<n+i&&y+f.width>-i&&y<t+i,Hs(a)}}var nr="field:register-body",or="field:unregister-body",rr="field:update-body";var Le=class{constructor(){U(this,"hosts",new Map)}register(t){this.hosts.set(t.element,t)}unregister(t){this.hosts.delete(t)}get size(){return this.hosts.size}bodies(t){let n=[];for(let[o,s]of this.hosts){if(!o.isConnected){this.hosts.delete(o);continue}let i=s.attrs?qs(s.attrs,o):void 0,a=t(o,i);s.getRect&&(a.rect=s.getRect),s.writeTarget&&(a.writeTarget=s.writeTarget),n.push(a)}return n}};function qs(e,t){return{get:n=>e[n]??t.getAttribute("data-"+n),has:n=>n in e||t.hasAttribute("data-"+n)}}function ir(e,t,n=.12){return e>=t?0:(1-e/t)*n}function De(e,t,n){if(e===t)return .5;let o=(n-e)/(t-e);return o<0?0:o>1?1:o}var sr=Object.freeze([]);function An(e,t,n,o,s){let i={x:De(e,t,s),y:0},a={x:1,y:De(t,n,s)},f={x:De(o,n,s),y:1},y={x:0,y:De(e,o,s)},p=(b,E)=>({x1:b.x,y1:b.y,x2:E.x,y2:E.y});switch((e>s?8:0)|(t>s?4:0)|(n>s?2:0)|(o>s?1:0)){case 0:case 15:return sr;case 1:case 14:return[p(y,f)];case 2:case 13:return[p(f,a)];case 3:case 12:return[p(y,a)];case 4:case 11:return[p(i,a)];case 6:case 9:return[p(i,f)];case 7:case 8:return[p(y,i)];case 5:return[p(y,i),p(f,a)];case 10:return[p(y,f),p(i,a)];default:return sr}}function Cn(e,t,n,o,s,i,a,f=1){if(a<=0)return;let y=Math.max(0,Math.floor((s-a)/o)),p=Math.min(t-1,Math.ceil((s+a)/o)),v=Math.max(0,Math.floor((i-a)/o)),b=Math.min(n-1,Math.ceil((i+a)/o)),E=a*a;for(let z=v;z<=b;z++)for(let F=y;F<=p;F++){let R=F*o-s,B=z*o-i,N=R*R+B*B;if(N>=E)continue;let X=1-Math.sqrt(N)/a,u=z*t+F;e[u]=e[u]+f*X*X}}function ar(e,t,n){let o=-1,s=1/0;for(let i=0;i<n.length;i++){let a=n[i],f=a.x-e,y=a.y-t,p=f*f+y*y;p<s&&(s=p,o=i)}return o}function cr(e,t,n){let o=[];for(let s=0;s<n;s++)for(let i=0;i<t;i++){let a=e[s*t+i];i+1<t&&e[s*t+i+1]!==a&&o.push({x1:i+.5,y1:s-.5,x2:i+.5,y2:s+.5}),s+1<n&&e[(s+1)*t+i]!==a&&o.push({x1:i-.5,y1:s+.5,x2:i+.5,y2:s+.5})}return o}var te=class{constructor(t,n,o="diffuse",s=32){U(this,"mode");U(this,"cell");U(this,"W");U(this,"H");U(this,"cols");U(this,"rows");U(this,"cur");U(this,"nxt");U(this,"prev");this.W=t,this.H=n,this.mode=o,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 o=t/this.cell,s=n/this.cell,i=Math.floor(o),a=Math.floor(s),f=o-i,y=s-a,p=this.at(i,a)*(1-f)+this.at(i+1,a)*f,v=this.at(i,a+1)*(1-f)+this.at(i+1,a+1)*f;return p*(1-y)+v*y}deposit(t,n,o){let s=this.clampCol(Math.round(t/this.cell)),i=this.clampRow(Math.round(n/this.cell));this.cur[i*this.cols+s]+=o}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 o=this.cell;return{x:(this.sample(t+o,n)-this.sample(t-o,n))/(2*o),y:(this.sample(t,n+o)-this.sample(t,n-o))/(2*o)}}step(){this.mode==="wave"?this.stepWave():this.mode==="memory"?this.stepDiffuse(.03,.004):this.stepDiffuse()}stepDiffuse(t=.18,n=.01){let o=t<0?0:t>.24?.24:t,s=1-n,{cols:i,rows:a,cur:f,nxt:y}=this;for(let p=0;p<a;p++)for(let v=0;v<i;v++){let b=p*i+v,E=this.at(v-1,p)+this.at(v+1,p)+this.at(v,p-1)+this.at(v,p+1)-4*f[b];y[b]=(f[b]+o*E)*s}this.cur=y,this.nxt=f}stepWave(t=.25,n=.002){let o=t<0?0:t>.5?.5:t,s=1-n,{cols:i,rows:a,cur:f,prev:y,nxt:p}=this;for(let v=0;v<a;v++)for(let b=0;b<i;b++){let E=v*i+b,z=this.at(b-1,v)+this.at(b+1,v)+this.at(b,v-1)+this.at(b,v+1)-4*f[E];p[E]=(2*f[E]-y[E]+o*z)*s}this.prev=f,this.cur=p,this.nxt=y}decay(t){let n=t<=0?1:t>=1?0:1-t;if(n!==1)for(let o=0;o<this.cur.length;o++)this.cur[o]*=n}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 o=this.cols*this.rows;this.cur=new Float32Array(o),this.nxt=new Float32Array(o),this.prev=new Float32Array(o)}};var lr=24,Ys=.12,Us=.22,de=class{constructor(t,n){U(this,"grid");U(this,"peak",.001);U(this,"cell",lr);this.grid=new te(Math.max(1,t),Math.max(1,n),"diffuse",lr)}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(Us,Ys);let n=this.grid.max(),o=n>this.peak?.25:.03;this.peak+=(Math.max(n,.001)-this.peak)*o}norm(t,n){return wt(this.grid.sample(t,n)/this.peak,0,1)}gradient(t,n){if(this.peak<=0)return{x:0,y:0};let o=this.grid.gradient(t,n);return{x:o.x/this.peak,y:o.y/this.peak}}};var Gs={position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"0",pointerEvents:"none",display:"block"},dr=Object.entries(Gs).map(([e,t])=>`${e.replace(/[A-Z]/g,n=>"-"+n.toLowerCase())}:${t}`).join(";");function fr(e){let t=e.width,n=e.height,o=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:a=>(o=a,1),cancelRaf:()=>{o=null},createCanvas:()=>{throw new Error("headlessHost does not render \u2014 use render:'none' and the signal read-outs (onFeedback / sampleScalar / readParticles).")},onResize:()=>()=>{},onScroll:()=>()=>{},onVisibility:()=>()=>{},onInput:()=>()=>{},onBodyEvent:()=>()=>{},tick(a){s=a??s+1e3/60;let f=o;o=null,f?.(s)},resize(a,f){t=a,n=f}}}var hr="10px ui-monospace, SFMono-Regular, Menlo, monospace";function Pn(e,t){let n=0,o=0;return{size(s,i,a){n=s,o=i,e.width=Math.floor(s*a),e.height=Math.floor(i*a),t.setTransform(a,0,0,a,0,0)},clear(){t.clearRect(0,0,n,o)},segments(s,i){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath();for(let a=0;a+3<s.length;a+=4)t.moveTo(s[a],s[a+1]),t.lineTo(s[a+2],s[a+3]);t.stroke()},polyline(s,i){if(!(s.length<4)){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath(),t.moveTo(s[0],s[1]);for(let a=2;a+1<s.length;a+=2)t.lineTo(s[a],s[a+1]);t.stroke()}},rect(s,i,a,f,y,p,v,b){t.fillStyle=`rgba(${y},${p},${v},${b})`,t.fillRect(s,i,a,f)},text(s,i,a,f,y,p,v){t.font=hr,t.textBaseline="middle",t.fillStyle=`rgba(${f},${y},${p},${v})`,t.fillText(s,i,a)},measureText(s){return t.font=hr,t.measureText(s).width}}}var On=(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),e.style.setProperty("--mass",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 o=e.dataset.fxLit==="1";n>.5&&!o?(e.dataset.fxLit="1",e.dispatchEvent(new CustomEvent("field:lit",{detail:{value:n}}))):n<.4&&o&&(e.dataset.fxLit="0",e.dispatchEvent(new CustomEvent("field:dim",{detail:{value:n}})))}},Rn=On;var _e=class{constructor(t){U(this,"lit",!1);U(this,"lastEdgeMs",-1/0);U(this,"cfg");this.cfg=t}update(t,n){let o=n-this.lastEdgeMs>=this.cfg.debounceMs;return!this.lit&&t>=this.cfg.enter&&o?(this.lit=!0,this.lastEdgeMs=n,"entered"):this.lit&&t<=this.cfg.exit&&o?(this.lit=!1,this.lastEdgeMs=n,"exited"):null}get isLit(){return this.lit}reset(){this.lit=!1,this.lastEdgeMs=-1/0}};var Vs={strengthen:1.5,decay:.3,remember:.2},$n=e=>e<0?0:e>1?1:e;function ur(e,t,n,o,s=Vs){e.active=t,e.tension=$n(n),e.strength=$n(e.strength+(t?s.strengthen:-s.decay)*o),e.memory=$n(e.memory+(t?s.remember:-s.remember*.5)*o)}function yr(e,t,n=Math.random){let o=[],s=t.absorbR+6;for(let i of e){if(i.cap!==t)continue;let a=n()*Math.PI*2,f=4+n()*3;i.cap=null,i.x=t.cx+Math.cos(a)*s,i.y=t.cy+Math.sin(a)*s,i.vx=Math.cos(a)*f,i.vy=Math.sin(a)*f,i.z&&(i.z=0),i.vz&&(i.vz=0),i.heat=1,i.age=void 0,o.push(i)}return t.accreted=0,o}function In(e){if(e.capacity<=0)return 0;let t=e.accreted/e.capacity;return t<0?0:t>1?1:t}function pr(e,t){return t&&!e?{fire:"captured",armed:!0}:!t&&e?{fire:"released",armed:!1}:{fire:null,armed:e}}function mr(e,t){let n=[];for(let o of e)o.when!=="active"||!o.tokens.includes("sink")||(o.wasOn&&!o.on&&o.accreted>0&&(t(o),n.push(o)),o.wasOn=o.on);return n}function Nn(e,t){let n=t.cx-e.x,o=t.cy-e.y;return n*n+o*o<t.absorbR*t.absorbR}function gr(e,t,n=.14){let o=e+(t-e)*n;return o<.001?0:o>.999?1:o}function xr(e,t,n,o){let s=e.x+t.x,i=e.y+t.y,a=t.x+(n.x-s)*o,f=t.y+(n.y-i)*o,y=1-o;return{tx:a,ty:f,scale:y,opacity:y}}var js={token:"attract",label:"Attract",apply(e,t,n){let o=e.range*(e.on?1.5:1),s=e.strength*(e.on?3:1);if(n.dist>=o)return;let i=(1-n.dist/o)**2*s*.5,a=n.dx/n.dist,f=n.dy/n.dist;t.vx+=a*i,t.vy+=f*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i),n.form.orbit&&(t.vx+=-f*i*n.form.orbit,t.vy+=a*i*n.form.orbit),e.on&&(t.heat=Math.max(t.heat,(1-n.dist/o)*.9))},meta:{desc:"a soft gravity-like well, bent into a spiral"}},Xs={token:"repel",label:"Repel",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**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"}},Js={token:"swirl",label:"Swirl",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**1.4*s*.45,a=e.spin,f=n.dx/n.dist,y=n.dy/n.dist;t.vx+=y*i*a+f*i*.12,t.vy+=-f*i*a+y*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/o)*.6))},meta:{desc:"tangential swirl with light inward retention"}},Ks={token:"stream",label:"Stream",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**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/o)*.5))},meta:{desc:"directional current along a heading"}},Qs={token:"viscosity",label:"Viscosity",apply(e,t,n){let o=e.range*(e.on?1.4:1);if(n.dist>=o)return;let s=(1-n.dist/o)*(.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"}},Zs={token:"jet",label:"Jet",kinematic:!0,apply(e,t,n){let o=e.range*(e.on?1.4:1);if(!(n.dist>=o))if(n.dist<24){let s=((n.rng??Math.random)()-.5)*.8,i=Math.cos(s),a=Math.sin(s),f=e.ux*i-e.uy*a,y=e.ux*a+e.uy*i,p=2.4+e.strength*2.6;t.vx=f*p,t.vy=y*p,t.x=e.cx+f*26,t.y=e.cy+y*26,t.z&&(t.z=0),t.vz&&(t.vz=0),t.heat=Math.max(t.heat,.9)}else{let s=(1-n.dist/o)**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"}},ti={token:"tether",label:"Tether",apply(e,t,n){let o=e.range*.6*(e.on?1.25:1),s=o*2.1;if(n.dist>=s)return;let i=(.006+e.strength*.012)*(e.on?1.7:1),a=n.dist-o,f=n.dx/n.dist,y=n.dy/n.dist;t.vx+=f*a*i,t.vy+=y*a*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*a*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(a)/o))*.5))},meta:{desc:"a tether with a rest length \u2014 holds matter at a fixed radius"}},ei={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 a=Math.hypot(t.vx,t.vy),f=e.hw+6-s,y=e.hh+6-i;f<y?(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),a>.7&&(n.spark(t.x,t.y,Math.min(2.4,a),e.tint??lo.wall.color),t.heat=Math.max(t.heat,Math.min(.85,a*.4)))},meta:{desc:"axis-aligned bouncing wall \u2014 sparks on impact"}},ni={token:"sink",label:"Sink",apply(e,t,n){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"}},oi=[js,Zs,ti,ei,Ks,Xs,Qs,Js,ni];function vr(e){for(let t of oi)e.force(t)}var Dn=1.5,ri=8,si=60;function ii(e,t,n,o){let s=Pe(e);if(Math.hypot(s[0].x-s[1].x,s[0].y-s[1].y)<Math.max(e.range*.06,ri)){let y=Math.max(e.range*.18,si),p=e.spin<0?-1:1;s=[{x:e.cx+e.ux*y,y:e.cy+e.uy*y,q:p},{x:e.cx-e.ux*y,y:e.cy-e.uy*y,q:-p}]}let a=o*(1+Dn*(e.d??0)),f=yo(s,t,n);return{x:f.x*a,y:f.y*a}}function ai(e,t,n,o){let s=t-e.cx,i=n-e.cy,a=Math.max(Math.hypot(s,i),Ce),y=(e.spin<0?-1:1)*o*(1+Dn*(e.d??0))/(a*a);return{x:s/a*y,y:i/a*y}}function wr(e,t,n,o){if(n.dist>=e.range)return;let s=2*n.G*e.M/(n.c*n.c),i=o/(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),_n(t,n.c)}function _n(e,t){let n=e.vz??0,o=Math.hypot(e.vx,e.vy,n);o>t&&(e.vx=e.vx/o*t,e.vy=e.vy/o*t,n&&(e.vz=n/o*t))}function ci(e,t,n){let o=e.cx-t,s=e.cy-n,i=Math.max(Math.hypot(o,s),Ce),a=e.M*(1+Dn*(e.d??0))/(i*i);return{x:o/i*a,y:s/i*a}}var li={token:"gravity",label:"Gravity",apply(e,t,n){wr(e,t,n,n.G*e.M)},field:(e,t,n)=>ci(e,t,n),meta:{desc:"true softened inverse-square gravity (a real 1/d\xB2 law)"}},di={token:"charge",label:"Charge",apply(e,t,n){let o=t.charge??0;o!==0&&wr(e,t,n,-(e.spin*o*n.G*e.M))},field:(e,t,n)=>ai(e,t,n,e.M),meta:{desc:"signed inverse-square \u2014 like repels, opposite attracts"}},fi={token:"magnetism",label:"Magnetism",apply(e,t,n){if(n.dist>=e.range)return;let o=t.charge??0;if(o===0)return;let s=1-n.dist/e.range,i=o*e.spin*e.strength*s,a=Math.cos(i),f=Math.sin(i),y=t.vx;t.vx=y*a-t.vy*f,t.vy=y*f+t.vy*a},field:(e,t,n)=>ii(e,t,n,e.strength),meta:{desc:"Lorentz force \u2014 curves a moving charge perpendicular to its velocity"}};function hi(e){return Math.sqrt(2*Math.max(0,e))}var ui={token:"thermal",label:"Thermal",apply(e,t,n){if(n.dist>=e.range)return;let o=1-n.dist/e.range,s=hi(e.strength*o);if(s===0)return;let i=Math.random()||1e-9,a=s*Math.sqrt(-2*Math.log(i)),f=2*Math.PI*Math.random();if(t.vx+=a*Math.cos(f),t.vy+=a*Math.sin(f),n.D){let y=Math.random()||1e-9;t.vz=(t.vz??0)+s*Math.sqrt(-2*Math.log(y))*Math.cos(2*Math.PI*Math.random())}e.on&&(t.heat=Math.max(t.heat,o*.4)),_n(t,n.c)},meta:{desc:"Langevin/Brownian agitation \u2014 a real temperature in the medium"}},yi={token:"collide",label:"Collide",apply(e,t,n){if(n.dist>=e.range)return;let o=Math.max(0,Math.min(1,e.strength)),s=Math.max(1,t.size);for(let i of n.neighbors(t,s*4)){let a=Math.max(1,i.size),f=t.x-i.x,y=t.y-i.y,p=(t.z??0)-(i.z??0),v=Math.hypot(f,y,p);if(v>=s+a||v<1e-6)continue;let b=f/v,E=y/v,z=p/v,F=(t.vx-i.vx)*b+(t.vy-i.vy)*E+((t.vz??0)-(i.vz??0))*z;if(F>=0)continue;let R=(1+o)*.5*F;t.vx-=R*b,t.vy-=R*E,i.vx+=R*b,i.vy+=R*E,p&&(t.vz=(t.vz??0)-R*z,i.vz=(i.vz??0)+R*z)}},meta:{desc:"elastic pairwise collision \u2014 the hard-sphere billiard force"}},pi={token:"diffuse",label:"Diffuse",apply(e,t,n){if(n.dist>=e.range)return;let o=n.grid("diffuse");o.deposit(t.x,t.y,e.strength);let s=o.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"}},mi=12,Ln=7,gi={token:"propagate",label:"Propagate",source(e,t){e.on&&t.frameN%mi===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 a=-n.dx/n.dist,f=-n.dy/n.dist;t.vx+=a*i*e.strength*Ln,t.vy+=f*i*e.strength*Ln,n.dz&&(t.vz=(t.vz??0)+-n.dz/n.dist*i*e.strength*Ln),_n(t,n.c)},meta:{desc:"a travelling wave \u2014 a shock train expands from the source, sweeping matter out"}},xi={token:"memory",label:"Memory",apply(e,t,n){if(n.dist>=e.range)return;let o=n.grid("memory");o.deposit(t.x,t.y,e.strength*.15);let s=1+.5*o.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"}},vi=[li,di,fi,ui,yi,pi,gi,xi];function br(e){for(let t of vi)e.force(t)}var wi={token:"lens",label:"Lens",kinematic:!0,apply(e,t,n){if(n.dist>=e.range)return;let o=e.strength*(1-n.dist/e.range)*e.spin,s=Math.cos(o),i=Math.sin(o),a=t.vx,f=t.vy;t.vx=a*s-f*i,t.vy=a*i+f*s},meta:{desc:"rotates velocity, preserving speed \u2014 bends paths without adding energy"}},bi={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"}},Mi=1,Ei=1,ki={token:"buoyancy",label:"Buoyancy",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=Mi/(t.size*(1+t.heat));t.vy-=(Ei-o)*e.strength},meta:{desc:"a constant lift/sink by density difference \u2014 light matter rises, dense settles"}},Si={token:"shear",label:"Shear",apply(e,t,n){if(n.dist>=e.range)return;let o=(t.x-e.cx)*-e.uy+(t.y-e.cy)*e.ux,s=e.strength*(o/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"}},Be=32,zi=.5,Ti={token:"crystallize",label:"Crystallize",apply(e,t,n){if(n.dist>=e.range||t.heat>=zi)return;let o=e.cx+Math.round((t.x-e.cx)/Be)*Be,s=e.cy+Math.round((t.y-e.cy)/Be)*Be;t.vx+=(o-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"}},Fi={token:"align",label:"Align",apply(e,t,n){if(n.dist>=e.range)return;let o=t.vz??0,s=Math.hypot(t.vx,t.vy,o),i=e.strength,a=e.ux,f=e.uy,y=0,p=0,v=0,b=0;for(let z of n.neighbors(t,e.range)){let F=z.vz??0,R=Math.hypot(z.vx,z.vy,F);R>1e-6&&(p+=z.vx/R,v+=z.vy/R,b+=F/R)}let E=Math.hypot(p,v,b);E>1e-6&&(a=p/E,f=v/E,y=b/E),t.vx+=(a*s-t.vx)*i,t.vy+=(f*s-t.vy)*i,(y||o)&&(t.vz=o+(y*s-o)*i)},meta:{desc:"steers toward the neighbour-mean heading (or the body heading when alone)"}};function Ai(e,t,n,o){let s=e*o+n*.2,i=t*o-n*.2;return{x:-o*Math.sin(s)*Math.sin(i),y:-o*Math.cos(s)*Math.cos(i)}}var Ci=.01,Pi={token:"wind",label:"Wind",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=Ai(t.x,t.y,n.t,Ci);t.vx+=o.x*e.strength,t.vy+=o.y*e.strength},meta:{desc:"divergence-free curl-noise turbulence"}},Oi=.5,Ri={token:"cohesion",label:"Cohesion",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=o*Oi,i=e.strength;for(let a of n.neighbors(t,o)){let f=a.x-t.x,y=a.y-t.y,p=(a.z??0)-(t.z??0),v=Math.hypot(f,y,p);if(v<1e-6)continue;let b=f/v,E=y/v,z=p/v;if(v<s){let F=i*(s-v)/s;t.vx-=F*b,t.vy-=F*E,p&&(t.vz=(t.vz??0)-F*z)}else{let F=i*(v-s)/(o-s);t.vx+=F*b,t.vy+=F*E,p&&(t.vz=(t.vz??0)+F*z)}}},meta:{desc:"short-range pressure + mid-range cohesion \u2014 surface tension over neighbours"}},$i=.5,Ii={token:"pressure",label:"Pressure",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=e.strength,i=0,a=n.neighbors(t,o);for(let y of a){let p=Math.hypot(y.x-t.x,y.y-t.y,(y.z??0)-(t.z??0));p<o&&(i+=(1-p/o)**2)}let f=i-$i;if(!(f<=0))for(let y of a){let p=t.x-y.x,v=t.y-y.y,b=(t.z??0)-(y.z??0),E=Math.hypot(p,v,b);if(E<1e-6||E>=o)continue;let z=s*f*(1-E/o)/E;t.vx+=z*p,t.vy+=z*v,b&&(t.vz=(t.vz??0)+z*b)}},meta:{desc:"SPH density relaxation \u2014 incompressible even-fill via mutual repulsion"}},Ni={token:"hunt",label:"Hunt",apply(e,t,n){if(n.dist>=e.range)return;let o=t.species??0,s=null,i=1/0;for(let b of n.neighbors(t,e.range)){if((b.species??0)===o)continue;let E=b.x-t.x,z=b.y-t.y,F=(b.z??0)-(t.z??0),R=E*E+z*z+F*F;R<i&&(i=R,s=b)}if(!s)return;let a=s.x-t.x,f=s.y-t.y,y=(s.z??0)-(t.z??0),p=Math.hypot(a,f,y)||1,v=o===0?1:-1;t.vx+=a/p*e.strength*v,t.vy+=f/p*e.strength*v,y&&(t.vz=(t.vz??0)+y/p*e.strength*v)},meta:{desc:"two-species pursuit \u2014 predators seek prey, prey flee predators"}},Li=.35,Di={token:"link",label:"Link",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=o*Li,i=e.strength;for(let a of n.neighbors(t,o)){let f=a.x-t.x,y=a.y-t.y,p=(a.z??0)-(t.z??0),v=Math.hypot(f,y,p);if(v<1e-6)continue;let b=v-s,E=.5*i*(b/s);t.vx+=E*(f/v),t.vy+=E*(y/v),p&&(t.vz=(t.vz??0)+E*(p/v))}},meta:{desc:"a Verlet distance constraint \u2014 holds a rest length, so matter ropes and drapes"}},Mr=40,_i={token:"morph",label:"Morph",apply(e,t,n){let o=e.targets;if(!o||o.length===0)return;let s=Math.min(o.length-1,Math.floor((t.gx??0)*o.length)),i=o[s],a=i.x-t.x,f=i.y-t.y,y=Math.hypot(a,f),p=e.strength;t.vx+=a*p*.02,t.vy+=f*p*.02,t.z&&(t.vz=(t.vz??0)-t.z*p*.02);let b=(1-(y<Mr?1-y/Mr:0))*p*.3;b>0&&(t.vx+=((n.rng??Math.random)()-.5)*b,t.vy+=((n.rng??Math.random)()-.5)*b)},meta:{desc:"matter assembles into a mark/chart/logo \u2014 never words (\xA711)"}},Bi=90,Wi={token:"spawn",label:"Spawn",apply(){},source(e,t){let n=e.life??Bi,o=Math.max(1,Math.round(e.strength*2));e.cap!=null&&e.cap>0&&n>0&&(o=Math.min(o,e.cap/n)),e.emitAcc=(e.emitAcc??0)+o;let s=Math.floor(e.emitAcc);for(e.emitAcc-=s;s>0;s--){let i=((t.rng??Math.random)()-.5)*.6,a=Math.cos(i),f=Math.sin(i),y=e.ux*a-e.uy*f,p=e.ux*f+e.uy*a,v=2+(t.rng??Math.random)()*2;t.spawn({x:e.cx,y:e.cy,vx:y*v,vy:p*v,age:n,heat:.6,...e.species!=null?{species:e.species}:{}})}},meta:{desc:"a source \u2014 emits matter along the heading, budgeted by a lifespan"}},Hi=3,qi={token:"resonate",label:"Resonate",apply(){},modify(e,t,n){return{strength:1+Math.sin(n.t*Hi*e.spin)}},meta:{desc:"pulses sibling forces with a time-varying strength S(t)=S\u2080(1+sin \u03C9t)"}},Yi=.5,Ui={token:"spotlight",label:"Spotlight",apply(){},modify(e,t,n){let o=-n.dx/n.dist,s=-n.dy/n.dist;return{gate:o*e.ux+s*e.uy<Yi}},meta:{desc:"gates sibling forces to an angular cone of the heading"}},Gi={token:"screen",label:"Screen",apply(){},meta:{desc:"a quiet zone \u2014 attenuates other bodies' forces on matter inside its radius"}},Vi={token:"pigment",label:"Pigment",apply(e,t,n){let o=e.tint;!o||n.dist>=e.range*.6||(t.color=t.color?ho(t.color,o,.08):o)},meta:{desc:"conserved color transport \u2014 matter takes on and carries a tint"}},ji=.5,Er=.12,Xi={token:"fieldflow",label:"Field Flow",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=n.fieldAt?.(t.x,t.y);if(!o)return;let s=Math.hypot(o.x,o.y);if(!(s>1e-9))return;let i=o.x/s,a=o.y/s,f=e.range>0?1-n.dist/e.range:1,y=e.strength*f,p=t.vz??0,v=Math.hypot(t.vx,t.vy,p);if(v>1e-6){let z=Math.min(1,y*ji);t.vx+=(i*v-t.vx)*z,t.vy+=(a*v-t.vy)*z,p&&(t.vz=p+(0-p)*z)}t.vx+=i*y*Er,t.vy+=a*y*Er;let b=t.vz??0,E=t.vx*t.vx+t.vy*t.vy+b*b;if(E>n.c*n.c){let z=n.c/Math.sqrt(E);t.vx*=z,t.vy*=z,b&&(t.vz=b*z)}e.on&&(t.heat=Math.max(t.heat,f*.4))},meta:{desc:"follow the field lines \u2014 steer onto and stream down the net field a body radiates"}},Ji={token:"warp",label:"Warp",kinematic:!0,apply(e,t,n){if(!e.warpHas||t.cap)return;let o=e.absorbR;if(n.dist>=o)return;let s=Math.cos(e.twist??0),i=Math.sin(e.twist??0),a=e.warpScale??1,f=-n.dx/n.dist,y=-n.dy/n.dist,p=f*s-y*i,v=f*i+y*s,b=o*a+6;t.x=e.warpX+p*b,t.y=e.warpY+v*b,t.z&&(t.z=-n.dz/n.dist*b);let E=t.vx,z=t.vy;t.vx=E*s-z*i,t.vy=E*i+z*s,t.heat=Math.max(t.heat,.6)},meta:{desc:"a wormhole throat \u2014 relocates matter to its paired body, conserved"}},Ki=[wi,bi,ki,Si,Ti,Fi,Pi,Ri,Ii,Di,Ni,_i,Wi,qi,Ui,Gi,Vi,Xi,Ji];function kr(e){for(let t of Ki)e.force(t)}function Qi(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 Zi(e){let t=0;for(let n of e)t+=n.heat;return t}function Sr(e){let t=Qi(e),n=Zi(e);return{kinetic:t,thermal:n,total:t+n,count:e.length}}var We={x:0,y:0},He=[0,0,0];function qe(e,t={}){let n=null;if((t.render??"none")!=="none"&&(n=e.getContext("2d"),!n))throw new Error("Fundamental: 2D canvas context unavailable");let o=t.overlayCanvas??null,s=n?o?.getContext("2d")??null:null,i=t.overlayBackend??(o&&s?Pn(o,s):null),a=new $e,f=1,y=new Map,p=Ho(),v=new Map,b=r=>(v.get(r)?.size??0)>0;function E(r,c){let l=v.get(r);if(l)for(let g of l)g(c)}let z=new Ie;function F(r,c){b(r)&&z.record(r,c)}function R(){z.flush(E)}let B=new WeakMap,N=new Map,X=new Map;function u(r){let c=b("enter")||b("exit"),l=b("met");if(!c&&!l)return;for(let d=0;d<r.length;d++){let x=r[d];if(c){let m=N.get(x);m||N.set(x,m=new Set);let h=x.range*x.range;for(let w=0;w<r.length;w++){if(d===w)continue;let M=r[w],S=M.cx-x.cx,T=M.cy-x.cy,k=S*S+T*T<h;k&&!m.has(M)?(m.add(M),b("enter")&&F("enter",{body:x,other:M})):!k&&m.has(M)&&(m.delete(M),b("exit")&&F("exit",{body:x,other:M}))}}if(l){let m=X.get(x);m||X.set(x,m=new Set);for(let h=d+1;h<r.length;h++){let w=r[h],M=Math.abs(w.cx-x.cx)<x.hw+w.hw&&Math.abs(w.cy-x.cy)<x.hh+w.hh;M&&!m.has(w)?(m.add(w),F("met",{a:x,b:w})):!M&&m.has(w)&&m.delete(w)}}}let g=new Set(r);for(let d of[N,X])for(let x of d.keys())g.has(x)||d.delete(x)}let Z=[],it=new WeakMap,lt=[],D=0,A=new WeakMap,j=new WeakMap,J=new Map,dt=new Map;if(vr(p),br(p),kr(p),!t.host)throw new Error("Fundamental: createField requires opts.host. Use @fundamental-engine/vanilla (createField/mountField) or @fundamental-engine/elements / @fundamental-engine/react, or pass browserHost() from @fundamental-engine/dom.");let _=t.host,tt=[],yt=_.reducedMotion(),Rt=vn[t.theme??wn]??vn[wn],O={accent:t.accent??Ae(t.palette)[0]??ze[0]??"#4da3ff",density:t.density&&t.density>0?t.density:1,render:t.render??"none",waves:t.waves??!0,waveStyle:t.waveStyle??"linear",waveCenter:t.waveCenter??null,background:t.background??"opaque",mass:t.mass??!1,separation:t.separation!=null&&t.separation>=0?t.separation:0,attention:t.attention??!1,causality:t.causality??!1,heatmap:t.heatmap??!1,overlay:t.overlay??"off",gridWarp:t.gridWarp!=null&&t.gridWarp>=0?t.gridWarp:1,gridIntensity:t.gridIntensity!=null&&t.gridIntensity>=0?Math.min(t.gridIntensity,1):.16,gradientCool:t.gradientCool?gt(t.gradientCool):Rt.cool,gradientWarm:t.gradientWarm?gt(t.gradientWarm):Rt.warm,waveBaseline:(t.waveBaseline??Rt.wave).map(gt),dprCap:t.dprCap&&t.dprCap>0?t.dprCap:2,depth:t.depth&&t.depth>0?t.depth:0,feedbackSink:t.feedbackSink??On},K=null,L=[],I=0,$=0,Y=0,Q=0,at=!1,Ut=1,ne=0,he=new WeakMap,qt=0,$t=0,Wn=!0,Hn={...Fe.ambient.preset},vt=[],Dt=[],qn=0,Yt=null,ht=t.rng??Math.random,Xe=t.now??(()=>performance.now()),ft=yt?1:0,Je=NaN,It=null,oe=null,_t=0,Nt=0,ue=null,Ke=[],Qe=null,ye=null,$r=Math.round(130*O.density)*4,xt={x:0,y:0,k:0},ut=null,Lt=null,Yn=0,Un=0,Gn=Ae(t.palette).map(gt),rt=gt(O.accent),pe=null,Ze=[],Bt=[],Gt=[],Vt=[],tn=[],en=[],jt=[],me=new Le,nn=!1,on=()=>{nn||(nn=!0,queueMicrotask(()=>{nn=!1,xe()}))},Ir=r=>{for(let c of["--d","--field-density","--load","--mass","--entropy","--coherence","--temperature"])r.style.removeProperty(c)},Nr=r=>{let c=r.detail;c?.element&&(me.register(c),on())},Lr=r=>{let c=r.detail;c?.element&&(me.unregister(c.element),Ir(c.writeTarget??c.element),on())},Dr=on,Tt={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null},Vn=Xe(),q={dx:0,dy:0,dz:0,dist:1,form:{...Fe.ambient.preset},W:0,H:0,D:O.depth,t:0,frameN:0,dt:yt?0:1,c:12,G:1,scrollV:0,rng:ht,spark:(r,c,l,g)=>jn(r,c,l,g),supernova:r=>{let c=yr(a.particles,r,ht),l=new Set(c);for(let g of a.particles){if(l.has(g))continue;let d=g.x-r.cx,x=g.y-r.cy,m=Math.hypot(d,x)||1;if(m<320){let h=(1-m/320)*4;g.vx+=d/m*h,g.vy+=x/m*h,g.heat=Math.max(g.heat,.8)}}En(Dt,vt,r.cx,r.cy,320,I,$,q.t,g=>void a.add(Xt(g))),jr(r),rn(r.el,"field:saturated",{peak:c.length}),r.el.dataset.fxCap==="1"&&(r.el.dataset.fxCap="0",Jt(r.el,"released",{accreted:0,load:0}),b("release")&&F("release",{body:r,count:c.length}),B.delete(r))},spawn:r=>{a.size>=$r||a.add(Xt(r))},neighbors:(r,c)=>a.neighbors(r,c),grid:r=>{let c=y.get(r);if(!c){let l=r.startsWith("wave")?"wave":r.startsWith("memory")?"memory":"diffuse";c=new te(I,$,l),y.set(r,c)}return c}};function jn(r,c,l,g){if(yt||Vt.length>260)return;let d=g?gt(g):[255,122,69],x=So(l);for(let m=0;m<x;m++){let h=ht()*6.28318,w=.8+ht()*(l>0?l:1)*1.7;Vt.push({x:r,y:c,vx:Math.cos(h)*w,vy:Math.sin(h)*w,life:1,c:d})}}function Xt(r={}){let c=r.size??.7+ht()*1.8;return{id:r.id??f++,x:r.x??ht()*I,y:r.y??ht()*$,vx:r.vx??(ht()-.5)*.25,vy:r.vy??(ht()-.5)*.18,z:r.z??(O.depth>0?ht()*O.depth:0),vz:r.vz??(O.depth>0?(ht()-.5)*.18:0),m:r.m??(O.mass?c:1),heat:r.heat??0,size:c,gx:r.gx??ht(),gy:r.gy??ht(),gz:r.gz??ht(),cap:null,...r.age!=null?{age:r.age}:{},...r.color!=null?{color:r.color}:{},...r.species!=null?{species:r.species}:{}}}let ge=[];function _r(){if(!ge.length)return;let r=a.particles;for(let c=0;c<r.length;c++){let l=ge[c%ge.length];r[c].atom=l;let g=typeof l.weight=="number"?Math.max(0,Math.min(1,l.weight)):.5;r[c].size*=.6+g*.9,r[c].m*=.6+g*1.2}}function Xn(){a.clear();let r=Math.round(130*O.density);for(let c=0;c<r;c++)a.add(Xt());_r(),vt=O.waves?Oo(O.waveBaseline):[],Dt=O.waves?Ro(vt.length,O.density,ht):[],qn=Dt.length}function xe(){let r=er(_.root);if(me.size>0){let g=new Set(r.map(d=>d.el));L=r.concat(me.bodies(le).filter(d=>!g.has(d.el)))}else L=r;Z.length>0&&(L=L.concat(Z)),Ne(L,I,$,Y,Q),Jr();let c=new Map(Bt.map(g=>[g.el,g]));Bt=[..._.root.querySelectorAll("[data-move]")].map(g=>{let d=g,x=d.getBoundingClientRect(),m=Number.parseFloat(d.dataset.mass??""),h=Number.isFinite(m)?m:Ao(x.width*x.height),w=(d.dataset.move??"").trim()==="layout",M=d.hasAttribute("data-dock"),S=d.hasAttribute("data-warp"),T=c.get(d);return T?{el:d,o:T.o,mEl:h,layout:w,dockable:M,dock:T.dock,docked:T.docked,warpable:S,warpCool:T.warpCool}:{el:d,o:{x:0,y:0,vx:0,vy:0},mEl:h,layout:w,dockable:M,dock:{dock:0},docked:null,warpable:S,warpCool:0}}),tn=[..._.root.querySelectorAll("[data-on]")].map(g=>{let d=g;return{el:d,body:L.find(x=>x.el===d)??null,bindings:kn(d.dataset.on??"")}}),en=[..._.root.querySelectorAll("[data-class]")].map(g=>{let d=g;return{el:d,body:L.find(x=>x.el===d)??null,bindings:kn(d.dataset.class??"")}});for(let g of L){if(!g.pair)continue;let d=null;try{d=_.root.querySelector(g.pair)}catch{d=null}g.pairBody=d?L.find(x=>x.el===d):void 0}let l=new Map(Gt.map(g=>[g.el,g]));for(let[g,d]of l)if(!_.root.contains(g))for(let x of d.emitted)x.remove();Gt=[..._.root.querySelectorAll("[data-emit]")].map(g=>{let d=g,x=d.dataset.emit??"",m=null;try{m=x?_.root.querySelector(x):null}catch{m=null}let h=Math.max(0,Math.round(Number.parseFloat(d.dataset.max??"")||8)),w=l.get(d);if(w){let M=w.emitted.filter(S=>S.isConnected);for(;M.length>h;)M.pop().remove();return{el:d,tmpl:m,cap:h,emitted:M}}return{el:d,tmpl:m,cap:h,emitted:[]}})}function Br(){for(let r of L)if(r.pairBody){if(!r.pairBody.el.isConnected){r.warpHas=!1,r.pairBody=void 0;continue}r.pairBody.vis?(r.warpX=r.pairBody.cx,r.warpY=r.pairBody.cy,r.warpHas=!0):r.warpHas=!1}else r.pair&&(r.warpHas=!1)}function Wr(){if(!(Gt.length===0||q.frameN%30!==0))for(let r of Gt){if(!r.tmpl||r.emitted.length>=r.cap)continue;let c=r.tmpl.cloneNode(!0);c.removeAttribute("id"),c.setAttribute("aria-hidden","true"),c.setAttribute("inert",""),c.dataset.fieldEmitted="",r.el.appendChild(c),r.emitted.push(c)}}function Hr(){if(tn.length!==0)for(let r of tn){let c=r.body?{d:r.body.d,on:r.body.on,accreted:r.body.accreted}:{d:0,on:r.el.dataset.active==="1",accreted:0};for(let l of r.bindings){let g=Sn(l.trigger,c);g&&!l.armed?(l.armed=!0,r.el.dispatchEvent(new CustomEvent(l.event,{bubbles:!0,detail:{trigger:l.trigger,d:c.d,on:c.on,accreted:c.accreted}}))):g||(l.armed=!1)}}}function qr(){if(en.length!==0)for(let r of en){let c=r.body?{d:r.body.d,on:r.body.on,accreted:r.body.accreted}:{d:0,on:r.el.dataset.active==="1",accreted:0};for(let l of r.bindings){let g=Sn(l.trigger,c);g&&!l.armed?(l.armed=!0,r.el.classList.add(l.event)):!g&&l.armed&&(l.armed=!1,r.el.classList.remove(l.event))}}}function Jt(r,c,l){r.dispatchEvent(new CustomEvent("field:"+c,{bubbles:!0,composed:!0,detail:l})),r.dispatchEvent(new CustomEvent("forces:"+c,{bubbles:!0,composed:!0,detail:l}))}function Yr(){for(let r of L){if(!r.vis||r.tokens.indexOf("sink")<0)continue;let c=r.el.dataset.fxCap==="1",l=pr(c,r.accreted>0);l.fire==="captured"?(r.el.dataset.fxCap="1",Jt(r.el,"captured",{accreted:r.accreted,load:In(r)}),b("absorb")&&F("absorb",{body:r,count:r.accreted}),B.set(r,r.accreted)):l.fire==="released"&&(r.el.dataset.fxCap="0",Jt(r.el,"released",{accreted:0,load:0}),b("release")&&F("release",{body:r,count:B.get(r)??0}),B.delete(r))}}let Ur=[{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"}],Gr=120;function rn(r,c,l){r.dispatchEvent(new CustomEvent(c,{bubbles:!0,composed:!0,detail:l}))}function Jn(r,c,l,g,d,x){let m=r.get(c);m||r.set(c,m=new Map);let h=m.get(g.metric);h||m.set(g.metric,h=new _e({enter:g.enter,exit:g.exit,debounceMs:Gr}));let w=h.update(d,x);w==="entered"?rn(l,g.rise,{metric:g.metric,value:d}):w==="exited"&&rn(l,g.fall,{metric:g.metric,value:d})}function Vr(r){for(let c of L)if(!(!c.vis||c.tokens.length===0))for(let l of Ur){let g;switch(l.metric){case"density":g=c.d;break;case"attention":O.attention&&(g=c.attn??1);break;case"entropy":g=c.metrics?.entropy;break}g!==void 0&&Jn(A,c,c.el,l,g,r)}for(let c of lt)Jn(j,c.agent,c.from.el,{metric:"memory",enter:.6,exit:.3,rise:"field:memory-threshold",fall:"field:memory-faded"},c.agent.memory,r)}function jr(r){for(let c of Bt)c.docked===r&&(c.docked=null,c.dock.dock=0,c.el.getAttribute("aria-hidden")==="true"&&c.el.removeAttribute("aria-hidden"),c.el.removeAttribute("inert"),c.el.style.opacity="",Jt(c.el,"released",{}))}function Xr(){if(Bt.length===0)return;let r=Bt.map(c=>{let l=c.el.getBoundingClientRect();return{x:l.left-Y+l.width/2,y:l.top-Q+l.height/2}});for(let c=0;c<Bt.length;c++){let l=Bt[c];if(!l.el.isConnected){l.docked&&(l.docked=null,l.dock.dock=0);continue}let g=r[c].x,d=r[c].y;if(l.docked){let M={x:g-l.o.x,y:d-l.o.y};l.dock.dock=gr(l.dock.dock,1);let S=xr(M,l.o,{x:l.docked.cx,y:l.docked.cy},l.dock.dock);l.el.style.transform=`translate(${S.tx.toFixed(2)}px, ${S.ty.toFixed(2)}px) scale(${S.scale.toFixed(3)})`,l.el.style.opacity=S.opacity.toFixed(3),l.dock.dock>=1&&l.el.getAttribute("aria-hidden")!=="true"&&(l.el.setAttribute("aria-hidden","true"),l.el.setAttribute("inert",""));continue}Tt.x=g,Tt.y=d,Tt.vx=0,Tt.vy=0,Tt.heat=0,Tt.cap=null;for(let M of L){if(!M.vis||M.tokens.length===0||M.el===l.el)continue;let S=M.cx-g,T=M.cy-d,k=Math.hypot(S,T);q.dx=S,q.dy=T,q.dist=k<1?1:k;for(let C of M.tokens)p.forces[C]?.apply(M,Tt,q)}Tt.cap=null;let x=Fo(l.o),m=Tt.vx+x.x,h=Tt.vy+x.y;if(l.layout){let M=Co({x:g,y:d},r,c),S=Po((T,k)=>a.near(T,k,40).length,g,d,16,6);m+=M.x+S.x,h+=M.y+S.y}let w={x:g-l.o.x,y:d-l.o.y};if(To(l.o,m,h,l.mEl,.9),l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.dockable){let M={x:w.x+l.o.x,y:w.y+l.o.y},S=L.find(T=>T.vis&&T.el!==l.el&&T.tokens.indexOf("sink")>=0&&Nn(M,T));S&&(l.docked=S,Jt(l.el,"captured",{sink:S.el}))}if(l.warpCool>0&&(l.warpCool-=1),l.warpable&&l.warpCool===0){let M={x:w.x+l.o.x,y:w.y+l.o.y},S=L.find(T=>T.vis&&T.el!==l.el&&T.warpHas&&T.tokens.indexOf("warp")>=0&&Nn(M,T));S&&(l.o.x=S.warpX-w.x,l.o.y=S.warpY-w.y,l.o.vx=0,l.o.vy=0,l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.warpCool=45,Jt(l.el,"relocated",{from:S.el}))}}}function Jr(){jt.length&&(jt=jt.filter(r=>r.el.isConnected?!0:(r.el.removeEventListener("pointerenter",r.enter),r.el.removeEventListener("pointerleave",r.leave),r.el.removeEventListener("focus",r.enter),r.el.removeEventListener("blur",r.leave),delete r.el.dataset.fxEngaged,!1))),_.root.querySelectorAll("[data-hot]").forEach(r=>{let c=r;if(c.dataset.fxEngaged==="1")return;c.dataset.fxEngaged="1";let l=()=>{c.dataset.active="1",pe=c.dataset.color??null;let d=c.closest("[data-index][data-threads]");if(d){let x=[...d.querySelectorAll("[data-hot]")].filter(m=>m!==c);sn(x.map(m=>({a:c,b:m,color:c.dataset.color??void 0})))}},g=()=>{c.dataset.active="0",pe=null,sn(null)};c.addEventListener("pointerenter",l),c.addEventListener("pointerleave",g),c.addEventListener("focus",l),c.addEventListener("blur",g),jt.push({el:c,enter:l,leave:g})})}function sn(r){Ze=(r??[]).map(c=>({a:c.a,b:c.b,c:gt(c.color??O.accent),seed:ht()*6.28}))}function Kr(){if(Ze.length===0)return;let r=q.t;n.globalCompositeOperation="lighter";for(let c of Ze){let l=c.a.getBoundingClientRect(),g=c.b.getBoundingClientRect(),d=l.left-Y+l.width/2,x=l.top-Q+l.height/2,m=g.left-Y+g.width/2,h=g.top-Q+g.height/2,[w,M,S]=c.c;n.strokeStyle=`rgba(${w},${M},${S},0.22)`,n.lineWidth=1,n.beginPath(),n.moveTo(d,x),n.lineTo(m,h),n.stroke();for(let T=0;T<3;T++){let k=(r*.6+c.seed+T/3)%1,C=d+(m-d)*k,H=x+(h-x)*k;n.fillStyle=`rgba(${w},${M},${S},${(1-k)*.9})`,n.beginPath(),n.arc(C,H,2.2,0,6.28318),n.fill()}}n.globalCompositeOperation="source-over"}let ve=0,Qr=[1/0,1.5,1.25,1];function we(r){if(!n)return;let c=Math.min(r||1,O.dprCap,Qr[ve]??1/0);e.width=Math.floor(I*c),e.height=Math.floor($*c),e.style.width=I+"px",e.style.height=$+"px",n.setTransform(c,0,0,c,0,0),i?.size(I,$,c)}function Kn(){let r=_.viewport();I=r.width,$=r.height,Y=r.originX??0,Q=r.originY??0,at=r.originX!=null||r.originY!=null,we(r.dpr),q.W=I,q.H=$,Ut=_.scrollHeight()-$||1;for(let c of y.values())c.resize(I,$);O.heatmap&&(K?K.resize(I,$):K=new de(I,$)),Xn(),xe()}function Zr(){let r=q.t,c=16;if(O.waveStyle==="circular"){let l=Yt||{x:I/2,y:$/2},g=Math.min(I,$)*.48;for(let d of vt){let[x,m,h]=d.color;n.beginPath();let w=.08,M=!0;for(let k=0;k<=2*Math.PI+.01;k+=w){let C=ce(d,k,r,g),H=l.x+Math.cos(k)*C,G=l.y+Math.sin(k)*C;M?(n.moveTo(H,G),M=!1):n.lineTo(H,G)}n.closePath();let S=d.baseFrac*g+d.offsetY,T=n.createRadialGradient(l.x,l.y,Math.max(0,S-d.amp),l.x,l.y,S+d.amp+80);T.addColorStop(0,`rgba(${x},${m},${h},${(.08+d.depth*.04)*ft})`),T.addColorStop(1,`rgba(${x},${m},${h},0)`),n.fillStyle=T,n.fill()}n.globalCompositeOperation="lighter";for(let d of vt){let[x,m,h]=d.color;n.beginPath();let w=.08,M=!0;for(let S=0;S<=2*Math.PI+.01;S+=w){let T=ce(d,S,r,g),k=l.x+Math.cos(S)*T,C=l.y+Math.sin(S)*T;M?(n.moveTo(k,C),M=!1):n.lineTo(k,C)}n.closePath(),n.lineWidth=5,n.strokeStyle=`rgba(${x},${m},${h},${(.05+d.depth*.04)*ft})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${x},${m},${h},${(.3+d.depth*.22)*ft})`,n.stroke()}n.globalCompositeOperation="source-over"}else{for(let l of vt){let[g,d,x]=l.color;n.beginPath(),n.moveTo(0,Et(l,0,r,$,1,1,xt));for(let w=0;w<=I;w+=c)n.lineTo(w,Et(l,w,r,$,1,1,xt));n.lineTo(I,$),n.lineTo(0,$),n.closePath();let m=l.baseFrac*$+l.offsetY-l.amp,h=n.createLinearGradient(0,m,0,m+320);h.addColorStop(0,`rgba(${g},${d},${x},${(.11+l.depth*.05)*ft})`),h.addColorStop(1,`rgba(${g},${d},${x},0)`),n.fillStyle=h,n.fill()}n.globalCompositeOperation="lighter";for(let l of vt){let[g,d,x]=l.color;n.beginPath(),n.moveTo(0,Et(l,0,r,$,1,1,xt));for(let m=0;m<=I;m+=c)n.lineTo(m,Et(l,m,r,$,1,1,xt));n.lineWidth=5,n.strokeStyle=`rgba(${g},${d},${x},${(.05+l.depth*.04)*ft})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${g},${d},${x},${(.3+l.depth*.22)*ft})`,n.stroke()}n.globalCompositeOperation="source-over"}}function ts(){n.globalCompositeOperation="lighter";let r=q.t,c=0;if(O.waveStyle==="circular"){let l=Yt||{x:I/2,y:$/2},g=Math.min(I,$)*.48;for(let d of Dt){let x=vt[d.wi];if(!x){c++;continue}q.dt&&(d.progress+=d.speed,d.progress>1?d.progress-=1:d.progress<0&&(d.progress+=1));let m=d.progress*2*Math.PI,h=ce(x,m,r,g)+d.phase*32,w=l.x+Math.cos(m)*h,M=l.y+Math.sin(m)*h,[S,T,k]=x.color,C=d.glow?.6+.4*Math.sin(r*2.2+c):.85;d.glow&&(n.fillStyle=`rgba(${S},${T},${k},${.16*C*ft})`,n.beginPath(),n.arc(w,M,d.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${S},${T},${k},${C*ft})`,n.beginPath(),n.arc(w,M,d.size,0,6.28318),n.fill(),c++}}else for(let l of Dt){let g=vt[l.wi];if(!g){c++;continue}q.dt&&(l.progress+=l.speed,l.progress>1?l.progress-=1:l.progress<0&&(l.progress+=1));let d=l.progress*I,x=Et(g,d,r,$,1,1,xt)+l.phase*32,[m,h,w]=g.color,M=l.glow?.6+.4*Math.sin(r*2.2+c):.85;l.glow&&(n.fillStyle=`rgba(${m},${h},${w},${.16*M*ft})`,n.beginPath(),n.arc(d,x,l.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${m},${h},${w},${M*ft})`,n.beginPath(),n.arc(d,x,l.size,0,6.28318),n.fill(),c++}n.globalCompositeOperation="source-over"}function es(){if(!O.attention)return;for(let l of L)l.attn=1;let r=L.filter(l=>l.vis&&l.tokens.length>0);if(r.length===0)return;let c=go(r);for(let l=0;l<r.length;l++)r[l].attn=c[l]}function ns(){if(!O.causality)return;let r=L.filter(l=>l.vis&&l.tokens.length>0);if(r.length===0)return;if(r.length===1){Qn(r[0],r[0].d);return}let c=xo(r.map(l=>({d:l.d,cx:l.cx,cy:l.cy})));for(let l=0;l<r.length;l++)Qn(r[l],wt(r[l].d+c[l],0,1))}function Qn(r,c){O.feedbackSink(r.el,{lit:c})}function os(){for(let r of L){if(!r.feedback)continue;let c=po(r.count,r.on);r.d+=(c-r.d)*.08;let l=r.writeTarget??r.el;if(r.fmax){let w=mo(r.fmin,r.fmax,r.d);he.get(l)!==w&&(he.set(l,w),l.style.fontVariationSettings=`"wght" ${w}`+(r.opsz?`, "opsz" ${r.opsz}`:""))}let g=K?K.norm(r.cx,r.cy):void 0,d=r.tokens.indexOf("sink")>=0&&r.capacity>0?In(r):void 0,x=Bo(r.thermo),m=r.metrics??(r.metrics={entropy:0,coherence:1,temperature:0});m.entropy+=(x.entropy-m.entropy)*.08,m.coherence+=(x.coherence-m.coherence)*.08,m.temperature+=(x.temperature-m.temperature)*.08;let h={density:r.d,heatmapDensity:g,load:d,entropy:m.entropy,coherence:m.coherence,temperature:m.temperature};O.feedbackSink(l,h),r.onFeedback?.(h)}}function rs(){if(Vt.length!==0){n.globalCompositeOperation="lighter";for(let r=Vt.length-1;r>=0;r--){let c=Vt[r];if(!c)continue;if(c.x+=c.vx,c.y+=c.vy,c.vx*=.9,c.vy*=.9,c.life*=.85,c.life<.05){Vt.splice(r,1);continue}let[l,g,d]=c.c;n.fillStyle=`rgba(${l},${g},${d},${.18*c.life})`,n.beginPath(),n.arc(c.x,c.y,2+c.life*4,0,6.28318),n.fill(),n.fillStyle=`rgba(${l},${g},${d},${c.life})`,n.beginPath(),n.arc(c.x,c.y,.6+c.life*1.5,0,6.28318),n.fill()}n.globalCompositeOperation="source-over"}}let Wt=null,be=null,Kt=null;function ss(){if(!K)return;let r=$>0?wt((1.15-ne/$)/.85,0,1):1;if(r<=.01)return;let c=K.cell,l=Math.max(1,Math.ceil(I/c)),g=Math.max(1,Math.ceil($/c));if(Wt||(Wt=_.createCanvas(),be=Wt.getContext("2d")),!!be){if((Wt.width!==l||Wt.height!==g)&&(Wt.width=l,Wt.height=g,Kt=null),Kt===null||$t%3===0){Kt===null&&(Kt=be.createImageData(l,g));let d=rt,x=Kt.data;for(let m=0;m<g;m++)for(let h=0;h<l;h++){let w=K.norm(h*c+c/2,m*c+c/2),M=(m*l+h)*4;x[M]=d[0],x[M+1]=d[1],x[M+2]=d[2],x[M+3]=Math.round(wt(w*.5*ft,0,1)*255)}be.putImageData(Kt,0,0)}n.globalCompositeOperation="lighter",n.imageSmoothingEnabled=!0,n.globalAlpha=r,n.drawImage(Wt,0,0,I,$),n.globalAlpha=1,n.globalCompositeOperation="source-over"}}function is(){O.background==="transparent"?O.render==="trails"?(n.globalCompositeOperation="destination-out",n.fillStyle="rgba(0,0,0,0.22)",n.fillRect(0,0,I,$),n.globalCompositeOperation="source-over"):n.clearRect(0,0,I,$):(O.render==="trails"?n.fillStyle="rgba(5,6,11,0.22)":n.fillStyle="rgb(5,6,11)",n.fillRect(0,0,I,$)),Zr(),K&&ve<2&&ss(),ts();let r=O.render!=="metaballs"&&O.render!=="streamlines";n.globalCompositeOperation="lighter";let c=rt,l=I/2,g=$*.4,d=Math.hypot(Math.max(l,I-l),Math.max(g,$-g))||1;if(ye===null||$t%6===0){ye=[];for(let m of L){if(!m.tint)continue;let h=(m.range||200)*1.4;ye.push({b:m,r2:h*h,rgb:gt(m.tint)})}}let x=ye;if(r)for(let m of a.particles){if(m.cap){n.fillStyle=`rgba(${c[0]},${c[1]},${c[2]},${.55*ft})`,n.beginPath(),n.arc(m.x,m.y,1.3,0,6.28318),n.fill();continue}let h=Math.min(1,Math.hypot(m.x-l,m.y-g)/d),w=h*h,M=m.heat;fo(He,w,M,c,O.gradientCool,O.gradientWarm);let S=He[0],T=He[1],k=He[2];if(x.length){let mt=0,nt=null;for(let st of x){let Ft=m.x-st.b.cx,At=m.y-st.b.cy,re=Ft*Ft+At*At;if(re>=st.r2)continue;let P=1-Math.sqrt(re/st.r2);P>mt&&(mt=P,nt=st.rgb)}if(nt){let st=mt*.7;S+=(nt[0]-S)*st,T+=(nt[1]-T)*st,k+=(nt[2]-k)*st}}if(m.color){let[mt,nt,st]=gt(m.color);S+=(mt-S)*.75,T+=(nt-T)*.75,k+=(st-k)*.75}let C=O.depth>0?1-Math.min(Math.abs(m.z??0)/O.depth,1)*.55:1,H=(m.size*(1-.4*w)+M*2)*C,G=wt((.5-.3*w+M*.5)*ft*C,0,1),ct=S|0,pt=T|0,bt=k|0;n.fillStyle=`rgba(${ct},${pt},${bt},${.12*G})`,n.beginPath(),n.arc(m.x,m.y,H+1.2,0,6.28318),n.fill(),n.fillStyle=`rgba(${ct},${pt},${bt},${G})`,n.beginPath(),n.arc(m.x,m.y,H,0,6.28318),n.fill()}if(rs(),Kr(),n.globalCompositeOperation="source-over",O.render==="links"){n.globalCompositeOperation="lighter";let m=rt,h=90;n.lineWidth=.6;for(let w of a.particles)if(!w.cap)for(let M of a.neighbors(w,h)){if(M.x<w.x||M.x===w.x&&M.y<w.y)continue;let S=ir(Math.hypot(M.x-w.x,M.y-w.y),h);S<=0||(n.strokeStyle=`rgba(${m[0]},${m[1]},${m[2]},${S})`,n.beginPath(),n.moveTo(w.x,w.y),n.lineTo(M.x,M.y),n.stroke())}n.globalCompositeOperation="source-over"}if(O.render==="metaballs"){let M=Math.ceil(I/16)+1,S=Math.ceil($/16)+1;!It||It.length!==M*S?It=new Float32Array(M*S):It.fill(0);for(let k of a.particles)k.cap||Cn(It,M,S,16,k.x,k.y,34,1);let T=rt;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${T[0]},${T[1]},${T[2]},${.5*ft})`,n.lineWidth=1.4,n.lineCap="round",n.beginPath();for(let k=0;k<S-1;k++)for(let C=0;C<M-1;C++){let H=It[k*M+C],G=It[k*M+C+1],ct=It[(k+1)*M+C+1],pt=It[(k+1)*M+C],bt=An(H,G,ct,pt,.9);if(!bt.length)continue;let mt=C*16,nt=k*16;for(let st of bt)n.moveTo(mt+st.x1*16,nt+st.y1*16),n.lineTo(mt+st.x2*16,nt+st.y2*16)}n.stroke(),n.globalCompositeOperation="source-over"}if(O.render==="voronoi"){let w=Math.ceil(I/18)+1,M=Math.ceil($/18)+1;(!oe||oe.length!==w*M)&&(oe=new Int32Array(w*M));let S=a.particles,T=new Map;for(let C=0;C<S.length;C++)T.set(S[C],C);for(let C=0;C<M;C++)for(let H=0;H<w;H++){let G=H*18,ct=C*18,pt=a.near(G,ct,54),bt=-1;if(pt.length){let mt=ar(G,ct,pt);mt>=0&&(bt=T.get(pt[mt])??-1)}oe[C*w+H]=bt}let k=rt;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${k[0]},${k[1]},${k[2]},${.32*ft})`,n.lineWidth=1,n.beginPath();for(let C of cr(oe,w,M))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==="streamlines"||O.render==="flow"){let h=rt;if(n.lineWidth=1,n.lineCap="round",ue===null||ut||$t%3===0){let w=[],M=[],S=0;for(let T=46/2;T<I;T+=46)for(let k=46/2;k<$;k+=46){let{fx:C,fy:H}=Zt(L,p.forces,q,T,k);if(ut){let ct=ae(We,T,k,ut,.04);C+=ct.x,H+=ct.y}let G=Math.hypot(C,H);if(!(G>1e-9)){M.push({gx:T,gy:k});continue}w.push({gx:T,gy:k,ux:C/G,uy:H/G,mag:G}),G>S&&(S=G)}_t===0?_t=S:_t=S>_t?_t*.7+S*.3:_t*.9+S*.1,ue=w,Ke=M}if(Ke.length){n.fillStyle=`rgba(${h[0]},${h[1]},${h[2]},0.05)`;for(let w of Ke)n.fillRect(w.gx-.5,w.gy-.5,1,1)}if(_t>0&&ue)for(let w of ue){let M=Math.sqrt(w.mag/_t),S=46*.46*(.28+.72*M),T=w.gx+w.ux*S,k=w.gy+w.uy*S;n.strokeStyle=`rgba(${h[0]},${h[1]},${h[2]},${wt(.1+M*.5,0,.72)})`,n.beginPath(),n.moveTo(w.gx,w.gy),n.lineTo(T,k);let C=3.4;n.moveTo(T,k),n.lineTo(T-w.ux*C-w.uy*C*.6,k-w.uy*C+w.ux*C*.6),n.moveTo(T,k),n.lineTo(T-w.ux*C+w.uy*C*.6,k-w.uy*C-w.ux*C*.6),n.stroke()}}}function Zn(r){return(r===void 0?[]:Array.isArray(r)?r:[r]).filter(l=>l!=="off")}function to(r,c,l){let d=rt;if(Qe===null||ut||$t%3===0){let h=[],w=0;for(let M=44/2;M<I;M+=44)for(let S=44/2;S<$;S+=44){let{fx:T,fy:k}=Zt(L,p.forces,q,M,S);if(ut){let H=ae(We,M,S,ut,.04);T+=H.x,k+=H.y}let C=Math.hypot(T,k);C>1e-9&&(h.push({gx:M,gy:S,ux:T/C,uy:k/C,mag:C}),C>w&&(w=C))}Nt===0?Nt=w:Nt=w>Nt?Nt*.7+w*.3:Nt*.9+w*.1,Qe=h}if(Nt<=0)return;let x={r:d[0],g:d[1],b:d[2],alpha:0,width:1.2},m=new Float64Array(12);for(let h of Qe){let w=l?wt(h.mag/Nt,0,1):Math.sqrt(h.mag/Nt),M=44*.5*(.25+.75*w),S=h.gx+h.ux*M,T=h.gy+h.uy*M,k=3.6;m[0]=h.gx,m[1]=h.gy,m[2]=S,m[3]=T,m[4]=S,m[5]=T,m[6]=S-h.ux*k-h.uy*k*.6,m[7]=T-h.uy*k+h.ux*k*.6,m[8]=S,m[9]=T,m[10]=S-h.ux*k+h.uy*k*.6,m[11]=T-h.uy*k-h.ux*k*.6,x.alpha=wt(.12+w*.55,0,.8),r.segments(m,x)}}function as(r){let c=ko(L);if(!c.length)return;let l=bo((x,m)=>Oe(L,p.forces,x,m),c,{step:6,maxSteps:200,bounds:{w:I,h:$},loopDist:8}),g=rt,d={r:g[0],g:g[1],b:g[2],alpha:.42,width:1.1};for(let x of l){if(x.length<2)continue;let m=new Float32Array(x.length*2);for(let h=0;h<x.length;h++)m[h*2]=x[h].x,m[h*2+1]=x[h].y;r.polyline(m,d)}}function cs(r){let l=22*O.gridWarp,g=48*.46,d=Math.floor(I/48)+2,x=Math.floor($/48)+2,m=new Float32Array(d*x),h=new Float32Array(d*x),w=0,M=new Float32Array(d*x);for(let P=0;P<x;P++)for(let W=0;W<d;W++){let{fx:et,fy:V}=Zt(L,p.forces,q,W*48,P*48),ot=Math.hypot(et,V),Mt=P*d+W;ot>1e-9&&(m[Mt]=et/ot,h[Mt]=V/ot,M[Mt]=ot,ot>w&&(w=ot))}let S=[rt,[120,110,255],[240,70,255],[255,50,130]],T=8,k=P=>w>0?Math.sqrt(M[P]/w):0,C=P=>Math.round(k(P)*T),H=P=>{let W=P/T,et=Mn(S,W);return{r:et[0],g:et[1],b:et[2],alpha:Math.min(1,O.gridIntensity*(.3+.85*W)),width:W>.55?1.4:1}},G=new Float32Array(d*x),ct=new Float32Array(d*x);for(let P=0;P<d*x;P++){let W=k(P);G[P]=m[P]*W*l,ct[P]=h[P]*W*l}let pt=new Float32Array(d*x),bt=new Float32Array(d*x);for(let P=0;P<x;P++)for(let W=0;W<d;W++){let et=0,V=0,ot=0;for(let Ct=-1;Ct<=1;Ct++)for(let Pt=-1;Pt<=1;Pt++){let zt=W+Pt,Ot=P+Ct;if(zt<0||Ot<0||zt>=d||Ot>=x)continue;let Qt=Ot*d+zt;et+=G[Qt],V+=ct[Qt],ot++}let Mt=P*d+W;pt[Mt]=et/ot,bt[Mt]=V/ot}let mt=48*1.5,nt=(P,W)=>{let et=W*d+P,V=pt[et],ot=bt[et],Mt=Math.hypot(V,ot);Mt>g&&(V=V/Mt*g,ot=ot/Mt*g);let Ct=P*48,Pt=W*48,zt=Math.min(Ct,I-Ct,Pt,$-Pt),Ot=zt<=0?0:zt<mt?zt/mt:1;return[Ct+V*Ot,Pt+ot*Ot]},st=4,Ft=P=>{let W=P.length>>1;if(W<3)return P;let et=[P[0],P[1]];for(let V=0;V<W-1;V++){let ot=(V>0?V-1:0)<<1,Mt=V<<1,Ct=V+1<<1,Pt=(V+2<W?V+2:W-1)<<1,zt=P[ot],Ot=P[ot+1],Qt=P[Mt],ln=P[Mt+1],dn=P[Ct],fn=P[Ct+1],io=P[Pt],ao=P[Pt+1];for(let hn=1;hn<=st;hn++){let se=hn/st,un=se*se,co=un*se;et.push(.5*(2*Qt+(-zt+dn)*se+(2*zt-5*Qt+4*dn-io)*un+(-zt+3*Qt-3*dn+io)*co),.5*(2*ln+(-Ot+fn)*se+(2*Ot-5*ln+4*fn-ao)*un+(-Ot+3*ln-3*fn+ao)*co))}}return et},At=(P,W)=>Math.max(C(P*d+W),C(P*d+W+1)),re=(P,W)=>Math.max(C(W*d+P),C((W+1)*d+P));for(let P=0;P<x;P++){let W=At(P,0),et=[...nt(0,P),...nt(1,P)];for(let V=1;V<d-1;V++){let ot=At(P,V);ot===W?et.push(...nt(V+1,P)):(r.polyline(Ft(et),H(W)),et=[...nt(V,P),...nt(V+1,P)],W=ot)}r.polyline(Ft(et),H(W))}for(let P=0;P<d;P++){let W=re(P,0),et=[...nt(P,0),...nt(P,1)];for(let V=1;V<x-1;V++){let ot=re(P,V);ot===W?et.push(...nt(P,V+1)):(r.polyline(Ft(et),H(W)),et=[...nt(P,V),...nt(P,V+1)],W=ot)}r.polyline(Ft(et),H(W))}}let kt=null;function eo(r,c,l){let x=Math.ceil(I/24)+1,m=Math.ceil($/24)+1;!kt||kt.length!==x*m?kt=new Float32Array(x*m):kt.fill(0);let h=!1;for(let k of a.particles){if(k.cap)continue;let C=c(k);C<=0||(h=!0,Cn(kt,x,m,24,k.x,k.y,42,C))}if(!h)return;let w=0;for(let k=0;k<kt.length;k++)kt[k]>w&&(w=kt[k]);if(w<=0)return;let M=rt,S=[.25,.5,.78],T=[];for(let k=0;k<S.length;k++){let C=S[k]*w;T.length=0;for(let H=0;H<m-1;H++)for(let G=0;G<x-1;G++){let ct=kt[H*x+G],pt=kt[H*x+G+1],bt=kt[(H+1)*x+G+1],mt=kt[(H+1)*x+G],nt=An(ct,pt,bt,mt,C);if(!nt.length)continue;let st=G*24,Ft=H*24;for(let At of nt)T.push(st+At.x1*24,Ft+At.y1*24,st+At.x2*24,Ft+At.y2*24)}T.length&&r.segments(T,{r:M[0],g:M[1],b:M[2],alpha:l*(.45+.55*(k/(S.length-1))),width:1+k*.3})}}function ls(r){let d=rt,x={r:d[0],g:d[1],b:d[2],alpha:0,width:1.1},m=new Float64Array(4);for(let h=104/2;h<I;h+=104)for(let w=104/2;w<$;w+=104){let M=h,S=w;for(let T=0;T<24;T++){let{fx:k,fy:C}=Zt(L,p.forces,q,M,S);if(ut){let pt=ae(We,M,S,ut,.04);k+=pt.x,C+=pt.y}let H=Math.hypot(k,C);if(!(H>1e-9))break;let G=M+k/H*9,ct=S+C/H*9;if(G<0||ct<0||G>I||ct>$)break;m[0]=M,m[1]=S,m[2]=G,m[3]=ct,x.alpha=.34*(1-T/24),r.segments(m,x),M=G,S=ct}}}function ds(r){let c=rt;for(let l of L){if(!l.vis||!l.feedback)continue;let g=`d ${l.d.toFixed(2)}`,d=l.cx+l.hw+8,x=l.cy;r.rect(d-3,x-7,r.measureText(g)+6,14,c[0],c[1],c[2],wt(.3+l.d*.55,0,.85)),r.text(g,d,x+.5,5,6,11,.92)}}function fs(r,c){if(r.clear(),!(!c.length||I===0||$===0))for(let l of c){l==="streamlines"?to(r,!1,!1):l==="force-vectors"?to(r,!1,!0):l==="field-lines"?as(r):l==="grid"?cs(r):l==="temperature"?eo(r,d=>d.heat,.5):l==="energy"?eo(r,d=>.5*d.m*(d.vx*d.vx+d.vy*d.vy),.42):l==="path"?ls(r):l==="data"&&ds(r);let g=dt.get(l);g&&g(r,q,I,$)}}function an(r){$t++,q.t=(r-Vn)/1e3,q.frameN=$t;let c=Number.isFinite(Je)?(r-Je)/16.6667:1;if(Je=r,q.dt=yt?0:wt(c,.2,2),ft<1&&(ft=Math.min(1,ft+.012)),qo(q.form,Hn,.03),at){let h=_.viewport();Y=h.originX??0,Q=h.originY??0}let l=_.scrollY(),g=l-ne;if(q.scrollV=(q.scrollV??0)*.7+Math.abs(g)*.3,ne=l,g!==0&&!at)for(let h of L)h.cy-=g;for(let h of vt){let w=l*(.025+h.depth*.08);h.offsetY+=(w-h.offsetY)*.04}if(L.length&&$t%6===0&&(Ne(L,I,$,Y,Q),u(L),mr(L,q.supernova)),lt.length&&q.dt){let h=q.dt/60;for(let w of lt)ur(w.agent,w.from.d>.08,0,h)}let d=null;for(let h of L)if(h.on&&h.vis){d=h;break}let x=ut??d;if(xt.k+=((x?1:0)-xt.k)*.07,x){let h=ut?ut.x:d.cx,w=ut?ut.y:d.cy;xt.x=xt.x?xt.x+(h-xt.x)*.16:h,xt.y=xt.y?xt.y+(w-xt.y)*.16:w}$t%30===0&&(Ut=_.scrollHeight()-$||1);let m=pe?gt(pe):Mn(Gn,l/Ut);if(rt=[rt[0]+(m[0]-rt[0])*.08,rt[1]+(m[1]-rt[1])*.08,rt[2]+(m[2]-rt[2])*.08],O.accent=bn(rt),a.reindex(),es(),q.dt&&Do(L,a.particles),ut&&q.dt)for(let h of a.particles){if(h.cap)continue;let w=ae(We,h.x,h.y,ut,.6);h.vx+=w.x,h.vy+=w.y}if(O.waveStyle==="circular")if(O.waveCenter)Yt=typeof O.waveCenter=="function"?O.waveCenter():O.waveCenter;else{let h=L.find(w=>w.tokens.includes("star")||w.tokens.includes("vortex"));h?Yt={x:h.cx,y:h.cy}:Yt={x:I/2,y:$/2}}else Yt=null;if(Br(),Go({store:a,bodies:L,env:q,forces:p.forces,conditions:p.conditions,waves:vt,waveStyle:O.waveStyle,waveCenter:Yt,separation:O.separation}),Lt&&(Lt.x=Yn,Lt.y=Un,Lt.vx=0,Lt.vy=0,Lt.heat=Math.min(1,Lt.heat+.2)),q.dt){for(let h of y.values())h.step();K&&K.update(a.particles),No(a,Dt,qn,vt,I,$,q.t,ht),Lo(Dt,vt,L,p.forces,I,$,q.t,h=>void a.add(Xt(h))),Xr(),Wr()}if(os(),ns(),Hr(),qr(),Yr(),Vr(r),R(),n&&O.render!=="none"&&Wn&&(!yt||$t%4===0)&&(is(),i)){let h=Zn(O.overlay);h.length&&fs(i,h)}qt=_.raf(an)}function cn(r){let c=Fe[r];c&&(Hn={...c.preset})}let Me="",no=Vn;function oo(){let r=_.viewport().height*.5,c="";_.root.querySelectorAll("[data-formation]").forEach(l=>{let g=l.getBoundingClientRect();g.top<=r&&g.bottom>=r&&(c=l.dataset.formation??"")}),c&&c!==Me&&(Me=c,cn(c))}let ro=()=>void(no=Xe()),hs=()=>{ro(),oo()},so=setInterval(()=>{Xe()-no>6e3&&Me!=="ambient"&&(Me="ambient",cn("ambient"))},1200);so.unref?.();let us=()=>Kn();Kn();let ys=()=>{_.hidden()?(_.cancelRaf(qt),qt=0):qt||(qt=_.raf(an))};return tt.push(_.onResize(us)),tt.push(_.onScroll(hs)),tt.push(_.onVisibility(ys)),tt.push(_.onInput(ro)),tt.push(_.onBodyEvent(nr,Nr)),tt.push(_.onBodyEvent(or,Lr)),tt.push(_.onBodyEvent(rr,Dr)),oo(),qt=_.raf(an),{scan:xe,rescan:xe,setAccent:r=>{O.accent=r,rt=gt(r)},setPalette:r=>{let c=Ae(r);Gn=c.map(gt);let l=c[0];l&&(O.accent=l,rt=gt(l))},setFormation:cn,setWaveStyle:r=>{O.waveStyle=r},setWaveCenter:r=>{O.waveCenter=r},setSeparation:r=>{O.separation=r>=0?r:0},setAttention:r=>{if(O.attention=r,!r)for(let c of L)c.attn=1},setCausality:r=>{if(O.causality=r,!r)for(let c of L)c.el.style.removeProperty("--lit"),c.el.dataset.fxLit="0"},setRender:r=>{if(r!=="none"&&!n){if(n=e.getContext("2d"),!n){console.warn(`Fundamental: setRender('${r}') could not acquire a 2d context; staying in render 'none'`);return}o&&!s&&(s=o.getContext("2d"),s&&!i&&(i=t.overlayBackend??Pn(o,s))),we(_.viewport().dpr)}O.render=r},setOverlay:r=>{O.overlay=r,Zn(r).length||i?.clear()},setHeatmap:r=>{if(O.heatmap=r,r)!K&&I>0&&(K=new de(I,$));else if(K){K.clear(),K=null;for(let c of L)(c.writeTarget??c.el).style.removeProperty("--field-heatmap-density")}},setDprCap:r=>{O.dprCap=r>0?r:2,n&&we(_.viewport().dpr)},setQualityTier:r=>{let c=Math.max(0,Math.min(3,Math.floor(r||0)));c!==ve&&(ve=c,n&&we(_.viewport().dpr))},threads:sn,burst:(r,c,l)=>{for(let d of a.particles){let x=zo(d.x-r,d.y-c,160,6,d.z??0);x.heat!==0&&(d.vx+=x.vx,d.vy+=x.vy,x.vz&&(d.vz=(d.vz??0)+x.vz),d.heat=Math.max(d.heat,x.heat),l&&(d.color=l))}En(Dt,vt,r,c,160,I,$,q.t,d=>void a.add(Xt(d))),jn(r,c,2,l)},flowTo:(r,c,l)=>{ut=vo(r,c,l)},clearFlow:()=>{ut=null},seed:r=>{ge=r,Xn()},atomAt:(r,c)=>{let l=null,g=1/0;for(let d of a.near(r,c,24)){if(d.atom==null)continue;let x=(d.x-r)**2+(d.y-c)**2+(d.z??0)**2;x<g&&(g=x,l=d.atom)}return l},focusAt:(r,c)=>{let l=null,g=1/0;for(let d of a.near(r,c,24)){if(d.atom==null)continue;let x=(d.x-r)**2+(d.y-c)**2+(d.z??0)**2;x<g&&(g=x,l=d)}return Lt=l,l?(Yn=l.x,Un=l.y,l.atom??null):null},clearFocus:()=>{Lt=null},particleCount:()=>a.size,readParticles:r=>{let c=a.particles,l=Math.floor(r.length/5),g=0;for(let d=0;d<c.length&&g<l;d++){let x=c[d];if(x.report!==void 0)continue;let m=g*5;r[m]=x.x,r[m+1]=x.y,r[m+2]=x.z??0,r[m+3]=x.heat,r[m+4]=x.size,g++}return g},readParticleIds:r=>{let c=a.particles,l=0;for(let g=0;g<c.length&&l<r.length;g++){let d=c[g];d.report===void 0&&(r[l++]=d.id??0)}return l},readParticleChannels:(r,c)=>{let l=a.particles,g=0;for(let d=0;d<l.length;d++){let x=l[d];if(!("report"in x&&x.report!==void 0)){if(g>=Math.min(...c.map(m=>m.length)))break;for(let m=0;m<r.length&&!(m>=c.length);m++){let h=r[m];c[m][g]=h==="x"?x.x:h==="y"?x.y:h==="z"?x.z??0:h==="vx"?x.vx:h==="vy"?x.vy:h==="heat"?x.heat:h==="size"?x.size:h==="m"?x.m:h==="id"?x.id??0:h==="age"?x.age??0:h==="charge"?x.charge??0:0}g++}}return g},registerOverlay:(r,c)=>(dt.set(r,c),()=>{dt.delete(r)}),addAgent:r=>{let c=Xt({x:r.x,y:r.y,z:r.z,species:r.species});return c.vx=0,c.vy=0,r.z===void 0&&O.depth<=0&&(c.z=0),r.mass!==void 0&&(c.m=r.mass),c.maxSpeed=r.maxSpeed,c.report=r.report,a.add(c),{particle:c,remove:()=>a.remove(c)}},addBody:r=>{let c={"data-body":Array.isArray(r.tokens)?r.tokens.join(" "):String(r.tokens)};r.strength!=null&&(c["data-strength"]=String(r.strength)),r.range!=null&&(c["data-range"]=String(r.range)),r.spin!=null&&(c["data-spin"]=String(r.spin)),r.angle!=null&&(c["data-angle"]=String(r.angle)),r.color!=null&&(c["data-color"]=r.color);let l=()=>{let h=r.rect();return{left:h.left,top:h.top,right:h.left+h.width,bottom:h.top+h.height,width:h.width,height:h.height,x:h.left,y:h.top,toJSON:()=>({})}},g={tagName:"DIV",id:"",className:"",dataset:r.color!=null?{color:r.color}:{},getAttribute:h=>c[h]??null,hasAttribute:h=>h in c,getBoundingClientRect:l,dispatchEvent:()=>!0,setAttribute:()=>{},removeAttribute:()=>{},style:{setProperty:()=>{},removeProperty:()=>{},getPropertyValue:()=>""}},d=le(g);d.rect=l,d.data=r.data,d.feedback=!0;let x={};d.onFeedback=h=>{Object.assign(x,h),r.onFeedback?.(h)},Z.push(d),L=L.concat(d),Ne([d],I,$,Y,Q);let m={data:r.data,get channels(){return x},set:h=>{h.strength!=null&&(c["data-strength"]=String(h.strength)),h.range!=null&&(c["data-range"]=String(h.range)),h.spin!=null&&(c["data-spin"]=String(h.spin)),h.angle!=null&&(c["data-angle"]=String(h.angle)),h.color!=null&&(c["data-color"]=h.color,g.dataset.color=h.color,d.tint=h.color)},remove:()=>{let h=Z.indexOf(d);h>=0&&Z.splice(h,1),L=L.filter(w=>w!==d);for(let w=lt.length-1;w>=0;w--){let M=lt[w];(M.from===d||M.to===d)&<.splice(w,1)}}};return it.set(m,d),m},addEdge:(r,c,l)=>{let g=it.get(r),d=it.get(c);if(!g||!d)throw new Error("addEdge: both arguments must be handles returned by addBody on this field.");let x={id:`e${D++}`,from:"",to:"",type:l?.type??"related",strength:l?.strength??.5,tension:0,memory:0,active:!1},m={agent:x,from:g,to:d,fromData:r.data,toData:c.data};return lt.push(m),{set:h=>{h.strength!=null&&(x.strength=h.strength<0?0:h.strength>1?1:h.strength),h.type!=null&&(x.type=h.type)},remove:()=>{let h=lt.indexOf(m);h>=0&<.splice(h,1)}}},readEdges:()=>lt.map(r=>({from:r.fromData,to:r.toData,type:r.agent.type,strength:r.agent.strength,memory:r.agent.memory,active:r.agent.active})),addField:(r,c)=>(J.set(r,c),{name:r,set:l=>{J.set(r,l)},remove:()=>{J.delete(r)}}),sampleField:(r,c,l)=>{let g=J.get(r);return g?g(c,l):0},energy:()=>Sr(a.particles),sample:(r,c)=>{let{fx:l,fy:g}=Zt(L,p.forces,q,r,c);return{x:l,y:g}},sampleScalar:(r,c)=>K?K.norm(r,c):(Fn("NOOP_NO_HEATMAP","sampleScalar() returned 0 because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),0),sampleGradient:(r,c)=>K?K.gradient(r,c):(Fn("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:r=>q.grid(r),on:(r,c)=>{let l=v.get(r);return l||(l=new Set,v.set(r,l)),l.add(c),()=>void l.delete(c)},version:ke,scrollV:()=>q.scrollV??0,setVisible:r=>{Wn=r},setBackground:r=>{O.background=r,r==="transparent"&&n&&n.clearRect(0,0,I,$)},destroy:()=>{_.cancelRaf(qt),clearInterval(so);for(let r of tt)r();for(let r of jt)r.el.removeEventListener("pointerenter",r.enter),r.el.removeEventListener("pointerleave",r.leave),r.el.removeEventListener("focus",r.enter),r.el.removeEventListener("blur",r.leave),delete r.el.dataset.fxEngaged;jt=[];for(let r of Bt)(r.docked||r.dock.dock>0)&&(r.docked=null,r.dock.dock=0,r.el.style.opacity="",r.el.getAttribute("aria-hidden")==="true"&&r.el.removeAttribute("aria-hidden"),r.el.removeAttribute("inert"));for(let r of Gt)for(let c of r.emitted)c.remove();Gt=[],a.clear()}}}var Ye={};function Ue(){return Ye.reducedMotion!==void 0?Ye.reducedMotion:typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function Ge(){return Ye.hidden!==void 0?Ye.hidden:typeof document<"u"&&document.hidden}var ta=["--field-density","--d"],zr=!1;function Tr(){if(zr)return[];zr=!0;let e=globalThis.CSS;if(!e||typeof e.registerProperty!="function")return[];let t=[];for(let n of ta)try{e.registerProperty({name:n,syntax:"<number>",inherits:!0,initialValue:"0"}),t.push(n)}catch{}return t}var Fr=["pointerdown","wheel","keydown","touchstart"];function ee(){return Tr(),{root:document,viewport:()=>({width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio||1}),scrollY:()=>window.scrollY||0,scrollHeight:()=>document.documentElement.scrollHeight,reducedMotion:()=>Ue(),hidden:()=>Ge(),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 Fr)window.addEventListener(t,e,{passive:!0});return()=>{for(let t of Fr)window.removeEventListener(t,e)}},onBodyEvent:(e,t)=>(document.addEventListener(e,t),()=>document.removeEventListener(e,t))}}var Ar=["pointerdown","wheel","keydown","touchstart"];function Cr(e){return{root:e,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:()=>Ue(),hidden:()=>Ge(),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 Ar)e.addEventListener(n,t,{passive:!0});return()=>{for(let n of Ar)e.removeEventListener(n,t)}},onBodyEvent:(t,n)=>(e.addEventListener(t,n),()=>e.removeEventListener(t,n))}}function Pr(e,t={}){return qe(e,{...t,host:ee()})}function Ve(e,t={}){let{host:n,bounds:o,...s}=t,i=n??(o?Cr(o):ee());return qe(e,{...s,host:i})}function Bn(){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 fe(e=document.body){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText=dr,e.appendChild(t),t}function Or(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 Rr(e={}){Bn();let{target:t=document.body,...n}=e,o=fe(t),s=Pr(o,n);return{...s,destroy:()=>{s.destroy(),o.remove()}}}var je=class{constructor(t={}){U(this,"canvas");U(this,"field");U(this,"managed");Bn();let{canvas:n,target:o,bounds:s,...i}=t;this.managed=!n,this.canvas=n??(s?Or(s):fe(o)),this.field=Ve(this.canvas,s?{...i,bounds:s}:i)}scan(){this.field.scan()}rescan(){this.field.rescan()}setAccent(t){this.field.setAccent(t)}setPalette(t){this.field.setPalette(t)}setFormation(t){this.field.setFormation(t)}setWaveStyle(t){this.field.setWaveStyle(t)}setWaveCenter(t){this.field.setWaveCenter(t)}setSeparation(t){this.field.setSeparation(t)}setAttention(t){this.field.setAttention(t)}setCausality(t){this.field.setCausality(t)}setHeatmap(t){this.field.setHeatmap(t)}setDprCap(t){this.field.setDprCap(t)}setQualityTier(t){this.field.setQualityTier(t)}setRender(t){this.field.setRender(t)}setOverlay(t){this.field.setOverlay(t)}threads(t){this.field.threads(t)}burst(t,n,o){this.field.burst(t,n,o)}flowTo(t,n,o){this.field.flowTo(t,n,o)}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,o){return this.field.addEdge(t,n,o)}readEdges(){return this.field.readEdges()}addField(t,n){return this.field.addField(t,n)}sampleField(t,n,o){return this.field.sampleField(t,n,o)}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)}on(t,n){return this.field.on(t,n)}get version(){return this.field.version}scrollV(){return this.field.scrollV()}setVisible(t){this.field.setVisible(t)}setBackground(t){this.field.setBackground(t)}destroy(){this.field.destroy(),this.managed&&this.canvas.remove()}};return bs(ea);})();
|
|
2
|
+
"use strict";var Fundamental=(()=>{var Ee=Object.defineProperty;var ps=Object.getOwnPropertyDescriptor;var ms=Object.getOwnPropertyNames;var gs=Object.prototype.hasOwnProperty;var xs=(e,t,n)=>t in e?Ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var vs=(e,t)=>{for(var n in t)Ee(e,n,{get:t[n],enumerable:!0})},ws=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ms(t))!gs.call(e,s)&&s!==n&&Ee(e,s,{get:()=>t[s],enumerable:!(o=ps(t,s))||o.enumerable});return e};var bs=e=>ws(Ee({},"__esModule",{value:!0}),e);var U=(e,t,n)=>xs(e,typeof t!="symbol"?t+"":t,n);var ea={};vs(ea,{CONDITIONS:()=>xn,FIELD_VERSION:()=>ke,FORCES:()=>Se,FORMATIONS:()=>gn,FieldField:()=>je,PALETTE:()=>ze,browserHost:()=>ee,createField:()=>Ve,cssFeedbackSink:()=>Rn,headlessHost:()=>fr,makeFieldCanvas:()=>fe,mountField:()=>Rr});var ke="0.9.1";var Se=[{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"}],lo=Object.fromEntries(Se.map(e=>[e.id,e])),ze=Se.map(e=>e.color),ie=["#4da3ff","#2dd4bf","#a78bfa","#ff6e9c","#ff9d5c"],yn=["spotlight","screen","resonate"],Ms=["spawn"],pn=300,mn=120;function Es(e){return yn.includes(e)?"modifier":Ms.includes(e)?"source":"force"}function Te(e){let t=[],n=[],o=[];for(let s of e){let i=Es(s);i==="modifier"?t.push(s):i==="source"?o.push(s):n.push(s)}return t.length>1&&t.sort((s,i)=>yn.indexOf(s)-yn.indexOf(i)),{modifiers:t,forces:n,sources:o}}var gn=[{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}}],Fe=Object.fromEntries(gn.map(e=>[e.id,e]));var xn=[{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}],sa=Object.fromEntries(xn.map(e=>[e.id,e]));var ks={ours:ie,heatmap:["#2b3a8c","#2d8fd4","#3fd07a","#ffe14d","#ff8a3d","#e23b3b"],infrared:["#2a0a4a","#8e24aa","#e53935","#ff8f00","#ffd54f","#fffde7"],spectrum:["#ff3b30","#ff9500","#ffcc00","#34c759","#00c7be","#007aff","#af52de"]};function Ae(e){return Array.isArray(e)?e.length>0?e:ie:typeof e=="string"?ks[e]??ie:ie}var vn={warm:{cool:[255,224,200],warm:[255,110,80],wave:["#ff8a5c","#f0628e","#ffc46b"]},cool:{cool:[206,226,255],warm:[74,132,255],wave:["#5c8aff","#62a0f0","#6bc4ff"]},mono:{cool:[232,232,238],warm:[148,148,158],wave:["#8a8a96","#b0b0bc","#9a9aa6"]}},wn="warm";var wt=(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,o=Number.parseInt(n.slice(0,6),16);return Number.isNaN(o)?[77,163,255]:[o>>16&255,o>>8&255,o&255]}var Ss=[255,224,200],zs=[255,110,80];function fo(e,t,n,o,s=Ss,i=zs){let a=s[0]+(i[0]-s[0])*t,f=s[1]+(i[1]-s[1])*t,y=s[2]+(i[2]-s[2])*t;return a+=(o[0]-a)*n,f+=(o[1]-f)*n,y+=(o[2]-y)*n,e[0]=a,e[1]=f,e[2]=y,e}function bn([e,t,n]){let o=s=>wt(Math.round(s),0,255).toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(n)}`}function ho(e,t,n){let[o,s,i]=gt(e),[a,f,y]=gt(t),p=n<0?0:n>1?1:n;return bn([o+(a-o)*p,s+(f-s)*p,i+(y-i)*p])}function Mn(e,t){if(e.length===0)return[77,163,255];if(e.length===1)return e[0];let n=wt(t,0,1)*(e.length-1),o=Math.min(e.length-2,Math.floor(n)),s=n-o,i=e[o],a=e[o+1];return[i[0]+(a[0]-i[0])*s,i[1]+(a[1]-i[1])*s,i[2]+(a[2]-i[2])*s]}function uo(e,t,n,o=0){if(!(t>0))return 1;let s=Math.max(0,1-e/t),i=1-n*s*s,a=Math.min(Math.max(o,0),1);return i<a?a:i>1?1:i}var Ce=1;function Pe(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,o=Math.min(t,n),s=e.ux*o,i=e.uy*o,a=e.spin<0?-1:1;return[{x:e.cx+s,y:e.cy+i,q:a},{x:e.cx-s,y:e.cy-i,q:-a}]}function yo(e,t,n){let o=0,s=0;for(let i of e){let a=t-i.x,f=n-i.y,y=Math.max(Ce,Math.hypot(a,f)),p=i.q/(y*y);o+=a/y*p,s+=f/y*p}return{x:o,y:s}}function po(e,t){let n=e/20+(t?.45:0);return n<0?0:n>1?1:n}function mo(e,t,n){return Math.round(e+(t-e)*n)}function go(e,t={}){let n=t.beta??2,o=t.lo??.25,s=t.hi??3,i=e.length,a=new Array(i).fill(1);if(i===0)return a;let f=0,y=0;for(let v of e){let b=v.strength>0?v.strength:0;f+=b,y+=b*(1+(v.on?n:0))}if(f<=0||y<=0)return a;let p=f/y;for(let v=0;v<i;v++){let E=(1+(e[v].on?n:0))*p;E<o?E=o:E>s&&(E=s),a[v]=E}return a}function xo(e,t={}){let n=t.threshold??.55,o=t.kappa??.6,s=t.falloff??320,i=e.length,a=new Array(i).fill(0);if(i<2)return a;let f=new Array(i).fill(0);for(let y=0;y<i;y++){let p=e[y],v=p.d-n;if(v<=0)continue;let b=0;for(let z=0;z<i;z++){if(z===y){f[z]=0;continue}let F=e[z],R=Math.hypot(p.cx-F.cx,p.cy-F.cy),B=R<s?1-R/s:0;f[z]=B,b+=B}if(b<=0)continue;let E=o*v;for(let z=0;z<i;z++){let F=f[z];if(F<=0)continue;let R=E*F/b;a[z]+=R,a[y]-=R}}return a}var Ht={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null};function Zt(e,t,n,o,s){Ht.x=o,Ht.y=s,Ht.vx=0,Ht.vy=0,Ht.heat=0;let i=0,a=0;for(let f of e){if(!f.vis||f.tokens.length===0)continue;let y,p;if(f.shaped){let E=f.cx-f.hw,z=f.cx+f.hw,F=f.cy-f.hh,R=f.cy+f.hh;y=(o<E?E:o>z?z:o)-o,p=(s<F?F:s>R?R:s)-s}else y=f.cx-o,p=f.cy-s;let v=y*y+p*p;if(f.range>0&&v>=f.range*f.range*2.56)continue;let b=Math.sqrt(v);n.dx=y,n.dy=p,n.dist=b<1?1:b;for(let E of f.tokens){let z=t[E];if(!(!z||z.modify))if(z.field){let F=z.field(f,o,s);i+=F.x,a+=F.y}else z.apply(f,Ht,n)}}return{fx:Ht.vx+i,fy:Ht.vy+a}}function Oe(e,t,n,o){let s=0,i=0;for(let a of e)if(!(!a.vis||a.tokens.length===0)){if(a.range>0){let f=a.cx-n,y=a.cy-o;if(f*f+y*y>=a.range*a.range*2.56)continue}for(let f of a.tokens){let y=t[f];if(y?.field){let p=y.field(a,n,o);s+=p.x,i+=p.y}}}return{x:s,y:i}}function vo(e,t,n={}){return{x:e,y:t,strength:n.strength??1,radius:n.radius&&n.radius>0?n.radius:360}}function ae(e,t,n,o,s=.6){let i=o.x-t,a=o.y-n,f=Math.hypot(i,a);if(f===0||f>=o.radius)return e.x=0,e.y=0,e;let y=(1-f/o.radius)*o.strength*s;return e.x=i/f*y,e.y=a/f*y,e}var Ts={step:6,maxSteps:400,minStrength:1e-9,loopDist:6,maxTurns:1/0};function wo(e,t,n,o,s){let i=[{x:t,y:n}],a=t,f=n,y=s.step,p=s.maxTurns*2*Math.PI,v=0,b=0,E=0;for(let z=0;z<s.maxSteps;z++){let F=e(a,f),R=Math.hypot(F.x,F.y);if(!(R>=s.minStrength))break;let B=F.x/R*o,N=F.y/R*o;if(Number.isFinite(p)){if(v!==0||b!==0){let X=Math.max(-1,Math.min(1,B*v+N*b));if(E+=Math.acos(X),E>p)break}v=B,b=N}if(a+=B*s.step,f+=N*s.step,s.bounds&&(a<-y||f<-y||a>s.bounds.w+y||f>s.bounds.h+y))break;if(z>4&&Math.hypot(a-t,f-n)<s.loopDist){i.push({x:a,y:f});break}i.push({x:a,y:f})}return i}function Fs(e,t,n,o={}){let s={...Ts,bounds:o.bounds,...o},i=wo(e,t,n,-1,s),a=wo(e,t,n,1,s);return i.reverse(),i.pop(),i.concat(a)}function bo(e,t,n={}){return t.map(o=>Fs(e,o.x,o.y,n)).filter(o=>o.length>1)}var As=8,Cs=60;function Mo(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},o=Pe(n),s=Math.hypot(o[0].x-o[1].x,o[0].y-o[1].y);if(s<Math.max(e.range*.06,As)){let p=Math.max(e.range*.18,Cs),v=e.spin<0?-1:1;o=[{x:e.cx+e.ux*p,y:e.cy+e.uy*p,q:v},{x:e.cx-e.ux*p,y:e.cy-e.uy*p,q:-v}],s=Math.hypot(o[0].x-o[1].x,o[0].y-o[1].y)}let i=-e.uy,a=e.ux,f=Math.max(s*.13,18),y=[{x:e.cx,y:e.cy}];for(let p=1;p<=t;p++){let v=p*f;y.push({x:e.cx+i*v,y:e.cy+a*v}),y.push({x:e.cx-i*v,y:e.cy-a*v})}return y}function Eo(e,t=18){let n=Math.max(Math.min(e.hw,e.hh)*.8,24),o=[];for(let s=0;s<t;s++){let i=s/t*Math.PI*2;o.push({x:e.cx+Math.cos(i)*n,y:e.cy+Math.sin(i)*n})}return o}function ko(e,t=8){let n=[];for(let o of e)!o.vis||o.tokens.length===0||(o.tokens.includes("magnetism")?n.push(...Mo(o,t)):(o.tokens.includes("charge")||o.tokens.includes("gravity"))&&n.push(...Eo(o)));return n}function So(e,t=Math.random){return 3+Math.floor(t()*(e>0?e:1)*3)}function zo(e,t,n,o=6,s=0){let i=Math.hypot(e,t,s)||1;if(i>=n)return{vx:0,vy:0,vz:0,heat:0};let a=1-i/n,f=a*o;return{vx:e/i*f,vy:t/i*f,vz:s/i*f,heat:a*.9}}function To(e,t,n,o,s=.9,i=80){let a=o>0?o:1;e.vx=(e.vx+t/a)*s,e.vy=(e.vy+n/a)*s,e.x+=e.vx,e.y+=e.vy;let f=Math.hypot(e.x,e.y);f>i&&(e.x=e.x/f*i,e.y=e.y/f*i)}function Fo(e,t=.02){return{x:-e.x*t,y:-e.y*t}}function Ao(e){let t=e/3e4;return t<.6?.6:t>6?6:t}function Co(e,t,n=-1,o=1600,s=26){let i=0,a=0,f=s*s;for(let y=0;y<t.length;y++){if(y===n)continue;let p=t[y],v=e.x-p.x,b=e.y-p.y,E=v*v+b*b+f;i+=o*v/E,a+=o*b/E}return{x:i,y:a}}function Po(e,t,n,o=16,s=1){let i=(e(t+o,n)-e(t-o,n))/(2*o),a=(e(t,n+o)-e(t,n-o))/(2*o);return{x:-i*s,y:-a*s}}var Ps=[.24,.4,.55,.7,.85];function Oo(e){let t=[];for(let n=0;n<5;n++)t.push({baseFrac:Ps[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 Ro(e,t,n){let o=Math.round(16*t),s=[];for(let i=0;i<e;i++)for(let a=0;a<o;a++)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 Et(e,t,n,o,s=1,i=1,a){let f=e.baseFrac*o+e.offsetY+Math.sin(t*e.freq+e.phase+n*e.speed*1e3*s)*e.amp*i;if(a&&a.k>.001){let y=t-a.x,p=260,v=Math.exp(-(y*y)/(2*p*p));f+=(a.y-f)*.42*v*a.k*(.45+e.depth*.55)}return f}function $o(e,t,n,o=1,s=1){return Math.cos(t*e.freq+e.phase+n*e.speed*1e3*o)*e.amp*e.freq*s}function ce(e,t,n,o,s=1,i=1){let a=e.baseFrac*o+e.offsetY,f=Math.max(1,Math.round(e.freq*2500));return a+Math.sin(f*t+e.phase+n*e.speed*1e3*s)*e.amp*i}function Io(e,t,n,o,s,i,a,f,y=1,p=1,v){if(a==="circular"){let b=t-f.x,E=n-f.y,z=Math.sqrt(b*b+E*E)||.001,F=Math.atan2(E,b),R=Math.min(s,i)*.48,B=ce(e,F,o,R,y,p);return{dist:Math.abs(z-B),rWave:B,r:z,theta:F}}else{let b=Et(e,t,o,i,y,p,v);return{dist:Math.abs(n-b),rWave:b,r:n,theta:0}}}function No(e,t,n,o,s,i,a,f){if(o.length===0)return;let y=e.particles;for(let p=y.length-1;p>=0&&!(t.length>=n);p--){let v=y[p];if(!v||v.cap||v.heat>=.12)continue;let b=-1,E=1e9,z=0;for(let R=0;R<o.length;R++){let B=Et(o[R],v.x,a,i),N=Math.abs(B-v.y);N<E&&(E=N,b=R,z=B)}if(b<0||E>=64)continue;let F=Math.min(.012,E*4e-4)*(1-v.heat/.12);v.vy+=z>v.y?F:-F,E<20&&v.vx*v.vx+v.vy*v.vy<.3&&f()<.03&&(t.push({wi:b,progress:v.x/s,phase:(f()-.5)*.22*Math.PI,size:v.size,glow:f()<.3,speed:(35e-5+f()*9e-4)*(f()<.5?1:-1)}),e.remove(v))}}function En(e,t,n,o,s,i,a,f,y){for(let p=e.length-1;p>=0;p--){let v=e[p];if(!v)continue;let b=t[v.wi];if(!b)continue;let E=v.progress*i,z=Et(b,E,f,a)+v.phase*32,F=E-n,R=z-o,B=Math.hypot(F,R);if(B<s&&B>.5){let N=(1-B/s)*4;y({x:E,y:z,vx:F/B*N,vy:R/B*N,size:v.size,heat:.9});let X=e.pop();X&&p<e.length&&(e[p]=X)}}}function Lo(e,t,n,o,s,i,a,f){let y=p=>p.tokens.some(v=>{let b=o[v];return!!b&&!b.modify&&!b.source});for(let p=e.length-1;p>=0;p--){let v=e[p];if(!v)continue;let b=t[v.wi];if(!b)continue;let E=v.progress*s,z=Et(b,E,a,i)+v.phase*32,F=!1,R=0,B=0;for(let N of n){if(!N.vis||N.when==="active"&&!N.on||N.when&&N.when!=="active")continue;let X=N.tokens,u=N.cx-E,Z=N.cy-z,it=Math.hypot(u,Z)||1,lt=N.range*(N.on?1.4:1);if(X.indexOf("wall")>=0&&Math.abs(E-N.cx)<N.hw+6&&Math.abs(z-N.cy)<N.hh+6&&(R=(E<N.cx?-1:1)*1.6,B=(z<N.cy?-1:1)*.8,F=!0),!F&&(X.indexOf("attract")>=0||X.indexOf("sink")>=0||X.indexOf("jet")>=0)&&it<lt*.8){let D=1.2+(N.on?1.6:0);R=u/it*D,B=Z/it*D,F=!0}if(!F&&X.indexOf("repel")>=0&&it<lt*.8){let D=1.2+(N.on?1.2:0);R=-(u/it)*D,B=-(Z/it)*D,F=!0}if(!F&&X.indexOf("swirl")>=0&&it<lt*.75&&(R=Z/it*1.2,B=-(u/it)*1.2,F=!0),!F&&X.indexOf("stream")>=0&&it<lt*.75&&(R=N.ux*1.3,B=N.uy*1.3,F=!0),!F&&it<lt*.8&&y(N)){let D=.8+(N.on?.8:0);R=u/it*D,B=Z/it*D,F=!0}if(F)break}if(F){f({x:E,y:z,vx:R,vy:B,size:v.size,heat:.5});let N=e.pop();N&&p<e.length&&(e[p]=N)}}}function Do(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 o=n.range*n.range;for(let s of t){if(s.charge)continue;let i=n.cx-s.x,a=n.cy-s.y;i*i+a*a>=o||(s.charge=i>=0?1:-1)}}}var Re=class{constructor(t=64){U(this,"cell");U(this,"bins",new Map);this.cell=t>0?t:64}key(t,n){return(t+32768)*65536+(n+32768)}clear(){this.bins.clear()}insert(t){let n=this.key(Math.floor(t.x/this.cell),Math.floor(t.y/this.cell)),o=this.bins.get(n);o?o.push(t):this.bins.set(n,[t])}rebuild(t){this.clear();for(let n of t)this.insert(n)}near(t,n,o,s=0){let i=[],a=o*o,f=Math.floor((t-o)/this.cell),y=Math.floor((t+o)/this.cell),p=Math.floor((n-o)/this.cell),v=Math.floor((n+o)/this.cell);for(let b=f;b<=y;b++)for(let E=p;E<=v;E++){let z=this.bins.get(this.key(b,E));if(z)for(let F of z){let R=F.x-t,B=F.y-n,N=(F.z??0)-s;R*R+B*B+N*N<=a&&i.push(F)}}return i}};var _o=e=>e<0?0:e>1?1:e;function Bo(e){if(!e||e.n===0)return{entropy:0,coherence:1,temperature:0};let t=e.sh/e.n,n=e.ss/e.n,o=e.ss2/e.n,s=_o(.5*t+.5*Math.min(1,o/9)),i=e.ss>1e-9?Math.hypot(e.sx,e.sy)/e.ss:1,a=_o((1-i)*Math.min(1,n/1.5));return{entropy:a,coherence:1-a,temperature:s}}var $e=class{constructor(t=64){U(this,"particles",[]);U(this,"hash");this.hash=new Re(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 o=this.particles.pop();o&&n<this.particles.length&&(this.particles[n]=o)}clear(){this.particles.length=0,this.hash.clear()}reindex(){this.hash.rebuild(this.particles)}neighbors(t,n){let o=this.hash.near(t.x,t.y,n,t.z??0),s=[];for(let i of o)i!==t&&s.push(i);return s}near(t,n,o){return this.hash.near(t,n,o)}};var Wo={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};var Ie=class{constructor(){U(this,"pending",new Map);U(this,"ids",new WeakMap);U(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==="met"){let s=n,[i,a]=[this.idOf(s.a.el??s.a),this.idOf(s.b.el??s.b)].sort((f,y)=>f-y);return`${i}:${a}`}if(t==="enter"||t==="exit"){let s=n;return`${this.idOf(s.body.el??s.body)}:${this.idOf(s.other.el??s.other)}`}let o=n;return String(this.idOf(o.body.el??o.body))}record(t,n){let o=this.pending.get(t);o||this.pending.set(t,o=new Map),o.set(this.keyOf(t,n),n)}flush(t){if(this.pending.size!==0){for(let[n,o]of this.pending)for(let s of o.values())t(n,s);this.pending.clear()}}};function kn(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 Sn(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}}function Ho(){let e={},t={...Wo};return{forces:e,conditions:t,force(n){e[n.token]=n},condition(n,o){t[n]=o}}}function qo(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 Yo(e){for(let t of e)if(t.vis&&t.tokens.indexOf("sink")>=0)return t;return null}var zn=.95,Os=.972,St=10;function Rs(e,t,n,o){if(!t.when)return!0;let s=e[t.when];return s?s(t,n,o):!0}function Uo(e){return e.classified??(e.classified=Te(e.tokens))}function Tn(e,t,n,o,s){if(s===1||e.kinematic){e.apply(t,n,o);return}let i=n.vx,a=n.vy,f=n.vz??0;e.apply(t,n,o),n.vx=i+(n.vx-i)*s,n.vy=a+(n.vy-a)*s,n.vz!==void 0&&(n.vz=f+(n.vz-f)*s)}function Go(e){let{store:t,bodies:n,env:o,forces:s,conditions:i,waves:a,separation:f}=e,y=o.dt;if(y===0)return;let{W:p,H:v,form:b}=o;o.fieldAt=(u,Z)=>Oe(n,s,u,Z);for(let u of n){u.count=0;let Z=u.thermo;Z&&(Z.n=0,Z.sx=0,Z.sy=0,Z.ss=0,Z.ss2=0,Z.sh=0)}let E=null;for(let u of n)u.vis&&u.tokens.length>0&&Uo(u).modifiers.indexOf("screen")>=0&&(E??(E=[])).push(u);let z=E?new Array(E.length):null,F=!!a&&a.length>0,R=n.length>0,B=null,N=b.conv>.02?Yo(n):null,X=o.D??0;for(let u of t.particles){if(u.cap){u.x+=(u.cap.cx-u.x)*.18,u.y+=(u.cap.cy-u.y)*.18,u.z&&(u.z+=-u.z*.18);continue}u.z===void 0&&(u.z=0),u.vz===void 0&&(u.vz=0);let Z=u.z;if(F)if(e.waveStyle==="circular"){let D=null,A=1e9,j=0,J=0,dt=0,_=e.waveCenter||{x:p/2,y:v/2};for(let tt of a){let yt=Io(tt,u.x,u.y,o.t,p,v,"circular",_);yt.dist<A&&(A=yt.dist,D=tt,j=yt.r,J=yt.rWave,dt=yt.theta)}if(D&&A<70){let tt=1-A/70,yt=-Math.sin(dt)*D.dir,Rt=Math.cos(dt)*D.dir;u.vx+=yt*.035*tt,u.vy+=Rt*.035*tt;let O=Math.cos(dt)*Math.sign(J-j),K=Math.sin(dt)*Math.sign(J-j);u.vx+=O*.05*tt,u.vy+=K*.05*tt}}else{let D=null,A=1e9;for(let j of a){let J=Math.abs(Et(j,u.x,o.t,v)-u.y);J<A&&(A=J,D=j)}D&&A<70&&(u.vx+=D.dir*.035*(1-A/70),u.vy+=$o(D,u.x,o.t)*.1*(1-A/70))}if(b.driftX&&(u.vx+=b.driftX*.02),b.spread>.02){let D=u.gx??.5,A=u.gy??.5,j=(D+o.frameN*4e-5)%1*p,J=A*v;u.vx+=(j-u.x)*6e-4*b.spread,u.vy+=(J-u.y)*6e-4*b.spread,X>0&&(u.vz+=((u.gz??.5)*X-Z)*6e-4*b.spread)}if(N){let D=N.cx-u.x,A=N.cy-u.y,j=-Z,J=Math.hypot(D,A,j)||1;u.vx+=D/J*b.conv*.06,u.vy+=A/J*b.conv*.06,u.vz+=j/J*b.conv*.06}if(R){if(E)for(let A=0;A<E.length;A++){let j=E[A],J=j.cx-u.x,dt=j.cy-u.y;z[A]=uo(Math.sqrt(J*J+dt*dt),j.range,j.strength,j.screenMin??0)}let D=u.m!==1&&u.m>0?1/u.m:1;for(let A of n){if(!A.vis||A.tokens.length===0||A.affects!==void 0&&!A.affects.has(u.species??0))continue;let j,J;if(A.shaped){let Y=A.cx-A.hw,Q=A.cx+A.hw,at=A.cy-A.hh,Ut=A.cy+A.hh,ne=u.x<Y?Y:u.x>Q?Q:u.x,he=u.y<at?at:u.y>Ut?Ut:u.y;j=ne-u.x,J=he-u.y}else j=A.cx-u.x,J=A.cy-u.y;let dt=-u.z,_=j*j+J*J+dt*dt;if(A.range>0&&_>=A.range*A.range*2.56)continue;let tt=Math.sqrt(_);if(A.feedback&&tt<A.range*.5){A.count+=1-tt/(A.range*.5);let Y=A.thermo??(A.thermo={n:0,sx:0,sy:0,ss:0,ss2:0,sh:0}),Q=u.vx*u.vx+u.vy*u.vy;Y.n++,Y.sx+=u.vx,Y.sy+=u.vy,Y.ss+=Math.sqrt(Q),Y.ss2+=Q,Y.sh+=u.heat}if(A.when&&!Rs(i,A,u,o))continue;o.dx=j,o.dy=J,o.dz=dt,o.dist=tt<1?1:tt;let yt=Uo(A),Rt=1,O=!1,K=!1;for(let Y of yt.modifiers){let Q=s[Y]?.modify;if(!Q)continue;K=!0;let at=Q(A,u,o);at.strength!=null&&(Rt*=at.strength),at.gate&&(O=!0)}for(let Y of yt.forces){let Q=s[Y]?.modify;if(!Q)continue;K=!0;let at=Q(A,u,o);at.strength!=null&&(Rt*=at.strength),at.gate&&(O=!0)}if(O)continue;let L=1;if(E)for(let Y=0;Y<E.length;Y++)E[Y]!==A&&(L*=z[Y]);let I=A.attn??1,$=Rt*I*L;if(!K&&$===1)for(let Y of A.tokens){let Q=s[Y];Q&&Tn(Q,A,u,o,D)}else if(K){let Y=A.strength;A.strength=Y*$;for(let Q of A.tokens){let at=s[Q];at&&!at.modify&&Tn(at,A,u,o,D)}A.strength=Y}else{let Y=A.strength;A.strength=Y*$;for(let Q of A.tokens){let at=s[Q];at&&Tn(at,A,u,o,D)}A.strength=Y}}}if(f&&f>0){let D=o.neighbors(u,12);for(let A of D){let j=u.x-A.x,J=u.y-A.y,dt=(u.z??0)-(A.z??0),_=Math.hypot(j,J,dt)||.1;if(_<12){let tt=(12-_)/12*f*.12;u.vx+=j/_*tt,u.vy+=J/_*tt,u.vz!==void 0&&(u.vz+=dt/_*tt)}}}let it=o.c,lt=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(lt>it*it){let D=it/Math.sqrt(lt);u.vx*=D,u.vy*=D,u.vz*=D}if(u.maxSpeed!==void 0){let D=u.maxSpeed*u.maxSpeed,A=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(A>D){let j=u.maxSpeed/Math.sqrt(A);u.vx*=j,u.vy*=j,u.vz*=j}}if(u.x+=u.vx*y,u.y+=u.vy*y,u.z+=u.vz*y,u.vx*=zn,u.vy*=zn,u.vz*=zn,u.report===void 0){if(o.frameN%40===0&&b.wander>0){let D=.05*b.wander;u.vx+=((o.rng??Math.random)()-.5)*D,u.vy+=((o.rng??Math.random)()-.5)*D,X>0&&(u.vz+=((o.rng??Math.random)()-.5)*D)}if(b.wander>.05){let D=(Math.sin(u.x*.0032+o.t*.12)+Math.cos(u.y*.0034-o.t*.15))*Math.PI;u.vx+=Math.cos(D)*.013*b.wander,u.vy+=Math.sin(D)*.013*b.wander}}u.heat*=Os,u.age!=null&&(u.age-=y,u.age<=0&&(B??(B=[])).push(u)),u.report===void 0?(u.x<-St?u.x=p+St:u.x>p+St&&(u.x=-St),u.y<-St?u.y=v+St:u.y>v+St&&(u.y=-St),X>0&&(u.z<-St?u.z=X+St:u.z>X+St&&(u.z=-St))):(u.x<0?(u.x=0,u.vx=Math.abs(u.vx)):u.x>p&&(u.x=p,u.vx=-Math.abs(u.vx)),u.y<0?(u.y=0,u.vy=Math.abs(u.vy)):u.y>v&&(u.y=v,u.vy=-Math.abs(u.vy)),X>0&&(u.z<0?(u.z=0,u.vz=Math.abs(u.vz)):u.z>X&&(u.z=X,u.vz=-Math.abs(u.vz))),u.report(u))}if(R){for(let u of n)if(!(!u.vis||u.tokens.length===0))for(let Z of u.tokens)s[Z]?.source?.(u,o)}if(B)for(let u of B)t.remove(u)}var Vo={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 $s(){return globalThis.process?.env?.NODE_ENV!=="production"}var Xo=$s();function Jo(){return Xo}var jo=new Set;function Fn(e,t){if(!Xo)return;let n=`${e}:${t}`;jo.has(n)||(jo.add(n),console.warn(`[Fundamental:${e}] ${t}`))}var Is={"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 Ko(e,t={}){let n=Is[e];if(!n)return null;let o=[...n.body];t.risk==="high"&&!o.includes("thermal")&&o.push("thermal");let s={"data-body":o.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:o.join(" "),strength:t.intensity,range:n.range,feedback:n.feedback??!1,render:n.render??["particles"],attributes:s}}function Zo(e){let t=(z,F)=>{let R=Number.parseFloat(e.get(z)??"");return Number.isFinite(R)?R:F},n=t("strength",.5),o=t("angle",0)*Math.PI/180,s=e.get("spin"),i=s==null?1:Number.isFinite(Number.parseFloat(s))?Number.parseFloat(s):0,a=(e.get("body")??"").split(/\s+/).filter(Boolean),f=Te(a),y=e.get("life"),p=e.get("cap"),v=Number.parseFloat(y??""),b=Number.parseFloat(p??""),E=y!=null||p!=null||e.has("budget")||e.has("sink");return{tokens:a,classified:f,...Number.isFinite(v)&&v>0?{life:v}:{},...Number.isFinite(b)&&b>0?{cap:b}:{},budgeted:E,strength:n,range:t("range",280),absorbR:t("absorb",64),capacity:t("max",60),spin:i,angle:o,ux:Math.cos(o),uy:Math.sin(o),when:e.get("when")??"",feedback:e.has("feedback"),shaped:e.has("shaped"),...e.get("species")!=null&&Number.isFinite(Number.parseFloat(e.get("species")))?{species:Number.parseFloat(e.get("species"))}:{},...(()=>{let z=e.get("affects");if(z==null)return{};let F=z.split(",").map(R=>Number.parseFloat(R.trim())).filter(R=>Number.isFinite(R));return F.length?{affects:new Set(F)}:{}})(),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 Ns(e){let t={body:e.body};return e.strength!=null&&(t.strength=String(e.strength)),e.range!=null&&(t.range=String(e.range)),e.spin!=null&&(t.spin=String(e.spin)),e.angle!=null&&(t.angle=String(e.angle)),e.absorb!=null&&(t.absorb=String(e.absorb)),e.max!=null&&(t.max=String(e.max)),e.life!=null&&(t.life=String(e.life)),e.cap!=null&&(t.cap=String(e.cap)),{get:n=>t[n]??null,has:n=>n in t}}function Ls(e){let t=Vo[e];return t?t.map(n=>Zo(Ns(n))):[]}function Ds(e){let t=(e.tagName??"element").toLowerCase(),n=e.id?`#${e.id}`:"",o=typeof e.className=="string"&&e.className?`.${e.className.split(/\s+/)[0]}`:"";return`<${t}${n}${o}>`}function _s(e,t="<body>"){!e.classified||e.classified.sources.length===0||e.budgeted||(e.life=pn,e.cap=mn,Jo()&&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="${pn}", data-cap="${mn}") \u2014 declare one to make the source's budget explicit (workover v0.3 source rules).`))}function tr(e,t){return _s(t,Ds(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 Bs(e){return{get:t=>e.getAttribute("data-"+t),has:t=>e.hasAttribute("data-"+t)}}function le(e,t){return tr(e,Zo(t??Bs(e)))}var Qo={source:"jet",sink:"sink",anchor:"tether",boundary:"wall",sensor:"",display:""};function Ws(e){let t=null,n=e.getAttribute("data-intent");if(n){let s=e.getAttribute("data-intensity"),i=Ko(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 Qo&&(t={body:Qo[s],feedback:""})}if(!t)return null;let o=t;return{get:s=>e.getAttribute("data-"+s)??o[s]??null,has:s=>e.hasAttribute("data-"+s)||s in o}}function er(e){let t=[];return e.querySelectorAll("[data-body]").forEach(n=>{t.push(le(n))}),e.querySelectorAll("[data-preset]").forEach(n=>{let o=n;for(let s of Ls(o.dataset.preset??""))t.push(tr(o,s))}),e.querySelectorAll("[data-intent]:not([data-body]), [data-field-role]:not([data-body]):not([data-intent])").forEach(n=>{let o=Ws(n);o&&t.push(le(n,o))}),t}function Hs(e){let t=e.el;if(typeof t.getAttribute!="function")return;let n=t.getAttribute("data-strength");if(n!=null){let a=Number.parseFloat(n);Number.isFinite(a)&&(e.strength=a,e.M=a)}let o=t.getAttribute("data-range");if(o!=null){let a=Number.parseFloat(o);Number.isFinite(a)&&(e.range=a)}let s=t.getAttribute("data-spin");if(s!=null){let a=Number.parseFloat(s);Number.isFinite(a)&&(e.spin=a)}let i=t.getAttribute("data-angle");if(i!=null){let a=Number.parseFloat(i);Number.isFinite(a)&&(e.angle=a*Math.PI/180,e.ux=Math.cos(e.angle),e.uy=Math.sin(e.angle))}}function Ne(e,t,n,o=0,s=0){let i=n*.15;for(let a of e){let f=a.rect?a.rect():a.el.getBoundingClientRect(),y=f.left-o,p=f.top-s;a.cx=y+f.width/2,a.cy=p+f.height/2,a.hw=f.width/2,a.hh=f.height/2,a.on=a.el.dataset.active==="1",a.vis=p+f.height>-i&&p<n+i&&y+f.width>-i&&y<t+i,Hs(a)}}var nr="field:register-body",or="field:unregister-body",rr="field:update-body";var Le=class{constructor(){U(this,"hosts",new Map)}register(t){this.hosts.set(t.element,t)}unregister(t){this.hosts.delete(t)}get size(){return this.hosts.size}bodies(t){let n=[];for(let[o,s]of this.hosts){if(!o.isConnected){this.hosts.delete(o);continue}let i=s.attrs?qs(s.attrs,o):void 0,a=t(o,i);s.getRect&&(a.rect=s.getRect),s.writeTarget&&(a.writeTarget=s.writeTarget),n.push(a)}return n}};function qs(e,t){return{get:n=>e[n]??t.getAttribute("data-"+n),has:n=>n in e||t.hasAttribute("data-"+n)}}function ir(e,t,n=.12){return e>=t?0:(1-e/t)*n}function De(e,t,n){if(e===t)return .5;let o=(n-e)/(t-e);return o<0?0:o>1?1:o}var sr=Object.freeze([]);function An(e,t,n,o,s){let i={x:De(e,t,s),y:0},a={x:1,y:De(t,n,s)},f={x:De(o,n,s),y:1},y={x:0,y:De(e,o,s)},p=(b,E)=>({x1:b.x,y1:b.y,x2:E.x,y2:E.y});switch((e>s?8:0)|(t>s?4:0)|(n>s?2:0)|(o>s?1:0)){case 0:case 15:return sr;case 1:case 14:return[p(y,f)];case 2:case 13:return[p(f,a)];case 3:case 12:return[p(y,a)];case 4:case 11:return[p(i,a)];case 6:case 9:return[p(i,f)];case 7:case 8:return[p(y,i)];case 5:return[p(y,i),p(f,a)];case 10:return[p(y,f),p(i,a)];default:return sr}}function Cn(e,t,n,o,s,i,a,f=1){if(a<=0)return;let y=Math.max(0,Math.floor((s-a)/o)),p=Math.min(t-1,Math.ceil((s+a)/o)),v=Math.max(0,Math.floor((i-a)/o)),b=Math.min(n-1,Math.ceil((i+a)/o)),E=a*a;for(let z=v;z<=b;z++)for(let F=y;F<=p;F++){let R=F*o-s,B=z*o-i,N=R*R+B*B;if(N>=E)continue;let X=1-Math.sqrt(N)/a,u=z*t+F;e[u]=e[u]+f*X*X}}function ar(e,t,n){let o=-1,s=1/0;for(let i=0;i<n.length;i++){let a=n[i],f=a.x-e,y=a.y-t,p=f*f+y*y;p<s&&(s=p,o=i)}return o}function cr(e,t,n){let o=[];for(let s=0;s<n;s++)for(let i=0;i<t;i++){let a=e[s*t+i];i+1<t&&e[s*t+i+1]!==a&&o.push({x1:i+.5,y1:s-.5,x2:i+.5,y2:s+.5}),s+1<n&&e[(s+1)*t+i]!==a&&o.push({x1:i-.5,y1:s+.5,x2:i+.5,y2:s+.5})}return o}var te=class{constructor(t,n,o="diffuse",s=32){U(this,"mode");U(this,"cell");U(this,"W");U(this,"H");U(this,"cols");U(this,"rows");U(this,"cur");U(this,"nxt");U(this,"prev");this.W=t,this.H=n,this.mode=o,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 o=t/this.cell,s=n/this.cell,i=Math.floor(o),a=Math.floor(s),f=o-i,y=s-a,p=this.at(i,a)*(1-f)+this.at(i+1,a)*f,v=this.at(i,a+1)*(1-f)+this.at(i+1,a+1)*f;return p*(1-y)+v*y}deposit(t,n,o){let s=this.clampCol(Math.round(t/this.cell)),i=this.clampRow(Math.round(n/this.cell));this.cur[i*this.cols+s]+=o}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 o=this.cell;return{x:(this.sample(t+o,n)-this.sample(t-o,n))/(2*o),y:(this.sample(t,n+o)-this.sample(t,n-o))/(2*o)}}step(){this.mode==="wave"?this.stepWave():this.mode==="memory"?this.stepDiffuse(.03,.004):this.stepDiffuse()}stepDiffuse(t=.18,n=.01){let o=t<0?0:t>.24?.24:t,s=1-n,{cols:i,rows:a,cur:f,nxt:y}=this;for(let p=0;p<a;p++)for(let v=0;v<i;v++){let b=p*i+v,E=this.at(v-1,p)+this.at(v+1,p)+this.at(v,p-1)+this.at(v,p+1)-4*f[b];y[b]=(f[b]+o*E)*s}this.cur=y,this.nxt=f}stepWave(t=.25,n=.002){let o=t<0?0:t>.5?.5:t,s=1-n,{cols:i,rows:a,cur:f,prev:y,nxt:p}=this;for(let v=0;v<a;v++)for(let b=0;b<i;b++){let E=v*i+b,z=this.at(b-1,v)+this.at(b+1,v)+this.at(b,v-1)+this.at(b,v+1)-4*f[E];p[E]=(2*f[E]-y[E]+o*z)*s}this.prev=f,this.cur=p,this.nxt=y}decay(t){let n=t<=0?1:t>=1?0:1-t;if(n!==1)for(let o=0;o<this.cur.length;o++)this.cur[o]*=n}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 o=this.cols*this.rows;this.cur=new Float32Array(o),this.nxt=new Float32Array(o),this.prev=new Float32Array(o)}};var lr=24,Ys=.12,Us=.22,de=class{constructor(t,n){U(this,"grid");U(this,"peak",.001);U(this,"cell",lr);this.grid=new te(Math.max(1,t),Math.max(1,n),"diffuse",lr)}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(Us,Ys);let n=this.grid.max(),o=n>this.peak?.25:.03;this.peak+=(Math.max(n,.001)-this.peak)*o}norm(t,n){return wt(this.grid.sample(t,n)/this.peak,0,1)}gradient(t,n){if(this.peak<=0)return{x:0,y:0};let o=this.grid.gradient(t,n);return{x:o.x/this.peak,y:o.y/this.peak}}};var Gs={position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"0",pointerEvents:"none",display:"block"},dr=Object.entries(Gs).map(([e,t])=>`${e.replace(/[A-Z]/g,n=>"-"+n.toLowerCase())}:${t}`).join(";");function fr(e){let t=e.width,n=e.height,o=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:a=>(o=a,1),cancelRaf:()=>{o=null},createCanvas:()=>{throw new Error("headlessHost does not render \u2014 use render:'none' and the signal read-outs (onFeedback / sampleScalar / readParticles).")},onResize:()=>()=>{},onScroll:()=>()=>{},onVisibility:()=>()=>{},onInput:()=>()=>{},onBodyEvent:()=>()=>{},tick(a){s=a??s+1e3/60;let f=o;o=null,f?.(s)},resize(a,f){t=a,n=f}}}var hr="10px ui-monospace, SFMono-Regular, Menlo, monospace";function Pn(e,t){let n=0,o=0;return{size(s,i,a){n=s,o=i,e.width=Math.floor(s*a),e.height=Math.floor(i*a),t.setTransform(a,0,0,a,0,0)},clear(){t.clearRect(0,0,n,o)},segments(s,i){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath();for(let a=0;a+3<s.length;a+=4)t.moveTo(s[a],s[a+1]),t.lineTo(s[a+2],s[a+3]);t.stroke()},polyline(s,i){if(!(s.length<4)){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath(),t.moveTo(s[0],s[1]);for(let a=2;a+1<s.length;a+=2)t.lineTo(s[a],s[a+1]);t.stroke()}},rect(s,i,a,f,y,p,v,b){t.fillStyle=`rgba(${y},${p},${v},${b})`,t.fillRect(s,i,a,f)},text(s,i,a,f,y,p,v){t.font=hr,t.textBaseline="middle",t.fillStyle=`rgba(${f},${y},${p},${v})`,t.fillText(s,i,a)},measureText(s){return t.font=hr,t.measureText(s).width}}}var On=(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),e.style.setProperty("--mass",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 o=e.dataset.fxLit==="1";n>.5&&!o?(e.dataset.fxLit="1",e.dispatchEvent(new CustomEvent("field:lit",{detail:{value:n}}))):n<.4&&o&&(e.dataset.fxLit="0",e.dispatchEvent(new CustomEvent("field:dim",{detail:{value:n}})))}},Rn=On;var _e=class{constructor(t){U(this,"lit",!1);U(this,"lastEdgeMs",-1/0);U(this,"cfg");this.cfg=t}update(t,n){let o=n-this.lastEdgeMs>=this.cfg.debounceMs;return!this.lit&&t>=this.cfg.enter&&o?(this.lit=!0,this.lastEdgeMs=n,"entered"):this.lit&&t<=this.cfg.exit&&o?(this.lit=!1,this.lastEdgeMs=n,"exited"):null}get isLit(){return this.lit}reset(){this.lit=!1,this.lastEdgeMs=-1/0}};var Vs={strengthen:1.5,decay:.3,remember:.2},$n=e=>e<0?0:e>1?1:e;function ur(e,t,n,o,s=Vs){e.active=t,e.tension=$n(n),e.strength=$n(e.strength+(t?s.strengthen:-s.decay)*o),e.memory=$n(e.memory+(t?s.remember:-s.remember*.5)*o)}function yr(e,t,n=Math.random){let o=[],s=t.absorbR+6;for(let i of e){if(i.cap!==t)continue;let a=n()*Math.PI*2,f=4+n()*3;i.cap=null,i.x=t.cx+Math.cos(a)*s,i.y=t.cy+Math.sin(a)*s,i.vx=Math.cos(a)*f,i.vy=Math.sin(a)*f,i.z&&(i.z=0),i.vz&&(i.vz=0),i.heat=1,i.age=void 0,o.push(i)}return t.accreted=0,o}function In(e){if(e.capacity<=0)return 0;let t=e.accreted/e.capacity;return t<0?0:t>1?1:t}function pr(e,t){return t&&!e?{fire:"captured",armed:!0}:!t&&e?{fire:"released",armed:!1}:{fire:null,armed:e}}function mr(e,t){let n=[];for(let o of e)o.when!=="active"||!o.tokens.includes("sink")||(o.wasOn&&!o.on&&o.accreted>0&&(t(o),n.push(o)),o.wasOn=o.on);return n}function Nn(e,t){let n=t.cx-e.x,o=t.cy-e.y;return n*n+o*o<t.absorbR*t.absorbR}function gr(e,t,n=.14){let o=e+(t-e)*n;return o<.001?0:o>.999?1:o}function xr(e,t,n,o){let s=e.x+t.x,i=e.y+t.y,a=t.x+(n.x-s)*o,f=t.y+(n.y-i)*o,y=1-o;return{tx:a,ty:f,scale:y,opacity:y}}var js={token:"attract",label:"Attract",apply(e,t,n){let o=e.range*(e.on?1.5:1),s=e.strength*(e.on?3:1);if(n.dist>=o)return;let i=(1-n.dist/o)**2*s*.5,a=n.dx/n.dist,f=n.dy/n.dist;t.vx+=a*i,t.vy+=f*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i),n.form.orbit&&(t.vx+=-f*i*n.form.orbit,t.vy+=a*i*n.form.orbit),e.on&&(t.heat=Math.max(t.heat,(1-n.dist/o)*.9))},meta:{desc:"a soft gravity-like well, bent into a spiral"}},Xs={token:"repel",label:"Repel",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**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"}},Js={token:"swirl",label:"Swirl",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**1.4*s*.45,a=e.spin,f=n.dx/n.dist,y=n.dy/n.dist;t.vx+=y*i*a+f*i*.12,t.vy+=-f*i*a+y*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/o)*.6))},meta:{desc:"tangential swirl with light inward retention"}},Ks={token:"stream",label:"Stream",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**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/o)*.5))},meta:{desc:"directional current along a heading"}},Qs={token:"viscosity",label:"Viscosity",apply(e,t,n){let o=e.range*(e.on?1.4:1);if(n.dist>=o)return;let s=(1-n.dist/o)*(.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"}},Zs={token:"jet",label:"Jet",kinematic:!0,apply(e,t,n){let o=e.range*(e.on?1.4:1);if(!(n.dist>=o))if(n.dist<24){let s=((n.rng??Math.random)()-.5)*.8,i=Math.cos(s),a=Math.sin(s),f=e.ux*i-e.uy*a,y=e.ux*a+e.uy*i,p=2.4+e.strength*2.6;t.vx=f*p,t.vy=y*p,t.x=e.cx+f*26,t.y=e.cy+y*26,t.z&&(t.z=0),t.vz&&(t.vz=0),t.heat=Math.max(t.heat,.9)}else{let s=(1-n.dist/o)**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"}},ti={token:"tether",label:"Tether",apply(e,t,n){let o=e.range*.6*(e.on?1.25:1),s=o*2.1;if(n.dist>=s)return;let i=(.006+e.strength*.012)*(e.on?1.7:1),a=n.dist-o,f=n.dx/n.dist,y=n.dy/n.dist;t.vx+=f*a*i,t.vy+=y*a*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*a*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(a)/o))*.5))},meta:{desc:"a tether with a rest length \u2014 holds matter at a fixed radius"}},ei={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 a=Math.hypot(t.vx,t.vy),f=e.hw+6-s,y=e.hh+6-i;f<y?(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),a>.7&&(n.spark(t.x,t.y,Math.min(2.4,a),e.tint??lo.wall.color),t.heat=Math.max(t.heat,Math.min(.85,a*.4)))},meta:{desc:"axis-aligned bouncing wall \u2014 sparks on impact"}},ni={token:"sink",label:"Sink",apply(e,t,n){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"}},oi=[js,Zs,ti,ei,Ks,Xs,Qs,Js,ni];function vr(e){for(let t of oi)e.force(t)}var Dn=1.5,ri=8,si=60;function ii(e,t,n,o){let s=Pe(e);if(Math.hypot(s[0].x-s[1].x,s[0].y-s[1].y)<Math.max(e.range*.06,ri)){let y=Math.max(e.range*.18,si),p=e.spin<0?-1:1;s=[{x:e.cx+e.ux*y,y:e.cy+e.uy*y,q:p},{x:e.cx-e.ux*y,y:e.cy-e.uy*y,q:-p}]}let a=o*(1+Dn*(e.d??0)),f=yo(s,t,n);return{x:f.x*a,y:f.y*a}}function ai(e,t,n,o){let s=t-e.cx,i=n-e.cy,a=Math.max(Math.hypot(s,i),Ce),y=(e.spin<0?-1:1)*o*(1+Dn*(e.d??0))/(a*a);return{x:s/a*y,y:i/a*y}}function wr(e,t,n,o){if(n.dist>=e.range)return;let s=2*n.G*e.M/(n.c*n.c),i=o/(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),_n(t,n.c)}function _n(e,t){let n=e.vz??0,o=Math.hypot(e.vx,e.vy,n);o>t&&(e.vx=e.vx/o*t,e.vy=e.vy/o*t,n&&(e.vz=n/o*t))}function ci(e,t,n){let o=e.cx-t,s=e.cy-n,i=Math.max(Math.hypot(o,s),Ce),a=e.M*(1+Dn*(e.d??0))/(i*i);return{x:o/i*a,y:s/i*a}}var li={token:"gravity",label:"Gravity",apply(e,t,n){wr(e,t,n,n.G*e.M)},field:(e,t,n)=>ci(e,t,n),meta:{desc:"true softened inverse-square gravity (a real 1/d\xB2 law)"}},di={token:"charge",label:"Charge",apply(e,t,n){let o=t.charge??0;o!==0&&wr(e,t,n,-(e.spin*o*n.G*e.M))},field:(e,t,n)=>ai(e,t,n,e.M),meta:{desc:"signed inverse-square \u2014 like repels, opposite attracts"}},fi={token:"magnetism",label:"Magnetism",apply(e,t,n){if(n.dist>=e.range)return;let o=t.charge??0;if(o===0)return;let s=1-n.dist/e.range,i=o*e.spin*e.strength*s,a=Math.cos(i),f=Math.sin(i),y=t.vx;t.vx=y*a-t.vy*f,t.vy=y*f+t.vy*a},field:(e,t,n)=>ii(e,t,n,e.strength),meta:{desc:"Lorentz force \u2014 curves a moving charge perpendicular to its velocity"}};function hi(e){return Math.sqrt(2*Math.max(0,e))}var ui={token:"thermal",label:"Thermal",apply(e,t,n){if(n.dist>=e.range)return;let o=1-n.dist/e.range,s=hi(e.strength*o);if(s===0)return;let i=Math.random()||1e-9,a=s*Math.sqrt(-2*Math.log(i)),f=2*Math.PI*Math.random();if(t.vx+=a*Math.cos(f),t.vy+=a*Math.sin(f),n.D){let y=Math.random()||1e-9;t.vz=(t.vz??0)+s*Math.sqrt(-2*Math.log(y))*Math.cos(2*Math.PI*Math.random())}e.on&&(t.heat=Math.max(t.heat,o*.4)),_n(t,n.c)},meta:{desc:"Langevin/Brownian agitation \u2014 a real temperature in the medium"}},yi={token:"collide",label:"Collide",apply(e,t,n){if(n.dist>=e.range)return;let o=Math.max(0,Math.min(1,e.strength)),s=Math.max(1,t.size);for(let i of n.neighbors(t,s*4)){let a=Math.max(1,i.size),f=t.x-i.x,y=t.y-i.y,p=(t.z??0)-(i.z??0),v=Math.hypot(f,y,p);if(v>=s+a||v<1e-6)continue;let b=f/v,E=y/v,z=p/v,F=(t.vx-i.vx)*b+(t.vy-i.vy)*E+((t.vz??0)-(i.vz??0))*z;if(F>=0)continue;let R=(1+o)*.5*F;t.vx-=R*b,t.vy-=R*E,i.vx+=R*b,i.vy+=R*E,p&&(t.vz=(t.vz??0)-R*z,i.vz=(i.vz??0)+R*z)}},meta:{desc:"elastic pairwise collision \u2014 the hard-sphere billiard force"}},pi={token:"diffuse",label:"Diffuse",apply(e,t,n){if(n.dist>=e.range)return;let o=n.grid("diffuse");o.deposit(t.x,t.y,e.strength);let s=o.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"}},mi=12,Ln=7,gi={token:"propagate",label:"Propagate",source(e,t){e.on&&t.frameN%mi===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 a=-n.dx/n.dist,f=-n.dy/n.dist;t.vx+=a*i*e.strength*Ln,t.vy+=f*i*e.strength*Ln,n.dz&&(t.vz=(t.vz??0)+-n.dz/n.dist*i*e.strength*Ln),_n(t,n.c)},meta:{desc:"a travelling wave \u2014 a shock train expands from the source, sweeping matter out"}},xi={token:"memory",label:"Memory",apply(e,t,n){if(n.dist>=e.range)return;let o=n.grid("memory");o.deposit(t.x,t.y,e.strength*.15);let s=1+.5*o.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"}},vi=[li,di,fi,ui,yi,pi,gi,xi];function br(e){for(let t of vi)e.force(t)}var wi={token:"lens",label:"Lens",kinematic:!0,apply(e,t,n){if(n.dist>=e.range)return;let o=e.strength*(1-n.dist/e.range)*e.spin,s=Math.cos(o),i=Math.sin(o),a=t.vx,f=t.vy;t.vx=a*s-f*i,t.vy=a*i+f*s},meta:{desc:"rotates velocity, preserving speed \u2014 bends paths without adding energy"}},bi={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"}},Mi=1,Ei=1,ki={token:"buoyancy",label:"Buoyancy",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=Mi/(t.size*(1+t.heat));t.vy-=(Ei-o)*e.strength},meta:{desc:"a constant lift/sink by density difference \u2014 light matter rises, dense settles"}},Si={token:"shear",label:"Shear",apply(e,t,n){if(n.dist>=e.range)return;let o=(t.x-e.cx)*-e.uy+(t.y-e.cy)*e.ux,s=e.strength*(o/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"}},Be=32,zi=.5,Ti={token:"crystallize",label:"Crystallize",apply(e,t,n){if(n.dist>=e.range||t.heat>=zi)return;let o=e.cx+Math.round((t.x-e.cx)/Be)*Be,s=e.cy+Math.round((t.y-e.cy)/Be)*Be;t.vx+=(o-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"}},Fi={token:"align",label:"Align",apply(e,t,n){if(n.dist>=e.range)return;let o=t.vz??0,s=Math.hypot(t.vx,t.vy,o),i=e.strength,a=e.ux,f=e.uy,y=0,p=0,v=0,b=0;for(let z of n.neighbors(t,e.range)){let F=z.vz??0,R=Math.hypot(z.vx,z.vy,F);R>1e-6&&(p+=z.vx/R,v+=z.vy/R,b+=F/R)}let E=Math.hypot(p,v,b);E>1e-6&&(a=p/E,f=v/E,y=b/E),t.vx+=(a*s-t.vx)*i,t.vy+=(f*s-t.vy)*i,(y||o)&&(t.vz=o+(y*s-o)*i)},meta:{desc:"steers toward the neighbour-mean heading (or the body heading when alone)"}};function Ai(e,t,n,o){let s=e*o+n*.2,i=t*o-n*.2;return{x:-o*Math.sin(s)*Math.sin(i),y:-o*Math.cos(s)*Math.cos(i)}}var Ci=.01,Pi={token:"wind",label:"Wind",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=Ai(t.x,t.y,n.t,Ci);t.vx+=o.x*e.strength,t.vy+=o.y*e.strength},meta:{desc:"divergence-free curl-noise turbulence"}},Oi=.5,Ri={token:"cohesion",label:"Cohesion",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=o*Oi,i=e.strength;for(let a of n.neighbors(t,o)){let f=a.x-t.x,y=a.y-t.y,p=(a.z??0)-(t.z??0),v=Math.hypot(f,y,p);if(v<1e-6)continue;let b=f/v,E=y/v,z=p/v;if(v<s){let F=i*(s-v)/s;t.vx-=F*b,t.vy-=F*E,p&&(t.vz=(t.vz??0)-F*z)}else{let F=i*(v-s)/(o-s);t.vx+=F*b,t.vy+=F*E,p&&(t.vz=(t.vz??0)+F*z)}}},meta:{desc:"short-range pressure + mid-range cohesion \u2014 surface tension over neighbours"}},$i=.5,Ii={token:"pressure",label:"Pressure",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=e.strength,i=0,a=n.neighbors(t,o);for(let y of a){let p=Math.hypot(y.x-t.x,y.y-t.y,(y.z??0)-(t.z??0));p<o&&(i+=(1-p/o)**2)}let f=i-$i;if(!(f<=0))for(let y of a){let p=t.x-y.x,v=t.y-y.y,b=(t.z??0)-(y.z??0),E=Math.hypot(p,v,b);if(E<1e-6||E>=o)continue;let z=s*f*(1-E/o)/E;t.vx+=z*p,t.vy+=z*v,b&&(t.vz=(t.vz??0)+z*b)}},meta:{desc:"SPH density relaxation \u2014 incompressible even-fill via mutual repulsion"}},Ni={token:"hunt",label:"Hunt",apply(e,t,n){if(n.dist>=e.range)return;let o=t.species??0,s=null,i=1/0;for(let b of n.neighbors(t,e.range)){if((b.species??0)===o)continue;let E=b.x-t.x,z=b.y-t.y,F=(b.z??0)-(t.z??0),R=E*E+z*z+F*F;R<i&&(i=R,s=b)}if(!s)return;let a=s.x-t.x,f=s.y-t.y,y=(s.z??0)-(t.z??0),p=Math.hypot(a,f,y)||1,v=o===0?1:-1;t.vx+=a/p*e.strength*v,t.vy+=f/p*e.strength*v,y&&(t.vz=(t.vz??0)+y/p*e.strength*v)},meta:{desc:"two-species pursuit \u2014 predators seek prey, prey flee predators"}},Li=.35,Di={token:"link",label:"Link",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=o*Li,i=e.strength;for(let a of n.neighbors(t,o)){let f=a.x-t.x,y=a.y-t.y,p=(a.z??0)-(t.z??0),v=Math.hypot(f,y,p);if(v<1e-6)continue;let b=v-s,E=.5*i*(b/s);t.vx+=E*(f/v),t.vy+=E*(y/v),p&&(t.vz=(t.vz??0)+E*(p/v))}},meta:{desc:"a Verlet distance constraint \u2014 holds a rest length, so matter ropes and drapes"}},Mr=40,_i={token:"morph",label:"Morph",apply(e,t,n){let o=e.targets;if(!o||o.length===0)return;let s=Math.min(o.length-1,Math.floor((t.gx??0)*o.length)),i=o[s],a=i.x-t.x,f=i.y-t.y,y=Math.hypot(a,f),p=e.strength;t.vx+=a*p*.02,t.vy+=f*p*.02,t.z&&(t.vz=(t.vz??0)-t.z*p*.02);let b=(1-(y<Mr?1-y/Mr:0))*p*.3;b>0&&(t.vx+=((n.rng??Math.random)()-.5)*b,t.vy+=((n.rng??Math.random)()-.5)*b)},meta:{desc:"matter assembles into a mark/chart/logo \u2014 never words (\xA711)"}},Bi=90,Wi={token:"spawn",label:"Spawn",apply(){},source(e,t){let n=e.life??Bi,o=Math.max(1,Math.round(e.strength*2));e.cap!=null&&e.cap>0&&n>0&&(o=Math.min(o,e.cap/n)),e.emitAcc=(e.emitAcc??0)+o;let s=Math.floor(e.emitAcc);for(e.emitAcc-=s;s>0;s--){let i=((t.rng??Math.random)()-.5)*.6,a=Math.cos(i),f=Math.sin(i),y=e.ux*a-e.uy*f,p=e.ux*f+e.uy*a,v=2+(t.rng??Math.random)()*2;t.spawn({x:e.cx,y:e.cy,vx:y*v,vy:p*v,age:n,heat:.6,...e.species!=null?{species:e.species}:{}})}},meta:{desc:"a source \u2014 emits matter along the heading, budgeted by a lifespan"}},Hi=3,qi={token:"resonate",label:"Resonate",apply(){},modify(e,t,n){return{strength:1+Math.sin(n.t*Hi*e.spin)}},meta:{desc:"pulses sibling forces with a time-varying strength S(t)=S\u2080(1+sin \u03C9t)"}},Yi=.5,Ui={token:"spotlight",label:"Spotlight",apply(){},modify(e,t,n){let o=-n.dx/n.dist,s=-n.dy/n.dist;return{gate:o*e.ux+s*e.uy<Yi}},meta:{desc:"gates sibling forces to an angular cone of the heading"}},Gi={token:"screen",label:"Screen",apply(){},meta:{desc:"a quiet zone \u2014 attenuates other bodies' forces on matter inside its radius"}},Vi={token:"pigment",label:"Pigment",apply(e,t,n){let o=e.tint;!o||n.dist>=e.range*.6||(t.color=t.color?ho(t.color,o,.08):o)},meta:{desc:"conserved color transport \u2014 matter takes on and carries a tint"}},ji=.5,Er=.12,Xi={token:"fieldflow",label:"Field Flow",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=n.fieldAt?.(t.x,t.y);if(!o)return;let s=Math.hypot(o.x,o.y);if(!(s>1e-9))return;let i=o.x/s,a=o.y/s,f=e.range>0?1-n.dist/e.range:1,y=e.strength*f,p=t.vz??0,v=Math.hypot(t.vx,t.vy,p);if(v>1e-6){let z=Math.min(1,y*ji);t.vx+=(i*v-t.vx)*z,t.vy+=(a*v-t.vy)*z,p&&(t.vz=p+(0-p)*z)}t.vx+=i*y*Er,t.vy+=a*y*Er;let b=t.vz??0,E=t.vx*t.vx+t.vy*t.vy+b*b;if(E>n.c*n.c){let z=n.c/Math.sqrt(E);t.vx*=z,t.vy*=z,b&&(t.vz=b*z)}e.on&&(t.heat=Math.max(t.heat,f*.4))},meta:{desc:"follow the field lines \u2014 steer onto and stream down the net field a body radiates"}},Ji={token:"warp",label:"Warp",kinematic:!0,apply(e,t,n){if(!e.warpHas||t.cap)return;let o=e.absorbR;if(n.dist>=o)return;let s=Math.cos(e.twist??0),i=Math.sin(e.twist??0),a=e.warpScale??1,f=-n.dx/n.dist,y=-n.dy/n.dist,p=f*s-y*i,v=f*i+y*s,b=o*a+6;t.x=e.warpX+p*b,t.y=e.warpY+v*b,t.z&&(t.z=-n.dz/n.dist*b);let E=t.vx,z=t.vy;t.vx=E*s-z*i,t.vy=E*i+z*s,t.heat=Math.max(t.heat,.6)},meta:{desc:"a wormhole throat \u2014 relocates matter to its paired body, conserved"}},Ki=[wi,bi,ki,Si,Ti,Fi,Pi,Ri,Ii,Di,Ni,_i,Wi,qi,Ui,Gi,Vi,Xi,Ji];function kr(e){for(let t of Ki)e.force(t)}function Qi(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 Zi(e){let t=0;for(let n of e)t+=n.heat;return t}function Sr(e){let t=Qi(e),n=Zi(e);return{kinetic:t,thermal:n,total:t+n,count:e.length}}var We={x:0,y:0},He=[0,0,0];function qe(e,t={}){let n=null;if((t.render??"none")!=="none"&&(n=e.getContext("2d"),!n))throw new Error("Fundamental: 2D canvas context unavailable");let o=t.overlayCanvas??null,s=n?o?.getContext("2d")??null:null,i=t.overlayBackend??(o&&s?Pn(o,s):null),a=new $e,f=1,y=new Map,p=Ho(),v=new Map,b=r=>(v.get(r)?.size??0)>0;function E(r,c){let l=v.get(r);if(l)for(let g of l)g(c)}let z=new Ie;function F(r,c){b(r)&&z.record(r,c)}function R(){z.flush(E)}let B=new WeakMap,N=new Map,X=new Map;function u(r){let c=b("enter")||b("exit"),l=b("met");if(!c&&!l)return;for(let d=0;d<r.length;d++){let x=r[d];if(c){let m=N.get(x);m||N.set(x,m=new Set);let h=x.range*x.range;for(let w=0;w<r.length;w++){if(d===w)continue;let M=r[w],S=M.cx-x.cx,T=M.cy-x.cy,k=S*S+T*T<h;k&&!m.has(M)?(m.add(M),b("enter")&&F("enter",{body:x,other:M})):!k&&m.has(M)&&(m.delete(M),b("exit")&&F("exit",{body:x,other:M}))}}if(l){let m=X.get(x);m||X.set(x,m=new Set);for(let h=d+1;h<r.length;h++){let w=r[h],M=Math.abs(w.cx-x.cx)<x.hw+w.hw&&Math.abs(w.cy-x.cy)<x.hh+w.hh;M&&!m.has(w)?(m.add(w),F("met",{a:x,b:w})):!M&&m.has(w)&&m.delete(w)}}}let g=new Set(r);for(let d of[N,X])for(let x of d.keys())g.has(x)||d.delete(x)}let Z=[],it=new WeakMap,lt=[],D=0,A=new WeakMap,j=new WeakMap,J=new Map,dt=new Map;if(vr(p),br(p),kr(p),!t.host)throw new Error("Fundamental: createField requires opts.host. Use @fundamental-engine/vanilla (createField/mountField) or @fundamental-engine/elements / @fundamental-engine/react, or pass browserHost() from @fundamental-engine/dom.");let _=t.host,tt=[],yt=_.reducedMotion(),Rt=vn[t.theme??wn]??vn[wn],O={accent:t.accent??Ae(t.palette)[0]??ze[0]??"#4da3ff",density:t.density&&t.density>0?t.density:1,render:t.render??"none",waves:t.waves??!0,waveStyle:t.waveStyle??"linear",waveCenter:t.waveCenter??null,background:t.background??"opaque",mass:t.mass??!1,separation:t.separation!=null&&t.separation>=0?t.separation:0,attention:t.attention??!1,causality:t.causality??!1,heatmap:t.heatmap??!1,overlay:t.overlay??"off",gridWarp:t.gridWarp!=null&&t.gridWarp>=0?t.gridWarp:1,gridIntensity:t.gridIntensity!=null&&t.gridIntensity>=0?Math.min(t.gridIntensity,1):.16,gradientCool:t.gradientCool?gt(t.gradientCool):Rt.cool,gradientWarm:t.gradientWarm?gt(t.gradientWarm):Rt.warm,waveBaseline:(t.waveBaseline??Rt.wave).map(gt),dprCap:t.dprCap&&t.dprCap>0?t.dprCap:2,depth:t.depth&&t.depth>0?t.depth:0,feedbackSink:t.feedbackSink??On},K=null,L=[],I=0,$=0,Y=0,Q=0,at=!1,Ut=1,ne=0,he=new WeakMap,qt=0,$t=0,Wn=!0,Hn={...Fe.ambient.preset},vt=[],Dt=[],qn=0,Yt=null,ht=t.rng??Math.random,Xe=t.now??(()=>performance.now()),ft=yt?1:0,Je=NaN,It=null,oe=null,_t=0,Nt=0,ue=null,Ke=[],Qe=null,ye=null,$r=Math.round(130*O.density)*4,xt={x:0,y:0,k:0},ut=null,Lt=null,Yn=0,Un=0,Gn=Ae(t.palette).map(gt),rt=gt(O.accent),pe=null,Ze=[],Bt=[],Gt=[],Vt=[],tn=[],en=[],jt=[],me=new Le,nn=!1,on=()=>{nn||(nn=!0,queueMicrotask(()=>{nn=!1,xe()}))},Ir=r=>{for(let c of["--d","--field-density","--load","--mass","--entropy","--coherence","--temperature"])r.style.removeProperty(c)},Nr=r=>{let c=r.detail;c?.element&&(me.register(c),on())},Lr=r=>{let c=r.detail;c?.element&&(me.unregister(c.element),Ir(c.writeTarget??c.element),on())},Dr=on,Tt={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null},Vn=Xe(),q={dx:0,dy:0,dz:0,dist:1,form:{...Fe.ambient.preset},W:0,H:0,D:O.depth,t:0,frameN:0,dt:yt?0:1,c:12,G:1,scrollV:0,rng:ht,spark:(r,c,l,g)=>jn(r,c,l,g),supernova:r=>{let c=yr(a.particles,r,ht),l=new Set(c);for(let g of a.particles){if(l.has(g))continue;let d=g.x-r.cx,x=g.y-r.cy,m=Math.hypot(d,x)||1;if(m<320){let h=(1-m/320)*4;g.vx+=d/m*h,g.vy+=x/m*h,g.heat=Math.max(g.heat,.8)}}En(Dt,vt,r.cx,r.cy,320,I,$,q.t,g=>void a.add(Xt(g))),jr(r),rn(r.el,"field:saturated",{peak:c.length}),r.el.dataset.fxCap==="1"&&(r.el.dataset.fxCap="0",Jt(r.el,"released",{accreted:0,load:0}),b("release")&&F("release",{body:r,count:c.length}),B.delete(r))},spawn:r=>{a.size>=$r||a.add(Xt(r))},neighbors:(r,c)=>a.neighbors(r,c),grid:r=>{let c=y.get(r);if(!c){let l=r.startsWith("wave")?"wave":r.startsWith("memory")?"memory":"diffuse";c=new te(I,$,l),y.set(r,c)}return c}};function jn(r,c,l,g){if(yt||Vt.length>260)return;let d=g?gt(g):[255,122,69],x=So(l);for(let m=0;m<x;m++){let h=ht()*6.28318,w=.8+ht()*(l>0?l:1)*1.7;Vt.push({x:r,y:c,vx:Math.cos(h)*w,vy:Math.sin(h)*w,life:1,c:d})}}function Xt(r={}){let c=r.size??.7+ht()*1.8;return{id:r.id??f++,x:r.x??ht()*I,y:r.y??ht()*$,vx:r.vx??(ht()-.5)*.25,vy:r.vy??(ht()-.5)*.18,z:r.z??(O.depth>0?ht()*O.depth:0),vz:r.vz??(O.depth>0?(ht()-.5)*.18:0),m:r.m??(O.mass?c:1),heat:r.heat??0,size:c,gx:r.gx??ht(),gy:r.gy??ht(),gz:r.gz??ht(),cap:null,...r.age!=null?{age:r.age}:{},...r.color!=null?{color:r.color}:{},...r.species!=null?{species:r.species}:{}}}let ge=[];function _r(){if(!ge.length)return;let r=a.particles;for(let c=0;c<r.length;c++){let l=ge[c%ge.length];r[c].atom=l;let g=typeof l.weight=="number"?Math.max(0,Math.min(1,l.weight)):.5;r[c].size*=.6+g*.9,r[c].m*=.6+g*1.2}}function Xn(){a.clear();let r=Math.round(130*O.density);for(let c=0;c<r;c++)a.add(Xt());_r(),vt=O.waves?Oo(O.waveBaseline):[],Dt=O.waves?Ro(vt.length,O.density,ht):[],qn=Dt.length}function xe(){let r=er(_.root);if(me.size>0){let g=new Set(r.map(d=>d.el));L=r.concat(me.bodies(le).filter(d=>!g.has(d.el)))}else L=r;Z.length>0&&(L=L.concat(Z)),Ne(L,I,$,Y,Q),Jr();let c=new Map(Bt.map(g=>[g.el,g]));Bt=[..._.root.querySelectorAll("[data-move]")].map(g=>{let d=g,x=d.getBoundingClientRect(),m=Number.parseFloat(d.dataset.mass??""),h=Number.isFinite(m)?m:Ao(x.width*x.height),w=(d.dataset.move??"").trim()==="layout",M=d.hasAttribute("data-dock"),S=d.hasAttribute("data-warp"),T=c.get(d);return T?{el:d,o:T.o,mEl:h,layout:w,dockable:M,dock:T.dock,docked:T.docked,warpable:S,warpCool:T.warpCool}:{el:d,o:{x:0,y:0,vx:0,vy:0},mEl:h,layout:w,dockable:M,dock:{dock:0},docked:null,warpable:S,warpCool:0}}),tn=[..._.root.querySelectorAll("[data-on]")].map(g=>{let d=g;return{el:d,body:L.find(x=>x.el===d)??null,bindings:kn(d.dataset.on??"")}}),en=[..._.root.querySelectorAll("[data-class]")].map(g=>{let d=g;return{el:d,body:L.find(x=>x.el===d)??null,bindings:kn(d.dataset.class??"")}});for(let g of L){if(!g.pair)continue;let d=null;try{d=_.root.querySelector(g.pair)}catch{d=null}g.pairBody=d?L.find(x=>x.el===d):void 0}let l=new Map(Gt.map(g=>[g.el,g]));for(let[g,d]of l)if(!_.root.contains(g))for(let x of d.emitted)x.remove();Gt=[..._.root.querySelectorAll("[data-emit]")].map(g=>{let d=g,x=d.dataset.emit??"",m=null;try{m=x?_.root.querySelector(x):null}catch{m=null}let h=Math.max(0,Math.round(Number.parseFloat(d.dataset.max??"")||8)),w=l.get(d);if(w){let M=w.emitted.filter(S=>S.isConnected);for(;M.length>h;)M.pop().remove();return{el:d,tmpl:m,cap:h,emitted:M}}return{el:d,tmpl:m,cap:h,emitted:[]}})}function Br(){for(let r of L)if(r.pairBody){if(!r.pairBody.el.isConnected){r.warpHas=!1,r.pairBody=void 0;continue}r.pairBody.vis?(r.warpX=r.pairBody.cx,r.warpY=r.pairBody.cy,r.warpHas=!0):r.warpHas=!1}else r.pair&&(r.warpHas=!1)}function Wr(){if(!(Gt.length===0||q.frameN%30!==0))for(let r of Gt){if(!r.tmpl||r.emitted.length>=r.cap)continue;let c=r.tmpl.cloneNode(!0);c.removeAttribute("id"),c.setAttribute("aria-hidden","true"),c.setAttribute("inert",""),c.dataset.fieldEmitted="",r.el.appendChild(c),r.emitted.push(c)}}function Hr(){if(tn.length!==0)for(let r of tn){let c=r.body?{d:r.body.d,on:r.body.on,accreted:r.body.accreted}:{d:0,on:r.el.dataset.active==="1",accreted:0};for(let l of r.bindings){let g=Sn(l.trigger,c);g&&!l.armed?(l.armed=!0,r.el.dispatchEvent(new CustomEvent(l.event,{bubbles:!0,detail:{trigger:l.trigger,d:c.d,on:c.on,accreted:c.accreted}}))):g||(l.armed=!1)}}}function qr(){if(en.length!==0)for(let r of en){let c=r.body?{d:r.body.d,on:r.body.on,accreted:r.body.accreted}:{d:0,on:r.el.dataset.active==="1",accreted:0};for(let l of r.bindings){let g=Sn(l.trigger,c);g&&!l.armed?(l.armed=!0,r.el.classList.add(l.event)):!g&&l.armed&&(l.armed=!1,r.el.classList.remove(l.event))}}}function Jt(r,c,l){r.dispatchEvent(new CustomEvent("field:"+c,{bubbles:!0,composed:!0,detail:l})),r.dispatchEvent(new CustomEvent("forces:"+c,{bubbles:!0,composed:!0,detail:l}))}function Yr(){for(let r of L){if(!r.vis||r.tokens.indexOf("sink")<0)continue;let c=r.el.dataset.fxCap==="1",l=pr(c,r.accreted>0);l.fire==="captured"?(r.el.dataset.fxCap="1",Jt(r.el,"captured",{accreted:r.accreted,load:In(r)}),b("absorb")&&F("absorb",{body:r,count:r.accreted}),B.set(r,r.accreted)):l.fire==="released"&&(r.el.dataset.fxCap="0",Jt(r.el,"released",{accreted:0,load:0}),b("release")&&F("release",{body:r,count:B.get(r)??0}),B.delete(r))}}let Ur=[{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"}],Gr=120;function rn(r,c,l){r.dispatchEvent(new CustomEvent(c,{bubbles:!0,composed:!0,detail:l}))}function Jn(r,c,l,g,d,x){let m=r.get(c);m||r.set(c,m=new Map);let h=m.get(g.metric);h||m.set(g.metric,h=new _e({enter:g.enter,exit:g.exit,debounceMs:Gr}));let w=h.update(d,x);w==="entered"?rn(l,g.rise,{metric:g.metric,value:d}):w==="exited"&&rn(l,g.fall,{metric:g.metric,value:d})}function Vr(r){for(let c of L)if(!(!c.vis||c.tokens.length===0))for(let l of Ur){let g;switch(l.metric){case"density":g=c.d;break;case"attention":O.attention&&(g=c.attn??1);break;case"entropy":g=c.metrics?.entropy;break}g!==void 0&&Jn(A,c,c.el,l,g,r)}for(let c of lt)Jn(j,c.agent,c.from.el,{metric:"memory",enter:.6,exit:.3,rise:"field:memory-threshold",fall:"field:memory-faded"},c.agent.memory,r)}function jr(r){for(let c of Bt)c.docked===r&&(c.docked=null,c.dock.dock=0,c.el.getAttribute("aria-hidden")==="true"&&c.el.removeAttribute("aria-hidden"),c.el.removeAttribute("inert"),c.el.style.opacity="",Jt(c.el,"released",{}))}function Xr(){if(Bt.length===0)return;let r=Bt.map(c=>{let l=c.el.getBoundingClientRect();return{x:l.left-Y+l.width/2,y:l.top-Q+l.height/2}});for(let c=0;c<Bt.length;c++){let l=Bt[c];if(!l.el.isConnected){l.docked&&(l.docked=null,l.dock.dock=0);continue}let g=r[c].x,d=r[c].y;if(l.docked){let M={x:g-l.o.x,y:d-l.o.y};l.dock.dock=gr(l.dock.dock,1);let S=xr(M,l.o,{x:l.docked.cx,y:l.docked.cy},l.dock.dock);l.el.style.transform=`translate(${S.tx.toFixed(2)}px, ${S.ty.toFixed(2)}px) scale(${S.scale.toFixed(3)})`,l.el.style.opacity=S.opacity.toFixed(3),l.dock.dock>=1&&l.el.getAttribute("aria-hidden")!=="true"&&(l.el.setAttribute("aria-hidden","true"),l.el.setAttribute("inert",""));continue}Tt.x=g,Tt.y=d,Tt.vx=0,Tt.vy=0,Tt.heat=0,Tt.cap=null;for(let M of L){if(!M.vis||M.tokens.length===0||M.el===l.el)continue;let S=M.cx-g,T=M.cy-d,k=Math.hypot(S,T);q.dx=S,q.dy=T,q.dist=k<1?1:k;for(let C of M.tokens)p.forces[C]?.apply(M,Tt,q)}Tt.cap=null;let x=Fo(l.o),m=Tt.vx+x.x,h=Tt.vy+x.y;if(l.layout){let M=Co({x:g,y:d},r,c),S=Po((T,k)=>a.near(T,k,40).length,g,d,16,6);m+=M.x+S.x,h+=M.y+S.y}let w={x:g-l.o.x,y:d-l.o.y};if(To(l.o,m,h,l.mEl,.9),l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.dockable){let M={x:w.x+l.o.x,y:w.y+l.o.y},S=L.find(T=>T.vis&&T.el!==l.el&&T.tokens.indexOf("sink")>=0&&Nn(M,T));S&&(l.docked=S,Jt(l.el,"captured",{sink:S.el}))}if(l.warpCool>0&&(l.warpCool-=1),l.warpable&&l.warpCool===0){let M={x:w.x+l.o.x,y:w.y+l.o.y},S=L.find(T=>T.vis&&T.el!==l.el&&T.warpHas&&T.tokens.indexOf("warp")>=0&&Nn(M,T));S&&(l.o.x=S.warpX-w.x,l.o.y=S.warpY-w.y,l.o.vx=0,l.o.vy=0,l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.warpCool=45,Jt(l.el,"relocated",{from:S.el}))}}}function Jr(){jt.length&&(jt=jt.filter(r=>r.el.isConnected?!0:(r.el.removeEventListener("pointerenter",r.enter),r.el.removeEventListener("pointerleave",r.leave),r.el.removeEventListener("focus",r.enter),r.el.removeEventListener("blur",r.leave),delete r.el.dataset.fxEngaged,!1))),_.root.querySelectorAll("[data-hot]").forEach(r=>{let c=r;if(c.dataset.fxEngaged==="1")return;c.dataset.fxEngaged="1";let l=()=>{c.dataset.active="1",pe=c.dataset.color??null;let d=c.closest("[data-index][data-threads]");if(d){let x=[...d.querySelectorAll("[data-hot]")].filter(m=>m!==c);sn(x.map(m=>({a:c,b:m,color:c.dataset.color??void 0})))}},g=()=>{c.dataset.active="0",pe=null,sn(null)};c.addEventListener("pointerenter",l),c.addEventListener("pointerleave",g),c.addEventListener("focus",l),c.addEventListener("blur",g),jt.push({el:c,enter:l,leave:g})})}function sn(r){Ze=(r??[]).map(c=>({a:c.a,b:c.b,c:gt(c.color??O.accent),seed:ht()*6.28}))}function Kr(){if(Ze.length===0)return;let r=q.t;n.globalCompositeOperation="lighter";for(let c of Ze){let l=c.a.getBoundingClientRect(),g=c.b.getBoundingClientRect(),d=l.left-Y+l.width/2,x=l.top-Q+l.height/2,m=g.left-Y+g.width/2,h=g.top-Q+g.height/2,[w,M,S]=c.c;n.strokeStyle=`rgba(${w},${M},${S},0.22)`,n.lineWidth=1,n.beginPath(),n.moveTo(d,x),n.lineTo(m,h),n.stroke();for(let T=0;T<3;T++){let k=(r*.6+c.seed+T/3)%1,C=d+(m-d)*k,H=x+(h-x)*k;n.fillStyle=`rgba(${w},${M},${S},${(1-k)*.9})`,n.beginPath(),n.arc(C,H,2.2,0,6.28318),n.fill()}}n.globalCompositeOperation="source-over"}let ve=0,Qr=[1/0,1.5,1.25,1];function we(r){if(!n)return;let c=Math.min(r||1,O.dprCap,Qr[ve]??1/0);e.width=Math.floor(I*c),e.height=Math.floor($*c),e.style.width=I+"px",e.style.height=$+"px",n.setTransform(c,0,0,c,0,0),i?.size(I,$,c)}function Kn(){let r=_.viewport();I=r.width,$=r.height,Y=r.originX??0,Q=r.originY??0,at=r.originX!=null||r.originY!=null,we(r.dpr),q.W=I,q.H=$,Ut=_.scrollHeight()-$||1;for(let c of y.values())c.resize(I,$);O.heatmap&&(K?K.resize(I,$):K=new de(I,$)),Xn(),xe()}function Zr(){let r=q.t,c=16;if(O.waveStyle==="circular"){let l=Yt||{x:I/2,y:$/2},g=Math.min(I,$)*.48;for(let d of vt){let[x,m,h]=d.color;n.beginPath();let w=.08,M=!0;for(let k=0;k<=2*Math.PI+.01;k+=w){let C=ce(d,k,r,g),H=l.x+Math.cos(k)*C,G=l.y+Math.sin(k)*C;M?(n.moveTo(H,G),M=!1):n.lineTo(H,G)}n.closePath();let S=d.baseFrac*g+d.offsetY,T=n.createRadialGradient(l.x,l.y,Math.max(0,S-d.amp),l.x,l.y,S+d.amp+80);T.addColorStop(0,`rgba(${x},${m},${h},${(.08+d.depth*.04)*ft})`),T.addColorStop(1,`rgba(${x},${m},${h},0)`),n.fillStyle=T,n.fill()}n.globalCompositeOperation="lighter";for(let d of vt){let[x,m,h]=d.color;n.beginPath();let w=.08,M=!0;for(let S=0;S<=2*Math.PI+.01;S+=w){let T=ce(d,S,r,g),k=l.x+Math.cos(S)*T,C=l.y+Math.sin(S)*T;M?(n.moveTo(k,C),M=!1):n.lineTo(k,C)}n.closePath(),n.lineWidth=5,n.strokeStyle=`rgba(${x},${m},${h},${(.05+d.depth*.04)*ft})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${x},${m},${h},${(.3+d.depth*.22)*ft})`,n.stroke()}n.globalCompositeOperation="source-over"}else{for(let l of vt){let[g,d,x]=l.color;n.beginPath(),n.moveTo(0,Et(l,0,r,$,1,1,xt));for(let w=0;w<=I;w+=c)n.lineTo(w,Et(l,w,r,$,1,1,xt));n.lineTo(I,$),n.lineTo(0,$),n.closePath();let m=l.baseFrac*$+l.offsetY-l.amp,h=n.createLinearGradient(0,m,0,m+320);h.addColorStop(0,`rgba(${g},${d},${x},${(.11+l.depth*.05)*ft})`),h.addColorStop(1,`rgba(${g},${d},${x},0)`),n.fillStyle=h,n.fill()}n.globalCompositeOperation="lighter";for(let l of vt){let[g,d,x]=l.color;n.beginPath(),n.moveTo(0,Et(l,0,r,$,1,1,xt));for(let m=0;m<=I;m+=c)n.lineTo(m,Et(l,m,r,$,1,1,xt));n.lineWidth=5,n.strokeStyle=`rgba(${g},${d},${x},${(.05+l.depth*.04)*ft})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${g},${d},${x},${(.3+l.depth*.22)*ft})`,n.stroke()}n.globalCompositeOperation="source-over"}}function ts(){n.globalCompositeOperation="lighter";let r=q.t,c=0;if(O.waveStyle==="circular"){let l=Yt||{x:I/2,y:$/2},g=Math.min(I,$)*.48;for(let d of Dt){let x=vt[d.wi];if(!x){c++;continue}q.dt&&(d.progress+=d.speed,d.progress>1?d.progress-=1:d.progress<0&&(d.progress+=1));let m=d.progress*2*Math.PI,h=ce(x,m,r,g)+d.phase*32,w=l.x+Math.cos(m)*h,M=l.y+Math.sin(m)*h,[S,T,k]=x.color,C=d.glow?.6+.4*Math.sin(r*2.2+c):.85;d.glow&&(n.fillStyle=`rgba(${S},${T},${k},${.16*C*ft})`,n.beginPath(),n.arc(w,M,d.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${S},${T},${k},${C*ft})`,n.beginPath(),n.arc(w,M,d.size,0,6.28318),n.fill(),c++}}else for(let l of Dt){let g=vt[l.wi];if(!g){c++;continue}q.dt&&(l.progress+=l.speed,l.progress>1?l.progress-=1:l.progress<0&&(l.progress+=1));let d=l.progress*I,x=Et(g,d,r,$,1,1,xt)+l.phase*32,[m,h,w]=g.color,M=l.glow?.6+.4*Math.sin(r*2.2+c):.85;l.glow&&(n.fillStyle=`rgba(${m},${h},${w},${.16*M*ft})`,n.beginPath(),n.arc(d,x,l.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${m},${h},${w},${M*ft})`,n.beginPath(),n.arc(d,x,l.size,0,6.28318),n.fill(),c++}n.globalCompositeOperation="source-over"}function es(){if(!O.attention)return;for(let l of L)l.attn=1;let r=L.filter(l=>l.vis&&l.tokens.length>0);if(r.length===0)return;let c=go(r);for(let l=0;l<r.length;l++)r[l].attn=c[l]}function ns(){if(!O.causality)return;let r=L.filter(l=>l.vis&&l.tokens.length>0);if(r.length===0)return;if(r.length===1){Qn(r[0],r[0].d);return}let c=xo(r.map(l=>({d:l.d,cx:l.cx,cy:l.cy})));for(let l=0;l<r.length;l++)Qn(r[l],wt(r[l].d+c[l],0,1))}function Qn(r,c){O.feedbackSink(r.el,{lit:c})}function os(){for(let r of L){if(!r.feedback)continue;let c=po(r.count,r.on);r.d+=(c-r.d)*.08;let l=r.writeTarget??r.el;if(r.fmax){let w=mo(r.fmin,r.fmax,r.d);he.get(l)!==w&&(he.set(l,w),l.style.fontVariationSettings=`"wght" ${w}`+(r.opsz?`, "opsz" ${r.opsz}`:""))}let g=K?K.norm(r.cx,r.cy):void 0,d=r.tokens.indexOf("sink")>=0&&r.capacity>0?In(r):void 0,x=Bo(r.thermo),m=r.metrics??(r.metrics={entropy:0,coherence:1,temperature:0});m.entropy+=(x.entropy-m.entropy)*.08,m.coherence+=(x.coherence-m.coherence)*.08,m.temperature+=(x.temperature-m.temperature)*.08;let h={density:r.d,heatmapDensity:g,load:d,entropy:m.entropy,coherence:m.coherence,temperature:m.temperature};O.feedbackSink(l,h),r.onFeedback?.(h)}}function rs(){if(Vt.length!==0){n.globalCompositeOperation="lighter";for(let r=Vt.length-1;r>=0;r--){let c=Vt[r];if(!c)continue;if(c.x+=c.vx,c.y+=c.vy,c.vx*=.9,c.vy*=.9,c.life*=.85,c.life<.05){Vt.splice(r,1);continue}let[l,g,d]=c.c;n.fillStyle=`rgba(${l},${g},${d},${.18*c.life})`,n.beginPath(),n.arc(c.x,c.y,2+c.life*4,0,6.28318),n.fill(),n.fillStyle=`rgba(${l},${g},${d},${c.life})`,n.beginPath(),n.arc(c.x,c.y,.6+c.life*1.5,0,6.28318),n.fill()}n.globalCompositeOperation="source-over"}}let Wt=null,be=null,Kt=null;function ss(){if(!K)return;let r=$>0?wt((1.15-ne/$)/.85,0,1):1;if(r<=.01)return;let c=K.cell,l=Math.max(1,Math.ceil(I/c)),g=Math.max(1,Math.ceil($/c));if(Wt||(Wt=_.createCanvas(),be=Wt.getContext("2d")),!!be){if((Wt.width!==l||Wt.height!==g)&&(Wt.width=l,Wt.height=g,Kt=null),Kt===null||$t%3===0){Kt===null&&(Kt=be.createImageData(l,g));let d=rt,x=Kt.data;for(let m=0;m<g;m++)for(let h=0;h<l;h++){let w=K.norm(h*c+c/2,m*c+c/2),M=(m*l+h)*4;x[M]=d[0],x[M+1]=d[1],x[M+2]=d[2],x[M+3]=Math.round(wt(w*.5*ft,0,1)*255)}be.putImageData(Kt,0,0)}n.globalCompositeOperation="lighter",n.imageSmoothingEnabled=!0,n.globalAlpha=r,n.drawImage(Wt,0,0,I,$),n.globalAlpha=1,n.globalCompositeOperation="source-over"}}function is(){O.background==="transparent"?O.render==="trails"?(n.globalCompositeOperation="destination-out",n.fillStyle="rgba(0,0,0,0.22)",n.fillRect(0,0,I,$),n.globalCompositeOperation="source-over"):n.clearRect(0,0,I,$):(O.render==="trails"?n.fillStyle="rgba(5,6,11,0.22)":n.fillStyle="rgb(5,6,11)",n.fillRect(0,0,I,$)),Zr(),K&&ve<2&&ss(),ts();let r=O.render!=="metaballs"&&O.render!=="streamlines";n.globalCompositeOperation="lighter";let c=rt,l=I/2,g=$*.4,d=Math.hypot(Math.max(l,I-l),Math.max(g,$-g))||1;if(ye===null||$t%6===0){ye=[];for(let m of L){if(!m.tint)continue;let h=(m.range||200)*1.4;ye.push({b:m,r2:h*h,rgb:gt(m.tint)})}}let x=ye;if(r)for(let m of a.particles){if(m.cap){n.fillStyle=`rgba(${c[0]},${c[1]},${c[2]},${.55*ft})`,n.beginPath(),n.arc(m.x,m.y,1.3,0,6.28318),n.fill();continue}let h=Math.min(1,Math.hypot(m.x-l,m.y-g)/d),w=h*h,M=m.heat;fo(He,w,M,c,O.gradientCool,O.gradientWarm);let S=He[0],T=He[1],k=He[2];if(x.length){let mt=0,nt=null;for(let st of x){let Ft=m.x-st.b.cx,At=m.y-st.b.cy,re=Ft*Ft+At*At;if(re>=st.r2)continue;let P=1-Math.sqrt(re/st.r2);P>mt&&(mt=P,nt=st.rgb)}if(nt){let st=mt*.7;S+=(nt[0]-S)*st,T+=(nt[1]-T)*st,k+=(nt[2]-k)*st}}if(m.color){let[mt,nt,st]=gt(m.color);S+=(mt-S)*.75,T+=(nt-T)*.75,k+=(st-k)*.75}let C=O.depth>0?1-Math.min(Math.abs(m.z??0)/O.depth,1)*.55:1,H=(m.size*(1-.4*w)+M*2)*C,G=wt((.5-.3*w+M*.5)*ft*C,0,1),ct=S|0,pt=T|0,bt=k|0;n.fillStyle=`rgba(${ct},${pt},${bt},${.12*G})`,n.beginPath(),n.arc(m.x,m.y,H+1.2,0,6.28318),n.fill(),n.fillStyle=`rgba(${ct},${pt},${bt},${G})`,n.beginPath(),n.arc(m.x,m.y,H,0,6.28318),n.fill()}if(rs(),Kr(),n.globalCompositeOperation="source-over",O.render==="links"){n.globalCompositeOperation="lighter";let m=rt,h=90;n.lineWidth=.6;for(let w of a.particles)if(!w.cap)for(let M of a.neighbors(w,h)){if(M.x<w.x||M.x===w.x&&M.y<w.y)continue;let S=ir(Math.hypot(M.x-w.x,M.y-w.y),h);S<=0||(n.strokeStyle=`rgba(${m[0]},${m[1]},${m[2]},${S})`,n.beginPath(),n.moveTo(w.x,w.y),n.lineTo(M.x,M.y),n.stroke())}n.globalCompositeOperation="source-over"}if(O.render==="metaballs"){let M=Math.ceil(I/16)+1,S=Math.ceil($/16)+1;!It||It.length!==M*S?It=new Float32Array(M*S):It.fill(0);for(let k of a.particles)k.cap||Cn(It,M,S,16,k.x,k.y,34,1);let T=rt;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${T[0]},${T[1]},${T[2]},${.5*ft})`,n.lineWidth=1.4,n.lineCap="round",n.beginPath();for(let k=0;k<S-1;k++)for(let C=0;C<M-1;C++){let H=It[k*M+C],G=It[k*M+C+1],ct=It[(k+1)*M+C+1],pt=It[(k+1)*M+C],bt=An(H,G,ct,pt,.9);if(!bt.length)continue;let mt=C*16,nt=k*16;for(let st of bt)n.moveTo(mt+st.x1*16,nt+st.y1*16),n.lineTo(mt+st.x2*16,nt+st.y2*16)}n.stroke(),n.globalCompositeOperation="source-over"}if(O.render==="voronoi"){let w=Math.ceil(I/18)+1,M=Math.ceil($/18)+1;(!oe||oe.length!==w*M)&&(oe=new Int32Array(w*M));let S=a.particles,T=new Map;for(let C=0;C<S.length;C++)T.set(S[C],C);for(let C=0;C<M;C++)for(let H=0;H<w;H++){let G=H*18,ct=C*18,pt=a.near(G,ct,54),bt=-1;if(pt.length){let mt=ar(G,ct,pt);mt>=0&&(bt=T.get(pt[mt])??-1)}oe[C*w+H]=bt}let k=rt;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${k[0]},${k[1]},${k[2]},${.32*ft})`,n.lineWidth=1,n.beginPath();for(let C of cr(oe,w,M))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==="streamlines"||O.render==="flow"){let h=rt;if(n.lineWidth=1,n.lineCap="round",ue===null||ut||$t%3===0){let w=[],M=[],S=0;for(let T=46/2;T<I;T+=46)for(let k=46/2;k<$;k+=46){let{fx:C,fy:H}=Zt(L,p.forces,q,T,k);if(ut){let ct=ae(We,T,k,ut,.04);C+=ct.x,H+=ct.y}let G=Math.hypot(C,H);if(!(G>1e-9)){M.push({gx:T,gy:k});continue}w.push({gx:T,gy:k,ux:C/G,uy:H/G,mag:G}),G>S&&(S=G)}_t===0?_t=S:_t=S>_t?_t*.7+S*.3:_t*.9+S*.1,ue=w,Ke=M}if(Ke.length){n.fillStyle=`rgba(${h[0]},${h[1]},${h[2]},0.05)`;for(let w of Ke)n.fillRect(w.gx-.5,w.gy-.5,1,1)}if(_t>0&&ue)for(let w of ue){let M=Math.sqrt(w.mag/_t),S=46*.46*(.28+.72*M),T=w.gx+w.ux*S,k=w.gy+w.uy*S;n.strokeStyle=`rgba(${h[0]},${h[1]},${h[2]},${wt(.1+M*.5,0,.72)})`,n.beginPath(),n.moveTo(w.gx,w.gy),n.lineTo(T,k);let C=3.4;n.moveTo(T,k),n.lineTo(T-w.ux*C-w.uy*C*.6,k-w.uy*C+w.ux*C*.6),n.moveTo(T,k),n.lineTo(T-w.ux*C+w.uy*C*.6,k-w.uy*C-w.ux*C*.6),n.stroke()}}}function Zn(r){return(r===void 0?[]:Array.isArray(r)?r:[r]).filter(l=>l!=="off")}function to(r,c,l){let d=rt;if(Qe===null||ut||$t%3===0){let h=[],w=0;for(let M=44/2;M<I;M+=44)for(let S=44/2;S<$;S+=44){let{fx:T,fy:k}=Zt(L,p.forces,q,M,S);if(ut){let H=ae(We,M,S,ut,.04);T+=H.x,k+=H.y}let C=Math.hypot(T,k);C>1e-9&&(h.push({gx:M,gy:S,ux:T/C,uy:k/C,mag:C}),C>w&&(w=C))}Nt===0?Nt=w:Nt=w>Nt?Nt*.7+w*.3:Nt*.9+w*.1,Qe=h}if(Nt<=0)return;let x={r:d[0],g:d[1],b:d[2],alpha:0,width:1.2},m=new Float64Array(12);for(let h of Qe){let w=l?wt(h.mag/Nt,0,1):Math.sqrt(h.mag/Nt),M=44*.5*(.25+.75*w),S=h.gx+h.ux*M,T=h.gy+h.uy*M,k=3.6;m[0]=h.gx,m[1]=h.gy,m[2]=S,m[3]=T,m[4]=S,m[5]=T,m[6]=S-h.ux*k-h.uy*k*.6,m[7]=T-h.uy*k+h.ux*k*.6,m[8]=S,m[9]=T,m[10]=S-h.ux*k+h.uy*k*.6,m[11]=T-h.uy*k-h.ux*k*.6,x.alpha=wt(.12+w*.55,0,.8),r.segments(m,x)}}function as(r){let c=ko(L);if(!c.length)return;let l=bo((x,m)=>Oe(L,p.forces,x,m),c,{step:6,maxSteps:200,bounds:{w:I,h:$},loopDist:8}),g=rt,d={r:g[0],g:g[1],b:g[2],alpha:.42,width:1.1};for(let x of l){if(x.length<2)continue;let m=new Float32Array(x.length*2);for(let h=0;h<x.length;h++)m[h*2]=x[h].x,m[h*2+1]=x[h].y;r.polyline(m,d)}}function cs(r){let l=22*O.gridWarp,g=48*.46,d=Math.floor(I/48)+2,x=Math.floor($/48)+2,m=new Float32Array(d*x),h=new Float32Array(d*x),w=0,M=new Float32Array(d*x);for(let P=0;P<x;P++)for(let W=0;W<d;W++){let{fx:et,fy:V}=Zt(L,p.forces,q,W*48,P*48),ot=Math.hypot(et,V),Mt=P*d+W;ot>1e-9&&(m[Mt]=et/ot,h[Mt]=V/ot,M[Mt]=ot,ot>w&&(w=ot))}let S=[rt,[120,110,255],[240,70,255],[255,50,130]],T=8,k=P=>w>0?Math.sqrt(M[P]/w):0,C=P=>Math.round(k(P)*T),H=P=>{let W=P/T,et=Mn(S,W);return{r:et[0],g:et[1],b:et[2],alpha:Math.min(1,O.gridIntensity*(.3+.85*W)),width:W>.55?1.4:1}},G=new Float32Array(d*x),ct=new Float32Array(d*x);for(let P=0;P<d*x;P++){let W=k(P);G[P]=m[P]*W*l,ct[P]=h[P]*W*l}let pt=new Float32Array(d*x),bt=new Float32Array(d*x);for(let P=0;P<x;P++)for(let W=0;W<d;W++){let et=0,V=0,ot=0;for(let Ct=-1;Ct<=1;Ct++)for(let Pt=-1;Pt<=1;Pt++){let zt=W+Pt,Ot=P+Ct;if(zt<0||Ot<0||zt>=d||Ot>=x)continue;let Qt=Ot*d+zt;et+=G[Qt],V+=ct[Qt],ot++}let Mt=P*d+W;pt[Mt]=et/ot,bt[Mt]=V/ot}let mt=48*1.5,nt=(P,W)=>{let et=W*d+P,V=pt[et],ot=bt[et],Mt=Math.hypot(V,ot);Mt>g&&(V=V/Mt*g,ot=ot/Mt*g);let Ct=P*48,Pt=W*48,zt=Math.min(Ct,I-Ct,Pt,$-Pt),Ot=zt<=0?0:zt<mt?zt/mt:1;return[Ct+V*Ot,Pt+ot*Ot]},st=4,Ft=P=>{let W=P.length>>1;if(W<3)return P;let et=[P[0],P[1]];for(let V=0;V<W-1;V++){let ot=(V>0?V-1:0)<<1,Mt=V<<1,Ct=V+1<<1,Pt=(V+2<W?V+2:W-1)<<1,zt=P[ot],Ot=P[ot+1],Qt=P[Mt],ln=P[Mt+1],dn=P[Ct],fn=P[Ct+1],io=P[Pt],ao=P[Pt+1];for(let hn=1;hn<=st;hn++){let se=hn/st,un=se*se,co=un*se;et.push(.5*(2*Qt+(-zt+dn)*se+(2*zt-5*Qt+4*dn-io)*un+(-zt+3*Qt-3*dn+io)*co),.5*(2*ln+(-Ot+fn)*se+(2*Ot-5*ln+4*fn-ao)*un+(-Ot+3*ln-3*fn+ao)*co))}}return et},At=(P,W)=>Math.max(C(P*d+W),C(P*d+W+1)),re=(P,W)=>Math.max(C(W*d+P),C((W+1)*d+P));for(let P=0;P<x;P++){let W=At(P,0),et=[...nt(0,P),...nt(1,P)];for(let V=1;V<d-1;V++){let ot=At(P,V);ot===W?et.push(...nt(V+1,P)):(r.polyline(Ft(et),H(W)),et=[...nt(V,P),...nt(V+1,P)],W=ot)}r.polyline(Ft(et),H(W))}for(let P=0;P<d;P++){let W=re(P,0),et=[...nt(P,0),...nt(P,1)];for(let V=1;V<x-1;V++){let ot=re(P,V);ot===W?et.push(...nt(P,V+1)):(r.polyline(Ft(et),H(W)),et=[...nt(P,V),...nt(P,V+1)],W=ot)}r.polyline(Ft(et),H(W))}}let kt=null;function eo(r,c,l){let x=Math.ceil(I/24)+1,m=Math.ceil($/24)+1;!kt||kt.length!==x*m?kt=new Float32Array(x*m):kt.fill(0);let h=!1;for(let k of a.particles){if(k.cap)continue;let C=c(k);C<=0||(h=!0,Cn(kt,x,m,24,k.x,k.y,42,C))}if(!h)return;let w=0;for(let k=0;k<kt.length;k++)kt[k]>w&&(w=kt[k]);if(w<=0)return;let M=rt,S=[.25,.5,.78],T=[];for(let k=0;k<S.length;k++){let C=S[k]*w;T.length=0;for(let H=0;H<m-1;H++)for(let G=0;G<x-1;G++){let ct=kt[H*x+G],pt=kt[H*x+G+1],bt=kt[(H+1)*x+G+1],mt=kt[(H+1)*x+G],nt=An(ct,pt,bt,mt,C);if(!nt.length)continue;let st=G*24,Ft=H*24;for(let At of nt)T.push(st+At.x1*24,Ft+At.y1*24,st+At.x2*24,Ft+At.y2*24)}T.length&&r.segments(T,{r:M[0],g:M[1],b:M[2],alpha:l*(.45+.55*(k/(S.length-1))),width:1+k*.3})}}function ls(r){let d=rt,x={r:d[0],g:d[1],b:d[2],alpha:0,width:1.1},m=new Float64Array(4);for(let h=104/2;h<I;h+=104)for(let w=104/2;w<$;w+=104){let M=h,S=w;for(let T=0;T<24;T++){let{fx:k,fy:C}=Zt(L,p.forces,q,M,S);if(ut){let pt=ae(We,M,S,ut,.04);k+=pt.x,C+=pt.y}let H=Math.hypot(k,C);if(!(H>1e-9))break;let G=M+k/H*9,ct=S+C/H*9;if(G<0||ct<0||G>I||ct>$)break;m[0]=M,m[1]=S,m[2]=G,m[3]=ct,x.alpha=.34*(1-T/24),r.segments(m,x),M=G,S=ct}}}function ds(r){let c=rt;for(let l of L){if(!l.vis||!l.feedback)continue;let g=`d ${l.d.toFixed(2)}`,d=l.cx+l.hw+8,x=l.cy;r.rect(d-3,x-7,r.measureText(g)+6,14,c[0],c[1],c[2],wt(.3+l.d*.55,0,.85)),r.text(g,d,x+.5,5,6,11,.92)}}function fs(r,c){if(r.clear(),!(!c.length||I===0||$===0))for(let l of c){l==="streamlines"?to(r,!1,!1):l==="force-vectors"?to(r,!1,!0):l==="field-lines"?as(r):l==="grid"?cs(r):l==="temperature"?eo(r,d=>d.heat,.5):l==="energy"?eo(r,d=>.5*d.m*(d.vx*d.vx+d.vy*d.vy),.42):l==="path"?ls(r):l==="data"&&ds(r);let g=dt.get(l);g&&g(r,q,I,$)}}function an(r){$t++,q.t=(r-Vn)/1e3,q.frameN=$t;let c=Number.isFinite(Je)?(r-Je)/16.6667:1;if(Je=r,q.dt=yt?0:wt(c,.2,2),ft<1&&(ft=Math.min(1,ft+.012)),qo(q.form,Hn,.03),at){let h=_.viewport();Y=h.originX??0,Q=h.originY??0}let l=_.scrollY(),g=l-ne;if(q.scrollV=(q.scrollV??0)*.7+Math.abs(g)*.3,ne=l,g!==0&&!at)for(let h of L)h.cy-=g;for(let h of vt){let w=l*(.025+h.depth*.08);h.offsetY+=(w-h.offsetY)*.04}if(L.length&&$t%6===0&&(Ne(L,I,$,Y,Q),u(L),mr(L,q.supernova)),lt.length&&q.dt){let h=q.dt/60;for(let w of lt)ur(w.agent,w.from.d>.08,0,h)}let d=null;for(let h of L)if(h.on&&h.vis){d=h;break}let x=ut??d;if(xt.k+=((x?1:0)-xt.k)*.07,x){let h=ut?ut.x:d.cx,w=ut?ut.y:d.cy;xt.x=xt.x?xt.x+(h-xt.x)*.16:h,xt.y=xt.y?xt.y+(w-xt.y)*.16:w}$t%30===0&&(Ut=_.scrollHeight()-$||1);let m=pe?gt(pe):Mn(Gn,l/Ut);if(rt=[rt[0]+(m[0]-rt[0])*.08,rt[1]+(m[1]-rt[1])*.08,rt[2]+(m[2]-rt[2])*.08],O.accent=bn(rt),a.reindex(),es(),q.dt&&Do(L,a.particles),ut&&q.dt)for(let h of a.particles){if(h.cap)continue;let w=ae(We,h.x,h.y,ut,.6);h.vx+=w.x,h.vy+=w.y}if(O.waveStyle==="circular")if(O.waveCenter)Yt=typeof O.waveCenter=="function"?O.waveCenter():O.waveCenter;else{let h=L.find(w=>w.tokens.includes("star")||w.tokens.includes("vortex"));h?Yt={x:h.cx,y:h.cy}:Yt={x:I/2,y:$/2}}else Yt=null;if(Br(),Go({store:a,bodies:L,env:q,forces:p.forces,conditions:p.conditions,waves:vt,waveStyle:O.waveStyle,waveCenter:Yt,separation:O.separation}),Lt&&(Lt.x=Yn,Lt.y=Un,Lt.vx=0,Lt.vy=0,Lt.heat=Math.min(1,Lt.heat+.2)),q.dt){for(let h of y.values())h.step();K&&K.update(a.particles),No(a,Dt,qn,vt,I,$,q.t,ht),Lo(Dt,vt,L,p.forces,I,$,q.t,h=>void a.add(Xt(h))),Xr(),Wr()}if(os(),ns(),Hr(),qr(),Yr(),Vr(r),R(),n&&O.render!=="none"&&Wn&&(!yt||$t%4===0)&&(is(),i)){let h=Zn(O.overlay);h.length&&fs(i,h)}qt=_.raf(an)}function cn(r){let c=Fe[r];c&&(Hn={...c.preset})}let Me="",no=Vn;function oo(){let r=_.viewport().height*.5,c="";_.root.querySelectorAll("[data-formation]").forEach(l=>{let g=l.getBoundingClientRect();g.top<=r&&g.bottom>=r&&(c=l.dataset.formation??"")}),c&&c!==Me&&(Me=c,cn(c))}let ro=()=>void(no=Xe()),hs=()=>{ro(),oo()},so=setInterval(()=>{Xe()-no>6e3&&Me!=="ambient"&&(Me="ambient",cn("ambient"))},1200);so.unref?.();let us=()=>Kn();Kn();let ys=()=>{_.hidden()?(_.cancelRaf(qt),qt=0):qt||(qt=_.raf(an))};return tt.push(_.onResize(us)),tt.push(_.onScroll(hs)),tt.push(_.onVisibility(ys)),tt.push(_.onInput(ro)),tt.push(_.onBodyEvent(nr,Nr)),tt.push(_.onBodyEvent(or,Lr)),tt.push(_.onBodyEvent(rr,Dr)),oo(),qt=_.raf(an),{scan:xe,rescan:xe,setAccent:r=>{O.accent=r,rt=gt(r)},setPalette:r=>{let c=Ae(r);Gn=c.map(gt);let l=c[0];l&&(O.accent=l,rt=gt(l))},setFormation:cn,setWaveStyle:r=>{O.waveStyle=r},setWaveCenter:r=>{O.waveCenter=r},setSeparation:r=>{O.separation=r>=0?r:0},setAttention:r=>{if(O.attention=r,!r)for(let c of L)c.attn=1},setCausality:r=>{if(O.causality=r,!r)for(let c of L)c.el.style.removeProperty("--lit"),c.el.dataset.fxLit="0"},setRender:r=>{if(r!=="none"&&!n){if(n=e.getContext("2d"),!n){console.warn(`Fundamental: setRender('${r}') could not acquire a 2d context; staying in render 'none'`);return}o&&!s&&(s=o.getContext("2d"),s&&!i&&(i=t.overlayBackend??Pn(o,s))),we(_.viewport().dpr)}O.render=r},setOverlay:r=>{O.overlay=r,Zn(r).length||i?.clear()},setHeatmap:r=>{if(O.heatmap=r,r)!K&&I>0&&(K=new de(I,$));else if(K){K.clear(),K=null;for(let c of L)(c.writeTarget??c.el).style.removeProperty("--field-heatmap-density")}},setDprCap:r=>{O.dprCap=r>0?r:2,n&&we(_.viewport().dpr)},setQualityTier:r=>{let c=Math.max(0,Math.min(3,Math.floor(r||0)));c!==ve&&(ve=c,n&&we(_.viewport().dpr))},threads:sn,burst:(r,c,l)=>{for(let d of a.particles){let x=zo(d.x-r,d.y-c,160,6,d.z??0);x.heat!==0&&(d.vx+=x.vx,d.vy+=x.vy,x.vz&&(d.vz=(d.vz??0)+x.vz),d.heat=Math.max(d.heat,x.heat),l&&(d.color=l))}En(Dt,vt,r,c,160,I,$,q.t,d=>void a.add(Xt(d))),jn(r,c,2,l)},flowTo:(r,c,l)=>{ut=vo(r,c,l)},clearFlow:()=>{ut=null},seed:r=>{ge=r,Xn()},atomAt:(r,c)=>{let l=null,g=1/0;for(let d of a.near(r,c,24)){if(d.atom==null)continue;let x=(d.x-r)**2+(d.y-c)**2+(d.z??0)**2;x<g&&(g=x,l=d.atom)}return l},focusAt:(r,c)=>{let l=null,g=1/0;for(let d of a.near(r,c,24)){if(d.atom==null)continue;let x=(d.x-r)**2+(d.y-c)**2+(d.z??0)**2;x<g&&(g=x,l=d)}return Lt=l,l?(Yn=l.x,Un=l.y,l.atom??null):null},clearFocus:()=>{Lt=null},particleCount:()=>a.size,readParticles:r=>{let c=a.particles,l=Math.floor(r.length/5),g=0;for(let d=0;d<c.length&&g<l;d++){let x=c[d];if(x.report!==void 0)continue;let m=g*5;r[m]=x.x,r[m+1]=x.y,r[m+2]=x.z??0,r[m+3]=x.heat,r[m+4]=x.size,g++}return g},readParticleIds:r=>{let c=a.particles,l=0;for(let g=0;g<c.length&&l<r.length;g++){let d=c[g];d.report===void 0&&(r[l++]=d.id??0)}return l},readParticleChannels:(r,c)=>{let l=a.particles,g=0;for(let d=0;d<l.length;d++){let x=l[d];if(!("report"in x&&x.report!==void 0)){if(g>=Math.min(...c.map(m=>m.length)))break;for(let m=0;m<r.length&&!(m>=c.length);m++){let h=r[m];c[m][g]=h==="x"?x.x:h==="y"?x.y:h==="z"?x.z??0:h==="vx"?x.vx:h==="vy"?x.vy:h==="heat"?x.heat:h==="size"?x.size:h==="m"?x.m:h==="id"?x.id??0:h==="age"?x.age??0:h==="charge"?x.charge??0:0}g++}}return g},registerOverlay:(r,c)=>(dt.set(r,c),()=>{dt.delete(r)}),addAgent:r=>{let c=Xt({x:r.x,y:r.y,z:r.z,species:r.species});return c.vx=0,c.vy=0,r.z===void 0&&O.depth<=0&&(c.z=0),r.mass!==void 0&&(c.m=r.mass),c.maxSpeed=r.maxSpeed,c.report=r.report,a.add(c),{particle:c,remove:()=>a.remove(c)}},addBody:r=>{let c={"data-body":Array.isArray(r.tokens)?r.tokens.join(" "):String(r.tokens)};r.strength!=null&&(c["data-strength"]=String(r.strength)),r.range!=null&&(c["data-range"]=String(r.range)),r.spin!=null&&(c["data-spin"]=String(r.spin)),r.angle!=null&&(c["data-angle"]=String(r.angle)),r.color!=null&&(c["data-color"]=r.color);let l=()=>{let h=r.rect();return{left:h.left,top:h.top,right:h.left+h.width,bottom:h.top+h.height,width:h.width,height:h.height,x:h.left,y:h.top,toJSON:()=>({})}},g={tagName:"DIV",id:"",className:"",dataset:r.color!=null?{color:r.color}:{},getAttribute:h=>c[h]??null,hasAttribute:h=>h in c,getBoundingClientRect:l,dispatchEvent:()=>!0,setAttribute:()=>{},removeAttribute:()=>{},style:{setProperty:()=>{},removeProperty:()=>{},getPropertyValue:()=>""}},d=le(g);d.rect=l,d.data=r.data,d.feedback=!0;let x={};d.onFeedback=h=>{Object.assign(x,h),r.onFeedback?.(h)},Z.push(d),L=L.concat(d),Ne([d],I,$,Y,Q);let m={data:r.data,get channels(){return x},set:h=>{h.strength!=null&&(c["data-strength"]=String(h.strength)),h.range!=null&&(c["data-range"]=String(h.range)),h.spin!=null&&(c["data-spin"]=String(h.spin)),h.angle!=null&&(c["data-angle"]=String(h.angle)),h.color!=null&&(c["data-color"]=h.color,g.dataset.color=h.color,d.tint=h.color)},remove:()=>{let h=Z.indexOf(d);h>=0&&Z.splice(h,1),L=L.filter(w=>w!==d);for(let w=lt.length-1;w>=0;w--){let M=lt[w];(M.from===d||M.to===d)&<.splice(w,1)}}};return it.set(m,d),m},addEdge:(r,c,l)=>{let g=it.get(r),d=it.get(c);if(!g||!d)throw new Error("addEdge: both arguments must be handles returned by addBody on this field.");let x={id:`e${D++}`,from:"",to:"",type:l?.type??"related",strength:l?.strength??.5,tension:0,memory:0,active:!1},m={agent:x,from:g,to:d,fromData:r.data,toData:c.data};return lt.push(m),{set:h=>{h.strength!=null&&(x.strength=h.strength<0?0:h.strength>1?1:h.strength),h.type!=null&&(x.type=h.type)},remove:()=>{let h=lt.indexOf(m);h>=0&<.splice(h,1)}}},readEdges:()=>lt.map(r=>({from:r.fromData,to:r.toData,type:r.agent.type,strength:r.agent.strength,memory:r.agent.memory,active:r.agent.active})),addField:(r,c)=>(J.set(r,c),{name:r,set:l=>{J.set(r,l)},remove:()=>{J.delete(r)}}),sampleField:(r,c,l)=>{let g=J.get(r);return g?g(c,l):0},energy:()=>Sr(a.particles),sample:(r,c)=>{let{fx:l,fy:g}=Zt(L,p.forces,q,r,c);return{x:l,y:g}},sampleScalar:(r,c)=>K?K.norm(r,c):(Fn("NOOP_NO_HEATMAP","sampleScalar() returned 0 because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),0),sampleGradient:(r,c)=>K?K.gradient(r,c):(Fn("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:r=>q.grid(r),on:(r,c)=>{let l=v.get(r);return l||(l=new Set,v.set(r,l)),l.add(c),()=>void l.delete(c)},version:ke,scrollV:()=>q.scrollV??0,setVisible:r=>{Wn=r},setBackground:r=>{O.background=r,r==="transparent"&&n&&n.clearRect(0,0,I,$)},destroy:()=>{_.cancelRaf(qt),clearInterval(so);for(let r of tt)r();for(let r of jt)r.el.removeEventListener("pointerenter",r.enter),r.el.removeEventListener("pointerleave",r.leave),r.el.removeEventListener("focus",r.enter),r.el.removeEventListener("blur",r.leave),delete r.el.dataset.fxEngaged;jt=[];for(let r of Bt)(r.docked||r.dock.dock>0)&&(r.docked=null,r.dock.dock=0,r.el.style.opacity="",r.el.getAttribute("aria-hidden")==="true"&&r.el.removeAttribute("aria-hidden"),r.el.removeAttribute("inert"));for(let r of Gt)for(let c of r.emitted)c.remove();Gt=[],a.clear()}}}var Ye={};function Ue(){return Ye.reducedMotion!==void 0?Ye.reducedMotion:typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function Ge(){return Ye.hidden!==void 0?Ye.hidden:typeof document<"u"&&document.hidden}var ta=["--field-density","--d"],zr=!1;function Tr(){if(zr)return[];zr=!0;let e=globalThis.CSS;if(!e||typeof e.registerProperty!="function")return[];let t=[];for(let n of ta)try{e.registerProperty({name:n,syntax:"<number>",inherits:!0,initialValue:"0"}),t.push(n)}catch{}return t}var Fr=["pointerdown","wheel","keydown","touchstart"];function ee(){return Tr(),{root:document,viewport:()=>({width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio||1}),scrollY:()=>window.scrollY||0,scrollHeight:()=>document.documentElement.scrollHeight,reducedMotion:()=>Ue(),hidden:()=>Ge(),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 Fr)window.addEventListener(t,e,{passive:!0});return()=>{for(let t of Fr)window.removeEventListener(t,e)}},onBodyEvent:(e,t)=>(document.addEventListener(e,t),()=>document.removeEventListener(e,t))}}var Ar=["pointerdown","wheel","keydown","touchstart"];function Cr(e){return{root:e,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:()=>Ue(),hidden:()=>Ge(),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 Ar)e.addEventListener(n,t,{passive:!0});return()=>{for(let n of Ar)e.removeEventListener(n,t)}},onBodyEvent:(t,n)=>(e.addEventListener(t,n),()=>e.removeEventListener(t,n))}}function Pr(e,t={}){return qe(e,{...t,host:ee()})}function Ve(e,t={}){let{host:n,bounds:o,...s}=t,i=n??(o?Cr(o):ee());return qe(e,{...s,host:i})}function Bn(){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 fe(e=document.body){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText=dr,e.appendChild(t),t}function Or(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 Rr(e={}){Bn();let{target:t=document.body,...n}=e,o=fe(t),s=Pr(o,n);return{...s,destroy:()=>{s.destroy(),o.remove()}}}var je=class{constructor(t={}){U(this,"canvas");U(this,"field");U(this,"managed");Bn();let{canvas:n,target:o,bounds:s,...i}=t;this.managed=!n,this.canvas=n??(s?Or(s):fe(o)),this.field=Ve(this.canvas,s?{...i,bounds:s}:i)}scan(){this.field.scan()}rescan(){this.field.rescan()}setAccent(t){this.field.setAccent(t)}setPalette(t){this.field.setPalette(t)}setFormation(t){this.field.setFormation(t)}setWaveStyle(t){this.field.setWaveStyle(t)}setWaveCenter(t){this.field.setWaveCenter(t)}setSeparation(t){this.field.setSeparation(t)}setAttention(t){this.field.setAttention(t)}setCausality(t){this.field.setCausality(t)}setHeatmap(t){this.field.setHeatmap(t)}setDprCap(t){this.field.setDprCap(t)}setQualityTier(t){this.field.setQualityTier(t)}setRender(t){this.field.setRender(t)}setOverlay(t){this.field.setOverlay(t)}threads(t){this.field.threads(t)}burst(t,n,o){this.field.burst(t,n,o)}flowTo(t,n,o){this.field.flowTo(t,n,o)}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,o){return this.field.addEdge(t,n,o)}readEdges(){return this.field.readEdges()}addField(t,n){return this.field.addField(t,n)}sampleField(t,n,o){return this.field.sampleField(t,n,o)}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)}on(t,n){return this.field.on(t,n)}get version(){return this.field.version}scrollV(){return this.field.scrollV()}setVisible(t){this.field.setVisible(t)}setBackground(t){this.field.setBackground(t)}destroy(){this.field.destroy(),this.managed&&this.canvas.remove()}};return bs(ea);})();
|
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 hs=Object.defineProperty;var us=(e,t,n)=>t in e?hs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var U=(e,t,n)=>us(e,typeof t!="symbol"?t+"":t,n);var cn="0.9.0";var dn=[{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"}],so=Object.fromEntries(dn.map(e=>[e.id,e])),fn=dn.map(e=>e.color),se=["#4da3ff","#2dd4bf","#a78bfa","#ff6e9c","#ff9d5c"],ln=["spotlight","screen","resonate"],ys=["spawn"],hn=300,un=120;function ps(e){return ln.includes(e)?"modifier":ys.includes(e)?"source":"force"}function Me(e){let t=[],n=[],o=[];for(let s of e){let i=ps(s);i==="modifier"?t.push(s):i==="source"?o.push(s):n.push(s)}return t.length>1&&t.sort((s,i)=>ln.indexOf(s)-ln.indexOf(i)),{modifiers:t,forces:n,sources:o}}var io=[{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(io.map(e=>[e.id,e]));var ao=[{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}],Qi=Object.fromEntries(ao.map(e=>[e.id,e]));var ms={ours:se,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:se:typeof e=="string"?ms[e]??se:se}var yn={warm:{cool:[255,224,200],warm:[255,110,80],wave:["#ff8a5c","#f0628e","#ffc46b"]},cool:{cool:[206,226,255],warm:[74,132,255],wave:["#5c8aff","#62a0f0","#6bc4ff"]},mono:{cool:[232,232,238],warm:[148,148,158],wave:["#8a8a96","#b0b0bc","#9a9aa6"]}},pn="warm";var wt=(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,o=Number.parseInt(n.slice(0,6),16);return Number.isNaN(o)?[77,163,255]:[o>>16&255,o>>8&255,o&255]}var gs=[255,224,200],xs=[255,110,80];function co(e,t,n,o,s=gs,i=xs){let a=s[0]+(i[0]-s[0])*t,f=s[1]+(i[1]-s[1])*t,y=s[2]+(i[2]-s[2])*t;return a+=(o[0]-a)*n,f+=(o[1]-f)*n,y+=(o[2]-y)*n,e[0]=a,e[1]=f,e[2]=y,e}function mn([e,t,n]){let o=s=>wt(Math.round(s),0,255).toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(n)}`}function lo(e,t,n){let[o,s,i]=gt(e),[a,f,y]=gt(t),p=n<0?0:n>1?1:n;return mn([o+(a-o)*p,s+(f-s)*p,i+(y-i)*p])}function gn(e,t){if(e.length===0)return[77,163,255];if(e.length===1)return e[0];let n=wt(t,0,1)*(e.length-1),o=Math.min(e.length-2,Math.floor(n)),s=n-o,i=e[o],a=e[o+1];return[i[0]+(a[0]-i[0])*s,i[1]+(a[1]-i[1])*s,i[2]+(a[2]-i[2])*s]}function fo(e,t,n,o=0){if(!(t>0))return 1;let s=Math.max(0,1-e/t),i=1-n*s*s,a=Math.min(Math.max(o,0),1);return i<a?a:i>1?1:i}var Se=1;function ze(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,o=Math.min(t,n),s=e.ux*o,i=e.uy*o,a=e.spin<0?-1:1;return[{x:e.cx+s,y:e.cy+i,q:a},{x:e.cx-s,y:e.cy-i,q:-a}]}function ho(e,t,n){let o=0,s=0;for(let i of e){let a=t-i.x,f=n-i.y,y=Math.max(Se,Math.hypot(a,f)),p=i.q/(y*y);o+=a/y*p,s+=f/y*p}return{x:o,y:s}}function uo(e,t){let n=e/20+(t?.45:0);return n<0?0:n>1?1:n}function yo(e,t,n){return Math.round(e+(t-e)*n)}function po(e,t={}){let n=t.beta??2,o=t.lo??.25,s=t.hi??3,i=e.length,a=new Array(i).fill(1);if(i===0)return a;let f=0,y=0;for(let v of e){let b=v.strength>0?v.strength:0;f+=b,y+=b*(1+(v.on?n:0))}if(f<=0||y<=0)return a;let p=f/y;for(let v=0;v<i;v++){let E=(1+(e[v].on?n:0))*p;E<o?E=o:E>s&&(E=s),a[v]=E}return a}function mo(e,t={}){let n=t.threshold??.55,o=t.kappa??.6,s=t.falloff??320,i=e.length,a=new Array(i).fill(0);if(i<2)return a;let f=new Array(i).fill(0);for(let y=0;y<i;y++){let p=e[y],v=p.d-n;if(v<=0)continue;let b=0;for(let z=0;z<i;z++){if(z===y){f[z]=0;continue}let F=e[z],R=Math.hypot(p.cx-F.cx,p.cy-F.cy),B=R<s?1-R/s:0;f[z]=B,b+=B}if(b<=0)continue;let E=o*v;for(let z=0;z<i;z++){let F=f[z];if(F<=0)continue;let R=E*F/b;a[z]+=R,a[y]-=R}}return a}var Ht={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null};function Zt(e,t,n,o,s){Ht.x=o,Ht.y=s,Ht.vx=0,Ht.vy=0,Ht.heat=0;let i=0,a=0;for(let f of e){if(!f.vis||f.tokens.length===0)continue;let y,p;if(f.shaped){let E=f.cx-f.hw,z=f.cx+f.hw,F=f.cy-f.hh,R=f.cy+f.hh;y=(o<E?E:o>z?z:o)-o,p=(s<F?F:s>R?R:s)-s}else y=f.cx-o,p=f.cy-s;let v=y*y+p*p;if(f.range>0&&v>=f.range*f.range*2.56)continue;let b=Math.sqrt(v);n.dx=y,n.dy=p,n.dist=b<1?1:b;for(let E of f.tokens){let z=t[E];if(!(!z||z.modify))if(z.field){let F=z.field(f,o,s);i+=F.x,a+=F.y}else z.apply(f,Ht,n)}}return{fx:Ht.vx+i,fy:Ht.vy+a}}function Te(e,t,n,o){let s=0,i=0;for(let a of e)if(!(!a.vis||a.tokens.length===0)){if(a.range>0){let f=a.cx-n,y=a.cy-o;if(f*f+y*y>=a.range*a.range*2.56)continue}for(let f of a.tokens){let y=t[f];if(y?.field){let p=y.field(a,n,o);s+=p.x,i+=p.y}}}return{x:s,y:i}}function go(e,t,n={}){return{x:e,y:t,strength:n.strength??1,radius:n.radius&&n.radius>0?n.radius:360}}function ie(e,t,n,o,s=.6){let i=o.x-t,a=o.y-n,f=Math.hypot(i,a);if(f===0||f>=o.radius)return e.x=0,e.y=0,e;let y=(1-f/o.radius)*o.strength*s;return e.x=i/f*y,e.y=a/f*y,e}var vs={step:6,maxSteps:400,minStrength:1e-9,loopDist:6,maxTurns:1/0};function xo(e,t,n,o,s){let i=[{x:t,y:n}],a=t,f=n,y=s.step,p=s.maxTurns*2*Math.PI,v=0,b=0,E=0;for(let z=0;z<s.maxSteps;z++){let F=e(a,f),R=Math.hypot(F.x,F.y);if(!(R>=s.minStrength))break;let B=F.x/R*o,N=F.y/R*o;if(Number.isFinite(p)){if(v!==0||b!==0){let X=Math.max(-1,Math.min(1,B*v+N*b));if(E+=Math.acos(X),E>p)break}v=B,b=N}if(a+=B*s.step,f+=N*s.step,s.bounds&&(a<-y||f<-y||a>s.bounds.w+y||f>s.bounds.h+y))break;if(z>4&&Math.hypot(a-t,f-n)<s.loopDist){i.push({x:a,y:f});break}i.push({x:a,y:f})}return i}function ws(e,t,n,o={}){let s={...vs,bounds:o.bounds,...o},i=xo(e,t,n,-1,s),a=xo(e,t,n,1,s);return i.reverse(),i.pop(),i.concat(a)}function vo(e,t,n={}){return t.map(o=>ws(e,o.x,o.y,n)).filter(o=>o.length>1)}var bs=8,Ms=60;function wo(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},o=ze(n),s=Math.hypot(o[0].x-o[1].x,o[0].y-o[1].y);if(s<Math.max(e.range*.06,bs)){let p=Math.max(e.range*.18,Ms),v=e.spin<0?-1:1;o=[{x:e.cx+e.ux*p,y:e.cy+e.uy*p,q:v},{x:e.cx-e.ux*p,y:e.cy-e.uy*p,q:-v}],s=Math.hypot(o[0].x-o[1].x,o[0].y-o[1].y)}let i=-e.uy,a=e.ux,f=Math.max(s*.13,18),y=[{x:e.cx,y:e.cy}];for(let p=1;p<=t;p++){let v=p*f;y.push({x:e.cx+i*v,y:e.cy+a*v}),y.push({x:e.cx-i*v,y:e.cy-a*v})}return y}function bo(e,t=18){let n=Math.max(Math.min(e.hw,e.hh)*.8,24),o=[];for(let s=0;s<t;s++){let i=s/t*Math.PI*2;o.push({x:e.cx+Math.cos(i)*n,y:e.cy+Math.sin(i)*n})}return o}function Mo(e,t=8){let n=[];for(let o of e)!o.vis||o.tokens.length===0||(o.tokens.includes("magnetism")?n.push(...wo(o,t)):(o.tokens.includes("charge")||o.tokens.includes("gravity"))&&n.push(...bo(o)));return n}function Eo(e,t=Math.random){return 3+Math.floor(t()*(e>0?e:1)*3)}function ko(e,t,n,o=6,s=0){let i=Math.hypot(e,t,s)||1;if(i>=n)return{vx:0,vy:0,vz:0,heat:0};let a=1-i/n,f=a*o;return{vx:e/i*f,vy:t/i*f,vz:s/i*f,heat:a*.9}}function So(e,t,n,o,s=.9,i=80){let a=o>0?o:1;e.vx=(e.vx+t/a)*s,e.vy=(e.vy+n/a)*s,e.x+=e.vx,e.y+=e.vy;let f=Math.hypot(e.x,e.y);f>i&&(e.x=e.x/f*i,e.y=e.y/f*i)}function zo(e,t=.02){return{x:-e.x*t,y:-e.y*t}}function To(e){let t=e/3e4;return t<.6?.6:t>6?6:t}function Fo(e,t,n=-1,o=1600,s=26){let i=0,a=0,f=s*s;for(let y=0;y<t.length;y++){if(y===n)continue;let p=t[y],v=e.x-p.x,b=e.y-p.y,E=v*v+b*b+f;i+=o*v/E,a+=o*b/E}return{x:i,y:a}}function Ao(e,t,n,o=16,s=1){let i=(e(t+o,n)-e(t-o,n))/(2*o),a=(e(t,n+o)-e(t,n-o))/(2*o);return{x:-i*s,y:-a*s}}var Es=[.24,.4,.55,.7,.85];function Co(e){let t=[];for(let n=0;n<5;n++)t.push({baseFrac:Es[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 Po(e,t,n){let o=Math.round(16*t),s=[];for(let i=0;i<e;i++)for(let a=0;a<o;a++)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 Et(e,t,n,o,s=1,i=1,a){let f=e.baseFrac*o+e.offsetY+Math.sin(t*e.freq+e.phase+n*e.speed*1e3*s)*e.amp*i;if(a&&a.k>.001){let y=t-a.x,p=260,v=Math.exp(-(y*y)/(2*p*p));f+=(a.y-f)*.42*v*a.k*(.45+e.depth*.55)}return f}function Oo(e,t,n,o=1,s=1){return Math.cos(t*e.freq+e.phase+n*e.speed*1e3*o)*e.amp*e.freq*s}function ae(e,t,n,o,s=1,i=1){let a=e.baseFrac*o+e.offsetY,f=Math.max(1,Math.round(e.freq*2500));return a+Math.sin(f*t+e.phase+n*e.speed*1e3*s)*e.amp*i}function Ro(e,t,n,o,s,i,a,f,y=1,p=1,v){if(a==="circular"){let b=t-f.x,E=n-f.y,z=Math.sqrt(b*b+E*E)||.001,F=Math.atan2(E,b),R=Math.min(s,i)*.48,B=ae(e,F,o,R,y,p);return{dist:Math.abs(z-B),rWave:B,r:z,theta:F}}else{let b=Et(e,t,o,i,y,p,v);return{dist:Math.abs(n-b),rWave:b,r:n,theta:0}}}function $o(e,t,n,o,s,i,a,f){if(o.length===0)return;let y=e.particles;for(let p=y.length-1;p>=0&&!(t.length>=n);p--){let v=y[p];if(!v||v.cap||v.heat>=.12)continue;let b=-1,E=1e9,z=0;for(let R=0;R<o.length;R++){let B=Et(o[R],v.x,a,i),N=Math.abs(B-v.y);N<E&&(E=N,b=R,z=B)}if(b<0||E>=64)continue;let F=Math.min(.012,E*4e-4)*(1-v.heat/.12);v.vy+=z>v.y?F:-F,E<20&&v.vx*v.vx+v.vy*v.vy<.3&&f()<.03&&(t.push({wi:b,progress:v.x/s,phase:(f()-.5)*.22*Math.PI,size:v.size,glow:f()<.3,speed:(35e-5+f()*9e-4)*(f()<.5?1:-1)}),e.remove(v))}}function xn(e,t,n,o,s,i,a,f,y){for(let p=e.length-1;p>=0;p--){let v=e[p];if(!v)continue;let b=t[v.wi];if(!b)continue;let E=v.progress*i,z=Et(b,E,f,a)+v.phase*32,F=E-n,R=z-o,B=Math.hypot(F,R);if(B<s&&B>.5){let N=(1-B/s)*4;y({x:E,y:z,vx:F/B*N,vy:R/B*N,size:v.size,heat:.9});let X=e.pop();X&&p<e.length&&(e[p]=X)}}}function Io(e,t,n,o,s,i,a,f){let y=p=>p.tokens.some(v=>{let b=o[v];return!!b&&!b.modify&&!b.source});for(let p=e.length-1;p>=0;p--){let v=e[p];if(!v)continue;let b=t[v.wi];if(!b)continue;let E=v.progress*s,z=Et(b,E,a,i)+v.phase*32,F=!1,R=0,B=0;for(let N of n){if(!N.vis||N.when==="active"&&!N.on||N.when&&N.when!=="active")continue;let X=N.tokens,u=N.cx-E,Z=N.cy-z,it=Math.hypot(u,Z)||1,lt=N.range*(N.on?1.4:1);if(X.indexOf("wall")>=0&&Math.abs(E-N.cx)<N.hw+6&&Math.abs(z-N.cy)<N.hh+6&&(R=(E<N.cx?-1:1)*1.6,B=(z<N.cy?-1:1)*.8,F=!0),!F&&(X.indexOf("attract")>=0||X.indexOf("sink")>=0||X.indexOf("jet")>=0)&&it<lt*.8){let D=1.2+(N.on?1.6:0);R=u/it*D,B=Z/it*D,F=!0}if(!F&&X.indexOf("repel")>=0&&it<lt*.8){let D=1.2+(N.on?1.2:0);R=-(u/it)*D,B=-(Z/it)*D,F=!0}if(!F&&X.indexOf("swirl")>=0&&it<lt*.75&&(R=Z/it*1.2,B=-(u/it)*1.2,F=!0),!F&&X.indexOf("stream")>=0&&it<lt*.75&&(R=N.ux*1.3,B=N.uy*1.3,F=!0),!F&&it<lt*.8&&y(N)){let D=.8+(N.on?.8:0);R=u/it*D,B=Z/it*D,F=!0}if(F)break}if(F){f({x:E,y:z,vx:R,vy:B,size:v.size,heat:.5});let N=e.pop();N&&p<e.length&&(e[p]=N)}}}function No(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 o=n.range*n.range;for(let s of t){if(s.charge)continue;let i=n.cx-s.x,a=n.cy-s.y;i*i+a*a>=o||(s.charge=i>=0?1:-1)}}}var Fe=class{constructor(t=64){U(this,"cell");U(this,"bins",new Map);this.cell=t>0?t:64}key(t,n){return(t+32768)*65536+(n+32768)}clear(){this.bins.clear()}insert(t){let n=this.key(Math.floor(t.x/this.cell),Math.floor(t.y/this.cell)),o=this.bins.get(n);o?o.push(t):this.bins.set(n,[t])}rebuild(t){this.clear();for(let n of t)this.insert(n)}near(t,n,o,s=0){let i=[],a=o*o,f=Math.floor((t-o)/this.cell),y=Math.floor((t+o)/this.cell),p=Math.floor((n-o)/this.cell),v=Math.floor((n+o)/this.cell);for(let b=f;b<=y;b++)for(let E=p;E<=v;E++){let z=this.bins.get(this.key(b,E));if(z)for(let F of z){let R=F.x-t,B=F.y-n,N=(F.z??0)-s;R*R+B*B+N*N<=a&&i.push(F)}}return i}};var Lo=e=>e<0?0:e>1?1:e;function Do(e){if(!e||e.n===0)return{entropy:0,coherence:1,temperature:0};let t=e.sh/e.n,n=e.ss/e.n,o=e.ss2/e.n,s=Lo(.5*t+.5*Math.min(1,o/9)),i=e.ss>1e-9?Math.hypot(e.sx,e.sy)/e.ss:1,a=Lo((1-i)*Math.min(1,n/1.5));return{entropy:a,coherence:1-a,temperature:s}}var Ae=class{constructor(t=64){U(this,"particles",[]);U(this,"hash");this.hash=new Fe(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 o=this.particles.pop();o&&n<this.particles.length&&(this.particles[n]=o)}clear(){this.particles.length=0,this.hash.clear()}reindex(){this.hash.rebuild(this.particles)}neighbors(t,n){let o=this.hash.near(t.x,t.y,n,t.z??0),s=[];for(let i of o)i!==t&&s.push(i);return s}near(t,n,o){return this.hash.near(t,n,o)}};var _o={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};var Ce=class{constructor(){U(this,"pending",new Map);U(this,"ids",new WeakMap);U(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==="met"){let s=n,[i,a]=[this.idOf(s.a.el??s.a),this.idOf(s.b.el??s.b)].sort((f,y)=>f-y);return`${i}:${a}`}if(t==="enter"||t==="exit"){let s=n;return`${this.idOf(s.body.el??s.body)}:${this.idOf(s.other.el??s.other)}`}let o=n;return String(this.idOf(o.body.el??o.body))}record(t,n){let o=this.pending.get(t);o||this.pending.set(t,o=new Map),o.set(this.keyOf(t,n),n)}flush(t){if(this.pending.size!==0){for(let[n,o]of this.pending)for(let s of o.values())t(n,s);this.pending.clear()}}};function vn(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 wn(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}}function Bo(){let e={},t={..._o};return{forces:e,conditions:t,force(n){e[n.token]=n},condition(n,o){t[n]=o}}}function Wo(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 Ho(e){for(let t of e)if(t.vis&&t.tokens.indexOf("sink")>=0)return t;return null}var bn=.95,ks=.972,St=10;function Ss(e,t,n,o){if(!t.when)return!0;let s=e[t.when];return s?s(t,n,o):!0}function qo(e){return e.classified??(e.classified=Me(e.tokens))}function Mn(e,t,n,o,s){if(s===1||e.kinematic){e.apply(t,n,o);return}let i=n.vx,a=n.vy,f=n.vz??0;e.apply(t,n,o),n.vx=i+(n.vx-i)*s,n.vy=a+(n.vy-a)*s,n.vz!==void 0&&(n.vz=f+(n.vz-f)*s)}function Yo(e){let{store:t,bodies:n,env:o,forces:s,conditions:i,waves:a,separation:f}=e,y=o.dt;if(y===0)return;let{W:p,H:v,form:b}=o;o.fieldAt=(u,Z)=>Te(n,s,u,Z);for(let u of n){u.count=0;let Z=u.thermo;Z&&(Z.n=0,Z.sx=0,Z.sy=0,Z.ss=0,Z.ss2=0,Z.sh=0)}let E=null;for(let u of n)u.vis&&u.tokens.length>0&&qo(u).modifiers.indexOf("screen")>=0&&(E??(E=[])).push(u);let z=E?new Array(E.length):null,F=!!a&&a.length>0,R=n.length>0,B=null,N=b.conv>.02?Ho(n):null,X=o.D??0;for(let u of t.particles){if(u.cap){u.x+=(u.cap.cx-u.x)*.18,u.y+=(u.cap.cy-u.y)*.18,u.z&&(u.z+=-u.z*.18);continue}u.z===void 0&&(u.z=0),u.vz===void 0&&(u.vz=0);let Z=u.z;if(F)if(e.waveStyle==="circular"){let D=null,A=1e9,j=0,J=0,dt=0,_=e.waveCenter||{x:p/2,y:v/2};for(let tt of a){let yt=Ro(tt,u.x,u.y,o.t,p,v,"circular",_);yt.dist<A&&(A=yt.dist,D=tt,j=yt.r,J=yt.rWave,dt=yt.theta)}if(D&&A<70){let tt=1-A/70,yt=-Math.sin(dt)*D.dir,Rt=Math.cos(dt)*D.dir;u.vx+=yt*.035*tt,u.vy+=Rt*.035*tt;let O=Math.cos(dt)*Math.sign(J-j),K=Math.sin(dt)*Math.sign(J-j);u.vx+=O*.05*tt,u.vy+=K*.05*tt}}else{let D=null,A=1e9;for(let j of a){let J=Math.abs(Et(j,u.x,o.t,v)-u.y);J<A&&(A=J,D=j)}D&&A<70&&(u.vx+=D.dir*.035*(1-A/70),u.vy+=Oo(D,u.x,o.t)*.1*(1-A/70))}if(b.driftX&&(u.vx+=b.driftX*.02),b.spread>.02){let D=u.gx??.5,A=u.gy??.5,j=(D+o.frameN*4e-5)%1*p,J=A*v;u.vx+=(j-u.x)*6e-4*b.spread,u.vy+=(J-u.y)*6e-4*b.spread,X>0&&(u.vz+=((u.gz??.5)*X-Z)*6e-4*b.spread)}if(N){let D=N.cx-u.x,A=N.cy-u.y,j=-Z,J=Math.hypot(D,A,j)||1;u.vx+=D/J*b.conv*.06,u.vy+=A/J*b.conv*.06,u.vz+=j/J*b.conv*.06}if(R){if(E)for(let A=0;A<E.length;A++){let j=E[A],J=j.cx-u.x,dt=j.cy-u.y;z[A]=fo(Math.sqrt(J*J+dt*dt),j.range,j.strength,j.screenMin??0)}let D=u.m!==1&&u.m>0?1/u.m:1;for(let A of n){if(!A.vis||A.tokens.length===0||A.affects!==void 0&&!A.affects.has(u.species??0))continue;let j,J;if(A.shaped){let Y=A.cx-A.hw,Q=A.cx+A.hw,at=A.cy-A.hh,Ut=A.cy+A.hh,ee=u.x<Y?Y:u.x>Q?Q:u.x,fe=u.y<at?at:u.y>Ut?Ut:u.y;j=ee-u.x,J=fe-u.y}else j=A.cx-u.x,J=A.cy-u.y;let dt=-u.z,_=j*j+J*J+dt*dt;if(A.range>0&&_>=A.range*A.range*2.56)continue;let tt=Math.sqrt(_);if(A.feedback&&tt<A.range*.5){A.count+=1-tt/(A.range*.5);let Y=A.thermo??(A.thermo={n:0,sx:0,sy:0,ss:0,ss2:0,sh:0}),Q=u.vx*u.vx+u.vy*u.vy;Y.n++,Y.sx+=u.vx,Y.sy+=u.vy,Y.ss+=Math.sqrt(Q),Y.ss2+=Q,Y.sh+=u.heat}if(A.when&&!Ss(i,A,u,o))continue;o.dx=j,o.dy=J,o.dz=dt,o.dist=tt<1?1:tt;let yt=qo(A),Rt=1,O=!1,K=!1;for(let Y of yt.modifiers){let Q=s[Y]?.modify;if(!Q)continue;K=!0;let at=Q(A,u,o);at.strength!=null&&(Rt*=at.strength),at.gate&&(O=!0)}for(let Y of yt.forces){let Q=s[Y]?.modify;if(!Q)continue;K=!0;let at=Q(A,u,o);at.strength!=null&&(Rt*=at.strength),at.gate&&(O=!0)}if(O)continue;let L=1;if(E)for(let Y=0;Y<E.length;Y++)E[Y]!==A&&(L*=z[Y]);let I=A.attn??1,$=Rt*I*L;if(!K&&$===1)for(let Y of A.tokens){let Q=s[Y];Q&&Mn(Q,A,u,o,D)}else if(K){let Y=A.strength;A.strength=Y*$;for(let Q of A.tokens){let at=s[Q];at&&!at.modify&&Mn(at,A,u,o,D)}A.strength=Y}else{let Y=A.strength;A.strength=Y*$;for(let Q of A.tokens){let at=s[Q];at&&Mn(at,A,u,o,D)}A.strength=Y}}}if(f&&f>0){let D=o.neighbors(u,12);for(let A of D){let j=u.x-A.x,J=u.y-A.y,dt=(u.z??0)-(A.z??0),_=Math.hypot(j,J,dt)||.1;if(_<12){let tt=(12-_)/12*f*.12;u.vx+=j/_*tt,u.vy+=J/_*tt,u.vz!==void 0&&(u.vz+=dt/_*tt)}}}let it=o.c,lt=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(lt>it*it){let D=it/Math.sqrt(lt);u.vx*=D,u.vy*=D,u.vz*=D}if(u.maxSpeed!==void 0){let D=u.maxSpeed*u.maxSpeed,A=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(A>D){let j=u.maxSpeed/Math.sqrt(A);u.vx*=j,u.vy*=j,u.vz*=j}}if(u.x+=u.vx*y,u.y+=u.vy*y,u.z+=u.vz*y,u.vx*=bn,u.vy*=bn,u.vz*=bn,u.report===void 0){if(o.frameN%40===0&&b.wander>0){let D=.05*b.wander;u.vx+=((o.rng??Math.random)()-.5)*D,u.vy+=((o.rng??Math.random)()-.5)*D,X>0&&(u.vz+=((o.rng??Math.random)()-.5)*D)}if(b.wander>.05){let D=(Math.sin(u.x*.0032+o.t*.12)+Math.cos(u.y*.0034-o.t*.15))*Math.PI;u.vx+=Math.cos(D)*.013*b.wander,u.vy+=Math.sin(D)*.013*b.wander}}u.heat*=ks,u.age!=null&&(u.age-=y,u.age<=0&&(B??(B=[])).push(u)),u.report===void 0?(u.x<-St?u.x=p+St:u.x>p+St&&(u.x=-St),u.y<-St?u.y=v+St:u.y>v+St&&(u.y=-St),X>0&&(u.z<-St?u.z=X+St:u.z>X+St&&(u.z=-St))):(u.x<0?(u.x=0,u.vx=Math.abs(u.vx)):u.x>p&&(u.x=p,u.vx=-Math.abs(u.vx)),u.y<0?(u.y=0,u.vy=Math.abs(u.vy)):u.y>v&&(u.y=v,u.vy=-Math.abs(u.vy)),X>0&&(u.z<0?(u.z=0,u.vz=Math.abs(u.vz)):u.z>X&&(u.z=X,u.vz=-Math.abs(u.vz))),u.report(u))}if(R){for(let u of n)if(!(!u.vis||u.tokens.length===0))for(let Z of u.tokens)s[Z]?.source?.(u,o)}if(B)for(let u of B)t.remove(u)}var Uo={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 zs(){return globalThis.process?.env?.NODE_ENV!=="production"}var Vo=zs();function jo(){return Vo}var Go=new Set;function En(e,t){if(!Vo)return;let n=`${e}:${t}`;Go.has(n)||(Go.add(n),console.warn(`[Fundamental:${e}] ${t}`))}var Ts={"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 Xo(e,t={}){let n=Ts[e];if(!n)return null;let o=[...n.body];t.risk==="high"&&!o.includes("thermal")&&o.push("thermal");let s={"data-body":o.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:o.join(" "),strength:t.intensity,range:n.range,feedback:n.feedback??!1,render:n.render??["particles"],attributes:s}}function Ko(e){let t=(z,F)=>{let R=Number.parseFloat(e.get(z)??"");return Number.isFinite(R)?R:F},n=t("strength",.5),o=t("angle",0)*Math.PI/180,s=e.get("spin"),i=s==null?1:Number.isFinite(Number.parseFloat(s))?Number.parseFloat(s):0,a=(e.get("body")??"").split(/\s+/).filter(Boolean),f=Me(a),y=e.get("life"),p=e.get("cap"),v=Number.parseFloat(y??""),b=Number.parseFloat(p??""),E=y!=null||p!=null||e.has("budget")||e.has("sink");return{tokens:a,classified:f,...Number.isFinite(v)&&v>0?{life:v}:{},...Number.isFinite(b)&&b>0?{cap:b}:{},budgeted:E,strength:n,range:t("range",280),absorbR:t("absorb",64),capacity:t("max",60),spin:i,angle:o,ux:Math.cos(o),uy:Math.sin(o),when:e.get("when")??"",feedback:e.has("feedback"),shaped:e.has("shaped"),...e.get("species")!=null&&Number.isFinite(Number.parseFloat(e.get("species")))?{species:Number.parseFloat(e.get("species"))}:{},...(()=>{let z=e.get("affects");if(z==null)return{};let F=z.split(",").map(R=>Number.parseFloat(R.trim())).filter(R=>Number.isFinite(R));return F.length?{affects:new Set(F)}:{}})(),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 Fs(e){let t={body:e.body};return e.strength!=null&&(t.strength=String(e.strength)),e.range!=null&&(t.range=String(e.range)),e.spin!=null&&(t.spin=String(e.spin)),e.angle!=null&&(t.angle=String(e.angle)),e.absorb!=null&&(t.absorb=String(e.absorb)),e.max!=null&&(t.max=String(e.max)),e.life!=null&&(t.life=String(e.life)),e.cap!=null&&(t.cap=String(e.cap)),{get:n=>t[n]??null,has:n=>n in t}}function As(e){let t=Uo[e];return t?t.map(n=>Ko(Fs(n))):[]}function Cs(e){let t=(e.tagName??"element").toLowerCase(),n=e.id?`#${e.id}`:"",o=typeof e.className=="string"&&e.className?`.${e.className.split(/\s+/)[0]}`:"";return`<${t}${n}${o}>`}function Ps(e,t="<body>"){!e.classified||e.classified.sources.length===0||e.budgeted||(e.life=hn,e.cap=un,jo()&&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="${hn}", data-cap="${un}") \u2014 declare one to make the source's budget explicit (workover v0.3 source rules).`))}function Qo(e,t){return Ps(t,Cs(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 Os(e){return{get:t=>e.getAttribute("data-"+t),has:t=>e.hasAttribute("data-"+t)}}function ce(e,t){return Qo(e,Ko(t??Os(e)))}var Jo={source:"jet",sink:"sink",anchor:"tether",boundary:"wall",sensor:"",display:""};function Rs(e){let t=null,n=e.getAttribute("data-intent");if(n){let s=e.getAttribute("data-intensity"),i=Xo(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 Jo&&(t={body:Jo[s],feedback:""})}if(!t)return null;let o=t;return{get:s=>e.getAttribute("data-"+s)??o[s]??null,has:s=>e.hasAttribute("data-"+s)||s in o}}function Zo(e){let t=[];return e.querySelectorAll("[data-body]").forEach(n=>{t.push(ce(n))}),e.querySelectorAll("[data-preset]").forEach(n=>{let o=n;for(let s of As(o.dataset.preset??""))t.push(Qo(o,s))}),e.querySelectorAll("[data-intent]:not([data-body]), [data-field-role]:not([data-body]):not([data-intent])").forEach(n=>{let o=Rs(n);o&&t.push(ce(n,o))}),t}function $s(e){let t=e.el;if(typeof t.getAttribute!="function")return;let n=t.getAttribute("data-strength");if(n!=null){let a=Number.parseFloat(n);Number.isFinite(a)&&(e.strength=a,e.M=a)}let o=t.getAttribute("data-range");if(o!=null){let a=Number.parseFloat(o);Number.isFinite(a)&&(e.range=a)}let s=t.getAttribute("data-spin");if(s!=null){let a=Number.parseFloat(s);Number.isFinite(a)&&(e.spin=a)}let i=t.getAttribute("data-angle");if(i!=null){let a=Number.parseFloat(i);Number.isFinite(a)&&(e.angle=a*Math.PI/180,e.ux=Math.cos(e.angle),e.uy=Math.sin(e.angle))}}function Pe(e,t,n,o=0,s=0){let i=n*.15;for(let a of e){let f=a.rect?a.rect():a.el.getBoundingClientRect(),y=f.left-o,p=f.top-s;a.cx=y+f.width/2,a.cy=p+f.height/2,a.hw=f.width/2,a.hh=f.height/2,a.on=a.el.dataset.active==="1",a.vis=p+f.height>-i&&p<n+i&&y+f.width>-i&&y<t+i,$s(a)}}var tr="field:register-body",er="field:unregister-body",nr="field:update-body";var Oe=class{constructor(){U(this,"hosts",new Map)}register(t){this.hosts.set(t.element,t)}unregister(t){this.hosts.delete(t)}get size(){return this.hosts.size}bodies(t){let n=[];for(let[o,s]of this.hosts){if(!o.isConnected){this.hosts.delete(o);continue}let i=s.attrs?Is(s.attrs,o):void 0,a=t(o,i);s.getRect&&(a.rect=s.getRect),s.writeTarget&&(a.writeTarget=s.writeTarget),n.push(a)}return n}};function Is(e,t){return{get:n=>e[n]??t.getAttribute("data-"+n),has:n=>n in e||t.hasAttribute("data-"+n)}}function rr(e,t,n=.12){return e>=t?0:(1-e/t)*n}function Re(e,t,n){if(e===t)return .5;let o=(n-e)/(t-e);return o<0?0:o>1?1:o}var or=Object.freeze([]);function kn(e,t,n,o,s){let i={x:Re(e,t,s),y:0},a={x:1,y:Re(t,n,s)},f={x:Re(o,n,s),y:1},y={x:0,y:Re(e,o,s)},p=(b,E)=>({x1:b.x,y1:b.y,x2:E.x,y2:E.y});switch((e>s?8:0)|(t>s?4:0)|(n>s?2:0)|(o>s?1:0)){case 0:case 15:return or;case 1:case 14:return[p(y,f)];case 2:case 13:return[p(f,a)];case 3:case 12:return[p(y,a)];case 4:case 11:return[p(i,a)];case 6:case 9:return[p(i,f)];case 7:case 8:return[p(y,i)];case 5:return[p(y,i),p(f,a)];case 10:return[p(y,f),p(i,a)];default:return or}}function Sn(e,t,n,o,s,i,a,f=1){if(a<=0)return;let y=Math.max(0,Math.floor((s-a)/o)),p=Math.min(t-1,Math.ceil((s+a)/o)),v=Math.max(0,Math.floor((i-a)/o)),b=Math.min(n-1,Math.ceil((i+a)/o)),E=a*a;for(let z=v;z<=b;z++)for(let F=y;F<=p;F++){let R=F*o-s,B=z*o-i,N=R*R+B*B;if(N>=E)continue;let X=1-Math.sqrt(N)/a,u=z*t+F;e[u]=e[u]+f*X*X}}function sr(e,t,n){let o=-1,s=1/0;for(let i=0;i<n.length;i++){let a=n[i],f=a.x-e,y=a.y-t,p=f*f+y*y;p<s&&(s=p,o=i)}return o}function ir(e,t,n){let o=[];for(let s=0;s<n;s++)for(let i=0;i<t;i++){let a=e[s*t+i];i+1<t&&e[s*t+i+1]!==a&&o.push({x1:i+.5,y1:s-.5,x2:i+.5,y2:s+.5}),s+1<n&&e[(s+1)*t+i]!==a&&o.push({x1:i-.5,y1:s+.5,x2:i+.5,y2:s+.5})}return o}var te=class{constructor(t,n,o="diffuse",s=32){U(this,"mode");U(this,"cell");U(this,"W");U(this,"H");U(this,"cols");U(this,"rows");U(this,"cur");U(this,"nxt");U(this,"prev");this.W=t,this.H=n,this.mode=o,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 o=t/this.cell,s=n/this.cell,i=Math.floor(o),a=Math.floor(s),f=o-i,y=s-a,p=this.at(i,a)*(1-f)+this.at(i+1,a)*f,v=this.at(i,a+1)*(1-f)+this.at(i+1,a+1)*f;return p*(1-y)+v*y}deposit(t,n,o){let s=this.clampCol(Math.round(t/this.cell)),i=this.clampRow(Math.round(n/this.cell));this.cur[i*this.cols+s]+=o}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 o=this.cell;return{x:(this.sample(t+o,n)-this.sample(t-o,n))/(2*o),y:(this.sample(t,n+o)-this.sample(t,n-o))/(2*o)}}step(){this.mode==="wave"?this.stepWave():this.mode==="memory"?this.stepDiffuse(.03,.004):this.stepDiffuse()}stepDiffuse(t=.18,n=.01){let o=t<0?0:t>.24?.24:t,s=1-n,{cols:i,rows:a,cur:f,nxt:y}=this;for(let p=0;p<a;p++)for(let v=0;v<i;v++){let b=p*i+v,E=this.at(v-1,p)+this.at(v+1,p)+this.at(v,p-1)+this.at(v,p+1)-4*f[b];y[b]=(f[b]+o*E)*s}this.cur=y,this.nxt=f}stepWave(t=.25,n=.002){let o=t<0?0:t>.5?.5:t,s=1-n,{cols:i,rows:a,cur:f,prev:y,nxt:p}=this;for(let v=0;v<a;v++)for(let b=0;b<i;b++){let E=v*i+b,z=this.at(b-1,v)+this.at(b+1,v)+this.at(b,v-1)+this.at(b,v+1)-4*f[E];p[E]=(2*f[E]-y[E]+o*z)*s}this.prev=f,this.cur=p,this.nxt=y}decay(t){let n=t<=0?1:t>=1?0:1-t;if(n!==1)for(let o=0;o<this.cur.length;o++)this.cur[o]*=n}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 o=this.cols*this.rows;this.cur=new Float32Array(o),this.nxt=new Float32Array(o),this.prev=new Float32Array(o)}};var ar=24,Ns=.12,Ls=.22,le=class{constructor(t,n){U(this,"grid");U(this,"peak",.001);U(this,"cell",ar);this.grid=new te(Math.max(1,t),Math.max(1,n),"diffuse",ar)}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(Ls,Ns);let n=this.grid.max(),o=n>this.peak?.25:.03;this.peak+=(Math.max(n,.001)-this.peak)*o}norm(t,n){return wt(this.grid.sample(t,n)/this.peak,0,1)}gradient(t,n){if(this.peak<=0)return{x:0,y:0};let o=this.grid.gradient(t,n);return{x:o.x/this.peak,y:o.y/this.peak}}};var Ds={position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"0",pointerEvents:"none",display:"block"},cr=Object.entries(Ds).map(([e,t])=>`${e.replace(/[A-Z]/g,n=>"-"+n.toLowerCase())}:${t}`).join(";");function _s(e){let t=e.width,n=e.height,o=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:a=>(o=a,1),cancelRaf:()=>{o=null},createCanvas:()=>{throw new Error("headlessHost does not render \u2014 use render:'none' and the signal read-outs (onFeedback / sampleScalar / readParticles).")},onResize:()=>()=>{},onScroll:()=>()=>{},onVisibility:()=>()=>{},onInput:()=>()=>{},onBodyEvent:()=>()=>{},tick(a){s=a??s+1e3/60;let f=o;o=null,f?.(s)},resize(a,f){t=a,n=f}}}var lr="10px ui-monospace, SFMono-Regular, Menlo, monospace";function zn(e,t){let n=0,o=0;return{size(s,i,a){n=s,o=i,e.width=Math.floor(s*a),e.height=Math.floor(i*a),t.setTransform(a,0,0,a,0,0)},clear(){t.clearRect(0,0,n,o)},segments(s,i){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath();for(let a=0;a+3<s.length;a+=4)t.moveTo(s[a],s[a+1]),t.lineTo(s[a+2],s[a+3]);t.stroke()},polyline(s,i){if(!(s.length<4)){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath(),t.moveTo(s[0],s[1]);for(let a=2;a+1<s.length;a+=2)t.lineTo(s[a],s[a+1]);t.stroke()}},rect(s,i,a,f,y,p,v,b){t.fillStyle=`rgba(${y},${p},${v},${b})`,t.fillRect(s,i,a,f)},text(s,i,a,f,y,p,v){t.font=lr,t.textBaseline="middle",t.fillStyle=`rgba(${f},${y},${p},${v})`,t.fillText(s,i,a)},measureText(s){return t.font=lr,t.measureText(s).width}}}var Tn=(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),e.style.setProperty("--mass",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 o=e.dataset.fxLit==="1";n>.5&&!o?(e.dataset.fxLit="1",e.dispatchEvent(new CustomEvent("field:lit",{detail:{value:n}}))):n<.4&&o&&(e.dataset.fxLit="0",e.dispatchEvent(new CustomEvent("field:dim",{detail:{value:n}})))}},dr=Tn;var $e=class{constructor(t){U(this,"lit",!1);U(this,"lastEdgeMs",-1/0);U(this,"cfg");this.cfg=t}update(t,n){let o=n-this.lastEdgeMs>=this.cfg.debounceMs;return!this.lit&&t>=this.cfg.enter&&o?(this.lit=!0,this.lastEdgeMs=n,"entered"):this.lit&&t<=this.cfg.exit&&o?(this.lit=!1,this.lastEdgeMs=n,"exited"):null}get isLit(){return this.lit}reset(){this.lit=!1,this.lastEdgeMs=-1/0}};var Bs={strengthen:1.5,decay:.3,remember:.2},Fn=e=>e<0?0:e>1?1:e;function fr(e,t,n,o,s=Bs){e.active=t,e.tension=Fn(n),e.strength=Fn(e.strength+(t?s.strengthen:-s.decay)*o),e.memory=Fn(e.memory+(t?s.remember:-s.remember*.5)*o)}function hr(e,t,n=Math.random){let o=[],s=t.absorbR+6;for(let i of e){if(i.cap!==t)continue;let a=n()*Math.PI*2,f=4+n()*3;i.cap=null,i.x=t.cx+Math.cos(a)*s,i.y=t.cy+Math.sin(a)*s,i.vx=Math.cos(a)*f,i.vy=Math.sin(a)*f,i.z&&(i.z=0),i.vz&&(i.vz=0),i.heat=1,i.age=void 0,o.push(i)}return t.accreted=0,o}function An(e){if(e.capacity<=0)return 0;let t=e.accreted/e.capacity;return t<0?0:t>1?1:t}function ur(e,t){return t&&!e?{fire:"captured",armed:!0}:!t&&e?{fire:"released",armed:!1}:{fire:null,armed:e}}function yr(e,t){let n=[];for(let o of e)o.when!=="active"||!o.tokens.includes("sink")||(o.wasOn&&!o.on&&o.accreted>0&&(t(o),n.push(o)),o.wasOn=o.on);return n}function Cn(e,t){let n=t.cx-e.x,o=t.cy-e.y;return n*n+o*o<t.absorbR*t.absorbR}function pr(e,t,n=.14){let o=e+(t-e)*n;return o<.001?0:o>.999?1:o}function mr(e,t,n,o){let s=e.x+t.x,i=e.y+t.y,a=t.x+(n.x-s)*o,f=t.y+(n.y-i)*o,y=1-o;return{tx:a,ty:f,scale:y,opacity:y}}var Ws={token:"attract",label:"Attract",apply(e,t,n){let o=e.range*(e.on?1.5:1),s=e.strength*(e.on?3:1);if(n.dist>=o)return;let i=(1-n.dist/o)**2*s*.5,a=n.dx/n.dist,f=n.dy/n.dist;t.vx+=a*i,t.vy+=f*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i),n.form.orbit&&(t.vx+=-f*i*n.form.orbit,t.vy+=a*i*n.form.orbit),e.on&&(t.heat=Math.max(t.heat,(1-n.dist/o)*.9))},meta:{desc:"a soft gravity-like well, bent into a spiral"}},Hs={token:"repel",label:"Repel",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**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"}},qs={token:"swirl",label:"Swirl",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**1.4*s*.45,a=e.spin,f=n.dx/n.dist,y=n.dy/n.dist;t.vx+=y*i*a+f*i*.12,t.vy+=-f*i*a+y*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/o)*.6))},meta:{desc:"tangential swirl with light inward retention"}},Ys={token:"stream",label:"Stream",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**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/o)*.5))},meta:{desc:"directional current along a heading"}},Us={token:"viscosity",label:"Viscosity",apply(e,t,n){let o=e.range*(e.on?1.4:1);if(n.dist>=o)return;let s=(1-n.dist/o)*(.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"}},Gs={token:"jet",label:"Jet",kinematic:!0,apply(e,t,n){let o=e.range*(e.on?1.4:1);if(!(n.dist>=o))if(n.dist<24){let s=((n.rng??Math.random)()-.5)*.8,i=Math.cos(s),a=Math.sin(s),f=e.ux*i-e.uy*a,y=e.ux*a+e.uy*i,p=2.4+e.strength*2.6;t.vx=f*p,t.vy=y*p,t.x=e.cx+f*26,t.y=e.cy+y*26,t.z&&(t.z=0),t.vz&&(t.vz=0),t.heat=Math.max(t.heat,.9)}else{let s=(1-n.dist/o)**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"}},Vs={token:"tether",label:"Tether",apply(e,t,n){let o=e.range*.6*(e.on?1.25:1),s=o*2.1;if(n.dist>=s)return;let i=(.006+e.strength*.012)*(e.on?1.7:1),a=n.dist-o,f=n.dx/n.dist,y=n.dy/n.dist;t.vx+=f*a*i,t.vy+=y*a*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*a*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(a)/o))*.5))},meta:{desc:"a tether with a rest length \u2014 holds matter at a fixed radius"}},js={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 a=Math.hypot(t.vx,t.vy),f=e.hw+6-s,y=e.hh+6-i;f<y?(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),a>.7&&(n.spark(t.x,t.y,Math.min(2.4,a),e.tint??so.wall.color),t.heat=Math.max(t.heat,Math.min(.85,a*.4)))},meta:{desc:"axis-aligned bouncing wall \u2014 sparks on impact"}},Xs={token:"sink",label:"Sink",apply(e,t,n){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"}},Js=[Ws,Gs,Vs,js,Ys,Hs,Us,qs,Xs];function gr(e){for(let t of Js)e.force(t)}var On=1.5,Ks=8,Qs=60;function Zs(e,t,n,o){let s=ze(e);if(Math.hypot(s[0].x-s[1].x,s[0].y-s[1].y)<Math.max(e.range*.06,Ks)){let y=Math.max(e.range*.18,Qs),p=e.spin<0?-1:1;s=[{x:e.cx+e.ux*y,y:e.cy+e.uy*y,q:p},{x:e.cx-e.ux*y,y:e.cy-e.uy*y,q:-p}]}let a=o*(1+On*(e.d??0)),f=ho(s,t,n);return{x:f.x*a,y:f.y*a}}function ti(e,t,n,o){let s=t-e.cx,i=n-e.cy,a=Math.max(Math.hypot(s,i),Se),y=(e.spin<0?-1:1)*o*(1+On*(e.d??0))/(a*a);return{x:s/a*y,y:i/a*y}}function xr(e,t,n,o){if(n.dist>=e.range)return;let s=2*n.G*e.M/(n.c*n.c),i=o/(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),Rn(t,n.c)}function Rn(e,t){let n=e.vz??0,o=Math.hypot(e.vx,e.vy,n);o>t&&(e.vx=e.vx/o*t,e.vy=e.vy/o*t,n&&(e.vz=n/o*t))}function ei(e,t,n){let o=e.cx-t,s=e.cy-n,i=Math.max(Math.hypot(o,s),Se),a=e.M*(1+On*(e.d??0))/(i*i);return{x:o/i*a,y:s/i*a}}var ni={token:"gravity",label:"Gravity",apply(e,t,n){xr(e,t,n,n.G*e.M)},field:(e,t,n)=>ei(e,t,n),meta:{desc:"true softened inverse-square gravity (a real 1/d\xB2 law)"}},oi={token:"charge",label:"Charge",apply(e,t,n){let o=t.charge??0;o!==0&&xr(e,t,n,-(e.spin*o*n.G*e.M))},field:(e,t,n)=>ti(e,t,n,e.M),meta:{desc:"signed inverse-square \u2014 like repels, opposite attracts"}},ri={token:"magnetism",label:"Magnetism",apply(e,t,n){if(n.dist>=e.range)return;let o=t.charge??0;if(o===0)return;let s=1-n.dist/e.range,i=o*e.spin*e.strength*s,a=Math.cos(i),f=Math.sin(i),y=t.vx;t.vx=y*a-t.vy*f,t.vy=y*f+t.vy*a},field:(e,t,n)=>Zs(e,t,n,e.strength),meta:{desc:"Lorentz force \u2014 curves a moving charge perpendicular to its velocity"}};function si(e){return Math.sqrt(2*Math.max(0,e))}var ii={token:"thermal",label:"Thermal",apply(e,t,n){if(n.dist>=e.range)return;let o=1-n.dist/e.range,s=si(e.strength*o);if(s===0)return;let i=Math.random()||1e-9,a=s*Math.sqrt(-2*Math.log(i)),f=2*Math.PI*Math.random();if(t.vx+=a*Math.cos(f),t.vy+=a*Math.sin(f),n.D){let y=Math.random()||1e-9;t.vz=(t.vz??0)+s*Math.sqrt(-2*Math.log(y))*Math.cos(2*Math.PI*Math.random())}e.on&&(t.heat=Math.max(t.heat,o*.4)),Rn(t,n.c)},meta:{desc:"Langevin/Brownian agitation \u2014 a real temperature in the medium"}},ai={token:"collide",label:"Collide",apply(e,t,n){if(n.dist>=e.range)return;let o=Math.max(0,Math.min(1,e.strength)),s=Math.max(1,t.size);for(let i of n.neighbors(t,s*4)){let a=Math.max(1,i.size),f=t.x-i.x,y=t.y-i.y,p=(t.z??0)-(i.z??0),v=Math.hypot(f,y,p);if(v>=s+a||v<1e-6)continue;let b=f/v,E=y/v,z=p/v,F=(t.vx-i.vx)*b+(t.vy-i.vy)*E+((t.vz??0)-(i.vz??0))*z;if(F>=0)continue;let R=(1+o)*.5*F;t.vx-=R*b,t.vy-=R*E,i.vx+=R*b,i.vy+=R*E,p&&(t.vz=(t.vz??0)-R*z,i.vz=(i.vz??0)+R*z)}},meta:{desc:"elastic pairwise collision \u2014 the hard-sphere billiard force"}},ci={token:"diffuse",label:"Diffuse",apply(e,t,n){if(n.dist>=e.range)return;let o=n.grid("diffuse");o.deposit(t.x,t.y,e.strength);let s=o.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"}},li=12,Pn=7,di={token:"propagate",label:"Propagate",source(e,t){e.on&&t.frameN%li===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 a=-n.dx/n.dist,f=-n.dy/n.dist;t.vx+=a*i*e.strength*Pn,t.vy+=f*i*e.strength*Pn,n.dz&&(t.vz=(t.vz??0)+-n.dz/n.dist*i*e.strength*Pn),Rn(t,n.c)},meta:{desc:"a travelling wave \u2014 a shock train expands from the source, sweeping matter out"}},fi={token:"memory",label:"Memory",apply(e,t,n){if(n.dist>=e.range)return;let o=n.grid("memory");o.deposit(t.x,t.y,e.strength*.15);let s=1+.5*o.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"}},hi=[ni,oi,ri,ii,ai,ci,di,fi];function vr(e){for(let t of hi)e.force(t)}var ui={token:"lens",label:"Lens",kinematic:!0,apply(e,t,n){if(n.dist>=e.range)return;let o=e.strength*(1-n.dist/e.range)*e.spin,s=Math.cos(o),i=Math.sin(o),a=t.vx,f=t.vy;t.vx=a*s-f*i,t.vy=a*i+f*s},meta:{desc:"rotates velocity, preserving speed \u2014 bends paths without adding energy"}},yi={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"}},pi=1,mi=1,gi={token:"buoyancy",label:"Buoyancy",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=pi/(t.size*(1+t.heat));t.vy-=(mi-o)*e.strength},meta:{desc:"a constant lift/sink by density difference \u2014 light matter rises, dense settles"}},xi={token:"shear",label:"Shear",apply(e,t,n){if(n.dist>=e.range)return;let o=(t.x-e.cx)*-e.uy+(t.y-e.cy)*e.ux,s=e.strength*(o/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"}},Ie=32,vi=.5,wi={token:"crystallize",label:"Crystallize",apply(e,t,n){if(n.dist>=e.range||t.heat>=vi)return;let o=e.cx+Math.round((t.x-e.cx)/Ie)*Ie,s=e.cy+Math.round((t.y-e.cy)/Ie)*Ie;t.vx+=(o-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"}},bi={token:"align",label:"Align",apply(e,t,n){if(n.dist>=e.range)return;let o=t.vz??0,s=Math.hypot(t.vx,t.vy,o),i=e.strength,a=e.ux,f=e.uy,y=0,p=0,v=0,b=0;for(let z of n.neighbors(t,e.range)){let F=z.vz??0,R=Math.hypot(z.vx,z.vy,F);R>1e-6&&(p+=z.vx/R,v+=z.vy/R,b+=F/R)}let E=Math.hypot(p,v,b);E>1e-6&&(a=p/E,f=v/E,y=b/E),t.vx+=(a*s-t.vx)*i,t.vy+=(f*s-t.vy)*i,(y||o)&&(t.vz=o+(y*s-o)*i)},meta:{desc:"steers toward the neighbour-mean heading (or the body heading when alone)"}};function Mi(e,t,n,o){let s=e*o+n*.2,i=t*o-n*.2;return{x:-o*Math.sin(s)*Math.sin(i),y:-o*Math.cos(s)*Math.cos(i)}}var Ei=.01,ki={token:"wind",label:"Wind",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=Mi(t.x,t.y,n.t,Ei);t.vx+=o.x*e.strength,t.vy+=o.y*e.strength},meta:{desc:"divergence-free curl-noise turbulence"}},Si=.5,zi={token:"cohesion",label:"Cohesion",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=o*Si,i=e.strength;for(let a of n.neighbors(t,o)){let f=a.x-t.x,y=a.y-t.y,p=(a.z??0)-(t.z??0),v=Math.hypot(f,y,p);if(v<1e-6)continue;let b=f/v,E=y/v,z=p/v;if(v<s){let F=i*(s-v)/s;t.vx-=F*b,t.vy-=F*E,p&&(t.vz=(t.vz??0)-F*z)}else{let F=i*(v-s)/(o-s);t.vx+=F*b,t.vy+=F*E,p&&(t.vz=(t.vz??0)+F*z)}}},meta:{desc:"short-range pressure + mid-range cohesion \u2014 surface tension over neighbours"}},Ti=.5,Fi={token:"pressure",label:"Pressure",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=e.strength,i=0,a=n.neighbors(t,o);for(let y of a){let p=Math.hypot(y.x-t.x,y.y-t.y,(y.z??0)-(t.z??0));p<o&&(i+=(1-p/o)**2)}let f=i-Ti;if(!(f<=0))for(let y of a){let p=t.x-y.x,v=t.y-y.y,b=(t.z??0)-(y.z??0),E=Math.hypot(p,v,b);if(E<1e-6||E>=o)continue;let z=s*f*(1-E/o)/E;t.vx+=z*p,t.vy+=z*v,b&&(t.vz=(t.vz??0)+z*b)}},meta:{desc:"SPH density relaxation \u2014 incompressible even-fill via mutual repulsion"}},Ai={token:"hunt",label:"Hunt",apply(e,t,n){if(n.dist>=e.range)return;let o=t.species??0,s=null,i=1/0;for(let b of n.neighbors(t,e.range)){if((b.species??0)===o)continue;let E=b.x-t.x,z=b.y-t.y,F=(b.z??0)-(t.z??0),R=E*E+z*z+F*F;R<i&&(i=R,s=b)}if(!s)return;let a=s.x-t.x,f=s.y-t.y,y=(s.z??0)-(t.z??0),p=Math.hypot(a,f,y)||1,v=o===0?1:-1;t.vx+=a/p*e.strength*v,t.vy+=f/p*e.strength*v,y&&(t.vz=(t.vz??0)+y/p*e.strength*v)},meta:{desc:"two-species pursuit \u2014 predators seek prey, prey flee predators"}},Ci=.35,Pi={token:"link",label:"Link",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=o*Ci,i=e.strength;for(let a of n.neighbors(t,o)){let f=a.x-t.x,y=a.y-t.y,p=(a.z??0)-(t.z??0),v=Math.hypot(f,y,p);if(v<1e-6)continue;let b=v-s,E=.5*i*(b/s);t.vx+=E*(f/v),t.vy+=E*(y/v),p&&(t.vz=(t.vz??0)+E*(p/v))}},meta:{desc:"a Verlet distance constraint \u2014 holds a rest length, so matter ropes and drapes"}},wr=40,Oi={token:"morph",label:"Morph",apply(e,t,n){let o=e.targets;if(!o||o.length===0)return;let s=Math.min(o.length-1,Math.floor((t.gx??0)*o.length)),i=o[s],a=i.x-t.x,f=i.y-t.y,y=Math.hypot(a,f),p=e.strength;t.vx+=a*p*.02,t.vy+=f*p*.02,t.z&&(t.vz=(t.vz??0)-t.z*p*.02);let b=(1-(y<wr?1-y/wr:0))*p*.3;b>0&&(t.vx+=((n.rng??Math.random)()-.5)*b,t.vy+=((n.rng??Math.random)()-.5)*b)},meta:{desc:"matter assembles into a mark/chart/logo \u2014 never words (\xA711)"}},Ri=90,$i={token:"spawn",label:"Spawn",apply(){},source(e,t){let n=e.life??Ri,o=Math.max(1,Math.round(e.strength*2));e.cap!=null&&e.cap>0&&n>0&&(o=Math.min(o,e.cap/n)),e.emitAcc=(e.emitAcc??0)+o;let s=Math.floor(e.emitAcc);for(e.emitAcc-=s;s>0;s--){let i=((t.rng??Math.random)()-.5)*.6,a=Math.cos(i),f=Math.sin(i),y=e.ux*a-e.uy*f,p=e.ux*f+e.uy*a,v=2+(t.rng??Math.random)()*2;t.spawn({x:e.cx,y:e.cy,vx:y*v,vy:p*v,age:n,heat:.6,...e.species!=null?{species:e.species}:{}})}},meta:{desc:"a source \u2014 emits matter along the heading, budgeted by a lifespan"}},Ii=3,Ni={token:"resonate",label:"Resonate",apply(){},modify(e,t,n){return{strength:1+Math.sin(n.t*Ii*e.spin)}},meta:{desc:"pulses sibling forces with a time-varying strength S(t)=S\u2080(1+sin \u03C9t)"}},Li=.5,Di={token:"spotlight",label:"Spotlight",apply(){},modify(e,t,n){let o=-n.dx/n.dist,s=-n.dy/n.dist;return{gate:o*e.ux+s*e.uy<Li}},meta:{desc:"gates sibling forces to an angular cone of the heading"}},_i={token:"screen",label:"Screen",apply(){},meta:{desc:"a quiet zone \u2014 attenuates other bodies' forces on matter inside its radius"}},Bi={token:"pigment",label:"Pigment",apply(e,t,n){let o=e.tint;!o||n.dist>=e.range*.6||(t.color=t.color?lo(t.color,o,.08):o)},meta:{desc:"conserved color transport \u2014 matter takes on and carries a tint"}},Wi=.5,br=.12,Hi={token:"fieldflow",label:"Field Flow",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=n.fieldAt?.(t.x,t.y);if(!o)return;let s=Math.hypot(o.x,o.y);if(!(s>1e-9))return;let i=o.x/s,a=o.y/s,f=e.range>0?1-n.dist/e.range:1,y=e.strength*f,p=t.vz??0,v=Math.hypot(t.vx,t.vy,p);if(v>1e-6){let z=Math.min(1,y*Wi);t.vx+=(i*v-t.vx)*z,t.vy+=(a*v-t.vy)*z,p&&(t.vz=p+(0-p)*z)}t.vx+=i*y*br,t.vy+=a*y*br;let b=t.vz??0,E=t.vx*t.vx+t.vy*t.vy+b*b;if(E>n.c*n.c){let z=n.c/Math.sqrt(E);t.vx*=z,t.vy*=z,b&&(t.vz=b*z)}e.on&&(t.heat=Math.max(t.heat,f*.4))},meta:{desc:"follow the field lines \u2014 steer onto and stream down the net field a body radiates"}},qi={token:"warp",label:"Warp",kinematic:!0,apply(e,t,n){if(!e.warpHas||t.cap)return;let o=e.absorbR;if(n.dist>=o)return;let s=Math.cos(e.twist??0),i=Math.sin(e.twist??0),a=e.warpScale??1,f=-n.dx/n.dist,y=-n.dy/n.dist,p=f*s-y*i,v=f*i+y*s,b=o*a+6;t.x=e.warpX+p*b,t.y=e.warpY+v*b,t.z&&(t.z=-n.dz/n.dist*b);let E=t.vx,z=t.vy;t.vx=E*s-z*i,t.vy=E*i+z*s,t.heat=Math.max(t.heat,.6)},meta:{desc:"a wormhole throat \u2014 relocates matter to its paired body, conserved"}},Yi=[ui,yi,gi,xi,wi,bi,ki,zi,Fi,Pi,Ai,Oi,$i,Ni,Di,_i,Bi,Hi,qi];function Mr(e){for(let t of Yi)e.force(t)}function Ui(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 Gi(e){let t=0;for(let n of e)t+=n.heat;return t}function Er(e){let t=Ui(e),n=Gi(e);return{kinetic:t,thermal:n,total:t+n,count:e.length}}var Ne={x:0,y:0},Le=[0,0,0];function De(e,t={}){let n=null;if((t.render??"none")!=="none"&&(n=e.getContext("2d"),!n))throw new Error("Fundamental: 2D canvas context unavailable");let o=t.overlayCanvas??null,s=n?o?.getContext("2d")??null:null,i=t.overlayBackend??(o&&s?zn(o,s):null),a=new Ae,f=1,y=new Map,p=Bo(),v=new Map,b=r=>(v.get(r)?.size??0)>0;function E(r,c){let l=v.get(r);if(l)for(let g of l)g(c)}let z=new Ce;function F(r,c){b(r)&&z.record(r,c)}function R(){z.flush(E)}let B=new WeakMap,N=new Map,X=new Map;function u(r){let c=b("enter")||b("exit"),l=b("met");if(!c&&!l)return;for(let d=0;d<r.length;d++){let x=r[d];if(c){let m=N.get(x);m||N.set(x,m=new Set);let h=x.range*x.range;for(let w=0;w<r.length;w++){if(d===w)continue;let M=r[w],S=M.cx-x.cx,T=M.cy-x.cy,k=S*S+T*T<h;k&&!m.has(M)?(m.add(M),b("enter")&&F("enter",{body:x,other:M})):!k&&m.has(M)&&(m.delete(M),b("exit")&&F("exit",{body:x,other:M}))}}if(l){let m=X.get(x);m||X.set(x,m=new Set);for(let h=d+1;h<r.length;h++){let w=r[h],M=Math.abs(w.cx-x.cx)<x.hw+w.hw&&Math.abs(w.cy-x.cy)<x.hh+w.hh;M&&!m.has(w)?(m.add(w),F("met",{a:x,b:w})):!M&&m.has(w)&&m.delete(w)}}}let g=new Set(r);for(let d of[N,X])for(let x of d.keys())g.has(x)||d.delete(x)}let Z=[],it=new WeakMap,lt=[],D=0,A=new WeakMap,j=new WeakMap,J=new Map,dt=new Map;if(gr(p),vr(p),Mr(p),!t.host)throw new Error("Fundamental: createField requires opts.host. Use @fundamental-engine/vanilla (createField/mountField) or @fundamental-engine/elements / @fundamental-engine/react, or pass browserHost() from @fundamental-engine/dom.");let _=t.host,tt=[],yt=_.reducedMotion(),Rt=yn[t.theme??pn]??yn[pn],O={accent:t.accent??ke(t.palette)[0]??fn[0]??"#4da3ff",density:t.density&&t.density>0?t.density:1,render:t.render??"none",waves:t.waves??!0,waveStyle:t.waveStyle??"linear",waveCenter:t.waveCenter??null,background:t.background??"opaque",mass:t.mass??!1,separation:t.separation!=null&&t.separation>=0?t.separation:0,attention:t.attention??!1,causality:t.causality??!1,heatmap:t.heatmap??!1,overlay:t.overlay??"off",gridWarp:t.gridWarp!=null&&t.gridWarp>=0?t.gridWarp:1,gridIntensity:t.gridIntensity!=null&&t.gridIntensity>=0?Math.min(t.gridIntensity,1):.16,gradientCool:t.gradientCool?gt(t.gradientCool):Rt.cool,gradientWarm:t.gradientWarm?gt(t.gradientWarm):Rt.warm,waveBaseline:(t.waveBaseline??Rt.wave).map(gt),dprCap:t.dprCap&&t.dprCap>0?t.dprCap:2,depth:t.depth&&t.depth>0?t.depth:0,feedbackSink:t.feedbackSink??Tn},K=null,L=[],I=0,$=0,Y=0,Q=0,at=!1,Ut=1,ee=0,fe=new WeakMap,qt=0,$t=0,Ln=!0,Dn={...Ee.ambient.preset},vt=[],Dt=[],_n=0,Yt=null,ht=t.rng??Math.random,qe=t.now??(()=>performance.now()),ft=yt?1:0,Ye=NaN,It=null,ne=null,_t=0,Nt=0,he=null,Ue=[],Ge=null,ue=null,Pr=Math.round(130*O.density)*4,xt={x:0,y:0,k:0},ut=null,Lt=null,Bn=0,Wn=0,Hn=ke(t.palette).map(gt),rt=gt(O.accent),ye=null,Ve=[],Bt=[],Gt=[],Vt=[],je=[],Xe=[],jt=[],pe=new Oe,Je=!1,Ke=()=>{Je||(Je=!0,queueMicrotask(()=>{Je=!1,ge()}))},Or=r=>{for(let c of["--d","--field-density","--load","--mass","--entropy","--coherence","--temperature"])r.style.removeProperty(c)},Rr=r=>{let c=r.detail;c?.element&&(pe.register(c),Ke())},$r=r=>{let c=r.detail;c?.element&&(pe.unregister(c.element),Or(c.writeTarget??c.element),Ke())},Ir=Ke,Tt={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null},qn=qe(),q={dx:0,dy:0,dz:0,dist:1,form:{...Ee.ambient.preset},W:0,H:0,D:O.depth,t:0,frameN:0,dt:yt?0:1,c:12,G:1,scrollV:0,rng:ht,spark:(r,c,l,g)=>Yn(r,c,l,g),supernova:r=>{let c=hr(a.particles,r,ht),l=new Set(c);for(let g of a.particles){if(l.has(g))continue;let d=g.x-r.cx,x=g.y-r.cy,m=Math.hypot(d,x)||1;if(m<320){let h=(1-m/320)*4;g.vx+=d/m*h,g.vy+=x/m*h,g.heat=Math.max(g.heat,.8)}}xn(Dt,vt,r.cx,r.cy,320,I,$,q.t,g=>void a.add(Xt(g))),Ur(r),Qe(r.el,"field:saturated",{peak:c.length}),r.el.dataset.fxCap==="1"&&(r.el.dataset.fxCap="0",Jt(r.el,"released",{accreted:0,load:0}),b("release")&&F("release",{body:r,count:c.length}),B.delete(r))},spawn:r=>{a.size>=Pr||a.add(Xt(r))},neighbors:(r,c)=>a.neighbors(r,c),grid:r=>{let c=y.get(r);if(!c){let l=r.startsWith("wave")?"wave":r.startsWith("memory")?"memory":"diffuse";c=new te(I,$,l),y.set(r,c)}return c}};function Yn(r,c,l,g){if(yt||Vt.length>260)return;let d=g?gt(g):[255,122,69],x=Eo(l);for(let m=0;m<x;m++){let h=ht()*6.28318,w=.8+ht()*(l>0?l:1)*1.7;Vt.push({x:r,y:c,vx:Math.cos(h)*w,vy:Math.sin(h)*w,life:1,c:d})}}function Xt(r={}){let c=r.size??.7+ht()*1.8;return{id:r.id??f++,x:r.x??ht()*I,y:r.y??ht()*$,vx:r.vx??(ht()-.5)*.25,vy:r.vy??(ht()-.5)*.18,z:r.z??(O.depth>0?ht()*O.depth:0),vz:r.vz??(O.depth>0?(ht()-.5)*.18:0),m:r.m??(O.mass?c:1),heat:r.heat??0,size:c,gx:r.gx??ht(),gy:r.gy??ht(),gz:r.gz??ht(),cap:null,...r.age!=null?{age:r.age}:{},...r.color!=null?{color:r.color}:{},...r.species!=null?{species:r.species}:{}}}let me=[];function Nr(){if(!me.length)return;let r=a.particles;for(let c=0;c<r.length;c++){let l=me[c%me.length];r[c].atom=l;let g=typeof l.weight=="number"?Math.max(0,Math.min(1,l.weight)):.5;r[c].size*=.6+g*.9,r[c].m*=.6+g*1.2}}function Un(){a.clear();let r=Math.round(130*O.density);for(let c=0;c<r;c++)a.add(Xt());Nr(),vt=O.waves?Co(O.waveBaseline):[],Dt=O.waves?Po(vt.length,O.density,ht):[],_n=Dt.length}function ge(){let r=Zo(_.root);if(pe.size>0){let g=new Set(r.map(d=>d.el));L=r.concat(pe.bodies(ce).filter(d=>!g.has(d.el)))}else L=r;Z.length>0&&(L=L.concat(Z)),Pe(L,I,$,Y,Q),Vr();let c=new Map(Bt.map(g=>[g.el,g]));Bt=[..._.root.querySelectorAll("[data-move]")].map(g=>{let d=g,x=d.getBoundingClientRect(),m=Number.parseFloat(d.dataset.mass??""),h=Number.isFinite(m)?m:To(x.width*x.height),w=(d.dataset.move??"").trim()==="layout",M=d.hasAttribute("data-dock"),S=d.hasAttribute("data-warp"),T=c.get(d);return T?{el:d,o:T.o,mEl:h,layout:w,dockable:M,dock:T.dock,docked:T.docked,warpable:S,warpCool:T.warpCool}:{el:d,o:{x:0,y:0,vx:0,vy:0},mEl:h,layout:w,dockable:M,dock:{dock:0},docked:null,warpable:S,warpCool:0}}),je=[..._.root.querySelectorAll("[data-on]")].map(g=>{let d=g;return{el:d,body:L.find(x=>x.el===d)??null,bindings:vn(d.dataset.on??"")}}),Xe=[..._.root.querySelectorAll("[data-class]")].map(g=>{let d=g;return{el:d,body:L.find(x=>x.el===d)??null,bindings:vn(d.dataset.class??"")}});for(let g of L){if(!g.pair)continue;let d=null;try{d=_.root.querySelector(g.pair)}catch{d=null}g.pairBody=d?L.find(x=>x.el===d):void 0}let l=new Map(Gt.map(g=>[g.el,g]));for(let[g,d]of l)if(!_.root.contains(g))for(let x of d.emitted)x.remove();Gt=[..._.root.querySelectorAll("[data-emit]")].map(g=>{let d=g,x=d.dataset.emit??"",m=null;try{m=x?_.root.querySelector(x):null}catch{m=null}let h=Math.max(0,Math.round(Number.parseFloat(d.dataset.max??"")||8)),w=l.get(d);if(w){let M=w.emitted.filter(S=>S.isConnected);for(;M.length>h;)M.pop().remove();return{el:d,tmpl:m,cap:h,emitted:M}}return{el:d,tmpl:m,cap:h,emitted:[]}})}function Lr(){for(let r of L)if(r.pairBody){if(!r.pairBody.el.isConnected){r.warpHas=!1,r.pairBody=void 0;continue}r.pairBody.vis?(r.warpX=r.pairBody.cx,r.warpY=r.pairBody.cy,r.warpHas=!0):r.warpHas=!1}else r.pair&&(r.warpHas=!1)}function Dr(){if(!(Gt.length===0||q.frameN%30!==0))for(let r of Gt){if(!r.tmpl||r.emitted.length>=r.cap)continue;let c=r.tmpl.cloneNode(!0);c.removeAttribute("id"),c.setAttribute("aria-hidden","true"),c.setAttribute("inert",""),c.dataset.fieldEmitted="",r.el.appendChild(c),r.emitted.push(c)}}function _r(){if(je.length!==0)for(let r of je){let c=r.body?{d:r.body.d,on:r.body.on,accreted:r.body.accreted}:{d:0,on:r.el.dataset.active==="1",accreted:0};for(let l of r.bindings){let g=wn(l.trigger,c);g&&!l.armed?(l.armed=!0,r.el.dispatchEvent(new CustomEvent(l.event,{bubbles:!0,detail:{trigger:l.trigger,d:c.d,on:c.on,accreted:c.accreted}}))):g||(l.armed=!1)}}}function Br(){if(Xe.length!==0)for(let r of Xe){let c=r.body?{d:r.body.d,on:r.body.on,accreted:r.body.accreted}:{d:0,on:r.el.dataset.active==="1",accreted:0};for(let l of r.bindings){let g=wn(l.trigger,c);g&&!l.armed?(l.armed=!0,r.el.classList.add(l.event)):!g&&l.armed&&(l.armed=!1,r.el.classList.remove(l.event))}}}function Jt(r,c,l){r.dispatchEvent(new CustomEvent("field:"+c,{bubbles:!0,composed:!0,detail:l})),r.dispatchEvent(new CustomEvent("forces:"+c,{bubbles:!0,composed:!0,detail:l}))}function Wr(){for(let r of L){if(!r.vis||r.tokens.indexOf("sink")<0)continue;let c=r.el.dataset.fxCap==="1",l=ur(c,r.accreted>0);l.fire==="captured"?(r.el.dataset.fxCap="1",Jt(r.el,"captured",{accreted:r.accreted,load:An(r)}),b("absorb")&&F("absorb",{body:r,count:r.accreted}),B.set(r,r.accreted)):l.fire==="released"&&(r.el.dataset.fxCap="0",Jt(r.el,"released",{accreted:0,load:0}),b("release")&&F("release",{body:r,count:B.get(r)??0}),B.delete(r))}}let Hr=[{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"}],qr=120;function Qe(r,c,l){r.dispatchEvent(new CustomEvent(c,{bubbles:!0,composed:!0,detail:l}))}function Gn(r,c,l,g,d,x){let m=r.get(c);m||r.set(c,m=new Map);let h=m.get(g.metric);h||m.set(g.metric,h=new $e({enter:g.enter,exit:g.exit,debounceMs:qr}));let w=h.update(d,x);w==="entered"?Qe(l,g.rise,{metric:g.metric,value:d}):w==="exited"&&Qe(l,g.fall,{metric:g.metric,value:d})}function Yr(r){for(let c of L)if(!(!c.vis||c.tokens.length===0))for(let l of Hr){let g;switch(l.metric){case"density":g=c.d;break;case"attention":O.attention&&(g=c.attn??1);break;case"entropy":g=c.metrics?.entropy;break}g!==void 0&&Gn(A,c,c.el,l,g,r)}for(let c of lt)Gn(j,c.agent,c.from.el,{metric:"memory",enter:.6,exit:.3,rise:"field:memory-threshold",fall:"field:memory-faded"},c.agent.memory,r)}function Ur(r){for(let c of Bt)c.docked===r&&(c.docked=null,c.dock.dock=0,c.el.getAttribute("aria-hidden")==="true"&&c.el.removeAttribute("aria-hidden"),c.el.removeAttribute("inert"),c.el.style.opacity="",Jt(c.el,"released",{}))}function Gr(){if(Bt.length===0)return;let r=Bt.map(c=>{let l=c.el.getBoundingClientRect();return{x:l.left-Y+l.width/2,y:l.top-Q+l.height/2}});for(let c=0;c<Bt.length;c++){let l=Bt[c];if(!l.el.isConnected){l.docked&&(l.docked=null,l.dock.dock=0);continue}let g=r[c].x,d=r[c].y;if(l.docked){let M={x:g-l.o.x,y:d-l.o.y};l.dock.dock=pr(l.dock.dock,1);let S=mr(M,l.o,{x:l.docked.cx,y:l.docked.cy},l.dock.dock);l.el.style.transform=`translate(${S.tx.toFixed(2)}px, ${S.ty.toFixed(2)}px) scale(${S.scale.toFixed(3)})`,l.el.style.opacity=S.opacity.toFixed(3),l.dock.dock>=1&&l.el.getAttribute("aria-hidden")!=="true"&&(l.el.setAttribute("aria-hidden","true"),l.el.setAttribute("inert",""));continue}Tt.x=g,Tt.y=d,Tt.vx=0,Tt.vy=0,Tt.heat=0,Tt.cap=null;for(let M of L){if(!M.vis||M.tokens.length===0||M.el===l.el)continue;let S=M.cx-g,T=M.cy-d,k=Math.hypot(S,T);q.dx=S,q.dy=T,q.dist=k<1?1:k;for(let C of M.tokens)p.forces[C]?.apply(M,Tt,q)}Tt.cap=null;let x=zo(l.o),m=Tt.vx+x.x,h=Tt.vy+x.y;if(l.layout){let M=Fo({x:g,y:d},r,c),S=Ao((T,k)=>a.near(T,k,40).length,g,d,16,6);m+=M.x+S.x,h+=M.y+S.y}let w={x:g-l.o.x,y:d-l.o.y};if(So(l.o,m,h,l.mEl,.9),l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.dockable){let M={x:w.x+l.o.x,y:w.y+l.o.y},S=L.find(T=>T.vis&&T.el!==l.el&&T.tokens.indexOf("sink")>=0&&Cn(M,T));S&&(l.docked=S,Jt(l.el,"captured",{sink:S.el}))}if(l.warpCool>0&&(l.warpCool-=1),l.warpable&&l.warpCool===0){let M={x:w.x+l.o.x,y:w.y+l.o.y},S=L.find(T=>T.vis&&T.el!==l.el&&T.warpHas&&T.tokens.indexOf("warp")>=0&&Cn(M,T));S&&(l.o.x=S.warpX-w.x,l.o.y=S.warpY-w.y,l.o.vx=0,l.o.vy=0,l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.warpCool=45,Jt(l.el,"relocated",{from:S.el}))}}}function Vr(){jt.length&&(jt=jt.filter(r=>r.el.isConnected?!0:(r.el.removeEventListener("pointerenter",r.enter),r.el.removeEventListener("pointerleave",r.leave),r.el.removeEventListener("focus",r.enter),r.el.removeEventListener("blur",r.leave),delete r.el.dataset.fxEngaged,!1))),_.root.querySelectorAll("[data-hot]").forEach(r=>{let c=r;if(c.dataset.fxEngaged==="1")return;c.dataset.fxEngaged="1";let l=()=>{c.dataset.active="1",ye=c.dataset.color??null;let d=c.closest("[data-index][data-threads]");if(d){let x=[...d.querySelectorAll("[data-hot]")].filter(m=>m!==c);Ze(x.map(m=>({a:c,b:m,color:c.dataset.color??void 0})))}},g=()=>{c.dataset.active="0",ye=null,Ze(null)};c.addEventListener("pointerenter",l),c.addEventListener("pointerleave",g),c.addEventListener("focus",l),c.addEventListener("blur",g),jt.push({el:c,enter:l,leave:g})})}function Ze(r){Ve=(r??[]).map(c=>({a:c.a,b:c.b,c:gt(c.color??O.accent),seed:ht()*6.28}))}function jr(){if(Ve.length===0)return;let r=q.t;n.globalCompositeOperation="lighter";for(let c of Ve){let l=c.a.getBoundingClientRect(),g=c.b.getBoundingClientRect(),d=l.left-Y+l.width/2,x=l.top-Q+l.height/2,m=g.left-Y+g.width/2,h=g.top-Q+g.height/2,[w,M,S]=c.c;n.strokeStyle=`rgba(${w},${M},${S},0.22)`,n.lineWidth=1,n.beginPath(),n.moveTo(d,x),n.lineTo(m,h),n.stroke();for(let T=0;T<3;T++){let k=(r*.6+c.seed+T/3)%1,C=d+(m-d)*k,H=x+(h-x)*k;n.fillStyle=`rgba(${w},${M},${S},${(1-k)*.9})`,n.beginPath(),n.arc(C,H,2.2,0,6.28318),n.fill()}}n.globalCompositeOperation="source-over"}let xe=0,Xr=[1/0,1.5,1.25,1];function ve(r){if(!n)return;let c=Math.min(r||1,O.dprCap,Xr[xe]??1/0);e.width=Math.floor(I*c),e.height=Math.floor($*c),e.style.width=I+"px",e.style.height=$+"px",n.setTransform(c,0,0,c,0,0),i?.size(I,$,c)}function Vn(){let r=_.viewport();I=r.width,$=r.height,Y=r.originX??0,Q=r.originY??0,at=r.originX!=null||r.originY!=null,ve(r.dpr),q.W=I,q.H=$,Ut=_.scrollHeight()-$||1;for(let c of y.values())c.resize(I,$);O.heatmap&&(K?K.resize(I,$):K=new le(I,$)),Un(),ge()}function Jr(){let r=q.t,c=16;if(O.waveStyle==="circular"){let l=Yt||{x:I/2,y:$/2},g=Math.min(I,$)*.48;for(let d of vt){let[x,m,h]=d.color;n.beginPath();let w=.08,M=!0;for(let k=0;k<=2*Math.PI+.01;k+=w){let C=ae(d,k,r,g),H=l.x+Math.cos(k)*C,G=l.y+Math.sin(k)*C;M?(n.moveTo(H,G),M=!1):n.lineTo(H,G)}n.closePath();let S=d.baseFrac*g+d.offsetY,T=n.createRadialGradient(l.x,l.y,Math.max(0,S-d.amp),l.x,l.y,S+d.amp+80);T.addColorStop(0,`rgba(${x},${m},${h},${(.08+d.depth*.04)*ft})`),T.addColorStop(1,`rgba(${x},${m},${h},0)`),n.fillStyle=T,n.fill()}n.globalCompositeOperation="lighter";for(let d of vt){let[x,m,h]=d.color;n.beginPath();let w=.08,M=!0;for(let S=0;S<=2*Math.PI+.01;S+=w){let T=ae(d,S,r,g),k=l.x+Math.cos(S)*T,C=l.y+Math.sin(S)*T;M?(n.moveTo(k,C),M=!1):n.lineTo(k,C)}n.closePath(),n.lineWidth=5,n.strokeStyle=`rgba(${x},${m},${h},${(.05+d.depth*.04)*ft})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${x},${m},${h},${(.3+d.depth*.22)*ft})`,n.stroke()}n.globalCompositeOperation="source-over"}else{for(let l of vt){let[g,d,x]=l.color;n.beginPath(),n.moveTo(0,Et(l,0,r,$,1,1,xt));for(let w=0;w<=I;w+=c)n.lineTo(w,Et(l,w,r,$,1,1,xt));n.lineTo(I,$),n.lineTo(0,$),n.closePath();let m=l.baseFrac*$+l.offsetY-l.amp,h=n.createLinearGradient(0,m,0,m+320);h.addColorStop(0,`rgba(${g},${d},${x},${(.11+l.depth*.05)*ft})`),h.addColorStop(1,`rgba(${g},${d},${x},0)`),n.fillStyle=h,n.fill()}n.globalCompositeOperation="lighter";for(let l of vt){let[g,d,x]=l.color;n.beginPath(),n.moveTo(0,Et(l,0,r,$,1,1,xt));for(let m=0;m<=I;m+=c)n.lineTo(m,Et(l,m,r,$,1,1,xt));n.lineWidth=5,n.strokeStyle=`rgba(${g},${d},${x},${(.05+l.depth*.04)*ft})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${g},${d},${x},${(.3+l.depth*.22)*ft})`,n.stroke()}n.globalCompositeOperation="source-over"}}function Kr(){n.globalCompositeOperation="lighter";let r=q.t,c=0;if(O.waveStyle==="circular"){let l=Yt||{x:I/2,y:$/2},g=Math.min(I,$)*.48;for(let d of Dt){let x=vt[d.wi];if(!x){c++;continue}q.dt&&(d.progress+=d.speed,d.progress>1?d.progress-=1:d.progress<0&&(d.progress+=1));let m=d.progress*2*Math.PI,h=ae(x,m,r,g)+d.phase*32,w=l.x+Math.cos(m)*h,M=l.y+Math.sin(m)*h,[S,T,k]=x.color,C=d.glow?.6+.4*Math.sin(r*2.2+c):.85;d.glow&&(n.fillStyle=`rgba(${S},${T},${k},${.16*C*ft})`,n.beginPath(),n.arc(w,M,d.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${S},${T},${k},${C*ft})`,n.beginPath(),n.arc(w,M,d.size,0,6.28318),n.fill(),c++}}else for(let l of Dt){let g=vt[l.wi];if(!g){c++;continue}q.dt&&(l.progress+=l.speed,l.progress>1?l.progress-=1:l.progress<0&&(l.progress+=1));let d=l.progress*I,x=Et(g,d,r,$,1,1,xt)+l.phase*32,[m,h,w]=g.color,M=l.glow?.6+.4*Math.sin(r*2.2+c):.85;l.glow&&(n.fillStyle=`rgba(${m},${h},${w},${.16*M*ft})`,n.beginPath(),n.arc(d,x,l.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${m},${h},${w},${M*ft})`,n.beginPath(),n.arc(d,x,l.size,0,6.28318),n.fill(),c++}n.globalCompositeOperation="source-over"}function Qr(){if(!O.attention)return;for(let l of L)l.attn=1;let r=L.filter(l=>l.vis&&l.tokens.length>0);if(r.length===0)return;let c=po(r);for(let l=0;l<r.length;l++)r[l].attn=c[l]}function Zr(){if(!O.causality)return;let r=L.filter(l=>l.vis&&l.tokens.length>0);if(r.length===0)return;if(r.length===1){jn(r[0],r[0].d);return}let c=mo(r.map(l=>({d:l.d,cx:l.cx,cy:l.cy})));for(let l=0;l<r.length;l++)jn(r[l],wt(r[l].d+c[l],0,1))}function jn(r,c){O.feedbackSink(r.el,{lit:c})}function ts(){for(let r of L){if(!r.feedback)continue;let c=uo(r.count,r.on);r.d+=(c-r.d)*.08;let l=r.writeTarget??r.el;if(r.fmax){let w=yo(r.fmin,r.fmax,r.d);fe.get(l)!==w&&(fe.set(l,w),l.style.fontVariationSettings=`"wght" ${w}`+(r.opsz?`, "opsz" ${r.opsz}`:""))}let g=K?K.norm(r.cx,r.cy):void 0,d=r.tokens.indexOf("sink")>=0&&r.capacity>0?An(r):void 0,x=Do(r.thermo),m=r.metrics??(r.metrics={entropy:0,coherence:1,temperature:0});m.entropy+=(x.entropy-m.entropy)*.08,m.coherence+=(x.coherence-m.coherence)*.08,m.temperature+=(x.temperature-m.temperature)*.08;let h={density:r.d,heatmapDensity:g,load:d,entropy:m.entropy,coherence:m.coherence,temperature:m.temperature};O.feedbackSink(l,h),r.onFeedback?.(h)}}function es(){if(Vt.length!==0){n.globalCompositeOperation="lighter";for(let r=Vt.length-1;r>=0;r--){let c=Vt[r];if(!c)continue;if(c.x+=c.vx,c.y+=c.vy,c.vx*=.9,c.vy*=.9,c.life*=.85,c.life<.05){Vt.splice(r,1);continue}let[l,g,d]=c.c;n.fillStyle=`rgba(${l},${g},${d},${.18*c.life})`,n.beginPath(),n.arc(c.x,c.y,2+c.life*4,0,6.28318),n.fill(),n.fillStyle=`rgba(${l},${g},${d},${c.life})`,n.beginPath(),n.arc(c.x,c.y,.6+c.life*1.5,0,6.28318),n.fill()}n.globalCompositeOperation="source-over"}}let Wt=null,we=null,Kt=null;function ns(){if(!K)return;let r=$>0?wt((1.15-ee/$)/.85,0,1):1;if(r<=.01)return;let c=K.cell,l=Math.max(1,Math.ceil(I/c)),g=Math.max(1,Math.ceil($/c));if(Wt||(Wt=_.createCanvas(),we=Wt.getContext("2d")),!!we){if((Wt.width!==l||Wt.height!==g)&&(Wt.width=l,Wt.height=g,Kt=null),Kt===null||$t%3===0){Kt===null&&(Kt=we.createImageData(l,g));let d=rt,x=Kt.data;for(let m=0;m<g;m++)for(let h=0;h<l;h++){let w=K.norm(h*c+c/2,m*c+c/2),M=(m*l+h)*4;x[M]=d[0],x[M+1]=d[1],x[M+2]=d[2],x[M+3]=Math.round(wt(w*.5*ft,0,1)*255)}we.putImageData(Kt,0,0)}n.globalCompositeOperation="lighter",n.imageSmoothingEnabled=!0,n.globalAlpha=r,n.drawImage(Wt,0,0,I,$),n.globalAlpha=1,n.globalCompositeOperation="source-over"}}function os(){O.background==="transparent"?O.render==="trails"?(n.globalCompositeOperation="destination-out",n.fillStyle="rgba(0,0,0,0.22)",n.fillRect(0,0,I,$),n.globalCompositeOperation="source-over"):n.clearRect(0,0,I,$):(O.render==="trails"?n.fillStyle="rgba(5,6,11,0.22)":n.fillStyle="rgb(5,6,11)",n.fillRect(0,0,I,$)),Jr(),K&&xe<2&&ns(),Kr();let r=O.render!=="metaballs"&&O.render!=="streamlines";n.globalCompositeOperation="lighter";let c=rt,l=I/2,g=$*.4,d=Math.hypot(Math.max(l,I-l),Math.max(g,$-g))||1;if(ue===null||$t%6===0){ue=[];for(let m of L){if(!m.tint)continue;let h=(m.range||200)*1.4;ue.push({b:m,r2:h*h,rgb:gt(m.tint)})}}let x=ue;if(r)for(let m of a.particles){if(m.cap){n.fillStyle=`rgba(${c[0]},${c[1]},${c[2]},${.55*ft})`,n.beginPath(),n.arc(m.x,m.y,1.3,0,6.28318),n.fill();continue}let h=Math.min(1,Math.hypot(m.x-l,m.y-g)/d),w=h*h,M=m.heat;co(Le,w,M,c,O.gradientCool,O.gradientWarm);let S=Le[0],T=Le[1],k=Le[2];if(x.length){let mt=0,nt=null;for(let st of x){let Ft=m.x-st.b.cx,At=m.y-st.b.cy,oe=Ft*Ft+At*At;if(oe>=st.r2)continue;let P=1-Math.sqrt(oe/st.r2);P>mt&&(mt=P,nt=st.rgb)}if(nt){let st=mt*.7;S+=(nt[0]-S)*st,T+=(nt[1]-T)*st,k+=(nt[2]-k)*st}}if(m.color){let[mt,nt,st]=gt(m.color);S+=(mt-S)*.75,T+=(nt-T)*.75,k+=(st-k)*.75}let C=O.depth>0?1-Math.min(Math.abs(m.z??0)/O.depth,1)*.55:1,H=(m.size*(1-.4*w)+M*2)*C,G=wt((.5-.3*w+M*.5)*ft*C,0,1),ct=S|0,pt=T|0,bt=k|0;n.fillStyle=`rgba(${ct},${pt},${bt},${.12*G})`,n.beginPath(),n.arc(m.x,m.y,H+1.2,0,6.28318),n.fill(),n.fillStyle=`rgba(${ct},${pt},${bt},${G})`,n.beginPath(),n.arc(m.x,m.y,H,0,6.28318),n.fill()}if(es(),jr(),n.globalCompositeOperation="source-over",O.render==="links"){n.globalCompositeOperation="lighter";let m=rt,h=90;n.lineWidth=.6;for(let w of a.particles)if(!w.cap)for(let M of a.neighbors(w,h)){if(M.x<w.x||M.x===w.x&&M.y<w.y)continue;let S=rr(Math.hypot(M.x-w.x,M.y-w.y),h);S<=0||(n.strokeStyle=`rgba(${m[0]},${m[1]},${m[2]},${S})`,n.beginPath(),n.moveTo(w.x,w.y),n.lineTo(M.x,M.y),n.stroke())}n.globalCompositeOperation="source-over"}if(O.render==="metaballs"){let M=Math.ceil(I/16)+1,S=Math.ceil($/16)+1;!It||It.length!==M*S?It=new Float32Array(M*S):It.fill(0);for(let k of a.particles)k.cap||Sn(It,M,S,16,k.x,k.y,34,1);let T=rt;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${T[0]},${T[1]},${T[2]},${.5*ft})`,n.lineWidth=1.4,n.lineCap="round",n.beginPath();for(let k=0;k<S-1;k++)for(let C=0;C<M-1;C++){let H=It[k*M+C],G=It[k*M+C+1],ct=It[(k+1)*M+C+1],pt=It[(k+1)*M+C],bt=kn(H,G,ct,pt,.9);if(!bt.length)continue;let mt=C*16,nt=k*16;for(let st of bt)n.moveTo(mt+st.x1*16,nt+st.y1*16),n.lineTo(mt+st.x2*16,nt+st.y2*16)}n.stroke(),n.globalCompositeOperation="source-over"}if(O.render==="voronoi"){let w=Math.ceil(I/18)+1,M=Math.ceil($/18)+1;(!ne||ne.length!==w*M)&&(ne=new Int32Array(w*M));let S=a.particles,T=new Map;for(let C=0;C<S.length;C++)T.set(S[C],C);for(let C=0;C<M;C++)for(let H=0;H<w;H++){let G=H*18,ct=C*18,pt=a.near(G,ct,54),bt=-1;if(pt.length){let mt=sr(G,ct,pt);mt>=0&&(bt=T.get(pt[mt])??-1)}ne[C*w+H]=bt}let k=rt;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${k[0]},${k[1]},${k[2]},${.32*ft})`,n.lineWidth=1,n.beginPath();for(let C of ir(ne,w,M))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==="streamlines"||O.render==="flow"){let h=rt;if(n.lineWidth=1,n.lineCap="round",he===null||ut||$t%3===0){let w=[],M=[],S=0;for(let T=46/2;T<I;T+=46)for(let k=46/2;k<$;k+=46){let{fx:C,fy:H}=Zt(L,p.forces,q,T,k);if(ut){let ct=ie(Ne,T,k,ut,.04);C+=ct.x,H+=ct.y}let G=Math.hypot(C,H);if(!(G>1e-9)){M.push({gx:T,gy:k});continue}w.push({gx:T,gy:k,ux:C/G,uy:H/G,mag:G}),G>S&&(S=G)}_t===0?_t=S:_t=S>_t?_t*.7+S*.3:_t*.9+S*.1,he=w,Ue=M}if(Ue.length){n.fillStyle=`rgba(${h[0]},${h[1]},${h[2]},0.05)`;for(let w of Ue)n.fillRect(w.gx-.5,w.gy-.5,1,1)}if(_t>0&&he)for(let w of he){let M=Math.sqrt(w.mag/_t),S=46*.46*(.28+.72*M),T=w.gx+w.ux*S,k=w.gy+w.uy*S;n.strokeStyle=`rgba(${h[0]},${h[1]},${h[2]},${wt(.1+M*.5,0,.72)})`,n.beginPath(),n.moveTo(w.gx,w.gy),n.lineTo(T,k);let C=3.4;n.moveTo(T,k),n.lineTo(T-w.ux*C-w.uy*C*.6,k-w.uy*C+w.ux*C*.6),n.moveTo(T,k),n.lineTo(T-w.ux*C+w.uy*C*.6,k-w.uy*C-w.ux*C*.6),n.stroke()}}}function Xn(r){return(r===void 0?[]:Array.isArray(r)?r:[r]).filter(l=>l!=="off")}function Jn(r,c,l){let d=rt;if(Ge===null||ut||$t%3===0){let h=[],w=0;for(let M=44/2;M<I;M+=44)for(let S=44/2;S<$;S+=44){let{fx:T,fy:k}=Zt(L,p.forces,q,M,S);if(ut){let H=ie(Ne,M,S,ut,.04);T+=H.x,k+=H.y}let C=Math.hypot(T,k);C>1e-9&&(h.push({gx:M,gy:S,ux:T/C,uy:k/C,mag:C}),C>w&&(w=C))}Nt===0?Nt=w:Nt=w>Nt?Nt*.7+w*.3:Nt*.9+w*.1,Ge=h}if(Nt<=0)return;let x={r:d[0],g:d[1],b:d[2],alpha:0,width:1.2},m=new Float64Array(12);for(let h of Ge){let w=l?wt(h.mag/Nt,0,1):Math.sqrt(h.mag/Nt),M=44*.5*(.25+.75*w),S=h.gx+h.ux*M,T=h.gy+h.uy*M,k=3.6;m[0]=h.gx,m[1]=h.gy,m[2]=S,m[3]=T,m[4]=S,m[5]=T,m[6]=S-h.ux*k-h.uy*k*.6,m[7]=T-h.uy*k+h.ux*k*.6,m[8]=S,m[9]=T,m[10]=S-h.ux*k+h.uy*k*.6,m[11]=T-h.uy*k-h.ux*k*.6,x.alpha=wt(.12+w*.55,0,.8),r.segments(m,x)}}function rs(r){let c=Mo(L);if(!c.length)return;let l=vo((x,m)=>Te(L,p.forces,x,m),c,{step:6,maxSteps:200,bounds:{w:I,h:$},loopDist:8}),g=rt,d={r:g[0],g:g[1],b:g[2],alpha:.42,width:1.1};for(let x of l){if(x.length<2)continue;let m=new Float32Array(x.length*2);for(let h=0;h<x.length;h++)m[h*2]=x[h].x,m[h*2+1]=x[h].y;r.polyline(m,d)}}function ss(r){let l=22*O.gridWarp,g=48*.46,d=Math.floor(I/48)+2,x=Math.floor($/48)+2,m=new Float32Array(d*x),h=new Float32Array(d*x),w=0,M=new Float32Array(d*x);for(let P=0;P<x;P++)for(let W=0;W<d;W++){let{fx:et,fy:V}=Zt(L,p.forces,q,W*48,P*48),ot=Math.hypot(et,V),Mt=P*d+W;ot>1e-9&&(m[Mt]=et/ot,h[Mt]=V/ot,M[Mt]=ot,ot>w&&(w=ot))}let S=[rt,[120,110,255],[240,70,255],[255,50,130]],T=8,k=P=>w>0?Math.sqrt(M[P]/w):0,C=P=>Math.round(k(P)*T),H=P=>{let W=P/T,et=gn(S,W);return{r:et[0],g:et[1],b:et[2],alpha:Math.min(1,O.gridIntensity*(.3+.85*W)),width:W>.55?1.4:1}},G=new Float32Array(d*x),ct=new Float32Array(d*x);for(let P=0;P<d*x;P++){let W=k(P);G[P]=m[P]*W*l,ct[P]=h[P]*W*l}let pt=new Float32Array(d*x),bt=new Float32Array(d*x);for(let P=0;P<x;P++)for(let W=0;W<d;W++){let et=0,V=0,ot=0;for(let Ct=-1;Ct<=1;Ct++)for(let Pt=-1;Pt<=1;Pt++){let zt=W+Pt,Ot=P+Ct;if(zt<0||Ot<0||zt>=d||Ot>=x)continue;let Qt=Ot*d+zt;et+=G[Qt],V+=ct[Qt],ot++}let Mt=P*d+W;pt[Mt]=et/ot,bt[Mt]=V/ot}let mt=48*1.5,nt=(P,W)=>{let et=W*d+P,V=pt[et],ot=bt[et],Mt=Math.hypot(V,ot);Mt>g&&(V=V/Mt*g,ot=ot/Mt*g);let Ct=P*48,Pt=W*48,zt=Math.min(Ct,I-Ct,Pt,$-Pt),Ot=zt<=0?0:zt<mt?zt/mt:1;return[Ct+V*Ot,Pt+ot*Ot]},st=4,Ft=P=>{let W=P.length>>1;if(W<3)return P;let et=[P[0],P[1]];for(let V=0;V<W-1;V++){let ot=(V>0?V-1:0)<<1,Mt=V<<1,Ct=V+1<<1,Pt=(V+2<W?V+2:W-1)<<1,zt=P[ot],Ot=P[ot+1],Qt=P[Mt],nn=P[Mt+1],on=P[Ct],rn=P[Ct+1],no=P[Pt],oo=P[Pt+1];for(let sn=1;sn<=st;sn++){let re=sn/st,an=re*re,ro=an*re;et.push(.5*(2*Qt+(-zt+on)*re+(2*zt-5*Qt+4*on-no)*an+(-zt+3*Qt-3*on+no)*ro),.5*(2*nn+(-Ot+rn)*re+(2*Ot-5*nn+4*rn-oo)*an+(-Ot+3*nn-3*rn+oo)*ro))}}return et},At=(P,W)=>Math.max(C(P*d+W),C(P*d+W+1)),oe=(P,W)=>Math.max(C(W*d+P),C((W+1)*d+P));for(let P=0;P<x;P++){let W=At(P,0),et=[...nt(0,P),...nt(1,P)];for(let V=1;V<d-1;V++){let ot=At(P,V);ot===W?et.push(...nt(V+1,P)):(r.polyline(Ft(et),H(W)),et=[...nt(V,P),...nt(V+1,P)],W=ot)}r.polyline(Ft(et),H(W))}for(let P=0;P<d;P++){let W=oe(P,0),et=[...nt(P,0),...nt(P,1)];for(let V=1;V<x-1;V++){let ot=oe(P,V);ot===W?et.push(...nt(P,V+1)):(r.polyline(Ft(et),H(W)),et=[...nt(P,V),...nt(P,V+1)],W=ot)}r.polyline(Ft(et),H(W))}}let kt=null;function Kn(r,c,l){let x=Math.ceil(I/24)+1,m=Math.ceil($/24)+1;!kt||kt.length!==x*m?kt=new Float32Array(x*m):kt.fill(0);let h=!1;for(let k of a.particles){if(k.cap)continue;let C=c(k);C<=0||(h=!0,Sn(kt,x,m,24,k.x,k.y,42,C))}if(!h)return;let w=0;for(let k=0;k<kt.length;k++)kt[k]>w&&(w=kt[k]);if(w<=0)return;let M=rt,S=[.25,.5,.78],T=[];for(let k=0;k<S.length;k++){let C=S[k]*w;T.length=0;for(let H=0;H<m-1;H++)for(let G=0;G<x-1;G++){let ct=kt[H*x+G],pt=kt[H*x+G+1],bt=kt[(H+1)*x+G+1],mt=kt[(H+1)*x+G],nt=kn(ct,pt,bt,mt,C);if(!nt.length)continue;let st=G*24,Ft=H*24;for(let At of nt)T.push(st+At.x1*24,Ft+At.y1*24,st+At.x2*24,Ft+At.y2*24)}T.length&&r.segments(T,{r:M[0],g:M[1],b:M[2],alpha:l*(.45+.55*(k/(S.length-1))),width:1+k*.3})}}function is(r){let d=rt,x={r:d[0],g:d[1],b:d[2],alpha:0,width:1.1},m=new Float64Array(4);for(let h=104/2;h<I;h+=104)for(let w=104/2;w<$;w+=104){let M=h,S=w;for(let T=0;T<24;T++){let{fx:k,fy:C}=Zt(L,p.forces,q,M,S);if(ut){let pt=ie(Ne,M,S,ut,.04);k+=pt.x,C+=pt.y}let H=Math.hypot(k,C);if(!(H>1e-9))break;let G=M+k/H*9,ct=S+C/H*9;if(G<0||ct<0||G>I||ct>$)break;m[0]=M,m[1]=S,m[2]=G,m[3]=ct,x.alpha=.34*(1-T/24),r.segments(m,x),M=G,S=ct}}}function as(r){let c=rt;for(let l of L){if(!l.vis||!l.feedback)continue;let g=`d ${l.d.toFixed(2)}`,d=l.cx+l.hw+8,x=l.cy;r.rect(d-3,x-7,r.measureText(g)+6,14,c[0],c[1],c[2],wt(.3+l.d*.55,0,.85)),r.text(g,d,x+.5,5,6,11,.92)}}function cs(r,c){if(r.clear(),!(!c.length||I===0||$===0))for(let l of c){l==="streamlines"?Jn(r,!1,!1):l==="force-vectors"?Jn(r,!1,!0):l==="field-lines"?rs(r):l==="grid"?ss(r):l==="temperature"?Kn(r,d=>d.heat,.5):l==="energy"?Kn(r,d=>.5*d.m*(d.vx*d.vx+d.vy*d.vy),.42):l==="path"?is(r):l==="data"&&as(r);let g=dt.get(l);g&&g(r,q,I,$)}}function tn(r){$t++,q.t=(r-qn)/1e3,q.frameN=$t;let c=Number.isFinite(Ye)?(r-Ye)/16.6667:1;if(Ye=r,q.dt=yt?0:wt(c,.2,2),ft<1&&(ft=Math.min(1,ft+.012)),Wo(q.form,Dn,.03),at){let h=_.viewport();Y=h.originX??0,Q=h.originY??0}let l=_.scrollY(),g=l-ee;if(q.scrollV=(q.scrollV??0)*.7+Math.abs(g)*.3,ee=l,g!==0&&!at)for(let h of L)h.cy-=g;for(let h of vt){let w=l*(.025+h.depth*.08);h.offsetY+=(w-h.offsetY)*.04}if(L.length&&$t%6===0&&(Pe(L,I,$,Y,Q),u(L),yr(L,q.supernova)),lt.length&&q.dt){let h=q.dt/60;for(let w of lt)fr(w.agent,w.from.d>.08,0,h)}let d=null;for(let h of L)if(h.on&&h.vis){d=h;break}let x=ut??d;if(xt.k+=((x?1:0)-xt.k)*.07,x){let h=ut?ut.x:d.cx,w=ut?ut.y:d.cy;xt.x=xt.x?xt.x+(h-xt.x)*.16:h,xt.y=xt.y?xt.y+(w-xt.y)*.16:w}$t%30===0&&(Ut=_.scrollHeight()-$||1);let m=ye?gt(ye):gn(Hn,l/Ut);if(rt=[rt[0]+(m[0]-rt[0])*.08,rt[1]+(m[1]-rt[1])*.08,rt[2]+(m[2]-rt[2])*.08],O.accent=mn(rt),a.reindex(),Qr(),q.dt&&No(L,a.particles),ut&&q.dt)for(let h of a.particles){if(h.cap)continue;let w=ie(Ne,h.x,h.y,ut,.6);h.vx+=w.x,h.vy+=w.y}if(O.waveStyle==="circular")if(O.waveCenter)Yt=typeof O.waveCenter=="function"?O.waveCenter():O.waveCenter;else{let h=L.find(w=>w.tokens.includes("star")||w.tokens.includes("vortex"));h?Yt={x:h.cx,y:h.cy}:Yt={x:I/2,y:$/2}}else Yt=null;if(Lr(),Yo({store:a,bodies:L,env:q,forces:p.forces,conditions:p.conditions,waves:vt,waveStyle:O.waveStyle,waveCenter:Yt,separation:O.separation}),Lt&&(Lt.x=Bn,Lt.y=Wn,Lt.vx=0,Lt.vy=0,Lt.heat=Math.min(1,Lt.heat+.2)),q.dt){for(let h of y.values())h.step();K&&K.update(a.particles),$o(a,Dt,_n,vt,I,$,q.t,ht),Io(Dt,vt,L,p.forces,I,$,q.t,h=>void a.add(Xt(h))),Gr(),Dr()}if(ts(),Zr(),_r(),Br(),Wr(),Yr(r),R(),n&&O.render!=="none"&&Ln&&(!yt||$t%4===0)&&(os(),i)){let h=Xn(O.overlay);h.length&&cs(i,h)}qt=_.raf(tn)}function en(r){let c=Ee[r];c&&(Dn={...c.preset})}let be="",Qn=qn;function Zn(){let r=_.viewport().height*.5,c="";_.root.querySelectorAll("[data-formation]").forEach(l=>{let g=l.getBoundingClientRect();g.top<=r&&g.bottom>=r&&(c=l.dataset.formation??"")}),c&&c!==be&&(be=c,en(c))}let to=()=>void(Qn=qe()),ls=()=>{to(),Zn()},eo=setInterval(()=>{qe()-Qn>6e3&&be!=="ambient"&&(be="ambient",en("ambient"))},1200);eo.unref?.();let ds=()=>Vn();Vn();let fs=()=>{_.hidden()?(_.cancelRaf(qt),qt=0):qt||(qt=_.raf(tn))};return tt.push(_.onResize(ds)),tt.push(_.onScroll(ls)),tt.push(_.onVisibility(fs)),tt.push(_.onInput(to)),tt.push(_.onBodyEvent(tr,Rr)),tt.push(_.onBodyEvent(er,$r)),tt.push(_.onBodyEvent(nr,Ir)),Zn(),qt=_.raf(tn),{scan:ge,rescan:ge,setAccent:r=>{O.accent=r,rt=gt(r)},setPalette:r=>{let c=ke(r);Hn=c.map(gt);let l=c[0];l&&(O.accent=l,rt=gt(l))},setFormation:en,setWaveStyle:r=>{O.waveStyle=r},setWaveCenter:r=>{O.waveCenter=r},setSeparation:r=>{O.separation=r>=0?r:0},setAttention:r=>{if(O.attention=r,!r)for(let c of L)c.attn=1},setCausality:r=>{if(O.causality=r,!r)for(let c of L)c.el.style.removeProperty("--lit"),c.el.dataset.fxLit="0"},setRender:r=>{if(r!=="none"&&!n){if(n=e.getContext("2d"),!n){console.warn(`Fundamental: setRender('${r}') could not acquire a 2d context; staying in render 'none'`);return}o&&!s&&(s=o.getContext("2d"),s&&!i&&(i=t.overlayBackend??zn(o,s))),ve(_.viewport().dpr)}O.render=r},setOverlay:r=>{O.overlay=r,Xn(r).length||i?.clear()},setHeatmap:r=>{if(O.heatmap=r,r)!K&&I>0&&(K=new le(I,$));else if(K){K.clear(),K=null;for(let c of L)(c.writeTarget??c.el).style.removeProperty("--field-heatmap-density")}},setDprCap:r=>{O.dprCap=r>0?r:2,n&&ve(_.viewport().dpr)},setQualityTier:r=>{let c=Math.max(0,Math.min(3,Math.floor(r||0)));c!==xe&&(xe=c,n&&ve(_.viewport().dpr))},threads:Ze,burst:(r,c,l)=>{for(let d of a.particles){let x=ko(d.x-r,d.y-c,160,6,d.z??0);x.heat!==0&&(d.vx+=x.vx,d.vy+=x.vy,x.vz&&(d.vz=(d.vz??0)+x.vz),d.heat=Math.max(d.heat,x.heat),l&&(d.color=l))}xn(Dt,vt,r,c,160,I,$,q.t,d=>void a.add(Xt(d))),Yn(r,c,2,l)},flowTo:(r,c,l)=>{ut=go(r,c,l)},clearFlow:()=>{ut=null},seed:r=>{me=r,Un()},atomAt:(r,c)=>{let l=null,g=1/0;for(let d of a.near(r,c,24)){if(d.atom==null)continue;let x=(d.x-r)**2+(d.y-c)**2+(d.z??0)**2;x<g&&(g=x,l=d.atom)}return l},focusAt:(r,c)=>{let l=null,g=1/0;for(let d of a.near(r,c,24)){if(d.atom==null)continue;let x=(d.x-r)**2+(d.y-c)**2+(d.z??0)**2;x<g&&(g=x,l=d)}return Lt=l,l?(Bn=l.x,Wn=l.y,l.atom??null):null},clearFocus:()=>{Lt=null},particleCount:()=>a.size,readParticles:r=>{let c=a.particles,l=Math.floor(r.length/5),g=0;for(let d=0;d<c.length&&g<l;d++){let x=c[d];if(x.report!==void 0)continue;let m=g*5;r[m]=x.x,r[m+1]=x.y,r[m+2]=x.z??0,r[m+3]=x.heat,r[m+4]=x.size,g++}return g},readParticleIds:r=>{let c=a.particles,l=0;for(let g=0;g<c.length&&l<r.length;g++){let d=c[g];d.report===void 0&&(r[l++]=d.id??0)}return l},readParticleChannels:(r,c)=>{let l=a.particles,g=0;for(let d=0;d<l.length;d++){let x=l[d];if(!("report"in x&&x.report!==void 0)){if(g>=Math.min(...c.map(m=>m.length)))break;for(let m=0;m<r.length&&!(m>=c.length);m++){let h=r[m];c[m][g]=h==="x"?x.x:h==="y"?x.y:h==="z"?x.z??0:h==="vx"?x.vx:h==="vy"?x.vy:h==="heat"?x.heat:h==="size"?x.size:h==="m"?x.m:h==="id"?x.id??0:h==="age"?x.age??0:h==="charge"?x.charge??0:0}g++}}return g},registerOverlay:(r,c)=>(dt.set(r,c),()=>{dt.delete(r)}),addAgent:r=>{let c=Xt({x:r.x,y:r.y,z:r.z,species:r.species});return c.vx=0,c.vy=0,r.z===void 0&&O.depth<=0&&(c.z=0),r.mass!==void 0&&(c.m=r.mass),c.maxSpeed=r.maxSpeed,c.report=r.report,a.add(c),{particle:c,remove:()=>a.remove(c)}},addBody:r=>{let c={"data-body":Array.isArray(r.tokens)?r.tokens.join(" "):String(r.tokens)};r.strength!=null&&(c["data-strength"]=String(r.strength)),r.range!=null&&(c["data-range"]=String(r.range)),r.spin!=null&&(c["data-spin"]=String(r.spin)),r.angle!=null&&(c["data-angle"]=String(r.angle)),r.color!=null&&(c["data-color"]=r.color);let l=()=>{let h=r.rect();return{left:h.left,top:h.top,right:h.left+h.width,bottom:h.top+h.height,width:h.width,height:h.height,x:h.left,y:h.top,toJSON:()=>({})}},g={tagName:"DIV",id:"",className:"",dataset:r.color!=null?{color:r.color}:{},getAttribute:h=>c[h]??null,hasAttribute:h=>h in c,getBoundingClientRect:l,dispatchEvent:()=>!0,setAttribute:()=>{},removeAttribute:()=>{},style:{setProperty:()=>{},removeProperty:()=>{},getPropertyValue:()=>""}},d=ce(g);d.rect=l,d.data=r.data,d.feedback=!0;let x={};d.onFeedback=h=>{Object.assign(x,h),r.onFeedback?.(h)},Z.push(d),L=L.concat(d),Pe([d],I,$,Y,Q);let m={data:r.data,get channels(){return x},set:h=>{h.strength!=null&&(c["data-strength"]=String(h.strength)),h.range!=null&&(c["data-range"]=String(h.range)),h.spin!=null&&(c["data-spin"]=String(h.spin)),h.angle!=null&&(c["data-angle"]=String(h.angle)),h.color!=null&&(c["data-color"]=h.color,g.dataset.color=h.color,d.tint=h.color)},remove:()=>{let h=Z.indexOf(d);h>=0&&Z.splice(h,1),L=L.filter(w=>w!==d);for(let w=lt.length-1;w>=0;w--){let M=lt[w];(M.from===d||M.to===d)&<.splice(w,1)}}};return it.set(m,d),m},addEdge:(r,c,l)=>{let g=it.get(r),d=it.get(c);if(!g||!d)throw new Error("addEdge: both arguments must be handles returned by addBody on this field.");let x={id:`e${D++}`,from:"",to:"",type:l?.type??"related",strength:l?.strength??.5,tension:0,memory:0,active:!1},m={agent:x,from:g,to:d,fromData:r.data,toData:c.data};return lt.push(m),{set:h=>{h.strength!=null&&(x.strength=h.strength<0?0:h.strength>1?1:h.strength),h.type!=null&&(x.type=h.type)},remove:()=>{let h=lt.indexOf(m);h>=0&<.splice(h,1)}}},readEdges:()=>lt.map(r=>({from:r.fromData,to:r.toData,type:r.agent.type,strength:r.agent.strength,memory:r.agent.memory,active:r.agent.active})),addField:(r,c)=>(J.set(r,c),{name:r,set:l=>{J.set(r,l)},remove:()=>{J.delete(r)}}),sampleField:(r,c,l)=>{let g=J.get(r);return g?g(c,l):0},energy:()=>Er(a.particles),sample:(r,c)=>{let{fx:l,fy:g}=Zt(L,p.forces,q,r,c);return{x:l,y:g}},sampleScalar:(r,c)=>K?K.norm(r,c):(En("NOOP_NO_HEATMAP","sampleScalar() returned 0 because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),0),sampleGradient:(r,c)=>K?K.gradient(r,c):(En("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:r=>q.grid(r),on:(r,c)=>{let l=v.get(r);return l||(l=new Set,v.set(r,l)),l.add(c),()=>void l.delete(c)},version:cn,scrollV:()=>q.scrollV??0,setVisible:r=>{Ln=r},setBackground:r=>{O.background=r,r==="transparent"&&n&&n.clearRect(0,0,I,$)},destroy:()=>{_.cancelRaf(qt),clearInterval(eo);for(let r of tt)r();for(let r of jt)r.el.removeEventListener("pointerenter",r.enter),r.el.removeEventListener("pointerleave",r.leave),r.el.removeEventListener("focus",r.enter),r.el.removeEventListener("blur",r.leave),delete r.el.dataset.fxEngaged;jt=[];for(let r of Bt)(r.docked||r.dock.dock>0)&&(r.docked=null,r.dock.dock=0,r.el.style.opacity="",r.el.getAttribute("aria-hidden")==="true"&&r.el.removeAttribute("aria-hidden"),r.el.removeAttribute("inert"));for(let r of Gt)for(let c of r.emitted)c.remove();Gt=[],a.clear()}}}var _e={};function Be(){return _e.reducedMotion!==void 0?_e.reducedMotion:typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function We(){return _e.hidden!==void 0?_e.hidden:typeof document<"u"&&document.hidden}var Vi=["--field-density","--d"],kr=!1;function Sr(){if(kr)return[];kr=!0;let e=globalThis.CSS;if(!e||typeof e.registerProperty!="function")return[];let t=[];for(let n of Vi)try{e.registerProperty({name:n,syntax:"<number>",inherits:!0,initialValue:"0"}),t.push(n)}catch{}return t}var zr=["pointerdown","wheel","keydown","touchstart"];function de(){return Sr(),{root:document,viewport:()=>({width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio||1}),scrollY:()=>window.scrollY||0,scrollHeight:()=>document.documentElement.scrollHeight,reducedMotion:()=>Be(),hidden:()=>We(),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 zr)window.addEventListener(t,e,{passive:!0});return()=>{for(let t of zr)window.removeEventListener(t,e)}},onBodyEvent:(e,t)=>(document.addEventListener(e,t),()=>document.removeEventListener(e,t))}}var Tr=["pointerdown","wheel","keydown","touchstart"];function Fr(e){return{root:e,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:()=>Be(),hidden:()=>We(),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 Tr)e.addEventListener(n,t,{passive:!0});return()=>{for(let n of Tr)e.removeEventListener(n,t)}},onBodyEvent:(t,n)=>(e.addEventListener(t,n),()=>e.removeEventListener(t,n))}}function Ar(e,t={}){return De(e,{...t,host:de()})}function $n(e,t={}){let{host:n,bounds:o,...s}=t,i=n??(o?Fr(o):de());return De(e,{...s,host:i})}function In(){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 He(e=document.body){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText=cr,e.appendChild(t),t}function Cr(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 ji(e={}){In();let{target:t=document.body,...n}=e,o=He(t),s=Ar(o,n);return{...s,destroy:()=>{s.destroy(),o.remove()}}}var Nn=class{constructor(t={}){U(this,"canvas");U(this,"field");U(this,"managed");In();let{canvas:n,target:o,bounds:s,...i}=t;this.managed=!n,this.canvas=n??(s?Cr(s):He(o)),this.field=$n(this.canvas,s?{...i,bounds:s}:i)}scan(){this.field.scan()}rescan(){this.field.rescan()}setAccent(t){this.field.setAccent(t)}setPalette(t){this.field.setPalette(t)}setFormation(t){this.field.setFormation(t)}setWaveStyle(t){this.field.setWaveStyle(t)}setWaveCenter(t){this.field.setWaveCenter(t)}setSeparation(t){this.field.setSeparation(t)}setAttention(t){this.field.setAttention(t)}setCausality(t){this.field.setCausality(t)}setHeatmap(t){this.field.setHeatmap(t)}setDprCap(t){this.field.setDprCap(t)}setQualityTier(t){this.field.setQualityTier(t)}setRender(t){this.field.setRender(t)}setOverlay(t){this.field.setOverlay(t)}threads(t){this.field.threads(t)}burst(t,n,o){this.field.burst(t,n,o)}flowTo(t,n,o){this.field.flowTo(t,n,o)}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,o){return this.field.addEdge(t,n,o)}readEdges(){return this.field.readEdges()}addField(t,n){return this.field.addField(t,n)}sampleField(t,n,o){return this.field.sampleField(t,n,o)}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)}on(t,n){return this.field.on(t,n)}get version(){return this.field.version}scrollV(){return this.field.scrollV()}setVisible(t){this.field.setVisible(t)}setBackground(t){this.field.setBackground(t)}destroy(){this.field.destroy(),this.managed&&this.canvas.remove()}};export{ao as CONDITIONS,cn as FIELD_VERSION,dn as FORCES,io as FORMATIONS,Nn as FieldField,fn as PALETTE,de as browserHost,$n as createField,dr as cssFeedbackSink,_s as headlessHost,He as makeFieldCanvas,ji as mountField};
|
|
2
|
+
var hs=Object.defineProperty;var us=(e,t,n)=>t in e?hs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var U=(e,t,n)=>us(e,typeof t!="symbol"?t+"":t,n);var cn="0.9.1";var dn=[{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"}],so=Object.fromEntries(dn.map(e=>[e.id,e])),fn=dn.map(e=>e.color),se=["#4da3ff","#2dd4bf","#a78bfa","#ff6e9c","#ff9d5c"],ln=["spotlight","screen","resonate"],ys=["spawn"],hn=300,un=120;function ps(e){return ln.includes(e)?"modifier":ys.includes(e)?"source":"force"}function Me(e){let t=[],n=[],o=[];for(let s of e){let i=ps(s);i==="modifier"?t.push(s):i==="source"?o.push(s):n.push(s)}return t.length>1&&t.sort((s,i)=>ln.indexOf(s)-ln.indexOf(i)),{modifiers:t,forces:n,sources:o}}var io=[{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(io.map(e=>[e.id,e]));var ao=[{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}],Qi=Object.fromEntries(ao.map(e=>[e.id,e]));var ms={ours:se,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:se:typeof e=="string"?ms[e]??se:se}var yn={warm:{cool:[255,224,200],warm:[255,110,80],wave:["#ff8a5c","#f0628e","#ffc46b"]},cool:{cool:[206,226,255],warm:[74,132,255],wave:["#5c8aff","#62a0f0","#6bc4ff"]},mono:{cool:[232,232,238],warm:[148,148,158],wave:["#8a8a96","#b0b0bc","#9a9aa6"]}},pn="warm";var wt=(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,o=Number.parseInt(n.slice(0,6),16);return Number.isNaN(o)?[77,163,255]:[o>>16&255,o>>8&255,o&255]}var gs=[255,224,200],xs=[255,110,80];function co(e,t,n,o,s=gs,i=xs){let a=s[0]+(i[0]-s[0])*t,f=s[1]+(i[1]-s[1])*t,y=s[2]+(i[2]-s[2])*t;return a+=(o[0]-a)*n,f+=(o[1]-f)*n,y+=(o[2]-y)*n,e[0]=a,e[1]=f,e[2]=y,e}function mn([e,t,n]){let o=s=>wt(Math.round(s),0,255).toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(n)}`}function lo(e,t,n){let[o,s,i]=gt(e),[a,f,y]=gt(t),p=n<0?0:n>1?1:n;return mn([o+(a-o)*p,s+(f-s)*p,i+(y-i)*p])}function gn(e,t){if(e.length===0)return[77,163,255];if(e.length===1)return e[0];let n=wt(t,0,1)*(e.length-1),o=Math.min(e.length-2,Math.floor(n)),s=n-o,i=e[o],a=e[o+1];return[i[0]+(a[0]-i[0])*s,i[1]+(a[1]-i[1])*s,i[2]+(a[2]-i[2])*s]}function fo(e,t,n,o=0){if(!(t>0))return 1;let s=Math.max(0,1-e/t),i=1-n*s*s,a=Math.min(Math.max(o,0),1);return i<a?a:i>1?1:i}var Se=1;function ze(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,o=Math.min(t,n),s=e.ux*o,i=e.uy*o,a=e.spin<0?-1:1;return[{x:e.cx+s,y:e.cy+i,q:a},{x:e.cx-s,y:e.cy-i,q:-a}]}function ho(e,t,n){let o=0,s=0;for(let i of e){let a=t-i.x,f=n-i.y,y=Math.max(Se,Math.hypot(a,f)),p=i.q/(y*y);o+=a/y*p,s+=f/y*p}return{x:o,y:s}}function uo(e,t){let n=e/20+(t?.45:0);return n<0?0:n>1?1:n}function yo(e,t,n){return Math.round(e+(t-e)*n)}function po(e,t={}){let n=t.beta??2,o=t.lo??.25,s=t.hi??3,i=e.length,a=new Array(i).fill(1);if(i===0)return a;let f=0,y=0;for(let v of e){let b=v.strength>0?v.strength:0;f+=b,y+=b*(1+(v.on?n:0))}if(f<=0||y<=0)return a;let p=f/y;for(let v=0;v<i;v++){let E=(1+(e[v].on?n:0))*p;E<o?E=o:E>s&&(E=s),a[v]=E}return a}function mo(e,t={}){let n=t.threshold??.55,o=t.kappa??.6,s=t.falloff??320,i=e.length,a=new Array(i).fill(0);if(i<2)return a;let f=new Array(i).fill(0);for(let y=0;y<i;y++){let p=e[y],v=p.d-n;if(v<=0)continue;let b=0;for(let z=0;z<i;z++){if(z===y){f[z]=0;continue}let F=e[z],R=Math.hypot(p.cx-F.cx,p.cy-F.cy),B=R<s?1-R/s:0;f[z]=B,b+=B}if(b<=0)continue;let E=o*v;for(let z=0;z<i;z++){let F=f[z];if(F<=0)continue;let R=E*F/b;a[z]+=R,a[y]-=R}}return a}var Ht={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null};function Zt(e,t,n,o,s){Ht.x=o,Ht.y=s,Ht.vx=0,Ht.vy=0,Ht.heat=0;let i=0,a=0;for(let f of e){if(!f.vis||f.tokens.length===0)continue;let y,p;if(f.shaped){let E=f.cx-f.hw,z=f.cx+f.hw,F=f.cy-f.hh,R=f.cy+f.hh;y=(o<E?E:o>z?z:o)-o,p=(s<F?F:s>R?R:s)-s}else y=f.cx-o,p=f.cy-s;let v=y*y+p*p;if(f.range>0&&v>=f.range*f.range*2.56)continue;let b=Math.sqrt(v);n.dx=y,n.dy=p,n.dist=b<1?1:b;for(let E of f.tokens){let z=t[E];if(!(!z||z.modify))if(z.field){let F=z.field(f,o,s);i+=F.x,a+=F.y}else z.apply(f,Ht,n)}}return{fx:Ht.vx+i,fy:Ht.vy+a}}function Te(e,t,n,o){let s=0,i=0;for(let a of e)if(!(!a.vis||a.tokens.length===0)){if(a.range>0){let f=a.cx-n,y=a.cy-o;if(f*f+y*y>=a.range*a.range*2.56)continue}for(let f of a.tokens){let y=t[f];if(y?.field){let p=y.field(a,n,o);s+=p.x,i+=p.y}}}return{x:s,y:i}}function go(e,t,n={}){return{x:e,y:t,strength:n.strength??1,radius:n.radius&&n.radius>0?n.radius:360}}function ie(e,t,n,o,s=.6){let i=o.x-t,a=o.y-n,f=Math.hypot(i,a);if(f===0||f>=o.radius)return e.x=0,e.y=0,e;let y=(1-f/o.radius)*o.strength*s;return e.x=i/f*y,e.y=a/f*y,e}var vs={step:6,maxSteps:400,minStrength:1e-9,loopDist:6,maxTurns:1/0};function xo(e,t,n,o,s){let i=[{x:t,y:n}],a=t,f=n,y=s.step,p=s.maxTurns*2*Math.PI,v=0,b=0,E=0;for(let z=0;z<s.maxSteps;z++){let F=e(a,f),R=Math.hypot(F.x,F.y);if(!(R>=s.minStrength))break;let B=F.x/R*o,N=F.y/R*o;if(Number.isFinite(p)){if(v!==0||b!==0){let X=Math.max(-1,Math.min(1,B*v+N*b));if(E+=Math.acos(X),E>p)break}v=B,b=N}if(a+=B*s.step,f+=N*s.step,s.bounds&&(a<-y||f<-y||a>s.bounds.w+y||f>s.bounds.h+y))break;if(z>4&&Math.hypot(a-t,f-n)<s.loopDist){i.push({x:a,y:f});break}i.push({x:a,y:f})}return i}function ws(e,t,n,o={}){let s={...vs,bounds:o.bounds,...o},i=xo(e,t,n,-1,s),a=xo(e,t,n,1,s);return i.reverse(),i.pop(),i.concat(a)}function vo(e,t,n={}){return t.map(o=>ws(e,o.x,o.y,n)).filter(o=>o.length>1)}var bs=8,Ms=60;function wo(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},o=ze(n),s=Math.hypot(o[0].x-o[1].x,o[0].y-o[1].y);if(s<Math.max(e.range*.06,bs)){let p=Math.max(e.range*.18,Ms),v=e.spin<0?-1:1;o=[{x:e.cx+e.ux*p,y:e.cy+e.uy*p,q:v},{x:e.cx-e.ux*p,y:e.cy-e.uy*p,q:-v}],s=Math.hypot(o[0].x-o[1].x,o[0].y-o[1].y)}let i=-e.uy,a=e.ux,f=Math.max(s*.13,18),y=[{x:e.cx,y:e.cy}];for(let p=1;p<=t;p++){let v=p*f;y.push({x:e.cx+i*v,y:e.cy+a*v}),y.push({x:e.cx-i*v,y:e.cy-a*v})}return y}function bo(e,t=18){let n=Math.max(Math.min(e.hw,e.hh)*.8,24),o=[];for(let s=0;s<t;s++){let i=s/t*Math.PI*2;o.push({x:e.cx+Math.cos(i)*n,y:e.cy+Math.sin(i)*n})}return o}function Mo(e,t=8){let n=[];for(let o of e)!o.vis||o.tokens.length===0||(o.tokens.includes("magnetism")?n.push(...wo(o,t)):(o.tokens.includes("charge")||o.tokens.includes("gravity"))&&n.push(...bo(o)));return n}function Eo(e,t=Math.random){return 3+Math.floor(t()*(e>0?e:1)*3)}function ko(e,t,n,o=6,s=0){let i=Math.hypot(e,t,s)||1;if(i>=n)return{vx:0,vy:0,vz:0,heat:0};let a=1-i/n,f=a*o;return{vx:e/i*f,vy:t/i*f,vz:s/i*f,heat:a*.9}}function So(e,t,n,o,s=.9,i=80){let a=o>0?o:1;e.vx=(e.vx+t/a)*s,e.vy=(e.vy+n/a)*s,e.x+=e.vx,e.y+=e.vy;let f=Math.hypot(e.x,e.y);f>i&&(e.x=e.x/f*i,e.y=e.y/f*i)}function zo(e,t=.02){return{x:-e.x*t,y:-e.y*t}}function To(e){let t=e/3e4;return t<.6?.6:t>6?6:t}function Fo(e,t,n=-1,o=1600,s=26){let i=0,a=0,f=s*s;for(let y=0;y<t.length;y++){if(y===n)continue;let p=t[y],v=e.x-p.x,b=e.y-p.y,E=v*v+b*b+f;i+=o*v/E,a+=o*b/E}return{x:i,y:a}}function Ao(e,t,n,o=16,s=1){let i=(e(t+o,n)-e(t-o,n))/(2*o),a=(e(t,n+o)-e(t,n-o))/(2*o);return{x:-i*s,y:-a*s}}var Es=[.24,.4,.55,.7,.85];function Co(e){let t=[];for(let n=0;n<5;n++)t.push({baseFrac:Es[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 Po(e,t,n){let o=Math.round(16*t),s=[];for(let i=0;i<e;i++)for(let a=0;a<o;a++)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 Et(e,t,n,o,s=1,i=1,a){let f=e.baseFrac*o+e.offsetY+Math.sin(t*e.freq+e.phase+n*e.speed*1e3*s)*e.amp*i;if(a&&a.k>.001){let y=t-a.x,p=260,v=Math.exp(-(y*y)/(2*p*p));f+=(a.y-f)*.42*v*a.k*(.45+e.depth*.55)}return f}function Oo(e,t,n,o=1,s=1){return Math.cos(t*e.freq+e.phase+n*e.speed*1e3*o)*e.amp*e.freq*s}function ae(e,t,n,o,s=1,i=1){let a=e.baseFrac*o+e.offsetY,f=Math.max(1,Math.round(e.freq*2500));return a+Math.sin(f*t+e.phase+n*e.speed*1e3*s)*e.amp*i}function Ro(e,t,n,o,s,i,a,f,y=1,p=1,v){if(a==="circular"){let b=t-f.x,E=n-f.y,z=Math.sqrt(b*b+E*E)||.001,F=Math.atan2(E,b),R=Math.min(s,i)*.48,B=ae(e,F,o,R,y,p);return{dist:Math.abs(z-B),rWave:B,r:z,theta:F}}else{let b=Et(e,t,o,i,y,p,v);return{dist:Math.abs(n-b),rWave:b,r:n,theta:0}}}function $o(e,t,n,o,s,i,a,f){if(o.length===0)return;let y=e.particles;for(let p=y.length-1;p>=0&&!(t.length>=n);p--){let v=y[p];if(!v||v.cap||v.heat>=.12)continue;let b=-1,E=1e9,z=0;for(let R=0;R<o.length;R++){let B=Et(o[R],v.x,a,i),N=Math.abs(B-v.y);N<E&&(E=N,b=R,z=B)}if(b<0||E>=64)continue;let F=Math.min(.012,E*4e-4)*(1-v.heat/.12);v.vy+=z>v.y?F:-F,E<20&&v.vx*v.vx+v.vy*v.vy<.3&&f()<.03&&(t.push({wi:b,progress:v.x/s,phase:(f()-.5)*.22*Math.PI,size:v.size,glow:f()<.3,speed:(35e-5+f()*9e-4)*(f()<.5?1:-1)}),e.remove(v))}}function xn(e,t,n,o,s,i,a,f,y){for(let p=e.length-1;p>=0;p--){let v=e[p];if(!v)continue;let b=t[v.wi];if(!b)continue;let E=v.progress*i,z=Et(b,E,f,a)+v.phase*32,F=E-n,R=z-o,B=Math.hypot(F,R);if(B<s&&B>.5){let N=(1-B/s)*4;y({x:E,y:z,vx:F/B*N,vy:R/B*N,size:v.size,heat:.9});let X=e.pop();X&&p<e.length&&(e[p]=X)}}}function Io(e,t,n,o,s,i,a,f){let y=p=>p.tokens.some(v=>{let b=o[v];return!!b&&!b.modify&&!b.source});for(let p=e.length-1;p>=0;p--){let v=e[p];if(!v)continue;let b=t[v.wi];if(!b)continue;let E=v.progress*s,z=Et(b,E,a,i)+v.phase*32,F=!1,R=0,B=0;for(let N of n){if(!N.vis||N.when==="active"&&!N.on||N.when&&N.when!=="active")continue;let X=N.tokens,u=N.cx-E,Z=N.cy-z,it=Math.hypot(u,Z)||1,lt=N.range*(N.on?1.4:1);if(X.indexOf("wall")>=0&&Math.abs(E-N.cx)<N.hw+6&&Math.abs(z-N.cy)<N.hh+6&&(R=(E<N.cx?-1:1)*1.6,B=(z<N.cy?-1:1)*.8,F=!0),!F&&(X.indexOf("attract")>=0||X.indexOf("sink")>=0||X.indexOf("jet")>=0)&&it<lt*.8){let D=1.2+(N.on?1.6:0);R=u/it*D,B=Z/it*D,F=!0}if(!F&&X.indexOf("repel")>=0&&it<lt*.8){let D=1.2+(N.on?1.2:0);R=-(u/it)*D,B=-(Z/it)*D,F=!0}if(!F&&X.indexOf("swirl")>=0&&it<lt*.75&&(R=Z/it*1.2,B=-(u/it)*1.2,F=!0),!F&&X.indexOf("stream")>=0&&it<lt*.75&&(R=N.ux*1.3,B=N.uy*1.3,F=!0),!F&&it<lt*.8&&y(N)){let D=.8+(N.on?.8:0);R=u/it*D,B=Z/it*D,F=!0}if(F)break}if(F){f({x:E,y:z,vx:R,vy:B,size:v.size,heat:.5});let N=e.pop();N&&p<e.length&&(e[p]=N)}}}function No(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 o=n.range*n.range;for(let s of t){if(s.charge)continue;let i=n.cx-s.x,a=n.cy-s.y;i*i+a*a>=o||(s.charge=i>=0?1:-1)}}}var Fe=class{constructor(t=64){U(this,"cell");U(this,"bins",new Map);this.cell=t>0?t:64}key(t,n){return(t+32768)*65536+(n+32768)}clear(){this.bins.clear()}insert(t){let n=this.key(Math.floor(t.x/this.cell),Math.floor(t.y/this.cell)),o=this.bins.get(n);o?o.push(t):this.bins.set(n,[t])}rebuild(t){this.clear();for(let n of t)this.insert(n)}near(t,n,o,s=0){let i=[],a=o*o,f=Math.floor((t-o)/this.cell),y=Math.floor((t+o)/this.cell),p=Math.floor((n-o)/this.cell),v=Math.floor((n+o)/this.cell);for(let b=f;b<=y;b++)for(let E=p;E<=v;E++){let z=this.bins.get(this.key(b,E));if(z)for(let F of z){let R=F.x-t,B=F.y-n,N=(F.z??0)-s;R*R+B*B+N*N<=a&&i.push(F)}}return i}};var Lo=e=>e<0?0:e>1?1:e;function Do(e){if(!e||e.n===0)return{entropy:0,coherence:1,temperature:0};let t=e.sh/e.n,n=e.ss/e.n,o=e.ss2/e.n,s=Lo(.5*t+.5*Math.min(1,o/9)),i=e.ss>1e-9?Math.hypot(e.sx,e.sy)/e.ss:1,a=Lo((1-i)*Math.min(1,n/1.5));return{entropy:a,coherence:1-a,temperature:s}}var Ae=class{constructor(t=64){U(this,"particles",[]);U(this,"hash");this.hash=new Fe(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 o=this.particles.pop();o&&n<this.particles.length&&(this.particles[n]=o)}clear(){this.particles.length=0,this.hash.clear()}reindex(){this.hash.rebuild(this.particles)}neighbors(t,n){let o=this.hash.near(t.x,t.y,n,t.z??0),s=[];for(let i of o)i!==t&&s.push(i);return s}near(t,n,o){return this.hash.near(t,n,o)}};var _o={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};var Ce=class{constructor(){U(this,"pending",new Map);U(this,"ids",new WeakMap);U(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==="met"){let s=n,[i,a]=[this.idOf(s.a.el??s.a),this.idOf(s.b.el??s.b)].sort((f,y)=>f-y);return`${i}:${a}`}if(t==="enter"||t==="exit"){let s=n;return`${this.idOf(s.body.el??s.body)}:${this.idOf(s.other.el??s.other)}`}let o=n;return String(this.idOf(o.body.el??o.body))}record(t,n){let o=this.pending.get(t);o||this.pending.set(t,o=new Map),o.set(this.keyOf(t,n),n)}flush(t){if(this.pending.size!==0){for(let[n,o]of this.pending)for(let s of o.values())t(n,s);this.pending.clear()}}};function vn(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 wn(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}}function Bo(){let e={},t={..._o};return{forces:e,conditions:t,force(n){e[n.token]=n},condition(n,o){t[n]=o}}}function Wo(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 Ho(e){for(let t of e)if(t.vis&&t.tokens.indexOf("sink")>=0)return t;return null}var bn=.95,ks=.972,St=10;function Ss(e,t,n,o){if(!t.when)return!0;let s=e[t.when];return s?s(t,n,o):!0}function qo(e){return e.classified??(e.classified=Me(e.tokens))}function Mn(e,t,n,o,s){if(s===1||e.kinematic){e.apply(t,n,o);return}let i=n.vx,a=n.vy,f=n.vz??0;e.apply(t,n,o),n.vx=i+(n.vx-i)*s,n.vy=a+(n.vy-a)*s,n.vz!==void 0&&(n.vz=f+(n.vz-f)*s)}function Yo(e){let{store:t,bodies:n,env:o,forces:s,conditions:i,waves:a,separation:f}=e,y=o.dt;if(y===0)return;let{W:p,H:v,form:b}=o;o.fieldAt=(u,Z)=>Te(n,s,u,Z);for(let u of n){u.count=0;let Z=u.thermo;Z&&(Z.n=0,Z.sx=0,Z.sy=0,Z.ss=0,Z.ss2=0,Z.sh=0)}let E=null;for(let u of n)u.vis&&u.tokens.length>0&&qo(u).modifiers.indexOf("screen")>=0&&(E??(E=[])).push(u);let z=E?new Array(E.length):null,F=!!a&&a.length>0,R=n.length>0,B=null,N=b.conv>.02?Ho(n):null,X=o.D??0;for(let u of t.particles){if(u.cap){u.x+=(u.cap.cx-u.x)*.18,u.y+=(u.cap.cy-u.y)*.18,u.z&&(u.z+=-u.z*.18);continue}u.z===void 0&&(u.z=0),u.vz===void 0&&(u.vz=0);let Z=u.z;if(F)if(e.waveStyle==="circular"){let D=null,A=1e9,j=0,J=0,dt=0,_=e.waveCenter||{x:p/2,y:v/2};for(let tt of a){let yt=Ro(tt,u.x,u.y,o.t,p,v,"circular",_);yt.dist<A&&(A=yt.dist,D=tt,j=yt.r,J=yt.rWave,dt=yt.theta)}if(D&&A<70){let tt=1-A/70,yt=-Math.sin(dt)*D.dir,Rt=Math.cos(dt)*D.dir;u.vx+=yt*.035*tt,u.vy+=Rt*.035*tt;let O=Math.cos(dt)*Math.sign(J-j),K=Math.sin(dt)*Math.sign(J-j);u.vx+=O*.05*tt,u.vy+=K*.05*tt}}else{let D=null,A=1e9;for(let j of a){let J=Math.abs(Et(j,u.x,o.t,v)-u.y);J<A&&(A=J,D=j)}D&&A<70&&(u.vx+=D.dir*.035*(1-A/70),u.vy+=Oo(D,u.x,o.t)*.1*(1-A/70))}if(b.driftX&&(u.vx+=b.driftX*.02),b.spread>.02){let D=u.gx??.5,A=u.gy??.5,j=(D+o.frameN*4e-5)%1*p,J=A*v;u.vx+=(j-u.x)*6e-4*b.spread,u.vy+=(J-u.y)*6e-4*b.spread,X>0&&(u.vz+=((u.gz??.5)*X-Z)*6e-4*b.spread)}if(N){let D=N.cx-u.x,A=N.cy-u.y,j=-Z,J=Math.hypot(D,A,j)||1;u.vx+=D/J*b.conv*.06,u.vy+=A/J*b.conv*.06,u.vz+=j/J*b.conv*.06}if(R){if(E)for(let A=0;A<E.length;A++){let j=E[A],J=j.cx-u.x,dt=j.cy-u.y;z[A]=fo(Math.sqrt(J*J+dt*dt),j.range,j.strength,j.screenMin??0)}let D=u.m!==1&&u.m>0?1/u.m:1;for(let A of n){if(!A.vis||A.tokens.length===0||A.affects!==void 0&&!A.affects.has(u.species??0))continue;let j,J;if(A.shaped){let Y=A.cx-A.hw,Q=A.cx+A.hw,at=A.cy-A.hh,Ut=A.cy+A.hh,ee=u.x<Y?Y:u.x>Q?Q:u.x,fe=u.y<at?at:u.y>Ut?Ut:u.y;j=ee-u.x,J=fe-u.y}else j=A.cx-u.x,J=A.cy-u.y;let dt=-u.z,_=j*j+J*J+dt*dt;if(A.range>0&&_>=A.range*A.range*2.56)continue;let tt=Math.sqrt(_);if(A.feedback&&tt<A.range*.5){A.count+=1-tt/(A.range*.5);let Y=A.thermo??(A.thermo={n:0,sx:0,sy:0,ss:0,ss2:0,sh:0}),Q=u.vx*u.vx+u.vy*u.vy;Y.n++,Y.sx+=u.vx,Y.sy+=u.vy,Y.ss+=Math.sqrt(Q),Y.ss2+=Q,Y.sh+=u.heat}if(A.when&&!Ss(i,A,u,o))continue;o.dx=j,o.dy=J,o.dz=dt,o.dist=tt<1?1:tt;let yt=qo(A),Rt=1,O=!1,K=!1;for(let Y of yt.modifiers){let Q=s[Y]?.modify;if(!Q)continue;K=!0;let at=Q(A,u,o);at.strength!=null&&(Rt*=at.strength),at.gate&&(O=!0)}for(let Y of yt.forces){let Q=s[Y]?.modify;if(!Q)continue;K=!0;let at=Q(A,u,o);at.strength!=null&&(Rt*=at.strength),at.gate&&(O=!0)}if(O)continue;let L=1;if(E)for(let Y=0;Y<E.length;Y++)E[Y]!==A&&(L*=z[Y]);let I=A.attn??1,$=Rt*I*L;if(!K&&$===1)for(let Y of A.tokens){let Q=s[Y];Q&&Mn(Q,A,u,o,D)}else if(K){let Y=A.strength;A.strength=Y*$;for(let Q of A.tokens){let at=s[Q];at&&!at.modify&&Mn(at,A,u,o,D)}A.strength=Y}else{let Y=A.strength;A.strength=Y*$;for(let Q of A.tokens){let at=s[Q];at&&Mn(at,A,u,o,D)}A.strength=Y}}}if(f&&f>0){let D=o.neighbors(u,12);for(let A of D){let j=u.x-A.x,J=u.y-A.y,dt=(u.z??0)-(A.z??0),_=Math.hypot(j,J,dt)||.1;if(_<12){let tt=(12-_)/12*f*.12;u.vx+=j/_*tt,u.vy+=J/_*tt,u.vz!==void 0&&(u.vz+=dt/_*tt)}}}let it=o.c,lt=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(lt>it*it){let D=it/Math.sqrt(lt);u.vx*=D,u.vy*=D,u.vz*=D}if(u.maxSpeed!==void 0){let D=u.maxSpeed*u.maxSpeed,A=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(A>D){let j=u.maxSpeed/Math.sqrt(A);u.vx*=j,u.vy*=j,u.vz*=j}}if(u.x+=u.vx*y,u.y+=u.vy*y,u.z+=u.vz*y,u.vx*=bn,u.vy*=bn,u.vz*=bn,u.report===void 0){if(o.frameN%40===0&&b.wander>0){let D=.05*b.wander;u.vx+=((o.rng??Math.random)()-.5)*D,u.vy+=((o.rng??Math.random)()-.5)*D,X>0&&(u.vz+=((o.rng??Math.random)()-.5)*D)}if(b.wander>.05){let D=(Math.sin(u.x*.0032+o.t*.12)+Math.cos(u.y*.0034-o.t*.15))*Math.PI;u.vx+=Math.cos(D)*.013*b.wander,u.vy+=Math.sin(D)*.013*b.wander}}u.heat*=ks,u.age!=null&&(u.age-=y,u.age<=0&&(B??(B=[])).push(u)),u.report===void 0?(u.x<-St?u.x=p+St:u.x>p+St&&(u.x=-St),u.y<-St?u.y=v+St:u.y>v+St&&(u.y=-St),X>0&&(u.z<-St?u.z=X+St:u.z>X+St&&(u.z=-St))):(u.x<0?(u.x=0,u.vx=Math.abs(u.vx)):u.x>p&&(u.x=p,u.vx=-Math.abs(u.vx)),u.y<0?(u.y=0,u.vy=Math.abs(u.vy)):u.y>v&&(u.y=v,u.vy=-Math.abs(u.vy)),X>0&&(u.z<0?(u.z=0,u.vz=Math.abs(u.vz)):u.z>X&&(u.z=X,u.vz=-Math.abs(u.vz))),u.report(u))}if(R){for(let u of n)if(!(!u.vis||u.tokens.length===0))for(let Z of u.tokens)s[Z]?.source?.(u,o)}if(B)for(let u of B)t.remove(u)}var Uo={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 zs(){return globalThis.process?.env?.NODE_ENV!=="production"}var Vo=zs();function jo(){return Vo}var Go=new Set;function En(e,t){if(!Vo)return;let n=`${e}:${t}`;Go.has(n)||(Go.add(n),console.warn(`[Fundamental:${e}] ${t}`))}var Ts={"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 Xo(e,t={}){let n=Ts[e];if(!n)return null;let o=[...n.body];t.risk==="high"&&!o.includes("thermal")&&o.push("thermal");let s={"data-body":o.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:o.join(" "),strength:t.intensity,range:n.range,feedback:n.feedback??!1,render:n.render??["particles"],attributes:s}}function Ko(e){let t=(z,F)=>{let R=Number.parseFloat(e.get(z)??"");return Number.isFinite(R)?R:F},n=t("strength",.5),o=t("angle",0)*Math.PI/180,s=e.get("spin"),i=s==null?1:Number.isFinite(Number.parseFloat(s))?Number.parseFloat(s):0,a=(e.get("body")??"").split(/\s+/).filter(Boolean),f=Me(a),y=e.get("life"),p=e.get("cap"),v=Number.parseFloat(y??""),b=Number.parseFloat(p??""),E=y!=null||p!=null||e.has("budget")||e.has("sink");return{tokens:a,classified:f,...Number.isFinite(v)&&v>0?{life:v}:{},...Number.isFinite(b)&&b>0?{cap:b}:{},budgeted:E,strength:n,range:t("range",280),absorbR:t("absorb",64),capacity:t("max",60),spin:i,angle:o,ux:Math.cos(o),uy:Math.sin(o),when:e.get("when")??"",feedback:e.has("feedback"),shaped:e.has("shaped"),...e.get("species")!=null&&Number.isFinite(Number.parseFloat(e.get("species")))?{species:Number.parseFloat(e.get("species"))}:{},...(()=>{let z=e.get("affects");if(z==null)return{};let F=z.split(",").map(R=>Number.parseFloat(R.trim())).filter(R=>Number.isFinite(R));return F.length?{affects:new Set(F)}:{}})(),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 Fs(e){let t={body:e.body};return e.strength!=null&&(t.strength=String(e.strength)),e.range!=null&&(t.range=String(e.range)),e.spin!=null&&(t.spin=String(e.spin)),e.angle!=null&&(t.angle=String(e.angle)),e.absorb!=null&&(t.absorb=String(e.absorb)),e.max!=null&&(t.max=String(e.max)),e.life!=null&&(t.life=String(e.life)),e.cap!=null&&(t.cap=String(e.cap)),{get:n=>t[n]??null,has:n=>n in t}}function As(e){let t=Uo[e];return t?t.map(n=>Ko(Fs(n))):[]}function Cs(e){let t=(e.tagName??"element").toLowerCase(),n=e.id?`#${e.id}`:"",o=typeof e.className=="string"&&e.className?`.${e.className.split(/\s+/)[0]}`:"";return`<${t}${n}${o}>`}function Ps(e,t="<body>"){!e.classified||e.classified.sources.length===0||e.budgeted||(e.life=hn,e.cap=un,jo()&&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="${hn}", data-cap="${un}") \u2014 declare one to make the source's budget explicit (workover v0.3 source rules).`))}function Qo(e,t){return Ps(t,Cs(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 Os(e){return{get:t=>e.getAttribute("data-"+t),has:t=>e.hasAttribute("data-"+t)}}function ce(e,t){return Qo(e,Ko(t??Os(e)))}var Jo={source:"jet",sink:"sink",anchor:"tether",boundary:"wall",sensor:"",display:""};function Rs(e){let t=null,n=e.getAttribute("data-intent");if(n){let s=e.getAttribute("data-intensity"),i=Xo(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 Jo&&(t={body:Jo[s],feedback:""})}if(!t)return null;let o=t;return{get:s=>e.getAttribute("data-"+s)??o[s]??null,has:s=>e.hasAttribute("data-"+s)||s in o}}function Zo(e){let t=[];return e.querySelectorAll("[data-body]").forEach(n=>{t.push(ce(n))}),e.querySelectorAll("[data-preset]").forEach(n=>{let o=n;for(let s of As(o.dataset.preset??""))t.push(Qo(o,s))}),e.querySelectorAll("[data-intent]:not([data-body]), [data-field-role]:not([data-body]):not([data-intent])").forEach(n=>{let o=Rs(n);o&&t.push(ce(n,o))}),t}function $s(e){let t=e.el;if(typeof t.getAttribute!="function")return;let n=t.getAttribute("data-strength");if(n!=null){let a=Number.parseFloat(n);Number.isFinite(a)&&(e.strength=a,e.M=a)}let o=t.getAttribute("data-range");if(o!=null){let a=Number.parseFloat(o);Number.isFinite(a)&&(e.range=a)}let s=t.getAttribute("data-spin");if(s!=null){let a=Number.parseFloat(s);Number.isFinite(a)&&(e.spin=a)}let i=t.getAttribute("data-angle");if(i!=null){let a=Number.parseFloat(i);Number.isFinite(a)&&(e.angle=a*Math.PI/180,e.ux=Math.cos(e.angle),e.uy=Math.sin(e.angle))}}function Pe(e,t,n,o=0,s=0){let i=n*.15;for(let a of e){let f=a.rect?a.rect():a.el.getBoundingClientRect(),y=f.left-o,p=f.top-s;a.cx=y+f.width/2,a.cy=p+f.height/2,a.hw=f.width/2,a.hh=f.height/2,a.on=a.el.dataset.active==="1",a.vis=p+f.height>-i&&p<n+i&&y+f.width>-i&&y<t+i,$s(a)}}var tr="field:register-body",er="field:unregister-body",nr="field:update-body";var Oe=class{constructor(){U(this,"hosts",new Map)}register(t){this.hosts.set(t.element,t)}unregister(t){this.hosts.delete(t)}get size(){return this.hosts.size}bodies(t){let n=[];for(let[o,s]of this.hosts){if(!o.isConnected){this.hosts.delete(o);continue}let i=s.attrs?Is(s.attrs,o):void 0,a=t(o,i);s.getRect&&(a.rect=s.getRect),s.writeTarget&&(a.writeTarget=s.writeTarget),n.push(a)}return n}};function Is(e,t){return{get:n=>e[n]??t.getAttribute("data-"+n),has:n=>n in e||t.hasAttribute("data-"+n)}}function rr(e,t,n=.12){return e>=t?0:(1-e/t)*n}function Re(e,t,n){if(e===t)return .5;let o=(n-e)/(t-e);return o<0?0:o>1?1:o}var or=Object.freeze([]);function kn(e,t,n,o,s){let i={x:Re(e,t,s),y:0},a={x:1,y:Re(t,n,s)},f={x:Re(o,n,s),y:1},y={x:0,y:Re(e,o,s)},p=(b,E)=>({x1:b.x,y1:b.y,x2:E.x,y2:E.y});switch((e>s?8:0)|(t>s?4:0)|(n>s?2:0)|(o>s?1:0)){case 0:case 15:return or;case 1:case 14:return[p(y,f)];case 2:case 13:return[p(f,a)];case 3:case 12:return[p(y,a)];case 4:case 11:return[p(i,a)];case 6:case 9:return[p(i,f)];case 7:case 8:return[p(y,i)];case 5:return[p(y,i),p(f,a)];case 10:return[p(y,f),p(i,a)];default:return or}}function Sn(e,t,n,o,s,i,a,f=1){if(a<=0)return;let y=Math.max(0,Math.floor((s-a)/o)),p=Math.min(t-1,Math.ceil((s+a)/o)),v=Math.max(0,Math.floor((i-a)/o)),b=Math.min(n-1,Math.ceil((i+a)/o)),E=a*a;for(let z=v;z<=b;z++)for(let F=y;F<=p;F++){let R=F*o-s,B=z*o-i,N=R*R+B*B;if(N>=E)continue;let X=1-Math.sqrt(N)/a,u=z*t+F;e[u]=e[u]+f*X*X}}function sr(e,t,n){let o=-1,s=1/0;for(let i=0;i<n.length;i++){let a=n[i],f=a.x-e,y=a.y-t,p=f*f+y*y;p<s&&(s=p,o=i)}return o}function ir(e,t,n){let o=[];for(let s=0;s<n;s++)for(let i=0;i<t;i++){let a=e[s*t+i];i+1<t&&e[s*t+i+1]!==a&&o.push({x1:i+.5,y1:s-.5,x2:i+.5,y2:s+.5}),s+1<n&&e[(s+1)*t+i]!==a&&o.push({x1:i-.5,y1:s+.5,x2:i+.5,y2:s+.5})}return o}var te=class{constructor(t,n,o="diffuse",s=32){U(this,"mode");U(this,"cell");U(this,"W");U(this,"H");U(this,"cols");U(this,"rows");U(this,"cur");U(this,"nxt");U(this,"prev");this.W=t,this.H=n,this.mode=o,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 o=t/this.cell,s=n/this.cell,i=Math.floor(o),a=Math.floor(s),f=o-i,y=s-a,p=this.at(i,a)*(1-f)+this.at(i+1,a)*f,v=this.at(i,a+1)*(1-f)+this.at(i+1,a+1)*f;return p*(1-y)+v*y}deposit(t,n,o){let s=this.clampCol(Math.round(t/this.cell)),i=this.clampRow(Math.round(n/this.cell));this.cur[i*this.cols+s]+=o}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 o=this.cell;return{x:(this.sample(t+o,n)-this.sample(t-o,n))/(2*o),y:(this.sample(t,n+o)-this.sample(t,n-o))/(2*o)}}step(){this.mode==="wave"?this.stepWave():this.mode==="memory"?this.stepDiffuse(.03,.004):this.stepDiffuse()}stepDiffuse(t=.18,n=.01){let o=t<0?0:t>.24?.24:t,s=1-n,{cols:i,rows:a,cur:f,nxt:y}=this;for(let p=0;p<a;p++)for(let v=0;v<i;v++){let b=p*i+v,E=this.at(v-1,p)+this.at(v+1,p)+this.at(v,p-1)+this.at(v,p+1)-4*f[b];y[b]=(f[b]+o*E)*s}this.cur=y,this.nxt=f}stepWave(t=.25,n=.002){let o=t<0?0:t>.5?.5:t,s=1-n,{cols:i,rows:a,cur:f,prev:y,nxt:p}=this;for(let v=0;v<a;v++)for(let b=0;b<i;b++){let E=v*i+b,z=this.at(b-1,v)+this.at(b+1,v)+this.at(b,v-1)+this.at(b,v+1)-4*f[E];p[E]=(2*f[E]-y[E]+o*z)*s}this.prev=f,this.cur=p,this.nxt=y}decay(t){let n=t<=0?1:t>=1?0:1-t;if(n!==1)for(let o=0;o<this.cur.length;o++)this.cur[o]*=n}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 o=this.cols*this.rows;this.cur=new Float32Array(o),this.nxt=new Float32Array(o),this.prev=new Float32Array(o)}};var ar=24,Ns=.12,Ls=.22,le=class{constructor(t,n){U(this,"grid");U(this,"peak",.001);U(this,"cell",ar);this.grid=new te(Math.max(1,t),Math.max(1,n),"diffuse",ar)}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(Ls,Ns);let n=this.grid.max(),o=n>this.peak?.25:.03;this.peak+=(Math.max(n,.001)-this.peak)*o}norm(t,n){return wt(this.grid.sample(t,n)/this.peak,0,1)}gradient(t,n){if(this.peak<=0)return{x:0,y:0};let o=this.grid.gradient(t,n);return{x:o.x/this.peak,y:o.y/this.peak}}};var Ds={position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"0",pointerEvents:"none",display:"block"},cr=Object.entries(Ds).map(([e,t])=>`${e.replace(/[A-Z]/g,n=>"-"+n.toLowerCase())}:${t}`).join(";");function _s(e){let t=e.width,n=e.height,o=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:a=>(o=a,1),cancelRaf:()=>{o=null},createCanvas:()=>{throw new Error("headlessHost does not render \u2014 use render:'none' and the signal read-outs (onFeedback / sampleScalar / readParticles).")},onResize:()=>()=>{},onScroll:()=>()=>{},onVisibility:()=>()=>{},onInput:()=>()=>{},onBodyEvent:()=>()=>{},tick(a){s=a??s+1e3/60;let f=o;o=null,f?.(s)},resize(a,f){t=a,n=f}}}var lr="10px ui-monospace, SFMono-Regular, Menlo, monospace";function zn(e,t){let n=0,o=0;return{size(s,i,a){n=s,o=i,e.width=Math.floor(s*a),e.height=Math.floor(i*a),t.setTransform(a,0,0,a,0,0)},clear(){t.clearRect(0,0,n,o)},segments(s,i){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath();for(let a=0;a+3<s.length;a+=4)t.moveTo(s[a],s[a+1]),t.lineTo(s[a+2],s[a+3]);t.stroke()},polyline(s,i){if(!(s.length<4)){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath(),t.moveTo(s[0],s[1]);for(let a=2;a+1<s.length;a+=2)t.lineTo(s[a],s[a+1]);t.stroke()}},rect(s,i,a,f,y,p,v,b){t.fillStyle=`rgba(${y},${p},${v},${b})`,t.fillRect(s,i,a,f)},text(s,i,a,f,y,p,v){t.font=lr,t.textBaseline="middle",t.fillStyle=`rgba(${f},${y},${p},${v})`,t.fillText(s,i,a)},measureText(s){return t.font=lr,t.measureText(s).width}}}var Tn=(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),e.style.setProperty("--mass",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 o=e.dataset.fxLit==="1";n>.5&&!o?(e.dataset.fxLit="1",e.dispatchEvent(new CustomEvent("field:lit",{detail:{value:n}}))):n<.4&&o&&(e.dataset.fxLit="0",e.dispatchEvent(new CustomEvent("field:dim",{detail:{value:n}})))}},dr=Tn;var $e=class{constructor(t){U(this,"lit",!1);U(this,"lastEdgeMs",-1/0);U(this,"cfg");this.cfg=t}update(t,n){let o=n-this.lastEdgeMs>=this.cfg.debounceMs;return!this.lit&&t>=this.cfg.enter&&o?(this.lit=!0,this.lastEdgeMs=n,"entered"):this.lit&&t<=this.cfg.exit&&o?(this.lit=!1,this.lastEdgeMs=n,"exited"):null}get isLit(){return this.lit}reset(){this.lit=!1,this.lastEdgeMs=-1/0}};var Bs={strengthen:1.5,decay:.3,remember:.2},Fn=e=>e<0?0:e>1?1:e;function fr(e,t,n,o,s=Bs){e.active=t,e.tension=Fn(n),e.strength=Fn(e.strength+(t?s.strengthen:-s.decay)*o),e.memory=Fn(e.memory+(t?s.remember:-s.remember*.5)*o)}function hr(e,t,n=Math.random){let o=[],s=t.absorbR+6;for(let i of e){if(i.cap!==t)continue;let a=n()*Math.PI*2,f=4+n()*3;i.cap=null,i.x=t.cx+Math.cos(a)*s,i.y=t.cy+Math.sin(a)*s,i.vx=Math.cos(a)*f,i.vy=Math.sin(a)*f,i.z&&(i.z=0),i.vz&&(i.vz=0),i.heat=1,i.age=void 0,o.push(i)}return t.accreted=0,o}function An(e){if(e.capacity<=0)return 0;let t=e.accreted/e.capacity;return t<0?0:t>1?1:t}function ur(e,t){return t&&!e?{fire:"captured",armed:!0}:!t&&e?{fire:"released",armed:!1}:{fire:null,armed:e}}function yr(e,t){let n=[];for(let o of e)o.when!=="active"||!o.tokens.includes("sink")||(o.wasOn&&!o.on&&o.accreted>0&&(t(o),n.push(o)),o.wasOn=o.on);return n}function Cn(e,t){let n=t.cx-e.x,o=t.cy-e.y;return n*n+o*o<t.absorbR*t.absorbR}function pr(e,t,n=.14){let o=e+(t-e)*n;return o<.001?0:o>.999?1:o}function mr(e,t,n,o){let s=e.x+t.x,i=e.y+t.y,a=t.x+(n.x-s)*o,f=t.y+(n.y-i)*o,y=1-o;return{tx:a,ty:f,scale:y,opacity:y}}var Ws={token:"attract",label:"Attract",apply(e,t,n){let o=e.range*(e.on?1.5:1),s=e.strength*(e.on?3:1);if(n.dist>=o)return;let i=(1-n.dist/o)**2*s*.5,a=n.dx/n.dist,f=n.dy/n.dist;t.vx+=a*i,t.vy+=f*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i),n.form.orbit&&(t.vx+=-f*i*n.form.orbit,t.vy+=a*i*n.form.orbit),e.on&&(t.heat=Math.max(t.heat,(1-n.dist/o)*.9))},meta:{desc:"a soft gravity-like well, bent into a spiral"}},Hs={token:"repel",label:"Repel",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**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"}},qs={token:"swirl",label:"Swirl",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**1.4*s*.45,a=e.spin,f=n.dx/n.dist,y=n.dy/n.dist;t.vx+=y*i*a+f*i*.12,t.vy+=-f*i*a+y*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/o)*.6))},meta:{desc:"tangential swirl with light inward retention"}},Ys={token:"stream",label:"Stream",apply(e,t,n){let o=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=o)return;let i=(1-n.dist/o)**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/o)*.5))},meta:{desc:"directional current along a heading"}},Us={token:"viscosity",label:"Viscosity",apply(e,t,n){let o=e.range*(e.on?1.4:1);if(n.dist>=o)return;let s=(1-n.dist/o)*(.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"}},Gs={token:"jet",label:"Jet",kinematic:!0,apply(e,t,n){let o=e.range*(e.on?1.4:1);if(!(n.dist>=o))if(n.dist<24){let s=((n.rng??Math.random)()-.5)*.8,i=Math.cos(s),a=Math.sin(s),f=e.ux*i-e.uy*a,y=e.ux*a+e.uy*i,p=2.4+e.strength*2.6;t.vx=f*p,t.vy=y*p,t.x=e.cx+f*26,t.y=e.cy+y*26,t.z&&(t.z=0),t.vz&&(t.vz=0),t.heat=Math.max(t.heat,.9)}else{let s=(1-n.dist/o)**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"}},Vs={token:"tether",label:"Tether",apply(e,t,n){let o=e.range*.6*(e.on?1.25:1),s=o*2.1;if(n.dist>=s)return;let i=(.006+e.strength*.012)*(e.on?1.7:1),a=n.dist-o,f=n.dx/n.dist,y=n.dy/n.dist;t.vx+=f*a*i,t.vy+=y*a*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*a*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(a)/o))*.5))},meta:{desc:"a tether with a rest length \u2014 holds matter at a fixed radius"}},js={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 a=Math.hypot(t.vx,t.vy),f=e.hw+6-s,y=e.hh+6-i;f<y?(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),a>.7&&(n.spark(t.x,t.y,Math.min(2.4,a),e.tint??so.wall.color),t.heat=Math.max(t.heat,Math.min(.85,a*.4)))},meta:{desc:"axis-aligned bouncing wall \u2014 sparks on impact"}},Xs={token:"sink",label:"Sink",apply(e,t,n){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"}},Js=[Ws,Gs,Vs,js,Ys,Hs,Us,qs,Xs];function gr(e){for(let t of Js)e.force(t)}var On=1.5,Ks=8,Qs=60;function Zs(e,t,n,o){let s=ze(e);if(Math.hypot(s[0].x-s[1].x,s[0].y-s[1].y)<Math.max(e.range*.06,Ks)){let y=Math.max(e.range*.18,Qs),p=e.spin<0?-1:1;s=[{x:e.cx+e.ux*y,y:e.cy+e.uy*y,q:p},{x:e.cx-e.ux*y,y:e.cy-e.uy*y,q:-p}]}let a=o*(1+On*(e.d??0)),f=ho(s,t,n);return{x:f.x*a,y:f.y*a}}function ti(e,t,n,o){let s=t-e.cx,i=n-e.cy,a=Math.max(Math.hypot(s,i),Se),y=(e.spin<0?-1:1)*o*(1+On*(e.d??0))/(a*a);return{x:s/a*y,y:i/a*y}}function xr(e,t,n,o){if(n.dist>=e.range)return;let s=2*n.G*e.M/(n.c*n.c),i=o/(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),Rn(t,n.c)}function Rn(e,t){let n=e.vz??0,o=Math.hypot(e.vx,e.vy,n);o>t&&(e.vx=e.vx/o*t,e.vy=e.vy/o*t,n&&(e.vz=n/o*t))}function ei(e,t,n){let o=e.cx-t,s=e.cy-n,i=Math.max(Math.hypot(o,s),Se),a=e.M*(1+On*(e.d??0))/(i*i);return{x:o/i*a,y:s/i*a}}var ni={token:"gravity",label:"Gravity",apply(e,t,n){xr(e,t,n,n.G*e.M)},field:(e,t,n)=>ei(e,t,n),meta:{desc:"true softened inverse-square gravity (a real 1/d\xB2 law)"}},oi={token:"charge",label:"Charge",apply(e,t,n){let o=t.charge??0;o!==0&&xr(e,t,n,-(e.spin*o*n.G*e.M))},field:(e,t,n)=>ti(e,t,n,e.M),meta:{desc:"signed inverse-square \u2014 like repels, opposite attracts"}},ri={token:"magnetism",label:"Magnetism",apply(e,t,n){if(n.dist>=e.range)return;let o=t.charge??0;if(o===0)return;let s=1-n.dist/e.range,i=o*e.spin*e.strength*s,a=Math.cos(i),f=Math.sin(i),y=t.vx;t.vx=y*a-t.vy*f,t.vy=y*f+t.vy*a},field:(e,t,n)=>Zs(e,t,n,e.strength),meta:{desc:"Lorentz force \u2014 curves a moving charge perpendicular to its velocity"}};function si(e){return Math.sqrt(2*Math.max(0,e))}var ii={token:"thermal",label:"Thermal",apply(e,t,n){if(n.dist>=e.range)return;let o=1-n.dist/e.range,s=si(e.strength*o);if(s===0)return;let i=Math.random()||1e-9,a=s*Math.sqrt(-2*Math.log(i)),f=2*Math.PI*Math.random();if(t.vx+=a*Math.cos(f),t.vy+=a*Math.sin(f),n.D){let y=Math.random()||1e-9;t.vz=(t.vz??0)+s*Math.sqrt(-2*Math.log(y))*Math.cos(2*Math.PI*Math.random())}e.on&&(t.heat=Math.max(t.heat,o*.4)),Rn(t,n.c)},meta:{desc:"Langevin/Brownian agitation \u2014 a real temperature in the medium"}},ai={token:"collide",label:"Collide",apply(e,t,n){if(n.dist>=e.range)return;let o=Math.max(0,Math.min(1,e.strength)),s=Math.max(1,t.size);for(let i of n.neighbors(t,s*4)){let a=Math.max(1,i.size),f=t.x-i.x,y=t.y-i.y,p=(t.z??0)-(i.z??0),v=Math.hypot(f,y,p);if(v>=s+a||v<1e-6)continue;let b=f/v,E=y/v,z=p/v,F=(t.vx-i.vx)*b+(t.vy-i.vy)*E+((t.vz??0)-(i.vz??0))*z;if(F>=0)continue;let R=(1+o)*.5*F;t.vx-=R*b,t.vy-=R*E,i.vx+=R*b,i.vy+=R*E,p&&(t.vz=(t.vz??0)-R*z,i.vz=(i.vz??0)+R*z)}},meta:{desc:"elastic pairwise collision \u2014 the hard-sphere billiard force"}},ci={token:"diffuse",label:"Diffuse",apply(e,t,n){if(n.dist>=e.range)return;let o=n.grid("diffuse");o.deposit(t.x,t.y,e.strength);let s=o.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"}},li=12,Pn=7,di={token:"propagate",label:"Propagate",source(e,t){e.on&&t.frameN%li===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 a=-n.dx/n.dist,f=-n.dy/n.dist;t.vx+=a*i*e.strength*Pn,t.vy+=f*i*e.strength*Pn,n.dz&&(t.vz=(t.vz??0)+-n.dz/n.dist*i*e.strength*Pn),Rn(t,n.c)},meta:{desc:"a travelling wave \u2014 a shock train expands from the source, sweeping matter out"}},fi={token:"memory",label:"Memory",apply(e,t,n){if(n.dist>=e.range)return;let o=n.grid("memory");o.deposit(t.x,t.y,e.strength*.15);let s=1+.5*o.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"}},hi=[ni,oi,ri,ii,ai,ci,di,fi];function vr(e){for(let t of hi)e.force(t)}var ui={token:"lens",label:"Lens",kinematic:!0,apply(e,t,n){if(n.dist>=e.range)return;let o=e.strength*(1-n.dist/e.range)*e.spin,s=Math.cos(o),i=Math.sin(o),a=t.vx,f=t.vy;t.vx=a*s-f*i,t.vy=a*i+f*s},meta:{desc:"rotates velocity, preserving speed \u2014 bends paths without adding energy"}},yi={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"}},pi=1,mi=1,gi={token:"buoyancy",label:"Buoyancy",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=pi/(t.size*(1+t.heat));t.vy-=(mi-o)*e.strength},meta:{desc:"a constant lift/sink by density difference \u2014 light matter rises, dense settles"}},xi={token:"shear",label:"Shear",apply(e,t,n){if(n.dist>=e.range)return;let o=(t.x-e.cx)*-e.uy+(t.y-e.cy)*e.ux,s=e.strength*(o/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"}},Ie=32,vi=.5,wi={token:"crystallize",label:"Crystallize",apply(e,t,n){if(n.dist>=e.range||t.heat>=vi)return;let o=e.cx+Math.round((t.x-e.cx)/Ie)*Ie,s=e.cy+Math.round((t.y-e.cy)/Ie)*Ie;t.vx+=(o-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"}},bi={token:"align",label:"Align",apply(e,t,n){if(n.dist>=e.range)return;let o=t.vz??0,s=Math.hypot(t.vx,t.vy,o),i=e.strength,a=e.ux,f=e.uy,y=0,p=0,v=0,b=0;for(let z of n.neighbors(t,e.range)){let F=z.vz??0,R=Math.hypot(z.vx,z.vy,F);R>1e-6&&(p+=z.vx/R,v+=z.vy/R,b+=F/R)}let E=Math.hypot(p,v,b);E>1e-6&&(a=p/E,f=v/E,y=b/E),t.vx+=(a*s-t.vx)*i,t.vy+=(f*s-t.vy)*i,(y||o)&&(t.vz=o+(y*s-o)*i)},meta:{desc:"steers toward the neighbour-mean heading (or the body heading when alone)"}};function Mi(e,t,n,o){let s=e*o+n*.2,i=t*o-n*.2;return{x:-o*Math.sin(s)*Math.sin(i),y:-o*Math.cos(s)*Math.cos(i)}}var Ei=.01,ki={token:"wind",label:"Wind",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=Mi(t.x,t.y,n.t,Ei);t.vx+=o.x*e.strength,t.vy+=o.y*e.strength},meta:{desc:"divergence-free curl-noise turbulence"}},Si=.5,zi={token:"cohesion",label:"Cohesion",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=o*Si,i=e.strength;for(let a of n.neighbors(t,o)){let f=a.x-t.x,y=a.y-t.y,p=(a.z??0)-(t.z??0),v=Math.hypot(f,y,p);if(v<1e-6)continue;let b=f/v,E=y/v,z=p/v;if(v<s){let F=i*(s-v)/s;t.vx-=F*b,t.vy-=F*E,p&&(t.vz=(t.vz??0)-F*z)}else{let F=i*(v-s)/(o-s);t.vx+=F*b,t.vy+=F*E,p&&(t.vz=(t.vz??0)+F*z)}}},meta:{desc:"short-range pressure + mid-range cohesion \u2014 surface tension over neighbours"}},Ti=.5,Fi={token:"pressure",label:"Pressure",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=e.strength,i=0,a=n.neighbors(t,o);for(let y of a){let p=Math.hypot(y.x-t.x,y.y-t.y,(y.z??0)-(t.z??0));p<o&&(i+=(1-p/o)**2)}let f=i-Ti;if(!(f<=0))for(let y of a){let p=t.x-y.x,v=t.y-y.y,b=(t.z??0)-(y.z??0),E=Math.hypot(p,v,b);if(E<1e-6||E>=o)continue;let z=s*f*(1-E/o)/E;t.vx+=z*p,t.vy+=z*v,b&&(t.vz=(t.vz??0)+z*b)}},meta:{desc:"SPH density relaxation \u2014 incompressible even-fill via mutual repulsion"}},Ai={token:"hunt",label:"Hunt",apply(e,t,n){if(n.dist>=e.range)return;let o=t.species??0,s=null,i=1/0;for(let b of n.neighbors(t,e.range)){if((b.species??0)===o)continue;let E=b.x-t.x,z=b.y-t.y,F=(b.z??0)-(t.z??0),R=E*E+z*z+F*F;R<i&&(i=R,s=b)}if(!s)return;let a=s.x-t.x,f=s.y-t.y,y=(s.z??0)-(t.z??0),p=Math.hypot(a,f,y)||1,v=o===0?1:-1;t.vx+=a/p*e.strength*v,t.vy+=f/p*e.strength*v,y&&(t.vz=(t.vz??0)+y/p*e.strength*v)},meta:{desc:"two-species pursuit \u2014 predators seek prey, prey flee predators"}},Ci=.35,Pi={token:"link",label:"Link",apply(e,t,n){if(n.dist>=e.range)return;let o=e.range,s=o*Ci,i=e.strength;for(let a of n.neighbors(t,o)){let f=a.x-t.x,y=a.y-t.y,p=(a.z??0)-(t.z??0),v=Math.hypot(f,y,p);if(v<1e-6)continue;let b=v-s,E=.5*i*(b/s);t.vx+=E*(f/v),t.vy+=E*(y/v),p&&(t.vz=(t.vz??0)+E*(p/v))}},meta:{desc:"a Verlet distance constraint \u2014 holds a rest length, so matter ropes and drapes"}},wr=40,Oi={token:"morph",label:"Morph",apply(e,t,n){let o=e.targets;if(!o||o.length===0)return;let s=Math.min(o.length-1,Math.floor((t.gx??0)*o.length)),i=o[s],a=i.x-t.x,f=i.y-t.y,y=Math.hypot(a,f),p=e.strength;t.vx+=a*p*.02,t.vy+=f*p*.02,t.z&&(t.vz=(t.vz??0)-t.z*p*.02);let b=(1-(y<wr?1-y/wr:0))*p*.3;b>0&&(t.vx+=((n.rng??Math.random)()-.5)*b,t.vy+=((n.rng??Math.random)()-.5)*b)},meta:{desc:"matter assembles into a mark/chart/logo \u2014 never words (\xA711)"}},Ri=90,$i={token:"spawn",label:"Spawn",apply(){},source(e,t){let n=e.life??Ri,o=Math.max(1,Math.round(e.strength*2));e.cap!=null&&e.cap>0&&n>0&&(o=Math.min(o,e.cap/n)),e.emitAcc=(e.emitAcc??0)+o;let s=Math.floor(e.emitAcc);for(e.emitAcc-=s;s>0;s--){let i=((t.rng??Math.random)()-.5)*.6,a=Math.cos(i),f=Math.sin(i),y=e.ux*a-e.uy*f,p=e.ux*f+e.uy*a,v=2+(t.rng??Math.random)()*2;t.spawn({x:e.cx,y:e.cy,vx:y*v,vy:p*v,age:n,heat:.6,...e.species!=null?{species:e.species}:{}})}},meta:{desc:"a source \u2014 emits matter along the heading, budgeted by a lifespan"}},Ii=3,Ni={token:"resonate",label:"Resonate",apply(){},modify(e,t,n){return{strength:1+Math.sin(n.t*Ii*e.spin)}},meta:{desc:"pulses sibling forces with a time-varying strength S(t)=S\u2080(1+sin \u03C9t)"}},Li=.5,Di={token:"spotlight",label:"Spotlight",apply(){},modify(e,t,n){let o=-n.dx/n.dist,s=-n.dy/n.dist;return{gate:o*e.ux+s*e.uy<Li}},meta:{desc:"gates sibling forces to an angular cone of the heading"}},_i={token:"screen",label:"Screen",apply(){},meta:{desc:"a quiet zone \u2014 attenuates other bodies' forces on matter inside its radius"}},Bi={token:"pigment",label:"Pigment",apply(e,t,n){let o=e.tint;!o||n.dist>=e.range*.6||(t.color=t.color?lo(t.color,o,.08):o)},meta:{desc:"conserved color transport \u2014 matter takes on and carries a tint"}},Wi=.5,br=.12,Hi={token:"fieldflow",label:"Field Flow",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let o=n.fieldAt?.(t.x,t.y);if(!o)return;let s=Math.hypot(o.x,o.y);if(!(s>1e-9))return;let i=o.x/s,a=o.y/s,f=e.range>0?1-n.dist/e.range:1,y=e.strength*f,p=t.vz??0,v=Math.hypot(t.vx,t.vy,p);if(v>1e-6){let z=Math.min(1,y*Wi);t.vx+=(i*v-t.vx)*z,t.vy+=(a*v-t.vy)*z,p&&(t.vz=p+(0-p)*z)}t.vx+=i*y*br,t.vy+=a*y*br;let b=t.vz??0,E=t.vx*t.vx+t.vy*t.vy+b*b;if(E>n.c*n.c){let z=n.c/Math.sqrt(E);t.vx*=z,t.vy*=z,b&&(t.vz=b*z)}e.on&&(t.heat=Math.max(t.heat,f*.4))},meta:{desc:"follow the field lines \u2014 steer onto and stream down the net field a body radiates"}},qi={token:"warp",label:"Warp",kinematic:!0,apply(e,t,n){if(!e.warpHas||t.cap)return;let o=e.absorbR;if(n.dist>=o)return;let s=Math.cos(e.twist??0),i=Math.sin(e.twist??0),a=e.warpScale??1,f=-n.dx/n.dist,y=-n.dy/n.dist,p=f*s-y*i,v=f*i+y*s,b=o*a+6;t.x=e.warpX+p*b,t.y=e.warpY+v*b,t.z&&(t.z=-n.dz/n.dist*b);let E=t.vx,z=t.vy;t.vx=E*s-z*i,t.vy=E*i+z*s,t.heat=Math.max(t.heat,.6)},meta:{desc:"a wormhole throat \u2014 relocates matter to its paired body, conserved"}},Yi=[ui,yi,gi,xi,wi,bi,ki,zi,Fi,Pi,Ai,Oi,$i,Ni,Di,_i,Bi,Hi,qi];function Mr(e){for(let t of Yi)e.force(t)}function Ui(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 Gi(e){let t=0;for(let n of e)t+=n.heat;return t}function Er(e){let t=Ui(e),n=Gi(e);return{kinetic:t,thermal:n,total:t+n,count:e.length}}var Ne={x:0,y:0},Le=[0,0,0];function De(e,t={}){let n=null;if((t.render??"none")!=="none"&&(n=e.getContext("2d"),!n))throw new Error("Fundamental: 2D canvas context unavailable");let o=t.overlayCanvas??null,s=n?o?.getContext("2d")??null:null,i=t.overlayBackend??(o&&s?zn(o,s):null),a=new Ae,f=1,y=new Map,p=Bo(),v=new Map,b=r=>(v.get(r)?.size??0)>0;function E(r,c){let l=v.get(r);if(l)for(let g of l)g(c)}let z=new Ce;function F(r,c){b(r)&&z.record(r,c)}function R(){z.flush(E)}let B=new WeakMap,N=new Map,X=new Map;function u(r){let c=b("enter")||b("exit"),l=b("met");if(!c&&!l)return;for(let d=0;d<r.length;d++){let x=r[d];if(c){let m=N.get(x);m||N.set(x,m=new Set);let h=x.range*x.range;for(let w=0;w<r.length;w++){if(d===w)continue;let M=r[w],S=M.cx-x.cx,T=M.cy-x.cy,k=S*S+T*T<h;k&&!m.has(M)?(m.add(M),b("enter")&&F("enter",{body:x,other:M})):!k&&m.has(M)&&(m.delete(M),b("exit")&&F("exit",{body:x,other:M}))}}if(l){let m=X.get(x);m||X.set(x,m=new Set);for(let h=d+1;h<r.length;h++){let w=r[h],M=Math.abs(w.cx-x.cx)<x.hw+w.hw&&Math.abs(w.cy-x.cy)<x.hh+w.hh;M&&!m.has(w)?(m.add(w),F("met",{a:x,b:w})):!M&&m.has(w)&&m.delete(w)}}}let g=new Set(r);for(let d of[N,X])for(let x of d.keys())g.has(x)||d.delete(x)}let Z=[],it=new WeakMap,lt=[],D=0,A=new WeakMap,j=new WeakMap,J=new Map,dt=new Map;if(gr(p),vr(p),Mr(p),!t.host)throw new Error("Fundamental: createField requires opts.host. Use @fundamental-engine/vanilla (createField/mountField) or @fundamental-engine/elements / @fundamental-engine/react, or pass browserHost() from @fundamental-engine/dom.");let _=t.host,tt=[],yt=_.reducedMotion(),Rt=yn[t.theme??pn]??yn[pn],O={accent:t.accent??ke(t.palette)[0]??fn[0]??"#4da3ff",density:t.density&&t.density>0?t.density:1,render:t.render??"none",waves:t.waves??!0,waveStyle:t.waveStyle??"linear",waveCenter:t.waveCenter??null,background:t.background??"opaque",mass:t.mass??!1,separation:t.separation!=null&&t.separation>=0?t.separation:0,attention:t.attention??!1,causality:t.causality??!1,heatmap:t.heatmap??!1,overlay:t.overlay??"off",gridWarp:t.gridWarp!=null&&t.gridWarp>=0?t.gridWarp:1,gridIntensity:t.gridIntensity!=null&&t.gridIntensity>=0?Math.min(t.gridIntensity,1):.16,gradientCool:t.gradientCool?gt(t.gradientCool):Rt.cool,gradientWarm:t.gradientWarm?gt(t.gradientWarm):Rt.warm,waveBaseline:(t.waveBaseline??Rt.wave).map(gt),dprCap:t.dprCap&&t.dprCap>0?t.dprCap:2,depth:t.depth&&t.depth>0?t.depth:0,feedbackSink:t.feedbackSink??Tn},K=null,L=[],I=0,$=0,Y=0,Q=0,at=!1,Ut=1,ee=0,fe=new WeakMap,qt=0,$t=0,Ln=!0,Dn={...Ee.ambient.preset},vt=[],Dt=[],_n=0,Yt=null,ht=t.rng??Math.random,qe=t.now??(()=>performance.now()),ft=yt?1:0,Ye=NaN,It=null,ne=null,_t=0,Nt=0,he=null,Ue=[],Ge=null,ue=null,Pr=Math.round(130*O.density)*4,xt={x:0,y:0,k:0},ut=null,Lt=null,Bn=0,Wn=0,Hn=ke(t.palette).map(gt),rt=gt(O.accent),ye=null,Ve=[],Bt=[],Gt=[],Vt=[],je=[],Xe=[],jt=[],pe=new Oe,Je=!1,Ke=()=>{Je||(Je=!0,queueMicrotask(()=>{Je=!1,ge()}))},Or=r=>{for(let c of["--d","--field-density","--load","--mass","--entropy","--coherence","--temperature"])r.style.removeProperty(c)},Rr=r=>{let c=r.detail;c?.element&&(pe.register(c),Ke())},$r=r=>{let c=r.detail;c?.element&&(pe.unregister(c.element),Or(c.writeTarget??c.element),Ke())},Ir=Ke,Tt={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null},qn=qe(),q={dx:0,dy:0,dz:0,dist:1,form:{...Ee.ambient.preset},W:0,H:0,D:O.depth,t:0,frameN:0,dt:yt?0:1,c:12,G:1,scrollV:0,rng:ht,spark:(r,c,l,g)=>Yn(r,c,l,g),supernova:r=>{let c=hr(a.particles,r,ht),l=new Set(c);for(let g of a.particles){if(l.has(g))continue;let d=g.x-r.cx,x=g.y-r.cy,m=Math.hypot(d,x)||1;if(m<320){let h=(1-m/320)*4;g.vx+=d/m*h,g.vy+=x/m*h,g.heat=Math.max(g.heat,.8)}}xn(Dt,vt,r.cx,r.cy,320,I,$,q.t,g=>void a.add(Xt(g))),Ur(r),Qe(r.el,"field:saturated",{peak:c.length}),r.el.dataset.fxCap==="1"&&(r.el.dataset.fxCap="0",Jt(r.el,"released",{accreted:0,load:0}),b("release")&&F("release",{body:r,count:c.length}),B.delete(r))},spawn:r=>{a.size>=Pr||a.add(Xt(r))},neighbors:(r,c)=>a.neighbors(r,c),grid:r=>{let c=y.get(r);if(!c){let l=r.startsWith("wave")?"wave":r.startsWith("memory")?"memory":"diffuse";c=new te(I,$,l),y.set(r,c)}return c}};function Yn(r,c,l,g){if(yt||Vt.length>260)return;let d=g?gt(g):[255,122,69],x=Eo(l);for(let m=0;m<x;m++){let h=ht()*6.28318,w=.8+ht()*(l>0?l:1)*1.7;Vt.push({x:r,y:c,vx:Math.cos(h)*w,vy:Math.sin(h)*w,life:1,c:d})}}function Xt(r={}){let c=r.size??.7+ht()*1.8;return{id:r.id??f++,x:r.x??ht()*I,y:r.y??ht()*$,vx:r.vx??(ht()-.5)*.25,vy:r.vy??(ht()-.5)*.18,z:r.z??(O.depth>0?ht()*O.depth:0),vz:r.vz??(O.depth>0?(ht()-.5)*.18:0),m:r.m??(O.mass?c:1),heat:r.heat??0,size:c,gx:r.gx??ht(),gy:r.gy??ht(),gz:r.gz??ht(),cap:null,...r.age!=null?{age:r.age}:{},...r.color!=null?{color:r.color}:{},...r.species!=null?{species:r.species}:{}}}let me=[];function Nr(){if(!me.length)return;let r=a.particles;for(let c=0;c<r.length;c++){let l=me[c%me.length];r[c].atom=l;let g=typeof l.weight=="number"?Math.max(0,Math.min(1,l.weight)):.5;r[c].size*=.6+g*.9,r[c].m*=.6+g*1.2}}function Un(){a.clear();let r=Math.round(130*O.density);for(let c=0;c<r;c++)a.add(Xt());Nr(),vt=O.waves?Co(O.waveBaseline):[],Dt=O.waves?Po(vt.length,O.density,ht):[],_n=Dt.length}function ge(){let r=Zo(_.root);if(pe.size>0){let g=new Set(r.map(d=>d.el));L=r.concat(pe.bodies(ce).filter(d=>!g.has(d.el)))}else L=r;Z.length>0&&(L=L.concat(Z)),Pe(L,I,$,Y,Q),Vr();let c=new Map(Bt.map(g=>[g.el,g]));Bt=[..._.root.querySelectorAll("[data-move]")].map(g=>{let d=g,x=d.getBoundingClientRect(),m=Number.parseFloat(d.dataset.mass??""),h=Number.isFinite(m)?m:To(x.width*x.height),w=(d.dataset.move??"").trim()==="layout",M=d.hasAttribute("data-dock"),S=d.hasAttribute("data-warp"),T=c.get(d);return T?{el:d,o:T.o,mEl:h,layout:w,dockable:M,dock:T.dock,docked:T.docked,warpable:S,warpCool:T.warpCool}:{el:d,o:{x:0,y:0,vx:0,vy:0},mEl:h,layout:w,dockable:M,dock:{dock:0},docked:null,warpable:S,warpCool:0}}),je=[..._.root.querySelectorAll("[data-on]")].map(g=>{let d=g;return{el:d,body:L.find(x=>x.el===d)??null,bindings:vn(d.dataset.on??"")}}),Xe=[..._.root.querySelectorAll("[data-class]")].map(g=>{let d=g;return{el:d,body:L.find(x=>x.el===d)??null,bindings:vn(d.dataset.class??"")}});for(let g of L){if(!g.pair)continue;let d=null;try{d=_.root.querySelector(g.pair)}catch{d=null}g.pairBody=d?L.find(x=>x.el===d):void 0}let l=new Map(Gt.map(g=>[g.el,g]));for(let[g,d]of l)if(!_.root.contains(g))for(let x of d.emitted)x.remove();Gt=[..._.root.querySelectorAll("[data-emit]")].map(g=>{let d=g,x=d.dataset.emit??"",m=null;try{m=x?_.root.querySelector(x):null}catch{m=null}let h=Math.max(0,Math.round(Number.parseFloat(d.dataset.max??"")||8)),w=l.get(d);if(w){let M=w.emitted.filter(S=>S.isConnected);for(;M.length>h;)M.pop().remove();return{el:d,tmpl:m,cap:h,emitted:M}}return{el:d,tmpl:m,cap:h,emitted:[]}})}function Lr(){for(let r of L)if(r.pairBody){if(!r.pairBody.el.isConnected){r.warpHas=!1,r.pairBody=void 0;continue}r.pairBody.vis?(r.warpX=r.pairBody.cx,r.warpY=r.pairBody.cy,r.warpHas=!0):r.warpHas=!1}else r.pair&&(r.warpHas=!1)}function Dr(){if(!(Gt.length===0||q.frameN%30!==0))for(let r of Gt){if(!r.tmpl||r.emitted.length>=r.cap)continue;let c=r.tmpl.cloneNode(!0);c.removeAttribute("id"),c.setAttribute("aria-hidden","true"),c.setAttribute("inert",""),c.dataset.fieldEmitted="",r.el.appendChild(c),r.emitted.push(c)}}function _r(){if(je.length!==0)for(let r of je){let c=r.body?{d:r.body.d,on:r.body.on,accreted:r.body.accreted}:{d:0,on:r.el.dataset.active==="1",accreted:0};for(let l of r.bindings){let g=wn(l.trigger,c);g&&!l.armed?(l.armed=!0,r.el.dispatchEvent(new CustomEvent(l.event,{bubbles:!0,detail:{trigger:l.trigger,d:c.d,on:c.on,accreted:c.accreted}}))):g||(l.armed=!1)}}}function Br(){if(Xe.length!==0)for(let r of Xe){let c=r.body?{d:r.body.d,on:r.body.on,accreted:r.body.accreted}:{d:0,on:r.el.dataset.active==="1",accreted:0};for(let l of r.bindings){let g=wn(l.trigger,c);g&&!l.armed?(l.armed=!0,r.el.classList.add(l.event)):!g&&l.armed&&(l.armed=!1,r.el.classList.remove(l.event))}}}function Jt(r,c,l){r.dispatchEvent(new CustomEvent("field:"+c,{bubbles:!0,composed:!0,detail:l})),r.dispatchEvent(new CustomEvent("forces:"+c,{bubbles:!0,composed:!0,detail:l}))}function Wr(){for(let r of L){if(!r.vis||r.tokens.indexOf("sink")<0)continue;let c=r.el.dataset.fxCap==="1",l=ur(c,r.accreted>0);l.fire==="captured"?(r.el.dataset.fxCap="1",Jt(r.el,"captured",{accreted:r.accreted,load:An(r)}),b("absorb")&&F("absorb",{body:r,count:r.accreted}),B.set(r,r.accreted)):l.fire==="released"&&(r.el.dataset.fxCap="0",Jt(r.el,"released",{accreted:0,load:0}),b("release")&&F("release",{body:r,count:B.get(r)??0}),B.delete(r))}}let Hr=[{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"}],qr=120;function Qe(r,c,l){r.dispatchEvent(new CustomEvent(c,{bubbles:!0,composed:!0,detail:l}))}function Gn(r,c,l,g,d,x){let m=r.get(c);m||r.set(c,m=new Map);let h=m.get(g.metric);h||m.set(g.metric,h=new $e({enter:g.enter,exit:g.exit,debounceMs:qr}));let w=h.update(d,x);w==="entered"?Qe(l,g.rise,{metric:g.metric,value:d}):w==="exited"&&Qe(l,g.fall,{metric:g.metric,value:d})}function Yr(r){for(let c of L)if(!(!c.vis||c.tokens.length===0))for(let l of Hr){let g;switch(l.metric){case"density":g=c.d;break;case"attention":O.attention&&(g=c.attn??1);break;case"entropy":g=c.metrics?.entropy;break}g!==void 0&&Gn(A,c,c.el,l,g,r)}for(let c of lt)Gn(j,c.agent,c.from.el,{metric:"memory",enter:.6,exit:.3,rise:"field:memory-threshold",fall:"field:memory-faded"},c.agent.memory,r)}function Ur(r){for(let c of Bt)c.docked===r&&(c.docked=null,c.dock.dock=0,c.el.getAttribute("aria-hidden")==="true"&&c.el.removeAttribute("aria-hidden"),c.el.removeAttribute("inert"),c.el.style.opacity="",Jt(c.el,"released",{}))}function Gr(){if(Bt.length===0)return;let r=Bt.map(c=>{let l=c.el.getBoundingClientRect();return{x:l.left-Y+l.width/2,y:l.top-Q+l.height/2}});for(let c=0;c<Bt.length;c++){let l=Bt[c];if(!l.el.isConnected){l.docked&&(l.docked=null,l.dock.dock=0);continue}let g=r[c].x,d=r[c].y;if(l.docked){let M={x:g-l.o.x,y:d-l.o.y};l.dock.dock=pr(l.dock.dock,1);let S=mr(M,l.o,{x:l.docked.cx,y:l.docked.cy},l.dock.dock);l.el.style.transform=`translate(${S.tx.toFixed(2)}px, ${S.ty.toFixed(2)}px) scale(${S.scale.toFixed(3)})`,l.el.style.opacity=S.opacity.toFixed(3),l.dock.dock>=1&&l.el.getAttribute("aria-hidden")!=="true"&&(l.el.setAttribute("aria-hidden","true"),l.el.setAttribute("inert",""));continue}Tt.x=g,Tt.y=d,Tt.vx=0,Tt.vy=0,Tt.heat=0,Tt.cap=null;for(let M of L){if(!M.vis||M.tokens.length===0||M.el===l.el)continue;let S=M.cx-g,T=M.cy-d,k=Math.hypot(S,T);q.dx=S,q.dy=T,q.dist=k<1?1:k;for(let C of M.tokens)p.forces[C]?.apply(M,Tt,q)}Tt.cap=null;let x=zo(l.o),m=Tt.vx+x.x,h=Tt.vy+x.y;if(l.layout){let M=Fo({x:g,y:d},r,c),S=Ao((T,k)=>a.near(T,k,40).length,g,d,16,6);m+=M.x+S.x,h+=M.y+S.y}let w={x:g-l.o.x,y:d-l.o.y};if(So(l.o,m,h,l.mEl,.9),l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.dockable){let M={x:w.x+l.o.x,y:w.y+l.o.y},S=L.find(T=>T.vis&&T.el!==l.el&&T.tokens.indexOf("sink")>=0&&Cn(M,T));S&&(l.docked=S,Jt(l.el,"captured",{sink:S.el}))}if(l.warpCool>0&&(l.warpCool-=1),l.warpable&&l.warpCool===0){let M={x:w.x+l.o.x,y:w.y+l.o.y},S=L.find(T=>T.vis&&T.el!==l.el&&T.warpHas&&T.tokens.indexOf("warp")>=0&&Cn(M,T));S&&(l.o.x=S.warpX-w.x,l.o.y=S.warpY-w.y,l.o.vx=0,l.o.vy=0,l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.warpCool=45,Jt(l.el,"relocated",{from:S.el}))}}}function Vr(){jt.length&&(jt=jt.filter(r=>r.el.isConnected?!0:(r.el.removeEventListener("pointerenter",r.enter),r.el.removeEventListener("pointerleave",r.leave),r.el.removeEventListener("focus",r.enter),r.el.removeEventListener("blur",r.leave),delete r.el.dataset.fxEngaged,!1))),_.root.querySelectorAll("[data-hot]").forEach(r=>{let c=r;if(c.dataset.fxEngaged==="1")return;c.dataset.fxEngaged="1";let l=()=>{c.dataset.active="1",ye=c.dataset.color??null;let d=c.closest("[data-index][data-threads]");if(d){let x=[...d.querySelectorAll("[data-hot]")].filter(m=>m!==c);Ze(x.map(m=>({a:c,b:m,color:c.dataset.color??void 0})))}},g=()=>{c.dataset.active="0",ye=null,Ze(null)};c.addEventListener("pointerenter",l),c.addEventListener("pointerleave",g),c.addEventListener("focus",l),c.addEventListener("blur",g),jt.push({el:c,enter:l,leave:g})})}function Ze(r){Ve=(r??[]).map(c=>({a:c.a,b:c.b,c:gt(c.color??O.accent),seed:ht()*6.28}))}function jr(){if(Ve.length===0)return;let r=q.t;n.globalCompositeOperation="lighter";for(let c of Ve){let l=c.a.getBoundingClientRect(),g=c.b.getBoundingClientRect(),d=l.left-Y+l.width/2,x=l.top-Q+l.height/2,m=g.left-Y+g.width/2,h=g.top-Q+g.height/2,[w,M,S]=c.c;n.strokeStyle=`rgba(${w},${M},${S},0.22)`,n.lineWidth=1,n.beginPath(),n.moveTo(d,x),n.lineTo(m,h),n.stroke();for(let T=0;T<3;T++){let k=(r*.6+c.seed+T/3)%1,C=d+(m-d)*k,H=x+(h-x)*k;n.fillStyle=`rgba(${w},${M},${S},${(1-k)*.9})`,n.beginPath(),n.arc(C,H,2.2,0,6.28318),n.fill()}}n.globalCompositeOperation="source-over"}let xe=0,Xr=[1/0,1.5,1.25,1];function ve(r){if(!n)return;let c=Math.min(r||1,O.dprCap,Xr[xe]??1/0);e.width=Math.floor(I*c),e.height=Math.floor($*c),e.style.width=I+"px",e.style.height=$+"px",n.setTransform(c,0,0,c,0,0),i?.size(I,$,c)}function Vn(){let r=_.viewport();I=r.width,$=r.height,Y=r.originX??0,Q=r.originY??0,at=r.originX!=null||r.originY!=null,ve(r.dpr),q.W=I,q.H=$,Ut=_.scrollHeight()-$||1;for(let c of y.values())c.resize(I,$);O.heatmap&&(K?K.resize(I,$):K=new le(I,$)),Un(),ge()}function Jr(){let r=q.t,c=16;if(O.waveStyle==="circular"){let l=Yt||{x:I/2,y:$/2},g=Math.min(I,$)*.48;for(let d of vt){let[x,m,h]=d.color;n.beginPath();let w=.08,M=!0;for(let k=0;k<=2*Math.PI+.01;k+=w){let C=ae(d,k,r,g),H=l.x+Math.cos(k)*C,G=l.y+Math.sin(k)*C;M?(n.moveTo(H,G),M=!1):n.lineTo(H,G)}n.closePath();let S=d.baseFrac*g+d.offsetY,T=n.createRadialGradient(l.x,l.y,Math.max(0,S-d.amp),l.x,l.y,S+d.amp+80);T.addColorStop(0,`rgba(${x},${m},${h},${(.08+d.depth*.04)*ft})`),T.addColorStop(1,`rgba(${x},${m},${h},0)`),n.fillStyle=T,n.fill()}n.globalCompositeOperation="lighter";for(let d of vt){let[x,m,h]=d.color;n.beginPath();let w=.08,M=!0;for(let S=0;S<=2*Math.PI+.01;S+=w){let T=ae(d,S,r,g),k=l.x+Math.cos(S)*T,C=l.y+Math.sin(S)*T;M?(n.moveTo(k,C),M=!1):n.lineTo(k,C)}n.closePath(),n.lineWidth=5,n.strokeStyle=`rgba(${x},${m},${h},${(.05+d.depth*.04)*ft})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${x},${m},${h},${(.3+d.depth*.22)*ft})`,n.stroke()}n.globalCompositeOperation="source-over"}else{for(let l of vt){let[g,d,x]=l.color;n.beginPath(),n.moveTo(0,Et(l,0,r,$,1,1,xt));for(let w=0;w<=I;w+=c)n.lineTo(w,Et(l,w,r,$,1,1,xt));n.lineTo(I,$),n.lineTo(0,$),n.closePath();let m=l.baseFrac*$+l.offsetY-l.amp,h=n.createLinearGradient(0,m,0,m+320);h.addColorStop(0,`rgba(${g},${d},${x},${(.11+l.depth*.05)*ft})`),h.addColorStop(1,`rgba(${g},${d},${x},0)`),n.fillStyle=h,n.fill()}n.globalCompositeOperation="lighter";for(let l of vt){let[g,d,x]=l.color;n.beginPath(),n.moveTo(0,Et(l,0,r,$,1,1,xt));for(let m=0;m<=I;m+=c)n.lineTo(m,Et(l,m,r,$,1,1,xt));n.lineWidth=5,n.strokeStyle=`rgba(${g},${d},${x},${(.05+l.depth*.04)*ft})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${g},${d},${x},${(.3+l.depth*.22)*ft})`,n.stroke()}n.globalCompositeOperation="source-over"}}function Kr(){n.globalCompositeOperation="lighter";let r=q.t,c=0;if(O.waveStyle==="circular"){let l=Yt||{x:I/2,y:$/2},g=Math.min(I,$)*.48;for(let d of Dt){let x=vt[d.wi];if(!x){c++;continue}q.dt&&(d.progress+=d.speed,d.progress>1?d.progress-=1:d.progress<0&&(d.progress+=1));let m=d.progress*2*Math.PI,h=ae(x,m,r,g)+d.phase*32,w=l.x+Math.cos(m)*h,M=l.y+Math.sin(m)*h,[S,T,k]=x.color,C=d.glow?.6+.4*Math.sin(r*2.2+c):.85;d.glow&&(n.fillStyle=`rgba(${S},${T},${k},${.16*C*ft})`,n.beginPath(),n.arc(w,M,d.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${S},${T},${k},${C*ft})`,n.beginPath(),n.arc(w,M,d.size,0,6.28318),n.fill(),c++}}else for(let l of Dt){let g=vt[l.wi];if(!g){c++;continue}q.dt&&(l.progress+=l.speed,l.progress>1?l.progress-=1:l.progress<0&&(l.progress+=1));let d=l.progress*I,x=Et(g,d,r,$,1,1,xt)+l.phase*32,[m,h,w]=g.color,M=l.glow?.6+.4*Math.sin(r*2.2+c):.85;l.glow&&(n.fillStyle=`rgba(${m},${h},${w},${.16*M*ft})`,n.beginPath(),n.arc(d,x,l.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${m},${h},${w},${M*ft})`,n.beginPath(),n.arc(d,x,l.size,0,6.28318),n.fill(),c++}n.globalCompositeOperation="source-over"}function Qr(){if(!O.attention)return;for(let l of L)l.attn=1;let r=L.filter(l=>l.vis&&l.tokens.length>0);if(r.length===0)return;let c=po(r);for(let l=0;l<r.length;l++)r[l].attn=c[l]}function Zr(){if(!O.causality)return;let r=L.filter(l=>l.vis&&l.tokens.length>0);if(r.length===0)return;if(r.length===1){jn(r[0],r[0].d);return}let c=mo(r.map(l=>({d:l.d,cx:l.cx,cy:l.cy})));for(let l=0;l<r.length;l++)jn(r[l],wt(r[l].d+c[l],0,1))}function jn(r,c){O.feedbackSink(r.el,{lit:c})}function ts(){for(let r of L){if(!r.feedback)continue;let c=uo(r.count,r.on);r.d+=(c-r.d)*.08;let l=r.writeTarget??r.el;if(r.fmax){let w=yo(r.fmin,r.fmax,r.d);fe.get(l)!==w&&(fe.set(l,w),l.style.fontVariationSettings=`"wght" ${w}`+(r.opsz?`, "opsz" ${r.opsz}`:""))}let g=K?K.norm(r.cx,r.cy):void 0,d=r.tokens.indexOf("sink")>=0&&r.capacity>0?An(r):void 0,x=Do(r.thermo),m=r.metrics??(r.metrics={entropy:0,coherence:1,temperature:0});m.entropy+=(x.entropy-m.entropy)*.08,m.coherence+=(x.coherence-m.coherence)*.08,m.temperature+=(x.temperature-m.temperature)*.08;let h={density:r.d,heatmapDensity:g,load:d,entropy:m.entropy,coherence:m.coherence,temperature:m.temperature};O.feedbackSink(l,h),r.onFeedback?.(h)}}function es(){if(Vt.length!==0){n.globalCompositeOperation="lighter";for(let r=Vt.length-1;r>=0;r--){let c=Vt[r];if(!c)continue;if(c.x+=c.vx,c.y+=c.vy,c.vx*=.9,c.vy*=.9,c.life*=.85,c.life<.05){Vt.splice(r,1);continue}let[l,g,d]=c.c;n.fillStyle=`rgba(${l},${g},${d},${.18*c.life})`,n.beginPath(),n.arc(c.x,c.y,2+c.life*4,0,6.28318),n.fill(),n.fillStyle=`rgba(${l},${g},${d},${c.life})`,n.beginPath(),n.arc(c.x,c.y,.6+c.life*1.5,0,6.28318),n.fill()}n.globalCompositeOperation="source-over"}}let Wt=null,we=null,Kt=null;function ns(){if(!K)return;let r=$>0?wt((1.15-ee/$)/.85,0,1):1;if(r<=.01)return;let c=K.cell,l=Math.max(1,Math.ceil(I/c)),g=Math.max(1,Math.ceil($/c));if(Wt||(Wt=_.createCanvas(),we=Wt.getContext("2d")),!!we){if((Wt.width!==l||Wt.height!==g)&&(Wt.width=l,Wt.height=g,Kt=null),Kt===null||$t%3===0){Kt===null&&(Kt=we.createImageData(l,g));let d=rt,x=Kt.data;for(let m=0;m<g;m++)for(let h=0;h<l;h++){let w=K.norm(h*c+c/2,m*c+c/2),M=(m*l+h)*4;x[M]=d[0],x[M+1]=d[1],x[M+2]=d[2],x[M+3]=Math.round(wt(w*.5*ft,0,1)*255)}we.putImageData(Kt,0,0)}n.globalCompositeOperation="lighter",n.imageSmoothingEnabled=!0,n.globalAlpha=r,n.drawImage(Wt,0,0,I,$),n.globalAlpha=1,n.globalCompositeOperation="source-over"}}function os(){O.background==="transparent"?O.render==="trails"?(n.globalCompositeOperation="destination-out",n.fillStyle="rgba(0,0,0,0.22)",n.fillRect(0,0,I,$),n.globalCompositeOperation="source-over"):n.clearRect(0,0,I,$):(O.render==="trails"?n.fillStyle="rgba(5,6,11,0.22)":n.fillStyle="rgb(5,6,11)",n.fillRect(0,0,I,$)),Jr(),K&&xe<2&&ns(),Kr();let r=O.render!=="metaballs"&&O.render!=="streamlines";n.globalCompositeOperation="lighter";let c=rt,l=I/2,g=$*.4,d=Math.hypot(Math.max(l,I-l),Math.max(g,$-g))||1;if(ue===null||$t%6===0){ue=[];for(let m of L){if(!m.tint)continue;let h=(m.range||200)*1.4;ue.push({b:m,r2:h*h,rgb:gt(m.tint)})}}let x=ue;if(r)for(let m of a.particles){if(m.cap){n.fillStyle=`rgba(${c[0]},${c[1]},${c[2]},${.55*ft})`,n.beginPath(),n.arc(m.x,m.y,1.3,0,6.28318),n.fill();continue}let h=Math.min(1,Math.hypot(m.x-l,m.y-g)/d),w=h*h,M=m.heat;co(Le,w,M,c,O.gradientCool,O.gradientWarm);let S=Le[0],T=Le[1],k=Le[2];if(x.length){let mt=0,nt=null;for(let st of x){let Ft=m.x-st.b.cx,At=m.y-st.b.cy,oe=Ft*Ft+At*At;if(oe>=st.r2)continue;let P=1-Math.sqrt(oe/st.r2);P>mt&&(mt=P,nt=st.rgb)}if(nt){let st=mt*.7;S+=(nt[0]-S)*st,T+=(nt[1]-T)*st,k+=(nt[2]-k)*st}}if(m.color){let[mt,nt,st]=gt(m.color);S+=(mt-S)*.75,T+=(nt-T)*.75,k+=(st-k)*.75}let C=O.depth>0?1-Math.min(Math.abs(m.z??0)/O.depth,1)*.55:1,H=(m.size*(1-.4*w)+M*2)*C,G=wt((.5-.3*w+M*.5)*ft*C,0,1),ct=S|0,pt=T|0,bt=k|0;n.fillStyle=`rgba(${ct},${pt},${bt},${.12*G})`,n.beginPath(),n.arc(m.x,m.y,H+1.2,0,6.28318),n.fill(),n.fillStyle=`rgba(${ct},${pt},${bt},${G})`,n.beginPath(),n.arc(m.x,m.y,H,0,6.28318),n.fill()}if(es(),jr(),n.globalCompositeOperation="source-over",O.render==="links"){n.globalCompositeOperation="lighter";let m=rt,h=90;n.lineWidth=.6;for(let w of a.particles)if(!w.cap)for(let M of a.neighbors(w,h)){if(M.x<w.x||M.x===w.x&&M.y<w.y)continue;let S=rr(Math.hypot(M.x-w.x,M.y-w.y),h);S<=0||(n.strokeStyle=`rgba(${m[0]},${m[1]},${m[2]},${S})`,n.beginPath(),n.moveTo(w.x,w.y),n.lineTo(M.x,M.y),n.stroke())}n.globalCompositeOperation="source-over"}if(O.render==="metaballs"){let M=Math.ceil(I/16)+1,S=Math.ceil($/16)+1;!It||It.length!==M*S?It=new Float32Array(M*S):It.fill(0);for(let k of a.particles)k.cap||Sn(It,M,S,16,k.x,k.y,34,1);let T=rt;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${T[0]},${T[1]},${T[2]},${.5*ft})`,n.lineWidth=1.4,n.lineCap="round",n.beginPath();for(let k=0;k<S-1;k++)for(let C=0;C<M-1;C++){let H=It[k*M+C],G=It[k*M+C+1],ct=It[(k+1)*M+C+1],pt=It[(k+1)*M+C],bt=kn(H,G,ct,pt,.9);if(!bt.length)continue;let mt=C*16,nt=k*16;for(let st of bt)n.moveTo(mt+st.x1*16,nt+st.y1*16),n.lineTo(mt+st.x2*16,nt+st.y2*16)}n.stroke(),n.globalCompositeOperation="source-over"}if(O.render==="voronoi"){let w=Math.ceil(I/18)+1,M=Math.ceil($/18)+1;(!ne||ne.length!==w*M)&&(ne=new Int32Array(w*M));let S=a.particles,T=new Map;for(let C=0;C<S.length;C++)T.set(S[C],C);for(let C=0;C<M;C++)for(let H=0;H<w;H++){let G=H*18,ct=C*18,pt=a.near(G,ct,54),bt=-1;if(pt.length){let mt=sr(G,ct,pt);mt>=0&&(bt=T.get(pt[mt])??-1)}ne[C*w+H]=bt}let k=rt;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${k[0]},${k[1]},${k[2]},${.32*ft})`,n.lineWidth=1,n.beginPath();for(let C of ir(ne,w,M))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==="streamlines"||O.render==="flow"){let h=rt;if(n.lineWidth=1,n.lineCap="round",he===null||ut||$t%3===0){let w=[],M=[],S=0;for(let T=46/2;T<I;T+=46)for(let k=46/2;k<$;k+=46){let{fx:C,fy:H}=Zt(L,p.forces,q,T,k);if(ut){let ct=ie(Ne,T,k,ut,.04);C+=ct.x,H+=ct.y}let G=Math.hypot(C,H);if(!(G>1e-9)){M.push({gx:T,gy:k});continue}w.push({gx:T,gy:k,ux:C/G,uy:H/G,mag:G}),G>S&&(S=G)}_t===0?_t=S:_t=S>_t?_t*.7+S*.3:_t*.9+S*.1,he=w,Ue=M}if(Ue.length){n.fillStyle=`rgba(${h[0]},${h[1]},${h[2]},0.05)`;for(let w of Ue)n.fillRect(w.gx-.5,w.gy-.5,1,1)}if(_t>0&&he)for(let w of he){let M=Math.sqrt(w.mag/_t),S=46*.46*(.28+.72*M),T=w.gx+w.ux*S,k=w.gy+w.uy*S;n.strokeStyle=`rgba(${h[0]},${h[1]},${h[2]},${wt(.1+M*.5,0,.72)})`,n.beginPath(),n.moveTo(w.gx,w.gy),n.lineTo(T,k);let C=3.4;n.moveTo(T,k),n.lineTo(T-w.ux*C-w.uy*C*.6,k-w.uy*C+w.ux*C*.6),n.moveTo(T,k),n.lineTo(T-w.ux*C+w.uy*C*.6,k-w.uy*C-w.ux*C*.6),n.stroke()}}}function Xn(r){return(r===void 0?[]:Array.isArray(r)?r:[r]).filter(l=>l!=="off")}function Jn(r,c,l){let d=rt;if(Ge===null||ut||$t%3===0){let h=[],w=0;for(let M=44/2;M<I;M+=44)for(let S=44/2;S<$;S+=44){let{fx:T,fy:k}=Zt(L,p.forces,q,M,S);if(ut){let H=ie(Ne,M,S,ut,.04);T+=H.x,k+=H.y}let C=Math.hypot(T,k);C>1e-9&&(h.push({gx:M,gy:S,ux:T/C,uy:k/C,mag:C}),C>w&&(w=C))}Nt===0?Nt=w:Nt=w>Nt?Nt*.7+w*.3:Nt*.9+w*.1,Ge=h}if(Nt<=0)return;let x={r:d[0],g:d[1],b:d[2],alpha:0,width:1.2},m=new Float64Array(12);for(let h of Ge){let w=l?wt(h.mag/Nt,0,1):Math.sqrt(h.mag/Nt),M=44*.5*(.25+.75*w),S=h.gx+h.ux*M,T=h.gy+h.uy*M,k=3.6;m[0]=h.gx,m[1]=h.gy,m[2]=S,m[3]=T,m[4]=S,m[5]=T,m[6]=S-h.ux*k-h.uy*k*.6,m[7]=T-h.uy*k+h.ux*k*.6,m[8]=S,m[9]=T,m[10]=S-h.ux*k+h.uy*k*.6,m[11]=T-h.uy*k-h.ux*k*.6,x.alpha=wt(.12+w*.55,0,.8),r.segments(m,x)}}function rs(r){let c=Mo(L);if(!c.length)return;let l=vo((x,m)=>Te(L,p.forces,x,m),c,{step:6,maxSteps:200,bounds:{w:I,h:$},loopDist:8}),g=rt,d={r:g[0],g:g[1],b:g[2],alpha:.42,width:1.1};for(let x of l){if(x.length<2)continue;let m=new Float32Array(x.length*2);for(let h=0;h<x.length;h++)m[h*2]=x[h].x,m[h*2+1]=x[h].y;r.polyline(m,d)}}function ss(r){let l=22*O.gridWarp,g=48*.46,d=Math.floor(I/48)+2,x=Math.floor($/48)+2,m=new Float32Array(d*x),h=new Float32Array(d*x),w=0,M=new Float32Array(d*x);for(let P=0;P<x;P++)for(let W=0;W<d;W++){let{fx:et,fy:V}=Zt(L,p.forces,q,W*48,P*48),ot=Math.hypot(et,V),Mt=P*d+W;ot>1e-9&&(m[Mt]=et/ot,h[Mt]=V/ot,M[Mt]=ot,ot>w&&(w=ot))}let S=[rt,[120,110,255],[240,70,255],[255,50,130]],T=8,k=P=>w>0?Math.sqrt(M[P]/w):0,C=P=>Math.round(k(P)*T),H=P=>{let W=P/T,et=gn(S,W);return{r:et[0],g:et[1],b:et[2],alpha:Math.min(1,O.gridIntensity*(.3+.85*W)),width:W>.55?1.4:1}},G=new Float32Array(d*x),ct=new Float32Array(d*x);for(let P=0;P<d*x;P++){let W=k(P);G[P]=m[P]*W*l,ct[P]=h[P]*W*l}let pt=new Float32Array(d*x),bt=new Float32Array(d*x);for(let P=0;P<x;P++)for(let W=0;W<d;W++){let et=0,V=0,ot=0;for(let Ct=-1;Ct<=1;Ct++)for(let Pt=-1;Pt<=1;Pt++){let zt=W+Pt,Ot=P+Ct;if(zt<0||Ot<0||zt>=d||Ot>=x)continue;let Qt=Ot*d+zt;et+=G[Qt],V+=ct[Qt],ot++}let Mt=P*d+W;pt[Mt]=et/ot,bt[Mt]=V/ot}let mt=48*1.5,nt=(P,W)=>{let et=W*d+P,V=pt[et],ot=bt[et],Mt=Math.hypot(V,ot);Mt>g&&(V=V/Mt*g,ot=ot/Mt*g);let Ct=P*48,Pt=W*48,zt=Math.min(Ct,I-Ct,Pt,$-Pt),Ot=zt<=0?0:zt<mt?zt/mt:1;return[Ct+V*Ot,Pt+ot*Ot]},st=4,Ft=P=>{let W=P.length>>1;if(W<3)return P;let et=[P[0],P[1]];for(let V=0;V<W-1;V++){let ot=(V>0?V-1:0)<<1,Mt=V<<1,Ct=V+1<<1,Pt=(V+2<W?V+2:W-1)<<1,zt=P[ot],Ot=P[ot+1],Qt=P[Mt],nn=P[Mt+1],on=P[Ct],rn=P[Ct+1],no=P[Pt],oo=P[Pt+1];for(let sn=1;sn<=st;sn++){let re=sn/st,an=re*re,ro=an*re;et.push(.5*(2*Qt+(-zt+on)*re+(2*zt-5*Qt+4*on-no)*an+(-zt+3*Qt-3*on+no)*ro),.5*(2*nn+(-Ot+rn)*re+(2*Ot-5*nn+4*rn-oo)*an+(-Ot+3*nn-3*rn+oo)*ro))}}return et},At=(P,W)=>Math.max(C(P*d+W),C(P*d+W+1)),oe=(P,W)=>Math.max(C(W*d+P),C((W+1)*d+P));for(let P=0;P<x;P++){let W=At(P,0),et=[...nt(0,P),...nt(1,P)];for(let V=1;V<d-1;V++){let ot=At(P,V);ot===W?et.push(...nt(V+1,P)):(r.polyline(Ft(et),H(W)),et=[...nt(V,P),...nt(V+1,P)],W=ot)}r.polyline(Ft(et),H(W))}for(let P=0;P<d;P++){let W=oe(P,0),et=[...nt(P,0),...nt(P,1)];for(let V=1;V<x-1;V++){let ot=oe(P,V);ot===W?et.push(...nt(P,V+1)):(r.polyline(Ft(et),H(W)),et=[...nt(P,V),...nt(P,V+1)],W=ot)}r.polyline(Ft(et),H(W))}}let kt=null;function Kn(r,c,l){let x=Math.ceil(I/24)+1,m=Math.ceil($/24)+1;!kt||kt.length!==x*m?kt=new Float32Array(x*m):kt.fill(0);let h=!1;for(let k of a.particles){if(k.cap)continue;let C=c(k);C<=0||(h=!0,Sn(kt,x,m,24,k.x,k.y,42,C))}if(!h)return;let w=0;for(let k=0;k<kt.length;k++)kt[k]>w&&(w=kt[k]);if(w<=0)return;let M=rt,S=[.25,.5,.78],T=[];for(let k=0;k<S.length;k++){let C=S[k]*w;T.length=0;for(let H=0;H<m-1;H++)for(let G=0;G<x-1;G++){let ct=kt[H*x+G],pt=kt[H*x+G+1],bt=kt[(H+1)*x+G+1],mt=kt[(H+1)*x+G],nt=kn(ct,pt,bt,mt,C);if(!nt.length)continue;let st=G*24,Ft=H*24;for(let At of nt)T.push(st+At.x1*24,Ft+At.y1*24,st+At.x2*24,Ft+At.y2*24)}T.length&&r.segments(T,{r:M[0],g:M[1],b:M[2],alpha:l*(.45+.55*(k/(S.length-1))),width:1+k*.3})}}function is(r){let d=rt,x={r:d[0],g:d[1],b:d[2],alpha:0,width:1.1},m=new Float64Array(4);for(let h=104/2;h<I;h+=104)for(let w=104/2;w<$;w+=104){let M=h,S=w;for(let T=0;T<24;T++){let{fx:k,fy:C}=Zt(L,p.forces,q,M,S);if(ut){let pt=ie(Ne,M,S,ut,.04);k+=pt.x,C+=pt.y}let H=Math.hypot(k,C);if(!(H>1e-9))break;let G=M+k/H*9,ct=S+C/H*9;if(G<0||ct<0||G>I||ct>$)break;m[0]=M,m[1]=S,m[2]=G,m[3]=ct,x.alpha=.34*(1-T/24),r.segments(m,x),M=G,S=ct}}}function as(r){let c=rt;for(let l of L){if(!l.vis||!l.feedback)continue;let g=`d ${l.d.toFixed(2)}`,d=l.cx+l.hw+8,x=l.cy;r.rect(d-3,x-7,r.measureText(g)+6,14,c[0],c[1],c[2],wt(.3+l.d*.55,0,.85)),r.text(g,d,x+.5,5,6,11,.92)}}function cs(r,c){if(r.clear(),!(!c.length||I===0||$===0))for(let l of c){l==="streamlines"?Jn(r,!1,!1):l==="force-vectors"?Jn(r,!1,!0):l==="field-lines"?rs(r):l==="grid"?ss(r):l==="temperature"?Kn(r,d=>d.heat,.5):l==="energy"?Kn(r,d=>.5*d.m*(d.vx*d.vx+d.vy*d.vy),.42):l==="path"?is(r):l==="data"&&as(r);let g=dt.get(l);g&&g(r,q,I,$)}}function tn(r){$t++,q.t=(r-qn)/1e3,q.frameN=$t;let c=Number.isFinite(Ye)?(r-Ye)/16.6667:1;if(Ye=r,q.dt=yt?0:wt(c,.2,2),ft<1&&(ft=Math.min(1,ft+.012)),Wo(q.form,Dn,.03),at){let h=_.viewport();Y=h.originX??0,Q=h.originY??0}let l=_.scrollY(),g=l-ee;if(q.scrollV=(q.scrollV??0)*.7+Math.abs(g)*.3,ee=l,g!==0&&!at)for(let h of L)h.cy-=g;for(let h of vt){let w=l*(.025+h.depth*.08);h.offsetY+=(w-h.offsetY)*.04}if(L.length&&$t%6===0&&(Pe(L,I,$,Y,Q),u(L),yr(L,q.supernova)),lt.length&&q.dt){let h=q.dt/60;for(let w of lt)fr(w.agent,w.from.d>.08,0,h)}let d=null;for(let h of L)if(h.on&&h.vis){d=h;break}let x=ut??d;if(xt.k+=((x?1:0)-xt.k)*.07,x){let h=ut?ut.x:d.cx,w=ut?ut.y:d.cy;xt.x=xt.x?xt.x+(h-xt.x)*.16:h,xt.y=xt.y?xt.y+(w-xt.y)*.16:w}$t%30===0&&(Ut=_.scrollHeight()-$||1);let m=ye?gt(ye):gn(Hn,l/Ut);if(rt=[rt[0]+(m[0]-rt[0])*.08,rt[1]+(m[1]-rt[1])*.08,rt[2]+(m[2]-rt[2])*.08],O.accent=mn(rt),a.reindex(),Qr(),q.dt&&No(L,a.particles),ut&&q.dt)for(let h of a.particles){if(h.cap)continue;let w=ie(Ne,h.x,h.y,ut,.6);h.vx+=w.x,h.vy+=w.y}if(O.waveStyle==="circular")if(O.waveCenter)Yt=typeof O.waveCenter=="function"?O.waveCenter():O.waveCenter;else{let h=L.find(w=>w.tokens.includes("star")||w.tokens.includes("vortex"));h?Yt={x:h.cx,y:h.cy}:Yt={x:I/2,y:$/2}}else Yt=null;if(Lr(),Yo({store:a,bodies:L,env:q,forces:p.forces,conditions:p.conditions,waves:vt,waveStyle:O.waveStyle,waveCenter:Yt,separation:O.separation}),Lt&&(Lt.x=Bn,Lt.y=Wn,Lt.vx=0,Lt.vy=0,Lt.heat=Math.min(1,Lt.heat+.2)),q.dt){for(let h of y.values())h.step();K&&K.update(a.particles),$o(a,Dt,_n,vt,I,$,q.t,ht),Io(Dt,vt,L,p.forces,I,$,q.t,h=>void a.add(Xt(h))),Gr(),Dr()}if(ts(),Zr(),_r(),Br(),Wr(),Yr(r),R(),n&&O.render!=="none"&&Ln&&(!yt||$t%4===0)&&(os(),i)){let h=Xn(O.overlay);h.length&&cs(i,h)}qt=_.raf(tn)}function en(r){let c=Ee[r];c&&(Dn={...c.preset})}let be="",Qn=qn;function Zn(){let r=_.viewport().height*.5,c="";_.root.querySelectorAll("[data-formation]").forEach(l=>{let g=l.getBoundingClientRect();g.top<=r&&g.bottom>=r&&(c=l.dataset.formation??"")}),c&&c!==be&&(be=c,en(c))}let to=()=>void(Qn=qe()),ls=()=>{to(),Zn()},eo=setInterval(()=>{qe()-Qn>6e3&&be!=="ambient"&&(be="ambient",en("ambient"))},1200);eo.unref?.();let ds=()=>Vn();Vn();let fs=()=>{_.hidden()?(_.cancelRaf(qt),qt=0):qt||(qt=_.raf(tn))};return tt.push(_.onResize(ds)),tt.push(_.onScroll(ls)),tt.push(_.onVisibility(fs)),tt.push(_.onInput(to)),tt.push(_.onBodyEvent(tr,Rr)),tt.push(_.onBodyEvent(er,$r)),tt.push(_.onBodyEvent(nr,Ir)),Zn(),qt=_.raf(tn),{scan:ge,rescan:ge,setAccent:r=>{O.accent=r,rt=gt(r)},setPalette:r=>{let c=ke(r);Hn=c.map(gt);let l=c[0];l&&(O.accent=l,rt=gt(l))},setFormation:en,setWaveStyle:r=>{O.waveStyle=r},setWaveCenter:r=>{O.waveCenter=r},setSeparation:r=>{O.separation=r>=0?r:0},setAttention:r=>{if(O.attention=r,!r)for(let c of L)c.attn=1},setCausality:r=>{if(O.causality=r,!r)for(let c of L)c.el.style.removeProperty("--lit"),c.el.dataset.fxLit="0"},setRender:r=>{if(r!=="none"&&!n){if(n=e.getContext("2d"),!n){console.warn(`Fundamental: setRender('${r}') could not acquire a 2d context; staying in render 'none'`);return}o&&!s&&(s=o.getContext("2d"),s&&!i&&(i=t.overlayBackend??zn(o,s))),ve(_.viewport().dpr)}O.render=r},setOverlay:r=>{O.overlay=r,Xn(r).length||i?.clear()},setHeatmap:r=>{if(O.heatmap=r,r)!K&&I>0&&(K=new le(I,$));else if(K){K.clear(),K=null;for(let c of L)(c.writeTarget??c.el).style.removeProperty("--field-heatmap-density")}},setDprCap:r=>{O.dprCap=r>0?r:2,n&&ve(_.viewport().dpr)},setQualityTier:r=>{let c=Math.max(0,Math.min(3,Math.floor(r||0)));c!==xe&&(xe=c,n&&ve(_.viewport().dpr))},threads:Ze,burst:(r,c,l)=>{for(let d of a.particles){let x=ko(d.x-r,d.y-c,160,6,d.z??0);x.heat!==0&&(d.vx+=x.vx,d.vy+=x.vy,x.vz&&(d.vz=(d.vz??0)+x.vz),d.heat=Math.max(d.heat,x.heat),l&&(d.color=l))}xn(Dt,vt,r,c,160,I,$,q.t,d=>void a.add(Xt(d))),Yn(r,c,2,l)},flowTo:(r,c,l)=>{ut=go(r,c,l)},clearFlow:()=>{ut=null},seed:r=>{me=r,Un()},atomAt:(r,c)=>{let l=null,g=1/0;for(let d of a.near(r,c,24)){if(d.atom==null)continue;let x=(d.x-r)**2+(d.y-c)**2+(d.z??0)**2;x<g&&(g=x,l=d.atom)}return l},focusAt:(r,c)=>{let l=null,g=1/0;for(let d of a.near(r,c,24)){if(d.atom==null)continue;let x=(d.x-r)**2+(d.y-c)**2+(d.z??0)**2;x<g&&(g=x,l=d)}return Lt=l,l?(Bn=l.x,Wn=l.y,l.atom??null):null},clearFocus:()=>{Lt=null},particleCount:()=>a.size,readParticles:r=>{let c=a.particles,l=Math.floor(r.length/5),g=0;for(let d=0;d<c.length&&g<l;d++){let x=c[d];if(x.report!==void 0)continue;let m=g*5;r[m]=x.x,r[m+1]=x.y,r[m+2]=x.z??0,r[m+3]=x.heat,r[m+4]=x.size,g++}return g},readParticleIds:r=>{let c=a.particles,l=0;for(let g=0;g<c.length&&l<r.length;g++){let d=c[g];d.report===void 0&&(r[l++]=d.id??0)}return l},readParticleChannels:(r,c)=>{let l=a.particles,g=0;for(let d=0;d<l.length;d++){let x=l[d];if(!("report"in x&&x.report!==void 0)){if(g>=Math.min(...c.map(m=>m.length)))break;for(let m=0;m<r.length&&!(m>=c.length);m++){let h=r[m];c[m][g]=h==="x"?x.x:h==="y"?x.y:h==="z"?x.z??0:h==="vx"?x.vx:h==="vy"?x.vy:h==="heat"?x.heat:h==="size"?x.size:h==="m"?x.m:h==="id"?x.id??0:h==="age"?x.age??0:h==="charge"?x.charge??0:0}g++}}return g},registerOverlay:(r,c)=>(dt.set(r,c),()=>{dt.delete(r)}),addAgent:r=>{let c=Xt({x:r.x,y:r.y,z:r.z,species:r.species});return c.vx=0,c.vy=0,r.z===void 0&&O.depth<=0&&(c.z=0),r.mass!==void 0&&(c.m=r.mass),c.maxSpeed=r.maxSpeed,c.report=r.report,a.add(c),{particle:c,remove:()=>a.remove(c)}},addBody:r=>{let c={"data-body":Array.isArray(r.tokens)?r.tokens.join(" "):String(r.tokens)};r.strength!=null&&(c["data-strength"]=String(r.strength)),r.range!=null&&(c["data-range"]=String(r.range)),r.spin!=null&&(c["data-spin"]=String(r.spin)),r.angle!=null&&(c["data-angle"]=String(r.angle)),r.color!=null&&(c["data-color"]=r.color);let l=()=>{let h=r.rect();return{left:h.left,top:h.top,right:h.left+h.width,bottom:h.top+h.height,width:h.width,height:h.height,x:h.left,y:h.top,toJSON:()=>({})}},g={tagName:"DIV",id:"",className:"",dataset:r.color!=null?{color:r.color}:{},getAttribute:h=>c[h]??null,hasAttribute:h=>h in c,getBoundingClientRect:l,dispatchEvent:()=>!0,setAttribute:()=>{},removeAttribute:()=>{},style:{setProperty:()=>{},removeProperty:()=>{},getPropertyValue:()=>""}},d=ce(g);d.rect=l,d.data=r.data,d.feedback=!0;let x={};d.onFeedback=h=>{Object.assign(x,h),r.onFeedback?.(h)},Z.push(d),L=L.concat(d),Pe([d],I,$,Y,Q);let m={data:r.data,get channels(){return x},set:h=>{h.strength!=null&&(c["data-strength"]=String(h.strength)),h.range!=null&&(c["data-range"]=String(h.range)),h.spin!=null&&(c["data-spin"]=String(h.spin)),h.angle!=null&&(c["data-angle"]=String(h.angle)),h.color!=null&&(c["data-color"]=h.color,g.dataset.color=h.color,d.tint=h.color)},remove:()=>{let h=Z.indexOf(d);h>=0&&Z.splice(h,1),L=L.filter(w=>w!==d);for(let w=lt.length-1;w>=0;w--){let M=lt[w];(M.from===d||M.to===d)&<.splice(w,1)}}};return it.set(m,d),m},addEdge:(r,c,l)=>{let g=it.get(r),d=it.get(c);if(!g||!d)throw new Error("addEdge: both arguments must be handles returned by addBody on this field.");let x={id:`e${D++}`,from:"",to:"",type:l?.type??"related",strength:l?.strength??.5,tension:0,memory:0,active:!1},m={agent:x,from:g,to:d,fromData:r.data,toData:c.data};return lt.push(m),{set:h=>{h.strength!=null&&(x.strength=h.strength<0?0:h.strength>1?1:h.strength),h.type!=null&&(x.type=h.type)},remove:()=>{let h=lt.indexOf(m);h>=0&<.splice(h,1)}}},readEdges:()=>lt.map(r=>({from:r.fromData,to:r.toData,type:r.agent.type,strength:r.agent.strength,memory:r.agent.memory,active:r.agent.active})),addField:(r,c)=>(J.set(r,c),{name:r,set:l=>{J.set(r,l)},remove:()=>{J.delete(r)}}),sampleField:(r,c,l)=>{let g=J.get(r);return g?g(c,l):0},energy:()=>Er(a.particles),sample:(r,c)=>{let{fx:l,fy:g}=Zt(L,p.forces,q,r,c);return{x:l,y:g}},sampleScalar:(r,c)=>K?K.norm(r,c):(En("NOOP_NO_HEATMAP","sampleScalar() returned 0 because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),0),sampleGradient:(r,c)=>K?K.gradient(r,c):(En("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:r=>q.grid(r),on:(r,c)=>{let l=v.get(r);return l||(l=new Set,v.set(r,l)),l.add(c),()=>void l.delete(c)},version:cn,scrollV:()=>q.scrollV??0,setVisible:r=>{Ln=r},setBackground:r=>{O.background=r,r==="transparent"&&n&&n.clearRect(0,0,I,$)},destroy:()=>{_.cancelRaf(qt),clearInterval(eo);for(let r of tt)r();for(let r of jt)r.el.removeEventListener("pointerenter",r.enter),r.el.removeEventListener("pointerleave",r.leave),r.el.removeEventListener("focus",r.enter),r.el.removeEventListener("blur",r.leave),delete r.el.dataset.fxEngaged;jt=[];for(let r of Bt)(r.docked||r.dock.dock>0)&&(r.docked=null,r.dock.dock=0,r.el.style.opacity="",r.el.getAttribute("aria-hidden")==="true"&&r.el.removeAttribute("aria-hidden"),r.el.removeAttribute("inert"));for(let r of Gt)for(let c of r.emitted)c.remove();Gt=[],a.clear()}}}var _e={};function Be(){return _e.reducedMotion!==void 0?_e.reducedMotion:typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function We(){return _e.hidden!==void 0?_e.hidden:typeof document<"u"&&document.hidden}var Vi=["--field-density","--d"],kr=!1;function Sr(){if(kr)return[];kr=!0;let e=globalThis.CSS;if(!e||typeof e.registerProperty!="function")return[];let t=[];for(let n of Vi)try{e.registerProperty({name:n,syntax:"<number>",inherits:!0,initialValue:"0"}),t.push(n)}catch{}return t}var zr=["pointerdown","wheel","keydown","touchstart"];function de(){return Sr(),{root:document,viewport:()=>({width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio||1}),scrollY:()=>window.scrollY||0,scrollHeight:()=>document.documentElement.scrollHeight,reducedMotion:()=>Be(),hidden:()=>We(),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 zr)window.addEventListener(t,e,{passive:!0});return()=>{for(let t of zr)window.removeEventListener(t,e)}},onBodyEvent:(e,t)=>(document.addEventListener(e,t),()=>document.removeEventListener(e,t))}}var Tr=["pointerdown","wheel","keydown","touchstart"];function Fr(e){return{root:e,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:()=>Be(),hidden:()=>We(),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 Tr)e.addEventListener(n,t,{passive:!0});return()=>{for(let n of Tr)e.removeEventListener(n,t)}},onBodyEvent:(t,n)=>(e.addEventListener(t,n),()=>e.removeEventListener(t,n))}}function Ar(e,t={}){return De(e,{...t,host:de()})}function $n(e,t={}){let{host:n,bounds:o,...s}=t,i=n??(o?Fr(o):de());return De(e,{...s,host:i})}function In(){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 He(e=document.body){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText=cr,e.appendChild(t),t}function Cr(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 ji(e={}){In();let{target:t=document.body,...n}=e,o=He(t),s=Ar(o,n);return{...s,destroy:()=>{s.destroy(),o.remove()}}}var Nn=class{constructor(t={}){U(this,"canvas");U(this,"field");U(this,"managed");In();let{canvas:n,target:o,bounds:s,...i}=t;this.managed=!n,this.canvas=n??(s?Cr(s):He(o)),this.field=$n(this.canvas,s?{...i,bounds:s}:i)}scan(){this.field.scan()}rescan(){this.field.rescan()}setAccent(t){this.field.setAccent(t)}setPalette(t){this.field.setPalette(t)}setFormation(t){this.field.setFormation(t)}setWaveStyle(t){this.field.setWaveStyle(t)}setWaveCenter(t){this.field.setWaveCenter(t)}setSeparation(t){this.field.setSeparation(t)}setAttention(t){this.field.setAttention(t)}setCausality(t){this.field.setCausality(t)}setHeatmap(t){this.field.setHeatmap(t)}setDprCap(t){this.field.setDprCap(t)}setQualityTier(t){this.field.setQualityTier(t)}setRender(t){this.field.setRender(t)}setOverlay(t){this.field.setOverlay(t)}threads(t){this.field.threads(t)}burst(t,n,o){this.field.burst(t,n,o)}flowTo(t,n,o){this.field.flowTo(t,n,o)}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,o){return this.field.addEdge(t,n,o)}readEdges(){return this.field.readEdges()}addField(t,n){return this.field.addField(t,n)}sampleField(t,n,o){return this.field.sampleField(t,n,o)}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)}on(t,n){return this.field.on(t,n)}get version(){return this.field.version}scrollV(){return this.field.scrollV()}setVisible(t){this.field.setVisible(t)}setBackground(t){this.field.setBackground(t)}destroy(){this.field.destroy(),this.managed&&this.canvas.remove()}};export{ao as CONDITIONS,cn as FIELD_VERSION,dn as FORCES,io as FORMATIONS,Nn as FieldField,fn as PALETTE,de as browserHost,$n as createField,dr as cssFeedbackSink,_s as headlessHost,He as makeFieldCanvas,ji as mountField};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fundamental-engine/vanilla",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Framework-free TypeScript wrapper for Fundamental — the reciprocal DOM-physics field as a typed FieldField class + mountField(), with no custom-element registration and no framework dependency.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@fundamental-engine/
|
|
56
|
-
"@fundamental-engine/
|
|
55
|
+
"@fundamental-engine/dom": "0.9.1",
|
|
56
|
+
"@fundamental-engine/core": "0.9.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"esbuild": "^0.25.0",
|