@fundamental-engine/vanilla 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/field.d.ts +10 -0
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +20 -0
- package/dist/field.js.map +1 -1
- 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 Te=Object.defineProperty;var Hs=Object.getOwnPropertyDescriptor;var js=Object.getOwnPropertyNames;var Ys=Object.prototype.hasOwnProperty;var Us=(e,t,n)=>t in e?Te(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Gs=(e,t)=>{for(var n in t)Te(e,n,{get:t[n],enumerable:!0})},Vs=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of js(t))!Ys.call(e,s)&&s!==n&&Te(e,s,{get:()=>t[s],enumerable:!(r=Hs(t,s))||r.enumerable});return e};var Xs=e=>Vs(Te({},"__esModule",{value:!0}),e);var V=(e,t,n)=>Us(e,typeof t!="symbol"?t+"":t,n);var Ca={};Gs(Ca,{CONDITIONS:()=>kn,FIELD_VERSION:()=>ce,FORCES:()=>Ae,FORMATIONS:()=>Mn,FieldField:()=>Qe,PALETTE:()=>Ce,browserHost:()=>re,createField:()=>Ke,cssFeedbackSink:()=>Hn,headlessHost:()=>Lr,makeFieldCanvas:()=>ye,mountField:()=>ts});var ce="0.9.2";var Ae=[{id:"attract",name:"Attract",color:"#4da3ff",does:"Pulls matter into a well",discipline:"Product strategy",verb:"gives direction",body:"attract",attrs:{"data-strength":"1","data-range":"300"},law:"a soft gravity-like well, bent into a spiral"},{id:"jet",name:"Jet",color:"#a78bfa",does:"Draws matter in, jets it out",discipline:"AI systems",verb:"adapts response",body:"jet",attrs:{"data-angle":"0","data-strength":"1","data-range":"300"},law:"recycles the field into a stream"},{id:"tether",name:"Tether",color:"#86e57f",does:"Tethers matter to a radius",discipline:"Software architecture",verb:"gives structure",body:"tether",attrs:{"data-strength":"1","data-range":"260"},law:"a rest length \u2014 a leash, not a drain"},{id:"wall",name:"Wall",color:"#c4b5fd",does:"A surface that bounces \u2014 throws sparks",discipline:"Experience design",verb:"the human surface",body:"wall",attrs:{},law:"elastic bounce off the bounding box"},{id:"stream",name:"Stream",color:"#7dd3fc",does:"Blows a directional current",discipline:"Motion",verb:"reveals motion",body:"stream",attrs:{"data-angle":"0","data-strength":"1","data-range":"340"},law:"constant force along a heading"},{id:"repel",name:"Repel",color:"#ff9d5c",does:"Pushes matter away",discipline:"Commerce",verb:"market pressure",body:"repel",attrs:{"data-strength":"1.1","data-range":"300"},law:"inverted well \u2014 carves a clean void"},{id:"viscosity",name:"Viscosity",color:"#8da2c0",does:"Thickens the medium",discipline:"Physical production",verb:"adds constraint",body:"viscosity",attrs:{"data-strength":"1","data-range":"300"},law:"viscosity \u2014 bleeds momentum off"},{id:"swirl",name:"Swirl",color:"#2dd4bf",does:"Spins matter into a swirl",discipline:"Creative technology",verb:"spins it together",body:"swirl",attrs:{"data-spin":"1","data-strength":"1","data-range":"320"},law:"tangential force \u2014 circles, never collapses"},{id:"sink",name:"Sink",color:"#ff6e9c",does:"Swallows matter, then pops",discipline:"Attention",verb:"holds, then releases",body:"sink attract",attrs:{"data-absorb":"64","data-max":"30","data-strength":"0.8","data-range":"360"},law:"accretion, then supernova"}],ko=Object.fromEntries(Ae.map(e=>[e.id,e])),Ce=Ae.map(e=>e.color),le=["#4da3ff","#2dd4bf","#a78bfa","#ff6e9c","#ff9d5c"],vn=["spotlight","screen","resonate"],Js=["spawn"],wn=300,bn=120;function Ks(e){return vn.includes(e)?"modifier":Js.includes(e)?"source":"force"}function Oe(e){let t=[],n=[],r=[];for(let s of e){let i=Ks(s);i==="modifier"?t.push(s):i==="source"?r.push(s):n.push(s)}return t.length>1&&t.sort((s,i)=>vn.indexOf(s)-vn.indexOf(i)),{modifiers:t,forces:n,sources:r}}var Mn=[{id:"ambient",name:"Ambient",section:"Hero",color:"#4da3ff",cue:"resting drift",preset:{driftX:0,wander:1,orbit:.1,spread:0,conv:0}},{id:"wells",name:"Wells",section:"Work",color:"#2dd4bf",cue:"matter pools",preset:{driftX:0,wander:.7,orbit:.85,spread:0,conv:0}},{id:"lanes",name:"Lanes",section:"Writing",color:"#ff9d5c",cue:"a current carries",preset:{driftX:.55,wander:.5,orbit:0,spread:0,conv:0}},{id:"scatter",name:"Scatter",section:"Practice",color:"#a78bfa",cue:"energy dispersed",preset:{driftX:0,wander:1.7,orbit:0,spread:.6,conv:0}},{id:"accretion",name:"Accretion",section:"Contact",color:"#ffce6b",cue:"everything gathers",preset:{driftX:0,wander:.6,orbit:.4,spread:0,conv:.6}}],Pe=Object.fromEntries(Mn.map(e=>[e.id,e]));var kn=[{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}],$a=Object.fromEntries(kn.map(e=>[e.id,e]));var Qs={ours:le,heatmap:["#2b3a8c","#2d8fd4","#3fd07a","#ffe14d","#ff8a3d","#e23b3b"],infrared:["#2a0a4a","#8e24aa","#e53935","#ff8f00","#ffd54f","#fffde7"],spectrum:["#ff3b30","#ff9500","#ffcc00","#34c759","#00c7be","#007aff","#af52de"]};function Re(e){return Array.isArray(e)?e.length>0?e:le:typeof e=="string"?Qs[e]??le:le}var En={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"]}},Sn="warm";var bt=(e,t,n)=>e<t?t:e>n?n:e;function gt(e){let t=e.replace("#",""),n=t.length===3?t.replace(/./g,s=>s+s):t,r=Number.parseInt(n.slice(0,6),16);return Number.isNaN(r)?[77,163,255]:[r>>16&255,r>>8&255,r&255]}var Zs=[255,224,200],ti=[255,110,80];function Eo(e,t,n,r,s=Zs,i=ti){let a=s[0]+(i[0]-s[0])*t,h=s[1]+(i[1]-s[1])*t,m=s[2]+(i[2]-s[2])*t;return a+=(r[0]-a)*n,h+=(r[1]-h)*n,m+=(r[2]-m)*n,e[0]=a,e[1]=h,e[2]=m,e}function zn([e,t,n]){let r=s=>bt(Math.round(s),0,255).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`}function So(e,t,n){let[r,s,i]=gt(e),[a,h,m]=gt(t),p=n<0?0:n>1?1:n;return zn([r+(a-r)*p,s+(h-s)*p,i+(m-i)*p])}function Fn(e,t){if(e.length===0)return[77,163,255];if(e.length===1)return e[0];let n=bt(t,0,1)*(e.length-1),r=Math.min(e.length-2,Math.floor(n)),s=n-r,i=e[r],a=e[r+1];return[i[0]+(a[0]-i[0])*s,i[1]+(a[1]-i[1])*s,i[2]+(a[2]-i[2])*s]}function zo(e,t,n,r=0){if(!(t>0))return 1;let s=Math.max(0,1-e/t),i=1-n*s*s,a=Math.min(Math.max(r,0),1);return i<a?a:i>1?1:i}var $e=1;function Ie(e){let t=e.ux!==0?e.hw/Math.abs(e.ux):1/0,n=e.uy!==0?e.hh/Math.abs(e.uy):1/0,r=Math.min(t,n),s=e.ux*r,i=e.uy*r,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 Fo(e,t,n){let r=0,s=0;for(let i of e){let a=t-i.x,h=n-i.y,m=Math.max($e,Math.hypot(a,h)),p=i.q/(m*m);r+=a/m*p,s+=h/m*p}return{x:r,y:s}}function To(e,t){let n=e/20+(t?.45:0);return n<0?0:n>1?1:n}function Ao(e,t,n){return Math.round(e+(t-e)*n)}function Co(e,t={}){let n=t.beta??2,r=t.lo??.25,s=t.hi??3,i=e.length,a=new Array(i).fill(1);if(i===0)return a;let h=0,m=0;for(let y of e){let b=y.strength>0?y.strength:0;h+=b,m+=b*(1+(y.on?n:0))}if(h<=0||m<=0)return a;let p=h/m;for(let y=0;y<i;y++){let E=(1+(e[y].on?n:0))*p;E<r?E=r:E>s&&(E=s),a[y]=E}return a}function Oo(e,t={}){let n=t.threshold??.55,r=t.kappa??.6,s=t.falloff??320,i=e.length,a=new Array(i).fill(0);if(i<2)return a;let h=new Array(i).fill(0);for(let m=0;m<i;m++){let p=e[m],y=p.d-n;if(y<=0)continue;let b=0;for(let M=0;M<i;M++){if(M===m){h[M]=0;continue}let S=e[M],A=Math.hypot(p.cx-S.cx,p.cy-S.cy),N=A<s?1-A/s:0;h[M]=N,b+=N}if(b<=0)continue;let E=r*y;for(let M=0;M<i;M++){let S=h[M];if(S<=0)continue;let A=E*S/b;a[M]+=A,a[m]-=A}}return a}var Po=e=>`${e.from}\0${e.to}\0${e.type}`;function Tn(e,t){let n=[],r=new Map(e.bodies.map(M=>[M.id,M])),s=new Map(t.bodies.map(M=>[M.id,M]));for(let[M,S]of r){let A=s.get(M);if(!A){n.push({id:M,kind:"removed"});continue}let N={},C=!1,H=new Set([...Object.keys(S.metrics),...Object.keys(A.metrics)]);for(let u of H){let K=S.metrics[u]??0,Z=A.metrics[u]??0;K!==Z&&(N[u]={from:K,to:Z},C=!0)}C&&n.push({id:M,kind:"changed",metrics:N})}for(let M of s.keys())r.has(M)||n.push({id:M,kind:"added"});let i=[],a=new Map(e.relationships.map(M=>[Po(M),M])),h=new Map(t.relationships.map(M=>[Po(M),M]));for(let[M,S]of a){let A=h.get(M);if(!A){i.push({from:S.from,to:S.to,type:S.type,kind:"removed"});continue}let N={from:S.from,to:S.to,type:S.type,kind:"changed"},C=!1;S.strength!==A.strength&&(N.strength={from:S.strength,to:A.strength},C=!0),S.active!==A.active&&(N.active={from:S.active,to:A.active},C=!0),C&&i.push(N)}for(let[M,S]of h)a.has(M)||i.push({from:S.from,to:S.to,type:S.type,kind:"added"});let m=[],p=new Set([...Object.keys(e.metrics),...Object.keys(t.metrics)]);for(let M of p){let S=e.metrics[M]??0,A=t.metrics[M]??0;S!==A&&m.push({key:M,from:S,to:A})}let y=[],b=new Set(e.formations),E=new Set(t.formations);for(let M of E)b.has(M)||y.push({id:M,kind:"activated"});for(let M of b)E.has(M)||y.push({id:M,kind:"deactivated"});return{from:e.id,to:t.id,bodyChanges:n,relationshipChanges:i,metricChanges:m,formationChanges:y}}function Ro(e,t,n={}){let r=y=>Math.round(y*1e3)/1e3,s=Tn(e,t),i=t.frame,a=t.createdAt,h=[],m=(y,b,E={})=>{h.push({frame:i,time:a,cause:y,description:b,...E})};for(let y of s.formationChanges)m("formation",`Formation '${y.id}' ${y.kind}`,{source:y.id});for(let y of s.relationshipChanges){let b;if(y.kind==="added")b="formed";else if(y.kind==="removed")b="dissolved";else{let E=[];if(y.active&&E.push(y.active.to?"became active":"went idle"),y.strength){let M=y.strength.to>=y.strength.from?"strengthened":"weakened";E.push(`${M} ${r(y.strength.from)}\u2192${r(y.strength.to)}`)}b=E.join(", ")||"changed"}m("relationship",`Relationship ${y.from}\u2192${y.to} (${y.type}) ${b}`,{source:y.from,target:y.to,contribution:y.strength})}for(let y of s.bodyChanges)if(y.kind==="added")m("measurement",`Body ${y.id} entered the field`,{source:y.id});else if(y.kind==="removed")m("measurement",`Body ${y.id} left the field`,{source:y.id});else if(y.metrics)for(let[b,E]of Object.entries(y.metrics)){let M=E.to>E.from?"rose":"fell";m("metric",`Body ${y.id} ${b} ${M} ${r(E.from)}\u2192${r(E.to)}`,{source:y.id,contribution:E})}if(e.influences&&t.influences){let y=S=>typeof S=="number"?Math.abs(S):Math.hypot(S.x,S.y,S.z??0),b=S=>`${S.source} ${S.force} ${S.channel??"linear"}`,E=new Map(e.influences.map(S=>[b(S),S])),M=new Map(t.influences.map(S=>[b(S),S]));for(let S of new Set([...E.keys(),...M.keys()])){let A=E.get(S),N=M.get(S),C=A?y(A.contribution):0,H=N?y(N.contribution):0;if(Math.abs(H-C)<1e-9)continue;let u=N??A,K=H>C?C===0?"engaged":"grew":H===0?"released":"weakened",Z=(u.channel??"linear")==="thermal"?" (thermal)":"";m("force",`Force ${u.force} on ${u.source}${Z} ${K} ${r(C)}\u2192${r(H)}`,{source:u.source,contribution:{from:C,to:H}})}}let p=n.focus?h.filter(y=>y.source===n.focus||y.target===n.focus):h;return{from:e.id,to:t.id,focus:n.focus,steps:p}}var Ne=class{constructor(t=64){V(this,"cell");V(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)),r=this.bins.get(n);r?r.push(t):this.bins.set(n,[t])}rebuild(t){this.clear();for(let n of t)this.insert(n)}near(t,n,r,s=0){let i=[],a=r*r,h=Math.floor((t-r)/this.cell),m=Math.floor((t+r)/this.cell),p=Math.floor((n-r)/this.cell),y=Math.floor((n+r)/this.cell);for(let b=h;b<=m;b++)for(let E=p;E<=y;E++){let M=this.bins.get(this.key(b,E));if(M)for(let S of M){let A=S.x-t,N=S.y-n,C=(S.z??0)-s;A*A+N*N+C*C<=a&&i.push(S)}}return i}};var De=class{constructor(t=64){V(this,"particles",[]);V(this,"hash");this.hash=new Ne(t)}get size(){return this.particles.length}add(t){return this.particles.push(t),t}remove(t){let n=this.particles.indexOf(t);if(n<0)return;let r=this.particles.pop();r&&n<this.particles.length&&(this.particles[n]=r)}clear(){this.particles.length=0,this.hash.clear()}reindex(){this.hash.rebuild(this.particles)}neighbors(t,n){let r=this.hash.near(t.x,t.y,n,t.z??0),s=[];for(let i of r)i!==t&&s.push(i);return s}near(t,n,r){return this.hash.near(t,n,r)}};function $o(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 Io(e){for(let t of e)if(t.vis&&t.tokens.indexOf("sink")>=0)return t;return null}var ei=[.24,.4,.55,.7,.85];function No(e){let t=[];for(let n=0;n<5;n++)t.push({baseFrac:ei[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 Do(e,t,n){let r=Math.round(16*t),s=[];for(let i=0;i<e;i++)for(let a=0;a<r;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,r,s=1,i=1,a){let h=e.baseFrac*r+e.offsetY+Math.sin(t*e.freq+e.phase+n*e.speed*1e3*s)*e.amp*i;if(a&&a.k>.001){let m=t-a.x,p=260,y=Math.exp(-(m*m)/(2*p*p));h+=(a.y-h)*.42*y*a.k*(.45+e.depth*.55)}return h}function Lo(e,t,n,r=1,s=1){return Math.cos(t*e.freq+e.phase+n*e.speed*1e3*r)*e.amp*e.freq*s}function de(e,t,n,r,s=1,i=1){let a=e.baseFrac*r+e.offsetY,h=Math.max(1,Math.round(e.freq*2500));return a+Math.sin(h*t+e.phase+n*e.speed*1e3*s)*e.amp*i}function _o(e,t,n,r,s,i,a,h,m=1,p=1,y){if(a==="circular"){let b=t-h.x,E=n-h.y,M=Math.sqrt(b*b+E*E)||.001,S=Math.atan2(E,b),A=Math.min(s,i)*.48,N=de(e,S,r,A,m,p);return{dist:Math.abs(M-N),rWave:N,r:M,theta:S}}else{let b=Et(e,t,r,i,m,p,y);return{dist:Math.abs(n-b),rWave:b,r:n,theta:0}}}var Ut={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null};function Vt(e,t,n,r,s){Ut.x=r,Ut.y=s,Ut.vx=0,Ut.vy=0,Ut.heat=0;let i=0,a=0;for(let h of e){if(!h.vis||h.tokens.length===0)continue;let m,p;if(h.shaped){let E=h.cx-h.hw,M=h.cx+h.hw,S=h.cy-h.hh,A=h.cy+h.hh;m=(r<E?E:r>M?M:r)-r,p=(s<S?S:s>A?A:s)-s}else m=h.cx-r,p=h.cy-s;let y=m*m+p*p;if(h.range>0&&y>=h.range*h.range*2.56)continue;let b=Math.sqrt(y);n.dx=m,n.dy=p,n.dist=b<1?1:b;for(let E of h.tokens){let M=t[E];if(!(!M||M.modify))if(M.field){let S=M.field(h,r,s);i+=S.x,a+=S.y}else M.apply(h,Ut,n)}}return{fx:Ut.vx+i,fy:Ut.vy+a}}function Le(e,t,n,r){let s=0,i=0;for(let a of e)if(!(!a.vis||a.tokens.length===0)){if(a.range>0){let h=a.cx-n,m=a.cy-r;if(h*h+m*m>=a.range*a.range*2.56)continue}for(let h of a.tokens){let m=t[h];if(m?.field){let p=m.field(a,n,r);s+=p.x,i+=p.y}}}return{x:s,y:i}}var Bo=.95,Wo=.972,Ft=10;function ni(e,t,n,r){if(!t.when)return!0;let s=e[t.when];return s?s(t,n,r):!0}function qo(e){return e.classified??(e.classified=Oe(e.tokens))}function Cn(e,t,n,r,s=1){let i=n.vx,a=n.vy,h=n.vz??0,m=n.heat,p=n.spin??0,y=n.age;e.apply(t,n,r),s===1||e.kinematic||(n.vx=i+(n.vx-i)*s,n.vy=a+(n.vy-a)*s,n.vz!==void 0&&(n.vz=h+(n.vz-h)*s));let b=r.accum;if(b!==void 0){let E=n.vx-i,M=n.vy-a,S=(n.vz??0)-h;(E!==0||M!==0||S!==0)&&(b.linear.x+=E,b.linear.y+=M,b.linear.z+=S,b.attribution.push({force:e.token,channel:"linear",contribution:{x:E,y:M,z:S}}));let A=n.heat-m;A!==0&&(b.thermal=(b.thermal??0)+A,b.attribution.push({force:e.token,channel:"thermal",contribution:A}));let N=(n.spin??0)-p;if(N!==0){let C=b.angular??(b.angular={x:0,y:0,z:0});C.z+=N,b.attribution.push({force:e.token,channel:"angular",contribution:N})}if(y!==void 0&&n.age!==void 0){let C=n.age-y;if(C!==0){let H=b.temporal??(b.temporal={});H.decay=(H.decay??0)+C,b.attribution.push({force:e.token,channel:"temporal",contribution:C})}}t.attn!==void 0&&t.attn!==1&&((b.semantic??(b.semantic={})).attention=t.attn,b.attribution.push({force:e.token,channel:"semantic",contribution:t.attn}))}}function An(e,t,n,r,s){if(r.accum===void 0){if(s===1||e.kinematic){e.apply(t,n,r);return}let i=n.vx,a=n.vy,h=n.vz??0;e.apply(t,n,r),n.vx=i+(n.vx-i)*s,n.vy=a+(n.vy-a)*s,n.vz!==void 0&&(n.vz=h+(n.vz-h)*s);return}Cn(e,t,n,r,s)}function Ho(){return{linear:{x:0,y:0,z:0},attribution:[]}}function jo(e){let{store:t,bodies:n,env:r,forces:s,conditions:i,waves:a,separation:h}=e,m=r.dt;if(m===0)return;let{W:p,H:y,form:b}=r;r.fieldAt=(u,K)=>Le(n,s,u,K);for(let u of n){u.count=0;let K=u.thermo;K&&(K.n=0,K.sx=0,K.sy=0,K.ss=0,K.ss2=0,K.sh=0)}let E=null;for(let u of n)u.vis&&u.tokens.length>0&&qo(u).modifiers.indexOf("screen")>=0&&(E??(E=[])).push(u);let M=E?new Array(E.length):null,S=!!a&&a.length>0,A=n.length>0,N=null,C=b.conv>.02?Io(n):null,H=r.D??0;for(let u of t.particles){if(u.cap){u.x+=(u.cap.cx-u.x)*.18,u.y+=(u.cap.cy-u.y)*.18,u.z&&(u.z+=-u.z*.18);continue}u.z===void 0&&(u.z=0),u.vz===void 0&&(u.vz=0);let K=u.z;if(S)if(e.waveStyle==="circular"){let Y=null,P=1e9,U=0,Q=0,B=0,ft=e.waveCenter||{x:p/2,y:y/2};for(let rt of a){let vt=_o(rt,u.x,u.y,r.t,p,y,"circular",ft);vt.dist<P&&(P=vt.dist,Y=rt,U=vt.r,Q=vt.rWave,B=vt.theta)}if(Y&&P<70){let rt=1-P/70,vt=-Math.sin(B)*Y.dir,$=Math.cos(B)*Y.dir;u.vx+=vt*.035*rt,u.vy+=$*.035*rt;let tt=Math.cos(B)*Math.sign(Q-U),L=Math.sin(B)*Math.sign(Q-U);u.vx+=tt*.05*rt,u.vy+=L*.05*rt}}else{let Y=null,P=1e9;for(let U of a){let Q=Math.abs(Et(U,u.x,r.t,y)-u.y);Q<P&&(P=Q,Y=U)}Y&&P<70&&(u.vx+=Y.dir*.035*(1-P/70),u.vy+=Lo(Y,u.x,r.t)*.1*(1-P/70))}if(b.driftX&&(u.vx+=b.driftX*.02),b.spread>.02){let Y=u.gx??.5,P=u.gy??.5,U=(Y+r.frameN*4e-5)%1*p,Q=P*y;u.vx+=(U-u.x)*6e-4*b.spread,u.vy+=(Q-u.y)*6e-4*b.spread,H>0&&(u.vz+=((u.gz??.5)*H-K)*6e-4*b.spread)}if(C){let Y=C.cx-u.x,P=C.cy-u.y,U=-K,Q=Math.hypot(Y,P,U)||1;u.vx+=Y/Q*b.conv*.06,u.vy+=P/Q*b.conv*.06,u.vz+=U/Q*b.conv*.06}if(A){if(E)for(let P=0;P<E.length;P++){let U=E[P],Q=U.cx-u.x,B=U.cy-u.y;M[P]=zo(Math.sqrt(Q*Q+B*B),U.range,U.strength,U.screenMin??0)}let Y=u.m!==1&&u.m>0?1/u.m:1;for(let P of n){if(!P.vis||P.tokens.length===0||P.affects!==void 0&&!P.affects.has(u.species??0))continue;let U,Q;if(P.shaped){let G=P.cx-P.hw,st=P.cx+P.hw,dt=P.cy-P.hh,Xt=P.cy+P.hh,me=u.x<G?G:u.x>st?st:u.x,It=u.y<dt?dt:u.y>Xt?Xt:u.y;U=me-u.x,Q=It-u.y}else U=P.cx-u.x,Q=P.cy-u.y;let B=-u.z,ft=U*U+Q*Q+B*B;if(P.range>0&&ft>=P.range*P.range*2.56)continue;let rt=Math.sqrt(ft);if(P.feedback&&rt<P.range*.5){P.count+=1-rt/(P.range*.5);let G=P.thermo??(P.thermo={n:0,sx:0,sy:0,ss:0,ss2:0,sh:0}),st=u.vx*u.vx+u.vy*u.vy;G.n++,G.sx+=u.vx,G.sy+=u.vy,G.ss+=Math.sqrt(st),G.ss2+=st,G.sh+=u.heat}if(P.when&&!ni(i,P,u,r))continue;r.dx=U,r.dy=Q,r.dz=B,r.dist=rt<1?1:rt;let vt=qo(P),$=1,tt=!1,L=!1;for(let G of vt.modifiers){let st=s[G]?.modify;if(!st)continue;L=!0;let dt=st(P,u,r);dt.strength!=null&&($*=dt.strength),dt.gate&&(tt=!0)}for(let G of vt.forces){let st=s[G]?.modify;if(!st)continue;L=!0;let dt=st(P,u,r);dt.strength!=null&&($*=dt.strength),dt.gate&&(tt=!0)}if(tt)continue;let _=1;if(E)for(let G=0;G<E.length;G++)E[G]!==P&&(_*=M[G]);let D=P.attn??1,St=$*D*_;if(!L&&St===1)for(let G of P.tokens){let st=s[G];st&&An(st,P,u,r,Y)}else if(L){let G=P.strength;P.strength=G*St;for(let st of P.tokens){let dt=s[st];dt&&!dt.modify&&An(dt,P,u,r,Y)}P.strength=G}else{let G=P.strength;P.strength=G*St;for(let st of P.tokens){let dt=s[st];dt&&An(dt,P,u,r,Y)}P.strength=G}}}if(h&&h>0){let Y=r.neighbors(u,12);for(let P of Y){let U=u.x-P.x,Q=u.y-P.y,B=(u.z??0)-(P.z??0),ft=Math.hypot(U,Q,B)||.1;if(ft<12){let rt=(12-ft)/12*h*.12;u.vx+=U/ft*rt,u.vy+=Q/ft*rt,u.vz!==void 0&&(u.vz+=B/ft*rt)}}}let Z=r.c,lt=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(lt>Z*Z){let Y=Z/Math.sqrt(lt);u.vx*=Y,u.vy*=Y,u.vz*=Y}if(u.maxSpeed!==void 0){let Y=u.maxSpeed*u.maxSpeed,P=u.vx*u.vx+u.vy*u.vy+u.vz*u.vz;if(P>Y){let U=u.maxSpeed/Math.sqrt(P);u.vx*=U,u.vy*=U,u.vz*=U}}u.x+=u.vx*m,u.y+=u.vy*m,u.z+=u.vz*m;let mt=r.integrator==="fixed"?Math.pow(Bo,m):Bo;if(u.vx*=mt,u.vy*=mt,u.vz*=mt,u.spin!==void 0&&(u.orient=(u.orient??0)+u.spin*m,u.spin*=mt),u.report===void 0){if(r.frameN%40===0&&b.wander>0){let Y=.05*b.wander;u.vx+=((r.rng??Math.random)()-.5)*Y,u.vy+=((r.rng??Math.random)()-.5)*Y,H>0&&(u.vz+=((r.rng??Math.random)()-.5)*Y)}if(b.wander>.05){let Y=(Math.sin(u.x*.0032+r.t*.12)+Math.cos(u.y*.0034-r.t*.15))*Math.PI;u.vx+=Math.cos(Y)*.013*b.wander,u.vy+=Math.sin(Y)*.013*b.wander}}u.heat*=r.integrator==="fixed"?Math.pow(Wo,m):Wo,u.age!=null&&(u.age-=m,u.age<=0&&(N??(N=[])).push(u)),u.report===void 0?(u.x<-Ft?u.x=p+Ft:u.x>p+Ft&&(u.x=-Ft),u.y<-Ft?u.y=y+Ft:u.y>y+Ft&&(u.y=-Ft),H>0&&(u.z<-Ft?u.z=H+Ft:u.z>H+Ft&&(u.z=-Ft))):(u.x<0?(u.x=0,u.vx=Math.abs(u.vx)):u.x>p&&(u.x=p,u.vx=-Math.abs(u.vx)),u.y<0?(u.y=0,u.vy=Math.abs(u.vy)):u.y>y&&(u.y=y,u.vy=-Math.abs(u.vy)),H>0&&(u.z<0?(u.z=0,u.vz=Math.abs(u.vz)):u.z>H&&(u.z=H,u.vz=-Math.abs(u.vz))),u.report(u))}if(A){for(let u of n)if(!(!u.vis||u.tokens.length===0))for(let K of u.tokens)s[K]?.source?.(u,r)}if(N)for(let u of N)t.remove(u)}var oe=class{constructor(t,n,r="diffuse",s=32){V(this,"mode");V(this,"cell");V(this,"W");V(this,"H");V(this,"cols");V(this,"rows");V(this,"cur");V(this,"nxt");V(this,"prev");this.W=t,this.H=n,this.mode=r,this.cell=s,this.cols=Math.max(2,Math.ceil(t/s)+1),this.rows=Math.max(2,Math.ceil(n/s)+1);let i=this.cols*this.rows;this.cur=new Float32Array(i),this.nxt=new Float32Array(i),this.prev=new Float32Array(i)}clampCol(t){return t<0?0:t>=this.cols?this.cols-1:t}clampRow(t){return t<0?0:t>=this.rows?this.rows-1:t}at(t,n){return this.cur[this.clampRow(n)*this.cols+this.clampCol(t)]}sample(t,n){let r=t/this.cell,s=n/this.cell,i=Math.floor(r),a=Math.floor(s),h=r-i,m=s-a,p=this.at(i,a)*(1-h)+this.at(i+1,a)*h,y=this.at(i,a+1)*(1-h)+this.at(i+1,a+1)*h;return p*(1-m)+y*m}deposit(t,n,r){let s=this.clampCol(Math.round(t/this.cell)),i=this.clampRow(Math.round(n/this.cell));this.cur[i*this.cols+s]+=r}max(){let t=0;for(let n=0;n<this.cur.length;n++)this.cur[n]>t&&(t=this.cur[n]);return t}gradient(t,n){let r=this.cell;return{x:(this.sample(t+r,n)-this.sample(t-r,n))/(2*r),y:(this.sample(t,n+r)-this.sample(t,n-r))/(2*r)}}step(){this.mode==="wave"?this.stepWave():this.mode==="memory"?this.stepDiffuse(.03,.004):this.stepDiffuse()}stepDiffuse(t=.18,n=.01){let r=t<0?0:t>.24?.24:t,s=1-n,{cols:i,rows:a,cur:h,nxt:m}=this;for(let p=0;p<a;p++)for(let y=0;y<i;y++){let b=p*i+y,E=this.at(y-1,p)+this.at(y+1,p)+this.at(y,p-1)+this.at(y,p+1)-4*h[b];m[b]=(h[b]+r*E)*s}this.cur=m,this.nxt=h}stepWave(t=.25,n=.002){let r=t<0?0:t>.5?.5:t,s=1-n,{cols:i,rows:a,cur:h,prev:m,nxt:p}=this;for(let y=0;y<a;y++)for(let b=0;b<i;b++){let E=y*i+b,M=this.at(b-1,y)+this.at(b+1,y)+this.at(b,y-1)+this.at(b,y+1)-4*h[E];p[E]=(2*h[E]-m[E]+r*M)*s}this.prev=h,this.cur=p,this.nxt=m}decay(t){let n=t<=0?1:t>=1?0:1-t;if(n!==1)for(let r=0;r<this.cur.length;r++)this.cur[r]*=n}clear(){this.cur.fill(0),this.nxt.fill(0),this.prev.fill(0)}resize(t,n){if(t===this.W&&n===this.H)return;this.W=t,this.H=n,this.cols=Math.max(2,Math.ceil(t/this.cell)+1),this.rows=Math.max(2,Math.ceil(n/this.cell)+1);let r=this.cols*this.rows;this.cur=new Float32Array(r),this.nxt=new Float32Array(r),this.prev=new Float32Array(r)}};var Yo={active:e=>e.on,fast:(e,t)=>t.vx*t.vx+t.vy*t.vy+(t.vz??0)*(t.vz??0)>.9,slow:(e,t)=>t.vx*t.vx+t.vy*t.vy+(t.vz??0)*(t.vz??0)<.22,hot:(e,t)=>t.heat>.3,cool:(e,t)=>t.heat<.08,scrolling:(e,t,n)=>(n?.scrollV??0)>.25};function Uo(){let e={},t={...Yo};return{forces:e,conditions:t,force(n){e[n.token]=n},condition(n,r){t[n]=r}}}var oi={token:"attract",label:"Attract",apply(e,t,n){let r=e.range*(e.on?1.5:1),s=e.strength*(e.on?3:1);if(n.dist>=r)return;let i=(1-n.dist/r)**2*s*.5,a=n.dx/n.dist,h=n.dy/n.dist;t.vx+=a*i,t.vy+=h*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i),n.form.orbit&&(t.vx+=-h*i*n.form.orbit,t.vy+=a*i*n.form.orbit),e.on&&(t.heat=Math.max(t.heat,(1-n.dist/r)*.9))},meta:{desc:"a soft gravity-like well, bent into a spiral"}},ri={token:"repel",label:"Repel",apply(e,t,n){let r=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=r)return;let i=(1-n.dist/r)**2*s*.5;t.vx-=n.dx/n.dist*i,t.vy-=n.dy/n.dist*i,n.dz&&(t.vz=(t.vz??0)-n.dz/n.dist*i)},meta:{desc:"inverse-square outward push"}},si={token:"swirl",label:"Swirl",apply(e,t,n){let r=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=r)return;let i=(1-n.dist/r)**1.4*s*.45,a=e.spin,h=n.dx/n.dist,m=n.dy/n.dist;t.vx+=m*i*a+h*i*.12,t.vy+=-h*i*a+m*i*.12,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i*.12),e.on&&(t.heat=Math.max(t.heat,(1-n.dist/r)*.6))},meta:{desc:"tangential swirl with light inward retention"}},ii={token:"stream",label:"Stream",apply(e,t,n){let r=e.range*(e.on?1.4:1),s=e.strength*(e.on?2:1);if(n.dist>=r)return;let i=(1-n.dist/r)**1.1*s*.5;t.vx+=e.ux*i,t.vy+=e.uy*i,e.on&&(t.heat=Math.max(t.heat,(1-n.dist/r)*.5))},meta:{desc:"directional current along a heading"}},ai={token:"viscosity",label:"Viscosity",apply(e,t,n){let r=e.range*(e.on?1.4:1);if(n.dist>=r)return;let s=(1-n.dist/r)*(.05+e.strength*.07)*(e.on?1.6:1);t.vx-=t.vx*s,t.vy-=t.vy*s,t.vz&&(t.vz-=t.vz*s)},meta:{desc:"thickens the medium \u2014 bleeds momentum"}},ci={token:"jet",label:"Jet",kinematic:!0,apply(e,t,n){let r=e.range*(e.on?1.4:1);if(!(n.dist>=r))if(n.dist<24){let s=((n.rng??Math.random)()-.5)*.8,i=Math.cos(s),a=Math.sin(s),h=e.ux*i-e.uy*a,m=e.ux*a+e.uy*i,p=2.4+e.strength*2.6;t.vx=h*p,t.vy=m*p,t.x=e.cx+h*26,t.y=e.cy+m*26,t.z&&(t.z=0),t.vz&&(t.vz=0),t.heat=Math.max(t.heat,.9)}else{let s=(1-n.dist/r)**2*(.25+e.strength*.15);t.vx+=n.dx/n.dist*s,t.vy+=n.dy/n.dist*s,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*s)}},meta:{desc:"a fountain \u2014 draws matter in, jets it out along a heading"}},li={token:"tether",label:"Tether",apply(e,t,n){let r=e.range*.6*(e.on?1.25:1),s=r*2.1;if(n.dist>=s)return;let i=(.006+e.strength*.012)*(e.on?1.7:1),a=n.dist-r,h=n.dx/n.dist,m=n.dy/n.dist;t.vx+=h*a*i,t.vy+=m*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)/r))*.5))},meta:{desc:"a tether with a rest length \u2014 holds matter at a fixed radius"}},di={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),h=e.hw+6-s,m=e.hh+6-i;h<m?(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??ko.wall.color),t.heat=Math.max(t.heat,Math.min(.85,a*.4)))},meta:{desc:"axis-aligned bouncing wall \u2014 sparks on impact"}},fi={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"}},hi=[oi,ci,li,di,ii,ri,ai,si,fi];function Go(e){for(let t of hi)e.force(t)}var Pn=1.5,ui=8,yi=60;function mi(e,t,n,r){let s=Ie(e);if(Math.hypot(s[0].x-s[1].x,s[0].y-s[1].y)<Math.max(e.range*.06,ui)){let m=Math.max(e.range*.18,yi),p=e.spin<0?-1:1;s=[{x:e.cx+e.ux*m,y:e.cy+e.uy*m,q:p},{x:e.cx-e.ux*m,y:e.cy-e.uy*m,q:-p}]}let a=r*(1+Pn*(e.d??0)),h=Fo(s,t,n);return{x:h.x*a,y:h.y*a}}function pi(e,t,n,r){let s=t-e.cx,i=n-e.cy,a=Math.max(Math.hypot(s,i),$e),m=(e.spin<0?-1:1)*r*(1+Pn*(e.d??0))/(a*a);return{x:s/a*m,y:i/a*m}}function Vo(e,t,n,r){if(n.dist>=e.range)return;let s=2*n.G*e.M/(n.c*n.c),i=r/(n.dist*n.dist+s*s);t.vx+=n.dx/n.dist*i,t.vy+=n.dy/n.dist*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i),Rn(t,n.c)}function Rn(e,t){let n=e.vz??0,r=Math.hypot(e.vx,e.vy,n);r>t&&(e.vx=e.vx/r*t,e.vy=e.vy/r*t,n&&(e.vz=n/r*t))}function gi(e,t,n){let r=e.cx-t,s=e.cy-n,i=Math.max(Math.hypot(r,s),$e),a=e.M*(1+Pn*(e.d??0))/(i*i);return{x:r/i*a,y:s/i*a}}var xi={token:"gravity",label:"Gravity",apply(e,t,n){Vo(e,t,n,n.G*e.M)},field:(e,t,n)=>gi(e,t,n),meta:{desc:"true softened inverse-square gravity (a real 1/d\xB2 law)"}},vi={token:"charge",label:"Charge",apply(e,t,n){let r=t.charge??0;r!==0&&Vo(e,t,n,-(e.spin*r*n.G*e.M))},field:(e,t,n)=>pi(e,t,n,e.M),meta:{desc:"signed inverse-square \u2014 like repels, opposite attracts"}},wi={token:"magnetism",label:"Magnetism",apply(e,t,n){if(n.dist>=e.range)return;let r=t.charge??0;if(r===0)return;let s=1-n.dist/e.range,i=r*e.spin*e.strength*s,a=Math.cos(i),h=Math.sin(i),m=t.vx;t.vx=m*a-t.vy*h,t.vy=m*h+t.vy*a},field:(e,t,n)=>mi(e,t,n,e.strength),meta:{desc:"Lorentz force \u2014 curves a moving charge perpendicular to its velocity"}};function bi(e){return Math.sqrt(2*Math.max(0,e))}var Mi={token:"thermal",label:"Thermal",apply(e,t,n){if(n.dist>=e.range)return;let r=1-n.dist/e.range,s=bi(e.strength*r);if(s===0)return;let i=Math.random()||1e-9,a=s*Math.sqrt(-2*Math.log(i)),h=2*Math.PI*Math.random();if(t.vx+=a*Math.cos(h),t.vy+=a*Math.sin(h),n.D){let m=Math.random()||1e-9;t.vz=(t.vz??0)+s*Math.sqrt(-2*Math.log(m))*Math.cos(2*Math.PI*Math.random())}e.on&&(t.heat=Math.max(t.heat,r*.4)),Rn(t,n.c)},meta:{desc:"Langevin/Brownian agitation \u2014 a real temperature in the medium"}},ki={token:"collide",label:"Collide",apply(e,t,n){if(n.dist>=e.range)return;let r=Math.max(0,Math.min(1,e.strength)),s=Math.max(1,t.size);for(let i of n.neighbors(t,s*4)){let a=Math.max(1,i.size),h=t.x-i.x,m=t.y-i.y,p=(t.z??0)-(i.z??0),y=Math.hypot(h,m,p);if(y>=s+a||y<1e-6)continue;let b=h/y,E=m/y,M=p/y,S=(t.vx-i.vx)*b+(t.vy-i.vy)*E+((t.vz??0)-(i.vz??0))*M;if(S>=0)continue;let A=(1+r)*.5*S;t.vx-=A*b,t.vy-=A*E,i.vx+=A*b,i.vy+=A*E,p&&(t.vz=(t.vz??0)-A*M,i.vz=(i.vz??0)+A*M)}},meta:{desc:"elastic pairwise collision \u2014 the hard-sphere billiard force"}},Ei={token:"diffuse",label:"Diffuse",apply(e,t,n){if(n.dist>=e.range)return;let r=n.grid("diffuse");r.deposit(t.x,t.y,e.strength);let s=r.gradient(t.x,t.y);t.vx+=s.x*e.strength,t.vy+=s.y*e.strength},meta:{desc:"pheromone field \u2014 deposit a mark and follow the diffused gradient"}},Si=12,On=7,zi={token:"propagate",label:"Propagate",source(e,t){e.on&&t.frameN%Si===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,h=-n.dy/n.dist;t.vx+=a*i*e.strength*On,t.vy+=h*i*e.strength*On,n.dz&&(t.vz=(t.vz??0)+-n.dz/n.dist*i*e.strength*On),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 r=n.grid("memory");r.deposit(t.x,t.y,e.strength*.15);let s=1+.5*r.sample(t.x,t.y),i=(1-n.dist/e.range)**2*e.strength*.5*s;t.vx+=n.dx/n.dist*i,t.vy+=n.dy/n.dist*i,n.dz&&(t.vz=(t.vz??0)+n.dz/n.dist*i)},meta:{desc:"the field remembers \u2014 occupancy wears in paths that pull harder"}},Ti=[xi,vi,wi,Mi,ki,Ei,zi,Fi];function Xo(e){for(let t of Ti)e.force(t)}var Ai={token:"lens",label:"Lens",kinematic:!0,apply(e,t,n){if(n.dist>=e.range)return;let r=e.strength*(1-n.dist/e.range)*e.spin,s=Math.cos(r),i=Math.sin(r),a=t.vx,h=t.vy;t.vx=a*s-h*i,t.vy=a*i+h*s},meta:{desc:"rotates velocity, preserving speed \u2014 bends paths without adding energy"}},Ci={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"}},Oi=1,Pi=1,Ri={token:"buoyancy",label:"Buoyancy",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let r=Oi/(t.size*(1+t.heat));t.vy-=(Pi-r)*e.strength},meta:{desc:"a constant lift/sink by density difference \u2014 light matter rises, dense settles"}},$i={token:"shear",label:"Shear",apply(e,t,n){if(n.dist>=e.range)return;let r=(t.x-e.cx)*-e.uy+(t.y-e.cy)*e.ux,s=e.strength*(r/e.range)*(1-n.dist/e.range);t.vx+=e.ux*s,t.vy+=e.uy*s},meta:{desc:"a laminar shear gradient \u2014 flow speed grows with perpendicular offset"}},_e=32,Ii=.5,Ni={token:"crystallize",label:"Crystallize",apply(e,t,n){if(n.dist>=e.range||t.heat>=Ii)return;let r=e.cx+Math.round((t.x-e.cx)/_e)*_e,s=e.cy+Math.round((t.y-e.cy)/_e)*_e;t.vx+=(r-t.x)*e.strength,t.vy+=(s-t.y)*e.strength,t.vx*=.9,t.vy*=.9},meta:{desc:"snaps cool matter onto a lattice; melts and frees it when hot"}},Di={token:"align",label:"Align",apply(e,t,n){if(n.dist>=e.range)return;let r=t.vz??0,s=Math.hypot(t.vx,t.vy,r),i=e.strength,a=e.ux,h=e.uy,m=0,p=0,y=0,b=0;for(let M of n.neighbors(t,e.range)){let S=M.vz??0,A=Math.hypot(M.vx,M.vy,S);A>1e-6&&(p+=M.vx/A,y+=M.vy/A,b+=S/A)}let E=Math.hypot(p,y,b);E>1e-6&&(a=p/E,h=y/E,m=b/E),t.vx+=(a*s-t.vx)*i,t.vy+=(h*s-t.vy)*i,(m||r)&&(t.vz=r+(m*s-r)*i)},meta:{desc:"steers toward the neighbour-mean heading (or the body heading when alone)"}};function Li(e,t,n,r){let s=e*r+n*.2,i=t*r-n*.2;return{x:-r*Math.sin(s)*Math.sin(i),y:-r*Math.cos(s)*Math.cos(i)}}var _i=.01,Bi={token:"wind",label:"Wind",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let r=Li(t.x,t.y,n.t,_i);t.vx+=r.x*e.strength,t.vy+=r.y*e.strength},meta:{desc:"divergence-free curl-noise turbulence"}},Wi=.5,qi={token:"cohesion",label:"Cohesion",apply(e,t,n){if(n.dist>=e.range)return;let r=e.range,s=r*Wi,i=e.strength;for(let a of n.neighbors(t,r)){let h=a.x-t.x,m=a.y-t.y,p=(a.z??0)-(t.z??0),y=Math.hypot(h,m,p);if(y<1e-6)continue;let b=h/y,E=m/y,M=p/y;if(y<s){let S=i*(s-y)/s;t.vx-=S*b,t.vy-=S*E,p&&(t.vz=(t.vz??0)-S*M)}else{let S=i*(y-s)/(r-s);t.vx+=S*b,t.vy+=S*E,p&&(t.vz=(t.vz??0)+S*M)}}},meta:{desc:"short-range pressure + mid-range cohesion \u2014 surface tension over neighbours"}},Hi=.5,ji={token:"pressure",label:"Pressure",apply(e,t,n){if(n.dist>=e.range)return;let r=e.range,s=e.strength,i=0,a=n.neighbors(t,r);for(let m of a){let p=Math.hypot(m.x-t.x,m.y-t.y,(m.z??0)-(t.z??0));p<r&&(i+=(1-p/r)**2)}let h=i-Hi;if(!(h<=0))for(let m of a){let p=t.x-m.x,y=t.y-m.y,b=(t.z??0)-(m.z??0),E=Math.hypot(p,y,b);if(E<1e-6||E>=r)continue;let M=s*h*(1-E/r)/E;t.vx+=M*p,t.vy+=M*y,b&&(t.vz=(t.vz??0)+M*b)}},meta:{desc:"SPH density relaxation \u2014 incompressible even-fill via mutual repulsion"}},Yi={token:"hunt",label:"Hunt",apply(e,t,n){if(n.dist>=e.range)return;let r=t.species??0,s=null,i=1/0;for(let b of n.neighbors(t,e.range)){if((b.species??0)===r)continue;let E=b.x-t.x,M=b.y-t.y,S=(b.z??0)-(t.z??0),A=E*E+M*M+S*S;A<i&&(i=A,s=b)}if(!s)return;let a=s.x-t.x,h=s.y-t.y,m=(s.z??0)-(t.z??0),p=Math.hypot(a,h,m)||1,y=r===0?1:-1;t.vx+=a/p*e.strength*y,t.vy+=h/p*e.strength*y,m&&(t.vz=(t.vz??0)+m/p*e.strength*y)},meta:{desc:"two-species pursuit \u2014 predators seek prey, prey flee predators"}},Ui=.35,Gi={token:"link",label:"Link",apply(e,t,n){if(n.dist>=e.range)return;let r=e.range,s=r*Ui,i=e.strength;for(let a of n.neighbors(t,r)){let h=a.x-t.x,m=a.y-t.y,p=(a.z??0)-(t.z??0),y=Math.hypot(h,m,p);if(y<1e-6)continue;let b=y-s,E=.5*i*(b/s);t.vx+=E*(h/y),t.vy+=E*(m/y),p&&(t.vz=(t.vz??0)+E*(p/y))}},meta:{desc:"a Verlet distance constraint \u2014 holds a rest length, so matter ropes and drapes"}},Jo=40,Vi={token:"morph",label:"Morph",apply(e,t,n){let r=e.targets;if(!r||r.length===0)return;let s=Math.min(r.length-1,Math.floor((t.gx??0)*r.length)),i=r[s],a=i.x-t.x,h=i.y-t.y,m=Math.hypot(a,h),p=e.strength;t.vx+=a*p*.02,t.vy+=h*p*.02,t.z&&(t.vz=(t.vz??0)-t.z*p*.02);let b=(1-(m<Jo?1-m/Jo: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)"}},Xi=90,Ji={token:"spawn",label:"Spawn",apply(){},source(e,t){let n=e.life??Xi,r=Math.max(1,Math.round(e.strength*2));e.cap!=null&&e.cap>0&&n>0&&(r=Math.min(r,e.cap/n)),e.emitAcc=(e.emitAcc??0)+r;let s=Math.floor(e.emitAcc);for(e.emitAcc-=s;s>0;s--){let i=((t.rng??Math.random)()-.5)*.6,a=Math.cos(i),h=Math.sin(i),m=e.ux*a-e.uy*h,p=e.ux*h+e.uy*a,y=2+(t.rng??Math.random)()*2;t.spawn({x:e.cx,y:e.cy,vx:m*y,vy:p*y,age:n,heat:.6,...e.species!=null?{species:e.species}:{}})}},meta:{desc:"a source \u2014 emits matter along the heading, budgeted by a lifespan"}},Ki=3,Qi={token:"resonate",label:"Resonate",apply(){},modify(e,t,n){return{strength:1+Math.sin(n.t*Ki*e.spin)}},meta:{desc:"pulses sibling forces with a time-varying strength S(t)=S\u2080(1+sin \u03C9t)"}},Zi=.5,ta={token:"spotlight",label:"Spotlight",apply(){},modify(e,t,n){let r=-n.dx/n.dist,s=-n.dy/n.dist;return{gate:r*e.ux+s*e.uy<Zi}},meta:{desc:"gates sibling forces to an angular cone of the heading"}},ea={token:"screen",label:"Screen",apply(){},meta:{desc:"a quiet zone \u2014 attenuates other bodies' forces on matter inside its radius"}},na={token:"pigment",label:"Pigment",apply(e,t,n){let r=e.tint;!r||n.dist>=e.range*.6||(t.color=t.color?So(t.color,r,.08):r)},meta:{desc:"conserved color transport \u2014 matter takes on and carries a tint"}},oa=.5,Ko=.12,ra={token:"fieldflow",label:"Field Flow",apply(e,t,n){if(e.range>0&&n.dist>=e.range)return;let r=n.fieldAt?.(t.x,t.y);if(!r)return;let s=Math.hypot(r.x,r.y);if(!(s>1e-9))return;let i=r.x/s,a=r.y/s,h=e.range>0?1-n.dist/e.range:1,m=e.strength*h,p=t.vz??0,y=Math.hypot(t.vx,t.vy,p);if(y>1e-6){let M=Math.min(1,m*oa);t.vx+=(i*y-t.vx)*M,t.vy+=(a*y-t.vy)*M,p&&(t.vz=p+(0-p)*M)}t.vx+=i*m*Ko,t.vy+=a*m*Ko;let b=t.vz??0,E=t.vx*t.vx+t.vy*t.vy+b*b;if(E>n.c*n.c){let M=n.c/Math.sqrt(E);t.vx*=M,t.vy*=M,b&&(t.vz=b*M)}e.on&&(t.heat=Math.max(t.heat,h*.4))},meta:{desc:"follow the field lines \u2014 steer onto and stream down the net field a body radiates"}},sa={token:"warp",label:"Warp",kinematic:!0,apply(e,t,n){if(!e.warpHas||t.cap)return;let r=e.absorbR;if(n.dist>=r)return;let s=Math.cos(e.twist??0),i=Math.sin(e.twist??0),a=e.warpScale??1,h=-n.dx/n.dist,m=-n.dy/n.dist,p=h*s-m*i,y=h*i+m*s,b=r*a+6;t.x=e.warpX+p*b,t.y=e.warpY+y*b,t.z&&(t.z=-n.dz/n.dist*b);let E=t.vx,M=t.vy;t.vx=E*s-M*i,t.vy=E*i+M*s,t.heat=Math.max(t.heat,.6)},meta:{desc:"a wormhole throat \u2014 relocates matter to its paired body, conserved"}},ia=[Ai,Ci,Ri,$i,Ni,Di,Bi,qi,ji,Gi,Yi,Vi,Ji,Qi,ta,ea,na,ra,sa];function Qo(e){for(let t of ia)e.force(t)}var Zo=new Set(["css","canvas","svg","typography","spatial","native"]);function tr(e){let t=[];for(let n of e)n.surfaces.some(s=>Zo.has(s))&&!n.reducedMotionEquivalent&&t.push({rule:"field/reduced-motion-equivalent-required",severity:"error",subject:n.id,message:`Projection "${n.id}" can express motion (${n.surfaces.filter(s=>Zo.has(s)).join(", ")}) but declares no reducedMotionEquivalent. Reduced motion must translate the behavior, not remove it.`}),n.accessibilityEquivalent||t.push({rule:"field/accessibility-equivalent-required",severity:"warning",subject:n.id,message:`Projection "${n.id}" declares no accessibilityEquivalent. Accessibility is an alternate projection of the same field state, not a fallback.`});return t}var $n=(e,t)=>t?Object.fromEntries(Object.entries(e).filter(([n])=>t.has(n))):e;function er(e,t){let n=t.metrics?new Set(t.metrics):null,r=t.channels?new Set(t.channels):null,s=t.tokens?new Set(t.tokens):null;return{...e,metrics:$n(e.metrics,n),bodies:e.bodies.filter(i=>!s||i.tokens.some(a=>s.has(a))).map(i=>({...i,metrics:$n(i.metrics,n),dimensions:$n(i.dimensions,n)})),influences:r?e.influences.filter(i=>r.has(i.channel??"linear")):e.influences,lens:t.id}}function nr(e,t,n={}){return{x:e,y:t,strength:n.strength??1,radius:n.radius&&n.radius>0?n.radius:360}}function fe(e,t,n,r,s=.6){let i=r.x-t,a=r.y-n,h=Math.hypot(i,a);if(h===0||h>=r.radius)return e.x=0,e.y=0,e;let m=(1-h/r.radius)*r.strength*s;return e.x=i/h*m,e.y=a/h*m,e}var aa={step:6,maxSteps:400,minStrength:1e-9,loopDist:6,maxTurns:1/0};function or(e,t,n,r,s){let i=[{x:t,y:n}],a=t,h=n,m=s.step,p=s.maxTurns*2*Math.PI,y=0,b=0,E=0;for(let M=0;M<s.maxSteps;M++){let S=e(a,h),A=Math.hypot(S.x,S.y);if(!(A>=s.minStrength))break;let N=S.x/A*r,C=S.y/A*r;if(Number.isFinite(p)){if(y!==0||b!==0){let H=Math.max(-1,Math.min(1,N*y+C*b));if(E+=Math.acos(H),E>p)break}y=N,b=C}if(a+=N*s.step,h+=C*s.step,s.bounds&&(a<-m||h<-m||a>s.bounds.w+m||h>s.bounds.h+m))break;if(M>4&&Math.hypot(a-t,h-n)<s.loopDist){i.push({x:a,y:h});break}i.push({x:a,y:h})}return i}function ca(e,t,n,r={}){let s={...aa,bounds:r.bounds,...r},i=or(e,t,n,-1,s),a=or(e,t,n,1,s);return i.reverse(),i.pop(),i.concat(a)}function rr(e,t,n={}){return t.map(r=>ca(e,r.x,r.y,n)).filter(r=>r.length>1)}var la=8,da=60;function sr(e,t=8){let n={cx:e.cx,cy:e.cy,hw:e.hw,hh:e.hh,ux:e.ux,uy:e.uy,spin:e.spin},r=Ie(n),s=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y);if(s<Math.max(e.range*.06,la)){let p=Math.max(e.range*.18,da),y=e.spin<0?-1:1;r=[{x:e.cx+e.ux*p,y:e.cy+e.uy*p,q:y},{x:e.cx-e.ux*p,y:e.cy-e.uy*p,q:-y}],s=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y)}let i=-e.uy,a=e.ux,h=Math.max(s*.13,18),m=[{x:e.cx,y:e.cy}];for(let p=1;p<=t;p++){let y=p*h;m.push({x:e.cx+i*y,y:e.cy+a*y}),m.push({x:e.cx-i*y,y:e.cy-a*y})}return m}function ir(e,t=18){let n=Math.max(Math.min(e.hw,e.hh)*.8,24),r=[];for(let s=0;s<t;s++){let i=s/t*Math.PI*2;r.push({x:e.cx+Math.cos(i)*n,y:e.cy+Math.sin(i)*n})}return r}function ar(e,t=8){let n=[];for(let r of e)!r.vis||r.tokens.length===0||(r.tokens.includes("magnetism")?n.push(...sr(r,t)):(r.tokens.includes("charge")||r.tokens.includes("gravity"))&&n.push(...ir(r)));return n}function cr(e,t=Math.random){return 3+Math.floor(t()*(e>0?e:1)*3)}function lr(e,t,n,r=6,s=0){let i=Math.hypot(e,t,s)||1;if(i>=n)return{vx:0,vy:0,vz:0,heat:0};let a=1-i/n,h=a*r;return{vx:e/i*h,vy:t/i*h,vz:s/i*h,heat:a*.9}}function dr(e,t,n,r,s=.9,i=80){let a=r>0?r:1;e.vx=(e.vx+t/a)*s,e.vy=(e.vy+n/a)*s,e.x+=e.vx,e.y+=e.vy;let h=Math.hypot(e.x,e.y);h>i&&(e.x=e.x/h*i,e.y=e.y/h*i)}function fr(e,t=.02){return{x:-e.x*t,y:-e.y*t}}function hr(e){let t=e/3e4;return t<.6?.6:t>6?6:t}function ur(e,t,n=-1,r=1600,s=26){let i=0,a=0,h=s*s;for(let m=0;m<t.length;m++){if(m===n)continue;let p=t[m],y=e.x-p.x,b=e.y-p.y,E=y*y+b*b+h;i+=r*y/E,a+=r*b/E}return{x:i,y:a}}function yr(e,t,n,r=16,s=1){let i=(e(t+r,n)-e(t-r,n))/(2*r),a=(e(t,n+r)-e(t,n-r))/(2*r);return{x:-i*s,y:-a*s}}function mr(e,t,n,r,s,i,a,h){if(r.length===0)return;let m=e.particles;for(let p=m.length-1;p>=0&&!(t.length>=n);p--){let y=m[p];if(!y||y.cap||y.heat>=.12)continue;let b=-1,E=1e9,M=0;for(let A=0;A<r.length;A++){let N=Et(r[A],y.x,a,i),C=Math.abs(N-y.y);C<E&&(E=C,b=A,M=N)}if(b<0||E>=64)continue;let S=Math.min(.012,E*4e-4)*(1-y.heat/.12);y.vy+=M>y.y?S:-S,E<20&&y.vx*y.vx+y.vy*y.vy<.3&&h()<.03&&(t.push({wi:b,progress:y.x/s,phase:(h()-.5)*.22*Math.PI,size:y.size,glow:h()<.3,speed:(35e-5+h()*9e-4)*(h()<.5?1:-1)}),e.remove(y))}}function In(e,t,n,r,s,i,a,h,m){for(let p=e.length-1;p>=0;p--){let y=e[p];if(!y)continue;let b=t[y.wi];if(!b)continue;let E=y.progress*i,M=Et(b,E,h,a)+y.phase*32,S=E-n,A=M-r,N=Math.hypot(S,A);if(N<s&&N>.5){let C=(1-N/s)*4;m({x:E,y:M,vx:S/N*C,vy:A/N*C,size:y.size,heat:.9});let H=e.pop();H&&p<e.length&&(e[p]=H)}}}function pr(e,t,n,r,s,i,a,h){let m=p=>p.tokens.some(y=>{let b=r[y];return!!b&&!b.modify&&!b.source});for(let p=e.length-1;p>=0;p--){let y=e[p];if(!y)continue;let b=t[y.wi];if(!b)continue;let E=y.progress*s,M=Et(b,E,a,i)+y.phase*32,S=!1,A=0,N=0;for(let C of n){if(!C.vis||C.when==="active"&&!C.on||C.when&&C.when!=="active")continue;let H=C.tokens,u=C.cx-E,K=C.cy-M,Z=Math.hypot(u,K)||1,lt=C.range*(C.on?1.4:1);if(H.indexOf("wall")>=0&&Math.abs(E-C.cx)<C.hw+6&&Math.abs(M-C.cy)<C.hh+6&&(A=(E<C.cx?-1:1)*1.6,N=(M<C.cy?-1:1)*.8,S=!0),!S&&(H.indexOf("attract")>=0||H.indexOf("sink")>=0||H.indexOf("jet")>=0)&&Z<lt*.8){let mt=1.2+(C.on?1.6:0);A=u/Z*mt,N=K/Z*mt,S=!0}if(!S&&H.indexOf("repel")>=0&&Z<lt*.8){let mt=1.2+(C.on?1.2:0);A=-(u/Z)*mt,N=-(K/Z)*mt,S=!0}if(!S&&H.indexOf("swirl")>=0&&Z<lt*.75&&(A=K/Z*1.2,N=-(u/Z)*1.2,S=!0),!S&&H.indexOf("stream")>=0&&Z<lt*.75&&(A=C.ux*1.3,N=C.uy*1.3,S=!0),!S&&Z<lt*.8&&m(C)){let mt=.8+(C.on?.8:0);A=u/Z*mt,N=K/Z*mt,S=!0}if(S)break}if(S){h({x:E,y:M,vx:A,vy:N,size:y.size,heat:.5});let C=e.pop();C&&p<e.length&&(e[p]=C)}}}function gr(e,t){for(let n of e){if(!n.vis||n.tokens.indexOf("charge")<0&&n.tokens.indexOf("magnetism")<0||n.range<=0)continue;let r=n.range*n.range;for(let s of t){if(s.charge)continue;let i=n.cx-s.x,a=n.cy-s.y;i*i+a*a>=r||(s.charge=i>=0?1:-1)}}}var xr=e=>e<0?0:e>1?1:e;function vr(e){if(!e||e.n===0)return{entropy:0,coherence:1,temperature:0};let t=e.sh/e.n,n=e.ss/e.n,r=e.ss2/e.n,s=xr(.5*t+.5*Math.min(1,r/9)),i=e.ss>1e-9?Math.hypot(e.sx,e.sy)/e.ss:1,a=xr((1-i)*Math.min(1,n/1.5));return{entropy:a,coherence:1-a,temperature:s}}var Be=class{constructor(){V(this,"pending",new Map);V(this,"ids",new WeakMap);V(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((h,m)=>h-m);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 r=n;return String(this.idOf(r.body.el??r.body))}record(t,n){let r=this.pending.get(t);r||this.pending.set(t,r=new Map),r.set(this.keyOf(t,n),n)}flush(t){if(this.pending.size!==0){for(let[n,r]of this.pending)for(let s of r.values())t(n,s);this.pending.clear()}}};function Nn(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 Dn(e,t){switch(e){case"dense":return t.d>.6;case"sparse":return t.d<.2;case"engaged":return t.on;case"captured":return t.accreted>0;default:return!1}}var wr={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 fa(){return globalThis.process?.env?.NODE_ENV!=="production"}var Mr=fa();function kr(){return Mr}var br=new Set;function Ln(e,t){if(!Mr)return;let n=`${e}:${t}`;br.has(n)||(br.add(n),console.warn(`[Fundamental:${e}] ${t}`))}var ha={"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 Er(e,t={}){let n=ha[e];if(!n)return null;let r=[...n.body];t.risk==="high"&&!r.includes("thermal")&&r.push("thermal");let s={"data-body":r.join(" ")};return t.intensity!=null&&(s["data-strength"]=String(t.intensity)),n.range!=null&&(s["data-range"]=String(n.range)),n.feedback&&(s["data-feedback"]=""),n.render?.length&&(s["data-render"]=n.render.join(" ")),{body:r.join(" "),strength:t.intensity,range:n.range,feedback:n.feedback??!1,render:n.render??["particles"],attributes:s}}function zr(e){let t=(A,N)=>{let C=Number.parseFloat(e.get(A)??"");return Number.isFinite(C)?C:N},n=t("strength",.5),r=t("angle",0)*Math.PI/180,s=e.get("spin"),i=s==null?1:Number.isFinite(Number.parseFloat(s))?Number.parseFloat(s):0,a=(e.get("body")??"").split(/\s+/).filter(Boolean),h=Oe(a),m=e.get("life"),p=e.get("cap"),y=Number.parseFloat(m??""),b=Number.parseFloat(p??""),E=m!=null||p!=null||e.has("budget")||e.has("sink"),M=e.get("authority");return{tokens:a,authority:M==="kinematic"||M==="dynamic"?M:"anchored",classified:h,...Number.isFinite(y)&&y>0?{life:y}:{},...Number.isFinite(b)&&b>0?{cap:b}:{},budgeted:E,strength:n,range:t("range",280),absorbR:t("absorb",64),capacity:t("max",60),spin:i,angle:r,ux:Math.cos(r),uy:Math.sin(r),when:e.get("when")??"",feedback:e.has("feedback"),shaped:e.has("shaped"),...e.get("species")!=null&&Number.isFinite(Number.parseFloat(e.get("species")))?{species:Number.parseFloat(e.get("species"))}:{},...(()=>{let A=e.get("affects");if(A==null)return{};let N=A.split(",").map(C=>Number.parseFloat(C.trim())).filter(C=>Number.isFinite(C));return N.length?{affects:new Set(N)}:{}})(),fmin:t("fmin",0),fmax:t("fmax",0),opsz: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 ua(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 ya(e){let t=wr[e];return t?t.map(n=>zr(ua(n))):[]}function ma(e){let t=(e.tagName??"element").toLowerCase(),n=e.id?`#${e.id}`:"",r=typeof e.className=="string"&&e.className?`.${e.className.split(/\s+/)[0]}`:"";return`<${t}${n}${r}>`}function pa(e,t="<body>"){!e.classified||e.classified.sources.length===0||e.budgeted||(e.life=wn,e.cap=bn,kr()&&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="${wn}", data-cap="${bn}") \u2014 declare one to make the source's budget explicit (workover v0.3 source rules).`))}function Fr(e,t){return pa(t,ma(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 ga(e){return{get:t=>e.getAttribute("data-"+t),has:t=>e.hasAttribute("data-"+t)}}function he(e,t){return Fr(e,zr(t??ga(e)))}var Sr={source:"jet",sink:"sink",anchor:"tether",boundary:"wall",sensor:"",display:""};function xa(e){let t=null,n=e.getAttribute("data-intent");if(n){let s=e.getAttribute("data-intensity"),i=Er(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 Sr&&(t={body:Sr[s],feedback:""})}if(!t)return null;let r=t;return{get:s=>e.getAttribute("data-"+s)??r[s]??null,has:s=>e.hasAttribute("data-"+s)||s in r}}function Tr(e){let t=[];return e.querySelectorAll("[data-body]").forEach(n=>{t.push(he(n))}),e.querySelectorAll("[data-preset]").forEach(n=>{let r=n;for(let s of ya(r.dataset.preset??""))t.push(Fr(r,s))}),e.querySelectorAll("[data-intent]:not([data-body]), [data-field-role]:not([data-body]):not([data-intent])").forEach(n=>{let r=xa(n);r&&t.push(he(n,r))}),t}function va(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 r=t.getAttribute("data-range");if(r!=null){let a=Number.parseFloat(r);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 We(e,t,n,r=0,s=0){let i=n*.15;for(let a of e){let h=a.rect?a.rect():a.el.getBoundingClientRect(),m=h.left-r,p=h.top-s;a.cx=m+h.width/2,a.cy=p+h.height/2,a.hw=h.width/2,a.hh=h.height/2,a.on=a.el.dataset.active==="1",a.vis=p+h.height>-i&&p<n+i&&m+h.width>-i&&m<t+i,va(a)}}var Ar="field:register-body",Cr="field:unregister-body",Or="field:update-body";var qe=class{constructor(){V(this,"hosts",new Map)}register(t){this.hosts.set(t.element,t)}unregister(t){this.hosts.delete(t)}get size(){return this.hosts.size}bodies(t){let n=[];for(let[r,s]of this.hosts){if(!r.isConnected){this.hosts.delete(r);continue}let i=s.attrs?wa(s.attrs,r):void 0,a=t(r,i);s.getRect&&(a.rect=s.getRect),s.writeTarget&&(a.writeTarget=s.writeTarget),n.push(a)}return n}};function wa(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 He(e,t,n){if(e===t)return .5;let r=(n-e)/(t-e);return r<0?0:r>1?1:r}var Pr=Object.freeze([]);function _n(e,t,n,r,s){let i={x:He(e,t,s),y:0},a={x:1,y:He(t,n,s)},h={x:He(r,n,s),y:1},m={x:0,y:He(e,r,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)|(r>s?1:0)){case 0:case 15:return Pr;case 1:case 14:return[p(m,h)];case 2:case 13:return[p(h,a)];case 3:case 12:return[p(m,a)];case 4:case 11:return[p(i,a)];case 6:case 9:return[p(i,h)];case 7:case 8:return[p(m,i)];case 5:return[p(m,i),p(h,a)];case 10:return[p(m,h),p(i,a)];default:return Pr}}function Bn(e,t,n,r,s,i,a,h=1){if(a<=0)return;let m=Math.max(0,Math.floor((s-a)/r)),p=Math.min(t-1,Math.ceil((s+a)/r)),y=Math.max(0,Math.floor((i-a)/r)),b=Math.min(n-1,Math.ceil((i+a)/r)),E=a*a;for(let M=y;M<=b;M++)for(let S=m;S<=p;S++){let A=S*r-s,N=M*r-i,C=A*A+N*N;if(C>=E)continue;let H=1-Math.sqrt(C)/a,u=M*t+S;e[u]=e[u]+h*H*H}}function $r(e,t,n){let r=-1,s=1/0;for(let i=0;i<n.length;i++){let a=n[i],h=a.x-e,m=a.y-t,p=h*h+m*m;p<s&&(s=p,r=i)}return r}function Ir(e,t,n){let r=[];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&&r.push({x1:i+.5,y1:s-.5,x2:i+.5,y2:s+.5}),s+1<n&&e[(s+1)*t+i]!==a&&r.push({x1:i-.5,y1:s+.5,x2:i+.5,y2:s+.5})}return r}var Nr=24,ba=.12,Ma=.22,ue=class{constructor(t,n){V(this,"grid");V(this,"peak",.001);V(this,"cell",Nr);this.grid=new oe(Math.max(1,t),Math.max(1,n),"diffuse",Nr)}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(Ma,ba);let n=this.grid.max(),r=n>this.peak?.25:.03;this.peak+=(Math.max(n,.001)-this.peak)*r}norm(t,n){return bt(this.grid.sample(t,n)/this.peak,0,1)}gradient(t,n){if(this.peak<=0)return{x:0,y:0};let r=this.grid.gradient(t,n);return{x:r.x/this.peak,y:r.y/this.peak}}};var ka={position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"0",pointerEvents:"none",display:"block"},Dr=Object.entries(ka).map(([e,t])=>`${e.replace(/[A-Z]/g,n=>"-"+n.toLowerCase())}:${t}`).join(";");function Lr(e){let t=e.width,n=e.height,r=null,s=0;return{root:{querySelectorAll:()=>[],querySelector:()=>null,contains:()=>!1},viewport:()=>({width:t,height:n,dpr:1}),scrollY:()=>0,scrollHeight:()=>n,reducedMotion:()=>!1,hidden:()=>!1,raf:a=>(r=a,1),cancelRaf:()=>{r=null},createCanvas:()=>{throw new Error("headlessHost does not render \u2014 use render:'none' and the signal read-outs (onFeedback / sampleScalar / readParticles).")},onResize:()=>()=>{},onScroll:()=>()=>{},onVisibility:()=>()=>{},onInput:()=>()=>{},onBodyEvent:()=>()=>{},tick(a){s=a??s+1e3/60;let h=r;r=null,h?.(s)},resize(a,h){t=a,n=h}}}var _r="10px ui-monospace, SFMono-Regular, Menlo, monospace";function Wn(e,t){let n=0,r=0;return{size(s,i,a){n=s,r=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,r)},segments(s,i){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath();for(let a=0;a+3<s.length;a+=4)t.moveTo(s[a],s[a+1]),t.lineTo(s[a+2],s[a+3]);t.stroke()},polyline(s,i){if(!(s.length<4)){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath(),t.moveTo(s[0],s[1]);for(let a=2;a+1<s.length;a+=2)t.lineTo(s[a],s[a+1]);t.stroke()}},rect(s,i,a,h,m,p,y,b){t.fillStyle=`rgba(${m},${p},${y},${b})`,t.fillRect(s,i,a,h)},text(s,i,a,h,m,p,y){t.font=_r,t.textBaseline="middle",t.fillStyle=`rgba(${h},${m},${p},${y})`,t.fillText(s,i,a)},measureText(s){return t.font=_r,t.measureText(s).width}}}var qn=(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 r=e.dataset.fxLit==="1";n>.5&&!r?(e.dataset.fxLit="1",e.dispatchEvent(new CustomEvent("field:lit",{detail:{value:n}}))):n<.4&&r&&(e.dataset.fxLit="0",e.dispatchEvent(new CustomEvent("field:dim",{detail:{value:n}})))}},Hn=qn;var je=class{constructor(t){V(this,"lit",!1);V(this,"lastEdgeMs",-1/0);V(this,"cfg");this.cfg=t}update(t,n){let r=n-this.lastEdgeMs>=this.cfg.debounceMs;return!this.lit&&t>=this.cfg.enter&&r?(this.lit=!0,this.lastEdgeMs=n,"entered"):this.lit&&t<=this.cfg.exit&&r?(this.lit=!1,this.lastEdgeMs=n,"exited"):null}get isLit(){return this.lit}reset(){this.lit=!1,this.lastEdgeMs=-1/0}};var Ea={strengthen:1.5,decay:.3,remember:.2},jn=e=>e<0?0:e>1?1:e;function Br(e,t,n,r,s=Ea){e.active=t,e.tension=jn(n),e.strength=jn(e.strength+(t?s.strengthen:-s.decay)*r),e.memory=jn(e.memory+(t?s.remember:-s.remember*.5)*r)}function Wr(e,t,n=Math.random){let r=[],s=t.absorbR+6;for(let i of e){if(i.cap!==t)continue;let a=n()*Math.PI*2,h=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)*h,i.vy=Math.sin(a)*h,i.z&&(i.z=0),i.vz&&(i.vz=0),i.heat=1,i.age=void 0,r.push(i)}return t.accreted=0,r}function Yn(e){if(e.capacity<=0)return 0;let t=e.accreted/e.capacity;return t<0?0:t>1?1:t}function qr(e,t){return t&&!e?{fire:"captured",armed:!0}:!t&&e?{fire:"released",armed:!1}:{fire:null,armed:e}}function Hr(e,t){let n=[];for(let r of e)r.when!=="active"||!r.tokens.includes("sink")||(r.wasOn&&!r.on&&r.accreted>0&&(t(r),n.push(r)),r.wasOn=r.on);return n}function Un(e,t){let n=t.cx-e.x,r=t.cy-e.y;return n*n+r*r<t.absorbR*t.absorbR}function jr(e,t,n=.14){let r=e+(t-e)*n;return r<.001?0:r>.999?1:r}function Yr(e,t,n,r){let s=e.x+t.x,i=e.y+t.y,a=t.x+(n.x-s)*r,h=t.y+(n.y-i)*r,m=1-r;return{tx:a,ty:h,scale:m,opacity:m}}function Sa(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 za(e){let t=0;for(let n of e)t+=n.heat;return t}function Ur(e){let t=Sa(e),n=za(e);return{kinetic:t,thermal:n,total:t+n,count:e.length}}var Fa={neutral:{vx:0,vy:0,charge:0,m:1,heat:0},positive:{vx:1,vy:0,charge:1,m:1,heat:0},negative:{vx:1,vy:0,charge:-1,m:1,heat:0},still:{vx:0,vy:0,charge:1,m:1,heat:0},fast:{vx:6,vy:0,charge:1,m:1,heat:0},hot:{vx:0,vy:0,charge:0,m:1,heat:1},massive:{vx:0,vy:0,charge:0,m:6,heat:0}};function Ta(e,t,n){let r=e.cx-t,s=e.cy-n;return{dx:r,dy:s,dist:Math.max(Math.hypot(r,s),1),form:{},c:12,G:1,t:0}}function Gn(e,t,n,r,s,i=Fa.neutral){let a=Ho(),h=Ta(n,r,s);h.accum=a;for(let m of t){let p=e[m];if(!p)continue;let y={x:r,y:s,vx:i.vx,vy:i.vy,charge:i.charge,m:i.m,heat:i.heat,size:1,cap:null};try{Cn(p,n,y,h)}catch{}}return a}var Ye={x:0,y:0},Ue=[0,0,0];function Ge(e,t={}){let n=null;if((t.render??"none")!=="none"&&(n=e.getContext("2d"),!n))throw new Error("Fundamental: 2D canvas context unavailable");let r=t.overlayCanvas??null,s=n?r?.getContext("2d")??null:null,i=t.overlayBackend??(r&&s?Wn(r,s):null),a=new De,h=1,m=new Map,p=Uo(),y=new Map,b=o=>(y.get(o)?.size??0)>0;function E(o,c){let l=y.get(o);if(l)for(let x of l)x(c)}let M=new Be;function S(o,c){b(o)&&M.record(o,c)}function A(){M.flush(E)}let N=new WeakMap,C=new Map,H=new Map;function u(o){let c=b("enter")||b("exit"),l=b("met");if(!c&&!l)return;for(let f=0;f<o.length;f++){let v=o[f];if(c){let g=C.get(v);g||C.set(v,g=new Set);let d=v.range*v.range;for(let w=0;w<o.length;w++){if(f===w)continue;let k=o[w],z=k.cx-v.cx,T=k.cy-v.cy,F=z*z+T*T<d;F&&!g.has(k)?(g.add(k),b("enter")&&S("enter",{body:v,other:k})):!F&&g.has(k)&&(g.delete(k),b("exit")&&S("exit",{body:v,other:k}))}}if(l){let g=H.get(v);g||H.set(v,g=new Set);for(let d=f+1;d<o.length;d++){let w=o[d],k=Math.abs(w.cx-v.cx)<v.hw+w.hw&&Math.abs(w.cy-v.cy)<v.hh+w.hh;k&&!g.has(w)?(g.add(w),S("met",{a:v,b:w})):!k&&g.has(w)&&g.delete(w)}}}let x=new Set(o);for(let f of[C,H])for(let v of f.keys())x.has(v)||f.delete(v)}let K=[],Z=new WeakMap,lt=[],mt=0,Y=new WeakMap,P=new WeakMap,U=new Map,Q=new Map;if(Go(p),Xo(p),Qo(p),!t.host)throw new Error("Fundamental: createField requires opts.host. Use @fundamental-engine/vanilla (createField/mountField) or @fundamental-engine/elements / @fundamental-engine/react, or pass browserHost() from @fundamental-engine/dom.");let B=t.host,ft=[],rt=B.reducedMotion(),vt=En[t.theme??Sn]??En[Sn],$={accent:t.accent??Re(t.palette)[0]??Ce[0]??"#4da3ff",density:t.density&&t.density>0?t.density:1,render:t.render??"none",waves:t.waves??!0,waveStyle:t.waveStyle??"linear",waveCenter:t.waveCenter??null,background:t.background??"opaque",mass:t.mass??!1,separation:t.separation!=null&&t.separation>=0?t.separation:0,attention:t.attention??!1,causality:t.causality??!1,heatmap:t.heatmap??!1,overlay:t.overlay??"off",gridWarp:t.gridWarp!=null&&t.gridWarp>=0?t.gridWarp:1,gridIntensity:t.gridIntensity!=null&&t.gridIntensity>=0?Math.min(t.gridIntensity,1):.16,gradientCool:t.gradientCool?gt(t.gradientCool):vt.cool,gradientWarm:t.gradientWarm?gt(t.gradientWarm):vt.warm,waveBaseline:(t.waveBaseline??vt.wave).map(gt),dprCap:t.dprCap&&t.dprCap>0?t.dprCap:2,depth:t.depth&&t.depth>0?t.depth:0,integrator:t.integrator==="fixed"?"fixed":"legacy",feedbackSink:t.feedbackSink??qn},tt=null,L=[],_=0,D=0,St=0,G=0,st=!1,dt=1,Xt=0,me=new WeakMap,It=0,Nt=0,Xn=!0,Jn={...Pe.ambient.preset},Ze="ambient",Kn=new WeakMap,es=0,Bt=o=>{if(o.el&&o.el.id)return o.el.id;let c=Kn.get(o);return c===void 0&&(c=`body-${es++}`,Kn.set(o,c)),c},Qn=o=>{let c={density:o.d,count:o.count,engaged:o.on?1:0};o.attn!==void 0&&(c.attention=o.attn),o.capacity>0&&(c.load=o.accreted/o.capacity);let l=o.metrics?{entropy:o.metrics.entropy,coherence:o.metrics.coherence,temperature:o.metrics.temperature}:{};return{metrics:c,dimensions:l}},ns=0,Wt=new Map,os=o=>({id:o.id,label:o.label,channels:o.channels.slice(),surfaces:o.surfaces.slice(),...o.reducedMotionEquivalent!==void 0?{reducedMotionEquivalent:o.reducedMotionEquivalent}:{},...o.accessibilityEquivalent!==void 0?{accessibilityEquivalent:o.accessibilityEquivalent}:{}}),pe=()=>[...Wt.values()].map(os),ge=[];function rs(){for(let o of ge)Wt.get(o.id)?.apply?.(o.source(),o.target)}let ss={register(o){return Wt.set(o.id,o),()=>{Wt.get(o.id)===o&&Wt.delete(o.id)}},unregister(o){Wt.delete(o)},get(o){return Wt.get(o)},list:pe,apply(o,c,l){Wt.get(o)?.apply?.(c,l)},bind(o,c,l){let x={id:o,target:c,source:l};return ge.push(x),()=>{let f=ge.indexOf(x);f>=0&&ge.splice(f,1)}},lint:()=>tr(pe())},Zn=.9,to=8;function is(){for(let o of L){if(o.authority!=="dynamic"||!o.vis)continue;o.bx===void 0&&(o.bx=o.cx,o.by=o.cy,o.bvx=0,o.bvy=0);let c=o.bx??o.cx,l=o.by??o.cy,x=L.filter(z=>z!==o&&z.vis&&z.tokens.length>0),{fx:f,fy:v}=Vt(x,p.forces,W,c,l),g=1/Math.max(o.M,1e-4),d=(o.bvx??0)+f*g*W.dt,w=(o.bvy??0)+v*g*W.dt;d*=Zn,w*=Zn;let k=Math.hypot(d,w);if(k>to){let z=to/k;d*=z,w*=z}o.bvx=d,o.bvy=w,o.bx=c+d*W.dt,o.by=l+w*W.dt,o.cx=o.bx,o.cy=o.by}}let eo=globalThis.structuredClone,as=o=>{if(o==null)return o;try{return eo?eo(o):JSON.parse(JSON.stringify(o))}catch{try{return JSON.parse(JSON.stringify(o))}catch{return o}}},wt=[],qt=[],no=0,Gt=null,ut=t.rng??Math.random,tn=t.now??(()=>performance.now()),ht=rt?1:0,en=NaN,Dt=null,se=null,Ht=0,Lt=0,xe=null,nn=[],on=null,ve=null,cs=Math.round(130*$.density)*4,xt={x:0,y:0,k:0},yt=null,_t=null,oo=0,ro=0,so=Re(t.palette).map(gt),it=gt($.accent),we=null,rn=[],jt=[],Jt=[],Kt=[],sn=[],an=[],Qt=[],be=new qe,cn=!1,ln=()=>{cn||(cn=!0,queueMicrotask(()=>{cn=!1,ke()}))},ls=o=>{for(let c of["--d","--field-density","--load","--mass","--entropy","--coherence","--temperature"])o.style.removeProperty(c)},ds=o=>{let c=o.detail;c?.element&&(be.register(c),ln())},fs=o=>{let c=o.detail;c?.element&&(be.unregister(c.element),ls(c.writeTarget??c.element),ln())},hs=ln,At={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null},io=tn(),W={dx:0,dy:0,dz:0,dist:1,form:{...Pe.ambient.preset},W:0,H:0,D:$.depth,integrator:$.integrator,t:0,frameN:0,dt:rt?0:1,c:12,G:1,scrollV:0,rng:ut,spark:(o,c,l,x)=>ao(o,c,l,x),supernova:o=>{let c=Wr(a.particles,o,ut),l=new Set(c);for(let x of a.particles){if(l.has(x))continue;let f=x.x-o.cx,v=x.y-o.cy,g=Math.hypot(f,v)||1;if(g<320){let d=(1-g/320)*4;x.vx+=f/g*d,x.vy+=v/g*d,x.heat=Math.max(x.heat,.8)}}In(qt,wt,o.cx,o.cy,320,_,D,W.t,x=>void a.add(Zt(x))),Ms(o),dn(o.el,"field:saturated",{peak:c.length}),o.el.dataset.fxCap==="1"&&(o.el.dataset.fxCap="0",te(o.el,"released",{accreted:0,load:0}),b("release")&&S("release",{body:o,count:c.length}),N.delete(o))},spawn:o=>{a.size>=cs||a.add(Zt(o))},neighbors:(o,c)=>a.neighbors(o,c),grid:o=>{let c=m.get(o);if(!c){let l=o.startsWith("wave")?"wave":o.startsWith("memory")?"memory":"diffuse";c=new oe(_,D,l),m.set(o,c)}return c}};function ao(o,c,l,x){if(rt||Kt.length>260)return;let f=x?gt(x):[255,122,69],v=cr(l);for(let g=0;g<v;g++){let d=ut()*6.28318,w=.8+ut()*(l>0?l:1)*1.7;Kt.push({x:o,y:c,vx:Math.cos(d)*w,vy:Math.sin(d)*w,life:1,c:f})}}function Zt(o={}){let c=o.size??.7+ut()*1.8;return{id:o.id??h++,x:o.x??ut()*_,y:o.y??ut()*D,vx:o.vx??(ut()-.5)*.25,vy:o.vy??(ut()-.5)*.18,z:o.z??($.depth>0?ut()*$.depth:0),vz:o.vz??($.depth>0?(ut()-.5)*.18:0),m:o.m??($.mass?c:1),heat:o.heat??0,size:c,gx:o.gx??ut(),gy:o.gy??ut(),gz:o.gz??ut(),cap:null,...o.age!=null?{age:o.age}:{},...o.color!=null?{color:o.color}:{},...o.species!=null?{species:o.species}:{}}}let Me=[];function us(){if(!Me.length)return;let o=a.particles;for(let c=0;c<o.length;c++){let l=Me[c%Me.length];o[c].atom=l;let x=typeof l.weight=="number"?Math.max(0,Math.min(1,l.weight)):.5;o[c].size*=.6+x*.9,o[c].m*=.6+x*1.2}}function co(){a.clear();let o=Math.round(130*$.density);for(let c=0;c<o;c++)a.add(Zt());us(),wt=$.waves?No($.waveBaseline):[],qt=$.waves?Do(wt.length,$.density,ut):[],no=qt.length}function ke(){let o=Tr(B.root);if(be.size>0){let x=new Set(o.map(f=>f.el));L=o.concat(be.bodies(he).filter(f=>!x.has(f.el)))}else L=o;K.length>0&&(L=L.concat(K)),We(L,_,D,St,G),Es();let c=new Map(jt.map(x=>[x.el,x]));jt=[...B.root.querySelectorAll("[data-move]")].map(x=>{let f=x,v=f.getBoundingClientRect(),g=Number.parseFloat(f.dataset.mass??""),d=Number.isFinite(g)?g:hr(v.width*v.height),w=(f.dataset.move??"").trim()==="layout",k=f.hasAttribute("data-dock"),z=f.hasAttribute("data-warp"),T=c.get(f);return T?{el:f,o:T.o,mEl:d,layout:w,dockable:k,dock:T.dock,docked:T.docked,warpable:z,warpCool:T.warpCool}:{el:f,o:{x:0,y:0,vx:0,vy:0},mEl:d,layout:w,dockable:k,dock:{dock:0},docked:null,warpable:z,warpCool:0}}),sn=[...B.root.querySelectorAll("[data-on]")].map(x=>{let f=x;return{el:f,body:L.find(v=>v.el===f)??null,bindings:Nn(f.dataset.on??"")}}),an=[...B.root.querySelectorAll("[data-class]")].map(x=>{let f=x;return{el:f,body:L.find(v=>v.el===f)??null,bindings:Nn(f.dataset.class??"")}});for(let x of L){if(!x.pair)continue;let f=null;try{f=B.root.querySelector(x.pair)}catch{f=null}x.pairBody=f?L.find(v=>v.el===f):void 0}let l=new Map(Jt.map(x=>[x.el,x]));for(let[x,f]of l)if(!B.root.contains(x))for(let v of f.emitted)v.remove();Jt=[...B.root.querySelectorAll("[data-emit]")].map(x=>{let f=x,v=f.dataset.emit??"",g=null;try{g=v?B.root.querySelector(v):null}catch{g=null}let d=Math.max(0,Math.round(Number.parseFloat(f.dataset.max??"")||8)),w=l.get(f);if(w){let k=w.emitted.filter(z=>z.isConnected);for(;k.length>d;)k.pop().remove();return{el:f,tmpl:g,cap:d,emitted:k}}return{el:f,tmpl:g,cap:d,emitted:[]}})}function ys(){for(let o of L)if(o.pairBody){if(!o.pairBody.el.isConnected){o.warpHas=!1,o.pairBody=void 0;continue}o.pairBody.vis?(o.warpX=o.pairBody.cx,o.warpY=o.pairBody.cy,o.warpHas=!0):o.warpHas=!1}else o.pair&&(o.warpHas=!1)}function ms(){if(!(Jt.length===0||W.frameN%30!==0))for(let o of Jt){if(!o.tmpl||o.emitted.length>=o.cap)continue;let c=o.tmpl.cloneNode(!0);c.removeAttribute("id"),c.setAttribute("aria-hidden","true"),c.setAttribute("inert",""),c.dataset.fieldEmitted="",o.el.appendChild(c),o.emitted.push(c)}}function ps(){if(sn.length!==0)for(let o of sn){let c=o.body?{d:o.body.d,on:o.body.on,accreted:o.body.accreted}:{d:0,on:o.el.dataset.active==="1",accreted:0};for(let l of o.bindings){let x=Dn(l.trigger,c);x&&!l.armed?(l.armed=!0,o.el.dispatchEvent(new CustomEvent(l.event,{bubbles:!0,detail:{trigger:l.trigger,d:c.d,on:c.on,accreted:c.accreted}}))):x||(l.armed=!1)}}}function gs(){if(an.length!==0)for(let o of an){let c=o.body?{d:o.body.d,on:o.body.on,accreted:o.body.accreted}:{d:0,on:o.el.dataset.active==="1",accreted:0};for(let l of o.bindings){let x=Dn(l.trigger,c);x&&!l.armed?(l.armed=!0,o.el.classList.add(l.event)):!x&&l.armed&&(l.armed=!1,o.el.classList.remove(l.event))}}}function te(o,c,l){o.dispatchEvent(new CustomEvent("field:"+c,{bubbles:!0,composed:!0,detail:l})),o.dispatchEvent(new CustomEvent("forces:"+c,{bubbles:!0,composed:!0,detail:l}))}function xs(){for(let o of L){if(!o.vis||o.tokens.indexOf("sink")<0)continue;let c=o.el.dataset.fxCap==="1",l=qr(c,o.accreted>0);l.fire==="captured"?(o.el.dataset.fxCap="1",te(o.el,"captured",{accreted:o.accreted,load:Yn(o)}),b("absorb")&&S("absorb",{body:o,count:o.accreted}),N.set(o,o.accreted)):l.fire==="released"&&(o.el.dataset.fxCap="0",te(o.el,"released",{accreted:0,load:0}),b("release")&&S("release",{body:o,count:N.get(o)??0}),N.delete(o))}}let vs=[{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"}],ws=120;function dn(o,c,l){o.dispatchEvent(new CustomEvent(c,{bubbles:!0,composed:!0,detail:l}))}function lo(o,c,l,x,f,v){let g=o.get(c);g||o.set(c,g=new Map);let d=g.get(x.metric);d||g.set(x.metric,d=new je({enter:x.enter,exit:x.exit,debounceMs:ws}));let w=d.update(f,v);w==="entered"?dn(l,x.rise,{metric:x.metric,value:f}):w==="exited"&&dn(l,x.fall,{metric:x.metric,value:f})}function bs(o){for(let c of L)if(!(!c.vis||c.tokens.length===0))for(let l of vs){let x;switch(l.metric){case"density":x=c.d;break;case"attention":$.attention&&(x=c.attn??1);break;case"entropy":x=c.metrics?.entropy;break}x!==void 0&&lo(Y,c,c.el,l,x,o)}for(let c of lt)lo(P,c.agent,c.from.el,{metric:"memory",enter:.6,exit:.3,rise:"field:memory-threshold",fall:"field:memory-faded"},c.agent.memory,o)}function Ms(o){for(let c of jt)c.docked===o&&(c.docked=null,c.dock.dock=0,c.el.getAttribute("aria-hidden")==="true"&&c.el.removeAttribute("aria-hidden"),c.el.removeAttribute("inert"),c.el.style.opacity="",te(c.el,"released",{}))}function ks(){if(jt.length===0)return;let o=jt.map(c=>{let l=c.el.getBoundingClientRect();return{x:l.left-St+l.width/2,y:l.top-G+l.height/2}});for(let c=0;c<jt.length;c++){let l=jt[c];if(!l.el.isConnected){l.docked&&(l.docked=null,l.dock.dock=0);continue}let x=o[c].x,f=o[c].y;if(l.docked){let k={x:x-l.o.x,y:f-l.o.y};l.dock.dock=jr(l.dock.dock,1);let z=Yr(k,l.o,{x:l.docked.cx,y:l.docked.cy},l.dock.dock);l.el.style.transform=`translate(${z.tx.toFixed(2)}px, ${z.ty.toFixed(2)}px) scale(${z.scale.toFixed(3)})`,l.el.style.opacity=z.opacity.toFixed(3),l.dock.dock>=1&&l.el.getAttribute("aria-hidden")!=="true"&&(l.el.setAttribute("aria-hidden","true"),l.el.setAttribute("inert",""));continue}At.x=x,At.y=f,At.vx=0,At.vy=0,At.heat=0,At.cap=null;for(let k of L){if(!k.vis||k.tokens.length===0||k.el===l.el)continue;let z=k.cx-x,T=k.cy-f,F=Math.hypot(z,T);W.dx=z,W.dy=T,W.dist=F<1?1:F;for(let O of k.tokens)p.forces[O]?.apply(k,At,W)}At.cap=null;let v=fr(l.o),g=At.vx+v.x,d=At.vy+v.y;if(l.layout){let k=ur({x,y:f},o,c),z=yr((T,F)=>a.near(T,F,40).length,x,f,16,6);g+=k.x+z.x,d+=k.y+z.y}let w={x:x-l.o.x,y:f-l.o.y};if(dr(l.o,g,d,l.mEl,.9),l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.dockable){let k={x:w.x+l.o.x,y:w.y+l.o.y},z=L.find(T=>T.vis&&T.el!==l.el&&T.tokens.indexOf("sink")>=0&&Un(k,T));z&&(l.docked=z,te(l.el,"captured",{sink:z.el}))}if(l.warpCool>0&&(l.warpCool-=1),l.warpable&&l.warpCool===0){let k={x:w.x+l.o.x,y:w.y+l.o.y},z=L.find(T=>T.vis&&T.el!==l.el&&T.warpHas&&T.tokens.indexOf("warp")>=0&&Un(k,T));z&&(l.o.x=z.warpX-w.x,l.o.y=z.warpY-w.y,l.o.vx=0,l.o.vy=0,l.el.style.transform=`translate(${l.o.x.toFixed(2)}px, ${l.o.y.toFixed(2)}px)`,l.warpCool=45,te(l.el,"relocated",{from:z.el}))}}}function Es(){Qt.length&&(Qt=Qt.filter(o=>o.el.isConnected?!0:(o.el.removeEventListener("pointerenter",o.enter),o.el.removeEventListener("pointerleave",o.leave),o.el.removeEventListener("focus",o.enter),o.el.removeEventListener("blur",o.leave),delete o.el.dataset.fxEngaged,!1))),B.root.querySelectorAll("[data-hot]").forEach(o=>{let c=o;if(c.dataset.fxEngaged==="1")return;c.dataset.fxEngaged="1";let l=()=>{c.dataset.active="1",we=c.dataset.color??null;let f=c.closest("[data-index][data-threads]");if(f){let v=[...f.querySelectorAll("[data-hot]")].filter(g=>g!==c);fn(v.map(g=>({a:c,b:g,color:c.dataset.color??void 0})))}},x=()=>{c.dataset.active="0",we=null,fn(null)};c.addEventListener("pointerenter",l),c.addEventListener("pointerleave",x),c.addEventListener("focus",l),c.addEventListener("blur",x),Qt.push({el:c,enter:l,leave:x})})}function fn(o){rn=(o??[]).map(c=>({a:c.a,b:c.b,c:gt(c.color??$.accent),seed:ut()*6.28}))}function Ss(){if(rn.length===0)return;let o=W.t;n.globalCompositeOperation="lighter";for(let c of rn){let l=c.a.getBoundingClientRect(),x=c.b.getBoundingClientRect(),f=l.left-St+l.width/2,v=l.top-G+l.height/2,g=x.left-St+x.width/2,d=x.top-G+x.height/2,[w,k,z]=c.c;n.strokeStyle=`rgba(${w},${k},${z},0.22)`,n.lineWidth=1,n.beginPath(),n.moveTo(f,v),n.lineTo(g,d),n.stroke();for(let T=0;T<3;T++){let F=(o*.6+c.seed+T/3)%1,O=f+(g-f)*F,q=v+(d-v)*F;n.fillStyle=`rgba(${w},${k},${z},${(1-F)*.9})`,n.beginPath(),n.arc(O,q,2.2,0,6.28318),n.fill()}}n.globalCompositeOperation="source-over"}let Ee=0,zs=[1/0,1.5,1.25,1];function Se(o){if(!n)return;let c=Math.min(o||1,$.dprCap,zs[Ee]??1/0);e.width=Math.floor(_*c),e.height=Math.floor(D*c),e.style.width=_+"px",e.style.height=D+"px",n.setTransform(c,0,0,c,0,0),i?.size(_,D,c)}function fo(){let o=B.viewport();_=o.width,D=o.height,St=o.originX??0,G=o.originY??0,st=o.originX!=null||o.originY!=null,Se(o.dpr),W.W=_,W.H=D,dt=B.scrollHeight()-D||1;for(let c of m.values())c.resize(_,D);$.heatmap&&(tt?tt.resize(_,D):tt=new ue(_,D)),co(),ke()}function Fs(){let o=W.t,c=16;if($.waveStyle==="circular"){let l=Gt||{x:_/2,y:D/2},x=Math.min(_,D)*.48;for(let f of wt){let[v,g,d]=f.color;n.beginPath();let w=.08,k=!0;for(let F=0;F<=2*Math.PI+.01;F+=w){let O=de(f,F,o,x),q=l.x+Math.cos(F)*O,R=l.y+Math.sin(F)*O;k?(n.moveTo(q,R),k=!1):n.lineTo(q,R)}n.closePath();let z=f.baseFrac*x+f.offsetY,T=n.createRadialGradient(l.x,l.y,Math.max(0,z-f.amp),l.x,l.y,z+f.amp+80);T.addColorStop(0,`rgba(${v},${g},${d},${(.08+f.depth*.04)*ht})`),T.addColorStop(1,`rgba(${v},${g},${d},0)`),n.fillStyle=T,n.fill()}n.globalCompositeOperation="lighter";for(let f of wt){let[v,g,d]=f.color;n.beginPath();let w=.08,k=!0;for(let z=0;z<=2*Math.PI+.01;z+=w){let T=de(f,z,o,x),F=l.x+Math.cos(z)*T,O=l.y+Math.sin(z)*T;k?(n.moveTo(F,O),k=!1):n.lineTo(F,O)}n.closePath(),n.lineWidth=5,n.strokeStyle=`rgba(${v},${g},${d},${(.05+f.depth*.04)*ht})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${v},${g},${d},${(.3+f.depth*.22)*ht})`,n.stroke()}n.globalCompositeOperation="source-over"}else{for(let l of wt){let[x,f,v]=l.color;n.beginPath(),n.moveTo(0,Et(l,0,o,D,1,1,xt));for(let w=0;w<=_;w+=c)n.lineTo(w,Et(l,w,o,D,1,1,xt));n.lineTo(_,D),n.lineTo(0,D),n.closePath();let g=l.baseFrac*D+l.offsetY-l.amp,d=n.createLinearGradient(0,g,0,g+320);d.addColorStop(0,`rgba(${x},${f},${v},${(.11+l.depth*.05)*ht})`),d.addColorStop(1,`rgba(${x},${f},${v},0)`),n.fillStyle=d,n.fill()}n.globalCompositeOperation="lighter";for(let l of wt){let[x,f,v]=l.color;n.beginPath(),n.moveTo(0,Et(l,0,o,D,1,1,xt));for(let g=0;g<=_;g+=c)n.lineTo(g,Et(l,g,o,D,1,1,xt));n.lineWidth=5,n.strokeStyle=`rgba(${x},${f},${v},${(.05+l.depth*.04)*ht})`,n.stroke(),n.lineWidth=1.2,n.strokeStyle=`rgba(${x},${f},${v},${(.3+l.depth*.22)*ht})`,n.stroke()}n.globalCompositeOperation="source-over"}}function Ts(){n.globalCompositeOperation="lighter";let o=W.t,c=0;if($.waveStyle==="circular"){let l=Gt||{x:_/2,y:D/2},x=Math.min(_,D)*.48;for(let f of qt){let v=wt[f.wi];if(!v){c++;continue}W.dt&&(f.progress+=f.speed,f.progress>1?f.progress-=1:f.progress<0&&(f.progress+=1));let g=f.progress*2*Math.PI,d=de(v,g,o,x)+f.phase*32,w=l.x+Math.cos(g)*d,k=l.y+Math.sin(g)*d,[z,T,F]=v.color,O=f.glow?.6+.4*Math.sin(o*2.2+c):.85;f.glow&&(n.fillStyle=`rgba(${z},${T},${F},${.16*O*ht})`,n.beginPath(),n.arc(w,k,f.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${z},${T},${F},${O*ht})`,n.beginPath(),n.arc(w,k,f.size,0,6.28318),n.fill(),c++}}else for(let l of qt){let x=wt[l.wi];if(!x){c++;continue}W.dt&&(l.progress+=l.speed,l.progress>1?l.progress-=1:l.progress<0&&(l.progress+=1));let f=l.progress*_,v=Et(x,f,o,D,1,1,xt)+l.phase*32,[g,d,w]=x.color,k=l.glow?.6+.4*Math.sin(o*2.2+c):.85;l.glow&&(n.fillStyle=`rgba(${g},${d},${w},${.16*k*ht})`,n.beginPath(),n.arc(f,v,l.size+2.5,0,6.28318),n.fill()),n.fillStyle=`rgba(${g},${d},${w},${k*ht})`,n.beginPath(),n.arc(f,v,l.size,0,6.28318),n.fill(),c++}n.globalCompositeOperation="source-over"}function As(){if(!$.attention)return;for(let l of L)l.attn=1;let o=L.filter(l=>l.vis&&l.tokens.length>0);if(o.length===0)return;let c=Co(o);for(let l=0;l<o.length;l++)o[l].attn=c[l]}function Cs(){if(!$.causality)return;let o=L.filter(l=>l.vis&&l.tokens.length>0);if(o.length===0)return;if(o.length===1){ho(o[0],o[0].d);return}let c=Oo(o.map(l=>({d:l.d,cx:l.cx,cy:l.cy})));for(let l=0;l<o.length;l++)ho(o[l],bt(o[l].d+c[l],0,1))}function ho(o,c){$.feedbackSink(o.el,{lit:c})}function Os(){for(let o of L){if(!o.feedback)continue;let c=To(o.count,o.on);o.d+=(c-o.d)*.08;let l=o.writeTarget??o.el;if(o.fmax){let w=Ao(o.fmin,o.fmax,o.d);me.get(l)!==w&&(me.set(l,w),l.style.fontVariationSettings=`"wght" ${w}`+(o.opsz?`, "opsz" ${o.opsz}`:""))}let x=tt?tt.norm(o.cx,o.cy):void 0,f=o.tokens.indexOf("sink")>=0&&o.capacity>0?Yn(o):void 0,v=vr(o.thermo),g=o.metrics??(o.metrics={entropy:0,coherence:1,temperature:0});g.entropy+=(v.entropy-g.entropy)*.08,g.coherence+=(v.coherence-g.coherence)*.08,g.temperature+=(v.temperature-g.temperature)*.08;let d={density:o.d,heatmapDensity:x,load:f,entropy:g.entropy,coherence:g.coherence,temperature:g.temperature};$.feedbackSink(l,d),o.onFeedback?.(d)}}function Ps(){if(Kt.length!==0){n.globalCompositeOperation="lighter";for(let o=Kt.length-1;o>=0;o--){let c=Kt[o];if(!c)continue;if(c.x+=c.vx,c.y+=c.vy,c.vx*=.9,c.vy*=.9,c.life*=.85,c.life<.05){Kt.splice(o,1);continue}let[l,x,f]=c.c;n.fillStyle=`rgba(${l},${x},${f},${.18*c.life})`,n.beginPath(),n.arc(c.x,c.y,2+c.life*4,0,6.28318),n.fill(),n.fillStyle=`rgba(${l},${x},${f},${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 Yt=null,ze=null,ee=null;function Rs(){if(!tt)return;let o=D>0?bt((1.15-Xt/D)/.85,0,1):1;if(o<=.01)return;let c=tt.cell,l=Math.max(1,Math.ceil(_/c)),x=Math.max(1,Math.ceil(D/c));if(Yt||(Yt=B.createCanvas(),ze=Yt.getContext("2d")),!!ze){if((Yt.width!==l||Yt.height!==x)&&(Yt.width=l,Yt.height=x,ee=null),ee===null||Nt%3===0){ee===null&&(ee=ze.createImageData(l,x));let f=it,v=ee.data;for(let g=0;g<x;g++)for(let d=0;d<l;d++){let w=tt.norm(d*c+c/2,g*c+c/2),k=(g*l+d)*4;v[k]=f[0],v[k+1]=f[1],v[k+2]=f[2],v[k+3]=Math.round(bt(w*.5*ht,0,1)*255)}ze.putImageData(ee,0,0)}n.globalCompositeOperation="lighter",n.imageSmoothingEnabled=!0,n.globalAlpha=o,n.drawImage(Yt,0,0,_,D),n.globalAlpha=1,n.globalCompositeOperation="source-over"}}function $s(){$.background==="transparent"?$.render==="trails"?(n.globalCompositeOperation="destination-out",n.fillStyle="rgba(0,0,0,0.22)",n.fillRect(0,0,_,D),n.globalCompositeOperation="source-over"):n.clearRect(0,0,_,D):($.render==="trails"?n.fillStyle="rgba(5,6,11,0.22)":n.fillStyle="rgb(5,6,11)",n.fillRect(0,0,_,D)),Fs(),tt&&Ee<2&&Rs(),Ts();let o=$.render!=="metaballs"&&$.render!=="streamlines";n.globalCompositeOperation="lighter";let c=it,l=_/2,x=D*.4,f=Math.hypot(Math.max(l,_-l),Math.max(x,D-x))||1;if(ve===null||Nt%6===0){ve=[];for(let g of L){if(!g.tint)continue;let d=(g.range||200)*1.4;ve.push({b:g,r2:d*d,rgb:gt(g.tint)})}}let v=ve;if(o)for(let g of a.particles){if(g.cap){n.fillStyle=`rgba(${c[0]},${c[1]},${c[2]},${.55*ht})`,n.beginPath(),n.arc(g.x,g.y,1.3,0,6.28318),n.fill();continue}let d=Math.min(1,Math.hypot(g.x-l,g.y-x)/f),w=d*d,k=g.heat;Eo(Ue,w,k,c,$.gradientCool,$.gradientWarm);let z=Ue[0],T=Ue[1],F=Ue[2];if(v.length){let pt=0,nt=null;for(let ct of v){let Ct=g.x-ct.b.cx,Ot=g.y-ct.b.cy,ie=Ct*Ct+Ot*Ot;if(ie>=ct.r2)continue;let I=1-Math.sqrt(ie/ct.r2);I>pt&&(pt=I,nt=ct.rgb)}if(nt){let ct=pt*.7;z+=(nt[0]-z)*ct,T+=(nt[1]-T)*ct,F+=(nt[2]-F)*ct}}if(g.color){let[pt,nt,ct]=gt(g.color);z+=(pt-z)*.75,T+=(nt-T)*.75,F+=(ct-F)*.75}let O=$.depth>0?1-Math.min(Math.abs(g.z??0)/$.depth,1)*.55:1,q=(g.size*(1-.4*w)+k*2)*O,R=bt((.5-.3*w+k*.5)*ht*O,0,1),X=z|0,at=T|0,Mt=F|0;n.fillStyle=`rgba(${X},${at},${Mt},${.12*R})`,n.beginPath(),n.arc(g.x,g.y,q+1.2,0,6.28318),n.fill(),n.fillStyle=`rgba(${X},${at},${Mt},${R})`,n.beginPath(),n.arc(g.x,g.y,q,0,6.28318),n.fill()}if(Ps(),Ss(),n.globalCompositeOperation="source-over",$.render==="links"){n.globalCompositeOperation="lighter";let g=it,d=90;n.lineWidth=.6;for(let w of a.particles)if(!w.cap)for(let k of a.neighbors(w,d)){if(k.x<w.x||k.x===w.x&&k.y<w.y)continue;let z=Rr(Math.hypot(k.x-w.x,k.y-w.y),d);z<=0||(n.strokeStyle=`rgba(${g[0]},${g[1]},${g[2]},${z})`,n.beginPath(),n.moveTo(w.x,w.y),n.lineTo(k.x,k.y),n.stroke())}n.globalCompositeOperation="source-over"}if($.render==="metaballs"){let k=Math.ceil(_/16)+1,z=Math.ceil(D/16)+1;!Dt||Dt.length!==k*z?Dt=new Float32Array(k*z):Dt.fill(0);for(let F of a.particles)F.cap||Bn(Dt,k,z,16,F.x,F.y,34,1);let T=it;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${T[0]},${T[1]},${T[2]},${.5*ht})`,n.lineWidth=1.4,n.lineCap="round",n.beginPath();for(let F=0;F<z-1;F++)for(let O=0;O<k-1;O++){let q=Dt[F*k+O],R=Dt[F*k+O+1],X=Dt[(F+1)*k+O+1],at=Dt[(F+1)*k+O],Mt=_n(q,R,X,at,.9);if(!Mt.length)continue;let pt=O*16,nt=F*16;for(let ct of Mt)n.moveTo(pt+ct.x1*16,nt+ct.y1*16),n.lineTo(pt+ct.x2*16,nt+ct.y2*16)}n.stroke(),n.globalCompositeOperation="source-over"}if($.render==="voronoi"){let w=Math.ceil(_/18)+1,k=Math.ceil(D/18)+1;(!se||se.length!==w*k)&&(se=new Int32Array(w*k));let z=a.particles,T=new Map;for(let O=0;O<z.length;O++)T.set(z[O],O);for(let O=0;O<k;O++)for(let q=0;q<w;q++){let R=q*18,X=O*18,at=a.near(R,X,54),Mt=-1;if(at.length){let pt=$r(R,X,at);pt>=0&&(Mt=T.get(at[pt])??-1)}se[O*w+q]=Mt}let F=it;n.globalCompositeOperation="lighter",n.strokeStyle=`rgba(${F[0]},${F[1]},${F[2]},${.32*ht})`,n.lineWidth=1,n.beginPath();for(let O of Ir(se,w,k))n.moveTo(O.x1*18,O.y1*18),n.lineTo(O.x2*18,O.y2*18);n.stroke(),n.globalCompositeOperation="source-over"}if($.render==="streamlines"||$.render==="flow"){let d=it;if(n.lineWidth=1,n.lineCap="round",xe===null||yt||Nt%3===0){let w=[],k=[],z=0;for(let T=46/2;T<_;T+=46)for(let F=46/2;F<D;F+=46){let{fx:O,fy:q}=Vt(L,p.forces,W,T,F);if(yt){let X=fe(Ye,T,F,yt,.04);O+=X.x,q+=X.y}let R=Math.hypot(O,q);if(!(R>1e-9)){k.push({gx:T,gy:F});continue}w.push({gx:T,gy:F,ux:O/R,uy:q/R,mag:R}),R>z&&(z=R)}Ht===0?Ht=z:Ht=z>Ht?Ht*.7+z*.3:Ht*.9+z*.1,xe=w,nn=k}if(nn.length){n.fillStyle=`rgba(${d[0]},${d[1]},${d[2]},0.05)`;for(let w of nn)n.fillRect(w.gx-.5,w.gy-.5,1,1)}if(Ht>0&&xe)for(let w of xe){let k=Math.sqrt(w.mag/Ht),z=46*.46*(.28+.72*k),T=w.gx+w.ux*z,F=w.gy+w.uy*z;n.strokeStyle=`rgba(${d[0]},${d[1]},${d[2]},${bt(.1+k*.5,0,.72)})`,n.beginPath(),n.moveTo(w.gx,w.gy),n.lineTo(T,F);let O=3.4;n.moveTo(T,F),n.lineTo(T-w.ux*O-w.uy*O*.6,F-w.uy*O+w.ux*O*.6),n.moveTo(T,F),n.lineTo(T-w.ux*O+w.uy*O*.6,F-w.uy*O-w.ux*O*.6),n.stroke()}}}function uo(o){return(o===void 0?[]:Array.isArray(o)?o:[o]).filter(l=>l!=="off")}function yo(o,c,l){let f=it;if(on===null||yt||Nt%3===0){let d=[],w=0;for(let k=44/2;k<_;k+=44)for(let z=44/2;z<D;z+=44){let{fx:T,fy:F}=Vt(L,p.forces,W,k,z);if(yt){let q=fe(Ye,k,z,yt,.04);T+=q.x,F+=q.y}let O=Math.hypot(T,F);O>1e-9&&(d.push({gx:k,gy:z,ux:T/O,uy:F/O,mag:O}),O>w&&(w=O))}Lt===0?Lt=w:Lt=w>Lt?Lt*.7+w*.3:Lt*.9+w*.1,on=d}if(Lt<=0)return;let v={r:f[0],g:f[1],b:f[2],alpha:0,width:1.2},g=new Float64Array(12);for(let d of on){let w=l?bt(d.mag/Lt,0,1):Math.sqrt(d.mag/Lt),k=44*.5*(.25+.75*w),z=d.gx+d.ux*k,T=d.gy+d.uy*k,F=3.6;g[0]=d.gx,g[1]=d.gy,g[2]=z,g[3]=T,g[4]=z,g[5]=T,g[6]=z-d.ux*F-d.uy*F*.6,g[7]=T-d.uy*F+d.ux*F*.6,g[8]=z,g[9]=T,g[10]=z-d.ux*F+d.uy*F*.6,g[11]=T-d.uy*F-d.ux*F*.6,v.alpha=bt(.12+w*.55,0,.8),o.segments(g,v)}}function Is(o){let c=ar(L);if(!c.length)return;let l=rr((v,g)=>Le(L,p.forces,v,g),c,{step:6,maxSteps:200,bounds:{w:_,h:D},loopDist:8}),x=it,f={r:x[0],g:x[1],b:x[2],alpha:.42,width:1.1};for(let v of l){if(v.length<2)continue;let g=new Float32Array(v.length*2);for(let d=0;d<v.length;d++)g[d*2]=v[d].x,g[d*2+1]=v[d].y;o.polyline(g,f)}}function Ns(o){let l=22*$.gridWarp,x=48*.46,f=Math.floor(_/48)+2,v=Math.floor(D/48)+2,g=new Float32Array(f*v),d=new Float32Array(f*v),w=0,k=new Float32Array(f*v);for(let I=0;I<v;I++)for(let j=0;j<f;j++){let{fx:et,fy:J}=Vt(L,p.forces,W,j*48,I*48),ot=Math.hypot(et,J),kt=I*f+j;ot>1e-9&&(g[kt]=et/ot,d[kt]=J/ot,k[kt]=ot,ot>w&&(w=ot))}let z=[it,[120,110,255],[240,70,255],[255,50,130]],T=8,F=I=>w>0?Math.sqrt(k[I]/w):0,O=I=>Math.round(F(I)*T),q=I=>{let j=I/T,et=Fn(z,j);return{r:et[0],g:et[1],b:et[2],alpha:Math.min(1,$.gridIntensity*(.3+.85*j)),width:j>.55?1.4:1}},R=new Float32Array(f*v),X=new Float32Array(f*v);for(let I=0;I<f*v;I++){let j=F(I);R[I]=g[I]*j*l,X[I]=d[I]*j*l}let at=new Float32Array(f*v),Mt=new Float32Array(f*v);for(let I=0;I<v;I++)for(let j=0;j<f;j++){let et=0,J=0,ot=0;for(let Pt=-1;Pt<=1;Pt++)for(let Rt=-1;Rt<=1;Rt++){let Tt=j+Rt,$t=I+Pt;if(Tt<0||$t<0||Tt>=f||$t>=v)continue;let ne=$t*f+Tt;et+=R[ne],J+=X[ne],ot++}let kt=I*f+j;at[kt]=et/ot,Mt[kt]=J/ot}let pt=48*1.5,nt=(I,j)=>{let et=j*f+I,J=at[et],ot=Mt[et],kt=Math.hypot(J,ot);kt>x&&(J=J/kt*x,ot=ot/kt*x);let Pt=I*48,Rt=j*48,Tt=Math.min(Pt,_-Pt,Rt,D-Rt),$t=Tt<=0?0:Tt<pt?Tt/pt:1;return[Pt+J*$t,Rt+ot*$t]},ct=4,Ct=I=>{let j=I.length>>1;if(j<3)return I;let et=[I[0],I[1]];for(let J=0;J<j-1;J++){let ot=(J>0?J-1:0)<<1,kt=J<<1,Pt=J+1<<1,Rt=(J+2<j?J+2:j-1)<<1,Tt=I[ot],$t=I[ot+1],ne=I[kt],yn=I[kt+1],mn=I[Pt],pn=I[Pt+1],wo=I[Rt],bo=I[Rt+1];for(let gn=1;gn<=ct;gn++){let ae=gn/ct,xn=ae*ae,Mo=xn*ae;et.push(.5*(2*ne+(-Tt+mn)*ae+(2*Tt-5*ne+4*mn-wo)*xn+(-Tt+3*ne-3*mn+wo)*Mo),.5*(2*yn+(-$t+pn)*ae+(2*$t-5*yn+4*pn-bo)*xn+(-$t+3*yn-3*pn+bo)*Mo))}}return et},Ot=(I,j)=>Math.max(O(I*f+j),O(I*f+j+1)),ie=(I,j)=>Math.max(O(j*f+I),O((j+1)*f+I));for(let I=0;I<v;I++){let j=Ot(I,0),et=[...nt(0,I),...nt(1,I)];for(let J=1;J<f-1;J++){let ot=Ot(I,J);ot===j?et.push(...nt(J+1,I)):(o.polyline(Ct(et),q(j)),et=[...nt(J,I),...nt(J+1,I)],j=ot)}o.polyline(Ct(et),q(j))}for(let I=0;I<f;I++){let j=ie(I,0),et=[...nt(I,0),...nt(I,1)];for(let J=1;J<v-1;J++){let ot=ie(I,J);ot===j?et.push(...nt(I,J+1)):(o.polyline(Ct(et),q(j)),et=[...nt(I,J),...nt(I,J+1)],j=ot)}o.polyline(Ct(et),q(j))}}let zt=null;function mo(o,c,l){let v=Math.ceil(_/24)+1,g=Math.ceil(D/24)+1;!zt||zt.length!==v*g?zt=new Float32Array(v*g):zt.fill(0);let d=!1;for(let F of a.particles){if(F.cap)continue;let O=c(F);O<=0||(d=!0,Bn(zt,v,g,24,F.x,F.y,42,O))}if(!d)return;let w=0;for(let F=0;F<zt.length;F++)zt[F]>w&&(w=zt[F]);if(w<=0)return;let k=it,z=[.25,.5,.78],T=[];for(let F=0;F<z.length;F++){let O=z[F]*w;T.length=0;for(let q=0;q<g-1;q++)for(let R=0;R<v-1;R++){let X=zt[q*v+R],at=zt[q*v+R+1],Mt=zt[(q+1)*v+R+1],pt=zt[(q+1)*v+R],nt=_n(X,at,Mt,pt,O);if(!nt.length)continue;let ct=R*24,Ct=q*24;for(let Ot of nt)T.push(ct+Ot.x1*24,Ct+Ot.y1*24,ct+Ot.x2*24,Ct+Ot.y2*24)}T.length&&o.segments(T,{r:k[0],g:k[1],b:k[2],alpha:l*(.45+.55*(F/(z.length-1))),width:1+F*.3})}}function Ds(o){let f=it,v={r:f[0],g:f[1],b:f[2],alpha:0,width:1.1},g=new Float64Array(4);for(let d=104/2;d<_;d+=104)for(let w=104/2;w<D;w+=104){let k=d,z=w;for(let T=0;T<24;T++){let{fx:F,fy:O}=Vt(L,p.forces,W,k,z);if(yt){let at=fe(Ye,k,z,yt,.04);F+=at.x,O+=at.y}let q=Math.hypot(F,O);if(!(q>1e-9))break;let R=k+F/q*9,X=z+O/q*9;if(R<0||X<0||R>_||X>D)break;g[0]=k,g[1]=z,g[2]=R,g[3]=X,v.alpha=.34*(1-T/24),o.segments(g,v),k=R,z=X}}}function Ls(o){let c=it;for(let l of L){if(!l.vis||!l.feedback)continue;let x=`d ${l.d.toFixed(2)}`,f=l.cx+l.hw+8,v=l.cy;o.rect(f-3,v-7,o.measureText(x)+6,14,c[0],c[1],c[2],bt(.3+l.d*.55,0,.85)),o.text(x,f,v+.5,5,6,11,.92)}}function _s(o,c){if(o.clear(),!(!c.length||_===0||D===0))for(let l of c){l==="streamlines"?yo(o,!1,!1):l==="force-vectors"?yo(o,!1,!0):l==="field-lines"?Is(o):l==="grid"?Ns(o):l==="temperature"?mo(o,f=>f.heat,.5):l==="energy"?mo(o,f=>.5*f.m*(f.vx*f.vx+f.vy*f.vy),.42):l==="path"?Ds(o):l==="data"&&Ls(o);let x=Q.get(l);x&&x(o,W,_,D)}}function hn(o){Nt++,W.t=(o-io)/1e3,W.frameN=Nt;let c=Number.isFinite(en)?(o-en)/16.6667:1;if(en=o,W.dt=rt?0:bt(c,.2,2),ht<1&&(ht=Math.min(1,ht+.012)),$o(W.form,Jn,.03),st){let d=B.viewport();St=d.originX??0,G=d.originY??0}let l=B.scrollY(),x=l-Xt;if(W.scrollV=(W.scrollV??0)*.7+Math.abs(x)*.3,Xt=l,x!==0&&!st)for(let d of L)d.cy-=x;for(let d of wt){let w=l*(.025+d.depth*.08);d.offsetY+=(w-d.offsetY)*.04}if(L.length&&Nt%6===0&&(We(L,_,D,St,G),u(L),Hr(L,W.supernova)),W.dt!==0&&is(),lt.length&&W.dt){let d=W.dt/60;for(let w of lt)Br(w.agent,w.from.d>.08,0,d)}let f=null;for(let d of L)if(d.on&&d.vis){f=d;break}let v=yt??f;if(xt.k+=((v?1:0)-xt.k)*.07,v){let d=yt?yt.x:f.cx,w=yt?yt.y:f.cy;xt.x=xt.x?xt.x+(d-xt.x)*.16:d,xt.y=xt.y?xt.y+(w-xt.y)*.16:w}Nt%30===0&&(dt=B.scrollHeight()-D||1);let g=we?gt(we):Fn(so,l/dt);if(it=[it[0]+(g[0]-it[0])*.08,it[1]+(g[1]-it[1])*.08,it[2]+(g[2]-it[2])*.08],$.accent=zn(it),a.reindex(),As(),W.dt&&gr(L,a.particles),yt&&W.dt)for(let d of a.particles){if(d.cap)continue;let w=fe(Ye,d.x,d.y,yt,.6);d.vx+=w.x,d.vy+=w.y}if($.waveStyle==="circular")if($.waveCenter)Gt=typeof $.waveCenter=="function"?$.waveCenter():$.waveCenter;else{let d=L.find(w=>w.tokens.includes("star")||w.tokens.includes("vortex"));d?Gt={x:d.cx,y:d.cy}:Gt={x:_/2,y:D/2}}else Gt=null;if(ys(),jo({store:a,bodies:L,env:W,forces:p.forces,conditions:p.conditions,waves:wt,waveStyle:$.waveStyle,waveCenter:Gt,separation:$.separation}),_t&&(_t.x=oo,_t.y=ro,_t.vx=0,_t.vy=0,_t.heat=Math.min(1,_t.heat+.2)),W.dt){for(let d of m.values())d.step();tt&&tt.update(a.particles),mr(a,qt,no,wt,_,D,W.t,ut),pr(qt,wt,L,p.forces,_,D,W.t,d=>void a.add(Zt(d))),ks(),ms()}if(Os(),rs(),Cs(),ps(),gs(),xs(),bs(o),A(),n&&$.render!=="none"&&Xn&&(!rt||Nt%4===0)&&($s(),i)){let d=uo($.overlay);d.length&&_s(i,d)}It=B.raf(hn)}function un(o){let c=Pe[o];c&&(Jn={...c.preset},Ze=o)}let Fe="",po=io;function go(){let o=B.viewport().height*.5,c="";B.root.querySelectorAll("[data-formation]").forEach(l=>{let x=l.getBoundingClientRect();x.top<=o&&x.bottom>=o&&(c=l.dataset.formation??"")}),c&&c!==Fe&&(Fe=c,un(c))}let xo=()=>void(po=tn()),Bs=()=>{xo(),go()},vo=setInterval(()=>{tn()-po>6e3&&Fe!=="ambient"&&(Fe="ambient",un("ambient"))},1200);vo.unref?.();let Ws=()=>fo();fo();let qs=()=>{B.hidden()?(B.cancelRaf(It),It=0):It||(It=B.raf(hn))};return ft.push(B.onResize(Ws)),ft.push(B.onScroll(Bs)),ft.push(B.onVisibility(qs)),ft.push(B.onInput(xo)),ft.push(B.onBodyEvent(Ar,ds)),ft.push(B.onBodyEvent(Cr,fs)),ft.push(B.onBodyEvent(Or,hs)),go(),It=B.raf(hn),{projections:ss,scan:ke,rescan:ke,setAccent:o=>{$.accent=o,it=gt(o)},setPalette:o=>{let c=Re(o);so=c.map(gt);let l=c[0];l&&($.accent=l,it=gt(l))},setFormation:un,setWaveStyle:o=>{$.waveStyle=o},setWaveCenter:o=>{$.waveCenter=o},setSeparation:o=>{$.separation=o>=0?o:0},setAttention:o=>{if($.attention=o,!o)for(let c of L)c.attn=1},setCausality:o=>{if($.causality=o,!o)for(let c of L)c.el.style.removeProperty("--lit"),c.el.dataset.fxLit="0"},setRender:o=>{if(o!=="none"&&!n){if(n=e.getContext("2d"),!n){console.warn(`Fundamental: setRender('${o}') could not acquire a 2d context; staying in render 'none'`);return}r&&!s&&(s=r.getContext("2d"),s&&!i&&(i=t.overlayBackend??Wn(r,s))),Se(B.viewport().dpr)}$.render=o},setOverlay:o=>{$.overlay=o,uo(o).length||i?.clear()},setHeatmap:o=>{if($.heatmap=o,o)!tt&&_>0&&(tt=new ue(_,D));else if(tt){tt.clear(),tt=null;for(let c of L)(c.writeTarget??c.el).style.removeProperty("--field-heatmap-density")}},setDprCap:o=>{$.dprCap=o>0?o:2,n&&Se(B.viewport().dpr)},setQualityTier:o=>{let c=Math.max(0,Math.min(3,Math.floor(o||0)));c!==Ee&&(Ee=c,n&&Se(B.viewport().dpr))},threads:fn,burst:(o,c,l)=>{for(let f of a.particles){let v=lr(f.x-o,f.y-c,160,6,f.z??0);v.heat!==0&&(f.vx+=v.vx,f.vy+=v.vy,v.vz&&(f.vz=(f.vz??0)+v.vz),f.heat=Math.max(f.heat,v.heat),l&&(f.color=l))}In(qt,wt,o,c,160,_,D,W.t,f=>void a.add(Zt(f))),ao(o,c,2,l)},flowTo:(o,c,l)=>{yt=nr(o,c,l)},clearFlow:()=>{yt=null},seed:o=>{Me=o,co()},atomAt:(o,c)=>{let l=null,x=1/0;for(let f of a.near(o,c,24)){if(f.atom==null)continue;let v=(f.x-o)**2+(f.y-c)**2+(f.z??0)**2;v<x&&(x=v,l=f.atom)}return l},focusAt:(o,c)=>{let l=null,x=1/0;for(let f of a.near(o,c,24)){if(f.atom==null)continue;let v=(f.x-o)**2+(f.y-c)**2+(f.z??0)**2;v<x&&(x=v,l=f)}return _t=l,l?(oo=l.x,ro=l.y,l.atom??null):null},clearFocus:()=>{_t=null},particleCount:()=>a.size,readParticles:o=>{let c=a.particles,l=Math.floor(o.length/5),x=0;for(let f=0;f<c.length&&x<l;f++){let v=c[f];if(v.report!==void 0)continue;let g=x*5;o[g]=v.x,o[g+1]=v.y,o[g+2]=v.z??0,o[g+3]=v.heat,o[g+4]=v.size,x++}return x},readParticleIds:o=>{let c=a.particles,l=0;for(let x=0;x<c.length&&l<o.length;x++){let f=c[x];f.report===void 0&&(o[l++]=f.id??0)}return l},readParticleChannels:(o,c)=>{let l=a.particles,x=0;for(let f=0;f<l.length;f++){let v=l[f];if(!("report"in v&&v.report!==void 0)){if(x>=Math.min(...c.map(g=>g.length)))break;for(let g=0;g<o.length&&!(g>=c.length);g++){let d=o[g];c[g][x]=d==="x"?v.x:d==="y"?v.y:d==="z"?v.z??0:d==="vx"?v.vx:d==="vy"?v.vy:d==="heat"?v.heat:d==="size"?v.size:d==="m"?v.m:d==="id"?v.id??0:d==="age"?v.age??0:d==="charge"?v.charge??0:0}x++}}return x},registerOverlay:(o,c)=>(Q.set(o,c),()=>{Q.delete(o)}),addAgent:o=>{let c=Zt({x:o.x,y:o.y,z:o.z,species:o.species});return c.vx=0,c.vy=0,o.z===void 0&&$.depth<=0&&(c.z=0),o.mass!==void 0&&(c.m=o.mass),c.maxSpeed=o.maxSpeed,c.report=o.report,a.add(c),{particle:c,remove:()=>a.remove(c)}},addBody:o=>{let c={"data-body":Array.isArray(o.tokens)?o.tokens.join(" "):String(o.tokens)};o.strength!=null&&(c["data-strength"]=String(o.strength)),o.range!=null&&(c["data-range"]=String(o.range)),o.spin!=null&&(c["data-spin"]=String(o.spin)),o.angle!=null&&(c["data-angle"]=String(o.angle)),o.color!=null&&(c["data-color"]=o.color);let l=()=>{let d=o.rect();return{left:d.left,top:d.top,right:d.left+d.width,bottom:d.top+d.height,width:d.width,height:d.height,x:d.left,y:d.top,toJSON:()=>({})}},x={tagName:"DIV",id:"",className:"",dataset:o.color!=null?{color:o.color}:{},getAttribute:d=>c[d]??null,hasAttribute:d=>d in c,getBoundingClientRect:l,dispatchEvent:()=>!0,setAttribute:()=>{},removeAttribute:()=>{},style:{setProperty:()=>{},removeProperty:()=>{},getPropertyValue:()=>""}},f=he(x);f.rect=l,f.data=o.data,o.authority&&(f.authority=o.authority),f.feedback=!0;let v={};f.onFeedback=d=>{Object.assign(v,d),o.onFeedback?.(d)},K.push(f),L=L.concat(f),We([f],_,D,St,G);let g={data:o.data,get channels(){return v},set:d=>{d.strength!=null&&(c["data-strength"]=String(d.strength)),d.range!=null&&(c["data-range"]=String(d.range)),d.spin!=null&&(c["data-spin"]=String(d.spin)),d.angle!=null&&(c["data-angle"]=String(d.angle)),d.color!=null&&(c["data-color"]=d.color,x.dataset.color=d.color,f.tint=d.color)},remove:()=>{let d=K.indexOf(f);d>=0&&K.splice(d,1),L=L.filter(w=>w!==f);for(let w=lt.length-1;w>=0;w--){let k=lt[w];(k.from===f||k.to===f)&<.splice(w,1)}}};return Z.set(g,f),g},addEdge:(o,c,l)=>{let x=Z.get(o),f=Z.get(c);if(!x||!f)throw new Error("addEdge: both arguments must be handles returned by addBody on this field.");let v={id:`e${mt++}`,from:"",to:"",type:l?.type??"related",strength:l?.strength??.5,tension:0,memory:0,active:!1},g={agent:v,from:x,to:f,fromData:o.data,toData:c.data};return lt.push(g),{set:d=>{d.strength!=null&&(v.strength=d.strength<0?0:d.strength>1?1:d.strength),d.type!=null&&(v.type=d.type)},remove:()=>{let d=lt.indexOf(g);d>=0&<.splice(d,1)}}},readEdges:()=>lt.map(o=>({from:o.fromData,to:o.toData,type:o.agent.type,strength:o.agent.strength,memory:o.agent.memory,active:o.agent.active})),query:(o={})=>{let c=o.at,l,x=0,f=0,v=0,g=!1;c&&("width"in c?(l={x:c.x,y:c.y,width:c.width,height:c.height},x=c.x+c.width/2,f=c.y+c.height/2,v=Math.max(c.width,c.height)/2):(v=o.radius??240,x=c.x,f=c.y,l={x:x-v,y:f-v,width:v*2,height:v*2}),g=!0);let d=new Set(o.include??(g?["bodies","metrics","relationships","influences"]:["bodies","metrics","relationships"])),w=R=>{if(!R.vis)return!1;if(!g)return!0;if("width"in c){let X=l;return R.cx>=X.x&&R.cx<=X.x+X.width&&R.cy>=X.y&&R.cy<=X.y+X.height}return Math.hypot(R.cx-x,R.cy-f)<=v},k=L.filter(w),z=d.has("bodies")?k.map(R=>{let{metrics:X,dimensions:at}=Qn(R);return{id:Bt(R),rect:{x:R.cx-R.hw,y:R.cy-R.hh,width:R.hw*2,height:R.hh*2},tokens:R.tokens.slice(),metrics:X,dimensions:at,activeFormations:[Ze],authority:R.authority??"anchored"}}):[],T={};if(d.has("metrics")&&(T.particles=a.size,T.bodies=k.length,k.length>0)){let R=0;for(let X of k)R+=X.d;T.meanDensity=R/k.length}let F=d.has("relationships")?lt.filter(R=>!g||w(R.from)||w(R.to)).map(R=>({from:Bt(R.from),to:Bt(R.to),type:R.agent.type,strength:R.agent.strength,memory:R.agent.memory,active:R.agent.active,causal:R.agent.active})):[],O=[];if(d.has("influences")&&g)for(let R of k){if(R.tokens.length===0)continue;let X=Gn(p.forces,R.tokens,R,x,f);for(let at of X.attribution)O.push({source:Bt(R),force:at.force,channel:at.channel,contribution:at.contribution})}let q={query:o,frame:W.frameN,time:W.t,region:l,bodies:z,metrics:T,relationships:F,influences:O,projections:pe()};return o.lens?er(q,o.lens):q},snapshot:(o={})=>{let c=o.includeRelationships!==!1,l=L.filter(d=>d.vis),x=l.map(d=>{let{metrics:w,dimensions:k}=Qn(d),z={id:Bt(d),authority:d.authority??"anchored",rect:{x:d.cx-d.hw,y:d.cy-d.hh,width:d.hw*2,height:d.hh*2},position:{x:d.cx,y:d.cy,z:0},tokens:d.tokens.slice(),metrics:w,dimensions:k};return o.includeData&&(z.data=as(d.data)),z}),f=c?lt.map(d=>({from:Bt(d.from),to:Bt(d.to),type:d.agent.type,strength:d.agent.strength,memory:d.agent.memory,active:d.agent.active,causal:d.agent.active})):[],v={particles:a.size,bodies:l.length};if(l.length>0){let d=0;for(let w of l)d+=w.d;v.meanDensity=d/l.length}let g={id:`snap-${W.frameN}-${ns++}`,createdAt:W.t,frame:W.frameN,version:ce,formations:[Ze],bodies:x,relationships:f,metrics:v,projections:pe()};if(o.includeParticles){let d=[];for(let w of a.particles)w.cap||d.push({x:w.x,y:w.y,z:w.z??0,heat:w.heat,size:w.size});g.particles=d}if(o.includeInfluences){let d=[];for(let w of l){if(w.tokens.length===0)continue;let k=Gn(p.forces,w.tokens,w,w.cx+8,w.cy);for(let z of k.attribution)d.push({source:Bt(w),force:z.force,channel:z.channel,contribution:z.contribution})}g.influences=d}return g},diff:(o,c)=>Tn(o,c),replay:(o,c,l)=>Ro(o,c,l),addField:(o,c)=>(U.set(o,c),{name:o,set:l=>{U.set(o,l)},remove:()=>{U.delete(o)}}),sampleField:(o,c,l)=>{let x=U.get(o);return x?x(c,l):0},energy:()=>Ur(a.particles),sample:(o,c)=>{let{fx:l,fy:x}=Vt(L,p.forces,W,o,c);return{x:l,y:x}},sampleScalar:(o,c)=>tt?tt.norm(o,c):(Ln("NOOP_NO_HEATMAP","sampleScalar() returned 0 because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),0),sampleGradient:(o,c)=>tt?tt.gradient(o,c):(Ln("NOOP_NO_HEATMAP","sampleGradient() returned { x: 0, y: 0 } because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),{x:0,y:0}),grid:o=>W.grid(o),on:(o,c)=>{let l=y.get(o);return l||(l=new Set,y.set(o,l)),l.add(c),()=>void l.delete(c)},version:ce,scrollV:()=>W.scrollV??0,setVisible:o=>{Xn=o},setBackground:o=>{$.background=o,o==="transparent"&&n&&n.clearRect(0,0,_,D)},destroy:()=>{B.cancelRaf(It),clearInterval(vo);for(let o of ft)o();for(let o of Qt)o.el.removeEventListener("pointerenter",o.enter),o.el.removeEventListener("pointerleave",o.leave),o.el.removeEventListener("focus",o.enter),o.el.removeEventListener("blur",o.leave),delete o.el.dataset.fxEngaged;Qt=[];for(let o of jt)(o.docked||o.dock.dock>0)&&(o.docked=null,o.dock.dock=0,o.el.style.opacity="",o.el.getAttribute("aria-hidden")==="true"&&o.el.removeAttribute("aria-hidden"),o.el.removeAttribute("inert"));for(let o of Jt)for(let c of o.emitted)c.remove();Jt=[],a.clear()}}}var Ve={};function Xe(){return Ve.reducedMotion!==void 0?Ve.reducedMotion:typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function Je(){return Ve.hidden!==void 0?Ve.hidden:typeof document<"u"&&document.hidden}var Aa=["--field-density","--d"],Gr=!1;function Vr(){if(Gr)return[];Gr=!0;let e=globalThis.CSS;if(!e||typeof e.registerProperty!="function")return[];let t=[];for(let n of Aa)try{e.registerProperty({name:n,syntax:"<number>",inherits:!0,initialValue:"0"}),t.push(n)}catch{}return t}var Xr=["pointerdown","wheel","keydown","touchstart"];function re(){return Vr(),{root:document,viewport:()=>({width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio||1}),scrollY:()=>window.scrollY||0,scrollHeight:()=>document.documentElement.scrollHeight,reducedMotion:()=>Xe(),hidden:()=>Je(),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 Xr)window.addEventListener(t,e,{passive:!0});return()=>{for(let t of Xr)window.removeEventListener(t,e)}},onBodyEvent:(e,t)=>(document.addEventListener(e,t),()=>document.removeEventListener(e,t))}}var Jr=["pointerdown","wheel","keydown","touchstart"];function Kr(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:()=>Xe(),hidden:()=>Je(),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 Jr)e.addEventListener(n,t,{passive:!0});return()=>{for(let n of Jr)e.removeEventListener(n,t)}},onBodyEvent:(t,n)=>(e.addEventListener(t,n),()=>e.removeEventListener(t,n))}}function Qr(e,t={}){return Ge(e,{...t,host:re()})}function Ke(e,t={}){let{host:n,bounds:r,...s}=t,i=n??(r?Kr(r):re());return Ge(e,{...s,host:i})}function Vn(){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 ye(e=document.body){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText=Dr,e.appendChild(t),t}function Zr(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 ts(e={}){Vn();let{target:t=document.body,...n}=e,r=ye(t),s=Qr(r,n);return{...s,destroy:()=>{s.destroy(),r.remove()}}}var Qe=class{constructor(t={}){V(this,"canvas");V(this,"field");V(this,"managed");Vn();let{canvas:n,target:r,bounds:s,...i}=t;this.managed=!n,this.canvas=n??(s?Zr(s):ye(r)),this.field=Ke(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,r){this.field.burst(t,n,r)}flowTo(t,n,r){this.field.flowTo(t,n,r)}clearFlow(){this.field.clearFlow()}seed(t){this.field.seed(t)}addAgent(t){return this.field.addAgent(t)}addBody(t){return this.field.addBody(t)}addEdge(t,n,r){return this.field.addEdge(t,n,r)}readEdges(){return this.field.readEdges()}query(t){return this.field.query(t)}snapshot(t){return this.field.snapshot(t)}diff(t,n){return this.field.diff(t,n)}replay(t,n,r){return this.field.replay(t,n,r)}get projections(){return this.field.projections}addField(t,n){return this.field.addField(t,n)}sampleField(t,n,r){return this.field.sampleField(t,n,r)}atomAt(t,n){return this.field.atomAt(t,n)}focusAt(t,n){return this.field.focusAt(t,n)}clearFocus(){this.field.clearFocus()}particleCount(){return this.field.particleCount()}readParticles(t){return this.field.readParticles(t)}readParticleIds(t){return this.field.readParticleIds(t)}readParticleChannels(t,n){return this.field.readParticleChannels(t,n)}registerOverlay(t,n){return this.field.registerOverlay(t,n)}energy(){return this.field.energy()}sample(t,n){return this.field.sample(t,n)}sampleScalar(t,n){return this.field.sampleScalar(t,n)}sampleGradient(t,n){return this.field.sampleGradient(t,n)}grid(t){return this.field.grid(t)}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 Xs(Ca);})();
|
|
2
|
+
"use strict";var Fundamental=(()=>{var We=Object.defineProperty;var Ci=Object.getOwnPropertyDescriptor;var Oi=Object.getOwnPropertyNames;var Ri=Object.prototype.hasOwnProperty;var Pi=(n,t,e)=>t in n?We(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var $i=(n,t)=>{for(var e in t)We(n,e,{get:t[e],enumerable:!0})},Ii=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Oi(t))!Ri.call(n,s)&&s!==e&&We(n,s,{get:()=>t[s],enumerable:!(r=Ci(t,s))||r.enumerable});return n};var Ni=n=>Ii(We({},"__esModule",{value:!0}),n);var Y=(n,t,e)=>Pi(n,typeof t!="symbol"?t+"":t,e);var Fc={};$i(Fc,{CONDITIONS:()=>Ln,FIELD_VERSION:()=>ge,FORCES:()=>He,FORMATIONS:()=>_n,FieldField:()=>hn,PALETTE:()=>qe,browserHost:()=>ue,createField:()=>un,cssFeedbackSink:()=>co,headlessHost:()=>bs,makeFieldCanvas:()=>Ee,mountField:()=>Ds});var ge="0.9.4";var He=[{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"}],Uo=Object.fromEntries(He.map(n=>[n.id,n])),qe=He.map(n=>n.color),xe=["#4da3ff","#2dd4bf","#a78bfa","#ff6e9c","#ff9d5c"],In=["spotlight","screen","resonate"],Di=["spawn"],Nn=300,Dn=120;function _i(n){return In.includes(n)?"modifier":Di.includes(n)?"source":"force"}function je(n){let t=[],e=[],r=[];for(let s of n){let i=_i(s);i==="modifier"?t.push(s):i==="source"?r.push(s):e.push(s)}return t.length>1&&t.sort((s,i)=>In.indexOf(s)-In.indexOf(i)),{modifiers:t,forces:e,sources:r}}var _n=[{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}}],ve=Object.fromEntries(_n.map(n=>[n.id,n]));var Ln=[{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}],Tc=Object.fromEntries(Ln.map(n=>[n.id,n]));var Li={ours:xe,heatmap:["#2b3a8c","#2d8fd4","#3fd07a","#ffe14d","#ff8a3d","#e23b3b"],infrared:["#2a0a4a","#8e24aa","#e53935","#ff8f00","#ffd54f","#fffde7"],spectrum:["#ff3b30","#ff9500","#ffcc00","#34c759","#00c7be","#007aff","#af52de"]};function Ue(n){return Array.isArray(n)?n.length>0?n:xe:typeof n=="string"?Li[n]??xe:xe}var Bn={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 mt=(n,t,e)=>n<t?t:n>e?e:n;function pt(n){let t=n.replace("#",""),e=t.length===3?t.replace(/./g,s=>s+s):t,r=Number.parseInt(e.slice(0,6),16);return Number.isNaN(r)?[77,163,255]:[r>>16&255,r>>8&255,r&255]}var Bi=[255,224,200],Wi=[255,110,80];function Hn(n,t,e,r,s=Bi,i=Wi){let l=s[0]+(i[0]-s[0])*t,d=s[1]+(i[1]-s[1])*t,g=s[2]+(i[2]-s[2])*t;return l+=(r[0]-l)*e,d+=(r[1]-d)*e,g+=(r[2]-g)*e,n[0]=l,n[1]=d,n[2]=g,n}function qn([n,t,e]){let r=s=>mt(Math.round(s),0,255).toString(16).padStart(2,"0");return`#${r(n)}${r(t)}${r(e)}`}function Yo(n,t,e){let[r,s,i]=pt(n),[l,d,g]=pt(t),w=e<0?0:e>1?1:e;return qn([r+(l-r)*w,s+(d-s)*w,i+(g-i)*w])}function jn(n,t){if(n.length===0)return[77,163,255];if(n.length===1)return n[0];let e=mt(t,0,1)*(n.length-1),r=Math.min(n.length-2,Math.floor(e)),s=e-r,i=n[r],l=n[r+1];return[i[0]+(l[0]-i[0])*s,i[1]+(l[1]-i[1])*s,i[2]+(l[2]-i[2])*s]}function Go(n,t,e,r=0){if(!(t>0))return 1;let s=Math.max(0,1-n/t),i=1-e*s*s,l=Math.min(Math.max(r,0),1);return i<l?l:i>1?1:i}var Ye=1;function Ge(n){let t=n.ux!==0?n.hw/Math.abs(n.ux):1/0,e=n.uy!==0?n.hh/Math.abs(n.uy):1/0,r=Math.min(t,e),s=n.ux*r,i=n.uy*r,l=n.spin<0?-1:1;return[{x:n.cx+s,y:n.cy+i,q:l},{x:n.cx-s,y:n.cy-i,q:-l}]}function Vo(n,t,e){let r=0,s=0;for(let i of n){let l=t-i.x,d=e-i.y,g=Math.max(Ye,Math.hypot(l,d)),w=i.q/(g*g);r+=l/g*w,s+=d/g*w}return{x:r,y:s}}function Xo(n,t,e,r,s,i){let l=s-n,d=i-t,g=Math.max(Ye,Math.hypot(l,d)),m=(e<0?-1:1)*r/(g*g);return{x:l/g*m,y:d/g*m}}function Ko(n,t){let e=n/20+(t?.45:0);return e<0?0:e>1?1:e}function Jo(n,t,e){return Math.round(n+(t-n)*e)}function Qo(n,t={}){let e=t.beta??2,r=t.lo??.25,s=t.hi??3,i=n.length,l=new Array(i).fill(1);if(i===0)return l;let d=0,g=0;for(let m of n){let M=m.strength>0?m.strength:0;d+=M,g+=M*(1+(m.on?e:0))}if(d<=0||g<=0)return l;let w=d/g;for(let m=0;m<i;m++){let z=(1+(n[m].on?e:0))*w;z<r?z=r:z>s&&(z=s),l[m]=z}return l}function Zo(n,t={}){let e=t.threshold??.55,r=t.kappa??.6,s=t.falloff??320,i=n.length,l=new Array(i).fill(0);if(i<2)return l;let d=new Array(i).fill(0);for(let g=0;g<i;g++){let w=n[g],m=w.d-e;if(m<=0)continue;let M=0;for(let E=0;E<i;E++){if(E===g){d[E]=0;continue}let T=n[E],P=Math.hypot(w.cx-T.cx,w.cy-T.cy),_=P<s?1-P/s:0;d[E]=_,M+=_}if(M<=0)continue;let z=r*m;for(let E=0;E<i;E++){let T=d[E];if(T<=0)continue;let P=z*T/M;l[E]+=P,l[g]-=P}}return l}var tr=n=>`${n.from}\0${n.to}\0${n.type}`;function Un(n,t){let e=[],r=new Map(n.bodies.map(E=>[E.id,E])),s=new Map(t.bodies.map(E=>[E.id,E]));for(let[E,T]of r){let P=s.get(E);if(!P){e.push({id:E,kind:"removed"});continue}let _={},I=!1,G=new Set([...Object.keys(T.metrics),...Object.keys(P.metrics)]);for(let J of G){let y=T.metrics[J]??0,X=P.metrics[J]??0;y!==X&&(_[J]={from:y,to:X},I=!0)}I&&e.push({id:E,kind:"changed",metrics:_})}for(let E of s.keys())r.has(E)||e.push({id:E,kind:"added"});let i=[],l=new Map(n.relationships.map(E=>[tr(E),E])),d=new Map(t.relationships.map(E=>[tr(E),E]));for(let[E,T]of l){let P=d.get(E);if(!P){i.push({from:T.from,to:T.to,type:T.type,kind:"removed"});continue}let _={from:T.from,to:T.to,type:T.type,kind:"changed"},I=!1;T.strength!==P.strength&&(_.strength={from:T.strength,to:P.strength},I=!0),T.active!==P.active&&(_.active={from:T.active,to:P.active},I=!0),I&&i.push(_)}for(let[E,T]of d)l.has(E)||i.push({from:T.from,to:T.to,type:T.type,kind:"added"});let g=[],w=new Set([...Object.keys(n.metrics),...Object.keys(t.metrics)]);for(let E of w){let T=n.metrics[E]??0,P=t.metrics[E]??0;T!==P&&g.push({key:E,from:T,to:P})}let m=[],M=new Set(n.formations),z=new Set(t.formations);for(let E of z)M.has(E)||m.push({id:E,kind:"activated"});for(let E of M)z.has(E)||m.push({id:E,kind:"deactivated"});return{from:n.id,to:t.id,bodyChanges:e,relationshipChanges:i,metricChanges:g,formationChanges:m}}function er(n,t,e={}){let r=m=>Math.round(m*1e3)/1e3,s=Un(n,t),i=t.frame,l=t.createdAt,d=[],g=(m,M,z={})=>{d.push({frame:i,time:l,cause:m,description:M,...z})};for(let m of s.formationChanges)g("formation",`Formation '${m.id}' ${m.kind}`,{source:m.id});for(let m of s.relationshipChanges){let M;if(m.kind==="added")M="formed";else if(m.kind==="removed")M="dissolved";else{let z=[];if(m.active&&z.push(m.active.to?"became active":"went idle"),m.strength){let E=m.strength.to>=m.strength.from?"strengthened":"weakened";z.push(`${E} ${r(m.strength.from)}\u2192${r(m.strength.to)}`)}M=z.join(", ")||"changed"}g("relationship",`Relationship ${m.from}\u2192${m.to} (${m.type}) ${M}`,{source:m.from,target:m.to,contribution:m.strength})}for(let m of s.bodyChanges)if(m.kind==="added")g("measurement",`Body ${m.id} entered the field`,{source:m.id});else if(m.kind==="removed")g("measurement",`Body ${m.id} left the field`,{source:m.id});else if(m.metrics)for(let[M,z]of Object.entries(m.metrics)){let E=z.to>z.from?"rose":"fell";g("metric",`Body ${m.id} ${M} ${E} ${r(z.from)}\u2192${r(z.to)}`,{source:m.id,contribution:z})}if(n.influences&&t.influences){let m=T=>typeof T=="number"?Math.abs(T):Math.hypot(T.x,T.y,T.z??0),M=T=>`${T.source} ${T.force} ${T.channel??"linear"}`,z=new Map(n.influences.map(T=>[M(T),T])),E=new Map(t.influences.map(T=>[M(T),T]));for(let T of new Set([...z.keys(),...E.keys()])){let P=z.get(T),_=E.get(T),I=P?m(P.contribution):0,G=_?m(_.contribution):0;if(Math.abs(G-I)<1e-9)continue;let J=_??P,y=G>I?I===0?"engaged":"grew":G===0?"released":"weakened",X=(J.channel??"linear")==="thermal"?" (thermal)":"";g("force",`Force ${J.force} on ${J.source}${X} ${y} ${r(I)}\u2192${r(G)}`,{source:J.source,contribution:{from:I,to:G}})}}let w=e.focus?d.filter(m=>m.source===e.focus||m.target===e.focus):d;return{from:n.id,to:t.id,focus:e.focus,steps:w}}var Ve=class{constructor(t=64){Y(this,"cell");Y(this,"bins",new Map);Y(this,"freeBins",[]);this.cell=t>0?t:64}key(t,e){return(t+32768)*65536+(e+32768)}clear(){for(let t of this.bins.values())t.length=0,this.freeBins.push(t);this.bins.clear()}insert(t){let e=this.key(Math.floor(t.x/this.cell),Math.floor(t.y/this.cell)),r=this.bins.get(e);if(r)r.push(t);else{let s=this.freeBins.pop();s?(s.push(t),this.bins.set(e,s)):this.bins.set(e,[t])}}rebuild(t){this.clear();for(let e of t)this.insert(e)}near(t,e,r,s=0){let i=[],l=r*r,d=Math.floor((t-r)/this.cell),g=Math.floor((t+r)/this.cell),w=Math.floor((e-r)/this.cell),m=Math.floor((e+r)/this.cell);for(let M=d;M<=g;M++)for(let z=w;z<=m;z++){let E=this.bins.get(this.key(M,z));if(E)for(let T of E){let P=T.x-t,_=T.y-e,I=(T.z??0)-s;P*P+_*_+I*I<=l&&i.push(T)}}return i}};var Xe=class{constructor(t=64){Y(this,"particles",[]);Y(this,"hash");this.hash=new Ve(t)}get size(){return this.particles.length}add(t){return this.particles.push(t),t}remove(t){let e=this.particles.indexOf(t);if(e<0)return;let r=this.particles.pop();r&&e<this.particles.length&&(this.particles[e]=r)}clear(){this.particles.length=0,this.hash.clear()}reindex(){this.hash.rebuild(this.particles)}neighbors(t,e){let r=this.hash.near(t.x,t.y,e,t.z??0),s=[];for(let i of r)i!==t&&s.push(i);return s}near(t,e,r){return this.hash.near(t,e,r)}};function nr(n,t,e=.03){n.driftX+=(t.driftX-n.driftX)*e,n.wander+=(t.wander-n.wander)*e,n.orbit+=(t.orbit-n.orbit)*e,n.spread+=(t.spread-n.spread)*e,n.conv+=(t.conv-n.conv)*e}function or(n){for(let t of n)if(t.vis&&t.tokens.indexOf("sink")>=0)return t;return null}var Hi=[.24,.4,.55,.7,.85];function rr(n){let t=[];for(let e=0;e<5;e++)t.push({baseFrac:Hi[e]??.5,amp:22+e*15,freq:.0012+e*8e-4,phase:e*1.7%6.28,speed:13e-5+e*9e-5,color:n[e%n.length]??[77,163,255],depth:e/4,dir:e%2?-1:1,offsetY:0});return t}function sr(n,t,e){let r=Math.round(16*t),s=[];for(let i=0;i<n;i++)for(let l=0;l<r;l++)s.push({wi:i,progress:e(),phase:(e()-.5)*.22*Math.PI,size:.7+e()*1.5,glow:e()<.3,speed:(35e-5+e()*9e-4)*(e()<.5?1:-1)});return s}function Et(n,t,e,r,s=1,i=1,l){let d=n.baseFrac*r+n.offsetY+Math.sin(t*n.freq+n.phase+e*n.speed*1e3*s)*n.amp*i;if(l&&l.k>.001){let g=t-l.x,w=260,m=Math.exp(-(g*g)/(2*w*w));d+=(l.y-d)*.42*m*l.k*(.45+n.depth*.55)}return d}function ir(n,t,e,r=1,s=1){return Math.cos(t*n.freq+n.phase+e*n.speed*1e3*r)*n.amp*n.freq*s}function be(n,t,e,r,s=1,i=1){let l=n.baseFrac*r+n.offsetY,d=Math.max(1,Math.round(n.freq*2500));return l+Math.sin(d*t+n.phase+e*n.speed*1e3*s)*n.amp*i}function ar(n,t,e,r,s,i,l,d,g=1,w=1,m){if(l==="circular"){let M=t-d.x,z=e-d.y,E=Math.sqrt(M*M+z*z)||.001,T=Math.atan2(z,M),P=Math.min(s,i)*.48,_=be(n,T,r,P,g,w);return{dist:Math.abs(E-_),rWave:_,r:E,theta:T}}else{let M=Et(n,t,r,i,g,w,m);return{dist:Math.abs(e-M),rWave:M,r:e,theta:0}}}var Yt={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null};function Gt(n,t,e,r,s){Yt.x=r,Yt.y=s,Yt.vx=0,Yt.vy=0,Yt.heat=0;let i=0,l=0;for(let d of n){if(!d.vis||d.tokens.length===0)continue;let g,w;if(d.shaped){let z=d.cx-d.hw,E=d.cx+d.hw,T=d.cy-d.hh,P=d.cy+d.hh;g=(r<z?z:r>E?E:r)-r,w=(s<T?T:s>P?P:s)-s}else g=d.cx-r,w=d.cy-s;let m=g*g+w*w;if(d.range>0&&m>=d.range*d.range*2.56)continue;let M=Math.sqrt(m);e.dx=g,e.dy=w,e.dist=M<1?1:M;for(let z of d.tokens){let E=t[z];if(!(!E||E.modify))if(E.field){let T=E.field(d,r,s);i+=T.x,l+=T.y}else E.apply(d,Yt,e)}}return{fx:Yt.vx+i,fy:Yt.vy+l}}function Ke(n,t,e,r){let s=0,i=0;for(let l of n)if(!(!l.vis||l.tokens.length===0)){if(l.range>0){let d=l.cx-e,g=l.cy-r;if(d*d+g*g>=l.range*l.range*2.56)continue}for(let d of l.tokens){let g=t[d];if(g?.field){let w=g.field(l,e,r);s+=w.x,i+=w.y}}}return{x:s,y:i}}var cr=.95,lr=.972,At=10;function qi(n,t,e,r){if(!t.when)return!0;let s=n[t.when];return s?s(t,e,r):!0}function fr(n){return n.classified??(n.classified=je(n.tokens))}function Gn(n,t,e,r,s=1){let i=e.vx,l=e.vy,d=e.vz??0,g=e.heat,w=e.spin??0,m=e.age;n.apply(t,e,r),s===1||n.kinematic||(e.vx=i+(e.vx-i)*s,e.vy=l+(e.vy-l)*s,e.vz!==void 0&&(e.vz=d+(e.vz-d)*s)),n.kinematic&&r.integrator==="velocity-verlet"&&(e.vx!==i||e.vy!==l||(e.vz??0)!==d)&&(r.kinTouch=!0);let M=r.accum;if(M!==void 0){let z=e.vx-i,E=e.vy-l,T=(e.vz??0)-d;(z!==0||E!==0||T!==0)&&(M.linear.x+=z,M.linear.y+=E,M.linear.z+=T,M.attribution.push({force:n.token,channel:"linear",contribution:{x:z,y:E,z:T}}));let P=e.heat-g;P!==0&&(M.thermal=(M.thermal??0)+P,M.attribution.push({force:n.token,channel:"thermal",contribution:P}));let _=(e.spin??0)-w;if(_!==0){let I=M.angular??(M.angular={x:0,y:0,z:0});I.z+=_,M.attribution.push({force:n.token,channel:"angular",contribution:_})}if(m!==void 0&&e.age!==void 0){let I=e.age-m;if(I!==0){let G=M.temporal??(M.temporal={});G.decay=(G.decay??0)+I,M.attribution.push({force:n.token,channel:"temporal",contribution:I})}}t.attn!==void 0&&t.attn!==1&&((M.semantic??(M.semantic={})).attention=t.attn,M.attribution.push({force:n.token,channel:"semantic",contribution:t.attn}))}}function Yn(n,t,e,r,s){if(r.accum===void 0){if(s===1||n.kinematic){if(n.kinematic&&r.integrator==="velocity-verlet"){let g=e.vx,w=e.vy,m=e.vz??0;n.apply(t,e,r),(e.vx!==g||e.vy!==w||(e.vz??0)!==m)&&(r.kinTouch=!0);return}n.apply(t,e,r);return}let i=e.vx,l=e.vy,d=e.vz??0;n.apply(t,e,r),e.vx=i+(e.vx-i)*s,e.vy=l+(e.vy-l)*s,e.vz!==void 0&&(e.vz=d+(e.vz-d)*s);return}Gn(n,t,e,r,s)}function ur(){return{linear:{x:0,y:0,z:0},attribution:[]}}function dr(n){for(let t of n){t.count=0;let e=t.thermo;e&&(e.n=0,e.sx=0,e.sy=0,e.ss=0,e.ss2=0,e.sh=0)}}function hr(n){let{store:t,bodies:e,env:r,forces:s,conditions:i,waves:l,separation:d}=n,g=r.dt;if(g===0){dr(e);return}let w=r.integrator==="velocity-verlet",{W:m,H:M,form:z}=r;r.fieldAt=(y,X)=>Ke(e,s,y,X),dr(e);let E=null;for(let y of e)y.vis&&y.tokens.length>0&&fr(y).modifiers.indexOf("screen")>=0&&(E??(E=[])).push(y);let T=E?new Array(E.length):null,P=!!l&&l.length>0,_=e.length>0,I=null,G=z.conv>.02?or(e):null,J=r.D??0;for(let y of t.particles){if(y.cap){y.x+=(y.cap.cx-y.x)*.18,y.y+=(y.cap.cy-y.y)*.18,y.z&&(y.z+=-y.z*.18),y.ax!==void 0&&(y.ax=y.ay=y.az=0);continue}y.z===void 0&&(y.z=0),y.vz===void 0&&(y.vz=0);let X=0,bt=0,tt=0;if(w){let H=.5*g*g;y.x+=y.vx*g+(y.ax??0)*H,y.y+=y.vy*g+(y.ay??0)*H,y.z+=y.vz*g+(y.az??0)*H,X=y.vx,bt=y.vy,tt=y.vz,r.kinTouch=!1}let Fe=y.z;if(P)if(n.waveStyle==="circular"){let H=null,A=1e9,j=0,et=0,nt=0,wt=n.waveCenter||{x:m/2,y:M/2};for(let ut of l){let Ft=ar(ut,y.x,y.y,r.t,m,M,"circular",wt);Ft.dist<A&&(A=Ft.dist,H=ut,j=Ft.r,et=Ft.rWave,nt=Ft.theta)}if(H&&A<70){let ut=1-A/70,Ft=-Math.sin(nt)*H.dir,Xt=Math.cos(nt)*H.dir;y.vx+=Ft*.035*ut,y.vy+=Xt*.035*ut;let Nt=Math.cos(nt)*Math.sign(et-j),O=Math.sin(nt)*Math.sign(et-j);y.vx+=Nt*.05*ut,y.vy+=O*.05*ut}}else{let H=null,A=1e9;for(let j of l){let et=Math.abs(Et(j,y.x,r.t,M)-y.y);et<A&&(A=et,H=j)}H&&A<70&&(y.vx+=H.dir*.035*(1-A/70),y.vy+=ir(H,y.x,r.t)*.1*(1-A/70))}if(z.driftX&&(y.vx+=z.driftX*.02),z.spread>.02){let H=y.gx??.5,A=y.gy??.5,j=(H+r.frameN*4e-5)%1*m,et=A*M;y.vx+=(j-y.x)*6e-4*z.spread,y.vy+=(et-y.y)*6e-4*z.spread,J>0&&(y.vz+=((y.gz??.5)*J-Fe)*6e-4*z.spread)}if(G){let H=G.cx-y.x,A=G.cy-y.y,j=-Fe,et=Math.hypot(H,A,j)||1;y.vx+=H/et*z.conv*.06,y.vy+=A/et*z.conv*.06,y.vz+=j/et*z.conv*.06}if(_){if(E)for(let A=0;A<E.length;A++){let j=E[A],et=j.cx-y.x,nt=j.cy-y.y;T[A]=Go(Math.sqrt(et*et+nt*nt),j.range,j.strength,j.screenMin??0)}let H=y.m!==1&&y.m>0?1/y.m:1;for(let A of e){if(!A.vis||A.tokens.length===0||A.affects!==void 0&&!A.affects.has(y.species??0))continue;let j,et;if(A.shaped){let R=A.cx-A.hw,Z=A.cx+A.hw,ot=A.cy-A.hh,ee=A.cy+A.hh,he=y.x<R?R:y.x>Z?Z:y.x,ye=y.y<ot?ot:y.y>ee?ee:y.y;j=he-y.x,et=ye-y.y}else j=A.cx-y.x,et=A.cy-y.y;let nt=-y.z,wt=j*j+et*et+nt*nt;if(A.range>0&&wt>=A.range*A.range*2.56)continue;let ut=Math.sqrt(wt);if(A.feedback&&ut<A.range*.5){A.count+=1-ut/(A.range*.5);let R=A.thermo??(A.thermo={n:0,sx:0,sy:0,ss:0,ss2:0,sh:0}),Z=y.vx*y.vx+y.vy*y.vy;R.n++,R.sx+=y.vx,R.sy+=y.vy,R.ss+=Math.sqrt(Z),R.ss2+=Z,R.sh+=y.heat}if(A.when&&!qi(i,A,y,r))continue;r.dx=j,r.dy=et,r.dz=nt,r.dist=ut<1?1:ut;let Ft=fr(A),Xt=1,Nt=!1,O=!1;for(let R of Ft.modifiers){let Z=s[R]?.modify;if(!Z)continue;O=!0;let ot=Z(A,y,r);ot.strength!=null&&(Xt*=ot.strength),ot.gate&&(Nt=!0)}for(let R of Ft.forces){let Z=s[R]?.modify;if(!Z)continue;O=!0;let ot=Z(A,y,r);ot.strength!=null&&(Xt*=ot.strength),ot.gate&&(Nt=!0)}if(Nt)continue;let ct=1;if(E)for(let R=0;R<E.length;R++)E[R]!==A&&(ct*=T[R]);let B=A.attn??1,L=Xt*B*ct*(A.focusMul??1);if(!O&&L===1)for(let R of A.tokens){let Z=s[R];Z&&Yn(Z,A,y,r,H)}else if(O){let R=A.strength;A.strength=R*L;for(let Z of A.tokens){let ot=s[Z];ot&&!ot.modify&&Yn(ot,A,y,r,H)}A.strength=R}else{let R=A.strength;A.strength=R*L;for(let Z of A.tokens){let ot=s[Z];ot&&Yn(ot,A,y,r,H)}A.strength=R}}}if(d&&d>0){let H=r.neighbors(y,12);for(let A of H){let j=y.x-A.x,et=y.y-A.y,nt=(y.z??0)-(A.z??0),wt=Math.hypot(j,et,nt)||.1;if(wt<12){let ut=(12-wt)/12*d*.12;y.vx+=j/wt*ut,y.vy+=et/wt*ut,y.vz!==void 0&&(y.vz+=nt/wt*ut)}}}if(w){let H=y.vx-X,A=y.vy-bt,j=y.vz-tt;r.kinTouch?y.ax=y.ay=y.az=0:(y.vx=X+.5*((y.ax??0)*g+H),y.vy=bt+.5*((y.ay??0)*g+A),y.vz=tt+.5*((y.az??0)*g+j),y.ax=H/g,y.ay=A/g,y.az=j/g)}let Vt=r.c,ze=y.vx*y.vx+y.vy*y.vy+y.vz*y.vz;if(ze>Vt*Vt){let H=Vt/Math.sqrt(ze);y.vx*=H,y.vy*=H,y.vz*=H}if(y.maxSpeed!==void 0){let H=y.maxSpeed*y.maxSpeed,A=y.vx*y.vx+y.vy*y.vy+y.vz*y.vz;if(A>H){let j=y.maxSpeed/Math.sqrt(A);y.vx*=j,y.vy*=j,y.vz*=j}}w||(y.x+=y.vx*g,y.y+=y.vy*g,y.z+=y.vz*g);let It=r.integrator==="fixed"||w?Math.pow(cr,g):cr;if(y.vx*=It,y.vy*=It,y.vz*=It,y.spin!==void 0&&(y.orient=(y.orient??0)+y.spin*g,y.spin*=It),y.report===void 0){if(r.frameN%40===0&&z.wander>0){let H=.05*z.wander;y.vx+=((r.rng??Math.random)()-.5)*H,y.vy+=((r.rng??Math.random)()-.5)*H,J>0&&(y.vz+=((r.rng??Math.random)()-.5)*H)}if(z.wander>.05){let H=(Math.sin(y.x*.0032+r.t*.12)+Math.cos(y.y*.0034-r.t*.15))*Math.PI;y.vx+=Math.cos(H)*.013*z.wander,y.vy+=Math.sin(H)*.013*z.wander}}y.heat*=r.integrator==="fixed"||w?Math.pow(lr,g):lr,y.age!=null&&(y.age-=g,y.age<=0&&(I??(I=[])).push(y)),y.report===void 0?(y.x<-At?y.x=m+At:y.x>m+At&&(y.x=-At),y.y<-At?y.y=M+At:y.y>M+At&&(y.y=-At),J>0&&(y.z<-At?y.z=J+At:y.z>J+At&&(y.z=-At))):(y.x<0?(y.x=0,y.vx=Math.abs(y.vx)):y.x>m&&(y.x=m,y.vx=-Math.abs(y.vx)),y.y<0?(y.y=0,y.vy=Math.abs(y.vy)):y.y>M&&(y.y=M,y.vy=-Math.abs(y.vy)),J>0&&(y.z<0?(y.z=0,y.vz=Math.abs(y.vz)):y.z>J&&(y.z=J,y.vz=-Math.abs(y.vz))),y.report(y))}if(_){for(let y of e)if(!(!y.vis||y.tokens.length===0))for(let X of y.tokens)s[X]?.source?.(y,r)}if(I)for(let y of I)t.remove(y)}var de=class{constructor(t,e,r="diffuse",s=32){Y(this,"mode");Y(this,"cell");Y(this,"W");Y(this,"H");Y(this,"cols");Y(this,"rows");Y(this,"cur");Y(this,"nxt");Y(this,"prev");this.W=t,this.H=e,this.mode=r,this.cell=s,this.cols=Math.max(2,Math.ceil(t/s)+1),this.rows=Math.max(2,Math.ceil(e/s)+1);let i=this.cols*this.rows;this.cur=new Float32Array(i),this.nxt=new Float32Array(i),this.prev=new Float32Array(i)}clampCol(t){return t<0?0:t>=this.cols?this.cols-1:t}clampRow(t){return t<0?0:t>=this.rows?this.rows-1:t}at(t,e){return this.cur[this.clampRow(e)*this.cols+this.clampCol(t)]}sample(t,e){let r=t/this.cell,s=e/this.cell,i=Math.floor(r),l=Math.floor(s),d=r-i,g=s-l,w=this.at(i,l)*(1-d)+this.at(i+1,l)*d,m=this.at(i,l+1)*(1-d)+this.at(i+1,l+1)*d;return w*(1-g)+m*g}deposit(t,e,r){let s=this.clampCol(Math.round(t/this.cell)),i=this.clampRow(Math.round(e/this.cell));this.cur[i*this.cols+s]+=r}max(){let t=0;for(let e=0;e<this.cur.length;e++)this.cur[e]>t&&(t=this.cur[e]);return t}gradient(t,e){let r=this.cell;return{x:(this.sample(t+r,e)-this.sample(t-r,e))/(2*r),y:(this.sample(t,e+r)-this.sample(t,e-r))/(2*r)}}step(){this.mode==="wave"?this.stepWave():this.mode==="memory"?this.stepDiffuse(.03,.004):this.stepDiffuse()}stepDiffuse(t=.18,e=.01){let r=t<0?0:t>.24?.24:t,s=1-e,{cols:i,rows:l,cur:d,nxt:g}=this;for(let w=0;w<l;w++)for(let m=0;m<i;m++){let M=w*i+m,z=this.at(m-1,w)+this.at(m+1,w)+this.at(m,w-1)+this.at(m,w+1)-4*d[M];g[M]=(d[M]+r*z)*s}this.cur=g,this.nxt=d}stepWave(t=.25,e=.002){let r=t<0?0:t>.5?.5:t,s=1-e,{cols:i,rows:l,cur:d,prev:g,nxt:w}=this;for(let m=0;m<l;m++)for(let M=0;M<i;M++){let z=m*i+M,E=this.at(M-1,m)+this.at(M+1,m)+this.at(M,m-1)+this.at(M,m+1)-4*d[z];w[z]=(2*d[z]-g[z]+r*E)*s}this.prev=d,this.cur=w,this.nxt=g}decay(t){let e=t<=0?1:t>=1?0:1-t;if(e!==1)for(let r=0;r<this.cur.length;r++)this.cur[r]*=e}clear(){this.cur.fill(0),this.nxt.fill(0),this.prev.fill(0)}resize(t,e){if(t===this.W&&e===this.H)return;this.W=t,this.H=e,this.cols=Math.max(2,Math.ceil(t/this.cell)+1),this.rows=Math.max(2,Math.ceil(e/this.cell)+1);let r=this.cols*this.rows;this.cur=new Float32Array(r),this.nxt=new Float32Array(r),this.prev=new Float32Array(r)}};var yr={active:n=>n.on,fast:(n,t)=>t.vx*t.vx+t.vy*t.vy+(t.vz??0)*(t.vz??0)>.9,slow:(n,t)=>t.vx*t.vx+t.vy*t.vy+(t.vz??0)*(t.vz??0)<.22,hot:(n,t)=>t.heat>.3,cool:(n,t)=>t.heat<.08,scrolling:(n,t,e)=>(e?.scrollV??0)>.25};function mr(){let n={},t={...yr};return{forces:n,conditions:t,force(e){n[e.token]=e},condition(e,r){t[e]=r}}}var ji={token:"attract",label:"Attract",apply(n,t,e){let r=n.range*(n.on?1.5:1),s=n.strength*(n.on?3:1);if(e.dist>=r)return;let i=(1-e.dist/r)**2*s*.5,l=e.dx/e.dist,d=e.dy/e.dist;t.vx+=l*i,t.vy+=d*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i),e.form.orbit&&(t.vx+=-d*i*e.form.orbit,t.vy+=l*i*e.form.orbit),n.on&&(t.heat=Math.max(t.heat,(1-e.dist/r)*.9))},meta:{desc:"a soft gravity-like well, bent into a spiral"}},Ui={token:"repel",label:"Repel",apply(n,t,e){let r=n.range*(n.on?1.4:1),s=n.strength*(n.on?2:1);if(e.dist>=r)return;let i=(1-e.dist/r)**2*s*.5;t.vx-=e.dx/e.dist*i,t.vy-=e.dy/e.dist*i,e.dz&&(t.vz=(t.vz??0)-e.dz/e.dist*i)},meta:{desc:"inverse-square outward push"}},Yi={token:"swirl",label:"Swirl",apply(n,t,e){let r=n.range*(n.on?1.4:1),s=n.strength*(n.on?2:1);if(e.dist>=r)return;let i=(1-e.dist/r)**1.4*s*.45,l=n.spin,d=e.dx/e.dist,g=e.dy/e.dist;t.vx+=g*i*l+d*i*.12,t.vy+=-d*i*l+g*i*.12,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i*.12),n.on&&(t.heat=Math.max(t.heat,(1-e.dist/r)*.6))},meta:{desc:"tangential swirl with light inward retention"}},Gi={token:"stream",label:"Stream",apply(n,t,e){let r=n.range*(n.on?1.4:1),s=n.strength*(n.on?2:1);if(e.dist>=r)return;let i=(1-e.dist/r)**1.1*s*.5;t.vx+=n.ux*i,t.vy+=n.uy*i,n.on&&(t.heat=Math.max(t.heat,(1-e.dist/r)*.5))},meta:{desc:"directional current along a heading"}},Vi={token:"viscosity",label:"Viscosity",apply(n,t,e){let r=n.range*(n.on?1.4:1);if(e.dist>=r)return;let s=(1-e.dist/r)*(.05+n.strength*.07)*(n.on?1.6:1);t.vx-=t.vx*s,t.vy-=t.vy*s,t.vz&&(t.vz-=t.vz*s)},meta:{desc:"thickens the medium \u2014 bleeds momentum"}},Xi={token:"jet",label:"Jet",kinematic:!0,apply(n,t,e){let r=n.range*(n.on?1.4:1);if(!(e.dist>=r))if(e.dist<24){let s=((e.rng??Math.random)()-.5)*.8,i=Math.cos(s),l=Math.sin(s),d=n.ux*i-n.uy*l,g=n.ux*l+n.uy*i,w=2.4+n.strength*2.6;t.vx=d*w,t.vy=g*w,t.x=n.cx+d*26,t.y=n.cy+g*26,t.z&&(t.z=0),t.vz&&(t.vz=0),t.heat=Math.max(t.heat,.9)}else{let s=(1-e.dist/r)**2*(.25+n.strength*.15);t.vx+=e.dx/e.dist*s,t.vy+=e.dy/e.dist*s,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*s)}},meta:{desc:"a fountain \u2014 draws matter in, jets it out along a heading"}},Ki={token:"tether",label:"Tether",apply(n,t,e){let r=n.range*.6*(n.on?1.25:1),s=r*2.1;if(e.dist>=s)return;let i=(.006+n.strength*.012)*(n.on?1.7:1),l=e.dist-r,d=e.dx/e.dist,g=e.dy/e.dist;t.vx+=d*l*i,t.vy+=g*l*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*l*i),t.vx*=.985,t.vy*=.985,t.vz&&(t.vz*=.985),n.on&&(t.heat=Math.max(t.heat,(1-Math.min(1,Math.abs(l)/r))*.5))},meta:{desc:"a tether with a rest length \u2014 holds matter at a fixed radius"}},Ji={token:"wall",label:"Wall",kinematic:!0,apply(n,t,e){let s=Math.abs(t.x-n.cx),i=Math.abs(t.y-n.cy);if(s>=n.hw+6||i>=n.hh+6)return;let l=Math.hypot(t.vx,t.vy),d=n.hw+6-s,g=n.hh+6-i;d<g?(t.x=t.x<n.cx?n.cx-n.hw-6:n.cx+n.hw+6,t.vx=-t.vx*.85):(t.y=t.y<n.cy?n.cy-n.hh-6:n.cy+n.hh+6,t.vy=-t.vy*.85),l>.7&&(e.spark(t.x,t.y,Math.min(2.4,l),n.tint??Uo.wall.color),t.heat=Math.max(t.heat,Math.min(.85,l*.4)))},meta:{desc:"axis-aligned bouncing wall \u2014 sparks on impact"}},Qi={token:"sink",label:"Sink",apply(n,t,e){t.cap||e.dist>=n.absorbR||(t.cap=n,n.accreted+=1,n.accreted>=n.capacity&&e.supernova(n))},meta:{desc:"captures matter, then releases it"}},Zi=[ji,Xi,Ki,Ji,Gi,Ui,Vi,Yi,Qi];function pr(n){for(let t of Zi)n.force(t)}var Xn=1.5,ta=8,ea=60;function na(n,t,e,r){let s=Ge(n);if(Math.hypot(s[0].x-s[1].x,s[0].y-s[1].y)<Math.max(n.range*.06,ta)){let g=Math.max(n.range*.18,ea),w=n.spin<0?-1:1;s=[{x:n.cx+n.ux*g,y:n.cy+n.uy*g,q:w},{x:n.cx-n.ux*g,y:n.cy-n.uy*g,q:-w}]}let l=r*(1+Xn*(n.d??0)),d=Vo(s,t,e);return{x:d.x*l,y:d.y*l}}function oa(n,t,e,r){return Xo(n.cx,n.cy,n.spin,r*(1+Xn*(n.d??0)),t,e)}function gr(n,t,e,r){if(e.dist>=n.range)return;let s=2*e.G*n.M/(e.c*e.c),i=r/(e.dist*e.dist+s*s);t.vx+=e.dx/e.dist*i,t.vy+=e.dy/e.dist*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i),Kn(t,e.c)}function Kn(n,t){let e=n.vz??0,r=Math.hypot(n.vx,n.vy,e);r>t&&(n.vx=n.vx/r*t,n.vy=n.vy/r*t,e&&(n.vz=e/r*t))}function ra(n,t,e){let r=n.cx-t,s=n.cy-e,i=Math.max(Math.hypot(r,s),Ye),l=n.M*(1+Xn*(n.d??0))/(i*i);return{x:r/i*l,y:s/i*l}}var sa={token:"gravity",label:"Gravity",apply(n,t,e){gr(n,t,e,e.G*n.M)},field:(n,t,e)=>ra(n,t,e),meta:{desc:"true softened inverse-square gravity (a real 1/d\xB2 law)"}},ia={token:"charge",label:"Charge",apply(n,t,e){let r=t.charge??0;r!==0&&gr(n,t,e,-(n.spin*r*e.G*n.M))},field:(n,t,e)=>oa(n,t,e,n.M),meta:{desc:"signed inverse-square \u2014 like repels, opposite attracts"}},aa={token:"magnetism",label:"Magnetism",apply(n,t,e){if(e.dist>=n.range)return;let r=t.charge??0;if(r===0)return;let s=1-e.dist/n.range,i=r*n.spin*n.strength*s,l=Math.cos(i),d=Math.sin(i),g=t.vx;t.vx=g*l-t.vy*d,t.vy=g*d+t.vy*l},field:(n,t,e)=>na(n,t,e,n.strength),meta:{desc:"Lorentz force \u2014 curves a moving charge perpendicular to its velocity"}};function ca(n){return Math.sqrt(2*Math.max(0,n))}var la={token:"thermal",label:"Thermal",apply(n,t,e){if(e.dist>=n.range)return;let r=1-e.dist/n.range,s=ca(n.strength*r);if(s===0)return;let i=(e.rng??Math.random)()||1e-9,l=s*Math.sqrt(-2*Math.log(i)),d=2*Math.PI*(e.rng??Math.random)();if(t.vx+=l*Math.cos(d),t.vy+=l*Math.sin(d),e.D){let g=(e.rng??Math.random)()||1e-9;t.vz=(t.vz??0)+s*Math.sqrt(-2*Math.log(g))*Math.cos(2*Math.PI*(e.rng??Math.random)())}n.on&&(t.heat=Math.max(t.heat,r*.4)),Kn(t,e.c)},meta:{desc:"Langevin/Brownian agitation \u2014 a real temperature in the medium"}},fa={token:"collide",label:"Collide",apply(n,t,e){if(e.dist>=n.range)return;let r=Math.max(0,Math.min(1,n.strength)),s=Math.max(1,t.size);for(let i of e.neighbors(t,s*4)){let l=Math.max(1,i.size),d=t.x-i.x,g=t.y-i.y,w=(t.z??0)-(i.z??0),m=Math.hypot(d,g,w);if(m>=s+l||m<1e-6)continue;let M=d/m,z=g/m,E=w/m,T=(t.vx-i.vx)*M+(t.vy-i.vy)*z+((t.vz??0)-(i.vz??0))*E;if(T>=0)continue;let P=(1+r)*.5*T;t.vx-=P*M,t.vy-=P*z,i.vx+=P*M,i.vy+=P*z,w&&(t.vz=(t.vz??0)-P*E,i.vz=(i.vz??0)+P*E)}},meta:{desc:"elastic pairwise collision \u2014 the hard-sphere billiard force"}},da={token:"diffuse",label:"Diffuse",apply(n,t,e){if(e.dist>=n.range)return;let r=e.grid("diffuse");r.deposit(t.x,t.y,n.strength);let s=r.gradient(t.x,t.y);t.vx+=s.x*n.strength,t.vy+=s.y*n.strength},meta:{desc:"pheromone field \u2014 deposit a mark and follow the diffused gradient"}},ua=12,Vn=7,ha={token:"propagate",label:"Propagate",source(n,t){n.on&&t.frameN%ua===0&&t.grid("wave-propagate").deposit(n.cx,n.cy,n.strength)},apply(n,t,e){if(e.dist>=n.range)return;let s=e.grid("wave-propagate").gradient(t.x,t.y),i=Math.hypot(s.x,s.y);if(i<1e-6)return;let l=-e.dx/e.dist,d=-e.dy/e.dist;t.vx+=l*i*n.strength*Vn,t.vy+=d*i*n.strength*Vn,e.dz&&(t.vz=(t.vz??0)+-e.dz/e.dist*i*n.strength*Vn),Kn(t,e.c)},meta:{desc:"a travelling wave \u2014 a shock train expands from the source, sweeping matter out"}},ya={token:"memory",label:"Memory",apply(n,t,e){if(e.dist>=n.range)return;let r=e.grid("memory");r.deposit(t.x,t.y,n.strength*.15);let s=1+.5*r.sample(t.x,t.y),i=(1-e.dist/n.range)**2*n.strength*.5*s;t.vx+=e.dx/e.dist*i,t.vy+=e.dy/e.dist*i,e.dz&&(t.vz=(t.vz??0)+e.dz/e.dist*i)},meta:{desc:"the field remembers \u2014 occupancy wears in paths that pull harder"}},ma=[sa,ia,aa,la,fa,da,ha,ya];function xr(n){for(let t of ma)n.force(t)}var pa={token:"lens",label:"Lens",kinematic:!0,apply(n,t,e){if(e.dist>=n.range)return;let r=n.strength*(1-e.dist/n.range)*n.spin,s=Math.cos(r),i=Math.sin(r),l=t.vx,d=t.vy;t.vx=l*s-d*i,t.vy=l*i+d*s},meta:{desc:"rotates velocity, preserving speed \u2014 bends paths without adding energy"}},ga={token:"gate",label:"Gate",kinematic:!0,apply(n,t,e){if(Math.abs(t.x-n.cx)>=n.hw+6||Math.abs(t.y-n.cy)>=n.hh+6)return;let s=t.vx*n.ux+t.vy*n.uy;s<0&&(t.vx-=2*s*n.ux,t.vy-=2*s*n.uy)},meta:{desc:"a one-way membrane \u2014 passes matter along its heading, reflects the reverse"}},xa=1,va=1,ba={token:"buoyancy",label:"Buoyancy",apply(n,t,e){if(n.range>0&&e.dist>=n.range)return;let r=xa/(t.size*(1+t.heat));t.vy-=(va-r)*n.strength},meta:{desc:"a constant lift/sink by density difference \u2014 light matter rises, dense settles"}},wa={token:"shear",label:"Shear",apply(n,t,e){if(e.dist>=n.range)return;let r=(t.x-n.cx)*-n.uy+(t.y-n.cy)*n.ux,s=n.strength*(r/n.range)*(1-e.dist/n.range);t.vx+=n.ux*s,t.vy+=n.uy*s},meta:{desc:"a laminar shear gradient \u2014 flow speed grows with perpendicular offset"}},Je=32,Ma=.5,ka={token:"crystallize",label:"Crystallize",apply(n,t,e){if(e.dist>=n.range||t.heat>=Ma)return;let r=n.cx+Math.round((t.x-n.cx)/Je)*Je,s=n.cy+Math.round((t.y-n.cy)/Je)*Je;t.vx+=(r-t.x)*n.strength,t.vy+=(s-t.y)*n.strength,t.vx*=.9,t.vy*=.9},meta:{desc:"snaps cool matter onto a lattice; melts and frees it when hot"}},Sa={token:"align",label:"Align",apply(n,t,e){if(e.dist>=n.range)return;let r=t.vz??0,s=Math.hypot(t.vx,t.vy,r),i=n.strength,l=n.ux,d=n.uy,g=0,w=0,m=0,M=0;for(let E of e.neighbors(t,n.range)){let T=E.vz??0,P=Math.hypot(E.vx,E.vy,T);P>1e-6&&(w+=E.vx/P,m+=E.vy/P,M+=T/P)}let z=Math.hypot(w,m,M);z>1e-6&&(l=w/z,d=m/z,g=M/z),t.vx+=(l*s-t.vx)*i,t.vy+=(d*s-t.vy)*i,(g||r)&&(t.vz=r+(g*s-r)*i)},meta:{desc:"steers toward the neighbour-mean heading (or the body heading when alone)"}};function Ea(n,t,e,r){let s=n*r+e*.2,i=t*r-e*.2;return{x:-r*Math.sin(s)*Math.sin(i),y:-r*Math.cos(s)*Math.cos(i)}}var Fa=.01,za={token:"wind",label:"Wind",apply(n,t,e){if(n.range>0&&e.dist>=n.range)return;let r=Ea(t.x,t.y,e.t,Fa);t.vx+=r.x*n.strength,t.vy+=r.y*n.strength},meta:{desc:"divergence-free curl-noise turbulence"}},Aa=.5,Ta={token:"cohesion",label:"Cohesion",apply(n,t,e){if(e.dist>=n.range)return;let r=n.range,s=r*Aa,i=n.strength;for(let l of e.neighbors(t,r)){let d=l.x-t.x,g=l.y-t.y,w=(l.z??0)-(t.z??0),m=Math.hypot(d,g,w);if(m<1e-6)continue;let M=d/m,z=g/m,E=w/m;if(m<s){let T=i*(s-m)/s;t.vx-=T*M,t.vy-=T*z,w&&(t.vz=(t.vz??0)-T*E)}else{let T=i*(m-s)/(r-s);t.vx+=T*M,t.vy+=T*z,w&&(t.vz=(t.vz??0)+T*E)}}},meta:{desc:"short-range pressure + mid-range cohesion \u2014 surface tension over neighbours"}},Ca=.5,Oa={token:"pressure",label:"Pressure",apply(n,t,e){if(e.dist>=n.range)return;let r=n.range,s=n.strength,i=0,l=e.neighbors(t,r);for(let g of l){let w=Math.hypot(g.x-t.x,g.y-t.y,(g.z??0)-(t.z??0));w<r&&(i+=(1-w/r)**2)}let d=i-Ca;if(!(d<=0))for(let g of l){let w=t.x-g.x,m=t.y-g.y,M=(t.z??0)-(g.z??0),z=Math.hypot(w,m,M);if(z<1e-6||z>=r)continue;let E=s*d*(1-z/r)/z;t.vx+=E*w,t.vy+=E*m,M&&(t.vz=(t.vz??0)+E*M)}},meta:{desc:"SPH density relaxation \u2014 incompressible even-fill via mutual repulsion"}},Ra={token:"hunt",label:"Hunt",apply(n,t,e){if(e.dist>=n.range)return;let r=t.species??0,s=null,i=1/0;for(let M of e.neighbors(t,n.range)){if((M.species??0)===r)continue;let z=M.x-t.x,E=M.y-t.y,T=(M.z??0)-(t.z??0),P=z*z+E*E+T*T;P<i&&(i=P,s=M)}if(!s)return;let l=s.x-t.x,d=s.y-t.y,g=(s.z??0)-(t.z??0),w=Math.hypot(l,d,g)||1,m=r===0?1:-1;t.vx+=l/w*n.strength*m,t.vy+=d/w*n.strength*m,g&&(t.vz=(t.vz??0)+g/w*n.strength*m)},meta:{desc:"two-species pursuit \u2014 predators seek prey, prey flee predators"}},Pa=.35,$a={token:"link",label:"Link",apply(n,t,e){if(e.dist>=n.range)return;let r=n.range,s=r*Pa,i=n.strength;for(let l of e.neighbors(t,r)){let d=l.x-t.x,g=l.y-t.y,w=(l.z??0)-(t.z??0),m=Math.hypot(d,g,w);if(m<1e-6)continue;let M=m-s,z=.5*i*(M/s);t.vx+=z*(d/m),t.vy+=z*(g/m),w&&(t.vz=(t.vz??0)+z*(w/m))}},meta:{desc:"a Verlet distance constraint \u2014 holds a rest length, so matter ropes and drapes"}},vr=40,Ia={token:"morph",label:"Morph",apply(n,t,e){let r=n.targets;if(!r||r.length===0)return;let s=Math.min(r.length-1,Math.floor((t.gx??0)*r.length)),i=r[s],l=i.x-t.x,d=i.y-t.y,g=Math.hypot(l,d),w=n.strength;t.vx+=l*w*.02,t.vy+=d*w*.02,t.z&&(t.vz=(t.vz??0)-t.z*w*.02);let M=(1-(g<vr?1-g/vr:0))*w*.3;M>0&&(t.vx+=((e.rng??Math.random)()-.5)*M,t.vy+=((e.rng??Math.random)()-.5)*M)},meta:{desc:"matter assembles into a mark/chart/logo \u2014 never words (\xA711)"}},Na=90,Da={token:"spawn",label:"Spawn",apply(){},source(n,t){let e=n.life??Na,r=Math.max(1,Math.round(n.strength*2));n.cap!=null&&n.cap>0&&e>0&&(r=Math.min(r,n.cap/e)),n.emitAcc=(n.emitAcc??0)+r;let s=Math.floor(n.emitAcc);for(n.emitAcc-=s;s>0;s--){let i=((t.rng??Math.random)()-.5)*.6,l=Math.cos(i),d=Math.sin(i),g=n.ux*l-n.uy*d,w=n.ux*d+n.uy*l,m=2+(t.rng??Math.random)()*2;t.spawn({x:n.cx,y:n.cy,vx:g*m,vy:w*m,age:e,heat:.6,...n.species!=null?{species:n.species}:{}})}},meta:{desc:"a source \u2014 emits matter along the heading, budgeted by a lifespan"}},_a=3,La={token:"resonate",label:"Resonate",apply(){},modify(n,t,e){return{strength:1+Math.sin(e.t*_a*n.spin)}},meta:{desc:"pulses sibling forces with a time-varying strength S(t)=S\u2080(1+sin \u03C9t)"}},Ba=.5,Wa={token:"spotlight",label:"Spotlight",apply(){},modify(n,t,e){let r=-e.dx/e.dist,s=-e.dy/e.dist;return{gate:r*n.ux+s*n.uy<Ba}},meta:{desc:"gates sibling forces to an angular cone of the heading"}},Ha={token:"screen",label:"Screen",apply(){},meta:{desc:"a quiet zone \u2014 attenuates other bodies' forces on matter inside its radius"}},qa={token:"pigment",label:"Pigment",apply(n,t,e){let r=n.tint;!r||e.dist>=n.range*.6||(t.color=t.color?Yo(t.color,r,.08):r)},meta:{desc:"conserved color transport \u2014 matter takes on and carries a tint"}},ja=.5,br=.12,Ua={token:"fieldflow",label:"Field Flow",apply(n,t,e){if(n.range>0&&e.dist>=n.range||n.chargeGated&&(t.charge??0)===0)return;let r=e.fieldAt?.(t.x,t.y);if(!r)return;let s=Math.hypot(r.x,r.y);if(!(s>1e-9))return;let i=r.x/s,l=r.y/s,d=n.range>0?1-e.dist/n.range:1,g=n.strength*d,w=t.vz??0,m=Math.hypot(t.vx,t.vy,w);if(m>1e-6){let E=Math.min(1,g*ja);t.vx+=(i*m-t.vx)*E,t.vy+=(l*m-t.vy)*E,w&&(t.vz=w+(0-w)*E)}t.vx+=i*g*br,t.vy+=l*g*br;let M=t.vz??0,z=t.vx*t.vx+t.vy*t.vy+M*M;if(z>e.c*e.c){let E=e.c/Math.sqrt(z);t.vx*=E,t.vy*=E,M&&(t.vz=M*E)}n.on&&(t.heat=Math.max(t.heat,d*.4))},meta:{desc:"follow the field lines \u2014 steer onto and stream down the net field a body radiates"}},Ya={token:"warp",label:"Warp",kinematic:!0,apply(n,t,e){if(!n.warpHas||t.cap)return;let r=n.absorbR;if(e.dist>=r)return;let s=Math.cos(n.twist??0),i=Math.sin(n.twist??0),l=n.warpScale??1,d=-e.dx/e.dist,g=-e.dy/e.dist,w=d*s-g*i,m=d*i+g*s,M=r*l+6;t.x=n.warpX+w*M,t.y=n.warpY+m*M,t.z&&(t.z=-e.dz/e.dist*M);let z=t.vx,E=t.vy;t.vx=z*s-E*i,t.vy=z*i+E*s,t.heat=Math.max(t.heat,.6)},meta:{desc:"a wormhole throat \u2014 relocates matter to its paired body, conserved"}},Ga=[pa,ga,ba,wa,ka,Sa,za,Ta,Oa,$a,Ra,Ia,Da,La,Wa,Ha,qa,Ua,Ya];function wr(n){for(let t of Ga)n.force(t)}var Mr=new Set(["css","canvas","svg","typography","spatial","native"]);function kr(n){let t=[];for(let e of n)e.surfaces.some(s=>Mr.has(s))&&!e.reducedMotionEquivalent&&t.push({rule:"field/reduced-motion-equivalent-required",severity:"error",subject:e.id,message:`Projection "${e.id}" can express motion (${e.surfaces.filter(s=>Mr.has(s)).join(", ")}) but declares no reducedMotionEquivalent. Reduced motion must translate the behavior, not remove it.`}),e.accessibilityEquivalent||t.push({rule:"field/accessibility-equivalent-required",severity:"warning",subject:e.id,message:`Projection "${e.id}" declares no accessibilityEquivalent. Accessibility is an alternate projection of the same field state, not a fallback.`});return t}var Jn=(n,t)=>t?Object.fromEntries(Object.entries(n).filter(([e])=>t.has(e))):n;function Sr(n,t){let e=t.metrics?new Set(t.metrics):null,r=t.channels?new Set(t.channels):null,s=t.tokens?new Set(t.tokens):null;return{...n,metrics:Jn(n.metrics,e),bodies:n.bodies.filter(i=>!s||i.tokens.some(l=>s.has(l))).map(i=>({...i,metrics:Jn(i.metrics,e),dimensions:Jn(i.dimensions,e)})),influences:r?n.influences.filter(i=>r.has(i.channel??"linear")):n.influences,lens:t.id}}function Er(n,t,e={}){return{x:n,y:t,strength:e.strength??1,radius:e.radius&&e.radius>0?e.radius:360}}function we(n,t,e,r,s=.6){let i=r.x-t,l=r.y-e,d=Math.hypot(i,l);if(d===0||d>=r.radius)return n.x=0,n.y=0,n;let g=(1-d/r.radius)*r.strength*s;return n.x=i/d*g,n.y=l/d*g,n}var Va={step:6,maxSteps:400,minStrength:1e-9,loopDist:6,maxTurns:1/0};function Fr(n,t,e,r,s){let i=[{x:t,y:e}],l=t,d=e,g=s.step,w=s.maxTurns*2*Math.PI,m=0,M=0,z=0;for(let E=0;E<s.maxSteps;E++){let T=n(l,d),P=Math.hypot(T.x,T.y);if(!(P>=s.minStrength))break;let _=T.x/P*r,I=T.y/P*r;if(Number.isFinite(w)){if(m!==0||M!==0){let G=Math.max(-1,Math.min(1,_*m+I*M));if(z+=Math.acos(G),z>w)break}m=_,M=I}if(l+=_*s.step,d+=I*s.step,s.bounds&&(l<-g||d<-g||l>s.bounds.w+g||d>s.bounds.h+g))break;if(E>4&&Math.hypot(l-t,d-e)<s.loopDist){i.push({x:l,y:d});break}i.push({x:l,y:d})}return i}function Xa(n,t,e,r={}){let s={...Va,bounds:r.bounds,...r},i=Fr(n,t,e,-1,s),l=Fr(n,t,e,1,s);return i.reverse(),i.pop(),i.concat(l)}function zr(n,t,e={}){return t.map(r=>Xa(n,r.x,r.y,e)).filter(r=>r.length>1)}var Ka=8,Ja=60;function Ar(n,t=8){let e={cx:n.cx,cy:n.cy,hw:n.hw,hh:n.hh,ux:n.ux,uy:n.uy,spin:n.spin},r=Ge(e),s=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y);if(s<Math.max(n.range*.06,Ka)){let w=Math.max(n.range*.18,Ja),m=n.spin<0?-1:1;r=[{x:n.cx+n.ux*w,y:n.cy+n.uy*w,q:m},{x:n.cx-n.ux*w,y:n.cy-n.uy*w,q:-m}],s=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y)}let i=-n.uy,l=n.ux,d=Math.max(s*.13,18),g=[{x:n.cx,y:n.cy}];for(let w=1;w<=t;w++){let m=w*d;g.push({x:n.cx+i*m,y:n.cy+l*m}),g.push({x:n.cx-i*m,y:n.cy-l*m})}return g}function Tr(n,t=18){let e=Math.max(Math.min(n.hw,n.hh)*.8,24),r=[];for(let s=0;s<t;s++){let i=s/t*Math.PI*2;r.push({x:n.cx+Math.cos(i)*e,y:n.cy+Math.sin(i)*e})}return r}function Cr(n,t=8){let e=[];for(let r of n)!r.vis||r.tokens.length===0||(r.tokens.includes("magnetism")?e.push(...Ar(r,t)):(r.tokens.includes("charge")||r.tokens.includes("gravity"))&&e.push(...Tr(r)));return e}function Or(n,t=Math.random){return 3+Math.floor(t()*(n>0?n:1)*3)}var Rr=160;function Pr(n,t,e,r=6,s=0){let i=Math.hypot(n,t,s)||1;if(i>=e)return{vx:0,vy:0,vz:0,heat:0};let l=1-i/e,d=l*r;return{vx:n/i*d,vy:t/i*d,vz:s/i*d,heat:l*.9}}function $r(n,t,e,r,s=.9,i=80){let l=r>0?r:1;n.vx=(n.vx+t/l)*s,n.vy=(n.vy+e/l)*s,n.x+=n.vx,n.y+=n.vy;let d=Math.hypot(n.x,n.y);d>i&&(n.x=n.x/d*i,n.y=n.y/d*i)}function Ir(n,t=.02){return{x:-n.x*t,y:-n.y*t}}function Nr(n){let t=n/3e4;return t<.6?.6:t>6?6:t}function Dr(n,t,e=-1,r=1600,s=26){let i=0,l=0,d=s*s;for(let g=0;g<t.length;g++){if(g===e)continue;let w=t[g],m=n.x-w.x,M=n.y-w.y,z=m*m+M*M+d;i+=r*m/z,l+=r*M/z}return{x:i,y:l}}function _r(n,t,e,r=16,s=1){let i=(n(t+r,e)-n(t-r,e))/(2*r),l=(n(t,e+r)-n(t,e-r))/(2*r);return{x:-i*s,y:-l*s}}function Lr(n,t,e,r,s,i,l,d){if(r.length===0)return;let g=n.particles;for(let w=g.length-1;w>=0&&!(t.length>=e);w--){let m=g[w];if(!m||m.cap||m.heat>=.12)continue;let M=-1,z=1e9,E=0;for(let P=0;P<r.length;P++){let _=Et(r[P],m.x,l,i),I=Math.abs(_-m.y);I<z&&(z=I,M=P,E=_)}if(M<0||z>=64)continue;let T=Math.min(.012,z*4e-4)*(1-m.heat/.12);m.vy+=E>m.y?T:-T,z<20&&m.vx*m.vx+m.vy*m.vy<.3&&d()<.03&&(t.push({wi:M,progress:m.x/s,phase:(d()-.5)*.22*Math.PI,size:m.size,glow:d()<.3,speed:(35e-5+d()*9e-4)*(d()<.5?1:-1)}),n.remove(m))}}function Qn(n,t,e,r,s,i,l,d,g){for(let w=n.length-1;w>=0;w--){let m=n[w];if(!m)continue;let M=t[m.wi];if(!M)continue;let z=m.progress*i,E=Et(M,z,d,l)+m.phase*32,T=z-e,P=E-r,_=Math.hypot(T,P);if(_<s&&_>.5){let I=(1-_/s)*4;g({x:z,y:E,vx:T/_*I,vy:P/_*I,size:m.size,heat:.9});let G=n.pop();G&&w<n.length&&(n[w]=G)}}}function Br(n,t,e,r,s,i,l,d){let g=w=>w.tokens.some(m=>{let M=r[m];return!!M&&!M.modify&&!M.source});for(let w=n.length-1;w>=0;w--){let m=n[w];if(!m)continue;let M=t[m.wi];if(!M)continue;let z=m.progress*s,E=Et(M,z,l,i)+m.phase*32,T=!1,P=0,_=0;for(let I of e){if(!I.vis||I.when==="active"&&!I.on||I.when&&I.when!=="active")continue;let G=I.tokens,J=I.cx-z,y=I.cy-E,X=Math.hypot(J,y)||1,bt=I.range*(I.on?1.4:1);if(G.indexOf("wall")>=0&&Math.abs(z-I.cx)<I.hw+6&&Math.abs(E-I.cy)<I.hh+6&&(P=(z<I.cx?-1:1)*1.6,_=(E<I.cy?-1:1)*.8,T=!0),!T&&(G.indexOf("attract")>=0||G.indexOf("sink")>=0||G.indexOf("jet")>=0)&&X<bt*.8){let tt=1.2+(I.on?1.6:0);P=J/X*tt,_=y/X*tt,T=!0}if(!T&&G.indexOf("repel")>=0&&X<bt*.8){let tt=1.2+(I.on?1.2:0);P=-(J/X)*tt,_=-(y/X)*tt,T=!0}if(!T&&G.indexOf("swirl")>=0&&X<bt*.75&&(P=y/X*1.2,_=-(J/X)*1.2,T=!0),!T&&G.indexOf("stream")>=0&&X<bt*.75&&(P=I.ux*1.3,_=I.uy*1.3,T=!0),!T&&X<bt*.8&&g(I)){let tt=.8+(I.on?.8:0);P=J/X*tt,_=y/X*tt,T=!0}if(T)break}if(T){d({x:z,y:E,vx:P,vy:_,size:m.size,heat:.5});let I=n.pop();I&&w<n.length&&(n[w]=I)}}}function Wr(n,t){for(let e of n){if(!e.vis||e.tokens.indexOf("charge")<0&&e.tokens.indexOf("magnetism")<0||e.range<=0)continue;let r=e.range*e.range;for(let s of t){if(s.charge)continue;let i=e.cx-s.x,l=e.cy-s.y;i*i+l*l>=r||(s.charge=i>=0?1:-1)}}}function Me(n,t,e){if(!Number.isFinite(n)||!Number.isFinite(t))return 0;let r=t-n;return r<=0?1:!Number.isFinite(e)||e<=0?0:Math.pow(2,-r/e)}var Hr=n=>n<0?0:n>1?1:n;function qr(n){if(!n||n.n===0)return{entropy:0,coherence:1,temperature:0};let t=n.sh/n.n,e=n.ss/n.n,r=n.ss2/n.n,s=Hr(.5*t+.5*Math.min(1,r/9)),i=n.ss>1e-9?Math.hypot(n.sx,n.sy)/n.ss:1,l=Hr((1-i)*Math.min(1,e/1.5));return{entropy:l,coherence:1-l,temperature:s}}var Qe=class{constructor(){Y(this,"pending",new Map);Y(this,"ids",new WeakMap);Y(this,"seq",0)}idOf(t){let e=this.ids.get(t);return e===void 0&&this.ids.set(t,e=++this.seq),e}keyOf(t,e){if(t==="focus"){let s=e;return`focus:${s.target}:${s.source}`}if(t==="met"){let s=e,[i,l]=[this.idOf(s.a.el??s.a),this.idOf(s.b.el??s.b)].sort((d,g)=>d-g);return`${i}:${l}`}if(t==="enter"||t==="exit"){let s=e;return`${this.idOf(s.body.el??s.body)}:${this.idOf(s.other.el??s.other)}`}let r=e;return String(this.idOf(r.body.el??r.body))}record(t,e){let r=this.pending.get(t);r||this.pending.set(t,r=new Map),r.set(this.keyOf(t,e),e)}flush(t){if(this.pending.size!==0){for(let[e,r]of this.pending)for(let s of r.values())t(e,s);this.pending.clear()}}};function Zn(n){return n.split(",").map(t=>t.trim()).filter(Boolean).map(t=>{let e=t.indexOf(":");return{trigger:t.slice(0,e).trim(),event:t.slice(e+1).trim(),armed:!1}}).filter(t=>t.trigger&&t.event)}function to(n,t){switch(n){case"dense":return t.d>.6;case"sparse":return t.d<.2;case"engaged":return t.on;case"captured":return t.accreted>0;default:return!1}}var jr={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 Qa(){return globalThis.process?.env?.NODE_ENV!=="production"}var Yr=Qa();function Gr(){return Yr}var Ur=new Set;function eo(n,t){if(!Yr)return;let e=`${n}:${t}`;Ur.has(e)||(Ur.add(e),console.warn(`[Fundamental:${n}] ${t}`))}var Za={"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 Vr(n,t={}){let e=Za[n];if(!e)return null;let r=[...e.body];t.risk==="high"&&!r.includes("thermal")&&r.push("thermal");let s={"data-body":r.join(" ")};return t.intensity!=null&&(s["data-strength"]=String(t.intensity)),e.range!=null&&(s["data-range"]=String(e.range)),e.feedback&&(s["data-feedback"]=""),e.render?.length&&(s["data-render"]=e.render.join(" ")),{body:r.join(" "),strength:t.intensity,range:e.range,feedback:e.feedback??!1,render:e.render??["particles"],attributes:s}}function Kr(n){let t=(P,_)=>{let I=Number.parseFloat(n.get(P)??"");return Number.isFinite(I)?I:_},e=t("strength",.5),r=t("angle",0)*Math.PI/180,s=n.get("spin"),i=s==null?1:Number.isFinite(Number.parseFloat(s))?Number.parseFloat(s):0,l=(n.get("body")??"").split(/\s+/).filter(Boolean),d=je(l),g=n.get("life"),w=n.get("cap"),m=Number.parseFloat(g??""),M=Number.parseFloat(w??""),z=g!=null||w!=null||n.has("budget")||n.has("sink"),E=n.get("authority");return{tokens:l,authority:E==="kinematic"||E==="dynamic"?E:"anchored",classified:d,...Number.isFinite(m)&&m>0?{life:m}:{},...Number.isFinite(M)&&M>0?{cap:M}:{},budgeted:z,strength:e,range:t("range",280),absorbR:t("absorb",64),capacity:t("max",60),spin:i,angle:r,ux:Math.cos(r),uy:Math.sin(r),when:n.get("when")??"",feedback:n.has("feedback"),shaped:n.has("shaped"),chargeGated:n.has("charge-gated"),...n.get("species")!=null&&Number.isFinite(Number.parseFloat(n.get("species")))?{species:Number.parseFloat(n.get("species"))}:{},...(()=>{let P=n.get("affects");if(P==null)return{};let _=P.split(",").map(I=>Number.parseFloat(I.trim())).filter(I=>Number.isFinite(I));return _.length?{affects:new Set(_)}:{}})(),fmin:t("fmin",0),fmax:t("fmax",0),opsz:n.get("opsz")??"",pair:n.get("pair")||void 0,twist:t("twist",0)*Math.PI/180,warpScale:t("scale",1),screenMin:t("screen-min",0),M:e}}function tc(n){let t={body:n.body};return n.strength!=null&&(t.strength=String(n.strength)),n.range!=null&&(t.range=String(n.range)),n.spin!=null&&(t.spin=String(n.spin)),n.angle!=null&&(t.angle=String(n.angle)),n.absorb!=null&&(t.absorb=String(n.absorb)),n.max!=null&&(t.max=String(n.max)),n.life!=null&&(t.life=String(n.life)),n.cap!=null&&(t.cap=String(n.cap)),{get:e=>t[e]??null,has:e=>e in t}}function ec(n){let t=jr[n];return t?t.map(e=>Kr(tc(e))):[]}function nc(n){let t=(n.tagName??"element").toLowerCase(),e=n.id?`#${n.id}`:"",r=typeof n.className=="string"&&n.className?`.${n.className.split(/\s+/)[0]}`:"";return`<${t}${e}${r}>`}function oc(n,t="<body>"){!n.classified||n.classified.sources.length===0||n.budgeted||(n.life=Nn,n.cap=Dn,Gr()&&console.warn(`[Fundamental:UNBUDGETED_SOURCE] ${t} runs the source force "${n.classified.sources.join(" ")}" with none of data-life / data-cap / data-budget / data-sink. Applying the safe default budget (data-life="${Nn}", data-cap="${Dn}") \u2014 declare one to make the source's budget explicit (workover v0.3 source rules).`))}function Jr(n,t){return oc(t,nc(n)),{el:n,...t,tint:n.dataset.color,cx:0,cy:0,hw:0,hh:0,on:!1,vis:!0,accreted:0,count:0,d:0,attn:1}}function rc(n){return{get:t=>n.getAttribute("data-"+t),has:t=>n.hasAttribute("data-"+t)}}function ke(n,t){return Jr(n,Kr(t??rc(n)))}var Xr={source:"jet",sink:"sink",anchor:"tether",boundary:"wall",sensor:"",display:""};function sc(n){let t=null,e=n.getAttribute("data-intent");if(e){let s=n.getAttribute("data-intensity"),i=Vr(e,{intensity:s!=null?Number(s):void 0,risk:n.getAttribute("data-risk")??void 0});i&&(t={body:i.body},i.strength!=null&&(t.strength=String(i.strength)),i.range!=null&&(t.range=String(i.range)),i.feedback&&(t.feedback=""))}if(!t){let s=n.getAttribute("data-field-role");s!=null&&s in Xr&&(t={body:Xr[s],feedback:""})}if(!t)return null;let r=t;return{get:s=>n.getAttribute("data-"+s)??r[s]??null,has:s=>n.hasAttribute("data-"+s)||s in r}}var Ze="data-field-boundary",ic=`[${Ze}]`;function no(n,t){if(typeof n.closest!="function")return!0;let e=n.closest(ic);return e===null||e===t}function Qr(n){let t=[];return n.querySelectorAll("[data-body]").forEach(e=>{no(e,n)&&t.push(ke(e))}),n.querySelectorAll("[data-preset]").forEach(e=>{if(!no(e,n))return;let r=e;for(let s of ec(r.dataset.preset??""))t.push(Jr(r,s))}),n.querySelectorAll("[data-intent]:not([data-body]), [data-field-role]:not([data-body]):not([data-intent])").forEach(e=>{if(!no(e,n))return;let r=sc(e);r&&t.push(ke(e,r))}),t}function ac(n){let t=n.el;if(typeof t.getAttribute!="function")return;let e=t.getAttribute("data-strength");if(e!=null){let l=Number.parseFloat(e);Number.isFinite(l)&&(n.strength=l,n.M=l)}let r=t.getAttribute("data-range");if(r!=null){let l=Number.parseFloat(r);Number.isFinite(l)&&(n.range=l)}let s=t.getAttribute("data-spin");if(s!=null){let l=Number.parseFloat(s);Number.isFinite(l)&&(n.spin=l)}let i=t.getAttribute("data-angle");if(i!=null){let l=Number.parseFloat(i);Number.isFinite(l)&&(n.angle=l*Math.PI/180,n.ux=Math.cos(n.angle),n.uy=Math.sin(n.angle))}}function tn(n,t,e,r=0,s=0){let i=e*.15;for(let l of n){let d=l.rect?l.rect():l.el.getBoundingClientRect(),g=d.left-r,w=d.top-s;l.cx=g+d.width/2,l.cy=w+d.height/2,l.hw=d.width/2,l.hh=d.height/2,l.on=l.el.dataset.active==="1",l.vis=w+d.height>-i&&w<e+i&&g+d.width>-i&&g<t+i,ac(l)}}var Zr="field:register-body",ts="field:unregister-body",es="field:update-body";var en=class{constructor(){Y(this,"hosts",new Map)}register(t){this.hosts.set(t.element,t)}unregister(t){this.hosts.delete(t)}get size(){return this.hosts.size}bodies(t){let e=[];for(let[r,s]of this.hosts){if(!r.isConnected){this.hosts.delete(r);continue}let i=s.attrs?cc(s.attrs,r):void 0,l=t(r,i);s.getRect&&(l.rect=s.getRect),s.writeTarget&&(l.writeTarget=s.writeTarget),e.push(l)}return e}};function cc(n,t){return{get:e=>n[e]??t.getAttribute("data-"+e),has:e=>e in n||t.hasAttribute("data-"+e)}}function rs(n,t,e=.12){return n>=t?0:(1-n/t)*e}function nn(n,t,e){if(n===t)return .5;let r=(e-n)/(t-n);return r<0?0:r>1?1:r}var ns=Object.freeze([]);function oo(n,t,e,r,s){let i={x:nn(n,t,s),y:0},l={x:1,y:nn(t,e,s)},d={x:nn(r,e,s),y:1},g={x:0,y:nn(n,r,s)},w=(M,z)=>({x1:M.x,y1:M.y,x2:z.x,y2:z.y});switch((n>s?8:0)|(t>s?4:0)|(e>s?2:0)|(r>s?1:0)){case 0:case 15:return ns;case 1:case 14:return[w(g,d)];case 2:case 13:return[w(d,l)];case 3:case 12:return[w(g,l)];case 4:case 11:return[w(i,l)];case 6:case 9:return[w(i,d)];case 7:case 8:return[w(g,i)];case 5:return[w(g,i),w(d,l)];case 10:return[w(g,d),w(i,l)];default:return ns}}function ro(n,t,e,r,s,i,l,d=1){if(l<=0)return;let g=Math.max(0,Math.floor((s-l)/r)),w=Math.min(t-1,Math.ceil((s+l)/r)),m=Math.max(0,Math.floor((i-l)/r)),M=Math.min(e-1,Math.ceil((i+l)/r)),z=l*l;for(let E=m;E<=M;E++)for(let T=g;T<=w;T++){let P=T*r-s,_=E*r-i,I=P*P+_*_;if(I>=z)continue;let G=1-Math.sqrt(I)/l,J=E*t+T;n[J]=n[J]+d*G*G}}function ss(n,t,e){let r=-1,s=1/0;for(let i=0;i<e.length;i++){let l=e[i],d=l.x-n,g=l.y-t,w=d*d+g*g;w<s&&(s=w,r=i)}return r}function is(n,t,e=1){let r=(n*2.6+t*2.5)*e;return r<2?2:r}function as(n,t,e,r,s,i){let l=n-s,d=t-i,g=Math.hypot(l,d);return g<1e-6?0:(l*e+d*r)/g}function cs(n,t){if(t<=0)return 0;let e=n/(.35*t);return e<-1?-1:e>1?1:e}function ls(n,t){return t<=0||n>=t?0:1-Math.sqrt(n/t)}function fs(n,t){let e=n+t*.6;return e<-1?-1:e>1?1:e}var lc=[96,160,255],os=[226,230,240],fc=[255,72,48];function ds(n,t){let e=t<-1?-1:t>1?1:t,r=e<0?lc:os,s=e<0?os:fc,i=e<0?e+1:e;return n[0]=r[0]+(s[0]-r[0])*i,n[1]=r[1]+(s[1]-r[1])*i,n[2]=r[2]+(s[2]-r[2])*i,n}function us(n,t,e,r){let s=.3*r,i=s>0?(n*n+t*t)/(s*s):0,l=.55*e+.55*(i>1?1:i);return l<0?0:l>1?1:l}var on=[[12,2,0],[130,24,2],[235,100,10],[255,180,90],[255,236,200],[201,218,255]];function hs(n,t){let r=(t<0?0:t>1?1:t)*(on.length-1),s=Math.min(Math.floor(r),on.length-2),i=r-s,l=on[s],d=on[s+1];return n[0]=l[0]+(d[0]-l[0])*i,n[1]=l[1]+(d[1]-l[1])*i,n[2]=l[2]+(d[2]-l[2])*i,n}function ys(n,t){let e=n<0?-n:n;return t/(t+e)}function so(n,t,e){return t+(n-t)*e}function ms(n){return 1-.55*(n<0?0:n>1?1:n)}function ps(n){return 4.5*(n<0?0:n>1?1:n)}function gs(n,t,e){let r=[];for(let s=0;s<e;s++)for(let i=0;i<t;i++){let l=n[s*t+i];i+1<t&&n[s*t+i+1]!==l&&r.push({x1:i+.5,y1:s-.5,x2:i+.5,y2:s+.5}),s+1<e&&n[(s+1)*t+i]!==l&&r.push({x1:i-.5,y1:s+.5,x2:i+.5,y2:s+.5})}return r}var xs=24,dc=.12,uc=.22,Se=class{constructor(t,e){Y(this,"grid");Y(this,"peak",.001);Y(this,"cell",xs);this.grid=new de(Math.max(1,t),Math.max(1,e),"diffuse",xs)}resize(t,e){this.grid.resize(t,e)}clear(){this.grid.clear(),this.peak=.001}update(t){for(let s of t)this.grid.deposit(s.x,s.y,1);this.grid.stepDiffuse(uc,dc);let e=this.grid.max(),r=e>this.peak?.25:.03;this.peak+=(Math.max(e,.001)-this.peak)*r}norm(t,e){return mt(this.grid.sample(t,e)/this.peak,0,1)}gradient(t,e){if(this.peak<=0)return{x:0,y:0};let r=this.grid.gradient(t,e);return{x:r.x/this.peak,y:r.y/this.peak}}};var hc={position:"fixed",inset:"0",width:"100%",height:"100%",zIndex:"0",pointerEvents:"none",display:"block"},vs=Object.entries(hc).map(([n,t])=>`${n.replace(/[A-Z]/g,e=>"-"+e.toLowerCase())}:${t}`).join(";");function bs(n){let t=n.width,e=n.height,r=null,s=0;return{root:{querySelectorAll:()=>[],querySelector:()=>null,contains:()=>!1},viewport:()=>({width:t,height:e,dpr:1}),scrollY:()=>0,scrollHeight:()=>e,reducedMotion:()=>!1,hidden:()=>!1,raf:l=>(r=l,1),cancelRaf:()=>{r=null},createCanvas:()=>{throw new Error("headlessHost does not render \u2014 use render:'none' and the signal read-outs (onFeedback / sampleScalar / readParticles).")},onResize:()=>()=>{},onScroll:()=>()=>{},onVisibility:()=>()=>{},onInput:()=>()=>{},onBodyEvent:()=>()=>{},tick(l){s=l??s+1e3/60;let d=r;r=null,d?.(s)},resize(l,d){t=l,e=d}}}var ws="10px ui-monospace, SFMono-Regular, Menlo, monospace";function io(n,t){let e=0,r=0;return{size(s,i,l){e=s,r=i,n.width=Math.floor(s*l),n.height=Math.floor(i*l),t.setTransform(l,0,0,l,0,0)},clear(){t.clearRect(0,0,e,r)},segments(s,i){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath();for(let l=0;l+3<s.length;l+=4)t.moveTo(s[l],s[l+1]),t.lineTo(s[l+2],s[l+3]);t.stroke()},polyline(s,i){if(!(s.length<4)){t.strokeStyle=`rgba(${i.r},${i.g},${i.b},${i.alpha})`,t.lineWidth=i.width,t.lineCap="round",t.beginPath(),t.moveTo(s[0],s[1]);for(let l=2;l+1<s.length;l+=2)t.lineTo(s[l],s[l+1]);t.stroke()}},rect(s,i,l,d,g,w,m,M){t.fillStyle=`rgba(${g},${w},${m},${M})`,t.fillRect(s,i,l,d)},text(s,i,l,d,g,w,m){t.font=ws,t.textBaseline="middle",t.fillStyle=`rgba(${d},${g},${w},${m})`,t.fillText(s,i,l)},measureText(s){return t.font=ws,t.measureText(s).width}}}var ao=(n,t)=>{if(t.density!==void 0){let e=t.density.toFixed(3);n.style.setProperty("--d",e),n.style.setProperty("--field-density",e)}if(t.heatmapDensity!==void 0){let e=t.heatmapDensity.toFixed(3);n.style.setProperty("--field-heatmap-density",e)}if(t.load!==void 0){let e=t.load.toFixed(3);n.style.setProperty("--load",e)}if(t.entropy!==void 0&&n.style.setProperty("--entropy",t.entropy.toFixed(3)),t.coherence!==void 0&&n.style.setProperty("--coherence",t.coherence.toFixed(3)),t.temperature!==void 0&&n.style.setProperty("--temperature",t.temperature.toFixed(3)),t.lit!==void 0){let e=t.lit;n.style.setProperty("--lit",e.toFixed(3));let r=n.dataset.fxLit==="1";e>.5&&!r?(n.dataset.fxLit="1",n.dispatchEvent(new CustomEvent("field:lit",{detail:{value:e}}))):e<.4&&r&&(n.dataset.fxLit="0",n.dispatchEvent(new CustomEvent("field:dim",{detail:{value:e}})))}},co=ao;var rn=class{constructor(t){Y(this,"lit",!1);Y(this,"lastEdgeMs",-1/0);Y(this,"cfg");this.cfg=t}update(t,e){let r=e-this.lastEdgeMs>=this.cfg.debounceMs;return!this.lit&&t>=this.cfg.enter&&r?(this.lit=!0,this.lastEdgeMs=e,"entered"):this.lit&&t<=this.cfg.exit&&r?(this.lit=!1,this.lastEdgeMs=e,"exited"):null}get isLit(){return this.lit}reset(){this.lit=!1,this.lastEdgeMs=-1/0}};var yc={strengthen:1.5,decay:.3,remember:.2},lo=n=>n<0?0:n>1?1:n;function Ms(n,t,e,r,s=yc){n.active=t,n.tension=lo(e),n.strength=lo(n.strength+(t?s.strengthen:-s.decay)*r),n.memory=lo(n.memory+(t?s.remember:-s.remember*.5)*r)}function ks(n,t,e=Math.random){let r=[],s=t.absorbR+6;for(let i of n){if(i.cap!==t)continue;let l=e()*Math.PI*2,d=4+e()*3;i.cap=null,i.x=t.cx+Math.cos(l)*s,i.y=t.cy+Math.sin(l)*s,i.vx=Math.cos(l)*d,i.vy=Math.sin(l)*d,i.z&&(i.z=0),i.vz&&(i.vz=0),i.heat=1,i.age=void 0,r.push(i)}return t.accreted=0,r}function fo(n){if(n.capacity<=0)return 0;let t=n.accreted/n.capacity;return t<0?0:t>1?1:t}function Ss(n,t){return t&&!n?{fire:"captured",armed:!0}:!t&&n?{fire:"released",armed:!1}:{fire:null,armed:n}}function Es(n,t){let e=[];for(let r of n)r.when!=="active"||!r.tokens.includes("sink")||(r.wasOn&&!r.on&&r.accreted>0&&(t(r),e.push(r)),r.wasOn=r.on);return e}function uo(n,t){let e=t.cx-n.x,r=t.cy-n.y;return e*e+r*r<t.absorbR*t.absorbR}function Fs(n,t,e=.14){let r=n+(t-n)*e;return r<.001?0:r>.999?1:r}function zs(n,t,e,r){let s=n.x+t.x,i=n.y+t.y,l=t.x+(e.x-s)*r,d=t.y+(e.y-i)*r,g=1-r;return{tx:l,ty:d,scale:g,opacity:g}}function mc(n){let t=0;for(let e of n)t+=.5*(e.m||1)*(e.vx*e.vx+e.vy*e.vy+(e.vz??0)*(e.vz??0));return t}function pc(n){let t=0;for(let e of n)t+=e.heat;return t}function As(n){let t=mc(n),e=pc(n);return{kinetic:t,thermal:e,total:t+e,count:n.length}}var gc={neutral:{vx:0,vy:0,charge:0,m:1,heat:0},positive:{vx:1,vy:0,charge:1,m:1,heat:0},negative:{vx:1,vy:0,charge:-1,m:1,heat:0},still:{vx:0,vy:0,charge:1,m:1,heat:0},fast:{vx:6,vy:0,charge:1,m:1,heat:0},hot:{vx:0,vy:0,charge:0,m:1,heat:1},massive:{vx:0,vy:0,charge:0,m:6,heat:0}};function xc(n,t,e){let r=n.cx-t,s=n.cy-e;return{dx:r,dy:s,dist:Math.max(Math.hypot(r,s),1),form:{},c:12,G:1,t:0}}function ho(n,t,e,r,s,i=gc.neutral){let l=ur(),d=xc(e,r,s);d.accum=l;for(let g of t){let w=n[g];if(!w)continue;let m={x:r,y:s,vx:i.vx,vy:i.vy,charge:i.charge,m:i.m,heat:i.heat,size:1,cap:null};try{Gn(w,e,m,d)}catch{}}return l}var sn={x:0,y:0},gt=[0,0,0];function yo(n){if(!n)return{};let t={};return n.allowBodyDataInSnapshots!=null&&(t.allowBodyDataInSnapshots=n.allowBodyDataInSnapshots),n.allowMotionProjection!=null&&(t.allowMotionProjection=n.allowMotionProjection),n.maxMotionBudget!=null&&(t.maxMotionBudget=n.maxMotionBudget),n.budgets&&(t.budgets={...n.budgets}),t}function vc(n){let t={debug:{includeParticles:!0,includeRelationships:!0,includeData:!0,includeInfluences:!0},agent:{includeParticles:!1,includeRelationships:!0,includeData:!1,includeInfluences:!0},"bug-report":{includeParticles:!1,includeRelationships:!0,includeData:!1,includeInfluences:!0},public:{includeParticles:!1,includeRelationships:!1,includeData:!1,includeInfluences:!1}},e=n.profile;if(!e)return{includeParticles:n.includeParticles===!0,includeRelationships:n.includeRelationships!==!1,includeData:n.includeData===!0,includeInfluences:n.includeInfluences===!0};let r=t[e];return{includeParticles:r.includeParticles&&n.includeParticles!==!1,includeRelationships:r.includeRelationships&&n.includeRelationships!==!1,includeData:r.includeData&&n.includeData!==!1,includeInfluences:r.includeInfluences&&n.includeInfluences!==!1}}function an(n,t){let e={body:"bodies",relationship:"relationships",influence:"influences",projection:"projections"};for(let r of t){let s=r.indexOf(".");if(s<0){delete n[r];continue}let i=r.slice(0,s),l=r.slice(s+1),d=e[i];if(d&&Array.isArray(n[d]))for(let g of n[d])g&&typeof g=="object"&&delete g[l];else if(i==="metrics"&&n.metrics&&typeof n.metrics=="object")delete n.metrics[l];else{let g=n[i];g&&typeof g=="object"&&delete g[l]}}return n}var bc=8,wc=8,Mc=.05,Ts=.02,kc=1,Sc=2;function cn(n,t={}){let e=null;if((t.render??"none")!=="none"&&(e=n.getContext("2d"),!e))throw new Error("Fundamental: 2D canvas context unavailable");let r=t.overlayCanvas??null,s=e?r?.getContext("2d")??null:null,i=t.overlayBackend??(r&&s?io(r,s):null);function l(){i||(!r&&t.overlayCanvasProvider&&(r=t.overlayCanvasProvider()??null),!(!r||!e)&&(s??(s=r.getContext("2d")),s&&(i=t.overlayBackend??io(r,s),i.size(L,R,A.viewport().dpr))))}let d=new Xe,g=1,w=new Map,m=mr(),M=new Map,z=o=>(M.get(o)?.size??0)>0;function E(o,a){let c=M.get(o);if(c)for(let v of c)v(a)}let T=new Qe;function P(o,a){z(o)&&T.record(o,a)}function _(){T.flush(E)}let I=new WeakMap,G=new Map,J=new Map;function y(o){let a=z("enter")||z("exit"),c=z("met");if(!a&&!c)return;for(let p=0;p<o.length;p++){let b=o[p];if(a){let h=G.get(b);h||G.set(b,h=new Set);let u=b.range*b.range;for(let f=0;f<o.length;f++){if(p===f)continue;let x=o[f],F=x.cx-b.cx,k=x.cy-b.cy,S=F*F+k*k<u;S&&!h.has(x)?(h.add(x),z("enter")&&P("enter",{body:b,other:x})):!S&&h.has(x)&&(h.delete(x),z("exit")&&P("exit",{body:b,other:x}))}}if(c){let h=J.get(b);h||J.set(b,h=new Set);for(let u=p+1;u<o.length;u++){let f=o[u],x=Math.abs(f.cx-b.cx)<b.hw+f.hw&&Math.abs(f.cy-b.cy)<b.hh+f.hh;x&&!h.has(f)?(h.add(f),P("met",{a:b,b:f})):!x&&h.has(f)&&h.delete(f)}}}let v=new Set(o);for(let p of[G,J])for(let b of p.keys())v.has(b)||p.delete(b)}let X=[],bt=new WeakMap,tt=[],Fe=0,Vt=new WeakMap,ze=new WeakMap,It=new Map,H=new Map;if(pr(m),xr(m),wr(m),!t.host)throw new Error("Fundamental: createField requires opts.host. Use @fundamental-engine/vanilla (createField/mountField) or @fundamental-engine/elements / @fundamental-engine/react, or pass browserHost() from @fundamental-engine/dom.");let A=t.host,j=[],et=()=>A.reducedMotion?.()??!1,nt=yo(t.policy),wt=()=>{if(et())return 0;let o=1;return nt.allowMotionProjection===!1?0:(nt.maxMotionBudget!=null&&(o=Math.min(o,nt.maxMotionBudget)),nt.budgets?.motion!=null&&(o=Math.min(o,nt.budgets.motion)),Math.max(0,Math.min(1,o)))},ut=wt()<=0,Ft=.5,Xt=()=>{if(nt.allowBodyDataInSnapshots===!1)return!1;let o=nt.budgets?.privacy;return!(o!=null&&o<Ft)},Nt=Bn[t.theme??Wn]??Bn[Wn],O={accent:t.accent??Ue(t.palette)[0]??qe[0]??"#4da3ff",density:t.density&&t.density>0?t.density:1,render:t.render??"none",waves:t.waves??!1,waveStyle:t.waveStyle??"linear",waveCenter:t.waveCenter??null,background:t.background??"opaque",mass:t.mass??!1,reaction:t.reaction??!1,separation:t.separation!=null&&t.separation>=0?t.separation:0,ambientOrbit:t.ambientOrbit!=null&&t.ambientOrbit>=0?t.ambientOrbit:ve.ambient.preset.orbit,ambientWander:t.ambientWander!=null&&t.ambientWander>=0?t.ambientWander:ve.ambient.preset.wander,attention:t.attention??!1,causality:t.causality??!1,heatmap:t.heatmap??!1,overlay:t.overlay??"off",gridWarp:t.gridWarp!=null&&t.gridWarp>=0?t.gridWarp:1,gridIntensity:t.gridIntensity!=null&&t.gridIntensity>=0?Math.min(t.gridIntensity,1):.16,gradientCool:t.gradientCool?pt(t.gradientCool):Nt.cool,gradientWarm:t.gradientWarm?pt(t.gradientWarm):Nt.warm,waveBaseline:(t.waveBaseline??Nt.wave).map(pt),dprCap:t.dprCap&&t.dprCap>0?t.dprCap:2,depth:t.depth&&t.depth>0?t.depth:0,heatCenterX:t.heatCenter&&Number.isFinite(t.heatCenter.x)?t.heatCenter.x:.5,heatCenterY:t.heatCenter&&Number.isFinite(t.heatCenter.y)?t.heatCenter.y:.4,redshiftObserverX:t.redshiftObserver&&Number.isFinite(t.redshiftObserver.x)?t.redshiftObserver.x:.5,redshiftObserverY:t.redshiftObserver&&Number.isFinite(t.redshiftObserver.y)?t.redshiftObserver.y:.5,depthFocal:t.depthFocal!=null&&t.depthFocal>0?t.depthFocal:480,heatmapFadeStart:t.heatmapFade&&Number.isFinite(t.heatmapFade.start)?t.heatmapFade.start:.3,heatmapFadeSpan:t.heatmapFade&&Number.isFinite(t.heatmapFade.span)&&t.heatmapFade.span>0?t.heatmapFade.span:.85,integrator:t.integrator==="fixed"||t.integrator==="velocity-verlet"?t.integrator:"legacy",feedbackSink:t.feedbackSink??ao},ct=null,B=[],L=0,R=0,Z=0,ot=0,ee=!1,he=1,ye=0,po=new WeakMap,Kt=0,Tt=0,go=!0,yn={...ve.ambient.preset,orbit:O.ambientOrbit,wander:O.ambientWander},xo={...yn},mn="ambient",_s=0,vo=t.identify,pn=o=>{if(o.identity)return o.identity;let a;return vo&&o.el&&(a=vo(o.el)),a||(a={id:(o.el&&o.el.id?o.el.id:void 0)??`body-${_s++}`}),o.identity=a,a},Jt=o=>pn(o).id,Qt=new Map,ne=new Map,bo=(o,a)=>{let c=Qt.get(o);if(!c)return 0;let v=0;for(let p of c.values())v+=p.mass*Me(p.at,a,p.halfLife);return v>1?1:v};function Ls(o,a){let c=typeof o=="string"?{id:o}:o,v=c.id;if(!v)return;let p=a?.amount??1,b=a?.source??"system",h=a?.halfLife??bc,u=a?.at??W.t;typeof o!="string"&&(c.namespace||c.kind||c.host)&&ne.set(v,c);let f=Qt.get(v);f||Qt.set(v,f=new Map);let x=f.get(b),k=(x?x.mass*Me(x.at,u,x.halfLife):0)+p;f.set(b,{mass:k,at:u,halfLife:h}),P("focus",{target:v,identity:ne.get(v)??c,source:b,amount:p,salience:bo(v,u),sourceSalience:k>1?1:k,frame:Tt,time:u})}function Bs(o){let a=W.t,c=o?.limit??wc,v=o?.threshold??Mc,p=o?.source,b=u=>u.find(f=>f.source===p)?.weight??0,h=[];for(let[u,f]of Qt){let x=[],F=0,k=0;for(let[S,C]of f){let D=C.mass*Me(C.at,a,C.halfLife);D<=0||(F+=D,C.at>k&&(k=C.at),x.push({source:S,weight:D>1?1:D,updatedAt:C.at}))}F>1&&(F=1),!((p?b(x):F)<v)&&(x.sort((S,C)=>C.weight-S.weight),h.push({target:u,identity:ne.get(u)??{id:u},salience:F,sources:x,updatedAt:k}))}return h.sort((u,f)=>p?b(f.sources)-b(u.sources):f.salience-u.salience),{frame:Tt,time:a,entries:h.slice(0,c)}}function Ws(){if(Qt.size===0)return;let o=W.t;for(let[a,c]of Qt){for(let[v,p]of c)p.mass*Me(p.at,o,p.halfLife)<Ts&&c.delete(v);c.size===0&&(Qt.delete(a),ne.delete(a))}for(let a of B){let c=bo(Jt(a),o);if(c>Ts){a.salience=c;let v=1+kc*c;a.focusMul=v>1?Math.min(Sc,v):void 0,a.identity&&!ne.has(a.identity.id)&&ne.set(a.identity.id,a.identity)}else a.salience!==void 0&&(a.salience=void 0),a.focusMul!==void 0&&(a.focusMul=void 0)}}let wo=o=>{let a={density:o.d,count:o.count,engaged:o.on?1:0};o.attn!==void 0&&(a.attention=o.attn),o.salience!==void 0&&(a.salience=o.salience),o.capacity>0&&(a.load=o.accreted/o.capacity);let c=o.metrics?{entropy:o.metrics.entropy,coherence:o.metrics.coherence,temperature:o.metrics.temperature}:{};return{metrics:a,dimensions:c}},Hs=0,Bt=new Map,qs=o=>({id:o.id,label:o.label,channels:o.channels.slice(),surfaces:o.surfaces.slice(),...o.reducedMotionEquivalent!==void 0?{reducedMotionEquivalent:o.reducedMotionEquivalent}:{},...o.accessibilityEquivalent!==void 0?{accessibilityEquivalent:o.accessibilityEquivalent}:{}}),Ae=()=>[...Bt.values()].map(qs),Te=[];function js(){for(let o of Te)Bt.get(o.id)?.apply?.(o.source(),o.target)}let Us={register(o){return Bt.set(o.id,o),()=>{Bt.get(o.id)===o&&Bt.delete(o.id)}},unregister(o){Bt.delete(o)},get(o){return Bt.get(o)},list:Ae,apply(o,a,c){Bt.get(o)?.apply?.(a,c)},bind(o,a,c){let v={id:o,target:a,source:c};return Te.push(v),()=>{let p=Te.indexOf(v);p>=0&&Te.splice(p,1)}},lint:()=>kr(Ae())},Mo=.9,ko=8,Ys=4800,So=.02;function Gs(){for(let o of B){if(o.authority!=="dynamic"||!o.vis)continue;o.bx===void 0&&(o.bx=o.cx,o.by=o.cy,o.bvx=0,o.bvy=0);let a=o.bx??o.cx,c=o.by??o.cy,v=B.filter(S=>S!==o&&S.vis&&S.tokens.length>0),{fx:p,fy:b}=Gt(v,m.forces,W,a,c);if(O.mass){let S=o.hw*2*(o.hh*2);o.inertia=Math.min(4,Math.max(.4,Math.sqrt(S/Ys)))}let h=1/Math.max(o.inertia??o.M,1e-4),u=0,f=0;if(O.reaction&&o.tokens.length>0){let S=o.range*o.range,C=[o];for(let D of d.particles){if(D.cap)continue;let $=D.x-a,q=D.y-c;if($*$+q*q>S)continue;let K=Gt(C,m.forces,W,D.x,D.y);u-=K.fx,f-=K.fy}}let x=(o.bvx??0)+(p+u*So)*h*W.dt,F=(o.bvy??0)+(b+f*So)*h*W.dt;x*=Mo,F*=Mo;let k=Math.hypot(x,F);if(k>ko){let S=ko/k;x*=S,F*=S}o.bvx=x,o.bvy=F,o.bx=a+x*W.dt,o.by=c+F*W.dt,o.cx=o.bx,o.cy=o.by}}let Eo=globalThis.structuredClone,Vs=o=>{if(o==null)return o;try{return Eo?Eo(o):JSON.parse(JSON.stringify(o))}catch{try{return JSON.parse(JSON.stringify(o))}catch{return o}}},vt=[],Wt=[],Fo=0,Zt=null,ht=t.rng??Math.random,gn=t.now??(()=>performance.now()),it=ut?1:0,xn=NaN,Dt=null,me=null,oe=null,Ht=0,_t=0,Ce=null,vn=[],bn=null,Oe=null,Xs=Math.round(130*O.density)*4,xt={x:0,y:0,k:0},yt=null,Lt=null,zo=0,Ao=0,To=Ue(t.palette).map(pt),lt=pt(O.accent),Re=null,wn=[],qt=[],re=[],se=[],Mn=[],kn=[],ie=[],Pe=new en,Sn=!1,En=()=>{Sn||(Sn=!0,queueMicrotask(()=>{Sn=!1,Ie()}))},Ks=o=>{for(let a of["--d","--field-density","--load","--entropy","--coherence","--temperature"])o.style.removeProperty(a)},Js=o=>{let a=o.detail;a?.element&&(Pe.register(a),En())},Qs=o=>{let a=o.detail;a?.element&&(Pe.unregister(a.element),Ks(a.writeTarget??a.element),En())},Zs=En,Ot={x:0,y:0,vx:0,vy:0,m:1,heat:0,size:1,cap:null},Co=gn(),W={dx:0,dy:0,dz:0,dist:1,form:{...yn},W:0,H:0,D:O.depth,integrator:O.integrator,t:0,frameN:0,dt:ut?0:1,c:12,G:1,scrollV:0,rng:ht,spark:(o,a,c,v)=>Oo(o,a,c,v),supernova:o=>{let a=ks(d.particles,o,ht),c=new Set(a);for(let v of d.particles){if(c.has(v))continue;let p=v.x-o.cx,b=v.y-o.cy,h=Math.hypot(p,b)||1;if(h<320){let u=(1-h/320)*4;v.vx+=p/h*u,v.vy+=b/h*u,v.heat=Math.max(v.heat,.8)}}Qn(Wt,vt,o.cx,o.cy,320,L,R,W.t,v=>void d.add(ae(v))),li(o),Fn(o.el,"field:saturated",{peak:a.length}),o.el.dataset.fxCap==="1"&&(o.el.dataset.fxCap="0",ce(o.el,"released",{accreted:0,load:0}),z("released")&&P("released",{body:o,count:a.length}),I.delete(o))},spawn:o=>{d.size>=Xs||d.add(ae(o))},neighbors:(o,a)=>d.neighbors(o,a),grid:o=>{let a=w.get(o);if(!a){let c=o.startsWith("wave")?"wave":o.startsWith("memory")?"memory":"diffuse";a=new de(L,R,c),w.set(o,a)}return a}};function Oo(o,a,c,v){if(ut||se.length>260)return;let p=v?pt(v):[255,122,69],b=Or(c,ht);for(let h=0;h<b;h++){let u=ht()*6.28318,f=.8+ht()*(c>0?c:1)*1.7;se.push({x:o,y:a,vx:Math.cos(u)*f,vy:Math.sin(u)*f,life:1,c:p})}}function ae(o={}){let a=o.size??.7+ht()*1.8;return{id:o.id??g++,x:o.x??ht()*L,y:o.y??ht()*R,vx:o.vx??(ht()-.5)*.25,vy:o.vy??(ht()-.5)*.18,z:o.z??(O.depth>0?ht()*O.depth:0),vz:o.vz??(O.depth>0?(ht()-.5)*.18:0),m:o.m??(O.mass?a:1),heat:o.heat??0,size:a,gx:o.gx??ht(),gy:o.gy??ht(),gz:o.gz??ht(),cap:null,...o.age!=null?{age:o.age}:{},...o.color!=null?{color:o.color}:{},...o.species!=null?{species:o.species}:{}}}let $e=[];function ti(){if(!$e.length)return;let o=d.particles;for(let a=0;a<o.length;a++){let c=$e[a%$e.length];o[a].atom=c;let v=typeof c.weight=="number"?Math.max(0,Math.min(1,c.weight)):.5;o[a].size*=.6+v*.9,o[a].m*=.6+v*1.2}}function Ro(){d.clear();let o=Math.round(130*O.density);for(let a=0;a<o;a++)d.add(ae());ti(),vt=O.waves?rr(O.waveBaseline):[],Wt=O.waves?sr(vt.length,O.density,ht):[],Fo=Wt.length}function Ie(){let o=B,a=Qr(A.root);if(Pe.size>0){let h=new Set(a.map(u=>u.el));B=a.concat(Pe.bodies(ke).filter(u=>!h.has(u.el)))}else B=a;X.length>0&&(B=B.concat(X));let c=null,v=!1;if(o.length>0){let h=new Map;for(let f of o){let x=h.get(f.el);x?x.push(f):h.set(f.el,[f])}let u=new Map;for(let f of B){let x=h.get(f.el);if(!x)continue;let F=u.get(f.el)??0;u.set(f.el,F+1);let k=x[F];if(!k||k===f)continue;k.identity!==void 0&&(f.identity=k.identity),k.bx!==void 0&&(f.bx=k.bx,f.by=k.by,f.bvx=k.bvx,f.bvy=k.bvy),f.d=k.d,k.attn!==void 0&&(f.attn=k.attn),f.accreted=k.accreted,f.count=k.count,k.wasOn!==void 0&&(f.wasOn=k.wasOn);let S=Vt.get(k);S&&Vt.set(f,S);let C=I.get(k);C!==void 0&&I.set(f,C),(c??(c=new Map)).set(k,f),k.accreted>0&&(v=!0)}if(v)for(let f of d.particles){if(!f.cap)continue;let x=c.get(f.cap);x&&(f.cap=x)}}tn(B,L,R,Z,ot),di();let p=new Map(qt.map(h=>[h.el,h]));qt=[...A.root.querySelectorAll("[data-move]")].map(h=>{let u=h,f=u.getBoundingClientRect(),x=Number.parseFloat(u.dataset.mass??""),F=Number.isFinite(x)?x:Nr(f.width*f.height),k=(u.dataset.move??"").trim()==="layout",S=u.hasAttribute("data-dock"),C=u.hasAttribute("data-warp"),D=p.get(u);if(D){let $=D.docked?c?.get(D.docked)??D.docked:null;return{el:u,o:D.o,mEl:F,layout:k,dockable:S,dock:D.dock,docked:$,warpable:C,warpCool:D.warpCool}}return{el:u,o:{x:0,y:0,vx:0,vy:0},mEl:F,layout:k,dockable:S,dock:{dock:0},docked:null,warpable:C,warpCool:0}}),Mn=[...A.root.querySelectorAll("[data-on]")].map(h=>{let u=h;return{el:u,body:B.find(f=>f.el===u)??null,bindings:Zn(u.dataset.on??"")}}),kn=[...A.root.querySelectorAll("[data-class]")].map(h=>{let u=h;return{el:u,body:B.find(f=>f.el===u)??null,bindings:Zn(u.dataset.class??"")}});for(let h of B){if(!h.pair)continue;let u=null;try{u=A.root.querySelector(h.pair)}catch{u=null}h.pairBody=u?B.find(f=>f.el===u):void 0}let b=new Map(re.map(h=>[h.el,h]));for(let[h,u]of b)if(!A.root.contains(h))for(let f of u.emitted)f.remove();re=[...A.root.querySelectorAll("[data-emit]")].map(h=>{let u=h,f=u.dataset.emit??"",x=null;try{x=f?A.root.querySelector(f):null}catch{x=null}let F=Math.max(0,Math.round(Number.parseFloat(u.dataset.max??"")||8)),k=b.get(u);if(k){let S=k.emitted.filter(C=>C.isConnected);for(;S.length>F;)S.pop().remove();return{el:u,tmpl:x,cap:F,emitted:S}}return{el:u,tmpl:x,cap:F,emitted:[]}})}function ei(){for(let o of B)if(o.pairBody){if(!o.pairBody.el.isConnected){o.warpHas=!1,o.pairBody=void 0;continue}o.pairBody.vis?(o.warpX=o.pairBody.cx,o.warpY=o.pairBody.cy,o.warpHas=!0):o.warpHas=!1}else o.pair&&(o.warpHas=!1)}function ni(){if(!(re.length===0||W.frameN%30!==0))for(let o of re){if(!o.tmpl||o.emitted.length>=o.cap)continue;let a=o.tmpl.cloneNode(!0);a.removeAttribute("id"),a.setAttribute("aria-hidden","true"),a.setAttribute("inert",""),a.dataset.fieldEmitted="",o.el.appendChild(a),o.emitted.push(a)}}function oi(){if(Mn.length!==0)for(let o of Mn){let a=o.body?{d:o.body.d,on:o.body.on,accreted:o.body.accreted}:{d:0,on:o.el.dataset.active==="1",accreted:0};for(let c of o.bindings){let v=to(c.trigger,a);v&&!c.armed?(c.armed=!0,o.el.dispatchEvent(new CustomEvent(c.event,{bubbles:!0,detail:{trigger:c.trigger,d:a.d,on:a.on,accreted:a.accreted}}))):v||(c.armed=!1)}}}function ri(){if(kn.length!==0)for(let o of kn){let a=o.body?{d:o.body.d,on:o.body.on,accreted:o.body.accreted}:{d:0,on:o.el.dataset.active==="1",accreted:0};for(let c of o.bindings){let v=to(c.trigger,a);v&&!c.armed?(c.armed=!0,o.el.classList.add(c.event)):!v&&c.armed&&(c.armed=!1,o.el.classList.remove(c.event))}}}function ce(o,a,c){o.dispatchEvent(new CustomEvent("field:"+a,{bubbles:!0,composed:!0,detail:c}))}function si(){for(let o of B){if(!o.vis||o.tokens.indexOf("sink")<0)continue;let a=o.el.dataset.fxCap==="1",c=Ss(a,o.accreted>0);c.fire==="captured"?(o.el.dataset.fxCap="1",ce(o.el,"captured",{accreted:o.accreted,load:fo(o)}),z("captured")&&P("captured",{body:o,count:o.accreted}),I.set(o,o.accreted)):c.fire==="released"&&(o.el.dataset.fxCap="0",ce(o.el,"released",{accreted:0,load:0}),z("released")&&P("released",{body:o,count:I.get(o)??0}),I.delete(o))}}let ii=[{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"}],ai=120;function Fn(o,a,c){o.dispatchEvent(new CustomEvent(a,{bubbles:!0,composed:!0,detail:c}))}function Po(o,a,c,v,p,b){let h=o.get(a);h||o.set(a,h=new Map);let u=h.get(v.metric);u||h.set(v.metric,u=new rn({enter:v.enter,exit:v.exit,debounceMs:ai}));let f=u.update(p,b);f==="entered"?Fn(c,v.rise,{metric:v.metric,value:p}):f==="exited"&&Fn(c,v.fall,{metric:v.metric,value:p})}function ci(o){for(let a of B)if(!(!a.vis||a.tokens.length===0))for(let c of ii){let v;switch(c.metric){case"density":v=a.d;break;case"attention":O.attention&&(v=a.attn??1);break;case"entropy":v=a.metrics?.entropy;break}v!==void 0&&Po(Vt,a,a.el,c,v,o)}for(let a of tt)Po(ze,a.agent,a.from.el,{metric:"memory",enter:.6,exit:.3,rise:"field:memory-threshold",fall:"field:memory-faded"},a.agent.memory,o)}function li(o){for(let a of qt)a.docked===o&&(a.docked=null,a.dock.dock=0,a.el.getAttribute("aria-hidden")==="true"&&a.el.removeAttribute("aria-hidden"),a.el.removeAttribute("inert"),a.el.style.opacity="",ce(a.el,"released",{}))}function fi(){if(qt.length===0)return;let o=qt.map(a=>{let c=a.el.getBoundingClientRect();return{x:c.left-Z+c.width/2,y:c.top-ot+c.height/2}});for(let a=0;a<qt.length;a++){let c=qt[a];if(!c.el.isConnected){c.docked&&(c.docked=null,c.dock.dock=0);continue}let v=o[a].x,p=o[a].y;if(c.docked){let x={x:v-c.o.x,y:p-c.o.y};c.dock.dock=Fs(c.dock.dock,1);let F=zs(x,c.o,{x:c.docked.cx,y:c.docked.cy},c.dock.dock);c.el.style.transform=`translate(${F.tx.toFixed(2)}px, ${F.ty.toFixed(2)}px) scale(${F.scale.toFixed(3)})`,c.el.style.opacity=F.opacity.toFixed(3),c.dock.dock>=1&&c.el.getAttribute("aria-hidden")!=="true"&&(c.el.setAttribute("aria-hidden","true"),c.el.setAttribute("inert",""));continue}Ot.x=v,Ot.y=p,Ot.vx=0,Ot.vy=0,Ot.heat=0,Ot.cap=null;for(let x of B){if(!x.vis||x.tokens.length===0||x.el===c.el)continue;let F=x.cx-v,k=x.cy-p,S=Math.hypot(F,k);W.dx=F,W.dy=k,W.dist=S<1?1:S;for(let C of x.tokens)m.forces[C]?.apply(x,Ot,W)}Ot.cap=null;let b=Ir(c.o),h=Ot.vx+b.x,u=Ot.vy+b.y;if(c.layout){let x=Dr({x:v,y:p},o,a),F=_r((k,S)=>d.near(k,S,40).length,v,p,16,6);h+=x.x+F.x,u+=x.y+F.y}let f={x:v-c.o.x,y:p-c.o.y};if($r(c.o,h,u,c.mEl,.9),c.el.style.transform=`translate(${c.o.x.toFixed(2)}px, ${c.o.y.toFixed(2)}px)`,c.dockable){let x={x:f.x+c.o.x,y:f.y+c.o.y},F=B.find(k=>k.vis&&k.el!==c.el&&k.tokens.indexOf("sink")>=0&&uo(x,k));F&&(c.docked=F,ce(c.el,"captured",{sink:F.el}))}if(c.warpCool>0&&(c.warpCool-=1),c.warpable&&c.warpCool===0){let x={x:f.x+c.o.x,y:f.y+c.o.y},F=B.find(k=>k.vis&&k.el!==c.el&&k.warpHas&&k.tokens.indexOf("warp")>=0&&uo(x,k));F&&(c.o.x=F.warpX-f.x,c.o.y=F.warpY-f.y,c.o.vx=0,c.o.vy=0,c.el.style.transform=`translate(${c.o.x.toFixed(2)}px, ${c.o.y.toFixed(2)}px)`,c.warpCool=45,ce(c.el,"relocated",{from:F.el}))}}}function di(){ie.length&&(ie=ie.filter(o=>o.el.isConnected?!0:(o.el.removeEventListener("pointerenter",o.enter),o.el.removeEventListener("pointerleave",o.leave),o.el.removeEventListener("focusin",o.enter),o.el.removeEventListener("focusout",o.leave),delete o.el.dataset.fxEngaged,!1))),A.root.querySelectorAll("[data-hot]").forEach(o=>{let a=o;if(a.dataset.fxEngaged==="1")return;a.dataset.fxEngaged="1";let c=()=>{a.dataset.active="1",Re=a.dataset.color??null;let p=a.closest("[data-index][data-threads]");if(p){let b=[...p.querySelectorAll("[data-hot]")].filter(h=>h!==a);zn(b.map(h=>({a,b:h,color:a.dataset.color??void 0})))}},v=()=>{a.dataset.active="0",Re=null,zn(null)};a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",v),a.addEventListener("focusin",c),a.addEventListener("focusout",v),ie.push({el:a,enter:c,leave:v})})}function zn(o){wn=(o??[]).map(a=>({a:a.a,b:a.b,c:pt(a.color??O.accent),seed:ht()*6.28}))}function ui(){if(wn.length===0)return;let o=W.t;e.globalCompositeOperation="lighter";for(let a of wn){let c=a.a.getBoundingClientRect(),v=a.b.getBoundingClientRect(),p=c.left-Z+c.width/2,b=c.top-ot+c.height/2,h=v.left-Z+v.width/2,u=v.top-ot+v.height/2,[f,x,F]=a.c;e.strokeStyle=`rgba(${f},${x},${F},0.22)`,e.lineWidth=1,e.beginPath(),e.moveTo(p,b),e.lineTo(h,u),e.stroke();for(let k=0;k<3;k++){let S=(o*.6+a.seed+k/3)%1,C=p+(h-p)*S,D=b+(u-b)*S;e.fillStyle=`rgba(${f},${x},${F},${(1-S)*.9})`,e.beginPath(),e.arc(C,D,2.2,0,6.28318),e.fill()}}e.globalCompositeOperation="source-over"}let Ne=0,hi=[1/0,1.5,1.25,1];function De(o){if(!e)return;let a=Math.min(o||1,O.dprCap,hi[Ne]??1/0);n.width=Math.floor(L*a),n.height=Math.floor(R*a),n.style.width=L+"px",n.style.height=R+"px",e.setTransform(a,0,0,a,0,0),i?.size(L,R,a)}function $o(){let o=A.viewport();L=o.width,R=o.height,Z=o.originX??0,ot=o.originY??0,ee=o.originX!=null||o.originY!=null,De(o.dpr),W.W=L,W.H=R,he=(A.scrollHeight?.()??R)-R||1;for(let a of w.values())a.resize(L,R);O.heatmap&&(ct?ct.resize(L,R):ct=new Se(L,R)),Ro(),Ie()}function yi(){let o=W.t,a=16;if(O.waveStyle==="circular"){let c=Zt||{x:L/2,y:R/2},v=Math.min(L,R)*.48;for(let p of vt){let[b,h,u]=p.color;e.beginPath();let f=.08,x=!0;for(let S=0;S<=2*Math.PI+.01;S+=f){let C=be(p,S,o,v),D=c.x+Math.cos(S)*C,$=c.y+Math.sin(S)*C;x?(e.moveTo(D,$),x=!1):e.lineTo(D,$)}e.closePath();let F=p.baseFrac*v+p.offsetY,k=e.createRadialGradient(c.x,c.y,Math.max(0,F-p.amp),c.x,c.y,F+p.amp+80);k.addColorStop(0,`rgba(${b},${h},${u},${(.08+p.depth*.04)*it})`),k.addColorStop(1,`rgba(${b},${h},${u},0)`),e.fillStyle=k,e.fill()}e.globalCompositeOperation="lighter";for(let p of vt){let[b,h,u]=p.color;e.beginPath();let f=.08,x=!0;for(let F=0;F<=2*Math.PI+.01;F+=f){let k=be(p,F,o,v),S=c.x+Math.cos(F)*k,C=c.y+Math.sin(F)*k;x?(e.moveTo(S,C),x=!1):e.lineTo(S,C)}e.closePath(),e.lineWidth=5,e.strokeStyle=`rgba(${b},${h},${u},${(.05+p.depth*.04)*it})`,e.stroke(),e.lineWidth=1.2,e.strokeStyle=`rgba(${b},${h},${u},${(.3+p.depth*.22)*it})`,e.stroke()}e.globalCompositeOperation="source-over"}else{for(let c of vt){let[v,p,b]=c.color;e.beginPath(),e.moveTo(0,Et(c,0,o,R,1,1,xt));for(let f=0;f<=L;f+=a)e.lineTo(f,Et(c,f,o,R,1,1,xt));e.lineTo(L,R),e.lineTo(0,R),e.closePath();let h=c.baseFrac*R+c.offsetY-c.amp,u=e.createLinearGradient(0,h,0,h+320);u.addColorStop(0,`rgba(${v},${p},${b},${(.11+c.depth*.05)*it})`),u.addColorStop(1,`rgba(${v},${p},${b},0)`),e.fillStyle=u,e.fill()}e.globalCompositeOperation="lighter";for(let c of vt){let[v,p,b]=c.color;e.beginPath(),e.moveTo(0,Et(c,0,o,R,1,1,xt));for(let h=0;h<=L;h+=a)e.lineTo(h,Et(c,h,o,R,1,1,xt));e.lineWidth=5,e.strokeStyle=`rgba(${v},${p},${b},${(.05+c.depth*.04)*it})`,e.stroke(),e.lineWidth=1.2,e.strokeStyle=`rgba(${v},${p},${b},${(.3+c.depth*.22)*it})`,e.stroke()}e.globalCompositeOperation="source-over"}}function mi(){e.globalCompositeOperation="lighter";let o=W.t,a=0;if(O.waveStyle==="circular"){let c=Zt||{x:L/2,y:R/2},v=Math.min(L,R)*.48;for(let p of Wt){let b=vt[p.wi];if(!b){a++;continue}W.dt&&(p.progress+=p.speed,p.progress>1?p.progress-=1:p.progress<0&&(p.progress+=1));let h=p.progress*2*Math.PI,u=be(b,h,o,v)+p.phase*32,f=c.x+Math.cos(h)*u,x=c.y+Math.sin(h)*u,[F,k,S]=b.color,C=p.glow?.6+.4*Math.sin(o*2.2+a):.85;p.glow&&(e.fillStyle=`rgba(${F},${k},${S},${.16*C*it})`,e.beginPath(),e.arc(f,x,p.size+2.5,0,6.28318),e.fill()),e.fillStyle=`rgba(${F},${k},${S},${C*it})`,e.beginPath(),e.arc(f,x,p.size,0,6.28318),e.fill(),a++}}else for(let c of Wt){let v=vt[c.wi];if(!v){a++;continue}W.dt&&(c.progress+=c.speed,c.progress>1?c.progress-=1:c.progress<0&&(c.progress+=1));let p=c.progress*L,b=Et(v,p,o,R,1,1,xt)+c.phase*32,[h,u,f]=v.color,x=c.glow?.6+.4*Math.sin(o*2.2+a):.85;c.glow&&(e.fillStyle=`rgba(${h},${u},${f},${.16*x*it})`,e.beginPath(),e.arc(p,b,c.size+2.5,0,6.28318),e.fill()),e.fillStyle=`rgba(${h},${u},${f},${x*it})`,e.beginPath(),e.arc(p,b,c.size,0,6.28318),e.fill(),a++}e.globalCompositeOperation="source-over"}function pi(){if(!O.attention)return;for(let c of B)c.attn=1;let o=B.filter(c=>c.vis&&c.tokens.length>0);if(o.length===0)return;let a=Qo(o);for(let c=0;c<o.length;c++)o[c].attn=a[c]}function gi(){if(!O.causality)return;let o=B.filter(c=>c.vis&&c.tokens.length>0);if(o.length===0)return;if(o.length===1){Io(o[0],o[0].d);return}let a=Zo(o.map(c=>({d:c.d,cx:c.cx,cy:c.cy})));for(let c=0;c<o.length;c++)Io(o[c],mt(o[c].d+a[c],0,1))}function Io(o,a){O.feedbackSink(o.el,{lit:a})}function xi(){for(let o of B){if(!o.feedback)continue;let a=Ko(o.count,o.on);o.d+=(a-o.d)*.08;let c=o.writeTarget??o.el;if(o.fmax){let f=Jo(o.fmin,o.fmax,o.d);po.get(c)!==f&&(po.set(c,f),c.style.fontVariationSettings=`"wght" ${f}`+(o.opsz?`, "opsz" ${o.opsz}`:""))}let v=ct?ct.norm(o.cx,o.cy):void 0,p=o.tokens.indexOf("sink")>=0&&o.capacity>0?fo(o):void 0,b=qr(o.thermo),h=o.metrics??(o.metrics={entropy:0,coherence:1,temperature:0});h.entropy+=(b.entropy-h.entropy)*.08,h.coherence+=(b.coherence-h.coherence)*.08,h.temperature+=(b.temperature-h.temperature)*.08;let u={density:o.d,heatmapDensity:v,load:p,entropy:h.entropy,coherence:h.coherence,temperature:h.temperature};O.feedbackSink(c,u),o.onFeedback?.(u)}}function vi(){if(se.length!==0){e.globalCompositeOperation="lighter";for(let o=se.length-1;o>=0;o--){let a=se[o];if(!a)continue;if(a.x+=a.vx,a.y+=a.vy,a.vx*=.9,a.vy*=.9,a.life*=.85,a.life<.05){se.splice(o,1);continue}let[c,v,p]=a.c;e.fillStyle=`rgba(${c},${v},${p},${.18*a.life})`,e.beginPath(),e.arc(a.x,a.y,2+a.life*4,0,6.28318),e.fill(),e.fillStyle=`rgba(${c},${v},${p},${a.life})`,e.beginPath(),e.arc(a.x,a.y,.6+a.life*1.5,0,6.28318),e.fill()}e.globalCompositeOperation="source-over"}}let jt=null,_e=null,le=null;function bi(){if(!ct)return;let o=R>0?mt((O.heatmapFadeStart+O.heatmapFadeSpan-ye/R)/O.heatmapFadeSpan,0,1):1;if(o<=.01)return;let a=ct.cell,c=Math.max(1,Math.ceil(L/a)),v=Math.max(1,Math.ceil(R/a));if(!jt){if(!A.createCanvas)throw new Error("Fundamental: this FieldHost provides no createCanvas() \u2014 the heatmap layer needs one. Use render:'none' (signals-first) or supply a host with a createCanvas capability.");jt=A.createCanvas(),_e=jt.getContext("2d")}if(_e){if((jt.width!==c||jt.height!==v)&&(jt.width=c,jt.height=v,le=null),le===null||Tt%3===0){le===null&&(le=_e.createImageData(c,v));let p=lt,b=le.data;for(let h=0;h<v;h++)for(let u=0;u<c;u++){let f=ct.norm(u*a+a/2,h*a+a/2),x=(h*c+u)*4;b[x]=p[0],b[x+1]=p[1],b[x+2]=p[2],b[x+3]=Math.round(mt(f*.5*it,0,1)*255)}_e.putImageData(le,0,0)}e.globalCompositeOperation="lighter",e.imageSmoothingEnabled=!0,e.globalAlpha=o,e.drawImage(jt,0,0,L,R),e.globalAlpha=1,e.globalCompositeOperation="source-over"}}function wi(){O.background==="transparent"?O.render==="trails"?(e.globalCompositeOperation="destination-out",e.fillStyle="rgba(0,0,0,0.22)",e.fillRect(0,0,L,R),e.globalCompositeOperation="source-over"):e.clearRect(0,0,L,R):(O.render==="trails"?e.fillStyle="rgba(5,6,11,0.22)":e.fillStyle="rgb(5,6,11)",e.fillRect(0,0,L,R)),yi(),ct&&Ne<2&&bi(),mi();let o=O.render!=="metaballs"&&O.render!=="streamlines"&&O.render!=="knockout"&&O.render!=="redshift"&&O.render!=="blackbody"&&O.render!=="depth";e.globalCompositeOperation="lighter";let a=lt,c=L*O.heatCenterX,v=R*O.heatCenterY,p=Math.hypot(Math.max(c,L-c),Math.max(v,R-v))||1;if(Oe===null||Tt%6===0){Oe=[];for(let h of B){if(!h.tint)continue;let u=(h.range||200)*1.4;Oe.push({b:h,r2:u*u,rgb:pt(h.tint)})}}let b=Oe;if(o)for(let h of d.particles){if(h.cap){e.fillStyle=`rgba(${a[0]},${a[1]},${a[2]},${.55*it})`,e.beginPath(),e.arc(h.x,h.y,1.3,0,6.28318),e.fill();continue}let u=Math.min(1,Math.hypot(h.x-c,h.y-v)/p),f=u*u,x=h.heat;Hn(gt,f,x,a,O.gradientCool,O.gradientWarm);let F=gt[0],k=gt[1],S=gt[2];if(b.length){let ft=0,Q=null;for(let rt of b){let Mt=h.x-rt.b.cx,kt=h.y-rt.b.cy,Ut=Mt*Mt+kt*kt;if(Ut>=rt.r2)continue;let N=1-Math.sqrt(Ut/rt.r2);N>ft&&(ft=N,Q=rt.rgb)}if(Q){let rt=ft*.7;F+=(Q[0]-F)*rt,k+=(Q[1]-k)*rt,S+=(Q[2]-S)*rt}}if(h.color){let[ft,Q,rt]=pt(h.color);F+=(ft-F)*.75,k+=(Q-k)*.75,S+=(rt-S)*.75}let C=O.depth>0?1-Math.min(Math.abs(h.z??0)/O.depth,1)*.55:1,D=(h.size*(1-.4*f)+x*2)*C,$=mt((.5-.3*f+x*.5)*it*C,0,1),q=F|0,K=k|0,dt=S|0;e.fillStyle=`rgba(${q},${K},${dt},${.12*$})`,e.beginPath(),e.arc(h.x,h.y,D+1.2,0,6.28318),e.fill(),e.fillStyle=`rgba(${q},${K},${dt},${$})`,e.beginPath(),e.arc(h.x,h.y,D,0,6.28318),e.fill()}if(vi(),ui(),e.globalCompositeOperation="source-over",O.render==="links"){e.globalCompositeOperation="lighter";let h=lt,u=90;e.lineWidth=.6;for(let f of d.particles)if(!f.cap)for(let x of d.neighbors(f,u)){if(x.x<f.x||x.x===f.x&&x.y<f.y)continue;let F=rs(Math.hypot(x.x-f.x,x.y-f.y),u);F<=0||(e.strokeStyle=`rgba(${h[0]},${h[1]},${h[2]},${F})`,e.beginPath(),e.moveTo(f.x,f.y),e.lineTo(x.x,x.y),e.stroke())}e.globalCompositeOperation="source-over"}if(O.render==="metaballs"){let x=Math.ceil(L/16)+1,F=Math.ceil(R/16)+1;!Dt||Dt.length!==x*F?Dt=new Float32Array(x*F):Dt.fill(0);for(let S of d.particles)S.cap||ro(Dt,x,F,16,S.x,S.y,34,1);let k=lt;e.globalCompositeOperation="lighter",e.strokeStyle=`rgba(${k[0]},${k[1]},${k[2]},${.5*it})`,e.lineWidth=1.4,e.lineCap="round",e.beginPath();for(let S=0;S<F-1;S++)for(let C=0;C<x-1;C++){let D=Dt[S*x+C],$=Dt[S*x+C+1],q=Dt[(S+1)*x+C+1],K=Dt[(S+1)*x+C],dt=oo(D,$,q,K,.9);if(!dt.length)continue;let ft=C*16,Q=S*16;for(let rt of dt)e.moveTo(ft+rt.x1*16,Q+rt.y1*16),e.lineTo(ft+rt.x2*16,Q+rt.y2*16)}e.stroke(),e.globalCompositeOperation="source-over"}if(O.render==="voronoi"){let f=Math.ceil(L/18)+1,x=Math.ceil(R/18)+1;(!me||me.length!==f*x)&&(me=new Int32Array(f*x));let F=d.particles,k=new Map;for(let C=0;C<F.length;C++)k.set(F[C],C);for(let C=0;C<x;C++)for(let D=0;D<f;D++){let $=D*18,q=C*18,K=d.near($,q,54),dt=-1;if(K.length){let ft=ss($,q,K);ft>=0&&(dt=k.get(K[ft])??-1)}me[C*f+D]=dt}let S=lt;e.globalCompositeOperation="lighter",e.strokeStyle=`rgba(${S[0]},${S[1]},${S[2]},${.32*it})`,e.lineWidth=1,e.beginPath();for(let C of gs(me,f,x))e.moveTo(C.x1*18,C.y1*18),e.lineTo(C.x2*18,C.y2*18);e.stroke(),e.globalCompositeOperation="source-over"}if(O.render==="knockout"){let h=lt;e.fillStyle=`rgba(${h[0]},${h[1]},${h[2]},${.22*it})`,e.fillRect(0,0,L,R),e.globalCompositeOperation="destination-out";for(let u of d.particles){if(u.cap)continue;let f=O.depth>0?1-Math.min(Math.abs(u.z??0)/O.depth,1)*.55:1,x=is(u.size,u.heat,f);e.fillStyle=`rgba(0,0,0,${.38*it})`,e.beginPath(),e.arc(u.x,u.y,x+2.2,0,6.28318),e.fill(),e.fillStyle=`rgba(0,0,0,${it})`,e.beginPath(),e.arc(u.x,u.y,x,0,6.28318),e.fill()}e.globalCompositeOperation="source-over"}if(O.render==="redshift"){e.globalCompositeOperation="lighter";let h=L*O.redshiftObserverX,u=R*O.redshiftObserverY;for(let f of d.particles){if(f.cap)continue;let x=0;for(let $ of B){let q=$.range||200,K=f.x-$.cx,dt=f.y-$.cy,ft=ls(K*K+dt*dt,q*q);ft>x&&(x=ft)}let F=fs(cs(as(f.x,f.y,f.vx,f.vy,h,u),W.c),x);ds(gt,F);let k=O.depth>0?1-Math.min(Math.abs(f.z??0)/O.depth,1)*.55:1,S=F<0?-F:F,C=(f.size+S*1.6)*k,D=mt((.4+.45*S)*it*k,0,1);e.fillStyle=`rgba(${gt[0]|0},${gt[1]|0},${gt[2]|0},${D})`,e.beginPath(),e.arc(f.x,f.y,C,0,6.28318),e.fill()}e.globalCompositeOperation="source-over"}if(O.render==="blackbody"){e.globalCompositeOperation="lighter";for(let h of d.particles){if(h.cap)continue;let u=us(h.vx,h.vy,h.heat,W.c);hs(gt,u);let f=O.depth>0?1-Math.min(Math.abs(h.z??0)/O.depth,1)*.55:1,x=(h.size+u*2.2)*f,F=mt((.16+.84*u)*it*f,0,1),k=gt[0]|0,S=gt[1]|0,C=gt[2]|0;e.fillStyle=`rgba(${k},${S},${C},${.14*F})`,e.beginPath(),e.arc(h.x,h.y,x+1.4+u*2,0,6.28318),e.fill(),e.fillStyle=`rgba(${k},${S},${C},${F})`,e.beginPath(),e.arc(h.x,h.y,x,0,6.28318),e.fill()}e.globalCompositeOperation="source-over"}if(O.render==="depth"){let h=d.particles,u=h.length;(!oe||oe.length!==u)&&(oe=new Array(u));for(let k=0;k<u;k++)oe[k]=k;oe.sort((k,S)=>Math.abs(h[S].z??0)-Math.abs(h[k].z??0));let f=O.depthFocal,x=L/2,F=R/2;for(let k=0;k<u;k++){let S=h[oe[k]];if(S.cap)continue;let C=S.z??0,D=O.depth>0?Math.min(Math.abs(C)/O.depth,1):0,$=ys(C,f),q=so(S.x,x,$),K=so(S.y,F,$),dt=Math.min(1,Math.hypot(q-c,K-v)/p),ft=dt*dt,Q=S.heat;Hn(gt,ft,Q,a,O.gradientCool,O.gradientWarm);let rt=(S.size*(1-.4*ft)+Q*2)*$,Mt=mt((.5-.3*ft+Q*.5)*it*ms(D),0,1),kt=gt[0]|0,Ut=gt[1]|0,N=gt[2]|0;e.fillStyle=`rgba(${kt},${Ut},${N},${.12*Mt})`,e.beginPath(),e.arc(q,K,rt+1.2+ps(D),0,6.28318),e.fill(),e.fillStyle=`rgba(${kt},${Ut},${N},${Mt})`,e.beginPath(),e.arc(q,K,rt,0,6.28318),e.fill()}}if(O.render==="streamlines"||O.render==="flow"){let u=lt;if(e.lineWidth=1,e.lineCap="round",Ce===null||yt||Tt%3===0){let f=[],x=[],F=0;for(let k=46/2;k<L;k+=46)for(let S=46/2;S<R;S+=46){let{fx:C,fy:D}=Gt(B,m.forces,W,k,S);if(yt){let q=we(sn,k,S,yt,.04);C+=q.x,D+=q.y}let $=Math.hypot(C,D);if(!($>1e-9)){x.push({gx:k,gy:S});continue}f.push({gx:k,gy:S,ux:C/$,uy:D/$,mag:$}),$>F&&(F=$)}Ht===0?Ht=F:Ht=F>Ht?Ht*.7+F*.3:Ht*.9+F*.1,Ce=f,vn=x}if(vn.length){e.fillStyle=`rgba(${u[0]},${u[1]},${u[2]},0.05)`;for(let f of vn)e.fillRect(f.gx-.5,f.gy-.5,1,1)}if(Ht>0&&Ce)for(let f of Ce){let x=Math.sqrt(f.mag/Ht),F=46*.46*(.28+.72*x),k=f.gx+f.ux*F,S=f.gy+f.uy*F;e.strokeStyle=`rgba(${u[0]},${u[1]},${u[2]},${mt(.1+x*.5,0,.72)})`,e.beginPath(),e.moveTo(f.gx,f.gy),e.lineTo(k,S);let C=3.4;e.moveTo(k,S),e.lineTo(k-f.ux*C-f.uy*C*.6,S-f.uy*C+f.ux*C*.6),e.moveTo(k,S),e.lineTo(k-f.ux*C+f.uy*C*.6,S-f.uy*C-f.ux*C*.6),e.stroke()}}}function Le(o){return(o===void 0?[]:Array.isArray(o)?o:[o]).filter(c=>c!=="off")}function No(o,a,c){let p=lt;if(bn===null||yt||Tt%3===0){let u=[],f=0;for(let x=44/2;x<L;x+=44)for(let F=44/2;F<R;F+=44){let{fx:k,fy:S}=Gt(B,m.forces,W,x,F);if(yt){let D=we(sn,x,F,yt,.04);k+=D.x,S+=D.y}let C=Math.hypot(k,S);C>1e-9&&(u.push({gx:x,gy:F,ux:k/C,uy:S/C,mag:C}),C>f&&(f=C))}_t===0?_t=f:_t=f>_t?_t*.7+f*.3:_t*.9+f*.1,bn=u}if(_t<=0)return;let b={r:p[0],g:p[1],b:p[2],alpha:0,width:1.2},h=new Float64Array(12);for(let u of bn){let f=c?mt(u.mag/_t,0,1):Math.sqrt(u.mag/_t),x=44*.5*(.25+.75*f),F=u.gx+u.ux*x,k=u.gy+u.uy*x,S=3.6;h[0]=u.gx,h[1]=u.gy,h[2]=F,h[3]=k,h[4]=F,h[5]=k,h[6]=F-u.ux*S-u.uy*S*.6,h[7]=k-u.uy*S+u.ux*S*.6,h[8]=F,h[9]=k,h[10]=F-u.ux*S+u.uy*S*.6,h[11]=k-u.uy*S-u.ux*S*.6,b.alpha=mt(.12+f*.55,0,.8),o.segments(h,b)}}function Mi(o){let a=Cr(B);if(!a.length)return;let c=zr((b,h)=>Ke(B,m.forces,b,h),a,{step:6,maxSteps:200,bounds:{w:L,h:R},loopDist:8}),v=lt,p={r:v[0],g:v[1],b:v[2],alpha:.42,width:1.1};for(let b of c){if(b.length<2)continue;let h=new Float32Array(b.length*2);for(let u=0;u<b.length;u++)h[u*2]=b[u].x,h[u*2+1]=b[u].y;o.polyline(h,p)}}function ki(o){let c=22*O.gridWarp,v=48*.46,p=Math.floor(L/48)+2,b=Math.floor(R/48)+2,h=new Float32Array(p*b),u=new Float32Array(p*b),f=0,x=new Float32Array(p*b);for(let N=0;N<b;N++)for(let U=0;U<p;U++){let{fx:st,fy:V}=Gt(B,m.forces,W,U*48,N*48),at=Math.hypot(st,V),St=N*p+U;at>1e-9&&(h[St]=st/at,u[St]=V/at,x[St]=at,at>f&&(f=at))}let F=[lt,[120,110,255],[240,70,255],[255,50,130]],k=8,S=N=>f>0?Math.sqrt(x[N]/f):0,C=N=>Math.round(S(N)*k),D=N=>{let U=N/k,st=jn(F,U);return{r:st[0],g:st[1],b:st[2],alpha:Math.min(1,O.gridIntensity*(.3+.85*U)),width:U>.55?1.4:1}},$=new Float32Array(p*b),q=new Float32Array(p*b);for(let N=0;N<p*b;N++){let U=S(N);$[N]=h[N]*U*c,q[N]=u[N]*U*c}let K=new Float32Array(p*b),dt=new Float32Array(p*b);for(let N=0;N<b;N++)for(let U=0;U<p;U++){let st=0,V=0,at=0;for(let Rt=-1;Rt<=1;Rt++)for(let Pt=-1;Pt<=1;Pt++){let Ct=U+Pt,$t=N+Rt;if(Ct<0||$t<0||Ct>=p||$t>=b)continue;let fe=$t*p+Ct;st+=$[fe],V+=q[fe],at++}let St=N*p+U;K[St]=st/at,dt[St]=V/at}let ft=48*1.5,Q=(N,U)=>{let st=U*p+N,V=K[st],at=dt[st],St=Math.hypot(V,at);St>v&&(V=V/St*v,at=at/St*v);let Rt=N*48,Pt=U*48,Ct=Math.min(Rt,L-Rt,Pt,R-Pt),$t=Ct<=0?0:Ct<ft?Ct/ft:1;return[Rt+V*$t,Pt+at*$t]},rt=4,Mt=N=>{let U=N.length>>1;if(U<3)return N;let st=[N[0],N[1]];for(let V=0;V<U-1;V++){let at=(V>0?V-1:0)<<1,St=V<<1,Rt=V+1<<1,Pt=(V+2<U?V+2:U-1)<<1,Ct=N[at],$t=N[at+1],fe=N[St],Cn=N[St+1],On=N[Rt],Rn=N[Rt+1],Ho=N[Pt],qo=N[Pt+1];for(let Pn=1;Pn<=rt;Pn++){let pe=Pn/rt,$n=pe*pe,jo=$n*pe;st.push(.5*(2*fe+(-Ct+On)*pe+(2*Ct-5*fe+4*On-Ho)*$n+(-Ct+3*fe-3*On+Ho)*jo),.5*(2*Cn+(-$t+Rn)*pe+(2*$t-5*Cn+4*Rn-qo)*$n+(-$t+3*Cn-3*Rn+qo)*jo))}}return st},kt=(N,U)=>Math.max(C(N*p+U),C(N*p+U+1)),Ut=(N,U)=>Math.max(C(U*p+N),C((U+1)*p+N));for(let N=0;N<b;N++){let U=kt(N,0),st=[...Q(0,N),...Q(1,N)];for(let V=1;V<p-1;V++){let at=kt(N,V);at===U?st.push(...Q(V+1,N)):(o.polyline(Mt(st),D(U)),st=[...Q(V,N),...Q(V+1,N)],U=at)}o.polyline(Mt(st),D(U))}for(let N=0;N<p;N++){let U=Ut(N,0),st=[...Q(N,0),...Q(N,1)];for(let V=1;V<b-1;V++){let at=Ut(N,V);at===U?st.push(...Q(N,V+1)):(o.polyline(Mt(st),D(U)),st=[...Q(N,V),...Q(N,V+1)],U=at)}o.polyline(Mt(st),D(U))}}let zt=null;function Do(o,a,c){let b=Math.ceil(L/24)+1,h=Math.ceil(R/24)+1;!zt||zt.length!==b*h?zt=new Float32Array(b*h):zt.fill(0);let u=!1;for(let S of d.particles){if(S.cap)continue;let C=a(S);C<=0||(u=!0,ro(zt,b,h,24,S.x,S.y,42,C))}if(!u)return;let f=0;for(let S=0;S<zt.length;S++)zt[S]>f&&(f=zt[S]);if(f<=0)return;let x=lt,F=[.25,.5,.78],k=[];for(let S=0;S<F.length;S++){let C=F[S]*f;k.length=0;for(let D=0;D<h-1;D++)for(let $=0;$<b-1;$++){let q=zt[D*b+$],K=zt[D*b+$+1],dt=zt[(D+1)*b+$+1],ft=zt[(D+1)*b+$],Q=oo(q,K,dt,ft,C);if(!Q.length)continue;let rt=$*24,Mt=D*24;for(let kt of Q)k.push(rt+kt.x1*24,Mt+kt.y1*24,rt+kt.x2*24,Mt+kt.y2*24)}k.length&&o.segments(k,{r:x[0],g:x[1],b:x[2],alpha:c*(.45+.55*(S/(F.length-1))),width:1+S*.3})}}function Si(o){let p=lt,b={r:p[0],g:p[1],b:p[2],alpha:0,width:1.1},h=new Float64Array(4);for(let u=104/2;u<L;u+=104)for(let f=104/2;f<R;f+=104){let x=u,F=f;for(let k=0;k<24;k++){let{fx:S,fy:C}=Gt(B,m.forces,W,x,F);if(yt){let K=we(sn,x,F,yt,.04);S+=K.x,C+=K.y}let D=Math.hypot(S,C);if(!(D>1e-9))break;let $=x+S/D*9,q=F+C/D*9;if($<0||q<0||$>L||q>R)break;h[0]=x,h[1]=F,h[2]=$,h[3]=q,b.alpha=.34*(1-k/24),o.segments(h,b),x=$,F=q}}}function Ei(o){let a=lt;for(let c of B){if(!c.vis||!c.feedback)continue;let v=`d ${c.d.toFixed(2)}`,p=c.cx+c.hw+8,b=c.cy;o.rect(p-3,b-7,o.measureText(v)+6,14,a[0],a[1],a[2],mt(.3+c.d*.55,0,.85)),o.text(v,p,b+.5,5,6,11,.92)}}function Fi(o,a){if(o.clear(),!(!a.length||L===0||R===0))for(let c of a){c==="streamlines"?No(o,!1,!1):c==="force-vectors"?No(o,!1,!0):c==="field-lines"?Mi(o):c==="grid"?ki(o):c==="temperature"?Do(o,p=>p.heat,.5):c==="energy"?Do(o,p=>.5*p.m*(p.vx*p.vx+p.vy*p.vy),.42):c==="path"?Si(o):c==="data"&&Ei(o);let v=H.get(c);v&&v(o,W,L,R)}}function An(o){Tt++,W.t=(o-Co)/1e3,W.frameN=Tt;let a=Number.isFinite(xn)?(o-xn)/16.6667:1;xn=o;let c=wt();if(W.dt=c<=0?0:mt(a,.2,2)*c,it<1&&(it=Math.min(1,it+.012)),nr(W.form,xo,.03),ee){let f=A.viewport();Z=f.originX??0,ot=f.originY??0}let v=A.scrollY?.()??0,p=v-ye;if(W.scrollV=(W.scrollV??0)*.7+Math.abs(p)*.3,ye=v,p!==0&&!ee)for(let f of B)f.cy-=p;for(let f of vt){let x=v*(.025+f.depth*.08);f.offsetY+=(x-f.offsetY)*.04}if(B.length&&Tt%6===0&&(tn(B,L,R,Z,ot),y(B),Es(B,W.supernova)),W.dt!==0&&Gs(),tt.length&&W.dt){let f=W.dt/60;for(let x of tt)Ms(x.agent,x.from.d>.08,0,f)}let b=null;for(let f of B)if(f.on&&f.vis){b=f;break}let h=yt??b;if(xt.k+=((h?1:0)-xt.k)*.07,h){let f=yt?yt.x:b.cx,x=yt?yt.y:b.cy;xt.x=xt.x?xt.x+(f-xt.x)*.16:f,xt.y=xt.y?xt.y+(x-xt.y)*.16:x}Tt%30===0&&(he=(A.scrollHeight?.()??R)-R||1);let u=Re?pt(Re):jn(To,v/he);if(lt=[lt[0]+(u[0]-lt[0])*.08,lt[1]+(u[1]-lt[1])*.08,lt[2]+(u[2]-lt[2])*.08],O.accent=qn(lt),d.reindex(),pi(),Ws(),W.dt&&Wr(B,d.particles),yt&&W.dt)for(let f of d.particles){if(f.cap)continue;let x=we(sn,f.x,f.y,yt,.6);f.vx+=x.x,f.vy+=x.y}if(O.waveStyle==="circular")if(O.waveCenter)Zt=typeof O.waveCenter=="function"?O.waveCenter():O.waveCenter;else{let f=B.find(x=>x.tokens.includes("star")||x.tokens.includes("vortex"));f?Zt={x:f.cx,y:f.cy}:Zt={x:L/2,y:R/2}}else Zt=null;if(ei(),hr({store:d,bodies:B,env:W,forces:m.forces,conditions:m.conditions,waves:vt,waveStyle:O.waveStyle,waveCenter:Zt,separation:O.separation}),Lt&&(Lt.x=zo,Lt.y=Ao,Lt.vx=0,Lt.vy=0,Lt.heat=Math.min(1,Lt.heat+.2)),W.dt){for(let f of w.values())f.step();ct&&ct.update(d.particles),Lr(d,Wt,Fo,vt,L,R,W.t,ht),Br(Wt,vt,B,m.forces,L,R,W.t,f=>void d.add(ae(f))),fi(),ni()}if(xi(),js(),gi(),oi(),ri(),si(),ci(o),_(),e&&O.render!=="none"&&go&&(c>0||Tt%4===0)&&(wi(),i)){let f=Le(O.overlay);f.length&&Fi(i,f)}Kt=A.raf(An)}function Tn(o){let a=ve[o];a&&(xo=o==="ambient"?{...yn}:{...a.preset},mn=o)}let Be="",_o=Co;function Lo(){let o=A.viewport().height*.5,a="";A.root.querySelectorAll("[data-formation]").forEach(c=>{let v=c.getBoundingClientRect();v.top<=o&&v.bottom>=o&&(a=c.dataset.formation??"")}),a&&a!==Be&&(Be=a,Tn(a))}let Bo=()=>void(_o=gn()),zi=()=>{Bo(),Lo()},Wo=setInterval(()=>{gn()-_o>6e3&&Be!=="ambient"&&(Be="ambient",Tn("ambient"))},1200);Wo.unref?.();let Ai=()=>$o();$o(),Le(O.overlay).length&&l();let Ti=()=>{A.hidden?.()??!1?(A.cancelRaf(Kt),Kt=0):Kt||(Kt=A.raf(An))};A.onResize&&j.push(A.onResize(Ai)),A.onScroll&&j.push(A.onScroll(zi)),A.onVisibility&&j.push(A.onVisibility(Ti)),A.onInput&&j.push(A.onInput(Bo)),A.onBodyEvent&&(j.push(A.onBodyEvent(Zr,Js)),j.push(A.onBodyEvent(ts,Qs)),j.push(A.onBodyEvent(es,Zs))),Lo(),Kt=A.raf(An);let te={projections:Us,scan:Ie,rescan:Ie,setAccent:o=>{O.accent=o,lt=pt(o)},setPalette:o=>{let a=Ue(o);To=a.map(pt);let c=a[0];c&&(O.accent=c,lt=pt(c))},setFormation:Tn,setWaveStyle:o=>{O.waveStyle=o},setWaveCenter:o=>{O.waveCenter=o},setSeparation:o=>{O.separation=o>=0?o:0},setAttention:o=>{if(O.attention=o,!o)for(let a of B)a.attn=1},setCausality:o=>{if(O.causality=o,!o)for(let a of B)a.el.style.removeProperty("--lit"),a.el.dataset.fxLit="0"},setRender:o=>{if(o!=="none"&&!e){if(e=n.getContext("2d"),!e){console.warn(`Fundamental: setRender('${o}') could not acquire a 2d context; staying in render 'none'`);return}Le(O.overlay).length&&l(),De(A.viewport().dpr)}O.render=o},setOverlay:o=>{O.overlay=o,Le(o).length?l():i?.clear()},setHeatmap:o=>{if(O.heatmap=o,o)!ct&&L>0&&(ct=new Se(L,R));else if(ct){ct.clear(),ct=null;for(let a of B)(a.writeTarget??a.el).style.removeProperty("--field-heatmap-density")}},setDprCap:o=>{O.dprCap=o>0?o:2,e&&De(A.viewport().dpr)},setQualityTier:o=>{let a=Math.max(0,Math.min(3,Math.floor(o||0)));a!==Ne&&(Ne=a,e&&De(A.viewport().dpr))},get policy(){return yo(nt)},setPolicy:o=>{nt=yo(o)},forAgent:o=>{let a=new Set(o.capabilities??[]),c=(o.redactions??[]).slice(),v=f=>a.has(f),p=()=>{let f=nt.budgets?.agentRead;return f==null||f>0},u={get capabilities(){return Object.freeze([...a])},get redactions(){return Object.freeze([...c])},query:(f={})=>{if(!p()){let C=te.query({...f,include:["bodies"]});return C.metrics={},C.relationships=[],C.influences=[],v("read:projections")||(C.projections=[]),an(C,c)}let x=new Set(["bodies"]);v("read:metrics")&&x.add("metrics"),v("read:relationships")&&x.add("relationships"),v("read:influences")&&x.add("influences");let F=f.include?new Set(f.include):null,k=[...x].filter(C=>!F||F.has(C)),S=te.query({...f,include:k});return v("read:metrics")||(S.metrics={}),v("read:relationships")||(S.relationships=[]),v("read:influences")||(S.influences=[]),v("read:projections")||(S.projections=[]),an(S,c)},snapshot:(f={})=>{if(!p()){let k=te.snapshot({profile:"public"});return an(k,c)}let x={...f};v("read:body-data")||(x.includeData=!1),v("read:relationships")||(x.includeRelationships=!1),v("read:influences")||(x.includeInfluences=!1);let F=te.snapshot(x);return v("read:projections")||(F.projections=[]),an(F,c)}};return v("read:replay")&&(u.replay=(f,x,F)=>te.replay(f,x,F)),v("read:focus")&&(u.focusState=f=>{let x=te.focusState(f);return p()?x:{frame:x.frame,time:x.time,entries:[]}}),Object.freeze(u)},threads:zn,burst:(o,a,c)=>{let v=Rr;for(let p of d.particles){let b=Pr(p.x-o,p.y-a,v,6,p.z??0);b.heat!==0&&(p.vx+=b.vx,p.vy+=b.vy,b.vz&&(p.vz=(p.vz??0)+b.vz),p.heat=Math.max(p.heat,b.heat),c&&(p.color=c))}Qn(Wt,vt,o,a,v,L,R,W.t,p=>void d.add(ae(p))),Oo(o,a,2,c)},flowTo:(o,a,c)=>{yt=Er(o,a,c)},clearFlow:()=>{yt=null},seed:o=>{$e=o,Ro()},atomAt:(o,a)=>{let c=null,v=1/0;for(let p of d.near(o,a,24)){if(p.atom==null)continue;let b=(p.x-o)**2+(p.y-a)**2+(p.z??0)**2;b<v&&(v=b,c=p.atom)}return c},focusAt:(o,a)=>{let c=null,v=1/0;for(let p of d.near(o,a,24)){if(p.atom==null)continue;let b=(p.x-o)**2+(p.y-a)**2+(p.z??0)**2;b<v&&(v=b,c=p)}return Lt=c,c?(zo=c.x,Ao=c.y,c.atom??null):null},clearFocus:()=>{Lt=null},particleCount:()=>d.size,readParticles:o=>{let a=d.particles,c=Math.floor(o.length/5),v=0;for(let p=0;p<a.length&&v<c;p++){let b=a[p];if(b.report!==void 0)continue;let h=v*5;o[h]=b.x,o[h+1]=b.y,o[h+2]=b.z??0,o[h+3]=b.heat,o[h+4]=b.size,v++}return v},readParticleIds:o=>{let a=d.particles,c=0;for(let v=0;v<a.length&&c<o.length;v++){let p=a[v];p.report===void 0&&(o[c++]=p.id??0)}return c},readParticleChannels:(o,a)=>{let c=d.particles,v=0;for(let p=0;p<c.length;p++){let b=c[p];if(!("report"in b&&b.report!==void 0)){if(v>=Math.min(...a.map(h=>h.length)))break;for(let h=0;h<o.length&&!(h>=a.length);h++){let u=o[h];a[h][v]=u==="x"?b.x:u==="y"?b.y:u==="z"?b.z??0:u==="vx"?b.vx:u==="vy"?b.vy:u==="heat"?b.heat:u==="size"?b.size:u==="m"?b.m:u==="id"?b.id??0:u==="age"?b.age??0:u==="charge"?b.charge??0:0}v++}}return v},registerOverlay:(o,a)=>(H.set(o,a),()=>{H.delete(o)}),addAgent:o=>{let a=ae({x:o.x,y:o.y,z:o.z,species:o.species});return a.vx=0,a.vy=0,o.z===void 0&&O.depth<=0&&(a.z=0),o.mass!==void 0&&(a.m=o.mass),a.maxSpeed=o.maxSpeed,a.report=o.report,d.add(a),{particle:a,remove:()=>d.remove(a)}},addBody:o=>{let a={"data-body":Array.isArray(o.tokens)?o.tokens.join(" "):String(o.tokens)};o.strength!=null&&(a["data-strength"]=String(o.strength)),o.range!=null&&(a["data-range"]=String(o.range)),o.spin!=null&&(a["data-spin"]=String(o.spin)),o.angle!=null&&(a["data-angle"]=String(o.angle)),o.color!=null&&(a["data-color"]=o.color);let c=()=>{let u=o.rect();return{left:u.left,top:u.top,right:u.left+u.width,bottom:u.top+u.height,width:u.width,height:u.height,x:u.left,y:u.top,toJSON:()=>({})}},v={tagName:"DIV",id:"",className:"",dataset:o.color!=null?{color:o.color}:{},getAttribute:u=>a[u]??null,hasAttribute:u=>u in a,getBoundingClientRect:c,dispatchEvent:()=>!0,setAttribute:()=>{},removeAttribute:()=>{},style:{setProperty:()=>{},removeProperty:()=>{},getPropertyValue:()=>""}},p=ke(v);p.rect=c,p.data=o.data,o.identity!=null&&(p.identity=typeof o.identity=="string"?{id:o.identity}:o.identity),o.authority&&(p.authority=o.authority),p.feedback=!0;let b={};p.onFeedback=u=>{Object.assign(b,u),o.onFeedback?.(u)},X.push(p),B=B.concat(p),tn([p],L,R,Z,ot);let h={data:o.data,get channels(){return b},set:u=>{u.strength!=null&&(a["data-strength"]=String(u.strength)),u.range!=null&&(a["data-range"]=String(u.range)),u.spin!=null&&(a["data-spin"]=String(u.spin)),u.angle!=null&&(a["data-angle"]=String(u.angle)),u.color!=null&&(a["data-color"]=u.color,v.dataset.color=u.color,p.tint=u.color)},remove:()=>{let u=X.indexOf(p);u>=0&&X.splice(u,1),B=B.filter(f=>f!==p);for(let f=tt.length-1;f>=0;f--){let x=tt[f];(x.from===p||x.to===p)&&tt.splice(f,1)}}};return bt.set(h,p),h},addEdge:(o,a,c)=>{let v=bt.get(o),p=bt.get(a);if(!v||!p)throw new Error("addEdge: both arguments must be handles returned by addBody on this field.");let b={id:`e${Fe++}`,from:"",to:"",type:c?.type??"related",strength:c?.strength??.5,tension:0,memory:0,active:!1},h={agent:b,from:v,to:p,fromData:o.data,toData:a.data};return tt.push(h),{set:u=>{u.strength!=null&&(b.strength=u.strength<0?0:u.strength>1?1:u.strength),u.type!=null&&(b.type=u.type)},remove:()=>{let u=tt.indexOf(h);u>=0&&tt.splice(u,1)}}},readEdges:()=>tt.map(o=>({from:o.fromData,to:o.toData,type:o.agent.type,strength:o.agent.strength,memory:o.agent.memory,active:o.agent.active})),query:(o={})=>{let a=o.at,c,v=0,p=0,b=0,h=!1;a&&("width"in a?(c={x:a.x,y:a.y,width:a.width,height:a.height},v=a.x+a.width/2,p=a.y+a.height/2,b=Math.max(a.width,a.height)/2):(b=o.radius??240,v=a.x,p=a.y,c={x:v-b,y:p-b,width:b*2,height:b*2}),h=!0);let u=new Set(o.include??(h?["bodies","metrics","relationships","influences"]:["bodies","metrics","relationships"])),f=$=>{if(!$.vis)return!1;if(!h)return!0;if("width"in a){let q=c;return $.cx>=q.x&&$.cx<=q.x+q.width&&$.cy>=q.y&&$.cy<=q.y+q.height}return Math.hypot($.cx-v,$.cy-p)<=b},x=B.filter(f),F=u.has("bodies")?x.map($=>{let{metrics:q,dimensions:K}=wo($),dt=pn($);return{id:dt.id,identity:dt,rect:{x:$.cx-$.hw,y:$.cy-$.hh,width:$.hw*2,height:$.hh*2},tokens:$.tokens.slice(),metrics:q,dimensions:K,activeFormations:[mn],authority:$.authority??"anchored"}}):[],k={};if(u.has("metrics")&&(k.particles=d.size,k.bodies=x.length,x.length>0)){let $=0;for(let q of x)$+=q.d;k.meanDensity=$/x.length}let S=u.has("relationships")?tt.filter($=>!h||f($.from)||f($.to)).map($=>({from:Jt($.from),to:Jt($.to),type:$.agent.type,strength:$.agent.strength,memory:$.agent.memory,active:$.agent.active,causal:$.agent.active})):[],C=[];if(u.has("influences")&&h)for(let $ of x){if($.tokens.length===0)continue;let q=ho(m.forces,$.tokens,$,v,p);for(let K of q.attribution)C.push({source:Jt($),force:K.force,channel:K.channel,contribution:K.contribution})}let D={query:o,frame:W.frameN,time:W.t,region:c,bodies:F,metrics:k,relationships:S,influences:C,projections:Ae()};return o.lens?Sr(D,o.lens):D},snapshot:(o={})=>{let a=vc(o),c=a.includeRelationships,v=B.filter(f=>f.vis),p=v.map(f=>{let{metrics:x,dimensions:F}=wo(f),k=pn(f),S={id:k.id,identity:k,authority:f.authority??"anchored",rect:{x:f.cx-f.hw,y:f.cy-f.hh,width:f.hw*2,height:f.hh*2},position:{x:f.cx,y:f.cy,z:0},tokens:f.tokens.slice(),metrics:x,dimensions:F};return a.includeData&&Xt()&&(S.data=Vs(f.data)),S}),b=c?tt.map(f=>({from:Jt(f.from),to:Jt(f.to),type:f.agent.type,strength:f.agent.strength,memory:f.agent.memory,active:f.agent.active,causal:f.agent.active})):[],h={particles:d.size,bodies:v.length};if(v.length>0){let f=0;for(let x of v)f+=x.d;h.meanDensity=f/v.length}let u={id:`snap-${W.frameN}-${Hs++}`,createdAt:W.t,frame:W.frameN,version:ge,formations:[mn],bodies:p,relationships:b,metrics:h,projections:Ae()};if(a.includeParticles){let f=[];for(let x of d.particles)x.cap||f.push({x:x.x,y:x.y,z:x.z??0,heat:x.heat,size:x.size});u.particles=f}if(a.includeInfluences){let f=[];for(let x of v){if(x.tokens.length===0)continue;let F=ho(m.forces,x.tokens,x,x.cx+8,x.cy);for(let k of F.attribution)f.push({source:Jt(x),force:k.force,channel:k.channel,contribution:k.contribution})}u.influences=f}return u},diff:(o,a)=>Un(o,a),replay:(o,a,c)=>er(o,a,c),addField:(o,a)=>(It.set(o,a),{name:o,set:c=>{It.set(o,c)},remove:()=>{It.delete(o)}}),sampleField:(o,a,c)=>{let v=It.get(o);return v?v(a,c):0},energy:()=>As(d.particles),sample:(o,a)=>{let{fx:c,fy:v}=Gt(B,m.forces,W,o,a);return{x:c,y:v}},sampleScalar:(o,a)=>ct?ct.norm(o,a):(eo("NOOP_NO_HEATMAP","sampleScalar() returned 0 because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),0),sampleGradient:(o,a)=>ct?ct.gradient(o,a):(eo("NOOP_NO_HEATMAP","sampleGradient() returned { x: 0, y: 0 } because the heatmap layer is off \u2014 construct with { heatmap: true } or call setHeatmap(true)."),{x:0,y:0}),grid:o=>W.grid(o),focus:(o,a)=>Ls(o,a),focusState:o=>Bs(o),on:(o,a)=>{let c=M.get(o);return c||(c=new Set,M.set(o,c)),c.add(a),()=>void c.delete(a)},version:ge,scrollV:()=>W.scrollV??0,setVisible:o=>{go=o},setBackground:o=>{O.background=o,o==="transparent"&&e&&e.clearRect(0,0,L,R)},destroy:()=>{A.cancelRaf(Kt),clearInterval(Wo);for(let o of j)o();for(let o of ie)o.el.removeEventListener("pointerenter",o.enter),o.el.removeEventListener("pointerleave",o.leave),o.el.removeEventListener("focusin",o.enter),o.el.removeEventListener("focusout",o.leave),delete o.el.dataset.fxEngaged;ie=[];for(let o of qt)(o.docked||o.dock.dock>0)&&(o.docked=null,o.dock.dock=0,o.el.style.opacity="",o.el.getAttribute("aria-hidden")==="true"&&o.el.removeAttribute("aria-hidden"),o.el.removeAttribute("inert"));for(let o of re)for(let a of o.emitted)a.remove();re=[],d.clear(),A.detach?.()}};return te}var ln={};function fn(){return ln.reducedMotion!==void 0?ln.reducedMotion:typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function dn(){return ln.hidden!==void 0?ln.hidden:typeof document<"u"&&document.hidden}var Ec=["--field-density","--d"],Cs=!1;function Os(){if(Cs)return[];Cs=!0;let n=globalThis.CSS;if(!n||typeof n.registerProperty!="function")return[];let t=[];for(let e of Ec)try{n.registerProperty({name:e,syntax:"<number>",inherits:!0,initialValue:"0"}),t.push(e)}catch{}return t}var Rs=["pointerdown","wheel","keydown","touchstart"];function ue(){return Os(),{root:document,viewport:()=>({width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio||1}),scrollY:()=>window.scrollY||0,scrollHeight:()=>document.documentElement.scrollHeight,reducedMotion:()=>fn(),hidden:()=>dn(),raf:n=>requestAnimationFrame(n),cancelRaf:n=>cancelAnimationFrame(n),createCanvas:()=>document.createElement("canvas"),onResize:n=>(window.addEventListener("resize",n,{passive:!0}),()=>window.removeEventListener("resize",n)),onScroll:n=>(window.addEventListener("scroll",n,{passive:!0}),()=>window.removeEventListener("scroll",n)),onVisibility:n=>(document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)),onInput:n=>{for(let t of Rs)window.addEventListener(t,n,{passive:!0});return()=>{for(let t of Rs)window.removeEventListener(t,n)}},onBodyEvent:(n,t)=>(document.addEventListener(n,t),()=>document.removeEventListener(n,t))}}var Ps=["pointerdown","wheel","keydown","touchstart"];function $s(n){return n.setAttribute(Ze,""),{root:n,detach:()=>n.removeAttribute(Ze),viewport:()=>{let t=n.getBoundingClientRect();return{width:t.width,height:t.height,dpr:window.devicePixelRatio||1,originX:t.left,originY:t.top}},scrollY:()=>n.scrollTop,scrollHeight:()=>n.scrollHeight,reducedMotion:()=>fn(),hidden:()=>dn(),raf:t=>requestAnimationFrame(t),cancelRaf:t=>cancelAnimationFrame(t),createCanvas:()=>document.createElement("canvas"),onResize:t=>{let e=new ResizeObserver(t);return e.observe(n),window.addEventListener("resize",t,{passive:!0}),()=>{e.disconnect(),window.removeEventListener("resize",t)}},onScroll:t=>(n.addEventListener("scroll",t,{passive:!0}),window.addEventListener("scroll",t,{passive:!0}),()=>{n.removeEventListener("scroll",t),window.removeEventListener("scroll",t)}),onVisibility:t=>(document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)),onInput:t=>{for(let e of Ps)n.addEventListener(e,t,{passive:!0});return()=>{for(let e of Ps)n.removeEventListener(e,t)}},onBodyEvent:(t,e)=>(n.addEventListener(t,e),()=>n.removeEventListener(t,e))}}function Is(n,t={}){return cn(n,{...t,host:ue()})}function un(n,t={}){let{host:e,bounds:r,...s}=t,i=e??(r?$s(r):ue());return cn(n,{...s,host:i})}function mo(){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 Ee(n=document.body){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText=vs,n.appendChild(t),t}function Ns(n){let t=document.createElement("canvas");return t.setAttribute("aria-hidden","true"),t.style.cssText="position:absolute;inset:0;width:100%;height:100%;pointer-events:none;",getComputedStyle(n).position==="static"&&(n.style.position="relative"),n.appendChild(t),t}function Ds(n={}){mo();let{target:t=document.body,...e}=n,r=Ee(t),s=Is(r,e);return{...s,destroy:()=>{s.destroy(),r.remove()}}}var hn=class{constructor(t={}){Y(this,"canvas");Y(this,"field");Y(this,"managed");mo();let{canvas:e,target:r,bounds:s,...i}=t;this.managed=!e,this.canvas=e??(s?Ns(s):Ee(r)),this.field=un(this.canvas,s?{...i,bounds:s}:i)}scan(){this.field.scan()}rescan(){this.field.rescan()}setAccent(t){this.field.setAccent(t)}setPalette(t){this.field.setPalette(t)}setFormation(t){this.field.setFormation(t)}setWaveStyle(t){this.field.setWaveStyle(t)}setWaveCenter(t){this.field.setWaveCenter(t)}setSeparation(t){this.field.setSeparation(t)}setAttention(t){this.field.setAttention(t)}setCausality(t){this.field.setCausality(t)}setHeatmap(t){this.field.setHeatmap(t)}setDprCap(t){this.field.setDprCap(t)}setQualityTier(t){this.field.setQualityTier(t)}get policy(){return this.field.policy}setPolicy(t){this.field.setPolicy(t)}forAgent(t){return this.field.forAgent(t)}setRender(t){this.field.setRender(t)}setOverlay(t){this.field.setOverlay(t)}threads(t){this.field.threads(t)}burst(t,e,r){this.field.burst(t,e,r)}flowTo(t,e,r){this.field.flowTo(t,e,r)}clearFlow(){this.field.clearFlow()}seed(t){this.field.seed(t)}addAgent(t){return this.field.addAgent(t)}addBody(t){return this.field.addBody(t)}addEdge(t,e,r){return this.field.addEdge(t,e,r)}readEdges(){return this.field.readEdges()}query(t){return this.field.query(t)}snapshot(t){return this.field.snapshot(t)}diff(t,e){return this.field.diff(t,e)}replay(t,e,r){return this.field.replay(t,e,r)}get projections(){return this.field.projections}addField(t,e){return this.field.addField(t,e)}sampleField(t,e,r){return this.field.sampleField(t,e,r)}atomAt(t,e){return this.field.atomAt(t,e)}focusAt(t,e){return this.field.focusAt(t,e)}clearFocus(){this.field.clearFocus()}particleCount(){return this.field.particleCount()}readParticles(t){return this.field.readParticles(t)}readParticleIds(t){return this.field.readParticleIds(t)}readParticleChannels(t,e){return this.field.readParticleChannels(t,e)}registerOverlay(t,e){return this.field.registerOverlay(t,e)}energy(){return this.field.energy()}sample(t,e){return this.field.sample(t,e)}sampleScalar(t,e){return this.field.sampleScalar(t,e)}sampleGradient(t,e){return this.field.sampleGradient(t,e)}grid(t){return this.field.grid(t)}focus(t,e){this.field.focus(t,e)}focusState(t){return this.field.focusState(t)}on(t,e){return this.field.on(t,e)}get version(){return this.field.version}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 Ni(Fc);})();
|