studius / widgets.js
2Btainment's picture
Empire P1: Docker+FastAPI backend, HF OAuth, Workspace on HF Bucket, asset bus, bee agents, Avatar studio; Merge node removed
fa32c20 verified
Raw History Blame Contribute Delete
17 kB
// 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=`<div class="chat"><p class="a">◆ STUDIUS-Core bereit. Frag mich etwas.</p></div><div class="row"><input placeholder="Nachricht… (Enter)"><button class="btn">➤</button></div>`;
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',`<p class="u">› ${inp.value.replace(/</g,'&lt;')}</p>`); inp.value='';
const p=$(`<p class="a">◆ </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=`<canvas></canvas><div class="row">Hue<input type="range" min="0" max="360" value="0"> <button class="btn alt">Pinsel</button><button class="btn alt">Reset</button></div>`;
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=`<input value="Goldene Biene fliegt durch Hex-Stadt bei Sonnenuntergang"><div class="row"><button class="btn">Generieren</button><span class="st">bereit</span></div><div class="prog" style="margin:6px 0"><i></i></div><canvas></canvas>`;
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=`<div style="font-size:10px;color:${CY}">Clips ziehen · Playhead läuft</div><div class="tl" style="position:relative"></div><div class="row"><button class="btn">▶/❚❚</button><span class="tc">00:00</span></div>`;
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=$(`<div class="track"></div>`); tr.forEach(([n,l,wd,col])=>{ const c=$(`<div class="clip" style="left:${l}%;width:${wd}%;background:${col}">${n}</div>`);
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=$(`<div style="position:absolute;top:0;bottom:0;width:2px;background:${RD};left:0"></div>`); 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=`<canvas></canvas><div class="row">Gain<input type="range" min="10" max="200" value="100"><button class="btn alt">Normalize</button></div>`;
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<N;i++){const v=Math.max(-1,Math.min(1,data[i]*gain)); x.moveTo(i,h/2-v*h/2.2); x.lineTo(i,h/2+v*h/2.2);} x.stroke();
const px=(t/20)%w; x.fillStyle=RD;x.fillRect(px,0,1.5,h); });
}},
{id:'stems',cat:'Audio',icon:'🎚',name:'Stem Split',like:'Moises-like',build(el){
const S=[['Vocals',G],['Drums',OR],['Bass',TE],['Other',CY]];
el.innerHTML=`<div class="row"><button class="btn">Trennen</button><div class="prog" style="flex:1"><i></i></div></div><div class="st"></div>`;
el.querySelector('.btn').onclick=()=>fakeProgress(el,1200,()=>{ const st=el.querySelector('.st'); st.innerHTML=S.map(([n,c])=>`<div class="row"><span style="width:52px;color:${c}">${n}</span><input type="range" value="80"><button class="btn alt" data-m>M</button></div>`).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=`<input value="Synthwave über Bienen im Retro-82 Sonnenuntergang"><div class="row"><button class="btn">♪ Song erzeugen</button></div><div class="songs"></div>`;
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=$(`<div class="row" style="border:1px solid #333;padding:4px"><span style="background:linear-gradient(135deg,${OR},${TE});width:26px;height:26px;display:inline-block"></span><span>${n}<br><small style="color:${CY}">2:4${s.children.length} · v4 sim</small></span><span class="eq" style="margin-left:auto;letter-spacing:-2px;color:${G}"></span></div>`); 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=`<canvas></canvas><div class="row"><button class="btn">▶ Execute workflow</button><span class="st" style="color:${CY}">Knoten ziehbar</span></div>`;
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&&mx<n.x+70&&my>n.y-12&&my<n.y+12); c.setPointerCapture(e.pointerId); c.onpointermove=m=>{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=`<input value="Recherche-Biene"><div style="margin:6px 0;font-size:10px;color:${CY}">Tools wählen:</div><div class="row tl">${tools.map(t=>`<button class="btn alt">${t}</button>`).join('')}</div><div class="row"><button class="btn go">Agent deployen</button></div><div class="code"></div>`;
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=`<span class="k">agent</span> <span class="s">"${el.querySelector('input').value}"</span>\n tools: [${sel.join(', ')||'–'}]\n model: einswarm-core (sim)\n status: <span class="s">● LIVE im Schwarm</span>`; };
}},
{id:'code',cat:'Code',icon:'⌨',name:'Coding Studio',like:'IDE',build(el){
el.innerHTML=`<textarea rows="5" spellcheck="false">function swarm(n){\n return Array.from({length:n},(_,i)=>'🐝'+i)\n}\nswarm(5)</textarea><div class="row"><button class="btn">▶ Run</button><button class="btn alt">✨ KI-Fix</button></div><div class="code out">// Ausgabe</div>`;
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=`<div class="grid">${items.map((n,i)=>`<div style="background:linear-gradient(${i*60}deg,#05182e,${[G,OR,TE][i%3]}33)">${n}<br>♥ <b>${(i*37+12)}</b></div>`).join('')}</div><div class="row"><button class="btn">+ Eigene Sim hosten</button></div>`;
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=`<div class="code term">$ </div><div class="row"><input placeholder="Befehl: ls, whoami, swarm, help"></div>`;
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=`<canvas></canvas><div class="row"><button class="btn" data-t="rect">▭</button><button class="btn alt" data-t="hex">⬡</button><button class="btn alt" data-t="text">T</button><span style="font-size:10px;color:${CY}">klicken = Form setzen</span></div>`;
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<w;i+=12)for(let j=0;j<h;j+=12)x.fillRect(i,j,1,1);
shapes.forEach(s=>{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=`<canvas></canvas><div class="row">${[G,OR,TE,RD,'#f6dcac'].map(c=>`<button class="btn" style="background:${c};width:22px;height:18px;padding:0" data-c="${c}"></button>`).join('')}<button class="btn alt cl">Leeren</button></div>`;
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=`<div style="font-size:11px;color:${CY};margin-bottom:6px">Weitere Studios in den Kern mergen (Simulation):</div><div class="row">${more.map(m=>`<button class="btn alt">+ ${m}</button>`).join('')}</div><div class="code" style="min-height:30px">STUDIUS-Kern: 15 Module</div>`;
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);