@omnimedia/omnitool 1.1.0-71 → 1.1.0-72
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/driver/parts/compositor.ts +30 -32
- package/x/demo/demo.bundle.min.js +1 -1
- package/x/demo/demo.bundle.min.js.map +2 -2
- package/x/driver/parts/compositor.js +20 -23
- package/x/driver/parts/compositor.js.map +1 -1
- package/x/index.html +2 -2
- package/x/tests.bundle.min.js +1 -1
- package/x/tests.bundle.min.js.map +2 -2
- package/x/tests.html +1 -1
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@ export class Compositor {
|
|
|
28
28
|
|
|
29
29
|
#transitions: Map<string, ReturnType<typeof makeTransition>> = new Map()
|
|
30
30
|
// objects rendered for current Composition
|
|
31
|
-
#activeObjects = new Map<number, Container>()
|
|
31
|
+
#activeObjects = new Map<number, {sprite: Container, dispose: () => void}>()
|
|
32
32
|
|
|
33
33
|
async composite(
|
|
34
34
|
composition: Composition,
|
|
@@ -55,7 +55,7 @@ export class Compositor {
|
|
|
55
55
|
* get object for current Composition
|
|
56
56
|
* */
|
|
57
57
|
getActiveObject(id: Id) {
|
|
58
|
-
return this.#activeObjects.get(id)
|
|
58
|
+
return this.#activeObjects.get(id)?.sprite
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
async #renderLayer(
|
|
@@ -93,11 +93,11 @@ export class Compositor {
|
|
|
93
93
|
layer: Extract<Layer, {kind: 'text'}>,
|
|
94
94
|
parent: Container,
|
|
95
95
|
) {
|
|
96
|
-
const
|
|
96
|
+
const sprite = this.#findOrCreate<Text>(layer)!
|
|
97
97
|
this.#applyTransform(sprite, layer.matrix)
|
|
98
98
|
parent.addChild(sprite)
|
|
99
99
|
return {
|
|
100
|
-
dispose: () =>
|
|
100
|
+
dispose: () => {}
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -106,7 +106,7 @@ export class Compositor {
|
|
|
106
106
|
parent: Container,
|
|
107
107
|
) {
|
|
108
108
|
const texture = Texture.from(layer.frame)
|
|
109
|
-
const
|
|
109
|
+
const sprite = this.#findOrCreate<Sprite>(layer)!
|
|
110
110
|
sprite.texture = texture
|
|
111
111
|
this.#applyTransform(sprite, layer.matrix)
|
|
112
112
|
parent.addChild(sprite)
|
|
@@ -114,7 +114,6 @@ export class Compositor {
|
|
|
114
114
|
dispose: () => {
|
|
115
115
|
texture.destroy(true)
|
|
116
116
|
layer.frame.close()
|
|
117
|
-
dispose()
|
|
118
117
|
}
|
|
119
118
|
}
|
|
120
119
|
}
|
|
@@ -154,44 +153,41 @@ export class Compositor {
|
|
|
154
153
|
text.eventMode = "static"
|
|
155
154
|
const down = () => this.onPointerDown.publish({id: layer.id, object: text})
|
|
156
155
|
const up = () => this.onPointerUp.publish({id: layer.id, object: text})
|
|
156
|
+
|
|
157
157
|
text.on("pointerdown", down)
|
|
158
158
|
text.on("pointerup", up)
|
|
159
159
|
|
|
160
|
-
return
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
160
|
+
return this.#activeObjects
|
|
161
|
+
.set(layer.id, {
|
|
162
|
+
sprite: text,
|
|
163
|
+
dispose() {
|
|
164
|
+
text.off("pointerdown", down)
|
|
165
|
+
text.off("pointerup", up)
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
.get(layer.id)?.sprite as T
|
|
169
169
|
}
|
|
170
170
|
case 'image': {
|
|
171
171
|
const sprite = new Sprite()
|
|
172
172
|
sprite.eventMode = "static"
|
|
173
173
|
const down = () => this.onPointerDown.publish({id: layer.id, object: sprite})
|
|
174
174
|
const up = () => this.onPointerUp.publish({id: layer.id, object: sprite})
|
|
175
|
+
|
|
175
176
|
sprite.on("pointerdown", down)
|
|
176
177
|
sprite.on("pointerup", up)
|
|
177
178
|
|
|
178
|
-
return
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
179
|
+
return this.#activeObjects
|
|
180
|
+
.set(layer.id, {
|
|
181
|
+
sprite,
|
|
182
|
+
dispose() {
|
|
183
|
+
sprite.off("pointerdown", down)
|
|
184
|
+
sprite.off("pointerup", up)
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
.get(layer.id)?.sprite as T
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
|
-
} else return
|
|
190
|
-
sprite: object,
|
|
191
|
-
dispose: () => {}} as {
|
|
192
|
-
sprite: T
|
|
193
|
-
dispose: () => void
|
|
194
|
-
}
|
|
190
|
+
} else return object.sprite as T
|
|
195
191
|
}
|
|
196
192
|
|
|
197
193
|
#collectIds(layers: Layer | Composition): Set<number> {
|
|
@@ -210,10 +206,12 @@ export class Compositor {
|
|
|
210
206
|
#cleanup(activeIds: Set<number>) {
|
|
211
207
|
for (const id of this.#activeObjects.keys()) {
|
|
212
208
|
if (!activeIds.has(id)) {
|
|
213
|
-
const
|
|
214
|
-
|
|
209
|
+
const {sprite, dispose} = this.#activeObjects.get(id)!
|
|
210
|
+
sprite.destroy(true)
|
|
211
|
+
dispose()
|
|
215
212
|
this.#activeObjects.delete(id)
|
|
216
213
|
}
|
|
217
214
|
}
|
|
218
215
|
}
|
|
219
216
|
}
|
|
217
|
+
|
|
@@ -2412,7 +2412,7 @@ vec4 transition(vec2 uv) {
|
|
|
2412
2412
|
vec2 uv = vTextureCoord.xy;
|
|
2413
2413
|
gl_FragColor = transition(vTextureCoord);
|
|
2414
2414
|
}
|
|
2415
|
-
`;function _a({name:r,renderer:e}){let t=Aa.default.find(c=>c.name===r),n=new gt,o=new $t,i=new Ir({}),s=new Ir({}),a=new go({glProgram:new po({vertex:Ca,fragment:Ia(t.glsl)}),resources:{from:i,to:s,uniforms:{...wi.basics,...wi.custom(t)}}});return n.filters=[a],{render({width:c,height:l,from:d,to:u,progress:f}){return(n.width!==c||n.height!==l)&&(n.setSize({width:c,height:l}),o.source.resize(c,l)),i.resource=d,s.resource=u,i.update(),s.update(),a.resources.uniforms.uniforms.progress=f,e.render({container:n,target:o,clear:!1,width:c,height:l}),o}}}var jn=class{pixi;onPointerDown=ve();onPointerUp=ve();static async setup(){let e=await Ti({width:1920,height:1080,preference:"webgl",background:"black",preferWebGLVersion:2}),t=new mo;return t.interactive=!0,new this({renderer:e,stage:t})}constructor(e){this.pixi=e}#e=new Map;#t=new Map;async composite(e){let{stage:t,renderer:n}=this.pixi;this.#l(this.#c(e));let{dispose:o}=await this.#r(e,t);n.render(t);let i=new VideoFrame(n.canvas,{timestamp:0,duration:0});return o(),i}getActiveObject(e){return this.#t.get(e)}async#r(e,t){if(Array.isArray(e)){e.reverse();let n=[];for(let o of e){let i=await this.#r(o,t);n.push(i.dispose)}return{dispose:()=>n.forEach(o=>o())}}switch(e.kind){case"text":return this.#n(e,t);case"image":return this.#i(e,t);case"transition":return this.#s(e,t);case"gap":return this.pixi?.renderer.clear(),{dispose:()=>{}};default:return console.warn("Unknown layer kind",e.kind),{dispose:()=>{}}}}#n(e,t){let{sprite:n,dispose:o}=this.#a(e);return this.#o(n,e.matrix),t.addChild(n),{dispose:()=>o()}}#i(e,t){let n=$t.from(e.frame),{sprite:o,dispose:i}=this.#a(e);return o.texture=n,this.#o(o,e.matrix),t.addChild(o),{dispose:()=>{n.destroy(!0),e.frame.close(),i()}}}#s({from:e,to:t,progress:n,name:o},i){let a=(this.#e.get(o)??(this.#e.set(o,_a({name:"circle",renderer:this.pixi.renderer})),this.#e.get(o))).render({from:e,to:t,progress:n,width:e.displayWidth,height:e.displayHeight}),c=new gt(a);return i.addChild(c),{dispose:()=>c.destroy(!1)}}#o(e,t){if(!t)return;let n=wa(t);e.setFromMatrix(n)}#a(e){let t=this.#t.get(e.id);if(t)return{sprite:t,dispose:()=>{}};switch(e.kind){case"text":{let n=new vr({text:e.content,style:e.style});n.eventMode="static";let o=()=>this.onPointerDown.publish({id:e.id,object:n}),i=()=>this.onPointerUp.publish({id:e.id,object:n});return n.on("pointerdown",o),n.on("pointerup",i),{sprite:this.#t.set(e.id,n).get(e.id),dispose:()=>{n.off("pointerdown",o),n.off("pointerup",i)}}}case"image":{let n=new gt;n.eventMode="static";let o=()=>this.onPointerDown.publish({id:e.id,object:n}),i=()=>this.onPointerUp.publish({id:e.id,object:n});return n.on("pointerdown",o),n.on("pointerup",i),{sprite:this.#t.set(e.id,n).get(e.id),dispose:()=>{n.off("pointerdown",o),n.off("pointerup",i)}}}}}#c(e){let t=new Set,n=o=>{if(Array.isArray(o))for(let i of o)n(i);else t.add(o.id)};return n(e),t}#l(e){for(let t of this.#t.keys())e.has(t)||(this.#t.get(t).destroy(!0),this.#t.delete(t))}};var Ea=r=>jr.host(e=>({async world(){r.count++}}));async function ce(r){return r instanceof Blob?new kr(r):new Sr(r)}var $n=class{machina;thread;compositor;static async setup(e){let t=new Hn,n=await jr.thread({label:"OmnitoolDriver",workerUrl:e?.workerUrl??"/node_modules/@omnimedia/omnitool/x/driver/driver.worker.bundle.min.js",setupHost:Ea(t)}),o=await jn.setup();return new this(t,n,o)}constructor(e,t,n){this.machina=e,this.thread=t,this.compositor=n}async hello(){return this.thread.work.hello()}async getAudioDuration(e){let n=await new ee({source:await ce(e),formats:ie}).getPrimaryAudioTrack();if(!n)throw new Error("primary audio track not found");return await n.computeDuration()}async getVideoDuration(e){return await(await new ee({source:await ce(e),formats:ie}).getPrimaryVideoTrack())?.computeDuration()}decodeVideo(e){let t=null,{port1:n,port2:o}=new MessageChannel,i=new TransformStream({async transform(s,a){let c=await e.onFrame?.(s)??s;t?.close(),a.enqueue(c),t=c}});return this.thread.work.decodeVideo[yt]({transfer:[i.writable,o]})({source:e.source,cancel:o,video:i.writable,start:e.start,end:e.end}),{readable:i.readable,cancel(){n.postMessage("close"),n.close()}}}decodeAudio(e){let t=new TransformStream,{port1:n,port2:o}=new MessageChannel;return this.thread.work.decodeAudio[yt]({transfer:[t.writable,o]})({source:e.source,cancel:o,audio:t.writable,start:e.start,end:e.end}),{readable:t.readable,cancel(){n.postMessage("close"),n.close()}}}encode({audio:e,video:t,config:n}){let{readable:o,writable:i}=new TransformStream,s=[e,t,i].filter(Er.happy),a=this.thread.work.encode[yt]({transfer:s})({audio:e,video:t,config:n,writable:i});return{readable:o,done:a}}async composite(e){return await this.compositor.composite(e)}};var M;(function(r){r[r.Sequence=0]="Sequence",r[r.Stack=1]="Stack",r[r.Video=2]="Video",r[r.Audio=3]="Audio",r[r.Text=4]="Text",r[r.Gap=5]="Gap",r[r.Spatial=6]="Spatial",r[r.Transition=7]="Transition",r[r.TextStyle=8]="TextStyle"})(M||(M={}));var Kn;(function(r){r[r.Crossfade=0]="Crossfade"})(Kn||(Kn={}));var Xn=class{datafile;duration=0;hasVideo=!1;hasAudio=!1;constructor(e){this.datafile=e}static async analyze(e){let t=new this(e),n=await this.duration(e.url)*1e3;t.duration=n;let{video:o,audio:i}=await this.#e(e.url);return t.hasAudio=i,t.hasVideo=o,t}static async duration(e){let n=await new ee({formats:ie,source:await ce(e)}).computeDuration();return Number(n.toFixed(5))}static async#e(e){let t=new ee({formats:ie,source:await ce(e)});return{audio:!!await t.getPrimaryAudioTrack(),video:!!await t.getPrimaryVideoTrack()}}};var Qn=class{#e=new Fr;async store(e){let t=await Xn.analyze(e),{hash:n}=t.datafile.checksum,{filename:o,bytes:i,url:s,blob:a}=t.datafile;if(this.#e.has(n)){let c=this.#e.require(n);c.filename=o}else this.#e.set(n,{kind:"media",filename:o,bytes:i,url:s,blob:a,duration:t.duration});return t}require(e){return this.#e.require(e)}};var Yn=class r{videoTrack;options;#e;#t=new Map;#r=[0,0];constructor(e,t){this.videoTrack=e,this.options=t,this.#e=new fr(e,t.canvasSinkOptions)}static async init(e,t){let o=await new ee({formats:ie,source:await ce(e)}).getPrimaryVideoTrack();if(o)return new r(o,{frequency:t.frequency??1,canvasSinkOptions:t.canvasSinkOptions??{width:80,height:50,fit:"fill"},onChange:t.onChange,onPlaceholders:t.onPlaceholders});throw new Error("Source has no video track")}set frequency(e){e!==this.options.frequency&&(this.options.frequency=e,this.#c())}get frequency(){return this.options.frequency}#n([e,t],n=1){let o=t-e;return[e-o*n,t+o*n]}async#i(){let[e,t]=this.#r,n=new Set,o=await this.videoTrack.computeDuration();for(let i=Math.max(0,e);i<=t;i+=this.options.frequency)i>=0&&i<=o&&n.add(i);this.options.onPlaceholders?.([...n])}async#s(){let[e,t]=this.#r,n=new Set,o=await this.videoTrack.computeDuration();for(let c=Math.max(0,e);c<=t;c+=this.options.frequency)c>=0&&c<=o&&n.add(c);let i=[...n].filter(c=>!this.#t.has(c)),s=0;for await(let c of this.#e.canvasesAtTimestamps(i))if(c){let l=i[s++];this.#t.set(l,c)}for(let c of this.#t.keys())n.has(c)||this.#t.delete(c);let a=[...this.#t.entries()].map(([c,l])=>({time:c,canvas:l}));this.options.onChange(a)}set range(e){let[t,n]=e,o=n-t,[i,s]=this.#r,a=i+o,c=s-o,l=t<a,d=n>c;!l&&!d||(this.#r=this.#n(e,2),this.#c())}#o=null;#a=!1;async#c(){if(this.#i(),this.#o){this.#a=!0;return}this.#o=this.#s(),await this.#o,this.#o=null,this.#a&&(this.#a=!1,await this.#c())}getThumbnail(e){return this.#t.get(e)}};function Fa(r,e){let t=typeof window<"u"&&window.devicePixelRatio||1,n=document.createElement("canvas");n.width=e.width*t,n.height=e.height*t,n.style.width=`${e.width}px`,n.style.height=`${e.height}px`;let o=n.getContext("2d");if(!o)return n;o.scale(t,t),o.fillStyle=e.color;let i=e.height/2,s=Math.max(1,e.width),a=r.length/s;for(let c=0;c<s;c++){let l=Math.floor(c*a),d=Math.max(l+1,Math.floor((c+1)*a)),u=0;for(let m=l;m<d&&m<r.length;m++)r[m]>u&&(u=r[m]);let f=u*e.height;o.fillRect(c,i-f/2,1,f)}return n}var ki=[2048,1024,512,256,128,64,32];async function Da(r,e){let t=await r.getAudioDuration(e)??0,n=r.decodeAudio({source:e}).readable,o=ki[ki.length-1],i=[],s=0,a=0,c=0;for await(let u of n){c||=u.sampleRate;let f=u.numberOfFrames,m=new Float32Array(f);u.copyTo(m,{planeIndex:0});for(let p=0;p<m.length;p++){let g=Math.abs(m[p]);g>s&&(s=g),a++,a>=o&&(i.push(s),s=0,a=0)}u.close()}a>0&&i.push(s);let l=new Float32Array(i),d=ki.map(u=>{let f=Math.max(1,Math.round(u/o)),m=f===1?l:Kc(l,f);return{samplesPerPeak:u,peaks:m,peaksPerSecond:c>0?c/u:0}});return{duration:t,levels:d}}function Kc(r,e){let t=new Float32Array(Math.ceil(r.length/e));for(let n=0;n<t.length;n++){let o=0,i=n*e,s=Math.min(i+e,r.length);for(let a=i;a<s;a++)r[a]>o&&(o=r[a]);t[n]=o}return t}var Xc=4096,Zn=class r{#e=new Map;#t=[0,0];#r=[0,0];#n;#i;#s;#o=!1;color;duration;tileSize;tileHeight;preloadMargin;constructor(e,t,n){this.#i=e,this.duration=t,this.tileSize=n.tileSize??1,this.#n=n.zoom??(n.tileWidth??256)/this.tileSize,this.tileHeight=n.tileHeight??96,this.preloadMargin=n.preloadMargin??2,this.color=n.color??"rgb(3, 148, 129)",this.#s=n.onChange}static async init(e,t,n={}){let{duration:o,levels:i}=await Da(e,t);return new r(i,o,n)}set zoom(e){let t=Math.max(1,e);t!==this.#n&&(this.#n=t,this.#e.clear(),this.#c())}get zoom(){return this.#n}get range(){return this.#r}#a([e,t],n=1){let o=t-e;return[Math.max(0,e-o*n),Math.min(this.duration,t+o*n)]}set range(e){this.#r=e;let[t,n]=e,o=n-t,[i,s]=this.#t,a=i>0,c=s<this.duration,l=!a||t>=i+o,d=!c||n<=s-o;l&&d||(this.#t=this.#a(e,this.preloadMargin),this.#c())}#c(){this.#o||(this.#o=!0,queueMicrotask(()=>{this.#o=!1,this.#l()}))}#l(){let[e,t]=this.#t,n=new Set,o=this.#d(),i=Math.max(0,Math.floor(e/this.tileSize)*this.tileSize),s=Math.min(this.duration,t);for(let a=i;a<=s;a+=this.tileSize)n.add(a);for(let a of n)if(!this.#e.has(a)){let c=Math.min(a+this.tileSize,this.duration);this.#e.set(a,this.#u(a,c,o))}for(let a of this.#e.keys())n.has(a)||this.#e.delete(a);this.#p()}#u(e,t,n){let o=this.#f(n,e,t);return{startTime:e,endTime:t,peaks:o,canvas:Fa(o,{width:this.#m(e,t),height:this.tileHeight,color:this.color})}}#d(){return this.#i.find(e=>e.peaksPerSecond>=this.#n)??this.#i[this.#i.length-1]}#f(e,t,n){if(!e.peaksPerSecond)return new Float32Array;let o=Math.max(0,Math.floor(t*e.peaksPerSecond)),i=Math.max(o+1,Math.min(e.peaks.length,Math.ceil(n*e.peaksPerSecond)));return e.peaks.slice(o,i)}#m(e,t){return Math.min(Xc,Math.max(1,Math.ceil((t-e)*this.#n)))}#p(){this.#s&&this.#s([...this.#e.values()].sort((e,t)=>e.startTime-t.startTime))}getTiles(){return this.#e}};var U=r=>r;var qt=r=>r;var Ra=()=>{let r=!1,e=qt(60),t=1e3/e,n=0,o=0,i=ve(),s=null,a=l=>{if(requestAnimationFrame(a),!!r)for(n=l;l-o>=t;)o+=t,s?.(),s=null,i()};async function*c(){for(n=performance.now(),o=n,requestAnimationFrame(a);;)await new Promise(l=>s=l),yield}return{play(){r||(r=!0,n=performance.now(),o=n)},pause(){r=!1},setFPS(l){e=l,t=1e3/e},isPlaying(){return r},ticks:c,onTick:i}},Ma=async(r,e)=>{let t=U(1e3/r.fps),n=r.duration/1e3,o=Math.ceil(n*r.fps);for(let i=0;i<o;i++){let s=U(i*t);await e(s,i)}};function Oa(r){return"duration"in r}function za(r){let e=[],t=new Map(r.timeline.items.map(n=>[n.id,n]));return Si(r.timeline.rootId,t,r.from,{sequence:()=>{},stack:()=>{},video:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),text:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),audio:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i})}),e}function Ua(r,e,t){let n=Sa;for(let o of e)n=Ba(r,o,n);return Ba(r,t,n)}function Ba(r,e,t){if("spatialId"in e&&e.spatialId){let n=r.get(e.spatialId);if(n?.enabled){let o=Ta(n.transform);return ka(o,t)}}return t}function Si(r,e,t,n,o=[]){let i=e.get(r);if(i)switch(i.kind){case M.Stack:n.stack(i,t,o);for(let s of i.childrenIds)Si(s,e,t,n,[...o,i]);break;case M.Sequence:{n.sequence(i,t,o);let s=U(0);for(let a of i.childrenIds){let c=e.get(a);if(!c||!Oa(c))continue;let l=U(s+c.duration);if(t>=l){s=l;continue}let d=U(Math.max(0,t-s));Si(a,e,d,n,[...o,i]),s=l}break}case M.Video:n.video(i,t,o);break;case M.Text:n.text(i,t,o);break;case M.Audio:n.audio(i,t,o);break}}function pe(r,e){let t=e.items.find(n=>n.id===r);if(!t)return U(0);switch(t.kind){case M.Sequence:{let n=t.childrenIds.map(i=>e.items.find(s=>s.id===i)).filter(Boolean),o=U(0);for(let i=0;i<n.length;i++){let s=n[i];if(s.kind===M.Transition){let a=n[i-1],c=n[i+1];if(a&&c&&a.kind!==M.Transition&&c.kind!==M.Transition){let l=pe(a.id,e),d=pe(c.id,e),u=Math.max(0,Math.min(s.duration,l,d));o=U(o-u)}continue}o=U(o+pe(s.id,e))}return o}case M.Stack:{let n=U(0);for(let o of t.childrenIds){let i=pe(o,e);i>n&&(n=i)}return n}default:return Oa(t)?t.duration:U(0)}}var Pr=r=>r;var Jn=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let n=new ee({formats:ie,source:await ce(this.resolveMedia(e))}),o=await n.getPrimaryVideoTrack(),s=!!o&&await o.canDecode()&&o?new Ct(o):null;return this.#e.set(e,{input:n,sink:s}),s}};async function Na(r,e,t,n){let[o,i]=await Promise.all([t,n]),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:r.id,kind:"transition",name:"circle",progress:e,from:s,to:a},...c]:c}async function Va(r,e,t,n){let o=Qc(r,e,t);if(!o)return[];let i=[...n,e];return o.isTransitioning?Na(o.transition,o.progress,mt(r,o.outgoing,o.outgoingTime,i),mt(r,o.incoming,o.incomingTime,i)):mt(r,o.item,o.localTime,i)}function Qc(r,e,t){let n=e.childrenIds.map(i=>r.items.get(i)).filter(i=>!!i),o=U(0);for(let i=0;i<n.length;i++){let s=n[i];if(s.kind===M.Transition)continue;let a=o,c=pe(s.id,r.timeline),l=U(a+c),d=n[i+1];if(!(d?.kind===M.Transition)){if(t<l)return{isTransitioning:!1,item:s,localTime:U(t-a)};o=l;continue}let f=d,m=n[i+2];if(!m||m.kind===M.Transition){o=l;continue}let p=pe(m.id,r.timeline),g=Math.max(0,Math.min(f.duration,c,p)),x=U(l-g);if(t<x)return{isTransitioning:!1,item:s,localTime:U(t-a)};if(t<l){let y=U(t-x),b=U(t-a);return{isTransitioning:!0,incoming:m,outgoing:s,outgoingTime:b,incomingTime:y,progress:g>0?y/g:1,transition:f}}o=x,i++}return null}async function mt(r,e,t,n){let o=Ua(r.items,n,e);switch(e.kind){case M.Stack:{let i=[...n,e];return(await Promise.all(e.childrenIds.map(a=>r.items.get(a)).filter(a=>!!a).map(a=>mt(r,a,t,i)))).flat()}case M.Sequence:return Va(r,e,t,n);case M.Video:{if(t<0||t>=e.duration)return[];let i=await r.videoSampler(e,t);return i?[{kind:"image",frame:i,matrix:o,id:e.id}]:[]}case M.Text:{if(t<0||t>=e.duration)return[];let i=e.styleId?r.items.get(e.styleId)?.style:void 0;return[{id:e.id,kind:"text",content:e.content,style:i,matrix:o}]}case M.Gap:return[{id:e.id,kind:"gap"}];default:return[]}}function La(r){return async(e,t)=>{let o=await(await r.getSink(e.mediaHash))?.getSample(t/1e3),i=o?.toVideoFrame();return o?.close(),i??void 0}}function eo(r,e){let t=new Jn(r),n=e??La(t);return{async sample(o,i){let s=new Map(o.items.map(c=>[c.id,c])),a=s.get(o.rootId);return a?mt({videoSampler:n,timeline:o,items:s},a,i,[]):[]}}}var Gt=class{driver;resolveMedia;timeline;#e=-1/0;#t=new Map;#r;constructor(e,t,n){this.driver=e,this.resolveMedia=t,this.timeline=n,this.#r=eo(this.resolveMedia,(o,i)=>{let s=Ha(i),a=this.#t.get(o.id);if(!a){let c=this.resolveMedia(o.mediaHash),l=Ha(U(o.start+o.duration));a=this.#n(c,s,l),this.#t.set(o.id,a)}return a.next(s)})}next(e){if(e<this.#e)throw new Error(`Forward-only cursor regression: ${e}ms < ${this.#e}ms`);return this.#e=e,this.#r.sample(this.timeline,e)}async cancel(){await Promise.all([...this.#t.values()].map(e=>e.cancel())),this.#t.clear()}#n(e,t,n){let o=this.driver.decodeVideo({source:e,start:t/1e6,end:n/1e6}),i=o.readable.getReader(),s=null,a=null,c=!1,l=async()=>{if(c)return null;let{done:d,value:u}=await i.read();if(d)return c=!0,null;let f=new VideoFrame(u);return u.close(),f};return{async next(d){if(s??=await l(),!!s)for(;;){a??=l();let u=await a;if(!u)return new VideoFrame(s);let f=s.timestamp??-1/0,m=u.timestamp??f;if(m<d){s.close(),s=u,a=null;continue}if(Math.abs(m-d)<Math.abs(f-d)){s.close(),s=u,a=null;continue}return new VideoFrame(s)}},async cancel(){let d=a;a=null,c=!0,(await d?.catch(()=>null))?.close(),s?.close(),s=null,o.cancel()}}}},Ha=r=>Math.round(r*1e3);async function qa(r,e,t){return(await Promise.all(e.map(async({item:o,localTime:i})=>{if(o.kind!==M.Audio)return;let s=await r.getSink(o.mediaHash);if(!s)return;let a=o.start+i,c=Pr((t-a)/1e3),l=s.samples(a/1e3),d=await l.next();if(d.done)return;let u=d.value,f=l.next();return{offset:c,gain:o.gain??1,get currentSample(){return u},timelineTime:()=>Pr(c+u.timestamp),output:()=>({sample:u,timestamp:c+u.timestamp,gain:o.gain??1}),advance:async()=>{let m=await f;return m.done?!1:(u=m.value,f=l.next(),!0)}}}))).filter(o=>!!o)}var to=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let n=new ee({formats:ie,source:await ce(this.resolveMedia(e))}),o=await n.getPrimaryAudioTrack(),s=!!o&&await o.canDecode()&&o?new mr(o):null;return this.#e.set(e,{input:n,sink:s}),s}};function Ga(r){let e={index:0,stream:r[0],time:r[0].timelineTime()};for(let[t,n]of r.entries()){let o=n.timelineTime();o<e.time&&(e={time:o,stream:n,index:t})}return e}function ro(r){let e=new to(r);return{async*sampleAudio(t,n){let o=za({timeline:t,from:n}),i=await qa(e,o,n);for(;i.length>0;){let{stream:s,index:a}=Ga(i);yield s.output(),await s.advance()||i.splice(a,1)}}}}var no=class{driver;timeline;resolveMedia;audioSampler;seekVisualSampler;playVisualSampler=null;#e=U(0);#t=null;#r=Ra();onTick=this.#r.onTick;audioContext=new AudioContext({sampleRate:48e3});audioGain=this.audioContext.createGain();audioNodes=new Set;#n=null;constructor(e,t,n){this.driver=e,this.timeline=t,this.resolveMedia=n,this.audioGain.connect(this.audioContext.destination),this.audioGain.gain.value=.7**2,this.seekVisualSampler=eo(this.resolveMedia),this.audioSampler=ro(this.resolveMedia),this.#i()}update(e){this.timeline=e}get isPlaying(){return this.#r.isPlaying()}async#i(){for await(let e of this.#r.ticks()){let t=await this.playVisualSampler?.next(this.currentTime)??[];(await this.driver.composite(t)).close(),this.currentTime>=this.duration&&this.pause()}}async seek(e){return this.pause(),this.#e=e,await this.seekVisualSampler.sample(this.timeline,e)}async start(){if(!this.#r.isPlaying()){await this.audioContext.resume(),this.#e=this.currentTime,this.#t=this.audioContext.currentTime,this.#n?.abort(),this.#n=new AbortController;for(let e of this.audioNodes)e.stop();this.audioNodes.clear(),this.playVisualSampler=new Gt(this.driver,this.resolveMedia,this.timeline),this.#r.play(),this.#s(this.#n.signal,Pr(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(),this.playVisualSampler&&(this.playVisualSampler.cancel(),this.playVisualSampler=null)}get duration(){return pe(this.timeline.rootId,this.timeline)}get currentTime(){if(!this.#r.isPlaying()||this.#t===null)return this.#e;let e=(this.audioContext.currentTime-this.#t)*1e3;return U(this.#e+e)}setFps(e){this.#r.setFPS(e)}async#s(e,t){let n=this.audioContext;if(this.#t!==null)for await(let{sample:o,timestamp:i}of this.audioSampler.sampleAudio(this.timeline,U(t*1e3))){if(e.aborted||!this.#r.isPlaying())return;for(;i-(n.currentTime-this.#t+t)>.75;)await new Promise(c=>setTimeout(c,25));let s=n.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>=n.currentTime?s.start(a):s.start(n.currentTime,n.currentTime-a)}}};var oo=class{driver;canvas;playback;#e=null;#t=null;constructor(e,t,n){this.driver=e,this.playback=new no(e,n,t),this.canvas=e.compositor.pixi.renderer.canvas}async play(){await this.playback.start()}pause(){this.playback.pause()}seek(e){return this.#e=e,this.#t??=this.#r().finally(()=>this.#t=null)}setFPS(e){this.playback.setFps(qt(e))}get isSeeking(){return this.#t!==null}get isPlaying(){return this.playback.isPlaying}get duration(){return this.playback.duration}get currentTime(){return this.playback.currentTime}update(e){this.playback.update(e)}async#r(){for(;this.#e!==null;){let e=this.#e;this.#e=null;let t=await this.playback.seek(U(e));(await this.driver.composite(t)).close()}}};var pt=class{state;constructor(e){this.state=e}require(e){return e===void 0?void 0:this.state.timeline.items.find(n=>n.id===e)}get timeline(){return this.state.timeline}getId(){return he.toInteger(he.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:M.TextStyle,style:e};return this.register(t),t};spatial=e=>{let t={id:this.getId(),kind:M.Spatial,transform:e,enabled:!0};return this.register(t),t};sequence=(...e)=>{let t={id:this.getId(),kind:M.Sequence,childrenIds:e.map(n=>n.id)};return this.register(t),t};stack=(...e)=>{let t={kind:M.Stack,id:this.getId(),childrenIds:e.map(n=>n.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 n={kind:M.Video,id:this.getId(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration};return this.register(n),n};audio=(e,t)=>{if(!e.hasAudio)throw new Error(`Audio clip error: media "${e.datafile.filename}" has no audio track.`);let n={kind:M.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(n),n};text=(e,t)=>{let n={id:this.getId(),content:e,kind:M.Text,duration:t?.duration??2e3};return t?.styles&&(n.styleId=this.textStyle(t.styles).id),this.register(n),n};gap=e=>{let t={id:this.getId(),kind:M.Gap,duration:e};return this.register(t),t};transition={crossfade:e=>{let t={id:this.getId(),kind:M.Transition,effect:Kn.Crossfade,duration:e};return this.register(t),t}};transform=e=>{let t=[e?.position?.[0]??0,e?.position?.[1]??0],n=[e?.scale?.[0]??1,e?.scale?.[1]??1],o=e?.rotation??0;return[t,n,o]};addChildren(e,...t){this.#e(n=>(n.items.find(({id:i})=>i===e.id).childrenIds.push(...t.map(i=>i.id)),n))}set=(e,t)=>{this.#e(n=>({...n,items:n.items.map(o=>o.id===e?{...o,...t}:o)}))}};var io=class{#e;#t;constructor(e={}){this.#e=e.chunkFrames??1024,this.#t=e.clamp??!0}async*mix(e){let t=this.#e,n=null,o=null,i=[],s=0,a=0;for await(let c of e){if(o===null)o=c.planes.length,n=c.sampleRate;else{if(c.planes.length!==o)throw new Error("Channel count changed");if(c.sampleRate!==n)throw new Error("Sample rate changed")}let l=Math.round(c.timestamp*n),d=c.planes[0]?.length??0;for(;s+t<=l;)yield this.#r(i,s,o,n),s+=t;i.push({startFrame:l,endFrame:l+d,data:c.planes}),a=Math.max(a,l+d)}if(o!==null&&n!==null)for(;s<a;)yield this.#r(i,s,o,n),s+=t}#r(e,t,n,o){let i=this.#e,s=new Float32Array(n*i),a=t+i;for(let c=0;c<n;c++){let l=c*i,d=s.subarray(l,l+i);for(let u of e){let f=u.data[c];if(!f)continue;let m=Math.max(t,u.startFrame),p=Math.min(a,u.endFrame);if(m>=p)continue;let g=m-t,x=m-u.startFrame,y=p-m;for(let b=0;b<y;b++)d[g+b]+=f[x+b]}if(this.#t)for(let u=0;u<i;u++){let f=d[u];d[u]=f<-1?-1:f>1?1:f}}for(let c=e.length-1;c>=0;c--)e[c].endFrame<=a&&e.splice(c,1);return{planar:s,sampleRate:o,channels:n,frames:i,startFrame:t}}};var Yc=(r,e,t)=>{if(e===t)return r;let n=t/e,o=Math.max(1,Math.round(r.length*n)),i=new Float32Array(o);for(let s=0;s<o;s++){let a=s/n,c=Math.floor(a),l=Math.min(c+1,r.length-1),d=a-c;i[s]=r[c]*(1-d)+r[l]*d}return i},Wa=(r,e)=>{let t=r.numberOfChannels,n=new Array(t),o=0;for(let i=0;i<t;i++){let s=new Float32Array(r.numberOfFrames);r.copyTo(s,{planeIndex:i,format:"f32-planar"});let a=Yc(s,r.sampleRate,e);n[i]=a,o=a.length}return{data:n,frames:o}};var ja=(r,e)=>{if(e!==1)for(let t of r)for(let n=0;n<t.length;n++)t[n]*=e};function $a({timeline:r,resolveMedia:e}){let t=new io,n=Zc(r,e),o=new TransformStream,i=o.writable.getWriter();async function s(){for await(let a of t.mix(n)){let c=new AudioData({format:"f32-planar",sampleRate:a.sampleRate,numberOfFrames:a.frames,numberOfChannels:a.channels,timestamp:Math.round(a.startFrame/a.sampleRate*1e6),data:new Float32Array(a.planar)});await i.write(c)}await i.close()}return s(),o.readable}async function*Zc(r,e){let t=ro(e);for await(let{sample:n,timestamp:o,gain:i}of t.sampleAudio(r,U(0))){let{data:s}=Wa(n,48e3);ja(s,i),yield{planes:s,sampleRate:48e3,timestamp:o},n.close()}}function Ka({timeline:r,fps:e,driver:t,resolveMedia:n}){let o=new TransformStream,i=o.writable.getWriter(),s=new Gt(t,n,r),a=1/e,c=pe(r.rootId,r);async function l(){await Ma({fps:e,duration:c},async(d,u)=>{let f=await s.next(d),m=await t.composite(f),p=new VideoFrame(m,{timestamp:Math.round(u*a*1e6),duration:Math.round(a*1e6)});await i.write(p),m.close()}),await i.close()}return l(),o.readable}function Xa(r){let e=$a({...r}),t=Ka({...r});return r.driver.encode({video:t,audio:e,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}})}var so=class{driver;resources=new Qn;constructor(e){this.driver=e}load=async e=>Object.fromEntries(await Promise.all(Object.entries(e).map(async([t,n])=>[t,await this.resources.store(await n)])));timeline=e=>{let t=new pt({timeline:{format:"timeline",info:"https://omniclip.app/",version:0,items:[],rootId:0}}),n=e(t);return t.timeline.rootId=n.id,t.timeline};playback=async e=>new oo(this.driver,t=>this.resources.require(t).url,e);render=async(e,t=30)=>Xa({timeline:e,fps:qt(t),driver:this.driver,resolveMedia:n=>this.resources.require(n).url})};var ao=class{data;bytes;hash;nickname;constructor(e,t,n,o){this.data=e,this.bytes=t,this.hash=n,this.nickname=o}static async make(e){let t=new Uint8Array(e),n=new Uint8Array(await crypto.subtle.digest("SHA-256",t)),o=_r.fromBytes(n),i=Ri.sigil.fromBytes(n);return new this(e,n,o,i)}};var co=class{url;bytes;blob;filename;checksum;constructor(e,t,n,o,i){this.url=e,this.bytes=t,this.blob=n,this.filename=o,this.checksum=i}static async make(e,t){let n=await e.arrayBuffer(),o=new Uint8Array(n),i=await ao.make(o),s=t??i.nickname,a=URL.createObjectURL(e);return new this(a,o,e,s,i)}static async load(e){}};async function Ya(r,e,t){let n=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 pt({timeline:r}),d=await e.playback(r);c.replaceChildren(d.canvas),n.disabled=!1,o.disabled=!1,n.addEventListener("click",()=>d.play()),o.addEventListener("click",()=>d.pause()),i.max=String(Math.ceil(d.duration));let u=!1;d.playback.onTick.on(()=>m(d.currentTime,d.duration));let f=(p,g)=>{a.textContent=`${Qa(p)} / ${Qa(g)}`};i.addEventListener("input",async()=>{u=!0;let p=Math.max(0,Math.min(+i.value,d.duration));f(p,d.duration),await d.seek(p)}),i.addEventListener("change",async()=>{u=!1;let p=Math.max(0,Math.min(+i.value,d.duration));await d.seek(p)});let m=(p,g)=>{let x=Math.max(0,Math.min(p,g));u||(i.value=String(Math.round(x)));let y=g?x/g*100:0;s.style.left=`${y}%`,f(x,g)};d.update(l.timeline)}function Qa(r){let e=Math.max(0,r),t=Math.floor(e/1e3),n=Math.floor(t/60),o=t%60,i=Math.floor(e%1e3);return`${n}:${String(o).padStart(2,"0")}.${String(i).padStart(3,"0")}`}async function Ja(r,e,t){let n=t.querySelector(".waveform-canvas"),o=t.querySelector(".width");n.replaceChildren(),n.style.position="relative",n.style.height="96px",n.style.overflow="hidden";let i=await Zn.init(r,e,{tileHeight:96,onChange:()=>s()}),s=()=>{let a=+o.value,c=Za(a,i.duration);i.zoom=c,n.style.width=`${a}px`,n.replaceChildren(...[...i.getTiles().values()].map(l=>(l.canvas.style.position="absolute",l.canvas.style.top="0",l.canvas.style.left=`${l.startTime*Za(a,i.duration)}px`,l.canvas.style.height="100%",l.canvas)))};o.oninput=s,i.range=[0,i.duration]}function Za(r,e){return e>0?r/e:0}async function vi(r,e){let t=new so(r),{videoA:n}=await t.load({videoA:co.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(n,{duration:3e3,start:1e3}),i.audio(n,{duration:1e3})),i.gap(500),i.video(n,{duration:7e3,start:5e3}))}),omni:t}}async function ec(r,e){let t=e.querySelector(".range"),n=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 d=await Yn.init(r,{onChange(u){let f=u.sort((m,p)=>m.time-p.time);a.replaceChildren(...f.map(({time:m,canvas:p})=>Jc(m,p.canvas)))},frequency:c,canvasSinkOptions:{width:80,height:50,fit:"fill"}});o.oninput=()=>{l=+o.value;let u=+t.value,f=u+l;d.range=[u,f],n.textContent=`visible time range: [${u}, ${f}]`},t.oninput=()=>{let u=+t.value,f=u+l;d.range=[u,f],n.textContent=`visible time range: [${u}, ${f}]`},i.oninput=()=>{d.frequency=1/+i.value,s.textContent=`frame every ${d.frequency.toFixed(3)} second (${i.value} frames per second)`},d.range=[10,10.5]}function Jc(r,e){let t=document.createElement("div");t.style.position="relative",t.style.display="inline-block",t.style.marginRight="4px",t.appendChild(e);let n=document.createElement("div");return n.textContent=`${r.toFixed(2)}s`,n.style.position="absolute",n.style.top="2px",n.style.right="4px",n.style.fontSize="10px",n.style.color="white",n.style.background="rgba(0,0,0,0.6)",n.style.padding="2px 4px",n.style.borderRadius="4px",n.style.pointerEvents="none",t.appendChild(n),t}function tc(r,e){let t={width:1920,height:1080},n=document.createElement("canvas");n.width=t.width,n.height=t.height;let o=n.getContext("2d");async function i(){let s=r.decodeVideo({source:e,async onFrame(f){let m=await r.composite([{id:0,kind:"image",frame:f},{id:1,kind:"text",content:"omnitool",style:{fontSize:50,fill:"green"}}]);return f.close(),o?.drawImage(m,0,0),m}}),a=r.decodeAudio({source:e}),{readable:c,done:l}=r.encode({video:s.readable,audio:a.readable,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}}),u=await(await window.showSaveFilePicker()).createWritable();await Promise.all([c.pipeTo(u),l])}return{canvas:n,run:i}}var Wt=await $n.setup({workerUrl:new URL("../driver/driver.worker.bundle.min.js",import.meta.url)}),el=document.querySelector("[data-demo='transcode']"),tl=document.querySelector("[data-demo='filmstrip']"),rl=document.querySelector("[data-demo='waveform']"),rc=document.querySelector("[data-demo='playback']"),ht=document.querySelector("[data-demo='export']"),nc=ht.querySelector("[data-action='export']"),lo=null;await Wt.thread.work.hello(),Wt.machina.count===1?console.log("\u2705 driver works"):console.error("\u274C FAIL driver call didn't work");var jt=(r,e)=>{let t=r.querySelector(".progress"),n=r.querySelector(".status");!t||!n||(e==="running"?(t.removeAttribute("value"),n.textContent="running"):e==="done"?(t.value=1,n.textContent="done"):(t.value=0,n.textContent="idle"))},Pi=(r,e)=>{let t=r.querySelector("input[type='file']"),n=r.querySelector("[data-action='run']");n.disabled=!0,t.addEventListener("input",()=>{n.disabled=!t.files?.length}),n.addEventListener("click",async()=>{let o=t.files?.[0];if(o){n.disabled=!0,jt(r,"running");try{await e(o,r),jt(r,"done")}finally{n.disabled=!1}}})};Pi(el,async(r,e)=>{let t=e.querySelector(".demo-preview"),n=tc(Wt,r);t.replaceChildren(n.canvas),await n.run()});Pi(tl,async(r,e)=>{await ec(r,e)});Pi(rl,async(r,e)=>{await Ja(Wt,r,e)});{let r=rc.querySelector("input[type='file']");r.addEventListener("input",async()=>{let e=r.files?.[0];if(!e)return;let{timeline:t,omni:n}=await vi(Wt,e);await Ya(t,n,rc)})}{let r=ht.querySelector("input[type='file']");r.addEventListener("input",async()=>{let e=r.files?.[0];if(!e)return;jt(ht,"running");let{timeline:t,omni:n}=await vi(Wt,e);lo={timeline:t,omni:n},nc.disabled=!1;let o=ht.querySelector(".demo-preview"),i=await n.playback(t);await i.seek(0),o.replaceChildren(i.canvas),jt(ht,"done")})}nc.addEventListener("click",async()=>{lo&&(jt(ht,"running"),await lo.omni.render(lo.timeline),jt(ht,"done"))});
|
|
2415
|
+
`;function _a({name:r,renderer:e}){let t=Aa.default.find(c=>c.name===r),n=new gt,o=new $t,i=new Ir({}),s=new Ir({}),a=new go({glProgram:new po({vertex:Ca,fragment:Ia(t.glsl)}),resources:{from:i,to:s,uniforms:{...wi.basics,...wi.custom(t)}}});return n.filters=[a],{render({width:c,height:l,from:d,to:u,progress:f}){return(n.width!==c||n.height!==l)&&(n.setSize({width:c,height:l}),o.source.resize(c,l)),i.resource=d,s.resource=u,i.update(),s.update(),a.resources.uniforms.uniforms.progress=f,e.render({container:n,target:o,clear:!1,width:c,height:l}),o}}}var jn=class{pixi;onPointerDown=ve();onPointerUp=ve();static async setup(){let e=await Ti({width:1920,height:1080,preference:"webgl",background:"black",preferWebGLVersion:2}),t=new mo;return t.interactive=!0,new this({renderer:e,stage:t})}constructor(e){this.pixi=e}#e=new Map;#t=new Map;async composite(e){let{stage:t,renderer:n}=this.pixi;this.#l(this.#c(e));let{dispose:o}=await this.#r(e,t);n.render(t);let i=new VideoFrame(n.canvas,{timestamp:0,duration:0});return o(),i}getActiveObject(e){return this.#t.get(e)?.sprite}async#r(e,t){if(Array.isArray(e)){e.reverse();let n=[];for(let o of e){let i=await this.#r(o,t);n.push(i.dispose)}return{dispose:()=>n.forEach(o=>o())}}switch(e.kind){case"text":return this.#n(e,t);case"image":return this.#i(e,t);case"transition":return this.#s(e,t);case"gap":return this.pixi?.renderer.clear(),{dispose:()=>{}};default:return console.warn("Unknown layer kind",e.kind),{dispose:()=>{}}}}#n(e,t){let n=this.#a(e);return this.#o(n,e.matrix),t.addChild(n),{dispose:()=>{}}}#i(e,t){let n=$t.from(e.frame),o=this.#a(e);return o.texture=n,this.#o(o,e.matrix),t.addChild(o),{dispose:()=>{n.destroy(!0),e.frame.close()}}}#s({from:e,to:t,progress:n,name:o},i){let a=(this.#e.get(o)??(this.#e.set(o,_a({name:"circle",renderer:this.pixi.renderer})),this.#e.get(o))).render({from:e,to:t,progress:n,width:e.displayWidth,height:e.displayHeight}),c=new gt(a);return i.addChild(c),{dispose:()=>c.destroy(!1)}}#o(e,t){if(!t)return;let n=wa(t);e.setFromMatrix(n)}#a(e){let t=this.#t.get(e.id);if(t)return t.sprite;switch(e.kind){case"text":{let n=new vr({text:e.content,style:e.style});n.eventMode="static";let o=()=>this.onPointerDown.publish({id:e.id,object:n}),i=()=>this.onPointerUp.publish({id:e.id,object:n});return n.on("pointerdown",o),n.on("pointerup",i),this.#t.set(e.id,{sprite:n,dispose(){n.off("pointerdown",o),n.off("pointerup",i)}}).get(e.id)?.sprite}case"image":{let n=new gt;n.eventMode="static";let o=()=>this.onPointerDown.publish({id:e.id,object:n}),i=()=>this.onPointerUp.publish({id:e.id,object:n});return n.on("pointerdown",o),n.on("pointerup",i),this.#t.set(e.id,{sprite:n,dispose(){n.off("pointerdown",o),n.off("pointerup",i)}}).get(e.id)?.sprite}}}#c(e){let t=new Set,n=o=>{if(Array.isArray(o))for(let i of o)n(i);else t.add(o.id)};return n(e),t}#l(e){for(let t of this.#t.keys())if(!e.has(t)){let{sprite:n,dispose:o}=this.#t.get(t);n.destroy(!0),o(),this.#t.delete(t)}}};var Ea=r=>jr.host(e=>({async world(){r.count++}}));async function ce(r){return r instanceof Blob?new kr(r):new Sr(r)}var $n=class{machina;thread;compositor;static async setup(e){let t=new Hn,n=await jr.thread({label:"OmnitoolDriver",workerUrl:e?.workerUrl??"/node_modules/@omnimedia/omnitool/x/driver/driver.worker.bundle.min.js",setupHost:Ea(t)}),o=await jn.setup();return new this(t,n,o)}constructor(e,t,n){this.machina=e,this.thread=t,this.compositor=n}async hello(){return this.thread.work.hello()}async getAudioDuration(e){let n=await new ee({source:await ce(e),formats:ie}).getPrimaryAudioTrack();if(!n)throw new Error("primary audio track not found");return await n.computeDuration()}async getVideoDuration(e){return await(await new ee({source:await ce(e),formats:ie}).getPrimaryVideoTrack())?.computeDuration()}decodeVideo(e){let t=null,{port1:n,port2:o}=new MessageChannel,i=new TransformStream({async transform(s,a){let c=await e.onFrame?.(s)??s;t?.close(),a.enqueue(c),t=c}});return this.thread.work.decodeVideo[yt]({transfer:[i.writable,o]})({source:e.source,cancel:o,video:i.writable,start:e.start,end:e.end}),{readable:i.readable,cancel(){n.postMessage("close"),n.close()}}}decodeAudio(e){let t=new TransformStream,{port1:n,port2:o}=new MessageChannel;return this.thread.work.decodeAudio[yt]({transfer:[t.writable,o]})({source:e.source,cancel:o,audio:t.writable,start:e.start,end:e.end}),{readable:t.readable,cancel(){n.postMessage("close"),n.close()}}}encode({audio:e,video:t,config:n}){let{readable:o,writable:i}=new TransformStream,s=[e,t,i].filter(Er.happy),a=this.thread.work.encode[yt]({transfer:s})({audio:e,video:t,config:n,writable:i});return{readable:o,done:a}}async composite(e){return await this.compositor.composite(e)}};var M;(function(r){r[r.Sequence=0]="Sequence",r[r.Stack=1]="Stack",r[r.Video=2]="Video",r[r.Audio=3]="Audio",r[r.Text=4]="Text",r[r.Gap=5]="Gap",r[r.Spatial=6]="Spatial",r[r.Transition=7]="Transition",r[r.TextStyle=8]="TextStyle"})(M||(M={}));var Kn;(function(r){r[r.Crossfade=0]="Crossfade"})(Kn||(Kn={}));var Xn=class{datafile;duration=0;hasVideo=!1;hasAudio=!1;constructor(e){this.datafile=e}static async analyze(e){let t=new this(e),n=await this.duration(e.url)*1e3;t.duration=n;let{video:o,audio:i}=await this.#e(e.url);return t.hasAudio=i,t.hasVideo=o,t}static async duration(e){let n=await new ee({formats:ie,source:await ce(e)}).computeDuration();return Number(n.toFixed(5))}static async#e(e){let t=new ee({formats:ie,source:await ce(e)});return{audio:!!await t.getPrimaryAudioTrack(),video:!!await t.getPrimaryVideoTrack()}}};var Qn=class{#e=new Fr;async store(e){let t=await Xn.analyze(e),{hash:n}=t.datafile.checksum,{filename:o,bytes:i,url:s,blob:a}=t.datafile;if(this.#e.has(n)){let c=this.#e.require(n);c.filename=o}else this.#e.set(n,{kind:"media",filename:o,bytes:i,url:s,blob:a,duration:t.duration});return t}require(e){return this.#e.require(e)}};var Yn=class r{videoTrack;options;#e;#t=new Map;#r=[0,0];constructor(e,t){this.videoTrack=e,this.options=t,this.#e=new fr(e,t.canvasSinkOptions)}static async init(e,t){let o=await new ee({formats:ie,source:await ce(e)}).getPrimaryVideoTrack();if(o)return new r(o,{frequency:t.frequency??1,canvasSinkOptions:t.canvasSinkOptions??{width:80,height:50,fit:"fill"},onChange:t.onChange,onPlaceholders:t.onPlaceholders});throw new Error("Source has no video track")}set frequency(e){e!==this.options.frequency&&(this.options.frequency=e,this.#c())}get frequency(){return this.options.frequency}#n([e,t],n=1){let o=t-e;return[e-o*n,t+o*n]}async#i(){let[e,t]=this.#r,n=new Set,o=await this.videoTrack.computeDuration();for(let i=Math.max(0,e);i<=t;i+=this.options.frequency)i>=0&&i<=o&&n.add(i);this.options.onPlaceholders?.([...n])}async#s(){let[e,t]=this.#r,n=new Set,o=await this.videoTrack.computeDuration();for(let c=Math.max(0,e);c<=t;c+=this.options.frequency)c>=0&&c<=o&&n.add(c);let i=[...n].filter(c=>!this.#t.has(c)),s=0;for await(let c of this.#e.canvasesAtTimestamps(i))if(c){let l=i[s++];this.#t.set(l,c)}for(let c of this.#t.keys())n.has(c)||this.#t.delete(c);let a=[...this.#t.entries()].map(([c,l])=>({time:c,canvas:l}));this.options.onChange(a)}set range(e){let[t,n]=e,o=n-t,[i,s]=this.#r,a=i+o,c=s-o,l=t<a,d=n>c;!l&&!d||(this.#r=this.#n(e,2),this.#c())}#o=null;#a=!1;async#c(){if(this.#i(),this.#o){this.#a=!0;return}this.#o=this.#s(),await this.#o,this.#o=null,this.#a&&(this.#a=!1,await this.#c())}getThumbnail(e){return this.#t.get(e)}};function Fa(r,e){let t=typeof window<"u"&&window.devicePixelRatio||1,n=document.createElement("canvas");n.width=e.width*t,n.height=e.height*t,n.style.width=`${e.width}px`,n.style.height=`${e.height}px`;let o=n.getContext("2d");if(!o)return n;o.scale(t,t),o.fillStyle=e.color;let i=e.height/2,s=Math.max(1,e.width),a=r.length/s;for(let c=0;c<s;c++){let l=Math.floor(c*a),d=Math.max(l+1,Math.floor((c+1)*a)),u=0;for(let m=l;m<d&&m<r.length;m++)r[m]>u&&(u=r[m]);let f=u*e.height;o.fillRect(c,i-f/2,1,f)}return n}var ki=[2048,1024,512,256,128,64,32];async function Da(r,e){let t=await r.getAudioDuration(e)??0,n=r.decodeAudio({source:e}).readable,o=ki[ki.length-1],i=[],s=0,a=0,c=0;for await(let u of n){c||=u.sampleRate;let f=u.numberOfFrames,m=new Float32Array(f);u.copyTo(m,{planeIndex:0});for(let p=0;p<m.length;p++){let g=Math.abs(m[p]);g>s&&(s=g),a++,a>=o&&(i.push(s),s=0,a=0)}u.close()}a>0&&i.push(s);let l=new Float32Array(i),d=ki.map(u=>{let f=Math.max(1,Math.round(u/o)),m=f===1?l:Kc(l,f);return{samplesPerPeak:u,peaks:m,peaksPerSecond:c>0?c/u:0}});return{duration:t,levels:d}}function Kc(r,e){let t=new Float32Array(Math.ceil(r.length/e));for(let n=0;n<t.length;n++){let o=0,i=n*e,s=Math.min(i+e,r.length);for(let a=i;a<s;a++)r[a]>o&&(o=r[a]);t[n]=o}return t}var Xc=4096,Zn=class r{#e=new Map;#t=[0,0];#r=[0,0];#n;#i;#s;#o=!1;color;duration;tileSize;tileHeight;preloadMargin;constructor(e,t,n){this.#i=e,this.duration=t,this.tileSize=n.tileSize??1,this.#n=n.zoom??(n.tileWidth??256)/this.tileSize,this.tileHeight=n.tileHeight??96,this.preloadMargin=n.preloadMargin??2,this.color=n.color??"rgb(3, 148, 129)",this.#s=n.onChange}static async init(e,t,n={}){let{duration:o,levels:i}=await Da(e,t);return new r(i,o,n)}set zoom(e){let t=Math.max(1,e);t!==this.#n&&(this.#n=t,this.#e.clear(),this.#c())}get zoom(){return this.#n}get range(){return this.#r}#a([e,t],n=1){let o=t-e;return[Math.max(0,e-o*n),Math.min(this.duration,t+o*n)]}set range(e){this.#r=e;let[t,n]=e,o=n-t,[i,s]=this.#t,a=i>0,c=s<this.duration,l=!a||t>=i+o,d=!c||n<=s-o;l&&d||(this.#t=this.#a(e,this.preloadMargin),this.#c())}#c(){this.#o||(this.#o=!0,queueMicrotask(()=>{this.#o=!1,this.#l()}))}#l(){let[e,t]=this.#t,n=new Set,o=this.#d(),i=Math.max(0,Math.floor(e/this.tileSize)*this.tileSize),s=Math.min(this.duration,t);for(let a=i;a<=s;a+=this.tileSize)n.add(a);for(let a of n)if(!this.#e.has(a)){let c=Math.min(a+this.tileSize,this.duration);this.#e.set(a,this.#u(a,c,o))}for(let a of this.#e.keys())n.has(a)||this.#e.delete(a);this.#p()}#u(e,t,n){let o=this.#f(n,e,t);return{startTime:e,endTime:t,peaks:o,canvas:Fa(o,{width:this.#m(e,t),height:this.tileHeight,color:this.color})}}#d(){return this.#i.find(e=>e.peaksPerSecond>=this.#n)??this.#i[this.#i.length-1]}#f(e,t,n){if(!e.peaksPerSecond)return new Float32Array;let o=Math.max(0,Math.floor(t*e.peaksPerSecond)),i=Math.max(o+1,Math.min(e.peaks.length,Math.ceil(n*e.peaksPerSecond)));return e.peaks.slice(o,i)}#m(e,t){return Math.min(Xc,Math.max(1,Math.ceil((t-e)*this.#n)))}#p(){this.#s&&this.#s([...this.#e.values()].sort((e,t)=>e.startTime-t.startTime))}getTiles(){return this.#e}};var U=r=>r;var qt=r=>r;var Ra=()=>{let r=!1,e=qt(60),t=1e3/e,n=0,o=0,i=ve(),s=null,a=l=>{if(requestAnimationFrame(a),!!r)for(n=l;l-o>=t;)o+=t,s?.(),s=null,i()};async function*c(){for(n=performance.now(),o=n,requestAnimationFrame(a);;)await new Promise(l=>s=l),yield}return{play(){r||(r=!0,n=performance.now(),o=n)},pause(){r=!1},setFPS(l){e=l,t=1e3/e},isPlaying(){return r},ticks:c,onTick:i}},Ma=async(r,e)=>{let t=U(1e3/r.fps),n=r.duration/1e3,o=Math.ceil(n*r.fps);for(let i=0;i<o;i++){let s=U(i*t);await e(s,i)}};function Oa(r){return"duration"in r}function za(r){let e=[],t=new Map(r.timeline.items.map(n=>[n.id,n]));return Si(r.timeline.rootId,t,r.from,{sequence:()=>{},stack:()=>{},video:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),text:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i}),audio:(n,o,i)=>e.push({item:n,localTime:o,ancestors:i})}),e}function Ua(r,e,t){let n=Sa;for(let o of e)n=Ba(r,o,n);return Ba(r,t,n)}function Ba(r,e,t){if("spatialId"in e&&e.spatialId){let n=r.get(e.spatialId);if(n?.enabled){let o=Ta(n.transform);return ka(o,t)}}return t}function Si(r,e,t,n,o=[]){let i=e.get(r);if(i)switch(i.kind){case M.Stack:n.stack(i,t,o);for(let s of i.childrenIds)Si(s,e,t,n,[...o,i]);break;case M.Sequence:{n.sequence(i,t,o);let s=U(0);for(let a of i.childrenIds){let c=e.get(a);if(!c||!Oa(c))continue;let l=U(s+c.duration);if(t>=l){s=l;continue}let d=U(Math.max(0,t-s));Si(a,e,d,n,[...o,i]),s=l}break}case M.Video:n.video(i,t,o);break;case M.Text:n.text(i,t,o);break;case M.Audio:n.audio(i,t,o);break}}function pe(r,e){let t=e.items.find(n=>n.id===r);if(!t)return U(0);switch(t.kind){case M.Sequence:{let n=t.childrenIds.map(i=>e.items.find(s=>s.id===i)).filter(Boolean),o=U(0);for(let i=0;i<n.length;i++){let s=n[i];if(s.kind===M.Transition){let a=n[i-1],c=n[i+1];if(a&&c&&a.kind!==M.Transition&&c.kind!==M.Transition){let l=pe(a.id,e),d=pe(c.id,e),u=Math.max(0,Math.min(s.duration,l,d));o=U(o-u)}continue}o=U(o+pe(s.id,e))}return o}case M.Stack:{let n=U(0);for(let o of t.childrenIds){let i=pe(o,e);i>n&&(n=i)}return n}default:return Oa(t)?t.duration:U(0)}}var Pr=r=>r;var Jn=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let n=new ee({formats:ie,source:await ce(this.resolveMedia(e))}),o=await n.getPrimaryVideoTrack(),s=!!o&&await o.canDecode()&&o?new Ct(o):null;return this.#e.set(e,{input:n,sink:s}),s}};async function Na(r,e,t,n){let[o,i]=await Promise.all([t,n]),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:r.id,kind:"transition",name:"circle",progress:e,from:s,to:a},...c]:c}async function Va(r,e,t,n){let o=Qc(r,e,t);if(!o)return[];let i=[...n,e];return o.isTransitioning?Na(o.transition,o.progress,mt(r,o.outgoing,o.outgoingTime,i),mt(r,o.incoming,o.incomingTime,i)):mt(r,o.item,o.localTime,i)}function Qc(r,e,t){let n=e.childrenIds.map(i=>r.items.get(i)).filter(i=>!!i),o=U(0);for(let i=0;i<n.length;i++){let s=n[i];if(s.kind===M.Transition)continue;let a=o,c=pe(s.id,r.timeline),l=U(a+c),d=n[i+1];if(!(d?.kind===M.Transition)){if(t<l)return{isTransitioning:!1,item:s,localTime:U(t-a)};o=l;continue}let f=d,m=n[i+2];if(!m||m.kind===M.Transition){o=l;continue}let p=pe(m.id,r.timeline),g=Math.max(0,Math.min(f.duration,c,p)),x=U(l-g);if(t<x)return{isTransitioning:!1,item:s,localTime:U(t-a)};if(t<l){let y=U(t-x),b=U(t-a);return{isTransitioning:!0,incoming:m,outgoing:s,outgoingTime:b,incomingTime:y,progress:g>0?y/g:1,transition:f}}o=x,i++}return null}async function mt(r,e,t,n){let o=Ua(r.items,n,e);switch(e.kind){case M.Stack:{let i=[...n,e];return(await Promise.all(e.childrenIds.map(a=>r.items.get(a)).filter(a=>!!a).map(a=>mt(r,a,t,i)))).flat()}case M.Sequence:return Va(r,e,t,n);case M.Video:{if(t<0||t>=e.duration)return[];let i=await r.videoSampler(e,t);return i?[{kind:"image",frame:i,matrix:o,id:e.id}]:[]}case M.Text:{if(t<0||t>=e.duration)return[];let i=e.styleId?r.items.get(e.styleId)?.style:void 0;return[{id:e.id,kind:"text",content:e.content,style:i,matrix:o}]}case M.Gap:return[{id:e.id,kind:"gap"}];default:return[]}}function La(r){return async(e,t)=>{let o=await(await r.getSink(e.mediaHash))?.getSample(t/1e3),i=o?.toVideoFrame();return o?.close(),i??void 0}}function eo(r,e){let t=new Jn(r),n=e??La(t);return{async sample(o,i){let s=new Map(o.items.map(c=>[c.id,c])),a=s.get(o.rootId);return a?mt({videoSampler:n,timeline:o,items:s},a,i,[]):[]}}}var Gt=class{driver;resolveMedia;timeline;#e=-1/0;#t=new Map;#r;constructor(e,t,n){this.driver=e,this.resolveMedia=t,this.timeline=n,this.#r=eo(this.resolveMedia,(o,i)=>{let s=Ha(i),a=this.#t.get(o.id);if(!a){let c=this.resolveMedia(o.mediaHash),l=Ha(U(o.start+o.duration));a=this.#n(c,s,l),this.#t.set(o.id,a)}return a.next(s)})}next(e){if(e<this.#e)throw new Error(`Forward-only cursor regression: ${e}ms < ${this.#e}ms`);return this.#e=e,this.#r.sample(this.timeline,e)}async cancel(){await Promise.all([...this.#t.values()].map(e=>e.cancel())),this.#t.clear()}#n(e,t,n){let o=this.driver.decodeVideo({source:e,start:t/1e6,end:n/1e6}),i=o.readable.getReader(),s=null,a=null,c=!1,l=async()=>{if(c)return null;let{done:d,value:u}=await i.read();if(d)return c=!0,null;let f=new VideoFrame(u);return u.close(),f};return{async next(d){if(s??=await l(),!!s)for(;;){a??=l();let u=await a;if(!u)return new VideoFrame(s);let f=s.timestamp??-1/0,m=u.timestamp??f;if(m<d){s.close(),s=u,a=null;continue}if(Math.abs(m-d)<Math.abs(f-d)){s.close(),s=u,a=null;continue}return new VideoFrame(s)}},async cancel(){let d=a;a=null,c=!0,(await d?.catch(()=>null))?.close(),s?.close(),s=null,o.cancel()}}}},Ha=r=>Math.round(r*1e3);async function qa(r,e,t){return(await Promise.all(e.map(async({item:o,localTime:i})=>{if(o.kind!==M.Audio)return;let s=await r.getSink(o.mediaHash);if(!s)return;let a=o.start+i,c=Pr((t-a)/1e3),l=s.samples(a/1e3),d=await l.next();if(d.done)return;let u=d.value,f=l.next();return{offset:c,gain:o.gain??1,get currentSample(){return u},timelineTime:()=>Pr(c+u.timestamp),output:()=>({sample:u,timestamp:c+u.timestamp,gain:o.gain??1}),advance:async()=>{let m=await f;return m.done?!1:(u=m.value,f=l.next(),!0)}}}))).filter(o=>!!o)}var to=class{resolveMedia;#e=new Map;constructor(e){this.resolveMedia=e}async getSink(e){let t=this.#e.get(e);if(t)return t.sink;let n=new ee({formats:ie,source:await ce(this.resolveMedia(e))}),o=await n.getPrimaryAudioTrack(),s=!!o&&await o.canDecode()&&o?new mr(o):null;return this.#e.set(e,{input:n,sink:s}),s}};function Ga(r){let e={index:0,stream:r[0],time:r[0].timelineTime()};for(let[t,n]of r.entries()){let o=n.timelineTime();o<e.time&&(e={time:o,stream:n,index:t})}return e}function ro(r){let e=new to(r);return{async*sampleAudio(t,n){let o=za({timeline:t,from:n}),i=await qa(e,o,n);for(;i.length>0;){let{stream:s,index:a}=Ga(i);yield s.output(),await s.advance()||i.splice(a,1)}}}}var no=class{driver;timeline;resolveMedia;audioSampler;seekVisualSampler;playVisualSampler=null;#e=U(0);#t=null;#r=Ra();onTick=this.#r.onTick;audioContext=new AudioContext({sampleRate:48e3});audioGain=this.audioContext.createGain();audioNodes=new Set;#n=null;constructor(e,t,n){this.driver=e,this.timeline=t,this.resolveMedia=n,this.audioGain.connect(this.audioContext.destination),this.audioGain.gain.value=.7**2,this.seekVisualSampler=eo(this.resolveMedia),this.audioSampler=ro(this.resolveMedia),this.#i()}update(e){this.timeline=e}get isPlaying(){return this.#r.isPlaying()}async#i(){for await(let e of this.#r.ticks()){let t=await this.playVisualSampler?.next(this.currentTime)??[];(await this.driver.composite(t)).close(),this.currentTime>=this.duration&&this.pause()}}async seek(e){return this.pause(),this.#e=e,await this.seekVisualSampler.sample(this.timeline,e)}async start(){if(!this.#r.isPlaying()){await this.audioContext.resume(),this.#e=this.currentTime,this.#t=this.audioContext.currentTime,this.#n?.abort(),this.#n=new AbortController;for(let e of this.audioNodes)e.stop();this.audioNodes.clear(),this.playVisualSampler=new Gt(this.driver,this.resolveMedia,this.timeline),this.#r.play(),this.#s(this.#n.signal,Pr(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(),this.playVisualSampler&&(this.playVisualSampler.cancel(),this.playVisualSampler=null)}get duration(){return pe(this.timeline.rootId,this.timeline)}get currentTime(){if(!this.#r.isPlaying()||this.#t===null)return this.#e;let e=(this.audioContext.currentTime-this.#t)*1e3;return U(this.#e+e)}setFps(e){this.#r.setFPS(e)}async#s(e,t){let n=this.audioContext;if(this.#t!==null)for await(let{sample:o,timestamp:i}of this.audioSampler.sampleAudio(this.timeline,U(t*1e3))){if(e.aborted||!this.#r.isPlaying())return;for(;i-(n.currentTime-this.#t+t)>.75;)await new Promise(c=>setTimeout(c,25));let s=n.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>=n.currentTime?s.start(a):s.start(n.currentTime,n.currentTime-a)}}};var oo=class{driver;canvas;playback;#e=null;#t=null;constructor(e,t,n){this.driver=e,this.playback=new no(e,n,t),this.canvas=e.compositor.pixi.renderer.canvas}async play(){await this.playback.start()}pause(){this.playback.pause()}seek(e){return this.#e=e,this.#t??=this.#r().finally(()=>this.#t=null)}setFPS(e){this.playback.setFps(qt(e))}get isSeeking(){return this.#t!==null}get isPlaying(){return this.playback.isPlaying}get duration(){return this.playback.duration}get currentTime(){return this.playback.currentTime}update(e){this.playback.update(e)}async#r(){for(;this.#e!==null;){let e=this.#e;this.#e=null;let t=await this.playback.seek(U(e));(await this.driver.composite(t)).close()}}};var pt=class{state;constructor(e){this.state=e}require(e){return e===void 0?void 0:this.state.timeline.items.find(n=>n.id===e)}get timeline(){return this.state.timeline}getId(){return he.toInteger(he.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:M.TextStyle,style:e};return this.register(t),t};spatial=e=>{let t={id:this.getId(),kind:M.Spatial,transform:e,enabled:!0};return this.register(t),t};sequence=(...e)=>{let t={id:this.getId(),kind:M.Sequence,childrenIds:e.map(n=>n.id)};return this.register(t),t};stack=(...e)=>{let t={kind:M.Stack,id:this.getId(),childrenIds:e.map(n=>n.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 n={kind:M.Video,id:this.getId(),mediaHash:e.datafile.checksum.hash,start:t?.start??0,duration:t?.duration??e.duration};return this.register(n),n};audio=(e,t)=>{if(!e.hasAudio)throw new Error(`Audio clip error: media "${e.datafile.filename}" has no audio track.`);let n={kind:M.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(n),n};text=(e,t)=>{let n={id:this.getId(),content:e,kind:M.Text,duration:t?.duration??2e3};return t?.styles&&(n.styleId=this.textStyle(t.styles).id),this.register(n),n};gap=e=>{let t={id:this.getId(),kind:M.Gap,duration:e};return this.register(t),t};transition={crossfade:e=>{let t={id:this.getId(),kind:M.Transition,effect:Kn.Crossfade,duration:e};return this.register(t),t}};transform=e=>{let t=[e?.position?.[0]??0,e?.position?.[1]??0],n=[e?.scale?.[0]??1,e?.scale?.[1]??1],o=e?.rotation??0;return[t,n,o]};addChildren(e,...t){this.#e(n=>(n.items.find(({id:i})=>i===e.id).childrenIds.push(...t.map(i=>i.id)),n))}set=(e,t)=>{this.#e(n=>({...n,items:n.items.map(o=>o.id===e?{...o,...t}:o)}))}};var io=class{#e;#t;constructor(e={}){this.#e=e.chunkFrames??1024,this.#t=e.clamp??!0}async*mix(e){let t=this.#e,n=null,o=null,i=[],s=0,a=0;for await(let c of e){if(o===null)o=c.planes.length,n=c.sampleRate;else{if(c.planes.length!==o)throw new Error("Channel count changed");if(c.sampleRate!==n)throw new Error("Sample rate changed")}let l=Math.round(c.timestamp*n),d=c.planes[0]?.length??0;for(;s+t<=l;)yield this.#r(i,s,o,n),s+=t;i.push({startFrame:l,endFrame:l+d,data:c.planes}),a=Math.max(a,l+d)}if(o!==null&&n!==null)for(;s<a;)yield this.#r(i,s,o,n),s+=t}#r(e,t,n,o){let i=this.#e,s=new Float32Array(n*i),a=t+i;for(let c=0;c<n;c++){let l=c*i,d=s.subarray(l,l+i);for(let u of e){let f=u.data[c];if(!f)continue;let m=Math.max(t,u.startFrame),p=Math.min(a,u.endFrame);if(m>=p)continue;let g=m-t,x=m-u.startFrame,y=p-m;for(let b=0;b<y;b++)d[g+b]+=f[x+b]}if(this.#t)for(let u=0;u<i;u++){let f=d[u];d[u]=f<-1?-1:f>1?1:f}}for(let c=e.length-1;c>=0;c--)e[c].endFrame<=a&&e.splice(c,1);return{planar:s,sampleRate:o,channels:n,frames:i,startFrame:t}}};var Yc=(r,e,t)=>{if(e===t)return r;let n=t/e,o=Math.max(1,Math.round(r.length*n)),i=new Float32Array(o);for(let s=0;s<o;s++){let a=s/n,c=Math.floor(a),l=Math.min(c+1,r.length-1),d=a-c;i[s]=r[c]*(1-d)+r[l]*d}return i},Wa=(r,e)=>{let t=r.numberOfChannels,n=new Array(t),o=0;for(let i=0;i<t;i++){let s=new Float32Array(r.numberOfFrames);r.copyTo(s,{planeIndex:i,format:"f32-planar"});let a=Yc(s,r.sampleRate,e);n[i]=a,o=a.length}return{data:n,frames:o}};var ja=(r,e)=>{if(e!==1)for(let t of r)for(let n=0;n<t.length;n++)t[n]*=e};function $a({timeline:r,resolveMedia:e}){let t=new io,n=Zc(r,e),o=new TransformStream,i=o.writable.getWriter();async function s(){for await(let a of t.mix(n)){let c=new AudioData({format:"f32-planar",sampleRate:a.sampleRate,numberOfFrames:a.frames,numberOfChannels:a.channels,timestamp:Math.round(a.startFrame/a.sampleRate*1e6),data:new Float32Array(a.planar)});await i.write(c)}await i.close()}return s(),o.readable}async function*Zc(r,e){let t=ro(e);for await(let{sample:n,timestamp:o,gain:i}of t.sampleAudio(r,U(0))){let{data:s}=Wa(n,48e3);ja(s,i),yield{planes:s,sampleRate:48e3,timestamp:o},n.close()}}function Ka({timeline:r,fps:e,driver:t,resolveMedia:n}){let o=new TransformStream,i=o.writable.getWriter(),s=new Gt(t,n,r),a=1/e,c=pe(r.rootId,r);async function l(){await Ma({fps:e,duration:c},async(d,u)=>{let f=await s.next(d),m=await t.composite(f),p=new VideoFrame(m,{timestamp:Math.round(u*a*1e6),duration:Math.round(a*1e6)});await i.write(p),m.close()}),await i.close()}return l(),o.readable}function Xa(r){let e=$a({...r}),t=Ka({...r});return r.driver.encode({video:t,audio:e,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}})}var so=class{driver;resources=new Qn;constructor(e){this.driver=e}load=async e=>Object.fromEntries(await Promise.all(Object.entries(e).map(async([t,n])=>[t,await this.resources.store(await n)])));timeline=e=>{let t=new pt({timeline:{format:"timeline",info:"https://omniclip.app/",version:0,items:[],rootId:0}}),n=e(t);return t.timeline.rootId=n.id,t.timeline};playback=async e=>new oo(this.driver,t=>this.resources.require(t).url,e);render=async(e,t=30)=>Xa({timeline:e,fps:qt(t),driver:this.driver,resolveMedia:n=>this.resources.require(n).url})};var ao=class{data;bytes;hash;nickname;constructor(e,t,n,o){this.data=e,this.bytes=t,this.hash=n,this.nickname=o}static async make(e){let t=new Uint8Array(e),n=new Uint8Array(await crypto.subtle.digest("SHA-256",t)),o=_r.fromBytes(n),i=Ri.sigil.fromBytes(n);return new this(e,n,o,i)}};var co=class{url;bytes;blob;filename;checksum;constructor(e,t,n,o,i){this.url=e,this.bytes=t,this.blob=n,this.filename=o,this.checksum=i}static async make(e,t){let n=await e.arrayBuffer(),o=new Uint8Array(n),i=await ao.make(o),s=t??i.nickname,a=URL.createObjectURL(e);return new this(a,o,e,s,i)}static async load(e){}};async function Ya(r,e,t){let n=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 pt({timeline:r}),d=await e.playback(r);c.replaceChildren(d.canvas),n.disabled=!1,o.disabled=!1,n.addEventListener("click",()=>d.play()),o.addEventListener("click",()=>d.pause()),i.max=String(Math.ceil(d.duration));let u=!1;d.playback.onTick.on(()=>m(d.currentTime,d.duration));let f=(p,g)=>{a.textContent=`${Qa(p)} / ${Qa(g)}`};i.addEventListener("input",async()=>{u=!0;let p=Math.max(0,Math.min(+i.value,d.duration));f(p,d.duration),await d.seek(p)}),i.addEventListener("change",async()=>{u=!1;let p=Math.max(0,Math.min(+i.value,d.duration));await d.seek(p)});let m=(p,g)=>{let x=Math.max(0,Math.min(p,g));u||(i.value=String(Math.round(x)));let y=g?x/g*100:0;s.style.left=`${y}%`,f(x,g)};d.update(l.timeline)}function Qa(r){let e=Math.max(0,r),t=Math.floor(e/1e3),n=Math.floor(t/60),o=t%60,i=Math.floor(e%1e3);return`${n}:${String(o).padStart(2,"0")}.${String(i).padStart(3,"0")}`}async function Ja(r,e,t){let n=t.querySelector(".waveform-canvas"),o=t.querySelector(".width");n.replaceChildren(),n.style.position="relative",n.style.height="96px",n.style.overflow="hidden";let i=await Zn.init(r,e,{tileHeight:96,onChange:()=>s()}),s=()=>{let a=+o.value,c=Za(a,i.duration);i.zoom=c,n.style.width=`${a}px`,n.replaceChildren(...[...i.getTiles().values()].map(l=>(l.canvas.style.position="absolute",l.canvas.style.top="0",l.canvas.style.left=`${l.startTime*Za(a,i.duration)}px`,l.canvas.style.height="100%",l.canvas)))};o.oninput=s,i.range=[0,i.duration]}function Za(r,e){return e>0?r/e:0}async function vi(r,e){let t=new so(r),{videoA:n}=await t.load({videoA:co.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(n,{duration:3e3,start:1e3}),i.audio(n,{duration:1e3})),i.gap(500),i.video(n,{duration:7e3,start:5e3}))}),omni:t}}async function ec(r,e){let t=e.querySelector(".range"),n=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 d=await Yn.init(r,{onChange(u){let f=u.sort((m,p)=>m.time-p.time);a.replaceChildren(...f.map(({time:m,canvas:p})=>Jc(m,p.canvas)))},frequency:c,canvasSinkOptions:{width:80,height:50,fit:"fill"}});o.oninput=()=>{l=+o.value;let u=+t.value,f=u+l;d.range=[u,f],n.textContent=`visible time range: [${u}, ${f}]`},t.oninput=()=>{let u=+t.value,f=u+l;d.range=[u,f],n.textContent=`visible time range: [${u}, ${f}]`},i.oninput=()=>{d.frequency=1/+i.value,s.textContent=`frame every ${d.frequency.toFixed(3)} second (${i.value} frames per second)`},d.range=[10,10.5]}function Jc(r,e){let t=document.createElement("div");t.style.position="relative",t.style.display="inline-block",t.style.marginRight="4px",t.appendChild(e);let n=document.createElement("div");return n.textContent=`${r.toFixed(2)}s`,n.style.position="absolute",n.style.top="2px",n.style.right="4px",n.style.fontSize="10px",n.style.color="white",n.style.background="rgba(0,0,0,0.6)",n.style.padding="2px 4px",n.style.borderRadius="4px",n.style.pointerEvents="none",t.appendChild(n),t}function tc(r,e){let t={width:1920,height:1080},n=document.createElement("canvas");n.width=t.width,n.height=t.height;let o=n.getContext("2d");async function i(){let s=r.decodeVideo({source:e,async onFrame(f){let m=await r.composite([{id:0,kind:"image",frame:f},{id:1,kind:"text",content:"omnitool",style:{fontSize:50,fill:"green"}}]);return f.close(),o?.drawImage(m,0,0),m}}),a=r.decodeAudio({source:e}),{readable:c,done:l}=r.encode({video:s.readable,audio:a.readable,config:{audio:{codec:"opus",bitrate:128e3},video:{codec:"vp9",bitrate:1e6}}}),u=await(await window.showSaveFilePicker()).createWritable();await Promise.all([c.pipeTo(u),l])}return{canvas:n,run:i}}var Wt=await $n.setup({workerUrl:new URL("../driver/driver.worker.bundle.min.js",import.meta.url)}),el=document.querySelector("[data-demo='transcode']"),tl=document.querySelector("[data-demo='filmstrip']"),rl=document.querySelector("[data-demo='waveform']"),rc=document.querySelector("[data-demo='playback']"),ht=document.querySelector("[data-demo='export']"),nc=ht.querySelector("[data-action='export']"),lo=null;await Wt.thread.work.hello(),Wt.machina.count===1?console.log("\u2705 driver works"):console.error("\u274C FAIL driver call didn't work");var jt=(r,e)=>{let t=r.querySelector(".progress"),n=r.querySelector(".status");!t||!n||(e==="running"?(t.removeAttribute("value"),n.textContent="running"):e==="done"?(t.value=1,n.textContent="done"):(t.value=0,n.textContent="idle"))},Pi=(r,e)=>{let t=r.querySelector("input[type='file']"),n=r.querySelector("[data-action='run']");n.disabled=!0,t.addEventListener("input",()=>{n.disabled=!t.files?.length}),n.addEventListener("click",async()=>{let o=t.files?.[0];if(o){n.disabled=!0,jt(r,"running");try{await e(o,r),jt(r,"done")}finally{n.disabled=!1}}})};Pi(el,async(r,e)=>{let t=e.querySelector(".demo-preview"),n=tc(Wt,r);t.replaceChildren(n.canvas),await n.run()});Pi(tl,async(r,e)=>{await ec(r,e)});Pi(rl,async(r,e)=>{await Ja(Wt,r,e)});{let r=rc.querySelector("input[type='file']");r.addEventListener("input",async()=>{let e=r.files?.[0];if(!e)return;let{timeline:t,omni:n}=await vi(Wt,e);await Ya(t,n,rc)})}{let r=ht.querySelector("input[type='file']");r.addEventListener("input",async()=>{let e=r.files?.[0];if(!e)return;jt(ht,"running");let{timeline:t,omni:n}=await vi(Wt,e);lo={timeline:t,omni:n},nc.disabled=!1;let o=ht.querySelector(".demo-preview"),i=await n.playback(t);await i.seek(0),o.replaceChildren(i.canvas),jt(ht,"done")})}nc.addEventListener("click",async()=>{lo&&(jt(ht,"running"),await lo.omni.render(lo.timeline),jt(ht,"done"))});
|
|
2416
2416
|
/*! Bundled license information:
|
|
2417
2417
|
|
|
2418
2418
|
mediabunny/dist/modules/src/misc.js:
|