// STUDIUS nano-widgets — pure simulation, no backends. const $ = (h) => { const t = document.createElement('template'); t.innerHTML = h.trim(); return t.content.firstChild; }; const G = '#f2c94c', OR = '#faa968', TE = '#028391', CY = '#8cbfb8', RD = '#f85525'; const loops = new Set(); const ivs = new Set(), cleanups = new Set(); export function every(fn,ms){ const id=setInterval(()=>fn(()=>{clearInterval(id);ivs.delete(id);}),ms); ivs.add(id); return id; } export function onStop(fn){ cleanups.add(fn); } export function stopLoops(){ loops.forEach(id=>cancelAnimationFrame(id)); loops.clear(); ivs.forEach(clearInterval); ivs.clear(); cleanups.forEach(f=>{try{f()}catch(e){}}); cleanups.clear(); } export function loop(fn){ let id; const f=(t)=>{ loops.delete(id); if(!document.hidden) fn(t); id=requestAnimationFrame(f); loops.add(id); }; id=requestAnimationFrame(f); loops.add(id); } export function cv(el,h=110){ const c=el.querySelector('canvas'); const w=c.clientWidth||300; c.width=w*devicePixelRatio; c.height=h*devicePixelRatio; c.style.height=h+'px'; const x=c.getContext('2d'); x.scale(devicePixelRatio,devicePixelRatio); return [c,x,w,h]; } export function fakeProgress(el,ms,done){ const i=el.querySelector('.prog i'); let p=0; every((stop)=>{ p+=100/(ms/80); i.style.width=Math.min(p,100)+'%'; if(p>=100){stop(); done&&done();} },80); } export const STUDIOS = [ {id:'chat',cat:'Text',icon:'💬',name:'Chat',like:'ChatGPT-like',build(el){ el.innerHTML=`

◆ STUDIUS-Core bereit. Frag mich etwas.

`; const log=el.querySelector('.chat'),inp=el.querySelector('input'); const R=['Simuliere Antwort über 7 Agenten im Schwarm…','Gute Frage! Der Schwarm schlägt 3 Varianten vor.','Ich habe das an das Coding-Studio weitergeleitet (simuliert).','Zusammenfassung: Klar, machbar, mit Gold-Rand. 🐝']; const send=()=>{ if(!inp.value.trim())return; log.insertAdjacentHTML('beforeend',`

