@fly-cut/av-canvas
Version:
Combine Text, Image, Video, Audio, UserMedia, DisplayMedia to generate MediaStream. With [AVRcorder](../av-recorder/README.md) you can output MP4 streams and save them as local files or push them to the server.
33 lines (32 loc) • 18.4 kB
JavaScript
(function(m,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@fly-cut/av-cliper"),require("@fly-cut/internal-utils")):typeof define=="function"&&define.amd?define(["exports","@fly-cut/av-cliper","@fly-cut/internal-utils"],f):(m=typeof globalThis<"u"?globalThis:m||self,f(m["av-canvas"]={},m.avCliper,m.internalUtils))})(this,function(m,f,v){"use strict";var Nt=Object.defineProperty;var xt=m=>{throw TypeError(m)};var qt=(m,f,v)=>f in m?Nt(m,f,{enumerable:!0,configurable:!0,writable:!0,value:v}):m[f]=v;var rt=(m,f,v)=>qt(m,typeof f!="symbol"?f+"":f,v),wt=(m,f,v)=>f.has(m)||xt("Cannot "+v);var n=(m,f,v)=>(wt(m,f,"read from private field"),v?v.call(m):f.get(m)),x=(m,f,v)=>f.has(m)?xt("Cannot add the same private member more than once"):f instanceof WeakSet?f.add(m):f.set(m,v),S=(m,f,v,at)=>(wt(m,f,"write to private field"),at?at.call(m,v):f.set(m,v),v),$=(m,f,v)=>(wt(m,f,"access private method"),v);var O,N,q,U,C,M,E,K,tt,et,P,J,z,A,Y,nt,X,k,ot,st,I,j,D,mt,W,it;const at=["t","b","l","r","lt","lb","rt","rb","rotate"];function G(i){return document.createElement(i)}function St(i){let t=16;const r=new ResizeObserver(o=>{const s=o[0];s!=null&&(t=10/(s.contentRect.width/i.width))});r.observe(i);function e(o){const{w:s,h}=o,a=t,c=a/2,l=s/2,d=h/2,p=a*1.5,u=p/2;return{...o.fixedAspectRatio?{}:{t:new f.Rect(-c,-d-c,a,a,o),b:new f.Rect(-c,d-c,a,a,o),l:new f.Rect(-l-c,-c,a,a,o),r:new f.Rect(l-c,-c,a,a,o)},lt:new f.Rect(-l-c,-d-c,a,a,o),lb:new f.Rect(-l-c,d-c,a,a,o),rt:new f.Rect(l-c,-d-c,a,a,o),rb:new f.Rect(l-c,d-c,a,a,o),rotate:new f.Rect(-u,-d-a*2-u,p,p,o)}}return{rectCtrlsGetter:e,destroy:()=>{r.disconnect()}}}var ct=(i=>(i.ActiveSpriteChange="activeSpriteChange",i.AddSprite="addSprite",i))(ct||{});class vt{constructor(){x(this,O,[]);x(this,N,null);x(this,q,new v.EventTool);rt(this,"on",n(this,q).on);x(this,U,0)}get activeSprite(){return n(this,N)}set activeSprite(t){t!==n(this,N)&&(S(this,N,t),n(this,q).emit("activeSpriteChange",t))}async addSprite(t){await t.ready,n(this,O).push(t),S(this,O,n(this,O).sort((r,e)=>r.zIndex-e.zIndex)),t.on("propsChange",r=>{r.zIndex!=null&&S(this,O,n(this,O).sort((e,o)=>e.zIndex-o.zIndex))}),n(this,q).emit("addSprite",t)}removeSprite(t){n(this,N)===t&&(this.activeSprite=null),S(this,O,n(this,O).filter(r=>r!==t)),t.destroy()}getSprites(t={time:!0}){return n(this,O).filter(r=>r.visible&&(t.time?n(this,U)>=r.time.offset&&n(this,U)<=r.time.offset+r.time.duration:!0))}updateRenderTime(t){S(this,U,t);const r=this.activeSprite;r!=null&&(t<r.time.offset||t>r.time.offset+r.time.duration)&&(this.activeSprite=null)}destroy(){n(this,q).destroy(),n(this,O).forEach(t=>t.destroy()),S(this,O,[])}}O=new WeakMap,N=new WeakMap,q=new WeakMap,U=new WeakMap;function Ct(i,t,r,e){const o={w:t.clientWidth/t.width,h:t.clientHeight/t.height},s=new ResizeObserver(()=>{o.w=t.clientWidth/t.width,o.h=t.clientHeight/t.height,r.activeSprite!=null&&ft(r.activeSprite,a,c,o,e,t)});s.observe(t);let h=()=>{};const{rectEl:a,ctrlsEl:c}=Mt(i),l=r.on(ct.ActiveSpriteChange,d=>{if(h(),d==null){a.style.display="none";return}ft(d,a,c,o,e,t),h=d.on("propsChange",()=>{ft(d,a,c,o,e,t)}),a.style.display=""});return()=>{s.disconnect(),l(),a.remove(),h()}}function Mt(i){const t=G("div");t.style.cssText=`
position: absolute;
pointer-events: none;
border: 1px solid #eee;
box-sizing: border-box;
display: none;
`;const r=Object.fromEntries(at.map(e=>{const o=G("div");return o.style.cssText=`
display: none;
position: absolute;
border: 1px solid #3ee; border-radius: 50%;
box-sizing: border-box;
background-color: #fff;
`,[e,o]}));return Object.values(r).forEach(e=>t.appendChild(e)),i.appendChild(t),{rectEl:t,ctrlsEl:r}}function ft(i,t,r,e,o,s){const{x:h,y:a,w:c,h:l,angle:d}=i.rect,p=s.width/2*e.w,u=s.height/2*e.h,w=h-c/2,y=a-l/2;Object.assign(t.style,{left:`${p+w*e.w}px`,top:`${u+y*e.h}px`,width:`${c*e.w}px`,height:`${l*e.h}px`,rotate:`${d}rad`}),Object.entries(o(i.rect)).forEach(([R,{x:T,y:b,w:g,h:Q}])=>{Object.assign(r[R].style,{display:"block",left:"50%",top:"50%",width:`${g*e.w}px`,height:`${Q*e.h}px`,transform:`translate(${T*e.w}px, ${b*e.h}px)`})})}function It(i,t,r){const e={w:i.clientWidth/i.width,h:i.clientHeight/i.height},o=new ResizeObserver(()=>{e.w=i.clientWidth/i.width,e.h=i.clientHeight/i.height});o.observe(i);const s=h=>{if(h.button!==0)return;const{offsetX:a,offsetY:c}=h,l=a/e.w,d=c/e.h,p=l-i.width/2,u=d-i.height/2;if(t.activeSprite!=null){const[w]=Object.entries(r(t.activeSprite.rect)).find(([,y])=>y.checkHit(p,u))??[];if(w!=null)return}t.activeSprite=t.getSprites().reverse().find(w=>w.visible&&w.selectable&&w.rect.checkHit(p,u))??null};return i.addEventListener("pointerdown",s),()=>{o.disconnect(),i.removeEventListener("pointerdown",s)}}function Tt(i,t,r,e){const o={w:i.clientWidth/i.width,h:i.clientHeight/i.height},s=new ResizeObserver(()=>{o.w=i.clientWidth/i.width,o.h=i.clientHeight/i.height});s.observe(i);let h=0,a=0,c=null;const l=Wt(i,r);let d=null;const p=y=>{if(y.button!==0||t.activeSprite==null)return;d=t.activeSprite;const{offsetX:R,offsetY:T,clientX:b,clientY:g}=y;Lt({rect:d.rect,offsetX:R,offsetY:T,clientX:b,clientY:g,cvsRatio:o,cvsEl:i,rectCtrlsGetter:e})||(c=d.rect.clone(),l.magneticEffect(d.rect.x,d.rect.y,d.rect),h=b,a=g,window.addEventListener("pointermove",u),window.addEventListener("pointerup",w))},u=y=>{if(d==null||c==null)return;const{clientX:R,clientY:T}=y;let b=c.x+(R-h)/o.w,g=c.y+(T-a)/o.h;gt(d.rect,i,l.magneticEffect(b,g,d.rect))};i.addEventListener("pointerdown",p);const w=()=>{l.hide(),window.removeEventListener("pointermove",u),window.removeEventListener("pointerup",w)};return()=>{s.disconnect(),l.destroy(),w(),i.removeEventListener("pointerdown",p)}}function kt({sprRect:i,startX:t,startY:r,ctrlKey:e,cvsRatio:o,cvsEl:s}){const h=i.clone(),a=l=>{const{clientX:d,clientY:p}=l,u=(d-t)/o.w,w=(p-r)/o.h,y=e.length===1?Rt:At,{x:R,y:T,w:b,h:g}=h,Q=Math.atan2(g,b),{incW:Z,incH:V,incS:B,rotateAngle:ht}=y({deltaX:u,deltaY:w,angle:i.angle,ctrlKey:e,diagonalAngle:Q}),L=10;let H=b,_=g,dt=h.fixedScaleCenter?Z*2:Z,lt=h.fixedScaleCenter?V*2:V,F=B;const bt=Math.sqrt(g**2+b**2),yt=Math.sqrt((L*(g/b))**2+L**2);switch(e){case"l":H=Math.max(b+dt,L),F=Math.min(B,b-L);break;case"r":H=Math.max(b+dt,L),F=Math.max(B,L-b);break;case"b":_=Math.max(g+lt,L),F=Math.min(B,g-L);break;case"t":_=Math.max(g+lt,L),F=Math.max(B,L-g);break;case"lt":case"lb":H=Math.max(b+dt,L),_=H===L?g/b*H:g+lt,F=Math.min(B,bt-yt);break;case"rt":case"rb":H=Math.max(b+dt,L),_=H===L?g/b*H:g+lt,F=Math.max(B,yt-bt);break}let ut=R,pt=T;if(h.fixedScaleCenter)ut=R+b/2-H/2,pt=T+g/2-_/2;else{const Vt=F/2*Math.cos(ht)+R+b/2,Ft=F/2*Math.sin(ht)+T+g/2;ut=Vt-H/2,pt=Ft-_/2}gt(i,s,{x:ut,y:pt,w:H,h:_})},c=()=>{window.removeEventListener("pointermove",a),window.removeEventListener("pointerup",c)};window.addEventListener("pointermove",a),window.addEventListener("pointerup",c)}function Rt({deltaX:i,deltaY:t,angle:r,ctrlKey:e}){let o=0,s=0,h=0,a=r;return e==="l"||e==="r"?(o=i*Math.cos(r)+t*Math.sin(r),s=o*(e==="l"?-1:1)):(e==="t"||e==="b")&&(a=r-Math.PI/2,o=i*Math.cos(a)+t*Math.sin(a),h=o*(e==="b"?-1:1)),{incW:s,incH:h,incS:o,rotateAngle:a}}function At({deltaX:i,deltaY:t,angle:r,ctrlKey:e,diagonalAngle:o}){const s=(e==="lt"||e==="rb"?1:-1)*o+r,h=i*Math.cos(s)+t*Math.sin(s),a=e==="lt"||e==="lb"?-1:1,c=h*Math.cos(o)*a,l=h*Math.sin(o)*a;return{incW:c,incH:l,incS:h,rotateAngle:s}}function Lt({rect:i,cvsRatio:t,offsetX:r,offsetY:e,clientX:o,clientY:s,cvsEl:h,rectCtrlsGetter:a}){const c=r/t.w,l=e/t.h,d=c-h.width/2,p=l-h.height/2,[u]=Object.entries(a(i)).find(([,w])=>w.checkHit(d,p))??[];return u==null?!1:(u==="rotate"?Ot(i,zt(i.center,t,h)):kt({sprRect:i,ctrlKey:u,startX:o,startY:s,cvsRatio:t,cvsEl:h}),!0)}function Ot(i,t){const r=({clientX:o,clientY:s})=>{const h=o-t.x,a=s-t.y,c=Math.atan2(a,h)+Math.PI/2;i.angle=c},e=()=>{window.removeEventListener("pointermove",r),window.removeEventListener("pointerup",e)};window.addEventListener("pointermove",r),window.addEventListener("pointerup",e)}function zt(i,t,r){const e=i.x*t.w,o=i.y*t.h,{left:s,top:h}=r.getBoundingClientRect();return{x:e+s,y:o+h}}function gt(i,t,r){const e={x:i.x,y:i.y,w:i.w,h:i.h,...r},o=.05,s=e.w*o,h=e.h*o,a=-t.width/2,c=t.width/2,l=-t.height/2,d=t.height/2,p=a-e.w/2+s,u=c+e.w/2-s,w=l-e.h/2+h,y=d+e.h/2-h;e.x<p?e.x=p:e.x>u&&(e.x=u),e.y<w?e.y=w:e.y>y&&(e.y=y),i.x=e.x,i.y=e.y,i.w=e.w,i.h=e.h}function Wt(i,t){const r="display: none; position: absolute;",e={w:0,h:0,x:0,y:0},o={vertMiddle:{...e,h:100,x:50,ref:{prop:"x",val:({w:c})=>(i.width-c)/2}},horMiddle:{...e,w:100,y:50,ref:{prop:"y",val:({h:c})=>(i.height-c)/2}},top:{...e,w:100,ref:{prop:"y",val:()=>0}},bottom:{...e,w:100,y:100,ref:{prop:"y",val:({h:c})=>i.height-c}},left:{...e,h:100,ref:{prop:"x",val:()=>0}},right:{...e,h:100,x:100,ref:{prop:"x",val:({w:c})=>i.width-c}}},s=G("div");s.style.cssText=`
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
pointer-events: none;
box-sizing: border-box;
`;const h=Object.fromEntries(Object.entries(o).map(([c,{w:l,h:d,x:p,y:u}])=>{const w=G("div");return w.style.cssText=`
${r}
border-${l>0?"top":"left"}: 1px solid #3ee;
top: ${u}%; left: ${p}%;
${p===100?"margin-left: -1px":""};
${u===100?"margin-top: -1px":""};
width: ${l}%; height: ${d}%;
`,s.appendChild(w),[c,w]}));t.appendChild(s);const a=6/(900/i.width);return{magneticEffect(c,l,d){const p={x:c,y:l};let u,w={x:!1,y:!1};for(u in o){const{prop:y,val:R}=o[u].ref;if(w[y])continue;const T=R(d);Math.abs(d[y]-T)<=a&&Math.abs(d[y]-(y==="x"?c:l))<=a?(p[y]=T,h[u].style.display="block",w[y]=!0):h[u].style.display="none"}return p},hide(){Object.values(h).forEach(c=>c.style.display="none")},destroy(){s.remove()}}}function Ht(i,t,r){const e={w:i.clientWidth/i.width,h:i.clientHeight/i.height},o=new ResizeObserver(()=>{e.w=i.clientWidth/i.width,e.h=i.clientHeight/i.height});o.observe(i);const s=i.style;let h=t.activeSprite;t.on(ct.ActiveSpriteChange,w=>{h=w,w==null&&(s.cursor="")});let a=!1;const c=({offsetX:w,offsetY:y})=>{a=!0;const R=w/e.w,T=y/e.h,b=R-i.width/2,g=T-i.height/2;(h==null?void 0:h.rect.checkHit(b,g))===!0&&s.cursor===""&&(s.cursor="move")},l=()=>{a=!1},d=["ns-resize","nesw-resize","ew-resize","nwse-resize","ns-resize","nesw-resize","ew-resize","nwse-resize"],p={t:0,rt:1,r:2,rb:3,b:4,lb:5,l:6,lt:7},u=w=>{if(h==null||a)return;const{offsetX:y,offsetY:R}=w,T=y/e.w,b=R/e.h,g=T-i.width/2,Q=b-i.height/2,[Z]=Object.entries(r(h.rect)).find(([,V])=>V.checkHit(g,Q))??[];if(Z!=null){if(Z==="rotate"){s.cursor="crosshair";return}const V=h.rect.angle,B=V<0?V+2*Math.PI:V,ht=(p[Z]+Math.floor((B+Math.PI/8)/(Math.PI/4)))%8;s.cursor=d[ht];return}if(h.rect.checkHit(g,Q)){s.cursor="move";return}s.cursor=""};return i.addEventListener("pointermove",u),i.addEventListener("pointerdown",c),window.addEventListener("pointerup",l),()=>{o.disconnect(),i.removeEventListener("pointermove",u),i.removeEventListener("pointerdown",c),window.removeEventListener("pointerup",l)}}const $t={sampleRate:48e3,channelCount:2,codec:"mp4a.40.2"};function Yt(i){const t=G("canvas");return t.style.cssText=`
width: 100%;
height: 100%;
display: block;
touch-action: none;
`,t.width=i.width,t.height=i.height,t}class Xt{constructor(t,r){x(this,k);x(this,C);x(this,M);x(this,E);x(this,K,!1);x(this,tt,[]);x(this,et);x(this,P,new v.EventTool);rt(this,"on",n(this,P).on);x(this,J);x(this,z,{mode:"cover",opacity:1,blur:0});x(this,A,null);x(this,Y,null);x(this,nt,{x:0,y:0});x(this,X,0);x(this,I,new AudioContext);x(this,j,n(this,I).createMediaStreamDestination());x(this,D,new Set);x(this,W,{start:0,end:0,step:0,audioPlayAt:0});x(this,it,new WeakMap);rt(this,"addSprite",async t=>{n(this,I).state==="suspended"&&n(this,I).resume().catch(f.Log.error);const r=t.getClip();if(r instanceof f.MediaStreamClip&&r.audioTrack!=null){const e=n(this,I).createMediaStreamSource(new MediaStream([r.audioTrack]));e.connect(n(this,j)),n(this,it).set(t,e)}await n(this,M).addSprite(t),t.preFrame(0)});rt(this,"removeSprite",t=>{var r;(r=n(this,it).get(t))==null||r.disconnect(),n(this,M).removeSprite(t)});S(this,J,r),S(this,C,Yt(r));const e=n(this,C).getContext("2d",{alpha:!1});if(e==null)throw Error("canvas context is null");S(this,E,e);const o=G("div");o.style.cssText="width: 100%; height: 100%; position: relative; overflow: hidden;",o.appendChild(n(this,C)),t.appendChild(o),Bt(n(this,I)).connect(n(this,j)),S(this,M,new vt);const{rectCtrlsGetter:s,destroy:h}=St(n(this,C));n(this,tt).push(h,It(n(this,C),n(this,M),s),Ht(n(this,C),n(this,M),s),Tt(n(this,C),n(this,M),o,s),Ct(o,n(this,C),n(this,M),s),v.EventTool.forwardEvent(n(this,M),n(this,P),[ct.ActiveSpriteChange]));let a=n(this,X),c=performance.now(),l=0;const d=1e3/30;S(this,et,v.workerTimer(()=>{(performance.now()-c)/(d*l)<1||(l+=1,$(this,k,mt).call(this),a!==n(this,X)&&(a=n(this,X),n(this,P).emit("timeupdate",Math.round(a))))},d))}play(t){const r=n(this,M).getSprites({time:!1}).map(o=>o.time.offset+o.time.duration),e=t.end??(r.length>0?Math.max(...r):1/0);if(t.start>=e||t.start<0)throw Error(`Invalid time parameter, ${JSON.stringify({start:t.start,end:e})}`);$(this,k,ot).call(this,t.start),n(this,M).getSprites({time:!1}).forEach(o=>{const{offset:s,duration:h}=o.time,a=n(this,X)-s;o.preFrame(a>0&&a<h?a:0)}),n(this,W).start=t.start,n(this,W).end=e,n(this,W).step=(t.playbackRate??1)*(1e3/30)*1e3,n(this,I).resume(),n(this,W).audioPlayAt=0,n(this,P).emit("playing"),f.Log.info("AVCanvs play by:",n(this,W))}pause(){$(this,k,st).call(this)}previewFrame(t){$(this,k,ot).call(this,t),$(this,k,st).call(this)}captureImage(){return n(this,C).toDataURL()}get activeSprite(){return n(this,M).activeSprite}set activeSprite(t){n(this,M).activeSprite=t}destroy(){var t;n(this,K)||(S(this,K,!0),n(this,I).close(),n(this,j).disconnect(),n(this,P).destroy(),n(this,et).call(this),(t=n(this,C).parentElement)==null||t.remove(),n(this,tt).forEach(r=>r()),n(this,D).clear(),n(this,M).destroy())}captureStream(){n(this,I).state==="suspended"&&n(this,I).resume().catch(f.Log.error);const t=new MediaStream(n(this,C).captureStream().getTracks().concat(n(this,j).stream.getTracks()));return f.Log.info("AVCanvas.captureStream, tracks:",t.getTracks().map(r=>r.kind)),t}async createCombinator(t={}){f.Log.info("AVCanvas.createCombinator, opts:",t);const r=new f.Combinator({...n(this,J),...t}),e=n(this,M).getSprites({time:!1});if(e.length===0)throw Error("No sprite added");for(const o of e){const s=new f.OffscreenSprite(o.getClip());s.time={...o.time},o.copyStateTo(s),await r.addSprite(s)}return r}async setBackgroundImage(t,r={}){let e;if(typeof t=="string"){const s=await(await fetch(t)).blob();e=await createImageBitmap(s)}else t instanceof HTMLImageElement?e=await createImageBitmap(t):e=t;if(S(this,Y,e),S(this,z,{mode:r.mode||"cover",opacity:r.opacity!==void 0?r.opacity:1,blur:r.blur!==void 0?r.blur:0}),n(this,z).blur>0){const o=new OffscreenCanvas(e.width,e.height),s=o.getContext("2d");s?(s.filter=`blur(${n(this,z).blur}px)`,s.drawImage(e,0,0),S(this,A,await createImageBitmap(o))):S(this,A,e)}else S(this,A,e)}async updateBackgroundOptions(t={}){if(n(this,Y)&&(t.mode!==void 0&&(n(this,z).mode=t.mode),t.opacity!==void 0&&(n(this,z).opacity=t.opacity),t.blur!==void 0&&(n(this,z).blur=t.blur),t.blur!==void 0))if(n(this,z).blur>0){const r=new OffscreenCanvas(n(this,Y).width,n(this,Y).height),e=r.getContext("2d");e&&(e.filter=`blur(${n(this,z).blur}px)`,e.drawImage(n(this,Y),0,0),S(this,A,await createImageBitmap(r)))}else S(this,A,n(this,Y))}clearBackgroundImage(){S(this,A,null),S(this,Y,null)}refresh(){$(this,k,ot).call(this,n(this,X)),$(this,k,st).call(this)}setAnchor(t,r){const e=n(this,C).width,o=n(this,C).height,s=t>=0&&t<=1?t*e:t,h=r>=0&&r<=1?r*o:r;S(this,nt,{x:s,y:h}),$(this,k,mt).call(this)}}C=new WeakMap,M=new WeakMap,E=new WeakMap,K=new WeakMap,tt=new WeakMap,et=new WeakMap,P=new WeakMap,J=new WeakMap,z=new WeakMap,A=new WeakMap,Y=new WeakMap,nt=new WeakMap,X=new WeakMap,k=new WeakSet,ot=function(t){S(this,X,t),n(this,M).updateRenderTime(t)},st=function(){const t=n(this,W).step!==0;n(this,W).step=0,t&&(n(this,P).emit("paused"),n(this,I).suspend());for(const r of n(this,D))r.stop(),r.disconnect();n(this,D).clear()},I=new WeakMap,j=new WeakMap,D=new WeakMap,mt=function(){var c;const t=n(this,E);let r=n(this,X);const{start:e,end:o,step:s,audioPlayAt:h}=n(this,W);if(s!==0&&r>=e&&r<o?r+=s:$(this,k,st).call(this),$(this,k,ot).call(this,r),t.fillStyle=n(this,J).bgColor,t.fillRect(0,0,n(this,C).width,n(this,C).height),n(this,A)){const{width:l,height:d}=n(this,C),{mode:p,opacity:u}=n(this,z);switch(t.save(),u!==1&&(t.globalAlpha=u),p){case"cover":jt(t,n(this,A),0,0,l,d);break;case"contain":Dt(t,n(this,A),0,0,l,d);break;case"stretch":t.drawImage(n(this,A),0,0,l,d);break;case"repeat":const w=t.createPattern(n(this,A),"repeat");w&&(t.fillStyle=w,t.fillRect(0,0,l,d));break}t.restore()}const a=[];for(const l of n(this,M).getSprites()){t.save();const{audio:d}=l.render(t,r-l.time.offset,n(this,nt));t.restore(),a.push(d)}if(t.resetTransform(),s!==0){const l=Math.max(n(this,I).currentTime,h),d=Pt(a,n(this,I));let p=0;for(const u of d)u.start(l),u.connect(n(this,I).destination),u.connect(n(this,j)),n(this,D).add(u),u.onended=()=>{u.disconnect(),n(this,D).delete(u)},p=Math.max(p,((c=u.buffer)==null?void 0:c.duration)??0);n(this,W).audioPlayAt=l+p}},W=new WeakMap,it=new WeakMap;function Pt(i,t){const r=[];if(i.length===0)return r;for(const[e,o]of i){if(e==null||e.length<=0)continue;const s=t.createBuffer(2,e.length,$t.sampleRate);s.copyToChannel(e,0),s.copyToChannel(o??e,1);const h=t.createBufferSource();h.buffer=s,r.push(h)}return r}function Bt(i){const t=i.createOscillator(),r=new Float32Array([0,0]),e=new Float32Array([0,0]),o=i.createPeriodicWave(r,e,{disableNormalization:!0});return t.setPeriodicWave(o),t.start(),t}function jt(i,t,r,e,o,s){const h=t.width/t.height,a=o/s;let c=o,l=s,d=0,p=0;a>h?(l=o/t.width*t.height,p=(s-l)/2):(c=s/t.height*t.width,d=(o-c)/2),i.drawImage(t,r+d,e+p,c,l)}function Dt(i,t,r,e,o,s){const h=t.width/t.height,a=o/s;let c=o,l=s,d=0,p=0;a<h?(l=o/t.width*t.height,p=(s-l)/2):(c=s/t.height*t.width,d=(o-c)/2),i.drawImage(t,r+d,e+p,c,l)}m.AVCanvas=Xt,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=av-canvas.umd.cjs.map