@naersen/tts-rich-text 0.11.0 → 0.12.1
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/CHANGELOG.md +29 -0
- package/README.md +11 -0
- package/dist/core/config.d.ts +3 -0
- package/dist/core/split-sentence-default.d.ts +7 -0
- package/dist/core/split-sentence-legacy.d.ts +2 -0
- package/dist/core/split-sentence.d.ts +10 -6
- package/dist/core.js +377 -244
- package/dist/index.js +1495 -1493
- package/package.json +87 -89
package/dist/core.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
const
|
|
1
|
+
const h = {
|
|
2
2
|
DELETE_NODE: "deleteNode",
|
|
3
3
|
CONVERT_TO_TEXT: "convertToText"
|
|
4
|
-
},
|
|
4
|
+
}, $t = 256, Dt = 256, p = {
|
|
5
5
|
stop: {
|
|
6
6
|
label: "停顿",
|
|
7
7
|
icon: "editor-stop",
|
|
8
8
|
type: "stop",
|
|
9
|
-
deleteMode:
|
|
9
|
+
deleteMode: h.DELETE_NODE
|
|
10
10
|
},
|
|
11
11
|
customStop: {
|
|
12
12
|
label: "长停顿",
|
|
13
13
|
icon: "editor-stop-long",
|
|
14
14
|
type: "customStop",
|
|
15
|
-
deleteMode:
|
|
15
|
+
deleteMode: h.DELETE_NODE
|
|
16
16
|
},
|
|
17
17
|
continue: {
|
|
18
18
|
label: "连续",
|
|
19
19
|
icon: "editor-continue",
|
|
20
20
|
type: "continue",
|
|
21
|
-
deleteMode:
|
|
21
|
+
deleteMode: h.CONVERT_TO_TEXT
|
|
22
22
|
},
|
|
23
23
|
pinyin: {
|
|
24
24
|
label: "拼音标注",
|
|
25
25
|
icon: "editor-pinyin",
|
|
26
26
|
type: "pinyin",
|
|
27
|
-
deleteMode:
|
|
27
|
+
deleteMode: h.CONVERT_TO_TEXT
|
|
28
28
|
},
|
|
29
29
|
replace: {
|
|
30
30
|
label: "替换",
|
|
31
31
|
icon: "editor-replace",
|
|
32
32
|
type: "replace",
|
|
33
|
-
deleteMode:
|
|
33
|
+
deleteMode: h.CONVERT_TO_TEXT
|
|
34
34
|
},
|
|
35
35
|
language: {
|
|
36
36
|
label: "语种标记",
|
|
37
37
|
icon: "editor-language",
|
|
38
38
|
type: "language",
|
|
39
|
-
deleteMode:
|
|
39
|
+
deleteMode: h.CONVERT_TO_TEXT
|
|
40
40
|
},
|
|
41
41
|
tone: {
|
|
42
42
|
label: "语气",
|
|
43
43
|
icon: "editor-tone",
|
|
44
44
|
type: "tone",
|
|
45
|
-
deleteMode:
|
|
45
|
+
deleteMode: h.DELETE_NODE
|
|
46
46
|
},
|
|
47
47
|
number: {
|
|
48
48
|
label: "数字读法",
|
|
@@ -68,9 +68,9 @@ const f = {
|
|
|
68
68
|
label: "忽略读音",
|
|
69
69
|
icon: "editor-ingore",
|
|
70
70
|
type: "ignore",
|
|
71
|
-
deleteMode:
|
|
71
|
+
deleteMode: h.CONVERT_TO_TEXT
|
|
72
72
|
}
|
|
73
|
-
},
|
|
73
|
+
}, j = [
|
|
74
74
|
{ label: "笑声", value: "笑声", tag: "[laughter]" },
|
|
75
75
|
{ label: "叹气", value: "叹气", tag: "[sigh]" },
|
|
76
76
|
{ label: "吸气", value: "吸气", tag: "[sniff]" },
|
|
@@ -85,21 +85,34 @@ const f = {
|
|
|
85
85
|
{ label: "惊讶(哇)", value: "惊讶(哇)", tag: "[surprise-wa]" },
|
|
86
86
|
{ label: "惊讶(哟)", value: "惊讶(哟)", tag: "[surprise-yo]" },
|
|
87
87
|
{ label: "不满", value: "不满", tag: "[dissatisfaction-hnn]" }
|
|
88
|
-
],
|
|
88
|
+
], R = [
|
|
89
89
|
{ value: "zh", label: "中文" },
|
|
90
90
|
{ value: "en", label: "英语" },
|
|
91
|
-
{ value: "
|
|
92
|
-
{ value: "
|
|
91
|
+
{ value: "ja", label: "日语" },
|
|
92
|
+
{ value: "ko", label: "韩语" },
|
|
93
93
|
{ value: "de", label: "德语" },
|
|
94
94
|
{ value: "fr", label: "法语" },
|
|
95
95
|
{ value: "es", label: "西班牙语" },
|
|
96
96
|
{ value: "it", label: "意大利语" },
|
|
97
97
|
{ value: "pt", label: "葡萄牙语" },
|
|
98
98
|
{ value: "ru", label: "俄语" }
|
|
99
|
-
],
|
|
99
|
+
], z = { jp: "ja", kr: "ko" }, _ = (t) => typeof t == "string" ? z[t] ?? t : t, G = (t) => {
|
|
100
|
+
var o, s;
|
|
101
|
+
const e = (o = t.attrs) == null ? void 0 : o.payload, n = t.type === "customTag" && ((s = t.attrs) == null ? void 0 : s.categ) === "language" && _(e == null ? void 0 : e.code) !== (e == null ? void 0 : e.code);
|
|
102
|
+
return {
|
|
103
|
+
...t,
|
|
104
|
+
...n && {
|
|
105
|
+
attrs: {
|
|
106
|
+
...t.attrs,
|
|
107
|
+
payload: { ...e, code: _(e.code) }
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
...t.content && { content: t.content.map(G) }
|
|
111
|
+
};
|
|
112
|
+
}, X = [
|
|
100
113
|
{ label: "停顿 0.5 秒", value: 0.5 },
|
|
101
114
|
{ label: "停顿 1 秒", value: 1 }
|
|
102
|
-
],
|
|
115
|
+
], Bt = {
|
|
103
116
|
SENTENCE: "sentence",
|
|
104
117
|
CUSTOM_TAG: "customTag",
|
|
105
118
|
/**
|
|
@@ -107,16 +120,16 @@ const f = {
|
|
|
107
120
|
* 工具栏与右键面板都要用它来主动收起气泡,避免两个浮层叠在一起。
|
|
108
121
|
*/
|
|
109
122
|
BUBBLE_MENU_KEY: "ttsRichTextBubbleMenu"
|
|
110
|
-
},
|
|
111
|
-
var
|
|
112
|
-
return ((
|
|
113
|
-
},
|
|
114
|
-
tools:
|
|
115
|
-
languages:
|
|
123
|
+
}, kt = (t) => {
|
|
124
|
+
var e;
|
|
125
|
+
return ((e = p[t]) == null ? void 0 : e.deleteMode) === h.DELETE_NODE;
|
|
126
|
+
}, wt = (t) => t === p.stop.type || t === p.customStop.type, Ht = (t) => t === p.customStop.type ? { time: X[0].value } : {}, Vt = (t, e) => t === p.customStop.type ? `${e == null ? void 0 : e.time} 秒` : "", M = Object.keys(p), m = {
|
|
127
|
+
tools: M.filter((t) => t !== p.tone.type),
|
|
128
|
+
languages: R,
|
|
116
129
|
maxPinyinLength: 4,
|
|
117
130
|
maxNumberLength: 16,
|
|
118
131
|
enablePreview: !0
|
|
119
|
-
},
|
|
132
|
+
}, Y = {
|
|
120
133
|
1: {
|
|
121
134
|
tools: [
|
|
122
135
|
"customStop",
|
|
@@ -129,20 +142,20 @@ const f = {
|
|
|
129
142
|
"upload",
|
|
130
143
|
"ignore"
|
|
131
144
|
],
|
|
132
|
-
languages:
|
|
145
|
+
languages: R.filter((t) => ["zh", "en"].includes(t.value))
|
|
133
146
|
},
|
|
134
|
-
2:
|
|
135
|
-
3: { tools:
|
|
136
|
-
},
|
|
137
|
-
const n =
|
|
147
|
+
2: m,
|
|
148
|
+
3: { tools: M.filter((t) => t !== p.language.type) }
|
|
149
|
+
}, Ut = (t, e = {}) => {
|
|
150
|
+
const n = Y[t] ?? m;
|
|
138
151
|
return {
|
|
139
|
-
...
|
|
152
|
+
...m,
|
|
140
153
|
...n,
|
|
141
|
-
...
|
|
142
|
-
tools:
|
|
143
|
-
languages:
|
|
154
|
+
...e,
|
|
155
|
+
tools: e.tools ?? n.tools ?? m.tools,
|
|
156
|
+
languages: e.languages ?? n.languages ?? m.languages
|
|
144
157
|
};
|
|
145
|
-
},
|
|
158
|
+
}, jt = () => ({
|
|
146
159
|
type: "doc",
|
|
147
160
|
content: [
|
|
148
161
|
{
|
|
@@ -150,13 +163,13 @@ const f = {
|
|
|
150
163
|
content: []
|
|
151
164
|
}
|
|
152
165
|
]
|
|
153
|
-
}),
|
|
154
|
-
const n = Number.isFinite(
|
|
155
|
-
return Array.from(
|
|
156
|
-
(s, a) => s + (
|
|
166
|
+
}), K = /[\u4e00-\u9fff]/, W = /\s/g, q = 0.28, J = 0.14, zt = (t, e = 1) => {
|
|
167
|
+
const n = Number.isFinite(e) && e > 0 ? e : 1;
|
|
168
|
+
return Array.from(t.replace(W, "")).reduce(
|
|
169
|
+
(s, a) => s + (K.test(a) ? q : J),
|
|
157
170
|
0
|
|
158
171
|
) / n;
|
|
159
|
-
},
|
|
172
|
+
}, O = {
|
|
160
173
|
0: "零",
|
|
161
174
|
1: "一",
|
|
162
175
|
2: "二",
|
|
@@ -167,7 +180,7 @@ const f = {
|
|
|
167
180
|
7: "七",
|
|
168
181
|
8: "八",
|
|
169
182
|
9: "九"
|
|
170
|
-
},
|
|
183
|
+
}, Z = {
|
|
171
184
|
0: "洞",
|
|
172
185
|
1: "幺",
|
|
173
186
|
2: "二",
|
|
@@ -178,49 +191,49 @@ const f = {
|
|
|
178
191
|
7: "七",
|
|
179
192
|
8: "八",
|
|
180
193
|
9: "九"
|
|
181
|
-
},
|
|
182
|
-
function
|
|
183
|
-
return
|
|
194
|
+
}, Q = ["", "十", "百", "千"], tt = ["", "万", "亿", "万亿"];
|
|
195
|
+
function et(t) {
|
|
196
|
+
return t ? t.split("").map((e) => O[e] || e).join("") : "";
|
|
184
197
|
}
|
|
185
|
-
function
|
|
186
|
-
return
|
|
198
|
+
function Gt(t) {
|
|
199
|
+
return t ? t.split("").map((e) => Z[e] || e).join("") : "";
|
|
187
200
|
}
|
|
188
|
-
function
|
|
189
|
-
const
|
|
201
|
+
function nt(t) {
|
|
202
|
+
const e = t.length;
|
|
190
203
|
let n = "", o = !1;
|
|
191
|
-
for (let s = 0; s <
|
|
192
|
-
const a =
|
|
193
|
-
a === "0" ? !o && n !== "" && (o = !0) : (o && (n += "零", o = !1), n +=
|
|
204
|
+
for (let s = 0; s < e; s++) {
|
|
205
|
+
const a = t[s], r = e - 1 - s;
|
|
206
|
+
a === "0" ? !o && n !== "" && (o = !0) : (o && (n += "零", o = !1), n += O[a] + Q[r]);
|
|
194
207
|
}
|
|
195
208
|
return n.startsWith("一十") && n.length === 2 && (n = n.substring(1)), n;
|
|
196
209
|
}
|
|
197
|
-
function
|
|
198
|
-
if (!
|
|
199
|
-
if (
|
|
200
|
-
let
|
|
201
|
-
const n =
|
|
210
|
+
function P(t) {
|
|
211
|
+
if (!t) return "";
|
|
212
|
+
if (t === "0" || (t = t.replace(/^0+/, "") || "0", t === "0")) return "零";
|
|
213
|
+
let e = "";
|
|
214
|
+
const n = t.length, o = [];
|
|
202
215
|
for (let s = n; s > 0; s -= 4) {
|
|
203
216
|
const a = Math.max(0, s - 4);
|
|
204
|
-
o.unshift(
|
|
217
|
+
o.unshift(t.substring(a, s));
|
|
205
218
|
}
|
|
206
219
|
for (let s = 0; s < o.length; s++) {
|
|
207
|
-
const a = o[s], r =
|
|
220
|
+
const a = o[s], r = nt(a);
|
|
208
221
|
if (r !== "") {
|
|
209
|
-
const
|
|
210
|
-
|
|
222
|
+
const i = o.length - 1 - s;
|
|
223
|
+
e += r + tt[i];
|
|
211
224
|
}
|
|
212
225
|
}
|
|
213
|
-
return
|
|
226
|
+
return e;
|
|
214
227
|
}
|
|
215
|
-
function
|
|
216
|
-
return
|
|
228
|
+
function ot(t) {
|
|
229
|
+
return P(t);
|
|
217
230
|
}
|
|
218
|
-
const
|
|
219
|
-
{ label: "基数读法", func:
|
|
231
|
+
const Xt = [
|
|
232
|
+
{ label: "基数读法", func: et },
|
|
220
233
|
// { label: '位数读法', func: toPhoneReading },
|
|
221
|
-
{ label: "位数读法", func:
|
|
222
|
-
{ label: "口语读法", func:
|
|
223
|
-
],
|
|
234
|
+
{ label: "位数读法", func: P },
|
|
235
|
+
{ label: "口语读法", func: ot }
|
|
236
|
+
], rt = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u00AD\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFE00-\uFE0F\uFEFF\uFFFD\uE000-\uF8FF]/g, st = /[\t\f\v\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, C = {
|
|
224
237
|
"‘": "'",
|
|
225
238
|
"’": "'",
|
|
226
239
|
"‚": "'",
|
|
@@ -252,63 +265,63 @@ const Le = [
|
|
|
252
265
|
"︔": ";",
|
|
253
266
|
"︕": "!",
|
|
254
267
|
"︖": "?"
|
|
255
|
-
},
|
|
268
|
+
}, at = new RegExp(`[${Object.keys(C).join("")}]`, "g"), it = (t) => t.replace(/[\uFF21-\uFF3A\uFF41-\uFF5A\uFF10-\uFF19]/g, (e) => String.fromCharCode(e.charCodeAt(0) - 65248)), lt = (t) => it(t).replace(/\r\n?/g, `
|
|
256
269
|
`).replace(/[\u2028\u2029]/g, `
|
|
257
|
-
`).replace(
|
|
270
|
+
`).replace(rt, "").replace(st, " ").replace(at, (e) => C[e] || "").replace(/ *\n */g, `
|
|
258
271
|
`).replace(/\n{3,}/g, `
|
|
259
272
|
|
|
260
|
-
`),
|
|
261
|
-
if (typeof window > "u" || !
|
|
262
|
-
return
|
|
263
|
-
const n = new DOMParser().parseFromString(
|
|
273
|
+
`), Yt = (t) => {
|
|
274
|
+
if (typeof window > "u" || !t)
|
|
275
|
+
return t;
|
|
276
|
+
const n = new DOMParser().parseFromString(t, "text/html"), o = n.createTreeWalker(n.body, NodeFilter.SHOW_TEXT);
|
|
264
277
|
let s = o.nextNode();
|
|
265
278
|
for (; s; )
|
|
266
|
-
s.textContent =
|
|
279
|
+
s.textContent = lt(s.textContent || ""), s = o.nextNode();
|
|
267
280
|
return n.body.innerHTML;
|
|
268
|
-
},
|
|
281
|
+
}, ct = {
|
|
269
282
|
minSegmentLength: 32,
|
|
270
283
|
maxSegmentLength: 128,
|
|
271
284
|
rebalanceRatio: 0.4
|
|
272
|
-
},
|
|
273
|
-
let
|
|
274
|
-
for (const n of
|
|
275
|
-
|
|
276
|
-
return
|
|
277
|
-
},
|
|
278
|
-
`).map((
|
|
279
|
-
let
|
|
280
|
-
for (; n !==
|
|
281
|
-
n =
|
|
282
|
-
for (n = ""; n !==
|
|
283
|
-
n =
|
|
284
|
-
return
|
|
285
|
-
},
|
|
285
|
+
}, y = /[一-鿿㐀-䶿豈- -〿-]/, ut = /[。!?!?\.]/, gt = /[;;]/, pt = /[,,、::]/, ht = /[。!?!?,,、;;::]/, A = "", v = "", d = (t) => {
|
|
286
|
+
let e = 0;
|
|
287
|
+
for (const n of t)
|
|
288
|
+
e += y.test(n) ? 2 : 1;
|
|
289
|
+
return e;
|
|
290
|
+
}, ft = (t) => t.replace(/\r/g, "").split(`
|
|
291
|
+
`).map((e) => e.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), Et = (t) => {
|
|
292
|
+
let e = t, n = "";
|
|
293
|
+
for (; n !== e; )
|
|
294
|
+
n = e, e = e.replace(/(\d),(\d)/g, `$1${A}$2`);
|
|
295
|
+
for (n = ""; n !== e; )
|
|
296
|
+
n = e, e = e.replace(/(\d)\.(\d)/g, `$1${v}$2`);
|
|
297
|
+
return e;
|
|
298
|
+
}, L = (t) => t.split(A).join(",").split(v).join("."), Tt = (t, e, n, o, s) => {
|
|
286
299
|
let a = -1, r = Number.POSITIVE_INFINITY;
|
|
287
|
-
const
|
|
288
|
-
for (let
|
|
289
|
-
if (!s.test(
|
|
300
|
+
const i = Math.max(1, n), c = Math.min(t.length, o);
|
|
301
|
+
for (let l = i; l <= c; l += 1) {
|
|
302
|
+
if (!s.test(t[l - 1]))
|
|
290
303
|
continue;
|
|
291
|
-
const u = Math.abs(
|
|
292
|
-
if (u < r && (r = u, a =
|
|
304
|
+
const u = Math.abs(l - e);
|
|
305
|
+
if (u < r && (r = u, a = l), l > e && a >= 0)
|
|
293
306
|
break;
|
|
294
307
|
}
|
|
295
308
|
return a;
|
|
296
|
-
},
|
|
309
|
+
}, dt = (t, e, n, o) => {
|
|
297
310
|
let s = -1, a = Number.POSITIVE_INFINITY;
|
|
298
|
-
const r = Math.max(1, n),
|
|
299
|
-
for (let
|
|
300
|
-
if (
|
|
311
|
+
const r = Math.max(1, n), i = Math.min(t.length, o);
|
|
312
|
+
for (let c = r; c <= i; c += 1) {
|
|
313
|
+
if (t[c - 1] !== " ")
|
|
301
314
|
continue;
|
|
302
|
-
const
|
|
303
|
-
if (
|
|
315
|
+
const l = Math.abs(c - e);
|
|
316
|
+
if (l < a && (a = l, s = c), c > e && s >= 0)
|
|
304
317
|
break;
|
|
305
318
|
}
|
|
306
319
|
return s;
|
|
307
|
-
},
|
|
320
|
+
}, F = (t, e, n, o, s) => {
|
|
308
321
|
for (const a of s) {
|
|
309
|
-
const r =
|
|
310
|
-
e,
|
|
322
|
+
const r = Tt(
|
|
311
323
|
t,
|
|
324
|
+
e,
|
|
312
325
|
n,
|
|
313
326
|
o,
|
|
314
327
|
a
|
|
@@ -316,262 +329,382 @@ const Le = [
|
|
|
316
329
|
if (r >= 0)
|
|
317
330
|
return r;
|
|
318
331
|
}
|
|
319
|
-
return
|
|
320
|
-
},
|
|
332
|
+
return dt(t, e, n, o);
|
|
333
|
+
}, mt = (t, e) => {
|
|
321
334
|
const n = [];
|
|
322
|
-
let o =
|
|
323
|
-
for (; o &&
|
|
324
|
-
const s =
|
|
325
|
-
let r = 0,
|
|
326
|
-
for (let
|
|
327
|
-
if (
|
|
328
|
-
|
|
335
|
+
let o = t;
|
|
336
|
+
for (; o && d(o) > e; ) {
|
|
337
|
+
const s = d(o), a = Math.floor(s / 2);
|
|
338
|
+
let r = 0, i = 0, c = 0;
|
|
339
|
+
for (let g = 0; g < o.length; g += 1)
|
|
340
|
+
if (c += y.test(o[g]) ? 2 : 1, !r && c >= a && (r = g + 1), c >= e) {
|
|
341
|
+
i = g + 1;
|
|
329
342
|
break;
|
|
330
343
|
}
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
let u =
|
|
334
|
-
|
|
335
|
-
|
|
344
|
+
i || (i = o.length), r || (r = Math.floor(o.length / 2));
|
|
345
|
+
const l = Math.max(1, Math.floor(r / 3));
|
|
346
|
+
let u = F(o, r, l, i, [
|
|
347
|
+
gt,
|
|
348
|
+
pt
|
|
336
349
|
]);
|
|
337
350
|
(u < 0 || u >= o.length) && (u = r), n.push(o.slice(0, u)), o = o.slice(u);
|
|
338
351
|
}
|
|
339
352
|
return o.trim() && n.push(o), n;
|
|
340
|
-
},
|
|
341
|
-
if (
|
|
342
|
-
return
|
|
343
|
-
const n =
|
|
353
|
+
}, bt = (t, e) => {
|
|
354
|
+
if (t.length <= 1)
|
|
355
|
+
return t;
|
|
356
|
+
const n = t[t.length - 1], o = t.reduce((g, E) => g + E.length, 0) / t.length, s = Math.floor(o * e);
|
|
344
357
|
if (n.length >= s)
|
|
345
|
-
return
|
|
346
|
-
const r = `${
|
|
347
|
-
|
|
358
|
+
return t;
|
|
359
|
+
const r = `${t[t.length - 2]}${n}`, i = Math.floor(r.length / 2), c = Math.max(1, Math.floor(i / 3)), l = F(r, i, c, r.length, [
|
|
360
|
+
ht
|
|
348
361
|
]);
|
|
349
|
-
if (
|
|
350
|
-
return
|
|
351
|
-
const u = [...
|
|
352
|
-
return u[u.length - 2] = r.slice(0,
|
|
353
|
-
},
|
|
362
|
+
if (l <= 0 || l >= r.length)
|
|
363
|
+
return t;
|
|
364
|
+
const u = [...t];
|
|
365
|
+
return u[u.length - 2] = r.slice(0, l), u[u.length - 1] = r.slice(l), u.filter(Boolean);
|
|
366
|
+
}, _t = (t, e = {}) => {
|
|
354
367
|
const n = {
|
|
355
|
-
...
|
|
356
|
-
...
|
|
357
|
-
}, o =
|
|
368
|
+
...ct,
|
|
369
|
+
...e
|
|
370
|
+
}, o = ft(t);
|
|
358
371
|
if (!o)
|
|
359
372
|
return [];
|
|
360
|
-
const s =
|
|
361
|
-
if (
|
|
362
|
-
return [
|
|
373
|
+
const s = Et(o);
|
|
374
|
+
if (d(s) <= n.minSegmentLength)
|
|
375
|
+
return [L(s)];
|
|
363
376
|
const a = [], r = s.split(new RegExp("(?<=[。!?!?\\.])"));
|
|
364
|
-
let
|
|
365
|
-
for (const
|
|
366
|
-
if (!
|
|
377
|
+
let i = "";
|
|
378
|
+
for (const l of r) {
|
|
379
|
+
if (!l)
|
|
367
380
|
continue;
|
|
368
|
-
|
|
369
|
-
const u =
|
|
370
|
-
|
|
381
|
+
i += l;
|
|
382
|
+
const u = i[i.length - 1] ?? "";
|
|
383
|
+
d(i) >= n.minSegmentLength && ut.test(u) && (a.push(i), i = "");
|
|
371
384
|
}
|
|
372
|
-
|
|
373
|
-
const
|
|
374
|
-
return
|
|
375
|
-
|
|
385
|
+
i && (a.length > 0 && d(i) < n.minSegmentLength ? a[a.length - 1] += i : a.push(i));
|
|
386
|
+
const c = a.flatMap((l) => d(l) <= n.maxSegmentLength ? [l] : mt(l, n.maxSegmentLength));
|
|
387
|
+
return bt(c, n.rebalanceRatio).map(
|
|
388
|
+
L
|
|
376
389
|
);
|
|
377
|
-
},
|
|
378
|
-
|
|
390
|
+
}, T = {
|
|
391
|
+
minSegmentLength: 32,
|
|
392
|
+
maxSegmentLength: 64,
|
|
393
|
+
rebalanceRatio: 0.4
|
|
394
|
+
}, $ = /[一-鿿㐀-䶿豈- -〿-]/, D = /[。!?!?\.]/, B = /[;;]/, k = /[,,::]/, Nt = /[、]/, w = "", H = "", f = (t) => {
|
|
395
|
+
let e = 0;
|
|
396
|
+
for (const n of t)
|
|
397
|
+
e += $.test(n) ? 2 : 1;
|
|
398
|
+
return e;
|
|
399
|
+
}, Lt = (t) => t.replace(/\r/g, "").split(`
|
|
400
|
+
`).map((e) => e.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), It = (t) => {
|
|
401
|
+
let e = t, n = "";
|
|
402
|
+
for (; n !== e; )
|
|
403
|
+
n = e, e = e.replace(/(\d),(\d)/g, `$1${w}$2`);
|
|
404
|
+
for (n = ""; n !== e; )
|
|
405
|
+
n = e, e = e.replace(/(\d)\.(\d)/g, `$1${H}$2`);
|
|
406
|
+
return e;
|
|
407
|
+
}, I = (t) => t.split(w).join(",").split(H).join("."), N = (t, e) => {
|
|
408
|
+
let n = 0;
|
|
409
|
+
for (let o = 0; o < t.length; o += 1)
|
|
410
|
+
if (n += $.test(t[o]) ? 2 : 1, n >= e)
|
|
411
|
+
return o + 1;
|
|
412
|
+
return t.length;
|
|
413
|
+
}, S = (t, e, n, o, s) => {
|
|
414
|
+
let a = -1, r = Number.POSITIVE_INFINITY;
|
|
415
|
+
const i = Math.max(1, n), c = Math.min(t.length - 1, o);
|
|
416
|
+
for (let l = i; l <= c; l += 1) {
|
|
417
|
+
if (!s.test(t[l - 1]))
|
|
418
|
+
continue;
|
|
419
|
+
const u = Math.abs(l - e);
|
|
420
|
+
if (u < r && (r = u, a = l), l > e && a >= 0)
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
return a;
|
|
424
|
+
}, St = (t, e, n, o) => {
|
|
425
|
+
let s = -1, a = Number.POSITIVE_INFINITY;
|
|
426
|
+
const r = Math.max(1, n), i = Math.min(t.length - 1, o);
|
|
427
|
+
for (let c = r; c <= i; c += 1) {
|
|
428
|
+
if (t[c - 1] !== " ")
|
|
429
|
+
continue;
|
|
430
|
+
const l = Math.abs(c - e);
|
|
431
|
+
if (l < a && (a = l, s = c), c > e && s >= 0)
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
return s;
|
|
435
|
+
}, V = (t, e, n, o, s) => {
|
|
436
|
+
for (const r of s) {
|
|
437
|
+
const i = S(
|
|
438
|
+
t,
|
|
439
|
+
e,
|
|
440
|
+
n,
|
|
441
|
+
o,
|
|
442
|
+
r
|
|
443
|
+
);
|
|
444
|
+
if (i >= 0)
|
|
445
|
+
return i;
|
|
446
|
+
}
|
|
447
|
+
const a = St(t, e, n, o);
|
|
448
|
+
return a >= 0 ? a : S(
|
|
449
|
+
t,
|
|
450
|
+
e,
|
|
451
|
+
n,
|
|
452
|
+
o,
|
|
453
|
+
Nt
|
|
454
|
+
);
|
|
455
|
+
}, xt = (t, e) => {
|
|
456
|
+
const n = [];
|
|
457
|
+
let o = t.trim();
|
|
458
|
+
for (; o && f(o) > e; ) {
|
|
459
|
+
const s = f(o), a = Math.min(Math.floor(s / 2), e), r = N(o, a), i = Math.max(1, Math.floor(r / 3)), c = Math.max(
|
|
460
|
+
r + 1,
|
|
461
|
+
N(o, e)
|
|
462
|
+
);
|
|
463
|
+
let l = V(o, r, i, c, [
|
|
464
|
+
B,
|
|
465
|
+
k
|
|
466
|
+
]);
|
|
467
|
+
(l < 0 || l >= o.length) && (l = r), n.push(o.slice(0, l).trim()), o = o.slice(l).trim();
|
|
468
|
+
}
|
|
469
|
+
return o && n.push(o), n;
|
|
470
|
+
}, Rt = (t, e) => {
|
|
471
|
+
if (t.length <= 1)
|
|
472
|
+
return t;
|
|
473
|
+
const n = t[t.length - 1], o = t.reduce((E, b) => E + f(b), 0) / t.length, s = Math.floor(o * e);
|
|
474
|
+
if (f(n) >= s)
|
|
475
|
+
return t;
|
|
476
|
+
const r = `${t[t.length - 2]}${n}`, i = Math.floor(f(r) / 2), c = N(r, i), l = Math.max(1, Math.floor(c / 3));
|
|
477
|
+
let u = V(r, c, l, r.length, [
|
|
478
|
+
D,
|
|
479
|
+
B,
|
|
480
|
+
k
|
|
481
|
+
]);
|
|
482
|
+
if (u <= 0 || u >= r.length)
|
|
483
|
+
return t;
|
|
484
|
+
const g = [...t];
|
|
485
|
+
return g[g.length - 2] = r.slice(0, u).trim(), g[g.length - 1] = r.slice(u).trim(), g.filter(Boolean);
|
|
486
|
+
}, Mt = (t) => {
|
|
487
|
+
const e = Lt(t);
|
|
488
|
+
if (!e)
|
|
489
|
+
return [];
|
|
490
|
+
const n = It(e);
|
|
491
|
+
if (f(n) <= T.minSegmentLength)
|
|
492
|
+
return [I(n)];
|
|
493
|
+
const o = [], s = n.split(new RegExp("(?<=[。!?!?\\.])"));
|
|
494
|
+
let a = "";
|
|
495
|
+
for (const i of s) {
|
|
496
|
+
if (!i)
|
|
497
|
+
continue;
|
|
498
|
+
a += i;
|
|
499
|
+
const c = a[a.length - 1] ?? "";
|
|
500
|
+
f(a) >= T.minSegmentLength && D.test(c) && (o.push(a.trim()), a = "");
|
|
501
|
+
}
|
|
502
|
+
a && (o.length > 0 && f(a) < T.minSegmentLength ? o[o.length - 1] += a : o.push(a.trim()));
|
|
503
|
+
const r = o.flatMap((i) => f(i) <= T.maxSegmentLength ? [i] : xt(i, T.maxSegmentLength));
|
|
504
|
+
return Rt(
|
|
505
|
+
r,
|
|
506
|
+
T.rebalanceRatio
|
|
507
|
+
).map(I);
|
|
508
|
+
}, Ot = (t, e = {}) => e.strategy === "legacy" ? Mt(t) : _t(t, e), U = (t) => t.type === "text" ? t.text || "" : (t.content || []).map(U).join(""), Pt = (t) => {
|
|
509
|
+
const e = t.content || [];
|
|
379
510
|
let n = "";
|
|
380
511
|
const o = [], s = [], a = {
|
|
381
|
-
[
|
|
512
|
+
[p.stop.type]: ({ position: r, actionCode: i }) => {
|
|
382
513
|
o.push({
|
|
383
514
|
action: "insert",
|
|
384
515
|
model: "control",
|
|
385
516
|
payload: "。 ",
|
|
386
517
|
position: r,
|
|
387
518
|
text: "",
|
|
388
|
-
actionCode:
|
|
519
|
+
actionCode: i
|
|
389
520
|
});
|
|
390
521
|
},
|
|
391
|
-
[
|
|
522
|
+
[p.customStop.type]: ({ payload: r, position: i, actionCode: c }) => {
|
|
392
523
|
o.push({
|
|
393
524
|
action: "insert",
|
|
394
525
|
model: "control",
|
|
395
526
|
payload: `[stop:${r == null ? void 0 : r.time}]`,
|
|
396
|
-
position:
|
|
527
|
+
position: i,
|
|
397
528
|
text: "",
|
|
398
|
-
actionCode:
|
|
529
|
+
actionCode: c
|
|
399
530
|
});
|
|
400
531
|
},
|
|
401
|
-
[
|
|
532
|
+
[p.continue.type]: ({ position: r, text: i, actionCode: c }) => {
|
|
402
533
|
o.push({
|
|
403
534
|
action: "replace",
|
|
404
535
|
model: "replace",
|
|
405
|
-
payload: `《${
|
|
536
|
+
payload: `《${i}》`,
|
|
406
537
|
position: r,
|
|
407
|
-
text:
|
|
408
|
-
actionCode:
|
|
538
|
+
text: i,
|
|
539
|
+
actionCode: c
|
|
409
540
|
});
|
|
410
541
|
},
|
|
411
|
-
[
|
|
542
|
+
[p.replace.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
|
|
412
543
|
o.push({
|
|
413
544
|
action: "replace",
|
|
414
545
|
model: "replace",
|
|
415
546
|
payload: `${r == null ? void 0 : r.text}`,
|
|
416
|
-
position:
|
|
417
|
-
text:
|
|
418
|
-
actionCode:
|
|
547
|
+
position: i,
|
|
548
|
+
text: c,
|
|
549
|
+
actionCode: l
|
|
419
550
|
});
|
|
420
551
|
},
|
|
421
|
-
[
|
|
552
|
+
[p.pinyin.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
|
|
422
553
|
o.push({
|
|
423
554
|
action: "replace",
|
|
424
555
|
model: "pinyin",
|
|
425
556
|
payload: `${r == null ? void 0 : r.text}`,
|
|
426
|
-
position:
|
|
427
|
-
text:
|
|
428
|
-
actionCode:
|
|
557
|
+
position: i,
|
|
558
|
+
text: c,
|
|
559
|
+
actionCode: l
|
|
429
560
|
});
|
|
430
561
|
},
|
|
431
|
-
[
|
|
562
|
+
[p.language.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
|
|
432
563
|
o.push({
|
|
433
564
|
action: "language",
|
|
434
565
|
model: "language",
|
|
435
|
-
payload: `${r == null ? void 0 : r.code}`,
|
|
436
|
-
position:
|
|
437
|
-
text:
|
|
438
|
-
actionCode:
|
|
566
|
+
payload: `${_(r == null ? void 0 : r.code)}`,
|
|
567
|
+
position: i,
|
|
568
|
+
text: c,
|
|
569
|
+
actionCode: l
|
|
439
570
|
});
|
|
440
571
|
},
|
|
441
|
-
[
|
|
572
|
+
[p.tone.type]: ({ payload: r, position: i, actionCode: c }) => {
|
|
442
573
|
var u;
|
|
443
|
-
const
|
|
444
|
-
|
|
574
|
+
const l = (u = j.find((g) => g.value === (r == null ? void 0 : r.code))) == null ? void 0 : u.tag;
|
|
575
|
+
l && o.push({
|
|
445
576
|
action: "insert",
|
|
446
577
|
model: "control",
|
|
447
|
-
payload:
|
|
448
|
-
position:
|
|
578
|
+
payload: l,
|
|
579
|
+
position: i,
|
|
449
580
|
text: "",
|
|
450
|
-
actionCode:
|
|
581
|
+
actionCode: c
|
|
451
582
|
});
|
|
452
583
|
},
|
|
453
|
-
[
|
|
584
|
+
[p.ignore.type]: ({ position: r, text: i, actionCode: c }) => {
|
|
454
585
|
o.push({
|
|
455
586
|
action: "replace",
|
|
456
587
|
model: "replace",
|
|
457
588
|
payload: " ",
|
|
458
589
|
position: r,
|
|
459
|
-
text:
|
|
460
|
-
actionCode:
|
|
590
|
+
text: i,
|
|
591
|
+
actionCode: c
|
|
461
592
|
});
|
|
462
593
|
}
|
|
463
594
|
};
|
|
464
|
-
return
|
|
465
|
-
var
|
|
595
|
+
return e.forEach((r) => {
|
|
596
|
+
var E, b;
|
|
466
597
|
if (r.type === "text") {
|
|
467
598
|
n += r.text || "";
|
|
468
599
|
return;
|
|
469
600
|
}
|
|
470
601
|
if (r.type !== "customTag") return;
|
|
471
|
-
const
|
|
602
|
+
const i = (E = r.attrs) == null ? void 0 : E.categ, c = (b = r.attrs) == null ? void 0 : b.payload, l = n.length, u = U(r), g = a[i];
|
|
472
603
|
u && s.push({
|
|
473
|
-
start:
|
|
474
|
-
end:
|
|
475
|
-
}),
|
|
476
|
-
payload:
|
|
477
|
-
position:
|
|
604
|
+
start: l,
|
|
605
|
+
end: l + u.length
|
|
606
|
+
}), g && g({
|
|
607
|
+
payload: c,
|
|
608
|
+
position: l,
|
|
478
609
|
text: u,
|
|
479
|
-
actionCode:
|
|
610
|
+
actionCode: i
|
|
480
611
|
}), n += u;
|
|
481
612
|
}), {
|
|
482
613
|
text: n,
|
|
483
614
|
protectedRanges: s,
|
|
484
615
|
playments: o
|
|
485
616
|
};
|
|
486
|
-
},
|
|
487
|
-
const
|
|
488
|
-
if (
|
|
489
|
-
if (
|
|
490
|
-
return
|
|
491
|
-
const n =
|
|
492
|
-
return n.length ? n :
|
|
617
|
+
}, x = (t) => t.type === "text" || t.type === "customTag", Ct = (t) => {
|
|
618
|
+
const e = t.content || [];
|
|
619
|
+
if (t.type === "paragraph") return [t];
|
|
620
|
+
if (t.type === "doc")
|
|
621
|
+
return e.filter((o) => o.type === "paragraph");
|
|
622
|
+
const n = e.filter((o) => o.type === "paragraph");
|
|
623
|
+
return n.length ? n : e.some(x) ? [
|
|
493
624
|
{
|
|
494
625
|
type: "paragraph",
|
|
495
|
-
content:
|
|
626
|
+
content: e.filter(x)
|
|
496
627
|
}
|
|
497
628
|
] : [];
|
|
498
|
-
},
|
|
629
|
+
}, yt = (t, e) => {
|
|
499
630
|
let n = 0;
|
|
500
|
-
return
|
|
501
|
-
const s =
|
|
631
|
+
return e.map((o) => {
|
|
632
|
+
const s = t.indexOf(o, n), a = s >= 0 ? s : n, r = a + o.length;
|
|
502
633
|
return n = r, {
|
|
503
634
|
text: o,
|
|
504
635
|
start: a,
|
|
505
636
|
end: r
|
|
506
637
|
};
|
|
507
638
|
});
|
|
508
|
-
},
|
|
509
|
-
if (
|
|
639
|
+
}, At = (t, e) => t.reduce((n, o) => {
|
|
640
|
+
if (e.some(
|
|
510
641
|
(a) => o.start > a.start && o.start < a.end
|
|
511
642
|
) && n.length) {
|
|
512
643
|
const a = n[n.length - 1];
|
|
513
644
|
return a.text += o.text, a.end = o.end, n;
|
|
514
645
|
}
|
|
515
646
|
return n.push({ ...o }), n;
|
|
516
|
-
}, []),
|
|
517
|
-
const n =
|
|
518
|
-
if (n.length <= 1) return [
|
|
519
|
-
const o =
|
|
520
|
-
|
|
521
|
-
|
|
647
|
+
}, []), vt = (t, e, n, o) => t.position >= e && t.position < n ? !0 : !t.text && o && t.position === n, Ft = (t, e) => {
|
|
648
|
+
const n = Ot(t.text, e);
|
|
649
|
+
if (n.length <= 1) return [t];
|
|
650
|
+
const o = At(
|
|
651
|
+
yt(t.text, n),
|
|
652
|
+
t.protectedRanges || []
|
|
522
653
|
);
|
|
523
654
|
return o.map((s, a) => {
|
|
524
|
-
const r = a === o.length - 1,
|
|
525
|
-
(
|
|
526
|
-
).map((
|
|
527
|
-
...
|
|
528
|
-
position:
|
|
655
|
+
const r = a === o.length - 1, i = t.playments.filter(
|
|
656
|
+
(c) => vt(c, s.start, s.end, r)
|
|
657
|
+
).map((c) => ({
|
|
658
|
+
...c,
|
|
659
|
+
position: c.position - s.start
|
|
529
660
|
}));
|
|
530
661
|
return {
|
|
531
662
|
text: s.text,
|
|
532
|
-
playments:
|
|
663
|
+
playments: i
|
|
533
664
|
};
|
|
534
665
|
});
|
|
535
|
-
},
|
|
666
|
+
}, Kt = (t, e = {}) => {
|
|
536
667
|
const n = {
|
|
537
668
|
playments: [],
|
|
538
669
|
sentences: []
|
|
539
670
|
};
|
|
540
|
-
return
|
|
541
|
-
const a =
|
|
542
|
-
!a.text && !a.playments.length ||
|
|
543
|
-
({ text: r, playments:
|
|
544
|
-
n.sentences.push(r), n.playments.push(
|
|
671
|
+
return Ct(t).forEach((s) => {
|
|
672
|
+
const a = Pt(s);
|
|
673
|
+
!a.text && !a.playments.length || Ft(a, e).forEach(
|
|
674
|
+
({ text: r, playments: i }) => {
|
|
675
|
+
n.sentences.push(r), n.playments.push(i);
|
|
545
676
|
}
|
|
546
677
|
);
|
|
547
678
|
}), n;
|
|
548
679
|
};
|
|
549
680
|
export {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
681
|
+
h as DeleteMode,
|
|
682
|
+
Bt as EditorConst,
|
|
683
|
+
R as LanguageOptions,
|
|
684
|
+
Dt as MAX_LANGUAGE_SELECTION_LENGTH,
|
|
685
|
+
$t as MAX_REPLACEMENT_TEXT_LENGTH,
|
|
686
|
+
Xt as NumberToTextTools,
|
|
687
|
+
X as StopOptions,
|
|
688
|
+
j as ToneOptions,
|
|
689
|
+
p as ToolConfig,
|
|
690
|
+
M as allToolTypes,
|
|
691
|
+
Kt as convertToTtsFormat,
|
|
692
|
+
zt as estimateTtsDuration,
|
|
693
|
+
Ht as getDefaultLockPayload,
|
|
694
|
+
jt as getInitContent,
|
|
695
|
+
Vt as getLockPayloadLabel,
|
|
696
|
+
d as getVisualLength,
|
|
697
|
+
kt as isInsertTagType,
|
|
698
|
+
wt as isLockableTagType,
|
|
699
|
+
_ as normalizeLanguageCode,
|
|
700
|
+
G as normalizeTtsContent,
|
|
701
|
+
Ut as resolveTtsEditorFeatures,
|
|
702
|
+
Yt as sanitizePastedHtml,
|
|
703
|
+
lt as sanitizePastedText,
|
|
704
|
+
Ot as splitTextToSentences,
|
|
705
|
+
et as toCardinal,
|
|
706
|
+
ot as toColloquial,
|
|
707
|
+
Gt as toPhoneReading,
|
|
708
|
+
P as toPositional,
|
|
709
|
+
Pt as transformParagraph
|
|
577
710
|
};
|