/*! * artplayer-proxy-webav.js v1.0.0 * Github: https://github.com/zhw2590582/ArtPlayer * (c) 2017-2024 Harvey Zack * Released under the MIT License. */ !function(t,e,r,s,n){var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},o="function"==typeof a[s]&&a[s],h=o.cache||{},l="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function u(e,r){if(!h[e]){if(!t[e]){var n="function"==typeof a[s]&&a[s];if(!r&&n)return n(e,!0);if(o)return o(e,!0);if(l&&"string"==typeof e)return l(e);var d=Error("Cannot find module '"+e+"'");throw d.code="MODULE_NOT_FOUND",d}p.resolve=function(r){var s=t[e][1][r];return null!=s?s:r},p.cache={};var f=h[e]=new u.Module(e);t[e][0].call(f.exports,p,f,f.exports,this)}return h[e].exports;function p(t){var e=p.resolve(t);return!1===e?{}:u(e)}}u.isParcelRequire=!0,u.Module=function(t){this.id=t,this.bundle=u,this.exports={}},u.modules=t,u.cache=h,u.parent=o,u.register=function(e,r){t[e]=[function(t,e){e.exports=r},{}]},Object.defineProperty(u,"root",{get:function(){return a[s]}}),a[s]=u;for(var d=0;da);var n=t("@webav/av-cliper");function a(){return t=>{let e,r;let{option:s,constructor:a}=t,{createElement:o,def:h}=a.utils,l=o("canvas"),u=l.getContext("2d"),d=null,f=null,p=null,c=null,m=0,g={playing:!1,duration:0,videoWidth:0,videoHeight:0,currentTime:0,playbackRate:1,paused:!0,ended:!1,readyState:0,buffered:0,muted:s.muted,volume:s.volume,autoplay:s.autoplay};function y(){p&&(clearInterval(p),p=null),f&&(f.stop(),f=null)}function _(){if(r){let t=g.muted?0:g.volume;r.gain.setValueAtTime(t,e.currentTime)}}async function b(){e||(r=(e=new AudioContext).createGain()).connect(e.destination);let s=1e6*g.currentTime,n=0,a=!0,o=performance.now();async function h(){if(!g.playing)return;let h=performance.now(),l=h-o;o=h,null!==c?(s=1e6*c,c=null,a=!0):s+=1e3*l*g.playbackRate,g.currentTime=s/1e6;let{state:p,video:m,audio:_}=await d.tick(Math.round(s));if(t.emit("video:timeupdate",{type:"timeupdate"}),"done"===p){y(),g.ended=!0,g.playing=!1,g.paused=!0,t.emit("video:ended",{type:"ended"});return}if(m&&"success"===p&&(u.clearRect(0,0,g.videoWidth,g.videoHeight),u.drawImage(m,0,0,g.videoWidth,g.videoHeight),m.close()),a)a=!1;else if(_?.[0]?.length){let t=e.createBuffer(2,_[0].length,48e3);t.copyToChannel(_[0],0),t.copyToChannel(_[1],1),(f=e.createBufferSource()).buffer=t,f.connect(r),f.playbackRate.setValueAtTime(g.playbackRate,e.currentTime),n=Math.max(e.currentTime,n),f.start(n),n+=t.duration/g.playbackRate}}y(),_(),g.playing=!0,g.paused=!1,p=setInterval(h,1e3/60)}async function w(t){let{video:e}=await d.tick(1e6*t);e&&(u.clearRect(0,0,l.width,l.height),u.drawImage(e,0,0,l.width,l.height),e.close())}function v(){let e=t.template?.$player;if(!e||s.autoSize)return;let r=l.videoWidth/l.videoHeight,n=e.clientWidth,a=e.clientHeight,o=0,h=0;n/a>r?o=(n-a*r)/2:h=(a-n/r)/2,Object.assign(l.style,{padding:`${h}px ${o}px`})}async function S(){if(!await (0,n.Combinator).isSupported())throw t.notice.show="WebAV is not supported",Error("WebAV is not supported");y(),Object.assign(g,{playing:!1,duration:0,videoWidth:0,videoHeight:0,currentTime:0,playbackRate:1,paused:!0,ended:!1,readyState:0,buffered:0,muted:s.muted,volume:s.volume,autoplay:s.autoplay}),d&&(d.destroy(),t.emit("video:abort",{type:"abort"}),t.emit("video:emptied",{type:"emptied"}));try{await Promise.resolve(),t.emit("video:loadstart",{type:"loadstart"});let e=await fetch(s.url);if(!e.body)throw Error("No response body");d=new n.MP4Clip(e.body)}catch(e){throw t.emit("video:error",e),e}let e=await d.ready;Object.assign(g,{readyState:4,duration:Math.round(e.duration/1e6),videoWidth:e.width,videoHeight:e.height}),l.width=g.videoWidth,l.height=g.videoHeight,await w(.1),v(),t.emit("video:loadedmetadata",{type:"loadedmetadata"}),t.emit("video:durationchange",{type:"durationchange"}),t.emit("video:loadeddata",{type:"loadeddata"}),t.emit("video:canplay",{type:"canplay"}),t.emit("video:canplaythrough",{type:"canplaythrough"})}return h(l,"textTracks",{get:()=>[]}),h(l,"duration",{get:()=>g.duration}),h(l,"videoWidth",{get:()=>g.videoWidth}),h(l,"videoHeight",{get:()=>g.videoHeight}),h(l,"volume",{get:()=>g.volume,set:e=>{g.volume=Math.max(0,Math.min(1,e)),_(),t.emit("video:volumechange",{type:"volumechange"})}}),h(l,"currentTime",{get:()=>g.currentTime,set:e=>{let r=Math.max(0,Math.min(e,g.duration)),s=performance.now();s-m>16&&(m=s,c=r,g.currentTime=r,g.playing||w(r),t.emit("video:timeupdate",{type:"timeupdate"}))}}),h(l,"autoplay",{get:()=>g.autoplay,set:t=>{g.autoplay=t,t&&g.readyState>=4&&l.play()}}),h(l,"src",{get:()=>s.url,set:t=>{s.url=t,S().then(()=>{s.autoplay&&l.play()})}}),h(l,"playbackRate",{get:()=>g.playbackRate,set:r=>{g.playbackRate=Math.max(.25,Math.min(2,r)),f&&f.playbackRate.setValueAtTime(g.playbackRate,e.currentTime),t.emit("video:ratechange",{type:"ratechange"})}}),h(l,"playing",{get:()=>g.playing}),h(l,"paused",{get:()=>g.paused}),h(l,"ended",{get:()=>g.ended}),h(l,"readyState",{get:()=>g.readyState}),h(l,"muted",{get:()=>g.muted,set:e=>{g.muted=e,_(),t.emit("video:volumechange",{type:"volumechange"})}}),h(l,"buffered",{get:()=>({start:()=>0,end:()=>g.buffered,length:1})}),h(l,"play",{value:async()=>{await b(),t.emit("video:play",{type:"play"}),t.emit("video:playing",{type:"playing"})}}),h(l,"pause",{value:()=>{y(),g.playing=!1,g.paused=!0,t.emit("video:pause",{type:"pause"})}}),t.on("destroy",()=>{y(),d&&d.destroy()}),t.on("resize",v),l}}"undefined"!=typeof window&&(window.artplayerProxyWebAV=a)},{"@webav/av-cliper":"b01Rz","@parcel/transformer-js/src/esmodule-helpers.js":"9pCYc"}],b01Rz:[function(t,e,r){var s,n,a,o,h,l,u,d,f,p,c,m,g,y,_,b,w,v,S,E,U,x,T,A,C,I,B,k,F,R,P,z,L,D,M,O,N,G,Y,W,V,H,X,j,Z,$,K,q,Q,J,tt,te,ti,tr,ts,tn,ta,to,th,tl,tu,td,tf,tp,tc,tm,tg,ty,t_,tb,tw,tv,tS,tE,tU,tx,tT,tA,tC,tI,tB,tk,tF,tR,tP,tz,tL,tD,tM,tO,tN,tG,tY,tW,tV,tH,tX,tj,tZ,t$,tK,tq,tQ,tJ,t0,t1,t2,t3,t6,t8,t4,t5,t9,t7,et,ee,ei,er,es,en,ea,eo,eh,el,eu,ed=t("@parcel/transformer-js/src/esmodule-helpers.js");ed.defineInteropFlag(r),ed.export(r,"AudioClip",()=>iX),ed.export(r,"Combinator",()=>rB),ed.export(r,"DEFAULT_AUDIO_CONF",()=>iC),ed.export(r,"EmbedSubtitlesClip",()=>iQ),ed.export(r,"EventTool",()=>i0),ed.export(r,"ImgClip",()=>iV),ed.export(r,"Log",()=>e5),ed.export(r,"MP4Clip",()=>iz),ed.export(r,"MediaStreamClip",()=>iK),ed.export(r,"OffscreenSprite",()=>rT),ed.export(r,"Rect",()=>rE),ed.export(r,"VisibleSprite",()=>rA),ed.export(r,"adjustAudioDataVolume",()=>iy),ed.export(r,"audioResample",()=>iw),ed.export(r,"autoReadStream",()=>iE),ed.export(r,"concatAudioClip",()=>ij),ed.export(r,"concatFloat32Array",()=>ip),ed.export(r,"concatPCMFragments",()=>ic),ed.export(r,"createChromakey",()=>rv),ed.export(r,"createEl",()=>eE),ed.export(r,"createHLSLoader",()=>rm),ed.export(r,"decodeImg",()=>i_),ed.export(r,"extractPCM4AudioBuffer",()=>ig),ed.export(r,"extractPCM4AudioData",()=>im),ed.export(r,"fastConcatMP4",()=>rt),ed.export(r,"file2stream",()=>i9),ed.export(r,"fixFMP4Duration",()=>ri),ed.export(r,"mixinMP4AndAudio",()=>rr),ed.export(r,"mixinPCM",()=>ib),ed.export(r,"recodemux",()=>i4),ed.export(r,"renderTxt2Img",()=>eU),ed.export(r,"renderTxt2ImgBitmap",()=>ex),ed.export(r,"ringSliceFloat32Array",()=>iS),ed.export(r,"workerTimer",()=>is);var ef=arguments[3],ep=t("718a311db185ef08").Buffer,ec=Object.defineProperty,em=t=>{throw TypeError(t)},eg=(t,e,r)=>e in t?ec(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ey=(t,e,r)=>eg(t,"symbol"!=typeof e?e+"":e,r),e_=(t,e,r)=>e.has(t)||em("Cannot "+r),eb=(t,e,r)=>(e_(t,e,"read from private field"),r?r.call(t):e.get(t)),ew=(t,e,r)=>e.has(t)?em("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),ev=(t,e,r,s)=>(e_(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r),eS=(t,e,r)=>(e_(t,e,"access private method"),r);function eE(t){return document.createElement(t)}function eU(t,e){let r=eE("pre");r.style.cssText=`margin: 0; ${e}; visibility: hidden; position: fixed;`,r.textContent=t,document.body.appendChild(r);let{width:s,height:n}=r.getBoundingClientRect();r.remove(),r.style.visibility="visible";let a=new Image;a.width=s,a.height=n;let o=`
${r.outerHTML}
`.replace(/\t/g,"").replace(/#/g,"%23");return a.src=`data:image/svg+xml;charset=utf-8,${o}`,a}async function ex(t,e){let r=eU(t,e);await new Promise(t=>{r.onload=t});let s=new OffscreenCanvas(r.width,r.height),n=s.getContext("2d");return null==n||n.drawImage(r,0,0,r.width,r.height),await createImageBitmap(s)}var eT=t=>{throw TypeError(t)},eA=(t,e,r)=>e.has(t)||eT("Cannot "+r),eC=(t,e,r)=>(eA(t,e,"read from private field"),r?r.call(t):e.get(t)),eI=(t,e,r)=>e.has(t)?eT("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),eB=(t,e,r,s)=>(eA(t,e,"write to private field"),e.set(t,r),r);let ek="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIHUobil7aWYobj09PSIvIilyZXR1cm57cGFyZW50Om51bGwsbmFtZToiIn07Y29uc3QgZT1uLnNwbGl0KCIvIikuZmlsdGVyKGk9PmkubGVuZ3RoPjApO2lmKGUubGVuZ3RoPT09MCl0aHJvdyBFcnJvcigiSW52YWxpZCBwYXRoIik7Y29uc3QgYT1lW2UubGVuZ3RoLTFdLHI9Ii8iK2Uuc2xpY2UoMCwtMSkuam9pbigiLyIpO3JldHVybntuYW1lOmEscGFyZW50OnJ9fWFzeW5jIGZ1bmN0aW9uIHcobixlKXtjb25zdHtwYXJlbnQ6YSxuYW1lOnJ9PXUobik7aWYoYT09bnVsbClyZXR1cm4gYXdhaXQgbmF2aWdhdG9yLnN0b3JhZ2UuZ2V0RGlyZWN0b3J5KCk7Y29uc3QgaT1hLnNwbGl0KCIvIikuZmlsdGVyKHQ9PnQubGVuZ3RoPjApO3RyeXtsZXQgdD1hd2FpdCBuYXZpZ2F0b3Iuc3RvcmFnZS5nZXREaXJlY3RvcnkoKTtmb3IoY29uc3QgcyBvZiBpKXQ9YXdhaXQgdC5nZXREaXJlY3RvcnlIYW5kbGUocyx7Y3JlYXRlOmUuY3JlYXRlfSk7aWYoZS5pc0ZpbGUpcmV0dXJuIGF3YWl0IHQuZ2V0RmlsZUhhbmRsZShyLHtjcmVhdGU6ZS5jcmVhdGV9KX1jYXRjaCh0KXtpZih0Lm5hbWU9PT0iTm90Rm91bmRFcnJvciIpcmV0dXJuIG51bGw7dGhyb3cgdH19Y29uc3QgZj17fTtzZWxmLm9ubWVzc2FnZT1hc3luYyBuPT57dmFyIGk7Y29uc3R7ZXZ0VHlwZTplLGFyZ3M6YX09bi5kYXRhO2xldCByPWZbYS5maWxlSWRdO3RyeXtsZXQgdDtjb25zdCBzPVtdO2lmKGU9PT0icmVnaXN0ZXIiKXtjb25zdCBsPWF3YWl0IHcoYS5maWxlUGF0aCx7Y3JlYXRlOiEwLGlzRmlsZTohMH0pO2lmKGw9PW51bGwpdGhyb3cgRXJyb3IoYG5vdCBmb3VuZCBmaWxlOiAke2EuZmlsZUlkfWApO3I9YXdhaXQgbC5jcmVhdGVTeW5jQWNjZXNzSGFuZGxlKHttb2RlOmEubW9kZX0pLGZbYS5maWxlSWRdPXJ9ZWxzZSBpZihlPT09ImNsb3NlIilhd2FpdCByLmNsb3NlKCksZGVsZXRlIGZbYS5maWxlSWRdO2Vsc2UgaWYoZT09PSJ0cnVuY2F0ZSIpYXdhaXQgci50cnVuY2F0ZShhLm5ld1NpemUpO2Vsc2UgaWYoZT09PSJ3cml0ZSIpe2NvbnN0e2RhdGE6bCxvcHRzOm99PW4uZGF0YS5hcmdzO3Q9YXdhaXQgci53cml0ZShsLG8pfWVsc2UgaWYoZT09PSJyZWFkIil7Y29uc3R7b2Zmc2V0Omwsc2l6ZTpvfT1uLmRhdGEuYXJncyxnPW5ldyBVaW50OEFycmF5KG8pLGQ9YXdhaXQgci5yZWFkKGcse2F0Omx9KSxjPWcuYnVmZmVyO3Q9ZD09PW8/YzooKGk9Yy50cmFuc2Zlcik9PW51bGw/dm9pZCAwOmkuY2FsbChjLGQpKT8/Yy5zbGljZSgwLGQpLHMucHVzaCh0KX1lbHNlIGU9PT0iZ2V0U2l6ZSI/dD1hd2FpdCByLmdldFNpemUoKTplPT09ImZsdXNoIiYmYXdhaXQgci5mbHVzaCgpO3NlbGYucG9zdE1lc3NhZ2Uoe2V2dFR5cGU6ImNhbGxiYWNrIixjYklkOm4uZGF0YS5jYklkLHJldHVyblZhbDp0fSxzKX1jYXRjaCh0KXtjb25zdCBzPXQ7c2VsZi5wb3N0TWVzc2FnZSh7ZXZ0VHlwZToidGhyb3dFcnJvciIsY2JJZDpuLmRhdGEuY2JJZCxlcnJNc2c6cy5uYW1lKyI6ICIrcy5tZXNzYWdlK2AKYCtKU09OLnN0cmluZ2lmeShuLmRhdGEpfSl9fX0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPW9wZnMtd29ya2VyLUY0UldscWNfLmpzLm1hcAo=",eF="u">typeof self&&self.Blob&&new Blob([Uint8Array.from(atob(ek),t=>t.charCodeAt(0))],{type:"text/javascript;charset=utf-8"});function eR(t){let e;try{if(!(e=eF&&(self.URL||self.webkitURL).createObjectURL(eF)))throw"";let r=new Worker(e,{name:null==t?void 0:t.name});return r.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),r}catch{return new Worker("data:text/javascript;base64,"+ek,{name:null==t?void 0:t.name})}finally{e&&(self.URL||self.webkitURL).revokeObjectURL(e)}}async function eP(t,e,r){let s=function(){if(ez.length<3){let t=function(){let t=new eR,e=0,r={};return t.onmessage=({data:t})=>{var e,s;"callback"===t.evtType?null==(e=r[t.cbId])||e.resolve(t.returnVal):"throwError"===t.evtType&&(null==(s=r[t.cbId])||s.reject(Error(t.errMsg))),delete r[t.cbId]},async function(s,n,a=[]){e+=1;let o=new Promise((t,s)=>{r[e]={resolve:t,reject:s}});return t.postMessage({cbId:e,evtType:s,args:n},a),o}}();return ez.push(t),t}{let t=ez[eL];return eL=(eL+1)%ez.length,t}}();return await s("register",{fileId:t,filePath:e,mode:r}),{read:async(e,r)=>await s("read",{fileId:t,offset:e,size:r}),write:async(e,r)=>await s("write",{fileId:t,data:e,opts:r},[ArrayBuffer.isView(e)?e.buffer:e]),close:async()=>await s("close",{fileId:t}),truncate:async e=>await s("truncate",{fileId:t,newSize:e}),getSize:async()=>await s("getSize",{fileId:t}),flush:async()=>await s("flush",{fileId:t})}}let ez=[],eL=0;function eD(t){if("/"===t)return{parent:null,name:""};let e=t.split("/").filter(t=>t.length>0);if(0===e.length)throw Error("Invalid path");return{name:e[e.length-1],parent:"/"+e.slice(0,-1).join("/")}}async function eM(t,e){let{parent:r,name:s}=eD(t);if(null==r)return await navigator.storage.getDirectory();let n=r.split("/").filter(t=>t.length>0);try{let t=await navigator.storage.getDirectory();for(let r of n)t=await t.getDirectoryHandle(r,{create:e.create});return e.isFile?await t.getFileHandle(s,{create:e.create}):await t.getDirectoryHandle(s,{create:e.create})}catch(t){if("NotFoundError"===t.name)return null;throw t}}async function eO(t){let{parent:e,name:r}=eD(t);if(null==e){let t=await navigator.storage.getDirectory();for await(let e of t.keys())await t.removeEntry(e,{recursive:!0});return}let s=await eM(e,{create:!1,isFile:!1});null!=s&&await s.removeEntry(r,{recursive:!0})}function eN(t,e){return`${t}/${e}`.replace("//","/")}function eG(t){return new eY(t)}class eY{constructor(t){eI(this,g),eI(this,y),eI(this,_),eB(this,g,t);let{parent:e,name:r}=eD(t);eB(this,y,r),eB(this,_,e)}get kind(){return"dir"}get name(){return eC(this,y)}get path(){return eC(this,g)}get parent(){return null==eC(this,_)?null:eG(eC(this,_))}async create(){return await eM(eC(this,g),{create:!0,isFile:!1}),eG(eC(this,g))}async exists(){return await eM(eC(this,g),{create:!1,isFile:!1}) instanceof FileSystemDirectoryHandle}async remove(){for(let t of(await this.children()))try{await t.remove()}catch(t){console.warn(t)}try{await eO(eC(this,g))}catch(t){console.warn(t)}}async children(){let t=await eM(eC(this,g),{create:!1,isFile:!1});if(null==t)return[];let e=[];for await(let r of t.values())e.push(("file"===r.kind?eV:eG)(eN(eC(this,g),r.name)));return e}async copyTo(t){if(!await this.exists())throw Error(`dir ${this.path} not exists`);let e=await t.exists()?eG(eN(t.path,this.name)):t;return await e.create(),await Promise.all((await this.children()).map(t=>t.copyTo(e))),e}async moveTo(t){let e=await this.copyTo(t);return await this.remove(),e}}g=/* @__PURE__ */new WeakMap,y=/* @__PURE__ */new WeakMap,_=/* @__PURE__ */new WeakMap;let eW=/* @__PURE__ */new Map;function eV(t,e="rw"){if("rw"===e){let r=eW.get(t)??new e$(t,e);return eW.set(t,r),r}return new e$(t,e)}async function eH(t,e,r={overwrite:!0}){if(e instanceof e$){await eH(t,await e.stream(),r);return}let s=await (t instanceof e$?t:eV(t,"rw")).createWriter();try{if(r.overwrite&&await s.truncate(0),e instanceof ReadableStream){let t=e.getReader();for(;;){let{done:e,value:r}=await t.read();if(e)break;await s.write(r)}}else await s.write(e)}catch(t){throw t}finally{await s.close()}}let eX=0,ej=()=>++eX,eZ=class t{constructor(t,e){eI(this,b),eI(this,w),eI(this,v),eI(this,S),eI(this,E),eI(this,U,0),eI(this,x,/* @__PURE__ */(()=>{let t=null;return()=>(eB(this,U,eC(this,U)+1),t??(t=new Promise(async(e,r)=>{try{let r=await eP(eC(this,E),eC(this,b),eC(this,S));e([r,async()=>{eB(this,U,eC(this,U)-1),eC(this,U)>0||(t=null,await r.close())}])}catch(t){r(t)}})))})()),eI(this,T,!1),eB(this,E,ej()),eB(this,b,t),eB(this,S,{r:"read-only",rw:"readwrite","rw-unsafe":"readwrite-unsafe"}[e]);let{parent:r,name:s}=eD(t);eB(this,v,s),eB(this,w,r)}get kind(){return"file"}get path(){return eC(this,b)}get name(){return eC(this,v)}get parent(){return null==eC(this,w)?null:eG(eC(this,w))}async createWriter(){if("read-only"===eC(this,S))throw Error("file is read-only");if(eC(this,T))throw Error("Other writer have not been closed");eB(this,T,!0);let t=new TextEncoder,[e,r]=await eC(this,x).call(this),s=await e.getSize(),n=!1;return{write:async(r,a={})=>{if(n)throw Error("Writer is closed");let o="string"==typeof r?t.encode(r):r,h=a.at??s;return s=h+o.byteLength,await e.write(o,{at:h})},truncate:async t=>{if(n)throw Error("Writer is closed");await e.truncate(t),s>t&&(s=t)},flush:async()=>{if(n)throw Error("Writer is closed");await e.flush()},close:async()=>{if(n)throw Error("Writer is closed");n=!0,eB(this,T,!1),await r()}}}async createReader(){let[t,e]=await eC(this,x).call(this),r=!1,s=0;return{read:async(e,n={})=>{if(r)throw Error("Reader is closed");let a=n.at??s,o=await t.read(a,e);return s=a+o.byteLength,o},getSize:async()=>{if(r)throw Error("Reader is closed");return await t.getSize()},close:async()=>{r||(r=!0,await e())}}}async text(){return new TextDecoder().decode(await this.arrayBuffer())}async arrayBuffer(){let t=await eM(eC(this,b),{create:!1,isFile:!0});return null==t?new ArrayBuffer(0):(await t.getFile()).arrayBuffer()}async stream(){let t=await this.getOriginFile();return null==t?new ReadableStream({pull:t=>{t.close()}}):t.stream()}async getOriginFile(){var t;return null==(t=await eM(eC(this,b),{create:!1,isFile:!0}))?void 0:t.getFile()}async getSize(){let t=await eM(eC(this,b),{create:!1,isFile:!0});return null==t?0:(await t.getFile()).size}async exists(){return await eM(eC(this,b),{create:!1,isFile:!0}) instanceof FileSystemFileHandle}async remove(){if(eC(this,U))throw Error("exists unclosed reader/writer");await eO(eC(this,b))}async copyTo(e){if(!await this.exists())throw Error(`file ${this.path} not exists`);if(e instanceof t)return eV(e.path)===this?this:(await eH(e.path,this),eV(e.path));if(e instanceof eY)return await this.copyTo(eV(eN(e.path,this.name)));throw Error("Illegal target type")}async moveTo(t){let e=await this.copyTo(t);return await this.remove(),e}};b=/* @__PURE__ */new WeakMap,w=/* @__PURE__ */new WeakMap,v=/* @__PURE__ */new WeakMap,S=/* @__PURE__ */new WeakMap,E=/* @__PURE__ */new WeakMap,U=/* @__PURE__ */new WeakMap,x=/* @__PURE__ */new WeakMap,T=/* @__PURE__ */new WeakMap;let e$=eZ,eK="/.opfs-tools-temp-dir";async function eq(t){try{if("file"===t.kind){if(!await t.exists())return!0;let e=await t.createWriter();await e.truncate(0),await e.close(),await t.remove()}else await t.remove();return!0}catch(t){return console.warn(t),!1}}let eQ=[],eJ=!1;async function e0(){if(null==globalThis.localStorage)return;let t="OPFS_TOOLS_EXPIRES_TMP_FILES";eJ||(eJ=!0,globalThis.addEventListener("unload",()=>{0!==eQ.length&&localStorage.setItem(t,`${localStorage.getItem(t)??""},${eQ.join(",")}`)}));let e=localStorage.getItem(t)??"";for(let t of e.split(","))0!==t.length&&await eq(eV(`${eK}/${t}`))&&(e=e.replace(t,""));localStorage.setItem(t,e.replace(/,{2,}/g,","))}function e1(){let t=`${Math.random().toString().slice(2)}-${Date.now()}`;return eQ.push(t),eV(`${eK}/${t}`)}!async function(){var t;!0===globalThis.__opfs_tools_tmpfile_init__||(globalThis.__opfs_tools_tmpfile_init__=!0,null==globalThis.FileSystemDirectoryHandle||null==globalThis.FileSystemFileHandle||(null==(t=globalThis.navigator)?void 0:t.storage.getDirectory)==null||(setInterval(async()=>{for(let t of(await eG(eK).children())){let e=/^\d+-(\d+)$/.exec(t.name);(null==e||Date.now()-Number(e[1])>2592e5)&&await eq(t)}},6e4),await e0()))}();let e2=1,e3=e1(),e6=null,e8=["debug","info","warn","error"].reduce((t,e,r)=>Object.assign(t,{[e]:(...t)=>{e2<=r&&(console[e](...t),null==e6||e6.write(`[${e}][${function(){let t=/* @__PURE__ */new Date;return`${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}.${t.getMilliseconds()}`}()}] ${t.map(t=>t instanceof Error?String(t):"object"==typeof t?JSON.stringify(t,(t,e)=>e instanceof Error?String(e):e):String(t)).join(" ")} `))}}),{}),e4=/* @__PURE__ */new Map,e5={setLogLevel:t=>{e2=e4.get(t)??1},...e8,create:t=>Object.fromEntries(Object.entries(e8).map(([e,r])=>[e,(...e)=>r(t,...e)])),dump:async()=>(await e7,await (null==e6?void 0:e6.flush()),await e3.text())};async function e9(){try{e6=await e3.createWriter(),e5.info(navigator.userAgent),e5.info("date: "+/* @__PURE__ */new Date().toLocaleDateString())}catch(t){if(!(t instanceof Error))throw t;if(t.message.includes("createSyncAccessHandle is not a function"))console.warn(t);else throw t}}e4.set(e5.debug,0),e4.set(e5.info,1),e4.set(e5.warn,2),e4.set(e5.error,3);let e7=null==globalThis.navigator?null:e9(),it=()=>{let t;self.onmessage=e=>{"start"===e.data.event&&(self.clearInterval(t),t=self.setInterval(()=>{self.postMessage({})},16.6)),"stop"===e.data.event&&self.clearInterval(t)}},ie=/* @__PURE__ */new Map,ii=1,ir=null;null!=globalThis.Worker&&((ir=(()=>{let t=new Blob([`(${it.toString()})()`]);return new Worker(URL.createObjectURL(t))})()).onmessage=()=>{for(let[t,e]of(ii+=1,ie))if(ii%t==0)for(let t of e)t()});let is=(t,e)=>{let r=Math.round(e/16.6),s=ie.get(r)??/* @__PURE__ */new Set;return s.add(t),ie.set(r,s),1===ie.size&&1===s.size&&(null==ir||ir.postMessage({event:"start"})),()=>{s.delete(t),0===s.size&&ie.delete(r),0===ie.size&&(ii=0,null==ir||ir.postMessage({event:"stop"}))}};class ia{constructor(t,e,r){var s;this.length_=t,this.scaleFactor_=(t-1)/e,this.interpolate=this.cubic,"point"===r.method?this.interpolate=this.point:"linear"===r.method?this.interpolate=this.linear:"sinc"===r.method&&(this.interpolate=this.sinc),this.tangentFactor_=1-Math.max(0,Math.min(1,r.tension||0)),this.sincFilterSize_=r.sincFilterSize||1,this.kernel_=(s=r.sincWindow||io,function(t){return(0===t?1:Math.sin(Math.PI*t)/(Math.PI*t))*s(t)})}point(t,e){return this.getClippedInput_(Math.round(this.scaleFactor_*t),e)}linear(t,e){let r=Math.floor(t=this.scaleFactor_*t);return(1-(t-=r))*this.getClippedInput_(r,e)+t*this.getClippedInput_(r+1,e)}cubic(t,e){let r=Math.floor(t=this.scaleFactor_*t),s=[this.getTangent_(r,e),this.getTangent_(r+1,e)],n=[this.getClippedInput_(r,e),this.getClippedInput_(r+1,e)],a=(t-=r)*t,o=t*a;return(2*o-3*a+1)*n[0]+(o-2*a+t)*s[0]+(-2*o+3*a)*n[1]+(o-a)*s[1]}sinc(t,e){let r=Math.floor(t=this.scaleFactor_*t),s=r-this.sincFilterSize_+1,n=r+this.sincFilterSize_,a=0;for(let r=s;r<=n;r++)a+=this.kernel_(t-r)*this.getClippedInput_(r,e);return a}getTangent_(t,e){return this.tangentFactor_*(this.getClippedInput_(t+1,e)-this.getClippedInput_(t-1,e))/2}getClippedInput_(t,e){return 0<=t&&tt.length).reduce((t,e)=>t+e)),r=0;for(let s of t)e.set(s,r),r+=s.length;return e}function ic(t){let e=[];for(let r=0;rnew Float32Array(r));for(let n=0;nt.getChannelData(r))}function iy(t,e){let r=new Float32Array(ip(im(t))).map(t=>t*e),s=new AudioData({sampleRate:t.sampleRate,numberOfChannels:t.numberOfChannels,timestamp:t.timestamp,format:t.format,numberOfFrames:t.numberOfFrames,data:r});return t.close(),s}async function i_(t,e){var r;let s=new ImageDecoder({type:e,data:t});await Promise.all([s.completed,s.tracks.ready]);let n=(null==(r=s.tracks.selectedTrack)?void 0:r.frameCount)??1,a=[];for(let t=0;t{var e;return(null==(e=t[0])?void 0:e.length)??0})),n=new Float32Array(2*s);for(let a=0;anew Float32Array(0));if(0===s)return n;let a=Math.max(...t.map(t=>t.length));if(0===a)return n;if(null==globalThis.OfflineAudioContext)return t.map(t=>new Float32Array(function(t,e,r,s={}){let n=(r-e)/e+1,a=new Float64Array(t.length*n);s.method=s.method||"cubic";let o=new ia(t.length,a.length,{method:s.method,tension:s.tension||0,sincFilterSize:s.sincFilterSize||6,sincWindow:s.sincWindow||void 0});if(void 0===s.LPF&&(s.LPF=ih[s.method]),s.LPF){s.LPFType=s.LPFType||"IIR";let n=iu[s.LPFType];r>e?function(t,e,r,s){for(let n=0,a=e.length;n=0;t--)e[t]=s.filter(e[t])}(t,a,o,new n(s.LPFOrder||il[s.LPFType],r,e/2)):function(t,e,r,s){for(let e=0,r=t.length;e=0;e--)t[e]=s.filter(t[e]);id(t,e,r)}(t,a,o,new n(s.LPFOrder||il[s.LPFType],e,r/2))}else id(t,a,o);return a}(t,e,r.rate,{method:"sinc",LPF:!1})));let o=new globalThis.OfflineAudioContext(r.chanCount,a*r.rate/e,r.rate),h=o.createBufferSource(),l=o.createBuffer(s,a,e);return t.forEach((t,e)=>l.copyToChannel(t,e)),h.buffer=l,h.connect(o.destination),h.start(),ig(await o.startRendering())}function iv(t){return new Promise(e=>{let r=is(()=>{r(),e()},t)})}function iS(t,e,r){let s=r-e,n=new Float32Array(s),a=0;for(;a{r=!0}}var iU="u">typeof globalThis?globalThis:"u">typeof window?window:"u">typeof ef?ef:"u">typeof self?self:{};function ix(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var iT={};(s=/* @__PURE__ */new Date,n=4,a={setLogLevel:function(t){t==this.debug?n=1:t==this.info?n=2:t==this.warn?n=3:(this.error,n=4)},debug:function(t,e){void 0===console.debug&&(console.debug=console.log),1>=n&&console.debug("["+a.getDurationString(/* @__PURE__ */new Date-s,1e3)+"]","["+t+"]",e)},log:function(t,e){this.debug(t.msg)},info:function(t,e){2>=n&&console.info("["+a.getDurationString(/* @__PURE__ */new Date-s,1e3)+"]","["+t+"]",e)},warn:function(t,e){3>=n&&console.warn("["+a.getDurationString(/* @__PURE__ */new Date-s,1e3)+"]","["+t+"]",e)},error:function(t,e){4>=n&&console.error("["+a.getDurationString(/* @__PURE__ */new Date-s,1e3)+"]","["+t+"]",e)}}).getDurationString=function(t,e){function r(t,e){for(var r=(""+t).split(".");r[0].length0))return"(empty)";for(var r="",s=0;s0&&(r+=","),r+="["+a.getDurationString(t.start(s))+","+a.getDurationString(t.end(s))+"]";return r},iT.Log=a,(o=function(t){if(t instanceof ArrayBuffer)this.buffer=t,this.dataview=new DataView(t);else throw"Needs an array buffer";this.position=0}).prototype.getPosition=function(){return this.position},o.prototype.getEndPosition=function(){return this.buffer.byteLength},o.prototype.getLength=function(){return this.buffer.byteLength},o.prototype.seek=function(t){var e=Math.max(0,Math.min(this.buffer.byteLength,t));return this.position=isNaN(e)||!isFinite(e)?0:e,!0},o.prototype.isEos=function(){return this.getPosition()>=this.getEndPosition()},o.prototype.readAnyInt=function(t,e){var r=0;if(this.position+t<=this.buffer.byteLength){switch(t){case 1:r=e?this.dataview.getInt8(this.position):this.dataview.getUint8(this.position);break;case 2:r=e?this.dataview.getInt16(this.position):this.dataview.getUint16(this.position);break;case 3:if(e)throw"No method for reading signed 24 bits values";r=this.dataview.getUint8(this.position)<<16|this.dataview.getUint8(this.position+1)<<8|this.dataview.getUint8(this.position+2);break;case 4:r=e?this.dataview.getInt32(this.position):this.dataview.getUint32(this.position);break;case 8:if(e)throw"No method for reading signed 64 bits values";r=this.dataview.getUint32(this.position)<<32|this.dataview.getUint32(this.position+4);break;default:throw"readInt method not implemented for size: "+t}return this.position+=t,r}throw"Not enough bytes in buffer"},o.prototype.readUint8=function(){return this.readAnyInt(1,!1)},o.prototype.readUint16=function(){return this.readAnyInt(2,!1)},o.prototype.readUint24=function(){return this.readAnyInt(3,!1)},o.prototype.readUint32=function(){return this.readAnyInt(4,!1)},o.prototype.readUint64=function(){return this.readAnyInt(8,!1)},o.prototype.readString=function(t){if(this.position+t<=this.buffer.byteLength){for(var e="",r=0;rthis._byteLength&&(this._byteLength=e);return}for(r<1&&(r=1);e>r;)r*=2;var s=new ArrayBuffer(r),n=new Uint8Array(this._buffer);new Uint8Array(s,0,n.length).set(n),this.buffer=s,this._byteLength=e}},h.prototype._trimAlloc=function(){if(this._byteLength!=this._buffer.byteLength){var t=new ArrayBuffer(this._byteLength),e=new Uint8Array(t),r=new Uint8Array(this._buffer,0,e.length);e.set(r),this.buffer=t}},h.BIG_ENDIAN=!1,h.LITTLE_ENDIAN=!0,h.prototype._byteLength=0,Object.defineProperty(h.prototype,"byteLength",{get:function(){return this._byteLength-this._byteOffset}}),Object.defineProperty(h.prototype,"buffer",{get:function(){return this._trimAlloc(),this._buffer},set:function(t){this._buffer=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(h.prototype,"byteOffset",{get:function(){return this._byteOffset},set:function(t){this._byteOffset=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(h.prototype,"dataView",{get:function(){return this._dataView},set:function(t){this._byteOffset=t.byteOffset,this._buffer=t.buffer,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._byteOffset+t.byteLength}}),h.prototype.seek=function(t){var e=Math.max(0,Math.min(this.byteLength,t));this.position=isNaN(e)||!isFinite(e)?0:e},h.prototype.isEof=function(){return this.position>=this._byteLength},h.prototype.mapUint8Array=function(t){this._realloc(1*t);var e=new Uint8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=1*t,e},h.prototype.readInt32Array=function(t,e){var r=new Int32Array(t=t??this.byteLength-this.position/4);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readInt16Array=function(t,e){var r=new Int16Array(t=t??this.byteLength-this.position/2);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readInt8Array=function(t){var e=new Int8Array(t=t??this.byteLength-this.position);return h.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},h.prototype.readUint32Array=function(t,e){var r=new Uint32Array(t=t??this.byteLength-this.position/4);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readUint16Array=function(t,e){var r=new Uint16Array(t=t??this.byteLength-this.position/2);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readUint8Array=function(t){var e=new Uint8Array(t=t??this.byteLength-this.position);return h.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},h.prototype.readFloat64Array=function(t,e){var r=new Float64Array(t=t??this.byteLength-this.position/8);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readFloat32Array=function(t,e){var r=new Float32Array(t=t??this.byteLength-this.position/4);return h.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),h.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},h.prototype.readInt32=function(t){var e=this._dataView.getInt32(this.position,t??this.endianness);return this.position+=4,e},h.prototype.readInt16=function(t){var e=this._dataView.getInt16(this.position,t??this.endianness);return this.position+=2,e},h.prototype.readInt8=function(){var t=this._dataView.getInt8(this.position);return this.position+=1,t},h.prototype.readUint32=function(t){var e=this._dataView.getUint32(this.position,t??this.endianness);return this.position+=4,e},h.prototype.readUint16=function(t){var e=this._dataView.getUint16(this.position,t??this.endianness);return this.position+=2,e},h.prototype.readUint8=function(){var t=this._dataView.getUint8(this.position);return this.position+=1,t},h.prototype.readFloat32=function(t){var e=this._dataView.getFloat32(this.position,t??this.endianness);return this.position+=4,e},h.prototype.readFloat64=function(t){var e=this._dataView.getFloat64(this.position,t??this.endianness);return this.position+=8,e},h.endianness=new Int8Array(new Int16Array([1]).buffer)[0]>0,h.memcpy=function(t,e,r,s,n){var a=new Uint8Array(t,e,n),o=new Uint8Array(r,s,n);a.set(o)},h.arrayToNative=function(t,e){return e==this.endianness?t:this.flipArrayEndianness(t)},h.nativeToEndian=function(t,e){return this.endianness==e?t:this.flipArrayEndianness(t)},h.flipArrayEndianness=function(t){for(var e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),r=0;rn;s--,n++){var a=e[n];e[n]=e[s],e[s]=a}return t},h.prototype.failurePosition=0,String.fromCharCodeUint8=function(t){for(var e=[],r=0;r>16),this.writeUint8((65280&t)>>8),this.writeUint8(255&t)},h.prototype.adjustUint32=function(t,e){var r=this.position;this.seek(t),this.writeUint32(e),this.seek(r)},h.prototype.mapInt32Array=function(t,e){this._realloc(4*t);var r=new Int32Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=4*t,r},h.prototype.mapInt16Array=function(t,e){this._realloc(2*t);var r=new Int16Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=2*t,r},h.prototype.mapInt8Array=function(t){this._realloc(1*t);var e=new Int8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=1*t,e},h.prototype.mapUint32Array=function(t,e){this._realloc(4*t);var r=new Uint32Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=4*t,r},h.prototype.mapUint16Array=function(t,e){this._realloc(2*t);var r=new Uint16Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=2*t,r},h.prototype.mapFloat64Array=function(t,e){this._realloc(8*t);var r=new Float64Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=8*t,r},h.prototype.mapFloat32Array=function(t,e){this._realloc(4*t);var r=new Float32Array(this._buffer,this.byteOffset+this.position,t);return h.arrayToNative(r,e??this.endianness),this.position+=4*t,r},(l=function(t){this.buffers=[],this.bufferIndex=-1,t&&(this.insertBuffer(t),this.bufferIndex=0)}).prototype=new h(new ArrayBuffer,0,h.BIG_ENDIAN),l.prototype.initialized=function(){var t;return this.bufferIndex>-1||(this.buffers.length>0?0===(t=this.buffers[0]).fileStart?(this.buffer=t,this.bufferIndex=0,a.debug("MultiBufferStream","Stream ready for parsing"),!0):(a.warn("MultiBufferStream","The first buffer should have a fileStart of 0"),this.logBufferLevel(),!1):(a.warn("MultiBufferStream","No buffer to start parsing from"),this.logBufferLevel(),!1))},ArrayBuffer.concat=function(t,e){a.debug("ArrayBuffer","Trying to create a new buffer of size: "+(t.byteLength+e.byteLength));var r=new Uint8Array(t.byteLength+e.byteLength);return r.set(new Uint8Array(t),0),r.set(new Uint8Array(e),t.byteLength),r.buffer},l.prototype.reduceBuffer=function(t,e,r){var s;return(s=new Uint8Array(r)).set(new Uint8Array(t,e,r)),s.buffer.fileStart=t.fileStart+e,s.buffer.usedBytes=0,s.buffer},l.prototype.insertBuffer=function(t){for(var e=!0,r=0;rs.byteLength){this.buffers.splice(r,1),r--;continue}a.warn("MultiBufferStream","Buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+") already appended, ignoring")}else t.fileStart+t.byteLength<=s.fileStart||(t=this.reduceBuffer(t,0,s.fileStart-t.fileStart)),a.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.splice(r,0,t),0===r&&(this.buffer=t);e=!1;break}if(t.fileStart0)t=this.reduceBuffer(t,n,o);else{e=!1;break}}}e&&(a.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.push(t),0===r&&(this.buffer=t))},l.prototype.logBufferLevel=function(t){var e,r,s,n,o,h=[],l="";for(s=0,n=0,e=0;e0&&(l+=o.end-1+"]"),(t?a.info:a.debug)("MultiBufferStream",0===this.buffers.length?"No more buffer in memory":""+this.buffers.length+" stored buffer(s) ("+s+"/"+n+" bytes), continuous ranges: "+l)},l.prototype.cleanBuffers=function(){var t,e;for(t=0;t"+this.buffer.byteLength+")"),!0},l.prototype.findPosition=function(t,e,r){var s,n=null,o=-1;for(s=!0===t?0:this.bufferIndex;s=e?(a.debug("MultiBufferStream","Found position in existing buffer #"+o),o):-1},l.prototype.findEndContiguousBuf=function(t){var e,r,s,n=void 0!==t?t:this.bufferIndex;if(r=this.buffers[n],this.buffers.length>n+1)for(e=n+1;e>3;return 31===s&&r.data.length>=2&&(s=32+((7&r.data[0])<<3)+((224&r.data[1])>>5)),s},r.DecoderConfigDescriptor=function(t){r.Descriptor.call(this,4,t)},r.DecoderConfigDescriptor.prototype=new r.Descriptor,r.DecoderConfigDescriptor.prototype.parse=function(t){this.oti=t.readUint8(),this.streamType=t.readUint8(),this.bufferSize=t.readUint24(),this.maxBitrate=t.readUint32(),this.avgBitrate=t.readUint32(),this.size-=13,this.parseRemainingDescriptors(t)},r.DecoderSpecificInfo=function(t){r.Descriptor.call(this,5,t)},r.DecoderSpecificInfo.prototype=new r.Descriptor,r.SLConfigDescriptor=function(t){r.Descriptor.call(this,6,t)},r.SLConfigDescriptor.prototype=new r.Descriptor,this},iT.MPEG4DescriptorParser=u,(d={ERR_INVALID_DATA:-1,ERR_NOT_ENOUGH_DATA:0,OK:1,BASIC_BOXES:["mdat","idat","free","skip","meco","strk"],FULL_BOXES:["hmhd","nmhd","iods","xml ","bxml","ipro","mere"],CONTAINER_BOXES:[["moov",["trak","pssh"]],["trak"],["edts"],["mdia"],["minf"],["dinf"],["stbl",["sgpd","sbgp"]],["mvex",["trex"]],["moof",["traf"]],["traf",["trun","sgpd","sbgp"]],["vttc"],["tref"],["iref"],["mfra",["tfra"]],["meco"],["hnti"],["hinf"],["strk"],["strd"],["sinf"],["rinf"],["schi"],["trgr"],["udta",["kind"]],["iprp",["ipma"]],["ipco"],["grpl"],["j2kH"],["etyp",["tyco"]]],boxCodes:[],fullBoxCodes:[],containerBoxCodes:[],sampleEntryCodes:{},sampleGroupEntryCodes:[],trackGroupTypes:[],UUIDBoxes:{},UUIDs:[],initialize:function(){d.FullBox.prototype=new d.Box,d.ContainerBox.prototype=new d.Box,d.SampleEntry.prototype=new d.Box,d.TrackGroupTypeBox.prototype=new d.FullBox,d.BASIC_BOXES.forEach(function(t){d.createBoxCtor(t)}),d.FULL_BOXES.forEach(function(t){d.createFullBoxCtor(t)}),d.CONTAINER_BOXES.forEach(function(t){d.createContainerBoxCtor(t[0],null,t[1])})},Box:function(t,e,r){this.type=t,this.size=e,this.uuid=r},FullBox:function(t,e,r){d.Box.call(this,t,e,r),this.flags=0,this.version=0},ContainerBox:function(t,e,r){d.Box.call(this,t,e,r),this.boxes=[]},SampleEntry:function(t,e,r,s){d.ContainerBox.call(this,t,e),this.hdr_size=r,this.start=s},SampleGroupEntry:function(t){this.grouping_type=t},TrackGroupTypeBox:function(t,e){d.FullBox.call(this,t,e)},createBoxCtor:function(t,e){d.boxCodes.push(t),d[t+"Box"]=function(e){d.Box.call(this,t,e)},d[t+"Box"].prototype=new d.Box,e&&(d[t+"Box"].prototype.parse=e)},createFullBoxCtor:function(t,e){d[t+"Box"]=function(e){d.FullBox.call(this,t,e)},d[t+"Box"].prototype=new d.FullBox,d[t+"Box"].prototype.parse=function(t){this.parseFullHeader(t),e&&e.call(this,t)}},addSubBoxArrays:function(t){if(t){this.subBoxNames=t;for(var e=t.length,r=0;rr?(a.error("BoxParser","Box of type '"+f+"' has a size "+u+" greater than its container size "+r),{code:d.ERR_NOT_ENOUGH_DATA,type:f,size:u,hdr_size:l,start:h}):0!==u&&h+u>t.getEndPosition()?(t.seek(h),a.info("BoxParser","Not enough data in stream to parse the entire '"+f+"' box"),{code:d.ERR_NOT_ENOUGH_DATA,type:f,size:u,hdr_size:l,start:h}):e?{code:d.OK,type:f,size:u,hdr_size:l,start:h}:(d[f+"Box"]?s=new d[f+"Box"](u):"uuid"!==f?(a.warn("BoxParser","Unknown box type: '"+f+"'"),(s=new d.Box(f,u)).has_unparsed_data=!0):d.UUIDBoxes[o]?s=new d.UUIDBoxes[o](u):(a.warn("BoxParser","Unknown uuid type: '"+o+"'"),(s=new d.Box(f,u)).uuid=o,s.has_unparsed_data=!0),s.hdr_size=l,s.start=h,s.write===d.Box.prototype.write&&"mdat"!==s.type&&(a.info("BoxParser","'"+p+"' box writing not yet implemented, keeping unparsed data in memory for later write"),s.parseDataAndRewind(t)),s.parse(t),(n=t.getPosition()-(s.start+s.size))<0?(a.warn("BoxParser","Parsing of box '"+p+"' did not read the entire indicated box data size (missing "+-n+" bytes), seeking forward"),t.seek(s.start+s.size)):n>0&&(a.error("BoxParser","Parsing of box '"+p+"' read "+n+" more bytes than the indicated box data size, seeking backwards"),0!==s.size&&t.seek(s.start+s.size)),{code:d.OK,box:s,size:s.size})},d.Box.prototype.parse=function(t){"mdat"!=this.type?this.data=t.readUint8Array(this.size-this.hdr_size):0===this.size?t.seek(t.getEndPosition()):t.seek(this.start+this.size)},d.Box.prototype.parseDataAndRewind=function(t){this.data=t.readUint8Array(this.size-this.hdr_size),t.position-=this.size-this.hdr_size},d.FullBox.prototype.parseDataAndRewind=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=4,t.position-=this.size-this.hdr_size},d.FullBox.prototype.parseFullHeader=function(t){this.version=t.readUint8(),this.flags=t.readUint24(),this.hdr_size+=4},d.FullBox.prototype.parse=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},d.ContainerBox.prototype.parse=function(t){for(var e,r;t.getPosition()>10&31,e[1]=this.language>>5&31,e[2]=31&this.language,this.languageString=String.fromCharCode(e[0]+96,e[1]+96,e[2]+96)},d.SAMPLE_ENTRY_TYPE_VISUAL="Visual",d.SAMPLE_ENTRY_TYPE_AUDIO="Audio",d.SAMPLE_ENTRY_TYPE_HINT="Hint",d.SAMPLE_ENTRY_TYPE_METADATA="Metadata",d.SAMPLE_ENTRY_TYPE_SUBTITLE="Subtitle",d.SAMPLE_ENTRY_TYPE_SYSTEM="System",d.SAMPLE_ENTRY_TYPE_TEXT="Text",d.SampleEntry.prototype.parseHeader=function(t){t.readUint8Array(6),this.data_reference_index=t.readUint16(),this.hdr_size+=8},d.SampleEntry.prototype.parse=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},d.SampleEntry.prototype.parseDataAndRewind=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=8,t.position-=this.size-this.hdr_size},d.SampleEntry.prototype.parseFooter=function(t){d.ContainerBox.prototype.parse.call(this,t)},d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_HINT),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SYSTEM),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_TEXT),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,function(t){var e;this.parseHeader(t),t.readUint16(),t.readUint16(),t.readUint32Array(3),this.width=t.readUint16(),this.height=t.readUint16(),this.horizresolution=t.readUint32(),this.vertresolution=t.readUint32(),t.readUint32(),this.frame_count=t.readUint16(),e=Math.min(31,t.readUint8()),this.compressorname=t.readString(e),e<31&&t.readString(31-e),this.depth=t.readUint16(),t.readUint16(),this.parseFooter(t)}),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,function(t){this.parseHeader(t),t.readUint32Array(2),this.channel_count=t.readUint16(),this.samplesize=t.readUint16(),t.readUint16(),t.readUint16(),this.samplerate=t.readUint32()/65536,this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc2"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc4"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"av01"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"dav1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"hvc1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"hev1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"hvt1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"lhe1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"dvh1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"dvhe"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvc1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvi1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvs1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvcN"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vp08"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vp09"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avs3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"j2ki"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"mjp2"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"mjpg"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"uncv"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mp4a"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"ac-3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"ac-4"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"ec-3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"Opus"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mha1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mha2"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mhm1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mhm2"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"encv"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"enca"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE,"encu"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SYSTEM,"encs"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_TEXT,"enct"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA,"encm"),d.createBoxCtor("a1lx",function(t){var e=((1&(1&t.readUint8()))+1)*16;this.layer_size=[];for(var r=0;r<3;r++)16==e?this.layer_size[r]=t.readUint16():this.layer_size[r]=t.readUint32()}),d.createBoxCtor("a1op",function(t){this.op_index=t.readUint8()}),d.createFullBoxCtor("auxC",function(t){this.aux_type=t.readCString();var e=this.size-this.hdr_size-(this.aux_type.length+1);this.aux_subtype=t.readUint8Array(e)}),d.createBoxCtor("av1C",function(t){var e=t.readUint8();if(this.version=127&e,1!==this.version){a.error("av1C version "+this.version+" not supported");return}if(e=t.readUint8(),this.seq_profile=e>>5&7,this.seq_level_idx_0=31&e,e=t.readUint8(),this.seq_tier_0=e>>7&1,this.high_bitdepth=e>>6&1,this.twelve_bit=e>>5&1,this.monochrome=e>>4&1,this.chroma_subsampling_x=e>>3&1,this.chroma_subsampling_y=e>>2&1,this.chroma_sample_position=3&e,e=t.readUint8(),this.reserved_1=e>>5&7,0!==this.reserved_1){a.error("av1C reserved_1 parsing problem");return}if(this.initial_presentation_delay_present=e>>4&1,1===this.initial_presentation_delay_present)this.initial_presentation_delay_minus_one=15&e;else if(this.reserved_2=15&e,0!==this.reserved_2){a.error("av1C reserved_2 parsing problem");return}var r=this.size-this.hdr_size-4;this.configOBUs=t.readUint8Array(r)}),d.createBoxCtor("avcC",function(t){var e,r;for(this.configurationVersion=t.readUint8(),this.AVCProfileIndication=t.readUint8(),this.profile_compatibility=t.readUint8(),this.AVCLevelIndication=t.readUint8(),this.lengthSizeMinusOne=3&t.readUint8(),this.nb_SPS_nalus=31&t.readUint8(),r=this.size-this.hdr_size-6,this.SPS=[],e=0;e0&&(this.ext=t.readUint8Array(r))}),d.createBoxCtor("btrt",function(t){this.bufferSizeDB=t.readUint32(),this.maxBitrate=t.readUint32(),this.avgBitrate=t.readUint32()}),d.createFullBoxCtor("ccst",function(t){var e=t.readUint8();this.all_ref_pics_intra=(128&e)==128,this.intra_pred_used=(64&e)==64,this.max_ref_per_pic=(63&e)>>2,t.readUint24()}),d.createBoxCtor("cdef",function(t){var e;for(this.channel_count=t.readUint16(),this.channel_indexes=[],this.channel_types=[],this.channel_associations=[],e=0;e=32768&&this.component_type_urls.push(t.readCString())}}),d.createFullBoxCtor("co64",function(t){var e,r;if(e=t.readUint32(),this.chunk_offsets=[],0===this.version)for(r=0;r>7}else"rICC"===this.colour_type?this.ICC_profile=t.readUint8Array(this.size-4):"prof"===this.colour_type&&(this.ICC_profile=t.readUint8Array(this.size-4))}),d.createFullBoxCtor("cprt",function(t){this.parseLanguage(t),this.notice=t.readCString()}),d.createFullBoxCtor("cslg",function(t){0===this.version&&(this.compositionToDTSShift=t.readInt32(),this.leastDecodeToDisplayDelta=t.readInt32(),this.greatestDecodeToDisplayDelta=t.readInt32(),this.compositionStartTime=t.readInt32(),this.compositionEndTime=t.readInt32())}),d.createFullBoxCtor("ctts",function(t){var e,r;if(e=t.readUint32(),this.sample_counts=[],this.sample_offsets=[],0===this.version)for(r=0;r>6,this.bsid=e>>1&31,this.bsmod=(1&e)<<2|r>>6&3,this.acmod=r>>3&7,this.lfeon=r>>2&1,this.bit_rate_code=3&r|s>>5&7}),d.createBoxCtor("dec3",function(t){var e=t.readUint16();this.data_rate=e>>3,this.num_ind_sub=7&e,this.ind_subs=[];for(var r=0;r>6,s.bsid=n>>1&31,s.bsmod=(1&n)<<4|a>>4&15,s.acmod=a>>1&7,s.lfeon=1&a,s.num_dep_sub=o>>1&15,s.num_dep_sub>0&&(s.chan_loc=(1&o)<<8|t.readUint8())}}),d.createFullBoxCtor("dfLa",function(t){var e=[],r=["STREAMINFO","PADDING","APPLICATION","SEEKTABLE","VORBIS_COMMENT","CUESHEET","PICTURE","RESERVED"];for(this.parseFullHeader(t);;){var s=t.readUint8(),n=Math.min(127&s,r.length-1);if(n?t.readUint8Array(t.readUint24()):(t.readUint8Array(13),this.samplerate=t.readUint32()>>12,t.readUint8Array(20)),e.push(r[n]),128&s)break}this.numMetadataBlocks=e.length+" ("+e.join(", ")+")"}),d.createBoxCtor("dimm",function(t){this.bytessent=t.readUint64()}),d.createBoxCtor("dmax",function(t){this.time=t.readUint32()}),d.createBoxCtor("dmed",function(t){this.bytessent=t.readUint64()}),d.createBoxCtor("dOps",function(t){if(this.Version=t.readUint8(),this.OutputChannelCount=t.readUint8(),this.PreSkip=t.readUint16(),this.InputSampleRate=t.readUint32(),this.OutputGain=t.readInt16(),this.ChannelMappingFamily=t.readUint8(),0!==this.ChannelMappingFamily){this.StreamCount=t.readUint8(),this.CoupledCount=t.readUint8(),this.ChannelMapping=[];for(var e=0;etypeof u){var r=new u;this.esd=r.parseOneDescriptor(new h(e.buffer,0,h.BIG_ENDIAN))}}),d.createBoxCtor("fiel",function(t){this.fieldCount=t.readUint8(),this.fieldOrdering=t.readUint8()}),d.createBoxCtor("frma",function(t){this.data_format=t.readString(4)}),d.createBoxCtor("ftyp",function(t){var e=this.size-this.hdr_size;this.major_brand=t.readString(4),this.minor_version=t.readUint32(),e-=8,this.compatible_brands=[];for(var r=0;e>=4;)this.compatible_brands[r]=t.readString(4),e-=4,r++}),d.createFullBoxCtor("hdlr",function(t){0===this.version&&(t.readUint32(),this.handler=t.readString(4),t.readUint32Array(3),this.name=t.readString(this.size-this.hdr_size-20),"\0"===this.name[this.name.length-1]&&(this.name=this.name.slice(0,-1)))}),d.createBoxCtor("hvcC",function(t){this.configurationVersion=t.readUint8(),n=t.readUint8(),this.general_profile_space=n>>6,this.general_tier_flag=(32&n)>>5,this.general_profile_idc=31&n,this.general_profile_compatibility=t.readUint32(),this.general_constraint_indicator=t.readUint8Array(6),this.general_level_idc=t.readUint8(),this.min_spatial_segmentation_idc=4095&t.readUint16(),this.parallelismType=3&t.readUint8(),this.chroma_format_idc=3&t.readUint8(),this.bit_depth_luma_minus8=7&t.readUint8(),this.bit_depth_chroma_minus8=7&t.readUint8(),this.avgFrameRate=t.readUint16(),n=t.readUint8(),this.constantFrameRate=n>>6,this.numTemporalLayers=(13&n)>>3,this.temporalIdNested=(4&n)>>2,this.lengthSizeMinusOne=3&n,this.nalu_arrays=[];var e,r,s,n,a=t.readUint8();for(e=0;e>7,o.nalu_type=63&n;var h=t.readUint16();for(r=0;r>4&15,this.length_size=15&e,e=t.readUint8(),this.base_offset_size=e>>4&15,1===this.version||2===this.version?this.index_size=15&e:this.index_size=0,this.items=[];var e,r=0;if(this.version<2)r=t.readUint16();else if(2===this.version)r=t.readUint32();else throw"version of iloc box not supported";for(var s=0;s>7,this.axis=1&e}),d.createFullBoxCtor("infe",function(t){if((0===this.version||1===this.version)&&(this.item_ID=t.readUint16(),this.item_protection_index=t.readUint16(),this.item_name=t.readCString(),this.content_type=t.readCString(),this.content_encoding=t.readCString()),1===this.version){this.extension_type=t.readString(4),a.warn("BoxParser","Cannot parse extension type"),t.seek(this.start+this.size);return}this.version>=2&&(2===this.version?this.item_ID=t.readUint16():3===this.version&&(this.item_ID=t.readUint32()),this.item_protection_index=t.readUint16(),this.item_type=t.readString(4),this.item_name=t.readCString(),"mime"===this.item_type?(this.content_type=t.readCString(),this.content_encoding=t.readCString()):"uri "===this.item_type&&(this.item_uri_type=t.readCString()))}),d.createFullBoxCtor("ipma",function(t){var e,r;for(entry_count=t.readUint32(),this.associations=[],e=0;e>7==1,1&this.flags?o.property_index=(127&a)<<8|t.readUint8():o.property_index=127&a}}}),d.createFullBoxCtor("iref",function(t){var e,r;for(this.references=[];t.getPosition()>7,s.assignment_type=127&n,s.assignment_type){case 0:s.grouping_type=t.readString(4);break;case 1:s.grouping_type=t.readString(4),s.grouping_type_parameter=t.readUint32();break;case 2:case 3:break;case 4:s.sub_track_id=t.readUint32();break;default:a.warn("BoxParser","Unknown leva assignement type")}}}),d.createBoxCtor("lsel",function(t){this.layer_id=t.readUint16()}),d.createBoxCtor("maxr",function(t){this.period=t.readUint32(),this.bytes=t.readUint32()}),d.createBoxCtor("mdcv",function(t){this.display_primaries=[],this.display_primaries[0]={},this.display_primaries[0].x=t.readUint16(),this.display_primaries[0].y=t.readUint16(),this.display_primaries[1]={},this.display_primaries[1].x=t.readUint16(),this.display_primaries[1].y=t.readUint16(),this.display_primaries[2]={},this.display_primaries[2].x=t.readUint16(),this.display_primaries[2].y=t.readUint16(),this.white_point={},this.white_point.x=t.readUint16(),this.white_point.y=t.readUint16(),this.max_display_mastering_luminance=t.readUint32(),this.min_display_mastering_luminance=t.readUint32()}),d.createFullBoxCtor("mdhd",function(t){1==this.version?(this.creation_time=t.readUint64(),this.modification_time=t.readUint64(),this.timescale=t.readUint32(),this.duration=t.readUint64()):(this.creation_time=t.readUint32(),this.modification_time=t.readUint32(),this.timescale=t.readUint32(),this.duration=t.readUint32()),this.parseLanguage(t),t.readUint16()}),d.createFullBoxCtor("mehd",function(t){1&this.flags&&(a.warn("BoxParser","mehd box incorrectly uses flags set to 1, converting version to 1"),this.version=1),1==this.version?this.fragment_duration=t.readUint64():this.fragment_duration=t.readUint32()}),d.createFullBoxCtor("meta",function(t){this.boxes=[],d.ContainerBox.prototype.parse.call(this,t)}),d.createFullBoxCtor("mfhd",function(t){this.sequence_number=t.readUint32()}),d.createFullBoxCtor("mfro",function(t){this._size=t.readUint32()}),d.createFullBoxCtor("mvhd",function(t){1==this.version?(this.creation_time=t.readUint64(),this.modification_time=t.readUint64(),this.timescale=t.readUint32(),this.duration=t.readUint64()):(this.creation_time=t.readUint32(),this.modification_time=t.readUint32(),this.timescale=t.readUint32(),this.duration=t.readUint32()),this.rate=t.readUint32(),this.volume=t.readUint16()>>8,t.readUint16(),t.readUint32Array(2),this.matrix=t.readUint32Array(9),t.readUint32Array(6),this.next_track_id=t.readUint32()}),d.createBoxCtor("npck",function(t){this.packetssent=t.readUint32()}),d.createBoxCtor("nump",function(t){this.packetssent=t.readUint64()}),d.createFullBoxCtor("padb",function(t){var e=t.readUint32();this.padbits=[];for(var r=0;r0){var e=t.readUint32();this.kid=[];for(var r=0;r0&&(this.data=t.readUint8Array(s))}),d.createFullBoxCtor("clef",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),d.createFullBoxCtor("enof",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),d.createFullBoxCtor("prof",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),d.createContainerBoxCtor("tapt",null,["clef","prof","enof"]),d.createBoxCtor("rtp ",function(t){this.descriptionformat=t.readString(4),this.sdptext=t.readString(this.size-this.hdr_size-4)}),d.createFullBoxCtor("saio",function(t){1&this.flags&&(this.aux_info_type=t.readUint32(),this.aux_info_type_parameter=t.readUint32());var e=t.readUint32();this.offset=[];for(var r=0;r>7,this.avgRateFlag=e>>6&1,this.durationFlag&&(this.duration=t.readUint32()),this.avgRateFlag&&(this.accurateStatisticsFlag=t.readUint8(),this.avgBitRate=t.readUint16(),this.avgFrameRate=t.readUint16()),this.dependency=[];for(var r=t.readUint8(),s=0;s>7,this.num_leading_samples=127&e}),d.createSampleGroupCtor("rash",function(t){if(this.operation_point_count=t.readUint16(),this.description_length!==2+(1===this.operation_point_count?2:6*this.operation_point_count)+9)a.warn("BoxParser","Mismatch in "+this.grouping_type+" sample group length"),this.data=t.readUint8Array(this.description_length-2);else{if(1===this.operation_point_count)this.target_rate_share=t.readUint16();else{this.target_rate_share=[],this.available_bitrate=[];for(var e=0;e>4,this.skip_byte_block=15&e,this.isProtected=t.readUint8(),this.Per_Sample_IV_Size=t.readUint8(),this.KID=d.parseHex16(t),this.constant_IV_size=0,this.constant_IV=0,1===this.isProtected&&0===this.Per_Sample_IV_Size&&(this.constant_IV_size=t.readUint8(),this.constant_IV=t.readUint8Array(this.constant_IV_size))}),d.createSampleGroupCtor("stsa",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("sync",function(t){var e=t.readUint8();this.NAL_unit_type=63&e}),d.createSampleGroupCtor("tele",function(t){var e=t.readUint8();this.level_independently_decodable=e>>7}),d.createSampleGroupCtor("tsas",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("tscl",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("vipr",function(t){a.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createFullBoxCtor("sbgp",function(t){this.grouping_type=t.readString(4),1===this.version?this.grouping_type_parameter=t.readUint32():this.grouping_type_parameter=0,this.entries=[];for(var e=t.readUint32(),r=0;r>6,this.sample_depends_on[s]=e>>4&3,this.sample_is_depended_on[s]=e>>2&3,this.sample_has_redundancy[s]=3&e}),d.createFullBoxCtor("senc"),d.createFullBoxCtor("sgpd",function(t){this.grouping_type=t.readString(4),a.debug("BoxParser","Found Sample Groups of type "+this.grouping_type),1===this.version?this.default_length=t.readUint32():this.default_length=0,this.version>=2&&(this.default_group_description_index=t.readUint32()),this.entries=[];for(var e,r=t.readUint32(),s=0;s>31&1,s.referenced_size=2147483647&n,s.subsegment_duration=t.readUint32(),n=t.readUint32(),s.starts_with_SAP=n>>31&1,s.SAP_type=n>>28&7,s.SAP_delta_time=268435455&n}}),d.SingleItemTypeReferenceBox=function(t,e,r,s){d.Box.call(this,t,e),this.hdr_size=r,this.start=s},d.SingleItemTypeReferenceBox.prototype=new d.Box,d.SingleItemTypeReferenceBox.prototype.parse=function(t){this.from_item_ID=t.readUint16();var e=t.readUint16();this.references=[];for(var r=0;r>4&15,this.sample_sizes[e+1]=15&s}else if(8===this.field_size)for(e=0;e0)for(r=0;r>4&15,this.default_skip_byte_block=15&e}this.default_isProtected=t.readUint8(),this.default_Per_Sample_IV_Size=t.readUint8(),this.default_KID=d.parseHex16(t),1===this.default_isProtected&&0===this.default_Per_Sample_IV_Size&&(this.default_constant_IV_size=t.readUint8(),this.default_constant_IV=t.readUint8Array(this.default_constant_IV_size))}),d.createFullBoxCtor("tfdt",function(t){1==this.version?this.baseMediaDecodeTime=t.readUint64():this.baseMediaDecodeTime=t.readUint32()}),d.createFullBoxCtor("tfhd",function(t){var e=0;this.track_id=t.readUint32(),this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_BASE_DATA_OFFSET?(this.base_data_offset=t.readUint64(),e+=8):this.base_data_offset=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_DESC?(this.default_sample_description_index=t.readUint32(),e+=4):this.default_sample_description_index=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_DUR?(this.default_sample_duration=t.readUint32(),e+=4):this.default_sample_duration=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_SIZE?(this.default_sample_size=t.readUint32(),e+=4):this.default_sample_size=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_FLAGS?(this.default_sample_flags=t.readUint32(),e+=4):this.default_sample_flags=0}),d.createFullBoxCtor("tfra",function(t){this.track_ID=t.readUint32(),t.readUint24();var e=t.readUint8();this.length_size_of_traf_num=e>>4&3,this.length_size_of_trun_num=e>>2&3,this.length_size_of_sample_num=3&e,this.entries=[];for(var r=t.readUint32(),s=0;s>8,t.readUint16(),this.matrix=t.readInt32Array(9),this.width=t.readUint32(),this.height=t.readUint32()}),d.createBoxCtor("tmax",function(t){this.time=t.readUint32()}),d.createBoxCtor("tmin",function(t){this.time=t.readUint32()}),d.createBoxCtor("totl",function(t){this.bytessent=t.readUint32()}),d.createBoxCtor("tpay",function(t){this.bytessent=t.readUint32()}),d.createBoxCtor("tpyl",function(t){this.bytessent=t.readUint64()}),d.TrackGroupTypeBox.prototype.parse=function(t){this.parseFullHeader(t),this.track_group_id=t.readUint32()},d.createTrackGroupCtor("msrc"),d.TrackReferenceTypeBox=function(t,e,r,s){d.Box.call(this,t,e),this.hdr_size=r,this.start=s},d.TrackReferenceTypeBox.prototype=new d.Box,d.TrackReferenceTypeBox.prototype.parse=function(t){this.track_ids=t.readUint32Array((this.size-this.hdr_size)/4)},d.trefBox.prototype.parse=function(t){for(var e,r;t.getPosition()e&&this.flags&d.TRUN_FLAGS_DATA_OFFSET?(this.data_offset=t.readInt32(),e+=4):this.data_offset=0,this.size-this.hdr_size>e&&this.flags&d.TRUN_FLAGS_FIRST_FLAG?(this.first_sample_flags=t.readUint32(),e+=4):this.first_sample_flags=0,this.sample_duration=[],this.sample_size=[],this.sample_flags=[],this.sample_composition_time_offset=[],this.size-this.hdr_size>e)for(var r=0;r>7&1,this.block_pad_lsb=r>>6&1,this.block_little_endian=r>>5&1,this.block_reversed=r>>4&1,this.pad_unknown=r>>3&1,this.pixel_size=t.readUint8(),this.row_align_size=t.readUint32(),this.tile_align_size=t.readUint32(),this.num_tile_cols_minus_one=t.readUint32(),this.num_tile_rows_minus_one=t.readUint32()}),d.createFullBoxCtor("url ",function(t){1!==this.flags&&(this.location=t.readCString())}),d.createFullBoxCtor("urn ",function(t){this.name=t.readCString(),this.size-this.hdr_size-this.name.length-1>0&&(this.location=t.readCString())}),d.createUUIDBox("a5d40b30e81411ddba2f0800200c9a66",!0,!1,function(t){this.LiveServerManifest=t.readString(this.size-this.hdr_size).replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}),d.createUUIDBox("d08a4f1810f34a82b6c832d8aba183d3",!0,!1,function(t){this.system_id=d.parseHex16(t);var e=t.readUint32();e>0&&(this.data=t.readUint8Array(e))}),d.createUUIDBox("a2394f525a9b4f14a2446c427c648df4",!0,!1),d.createUUIDBox("8974dbce7be74c5184f97148f9882554",!0,!1,function(t){this.default_AlgorithmID=t.readUint24(),this.default_IV_size=t.readUint8(),this.default_KID=d.parseHex16(t)}),d.createUUIDBox("d4807ef2ca3946958e5426cb9e46a79f",!0,!1,function(t){this.fragment_count=t.readUint8(),this.entries=[];for(var e=0;e>4,this.chromaSubsampling=e>>1&7,this.videoFullRangeFlag=1&e,this.colourPrimaries=t.readUint8(),this.transferCharacteristics=t.readUint8(),this.matrixCoefficients=t.readUint8()):(this.profile=t.readUint8(),this.level=t.readUint8(),e=t.readUint8(),this.bitDepth=e>>4&15,this.colorSpace=15&e,e=t.readUint8(),this.chromaSubsampling=e>>4&15,this.transferFunction=e>>1&7,this.videoFullRangeFlag=1&e),this.codecIntializationDataSize=t.readUint16(),this.codecIntializationData=t.readUint8Array(this.codecIntializationDataSize)}),d.createBoxCtor("vttC",function(t){this.text=t.readString(this.size-this.hdr_size)}),d.createFullBoxCtor("vvcC",function(t){var e,r,s={held_bits:void 0,num_held_bits:0,stream_read_1_bytes:function(t){this.held_bits=t.readUint8(),this.num_held_bits=8},stream_read_2_bytes:function(t){this.held_bits=t.readUint16(),this.num_held_bits=16},extract_bits:function(t){var e=this.held_bits>>this.num_held_bits-t&(1<1){for(s.stream_read_1_bytes(t),this.ptl_sublayer_present_mask=0,r=this.num_sublayers-2;r>=0;--r){var o=s.extract_bits(1);this.ptl_sublayer_present_mask|=o<1;++r)s.extract_bits(1);for(this.sublayer_level_idc=[],r=this.num_sublayers-2;r>=0;--r)this.ptl_sublayer_present_mask&1<"u"||null===e?e=2:e;r.length>=1;e+=d.decimalToHex(s,0)+".",0===this.hvcC.general_tier_flag?e+="L":e+="H",e+=this.hvcC.general_level_idc;var n=!1,a="";for(t=5;t>=0;t--)(this.hvcC.general_constraint_indicator[t]||n)&&(a="."+d.decimalToHex(this.hvcC.general_constraint_indicator[t],0)+a,n=!0);e+=a}return e},d.vvc1SampleEntry.prototype.getCodec=d.vvi1SampleEntry.prototype.getCodec=function(){var t,e=d.SampleEntry.prototype.getCodec.call(this);if(this.vvcC){e+="."+this.vvcC.general_profile_idc,this.vvcC.general_tier_flag?e+=".H":e+=".L",e+=this.vvcC.general_level_idc;var r="";if(this.vvcC.general_constraint_info){var s,n,a=[];for(n=0|this.vvcC.ptl_frame_only_constraint<<7|this.vvcC.ptl_multilayer_enabled<<6,t=0;t>2&63,a.push(n),n&&(s=t),n=this.vvcC.general_constraint_info[t]>>2&3;if(void 0===s)r=".CA";else{r=".C";var o="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",h=0,l=0;for(t=0;t<=s;++t)for(h=h<<8|a[t],l+=8;l>=5;)r+=o[h>>l-5&31],l-=5,h&=(1<4294967296&&(this.size+=8),"uuid"===this.type&&(this.size+=16),a.debug("BoxWriter","Writing box "+this.type+" of size: "+this.size+" at position "+t.getPosition()+(e||"")),this.size>4294967296?t.writeUint32(1):(this.sizePosition=t.getPosition(),t.writeUint32(this.size)),t.writeString(this.type,null,4),"uuid"===this.type&&t.writeUint8Array(this.uuid),this.size>4294967296&&t.writeUint64(this.size)},d.FullBox.prototype.writeHeader=function(t){this.size+=4,d.Box.prototype.writeHeader.call(this,t," v="+this.version+" f="+this.flags),t.writeUint8(this.version),t.writeUint24(this.flags)},d.Box.prototype.write=function(t){"mdat"===this.type?this.data&&(this.size=this.data.length,this.writeHeader(t),t.writeUint8Array(this.data)):(this.size=this.data?this.data.length:0,this.writeHeader(t),this.data&&t.writeUint8Array(this.data))},d.ContainerBox.prototype.write=function(t){this.size=0,this.writeHeader(t);for(var e=0;e=2&&t.writeUint32(this.default_sample_description_index),t.writeUint32(this.entries.length),e=0;e0)for(e=0;e+14294967295?1:0,this.flags=0,this.size=4,1===this.version&&(this.size+=4),this.writeHeader(t),1===this.version?t.writeUint64(this.baseMediaDecodeTime):t.writeUint32(this.baseMediaDecodeTime)},d.tfhdBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&d.TFHD_FLAG_BASE_DATA_OFFSET&&(this.size+=8),this.flags&d.TFHD_FLAG_SAMPLE_DESC&&(this.size+=4),this.flags&d.TFHD_FLAG_SAMPLE_DUR&&(this.size+=4),this.flags&d.TFHD_FLAG_SAMPLE_SIZE&&(this.size+=4),this.flags&d.TFHD_FLAG_SAMPLE_FLAGS&&(this.size+=4),this.writeHeader(t),t.writeUint32(this.track_id),this.flags&d.TFHD_FLAG_BASE_DATA_OFFSET&&t.writeUint64(this.base_data_offset),this.flags&d.TFHD_FLAG_SAMPLE_DESC&&t.writeUint32(this.default_sample_description_index),this.flags&d.TFHD_FLAG_SAMPLE_DUR&&t.writeUint32(this.default_sample_duration),this.flags&d.TFHD_FLAG_SAMPLE_SIZE&&t.writeUint32(this.default_sample_size),this.flags&d.TFHD_FLAG_SAMPLE_FLAGS&&t.writeUint32(this.default_sample_flags)},d.tkhdBox.prototype.write=function(t){this.version=0,this.size=80,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.track_id),t.writeUint32(0),t.writeUint32(this.duration),t.writeUint32(0),t.writeUint32(0),t.writeInt16(this.layer),t.writeInt16(this.alternate_group),t.writeInt16(this.volume<<8),t.writeUint16(0),t.writeInt32Array(this.matrix),t.writeUint32(this.width),t.writeUint32(this.height)},d.trexBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=20,this.writeHeader(t),t.writeUint32(this.track_id),t.writeUint32(this.default_sample_description_index),t.writeUint32(this.default_sample_duration),t.writeUint32(this.default_sample_size),t.writeUint32(this.default_sample_flags)},d.trunBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&d.TRUN_FLAGS_DATA_OFFSET&&(this.size+=4),this.flags&d.TRUN_FLAGS_FIRST_FLAG&&(this.size+=4),this.flags&d.TRUN_FLAGS_DURATION&&(this.size+=4*this.sample_duration.length),this.flags&d.TRUN_FLAGS_SIZE&&(this.size+=4*this.sample_size.length),this.flags&d.TRUN_FLAGS_FLAGS&&(this.size+=4*this.sample_flags.length),this.flags&d.TRUN_FLAGS_CTS_OFFSET&&(this.size+=4*this.sample_composition_time_offset.length),this.writeHeader(t),t.writeUint32(this.sample_count),this.flags&d.TRUN_FLAGS_DATA_OFFSET&&(this.data_offset_position=t.getPosition(),t.writeInt32(this.data_offset)),this.flags&d.TRUN_FLAGS_FIRST_FLAG&&t.writeUint32(this.first_sample_flags);for(var e=0;e-1)){if(t[r]instanceof d.Box||e[r]instanceof d.Box||typeof t[r]>"u"||typeof e[r]>"u"||"function"==typeof t[r]||"function"==typeof e[r]||t.subBoxNames&&t.subBoxNames.indexOf(r.slice(0,4))>-1||e.subBoxNames&&e.subBoxNames.indexOf(r.slice(0,4))>-1||"data"===r||"start"===r||"size"===r||"creation_time"===r||"modification_time"===r||d.DIFF_PRIMITIVE_ARRAY_PROP_NAMES.indexOf(r)>-1)continue;if(t[r]!==e[r])return!1}return!0},d.boxEqual=function(t,e){if(!d.boxEqualFields(t,e))return!1;for(var r=0;r1)for(e=1;etypeof DOMParser&&(r.document=new DOMParser().parseFromString(r.documentString,"application/xml")),r},(p=function(){}).prototype.parseSample=function(t){return new o(t.data.buffer).readString(t.data.length)},p.prototype.parseConfig=function(t){var e=new o(t.buffer);return e.readUint32(),e.readCString()},iT.XMLSubtitlein4Parser=f,iT.Textin4Parser=p,(c=function(t){this.stream=t||new l,this.boxes=[],this.mdats=[],this.moofs=[],this.isProgressive=!1,this.moovStartFound=!1,this.onMoovStart=null,this.moovStartSent=!1,this.onReady=null,this.readySent=!1,this.onSegment=null,this.onSamples=null,this.onError=null,this.sampleListBuilt=!1,this.fragmentedTracks=[],this.extractedTracks=[],this.isFragmentationInitialized=!1,this.sampleProcessingStarted=!1,this.nextMoofNumber=0,this.itemListBuilt=!1,this.onSidx=null,this.sidxSent=!1}).prototype.setSegmentOptions=function(t,e,r){var s=this.getTrackById(t);if(s){var n={};this.fragmentedTracks.push(n),n.id=t,n.user=e,n.trak=s,s.nextSample=0,n.segmentStream=null,n.nb_samples=1e3,n.rapAlignement=!0,r&&(r.nbSamples&&(n.nb_samples=r.nbSamples),r.rapAlignement&&(n.rapAlignement=r.rapAlignement))}},c.prototype.unsetSegmentOptions=function(t){for(var e=-1,r=0;r-1&&this.fragmentedTracks.splice(e,1)},c.prototype.setExtractionOptions=function(t,e,r){var s=this.getTrackById(t);if(s){var n={};this.extractedTracks.push(n),n.id=t,n.user=e,n.trak=s,s.nextSample=0,n.nb_samples=1e3,n.samples=[],r&&r.nbSamples&&(n.nb_samples=r.nbSamples)}},c.prototype.unsetExtractionOptions=function(t){for(var e=-1,r=0;r-1&&this.extractedTracks.splice(e,1)},c.prototype.parse=function(){var t,e,r;if(!(this.restoreParsePosition&&!this.restoreParsePosition()))for(;;)if(this.hasIncompleteMdat&&this.hasIncompleteMdat()){if(this.processIncompleteMdat())continue;return}else if(this.saveParsePosition&&this.saveParsePosition(),(e=d.parseOneBox(this.stream,!1)).code===d.ERR_NOT_ENOUGH_DATA){if(!this.processIncompleteBox)return;if(this.processIncompleteBox(e))continue;return}else{switch(t="uuid"!==(r=e.box).type?r.type:r.uuid,this.boxes.push(r),t){case"mdat":this.mdats.push(r);break;case"moof":this.moofs.push(r);break;case"moov":this.moovStartFound=!0,0===this.mdats.length&&(this.isProgressive=!0);default:void 0!==this[t]&&a.warn("ISOFile","Duplicate Box of type: "+t+", overriding previous occurrence"),this[t]=r}this.updateUsedBytes&&this.updateUsedBytes(r,e)}},c.prototype.checkBuffer=function(t){if(null==t)throw"Buffer must be defined and non empty";if(void 0===t.fileStart)throw"Buffer must have a fileStart property";return 0===t.byteLength?(a.warn("ISOFile","Ignoring empty buffer (fileStart: "+t.fileStart+")"),this.stream.logBufferLevel(),!1):(a.info("ISOFile","Processing buffer (fileStart: "+t.fileStart+")"),t.usedBytes=0,this.stream.insertBuffer(t),this.stream.logBufferLevel(),!!this.stream.initialized()||(a.warn("ISOFile","Not ready to start parsing"),!1))},c.prototype.appendBuffer=function(t,e){var r;if(this.checkBuffer(t))return this.parse(),this.moovStartFound&&!this.moovStartSent&&(this.moovStartSent=!0,this.onMoovStart&&this.onMoovStart()),this.moov?(this.sampleListBuilt||(this.buildSampleLists(),this.sampleListBuilt=!0),this.updateSampleLists(),this.onReady&&!this.readySent&&(this.readySent=!0,this.onReady(this.getInfo())),this.processSamples(e),this.nextSeekPosition?(r=this.nextSeekPosition,this.nextSeekPosition=void 0):r=this.nextParsePosition,this.stream.getEndFilePositionAfter&&(r=this.stream.getEndFilePositionAfter(r))):r=this.nextParsePosition?this.nextParsePosition:0,this.sidx&&this.onSidx&&!this.sidxSent&&(this.onSidx(this.sidx),this.sidxSent=!0),this.meta&&(this.flattenItemInfo&&!this.itemListBuilt&&(this.flattenItemInfo(),this.itemListBuilt=!0),this.processItems&&this.processItems(this.onItem)),this.stream.cleanBuffers&&(a.info("ISOFile","Done processing buffer (fileStart: "+t.fileStart+") - next buffer to fetch should have a fileStart position of "+r),this.stream.logBufferLevel(),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0),a.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize())),r},c.prototype.getInfo=function(){var t,e,r,s,n,a,o={},h=/* @__PURE__ */new Date("1904-01-01T00:00:00Z").getTime();if(this.moov)for(o.hasMoov=!0,o.duration=this.moov.mvhd.duration,o.timescale=this.moov.mvhd.timescale,o.isFragmented=null!=this.moov.mvex,o.isFragmented&&this.moov.mvex.mehd&&(o.fragment_duration=this.moov.mvex.mehd.fragment_duration),o.isProgressive=this.isProgressive,o.hasIOD=null!=this.moov.iods,o.brands=[],o.brands.push(this.ftyp.major_brand),o.brands=o.brands.concat(this.ftyp.compatible_brands),o.created=new Date(h+1e3*this.moov.mvhd.creation_time),o.modified=new Date(h+1e3*this.moov.mvhd.modification_time),o.tracks=[],o.audioTracks=[],o.videoTracks=[],o.subtitleTracks=[],o.metadataTracks=[],o.hintTracks=[],o.otherTracks=[],t=0;t0?o.mime+='video/mp4; codecs="':o.audioTracks&&o.audioTracks.length>0?o.mime+='audio/mp4; codecs="':o.mime+='application/mp4; codecs="',t=0;t=r.samples.length)&&(a.info("ISOFile","Sending fragmented data on track #"+s.id+" for samples ["+Math.max(0,r.nextSample-s.nb_samples)+","+(r.nextSample-1)+"]"),a.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize()),this.onSegment&&this.onSegment(s.id,s.user,s.segmentStream.buffer,r.nextSample,t||r.nextSample>=r.samples.length),s.segmentStream=null,s!==this.fragmentedTracks[e]))break}}if(null!==this.onSamples)for(e=0;e=r.samples.length)&&(a.debug("ISOFile","Sending samples on track #"+o.id+" for sample "+r.nextSample),this.onSamples&&this.onSamples(o.id,o.user,o.samples),o.samples=[],o!==this.extractedTracks[e]))break}}}},c.prototype.getBox=function(t){var e=this.getBoxes(t,!0);return e.length?e[0]:null},c.prototype.getBoxes=function(t,e){var r=[];return c._sweep.call(this,t,r,e),r},c._sweep=function(t,e,r){for(var s in this.type&&this.type==t&&e.push(this),this.boxes){if(e.length&&r)return;c._sweep.call(this.boxes[s],t,e,r)}},c.prototype.getTrackSamplesInfo=function(t){var e=this.getTrackById(t);if(e)return e.samples},c.prototype.getTrackSample=function(t,e){var r=this.getTrackById(t);return this.getSample(r,e)},c.prototype.releaseUsedSamples=function(t,e){var r=0,s=this.getTrackById(t);s.lastValidSample||(s.lastValidSample=0);for(var n=s.lastValidSample;nt*n.timescale){u=s-1;break}e&&n.is_sync&&(l=s)}for(e&&(u=l),t=r.samples[u].cts,r.nextSample=u;r.samples[u].alreadyRead===r.samples[u].size&&r.samples[u+1];)u++;return h=r.samples[u].offset+r.samples[u].alreadyRead,a.info("ISOFile","Seeking to "+(e?"RAP":"")+" sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+a.getDurationString(t,o)+" and offset: "+h),{offset:h,time:t/o}},c.prototype.getTrackDuration=function(t){var e;return t.samples?((e=t.samples[t.samples.length-1]).cts+e.duration)/e.timescale:1/0},c.prototype.seek=function(t,e){var r,s,n,o=this.moov,h={offset:1/0,time:1/0};if(this.moov){for(n=0;nthis.getTrackDuration(r))&&((s=this.seekTrack(t,e,r)).offset-1){h=l;break}switch(h){case"Visual":if(n.add("vmhd").set("graphicsmode",0).set("opcolor",[0,0,0]),a.set("width",e.width).set("height",e.height).set("horizresolution",4718592).set("vertresolution",4718592).set("frame_count",1).set("compressorname",e.type+" Compressor").set("depth",24),e.avcDecoderConfigRecord){var p=new d.avcCBox;p.parse(new o(e.avcDecoderConfigRecord)),a.addBox(p)}else if(e.hevcDecoderConfigRecord){var c=new d.hvcCBox;c.parse(new o(e.hevcDecoderConfigRecord)),a.addBox(c)}break;case"Audio":n.add("smhd").set("balance",e.balance||0),a.set("channel_count",e.channel_count||2).set("samplesize",e.samplesize||16).set("samplerate",e.samplerate||65536);break;case"Hint":n.add("hmhd");break;case"Subtitle":n.add("sthd"),"stpp"===e.type&&a.set("namespace",e.namespace||"nonamespace").set("schema_location",e.schema_location||"").set("auxiliary_mime_types",e.auxiliary_mime_types||"");break;default:n.add("nmhd")}e.description&&a.addBox(e.description),e.description_boxes&&e.description_boxes.forEach(function(t){a.addBox(t)}),n.add("dinf").add("dref").addEntry(new d["url Box"]().set("flags",1));var m=n.add("stbl");return m.add("stsd").addEntry(a),m.add("stts").set("sample_counts",[]).set("sample_deltas",[]),m.add("stsc").set("first_chunk",[]).set("samples_per_chunk",[]).set("sample_description_index",[]),m.add("stco").set("chunk_offsets",[]),m.add("stsz").set("sample_sizes",[]),this.moov.mvex.add("trex").set("track_id",e.id).set("default_sample_description_index",e.default_sample_description_index||1).set("default_sample_duration",e.default_sample_duration||0).set("default_sample_size",e.default_sample_size||0).set("default_sample_flags",e.default_sample_flags||0),this.buildTrakSampleLists(r),e.id}},d.Box.prototype.computeSize=function(t){var e=t||new h;e.endianness=h.BIG_ENDIAN,this.write(e)},c.prototype.addSample=function(t,e,r){var s=r||{},n={},a=this.getTrackById(t);if(null!==a){n.number=a.samples.length,n.track_id=a.tkhd.track_id,n.timescale=a.mdia.mdhd.timescale,n.description_index=s.sample_description_index?s.sample_description_index-1:0,n.description=a.mdia.minf.stbl.stsd.entries[n.description_index],n.data=e,n.size=e.byteLength,n.alreadyRead=n.size,n.duration=s.duration||1,n.cts=s.cts||0,n.dts=s.dts||0,n.is_sync=s.is_sync||!1,n.is_leading=s.is_leading||0,n.depends_on=s.depends_on||0,n.is_depended_on=s.is_depended_on||0,n.has_redundancy=s.has_redundancy||0,n.degradation_priority=s.degradation_priority||0,n.offset=0,n.subsamples=s.subsamples,a.samples.push(n),a.samples_size+=n.size,a.samples_duration+=n.duration,void 0===a.first_dts&&(a.first_dts=s.dts),this.processSamples();var o=this.createSingleSampleMoof(n);return this.addBox(o),o.computeSize(),o.trafs[0].truns[0].data_offset=o.size+8,this.add("mdat").data=new Uint8Array(e),n}},c.prototype.createSingleSampleMoof=function(t){var e=0;e=t.is_sync?33554432:65536;var r=new d.moofBox;r.add("mfhd").set("sequence_number",this.nextMoofNumber),this.nextMoofNumber++;var s=r.add("traf"),n=this.getTrackById(t.track_id);return s.add("tfhd").set("track_id",t.track_id).set("flags",d.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),s.add("tfdt").set("baseMediaDecodeTime",t.dts-(n.first_dts||0)),s.add("trun").set("flags",d.TRUN_FLAGS_DATA_OFFSET|d.TRUN_FLAGS_DURATION|d.TRUN_FLAGS_SIZE|d.TRUN_FLAGS_FLAGS|d.TRUN_FLAGS_CTS_OFFSET).set("data_offset",0).set("first_sample_flags",0).set("sample_count",1).set("sample_duration",[t.duration]).set("sample_size",[t.size]).set("sample_flags",[e]).set("sample_composition_time_offset",[t.cts-t.dts]),r},c.prototype.lastMoofIndex=0,c.prototype.samplesDataSize=0,c.prototype.resetTables=function(){var t,e,r,s,n,a;for(this.initial_duration=this.moov.mvhd.duration,this.moov.mvhd.duration=0,t=0;t=2&&(l=n[o].grouping_type+"/0",(h=new u(n[o].grouping_type,0)).is_fragment=!0,e.sample_groups_info[l]||(e.sample_groups_info[l]=h))}else for(o=0;o=2&&(l=s[o].grouping_type+"/0",h=new u(s[o].grouping_type,0),t.sample_groups_info[l]||(t.sample_groups_info[l]=h))},c.setSampleGroupProperties=function(t,e,r,s){var n,a,o;for(n in e.sample_groups=[],s)e.sample_groups[n]={},e.sample_groups[n].grouping_type=s[n].grouping_type,e.sample_groups[n].grouping_type_parameter=s[n].grouping_type_parameter,r>=s[n].last_sample_in_run&&(s[n].last_sample_in_run<0&&(s[n].last_sample_in_run=0),s[n].entry_index++,s[n].entry_index<=s[n].sbgp.entries.length-1&&(s[n].last_sample_in_run+=s[n].sbgp.entries[s[n].entry_index].sample_count)),s[n].entry_index<=s[n].sbgp.entries.length-1?e.sample_groups[n].group_description_index=s[n].sbgp.entries[s[n].entry_index].group_description_index:e.sample_groups[n].group_description_index=-1,0!==e.sample_groups[n].group_description_index&&(o=s[n].fragment_description?s[n].fragment_description:s[n].description,e.sample_groups[n].group_description_index>0?(a=e.sample_groups[n].group_description_index>65535?(e.sample_groups[n].group_description_index>>16)-1:e.sample_groups[n].group_description_index-1,o&&a>=0&&(e.sample_groups[n].description=o.entries[a])):o&&o.version>=2&&o.default_group_description_index>0&&(e.sample_groups[n].description=o.entries[o.default_group_description_index-1]))},c.process_sdtp=function(t,e,r){e&&(t?(e.is_leading=t.is_leading[r],e.depends_on=t.sample_depends_on[r],e.is_depended_on=t.sample_is_depended_on[r],e.has_redundancy=t.sample_has_redundancy[r]):(e.is_leading=0,e.depends_on=0,e.is_depended_on=0,e.has_redundancy=0))},c.prototype.buildSampleLists=function(){var t,e;for(t=0;t"u")){for(e=0;ew&&(v++,w<0&&(w=0),w+=a.sample_counts[v]),e>0?(t.samples[e-1].duration=a.sample_deltas[v],t.samples_duration+=t.samples[e-1].duration,A.dts=t.samples[e-1].dts+t.samples[e-1].duration):A.dts=0,o?(e>=S&&(E++,S<0&&(S=0),S+=o.sample_counts[E]),A.cts=t.samples[e].dts+o.sample_offsets[E]):A.cts=A.dts,h?(e==h.sample_numbers[U]-1?(A.is_sync=!0,U++):(A.is_sync=!1,A.degradation_priority=0),u&&u.entries[x].sample_delta+T==e+1&&(A.subsamples=u.entries[x].subsamples,T+=u.entries[x].sample_delta,x++)):A.is_sync=!0,c.process_sdtp(t.mdia.minf.stbl.sdtp,A,A.number),p?A.degradation_priority=p.priority[e]:A.degradation_priority=0,u&&u.entries[x].sample_delta+T==e&&(A.subsamples=u.entries[x].subsamples,T+=u.entries[x].sample_delta),(d.length>0||f.length>0)&&c.setSampleGroupProperties(t,A,e,t.sample_groups_info)}e>0&&(t.samples[e-1].duration=Math.max(t.mdia.mdhd.duration-t.samples[e-1].dts,0),t.samples_duration+=t.samples[e-1].duration)}},c.prototype.updateSampleLists=function(){var t,e,r,s,n,a,o,h,l,u,f,p,m,g;if(void 0!==this.moov){for(;this.lastMoofIndex0&&c.initSampleGroups(f,u,u.sbgps,f.mdia.minf.stbl.sgpds,u.sgpds),e=0;e0?m.dts=f.samples[f.samples.length-2].dts+f.samples[f.samples.length-2].duration:(u.tfdt?m.dts=u.tfdt.baseMediaDecodeTime:m.dts=0,f.first_traf_merged=!0),m.cts=m.dts,y.flags&d.TRUN_FLAGS_CTS_OFFSET&&(m.cts=m.dts+y.sample_composition_time_offset[r]),g=o,y.flags&d.TRUN_FLAGS_FLAGS?g=y.sample_flags[r]:0===r&&y.flags&d.TRUN_FLAGS_FIRST_FLAG&&(g=y.first_sample_flags),m.is_sync=!(g>>16&1),m.is_leading=g>>26&3,m.depends_on=g>>24&3,m.is_depended_on=g>>22&3,m.has_redundancy=g>>20&3,m.degradation_priority=65535&g;var _=!!(u.tfhd.flags&d.TFHD_FLAG_BASE_DATA_OFFSET),b=!!(u.tfhd.flags&d.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),w=!!(y.flags&d.TRUN_FLAGS_DATA_OFFSET),v=0;v=_?u.tfhd.base_data_offset:b||0===e?l.start:h,0===e&&0===r?w?m.offset=v+y.data_offset:m.offset=v:m.offset=h,h=m.offset+m.size,(u.sbgps.length>0||u.sgpds.length>0||f.mdia.minf.stbl.sbgps.length>0||f.mdia.minf.stbl.sgpds.length>0)&&c.setSampleGroupProperties(f,m,m.number_in_traf,u.sample_groups_info)}}if(u.subs){f.has_fragment_subsamples=!0;var S=u.first_sample_index;for(e=0;e-1))return null;var o=(r=this.stream.buffers[n]).byteLength-(s.offset+s.alreadyRead-r.fileStart);if(s.size-s.alreadyRead<=o)return a.debug("ISOFile","Getting sample #"+e+" data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-r.fileStart)+" read size: "+(s.size-s.alreadyRead)+" full size: "+s.size+")"),h.memcpy(s.data.buffer,s.alreadyRead,r,s.offset+s.alreadyRead-r.fileStart,s.size-s.alreadyRead),r.usedBytes+=s.size-s.alreadyRead,this.stream.logBufferLevel(),s.alreadyRead=s.size,s;if(0===o)return null;a.debug("ISOFile","Getting sample #"+e+" partial data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-r.fileStart)+" read size: "+o+" full size: "+s.size+")"),h.memcpy(s.data.buffer,s.alreadyRead,r,s.offset+s.alreadyRead-r.fileStart,o),s.alreadyRead+=o,r.usedBytes+=o,this.stream.logBufferLevel()}},c.prototype.releaseSample=function(t,e){var r=t.samples[e];return r.data?(this.samplesDataSize-=r.size,r.data=null,r.alreadyRead=0,r.size):0},c.prototype.getAllocatedSampleDataSize=function(){return this.samplesDataSize},c.prototype.getCodecs=function(){var t,e="";for(t=0;t0&&(e+=","),e+=r.mdia.minf.stbl.stsd.entries[0].getCodec()}return e},c.prototype.getTrexById=function(t){var e;if(!this.moov||!this.moov.mvex)return null;for(e=0;e0&&(r.protection=n.ipro.protections[n.iinf.item_infos[t].protection_index-1]),n.iinf.item_infos[t].item_type?r.type=n.iinf.item_infos[t].item_type:r.type="mime",r.content_type=n.iinf.item_infos[t].content_type,r.content_encoding=n.iinf.item_infos[t].content_encoding;if(n.iloc)for(t=0;t0&&f.property_index-1-1))return null;var l=(e=this.stream.buffers[o]).byteLength-(n.offset+n.alreadyRead-e.fileStart);if(!(n.length-n.alreadyRead<=l))return a.debug("ISOFile","Getting item #"+t+" extent #"+s+" partial data (alreadyRead: "+n.alreadyRead+" offset: "+(n.offset+n.alreadyRead-e.fileStart)+" read size: "+l+" full extent size: "+n.length+" full item size: "+r.size+")"),h.memcpy(r.data.buffer,r.alreadyRead,e,n.offset+n.alreadyRead-e.fileStart,l),n.alreadyRead+=l,r.alreadyRead+=l,e.usedBytes+=l,this.stream.logBufferLevel(),null;a.debug("ISOFile","Getting item #"+t+" extent #"+s+" data (alreadyRead: "+n.alreadyRead+" offset: "+(n.offset+n.alreadyRead-e.fileStart)+" read size: "+(n.length-n.alreadyRead)+" full extent size: "+n.length+" full item size: "+r.size+")"),h.memcpy(r.data.buffer,r.alreadyRead,e,n.offset+n.alreadyRead-e.fileStart,n.length-n.alreadyRead),e.usedBytes+=n.length-n.alreadyRead,this.stream.logBufferLevel(),r.alreadyRead+=n.length-n.alreadyRead,n.alreadyRead=n.length}}return r.alreadyRead===r.size?r:null},c.prototype.releaseItem=function(t){var e=this.items[t];if(!e.data)return 0;this.itemsDataSize-=e.size,e.data=null,e.alreadyRead=0;for(var r=0;r0?this.moov.traks[t].samples[0].duration:0),e.push(s)}return e},d.Box.prototype.printHeader=function(t){this.size+=8,this.size>4294967296&&(this.size+=8),"uuid"===this.type&&(this.size+=16),t.log(t.indent+"size:"+this.size),t.log(t.indent+"type:"+this.type)},d.FullBox.prototype.printHeader=function(t){this.size+=4,d.Box.prototype.printHeader.call(this,t),t.log(t.indent+"version:"+this.version),t.log(t.indent+"flags:"+this.flags)},d.Box.prototype.print=function(t){this.printHeader(t)},d.ContainerBox.prototype.print=function(t){this.printHeader(t);for(var e=0;e>8)),t.log(t.indent+"matrix: "+this.matrix.join(", ")),t.log(t.indent+"next_track_id: "+this.next_track_id)},d.tkhdBox.prototype.print=function(t){d.FullBox.prototype.printHeader.call(this,t),t.log(t.indent+"creation_time: "+this.creation_time),t.log(t.indent+"modification_time: "+this.modification_time),t.log(t.indent+"track_id: "+this.track_id),t.log(t.indent+"duration: "+this.duration),t.log(t.indent+"volume: "+(this.volume>>8)),t.log(t.indent+"matrix: "+this.matrix.join(", ")),t.log(t.indent+"layer: "+this.layer),t.log(t.indent+"alternate_group: "+this.alternate_group),t.log(t.indent+"width: "+this.width),t.log(t.indent+"height: "+this.height)},(m={}).createFile=function(t,e){var r=new c(e);return r.discardMdatData=!(void 0===t||t),r},iT.createFile=m.createFile;let iA=/* @__PURE__ */ix(iT),iC={sampleRate:48e3,channelCount:2,codec:"mp4a.40.2"};function iI(t,e){let r=e.videoTracks[0],s={};if(null!=r){let n=function(t){for(let e of t.mdia.minf.stbl.stsd.entries){let t=e.avcC??e.hvcC??e.vpcC;if(null!=t){let e=new iA.DataStream(void 0,0,iA.DataStream.BIG_ENDIAN);return t.write(e),new Uint8Array(e.buffer.slice(8))}}throw Error("avcC, hvcC or VPX not found")}(t.getTrackById(r.id)).buffer,{descKey:a,type:o}=r.codec.startsWith("avc1")?{descKey:"avcDecoderConfigRecord",type:"avc1"}:r.codec.startsWith("hvc1")?{descKey:"hevcDecoderConfigRecord",type:"hvc1"}:{descKey:"",type:""};""!==a&&(s.videoTrackConf={timescale:r.timescale,duration:r.duration,width:r.video.width,height:r.video.height,brands:e.brands,type:o,[a]:n}),s.videoDecoderConf={codec:r.codec,codedHeight:r.video.height,codedWidth:r.video.width,description:n}}let n=e.audioTracks[0];if(null!=n){let e=iB(t);s.audioTrackConf={timescale:n.timescale,samplerate:n.audio.sample_rate,channel_count:n.audio.channel_count,hdlr:"soun",type:n.codec.startsWith("mp4a")?"mp4a":n.codec,description:iB(t)},s.audioDecoderConf={codec:n.codec.startsWith("mp4a")?iC.codec:n.codec,numberOfChannels:n.audio.channel_count,sampleRate:n.audio.sample_rate,...null==e?{}:function(t){var e;let r=null==(e=t.esd.descs[0])?void 0:e.descs[0];if(null==r)return{};let[s,n]=r.data;return{sampleRate:[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][((7&s)<<1)+(n>>7)],numberOfChannels:(127&n)>>3}}(e)}}return s}function iB(t,e="mp4a"){var r;let s=null==(r=t.moov)?void 0:r.traks.map(t=>t.mdia.minf.stbl.stsd.entries).flat().find(({type:t})=>t===e);return null==s?void 0:s.esds}class ik{constructor(){ey(this,"readable"),ey(this,"writable"),ew(this,A,0);let t=iA.createFile(),e=!1;this.readable=new ReadableStream({start:e=>{t.onReady=r=>{var s,n;let a=null==(s=r.videoTracks[0])?void 0:s.id;null!=a&&t.setExtractionOptions(a,"video",{nbSamples:100});let o=null==(n=r.audioTracks[0])?void 0:n.id;null!=o&&t.setExtractionOptions(o,"audio",{nbSamples:100}),e.enqueue({chunkType:"ready",data:{info:r,file:t}}),t.start()};let r={};t.onSamples=(s,n,a)=>{e.enqueue({chunkType:"samples",data:{id:s,type:n,samples:a.map(t=>({...t}))}}),r[s]=(r[s]??0)+a.length,t.releaseUsedSamples(s,r[s])},t.onFlush=()=>{e.close()}},cancel:()=>{t.stop(),e=!0}},{highWaterMark:50}),this.writable=new WritableStream({write:async r=>{if(e){this.writable.abort();return}let s=r.buffer;s.fileStart=eb(this,A),ev(this,A,eb(this,A)+s.byteLength),t.appendBuffer(s)},close:()=>{var e;t.flush(),t.stop(),null==(e=t.onFlush)||e.call(t)}})}}A=new WeakMap;let iF=0;function iR(t){return"file"===t.kind&&t.createReader instanceof Function}let iP=class t{constructor(t,e={audio:!0}){if(ew(this,C,e5.create(`MP4Clip id:${iF++},`)),ey(this,"ready"),ew(this,I,!1),ew(this,B,{duration:0,width:0,height:0,audioSampleRate:0,audioChanCount:0}),ew(this,k),ew(this,F,1),ew(this,R,[]),ew(this,P,[]),ew(this,z,null),ew(this,L,null),ew(this,D,{video:null,audio:null}),ew(this,M,{audio:!0}),ey(this,"tickInterceptor",async(t,e)=>e),ew(this,O,new AbortController),!(t instanceof ReadableStream)&&!iR(t)&&!Array.isArray(t.videoSamples))throw Error("Illegal argument");ev(this,M,{...e}),ev(this,F,"object"==typeof e.audio&&"volume"in e.audio?e.audio.volume:1);let r=async t=>(await eH(eb(this,k),t),await eb(this,k).stream());ev(this,k,iR(t)?t:"localFile"in t?t.localFile:e1()),this.ready=(t instanceof ReadableStream?r(t).then(t=>iL(t,eb(this,M))):iR(t)?t.stream().then(t=>iL(t,eb(this,M))):Promise.resolve(t)).then(async({videoSamples:t,audioSamples:e,decoderConf:r})=>{var s,n,a;ev(this,R,t),ev(this,P,e),ev(this,D,r);let{videoFrameFinder:o,audioFrameFinder:h}=(s={video:null==r.video?null:{...r.video,hardwareAcceleration:eb(this,M).__unsafe_hardwareAcceleration__},audio:r.audio},n=await eb(this,k).createReader(),{audioFrameFinder:null==(a=!1!==eb(this,M).audio?eb(this,F):null)||null==s.audio||0===e.length?null:new iM(n,e,s.audio,{volume:a,targetSampleRate:iC.sampleRate}),videoFrameFinder:null==s.video||0===t.length?null:new iD(n,t,s.video)});return ev(this,z,o),ev(this,L,h),ev(this,B,function(t,e,r){let s={duration:0,width:0,height:0,audioSampleRate:0,audioChanCount:0};null!=t.video&&e.length>0&&(s.width=t.video.codedWidth??0,s.height=t.video.codedHeight??0),null!=t.audio&&r.length>0&&(s.audioSampleRate=iC.sampleRate,s.audioChanCount=iC.channelCount);let n=0,a=0;if(e.length>0)for(let t=e.length-1;t>=0;t--){let r=e[t];if(!r.deleted){n=r.cts+r.duration;break}}if(r.length>0){let t=r.at(-1);a=t.cts+t.duration}return s.duration=Math.max(n,a),s}(r,t,e)),eb(this,C).info("MP4Clip meta:",eb(this,B)),{...eb(this,B)}})}get meta(){return{...eb(this,B)}}async tick(t){var e,r;if(t>=eb(this,B).duration)return await this.tickInterceptor(t,{audio:[],state:"done"});let[s,n]=await Promise.all([(null==(e=eb(this,L))?void 0:e.find(t))??[],null==(r=eb(this,z))?void 0:r.find(t)]);return null==n?await this.tickInterceptor(t,{audio:s,state:"success"}):await this.tickInterceptor(t,{video:n,audio:s,state:"success"})}async thumbnails(t=100,e){eb(this,O).abort(),ev(this,O,new AbortController);let r=eb(this,O).signal;await this.ready;let s="generate thumbnails aborted";if(r.aborted)throw Error(s);let{width:n,height:a}=eb(this,B),o=function(t,e,r){let s=new OffscreenCanvas(t,e),n=s.getContext("2d");return async a=>(n.drawImage(a,0,0,t,e),a.close(),await s.convertToBlob(r))}(t,Math.round(t/n*a),{quality:.1,type:"image/png"});return new Promise(async(t,n)=>{let a=[],h=eb(this,D).video;if(null==h||0===eb(this,R).length){l();return}async function l(){r.aborted||t(await Promise.all(a.map(async t=>({ts:t.ts,img:await t.img}))))}function u(t){a.push({ts:t.timestamp,img:o(t)})}r.addEventListener("abort",()=>{n(Error(s))});let{start:d=0,end:f=eb(this,B).duration,step:p}=e??{};if(p){let t=d,e=new iD(await eb(this,k).createReader(),eb(this,R),{...h,hardwareAcceleration:eb(this,M).__unsafe_hardwareAcceleration__});for(;t<=f&&!r.aborted;){let r=await e.find(t);r&&u(r),t+=p}e.destroy(),l()}else await iY(eb(this,R),eb(this,k),h,r,{start:d,end:f},(t,e)=>{u(t),e&&l()})})}async split(e){if(await this.ready,e<=0||e>=eb(this,B).duration)throw Error('"time" out of bounds');let[r,s]=function(t,e){if(0===t.length)return[];let r=0,s=0,n=-1;for(let a=0;a({...t}));for(let t=r;t({...t,cts:t.cts-e}));for(let t of h){if(t.cts>=0)break;t.deleted=!0,t.cts=-1}return[o,h]}(eb(this,R),e),[n,a]=function(t,e){if(0===t.length)return[];let r=-1;for(let s=0;st[s].cts)){r=s;break}if(-1===r)throw Error("Not found audio sample by time");return[t.slice(0,r),t.slice(r).map(t=>({...t,cts:t.cts-e}))]}(eb(this,P),e),o=new t({localFile:eb(this,k),videoSamples:r??[],audioSamples:n??[],decoderConf:eb(this,D)},eb(this,M)),h=new t({localFile:eb(this,k),videoSamples:s??[],audioSamples:a??[],decoderConf:eb(this,D)},eb(this,M));return await Promise.all([o.ready,h.ready]),[o,h]}async clone(){await this.ready;let e=new t({localFile:eb(this,k),videoSamples:[...eb(this,R)],audioSamples:[...eb(this,P)],decoderConf:eb(this,D)},eb(this,M));return await e.ready,e.tickInterceptor=this.tickInterceptor,e}async splitTrack(){await this.ready;let e=[];if(eb(this,R).length>0){let r=new t({localFile:eb(this,k),videoSamples:[...eb(this,R)],audioSamples:[],decoderConf:{video:eb(this,D).video,audio:null}},eb(this,M));await r.ready,r.tickInterceptor=this.tickInterceptor,e.push(r)}if(eb(this,P).length>0){let r=new t({localFile:eb(this,k),videoSamples:[],audioSamples:[...eb(this,P)],decoderConf:{audio:eb(this,D).audio,video:null}},eb(this,M));await r.ready,r.tickInterceptor=this.tickInterceptor,e.push(r)}return e}destroy(){var t,e;eb(this,I)||(eb(this,C).info("MP4Clip destroy"),ev(this,I,!0),null==(t=eb(this,z))||t.destroy(),null==(e=eb(this,L))||e.destroy())}};C=new WeakMap,I=new WeakMap,B=new WeakMap,k=new WeakMap,F=new WeakMap,R=new WeakMap,P=new WeakMap,z=new WeakMap,L=new WeakMap,D=new WeakMap,M=new WeakMap,O=new WeakMap;let iz=iP;async function iL(t,e={}){let r;let s={video:null,audio:null},n=[],a=[];return new Promise(async(h,l)=>{let u=-1,d=-1,f=iE(t.pipeThrough(new ik),{onChunk:async({chunkType:t,data:h})=>{if("ready"===t){r=h.info;let{videoDecoderConf:t,audioDecoderConf:e}=iI(h.file,h.info);s.video=t??null,s.audio=e??null,null==t&&null==e&&(f(),l(Error("MP4Clip must contain at least one video or audio track"))),e5.info("mp4BoxFile moov ready",{...h.info,tracks:null,videoTracks:null,audioTracks:null},s)}else if("samples"===t){if("video"===h.type)for(let t of(-1===u&&(u=h.samples[0].dts),h.samples))n.push(o(t,u,"video"));else if("audio"===h.type&&e.audio)for(let t of(-1===d&&(d=h.samples[0].dts),h.samples))a.push(o(t,d,"audio"))}},onDone:()=>{let t=n.at(-1)??a.at(-1);if(null==r){l(Error("MP4Clip stream is done, but not emit ready"));return}if(null==t){l(Error("MP4Clip stream not contain any sample"));return}let e=n[0];null!=e&&e.cts<2e5&&(e.duration+=e.cts,e.cts=0),e5.info("mp4 stream parsed"),h({videoSamples:n,audioSamples:a,decoderConf:s})}})});function o(t,e=0,r){return{...t,is_idr:"video"===r&&t.is_sync&&function(t){let e=new DataView(t.buffer),r=0;for(;r((null==eb(this,N)||t<=eb(this,G)||t-eb(this,G)>3e6)&&eb(this,Q).call(this,t),eb(this,Y).abort=!0,ev(this,G,t),ev(this,Y,{abort:!1,st:performance.now()}),await eb(this,$).call(this,t,eb(this,N),eb(this,Y)))),ew(this,W,0),ew(this,V,!1),ew(this,H,0),ew(this,X,[]),ew(this,j,0),ew(this,Z,0),ew(this,$,async(t,e,r)=>{if(null==e||"closed"===e.state||r.abort)return null;if(eb(this,X).length>0){let s=eb(this,X)[0];return ts.timestamp+(s.duration??0)?(s.close(),await eb(this,$).call(this,t,e,r)):(eb(this,X).length<10&&eb(this,q).call(this,e).catch(e=>{throw eb(this,Q).call(this,t),e}),s))}if(eb(this,K)||eb(this,j)0){if(performance.now()-r.st>3e3)throw Error(`MP4Clip.tick video timeout, ${JSON.stringify(eb(this,J).call(this))}`);await iv(15)}else{if(eb(this,H)>=this.samples.length)return null;try{await eb(this,q).call(this,e)}catch(e){throw eb(this,Q).call(this,t),e}}return await eb(this,$).call(this,t,e,r)}),ew(this,K,!1),ew(this,q,async t=>{var e,r;if(eb(this,K))return;ev(this,K,!0);let s=eb(this,H)+1,n=!1;for(;s{if(eb(this,V))throw t;ev(this,V,!0),e5.warn("Downgrade to software decode"),eb(this,Q).call(this)}}),ev(this,Z,eb(this,Z)+e.length)}}ev(this,H,s),ev(this,K,!1)}),ew(this,Q,t=>{var e,r;if(ev(this,K,!1),eb(this,X).forEach(t=>t.close()),ev(this,X,[]),null==t||0===t)ev(this,H,0);else{let e=0;for(let r=0;r{if(ev(this,j,eb(this,j)+1),-1===t.timestamp){t.close();return}let e=t;null==t.duration&&(e=new VideoFrame(t,{duration:eb(this,W)}),t.close()),eb(this,X).push(e)},error:t=>{e5.error(`MP4Clip VideoDecoder err: ${t.message}`)}})),eb(this,N).configure({...this.conf,...eb(this,V)?{hardwareAcceleration:"prefer-software"}:{}})}),ew(this,J,()=>{var t,e;return{time:eb(this,G),decState:null==(t=eb(this,N))?void 0:t.state,decQSize:null==(e=eb(this,N))?void 0:e.decodeQueueSize,decCusorIdx:eb(this,H),sampleLen:this.samples.length,inputCnt:eb(this,Z),outputCnt:eb(this,j),cacheFrameLen:eb(this,X).length,softDeocde:eb(this,V)}}),ey(this,"destroy",()=>{var t,e;(null==(t=eb(this,N))?void 0:t.state)!=="closed"&&(null==(e=eb(this,N))||e.close()),ev(this,N,null),eb(this,Y).abort=!0,eb(this,X).forEach(t=>t.close()),ev(this,X,[]),this.localFileReader.close()}),this.localFileReader=t,this.samples=e,this.conf=r}}N=new WeakMap,G=new WeakMap,Y=new WeakMap,W=new WeakMap,V=new WeakMap,H=new WeakMap,X=new WeakMap,j=new WeakMap,Z=new WeakMap,$=new WeakMap,K=new WeakMap,q=new WeakMap,Q=new WeakMap,J=new WeakMap;class iM{constructor(t,e,r,s){ew(this,tt,1),ew(this,te),ew(this,ti,null),ew(this,tr,{abort:!1,st:performance.now()}),ey(this,"find",async t=>{if(null==eb(this,ti)||t<=eb(this,ts)||t-eb(this,ts)>1e5){eb(this,tl).call(this),ev(this,ts,t);for(let e=0;e{if(null==e||r.abort||"closed"===e.state)return[];let s=Math.ceil(t*(eb(this,te)/1e6));if(0===s)return[];let n=eb(this,ta).frameCnt-s;if(n>0)return ne){let h=e-s;r[0].set(a.subarray(0,h),s),r[1].set(o.subarray(0,h),s),t.data[n][0]=a.subarray(h,a.length),t.data[n][1]=o.subarray(h,o.length);break}r[0].set(a,s),r[1].set(o,s),s+=a.length,n++}return t.data=t.data.slice(n),t.frameCnt-=e,r}(eb(this,ta),s);if(e.decodeQueueSize>10){if(performance.now()-r.st>3e3)throw r.abort=!0,Error(`MP4Clip.tick audio timeout, ${JSON.stringify(eb(this,tu).call(this))}`);await iv(15)}else{if(eb(this,tn)>=this.samples.length-1)return[];eb(this,th).call(this,e)}return eb(this,to).call(this,t,e,r)}),ew(this,th,t=>{if(t.decodeQueueSize>100)return;let e=[],r=eb(this,tn);for(;r=10))break}ev(this,tn,r),t.decode(e.map(t=>new EncodedAudioChunk({type:"key",timestamp:t.cts,duration:t.duration,data:t.data})))}),ew(this,tl,()=>{var t;ev(this,ts,0),ev(this,tn,0),ev(this,ta,{frameCnt:0,data:[]}),null==(t=eb(this,ti))||t.close(),ev(this,ti,function(t,e,r){let s=t=>{if(0!==t.length){if(1!==e.volume)for(let r of t)for(let t=0;t{let r=n;n+=1,t().then(t=>{e[r]=t,s()}).catch(t=>{e[r]=t,s()})}}(s),a=e.resampleRate!==t.sampleRate,o=new AudioDecoder({output:t=>{let r=im(t);a?n(()=>iw(r,t.sampleRate,{rate:e.resampleRate,chanCount:t.numberOfChannels})):s(r),t.close()},error:t=>{e5.error(`MP4Clip AudioDecoder err: ${t.message}`)}});return o.configure(t),{decode(t){for(let e of t)o.decode(e)},close(){"closed"!==o.state&&o.close()},get state(){return o.state},get decodeQueueSize(){return o.decodeQueueSize}}}(this.conf,{resampleRate:iC.sampleRate,volume:eb(this,tt)},t=>{eb(this,ta).data.push(t),eb(this,ta).frameCnt+=t[0].length}))}),ew(this,tu,()=>{var t,e;return{time:eb(this,ts),decState:null==(t=eb(this,ti))?void 0:t.state,decQSize:null==(e=eb(this,ti))?void 0:e.decodeQueueSize,decCusorIdx:eb(this,tn),sampleLen:this.samples.length,pcmLen:eb(this,ta).frameCnt}}),ey(this,"destroy",()=>{ev(this,ti,null),eb(this,tr).abort=!0,ev(this,ta,{frameCnt:0,data:[]}),this.localFileReader.close()}),this.localFileReader=t,this.samples=e,this.conf=r,ev(this,tt,s.volume),ev(this,te,s.targetSampleRate)}}async function iO(t,e){let r=t[0],s=t.at(-1);if(null==s)return[];let n=s.offset+s.size-r.offset;if(n<3e7){let s=new Uint8Array(await e.read(n,{at:r.offset}));return t.map(t=>{let e=t.offset-r.offset,n=s.subarray(e,e+t.size);return t.is_idr&&(n=iG(n)),new EncodedVideoChunk({type:t.is_sync?"key":"delta",timestamp:t.cts,duration:t.duration,data:n})})}return await Promise.all(t.map(async t=>{let r=await e.read(t.size,{at:t.offset});return t.is_idr&&(r=iG(new Uint8Array(r))),new EncodedVideoChunk({type:t.is_sync?"key":"delta",timestamp:t.cts,duration:t.duration,data:r})}))}function iN(t,e,r){let s=0;if("configured"===t.state){for(;s{if(!(t instanceof Error))throw t;if(t.message.includes("Decoding error")&&null!=r.onDecodingError){r.onDecodingError(t);return}if(!t.message.includes("Aborted due to close"))throw t})}}function iG(t){let e=new DataView(t.buffer);return(31&e.getUint8(4))==6?t.subarray(e.getUint32(0)+4):t}async function iY(t,e,r,s,n,a){let o=await e.createReader(),h=0,l=new VideoDecoder({output:t=>{let e=(h+=1)===u.length;a(t,e),e&&o.close()},error:e5.error});s.addEventListener("abort",()=>{o.close(),l.close()});let u=await iO(t.filter(t=>!t.deleted&&t.is_sync&&t.cts>=n.start&&t.cts<=n.end),o);0===u.length||s.aborted||(l.configure(r),iN(l,u,{}))}tt=new WeakMap,te=new WeakMap,ti=new WeakMap,tr=new WeakMap,ts=new WeakMap,tn=new WeakMap,ta=new WeakMap,to=new WeakMap,th=new WeakMap,tl=new WeakMap,tu=new WeakMap;let iW=class t{constructor(t){ew(this,tc),ey(this,"ready"),ew(this,td,{duration:0,width:0,height:0}),ew(this,tf,null),ew(this,tp,[]);let e=t=>(ev(this,tf,t),eb(this,td).width=t.width,eb(this,td).height=t.height,eb(this,td).duration=1/0,{...eb(this,td)});if(t instanceof ReadableStream)this.ready=new Response(t).blob().then(t=>createImageBitmap(t)).then(e);else if(t instanceof ImageBitmap)this.ready=Promise.resolve(e(t));else if(Array.isArray(t)&&t.every(t=>t instanceof VideoFrame)){ev(this,tp,t);let e=eb(this,tp)[0];if(null==e)throw Error("The frame count must be greater than 0");ev(this,td,{width:e.displayWidth,height:e.displayHeight,duration:eb(this,tp).reduce((t,e)=>t+(e.duration??0),0)}),this.ready=Promise.resolve({...eb(this,td),duration:1/0})}else if("type"in t)this.ready=eS(this,tc,tm).call(this,t.stream,t.type).then(()=>({width:eb(this,td).width,height:eb(this,td).height,duration:1/0}));else throw Error("Illegal arguments")}get meta(){return{...eb(this,td)}}async tick(t){if(null!=eb(this,tf))return{video:await createImageBitmap(eb(this,tf)),state:"success"};let e=t%eb(this,td).duration;return{video:(eb(this,tp).find(t=>e>=t.timestamp&&e<=t.timestamp+(t.duration??0))??eb(this,tp)[0]).clone(),state:"success"}}async split(e){if(await this.ready,null!=eb(this,tf))return[new t(await createImageBitmap(eb(this,tf))),new t(await createImageBitmap(eb(this,tf)))];let r=-1;for(let t=0;teb(this,tp)[t].timestamp)){r=t;break}if(-1===r)throw Error("Not found frame by time");let s=eb(this,tp).slice(0,r).map(t=>new VideoFrame(t)),n=eb(this,tp).slice(r).map(t=>new VideoFrame(t,{timestamp:t.timestamp-e}));return[new t(s),new t(n)]}async clone(){return await this.ready,new t(null==eb(this,tf)?eb(this,tp).map(t=>t.clone()):await createImageBitmap(eb(this,tf)))}destroy(){var t;e5.info("ImgClip destroy"),null==(t=eb(this,tf))||t.close(),eb(this,tp).forEach(t=>t.close())}};td=new WeakMap,tf=new WeakMap,tp=new WeakMap,tc=new WeakSet,tm=async function(t,e){ev(this,tp,await i_(t,e));let r=eb(this,tp)[0];if(null==r)throw Error("No frame available in gif");ev(this,td,{duration:eb(this,tp).reduce((t,e)=>t+(e.duration??0),0),width:r.codedWidth,height:r.codedHeight}),e5.info("ImgClip ready:",eb(this,td))};let iV=iW,iH=class t{constructor(t,e={}){ew(this,tw),ey(this,"ready"),ew(this,tg,{duration:0,width:0,height:0}),ew(this,ty,new Float32Array),ew(this,t_,new Float32Array),ew(this,tb),ew(this,tS,0),ew(this,tE,0),ev(this,tb,{loop:!1,volume:1,...e}),this.ready=eS(this,tw,tv).call(this,t).then(()=>({width:0,height:0,duration:e.loop?1/0:eb(this,tg).duration}))}get meta(){return{...eb(this,tg),sampleRate:iC.sampleRate,chanCount:2}}getPCMData(){return[eb(this,ty),eb(this,t_)]}async tick(t){if(!eb(this,tb).loop&&t>=eb(this,tg).duration)return{audio:[],state:"done"};let e=t-eb(this,tS);if(t3e6)return ev(this,tS,t),ev(this,tE,Math.ceil(eb(this,tS)/1e6*iC.sampleRate)),{audio:[new Float32Array(0),new Float32Array(0)],state:"success"};ev(this,tS,t);let r=Math.ceil(e/1e6*iC.sampleRate),s=eb(this,tE)+r,n=eb(this,tb).loop?[iS(eb(this,ty),eb(this,tE),s),iS(eb(this,t_),eb(this,tE),s)]:[eb(this,ty).slice(eb(this,tE),s),eb(this,t_).slice(eb(this,tE),s)];return ev(this,tE,s),{audio:n,state:"success"}}async split(e){await this.ready;let r=Math.ceil(e/1e6*iC.sampleRate);return[new t(this.getPCMData().map(t=>t.slice(0,r)),eb(this,tb)),new t(this.getPCMData().map(t=>t.slice(r)),eb(this,tb))]}async clone(){await this.ready;let e=new t(this.getPCMData(),eb(this,tb));return await e.ready,e}destroy(){ev(this,ty,new Float32Array(0)),ev(this,t_,new Float32Array(0)),e5.info("---- audioclip destroy ----")}};tg=new WeakMap,ty=new WeakMap,t_=new WeakMap,tb=new WeakMap,tw=new WeakSet,tv=async function(t){null==iH.ctx&&(iH.ctx=new AudioContext({sampleRate:iC.sampleRate}));let e=performance.now(),r=t instanceof ReadableStream?await iZ(t,iH.ctx):t;e5.info("Audio clip decoded complete:",performance.now()-e);let s=eb(this,tb).volume;if(1!==s)for(let t of r)for(let e=0;e{}),ey(this,"audioTrack"),ew(this,tT,null),ew(this,tA),ev(this,tA,t);let e=t.getVideoTracks()[0];if(null!=e){var r;let{width:t,height:s}=e.getSettings();e.contentHint="motion",eb(this,tU).width=t??0,eb(this,tU).height=s??0,ev(this,tT,new OffscreenCanvas(t??0,s??0)),ev(this,tx,(r=eb(this,tT).getContext("2d"),iE(new MediaStreamTrackProcessor({track:e}).readable,{onChunk:async t=>{r.drawImage(t,0,0),t.close()},onDone:async()=>{}})))}this.audioTrack=t.getAudioTracks()[0]??null,eb(this,tU).duration=1/0,this.ready=Promise.resolve(this.meta)}get meta(){return{...eb(this,tU)}}async tick(){return{video:null==eb(this,tT)?null:await createImageBitmap(eb(this,tT)),audio:[],state:"success"}}async split(){return[await this.clone(),await this.clone()]}async clone(){return new t(eb(this,tA).clone())}destroy(){eb(this,tA).getTracks().forEach(t=>t.stop()),eb(this,tx).call(this)}};tU=new WeakMap,tx=new WeakMap,tT=new WeakMap,tA=new WeakMap,ey(i$,"ctx",null);let iK=i$,iq=class t{constructor(t,e){var r;if(ew(this,tL),ey(this,"ready"),ew(this,tC,[]),ew(this,tI,{width:0,height:0,duration:0}),ew(this,tB,{color:"#FFF",textBgColor:null,type:"srt",fontSize:30,letterSpacing:null,bottomOffset:30,fontFamily:"Noto Sans SC",strokeStyle:"#000",lineWidth:null,lineCap:null,lineJoin:null,textShadow:{offsetX:2,offsetY:2,blur:4,color:"#000"},videoWidth:1280,videoHeight:720}),ew(this,tk),ew(this,tF),ew(this,tR,null),ew(this,tP,0),ew(this,tz,0),ev(this,tC,Array.isArray(t)?t:t.split(/\r|\n/).map(t=>t.trim()).filter(t=>t.length>0).map(t=>({lineStr:t,match:t.match(/(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})/)})).filter(({lineStr:t},e,r)=>{var s;return!(/^\d+$/.test(t)&&(null==(s=r[e+1])?void 0:s.match)!=null)}).reduce((t,{lineStr:e,match:r})=>{if(null==r){let r=t.at(-1);if(null==r)return t;r.text+=0===r.text.length?e:` ${e}`}else t.push({start:iJ(r[1]),end:iJ(r[2]),text:""});return t},[]).map(({start:t,end:e,text:r})=>({start:1e6*t,end:1e6*e,text:r}))),0===eb(this,tC).length)throw Error("No subtitles content");ev(this,tB,Object.assign(eb(this,tB),e)),ev(this,tz,null==e.textBgColor?0:(e.fontSize??50)*.2);let{fontSize:s,fontFamily:n,videoWidth:a,videoHeight:o,letterSpacing:h}=eb(this,tB);ev(this,tP,s+2*eb(this,tz)),ev(this,tk,new OffscreenCanvas(a,o)),ev(this,tF,eb(this,tk).getContext("2d")),eb(this,tF).font=`${s}px ${n}`,eb(this,tF).textAlign="center",eb(this,tF).textBaseline="top",eb(this,tF).letterSpacing=h??"0px",ev(this,tI,{width:a,height:o,duration:(null==(r=eb(this,tC).at(-1))?void 0:r.end)??0}),this.ready=Promise.resolve(this.meta)}get meta(){return{...eb(this,tI)}}async tick(t){var e,r;if(null!=eb(this,tR)&&t>=eb(this,tR).timestamp&&t<=eb(this,tR).timestamp+(eb(this,tR).duration??0))return{video:eb(this,tR).clone(),state:"success"};let s=0;for(;sn.end)return{state:"done"};if(teb(this,tC)[t].start)){r=t;break}if(-1===r)throw Error("Not found subtitle by time");let s=eb(this,tC).slice(0,r).map(t=>({...t})),n=s.at(-1),a=null;null!=n&&n.end>e&&(a={start:0,end:n.end-e,text:n.text},n.end=e);let o=eb(this,tC).slice(r).map(t=>({...t,start:t.start-e,end:t.end-e}));return null!=a&&o.unshift(a),[new t(s,eb(this,tB)),new t(o,eb(this,tB))]}async clone(){return new t(eb(this,tC).slice(0),eb(this,tB))}destroy(){var t;null==(t=eb(this,tR))||t.close()}};tC=new WeakMap,tI=new WeakMap,tB=new WeakMap,tk=new WeakMap,tF=new WeakMap,tR=new WeakMap,tP=new WeakMap,tz=new WeakMap,tL=new WeakSet,tD=function(t){let e=t.split(` `).reverse().map(t=>t.trim()),{width:r,height:s}=eb(this,tk),{color:n,fontSize:a,textBgColor:o,textShadow:h,strokeStyle:l,lineWidth:u,lineCap:d,lineJoin:f,bottomOffset:p}=eb(this,tB),c=eb(this,tF);c.clearRect(0,0,r,s),c.globalAlpha=.6;let m=p;for(let t of e){let e=c.measureText(t),p=r/2;null!=o&&(c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=0,c.fillStyle=o,c.globalAlpha=.5,c.fillRect(p-e.actualBoundingBoxLeft-eb(this,tz),s-m-eb(this,tP),e.width+2*eb(this,tz),eb(this,tP))),c.shadowColor=h.color,c.shadowOffsetX=h.offsetX,c.shadowOffsetY=h.offsetY,c.shadowBlur=h.blur,c.globalAlpha=1,null!=l&&(c.lineWidth=u??a/6,null!=d&&(c.lineCap=d),null!=f&&(c.lineJoin=f),c.strokeStyle=l,c.strokeText(t,p,s-m-eb(this,tP)+eb(this,tz))),c.fillStyle=n,c.fillText(t,p,s-m-eb(this,tP)+eb(this,tz)),m+=eb(this,tP)+.2*a}};let iQ=iq;function iJ(t){let e=t.match(/(\d{2}):(\d{2}):(\d{2}),(\d{3})/);if(null==e)throw Error(`time format error: ${t}`);let r=Number(e[1]);return 3600*r+60*Number(e[2])+Number(e[3])+Number(e[4])/1e3}class i0{constructor(){ew(this,tM,/* @__PURE__ */new Map),ey(this,"on",(t,e)=>{let r=eb(this,tM).get(t)??/* @__PURE__ */new Set;return r.add(e),eb(this,tM).has(t)||eb(this,tM).set(t,r),()=>{r.delete(e),0===r.size&&eb(this,tM).delete(t)}}),ey(this,"once",(t,e)=>{let r=this.on(t,(...t)=>{r(),e(...t)});return r}),ey(this,"emit",(t,...e)=>{let r=eb(this,tM).get(t);null!=r&&r.forEach(t=>t(...e))})}static forwardEvent(t,e,r){let s=r.map(r=>{let[s,n]=Array.isArray(r)?r:[r,r];return t.on(s,(...t)=>{e.emit(n,...t)})});return()=>{s.forEach(t=>t())}}destroy(){eb(this,tM).clear()}}tM=new WeakMap;let i1=(t,e)=>{let r=new Uint8Array(8);new DataView(r.buffer).setUint32(0,e);for(let e=0;e<4;e++)r[4+e]=t.charCodeAt(e);return r},i2=()=>{let t=new TextEncoder,e=t.encode("mdta"),r=t.encode("mp4 handler"),s=32+r.byteLength+1,n=new Uint8Array(s),a=new DataView(n.buffer);return n.set(i1("hdlr",s),0),a.setUint32(8,0),n.set(e,16),n.set(r,32),n},i3=t=>{let e=new TextEncoder,r=e.encode("mdta"),s=t.map(t=>{let s=e.encode(t),n=8+s.byteLength,a=new Uint8Array(n);return new DataView(a.buffer).setUint32(0,n),a.set(r,4),a.set(s,4+r.byteLength),a}),n=16+s.reduce((t,e)=>t+e.byteLength,0),a=new Uint8Array(n),o=new DataView(a.buffer);a.set(i1("keys",n),0),o.setUint32(8,0),o.setUint32(12,t.length);let h=16;for(let t of s)a.set(t,h),h+=t.byteLength;return a},i6=t=>{let e=new TextEncoder,r=e.encode("data"),s=Object.entries(t).map(([t,s],n)=>{let a=e.encode(s),o=24+a.byteLength,h=new Uint8Array(o),l=new DataView(h.buffer);return l.setUint32(0,o),l.setUint32(4,n+1),l.setUint32(8,16+a.byteLength),h.set(r,12),l.setUint32(16,1),h.set(a,24),h}),n=8+s.reduce((t,e)=>t+e.byteLength,0),a=new Uint8Array(n);a.set(i1("ilst",n),0);let o=8;for(let t of s)a.set(t,o),o+=t.byteLength;return a},i8=t=>{let e=i2(),r=i3(Object.keys(t)),s=i6(t),n=new Uint8Array(e.length+r.length+s.length);return n.set(e,0),n.set(r,e.length),n.set(s,e.length+r.length),n};function i4(t){e5.info("recodemux opts:",t);let e=iA.createFile(),r=new i0,s=(t,e)=>{let r=t.add("udta").add("meta");r.data=i8(e),r.size=r.data.byteLength},n=!1,a=()=>{null==e.moov||n||(n=!0,null!=t.metaDataTags&&s(e.moov,t.metaDataTags),null!=t.duration&&(e.moov.mvhd.duration=t.duration))};r.once("VideoReady",a),r.once("AudioReady",a);let o=null!=t.video?function(t,e,r){let s={timescale:1e6,width:t.width,height:t.height,brands:["isom","iso2","avc1","mp42","mp41"],avcDecoderConfigRecord:null,name:"Track created with WebAV"},n=-1,a=!1;r.once("AudioReady",()=>{a=!0});let o={encoder0:[],encoder1:[]},h=(t,a,h)=>{var l;if(-1===n&&null!=h){let t=null==(l=h.decoderConfig)?void 0:l.description;(function(t){let e=new Uint8Array(t);e[2].toString(2).slice(-2).includes("1")&&(e[2]=0)})(t),s.avcDecoderConfigRecord=t,n=e.addTrack(s),r.emit("VideoReady"),e5.info("VideoEncoder, video track ready, trackId:",n)}o[t].push(i7(a))},l="encoder1",u=0;function d(){if(!a)return;let t="encoder1"===l?"encoder0":"encoder1",r=o[l],s=o[t];if(0===r.length&&0===s.length)return;let h=r[0];if(null!=h&&h.cts-u<1e4){let t=function(t){let r=-1,s=0;for(;s0&&a.is_sync)break;e.addSample(n,a.data,a),r=a.cts+a.duration}return t.splice(0,s),r}(r);t>u&&(u=t)}let f=s[0];null!=f&&f.cts-u<1e4&&(l=t,d())}let f=is(d,15),p=i5(t,(t,e)=>h("encoder0",t,e)),c=i5(t,(t,e)=>h("encoder1",t,e)),m=0;return{get encodeQueueSize(){return p.encodeQueueSize+c.encodeQueueSize},encode:(t,e)=>{e.keyFrame&&(m+=1),(m%2==0?p:c).encode(t,e)},flush:async()=>{await Promise.all(["configured"===p.state?await p.flush():null,"configured"===c.state?await c.flush():null]),f(),d()},close:()=>{"configured"===p.state&&p.close(),"configured"===c.state&&c.close()}}}(t.video,e,r):null,h=null!=t.audio?function(t,e,r){let s={timescale:1e6,samplerate:t.sampleRate,channel_count:t.channelCount,hdlr:"soun",type:"aac"===t.codec?"mp4a":"Opus",name:"Track created with WebAV"},n=-1,a=[],o=!1;r.once("VideoReady",()=>{o=!0,a.forEach(t=>{let r=i7(t);e.addSample(n,r.data,r)}),a=[]});let h=new AudioEncoder({error:e5.error,output:(t,h)=>{var l;if(-1===n){let t=null==(l=h.decoderConfig)?void 0:l.description;n=e.addTrack({...s,description:null==t?void 0:function(t){let e=t.byteLength,r=new Uint8Array([0,0,0,0,3,23+e,0,2,0,4,18+e,64,21,0,0,0,0,0,0,0,0,0,0,0,5,e,...new Uint8Array(t instanceof ArrayBuffer?t:t.buffer),6,1,2]),s=new iA.BoxParser.esdsBox(r.byteLength);return s.hdr_size=0,s.parse(new iA.DataStream(r,0,iA.DataStream.BIG_ENDIAN)),s}(t)}),r.emit("AudioReady"),e5.info("AudioEncoder, audio track ready, trackId:",n)}if(o){let r=i7(t);e.addSample(n,r.data,r)}else a.push(t)}});return h.configure({codec:"aac"===t.codec?iC.codec:"opus",sampleRate:t.sampleRate,numberOfChannels:t.channelCount,bitrate:128e3}),h}(t.audio,e,r):null;return null==t.video&&r.emit("VideoReady"),null==t.audio&&r.emit("AudioReady"),{encodeVideo:(t,e)=>{null==o||o.encode(t,e),t.close()},encodeAudio:t=>{null!=h&&(h.encode(t),t.close())},getEncodeQueueSize:()=>(null==o?void 0:o.encodeQueueSize)??(null==h?void 0:h.encodeQueueSize)??0,flush:async()=>{await Promise.all([null==o?void 0:o.flush(),(null==h?void 0:h.state)==="configured"?h.flush():null])},close:()=>{r.destroy(),null==o||o.close(),(null==h?void 0:h.state)==="configured"&&h.close()},mp4file:e}}function i5(t,e){let r=new VideoEncoder({error:e5.error,output:e});return r.configure({codec:t.codec,framerate:t.expectFPS,hardwareAcceleration:t.__unsafe_hardwareAcceleration__,bitrate:t.bitrate,width:t.width,height:t.height,alpha:"discard",avc:{format:"avc"}}),r}function i9(t,e,r){let s=0,n=0,a=t.boxes,o=!1,h=()=>{var e;if(!o){if(null==a.find(t=>"moof"===t.type))return null;o=!0}if(n>=a.length)return null;let r=new iA.DataStream;r.endianness=iA.DataStream.BIG_ENDIAN;let s=n;try{for(;s{let t=h();null==t||u||r.enqueue(t)},e),d=e=>{if(clearInterval(s),t.flush(),null!=e){r.error(e);return}let n=h();null==n||u||r.enqueue(n),u||r.close()},l&&d()},cancel(){u=!0,clearInterval(s),null==r||r()}}),stop:t=>{l||(l=!0,null==d||d(t))}}}function i7(t){let e=new ArrayBuffer(t.byteLength);t.copyTo(e);let r=t.timestamp;return{duration:t.duration??0,dts:r,cts:r,is_sync:"key"===t.type,data:e}}async function rt(t){let e=iA.createFile(),r=function(t){let e=0,r=t.boxes,s=[],n=0;async function a(){let a=c(r,e);e=r.length,s.forEach(({track:e,id:r})=>{let s=e.samples.at(-1);null!=s&&(n=Math.max(n,s.cts+s.duration)),t.releaseUsedSamples(r,e.samples.length),e.samples=[]}),t.mdats=[],t.moofs=[],null!=a&&await (null==d?void 0:d.write(a))}let o=[];function h(){if(o.length>0)return!0;let n=r.findIndex(t=>"moov"===t.type);if(-1===n)return!1;if(o=r.slice(0,n+1),e=n+1,0===s.length)for(let e=1;;e+=1){let r=t.getTrackById(e);if(null==r)break;s.push({track:r,id:e})}return!0}let l=0,u=e1(),d=null,f=(async()=>{d=await u.createWriter(),l=self.setInterval(()=>{h()&&a()},100)})(),p=!1;return async()=>{if(p)throw Error("File exported");if(p=!0,await f,clearInterval(l),!h()||null==d)return null;t.flush(),await a(),await (null==d?void 0:d.close());let e=o.find(t=>"moov"===t.type);if(null==e)return null;e.mvhd.duration=n;let r=e1(),s=c(o,0);return await eH(r,s),await eH(r,u,{overwrite:!1}),await r.stream()};function c(t,e){if(e>=t.length)return null;let r=new iA.DataStream;r.endianness=iA.DataStream.BIG_ENDIAN;for(let s=e;s{iE(d.pipeThrough(new ik),{onDone:t,onChunk:async({chunkType:t,data:d})=>{if("ready"===t){let{videoTrackConf:t,audioTrackConf:s}=iI(d.file,d.info);0===r&&null!=t&&(r=e.addTrack(t)),0===a&&null!=s&&(a=e.addTrack(s))}else if("samples"===t){let{type:t,samples:f}=d,p="video"===t?r:a,c="video"===t?s:o,m="video"===t?n:h;f.forEach(t=>{e.addSample(p,t.data,{duration:t.duration,dts:t.dts+c,cts:t.cts+m,is_sync:t.is_sync})});let g=f.at(-1);if(null==g)return;"video"===t?l=g:"audio"===t&&(u=g)}}})}),null!=l&&(s+=l.dts,n+=l.cts),null!=u&&(o+=u.dts,h+=u.cts)}async function ri(t){return await rt([t])}function rr(t,e){e5.info("mixinMP4AndAudio, opts:",{volume:e.volume,loop:e.loop});let r=iA.createFile(),{stream:s,stop:n}=i9(r,500),a=null,o=null,h=[],l=0,u=0,d=0,f=!0,p=48e3;function c(t){let r=h.map(r=>e.loop?iS(r,d,d+t):r.slice(d,d+t));if(d+=t,1!==e.volume)for(let t of r)for(let r=0;r{await (null==o?void 0:o.stop()),null==a||a.close(),n()},onChunk:async({chunkType:t,data:s})=>{if("ready"===t){let{videoTrackConf:t,audioTrackConf:n,audioDecoderConf:d}=iI(s.file,s.info);0===l&&null!=t&&(l=r.addTrack(t));let c=n??{timescale:1e6,samplerate:p,channel_count:iC.channelCount,hdlr:"soun",name:"SoundHandler",type:"mp4a"};0===u&&(u=r.addTrack(c),p=(null==n?void 0:n.samplerate)??p,f=null!=n);let m=new AudioContext({sampleRate:p});h=ig(await m.decodeAudioData(await new Response(e.stream).arrayBuffer())),null!=d&&(a=function(t){let e=[],r=new AudioDecoder({output:t=>{e.push(t)},error:e5.error});return r.configure(t),{decode:async t=>{t.forEach(t=>{r.decode(new EncodedAudioChunk({type:t.is_sync?"key":"delta",timestamp:1e6*t.cts/t.timescale,duration:1e6*t.duration/t.timescale,data:t.data}))}),await r.flush();let s=e;return e=[],s},close:()=>{r.close()}}}(d)),o=function(t,e){let r=new AudioEncoder({output:t=>{e(i7(t))},error:e5.error});r.configure({codec:t.codec,sampleRate:t.sampleRate,numberOfChannels:t.numberOfChannels});let s=null;function n(e,r){return new AudioData({timestamp:r,numberOfChannels:t.numberOfChannels,numberOfFrames:e.length/t.numberOfChannels,sampleRate:t.sampleRate,format:"f32-planar",data:e})}return{encode:async(t,e)=>{null!=s&&r.encode(n(s.data,s.ts)),s={data:t,ts:e}},stop:async()=>{null!=s&&(function(t,e,r){let s=t.length-1,n=Math.min(r/2,s);for(let r=0;rr.addSample(u,t.data,t))}else if("samples"===t){let{id:t,type:e,samples:n}=s;if("video"===e){n.forEach(e=>r.addSample(t,e.data,e)),f||await m(n);return}"audio"===e&&await g(n)}}}),s}var rs=/* @__PURE__ */function(){function t(){this.listeners={}}var e=t.prototype;return e.on=function(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)},e.off=function(t,e){if(!this.listeners[t])return!1;var r=this.listeners[t].indexOf(e);return this.listeners[t]=this.listeners[t].slice(0),this.listeners[t].splice(r,1),r>-1},e.trigger=function(t){var e=this.listeners[t];if(e){if(2==arguments.length)for(var r=e.length,s=0;stypeof window?tO=window:"u">typeof iU?tO=iU:"u">typeof self?tO=self:tO={};let ra=/* @__PURE__ */ix(tO);/*! @name m3u8-parser @version 7.1.0 @license Apache-2.0 */class ro extends rs{constructor(){super(),this.buffer=""}push(t){let e;for(this.buffer+=t,e=this.buffer.indexOf(` `);e>-1;e=this.buffer.indexOf(` `))this.trigger("data",this.buffer.substring(0,e)),this.buffer=this.buffer.substring(e+1)}}let rh=function(t){let e=/([0-9.]*)?@?([0-9.]*)?/.exec(t||""),r={};return e[1]&&(r.length=parseInt(e[1],10)),e[2]&&(r.offset=parseInt(e[2],10)),r},rl=function(t){let e={};if(!t)return e;let r=t.split(RegExp('(?:^|,)((?:[^=]*)=(?:"[^"]*"|[^,]*))')),s=r.length,n;for(;s--;)""!==r[s]&&((n=/([^=]*)=(.*)/.exec(r[s]).slice(1))[0]=n[0].replace(/^\s+|\s+$/g,""),n[1]=n[1].replace(/^\s+|\s+$/g,""),n[1]=n[1].replace(/^['"](.*)['"]$/g,"$1"),e[n[0]]=n[1]);return e};class ru extends rs{constructor(){super(),this.customParsers=[],this.tagMappers=[]}push(t){let e,r;if(0!==(t=t.trim()).length){if("#"!==t[0]){this.trigger("data",{type:"uri",uri:t});return}this.tagMappers.reduce((e,r)=>{let s=r(t);return s===t?e:e.concat([s])},[t]).forEach(t=>{for(let e=0;et),this.customParsers.push(n=>{if(t.exec(n))return this.trigger("data",{type:"custom",data:r(n),customType:e,segment:s}),!0})}addTagMapper({expression:t,map:e}){this.tagMappers.push(r=>t.test(r)?e(r):r)}}let rd=t=>t.toLowerCase().replace(/-(\w)/g,t=>t[1].toUpperCase()),rf=function(t){let e={};return Object.keys(t).forEach(function(r){e[rd(r)]=t[r]}),e},rp=function(t){let{serverControl:e,targetDuration:r,partTargetDuration:s}=t;if(!e)return;let n="#EXT-X-SERVER-CONTROL",a="holdBack",o="partHoldBack",h=r&&3*r,l=s&&2*s;r&&!e.hasOwnProperty(a)&&(e[a]=h,this.trigger("info",{message:`${n} defaulting HOLD-BACK to targetDuration * 3 (${h}).`})),h&&e[a]{!r.uri&&(r.parts||r.preloadHints)&&(!r.map&&s&&(r.map=s),!r.key&&n&&(r.key=n),r.timeline||"number"!=typeof l||(r.timeline=l),this.manifest.preloadSegment=r)}),this.parseStream.on("data",function(p){let c,m;({tag(){(({version(){p.version&&(this.manifest.version=p.version)},"allow-cache"(){this.manifest.allowCache=p.allowed,"allowed"in p||(this.trigger("info",{message:"defaulting allowCache to YES"}),this.manifest.allowCache=!0)},byterange(){let t={};"length"in p&&(r.byterange=t,t.length=p.length,"offset"in p||(p.offset=u)),"offset"in p&&(r.byterange=t,t.offset=p.offset),u=t.offset+t.length},endlist(){this.manifest.endList=!0},inf(){"mediaSequence"in this.manifest||(this.manifest.mediaSequence=0,this.trigger("info",{message:"defaulting media sequence to zero"})),"discontinuitySequence"in this.manifest||(this.manifest.discontinuitySequence=0,this.trigger("info",{message:"defaulting discontinuity sequence to zero"})),p.title&&(r.title=p.title),p.duration>0&&(r.duration=p.duration),0===p.duration&&(r.duration=.01,this.trigger("info",{message:"updating zero segment duration to a small value"})),this.manifest.segments=e},key(){if(!p.attributes){this.trigger("warn",{message:"ignoring key declaration without attribute list"});return}if("NONE"===p.attributes.METHOD){n=null;return}if(!p.attributes.URI){this.trigger("warn",{message:"ignoring key declaration without URI"});return}if("com.apple.streamingkeydelivery"===p.attributes.KEYFORMAT){this.manifest.contentProtection=this.manifest.contentProtection||{},this.manifest.contentProtection["com.apple.fps.1_0"]={attributes:p.attributes};return}if("com.microsoft.playready"===p.attributes.KEYFORMAT){this.manifest.contentProtection=this.manifest.contentProtection||{},this.manifest.contentProtection["com.microsoft.playready"]={uri:p.attributes.URI};return}if("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"===p.attributes.KEYFORMAT){if(-1===["SAMPLE-AES","SAMPLE-AES-CTR","SAMPLE-AES-CENC"].indexOf(p.attributes.METHOD)){this.trigger("warn",{message:"invalid key method provided for Widevine"});return}if("SAMPLE-AES-CENC"===p.attributes.METHOD&&this.trigger("warn",{message:"SAMPLE-AES-CENC is deprecated, please use SAMPLE-AES-CTR instead"}),"data:text/plain;base64,"!==p.attributes.URI.substring(0,23)){this.trigger("warn",{message:"invalid key URI provided for Widevine"});return}if(!(p.attributes.KEYID&&"0x"===p.attributes.KEYID.substring(0,2))){this.trigger("warn",{message:"invalid key ID provided for Widevine"});return}this.manifest.contentProtection=this.manifest.contentProtection||{},this.manifest.contentProtection["com.widevine.alpha"]={attributes:{schemeIdUri:p.attributes.KEYFORMAT,keyId:p.attributes.KEYID.substring(2)},pssh:function(t){for(var e=ra.atob?ra.atob(t):ep.from(t,"base64").toString("binary"),r=new Uint8Array(e.length),s=0;stypeof p.attributes.IV&&(n.iv=p.attributes.IV)},"media-sequence"(){if(!isFinite(p.number)){this.trigger("warn",{message:"ignoring invalid media sequence: "+p.number});return}this.manifest.mediaSequence=p.number},"discontinuity-sequence"(){if(!isFinite(p.number)){this.trigger("warn",{message:"ignoring invalid discontinuity sequence: "+p.number});return}this.manifest.discontinuitySequence=p.number,l=p.number},"playlist-type"(){if(!/VOD|EVENT/.test(p.playlistType)){this.trigger("warn",{message:"ignoring unknown playlist type: "+p.playlist});return}this.manifest.playlistType=p.playlistType},map(){s={},p.uri&&(s.uri=p.uri),p.byterange&&(s.byterange=p.byterange),n&&(s.key=n)},"stream-inf"(){if(this.manifest.playlists=e,this.manifest.mediaGroups=this.manifest.mediaGroups||h,!p.attributes){this.trigger("warn",{message:"ignoring empty stream-inf attributes"});return}r.attributes||(r.attributes={}),rn(r.attributes,p.attributes)},media(){if(this.manifest.mediaGroups=this.manifest.mediaGroups||h,!(p.attributes&&p.attributes.TYPE&&p.attributes["GROUP-ID"]&&p.attributes.NAME)){this.trigger("warn",{message:"ignoring incomplete or missing media group"});return}let t=this.manifest.mediaGroups[p.attributes.TYPE];t[p.attributes["GROUP-ID"]]=t[p.attributes["GROUP-ID"]]||{},c=t[p.attributes["GROUP-ID"]],(m={default:/yes/i.test(p.attributes.DEFAULT)}).default?m.autoselect=!0:m.autoselect=/yes/i.test(p.attributes.AUTOSELECT),p.attributes.LANGUAGE&&(m.language=p.attributes.LANGUAGE),p.attributes.URI&&(m.uri=p.attributes.URI),p.attributes["INSTREAM-ID"]&&(m.instreamId=p.attributes["INSTREAM-ID"]),p.attributes.CHARACTERISTICS&&(m.characteristics=p.attributes.CHARACTERISTICS),p.attributes.FORCED&&(m.forced=/yes/i.test(p.attributes.FORCED)),c[p.attributes.NAME]=m},discontinuity(){l+=1,r.discontinuity=!0,this.manifest.discontinuityStarts.push(e.length)},"program-date-time"(){typeof this.manifest.dateTimeString>"u"&&(this.manifest.dateTimeString=p.dateTimeString,this.manifest.dateTimeObject=p.dateTimeObject),r.dateTimeString=p.dateTimeString,r.dateTimeObject=p.dateTimeObject;let{lastProgramDateTime:t}=this;this.lastProgramDateTime=new Date(p.dateTimeString).getTime(),null===t&&this.manifest.segments.reduceRight((t,e)=>(e.programDateTime=t-1e3*e.duration,e.programDateTime),this.lastProgramDateTime)},targetduration(){if(!isFinite(p.duration)||p.duration<0){this.trigger("warn",{message:"ignoring invalid target duration: "+p.duration});return}this.manifest.targetDuration=p.duration,rp.call(this,this.manifest)},start(){if(!p.attributes||isNaN(p.attributes["TIME-OFFSET"])){this.trigger("warn",{message:"ignoring start declaration without appropriate attribute list"});return}this.manifest.start={timeOffset:p.attributes["TIME-OFFSET"],precise:p.attributes.PRECISE}},"cue-out"(){r.cueOut=p.data},"cue-out-cont"(){r.cueOutCont=p.data},"cue-in"(){r.cueIn=p.data},skip(){this.manifest.skip=rf(p.attributes),this.warnOnMissingAttributes_("#EXT-X-SKIP",p.attributes,["SKIPPED-SEGMENTS"])},part(){a=!0;let t=this.manifest.segments.length,e=rf(p.attributes);r.parts=r.parts||[],r.parts.push(e),e.byterange&&(e.byterange.hasOwnProperty("offset")||(e.byterange.offset=d),d=e.byterange.offset+e.byterange.length);let s=r.parts.length-1;this.warnOnMissingAttributes_(`#EXT-X-PART #${s} for segment #${t}`,p.attributes,["URI","DURATION"]),this.manifest.renditionReports&&this.manifest.renditionReports.forEach((t,e)=>{t.hasOwnProperty("lastPart")||this.trigger("warn",{message:`#EXT-X-RENDITION-REPORT #${e} lacks required attribute(s): LAST-PART`})})},"server-control"(){let t=this.manifest.serverControl=rf(p.attributes);t.hasOwnProperty("canBlockReload")||(t.canBlockReload=!1,this.trigger("info",{message:"#EXT-X-SERVER-CONTROL defaulting CAN-BLOCK-RELOAD to false"})),rp.call(this,this.manifest),t.canSkipDateranges&&!t.hasOwnProperty("canSkipUntil")&&this.trigger("warn",{message:"#EXT-X-SERVER-CONTROL lacks required attribute CAN-SKIP-UNTIL which is required when CAN-SKIP-DATERANGES is set"})},"preload-hint"(){let t=this.manifest.segments.length,e=rf(p.attributes),s=e.type&&"PART"===e.type;r.preloadHints=r.preloadHints||[],r.preloadHints.push(e),e.byterange&&(e.byterange.hasOwnProperty("offset")||(e.byterange.offset=s?d:0,s&&(d=e.byterange.offset+e.byterange.length)));let n=r.preloadHints.length-1;if(this.warnOnMissingAttributes_(`#EXT-X-PRELOAD-HINT #${n} for segment #${t}`,p.attributes,["TYPE","URI"]),e.type)for(let s=0;st.id===e.id);this.manifest.dateRanges[t]=rn(this.manifest.dateRanges[t],e),f[e.id]=rn(f[e.id],e),this.manifest.dateRanges.pop()}else f[e.id]=e},"independent-segments"(){this.manifest.independentSegments=!0},"content-steering"(){this.manifest.contentSteering=rf(p.attributes),this.warnOnMissingAttributes_("#EXT-X-CONTENT-STEERING",p.attributes,["SERVER-URI"])}})[p.tagType]||o).call(t)},uri(){r.uri=p.uri,e.push(r),!this.manifest.targetDuration||"duration"in r||(this.trigger("warn",{message:"defaulting segment duration to the target duration"}),r.duration=this.manifest.targetDuration),n&&(r.key=n),r.timeline=l,s&&(r.map=s),d=0,null!==this.lastProgramDateTime&&(r.programDateTime=this.lastProgramDateTime,this.lastProgramDateTime+=1e3*r.duration),r={}},comment(){},custom(){p.segment?(r.custom=r.custom||{},r.custom[p.customType]=p.data):(this.manifest.custom=this.manifest.custom||{},this.manifest.custom[p.customType]=p.data)}})[p.type].call(t)})}warnOnMissingAttributes_(t,e,r){let s=[];r.forEach(function(t){e.hasOwnProperty(t)||s.push(t)}),s.length&&this.trigger("warn",{message:`${t} lacks required attribute(s): ${s.join(", ")}`})}push(t){this.lineStream.push(t)}end(){this.lineStream.push(` `),this.manifest.dateRanges.length&&null===this.lastProgramDateTime&&this.trigger("warn",{message:"A playlist with EXT-X-DATERANGE tag must contain atleast one EXT-X-PROGRAM-DATE-TIME tag"}),this.lastProgramDateTime=null,this.trigger("end")}addParser(t){this.parseStream.addParser(t)}addTagMapper(t){this.parseStream.addTagMapper(t)}}async function rm(t,e=10){let r=new rc;r.push(await (await fetch(t)).text()),r.end();let s=r.manifest.segments.reduce((t,e)=>(t[e.map.uri]=t[e.map.uri]??[],t[e.map.uri].push(e),t),{}),n=new URL(t,location.href),a={};async function o(t,r,s){async function o(t){return(await fetch(t)).arrayBuffer()}let h=function(e){let n=0,a=0,o=[];async function h(){if(na[t]=o(t))}}async function h(t){let e=await a[t];return delete a[t],e}return{load(t=0,e=1/0){let r={},a=0,l=0;for(let[n,o]of Object.entries(s)){let s=0,h=[],u=-1,d=-1;for(let r=0;rt/1e6&&(u=r,a=(s-n.duration)*1e6),u>-1&&-1===d&&s>=e/1e6){d=r+1,l=1e6*s;break}}e>=1e6*s&&(d=o.length,l=1e6*s),d>u&&(h=h.concat(o.slice(u,d))),h.length>0&&(r[n]={actualStartTime:a,actualEndTime:l,segments:h})}return 0===Object.keys(r).length?null:Object.entries(r).map(([t,{actualStartTime:e,actualEndTime:r,segments:s}])=>{let a=0,l=new i0;return{actualStartTime:e,actualEndTime:r,on:l.on,stream:new ReadableStream({start:async e=>{o(s,e,l),e.enqueue(new Uint8Array(await (await fetch(new URL(t,n).href)).arrayBuffer()))},pull:async t=>{let e=new URL(s[a].uri,n).href;t.enqueue(new Uint8Array(await h(e))),(a+=1)>=s.length&&(t.close(),l.destroy())}})}})}}}let rg=`#version 300 es layout (location = 0) in vec4 a_position; layout (location = 1) in vec2 a_texCoord; out vec2 v_texCoord; void main () { gl_Position = a_position; v_texCoord = a_texCoord; } `,ry=`#version 300 es precision mediump float; out vec4 FragColor; in vec2 v_texCoord; uniform sampler2D frameTexture; uniform vec3 keyColor; // \u{8272}\u{5EA6}\u{7684}\u{76F8}\u{4F3C}\u{5EA6}\u{8BA1}\u{7B97} uniform float similarity; // \u{900F}\u{660E}\u{5EA6}\u{7684}\u{5E73}\u{6ED1}\u{5EA6}\u{8BA1}\u{7B97} uniform float smoothness; // \u{964D}\u{4F4E}\u{7EFF}\u{5E55}\u{9971}\u{548C}\u{5EA6}\u{FF0C}\u{63D0}\u{9AD8}\u{62A0}\u{56FE}\u{51C6}\u{786E}\u{5EA6} uniform float spill; vec2 RGBtoUV(vec3 rgb) { return vec2( rgb.r * -0.169 + rgb.g * -0.331 + rgb.b * 0.5 + 0.5, rgb.r * 0.5 + rgb.g * -0.419 + rgb.b * -0.081 + 0.5 ); } void main() { // \u{83B7}\u{53D6}\u{5F53}\u{524D}\u{50CF}\u{7D20}\u{7684}rgba\u{503C} vec4 rgba = texture(frameTexture, v_texCoord); // \u{8BA1}\u{7B97}\u{5F53}\u{524D}\u{50CF}\u{7D20}\u{4E0E}\u{7EFF}\u{5E55}\u{50CF}\u{7D20}\u{7684}\u{8272}\u{5EA6}\u{5DEE}\u{503C} vec2 chromaVec = RGBtoUV(rgba.rgb) - RGBtoUV(keyColor); // \u{8BA1}\u{7B97}\u{5F53}\u{524D}\u{50CF}\u{7D20}\u{4E0E}\u{7EFF}\u{5E55}\u{50CF}\u{7D20}\u{7684}\u{8272}\u{5EA6}\u{8DDD}\u{79BB}\u{FF08}\u{5411}\u{91CF}\u{957F}\u{5EA6}\u{FF09}, \u{8D8A}\u{76F8}\u{50CF}\u{5219}\u{8272}\u{5EA6}\u{8DDD}\u{79BB}\u{8D8A}\u{5C0F} float chromaDist = sqrt(dot(chromaVec, chromaVec)); // \u{8BBE}\u{7F6E}\u{4E86}\u{4E00}\u{4E2A}\u{76F8}\u{4F3C}\u{5EA6}\u{9608}\u{503C}\u{FF0C}baseMask\u{4E3A}\u{8D1F}\u{FF0C}\u{5219}\u{8868}\u{660E}\u{662F}\u{7EFF}\u{5E55}\u{FF0C}\u{4E3A}\u{6B63}\u{5219}\u{8868}\u{660E}\u{4E0D}\u{662F}\u{7EFF}\u{5E55} float baseMask = chromaDist - similarity; // \u{5982}\u{679C}baseMask\u{4E3A}\u{8D1F}\u{6570}\u{FF0C}fullMask\u{7B49}\u{4E8E}0\u{FF1B}baseMask\u{4E3A}\u{6B63}\u{6570}\u{FF0C}\u{8D8A}\u{5927}\u{FF0C}\u{5219}\u{900F}\u{660E}\u{5EA6}\u{8D8A}\u{4F4E} float fullMask = pow(clamp(baseMask / smoothness, 0., 1.), 1.5); rgba.a = fullMask; // \u{8BBE}\u{7F6E}\u{900F}\u{660E}\u{5EA6} // \u{5982}\u{679C}baseMask\u{4E3A}\u{8D1F}\u{6570}\u{FF0C}spillVal\u{7B49}\u{4E8E}0\u{FF1B}baseMask\u{4E3A}\u{6574}\u{6570}\u{FF0C}\u{8D8A}\u{5C0F}\u{FF0C}\u{9971}\u{548C}\u{5EA6}\u{8D8A}\u{4F4E} float spillVal = pow(clamp(baseMask / spill, 0., 1.), 1.5); float desat = clamp(rgba.r * 0.2126 + rgba.g * 0.7152 + rgba.b * 0.0722, 0., 1.); // \u{8BA1}\u{7B97}\u{5F53}\u{524D}\u{50CF}\u{7D20}\u{7684}\u{7070}\u{5EA6}\u{503C} rgba.rgb = mix(vec3(desat, desat, desat), rgba.rgb, spillVal); FragColor = rgba; } `,r_=[-1,1,-1,-1,1,-1,1,-1,1,1,-1,1],rb=[0,1,0,0,1,0,1,0,1,1,0,1];function rw(t,e,r){let s=t.createShader(e);if(t.shaderSource(s,r),t.compileShader(s),!t.getShaderParameter(s,t.COMPILE_STATUS)){let e=t.getShaderInfoLog(s);throw t.deleteShader(s),Error(e??"An error occurred compiling the shaders")}return s}let rv=t=>{let e=null,r=null,s=t.keyColor,n=null;return async a=>{var o,h;if((null==e||null==r||null==n)&&(null==s&&(s=function(t){let e=new OffscreenCanvas(1,1).getContext("2d");e.drawImage(t,0,0);let{data:[r,s,n]}=e.getImageData(0,0,1,1);return[r,s,n]}(a)),{cvs:e,gl:r}=function(t){let e="document"in globalThis?globalThis.document.createElement("canvas"):new OffscreenCanvas(t.width,t.height);e.width=t.width,e.height=t.height;let r=e.getContext("webgl2",{premultipliedAlpha:!1,alpha:!0});if(null==r)throw Error("Cant create gl context");let s=function(t,e,r){let s=rw(t,t.VERTEX_SHADER,e),n=rw(t,t.FRAGMENT_SHADER,r),a=t.createProgram();if(t.attachShader(a,s),t.attachShader(a,n),t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))throw Error(t.getProgramInfoLog(a)??"Unable to initialize the shader program");return a}(r,rg,ry);r.useProgram(s),r.uniform3fv(r.getUniformLocation(s,"keyColor"),t.keyColor.map(t=>t/255)),r.uniform1f(r.getUniformLocation(s,"similarity"),t.similarity),r.uniform1f(r.getUniformLocation(s,"smoothness"),t.smoothness),r.uniform1f(r.getUniformLocation(s,"spill"),t.spill);let n=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,n),r.bufferData(r.ARRAY_BUFFER,new Float32Array(r_),r.STATIC_DRAW);let a=r.getAttribLocation(s,"a_position");r.vertexAttribPointer(a,2,r.FLOAT,!1,2*Float32Array.BYTES_PER_ELEMENT,0),r.enableVertexAttribArray(a);let o=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,o),r.bufferData(r.ARRAY_BUFFER,new Float32Array(rb),r.STATIC_DRAW);let h=r.getAttribLocation(s,"a_texCoord");return r.vertexAttribPointer(h,2,r.FLOAT,!1,2*Float32Array.BYTES_PER_ELEMENT,0),r.enableVertexAttribArray(h),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),{cvs:e,gl:r}}({...a instanceof VideoFrame?{width:a.codedWidth,height:a.codedHeight}:{width:a.width,height:a.height},keyColor:s,...t}),n=function(t){let e=t.createTexture();if(null==e)throw Error("Create WebGL texture error");t.bindTexture(t.TEXTURE_2D,e);let r=t.RGBA,s=t.RGBA,n=t.UNSIGNED_BYTE,a=new Uint8Array([0,0,255,255]);return t.texImage2D(t.TEXTURE_2D,0,r,1,1,0,s,n,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),e}(r)),o=r,h=n,o.bindTexture(o.TEXTURE_2D,h),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,a),o.drawArrays(o.TRIANGLES,0,6),null!=globalThis.VideoFrame&&a instanceof globalThis.VideoFrame){let t=new VideoFrame(e,{alpha:"keep",timestamp:a.timestamp,duration:a.duration??void 0});return a.close(),t}return createImageBitmap(e,{imageOrientation:a instanceof ImageBitmap?"flipY":"none"})}},rS=class t{constructor(t,e,r,s,n){ew(this,tX),ew(this,tN,new i0),ey(this,"on",eb(this,tN).on),ew(this,tG,0),ew(this,tY,0),ew(this,tW,0),ew(this,tV,0),ew(this,tH,0),ey(this,"master",null),ey(this,"fixedAspectRatio",!1),this.x=t??0,this.y=e??0,this.w=r??0,this.h=s??0,this.master=n??null}get x(){return eb(this,tG)}set x(t){eS(this,tX,tj).call(this,"x",t)}get y(){return eb(this,tY)}set y(t){eS(this,tX,tj).call(this,"y",t)}get w(){return eb(this,tW)}set w(t){eS(this,tX,tj).call(this,"w",t)}get h(){return eb(this,tV)}set h(t){eS(this,tX,tj).call(this,"h",t)}get angle(){return eb(this,tH)}set angle(t){eS(this,tX,tj).call(this,"angle",t)}get center(){let{x:t,y:e,w:r,h:s}=this;return{x:t+r/2,y:e+s/2}}get ctrls(){let{w:e,h:r}=this,s=t.CTRL_SIZE,n=s/2,a=e/2,o=r/2,h=1.5*s,l=h/2;return{...this.fixedAspectRatio?{}:{t:new t(-n,-o-n,s,s,this),b:new t(-n,o-n,s,s,this),l:new t(-a-n,-n,s,s,this),r:new t(a-n,-n,s,s,this)},lt:new t(-a-n,-o-n,s,s,this),lb:new t(-a-n,o-n,s,s,this),rt:new t(a-n,-o-n,s,s,this),rb:new t(a-n,o-n,s,s,this),rotate:new t(-l,-o-2*s-l,h,h,this)}}clone(){let{x:e,y:r,w:s,h:n,master:a}=this,o=new t(e,r,s,n,a);return o.angle=this.angle,o.fixedAspectRatio=this.fixedAspectRatio,o}checkHit(t,e){let{angle:r,center:s,x:n,y:a,w:o,h:h,master:l}=this,u=(null==l?void 0:l.center)??s,d=(null==l?void 0:l.angle)??r;null==l&&(n-=u.x,a-=u.y);let f=t-u.x,p=e-u.y,c=f,m=p;return 0!==d&&(c=f*Math.cos(d)+p*Math.sin(d),m=p*Math.cos(d)-f*Math.sin(d)),!(cn+o||ma+h)}};tN=new WeakMap,tG=new WeakMap,tY=new WeakMap,tW=new WeakMap,tV=new WeakMap,tH=new WeakMap,tX=new WeakSet,tj=function(t,e){let r=this[t]!==e;switch(t){case"x":ev(this,tG,e);break;case"y":ev(this,tY,e);break;case"w":ev(this,tW,e);break;case"h":ev(this,tV,e);break;case"angle":ev(this,tH,e)}r&&eb(this,tN).emit("propsChange",{[t]:e})},ey(rS,"CTRL_SIZE",16),ey(rS,"CTRL_KEYS",["t","b","l","r","lt","lb","rt","rb","rotate"]);let rE=rS;class rU{constructor(){ey(this,"rect",new rE),ey(this,"time",{offset:0,duration:0}),ey(this,"visible",!0),ew(this,tZ,new i0),ey(this,"on",eb(this,tZ).on),ew(this,t$,0),ey(this,"opacity",1),ey(this,"flip",null),ew(this,tK,null),ew(this,tq,null),ey(this,"ready",Promise.resolve()),this.rect.on("propsChange",t=>{eb(this,tZ).emit("propsChange",{rect:t})})}get zIndex(){return eb(this,t$)}set zIndex(t){let e=eb(this,t$)!==t;ev(this,t$,t),e&&eb(this,tZ).emit("propsChange",{zIndex:t})}_render(t){let{rect:{center:e,angle:r}}=this;t.setTransform("horizontal"===this.flip?-1:1,0,0,"vertical"===this.flip?-1:1,e.x,e.y),t.rotate((null==this.flip?1:-1)*r),t.globalAlpha=this.opacity}setAnimation(t,e){ev(this,tK,Object.entries(t).map(([t,e])=>{let r={from:0,to:100}[t]??Number(t.slice(0,-1));if(isNaN(r)||r>100||r<0)throw Error("keyFrame must between 0~100");return[r/100,e]})),ev(this,tq,Object.assign({},eb(this,tq),{duration:1e6*e.duration,delay:(e.delay??0)*1e6,iterCount:e.iterCount??1/0}))}animate(t){if(null==eb(this,tK)||null==eb(this,tq)||t=r.iterCount)return{};let s=t%r.duration,n=t===r.duration?1:s/r.duration,a=e.findIndex(t=>t[0]>=n);if(-1===a)return{};let o=e[a-1],h=e[a],l=h[1];if(null==o)return l;let u=o[1],d={},f=(n-o[0])/(h[0]-o[0]);for(let t in l)null!=u[t]&&(d[t]=(l[t]-u[t])*f+u[t]);return d}(t,eb(this,tK),eb(this,tq));for(let t in e)switch(t){case"opacity":this.opacity=e[t];break;case"x":case"y":case"w":case"h":case"angle":this.rect[t]=e[t]}}copyStateTo(t){ev(t,tK,eb(this,tK)),ev(t,tq,eb(this,tq)),t.visible=this.visible,t.zIndex=this.zIndex,t.opacity=this.opacity,t.flip=this.flip,t.rect=this.rect.clone(),t.time={...this.time}}destroy(){eb(this,tZ).destroy()}}tZ=new WeakMap,t$=new WeakMap,tK=new WeakMap,tq=new WeakMap;let rx=class t extends rU{constructor(t){super(),ew(this,tQ),ew(this,tJ,null),ew(this,t0,!1),ev(this,tQ,t),this.ready=t.ready.then(({width:t,height:e,duration:r})=>{this.rect.w=0===this.rect.w?t:this.rect.w,this.rect.h=0===this.rect.h?e:this.rect.h,this.time.duration=0===this.time.duration?r:this.time.duration})}async offscreenRender(t,e){var r;this.animate(e),super._render(t);let{w:s,h:n}=this.rect,{video:a,audio:o,state:h}=await eb(this,tQ).tick(e);if("done"===h)return{audio:o??[],done:!0};let l=a??eb(this,tJ);return null!=l&&t.drawImage(l,-s/2,-n/2,s,n),null!=a&&(null==(r=eb(this,tJ))||r.close(),ev(this,tJ,a)),{audio:o??[],done:!1}}async clone(){let e=new t(await eb(this,tQ).clone());return await e.ready,this.copyStateTo(e),e}destroy(){var t;eb(this,t0)||(ev(this,t0,!0),e5.info("OffscreenSprite destroy"),super.destroy(),null==(t=eb(this,tJ))||t.close(),ev(this,tJ,null),eb(this,tQ).destroy())}};tQ=new WeakMap,tJ=new WeakMap,t0=new WeakMap;let rT=rx;class rA extends rU{constructor(t){super(),ew(this,t8),ew(this,t1),ew(this,t2,null),ew(this,t3,[]),ew(this,t6,!1),ew(this,t5,-1),ew(this,t9,!1),ev(this,t1,t),this.ready=t.ready.then(({width:t,height:e,duration:r})=>{this.rect.w=0===this.rect.w?t:this.rect.w,this.rect.h=0===this.rect.h?e:this.rect.h,this.time.duration=0===this.time.duration?r:this.time.duration})}getClip(){return eb(this,t1)}preFrame(t){eS(this,t8,t4).call(this,t)}render(t,e){this.animate(e),super._render(t);let{w:r,h:s}=this.rect;eb(this,t5)!==e&&eS(this,t8,t4).call(this,e),ev(this,t5,e);let n=eb(this,t3);ev(this,t3,[]);let a=eb(this,t2);return null!=a&&t.drawImage(a,-r/2,-s/2,r,s),{audio:n}}destroy(){var t;eb(this,t9)||(ev(this,t9,!0),e5.info("VisibleSprite destroy"),super.destroy(),null==(t=eb(this,t2))||t.close(),ev(this,t2,null),eb(this,t1).destroy())}}t1=new WeakMap,t2=new WeakMap,t3=new WeakMap,t6=new WeakMap,t8=new WeakSet,t4=function(t){eb(this,t6)||(ev(this,t6,!0),eb(this,t1).tick(t).then(({video:t,audio:e})=>{var r;null!=t&&(null==(r=eb(this,t2))||r.close(),ev(this,t2,t??null)),ev(this,t3,e??[])}).finally(()=>{ev(this,t6,!1)}))},t5=new WeakMap,t9=new WeakMap;let rC=0;async function rI(t){t()>50&&(await iv(15),await rI(t))}class rB{constructor(t={}){ew(this,eh),ew(this,t7,e5.create(`id:${rC++},`)),ew(this,et,!1),ew(this,ee,[]),ew(this,ei),ew(this,er),ew(this,es,null),ew(this,en),ew(this,ea),ew(this,eo,new i0),ey(this,"on",eb(this,eo).on);let{width:e=0,height:r=0}=t;ev(this,ei,new OffscreenCanvas(e,r));let s=eb(this,ei).getContext("2d",{alpha:!1});if(null==s)throw Error("Can not create 2d offscreen context");ev(this,er,s),ev(this,en,Object.assign({bgColor:"#000",width:0,height:0,videoCodec:"avc1.42E032",audio:!0,bitrate:5e6,metaDataTags:null},t)),ev(this,ea,e*r>0)}static async isSupported(t={videoCodec:"avc1.42E032"}){return null!=self.OffscreenCanvas&&null!=self.VideoEncoder&&null!=self.VideoDecoder&&null!=self.VideoFrame&&null!=self.AudioEncoder&&null!=self.AudioDecoder&&null!=self.AudioData&&((await self.VideoEncoder.isConfigSupported({codec:t.videoCodec,width:1280,height:720})).supported??!1)&&(await self.AudioEncoder.isConfigSupported({codec:iC.codec,sampleRate:iC.sampleRate,numberOfChannels:iC.channelCount})).supported}async addSprite(t,e={}){eb(this,t7).info("Combinator add sprite",t);let r=await t.clone();eb(this,t7).info("Combinator add sprite ready",t),eb(this,ee).push(Object.assign(r,{main:e.main??!1,expired:!1})),eb(this,ee).sort((t,e)=>t.zIndex-e.zIndex)}output(){if(0===eb(this,ee).length)throw Error("No sprite added");let t=eb(this,ee).find(t=>t.main),e=null!=t?t.time.offset+t.time.duration:Math.max(...eb(this,ee).map(t=>t.time.offset+t.time.duration));if(e===1/0)throw Error("Unable to determine the end time, please specify a main sprite, or limit the duration of ImgClip, AudioCli");-1===e&&eb(this,t7).warn("Unable to determine the end time, process value don't update"),eb(this,t7).info(`start combinate video, maxTime:${e}`);let r=eS(this,eh,el).call(this,e),s=performance.now(),n=eS(this,eh,eu).call(this,r,e,{onProgress:t=>{eb(this,t7).debug("OutputProgress:",t),eb(this,eo).emit("OutputProgress",t)},onEnded:async()=>{await r.flush(),eb(this,t7).info("===== output ended =====, cost:",performance.now()-s),eb(this,eo).emit("OutputProgress",1),this.destroy()},onError:t=>{eb(this,eo).emit("error",t),o(t),this.destroy()}});ev(this,es,()=>{n(),r.close(),o()});let{stream:a,stop:o}=i9(r.mp4file,500,this.destroy);return a}destroy(){var t;eb(this,et)||(ev(this,et,!0),null==(t=eb(this,es))||t.call(this),eb(this,eo).destroy())}}t7=new WeakMap,et=new WeakMap,ee=new WeakMap,ei=new WeakMap,er=new WeakMap,es=new WeakMap,en=new WeakMap,ea=new WeakMap,eo=new WeakMap,eh=new WeakSet,el=function(t){let{width:e,height:r,videoCodec:s,bitrate:n,audio:a,metaDataTags:o}=eb(this,en);return i4({video:eb(this,ea)?{width:e,height:r,expectFPS:30,codec:s,bitrate:n,__unsafe_hardwareAcceleration__:eb(this,en).__unsafe_hardwareAcceleration__}:null,audio:!1===a?null:{codec:"aac",sampleRate:iC.sampleRate,channelCount:iC.channelCount},duration:t,metaDataTags:o})},eu=function(t,e,{onProgress:r,onEnded:s,onError:n}){let a=0,o=!1,h=null;(async()=>{let r=0,{width:n,height:l}=eb(this,ei),d=eb(this,er),f=0;for(;;){if(null!=h)return;if(o||-1!==e&&f>e||0===eb(this,ee).length){u(),await s();return}a=f/e,d.fillStyle=eb(this,en).bgColor,d.fillRect(0,0,n,l);let p=[];for(let t of eb(this,ee)){if(o)break;if(f0&&f>t.time.offset+t.time.duration||r){if(t.main){u(),await s();return}t.destroy(),t.expired=!0}}if(o)return;if(!1!==eb(this,en).audio){if(p.flat().every(t=>0===t.length))t.encodeAudio(function(t,e,r){let s=Math.floor(33e3*r/1e6);return new AudioData({timestamp:t,numberOfChannels:iC.channelCount,numberOfFrames:s,sampleRate:r,format:"f32-planar",data:new Float32Array(2*s)})}(f,0,iC.sampleRate));else{let e=ib(p);t.encodeAudio(new AudioData({timestamp:f,numberOfChannels:iC.channelCount,numberOfFrames:e.length/iC.channelCount,sampleRate:iC.sampleRate,format:"f32-planar",data:e}))}}if(eb(this,ea)){let e=new VideoFrame(eb(this,ei),{duration:33e3,timestamp:f});t.encodeVideo(e,{keyFrame:r%150==0}),d.resetTransform(),d.clearRect(0,0,n,l),r+=1}f+=33e3,await rI(t.getEncodeQueueSize)}})().catch(t=>{h=t,eb(this,t7).error(t),u(),n(t)});let l=setInterval(()=>{r(a)},500),u=()=>{o||(o=!0,clearInterval(l),eb(this,ee).forEach(t=>t.destroy()))};return u}},{"718a311db185ef08":"juSMc","@parcel/transformer-js/src/esmodule-helpers.js":"9pCYc"}],juSMc:[function(t,e,r){var s=t("9c62938f1dccc73c"),n=t("aceacb6a4531a9d2"),a="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;function o(t){if(t>2147483647)throw RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return Object.setPrototypeOf(e,h.prototype),e}function h(t,e,r){if("number"==typeof t){if("string"==typeof e)throw TypeError('The "string" argument must be of type string. Received type number');return d(t)}return l(t,e,r)}function l(t,e,r){if("string"==typeof t)return function(t,e){if(("string"!=typeof e||""===e)&&(e="utf8"),!h.isEncoding(e))throw TypeError("Unknown encoding: "+e);var r=0|m(t,e),s=o(r),n=s.write(t,e);return n!==r&&(s=s.slice(0,n)),s}(t,e);if(ArrayBuffer.isView(t))return function(t){if(B(t,Uint8Array)){var e=new Uint8Array(t);return p(e.buffer,e.byteOffset,e.byteLength)}return f(t)}(t);if(null==t)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(B(t,ArrayBuffer)||t&&B(t.buffer,ArrayBuffer)||"undefined"!=typeof SharedArrayBuffer&&(B(t,SharedArrayBuffer)||t&&B(t.buffer,SharedArrayBuffer)))return p(t,e,r);if("number"==typeof t)throw TypeError('The "value" argument must not be of type number. Received type number');var s=t.valueOf&&t.valueOf();if(null!=s&&s!==t)return h.from(s,e,r);var n=function(t){if(h.isBuffer(t)){var e,r=0|c(t.length),s=o(r);return 0===s.length||t.copy(s,0,0,r),s}return void 0!==t.length?"number"!=typeof t.length||(e=t.length)!=e?o(0):f(t):"Buffer"===t.type&&Array.isArray(t.data)?f(t.data):void 0}(t);if(n)return n;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return h.from(t[Symbol.toPrimitive]("string"),e,r);throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function u(t){if("number"!=typeof t)throw TypeError('"size" argument must be of type number');if(t<0)throw RangeError('The value "'+t+'" is invalid for option "size"')}function d(t){return u(t),o(t<0?0:0|c(t))}function f(t){for(var e=t.length<0?0:0|c(t.length),r=o(e),s=0;s=2147483647)throw RangeError("Attempt to allocate Buffer larger than maximum size: 0x7fffffff bytes");return 0|t}function m(t,e){if(h.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||B(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,s=arguments.length>2&&!0===arguments[2];if(!s&&0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return A(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return C(t).length;default:if(n)return s?-1:A(t).length;e=(""+e).toLowerCase(),n=!0}}function g(t,e,r){var n,a,o=!1;if((void 0===e||e<0)&&(e=0),e>this.length||((void 0===r||r>this.length)&&(r=this.length),r<=0||(r>>>=0)<=(e>>>=0)))return"";for(t||(t="utf8");;)switch(t){case"hex":return function(t,e,r){var s=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>s)&&(r=s);for(var n="",a=e;a2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),(a=r=+r)!=a&&(r=n?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(n)return -1;r=t.length-1}else if(r<0){if(!n)return -1;r=0}if("string"==typeof e&&(e=h.from(e,s)),h.isBuffer(e))return 0===e.length?-1:b(t,e,r,s,n);if("number"==typeof e)return(e&=255,"function"==typeof Uint8Array.prototype.indexOf)?n?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):b(t,[e],r,s,n);throw TypeError("val must be string, number or Buffer")}function b(t,e,r,s,n){var a,o=1,h=t.length,l=e.length;if(void 0!==s&&("ucs2"===(s=String(s).toLowerCase())||"ucs-2"===s||"utf16le"===s||"utf-16le"===s)){if(t.length<2||e.length<2)return -1;o=2,h/=2,l/=2,r/=2}function u(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(n){var d=-1;for(a=r;ah&&(r=h-l),a=r;a>=0;a--){for(var f=!0,p=0;p239?4:u>223?3:u>191?2:1;if(n+f<=r)switch(f){case 1:u<128&&(d=u);break;case 2:(192&(a=t[n+1]))==128&&(l=(31&u)<<6|63&a)>127&&(d=l);break;case 3:a=t[n+1],o=t[n+2],(192&a)==128&&(192&o)==128&&(l=(15&u)<<12|(63&a)<<6|63&o)>2047&&(l<55296||l>57343)&&(d=l);break;case 4:a=t[n+1],o=t[n+2],h=t[n+3],(192&a)==128&&(192&o)==128&&(192&h)==128&&(l=(15&u)<<18|(63&a)<<12|(63&o)<<6|63&h)>65535&&l<1114112&&(d=l)}null===d?(d=65533,f=1):d>65535&&(d-=65536,s.push(d>>>10&1023|55296),d=56320|1023&d),s.push(d),n+=f}return function(t){var e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);for(var r="",s=0;sr)throw RangeError("Trying to access beyond buffer length")}function S(t,e,r,s,n,a){if(!h.isBuffer(t))throw TypeError('"buffer" argument must be a Buffer instance');if(e>n||et.length)throw RangeError("Index out of range")}function E(t,e,r,s,n,a){if(r+s>t.length||r<0)throw RangeError("Index out of range")}function U(t,e,r,s,a){return e=+e,r>>>=0,a||E(t,e,r,4,34028234663852886e22,-34028234663852886e22),n.write(t,e,r,s,23,4),r+4}function x(t,e,r,s,a){return e=+e,r>>>=0,a||E(t,e,r,8,17976931348623157e292,-17976931348623157e292),n.write(t,e,r,s,52,8),r+8}r.Buffer=h,r.SlowBuffer=function(t){return+t!=t&&(t=0),h.alloc(+t)},r.INSPECT_MAX_BYTES=50,r.kMaxLength=2147483647,h.TYPED_ARRAY_SUPPORT=function(){try{var t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),h.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(h.prototype,"parent",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.buffer}}),Object.defineProperty(h.prototype,"offset",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.byteOffset}}),h.poolSize=8192,h.from=function(t,e,r){return l(t,e,r)},Object.setPrototypeOf(h.prototype,Uint8Array.prototype),Object.setPrototypeOf(h,Uint8Array),h.alloc=function(t,e,r){return(u(t),t<=0)?o(t):void 0!==e?"string"==typeof r?o(t).fill(e,r):o(t).fill(e):o(t)},h.allocUnsafe=function(t){return d(t)},h.allocUnsafeSlow=function(t){return d(t)},h.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==h.prototype},h.compare=function(t,e){if(B(t,Uint8Array)&&(t=h.from(t,t.offset,t.byteLength)),B(e,Uint8Array)&&(e=h.from(e,e.offset,e.byteLength)),!h.isBuffer(t)||!h.isBuffer(e))throw TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;for(var r=t.length,s=e.length,n=0,a=Math.min(r,s);ns.length?h.from(a).copy(s,n):Uint8Array.prototype.set.call(s,a,n);else if(h.isBuffer(a))a.copy(s,n);else throw TypeError('"list" argument must be an Array of Buffers');n+=a.length}return s},h.byteLength=m,h.prototype._isBuffer=!0,h.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;ee&&(t+=" ... "),""},a&&(h.prototype[a]=h.prototype.inspect),h.prototype.compare=function(t,e,r,s,n){if(B(t,Uint8Array)&&(t=h.from(t,t.offset,t.byteLength)),!h.isBuffer(t))throw TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===s&&(s=0),void 0===n&&(n=this.length),e<0||r>t.length||s<0||n>this.length)throw RangeError("out of range index");if(s>=n&&e>=r)return 0;if(s>=n)return -1;if(e>=r)return 1;if(e>>>=0,r>>>=0,s>>>=0,n>>>=0,this===t)return 0;for(var a=n-s,o=r-e,l=Math.min(a,o),u=this.slice(s,n),d=t.slice(e,r),f=0;f>>=0,isFinite(r)?(r>>>=0,void 0===s&&(s="utf8")):(s=r,r=void 0);else throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var n,a,o,h,l,u,d,f,p=this.length-e;if((void 0===r||r>p)&&(r=p),t.length>0&&(r<0||e<0)||e>this.length)throw RangeError("Attempt to write outside buffer bounds");s||(s="utf8");for(var c=!1;;)switch(s){case"hex":return function(t,e,r,s){r=Number(r)||0;var n=t.length-r;s?(s=Number(s))>n&&(s=n):s=n;var a=e.length;s>a/2&&(s=a/2);for(var o=0;o>8,n.push(r%256),n.push(s);return n}(t,this.length-d),this,d,f);default:if(c)throw TypeError("Unknown encoding: "+s);s=(""+s).toLowerCase(),c=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},h.prototype.slice=function(t,e){var r=this.length;t=~~t,e=void 0===e?r:~~e,t<0?(t+=r)<0&&(t=0):t>r&&(t=r),e<0?(e+=r)<0&&(e=0):e>r&&(e=r),e>>=0,e>>>=0,r||v(t,e,this.length);for(var s=this[t],n=1,a=0;++a>>=0,e>>>=0,r||v(t,e,this.length);for(var s=this[t+--e],n=1;e>0&&(n*=256);)s+=this[t+--e]*n;return s},h.prototype.readUint8=h.prototype.readUInt8=function(t,e){return t>>>=0,e||v(t,1,this.length),this[t]},h.prototype.readUint16LE=h.prototype.readUInt16LE=function(t,e){return t>>>=0,e||v(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUint16BE=h.prototype.readUInt16BE=function(t,e){return t>>>=0,e||v(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUint32LE=h.prototype.readUInt32LE=function(t,e){return t>>>=0,e||v(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUint32BE=h.prototype.readUInt32BE=function(t,e){return t>>>=0,e||v(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||v(t,e,this.length);for(var s=this[t],n=1,a=0;++a=(n*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||v(t,e,this.length);for(var s=e,n=1,a=this[t+--s];s>0&&(n*=256);)a+=this[t+--s]*n;return a>=(n*=128)&&(a-=Math.pow(2,8*e)),a},h.prototype.readInt8=function(t,e){return(t>>>=0,e||v(t,1,this.length),128&this[t])?-((255-this[t]+1)*1):this[t]},h.prototype.readInt16LE=function(t,e){t>>>=0,e||v(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt16BE=function(t,e){t>>>=0,e||v(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt32LE=function(t,e){return t>>>=0,e||v(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return t>>>=0,e||v(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return t>>>=0,e||v(t,4,this.length),n.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return t>>>=0,e||v(t,4,this.length),n.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return t>>>=0,e||v(t,8,this.length),n.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return t>>>=0,e||v(t,8,this.length),n.read(this,t,!1,52,8)},h.prototype.writeUintLE=h.prototype.writeUIntLE=function(t,e,r,s){if(t=+t,e>>>=0,r>>>=0,!s){var n=Math.pow(2,8*r)-1;S(this,t,e,r,n,0)}var a=1,o=0;for(this[e]=255&t;++o>>=0,r>>>=0,!s){var n=Math.pow(2,8*r)-1;S(this,t,e,r,n,0)}var a=r-1,o=1;for(this[e+a]=255&t;--a>=0&&(o*=256);)this[e+a]=t/o&255;return e+r},h.prototype.writeUint8=h.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,1,255,0),this[e]=255&t,e+1},h.prototype.writeUint16LE=h.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},h.prototype.writeUint16BE=h.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},h.prototype.writeUint32LE=h.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},h.prototype.writeUint32BE=h.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},h.prototype.writeIntLE=function(t,e,r,s){if(t=+t,e>>>=0,!s){var n=Math.pow(2,8*r-1);S(this,t,e,r,n-1,-n)}var a=0,o=1,h=0;for(this[e]=255&t;++a>0)-h&255;return e+r},h.prototype.writeIntBE=function(t,e,r,s){if(t=+t,e>>>=0,!s){var n=Math.pow(2,8*r-1);S(this,t,e,r,n-1,-n)}var a=r-1,o=1,h=0;for(this[e+a]=255&t;--a>=0&&(o*=256);)t<0&&0===h&&0!==this[e+a+1]&&(h=1),this[e+a]=(t/o>>0)-h&255;return e+r},h.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},h.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},h.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},h.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},h.prototype.writeFloatLE=function(t,e,r){return U(this,t,e,!0,r)},h.prototype.writeFloatBE=function(t,e,r){return U(this,t,e,!1,r)},h.prototype.writeDoubleLE=function(t,e,r){return x(this,t,e,!0,r)},h.prototype.writeDoubleBE=function(t,e,r){return x(this,t,e,!1,r)},h.prototype.copy=function(t,e,r,s){if(!h.isBuffer(t))throw TypeError("argument should be a Buffer");if(r||(r=0),s||0===s||(s=this.length),e>=t.length&&(e=t.length),e||(e=0),s>0&&s=this.length)throw RangeError("Index out of range");if(s<0)throw RangeError("sourceEnd out of bounds");s>this.length&&(s=this.length),t.length-e>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(n=e;n55295&&r<57344){if(!n){if(r>56319||o+1===s){(e-=3)>-1&&a.push(239,191,189);continue}n=r;continue}if(r<56320){(e-=3)>-1&&a.push(239,191,189),n=r;continue}r=(n-55296<<10|r-56320)+65536}else n&&(e-=3)>-1&&a.push(239,191,189);if(n=null,r<128){if((e-=1)<0)break;a.push(r)}else if(r<2048){if((e-=2)<0)break;a.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;a.push(r>>12|224,r>>6&63|128,63&r|128)}else if(r<1114112){if((e-=4)<0)break;a.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}else throw Error("Invalid code point")}return a}function C(t){return s.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(T,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function I(t,e,r,s){for(var n=0;n=e.length)&&!(n>=t.length);++n)e[n+r]=t[n];return n}function B(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}var k=function(){for(var t="0123456789abcdef",e=Array(256),r=0;r<16;++r)for(var s=16*r,n=0;n<16;++n)e[s+n]=t[r]+t[n];return e}()},{"9c62938f1dccc73c":"iaOvk",aceacb6a4531a9d2:"9RC4J"}],iaOvk:[function(t,e,r){r.byteLength=function(t){var e=u(t),r=e[0],s=e[1];return(r+s)*3/4-s},r.toByteArray=function(t){var e,r,s=u(t),o=s[0],h=s[1],l=new a((o+h)*3/4-h),d=0,f=h>0?o-4:o;for(r=0;r>16&255,l[d++]=e>>8&255,l[d++]=255&e;return 2===h&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,l[d++]=255&e),1===h&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,l[d++]=e>>8&255,l[d++]=255&e),l},r.fromByteArray=function(t){for(var e,r=t.length,n=r%3,a=[],o=0,h=r-n;o>18&63]+s[n>>12&63]+s[n>>6&63]+s[63&n]);return a.join("")}(t,o,o+16383>h?h:o+16383));return 1===n?a.push(s[(e=t[r-1])>>2]+s[e<<4&63]+"=="):2===n&&a.push(s[(e=(t[r-2]<<8)+t[r-1])>>10]+s[e>>4&63]+s[e<<2&63]+"="),a.join("")};for(var s=[],n=[],a="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=0,l=o.length;h0)throw Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");-1===r&&(r=e);var s=r===e?0:4-r%4;return[r,s]}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},{}],"9RC4J":[function(t,e,r){/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh*/r.read=function(t,e,r,s,n){var a,o,h=8*n-s-1,l=(1<>1,d=-7,f=r?n-1:0,p=r?-1:1,c=t[e+f];for(f+=p,a=c&(1<<-d)-1,c>>=-d,d+=h;d>0;a=256*a+t[e+f],f+=p,d-=8);for(o=a&(1<<-d)-1,a>>=-d,d+=s;d>0;o=256*o+t[e+f],f+=p,d-=8);if(0===a)a=1-u;else{if(a===l)return o?NaN:1/0*(c?-1:1);o+=Math.pow(2,s),a-=u}return(c?-1:1)*o*Math.pow(2,a-s)},r.write=function(t,e,r,s,n,a){var o,h,l,u=8*a-n-1,d=(1<>1,p=23===n?5960464477539062e-23:0,c=s?0:a-1,m=s?1:-1,g=e<0||0===e&&1/e<0?1:0;for(isNaN(e=Math.abs(e))||e===1/0?(h=isNaN(e)?1:0,o=d):(o=Math.floor(Math.log(e)/Math.LN2),e*(l=Math.pow(2,-o))<1&&(o--,l*=2),o+f>=1?e+=p/l:e+=p*Math.pow(2,1-f),e*l>=2&&(o++,l/=2),o+f>=d?(h=0,o=d):o+f>=1?(h=(e*l-1)*Math.pow(2,n),o+=f):(h=e*Math.pow(2,f-1)*Math.pow(2,n),o=0));n>=8;t[r+c]=255&h,c+=m,h/=256,n-=8);for(o=o<0;t[r+c]=255&o,c+=m,o/=256,u-=8);t[r+c-m]|=128*g}},{}],"9pCYc":[function(t,e,r){r.interopDefault=function(t){return t&&t.__esModule?t:{default:t}},r.defineInteropFlag=function(t){Object.defineProperty(t,"__esModule",{value:!0})},r.exportAll=function(t,e){return Object.keys(t).forEach(function(r){"default"===r||"__esModule"===r||Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})}),e},r.export=function(t,e,r){Object.defineProperty(t,e,{enumerable:!0,get:r})}},{}]},["jc2x7"],"jc2x7","parcelRequire4dc0");