@aim-packages/subtitle 0.0.1 → 0.0.2

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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(e,t=2){return e.toString().padStart(t,"0")}function m(e){const t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%3600%60,o=Math.floor(r%1*1e3),l=g(t),a=g(n),p=g(Math.floor(r)),u=g(o,3);return`${l}:${a}:${p}.${u}`}function S(e){if(!e)return 0;const t=e.split(":");try{let n=t[2].split(",");return n.length===1&&(n=t[2].split(".")),parseFloat(t[0])*3600+parseFloat(t[1])*60+parseFloat(n[0])+parseFloat("0."+n[1])}catch{return 0}}const N=Object.freeze(Object.defineProperty({__proto__:null,convertToSeconds:S,formatTime:m,padNumber:g},Symbol.toStringTag,{value:"Module"}));/**
1
+ "use strict";var b=Object.defineProperty;var j=(s,e,t)=>e in s?b(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var f=(s,e,t)=>j(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s,e=2){return s.toString().padStart(e,"0")}function m(s){const e=Math.floor(s/3600),t=Math.floor(s%3600/60),r=s%3600%60,n=Math.floor(r%1*1e3),i=g(e),c=g(t),o=g(Math.floor(r)),d=g(n,3);return`${i}:${c}:${o}.${d}`}function y(s){if(!s)return 0;const e=s.split(":");try{let t=e[2].split(",");return t.length===1&&(t=e[2].split(".")),parseFloat(e[0])*3600+parseFloat(e[1])*60+parseFloat(t[0])+parseFloat("0."+t[1])}catch{return 0}}const w=Object.freeze(Object.defineProperty({__proto__:null,convertToSeconds:y,formatTime:m,padNumber:g},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 b(e){const t=new RegExp("Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$","i");function n(r=""){return r.split(/[:.]/).map((o,l,a)=>{if(l===a.length-1){if(o.length===1)return"."+o+"00";if(o.length===2)return"."+o+"0"}else if(o.length===1)return(l===0?"0":":0")+o;return l===0?o:l===a.length-1?"."+o:":"+o}).join("")}return`WEBVTT
6
+ */function F(s){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 t(r=""){return r.split(/[:.]/).map((n,i,c)=>{if(i===c.length-1){if(n.length===1)return"."+n+"00";if(n.length===2)return"."+n+"0"}else if(n.length===1)return(i===0?"0":":0")+n;return i===0?n:i===c.length-1?"."+n:":"+n}).join("")}return`WEBVTT
7
7
 
8
- `+e.split(/\r?\n/).map(r=>{const o=r.match(t);return o?{start:n(o[1].trim()),end:n(o[2].trim()),text:o[5].replace(/{[\s\S]*?}/g,"").replace(/(\\N)/g,"<br />").trim().split(/\r?\n/).map(l=>l.trim()).join(`
9
- `)}:null}).filter(r=>r).map((r,o)=>r?r.start+" --> "+r.end+`
8
+ `+s.split(/\r?\n/).map(r=>{const n=r.match(e);return n?{start:t(n[1].trim()),end:t(n[2].trim()),text:n[5].replace(/{[\s\S]*?}/g,"").replace(/(\\N)/g,"<br />").trim().split(/\r?\n/).map(i=>i.trim()).join(`
9
+ `)}:null}).filter(r=>r).map((r,n)=>r?r.start+" --> "+r.end+`
10
10
  `+r.text:"").filter(r=>r.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 j(e,t){let n=t;for(;!e[n];)n++;return n}function _(e){let t=e.length-1;for(;t>=0&&!e[t];)t--;return t}function O(e="",t={propName:{}}){const n=[],r=e.split(/(?:\r\n|\r|\n)/gm).filter(s=>s.length>0),o=r.map((s,c)=>r[c+2]&&/\d{2}:\d{2}:\d{2}[,\.]\d{2,3}\s*-->\s*\d{2}:\d{2}:\d{2}[,\.]\d{2,3}/.test(r[c+2])?s+`\r
21
- `:s).join(`
22
- `).split(/(?:\r\n|\r|\n)/gm),l=_(o)+1;let a=0,p,u,i;for(let s=0;s<l;s++){for(i={},u=[],s=j(o,s),i.id=parseInt(o[s++],10),p=o[s++].split(/[\t ]*-->[\t ]*/),i[t.propName.start||"start"]=t.timeInText?p[0]:S(p[0]),a=p[1].indexOf(" "),a!==-1&&(p[1]=p[1].substr(0,a)),i[t.propName.end||"end"]=t.timeInText?p[1]:S(p[1]);s<l&&o[s];)u.push(o[s++]);const c=t.propName.text||"text";i[c]=u.join(t.keepMultiLine?`
23
- `:" ").replace(/\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}/gi,""),i[c]=i[c].replace(/</g,"&lt;").replace(/>/g,"&gt;"),i[c]=i[c].replace(/&lt;(\/?(font|b|u|i|s))((\s+(\w|\w[\w\-]*\w)(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/?)&gt;/gi,"<$1$3$7>"),t.ignoreLineBreaks?i[c]=i[c].replace(/\\N/gi,""):i[c]=i[c].replace(/\\N/gi,"<br />"),n.push(i)}return n}function v(e,t){const n=/<\/?[^>]+(>|$)/g;return new Promise((r,o)=>{let l={};const a=[];let p=!1;const u=e.split(`
24
- `);u.forEach((s,c)=>{s.replace(n,"")===" "||s.replace(n,"")===""||(s.indexOf("-->")!==-1?(p=!0,typeof l.start=="number"&&l.start>=0&&a.push(T(l)),l={start:y(s.split("-->")[0].trimRight().split(" ").pop()),end:y(s.split("-->")[1].trimLeft().split(" ").shift()),part:""}):p&&(a.length!==0?(a[a.length-1].part.replace(n,""),s.replace(n,""),l.part.length===0?l.part=s:l.part=`${l.part}
25
- ${s}`,c===u.length-1&&a.push(T(l))):(l.part=s,a.push(T(l)),l.part="")))}),l=[];const i=/(<([0-9:.>]+)>)/ig;a.forEach(s=>{const M=s.part.split().map(function(f){return f.replace(i,function(d){return d.split("").reduce(function(x,F){return`==${d.replace("<","").replace(">","")}`},0)})})[0].replace(n,"").split(" "),h=[];M.forEach(function(f){if(f.indexOf("==")>-1){const d=f.split("=="),x=d[0];if(d[1],x==""||x=="##")return;h.push({word:w(f.split("==")[0]),time:y(f.split("==")[1])})}else h.push({word:w(f),time:void 0})}),s.words=h,s.part=s.part.replace(n,"")}),r(a)})}function y(e){const t=e.split(":"),n=t[t.length-3]?+t[t.length-3]:0,r=t[t.length-2]?+t[t.length-2]:0,o=+t[t.length-1];return n*3600+r*60+o}function w(e){return e.replace(/[^0-9a-z'-]/gi,"").toLowerCase()}function T(e){if(e==null||typeof e!="object")return e;const t=e.constructor();for(const n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}async function L(e){return O(e,{keepMultiLine:!0,propName:{}}).filter(r=>r.text).map(r=>({st:m(r.start),et:m(r.end),text:r.text}))}async function $(e){return(await v(e)).filter(r=>r.part).map(r=>({st:m(r.start),et:m(r.end),text:r.part}))}async function E(e){return $(b(e))}const P=Object.freeze(Object.defineProperty({__proto__:null,assToAimSegments:E,srtToAimSegments:L,vttToAimSegments:$},Symbol.toStringTag,{value:"Module"}));exports.parser=P;exports.utils=N;
20
+ */function $(s,e){let t=e;for(;!s[t];)t++;return t}function M(s){let e=s.length-1;for(;e>=0&&!s[e];)e--;return e}function E(s="",e={propName:{}}){const t=[],r=s.split(/(?:\r\n|\r|\n)/gm).filter(l=>l.length>0),n=r.map((l,a)=>r[a+2]&&/\d{2}:\d{2}:\d{2}[,\.]\d{2,3}\s*-->\s*\d{2}:\d{2}:\d{2}[,\.]\d{2,3}/.test(r[a+2])?l+`\r
21
+ `:l).join(`
22
+ `).split(/(?:\r\n|\r|\n)/gm),i=M(n)+1;let c=0,o,d,h;for(let l=0;l<i;l++){for(h={},d=[],l=$(n,l),h.id=parseInt(n[l++],10),o=n[l++].split(/[\t ]*-->[\t ]*/),h[e.propName.start||"start"]=e.timeInText?o[0]:y(o[0]),c=o[1].indexOf(" "),c!==-1&&(o[1]=o[1].substr(0,c)),h[e.propName.end||"end"]=e.timeInText?o[1]:y(o[1]);l<i&&n[l];)d.push(n[l++]);const a=e.propName.text||"text";h[a]=d.join(e.keepMultiLine?`
23
+ `:" ").replace(/\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}/gi,""),h[a]=h[a].replace(/</g,"&lt;").replace(/>/g,"&gt;"),h[a]=h[a].replace(/&lt;(\/?(font|b|u|i|s))((\s+(\w|\w[\w\-]*\w)(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/?)&gt;/gi,"<$1$3$7>"),e.ignoreLineBreaks?h[a]=h[a].replace(/\\N/gi,""):h[a]=h[a].replace(/\\N/gi,"<br />"),t.push(h)}return t}function N(s,e){const t=/<\/?[^>]+(>|$)/g;return new Promise((r,n)=>{let i={};const c=[];let o=!1;const d=s.split(`
24
+ `);d.forEach((l,a)=>{l.replace(t,"")===" "||l.replace(t,"")===""||(l.indexOf("-->")!==-1?(o=!0,typeof i.start=="number"&&i.start>=0&&c.push(v(i)),i={start:k(l.split("-->")[0].trimRight().split(" ").pop()),end:k(l.split("-->")[1].trimLeft().split(" ").shift()),part:""}):o&&(c.length!==0?(c[c.length-1].part.replace(t,""),l.replace(t,""),i.part.length===0?i.part=l:i.part=`${i.part}
25
+ ${l}`,a===d.length-1&&c.push(v(i))):(i.part=l,c.push(v(i)),i.part="")))}),i=[];const h=/(<([0-9:.>]+)>)/ig;c.forEach(l=>{const _=l.part.split().map(function(p){return p.replace(h,function(u){return u.split("").reduce(function(T,D){return`==${u.replace("<","").replace(">","")}`},0)})})[0].replace(t,"").split(" "),x=[];_.forEach(function(p){if(p.indexOf("==")>-1){const u=p.split("=="),T=u[0];if(u[1],T==""||T=="##")return;x.push({word:L(p.split("==")[0]),time:k(p.split("==")[1])})}else x.push({word:L(p),time:void 0})}),l.words=x,l.part=l.part.replace(t,"")}),r(c)})}function k(s){const e=s.split(":"),t=e[e.length-3]?+e[e.length-3]:0,r=e[e.length-2]?+e[e.length-2]:0,n=+e[e.length-1];return t*3600+r*60+n}function L(s){return s.replace(/[^0-9a-z'-]/gi,"").toLowerCase()}function v(s){if(s==null||typeof s!="object")return s;const e=s.constructor();for(const t in s)s.hasOwnProperty(t)&&(e[t]=s[t]);return e}async function O(s){return E(s,{keepMultiLine:!0,propName:{}}).filter(r=>r.text).map(r=>({st:m(r.start),et:m(r.end),text:r.text}))}async function S(s){return(await N(s)).filter(r=>r.part).map(r=>({st:m(r.start),et:m(r.end),text:r.part}))}async function P(s){return S(F(s))}const A=Object.freeze(Object.defineProperty({__proto__:null,assToAimSegments:P,srtToAimSegments:O,vttToAimSegments:S},Symbol.toStringTag,{value:"Module"}));class z{constructor(e){f(this,"chains",{});f(this,"delimit","__replace__");f(this,"onFilter");f(this,"checked",!1);f(this,"checkedText","");f(this,"checkedLevel");f(this,"filteredText","");this.onFilter=e}add(e,t){typeof e!="string"&&(e=new TextDecoder().decode(e));const r=e;if(!r)return;let n=this.chains;for(let i=0;i<r.length;i++){if(r[i]in n)n=n[r[i]];else{if(!(n instanceof Object))break;let c,o;for(let d=i;d<r.length;d++)n[r[d]]={},[c,o]=[n,r[d]],n=n[r[d]];c&&o&&(c[o]={[this.delimit]:t||""});break}i===r.length-1&&(n[this.delimit]=t||"")}}parse(e){e.forEach(t=>{this.add(...t)})}reParse(e){this.chains={},e.forEach(t=>{this.add(t[0],t[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 t=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;t&&t.length&&t.split("").forEach(r=>{this.filteredText+=r,this.onFilter&&this.onFilter(r)}),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(r=>{this.feed(r)}),this.end()):""}end(){if(this.checked&&this.checkedText){const t=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;t&&t.length&&t.split("").forEach(r=>{this.onFilter&&this.onFilter(r),this.filteredText+=r}),this.checkedText="",this.checkedLevel=void 0,this.checked=!1}const e=this.filteredText;return this.filteredText="",e}}const I=Object.freeze(Object.defineProperty({__proto__:null,StreamFilter:z},Symbol.toStringTag,{value:"Module"}));exports.filter=I;exports.parser=A;exports.utils=w;
package/dist/index.d.ts CHANGED
@@ -75,6 +75,12 @@ declare function assToAimSegments(text: string): Promise<AimSegments[]>;
75
75
  */
76
76
  declare function convertToSeconds(time?: string): number;
77
77
 
78
+ export declare namespace filter {
79
+ export {
80
+ StreamFilter
81
+ }
82
+ }
83
+
78
84
  /**
79
85
  * 将秒数转换为 xx:xx:xx.xxx 格式
80
86
  *
@@ -99,6 +105,23 @@ export declare namespace parser {
99
105
 
100
106
  declare function srtToAimSegments(text: string): Promise<AimSegments[]>;
101
107
 
108
+ declare class StreamFilter {
109
+ chains: Record<string, any>;
110
+ delimit: string;
111
+ onFilter?: (text: string) => any;
112
+ checked: boolean;
113
+ checkedText: string;
114
+ checkedLevel?: Record<string, any>;
115
+ filteredText: string;
116
+ constructor(onFilter?: (text: string) => any);
117
+ add(keyword: string, replaceText?: string): void;
118
+ parse(data: [string, string][]): void;
119
+ reParse(data: string[][]): void;
120
+ feed(c: string): void;
121
+ feedAll(text: string): string;
122
+ end(): string;
123
+ }
124
+
102
125
  export declare namespace utils {
103
126
  export {
104
127
  padNumber,
package/dist/index.es.js CHANGED
@@ -1,24 +1,27 @@
1
- function g(e, t = 2) {
2
- return e.toString().padStart(t, "0");
1
+ var b = Object.defineProperty;
2
+ var w = (s, e, t) => e in s ? b(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var f = (s, e, t) => w(s, typeof e != "symbol" ? e + "" : e, t);
4
+ function g(s, e = 2) {
5
+ return s.toString().padStart(e, "0");
3
6
  }
4
- function m(e) {
5
- const t = Math.floor(e / 3600), n = Math.floor(e % 3600 / 60), r = e % 3600 % 60, o = Math.floor(r % 1 * 1e3), l = g(t), a = g(n), p = g(Math.floor(r)), u = g(o, 3);
6
- return `${l}:${a}:${p}.${u}`;
7
+ function m(s) {
8
+ const e = Math.floor(s / 3600), t = Math.floor(s % 3600 / 60), r = s % 3600 % 60, n = Math.floor(r % 1 * 1e3), i = g(e), c = g(t), o = g(Math.floor(r)), d = g(n, 3);
9
+ return `${i}:${c}:${o}.${d}`;
7
10
  }
8
- function y(e) {
9
- if (!e)
11
+ function L(s) {
12
+ if (!s)
10
13
  return 0;
11
- const t = e.split(":");
14
+ const e = s.split(":");
12
15
  try {
13
- let n = t[2].split(",");
14
- return n.length === 1 && (n = t[2].split(".")), parseFloat(t[0]) * 3600 + parseFloat(t[1]) * 60 + parseFloat(n[0]) + parseFloat("0." + n[1]);
16
+ let t = e[2].split(",");
17
+ return t.length === 1 && (t = e[2].split(".")), parseFloat(e[0]) * 3600 + parseFloat(e[1]) * 60 + parseFloat(t[0]) + parseFloat("0." + t[1]);
15
18
  } catch {
16
19
  return 0;
17
20
  }
18
21
  }
19
- const k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
22
+ const B = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
20
23
  __proto__: null,
21
- convertToSeconds: y,
24
+ convertToSeconds: L,
22
25
  formatTime: m,
23
26
  padNumber: g
24
27
  }, Symbol.toStringTag, { value: "Module" }));
@@ -28,34 +31,34 @@ const k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
28
31
  * @author YuQian2015 (https://github.com/YuQian2015)
29
32
  * @license MIT
30
33
  */
31
- function M(e) {
32
- const t = new RegExp(
34
+ function F(s) {
35
+ const e = new RegExp(
33
36
  "Dialogue:\\s\\d,(\\d+:\\d\\d:\\d\\d.\\d\\d),(\\d+:\\d\\d:\\d\\d.\\d\\d),([^,]*),([^,]*),(?:[^,]*,){4}([\\s\\S]*)$",
34
37
  "i"
35
38
  );
36
- function n(r = "") {
37
- return r.split(/[:.]/).map((o, l, a) => {
38
- if (l === a.length - 1) {
39
- if (o.length === 1)
40
- return "." + o + "00";
41
- if (o.length === 2)
42
- return "." + o + "0";
43
- } else if (o.length === 1)
44
- return (l === 0 ? "0" : ":0") + o;
45
- return l === 0 ? o : l === a.length - 1 ? "." + o : ":" + o;
39
+ function t(r = "") {
40
+ return r.split(/[:.]/).map((n, i, c) => {
41
+ if (i === c.length - 1) {
42
+ if (n.length === 1)
43
+ return "." + n + "00";
44
+ if (n.length === 2)
45
+ return "." + n + "0";
46
+ } else if (n.length === 1)
47
+ return (i === 0 ? "0" : ":0") + n;
48
+ return i === 0 ? n : i === c.length - 1 ? "." + n : ":" + n;
46
49
  }).join("");
47
50
  }
48
51
  return `WEBVTT
49
52
 
50
- ` + e.split(/\r?\n/).map((r) => {
51
- const o = r.match(t);
52
- return o ? {
53
- start: n(o[1].trim()),
54
- end: n(o[2].trim()),
55
- text: o[5].replace(/{[\s\S]*?}/g, "").replace(/(\\N)/g, "<br />").trim().split(/\r?\n/).map((l) => l.trim()).join(`
53
+ ` + s.split(/\r?\n/).map((r) => {
54
+ const n = r.match(e);
55
+ return n ? {
56
+ start: t(n[1].trim()),
57
+ end: t(n[2].trim()),
58
+ text: n[5].replace(/{[\s\S]*?}/g, "").replace(/(\\N)/g, "<br />").trim().split(/\r?\n/).map((i) => i.trim()).join(`
56
59
  `)
57
60
  } : null;
58
- }).filter((r) => r).map((r, o) => r ? r.start + " --> " + r.end + `
61
+ }).filter((r) => r).map((r, n) => r ? r.start + " --> " + r.end + `
59
62
  ` + r.text : "").filter((r) => r.trim()).join(`
60
63
 
61
64
  `);
@@ -69,92 +72,92 @@ function M(e) {
69
72
  * @version 1.0.1
70
73
  * @license MIT
71
74
  */
72
- function j(e, t) {
73
- let n = t;
74
- for (; !e[n]; )
75
- n++;
76
- return n;
77
- }
78
- function _(e) {
79
- let t = e.length - 1;
80
- for (; t >= 0 && !e[t]; )
81
- t--;
75
+ function $(s, e) {
76
+ let t = e;
77
+ for (; !s[t]; )
78
+ t++;
82
79
  return t;
83
80
  }
84
- function b(e = "", t = { propName: {} }) {
85
- const n = [], r = e.split(/(?:\r\n|\r|\n)/gm).filter((s) => s.length > 0), o = r.map((s, c) => r[c + 2] && /\d{2}:\d{2}:\d{2}[,\.]\d{2,3}\s*-->\s*\d{2}:\d{2}:\d{2}[,\.]\d{2,3}/.test(r[c + 2]) ? s + `\r
86
- ` : s).join(`
87
- `).split(/(?:\r\n|\r|\n)/gm), l = _(o) + 1;
88
- let a = 0, p, u, i;
89
- for (let s = 0; s < l; s++) {
90
- for (i = {}, u = [], s = j(o, s), i.id = parseInt(o[s++], 10), p = o[s++].split(/[\t ]*-->[\t ]*/), i[t.propName.start || "start"] = t.timeInText ? p[0] : y(p[0]), a = p[1].indexOf(" "), a !== -1 && (p[1] = p[1].substr(0, a)), i[t.propName.end || "end"] = t.timeInText ? p[1] : y(p[1]); s < l && o[s]; )
91
- u.push(o[s++]);
92
- const c = t.propName.text || "text";
93
- i[c] = u.join(t.keepMultiLine ? `
94
- ` : " ").replace(/\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}/gi, ""), i[c] = i[c].replace(/</g, "&lt;").replace(/>/g, "&gt;"), i[c] = i[c].replace(/&lt;(\/?(font|b|u|i|s))((\s+(\w|\w[\w\-]*\w)(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/?)&gt;/gi, "<$1$3$7>"), t.ignoreLineBreaks ? i[c] = i[c].replace(/\\N/gi, "") : i[c] = i[c].replace(/\\N/gi, "<br />"), n.push(i);
81
+ function j(s) {
82
+ let e = s.length - 1;
83
+ for (; e >= 0 && !s[e]; )
84
+ e--;
85
+ return e;
86
+ }
87
+ function E(s = "", e = { propName: {} }) {
88
+ const t = [], r = s.split(/(?:\r\n|\r|\n)/gm).filter((l) => l.length > 0), n = r.map((l, a) => r[a + 2] && /\d{2}:\d{2}:\d{2}[,\.]\d{2,3}\s*-->\s*\d{2}:\d{2}:\d{2}[,\.]\d{2,3}/.test(r[a + 2]) ? l + `\r
89
+ ` : l).join(`
90
+ `).split(/(?:\r\n|\r|\n)/gm), i = j(n) + 1;
91
+ let c = 0, o, d, h;
92
+ for (let l = 0; l < i; l++) {
93
+ for (h = {}, d = [], l = $(n, l), h.id = parseInt(n[l++], 10), o = n[l++].split(/[\t ]*-->[\t ]*/), h[e.propName.start || "start"] = e.timeInText ? o[0] : L(o[0]), c = o[1].indexOf(" "), c !== -1 && (o[1] = o[1].substr(0, c)), h[e.propName.end || "end"] = e.timeInText ? o[1] : L(o[1]); l < i && n[l]; )
94
+ d.push(n[l++]);
95
+ const a = e.propName.text || "text";
96
+ h[a] = d.join(e.keepMultiLine ? `
97
+ ` : " ").replace(/\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}/gi, ""), h[a] = h[a].replace(/</g, "&lt;").replace(/>/g, "&gt;"), h[a] = h[a].replace(/&lt;(\/?(font|b|u|i|s))((\s+(\w|\w[\w\-]*\w)(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/?)&gt;/gi, "<$1$3$7>"), e.ignoreLineBreaks ? h[a] = h[a].replace(/\\N/gi, "") : h[a] = h[a].replace(/\\N/gi, "<br />"), t.push(h);
95
98
  }
96
- return n;
99
+ return t;
97
100
  }
98
- function L(e, t) {
99
- const n = /<\/?[^>]+(>|$)/g;
100
- return new Promise((r, o) => {
101
- let l = {};
102
- const a = [];
103
- let p = !1;
104
- const u = e.split(`
101
+ function M(s, e) {
102
+ const t = /<\/?[^>]+(>|$)/g;
103
+ return new Promise((r, n) => {
104
+ let i = {};
105
+ const c = [];
106
+ let o = !1;
107
+ const d = s.split(`
105
108
  `);
106
- u.forEach((s, c) => {
107
- s.replace(n, "") === " " || s.replace(n, "") === "" || (s.indexOf("-->") !== -1 ? (p = !0, typeof l.start == "number" && l.start >= 0 && a.push(w(l)), l = {
108
- start: T(s.split("-->")[0].trimRight().split(" ").pop()),
109
- end: T(s.split("-->")[1].trimLeft().split(" ").shift()),
109
+ d.forEach((l, a) => {
110
+ l.replace(t, "") === " " || l.replace(t, "") === "" || (l.indexOf("-->") !== -1 ? (o = !0, typeof i.start == "number" && i.start >= 0 && c.push(v(i)), i = {
111
+ start: k(l.split("-->")[0].trimRight().split(" ").pop()),
112
+ end: k(l.split("-->")[1].trimLeft().split(" ").shift()),
110
113
  part: ""
111
- }) : p && (a.length !== 0 ? (a[a.length - 1].part.replace(n, ""), s.replace(n, ""), l.part.length === 0 ? l.part = s : l.part = `${l.part}
112
- ${s}`, c === u.length - 1 && a.push(w(l))) : (l.part = s, a.push(w(l)), l.part = "")));
113
- }), l = [];
114
- const i = /(<([0-9:.>]+)>)/ig;
115
- a.forEach((s) => {
116
- const N = s.part.split().map(function(f) {
117
- return f.replace(i, function(d) {
118
- return d.split("").reduce(function(x, P) {
119
- return `==${d.replace("<", "").replace(">", "")}`;
114
+ }) : o && (c.length !== 0 ? (c[c.length - 1].part.replace(t, ""), l.replace(t, ""), i.part.length === 0 ? i.part = l : i.part = `${i.part}
115
+ ${l}`, a === d.length - 1 && c.push(v(i))) : (i.part = l, c.push(v(i)), i.part = "")));
116
+ }), i = [];
117
+ const h = /(<([0-9:.>]+)>)/ig;
118
+ c.forEach((l) => {
119
+ const S = l.part.split().map(function(p) {
120
+ return p.replace(h, function(u) {
121
+ return u.split("").reduce(function(T, I) {
122
+ return `==${u.replace("<", "").replace(">", "")}`;
120
123
  }, 0);
121
124
  });
122
- })[0].replace(n, "").split(" "), h = [];
123
- N.forEach(function(f) {
124
- if (f.indexOf("==") > -1) {
125
- const d = f.split("=="), x = d[0];
126
- if (d[1], x == "" || x == "##")
125
+ })[0].replace(t, "").split(" "), x = [];
126
+ S.forEach(function(p) {
127
+ if (p.indexOf("==") > -1) {
128
+ const u = p.split("=="), T = u[0];
129
+ if (u[1], T == "" || T == "##")
127
130
  return;
128
- h.push({
129
- word: S(f.split("==")[0]),
130
- time: T(f.split("==")[1])
131
+ x.push({
132
+ word: _(p.split("==")[0]),
133
+ time: k(p.split("==")[1])
131
134
  });
132
135
  } else
133
- h.push({
134
- word: S(f),
136
+ x.push({
137
+ word: _(p),
135
138
  time: void 0
136
139
  });
137
- }), s.words = h, s.part = s.part.replace(n, "");
138
- }), r(a);
140
+ }), l.words = x, l.part = l.part.replace(t, "");
141
+ }), r(c);
139
142
  });
140
143
  }
141
- function T(e) {
142
- const t = e.split(":"), n = t[t.length - 3] ? +t[t.length - 3] : 0, r = t[t.length - 2] ? +t[t.length - 2] : 0, o = +t[t.length - 1];
143
- return n * 3600 + r * 60 + o;
144
+ function k(s) {
145
+ const e = s.split(":"), t = e[e.length - 3] ? +e[e.length - 3] : 0, r = e[e.length - 2] ? +e[e.length - 2] : 0, n = +e[e.length - 1];
146
+ return t * 3600 + r * 60 + n;
144
147
  }
145
- function S(e) {
146
- return e.replace(/[^0-9a-z'-]/gi, "").toLowerCase();
148
+ function _(s) {
149
+ return s.replace(/[^0-9a-z'-]/gi, "").toLowerCase();
147
150
  }
148
- function w(e) {
149
- if (e == null || typeof e != "object")
150
- return e;
151
- const t = e.constructor();
152
- for (const n in e)
153
- e.hasOwnProperty(n) && (t[n] = e[n]);
154
- return t;
151
+ function v(s) {
152
+ if (s == null || typeof s != "object")
153
+ return s;
154
+ const e = s.constructor();
155
+ for (const t in s)
156
+ s.hasOwnProperty(t) && (e[t] = s[t]);
157
+ return e;
155
158
  }
156
- async function O(e) {
157
- return b(e, {
159
+ async function N(s) {
160
+ return E(s, {
158
161
  keepMultiLine: !0,
159
162
  propName: {}
160
163
  }).filter((r) => r.text).map((r) => ({
@@ -163,23 +166,106 @@ async function O(e) {
163
166
  text: r.text
164
167
  }));
165
168
  }
166
- async function $(e) {
167
- return (await L(e)).filter((r) => r.part).map((r) => ({
169
+ async function y(s) {
170
+ return (await M(s)).filter((r) => r.part).map((r) => ({
168
171
  st: m(r.start),
169
172
  et: m(r.end),
170
173
  text: r.part
171
174
  }));
172
175
  }
173
- async function v(e) {
174
- return $(M(e));
176
+ async function O(s) {
177
+ return y(F(s));
178
+ }
179
+ const D = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
180
+ __proto__: null,
181
+ assToAimSegments: O,
182
+ srtToAimSegments: N,
183
+ vttToAimSegments: y
184
+ }, Symbol.toStringTag, { value: "Module" }));
185
+ class P {
186
+ constructor(e) {
187
+ f(this, "chains", {});
188
+ f(this, "delimit", "__replace__");
189
+ f(this, "onFilter");
190
+ f(this, "checked", !1);
191
+ f(this, "checkedText", "");
192
+ f(this, "checkedLevel");
193
+ f(this, "filteredText", "");
194
+ this.onFilter = e;
195
+ }
196
+ add(e, t) {
197
+ typeof e != "string" && (e = new TextDecoder().decode(e));
198
+ const r = e;
199
+ if (!r)
200
+ return;
201
+ let n = this.chains;
202
+ for (let i = 0; i < r.length; i++) {
203
+ if (r[i] in n)
204
+ n = n[r[i]];
205
+ else {
206
+ if (!(n instanceof Object))
207
+ break;
208
+ let c, o;
209
+ for (let d = i; d < r.length; d++)
210
+ n[r[d]] = {}, [c, o] = [n, r[d]], n = n[r[d]];
211
+ c && o && (c[o] = { [this.delimit]: t || "" });
212
+ break;
213
+ }
214
+ i === r.length - 1 && (n[this.delimit] = t || "");
215
+ }
216
+ }
217
+ parse(e) {
218
+ e.forEach((t) => {
219
+ this.add(...t);
220
+ });
221
+ }
222
+ reParse(e) {
223
+ this.chains = {}, e.forEach((t) => {
224
+ this.add(t[0], t[1]);
225
+ });
226
+ }
227
+ feed(e) {
228
+ if (!this.checked && !this.chains[e]) {
229
+ this.filteredText += e, this.onFilter && this.onFilter(e);
230
+ return;
231
+ }
232
+ if (!this.checked && this.chains[e]) {
233
+ this.checked = !0, this.checkedLevel = this.chains[e], this.checkedText += e;
234
+ return;
235
+ }
236
+ if (this.checked && this.checkedLevel[e]) {
237
+ this.checkedLevel = this.checkedLevel[e], this.checkedText += e;
238
+ return;
239
+ }
240
+ if (this.checked && !this.checkedLevel[e]) {
241
+ const t = typeof this.checkedLevel[this.delimit] == "string" ? this.checkedLevel[this.delimit] : this.checkedText;
242
+ t && t.length && t.split("").forEach((r) => {
243
+ this.filteredText += r, this.onFilter && this.onFilter(r);
244
+ }), 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);
245
+ }
246
+ }
247
+ feedAll(e) {
248
+ return e.length ? (e.split("").forEach((r) => {
249
+ this.feed(r);
250
+ }), this.end()) : "";
251
+ }
252
+ end() {
253
+ if (this.checked && this.checkedText) {
254
+ const t = typeof this.checkedLevel[this.delimit] == "string" ? this.checkedLevel[this.delimit] : this.checkedText;
255
+ t && t.length && t.split("").forEach((r) => {
256
+ this.onFilter && this.onFilter(r), this.filteredText += r;
257
+ }), this.checkedText = "", this.checkedLevel = void 0, this.checked = !1;
258
+ }
259
+ const e = this.filteredText;
260
+ return this.filteredText = "", e;
261
+ }
175
262
  }
176
- const F = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
263
+ const H = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
177
264
  __proto__: null,
178
- assToAimSegments: v,
179
- srtToAimSegments: O,
180
- vttToAimSegments: $
265
+ StreamFilter: P
181
266
  }, Symbol.toStringTag, { value: "Module" }));
182
267
  export {
183
- F as parser,
184
- k as utils
268
+ H as filter,
269
+ D as parser,
270
+ B as utils
185
271
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aim-packages/subtitle",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "main": "dist/index.cjs.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {