diff --git a/.gitignore b/.gitignore index ed16bba..6bdbe62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -/dist/ /node_modules/ /.idea/ diff --git a/dist/browserSupport.d.ts b/dist/browserSupport.d.ts new file mode 100644 index 0000000..752a8c7 --- /dev/null +++ b/dist/browserSupport.d.ts @@ -0,0 +1,15 @@ +import { PgsRendererMode } from "./pgsRendererMode"; +export declare class BrowserSupport { + /** + * Checks if the web worker is supported in the current environment. + */ + static isWorkerSupported(): boolean; + /** + * Checks if the offscreen-canvas and `transferControlToOffscreen` are supported in the current environment. + */ + static isOffscreenCanvasSupported(): boolean; + /** + * Returns the optimal PGS renderer mode for the current platform. + */ + static getRendererModeByPlatform(): PgsRendererMode; +} diff --git a/dist/libpgs.d.ts b/dist/libpgs.d.ts new file mode 100644 index 0000000..04c9c19 --- /dev/null +++ b/dist/libpgs.d.ts @@ -0,0 +1,4 @@ +import "core-js/stable/promise"; +import "whatwg-fetch"; +import { PgsRenderer } from "./pgsRenderer"; +export { PgsRenderer }; diff --git a/dist/libpgs.js b/dist/libpgs.js new file mode 100644 index 0000000..c1fcf0f --- /dev/null +++ b/dist/libpgs.js @@ -0,0 +1 @@ +var t,e,r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n={},i={};function o(){if(e)return t;e=1;var n=function(t){return t&&t.Math===Math&&t};return t=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof r&&r)||n("object"==typeof t&&t)||function(){return this}()||Function("return this")()}var a,u,s,c,f,h,p,d,l={};function v(){return u?a:(u=1,a=function(t){try{return!!t()}catch(t){return!0}})}function y(){if(c)return s;c=1;var t=v();return s=!t((function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]}))}function m(){if(h)return f;h=1;var t=v();return f=!t((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")}))}function b(){if(d)return p;d=1;var t=m(),e=Function.prototype.call;return p=t?e.bind(e):function(){return e.apply(e,arguments)},p}var g,w,O,T,S,P,j,E,A,I,U,x,R,D,C,B,k,_,F,L,N,M,$,H,W,q,G,V,z,J,X,Y,K,Z,Q,tt,et,rt,nt,it,ot,at={};function ut(){return O?w:(O=1,w=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}})}function st(){if(S)return T;S=1;var t=m(),e=Function.prototype,r=e.call,n=t&&e.bind.bind(r,r);return T=t?n:function(t){return function(){return r.apply(t,arguments)}},T}function ct(){if(j)return P;j=1;var t=st(),e=t({}.toString),r=t("".slice);return P=function(t){return r(e(t),8,-1)}}function ft(){return U?I:(U=1,I=function(t){return null==t})}function ht(){if(R)return x;R=1;var t=ft(),e=TypeError;return x=function(r){if(t(r))throw new e("Can't call method on "+r);return r}}function pt(){if(C)return D;C=1;var t=function(){if(A)return E;A=1;var t=st(),e=v(),r=ct(),n=Object,i=t("".split);return E=e((function(){return!n("z").propertyIsEnumerable(0)}))?function(t){return"String"===r(t)?i(t,""):n(t)}:n}(),e=ht();return D=function(r){return t(e(r))}}function dt(){if(k)return B;k=1;var t="object"==typeof document&&document.all;return B=void 0===t&&void 0!==t?function(e){return"function"==typeof e||e===t}:function(t){return"function"==typeof t}}function lt(){if(F)return _;F=1;var t=dt();return _=function(e){return"object"==typeof e?null!==e:t(e)}}function vt(){if(N)return L;N=1;var t=o(),e=dt();return L=function(r,n){return arguments.length<2?(i=t[r],e(i)?i:void 0):t[r]&&t[r][n];var i},L}function yt(){if($)return M;$=1;var t=st();return M=t({}.isPrototypeOf)}function mt(){if(W)return H;W=1;var t=o().navigator,e=t&&t.userAgent;return H=e?String(e):""}function bt(){if(G)return q;G=1;var t,e,r=o(),n=mt(),i=r.process,a=r.Deno,u=i&&i.versions||a&&a.version,s=u&&u.v8;return s&&(e=(t=s.split("."))[0]>0&&t[0]<4?1:+(t[0]+t[1])),!e&&n&&(!(t=n.match(/Edge\/(\d+)/))||t[1]>=74)&&(t=n.match(/Chrome\/(\d+)/))&&(e=+t[1]),q=e}function gt(){if(z)return V;z=1;var t=bt(),e=v(),r=o().String;return V=!!Object.getOwnPropertySymbols&&!e((function(){var e=Symbol("symbol detection");return!r(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&t&&t<41}))}function wt(){if(X)return J;X=1;var t=gt();return J=t&&!Symbol.sham&&"symbol"==typeof Symbol.iterator}function Ot(){if(K)return Y;K=1;var t=vt(),e=dt(),r=yt(),n=wt(),i=Object;return Y=n?function(t){return"symbol"==typeof t}:function(n){var o=t("Symbol");return e(o)&&r(o.prototype,i(n))}}function Tt(){if(Q)return Z;Q=1;var t=String;return Z=function(e){try{return t(e)}catch(t){return"Object"}}}function St(){if(et)return tt;et=1;var t=dt(),e=Tt(),r=TypeError;return tt=function(n){if(t(n))return n;throw new r(e(n)+" is not a function")}}function Pt(){if(nt)return rt;nt=1;var t=St(),e=ft();return rt=function(r,n){var i=r[n];return e(i)?void 0:t(i)}}function jt(){if(ot)return it;ot=1;var t=b(),e=dt(),r=lt(),n=TypeError;return it=function(i,o){var a,u;if("string"===o&&e(a=i.toString)&&!r(u=t(a,i)))return u;if(e(a=i.valueOf)&&!r(u=t(a,i)))return u;if("string"!==o&&e(a=i.toString)&&!r(u=t(a,i)))return u;throw new n("Can't convert object to primitive value")}}var Et,At,It,Ut,xt,Rt,Dt,Ct,Bt,kt,_t,Ft,Lt,Nt,Mt,$t,Ht,Wt,qt,Gt,Vt,zt,Jt,Xt,Yt={exports:{}};function Kt(){return At?Et:(At=1,Et=!1)}function Zt(){if(Ut)return It;Ut=1;var t=o(),e=Object.defineProperty;return It=function(r,n){try{e(t,r,{value:n,configurable:!0,writable:!0})}catch(e){t[r]=n}return n}}function Qt(){if(xt)return Yt.exports;xt=1;var t=Kt(),e=o(),r=Zt(),n="__core-js_shared__",i=Yt.exports=e[n]||r(n,{});return(i.versions||(i.versions=[])).push({version:"3.50.0",mode:t?"pure":"global",copyright:"© 2013–2025 Denis Pushkarev (zloirock.ru), 2025–2026 CoreJS Company (core-js.io). All rights reserved.",license:"https://github.com/zloirock/core-js/blob/v3.50.0/LICENSE",source:"https://github.com/zloirock/core-js"}),Yt.exports}function te(){if(Dt)return Rt;Dt=1;var t=Qt(),e=Object.create||Object;return Rt=function(r,n){return t[r]||(t[r]=n||e(null))}}function ee(){if(Bt)return Ct;Bt=1;var t=ht(),e=Object;return Ct=function(r){return e(t(r))}}function re(){if(_t)return kt;_t=1;var t=st(),e=ee(),r=t({}.hasOwnProperty);return kt=Object.hasOwn||function(t,n){return r(e(t),n)}}function ne(){if(Lt)return Ft;Lt=1;var t=st(),e=0,r=Math.random(),n=t(1.1.toString);return Ft=function(t){return"Symbol("+(void 0===t?"":t)+")_"+n(++e+r,36)}}function ie(){if(Mt)return Nt;Mt=1;var t=o(),e=te(),r=re(),n=ne(),i=gt(),a=wt(),u=t.Symbol,s=e("wks"),c=a?u.for||u:u&&u.withoutSetter||n;return Nt=function(t){return r(s,t)||(s[t]=i&&r(u,t)?u[t]:c("Symbol."+t)),s[t]}}function oe(){if(Ht)return $t;Ht=1;var t=b(),e=lt(),r=Ot(),n=Pt(),i=jt(),o=ie(),a=TypeError,u=o("toPrimitive");return $t=function(o,s){if(!e(o)||r(o))return o;var c,f=n(o,u);if(f){if(void 0===s&&(s="default"),c=t(f,o,s),!e(c)||r(c))return c;throw new a("Can't convert object to primitive value")}return void 0===s&&(s="number"),i(o,s)}}function ae(){if(qt)return Wt;qt=1;var t=oe(),e=Ot();return Wt=function(r){var n=t(r,"string");return e(n)?n:n+""}}function ue(){if(Vt)return Gt;Vt=1;var t=o(),e=lt(),r=t.document,n=e(r)&&e(r.createElement);return Gt=function(t){return n?r.createElement(t):{}}}function se(){if(Jt)return zt;Jt=1;var t=y(),e=v(),r=ue();return zt=!t&&!e((function(){return 7!==Object.defineProperty(r("div"),"a",{get:function(){return 7}}).a}))}function ce(){if(Xt)return l;Xt=1;var t=y(),e=b(),r=function(){if(g)return at;g=1;var t={}.propertyIsEnumerable,e=Object.getOwnPropertyDescriptor,r=e&&!t.call({1:2},1);return at.f=r?function(t){var r=e(this,t);return!!r&&r.enumerable}:t,at}(),n=ut(),i=pt(),o=ae(),a=re(),u=se(),s=Object.getOwnPropertyDescriptor;return l.f=t?s:function(t,c){if(t=i(t),c=o(c),u)try{return s(t,c)}catch(t){}if(a(t,c))return n(!e(r.f,t,c),t[c])},l}var fe,he,pe,de,le,ve,ye,me={};function be(){if(he)return fe;he=1;var t=y(),e=v();return fe=t&&e((function(){return 42!==Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype}))}function ge(){if(de)return pe;de=1;var t=lt(),e=String,r=TypeError;return pe=function(n){if(t(n))return n;throw new r(e(n)+" is not an object")}}function we(){if(le)return me;le=1;var t=y(),e=se(),r=be(),n=ge(),i=ae(),o=TypeError,a=Object.defineProperty,u=Object.getOwnPropertyDescriptor,s="enumerable",c="configurable",f="writable";return me.f=t?r?function(t,e,r){if(n(t),e=i(e),n(r),"function"==typeof t&&"prototype"===e&&"value"in r&&f in r&&!r[f]){var o=u(t,e);o&&o[f]&&(t[e]=r.value,r={configurable:c in r?r[c]:o[c],enumerable:s in r?r[s]:o[s],writable:!1})}return a(t,e,r)}:a:function(t,r,u){if(n(t),r=i(r),n(u),e)try{return a(t,r,u)}catch(t){}if("get"in u||"set"in u)throw new o("Accessors not supported");return"value"in u&&(t[r]=u.value),t},me}function Oe(){if(ye)return ve;ye=1;var t=y(),e=we(),r=ut();return ve=t?function(t,n,i){return e.f(t,n,r(1,i))}:function(t,e,r){return t[e]=r,t}}var Te,Se,Pe,je,Ee,Ae,Ie,Ue,xe,Re,De,Ce,Be,ke,_e,Fe={exports:{}};function Le(){if(Se)return Te;Se=1;var t=y(),e=re(),r=Function.prototype,n=t&&Object.getOwnPropertyDescriptor,i=e(r,"name"),o=i&&"something"===function(){}.name,a=i&&(!t||t&&n(r,"name").configurable);return Te={EXISTS:i,PROPER:o,CONFIGURABLE:a}}function Ne(){if(je)return Pe;je=1;var t=st(),e=dt(),r=Qt(),n=t(Function.toString);return e(r.inspectSource)||(r.inspectSource=function(t){return n(t)}),Pe=r.inspectSource}function Me(){if(Ue)return Ie;Ue=1;var t=te(),e=ne(),r=t("keys");return Ie=function(t){return r[t]||(r[t]=e(t))}}function $e(){return Re?xe:(Re=1,xe={})}function He(){if(Ce)return De;Ce=1;var t,e,r,n=function(){if(Ae)return Ee;Ae=1;var t=o(),e=dt(),r=t.WeakMap;return Ee=e(r)&&/native code/.test(String(r))}(),i=o(),a=lt(),u=Oe(),s=re(),c=Qt(),f=Me(),h=$e(),p="Object already initialized",d=i.TypeError,l=i.WeakMap;if(n||c.state){var v=c.state||(c.state=new l);v.get=v.get,v.has=v.has,v.set=v.set,t=function(t,e){if(v.has(t))throw new d(p);return e.facade=t,v.set(t,e),e},e=function(t){return v.get(t)||{}},r=function(t){return v.has(t)}}else{var y=f("state");h[y]=!0,t=function(t,e){if(s(t,y))throw new d(p);return e.facade=t,u(t,y,e),e},e=function(t){return s(t,y)?t[y]:{}},r=function(t){return s(t,y)}}return De={set:t,get:e,has:r,enforce:function(n){return r(n)?e(n):t(n,{})},getterFor:function(t){return function(r){var n;if(!a(r)||(n=e(r)).type!==t)throw new d("Incompatible receiver, "+t+" required");return n}}}}function We(){if(Be)return Fe.exports;Be=1;var t=st(),e=v(),r=dt(),n=re(),i=y(),o=Le().CONFIGURABLE,a=Ne(),u=He(),s=u.enforce,c=u.get,f=String,h=Object.defineProperty,p=t("".slice),d=t("".replace),l=t([].join),m=i&&!e((function(){return 8!==h((function(){}),"length",{value:8}).length})),b=String(String).split("String"),g=Fe.exports=function(t,e,r){"Symbol("===p(f(e),0,7)&&(e="["+d(f(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!n(t,"name")||o&&t.name!==e)&&(i?h(t,"name",{value:e,configurable:!0}):t.name=e),m&&r&&n(r,"arity")&&t.length!==r.arity&&h(t,"length",{value:r.arity});try{r&&n(r,"constructor")&&r.constructor?i&&h(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch(t){}var a=s(t);return n(a,"source")||(a.source=l(b,"string"==typeof e?e:"")),t};return Function.prototype.toString=g((function(){return r(this)&&c(this).source||a(this)}),"toString"),Fe.exports}function qe(){if(_e)return ke;_e=1;var t=dt(),e=we(),r=We(),n=Zt();return ke=function(i,o,a,u){u||(u={});var s=u.enumerable,c=void 0!==u.name?u.name:o;if(t(a)&&r(a,c,u),u.global)s?i[o]=a:n(o,a);else{try{u.unsafe?i[o]&&(s=!0):delete i[o]}catch(t){}s?i[o]=a:e.f(i,o,{value:a,enumerable:!1,configurable:!u.nonConfigurable,writable:!u.nonWritable})}return i}}var Ge,Ve,ze,Je,Xe,Ye,Ke,Ze,Qe,tr,er,rr,nr,ir,or,ar,ur,sr={};function cr(){if(Je)return ze;Je=1;var t=function(){if(Ve)return Ge;Ve=1;var t=Math.ceil,e=Math.floor;return Ge=Math.trunc||function(r){var n=+r;return(n>0?e:t)(n)}}();return ze=function(e){var r=+e;return r!=r||0===r?0:t(r)}}function fr(){if(Ye)return Xe;Ye=1;var t=cr(),e=Math.max,r=Math.min;return Xe=function(n,i){var o=t(n);return o<0?e(o+i,0):r(o,i)}}function hr(){if(Ze)return Ke;Ze=1;var t=cr(),e=Math.min;return Ke=function(r){var n=t(r);return n>0?e(n,9007199254740991):0}}function pr(){if(tr)return Qe;tr=1;var t=hr();return Qe=function(e){return t(e.length)}}function dr(){if(ir)return nr;ir=1;var t=st(),e=re(),r=pt(),n=function(){if(rr)return er;rr=1;var t=pt(),e=fr(),r=pr(),n=function(n){return function(i,o,a){var u=t(i),s=r(u);if(0===s)return!n&&-1;var c,f=e(a,s);if(n&&o!=o){for(;s>f;)if((c=u[f++])!=c)return!0}else for(;s>f;f++)if((n||f in u)&&u[f]===o)return n||f||0;return!n&&-1}};return er={includes:n(!0),indexOf:n(!1)}}().indexOf,i=$e(),o=t([].push);return nr=function(t,a){var u,s=r(t),c=0,f=[];for(u in s)!e(i,u)&&e(s,u)&&o(f,u);for(;a.length>c;)e(s,u=a[c++])&&(~n(f,u)||o(f,u));return f}}function lr(){return ar?or:(ar=1,or=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"])}var vr,yr,mr,br,gr,wr,Or,Tr,Sr,Pr,jr,Er,Ar,Ir,Ur,xr,Rr,Dr,Cr,Br,kr,_r={};function Fr(){if(mr)return yr;mr=1;var t=vt(),e=st(),r=function(){if(ur)return sr;ur=1;var t=dr(),e=lr().concat("length","prototype");return sr.f=Object.getOwnPropertyNames||function(r){return t(r,e)},sr}(),n=(vr||(vr=1,_r.f=Object.getOwnPropertySymbols),_r),i=ge(),o=e([].concat);return yr=t("Reflect","ownKeys")||function(t){var e=r.f(i(t)),a=n.f;return a?o(e,a(t)):e}}function Lr(){if(gr)return br;gr=1;var t=re(),e=Fr(),r=ce(),n=we();return br=function(i,o,a){for(var u=e(o),s=n.f,c=r.f,f=0;ff;)r.f(t,a=s[f++],u[a]);return t},zn}(),n=lr(),i=$e(),o=Xn(),a=ue(),u=Me(),s="prototype",c="script",f=u("IE_PROTO"),h=function(){},p=function(t){return"<"+c+">"+t+""},d=function(t){t.write(p("")),t.close();var e=t.parentWindow.Object;return t=null,e},l=function(){try{t=new ActiveXObject("htmlfile")}catch(t){}var e,r,i;l="undefined"!=typeof document?document.domain&&t?d(t):(r=a("iframe"),i="java"+c+":",r.style.display="none",o.appendChild(r),r.src=String(i),(e=r.contentWindow.document).open(),e.write(p("document.F=Object")),e.close(),e.F):d(t);for(var u=n.length;u--;)delete l[s][n[u]];return l()};return i[f]=!0,Yr=Object.create||function(t,n){var i;return null!==t?(h[s]=e(t),i=new h,h[s]=null,i[f]=t):i=l(),void 0===n?i:r.f(i,n)}}function Kn(){if(Qr)return Zr;Qr=1;var t=lt(),e=Oe();return Zr=function(r,n){t(n)&&"cause"in n&&e(r,"cause",n.cause)}}function Zn(){if(an)return on;an=1;var t=Oe(),e=function(){if(en)return tn;en=1;var t=st(),e=Error,r=t("".replace),n=String(new e("zxcasd").stack),i=/\n\s*at [^:]*:[^\n]*/,o=i.test(n);return tn=function(t,n){if(o&&"string"==typeof t&&!e.prepareStackTrace)for(;n--;)t=r(t,i,"");return t}}(),r=function(){if(nn)return rn;nn=1;var t=v(),e=ut();return rn=!t((function(){var t=new Error("a");return!("stack"in t)||(Object.defineProperty(t,"stack",e(1,7)),7!==t.stack)}))}(),n=Error.captureStackTrace;return on=function(i,o,a,u){r&&(n?n(i,o):t(i,"stack",e(a,u)))}}function Qn(){if(fn)return cn;fn=1;var t=function(){if(sn)return un;sn=1;var t=ct(),e=st();return un=function(r){if("Function"===t(r))return e(r)}}(),e=St(),r=m(),n=t(t.bind);return cn=function(t,i){return e(t),void 0===i?t:r?n(t,i):function(){return t.apply(i,arguments)}},cn}function ti(){return pn?hn:(pn=1,hn=Object.create?Object.create(null):{})}function ei(){if(ln)return dn;ln=1;var t=ie(),e=ti(),r=t("iterator"),n=Array.prototype;return dn=function(t){return void 0!==t&&(e.Array===t||n[r]===t)}}function ri(){if(yn)return vn;yn=1;var t=ct(),e=ft(),r=Pt(),n=ie()("iterator"),i=Array.prototype;return vn=function(o){if(!e(o))return r(o,n)||r(o,"@@iterator")||("Arguments"===t(o)?i[n]:void 0)}}function ni(){if(wn)return gn;wn=1;var t=b(),e=ge(),r=Pt();return gn=function(n,i,o){var a,u;e(n);try{if(!(a=r(n,"return"))){if("throw"===i)throw o;return o}a=t(a,n)}catch(t){u=!0,a=t}if("throw"===i)throw o;if(u)throw a;return e(a),o}}function ii(){if(Tn)return On;Tn=1;var t=Qn(),e=b(),r=ge(),n=Tt(),i=ei(),o=pr(),a=yt(),u=function(){if(bn)return mn;bn=1;var t=b(),e=dt(),r=ge(),n=Tt(),i=ri(),o=TypeError;return mn=function(a,u){var s=arguments.length<2?i(a):u;if(e(s))return r(t(s,a));throw new o(n(a)+" is not iterable")},mn}(),s=ri(),c=ni(),f=TypeError,h=function(t,e){this.stopped=t,this.result=e},p=h.prototype;return On=function(d,l,v){var y,m,b,g,w,O,T,S=v&&v.that,P=!(!v||!v.AS_ENTRIES),j=!(!v||!v.IS_RECORD),E=!(!v||!v.IS_ITERATOR),A=!(!v||!v.INTERRUPTED),I=t(l,S),U=function(t){var e=y;return y=void 0,e&&c(e,"normal"),new h(!0,t)},x=function(t){return P?(r(t),A?I(t[0],t[1],U):I(t[0],t[1])):A?I(t,U):I(t)};if(j)y=d.iterator;else if(E)y=d;else{if(!(m=s(d)))throw new f(n(d)+" is not iterable");if(i(m)){for(b=0,g=o(d);g>b;b++)if((w=x(d[b]))&&a(p,w))return w;return new h(!1)}y=u(d,m)}for(O=j?d.next:y.next;!(T=e(O,y)).done;){var R=T.value;try{w=x(R)}catch(t){if(!y)throw t;c(y,"throw",t)}if("object"==typeof w&&w&&a(p,w))return w}return new h(!1)}}function oi(){if(Pn)return Sn;Pn=1;var t={};return t[ie()("toStringTag")]="z",Sn="[object z]"===String(t)}function ai(){if(En)return jn;En=1;var t=oi(),e=dt(),r=ct(),n=ie()("toStringTag"),i=Object,o="Arguments"===r(function(){return arguments}());return jn=t?r:function(t){var a,u,s;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(u=function(t,e){try{return t[e]}catch(t){}}(a=i(t),n))?u:o?r(a):"Object"===(s=r(a))&&e(a.callee)?"Arguments":s}}function ui(){if(In)return An;In=1;var t=ai(),e=String;return An=function(r){if("Symbol"===t(r))throw new TypeError("Cannot convert a Symbol value to a string");return e(r)}}function si(){if(xn)return Un;xn=1;var t=ui();return Un=function(e,r){return void 0===e?arguments.length<2?"":r:t(e)},Un}function ci(){return Dn||(Dn=1,function(){if(Rn)return i;Rn=1;var t=Mr(),e=yt(),r=$r(),n=qr(),o=Lr(),a=Yn(),u=Oe(),s=ut(),c=Kn(),f=Zn(),h=ii(),p=si(),d=ie()("toStringTag"),l=Error,v=[].push,y=function(t,i){var o,s=e(m,this);n?o=n(new l,s?r(this):m):(o=s?this:a(m),u(o,d,"Error")),void 0!==i&&u(o,"message",p(i)),f(o,y,o.stack,1),arguments.length>2&&c(o,arguments[2]);var b=[];return h(t,v,{that:b}),u(o,"errors",b),o};n?n(y,l):o(y,l,{name:!0});var m=y.prototype=a(l.prototype,{constructor:s(1,y),message:s(1,""),name:s(1,"AggregateError")});t({global:!0,constructor:!0,arity:2},{AggregateError:y})}()),n}function fi(){if(Bn)return Cn;Bn=1;var t=ie(),e=Yn(),r=we().f,n=t("unscopables"),i=Array.prototype;return void 0===i[n]&&r(i,n,{configurable:!0,value:e(null)}),Cn=function(t){i[n][t]=!0}}function hi(){if(_n)return kn;_n=1;var t,e,r,n=v(),i=dt(),o=lt(),a=Yn(),u=$r(),s=qe(),c=ie(),f=Kt(),h=c("iterator"),p=!1;return[].keys&&("next"in(r=[].keys())?(e=u(u(r)))!==Object.prototype&&(t=e):p=!0),!o(t)||n((function(){var e={};return t[h].call(e)!==e}))?t={}:f&&(t=a(t)),i(t[h])||s(t,h,(function(){return this})),kn={IteratorPrototype:t,BUGGY_SAFARI_ITERATORS:p}}function pi(){if(Ln)return Fn;Ln=1;var t=we().f,e=re(),r=ie()("toStringTag");return Fn=function(n,i,o){n&&!o&&(n=n.prototype),n&&!e(n,r)&&t(n,r,{configurable:!0,value:i})}}function di(){if(Hn)return $n;Hn=1;var t=Mr(),e=b(),r=Kt(),n=Le(),i=dt(),o=function(){if(Mn)return Nn;Mn=1;var t=hi().IteratorPrototype,e=Yn(),r=ut(),n=pi(),i=ti(),o=function(){return this};return Nn=function(a,u,s,c){var f=u+" Iterator";return a.prototype=e(t,{next:r(+!c,s)}),n(a,f,!1,!0),i[f]=o,a}}(),a=$r(),u=qr(),s=pi(),c=Oe(),f=qe(),h=ie(),p=ti(),d=hi(),l=n.PROPER,v=n.CONFIGURABLE,y=d.IteratorPrototype,m=d.BUGGY_SAFARI_ITERATORS,g=h("iterator"),w="keys",O="values",T="entries",S=function(){return this};return $n=function(n,h,d,b,P,j,E){o(d,h,b);var A,I,U,x=function(t){if(t===P&&k)return k;if(!m&&t&&t in C)return C[t];switch(t){case w:case O:case T:return function(){return new d(this,t)}}return function(){return new d(this)}},R=h+" Iterator",D=!1,C=n.prototype,B=C[g]||C["@@iterator"]||P&&C[P],k=!m&&B||x(P),_="Array"===h&&C.entries||B;if(_&&(A=a(_.call(new n)))!==Object.prototype&&A.next&&(r||a(A)===y||(u?u(A,y):i(A[g])||f(A,g,S)),s(A,R,!0,!0),r&&(p[R]=S)),l&&P===O&&B&&B.name!==O&&(!r&&v?c(C,"name",O):(D=!0,k=function(){return e(B,this)})),P)if(I={values:x(O),keys:j?k:x(w),entries:x(T)},E)for(U in I)(m||D||!(U in C))&&f(C,U,I[U]);else t({target:h,proto:!0,forced:m||D},I);return r&&!E||C[g]===k||f(C,g,k,{name:P}),p[h]=k,I},$n}function li(){return qn?Wn:(qn=1,Wn=function(t,e){return{value:t,done:e}})}function vi(){if(Vn)return Gn;Vn=1;var t=pt(),e=fi(),r=ti(),n=He(),i=we().f,o=di(),a=li(),u=Kt(),s=y(),c="Array Iterator",f=n.set,h=n.getterFor(c);Gn=o(Array,"Array",(function(e,r){f(this,{type:c,target:t(e),index:0,kind:r})}),(function(){var t=h(this),e=t.target,r=t.index++;if(!e||r>=e.length)return t.target=null,a(void 0,!0);switch(t.kind){case"keys":return a(r,!1);case"values":return a(e[r],!1)}return a([r,e[r]],!1)}),"values");var p=r.Arguments=r.Array;if(e("keys"),e("values"),e("entries"),!u&&s&&"values"!==p.name)try{i(p,"name",{value:"values"})}catch(t){}return Gn}var yi,mi,bi,gi={};function wi(){if(bi)return gi;bi=1;var t=oi(),e=qe(),r=function(){if(mi)return yi;mi=1;var t=oi(),e=ai();return yi=t?{}.toString:function(){return"[object "+e(this)+"]"}}();return t||e(Object.prototype,"toString",r,{unsafe:!0}),gi}var Oi,Ti,Si,Pi,ji,Ei,Ai,Ii,Ui,xi,Ri,Di,Ci,Bi,ki,_i,Fi,Li,Ni,Mi,$i,Hi,Wi,qi,Gi,Vi,zi,Ji,Xi,Yi,Ki,Zi,Qi,to,eo,ro,no,io,oo,ao,uo,so,co,fo,ho,po,lo={},vo={};function yo(){if(Ti)return Oi;Ti=1;var t=o(),e=mt(),r=ct(),n=function(t){return e.slice(0,t.length)===t};return Oi=n("Bun/")?"BUN":n("Cloudflare-Workers")?"CLOUDFLARE":n("Deno/")?"DENO":n("Node.js/")?"NODE":t.Bun&&"string"==typeof Bun.version?"BUN":t.Deno&&"object"==typeof Deno.version?"DENO":"process"===r(t.process)?"NODE":t.window&&t.document?"BROWSER":"REST"}function mo(){if(Pi)return Si;Pi=1;var t=yo();return Si="NODE"===t}function bo(){if(Ei)return ji;Ei=1;var t=o();return ji=t}function go(){if(Ii)return Ai;Ii=1;var t=We(),e=we();return Ai=function(r,n,i){return i.get&&t(i.get,n,{getter:!0}),i.set&&t(i.set,n,{setter:!0}),e.f(r,n,i)}}function wo(){if(xi)return Ui;xi=1;var t=vt(),e=go(),r=ie(),n=y(),i=r("species");return Ui=function(r){var o=t(r);n&&o&&!o[i]&&e(o,i,{configurable:!0,get:function(){return this}})}}function Oo(){if(Di)return Ri;Di=1;var t=yt(),e=TypeError;return Ri=function(r,n){if(t(n,r))return r;throw new e("Incorrect invocation")}}function To(){if(Bi)return Ci;Bi=1;var t=st(),e=v(),r=dt(),n=ai(),i=vt(),o=Ne(),a=function(){},u=i("Reflect","construct"),s=/^\s*(?:class|function)\b/,c=t(s.exec),f=!s.test(a),h=function(t){if(!r(t))return!1;try{return u(a,[],t),!0}catch(t){return!1}},p=function(t){if(!r(t))return!1;switch(n(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return f||!!c(s,o(t))}catch(t){return!0}};return p.sham=!0,Ci=!u||e((function(){var t;return h(h.call)||!h(Object)||!h((function(){t=!0}))||t}))?p:h}function So(){if(_i)return ki;_i=1;var t=To(),e=Tt(),r=TypeError;return ki=function(n){if(t(n))return n;throw new r(e(n)+" is not a constructor")}}function Po(){if(Li)return Fi;Li=1;var t=ge(),e=So(),r=ft(),n=ie()("species");return Fi=function(i,o){var a,u=t(i).constructor;return void 0===u||r(a=t(u)[n])?o:e(a)}}function jo(){if(Mi)return Ni;Mi=1;var t=m(),e=Function.prototype,r=e.apply,n=e.call;return Ni="object"==typeof Reflect&&Reflect.apply||(t?n.bind(r):function(){return n.apply(r,arguments)}),Ni}function Eo(){if(Hi)return $i;Hi=1;var t=st();return $i=t([].slice)}function Ao(){if(qi)return Wi;qi=1;var t=TypeError;return Wi=function(e,r){if(e=d?t?"":void 0:(c=o(h,p))<55296||c>56319||p+1===d||(f=o(h,p+1))<56320||f>57343?t?i(h,p):c:t?a(h,p,p+2):f-56320+(c-55296<<10)+65536}};return ba={codeAt:u(!1),charAt:u(!0)}}().charAt,e=ui(),r=He(),n=di(),i=li(),o="String Iterator",a=r.set,u=r.getterFor(o);return n(String,"String",(function(t){a(this,{type:o,string:e(t),index:0})}),(function(){var e,r=u(this),n=r.string,o=r.index;return o>=n.length?i(void 0,!0):(e=t(n,o),r.index+=e.length,i(e,!1))})),Sa}function ja(){if(Ta)return Oa;Ta=1,ci(),vi(),wi(),ua(),function(){if(sa)return ca;sa=1;var t=Mr(),e=b(),r=St(),n=Mo(),i=Bo(),o=ii();t({target:"Promise",stat:!0,forced:Jo()},{allSettled:function(t){var a=this,u=n.f(a),s=u.resolve,c=u.reject,f=i((function(){var n=r(a.resolve),i=[],u=0,c=1;o(t,(function(t){var r=u++,o=!1;c++,e(n,a,t).then((function(t){o||(o=!0,i[r]={status:"fulfilled",value:t},--c||s(i))}),(function(t){o||(o=!0,i[r]={status:"rejected",reason:t},--c||s(i))}))})),--c||s(i)}));return f.error&&c(f.value),u.promise}})}(),function(){if(fa)return ha;fa=1;var t=Mr(),e=b(),r=St(),n=vt(),i=Mo(),o=Bo(),a=ii(),u=Jo(),s="No one promise resolved";t({target:"Promise",stat:!0,forced:u},{any:function(t){var u=this,c=n("AggregateError"),f=i.f(u),h=f.resolve,p=f.reject,d=o((function(){var n=r(u.resolve),i=[],o=0,f=1,d=!1;a(t,(function(t){var r=o++,a=!1;f++,e(n,u,t).then((function(t){a||d||(d=!0,h(t))}),(function(t){a||d||(a=!0,i[r]=t,--f||p(new c(i,s)))}))})),--f||p(new c(i,s))}));return d.error&&p(d.value),f.promise}})}(),function(){if(pa)return da;pa=1;var t=Mr(),e=o(),r=jo(),n=Eo(),i=aa(),a=Mo(),u=St(),s=Bo(),c=v(),f=e.Promise,h=!1;t({target:"Promise",stat:!0,forced:!f||!f.try||c((function(){var t=f.resolve();return f.try((function(e){return h=8===e,t}),8)!==t}))||!h},{try:function(t){var e=arguments.length>1?n(arguments,1):[],o=s((function(){return r(u(t),void 0,e)}));if(!o.error)return i(this,o.value);var c=a.f(this);return(0,c.reject)(o.value),c.promise}})}(),function(){if(la)return va;la=1;var t=Mr(),e=Mo();t({target:"Promise",stat:!0},{withResolvers:function(){var t=e.f(this);return{promise:t.promise,resolve:t.resolve,reject:t.reject}}})}(),function(){if(ya)return ma;ya=1;var t=Mr(),e=Kt(),r=ko(),n=v(),i=vt(),o=dt(),a=Po(),u=aa(),s=qe(),c=r&&r.prototype;if(t({target:"Promise",proto:!0,real:!0,forced:!!r&&n((function(){c.finally.call({then:function(){}},(function(){}))}))},{finally:function(t){var e=a(this,i("Promise")),r=o(t);return this.then(r?function(r){return u(e,t()).then((function(){return r}))}:t,r?function(r){return u(e,t()).then((function(){throw r}))}:t)}}),!e&&o(r)){var f=i("Promise").prototype.finally;c.finally!==f&&s(c,"finally",f,{unsafe:!0})}}(),Pa();var t=bo();return Oa=t.Promise}var Ea,Aa,Ia,Ua,xa,Ra,Da,Ca={};function Ba(){if(xa)return Ca;xa=1;var t=o(),e=Aa?Ea:(Aa=1,Ea={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}),r=function(){if(Ua)return Ia;Ua=1;var t=ue()("span").classList,e=t&&t.constructor&&t.constructor.prototype;return Ia=e===Object.prototype?void 0:e}(),n=vi(),i=Oe(),a=pi(),u=ie()("iterator"),s=n.values,c=function(t,r){if(t){if(t[u]!==s)try{i(t,u,s)}catch(e){t[u]=s}if(a(t,r,!0),e[r])for(var o in n)if(t[o]!==n[o])try{i(t,o,n[o])}catch(e){t[o]=n[o]}}};for(var f in e)c(t[f]&&t[f].prototype,f);return c(r,"DOMTokenList"),Ca}!function(){if(Da)return Ra;Da=1;var t=ja();Ba(),Ra=t}();var ka="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{},_a="URLSearchParams"in ka,Fa="Symbol"in ka&&"iterator"in Symbol,La="FileReader"in ka&&"Blob"in ka&&function(){try{return new Blob,!0}catch(t){return!1}}(),Na="FormData"in ka,Ma="ArrayBuffer"in ka;if(Ma)var $a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],Ha=ArrayBuffer.isView||function(t){return t&&$a.indexOf(Object.prototype.toString.call(t))>-1};function Wa(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(t)||""===t)throw new TypeError('Invalid character in header field name: "'+t+'"');return t.toLowerCase()}function qa(t){return"string"!=typeof t&&(t=String(t)),t}function Ga(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return Fa&&(e[Symbol.iterator]=function(){return e}),e}function Va(t){this.map={},t instanceof Va?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){if(2!=t.length)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+t.length);this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function za(t){if(!t._noBody)return t.bodyUsed?Promise.reject(new TypeError("Already read")):void(t.bodyUsed=!0)}function Ja(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function Xa(t){var e=new FileReader,r=Ja(e);return e.readAsArrayBuffer(t),r}function Ya(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function Ka(){return this.bodyUsed=!1,this._initBody=function(t){var e;this.bodyUsed=this.bodyUsed,this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:La&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:Na&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:_a&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():Ma&&La&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=Ya(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):Ma&&(ArrayBuffer.prototype.isPrototypeOf(t)||Ha(t))?this._bodyArrayBuffer=Ya(t):this._bodyText=t=Object.prototype.toString.call(t):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):_a&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},La&&(this.blob=function(){var t=za(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var t=za(this);return t||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}if(La)return this.blob().then(Xa);throw new Error("could not read as ArrayBuffer")},this.text=function(){var t=za(this);if(t)return t;if(this._bodyBlob)return function(t){var e=new FileReader,r=Ja(e),n=/charset=([A-Za-z0-9_-]+)/.exec(t.type),i=n?n[1]:"utf-8";return e.readAsText(t,i),r}(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal||function(){if("AbortController"in ka)return(new AbortController).signal}(),this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(i),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==e.cache&&"no-cache"!==e.cache)){var o=/([?&])_=[^&]*/;if(o.test(this.url))this.url=this.url.replace(o,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function tu(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),i=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(i))}})),e}function eu(t,e){if(!(this instanceof eu))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=void 0===e.statusText?"":""+e.statusText,this.headers=new Va(e.headers),this.url=e.url||"",this._initBody(t)}Qa.prototype.clone=function(){return new Qa(this,{body:this._bodyInit})},Ka.call(Qa.prototype),Ka.call(eu.prototype),eu.prototype.clone=function(){return new eu(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new Va(this.headers),url:this.url})},eu.error=function(){var t=new eu(null,{status:200,statusText:""});return t.ok=!1,t.status=0,t.type="error",t};var ru=[301,302,303,307,308];eu.redirect=function(t,e){if(-1===ru.indexOf(e))throw new RangeError("Invalid status code");return new eu(null,{status:e,headers:{location:t}})};var nu=ka.DOMException;try{new nu}catch(t){(nu=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack}).prototype=Object.create(Error.prototype),nu.prototype.constructor=nu}function iu(t,e){return new Promise((function(r,n){var i=new Qa(t,e);if(i.signal&&i.signal.aborted)return n(new nu("Aborted","AbortError"));var o=new XMLHttpRequest;function a(){o.abort()}if(o.onload=function(){var t,e,n={statusText:o.statusText,headers:(t=o.getAllResponseHeaders()||"",e=new Va,t.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(t){return 0===t.indexOf("\n")?t.substr(1,t.length):t})).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var i=r.join(":").trim();try{e.append(n,i)}catch(t){console.warn("Response "+t.message)}}})),e)};0===i.url.indexOf("file://")&&(o.status<200||o.status>599)?n.status=200:n.status=o.status,n.url="responseURL"in o?o.responseURL:n.headers.get("X-Request-URL");var a="response"in o?o.response:o.responseText;setTimeout((function(){r(new eu(a,n))}),0)},o.onerror=function(){setTimeout((function(){n(new TypeError("Network request failed"))}),0)},o.ontimeout=function(){setTimeout((function(){n(new TypeError("Network request timed out"))}),0)},o.onabort=function(){setTimeout((function(){n(new nu("Aborted","AbortError"))}),0)},o.open(i.method,function(t){try{return""===t&&ka.location.href?ka.location.href:t}catch(e){return t}}(i.url),!0),"include"===i.credentials?o.withCredentials=!0:"omit"===i.credentials&&(o.withCredentials=!1),"responseType"in o&&(La?o.responseType="blob":Ma&&(o.responseType="arraybuffer")),e&&"object"==typeof e.headers&&!(e.headers instanceof Va||ka.Headers&&e.headers instanceof ka.Headers)){var u=[];Object.getOwnPropertyNames(e.headers).forEach((function(t){u.push(Wa(t)),o.setRequestHeader(t,qa(e.headers[t]))})),i.headers.forEach((function(t,e){-1===u.indexOf(e)&&o.setRequestHeader(e,t)}))}else i.headers.forEach((function(t,e){o.setRequestHeader(e,t)}));i.signal&&(i.signal.addEventListener("abort",a),o.onreadystatechange=function(){4===o.readyState&&i.signal.removeEventListener("abort",a)}),o.send(void 0===i._bodyInit?null:i._bodyInit)}))}iu.polyfill=!0,ka.fetch||(ka.fetch=iu,ka.Headers=Va,ka.Request=Qa,ka.Response=eu);var ou=function(t,e){return ou=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},ou(t,e)};function au(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}ou(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function uu(t,e,r,n){return new(r||(r=Promise))((function(i,o){function a(t){try{s(n.next(t))}catch(t){o(t)}}function u(t){try{s(n.throw(t))}catch(t){o(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,u)}s((n=n.apply(t,e||[])).next())}))}function su(t,e){var r,n,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=u(0),a.throw=u(1),a.return=u(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(s){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&u[0]?n.return:u[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,u[1])).done)return i;switch(n=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,n=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]0&&rr)break;n++}return n},t}(),hu=function(){function t(){this.updateTimestamps=[],this.previousTimestampIndex=0}return t.prototype.setUpdateTimestamps=function(t){this.updateTimestamps=t,this.onTimestampsUpdated&&this.onTimestampsUpdated()},t.prototype.renderAtTimestamp=function(t){var e=fu.getIndexFromTimestamps(t,this.updateTimestamps);this.renderAtIndex(e)},t.prototype.renderAtIndex=function(t){this.previousTimestampIndex!==t&&(this.previousTimestampIndex=t,this.render(t))},t}(),pu=function(t){function e(e){var r,n=t.call(this)||this;n.pendingLoads=[],n.$onWorkerMessage=function(t){n.onWorkerMessage(t)};var i=null!==(r=e.workerUrl)&&void 0!==r?r:"libpgs.worker.js";return n.worker=new Worker(i),n.worker.onmessage=n.$onWorkerMessage,n}return au(e,t),e.prototype.loadFromUrl=function(t){var e=this;return this.worker.postMessage({op:"loadFromUrl",url:t}),new Promise((function(t,r){return e.pendingLoads.push({resolve:t,reject:r})}))},e.prototype.loadFromBuffer=function(t){var e=this;return this.worker.postMessage({op:"loadFromBuffer",buffer:t}),new Promise((function(t,r){return e.pendingLoads.push({resolve:t,reject:r})}))},e.prototype.onWorkerMessage=function(t){switch(t.data.op){case"updateTimestamps":this.setUpdateTimestamps(t.data.updateTimestamps);break;case"loaded":var e=this.pendingLoads.shift();t.data.error?null==e||e.reject(new Error(t.data.error)):null==e||e.resolve()}},e.prototype.dispose=function(){this.worker.terminate();for(var t=0,e=this.pendingLoads;tthis.x+this.width&&(this.width=t+r-this.x),e+n>this.y+this.height&&(this.height=e+n-this.y))},t}(),vu=function(){function t(t){this.dirtyArea=new lu,this.canvas=t,this.context=t.getContext("2d")}return t.prototype.draw=function(t){this.canvas&&this.context&&(this.dirtyArea.empty||(this.context.clearRect(this.dirtyArea.x,this.dirtyArea.y,this.dirtyArea.width,this.dirtyArea.height),this.dirtyArea.reset()),t&&(this.canvas.width==t.width&&this.canvas.height==t.height||(this.canvas.width=t.width,this.canvas.height=t.height),this.drawSubtitleData(t,this.dirtyArea)))},t.prototype.drawSubtitleData=function(t,e){for(var r=0,n=t.compositionData;r=this.length},enumerable:!1,configurable:!0}),t.prototype.readByte=function(){return this.array[this.$position++]},t.prototype.readBytes=function(t){var e=this.array.slice(this.$position,this.$position+t);return this.$position+=t,e},t}(),mu=function(){function t(t){t instanceof Uint8Array?this.baseReader=new yu(t):this.baseReader=t}return Object.defineProperty(t.prototype,"position",{get:function(){return this.baseReader.position},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"length",{get:function(){return this.baseReader.length},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"eof",{get:function(){return this.baseReader.eof},enumerable:!1,configurable:!0}),t.prototype.readUInt8=function(){return this.baseReader.readByte()},t.prototype.readUInt16=function(){return(this.baseReader.readByte()<<8)+this.baseReader.readByte()},t.prototype.readUInt24=function(){return(this.baseReader.readByte()<<16)+(this.baseReader.readByte()<<8)+this.baseReader.readByte()},t.prototype.readUInt32=function(){return(this.baseReader.readByte()<<24)+(this.baseReader.readByte()<<16)+(this.baseReader.readByte()<<8)+this.baseReader.readByte()},t.prototype.readBytes=function(t){return this.baseReader.readBytes(t)},t}();!function(t){t[t.paletteDefinition=20]="paletteDefinition",t[t.objectDefinition=21]="objectDefinition",t[t.presentationComposition=22]="presentationComposition",t[t.windowDefinition=23]="windowDefinition",t[t.end=128]="end"}(cu||(cu={}));var bu,gu=function(){function t(){this.id=0,this.windowId=0,this.croppedFlag=0,this.horizontalPosition=0,this.verticalPosition=0,this.croppingHorizontalPosition=0,this.croppingVerticalPosition=0,this.croppingWidth=0,this.croppingHeight=0}return Object.defineProperty(t.prototype,"hasCropping",{get:function(){return!!(128&this.croppedFlag)},enumerable:!1,configurable:!0}),t}(),wu=function(){function t(){this.width=0,this.height=0,this.frameRate=0,this.compositionNumber=0,this.compositionState=0,this.paletteUpdateFlag=0,this.paletteId=0,this.compositionObjects=[]}return Object.defineProperty(t.prototype,"segmentType",{get:function(){return cu.presentationComposition},enumerable:!1,configurable:!0}),t.prototype.read=function(t,e){this.width=t.readUInt16(),this.height=t.readUInt16(),this.frameRate=t.readUInt8(),this.compositionNumber=t.readUInt16(),this.compositionState=t.readUInt8(),this.paletteUpdateFlag=t.readUInt8(),this.paletteId=t.readUInt8();var r=t.readUInt8();this.compositionObjects=[];for(var n=0;nr?r:t},t}(),Tu=function(){function t(){this.id=0,this.versionNumber=0,this.lastInSequenceFlag=0,this.width=0,this.height=0,this.dataLength=0}return Object.defineProperty(t.prototype,"isFirstInSequence",{get:function(){return!!(128&this.lastInSequenceFlag)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isLastInSequence",{get:function(){return!!(64&this.lastInSequenceFlag)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"segmentType",{get:function(){return cu.objectDefinition},enumerable:!1,configurable:!0}),t.prototype.read=function(t,e){this.id=t.readUInt16(),this.versionNumber=t.readUInt8(),this.lastInSequenceFlag=t.readUInt8(),this.isFirstInSequence?(this.dataLength=t.readUInt24(),this.width=t.readUInt16(),this.height=t.readUInt16(),this.data=t.readBytes(e-11)):this.data=t.readBytes(e-4)},t}(),Su=function(){this.id=0,this.horizontalPosition=0,this.verticalPosition=0,this.width=0,this.height=0},Pu=function(){function t(){this.windows=[]}return Object.defineProperty(t.prototype,"segmentType",{get:function(){return cu.windowDefinition},enumerable:!1,configurable:!0}),t.prototype.read=function(t,e){var r=t.readUInt8();this.windows=[];for(var n=0;n=this.length},enumerable:!1,configurable:!0}),t.prototype.readByte=function(){for(;this.subReaders[this.subReaderIndex].position>=this.subReaders[this.subReaderIndex].length;)this.subReaderIndex++;return this.$position++,this.subReaders[this.subReaderIndex].readByte()},t.prototype.readBytes=function(t){for(var e=new Uint8Array(t),r=0;rthis.reader.length&&!this.$eof?[4,this.stream.read()]:[3,2];case 1:return e=i.sent(),r=e.value,n=e.done,r&&this.reader.push(r),n&&(this.$eof=!0),[3,0];case 2:return[2,this.reader.position+t<=this.reader.length]}}))}))},t}(),Iu=function(t,e,r){this.width=t,this.height=e,this.compositionData=r},Uu=function(t,e,r){this.compositionObject=t,this.window=e,this.pixelData=r},xu=function(){function t(){}return t.decode=function(t,e,r){t instanceof Uint8Array&&(t=new yu(t));for(var n=0;t.positionr+1e3&&(r=o,e.onProgress()),[3,1];case 3:return(null==e?void 0:e.onProgress)&&e.onProgress(),[2]}}))}))},t.prototype.cacheSubtitleAtIndex=function(t){var e=this.getSubtitleAtIndex(t);this.cachedSubtitleData={index:t,data:e}},t.prototype.getSubtitleAtTimestamp=function(t){var e=fu.getIndexFromTimestamps(t,this.updateTimestamps);return this.getSubtitleAtIndex(e)},t.prototype.getSubtitleAtIndex=function(t){var e;if(this.cachedSubtitleData&&this.cachedSubtitleData.index===t)return this.cachedSubtitleData.data;if(!(t<0||t>=this.displaySets.length)){var r=this.displaySets[t];if(r.presentationComposition){for(var n=[],i=[],o=[],a=t;a>=0;){var u=this.displaySets[a];n.unshift.apply(n,u.objectDefinitions),i.unshift.apply(i,u.paletteDefinitions);for(var s=0,c=u.windowDefinitions;s=0;if(r&&r<36)return bu.mainThread;if(i&&i<25)return bu.mainThread;if(o&&void 0===r)return bu.mainThread;if(o&&r&&r<=68)return bu.mainThread;var a=this.isWorkerSupported(),u=this.isOffscreenCanvasSupported();return a?u?bu.worker:bu.workerWithoutOffscreenCanvas:bu.mainThread},t}(),ku=function(){function t(t){var e,r=this;if(this.ready=Promise.resolve(),this.$timeOffset=0,this.onTimeUpdate=function(){r.renderAtVideoTimestamp()},this.$aspectRatio="contain",t.video&&(this.video=t.video),t.canvas)this.canvas=t.canvas,this.canvasOwner=!1;else{if(!this.video)throw new Error("No canvas or video element was provided!");this.canvas=this.createCanvasElement(),this.canvasOwner=!0,this.video.parentElement.appendChild(this.canvas)}this.implementation=this.createPgsRenderer(t),this.implementation.onTimestampsUpdated=function(){r.renderAtVideoTimestamp()},this.$timeOffset=null!==(e=t.timeOffset)&&void 0!==e?e:0,t.aspectRatio&&(this.aspectRatio=t.aspectRatio),t.subUrl&&this.loadFromUrl(t.subUrl).catch((function(){})),this.registerVideoEvents()}return t.prototype.createPgsRenderer=function(t){var e;switch(null!==(e=t.mode)&&void 0!==e?e:Bu.getRendererModeByPlatform()){case bu.worker:return new du(t,this.canvas);case bu.workerWithoutOffscreenCanvas:return new Cu(t,this.canvas);case bu.mainThread:return new Du(t,this.canvas)}},t.prototype.loadFromUrl=function(t){return this.ready=this.implementation.loadFromUrl(t),this.ready},t.prototype.loadFromBuffer=function(t){return this.ready=this.implementation.loadFromBuffer(t),this.ready},t.prototype.renderAtTimestamp=function(t){this.implementation.renderAtTimestamp(t)},Object.defineProperty(t.prototype,"timeOffset",{get:function(){return this.$timeOffset},set:function(t){this.$timeOffset!==t&&(this.$timeOffset=t,this.renderAtVideoTimestamp())},enumerable:!1,configurable:!0}),t.prototype.registerVideoEvents=function(){var t;null===(t=this.video)||void 0===t||t.addEventListener("timeupdate",this.onTimeUpdate)},t.prototype.unregisterVideoEvents=function(){var t;null===(t=this.video)||void 0===t||t.removeEventListener("timeupdate",this.onTimeUpdate)},t.prototype.renderAtVideoTimestamp=function(){this.video&&this.renderAtTimestamp(this.video.currentTime+this.$timeOffset)},t.prototype.createCanvasElement=function(){var t=document.createElement("canvas");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.right="0",t.style.bottom="0",t.style.pointerEvents="none",t.style.objectFit=this.$aspectRatio,t.style.width="100%",t.style.height="100%",t},t.prototype.destroyCanvasElement=function(){this.canvas.remove()},Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return this.$aspectRatio},set:function(t){this.$aspectRatio=t,this.canvas.style.objectFit=this.$aspectRatio},enumerable:!1,configurable:!0}),t.prototype.dispose=function(){this.implementation.dispose(),this.unregisterVideoEvents(),this.canvasOwner&&this.destroyCanvasElement()},t}();export{ku as PgsRenderer}; diff --git a/dist/libpgs.worker.js b/dist/libpgs.worker.js new file mode 100644 index 0000000..e48c0c2 --- /dev/null +++ b/dist/libpgs.worker.js @@ -0,0 +1 @@ +var t,e,r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n={};function i(){if(e)return t;e=1;var n=function(t){return t&&t.Math===Math&&t};return t=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof r&&r)||n("object"==typeof t&&t)||function(){return this}()||Function("return this")()}var o,a,u,s,c,f,h,p,l={};function d(){return a?o:(a=1,o=function(t){try{return!!t()}catch(t){return!0}})}function y(){if(s)return u;s=1;var t=d();return u=!t((function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]}))}function v(){if(f)return c;f=1;var t=d();return c=!t((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")}))}function b(){if(p)return h;p=1;var t=v(),e=Function.prototype.call;return h=t?e.bind(e):function(){return e.apply(e,arguments)},h}var g,m,w,O,S,j,P,T,A,I,E,x,R,U,D,B,C,_,F,L,k,N,M,q,H,G,z,$,V,W,J,X,Y,K,Z,Q,tt,et,rt,nt,it,ot={};function at(){return w?m:(w=1,m=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}})}function ut(){if(S)return O;S=1;var t=v(),e=Function.prototype,r=e.call,n=t&&e.bind.bind(r,r);return O=t?n:function(t){return function(){return r.apply(t,arguments)}},O}function st(){if(P)return j;P=1;var t=ut(),e=t({}.toString),r=t("".slice);return j=function(t){return r(e(t),8,-1)}}function ct(){if(A)return T;A=1;var t=ut(),e=d(),r=st(),n=Object,i=t("".split);return T=e((function(){return!n("z").propertyIsEnumerable(0)}))?function(t){return"String"===r(t)?i(t,""):n(t)}:n}function ft(){return E?I:(E=1,I=function(t){return null==t})}function ht(){if(R)return x;R=1;var t=ft(),e=TypeError;return x=function(r){if(t(r))throw new e("Can't call method on "+r);return r}}function pt(){if(D)return U;D=1;var t=ct(),e=ht();return U=function(r){return t(e(r))}}function lt(){if(C)return B;C=1;var t="object"==typeof document&&document.all;return B=void 0===t&&void 0!==t?function(e){return"function"==typeof e||e===t}:function(t){return"function"==typeof t}}function dt(){if(F)return _;F=1;var t=lt();return _=function(e){return"object"==typeof e?null!==e:t(e)}}function yt(){if(k)return L;k=1;var t=i(),e=lt();return L=function(r,n){return arguments.length<2?(i=t[r],e(i)?i:void 0):t[r]&&t[r][n];var i},L}function vt(){if(M)return N;M=1;var t=ut();return N=t({}.isPrototypeOf)}function bt(){if(H)return q;H=1;var t=i().navigator,e=t&&t.userAgent;return q=e?String(e):""}function gt(){if(z)return G;z=1;var t,e,r=i(),n=bt(),o=r.process,a=r.Deno,u=o&&o.versions||a&&a.version,s=u&&u.v8;return s&&(e=(t=s.split("."))[0]>0&&t[0]<4?1:+(t[0]+t[1])),!e&&n&&(!(t=n.match(/Edge\/(\d+)/))||t[1]>=74)&&(t=n.match(/Chrome\/(\d+)/))&&(e=+t[1]),G=e}function mt(){if(V)return $;V=1;var t=gt(),e=d(),r=i().String;return $=!!Object.getOwnPropertySymbols&&!e((function(){var e=Symbol("symbol detection");return!r(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&t&&t<41}))}function wt(){if(J)return W;J=1;var t=mt();return W=t&&!Symbol.sham&&"symbol"==typeof Symbol.iterator}function Ot(){if(Y)return X;Y=1;var t=yt(),e=lt(),r=vt(),n=wt(),i=Object;return X=n?function(t){return"symbol"==typeof t}:function(n){var o=t("Symbol");return e(o)&&r(o.prototype,i(n))}}function St(){if(Z)return K;Z=1;var t=String;return K=function(e){try{return t(e)}catch(t){return"Object"}}}function jt(){if(tt)return Q;tt=1;var t=lt(),e=St(),r=TypeError;return Q=function(n){if(t(n))return n;throw new r(e(n)+" is not a function")}}function Pt(){if(rt)return et;rt=1;var t=jt(),e=ft();return et=function(r,n){var i=r[n];return e(i)?void 0:t(i)}}function Tt(){if(it)return nt;it=1;var t=b(),e=lt(),r=dt(),n=TypeError;return nt=function(i,o){var a,u;if("string"===o&&e(a=i.toString)&&!r(u=t(a,i)))return u;if(e(a=i.valueOf)&&!r(u=t(a,i)))return u;if("string"!==o&&e(a=i.toString)&&!r(u=t(a,i)))return u;throw new n("Can't convert object to primitive value")}}var At,It,Et,xt,Rt,Ut,Dt,Bt,Ct,_t,Ft,Lt,kt,Nt,Mt,qt,Ht,Gt,zt,$t,Vt,Wt,Jt,Xt,Yt={exports:{}};function Kt(){return It?At:(It=1,At=!1)}function Zt(){if(xt)return Et;xt=1;var t=i(),e=Object.defineProperty;return Et=function(r,n){try{e(t,r,{value:n,configurable:!0,writable:!0})}catch(e){t[r]=n}return n}}function Qt(){if(Rt)return Yt.exports;Rt=1;var t=Kt(),e=i(),r=Zt(),n="__core-js_shared__",o=Yt.exports=e[n]||r(n,{});return(o.versions||(o.versions=[])).push({version:"3.50.0",mode:t?"pure":"global",copyright:"© 2013–2025 Denis Pushkarev (zloirock.ru), 2025–2026 CoreJS Company (core-js.io). All rights reserved.",license:"https://github.com/zloirock/core-js/blob/v3.50.0/LICENSE",source:"https://github.com/zloirock/core-js"}),Yt.exports}function te(){if(Dt)return Ut;Dt=1;var t=Qt(),e=Object.create||Object;return Ut=function(r,n){return t[r]||(t[r]=n||e(null))}}function ee(){if(Ct)return Bt;Ct=1;var t=ht(),e=Object;return Bt=function(r){return e(t(r))}}function re(){if(Ft)return _t;Ft=1;var t=ut(),e=ee(),r=t({}.hasOwnProperty);return _t=Object.hasOwn||function(t,n){return r(e(t),n)}}function ne(){if(kt)return Lt;kt=1;var t=ut(),e=0,r=Math.random(),n=t(1.1.toString);return Lt=function(t){return"Symbol("+(void 0===t?"":t)+")_"+n(++e+r,36)}}function ie(){if(Mt)return Nt;Mt=1;var t=i(),e=te(),r=re(),n=ne(),o=mt(),a=wt(),u=t.Symbol,s=e("wks"),c=a?u.for||u:u&&u.withoutSetter||n;return Nt=function(t){return r(s,t)||(s[t]=o&&r(u,t)?u[t]:c("Symbol."+t)),s[t]}}function oe(){if(Ht)return qt;Ht=1;var t=b(),e=dt(),r=Ot(),n=Pt(),i=Tt(),o=ie(),a=TypeError,u=o("toPrimitive");return qt=function(o,s){if(!e(o)||r(o))return o;var c,f=n(o,u);if(f){if(void 0===s&&(s="default"),c=t(f,o,s),!e(c)||r(c))return c;throw new a("Can't convert object to primitive value")}return void 0===s&&(s="number"),i(o,s)}}function ae(){if(zt)return Gt;zt=1;var t=oe(),e=Ot();return Gt=function(r){var n=t(r,"string");return e(n)?n:n+""}}function ue(){if(Vt)return $t;Vt=1;var t=i(),e=dt(),r=t.document,n=e(r)&&e(r.createElement);return $t=function(t){return n?r.createElement(t):{}}}function se(){if(Jt)return Wt;Jt=1;var t=y(),e=d(),r=ue();return Wt=!t&&!e((function(){return 7!==Object.defineProperty(r("div"),"a",{get:function(){return 7}}).a}))}function ce(){if(Xt)return l;Xt=1;var t=y(),e=b(),r=function(){if(g)return ot;g=1;var t={}.propertyIsEnumerable,e=Object.getOwnPropertyDescriptor,r=e&&!t.call({1:2},1);return ot.f=r?function(t){var r=e(this,t);return!!r&&r.enumerable}:t,ot}(),n=at(),i=pt(),o=ae(),a=re(),u=se(),s=Object.getOwnPropertyDescriptor;return l.f=t?s:function(t,c){if(t=i(t),c=o(c),u)try{return s(t,c)}catch(t){}if(a(t,c))return n(!e(r.f,t,c),t[c])},l}var fe,he,pe,le,de,ye,ve,be={};function ge(){if(he)return fe;he=1;var t=y(),e=d();return fe=t&&e((function(){return 42!==Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype}))}function me(){if(le)return pe;le=1;var t=dt(),e=String,r=TypeError;return pe=function(n){if(t(n))return n;throw new r(e(n)+" is not an object")}}function we(){if(de)return be;de=1;var t=y(),e=se(),r=ge(),n=me(),i=ae(),o=TypeError,a=Object.defineProperty,u=Object.getOwnPropertyDescriptor,s="enumerable",c="configurable",f="writable";return be.f=t?r?function(t,e,r){if(n(t),e=i(e),n(r),"function"==typeof t&&"prototype"===e&&"value"in r&&f in r&&!r[f]){var o=u(t,e);o&&o[f]&&(t[e]=r.value,r={configurable:c in r?r[c]:o[c],enumerable:s in r?r[s]:o[s],writable:!1})}return a(t,e,r)}:a:function(t,r,u){if(n(t),r=i(r),n(u),e)try{return a(t,r,u)}catch(t){}if("get"in u||"set"in u)throw new o("Accessors not supported");return"value"in u&&(t[r]=u.value),t},be}function Oe(){if(ve)return ye;ve=1;var t=y(),e=we(),r=at();return ye=t?function(t,n,i){return e.f(t,n,r(1,i))}:function(t,e,r){return t[e]=r,t}}var Se,je,Pe,Te,Ae,Ie,Ee,xe,Re,Ue,De,Be,Ce,_e,Fe,Le={exports:{}};function ke(){if(je)return Se;je=1;var t=y(),e=re(),r=Function.prototype,n=t&&Object.getOwnPropertyDescriptor,i=e(r,"name"),o=i&&"something"===function(){}.name,a=i&&(!t||t&&n(r,"name").configurable);return Se={EXISTS:i,PROPER:o,CONFIGURABLE:a}}function Ne(){if(Te)return Pe;Te=1;var t=ut(),e=lt(),r=Qt(),n=t(Function.toString);return e(r.inspectSource)||(r.inspectSource=function(t){return n(t)}),Pe=r.inspectSource}function Me(){if(xe)return Ee;xe=1;var t=te(),e=ne(),r=t("keys");return Ee=function(t){return r[t]||(r[t]=e(t))}}function qe(){return Ue?Re:(Ue=1,Re={})}function He(){if(Be)return De;Be=1;var t,e,r,n=function(){if(Ie)return Ae;Ie=1;var t=i(),e=lt(),r=t.WeakMap;return Ae=e(r)&&/native code/.test(String(r))}(),o=i(),a=dt(),u=Oe(),s=re(),c=Qt(),f=Me(),h=qe(),p="Object already initialized",l=o.TypeError,d=o.WeakMap;if(n||c.state){var y=c.state||(c.state=new d);y.get=y.get,y.has=y.has,y.set=y.set,t=function(t,e){if(y.has(t))throw new l(p);return e.facade=t,y.set(t,e),e},e=function(t){return y.get(t)||{}},r=function(t){return y.has(t)}}else{var v=f("state");h[v]=!0,t=function(t,e){if(s(t,v))throw new l(p);return e.facade=t,u(t,v,e),e},e=function(t){return s(t,v)?t[v]:{}},r=function(t){return s(t,v)}}return De={set:t,get:e,has:r,enforce:function(n){return r(n)?e(n):t(n,{})},getterFor:function(t){return function(r){var n;if(!a(r)||(n=e(r)).type!==t)throw new l("Incompatible receiver, "+t+" required");return n}}}}function Ge(){if(Ce)return Le.exports;Ce=1;var t=ut(),e=d(),r=lt(),n=re(),i=y(),o=ke().CONFIGURABLE,a=Ne(),u=He(),s=u.enforce,c=u.get,f=String,h=Object.defineProperty,p=t("".slice),l=t("".replace),v=t([].join),b=i&&!e((function(){return 8!==h((function(){}),"length",{value:8}).length})),g=String(String).split("String"),m=Le.exports=function(t,e,r){"Symbol("===p(f(e),0,7)&&(e="["+l(f(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),r&&r.getter&&(e="get "+e),r&&r.setter&&(e="set "+e),(!n(t,"name")||o&&t.name!==e)&&(i?h(t,"name",{value:e,configurable:!0}):t.name=e),b&&r&&n(r,"arity")&&t.length!==r.arity&&h(t,"length",{value:r.arity});try{r&&n(r,"constructor")&&r.constructor?i&&h(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch(t){}var a=s(t);return n(a,"source")||(a.source=v(g,"string"==typeof e?e:"")),t};return Function.prototype.toString=m((function(){return r(this)&&c(this).source||a(this)}),"toString"),Le.exports}function ze(){if(Fe)return _e;Fe=1;var t=lt(),e=we(),r=Ge(),n=Zt();return _e=function(i,o,a,u){u||(u={});var s=u.enumerable,c=void 0!==u.name?u.name:o;if(t(a)&&r(a,c,u),u.global)s?i[o]=a:n(o,a);else{try{u.unsafe?i[o]&&(s=!0):delete i[o]}catch(t){}s?i[o]=a:e.f(i,o,{value:a,enumerable:!1,configurable:!u.nonConfigurable,writable:!u.nonWritable})}return i}}var $e,Ve,We,Je,Xe,Ye,Ke,Ze,Qe,tr,er,rr,nr,ir,or,ar,ur,sr={};function cr(){if(Je)return We;Je=1;var t=function(){if(Ve)return $e;Ve=1;var t=Math.ceil,e=Math.floor;return $e=Math.trunc||function(r){var n=+r;return(n>0?e:t)(n)}}();return We=function(e){var r=+e;return r!=r||0===r?0:t(r)}}function fr(){if(Ye)return Xe;Ye=1;var t=cr(),e=Math.max,r=Math.min;return Xe=function(n,i){var o=t(n);return o<0?e(o+i,0):r(o,i)}}function hr(){if(Ze)return Ke;Ze=1;var t=cr(),e=Math.min;return Ke=function(r){var n=t(r);return n>0?e(n,9007199254740991):0}}function pr(){if(tr)return Qe;tr=1;var t=hr();return Qe=function(e){return t(e.length)}}function lr(){if(ir)return nr;ir=1;var t=ut(),e=re(),r=pt(),n=function(){if(rr)return er;rr=1;var t=pt(),e=fr(),r=pr(),n=function(n){return function(i,o,a){var u=t(i),s=r(u);if(0===s)return!n&&-1;var c,f=e(a,s);if(n&&o!=o){for(;s>f;)if((c=u[f++])!=c)return!0}else for(;s>f;f++)if((n||f in u)&&u[f]===o)return n||f||0;return!n&&-1}};return er={includes:n(!0),indexOf:n(!1)}}().indexOf,i=qe(),o=t([].push);return nr=function(t,a){var u,s=r(t),c=0,f=[];for(u in s)!e(i,u)&&e(s,u)&&o(f,u);for(;a.length>c;)e(s,u=a[c++])&&(~n(f,u)||o(f,u));return f}}function dr(){return ar?or:(ar=1,or=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"])}var yr,vr,br,gr,mr,wr,Or,Sr,jr,Pr,Tr,Ar,Ir,Er,xr,Rr,Ur,Dr,Br,Cr,_r,Fr,Lr,kr,Nr,Mr,qr,Hr,Gr,zr={};function $r(){if(br)return vr;br=1;var t=yt(),e=ut(),r=function(){if(ur)return sr;ur=1;var t=lr(),e=dr().concat("length","prototype");return sr.f=Object.getOwnPropertyNames||function(r){return t(r,e)},sr}(),n=(yr||(yr=1,zr.f=Object.getOwnPropertySymbols),zr),i=me(),o=e([].concat);return vr=t("Reflect","ownKeys")||function(t){var e=r.f(i(t)),a=n.f;return a?o(e,a(t)):e}}function Vr(){if(mr)return gr;mr=1;var t=re(),e=$r(),r=ce(),n=we();return gr=function(i,o,a){for(var u=e(o),s=n.f,c=r.f,f=0;ff;)r.f(t,a=s[f++],u[a]);return t},wn}(),n=dr(),i=qe(),o=Sn(),a=ue(),u=Me(),s="prototype",c="script",f=u("IE_PROTO"),h=function(){},p=function(t){return"<"+c+">"+t+""},l=function(t){t.write(p("")),t.close();var e=t.parentWindow.Object;return t=null,e},d=function(){try{t=new ActiveXObject("htmlfile")}catch(t){}var e,r,i;d="undefined"!=typeof document?document.domain&&t?l(t):(r=a("iframe"),i="java"+c+":",r.style.display="none",o.appendChild(r),r.src=String(i),(e=r.contentWindow.document).open(),e.write(p("document.F=Object")),e.close(),e.F):l(t);for(var u=n.length;u--;)delete d[s][n[u]];return d()};return i[f]=!0,cn=Object.create||function(t,n){var i;return null!==t?(h[s]=e(t),i=new h,h[s]=null,i[f]=t):i=d(),void 0===n?i:r.f(i,n)}}function Pn(){if(pn)return hn;pn=1;var t=ie(),e=jn(),r=we().f,n=t("unscopables"),i=Array.prototype;return void 0===i[n]&&r(i,n,{configurable:!0,value:e(null)}),hn=function(t){i[n][t]=!0}}function Tn(){if(ln)return n;ln=1;var t=Jr(),e=function(){if(Gr)return Hr;Gr=1;var t=Xr(),e=ct(),r=ee(),n=pr(),i=en(),o=rn(),a=function(a){var u=1===a,s=2===a,c=3===a,f=4===a,h=6===a,p=7===a,l=5===a||h;return function(d,y,v){for(var b,g,m=r(d),w=e(m),O=n(w),S=t(y,v),j=0,P=0,T=u?i(d,O):s||p?i(d,0):void 0;O>j;j++)if((l||j in w)&&(g=S(b=w[j],j,m),a))if(u)o(T,j,g);else if(g)switch(a){case 3:return!0;case 5:return b;case 6:return j;case 2:o(T,P++,b)}else switch(a){case 4:return!1;case 7:o(T,P++,b)}return h?-1:c||f?f:T}};return Hr={forEach:a(0),map:a(1),filter:a(2),some:a(3),every:a(4),find:a(5),findIndex:a(6),filterReject:a(7)}}().find,r=Pn(),i="find",o=!0;return i in[]&&Array(1)[i]((function(){o=!1})),t({target:"Array",proto:!0,forced:o},{find:function(t){return e(this,t,arguments.length>1?arguments[1]:void 0)}}),r(i),n}function An(){if(yn)return dn;yn=1;var t=i(),e=ut();return dn=function(r,n){return e(t[r].prototype[n])}}!function(){if(mn)return gn;mn=1;var t=function(){if(bn)return vn;bn=1,Tn();var t=An();return vn=t("Array","find")}();gn=t}();var In,En,xn,Rn,Un,Dn,Bn,Cn,_n,Fn,Ln,kn,Nn,Mn,qn,Hn,Gn,zn,$n,Vn,Wn,Jn,Xn,Yn,Kn,Zn,Qn,ti,ei,ri,ni,ii,oi,ai,ui,si,ci,fi,hi,pi,li,di,yi,vi,bi,gi,mi,wi,Oi,Si,ji={},Pi={};function Ti(){if(Rn)return xn;Rn=1;var t=re(),e=lt(),r=ee(),n=Me(),i=function(){if(En)return In;En=1;var t=d();return In=!t((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype}))}(),o=n("IE_PROTO"),a=Object,u=a.prototype;return xn=i?a.getPrototypeOf:function(n){var i=r(n);if(t(i,o))return i[o];var s=i.constructor;return e(s)&&i instanceof s?s.prototype:i instanceof a?u:null}}function Ai(){if(Cn)return Bn;Cn=1;var t=dt();return Bn=function(e){return t(e)||null===e}}function Ii(){if(Fn)return _n;Fn=1;var t=Ai(),e=String,r=TypeError;return _n=function(n){if(t(n))return n;throw new r("Can't set "+e(n)+" as a prototype")}}function Ei(){if(kn)return Ln;kn=1;var t=function(){if(Dn)return Un;Dn=1;var t=ut(),e=jt();return Un=function(r,n,i){try{return t(e(Object.getOwnPropertyDescriptor(r,n)[i]))}catch(t){}}}(),e=dt(),r=ht(),n=Ii();return Ln=Object.setPrototypeOf||("__proto__"in{}?function(){var i,o=!1,a={};try{(i=t(Object.prototype,"__proto__","set"))(a,[]),o=a instanceof Array}catch(t){}return function(t,a){return r(t),n(a),e(t)?(o?i(t,a):t.__proto__=a,t):t}}():void 0)}function xi(){if(Mn)return Nn;Mn=1;var t=dt(),e=Oe();return Nn=function(r,n){t(n)&&"cause"in n&&e(r,"cause",n.cause)}}function Ri(){if(Vn)return $n;Vn=1;var t=Oe(),e=function(){if(Hn)return qn;Hn=1;var t=ut(),e=Error,r=t("".replace),n=String(new e("zxcasd").stack),i=/\n\s*at [^:]*:[^\n]*/,o=i.test(n);return qn=function(t,n){if(o&&"string"==typeof t&&!e.prepareStackTrace)for(;n--;)t=r(t,i,"");return t}}(),r=function(){if(zn)return Gn;zn=1;var t=d(),e=at();return Gn=!t((function(){var t=new Error("a");return!("stack"in t)||(Object.defineProperty(t,"stack",e(1,7)),7!==t.stack)}))}(),n=Error.captureStackTrace;return $n=function(i,o,a,u){r&&(n?n(i,o):t(i,"stack",e(a,u)))}}function Ui(){return Jn?Wn:(Jn=1,Wn=Object.create?Object.create(null):{})}function Di(){if(Yn)return Xn;Yn=1;var t=ie(),e=Ui(),r=t("iterator"),n=Array.prototype;return Xn=function(t){return void 0!==t&&(e.Array===t||n[r]===t)}}function Bi(){if(Zn)return Kn;Zn=1;var t=st(),e=ft(),r=Pt(),n=ie()("iterator"),i=Array.prototype;return Kn=function(o){if(!e(o))return r(o,n)||r(o,"@@iterator")||("Arguments"===t(o)?i[n]:void 0)}}function Ci(){if(ri)return ei;ri=1;var t=b(),e=me(),r=Pt();return ei=function(n,i,o){var a,u;e(n);try{if(!(a=r(n,"return"))){if("throw"===i)throw o;return o}a=t(a,n)}catch(t){u=!0,a=t}if("throw"===i)throw o;if(u)throw a;return e(a),o}}function _i(){if(ii)return ni;ii=1;var t=Xr(),e=b(),r=me(),n=St(),i=Di(),o=pr(),a=vt(),u=function(){if(ti)return Qn;ti=1;var t=b(),e=lt(),r=me(),n=St(),i=Bi(),o=TypeError;return Qn=function(a,u){var s=arguments.length<2?i(a):u;if(e(s))return r(t(s,a));throw new o(n(a)+" is not iterable")},Qn}(),s=Bi(),c=Ci(),f=TypeError,h=function(t,e){this.stopped=t,this.result=e},p=h.prototype;return ni=function(l,d,y){var v,b,g,m,w,O,S,j=y&&y.that,P=!(!y||!y.AS_ENTRIES),T=!(!y||!y.IS_RECORD),A=!(!y||!y.IS_ITERATOR),I=!(!y||!y.INTERRUPTED),E=t(d,j),x=function(t){var e=v;return v=void 0,e&&c(e,"normal"),new h(!0,t)},R=function(t){return P?(r(t),I?E(t[0],t[1],x):E(t[0],t[1])):I?E(t,x):E(t)};if(T)v=l.iterator;else if(A)v=l;else{if(!(b=s(l)))throw new f(n(l)+" is not iterable");if(i(b)){for(g=0,m=o(l);m>g;g++)if((w=R(l[g]))&&a(p,w))return w;return new h(!1)}v=u(l,b)}for(O=T?l.next:v.next;!(S=e(O,v)).done;){var U=S.value;try{w=R(U)}catch(t){if(!v)throw t;c(v,"throw",t)}if("object"==typeof w&&w&&a(p,w))return w}return new h(!1)}}function Fi(){if(ai)return oi;ai=1;var t=Zr(),e=String;return oi=function(r){if("Symbol"===t(r))throw new TypeError("Cannot convert a Symbol value to a string");return e(r)}}function Li(){if(si)return ui;si=1;var t=Fi();return ui=function(e,r){return void 0===e?arguments.length<2?"":r:t(e)},ui}function ki(){return fi||(fi=1,function(){if(ci)return Pi;ci=1;var t=Jr(),e=vt(),r=Ti(),n=Ei(),i=Vr(),o=jn(),a=Oe(),u=at(),s=xi(),c=Ri(),f=_i(),h=Li(),p=ie()("toStringTag"),l=Error,d=[].push,y=function(t,i){var u,b=e(v,this);n?u=n(new l,b?r(this):v):(u=b?this:o(v),a(u,p,"Error")),void 0!==i&&a(u,"message",h(i)),c(u,y,u.stack,1),arguments.length>2&&s(u,arguments[2]);var g=[];return f(t,d,{that:g}),a(u,"errors",g),u};n?n(y,l):i(y,l,{name:!0});var v=y.prototype=o(l.prototype,{constructor:u(1,y),message:u(1,""),name:u(1,"AggregateError")});t({global:!0,constructor:!0,arity:2},{AggregateError:y})}()),ji}function Ni(){if(pi)return hi;pi=1;var t,e,r,n=d(),i=lt(),o=dt(),a=jn(),u=Ti(),s=ze(),c=ie(),f=Kt(),h=c("iterator"),p=!1;return[].keys&&("next"in(r=[].keys())?(e=u(u(r)))!==Object.prototype&&(t=e):p=!0),!o(t)||n((function(){var e={};return t[h].call(e)!==e}))?t={}:f&&(t=a(t)),i(t[h])||s(t,h,(function(){return this})),hi={IteratorPrototype:t,BUGGY_SAFARI_ITERATORS:p}}function Mi(){if(di)return li;di=1;var t=we().f,e=re(),r=ie()("toStringTag");return li=function(n,i,o){n&&!o&&(n=n.prototype),n&&!e(n,r)&&t(n,r,{configurable:!0,value:i})}}function qi(){if(gi)return bi;gi=1;var t=Jr(),e=b(),r=Kt(),n=ke(),i=lt(),o=function(){if(vi)return yi;vi=1;var t=Ni().IteratorPrototype,e=jn(),r=at(),n=Mi(),i=Ui(),o=function(){return this};return yi=function(a,u,s,c){var f=u+" Iterator";return a.prototype=e(t,{next:r(+!c,s)}),n(a,f,!1,!0),i[f]=o,a}}(),a=Ti(),u=Ei(),s=Mi(),c=Oe(),f=ze(),h=ie(),p=Ui(),l=Ni(),d=n.PROPER,y=n.CONFIGURABLE,v=l.IteratorPrototype,g=l.BUGGY_SAFARI_ITERATORS,m=h("iterator"),w="keys",O="values",S="entries",j=function(){return this};return bi=function(n,h,l,b,P,T,A){o(l,h,b);var I,E,x,R=function(t){if(t===P&&_)return _;if(!g&&t&&t in B)return B[t];switch(t){case w:case O:case S:return function(){return new l(this,t)}}return function(){return new l(this)}},U=h+" Iterator",D=!1,B=n.prototype,C=B[m]||B["@@iterator"]||P&&B[P],_=!g&&C||R(P),F="Array"===h&&B.entries||C;if(F&&(I=a(F.call(new n)))!==Object.prototype&&I.next&&(r||a(I)===v||(u?u(I,v):i(I[m])||f(I,m,j)),s(I,U,!0,!0),r&&(p[U]=j)),d&&P===O&&C&&C.name!==O&&(!r&&y?c(B,"name",O):(D=!0,_=function(){return e(C,this)})),P)if(E={values:R(O),keys:T?_:R(w),entries:R(S)},A)for(x in E)(g||D||!(x in B))&&f(B,x,E[x]);else t({target:h,proto:!0,forced:g||D},E);return r&&!A||B[m]===_||f(B,m,_,{name:P}),p[h]=_,E},bi}function Hi(){return wi?mi:(wi=1,mi=function(t,e){return{value:t,done:e}})}function Gi(){if(Si)return Oi;Si=1;var t=pt(),e=Pn(),r=Ui(),n=He(),i=we().f,o=qi(),a=Hi(),u=Kt(),s=y(),c="Array Iterator",f=n.set,h=n.getterFor(c);Oi=o(Array,"Array",(function(e,r){f(this,{type:c,target:t(e),index:0,kind:r})}),(function(){var t=h(this),e=t.target,r=t.index++;if(!e||r>=e.length)return t.target=null,a(void 0,!0);switch(t.kind){case"keys":return a(r,!1);case"values":return a(e[r],!1)}return a([r,e[r]],!1)}),"values");var p=r.Arguments=r.Array;if(e("keys"),e("values"),e("entries"),!u&&s&&"values"!==p.name)try{i(p,"name",{value:"values"})}catch(t){}return Oi}var zi,$i,Vi,Wi={};function Ji(){if(Vi)return Wi;Vi=1;var t=Kr(),e=ze(),r=function(){if($i)return zi;$i=1;var t=Kr(),e=Zr();return zi=t?{}.toString:function(){return"[object "+e(this)+"]"}}();return t||e(Object.prototype,"toString",r,{unsafe:!0}),Wi}var Xi,Yi,Ki,Zi,Qi,to,eo,ro,no,io,oo,ao,uo,so,co,fo,ho,po,lo,yo,vo,bo,go,mo,wo,Oo,So,jo,Po,To,Ao,Io,Eo,xo,Ro,Uo,Do,Bo,Co,_o,Fo,Lo,ko,No,Mo={},qo={};function Ho(){if(Yi)return Xi;Yi=1;var t=i(),e=bt(),r=st(),n=function(t){return e.slice(0,t.length)===t};return Xi=n("Bun/")?"BUN":n("Cloudflare-Workers")?"CLOUDFLARE":n("Deno/")?"DENO":n("Node.js/")?"NODE":t.Bun&&"string"==typeof Bun.version?"BUN":t.Deno&&"object"==typeof Deno.version?"DENO":"process"===r(t.process)?"NODE":t.window&&t.document?"BROWSER":"REST"}function Go(){if(Zi)return Ki;Zi=1;var t=Ho();return Ki="NODE"===t}function zo(){if(to)return Qi;to=1;var t=i();return Qi=t}function $o(){if(ro)return eo;ro=1;var t=Ge(),e=we();return eo=function(r,n,i){return i.get&&t(i.get,n,{getter:!0}),i.set&&t(i.set,n,{setter:!0}),e.f(r,n,i)}}function Vo(){if(io)return no;io=1;var t=yt(),e=$o(),r=ie(),n=y(),i=r("species");return no=function(r){var o=t(r);n&&o&&!o[i]&&e(o,i,{configurable:!0,get:function(){return this}})}}function Wo(){if(ao)return oo;ao=1;var t=vt(),e=TypeError;return oo=function(r,n){if(t(n,r))return r;throw new e("Incorrect invocation")}}function Jo(){if(so)return uo;so=1;var t=Qr(),e=St(),r=TypeError;return uo=function(n){if(t(n))return n;throw new r(e(n)+" is not a constructor")}}function Xo(){if(fo)return co;fo=1;var t=me(),e=Jo(),r=ft(),n=ie()("species");return co=function(i,o){var a,u=t(i).constructor;return void 0===u||r(a=t(u)[n])?o:e(a)}}function Yo(){if(po)return ho;po=1;var t=v(),e=Function.prototype,r=e.apply,n=e.call;return ho="object"==typeof Reflect&&Reflect.apply||(t?n.bind(r):function(){return n.apply(r,arguments)}),ho}function Ko(){if(yo)return lo;yo=1;var t=ut();return lo=t([].slice)}function Zo(){if(bo)return vo;bo=1;var t=TypeError;return vo=function(e,r){if(e=l?t?"":void 0:(c=o(h,p))<55296||c>56319||p+1===l||(f=o(h,p+1))<56320||f>57343?t?i(h,p):c:t?a(h,p,p+2):f-56320+(c-55296<<10)+65536}};return Ga={codeAt:u(!1),charAt:u(!0)}}().charAt,e=Fi(),r=He(),n=qi(),i=Hi(),o="String Iterator",a=r.set,u=r.getterFor(o);return n(String,"String",(function(t){a(this,{type:o,string:e(t),index:0})}),(function(){var e,r=u(this),n=r.string,o=r.index;return o>=n.length?i(void 0,!0):(e=t(n,o),r.index+=e.length,i(e,!1))})),Ja}function Ya(){if(Wa)return Va;Wa=1,ki(),Gi(),Ji(),Da(),function(){if(Ba)return Ca;Ba=1;var t=Jr(),e=b(),r=jt(),n=ha(),i=oa(),o=_i();t({target:"Promise",stat:!0,forced:ma()},{allSettled:function(t){var a=this,u=n.f(a),s=u.resolve,c=u.reject,f=i((function(){var n=r(a.resolve),i=[],u=0,c=1;o(t,(function(t){var r=u++,o=!1;c++,e(n,a,t).then((function(t){o||(o=!0,i[r]={status:"fulfilled",value:t},--c||s(i))}),(function(t){o||(o=!0,i[r]={status:"rejected",reason:t},--c||s(i))}))})),--c||s(i)}));return f.error&&c(f.value),u.promise}})}(),function(){if(_a)return Fa;_a=1;var t=Jr(),e=b(),r=jt(),n=yt(),i=ha(),o=oa(),a=_i(),u=ma(),s="No one promise resolved";t({target:"Promise",stat:!0,forced:u},{any:function(t){var u=this,c=n("AggregateError"),f=i.f(u),h=f.resolve,p=f.reject,l=o((function(){var n=r(u.resolve),i=[],o=0,f=1,l=!1;a(t,(function(t){var r=o++,a=!1;f++,e(n,u,t).then((function(t){a||l||(l=!0,h(t))}),(function(t){a||l||(a=!0,i[r]=t,--f||p(new c(i,s)))}))})),--f||p(new c(i,s))}));return l.error&&p(l.value),f.promise}})}(),function(){if(La)return ka;La=1;var t=Jr(),e=i(),r=Yo(),n=Ko(),o=Ua(),a=ha(),u=jt(),s=oa(),c=d(),f=e.Promise,h=!1;t({target:"Promise",stat:!0,forced:!f||!f.try||c((function(){var t=f.resolve();return f.try((function(e){return h=8===e,t}),8)!==t}))||!h},{try:function(t){var e=arguments.length>1?n(arguments,1):[],i=s((function(){return r(u(t),void 0,e)}));if(!i.error)return o(this,i.value);var c=a.f(this);return(0,c.reject)(i.value),c.promise}})}(),function(){if(Na)return Ma;Na=1;var t=Jr(),e=ha();t({target:"Promise",stat:!0},{withResolvers:function(){var t=e.f(this);return{promise:t.promise,resolve:t.resolve,reject:t.reject}}})}(),function(){if(qa)return Ha;qa=1;var t=Jr(),e=Kt(),r=aa(),n=d(),i=yt(),o=lt(),a=Xo(),u=Ua(),s=ze(),c=r&&r.prototype;if(t({target:"Promise",proto:!0,real:!0,forced:!!r&&n((function(){c.finally.call({then:function(){}},(function(){}))}))},{finally:function(t){var e=a(this,i("Promise")),r=o(t);return this.then(r?function(r){return u(e,t()).then((function(){return r}))}:t,r?function(r){return u(e,t()).then((function(){throw r}))}:t)}}),!e&&o(r)){var f=i("Promise").prototype.finally;c.finally!==f&&s(c,"finally",f,{unsafe:!0})}}(),Xa();var t=zo();return Va=t.Promise}var Ka,Za,Qa,tu,eu,ru,nu,iu={};function ou(){if(eu)return iu;eu=1;var t=i(),e=Za?Ka:(Za=1,Ka={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}),r=function(){if(tu)return Qa;tu=1;var t=ue()("span").classList,e=t&&t.constructor&&t.constructor.prototype;return Qa=e===Object.prototype?void 0:e}(),n=Gi(),o=Oe(),a=Mi(),u=ie()("iterator"),s=n.values,c=function(t,r){if(t){if(t[u]!==s)try{o(t,u,s)}catch(e){t[u]=s}if(a(t,r,!0),e[r])for(var i in n)if(t[i]!==n[i])try{o(t,i,n[i])}catch(e){t[i]=n[i]}}};for(var f in e)c(t[f]&&t[f].prototype,f);return c(r,"DOMTokenList"),iu}!function(){if(nu)return ru;nu=1;var t=Ya();ou(),ru=t}();var au="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{},uu="URLSearchParams"in au,su="Symbol"in au&&"iterator"in Symbol,cu="FileReader"in au&&"Blob"in au&&function(){try{return new Blob,!0}catch(t){return!1}}(),fu="FormData"in au,hu="ArrayBuffer"in au;if(hu)var pu=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],lu=ArrayBuffer.isView||function(t){return t&&pu.indexOf(Object.prototype.toString.call(t))>-1};function du(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(t)||""===t)throw new TypeError('Invalid character in header field name: "'+t+'"');return t.toLowerCase()}function yu(t){return"string"!=typeof t&&(t=String(t)),t}function vu(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return su&&(e[Symbol.iterator]=function(){return e}),e}function bu(t){this.map={},t instanceof bu?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){if(2!=t.length)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+t.length);this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function gu(t){if(!t._noBody)return t.bodyUsed?Promise.reject(new TypeError("Already read")):void(t.bodyUsed=!0)}function mu(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function wu(t){var e=new FileReader,r=mu(e);return e.readAsArrayBuffer(t),r}function Ou(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function Su(){return this.bodyUsed=!1,this._initBody=function(t){var e;this.bodyUsed=this.bodyUsed,this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:cu&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:fu&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:uu&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():hu&&cu&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=Ou(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):hu&&(ArrayBuffer.prototype.isPrototypeOf(t)||lu(t))?this._bodyArrayBuffer=Ou(t):this._bodyText=t=Object.prototype.toString.call(t):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):uu&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},cu&&(this.blob=function(){var t=gu(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var t=gu(this);return t||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}if(cu)return this.blob().then(wu);throw new Error("could not read as ArrayBuffer")},this.text=function(){var t=gu(this);if(t)return t;if(this._bodyBlob)return function(t){var e=new FileReader,r=mu(e),n=/charset=([A-Za-z0-9_-]+)/.exec(t.type),i=n?n[1]:"utf-8";return e.readAsText(t,i),r}(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal||function(){if("AbortController"in au)return(new AbortController).signal}(),this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(i),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==e.cache&&"no-cache"!==e.cache)){var o=/([?&])_=[^&]*/;if(o.test(this.url))this.url=this.url.replace(o,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function Tu(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),i=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(i))}})),e}function Au(t,e){if(!(this instanceof Au))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=void 0===e.statusText?"":""+e.statusText,this.headers=new bu(e.headers),this.url=e.url||"",this._initBody(t)}Pu.prototype.clone=function(){return new Pu(this,{body:this._bodyInit})},Su.call(Pu.prototype),Su.call(Au.prototype),Au.prototype.clone=function(){return new Au(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new bu(this.headers),url:this.url})},Au.error=function(){var t=new Au(null,{status:200,statusText:""});return t.ok=!1,t.status=0,t.type="error",t};var Iu=[301,302,303,307,308];Au.redirect=function(t,e){if(-1===Iu.indexOf(e))throw new RangeError("Invalid status code");return new Au(null,{status:e,headers:{location:t}})};var Eu=au.DOMException;try{new Eu}catch(t){(Eu=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack}).prototype=Object.create(Error.prototype),Eu.prototype.constructor=Eu}function xu(t,e){return new Promise((function(r,n){var i=new Pu(t,e);if(i.signal&&i.signal.aborted)return n(new Eu("Aborted","AbortError"));var o=new XMLHttpRequest;function a(){o.abort()}if(o.onload=function(){var t,e,n={statusText:o.statusText,headers:(t=o.getAllResponseHeaders()||"",e=new bu,t.replace(/\r?\n[\t ]+/g," ").split("\r").map((function(t){return 0===t.indexOf("\n")?t.substr(1,t.length):t})).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var i=r.join(":").trim();try{e.append(n,i)}catch(t){console.warn("Response "+t.message)}}})),e)};0===i.url.indexOf("file://")&&(o.status<200||o.status>599)?n.status=200:n.status=o.status,n.url="responseURL"in o?o.responseURL:n.headers.get("X-Request-URL");var a="response"in o?o.response:o.responseText;setTimeout((function(){r(new Au(a,n))}),0)},o.onerror=function(){setTimeout((function(){n(new TypeError("Network request failed"))}),0)},o.ontimeout=function(){setTimeout((function(){n(new TypeError("Network request timed out"))}),0)},o.onabort=function(){setTimeout((function(){n(new Eu("Aborted","AbortError"))}),0)},o.open(i.method,function(t){try{return""===t&&au.location.href?au.location.href:t}catch(e){return t}}(i.url),!0),"include"===i.credentials?o.withCredentials=!0:"omit"===i.credentials&&(o.withCredentials=!1),"responseType"in o&&(cu?o.responseType="blob":hu&&(o.responseType="arraybuffer")),e&&"object"==typeof e.headers&&!(e.headers instanceof bu||au.Headers&&e.headers instanceof au.Headers)){var u=[];Object.getOwnPropertyNames(e.headers).forEach((function(t){u.push(du(t)),o.setRequestHeader(t,yu(e.headers[t]))})),i.headers.forEach((function(t,e){-1===u.indexOf(e)&&o.setRequestHeader(e,t)}))}else i.headers.forEach((function(t,e){o.setRequestHeader(e,t)}));i.signal&&(i.signal.addEventListener("abort",a),o.onreadystatechange=function(){4===o.readyState&&i.signal.removeEventListener("abort",a)}),o.send(void 0===i._bodyInit?null:i._bodyInit)}))}xu.polyfill=!0,au.fetch||(au.fetch=xu,au.Headers=bu,au.Request=Pu,au.Response=Au);var Ru=function(){function t(){this.empty=!0,this.x=0,this.y=0,this.width=0,this.height=0}return t.prototype.reset=function(){this.empty=!0,this.x=0,this.y=0,this.width=0,this.height=0},t.prototype.set=function(t,e,r,n){void 0===r&&(r=0),void 0===n&&(n=0),this.empty=!1,this.x=t,this.y=e,this.width=r,this.height=n},t.prototype.union=function(t,e,r,n){void 0===r&&(r=0),void 0===n&&(n=0),this.empty?(this.empty=!1,this.x=t,this.y=e,this.width=r,this.height=n):(tthis.x+this.width&&(this.width=t+r-this.x),e+n>this.y+this.height&&(this.height=e+n-this.y))},t}(),Uu=function(){function t(t){this.dirtyArea=new Ru,this.canvas=t,this.context=t.getContext("2d")}return t.prototype.draw=function(t){this.canvas&&this.context&&(this.dirtyArea.empty||(this.context.clearRect(this.dirtyArea.x,this.dirtyArea.y,this.dirtyArea.width,this.dirtyArea.height),this.dirtyArea.reset()),t&&(this.canvas.width==t.width&&this.canvas.height==t.height||(this.canvas.width=t.width,this.canvas.height=t.height),this.drawSubtitleData(t,this.dirtyArea)))},t.prototype.drawSubtitleData=function(t,e){for(var r=0,n=t.compositionData;r0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]=this.length},enumerable:!1,configurable:!0}),t.prototype.readByte=function(){return this.array[this.$position++]},t.prototype.readBytes=function(t){var e=this.array.slice(this.$position,this.$position+t);return this.$position+=t,e},t}(),Fu=function(){function t(t){t instanceof Uint8Array?this.baseReader=new _u(t):this.baseReader=t}return Object.defineProperty(t.prototype,"position",{get:function(){return this.baseReader.position},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"length",{get:function(){return this.baseReader.length},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"eof",{get:function(){return this.baseReader.eof},enumerable:!1,configurable:!0}),t.prototype.readUInt8=function(){return this.baseReader.readByte()},t.prototype.readUInt16=function(){return(this.baseReader.readByte()<<8)+this.baseReader.readByte()},t.prototype.readUInt24=function(){return(this.baseReader.readByte()<<16)+(this.baseReader.readByte()<<8)+this.baseReader.readByte()},t.prototype.readUInt32=function(){return(this.baseReader.readByte()<<24)+(this.baseReader.readByte()<<16)+(this.baseReader.readByte()<<8)+this.baseReader.readByte()},t.prototype.readBytes=function(t){return this.baseReader.readBytes(t)},t}();!function(t){t[t.paletteDefinition=20]="paletteDefinition",t[t.objectDefinition=21]="objectDefinition",t[t.presentationComposition=22]="presentationComposition",t[t.windowDefinition=23]="windowDefinition",t[t.end=128]="end"}(Cu||(Cu={}));var Lu=function(){function t(){this.id=0,this.windowId=0,this.croppedFlag=0,this.horizontalPosition=0,this.verticalPosition=0,this.croppingHorizontalPosition=0,this.croppingVerticalPosition=0,this.croppingWidth=0,this.croppingHeight=0}return Object.defineProperty(t.prototype,"hasCropping",{get:function(){return!!(128&this.croppedFlag)},enumerable:!1,configurable:!0}),t}(),ku=function(){function t(){this.width=0,this.height=0,this.frameRate=0,this.compositionNumber=0,this.compositionState=0,this.paletteUpdateFlag=0,this.paletteId=0,this.compositionObjects=[]}return Object.defineProperty(t.prototype,"segmentType",{get:function(){return Cu.presentationComposition},enumerable:!1,configurable:!0}),t.prototype.read=function(t,e){this.width=t.readUInt16(),this.height=t.readUInt16(),this.frameRate=t.readUInt8(),this.compositionNumber=t.readUInt16(),this.compositionState=t.readUInt8(),this.paletteUpdateFlag=t.readUInt8(),this.paletteId=t.readUInt8();var r=t.readUInt8();this.compositionObjects=[];for(var n=0;nr?r:t},t}(),Mu=function(){function t(){this.id=0,this.versionNumber=0,this.lastInSequenceFlag=0,this.width=0,this.height=0,this.dataLength=0}return Object.defineProperty(t.prototype,"isFirstInSequence",{get:function(){return!!(128&this.lastInSequenceFlag)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isLastInSequence",{get:function(){return!!(64&this.lastInSequenceFlag)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"segmentType",{get:function(){return Cu.objectDefinition},enumerable:!1,configurable:!0}),t.prototype.read=function(t,e){this.id=t.readUInt16(),this.versionNumber=t.readUInt8(),this.lastInSequenceFlag=t.readUInt8(),this.isFirstInSequence?(this.dataLength=t.readUInt24(),this.width=t.readUInt16(),this.height=t.readUInt16(),this.data=t.readBytes(e-11)):this.data=t.readBytes(e-4)},t}(),qu=function(){this.id=0,this.horizontalPosition=0,this.verticalPosition=0,this.width=0,this.height=0},Hu=function(){function t(){this.windows=[]}return Object.defineProperty(t.prototype,"segmentType",{get:function(){return Cu.windowDefinition},enumerable:!1,configurable:!0}),t.prototype.read=function(t,e){var r=t.readUInt8();this.windows=[];for(var n=0;n=this.length},enumerable:!1,configurable:!0}),t.prototype.readByte=function(){for(;this.subReaders[this.subReaderIndex].position>=this.subReaders[this.subReaderIndex].length;)this.subReaderIndex++;return this.$position++,this.subReaders[this.subReaderIndex].readByte()},t.prototype.readBytes=function(t){for(var e=new Uint8Array(t),r=0;rthis.reader.length&&!this.$eof?[4,this.stream.read()]:[3,2];case 1:return e=i.sent(),r=e.value,n=e.done,r&&this.reader.push(r),n&&(this.$eof=!0),[3,0];case 2:return[2,this.reader.position+t<=this.reader.length]}}))}))},t}(),Vu=function(t,e,r){this.width=t,this.height=e,this.compositionData=r},Wu=function(t,e,r){this.compositionObject=t,this.window=e,this.pixelData=r},Ju=function(){function t(){}return t.decode=function(t,e,r){t instanceof Uint8Array&&(t=new _u(t));for(var n=0;t.position0&&rr)break;n++}return n},t}(),Yu=new(function(){function t(){this.displaySets=[],this.updateTimestamps=[]}return t.prototype.loadFromUrl=function(t,e){return Du(this,void 0,void 0,(function(){var r,n,i,o,a;return Bu(this,(function(u){switch(u.label){case 0:return[4,fetch(t)];case 1:if(!(r=u.sent()).ok)throw new Error("HTTP error: ".concat(r.status));return(n=null===(a=r.body)||void 0===a?void 0:a.getReader())?(i=new $u(n),[3,4]):[3,2];case 2:return[4,r.arrayBuffer()];case 3:o=u.sent(),i=new _u(new Uint8Array(o)),u.label=4;case 4:return[4,this.loadFromReader(i,e)];case 5:return u.sent(),[2]}}))}))},t.prototype.loadFromBuffer=function(t,e){return Du(this,void 0,void 0,(function(){return Bu(this,(function(r){switch(r.label){case 0:return[4,this.loadFromReader(new _u(new Uint8Array(t)),e)];case 1:return r.sent(),[2]}}))}))},t.prototype.loadFromReader=function(t,e){return Du(this,void 0,void 0,(function(){var r,n,i,o;return Bu(this,(function(a){switch(a.label){case 0:this.displaySets=[],this.updateTimestamps=[],this.cachedSubtitleData=void 0,r=performance.now(),n=new Fu(t),a.label=1;case 1:return t.eof?[3,3]:[4,(i=new Gu).read(n,!0)];case 2:return a.sent(),this.displaySets.push(i),this.updateTimestamps.push(i.presentationTimestamp),(null==e?void 0:e.onProgress)&&(o=performance.now())>r+1e3&&(r=o,e.onProgress()),[3,1];case 3:return(null==e?void 0:e.onProgress)&&e.onProgress(),[2]}}))}))},t.prototype.cacheSubtitleAtIndex=function(t){var e=this.getSubtitleAtIndex(t);this.cachedSubtitleData={index:t,data:e}},t.prototype.getSubtitleAtTimestamp=function(t){var e=Xu.getIndexFromTimestamps(t,this.updateTimestamps);return this.getSubtitleAtIndex(e)},t.prototype.getSubtitleAtIndex=function(t){var e;if(this.cachedSubtitleData&&this.cachedSubtitleData.index===t)return this.cachedSubtitleData.data;if(!(t<0||t>=this.displaySets.length)){var r=this.displaySets[t];if(r.presentationComposition){for(var n=[],i=[],o=[],a=t;a>=0;){var u=this.displaySets[a];n.unshift.apply(n,u.objectDefinitions),i.unshift.apply(i,u.paletteDefinitions);for(var s=0,c=u.windowDefinitions;s void; +} +/** + * The PGS subtitle data class. This can load and cache sup files from a buffer or url. + * It can also build image data for a given timestamp or timestamp index. + */ +export declare class Pgs { + /** + * The currently loaded display sets. + */ + displaySets: DisplaySet[]; + /** + * The PGS timestamps when a display set with the same index is presented. + */ + updateTimestamps: number[]; + /** + * Loads the subtitle file from the given url. + * @param url The url to the PGS file. + * @param options Optional loading options. Use `onProgress` as callback for partial update while loading. + */ + loadFromUrl(url: string, options?: PgsLoadOptions): Promise; + /** + * Loads the subtitle file from the given buffer. + * @param buffer The PGS data. + * @param options Optional loading options. Use `onProgress` as callback for partial update while loading. + */ + loadFromBuffer(buffer: ArrayBuffer, options?: PgsLoadOptions): Promise; + /** + * Loads the subtitle file from the given buffer. + * @param reader The PGS data reader. + * @param options Optional loading options. Use `onProgress` as callback for partial update while loading. + */ + loadFromReader(reader: BinaryReader, options?: PgsLoadOptions): Promise; + private cachedSubtitleData?; + /** + * Pre-compiles and caches the subtitle data for the given index. + * This will speed up the next call to `buildSubtitleDataAtIndex` with the same index. + * @param index The index of the display set to cache. + */ + cacheSubtitleAtIndex(index: number): void; + /** + * Renders the subtitle at the given timestamp. + * @param time The timestamp in seconds. + */ + getSubtitleAtTimestamp(time: number): SubtitleData | undefined; + /** + * Pre-compiles the required subtitle data (windows and pixel data) for the frame at the given index. + * @param index The index of the display set to render. + */ + getSubtitleAtIndex(index: number): SubtitleData | undefined; + private getPixelDataFromComposition; +} diff --git a/dist/pgs/displaySet.d.ts b/dist/pgs/displaySet.d.ts new file mode 100644 index 0000000..f98deb6 --- /dev/null +++ b/dist/pgs/displaySet.d.ts @@ -0,0 +1,23 @@ +import { BigEndianBinaryReader } from "../utils/bigEndianBinaryReader"; +import { PresentationCompositionSegment } from "./presentationCompositionSegment"; +import { PaletteDefinitionSegment } from "./paletteDefinitionSegment"; +import { ObjectDefinitionSegment } from "./objectDefinitionSegment"; +import { WindowDefinitionSegment } from "./windowDefinitionSegment"; +/** + * The PGS display set holds all data for the current subtitle update at a given timestamp. + */ +export declare class DisplaySet { + presentationTimestamp: number; + decodingTimestamp: number; + presentationComposition?: PresentationCompositionSegment; + paletteDefinitions: PaletteDefinitionSegment[]; + objectDefinitions: ObjectDefinitionSegment[]; + windowDefinitions: WindowDefinitionSegment[]; + /** + * Reads a display set from the given binary reader. The current data is cleared. + * @param reader The binary reader to read from. + * @param includeHeader If true, the magic-number and timestamps are read. If false, reading starts at the first + * segment. + */ + read(reader: BigEndianBinaryReader, includeHeader: boolean): Promise; +} diff --git a/dist/pgs/endSegment.d.ts b/dist/pgs/endSegment.d.ts new file mode 100644 index 0000000..24d24f8 --- /dev/null +++ b/dist/pgs/endSegment.d.ts @@ -0,0 +1,6 @@ +import { BigEndianBinaryReader } from "../utils/bigEndianBinaryReader"; +import { Segment } from "./segment"; +export declare class EndSegment implements Segment { + get segmentType(): number; + read(reader: BigEndianBinaryReader, length: number): void; +} diff --git a/dist/pgs/objectDefinitionSegment.d.ts b/dist/pgs/objectDefinitionSegment.d.ts new file mode 100644 index 0000000..0a0c789 --- /dev/null +++ b/dist/pgs/objectDefinitionSegment.d.ts @@ -0,0 +1,15 @@ +import { Segment } from "./segment"; +import { BigEndianBinaryReader } from "../utils/bigEndianBinaryReader"; +export declare class ObjectDefinitionSegment implements Segment { + id: number; + versionNumber: number; + lastInSequenceFlag: number; + width: number; + height: number; + dataLength: number; + data?: Uint8Array; + get isFirstInSequence(): boolean; + get isLastInSequence(): boolean; + get segmentType(): number; + read(reader: BigEndianBinaryReader, length: number): void; +} diff --git a/dist/pgs/paletteDefinitionSegment.d.ts b/dist/pgs/paletteDefinitionSegment.d.ts new file mode 100644 index 0000000..a7ad31c --- /dev/null +++ b/dist/pgs/paletteDefinitionSegment.d.ts @@ -0,0 +1,10 @@ +import { Segment } from "./segment"; +import { BigEndianBinaryReader } from "../utils/bigEndianBinaryReader"; +export declare class PaletteDefinitionSegment implements Segment { + id: number; + versionNumber: number; + rgba: number[]; + get segmentType(): number; + read(reader: BigEndianBinaryReader, length: number): void; + private static clamp; +} diff --git a/dist/pgs/presentationCompositionSegment.d.ts b/dist/pgs/presentationCompositionSegment.d.ts new file mode 100644 index 0000000..123877b --- /dev/null +++ b/dist/pgs/presentationCompositionSegment.d.ts @@ -0,0 +1,26 @@ +import { Segment } from "./segment"; +import { BigEndianBinaryReader } from "../utils/bigEndianBinaryReader"; +export declare class CompositionObject { + id: number; + windowId: number; + croppedFlag: number; + horizontalPosition: number; + verticalPosition: number; + croppingHorizontalPosition: number; + croppingVerticalPosition: number; + croppingWidth: number; + croppingHeight: number; + get hasCropping(): boolean; +} +export declare class PresentationCompositionSegment implements Segment { + width: number; + height: number; + frameRate: number; + compositionNumber: number; + compositionState: number; + paletteUpdateFlag: number; + paletteId: number; + compositionObjects: CompositionObject[]; + get segmentType(): number; + read(reader: BigEndianBinaryReader, length: number): void; +} diff --git a/dist/pgs/segment.d.ts b/dist/pgs/segment.d.ts new file mode 100644 index 0000000..3f6a6c5 --- /dev/null +++ b/dist/pgs/segment.d.ts @@ -0,0 +1,13 @@ +import { BigEndianBinaryReader } from "../utils/bigEndianBinaryReader"; +export interface Segment { + /** + * Gets the {@link SegmentType} identifier byte. + */ + get segmentType(): number; + /** + * Reads the segment from the data stream. + * @param reader The binary reader to read from. + * @param length The length of the segment in bytes. + */ + read(reader: BigEndianBinaryReader, length: number): void; +} diff --git a/dist/pgs/segmentType.d.ts b/dist/pgs/segmentType.d.ts new file mode 100644 index 0000000..a8019b8 --- /dev/null +++ b/dist/pgs/segmentType.d.ts @@ -0,0 +1,7 @@ +export declare enum SegmentType { + paletteDefinition = 20, + objectDefinition = 21, + presentationComposition = 22, + windowDefinition = 23, + end = 128 +} diff --git a/dist/pgs/windowDefinitionSegment.d.ts b/dist/pgs/windowDefinitionSegment.d.ts new file mode 100644 index 0000000..15825ed --- /dev/null +++ b/dist/pgs/windowDefinitionSegment.d.ts @@ -0,0 +1,14 @@ +import { Segment } from "./segment"; +import { BigEndianBinaryReader } from "../utils/bigEndianBinaryReader"; +export declare class WindowDefinition { + id: number; + horizontalPosition: number; + verticalPosition: number; + width: number; + height: number; +} +export declare class WindowDefinitionSegment implements Segment { + windows: WindowDefinition[]; + get segmentType(): number; + read(reader: BigEndianBinaryReader, length: number): void; +} diff --git a/dist/pgsRenderer.d.ts b/dist/pgsRenderer.d.ts new file mode 100644 index 0000000..d3c5b39 --- /dev/null +++ b/dist/pgsRenderer.d.ts @@ -0,0 +1,70 @@ +import { PgsRendererOptions } from "./pgsRendererOptions"; +/** + * Renders PGS subtitle on-top of a video element using a canvas element. This also handles timestamp updates if a + * video element is provided. + */ +export declare class PgsRenderer { + /** + * Creates and starts a PGS subtitle render with the given option. + * @param options The PGS renderer options. + */ + constructor(options: PgsRendererOptions); + /** + * Creates the PGS renderer implementation for the given option. + * @param options The PGS renderer options. + */ + private createPgsRenderer; + private implementation; + /** + * Resolves once the last loaded subtitle file - `subUrl` included - can be rendered. + */ + ready: Promise; + /** + * Loads the subtitle file from the given url. + * @param url The url to the PGS file. + */ + loadFromUrl(url: string): Promise; + /** + * Loads the subtitle file from the given buffer. + * @param buffer The PGS data. + */ + loadFromBuffer(buffer: ArrayBuffer): Promise; + /** + * Renders the subtitle for the given timestamp. + * @param time The timestamp in seconds. + */ + renderAtTimestamp(time: number): void; + private readonly video?; + private $timeOffset; + /** + * Gets the video-to-subtitle time offset in seconds. + */ + get timeOffset(): number; + /** + * Sets the video-to-subtitle time offset and re-renders the current subtitle if needed. + * @param timeOffset The new time offset in seconds. + */ + set timeOffset(timeOffset: number); + private registerVideoEvents; + private unregisterVideoEvents; + private onTimeUpdate; + private renderAtVideoTimestamp; + private readonly canvas; + private readonly canvasOwner; + private createCanvasElement; + private destroyCanvasElement; + private $aspectRatio; + /** + * Gets the aspect ratio mode of the canvas. + */ + get aspectRatio(): 'contain' | 'cover' | 'fill'; + /** + * Sets the aspect ratio mode of the canvas. This should match the `object-fit` property of the video. + * @param aspectMode The aspect mode. + */ + set aspectRatio(aspectMode: 'contain' | 'cover' | 'fill'); + /** + * Destroys the subtitle canvas and removes event listeners. + */ + dispose(): void; +} diff --git a/dist/pgsRendererHelper.d.ts b/dist/pgsRendererHelper.d.ts new file mode 100644 index 0000000..a68f83e --- /dev/null +++ b/dist/pgsRendererHelper.d.ts @@ -0,0 +1,9 @@ +export declare class PgsRendererHelper { + /** + * Returns the array index position for the previous timestamp position from the given array. + * Returns -1 if the given time is outside the timestamp range. + * @param time The timestamp to check in seconds. + * @param pgsTimestamps The list of available PGS timestamps. + */ + static getIndexFromTimestamps(time: number, pgsTimestamps: number[]): number; +} diff --git a/dist/pgsRendererImpl.d.ts b/dist/pgsRendererImpl.d.ts new file mode 100644 index 0000000..5911244 --- /dev/null +++ b/dist/pgsRendererImpl.d.ts @@ -0,0 +1,47 @@ +/** + * The base for handling pgs loading and rendering. There are different ways to render a subtitle file. Modern browser + * support a more efficient asynchrone method using a web-worker. But if this isn't working for the current browser + * a more compatible implementation can be used. + */ +export declare abstract class PgsRendererImpl { + private updateTimestamps; + private previousTimestampIndex; + /** + * Is called when the timestamps were updated. + */ + onTimestampsUpdated?: () => void; + /** + * Sets the update timestamps and invokes an update event. + * @param updateTimestamps The new array of update timestamps. + */ + protected setUpdateTimestamps(updateTimestamps: number[]): void; + /** + * Renders the subtitle for the given timestamp. + * @param time The timestamp in seconds. + */ + renderAtTimestamp(time: number): void; + /** + * Renders the subtitle at the given timestamp index. + * @param index The timestamp index. + */ + renderAtIndex(index: number): void; + /** + * Renders the subtitle at the given timestamp index. Internal render method to overwrite. + * @param index The timestamp index. + */ + protected abstract render(index: number): void; + /** + * Loads the subtitle file from the given url. + * @param url The url to the PGS file. + */ + abstract loadFromUrl(url: string): Promise; + /** + * Loads the subtitle file from the given buffer. + * @param buffer The PGS data. + */ + abstract loadFromBuffer(buffer: ArrayBuffer): Promise; + /** + * Disposes the renderer. + */ + abstract dispose(): void; +} diff --git a/dist/pgsRendererInMainThread.d.ts b/dist/pgsRendererInMainThread.d.ts new file mode 100644 index 0000000..1e830eb --- /dev/null +++ b/dist/pgsRendererInMainThread.d.ts @@ -0,0 +1,29 @@ +import { PgsRendererImpl } from "./pgsRendererImpl"; +import { PgsRendererOptions } from "./pgsRendererOptions"; +/** + * The implementation without web workers. This loads and renders the subtitle in the main thread. + * This is meant as a compatibility fallback if advanced workers are not supported. + */ +export declare class PgsRendererInMainThread extends PgsRendererImpl { + constructor(options: PgsRendererOptions, canvas: HTMLCanvasElement); + /** + * The PGS loader. + * @private + */ + private readonly pgs; + /** + * The subtitle renderer, running in the main thread. + */ + private readonly renderer; + protected render(index: number): void; + loadFromUrl(url: string): Promise; + loadFromBuffer(buffer: ArrayBuffer): Promise; + /** + * Submits the update timestamps from the pgs loader and invokes events. + */ + private invokeTimestampsUpdate; + /** + * Disposes the renderer. + */ + dispose(): void; +} diff --git a/dist/pgsRendererInWorker.d.ts b/dist/pgsRendererInWorker.d.ts new file mode 100644 index 0000000..aeae6c7 --- /dev/null +++ b/dist/pgsRendererInWorker.d.ts @@ -0,0 +1,32 @@ +import { PgsRendererImpl } from "./pgsRendererImpl"; +import { PgsRendererOptions } from "./pgsRendererOptions"; +/** + * The base implementation for a pgs renderer in side a worker. + */ +export declare abstract class PgsRendererInWorker extends PgsRendererImpl { + protected constructor(options: PgsRendererOptions); + loadFromUrl(url: string): Promise; + loadFromBuffer(buffer: ArrayBuffer): Promise; + /** + * The background worker. + */ + protected readonly worker: Worker; + /** + * The loads the worker still has to answer, in the order it answers them. + */ + private readonly pendingLoads; + /** + * Handles messages from the worker. + * @param e The event message. + */ + private readonly $onWorkerMessage; + /** + * Handles messages from the worker. + * @param e The event message. + */ + protected onWorkerMessage(e: MessageEvent): void; + /** + * Disposes the renderer and terminates the worker. + */ + dispose(): void; +} diff --git a/dist/pgsRendererInWorkerWithOffscreenCanvas.d.ts b/dist/pgsRendererInWorkerWithOffscreenCanvas.d.ts new file mode 100644 index 0000000..21fb02b --- /dev/null +++ b/dist/pgsRendererInWorkerWithOffscreenCanvas.d.ts @@ -0,0 +1,10 @@ +import { PgsRendererOptions } from "./pgsRendererOptions"; +import { PgsRendererInWorker } from "./pgsRendererInWorker"; +/** + * A subtitle renderer running fully in a web-worker. It loads and renders the subtitles in the web-worker. + * This requires browser support for web-workers and offscreen-canvas. + */ +export declare class PgsRendererInWorkerWithOffscreenCanvas extends PgsRendererInWorker { + constructor(options: PgsRendererOptions, canvas: HTMLCanvasElement); + protected render(index: number): void; +} diff --git a/dist/pgsRendererInWorkerWithoutOffscreenCanvas.d.ts b/dist/pgsRendererInWorkerWithoutOffscreenCanvas.d.ts new file mode 100644 index 0000000..5f82244 --- /dev/null +++ b/dist/pgsRendererInWorkerWithoutOffscreenCanvas.d.ts @@ -0,0 +1,15 @@ +import { PgsRendererInWorker } from "./pgsRendererInWorker"; +import { PgsRendererOptions } from "./pgsRendererOptions"; +/** + * A subtitle renderer running partially in a web-worker. It loads the subtitles in the web-worker, but rendering is + * done on the main thread. This still requires web-workers, but skips the requirement of the offscreen-canvas. + */ +export declare class PgsRendererInWorkerWithoutOffscreenCanvas extends PgsRendererInWorker { + constructor(options: PgsRendererOptions, canvas: HTMLCanvasElement); + /** + * The subtitle renderer, running in the main thread. + */ + private readonly renderer; + protected render(index: number): void; + protected onWorkerMessage(e: MessageEvent): void; +} diff --git a/dist/pgsRendererMode.d.ts b/dist/pgsRendererMode.d.ts new file mode 100644 index 0000000..3afd9fe --- /dev/null +++ b/dist/pgsRendererMode.d.ts @@ -0,0 +1,14 @@ +export declare enum PgsRendererMode { + /** + * A worker thread is used to load, build and render the subtitles. This requires OffscreenCanvas support. + */ + worker = "worker", + /** + * A worker thread is used to load and build the subtitles. They are rendered in the main thread. + */ + workerWithoutOffscreenCanvas = "workerWithoutOffscreenCanvas", + /** + * The subtitles are loaded, built and rendered in the main thread. + */ + mainThread = "mainThread" +} diff --git a/dist/pgsRendererOptions.d.ts b/dist/pgsRendererOptions.d.ts new file mode 100644 index 0000000..88e1053 --- /dev/null +++ b/dist/pgsRendererOptions.d.ts @@ -0,0 +1,34 @@ +import { PgsRendererMode } from "./pgsRendererMode"; +export interface PgsRendererOptions { + /** + * The video element to sync the subtitle to. + * Optional, if you provide a custom canvas and use `renderAtTimestamp` to manually update the timestamp. + */ + video?: HTMLVideoElement; + /** + * The initial canvas element to draw the subtitles to. + * If not provided, the renderer creates its own canvas next to the video element. + */ + canvas?: HTMLCanvasElement; + /** + * The video-to-subtitle time offset in seconds. + */ + timeOffset?: number; + /** + * The canvas aspect ratio mode. This should match the `object-fit` property of the video. + */ + aspectRatio?: 'contain' | 'cover' | 'fill'; + /** + * The initial subtitle file url to load from. + */ + subUrl?: string; + /** + * The url to the worker javascript file. + */ + workerUrl?: string; + /** + * The forced renderer mode. + * If not provided, the renderer checks the current browser to detect the best mode for your platform. + */ + mode?: PgsRendererMode; +} diff --git a/dist/renderer.d.ts b/dist/renderer.d.ts new file mode 100644 index 0000000..53f1bc7 --- /dev/null +++ b/dist/renderer.d.ts @@ -0,0 +1,28 @@ +import { SubtitleData } from "./subtitleData"; +/** + * This handles the low-level PGS loading and rendering. This renderer can operate inside the web worker without being + * linked to a video element. + */ +export declare class Renderer { + private readonly canvas; + private readonly context; + private readonly dirtyArea; + constructor(canvas: OffscreenCanvas | HTMLCanvasElement); + /** + * Renders the given subtitle data to the canvas. + * @param subtitleData The pre-compiled subtitle data to render. + */ + draw(subtitleData?: SubtitleData): void; + /** + * Draws the whole subtitle frame to the given context. + * @param subtitleData The subtitle data to draw. + * @param dirtyArea If given, it will extend the dirty rect to include the affected subtitle area. + */ + private drawSubtitleData; + /** + * Draws this subtitle composition to the given context. + * @param compositionData The subtitle composition data to draw. + * @param dirtyArea If given, it will extend the dirty rect to include the affected subtitle area. + */ + private drawSubtitleCompositionData; +} diff --git a/dist/subtitleData.d.ts b/dist/subtitleData.d.ts new file mode 100644 index 0000000..82338e4 --- /dev/null +++ b/dist/subtitleData.d.ts @@ -0,0 +1,38 @@ +import { WindowDefinition } from "./pgs/windowDefinitionSegment"; +import { CompositionObject } from "./pgs/presentationCompositionSegment"; +/** + * This class contains the compiled subtitle data for a whole frame. + */ +export declare class SubtitleData { + /** + * The total width of the presentation composition (screen). + */ + readonly width: number; + /** + * The total height of the presentation composition (screen). + */ + readonly height: number; + /** + * The pre-compiled composition elements. + */ + readonly compositionData: SubtitleCompositionData[]; + constructor(width: number, height: number, compositionData: SubtitleCompositionData[]); +} +/** + * This class contains the compiled subtitle data for a single composition. + */ +export declare class SubtitleCompositionData { + /** + * The original composition object of the subtile data. + */ + readonly compositionObject: CompositionObject; + /** + * The pgs window to draw on (the on-screen position). + */ + readonly window: WindowDefinition; + /** + * The compiled pixel data of the subtitle. + */ + readonly pixelData: ImageData; + constructor(compositionObject: CompositionObject, window: WindowDefinition, pixelData: ImageData); +} diff --git a/dist/utils/arrayBinaryReader.d.ts b/dist/utils/arrayBinaryReader.d.ts new file mode 100644 index 0000000..5a48b4b --- /dev/null +++ b/dist/utils/arrayBinaryReader.d.ts @@ -0,0 +1,14 @@ +import { BinaryReader } from "./binaryReader"; +/** + * A binary reader based on a {@link Uint8Array}. + */ +export declare class ArrayBinaryReader implements BinaryReader { + private readonly array; + private $position; + constructor(array: Uint8Array); + get position(): number; + get length(): number; + get eof(): boolean; + readByte(): number; + readBytes(count: number): Uint8Array; +} diff --git a/dist/utils/asyncBinaryReader.d.ts b/dist/utils/asyncBinaryReader.d.ts new file mode 100644 index 0000000..c2fb516 --- /dev/null +++ b/dist/utils/asyncBinaryReader.d.ts @@ -0,0 +1,10 @@ +import { BinaryReader } from "./binaryReader"; +export interface AsyncBinaryReader extends BinaryReader { + /** + * Ensures that the given number of bytes is available to read synchronously. + * This will wait until the data is ready to read. + * @param count The number of bytes requested. + * @return Returns if the requested number of bytes could be loaded. + */ + requestData(count: number): Promise; +} diff --git a/dist/utils/bigEndianBinaryReader.d.ts b/dist/utils/bigEndianBinaryReader.d.ts new file mode 100644 index 0000000..851da92 --- /dev/null +++ b/dist/utils/bigEndianBinaryReader.d.ts @@ -0,0 +1,16 @@ +import { BinaryReader } from "./binaryReader"; +export declare class BigEndianBinaryReader { + /** + * The base binary reader. + */ + readonly baseReader: BinaryReader; + constructor(buffer: BinaryReader | Uint8Array); + get position(): number; + get length(): number; + get eof(): boolean; + readUInt8(): number; + readUInt16(): number; + readUInt24(): number; + readUInt32(): number; + readBytes(count: number): Uint8Array; +} diff --git a/dist/utils/binaryReader.d.ts b/dist/utils/binaryReader.d.ts new file mode 100644 index 0000000..1edbd7d --- /dev/null +++ b/dist/utils/binaryReader.d.ts @@ -0,0 +1,23 @@ +export interface BinaryReader { + /** + * Gets the current position in the binary buffer. + */ + get position(): number; + /** + * Gets the length of the binary buffer. + */ + get length(): number; + /** + * Gets if the binary reader has reached the end of the data. + */ + get eof(): boolean; + /** + * Reads a single byte from this buffer. + */ + readByte(): number; + /** + * Reads the given number of bytes from the buffer. + * @param count The number of bytes to read. + */ + readBytes(count: number): Uint8Array; +} diff --git a/dist/utils/combinedBinaryReader.d.ts b/dist/utils/combinedBinaryReader.d.ts new file mode 100644 index 0000000..86762de --- /dev/null +++ b/dist/utils/combinedBinaryReader.d.ts @@ -0,0 +1,21 @@ +import { BinaryReader } from "./binaryReader"; +/** + * A binary reader that combines multiple binary readers in one data stream. + */ +export declare class CombinedBinaryReader implements BinaryReader { + private readonly subReaders; + private $length; + private $position; + private subReaderIndex; + constructor(subReaders: BinaryReader[] | Uint8Array[]); + /** + * Adding another sub-reader to the collection. + * @param subReader The new sub-reader to add. + */ + push(subReader: BinaryReader | Uint8Array): void; + get position(): number; + get length(): number; + get eof(): boolean; + readByte(): number; + readBytes(count: number): Uint8Array; +} diff --git a/dist/utils/rect.d.ts b/dist/utils/rect.d.ts new file mode 100644 index 0000000..ef909b5 --- /dev/null +++ b/dist/utils/rect.d.ts @@ -0,0 +1,45 @@ +/** + * A simple rectangular class. + */ +export declare class Rect { + /** + * Gets if the rect is still empty and doesn't contain any area. + */ + empty: boolean; + /** + * Gets the x coordinate of the rectangular area if not empty. + */ + x: number; + /** + * Gets the y coordinate of the rectangular area if not empty. + */ + y: number; + /** + * Gets the width of the rectangular area if not empty. + */ + width: number; + /** + * Gets the height of the rectangular area if not empty. + */ + height: number; + /** + * Clears the rectangular. + */ + reset(): void; + /** + * Grows this rectangular area to include the given area. + * @param x The x coordinate of the new area. + * @param y The y coordinate of the new area. + * @param width The width of the new area. Negative values are not supported. + * @param height The height of the new area. Negative values are not supported. + */ + set(x: number, y: number, width?: number, height?: number): void; + /** + * Grows this rectangular area to include the given area. + * @param x The x coordinate of the new area to include. + * @param y The y coordinate of the new area to include. + * @param width The width of the new area to include. Negative values are not supported. + * @param height The height of the new area to include. Negative values are not supported. + */ + union(x: number, y: number, width?: number, height?: number): void; +} diff --git a/dist/utils/runLengthEncoding.d.ts b/dist/utils/runLengthEncoding.d.ts new file mode 100644 index 0000000..1aa9a7a --- /dev/null +++ b/dist/utils/runLengthEncoding.d.ts @@ -0,0 +1,14 @@ +import { BinaryReader } from "./binaryReader"; +/** + * Handles run length encoded images. + */ +export declare abstract class RunLengthEncoding { + /** + * Decodes the run length encoded image. + * @param reader The run length encoded binary data reader or buffer. + * @param source The source maps the index value to the raw output pixel data. + * @param target The pixel data is written to the output. + * @return Returns the number of decoded pixels. + */ + static decode(reader: BinaryReader | Uint8Array, source: number[] | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array, target: number[] | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array): number; +} diff --git a/dist/utils/streamBinaryReader.d.ts b/dist/utils/streamBinaryReader.d.ts new file mode 100644 index 0000000..5ddc791 --- /dev/null +++ b/dist/utils/streamBinaryReader.d.ts @@ -0,0 +1,16 @@ +import { AsyncBinaryReader } from "./asyncBinaryReader"; +/** + * A binary reader based on a readable stream. This can read a partially loaded stream - for example a download. + */ +export declare class StreamBinaryReader implements AsyncBinaryReader { + private readonly stream; + private readonly reader; + private $eof; + constructor(stream: ReadableStreamDefaultReader); + get position(): number; + get length(): number; + get eof(): boolean; + readByte(): number; + readBytes(count: number): Uint8Array; + requestData(count?: number): Promise; +} diff --git a/dist/worker.d.ts b/dist/worker.d.ts new file mode 100644 index 0000000..866d261 --- /dev/null +++ b/dist/worker.d.ts @@ -0,0 +1,3 @@ +import "core-js/stable/array/find"; +import "core-js/stable/promise"; +import "whatwg-fetch";