@omnimedia/omnitool 1.1.0-41 → 1.1.0-42

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-41",
3
+ "version": "1.1.0-42",
4
4
  "description": "open source video processing tools",
5
5
  "license": "MIT",
6
6
  "author": "Przemysław Gałęzki",
package/s/index.html.ts CHANGED
@@ -29,6 +29,7 @@ export default ssg.page(import.meta.url, async orb => ({
29
29
  body: html`
30
30
  <section>
31
31
  <h1>Omnitool <small>v${orb.packageVersion()}</small></h1>
32
+ <button class=export>export</button>
32
33
  <button class=fetch>fetch</button>
33
34
  <input type="file" class="file-input">
34
35
  <div class=results></div>
@@ -33,8 +33,11 @@ export const getWorldMat6 = (
33
33
  let world = parent ?? I6
34
34
  if (item.spatialId) {
35
35
  const spatial = requireItem(items, item.spatialId) as Item.Spatial
36
- const local = transformToMat6(spatial.transform)
37
- world = mul6(local, world)
36
+ if(spatial.enabled) {
37
+ // reason we put transfrom to matrix is because its easier to calculate
38
+ const local = transformToMat6(spatial.transform)
39
+ world = mul6(local, world)
40
+ }
38
41
  }
39
42
  return world
40
43
  }
@@ -30,6 +30,7 @@ export namespace Item {
30
30
  id: Id
31
31
  kind: Kind.Spatial
32
32
  transform: Transform
33
+ enabled: boolean
33
34
  }
34
35
 
35
36
  export type Gap = {
@@ -45,7 +45,8 @@ export class O {
45
45
  const item: Item.Spatial = {
46
46
  id: this.#getId(),
47
47
  kind: Kind.Spatial,
48
- transform
48
+ transform,
49
+ enabled: true
49
50
  }
50
51
  this.register(item)
51
52
  return item
@@ -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),k=Math.abs(o[_]||0);T>x&&(x=T),k>w&&(w=k)}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)})))})}};Ns.MAX_CANVAS_WIDTH=8e3,Ns.MAX_NODES=10;var Jl=class extends Vr{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}},Gs=class extends Vr{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}},pS={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3},Ii=class i extends Ql{static create(e){return new i(e)}constructor(e){let t=e.media||(e.backend==="WebAudio"?new Gs: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({},pS,e),this.timer=new Jl;let r=t?void 0:this.getMediaElement();this.renderer=new Ns(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=ia.createBuffer(this.exportPeaks(),e.duration)),e.peaks&&e.duration&&(this.decodedData=ia.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 mS.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 Gs&&(a.duration=o)}if(r)this.decodedData=ia.createBuffer(r,o||0);else if(t){let a=yield t.arrayBuffer();this.decodedData=yield ia.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 Gs?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()}};Ii.BasePlugin=class extends Vr{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}},Ii.dom=fS;var sa=class i{wavesurfer;constructor(e,t,r){this.wavesurfer=Ii.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 Bm(i){let e=document.querySelector(".waveform-demo"),t=document.querySelector(".width"),r=await sa.init(i,"/assets/temp/gl.mp4",e);t.addEventListener("change",()=>{let s=+t.value;r.width=s})}var na=class i{videoTrack;options;#e;#t=new Map;#r=[0,0];constructor(e,t){this.videoTrack=e,this.options=t,this.#e=new Fs(e,t.canvasSinkOptions)}static async init(e,t){let s=await new _t({formats:hr,source:await Lr(e)}).getPrimaryVideoTrack();if(s)return new i(s,{frequency:t.frequency??1,canvasSinkOptions:t.canvasSinkOptions??{width:80,height:50,fit:"fill"},onChange:t.onChange,onPlaceholders:t.onPlaceholders});throw new Error("Source has no video track")}set frequency(e){e!==this.options.frequency&&(this.options.frequency=e,this.#c())}get frequency(){return this.options.frequency}#i([e,t],r=1){let s=t-e;return[e-s*r,t+s*r]}async#s(){let[e,t]=this.#r,r=new Set,s=await this.videoTrack.computeDuration();for(let n=Math.max(0,e);n<=t;n+=this.options.frequency)n>=0&&n<=s&&r.add(n);this.options.onPlaceholders?.([...r])}async#o(){let[e,t]=this.#r,r=new Set,s=await this.videoTrack.computeDuration();for(let c=Math.max(0,e);c<=t;c+=this.options.frequency)c>=0&&c<=s&&r.add(c);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,r]=e,s=r-t,[n,o]=this.#r,a=n+s,c=o-s,l=t<a,u=r>c;!l&&!u||(this.#r=this.#i(e,2),this.#c())}#n=null;#a=!1;async#c(){if(this.#s(),this.#n){this.#a=!0;return}this.#n=this.#o(),await this.#n,this.#n=null,this.#a&&(this.#a=!1,await this.#c())}getThumbnail(e){return this.#t.get(e)}};async function Fm(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 na.init(i,{onChange(u){let h=u.sort((d,f)=>d.time-f.time);o.replaceChildren(...h.map(({time:d,canvas:f})=>gS(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 gS(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 eu(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",style:{fontSize:50,fill:"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 oa;(function(i){i[i.Crossfade=0]="Crossfade"})(oa||(oa={}));var aa=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 _t({formats:hr,source:await Lr(e)});return{audio:!!await t.getPrimaryAudioTrack(),video:!!await t.getPrimaryVideoTrack()}}};var Mi=Object.freeze({eq(i,e){if(i.length!==e.length)return!1;for(let t=0;t<=i.length;t++)if(i.at(t)!==e.at(t))return!1;return!0},random(i){return crypto.getRandomValues(new Uint8Array(i))}});var Te=class{lexicon;static lexicons=Object.freeze({base2:{characters:"01"},hex:{characters:"0123456789abcdef"},base36:{characters:"0123456789abcdefghijklmnopqrstuvwxyz"},base58:{characters:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"},base62:{characters:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"},base64url:{negativePrefix:"~",characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"},base64:{characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",padding:{character:"=",size:4}}});lookup;negativePrefix;constructor(e){this.lexicon=e,this.lookup=Object.fromEntries([...e.characters].map((t,r)=>[t,r])),this.negativePrefix=e.negativePrefix??"-"}toBytes(e){let t=Math.log2(this.lexicon.characters.length);if(Number.isInteger(t)){let a=0,c=0,l=[];for(let u of e){if(u===this.lexicon.padding?.character)continue;let h=this.lookup[u];if(h===void 0)throw new Error(`Invalid character: ${u}`);for(a=a<<t|h,c+=t;c>=8;)c-=8,l.push(a>>c&255)}return new Uint8Array(l)}let r=0n,s=BigInt(this.lexicon.characters.length),n=!1;e.startsWith(this.negativePrefix)&&(e=e.slice(this.negativePrefix.length),n=!0);for(let a of e){let c=this.lookup[a];if(c===void 0)throw new Error(`Invalid character: ${a}`);r=r*s+BigInt(c)}let o=[];for(;r>0n;)o.unshift(Number(r%256n)),r=r/256n;return new Uint8Array(o)}fromBytes(e){let t=Math.log2(this.lexicon.characters.length);if(Number.isInteger(t)){let o=0,a=0,c="";for(let l of e)for(o=o<<8|l,a+=8;a>=t;){a-=t;let u=o>>a&(1<<t)-1;c+=this.lexicon.characters[u]}if(a>0){let l=o<<t-a&(1<<t)-1;c+=this.lexicon.characters[l]}if(this.lexicon.padding)for(;c.length%this.lexicon.padding.size!==0;)c+=this.lexicon.padding.character;return c}let r=0n;for(let o of e)r=(r<<8n)+BigInt(o);if(r===0n)return this.lexicon.characters[0];let s=BigInt(this.lexicon.characters.length),n="";for(;r>0n;)n=this.lexicon.characters[Number(r%s)]+n,r=r/s;return n}toInteger(e){if(!e)return 0;let t=0n,r=!1,s=BigInt(this.lexicon.characters.length);e.startsWith(this.negativePrefix)&&(e=e.slice(this.negativePrefix.length),r=!0);for(let n of e){let o=this.lookup[n];if(o===void 0)throw new Error(`Invalid character: ${n}`);t=t*s+BigInt(o)}return Number(r?-t:t)}fromInteger(e){e=Math.floor(e);let t=e<0,r=BigInt(t?-e:e);if(r===0n)return this.lexicon.characters[0];let s=BigInt(this.lexicon.characters.length),n="";for(;r>0n;)n=this.lexicon.characters[Number(r%s)]+n,r=r/s;return t?`${this.negativePrefix}${n}`:n}random(e=32){return this.fromBytes(Mi.random(e))}};var St=new Te(Te.lexicons.hex),xR=new Te(Te.lexicons.base2),yR=new Te(Te.lexicons.base36),tu=new Te(Te.lexicons.base58),bR=new Te(Te.lexicons.base62),wR=new Te(Te.lexicons.base64),_R=new Te(Te.lexicons.base64url);var ru=["doz","mar","bin","wan","sam","lit","sig","hid","fid","lis","sog","dir","wac","sab","wis","sib","rig","sol","dop","mod","fog","lid","hop","dar","dor","lor","hod","fol","rin","tog","sil","mir","hol","pas","lac","rov","liv","dal","sat","lib","tab","han","tic","pid","tor","bol","fos","dot","los","dil","for","pil","ram","tir","win","tad","bic","dif","roc","wid","bis","das","mid","lop","ril","nar","dap","mol","san","loc","nov","sit","nid","tip","sic","rop","wit","nat","pan","min","rit","pod","mot","tam","tol","sav","pos","nap","nop","som","fin","fon","ban","mor","wor","sip","ron","nor","bot","wic","soc","wat","dol","mag","pic","dav","bid","bal","tim","tas","mal","lig","siv","tag","pad","sal","div","dac","tan","sid","fab","tar","mon","ran","nis","wol","mis","pal","las","dis","map","rab","tob","rol","lat","lon","nod","nav","fig","nom","nib","pag","sop","ral","bil","had","doc","rid","moc","pac","rav","rip","fal","tod","til","tin","hap","mic","fan","pat","tac","lab","mog","sim","son","pin","lom","ric","tap","fir","has","bos","bat","poc","hac","tid","hav","sap","lin","dib","hos","dab","bit","bar","rac","par","lod","dos","bor","toc","hil","mac","tom","dig","fil","fas","mit","hob","har","mig","hin","rad","mas","hal","rag","lag","fad","top","mop","hab","nil","nos","mil","fop","fam","dat","nol","din","hat","nac","ris","fot","rib","hoc","nim","lar","fit","wal","rap","sar","nal","mos","lan","don","dan","lad","dov","riv","bac","pol","lap","tal","pit","nam","bon","ros","ton","fod","pon","sov","noc","sor","lav","mat","mip","fip"];var iu=["zod","nec","bud","wes","sev","per","sut","let","ful","pen","syt","dur","wep","ser","wyl","sun","ryp","syx","dyr","nup","heb","peg","lup","dep","dys","put","lug","hec","ryt","tyv","syd","nex","lun","mep","lut","sep","pes","del","sul","ped","tem","led","tul","met","wen","byn","hex","feb","pyl","dul","het","mev","rut","tyl","wyd","tep","bes","dex","sef","wyc","bur","der","nep","pur","rys","reb","den","nut","sub","pet","rul","syn","reg","tyd","sup","sem","wyn","rec","meg","net","sec","mul","nym","tev","web","sum","mut","nyx","rex","teb","fus","hep","ben","mus","wyx","sym","sel","ruc","dec","wex","syr","wet","dyl","myn","mes","det","bet","bel","tux","tug","myr","pel","syp","ter","meb","set","dut","deg","tex","sur","fel","tud","nux","rux","ren","wyt","nub","med","lyt","dus","neb","rum","tyn","seg","lyx","pun","res","red","fun","rev","ref","mec","ted","rus","bex","leb","dux","ryn","num","pyx","ryg","ryx","fep","tyr","tus","tyc","leg","nem","fer","mer","ten","lus","nus","syl","tec","mex","pub","rym","tuc","fyl","lep","deb","ber","mug","hut","tun","byl","sud","pem","dev","lur","def","bus","bep","run","mel","pex","dyt","byt","typ","lev","myl","wed","duc","fur","fex","nul","luc","len","ner","lex","rup","ned","lec","ryd","lyd","fen","wel","nyd","hus","rel","rud","nes","hes","fet","des","ret","dun","ler","nyr","seb","hul","ryl","lud","rem","lys","fyn","wer","ryc","sug","nys","nyl","lyn","dyn","dem","lux","fed","sed","bec","mun","lyr","tes","mud","nyt","byr","sen","weg","fyr","mur","tel","rep","teg","pec","nel","nev","fes"];var $t={defaults:{groupSize:4,wordSeparator:".",groupSeparator:" "},random(i,e){let t=Mi.random(i);return this.fromBytes(t,e)},fromBytes(i,e={}){let{groupSize:t=$t.defaults.groupSize,wordSeparator:r=$t.defaults.wordSeparator,groupSeparator:s=$t.defaults.groupSeparator}=e,n=[],o=[];i.forEach((c,l)=>{let u=l%2===0?ru:iu;o.push(u[c]),o.length===2&&(n.push(o.join("")),o=[])}),o.length&&n.push(o.join(""));let a=[];for(let c=0;c<n.length;c+=t)a.push(n.slice(c,c+t).join(r));return a.join(s)},toBytes(i){let e=i.toLowerCase().replace(/[^a-z]/g,"");if(e.length/3%1!==0)throw new Error(`invalid triplet count, ${e.length} does not divide into triplets`);let r=[];for(let s=0;s<e.length;s+=3)r.push(e.slice(s,s+3));return new Uint8Array(r.map((s,n)=>{let a=(n%2===0?ru:iu).findIndex(c=>c===s);if(a===-1)throw new Error(`unknown triplet ${s}`);return a}))},toHex(i){return St.fromBytes($t.toBytes(i))},fromHex(i,e){return $t.fromBytes(St.toBytes(i),e)}};var Tt={defaults:{delimiter:".",sigilBytes:4,previewBytes:8},toBytes(i){i=i.trim();let e=i.split(/[^a-zA-Z0-9]+/m).filter(Boolean).map(s=>s.trim());if(e.length<2)return $t.toBytes(e.join(""));let t=e.pop(),r=e.join("");return new Uint8Array([...$t.toBytes(r),...tu.toBytes(t)])},parse(i,e){let t=Tt.toBytes(i);return Tt.build.fromBytes(t,e)},build:{fromBytes(i,e={}){let{delimiter:t,previewBytes:r,sigilBytes:s}={...Tt.defaults,...e},n=u=>i.length>0?$t.fromBytes(i.slice(0,u),{wordSeparator:t,groupSeparator:t}):"",o=n(s),a=n(r),c=i.length>r?tu.fromBytes(i.slice(r)):"",l=[a,c].filter(u=>u.length>0).join(t);return{raw:i,full:l,preview:a,bulk:c,sigil:o,bytes:i,thumbprint:l}},fromHex(i,e){let t=St.toBytes(i);return Tt.build.fromBytes(t,e)}},toHex(i){let e=Tt.toBytes(i);return St.fromBytes(e)},fromBytes(i,e){return Tt.build.fromBytes(i,e).full},fromHex(i,e){return Tt.fromBytes(St.toBytes(i),e)},sigil:{fromHex(i,e){return Tt.build.fromHex(i,e).sigil},fromBytes(i,e){return Tt.build.fromBytes(i,e).sigil}}},Rm=Tt;var ca=Object.freeze({fromBytes(i){return[...i].map(e=>e.toString(16).padStart(2,"0")).join("")},toBytes(i){if(i.length%2!==0)throw new Error("must have even number of hex characters");let e=new Uint8Array(i.length/2);for(let t=0;t<i.length;t+=2)e[t/2]=parseInt(i.slice(t,t+2),16);return e},random(i=32){return this.fromBytes(Mi.random(i))},string(i){return ca.fromBytes(i)},bytes(i){return ca.toBytes(i)}});function Dm(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}}var su=class i extends Map{static require(e,t){if(e.has(t))return e.get(t);throw new Error(`required key not found: "${t}"`)}static guarantee(e,t,r){if(e.has(t))return e.get(t);{let s=r();return e.set(t,s),s}}array(){return[...this]}require(e){return i.require(this,e)}guarantee(e,t){return i.guarantee(this,e,t)}},Om=su;function zm(){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 xS(){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}=zm(),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 la(i){let e=xS();return i&&e.sub(i),e.sub}var ua=class{#e=new Om;async store(e){let t=await aa.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}};var nu=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=la(),this.#t.set(e,t)),t}},Ke=globalThis[Symbol.for("e280.tracker")]??=new nu;var Bi=class{sneak;constructor(e){this.sneak=e}get(){return Ke.notifyRead(this),this.sneak}get value(){return this.get()}};var Fi=class extends Bi{on=la();dispose(){this.on.clear()}};function ha(i,e=i){let{seen:t,result:r}=Ke.observe(i),s=Dm(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 Ri(i,e){return i===e}var da=class extends Fi{#e;constructor(e,t){let r=t?.compare??Ri,{result:s,dispose:n}=ha(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 fa=class extends Bi{#e;#t;#r=!1;#i;constructor(e,t){super(void 0),this.#e=e,this.#t=t?.compare??Ri}toString(){return`($lazy "${String(this.get())}")`}get(){if(!this.#i){let{result:e,dispose:t}=ha(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 ma=class extends Fi{#e=!1;#t;constructor(e,t){super(e),this.#t=t?.compare??Ri}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 yS(i,e){return new fa(i,e).fn()}function Um(i,e){return new da(i,e).fn()}function Ls(i,e){return new ma(i,e).fn()}Ls.lazy=yS;Ls.derived=Um;var Gm=(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}}},Nm=async(i,e)=>{let t=1e3/i.fps,r=i.duration/1e3,s=Math.ceil(r*i.fps);for(let n=0;n<s&&!i.abort?.aborted;n++){let o=n*t;await e(o,n)}};var Lm=i=>i instanceof Blob?URL.createObjectURL(i):String(i);function Wm(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=Lm(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=Lm(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 Vm(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 Vm(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 Vm(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 o_={extension:{type:A.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await Promise.resolve().then(()=>(n_(),Mv))}};G();var c_={extension:{type:A.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await Promise.resolve().then(()=>(a_(),Bv))}};G();Ha();Ua();ch();He();L.add(o_,c_);var l_=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 u_=(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]},h_=[1,0,0,1,0,0];var jd=(i,e)=>i.get(e),qc=(i,e,t)=>{let r=t??h_;if(e.spatialId){let s=jd(i,e.spatialId),n=l_(s.transform);r=u_(n,r)}return r},hs=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,qc(this.items,e,t));case me.Audio:return this.sampler.audio(e);case me.Text:{let r=qc(this.items,e,t),s=e.styleId!==void 0?this.items.get(e.styleId):void 0;return{duration:e.duration,visuals:{sampleAt:async n=>n<0||n>=e.duration?[]:[{kind:"text",content:e.content,style:s?.style,matrix:r}]}}}case me.Gap:return{duration:e.duration,visuals:{sampleAt:async()=>[]}};case me.Stack:{let r=qc(this.items,e,t),s=await Promise.all(e.childrenIds.map(n=>this.build(jd(this.items,n),r)));return this.#r(s)}case me.Sequence:{let r=qc(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=>jd(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.#o(n,o,c);r.push(l),s++}return r}async#o(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 $d=class extends hs{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 qd(i,e,t){return new $d(e,t).build(i)}var Xc=class{driver;canvas;root;sampler;resolveMedia;currentTime=Ls(0);#e=Gm(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=Wm(()=>"/assets/temp/gl.mp4"),o=await qd(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)}async update(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]));this.root=await qd(t,r,this.sampler),await this.seek(this.currentTime())}};var Yc=class{state;constructor(e){this.state=e}require(e){return e===void 0?void 0:this.state.project.items.find(r=>r.id===e)}#e(){return St.toInteger(St.random())}#t(e){this.state.project=e(this.state.project)}register(e){this.#t(t=>({...t,items:[...t.items,e]}))}textStyle=e=>{let t={id:this.#e(),kind:me.TextStyle,style:e};return this.register(t),t};spatial=e=>{let t={id:this.#e(),kind:me.Spatial,transform:e};return this.register(t),t};sequence=(...e)=>{let t={id:this.#e(),kind:me.Sequence,childrenIds:e.map(r=>r.id)};return this.register(t),t};stack=(...e)=>{let t={kind:me.Stack,id:this.#e(),childrenIds:e.map(r=>r.id)};return this.register(t),t};video=(e,t)=>{if(!e.hasVideo)throw new Error(`Video clip error: media "${e.datafile.filename}" has no video track.`);let r={kind:me.Video,id:this.#e(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration};return this.register(r),r};audio=(e,t)=>{if(!e.hasAudio)throw new Error(`Audio clip error: media "${e.datafile.filename}" has no audio track.`);let r={kind:me.Audio,id:this.#e(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration};return this.register(r),r};text=e=>{let t={id:this.#e(),content:e,kind:me.Text,duration:2e3};return this.register(t),t};gap=e=>{let t={id:this.#e(),kind:me.Gap,duration:e};return this.register(t),t};transition={crossfade:e=>{let t={id:this.#e(),kind:me.Transition,effect:oa.Crossfade,duration:e};return this.register(t),t}};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.#t(r=>(r.items.find(({id:n})=>n===e.id).childrenIds.push(...t.map(n=>n.id)),r))}set=(e,t)=>{this.#t(r=>({...r,items:r.items.map(s=>s.id===e?{...s,...t}:s)}))}};var Kc=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 Zc=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 d_=i=>Math.round(i*1e3);function f_(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 Kc(a.getReader());return t.set(s.id,c),c}return{async video(s,n){let o=await r(s),a=d_(s.start);return{duration:s.duration,visuals:{sampleAt:async c=>{let l=await o.atOrNear(a+d_(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/1e3,a=(s.start+s.duration)/1e3,c=i.decodeAudio({source:n,start:o,end:a});yield*new Zc(c.getReader()).stream()}}}},async dispose(){let s=Array.from([...t.values()],n=>n.cancel());t.clear(),await Promise.all(s)}}}var Xd=class extends hs{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 m_(i,e,t){return new Xd(e,t).build(i)}var Qc=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=f_(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 m_(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 Nm({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 Jc=class{driver;resources=new ua;#e;constructor(e){this.driver=e,this.#e=new Qc(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 Yc({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 el=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=ca.fromBytes(r),n=Rm.sigil.fromBytes(r);return new this(e,r,s,n)}};var tl=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 el.make(e),s=t??r.nickname;return new this(e,s,r)}static async load(e){throw new Error("TODO implement")}};var oi=await ra.setup({workerUrl:new URL("../driver/driver.worker.bundle.min.js",import.meta.url)}),Fv=document.querySelector(".results"),Rv=document.querySelector(".fetch"),Dv=document.querySelector(".import"),Ov=document.querySelector(".play"),zv=document.querySelector(".stop"),Uv=document.querySelector(".seek");Rv?.addEventListener("click",Hv);Dv?.addEventListener("click",Wv);var p_=new Jc(oi),Gv=await fetch("/assets/temp/gl.mp4"),Nv=await Gv.arrayBuffer(),Lv=new Uint8Array(Nv),{videoA:Yd}=await p_.load({videoA:tl.make(Lv)}),Vv=p_.timeline(i=>i.sequence(i.stack(i.video(Yd,{duration:5e3}),i.audio(Yd,{duration:8e3})),i.video(Yd,{duration:7e3}))),rl=await Xc.create(oi,Vv);document.body.appendChild(rl.canvas);Ov.addEventListener("click",()=>rl.play());zv.addEventListener("click",()=>rl.pause());Uv.addEventListener("change",async i=>{let e=i.target;await rl.seek(+e.value)});Bm(oi);await oi.thread.work.hello(),oi.machina.count===1?console.log("\u2705 driver works"):console.error("\u274C FAIL driver call didn't work");async function Wv(){let[i]=await window.showOpenFilePicker(),e=await i.getFile(),t=eu(oi,e);await Fm(e),g_(t,i.name)}async function Hv(){let i=["/assets/temp/gl.mp4"];for(let e of i){let t=eu(oi,"/assets/temp/gl.mp4");g_(t,e)}}async function g_(i,e){let t=document.createElement("div");Fv.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),k=Math.abs(o[_]||0);T>x&&(x=T),k>w&&(w=k)}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)})))})}};Ns.MAX_CANVAS_WIDTH=8e3,Ns.MAX_NODES=10;var Jl=class extends Vr{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}},Gs=class extends Vr{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}},pS={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3},Ii=class i extends Ql{static create(e){return new i(e)}constructor(e){let t=e.media||(e.backend==="WebAudio"?new Gs: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({},pS,e),this.timer=new Jl;let r=t?void 0:this.getMediaElement();this.renderer=new Ns(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=ia.createBuffer(this.exportPeaks(),e.duration)),e.peaks&&e.duration&&(this.decodedData=ia.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 mS.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 Gs&&(a.duration=o)}if(r)this.decodedData=ia.createBuffer(r,o||0);else if(t){let a=yield t.arrayBuffer();this.decodedData=yield ia.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 Gs?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()}};Ii.BasePlugin=class extends Vr{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}},Ii.dom=fS;var sa=class i{wavesurfer;constructor(e,t,r){this.wavesurfer=Ii.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 Bm(i){let e=document.querySelector(".waveform-demo"),t=document.querySelector(".width"),r=await sa.init(i,"/assets/temp/gl.mp4",e);t.addEventListener("change",()=>{let s=+t.value;r.width=s})}var na=class i{videoTrack;options;#e;#t=new Map;#r=[0,0];constructor(e,t){this.videoTrack=e,this.options=t,this.#e=new Fs(e,t.canvasSinkOptions)}static async init(e,t){let s=await new _t({formats:hr,source:await Lr(e)}).getPrimaryVideoTrack();if(s)return new i(s,{frequency:t.frequency??1,canvasSinkOptions:t.canvasSinkOptions??{width:80,height:50,fit:"fill"},onChange:t.onChange,onPlaceholders:t.onPlaceholders});throw new Error("Source has no video track")}set frequency(e){e!==this.options.frequency&&(this.options.frequency=e,this.#c())}get frequency(){return this.options.frequency}#i([e,t],r=1){let s=t-e;return[e-s*r,t+s*r]}async#s(){let[e,t]=this.#r,r=new Set,s=await this.videoTrack.computeDuration();for(let n=Math.max(0,e);n<=t;n+=this.options.frequency)n>=0&&n<=s&&r.add(n);this.options.onPlaceholders?.([...r])}async#o(){let[e,t]=this.#r,r=new Set,s=await this.videoTrack.computeDuration();for(let c=Math.max(0,e);c<=t;c+=this.options.frequency)c>=0&&c<=s&&r.add(c);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,r]=e,s=r-t,[n,o]=this.#r,a=n+s,c=o-s,l=t<a,u=r>c;!l&&!u||(this.#r=this.#i(e,2),this.#c())}#n=null;#a=!1;async#c(){if(this.#s(),this.#n){this.#a=!0;return}this.#n=this.#o(),await this.#n,this.#n=null,this.#a&&(this.#a=!1,await this.#c())}getThumbnail(e){return this.#t.get(e)}};async function Fm(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 na.init(i,{onChange(u){let h=u.sort((d,f)=>d.time-f.time);o.replaceChildren(...h.map(({time:d,canvas:f})=>gS(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 gS(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 eu(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",style:{fontSize:50,fill:"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 oa;(function(i){i[i.Crossfade=0]="Crossfade"})(oa||(oa={}));var aa=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 _t({formats:hr,source:await Lr(e)});return{audio:!!await t.getPrimaryAudioTrack(),video:!!await t.getPrimaryVideoTrack()}}};var Mi=Object.freeze({eq(i,e){if(i.length!==e.length)return!1;for(let t=0;t<=i.length;t++)if(i.at(t)!==e.at(t))return!1;return!0},random(i){return crypto.getRandomValues(new Uint8Array(i))}});var Te=class{lexicon;static lexicons=Object.freeze({base2:{characters:"01"},hex:{characters:"0123456789abcdef"},base36:{characters:"0123456789abcdefghijklmnopqrstuvwxyz"},base58:{characters:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"},base62:{characters:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"},base64url:{negativePrefix:"~",characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"},base64:{characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",padding:{character:"=",size:4}}});lookup;negativePrefix;constructor(e){this.lexicon=e,this.lookup=Object.fromEntries([...e.characters].map((t,r)=>[t,r])),this.negativePrefix=e.negativePrefix??"-"}toBytes(e){let t=Math.log2(this.lexicon.characters.length);if(Number.isInteger(t)){let a=0,c=0,l=[];for(let u of e){if(u===this.lexicon.padding?.character)continue;let h=this.lookup[u];if(h===void 0)throw new Error(`Invalid character: ${u}`);for(a=a<<t|h,c+=t;c>=8;)c-=8,l.push(a>>c&255)}return new Uint8Array(l)}let r=0n,s=BigInt(this.lexicon.characters.length),n=!1;e.startsWith(this.negativePrefix)&&(e=e.slice(this.negativePrefix.length),n=!0);for(let a of e){let c=this.lookup[a];if(c===void 0)throw new Error(`Invalid character: ${a}`);r=r*s+BigInt(c)}let o=[];for(;r>0n;)o.unshift(Number(r%256n)),r=r/256n;return new Uint8Array(o)}fromBytes(e){let t=Math.log2(this.lexicon.characters.length);if(Number.isInteger(t)){let o=0,a=0,c="";for(let l of e)for(o=o<<8|l,a+=8;a>=t;){a-=t;let u=o>>a&(1<<t)-1;c+=this.lexicon.characters[u]}if(a>0){let l=o<<t-a&(1<<t)-1;c+=this.lexicon.characters[l]}if(this.lexicon.padding)for(;c.length%this.lexicon.padding.size!==0;)c+=this.lexicon.padding.character;return c}let r=0n;for(let o of e)r=(r<<8n)+BigInt(o);if(r===0n)return this.lexicon.characters[0];let s=BigInt(this.lexicon.characters.length),n="";for(;r>0n;)n=this.lexicon.characters[Number(r%s)]+n,r=r/s;return n}toInteger(e){if(!e)return 0;let t=0n,r=!1,s=BigInt(this.lexicon.characters.length);e.startsWith(this.negativePrefix)&&(e=e.slice(this.negativePrefix.length),r=!0);for(let n of e){let o=this.lookup[n];if(o===void 0)throw new Error(`Invalid character: ${n}`);t=t*s+BigInt(o)}return Number(r?-t:t)}fromInteger(e){e=Math.floor(e);let t=e<0,r=BigInt(t?-e:e);if(r===0n)return this.lexicon.characters[0];let s=BigInt(this.lexicon.characters.length),n="";for(;r>0n;)n=this.lexicon.characters[Number(r%s)]+n,r=r/s;return t?`${this.negativePrefix}${n}`:n}random(e=32){return this.fromBytes(Mi.random(e))}};var St=new Te(Te.lexicons.hex),xR=new Te(Te.lexicons.base2),yR=new Te(Te.lexicons.base36),tu=new Te(Te.lexicons.base58),bR=new Te(Te.lexicons.base62),wR=new Te(Te.lexicons.base64),_R=new Te(Te.lexicons.base64url);var ru=["doz","mar","bin","wan","sam","lit","sig","hid","fid","lis","sog","dir","wac","sab","wis","sib","rig","sol","dop","mod","fog","lid","hop","dar","dor","lor","hod","fol","rin","tog","sil","mir","hol","pas","lac","rov","liv","dal","sat","lib","tab","han","tic","pid","tor","bol","fos","dot","los","dil","for","pil","ram","tir","win","tad","bic","dif","roc","wid","bis","das","mid","lop","ril","nar","dap","mol","san","loc","nov","sit","nid","tip","sic","rop","wit","nat","pan","min","rit","pod","mot","tam","tol","sav","pos","nap","nop","som","fin","fon","ban","mor","wor","sip","ron","nor","bot","wic","soc","wat","dol","mag","pic","dav","bid","bal","tim","tas","mal","lig","siv","tag","pad","sal","div","dac","tan","sid","fab","tar","mon","ran","nis","wol","mis","pal","las","dis","map","rab","tob","rol","lat","lon","nod","nav","fig","nom","nib","pag","sop","ral","bil","had","doc","rid","moc","pac","rav","rip","fal","tod","til","tin","hap","mic","fan","pat","tac","lab","mog","sim","son","pin","lom","ric","tap","fir","has","bos","bat","poc","hac","tid","hav","sap","lin","dib","hos","dab","bit","bar","rac","par","lod","dos","bor","toc","hil","mac","tom","dig","fil","fas","mit","hob","har","mig","hin","rad","mas","hal","rag","lag","fad","top","mop","hab","nil","nos","mil","fop","fam","dat","nol","din","hat","nac","ris","fot","rib","hoc","nim","lar","fit","wal","rap","sar","nal","mos","lan","don","dan","lad","dov","riv","bac","pol","lap","tal","pit","nam","bon","ros","ton","fod","pon","sov","noc","sor","lav","mat","mip","fip"];var iu=["zod","nec","bud","wes","sev","per","sut","let","ful","pen","syt","dur","wep","ser","wyl","sun","ryp","syx","dyr","nup","heb","peg","lup","dep","dys","put","lug","hec","ryt","tyv","syd","nex","lun","mep","lut","sep","pes","del","sul","ped","tem","led","tul","met","wen","byn","hex","feb","pyl","dul","het","mev","rut","tyl","wyd","tep","bes","dex","sef","wyc","bur","der","nep","pur","rys","reb","den","nut","sub","pet","rul","syn","reg","tyd","sup","sem","wyn","rec","meg","net","sec","mul","nym","tev","web","sum","mut","nyx","rex","teb","fus","hep","ben","mus","wyx","sym","sel","ruc","dec","wex","syr","wet","dyl","myn","mes","det","bet","bel","tux","tug","myr","pel","syp","ter","meb","set","dut","deg","tex","sur","fel","tud","nux","rux","ren","wyt","nub","med","lyt","dus","neb","rum","tyn","seg","lyx","pun","res","red","fun","rev","ref","mec","ted","rus","bex","leb","dux","ryn","num","pyx","ryg","ryx","fep","tyr","tus","tyc","leg","nem","fer","mer","ten","lus","nus","syl","tec","mex","pub","rym","tuc","fyl","lep","deb","ber","mug","hut","tun","byl","sud","pem","dev","lur","def","bus","bep","run","mel","pex","dyt","byt","typ","lev","myl","wed","duc","fur","fex","nul","luc","len","ner","lex","rup","ned","lec","ryd","lyd","fen","wel","nyd","hus","rel","rud","nes","hes","fet","des","ret","dun","ler","nyr","seb","hul","ryl","lud","rem","lys","fyn","wer","ryc","sug","nys","nyl","lyn","dyn","dem","lux","fed","sed","bec","mun","lyr","tes","mud","nyt","byr","sen","weg","fyr","mur","tel","rep","teg","pec","nel","nev","fes"];var $t={defaults:{groupSize:4,wordSeparator:".",groupSeparator:" "},random(i,e){let t=Mi.random(i);return this.fromBytes(t,e)},fromBytes(i,e={}){let{groupSize:t=$t.defaults.groupSize,wordSeparator:r=$t.defaults.wordSeparator,groupSeparator:s=$t.defaults.groupSeparator}=e,n=[],o=[];i.forEach((c,l)=>{let u=l%2===0?ru:iu;o.push(u[c]),o.length===2&&(n.push(o.join("")),o=[])}),o.length&&n.push(o.join(""));let a=[];for(let c=0;c<n.length;c+=t)a.push(n.slice(c,c+t).join(r));return a.join(s)},toBytes(i){let e=i.toLowerCase().replace(/[^a-z]/g,"");if(e.length/3%1!==0)throw new Error(`invalid triplet count, ${e.length} does not divide into triplets`);let r=[];for(let s=0;s<e.length;s+=3)r.push(e.slice(s,s+3));return new Uint8Array(r.map((s,n)=>{let a=(n%2===0?ru:iu).findIndex(c=>c===s);if(a===-1)throw new Error(`unknown triplet ${s}`);return a}))},toHex(i){return St.fromBytes($t.toBytes(i))},fromHex(i,e){return $t.fromBytes(St.toBytes(i),e)}};var Tt={defaults:{delimiter:".",sigilBytes:4,previewBytes:8},toBytes(i){i=i.trim();let e=i.split(/[^a-zA-Z0-9]+/m).filter(Boolean).map(s=>s.trim());if(e.length<2)return $t.toBytes(e.join(""));let t=e.pop(),r=e.join("");return new Uint8Array([...$t.toBytes(r),...tu.toBytes(t)])},parse(i,e){let t=Tt.toBytes(i);return Tt.build.fromBytes(t,e)},build:{fromBytes(i,e={}){let{delimiter:t,previewBytes:r,sigilBytes:s}={...Tt.defaults,...e},n=u=>i.length>0?$t.fromBytes(i.slice(0,u),{wordSeparator:t,groupSeparator:t}):"",o=n(s),a=n(r),c=i.length>r?tu.fromBytes(i.slice(r)):"",l=[a,c].filter(u=>u.length>0).join(t);return{raw:i,full:l,preview:a,bulk:c,sigil:o,bytes:i,thumbprint:l}},fromHex(i,e){let t=St.toBytes(i);return Tt.build.fromBytes(t,e)}},toHex(i){let e=Tt.toBytes(i);return St.fromBytes(e)},fromBytes(i,e){return Tt.build.fromBytes(i,e).full},fromHex(i,e){return Tt.fromBytes(St.toBytes(i),e)},sigil:{fromHex(i,e){return Tt.build.fromHex(i,e).sigil},fromBytes(i,e){return Tt.build.fromBytes(i,e).sigil}}},Rm=Tt;var ca=Object.freeze({fromBytes(i){return[...i].map(e=>e.toString(16).padStart(2,"0")).join("")},toBytes(i){if(i.length%2!==0)throw new Error("must have even number of hex characters");let e=new Uint8Array(i.length/2);for(let t=0;t<i.length;t+=2)e[t/2]=parseInt(i.slice(t,t+2),16);return e},random(i=32){return this.fromBytes(Mi.random(i))},string(i){return ca.fromBytes(i)},bytes(i){return ca.toBytes(i)}});function Dm(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}}var su=class i extends Map{static require(e,t){if(e.has(t))return e.get(t);throw new Error(`required key not found: "${t}"`)}static guarantee(e,t,r){if(e.has(t))return e.get(t);{let s=r();return e.set(t,s),s}}array(){return[...this]}require(e){return i.require(this,e)}guarantee(e,t){return i.guarantee(this,e,t)}},Om=su;function zm(){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 xS(){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}=zm(),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 la(i){let e=xS();return i&&e.sub(i),e.sub}var ua=class{#e=new Om;async store(e){let t=await aa.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}};var nu=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=la(),this.#t.set(e,t)),t}},Ke=globalThis[Symbol.for("e280.tracker")]??=new nu;var Bi=class{sneak;constructor(e){this.sneak=e}get(){return Ke.notifyRead(this),this.sneak}get value(){return this.get()}};var Fi=class extends Bi{on=la();dispose(){this.on.clear()}};function ha(i,e=i){let{seen:t,result:r}=Ke.observe(i),s=Dm(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 Ri(i,e){return i===e}var da=class extends Fi{#e;constructor(e,t){let r=t?.compare??Ri,{result:s,dispose:n}=ha(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 fa=class extends Bi{#e;#t;#r=!1;#i;constructor(e,t){super(void 0),this.#e=e,this.#t=t?.compare??Ri}toString(){return`($lazy "${String(this.get())}")`}get(){if(!this.#i){let{result:e,dispose:t}=ha(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 ma=class extends Fi{#e=!1;#t;constructor(e,t){super(e),this.#t=t?.compare??Ri}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 yS(i,e){return new fa(i,e).fn()}function Um(i,e){return new da(i,e).fn()}function Ls(i,e){return new ma(i,e).fn()}Ls.lazy=yS;Ls.derived=Um;var Gm=(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}}},Nm=async(i,e)=>{let t=1e3/i.fps,r=i.duration/1e3,s=Math.ceil(r*i.fps);for(let n=0;n<s&&!i.abort?.aborted;n++){let o=n*t;await e(o,n)}};var Lm=i=>i instanceof Blob?URL.createObjectURL(i):String(i);function Wm(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=Lm(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=Lm(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 Vm(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 Vm(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 Vm(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 o_={extension:{type:A.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await Promise.resolve().then(()=>(n_(),Mv))}};G();var c_={extension:{type:A.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await Promise.resolve().then(()=>(a_(),Bv))}};G();Ha();Ua();ch();He();L.add(o_,c_);var l_=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 u_=(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]},h_=[1,0,0,1,0,0];var jd=(i,e)=>i.get(e),qc=(i,e,t)=>{let r=t??h_;if(e.spatialId){let s=jd(i,e.spatialId);if(s.enabled){let n=l_(s.transform);r=u_(n,r)}}return r},hs=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,qc(this.items,e,t));case me.Audio:return this.sampler.audio(e);case me.Text:{let r=qc(this.items,e,t),s=e.styleId!==void 0?this.items.get(e.styleId):void 0;return{duration:e.duration,visuals:{sampleAt:async n=>n<0||n>=e.duration?[]:[{kind:"text",content:e.content,style:s?.style,matrix:r}]}}}case me.Gap:return{duration:e.duration,visuals:{sampleAt:async()=>[]}};case me.Stack:{let r=qc(this.items,e,t),s=await Promise.all(e.childrenIds.map(n=>this.build(jd(this.items,n),r)));return this.#r(s)}case me.Sequence:{let r=qc(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=>jd(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.#o(n,o,c);r.push(l),s++}return r}async#o(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 $d=class extends hs{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 qd(i,e,t){return new $d(e,t).build(i)}var Xc=class{driver;canvas;root;sampler;resolveMedia;currentTime=Ls(0);#e=Gm(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=Wm(()=>"/assets/temp/gl.mp4"),o=await qd(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)}async update(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]));this.root=await qd(t,r,this.sampler),await this.seek(this.currentTime())}};var Yc=class{state;constructor(e){this.state=e}require(e){return e===void 0?void 0:this.state.project.items.find(r=>r.id===e)}#e(){return St.toInteger(St.random())}#t(e){this.state.project=e(this.state.project)}register(e){this.#t(t=>({...t,items:[...t.items,e]}))}textStyle=e=>{let t={id:this.#e(),kind:me.TextStyle,style:e};return this.register(t),t};spatial=e=>{let t={id:this.#e(),kind:me.Spatial,transform:e,enabled:!0};return this.register(t),t};sequence=(...e)=>{let t={id:this.#e(),kind:me.Sequence,childrenIds:e.map(r=>r.id)};return this.register(t),t};stack=(...e)=>{let t={kind:me.Stack,id:this.#e(),childrenIds:e.map(r=>r.id)};return this.register(t),t};video=(e,t)=>{if(!e.hasVideo)throw new Error(`Video clip error: media "${e.datafile.filename}" has no video track.`);let r={kind:me.Video,id:this.#e(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration};return this.register(r),r};audio=(e,t)=>{if(!e.hasAudio)throw new Error(`Audio clip error: media "${e.datafile.filename}" has no audio track.`);let r={kind:me.Audio,id:this.#e(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration};return this.register(r),r};text=e=>{let t={id:this.#e(),content:e,kind:me.Text,duration:2e3};return this.register(t),t};gap=e=>{let t={id:this.#e(),kind:me.Gap,duration:e};return this.register(t),t};transition={crossfade:e=>{let t={id:this.#e(),kind:me.Transition,effect:oa.Crossfade,duration:e};return this.register(t),t}};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.#t(r=>(r.items.find(({id:n})=>n===e.id).childrenIds.push(...t.map(n=>n.id)),r))}set=(e,t)=>{this.#t(r=>({...r,items:r.items.map(s=>s.id===e?{...s,...t}:s)}))}};var Kc=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 Zc=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 d_=i=>Math.round(i*1e3);function f_(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 Kc(a.getReader());return t.set(s.id,c),c}return{async video(s,n){let o=await r(s),a=d_(s.start);return{duration:s.duration,visuals:{sampleAt:async c=>{let l=await o.atOrNear(a+d_(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/1e3,a=(s.start+s.duration)/1e3,c=i.decodeAudio({source:n,start:o,end:a});yield*new Zc(c.getReader()).stream()}}}},async dispose(){let s=Array.from([...t.values()],n=>n.cancel());t.clear(),await Promise.all(s)}}}var Xd=class extends hs{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 m_(i,e,t){return new Xd(e,t).build(i)}var Qc=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=f_(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 m_(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 Nm({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 Jc=class{driver;resources=new ua;#e;constructor(e){this.driver=e,this.#e=new Qc(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 Yc({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 el=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=ca.fromBytes(r),n=Rm.sigil.fromBytes(r);return new this(e,r,s,n)}};var tl=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 el.make(e),s=t??r.nickname;return new this(e,s,r)}static async load(e){throw new Error("TODO implement")}};var oi=await ra.setup({workerUrl:new URL("../driver/driver.worker.bundle.min.js",import.meta.url)}),Fv=document.querySelector(".results"),Rv=document.querySelector(".fetch"),Dv=document.querySelector(".import"),Ov=document.querySelector(".play"),zv=document.querySelector(".stop"),Uv=document.querySelector(".seek");Rv?.addEventListener("click",Hv);Dv?.addEventListener("click",Wv);var p_=new Jc(oi),Gv=await fetch("/assets/temp/gl.mp4"),Nv=await Gv.arrayBuffer(),Lv=new Uint8Array(Nv),{videoA:Yd}=await p_.load({videoA:tl.make(Lv)}),Vv=p_.timeline(i=>i.sequence(i.stack(i.video(Yd,{duration:5e3}),i.audio(Yd,{duration:8e3})),i.video(Yd,{duration:7e3}))),rl=await Xc.create(oi,Vv);document.body.appendChild(rl.canvas);Ov.addEventListener("click",()=>rl.play());zv.addEventListener("click",()=>rl.pause());Uv.addEventListener("change",async i=>{let e=i.target;await rl.seek(+e.value)});Bm(oi);await oi.thread.work.hello(),oi.machina.count===1?console.log("\u2705 driver works"):console.error("\u274C FAIL driver call didn't work");async function Wv(){let[i]=await window.showOpenFilePicker(),e=await i.getFile(),t=eu(oi,e);await Fm(e),g_(t,i.name)}async function Hv(){let i=["/assets/temp/gl.mp4"];for(let e of i){let t=eu(oi,"/assets/temp/gl.mp4");g_(t,e)}}async function g_(i,e){let t=document.createElement("div");Fv.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: