@aim-packages/subtitle 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1,12 +1,12 @@
1
- "use strict";var re=Object.defineProperty;var ne=(t,e,r)=>e in t?re(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var d=(t,e,r)=>ne(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function I(t,e=2){return t.toString().padStart(e,"0")}function M(t){const e=Math.floor(t/3600),r=Math.floor(t%3600/60),n=t%3600%60,i=Math.floor(n%1*1e3),s=I(e),o=I(r),f=I(Math.floor(n)),a=I(i,3);return`${s}:${o}:${f}.${a}`}function z(t){if(!t)return 0;const e=t.split(":");try{let r=e[2].split(",");return r.length===1&&(r=e[2].split(".")),parseFloat(e[0])*3600+parseFloat(e[1])*60+parseFloat(r[0])+parseFloat("0."+r[1])}catch{return 0}}function ae(t){return/[\u4E00-\u9FFF\u3040-\u309F\u30A0-\u30FF\uAC00-\uD7AF]/.test(t)}const ie=Object.freeze(Object.defineProperty({__proto__:null,containsCJKCharacters:ae,convertToSeconds:z,formatTime:M,padNumber:I},Symbol.toStringTag,{value:"Module"}));/**
1
+ "use strict";var me=Object.defineProperty;var je=(t,e,r)=>e in t?me(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var y=(t,e,r)=>je(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function D(t,e=2){return t.toString().padStart(e,"0")}function S(t){const e=Math.floor(t/3600),r=Math.floor(t%3600/60),n=t%3600%60,a=Math.floor(n%1*1e3),o=D(e),i=D(r),f=D(Math.floor(n)),s=D(a,3);return`${o}:${i}:${f}.${s}`}function $(t){if(!t)return 0;const e=t.split(":");try{let r=e[2].split(",");return r.length===1&&(r=e[2].split(".")),parseFloat(e[0])*3600+parseFloat(e[1])*60+parseFloat(r[0])+parseFloat("0."+r[1])}catch{return 0}}function Kt(t){return/[\u4E00-\u9FFF\u3040-\u309F\u30A0-\u30FF\uAC00-\uD7AF]/.test(t)}const Se=Object.freeze(Object.defineProperty({__proto__:null,containsCJKCharacters:Kt,convertToSeconds:$,formatTime:S,padNumber:D},Symbol.toStringTag,{value:"Module"}));/**
2
2
  * @name ass2vtt
3
3
  * @desc Converts ASS subtitle data into VTT format.
4
4
  * @author YuQian2015 (https://github.com/YuQian2015)
5
5
  * @license MIT
6
- */function se(t){const e=new RegExp("Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$","i");function r(n=""){return n.split(/[:.]/).map((i,s,o)=>{if(s===o.length-1){if(i.length===1)return"."+i+"00";if(i.length===2)return"."+i+"0"}else if(i.length===1)return(s===0?"0":":0")+i;return s===0?i:s===o.length-1?"."+i:":"+i}).join("")}return`WEBVTT
6
+ */function $e(t){const e=new RegExp("Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$","i");function r(n=""){return n.split(/[:.]/).map((a,o,i)=>{if(o===i.length-1){if(a.length===1)return"."+a+"00";if(a.length===2)return"."+a+"0"}else if(a.length===1)return(o===0?"0":":0")+a;return o===0?a:o===i.length-1?"."+a:":"+a}).join("")}return`WEBVTT
7
7
 
8
- `+t.split(/\r?\n/).map(n=>{const i=n.match(e);return i?{start:r(i[1].trim()),end:r(i[2].trim()),text:i[5].replace(/{[\s\S]*?}/g,"").replace(/(\\N)/g,"<br />").trim().split(/\r?\n/).map(s=>s.trim()).join(`
9
- `)}:null}).filter(n=>n).map((n,i)=>n?n.start+" --> "+n.end+`
8
+ `+t.split(/\r?\n/).map(n=>{const a=n.match(e);return a?{start:r(a[1].trim()),end:r(a[2].trim()),text:a[5].replace(/{[\s\S]*?}/g,"").replace(/(\\N)/g,"<br />").trim().split(/\r?\n/).map(o=>o.trim()).join(`
9
+ `)}:null}).filter(n=>n).map((n,a)=>n?n.start+" --> "+n.end+`
10
10
  `+n.text:"").filter(n=>n.trim()).join(`
11
11
 
12
12
  `)}/**
@@ -17,9 +17,9 @@
17
17
  * @author Newtopia Dev (http://www.newtopia.com)
18
18
  * @version 1.0.1
19
19
  * @license MIT
20
- */function oe(t,e){let r=e;for(;!t[r];)r++;return r}function ce(t){let e=t.length-1;for(;e>=0&&!t[e];)e--;return e}function ue(t="",e={propName:{}}){const r=[],n=t.split(/(?:\r\n|\r|\n)/gm).filter(u=>u.length>0),i=n.map((u,h)=>n[h+2]&&/\d{2}:\d{2}:\d{2}[,\.]\d{2,3}\s*-->\s*\d{2}:\d{2}:\d{2}[,\.]\d{2,3}/.test(n[h+2])?u+`\r
20
+ */function xe(t,e){let r=e;for(;!t[r];)r++;return r}function Oe(t){let e=t.length-1;for(;e>=0&&!t[e];)e--;return e}function we(t="",e={propName:{}}){const r=[],n=t.split(/(?:\r\n|\r|\n)/gm).filter(u=>u.length>0),a=n.map((u,l)=>n[l+2]&&/\d{2}:\d{2}:\d{2}[,\.]\d{2,3}\s*-->\s*\d{2}:\d{2}:\d{2}[,\.]\d{2,3}/.test(n[l+2])?u+`\r
21
21
  `:u).join(`
22
- `).split(/(?:\r\n|\r|\n)/gm),s=ce(i)+1;let o=0,f,a,c;for(let u=0;u<s;u++){for(c={},a=[],u=oe(i,u),c.id=parseInt(i[u++],10),f=i[u++].split(/[\t ]*-->[\t ]*/),c[e.propName.start||"start"]=e.timeInText?f[0]:z(f[0]),o=f[1].indexOf(" "),o!==-1&&(f[1]=f[1].substr(0,o)),c[e.propName.end||"end"]=e.timeInText?f[1]:z(f[1]);u<s&&i[u];)a.push(i[u++]);const h=e.propName.text||"text";c[h]=a.join(e.keepMultiLine?`
23
- `:" ").replace(/\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}/gi,""),c[h]=c[h].replace(/</g,"&lt;").replace(/>/g,"&gt;"),c[h]=c[h].replace(/&lt;(\/?(font|b|u|i|s))((\s+(\w|\w[\w\-]*\w)(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/?)&gt;/gi,"<$1$3$7>"),e.ignoreLineBreaks?c[h]=c[h].replace(/\\N/gi,""):c[h]=c[h].replace(/\\N/gi,"<br />"),r.push(c)}return r}function fe(t,e){const r=/<\/?[^>]+(>|$)/g;return new Promise((n,i)=>{let s={};const o=[];let f=!1;const a=t.split(`
24
- `);a.forEach((u,h)=>{u.replace(r,"")===" "||u.replace(r,"")===""||(u.indexOf("-->")!==-1?(f=!0,typeof s.start=="number"&&s.start>=0&&o.push(q(s)),s={start:W(u.split("-->")[0].trimRight().split(" ").pop()),end:W(u.split("-->")[1].trimLeft().split(" ").shift()),part:""}):f&&(o.length!==0?(o[o.length-1].part.replace(r,""),u.replace(r,""),s.part.length===0?s.part=u:s.part=`${s.part}
25
- ${u}`,h===a.length-1&&o.push(q(s))):(s.part=u,o.push(q(s)),s.part="")))}),s=[];const c=/(<([0-9:.>]+)>)/ig;o.forEach(u=>{const F=u.part.split().map(function(g){return g.replace(c,function(b){return b.split("").reduce(function(V,Ya){return`==${b.replace("<","").replace(">","")}`},0)})})[0].replace(r,"").split(" "),T=[];F.forEach(function(g){if(g.indexOf("==")>-1){const b=g.split("=="),V=b[0];if(b[1],V==""||V=="##")return;T.push({word:ct(g.split("==")[0]),time:W(g.split("==")[1])})}else T.push({word:ct(g),time:void 0})}),u.words=T,u.part=u.part.replace(r,"")}),n(o)})}function W(t){const e=t.split(":"),r=e[e.length-3]?+e[e.length-3]:0,n=e[e.length-2]?+e[e.length-2]:0,i=+e[e.length-1];return r*3600+n*60+i}function ct(t){return t.replace(/[^0-9a-z'-]/gi,"").toLowerCase()}function q(t){if(t==null||typeof t!="object")return t;const e=t.constructor();for(const r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e}async function le(t){return ue(t,{keepMultiLine:!0,propName:{}}).filter(n=>n.text).map(n=>({st:M(n.start),et:M(n.end),text:n.text}))}async function Ft(t){return(await fe(t)).filter(n=>n.part).map(n=>({st:M(n.start),et:M(n.end),text:n.part}))}async function he(t){return Ft(se(t))}const pe=Object.freeze(Object.defineProperty({__proto__:null,assToAimSegments:he,srtToAimSegments:le,vttToAimSegments:Ft},Symbol.toStringTag,{value:"Module"}));class ge{constructor(e){d(this,"chains",{});d(this,"delimit","__replace__");d(this,"onFilter");d(this,"checked",!1);d(this,"checkedText","");d(this,"checkedLevel");d(this,"filteredText","");this.onFilter=e}add(e,r){typeof e!="string"&&(e=new TextDecoder().decode(e));const n=e;if(!n)return;let i=this.chains;for(let s=0;s<n.length;s++){if(n[s]in i)i=i[n[s]];else{if(!(i instanceof Object))break;let o,f;for(let a=s;a<n.length;a++)i[n[a]]={},[o,f]=[i,n[a]],i=i[n[a]];o&&f&&(o[f]={[this.delimit]:r||""});break}s===n.length-1&&(i[this.delimit]=r||"")}}parse(e){e.forEach(r=>{this.add(...r)})}reParse(e){this.chains={},e.forEach(r=>{this.add(r[0],r[1])})}feed(e){if(!this.checked&&!this.chains[e]){this.filteredText+=e,this.onFilter&&this.onFilter(e);return}if(!this.checked&&this.chains[e]){this.checked=!0,this.checkedLevel=this.chains[e],this.checkedText+=e;return}if(this.checked&&this.checkedLevel[e]){this.checkedLevel=this.checkedLevel[e],this.checkedText+=e;return}if(this.checked&&!this.checkedLevel[e]){const r=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;r&&r.length&&r.split("").forEach(n=>{this.filteredText+=n,this.onFilter&&this.onFilter(n)}),this.checked=!1,this.checkedText="",this.checkedLevel=void 0,this.chains[e]?(this.checked=!0,this.checkedLevel=this.chains[e],this.checkedText=e):(this.onFilter&&this.onFilter(e),this.filteredText+=e)}}feedAll(e){return e.length?(e.split("").forEach(n=>{this.feed(n)}),this.end()):""}end(){if(this.checked&&this.checkedText){const r=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;r&&r.length&&r.split("").forEach(n=>{this.onFilter&&this.onFilter(n),this.filteredText+=n}),this.checkedText="",this.checkedLevel=void 0,this.checked=!1}const e=this.filteredText;return this.filteredText="",e}}const de=Object.freeze(Object.defineProperty({__proto__:null,StreamFilter:ge},Symbol.toStringTag,{value:"Module"}));var Ct=typeof global=="object"&&global&&global.Object===Object&&global,be=typeof self=="object"&&self&&self.Object===Object&&self,y=Ct||be||Function("return this")(),x=y.Symbol,It=Object.prototype,ye=It.hasOwnProperty,Te=It.toString,C=x?x.toStringTag:void 0;function ve(t){var e=ye.call(t,C),r=t[C];try{t[C]=void 0;var n=!0}catch{}var i=Te.call(t);return n&&(e?t[C]=r:delete t[C]),i}var _e=Object.prototype,me=_e.toString;function je(t){return me.call(t)}var $e="[object Null]",Se="[object Undefined]",ut=x?x.toStringTag:void 0;function B(t){return t==null?t===void 0?Se:$e:ut&&ut in Object(t)?ve(t):je(t)}function U(t){return t!=null&&typeof t=="object"}var et=Array.isArray;function k(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var Oe="[object AsyncFunction]",xe="[object Function]",we="[object GeneratorFunction]",Ae="[object Proxy]";function Lt(t){if(!k(t))return!1;var e=B(t);return e==xe||e==we||e==Oe||e==Ae}var Y=y["__core-js_shared__"],ft=function(){var t=/[^.]+$/.exec(Y&&Y.keys&&Y.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function Pe(t){return!!ft&&ft in t}var Ee=Function.prototype,Fe=Ee.toString;function $(t){if(t!=null){try{return Fe.call(t)}catch{}try{return t+""}catch{}}return""}var Ce=/[\\^$.*+?()[\]{}|]/g,Ie=/^\[object .+?Constructor\]$/,Le=Function.prototype,Me=Object.prototype,ze=Le.toString,Ne=Me.hasOwnProperty,De=RegExp("^"+ze.call(Ne).replace(Ce,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Be(t){if(!k(t)||Pe(t))return!1;var e=Lt(t)?De:Ie;return e.test($(t))}function Ue(t,e){return t==null?void 0:t[e]}function S(t,e){var r=Ue(t,e);return Be(r)?r:void 0}var X=S(y,"WeakMap"),lt=Object.create,ke=function(){function t(){}return function(e){if(!k(e))return{};if(lt)return lt(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();function Ge(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}var ht=function(){try{var t=S(Object,"defineProperty");return t({},"",{}),t}catch{}}();function Re(t,e){for(var r=-1,n=t==null?0:t.length;++r<n&&e(t[r],r,t)!==!1;);return t}var He=9007199254740991,Ke=/^(?:0|[1-9]\d*)$/;function Ve(t,e){var r=typeof t;return e=e??He,!!e&&(r=="number"||r!="symbol"&&Ke.test(t))&&t>-1&&t%1==0&&t<e}function Mt(t,e,r){e=="__proto__"&&ht?ht(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}function zt(t,e){return t===e||t!==t&&e!==e}var We=Object.prototype,qe=We.hasOwnProperty;function Nt(t,e,r){var n=t[e];(!(qe.call(t,e)&&zt(n,r))||r===void 0&&!(e in t))&&Mt(t,e,r)}function R(t,e,r,n){var i=!r;r||(r={});for(var s=-1,o=e.length;++s<o;){var f=e[s],a=void 0;a===void 0&&(a=t[f]),i?Mt(r,f,a):Nt(r,f,a)}return r}var Ye=9007199254740991;function Dt(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Ye}function Bt(t){return t!=null&&Dt(t.length)&&!Lt(t)}var Je=Object.prototype;function rt(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||Je;return t===r}function Xe(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}var Ze="[object Arguments]";function pt(t){return U(t)&&B(t)==Ze}var Ut=Object.prototype,Qe=Ut.hasOwnProperty,tr=Ut.propertyIsEnumerable,er=pt(function(){return arguments}())?pt:function(t){return U(t)&&Qe.call(t,"callee")&&!tr.call(t,"callee")};function rr(){return!1}var kt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,gt=kt&&typeof module=="object"&&module&&!module.nodeType&&module,nr=gt&&gt.exports===kt,dt=nr?y.Buffer:void 0,ar=dt?dt.isBuffer:void 0,Gt=ar||rr,ir="[object Arguments]",sr="[object Array]",or="[object Boolean]",cr="[object Date]",ur="[object Error]",fr="[object Function]",lr="[object Map]",hr="[object Number]",pr="[object Object]",gr="[object RegExp]",dr="[object Set]",br="[object String]",yr="[object WeakMap]",Tr="[object ArrayBuffer]",vr="[object DataView]",_r="[object Float32Array]",mr="[object Float64Array]",jr="[object Int8Array]",$r="[object Int16Array]",Sr="[object Int32Array]",Or="[object Uint8Array]",xr="[object Uint8ClampedArray]",wr="[object Uint16Array]",Ar="[object Uint32Array]",p={};p[_r]=p[mr]=p[jr]=p[$r]=p[Sr]=p[Or]=p[xr]=p[wr]=p[Ar]=!0;p[ir]=p[sr]=p[Tr]=p[or]=p[vr]=p[cr]=p[ur]=p[fr]=p[lr]=p[hr]=p[pr]=p[gr]=p[dr]=p[br]=p[yr]=!1;function Pr(t){return U(t)&&Dt(t.length)&&!!p[B(t)]}function nt(t){return function(e){return t(e)}}var Rt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,L=Rt&&typeof module=="object"&&module&&!module.nodeType&&module,Er=L&&L.exports===Rt,J=Er&&Ct.process,w=function(){try{var t=L&&L.require&&L.require("util").types;return t||J&&J.binding&&J.binding("util")}catch{}}(),bt=w&&w.isTypedArray,Fr=bt?nt(bt):Pr,Cr=Object.prototype,Ir=Cr.hasOwnProperty;function Ht(t,e){var r=et(t),n=!r&&er(t),i=!r&&!n&&Gt(t),s=!r&&!n&&!i&&Fr(t),o=r||n||i||s,f=o?Xe(t.length,String):[],a=f.length;for(var c in t)(e||Ir.call(t,c))&&!(o&&(c=="length"||i&&(c=="offset"||c=="parent")||s&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||Ve(c,a)))&&f.push(c);return f}function Kt(t,e){return function(r){return t(e(r))}}var Lr=Kt(Object.keys,Object),Mr=Object.prototype,zr=Mr.hasOwnProperty;function Nr(t){if(!rt(t))return Lr(t);var e=[];for(var r in Object(t))zr.call(t,r)&&r!="constructor"&&e.push(r);return e}function at(t){return Bt(t)?Ht(t):Nr(t)}function Dr(t){var e=[];if(t!=null)for(var r in Object(t))e.push(r);return e}var Br=Object.prototype,Ur=Br.hasOwnProperty;function kr(t){if(!k(t))return Dr(t);var e=rt(t),r=[];for(var n in t)n=="constructor"&&(e||!Ur.call(t,n))||r.push(n);return r}function it(t){return Bt(t)?Ht(t,!0):kr(t)}var N=S(Object,"create");function Gr(){this.__data__=N?N(null):{},this.size=0}function Rr(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var Hr="__lodash_hash_undefined__",Kr=Object.prototype,Vr=Kr.hasOwnProperty;function Wr(t){var e=this.__data__;if(N){var r=e[t];return r===Hr?void 0:r}return Vr.call(e,t)?e[t]:void 0}var qr=Object.prototype,Yr=qr.hasOwnProperty;function Jr(t){var e=this.__data__;return N?e[t]!==void 0:Yr.call(e,t)}var Xr="__lodash_hash_undefined__";function Zr(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=N&&e===void 0?Xr:e,this}function j(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}j.prototype.clear=Gr;j.prototype.delete=Rr;j.prototype.get=Wr;j.prototype.has=Jr;j.prototype.set=Zr;function Qr(){this.__data__=[],this.size=0}function H(t,e){for(var r=t.length;r--;)if(zt(t[r][0],e))return r;return-1}var tn=Array.prototype,en=tn.splice;function rn(t){var e=this.__data__,r=H(e,t);if(r<0)return!1;var n=e.length-1;return r==n?e.pop():en.call(e,r,1),--this.size,!0}function nn(t){var e=this.__data__,r=H(e,t);return r<0?void 0:e[r][1]}function an(t){return H(this.__data__,t)>-1}function sn(t,e){var r=this.__data__,n=H(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this}function _(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}_.prototype.clear=Qr;_.prototype.delete=rn;_.prototype.get=nn;_.prototype.has=an;_.prototype.set=sn;var D=S(y,"Map");function on(){this.size=0,this.__data__={hash:new j,map:new(D||_),string:new j}}function cn(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function K(t,e){var r=t.__data__;return cn(e)?r[typeof e=="string"?"string":"hash"]:r.map}function un(t){var e=K(this,t).delete(t);return this.size-=e?1:0,e}function fn(t){return K(this,t).get(t)}function ln(t){return K(this,t).has(t)}function hn(t,e){var r=K(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this}function A(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}A.prototype.clear=on;A.prototype.delete=un;A.prototype.get=fn;A.prototype.has=ln;A.prototype.set=hn;function Vt(t,e){for(var r=-1,n=e.length,i=t.length;++r<n;)t[i+r]=e[r];return t}var Wt=Kt(Object.getPrototypeOf,Object);function pn(){this.__data__=new _,this.size=0}function gn(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}function dn(t){return this.__data__.get(t)}function bn(t){return this.__data__.has(t)}var yn=200;function Tn(t,e){var r=this.__data__;if(r instanceof _){var n=r.__data__;if(!D||n.length<yn-1)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new A(n)}return r.set(t,e),this.size=r.size,this}function P(t){var e=this.__data__=new _(t);this.size=e.size}P.prototype.clear=pn;P.prototype.delete=gn;P.prototype.get=dn;P.prototype.has=bn;P.prototype.set=Tn;function vn(t,e){return t&&R(e,at(e),t)}function _n(t,e){return t&&R(e,it(e),t)}var qt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,yt=qt&&typeof module=="object"&&module&&!module.nodeType&&module,mn=yt&&yt.exports===qt,Tt=mn?y.Buffer:void 0,vt=Tt?Tt.allocUnsafe:void 0;function jn(t,e){if(e)return t.slice();var r=t.length,n=vt?vt(r):new t.constructor(r);return t.copy(n),n}function $n(t,e){for(var r=-1,n=t==null?0:t.length,i=0,s=[];++r<n;){var o=t[r];e(o,r,t)&&(s[i++]=o)}return s}function Yt(){return[]}var Sn=Object.prototype,On=Sn.propertyIsEnumerable,_t=Object.getOwnPropertySymbols,st=_t?function(t){return t==null?[]:(t=Object(t),$n(_t(t),function(e){return On.call(t,e)}))}:Yt;function xn(t,e){return R(t,st(t),e)}var wn=Object.getOwnPropertySymbols,Jt=wn?function(t){for(var e=[];t;)Vt(e,st(t)),t=Wt(t);return e}:Yt;function An(t,e){return R(t,Jt(t),e)}function Xt(t,e,r){var n=e(t);return et(t)?n:Vt(n,r(t))}function Pn(t){return Xt(t,at,st)}function En(t){return Xt(t,it,Jt)}var Z=S(y,"DataView"),Q=S(y,"Promise"),tt=S(y,"Set"),mt="[object Map]",Fn="[object Object]",jt="[object Promise]",$t="[object Set]",St="[object WeakMap]",Ot="[object DataView]",Cn=$(Z),In=$(D),Ln=$(Q),Mn=$(tt),zn=$(X),v=B;(Z&&v(new Z(new ArrayBuffer(1)))!=Ot||D&&v(new D)!=mt||Q&&v(Q.resolve())!=jt||tt&&v(new tt)!=$t||X&&v(new X)!=St)&&(v=function(t){var e=B(t),r=e==Fn?t.constructor:void 0,n=r?$(r):"";if(n)switch(n){case Cn:return Ot;case In:return mt;case Ln:return jt;case Mn:return $t;case zn:return St}return e});var Nn=Object.prototype,Dn=Nn.hasOwnProperty;function Bn(t){var e=t.length,r=new t.constructor(e);return e&&typeof t[0]=="string"&&Dn.call(t,"index")&&(r.index=t.index,r.input=t.input),r}var xt=y.Uint8Array;function ot(t){var e=new t.constructor(t.byteLength);return new xt(e).set(new xt(t)),e}function Un(t,e){var r=e?ot(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}var kn=/\w*$/;function Gn(t){var e=new t.constructor(t.source,kn.exec(t));return e.lastIndex=t.lastIndex,e}var wt=x?x.prototype:void 0,At=wt?wt.valueOf:void 0;function Rn(t){return At?Object(At.call(t)):{}}function Hn(t,e){var r=e?ot(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}var Kn="[object Boolean]",Vn="[object Date]",Wn="[object Map]",qn="[object Number]",Yn="[object RegExp]",Jn="[object Set]",Xn="[object String]",Zn="[object Symbol]",Qn="[object ArrayBuffer]",ta="[object DataView]",ea="[object Float32Array]",ra="[object Float64Array]",na="[object Int8Array]",aa="[object Int16Array]",ia="[object Int32Array]",sa="[object Uint8Array]",oa="[object Uint8ClampedArray]",ca="[object Uint16Array]",ua="[object Uint32Array]";function fa(t,e,r){var n=t.constructor;switch(e){case Qn:return ot(t);case Kn:case Vn:return new n(+t);case ta:return Un(t,r);case ea:case ra:case na:case aa:case ia:case sa:case oa:case ca:case ua:return Hn(t,r);case Wn:return new n;case qn:case Xn:return new n(t);case Yn:return Gn(t);case Jn:return new n;case Zn:return Rn(t)}}function la(t){return typeof t.constructor=="function"&&!rt(t)?ke(Wt(t)):{}}var ha="[object Map]";function pa(t){return U(t)&&v(t)==ha}var Pt=w&&w.isMap,ga=Pt?nt(Pt):pa,da="[object Set]";function ba(t){return U(t)&&v(t)==da}var Et=w&&w.isSet,ya=Et?nt(Et):ba,Ta=1,va=2,_a=4,Zt="[object Arguments]",ma="[object Array]",ja="[object Boolean]",$a="[object Date]",Sa="[object Error]",Qt="[object Function]",Oa="[object GeneratorFunction]",xa="[object Map]",wa="[object Number]",te="[object Object]",Aa="[object RegExp]",Pa="[object Set]",Ea="[object String]",Fa="[object Symbol]",Ca="[object WeakMap]",Ia="[object ArrayBuffer]",La="[object DataView]",Ma="[object Float32Array]",za="[object Float64Array]",Na="[object Int8Array]",Da="[object Int16Array]",Ba="[object Int32Array]",Ua="[object Uint8Array]",ka="[object Uint8ClampedArray]",Ga="[object Uint16Array]",Ra="[object Uint32Array]",l={};l[Zt]=l[ma]=l[Ia]=l[La]=l[ja]=l[$a]=l[Ma]=l[za]=l[Na]=l[Da]=l[Ba]=l[xa]=l[wa]=l[te]=l[Aa]=l[Pa]=l[Ea]=l[Fa]=l[Ua]=l[ka]=l[Ga]=l[Ra]=!0;l[Sa]=l[Qt]=l[Ca]=!1;function G(t,e,r,n,i,s){var o,f=e&Ta,a=e&va,c=e&_a;if(o!==void 0)return o;if(!k(t))return t;var u=et(t);if(u){if(o=Bn(t),!f)return Ge(t,o)}else{var h=v(t),O=h==Qt||h==Oa;if(Gt(t))return jn(t,f);if(h==te||h==Zt||O&&!i){if(o=a||O?{}:la(t),!f)return a?An(t,_n(o,t)):xn(t,vn(o,t))}else{if(!l[h])return i?t:{};o=fa(t,h,f)}}s||(s=new P);var E=s.get(t);if(E)return E;s.set(t,o),ya(t)?t.forEach(function(g){o.add(G(g,e,r,g,t,s))}):ga(t)&&t.forEach(function(g,b){o.set(b,G(g,e,r,b,t,s))});var F=c?a?En:Pn:a?it:at,T=u?void 0:F(t);return Re(T||t,function(g,b){T&&(b=g,g=t[b]),Nt(o,b,G(g,e,r,b,t,s))}),o}var Ha=1,Ka=4;function Va(t){return G(t,Ha|Ka)}class ee{constructor(e){d(this,"threshold",2);d(this,"hit",0);d(this,"prevSegment");d(this,"hitSegment");d(this,"hitSegmentList",[]);d(this,"options");this.options=e||{}}push(e){var r,n;this.hitSegment&&this.hitSegment.text!==e.text&&(this.hitSegmentList.push(this.hitSegment),this.reset()),this.prevSegment&&e.text===this.prevSegment.text?(this.hit++,this.hit===1&&(this.hitSegment=Va(this.prevSegment)),this.threshold<=this.hit&&this.hitSegment&&(this.hitSegment.et=e.et,this.hitSegment.hit=this.hit,(n=(r=this.options).onHit)==null||n.call(r,this.hitSegmentList))):this.hit=0,this.prevSegment=e}end(){var e,r;this.hitSegment&&(this.hitSegmentList.push(this.hitSegment),(r=(e=this.options).onHit)==null||r.call(e,this.hitSegmentList)),this.reset()}reset(){this.hit=0,this.prevSegment=void 0,this.hitSegment=void 0}}const m={punc:/[.,?!\],。!?…]{1}/,em:/[.?!\]。!?…]{1}/,space:/^\s+|\s+$|\s{2,}/g,ep:/[.,?!,。!?…]{1}\s*$/};function Wa(t,e){let r=[];const n=new ee({onHit:a=>{r=a}}),i=a=>a.trim().length===0,s=a=>{const c=z(a.st),u=z(a.et);return c>=u},o={emt:[],ep:[],zf:[],punc:[],em:[],space:[]},f=[];return t.forEach((a,c)=>{const u=m.punc.test(a.text),h=m.em.test(a.text),O=m.space.test(a.text),E=i(a.text),F=s(a),T=m.ep.test(a.text);n.push(a),a.punc=u?1:0,u&&o.punc.push(c),a.em=h?1:0,h&&o.em.push(c),a.space=O?1:0,O&&(e!=null&&e.space?a.text=a.text.replace(m.space," ").trim():o.space.push(c)),a.emt=i(a.text)?1:0,E&&(e!=null&&e.emt||o.emt.push(c)),a.zf=s(a)?1:0,F&&(e!=null&&e.zf||o.zf.push(c)),a.ep=T?1:0,T&&(e!=null&&e.ep?a.text=a.text.replace(m.ep,""):o.ep.push(c)),!(e!=null&&e.zf&&a.zf)&&(e!=null&&e.emt&&a.emt||f.push(a))}),n.end(),{result:o,repeat:r,segments:f}}const qa=Object.freeze(Object.defineProperty({__proto__:null,RepeatCheck:ee,subtitleOptimization:Wa,subtitleOptimizationRegExp:m},Symbol.toStringTag,{value:"Module"}));exports.filter=de;exports.parser=pe;exports.tools=qa;exports.utils=ie;
22
+ `).split(/(?:\r\n|\r|\n)/gm),o=Oe(a)+1;let i=0,f,s,c;for(let u=0;u<o;u++){for(c={},s=[],u=xe(a,u),c.id=parseInt(a[u++],10),f=a[u++].split(/[\t ]*-->[\t ]*/),c[e.propName.start||"start"]=e.timeInText?f[0]:$(f[0]),i=f[1].indexOf(" "),i!==-1&&(f[1]=f[1].substr(0,i)),c[e.propName.end||"end"]=e.timeInText?f[1]:$(f[1]);u<o&&a[u];)s.push(a[u++]);const l=e.propName.text||"text";c[l]=s.join(e.keepMultiLine?`
23
+ `:" ").replace(/\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}/gi,""),c[l]=c[l].replace(/</g,"&lt;").replace(/>/g,"&gt;"),c[l]=c[l].replace(/&lt;(\/?(font|b|u|i|s))((\s+(\w|\w[\w\-]*\w)(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/?)&gt;/gi,"<$1$3$7>"),e.ignoreLineBreaks?c[l]=c[l].replace(/\\N/gi,""):c[l]=c[l].replace(/\\N/gi,"<br />"),r.push(c)}return r}function Ae(t,e){const r=/<\/?[^>]+(>|$)/g;return new Promise((n,a)=>{let o={};const i=[];let f=!1;const s=t.split(`
24
+ `);s.forEach((u,l)=>{u.replace(r,"")===" "||u.replace(r,"")===""||(u.indexOf("-->")!==-1?(f=!0,typeof o.start=="number"&&o.start>=0&&i.push(et(o)),o={start:tt(u.split("-->")[0].trimRight().split(" ").pop()),end:tt(u.split("-->")[1].trimLeft().split(" ").shift()),part:""}):f&&(i.length!==0?(i[i.length-1].part.replace(r,""),u.replace(r,""),o.part.length===0?o.part=u:o.part=`${o.part}
25
+ ${u}`,l===s.length-1&&i.push(et(o))):(o.part=u,i.push(et(o)),o.part="")))}),o=[];const c=/(<([0-9:.>]+)>)/ig;i.forEach(u=>{const j=u.part.split().map(function(d){return d.replace(c,function(g){return g.split("").reduce(function(O,bt){return`==${g.replace("<","").replace(">","")}`},0)})})[0].replace(r,"").split(" "),b=[];j.forEach(function(d){if(d.indexOf("==")>-1){const g=d.split("=="),O=g[0];if(g[1],O==""||O=="##")return;b.push({word:jt(d.split("==")[0]),time:tt(d.split("==")[1])})}else b.push({word:jt(d),time:void 0})}),u.words=b,u.part=u.part.replace(r,"")}),n(i)})}function tt(t){const e=t.split(":"),r=e[e.length-3]?+e[e.length-3]:0,n=e[e.length-2]?+e[e.length-2]:0,a=+e[e.length-1];return r*3600+n*60+a}function jt(t){return t.replace(/[^0-9a-z'-]/gi,"").toLowerCase()}function et(t){if(t==null||typeof t!="object")return t;const e=t.constructor();for(const r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e}const rt={padding:[.4,0],maxGap:10,minGap:2,minStart:6};function Pe(t){let e,r,n,a,o,i,f,s,c;const u=!!(t&&t.vad&&t.vad.length>0),l="[--end--]",m="[--Single--]",x="[--Full--]",j=/\[(\d{2}:\d{2}:\d{2}\.\d{3}) --> (\d{2}:\d{2}:\d{2}\.\d{3})\]/;let b=!1,d=!1,g="";return O(),{feed:yt,reset:O,end:bt};function O(){e=!0,r="",n=!1,a="",o=!1,i=void 0,f=0,s=!1,c=0}function bt(){if(s){console.log("whisper parser is already end");return}yt(l)}function ve(K){b||(g+=K),!b&&!d&&Kt(g)&&(d=!0),!b&&g.length>50&&(b=!0)}function yt(K){var vt,Tt,_t;ve(K);const V=[];r+=K,e&&((vt=t==null?void 0:t.onStart)==null||vt.call(t,{type:"event",event:"start",data:[]})),e&&Ee(r)&&(r=r.slice(Vt.length)),e=!1;const Te=r.length;for(;f<Te;){const W=r[f];if(++f,o&&i&&W!=="["&&(i.text+=W),W==="["&&(n&&a.length&&i&&(i.text+=a),a="",n=!0,o=!1),n){if(a+=W,a===x&&(a=""),a===m&&(a="",u&&c++),a===l){i&&V.push(i),s=!0;break}if(j.test(a)){const C=j.exec(a),z=C==null?void 0:C[1],Q=C==null?void 0:C[2];if(i&&V.push(i),z&&Q){if(u&&(t!=null&&t.vad)&&t.vad.length>0){let q=0;q=t.vad[c].start-rt.padding[0]<0?0:t.vad[c].start-rt.padding[0];const _e=z==="00:00:00.000";let mt=S($(z)+q);c>0&&_e&&(mt=S($(z)+q+rt.padding[0])),i={st:mt,et:S($(Q)+q),text:"",children:[]}}else i={st:z,et:Q,text:"",children:[]};o=!0,n=!1,a=""}}}}V.length&&((Tt=t==null?void 0:t.onParse)==null||Tt.call(t,{type:"event",event:"message",data:V})),s&&((_t=t==null?void 0:t.onEnd)==null||_t.call(t,{type:"event",event:"end",data:r}),O())}}const Vt=[239,187,191];function Ee(t){return Vt.every((e,r)=>t.charCodeAt(r)===e)}async function Ce(t){return we(t,{keepMultiLine:!0,propName:{}}).filter(n=>n.text).map(n=>({st:S(n.start),et:S(n.end),text:n.text}))}async function Wt(t){return(await Ae(t)).filter(n=>n.part).map(n=>({st:S(n.start),et:S(n.end),text:n.part}))}async function Fe(t){return Wt($e(t))}const Ie=Object.freeze(Object.defineProperty({__proto__:null,assToAimSegments:Fe,createWhisperStreamParser:Pe,srtToAimSegments:Ce,vttToAimSegments:Wt},Symbol.toStringTag,{value:"Module"}));class Le{constructor(e){y(this,"chains",{});y(this,"delimit","__replace__");y(this,"onFilter");y(this,"checked",!1);y(this,"checkedText","");y(this,"checkedLevel");y(this,"filteredText","");this.onFilter=e}add(e,r){typeof e!="string"&&(e=new TextDecoder().decode(e));const n=e;if(!n)return;let a=this.chains;for(let o=0;o<n.length;o++){if(n[o]in a)a=a[n[o]];else{if(!(a instanceof Object))break;let i,f;for(let s=o;s<n.length;s++)a[n[s]]={},[i,f]=[a,n[s]],a=a[n[s]];i&&f&&(i[f]={[this.delimit]:r||""});break}o===n.length-1&&(a[this.delimit]=r||"")}}parse(e){e.forEach(r=>{this.add(...r)})}reParse(e){this.chains={},e.forEach(r=>{this.add(r[0],r[1])})}feed(e){if(!this.checked&&!this.chains[e]){this.filteredText+=e,this.onFilter&&this.onFilter(e);return}if(!this.checked&&this.chains[e]){this.checked=!0,this.checkedLevel=this.chains[e],this.checkedText+=e;return}if(this.checked&&this.checkedLevel[e]){this.checkedLevel=this.checkedLevel[e],this.checkedText+=e;return}if(this.checked&&!this.checkedLevel[e]){const r=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;r&&r.length&&r.split("").forEach(n=>{this.filteredText+=n,this.onFilter&&this.onFilter(n)}),this.checked=!1,this.checkedText="",this.checkedLevel=void 0,this.chains[e]?(this.checked=!0,this.checkedLevel=this.chains[e],this.checkedText=e):(this.onFilter&&this.onFilter(e),this.filteredText+=e)}}feedAll(e){return e.length?(e.split("").forEach(n=>{this.feed(n)}),this.end()):""}end(){if(this.checked&&this.checkedText){const r=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;r&&r.length&&r.split("").forEach(n=>{this.onFilter&&this.onFilter(n),this.filteredText+=n}),this.checkedText="",this.checkedLevel=void 0,this.checked=!1}const e=this.filteredText;return this.filteredText="",e}}const Me=Object.freeze(Object.defineProperty({__proto__:null,StreamFilter:Le},Symbol.toStringTag,{value:"Module"}));var qt=typeof global=="object"&&global&&global.Object===Object&&global,ze=typeof self=="object"&&self&&self.Object===Object&&self,v=qt||ze||Function("return this")(),F=v.Symbol,Jt=Object.prototype,Ne=Jt.hasOwnProperty,De=Jt.toString,N=F?F.toStringTag:void 0;function ke(t){var e=Ne.call(t,N),r=t[N];try{t[N]=void 0;var n=!0}catch{}var a=De.call(t);return n&&(e?t[N]=r:delete t[N]),a}var Be=Object.prototype,Ge=Be.toString;function Ue(t){return Ge.call(t)}var Re="[object Null]",He="[object Undefined]",St=F?F.toStringTag:void 0;function U(t){return t==null?t===void 0?He:Re:St&&St in Object(t)?ke(t):Ue(t)}function R(t){return t!=null&&typeof t=="object"}var ut=Array.isArray;function H(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var Ke="[object AsyncFunction]",Ve="[object Function]",We="[object GeneratorFunction]",qe="[object Proxy]";function Yt(t){if(!H(t))return!1;var e=U(t);return e==Ve||e==We||e==Ke||e==qe}var nt=v["__core-js_shared__"],$t=function(){var t=/[^.]+$/.exec(nt&&nt.keys&&nt.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function Je(t){return!!$t&&$t in t}var Ye=Function.prototype,Xe=Ye.toString;function P(t){if(t!=null){try{return Xe.call(t)}catch{}try{return t+""}catch{}}return""}var Ze=/[\\^$.*+?()[\]{}|]/g,Qe=/^\[object .+?Constructor\]$/,tr=Function.prototype,er=Object.prototype,rr=tr.toString,nr=er.hasOwnProperty,ar=RegExp("^"+rr.call(nr).replace(Ze,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ir(t){if(!H(t)||Je(t))return!1;var e=Yt(t)?ar:Qe;return e.test(P(t))}function sr(t,e){return t==null?void 0:t[e]}function E(t,e){var r=sr(t,e);return ir(r)?r:void 0}var it=E(v,"WeakMap"),xt=Object.create,or=function(){function t(){}return function(e){if(!H(e))return{};if(xt)return xt(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();function cr(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}var Ot=function(){try{var t=E(Object,"defineProperty");return t({},"",{}),t}catch{}}();function ur(t,e){for(var r=-1,n=t==null?0:t.length;++r<n&&e(t[r],r,t)!==!1;);return t}var fr=9007199254740991,lr=/^(?:0|[1-9]\d*)$/;function hr(t,e){var r=typeof t;return e=e??fr,!!e&&(r=="number"||r!="symbol"&&lr.test(t))&&t>-1&&t%1==0&&t<e}function Xt(t,e,r){e=="__proto__"&&Ot?Ot(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}function Zt(t,e){return t===e||t!==t&&e!==e}var pr=Object.prototype,dr=pr.hasOwnProperty;function Qt(t,e,r){var n=t[e];(!(dr.call(t,e)&&Zt(n,r))||r===void 0&&!(e in t))&&Xt(t,e,r)}function Y(t,e,r,n){var a=!r;r||(r={});for(var o=-1,i=e.length;++o<i;){var f=e[o],s=void 0;s===void 0&&(s=t[f]),a?Xt(r,f,s):Qt(r,f,s)}return r}var gr=9007199254740991;function te(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=gr}function ee(t){return t!=null&&te(t.length)&&!Yt(t)}var br=Object.prototype;function ft(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||br;return t===r}function yr(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}var vr="[object Arguments]";function wt(t){return R(t)&&U(t)==vr}var re=Object.prototype,Tr=re.hasOwnProperty,_r=re.propertyIsEnumerable,mr=wt(function(){return arguments}())?wt:function(t){return R(t)&&Tr.call(t,"callee")&&!_r.call(t,"callee")};function jr(){return!1}var ne=typeof exports=="object"&&exports&&!exports.nodeType&&exports,At=ne&&typeof module=="object"&&module&&!module.nodeType&&module,Sr=At&&At.exports===ne,Pt=Sr?v.Buffer:void 0,$r=Pt?Pt.isBuffer:void 0,ae=$r||jr,xr="[object Arguments]",Or="[object Array]",wr="[object Boolean]",Ar="[object Date]",Pr="[object Error]",Er="[object Function]",Cr="[object Map]",Fr="[object Number]",Ir="[object Object]",Lr="[object RegExp]",Mr="[object Set]",zr="[object String]",Nr="[object WeakMap]",Dr="[object ArrayBuffer]",kr="[object DataView]",Br="[object Float32Array]",Gr="[object Float64Array]",Ur="[object Int8Array]",Rr="[object Int16Array]",Hr="[object Int32Array]",Kr="[object Uint8Array]",Vr="[object Uint8ClampedArray]",Wr="[object Uint16Array]",qr="[object Uint32Array]",p={};p[Br]=p[Gr]=p[Ur]=p[Rr]=p[Hr]=p[Kr]=p[Vr]=p[Wr]=p[qr]=!0;p[xr]=p[Or]=p[Dr]=p[wr]=p[kr]=p[Ar]=p[Pr]=p[Er]=p[Cr]=p[Fr]=p[Ir]=p[Lr]=p[Mr]=p[zr]=p[Nr]=!1;function Jr(t){return R(t)&&te(t.length)&&!!p[U(t)]}function lt(t){return function(e){return t(e)}}var ie=typeof exports=="object"&&exports&&!exports.nodeType&&exports,k=ie&&typeof module=="object"&&module&&!module.nodeType&&module,Yr=k&&k.exports===ie,at=Yr&&qt.process,I=function(){try{var t=k&&k.require&&k.require("util").types;return t||at&&at.binding&&at.binding("util")}catch{}}(),Et=I&&I.isTypedArray,Xr=Et?lt(Et):Jr,Zr=Object.prototype,Qr=Zr.hasOwnProperty;function se(t,e){var r=ut(t),n=!r&&mr(t),a=!r&&!n&&ae(t),o=!r&&!n&&!a&&Xr(t),i=r||n||a||o,f=i?yr(t.length,String):[],s=f.length;for(var c in t)(e||Qr.call(t,c))&&!(i&&(c=="length"||a&&(c=="offset"||c=="parent")||o&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||hr(c,s)))&&f.push(c);return f}function oe(t,e){return function(r){return t(e(r))}}var tn=oe(Object.keys,Object),en=Object.prototype,rn=en.hasOwnProperty;function nn(t){if(!ft(t))return tn(t);var e=[];for(var r in Object(t))rn.call(t,r)&&r!="constructor"&&e.push(r);return e}function ht(t){return ee(t)?se(t):nn(t)}function an(t){var e=[];if(t!=null)for(var r in Object(t))e.push(r);return e}var sn=Object.prototype,on=sn.hasOwnProperty;function cn(t){if(!H(t))return an(t);var e=ft(t),r=[];for(var n in t)n=="constructor"&&(e||!on.call(t,n))||r.push(n);return r}function pt(t){return ee(t)?se(t,!0):cn(t)}var B=E(Object,"create");function un(){this.__data__=B?B(null):{},this.size=0}function fn(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var ln="__lodash_hash_undefined__",hn=Object.prototype,pn=hn.hasOwnProperty;function dn(t){var e=this.__data__;if(B){var r=e[t];return r===ln?void 0:r}return pn.call(e,t)?e[t]:void 0}var gn=Object.prototype,bn=gn.hasOwnProperty;function yn(t){var e=this.__data__;return B?e[t]!==void 0:bn.call(e,t)}var vn="__lodash_hash_undefined__";function Tn(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=B&&e===void 0?vn:e,this}function A(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}A.prototype.clear=un;A.prototype.delete=fn;A.prototype.get=dn;A.prototype.has=yn;A.prototype.set=Tn;function _n(){this.__data__=[],this.size=0}function X(t,e){for(var r=t.length;r--;)if(Zt(t[r][0],e))return r;return-1}var mn=Array.prototype,jn=mn.splice;function Sn(t){var e=this.__data__,r=X(e,t);if(r<0)return!1;var n=e.length-1;return r==n?e.pop():jn.call(e,r,1),--this.size,!0}function $n(t){var e=this.__data__,r=X(e,t);return r<0?void 0:e[r][1]}function xn(t){return X(this.__data__,t)>-1}function On(t,e){var r=this.__data__,n=X(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this}function _(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}_.prototype.clear=_n;_.prototype.delete=Sn;_.prototype.get=$n;_.prototype.has=xn;_.prototype.set=On;var G=E(v,"Map");function wn(){this.size=0,this.__data__={hash:new A,map:new(G||_),string:new A}}function An(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function Z(t,e){var r=t.__data__;return An(e)?r[typeof e=="string"?"string":"hash"]:r.map}function Pn(t){var e=Z(this,t).delete(t);return this.size-=e?1:0,e}function En(t){return Z(this,t).get(t)}function Cn(t){return Z(this,t).has(t)}function Fn(t,e){var r=Z(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this}function L(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}L.prototype.clear=wn;L.prototype.delete=Pn;L.prototype.get=En;L.prototype.has=Cn;L.prototype.set=Fn;function ce(t,e){for(var r=-1,n=e.length,a=t.length;++r<n;)t[a+r]=e[r];return t}var ue=oe(Object.getPrototypeOf,Object);function In(){this.__data__=new _,this.size=0}function Ln(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}function Mn(t){return this.__data__.get(t)}function zn(t){return this.__data__.has(t)}var Nn=200;function Dn(t,e){var r=this.__data__;if(r instanceof _){var n=r.__data__;if(!G||n.length<Nn-1)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new L(n)}return r.set(t,e),this.size=r.size,this}function M(t){var e=this.__data__=new _(t);this.size=e.size}M.prototype.clear=In;M.prototype.delete=Ln;M.prototype.get=Mn;M.prototype.has=zn;M.prototype.set=Dn;function kn(t,e){return t&&Y(e,ht(e),t)}function Bn(t,e){return t&&Y(e,pt(e),t)}var fe=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ct=fe&&typeof module=="object"&&module&&!module.nodeType&&module,Gn=Ct&&Ct.exports===fe,Ft=Gn?v.Buffer:void 0,It=Ft?Ft.allocUnsafe:void 0;function Un(t,e){if(e)return t.slice();var r=t.length,n=It?It(r):new t.constructor(r);return t.copy(n),n}function Rn(t,e){for(var r=-1,n=t==null?0:t.length,a=0,o=[];++r<n;){var i=t[r];e(i,r,t)&&(o[a++]=i)}return o}function le(){return[]}var Hn=Object.prototype,Kn=Hn.propertyIsEnumerable,Lt=Object.getOwnPropertySymbols,dt=Lt?function(t){return t==null?[]:(t=Object(t),Rn(Lt(t),function(e){return Kn.call(t,e)}))}:le;function Vn(t,e){return Y(t,dt(t),e)}var Wn=Object.getOwnPropertySymbols,he=Wn?function(t){for(var e=[];t;)ce(e,dt(t)),t=ue(t);return e}:le;function qn(t,e){return Y(t,he(t),e)}function pe(t,e,r){var n=e(t);return ut(t)?n:ce(n,r(t))}function Jn(t){return pe(t,ht,dt)}function Yn(t){return pe(t,pt,he)}var st=E(v,"DataView"),ot=E(v,"Promise"),ct=E(v,"Set"),Mt="[object Map]",Xn="[object Object]",zt="[object Promise]",Nt="[object Set]",Dt="[object WeakMap]",kt="[object DataView]",Zn=P(st),Qn=P(G),ta=P(ot),ea=P(ct),ra=P(it),T=U;(st&&T(new st(new ArrayBuffer(1)))!=kt||G&&T(new G)!=Mt||ot&&T(ot.resolve())!=zt||ct&&T(new ct)!=Nt||it&&T(new it)!=Dt)&&(T=function(t){var e=U(t),r=e==Xn?t.constructor:void 0,n=r?P(r):"";if(n)switch(n){case Zn:return kt;case Qn:return Mt;case ta:return zt;case ea:return Nt;case ra:return Dt}return e});var na=Object.prototype,aa=na.hasOwnProperty;function ia(t){var e=t.length,r=new t.constructor(e);return e&&typeof t[0]=="string"&&aa.call(t,"index")&&(r.index=t.index,r.input=t.input),r}var Bt=v.Uint8Array;function gt(t){var e=new t.constructor(t.byteLength);return new Bt(e).set(new Bt(t)),e}function sa(t,e){var r=e?gt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}var oa=/\w*$/;function ca(t){var e=new t.constructor(t.source,oa.exec(t));return e.lastIndex=t.lastIndex,e}var Gt=F?F.prototype:void 0,Ut=Gt?Gt.valueOf:void 0;function ua(t){return Ut?Object(Ut.call(t)):{}}function fa(t,e){var r=e?gt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}var la="[object Boolean]",ha="[object Date]",pa="[object Map]",da="[object Number]",ga="[object RegExp]",ba="[object Set]",ya="[object String]",va="[object Symbol]",Ta="[object ArrayBuffer]",_a="[object DataView]",ma="[object Float32Array]",ja="[object Float64Array]",Sa="[object Int8Array]",$a="[object Int16Array]",xa="[object Int32Array]",Oa="[object Uint8Array]",wa="[object Uint8ClampedArray]",Aa="[object Uint16Array]",Pa="[object Uint32Array]";function Ea(t,e,r){var n=t.constructor;switch(e){case Ta:return gt(t);case la:case ha:return new n(+t);case _a:return sa(t,r);case ma:case ja:case Sa:case $a:case xa:case Oa:case wa:case Aa:case Pa:return fa(t,r);case pa:return new n;case da:case ya:return new n(t);case ga:return ca(t);case ba:return new n;case va:return ua(t)}}function Ca(t){return typeof t.constructor=="function"&&!ft(t)?or(ue(t)):{}}var Fa="[object Map]";function Ia(t){return R(t)&&T(t)==Fa}var Rt=I&&I.isMap,La=Rt?lt(Rt):Ia,Ma="[object Set]";function za(t){return R(t)&&T(t)==Ma}var Ht=I&&I.isSet,Na=Ht?lt(Ht):za,Da=1,ka=2,Ba=4,de="[object Arguments]",Ga="[object Array]",Ua="[object Boolean]",Ra="[object Date]",Ha="[object Error]",ge="[object Function]",Ka="[object GeneratorFunction]",Va="[object Map]",Wa="[object Number]",be="[object Object]",qa="[object RegExp]",Ja="[object Set]",Ya="[object String]",Xa="[object Symbol]",Za="[object WeakMap]",Qa="[object ArrayBuffer]",ti="[object DataView]",ei="[object Float32Array]",ri="[object Float64Array]",ni="[object Int8Array]",ai="[object Int16Array]",ii="[object Int32Array]",si="[object Uint8Array]",oi="[object Uint8ClampedArray]",ci="[object Uint16Array]",ui="[object Uint32Array]",h={};h[de]=h[Ga]=h[Qa]=h[ti]=h[Ua]=h[Ra]=h[ei]=h[ri]=h[ni]=h[ai]=h[ii]=h[Va]=h[Wa]=h[be]=h[qa]=h[Ja]=h[Ya]=h[Xa]=h[si]=h[oi]=h[ci]=h[ui]=!0;h[Ha]=h[ge]=h[Za]=!1;function J(t,e,r,n,a,o){var i,f=e&Da,s=e&ka,c=e&Ba;if(i!==void 0)return i;if(!H(t))return t;var u=ut(t);if(u){if(i=ia(t),!f)return cr(t,i)}else{var l=T(t),m=l==ge||l==Ka;if(ae(t))return Un(t,f);if(l==be||l==de||m&&!a){if(i=s||m?{}:Ca(t),!f)return s?qn(t,Bn(i,t)):Vn(t,kn(i,t))}else{if(!h[l])return a?t:{};i=Ea(t,l,f)}}o||(o=new M);var x=o.get(t);if(x)return x;o.set(t,i),Na(t)?t.forEach(function(d){i.add(J(d,e,r,d,t,o))}):La(t)&&t.forEach(function(d,g){i.set(g,J(d,e,r,g,t,o))});var j=c?s?Yn:Jn:s?pt:ht,b=u?void 0:j(t);return ur(b||t,function(d,g){b&&(g=d,d=t[g]),Qt(i,g,J(d,e,r,g,t,o))}),i}var fi=1,li=4;function hi(t){return J(t,fi|li)}class ye{constructor(e){y(this,"threshold",2);y(this,"hit",0);y(this,"prevSegment");y(this,"hitSegment");y(this,"hitSegmentList",[]);y(this,"options");this.options=e||{}}push(e){var r,n;this.hitSegment&&this.hitSegment.text!==e.text&&(this.hitSegmentList.push(this.hitSegment),this.reset()),this.prevSegment&&e.text===this.prevSegment.text?(this.hit++,this.hit===1&&(this.hitSegment=hi(this.prevSegment)),this.threshold<=this.hit&&this.hitSegment&&(this.hitSegment.et=e.et,this.hitSegment.hit=this.hit,(n=(r=this.options).onHit)==null||n.call(r,this.hitSegmentList))):this.hit=0,this.prevSegment=e}end(){var e,r;this.hitSegment&&(this.hitSegmentList.push(this.hitSegment),(r=(e=this.options).onHit)==null||r.call(e,this.hitSegmentList)),this.reset()}reset(){this.hit=0,this.prevSegment=void 0,this.hitSegment=void 0}}const w={punc:/[.,?!\],。!?…]{1}/,em:/[.?!\]。!?…]{1}/,space:/^\s+|\s+$|\s{2,}/g,ep:/[.,?!,。!?…]{1}\s*$/};function pi(t,e){let r=[];const n=new ye({onHit:s=>{r=s}}),a=s=>s.trim().length===0,o=s=>{const c=$(s.st),u=$(s.et);return c>=u},i={emt:[],ep:[],zf:[],punc:[],em:[],space:[]},f=[];return t.forEach((s,c)=>{const u=w.punc.test(s.text),l=w.em.test(s.text),m=w.space.test(s.text),x=a(s.text),j=o(s),b=w.ep.test(s.text);n.push(s),s.punc=u?1:0,u&&i.punc.push(c),s.em=l?1:0,l&&i.em.push(c),s.space=m?1:0,m&&(e!=null&&e.space?s.text=s.text.replace(w.space," ").trim():i.space.push(c)),s.emt=a(s.text)?1:0,x&&(e!=null&&e.emt||i.emt.push(c)),s.zf=o(s)?1:0,j&&(e!=null&&e.zf||i.zf.push(c)),s.ep=b?1:0,b&&(e!=null&&e.ep?s.text=s.text.replace(w.ep,""):i.ep.push(c)),!(e!=null&&e.zf&&s.zf)&&(e!=null&&e.emt&&s.emt||f.push(s))}),n.end(),{result:i,repeat:r,segments:f}}const di=Object.freeze(Object.defineProperty({__proto__:null,RepeatCheck:ye,subtitleOptimization:pi,subtitleOptimizationRegExp:w},Symbol.toStringTag,{value:"Module"}));exports.filter=Me;exports.parser=Ie;exports.tools=di;exports.utils=Se;
package/dist/index.d.ts CHANGED
@@ -84,6 +84,19 @@ declare function containsCJKCharacters(str: string): boolean;
84
84
  */
85
85
  declare function convertToSeconds(time?: string): number;
86
86
 
87
+ /**
88
+ * Creates a new Parser parser.
89
+ *
90
+ * @param onParse - Callback to invoke when a new event is parsed, or a new reconnection interval
91
+ * has been sent from the server
92
+ *
93
+ * @returns A new Parser parser, with `parse`, `end` and `reset` methods.
94
+ * @public
95
+ */
96
+ declare function create(options?: ParserOptions<AimSegments[], AimSegments[], string> & {
97
+ vad?: VADTimeItem[];
98
+ }): Parser<string>;
99
+
87
100
  export declare namespace filter {
88
101
  export {
89
102
  StreamFilter
@@ -113,14 +126,74 @@ declare interface OptimizationOptions {
113
126
  */
114
127
  declare function padNumber(num: number, length?: number): string;
115
128
 
129
+ /**
130
+ * Callback passed as the `onParse` callback to a parser
131
+ *
132
+ * @public
133
+ */
134
+ declare type ParseCallback<T> = (event: ParsedEvent<T>) => void;
135
+
136
+ declare interface ParsedEvent<T> {
137
+ type: "event";
138
+ event: "start" | "message" | "end";
139
+ data?: T;
140
+ }
141
+
142
+ /**
143
+ * Parser parser instance.
144
+ *
145
+ * Needs to be reset between reconnections/when switching data source, using the `reset()` method.
146
+ *
147
+ * @public
148
+ */
149
+ declare interface Parser<T = string> {
150
+ /**
151
+ * Feeds the parser another chunk. The method _does not_ return a parsed message.
152
+ * Instead, if the chunk was a complete message (or completed a previously incomplete message),
153
+ * it will invoke the `onParse` callback used to create the parsers.
154
+ *
155
+ * @param chunk - The chunk to parse. Can be a partial, eg in the case of streaming messages.
156
+ * @public
157
+ */
158
+ feed(chunk: T): void;
159
+ /**
160
+ * Resets the parser state. This is required when you have a new stream of messages -
161
+ * for instance in the case of a client being disconnected and reconnecting.
162
+ *
163
+ * @public
164
+ */
165
+ reset(): void;
166
+ end(): void;
167
+ }
168
+
116
169
  export declare namespace parser {
117
170
  export {
118
171
  srtToAimSegments,
119
172
  vttToAimSegments,
120
- assToAimSegments
173
+ assToAimSegments,
174
+ create as createWhisperStreamParser
121
175
  }
122
176
  }
123
177
 
178
+ /**
179
+ * `ParserOptions` 是一个泛型类型,用于配置解析器的回调函数。
180
+ *
181
+ * @template S - 解析开始时的状态类型
182
+ * @template P - 解析过程中使用的状态类型
183
+ * @template E - 解析结束时的状态类型
184
+ *
185
+ * @property {ParseCallback<S>} [onStart] - 解析开始时的回调函数
186
+ * @property {ParseCallback<P>} [onParse] - 解析过程中调用的回调函数
187
+ * @property {ParseCallback<P>} [onProgress] - 解析进度更新时的回调函数
188
+ * @property {ParseCallback<E>} [onEnd] - 解析结束时的回调函数
189
+ */
190
+ declare type ParserOptions<S, P, E> = {
191
+ onStart?: ParseCallback<S>;
192
+ onParse?: ParseCallback<P>;
193
+ onProgress?: ParseCallback<P>;
194
+ onEnd?: ParseCallback<E>;
195
+ };
196
+
124
197
  declare class RepeatCheck {
125
198
  threshold: number;
126
199
  hit: number;
@@ -195,6 +268,11 @@ export declare namespace utils {
195
268
  }
196
269
  }
197
270
 
271
+ declare type VADTimeItem = {
272
+ start: number;
273
+ end: number;
274
+ };
275
+
198
276
  declare function vttToAimSegments(text: string): Promise<AimSegments[]>;
199
277
 
200
278
  export { }