jassub 1.5.12 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/jassub-worker-legacy.js +10 -10
- package/dist/jassub-worker.js +11 -11
- package/dist/jassub-worker.wasm +0 -0
- package/dist/jassub.es.js +119 -84
- package/dist/jassub.umd.js +2 -1
- package/package.json +1 -1
- package/src/jassub.js +64 -13
package/dist/jassub-worker.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
var p=p,Be=e=>console.log(e),xe=e=>console.error(e);function ze(){}self.assert||(self.assert=(e,r)=>{if(!e)throw r});String.prototype.startsWith||(String.prototype.startsWith=function(e,r){return r===void 0&&(r=0),this.substring(r,e.length)===e});String.prototype.includes||(String.prototype.includes=function(e,r){return this.indexOf(e,r)!==-1});if(!ArrayBuffer.isView){const e=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];ArrayBuffer.isView=r=>r&&r.constructor&&e.indexOf(r.constructor)!==-1}Uint8Array.prototype.slice||(Uint8Array.prototype.slice=function(e,r){return new Uint8Array(this.subarray(e,r))});Date.now||(Date.now=()=>new Date().getTime());"performance"in self||(self.performance={now:()=>Date.now()});if(typeof console>"u"){const e=(r,t)=>{postMessage({target:"console",command:r,content:JSON.stringify(Array.prototype.slice.call(t))})};console={log:function(){e("log",arguments)},debug:function(){e("debug",arguments)},info:function(){e("info",arguments)},warn:function(){e("warn",arguments)},error:function(){e("error",arguments)}},console.log("Detected lack of console, overridden console")}const Te=(e,r)=>{const t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType=r?"arraybuffer":"text",t.send(null),t.response},mr=(e,r,t)=>{const n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=()=>{if((n.status===200||n.status===0)&&n.response)return r(n.response);t()},n.onerror=t,n.send(null)};p={wasm:WebAssembly&&!WebAssembly.instantiateStreaming&&Te("jassub-worker.wasm",!0)};ze=()=>postMessage({target:"ready"});Be=e=>{e==="JASSUB: No usable fontconfig configuration file found, using fallback."?console.debug(e):console.log(e)};xe=e=>{e==="Fontconfig error: Cannot load default config file: No such file: (null)"?console.debug(e):console.error(e)};let x=0;const br=1;let j=null,Re=!1,Pe=Date.now(),re=24,Ge=!1,Je="js",te={};const Le={};let wr=0,Xe;self.width=0;self.height=0;let E=!1;self.addFont=({font:e})=>$e(e);const we=e=>{e=e.trim().toLowerCase(),e.startsWith("@")&&(e=e.substring(1)),!Le[e]&&(Le[e]=!0,te[e]?$e(te[e]):Ge&&postMessage({target:"getLocalFont",font:e}))},$e=e=>{ArrayBuffer.isView(e)?Ie(e):mr(e,r=>{Ie(new Uint8Array(r))},console.error)},Ie=e=>{const r=ge(e.byteLength);m.set(e,r),self.jassubObj.addFont("font-"+wr++,r,e.byteLength),self.jassubObj.reloadFonts()},qe=e=>{if(!te)return;const r=Pr(e);for(let i=0;i<r.length;i++)for(let s=0;s<r[i].body.length;s++)r[i].body[s].key==="Style"&&we(r[i].body[s].value.Fontname);const t=/\\fn([^\\}]*?)[\\}]/g;let n;for(;(n=t.exec(e))!==null;)we(n[1])};self.setTrack=({content:e})=>{qe(e),self.jassubObj.createTrackMem(e)};self.freeTrack=()=>{self.jassubObj.removeTrack()};self.setTrackByUrl=({url:e})=>{self.setTrack({content:Te(e)})};const _r=(e,r)=>{self.width=e,self.height=r,self.jassubObj.resizeCanvas(e,r)},Cr=()=>{const e=(Date.now()-Pe)/1e3;return ne?x:(e>5&&(console.error("Didn't received currentTime > 5 seconds. Assuming video was paused."),Ye(!0)),x+e*br)},Tr=e=>{x=e,Pe=Date.now(),j||(Re?j=Fe(ie):(ie(),setTimeout(()=>{Re=!1},20)))};let ne=!0;const Ye=e=>{e!==ne&&(ne=e,e?j&&(clearTimeout(j),j=null):(Pe=Date.now(),j=Fe(ie)))},Ae=(e,r)=>{const t=performance.now(),n=Je==="wasm"?self.jassubObj.renderBlend(e,r||0):self.jassubObj.renderImage(e,r||0),i={renderTime:performance.now()-t-self.jassubObj.time,decodeTime:self.jassubObj.time};if(self.jassubObj.changed!==0||r){const s=[];let f=[];const o=performance.now();if(!n)return me({images:s,buffers:f,times:i,decodeStartTime:o});if(E){const a=[];for(let l=n,u=0;u<self.jassubObj.count;l=l.next,++u)s.push({w:l.w,h:l.h,x:l.x,y:l.y}),a.push(createImageBitmap(new ImageData(Se.slice(l.image,l.image+l.w*l.h*4),l.w,l.h)));Promise.all(a).then(l=>{for(let u=0;u<s.length;u++)s[u].image=l[u];f=l,me({images:s,buffers:f,times:i,decodeStartTime:o})})}else{for(let a=n,l=0;l<self.jassubObj.count;a=a.next,++l){const u={w:a.w,h:a.h,x:a.x,y:a.y,image:a.image};if(!M){const c=X.slice(a.image,a.image+a.w*a.h*4);f.push(c),u.image=c}s.push(u)}me({images:s,buffers:f,times:i,decodeStartTime:o})}}else postMessage({target:"unbusy"})};self.demand=({time:e})=>{x=e,Ae(e)};const ie=e=>{j=0,Ae(Cr(),e),ne||(j=Fe(ie))},me=({times:e,images:r,decodeStartTime:t,buffers:n})=>{if(e.decodeTime=performance.now()-t,M){const i=performance.now();I.width=self.width,I.height!==self.height&&(I.height=self.height),M.clearRect(0,0,self.width,self.height);for(const s of r)s.image&&(E?(M.drawImage(s.image,s.x,s.y),s.image.close()):(self.bufferCanvas.width=s.w,self.bufferCanvas.height=s.h,self.bufferCtx.putImageData(new ImageData(Se.subarray(s.image,s.image+s.w*s.h*4),s.w,s.h),0,0),M.drawImage(self.bufferCanvas,s.x,s.y)));if(Xe){e.drawTime=performance.now()-i;let s=0;for(const f in e)s+=e[f];console.log("Bitmaps: "+r.length+" Total: "+Math.round(s)+"ms",e)}postMessage({target:"unbusy"})}else postMessage({target:"render",async:E,images:r,times:e,width:self.width,height:self.height},n)},Pr=e=>{let r,t,n,i,s,f,o,a,l,u;const c=[],d=e.split(/[\r\n]+/g);for(a=0;a<d.length;a++)if(r=d[a].match(/^\[(.*)\]$/),r)t=null,c.push({name:r[1],body:[]});else{if(/^\s*$/.test(d[a])||c.length===0)continue;if(u=c[c.length-1].body,d[a][0]===";")u.push({type:"comment",value:d[a].substring(1)});else{if(i=d[a].split(":"),s=i[0],f=i.slice(1).join(":").trim(),(t||s==="Format")&&(f=f.split(","),t&&f.length>t.length&&(n=f.slice(t.length-1).join(","),f=f.slice(0,t.length-1),f.push(n)),f=f.map(h=>h.trim()),t)){for(o={},l=0;l<f.length;l++)o[t[l]]=f[l];f=o}s==="Format"&&(t=f),u.push({key:s,value:f})}}return c},Fe=(()=>{let e=0;return r=>{const t=Date.now();if(e===0)e=t+1e3/re;else for(;t+2>=e;)e+=1e3/re;const n=Math.max(e-t,0);return setTimeout(r,n)}})(),le=(e,r)=>{for(const t of Object.keys(e))r[t]=e[t]};self.init=e=>{self.width=e.width,self.height=e.height,Je=e.blendMode,E=e.asyncRender,E&&typeof createImageBitmap>"u"&&(E=!1,console.error("'createImageBitmap' needed for 'asyncRender' unsupported!")),te=e.availableFonts,Xe=e.debug,re=e.targetFps||re,Ge=e.useLocalFonts;const r=e.fallbackFont.toLowerCase();self.jassubObj=new p.JASSUB(self.width,self.height,r||null),r&&we(r);let t=e.subContent;t||(t=Te(e.subUrl)),qe(t);for(const n of e.fonts||[])$e(n);self.jassubObj.createTrackMem(t),self.jassubObj.setDropAnimations(e.dropAllAnimations||0),(e.libassMemoryLimit>0||e.libassGlyphLimit>0)&&self.jassubObj.setMemoryLimits(e.libassGlyphLimit||0,e.libassMemoryLimit||0)};self.canvas=({width:e,height:r,force:t})=>{if(e==null)throw new Error("Invalid canvas size specified");_r(e,r),t&&Ae(x)};self.video=({currentTime:e,isPaused:r,rate:t})=>{e!=null&&Tr(e),r!=null&&Ye(r),t=t||t};let I,M;self.offscreenCanvas=({transferable:e})=>{I=e[0],M=I.getContext("2d",{desynchronized:!0}),E||(self.bufferCanvas=new OffscreenCanvas(self.height,self.width),self.bufferCtx=self.bufferCanvas.getContext("2d",{desynchronized:!0}))};self.destroy=()=>{self.jassubObj.quitLibrary()};self.createEvent=({event:e})=>{le(e,self.jassubObj.getEvent(self.jassubObj.allocEvent()))};self.getEvents=()=>{const e=[];for(let r=0;r<self.jassubObj.getEventCount();r++){const{Start:t,Duration:n,ReadOrder:i,Layer:s,Style:f,MarginL:o,MarginR:a,MarginV:l,Name:u,Text:c,Effect:d}=self.jassubObj.getEvent(r);e.push({Start:t,Duration:n,ReadOrder:i,Layer:s,Style:f,MarginL:o,MarginR:a,MarginV:l,Name:u,Text:c,Effect:d})}postMessage({target:"getEvents",events:e})};self.setEvent=({event:e,index:r})=>{le(e,self.jassubObj.getEvent(r))};self.removeEvent=({index:e})=>{self.jassubObj.removeEvent(e)};self.createStyle=({style:e})=>{le(e,self.jassubObj.getStyle(self.jassubObj.allocStyle()))};self.getStyles=()=>{const e=[];for(let r=0;r<self.jassubObj.getStyleCount();r++){const{Name:t,FontName:n,FontSize:i,PrimaryColour:s,SecondaryColour:f,OutlineColour:o,BackColour:a,Bold:l,Italic:u,Underline:c,StrikeOut:d,ScaleX:h,ScaleY:v,Spacing:y,Angle:b,BorderStyle:_,Outline:k,Shadow:T,Alignment:ye,MarginL:Y,MarginR:K,MarginV:Q,Encoding:pr,treat_fontname_as_pattern:hr,Blur:vr,Justify:yr}=self.jassubObj.getStyle(r);e.push({Name:t,FontName:n,FontSize:i,PrimaryColour:s,SecondaryColour:f,OutlineColour:o,BackColour:a,Bold:l,Italic:u,Underline:c,StrikeOut:d,ScaleX:h,ScaleY:v,Spacing:y,Angle:b,BorderStyle:_,Outline:k,Shadow:T,Alignment:ye,MarginL:Y,MarginR:K,MarginV:Q,Encoding:pr,treat_fontname_as_pattern:hr,Blur:vr,Justify:yr})}postMessage({target:"getStyles",time:Date.now(),styles:e})};self.setStyle=({style:e,index:r})=>{le(e,self.jassubObj.getStyle(r))};self.removeStyle=({index:e})=>{self.jassubObj.removeStyle(e)};onmessage=({data:e})=>{if(self[e.target])self[e.target](e);else throw new Error("Unknown event target "+e.target)};let Se=null;ae=(e=>r=>{e(r),Se=new Uint8ClampedArray(X)})(ae);function Ke(e){throw e}var Qe=new TextDecoder("utf8");function $r(e,r,t){for(var n=r+t,i=r;e[i]&&!(i>=n);)++i;return Qe.decode(e.buffer?e.subarray(r,i):new Uint8Array(e.slice(r,i)))}function ee(e,r){if(!e)return"";for(var t=e+r,n=e;!(n>=t)&&m[n];)++n;return Qe.decode(m.subarray(e,n))}function Ar(e,r,t,n){if(!(n>0))return 0;for(var i=t,s=t+n-1,f=0;f<e.length;++f){var o=e.charCodeAt(f);if(o>=55296&&o<=57343){var a=e.charCodeAt(++f);o=65536+((o&1023)<<10)|a&1023}if(o<=127){if(t>=s)break;r[t++]=o}else if(o<=2047){if(t+1>=s)break;r[t++]=192|o>>6,r[t++]=128|o&63}else if(o<=65535){if(t+2>=s)break;r[t++]=224|o>>12,r[t++]=128|o>>6&63,r[t++]=128|o&63}else{if(t+3>=s)break;r[t++]=240|o>>18,r[t++]=128|o>>12&63,r[t++]=128|o>>6&63,r[t++]=128|o&63}}return r[t]=0,t-i}function Fr(e,r,t){return Ar(e,m,r,t)}function Sr(e){for(var r=0,t=0;t<e.length;++t){var n=e.charCodeAt(t);n<=127?r++:n<=2047?r+=2:n>=55296&&n<=57343?(r+=4,++t):r+=3}return r}var je,z,U,m,ue,C,Ze,Ne,se,X,er;function ae(e){X=e,je=new Int8Array(e),z=new Int16Array(e),U=new Int32Array(e),m=new Uint8Array(e),ue=new Uint16Array(e),C=new Uint32Array(e),Ze=new Float32Array(e),Ne=new Float64Array(e)}function jr(e,r,t,n){Ke("Assertion failed: "+ee(e)+", at: "+[r?ee(r):"unknown filename",t,n?ee(n):"unknown function"])}function Or(e,r,t){return 0}function kr(e,r,t){}function Er(e,r,t){return 0}function Ur(e,r,t,n){}function Dr(e,r,t,n,i){}function Oe(e){switch(e){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+e)}}function Mr(){for(var e=new Array(256),r=0;r<256;++r)e[r]=String.fromCharCode(r);rr=e}var rr=void 0;function w(e){for(var r="",t=e;m[t];)r+=rr[m[t++]];return r}var W={},R={},oe={},Wr=48,Rr=57;function ke(e){if(e===void 0)return"_unknown";e=e.replace(/[^a-zA-Z0-9_]/g,"$");var r=e.charCodeAt(0);return r>=Wr&&r<=Rr?"_"+e:e}function Ee(e,r){return e=ke(e),new Function("body","return function "+e+`() {
|
|
1
|
+
var h=h,qe=e=>console.log(e),Ye=e=>console.error(e);function Ke(){}self.assert||(self.assert=(e,r)=>{if(!e)throw r});String.prototype.startsWith||(String.prototype.startsWith=function(e,r){return r===void 0&&(r=0),this.substring(r,e.length)===e});String.prototype.includes||(String.prototype.includes=function(e,r){return this.indexOf(e,r)!==-1});if(!ArrayBuffer.isView){const e=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];ArrayBuffer.isView=r=>r&&r.constructor&&e.indexOf(r.constructor)!==-1}Uint8Array.prototype.slice||(Uint8Array.prototype.slice=function(e,r){return new Uint8Array(this.subarray(e,r))});Date.now||(Date.now=()=>new Date().getTime());"performance"in self||(self.performance={now:()=>Date.now()});if(typeof console>"u"){const e=(r,t)=>{postMessage({target:"console",command:r,content:JSON.stringify(Array.prototype.slice.call(t))})};console={log:function(){e("log",arguments)},debug:function(){e("debug",arguments)},info:function(){e("info",arguments)},warn:function(){e("warn",arguments)},error:function(){e("error",arguments)}},console.log("Detected lack of console, overridden console")}const Se=(e,r)=>{const t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType=r?"arraybuffer":"text",t.send(null),t.response},Sr=(e,r,t)=>{const n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=()=>{if((n.status===200||n.status===0)&&n.response)return r(n.response);t()},n.onerror=t,n.send(null)};h={wasm:WebAssembly&&!WebAssembly.instantiateStreaming&&Se("jassub-worker.wasm",!0)};Ke=()=>postMessage({target:"ready"});qe=e=>{e==="JASSUB: No usable fontconfig configuration file found, using fallback."?console.debug(e):console.log(e)};Ye=e=>{e==="Fontconfig error: Cannot load default config file: No such file: (null)"?console.debug(e):console.error(e)};let J=0;const Fr=1;let E=null,He=!1,Fe=Date.now(),ie=24,Qe=!1,Ze="js",oe={};const Ve={};let Ar=0,Ne;self.width=0;self.height=0;let M=!1;self.addFont=({font:e})=>Ae(e);const Te=e=>{e=e.trim().toLowerCase(),e.startsWith("@")&&(e=e.substring(1)),!Ve[e]&&(Ve[e]=!0,oe[e]?Ae(oe[e]):Qe&&postMessage({target:"getLocalFont",font:e}))},Ae=e=>{ArrayBuffer.isView(e)?xe(e):Sr(e,r=>{xe(new Uint8Array(r))},console.error)},xe=e=>{const r=ve(e.byteLength);w.set(e,r),p.addFont("font-"+Ar++,r,e.byteLength),p.reloadFonts()},er=e=>{if(!oe)return;const r=Or(e);for(let i=0;i<r.length;i++)for(let s=0;s<r[i].body.length;s++)r[i].body[s].key==="Style"&&Te(r[i].body[s].value.Fontname);const t=/\\fn([^\\}]*?)[\\}]/g;let n;for(;(n=t.exec(e))!==null;)Te(n[1])};self.setTrack=({content:e})=>{er(e),p.createTrackMem(e),Oe=tr[p.getTrackColorSpace()]};self.freeTrack=()=>{p.removeTrack()};self.setTrackByUrl=({url:e})=>{self.setTrack({content:Se(e)})};const kr=()=>{const e=(Date.now()-Fe)/1e3;return ae?J:(e>5&&(console.error("Didn't received currentTime > 5 seconds. Assuming video was paused."),rr(!0)),J+e*Fr)},Er=e=>{J=e,Fe=Date.now(),E||(He?E=Ee(se):(se(),setTimeout(()=>{He=!1},20)))};let ae=!0;const rr=e=>{e!==ae&&(ae=e,e?E&&(clearTimeout(E),E=null):(Fe=Date.now(),E=Ee(se)))},H="BT.601",ze="BT.709",Ge="SMPTE240M",tr=[H,H,H,H,H,ze,ze,Ge,Ge,"FCC","FCC"],ke=(e,r)=>{const t=performance.now(),n=Ze==="wasm"?p.renderBlend(e,r||0):p.renderImage(e,r||0),i={renderTime:performance.now()-t-p.time,decodeTime:p.time};if(p.changed!==0||r){const s=[];let o=[];const f=performance.now();if(!n)return _e({images:s,buffers:o,times:i,decodeStartTime:f});if(M){const a=[];for(let l=n,u=0;u<p.count;l=l.next,++u)s.push({w:l.w,h:l.h,x:l.x,y:l.y}),a.push(createImageBitmap(new ImageData(Ue.slice(l.image,l.image+l.w*l.h*4),l.w,l.h)));Promise.all(a).then(l=>{for(let u=0;u<s.length;u++)s[u].image=l[u];o=l,_e({images:s,buffers:o,times:i,decodeStartTime:f})})}else{for(let a=n,l=0;l<p.count;a=a.next,++l){const u={w:a.w,h:a.h,x:a.x,y:a.y,image:a.image};if(!j){const c=K.slice(a.image,a.image+a.w*a.h*4);o.push(c),u.image=c}s.push(u)}_e({images:s,buffers:o,times:i,decodeStartTime:f})}}else postMessage({target:"unbusy"})};self.demand=({time:e})=>{J=e,ke(e)};const se=e=>{E=0,ke(kr(),e),ae||(E=Ee(se))},_e=({times:e,images:r,decodeStartTime:t,buffers:n})=>{e.decodeTime=performance.now()-t;const i={target:"render",async:M,images:r,times:e,width:self.width,height:self.height,colorSpace:Oe};if(j){const s=performance.now();(D.height!==self.height||D.width!==self.width)&&(D.width=self.width,D.height=self.height),j.clearRect(0,0,self.width,self.height);for(const o of r)o.image&&(M?(j.drawImage(o.image,o.x,o.y),o.image.close()):(V.width=o.w,V.height=o.h,nr.putImageData(new ImageData(Ue.subarray(o.image,o.image+o.w*o.h*4),o.w,o.h),0,0),j.drawImage(V,o.x,o.y)));if(Ne){e.drawTime=performance.now()-s;let o=0;for(const f in e)o+=e[f];console.log("Bitmaps: "+r.length+" Total: "+Math.round(o)+"ms",e)}try{const o=D.transferToImageBitmap();i.images=[{image:o,x:0,y:0}],i.async=!0,postMessage(i,[o])}catch{postMessage({target:"unbusy"})}}else postMessage(i,n)},Or=e=>{let r,t,n,i,s,o,f,a,l,u;const c=[],d=e.split(/[\r\n]+/g);for(a=0;a<d.length;a++)if(r=d[a].match(/^\[(.*)\]$/),r)t=null,c.push({name:r[1],body:[]});else{if(/^\s*$/.test(d[a])||c.length===0)continue;if(u=c[c.length-1].body,d[a][0]===";")u.push({type:"comment",value:d[a].substring(1)});else{if(i=d[a].split(":"),s=i[0],o=i.slice(1).join(":").trim(),(t||s==="Format")&&(o=o.split(","),t&&o.length>t.length&&(n=o.slice(t.length-1).join(","),o=o.slice(0,t.length-1),o.push(n)),o=o.map(v=>v.trim()),t)){for(f={},l=0;l<o.length;l++)f[t[l]]=o[l];o=f}s==="Format"&&(t=o),u.push({key:s,value:o})}}return c},Ee=(()=>{let e=0;return r=>{const t=Date.now();if(e===0)e=t+1e3/ie;else for(;t+2>=e;)e+=1e3/ie;const n=Math.max(e-t,0);return setTimeout(r,n)}})(),de=(e,r)=>{for(const t of Object.keys(e))r[t]=e[t]};let D,j,V,nr,p,Oe;self.init=e=>{self.width=e.width,self.height=e.height,Ze=e.blendMode,M=e.asyncRender,M&&typeof createImageBitmap>"u"&&(M=!1,console.error("'createImageBitmap' needed for 'asyncRender' unsupported!")),oe=e.availableFonts,Ne=e.debug,ie=e.targetFps||ie,Qe=e.useLocalFonts;const r=e.fallbackFont.toLowerCase();p=new h.JASSUB(self.width,self.height,r||null),r&&Te(r);let t=e.subContent;t||(t=Se(e.subUrl)),er(t);for(const n of e.fonts||[])Ae(n);p.createTrackMem(t),Oe=tr[p.trackColorSpace],p.setDropAnimations(e.dropAllAnimations||0),(e.libassMemoryLimit>0||e.libassGlyphLimit>0)&&p.setMemoryLimits(e.libassGlyphLimit||0,e.libassMemoryLimit||0),e.offscreenRender&&(D=new OffscreenCanvas(self.height,self.width),j=D.getContext("2d",{desynchronized:!0}),M||(V=new OffscreenCanvas(self.height,self.width),nr=V.getContext("2d",{desynchronized:!0})))};self.canvas=({width:e,height:r,force:t})=>{if(e==null)throw new Error("Invalid canvas size specified");self.width=e,self.height=r,p.resizeCanvas(e,r),t&&ke(J)};self.video=({currentTime:e,isPaused:r,rate:t})=>{e!=null&&Er(e),r!=null&&rr(r),t=t||t};self.destroy=()=>{p.quitLibrary()};self.createEvent=({event:e})=>{de(e,p.getEvent(p.allocEvent()))};self.getEvents=()=>{const e=[];for(let r=0;r<p.getEventCount();r++){const{Start:t,Duration:n,ReadOrder:i,Layer:s,Style:o,MarginL:f,MarginR:a,MarginV:l,Name:u,Text:c,Effect:d}=p.getEvent(r);e.push({Start:t,Duration:n,ReadOrder:i,Layer:s,Style:o,MarginL:f,MarginR:a,MarginV:l,Name:u,Text:c,Effect:d})}postMessage({target:"getEvents",events:e})};self.setEvent=({event:e,index:r})=>{de(e,p.getEvent(r))};self.removeEvent=({index:e})=>{p.removeEvent(e)};self.createStyle=({style:e})=>{de(e,p.getStyle(p.allocStyle()))};self.getStyles=()=>{const e=[];for(let r=0;r<p.getStyleCount();r++){const{Name:t,FontName:n,FontSize:i,PrimaryColour:s,SecondaryColour:o,OutlineColour:f,BackColour:a,Bold:l,Italic:u,Underline:c,StrikeOut:d,ScaleX:v,ScaleY:y,Spacing:m,Angle:b,BorderStyle:C,Outline:U,Shadow:P,Alignment:be,MarginL:Z,MarginR:N,MarginV:ee,Encoding:Cr,treat_fontname_as_pattern:Tr,Blur:Pr,Justify:$r}=p.getStyle(r);e.push({Name:t,FontName:n,FontSize:i,PrimaryColour:s,SecondaryColour:o,OutlineColour:f,BackColour:a,Bold:l,Italic:u,Underline:c,StrikeOut:d,ScaleX:v,ScaleY:y,Spacing:m,Angle:b,BorderStyle:C,Outline:U,Shadow:P,Alignment:be,MarginL:Z,MarginR:N,MarginV:ee,Encoding:Cr,treat_fontname_as_pattern:Tr,Blur:Pr,Justify:$r})}postMessage({target:"getStyles",time:Date.now(),styles:e})};self.setStyle=({style:e,index:r})=>{de(e,p.getStyle(r))};self.removeStyle=({index:e})=>{p.removeStyle(e)};onmessage=({data:e})=>{if(self[e.target])self[e.target](e);else throw new Error("Unknown event target "+e.target)};let Ue=null;le=(e=>r=>{e(r),Ue=new Uint8ClampedArray(K)})(le);function ir(e){throw e}var or=new TextDecoder("utf8");function Ur(e,r,t){for(var n=r+t,i=r;e[i]&&!(i>=n);)++i;return or.decode(e.buffer?e.subarray(r,i):new Uint8Array(e.slice(r,i)))}function ne(e,r){if(!e)return"";for(var t=e+r,n=e;!(n>=t)&&w[n];)++n;return or.decode(w.subarray(e,n))}function Dr(e,r,t,n){if(!(n>0))return 0;for(var i=t,s=t+n-1,o=0;o<e.length;++o){var f=e.charCodeAt(o);if(f>=55296&&f<=57343){var a=e.charCodeAt(++o);f=65536+((f&1023)<<10)|a&1023}if(f<=127){if(t>=s)break;r[t++]=f}else if(f<=2047){if(t+1>=s)break;r[t++]=192|f>>6,r[t++]=128|f&63}else if(f<=65535){if(t+2>=s)break;r[t++]=224|f>>12,r[t++]=128|f>>6&63,r[t++]=128|f&63}else{if(t+3>=s)break;r[t++]=240|f>>18,r[t++]=128|f>>12&63,r[t++]=128|f>>6&63,r[t++]=128|f&63}}return r[t]=0,t-i}function Mr(e,r,t){return Dr(e,w,r,t)}function Wr(e){for(var r=0,t=0;t<e.length;++t){var n=e.charCodeAt(t);n<=127?r++:n<=2047?r+=2:n>=55296&&n<=57343?(r+=4,++t):r+=3}return r}var De,X,W,w,ge,T,ar,sr,fe,K,fr;function le(e){K=e,De=new Int8Array(e),X=new Int16Array(e),W=new Int32Array(e),w=new Uint8Array(e),ge=new Uint16Array(e),T=new Uint32Array(e),ar=new Float32Array(e),sr=new Float64Array(e)}function Rr(e,r,t,n){ir("Assertion failed: "+ne(e)+", at: "+[r?ne(r):"unknown filename",t,n?ne(n):"unknown function"])}function jr(e,r,t){return 0}function Ir(e,r,t){}function Lr(e,r,t){return 0}function Br(e,r,t,n){}function Hr(e,r,t,n,i){}function Me(e){switch(e){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+e)}}function Vr(){for(var e=new Array(256),r=0;r<256;++r)e[r]=String.fromCharCode(r);lr=e}var lr=void 0;function _(e){for(var r="",t=e;w[t];)r+=lr[w[t++]];return r}var I={},L={},ue={},xr=48,zr=57;function We(e){if(e===void 0)return"_unknown";e=e.replace(/[^a-zA-Z0-9_]/g,"$");var r=e.charCodeAt(0);return r>=xr&&r<=zr?"_"+e:e}function Re(e,r){return e=We(e),new Function("body","return function "+e+`() {
|
|
2
2
|
"use strict"; return body.apply(this, arguments);
|
|
3
3
|
};
|
|
4
|
-
`)(r)}function
|
|
5
|
-
`+i.replace(/^Error(:[^\n]*)?\n/,""))});return t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.prototype.toString=function(){return this.message===void 0?this.name:this.name+": "+this.message},t}var L=void 0;function g(e){throw new L(e)}var tr=void 0;function fe(e){throw new tr(e)}function D(e,r,t){e.forEach(function(o){oe[o]=r});function n(o){var a=t(o);a.length!==e.length&&fe("Mismatched type converter count");for(var l=0;l<e.length;++l)F(e[l],a[l])}var i=new Array(r.length),s=[],f=0;r.forEach((o,a)=>{R.hasOwnProperty(o)?i[a]=R[o]:(s.push(o),W.hasOwnProperty(o)||(W[o]=[]),W[o].push(()=>{i[a]=R[o],++f,f===s.length&&n(i)}))}),s.length===0&&n(i)}function F(e,r,t={}){if(!("argPackAdvance"in r))throw new TypeError("registerType registeredInstance requires argPackAdvance");var n=r.name;if(e||g('type "'+n+'" must have a positive integer typeid pointer'),R.hasOwnProperty(e)){if(t.ignoreDuplicateRegistrations)return;g("Cannot register type '"+n+"' twice")}if(R[e]=r,delete oe[e],W.hasOwnProperty(e)){var i=W[e];delete W[e],i.forEach(s=>s())}}function Lr(e,r,t,n,i){var s=Oe(t);r=w(r),F(e,{name:r,fromWireType:function(f){return!!f},toWireType:function(f,o){return o?n:i},argPackAdvance:8,readValueFromPointer:function(f){var o;if(t===1)o=je;else if(t===2)o=z;else if(t===4)o=U;else throw new TypeError("Unknown boolean type size: "+r);return this.fromWireType(o[f>>s])},destructorFunction:null})}function Ir(e){if(!(this instanceof S)||!(e instanceof S))return!1;for(var r=this.$$.ptrType.registeredClass,t=this.$$.ptr,n=e.$$.ptrType.registeredClass,i=e.$$.ptr;r.baseClass;)t=r.upcast(t),r=r.baseClass;for(;n.baseClass;)i=n.upcast(i),n=n.baseClass;return r===n&&t===i}function Hr(e){return{count:e.count,deleteScheduled:e.deleteScheduled,preservePointerOnDelete:e.preservePointerOnDelete,ptr:e.ptr,ptrType:e.ptrType,smartPtr:e.smartPtr,smartPtrType:e.smartPtrType}}function De(e){function r(t){return t.$$.ptrType.registeredClass.name}g(r(e)+" instance already deleted")}var be=!1;function nr(e){}function Vr(e){e.smartPtr?e.smartPtrType.rawDestructor(e.smartPtr):e.ptrType.registeredClass.rawDestructor(e.ptr)}function ir(e){e.count.value-=1;var r=e.count.value===0;r&&Vr(e)}function sr(e,r,t){if(r===t)return e;if(t.baseClass===void 0)return null;var n=sr(e,r,t.baseClass);return n===null?null:t.downcast(n)}var ar={};function Br(){return Object.keys(V).length}function xr(){var e=[];for(var r in V)V.hasOwnProperty(r)&&e.push(V[r]);return e}var G=[];function Me(){for(;G.length;){var e=G.pop();e.$$.deleteScheduled=!1,e.delete()}}var H=void 0;function zr(e){H=e,G.length&&H&&H(Me)}function Gr(){p.getInheritedInstanceCount=Br,p.getLiveInheritedInstances=xr,p.flushPendingDeletes=Me,p.setDelayFunction=zr}var V={};function Jr(e,r){for(r===void 0&&g("ptr should not be undefined");e.baseClass;)r=e.upcast(r),e=e.baseClass;return r}function Xr(e,r){return r=Jr(e,r),V[r]}function Z(e,r){(!r.ptrType||!r.ptr)&&fe("makeClassHandle requires ptr and ptrType");var t=!!r.smartPtrType,n=!!r.smartPtr;return t!==n&&fe("Both smartPtrType and smartPtr must be specified"),r.count={value:1},B(Object.create(e,{$$:{value:r}}))}function qr(e){var r=this.getPointee(e);if(!r)return this.destructor(e),null;var t=Xr(this.registeredClass,r);if(t!==void 0){if(t.$$.count.value===0)return t.$$.ptr=r,t.$$.smartPtr=e,t.clone();var n=t.clone();return this.destructor(e),n}function i(){return this.isSmartPointer?Z(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:r,smartPtrType:this,smartPtr:e}):Z(this.registeredClass.instancePrototype,{ptrType:this,ptr:e})}var s=this.registeredClass.getActualType(r),f=ar[s];if(!f)return i.call(this);var o;this.isConst?o=f.constPointerType:o=f.pointerType;var a=sr(r,this.registeredClass,o.registeredClass);return a===null?i.call(this):this.isSmartPointer?Z(o.registeredClass.instancePrototype,{ptrType:o,ptr:a,smartPtrType:this,smartPtr:e}):Z(o.registeredClass.instancePrototype,{ptrType:o,ptr:a})}function B(e){return typeof FinalizationRegistry>"u"?(B=r=>r,e):(be=new FinalizationRegistry(r=>{ir(r.$$)}),B=r=>{var t=r.$$,n=!!t.smartPtr;if(n){var i={$$:t};be.register(r,i,r)}return r},nr=r=>be.unregister(r),B(e))}function Yr(){if(this.$$.ptr||De(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var e=B(Object.create(Object.getPrototypeOf(this),{$$:{value:Hr(this.$$)}}));return e.$$.count.value+=1,e.$$.deleteScheduled=!1,e}function Kr(){this.$$.ptr||De(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&g("Object already scheduled for deletion"),nr(this),ir(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function Qr(){return!this.$$.ptr}function Zr(){return this.$$.ptr||De(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&g("Object already scheduled for deletion"),G.push(this),G.length===1&&H&&H(Me),this.$$.deleteScheduled=!0,this}function Nr(){S.prototype.isAliasOf=Ir,S.prototype.clone=Yr,S.prototype.delete=Kr,S.prototype.isDeleted=Qr,S.prototype.deleteLater=Zr}function S(){}function or(e,r,t){if(e[r].overloadTable===void 0){var n=e[r];e[r]=function(){return e[r].overloadTable.hasOwnProperty(arguments.length)||g("Function '"+t+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+e[r].overloadTable+")!"),e[r].overloadTable[arguments.length].apply(this,arguments)},e[r].overloadTable=[],e[r].overloadTable[n.argCount]=n}}function et(e,r,t){p.hasOwnProperty(e)?((t===void 0||p[e].overloadTable!==void 0&&p[e].overloadTable[t]!==void 0)&&g("Cannot register public name '"+e+"' twice"),or(p,e,e),p.hasOwnProperty(t)&&g("Cannot register multiple overloads of a function with the same number of arguments ("+t+")!"),p[e].overloadTable[t]=r):(p[e]=r,t!==void 0&&(p[e].numArguments=t))}function rt(e,r,t,n,i,s,f,o){this.name=e,this.constructor=r,this.instancePrototype=t,this.rawDestructor=n,this.baseClass=i,this.getActualType=s,this.upcast=f,this.downcast=o,this.pureVirtualFunctions=[]}function ce(e,r,t){for(;r!==t;)r.upcast||g("Expected null or instance of "+t.name+", got an instance of "+r.name),e=r.upcast(e),r=r.baseClass;return e}function tt(e,r){if(r===null)return this.isReference&&g("null is not a valid "+this.name),0;r.$$||g('Cannot pass "'+We(r)+'" as a '+this.name),r.$$.ptr||g("Cannot pass deleted object as a pointer of type "+this.name);var t=r.$$.ptrType.registeredClass,n=ce(r.$$.ptr,t,this.registeredClass);return n}function nt(e,r){var t;if(r===null)return this.isReference&&g("null is not a valid "+this.name),this.isSmartPointer?(t=this.rawConstructor(),e!==null&&e.push(this.rawDestructor,t),t):0;r.$$||g('Cannot pass "'+We(r)+'" as a '+this.name),r.$$.ptr||g("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&r.$$.ptrType.isConst&&g("Cannot convert argument of type "+(r.$$.smartPtrType?r.$$.smartPtrType.name:r.$$.ptrType.name)+" to parameter type "+this.name);var n=r.$$.ptrType.registeredClass;if(t=ce(r.$$.ptr,n,this.registeredClass),this.isSmartPointer)switch(r.$$.smartPtr===void 0&&g("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:r.$$.smartPtrType===this?t=r.$$.smartPtr:g("Cannot convert argument of type "+(r.$$.smartPtrType?r.$$.smartPtrType.name:r.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:t=r.$$.smartPtr;break;case 2:if(r.$$.smartPtrType===this)t=r.$$.smartPtr;else{var i=r.clone();t=this.rawShare(t,Ce.toHandle(function(){i.delete()})),e!==null&&e.push(this.rawDestructor,t)}break;default:g("Unsupporting sharing policy")}return t}function it(e,r){if(r===null)return this.isReference&&g("null is not a valid "+this.name),0;r.$$||g('Cannot pass "'+We(r)+'" as a '+this.name),r.$$.ptr||g("Cannot pass deleted object as a pointer of type "+this.name),r.$$.ptrType.isConst&&g("Cannot convert argument of type "+r.$$.ptrType.name+" to parameter type "+this.name);var t=r.$$.ptrType.registeredClass,n=ce(r.$$.ptr,t,this.registeredClass);return n}function de(e){return this.fromWireType(U[e>>2])}function st(e){return this.rawGetPointee&&(e=this.rawGetPointee(e)),e}function at(e){this.rawDestructor&&this.rawDestructor(e)}function ot(e){e!==null&&e.delete()}function ft(){$.prototype.getPointee=st,$.prototype.destructor=at,$.prototype.argPackAdvance=8,$.prototype.readValueFromPointer=de,$.prototype.deleteObject=ot,$.prototype.fromWireType=qr}function $(e,r,t,n,i,s,f,o,a,l,u){this.name=e,this.registeredClass=r,this.isReference=t,this.isConst=n,this.isSmartPointer=i,this.pointeeType=s,this.sharingPolicy=f,this.rawGetPointee=o,this.rawConstructor=a,this.rawShare=l,this.rawDestructor=u,!i&&r.baseClass===void 0?n?(this.toWireType=tt,this.destructorFunction=null):(this.toWireType=it,this.destructorFunction=null):this.toWireType=nt}function lt(e,r,t){p.hasOwnProperty(e)||fe("Replacing nonexistant public symbol"),p[e].overloadTable!==void 0&&t!==void 0?p[e].overloadTable[t]=r:(p[e]=r,p[e].argCount=t)}function ut(e,r,t){var n=dynCalls[e];return t&&t.length?n.apply(null,[r].concat(t)):n.call(null,r)}var N=[];function q(e){var r=N[e];return r||(e>=N.length&&(N.length=e+1),N[e]=r=er.get(e)),r}function ct(e,r,t){if(e.includes("j"))return ut(e,r,t);var n=q(r).apply(null,t);return n}function dt(e,r){var t=[];return function(){return t.length=0,Object.assign(t,arguments),ct(e,r,t)}}function O(e,r){e=w(e);function t(){return e.includes("j")?dt(e,r):q(r)}var n=t();return typeof n!="function"&&g("unknown function pointer with signature "+e+": "+r),n}var fr=void 0;function gt(e){var r=gr(e),t=w(r);return A(r),t}function J(e,r){var t=[],n={};function i(s){if(!n[s]&&!R[s]){if(oe[s]){oe[s].forEach(i);return}t.push(s),n[s]=!0}}throw r.forEach(i),new fr(e+": "+t.map(gt).join([", "]))}function pt(e,r,t,n,i,s,f,o,a,l,u,c,d){u=w(u),s=O(i,s),o&&(o=O(f,o)),l&&(l=O(a,l)),d=O(c,d);var h=ke(u);et(h,function(){J("Cannot construct "+u+" due to unbound types",[n])}),D([e,r,t],n?[n]:[],function(v){v=v[0];var y,b;n?(y=v.registeredClass,b=y.instancePrototype):b=S.prototype;var _=Ee(h,function(){if(Object.getPrototypeOf(this)!==k)throw new L("Use 'new' to construct "+u);if(T.constructor_body===void 0)throw new L(u+" has no accessible constructor");var Q=T.constructor_body[arguments.length];if(Q===void 0)throw new L("Tried to invoke ctor of "+u+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(T.constructor_body).toString()+") parameters instead!");return Q.apply(this,arguments)}),k=Object.create(b,{constructor:{value:_}});_.prototype=k;var T=new rt(u,_,k,d,y,s,o,l),ye=new $(u,T,!0,!1,!1),Y=new $(u+"*",T,!1,!1,!1),K=new $(u+" const*",T,!1,!0,!1);return ar[e]={pointerType:Y,constPointerType:K},lt(h,_),[ye,Y,K]})}function lr(e,r){for(var t=[],n=0;n<e;n++)t.push(C[r+n*4>>2]);return t}function ur(e){for(;e.length;){var r=e.pop(),t=e.pop();t(r)}}function ht(e,r){if(!(e instanceof Function))throw new TypeError("new_ called with constructor type "+typeof e+" which is not a function");var t=Ee(e.name||"unknownFunctionName",function(){});t.prototype=e.prototype;var n=new t,i=e.apply(n,r);return i instanceof Object?i:n}function cr(e,r,t,n,i){var s=r.length;s<2&&g("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var f=r[1]!==null&&t!==null,o=!1,a=1;a<r.length;++a)if(r[a]!==null&&r[a].destructorFunction===void 0){o=!0;break}for(var l=r[0].name!=="void",u="",c="",a=0;a<s-2;++a)u+=(a!==0?", ":"")+"arg"+a,c+=(a!==0?", ":"")+"arg"+a+"Wired";var d="return function "+ke(e)+"("+u+`) {
|
|
4
|
+
`)(r)}function je(e,r){var t=Re(r,function(n){this.name=r,this.message=n;var i=new Error(n).stack;i!==void 0&&(this.stack=this.toString()+`
|
|
5
|
+
`+i.replace(/^Error(:[^\n]*)?\n/,""))});return t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.prototype.toString=function(){return this.message===void 0?this.name:this.name+": "+this.message},t}var B=void 0;function g(e){throw new B(e)}var ur=void 0;function ce(e){throw new ur(e)}function R(e,r,t){e.forEach(function(f){ue[f]=r});function n(f){var a=t(f);a.length!==e.length&&ce("Mismatched type converter count");for(var l=0;l<e.length;++l)A(e[l],a[l])}var i=new Array(r.length),s=[],o=0;r.forEach((f,a)=>{L.hasOwnProperty(f)?i[a]=L[f]:(s.push(f),I.hasOwnProperty(f)||(I[f]=[]),I[f].push(()=>{i[a]=L[f],++o,o===s.length&&n(i)}))}),s.length===0&&n(i)}function A(e,r,t={}){if(!("argPackAdvance"in r))throw new TypeError("registerType registeredInstance requires argPackAdvance");var n=r.name;if(e||g('type "'+n+'" must have a positive integer typeid pointer'),L.hasOwnProperty(e)){if(t.ignoreDuplicateRegistrations)return;g("Cannot register type '"+n+"' twice")}if(L[e]=r,delete ue[e],I.hasOwnProperty(e)){var i=I[e];delete I[e],i.forEach(s=>s())}}function Gr(e,r,t,n,i){var s=Me(t);r=_(r),A(e,{name:r,fromWireType:function(o){return!!o},toWireType:function(o,f){return f?n:i},argPackAdvance:8,readValueFromPointer:function(o){var f;if(t===1)f=De;else if(t===2)f=X;else if(t===4)f=W;else throw new TypeError("Unknown boolean type size: "+r);return this.fromWireType(f[o>>s])},destructorFunction:null})}function Jr(e){if(!(this instanceof k)||!(e instanceof k))return!1;for(var r=this.$$.ptrType.registeredClass,t=this.$$.ptr,n=e.$$.ptrType.registeredClass,i=e.$$.ptr;r.baseClass;)t=r.upcast(t),r=r.baseClass;for(;n.baseClass;)i=n.upcast(i),n=n.baseClass;return r===n&&t===i}function Xr(e){return{count:e.count,deleteScheduled:e.deleteScheduled,preservePointerOnDelete:e.preservePointerOnDelete,ptr:e.ptr,ptrType:e.ptrType,smartPtr:e.smartPtr,smartPtrType:e.smartPtrType}}function Ie(e){function r(t){return t.$$.ptrType.registeredClass.name}g(r(e)+" instance already deleted")}var Ce=!1;function cr(e){}function qr(e){e.smartPtr?e.smartPtrType.rawDestructor(e.smartPtr):e.ptrType.registeredClass.rawDestructor(e.ptr)}function dr(e){e.count.value-=1;var r=e.count.value===0;r&&qr(e)}function gr(e,r,t){if(r===t)return e;if(t.baseClass===void 0)return null;var n=gr(e,r,t.baseClass);return n===null?null:t.downcast(n)}var pr={};function Yr(){return Object.keys(z).length}function Kr(){var e=[];for(var r in z)z.hasOwnProperty(r)&&e.push(z[r]);return e}var q=[];function Le(){for(;q.length;){var e=q.pop();e.$$.deleteScheduled=!1,e.delete()}}var x=void 0;function Qr(e){x=e,q.length&&x&&x(Le)}function Zr(){h.getInheritedInstanceCount=Yr,h.getLiveInheritedInstances=Kr,h.flushPendingDeletes=Le,h.setDelayFunction=Qr}var z={};function Nr(e,r){for(r===void 0&&g("ptr should not be undefined");e.baseClass;)r=e.upcast(r),e=e.baseClass;return r}function et(e,r){return r=Nr(e,r),z[r]}function re(e,r){(!r.ptrType||!r.ptr)&&ce("makeClassHandle requires ptr and ptrType");var t=!!r.smartPtrType,n=!!r.smartPtr;return t!==n&&ce("Both smartPtrType and smartPtr must be specified"),r.count={value:1},G(Object.create(e,{$$:{value:r}}))}function rt(e){var r=this.getPointee(e);if(!r)return this.destructor(e),null;var t=et(this.registeredClass,r);if(t!==void 0){if(t.$$.count.value===0)return t.$$.ptr=r,t.$$.smartPtr=e,t.clone();var n=t.clone();return this.destructor(e),n}function i(){return this.isSmartPointer?re(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:r,smartPtrType:this,smartPtr:e}):re(this.registeredClass.instancePrototype,{ptrType:this,ptr:e})}var s=this.registeredClass.getActualType(r),o=pr[s];if(!o)return i.call(this);var f;this.isConst?f=o.constPointerType:f=o.pointerType;var a=gr(r,this.registeredClass,f.registeredClass);return a===null?i.call(this):this.isSmartPointer?re(f.registeredClass.instancePrototype,{ptrType:f,ptr:a,smartPtrType:this,smartPtr:e}):re(f.registeredClass.instancePrototype,{ptrType:f,ptr:a})}function G(e){return typeof FinalizationRegistry>"u"?(G=r=>r,e):(Ce=new FinalizationRegistry(r=>{dr(r.$$)}),G=r=>{var t=r.$$,n=!!t.smartPtr;if(n){var i={$$:t};Ce.register(r,i,r)}return r},cr=r=>Ce.unregister(r),G(e))}function tt(){if(this.$$.ptr||Ie(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var e=G(Object.create(Object.getPrototypeOf(this),{$$:{value:Xr(this.$$)}}));return e.$$.count.value+=1,e.$$.deleteScheduled=!1,e}function nt(){this.$$.ptr||Ie(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&g("Object already scheduled for deletion"),cr(this),dr(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function it(){return!this.$$.ptr}function ot(){return this.$$.ptr||Ie(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&g("Object already scheduled for deletion"),q.push(this),q.length===1&&x&&x(Le),this.$$.deleteScheduled=!0,this}function at(){k.prototype.isAliasOf=Jr,k.prototype.clone=tt,k.prototype.delete=nt,k.prototype.isDeleted=it,k.prototype.deleteLater=ot}function k(){}function hr(e,r,t){if(e[r].overloadTable===void 0){var n=e[r];e[r]=function(){return e[r].overloadTable.hasOwnProperty(arguments.length)||g("Function '"+t+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+e[r].overloadTable+")!"),e[r].overloadTable[arguments.length].apply(this,arguments)},e[r].overloadTable=[],e[r].overloadTable[n.argCount]=n}}function st(e,r,t){h.hasOwnProperty(e)?((t===void 0||h[e].overloadTable!==void 0&&h[e].overloadTable[t]!==void 0)&&g("Cannot register public name '"+e+"' twice"),hr(h,e,e),h.hasOwnProperty(t)&&g("Cannot register multiple overloads of a function with the same number of arguments ("+t+")!"),h[e].overloadTable[t]=r):(h[e]=r,t!==void 0&&(h[e].numArguments=t))}function ft(e,r,t,n,i,s,o,f){this.name=e,this.constructor=r,this.instancePrototype=t,this.rawDestructor=n,this.baseClass=i,this.getActualType=s,this.upcast=o,this.downcast=f,this.pureVirtualFunctions=[]}function pe(e,r,t){for(;r!==t;)r.upcast||g("Expected null or instance of "+t.name+", got an instance of "+r.name),e=r.upcast(e),r=r.baseClass;return e}function lt(e,r){if(r===null)return this.isReference&&g("null is not a valid "+this.name),0;r.$$||g('Cannot pass "'+Be(r)+'" as a '+this.name),r.$$.ptr||g("Cannot pass deleted object as a pointer of type "+this.name);var t=r.$$.ptrType.registeredClass,n=pe(r.$$.ptr,t,this.registeredClass);return n}function ut(e,r){var t;if(r===null)return this.isReference&&g("null is not a valid "+this.name),this.isSmartPointer?(t=this.rawConstructor(),e!==null&&e.push(this.rawDestructor,t),t):0;r.$$||g('Cannot pass "'+Be(r)+'" as a '+this.name),r.$$.ptr||g("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&r.$$.ptrType.isConst&&g("Cannot convert argument of type "+(r.$$.smartPtrType?r.$$.smartPtrType.name:r.$$.ptrType.name)+" to parameter type "+this.name);var n=r.$$.ptrType.registeredClass;if(t=pe(r.$$.ptr,n,this.registeredClass),this.isSmartPointer)switch(r.$$.smartPtr===void 0&&g("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:r.$$.smartPtrType===this?t=r.$$.smartPtr:g("Cannot convert argument of type "+(r.$$.smartPtrType?r.$$.smartPtrType.name:r.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:t=r.$$.smartPtr;break;case 2:if(r.$$.smartPtrType===this)t=r.$$.smartPtr;else{var i=r.clone();t=this.rawShare(t,$e.toHandle(function(){i.delete()})),e!==null&&e.push(this.rawDestructor,t)}break;default:g("Unsupporting sharing policy")}return t}function ct(e,r){if(r===null)return this.isReference&&g("null is not a valid "+this.name),0;r.$$||g('Cannot pass "'+Be(r)+'" as a '+this.name),r.$$.ptr||g("Cannot pass deleted object as a pointer of type "+this.name),r.$$.ptrType.isConst&&g("Cannot convert argument of type "+r.$$.ptrType.name+" to parameter type "+this.name);var t=r.$$.ptrType.registeredClass,n=pe(r.$$.ptr,t,this.registeredClass);return n}function he(e){return this.fromWireType(W[e>>2])}function dt(e){return this.rawGetPointee&&(e=this.rawGetPointee(e)),e}function gt(e){this.rawDestructor&&this.rawDestructor(e)}function pt(e){e!==null&&e.delete()}function ht(){S.prototype.getPointee=dt,S.prototype.destructor=gt,S.prototype.argPackAdvance=8,S.prototype.readValueFromPointer=he,S.prototype.deleteObject=pt,S.prototype.fromWireType=rt}function S(e,r,t,n,i,s,o,f,a,l,u){this.name=e,this.registeredClass=r,this.isReference=t,this.isConst=n,this.isSmartPointer=i,this.pointeeType=s,this.sharingPolicy=o,this.rawGetPointee=f,this.rawConstructor=a,this.rawShare=l,this.rawDestructor=u,!i&&r.baseClass===void 0?n?(this.toWireType=lt,this.destructorFunction=null):(this.toWireType=ct,this.destructorFunction=null):this.toWireType=ut}function vt(e,r,t){h.hasOwnProperty(e)||ce("Replacing nonexistant public symbol"),h[e].overloadTable!==void 0&&t!==void 0?h[e].overloadTable[t]=r:(h[e]=r,h[e].argCount=t)}function yt(e,r,t){var n=dynCalls[e];return t&&t.length?n.apply(null,[r].concat(t)):n.call(null,r)}var te=[];function Q(e){var r=te[e];return r||(e>=te.length&&(te.length=e+1),te[e]=r=fr.get(e)),r}function mt(e,r,t){if(e.includes("j"))return yt(e,r,t);var n=Q(r).apply(null,t);return n}function wt(e,r){var t=[];return function(){return t.length=0,Object.assign(t,arguments),mt(e,r,t)}}function O(e,r){e=_(e);function t(){return e.includes("j")?wt(e,r):Q(r)}var n=t();return typeof n!="function"&&g("unknown function pointer with signature "+e+": "+r),n}var vr=void 0;function bt(e){var r=_r(e),t=_(r);return F(r),t}function Y(e,r){var t=[],n={};function i(s){if(!n[s]&&!L[s]){if(ue[s]){ue[s].forEach(i);return}t.push(s),n[s]=!0}}throw r.forEach(i),new vr(e+": "+t.map(bt).join([", "]))}function _t(e,r,t,n,i,s,o,f,a,l,u,c,d){u=_(u),s=O(i,s),f&&(f=O(o,f)),l&&(l=O(a,l)),d=O(c,d);var v=We(u);st(v,function(){Y("Cannot construct "+u+" due to unbound types",[n])}),R([e,r,t],n?[n]:[],function(y){y=y[0];var m,b;n?(m=y.registeredClass,b=m.instancePrototype):b=k.prototype;var C=Re(v,function(){if(Object.getPrototypeOf(this)!==U)throw new B("Use 'new' to construct "+u);if(P.constructor_body===void 0)throw new B(u+" has no accessible constructor");var ee=P.constructor_body[arguments.length];if(ee===void 0)throw new B("Tried to invoke ctor of "+u+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(P.constructor_body).toString()+") parameters instead!");return ee.apply(this,arguments)}),U=Object.create(b,{constructor:{value:C}});C.prototype=U;var P=new ft(u,C,U,d,m,s,f,l),be=new S(u,P,!0,!1,!1),Z=new S(u+"*",P,!1,!1,!1),N=new S(u+" const*",P,!1,!0,!1);return pr[e]={pointerType:Z,constPointerType:N},vt(v,C),[be,Z,N]})}function yr(e,r){for(var t=[],n=0;n<e;n++)t.push(T[r+n*4>>2]);return t}function mr(e){for(;e.length;){var r=e.pop(),t=e.pop();t(r)}}function Ct(e,r){if(!(e instanceof Function))throw new TypeError("new_ called with constructor type "+typeof e+" which is not a function");var t=Re(e.name||"unknownFunctionName",function(){});t.prototype=e.prototype;var n=new t,i=e.apply(n,r);return i instanceof Object?i:n}function wr(e,r,t,n,i){var s=r.length;s<2&&g("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var o=r[1]!==null&&t!==null,f=!1,a=1;a<r.length;++a)if(r[a]!==null&&r[a].destructorFunction===void 0){f=!0;break}for(var l=r[0].name!=="void",u="",c="",a=0;a<s-2;++a)u+=(a!==0?", ":"")+"arg"+a,c+=(a!==0?", ":"")+"arg"+a+"Wired";var d="return function "+We(e)+"("+u+`) {
|
|
6
6
|
if (arguments.length !== `+(s-2)+`) {
|
|
7
7
|
throwBindingError('function `+e+" called with ' + arguments.length + ' arguments, expected "+(s-2)+` args!');
|
|
8
8
|
}
|
|
9
|
-
`;
|
|
10
|
-
`);var
|
|
11
|
-
`);for(var a=0;a<s-2;++a)d+="var arg"+a+"Wired = argType"+a+".toWireType("+
|
|
12
|
-
`,
|
|
13
|
-
`,
|
|
14
|
-
`;else for(var a=
|
|
15
|
-
`,
|
|
9
|
+
`;f&&(d+=`var destructors = [];
|
|
10
|
+
`);var v=f?"destructors":"null",y=["throwBindingError","invoker","fn","runDestructors","retType","classParam"],m=[g,n,i,mr,r[0],r[1]];o&&(d+="var thisWired = classParam.toWireType("+v+`, this);
|
|
11
|
+
`);for(var a=0;a<s-2;++a)d+="var arg"+a+"Wired = argType"+a+".toWireType("+v+", arg"+a+"); // "+r[a+2].name+`
|
|
12
|
+
`,y.push("argType"+a),m.push(r[a+2]);if(o&&(c="thisWired"+(c.length>0?", ":"")+c),d+=(l?"var rv = ":"")+"invoker(fn"+(c.length>0?", ":"")+c+`);
|
|
13
|
+
`,f)d+=`runDestructors(destructors);
|
|
14
|
+
`;else for(var a=o?1:2;a<r.length;++a){var b=a===1?"thisWired":"arg"+(a-2)+"Wired";r[a].destructorFunction!==null&&(d+=b+"_dtor("+b+"); // "+r[a].name+`
|
|
15
|
+
`,y.push(b+"_dtor"),m.push(r[a].destructorFunction))}l&&(d+=`var ret = retType.fromWireType(rv);
|
|
16
16
|
return ret;
|
|
17
17
|
`),d+=`}
|
|
18
|
-
`,
|
|
18
|
+
`,y.push(d);var C=Ct(Function,y).apply(null,m);return C}function Tt(e,r,t,n,i,s){assert(r>0);var o=yr(r,t);i=O(n,i),R([],[e],function(f){f=f[0];var a="constructor "+f.name;if(f.registeredClass.constructor_body===void 0&&(f.registeredClass.constructor_body=[]),f.registeredClass.constructor_body[r-1]!==void 0)throw new B("Cannot register multiple constructors with identical number of parameters ("+(r-1)+") for class '"+f.name+"'! Overload resolution is currently only performed using the parameter count, not actual type info!");return f.registeredClass.constructor_body[r-1]=()=>{Y("Cannot construct "+f.name+" due to unbound types",o)},R([],o,function(l){return l.splice(1,0,null),f.registeredClass.constructor_body[r-1]=wr(a,l,null,i,s),[]}),[]})}function Pt(e,r,t,n,i,s,o,f){var a=yr(t,n);r=_(r),s=O(i,s),R([],[e],function(l){l=l[0];var u=l.name+"."+r;r.startsWith("@@")&&(r=Symbol[r.substring(2)]),f&&l.registeredClass.pureVirtualFunctions.push(r);function c(){Y("Cannot call "+u+" due to unbound types",a)}var d=l.registeredClass.instancePrototype,v=d[r];return v===void 0||v.overloadTable===void 0&&v.className!==l.name&&v.argCount===t-2?(c.argCount=t-2,c.className=l.name,d[r]=c):(hr(d,r,u),d[r].overloadTable[t-2]=c),R([],a,function(y){var m=wr(u,y,l,s,o);return d[r].overloadTable===void 0?(m.argCount=t-2,d[r]=m):d[r].overloadTable[t-2]=m,[]}),[]})}function Je(e,r,t){return e instanceof Object||g(t+' with invalid "this": '+e),e instanceof r.registeredClass.constructor||g(t+' incompatible with "this" of type '+e.constructor.name),e.$$.ptr||g("cannot call emscripten binding method "+t+" on deleted object"),pe(e.$$.ptr,e.$$.ptrType.registeredClass,r.registeredClass)}function $t(e,r,t,n,i,s,o,f,a,l){r=_(r),i=O(n,i),R([],[e],function(u){u=u[0];var c=u.name+"."+r,d={get:function(){Y("Cannot access "+c+" due to unbound types",[t,o])},enumerable:!0,configurable:!0};return a?d.set=()=>{Y("Cannot access "+c+" due to unbound types",[t,o])}:d.set=v=>{g(c+" is a read-only property")},Object.defineProperty(u.registeredClass.instancePrototype,r,d),R([],a?[t,o]:[t],function(v){var y=v[0],m={get:function(){var C=Je(this,u,c+" getter");return y.fromWireType(i(s,C))},enumerable:!0};if(a){a=O(f,a);var b=v[1];m.set=function(C){var U=Je(this,u,c+" setter"),P=[];a(l,U,b.toWireType(P,C)),mr(P)}}return Object.defineProperty(u.registeredClass.instancePrototype,r,m),[]}),[]})}var Pe=[],$=[{},{value:void 0},{value:null},{value:!0},{value:!1}];function St(e){e>4&&--$[e].refcount===0&&($[e]=void 0,Pe.push(e))}function Ft(){for(var e=0,r=5;r<$.length;++r)$[r]!==void 0&&++e;return e}function At(){for(var e=5;e<$.length;++e)if($[e]!==void 0)return $[e];return null}function kt(){h.count_emval_handles=Ft,h.get_first_emval=At}var $e={toValue:e=>(e||g("Cannot use deleted val. handle = "+e),$[e].value),toHandle:e=>{switch(e){case void 0:return 1;case null:return 2;case!0:return 3;case!1:return 4;default:{var r=Pe.length?Pe.pop():$.length;return $[r]={refcount:1,value:e},r}}}};function Et(e,r){r=_(r),A(e,{name:r,fromWireType:function(t){var n=$e.toValue(t);return St(t),n},toWireType:function(t,n){return $e.toHandle(n)},argPackAdvance:8,readValueFromPointer:he,destructorFunction:null})}function Be(e){if(e===null)return"null";var r=typeof e;return r==="object"||r==="array"||r==="function"?e.toString():""+e}function Ot(e,r){switch(r){case 2:return function(t){return this.fromWireType(ar[t>>2])};case 3:return function(t){return this.fromWireType(sr[t>>3])};default:throw new TypeError("Unknown float type: "+e)}}function Ut(e,r,t){var n=Me(t);r=_(r),A(e,{name:r,fromWireType:function(i){return i},toWireType:function(i,s){return s},argPackAdvance:8,readValueFromPointer:Ot(r,n),destructorFunction:null})}function Dt(e,r,t){switch(r){case 0:return t?function(i){return De[i]}:function(i){return w[i]};case 1:return t?function(i){return X[i>>1]}:function(i){return ge[i>>1]};case 2:return t?function(i){return W[i>>2]}:function(i){return T[i>>2]};default:throw new TypeError("Unknown integer type: "+e)}}function Mt(e,r,t,n,i){r=_(r);var s=Me(t),o=c=>c;if(n===0){var f=32-8*t;o=c=>c<<f>>>f}var a=r.includes("unsigned"),l=(c,d)=>{},u;a?u=function(c,d){return l(d,this.name),d>>>0}:u=function(c,d){return l(d,this.name),d},A(e,{name:r,fromWireType:o,toWireType:u,argPackAdvance:8,readValueFromPointer:Dt(r,s,n!==0),destructorFunction:null})}function Wt(e,r,t){var n=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],i=n[r];function s(o){o=o>>2;var f=T,a=f[o],l=f[o+1];return new i(K,l,a)}t=_(t),A(e,{name:t,fromWireType:s,argPackAdvance:8,readValueFromPointer:s},{ignoreDuplicateRegistrations:!0})}function Rt(e,r){r=_(r);var t=r==="std::string";A(e,{name:r,fromWireType:function(n){var i=T[n>>2],s=n+4,o;if(t)for(var f=s,a=0;a<=i;++a){var l=s+a;if(a==i||w[l]==0){var u=l-f,c=ne(f,u);o===void 0?o=c:(o+=String.fromCharCode(0),o+=c),f=l+1}}else{for(var d=new Array(i),a=0;a<i;++a)d[a]=String.fromCharCode(w[s+a]);o=d.join("")}return F(n),o},toWireType:function(n,i){i instanceof ArrayBuffer&&(i=new Uint8Array(i));var s,o=typeof i=="string";o||i instanceof Uint8Array||i instanceof Uint8ClampedArray||i instanceof Int8Array||g("Cannot pass non-string to std::string"),t&&o?s=Wr(i):s=i.length;var f=ve(4+s+1),a=f+4;if(T[f>>2]=s,t&&o)Mr(i,a,s+1);else if(o)for(var l=0;l<s;++l){var u=i.charCodeAt(l);u>255&&(F(a),g("String has UTF-16 code units that do not fit in 8 bits")),w[a+l]=u}else for(var l=0;l<s;++l)w[a+l]=i[l];return n!==null&&n.push(F,f),f},argPackAdvance:8,readValueFromPointer:he,destructorFunction:function(n){F(n)}})}var jt=new TextDecoder("utf-16le");function It(e,r){for(var t=e,n=t>>1,i=n+r/2;!(n>=i)&&ge[n];)++n;return t=n<<1,jt.decode(w.subarray(e,t))}function Lt(e,r,t){if(t===void 0&&(t=2147483647),t<2)return 0;t-=2;for(var n=r,i=t<e.length*2?t/2:e.length,s=0;s<i;++s){var o=e.charCodeAt(s);X[r>>1]=o,r+=2}return X[r>>1]=0,r-n}function Bt(e){return e.length*2}function Ht(e,r){for(var t=0,n="";!(t>=r/4);){var i=W[e+t*4>>2];if(i==0)break;if(++t,i>=65536){var s=i-65536;n+=String.fromCharCode(55296|s>>10,56320|s&1023)}else n+=String.fromCharCode(i)}return n}function Vt(e,r,t){if(t===void 0&&(t=2147483647),t<4)return 0;for(var n=r,i=n+t-4,s=0;s<e.length;++s){var o=e.charCodeAt(s);if(o>=55296&&o<=57343){var f=e.charCodeAt(++s);o=65536+((o&1023)<<10)|f&1023}if(W[r>>2]=o,r+=4,r+4>i)break}return W[r>>2]=0,r-n}function xt(e){for(var r=0,t=0;t<e.length;++t){var n=e.charCodeAt(t);n>=55296&&n<=57343&&++t,r+=4}return r}function zt(e,r,t){t=_(t);var n,i,s,o,f;r===2?(n=It,i=Lt,o=Bt,s=()=>ge,f=1):r===4&&(n=Ht,i=Vt,o=xt,s=()=>T,f=2),A(e,{name:t,fromWireType:function(a){for(var l=T[a>>2],u=s(),c,d=a+4,v=0;v<=l;++v){var y=a+4+v*r;if(v==l||u[y>>f]==0){var m=y-d,b=n(d,m);c===void 0?c=b:(c+=String.fromCharCode(0),c+=b),d=y+r}}return F(a),c},toWireType:function(a,l){typeof l!="string"&&g("Cannot pass non-string to C++ string type "+t);var u=o(l),c=ve(4+u+r);return T[c>>2]=u>>f,i(l,c+4,u+r),a!==null&&a.push(F,c),c},argPackAdvance:8,readValueFromPointer:he,destructorFunction:function(a){F(a)}})}function Gt(e,r){r=_(r),A(e,{isVoid:!0,name:r,argPackAdvance:0,fromWireType:function(){},toWireType:function(t,n){}})}function Jt(){throw 1/0}function Xt(){ir("")}var br;br=()=>performance.now();function qt(e,r,t){w.copyWithin(e,r,r+t)}function Yt(){return 2147483648}function Kt(e){try{return fe.grow(e-K.byteLength+65535>>>16),le(fe.buffer),1}catch{}}function Qt(e){var r=w.length;e=e>>>0;var t=Yt();if(e>t)return!1;let n=(a,l)=>a+(l-a%l)%l;for(var i=1;i<=4;i*=2){var s=r*(1+.2/i);s=Math.min(s,e+100663296);var o=Math.min(t,n(Math.max(e,s),65536)),f=Kt(o);if(f)return!0}return!1}function Zt(e){throw"exit("+e+")"}var Nt=Zt;function en(e){return 52}function rn(e,r,t,n){return 52}function tn(e,r,t,n,i){return 70}var nn=[null,[],[]];function on(e,r){var t=nn[e];r===0||r===10?((e===1?qe:Ye)(Ur(t,0)),t.length=0):t.push(r)}function an(e,r,t,n){for(var i=0,s=0;s<t;s++){var o=T[r>>2],f=T[r+4>>2];r+=8;for(var a=0;a<f;a++)on(e,w[o+a]);i+=f}return T[n>>2]=i,0}Vr();B=h.BindingError=je(Error,"BindingError");ur=h.InternalError=je(Error,"InternalError");at();Zr();ht();vr=h.UnboundTypeError=je(Error,"UnboundTypeError");kt();var sn={a:Rr,m:jr,z:Ir,D:Lr,l:Br,t:Hr,p:Gr,j:_t,s:Tt,c:Pt,b:$t,E:Et,n:Ut,f:Mt,d:Wt,o:Rt,k:zt,q:Gt,x:Jt,e:Xt,g:br,A:qt,y:Qt,h:Nt,i:en,C:rn,r:tn,B:an,w:fn,u:un,v:ln};function fn(e,r,t){var n=me();try{return Q(e)(r,t)}catch(i){if(we(n),i!==i+0)throw i;ye(1,0)}}function ln(e,r,t,n,i){var s=me();try{return Q(e)(r,t,n,i)}catch(o){if(we(s),o!==o+0)throw o;ye(1,0)}}function un(e,r,t,n){var i=me();try{return Q(e)(r,t,n)}catch(s){if(we(i),s!==s+0)throw s;ye(1,0)}}function cn(e){e.G()}var Xe={a:sn},ve,F,_r,ye,me,we;(WebAssembly.instantiateStreaming?WebAssembly.instantiateStreaming(fetch("jassub-worker.wasm"),Xe):WebAssembly.instantiate(h.wasm,Xe)).then(function(e){asm=(e.instance||e).exports,ve=asm.H,F=asm.I,_r=asm.J,asm.K,ye=asm.M,asm.N,me=asm.O,we=asm.P,asm.Q,asm.R,asm.S,asm.T,fr=asm.L,fe=asm.F,le(fe.buffer),cn(asm),Ke()});
|
package/dist/jassub-worker.wasm
CHANGED
|
Binary file
|
package/dist/jassub.es.js
CHANGED
|
@@ -1,28 +1,51 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var _ = Object.defineProperty;
|
|
2
|
+
var u = (d, e, t) => e in d ? _(d, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : d[e] = t;
|
|
3
|
+
var f = (d, e, t) => (u(d, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
4
|
!("requestVideoFrameCallback" in HTMLVideoElement.prototype) && "getVideoPlaybackQuality" in HTMLVideoElement.prototype && (HTMLVideoElement.prototype._rvfcpolyfillmap = {}, HTMLVideoElement.prototype.requestVideoFrameCallback = function(d) {
|
|
5
|
-
const e = this.getVideoPlaybackQuality(), t = this.mozPresentedFrames || this.mozPaintedFrames || e.totalVideoFrames - e.droppedVideoFrames, s = (
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
const
|
|
9
|
-
d(
|
|
10
|
-
presentationTime:
|
|
11
|
-
expectedDisplayTime:
|
|
5
|
+
const e = this.getVideoPlaybackQuality(), t = this.mozPresentedFrames || this.mozPaintedFrames || e.totalVideoFrames - e.droppedVideoFrames, s = (n, r) => {
|
|
6
|
+
const a = this.getVideoPlaybackQuality(), h = this.mozPresentedFrames || this.mozPaintedFrames || a.totalVideoFrames - a.droppedVideoFrames;
|
|
7
|
+
if (h > t) {
|
|
8
|
+
const c = this.mozFrameDelay || a.totalFrameDelay - e.totalFrameDelay || 0, m = r - n;
|
|
9
|
+
d(r, {
|
|
10
|
+
presentationTime: r + c * 1e3,
|
|
11
|
+
expectedDisplayTime: r + m,
|
|
12
12
|
width: this.videoWidth,
|
|
13
13
|
height: this.videoHeight,
|
|
14
14
|
mediaTime: Math.max(0, this.currentTime || 0) + m / 1e3,
|
|
15
|
-
presentedFrames:
|
|
16
|
-
processingDuration:
|
|
17
|
-
}), delete this._rvfcpolyfillmap[
|
|
15
|
+
presentedFrames: h,
|
|
16
|
+
processingDuration: c
|
|
17
|
+
}), delete this._rvfcpolyfillmap[i];
|
|
18
18
|
} else
|
|
19
|
-
this._rvfcpolyfillmap[
|
|
20
|
-
},
|
|
21
|
-
return this._rvfcpolyfillmap[
|
|
19
|
+
this._rvfcpolyfillmap[i] = requestAnimationFrame((c) => s(r, c));
|
|
20
|
+
}, i = Date.now(), o = performance.now();
|
|
21
|
+
return this._rvfcpolyfillmap[i] = requestAnimationFrame((n) => s(o, n)), i;
|
|
22
22
|
}, HTMLVideoElement.prototype.cancelVideoFrameCallback = function(d) {
|
|
23
23
|
cancelAnimationFrame(this._rvfcpolyfillmap[d]), delete this._rvfcpolyfillmap[d];
|
|
24
24
|
});
|
|
25
|
-
const
|
|
25
|
+
const g = {
|
|
26
|
+
bt709: "BT.709",
|
|
27
|
+
// these might not be exactly correct? oops?
|
|
28
|
+
bt470bg: "BT.601",
|
|
29
|
+
// alias BT.601 PAL... whats the difference?
|
|
30
|
+
smpte170m: "BT.601"
|
|
31
|
+
// alias BT.601 NTSC... whats the difference?
|
|
32
|
+
}, p = {
|
|
33
|
+
"BT.601": {
|
|
34
|
+
"BT.709": `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='f'><feColorMatrix type='matrix' values='1.0863 -0.0723 -0.014 0 0 0.0965 0.8451 0.0584 0 0 -0.0141 -0.0277 1.0418 0 0 0 0 0 1 0'/></filter></svg>#f")`
|
|
35
|
+
},
|
|
36
|
+
"BT.709": {
|
|
37
|
+
"BT.601": `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='f'><feColorMatrix type='matrix' values='0.9137 0.0784 0.0079 0 0 -0.1049 1.1722 -0.0671 0 0 0.0096 0.0322 0.9582 0 0 0 0 0 1 0'/></filter></svg>#f")`
|
|
38
|
+
},
|
|
39
|
+
FCC: {
|
|
40
|
+
"BT.709": `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='f'><feColorMatrix type='matrix' values='1.0873 -0.0736 -0.0137 0 0 0.0974 0.8494 0.0531 0 0 -0.0127 -0.0251
|
|
41
|
+
1.0378 0 0 0 0 0 1 0'/></filter></svg>#f")`,
|
|
42
|
+
"BT.601": `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='f'><feColorMatrix type='matrix' values='1.001 -0.0008 -0.0002 0 0 0.0009 1.005 -0.006 0 0 0.0013 0.0027 0.996 0 0 0 0 0 1 0'/></filter></svg>#f")`
|
|
43
|
+
},
|
|
44
|
+
SMPTE240M: {
|
|
45
|
+
"BT.709": `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='f'><feColorMatrix type='matrix' values='0.9993 0.0006 0.0001 0 0 -0.0004 0.9812 0.0192 0 0 -0.0034 -0.0114 1.0148 0 0 0 0 0 1 0'/></filter></svg>#f")`,
|
|
46
|
+
"BT.601": `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='f'><feColorMatrix type='matrix' values='0.913 0.0774 0.0096 0 0 -0.1051 1.1508 -0.0456 0 0 0.0063 0.0207 0.973 0 0 0 0 0 1 0'/></filter></svg>#f")`
|
|
47
|
+
}
|
|
48
|
+
}, l = class extends EventTarget {
|
|
26
49
|
/**
|
|
27
50
|
* @param {Object} options Settings object.
|
|
28
51
|
* @param {HTMLVideoElement} options.video Video to use as target for rendering and event listeners. Optional if canvas is specified instead.
|
|
@@ -50,19 +73,16 @@ const h = class extends EventTarget {
|
|
|
50
73
|
* @param {Number} [options.libassGlyphLimit] libass glyph cache memory limit in MiB (approximate).
|
|
51
74
|
*/
|
|
52
75
|
constructor(e = {}) {
|
|
53
|
-
super(), globalThis.Worker || this.destroy("Worker not supported"),
|
|
54
|
-
const t = e.blendMode || "js", s = typeof createImageBitmap < "u" && (e.asyncRender ?? !0), a = typeof OffscreenCanvas < "u" && (e.offscreenRender ?? !0);
|
|
55
|
-
this._onDemandRender = "requestVideoFrameCallback" in HTMLVideoElement.prototype && (e.onDemandRender ?? !0), this.timeOffset = e.timeOffset || 0, this._video = e.video, this._videoHeight = 0, this._videoWidth = 0, this._canvas = e.canvas, this._video && !this._canvas ? (this._canvasParent = document.createElement("div"), this._canvasParent.className = "JASSUB", this._canvasParent.style.position = "relative", this._canvas = document.createElement("canvas"), this._canvas.style.display = "block", this._canvas.style.position = "absolute", this._canvas.style.pointerEvents = "none", this._canvasParent.appendChild(this._canvas), this._video.nextSibling ? this._video.parentNode.insertBefore(this._canvasParent, this._video.nextSibling) : this._video.parentNode.appendChild(this._canvasParent)) : this._canvas || this.destroy("Don't know where to render: you should give video or canvas in options."), this._bufferCanvas = document.createElement("canvas"), this._bufferCtx = this._bufferCanvas.getContext("2d", { desynchronized: !0, willReadFrequently: !0 }), this._canvasctrl = a ? this._canvas.transferControlToOffscreen() : this._canvas, this._ctx = !a && this._canvasctrl.getContext("2d", { desynchronized: !0 }), this._lastRenderTime = 0, this.debug = !!e.debug, this.prescaleFactor = e.prescaleFactor || 1, this.prescaleHeightLimit = e.prescaleHeightLimit || 1080, this.maxRenderHeight = e.maxRenderHeight || 0, this._worker = new Worker(h._supportsWebAssembly ? e.workerUrl || "jassub-worker.js" : e.legacyWorkerUrl || "jassub-worker-legacy.js"), this._worker.onmessage = (n) => this._onmessage(n), this._worker.onerror = (n) => this._error(n), this._loaded = new Promise((n) => {
|
|
76
|
+
super(), globalThis.Worker || this.destroy("Worker not supported"), l._test(), this._onDemandRender = "requestVideoFrameCallback" in HTMLVideoElement.prototype && (e.onDemandRender ?? !0), this.timeOffset = e.timeOffset || 0, this._video = e.video, this._videoHeight = 0, this._videoWidth = 0, this._videoColorSpace = null, this._canvas = e.canvas, this._video && !this._canvas ? (this._canvasParent = document.createElement("div"), this._canvasParent.className = "JASSUB", this._canvasParent.style.position = "relative", this._canvas = document.createElement("canvas"), this._canvas.style.display = "block", this._canvas.style.position = "absolute", this._canvas.style.pointerEvents = "none", this._canvasParent.appendChild(this._canvas), this._video.nextSibling ? this._video.parentNode.insertBefore(this._canvasParent, this._video.nextSibling) : this._video.parentNode.appendChild(this._canvasParent)) : this._canvas || this.destroy("Don't know where to render: you should give video or canvas in options."), this._bufferCanvas = document.createElement("canvas"), this._bufferCtx = this._bufferCanvas.getContext("2d", { desynchronized: !0, willReadFrequently: !0 }), this._canvasctrl = this._canvas, this._ctx = this._canvasctrl.getContext("2d", { desynchronized: !0 }), this._lastRenderTime = 0, this.debug = !!e.debug, this.prescaleFactor = e.prescaleFactor || 1, this.prescaleHeightLimit = e.prescaleHeightLimit || 1080, this.maxRenderHeight = e.maxRenderHeight || 0, this._worker = new Worker(l._supportsWebAssembly ? e.workerUrl || "jassub-worker.js" : e.legacyWorkerUrl || "jassub-worker-legacy.js"), this._worker.onmessage = (t) => this._onmessage(t), this._worker.onerror = (t) => this._error(t), this._loaded = new Promise((t) => {
|
|
56
77
|
this._init = () => {
|
|
57
|
-
var r;
|
|
58
78
|
this._destroyed || (this._worker.postMessage({
|
|
59
79
|
target: "init",
|
|
60
|
-
asyncRender:
|
|
80
|
+
asyncRender: typeof createImageBitmap < "u" && (e.asyncRender ?? !0),
|
|
61
81
|
onDemandRender: this._onDemandRender,
|
|
62
|
-
width: this._canvasctrl.width,
|
|
63
|
-
height: this._canvasctrl.height,
|
|
82
|
+
width: this._canvasctrl.width || 0,
|
|
83
|
+
height: this._canvasctrl.height || 0,
|
|
64
84
|
preMain: !0,
|
|
65
|
-
blendMode:
|
|
85
|
+
blendMode: e.blendMode || "js",
|
|
66
86
|
subUrl: e.subUrl,
|
|
67
87
|
subContent: e.subContent || null,
|
|
68
88
|
fonts: e.fonts || [],
|
|
@@ -73,39 +93,40 @@ const h = class extends EventTarget {
|
|
|
73
93
|
dropAllAnimations: e.dropAllAnimations,
|
|
74
94
|
libassMemoryLimit: e.libassMemoryLimit || 0,
|
|
75
95
|
libassGlyphLimit: e.libassGlyphLimit || 0,
|
|
76
|
-
hasAlphaBug:
|
|
96
|
+
hasAlphaBug: l._hasAlphaBug,
|
|
97
|
+
offscreenRender: typeof OffscreenCanvas < "u" && (e.offscreenRender ?? !0),
|
|
77
98
|
useLocalFonts: "queryLocalFonts" in self && (e.useLocalFonts ?? !0)
|
|
78
|
-
}),
|
|
99
|
+
}), this._boundResize = this.resize.bind(this), this._boundTimeUpdate = this._timeupdate.bind(this), this._boundSetRate = this.setRate.bind(this), this._boundUpdateColorSpace = this._updateColorSpace.bind(this), this._video && this.setVideo(e.video), this._onDemandRender && (this.busy = !1, this._lastDemandTime = null), t());
|
|
79
100
|
};
|
|
80
101
|
});
|
|
81
102
|
}
|
|
82
103
|
static _test() {
|
|
83
|
-
if (
|
|
104
|
+
if (l._supportsWebAssembly !== null)
|
|
84
105
|
return null;
|
|
85
106
|
const e = document.createElement("canvas"), t = e.getContext("2d", { willReadFrequently: !0 });
|
|
86
107
|
if (typeof ImageData.prototype.constructor == "function")
|
|
87
108
|
try {
|
|
88
109
|
new ImageData(new Uint8ClampedArray([0, 0, 0, 0]), 1, 1);
|
|
89
110
|
} catch {
|
|
90
|
-
console.log("Detected that ImageData is not constructable despite browser saying so"), self.ImageData = function(
|
|
91
|
-
const m = t.createImageData(
|
|
92
|
-
return
|
|
111
|
+
console.log("Detected that ImageData is not constructable despite browser saying so"), self.ImageData = function(a, h, c) {
|
|
112
|
+
const m = t.createImageData(h, c);
|
|
113
|
+
return a && m.data.set(a), m;
|
|
93
114
|
};
|
|
94
115
|
}
|
|
95
116
|
try {
|
|
96
117
|
if (typeof WebAssembly == "object" && typeof WebAssembly.instantiate == "function") {
|
|
97
|
-
const
|
|
98
|
-
|
|
118
|
+
const r = new WebAssembly.Module(Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0));
|
|
119
|
+
r instanceof WebAssembly.Module && (l._supportsWebAssembly = new WebAssembly.Instance(r) instanceof WebAssembly.Instance);
|
|
99
120
|
}
|
|
100
121
|
} catch {
|
|
101
|
-
|
|
122
|
+
l._supportsWebAssembly = !1;
|
|
102
123
|
}
|
|
103
|
-
const s = document.createElement("canvas"),
|
|
104
|
-
e.width = s.width = 1, e.height = s.height = 1, t.clearRect(0, 0, 1, 1),
|
|
105
|
-
const
|
|
106
|
-
t.putImageData(new ImageData(new Uint8ClampedArray([0, 255, 0, 0]), 1, 1), 0, 0),
|
|
107
|
-
const
|
|
108
|
-
|
|
124
|
+
const s = document.createElement("canvas"), i = s.getContext("2d", { willReadFrequently: !0 });
|
|
125
|
+
e.width = s.width = 1, e.height = s.height = 1, t.clearRect(0, 0, 1, 1), i.clearRect(0, 0, 1, 1);
|
|
126
|
+
const o = i.getImageData(0, 0, 1, 1).data;
|
|
127
|
+
t.putImageData(new ImageData(new Uint8ClampedArray([0, 255, 0, 0]), 1, 1), 0, 0), i.drawImage(e, 0, 0);
|
|
128
|
+
const n = i.getImageData(0, 0, 1, 1).data;
|
|
129
|
+
l._hasAlphaBug = o[1] !== n[1], l._hasAlphaBug && console.log("Detected a browser having issue with transparent pixels, applying workaround"), e.remove(), s.remove();
|
|
109
130
|
}
|
|
110
131
|
/**
|
|
111
132
|
* Resize the canvas to given parameters. Auto-generated if values are ommited.
|
|
@@ -115,33 +136,33 @@ const h = class extends EventTarget {
|
|
|
115
136
|
* @param {Number} [left=0]
|
|
116
137
|
* @param {Boolean} [force=false]
|
|
117
138
|
*/
|
|
118
|
-
resize(e = 0, t = 0, s = 0,
|
|
139
|
+
resize(e = 0, t = 0, s = 0, i = 0, o = ((n) => (n = this._video) == null ? void 0 : n.paused)()) {
|
|
119
140
|
if ((!e || !t) && this._video) {
|
|
120
|
-
const
|
|
121
|
-
let
|
|
141
|
+
const r = this._getVideoPosition();
|
|
142
|
+
let a = null;
|
|
122
143
|
if (this._videoWidth) {
|
|
123
|
-
const
|
|
124
|
-
|
|
144
|
+
const h = this._video.videoWidth / this._videoWidth, c = this._video.videoHeight / this._videoHeight;
|
|
145
|
+
a = this._computeCanvasSize((r.width || 0) / h, (r.height || 0) / c);
|
|
125
146
|
} else
|
|
126
|
-
|
|
127
|
-
e =
|
|
147
|
+
a = this._computeCanvasSize(r.width || 0, r.height || 0);
|
|
148
|
+
e = a.width, t = a.height, this._canvasParent && (s = r.y - (this._canvasParent.getBoundingClientRect().top - this._video.getBoundingClientRect().top), i = r.x), this._canvas.style.width = r.width + "px", this._canvas.style.height = r.height + "px";
|
|
128
149
|
}
|
|
129
|
-
this._canvas.style.top = s + "px", this._canvas.style.left =
|
|
150
|
+
this._canvas.style.top = s + "px", this._canvas.style.left = i + "px", this.sendMessage("canvas", { width: e, height: t, force: o && this.busy === !1 });
|
|
130
151
|
}
|
|
131
152
|
_getVideoPosition(e = this._video.videoWidth, t = this._video.videoHeight) {
|
|
132
|
-
const s = e / t, { offsetWidth:
|
|
133
|
-
e =
|
|
134
|
-
const
|
|
135
|
-
return { width: e, height: t, x:
|
|
153
|
+
const s = e / t, { offsetWidth: i, offsetHeight: o } = this._video, n = i / o;
|
|
154
|
+
e = i, t = o, n > s ? e = Math.floor(o * s) : t = Math.floor(i / s);
|
|
155
|
+
const r = (i - e) / 2, a = (o - t) / 2;
|
|
156
|
+
return { width: e, height: t, x: r, y: a };
|
|
136
157
|
}
|
|
137
158
|
_computeCanvasSize(e = 0, t = 0) {
|
|
138
|
-
const s = this.prescaleFactor <= 0 ? 1 : this.prescaleFactor,
|
|
139
|
-
if (e = e *
|
|
159
|
+
const s = this.prescaleFactor <= 0 ? 1 : this.prescaleFactor, i = self.devicePixelRatio || 1;
|
|
160
|
+
if (e = e * i, t = t * i, t <= 0 || e <= 0)
|
|
140
161
|
e = 0, t = 0;
|
|
141
162
|
else {
|
|
142
|
-
const
|
|
143
|
-
let
|
|
144
|
-
|
|
163
|
+
const o = s < 1 ? -1 : 1;
|
|
164
|
+
let n = t * i;
|
|
165
|
+
o * n * s <= o * this.prescaleHeightLimit ? n *= s : o * n < o * this.prescaleHeightLimit && (n = this.prescaleHeightLimit), this.maxRenderHeight > 0 && n > this.maxRenderHeight && (n = this.maxRenderHeight), e *= n / t, t = n;
|
|
145
166
|
}
|
|
146
167
|
return { width: e, height: t };
|
|
147
168
|
}
|
|
@@ -153,12 +174,18 @@ const h = class extends EventTarget {
|
|
|
153
174
|
}[e];
|
|
154
175
|
s != null && (this._playstate = s), this.setCurrentTime(this._video.paused || this._playstate, this._video.currentTime + this.timeOffset);
|
|
155
176
|
}
|
|
177
|
+
_updateColorSpace() {
|
|
178
|
+
this._video.requestVideoFrameCallback(() => {
|
|
179
|
+
const e = new VideoFrame(this._video);
|
|
180
|
+
this._videoColorSpace = g[e.colorSpace.matrix], e.close();
|
|
181
|
+
});
|
|
182
|
+
}
|
|
156
183
|
/**
|
|
157
184
|
* Change the video to use as target for event listeners.
|
|
158
185
|
* @param {HTMLVideoElement} video
|
|
159
186
|
*/
|
|
160
187
|
setVideo(e) {
|
|
161
|
-
e instanceof HTMLVideoElement ? (this._removeListeners(), this._video = e, this._onDemandRender ? this._video.requestVideoFrameCallback(this._handleRVFC.bind(this)) : (this._playstate = e.paused, e.addEventListener("timeupdate", this._boundTimeUpdate, !1), e.addEventListener("progress", this._boundTimeUpdate, !1), e.addEventListener("waiting", this._boundTimeUpdate, !1), e.addEventListener("seeking", this._boundTimeUpdate, !1), e.addEventListener("playing", this._boundTimeUpdate, !1), e.addEventListener("ratechange", this._boundSetRate, !1), e.addEventListener("resize", this._boundResize)), e.videoWidth > 0 && this.resize(), typeof ResizeObserver < "u" && (this._ro || (this._ro = new ResizeObserver(() => this.resize())), this._ro.observe(e))) : this._error("Video element invalid!");
|
|
188
|
+
e instanceof HTMLVideoElement ? (this._removeListeners(), this._video = e, this._onDemandRender ? this._video.requestVideoFrameCallback(this._handleRVFC.bind(this)) : (this._playstate = e.paused, e.addEventListener("timeupdate", this._boundTimeUpdate, !1), e.addEventListener("progress", this._boundTimeUpdate, !1), e.addEventListener("waiting", this._boundTimeUpdate, !1), e.addEventListener("seeking", this._boundTimeUpdate, !1), e.addEventListener("playing", this._boundTimeUpdate, !1), e.addEventListener("ratechange", this._boundSetRate, !1), e.addEventListener("resize", this._boundResize, !1)), "VideoFrame" in window && (e.addEventListener("loadedmetadata", this._boundUpdateColorSpace, !1), e.readyState > 2 && this._updateColorSpace()), e.videoWidth > 0 && this.resize(), typeof ResizeObserver < "u" && (this._ro || (this._ro = new ResizeObserver(() => this.resize())), this._ro.observe(e))) : this._error("Video element invalid!");
|
|
162
189
|
}
|
|
163
190
|
runBenchmark() {
|
|
164
191
|
this.sendMessage("runBenchmark");
|
|
@@ -326,10 +353,10 @@ const h = class extends EventTarget {
|
|
|
326
353
|
_sendLocalFont(e) {
|
|
327
354
|
try {
|
|
328
355
|
queryLocalFonts().then((t) => {
|
|
329
|
-
const s = t == null ? void 0 : t.find((
|
|
330
|
-
s && s.blob().then((
|
|
331
|
-
|
|
332
|
-
this.addFont(new Uint8Array(
|
|
356
|
+
const s = t == null ? void 0 : t.find((i) => i.fullName.toLowerCase() === e);
|
|
357
|
+
s && s.blob().then((i) => {
|
|
358
|
+
i.arrayBuffer().then((o) => {
|
|
359
|
+
this.addFont(new Uint8Array(o));
|
|
333
360
|
});
|
|
334
361
|
});
|
|
335
362
|
});
|
|
@@ -350,30 +377,38 @@ const h = class extends EventTarget {
|
|
|
350
377
|
_unbusy() {
|
|
351
378
|
this._lastDemandTime ? this._demandRender(this._lastDemandTime) : this.busy = !1;
|
|
352
379
|
}
|
|
353
|
-
_handleRVFC(e, { mediaTime: t, width: s, height:
|
|
380
|
+
_handleRVFC(e, { mediaTime: t, width: s, height: i }) {
|
|
354
381
|
if (this._destroyed)
|
|
355
382
|
return null;
|
|
356
|
-
this.busy ? this._lastDemandTime = { mediaTime: t, width: s, height:
|
|
383
|
+
this.busy ? this._lastDemandTime = { mediaTime: t, width: s, height: i } : (this.busy = !0, this._demandRender({ mediaTime: t, width: s, height: i })), this._video.requestVideoFrameCallback(this._handleRVFC.bind(this));
|
|
357
384
|
}
|
|
358
385
|
_demandRender({ mediaTime: e, width: t, height: s }) {
|
|
359
386
|
this._lastDemandTime = null, (t !== this._videoWidth || s !== this._videoHeight) && (this._videoWidth = t, this._videoHeight = s, this.resize()), this.sendMessage("demand", { time: e + this.timeOffset });
|
|
360
387
|
}
|
|
361
|
-
|
|
388
|
+
/**
|
|
389
|
+
* Veryify the color spaces for subtitles and videos, then apply filters to correct the color of subtitles.
|
|
390
|
+
* @param {String} subtitleColorSpace Subtitle color space. One of: BT.601 BT.709 SMPTE240M FCC
|
|
391
|
+
* @param {String} videoColorSpace Video color space. One of: BT.601 BT.709
|
|
392
|
+
*/
|
|
393
|
+
verifyColorSpace(e, t = this._videoColorSpace) {
|
|
394
|
+
!e || !t || e !== t && (this._ctx.filter = p[e][t]);
|
|
395
|
+
}
|
|
396
|
+
_render({ images: e, async: t, times: s, width: i, height: o, colorSpace: n }) {
|
|
362
397
|
this._unbusy();
|
|
363
398
|
const r = Date.now();
|
|
364
|
-
(this._canvasctrl.width !==
|
|
365
|
-
for (const
|
|
366
|
-
|
|
399
|
+
(this._canvasctrl.width !== i || this._canvasctrl.height !== o) && (this._canvasctrl.width = i, this._canvasctrl.height = o, this.verifyColorSpace(n)), this._ctx.clearRect(0, 0, this._canvasctrl.width, this._canvasctrl.height);
|
|
400
|
+
for (const a of e)
|
|
401
|
+
a.image && (t ? (this._ctx.drawImage(a.image, a.x, a.y), a.image.close()) : (this._bufferCanvas.width = a.w, this._bufferCanvas.height = a.h, this._bufferCtx.putImageData(new ImageData(this._fixAlpha(new Uint8ClampedArray(a.image)), a.w, a.h), 0, 0), this._ctx.drawImage(this._bufferCanvas, a.x, a.y)));
|
|
367
402
|
if (this.debug) {
|
|
368
403
|
s.drawTime = Date.now() - r;
|
|
369
|
-
let
|
|
370
|
-
for (const
|
|
371
|
-
|
|
372
|
-
console.log("Bitmaps: " + e.length + " Total: " + Math.round(
|
|
404
|
+
let a = 0;
|
|
405
|
+
for (const h in s)
|
|
406
|
+
a += s[h];
|
|
407
|
+
console.log("Bitmaps: " + e.length + " Total: " + Math.round(a) + "ms", s);
|
|
373
408
|
}
|
|
374
409
|
}
|
|
375
410
|
_fixAlpha(e) {
|
|
376
|
-
if (
|
|
411
|
+
if (l._hasAlphaBug)
|
|
377
412
|
for (let t = 3; t < e.length; t += 4)
|
|
378
413
|
e[t] = e[t] > 1 ? e[t] : 1;
|
|
379
414
|
return e;
|
|
@@ -399,14 +434,14 @@ const h = class extends EventTarget {
|
|
|
399
434
|
}
|
|
400
435
|
_fetchFromWorker(e, t) {
|
|
401
436
|
try {
|
|
402
|
-
const s = e.target,
|
|
403
|
-
|
|
404
|
-
}, 5e3),
|
|
405
|
-
|
|
406
|
-
},
|
|
407
|
-
t(
|
|
437
|
+
const s = e.target, i = setTimeout(() => {
|
|
438
|
+
n(new Error("Error: Timeout while try to fetch " + s));
|
|
439
|
+
}, 5e3), o = ({ data: r }) => {
|
|
440
|
+
r.target === s && (t(null, r), this._worker.removeEventListener("message", o), this._worker.removeEventListener("error", n), clearTimeout(i));
|
|
441
|
+
}, n = (r) => {
|
|
442
|
+
t(r), this._worker.removeEventListener("message", o), this._worker.removeEventListener("error", n), clearTimeout(i);
|
|
408
443
|
};
|
|
409
|
-
this._worker.addEventListener("message",
|
|
444
|
+
this._worker.addEventListener("message", o), this._worker.addEventListener("error", n), this._worker.postMessage(e);
|
|
410
445
|
} catch (s) {
|
|
411
446
|
this._error(s);
|
|
412
447
|
}
|
|
@@ -422,7 +457,7 @@ const h = class extends EventTarget {
|
|
|
422
457
|
this.dispatchEvent(s), console.error(t);
|
|
423
458
|
}
|
|
424
459
|
_removeListeners() {
|
|
425
|
-
this._video && (this._ro && this._ro.unobserve(this._video), this._video.removeEventListener("timeupdate", this._boundTimeUpdate), this._video.removeEventListener("progress", this._boundTimeUpdate), this._video.removeEventListener("waiting", this._boundTimeUpdate), this._video.removeEventListener("seeking", this._boundTimeUpdate), this._video.removeEventListener("playing", this._boundTimeUpdate), this._video.removeEventListener("ratechange", this._boundSetRate), this._video.removeEventListener("resize", this._boundResize));
|
|
460
|
+
this._video && (this._ro && this._ro.unobserve(this._video), this._ctx.filter = "none", this._video.removeEventListener("timeupdate", this._boundTimeUpdate), this._video.removeEventListener("progress", this._boundTimeUpdate), this._video.removeEventListener("waiting", this._boundTimeUpdate), this._video.removeEventListener("seeking", this._boundTimeUpdate), this._video.removeEventListener("playing", this._boundTimeUpdate), this._video.removeEventListener("ratechange", this._boundSetRate), this._video.removeEventListener("resize", this._boundResize), this._video.removeEventListener("loadedmetadata", this._boundUpdateColorSpace));
|
|
426
461
|
}
|
|
427
462
|
/**
|
|
428
463
|
* Destroy the object, worker, listeners and all data.
|
|
@@ -432,9 +467,9 @@ const h = class extends EventTarget {
|
|
|
432
467
|
e && this._error(e), this._video && this._canvasParent && this._video.parentNode.removeChild(this._canvasParent), this._destroyed = !0, this._removeListeners(), this.sendMessage("destroy"), this._worker.terminate();
|
|
433
468
|
}
|
|
434
469
|
};
|
|
435
|
-
let
|
|
470
|
+
let v = l;
|
|
436
471
|
// test support for WASM, ImageData, alphaBug, but only once, on init so it doesn't run when first running the page
|
|
437
|
-
v
|
|
472
|
+
f(v, "_supportsWebAssembly", null), f(v, "_hasAlphaBug", null);
|
|
438
473
|
export {
|
|
439
|
-
|
|
474
|
+
v as default
|
|
440
475
|
};
|