@omnimedia/omnitool 1.1.0-21 → 1.1.0-22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnimedia/omnitool",
3
- "version": "1.1.0-21",
3
+ "version": "1.1.0-22",
4
4
  "description": "open source video processing tools",
5
5
  "license": "MIT",
6
6
  "author": "Przemysław Gałęzki",
@@ -94,6 +94,7 @@ export namespace Item {
94
94
  | Gap
95
95
  | Transition
96
96
  | Spatial
97
+ | TextStyle
97
98
  )
98
99
  }
99
100
 
@@ -10,10 +10,12 @@ export class O {
10
10
 
11
11
  constructor(public state: {project: TimelineFile}) {}
12
12
 
13
- require<T extends Item.Any>(id: Id): T {
13
+ require<T extends Item.Any>(id: Id | undefined) {
14
+ if (id === undefined)
15
+ return undefined
14
16
  const item = this.state.project.items.find(item => item.id === id)
15
- return item as T
16
- }
17
+ return item as T | undefined
18
+ }
17
19
 
18
20
  #getId() {
19
21
  return this.#nextId++
@@ -644,7 +644,7 @@ fn mainFragment(
644
644
  <div class="cursor" part="cursor"></div>
645
645
  </div>
646
646
  </div>
647
- `,[e,t]}setOptions(e){if(this.options.container!==e.container){let t=this.parentFromOptionsContainer(e.container);t.appendChild(this.container),this.parent=t}e.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.options=e,this.reRender()}getWrapper(){return this.wrapper}getWidth(){return this.scrollContainer.clientWidth}getScroll(){return this.scrollContainer.scrollLeft}setScroll(e){this.scrollContainer.scrollLeft=e}setScrollPercentage(e){let{scrollWidth:t}=this.scrollContainer,r=t*e;this.setScroll(r)}destroy(){var e,t;this.subscriptions.forEach(r=>r()),this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.unsubscribeOnScroll)===null||t===void 0||t.forEach(r=>r()),this.unsubscribeOnScroll=[]}createDelay(e=10){let t,r,s=()=>{t&&clearTimeout(t),r&&r()};return this.timeouts.push(s),()=>new Promise((n,o)=>{s(),r=o,t=setTimeout(()=>{t=void 0,r=void 0,n()},e)})}convertColorValues(e){if(!Array.isArray(e))return e||"";if(e.length<2)return e[0]||"";let t=document.createElement("canvas"),r=t.getContext("2d"),s=t.height*(window.devicePixelRatio||1),n=r.createLinearGradient(0,0,0,s),o=1/(e.length-1);return e.forEach((a,c)=>{let l=c*o;n.addColorStop(l,a)}),n}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(e,t,r,s){let n=e[0],o=e[1]||e[0],a=n.length,{width:c,height:l}=r.canvas,u=l/2,h=this.getPixelRatio(),d=t.barWidth?t.barWidth*h:1,f=t.barGap?t.barGap*h:t.barWidth?d/2:0,m=t.barRadius||0,p=c/(d+f)/a,g=m&&"roundRect"in r?"roundRect":"rect";r.beginPath();let y=0,x=0,w=0;for(let _=0;_<=a;_++){let S=Math.round(_*p);if(S>y){let M=Math.round(x*u*s),P=M+Math.round(w*u*s)||1,C=u-M;t.barAlign==="top"?C=0:t.barAlign==="bottom"&&(C=l-P),r[g](y*(d+f),C,d,P,m),y=S,x=0,w=0}let T=Math.abs(n[_]||0),v=Math.abs(o[_]||0);T>x&&(x=T),v>w&&(w=v)}r.fill(),r.closePath()}renderLineWaveform(e,t,r,s){let n=o=>{let a=e[o]||e[0],c=a.length,{height:l}=r.canvas,u=l/2,h=r.canvas.width/c;r.moveTo(0,u);let d=0,f=0;for(let m=0;m<=c;m++){let p=Math.round(m*h);if(p>d){let y=u+(Math.round(f*u*s)||1)*(o===0?-1:1);r.lineTo(d,y),d=p,f=0}let g=Math.abs(a[m]||0);g>f&&(f=g)}r.lineTo(d,u)};r.beginPath(),n(0),n(1),r.fill(),r.closePath()}renderWaveform(e,t,r){if(r.fillStyle=this.convertColorValues(t.waveColor),t.renderFunction)return void t.renderFunction(e,r);let s=t.barHeight||1;if(t.normalize){let n=Array.from(e[0]).reduce((o,a)=>Math.max(o,Math.abs(a)),0);s=n?1/n:1}t.barWidth||t.barGap||t.barAlign?this.renderBarWaveform(e,t,r,s):this.renderLineWaveform(e,t,r,s)}renderSingleCanvas(e,t,r,s,n,o,a){let c=this.getPixelRatio(),l=document.createElement("canvas");l.width=Math.round(r*c),l.height=Math.round(s*c),l.style.width=`${r}px`,l.style.height=`${s}px`,l.style.left=`${Math.round(n)}px`,o.appendChild(l);let u=l.getContext("2d");if(this.renderWaveform(e,t,u),l.width>0&&l.height>0){let h=l.cloneNode(),d=h.getContext("2d");d.drawImage(l,0,0),d.globalCompositeOperation="source-in",d.fillStyle=this.convertColorValues(t.progressColor),d.fillRect(0,0,l.width,l.height),a.appendChild(h)}}renderMultiCanvas(e,t,r,s,n,o){let a=this.getPixelRatio(),{clientWidth:c}=this.scrollContainer,l=r/a,u=Math.min(i.MAX_CANVAS_WIDTH,c,l),h={};if(t.barWidth||t.barGap){let g=t.barWidth||.5,y=g+(t.barGap||g/2);u%y!=0&&(u=Math.floor(u/y)*y)}if(u===0)return;let d=g=>{if(g<0||g>=f||h[g])return;h[g]=!0;let y=g*u,x=Math.min(l-y,u);if(t.barWidth||t.barGap){let _=t.barWidth||.5,S=_+(t.barGap||_/2);x=Math.floor(x/S)*S}if(x<=0)return;let w=e.map(_=>{let S=Math.floor(y/l*_.length),T=Math.floor((y+x)/l*_.length);return _.slice(S,T)});this.renderSingleCanvas(w,t,x,s,y,n,o)},f=Math.ceil(l/u);if(!this.isScrollable){for(let g=0;g<f;g++)d(g);return}let m=this.scrollContainer.scrollLeft/l,p=Math.floor(m*f);if(d(p-1),d(p),d(p+1),f>1){let g=this.on("scroll",()=>{let{scrollLeft:y}=this.scrollContainer,x=Math.floor(y/l*f);Object.keys(h).length>i.MAX_NODES&&(n.innerHTML="",o.innerHTML="",h={}),d(x-1),d(x),d(x+1)});this.unsubscribeOnScroll.push(g)}}renderChannel(e,t,r,s){var{overlay:n}=t,o=function(u,h){var d={};for(var f in u)Object.prototype.hasOwnProperty.call(u,f)&&h.indexOf(f)<0&&(d[f]=u[f]);if(u!=null&&typeof Object.getOwnPropertySymbols=="function"){var m=0;for(f=Object.getOwnPropertySymbols(u);m<f.length;m++)h.indexOf(f[m])<0&&Object.prototype.propertyIsEnumerable.call(u,f[m])&&(d[f[m]]=u[f[m]])}return d}(t,["overlay"]);let a=document.createElement("div"),c=this.getHeight(o.height,o.splitChannels);a.style.height=`${c}px`,n&&s>0&&(a.style.marginTop=`-${c}px`),this.canvasWrapper.style.minHeight=`${c}px`,this.canvasWrapper.appendChild(a);let l=a.cloneNode();this.progressWrapper.appendChild(l),this.renderMultiCanvas(e,o,r,c,a,l)}render(e){return Se(this,void 0,void 0,function*(){var t;this.timeouts.forEach(c=>c()),this.timeouts=[],this.canvasWrapper.innerHTML="",this.progressWrapper.innerHTML="",this.options.width!=null&&(this.scrollContainer.style.width=typeof this.options.width=="number"?`${this.options.width}px`:this.options.width);let r=this.getPixelRatio(),s=this.scrollContainer.clientWidth,n=Math.ceil(e.duration*(this.options.minPxPerSec||0));this.isScrollable=n>s;let o=this.options.fillParent&&!this.isScrollable,a=(o?s:n)*r;if(this.wrapper.style.width=o?"100%":`${n}px`,this.scrollContainer.style.overflowX=this.isScrollable?"auto":"hidden",this.scrollContainer.classList.toggle("noScrollbar",!!this.options.hideScrollbar),this.cursor.style.backgroundColor=`${this.options.cursorColor||this.options.progressColor}`,this.cursor.style.width=`${this.options.cursorWidth}px`,this.audioData=e,this.emit("render"),this.options.splitChannels)for(let c=0;c<e.numberOfChannels;c++){let l=Object.assign(Object.assign({},this.options),(t=this.options.splitChannels)===null||t===void 0?void 0:t[c]);this.renderChannel([e.getChannelData(c)],l,a,c)}else{let c=[e.getChannelData(0)];e.numberOfChannels>1&&c.push(e.getChannelData(1)),this.renderChannel(c,this.options,a,0)}Promise.resolve().then(()=>this.emit("rendered"))})}reRender(){if(this.unsubscribeOnScroll.forEach(r=>r()),this.unsubscribeOnScroll=[],!this.audioData)return;let{scrollWidth:e}=this.scrollContainer,{right:t}=this.progressWrapper.getBoundingClientRect();if(this.render(this.audioData),this.isScrollable&&e!==this.scrollContainer.scrollWidth){let{right:r}=this.progressWrapper.getBoundingClientRect(),s=r-t;s*=2,s=s<0?Math.floor(s):Math.ceil(s),s/=2,this.scrollContainer.scrollLeft+=s}}zoom(e){this.options.minPxPerSec=e,this.reRender()}scrollIntoView(e,t=!1){let{scrollLeft:r,scrollWidth:s,clientWidth:n}=this.scrollContainer,o=e*s,a=r,c=r+n,l=n/2;if(this.isDragging)o+30>c?this.scrollContainer.scrollLeft+=30:o-30<a&&(this.scrollContainer.scrollLeft-=30);else{(o<a||o>c)&&(this.scrollContainer.scrollLeft=o-(this.options.autoCenter?l:0));let u=o-r-l;t&&this.options.autoCenter&&u>0&&(this.scrollContainer.scrollLeft+=Math.min(u,10))}{let u=this.scrollContainer.scrollLeft,h=u/s,d=(u+n)/s;this.emit("scroll",h,d,u,u+n)}}renderProgress(e,t){if(isNaN(e))return;let r=100*e;this.canvasWrapper.style.clipPath=`polygon(${r}% 0%, 100% 0%, 100% 100%, ${r}% 100%)`,this.progressWrapper.style.width=`${r}%`,this.cursor.style.left=`${r}%`,this.cursor.style.transform=`translateX(-${Math.round(r)===100?this.options.cursorWidth:0}px)`,this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(e,t)}exportImage(e,t,r){return Se(this,void 0,void 0,function*(){let s=this.canvasWrapper.querySelectorAll("canvas");if(!s.length)throw new Error("No waveform data");if(r==="dataURL"){let n=Array.from(s).map(o=>o.toDataURL(e,t));return Promise.resolve(n)}return Promise.all(Array.from(s).map(n=>new Promise((o,a)=>{n.toBlob(c=>{c?o(c):a(new Error("Could not export image"))},e,t)})))})}};zs.MAX_CANVAS_WIDTH=8e3,zs.MAX_NODES=10;var Ql=class extends Lr{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}},Us=class extends Lr{constructor(e=new AudioContext){super(),this.bufferNode=null,this.playStartTime=0,this.playedDuration=0,this._muted=!1,this._playbackRate=1,this._duration=void 0,this.buffer=null,this.currentSrc="",this.paused=!0,this.crossOrigin=null,this.seeking=!1,this.autoplay=!1,this.addEventListener=this.on,this.removeEventListener=this.un,this.audioContext=e,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}load(){return Se(this,void 0,void 0,function*(){})}get src(){return this.currentSrc}set src(e){if(this.currentSrc=e,this._duration=void 0,!e)return this.buffer=null,void this.emit("emptied");fetch(e).then(t=>{if(t.status>=400)throw new Error(`Failed to fetch ${e}: ${t.status} (${t.statusText})`);return t.arrayBuffer()}).then(t=>this.currentSrc!==e?null:this.audioContext.decodeAudioData(t)).then(t=>{this.currentSrc===e&&(this.buffer=t,this.emit("loadedmetadata"),this.emit("canplay"),this.autoplay&&this.play())})}_play(){var e;if(!this.paused)return;this.paused=!1,(e=this.bufferNode)===null||e===void 0||e.disconnect(),this.bufferNode=this.audioContext.createBufferSource(),this.buffer&&(this.bufferNode.buffer=this.buffer),this.bufferNode.playbackRate.value=this._playbackRate,this.bufferNode.connect(this.gainNode);let t=this.playedDuration*this._playbackRate;(t>=this.duration||t<0)&&(t=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,t),this.playStartTime=this.audioContext.currentTime,this.bufferNode.onended=()=>{this.currentTime>=this.duration&&(this.pause(),this.emit("ended"))}}_pause(){var e;this.paused=!0,(e=this.bufferNode)===null||e===void 0||e.stop(),this.playedDuration+=this.audioContext.currentTime-this.playStartTime}play(){return Se(this,void 0,void 0,function*(){this.paused&&(this._play(),this.emit("play"))})}pause(){this.paused||(this._pause(),this.emit("pause"))}stopAt(e){let t=e-this.currentTime,r=this.bufferNode;r?.stop(this.audioContext.currentTime+t),r?.addEventListener("ended",()=>{r===this.bufferNode&&(this.bufferNode=null,this.pause())},{once:!0})}setSinkId(e){return Se(this,void 0,void 0,function*(){return this.audioContext.setSinkId(e)})}get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate=e,this.bufferNode&&(this.bufferNode.playbackRate.value=e)}get currentTime(){return(this.paused?this.playedDuration:this.playedDuration+(this.audioContext.currentTime-this.playStartTime))*this._playbackRate}set currentTime(e){let t=!this.paused;t&&this._pause(),this.playedDuration=e/this._playbackRate,t&&this._play(),this.emit("seeking"),this.emit("timeupdate")}get duration(){var e,t;return(e=this._duration)!==null&&e!==void 0?e:((t=this.buffer)===null||t===void 0?void 0:t.duration)||0}set duration(e){this._duration=e}get volume(){return this.gainNode.gain.value}set volume(e){this.gainNode.gain.value=e,this.emit("volumechange")}get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this._muted?this.gainNode.disconnect():this.gainNode.connect(this.audioContext.destination))}canPlayType(e){return/^(audio|video)\//.test(e)}getGainNode(){return this.gainNode}getChannelData(){let e=[];if(!this.buffer)return e;let t=this.buffer.numberOfChannels;for(let r=0;r<t;r++)e.push(this.buffer.getChannelData(r));return e}},cS={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3},Ei=class i extends Zl{static create(e){return new i(e)}constructor(e){let t=e.media||(e.backend==="WebAudio"?new Us:void 0);super({media:t,mediaControls:e.mediaControls,autoplay:e.autoplay,playbackRate:e.audioRate}),this.plugins=[],this.decodedData=null,this.stopAtPosition=null,this.subscriptions=[],this.mediaSubscriptions=[],this.abortController=null,this.options=Object.assign({},cS,e),this.timer=new Ql;let r=t?void 0:this.getMediaElement();this.renderer=new zs(this.options,r),this.initPlayerEvents(),this.initRendererEvents(),this.initTimerEvents(),this.initPlugins();let s=this.options.url||this.getSrc()||"";Promise.resolve().then(()=>{this.emit("init");let{peaks:n,duration:o}=this.options;(s||n&&o)&&this.load(s,n,o).catch(()=>null)})}updateProgress(e=this.getCurrentTime()){return this.renderer.renderProgress(e/this.getDuration(),this.isPlaying()),e}initTimerEvents(){this.subscriptions.push(this.timer.on("tick",()=>{if(!this.isSeeking()){let e=this.updateProgress();this.emit("timeupdate",e),this.emit("audioprocess",e),this.stopAtPosition!=null&&this.isPlaying()&&e>=this.stopAtPosition&&this.pause()}}))}initPlayerEvents(){this.isPlaying()&&(this.emit("play"),this.timer.start()),this.mediaSubscriptions.push(this.onMediaEvent("timeupdate",()=>{let e=this.updateProgress();this.emit("timeupdate",e)}),this.onMediaEvent("play",()=>{this.emit("play"),this.timer.start()}),this.onMediaEvent("pause",()=>{this.emit("pause"),this.timer.stop(),this.stopAtPosition=null}),this.onMediaEvent("emptied",()=>{this.timer.stop(),this.stopAtPosition=null}),this.onMediaEvent("ended",()=>{this.emit("timeupdate",this.getDuration()),this.emit("finish"),this.stopAtPosition=null}),this.onMediaEvent("seeking",()=>{this.emit("seeking",this.getCurrentTime())}),this.onMediaEvent("error",()=>{var e;this.emit("error",(e=this.getMediaElement().error)!==null&&e!==void 0?e:new Error("Media error")),this.stopAtPosition=null}))}initRendererEvents(){this.subscriptions.push(this.renderer.on("click",(e,t)=>{this.options.interact&&(this.seekTo(e),this.emit("interaction",e*this.getDuration()),this.emit("click",e,t))}),this.renderer.on("dblclick",(e,t)=>{this.emit("dblclick",e,t)}),this.renderer.on("scroll",(e,t,r,s)=>{let n=this.getDuration();this.emit("scroll",e*n,t*n,r,s)}),this.renderer.on("render",()=>{this.emit("redraw")}),this.renderer.on("rendered",()=>{this.emit("redrawcomplete")}),this.renderer.on("dragstart",e=>{this.emit("dragstart",e)}),this.renderer.on("dragend",e=>{this.emit("dragend",e)}));{let e;this.subscriptions.push(this.renderer.on("drag",t=>{if(!this.options.interact)return;let r;this.renderer.renderProgress(t),clearTimeout(e),this.isPlaying()?r=0:this.options.dragToSeek===!0?r=200:typeof this.options.dragToSeek=="object"&&this.options.dragToSeek!==void 0&&(r=this.options.dragToSeek.debounceTime),e=setTimeout(()=>{this.seekTo(t)},r),this.emit("interaction",t*this.getDuration()),this.emit("drag",t)}))}}initPlugins(){var e;!((e=this.options.plugins)===null||e===void 0)&&e.length&&this.options.plugins.forEach(t=>{this.registerPlugin(t)})}unsubscribePlayerEvents(){this.mediaSubscriptions.forEach(e=>e()),this.mediaSubscriptions=[]}setOptions(e){this.options=Object.assign({},this.options,e),e.duration&&!e.peaks&&(this.decodedData=ra.createBuffer(this.exportPeaks(),e.duration)),e.peaks&&e.duration&&(this.decodedData=ra.createBuffer(e.peaks,e.duration)),this.renderer.setOptions(this.options),e.audioRate&&this.setPlaybackRate(e.audioRate),e.mediaControls!=null&&(this.getMediaElement().controls=e.mediaControls)}registerPlugin(e){if(this.plugins.includes(e))return e;e._init(this),this.plugins.push(e);let t=e.once("destroy",()=>{this.plugins=this.plugins.filter(r=>r!==e),this.subscriptions=this.subscriptions.filter(r=>r!==t)});return this.subscriptions.push(t),e}unregisterPlugin(e){this.plugins=this.plugins.filter(t=>t!==e),e.destroy()}getWrapper(){return this.renderer.getWrapper()}getWidth(){return this.renderer.getWidth()}getScroll(){return this.renderer.getScroll()}setScroll(e){return this.renderer.setScroll(e)}setScrollTime(e){let t=e/this.getDuration();this.renderer.setScrollPercentage(t)}getActivePlugins(){return this.plugins}loadAudio(e,t,r,s){return Se(this,void 0,void 0,function*(){var n;if(this.emit("load",e),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,this.stopAtPosition=null,!t&&!r){let a=this.options.fetchParams||{};window.AbortController&&!a.signal&&(this.abortController=new AbortController,a.signal=(n=this.abortController)===null||n===void 0?void 0:n.signal);let c=u=>this.emit("loading",u);t=yield aS.fetchBlob(e,c,a);let l=this.options.blobMimeType;l&&(t=new Blob([t],{type:l}))}this.setSrc(e,t);let o=yield new Promise(a=>{let c=s||this.getDuration();c?a(c):this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata",()=>a(this.getDuration()),{once:!0}))});if(!e&&!t){let a=this.getMediaElement();a instanceof Us&&(a.duration=o)}if(r)this.decodedData=ra.createBuffer(r,o||0);else if(t){let a=yield t.arrayBuffer();this.decodedData=yield ra.decode(a,this.options.sampleRate)}this.decodedData&&(this.emit("decode",this.getDuration()),this.renderer.render(this.decodedData)),this.emit("ready",this.getDuration())})}load(e,t,r){return Se(this,void 0,void 0,function*(){try{return yield this.loadAudio(e,void 0,t,r)}catch(s){throw this.emit("error",s),s}})}loadBlob(e,t,r){return Se(this,void 0,void 0,function*(){try{return yield this.loadAudio("",e,t,r)}catch(s){throw this.emit("error",s),s}})}zoom(e){if(!this.decodedData)throw new Error("No audio loaded");this.renderer.zoom(e),this.emit("zoom",e)}getDecodedData(){return this.decodedData}exportPeaks({channels:e=2,maxLength:t=8e3,precision:r=1e4}={}){if(!this.decodedData)throw new Error("The audio has not been decoded yet");let s=Math.min(e,this.decodedData.numberOfChannels),n=[];for(let o=0;o<s;o++){let a=this.decodedData.getChannelData(o),c=[],l=a.length/t;for(let u=0;u<t;u++){let h=a.slice(Math.floor(u*l),Math.ceil((u+1)*l)),d=0;for(let f=0;f<h.length;f++){let m=h[f];Math.abs(m)>Math.abs(d)&&(d=m)}c.push(Math.round(d*r)/r)}n.push(c)}return n}getDuration(){let e=super.getDuration()||0;return e!==0&&e!==1/0||!this.decodedData||(e=this.decodedData.duration),e}toggleInteraction(e){this.options.interact=e}setTime(e){this.stopAtPosition=null,super.setTime(e),this.updateProgress(e),this.emit("timeupdate",e)}seekTo(e){let t=this.getDuration()*e;this.setTime(t)}play(e,t){let r=Object.create(null,{play:{get:()=>super.play}});return Se(this,void 0,void 0,function*(){e!=null&&this.setTime(e);let s=yield r.play.call(this);return t!=null&&(this.media instanceof Us?this.media.stopAt(t):this.stopAtPosition=t),s})}playPause(){return Se(this,void 0,void 0,function*(){return this.isPlaying()?this.pause():this.play()})}stop(){this.pause(),this.setTime(0)}skip(e){this.setTime(this.getCurrentTime()+e)}empty(){this.load("",[[0]],.001)}setMediaElement(e){this.unsubscribePlayerEvents(),super.setMediaElement(e),this.initPlayerEvents()}exportImage(){return Se(this,arguments,void 0,function*(e="image/png",t=1,r="dataURL"){return this.renderer.exportImage(e,t,r)})}destroy(){var e;this.emit("destroy"),(e=this.abortController)===null||e===void 0||e.abort(),this.plugins.forEach(t=>t.destroy()),this.subscriptions.forEach(t=>t()),this.unsubscribePlayerEvents(),this.timer.destroy(),this.renderer.destroy(),super.destroy()}};Ei.BasePlugin=class extends Lr{constructor(i){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=i}onInit(){}_init(i){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=i,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(i=>i()),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}},Ei.dom=oS;var ia=class i{wavesurfer;constructor(e,t,r){this.wavesurfer=Ei.create({container:t,waveColor:"rgb(200, 0, 200)",progressColor:"rgb(100, 0, 100)",barWidth:10,barRadius:10,barGap:2,peaks:[e],duration:r})}static async init(e,t,r){let s=e.decodeAudio({source:t}).getReader(),n=[],o=[],a=1024,c=await e.getAudioDuration(t);for(;;){let{done:l,value:u}=await s.read();if(l)break;let h=u.numberOfFrames,d=new Float32Array(h);u.copyTo(d,{planeIndex:0});for(let f=0;f<d.length;f++)if(o.push(d[f]),o.length>=a){let m=o.splice(0,a),p=Math.min(...m),g=Math.max(...m);n.push(p,g)}u.close()}return new i(n,r,c??0)}set width(e){this.wavesurfer.setOptions({width:e})}};async function Pm(i){let e=document.querySelector(".waveform-demo"),t=document.querySelector(".width"),r=await ia.init(i,"/assets/temp/gl.mp4",e);t.addEventListener("change",()=>{let s=+t.value;r.width=s})}var sa=class i{videoTrack;options;#e;#t=new Map;#r=[0,0];constructor(e,t){this.videoTrack=e,this.options=t,this.#e=new Ms(e,t.canvasSinkOptions)}static async init(e,t){let s=await new St({formats:ur,source:await Gr(e)}).getPrimaryVideoTrack();if(s)return new i(s,{frequency:t.frequency??1,canvasSinkOptions:t.canvasSinkOptions??{width:80,height:50,fit:"fill"},onChange:t.onChange});throw new Error("Source has no video track")}set frequency(e){e!==this.options.frequency&&(this.options.frequency=e,this.#a())}get frequency(){return this.options.frequency}#i([e,t]){let r=t-e;return[e-r,t+r]}async#s(){let[e,t]=this.#r,r=new Set,s=await this.videoTrack.computeDuration();for(let c=e;c<=t;c+=this.options.frequency)c>=0&&c<=s&&r.add(+c.toFixed(3));let n=[...r].filter(c=>!this.#t.has(c)),o=0;for await(let c of this.#e.canvasesAtTimestamps(n))if(c){let l=n[o++];this.#t.set(l,c)}for(let c of this.#t.keys())r.has(c)||this.#t.delete(c);let a=[...this.#t.entries()].map(([c,l])=>({time:c,canvas:l}));this.options.onChange(a)}set range(e){let t=this.#i(e);this.#r[0]===t[0]&&this.#r[1]===t[1]||(this.#r=t,this.#a())}#n=null;#o=!1;async#a(){if(this.#n){this.#o=!0;return}this.#n=this.#s(),await this.#n,this.#n=null,this.#o&&(this.#o=!1,await this.#a())}getThumbnail(e){return this.#t.get(e)}};async function Cm(i){let e=document.querySelector(".range"),t=document.querySelector(".range-view"),r=document.querySelector(".range-size"),s=document.querySelector(".frequency"),n=document.querySelector(".frequency-view"),o=document.querySelector("#filmstrip"),a=1e3/10/1e3,c=.5,l=await sa.init(i,{onChange(u){let h=u.sort((d,f)=>d.time-f.time);o.replaceChildren(...h.map(({time:d,canvas:f})=>lS(d,f.canvas)))},frequency:a,canvasSinkOptions:{width:80,height:50,fit:"fill"}});r.addEventListener("change",()=>{c=+r.value;let[u,h]=[+e.value,+e.value+c];l.range=[u,h],t.textContent=`visible time range: [${u}, ${h}]`}),e.addEventListener("change",()=>{let[u,h]=[+e.value,+e.value+c];l.range=[u,h],t.textContent=`visible time range: [${u}, ${h}]`}),s.addEventListener("change",()=>{l.frequency=1e3/+s.value/1e3,n.textContent=`frame every ${l.frequency.toFixed(3)} second (${s.value} frames per second)`}),l.range=[10,10.5]}function lS(i,e){let t=document.createElement("div");t.style.position="relative",t.style.display="inline-block",t.style.marginRight="4px",t.appendChild(e);let r=document.createElement("div");return r.textContent=`${i.toFixed(2)}s`,r.style.position="absolute",r.style.top="2px",r.style.right="4px",r.style.fontSize="10px",r.style.color="white",r.style.background="rgba(0,0,0,0.6)",r.style.padding="2px 4px",r.style.borderRadius="4px",r.style.pointerEvents="none",t.appendChild(r),t}function Jl(i,e){let t={width:1920,height:1080},r=document.createElement("canvas");r.width=t.width,r.height=t.height;let s=r.getContext("2d");async function n(){let o=i.decodeVideo({source:e,async onFrame(c){let l=await i.composite([{kind:"image",frame:c},{kind:"text",content:"omnitool",fontSize:50,color:"green"}]);return c.close(),s?.drawImage(l,0,0),l}}),a=i.decodeAudio({source:e});await i.encode({video:o,audio:a,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}})}return{canvas:r,run:n}}var me;(function(i){i[i.Sequence=0]="Sequence",i[i.Stack=1]="Stack",i[i.Video=2]="Video",i[i.Audio=3]="Audio",i[i.Text=4]="Text",i[i.Gap=5]="Gap",i[i.Spatial=6]="Spatial",i[i.Transition=7]="Transition",i[i.TextStyle=8]="TextStyle"})(me||(me={}));var na;(function(i){i[i.Crossfade=0]="Crossfade"})(na||(na={}));var oa=class{datafile;duration=0;hasVideo=!1;hasAudio=!1;constructor(e){this.datafile=e}static async analyze(e){let t=new this(e);t.duration=10;let{video:r,audio:s}=await this.#e("/assets/temp/gl.mp4");return t.hasAudio=s,t.hasVideo=r,t}static async#e(e){let t=new St({formats:ur,source:await Gr(e)});return{audio:!!await t.getPrimaryAudioTrack(),video:!!await t.getPrimaryVideoTrack()}}};var aa=class{#e=new no;async store(e){let t=await oa.analyze(e),{hash:r}=t.datafile.checksum,{filename:s,bytes:n}=t.datafile;if(this.#e.has(r)){let o=this.#e.require(r);o.filename=s}else this.#e.set(r,{kind:"media",filename:s,bytes:n});return t}};function Em(i,e){let t,r,s=[];function n(){t=[],r&&clearTimeout(r),r=void 0,s=[]}return n(),(...o)=>{t=o,r&&clearTimeout(r);let a=new Promise((c,l)=>{s.push({resolve:c,reject:l})});return r=setTimeout(()=>{Promise.resolve().then(()=>e(...t)).then(c=>{for(let{resolve:l}of s)l(c);n()}).catch(c=>{for(let{reject:l}of s)l(c);n()})},i),a}}function Am(){let i,e,t=new Promise((s,n)=>{i=s,e=n});function r(s){return s.then(i).catch(e),t}return{promise:t,resolve:i,reject:e,entangle:r}}function uS(){let i=new Set;async function e(...c){await Promise.all([...i].map(l=>l(...c)))}function t(c){return i.add(c),()=>{i.delete(c)}}async function r(...c){return e(...c)}function s(c){return t(c)}async function n(c){let{promise:l,resolve:u}=Am(),h=s(async(...d)=>{c&&await c(...d),u(d),h()});return l}function o(){i.clear()}let a={pub:r,sub:s,publish:e,subscribe:t,on:t,next:n,clear:o};return Object.assign(s,a),Object.assign(r,a),a}function ca(i){let e=uS();return i&&e.sub(i),e.sub}var eu=class{#e=[];#t=new WeakMap;#r=[];#i=new Set;notifyRead(e){this.#e.at(-1)?.add(e)}async notifyWrite(e){if(this.#i.has(e))throw new Error("circularity forbidden");let t=this.#s(e).pub();return this.#r.at(-1)?.add(t),t}observe(e){this.#e.push(new Set);let t=e();return{seen:this.#e.pop(),result:t}}subscribe(e,t){return this.#s(e)(async()=>{let r=new Set;this.#r.push(r),this.#i.add(e),r.add(t()),this.#i.delete(e),await Promise.all(r),this.#r.pop()})}#s(e){let t=this.#t.get(e);return t||(t=ca(),this.#t.set(e,t)),t}},Ke=globalThis[Symbol.for("e280.tracker")]??=new eu;var Ai=class{sneak;constructor(e){this.sneak=e}get(){return Ke.notifyRead(this),this.sneak}get value(){return this.get()}};var Ii=class extends Ai{on=ca();dispose(){this.on.clear()}};function la(i,e=i){let{seen:t,result:r}=Ke.observe(i),s=Em(0,e),n=[],o=()=>n.forEach(a=>a());for(let a of t){let c=Ke.subscribe(a,s);n.push(c)}return{result:r,dispose:o}}function Mi(i,e){return i===e}var ua=class extends Ii{#e;constructor(e,t){let r=t?.compare??Mi,{result:s,dispose:n}=la(e,async()=>{let o=e();!r(this.sneak,o)&&(this.sneak=o,await Promise.all([Ke.notifyWrite(this),this.on.pub(o)]))});super(s),this.#e=n}toString(){return`(derived "${String(this.get())}")`}dispose(){super.dispose(),this.#e()}get core(){return this}fn(){let e=this;function t(){return e.get()}return t.core=e,t.get=e.get.bind(e),t.on=e.on,t.dispose=e.dispose.bind(e),t.fn=e.fn.bind(e),Object.defineProperty(t,"value",{get:()=>e.value}),Object.defineProperty(t,"sneak",{get:()=>e.sneak}),t}};var ha=class extends Ai{#e;#t;#r=!1;#i;constructor(e,t){super(void 0),this.#e=e,this.#t=t?.compare??Mi}toString(){return`($lazy "${String(this.get())}")`}get(){if(!this.#i){let{result:e,dispose:t}=la(this.#e,()=>this.#r=!0);this.#i=t,this.sneak=e}if(this.#r){this.#r=!1;let e=this.#e();!this.#t(this.sneak,e)&&(this.sneak=e,Ke.notifyWrite(this))}return super.get()}dispose(){this.#i&&this.#i()}get core(){return this}fn(){let e=this;function t(){return e.get()}return t.core=e,t.get=e.get.bind(e),t.dispose=e.dispose.bind(e),t.fn=e.fn.bind(e),Object.defineProperty(t,"value",{get:()=>e.value}),Object.defineProperty(t,"sneak",{get:()=>e.sneak}),t}};var da=class extends Ii{#e=!1;#t;constructor(e,t){super(e),this.#t=t?.compare??Mi}toString(){return`($signal "${String(this.get())}")`}async set(e,t=!1){let r=this.sneak;return this.sneak=e,(t||!this.#t(r,e))&&await this.publish(),e}get value(){return this.get()}set value(e){this.set(e)}async publish(){if(this.#e)throw new Error("forbid circularity");let e=this.sneak,t=Promise.resolve();try{this.#e=!0,t=Promise.all([Ke.notifyWrite(this),this.on.publish(e)])}finally{this.#e=!1}return await t,e}get core(){return this}fn(){let e=this;function t(r){return arguments.length===0?e.get():e.set(arguments[0])}return t.core=e,t.get=e.get.bind(e),t.set=e.set.bind(e),t.on=e.on,t.dispose=e.dispose.bind(e),t.publish=e.publish.bind(e),t.fn=e.fn.bind(e),Object.defineProperty(t,"value",{get:()=>e.value,set:r=>e.value=r}),Object.defineProperty(t,"sneak",{get:()=>e.sneak,set:r=>e.sneak=r}),t}};function hS(i,e){return new ha(i,e).fn()}function Im(i,e){return new ua(i,e).fn()}function Gs(i,e){return new da(i,e).fn()}Gs.lazy=hS;Gs.derived=Im;var Mm=(i,e)=>{let t=!1,r=null,s=60,n=1e3/s,o=0,a=0,c=0,l=0,u=h=>{if(!t)return;let d=h-a;for(a=h,c+=d,l+=d,e(l);c>=n;)i(o),o+=n,c-=n;r=requestAnimationFrame(u)};return{play(){t||(t=!0,a=performance.now(),r=requestAnimationFrame(u))},pause(){t&&(t=!1,r!==null&&cancelAnimationFrame(r),r=null)},seek(h){o=h,c=0,l=h,e(h)},dispose(){this.pause()},isPlaying(){return t},setFPS(h){s=h,n=1e3/s}}},Bm=async(i,e)=>{let t=1/i.fps,r=Math.ceil(i.duration*i.fps);for(let s=0;s<r&&!i.abort?.aborted;s++){let n=s*t;await e(n,s)}};var Fm=i=>i instanceof Blob?URL.createObjectURL(i):String(i);function Dm(i){let e=new Map,t=new Map;function r(o){let a=e.get(o.id);return a||(a=document.createElement("video"),a.playsInline=!0,a.muted=!0,a.preload="auto",a.crossOrigin="anonymous",a.src=Fm(i(o.mediaHash)),e.set(o.id,a)),a}function s(o){let a=t.get(o.id);return a||(a=document.createElement("audio"),a.preload="auto",a.crossOrigin="anonymous",a.src=Fm(i(o.mediaHash)),a.volume=.2,t.set(o.id,a)),a}let n=!0;return{async video(o,a){let c=r(o);return{duration:o.duration,visuals:{sampleAt:async l=>{if(l<0||l>=o.duration)return[];c.paused&&n&&await Rm(c,l/1e3),c.paused&&!n&&await c.play();let u=new VideoFrame(c);return u?[{kind:"image",frame:u,matrix:a}]:[]}}}},async audio(o){let a=s(o);return{duration:o.duration,audio:{onTimeUpdate:async c=>{let l=o.start+c;return a.paused&&n&&await Rm(a,l/1e3),a.paused&&!n&&await a.play(),[]}}}},async dispose(){let o=[...e.values(),...t.values()];for(let a of o)a.pause(),a.src.startsWith("blob:")&&URL.revokeObjectURL(a.src),a.remove();e.clear(),t.clear()},async setPaused(o){n=o;let a=[...e.values(),...t.values()];for(let c of a)o&&c.pause()}}}function Rm(i,e){return new Promise(t=>{let r=()=>{i.removeEventListener("seeked",r),t()};i.addEventListener("seeked",r),i.fastSeek?i.fastSeek(e):i.currentTime=e})}G();var Qw={extension:{type:A.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await Promise.resolve().then(()=>(Zw(),kk))}};G();var e_={extension:{type:A.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await Promise.resolve().then(()=>(Jw(),vk))}};G();Va();Oa();ih();He();N.add(Qw,e_);var t_=i=>{let[e,t,r]=i,[s,n]=e,[o,a]=t,c=r*Math.PI/180,l=Math.cos(c),u=Math.sin(c);return[l*o,u*o,-u*a,l*a,s,n]};var r_=(i,e)=>{let[t,r,s,n,o,a]=i,[c,l,u,h,d,f]=e;return[t*c+s*l,r*c+n*l,t*u+s*h,r*u+n*h,t*d+s*f+o,r*d+n*f+a]},i_=[1,0,0,1,0,0];var Ld=(i,e)=>i.get(e),jc=(i,e,t)=>{let r=t??i_;if(e.spatialId){let s=Ld(i,e.spatialId),n=t_(s.transform);r=r_(n,r)}return r},cs=class{items;sampler;constructor(e,t){this.items=e,this.sampler=t}async build(e,t){switch(e.kind){case me.Video:return this.sampler.video(e,jc(this.items,e,t));case me.Audio:return this.sampler.audio(e);case me.Text:{let r=jc(this.items,e,t);return{duration:e.duration,visuals:{sampleAt:async s=>s<0||s>=e.duration?[]:[{kind:"text",content:e.content,color:"white",fontSize:48,matrix:r}]}}}case me.Gap:return{duration:e.duration,visuals:{sampleAt:async()=>[]}};case me.Stack:{let r=jc(this.items,e,t),s=await Promise.all(e.childrenIds.map(n=>this.build(Ld(this.items,n),r)));return this.#r(s)}case me.Sequence:{let r=jc(this.items,e,t);return this.#i(e,r)}default:return{duration:0}}}#e(e){return{sampleAt:async t=>(await Promise.all(e.map(s=>s.visuals?s.visuals.sampleAt(t):Promise.resolve([])))).flat()}}#t(e){return{sampleAt:async t=>{let r=t;for(let s of e){if(r<s.duration)return s.visuals?s.visuals.sampleAt(r):[];r-=s.duration}return[]}}}#r(e){return{duration:Math.max(0,...e.map(r=>Number.isFinite(r.duration)?r.duration:0)),visuals:this.#e(e),audio:this.composeAudio_Stack(e)}}async#i(e,t){let r=e.childrenIds.map(o=>Ld(this.items,o)),s=await this.#s(r,t);return{duration:s.reduce((o,a)=>o+a.duration,0),visuals:this.#t(s),audio:this.composeAudio_Sequence(s)}}async#s(e,t){let r=[];for(let s=0;s<e.length;s++){let n=e[s];if(n.kind!==me.Transition){r.push(await this.build(n,t));continue}let o=r.pop(),a=e[s+1];if(!o||!a||a.kind===me.Transition){o&&r.push(o);continue}let c=await this.build(a,t),l=await this.#n(n,o,c);r.push(l),s++}return r}async#n(e,t,r){let s=Math.max(0,Math.min(e.duration,t.duration,r.duration)),n=Math.max(0,t.duration-s);return{duration:t.duration+r.duration-s,visuals:{sampleAt:async a=>{if(!t.visuals||!r.visuals)return[];if(a<n)return t.visuals.sampleAt(a);if(a<t.duration){let c=a-n,l=s>0?c/s:1,u=await t.visuals.sampleAt(a),h=await r.visuals.sampleAt(c);return!u[0]?.frame||!h[0]?.frame?[]:[{kind:"transition",name:"circle",progress:l,from:u[0].frame,to:h[0].frame}]}return r.visuals.sampleAt(a-t.duration+s)}},audio:this.composeAudio_Sequence([t,r])}}};var Nd=class extends cs{items;sampler;constructor(e,t){super(e,t),this.items=e,this.sampler=t}composeAudio_Stack(e){return{onTimeUpdate:t=>{for(let r of e)r.audio&&r.audio.onTimeUpdate(t)}}}composeAudio_Sequence(e){return{onTimeUpdate:t=>{let r=t;for(let s of e){if(r<s.duration){s.audio&&s.audio.onTimeUpdate(r);break}r-=s.duration}}}}};function s_(i,e,t){return new Nd(e,t).build(i)}var $c=class{driver;canvas;root;sampler;resolveMedia;currentTime=Gs(0);#e=Mm(e=>this.#t(e),e=>this.currentTime(e));constructor(e,t,r,s,n=o=>"/assets/temp/gl.mp4"){this.driver=e,this.canvas=t,this.root=r,this.sampler=s,this.resolveMedia=n,this.#e.setFPS(30)}get context(){return this.canvas.getContext("2d")}static async create(e,t){let r=new Map(t.items.map(c=>[c.id,c])).get(t.rootId),s=new Map(t.items.map(c=>[c.id,c])),n=Dm(()=>"/assets/temp/gl.mp4"),o=await s_(r,s,n),a=document.createElement("canvas");return a.width=1920,a.height=1080,new this(e,a,o,n)}async#t(e){let t=this.root.duration,r=e>t?t:e;this.root.audio?.onTimeUpdate(r);let s=await this.root.visuals?.sampleAt(r)??[],n=await this.driver.composite(s);this.context.drawImage(n,0,0),n.close(),e>=t&&this.pause()}async play(){this.#e.isPlaying()||(this.sampler.setPaused(!1),this.#e.play())}pause(){this.#e.isPlaying()&&(this.#e.pause(),this.sampler.setPaused(!0))}async seek(e){this.pause(),this.#e.seek(e),this.root.audio?.onTimeUpdate(e);let t=await this.root.visuals?.sampleAt(e)??[],r=await this.driver.composite(t);this.context.drawImage(r,0,0),r.close()}setFPS(e){this.#e.setFPS(e)}};var qc=class{state;#e=0;constructor(e){this.state=e}require(e){return this.state.project.items.find(r=>r.id===e)}#t(){return this.#e++}#r(e){this.state.project=e(this.state.project)}textStyle=e=>({id:this.#t(),kind:me.TextStyle,style:e});spatial=e=>({id:this.#t(),kind:me.Spatial,transform:e});sequence=(...e)=>{let t={id:this.#t(),kind:me.Sequence,childrenIds:e.map(r=>r.id)};return this.#r(r=>(r.items.push(t,...e),r)),t};stack=(...e)=>{let t={kind:me.Stack,id:this.#t(),childrenIds:e.map(r=>r.id)};return this.#r(r=>(r.items.push(t,...e),r)),t};video=(e,t)=>{if(!e.hasVideo)throw new Error(`Video clip error: media "${e.datafile.filename}" has no video track.`);return{kind:me.Video,id:this.#t(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration}};audio=(e,t)=>{if(!e.hasAudio)throw new Error(`Audio clip error: media "${e.datafile.filename}" has no audio track.`);return{kind:me.Audio,id:this.#t(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration}};text=e=>({id:this.#t(),content:e,kind:me.Text,duration:2e3});gap=e=>({id:this.#t(),kind:me.Gap,duration:e});transition={crossfade:e=>({id:this.#t(),kind:me.Transition,effect:na.Crossfade,duration:e})};transform=e=>{let t=[e?.position?.[0]??0,e?.position?.[1]??0],r=[e?.scale?.[0]??1,e?.scale?.[1]??1],s=e?.rotation??0;return[t,r,s]};addChildren(e,...t){this.#r(r=>(r.items.find(({id:n})=>n===e.id).childrenIds.push(...t.map(n=>n.id)),r.items.push(...t),r))}update=(e,t,r)=>{this.#r(s=>{let n=s.items.map(o=>o.id===e?{...o,[t]:r}:o);return{...s,items:n}})}};var Xc=class{reader;constructor(e){this.reader=e}async atOrNear(e){let t=null;for(;;){let{done:r,value:s}=await this.reader.read();if(r){let o=t?new VideoFrame(t):void 0;return t?.close(),o}let n=s.timestamp??0;if(n>=e){let o=t?.timestamp??Number.NEGATIVE_INFINITY,a=!!t&&Math.abs(o-e)<Math.abs(n-e),c=a?t:s,l=a?s:t,u=new VideoFrame(c);return c.close(),l?.close(),u}t?.close(),t=s}}cancel=async()=>await this.reader.cancel()};var Yc=class{reader;constructor(e){this.reader=e}async*stream(){for(;;){let{done:e,value:t}=await this.reader.read();if(e)break;yield t}}cancel=async()=>await this.reader.cancel()};var n_=i=>Math.round(i*1e6);function o_(i,e){let t=new Map;async function r(s){let n=t.get(s.id);if(n)return n;let o=e(s.mediaHash),a=i.decodeVideo({source:o}),c=new Xc(a.getReader());return t.set(s.id,c),c}return{async video(s,n){let o=await r(s),a=n_(s.start??0);return{duration:s.duration,visuals:{sampleAt:async c=>{let l=await o.atOrNear(a+n_(c));return l?[{kind:"image",frame:l,matrix:n}]:[]}}}},async audio(s){return{duration:s.duration,audio:{getStream:async function*(){let n=e(s.mediaHash),o=s.start,a=s.start+s.duration,c=i.decodeAudio({source:n,start:o,end:a});yield*new Yc(c.getReader()).stream()}}}},async dispose(){let s=Array.from([...t.values()],n=>n.cancel());t.clear(),await Promise.all(s)}}}var Vd=class extends cs{composeAudio_Stack(e){return{getStream:async function*(){for(let t of e)t.audio&&(yield*t.audio.getStream())}}}composeAudio_Sequence(e){return{getStream:async function*(){for(let t of e)t.audio&&(yield*t.audio.getStream())}}}};function a_(i,e,t){return new Vd(e,t).build(i)}var Kc=class{driver;framerate;resolveMedia;#e;constructor(e,t=30,r=s=>"/assets/temp/gl.mp4"){this.driver=e,this.framerate=t,this.resolveMedia=r,this.#e=o_(this.driver,this.resolveMedia)}async#t(e){let t=new Map(e.items.map(s=>[s.id,s])).get(e.rootId),r=new Map(e.items.map(s=>[s.id,s]));return await a_(t,r,this.#e)}async render(e){let t=await this.#t(e),r=new TransformStream,s=new TransformStream,n=this.driver.encode({video:r.readable,audio:s.readable,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}}),o=r.writable.getWriter(),a=s.writable.getWriter(),c=(async()=>{if(t.audio)for await(let u of t.audio.getStream())await a.write(u);await a.close()})(),l=(async()=>{let u=0,h=1/this.framerate;await Bm({fps:this.framerate,duration:t.duration??0},async d=>{let f=await t.visuals?.sampleAt(d)??[],m=await this.driver.composite(f),p=new VideoFrame(m,{timestamp:Math.round(u*h*1e6),duration:Math.round(h*1e6)});await o.write(p),m.close(),u++}),await o.close()})();await c,await l,await n}};var Zc=class{driver;resources=new aa;#e;constructor(e){this.driver=e,this.#e=new Kc(e)}load=async e=>Object.fromEntries(await Promise.all(Object.entries(e).map(async([t,r])=>[t,await this.resources.store(await r)])));timeline=e=>{let t=new qc({project:{format:"timeline",info:"https://omniclip.app/",version:0,items:[],rootId:0}}),r=e(t);return t.state.project.rootId=r.id,t.state.project};render=async(e,t)=>{await this.#e.render(e)}};var Qc=class{data;bytes;hash;nickname;constructor(e,t,r,s){this.data=e,this.bytes=t,this.hash=r,this.nickname=s}static async make(e){let t=new Uint8Array(e),r=new Uint8Array(await crypto.subtle.digest("SHA-256",t)),s=Ne.fromBytes(r),n=ot.sigil.fromBytes(r);return new this(e,r,s,n)}};var Jc=class{bytes;filename;checksum;constructor(e,t,r){this.bytes=e,this.filename=t,this.checksum=r}static async make(e,t){let r=await Qc.make(e),s=t??r.nickname;return new this(e,s,r)}static async load(e){throw new Error("TODO implement")}};var si=await ta.setup({workerUrl:new URL("../driver/driver.worker.bundle.min.js",import.meta.url)}),Pk=document.querySelector(".results"),Ck=document.querySelector(".fetch"),Ek=document.querySelector(".import"),Ak=document.querySelector(".play"),Ik=document.querySelector(".stop"),Mk=document.querySelector(".seek");Ck?.addEventListener("click",Uk);Ek?.addEventListener("click",Ok);var c_=new Zc(si),Bk=await fetch("/assets/temp/gl.mp4"),Fk=await Bk.arrayBuffer(),Rk=new Uint8Array(Fk),{videoA:Wd}=await c_.load({videoA:Jc.make(Rk)}),Dk=c_.timeline(i=>i.sequence(i.stack(i.video(Wd,{duration:5e3}),i.audio(Wd,{duration:8e3})),i.video(Wd,{duration:7e3}))),el=await $c.create(si,Dk);document.body.appendChild(el.canvas);Ak.addEventListener("click",()=>el.play());Ik.addEventListener("click",()=>el.pause());Mk.addEventListener("change",async i=>{let e=i.target;await el.seek(+e.value)});Pm(si);await si.thread.work.hello(),si.machina.count===1?console.log("\u2705 driver works"):console.error("\u274C FAIL driver call didn't work");async function Ok(){let[i]=await window.showOpenFilePicker(),e=await i.getFile(),t=Jl(si,e);await Cm(e),l_(t,i.name)}async function Uk(){let i=["/assets/temp/gl.mp4"];for(let e of i){let t=Jl(si,"/assets/temp/gl.mp4");l_(t,e)}}async function l_(i,e){let t=document.createElement("div");Pk.append(t);let r=document.createElement("p");r.textContent=e,t.append(r),t.append(i.canvas),await i.run()}
647
+ `,[e,t]}setOptions(e){if(this.options.container!==e.container){let t=this.parentFromOptionsContainer(e.container);t.appendChild(this.container),this.parent=t}e.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.options=e,this.reRender()}getWrapper(){return this.wrapper}getWidth(){return this.scrollContainer.clientWidth}getScroll(){return this.scrollContainer.scrollLeft}setScroll(e){this.scrollContainer.scrollLeft=e}setScrollPercentage(e){let{scrollWidth:t}=this.scrollContainer,r=t*e;this.setScroll(r)}destroy(){var e,t;this.subscriptions.forEach(r=>r()),this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.unsubscribeOnScroll)===null||t===void 0||t.forEach(r=>r()),this.unsubscribeOnScroll=[]}createDelay(e=10){let t,r,s=()=>{t&&clearTimeout(t),r&&r()};return this.timeouts.push(s),()=>new Promise((n,o)=>{s(),r=o,t=setTimeout(()=>{t=void 0,r=void 0,n()},e)})}convertColorValues(e){if(!Array.isArray(e))return e||"";if(e.length<2)return e[0]||"";let t=document.createElement("canvas"),r=t.getContext("2d"),s=t.height*(window.devicePixelRatio||1),n=r.createLinearGradient(0,0,0,s),o=1/(e.length-1);return e.forEach((a,c)=>{let l=c*o;n.addColorStop(l,a)}),n}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(e,t,r,s){let n=e[0],o=e[1]||e[0],a=n.length,{width:c,height:l}=r.canvas,u=l/2,h=this.getPixelRatio(),d=t.barWidth?t.barWidth*h:1,f=t.barGap?t.barGap*h:t.barWidth?d/2:0,m=t.barRadius||0,p=c/(d+f)/a,g=m&&"roundRect"in r?"roundRect":"rect";r.beginPath();let y=0,x=0,w=0;for(let _=0;_<=a;_++){let S=Math.round(_*p);if(S>y){let M=Math.round(x*u*s),P=M+Math.round(w*u*s)||1,C=u-M;t.barAlign==="top"?C=0:t.barAlign==="bottom"&&(C=l-P),r[g](y*(d+f),C,d,P,m),y=S,x=0,w=0}let T=Math.abs(n[_]||0),v=Math.abs(o[_]||0);T>x&&(x=T),v>w&&(w=v)}r.fill(),r.closePath()}renderLineWaveform(e,t,r,s){let n=o=>{let a=e[o]||e[0],c=a.length,{height:l}=r.canvas,u=l/2,h=r.canvas.width/c;r.moveTo(0,u);let d=0,f=0;for(let m=0;m<=c;m++){let p=Math.round(m*h);if(p>d){let y=u+(Math.round(f*u*s)||1)*(o===0?-1:1);r.lineTo(d,y),d=p,f=0}let g=Math.abs(a[m]||0);g>f&&(f=g)}r.lineTo(d,u)};r.beginPath(),n(0),n(1),r.fill(),r.closePath()}renderWaveform(e,t,r){if(r.fillStyle=this.convertColorValues(t.waveColor),t.renderFunction)return void t.renderFunction(e,r);let s=t.barHeight||1;if(t.normalize){let n=Array.from(e[0]).reduce((o,a)=>Math.max(o,Math.abs(a)),0);s=n?1/n:1}t.barWidth||t.barGap||t.barAlign?this.renderBarWaveform(e,t,r,s):this.renderLineWaveform(e,t,r,s)}renderSingleCanvas(e,t,r,s,n,o,a){let c=this.getPixelRatio(),l=document.createElement("canvas");l.width=Math.round(r*c),l.height=Math.round(s*c),l.style.width=`${r}px`,l.style.height=`${s}px`,l.style.left=`${Math.round(n)}px`,o.appendChild(l);let u=l.getContext("2d");if(this.renderWaveform(e,t,u),l.width>0&&l.height>0){let h=l.cloneNode(),d=h.getContext("2d");d.drawImage(l,0,0),d.globalCompositeOperation="source-in",d.fillStyle=this.convertColorValues(t.progressColor),d.fillRect(0,0,l.width,l.height),a.appendChild(h)}}renderMultiCanvas(e,t,r,s,n,o){let a=this.getPixelRatio(),{clientWidth:c}=this.scrollContainer,l=r/a,u=Math.min(i.MAX_CANVAS_WIDTH,c,l),h={};if(t.barWidth||t.barGap){let g=t.barWidth||.5,y=g+(t.barGap||g/2);u%y!=0&&(u=Math.floor(u/y)*y)}if(u===0)return;let d=g=>{if(g<0||g>=f||h[g])return;h[g]=!0;let y=g*u,x=Math.min(l-y,u);if(t.barWidth||t.barGap){let _=t.barWidth||.5,S=_+(t.barGap||_/2);x=Math.floor(x/S)*S}if(x<=0)return;let w=e.map(_=>{let S=Math.floor(y/l*_.length),T=Math.floor((y+x)/l*_.length);return _.slice(S,T)});this.renderSingleCanvas(w,t,x,s,y,n,o)},f=Math.ceil(l/u);if(!this.isScrollable){for(let g=0;g<f;g++)d(g);return}let m=this.scrollContainer.scrollLeft/l,p=Math.floor(m*f);if(d(p-1),d(p),d(p+1),f>1){let g=this.on("scroll",()=>{let{scrollLeft:y}=this.scrollContainer,x=Math.floor(y/l*f);Object.keys(h).length>i.MAX_NODES&&(n.innerHTML="",o.innerHTML="",h={}),d(x-1),d(x),d(x+1)});this.unsubscribeOnScroll.push(g)}}renderChannel(e,t,r,s){var{overlay:n}=t,o=function(u,h){var d={};for(var f in u)Object.prototype.hasOwnProperty.call(u,f)&&h.indexOf(f)<0&&(d[f]=u[f]);if(u!=null&&typeof Object.getOwnPropertySymbols=="function"){var m=0;for(f=Object.getOwnPropertySymbols(u);m<f.length;m++)h.indexOf(f[m])<0&&Object.prototype.propertyIsEnumerable.call(u,f[m])&&(d[f[m]]=u[f[m]])}return d}(t,["overlay"]);let a=document.createElement("div"),c=this.getHeight(o.height,o.splitChannels);a.style.height=`${c}px`,n&&s>0&&(a.style.marginTop=`-${c}px`),this.canvasWrapper.style.minHeight=`${c}px`,this.canvasWrapper.appendChild(a);let l=a.cloneNode();this.progressWrapper.appendChild(l),this.renderMultiCanvas(e,o,r,c,a,l)}render(e){return Se(this,void 0,void 0,function*(){var t;this.timeouts.forEach(c=>c()),this.timeouts=[],this.canvasWrapper.innerHTML="",this.progressWrapper.innerHTML="",this.options.width!=null&&(this.scrollContainer.style.width=typeof this.options.width=="number"?`${this.options.width}px`:this.options.width);let r=this.getPixelRatio(),s=this.scrollContainer.clientWidth,n=Math.ceil(e.duration*(this.options.minPxPerSec||0));this.isScrollable=n>s;let o=this.options.fillParent&&!this.isScrollable,a=(o?s:n)*r;if(this.wrapper.style.width=o?"100%":`${n}px`,this.scrollContainer.style.overflowX=this.isScrollable?"auto":"hidden",this.scrollContainer.classList.toggle("noScrollbar",!!this.options.hideScrollbar),this.cursor.style.backgroundColor=`${this.options.cursorColor||this.options.progressColor}`,this.cursor.style.width=`${this.options.cursorWidth}px`,this.audioData=e,this.emit("render"),this.options.splitChannels)for(let c=0;c<e.numberOfChannels;c++){let l=Object.assign(Object.assign({},this.options),(t=this.options.splitChannels)===null||t===void 0?void 0:t[c]);this.renderChannel([e.getChannelData(c)],l,a,c)}else{let c=[e.getChannelData(0)];e.numberOfChannels>1&&c.push(e.getChannelData(1)),this.renderChannel(c,this.options,a,0)}Promise.resolve().then(()=>this.emit("rendered"))})}reRender(){if(this.unsubscribeOnScroll.forEach(r=>r()),this.unsubscribeOnScroll=[],!this.audioData)return;let{scrollWidth:e}=this.scrollContainer,{right:t}=this.progressWrapper.getBoundingClientRect();if(this.render(this.audioData),this.isScrollable&&e!==this.scrollContainer.scrollWidth){let{right:r}=this.progressWrapper.getBoundingClientRect(),s=r-t;s*=2,s=s<0?Math.floor(s):Math.ceil(s),s/=2,this.scrollContainer.scrollLeft+=s}}zoom(e){this.options.minPxPerSec=e,this.reRender()}scrollIntoView(e,t=!1){let{scrollLeft:r,scrollWidth:s,clientWidth:n}=this.scrollContainer,o=e*s,a=r,c=r+n,l=n/2;if(this.isDragging)o+30>c?this.scrollContainer.scrollLeft+=30:o-30<a&&(this.scrollContainer.scrollLeft-=30);else{(o<a||o>c)&&(this.scrollContainer.scrollLeft=o-(this.options.autoCenter?l:0));let u=o-r-l;t&&this.options.autoCenter&&u>0&&(this.scrollContainer.scrollLeft+=Math.min(u,10))}{let u=this.scrollContainer.scrollLeft,h=u/s,d=(u+n)/s;this.emit("scroll",h,d,u,u+n)}}renderProgress(e,t){if(isNaN(e))return;let r=100*e;this.canvasWrapper.style.clipPath=`polygon(${r}% 0%, 100% 0%, 100% 100%, ${r}% 100%)`,this.progressWrapper.style.width=`${r}%`,this.cursor.style.left=`${r}%`,this.cursor.style.transform=`translateX(-${Math.round(r)===100?this.options.cursorWidth:0}px)`,this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(e,t)}exportImage(e,t,r){return Se(this,void 0,void 0,function*(){let s=this.canvasWrapper.querySelectorAll("canvas");if(!s.length)throw new Error("No waveform data");if(r==="dataURL"){let n=Array.from(s).map(o=>o.toDataURL(e,t));return Promise.resolve(n)}return Promise.all(Array.from(s).map(n=>new Promise((o,a)=>{n.toBlob(c=>{c?o(c):a(new Error("Could not export image"))},e,t)})))})}};zs.MAX_CANVAS_WIDTH=8e3,zs.MAX_NODES=10;var Ql=class extends Lr{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}},Us=class extends Lr{constructor(e=new AudioContext){super(),this.bufferNode=null,this.playStartTime=0,this.playedDuration=0,this._muted=!1,this._playbackRate=1,this._duration=void 0,this.buffer=null,this.currentSrc="",this.paused=!0,this.crossOrigin=null,this.seeking=!1,this.autoplay=!1,this.addEventListener=this.on,this.removeEventListener=this.un,this.audioContext=e,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}load(){return Se(this,void 0,void 0,function*(){})}get src(){return this.currentSrc}set src(e){if(this.currentSrc=e,this._duration=void 0,!e)return this.buffer=null,void this.emit("emptied");fetch(e).then(t=>{if(t.status>=400)throw new Error(`Failed to fetch ${e}: ${t.status} (${t.statusText})`);return t.arrayBuffer()}).then(t=>this.currentSrc!==e?null:this.audioContext.decodeAudioData(t)).then(t=>{this.currentSrc===e&&(this.buffer=t,this.emit("loadedmetadata"),this.emit("canplay"),this.autoplay&&this.play())})}_play(){var e;if(!this.paused)return;this.paused=!1,(e=this.bufferNode)===null||e===void 0||e.disconnect(),this.bufferNode=this.audioContext.createBufferSource(),this.buffer&&(this.bufferNode.buffer=this.buffer),this.bufferNode.playbackRate.value=this._playbackRate,this.bufferNode.connect(this.gainNode);let t=this.playedDuration*this._playbackRate;(t>=this.duration||t<0)&&(t=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,t),this.playStartTime=this.audioContext.currentTime,this.bufferNode.onended=()=>{this.currentTime>=this.duration&&(this.pause(),this.emit("ended"))}}_pause(){var e;this.paused=!0,(e=this.bufferNode)===null||e===void 0||e.stop(),this.playedDuration+=this.audioContext.currentTime-this.playStartTime}play(){return Se(this,void 0,void 0,function*(){this.paused&&(this._play(),this.emit("play"))})}pause(){this.paused||(this._pause(),this.emit("pause"))}stopAt(e){let t=e-this.currentTime,r=this.bufferNode;r?.stop(this.audioContext.currentTime+t),r?.addEventListener("ended",()=>{r===this.bufferNode&&(this.bufferNode=null,this.pause())},{once:!0})}setSinkId(e){return Se(this,void 0,void 0,function*(){return this.audioContext.setSinkId(e)})}get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate=e,this.bufferNode&&(this.bufferNode.playbackRate.value=e)}get currentTime(){return(this.paused?this.playedDuration:this.playedDuration+(this.audioContext.currentTime-this.playStartTime))*this._playbackRate}set currentTime(e){let t=!this.paused;t&&this._pause(),this.playedDuration=e/this._playbackRate,t&&this._play(),this.emit("seeking"),this.emit("timeupdate")}get duration(){var e,t;return(e=this._duration)!==null&&e!==void 0?e:((t=this.buffer)===null||t===void 0?void 0:t.duration)||0}set duration(e){this._duration=e}get volume(){return this.gainNode.gain.value}set volume(e){this.gainNode.gain.value=e,this.emit("volumechange")}get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this._muted?this.gainNode.disconnect():this.gainNode.connect(this.audioContext.destination))}canPlayType(e){return/^(audio|video)\//.test(e)}getGainNode(){return this.gainNode}getChannelData(){let e=[];if(!this.buffer)return e;let t=this.buffer.numberOfChannels;for(let r=0;r<t;r++)e.push(this.buffer.getChannelData(r));return e}},cS={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3},Ei=class i extends Zl{static create(e){return new i(e)}constructor(e){let t=e.media||(e.backend==="WebAudio"?new Us:void 0);super({media:t,mediaControls:e.mediaControls,autoplay:e.autoplay,playbackRate:e.audioRate}),this.plugins=[],this.decodedData=null,this.stopAtPosition=null,this.subscriptions=[],this.mediaSubscriptions=[],this.abortController=null,this.options=Object.assign({},cS,e),this.timer=new Ql;let r=t?void 0:this.getMediaElement();this.renderer=new zs(this.options,r),this.initPlayerEvents(),this.initRendererEvents(),this.initTimerEvents(),this.initPlugins();let s=this.options.url||this.getSrc()||"";Promise.resolve().then(()=>{this.emit("init");let{peaks:n,duration:o}=this.options;(s||n&&o)&&this.load(s,n,o).catch(()=>null)})}updateProgress(e=this.getCurrentTime()){return this.renderer.renderProgress(e/this.getDuration(),this.isPlaying()),e}initTimerEvents(){this.subscriptions.push(this.timer.on("tick",()=>{if(!this.isSeeking()){let e=this.updateProgress();this.emit("timeupdate",e),this.emit("audioprocess",e),this.stopAtPosition!=null&&this.isPlaying()&&e>=this.stopAtPosition&&this.pause()}}))}initPlayerEvents(){this.isPlaying()&&(this.emit("play"),this.timer.start()),this.mediaSubscriptions.push(this.onMediaEvent("timeupdate",()=>{let e=this.updateProgress();this.emit("timeupdate",e)}),this.onMediaEvent("play",()=>{this.emit("play"),this.timer.start()}),this.onMediaEvent("pause",()=>{this.emit("pause"),this.timer.stop(),this.stopAtPosition=null}),this.onMediaEvent("emptied",()=>{this.timer.stop(),this.stopAtPosition=null}),this.onMediaEvent("ended",()=>{this.emit("timeupdate",this.getDuration()),this.emit("finish"),this.stopAtPosition=null}),this.onMediaEvent("seeking",()=>{this.emit("seeking",this.getCurrentTime())}),this.onMediaEvent("error",()=>{var e;this.emit("error",(e=this.getMediaElement().error)!==null&&e!==void 0?e:new Error("Media error")),this.stopAtPosition=null}))}initRendererEvents(){this.subscriptions.push(this.renderer.on("click",(e,t)=>{this.options.interact&&(this.seekTo(e),this.emit("interaction",e*this.getDuration()),this.emit("click",e,t))}),this.renderer.on("dblclick",(e,t)=>{this.emit("dblclick",e,t)}),this.renderer.on("scroll",(e,t,r,s)=>{let n=this.getDuration();this.emit("scroll",e*n,t*n,r,s)}),this.renderer.on("render",()=>{this.emit("redraw")}),this.renderer.on("rendered",()=>{this.emit("redrawcomplete")}),this.renderer.on("dragstart",e=>{this.emit("dragstart",e)}),this.renderer.on("dragend",e=>{this.emit("dragend",e)}));{let e;this.subscriptions.push(this.renderer.on("drag",t=>{if(!this.options.interact)return;let r;this.renderer.renderProgress(t),clearTimeout(e),this.isPlaying()?r=0:this.options.dragToSeek===!0?r=200:typeof this.options.dragToSeek=="object"&&this.options.dragToSeek!==void 0&&(r=this.options.dragToSeek.debounceTime),e=setTimeout(()=>{this.seekTo(t)},r),this.emit("interaction",t*this.getDuration()),this.emit("drag",t)}))}}initPlugins(){var e;!((e=this.options.plugins)===null||e===void 0)&&e.length&&this.options.plugins.forEach(t=>{this.registerPlugin(t)})}unsubscribePlayerEvents(){this.mediaSubscriptions.forEach(e=>e()),this.mediaSubscriptions=[]}setOptions(e){this.options=Object.assign({},this.options,e),e.duration&&!e.peaks&&(this.decodedData=ra.createBuffer(this.exportPeaks(),e.duration)),e.peaks&&e.duration&&(this.decodedData=ra.createBuffer(e.peaks,e.duration)),this.renderer.setOptions(this.options),e.audioRate&&this.setPlaybackRate(e.audioRate),e.mediaControls!=null&&(this.getMediaElement().controls=e.mediaControls)}registerPlugin(e){if(this.plugins.includes(e))return e;e._init(this),this.plugins.push(e);let t=e.once("destroy",()=>{this.plugins=this.plugins.filter(r=>r!==e),this.subscriptions=this.subscriptions.filter(r=>r!==t)});return this.subscriptions.push(t),e}unregisterPlugin(e){this.plugins=this.plugins.filter(t=>t!==e),e.destroy()}getWrapper(){return this.renderer.getWrapper()}getWidth(){return this.renderer.getWidth()}getScroll(){return this.renderer.getScroll()}setScroll(e){return this.renderer.setScroll(e)}setScrollTime(e){let t=e/this.getDuration();this.renderer.setScrollPercentage(t)}getActivePlugins(){return this.plugins}loadAudio(e,t,r,s){return Se(this,void 0,void 0,function*(){var n;if(this.emit("load",e),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,this.stopAtPosition=null,!t&&!r){let a=this.options.fetchParams||{};window.AbortController&&!a.signal&&(this.abortController=new AbortController,a.signal=(n=this.abortController)===null||n===void 0?void 0:n.signal);let c=u=>this.emit("loading",u);t=yield aS.fetchBlob(e,c,a);let l=this.options.blobMimeType;l&&(t=new Blob([t],{type:l}))}this.setSrc(e,t);let o=yield new Promise(a=>{let c=s||this.getDuration();c?a(c):this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata",()=>a(this.getDuration()),{once:!0}))});if(!e&&!t){let a=this.getMediaElement();a instanceof Us&&(a.duration=o)}if(r)this.decodedData=ra.createBuffer(r,o||0);else if(t){let a=yield t.arrayBuffer();this.decodedData=yield ra.decode(a,this.options.sampleRate)}this.decodedData&&(this.emit("decode",this.getDuration()),this.renderer.render(this.decodedData)),this.emit("ready",this.getDuration())})}load(e,t,r){return Se(this,void 0,void 0,function*(){try{return yield this.loadAudio(e,void 0,t,r)}catch(s){throw this.emit("error",s),s}})}loadBlob(e,t,r){return Se(this,void 0,void 0,function*(){try{return yield this.loadAudio("",e,t,r)}catch(s){throw this.emit("error",s),s}})}zoom(e){if(!this.decodedData)throw new Error("No audio loaded");this.renderer.zoom(e),this.emit("zoom",e)}getDecodedData(){return this.decodedData}exportPeaks({channels:e=2,maxLength:t=8e3,precision:r=1e4}={}){if(!this.decodedData)throw new Error("The audio has not been decoded yet");let s=Math.min(e,this.decodedData.numberOfChannels),n=[];for(let o=0;o<s;o++){let a=this.decodedData.getChannelData(o),c=[],l=a.length/t;for(let u=0;u<t;u++){let h=a.slice(Math.floor(u*l),Math.ceil((u+1)*l)),d=0;for(let f=0;f<h.length;f++){let m=h[f];Math.abs(m)>Math.abs(d)&&(d=m)}c.push(Math.round(d*r)/r)}n.push(c)}return n}getDuration(){let e=super.getDuration()||0;return e!==0&&e!==1/0||!this.decodedData||(e=this.decodedData.duration),e}toggleInteraction(e){this.options.interact=e}setTime(e){this.stopAtPosition=null,super.setTime(e),this.updateProgress(e),this.emit("timeupdate",e)}seekTo(e){let t=this.getDuration()*e;this.setTime(t)}play(e,t){let r=Object.create(null,{play:{get:()=>super.play}});return Se(this,void 0,void 0,function*(){e!=null&&this.setTime(e);let s=yield r.play.call(this);return t!=null&&(this.media instanceof Us?this.media.stopAt(t):this.stopAtPosition=t),s})}playPause(){return Se(this,void 0,void 0,function*(){return this.isPlaying()?this.pause():this.play()})}stop(){this.pause(),this.setTime(0)}skip(e){this.setTime(this.getCurrentTime()+e)}empty(){this.load("",[[0]],.001)}setMediaElement(e){this.unsubscribePlayerEvents(),super.setMediaElement(e),this.initPlayerEvents()}exportImage(){return Se(this,arguments,void 0,function*(e="image/png",t=1,r="dataURL"){return this.renderer.exportImage(e,t,r)})}destroy(){var e;this.emit("destroy"),(e=this.abortController)===null||e===void 0||e.abort(),this.plugins.forEach(t=>t.destroy()),this.subscriptions.forEach(t=>t()),this.unsubscribePlayerEvents(),this.timer.destroy(),this.renderer.destroy(),super.destroy()}};Ei.BasePlugin=class extends Lr{constructor(i){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=i}onInit(){}_init(i){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=i,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(i=>i()),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}},Ei.dom=oS;var ia=class i{wavesurfer;constructor(e,t,r){this.wavesurfer=Ei.create({container:t,waveColor:"rgb(200, 0, 200)",progressColor:"rgb(100, 0, 100)",barWidth:10,barRadius:10,barGap:2,peaks:[e],duration:r})}static async init(e,t,r){let s=e.decodeAudio({source:t}).getReader(),n=[],o=[],a=1024,c=await e.getAudioDuration(t);for(;;){let{done:l,value:u}=await s.read();if(l)break;let h=u.numberOfFrames,d=new Float32Array(h);u.copyTo(d,{planeIndex:0});for(let f=0;f<d.length;f++)if(o.push(d[f]),o.length>=a){let m=o.splice(0,a),p=Math.min(...m),g=Math.max(...m);n.push(p,g)}u.close()}return new i(n,r,c??0)}set width(e){this.wavesurfer.setOptions({width:e})}};async function Pm(i){let e=document.querySelector(".waveform-demo"),t=document.querySelector(".width"),r=await ia.init(i,"/assets/temp/gl.mp4",e);t.addEventListener("change",()=>{let s=+t.value;r.width=s})}var sa=class i{videoTrack;options;#e;#t=new Map;#r=[0,0];constructor(e,t){this.videoTrack=e,this.options=t,this.#e=new Ms(e,t.canvasSinkOptions)}static async init(e,t){let s=await new St({formats:ur,source:await Gr(e)}).getPrimaryVideoTrack();if(s)return new i(s,{frequency:t.frequency??1,canvasSinkOptions:t.canvasSinkOptions??{width:80,height:50,fit:"fill"},onChange:t.onChange});throw new Error("Source has no video track")}set frequency(e){e!==this.options.frequency&&(this.options.frequency=e,this.#a())}get frequency(){return this.options.frequency}#i([e,t]){let r=t-e;return[e-r,t+r]}async#s(){let[e,t]=this.#r,r=new Set,s=await this.videoTrack.computeDuration();for(let c=e;c<=t;c+=this.options.frequency)c>=0&&c<=s&&r.add(+c.toFixed(3));let n=[...r].filter(c=>!this.#t.has(c)),o=0;for await(let c of this.#e.canvasesAtTimestamps(n))if(c){let l=n[o++];this.#t.set(l,c)}for(let c of this.#t.keys())r.has(c)||this.#t.delete(c);let a=[...this.#t.entries()].map(([c,l])=>({time:c,canvas:l}));this.options.onChange(a)}set range(e){let t=this.#i(e);this.#r[0]===t[0]&&this.#r[1]===t[1]||(this.#r=t,this.#a())}#n=null;#o=!1;async#a(){if(this.#n){this.#o=!0;return}this.#n=this.#s(),await this.#n,this.#n=null,this.#o&&(this.#o=!1,await this.#a())}getThumbnail(e){return this.#t.get(e)}};async function Cm(i){let e=document.querySelector(".range"),t=document.querySelector(".range-view"),r=document.querySelector(".range-size"),s=document.querySelector(".frequency"),n=document.querySelector(".frequency-view"),o=document.querySelector("#filmstrip"),a=1e3/10/1e3,c=.5,l=await sa.init(i,{onChange(u){let h=u.sort((d,f)=>d.time-f.time);o.replaceChildren(...h.map(({time:d,canvas:f})=>lS(d,f.canvas)))},frequency:a,canvasSinkOptions:{width:80,height:50,fit:"fill"}});r.addEventListener("change",()=>{c=+r.value;let[u,h]=[+e.value,+e.value+c];l.range=[u,h],t.textContent=`visible time range: [${u}, ${h}]`}),e.addEventListener("change",()=>{let[u,h]=[+e.value,+e.value+c];l.range=[u,h],t.textContent=`visible time range: [${u}, ${h}]`}),s.addEventListener("change",()=>{l.frequency=1e3/+s.value/1e3,n.textContent=`frame every ${l.frequency.toFixed(3)} second (${s.value} frames per second)`}),l.range=[10,10.5]}function lS(i,e){let t=document.createElement("div");t.style.position="relative",t.style.display="inline-block",t.style.marginRight="4px",t.appendChild(e);let r=document.createElement("div");return r.textContent=`${i.toFixed(2)}s`,r.style.position="absolute",r.style.top="2px",r.style.right="4px",r.style.fontSize="10px",r.style.color="white",r.style.background="rgba(0,0,0,0.6)",r.style.padding="2px 4px",r.style.borderRadius="4px",r.style.pointerEvents="none",t.appendChild(r),t}function Jl(i,e){let t={width:1920,height:1080},r=document.createElement("canvas");r.width=t.width,r.height=t.height;let s=r.getContext("2d");async function n(){let o=i.decodeVideo({source:e,async onFrame(c){let l=await i.composite([{kind:"image",frame:c},{kind:"text",content:"omnitool",fontSize:50,color:"green"}]);return c.close(),s?.drawImage(l,0,0),l}}),a=i.decodeAudio({source:e});await i.encode({video:o,audio:a,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}})}return{canvas:r,run:n}}var me;(function(i){i[i.Sequence=0]="Sequence",i[i.Stack=1]="Stack",i[i.Video=2]="Video",i[i.Audio=3]="Audio",i[i.Text=4]="Text",i[i.Gap=5]="Gap",i[i.Spatial=6]="Spatial",i[i.Transition=7]="Transition",i[i.TextStyle=8]="TextStyle"})(me||(me={}));var na;(function(i){i[i.Crossfade=0]="Crossfade"})(na||(na={}));var oa=class{datafile;duration=0;hasVideo=!1;hasAudio=!1;constructor(e){this.datafile=e}static async analyze(e){let t=new this(e);t.duration=10;let{video:r,audio:s}=await this.#e("/assets/temp/gl.mp4");return t.hasAudio=s,t.hasVideo=r,t}static async#e(e){let t=new St({formats:ur,source:await Gr(e)});return{audio:!!await t.getPrimaryAudioTrack(),video:!!await t.getPrimaryVideoTrack()}}};var aa=class{#e=new no;async store(e){let t=await oa.analyze(e),{hash:r}=t.datafile.checksum,{filename:s,bytes:n}=t.datafile;if(this.#e.has(r)){let o=this.#e.require(r);o.filename=s}else this.#e.set(r,{kind:"media",filename:s,bytes:n});return t}};function Em(i,e){let t,r,s=[];function n(){t=[],r&&clearTimeout(r),r=void 0,s=[]}return n(),(...o)=>{t=o,r&&clearTimeout(r);let a=new Promise((c,l)=>{s.push({resolve:c,reject:l})});return r=setTimeout(()=>{Promise.resolve().then(()=>e(...t)).then(c=>{for(let{resolve:l}of s)l(c);n()}).catch(c=>{for(let{reject:l}of s)l(c);n()})},i),a}}function Am(){let i,e,t=new Promise((s,n)=>{i=s,e=n});function r(s){return s.then(i).catch(e),t}return{promise:t,resolve:i,reject:e,entangle:r}}function uS(){let i=new Set;async function e(...c){await Promise.all([...i].map(l=>l(...c)))}function t(c){return i.add(c),()=>{i.delete(c)}}async function r(...c){return e(...c)}function s(c){return t(c)}async function n(c){let{promise:l,resolve:u}=Am(),h=s(async(...d)=>{c&&await c(...d),u(d),h()});return l}function o(){i.clear()}let a={pub:r,sub:s,publish:e,subscribe:t,on:t,next:n,clear:o};return Object.assign(s,a),Object.assign(r,a),a}function ca(i){let e=uS();return i&&e.sub(i),e.sub}var eu=class{#e=[];#t=new WeakMap;#r=[];#i=new Set;notifyRead(e){this.#e.at(-1)?.add(e)}async notifyWrite(e){if(this.#i.has(e))throw new Error("circularity forbidden");let t=this.#s(e).pub();return this.#r.at(-1)?.add(t),t}observe(e){this.#e.push(new Set);let t=e();return{seen:this.#e.pop(),result:t}}subscribe(e,t){return this.#s(e)(async()=>{let r=new Set;this.#r.push(r),this.#i.add(e),r.add(t()),this.#i.delete(e),await Promise.all(r),this.#r.pop()})}#s(e){let t=this.#t.get(e);return t||(t=ca(),this.#t.set(e,t)),t}},Ke=globalThis[Symbol.for("e280.tracker")]??=new eu;var Ai=class{sneak;constructor(e){this.sneak=e}get(){return Ke.notifyRead(this),this.sneak}get value(){return this.get()}};var Ii=class extends Ai{on=ca();dispose(){this.on.clear()}};function la(i,e=i){let{seen:t,result:r}=Ke.observe(i),s=Em(0,e),n=[],o=()=>n.forEach(a=>a());for(let a of t){let c=Ke.subscribe(a,s);n.push(c)}return{result:r,dispose:o}}function Mi(i,e){return i===e}var ua=class extends Ii{#e;constructor(e,t){let r=t?.compare??Mi,{result:s,dispose:n}=la(e,async()=>{let o=e();!r(this.sneak,o)&&(this.sneak=o,await Promise.all([Ke.notifyWrite(this),this.on.pub(o)]))});super(s),this.#e=n}toString(){return`(derived "${String(this.get())}")`}dispose(){super.dispose(),this.#e()}get core(){return this}fn(){let e=this;function t(){return e.get()}return t.core=e,t.get=e.get.bind(e),t.on=e.on,t.dispose=e.dispose.bind(e),t.fn=e.fn.bind(e),Object.defineProperty(t,"value",{get:()=>e.value}),Object.defineProperty(t,"sneak",{get:()=>e.sneak}),t}};var ha=class extends Ai{#e;#t;#r=!1;#i;constructor(e,t){super(void 0),this.#e=e,this.#t=t?.compare??Mi}toString(){return`($lazy "${String(this.get())}")`}get(){if(!this.#i){let{result:e,dispose:t}=la(this.#e,()=>this.#r=!0);this.#i=t,this.sneak=e}if(this.#r){this.#r=!1;let e=this.#e();!this.#t(this.sneak,e)&&(this.sneak=e,Ke.notifyWrite(this))}return super.get()}dispose(){this.#i&&this.#i()}get core(){return this}fn(){let e=this;function t(){return e.get()}return t.core=e,t.get=e.get.bind(e),t.dispose=e.dispose.bind(e),t.fn=e.fn.bind(e),Object.defineProperty(t,"value",{get:()=>e.value}),Object.defineProperty(t,"sneak",{get:()=>e.sneak}),t}};var da=class extends Ii{#e=!1;#t;constructor(e,t){super(e),this.#t=t?.compare??Mi}toString(){return`($signal "${String(this.get())}")`}async set(e,t=!1){let r=this.sneak;return this.sneak=e,(t||!this.#t(r,e))&&await this.publish(),e}get value(){return this.get()}set value(e){this.set(e)}async publish(){if(this.#e)throw new Error("forbid circularity");let e=this.sneak,t=Promise.resolve();try{this.#e=!0,t=Promise.all([Ke.notifyWrite(this),this.on.publish(e)])}finally{this.#e=!1}return await t,e}get core(){return this}fn(){let e=this;function t(r){return arguments.length===0?e.get():e.set(arguments[0])}return t.core=e,t.get=e.get.bind(e),t.set=e.set.bind(e),t.on=e.on,t.dispose=e.dispose.bind(e),t.publish=e.publish.bind(e),t.fn=e.fn.bind(e),Object.defineProperty(t,"value",{get:()=>e.value,set:r=>e.value=r}),Object.defineProperty(t,"sneak",{get:()=>e.sneak,set:r=>e.sneak=r}),t}};function hS(i,e){return new ha(i,e).fn()}function Im(i,e){return new ua(i,e).fn()}function Gs(i,e){return new da(i,e).fn()}Gs.lazy=hS;Gs.derived=Im;var Mm=(i,e)=>{let t=!1,r=null,s=60,n=1e3/s,o=0,a=0,c=0,l=0,u=h=>{if(!t)return;let d=h-a;for(a=h,c+=d,l+=d,e(l);c>=n;)i(o),o+=n,c-=n;r=requestAnimationFrame(u)};return{play(){t||(t=!0,a=performance.now(),r=requestAnimationFrame(u))},pause(){t&&(t=!1,r!==null&&cancelAnimationFrame(r),r=null)},seek(h){o=h,c=0,l=h,e(h)},dispose(){this.pause()},isPlaying(){return t},setFPS(h){s=h,n=1e3/s}}},Bm=async(i,e)=>{let t=1/i.fps,r=Math.ceil(i.duration*i.fps);for(let s=0;s<r&&!i.abort?.aborted;s++){let n=s*t;await e(n,s)}};var Fm=i=>i instanceof Blob?URL.createObjectURL(i):String(i);function Dm(i){let e=new Map,t=new Map;function r(o){let a=e.get(o.id);return a||(a=document.createElement("video"),a.playsInline=!0,a.muted=!0,a.preload="auto",a.crossOrigin="anonymous",a.src=Fm(i(o.mediaHash)),e.set(o.id,a)),a}function s(o){let a=t.get(o.id);return a||(a=document.createElement("audio"),a.preload="auto",a.crossOrigin="anonymous",a.src=Fm(i(o.mediaHash)),a.volume=.2,t.set(o.id,a)),a}let n=!0;return{async video(o,a){let c=r(o);return{duration:o.duration,visuals:{sampleAt:async l=>{if(l<0||l>=o.duration)return[];c.paused&&n&&await Rm(c,l/1e3),c.paused&&!n&&await c.play();let u=new VideoFrame(c);return u?[{kind:"image",frame:u,matrix:a}]:[]}}}},async audio(o){let a=s(o);return{duration:o.duration,audio:{onTimeUpdate:async c=>{let l=o.start+c;return a.paused&&n&&await Rm(a,l/1e3),a.paused&&!n&&await a.play(),[]}}}},async dispose(){let o=[...e.values(),...t.values()];for(let a of o)a.pause(),a.src.startsWith("blob:")&&URL.revokeObjectURL(a.src),a.remove();e.clear(),t.clear()},async setPaused(o){n=o;let a=[...e.values(),...t.values()];for(let c of a)o&&c.pause()}}}function Rm(i,e){return new Promise(t=>{let r=()=>{i.removeEventListener("seeked",r),t()};i.addEventListener("seeked",r),i.fastSeek?i.fastSeek(e):i.currentTime=e})}G();var Qw={extension:{type:A.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await Promise.resolve().then(()=>(Zw(),kk))}};G();var e_={extension:{type:A.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await Promise.resolve().then(()=>(Jw(),vk))}};G();Va();Oa();ih();He();N.add(Qw,e_);var t_=i=>{let[e,t,r]=i,[s,n]=e,[o,a]=t,c=r*Math.PI/180,l=Math.cos(c),u=Math.sin(c);return[l*o,u*o,-u*a,l*a,s,n]};var r_=(i,e)=>{let[t,r,s,n,o,a]=i,[c,l,u,h,d,f]=e;return[t*c+s*l,r*c+n*l,t*u+s*h,r*u+n*h,t*d+s*f+o,r*d+n*f+a]},i_=[1,0,0,1,0,0];var Ld=(i,e)=>i.get(e),jc=(i,e,t)=>{let r=t??i_;if(e.spatialId){let s=Ld(i,e.spatialId),n=t_(s.transform);r=r_(n,r)}return r},cs=class{items;sampler;constructor(e,t){this.items=e,this.sampler=t}async build(e,t){switch(e.kind){case me.Video:return this.sampler.video(e,jc(this.items,e,t));case me.Audio:return this.sampler.audio(e);case me.Text:{let r=jc(this.items,e,t);return{duration:e.duration,visuals:{sampleAt:async s=>s<0||s>=e.duration?[]:[{kind:"text",content:e.content,color:"white",fontSize:48,matrix:r}]}}}case me.Gap:return{duration:e.duration,visuals:{sampleAt:async()=>[]}};case me.Stack:{let r=jc(this.items,e,t),s=await Promise.all(e.childrenIds.map(n=>this.build(Ld(this.items,n),r)));return this.#r(s)}case me.Sequence:{let r=jc(this.items,e,t);return this.#i(e,r)}default:return{duration:0}}}#e(e){return{sampleAt:async t=>(await Promise.all(e.map(s=>s.visuals?s.visuals.sampleAt(t):Promise.resolve([])))).flat()}}#t(e){return{sampleAt:async t=>{let r=t;for(let s of e){if(r<s.duration)return s.visuals?s.visuals.sampleAt(r):[];r-=s.duration}return[]}}}#r(e){return{duration:Math.max(0,...e.map(r=>Number.isFinite(r.duration)?r.duration:0)),visuals:this.#e(e),audio:this.composeAudio_Stack(e)}}async#i(e,t){let r=e.childrenIds.map(o=>Ld(this.items,o)),s=await this.#s(r,t);return{duration:s.reduce((o,a)=>o+a.duration,0),visuals:this.#t(s),audio:this.composeAudio_Sequence(s)}}async#s(e,t){let r=[];for(let s=0;s<e.length;s++){let n=e[s];if(n.kind!==me.Transition){r.push(await this.build(n,t));continue}let o=r.pop(),a=e[s+1];if(!o||!a||a.kind===me.Transition){o&&r.push(o);continue}let c=await this.build(a,t),l=await this.#n(n,o,c);r.push(l),s++}return r}async#n(e,t,r){let s=Math.max(0,Math.min(e.duration,t.duration,r.duration)),n=Math.max(0,t.duration-s);return{duration:t.duration+r.duration-s,visuals:{sampleAt:async a=>{if(!t.visuals||!r.visuals)return[];if(a<n)return t.visuals.sampleAt(a);if(a<t.duration){let c=a-n,l=s>0?c/s:1,u=await t.visuals.sampleAt(a),h=await r.visuals.sampleAt(c);return!u[0]?.frame||!h[0]?.frame?[]:[{kind:"transition",name:"circle",progress:l,from:u[0].frame,to:h[0].frame}]}return r.visuals.sampleAt(a-t.duration+s)}},audio:this.composeAudio_Sequence([t,r])}}};var Nd=class extends cs{items;sampler;constructor(e,t){super(e,t),this.items=e,this.sampler=t}composeAudio_Stack(e){return{onTimeUpdate:t=>{for(let r of e)r.audio&&r.audio.onTimeUpdate(t)}}}composeAudio_Sequence(e){return{onTimeUpdate:t=>{let r=t;for(let s of e){if(r<s.duration){s.audio&&s.audio.onTimeUpdate(r);break}r-=s.duration}}}}};function s_(i,e,t){return new Nd(e,t).build(i)}var $c=class{driver;canvas;root;sampler;resolveMedia;currentTime=Gs(0);#e=Mm(e=>this.#t(e),e=>this.currentTime(e));constructor(e,t,r,s,n=o=>"/assets/temp/gl.mp4"){this.driver=e,this.canvas=t,this.root=r,this.sampler=s,this.resolveMedia=n,this.#e.setFPS(30)}get context(){return this.canvas.getContext("2d")}static async create(e,t){let r=new Map(t.items.map(c=>[c.id,c])).get(t.rootId),s=new Map(t.items.map(c=>[c.id,c])),n=Dm(()=>"/assets/temp/gl.mp4"),o=await s_(r,s,n),a=document.createElement("canvas");return a.width=1920,a.height=1080,new this(e,a,o,n)}async#t(e){let t=this.root.duration,r=e>t?t:e;this.root.audio?.onTimeUpdate(r);let s=await this.root.visuals?.sampleAt(r)??[],n=await this.driver.composite(s);this.context.drawImage(n,0,0),n.close(),e>=t&&this.pause()}async play(){this.#e.isPlaying()||(this.sampler.setPaused(!1),this.#e.play())}pause(){this.#e.isPlaying()&&(this.#e.pause(),this.sampler.setPaused(!0))}async seek(e){this.pause(),this.#e.seek(e),this.root.audio?.onTimeUpdate(e);let t=await this.root.visuals?.sampleAt(e)??[],r=await this.driver.composite(t);this.context.drawImage(r,0,0),r.close()}setFPS(e){this.#e.setFPS(e)}};var qc=class{state;#e=0;constructor(e){this.state=e}require(e){return e===void 0?void 0:this.state.project.items.find(r=>r.id===e)}#t(){return this.#e++}#r(e){this.state.project=e(this.state.project)}textStyle=e=>({id:this.#t(),kind:me.TextStyle,style:e});spatial=e=>({id:this.#t(),kind:me.Spatial,transform:e});sequence=(...e)=>{let t={id:this.#t(),kind:me.Sequence,childrenIds:e.map(r=>r.id)};return this.#r(r=>(r.items.push(t,...e),r)),t};stack=(...e)=>{let t={kind:me.Stack,id:this.#t(),childrenIds:e.map(r=>r.id)};return this.#r(r=>(r.items.push(t,...e),r)),t};video=(e,t)=>{if(!e.hasVideo)throw new Error(`Video clip error: media "${e.datafile.filename}" has no video track.`);return{kind:me.Video,id:this.#t(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration}};audio=(e,t)=>{if(!e.hasAudio)throw new Error(`Audio clip error: media "${e.datafile.filename}" has no audio track.`);return{kind:me.Audio,id:this.#t(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration}};text=e=>({id:this.#t(),content:e,kind:me.Text,duration:2e3});gap=e=>({id:this.#t(),kind:me.Gap,duration:e});transition={crossfade:e=>({id:this.#t(),kind:me.Transition,effect:na.Crossfade,duration:e})};transform=e=>{let t=[e?.position?.[0]??0,e?.position?.[1]??0],r=[e?.scale?.[0]??1,e?.scale?.[1]??1],s=e?.rotation??0;return[t,r,s]};addChildren(e,...t){this.#r(r=>(r.items.find(({id:n})=>n===e.id).childrenIds.push(...t.map(n=>n.id)),r.items.push(...t),r))}update=(e,t,r)=>{this.#r(s=>{let n=s.items.map(o=>o.id===e?{...o,[t]:r}:o);return{...s,items:n}})}};var Xc=class{reader;constructor(e){this.reader=e}async atOrNear(e){let t=null;for(;;){let{done:r,value:s}=await this.reader.read();if(r){let o=t?new VideoFrame(t):void 0;return t?.close(),o}let n=s.timestamp??0;if(n>=e){let o=t?.timestamp??Number.NEGATIVE_INFINITY,a=!!t&&Math.abs(o-e)<Math.abs(n-e),c=a?t:s,l=a?s:t,u=new VideoFrame(c);return c.close(),l?.close(),u}t?.close(),t=s}}cancel=async()=>await this.reader.cancel()};var Yc=class{reader;constructor(e){this.reader=e}async*stream(){for(;;){let{done:e,value:t}=await this.reader.read();if(e)break;yield t}}cancel=async()=>await this.reader.cancel()};var n_=i=>Math.round(i*1e6);function o_(i,e){let t=new Map;async function r(s){let n=t.get(s.id);if(n)return n;let o=e(s.mediaHash),a=i.decodeVideo({source:o}),c=new Xc(a.getReader());return t.set(s.id,c),c}return{async video(s,n){let o=await r(s),a=n_(s.start??0);return{duration:s.duration,visuals:{sampleAt:async c=>{let l=await o.atOrNear(a+n_(c));return l?[{kind:"image",frame:l,matrix:n}]:[]}}}},async audio(s){return{duration:s.duration,audio:{getStream:async function*(){let n=e(s.mediaHash),o=s.start,a=s.start+s.duration,c=i.decodeAudio({source:n,start:o,end:a});yield*new Yc(c.getReader()).stream()}}}},async dispose(){let s=Array.from([...t.values()],n=>n.cancel());t.clear(),await Promise.all(s)}}}var Vd=class extends cs{composeAudio_Stack(e){return{getStream:async function*(){for(let t of e)t.audio&&(yield*t.audio.getStream())}}}composeAudio_Sequence(e){return{getStream:async function*(){for(let t of e)t.audio&&(yield*t.audio.getStream())}}}};function a_(i,e,t){return new Vd(e,t).build(i)}var Kc=class{driver;framerate;resolveMedia;#e;constructor(e,t=30,r=s=>"/assets/temp/gl.mp4"){this.driver=e,this.framerate=t,this.resolveMedia=r,this.#e=o_(this.driver,this.resolveMedia)}async#t(e){let t=new Map(e.items.map(s=>[s.id,s])).get(e.rootId),r=new Map(e.items.map(s=>[s.id,s]));return await a_(t,r,this.#e)}async render(e){let t=await this.#t(e),r=new TransformStream,s=new TransformStream,n=this.driver.encode({video:r.readable,audio:s.readable,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}}),o=r.writable.getWriter(),a=s.writable.getWriter(),c=(async()=>{if(t.audio)for await(let u of t.audio.getStream())await a.write(u);await a.close()})(),l=(async()=>{let u=0,h=1/this.framerate;await Bm({fps:this.framerate,duration:t.duration??0},async d=>{let f=await t.visuals?.sampleAt(d)??[],m=await this.driver.composite(f),p=new VideoFrame(m,{timestamp:Math.round(u*h*1e6),duration:Math.round(h*1e6)});await o.write(p),m.close(),u++}),await o.close()})();await c,await l,await n}};var Zc=class{driver;resources=new aa;#e;constructor(e){this.driver=e,this.#e=new Kc(e)}load=async e=>Object.fromEntries(await Promise.all(Object.entries(e).map(async([t,r])=>[t,await this.resources.store(await r)])));timeline=e=>{let t=new qc({project:{format:"timeline",info:"https://omniclip.app/",version:0,items:[],rootId:0}}),r=e(t);return t.state.project.rootId=r.id,t.state.project};render=async(e,t)=>{await this.#e.render(e)}};var Qc=class{data;bytes;hash;nickname;constructor(e,t,r,s){this.data=e,this.bytes=t,this.hash=r,this.nickname=s}static async make(e){let t=new Uint8Array(e),r=new Uint8Array(await crypto.subtle.digest("SHA-256",t)),s=Ne.fromBytes(r),n=ot.sigil.fromBytes(r);return new this(e,r,s,n)}};var Jc=class{bytes;filename;checksum;constructor(e,t,r){this.bytes=e,this.filename=t,this.checksum=r}static async make(e,t){let r=await Qc.make(e),s=t??r.nickname;return new this(e,s,r)}static async load(e){throw new Error("TODO implement")}};var si=await ta.setup({workerUrl:new URL("../driver/driver.worker.bundle.min.js",import.meta.url)}),Pk=document.querySelector(".results"),Ck=document.querySelector(".fetch"),Ek=document.querySelector(".import"),Ak=document.querySelector(".play"),Ik=document.querySelector(".stop"),Mk=document.querySelector(".seek");Ck?.addEventListener("click",Uk);Ek?.addEventListener("click",Ok);var c_=new Zc(si),Bk=await fetch("/assets/temp/gl.mp4"),Fk=await Bk.arrayBuffer(),Rk=new Uint8Array(Fk),{videoA:Wd}=await c_.load({videoA:Jc.make(Rk)}),Dk=c_.timeline(i=>i.sequence(i.stack(i.video(Wd,{duration:5e3}),i.audio(Wd,{duration:8e3})),i.video(Wd,{duration:7e3}))),el=await $c.create(si,Dk);document.body.appendChild(el.canvas);Ak.addEventListener("click",()=>el.play());Ik.addEventListener("click",()=>el.pause());Mk.addEventListener("change",async i=>{let e=i.target;await el.seek(+e.value)});Pm(si);await si.thread.work.hello(),si.machina.count===1?console.log("\u2705 driver works"):console.error("\u274C FAIL driver call didn't work");async function Ok(){let[i]=await window.showOpenFilePicker(),e=await i.getFile(),t=Jl(si,e);await Cm(e),l_(t,i.name)}async function Uk(){let i=["/assets/temp/gl.mp4"];for(let e of i){let t=Jl(si,"/assets/temp/gl.mp4");l_(t,e)}}async function l_(i,e){let t=document.createElement("div");Pk.append(t);let r=document.createElement("p");r.textContent=e,t.append(r),t.append(i.canvas),await i.run()}
648
648
  /*! Bundled license information:
649
649
 
650
650
  mediabunny/dist/modules/src/misc.js: