jassub 1.7.3 → 1.7.5
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/dist/jassub-worker.js +1 -1
- package/dist/jassub.es.js +5 -5
- package/dist/jassub.umd.js +1 -1
- package/package.json +2 -1
- package/src/jassub.js +1 -5
package/dist/jassub-worker.js
CHANGED
|
@@ -12,4 +12,4 @@ throwBindingError('function `+t+" called with ' + arguments.length + ' arguments
|
|
|
12
12
|
`,D.push(L+"_dtor"),U.push(r[g].destructorFunction))}return y&&(P+=`var ret = retType.fromWireType(rv);
|
|
13
13
|
return ret;
|
|
14
14
|
`),P+=`}
|
|
15
|
-
`,D.push(P),Gt(Function,D).apply(null,U)}function zt(t,r,n,s,i,f){F(r>0);var u=ze(r,n);i=q(s,i),K([],[t],function(l){l=l[0];var h="constructor "+l.name;if(l.registeredClass.constructor_body===void 0&&(l.registeredClass.constructor_body=[]),l.registeredClass.constructor_body[r-1]!==void 0)throw new N(`Cannot register multiple constructors with identical number of parameters (${r-1}) for class '${l.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);return l.registeredClass.constructor_body[r-1]=()=>{se(`Cannot construct ${l.name} due to unbound types`,u)},K([],u,function(g){return g.splice(1,0,null),l.registeredClass.constructor_body[r-1]=Ke(h,g,null,i,f),[]}),[]})}function qt(t,r,n,s,i,f,u,l,h){var g=ze(n,s);r=I(r),f=q(i,f),K([],[t],function(y){y=y[0];var _=y.name+"."+r;r.startsWith("@@")&&(r=Symbol[r.substring(2)]),l&&y.registeredClass.pureVirtualFunctions.push(r);function T(){se(`Cannot call ${_} due to unbound types`,g)}var P=y.registeredClass.instancePrototype,M=P[r];return M===void 0||M.overloadTable===void 0&&M.className!==y.name&&M.argCount===n-2?(T.argCount=n-2,T.className=y.name,P[r]=T):(Je(P,r,_),P[r].overloadTable[n-2]=T),K([],g,function(D){var U=Ke(_,D,y,f,u,h);return P[r].overloadTable===void 0?(U.argCount=n-2,P[r]=U):P[r].overloadTable[n-2]=U,[]}),[]})}function Ye(t,r,n){return t instanceof Object||w(n+' with invalid "this": '+t),t instanceof r.registeredClass.constructor||w(n+' incompatible with "this" of type '+t.constructor.name),t.$$.ptr||w(`cannot call emscripten binding method ${n} on deleted object`),ve(t.$$.ptr,t.$$.ptrType.registeredClass,r.registeredClass)}function Kt(t,r,n,s,i,f,u,l,h,g){r=I(r),i=q(s,i),K([],[t],function(y){y=y[0];var _=y.name+"."+r,T={get:function(){se(`Cannot access ${_} due to unbound types`,[n,u])},enumerable:!0,configurable:!0};return h?T.set=()=>{se(`Cannot access ${_} due to unbound types`,[n,u])}:T.set=P=>{w(_+" is a read-only property")},Object.defineProperty(y.registeredClass.instancePrototype,r,T),K([],h?[n,u]:[n],function(P){var M=P[0],D={get:function(){var L=Ye(this,y,_+" getter");return M.fromWireType(i(f,L))},enumerable:!0};if(h){h=q(l,h);var U=P[1];D.set=function(L){var oe=Ye(this,y,_+" setter"),W=[];h(g,oe,U.toWireType(W,L)),qe(W)}}return Object.defineProperty(y.registeredClass.instancePrototype,r,D),[]}),[]})}function Yt(){this.allocated=[void 0],this.freelist=[],this.get=function(t){return this.allocated[t]},this.allocate=function(t){var r=this.freelist.pop()||this.allocated.length;return this.allocated[r]=t,r},this.free=function(t){this.allocated[t]=void 0,this.freelist.push(t)}}var H=new Yt;function Xt(t){t>=H.reserved&&--H.get(t).refcount===0&&H.free(t)}function Qt(){for(var t=0,r=H.reserved;r<H.allocated.length;++r)H.allocated[r]!==void 0&&++t;return t}function Zt(){H.allocated.push({value:void 0},{value:null},{value:!0},{value:!1}),H.reserved=H.allocated.length,p.count_emval_handles=Qt}var Me={toValue:t=>(t||w("Cannot use deleted val. handle = "+t),H.get(t).value),toHandle:t=>{switch(t){case void 0:return 1;case null:return 2;case!0:return 3;case!1:return 4;default:return H.allocate({refcount:1,value:t})}}};function Nt(t,r){r=I(r),x(t,{name:r,fromWireType:function(n){var s=Me.toValue(n);return Xt(n),s},toWireType:function(n,s){return Me.toHandle(s)},argPackAdvance:8,readValueFromPointer:ye,destructorFunction:null})}function Ue(t){if(t===null)return"null";var r=typeof t;return r==="object"||r==="array"||r==="function"?t.toString():""+t}function er(t,r){switch(r){case 2:return function(n){return this.fromWireType(le[n>>2])};case 3:return function(n){return this.fromWireType(fe[n>>3])};default:throw new TypeError("Unknown float type: "+t)}}function tr(t,r,n){var s=Fe(n);r=I(r),x(t,{name:r,fromWireType:function(i){return i},toWireType:function(i,f){return f},argPackAdvance:8,readValueFromPointer:er(r,s),destructorFunction:null})}function rr(t,r,n){switch(r){case 0:return n?function(i){return j[i]}:function(i){return O[i]};case 1:return n?function(i){return E[i>>1]}:function(i){return G[i>>1]};case 2:return n?function(i){return k[i>>2]}:function(i){return R[i>>2]};default:throw new TypeError("Unknown integer type: "+t)}}function nr(t,r,n,s,i){r=I(r);var f=Fe(n),u=_=>_;if(s===0){var l=32-8*n;u=_=>_<<l>>>l}var h=r.includes("unsigned"),g=(_,T)=>{},y;h?y=function(_,T){return g(T,this.name),T>>>0}:y=function(_,T){return g(T,this.name),T},x(t,{name:r,fromWireType:u,toWireType:y,argPackAdvance:8,readValueFromPointer:rr(r,f,s!==0),destructorFunction:null})}function ar(t,r,n){var s=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],i=s[r];function f(u){u=u>>2;var l=R,h=l[u],g=l[u+1];return new i(l.buffer,g,h)}n=I(n),x(t,{name:n,fromWireType:f,argPackAdvance:8,readValueFromPointer:f},{ignoreDuplicateRegistrations:!0})}function sr(t){for(var r=0,n=0;n<t.length;++n){var s=t.charCodeAt(n);s<=127?r++:s<=2047?r+=2:s>=55296&&s<=57343?(r+=4,++n):r+=3}return r}function ir(t,r){r=I(r);var n=r==="std::string";x(t,{name:r,fromWireType:function(s){var i=R[s>>2],f=s+4,u;if(n)for(var l=f,h=0;h<=i;++h){var g=f+h;if(h==i||O[g]==0){var y=g-l,_=X(l,y);u===void 0?u=_:(u+=String.fromCharCode(0),u+=_),l=g+1}}else{for(var T=new Array(i),h=0;h<i;++h)T[h]=String.fromCharCode(O[f+h]);u=T.join("")}return J(s),u},toWireType:function(s,i){i instanceof ArrayBuffer&&(i=new Uint8Array(i));var f,u=typeof i=="string";u||i instanceof Uint8Array||i instanceof Uint8ClampedArray||i instanceof Int8Array||w("Cannot pass non-string to std::string"),n&&u?f=sr(i):f=i.length;var l=We(4+f+1),h=l+4;if(R[l>>2]=f,n&&u)Ae(i,h,f+1);else if(u)for(var g=0;g<f;++g){var y=i.charCodeAt(g);y>255&&(J(h),w("String has UTF-16 code units that do not fit in 8 bits")),O[h+g]=y}else for(var g=0;g<f;++g)O[h+g]=i[g];return s!==null&&s.push(J,l),l},argPackAdvance:8,readValueFromPointer:ye,destructorFunction:function(s){J(s)}})}var Xe=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0;function or(t,r){for(var n=t,s=n>>1,i=s+r/2;!(s>=i)&&G[s];)++s;if(n=s<<1,n-t>32&&Xe)return Xe.decode(O.subarray(t,n));for(var f="",u=0;!(u>=r/2);++u){var l=E[t+u*2>>1];if(l==0)break;f+=String.fromCharCode(l)}return f}function lr(t,r,n){if(n===void 0&&(n=2147483647),n<2)return 0;n-=2;for(var s=r,i=n<t.length*2?n/2:t.length,f=0;f<i;++f){var u=t.charCodeAt(f);E[r>>1]=u,r+=2}return E[r>>1]=0,r-s}function fr(t){return t.length*2}function ur(t,r){for(var n=0,s="";!(n>=r/4);){var i=k[t+n*4>>2];if(i==0)break;if(++n,i>=65536){var f=i-65536;s+=String.fromCharCode(55296|f>>10,56320|f&1023)}else s+=String.fromCharCode(i)}return s}function cr(t,r,n){if(n===void 0&&(n=2147483647),n<4)return 0;for(var s=r,i=s+n-4,f=0;f<t.length;++f){var u=t.charCodeAt(f);if(u>=55296&&u<=57343){var l=t.charCodeAt(++f);u=65536+((u&1023)<<10)|l&1023}if(k[r>>2]=u,r+=4,r+4>i)break}return k[r>>2]=0,r-s}function dr(t){for(var r=0,n=0;n<t.length;++n){var s=t.charCodeAt(n);s>=55296&&s<=57343&&++n,r+=4}return r}function pr(t,r,n){n=I(n);var s,i,f,u,l;r===2?(s=or,i=lr,u=fr,f=()=>G,l=1):r===4&&(s=ur,i=cr,u=dr,f=()=>R,l=2),x(t,{name:n,fromWireType:function(h){for(var g=R[h>>2],y=f(),_,T=h+4,P=0;P<=g;++P){var M=h+4+P*r;if(P==g||y[M>>l]==0){var D=M-T,U=s(T,D);_===void 0?_=U:(_+=String.fromCharCode(0),_+=U),T=M+r}}return J(h),_},toWireType:function(h,g){typeof g!="string"&&w("Cannot pass non-string to C++ string type "+n);var y=u(g),_=We(4+y+r);return R[_>>2]=y>>l,i(g,_+4,y+r),h!==null&&h.push(J,_),_},argPackAdvance:8,readValueFromPointer:ye,destructorFunction:function(h){J(h)}})}function gr(t,r){r=I(r),x(t,{isVoid:!0,name:r,argPackAdvance:0,fromWireType:function(){},toWireType:function(n,s){}})}function hr(){throw 1/0}function vr(t,r,n,s,i,f,u){return-52}function yr(t,r,n,s,i,f){}function br(){A("")}var Qe;Qe=()=>performance.now();function mr(){return 2147483648}function Cr(t){var r=B.buffer;try{return B.grow(t-r.byteLength+65535>>>16),Y(),1}catch{}}function wr(t){var r=O.length;t=t>>>0;var n=mr();if(t>n)return!1;for(var s=(h,g)=>h+(g-h%g)%g,i=1;i<=4;i*=2){var f=r*(1+.2/i);f=Math.min(f,t+100663296);var u=Math.min(n,s(Math.max(t,f),65536)),l=Cr(u);if(l)return!0}return!1}var De={};function _r(){return"./this.program"}function ie(){if(!ie.strings){var t=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",r={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:t,_:_r()};for(var n in De)De[n]===void 0?delete r[n]:r[n]=De[n];var s=[];for(var n in r)s.push(n+"="+r[n]);ie.strings=s}return ie.strings}function $r(t,r){for(var n=0;n<t.length;++n)j[r++>>0]=t.charCodeAt(n);j[r>>0]=0}function Tr(t,r){var n=0;return ie().forEach(function(s,i){var f=r+n;R[t+i*4>>2]=f,$r(s,f),n+=s.length+1}),0}function Pr(t,r){var n=ie();R[t>>2]=n.length;var s=0;return n.forEach(function(i){s+=i.length+1}),R[r>>2]=s,0}function Ar(t){throw"exit("+t+")"}var Fr=Ar;function Sr(t){return 52}function jr(t,r,n,s){return 52}function Or(t,r,n,s,i){return 70}var Er=[null,[],[]];function kr(t,r){var n=Er[t];r===0||r===10?((t===1?$:m)(de(n,0)),n.length=0):n.push(r)}function Rr(t,r,n,s){for(var i=0,f=0;f<n;f++){var u=R[r>>2],l=R[r+4>>2];r+=8;for(var h=0;h<l;h++)kr(t,O[u+h]);i+=l}return R[s>>2]=i,0}ct(),N=p.BindingError=Oe(Error,"BindingError"),Le=p.InternalError=Oe(Error,"InternalError"),jt(),wt(),It(),Ge=p.UnboundTypeError=Oe(Error,"UnboundTypeError"),Zt();var Mr={b:_e,k:$e,I:Te,B:st,K:it,G:ot,n:lt,H:ft,u:ut,r:gt,j:Jt,A:zt,d:qt,c:Kt,L:Nt,p:tr,g:nr,e:ar,q:ir,l:pr,s:gr,y:hr,C:vr,D:yr,f:br,m:Qe,z:wr,E:Tr,F:Pr,h:Fr,i:Sr,o:jr,t:Or,J:Rr,x:Ur,v:Wr,w:Dr,a:B};function Ur(t,r,n){var s=Ce();try{return ae(t)(r,n)}catch(i){if(we(s),i!==i+0)throw i;me(1,0)}}function Dr(t,r,n,s,i){var f=Ce();try{return ae(t)(r,n,s,i)}catch(u){if(we(f),u!==u+0)throw u;me(1,0)}}function Wr(t,r,n,s){var i=Ce();try{return ae(t)(r,n,s)}catch(f){if(we(i),f!==f+0)throw f;me(1,0)}}p.getTempRet0=tt,p.setTempRet0=et;function Ir(t){t.M()}var Ze={a:Mr},We,J,Ne,me,et,tt,Ce,we;return(WebAssembly.instantiateStreaming?WebAssembly.instantiateStreaming(fetch("jassub-worker-modern.wasm"),Ze):WebAssembly.instantiate(p.wasm,Ze)).then(function(t){C=(t.instance||t).exports,p._malloc=We=C.N,J=C.O,Ne=C.P,p.__embind_initialize_bindings=C.Q,me=C.S,et=C.T,tt=C.U,Ce=C.V,we=C.W,C.X,C.Y,C.Z,C._,ue=C.R,Ir(C),S()}),p.ready};const read_=(o,p)=>{const v=new XMLHttpRequest;return v.open("GET",o,!1),v.responseType=p?"arraybuffer":"text",v.send(null),v.response},readAsync=(o,p,v)=>{const $=new XMLHttpRequest;$.open("GET",o,!0),$.responseType="arraybuffer",$.onload=()=>{if(($.status===200||$.status===0)&&$.response)return p($.response)},$.onerror=v,$.send(null)};Date.now||(Date.now=()=>new Date().getTime());"performance"in self||(self.performance={now:()=>Date.now()});if(typeof console>"u"){const o=(p,v)=>{postMessage({target:"console",command:p,content:JSON.stringify(Array.prototype.slice.call(v))})};console={log:function(){o("log",arguments)},debug:function(){o("debug",arguments)},info:function(){o("info",arguments)},warn:function(){o("warn",arguments)},error:function(){o("error",arguments)}},console.log("Detected lack of console, overridden console")}let lastCurrentTime=0;const rate=1;let rafId=null,nextIsRaf=!1,lastCurrentTimeReceivedAt=Date.now(),targetFps=24,useLocalFonts=!1,blendMode="js",availableFonts={};const fontMap_={};let fontId=0,debug;self.width=0;self.height=0;let asyncRender=!1;self.addFont=({font:o})=>asyncWrite(o);const findAvailableFonts=o=>{o=o.trim().toLowerCase(),o.startsWith("@")&&(o=o.substring(1)),!fontMap_[o]&&(fontMap_[o]=!0,availableFonts[o]?asyncWrite(availableFonts[o]):useLocalFonts&&postMessage({target:"getLocalFont",font:o}))},asyncWrite=o=>{typeof o=="string"?readAsync(o,p=>{allocFont(new Uint8Array(p))},console.error):allocFont(o)},allocFont=o=>{const p=_malloc(o.byteLength);self.HEAPU8.set(o,p),jassubObj.addFont("font-"+fontId++,p,o.byteLength),jassubObj.reloadFonts()},processAvailableFonts=o=>{if(!availableFonts)return;const p=parseAss(o);for(let m=0;m<p.length;m++)for(let S=0;S<p[m].body.length;S++)p[m].body[S].key==="Style"&&findAvailableFonts(p[m].body[S].value.Fontname);const v=/\\fn([^\\}]*?)[\\}]/g;let $;for(;($=v.exec(o))!==null;)findAvailableFonts($[1])};self.setTrack=({content:o})=>{processAvailableFonts(o),dropAllBlur&&(o=dropBlur(o)),jassubObj.createTrackMem(o),subtitleColorSpace=libassYCbCrMap[jassubObj.trackColorSpace],postMessage({target:"verifyColorSpace",subtitleColorSpace})};self.getColorSpace=()=>postMessage({target:"verifyColorSpace",subtitleColorSpace});self.freeTrack=()=>{jassubObj.removeTrack()};self.setTrackByUrl=({url:o})=>{self.setTrack({content:read_(o)})};const getCurrentTime=()=>{const o=(Date.now()-lastCurrentTimeReceivedAt)/1e3;return _isPaused?lastCurrentTime:(o>5&&(console.error("Didn't received currentTime > 5 seconds. Assuming video was paused."),setIsPaused(!0)),lastCurrentTime+o*rate)},setCurrentTime=o=>{lastCurrentTime=o,lastCurrentTimeReceivedAt=Date.now(),rafId||(nextIsRaf?rafId=requestAnimationFrame(renderLoop):(renderLoop(),setTimeout(()=>{nextIsRaf=!1},20)))};let _isPaused=!0;const setIsPaused=o=>{o!==_isPaused&&(_isPaused=o,o?rafId&&(clearTimeout(rafId),rafId=null):(lastCurrentTimeReceivedAt=Date.now(),rafId=requestAnimationFrame(renderLoop)))},a="BT601",b="BT709",c="SMPTE240M",d="FCC",libassYCbCrMap=[null,a,null,a,a,b,b,c,c,d,d],render=(o,p)=>{const v={},$=performance.now(),m=blendMode==="wasm"?jassubObj.renderBlend(o,p||0):jassubObj.renderImage(o,p||0);if(debug){const S=performance.now(),F=jassubObj.time;v.WASMRenderTime=F-$,v.WASMBitmapDecodeTime=S-F,v.JSRenderTime=Date.now()}if(jassubObj.changed!==0||p){const S=[],F=[];if(!m)return paintImages({images:S,buffers:F,times:v});if(asyncRender){const C=[];for(let A=m,j=0;j<jassubObj.count;A=A.next,++j){const E={w:A.w,h:A.h,x:A.x,y:A.y},k=A.image,O=hasBitmapBug?self.HEAPU8C.slice(k,k+E.w*E.h*4):self.HEAPU8C.subarray(k,k+E.w*E.h*4);C.push(createImageBitmap(new ImageData(O,E.w,E.h))),S.push(E)}Promise.all(C).then(A=>{for(let j=0;j<S.length;j++)S[j].image=A[j];debug&&(v.JSBitmapGenerationTime=Date.now()-v.JSRenderTime),paintImages({images:S,buffers:A,times:v})})}else{for(let C=m,A=0;A<jassubObj.count;C=C.next,++A){const j={w:C.w,h:C.h,x:C.x,y:C.y,image:C.image};if(!offCanvasCtx){const E=self.wasmMemory.buffer.slice(C.image,C.image+C.w*C.h*4);F.push(E),j.image=E}S.push(j)}paintImages({images:S,buffers:F,times:v})}}else postMessage({target:"unbusy"})};self.demand=({time:o})=>{lastCurrentTime=o,render(o)};const renderLoop=o=>{rafId=0,render(getCurrentTime(),o),_isPaused||(rafId=requestAnimationFrame(renderLoop))},paintImages=({times:o,images:p,buffers:v})=>{const $={target:"render",asyncRender,images:p,times:o,width:self.width,height:self.height,colorSpace:subtitleColorSpace};if(offscreenRender){(offCanvas.height!==self.height||offCanvas.width!==self.width)&&(offCanvas.width=self.width,offCanvas.height=self.height),offCanvasCtx.clearRect(0,0,self.width,self.height);for(const m of p)m.image&&(asyncRender?(offCanvasCtx.drawImage(m.image,m.x,m.y),m.image.close()):(bufferCanvas.width=m.w,bufferCanvas.height=m.h,bufferCtx.putImageData(new ImageData(self.HEAPU8C.subarray(m.image,m.image+m.w*m.h*4),m.w,m.h),0,0),offCanvasCtx.drawImage(bufferCanvas,m.x,m.y)));if(offscreenRender==="hybrid"){if(!p.length)return postMessage($);debug&&(o.bitmaps=p.length);try{const m=offCanvas.transferToImageBitmap();$.images=[{image:m,x:0,y:0}],$.asyncRender=!0,postMessage($,[m])}catch{postMessage({target:"unbusy"})}}else{if(debug){o.JSRenderTime=Date.now()-o.JSRenderTime-(o.JSBitmapGenerationTime||0);let m=0;for(const S in o)m+=o[S];console.log("Bitmaps: "+p.length+" Total: "+(m|0)+"ms",o)}postMessage({target:"unbusy"})}}else postMessage($,v)},parseAss=o=>{let p,v,$,m,S,F,C,A,j,E;const k=[],O=o.split(/[\r\n]+/g);for(A=0;A<O.length;A++)if(p=O[A].match(/^\[(.*)\]$/),p)v=null,k.push({name:p[1],body:[]});else{if(/^\s*$/.test(O[A])||k.length===0)continue;if(E=k[k.length-1].body,O[A][0]===";")E.push({type:"comment",value:O[A].substring(1)});else{if(m=O[A].split(":"),S=m[0],F=m.slice(1).join(":").trim(),(v||S==="Format")&&(F=F.split(","),v&&F.length>v.length&&($=F.slice(v.length-1).join(","),F=F.slice(0,v.length-1),F.push($)),F=F.map(G=>G.trim()),v)){for(C={},j=0;j<F.length;j++)C[v[j]]=F[j];F=C}S==="Format"&&(v=F),E.push({key:S,value:F})}}return k},blurRegex=/\\blur(?:[0-9]+\.)?[0-9]+/gm,dropBlur=o=>o.replace(blurRegex,""),requestAnimationFrame=(()=>{let o=0;return p=>{const v=Date.now();if(o===0)o=v+1e3/targetFps;else for(;v+2>=o;)o+=1e3/targetFps;const $=Math.max(o-v,0);return setTimeout(p,$)}})(),_applyKeys=(o,p)=>{for(const v of Object.keys(o))p[v]=o[v]};let offCanvas,offCanvasCtx,offscreenRender,bufferCanvas,bufferCtx,jassubObj,subtitleColorSpace,dropAllBlur,_malloc,hasBitmapBug;self.init=data=>{hasBitmapBug=data.hasBitmapBug;try{const o=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(!(o instanceof WebAssembly.Module)||!(new WebAssembly.Instance(o)instanceof WebAssembly.Instance))throw new Error("WASM not supported")}catch(e){console.warn(e),eval(read_(data.legacyWasmUrl))}const _fetch=fetch,wasm=!WebAssembly.instantiateStreaming&&read_(data.wasmUrl,!0);WebAssembly.instantiateStreaming&&(self.fetch=o=>_fetch(data.wasmUrl)),Module({wasm}).then(o=>{_malloc=o._malloc,self.width=data.width,self.height=data.height,blendMode=data.blendMode,asyncRender=data.asyncRender,asyncRender&&typeof createImageBitmap>"u"&&(asyncRender=!1,console.error("'createImageBitmap' needed for 'asyncRender' unsupported!")),availableFonts=data.availableFonts,debug=data.debug,targetFps=data.targetFps||targetFps,useLocalFonts=data.useLocalFonts,dropAllBlur=data.dropAllBlur;const p=data.fallbackFont.toLowerCase();jassubObj=new o.JASSUB(self.width,self.height,p||null,debug),p&&findAvailableFonts(p);let v=data.subContent;v||(v=read_(data.subUrl)),processAvailableFonts(v),dropAllBlur&&(v=dropBlur(v));for(const $ of data.fonts||[])asyncWrite($);jassubObj.createTrackMem(v),subtitleColorSpace=libassYCbCrMap[jassubObj.trackColorSpace],jassubObj.setDropAnimations(data.dropAllAnimations||0),(data.libassMemoryLimit>0||data.libassGlyphLimit>0)&&jassubObj.setMemoryLimits(data.libassGlyphLimit||0,data.libassMemoryLimit||0),postMessage({target:"ready"}),postMessage({target:"verifyColorSpace",subtitleColorSpace})})};self.offscreenCanvas=({transferable:o})=>{offCanvas=o[0],offCanvasCtx=offCanvas.getContext("2d"),asyncRender||(bufferCanvas=new OffscreenCanvas(self.height,self.width),bufferCtx=bufferCanvas.getContext("2d",{desynchronized:!0})),offscreenRender=!0};self.detachOffscreen=()=>{offCanvas=new OffscreenCanvas(self.height,self.width),offCanvasCtx=offCanvas.getContext("2d",{desynchronized:!0}),offscreenRender="hybrid"};self.canvas=({width:o,height:p,force:v})=>{if(o==null)throw new Error("Invalid canvas size specified");self.width=o,self.height=p,jassubObj&&jassubObj.resizeCanvas(o,p),v&&render(lastCurrentTime,!0)};self.video=({currentTime:o,isPaused:p,rate:v})=>{o!=null&&setCurrentTime(o),p!=null&&setIsPaused(p),v=v||v};self.destroy=()=>{jassubObj.quitLibrary()};self.createEvent=({event:o})=>{_applyKeys(o,jassubObj.getEvent(jassubObj.allocEvent()))};self.getEvents=()=>{const o=[];for(let p=0;p<jassubObj.getEventCount();p++){const{Start:v,Duration:$,ReadOrder:m,Layer:S,Style:F,MarginL:C,MarginR:A,MarginV:j,Name:E,Text:k,Effect:O}=jassubObj.getEvent(p);o.push({Start:v,Duration:$,ReadOrder:m,Layer:S,Style:F,MarginL:C,MarginR:A,MarginV:j,Name:E,Text:k,Effect:O})}postMessage({target:"getEvents",events:o})};self.setEvent=({event:o,index:p})=>{_applyKeys(o,jassubObj.getEvent(p))};self.removeEvent=({index:o})=>{jassubObj.removeEvent(o)};self.createStyle=({style:o})=>{_applyKeys(o,jassubObj.getStyle(jassubObj.allocStyle()))};self.getStyles=()=>{const o=[];for(let p=0;p<jassubObj.getStyleCount();p++){const{Name:v,FontName:$,FontSize:m,PrimaryColour:S,SecondaryColour:F,OutlineColour:C,BackColour:A,Bold:j,Italic:E,Underline:k,StrikeOut:O,ScaleX:G,ScaleY:R,Spacing:le,Angle:fe,BorderStyle:B,Outline:ue,Shadow:Y,Alignment:ce,MarginL:de,MarginR:X,MarginV:_e,Encoding:$e,treat_fontname_as_pattern:Te,Blur:Pe,Justify:Ae}=jassubObj.getStyle(p);o.push({Name:v,FontName:$,FontSize:m,PrimaryColour:S,SecondaryColour:F,OutlineColour:C,BackColour:A,Bold:j,Italic:E,Underline:k,StrikeOut:O,ScaleX:G,ScaleY:R,Spacing:le,Angle:fe,BorderStyle:B,Outline:ue,Shadow:Y,Alignment:ce,MarginL:de,MarginR:X,MarginV:_e,Encoding:$e,treat_fontname_as_pattern:Te,Blur:Pe,Justify:Ae})}postMessage({target:"getStyles",time:Date.now(),styles:o})};self.setStyle=({style:o,index:p})=>{_applyKeys(o,jassubObj.getStyle(p))};self.removeStyle=({index:o})=>{jassubObj.removeStyle(o)};onmessage=({data:o})=>{if(self[o.target])self[o.target](o);else throw new Error("Unknown event target "+o.target)};
|
|
15
|
+
`,D.push(P),Gt(Function,D).apply(null,U)}function zt(t,r,n,s,i,f){F(r>0);var u=ze(r,n);i=q(s,i),K([],[t],function(l){l=l[0];var h="constructor "+l.name;if(l.registeredClass.constructor_body===void 0&&(l.registeredClass.constructor_body=[]),l.registeredClass.constructor_body[r-1]!==void 0)throw new N(`Cannot register multiple constructors with identical number of parameters (${r-1}) for class '${l.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);return l.registeredClass.constructor_body[r-1]=()=>{se(`Cannot construct ${l.name} due to unbound types`,u)},K([],u,function(g){return g.splice(1,0,null),l.registeredClass.constructor_body[r-1]=Ke(h,g,null,i,f),[]}),[]})}function qt(t,r,n,s,i,f,u,l,h){var g=ze(n,s);r=I(r),f=q(i,f),K([],[t],function(y){y=y[0];var _=y.name+"."+r;r.startsWith("@@")&&(r=Symbol[r.substring(2)]),l&&y.registeredClass.pureVirtualFunctions.push(r);function T(){se(`Cannot call ${_} due to unbound types`,g)}var P=y.registeredClass.instancePrototype,M=P[r];return M===void 0||M.overloadTable===void 0&&M.className!==y.name&&M.argCount===n-2?(T.argCount=n-2,T.className=y.name,P[r]=T):(Je(P,r,_),P[r].overloadTable[n-2]=T),K([],g,function(D){var U=Ke(_,D,y,f,u,h);return P[r].overloadTable===void 0?(U.argCount=n-2,P[r]=U):P[r].overloadTable[n-2]=U,[]}),[]})}function Ye(t,r,n){return t instanceof Object||w(n+' with invalid "this": '+t),t instanceof r.registeredClass.constructor||w(n+' incompatible with "this" of type '+t.constructor.name),t.$$.ptr||w(`cannot call emscripten binding method ${n} on deleted object`),ve(t.$$.ptr,t.$$.ptrType.registeredClass,r.registeredClass)}function Kt(t,r,n,s,i,f,u,l,h,g){r=I(r),i=q(s,i),K([],[t],function(y){y=y[0];var _=y.name+"."+r,T={get:function(){se(`Cannot access ${_} due to unbound types`,[n,u])},enumerable:!0,configurable:!0};return h?T.set=()=>{se(`Cannot access ${_} due to unbound types`,[n,u])}:T.set=P=>{w(_+" is a read-only property")},Object.defineProperty(y.registeredClass.instancePrototype,r,T),K([],h?[n,u]:[n],function(P){var M=P[0],D={get:function(){var L=Ye(this,y,_+" getter");return M.fromWireType(i(f,L))},enumerable:!0};if(h){h=q(l,h);var U=P[1];D.set=function(L){var oe=Ye(this,y,_+" setter"),W=[];h(g,oe,U.toWireType(W,L)),qe(W)}}return Object.defineProperty(y.registeredClass.instancePrototype,r,D),[]}),[]})}function Yt(){this.allocated=[void 0],this.freelist=[],this.get=function(t){return this.allocated[t]},this.allocate=function(t){var r=this.freelist.pop()||this.allocated.length;return this.allocated[r]=t,r},this.free=function(t){this.allocated[t]=void 0,this.freelist.push(t)}}var H=new Yt;function Xt(t){t>=H.reserved&&--H.get(t).refcount===0&&H.free(t)}function Qt(){for(var t=0,r=H.reserved;r<H.allocated.length;++r)H.allocated[r]!==void 0&&++t;return t}function Zt(){H.allocated.push({value:void 0},{value:null},{value:!0},{value:!1}),H.reserved=H.allocated.length,p.count_emval_handles=Qt}var Me={toValue:t=>(t||w("Cannot use deleted val. handle = "+t),H.get(t).value),toHandle:t=>{switch(t){case void 0:return 1;case null:return 2;case!0:return 3;case!1:return 4;default:return H.allocate({refcount:1,value:t})}}};function Nt(t,r){r=I(r),x(t,{name:r,fromWireType:function(n){var s=Me.toValue(n);return Xt(n),s},toWireType:function(n,s){return Me.toHandle(s)},argPackAdvance:8,readValueFromPointer:ye,destructorFunction:null})}function Ue(t){if(t===null)return"null";var r=typeof t;return r==="object"||r==="array"||r==="function"?t.toString():""+t}function er(t,r){switch(r){case 2:return function(n){return this.fromWireType(le[n>>2])};case 3:return function(n){return this.fromWireType(fe[n>>3])};default:throw new TypeError("Unknown float type: "+t)}}function tr(t,r,n){var s=Fe(n);r=I(r),x(t,{name:r,fromWireType:function(i){return i},toWireType:function(i,f){return f},argPackAdvance:8,readValueFromPointer:er(r,s),destructorFunction:null})}function rr(t,r,n){switch(r){case 0:return n?function(i){return j[i]}:function(i){return O[i]};case 1:return n?function(i){return E[i>>1]}:function(i){return G[i>>1]};case 2:return n?function(i){return k[i>>2]}:function(i){return R[i>>2]};default:throw new TypeError("Unknown integer type: "+t)}}function nr(t,r,n,s,i){r=I(r);var f=Fe(n),u=_=>_;if(s===0){var l=32-8*n;u=_=>_<<l>>>l}var h=r.includes("unsigned"),g=(_,T)=>{},y;h?y=function(_,T){return g(T,this.name),T>>>0}:y=function(_,T){return g(T,this.name),T},x(t,{name:r,fromWireType:u,toWireType:y,argPackAdvance:8,readValueFromPointer:rr(r,f,s!==0),destructorFunction:null})}function ar(t,r,n){var s=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],i=s[r];function f(u){u=u>>2;var l=R,h=l[u],g=l[u+1];return new i(l.buffer,g,h)}n=I(n),x(t,{name:n,fromWireType:f,argPackAdvance:8,readValueFromPointer:f},{ignoreDuplicateRegistrations:!0})}function sr(t){for(var r=0,n=0;n<t.length;++n){var s=t.charCodeAt(n);s<=127?r++:s<=2047?r+=2:s>=55296&&s<=57343?(r+=4,++n):r+=3}return r}function ir(t,r){r=I(r);var n=r==="std::string";x(t,{name:r,fromWireType:function(s){var i=R[s>>2],f=s+4,u;if(n)for(var l=f,h=0;h<=i;++h){var g=f+h;if(h==i||O[g]==0){var y=g-l,_=X(l,y);u===void 0?u=_:(u+=String.fromCharCode(0),u+=_),l=g+1}}else{for(var T=new Array(i),h=0;h<i;++h)T[h]=String.fromCharCode(O[f+h]);u=T.join("")}return J(s),u},toWireType:function(s,i){i instanceof ArrayBuffer&&(i=new Uint8Array(i));var f,u=typeof i=="string";u||i instanceof Uint8Array||i instanceof Uint8ClampedArray||i instanceof Int8Array||w("Cannot pass non-string to std::string"),n&&u?f=sr(i):f=i.length;var l=We(4+f+1),h=l+4;if(R[l>>2]=f,n&&u)Ae(i,h,f+1);else if(u)for(var g=0;g<f;++g){var y=i.charCodeAt(g);y>255&&(J(h),w("String has UTF-16 code units that do not fit in 8 bits")),O[h+g]=y}else for(var g=0;g<f;++g)O[h+g]=i[g];return s!==null&&s.push(J,l),l},argPackAdvance:8,readValueFromPointer:ye,destructorFunction:function(s){J(s)}})}var Xe=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0;function or(t,r){for(var n=t,s=n>>1,i=s+r/2;!(s>=i)&&G[s];)++s;if(n=s<<1,n-t>32&&Xe)return Xe.decode(O.subarray(t,n));for(var f="",u=0;!(u>=r/2);++u){var l=E[t+u*2>>1];if(l==0)break;f+=String.fromCharCode(l)}return f}function lr(t,r,n){if(n===void 0&&(n=2147483647),n<2)return 0;n-=2;for(var s=r,i=n<t.length*2?n/2:t.length,f=0;f<i;++f){var u=t.charCodeAt(f);E[r>>1]=u,r+=2}return E[r>>1]=0,r-s}function fr(t){return t.length*2}function ur(t,r){for(var n=0,s="";!(n>=r/4);){var i=k[t+n*4>>2];if(i==0)break;if(++n,i>=65536){var f=i-65536;s+=String.fromCharCode(55296|f>>10,56320|f&1023)}else s+=String.fromCharCode(i)}return s}function cr(t,r,n){if(n===void 0&&(n=2147483647),n<4)return 0;for(var s=r,i=s+n-4,f=0;f<t.length;++f){var u=t.charCodeAt(f);if(u>=55296&&u<=57343){var l=t.charCodeAt(++f);u=65536+((u&1023)<<10)|l&1023}if(k[r>>2]=u,r+=4,r+4>i)break}return k[r>>2]=0,r-s}function dr(t){for(var r=0,n=0;n<t.length;++n){var s=t.charCodeAt(n);s>=55296&&s<=57343&&++n,r+=4}return r}function pr(t,r,n){n=I(n);var s,i,f,u,l;r===2?(s=or,i=lr,u=fr,f=()=>G,l=1):r===4&&(s=ur,i=cr,u=dr,f=()=>R,l=2),x(t,{name:n,fromWireType:function(h){for(var g=R[h>>2],y=f(),_,T=h+4,P=0;P<=g;++P){var M=h+4+P*r;if(P==g||y[M>>l]==0){var D=M-T,U=s(T,D);_===void 0?_=U:(_+=String.fromCharCode(0),_+=U),T=M+r}}return J(h),_},toWireType:function(h,g){typeof g!="string"&&w("Cannot pass non-string to C++ string type "+n);var y=u(g),_=We(4+y+r);return R[_>>2]=y>>l,i(g,_+4,y+r),h!==null&&h.push(J,_),_},argPackAdvance:8,readValueFromPointer:ye,destructorFunction:function(h){J(h)}})}function gr(t,r){r=I(r),x(t,{isVoid:!0,name:r,argPackAdvance:0,fromWireType:function(){},toWireType:function(n,s){}})}function hr(){throw 1/0}function vr(t,r,n,s,i,f,u){return-52}function yr(t,r,n,s,i,f){}function br(){A("")}var Qe;Qe=()=>performance.now();function mr(){return 2147483648}function Cr(t){var r=B.buffer;try{return B.grow(t-r.byteLength+65535>>>16),Y(),1}catch{}}function wr(t){var r=O.length;t=t>>>0;var n=mr();if(t>n)return!1;for(var s=(h,g)=>h+(g-h%g)%g,i=1;i<=4;i*=2){var f=r*(1+.2/i);f=Math.min(f,t+100663296);var u=Math.min(n,s(Math.max(t,f),65536)),l=Cr(u);if(l)return!0}return!1}var De={};function _r(){return"./this.program"}function ie(){if(!ie.strings){var t=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",r={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:t,_:_r()};for(var n in De)De[n]===void 0?delete r[n]:r[n]=De[n];var s=[];for(var n in r)s.push(n+"="+r[n]);ie.strings=s}return ie.strings}function $r(t,r){for(var n=0;n<t.length;++n)j[r++>>0]=t.charCodeAt(n);j[r>>0]=0}function Tr(t,r){var n=0;return ie().forEach(function(s,i){var f=r+n;R[t+i*4>>2]=f,$r(s,f),n+=s.length+1}),0}function Pr(t,r){var n=ie();R[t>>2]=n.length;var s=0;return n.forEach(function(i){s+=i.length+1}),R[r>>2]=s,0}function Ar(t){throw"exit("+t+")"}var Fr=Ar;function Sr(t){return 52}function jr(t,r,n,s){return 52}function Or(t,r,n,s,i){return 70}var Er=[null,[],[]];function kr(t,r){var n=Er[t];r===0||r===10?((t===1?$:m)(de(n,0)),n.length=0):n.push(r)}function Rr(t,r,n,s){for(var i=0,f=0;f<n;f++){var u=R[r>>2],l=R[r+4>>2];r+=8;for(var h=0;h<l;h++)kr(t,O[u+h]);i+=l}return R[s>>2]=i,0}ct(),N=p.BindingError=Oe(Error,"BindingError"),Le=p.InternalError=Oe(Error,"InternalError"),jt(),wt(),It(),Ge=p.UnboundTypeError=Oe(Error,"UnboundTypeError"),Zt();var Mr={b:_e,k:$e,I:Te,B:st,K:it,G:ot,n:lt,H:ft,u:ut,r:gt,j:Jt,A:zt,d:qt,c:Kt,L:Nt,p:tr,g:nr,e:ar,q:ir,l:pr,s:gr,y:hr,C:vr,D:yr,f:br,m:Qe,z:wr,E:Tr,F:Pr,h:Fr,i:Sr,o:jr,t:Or,J:Rr,x:Ur,v:Wr,w:Dr,a:B};function Ur(t,r,n){var s=Ce();try{return ae(t)(r,n)}catch(i){if(we(s),i!==i+0)throw i;me(1,0)}}function Dr(t,r,n,s,i){var f=Ce();try{return ae(t)(r,n,s,i)}catch(u){if(we(f),u!==u+0)throw u;me(1,0)}}function Wr(t,r,n,s){var i=Ce();try{return ae(t)(r,n,s)}catch(f){if(we(i),f!==f+0)throw f;me(1,0)}}p.getTempRet0=tt,p.setTempRet0=et;function Ir(t){t.M()}var Ze={a:Mr},We,J,Ne,me,et,tt,Ce,we;return(WebAssembly.instantiateStreaming?WebAssembly.instantiateStreaming(fetch("jassub-worker-modern.wasm"),Ze):WebAssembly.instantiate(p.wasm,Ze)).then(function(t){C=(t.instance||t).exports,p._malloc=We=C.N,J=C.O,Ne=C.P,p.__embind_initialize_bindings=C.Q,me=C.S,et=C.T,tt=C.U,Ce=C.V,we=C.W,C.X,C.Y,C.Z,C._,ue=C.R,Ir(C),S()}),p.ready};const read_=(o,p)=>{const v=new XMLHttpRequest;return v.open("GET",o,!1),v.responseType=p?"arraybuffer":"text",v.send(null),v.response},readAsync=(o,p,v)=>{const $=new XMLHttpRequest;$.open("GET",o,!0),$.responseType="arraybuffer",$.onload=()=>{if(($.status===200||$.status===0)&&$.response)return p($.response)},$.onerror=v,$.send(null)};Date.now||(Date.now=()=>new Date().getTime());"performance"in self||(self.performance={now:()=>Date.now()});if(typeof console>"u"){const o=(p,v)=>{postMessage({target:"console",command:p,content:JSON.stringify(Array.prototype.slice.call(v))})};self.console={log:function(){o("log",arguments)},debug:function(){o("debug",arguments)},info:function(){o("info",arguments)},warn:function(){o("warn",arguments)},error:function(){o("error",arguments)}},console.log("Detected lack of console, overridden console")}let lastCurrentTime=0;const rate=1;let rafId=null,nextIsRaf=!1,lastCurrentTimeReceivedAt=Date.now(),targetFps=24,useLocalFonts=!1,blendMode="js",availableFonts={};const fontMap_={};let fontId=0,debug;self.width=0;self.height=0;let asyncRender=!1;self.addFont=({font:o})=>asyncWrite(o);const findAvailableFonts=o=>{o=o.trim().toLowerCase(),o.startsWith("@")&&(o=o.substring(1)),!fontMap_[o]&&(fontMap_[o]=!0,availableFonts[o]?asyncWrite(availableFonts[o]):useLocalFonts&&postMessage({target:"getLocalFont",font:o}))},asyncWrite=o=>{typeof o=="string"?readAsync(o,p=>{allocFont(new Uint8Array(p))},console.error):allocFont(o)},allocFont=o=>{const p=_malloc(o.byteLength);self.HEAPU8.set(o,p),jassubObj.addFont("font-"+fontId++,p,o.byteLength),jassubObj.reloadFonts()},processAvailableFonts=o=>{if(!availableFonts)return;const p=parseAss(o);for(let m=0;m<p.length;m++)for(let S=0;S<p[m].body.length;S++)p[m].body[S].key==="Style"&&findAvailableFonts(p[m].body[S].value.Fontname);const v=/\\fn([^\\}]*?)[\\}]/g;let $;for(;($=v.exec(o))!==null;)findAvailableFonts($[1])};self.setTrack=({content:o})=>{processAvailableFonts(o),dropAllBlur&&(o=dropBlur(o)),jassubObj.createTrackMem(o),subtitleColorSpace=libassYCbCrMap[jassubObj.trackColorSpace],postMessage({target:"verifyColorSpace",subtitleColorSpace})};self.getColorSpace=()=>postMessage({target:"verifyColorSpace",subtitleColorSpace});self.freeTrack=()=>{jassubObj.removeTrack()};self.setTrackByUrl=({url:o})=>{self.setTrack({content:read_(o)})};const getCurrentTime=()=>{const o=(Date.now()-lastCurrentTimeReceivedAt)/1e3;return _isPaused?lastCurrentTime:(o>5&&(console.error("Didn't received currentTime > 5 seconds. Assuming video was paused."),setIsPaused(!0)),lastCurrentTime+o*rate)},setCurrentTime=o=>{lastCurrentTime=o,lastCurrentTimeReceivedAt=Date.now(),rafId||(nextIsRaf?rafId=requestAnimationFrame(renderLoop):(renderLoop(),setTimeout(()=>{nextIsRaf=!1},20)))};let _isPaused=!0;const setIsPaused=o=>{o!==_isPaused&&(_isPaused=o,o?rafId&&(clearTimeout(rafId),rafId=null):(lastCurrentTimeReceivedAt=Date.now(),rafId=requestAnimationFrame(renderLoop)))},a="BT601",b="BT709",c="SMPTE240M",d="FCC",libassYCbCrMap=[null,a,null,a,a,b,b,c,c,d,d],render=(o,p)=>{const v={},$=performance.now(),m=blendMode==="wasm"?jassubObj.renderBlend(o,p||0):jassubObj.renderImage(o,p||0);if(debug){const S=performance.now(),F=jassubObj.time;v.WASMRenderTime=F-$,v.WASMBitmapDecodeTime=S-F,v.JSRenderTime=Date.now()}if(jassubObj.changed!==0||p){const S=[],F=[];if(!m)return paintImages({images:S,buffers:F,times:v});if(asyncRender){const C=[];for(let A=m,j=0;j<jassubObj.count;A=A.next,++j){const E={w:A.w,h:A.h,x:A.x,y:A.y},k=A.image,O=hasBitmapBug?self.HEAPU8C.slice(k,k+E.w*E.h*4):self.HEAPU8C.subarray(k,k+E.w*E.h*4);C.push(createImageBitmap(new ImageData(O,E.w,E.h))),S.push(E)}Promise.all(C).then(A=>{for(let j=0;j<S.length;j++)S[j].image=A[j];debug&&(v.JSBitmapGenerationTime=Date.now()-v.JSRenderTime),paintImages({images:S,buffers:A,times:v})})}else{for(let C=m,A=0;A<jassubObj.count;C=C.next,++A){const j={w:C.w,h:C.h,x:C.x,y:C.y,image:C.image};if(!offCanvasCtx){const E=self.wasmMemory.buffer.slice(C.image,C.image+C.w*C.h*4);F.push(E),j.image=E}S.push(j)}paintImages({images:S,buffers:F,times:v})}}else postMessage({target:"unbusy"})};self.demand=({time:o})=>{lastCurrentTime=o,render(o)};const renderLoop=o=>{rafId=0,render(getCurrentTime(),o),_isPaused||(rafId=requestAnimationFrame(renderLoop))},paintImages=({times:o,images:p,buffers:v})=>{const $={target:"render",asyncRender,images:p,times:o,width:self.width,height:self.height,colorSpace:subtitleColorSpace};if(offscreenRender){(offCanvas.height!==self.height||offCanvas.width!==self.width)&&(offCanvas.width=self.width,offCanvas.height=self.height),offCanvasCtx.clearRect(0,0,self.width,self.height);for(const m of p)m.image&&(asyncRender?(offCanvasCtx.drawImage(m.image,m.x,m.y),m.image.close()):(bufferCanvas.width=m.w,bufferCanvas.height=m.h,bufferCtx.putImageData(new ImageData(self.HEAPU8C.subarray(m.image,m.image+m.w*m.h*4),m.w,m.h),0,0),offCanvasCtx.drawImage(bufferCanvas,m.x,m.y)));if(offscreenRender==="hybrid"){if(!p.length)return postMessage($);debug&&(o.bitmaps=p.length);try{const m=offCanvas.transferToImageBitmap();$.images=[{image:m,x:0,y:0}],$.asyncRender=!0,postMessage($,[m])}catch{postMessage({target:"unbusy"})}}else{if(debug){o.JSRenderTime=Date.now()-o.JSRenderTime-(o.JSBitmapGenerationTime||0);let m=0;for(const S in o)m+=o[S];console.log("Bitmaps: "+p.length+" Total: "+(m|0)+"ms",o)}postMessage({target:"unbusy"})}}else postMessage($,v)},parseAss=o=>{let p,v,$,m,S,F,C,A,j,E;const k=[],O=o.split(/[\r\n]+/g);for(A=0;A<O.length;A++)if(p=O[A].match(/^\[(.*)\]$/),p)v=null,k.push({name:p[1],body:[]});else{if(/^\s*$/.test(O[A])||k.length===0)continue;if(E=k[k.length-1].body,O[A][0]===";")E.push({type:"comment",value:O[A].substring(1)});else{if(m=O[A].split(":"),S=m[0],F=m.slice(1).join(":").trim(),(v||S==="Format")&&(F=F.split(","),v&&F.length>v.length&&($=F.slice(v.length-1).join(","),F=F.slice(0,v.length-1),F.push($)),F=F.map(G=>G.trim()),v)){for(C={},j=0;j<F.length;j++)C[v[j]]=F[j];F=C}S==="Format"&&(v=F),E.push({key:S,value:F})}}return k},blurRegex=/\\blur(?:[0-9]+\.)?[0-9]+/gm,dropBlur=o=>o.replace(blurRegex,""),requestAnimationFrame=(()=>{let o=0;return p=>{const v=Date.now();if(o===0)o=v+1e3/targetFps;else for(;v+2>=o;)o+=1e3/targetFps;const $=Math.max(o-v,0);return setTimeout(p,$)}})(),_applyKeys=(o,p)=>{for(const v of Object.keys(o))p[v]=o[v]};let offCanvas,offCanvasCtx,offscreenRender,bufferCanvas,bufferCtx,jassubObj,subtitleColorSpace,dropAllBlur,_malloc,hasBitmapBug;self.init=data=>{hasBitmapBug=data.hasBitmapBug;try{const o=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(!(o instanceof WebAssembly.Module)||!(new WebAssembly.Instance(o)instanceof WebAssembly.Instance))throw new Error("WASM not supported")}catch(e){console.warn(e),eval(read_(data.legacyWasmUrl))}if(WebAssembly.instantiateStreaming){const o=self.fetch;self.fetch=p=>o(data.wasmUrl)}Module({wasm:!WebAssembly.instantiateStreaming&&read_(data.wasmUrl,!0)}).then(o=>{_malloc=o._malloc,self.width=data.width,self.height=data.height,blendMode=data.blendMode,asyncRender=data.asyncRender,asyncRender&&typeof createImageBitmap>"u"&&(asyncRender=!1,console.error("'createImageBitmap' needed for 'asyncRender' unsupported!")),availableFonts=data.availableFonts,debug=data.debug,targetFps=data.targetFps||targetFps,useLocalFonts=data.useLocalFonts,dropAllBlur=data.dropAllBlur;const p=data.fallbackFont.toLowerCase();jassubObj=new o.JASSUB(self.width,self.height,p||null,debug),p&&findAvailableFonts(p);let v=data.subContent;v||(v=read_(data.subUrl)),processAvailableFonts(v),dropAllBlur&&(v=dropBlur(v));for(const $ of data.fonts||[])asyncWrite($);jassubObj.createTrackMem(v),subtitleColorSpace=libassYCbCrMap[jassubObj.trackColorSpace],jassubObj.setDropAnimations(data.dropAllAnimations||0),(data.libassMemoryLimit>0||data.libassGlyphLimit>0)&&jassubObj.setMemoryLimits(data.libassGlyphLimit||0,data.libassMemoryLimit||0),postMessage({target:"ready"}),postMessage({target:"verifyColorSpace",subtitleColorSpace})})};self.offscreenCanvas=({transferable:o})=>{offCanvas=o[0],offCanvasCtx=offCanvas.getContext("2d"),asyncRender||(bufferCanvas=new OffscreenCanvas(self.height,self.width),bufferCtx=bufferCanvas.getContext("2d",{desynchronized:!0})),offscreenRender=!0};self.detachOffscreen=()=>{offCanvas=new OffscreenCanvas(self.height,self.width),offCanvasCtx=offCanvas.getContext("2d",{desynchronized:!0}),offscreenRender="hybrid"};self.canvas=({width:o,height:p,force:v})=>{if(o==null)throw new Error("Invalid canvas size specified");self.width=o,self.height=p,jassubObj&&jassubObj.resizeCanvas(o,p),v&&render(lastCurrentTime,!0)};self.video=({currentTime:o,isPaused:p,rate:v})=>{o!=null&&setCurrentTime(o),p!=null&&setIsPaused(p),v=v||v};self.destroy=()=>{jassubObj.quitLibrary()};self.createEvent=({event:o})=>{_applyKeys(o,jassubObj.getEvent(jassubObj.allocEvent()))};self.getEvents=()=>{const o=[];for(let p=0;p<jassubObj.getEventCount();p++){const{Start:v,Duration:$,ReadOrder:m,Layer:S,Style:F,MarginL:C,MarginR:A,MarginV:j,Name:E,Text:k,Effect:O}=jassubObj.getEvent(p);o.push({Start:v,Duration:$,ReadOrder:m,Layer:S,Style:F,MarginL:C,MarginR:A,MarginV:j,Name:E,Text:k,Effect:O})}postMessage({target:"getEvents",events:o})};self.setEvent=({event:o,index:p})=>{_applyKeys(o,jassubObj.getEvent(p))};self.removeEvent=({index:o})=>{jassubObj.removeEvent(o)};self.createStyle=({style:o})=>{_applyKeys(o,jassubObj.getStyle(jassubObj.allocStyle()))};self.getStyles=()=>{const o=[];for(let p=0;p<jassubObj.getStyleCount();p++){const{Name:v,FontName:$,FontSize:m,PrimaryColour:S,SecondaryColour:F,OutlineColour:C,BackColour:A,Bold:j,Italic:E,Underline:k,StrikeOut:O,ScaleX:G,ScaleY:R,Spacing:le,Angle:fe,BorderStyle:B,Outline:ue,Shadow:Y,Alignment:ce,MarginL:de,MarginR:X,MarginV:_e,Encoding:$e,treat_fontname_as_pattern:Te,Blur:Pe,Justify:Ae}=jassubObj.getStyle(p);o.push({Name:v,FontName:$,FontSize:m,PrimaryColour:S,SecondaryColour:F,OutlineColour:C,BackColour:A,Bold:j,Italic:E,Underline:k,StrikeOut:O,ScaleX:G,ScaleY:R,Spacing:le,Angle:fe,BorderStyle:B,Outline:ue,Shadow:Y,Alignment:ce,MarginL:de,MarginR:X,MarginV:_e,Encoding:$e,treat_fontname_as_pattern:Te,Blur:Pe,Justify:Ae})}postMessage({target:"getStyles",time:Date.now(),styles:o})};self.setStyle=({style:o,index:p})=>{_applyKeys(o,jassubObj.getStyle(p))};self.removeStyle=({index:o})=>{jassubObj.removeStyle(o)};onmessage=({data:o})=>{if(self[o.target])self[o.target](o);else throw new Error("Unknown event target "+o.target)};
|
package/dist/jassub.es.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
}, HTMLVideoElement.prototype.cancelVideoFrameCallback = function(c) {
|
|
20
20
|
cancelAnimationFrame(this._rvfcpolyfillmap[c]), delete this._rvfcpolyfillmap[c];
|
|
21
21
|
});
|
|
22
|
-
const
|
|
22
|
+
const _ = {
|
|
23
23
|
bt709: "BT709",
|
|
24
24
|
// these might not be exactly correct? oops?
|
|
25
25
|
bt470bg: "BT601",
|
|
@@ -83,7 +83,7 @@ class h extends EventTarget {
|
|
|
83
83
|
});
|
|
84
84
|
const t = h._test();
|
|
85
85
|
if (this._onDemandRender = "requestVideoFrameCallback" in HTMLVideoElement.prototype && (e.onDemandRender ?? !0), this._offscreenRender = "transferControlToOffscreen" in HTMLCanvasElement.prototype && !e.canvas && (e.offscreenRender ?? !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)
|
|
86
|
-
this._canvasParent = document.createElement("div"), this._canvasParent.className = "JASSUB", this._canvasParent.style.position = "relative", this._canvas = this._createCanvas(), this._video.
|
|
86
|
+
this._canvasParent = document.createElement("div"), this._canvasParent.className = "JASSUB", this._canvasParent.style.position = "relative", this._canvas = this._createCanvas(), this._video.insertAdjacentElement("afterend", this._canvasParent);
|
|
87
87
|
else if (!this._canvas)
|
|
88
88
|
throw this.destroy("Don't know where to render: you should give video or canvas in options.");
|
|
89
89
|
if (this._bufferCanvas = document.createElement("canvas"), this._bufferCtx = this._bufferCanvas.getContext("2d"), !this._bufferCtx)
|
|
@@ -141,8 +141,8 @@ class h extends EventTarget {
|
|
|
141
141
|
new ImageData(new Uint8ClampedArray([0, 0, 0, 0]), 1, 1);
|
|
142
142
|
} catch {
|
|
143
143
|
console.log("Detected that ImageData is not constructable despite browser saying so"), self.ImageData = function(o, d, l) {
|
|
144
|
-
const
|
|
145
|
-
return o &&
|
|
144
|
+
const m = t.createImageData(d, l);
|
|
145
|
+
return o && m.data.set(o), m;
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
148
|
const s = document.createElement("canvas"), a = s.getContext("2d", { willReadFrequently: !0 });
|
|
@@ -432,7 +432,7 @@ class h extends EventTarget {
|
|
|
432
432
|
this._video.requestVideoFrameCallback(() => {
|
|
433
433
|
try {
|
|
434
434
|
const e = new VideoFrame(this._video);
|
|
435
|
-
this._videoColorSpace =
|
|
435
|
+
this._videoColorSpace = _[e.colorSpace.matrix], e.close(), this.sendMessage("getColorSpace");
|
|
436
436
|
} catch (e) {
|
|
437
437
|
console.warn(e);
|
|
438
438
|
}
|
package/dist/jassub.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,m){typeof exports=="object"&&typeof module<"u"?module.exports=m():typeof define=="function"&&define.amd?define(m):(c=typeof globalThis<"u"?globalThis:c||self,c.JASSUB=m())})(this,function(){"use strict";!("requestVideoFrameCallback"in HTMLVideoElement.prototype)&&"getVideoPlaybackQuality"in HTMLVideoElement.prototype&&(HTMLVideoElement.prototype._rvfcpolyfillmap={},HTMLVideoElement.prototype.requestVideoFrameCallback=function(_){const e=performance.now(),t=this.getVideoPlaybackQuality(),s=this.mozPresentedFrames||this.mozPaintedFrames||t.totalVideoFrames-t.droppedVideoFrames,a=(n,r)=>{const i=this.getVideoPlaybackQuality(),h=this.mozPresentedFrames||this.mozPaintedFrames||i.totalVideoFrames-i.droppedVideoFrames;if(h>s){const d=this.mozFrameDelay||i.totalFrameDelay-t.totalFrameDelay||0,l=r-n;_(r,{presentationTime:r+d*1e3,expectedDisplayTime:r+l,width:this.videoWidth,height:this.videoHeight,mediaTime:Math.max(0,this.currentTime||0)+l/1e3,presentedFrames:h,processingDuration:d}),delete this._rvfcpolyfillmap[e]}else this._rvfcpolyfillmap[e]=requestAnimationFrame(d=>a(r,d))};return this._rvfcpolyfillmap[e]=requestAnimationFrame(n=>a(e,n)),e},HTMLVideoElement.prototype.cancelVideoFrameCallback=function(_){cancelAnimationFrame(this._rvfcpolyfillmap[_]),delete this._rvfcpolyfillmap[_]});const c={bt709:"BT709",bt470bg:"BT601",smpte170m:"BT601"},m={BT601:{BT709:"1.0863 -0.0723 -0.014 0 0 0.0965 0.8451 0.0584 0 0 -0.0141 -0.0277 1.0418"},BT709:{BT601:"0.9137 0.0784 0.0079 0 0 -0.1049 1.1722 -0.0671 0 0 0.0096 0.0322 0.9582"},FCC:{BT709:"1.0873 -0.0736 -0.0137 0 0 0.0974 0.8494 0.0531 0 0 -0.0127 -0.0251 1.0378",BT601:"1.001 -0.0008 -0.0002 0 0 0.0009 1.005 -0.006 0 0 0.0013 0.0027 0.996"},SMPTE240M:{BT709:"0.9993 0.0006 0.0001 0 0 -0.0004 0.9812 0.0192 0 0 -0.0034 -0.0114 1.0148",BT601:"0.913 0.0774 0.0096 0 0 -0.1051 1.1508 -0.0456 0 0 0.0063 0.0207 0.973"}};class o extends EventTarget{constructor(e){if(super(),!globalThis.Worker)throw this.destroy("Worker not supported");if(!e)throw this.destroy("No options provided");this._loaded=new Promise(s=>{this._init=s});const t=o._test();if(this._onDemandRender="requestVideoFrameCallback"in HTMLVideoElement.prototype&&(e.onDemandRender??!0),this._offscreenRender="transferControlToOffscreen"in HTMLCanvasElement.prototype&&!e.canvas&&(e.offscreenRender??!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=this._createCanvas(),this._video.nextSibling?this._video.parentNode.insertBefore(this._canvasParent,this._video.nextSibling):this._video.parentNode.appendChild(this._canvasParent);else if(!this._canvas)throw this.destroy("Don't know where to render: you should give video or canvas in options.");if(this._bufferCanvas=document.createElement("canvas"),this._bufferCtx=this._bufferCanvas.getContext("2d"),!this._bufferCtx)throw this.destroy("Canvas rendering not supported");this._canvasctrl=this._offscreenRender?this._canvas.transferControlToOffscreen():this._canvas,this._ctx=!this._offscreenRender&&this._canvasctrl.getContext("2d"),this._lastRenderTime=0,this.debug=!!e.debug,this.prescaleFactor=e.prescaleFactor||1,this.prescaleHeightLimit=e.prescaleHeightLimit||1080,this.maxRenderHeight=e.maxRenderHeight||0,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),this._worker=new Worker(e.workerUrl||"jassub-worker.js"),this._worker.onmessage=s=>this._onmessage(s),this._worker.onerror=s=>this._error(s),t.then(()=>{this._worker.postMessage({target:"init",wasmUrl:o._supportsSIMD&&e.modernWasmUrl?e.modernWasmUrl:e.wasmUrl||"jassub-worker.wasm",legacyWasmUrl:e.legacyWasmUrl||"jassub-worker.wasm.js",asyncRender:typeof createImageBitmap<"u"&&(e.asyncRender??!0),onDemandRender:this._onDemandRender,width:this._canvasctrl.width||0,height:this._canvasctrl.height||0,blendMode:e.blendMode||"js",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,dropAllBlur:e.dropAllBlur,libassMemoryLimit:e.libassMemoryLimit||0,libassGlyphLimit:e.libassGlyphLimit||0,useLocalFonts:typeof queryLocalFonts<"u"&&(e.useLocalFonts??!0),hasBitmapBug:o._hasBitmapBug}),this._offscreenRender===!0&&this.sendMessage("offscreenCanvas",null,[this._canvasctrl])})}_createCanvas(){return 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._canvas}static _supportsSIMD=null;static _hasAlphaBug=null;static _hasBitmapBug=null;static async _test(){if(o._hasBitmapBug!==null)return null;try{o._supportsSIMD=WebAssembly.validate(Uint8Array.of(0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11))}catch{o._supportsSIMD=!1}const e=document.createElement("canvas"),t=e.getContext("2d",{willReadFrequently:!0});if(!t)throw new Error("Canvas rendering not supported");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(h,d,l){const f=t.createImageData(d,l);return h&&f.data.set(h),f}}const s=document.createElement("canvas"),a=s.getContext("2d",{willReadFrequently:!0});if(!a)throw new Error("Canvas rendering not supported");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;if(o._hasAlphaBug=n[1]!==r[1],o._hasAlphaBug&&console.log("Detected a browser having issue with transparent pixels, applying workaround"),typeof createImageBitmap<"u"){const i=new Uint8ClampedArray([255,0,255,0,255]).subarray(1,5);a.drawImage(await createImageBitmap(new ImageData(i,1)),0,0);const{data:h}=a.getImageData(0,0,1,1);o._hasBitmapBug=!1;for(const[d,l]of h.entries())if(Math.abs(i[d]-l)>15){o._hasBitmapBug=!0,console.log("Detected a browser having issue with partial bitmaps, applying workaround");break}}else o._hasBitmapBug=!1;e.remove(),s.remove()}resize(e=0,t=0,s=0,a=0,n=this._video?.paused){if((!e||!t)&&this._video){const r=this._getVideoPosition();let i=null;if(this._videoWidth){const h=this._video.videoWidth/this._videoWidth,d=this._video.videoHeight/this._videoHeight;i=this._computeCanvasSize((r.width||0)/h,(r.height||0)/d)}else i=this._computeCanvasSize(r.width||0,r.height||0);e=i.width,t=i.height,this._canvasParent&&(s=r.y-(this._canvasParent.getBoundingClientRect().top-this._video.getBoundingClientRect().top),a=r.x),this._canvas.style.width=r.width+"px",this._canvas.style.height=r.height+"px"}this._canvas.style.top=s+"px",this._canvas.style.left=a+"px",n&&this.busy===!1?this.busy=!0:n=!1,this.sendMessage("canvas",{width:e,height:t,force:n})}_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,h=(n-t)/2;return{width:e,height:t,x:i,y:h}}_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,!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!")}runBenchmark(){this.sendMessage("runBenchmark")}setTrackByUrl(e){this.sendMessage("setTrackByUrl",{url:e}),this._reAttachOffscreen(),this._ctx&&(this._ctx.filter="none")}setTrack(e){this.sendMessage("setTrack",{content:e}),this._reAttachOffscreen(),this._ctx&&(this._ctx.filter="none")}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,colorSpace:this._videoColorSpace})}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?.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}){try{navigator?.permissions?.query?navigator.permissions.query({name:"local-fonts"}).then(t=>{t.state==="granted"&&this._sendLocalFont(e)}):this._sendLocalFont(e)}catch(t){console.warn("Local fonts API:",t)}}_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})}_detachOffscreen(){if(!this._offscreenRender||this._ctx)return null;this._canvas.remove(),this._createCanvas(),this._canvasctrl=this._canvas,this._ctx=this._canvasctrl.getContext("2d"),this.sendMessage("detachOffscreen"),this.busy=!1,this.resize(0,0,0,0,!0)}_reAttachOffscreen(){if(!this._offscreenRender||!this._ctx)return null;this._canvas.remove(),this._createCanvas(),this._canvasctrl=this._canvas.transferControlToOffscreen(),this._ctx=!1,this.sendMessage("offscreenCanvas",null,[this._canvasctrl]),this.resize(0,0,0,0,!0)}_updateColorSpace(){this._video.requestVideoFrameCallback(()=>{try{const e=new VideoFrame(this._video);this._videoColorSpace=c[e.colorSpace.matrix],e.close(),this.sendMessage("getColorSpace")}catch(e){console.warn(e)}})}_verifyColorSpace({subtitleColorSpace:e,videoColorSpace:t=this._videoColorSpace}){!e||!t||e!==t&&(this._detachOffscreen(),this._ctx.filter=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='f'><feColorMatrix type='matrix' values='${m[e][t]} 0 0 0 0 0 1 0'/></filter></svg>#f")`)}_render({images:e,asyncRender:t,times:s,width:a,height:n,colorSpace:r}){this._unbusy(),this.debug&&(s.IPCTime=Date.now()-s.JSRenderTime),(this._canvasctrl.width!==a||this._canvasctrl.height!==n)&&(this._canvasctrl.width=a,this._canvasctrl.height=n,this._verifyColorSpace({subtitleColorSpace:r})),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.JSRenderTime=Date.now()-s.JSRenderTime-s.IPCTime;let i=0;const h=s.bitmaps||e.length;delete s.bitmaps;for(const d in s)i+=s[d];console.log("Bitmaps: "+h+" Total: "+(i|0)+"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});return this.dispatchEvent(s),console.error(t),t}_removeListeners(){this._video&&(this._ro&&this._ro.unobserve(this._video),this._ctx&&(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))}destroy(e){return 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(),e}}return o});
|
|
1
|
+
(function(c,m){typeof exports=="object"&&typeof module<"u"?module.exports=m():typeof define=="function"&&define.amd?define(m):(c=typeof globalThis<"u"?globalThis:c||self,c.JASSUB=m())})(this,function(){"use strict";!("requestVideoFrameCallback"in HTMLVideoElement.prototype)&&"getVideoPlaybackQuality"in HTMLVideoElement.prototype&&(HTMLVideoElement.prototype._rvfcpolyfillmap={},HTMLVideoElement.prototype.requestVideoFrameCallback=function(_){const e=performance.now(),t=this.getVideoPlaybackQuality(),s=this.mozPresentedFrames||this.mozPaintedFrames||t.totalVideoFrames-t.droppedVideoFrames,a=(n,r)=>{const i=this.getVideoPlaybackQuality(),h=this.mozPresentedFrames||this.mozPaintedFrames||i.totalVideoFrames-i.droppedVideoFrames;if(h>s){const d=this.mozFrameDelay||i.totalFrameDelay-t.totalFrameDelay||0,l=r-n;_(r,{presentationTime:r+d*1e3,expectedDisplayTime:r+l,width:this.videoWidth,height:this.videoHeight,mediaTime:Math.max(0,this.currentTime||0)+l/1e3,presentedFrames:h,processingDuration:d}),delete this._rvfcpolyfillmap[e]}else this._rvfcpolyfillmap[e]=requestAnimationFrame(d=>a(r,d))};return this._rvfcpolyfillmap[e]=requestAnimationFrame(n=>a(e,n)),e},HTMLVideoElement.prototype.cancelVideoFrameCallback=function(_){cancelAnimationFrame(this._rvfcpolyfillmap[_]),delete this._rvfcpolyfillmap[_]});const c={bt709:"BT709",bt470bg:"BT601",smpte170m:"BT601"},m={BT601:{BT709:"1.0863 -0.0723 -0.014 0 0 0.0965 0.8451 0.0584 0 0 -0.0141 -0.0277 1.0418"},BT709:{BT601:"0.9137 0.0784 0.0079 0 0 -0.1049 1.1722 -0.0671 0 0 0.0096 0.0322 0.9582"},FCC:{BT709:"1.0873 -0.0736 -0.0137 0 0 0.0974 0.8494 0.0531 0 0 -0.0127 -0.0251 1.0378",BT601:"1.001 -0.0008 -0.0002 0 0 0.0009 1.005 -0.006 0 0 0.0013 0.0027 0.996"},SMPTE240M:{BT709:"0.9993 0.0006 0.0001 0 0 -0.0004 0.9812 0.0192 0 0 -0.0034 -0.0114 1.0148",BT601:"0.913 0.0774 0.0096 0 0 -0.1051 1.1508 -0.0456 0 0 0.0063 0.0207 0.973"}};class o extends EventTarget{constructor(e){if(super(),!globalThis.Worker)throw this.destroy("Worker not supported");if(!e)throw this.destroy("No options provided");this._loaded=new Promise(s=>{this._init=s});const t=o._test();if(this._onDemandRender="requestVideoFrameCallback"in HTMLVideoElement.prototype&&(e.onDemandRender??!0),this._offscreenRender="transferControlToOffscreen"in HTMLCanvasElement.prototype&&!e.canvas&&(e.offscreenRender??!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=this._createCanvas(),this._video.insertAdjacentElement("afterend",this._canvasParent);else if(!this._canvas)throw this.destroy("Don't know where to render: you should give video or canvas in options.");if(this._bufferCanvas=document.createElement("canvas"),this._bufferCtx=this._bufferCanvas.getContext("2d"),!this._bufferCtx)throw this.destroy("Canvas rendering not supported");this._canvasctrl=this._offscreenRender?this._canvas.transferControlToOffscreen():this._canvas,this._ctx=!this._offscreenRender&&this._canvasctrl.getContext("2d"),this._lastRenderTime=0,this.debug=!!e.debug,this.prescaleFactor=e.prescaleFactor||1,this.prescaleHeightLimit=e.prescaleHeightLimit||1080,this.maxRenderHeight=e.maxRenderHeight||0,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),this._worker=new Worker(e.workerUrl||"jassub-worker.js"),this._worker.onmessage=s=>this._onmessage(s),this._worker.onerror=s=>this._error(s),t.then(()=>{this._worker.postMessage({target:"init",wasmUrl:o._supportsSIMD&&e.modernWasmUrl?e.modernWasmUrl:e.wasmUrl||"jassub-worker.wasm",legacyWasmUrl:e.legacyWasmUrl||"jassub-worker.wasm.js",asyncRender:typeof createImageBitmap<"u"&&(e.asyncRender??!0),onDemandRender:this._onDemandRender,width:this._canvasctrl.width||0,height:this._canvasctrl.height||0,blendMode:e.blendMode||"js",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,dropAllBlur:e.dropAllBlur,libassMemoryLimit:e.libassMemoryLimit||0,libassGlyphLimit:e.libassGlyphLimit||0,useLocalFonts:typeof queryLocalFonts<"u"&&(e.useLocalFonts??!0),hasBitmapBug:o._hasBitmapBug}),this._offscreenRender===!0&&this.sendMessage("offscreenCanvas",null,[this._canvasctrl])})}_createCanvas(){return 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._canvas}static _supportsSIMD=null;static _hasAlphaBug=null;static _hasBitmapBug=null;static async _test(){if(o._hasBitmapBug!==null)return null;try{o._supportsSIMD=WebAssembly.validate(Uint8Array.of(0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11))}catch{o._supportsSIMD=!1}const e=document.createElement("canvas"),t=e.getContext("2d",{willReadFrequently:!0});if(!t)throw new Error("Canvas rendering not supported");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(h,d,l){const f=t.createImageData(d,l);return h&&f.data.set(h),f}}const s=document.createElement("canvas"),a=s.getContext("2d",{willReadFrequently:!0});if(!a)throw new Error("Canvas rendering not supported");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;if(o._hasAlphaBug=n[1]!==r[1],o._hasAlphaBug&&console.log("Detected a browser having issue with transparent pixels, applying workaround"),typeof createImageBitmap<"u"){const i=new Uint8ClampedArray([255,0,255,0,255]).subarray(1,5);a.drawImage(await createImageBitmap(new ImageData(i,1)),0,0);const{data:h}=a.getImageData(0,0,1,1);o._hasBitmapBug=!1;for(const[d,l]of h.entries())if(Math.abs(i[d]-l)>15){o._hasBitmapBug=!0,console.log("Detected a browser having issue with partial bitmaps, applying workaround");break}}else o._hasBitmapBug=!1;e.remove(),s.remove()}resize(e=0,t=0,s=0,a=0,n=this._video?.paused){if((!e||!t)&&this._video){const r=this._getVideoPosition();let i=null;if(this._videoWidth){const h=this._video.videoWidth/this._videoWidth,d=this._video.videoHeight/this._videoHeight;i=this._computeCanvasSize((r.width||0)/h,(r.height||0)/d)}else i=this._computeCanvasSize(r.width||0,r.height||0);e=i.width,t=i.height,this._canvasParent&&(s=r.y-(this._canvasParent.getBoundingClientRect().top-this._video.getBoundingClientRect().top),a=r.x),this._canvas.style.width=r.width+"px",this._canvas.style.height=r.height+"px"}this._canvas.style.top=s+"px",this._canvas.style.left=a+"px",n&&this.busy===!1?this.busy=!0:n=!1,this.sendMessage("canvas",{width:e,height:t,force:n})}_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,h=(n-t)/2;return{width:e,height:t,x:i,y:h}}_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,!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!")}runBenchmark(){this.sendMessage("runBenchmark")}setTrackByUrl(e){this.sendMessage("setTrackByUrl",{url:e}),this._reAttachOffscreen(),this._ctx&&(this._ctx.filter="none")}setTrack(e){this.sendMessage("setTrack",{content:e}),this._reAttachOffscreen(),this._ctx&&(this._ctx.filter="none")}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,colorSpace:this._videoColorSpace})}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?.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}){try{navigator?.permissions?.query?navigator.permissions.query({name:"local-fonts"}).then(t=>{t.state==="granted"&&this._sendLocalFont(e)}):this._sendLocalFont(e)}catch(t){console.warn("Local fonts API:",t)}}_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})}_detachOffscreen(){if(!this._offscreenRender||this._ctx)return null;this._canvas.remove(),this._createCanvas(),this._canvasctrl=this._canvas,this._ctx=this._canvasctrl.getContext("2d"),this.sendMessage("detachOffscreen"),this.busy=!1,this.resize(0,0,0,0,!0)}_reAttachOffscreen(){if(!this._offscreenRender||!this._ctx)return null;this._canvas.remove(),this._createCanvas(),this._canvasctrl=this._canvas.transferControlToOffscreen(),this._ctx=!1,this.sendMessage("offscreenCanvas",null,[this._canvasctrl]),this.resize(0,0,0,0,!0)}_updateColorSpace(){this._video.requestVideoFrameCallback(()=>{try{const e=new VideoFrame(this._video);this._videoColorSpace=c[e.colorSpace.matrix],e.close(),this.sendMessage("getColorSpace")}catch(e){console.warn(e)}})}_verifyColorSpace({subtitleColorSpace:e,videoColorSpace:t=this._videoColorSpace}){!e||!t||e!==t&&(this._detachOffscreen(),this._ctx.filter=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='f'><feColorMatrix type='matrix' values='${m[e][t]} 0 0 0 0 0 1 0'/></filter></svg>#f")`)}_render({images:e,asyncRender:t,times:s,width:a,height:n,colorSpace:r}){this._unbusy(),this.debug&&(s.IPCTime=Date.now()-s.JSRenderTime),(this._canvasctrl.width!==a||this._canvasctrl.height!==n)&&(this._canvasctrl.width=a,this._canvasctrl.height=n,this._verifyColorSpace({subtitleColorSpace:r})),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.JSRenderTime=Date.now()-s.JSRenderTime-s.IPCTime;let i=0;const h=s.bitmaps||e.length;delete s.bitmaps;for(const d in s)i+=s[d];console.log("Bitmaps: "+h+" Total: "+(i|0)+"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});return this.dispatchEvent(s),console.error(t),t}_removeListeners(){this._video&&(this._ro&&this._ro.unobserve(this._video),this._ctx&&(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))}destroy(e){return 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(),e}}return o});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jassub",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.5",
|
|
4
4
|
"description": "libass Subtitle Renderer and Parser library for browsers",
|
|
5
5
|
"main": "src/jassub.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"rvfc-polyfill": "^1.0.6"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
+
"@types/emscripten": "^1.39.7",
|
|
35
36
|
"terser": "^5.19.4",
|
|
36
37
|
"vite": "^4.4.9",
|
|
37
38
|
"vite-plugin-static-copy": "^0.17.0"
|
package/src/jassub.js
CHANGED
|
@@ -86,11 +86,7 @@ export default class JASSUB extends EventTarget {
|
|
|
86
86
|
|
|
87
87
|
this._canvas = this._createCanvas()
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
this._video.parentNode.insertBefore(this._canvasParent, this._video.nextSibling)
|
|
91
|
-
} else {
|
|
92
|
-
this._video.parentNode.appendChild(this._canvasParent)
|
|
93
|
-
}
|
|
89
|
+
this._video.insertAdjacentElement('afterend', this._canvasParent)
|
|
94
90
|
} else if (!this._canvas) {
|
|
95
91
|
throw this.destroy('Don\'t know where to render: you should give video or canvas in options.')
|
|
96
92
|
}
|