import"../chunks/Bzak7iHL.js";import{o as we,a as Ne}from"../chunks/CNjeV5xa.js";import{p as Me,s as A,c as le,aB as ve,d as y,e as p,t as L,g as e,f as Ee,u as de,r as v,a as Se,h as d,n as me}from"../chunks/CvjSAYrz.js";import{s as K,d as Ie,a as xe}from"../chunks/FzvEaXMa.js";import{i as ue}from"../chunks/ciN1mm2W.js";import{a as E,c as Fe,b as oe,f as X}from"../chunks/BsvCUYx-.js";import{s as o,r as ge}from"../chunks/CNfQDikv.js";import{b as Ge,a as Pe}from"../chunks/CVpUe0w3.js";import{a as he}from"../chunks/DNjM5a-l.js";import{e as ke}from"../chunks/CtkE7HV2.js";import{e as fe,i as ye}from"../chunks/DTnG8poT.js";import{p as W}from"../chunks/B_YDQCB6.js";import{N as Ce}from"../chunks/DzfRjky4.js";const Re=.93,Te=.05,be="#8B95A5",Le="#818cf8",Oe=140,pe=8,De=4,Ke=12;function je(s){return!Number.isFinite(s)||s<=0?0:s*Re}function Ue(s){return Number.isFinite(s)?s>=Te:!1}function Ae(s){return!Number.isFinite(s)||stypeof b=="string");M.length!==0&&u.push({source_id:N.source_id,target_ids:M})}return u.reverse()}var Qe=oe(''),We=oe(''),Xe=oe(' '),Je=oe(''),Ze=oe('');function $e(s,f){Me(f,!0);let u=W(f,"width",3,900),x=W(f,"height",3,560),N=W(f,"source",3,null),M=W(f,"neighbours",19,()=>[]),b=W(f,"liveBurstKey",3,0),S=W(f,"liveBurst",3,null);const F=22,J=14;let B=A(le([])),G=A(le([])),T=A(le([])),U=0,O=null,ne=null,Z=0;function $(n,t,c,_){U+=1;const i=U,l=b()>0&&e(B).length>0?40:0,m=c+(Math.random()-.5)*l,g=_+(Math.random()-.5)*l;d(T,[...e(T),{burstId:i,x:m,y:g,radius:F,opacity:.75},{burstId:i,x:m,y:g,radius:F,opacity:.5}],!0);const V={id:`${n.id}::${i}`,label:n.label,nodeType:"source",x:m,y:g,activation:1,isSource:!0,sourceBurstId:i},H=[],k=[],C=U*.37%(Math.PI*2),re=qe(m,g,t.length,C);t.forEach((D,ie)=>{const se=re[ie];se&&(H.push({id:`${D.id}::${i}`,label:D.label,nodeType:D.nodeType,x:se.x,y:se.y,activation:Ye(ie,t.length),isSource:!1,sourceBurstId:i}),k.push({burstId:i,sourceNodeId:V.id,targetNodeId:`${D.id}::${i}`,drawProgress:0,staggerDelay:ze(ie),framesElapsed:0}))}),d(B,[...e(B),V,...H],!0),d(G,[...e(G),...k],!0)}function q(){let n=[];for(const i of e(B)){const l=je(i.activation);Ue(l)&&n.push({...i,activation:l})}d(B,n,!0);const t=new Set(n.map(i=>i.id));let c=[];for(const i of e(G)){if(!t.has(i.sourceNodeId)||!t.has(i.targetNodeId))continue;const l=i.framesElapsed+1;let m=i.drawProgress;l>=i.staggerDelay&&(m=Math.min(1,m+1/15)),c.push({...i,framesElapsed:l,drawProgress:m})}d(G,c,!0);let _=[];for(const i of e(T)){const l=i.radius+6,m=i.opacity*.96;m<.02||l>Math.max(u(),x())||_.push({...i,radius:l,opacity:m})}d(T,_,!0),O=requestAnimationFrame(q)}function Y(){d(B,[],!0),d(G,[],!0),d(T,[],!0)}ve(()=>{if(!N())return;const n=N().id;n!==ne&&(ne=n,Y(),$(N(),M(),u()/2,x()/2))}),ve(()=>{if(!S()||b()===0||b()===Z)return;Z=b();const n=(Math.random()-.5)*120,t=(Math.random()-.5)*120;$(S().source,S().neighbours,u()/2+n,x()/2+t)}),we(()=>{O=requestAnimationFrame(q)}),Ne(()=>{O!==null&&cancelAnimationFrame(O)});function ce(n,t){return Ve(n,t)}function ee(n){const t=e(B).find(l=>l.id===n.sourceNodeId),c=e(B).find(l=>l.id===n.targetNodeId);if(!t||!c)return null;const _=t.x+(c.x-t.x)*n.drawProgress,i=t.y+(c.y-t.y)*n.drawProgress;return{x1:t.x,y1:t.y,x2:_,y2:i}}var P=Ze(),te=y(p(P));fe(te,17,()=>e(T),ye,(n,t)=>{var c=Qe();L(()=>{o(c,"cx",e(t).x),o(c,"cy",e(t).y),o(c,"r",e(t).radius),o(c,"opacity",e(t).opacity)}),E(n,c)});var j=y(te);fe(j,17,()=>e(G),ye,(n,t)=>{const c=de(()=>ee(e(t)));var _=Fe(),i=Ee(_);{var l=m=>{var g=We();L(()=>{o(g,"x1",e(c).x1),o(g,"y1",e(c).y1),o(g,"x2",e(c).x2),o(g,"y2",e(c).y2),o(g,"opacity",.35*e(t).drawProgress)}),E(m,g)};ue(i,m=>{e(c)&&m(l)})}E(n,_)});var z=y(j);fe(z,17,()=>e(B),n=>n.id,(n,t)=>{const c=de(()=>ce(e(t).nodeType,e(t).isSource)),_=de(()=>e(t).isSource?F*(.7+.3*e(t).activation):J*(.5+.8*e(t).activation));var i=Je(),l=p(i),m=y(l),g=y(m),V=y(g);{var H=k=>{var C=Xe(),re=p(C,!0);v(C),L(D=>{o(C,"x",e(t).x),o(C,"y",e(t).y+e(_)+18),o(C,"opacity",.9*e(t).activation),K(re,D)},[()=>e(t).label.length>40?e(t).label.slice(0,40)+"…":e(t).label]),E(k,C)};ue(V,k=>{e(t).isSource&&e(t).label&&k(H)})}v(i),L(k=>{o(i,"opacity",k),o(l,"cx",e(t).x),o(l,"cy",e(t).y),o(l,"r",e(_)*1.9),o(l,"fill",e(c)),o(l,"opacity",.18*e(t).activation),o(m,"cx",e(t).x),o(m,"cy",e(t).y),o(m,"r",e(_)),o(m,"fill",e(c)),o(g,"cx",e(t).x-e(_)*.3),o(g,"cy",e(t).y-e(_)*.3),o(g,"r",e(_)*.35),o(g,"opacity",.35*e(t).activation)},[()=>Math.min(1,e(t).activation*1.25)]),E(n,i)}),v(P),L(()=>{o(P,"width",u()),o(P,"height",x()),o(P,"viewBox",`0 0 ${u()??""} ${x()??""}`)}),E(s,P),Se()}var et=X('

Computing activation...

'),tt=X('

Activation failed

'),rt=X(`

No matching memory

Nothing in the graph matches . Try a broader query or switch on live mode to watch the engine fire its own bursts.

`),it=X(`

Waiting for activation

Seed a burst with the search bar above, or enable live mode to overlay bursts from the cognitive engine as they happen.

`),st=X('
Seed

'),at=X(`

Spreading Activation

Collins & Loftus 1975 — activation spreads from a seed memory to neighbours along semantic edges, decaying by 0.93 per animation frame until it drops below 0.05. Search seeds a focused burst; live mode overlays every spread event fired by the cognitive engine in real time.

Seed Memory
Live bursts fired:
`);function yt(s,f){Me(f,!0);let u=A(""),x=A(!1),N=A(!1),M=A(null),b=A(null),S=A(le([])),F=A(!0),J=A(0),B=A(null),G=A(0);const T=new Map;function U(r){T.set(r.id,r)}function O(r){return{id:r.id,label:ne(r.content,r.id),nodeType:r.nodeType}}function ne(r,a){if(r&&r.trim().length>0){const h=r.trim();return h.length>60?h.slice(0,60)+"…":h}return a.slice(0,8)}function Z(r){const a=T.get(r);return a?O(a):{id:r,label:r.slice(0,8),nodeType:"note"}}async function $(){const r=e(u).trim();if(!r){d(M,null);return}d(x,!0),d(N,!0),d(M,null),d(b,null),d(S,[],!0);try{const a=await he.search(r,1);if(!a.results||a.results.length===0)return;const h=a.results[0];U(h),d(b,O(h),!0);const w=await he.explore(h.id,"associations",void 0,15),I=(w==null?void 0:w.results)??(w==null?void 0:w.nodes)??(w==null?void 0:w.associations)??[],R=[];for(const Q of I){if(!Q||typeof Q!="object"||!("id"in Q))continue;const ae=Q;U(ae),R.push(O(ae))}d(S,R,!0)}catch(a){d(M,a instanceof Error?a.message:String(a),!0),d(b,null),d(S,[],!0)}finally{d(x,!1)}}let q=null,Y=null,ce=!1;we(()=>{q=ke.subscribe(r=>{if(!r||r.length===0)return;if(!ce){Y=r[0],ce=!0;return}if(!e(F)){Y=r[0];return}const a=He(r,Y);if(Y=r[0],a.length!==0)for(const h of a){const w=Z(h.source_id),I=h.target_ids.map(R=>Z(R));d(J,e(J)+1),d(B,{source:w,neighbours:I},!0),d(G,e(G)+1)}})}),Ne(()=>{q&&q()});var ee=at(),P=y(p(ee),2),te=y(p(P),2),j=p(te);ge(j);var z=y(j,2),n=p(z,!0);v(z),v(te),v(P);var t=y(P,2),c=p(t),_=p(c);ge(_),me(2),v(c);var i=y(c,2),l=y(p(i)),m=p(l,!0);v(l),v(i),v(t);var g=y(t,2),V=p(g);{var H=r=>{var a=et();E(r,a)},k=r=>{var a=tt(),h=p(a),w=y(p(h),4),I=p(w,!0);v(w),v(h),v(a),L(()=>K(I,e(M))),E(r,a)},C=r=>{var a=rt(),h=p(a),w=y(p(h),4),I=y(p(w)),R=p(I);v(I),me(),v(w),v(h),v(a),L(()=>K(R,`"${e(u)??""}"`)),E(r,a)},re=r=>{var a=it();E(r,a)},D=r=>{$e(r,{width:1040,height:560,get source(){return e(b)},get neighbours(){return e(S)},get liveBurstKey(){return e(J)},get liveBurst(){return e(B)}})};ue(V,r=>{e(x)?r(H):e(M)?r(k,1):!e(b)&&e(N)?r(C,2):e(b)?r(D,!1):r(re,3)})}v(g);var ie=y(g,2);{var se=r=>{var a=st(),h=y(p(a),2),w=p(h,!0);v(h);var I=y(h,2),R=p(I),Q=p(R,!0);v(R);var ae=y(R,2),Be=p(ae);v(ae),v(I),v(a),L(()=>{K(w,e(b).label),K(Q,e(b).nodeType),K(Be,`${e(S).length??""} neighbours`)}),E(r,a)};ue(ie,r=>{e(b)&&r(se)})}v(ee),L(()=>{z.disabled=e(x),K(n,e(x)?"Activating…":"Activate"),K(m,e(G))}),xe("keydown",j,r=>r.key==="Enter"&&$()),Ge(j,()=>e(u),r=>d(u,r)),xe("click",z,$),Pe(_,()=>e(F),r=>d(F,r)),E(s,ee),Se()}Ie(["keydown","click"]);export{yt as component};