@omnimedia/omnitool 1.1.0-108 → 1.1.0-109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/x/index.html CHANGED
@@ -295,7 +295,7 @@ canvas {
295
295
  }
296
296
  }
297
297
  </style>
298
- <script type=module src="demo/demo.bundle.min.js?v=037cfe63cf8c"></script>
298
+ <script type=module src="demo/demo.bundle.min.js?v=d6e68b828150"></script>
299
299
 
300
300
 
301
301
  <meta name="theme-color" content="#3cff9c">
@@ -317,7 +317,7 @@ canvas {
317
317
  <section>
318
318
  <header class="hero">
319
319
  <div>
320
- <h1>Omnitool <small>v1.1.0-108</small></h1>
320
+ <h1>Omnitool <small>v1.1.0-109</small></h1>
321
321
  <p>Developer demos for decoding, preview, waveform, playback, and export.</p>
322
322
  </div>
323
323
  </header>
@@ -2862,7 +2862,7 @@ fn mainFragment(
2862
2862
  sample.b *= sample.a;
2863
2863
 
2864
2864
  return sample;
2865
- }`;var Ul=class Hl extends P{constructor(e={}){e={...Hl.defaultOptions,...e};let t=M.from({vertex:{source:ja,entryPoint:"mainVertex"},fragment:{source:ja,entryPoint:"mainFragment"}}),n=F.from({vertex:Hr,fragment:_l,name:"noise-filter"}),{noise:o,seed:i,...s}=e;super({...s,gpuProgram:t,glProgram:n,resources:{noiseUniforms:new Ur({uNoise:{value:1,type:"f32"},uSeed:{value:1,type:"f32"}})}}),this.noise=o,this.seed=i??Math.random()}get noise(){return this.resources.noiseUniforms.uniforms.uNoise}set noise(e){this.resources.noiseUniforms.uniforms.uNoise=e}get seed(){return this.resources.noiseUniforms.uniforms.uSeed}set seed(e){this.resources.noiseUniforms.uniforms.uSeed=e}};Ul.defaultOptions={noise:.5};var Za=Ul;var _i=class extends Mc{constructor(e,t){let{text:n,resolution:o,style:i,anchor:s,width:a,height:c,roundPixels:u,...f}=e;super({...f}),this.batched=!0,this._resolution=null,this._autoResolution=!0,this._didTextUpdate=!0,this._styleClass=t,this.text=n??"",this.style=i,this.resolution=o??null,this.allowChildren=!1,this._anchor=new Qn({_onUpdate:()=>{this.onViewUpdate()}}),s&&(this.anchor=s),this.roundPixels=u??!1,a!==void 0&&(this.width=a),c!==void 0&&(this.height=c)}get anchor(){return this._anchor}set anchor(e){typeof e=="number"?this._anchor.set(e):this._anchor.copyFrom(e)}set text(e){e=e.toString(),this._text!==e&&(this._text=e,this.onViewUpdate())}get text(){return this._text}set resolution(e){this._autoResolution=e===null,this._resolution=e,this.onViewUpdate()}get resolution(){return this._resolution}get style(){return this._style}set style(e){e||(e={}),this._style?.off("update",this.onViewUpdate,this),e instanceof this._styleClass?this._style=e:this._style=new this._styleClass(e),this._style.on("update",this.onViewUpdate,this),this.onViewUpdate()}get width(){return Math.abs(this.scale.x)*this.bounds.width}set width(e){this._setWidth(e,this.bounds.width)}get height(){return Math.abs(this.scale.y)*this.bounds.height}set height(e){this._setHeight(e,this.bounds.height)}getSize(e){return e||(e={}),e.width=Math.abs(this.scale.x)*this.bounds.width,e.height=Math.abs(this.scale.y)*this.bounds.height,e}setSize(e,t){typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,this.bounds.width),t!==void 0&&this._setHeight(t,this.bounds.height)}containsPoint(e){let t=this.bounds.width,n=this.bounds.height,o=-t*this.anchor.x,i=0;return e.x>=o&&e.x<=o+t&&(i=-n*this.anchor.y,e.y>=i&&e.y<=i+n)}onViewUpdate(){this.didViewUpdate||(this._didTextUpdate=!0),super.onViewUpdate()}destroy(e=!1){super.destroy(e),this.owner=null,this._bounds=null,this._anchor=null,(typeof e=="boolean"?e:e?.style)&&this._style.destroy(e),this._style=null,this._text=null}get styleKey(){return`${this._text}:${this._style.styleKey}:${this._resolution}`}};function Rl(r,e){let t=r[0]??{};return(typeof t=="string"||r[1])&&(X(kn,`use new ${e}({ text: "hi!", style }) instead`),t={text:t,style:r[1]}),t}var uo=class extends _i{constructor(...e){let t=Rl(e,"Text");super(t,_c),this.renderPipeId="text",t.textureStyle&&(this.textureStyle=t.textureStyle instanceof Ps?t.textureStyle:new Ps(t.textureStyle))}updateBounds(){let e=this._bounds,t=this._anchor,n=0,o=0;if(this._style.trim){let{frame:i,canvasAndContext:s}=_s.getCanvasAndContext({text:this.text,style:this._style,resolution:1});_s.returnCanvasAndContext(s),n=i.width,o=i.height}else{let i=Uc.measureText(this._text,this._style);n=i.width,o=i.height}e.minX=-t._x*n,e.maxX=e.minX+n,e.minY=-t._y*o,e.maxY=e.minY+o}};Fc.add(Cl,xl);var $a=r=>{let[e,t,n]=r,[o,i]=e,[s,a]=t,c=n*Math.PI/180,u=Math.cos(c),f=Math.sin(c);return[u*s,f*s,-f*a,u*a,o,i]},Gl=([r,e,t,n,o,i])=>new Ts(r,e,t,n,o,i);var ec=(r,e)=>{let[t,n,o,i,s,a]=r,[c,u,f,l,m,g]=e;return[t*c+o*u,n*c+i*u,t*f+o*l,n*f+i*l,t*m+o*g+s,n*m+i*g+a]};var zl=[1,0,0,1,0,0];var tc=class{keys;index;constructor(e,t){this.keys=e,this.index=t}near(e){return this.keys[Math.max(0,Math.min(this.keys.length-1,this.index+e))][1]}},Nl=r=>r,lo=r=>Nl((e,t)=>r(e,t.near(0),t.near(1))),fo=(r,e,t)=>e+(t-e)*r,rh={linear:lo(fo),ease:lo((r,e,t)=>{let n=r<.5?4*r*r*r:1-Math.pow(-2*r+2,3)/2;return fo(n,e,t)}),easeIn:lo((r,e,t)=>fo(r*r*r,e,t)),easeOut:lo((r,e,t)=>fo(1-Math.pow(1-r,3),e,t)),bounce:lo((r,e,t)=>{let i=r<.36363636363636365?7.5625*r*r:r<.7272727272727273?7.5625*(r-.5454545454545454)**2+.75:r<.9090909090909091?7.5625*(r-.8181818181818182)**2+.9375:7.5625*(r-.9545454545454546)**2+.984375;return fo(i,e,t)}),catmullRom:Nl((r,e)=>{let t=e.near(-1),n=e.near(0),o=e.near(1),i=e.near(2),s=r*r,a=s*r;return .5*(2*n+(-t+o)*r+(2*t-5*n+4*o-i)*s+(-t+3*n-3*o+i)*a)})},Ol=(r,e,t,n)=>{let o=rh[r];if(!o)throw new Error(`unknown terp "${r}"`);return o(e,new tc(t,n))};var an=(r,e,t,n=0)=>{if(e.length===0)return n;if(e.length===1)return e[0][1];let o=[...e].sort((l,m)=>l[0]-m[0]);if(r<=o[0][0])return o[0][1];let i=o[o.length-1];if(r>=i[0])return i[1];let s=0;for(let l=0;l<o.length-1;l++){let m=o[l],g=o[l+1];if(r>=m[0]&&r<=g[0]){s=l;break}}let[a]=o[s],[c]=o[s+1],u=c-a,f=u===0?0:(r-a)/u;return Ol(t,f,o,s)},Ui=(r,e)=>[[an(r,e.track.position.x,e.terp),an(r,e.track.position.y,e.terp)],[an(r,e.track.scale.x,e.terp,1),an(r,e.track.scale.y,e.terp,1)],an(r,e.track.rotation,e.terp)],Ll=(r,e)=>an(r,e.track,e.terp);function nh(r){return"duration"in r}function Vl(r){let e=[],t=new Map(r.timeline.items.map(n=>[n.id,n]));return rc(r.timeline.rootId,t,r.from,{sequence:()=>{},stack:()=>{},video:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),image:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),text:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),caption:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),audio:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i})}),e}function Kl(r,e,t,n){let o=zl;for(let i of e)o=ql(r,i.item,o,i.localTime);return ql(r,t,o,n)}function ql(r,e,t,n){let o=t;if("spatialId"in e&&e.spatialId){let i=r.get(e.spatialId);if(i&&i.enabled!==!1){let s=$a(i.transform);o=ec(s,o)}}if("animationIds"in e&&e.animationIds)for(let i of e.animationIds){let s=r.get(i),a=s?.anims.transform;if(s?.enabled!==!1&&a&&oh(a,n)){let c=$a(Ui(n,a));o=ec(c,o)}}return o}function rc(r,e,t,n,o=[]){let i=e.get(r);if(i)switch(i.kind){case Z.Stack:n.stack(i,t,o);for(let s of i.childrenIds)rc(s,e,t,n,[...o,{item:i,localTime:t}]);break;case Z.Sequence:{n.sequence(i,t,o);let s=$(0);for(let a of i.childrenIds){let c=e.get(a);if(!c)continue;let u=Hi(c.id,e);if(u<=0)continue;let f=$(s+u);if(t>=f){s=f;continue}let l=$(Math.max(0,t-s));rc(a,e,l,n,[...o,{item:i,localTime:t}]),s=f}break}case Z.Video:n.video(i,t,o);break;case Z.Image:n.image(i,t,o);break;case Z.Text:n.text(i,t,o);break;case Z.Caption:n.caption(i,t,o);break;case Z.Audio:n.audio(i,t,o);break}}function Ae(r,e){return Hi(r,new Map(e.items.map(t=>[t.id,t])))}function Hi(r,e){let t=e.get(r);if(!t)return $(0);switch(t.kind){case Z.Sequence:{let n=$(0);for(let o of t.childrenIds)n=$(n+Hi(o,e));return n}case Z.Stack:{let n=$(0);for(let o of t.childrenIds){let i=Hi(o,e);i>n&&(n=i)}return n}default:return nh(t)?t.duration:$(0)}}function Yl(r,e,t){if(!("animationIds"in e)||e.animationIds===void 0)return 1;let n=1;for(let o of e.animationIds){let i=r.items.get(o),s=i?.anims.opacity;i?.enabled!==!1&&s&&cn(s.track,t)&&(n=Ll(t,s))}return n}function cn(r,e){if(r.length===0)return!1;let t=r[0][0],n=r[0][0];for(let[o]of r)t=Math.min(t,o),n=Math.max(n,o);return e>=t&&e<=n}function oh(r,e){return cn(r.track.position.x,e)||cn(r.track.position.y,e)||cn(r.track.scale.x,e)||cn(r.track.scale.y,e)||cn(r.track.rotation,e)}var Ri=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let n=new Ne({formats:Je,source:await tt(this.resolveMedia(e))}),o=await n.getPrimaryVideoTrack(),s=!!o&&await o.canDecode()&&o?new pr(o):null;return this.#e.set(e,{input:n,sink:s}),s}};var Gi=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getFrame(e,t){let n=await this.#t(e);return new VideoFrame(n.bitmap,{timestamp:Math.round(t*1e3)})}async#t(e){let t=this.#e.get(e);if(t)return t;let n=this.resolveMedia(e),o=n instanceof Blob?n:await fetch(n).then(s=>s.blob()),i={bitmap:await createImageBitmap(o)};return this.#e.set(e,i),i}disposeAll(){for(let e of this.#e.values())e.bitmap.close();this.#e.clear()}dispose(e){this.#e.get(e)?.bitmap.close(),this.#e.delete(e)}};async function Jl(r,e,t,n){let[o,i]=await Promise.all([t,n]),s=o.find(u=>u.kind==="image")?.frame,a=i.find(u=>u.kind==="image")?.frame,c=[...o.filter(u=>u.kind!=="image"),...i.filter(u=>u.kind!=="image")];return s&&a?[{id:r.id,kind:"transition",name:r.name,progress:e,from:s,to:a},...c]:c}async function Xl(r,e,t,n){let o=ih(r,e,t);if(!o)return[];let i=[...n,{item:e,localTime:t}];return o.isTransitioning?Jl(o.transition,o.progress,Wl(r,o.outgoing,o.outgoingTime,i),Wl(r,o.incoming,o.incomingTime,i)):wr(r,o.item,o.localTime,i)}function ih(r,e,t){let n=e.childrenIds.map(i=>r.items.get(i)).filter(i=>!!i),o=$(0);for(let i=0;i<n.length;i++){let s=n[i],a=Ae(s.id,r.timeline),c=$(o+a);if(a<=0){o=c;continue}if(t<o||t>=c){o=c;continue}let u=$(t-o);if(s.enabled===!1)return{isTransitioning:!1,item:s,localTime:u};if(s.kind!==Z.Transition)return{isTransitioning:!1,item:s,localTime:u};let f=n[i-1],l=n[i+1];if(!(f&&l&&f.kind!==Z.Transition&&l.kind!==Z.Transition))return null;let g=Ae(f.id,r.timeline);return{isTransitioning:!0,incoming:l,outgoing:f,outgoingTime:$(g+u),incomingTime:$(u-a),progress:u/a,transition:s}}return null}async function Wl(r,e,t,n){let o=await wr(r,e,t,n,{allowHandles:!0});if(o.some(a=>a.kind==="image"))return o;let i=Ae(e.id,r.timeline),s=$(Math.max(0,Math.min(t,i>0?i-1:0)));return wr(r,e,s,n)}async function wr(r,e,t,n,o={}){if("enabled"in e&&e.enabled===!1)return e.kind===Z.Gap?[{id:e.id,kind:"gap"}]:[];let i=Kl(r.items,n,e,t),s=Yl(r,e,t),a="spatialId"in e&&e.spatialId?r.items.get(e.spatialId)?.crop:void 0,c="filterIds"in e&&e.filterIds?e.filterIds.map(u=>r.items.get(u)).filter(u=>!!u&&u.enabled!==!1).map(u=>({type:u.type,params:u.params})):void 0;switch(e.kind){case Z.Stack:{let u=[...n,{item:e,localTime:t}];return(await Promise.all(e.childrenIds.map(l=>r.items.get(l)).filter(l=>!!l).map(l=>wr(r,l,t,u,o)))).flat()}case Z.Sequence:return Xl(r,e,t,n);case Z.Video:{if(!o.allowHandles&&(t<0||t>=e.duration))return[];let u=await r.videoSampler(e,t);return u?[{kind:"image",frame:u,matrix:i,alpha:s,crop:a,filters:c,id:e.id}]:[]}case Z.Image:{if(!o.allowHandles&&(t<0||t>=e.duration))return[];let u=await r.imageSampler(e,t);return u?[{kind:"image",frame:u,matrix:i,alpha:s,crop:a,filters:c,id:e.id}]:[]}case Z.Text:{if(!o.allowHandles&&(t<0||t>=e.duration))return[];let u=e.styleId?r.items.get(e.styleId):void 0,f=u?.enabled!==!1?u?.style:void 0;return[{id:e.id,kind:"text",content:e.content,style:f,matrix:i,alpha:s,crop:a,filters:c}]}case Z.Caption:{if(!o.allowHandles&&(t<0||t>=e.duration))return[];let u=e.start+t,f=ea(e.transcript,e).find(g=>{let[d,p]=g.timestamp;return u>=d&&u<p});if(!f)return[];let l=e.styleId?r.items.get(e.styleId):void 0,m=l?.enabled!==!1?l?.style:void 0;return[{id:e.id,kind:"text",content:f.text,style:m,matrix:i,alpha:s,crop:a,filters:c}]}case Z.Gap:return[{id:e.id,kind:"gap"}];default:return[]}}function jl(r){return async(e,t)=>{let n=await r.getSink(e.mediaHash),o=e.start+t,i=await n?.getSample(o/1e3),s=i?.toVideoFrame();return i?.close(),s??void 0}}function Zl(r){return async(e,t)=>await r.getFrame(e.mediaHash,t)}function vr(r,e){let t=new Gi(r),n=new Ri(r),o=Zl(t),i=e??jl(n);return{async sample(s,a){let c=new Map(s.items.map(f=>[f.id,f])),u=c.get(s.rootId);return u?wr({imageSampler:o,videoSampler:i,timeline:s,items:c},u,a,[]):[]}}}var zi=class{driver;resolveMedia;timeline;#e=new Map;#t;constructor(e,t,n){this.driver=e,this.resolveMedia=t,this.timeline=n,this.#t=vr(this.resolveMedia,(o,i)=>{let s=$l($(o.start+i)),a=this.#e.get(o.id);if(!a){let c=this.resolveMedia(o.mediaHash),u=$l($(o.start+o.duration));a=this.createCursor(c,s,u),this.#e.set(o.id,a)}return a.next(s)})}sample(e){return this.#t.sample(this.timeline,e)}async cancel(){await Promise.all([...this.#e.values()].map(e=>e.cancel())),this.#e.clear()}},Ft=class extends zi{#e=-1/0;next(e){if(e<this.#e)throw new Error(`Forward-only cursor regression: ${e}ms < ${this.#e}ms`);return this.#e=e,this.sample(e)}createCursor(e,t,n){let o=this.driver.decodeVideo({source:e,start:t/1e6,end:n/1e6}),i=o.readable.getReader(),s=null,a=null,c=!1,u=async()=>{if(c)return null;let{done:f,value:l}=await i.read();if(f)return c=!0,null;let m=new VideoFrame(l);return l.close(),m};return{async next(f){if(s??=await u(),!!s)for(;;){a??=u();let l=await a;if(!l)return new VideoFrame(s);let m=s.timestamp??-1/0,g=l.timestamp??m;if(g<f){s.close(),s=l,a=null;continue}if(Math.abs(g-f)<Math.abs(m-f)){s.close(),s=l,a=null;continue}return new VideoFrame(s)}},async cancel(){let f=a;a=null,c=!0,(await f?.catch(()=>null))?.close(),s?.close(),s=null,o.cancel()}}}},mo=class extends zi{#e=1/0;next(e){if(e>this.#e)throw new Error(`Reverse-only cursor regression: ${e}ms > ${this.#e}ms`);return this.#e=e,this.sample(e)}createCursor(e,t,n){let s=[],a=1/0,c=-1/0,u=null,f=null,l=null,m=0,g=Promise.resolve(),d=null,p=!1,A=()=>{for(let w of s)w.close();s=[]},C=()=>{m++===0&&(g=new Promise(w=>d=w))},I=()=>{--m===0&&(d?.(),d=null)},v=async()=>{if(f)return f;u=new Ne({source:await tt(e),formats:Je});let w=await u.getPrimaryVideoTrack();return f=w&&await w.canDecode()?new pr(w):null,f},x=async w=>{C();let T=Math.min(n,w+1),y=Math.max(t,T-1e6),Q=[],N=await v();if(N)for await(let O of N.samples(y/1e6,T/1e6))Q.push(O.toVideoFrame()),O.close();return I(),{frames:Q,windowStart:y,windowEnd:T}},S=async w=>{A();let T=await x(w);s=T.frames,a=T.windowStart,c=T.windowEnd};return{async next(w){if(p)return;if(w<a||w>c)if(l){let Q=await l;if(l=null,p){for(let N of Q.frames)N.close();return}if(w>=Q.windowStart&&w<=Q.windowEnd)A(),s=Q.frames,a=Q.windowStart,c=Q.windowEnd;else{for(let N of Q.frames)N.close();await S(w)}}else await S(w);!l&&w<a+5e5&&a>t&&(l=x(a-1));let T,y=1/0;for(let Q of s){let N=Math.abs((Q.timestamp??w)-w);N<y&&(T=Q,y=N)}return T?new VideoFrame(T):void 0},async cancel(){p=!0;let w=l;l=null;let T=await w?.catch(()=>null);if(T)for(let y of T.frames)y.close();await g,A(),u?.dispose(),u=null,f=null}}}},$l=r=>Math.round(r*1e3);async function ef(r,e,t){return(await Promise.all(e.map(async({item:o,localTime:i})=>{if(o.kind!==Z.Audio||o.enabled===!1||i>=o.duration)return;let s=await r.getSink(o.mediaHash);if(!s)return;let a=o.start+i,c=o.start+o.duration,u=ao((t-a)/1e3),f=s.samples(a/1e3,c/1e3),l=await f.next();if(l.done)return;let m=l.value,g=f.next();return{offset:u,gain:o.gain??1,get currentSample(){return m},timelineTime:()=>ao(u+m.timestamp),output:()=>({itemId:o.id,sample:m,timestamp:u+m.timestamp,gain:o.gain??1}),advance:async()=>{let d=await g;return d.done?!1:(m=d.value,g=f.next(),!0)}}}))).filter(o=>!!o)}var Ni=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let n=new Ne({formats:Je,source:await tt(this.resolveMedia(e))}),o=await n.getPrimaryAudioTrack(),s=!!o&&await o.canDecode()&&o?new Xn(o):null;return this.#e.set(e,{input:n,sink:s}),s}};function tf(r){let e={index:0,stream:r[0],time:r[0].timelineTime()};for(let[t,n]of r.entries()){let o=n.timelineTime();o<e.time&&(e={time:o,stream:n,index:t})}return e}function Oi(r){let e=new Ni(r);return{async*sampleAudio(t,n){let o=Vl({timeline:t,from:n}),i=await ef(e,o,n);for(;i.length>0;){let{stream:s,index:a}=tf(i);yield s.output(),await s.advance()||i.splice(a,1)}}}}var Li=class{driver;timeline;resolveMedia;audioLevels;audioSampler;seekVisualSampler;playVisualSampler=null;reversePlayVisualSampler=null;#e=$(0);#t=null;#r=1;#n=Al();onTick=this.#n.onTick;audioContext=new AudioContext({sampleRate:48e3});audioGain=this.audioContext.createGain();audioNodes=new Map;#o=null;constructor(e,t,n){this.driver=e,this.timeline=t,this.resolveMedia=n,this.audioGain.connect(this.audioContext.destination),this.audioGain.gain.value=.7**2,this.audioLevels=new Ti(this.audioContext,()=>this.currentTime,()=>this.#n.isPlaying()),this.seekVisualSampler=vr(this.resolveMedia),this.audioSampler=Oi(this.resolveMedia),this.#s()}update(e){this.timeline=e}get isPlaying(){return this.#n.isPlaying()}async#s(){for await(let e of this.#n.ticks()){let t=this.currentTime,n=this.#r>=0?await this.playVisualSampler?.next(t)??[]:await this.reversePlayVisualSampler?.next(t)??[];(await this.driver.composite(n)).close(),(this.#r>=0?t>=this.duration:t<=0)&&this.pause()}}async seek(e){return this.pause(),this.#e=e,await this.seekVisualSampler.sample(this.timeline,e)}async start(){this.#n.isPlaying()||(await this.audioContext.resume(),this.#e=this.currentTime,this.#t=this.audioContext.currentTime,this.#i(),this.playVisualSampler=new Ft(this.driver,this.resolveMedia,this.timeline),this.reversePlayVisualSampler=new mo(this.driver,this.resolveMedia,this.timeline),this.#n.play(),this.audioLevels.start(),this.#a())}pause(){this.#e=this.currentTime,this.#n.pause(),this.audioLevels.stop(),this.#i(),this.playVisualSampler&&(this.playVisualSampler.cancel(),this.playVisualSampler=null),this.reversePlayVisualSampler&&(this.reversePlayVisualSampler.cancel(),this.reversePlayVisualSampler=null)}get duration(){return Ae(this.timeline.rootId,this.timeline)}get currentTime(){if(!this.#n.isPlaying()||this.#t===null)return this.#e;let e=(this.audioContext.currentTime-this.#t)*1e3,t=this.#e+e*this.#r;return $(Math.max(0,Math.min(this.duration,t)))}get playbackRate(){return this.#r}set playbackRate(e){if(!Number.isFinite(e)||e===0)throw new Error(`Invalid playback rate "${e}".`);this.#e=this.currentTime,this.#t=this.#n.isPlaying()?this.audioContext.currentTime:null;let t=this.#r<0;this.#r=e,this.#n.isPlaying()&&(t&&e>0?(this.playVisualSampler?.cancel(),this.playVisualSampler=new Ft(this.driver,this.resolveMedia,this.timeline)):!t&&e<0&&(this.reversePlayVisualSampler?.cancel(),this.reversePlayVisualSampler=new mo(this.driver,this.resolveMedia,this.timeline)),this.#c())}setFps(e){this.#n.setFPS(e)}#c(){this.#i(),this.#a()}#i(){this.#o?.abort(),this.#o=null;for(let[e,t]of this.audioNodes)e.stop(),this.audioLevels.detach(t);this.audioNodes.clear()}async#a(){if(this.#r!==1)return;let e=ao(this.#e/1e3);this.#o=new AbortController;let t=this.#o.signal,n=this.audioContext;if(this.#t!==null)for await(let{itemId:o,sample:i,timestamp:s,gain:a}of this.audioSampler.sampleAudio(this.timeline,$(e*1e3))){if(t.aborted||!this.#n.isPlaying())return;for(;s-(n.currentTime-this.#t+e)>.75;)await new Promise(l=>setTimeout(l,25));let c=n.createBufferSource(),u=n.createGain();c.buffer=i.toAudioBuffer(),u.gain.value=a,c.connect(u),u.connect(this.audioGain),c.onended=()=>{this.audioNodes.delete(c),this.audioLevels.detach(u)},this.audioNodes.set(c,u),this.audioLevels.attach(o,u);let f=this.#t+s-e;f>=n.currentTime?c.start(f):c.start(n.currentTime,n.currentTime-f)}}};var qi=class{driver;canvas;playback;audio;#e=null;#t=null;constructor(e,t,n){this.driver=e,this.playback=new Li(e,n,t),this.audio={levels:this.playback.audioLevels},this.canvas=e.compositor.pixi.renderer.canvas}async play(){await this.playback.start()}pause(){this.playback.pause()}seek(e){return this.#e=e,this.#t??=this.#r().finally(()=>this.#t=null)}setFPS(e){this.playback.setFps(Gt(e))}resize(e,t){this.driver.resize(e,t)}get isSeeking(){return this.#t!==null}get isPlaying(){return this.playback.isPlaying}get duration(){return this.playback.duration}get currentTime(){return this.playback.currentTime}get playbackRate(){return this.playback.playbackRate}set playbackRate(e){this.playback.playbackRate=e}async update(e){this.playback.update(e),this.isPlaying||await this.seek(this.currentTime)}async#r(){for(;this.#e!==null;){let e=this.#e;this.#e=null;let t=await this.playback.seek($(e));(await this.driver.composite(t)).close()}}};var It=class{#e;#t;constructor(e={}){this.#e=e.chunkFrames??1024,this.#t=e.clamp??!0}async*mix(e){let t=this.#e,n=null,o=null,i=[],s=0,a=0;for await(let c of e){if(o===null)o=c.planes.length,n=c.sampleRate;else{if(c.planes.length!==o)throw new Error("Channel count changed");if(c.sampleRate!==n)throw new Error("Sample rate changed")}let u=Math.round(c.timestamp*n),f=c.planes[0]?.length??0;for(;s+t<=u;)yield this.#r(i,s,o,n),s+=t;i.push({startFrame:u,endFrame:u+f,data:c.planes}),a=Math.max(a,u+f)}if(o!==null&&n!==null)for(;s<a;)yield this.#r(i,s,o,n),s+=t}#r(e,t,n,o){let i=this.#e,s=new Float32Array(n*i),a=t+i;for(let c=0;c<n;c++){let u=c*i,f=s.subarray(u,u+i);for(let l of e){let m=l.data[c];if(!m)continue;let g=Math.max(t,l.startFrame),d=Math.min(a,l.endFrame);if(g>=d)continue;let p=g-t,A=g-l.startFrame,C=d-g;for(let I=0;I<C;I++)f[p+I]+=m[A+I]}if(this.#t)for(let l=0;l<i;l++){let m=f[l];f[l]=m<-1?-1:m>1?1:m}}for(let c=e.length-1;c>=0;c--)e[c].endFrame<=a&&e.splice(c,1);return{planar:s,sampleRate:o,channels:n,frames:i,startFrame:t}}};var sh=(r,e,t)=>{if(e===t)return r;let n=t/e,o=Math.max(1,Math.round(r.length*n)),i=new Float32Array(o);for(let s=0;s<o;s++){let a=s/n,c=Math.floor(a),u=Math.min(c+1,r.length-1),f=a-c;i[s]=r[c]*(1-f)+r[u]*f}return i},Ct=(r,e)=>{let t=r.numberOfChannels,n=new Array(t),o=0;for(let i=0;i<t;i++){let s=new Float32Array(r.numberOfFrames);r.copyTo(s,{planeIndex:i,format:"f32-planar"});let a=sh(s,r.sampleRate,e);n[i]=a,o=a.length}return{data:n,frames:o}};var un=(r,e)=>{if(e!==1)for(let t of r)for(let n=0;n<t.length;n++)t[n]*=e};function Vi({timeline:r,resolveMedia:e}){let t=new It,n=ah(r,e),o=new TransformStream,i=o.writable.getWriter();async function s(){for await(let a of t.mix(n)){let c=new AudioData({format:"f32-planar",sampleRate:a.sampleRate,numberOfFrames:a.frames,numberOfChannels:a.channels,timestamp:Math.round(a.startFrame/a.sampleRate*1e6),data:new Float32Array(a.planar)});await i.write(c)}await i.close()}return s(),o.readable}async function*ah(r,e){let t=Oi(e);for await(let{sample:n,timestamp:o,gain:i}of t.sampleAudio(r,$(0))){let{data:s}=Ct(n,48e3);un(s,i),yield{planes:s,sampleRate:48e3,timestamp:o},n.close()}}function Ki({timeline:r,fps:e,driver:t,resolveMedia:n}){let o=new TransformStream,i=o.writable.getWriter(),s=new Ft(t,n,r),a=1/e,c=Ae(r.rootId,r);async function u(){await Il({fps:e,duration:c},async(f,l)=>{let m=await s.next(f),g=await t.composite(m),d=new VideoFrame(g,{timestamp:Math.round(l*a*1e6),duration:Math.round(a*1e6)});await i.write(d),g.close()}),await i.close()}return u(),o.readable}function rf(r){let e=Vi({...r}),t=Ki({...r});return r.driver.encode({video:t,audio:e,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}})}var Xt=class{driver;resources=new ki;constructor(e){this.driver=e}load=async e=>Object.fromEntries(await Promise.all(Object.entries(e).map(async([t,n])=>[t,await this.resources.store(await n)])));timeline=e=>{let t=new de({timeline:{format:"timeline",info:"https://omniclip.app/",version:0,items:[],rootId:0}}),n=e(t);return t.timeline.rootId=n.id,t.timeline};playback=async e=>new qi(this.driver,t=>this.resources.require(t).url,e);render=async(e,t=30)=>rf({timeline:e,fps:Gt(t),driver:this.driver,resolveMedia:n=>this.resources.require(n).url})};function nc(r,e){return{error:t=>r.error({...e,...t}),rpcRequest:t=>r.rpcRequest({...e,...t}),rpcError:t=>r.rpcError({...e,...t})}}var Yi=()=>r=>({plain:r.none,errMessage:r.mix(r.brightRed,r.bold),errName:r.red,errStack:r.mix(r.red,r.dim),timestamp:r.blue,timestampErr:r.red});function nf(){return Yi()}var jt=Object.freeze({black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",brightBlack:"\x1B[90m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m",bgBlack:"\x1B[40m",bgRed:"\x1B[41m",bgGreen:"\x1B[42m",bgYellow:"\x1B[43m",bgBlue:"\x1B[44m",bgMagenta:"\x1B[45m",bgCyan:"\x1B[46m",bgWhite:"\x1B[47m",bgBrightBlack:"\x1B[100m",bgBrightRed:"\x1B[101m",bgBrightGreen:"\x1B[102m",bgBrightYellow:"\x1B[103m",bgBrightBlue:"\x1B[104m",bgBrightMagenta:"\x1B[105m",bgBrightCyan:"\x1B[106m",bgBrightWhite:"\x1B[107m",bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",inverse:"\x1B[7m",hidden:"\x1B[8m",strikethrough:"\x1B[9m",reset:"\x1B[0m"});var Ji=()=>({none:r=>r,uncolor:uh,mix:lh,hex:fh,rgb:of,bgRgb:mh});function uh(r){return r.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,"")}function lh(...r){return e=>{for(let t of r)e=t(e);return e}}function fh(r){r=r.replace(/^#/,"");let e,t,n,o;if(r.length===3)e=parseInt(r.split("").map(i=>i+i).join(""),16);else if(r.length===6)e=parseInt(r,16);else throw new Error("Invalid hex color");return t=e>>16&255,n=e>>8&255,o=e&255,of(t,n,o)}function of(r,e,t){let n=`\x1B[38;2;${r};${e};${t}m`;return o=>`${n}${o}${jt.reset}`}function mh(r,e,t){let n=`\x1B[48;2;${r};${e};${t}m`;return o=>`${n}${o}${jt.reset}`}var go={...Object.fromEntries(Object.entries(jt).map(([r])=>[r,e=>e])),...Ji()};var po={...Object.fromEntries(Object.entries(jt).map(([r,e])=>[r,t=>`${e}${t}${jt.reset}`])),...Ji()};function oc(){return typeof Deno<"u"&&typeof Deno.version<"u"}function ic(){return typeof process<"u"&&process.versions&&process.versions.node}function sf(){return ic()?process.env.FORCE_COLOR||process.stdout.isTTY&&process.env.TERM!=="dumb":oc()?Deno.env.get("FORCE_COLOR")||Deno.isatty(Deno.stdout.rid)&&Deno.env.get("TERM")!=="dumb":!1}var sc=()=>sf()?po:go;var Wi=()=>({colors:r,theme:e})=>{let t=e(r);function n(s){let a=s.stack?`
2865
+ }`;var Ul=class Hl extends P{constructor(e={}){e={...Hl.defaultOptions,...e};let t=M.from({vertex:{source:ja,entryPoint:"mainVertex"},fragment:{source:ja,entryPoint:"mainFragment"}}),n=F.from({vertex:Hr,fragment:_l,name:"noise-filter"}),{noise:o,seed:i,...s}=e;super({...s,gpuProgram:t,glProgram:n,resources:{noiseUniforms:new Ur({uNoise:{value:1,type:"f32"},uSeed:{value:1,type:"f32"}})}}),this.noise=o,this.seed=i??Math.random()}get noise(){return this.resources.noiseUniforms.uniforms.uNoise}set noise(e){this.resources.noiseUniforms.uniforms.uNoise=e}get seed(){return this.resources.noiseUniforms.uniforms.uSeed}set seed(e){this.resources.noiseUniforms.uniforms.uSeed=e}};Ul.defaultOptions={noise:.5};var Za=Ul;var _i=class extends Mc{constructor(e,t){let{text:n,resolution:o,style:i,anchor:s,width:a,height:c,roundPixels:u,...f}=e;super({...f}),this.batched=!0,this._resolution=null,this._autoResolution=!0,this._didTextUpdate=!0,this._styleClass=t,this.text=n??"",this.style=i,this.resolution=o??null,this.allowChildren=!1,this._anchor=new Qn({_onUpdate:()=>{this.onViewUpdate()}}),s&&(this.anchor=s),this.roundPixels=u??!1,a!==void 0&&(this.width=a),c!==void 0&&(this.height=c)}get anchor(){return this._anchor}set anchor(e){typeof e=="number"?this._anchor.set(e):this._anchor.copyFrom(e)}set text(e){e=e.toString(),this._text!==e&&(this._text=e,this.onViewUpdate())}get text(){return this._text}set resolution(e){this._autoResolution=e===null,this._resolution=e,this.onViewUpdate()}get resolution(){return this._resolution}get style(){return this._style}set style(e){e||(e={}),this._style?.off("update",this.onViewUpdate,this),e instanceof this._styleClass?this._style=e:this._style=new this._styleClass(e),this._style.on("update",this.onViewUpdate,this),this.onViewUpdate()}get width(){return Math.abs(this.scale.x)*this.bounds.width}set width(e){this._setWidth(e,this.bounds.width)}get height(){return Math.abs(this.scale.y)*this.bounds.height}set height(e){this._setHeight(e,this.bounds.height)}getSize(e){return e||(e={}),e.width=Math.abs(this.scale.x)*this.bounds.width,e.height=Math.abs(this.scale.y)*this.bounds.height,e}setSize(e,t){typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,this.bounds.width),t!==void 0&&this._setHeight(t,this.bounds.height)}containsPoint(e){let t=this.bounds.width,n=this.bounds.height,o=-t*this.anchor.x,i=0;return e.x>=o&&e.x<=o+t&&(i=-n*this.anchor.y,e.y>=i&&e.y<=i+n)}onViewUpdate(){this.didViewUpdate||(this._didTextUpdate=!0),super.onViewUpdate()}destroy(e=!1){super.destroy(e),this.owner=null,this._bounds=null,this._anchor=null,(typeof e=="boolean"?e:e?.style)&&this._style.destroy(e),this._style=null,this._text=null}get styleKey(){return`${this._text}:${this._style.styleKey}:${this._resolution}`}};function Rl(r,e){let t=r[0]??{};return(typeof t=="string"||r[1])&&(X(kn,`use new ${e}({ text: "hi!", style }) instead`),t={text:t,style:r[1]}),t}var uo=class extends _i{constructor(...e){let t=Rl(e,"Text");super(t,_c),this.renderPipeId="text",t.textureStyle&&(this.textureStyle=t.textureStyle instanceof Ps?t.textureStyle:new Ps(t.textureStyle))}updateBounds(){let e=this._bounds,t=this._anchor,n=0,o=0;if(this._style.trim){let{frame:i,canvasAndContext:s}=_s.getCanvasAndContext({text:this.text,style:this._style,resolution:1});_s.returnCanvasAndContext(s),n=i.width,o=i.height}else{let i=Uc.measureText(this._text,this._style);n=i.width,o=i.height}e.minX=-t._x*n,e.maxX=e.minX+n,e.minY=-t._y*o,e.maxY=e.minY+o}};Fc.add(Cl,xl);var $a=r=>{let[e,t,n]=r,[o,i]=e,[s,a]=t,c=n*Math.PI/180,u=Math.cos(c),f=Math.sin(c);return[u*s,f*s,-f*a,u*a,o,i]},Gl=([r,e,t,n,o,i])=>new Ts(r,e,t,n,o,i);var ec=(r,e)=>{let[t,n,o,i,s,a]=r,[c,u,f,l,m,g]=e;return[t*c+o*u,n*c+i*u,t*f+o*l,n*f+i*l,t*m+o*g+s,n*m+i*g+a]};var zl=[1,0,0,1,0,0];var tc=class{keys;index;constructor(e,t){this.keys=e,this.index=t}near(e){return this.keys[Math.max(0,Math.min(this.keys.length-1,this.index+e))][1]}},Nl=r=>r,lo=r=>Nl((e,t)=>r(e,t.near(0),t.near(1))),fo=(r,e,t)=>e+(t-e)*r,rh={linear:lo(fo),ease:lo((r,e,t)=>{let n=r<.5?4*r*r*r:1-Math.pow(-2*r+2,3)/2;return fo(n,e,t)}),easeIn:lo((r,e,t)=>fo(r*r*r,e,t)),easeOut:lo((r,e,t)=>fo(1-Math.pow(1-r,3),e,t)),bounce:lo((r,e,t)=>{let i=r<.36363636363636365?7.5625*r*r:r<.7272727272727273?7.5625*(r-.5454545454545454)**2+.75:r<.9090909090909091?7.5625*(r-.8181818181818182)**2+.9375:7.5625*(r-.9545454545454546)**2+.984375;return fo(i,e,t)}),catmullRom:Nl((r,e)=>{let t=e.near(-1),n=e.near(0),o=e.near(1),i=e.near(2),s=r*r,a=s*r;return .5*(2*n+(-t+o)*r+(2*t-5*n+4*o-i)*s+(-t+3*n-3*o+i)*a)})},Ol=(r,e,t,n)=>{let o=rh[r];if(!o)throw new Error(`unknown terp "${r}"`);return o(e,new tc(t,n))};var an=(r,e,t,n=0)=>{if(e.length===0)return n;if(e.length===1)return e[0][1];let o=[...e].sort((l,m)=>l[0]-m[0]);if(r<=o[0][0])return o[0][1];let i=o[o.length-1];if(r>=i[0])return i[1];let s=0;for(let l=0;l<o.length-1;l++){let m=o[l],g=o[l+1];if(r>=m[0]&&r<=g[0]){s=l;break}}let[a]=o[s],[c]=o[s+1],u=c-a,f=u===0?0:(r-a)/u;return Ol(t,f,o,s)},Ui=(r,e)=>[[an(r,e.track.position.x,e.terp),an(r,e.track.position.y,e.terp)],[an(r,e.track.scale.x,e.terp,1),an(r,e.track.scale.y,e.terp,1)],an(r,e.track.rotation,e.terp)],Ll=(r,e)=>an(r,e.track,e.terp);function nh(r){return"duration"in r}function Vl(r){let e=[],t=new Map(r.timeline.items.map(n=>[n.id,n]));return rc(r.timeline.rootId,t,r.from,{sequence:()=>{},stack:()=>{},video:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),image:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),text:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),caption:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),audio:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i})}),e}function Kl(r,e,t,n){let o=zl;for(let i of e)o=ql(r,i.item,o,i.localTime);return ql(r,t,o,n)}function ql(r,e,t,n){let o=t;if("spatialId"in e&&e.spatialId){let i=r.get(e.spatialId);if(i&&i.enabled!==!1){let s=$a(i.transform);o=ec(s,o)}}if("animationIds"in e&&e.animationIds)for(let i of e.animationIds){let s=r.get(i),a=s?.anims.transform;if(s?.enabled!==!1&&a&&oh(a,n)){let c=$a(Ui(n,a));o=ec(c,o)}}return o}function rc(r,e,t,n,o=[]){let i=e.get(r);if(i)switch(i.kind){case Z.Stack:n.stack(i,t,o);for(let s of i.childrenIds)rc(s,e,t,n,[...o,{item:i,localTime:t}]);break;case Z.Sequence:{n.sequence(i,t,o);let s=$(0);for(let a of i.childrenIds){let c=e.get(a);if(!c)continue;let u=Hi(c.id,e);if(u<=0)continue;let f=$(s+u);if(t>=f){s=f;continue}let l=$(Math.max(0,t-s));rc(a,e,l,n,[...o,{item:i,localTime:t}]),s=f}break}case Z.Video:n.video(i,t,o);break;case Z.Image:n.image(i,t,o);break;case Z.Text:n.text(i,t,o);break;case Z.Caption:n.caption(i,t,o);break;case Z.Audio:n.audio(i,t,o);break}}function Ae(r,e){return Hi(r,new Map(e.items.map(t=>[t.id,t])))}function Hi(r,e){let t=e.get(r);if(!t)return $(0);switch(t.kind){case Z.Sequence:{let n=$(0);for(let o of t.childrenIds)n=$(n+Hi(o,e));return n}case Z.Stack:{let n=$(0);for(let o of t.childrenIds){let i=Hi(o,e);i>n&&(n=i)}return n}default:return nh(t)?t.duration:$(0)}}function Yl(r,e,t){if(!("animationIds"in e)||e.animationIds===void 0)return 1;let n=1;for(let o of e.animationIds){let i=r.items.get(o),s=i?.anims.opacity;i?.enabled!==!1&&s&&cn(s.track,t)&&(n=Ll(t,s))}return n}function cn(r,e){if(r.length===0)return!1;let t=r[0][0],n=r[0][0];for(let[o]of r)t=Math.min(t,o),n=Math.max(n,o);return e>=t&&e<=n}function oh(r,e){return cn(r.track.position.x,e)||cn(r.track.position.y,e)||cn(r.track.scale.x,e)||cn(r.track.scale.y,e)||cn(r.track.rotation,e)}var Ri=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let n=new Ne({formats:Je,source:await tt(this.resolveMedia(e))}),o=await n.getPrimaryVideoTrack(),s=!!o&&await o.canDecode()&&o?new pr(o):null;return this.#e.set(e,{input:n,sink:s}),s}};var Gi=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getFrame(e,t){let n=await this.#t(e);return new VideoFrame(n.bitmap,{timestamp:Math.round(t*1e3)})}async#t(e){let t=this.#e.get(e);if(t)return t;let n=this.resolveMedia(e),o=n instanceof Blob?n:await fetch(n).then(s=>s.blob()),i={bitmap:await createImageBitmap(o)};return this.#e.set(e,i),i}disposeAll(){for(let e of this.#e.values())e.bitmap.close();this.#e.clear()}dispose(e){this.#e.get(e)?.bitmap.close(),this.#e.delete(e)}};async function Jl(r,e,t,n){let[o,i]=await Promise.all([t,n]),s=o.find(u=>u.kind==="image")?.frame,a=i.find(u=>u.kind==="image")?.frame,c=[...o.filter(u=>u.kind!=="image"),...i.filter(u=>u.kind!=="image")];return s&&a?[{id:r.id,kind:"transition",name:r.name,progress:e,from:s,to:a},...c]:c}async function Xl(r,e,t,n){let o=ih(r,e,t);if(!o)return[];let i=[...n,{item:e,localTime:t}];return o.isTransitioning?Jl(o.transition,o.progress,Wl(r,o.outgoing,o.outgoingTime,i),Wl(r,o.incoming,o.incomingTime,i)):wr(r,o.item,o.localTime,i)}function ih(r,e,t){let n=e.childrenIds.map(i=>r.items.get(i)).filter(i=>!!i),o=$(0);for(let i=0;i<n.length;i++){let s=n[i],a=Ae(s.id,r.timeline),c=$(o+a);if(a<=0){o=c;continue}if(t<o||t>=c){o=c;continue}let u=$(t-o);if(s.enabled===!1)return{isTransitioning:!1,item:s,localTime:u};if(s.kind!==Z.Transition)return{isTransitioning:!1,item:s,localTime:u};let f=n[i-1],l=n[i+1];if(!(f&&l&&f.kind!==Z.Transition&&l.kind!==Z.Transition))return null;let g=Ae(f.id,r.timeline);return{isTransitioning:!0,incoming:l,outgoing:f,outgoingTime:$(g+u),incomingTime:$(u-a),progress:u/a,transition:s}}return null}async function Wl(r,e,t,n){let o=await wr(r,e,t,n,{allowHandles:!0});if(o.some(a=>a.kind==="image"))return o;let i=Ae(e.id,r.timeline),s=$(Math.max(0,Math.min(t,i>0?i-1:0)));return wr(r,e,s,n)}async function wr(r,e,t,n,o={}){if("enabled"in e&&e.enabled===!1)return e.kind===Z.Gap?[{id:e.id,kind:"gap"}]:[];let i=Kl(r.items,n,e,t),s=Yl(r,e,t),a="spatialId"in e&&e.spatialId?r.items.get(e.spatialId)?.crop:void 0,c="filterIds"in e&&e.filterIds?e.filterIds.map(u=>r.items.get(u)).filter(u=>!!u&&u.enabled!==!1).map(u=>({type:u.type,params:u.params})):void 0;switch(e.kind){case Z.Stack:{let u=[...n,{item:e,localTime:t}];return(await Promise.all(e.childrenIds.map(l=>r.items.get(l)).filter(l=>!!l).map(l=>wr(r,l,t,u,o)))).flat()}case Z.Sequence:return Xl(r,e,t,n);case Z.Video:{if(!o.allowHandles&&(t<0||t>=e.duration))return[];let u=await r.videoSampler(e,t);return u?[{kind:"image",frame:u,matrix:i,alpha:s,crop:a,filters:c,id:e.id}]:[]}case Z.Image:{if(!o.allowHandles&&(t<0||t>=e.duration))return[];let u=await r.imageSampler(e,t);return u?[{kind:"image",frame:u,matrix:i,alpha:s,crop:a,filters:c,id:e.id}]:[]}case Z.Text:{if(!o.allowHandles&&(t<0||t>=e.duration))return[];let u=e.styleId?r.items.get(e.styleId):void 0,f=u?.enabled!==!1?u?.style:void 0;return[{id:e.id,kind:"text",content:e.content,style:f,matrix:i,alpha:s,crop:a,filters:c}]}case Z.Caption:{if(!o.allowHandles&&(t<0||t>=e.duration))return[];let u=e.start+t,f=ea(e.transcript,e).find(g=>{let[d,p]=g.timestamp;return u>=d&&u<p});if(!f)return[];let l=e.styleId?r.items.get(e.styleId):void 0,m=l?.enabled!==!1?l?.style:void 0;return[{id:e.id,kind:"text",content:f.text,style:m,matrix:i,alpha:s,crop:a,filters:c}]}case Z.Gap:return[{id:e.id,kind:"gap"}];default:return[]}}function jl(r){return async(e,t)=>{let n=await r.getSink(e.mediaHash),o=e.start+t,i=await n?.getSample(o/1e3),s=i?.toVideoFrame();return i?.close(),s??void 0}}function Zl(r){return async(e,t)=>await r.getFrame(e.mediaHash,t)}function vr(r,e){let t=new Gi(r),n=new Ri(r),o=Zl(t),i=e??jl(n);return{async sample(s,a){let c=new Map(s.items.map(f=>[f.id,f])),u=c.get(s.rootId);return u?wr({imageSampler:o,videoSampler:i,timeline:s,items:c},u,a,[]):[]}}}var zi=class{driver;resolveMedia;timeline;#e=new Map;#t;constructor(e,t,n){this.driver=e,this.resolveMedia=t,this.timeline=n,this.#t=vr(this.resolveMedia,(o,i)=>{let s=$l($(o.start+i)),a=this.#e.get(o.id);if(!a){let c=this.resolveMedia(o.mediaHash),u=$l($(o.start+o.duration));a=this.createCursor(c,s,u),this.#e.set(o.id,a)}return a.next(s)})}sample(e){return this.#t.sample(this.timeline,e)}async cancel(){await Promise.all([...this.#e.values()].map(e=>e.cancel())),this.#e.clear()}},Ft=class extends zi{#e=-1/0;next(e){if(e<this.#e)throw new Error(`Forward-only cursor regression: ${e}ms < ${this.#e}ms`);return this.#e=e,this.sample(e)}createCursor(e,t,n){let o=this.driver.decodeVideo({source:e,start:t/1e6,end:n/1e6}),i=o.readable.getReader(),s=null,a=null,c=!1,u=async()=>{if(c)return null;let{done:f,value:l}=await i.read();if(f)return c=!0,null;let m=new VideoFrame(l);return l.close(),m};return{async next(f){if(s??=await u(),!!s)for(;;){a??=u();let l=await a;if(!l)return new VideoFrame(s);let m=s.timestamp??-1/0,g=l.timestamp??m;if(g<f){s.close(),s=l,a=null;continue}if(Math.abs(g-f)<Math.abs(m-f)){s.close(),s=l,a=null;continue}return new VideoFrame(s)}},async cancel(){let f=a;a=null,c=!0,(await f?.catch(()=>null))?.close(),s?.close(),s=null,o.cancel()}}}},mo=class extends zi{#e=1/0;next(e){if(e>this.#e)throw new Error(`Reverse-only cursor regression: ${e}ms > ${this.#e}ms`);return this.#e=e,this.sample(e)}createCursor(e,t,n){let s=[],a=1/0,c=-1/0,u=null,f=null,l=null,m=0,g=Promise.resolve(),d=null,p=!1,A=()=>{for(let w of s)w.close();s=[]},C=()=>{m++===0&&(g=new Promise(w=>d=w))},I=()=>{--m===0&&(d?.(),d=null)},v=async()=>{if(f)return f;u=new Ne({source:await tt(e),formats:Je});let w=await u.getPrimaryVideoTrack();return f=w&&await w.canDecode()?new pr(w):null,f},x=async w=>{C();let T=Math.min(n,w+1),y=Math.max(t,T-1e6),Q=[],N=await v();if(N)for await(let O of N.samples(y/1e6,T/1e6))Q.push(O.toVideoFrame()),O.close();return I(),{frames:Q,windowStart:y,windowEnd:T}},S=async w=>{A();let T=await x(w);s=T.frames,a=T.windowStart,c=T.windowEnd};return{async next(w){if(p)return;if(w<a||w>c)if(l){let Q=await l;if(l=null,p){for(let N of Q.frames)N.close();return}if(w>=Q.windowStart&&w<=Q.windowEnd)A(),s=Q.frames,a=Q.windowStart,c=Q.windowEnd;else{for(let N of Q.frames)N.close();await S(w)}}else await S(w);!l&&w<a+5e5&&a>t&&(l=x(a-1));let T,y=1/0;for(let Q of s){let N=Math.abs((Q.timestamp??w)-w);N<y&&(T=Q,y=N)}return T?new VideoFrame(T):void 0},async cancel(){p=!0;let w=l;l=null;let T=await w?.catch(()=>null);if(T)for(let y of T.frames)y.close();await g,A(),u?.dispose(),u=null,f=null}}}},$l=r=>Math.round(r*1e3);async function ef(r,e,t){return(await Promise.all(e.map(async({item:o,localTime:i})=>{if(o.kind!==Z.Audio||o.enabled===!1||i>=o.duration)return;let s=await r.getSink(o.mediaHash);if(!s)return;let a=o.start+i,c=o.start+o.duration,u=ao((t-a)/1e3),f=s.samples(a/1e3,c/1e3),l=await f.next();if(l.done)return;let m=l.value,g=f.next();return{offset:u,gain:o.gain??1,get currentSample(){return m},timelineTime:()=>ao(u+m.timestamp),output:()=>({itemId:o.id,sample:m,timestamp:u+m.timestamp,gain:o.gain??1}),advance:async()=>{let d=await g;return d.done?!1:(m=d.value,g=f.next(),!0)}}}))).filter(o=>!!o)}var Ni=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let n=new Ne({formats:Je,source:await tt(this.resolveMedia(e))}),o=await n.getPrimaryAudioTrack(),s=!!o&&await o.canDecode()&&o?new Xn(o):null;return this.#e.set(e,{input:n,sink:s}),s}};function tf(r){let e={index:0,stream:r[0],time:r[0].timelineTime()};for(let[t,n]of r.entries()){let o=n.timelineTime();o<e.time&&(e={time:o,stream:n,index:t})}return e}function Oi(r){let e=new Ni(r);return{async*sampleAudio(t,n){let o=Vl({timeline:t,from:n}),i=await ef(e,o,n);for(;i.length>0;){let{stream:s,index:a}=tf(i);yield s.output(),await s.advance()||i.splice(a,1)}}}}var Li=class{driver;timeline;resolveMedia;audioLevels;audioSampler;seekVisualSampler;playVisualSampler=null;reversePlayVisualSampler=null;#e=$(0);#t=null;#r=1;#n=Al();onTick=this.#n.onTick;audioContext=new AudioContext({sampleRate:48e3});audioGain=this.audioContext.createGain();audioNodes=new Map;#o=null;constructor(e,t,n){this.driver=e,this.timeline=t,this.resolveMedia=n,this.audioGain.connect(this.audioContext.destination),this.audioGain.gain.value=1,this.audioLevels=new Ti(this.audioContext,()=>this.currentTime,()=>this.#n.isPlaying()),this.seekVisualSampler=vr(this.resolveMedia),this.audioSampler=Oi(this.resolveMedia),this.#s()}update(e){this.timeline=e}get isPlaying(){return this.#n.isPlaying()}async#s(){for await(let e of this.#n.ticks()){let t=this.currentTime,n=this.#r>=0?await this.playVisualSampler?.next(t)??[]:await this.reversePlayVisualSampler?.next(t)??[];(await this.driver.composite(n)).close(),(this.#r>=0?t>=this.duration:t<=0)&&this.pause()}}async seek(e){return this.pause(),this.#e=e,await this.seekVisualSampler.sample(this.timeline,e)}async start(){this.#n.isPlaying()||(await this.audioContext.resume(),this.#e=this.currentTime,this.#t=this.audioContext.currentTime,this.#i(),this.playVisualSampler=new Ft(this.driver,this.resolveMedia,this.timeline),this.reversePlayVisualSampler=new mo(this.driver,this.resolveMedia,this.timeline),this.#n.play(),this.audioLevels.start(),this.#a())}pause(){this.#e=this.currentTime,this.#n.pause(),this.audioLevels.stop(),this.#i(),this.playVisualSampler&&(this.playVisualSampler.cancel(),this.playVisualSampler=null),this.reversePlayVisualSampler&&(this.reversePlayVisualSampler.cancel(),this.reversePlayVisualSampler=null)}get duration(){return Ae(this.timeline.rootId,this.timeline)}get currentTime(){if(!this.#n.isPlaying()||this.#t===null)return this.#e;let e=(this.audioContext.currentTime-this.#t)*1e3,t=this.#e+e*this.#r;return $(Math.max(0,Math.min(this.duration,t)))}get playbackRate(){return this.#r}set playbackRate(e){if(!Number.isFinite(e)||e===0)throw new Error(`Invalid playback rate "${e}".`);this.#e=this.currentTime,this.#t=this.#n.isPlaying()?this.audioContext.currentTime:null;let t=this.#r<0;this.#r=e,this.#n.isPlaying()&&(t&&e>0?(this.playVisualSampler?.cancel(),this.playVisualSampler=new Ft(this.driver,this.resolveMedia,this.timeline)):!t&&e<0&&(this.reversePlayVisualSampler?.cancel(),this.reversePlayVisualSampler=new mo(this.driver,this.resolveMedia,this.timeline)),this.#c())}setFps(e){this.#n.setFPS(e)}#c(){this.#i(),this.#a()}#i(){this.#o?.abort(),this.#o=null;for(let[e,t]of this.audioNodes)e.stop(),this.audioLevels.detach(t);this.audioNodes.clear()}async#a(){if(this.#r!==1)return;let e=ao(this.#e/1e3);this.#o=new AbortController;let t=this.#o.signal,n=this.audioContext;if(this.#t!==null)for await(let{itemId:o,sample:i,timestamp:s,gain:a}of this.audioSampler.sampleAudio(this.timeline,$(e*1e3))){if(t.aborted||!this.#n.isPlaying())return;for(;s-(n.currentTime-this.#t+e)>.75;)await new Promise(l=>setTimeout(l,25));let c=n.createBufferSource(),u=n.createGain();c.buffer=i.toAudioBuffer(),u.gain.value=a,c.connect(u),u.connect(this.audioGain),c.onended=()=>{this.audioNodes.delete(c),this.audioLevels.detach(u)},this.audioNodes.set(c,u),this.audioLevels.attach(o,u);let f=this.#t+s-e;f>=n.currentTime?c.start(f):c.start(n.currentTime,n.currentTime-f)}}};var qi=class{driver;canvas;playback;audio;#e=null;#t=null;constructor(e,t,n){this.driver=e,this.playback=new Li(e,n,t),this.audio={levels:this.playback.audioLevels},this.canvas=e.compositor.pixi.renderer.canvas}async play(){await this.playback.start()}pause(){this.playback.pause()}seek(e){return this.#e=e,this.#t??=this.#r().finally(()=>this.#t=null)}setFPS(e){this.playback.setFps(Gt(e))}resize(e,t){this.driver.resize(e,t)}get isSeeking(){return this.#t!==null}get isPlaying(){return this.playback.isPlaying}get duration(){return this.playback.duration}get currentTime(){return this.playback.currentTime}get playbackRate(){return this.playback.playbackRate}set playbackRate(e){this.playback.playbackRate=e}async update(e){this.playback.update(e),this.isPlaying||await this.seek(this.currentTime)}async#r(){for(;this.#e!==null;){let e=this.#e;this.#e=null;let t=await this.playback.seek($(e));(await this.driver.composite(t)).close()}}};var It=class{#e;#t;constructor(e={}){this.#e=e.chunkFrames??1024,this.#t=e.clamp??!0}async*mix(e){let t=this.#e,n=null,o=null,i=[],s=0,a=0;for await(let c of e){if(o===null)o=c.planes.length,n=c.sampleRate;else{if(c.planes.length!==o)throw new Error("Channel count changed");if(c.sampleRate!==n)throw new Error("Sample rate changed")}let u=Math.round(c.timestamp*n),f=c.planes[0]?.length??0;for(;s+t<=u;)yield this.#r(i,s,o,n),s+=t;i.push({startFrame:u,endFrame:u+f,data:c.planes}),a=Math.max(a,u+f)}if(o!==null&&n!==null)for(;s<a;)yield this.#r(i,s,o,n),s+=t}#r(e,t,n,o){let i=this.#e,s=new Float32Array(n*i),a=t+i;for(let c=0;c<n;c++){let u=c*i,f=s.subarray(u,u+i);for(let l of e){let m=l.data[c];if(!m)continue;let g=Math.max(t,l.startFrame),d=Math.min(a,l.endFrame);if(g>=d)continue;let p=g-t,A=g-l.startFrame,C=d-g;for(let I=0;I<C;I++)f[p+I]+=m[A+I]}if(this.#t)for(let l=0;l<i;l++){let m=f[l];f[l]=m<-1?-1:m>1?1:m}}for(let c=e.length-1;c>=0;c--)e[c].endFrame<=a&&e.splice(c,1);return{planar:s,sampleRate:o,channels:n,frames:i,startFrame:t}}};var sh=(r,e,t)=>{if(e===t)return r;let n=t/e,o=Math.max(1,Math.round(r.length*n)),i=new Float32Array(o);for(let s=0;s<o;s++){let a=s/n,c=Math.floor(a),u=Math.min(c+1,r.length-1),f=a-c;i[s]=r[c]*(1-f)+r[u]*f}return i},Ct=(r,e)=>{let t=r.numberOfChannels,n=new Array(t),o=0;for(let i=0;i<t;i++){let s=new Float32Array(r.numberOfFrames);r.copyTo(s,{planeIndex:i,format:"f32-planar"});let a=sh(s,r.sampleRate,e);n[i]=a,o=a.length}return{data:n,frames:o}};var un=(r,e)=>{if(e!==1)for(let t of r)for(let n=0;n<t.length;n++)t[n]*=e};function Vi({timeline:r,resolveMedia:e}){let t=new It,n=ah(r,e),o=new TransformStream,i=o.writable.getWriter();async function s(){for await(let a of t.mix(n)){let c=new AudioData({format:"f32-planar",sampleRate:a.sampleRate,numberOfFrames:a.frames,numberOfChannels:a.channels,timestamp:Math.round(a.startFrame/a.sampleRate*1e6),data:new Float32Array(a.planar)});await i.write(c)}await i.close()}return s(),o.readable}async function*ah(r,e){let t=Oi(e);for await(let{sample:n,timestamp:o,gain:i}of t.sampleAudio(r,$(0))){let{data:s}=Ct(n,48e3);un(s,i),yield{planes:s,sampleRate:48e3,timestamp:o},n.close()}}function Ki({timeline:r,fps:e,driver:t,resolveMedia:n}){let o=new TransformStream,i=o.writable.getWriter(),s=new Ft(t,n,r),a=1/e,c=Ae(r.rootId,r);async function u(){await Il({fps:e,duration:c},async(f,l)=>{let m=await s.next(f),g=await t.composite(m),d=new VideoFrame(g,{timestamp:Math.round(l*a*1e6),duration:Math.round(a*1e6)});await i.write(d),g.close()}),await i.close()}return u(),o.readable}function rf(r){let e=Vi({...r}),t=Ki({...r});return r.driver.encode({video:t,audio:e,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}})}var Xt=class{driver;resources=new ki;constructor(e){this.driver=e}load=async e=>Object.fromEntries(await Promise.all(Object.entries(e).map(async([t,n])=>[t,await this.resources.store(await n)])));timeline=e=>{let t=new de({timeline:{format:"timeline",info:"https://omniclip.app/",version:0,items:[],rootId:0}}),n=e(t);return t.timeline.rootId=n.id,t.timeline};playback=async e=>new qi(this.driver,t=>this.resources.require(t).url,e);render=async(e,t=30)=>rf({timeline:e,fps:Gt(t),driver:this.driver,resolveMedia:n=>this.resources.require(n).url})};function nc(r,e){return{error:t=>r.error({...e,...t}),rpcRequest:t=>r.rpcRequest({...e,...t}),rpcError:t=>r.rpcError({...e,...t})}}var Yi=()=>r=>({plain:r.none,errMessage:r.mix(r.brightRed,r.bold),errName:r.red,errStack:r.mix(r.red,r.dim),timestamp:r.blue,timestampErr:r.red});function nf(){return Yi()}var jt=Object.freeze({black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",brightBlack:"\x1B[90m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m",bgBlack:"\x1B[40m",bgRed:"\x1B[41m",bgGreen:"\x1B[42m",bgYellow:"\x1B[43m",bgBlue:"\x1B[44m",bgMagenta:"\x1B[45m",bgCyan:"\x1B[46m",bgWhite:"\x1B[47m",bgBrightBlack:"\x1B[100m",bgBrightRed:"\x1B[101m",bgBrightGreen:"\x1B[102m",bgBrightYellow:"\x1B[103m",bgBrightBlue:"\x1B[104m",bgBrightMagenta:"\x1B[105m",bgBrightCyan:"\x1B[106m",bgBrightWhite:"\x1B[107m",bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",inverse:"\x1B[7m",hidden:"\x1B[8m",strikethrough:"\x1B[9m",reset:"\x1B[0m"});var Ji=()=>({none:r=>r,uncolor:uh,mix:lh,hex:fh,rgb:of,bgRgb:mh});function uh(r){return r.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,"")}function lh(...r){return e=>{for(let t of r)e=t(e);return e}}function fh(r){r=r.replace(/^#/,"");let e,t,n,o;if(r.length===3)e=parseInt(r.split("").map(i=>i+i).join(""),16);else if(r.length===6)e=parseInt(r,16);else throw new Error("Invalid hex color");return t=e>>16&255,n=e>>8&255,o=e&255,of(t,n,o)}function of(r,e,t){let n=`\x1B[38;2;${r};${e};${t}m`;return o=>`${n}${o}${jt.reset}`}function mh(r,e,t){let n=`\x1B[48;2;${r};${e};${t}m`;return o=>`${n}${o}${jt.reset}`}var go={...Object.fromEntries(Object.entries(jt).map(([r])=>[r,e=>e])),...Ji()};var po={...Object.fromEntries(Object.entries(jt).map(([r,e])=>[r,t=>`${e}${t}${jt.reset}`])),...Ji()};function oc(){return typeof Deno<"u"&&typeof Deno.version<"u"}function ic(){return typeof process<"u"&&process.versions&&process.versions.node}function sf(){return ic()?process.env.FORCE_COLOR||process.stdout.isTTY&&process.env.TERM!=="dumb":oc()?Deno.env.get("FORCE_COLOR")||Deno.isatty(Deno.stdout.rid)&&Deno.env.get("TERM")!=="dumb":!1}var sc=()=>sf()?po:go;var Wi=()=>({colors:r,theme:e})=>{let t=e(r);function n(s){let a=s.stack?`
2866
2866
  `+s.stack+`
2867
2867
  `:"";return[t.errName(s.name+":"),t.errMessage(s.message)].join(" ")+t.errStack(a)}function o(s){return s&&s instanceof Error?n(s):s}function i(s){return s&&s instanceof Error?n(s):t.errMessage(s)}return{stdout:s=>s.map(o),stderr:s=>s.map(i)}};function ho(...r){return e=>({stdout:t=>{for(let n of r)t=n(e).stdout(t);return t},stderr:t=>{for(let n of r)t=n(e).stderr(t);return t}})}function gh(){return{icon:"\u{1F6A8}",now:()=>Date.now()}}var Xi=r=>({colors:e,theme:t})=>{let n={...gh(),...r},o=t(e),i=new Date(n.now()),s=i.getUTCFullYear().toString().padStart(4,"0"),a=(i.getUTCMonth()+1).toString().padStart(2,"0"),c=i.getUTCDate().toString().padStart(2,"0"),u=`${s}-${a}-${c}`,f=i.getUTCHours().toString().padStart(2,"0"),l=i.getUTCMinutes().toString().padStart(2,"0"),m=i.getUTCSeconds().toString().padStart(2,"0"),g=i.getUTCMilliseconds().toString().padStart(3,"0"),d=`${f}:${l}:${m}.${g}`,p=`${u}::${d}`;return{stdout:A=>[o.timestamp(p),...A],stderr:A=>[o.timestampErr(p),...[n.icon].filter(Boolean),...A]}};function af(){return ho(Wi(),Xi())}var ji=()=>({stdout:async r=>{await Deno.stdout.write(new TextEncoder().encode(r+`
2868
2868
  `))},stderr:async r=>{await Deno.stderr.write(new TextEncoder().encode(r+`