@omnimedia/omnitool 1.1.0-52 → 1.1.0-53
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 +1 -1
- package/s/timeline/sugar/o.ts +10 -10
- package/x/demo/demo.bundle.min.js +1 -1
- package/x/demo/demo.bundle.min.js.map +3 -3
- package/x/index.html +2 -2
- package/x/tests.bundle.min.js +1 -1
- package/x/tests.bundle.min.js.map +3 -3
- package/x/tests.html +1 -1
- package/x/timeline/sugar/o.d.ts +1 -0
- package/x/timeline/sugar/o.js +10 -10
- package/x/timeline/sugar/o.js.map +1 -1
package/package.json
CHANGED
package/s/timeline/sugar/o.ts
CHANGED
|
@@ -20,7 +20,7 @@ export class O {
|
|
|
20
20
|
return this.state.timeline
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
getId() {
|
|
24
24
|
return hex.toInteger(hex.random())
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -37,7 +37,7 @@ export class O {
|
|
|
37
37
|
|
|
38
38
|
textStyle = (style: TextStyleOptions): Item.TextStyle => {
|
|
39
39
|
const item = {
|
|
40
|
-
id: this
|
|
40
|
+
id: this.getId(),
|
|
41
41
|
kind: Kind.TextStyle,
|
|
42
42
|
style
|
|
43
43
|
} as Item.TextStyle
|
|
@@ -47,7 +47,7 @@ export class O {
|
|
|
47
47
|
|
|
48
48
|
spatial = (transform: Transform): Item.Spatial => {
|
|
49
49
|
const item: Item.Spatial = {
|
|
50
|
-
id: this
|
|
50
|
+
id: this.getId(),
|
|
51
51
|
kind: Kind.Spatial,
|
|
52
52
|
transform,
|
|
53
53
|
enabled: true
|
|
@@ -58,7 +58,7 @@ export class O {
|
|
|
58
58
|
|
|
59
59
|
sequence = (...items: Item.Any[]): Item.Sequence => {
|
|
60
60
|
const item = {
|
|
61
|
-
id: this
|
|
61
|
+
id: this.getId(),
|
|
62
62
|
kind: Kind.Sequence,
|
|
63
63
|
childrenIds: items.map(item => item.id)
|
|
64
64
|
} as Item.Sequence
|
|
@@ -69,7 +69,7 @@ export class O {
|
|
|
69
69
|
stack = (...items: Item.Any[]): Item.Stack => {
|
|
70
70
|
const item = {
|
|
71
71
|
kind: Kind.Stack,
|
|
72
|
-
id: this
|
|
72
|
+
id: this.getId(),
|
|
73
73
|
childrenIds: items.map(item => item.id)
|
|
74
74
|
} as Item.Stack
|
|
75
75
|
this.register(item)
|
|
@@ -88,7 +88,7 @@ export class O {
|
|
|
88
88
|
|
|
89
89
|
const item: Item.Video = {
|
|
90
90
|
kind: Kind.Video,
|
|
91
|
-
id: this
|
|
91
|
+
id: this.getId(),
|
|
92
92
|
mediaHash: media.datafile.checksum.hash,
|
|
93
93
|
start: options?.start ?? 0,
|
|
94
94
|
duration: options?.duration ?? media.duration
|
|
@@ -110,7 +110,7 @@ export class O {
|
|
|
110
110
|
|
|
111
111
|
const item: Item.Audio = {
|
|
112
112
|
kind: Kind.Audio,
|
|
113
|
-
id: this
|
|
113
|
+
id: this.getId(),
|
|
114
114
|
mediaHash: media.datafile.checksum.hash,
|
|
115
115
|
start: options?.start ?? 0,
|
|
116
116
|
duration: options?.duration ?? media.duration,
|
|
@@ -126,7 +126,7 @@ export class O {
|
|
|
126
126
|
}): Item.Text => {
|
|
127
127
|
|
|
128
128
|
const item = {
|
|
129
|
-
id: this
|
|
129
|
+
id: this.getId(),
|
|
130
130
|
content,
|
|
131
131
|
kind: Kind.Text,
|
|
132
132
|
duration: options?.duration ?? 2000
|
|
@@ -141,7 +141,7 @@ export class O {
|
|
|
141
141
|
|
|
142
142
|
gap = (duration: number): Item.Gap => {
|
|
143
143
|
const item = {
|
|
144
|
-
id: this
|
|
144
|
+
id: this.getId(),
|
|
145
145
|
kind: Kind.Gap,
|
|
146
146
|
duration
|
|
147
147
|
} as Item.Gap
|
|
@@ -152,7 +152,7 @@ export class O {
|
|
|
152
152
|
transition = {
|
|
153
153
|
crossfade: (duration: number): Item.Transition => {
|
|
154
154
|
const item = {
|
|
155
|
-
id: this
|
|
155
|
+
id: this.getId(),
|
|
156
156
|
kind: Kind.Transition,
|
|
157
157
|
effect: Effect.Crossfade,
|
|
158
158
|
duration,
|
|
@@ -2485,7 +2485,7 @@ vec4 transition(vec2 uv) {
|
|
|
2485
2485
|
<div class="cursor" part="cursor"></div>
|
|
2486
2486
|
</div>
|
|
2487
2487
|
</div>
|
|
2488
|
-
`,[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;this.subscriptions.forEach((t=>t())),this.container.remove(),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),(e=this.unsubscribeOnScroll)===null||e===void 0||e.forEach((t=>t())),this.unsubscribeOnScroll=[],this.dragStream&&(this.dragStream.cleanup(),this.dragStream=null),this.scrollStream&&(this.scrollStream.cleanup(),this.scrollStream=null)}createDelay(e=10){let t,r,o=()=>{t&&(clearTimeout(t),t=void 0),r&&(r(),r=void 0)};return this.timeouts.push(o),()=>new Promise(((i,s)=>{o(),r=s,t=setTimeout((()=>{t=void 0,r=void 0,i()}),e)}))}getHeight(e,t){var r;let o=((r=this.audioData)===null||r===void 0?void 0:r.numberOfChannels)||1;return(function({optionsHeight:i,optionsSplitChannels:s,parentHeight:a,numberOfChannels:c,defaultHeight:l=128}){if(i==null)return l;let u=Number(i);if(!isNaN(u))return u;if(i==="auto"){let d=a||l;return s?.every((m=>!m.overlay))?d/c:d}return l})({optionsHeight:e,optionsSplitChannels:t,parentHeight:this.parent.clientHeight,numberOfChannels:o,defaultHeight:128})}convertColorValues(e,t){return(function(r,o,i){if(!Array.isArray(r))return r||"";if(r.length===0)return"#999";if(r.length<2)return r[0]||"";let s=document.createElement("canvas"),a=s.getContext("2d"),c=i??s.height*o,l=a.createLinearGradient(0,0,0,c||o),u=1/(r.length-1);return r.forEach(((d,m)=>{l.addColorStop(m*u,d)})),l})(e,this.getPixelRatio(),t?.canvas.height)}getPixelRatio(){return e=window.devicePixelRatio,Math.max(1,e||1);var e}renderBarWaveform(e,t,r,o){let{width:i,height:s}=r.canvas,{halfHeight:a,barWidth:c,barRadius:l,barIndexScale:u,barSpacing:d,barMinHeight:m}=(function({width:p,height:h,length:g,options:y,pixelRatio:x}){let v=h/2,T=y.barWidth?y.barWidth*x:1,S=y.barGap?y.barGap*x:y.barWidth?T/2:0,k=T+S||1;return{halfHeight:v,barWidth:T,barGap:S,barRadius:y.barRadius||0,barMinHeight:y.barMinHeight?y.barMinHeight*x:0,barIndexScale:g>0?p/k/g:0,barSpacing:k}})({width:i,height:s,length:(e[0]||[]).length,options:t,pixelRatio:this.getPixelRatio()}),f=(function({channelData:p,barIndexScale:h,barSpacing:g,barWidth:y,halfHeight:x,vScale:v,canvasHeight:T,barAlign:S,barMinHeight:k}){let I=p[0]||[],C=p[1]||I,A=I.length,R=[],D=0,L=0,Y=0;for(let U=0;U<=A;U++){let Ne=Math.round(U*h);if(Ne>D){let{topHeight:wc,totalHeight:Li}=gl({maxTop:L,maxBottom:Y,halfHeight:x,vScale:v,barMinHeight:k,barAlign:S}),kc=xl({barAlign:S,halfHeight:x,topHeight:wc,totalHeight:Li,canvasHeight:T});R.push({x:D*g,y:kc,width:y,height:Li}),D=Ne,L=0,Y=0}let Ni=Math.abs(I[U]||0),Ui=Math.abs(C[U]||0);Ni>L&&(L=Ni),Ui>Y&&(Y=Ui)}return R})({channelData:e,barIndexScale:u,barSpacing:d,barWidth:c,halfHeight:a,vScale:o,canvasHeight:s,barAlign:t.barAlign,barMinHeight:m});r.beginPath();for(let p of f)l&&"roundRect"in r?r.roundRect(p.x,p.y,p.width,p.height,l):r.rect(p.x,p.y,p.width,p.height);r.fill(),r.closePath()}renderLineWaveform(e,t,r,o){let{width:i,height:s}=r.canvas,a=(function({channelData:c,width:l,height:u,vScale:d}){let m=u/2,f=c[0]||[];return[f,c[1]||f].map(((p,h)=>{let g=p.length,y=g?l/g:0,x=m,v=h===0?-1:1,T=[{x:0,y:x}],S=0,k=0;for(let I=0;I<=g;I++){let C=Math.round(I*y);if(C>S){let R=x+(Math.round(k*m*d)||1)*v;T.push({x:S,y:R}),S=C,k=0}let A=Math.abs(p[I]||0);A>k&&(k=A)}return T.push({x:S,y:x}),T}))})({channelData:e,width:i,height:s,vScale:o});r.beginPath();for(let c of a)if(c.length){r.moveTo(c[0].x,c[0].y);for(let l=1;l<c.length;l++){let u=c[l];r.lineTo(u.x,u.y)}}r.fill(),r.closePath()}renderWaveform(e,t,r){if(r.fillStyle=this.convertColorValues(t.waveColor,r),t.renderFunction)return void t.renderFunction(e,r);let o=(function({channelData:i,barHeight:s,normalize:a,maxPeak:c}){var l;let u=s||1;if(!a)return u;let d=i[0];if(!d||d.length===0)return u;let m=c??0;if(!c)for(let f=0;f<d.length;f++){let p=(l=d[f])!==null&&l!==void 0?l:0,h=Math.abs(p);h>m&&(m=h)}return m?u/m:u})({channelData:e,barHeight:t.barHeight,normalize:t.normalize,maxPeak:t.maxPeak});Ya(t)?this.renderBarWaveform(e,t,r,o):this.renderLineWaveform(e,t,r,o)}renderSingleCanvas(e,t,r,o,i,s,a){let c=this.getPixelRatio(),l=document.createElement("canvas");l.width=Math.round(r*c),l.height=Math.round(o*c),l.style.width=`${r}px`,l.style.height=`${o}px`,l.style.left=`${Math.round(i)}px`,s.appendChild(l);let u=l.getContext("2d");if(t.renderFunction?(u.fillStyle=this.convertColorValues(t.waveColor,u),t.renderFunction(e,u)):this.renderWaveform(e,t,u),l.width>0&&l.height>0){let d=l.cloneNode(),m=d.getContext("2d");m.drawImage(l,0,0),m.globalCompositeOperation="source-in",m.fillStyle=this.convertColorValues(t.progressColor,m),m.fillRect(0,0,l.width,l.height),a.appendChild(d)}}renderMultiCanvas(e,t,r,o,i,s){let a=this.getPixelRatio(),{clientWidth:c}=this.scrollContainer,l=r/a,u=(function({clientWidth:p,totalWidth:h,options:g}){return Xa(Math.min(8e3,p,h),g)})({clientWidth:c,totalWidth:l,options:t}),d={};if(u===0)return;let m=p=>{if(p<0||p>=f||d[p])return;d[p]=!0;let h=p*u,g=Math.min(l-h,u);if(g=Xa(g,t),g<=0)return;let y=(function({channelData:x,offset:v,clampedWidth:T,totalWidth:S}){return x.map((k=>{let I=Math.floor(v/S*k.length),C=Math.floor((v+T)/S*k.length);return k.slice(I,C)}))})({channelData:e,offset:h,clampedWidth:g,totalWidth:l});this.renderSingleCanvas(y,t,g,o,h,i,s)},f=Math.ceil(l/u);if(!this.isScrollable){for(let p=0;p<f;p++)m(p);return}if(Ka({scrollLeft:this.scrollContainer.scrollLeft,totalWidth:l,numCanvases:f}).forEach((p=>m(p))),f>1){let p=this.on("scroll",(()=>{let{scrollLeft:h}=this.scrollContainer;Object.keys(d).length>10&&(i.innerHTML="",s.innerHTML="",d={}),Ka({scrollLeft:h,totalWidth:l,numCanvases:f}).forEach((g=>m(g)))}));this.unsubscribeOnScroll.push(p)}}renderChannel(e,t,r,o){var{overlay:i}=t,s=(function(u,d){var m={};for(var f in u)Object.prototype.hasOwnProperty.call(u,f)&&d.indexOf(f)<0&&(m[f]=u[f]);if(u!=null&&typeof Object.getOwnPropertySymbols=="function"){var p=0;for(f=Object.getOwnPropertySymbols(u);p<f.length;p++)d.indexOf(f[p])<0&&Object.prototype.propertyIsEnumerable.call(u,f[p])&&(m[f[p]]=u[f[p]])}return m})(t,["overlay"]);let a=document.createElement("div"),c=this.getHeight(s.height,s.splitChannels);a.style.height=`${c}px`,i&&o>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,s,r,c,a,l)}render(e){return oe(this,void 0,void 0,(function*(){var t;this.timeouts.forEach((l=>l())),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(),o=this.scrollContainer.clientWidth,{scrollWidth:i,isScrollable:s,useParentWidth:a,width:c}=(function({duration:l,minPxPerSec:u=0,parentWidth:d,fillParent:m,pixelRatio:f}){let p=Math.ceil(l*u),h=p>d,g=!!(m&&!h);return{scrollWidth:p,isScrollable:h,useParentWidth:g,width:(g?d:p)*f}})({duration:e.duration,minPxPerSec:this.options.minPxPerSec||0,parentWidth:o,fillParent:this.options.fillParent,pixelRatio:r});if(this.isScrollable=s,this.wrapper.style.width=a?"100%":`${i}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 l=0;l<e.numberOfChannels;l++){let u=Object.assign(Object.assign({},this.options),(t=this.options.splitChannels)===null||t===void 0?void 0:t[l]);this.renderChannel([e.getChannelData(l)],u,c,l)}else{let l=[e.getChannelData(0)];e.numberOfChannels>1&&l.push(e.getChannelData(1)),this.renderChannel(l,this.options,c,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(),o=(function(i){let s=2*i;return(s<0?Math.floor(s):Math.ceil(s))/2})(r-t);this.scrollContainer.scrollLeft+=o}}zoom(e){this.options.minPxPerSec=e,this.reRender()}scrollIntoView(e,t=!1){let{scrollLeft:r,scrollWidth:o,clientWidth:i}=this.scrollContainer,s=e*o,a=r,c=r+i,l=i/2;if(this.isDragging)s+30>c?this.scrollContainer.scrollLeft+=30:s-30<a&&(this.scrollContainer.scrollLeft-=30);else{(s<a||s>c)&&(this.scrollContainer.scrollLeft=s-(this.options.autoCenter?l:0));let u=s-r-l;t&&this.options.autoCenter&&u>0&&(this.scrollContainer.scrollLeft+=u)}}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=this.options.cursorWidth?`translateX(-${e*this.options.cursorWidth}px)`:"",this.isScrollable&&this.options.autoScroll&&this.audioData&&this.audioData.duration>0&&this.scrollIntoView(e,t)}exportImage(e,t,r){return oe(this,void 0,void 0,(function*(){let o=this.canvasWrapper.querySelectorAll("canvas");if(!o.length)throw new Error("No waveform data");if(r==="dataURL"){let i=Array.from(o).map((s=>s.toDataURL(e,t)));return Promise.resolve(i)}return Promise.all(Array.from(o).map((i=>new Promise(((s,a)=>{i.toBlob((c=>{c?s(c):a(new Error("Could not export image"))}),e,t)})))))}))}},Mi=class extends bt{constructor(){super(...arguments),this.animationFrameId=null,this.isRunning=!1}start(){if(this.isRunning)return;this.isRunning=!0;let e=()=>{this.isRunning&&(this.emit("tick"),this.animationFrameId=requestAnimationFrame(e))};e()}stop(){this.isRunning=!1,this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}destroy(){this.stop()}},Dr=class extends bt{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 oe(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())})).catch((t=>{console.error("WebAudioPlayer load error:",t)}))}_play(){if(!this.paused)return;this.paused=!1,this.bufferNode&&(this.bufferNode.onended=null,this.bufferNode.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 e=this.playedDuration*this._playbackRate;(e>=this.duration||e<0)&&(e=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,e),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 oe(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 oe(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}removeAttribute(e){switch(e){case"src":this.src="";break;case"playbackRate":this.playbackRate=0;break;case"currentTime":this.currentTime=0;break;case"duration":this.duration=0;break;case"volume":this.volume=0;break;case"muted":this.muted=!1}}},yl={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3},Qt=class n extends Di{static create(e){return new n(e)}getState(){return this.wavesurferState}getRenderer(){return this.renderer}constructor(e){let t=e.media||(e.backend==="WebAudio"?new Dr: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.reactiveCleanups=[],this.options=Object.assign({},yl,e);let{state:r,actions:o}=(function(a){var c,l,u,d,m,f;let p=(c=a?.currentTime)!==null&&c!==void 0?c:q(0),h=(l=a?.duration)!==null&&l!==void 0?l:q(0),g=(u=a?.isPlaying)!==null&&u!==void 0?u:q(!1),y=(d=a?.isSeeking)!==null&&d!==void 0?d:q(!1),x=(m=a?.volume)!==null&&m!==void 0?m:q(1),v=(f=a?.playbackRate)!==null&&f!==void 0?f:q(1),T=q(null),S=q(null),k=q(""),I=q(0),C=q(0),A=xt((()=>!g.value),[g]),R=xt((()=>T.value!==null),[T]),D=xt((()=>R.value&&h.value>0),[R,h]),L=xt((()=>p.value),[p]),Y=xt((()=>h.value>0?p.value/h.value:0),[p,h]);return{state:{currentTime:p,duration:h,isPlaying:g,isPaused:A,isSeeking:y,volume:x,playbackRate:v,audioBuffer:T,peaks:S,url:k,zoom:I,scrollPosition:C,canPlay:R,isReady:D,progress:L,progressPercent:Y},actions:{setCurrentTime:U=>{let Ne=Math.max(0,Math.min(h.value||1/0,U));p.set(Ne)},setDuration:U=>{h.set(Math.max(0,U))},setPlaying:U=>{g.set(U)},setSeeking:U=>{y.set(U)},setVolume:U=>{let Ne=Math.max(0,Math.min(1,U));x.set(Ne)},setPlaybackRate:U=>{let Ne=Math.max(.1,Math.min(16,U));v.set(Ne)},setAudioBuffer:U=>{T.set(U),U&&h.set(U.duration)},setPeaks:U=>{S.set(U)},setUrl:U=>{k.set(U)},setZoom:U=>{I.set(Math.max(0,U))},setScrollPosition:U=>{C.set(Math.max(0,U))}}}})({isPlaying:this.isPlayingSignal,currentTime:this.currentTimeSignal,duration:this.durationSignal,volume:this.volumeSignal,playbackRate:this.playbackRateSignal,isSeeking:this.seekingSignal});this.wavesurferState=r,this.wavesurferActions=o,this.timer=new Mi;let i=t?void 0:this.getMediaElement();this.renderer=new Ri(this.options,i),this.initPlayerEvents(),this.initRendererEvents(),this.initTimerEvents(),this.initReactiveState(),this.initPlugins();let s=this.options.url||this.getSrc()||"";Promise.resolve().then((()=>{this.emit("init");let{peaks:a,duration:c}=this.options;(s||a&&c)&&this.load(s,a,c).catch((l=>{this.emit("error",l instanceof Error?l:new Error(String(l)))}))}))}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()}})))}initReactiveState(){this.reactiveCleanups.push((function(e,t){let r=[];r.push(Ke((()=>{let s=e.isPlaying.value;t.emit(s?"play":"pause")}),[e.isPlaying])),r.push(Ke((()=>{let s=e.currentTime.value;t.emit("timeupdate",s),e.isPlaying.value&&t.emit("audioprocess",s)}),[e.currentTime,e.isPlaying])),r.push(Ke((()=>{e.isSeeking.value&&t.emit("seeking",e.currentTime.value)}),[e.isSeeking,e.currentTime]));let o=!1;r.push(Ke((()=>{e.isReady.value&&!o&&(o=!0,t.emit("ready",e.duration.value))}),[e.isReady,e.duration]));let i=!1;return r.push(Ke((()=>{let s=e.isPlaying.value,a=e.currentTime.value,c=e.duration.value,l=c>0&&a>=c;i&&!s&&l&&t.emit("finish"),i=s&&l}),[e.isPlaying,e.currentTime,e.duration])),r.push(Ke((()=>{let s=e.zoom.value;s>0&&t.emit("zoom",s)}),[e.zoom])),()=>{r.forEach((s=>s()))}})(this.wavesurferState,{emit:this.emit.bind(this)}))}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,o)=>{let i=this.getDuration();this.emit("scroll",e*i,t*i,r,o)})),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)})),this.renderer.on("resize",(()=>{this.emit("resize")})));{let e,t=this.renderer.on("drag",(r=>{var o;if(!this.options.interact)return;this.renderer.renderProgress(r),clearTimeout(e);let i=0,s=this.options.dragToSeek;this.isPlaying()?i=0:s===!0?i=200:s&&typeof s=="object"&&(i=(o=s.debounceTime)!==null&&o!==void 0?o:200),e=setTimeout((()=>{this.seekTo(r)}),i),this.emit("interaction",r*this.getDuration()),this.emit("drag",r)}));this.subscriptions.push((()=>{clearTimeout(e),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=so.createBuffer(this.exportPeaks(),e.duration)),e.peaks&&e.duration&&(this.decodedData=so.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,o){return oe(this,void 0,void 0,(function*(){var i;if(this.emit("load",e),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,this.stopAtPosition=null,(i=this.abortController)===null||i===void 0||i.abort(),this.abortController=null,!t&&!r){let a=this.options.fetchParams||{};window.AbortController&&!a.signal&&(this.abortController=new AbortController,a.signal=this.abortController.signal);let c=u=>this.emit("loading",u);t=yield hl.fetchBlob(e,c,a);let l=this.options.blobMimeType;l&&(t=new Blob([t],{type:l}))}this.setSrc(e,t);let s=yield new Promise((a=>{let c=o||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 Dr&&(a.duration=s)}if(r)this.decodedData=so.createBuffer(r,s||0);else if(t){let a=yield t.arrayBuffer();this.decodedData=yield so.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 oe(this,void 0,void 0,(function*(){try{return yield this.loadAudio(e,void 0,t,r)}catch(o){throw this.emit("error",o),o}}))}loadBlob(e,t,r){return oe(this,void 0,void 0,(function*(){try{return yield this.loadAudio("",e,t,r)}catch(o){throw this.emit("error",o),o}}))}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 o=Math.min(e,this.decodedData.numberOfChannels),i=[];for(let s=0;s<o;s++){let a=this.decodedData.getChannelData(s),c=[],l=a.length/t;for(let u=0;u<t;u++){let d=a.slice(Math.floor(u*l),Math.ceil((u+1)*l)),m=0;for(let f=0;f<d.length;f++){let p=d[f];Math.abs(p)>Math.abs(m)&&(m=p)}c.push(Math.round(m*r)/r)}i.push(c)}return i}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 oe(this,void 0,void 0,(function*(){e!=null&&this.setTime(e);let o=yield r.play.call(this);return t!=null&&(this.media instanceof Dr?this.media.stopAt(t):this.stopAtPosition=t),o}))}playPause(){return oe(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 oe(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.reactiveCleanups.forEach((t=>t())),this.reactiveCleanups=[],this.timer.destroy(),this.renderer.destroy(),super.destroy()}};Qt.BasePlugin=class extends bt{constructor(n){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=n}onInit(){}_init(n){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=n,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((n=>n())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}},Qt.dom=pl;var ao=class n{wavesurfer;constructor(e,t,r){this.wavesurfer=Qt.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 o=e.decodeAudio({source:t}).getReader(),i=[],s=[],a=1024,c=await e.getAudioDuration(t);for(;;){let{done:l,value:u}=await o.read();if(l)break;let d=u.numberOfFrames,m=new Float32Array(d);u.copyTo(m,{planeIndex:0});for(let f=0;f<m.length;f++)if(s.push(m[f]),s.length>=a){let p=s.splice(0,a),h=Math.min(...p),g=Math.max(...p);i.push(h,g)}u.close()}return new n(i,r,c??0)}set width(e){this.wavesurfer.setOptions({width:e})}};var N=n=>n;var Yt=n=>n;var Ja=()=>{let n=!1,e=Yt(60),t=1e3/e,r=0,o=0,i=St(),s=null,a=l=>{if(requestAnimationFrame(a),!!n)for(r=l;l-o>=t;)o+=t,s?.(),s=null,i()};async function*c(){for(r=performance.now(),o=r,requestAnimationFrame(a);;)await new Promise(l=>s=l),yield}return{play(){n||(n=!0,r=performance.now(),o=r)},pause(){n=!1},setFPS(l){e=l,t=1e3/e},isPlaying(){return n},ticks:c,onTick:i}},ec=async(n,e)=>{let t=N(1e3/n.fps),r=n.duration/1e3,o=Math.ceil(r*n.fps);for(let i=0;i<o;i++){let s=N(i*t);await e(s,i)}};var Rr=n=>n;function rc(n){return"duration"in n}function nc(n){let e=[],t=new Map(n.timeline.items.map(r=>[r.id,r]));return Bi(n.timeline.rootId,t,n.from,{sequence:()=>{},stack:()=>{},video:(r,o,i)=>e.push({item:r,localTime:o,ancestors:i}),text:(r,o,i)=>e.push({item:r,localTime:o,ancestors:i}),audio:(r,o,i)=>e.push({item:r,localTime:o,ancestors:i})}),e}function oc(n,e,t){let r=Na;for(let o of e)r=tc(n,o,r);return tc(n,t,r)}function tc(n,e,t){if("spatialId"in e&&e.spatialId){let r=n.get(e.spatialId);if(r?.enabled){let o=Ba(r.transform);return za(o,t)}}return t}function Bi(n,e,t,r,o=[]){let i=e.get(n);if(i)switch(i.kind){case B.Stack:r.stack(i,t,o);for(let s of i.childrenIds)Bi(s,e,t,r,[...o,i]);break;case B.Sequence:{r.sequence(i,t,o);let s=N(0);for(let a of i.childrenIds){let c=e.get(a);if(!c||!rc(c))continue;let l=N(s+c.duration);if(t>=l){s=l;continue}let u=N(Math.max(0,t-s));Bi(a,e,u,r,[...o,i]),s=l}break}case B.Video:r.video(i,t,o);break;case B.Text:r.text(i,t,o);break;case B.Audio:r.audio(i,t,o);break}}function be(n,e){let t=e.items.find(r=>r.id===n);if(!t)return N(0);switch(t.kind){case B.Sequence:{let r=t.childrenIds.map(i=>e.items.find(s=>s.id===i)).filter(Boolean),o=N(0);for(let i=0;i<r.length;i++){let s=r[i];if(s.kind===B.Transition){let a=r[i-1],c=r[i+1];if(a&&c&&a.kind!==B.Transition&&c.kind!==B.Transition){let l=be(a.id,e),u=be(c.id,e),d=Math.max(0,Math.min(s.duration,l,u));o=N(o-d)}continue}o=N(o+be(s.id,e))}return o}case B.Stack:{let r=N(0);for(let o of t.childrenIds){let i=be(o,e);i>r&&(r=i)}return r}default:return rc(t)?t.duration:N(0)}}async function ic(n,e,t){return(await Promise.all(e.map(async({item:o,localTime:i})=>{if(o.kind!==B.Audio)return;let s=await n.getSink(o.mediaHash);if(!s)return;let a=o.start+i,c=Rr((t-a)/1e3),l=s.samples(a/1e3),u=await l.next();if(u.done)return;let d=u.value,m=l.next();return{offset:c,gain:o.gain??1,get currentSample(){return d},timelineTime:()=>Rr(c+d.timestamp),output:()=>({sample:d,timestamp:c+d.timestamp,gain:o.gain??1}),advance:async()=>{let f=await m;return f.done?!1:(d=f.value,m=l.next(),!0)}}}))).filter(o=>!!o)}var co=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let r=new ne({formats:le,source:await me(this.resolveMedia(e))}),o=await r.getPrimaryAudioTrack(),s=!!o&&await o.canDecode()&&o?new vr(o):null;return this.#e.set(e,{input:r,sink:s}),s}};function sc(n){let e={index:0,stream:n[0],time:n[0].timelineTime()};for(let[t,r]of n.entries()){let o=r.timelineTime();o<e.time&&(e={time:o,stream:r,index:t})}return e}function lo(n){let e=new co(n);return{async*sampleAudio(t,r){let o=nc({timeline:t,from:r}),i=await ic(e,o,r);for(;i.length>0;){let{stream:s,index:a}=sc(i);yield s.output(),await s.advance()||i.splice(a,1)}}}}var uo=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let r=new ne({formats:le,source:await me(this.resolveMedia(e))}),o=await r.getPrimaryVideoTrack(),s=!!o&&await o.canDecode()&&o?new Rt(o):null;return this.#e.set(e,{input:r,sink:s}),s}};async function ac(n,e,t,r){let[o,i]=await Promise.all([t,r]),s=o.find(l=>l.kind==="image")?.frame,a=i.find(l=>l.kind==="image")?.frame,c=[...o.filter(l=>l.kind!=="image"),...i.filter(l=>l.kind!=="image")];return s&&a?[{id:n.id,kind:"transition",name:"circle",progress:e,from:s,to:a},...c]:c}async function cc(n,e,t,r){let o=vl(n,e,t);if(!o)return[];let i=[...r,e];return o.isTransitioning?ac(o.transition,o.progress,yt(n,o.outgoing,o.outgoingTime,i),yt(n,o.incoming,o.incomingTime,i)):yt(n,o.item,o.localTime,i)}function vl(n,e,t){let r=e.childrenIds.map(i=>n.items.get(i)).filter(i=>!!i),o=N(0);for(let i=0;i<r.length;i++){let s=r[i];if(s.kind===B.Transition)continue;let a=o,c=be(s.id,n.timeline),l=N(a+c),u=r[i+1];if(!(u?.kind===B.Transition)){if(t<l)return{isTransitioning:!1,item:s,localTime:N(t-a)};o=l;continue}let m=u,f=r[i+2];if(!f||f.kind===B.Transition){o=l;continue}let p=be(f.id,n.timeline),h=Math.max(0,Math.min(m.duration,c,p)),g=N(l-h);if(t<g)return{isTransitioning:!1,item:s,localTime:N(t-a)};if(t<l){let y=N(t-g),x=N(t-a);return{isTransitioning:!0,incoming:f,outgoing:s,outgoingTime:x,incomingTime:y,progress:h>0?y/h:1,transition:m}}o=g,i++}return null}async function yt(n,e,t,r){let o=oc(n.items,r,e);switch(e.kind){case B.Stack:{let i=[...r,e];return(await Promise.all(e.childrenIds.map(a=>n.items.get(a)).filter(a=>!!a).map(a=>yt(n,a,t,i)))).flat()}case B.Sequence:return cc(n,e,t,r);case B.Video:{if(t<0||t>=e.duration)return[];let i=await n.videoSampler(e,t);return i?[{kind:"image",frame:i,matrix:o,id:e.id}]:[]}case B.Text:{if(t<0||t>=e.duration)return[];let i=e.styleId?n.items.get(e.styleId)?.style:void 0;return[{id:e.id,kind:"text",content:e.content,style:i,matrix:o}]}case B.Gap:return[{id:e.id,kind:"gap"}];default:return[]}}function lc(n){return async(e,t)=>{let o=await(await n.getSink(e.mediaHash))?.getSample(t/1e3),i=o?.toVideoFrame();return o?.close(),i??void 0}}function mo(n,e){let t=new uo(n),r=e??lc(t);return{async sample(o,i){let s=new Map(o.items.map(c=>[c.id,c])),a=s.get(o.rootId);return a?yt({videoSampler:r,timeline:o,items:s},a,i,[]):[]}}}var fo=class{timeline;resolveMedia;visualSampler;audioSampler;#e=N(0);#t=null;#r=Ja();onTick=this.#r.onTick;audioContext=new AudioContext({sampleRate:48e3});audioGain=this.audioContext.createGain();audioNodes=new Set;#n=null;constructor(e,t){this.timeline=e,this.resolveMedia=t,this.audioGain.connect(this.audioContext.destination),this.audioGain.gain.value=.7**2,this.visualSampler=mo(this.resolveMedia),this.audioSampler=lo(this.resolveMedia)}async*samples(){for await(let e of this.#r.ticks())yield this.visualSampler.sample(this.timeline,this.currentTime)}async seek(e){return this.pause(),this.#e=e,await this.visualSampler.sample(this.timeline,e)}async start(e){this.timeline=e,await this.audioContext.resume(),this.#e=this.currentTime,this.#t=this.audioContext.currentTime,this.#n?.abort(),this.#n=new AbortController;for(let t of this.audioNodes)t.stop();this.audioNodes.clear(),this.#r.play(),this.#o(this.#n.signal,Rr(this.#e/1e3))}pause(){this.#e=this.currentTime,this.#r.pause(),this.#n?.abort();for(let e of this.audioNodes)e.stop();this.audioNodes.clear()}get currentTime(){if(!this.#r.isPlaying()||this.#t===null)return this.#e;let e=(this.audioContext.currentTime-this.#t)*1e3;return N(this.#e+e)}setFps(e){this.#r.setFPS(e)}async#o(e,t){let r=this.audioContext;if(this.#t!==null)for await(let{sample:o,timestamp:i}of this.audioSampler.sampleAudio(this.timeline,N(t*1e3))){if(e.aborted||!this.#r.isPlaying())return;for(;i-(r.currentTime-this.#t+t)>.75;)await new Promise(c=>setTimeout(c,25));let s=r.createBufferSource();s.buffer=o.toAudioBuffer(),s.connect(this.audioGain),s.onended=()=>this.audioNodes.delete(s),this.audioNodes.add(s);let a=this.#t+i-t;a>=r.currentTime?s.start(a):s.start(r.currentTime,r.currentTime-a)}}};var po=class{driver;timeline;canvas;playback;constructor(e,t,r){this.driver=e,this.timeline=r,this.playback=new fo(r,t),this.canvas=e.compositor.pixi.renderer.canvas}async play(){await this.playback.start(this.timeline);for await(let e of this.playback.samples())(await this.driver.composite(e)).close(),this.currentTime>=this.duration&&this.pause()}pause(){this.playback.pause()}async seek(e){let t=await this.playback.seek(N(e));(await this.driver.composite(t)).close()}setFPS(e){this.playback.setFps(Yt(e))}get duration(){return be(this.timeline.rootId,this.timeline)}get currentTime(){return this.playback.currentTime}async update(e){this.timeline=e}};var vt=class{state;constructor(e){this.state=e}require(e){return e===void 0?void 0:this.state.timeline.items.find(r=>r.id===e)}get timeline(){return this.state.timeline}#e(){return ye.toInteger(ye.random())}#t(e){this.state.timeline=e(this.state.timeline)}register(e){this.#t(t=>({...t,items:[...t.items,e]}))}textStyle=e=>{let t={id:this.#e(),kind:B.TextStyle,style:e};return this.register(t),t};spatial=e=>{let t={id:this.#e(),kind:B.Spatial,transform:e,enabled:!0};return this.register(t),t};sequence=(...e)=>{let t={id:this.#e(),kind:B.Sequence,childrenIds:e.map(r=>r.id)};return this.register(t),t};stack=(...e)=>{let t={kind:B.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:B.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:B.Audio,id:this.#e(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration,gain:t?.gain??1};return this.register(r),r};text=(e,t)=>{let r={id:this.#e(),content:e,kind:B.Text,duration:t?.duration??2e3};return t?.styles&&(r.styleId=this.textStyle(t.styles).id),this.register(r),r};gap=e=>{let t={id:this.#e(),kind:B.Gap,duration:e};return this.register(t),t};transition={crossfade:e=>{let t={id:this.#e(),kind:B.Transition,effect:ro.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],o=e?.rotation??0;return[t,r,o]};addChildren(e,...t){this.#t(r=>(r.items.find(({id:i})=>i===e.id).childrenIds.push(...t.map(i=>i.id)),r))}set=(e,t)=>{this.#t(r=>({...r,items:r.items.map(o=>o.id===e?{...o,...t}:o)}))}};var ho=class{#e;#t;constructor(e={}){this.#e=e.chunkFrames??1024,this.#t=e.clamp??!0}async*mix(e){let t=this.#e,r=null,o=null,i=[],s=0,a=0;for await(let c of e){if(o===null)o=c.planes.length,r=c.sampleRate;else{if(c.planes.length!==o)throw new Error("Channel count changed");if(c.sampleRate!==r)throw new Error("Sample rate changed")}let l=Math.round(c.timestamp*r),u=c.planes[0]?.length??0;for(;s+t<=l;)yield this.#r(i,s,o,r),s+=t;i.push({startFrame:l,endFrame:l+u,data:c.planes}),a=Math.max(a,l+u)}if(o!==null&&r!==null)for(;s<a;)yield this.#r(i,s,o,r),s+=t}#r(e,t,r,o){let i=this.#e,s=new Float32Array(r*i),a=t+i;for(let c=0;c<r;c++){let l=c*i,u=s.subarray(l,l+i);for(let d of e){let m=d.data[c];if(!m)continue;let f=Math.max(t,d.startFrame),p=Math.min(a,d.endFrame);if(f>=p)continue;let h=f-t,g=f-d.startFrame,y=p-f;for(let x=0;x<y;x++)u[h+x]+=m[g+x]}if(this.#t)for(let d=0;d<i;d++){let m=u[d];u[d]=m<-1?-1:m>1?1:m}}for(let c=e.length-1;c>=0;c--)e[c].endFrame<=a&&e.splice(c,1);return{planar:s,sampleRate:o,channels:r,frames:i,startFrame:t}}};var Tl=(n,e,t)=>{if(e===t)return n;let r=t/e,o=Math.max(1,Math.round(n.length*r)),i=new Float32Array(o);for(let s=0;s<o;s++){let a=s/r,c=Math.floor(a),l=Math.min(c+1,n.length-1),u=a-c;i[s]=n[c]*(1-u)+n[l]*u}return i},uc=(n,e)=>{let t=n.numberOfChannels,r=new Array(t),o=0;for(let i=0;i<t;i++){let s=new Float32Array(n.numberOfFrames);n.copyTo(s,{planeIndex:i,format:"f32-planar"});let a=Tl(s,n.sampleRate,e);r[i]=a,o=a.length}return{data:r,frames:o}};var dc=(n,e)=>{if(e!==1)for(let t of n)for(let r=0;r<t.length;r++)t[r]*=e};function mc({timeline:n,resolveMedia:e}){let t=new ho,r=wl(n,e),o=new TransformStream,i=o.writable.getWriter();async function s(){for await(let a of t.mix(r)){let c=new AudioData({format:"f32-planar",sampleRate:a.sampleRate,numberOfFrames:a.frames,numberOfChannels:a.channels,timestamp:Math.round(a.startFrame/a.sampleRate*1e6),data:new Float32Array(a.planar)});await i.write(c)}await i.close()}return s(),o.readable}async function*wl(n,e){let t=lo(e);for await(let{sample:r,timestamp:o,gain:i}of t.sampleAudio(n,N(0))){let{data:s}=uc(r,48e3);dc(s,i),yield{planes:s,sampleRate:48e3,timestamp:o},r.close()}}var go=class{driver;resolveMedia;#e;#t=new Map;constructor(e,t){this.driver=e,this.resolveMedia=t,this.#e=mo(t,(r,o)=>{let i=kl(N(r.start+o));return this.#r(r).next(i)})}cursor(e){let t=Number.NEGATIVE_INFINITY;return{next:r=>{if(r<t)throw new Error(`CursorVisualSampler is forward-only: requested ${r}ms after ${t}ms`);return t=r,this.#e.sample(e,r)},cancel:()=>this.#n()}}#r(e){let t=this.#t.get(e.id);if(t)return t;let r=this.resolveMedia(e.mediaHash),o=this.driver.decodeVideo({source:r}),i=this.#o(o.getReader());return this.#t.set(e.id,i),i}async#n(){await Promise.all([...this.#t.values()].map(e=>e.cancel())),this.#t.clear()}#o(e){return{async next(t){let r=null;for(;;){let{done:o,value:i}=await e.read();if(o){let a=r?new VideoFrame(r):void 0;return r?.close(),a}let s=i.timestamp??0;if(s>=t){let a=r?.timestamp??Number.NEGATIVE_INFINITY,c=!!r&&Math.abs(a-t)<Math.abs(s-t),l=c?r:i,u=c?i:r,d=new VideoFrame(l);return l.close(),u?.close(),d}r?.close(),r=i}},cancel:async()=>await e.cancel()}}},kl=n=>Math.round(n*1e3);function fc({timeline:n,fps:e,driver:t,resolveMedia:r}){let o=new TransformStream,i=o.writable.getWriter(),a=new go(t,r).cursor(n),c=1/e,l=be(n.rootId,n);async function u(){await ec({fps:e,duration:l},async(d,m)=>{let f=await a.next(d),p=await t.composite(f),h=new VideoFrame(p,{timestamp:Math.round(m*c*1e6),duration:Math.round(c*1e6)});await i.write(h),p.close()}),await i.close()}return u(),o.readable}function pc(n){let e=mc({...n}),t=fc({...n});return n.driver.encode({video:t,audio:e,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}})}var xo=class{driver;resources=new oo;constructor(e){this.driver=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 vt({timeline:{format:"timeline",info:"https://omniclip.app/",version:0,items:[],rootId:0}}),r=e(t);return t.timeline.rootId=r.id,t.timeline};playback=async e=>new po(this.driver,t=>this.resources.require(t).url,e);render=async(e,t=30)=>pc({timeline:e,fps:Yt(t),driver:this.driver,resolveMedia:r=>this.resources.require(r).url})};var bo=class{data;bytes;hash;nickname;constructor(e,t,r,o){this.data=e,this.bytes=t,this.hash=r,this.nickname=o}static async make(e){let t=new Uint8Array(e),r=new Uint8Array(await crypto.subtle.digest("SHA-256",t)),o=zr.fromBytes(r),i=Xi.sigil.fromBytes(r);return new this(e,r,o,i)}};var yo=class{url;bytes;blob;filename;checksum;constructor(e,t,r,o,i){this.url=e,this.bytes=t,this.blob=r,this.filename=o,this.checksum=i}static async make(e,t){let r=await e.arrayBuffer(),o=new Uint8Array(r),i=await bo.make(o),s=t??i.nickname,a=URL.createObjectURL(e);return new this(a,o,e,s,i)}static async load(e){}};async function gc(n,e,t){let r=t.querySelector(".play"),o=t.querySelector(".stop"),i=t.querySelector(".scrub"),s=t.querySelector(".playhead"),a=t.querySelector(".timecode"),c=t.querySelector(".player-canvas"),l=new vt({timeline:n}),u=await e.playback(n);c.replaceChildren(u.canvas),r.disabled=!1,o.disabled=!1,r.addEventListener("click",()=>u.play()),o.addEventListener("click",()=>u.pause()),i.max=String(Math.ceil(u.duration));let d=!1,m=null,f=!1;u.playback.onTick.on(()=>g(u.currentTime,u.duration));let p=async y=>{if(m=y,!f){for(f=!0;m;){let x=m;m=null,await u.seek(x)}f=!1}},h=(y,x)=>{a.textContent=`${hc(y)} / ${hc(x)}`};i.addEventListener("input",async()=>{d=!0;let y=Math.max(0,Math.min(+i.value,u.duration));h(y,u.duration),await p(y)}),i.addEventListener("change",async()=>{d=!1;let y=Math.max(0,Math.min(+i.value,u.duration));await p(y)});let g=(y,x)=>{let v=Math.max(0,Math.min(y,x));d||(i.value=String(Math.round(v)));let T=x?v/x*100:0;s.style.left=`${T}%`,h(v,x)};u.update(l.timeline)}function hc(n){let e=Math.max(0,n),t=Math.floor(e/1e3),r=Math.floor(t/60),o=t%60,i=Math.floor(e%1e3);return`${r}:${String(o).padStart(2,"0")}.${String(i).padStart(3,"0")}`}async function xc(n,e,t){let r=t.querySelector(".waveform-canvas"),o=t.querySelector(".width");r.replaceChildren();let i=await ao.init(n,e,r);o.oninput=()=>{let s=+o.value;i.width=s}}async function Oi(n,e){let t=new xo(n),{videoA:r}=await t.load({videoA:yo.make(e)});return{timeline:t.timeline(i=>{let s=i.text("content",{duration:1e3}),a=i.textStyle({fill:"green",fontSize:100});return i.set(s.id,{styleId:a.id}),i.sequence(i.stack(s,i.video(r,{duration:3e3,start:1e3}),i.audio(r,{duration:1e3})),i.gap(500),i.video(r,{duration:7e3,start:5e3}))}),omni:t}}async function bc(n,e){let t=e.querySelector(".range"),r=e.querySelector(".range-view"),o=e.querySelector(".range-size"),i=e.querySelector(".frequency"),s=e.querySelector(".frequency-view"),a=e.querySelector(".filmstrip"),c=1/10,l=.5;a.replaceChildren();let u=await io.init(n,{onChange(d){let m=d.sort((f,p)=>f.time-p.time);a.replaceChildren(...m.map(({time:f,canvas:p})=>Sl(f,p.canvas)))},frequency:c,canvasSinkOptions:{width:80,height:50,fit:"fill"}});o.oninput=()=>{l=+o.value;let d=+t.value,m=d+l;u.range=[d,m],r.textContent=`visible time range: [${d}, ${m}]`},t.oninput=()=>{let d=+t.value,m=d+l;u.range=[d,m],r.textContent=`visible time range: [${d}, ${m}]`},i.oninput=()=>{u.frequency=1/+i.value,s.textContent=`frame every ${u.frequency.toFixed(3)} second (${i.value} frames per second)`},u.range=[10,10.5]}function Sl(n,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=`${n.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 yc(n,e){let t={width:1920,height:1080},r=document.createElement("canvas");r.width=t.width,r.height=t.height;let o=r.getContext("2d");async function i(){let s=n.decodeVideo({source:e,async onFrame(m){let f=await n.composite([{id:0,kind:"image",frame:m},{id:1,kind:"text",content:"omnitool",style:{fontSize:50,fill:"green"}}]);return m.close(),o?.drawImage(f,0,0),f}}),a=n.decodeAudio({source:e}),{readable:c,done:l}=n.encode({video:s,audio:a,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}}),d=await(await window.showSaveFilePicker()).createWritable();await Promise.all([c.pipeTo(d),l])}return{canvas:r,run:i}}var Zt=await to.setup({workerUrl:new URL("../driver/driver.worker.bundle.min.js",import.meta.url)}),Cl=document.querySelector("[data-demo='transcode']"),Pl=document.querySelector("[data-demo='filmstrip']"),Il=document.querySelector("[data-demo='waveform']"),vc=document.querySelector("[data-demo='playback']"),Tt=document.querySelector("[data-demo='export']"),Tc=Tt.querySelector("[data-action='export']"),vo=null;await Zt.thread.work.hello(),Zt.machina.count===1?console.log("\u2705 driver works"):console.error("\u274C FAIL driver call didn't work");var Jt=(n,e)=>{let t=n.querySelector(".progress"),r=n.querySelector(".status");e==="running"?(t.removeAttribute("value"),r.textContent="running"):e==="done"?(t.value=1,r.textContent="done"):(t.value=0,r.textContent="idle")},zi=(n,e)=>{let t=n.querySelector("input[type='file']"),r=n.querySelector("[data-action='run']");r.disabled=!0,t.addEventListener("input",()=>{r.disabled=!t.files?.length}),r.addEventListener("click",async()=>{let o=t.files?.[0];if(o){r.disabled=!0,Jt(n,"running");try{await e(o,n),Jt(n,"done")}finally{r.disabled=!1}}})};zi(Cl,async(n,e)=>{let t=e.querySelector(".demo-preview"),r=yc(Zt,n);t.replaceChildren(r.canvas),await r.run()});zi(Pl,async(n,e)=>{await bc(n,e)});zi(Il,async(n,e)=>{await xc(Zt,n,e)});{let n=vc.querySelector("input[type='file']");n.addEventListener("input",async()=>{let e=n.files?.[0];if(!e)return;let{timeline:t,omni:r}=await Oi(Zt,e);await gc(t,r,vc)})}{let n=Tt.querySelector("input[type='file']");n.addEventListener("input",async()=>{let e=n.files?.[0];if(!e)return;Jt(Tt,"running");let{timeline:t,omni:r}=await Oi(Zt,e);vo={timeline:t,omni:r},Tc.disabled=!1;let o=Tt.querySelector(".demo-preview"),i=await r.playback(t);await i.seek(0),o.replaceChildren(i.canvas),Jt(Tt,"done")})}Tc.addEventListener("click",async()=>{vo&&(Jt(Tt,"running"),await vo.omni.render(vo.timeline),Jt(Tt,"done"))});
|
|
2488
|
+
`,[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;this.subscriptions.forEach((t=>t())),this.container.remove(),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),(e=this.unsubscribeOnScroll)===null||e===void 0||e.forEach((t=>t())),this.unsubscribeOnScroll=[],this.dragStream&&(this.dragStream.cleanup(),this.dragStream=null),this.scrollStream&&(this.scrollStream.cleanup(),this.scrollStream=null)}createDelay(e=10){let t,r,o=()=>{t&&(clearTimeout(t),t=void 0),r&&(r(),r=void 0)};return this.timeouts.push(o),()=>new Promise(((i,s)=>{o(),r=s,t=setTimeout((()=>{t=void 0,r=void 0,i()}),e)}))}getHeight(e,t){var r;let o=((r=this.audioData)===null||r===void 0?void 0:r.numberOfChannels)||1;return(function({optionsHeight:i,optionsSplitChannels:s,parentHeight:a,numberOfChannels:c,defaultHeight:l=128}){if(i==null)return l;let u=Number(i);if(!isNaN(u))return u;if(i==="auto"){let d=a||l;return s?.every((m=>!m.overlay))?d/c:d}return l})({optionsHeight:e,optionsSplitChannels:t,parentHeight:this.parent.clientHeight,numberOfChannels:o,defaultHeight:128})}convertColorValues(e,t){return(function(r,o,i){if(!Array.isArray(r))return r||"";if(r.length===0)return"#999";if(r.length<2)return r[0]||"";let s=document.createElement("canvas"),a=s.getContext("2d"),c=i??s.height*o,l=a.createLinearGradient(0,0,0,c||o),u=1/(r.length-1);return r.forEach(((d,m)=>{l.addColorStop(m*u,d)})),l})(e,this.getPixelRatio(),t?.canvas.height)}getPixelRatio(){return e=window.devicePixelRatio,Math.max(1,e||1);var e}renderBarWaveform(e,t,r,o){let{width:i,height:s}=r.canvas,{halfHeight:a,barWidth:c,barRadius:l,barIndexScale:u,barSpacing:d,barMinHeight:m}=(function({width:p,height:h,length:g,options:y,pixelRatio:x}){let v=h/2,T=y.barWidth?y.barWidth*x:1,S=y.barGap?y.barGap*x:y.barWidth?T/2:0,k=T+S||1;return{halfHeight:v,barWidth:T,barGap:S,barRadius:y.barRadius||0,barMinHeight:y.barMinHeight?y.barMinHeight*x:0,barIndexScale:g>0?p/k/g:0,barSpacing:k}})({width:i,height:s,length:(e[0]||[]).length,options:t,pixelRatio:this.getPixelRatio()}),f=(function({channelData:p,barIndexScale:h,barSpacing:g,barWidth:y,halfHeight:x,vScale:v,canvasHeight:T,barAlign:S,barMinHeight:k}){let I=p[0]||[],C=p[1]||I,A=I.length,R=[],D=0,L=0,Y=0;for(let U=0;U<=A;U++){let Ne=Math.round(U*h);if(Ne>D){let{topHeight:wc,totalHeight:Li}=gl({maxTop:L,maxBottom:Y,halfHeight:x,vScale:v,barMinHeight:k,barAlign:S}),kc=xl({barAlign:S,halfHeight:x,topHeight:wc,totalHeight:Li,canvasHeight:T});R.push({x:D*g,y:kc,width:y,height:Li}),D=Ne,L=0,Y=0}let Ni=Math.abs(I[U]||0),Ui=Math.abs(C[U]||0);Ni>L&&(L=Ni),Ui>Y&&(Y=Ui)}return R})({channelData:e,barIndexScale:u,barSpacing:d,barWidth:c,halfHeight:a,vScale:o,canvasHeight:s,barAlign:t.barAlign,barMinHeight:m});r.beginPath();for(let p of f)l&&"roundRect"in r?r.roundRect(p.x,p.y,p.width,p.height,l):r.rect(p.x,p.y,p.width,p.height);r.fill(),r.closePath()}renderLineWaveform(e,t,r,o){let{width:i,height:s}=r.canvas,a=(function({channelData:c,width:l,height:u,vScale:d}){let m=u/2,f=c[0]||[];return[f,c[1]||f].map(((p,h)=>{let g=p.length,y=g?l/g:0,x=m,v=h===0?-1:1,T=[{x:0,y:x}],S=0,k=0;for(let I=0;I<=g;I++){let C=Math.round(I*y);if(C>S){let R=x+(Math.round(k*m*d)||1)*v;T.push({x:S,y:R}),S=C,k=0}let A=Math.abs(p[I]||0);A>k&&(k=A)}return T.push({x:S,y:x}),T}))})({channelData:e,width:i,height:s,vScale:o});r.beginPath();for(let c of a)if(c.length){r.moveTo(c[0].x,c[0].y);for(let l=1;l<c.length;l++){let u=c[l];r.lineTo(u.x,u.y)}}r.fill(),r.closePath()}renderWaveform(e,t,r){if(r.fillStyle=this.convertColorValues(t.waveColor,r),t.renderFunction)return void t.renderFunction(e,r);let o=(function({channelData:i,barHeight:s,normalize:a,maxPeak:c}){var l;let u=s||1;if(!a)return u;let d=i[0];if(!d||d.length===0)return u;let m=c??0;if(!c)for(let f=0;f<d.length;f++){let p=(l=d[f])!==null&&l!==void 0?l:0,h=Math.abs(p);h>m&&(m=h)}return m?u/m:u})({channelData:e,barHeight:t.barHeight,normalize:t.normalize,maxPeak:t.maxPeak});Ya(t)?this.renderBarWaveform(e,t,r,o):this.renderLineWaveform(e,t,r,o)}renderSingleCanvas(e,t,r,o,i,s,a){let c=this.getPixelRatio(),l=document.createElement("canvas");l.width=Math.round(r*c),l.height=Math.round(o*c),l.style.width=`${r}px`,l.style.height=`${o}px`,l.style.left=`${Math.round(i)}px`,s.appendChild(l);let u=l.getContext("2d");if(t.renderFunction?(u.fillStyle=this.convertColorValues(t.waveColor,u),t.renderFunction(e,u)):this.renderWaveform(e,t,u),l.width>0&&l.height>0){let d=l.cloneNode(),m=d.getContext("2d");m.drawImage(l,0,0),m.globalCompositeOperation="source-in",m.fillStyle=this.convertColorValues(t.progressColor,m),m.fillRect(0,0,l.width,l.height),a.appendChild(d)}}renderMultiCanvas(e,t,r,o,i,s){let a=this.getPixelRatio(),{clientWidth:c}=this.scrollContainer,l=r/a,u=(function({clientWidth:p,totalWidth:h,options:g}){return Xa(Math.min(8e3,p,h),g)})({clientWidth:c,totalWidth:l,options:t}),d={};if(u===0)return;let m=p=>{if(p<0||p>=f||d[p])return;d[p]=!0;let h=p*u,g=Math.min(l-h,u);if(g=Xa(g,t),g<=0)return;let y=(function({channelData:x,offset:v,clampedWidth:T,totalWidth:S}){return x.map((k=>{let I=Math.floor(v/S*k.length),C=Math.floor((v+T)/S*k.length);return k.slice(I,C)}))})({channelData:e,offset:h,clampedWidth:g,totalWidth:l});this.renderSingleCanvas(y,t,g,o,h,i,s)},f=Math.ceil(l/u);if(!this.isScrollable){for(let p=0;p<f;p++)m(p);return}if(Ka({scrollLeft:this.scrollContainer.scrollLeft,totalWidth:l,numCanvases:f}).forEach((p=>m(p))),f>1){let p=this.on("scroll",(()=>{let{scrollLeft:h}=this.scrollContainer;Object.keys(d).length>10&&(i.innerHTML="",s.innerHTML="",d={}),Ka({scrollLeft:h,totalWidth:l,numCanvases:f}).forEach((g=>m(g)))}));this.unsubscribeOnScroll.push(p)}}renderChannel(e,t,r,o){var{overlay:i}=t,s=(function(u,d){var m={};for(var f in u)Object.prototype.hasOwnProperty.call(u,f)&&d.indexOf(f)<0&&(m[f]=u[f]);if(u!=null&&typeof Object.getOwnPropertySymbols=="function"){var p=0;for(f=Object.getOwnPropertySymbols(u);p<f.length;p++)d.indexOf(f[p])<0&&Object.prototype.propertyIsEnumerable.call(u,f[p])&&(m[f[p]]=u[f[p]])}return m})(t,["overlay"]);let a=document.createElement("div"),c=this.getHeight(s.height,s.splitChannels);a.style.height=`${c}px`,i&&o>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,s,r,c,a,l)}render(e){return oe(this,void 0,void 0,(function*(){var t;this.timeouts.forEach((l=>l())),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(),o=this.scrollContainer.clientWidth,{scrollWidth:i,isScrollable:s,useParentWidth:a,width:c}=(function({duration:l,minPxPerSec:u=0,parentWidth:d,fillParent:m,pixelRatio:f}){let p=Math.ceil(l*u),h=p>d,g=!!(m&&!h);return{scrollWidth:p,isScrollable:h,useParentWidth:g,width:(g?d:p)*f}})({duration:e.duration,minPxPerSec:this.options.minPxPerSec||0,parentWidth:o,fillParent:this.options.fillParent,pixelRatio:r});if(this.isScrollable=s,this.wrapper.style.width=a?"100%":`${i}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 l=0;l<e.numberOfChannels;l++){let u=Object.assign(Object.assign({},this.options),(t=this.options.splitChannels)===null||t===void 0?void 0:t[l]);this.renderChannel([e.getChannelData(l)],u,c,l)}else{let l=[e.getChannelData(0)];e.numberOfChannels>1&&l.push(e.getChannelData(1)),this.renderChannel(l,this.options,c,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(),o=(function(i){let s=2*i;return(s<0?Math.floor(s):Math.ceil(s))/2})(r-t);this.scrollContainer.scrollLeft+=o}}zoom(e){this.options.minPxPerSec=e,this.reRender()}scrollIntoView(e,t=!1){let{scrollLeft:r,scrollWidth:o,clientWidth:i}=this.scrollContainer,s=e*o,a=r,c=r+i,l=i/2;if(this.isDragging)s+30>c?this.scrollContainer.scrollLeft+=30:s-30<a&&(this.scrollContainer.scrollLeft-=30);else{(s<a||s>c)&&(this.scrollContainer.scrollLeft=s-(this.options.autoCenter?l:0));let u=s-r-l;t&&this.options.autoCenter&&u>0&&(this.scrollContainer.scrollLeft+=u)}}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=this.options.cursorWidth?`translateX(-${e*this.options.cursorWidth}px)`:"",this.isScrollable&&this.options.autoScroll&&this.audioData&&this.audioData.duration>0&&this.scrollIntoView(e,t)}exportImage(e,t,r){return oe(this,void 0,void 0,(function*(){let o=this.canvasWrapper.querySelectorAll("canvas");if(!o.length)throw new Error("No waveform data");if(r==="dataURL"){let i=Array.from(o).map((s=>s.toDataURL(e,t)));return Promise.resolve(i)}return Promise.all(Array.from(o).map((i=>new Promise(((s,a)=>{i.toBlob((c=>{c?s(c):a(new Error("Could not export image"))}),e,t)})))))}))}},Mi=class extends bt{constructor(){super(...arguments),this.animationFrameId=null,this.isRunning=!1}start(){if(this.isRunning)return;this.isRunning=!0;let e=()=>{this.isRunning&&(this.emit("tick"),this.animationFrameId=requestAnimationFrame(e))};e()}stop(){this.isRunning=!1,this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}destroy(){this.stop()}},Dr=class extends bt{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 oe(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())})).catch((t=>{console.error("WebAudioPlayer load error:",t)}))}_play(){if(!this.paused)return;this.paused=!1,this.bufferNode&&(this.bufferNode.onended=null,this.bufferNode.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 e=this.playedDuration*this._playbackRate;(e>=this.duration||e<0)&&(e=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,e),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 oe(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 oe(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}removeAttribute(e){switch(e){case"src":this.src="";break;case"playbackRate":this.playbackRate=0;break;case"currentTime":this.currentTime=0;break;case"duration":this.duration=0;break;case"volume":this.volume=0;break;case"muted":this.muted=!1}}},yl={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3},Qt=class n extends Di{static create(e){return new n(e)}getState(){return this.wavesurferState}getRenderer(){return this.renderer}constructor(e){let t=e.media||(e.backend==="WebAudio"?new Dr: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.reactiveCleanups=[],this.options=Object.assign({},yl,e);let{state:r,actions:o}=(function(a){var c,l,u,d,m,f;let p=(c=a?.currentTime)!==null&&c!==void 0?c:q(0),h=(l=a?.duration)!==null&&l!==void 0?l:q(0),g=(u=a?.isPlaying)!==null&&u!==void 0?u:q(!1),y=(d=a?.isSeeking)!==null&&d!==void 0?d:q(!1),x=(m=a?.volume)!==null&&m!==void 0?m:q(1),v=(f=a?.playbackRate)!==null&&f!==void 0?f:q(1),T=q(null),S=q(null),k=q(""),I=q(0),C=q(0),A=xt((()=>!g.value),[g]),R=xt((()=>T.value!==null),[T]),D=xt((()=>R.value&&h.value>0),[R,h]),L=xt((()=>p.value),[p]),Y=xt((()=>h.value>0?p.value/h.value:0),[p,h]);return{state:{currentTime:p,duration:h,isPlaying:g,isPaused:A,isSeeking:y,volume:x,playbackRate:v,audioBuffer:T,peaks:S,url:k,zoom:I,scrollPosition:C,canPlay:R,isReady:D,progress:L,progressPercent:Y},actions:{setCurrentTime:U=>{let Ne=Math.max(0,Math.min(h.value||1/0,U));p.set(Ne)},setDuration:U=>{h.set(Math.max(0,U))},setPlaying:U=>{g.set(U)},setSeeking:U=>{y.set(U)},setVolume:U=>{let Ne=Math.max(0,Math.min(1,U));x.set(Ne)},setPlaybackRate:U=>{let Ne=Math.max(.1,Math.min(16,U));v.set(Ne)},setAudioBuffer:U=>{T.set(U),U&&h.set(U.duration)},setPeaks:U=>{S.set(U)},setUrl:U=>{k.set(U)},setZoom:U=>{I.set(Math.max(0,U))},setScrollPosition:U=>{C.set(Math.max(0,U))}}}})({isPlaying:this.isPlayingSignal,currentTime:this.currentTimeSignal,duration:this.durationSignal,volume:this.volumeSignal,playbackRate:this.playbackRateSignal,isSeeking:this.seekingSignal});this.wavesurferState=r,this.wavesurferActions=o,this.timer=new Mi;let i=t?void 0:this.getMediaElement();this.renderer=new Ri(this.options,i),this.initPlayerEvents(),this.initRendererEvents(),this.initTimerEvents(),this.initReactiveState(),this.initPlugins();let s=this.options.url||this.getSrc()||"";Promise.resolve().then((()=>{this.emit("init");let{peaks:a,duration:c}=this.options;(s||a&&c)&&this.load(s,a,c).catch((l=>{this.emit("error",l instanceof Error?l:new Error(String(l)))}))}))}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()}})))}initReactiveState(){this.reactiveCleanups.push((function(e,t){let r=[];r.push(Ke((()=>{let s=e.isPlaying.value;t.emit(s?"play":"pause")}),[e.isPlaying])),r.push(Ke((()=>{let s=e.currentTime.value;t.emit("timeupdate",s),e.isPlaying.value&&t.emit("audioprocess",s)}),[e.currentTime,e.isPlaying])),r.push(Ke((()=>{e.isSeeking.value&&t.emit("seeking",e.currentTime.value)}),[e.isSeeking,e.currentTime]));let o=!1;r.push(Ke((()=>{e.isReady.value&&!o&&(o=!0,t.emit("ready",e.duration.value))}),[e.isReady,e.duration]));let i=!1;return r.push(Ke((()=>{let s=e.isPlaying.value,a=e.currentTime.value,c=e.duration.value,l=c>0&&a>=c;i&&!s&&l&&t.emit("finish"),i=s&&l}),[e.isPlaying,e.currentTime,e.duration])),r.push(Ke((()=>{let s=e.zoom.value;s>0&&t.emit("zoom",s)}),[e.zoom])),()=>{r.forEach((s=>s()))}})(this.wavesurferState,{emit:this.emit.bind(this)}))}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,o)=>{let i=this.getDuration();this.emit("scroll",e*i,t*i,r,o)})),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)})),this.renderer.on("resize",(()=>{this.emit("resize")})));{let e,t=this.renderer.on("drag",(r=>{var o;if(!this.options.interact)return;this.renderer.renderProgress(r),clearTimeout(e);let i=0,s=this.options.dragToSeek;this.isPlaying()?i=0:s===!0?i=200:s&&typeof s=="object"&&(i=(o=s.debounceTime)!==null&&o!==void 0?o:200),e=setTimeout((()=>{this.seekTo(r)}),i),this.emit("interaction",r*this.getDuration()),this.emit("drag",r)}));this.subscriptions.push((()=>{clearTimeout(e),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=so.createBuffer(this.exportPeaks(),e.duration)),e.peaks&&e.duration&&(this.decodedData=so.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,o){return oe(this,void 0,void 0,(function*(){var i;if(this.emit("load",e),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,this.stopAtPosition=null,(i=this.abortController)===null||i===void 0||i.abort(),this.abortController=null,!t&&!r){let a=this.options.fetchParams||{};window.AbortController&&!a.signal&&(this.abortController=new AbortController,a.signal=this.abortController.signal);let c=u=>this.emit("loading",u);t=yield hl.fetchBlob(e,c,a);let l=this.options.blobMimeType;l&&(t=new Blob([t],{type:l}))}this.setSrc(e,t);let s=yield new Promise((a=>{let c=o||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 Dr&&(a.duration=s)}if(r)this.decodedData=so.createBuffer(r,s||0);else if(t){let a=yield t.arrayBuffer();this.decodedData=yield so.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 oe(this,void 0,void 0,(function*(){try{return yield this.loadAudio(e,void 0,t,r)}catch(o){throw this.emit("error",o),o}}))}loadBlob(e,t,r){return oe(this,void 0,void 0,(function*(){try{return yield this.loadAudio("",e,t,r)}catch(o){throw this.emit("error",o),o}}))}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 o=Math.min(e,this.decodedData.numberOfChannels),i=[];for(let s=0;s<o;s++){let a=this.decodedData.getChannelData(s),c=[],l=a.length/t;for(let u=0;u<t;u++){let d=a.slice(Math.floor(u*l),Math.ceil((u+1)*l)),m=0;for(let f=0;f<d.length;f++){let p=d[f];Math.abs(p)>Math.abs(m)&&(m=p)}c.push(Math.round(m*r)/r)}i.push(c)}return i}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 oe(this,void 0,void 0,(function*(){e!=null&&this.setTime(e);let o=yield r.play.call(this);return t!=null&&(this.media instanceof Dr?this.media.stopAt(t):this.stopAtPosition=t),o}))}playPause(){return oe(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 oe(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.reactiveCleanups.forEach((t=>t())),this.reactiveCleanups=[],this.timer.destroy(),this.renderer.destroy(),super.destroy()}};Qt.BasePlugin=class extends bt{constructor(n){super(),this.subscriptions=[],this.isDestroyed=!1,this.options=n}onInit(){}_init(n){this.isDestroyed&&(this.subscriptions=[],this.isDestroyed=!1),this.wavesurfer=n,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((n=>n())),this.subscriptions=[],this.isDestroyed=!0,this.wavesurfer=void 0}},Qt.dom=pl;var ao=class n{wavesurfer;constructor(e,t,r){this.wavesurfer=Qt.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 o=e.decodeAudio({source:t}).getReader(),i=[],s=[],a=1024,c=await e.getAudioDuration(t);for(;;){let{done:l,value:u}=await o.read();if(l)break;let d=u.numberOfFrames,m=new Float32Array(d);u.copyTo(m,{planeIndex:0});for(let f=0;f<m.length;f++)if(s.push(m[f]),s.length>=a){let p=s.splice(0,a),h=Math.min(...p),g=Math.max(...p);i.push(h,g)}u.close()}return new n(i,r,c??0)}set width(e){this.wavesurfer.setOptions({width:e})}};var N=n=>n;var Yt=n=>n;var Ja=()=>{let n=!1,e=Yt(60),t=1e3/e,r=0,o=0,i=St(),s=null,a=l=>{if(requestAnimationFrame(a),!!n)for(r=l;l-o>=t;)o+=t,s?.(),s=null,i()};async function*c(){for(r=performance.now(),o=r,requestAnimationFrame(a);;)await new Promise(l=>s=l),yield}return{play(){n||(n=!0,r=performance.now(),o=r)},pause(){n=!1},setFPS(l){e=l,t=1e3/e},isPlaying(){return n},ticks:c,onTick:i}},ec=async(n,e)=>{let t=N(1e3/n.fps),r=n.duration/1e3,o=Math.ceil(r*n.fps);for(let i=0;i<o;i++){let s=N(i*t);await e(s,i)}};var Rr=n=>n;function rc(n){return"duration"in n}function nc(n){let e=[],t=new Map(n.timeline.items.map(r=>[r.id,r]));return Bi(n.timeline.rootId,t,n.from,{sequence:()=>{},stack:()=>{},video:(r,o,i)=>e.push({item:r,localTime:o,ancestors:i}),text:(r,o,i)=>e.push({item:r,localTime:o,ancestors:i}),audio:(r,o,i)=>e.push({item:r,localTime:o,ancestors:i})}),e}function oc(n,e,t){let r=Na;for(let o of e)r=tc(n,o,r);return tc(n,t,r)}function tc(n,e,t){if("spatialId"in e&&e.spatialId){let r=n.get(e.spatialId);if(r?.enabled){let o=Ba(r.transform);return za(o,t)}}return t}function Bi(n,e,t,r,o=[]){let i=e.get(n);if(i)switch(i.kind){case B.Stack:r.stack(i,t,o);for(let s of i.childrenIds)Bi(s,e,t,r,[...o,i]);break;case B.Sequence:{r.sequence(i,t,o);let s=N(0);for(let a of i.childrenIds){let c=e.get(a);if(!c||!rc(c))continue;let l=N(s+c.duration);if(t>=l){s=l;continue}let u=N(Math.max(0,t-s));Bi(a,e,u,r,[...o,i]),s=l}break}case B.Video:r.video(i,t,o);break;case B.Text:r.text(i,t,o);break;case B.Audio:r.audio(i,t,o);break}}function be(n,e){let t=e.items.find(r=>r.id===n);if(!t)return N(0);switch(t.kind){case B.Sequence:{let r=t.childrenIds.map(i=>e.items.find(s=>s.id===i)).filter(Boolean),o=N(0);for(let i=0;i<r.length;i++){let s=r[i];if(s.kind===B.Transition){let a=r[i-1],c=r[i+1];if(a&&c&&a.kind!==B.Transition&&c.kind!==B.Transition){let l=be(a.id,e),u=be(c.id,e),d=Math.max(0,Math.min(s.duration,l,u));o=N(o-d)}continue}o=N(o+be(s.id,e))}return o}case B.Stack:{let r=N(0);for(let o of t.childrenIds){let i=be(o,e);i>r&&(r=i)}return r}default:return rc(t)?t.duration:N(0)}}async function ic(n,e,t){return(await Promise.all(e.map(async({item:o,localTime:i})=>{if(o.kind!==B.Audio)return;let s=await n.getSink(o.mediaHash);if(!s)return;let a=o.start+i,c=Rr((t-a)/1e3),l=s.samples(a/1e3),u=await l.next();if(u.done)return;let d=u.value,m=l.next();return{offset:c,gain:o.gain??1,get currentSample(){return d},timelineTime:()=>Rr(c+d.timestamp),output:()=>({sample:d,timestamp:c+d.timestamp,gain:o.gain??1}),advance:async()=>{let f=await m;return f.done?!1:(d=f.value,m=l.next(),!0)}}}))).filter(o=>!!o)}var co=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let r=new ne({formats:le,source:await me(this.resolveMedia(e))}),o=await r.getPrimaryAudioTrack(),s=!!o&&await o.canDecode()&&o?new vr(o):null;return this.#e.set(e,{input:r,sink:s}),s}};function sc(n){let e={index:0,stream:n[0],time:n[0].timelineTime()};for(let[t,r]of n.entries()){let o=r.timelineTime();o<e.time&&(e={time:o,stream:r,index:t})}return e}function lo(n){let e=new co(n);return{async*sampleAudio(t,r){let o=nc({timeline:t,from:r}),i=await ic(e,o,r);for(;i.length>0;){let{stream:s,index:a}=sc(i);yield s.output(),await s.advance()||i.splice(a,1)}}}}var uo=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let r=new ne({formats:le,source:await me(this.resolveMedia(e))}),o=await r.getPrimaryVideoTrack(),s=!!o&&await o.canDecode()&&o?new Rt(o):null;return this.#e.set(e,{input:r,sink:s}),s}};async function ac(n,e,t,r){let[o,i]=await Promise.all([t,r]),s=o.find(l=>l.kind==="image")?.frame,a=i.find(l=>l.kind==="image")?.frame,c=[...o.filter(l=>l.kind!=="image"),...i.filter(l=>l.kind!=="image")];return s&&a?[{id:n.id,kind:"transition",name:"circle",progress:e,from:s,to:a},...c]:c}async function cc(n,e,t,r){let o=vl(n,e,t);if(!o)return[];let i=[...r,e];return o.isTransitioning?ac(o.transition,o.progress,yt(n,o.outgoing,o.outgoingTime,i),yt(n,o.incoming,o.incomingTime,i)):yt(n,o.item,o.localTime,i)}function vl(n,e,t){let r=e.childrenIds.map(i=>n.items.get(i)).filter(i=>!!i),o=N(0);for(let i=0;i<r.length;i++){let s=r[i];if(s.kind===B.Transition)continue;let a=o,c=be(s.id,n.timeline),l=N(a+c),u=r[i+1];if(!(u?.kind===B.Transition)){if(t<l)return{isTransitioning:!1,item:s,localTime:N(t-a)};o=l;continue}let m=u,f=r[i+2];if(!f||f.kind===B.Transition){o=l;continue}let p=be(f.id,n.timeline),h=Math.max(0,Math.min(m.duration,c,p)),g=N(l-h);if(t<g)return{isTransitioning:!1,item:s,localTime:N(t-a)};if(t<l){let y=N(t-g),x=N(t-a);return{isTransitioning:!0,incoming:f,outgoing:s,outgoingTime:x,incomingTime:y,progress:h>0?y/h:1,transition:m}}o=g,i++}return null}async function yt(n,e,t,r){let o=oc(n.items,r,e);switch(e.kind){case B.Stack:{let i=[...r,e];return(await Promise.all(e.childrenIds.map(a=>n.items.get(a)).filter(a=>!!a).map(a=>yt(n,a,t,i)))).flat()}case B.Sequence:return cc(n,e,t,r);case B.Video:{if(t<0||t>=e.duration)return[];let i=await n.videoSampler(e,t);return i?[{kind:"image",frame:i,matrix:o,id:e.id}]:[]}case B.Text:{if(t<0||t>=e.duration)return[];let i=e.styleId?n.items.get(e.styleId)?.style:void 0;return[{id:e.id,kind:"text",content:e.content,style:i,matrix:o}]}case B.Gap:return[{id:e.id,kind:"gap"}];default:return[]}}function lc(n){return async(e,t)=>{let o=await(await n.getSink(e.mediaHash))?.getSample(t/1e3),i=o?.toVideoFrame();return o?.close(),i??void 0}}function mo(n,e){let t=new uo(n),r=e??lc(t);return{async sample(o,i){let s=new Map(o.items.map(c=>[c.id,c])),a=s.get(o.rootId);return a?yt({videoSampler:r,timeline:o,items:s},a,i,[]):[]}}}var fo=class{timeline;resolveMedia;visualSampler;audioSampler;#e=N(0);#t=null;#r=Ja();onTick=this.#r.onTick;audioContext=new AudioContext({sampleRate:48e3});audioGain=this.audioContext.createGain();audioNodes=new Set;#n=null;constructor(e,t){this.timeline=e,this.resolveMedia=t,this.audioGain.connect(this.audioContext.destination),this.audioGain.gain.value=.7**2,this.visualSampler=mo(this.resolveMedia),this.audioSampler=lo(this.resolveMedia)}async*samples(){for await(let e of this.#r.ticks())yield this.visualSampler.sample(this.timeline,this.currentTime)}async seek(e){return this.pause(),this.#e=e,await this.visualSampler.sample(this.timeline,e)}async start(e){this.timeline=e,await this.audioContext.resume(),this.#e=this.currentTime,this.#t=this.audioContext.currentTime,this.#n?.abort(),this.#n=new AbortController;for(let t of this.audioNodes)t.stop();this.audioNodes.clear(),this.#r.play(),this.#o(this.#n.signal,Rr(this.#e/1e3))}pause(){this.#e=this.currentTime,this.#r.pause(),this.#n?.abort();for(let e of this.audioNodes)e.stop();this.audioNodes.clear()}get currentTime(){if(!this.#r.isPlaying()||this.#t===null)return this.#e;let e=(this.audioContext.currentTime-this.#t)*1e3;return N(this.#e+e)}setFps(e){this.#r.setFPS(e)}async#o(e,t){let r=this.audioContext;if(this.#t!==null)for await(let{sample:o,timestamp:i}of this.audioSampler.sampleAudio(this.timeline,N(t*1e3))){if(e.aborted||!this.#r.isPlaying())return;for(;i-(r.currentTime-this.#t+t)>.75;)await new Promise(c=>setTimeout(c,25));let s=r.createBufferSource();s.buffer=o.toAudioBuffer(),s.connect(this.audioGain),s.onended=()=>this.audioNodes.delete(s),this.audioNodes.add(s);let a=this.#t+i-t;a>=r.currentTime?s.start(a):s.start(r.currentTime,r.currentTime-a)}}};var po=class{driver;timeline;canvas;playback;constructor(e,t,r){this.driver=e,this.timeline=r,this.playback=new fo(r,t),this.canvas=e.compositor.pixi.renderer.canvas}async play(){await this.playback.start(this.timeline);for await(let e of this.playback.samples())(await this.driver.composite(e)).close(),this.currentTime>=this.duration&&this.pause()}pause(){this.playback.pause()}async seek(e){let t=await this.playback.seek(N(e));(await this.driver.composite(t)).close()}setFPS(e){this.playback.setFps(Yt(e))}get duration(){return be(this.timeline.rootId,this.timeline)}get currentTime(){return this.playback.currentTime}async update(e){this.timeline=e}};var vt=class{state;constructor(e){this.state=e}require(e){return e===void 0?void 0:this.state.timeline.items.find(r=>r.id===e)}get timeline(){return this.state.timeline}getId(){return ye.toInteger(ye.random())}#e(e){this.state.timeline=e(this.state.timeline)}register(e){this.#e(t=>({...t,items:[...t.items,e]}))}textStyle=e=>{let t={id:this.getId(),kind:B.TextStyle,style:e};return this.register(t),t};spatial=e=>{let t={id:this.getId(),kind:B.Spatial,transform:e,enabled:!0};return this.register(t),t};sequence=(...e)=>{let t={id:this.getId(),kind:B.Sequence,childrenIds:e.map(r=>r.id)};return this.register(t),t};stack=(...e)=>{let t={kind:B.Stack,id:this.getId(),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:B.Video,id:this.getId(),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:B.Audio,id:this.getId(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration,gain:t?.gain??1};return this.register(r),r};text=(e,t)=>{let r={id:this.getId(),content:e,kind:B.Text,duration:t?.duration??2e3};return t?.styles&&(r.styleId=this.textStyle(t.styles).id),this.register(r),r};gap=e=>{let t={id:this.getId(),kind:B.Gap,duration:e};return this.register(t),t};transition={crossfade:e=>{let t={id:this.getId(),kind:B.Transition,effect:ro.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],o=e?.rotation??0;return[t,r,o]};addChildren(e,...t){this.#e(r=>(r.items.find(({id:i})=>i===e.id).childrenIds.push(...t.map(i=>i.id)),r))}set=(e,t)=>{this.#e(r=>({...r,items:r.items.map(o=>o.id===e?{...o,...t}:o)}))}};var ho=class{#e;#t;constructor(e={}){this.#e=e.chunkFrames??1024,this.#t=e.clamp??!0}async*mix(e){let t=this.#e,r=null,o=null,i=[],s=0,a=0;for await(let c of e){if(o===null)o=c.planes.length,r=c.sampleRate;else{if(c.planes.length!==o)throw new Error("Channel count changed");if(c.sampleRate!==r)throw new Error("Sample rate changed")}let l=Math.round(c.timestamp*r),u=c.planes[0]?.length??0;for(;s+t<=l;)yield this.#r(i,s,o,r),s+=t;i.push({startFrame:l,endFrame:l+u,data:c.planes}),a=Math.max(a,l+u)}if(o!==null&&r!==null)for(;s<a;)yield this.#r(i,s,o,r),s+=t}#r(e,t,r,o){let i=this.#e,s=new Float32Array(r*i),a=t+i;for(let c=0;c<r;c++){let l=c*i,u=s.subarray(l,l+i);for(let d of e){let m=d.data[c];if(!m)continue;let f=Math.max(t,d.startFrame),p=Math.min(a,d.endFrame);if(f>=p)continue;let h=f-t,g=f-d.startFrame,y=p-f;for(let x=0;x<y;x++)u[h+x]+=m[g+x]}if(this.#t)for(let d=0;d<i;d++){let m=u[d];u[d]=m<-1?-1:m>1?1:m}}for(let c=e.length-1;c>=0;c--)e[c].endFrame<=a&&e.splice(c,1);return{planar:s,sampleRate:o,channels:r,frames:i,startFrame:t}}};var Tl=(n,e,t)=>{if(e===t)return n;let r=t/e,o=Math.max(1,Math.round(n.length*r)),i=new Float32Array(o);for(let s=0;s<o;s++){let a=s/r,c=Math.floor(a),l=Math.min(c+1,n.length-1),u=a-c;i[s]=n[c]*(1-u)+n[l]*u}return i},uc=(n,e)=>{let t=n.numberOfChannels,r=new Array(t),o=0;for(let i=0;i<t;i++){let s=new Float32Array(n.numberOfFrames);n.copyTo(s,{planeIndex:i,format:"f32-planar"});let a=Tl(s,n.sampleRate,e);r[i]=a,o=a.length}return{data:r,frames:o}};var dc=(n,e)=>{if(e!==1)for(let t of n)for(let r=0;r<t.length;r++)t[r]*=e};function mc({timeline:n,resolveMedia:e}){let t=new ho,r=wl(n,e),o=new TransformStream,i=o.writable.getWriter();async function s(){for await(let a of t.mix(r)){let c=new AudioData({format:"f32-planar",sampleRate:a.sampleRate,numberOfFrames:a.frames,numberOfChannels:a.channels,timestamp:Math.round(a.startFrame/a.sampleRate*1e6),data:new Float32Array(a.planar)});await i.write(c)}await i.close()}return s(),o.readable}async function*wl(n,e){let t=lo(e);for await(let{sample:r,timestamp:o,gain:i}of t.sampleAudio(n,N(0))){let{data:s}=uc(r,48e3);dc(s,i),yield{planes:s,sampleRate:48e3,timestamp:o},r.close()}}var go=class{driver;resolveMedia;#e;#t=new Map;constructor(e,t){this.driver=e,this.resolveMedia=t,this.#e=mo(t,(r,o)=>{let i=kl(N(r.start+o));return this.#r(r).next(i)})}cursor(e){let t=Number.NEGATIVE_INFINITY;return{next:r=>{if(r<t)throw new Error(`CursorVisualSampler is forward-only: requested ${r}ms after ${t}ms`);return t=r,this.#e.sample(e,r)},cancel:()=>this.#n()}}#r(e){let t=this.#t.get(e.id);if(t)return t;let r=this.resolveMedia(e.mediaHash),o=this.driver.decodeVideo({source:r}),i=this.#o(o.getReader());return this.#t.set(e.id,i),i}async#n(){await Promise.all([...this.#t.values()].map(e=>e.cancel())),this.#t.clear()}#o(e){return{async next(t){let r=null;for(;;){let{done:o,value:i}=await e.read();if(o){let a=r?new VideoFrame(r):void 0;return r?.close(),a}let s=i.timestamp??0;if(s>=t){let a=r?.timestamp??Number.NEGATIVE_INFINITY,c=!!r&&Math.abs(a-t)<Math.abs(s-t),l=c?r:i,u=c?i:r,d=new VideoFrame(l);return l.close(),u?.close(),d}r?.close(),r=i}},cancel:async()=>await e.cancel()}}},kl=n=>Math.round(n*1e3);function fc({timeline:n,fps:e,driver:t,resolveMedia:r}){let o=new TransformStream,i=o.writable.getWriter(),a=new go(t,r).cursor(n),c=1/e,l=be(n.rootId,n);async function u(){await ec({fps:e,duration:l},async(d,m)=>{let f=await a.next(d),p=await t.composite(f),h=new VideoFrame(p,{timestamp:Math.round(m*c*1e6),duration:Math.round(c*1e6)});await i.write(h),p.close()}),await i.close()}return u(),o.readable}function pc(n){let e=mc({...n}),t=fc({...n});return n.driver.encode({video:t,audio:e,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}})}var xo=class{driver;resources=new oo;constructor(e){this.driver=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 vt({timeline:{format:"timeline",info:"https://omniclip.app/",version:0,items:[],rootId:0}}),r=e(t);return t.timeline.rootId=r.id,t.timeline};playback=async e=>new po(this.driver,t=>this.resources.require(t).url,e);render=async(e,t=30)=>pc({timeline:e,fps:Yt(t),driver:this.driver,resolveMedia:r=>this.resources.require(r).url})};var bo=class{data;bytes;hash;nickname;constructor(e,t,r,o){this.data=e,this.bytes=t,this.hash=r,this.nickname=o}static async make(e){let t=new Uint8Array(e),r=new Uint8Array(await crypto.subtle.digest("SHA-256",t)),o=zr.fromBytes(r),i=Xi.sigil.fromBytes(r);return new this(e,r,o,i)}};var yo=class{url;bytes;blob;filename;checksum;constructor(e,t,r,o,i){this.url=e,this.bytes=t,this.blob=r,this.filename=o,this.checksum=i}static async make(e,t){let r=await e.arrayBuffer(),o=new Uint8Array(r),i=await bo.make(o),s=t??i.nickname,a=URL.createObjectURL(e);return new this(a,o,e,s,i)}static async load(e){}};async function gc(n,e,t){let r=t.querySelector(".play"),o=t.querySelector(".stop"),i=t.querySelector(".scrub"),s=t.querySelector(".playhead"),a=t.querySelector(".timecode"),c=t.querySelector(".player-canvas"),l=new vt({timeline:n}),u=await e.playback(n);c.replaceChildren(u.canvas),r.disabled=!1,o.disabled=!1,r.addEventListener("click",()=>u.play()),o.addEventListener("click",()=>u.pause()),i.max=String(Math.ceil(u.duration));let d=!1,m=null,f=!1;u.playback.onTick.on(()=>g(u.currentTime,u.duration));let p=async y=>{if(m=y,!f){for(f=!0;m;){let x=m;m=null,await u.seek(x)}f=!1}},h=(y,x)=>{a.textContent=`${hc(y)} / ${hc(x)}`};i.addEventListener("input",async()=>{d=!0;let y=Math.max(0,Math.min(+i.value,u.duration));h(y,u.duration),await p(y)}),i.addEventListener("change",async()=>{d=!1;let y=Math.max(0,Math.min(+i.value,u.duration));await p(y)});let g=(y,x)=>{let v=Math.max(0,Math.min(y,x));d||(i.value=String(Math.round(v)));let T=x?v/x*100:0;s.style.left=`${T}%`,h(v,x)};u.update(l.timeline)}function hc(n){let e=Math.max(0,n),t=Math.floor(e/1e3),r=Math.floor(t/60),o=t%60,i=Math.floor(e%1e3);return`${r}:${String(o).padStart(2,"0")}.${String(i).padStart(3,"0")}`}async function xc(n,e,t){let r=t.querySelector(".waveform-canvas"),o=t.querySelector(".width");r.replaceChildren();let i=await ao.init(n,e,r);o.oninput=()=>{let s=+o.value;i.width=s}}async function Oi(n,e){let t=new xo(n),{videoA:r}=await t.load({videoA:yo.make(e)});return{timeline:t.timeline(i=>{let s=i.text("content",{duration:1e3}),a=i.textStyle({fill:"green",fontSize:100});return i.set(s.id,{styleId:a.id}),i.sequence(i.stack(s,i.video(r,{duration:3e3,start:1e3}),i.audio(r,{duration:1e3})),i.gap(500),i.video(r,{duration:7e3,start:5e3}))}),omni:t}}async function bc(n,e){let t=e.querySelector(".range"),r=e.querySelector(".range-view"),o=e.querySelector(".range-size"),i=e.querySelector(".frequency"),s=e.querySelector(".frequency-view"),a=e.querySelector(".filmstrip"),c=1/10,l=.5;a.replaceChildren();let u=await io.init(n,{onChange(d){let m=d.sort((f,p)=>f.time-p.time);a.replaceChildren(...m.map(({time:f,canvas:p})=>Sl(f,p.canvas)))},frequency:c,canvasSinkOptions:{width:80,height:50,fit:"fill"}});o.oninput=()=>{l=+o.value;let d=+t.value,m=d+l;u.range=[d,m],r.textContent=`visible time range: [${d}, ${m}]`},t.oninput=()=>{let d=+t.value,m=d+l;u.range=[d,m],r.textContent=`visible time range: [${d}, ${m}]`},i.oninput=()=>{u.frequency=1/+i.value,s.textContent=`frame every ${u.frequency.toFixed(3)} second (${i.value} frames per second)`},u.range=[10,10.5]}function Sl(n,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=`${n.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 yc(n,e){let t={width:1920,height:1080},r=document.createElement("canvas");r.width=t.width,r.height=t.height;let o=r.getContext("2d");async function i(){let s=n.decodeVideo({source:e,async onFrame(m){let f=await n.composite([{id:0,kind:"image",frame:m},{id:1,kind:"text",content:"omnitool",style:{fontSize:50,fill:"green"}}]);return m.close(),o?.drawImage(f,0,0),f}}),a=n.decodeAudio({source:e}),{readable:c,done:l}=n.encode({video:s,audio:a,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}}),d=await(await window.showSaveFilePicker()).createWritable();await Promise.all([c.pipeTo(d),l])}return{canvas:r,run:i}}var Zt=await to.setup({workerUrl:new URL("../driver/driver.worker.bundle.min.js",import.meta.url)}),Cl=document.querySelector("[data-demo='transcode']"),Pl=document.querySelector("[data-demo='filmstrip']"),Il=document.querySelector("[data-demo='waveform']"),vc=document.querySelector("[data-demo='playback']"),Tt=document.querySelector("[data-demo='export']"),Tc=Tt.querySelector("[data-action='export']"),vo=null;await Zt.thread.work.hello(),Zt.machina.count===1?console.log("\u2705 driver works"):console.error("\u274C FAIL driver call didn't work");var Jt=(n,e)=>{let t=n.querySelector(".progress"),r=n.querySelector(".status");e==="running"?(t.removeAttribute("value"),r.textContent="running"):e==="done"?(t.value=1,r.textContent="done"):(t.value=0,r.textContent="idle")},zi=(n,e)=>{let t=n.querySelector("input[type='file']"),r=n.querySelector("[data-action='run']");r.disabled=!0,t.addEventListener("input",()=>{r.disabled=!t.files?.length}),r.addEventListener("click",async()=>{let o=t.files?.[0];if(o){r.disabled=!0,Jt(n,"running");try{await e(o,n),Jt(n,"done")}finally{r.disabled=!1}}})};zi(Cl,async(n,e)=>{let t=e.querySelector(".demo-preview"),r=yc(Zt,n);t.replaceChildren(r.canvas),await r.run()});zi(Pl,async(n,e)=>{await bc(n,e)});zi(Il,async(n,e)=>{await xc(Zt,n,e)});{let n=vc.querySelector("input[type='file']");n.addEventListener("input",async()=>{let e=n.files?.[0];if(!e)return;let{timeline:t,omni:r}=await Oi(Zt,e);await gc(t,r,vc)})}{let n=Tt.querySelector("input[type='file']");n.addEventListener("input",async()=>{let e=n.files?.[0];if(!e)return;Jt(Tt,"running");let{timeline:t,omni:r}=await Oi(Zt,e);vo={timeline:t,omni:r},Tc.disabled=!1;let o=Tt.querySelector(".demo-preview"),i=await r.playback(t);await i.seek(0),o.replaceChildren(i.canvas),Jt(Tt,"done")})}Tc.addEventListener("click",async()=>{vo&&(Jt(Tt,"running"),await vo.omni.render(vo.timeline),Jt(Tt,"done"))});
|
|
2489
2489
|
/*! Bundled license information:
|
|
2490
2490
|
|
|
2491
2491
|
mediabunny/dist/modules/src/misc.js:
|