@naersen/tts-rich-text 0.12.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 +14 -0
- package/dist/core/config.d.ts +3 -0
- package/dist/core.js +310 -295
- package/dist/index.js +1495 -1493
- package/package.json +87 -89
package/dist/core.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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",
|
|
@@ -70,7 +70,7 @@ const h = {
|
|
|
70
70
|
type: "ignore",
|
|
71
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 h = {
|
|
|
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 h = {
|
|
|
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 h = {
|
|
|
129
142
|
"upload",
|
|
130
143
|
"ignore"
|
|
131
144
|
],
|
|
132
|
-
languages:
|
|
145
|
+
languages: R.filter((t) => ["zh", "en"].includes(t.value))
|
|
133
146
|
},
|
|
134
147
|
2: m,
|
|
135
|
-
3: { tools:
|
|
136
|
-
},
|
|
137
|
-
const n =
|
|
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 h = {
|
|
|
150
163
|
content: []
|
|
151
164
|
}
|
|
152
165
|
]
|
|
153
|
-
}),
|
|
154
|
-
const n = Number.isFinite(
|
|
155
|
-
return Array.from(
|
|
156
|
-
(
|
|
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 h = {
|
|
|
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 h = {
|
|
|
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
|
|
192
|
-
const
|
|
193
|
-
|
|
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 =
|
|
202
|
-
for (let
|
|
203
|
-
const
|
|
204
|
-
o.unshift(
|
|
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 = [];
|
|
215
|
+
for (let s = n; s > 0; s -= 4) {
|
|
216
|
+
const a = Math.max(0, s - 4);
|
|
217
|
+
o.unshift(t.substring(a, s));
|
|
205
218
|
}
|
|
206
|
-
for (let
|
|
207
|
-
const
|
|
219
|
+
for (let s = 0; s < o.length; s++) {
|
|
220
|
+
const a = o[s], r = nt(a);
|
|
208
221
|
if (r !== "") {
|
|
209
|
-
const i = o.length - 1 -
|
|
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,178 +265,178 @@ const je = [
|
|
|
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(
|
|
264
|
-
let
|
|
265
|
-
for (;
|
|
266
|
-
|
|
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);
|
|
277
|
+
let s = o.nextNode();
|
|
278
|
+
for (; s; )
|
|
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
|
-
},
|
|
286
|
-
let
|
|
287
|
-
const i = Math.max(1, n), c = Math.min(
|
|
288
|
-
for (let
|
|
289
|
-
if (!
|
|
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) => {
|
|
299
|
+
let a = -1, r = Number.POSITIVE_INFINITY;
|
|
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,
|
|
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
|
-
return
|
|
296
|
-
},
|
|
297
|
-
let
|
|
298
|
-
const r = Math.max(1, n), i = Math.min(
|
|
308
|
+
return a;
|
|
309
|
+
}, dt = (t, e, n, o) => {
|
|
310
|
+
let s = -1, a = Number.POSITIVE_INFINITY;
|
|
311
|
+
const r = Math.max(1, n), i = Math.min(t.length, o);
|
|
299
312
|
for (let c = r; c <= i; c += 1) {
|
|
300
|
-
if (
|
|
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
|
-
return
|
|
307
|
-
},
|
|
308
|
-
for (const
|
|
309
|
-
const r =
|
|
310
|
-
e,
|
|
319
|
+
return s;
|
|
320
|
+
}, F = (t, e, n, o, s) => {
|
|
321
|
+
for (const a of s) {
|
|
322
|
+
const r = Tt(
|
|
311
323
|
t,
|
|
324
|
+
e,
|
|
312
325
|
n,
|
|
313
326
|
o,
|
|
314
|
-
|
|
327
|
+
a
|
|
315
328
|
);
|
|
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
|
|
335
|
+
let o = t;
|
|
336
|
+
for (; o && d(o) > e; ) {
|
|
337
|
+
const s = d(o), a = Math.floor(s / 2);
|
|
325
338
|
let r = 0, i = 0, c = 0;
|
|
326
339
|
for (let g = 0; g < o.length; g += 1)
|
|
327
|
-
if (c +=
|
|
340
|
+
if (c += y.test(o[g]) ? 2 : 1, !r && c >= a && (r = g + 1), c >= e) {
|
|
328
341
|
i = g + 1;
|
|
329
342
|
break;
|
|
330
343
|
}
|
|
331
344
|
i || (i = o.length), r || (r = Math.floor(o.length / 2));
|
|
332
|
-
const
|
|
333
|
-
let u =
|
|
334
|
-
|
|
335
|
-
|
|
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 =
|
|
344
|
-
if (n.length >=
|
|
345
|
-
return
|
|
346
|
-
const r = `${
|
|
347
|
-
|
|
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);
|
|
357
|
+
if (n.length >= s)
|
|
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
|
|
361
|
-
if (
|
|
362
|
-
return [
|
|
363
|
-
const
|
|
373
|
+
const s = Et(o);
|
|
374
|
+
if (d(s) <= n.minSegmentLength)
|
|
375
|
+
return [L(s)];
|
|
376
|
+
const a = [], r = s.split(new RegExp("(?<=[。!?!?\\.])"));
|
|
364
377
|
let i = "";
|
|
365
|
-
for (const
|
|
366
|
-
if (!
|
|
378
|
+
for (const l of r) {
|
|
379
|
+
if (!l)
|
|
367
380
|
continue;
|
|
368
|
-
i +=
|
|
381
|
+
i += l;
|
|
369
382
|
const u = i[i.length - 1] ?? "";
|
|
370
|
-
|
|
383
|
+
d(i) >= n.minSegmentLength && ut.test(u) && (a.push(i), i = "");
|
|
371
384
|
}
|
|
372
|
-
i && (
|
|
373
|
-
const c =
|
|
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
|
-
},
|
|
390
|
+
}, T = {
|
|
378
391
|
minSegmentLength: 32,
|
|
379
392
|
maxSegmentLength: 64,
|
|
380
393
|
rebalanceRatio: 0.4
|
|
381
|
-
},
|
|
382
|
-
let
|
|
383
|
-
for (const n of
|
|
384
|
-
|
|
385
|
-
return
|
|
386
|
-
},
|
|
387
|
-
`).map((
|
|
388
|
-
let
|
|
389
|
-
for (; n !==
|
|
390
|
-
n =
|
|
391
|
-
for (n = ""; n !==
|
|
392
|
-
n =
|
|
393
|
-
return
|
|
394
|
-
},
|
|
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) => {
|
|
395
408
|
let n = 0;
|
|
396
|
-
for (let o = 0; o <
|
|
397
|
-
if (n +=
|
|
409
|
+
for (let o = 0; o < t.length; o += 1)
|
|
410
|
+
if (n += $.test(t[o]) ? 2 : 1, n >= e)
|
|
398
411
|
return o + 1;
|
|
399
|
-
return
|
|
400
|
-
},
|
|
401
|
-
let
|
|
402
|
-
const i = Math.max(1, n), c = Math.min(
|
|
403
|
-
for (let
|
|
404
|
-
if (!
|
|
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]))
|
|
405
418
|
continue;
|
|
406
|
-
const u = Math.abs(
|
|
407
|
-
if (u < r && (r = u,
|
|
419
|
+
const u = Math.abs(l - e);
|
|
420
|
+
if (u < r && (r = u, a = l), l > e && a >= 0)
|
|
408
421
|
break;
|
|
409
422
|
}
|
|
410
|
-
return
|
|
411
|
-
},
|
|
412
|
-
let
|
|
413
|
-
const r = Math.max(1, n), i = Math.min(
|
|
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);
|
|
414
427
|
for (let c = r; c <= i; c += 1) {
|
|
415
|
-
if (
|
|
428
|
+
if (t[c - 1] !== " ")
|
|
416
429
|
continue;
|
|
417
|
-
const
|
|
418
|
-
if (
|
|
430
|
+
const l = Math.abs(c - e);
|
|
431
|
+
if (l < a && (a = l, s = c), c > e && s >= 0)
|
|
419
432
|
break;
|
|
420
433
|
}
|
|
421
|
-
return
|
|
422
|
-
}, V = (
|
|
423
|
-
for (const r of
|
|
424
|
-
const i =
|
|
425
|
-
e,
|
|
434
|
+
return s;
|
|
435
|
+
}, V = (t, e, n, o, s) => {
|
|
436
|
+
for (const r of s) {
|
|
437
|
+
const i = S(
|
|
426
438
|
t,
|
|
439
|
+
e,
|
|
427
440
|
n,
|
|
428
441
|
o,
|
|
429
442
|
r
|
|
@@ -431,71 +444,71 @@ const je = [
|
|
|
431
444
|
if (i >= 0)
|
|
432
445
|
return i;
|
|
433
446
|
}
|
|
434
|
-
const
|
|
435
|
-
return
|
|
436
|
-
e,
|
|
447
|
+
const a = St(t, e, n, o);
|
|
448
|
+
return a >= 0 ? a : S(
|
|
437
449
|
t,
|
|
450
|
+
e,
|
|
438
451
|
n,
|
|
439
452
|
o,
|
|
440
|
-
|
|
453
|
+
Nt
|
|
441
454
|
);
|
|
442
|
-
},
|
|
455
|
+
}, xt = (t, e) => {
|
|
443
456
|
const n = [];
|
|
444
|
-
let o =
|
|
445
|
-
for (; o && f(o) >
|
|
446
|
-
const
|
|
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(
|
|
447
460
|
r + 1,
|
|
448
|
-
|
|
461
|
+
N(o, e)
|
|
449
462
|
);
|
|
450
|
-
let
|
|
451
|
-
|
|
452
|
-
|
|
463
|
+
let l = V(o, r, i, c, [
|
|
464
|
+
B,
|
|
465
|
+
k
|
|
453
466
|
]);
|
|
454
|
-
(
|
|
467
|
+
(l < 0 || l >= o.length) && (l = r), n.push(o.slice(0, l).trim()), o = o.slice(l).trim();
|
|
455
468
|
}
|
|
456
469
|
return o && n.push(o), n;
|
|
457
|
-
},
|
|
458
|
-
if (
|
|
459
|
-
return
|
|
460
|
-
const n =
|
|
461
|
-
if (f(n) >=
|
|
462
|
-
return
|
|
463
|
-
const r = `${
|
|
464
|
-
let u = V(r, c,
|
|
465
|
-
$,
|
|
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, [
|
|
466
478
|
D,
|
|
467
|
-
B
|
|
479
|
+
B,
|
|
480
|
+
k
|
|
468
481
|
]);
|
|
469
482
|
if (u <= 0 || u >= r.length)
|
|
470
|
-
return
|
|
471
|
-
const g = [...
|
|
483
|
+
return t;
|
|
484
|
+
const g = [...t];
|
|
472
485
|
return g[g.length - 2] = r.slice(0, u).trim(), g[g.length - 1] = r.slice(u).trim(), g.filter(Boolean);
|
|
473
|
-
},
|
|
474
|
-
const
|
|
475
|
-
if (!
|
|
486
|
+
}, Mt = (t) => {
|
|
487
|
+
const e = Lt(t);
|
|
488
|
+
if (!e)
|
|
476
489
|
return [];
|
|
477
|
-
const n =
|
|
478
|
-
if (f(n) <=
|
|
479
|
-
return [
|
|
480
|
-
const o = [],
|
|
481
|
-
let
|
|
482
|
-
for (const i of
|
|
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) {
|
|
483
496
|
if (!i)
|
|
484
497
|
continue;
|
|
485
|
-
|
|
486
|
-
const c =
|
|
487
|
-
f(
|
|
498
|
+
a += i;
|
|
499
|
+
const c = a[a.length - 1] ?? "";
|
|
500
|
+
f(a) >= T.minSegmentLength && D.test(c) && (o.push(a.trim()), a = "");
|
|
488
501
|
}
|
|
489
|
-
|
|
490
|
-
const r = o.flatMap((i) => f(i) <=
|
|
491
|
-
return
|
|
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(
|
|
492
505
|
r,
|
|
493
|
-
|
|
494
|
-
).map(
|
|
495
|
-
},
|
|
496
|
-
const
|
|
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 || [];
|
|
497
510
|
let n = "";
|
|
498
|
-
const o = [],
|
|
511
|
+
const o = [], s = [], a = {
|
|
499
512
|
[p.stop.type]: ({ position: r, actionCode: i }) => {
|
|
500
513
|
o.push({
|
|
501
514
|
action: "insert",
|
|
@@ -526,43 +539,43 @@ const je = [
|
|
|
526
539
|
actionCode: c
|
|
527
540
|
});
|
|
528
541
|
},
|
|
529
|
-
[p.replace.type]: ({ payload: r, position: i, text: c, actionCode:
|
|
542
|
+
[p.replace.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
|
|
530
543
|
o.push({
|
|
531
544
|
action: "replace",
|
|
532
545
|
model: "replace",
|
|
533
546
|
payload: `${r == null ? void 0 : r.text}`,
|
|
534
547
|
position: i,
|
|
535
548
|
text: c,
|
|
536
|
-
actionCode:
|
|
549
|
+
actionCode: l
|
|
537
550
|
});
|
|
538
551
|
},
|
|
539
|
-
[p.pinyin.type]: ({ payload: r, position: i, text: c, actionCode:
|
|
552
|
+
[p.pinyin.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
|
|
540
553
|
o.push({
|
|
541
554
|
action: "replace",
|
|
542
555
|
model: "pinyin",
|
|
543
556
|
payload: `${r == null ? void 0 : r.text}`,
|
|
544
557
|
position: i,
|
|
545
558
|
text: c,
|
|
546
|
-
actionCode:
|
|
559
|
+
actionCode: l
|
|
547
560
|
});
|
|
548
561
|
},
|
|
549
|
-
[p.language.type]: ({ payload: r, position: i, text: c, actionCode:
|
|
562
|
+
[p.language.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
|
|
550
563
|
o.push({
|
|
551
564
|
action: "language",
|
|
552
565
|
model: "language",
|
|
553
|
-
payload: `${r == null ? void 0 : r.code}`,
|
|
566
|
+
payload: `${_(r == null ? void 0 : r.code)}`,
|
|
554
567
|
position: i,
|
|
555
568
|
text: c,
|
|
556
|
-
actionCode:
|
|
569
|
+
actionCode: l
|
|
557
570
|
});
|
|
558
571
|
},
|
|
559
572
|
[p.tone.type]: ({ payload: r, position: i, actionCode: c }) => {
|
|
560
573
|
var u;
|
|
561
|
-
const
|
|
562
|
-
|
|
574
|
+
const l = (u = j.find((g) => g.value === (r == null ? void 0 : r.code))) == null ? void 0 : u.tag;
|
|
575
|
+
l && o.push({
|
|
563
576
|
action: "insert",
|
|
564
577
|
model: "control",
|
|
565
|
-
payload:
|
|
578
|
+
payload: l,
|
|
566
579
|
position: i,
|
|
567
580
|
text: "",
|
|
568
581
|
actionCode: c
|
|
@@ -579,85 +592,85 @@ const je = [
|
|
|
579
592
|
});
|
|
580
593
|
}
|
|
581
594
|
};
|
|
582
|
-
return
|
|
595
|
+
return e.forEach((r) => {
|
|
583
596
|
var E, b;
|
|
584
597
|
if (r.type === "text") {
|
|
585
598
|
n += r.text || "";
|
|
586
599
|
return;
|
|
587
600
|
}
|
|
588
601
|
if (r.type !== "customTag") return;
|
|
589
|
-
const i = (E = r.attrs) == null ? void 0 : E.categ, c = (b = r.attrs) == null ? void 0 : b.payload,
|
|
590
|
-
u &&
|
|
591
|
-
start:
|
|
592
|
-
end:
|
|
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];
|
|
603
|
+
u && s.push({
|
|
604
|
+
start: l,
|
|
605
|
+
end: l + u.length
|
|
593
606
|
}), g && g({
|
|
594
607
|
payload: c,
|
|
595
|
-
position:
|
|
608
|
+
position: l,
|
|
596
609
|
text: u,
|
|
597
610
|
actionCode: i
|
|
598
611
|
}), n += u;
|
|
599
612
|
}), {
|
|
600
613
|
text: n,
|
|
601
|
-
protectedRanges:
|
|
614
|
+
protectedRanges: s,
|
|
602
615
|
playments: o
|
|
603
616
|
};
|
|
604
|
-
},
|
|
605
|
-
const
|
|
606
|
-
if (
|
|
607
|
-
if (
|
|
608
|
-
return
|
|
609
|
-
const n =
|
|
610
|
-
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) ? [
|
|
611
624
|
{
|
|
612
625
|
type: "paragraph",
|
|
613
|
-
content:
|
|
626
|
+
content: e.filter(x)
|
|
614
627
|
}
|
|
615
628
|
] : [];
|
|
616
|
-
},
|
|
629
|
+
}, yt = (t, e) => {
|
|
617
630
|
let n = 0;
|
|
618
|
-
return
|
|
619
|
-
const
|
|
631
|
+
return e.map((o) => {
|
|
632
|
+
const s = t.indexOf(o, n), a = s >= 0 ? s : n, r = a + o.length;
|
|
620
633
|
return n = r, {
|
|
621
634
|
text: o,
|
|
622
|
-
start:
|
|
635
|
+
start: a,
|
|
623
636
|
end: r
|
|
624
637
|
};
|
|
625
638
|
});
|
|
626
|
-
},
|
|
627
|
-
if (
|
|
628
|
-
(
|
|
639
|
+
}, At = (t, e) => t.reduce((n, o) => {
|
|
640
|
+
if (e.some(
|
|
641
|
+
(a) => o.start > a.start && o.start < a.end
|
|
629
642
|
) && n.length) {
|
|
630
|
-
const
|
|
631
|
-
return
|
|
643
|
+
const a = n[n.length - 1];
|
|
644
|
+
return a.text += o.text, a.end = o.end, n;
|
|
632
645
|
}
|
|
633
646
|
return n.push({ ...o }), n;
|
|
634
|
-
}, []),
|
|
635
|
-
const n =
|
|
636
|
-
if (n.length <= 1) return [
|
|
637
|
-
const o =
|
|
638
|
-
|
|
639
|
-
|
|
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 || []
|
|
640
653
|
);
|
|
641
|
-
return o.map((
|
|
642
|
-
const r =
|
|
643
|
-
(c) =>
|
|
654
|
+
return o.map((s, a) => {
|
|
655
|
+
const r = a === o.length - 1, i = t.playments.filter(
|
|
656
|
+
(c) => vt(c, s.start, s.end, r)
|
|
644
657
|
).map((c) => ({
|
|
645
658
|
...c,
|
|
646
|
-
position: c.position -
|
|
659
|
+
position: c.position - s.start
|
|
647
660
|
}));
|
|
648
661
|
return {
|
|
649
|
-
text:
|
|
662
|
+
text: s.text,
|
|
650
663
|
playments: i
|
|
651
664
|
};
|
|
652
665
|
});
|
|
653
|
-
},
|
|
666
|
+
}, Kt = (t, e = {}) => {
|
|
654
667
|
const n = {
|
|
655
668
|
playments: [],
|
|
656
669
|
sentences: []
|
|
657
670
|
};
|
|
658
|
-
return
|
|
659
|
-
const
|
|
660
|
-
!
|
|
671
|
+
return Ct(t).forEach((s) => {
|
|
672
|
+
const a = Pt(s);
|
|
673
|
+
!a.text && !a.playments.length || Ft(a, e).forEach(
|
|
661
674
|
({ text: r, playments: i }) => {
|
|
662
675
|
n.sentences.push(r), n.playments.push(i);
|
|
663
676
|
}
|
|
@@ -666,30 +679,32 @@ const je = [
|
|
|
666
679
|
};
|
|
667
680
|
export {
|
|
668
681
|
h as DeleteMode,
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
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,
|
|
676
689
|
p as ToolConfig,
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
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
|
|
695
710
|
};
|