mirror of
https://git.j0bot.ch/admin_j0bot/ploxion-preview.git
synced 2026-11-29 07:05:07 +00:00
100 lines
8.1 KiB
PHP
100 lines
8.1 KiB
PHP
{{-- PL0XI0N preview — LE MONITEUR : rejoue le projet de montage (xb:montage:project,
|
|
écrit par le ploxion montage « La Table ») en grand, play/scrub/plein écran. C'est
|
|
le 2e moniteur (RS-7 : « ploxion montage ET ploxion preview de montage »). Lecture
|
|
séquentielle des clips vidéo (même logique que La Table, read-only). Se rafraîchit
|
|
quand le projet change. 100% client. window.jOSApps['preview']. --}}
|
|
<style>
|
|
.pv{display:flex;flex-direction:column;height:100%;background:#000;color:#e7ecf5;font-family:ui-sans-serif,system-ui,sans-serif;font-size:.82rem}
|
|
.pv__stage{flex:1;min-height:0;display:flex;align-items:center;justify-content:center;background:#000;position:relative}
|
|
.pv__video{max-width:100%;max-height:100%;background:#000;display:block}
|
|
.pv__canvas{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);max-width:100%;max-height:100%;display:block}
|
|
.pv__empty{color:rgba(180,200,235,.6);text-align:center;padding:24px;line-height:1.5}
|
|
.pv__bar{flex:0 0 auto;display:flex;align-items:center;gap:10px;padding:9px 12px;background:rgba(8,12,18,.92);border-top:1px solid rgba(120,180,255,.16)}
|
|
.pv__pp{width:42px;height:42px;border-radius:50%;border:1px solid var(--xr-accent,#3fe0d0);background:rgba(20,40,50,.6);color:var(--xr-accent,#3fe0d0);font-size:1.1rem;cursor:pointer;flex:0 0 auto}
|
|
.pv__seek{flex:1;accent-color:var(--xr-accent,#3fe0d0)}
|
|
.pv__tc{font-family:ui-monospace,monospace;color:#9ec0ff;font-size:.74rem;min-width:104px;text-align:center}
|
|
.pv__ic{width:38px;height:38px;border-radius:9px;border:1px solid rgba(120,180,255,.3);background:rgba(30,45,75,.5);color:#dfe8ff;cursor:pointer;flex:0 0 auto}
|
|
</style>
|
|
<script>
|
|
(function () {
|
|
'use strict';
|
|
var ID='preview', KEY='xb:montage:project';
|
|
function load(){ try{ var p=JSON.parse(localStorage.getItem(KEY)); if(p&&p.tracks) return p; }catch(e){} return null; }
|
|
function clamp(v,a,b){return window.jOSb&&window.jOSb.clamp?window.jOSb.clamp(v,a,b):(v<a?a:(v>b?b:v));}
|
|
function fmtTC(t,fps){ t=Math.max(0,t); fps=fps||30; var f=Math.floor((t%1)*fps); var s=Math.floor(t); return ('0'+Math.floor(s/60)).slice(-2)+':'+('0'+(s%60)).slice(-2)+':'+('0'+f).slice(-2); }
|
|
|
|
function describe(){
|
|
var p = load();
|
|
var tracks = p&&p.tracks?p.tracks.length:0;
|
|
return { v:1, id:ID, title:'Le Moniteur', icon:'▶️', items:[
|
|
{ p:1, kind:'stat', label:'pistes du montage', value:tracks }
|
|
]};
|
|
}
|
|
function mount(container, ctx){
|
|
var P=load(), playing=false, raf=0, head=0;
|
|
container.innerHTML=
|
|
'<div class="pv"><div class="pv__stage"><video class="pv__video" data-video playsinline webkit-playsinline></video><canvas class="pv__canvas" data-canvas hidden></canvas><div class="pv__empty" data-empty hidden>Rien à monter. Ouvre 🎬 La Table, importe une vidéo, puis reviens ici.</div></div>'
|
|
+'<div class="pv__bar"><button class="pv__pp" data-pp>▶</button>'
|
|
+'<input type="range" class="pv__seek" data-seek min="0" max="1000" value="0">'
|
|
+'<span class="pv__tc" data-tc>00:00:00</span>'
|
|
+'<button class="pv__ic" data-full title="plein écran">⛶</button></div></div>';
|
|
var video=container.querySelector('[data-video]'), ppEl=container.querySelector('[data-pp]'),
|
|
seek=container.querySelector('[data-seek]'), tcEl=container.querySelector('[data-tc]'),
|
|
emptyEl=container.querySelector('[data-empty]'), stage=container.querySelector('.pv__stage'),
|
|
canvasEl=container.querySelector('[data-canvas]');
|
|
var ctx2d=canvasEl.getContext('2d',{willReadFrequently:true});
|
|
|
|
// ---- BION WASM grade : étalonnage couleur, comme La Table (même /bions/grade.wasm) ----
|
|
var wGrade=null, wMem=null, gradeTainted=false;
|
|
function loadGrade(){ if(wGrade!==null) return; wGrade=false; fetch('/bions/grade.wasm').then(function(r){return r.arrayBuffer();}).then(function(b){return WebAssembly.instantiate(b);}).then(function(m){ wGrade=m.instance.exports.grade; wMem=m.instance.exports.mem; }).catch(function(){ wGrade=false; }); }
|
|
function colorNeutral(){ var c=P&&P.color; if(!c) return true; return c.bri===0&&c.con===1&&c.sat===1&&c.gain===1&&c.lift===0; }
|
|
function paintFrame(){
|
|
if(colorNeutral()||gradeTainted){ canvasEl.hidden=true; video.style.opacity='1'; return; }
|
|
var vw=video.videoWidth, vh=video.videoHeight; if(!vw||!vh) return;
|
|
var sc=Math.min(1,720/vw), cw=Math.max(2,Math.round(vw*sc)), ch=Math.max(2,Math.round(vh*sc));
|
|
if(canvasEl.width!==cw){ canvasEl.width=cw; canvasEl.height=ch; }
|
|
try{ ctx2d.drawImage(video,0,0,cw,ch); }catch(e){ return; }
|
|
if(wGrade&&wMem){ var img; try{ img=ctx2d.getImageData(0,0,cw,ch); }catch(e){ gradeTainted=true; canvasEl.hidden=true; video.style.opacity='1'; return; }
|
|
var len=img.data.length; if(wMem.buffer.byteLength<len){ try{ wMem.grow(Math.ceil((len-wMem.buffer.byteLength)/65536)); }catch(e){} }
|
|
var u8=new Uint8Array(wMem.buffer); u8.set(img.data,0);
|
|
var c=P.color; wGrade(0,len, c.bri,c.con,c.sat,c.gain,c.lift);
|
|
img.data.set(u8.subarray(0,len)); ctx2d.putImageData(img,0,0);
|
|
}
|
|
canvasEl.hidden=false; video.style.opacity='0';
|
|
}
|
|
video.addEventListener('seeked', paintFrame);
|
|
video.addEventListener('loadeddata', function(){ gradeTainted=false; paintFrame(); });
|
|
loadGrade();
|
|
|
|
function total(){ if(!P) return 0; var m=0; P.tracks.forEach(function(t){ t.clips.forEach(function(c){ m=Math.max(m,c.start+c.dur); }); }); return m; }
|
|
function clipAt(t){ if(!P) return null; for(var i=0;i<P.tracks.length;i++){ var tr=P.tracks[i]; if(tr.kind!=='video')continue; for(var j=0;j<tr.clips.length;j++){ var c=tr.clips[j]; if(t>=c.start-1e-4 && t<c.start+c.dur-1e-4) return c; } } return null; }
|
|
|
|
function showFrame(){ var c=clipAt(head); if(!c) return; if(video.dataset.clip!==c.id){ video.dataset.clip=c.id; video.src=c.src; } var lt=clamp(head-c.start+c.inP,0,c.natDur||1e9); try{ if(Math.abs(video.currentTime-lt)>0.08) video.currentTime=lt; }catch(e){} }
|
|
function ui(){ var d=total(); seek.value=d>0?Math.round(head/d*1000):0; tcEl.textContent=fmtTC(head,P&&P.fps)+' / '+fmtTC(d,P&&P.fps); emptyEl.hidden=d>0; }
|
|
function seekTo(t){ head=clamp(t,0,total()); showFrame(); ui(); }
|
|
|
|
var last=0;
|
|
function tick(ts){ if(!playing) return; var c=clipAt(head);
|
|
if(!c){ head+=(ts-last)/1000; last=ts; if(head>=total()){ pause(); head=total(); ui(); return; } }
|
|
else { if(video.dataset.clip!==c.id){ video.dataset.clip=c.id; video.src=c.src; video.currentTime=head-c.start+c.inP; video.play().catch(function(){}); }
|
|
if(video.currentTime>=c.inP+c.dur-0.03){ head=c.start+c.dur; } else { head=c.start+(video.currentTime-c.inP); if(video.paused) video.play().catch(function(){}); } last=ts; }
|
|
ui(); paintFrame(); raf=requestAnimationFrame(tick); }
|
|
function play(){ if(playing||!total())return; if(head>=total())head=0; playing=true; ppEl.textContent='⏸'; last=performance.now(); var c=clipAt(head); if(c){ video.dataset.clip=c.id; video.src=c.src; video.currentTime=head-c.start+c.inP; video.play().catch(function(){}); } raf=requestAnimationFrame(tick); }
|
|
function pause(){ playing=false; ppEl.textContent='▶'; try{ video.pause(); }catch(e){} if(raf)cancelAnimationFrame(raf); }
|
|
|
|
ppEl.onclick=function(){ playing?pause():play(); };
|
|
seek.oninput=function(){ pause(); seekTo(seek.value/1000*total()); };
|
|
container.querySelector('[data-full]').onclick=function(){ var el=(!canvasEl.hidden)?canvasEl:video; (el.requestFullscreen||el.webkitEnterFullscreen||el.webkitRequestFullscreen||function(){}).call(el); };
|
|
|
|
var onChange=function(){ P=load(); var d=total(); if(head>d) head=d; showFrame(); ui(); paintFrame(); };
|
|
document.addEventListener('xb:montage', onChange);
|
|
window.addEventListener('storage', function(e){ if(e.key===KEY) onChange(); });
|
|
|
|
seekTo(0);
|
|
return { unmount:function(){ pause(); document.removeEventListener('xb:montage',onChange); try{ if((video.src||'').indexOf('blob:')===0) video.src=''; }catch(e){} container.innerHTML=''; } };
|
|
}
|
|
window.jOSApps=window.jOSApps||{};
|
|
window.jOSApps[ID]={ manifest:{ id:ID, name:'Le Moniteur', icon:'▶️' }, mount: mount, describe: describe };
|
|
})();
|
|
</script>
|