› ${inp.value.replace(/`); inp.value=''; const p=$(`

◆

`); log.append(p); const txt=R[Math.random()*R.length|0]; let k=0; every((stop)=>{p.textContent='◆ '+txt.slice(0,++k); log.scrollTop=1e4; if(k>=txt.length)stop();},18); }; el.querySelector('button').onclick=send; inp.onkeydown=e=>{e.stopPropagation(); if(e.key==='Enter')send();}; }}, {id:'image',cat:'Bild',icon:'🖌',name:'Image Edit',like:'Photoshop-like',build(el){ el.innerHTML=`
Hue
`; const [c,x,w,h]=cv(el,120); let hue=0, brush=false, paint=[]; const draw=()=>{ const g=x.createLinearGradient(0,0,w,h); g.addColorStop(0,`hsl(${30+hue},80%,55%)`); g.addColorStop(1,`hsl(${200+hue},70%,20%)`); x.fillStyle=g; x.fillRect(0,0,w,h); x.fillStyle=`hsl(${45+hue},90%,60%)`; x.beginPath(); x.arc(w*.7,h*.4,24,0,7); x.fill(); x.fillStyle='#000'; for(let i=0;i<5;i++){x.beginPath();x.moveTo(i*w/4-40,h);x.lineTo(i*w/4+20,h*.55);x.lineTo(i*w/4+80,h);x.fill();} x.fillStyle=G; paint.forEach(p=>{x.beginPath();x.arc(p[0],p[1],4,0,7);x.fill();}); }; draw(); el.querySelector('input').oninput=e=>{hue=+e.target.value;draw();}; const [b1,b2]=el.querySelectorAll('.btn'); b1.onclick=()=>{brush=!brush;b1.classList.toggle('alt');}; b2.onclick=()=>{paint=[];hue=0;el.querySelector('input').value=0;draw();}; c.onpointermove=e=>{ if(brush&&e.buttons){ const r=c.getBoundingClientRect(); paint.push([e.clientX-r.left,e.clientY-r.top]); draw(); } }; }}, {id:'videogen',cat:'Video',icon:'🎬',name:'Video Gen',like:'Sora-like',build(el){ el.innerHTML=`
bereit
`; const [c,x,w,h]=cv(el,100); let on=false; el.querySelector('input').onkeydown=e=>e.stopPropagation(); el.querySelector('.btn').onclick=()=>{ el.querySelector('.st').textContent='Diffusion… (simuliert)'; fakeProgress(el,1800,()=>{on=true;el.querySelector('.st').textContent='▶ 4s · 720p';}); }; loop(t=>{ x.fillStyle='#000';x.fillRect(0,0,w,h); if(!on){ for(let i=0;i<300;i++){x.fillStyle=`rgba(242,201,76,${Math.random()*.4})`;x.fillRect(Math.random()*w,Math.random()*h,2,2);} return;} const s=t/1000; const g=x.createLinearGradient(0,0,0,h); g.addColorStop(0,'#05182e');g.addColorStop(1,OR); x.fillStyle=g;x.fillRect(0,0,w,h); x.fillStyle='#020c17'; for(let i=0;i<10;i++){const bx=((i*47-s*30)%(w+60)+w+60)%(w+60)-30; x.fillRect(bx,h-20-(i*13%40),26,60);} const bx=w/2+Math.sin(s*1.3)*w*.3, by=h*.4+Math.sin(s*3)*10; x.fillStyle=G;x.beginPath();x.ellipse(bx,by,9,6,0,0,7);x.fill(); x.fillStyle='rgba(246,220,172,.7)';x.beginPath();x.ellipse(bx-2,by-7,6,3+Math.sin(s*40)*2,0,0,7);x.fill(); }); }}, {id:'videoedit',cat:'Video',icon:'✂',name:'Video Edit',like:'CapCut-like',build(el){ el.innerHTML=`
Clips ziehen · Playhead läuft
00:00
`; const tl=el.querySelector('.tl'); const tracks=[[['Intro',0,30,G],['Swarm',32,40,OR]],[['Titel',10,25,CY]],[['Musik',0,90,TE]]]; tracks.forEach(tr=>{ const d=$(`
`); tr.forEach(([n,l,wd,col])=>{ const c=$(`
${n}
`); c.onpointerdown=e=>{ e.stopPropagation(); c.setPointerCapture(e.pointerId); const sx=e.clientX, sl=parseFloat(c.style.left); c.onpointermove=m=>{ c.style.left=Math.max(0,Math.min(100-wd,sl+(m.clientX-sx)/d.clientWidth*100))+'%'; }; c.onpointerup=()=>c.onpointermove=null; }; d.append(c); }); tl.append(d); }); const ph=$(`
`); tl.append(ph); let play=true,p=0; el.querySelector('.btn').onclick=()=>play=!play; loop(()=>{ if(play){p=(p+.15)%100; ph.style.left=p+'%'; el.querySelector('.tc').textContent='00:'+String(Math.floor(p*.3)).padStart(2,'0');} }); }}, {id:'audio',cat:'Audio',icon:'〰',name:'Audio Edit',like:'Audition-like',build(el){ el.innerHTML=`
Gain
`; const [c,x,w,h]=cv(el,90); let gain=1, sel=null; const N=Math.floor(w); const data=[...Array(N)].map((_,i)=>Math.sin(i*.07)*Math.sin(i*.013)*.8+(Math.random()-.5)*.3); el.querySelector('input').oninput=e=>gain=e.target.value/100; el.querySelector('.btn').onclick=()=>gain=1/Math.max(...data.map(Math.abs)); c.onpointerdown=e=>{const r=c.getBoundingClientRect(); sel=[e.clientX-r.left,e.clientX-r.left]; c.onpointermove=m=>sel[1]=m.clientX-r.left; c.onpointerup=()=>c.onpointermove=null;}; loop(t=>{ x.fillStyle='#000';x.fillRect(0,0,w,h); if(sel){x.fillStyle='rgba(2,131,145,.35)';x.fillRect(Math.min(...sel),0,Math.abs(sel[1]-sel[0]),h);} x.strokeStyle=G;x.beginPath(); for(let i=0;i
`; el.querySelector('.btn').onclick=()=>fakeProgress(el,1200,()=>{ const st=el.querySelector('.st'); st.innerHTML=S.map(([n,c])=>`
${n}
`).join(''); st.querySelectorAll('[data-m]').forEach(b=>b.onclick=()=>b.classList.toggle('alt')); }); }}, {id:'music',cat:'Audio',icon:'🎵',name:'Music Gen',like:'Suno-like',build(el){ el.innerHTML=`
`; el.querySelector('input').onkeydown=e=>e.stopPropagation(); el.querySelector('.btn').onclick=()=>{ const s=el.querySelector('.songs'); const n=['Golden Hive','Hex Sunset','Swarm Drive'][s.children.length%3]; const d=$(`
${n}
2:4${s.children.length} · v4 sim
`); s.prepend(d); let k=0; every((stop)=>{ if(!d.isConnected)return stop(); d.querySelector('.eq').textContent=[...Array(8)].map(()=>'▁▂▃▄▅▆▇'[Math.random()*7|0]).join(''); if(++k>200)stop();},120); }; }}, {id:'auto',cat:'Automation',icon:'⛓',name:'Automation',like:'n8n-like',build(el){ el.innerHTML=`
Knoten ziehbar
`; const [c,x,w,h]=cv(el,120); const N=[['Webhook',20,50],['KI-Agent',w*.38,25],['Filter',w*.38,85],['Slack',w*.7,50]].map(a=>({n:a[0],x:a[1],y:a[2],on:0})); const E=[[0,1],[0,2],[1,3],[2,3]]; let drag=null, run=-1, rt=0; c.onpointerdown=e=>{const r=c.getBoundingClientRect(),mx=e.clientX-r.left,my=e.clientY-r.top; drag=N.find(n=>mx>n.x&&mxn.y-12&&my{if(drag){drag.x=m.clientX-r.left-35;drag.y=m.clientY-r.top;}}; c.onpointerup=()=>{drag=null;c.onpointermove=null;};}; el.querySelector('.btn').onclick=()=>{run=0;rt=0;N.forEach(n=>n.on=0);}; loop(()=>{ x.fillStyle='#020c17';x.fillRect(0,0,w,h); if(run>=0){rt++; if(rt%30===0){N[[0,1,2,3][run]].on=1; run++; if(run>3){run=-1; el.querySelector('.st').textContent='✔ 4/4 Knoten OK (sim)';}}} E.forEach(([a,b])=>{const A=N[a],B=N[b];x.strokeStyle=A.on&&B.on?G:'#2a6b78';x.beginPath();x.moveTo(A.x+70,A.y);x.bezierCurveTo(A.x+100,A.y,B.x-30,B.y,B.x,B.y);x.stroke();}); N.forEach(n=>{x.fillStyle=n.on?'#3a2f10':'#000';x.strokeStyle=n.on?G:OR;x.fillRect(n.x,n.y-12,70,24);x.strokeRect(n.x,n.y-12,70,24);x.fillStyle=n.on?G:'#f6dcac';x.font='10px JBM';x.fillText(n.n,n.x+6,n.y+4);}); }); }}, {id:'agent',cat:'Automation',icon:'🤖',name:'Agent Builder',like:'Agent builder',build(el){ const tools=['Web-Suche','Code','Datei','Mail','Kalender','Bild']; el.innerHTML=`
Tools wählen:
${tools.map(t=>``).join('')}
`; el.querySelector('input').onkeydown=e=>e.stopPropagation(); el.querySelectorAll('.tl .btn').forEach(b=>b.onclick=()=>b.classList.toggle('alt')); el.querySelector('.go').onclick=()=>{ const sel=[...el.querySelectorAll('.tl .btn:not(.alt)')].map(b=>b.textContent); el.querySelector('.code').innerHTML=`agent "${el.querySelector('input').value}"\n tools: [${sel.join(', ')||'–'}]\n model: einswarm-core (sim)\n status: ● LIVE im Schwarm`; }; }}, {id:'code',cat:'Code',icon:'⌨',name:'Coding Studio',like:'IDE',build(el){ el.innerHTML=`
// Ausgabe
`; const ta=el.querySelector('textarea'); ta.onkeydown=e=>e.stopPropagation(); const out=el.querySelector('.out'); const [r,f]=el.querySelectorAll('.btn'); r.onclick=()=>{ try{ out.textContent='> '+JSON.stringify(Function('"use strict";'+ta.value.replace(/\n([^\n]*)$/,'\nreturn $1'))()); }catch(e){ out.textContent='✖ '+e.message; } }; f.onclick=()=>{ out.textContent='✨ KI schlägt vor: Typen ergänzen, Tests schreiben (simuliert)'; }; }}, {id:'community',cat:'Community',icon:'🌐',name:'Community Hub',like:'websim-like',build(el){ const items=['Hex Racer','Bee Synth','Gold Chat','Retro OS','Swarm Map','Pixel Hive']; el.innerHTML=`
${items.map((n,i)=>`
${n}
♥ ${(i*37+12)}
`).join('')}
`; el.querySelectorAll('.grid div').forEach(d=>d.onclick=()=>{ const b=d.querySelector('b'); b.textContent=+b.textContent+1; d.style.borderColor=G; }); el.querySelector('.btn').onclick=e=>e.target.textContent='✔ veröffentlicht unter /sim/neu (sim)'; }}, {id:'sandbox',cat:'Code',icon:'🧪',name:'Sandbox',like:'Container',build(el){ el.innerHTML=`
$
`; const t=el.querySelector('.term'), i=el.querySelector('input'); const C={ls:'agents/ studios/ hive.toml',whoami:'rob@studius-sandbox',swarm:'🐝 128 Agenten aktiv · 0 Fehler',help:'ls whoami swarm clear'}; i.onkeydown=e=>{e.stopPropagation(); if(e.key==='Enter'){ const v=i.value.trim(); if(v==='clear')t.textContent='$ '; else t.textContent+=v+'\n'+(C[v]||'command not found: '+v)+'\n$ '; i.value=''; t.scrollTop=1e4; } }; }}, {id:'design',cat:'Design',icon:'📐',name:'Design Board',like:'Figma/Excalidraw-like',build(el){ el.innerHTML=`
klicken = Form setzen
`; const [c,x,w,h]=cv(el,120); let tool='rect'; const shapes=[{t:'hex',x:60,y:60},{t:'rect',x:150,y:50},{t:'text',x:200,y:95}]; el.querySelectorAll('[data-t]').forEach(b=>b.onclick=()=>{tool=b.dataset.t; el.querySelectorAll('[data-t]').forEach(o=>o.classList.toggle('alt',o!==b));}); c.onclick=e=>{const r=c.getBoundingClientRect(); shapes.push({t:tool,x:e.clientX-r.left,y:e.clientY-r.top});}; loop(()=>{ x.fillStyle='#0b0b0b';x.fillRect(0,0,w,h); x.fillStyle='#1d1d1d'; for(let i=0;i{x.strokeStyle=s.t==='hex'?G:OR;x.lineWidth=1.5; if(s.t==='rect')x.strokeRect(s.x-22,s.y-14,44,28); else if(s.t==='hex'){x.beginPath();for(let k=0;k<7;k++){const a=k*Math.PI/3;x.lineTo(s.x+20*Math.cos(a),s.y+20*Math.sin(a));}x.stroke();} else {x.fillStyle=CY;x.font='12px JBM';x.fillText('Idee',s.x,s.y);} }); }); }}, {id:'canvas',cat:'Design',icon:'🎨',name:'Canvas',like:'Freihand',build(el){ el.innerHTML=`
${[G,OR,TE,RD,'#f6dcac'].map(c=>``).join('')}
`; const [c,x,w,h]=cv(el,120); let col=G,last=null; x.fillStyle='#000';x.fillRect(0,0,w,h); el.querySelectorAll('[data-c]').forEach(b=>b.onclick=()=>col=b.dataset.c); el.querySelector('.cl').onclick=()=>{x.fillStyle='#000';x.fillRect(0,0,w,h);}; c.onpointerdown=e=>{c.setPointerCapture(e.pointerId);const r=c.getBoundingClientRect();last=[e.clientX-r.left,e.clientY-r.top];}; c.onpointermove=e=>{ if(!last)return; const r=c.getBoundingClientRect(),p=[e.clientX-r.left,e.clientY-r.top]; x.strokeStyle=col;x.lineWidth=3;x.lineCap='round';x.beginPath();x.moveTo(...last);x.lineTo(...p);x.stroke();last=p;}; c.onpointerup=()=>last=null; }}, {id:'merge',cat:'+',icon:'+',name:'Merge',like:'Studio andocken',build(el){ const more=['3D-Studio','Game-Studio','Podcast','Übersetzer','Daten-Lab','Avatar']; el.innerHTML=`
Weitere Studios in den Kern mergen (Simulation):
${more.map(m=>``).join('')}
STUDIUS-Kern: 15 Module
`; let n=15; el.querySelectorAll('.btn').forEach(b=>b.onclick=()=>{ if(b.disabled)return; b.disabled=true; b.textContent='✔ '+b.textContent.slice(2); b.classList.remove('alt'); el.querySelector('.code').textContent=`STUDIUS-Kern: ${++n} Module · Merge OK (sim)`; window.dispatchEvent(new CustomEvent('studius-merge')); }); }}, ]; // Merge concept dropped (owner decision 2026-10-13): keep code for history, remove from the scene. STUDIOS.splice(STUDIOS.findIndex(s => s.id === 'merge'), 1);