1import{r as s,j as d}from"./index-_Sg_1KT6.js";import{u as _e}from"./useCanvas-DRXw8nFR.js";import{E as We}from"./ExperimentControls-DmwC3FZh.js";import{E as De}from"./ExperimentMetrics-D-l2z47K.js";import{E as Le}from"./ExperimentNav-CPfQyQAJ.js";const w=32,$=8,W=32,Ue=W*8,le=[8,12,16,20],Xe=(m,o=0,p=1)=>Math.min(p,Math.max(o,m)),qe=[{id:"digest",label:"view.digest()"},{id:"avalanche",label:"view.avalanche()"},{id:"mining",label:"view.mining()"}],J=(m,o)=>(m<<o|m>>>32-o)>>>0,ce=m=>{const o=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569];for(let e=0;e<m.length;e++){const c=m.charCodeAt(e),r=e&7,j=r+1&7,b=r+5&7;o[r]=Math.imul(o[r]^c^e*40503,2246822507)>>>0,o[j]=o[j]+J(o[r],e%17+5)>>>0,o[b]^=Math.imul(J(c+o[j],r%11+7),3266489909)>>>0}for(let e=0;e<10;e++)for(let c=0;c<o.length;c++){const r=o[c],j=o[c+1&7],b=o[c+3&7];o[c]=Math.imul((r^J(j,13)^J(b,23))>>>0,668265261)>>>0}const p=new Uint8Array(W);return o.forEach((e,c)=>{const r=c*4;p[r]=e>>>24&255,p[r+1]=e>>>16&255,p[r+2]=e>>>8&255,p[r+3]=e&255}),p},de=m=>Array.from(m).map(o=>o.toString(16).padStart(2,"0")).join(""),Ye=m=>{let o=m;return o-=o>>>1&85,o=(o&51)+(o>>>2&51),(o+(o>>>4)&15)*1>>>0},Je=(m,o)=>{let p=0;for(let e=0;e<W;e++)p+=Ye(m[e]^o[e]);return p},$e=m=>{let o=0;for(const p of m){if(p===0){o+=8;continue}for(let e=7;e>=0;e--){if((p&1<<e)!==0)return o;o++}}return o},K=(m,o)=>{const p=m[o>>3],e=7-(o&7);return p>>e&1},Ke=(m,o,p)=>{const c=(m||"signal").split(""),r=Math.min(c.length-1,Math.max(0,o)),b=32+(c[r].charCodeAt(0)^p)%95;return c[r]=String.fromCharCode(b===c[r].charCodeAt(0)?33:b),c.join("")},he=()=>({nonce:0,hashes:0,bestZeros:0,bestNonce:0,bestHex:""}),at=({category:m,experiment:o})=>{const{canvasRef:p,ctx:e,dimensions:c}=_e(),[r,j]=s.useState("digest"),[b,me]=s.useState("signal eats its own shadow"),[ue,je]=s.useState(0),[fe,Ne]=s.useState(1),[z,Re]=s.useState(12),[D,Q]=s.useState(!1),[V,Be]=s.useState(!1),[ee,Z]=s.useState("type a message; one changed bit will remake the checksum weather"),[T,te]=s.useState(he),pe=s.useRef(0),H=s.useRef(T),oe=s.useMemo(()=>Ke(b,ue,fe),[ue,fe,b]),be=`${b}|nonce:${T.nonce}`,ge=`${oe}|nonce:${T.nonce}`,y=s.useMemo(()=>ce(be),[be]),G=s.useMemo(()=>ce(ge),[ge]),ae=s.useMemo(()=>de(y),[y]),Ee=s.useMemo(()=>de(G),[G]),ne=s.useMemo(()=>Je(y,G),[y,G]),L=s.useMemo(()=>$e(y),[y]);s.useEffect(()=>{H.current=T},[T]),s.useEffect(()=>{const a=he();H.current=a,te(a)},[b]);const U=s.useCallback((a=120)=>{let n={...H.current};for(let u=0;u<a;u++){const t=n.nonce+1,N=ce(`${b}|nonce:${t}`),i=$e(N),l=de(N);if(n={...n,nonce:t,hashes:n.hashes+1},i>n.bestZeros&&(n.bestZeros=i,n.bestNonce=t,n.bestHex=l.slice(0,18),Z(`nonce ${t} found ${i} leading zero bits`)),i>=z){Z(`target ${z} opened at nonce ${t}`),Q(!1);break}}H.current=n,te(n)},[b,z]),Te=s.useCallback(()=>{je(a=>{const n=Math.max(1,b.length);return(a+1+Math.floor(Math.random()*n))%n}),Ne(a=>a>=128?1:a<<1),Z("single-bit mutation inserted; avalanche distance recalculated")},[b.length]),Oe=s.useCallback(()=>{j("mining"),U(1)},[U]),Pe=s.useCallback(()=>{j("mining"),Q(a=>{const n=!a;return Z(n?"nonce search walking the leading-zero threshold":"nonce search paused"),n})},[]),Ae=s.useCallback(()=>{Re(a=>le[(le.indexOf(a)+1)%le.length])},[]),Ie=s.useCallback(()=>{const a=he();H.current=a,te(a),Q(!1),Z("nonce slate cleared; checksum field returned to origin")},[]),ze=s.useCallback(()=>{const a=["computronium wants a memory of rain","the corridor learns by being crossed","one bit coughs and the palace changes weather","attention is a lantern with teeth","checksum snow falls upward through the archive"];me(a[Math.floor(Math.random()*a.length)])},[]),xe=s.useCallback((a,n,u,t,N={})=>{if(!e)return;const{alpha:i=1,prefixBits:l=0,muted:M=!1,time:g=0}=N;e.save(),e.globalCompositeOperation="lighter",e.lineWidth=1,e.filter="blur(0.2px)";for(let f=0;f<$;f++){e.beginPath();let x=0;for(let h=0;h<w;h++){const k=f*w+h;x+=K(a,k);const S=n+h*t+t*.5,C=Math.sin(k*.41+g*.018)*t*.28,R=u+f*t+t*.5+C;h===0?e.moveTo(S,R):e.lineTo(S,R)}const v=x/w;v>.2&&(e.strokeStyle=`rgba(142, 245, 255, ${i*v*(M?.07:.14)})`,e.stroke())}for(let f=0;f<w;f+=3){let x=0;for(let h=0;h<$;h++)x+=K(a,h*w+f);
1const v=x/$;if(!(v<.32)){e.beginPath();for(let h=0;h<$;h++){const k=h*w+f,S=n+f*t+t*.5+Math.sin(g*.014+k)*t*.22,C=u+h*t+t*.5;h===0?e.moveTo(S,C):e.lineTo(S,C)}e.strokeStyle=`rgba(255, 219, 112, ${i*v*.08})`,e.stroke()}}if(l>0){const f=n+Math.min(l,w)*t,x=e.createRadialGradient(f,u,0,f,u,Math.max(40,t*8));x.addColorStop(0,`rgba(255, 102, 153, ${.2*i})`),x.addColorStop(1,"rgba(255, 102, 153, 0)"),e.fillStyle=x,e.fillRect(f-t*8,u-t*5,t*16,$*t+t*10)}e.restore()},[e]),X=s.useCallback((a,n,u,t,N={})=>{if(!e)return;const{compareBytes:i=null,alpha:l=1,prefixBits:M=0,muted:g=!1,time:f=0,zOffset:x=0}=N,v=w*t,h=$*t,k=n+v*.5,S=u+h*.5,C=Math.max(v,h)*.56;e.save(),e.globalCompositeOperation="source-over";const R=e.createRadialGradient(k,S,h*.1,k,S,C);R.addColorStop(0,`rgba(3, 18, 24, ${g?.1:.18})`),R.addColorStop(.58,"rgba(1, 5, 12, 0.16)"),R.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=R,e.fillRect(n-t*8,u-t*8,v+t*16,h+t*16);const q=e.createRadialGradient(k,S,0,k,S,C);q.addColorStop(0,`rgba(102, 255, 204, ${.11*l})`),q.addColorStop(.5,`rgba(142, 245, 255, ${.055*l})`),q.addColorStop(1,"rgba(0, 4, 10, 0)"),e.fillStyle=q,e.fillRect(n-t*10,u-t*10,v+t*20,h+t*20),xe(a,n,u,t,{alpha:l,prefixBits:M,muted:g,time:f});for(let O=0;O<Ue;O++){const Ce=O%w,ye=Math.floor(O/w),_=K(a,O),se=i?_!==K(i,O):!1,re=O<M,Ze=a[O>>3],P=Xe(Ze/255*.68+(Math.sin(O*.63+f*.021+x)+1)*.16),ke=(P-.5)*t*1.35,B=n+Ce*t+t*.5+Math.sin(f*.011+ye*.7)*ke,E=u+ye*t+t*.5+Math.cos(f*.013+Ce*.31)*ke,F=t*(_?.18+P*.2:.12+P*.1),A=re?336:se?44:160+P*58,He=_?(g?.26:.52)*l:.12*l,we=_?(g?.12:.22)*l:.035*l;e.save(),e.globalCompositeOperation="multiply";const ie=e.createRadialGradient(B+t*.22,E+t*.28,0,B+t*.22,E+t*.28,t*(1.1+P));ie.addColorStop(0,`rgba(0, 0, 0, ${.22*l})`),ie.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=ie,e.beginPath(),e.arc(B+t*.12,E+t*.18,t*(.72+P*.55),0,Math.PI*2),e.fill(),e.restore(),e.save(),e.globalCompositeOperation="lighter";const Y=e.createRadialGradient(B,E,0,B,E,t*(1.9+P*2.6));Y.addColorStop(0,`hsla(${A}, 96%, 68%, ${we})`),Y.addColorStop(.34,`hsla(${A}, 90%, 55%, ${we*.38})`),Y.addColorStop(1,`hsla(${A}, 88%, 48%, 0)`),e.fillStyle=Y,e.beginPath(),e.arc(B,E,t*(2+P*2.3),0,Math.PI*2),e.fill(),e.restore();const I=e.createRadialGradient(B-F*.45,E-F*.55,F*.1,B,E,F*1.8);_||se||re?(I.addColorStop(0,`hsla(${A}, 100%, 92%, ${.92*l})`),I.addColorStop(.42,`hsla(${A}, 94%, 62%, ${He})`),I.addColorStop(1,`hsla(${A}, 92%, 28%, ${.1*l})`)):(I.addColorStop(0,`rgba(23, 54, 64, ${.2*l})`),I.addColorStop(.7,`rgba(4, 16, 24, ${.28*l})`),I.addColorStop(1,`rgba(0, 0, 0, ${.08*l})`)),e.fillStyle=I,e.beginPath(),e.arc(B,E,Math.max(1.3,F),0,Math.PI*2),e.fill(),(se||re)&&(e.save(),e.globalCompositeOperation="lighter",e.strokeStyle=`hsla(${A}, 100%, 72%, ${.38*l})`,e.lineWidth=Math.max(1,t*.07),e.beginPath(),e.arc(B,E,F*2.1,0,Math.PI*2),e.stroke(),e.restore())}e.restore()},[e,xe]),ve=s.useCallback((a,n,u,t)=>{if(!e)return;const N=a.match(/.{1,8}/g)||[];e.font="11px ui-monospace, SFMono-Regular, Menlo, monospace",e.textBaseline="top",N.slice(0,8).forEach((i,l)=>{const g=150+parseInt(i.slice(0,2),16)/255*90;e.fillStyle=`hsla(${g}, 80%, 62%, 0.72)`,e.fillText(i,n+l%4*(t/4),u+Math.floor(l/4)*16)})},[e]),Me=s.useCallback(()=>{if(!e||c.width===0)return;const a=c.width,n=c.height,u=pe.current;e.fillStyle="rgba(0, 3, 9, 0.985)",e.fillRect(0,0,a,n);const t=e.createRadialGradient(a*.5,n*.42,0,a*.5,n*.42,Math.max(a,n)*.78);t.addColorStop(0,"rgba(12, 42, 52, 0.24)"),t.addColorStop(.38,"rgba(4, 16, 26, 0.18)"),t.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=t,e.fillRect(0,0,a,n);const N=r==="mining"?132:76,i=Math.max(5,Math.min(20,Math.floor((a-72)/w),Math.floor((n-N)/(r==="avalanche"?18:11)))),l=w*i,M=(a-l)/2,g=r==="avalanche"?Math.max(74,n*.22):Math.max(96,n*.34);if(r==="avalanche")X(y,M,g,i,{muted:!0,time:u,zOffset:.4}),X(G,M,g+$*i+i*2.3,i,{compareBytes:y,time:u,zOffset:1.6}),e.font="12px ui-monospace, SFMono-Regular, Menlo, monospace",e.textBaseline="top",e.fillStyle="rgba(142, 245, 255, 0.52)",e.fillText(`source: ${b.slice(0,54)}`,M,g-22),e.fillStyle="rgba(255, 219, 112, 0.78)",e.fillText(`mutant: ${oe.slice(0,54)}`,M,g+$*i+i*1.35);else{const f=r==="mining"?Math.min(z,L):0;X(y,M,g,i,{prefixBits:f,time:u});const x=M+u*.45%l,v=e.createLinearGradient(x-20,0,x+20,0);if(v.addColorStop(0,"rgba(102, 255, 204, 0)"),v.addColorStop(.5,"rgba(142, 245, 255, 0.12)"),v.addColorStop(1,"rgba(102, 255, 204, 0)"),e.fillStyle=v,e.fillRect(x-20,g-i*5,40,$*i+i*10),ve(ae,M,g+$*i+24,l),r==="mining"){const h=M,k=g+$*i+66,S=l/W;for(let C=0;C<W;C++){const R=y[C]/255*Math.min(90,n-k-22);e.fillStyle=`hsla(${145+y[C]*.5}, 80%, 58%, 0.42)`,e.fillRect(h+C*S,k+92-R,Math.max(2,S-2),R)}}}e.font="12px ui-monospace, SFMono-Regular, Menlo, monospace",e.textBaseline="bottom",e.fillStyle="rgba(142, 245, 255, 0.46)",e.fillText(ee,16,n-16)},[e,y,ae,c.height,c.width,ve,X,L,ee,r,G,oe,b,z]),Se=s.useCallback(()=>{pe.current++,D&&U(90),Me()},[D,Me,U]);s.useEffect(()=>{if(!e||c.width===0)return;let a;const n=()=>{Se(),a=requestAnimationFrame(n)};return a=requestAnimationFrame(n),()=>cancelAnimationFrame(a)},[e,c.width,Se]);const Ge=s.useMemo(()=>[{label:"diff",value:`${ne}/256`,color:ne>112?"#66ffcc":"#ffcc66"},{label:"zeros",value:L},{label:"best",value:T.bestZeros},{label:"nonce",value:T.nonce}],[ne,L,T.bestZeros,T.nonce]),Fe=[{id:"mutate",label:"mutate.bit()",onClick:Te},{id:"mine-step",label:"mine.step()",onClick:Oe},{id:"auto-mine",label:D?"halt.mine()":"auto.mine()",onClick:Pe,active:D},{id:"target",label:`target.${z}()`,onClick:Ae},{id:"random",label:"phrase.cast()",onClick:ze},{id:"zero",label:"nonce.zero()",onClick:Ie,variant:"reset"}];return d.jsxs("div",{className:"fixed inset-0 overflow-hidden bg-void-dark",children:[d.jsx("div",{className:"absolute inset-0",children:d.jsx("canvas",{ref:p,className:"absolute inset-0 w-full h-full","data-testid":"avalanche-hash-canvas"})}),d.jsxs("header",{className:"pointer-events-none absolute left-0 right-0 top-0 z-50 flex items-start justify-between gap-3 p-3 sm:p-4",children:[d.jsxs("div",{className:"flex items-center gap-2 sm:gap-4",children:[d.jsx("div",{className:"pointer-events-auto",children:d.jsx(Le,{currentCategory:m.slug,currentExperiment:o.slug})}),d.jsx("h1",{className:"hidden rounded-full border border-void-green/15 bg-void-dark/45 px-3 py-2 text-sm text-glow backdrop-blur-md sm:block",style:{color:o.color},children:o.name})]}),d.jsx("div",{className:"rounded-full border border-void-green/15 bg-void-dark/45 px-3 py-2 backdrop-blur-md",children:d.jsx(De,{metrics:Ge})})]}),d.jsx("aside",{className:`absolute bottom-3 right-3 z-50 w-[min(23rem,calc(100vw-1.5rem))] transition-transform duration-300 sm:bottom-4 sm:right-4 ${V?"translate-y-0":"translate-y-[calc(100%-3rem)]"}`,children:d.jsxs("div",{className:"overflow-hidden border border-void-green/16 bg-void-dark/62 shadow-[0_0_40px_rgba(0,0,0,0.38)] backdrop-blur-xl",children:[d.jsxs("button",{type:"button",onClick:()=>Be(a=>!a),className:"flex min-h-[44px] w-full items-center justify-between border-b border-void-green/12 px-3 py-2 text-left font-mono text-xs text-void-cyan/85 transition-colors hover:bg-void-cyan/8","aria-expanded":V,children:[d.jsx("span",{children:V?"fold.controls()":"open.controls()"}),d.jsx("span",{className:"text-void-green/45",children:r})]}
1),d.jsxs("div",{className:"grid max-h-[58vh] gap-3 overflow-y-auto p-3",children:[d.jsx(We,{modes:qe,currentMode:r,onModeChange:j,controls:Fe,className:"max-sm:[&_button]:px-3 max-sm:[&_button]:py-2 max-sm:[&_button]:text-xs"}),d.jsxs("div",{className:"grid gap-2",children:[d.jsxs("label",{className:"min-w-0",children:[d.jsx("span",{className:"sr-only",children:"message input"}),d.jsx("input",{value:b,onChange:a=>me(a.target.value),className:"w-full min-h-[44px] bg-void-dark/80 border border-void-green/25 px-3 py-2 text-sm text-void-green/90 font-mono outline-none transition-colors placeholder:text-void-green/30 focus:border-void-cyan/60",placeholder:"type a phrase for the digest field","data-testid":"avalanche-phrase-input"})]}),d.jsx("div",{className:"min-h-[44px] flex items-center overflow-hidden border border-void-green/15 bg-void-dark/55 px-3 text-[11px] font-mono text-void-green/55",children:d.jsx("span",{className:"truncate",children:r==="avalanche"?Ee:ae})})]})]})]})}),d.jsx("div",{className:"pointer-events-none absolute bottom-3 left-3 z-40 max-w-[calc(100vw-2rem)] sm:hidden",children:d.jsx("div",{className:"rounded-full border border-void-green/12 bg-void-dark/45 px-3 py-2 text-[11px] font-mono text-void-cyan/50 backdrop-blur-md",children:ee})})]})};export{at as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.