jassub 1.5.6 → 1.5.8

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.
@@ -1,18 +1,15 @@
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("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==="libass: 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(),ee=24,Ge=!1,Je="js",re={};const Le={};let wr=0,Xe;self.width=0;self.height=0;let E=!1;self.addFont=({font:e})=>$e(e);const we=e=>{if(e=e.trim().toLowerCase(),e.startsWith("@")&&(e=e.substring(1)),!Le[e]){if(Le[e]=!0,!re[e]&&Ge)return postMessage({target:"getLocalFont",font:e});$e(re[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(!re)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 te?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(ne):(ne(),setTimeout(()=>{Re=!1},20)))};let te=!0;const Ye=e=>{e!==te&&(te=e,e?j&&(clearTimeout(j),j=null):(Pe=Date.now(),j=Fe(ne)))},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.subarray(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=ue.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 ne=e=>{j=0,Ae(Cr(),e),te||(j=Fe(ne))},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/ee;else for(;t+2>=e;)e+=1e3/ee;const n=Math.max(e-t,0);return setTimeout(r,n)}})(),fe=(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!")),re=e.availableFonts,Xe=e.debug,ee=e.targetFps||ee,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})=>{fe(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})=>{fe(e,self.jassubObj.getEvent(r))};self.removeEvent=({index:e})=>{self.jassubObj.removeEvent(e)};self.createStyle=({style:e})=>{fe(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:q,MarginR:Y,MarginV:K,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:q,MarginR:Y,MarginV:K,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})=>{fe(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;se=(e=>r=>{e(r),Se=new Uint8ClampedArray(r)})(se);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 N(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,le,C,Ze,Ne,ie,ue,er;function se(e){ue=e,je=new Int8Array(e),z=new Int16Array(e),U=new Int32Array(e),m=new Uint8Array(e),le=new Uint16Array(e),C=new Uint32Array(e),Ze=new Float32Array(e),Ne=new Float64Array(e)}function jr(e,r,t,n){Ke("Assertion failed: "+N(e)+", at: "+[r?N(r):"unknown filename",t,n?N(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={},ae={},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+`() {
2
- "use strict"; return body.apply(this, arguments);
3
- };
4
- `)(r)}function Ue(e,r){var t=Ee(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 L=void 0;function g(e){throw new L(e)}var tr=void 0;function oe(e){throw new tr(e)}function D(e,r,t){e.forEach(function(o){ae[o]=r});function n(o){var a=t(o);a.length!==e.length&&oe("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 ae[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 Q(e,r){(!r.ptrType||!r.ptr)&&oe("makeClassHandle requires ptr and ptrType");var t=!!r.smartPtrType,n=!!r.smartPtr;return t!==n&&oe("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?Q(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:r,smartPtrType:this,smartPtr:e}):Q(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?Q(o.registeredClass.instancePrototype,{ptrType:o,ptr:a,smartPtrType:this,smartPtr:e}):Q(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)||oe("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 Z=[];function X(e){var r=Z[e];return r||(e>=Z.length&&(Z.length=e+1),Z[e]=r=er.get(e)),r}function ct(e,r,t){if(e.includes("j"))return ut(e,r,t);var n=X(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):X(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(ae[s]){ae[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 K=T.constructor_body[arguments.length];if(K===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 K.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),q=new $(u+"*",T,!1,!1,!1),Y=new $(u+" const*",T,!1,!0,!1);return ar[e]={pointerType:q,constPointerType:Y},lt(h,_),[ye,q,Y]})}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+`) {
6
- if (arguments.length !== `+(s-2)+`) {
7
- throwBindingError('function `+e+" called with ' + arguments.length + ' arguments, expected "+(s-2)+` args!');
1
+ var h=h,Ve=e=>console.log(e),Be=e=>console.error(e);function xe(){}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("overridden console")}const Ce=(e,r)=>{const t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType=r?"arraybuffer":"text",t.send(null),t.response},yr=(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&&Ce("jassub-worker.wasm",!0)};xe=()=>postMessage({target:"ready"});Ve=e=>{e==="JASSUB: No usable fontconfig configuration file found, using fallback."?console.debug(e):console.log(e)};Be=e=>{e==="Fontconfig error: Cannot load default config file: No such file: (null)"?console.debug(e):console.error(e)};let z=0;const mr=1;let O=null,We=!1,Te=Date.now(),re=24,ze=!1,Je="js",te={};const Re={};let br=0,Ge;self.width=0;self.height=0;let E=!1;self.addFont=({font:e})=>Pe(e);const be=e=>{if(e=e.trim().toLowerCase(),e.startsWith("@")&&(e=e.substring(1)),!Re[e]){if(Re[e]=!0,!te[e]&&ze)return postMessage({target:"getLocalFont",font:e});Pe(te[e])}},Pe=e=>{ArrayBuffer.isView(e)?Ie(e):yr(e,r=>{Ie(new Uint8Array(r))},console.error)},Ie=e=>{const r=de(e.byteLength);b.set(e,r),self.jassubObj.addFont("font-"+br++,r,e.byteLength),self.jassubObj.reloadFonts()},Xe=e=>{if(!te)return;const r=Tr(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"&&be(r[i].body[s].value.Fontname);const t=/\\fn([^\\}]*?)[\\}]/g;let n;for(;(n=t.exec(e))!==null;)be(n[1])};self.setTrack=({content:e})=>{Xe(e),self.jassubObj.createTrackMem(e)};self.freeTrack=()=>{self.jassubObj.removeTrack()};self.setTrackByUrl=({url:e})=>{self.setTrack({content:Ce(e)})};const wr=(e,r)=>{self.width=e,self.height=r,self.jassubObj.resizeCanvas(e,r)},_r=()=>{const e=(Date.now()-Te)/1e3;return ne?z:(e>5&&(console.error("Didn't received currentTime > 5 seconds. Assuming video was paused."),qe(!0)),z+e*mr)},Cr=e=>{z=e,Te=Date.now(),O||(We?O=Ae(ie):(ie(),setTimeout(()=>{We=!1},20)))};let ne=!0;const qe=e=>{e!==ne&&(ne=e,e?O&&(clearTimeout(O),O=null):(Te=Date.now(),O=Ae(ie)))},$e=(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 a=performance.now();if(!n)return ye({images:s,buffers:f,times:i,decodeStartTime:a});if(E){const l=[];for(let o=n,u=0;u<self.jassubObj.count;o=o.next,++u)s.push({w:o.w,h:o.h,x:o.x,y:o.y}),l.push(createImageBitmap(new ImageData(Fe.subarray(o.image,o.image+o.w*o.h*4),o.w,o.h)));Promise.all(l).then(o=>{for(let u=0;u<s.length;u++)s[u].image=o[u];f=o,ye({images:s,buffers:f,times:i,decodeStartTime:a})})}else{for(let l=n,o=0;o<self.jassubObj.count;l=l.next,++o){const u={w:l.w,h:l.h,x:l.x,y:l.y,image:l.image};if(!M){const c=L.buffer.slice(l.image,l.image+l.w*l.h*4);f.push(c),u.image=c}s.push(u)}ye({images:s,buffers:f,times:i,decodeStartTime:a})}}else postMessage({target:"unbusy"})};self.demand=({time:e})=>{z=e,$e(e)};const ie=e=>{O=0,$e(_r(),e),ne||(O=Ae(ie))},ye=({times:e,images:r,decodeStartTime:t,buffers:n})=>{if(e.decodeTime=performance.now()-t,M){const i=performance.now();H.width=self.width,H.height!==self.height&&(H.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(Fe.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(Ge){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)},Tr=e=>{let r,t,n,i,s,f,a,l,o,u;const c=[],d=e.split(/[\r\n]+/g);for(l=0;l<d.length;l++)if(r=d[l].match(/^\[(.*)\]$/),r)t=null,c.push({name:r[1],body:[]});else{if(/^\s*$/.test(d[l])||c.length===0)continue;if(u=c[c.length-1].body,d[l][0]===";")u.push({type:"comment",value:d[l].substring(1)});else{if(i=d[l].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(p=>p.trim()),t)){for(a={},o=0;o<f.length;o++)a[t[o]]=f[o];f=a}s==="Format"&&(t=f),u.push({key:s,value:f})}}return c},Ae=(()=>{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)}})(),fe=(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,Ge=e.debug,re=e.targetFps||re,ze=e.useLocalFonts;const r=e.fallbackFont.toLowerCase();self.jassubObj=new h.JASSUB(self.width,self.height,r||null),r&&be(r);let t=e.subContent;t||(t=Ce(e.subUrl)),Xe(t);for(const n of e.fonts||[])Pe(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");wr(e,r),t&&$e(z)};self.video=({currentTime:e,isPaused:r,rate:t})=>{e!=null&&Cr(e),r!=null&&qe(r),t=t||t};let H,M;self.offscreenCanvas=({transferable:e})=>{H=e[0],M=H.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})=>{fe(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:a,MarginR:l,MarginV:o,Name:u,Text:c,Effect:d}=self.jassubObj.getEvent(r);e.push({Start:t,Duration:n,ReadOrder:i,Layer:s,Style:f,MarginL:a,MarginR:l,MarginV:o,Name:u,Text:c,Effect:d})}postMessage({target:"getEvents",events:e})};self.setEvent=({event:e,index:r})=>{fe(e,self.jassubObj.getEvent(r))};self.removeEvent=({index:e})=>{self.jassubObj.removeEvent(e)};self.createStyle=({style:e})=>{fe(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:a,BackColour:l,Bold:o,Italic:u,Underline:c,StrikeOut:d,ScaleX:p,ScaleY:v,Spacing:m,Angle:y,BorderStyle:w,Outline:$,Shadow:T,Alignment:ve,MarginL:Y,MarginR:K,MarginV:Q,Encoding:gr,treat_fontname_as_pattern:pr,Blur:hr,Justify:vr}=self.jassubObj.getStyle(r);e.push({Name:t,FontName:n,FontSize:i,PrimaryColour:s,SecondaryColour:f,OutlineColour:a,BackColour:l,Bold:o,Italic:u,Underline:c,StrikeOut:d,ScaleX:p,ScaleY:v,Spacing:m,Angle:y,BorderStyle:w,Outline:$,Shadow:T,Alignment:ve,MarginL:Y,MarginR:K,MarginV:Q,Encoding:gr,treat_fontname_as_pattern:pr,Blur:hr,Justify:vr})}postMessage({target:"getStyles",time:Date.now(),styles:e})};self.setStyle=({style:e,index:r})=>{fe(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 Fe=null;se=(e=>()=>{e(),Fe=new Uint8ClampedArray(L.buffer)})(se);function Ye(e){throw e}var Ke=new TextDecoder("utf8");function Pr(e,r,t){for(var n=r+t,i=r;e[i]&&!(i>=n);)++i;return Ke.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)&&b[n];)++n;return Ke.decode(b.subarray(e,n))}function $r(e,r,t,n){if(!(n>0))return 0;for(var i=t,s=t+n-1,f=0;f<e.length;++f){var a=e.charCodeAt(f);if(a>=55296&&a<=57343){var l=e.charCodeAt(++f);a=65536+((a&1023)<<10)|l&1023}if(a<=127){if(t>=s)break;r[t++]=a}else if(a<=2047){if(t+1>=s)break;r[t++]=192|a>>6,r[t++]=128|a&63}else if(a<=65535){if(t+2>=s)break;r[t++]=224|a>>12,r[t++]=128|a>>6&63,r[t++]=128|a&63}else{if(t+3>=s)break;r[t++]=240|a>>18,r[t++]=128|a>>12&63,r[t++]=128|a>>6&63,r[t++]=128|a&63}}return r[t]=0,t-i}function Ar(e,r,t){return $r(e,b,r,t)}function Fr(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 Se,J,U,b,le,C,Qe,Ze,L,Ne;function se(){var e=L.buffer;Se=new Int8Array(e),J=new Int16Array(e),U=new Int32Array(e),b=new Uint8Array(e),le=new Uint16Array(e),C=new Uint32Array(e),Qe=new Float32Array(e),Ze=new Float64Array(e)}function Sr(e,r,t,n){Ye("Assertion failed: "+ee(e)+", at: "+[r?ee(r):"unknown filename",t,n?ee(n):"unknown function"])}function jr(e,r,t){return 0}function Or(e,r,t){}function kr(e,r,t){return 0}function Er(e,r,t,n){}function Ur(e,r,t,n,i){}function je(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 Dr(){for(var e=new Array(256),r=0;r<256;++r)e[r]=String.fromCharCode(r);er=e}var er=void 0;function _(e){for(var r="",t=e;b[t];)r+=er[b[t++]];return r}var W={},R={},ae={},Mr=48,Wr=57;function Oe(e){if(e===void 0)return"_unknown";e=e.replace(/[^a-zA-Z0-9_]/g,"$");var r=e.charCodeAt(0);return r>=Mr&&r<=Wr?"_"+e:e}function ke(e,r){return e=Oe(e),{[e]:function(){return r.apply(this,arguments)}}[e]}function Ee(e,r){var t=ke(r,function(n){this.name=r,this.message=n;var i=new Error(n).stack;i!==void 0&&(this.stack=this.toString()+`
2
+ `+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 I=void 0;function g(e){throw new I(e)}var rr=void 0;function oe(e){throw new rr(e)}function D(e,r,t){e.forEach(function(a){ae[a]=r});function n(a){var l=t(a);l.length!==e.length&&oe("Mismatched type converter count");for(var o=0;o<e.length;++o)S(e[o],l[o])}var i=new Array(r.length),s=[],f=0;r.forEach((a,l)=>{R.hasOwnProperty(a)?i[l]=R[a]:(s.push(a),W.hasOwnProperty(a)||(W[a]=[]),W[a].push(()=>{i[l]=R[a],++f,f===s.length&&n(i)}))}),s.length===0&&n(i)}function S(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 ae[e],W.hasOwnProperty(e)){var i=W[e];delete W[e],i.forEach(s=>s())}}function Rr(e,r,t,n,i){var s=je(t);r=_(r),S(e,{name:r,fromWireType:function(f){return!!f},toWireType:function(f,a){return a?n:i},argPackAdvance:8,readValueFromPointer:function(f){var a;if(t===1)a=Se;else if(t===2)a=J;else if(t===4)a=U;else throw new TypeError("Unknown boolean type size: "+r);return this.fromWireType(a[f>>s])},destructorFunction:null})}function Ir(e){if(!(this instanceof j)||!(e instanceof j))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 Lr(e){return{count:e.count,deleteScheduled:e.deleteScheduled,preservePointerOnDelete:e.preservePointerOnDelete,ptr:e.ptr,ptrType:e.ptrType,smartPtr:e.smartPtr,smartPtrType:e.smartPtrType}}function Ue(e){function r(t){return t.$$.ptrType.registeredClass.name}g(r(e)+" instance already deleted")}var me=!1;function tr(e){}function Hr(e){e.smartPtr?e.smartPtrType.rawDestructor(e.smartPtr):e.ptrType.registeredClass.rawDestructor(e.ptr)}function nr(e){e.count.value-=1;var r=e.count.value===0;r&&Hr(e)}function ir(e,r,t){if(r===t)return e;if(t.baseClass===void 0)return null;var n=ir(e,r,t.baseClass);return n===null?null:t.downcast(n)}var sr={};function Vr(){return Object.keys(B).length}function Br(){var e=[];for(var r in B)B.hasOwnProperty(r)&&e.push(B[r]);return e}var G=[];function De(){for(;G.length;){var e=G.pop();e.$$.deleteScheduled=!1,e.delete()}}var V=void 0;function xr(e){V=e,G.length&&V&&V(De)}function zr(){h.getInheritedInstanceCount=Vr,h.getLiveInheritedInstances=Br,h.flushPendingDeletes=De,h.setDelayFunction=xr}var B={};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 Gr(e,r){return r=Jr(e,r),B[r]}function Z(e,r){(!r.ptrType||!r.ptr)&&oe("makeClassHandle requires ptr and ptrType");var t=!!r.smartPtrType,n=!!r.smartPtr;return t!==n&&oe("Both smartPtrType and smartPtr must be specified"),r.count={value:1},x(Object.create(e,{$$:{value:r}}))}function Xr(e){var r=this.getPointee(e);if(!r)return this.destructor(e),null;var t=Gr(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=sr[s];if(!f)return i.call(this);var a;this.isConst?a=f.constPointerType:a=f.pointerType;var l=ir(r,this.registeredClass,a.registeredClass);return l===null?i.call(this):this.isSmartPointer?Z(a.registeredClass.instancePrototype,{ptrType:a,ptr:l,smartPtrType:this,smartPtr:e}):Z(a.registeredClass.instancePrototype,{ptrType:a,ptr:l})}function x(e){return typeof FinalizationRegistry>"u"?(x=r=>r,e):(me=new FinalizationRegistry(r=>{nr(r.$$)}),x=r=>{var t=r.$$,n=!!t.smartPtr;if(n){var i={$$:t};me.register(r,i,r)}return r},tr=r=>me.unregister(r),x(e))}function qr(){if(this.$$.ptr||Ue(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var e=x(Object.create(Object.getPrototypeOf(this),{$$:{value:Lr(this.$$)}}));return e.$$.count.value+=1,e.$$.deleteScheduled=!1,e}function Yr(){this.$$.ptr||Ue(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&g("Object already scheduled for deletion"),tr(this),nr(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function Kr(){return!this.$$.ptr}function Qr(){return this.$$.ptr||Ue(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&g("Object already scheduled for deletion"),G.push(this),G.length===1&&V&&V(De),this.$$.deleteScheduled=!0,this}function Zr(){j.prototype.isAliasOf=Ir,j.prototype.clone=qr,j.prototype.delete=Yr,j.prototype.isDeleted=Kr,j.prototype.deleteLater=Qr}function j(){}function ar(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 Nr(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"),ar(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 et(e,r,t,n,i,s,f,a){this.name=e,this.constructor=r,this.instancePrototype=t,this.rawDestructor=n,this.baseClass=i,this.getActualType=s,this.upcast=f,this.downcast=a,this.pureVirtualFunctions=[]}function ue(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 rt(e,r){if(r===null)return this.isReference&&g("null is not a valid "+this.name),0;r.$$||g('Cannot pass "'+Me(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=ue(r.$$.ptr,t,this.registeredClass);return n}function tt(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 "'+Me(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=ue(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 nt(e,r){if(r===null)return this.isReference&&g("null is not a valid "+this.name),0;r.$$||g('Cannot pass "'+Me(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=ue(r.$$.ptr,t,this.registeredClass);return n}function ce(e){return this.fromWireType(U[e>>2])}function it(e){return this.rawGetPointee&&(e=this.rawGetPointee(e)),e}function st(e){this.rawDestructor&&this.rawDestructor(e)}function at(e){e!==null&&e.delete()}function ot(){A.prototype.getPointee=it,A.prototype.destructor=st,A.prototype.argPackAdvance=8,A.prototype.readValueFromPointer=ce,A.prototype.deleteObject=at,A.prototype.fromWireType=Xr}function A(e,r,t,n,i,s,f,a,l,o,u){this.name=e,this.registeredClass=r,this.isReference=t,this.isConst=n,this.isSmartPointer=i,this.pointeeType=s,this.sharingPolicy=f,this.rawGetPointee=a,this.rawConstructor=l,this.rawShare=o,this.rawDestructor=u,!i&&r.baseClass===void 0?n?(this.toWireType=rt,this.destructorFunction=null):(this.toWireType=nt,this.destructorFunction=null):this.toWireType=tt}function ft(e,r,t){h.hasOwnProperty(e)||oe("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 lt(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=Ne.get(e)),r}function ut(e,r,t){if(e.includes("j"))return lt(e,r,t);var n=q(r).apply(null,t);return n}function ct(e,r){var t=[];return function(){return t.length=0,Object.assign(t,arguments),ut(e,r,t)}}function k(e,r){e=_(e);function t(){return e.includes("j")?ct(e,r):q(r)}var n=t();return typeof n!="function"&&g("unknown function pointer with signature "+e+": "+r),n}var or=void 0;function dt(e){var r=dr(e),t=_(r);return F(r),t}function X(e,r){var t=[],n={};function i(s){if(!n[s]&&!R[s]){if(ae[s]){ae[s].forEach(i);return}t.push(s),n[s]=!0}}throw r.forEach(i),new or(e+": "+t.map(dt).join([", "]))}function gt(e,r,t,n,i,s,f,a,l,o,u,c,d){u=_(u),s=k(i,s),a&&(a=k(f,a)),o&&(o=k(l,o)),d=k(c,d);var p=Oe(u);Nr(p,function(){X("Cannot construct "+u+" due to unbound types",[n])}),D([e,r,t],n?[n]:[],function(v){v=v[0];var m,y;n?(m=v.registeredClass,y=m.instancePrototype):y=j.prototype;var w=ke(p,function(){if(Object.getPrototypeOf(this)!==$)throw new I("Use 'new' to construct "+u);if(T.constructor_body===void 0)throw new I(u+" has no accessible constructor");var Q=T.constructor_body[arguments.length];if(Q===void 0)throw new I("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)}),$=Object.create(y,{constructor:{value:w}});w.prototype=$;var T=new et(u,w,$,d,m,s,a,o),ve=new A(u,T,!0,!1,!1),Y=new A(u+"*",T,!1,!1,!1),K=new A(u+" const*",T,!1,!0,!1);return sr[e]={pointerType:Y,constPointerType:K},ft(p,w),[ve,Y,K]})}function fr(e,r){for(var t=[],n=0;n<e;n++)t.push(C[r+n*4>>2]);return t}function lr(e){for(;e.length;){var r=e.pop(),t=e.pop();t(r)}}function pt(e,r){if(!(e instanceof Function))throw new TypeError("new_ called with constructor type "+typeof e+" which is not a function");var t=ke(e.name||"unknownFunctionName",function(){});t.prototype=e.prototype;var n=new t,i=e.apply(n,r);return i instanceof Object?i:n}function ur(e,r,t,n,i,s){var f=r.length;f<2&&g("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var a=r[1]!==null&&t!==null,l=!1,o=1;o<r.length;++o)if(r[o]!==null&&r[o].destructorFunction===void 0){l=!0;break}for(var u=r[0].name!=="void",c="",d="",o=0;o<f-2;++o)c+=(o!==0?", ":"")+"arg"+o,d+=(o!==0?", ":"")+"arg"+o+"Wired";var p="return function "+Oe(e)+"("+c+`) {
3
+ if (arguments.length !== `+(f-2)+`) {
4
+ throwBindingError('function `+e+" called with ' + arguments.length + ' arguments, expected "+(f-2)+` args!');
8
5
  }
9
- `;o&&(d+=`var destructors = [];
10
- `);var h=o?"destructors":"null",v=["throwBindingError","invoker","fn","runDestructors","retType","classParam"],y=[g,n,i,ur,r[0],r[1]];f&&(d+="var thisWired = classParam.toWireType("+h+`, this);
11
- `);for(var a=0;a<s-2;++a)d+="var arg"+a+"Wired = argType"+a+".toWireType("+h+", arg"+a+"); // "+r[a+2].name+`
12
- `,v.push("argType"+a),y.push(r[a+2]);if(f&&(c="thisWired"+(c.length>0?", ":"")+c),d+=(l?"var rv = ":"")+"invoker(fn"+(c.length>0?", ":"")+c+`);
13
- `,o)d+=`runDestructors(destructors);
14
- `;else for(var a=f?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
- `,v.push(b+"_dtor"),y.push(r[a].destructorFunction))}l&&(d+=`var ret = retType.fromWireType(rv);
6
+ `;l&&(p+=`var destructors = [];
7
+ `);var v=l?"destructors":"null",m=["throwBindingError","invoker","fn","runDestructors","retType","classParam"],y=[g,n,i,lr,r[0],r[1]];a&&(p+="var thisWired = classParam.toWireType("+v+`, this);
8
+ `);for(var o=0;o<f-2;++o)p+="var arg"+o+"Wired = argType"+o+".toWireType("+v+", arg"+o+"); // "+r[o+2].name+`
9
+ `,m.push("argType"+o),y.push(r[o+2]);if(a&&(d="thisWired"+(d.length>0?", ":"")+d),p+=(u||s?"var rv = ":"")+"invoker(fn"+(d.length>0?", ":"")+d+`);
10
+ `,l)p+=`runDestructors(destructors);
11
+ `;else for(var o=a?1:2;o<r.length;++o){var w=o===1?"thisWired":"arg"+(o-2)+"Wired";r[o].destructorFunction!==null&&(p+=w+"_dtor("+w+"); // "+r[o].name+`
12
+ `,m.push(w+"_dtor"),y.push(r[o].destructorFunction))}u&&(p+=`var ret = retType.fromWireType(rv);
16
13
  return ret;
17
- `),d+=`}
18
- `,v.push(d);var _=ht(Function,v).apply(null,y);return _}function vt(e,r,t,n,i,s){assert(r>0);var f=lr(r,t);i=O(n,i),D([],[e],function(o){o=o[0];var a="constructor "+o.name;if(o.registeredClass.constructor_body===void 0&&(o.registeredClass.constructor_body=[]),o.registeredClass.constructor_body[r-1]!==void 0)throw new L("Cannot register multiple constructors with identical number of parameters ("+(r-1)+") for class '"+o.name+"'! Overload resolution is currently only performed using the parameter count, not actual type info!");return o.registeredClass.constructor_body[r-1]=()=>{J("Cannot construct "+o.name+" due to unbound types",f)},D([],f,function(l){return l.splice(1,0,null),o.registeredClass.constructor_body[r-1]=cr(a,l,null,i,s),[]}),[]})}function yt(e,r,t,n,i,s,f,o){var a=lr(t,n);r=w(r),s=O(i,s),D([],[e],function(l){l=l[0];var u=l.name+"."+r;r.startsWith("@@")&&(r=Symbol[r.substring(2)]),o&&l.registeredClass.pureVirtualFunctions.push(r);function c(){J("Cannot call "+u+" due to unbound types",a)}var d=l.registeredClass.instancePrototype,h=d[r];return h===void 0||h.overloadTable===void 0&&h.className!==l.name&&h.argCount===t-2?(c.argCount=t-2,c.className=l.name,d[r]=c):(or(d,r,u),d[r].overloadTable[t-2]=c),D([],a,function(v){var y=cr(u,v,l,s,f);return d[r].overloadTable===void 0?(y.argCount=t-2,d[r]=y):d[r].overloadTable[t-2]=y,[]}),[]})}function He(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"),ce(e.$$.ptr,e.$$.ptrType.registeredClass,r.registeredClass)}function mt(e,r,t,n,i,s,f,o,a,l){r=w(r),i=O(n,i),D([],[e],function(u){u=u[0];var c=u.name+"."+r,d={get:function(){J("Cannot access "+c+" due to unbound types",[t,f])},enumerable:!0,configurable:!0};return a?d.set=()=>{J("Cannot access "+c+" due to unbound types",[t,f])}:d.set=h=>{g(c+" is a read-only property")},Object.defineProperty(u.registeredClass.instancePrototype,r,d),D([],a?[t,f]:[t],function(h){var v=h[0],y={get:function(){var _=He(this,u,c+" getter");return v.fromWireType(i(s,_))},enumerable:!0};if(a){a=O(o,a);var b=h[1];y.set=function(_){var k=He(this,u,c+" setter"),T=[];a(l,k,b.toWireType(T,_)),ur(T)}}return Object.defineProperty(u.registeredClass.instancePrototype,r,y),[]}),[]})}var _e=[],P=[{},{value:void 0},{value:null},{value:!0},{value:!1}];function bt(e){e>4&&--P[e].refcount===0&&(P[e]=void 0,_e.push(e))}function wt(){for(var e=0,r=5;r<P.length;++r)P[r]!==void 0&&++e;return e}function _t(){for(var e=5;e<P.length;++e)if(P[e]!==void 0)return P[e];return null}function Ct(){p.count_emval_handles=wt,p.get_first_emval=_t}var Ce={toValue:e=>(e||g("Cannot use deleted val. handle = "+e),P[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=_e.length?_e.pop():P.length;return P[r]={refcount:1,value:e},r}}}};function Tt(e,r){r=w(r),F(e,{name:r,fromWireType:function(t){var n=Ce.toValue(t);return bt(t),n},toWireType:function(t,n){return Ce.toHandle(n)},argPackAdvance:8,readValueFromPointer:de,destructorFunction:null})}function We(e){if(e===null)return"null";var r=typeof e;return r==="object"||r==="array"||r==="function"?e.toString():""+e}function Pt(e,r){switch(r){case 2:return function(t){return this.fromWireType(Ze[t>>2])};case 3:return function(t){return this.fromWireType(Ne[t>>3])};default:throw new TypeError("Unknown float type: "+e)}}function $t(e,r,t){var n=Oe(t);r=w(r),F(e,{name:r,fromWireType:function(i){return i},toWireType:function(i,s){return s},argPackAdvance:8,readValueFromPointer:Pt(r,n),destructorFunction:null})}function At(e,r,t){switch(r){case 0:return t?function(i){return je[i]}:function(i){return m[i]};case 1:return t?function(i){return z[i>>1]}:function(i){return le[i>>1]};case 2:return t?function(i){return U[i>>2]}:function(i){return C[i>>2]};default:throw new TypeError("Unknown integer type: "+e)}}function Ft(e,r,t,n,i){r=w(r);var s=Oe(t),f=c=>c;if(n===0){var o=32-8*t;f=c=>c<<o>>>o}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},F(e,{name:r,fromWireType:f,toWireType:u,argPackAdvance:8,readValueFromPointer:At(r,s,n!==0),destructorFunction:null})}function St(e,r,t){var n=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],i=n[r];function s(f){f=f>>2;var o=C,a=o[f],l=o[f+1];return new i(ue,l,a)}t=w(t),F(e,{name:t,fromWireType:s,argPackAdvance:8,readValueFromPointer:s},{ignoreDuplicateRegistrations:!0})}function jt(e,r){r=w(r);var t=r==="std::string";F(e,{name:r,fromWireType:function(n){var i=C[n>>2],s=n+4,f;if(t)for(var o=s,a=0;a<=i;++a){var l=s+a;if(a==i||m[l]==0){var u=l-o,c=N(o,u);f===void 0?f=c:(f+=String.fromCharCode(0),f+=c),o=l+1}}else{for(var d=new Array(i),a=0;a<i;++a)d[a]=String.fromCharCode(m[s+a]);f=d.join("")}return A(n),f},toWireType:function(n,i){i instanceof ArrayBuffer&&(i=new Uint8Array(i));var s,f=typeof i=="string";f||i instanceof Uint8Array||i instanceof Uint8ClampedArray||i instanceof Int8Array||g("Cannot pass non-string to std::string"),t&&f?s=Sr(i):s=i.length;var o=ge(4+s+1),a=o+4;if(C[o>>2]=s,t&&f)Fr(i,a,s+1);else if(f)for(var l=0;l<s;++l){var u=i.charCodeAt(l);u>255&&(A(a),g("String has UTF-16 code units that do not fit in 8 bits")),m[a+l]=u}else for(var l=0;l<s;++l)m[a+l]=i[l];return n!==null&&n.push(A,o),o},argPackAdvance:8,readValueFromPointer:de,destructorFunction:function(n){A(n)}})}var Ot=new TextDecoder("utf-16le");function kt(e,r){for(var t=e,n=t>>1,i=n+r/2;!(n>=i)&&le[n];)++n;return t=n<<1,Ot.decode(m.subarray(e,t))}function Et(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 f=e.charCodeAt(s);z[r>>1]=f,r+=2}return z[r>>1]=0,r-n}function Ut(e){return e.length*2}function Dt(e,r){for(var t=0,n="";!(t>=r/4);){var i=U[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 Mt(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 f=e.charCodeAt(s);if(f>=55296&&f<=57343){var o=e.charCodeAt(++s);f=65536+((f&1023)<<10)|o&1023}if(U[r>>2]=f,r+=4,r+4>i)break}return U[r>>2]=0,r-n}function Wt(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 Rt(e,r,t){t=w(t);var n,i,s,f,o;r===2?(n=kt,i=Et,f=Ut,s=()=>le,o=1):r===4&&(n=Dt,i=Mt,f=Wt,s=()=>C,o=2),F(e,{name:t,fromWireType:function(a){for(var l=C[a>>2],u=s(),c,d=a+4,h=0;h<=l;++h){var v=a+4+h*r;if(h==l||u[v>>o]==0){var y=v-d,b=n(d,y);c===void 0?c=b:(c+=String.fromCharCode(0),c+=b),d=v+r}}return A(a),c},toWireType:function(a,l){typeof l!="string"&&g("Cannot pass non-string to C++ string type "+t);var u=f(l),c=ge(4+u+r);return C[c>>2]=u>>o,i(l,c+4,u+r),a!==null&&a.push(A,c),c},argPackAdvance:8,readValueFromPointer:de,destructorFunction:function(a){A(a)}})}function Lt(e,r){r=w(r),F(e,{isVoid:!0,name:r,argPackAdvance:0,fromWireType:function(){},toWireType:function(t,n){}})}function It(){throw 1/0}function Ht(){Ke("")}var dr;dr=()=>performance.now();function Vt(e,r,t){m.copyWithin(e,r,r+t)}function Bt(){return 2147483648}function xt(e){try{return ie.grow(e-ue.byteLength+65535>>>16),se(ie.buffer),1}catch{}}function zt(e){var r=m.length;e=e>>>0;var t=Bt();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 f=Math.min(t,n(Math.max(e,s),65536)),o=xt(f);if(o)return!0}return!1}function Gt(e){throw"exit("+e+")"}var Jt=Gt;function Xt(e){return 52}function qt(e,r,t,n){return 52}function Yt(e,r,t,n,i){return 70}var Kt=[null,[],[]];function Qt(e,r){var t=Kt[e];r===0||r===10?((e===1?Be:xe)($r(t,0)),t.length=0):t.push(r)}function Zt(e,r,t,n){for(var i=0,s=0;s<t;s++){var f=C[r>>2],o=C[r+4>>2];r+=8;for(var a=0;a<o;a++)Qt(e,m[f+a]);i+=o}return C[n>>2]=i,0}Mr();L=p.BindingError=Ue(Error,"BindingError");tr=p.InternalError=Ue(Error,"InternalError");Nr();Gr();ft();fr=p.UnboundTypeError=Ue(Error,"UnboundTypeError");Ct();var Nt={a:jr,m:Or,z:kr,D:Er,l:Ur,t:Dr,p:Lr,j:pt,s:vt,c:yt,b:mt,E:Tt,n:$t,f:Ft,d:St,o:jt,k:Rt,q:Lt,x:It,e:Ht,g:dr,A:Vt,y:zt,h:Jt,i:Xt,C:qt,r:Yt,B:Zt,w:en,u:tn,v:rn};function en(e,r,t){var n=he();try{return X(e)(r,t)}catch(i){if(ve(n),i!==i+0)throw i;pe(1,0)}}function rn(e,r,t,n,i){var s=he();try{return X(e)(r,t,n,i)}catch(f){if(ve(s),f!==f+0)throw f;pe(1,0)}}function tn(e,r,t,n){var i=he();try{return X(e)(r,t,n)}catch(s){if(ve(i),s!==s+0)throw s;pe(1,0)}}function nn(e){e.G()}var Ve={a:Nt},ge,A,gr,pe,he,ve;(WebAssembly.instantiateStreaming?WebAssembly.instantiateStreaming(fetch("jassub-worker.wasm"),Ve):WebAssembly.instantiate(p.wasm,Ve)).then(function(e){asm=(e.instance||e).exports,ge=asm.H,A=asm.I,gr=asm.J,asm.K,pe=asm.M,asm.N,he=asm.O,ve=asm.P,asm.Q,asm.R,asm.S,asm.T,er=asm.L,ie=asm.F,se(ie.buffer),nn(asm),ze()});
14
+ `),p+=`}
15
+ `,m.push(p);var $=pt(Function,m).apply(null,y);return $}function ht(e,r,t,n,i,s){assert(r>0);var f=fr(r,t);i=k(n,i),D([],[e],function(a){a=a[0];var l="constructor "+a.name;if(a.registeredClass.constructor_body===void 0&&(a.registeredClass.constructor_body=[]),a.registeredClass.constructor_body[r-1]!==void 0)throw new I("Cannot register multiple constructors with identical number of parameters ("+(r-1)+") for class '"+a.name+"'! Overload resolution is currently only performed using the parameter count, not actual type info!");return a.registeredClass.constructor_body[r-1]=()=>{X("Cannot construct "+a.name+" due to unbound types",f)},D([],f,function(o){return o.splice(1,0,null),a.registeredClass.constructor_body[r-1]=ur(l,o,null,i,s),[]}),[]})}function vt(e,r,t,n,i,s,f,a,l){var o=fr(t,n);r=_(r),s=k(i,s),D([],[e],function(u){u=u[0];var c=u.name+"."+r;r.startsWith("@@")&&(r=Symbol[r.substring(2)]),a&&u.registeredClass.pureVirtualFunctions.push(r);function d(){X("Cannot call "+c+" due to unbound types",o)}var p=u.registeredClass.instancePrototype,v=p[r];return v===void 0||v.overloadTable===void 0&&v.className!==u.name&&v.argCount===t-2?(d.argCount=t-2,d.className=u.name,p[r]=d):(ar(p,r,c),p[r].overloadTable[t-2]=d),D([],o,function(m){var y=ur(c,m,u,s,f,l);return p[r].overloadTable===void 0?(y.argCount=t-2,p[r]=y):p[r].overloadTable[t-2]=y,[]}),[]})}function Le(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"),ue(e.$$.ptr,e.$$.ptrType.registeredClass,r.registeredClass)}function yt(e,r,t,n,i,s,f,a,l,o){r=_(r),i=k(n,i),D([],[e],function(u){u=u[0];var c=u.name+"."+r,d={get:function(){X("Cannot access "+c+" due to unbound types",[t,f])},enumerable:!0,configurable:!0};return l?d.set=()=>{X("Cannot access "+c+" due to unbound types",[t,f])}:d.set=p=>{g(c+" is a read-only property")},Object.defineProperty(u.registeredClass.instancePrototype,r,d),D([],l?[t,f]:[t],function(p){var v=p[0],m={get:function(){var w=Le(this,u,c+" getter");return v.fromWireType(i(s,w))},enumerable:!0};if(l){l=k(a,l);var y=p[1];m.set=function(w){var $=Le(this,u,c+" setter"),T=[];l(o,$,y.toWireType(T,w)),lr(T)}}return Object.defineProperty(u.registeredClass.instancePrototype,r,m),[]}),[]})}var we=[],P=[{},{value:void 0},{value:null},{value:!0},{value:!1}];function mt(e){e>4&&--P[e].refcount===0&&(P[e]=void 0,we.push(e))}function bt(){for(var e=0,r=5;r<P.length;++r)P[r]!==void 0&&++e;return e}function wt(){for(var e=5;e<P.length;++e)if(P[e]!==void 0)return P[e];return null}function _t(){h.count_emval_handles=bt,h.get_first_emval=wt}var _e={toValue:e=>(e||g("Cannot use deleted val. handle = "+e),P[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=we.length?we.pop():P.length;return P[r]={refcount:1,value:e},r}}}};function Ct(e,r){r=_(r),S(e,{name:r,fromWireType:function(t){var n=_e.toValue(t);return mt(t),n},toWireType:function(t,n){return _e.toHandle(n)},argPackAdvance:8,readValueFromPointer:ce,destructorFunction:null})}function Me(e){if(e===null)return"null";var r=typeof e;return r==="object"||r==="array"||r==="function"?e.toString():""+e}function Tt(e,r){switch(r){case 2:return function(t){return this.fromWireType(Qe[t>>2])};case 3:return function(t){return this.fromWireType(Ze[t>>3])};default:throw new TypeError("Unknown float type: "+e)}}function Pt(e,r,t){var n=je(t);r=_(r),S(e,{name:r,fromWireType:function(i){return i},toWireType:function(i,s){return s},argPackAdvance:8,readValueFromPointer:Tt(r,n),destructorFunction:null})}function $t(e,r,t){switch(r){case 0:return t?function(i){return Se[i]}:function(i){return b[i]};case 1:return t?function(i){return J[i>>1]}:function(i){return le[i>>1]};case 2:return t?function(i){return U[i>>2]}:function(i){return C[i>>2]};default:throw new TypeError("Unknown integer type: "+e)}}function At(e,r,t,n,i){r=_(r);var s=je(t),f=c=>c;if(n===0){var a=32-8*t;f=c=>c<<a>>>a}var l=r.includes("unsigned"),o=(c,d)=>{},u;l?u=function(c,d){return o(d,this.name),d>>>0}:u=function(c,d){return o(d,this.name),d},S(e,{name:r,fromWireType:f,toWireType:u,argPackAdvance:8,readValueFromPointer:$t(r,s,n!==0),destructorFunction:null})}function Ft(e,r,t){var n=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],i=n[r];function s(f){f=f>>2;var a=C,l=a[f],o=a[f+1];return new i(a.buffer,o,l)}t=_(t),S(e,{name:t,fromWireType:s,argPackAdvance:8,readValueFromPointer:s},{ignoreDuplicateRegistrations:!0})}function St(e,r){r=_(r);var t=r==="std::string";S(e,{name:r,fromWireType:function(n){var i=C[n>>2],s=n+4,f;if(t)for(var a=s,l=0;l<=i;++l){var o=s+l;if(l==i||b[o]==0){var u=o-a,c=ee(a,u);f===void 0?f=c:(f+=String.fromCharCode(0),f+=c),a=o+1}}else{for(var d=new Array(i),l=0;l<i;++l)d[l]=String.fromCharCode(b[s+l]);f=d.join("")}return F(n),f},toWireType:function(n,i){i instanceof ArrayBuffer&&(i=new Uint8Array(i));var s,f=typeof i=="string";f||i instanceof Uint8Array||i instanceof Uint8ClampedArray||i instanceof Int8Array||g("Cannot pass non-string to std::string"),t&&f?s=Fr(i):s=i.length;var a=de(4+s+1),l=a+4;if(C[a>>2]=s,t&&f)Ar(i,l,s+1);else if(f)for(var o=0;o<s;++o){var u=i.charCodeAt(o);u>255&&(F(l),g("String has UTF-16 code units that do not fit in 8 bits")),b[l+o]=u}else for(var o=0;o<s;++o)b[l+o]=i[o];return n!==null&&n.push(F,a),a},argPackAdvance:8,readValueFromPointer:ce,destructorFunction:function(n){F(n)}})}var jt=new TextDecoder("utf-16le");function Ot(e,r){for(var t=e,n=t>>1,i=n+r/2;!(n>=i)&&le[n];)++n;return t=n<<1,jt.decode(b.subarray(e,t))}function kt(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 f=e.charCodeAt(s);J[r>>1]=f,r+=2}return J[r>>1]=0,r-n}function Et(e){return e.length*2}function Ut(e,r){for(var t=0,n="";!(t>=r/4);){var i=U[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 Dt(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 f=e.charCodeAt(s);if(f>=55296&&f<=57343){var a=e.charCodeAt(++s);f=65536+((f&1023)<<10)|a&1023}if(U[r>>2]=f,r+=4,r+4>i)break}return U[r>>2]=0,r-n}function Mt(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 Wt(e,r,t){t=_(t);var n,i,s,f,a;r===2?(n=Ot,i=kt,f=Et,s=()=>le,a=1):r===4&&(n=Ut,i=Dt,f=Mt,s=()=>C,a=2),S(e,{name:t,fromWireType:function(l){for(var o=C[l>>2],u=s(),c,d=l+4,p=0;p<=o;++p){var v=l+4+p*r;if(p==o||u[v>>a]==0){var m=v-d,y=n(d,m);c===void 0?c=y:(c+=String.fromCharCode(0),c+=y),d=v+r}}return F(l),c},toWireType:function(l,o){typeof o!="string"&&g("Cannot pass non-string to C++ string type "+t);var u=f(o),c=de(4+u+r);return C[c>>2]=u>>a,i(o,c+4,u+r),l!==null&&l.push(F,c),c},argPackAdvance:8,readValueFromPointer:ce,destructorFunction:function(l){F(l)}})}function Rt(e,r){r=_(r),S(e,{isVoid:!0,name:r,argPackAdvance:0,fromWireType:function(){},toWireType:function(t,n){}})}function It(){throw 1/0}function Lt(){Ye("")}var cr;cr=()=>performance.now();function Ht(e,r,t){b.copyWithin(e,r,r+t)}function Vt(){return 2147483648}function Bt(e){var r=L.buffer;try{return L.grow(e-r.byteLength+65535>>>16),se(),1}catch{}}function xt(e){var r=b.length;e=e>>>0;var t=Vt();if(e>t)return!1;let n=(l,o)=>l+(o-l%o)%o;for(var i=1;i<=4;i*=2){var s=r*(1+.2/i);s=Math.min(s,e+100663296);var f=Math.min(t,n(Math.max(e,s),65536)),a=Bt(f);if(a)return!0}return!1}function zt(e){throw"exit("+e+")"}var Jt=zt;function Gt(e){return 52}function Xt(e,r,t,n){return 52}function qt(e,r,t,n,i){return 70}var Yt=[null,[],[]];function Kt(e,r){var t=Yt[e];r===0||r===10?((e===1?Ve:Be)(Pr(t,0)),t.length=0):t.push(r)}function Qt(e,r,t,n){for(var i=0,s=0;s<t;s++){var f=C[r>>2],a=C[r+4>>2];r+=8;for(var l=0;l<a;l++)Kt(e,b[f+l]);i+=a}return C[n>>2]=i,0}Dr();I=h.BindingError=Ee(Error,"BindingError");rr=h.InternalError=Ee(Error,"InternalError");Zr();zr();ot();or=h.UnboundTypeError=Ee(Error,"UnboundTypeError");_t();var Zt={a:Sr,m:jr,z:Or,D:kr,l:Er,t:Ur,p:Rr,j:gt,s:ht,c:vt,b:yt,E:Ct,n:Pt,f:At,d:Ft,o:St,k:Wt,q:Rt,x:It,e:Lt,g:cr,A:Ht,y:xt,h:Jt,i:Gt,C:Xt,r:qt,B:Qt,w:Nt,u:rn,v:en};function Nt(e,r,t){var n=pe();try{return q(e)(r,t)}catch(i){if(he(n),i!==i+0)throw i;ge(1,0)}}function en(e,r,t,n,i){var s=pe();try{return q(e)(r,t,n,i)}catch(f){if(he(s),f!==f+0)throw f;ge(1,0)}}function rn(e,r,t,n){var i=pe();try{return q(e)(r,t,n)}catch(s){if(he(i),s!==s+0)throw s;ge(1,0)}}function tn(e){e.G()}var He={a:Zt},de,F,dr,ge,pe,he;(WebAssembly.instantiateStreaming?WebAssembly.instantiateStreaming(fetch("jassub-worker.wasm"),He):WebAssembly.instantiate(h.wasm,He)).then(function(e){asm=(e.instance||e).exports,de=asm.H,F=asm.I,dr=asm.J,asm.K,ge=asm.M,asm.N,pe=asm.O,he=asm.P,asm.Q,asm.R,asm.S,asm.T,Ne=asm.L,L=asm.F,se(),tn(asm),xe()});
Binary file
package/dist/jassub.es.js CHANGED
@@ -87,7 +87,7 @@ const h = class extends EventTarget {
87
87
  try {
88
88
  new ImageData(new Uint8ClampedArray([0, 0, 0, 0]), 1, 1);
89
89
  } catch {
90
- console.log("detected that ImageData is not constructable despite browser saying so"), self.ImageData = function(o, c, l) {
90
+ console.log("Detected that ImageData is not constructable despite browser saying so"), self.ImageData = function(o, c, l) {
91
91
  const m = t.createImageData(c, l);
92
92
  return o && m.data.set(o), m;
93
93
  };
@@ -1 +1 @@
1
- (function(h,o){typeof exports=="object"&&typeof module<"u"?module.exports=o():typeof define=="function"&&define.amd?define(o):(h=typeof globalThis<"u"?globalThis:h||self,h.JASSUB=o())})(this,function(){"use strict";var u=Object.defineProperty;var f=(h,o,l)=>o in h?u(h,o,{enumerable:!0,configurable:!0,writable:!0,value:l}):h[o]=l;var v=(h,o,l)=>(f(h,typeof o!="symbol"?o+"":o,l),l);!("requestVideoFrameCallback"in HTMLVideoElement.prototype)&&"getVideoPlaybackQuality"in HTMLVideoElement.prototype&&(HTMLVideoElement.prototype._rvfcpolyfillmap={},HTMLVideoElement.prototype.requestVideoFrameCallback=function(l){const e=this.getVideoPlaybackQuality(),t=this.mozPresentedFrames||this.mozPaintedFrames||e.totalVideoFrames-e.droppedVideoFrames,s=(r,i)=>{const d=this.getVideoPlaybackQuality(),m=this.mozPresentedFrames||this.mozPaintedFrames||d.totalVideoFrames-d.droppedVideoFrames;if(m>t){const c=this.mozFrameDelay||d.totalFrameDelay-e.totalFrameDelay||0,_=i-r;l(i,{presentationTime:i+c*1e3,expectedDisplayTime:i+_,width:this.videoWidth,height:this.videoHeight,mediaTime:Math.max(0,this.currentTime||0)+_/1e3,presentedFrames:m,processingDuration:c}),delete this._rvfcpolyfillmap[a]}else this._rvfcpolyfillmap[a]=requestAnimationFrame(c=>s(i,c))},a=Date.now(),n=performance.now();return this._rvfcpolyfillmap[a]=requestAnimationFrame(r=>s(n,r)),a},HTMLVideoElement.prototype.cancelVideoFrameCallback=function(l){cancelAnimationFrame(this._rvfcpolyfillmap[l]),delete this._rvfcpolyfillmap[l]});const o=class extends EventTarget{constructor(e={}){super(),globalThis.Worker||this.destroy("Worker not supported"),o._test();const t=e.blendMode||"js",s=typeof createImageBitmap<"u"&&(e.asyncRender??!0),a=typeof OffscreenCanvas<"u"&&(e.offscreenRender??!0);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(o._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=>{this._init=()=>{var r;this._destroyed||(this._worker.postMessage({target:"init",asyncRender:s,onDemandRender:this._onDemandRender,width:this._canvasctrl.width,height:this._canvasctrl.height,preMain:!0,blendMode:t,subUrl:e.subUrl,subContent:e.subContent||null,fonts:e.fonts||[],availableFonts:e.availableFonts||{"liberation sans":"./default.woff2"},fallbackFont:e.fallbackFont||"liberation sans",debug:this.debug,targetFps:e.targetFps||24,dropAllAnimations:e.dropAllAnimations,libassMemoryLimit:e.libassMemoryLimit||0,libassGlyphLimit:e.libassGlyphLimit||0,hasAlphaBug:o._hasAlphaBug,useLocalFonts:"queryLocalFonts"in self&&(e.useLocalFonts??!0)}),a===!0&&this.sendMessage("offscreenCanvas",null,[this._canvasctrl]),this._boundResize=this.resize.bind(this),this._boundTimeUpdate=this._timeupdate.bind(this),this._boundSetRate=this.setRate.bind(this),this._video&&this.setVideo(e.video),this._onDemandRender&&(this.busy=!1,this._lastDemandTime=null,(r=this._video)==null||r.requestVideoFrameCallback(this._handleRVFC.bind(this))),n())}})}static _test(){if(o._supportsWebAssembly!==null)return null;const e=document.createElement("canvas"),t=e.getContext("2d",{willReadFrequently:!0});if(typeof ImageData.prototype.constructor=="function")try{new ImageData(new Uint8ClampedArray([0,0,0,0]),1,1)}catch{console.log("detected that ImageData is not constructable despite browser saying so"),self.ImageData=function(d,m,c){const _=t.createImageData(m,c);return d&&_.data.set(d),_}}try{if(typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function"){const i=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));i instanceof WebAssembly.Module&&(o._supportsWebAssembly=new WebAssembly.Instance(i)instanceof WebAssembly.Instance)}}catch{o._supportsWebAssembly=!1}const s=document.createElement("canvas"),a=s.getContext("2d",{willReadFrequently:!0});e.width=s.width=1,e.height=s.height=1,t.clearRect(0,0,1,1),a.clearRect(0,0,1,1);const n=a.getImageData(0,0,1,1).data;t.putImageData(new ImageData(new Uint8ClampedArray([0,255,0,0]),1,1),0,0),a.drawImage(e,0,0);const r=a.getImageData(0,0,1,1).data;o._hasAlphaBug=n[1]!==r[1],o._hasAlphaBug&&console.log("Detected a browser having issue with transparent pixels, applying workaround"),e.remove(),s.remove()}resize(e=0,t=0,s=0,a=0,n=(r=>(r=this._video)==null?void 0:r.paused)()){if((!e||!t)&&this._video){const i=this._getVideoPosition();let d=null;if(this._videoWidth){const m=this._video.videoWidth/this._videoWidth,c=this._video.videoHeight/this._videoHeight;d=this._computeCanvasSize((i.width||0)/m,(i.height||0)/c)}else d=this._computeCanvasSize(i.width||0,i.height||0);e=d.width,t=d.height,this._canvasParent&&(s=i.y-(this._canvasParent.getBoundingClientRect().top-this._video.getBoundingClientRect().top),a=i.x),this._canvas.style.width=i.width+"px",this._canvas.style.height=i.height+"px"}this._canvas.style.top=s+"px",this._canvas.style.left=a+"px",this.sendMessage("canvas",{width:e,height:t,force:n&&this.busy===!1})}_getVideoPosition(e=this._video.videoWidth,t=this._video.videoHeight){const s=e/t,{offsetWidth:a,offsetHeight:n}=this._video,r=a/n;e=a,t=n,r>s?e=Math.floor(n*s):t=Math.floor(a/s);const i=(a-e)/2,d=(n-t)/2;return{width:e,height:t,x:i,y:d}}_computeCanvasSize(e=0,t=0){const s=this.prescaleFactor<=0?1:this.prescaleFactor,a=self.devicePixelRatio||1;if(e=e*a,t=t*a,t<=0||e<=0)e=0,t=0;else{const n=s<1?-1:1;let r=t*a;n*r*s<=n*this.prescaleHeightLimit?r*=s:n*r<n*this.prescaleHeightLimit&&(r=this.prescaleHeightLimit),this.maxRenderHeight>0&&r>this.maxRenderHeight&&(r=this.maxRenderHeight),e*=r/t,t=r}return{width:e,height:t}}_timeupdate({type:e}){const s={seeking:!0,waiting:!0,playing:!1}[e];s!=null&&(this._playstate=s),this.setCurrentTime(this._video.paused||this._playstate,this._video.currentTime+this.timeOffset)}setVideo(e){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!")}runBenchmark(){this.sendMessage("runBenchmark")}setTrackByUrl(e){this.sendMessage("setTrackByUrl",{url:e})}setTrack(e){this.sendMessage("setTrack",{content:e})}freeTrack(){this.sendMessage("freeTrack")}setIsPaused(e){this.sendMessage("video",{isPaused:e})}setRate(e){this.sendMessage("video",{rate:e})}setCurrentTime(e,t,s){this.sendMessage("video",{isPaused:e,currentTime:t,rate:s})}createEvent(e){this.sendMessage("createEvent",{event:e})}setEvent(e,t){this.sendMessage("setEvent",{event:e,index:t})}removeEvent(e){this.sendMessage("removeEvent",{index:e})}getEvents(e){this._fetchFromWorker({target:"getEvents"},(t,{events:s})=>{e(t,s)})}createStyle(e){this.sendMessage("createStyle",{style:e})}setStyle(e,t){this.sendMessage("setStyle",{event:e,index:t})}removeStyle(e){this.sendMessage("removeStyle",{index:e})}getStyles(e){this._fetchFromWorker({target:"getStyles"},(t,{styles:s})=>{e(t,s)})}addFont(e){this.sendMessage("addFont",{font:e})}_sendLocalFont(e){try{queryLocalFonts().then(t=>{const s=t==null?void 0:t.find(a=>a.fullName.toLowerCase()===e);s&&s.blob().then(a=>{a.arrayBuffer().then(n=>{this.addFont(new Uint8Array(n))})})})}catch(t){console.warn("Local fonts API:",t)}}_getLocalFont({font:e}){var t;try{(t=navigator==null?void 0:navigator.permissions)!=null&&t.query?navigator.permissions.query({name:"local-fonts"}).then(s=>{s.state==="granted"&&this._sendLocalFont(e)}):this._sendLocalFont(e)}catch(s){console.warn("Local fonts API:",s)}}_unbusy(){this._lastDemandTime?this._demandRender(this._lastDemandTime):this.busy=!1}_handleRVFC(e,{mediaTime:t,width:s,height:a}){if(this._destroyed)return null;this.busy?this._lastDemandTime={mediaTime:t,width:s,height:a}:(this.busy=!0,this._demandRender({mediaTime:t,width:s,height:a})),this._video.requestVideoFrameCallback(this._handleRVFC.bind(this))}_demandRender({mediaTime:e,width:t,height:s}){this._lastDemandTime=null,(t!==this._videoWidth||s!==this._videoHeight)&&(this._videoWidth=t,this._videoHeight=s,this.resize()),this.sendMessage("demand",{time:e+this.timeOffset})}_render({images:e,async:t,times:s,width:a,height:n}){this._unbusy();const r=Date.now();(this._canvasctrl.width!==a||this._canvasctrl.height!==n)&&(this._canvasctrl.width=a,this._canvasctrl.height=n),this._ctx.clearRect(0,0,this._canvasctrl.width,this._canvasctrl.height);for(const i of e)i.image&&(t?(this._ctx.drawImage(i.image,i.x,i.y),i.image.close()):(this._bufferCanvas.width=i.w,this._bufferCanvas.height=i.h,this._bufferCtx.putImageData(new ImageData(this._fixAlpha(new Uint8ClampedArray(i.image)),i.w,i.h),0,0),this._ctx.drawImage(this._bufferCanvas,i.x,i.y)));if(this.debug){s.drawTime=Date.now()-r;let i=0;for(const d in s)i+=s[d];console.log("Bitmaps: "+e.length+" Total: "+Math.round(i)+"ms",s)}}_fixAlpha(e){if(o._hasAlphaBug)for(let t=3;t<e.length;t+=4)e[t]=e[t]>1?e[t]:1;return e}_ready(){this._init(),this.dispatchEvent(new CustomEvent("ready"))}async sendMessage(e,t={},s){await this._loaded,s?this._worker.postMessage({target:e,transferable:s,...t},[...s]):this._worker.postMessage({target:e,...t})}_fetchFromWorker(e,t){try{const s=e.target,a=setTimeout(()=>{r(new Error("Error: Timeout while try to fetch "+s))},5e3),n=({data:i})=>{i.target===s&&(t(null,i),this._worker.removeEventListener("message",n),this._worker.removeEventListener("error",r),clearTimeout(a))},r=i=>{t(i),this._worker.removeEventListener("message",n),this._worker.removeEventListener("error",r),clearTimeout(a)};this._worker.addEventListener("message",n),this._worker.addEventListener("error",r),this._worker.postMessage(e)}catch(s){this._error(s)}}_console({content:e,command:t}){console[t].apply(console,JSON.parse(e))}_onmessage({data:e}){this["_"+e.target]&&this["_"+e.target](e)}_error(e){const t=e instanceof Error?e:e instanceof ErrorEvent?e.error:new Error(e),s=e instanceof Event?new ErrorEvent(e.type,e):new ErrorEvent("error",{error:t});this.dispatchEvent(s),console.error(t)}_removeListeners(){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))}destroy(e){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()}};let h=o;return v(h,"_supportsWebAssembly",null),v(h,"_hasAlphaBug",null),h});
1
+ (function(h,o){typeof exports=="object"&&typeof module<"u"?module.exports=o():typeof define=="function"&&define.amd?define(o):(h=typeof globalThis<"u"?globalThis:h||self,h.JASSUB=o())})(this,function(){"use strict";var u=Object.defineProperty;var f=(h,o,l)=>o in h?u(h,o,{enumerable:!0,configurable:!0,writable:!0,value:l}):h[o]=l;var v=(h,o,l)=>(f(h,typeof o!="symbol"?o+"":o,l),l);!("requestVideoFrameCallback"in HTMLVideoElement.prototype)&&"getVideoPlaybackQuality"in HTMLVideoElement.prototype&&(HTMLVideoElement.prototype._rvfcpolyfillmap={},HTMLVideoElement.prototype.requestVideoFrameCallback=function(l){const e=this.getVideoPlaybackQuality(),t=this.mozPresentedFrames||this.mozPaintedFrames||e.totalVideoFrames-e.droppedVideoFrames,s=(r,i)=>{const d=this.getVideoPlaybackQuality(),m=this.mozPresentedFrames||this.mozPaintedFrames||d.totalVideoFrames-d.droppedVideoFrames;if(m>t){const c=this.mozFrameDelay||d.totalFrameDelay-e.totalFrameDelay||0,_=i-r;l(i,{presentationTime:i+c*1e3,expectedDisplayTime:i+_,width:this.videoWidth,height:this.videoHeight,mediaTime:Math.max(0,this.currentTime||0)+_/1e3,presentedFrames:m,processingDuration:c}),delete this._rvfcpolyfillmap[a]}else this._rvfcpolyfillmap[a]=requestAnimationFrame(c=>s(i,c))},a=Date.now(),n=performance.now();return this._rvfcpolyfillmap[a]=requestAnimationFrame(r=>s(n,r)),a},HTMLVideoElement.prototype.cancelVideoFrameCallback=function(l){cancelAnimationFrame(this._rvfcpolyfillmap[l]),delete this._rvfcpolyfillmap[l]});const o=class extends EventTarget{constructor(e={}){super(),globalThis.Worker||this.destroy("Worker not supported"),o._test();const t=e.blendMode||"js",s=typeof createImageBitmap<"u"&&(e.asyncRender??!0),a=typeof OffscreenCanvas<"u"&&(e.offscreenRender??!0);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(o._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=>{this._init=()=>{var r;this._destroyed||(this._worker.postMessage({target:"init",asyncRender:s,onDemandRender:this._onDemandRender,width:this._canvasctrl.width,height:this._canvasctrl.height,preMain:!0,blendMode:t,subUrl:e.subUrl,subContent:e.subContent||null,fonts:e.fonts||[],availableFonts:e.availableFonts||{"liberation sans":"./default.woff2"},fallbackFont:e.fallbackFont||"liberation sans",debug:this.debug,targetFps:e.targetFps||24,dropAllAnimations:e.dropAllAnimations,libassMemoryLimit:e.libassMemoryLimit||0,libassGlyphLimit:e.libassGlyphLimit||0,hasAlphaBug:o._hasAlphaBug,useLocalFonts:"queryLocalFonts"in self&&(e.useLocalFonts??!0)}),a===!0&&this.sendMessage("offscreenCanvas",null,[this._canvasctrl]),this._boundResize=this.resize.bind(this),this._boundTimeUpdate=this._timeupdate.bind(this),this._boundSetRate=this.setRate.bind(this),this._video&&this.setVideo(e.video),this._onDemandRender&&(this.busy=!1,this._lastDemandTime=null,(r=this._video)==null||r.requestVideoFrameCallback(this._handleRVFC.bind(this))),n())}})}static _test(){if(o._supportsWebAssembly!==null)return null;const e=document.createElement("canvas"),t=e.getContext("2d",{willReadFrequently:!0});if(typeof ImageData.prototype.constructor=="function")try{new ImageData(new Uint8ClampedArray([0,0,0,0]),1,1)}catch{console.log("Detected that ImageData is not constructable despite browser saying so"),self.ImageData=function(d,m,c){const _=t.createImageData(m,c);return d&&_.data.set(d),_}}try{if(typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function"){const i=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));i instanceof WebAssembly.Module&&(o._supportsWebAssembly=new WebAssembly.Instance(i)instanceof WebAssembly.Instance)}}catch{o._supportsWebAssembly=!1}const s=document.createElement("canvas"),a=s.getContext("2d",{willReadFrequently:!0});e.width=s.width=1,e.height=s.height=1,t.clearRect(0,0,1,1),a.clearRect(0,0,1,1);const n=a.getImageData(0,0,1,1).data;t.putImageData(new ImageData(new Uint8ClampedArray([0,255,0,0]),1,1),0,0),a.drawImage(e,0,0);const r=a.getImageData(0,0,1,1).data;o._hasAlphaBug=n[1]!==r[1],o._hasAlphaBug&&console.log("Detected a browser having issue with transparent pixels, applying workaround"),e.remove(),s.remove()}resize(e=0,t=0,s=0,a=0,n=(r=>(r=this._video)==null?void 0:r.paused)()){if((!e||!t)&&this._video){const i=this._getVideoPosition();let d=null;if(this._videoWidth){const m=this._video.videoWidth/this._videoWidth,c=this._video.videoHeight/this._videoHeight;d=this._computeCanvasSize((i.width||0)/m,(i.height||0)/c)}else d=this._computeCanvasSize(i.width||0,i.height||0);e=d.width,t=d.height,this._canvasParent&&(s=i.y-(this._canvasParent.getBoundingClientRect().top-this._video.getBoundingClientRect().top),a=i.x),this._canvas.style.width=i.width+"px",this._canvas.style.height=i.height+"px"}this._canvas.style.top=s+"px",this._canvas.style.left=a+"px",this.sendMessage("canvas",{width:e,height:t,force:n&&this.busy===!1})}_getVideoPosition(e=this._video.videoWidth,t=this._video.videoHeight){const s=e/t,{offsetWidth:a,offsetHeight:n}=this._video,r=a/n;e=a,t=n,r>s?e=Math.floor(n*s):t=Math.floor(a/s);const i=(a-e)/2,d=(n-t)/2;return{width:e,height:t,x:i,y:d}}_computeCanvasSize(e=0,t=0){const s=this.prescaleFactor<=0?1:this.prescaleFactor,a=self.devicePixelRatio||1;if(e=e*a,t=t*a,t<=0||e<=0)e=0,t=0;else{const n=s<1?-1:1;let r=t*a;n*r*s<=n*this.prescaleHeightLimit?r*=s:n*r<n*this.prescaleHeightLimit&&(r=this.prescaleHeightLimit),this.maxRenderHeight>0&&r>this.maxRenderHeight&&(r=this.maxRenderHeight),e*=r/t,t=r}return{width:e,height:t}}_timeupdate({type:e}){const s={seeking:!0,waiting:!0,playing:!1}[e];s!=null&&(this._playstate=s),this.setCurrentTime(this._video.paused||this._playstate,this._video.currentTime+this.timeOffset)}setVideo(e){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!")}runBenchmark(){this.sendMessage("runBenchmark")}setTrackByUrl(e){this.sendMessage("setTrackByUrl",{url:e})}setTrack(e){this.sendMessage("setTrack",{content:e})}freeTrack(){this.sendMessage("freeTrack")}setIsPaused(e){this.sendMessage("video",{isPaused:e})}setRate(e){this.sendMessage("video",{rate:e})}setCurrentTime(e,t,s){this.sendMessage("video",{isPaused:e,currentTime:t,rate:s})}createEvent(e){this.sendMessage("createEvent",{event:e})}setEvent(e,t){this.sendMessage("setEvent",{event:e,index:t})}removeEvent(e){this.sendMessage("removeEvent",{index:e})}getEvents(e){this._fetchFromWorker({target:"getEvents"},(t,{events:s})=>{e(t,s)})}createStyle(e){this.sendMessage("createStyle",{style:e})}setStyle(e,t){this.sendMessage("setStyle",{event:e,index:t})}removeStyle(e){this.sendMessage("removeStyle",{index:e})}getStyles(e){this._fetchFromWorker({target:"getStyles"},(t,{styles:s})=>{e(t,s)})}addFont(e){this.sendMessage("addFont",{font:e})}_sendLocalFont(e){try{queryLocalFonts().then(t=>{const s=t==null?void 0:t.find(a=>a.fullName.toLowerCase()===e);s&&s.blob().then(a=>{a.arrayBuffer().then(n=>{this.addFont(new Uint8Array(n))})})})}catch(t){console.warn("Local fonts API:",t)}}_getLocalFont({font:e}){var t;try{(t=navigator==null?void 0:navigator.permissions)!=null&&t.query?navigator.permissions.query({name:"local-fonts"}).then(s=>{s.state==="granted"&&this._sendLocalFont(e)}):this._sendLocalFont(e)}catch(s){console.warn("Local fonts API:",s)}}_unbusy(){this._lastDemandTime?this._demandRender(this._lastDemandTime):this.busy=!1}_handleRVFC(e,{mediaTime:t,width:s,height:a}){if(this._destroyed)return null;this.busy?this._lastDemandTime={mediaTime:t,width:s,height:a}:(this.busy=!0,this._demandRender({mediaTime:t,width:s,height:a})),this._video.requestVideoFrameCallback(this._handleRVFC.bind(this))}_demandRender({mediaTime:e,width:t,height:s}){this._lastDemandTime=null,(t!==this._videoWidth||s!==this._videoHeight)&&(this._videoWidth=t,this._videoHeight=s,this.resize()),this.sendMessage("demand",{time:e+this.timeOffset})}_render({images:e,async:t,times:s,width:a,height:n}){this._unbusy();const r=Date.now();(this._canvasctrl.width!==a||this._canvasctrl.height!==n)&&(this._canvasctrl.width=a,this._canvasctrl.height=n),this._ctx.clearRect(0,0,this._canvasctrl.width,this._canvasctrl.height);for(const i of e)i.image&&(t?(this._ctx.drawImage(i.image,i.x,i.y),i.image.close()):(this._bufferCanvas.width=i.w,this._bufferCanvas.height=i.h,this._bufferCtx.putImageData(new ImageData(this._fixAlpha(new Uint8ClampedArray(i.image)),i.w,i.h),0,0),this._ctx.drawImage(this._bufferCanvas,i.x,i.y)));if(this.debug){s.drawTime=Date.now()-r;let i=0;for(const d in s)i+=s[d];console.log("Bitmaps: "+e.length+" Total: "+Math.round(i)+"ms",s)}}_fixAlpha(e){if(o._hasAlphaBug)for(let t=3;t<e.length;t+=4)e[t]=e[t]>1?e[t]:1;return e}_ready(){this._init(),this.dispatchEvent(new CustomEvent("ready"))}async sendMessage(e,t={},s){await this._loaded,s?this._worker.postMessage({target:e,transferable:s,...t},[...s]):this._worker.postMessage({target:e,...t})}_fetchFromWorker(e,t){try{const s=e.target,a=setTimeout(()=>{r(new Error("Error: Timeout while try to fetch "+s))},5e3),n=({data:i})=>{i.target===s&&(t(null,i),this._worker.removeEventListener("message",n),this._worker.removeEventListener("error",r),clearTimeout(a))},r=i=>{t(i),this._worker.removeEventListener("message",n),this._worker.removeEventListener("error",r),clearTimeout(a)};this._worker.addEventListener("message",n),this._worker.addEventListener("error",r),this._worker.postMessage(e)}catch(s){this._error(s)}}_console({content:e,command:t}){console[t].apply(console,JSON.parse(e))}_onmessage({data:e}){this["_"+e.target]&&this["_"+e.target](e)}_error(e){const t=e instanceof Error?e:e instanceof ErrorEvent?e.error:new Error(e),s=e instanceof Event?new ErrorEvent(e.type,e):new ErrorEvent("error",{error:t});this.dispatchEvent(s),console.error(t)}_removeListeners(){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))}destroy(e){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()}};let h=o;return v(h,"_supportsWebAssembly",null),v(h,"_hasAlphaBug",null),h});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jassub",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "description": "libass Subtitle Renderer and Parser library for browsers",
5
5
  "main": "src/jassub.js",
6
6
  "files": [
package/src/jassub.js CHANGED
@@ -143,7 +143,7 @@ export default class JASSUB extends EventTarget {
143
143
  // eslint-disable-next-line no-new
144
144
  new ImageData(new Uint8ClampedArray([0, 0, 0, 0]), 1, 1)
145
145
  } catch (e) {
146
- console.log('detected that ImageData is not constructable despite browser saying so')
146
+ console.log('Detected that ImageData is not constructable despite browser saying so')
147
147
 
148
148
  self.ImageData = function (data, width, height) {
149
149
  const imageData = ctx1.createImageData(width, height)
Binary file