@naersen/tts-rich-text 0.12.1 → 0.13.0
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 +25 -0
- package/README.md +93 -9
- package/dist/base.css +1 -1
- package/dist/components/tts-rich-text/editor/plugins/tts-sentence-highlight.d.ts +17 -0
- package/dist/components/tts-rich-text/hooks/useSentenceHighlight.d.ts +13 -0
- package/dist/components/tts-rich-text/hooks/useSynthesizeAudioTool.d.ts +3 -0
- package/dist/core.js +214 -211
- package/dist/editor/index.d.ts +1 -0
- package/dist/index.js +4011 -5872
- package/dist/type/index.d.ts +5 -1
- package/package.json +89 -87
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
|
+
}, $e = 256, De = 256, p = {
|
|
5
5
|
stop: {
|
|
6
6
|
label: "停顿",
|
|
7
7
|
icon: "editor-stop",
|
|
@@ -96,23 +96,23 @@ const h = {
|
|
|
96
96
|
{ value: "it", label: "意大利语" },
|
|
97
97
|
{ value: "pt", label: "葡萄牙语" },
|
|
98
98
|
{ value: "ru", label: "俄语" }
|
|
99
|
-
], z = { jp: "ja", kr: "ko" }, _ = (
|
|
99
|
+
], z = { jp: "ja", kr: "ko" }, _ = (e) => typeof e == "string" ? z[e] ?? e : e, G = (e) => {
|
|
100
100
|
var o, s;
|
|
101
|
-
const
|
|
101
|
+
const t = (o = e.attrs) == null ? void 0 : o.payload, n = e.type === "customTag" && ((s = e.attrs) == null ? void 0 : s.categ) === "language" && _(t == null ? void 0 : t.code) !== (t == null ? void 0 : t.code);
|
|
102
102
|
return {
|
|
103
|
-
...
|
|
103
|
+
...e,
|
|
104
104
|
...n && {
|
|
105
105
|
attrs: {
|
|
106
|
-
...
|
|
107
|
-
payload: { ...
|
|
106
|
+
...e.attrs,
|
|
107
|
+
payload: { ...t, code: _(t.code) }
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
|
-
...
|
|
110
|
+
...e.content && { content: e.content.map(G) }
|
|
111
111
|
};
|
|
112
112
|
}, X = [
|
|
113
113
|
{ label: "停顿 0.5 秒", value: 0.5 },
|
|
114
114
|
{ label: "停顿 1 秒", value: 1 }
|
|
115
|
-
],
|
|
115
|
+
], Be = {
|
|
116
116
|
SENTENCE: "sentence",
|
|
117
117
|
CUSTOM_TAG: "customTag",
|
|
118
118
|
/**
|
|
@@ -120,15 +120,18 @@ const h = {
|
|
|
120
120
|
* 工具栏与右键面板都要用它来主动收起气泡,避免两个浮层叠在一起。
|
|
121
121
|
*/
|
|
122
122
|
BUBBLE_MENU_KEY: "ttsRichTextBubbleMenu"
|
|
123
|
-
},
|
|
124
|
-
var
|
|
125
|
-
return ((
|
|
126
|
-
},
|
|
127
|
-
tools: M.filter((
|
|
123
|
+
}, He = (e) => {
|
|
124
|
+
var t;
|
|
125
|
+
return ((t = p[e]) == null ? void 0 : t.deleteMode) === h.DELETE_NODE;
|
|
126
|
+
}, ke = (e) => e === p.stop.type || e === p.customStop.type, we = (e) => e === p.customStop.type ? { time: X[0].value } : {}, Ve = (e, t) => e === p.customStop.type ? `${t == null ? void 0 : t.time} 秒` : "", M = Object.keys(p), m = {
|
|
127
|
+
tools: M.filter((e) => e !== p.tone.type),
|
|
128
128
|
languages: R,
|
|
129
129
|
maxPinyinLength: 4,
|
|
130
130
|
maxNumberLength: 16,
|
|
131
|
-
enablePreview: !0
|
|
131
|
+
enablePreview: !0,
|
|
132
|
+
enableContextMenu: !0,
|
|
133
|
+
// 保持已有业务项目的试听表现,需要句子高亮时由项目显式开启。
|
|
134
|
+
enableSentenceHighlight: !1
|
|
132
135
|
}, Y = {
|
|
133
136
|
1: {
|
|
134
137
|
tools: [
|
|
@@ -142,20 +145,20 @@ const h = {
|
|
|
142
145
|
"upload",
|
|
143
146
|
"ignore"
|
|
144
147
|
],
|
|
145
|
-
languages: R.filter((
|
|
148
|
+
languages: R.filter((e) => ["zh", "en"].includes(e.value))
|
|
146
149
|
},
|
|
147
150
|
2: m,
|
|
148
|
-
3: { tools: M.filter((
|
|
149
|
-
},
|
|
150
|
-
const n = Y[
|
|
151
|
+
3: { tools: M.filter((e) => e !== p.language.type) }
|
|
152
|
+
}, Ue = (e, t = {}) => {
|
|
153
|
+
const n = Y[e] ?? m;
|
|
151
154
|
return {
|
|
152
155
|
...m,
|
|
153
156
|
...n,
|
|
154
|
-
...
|
|
155
|
-
tools:
|
|
156
|
-
languages:
|
|
157
|
+
...t,
|
|
158
|
+
tools: t.tools ?? n.tools ?? m.tools,
|
|
159
|
+
languages: t.languages ?? n.languages ?? m.languages
|
|
157
160
|
};
|
|
158
|
-
},
|
|
161
|
+
}, je = () => ({
|
|
159
162
|
type: "doc",
|
|
160
163
|
content: [
|
|
161
164
|
{
|
|
@@ -163,9 +166,9 @@ const h = {
|
|
|
163
166
|
content: []
|
|
164
167
|
}
|
|
165
168
|
]
|
|
166
|
-
}), K = /[\u4e00-\u9fff]/, W = /\s/g, q = 0.28, J = 0.14,
|
|
167
|
-
const n = Number.isFinite(
|
|
168
|
-
return Array.from(
|
|
169
|
+
}), K = /[\u4e00-\u9fff]/, W = /\s/g, q = 0.28, J = 0.14, ze = (e, t = 1) => {
|
|
170
|
+
const n = Number.isFinite(t) && t > 0 ? t : 1;
|
|
171
|
+
return Array.from(e.replace(W, "")).reduce(
|
|
169
172
|
(s, a) => s + (K.test(a) ? q : J),
|
|
170
173
|
0
|
|
171
174
|
) / n;
|
|
@@ -191,49 +194,49 @@ const h = {
|
|
|
191
194
|
7: "七",
|
|
192
195
|
8: "八",
|
|
193
196
|
9: "九"
|
|
194
|
-
}, Q = ["", "十", "百", "千"],
|
|
195
|
-
function
|
|
196
|
-
return
|
|
197
|
+
}, Q = ["", "十", "百", "千"], ee = ["", "万", "亿", "万亿"];
|
|
198
|
+
function te(e) {
|
|
199
|
+
return e ? e.split("").map((t) => O[t] || t).join("") : "";
|
|
197
200
|
}
|
|
198
|
-
function
|
|
199
|
-
return
|
|
201
|
+
function Ge(e) {
|
|
202
|
+
return e ? e.split("").map((t) => Z[t] || t).join("") : "";
|
|
200
203
|
}
|
|
201
|
-
function
|
|
202
|
-
const
|
|
204
|
+
function ne(e) {
|
|
205
|
+
const t = e.length;
|
|
203
206
|
let n = "", o = !1;
|
|
204
|
-
for (let s = 0; s <
|
|
205
|
-
const a =
|
|
207
|
+
for (let s = 0; s < t; s++) {
|
|
208
|
+
const a = e[s], r = t - 1 - s;
|
|
206
209
|
a === "0" ? !o && n !== "" && (o = !0) : (o && (n += "零", o = !1), n += O[a] + Q[r]);
|
|
207
210
|
}
|
|
208
211
|
return n.startsWith("一十") && n.length === 2 && (n = n.substring(1)), n;
|
|
209
212
|
}
|
|
210
|
-
function P(
|
|
211
|
-
if (!
|
|
212
|
-
if (
|
|
213
|
-
let
|
|
214
|
-
const n =
|
|
213
|
+
function P(e) {
|
|
214
|
+
if (!e) return "";
|
|
215
|
+
if (e === "0" || (e = e.replace(/^0+/, "") || "0", e === "0")) return "零";
|
|
216
|
+
let t = "";
|
|
217
|
+
const n = e.length, o = [];
|
|
215
218
|
for (let s = n; s > 0; s -= 4) {
|
|
216
219
|
const a = Math.max(0, s - 4);
|
|
217
|
-
o.unshift(
|
|
220
|
+
o.unshift(e.substring(a, s));
|
|
218
221
|
}
|
|
219
222
|
for (let s = 0; s < o.length; s++) {
|
|
220
|
-
const a = o[s], r =
|
|
223
|
+
const a = o[s], r = ne(a);
|
|
221
224
|
if (r !== "") {
|
|
222
225
|
const i = o.length - 1 - s;
|
|
223
|
-
|
|
226
|
+
t += r + ee[i];
|
|
224
227
|
}
|
|
225
228
|
}
|
|
226
|
-
return
|
|
229
|
+
return t;
|
|
227
230
|
}
|
|
228
|
-
function
|
|
229
|
-
return P(
|
|
231
|
+
function oe(e) {
|
|
232
|
+
return P(e);
|
|
230
233
|
}
|
|
231
|
-
const
|
|
232
|
-
{ label: "基数读法", func:
|
|
234
|
+
const Xe = [
|
|
235
|
+
{ label: "基数读法", func: te },
|
|
233
236
|
// { label: '位数读法', func: toPhoneReading },
|
|
234
237
|
{ label: "位数读法", func: P },
|
|
235
|
-
{ label: "口语读法", func:
|
|
236
|
-
],
|
|
238
|
+
{ label: "口语读法", func: oe }
|
|
239
|
+
], re = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u00AD\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFE00-\uFE0F\uFEFF\uFFFD\uE000-\uF8FF]/g, se = /[\t\f\v\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, C = {
|
|
237
240
|
"‘": "'",
|
|
238
241
|
"’": "'",
|
|
239
242
|
"‚": "'",
|
|
@@ -265,63 +268,63 @@ const Xt = [
|
|
|
265
268
|
"︔": ";",
|
|
266
269
|
"︕": "!",
|
|
267
270
|
"︖": "?"
|
|
268
|
-
},
|
|
271
|
+
}, ae = new RegExp(`[${Object.keys(C).join("")}]`, "g"), ie = (e) => e.replace(/[\uFF21-\uFF3A\uFF41-\uFF5A\uFF10-\uFF19]/g, (t) => String.fromCharCode(t.charCodeAt(0) - 65248)), le = (e) => ie(e).replace(/\r\n?/g, `
|
|
269
272
|
`).replace(/[\u2028\u2029]/g, `
|
|
270
|
-
`).replace(
|
|
273
|
+
`).replace(re, "").replace(se, " ").replace(ae, (t) => C[t] || "").replace(/ *\n */g, `
|
|
271
274
|
`).replace(/\n{3,}/g, `
|
|
272
275
|
|
|
273
|
-
`),
|
|
274
|
-
if (typeof window > "u" || !
|
|
275
|
-
return
|
|
276
|
-
const n = new DOMParser().parseFromString(
|
|
276
|
+
`), Ye = (e) => {
|
|
277
|
+
if (typeof window > "u" || !e)
|
|
278
|
+
return e;
|
|
279
|
+
const n = new DOMParser().parseFromString(e, "text/html"), o = n.createTreeWalker(n.body, NodeFilter.SHOW_TEXT);
|
|
277
280
|
let s = o.nextNode();
|
|
278
281
|
for (; s; )
|
|
279
|
-
s.textContent =
|
|
282
|
+
s.textContent = le(s.textContent || ""), s = o.nextNode();
|
|
280
283
|
return n.body.innerHTML;
|
|
281
|
-
},
|
|
284
|
+
}, ce = {
|
|
282
285
|
minSegmentLength: 32,
|
|
283
286
|
maxSegmentLength: 128,
|
|
284
287
|
rebalanceRatio: 0.4
|
|
285
|
-
}, y = /[一-鿿㐀-䶿豈- -〿-]/,
|
|
286
|
-
let
|
|
287
|
-
for (const n of
|
|
288
|
-
|
|
289
|
-
return
|
|
290
|
-
},
|
|
291
|
-
`).map((
|
|
292
|
-
let
|
|
293
|
-
for (; n !==
|
|
294
|
-
n =
|
|
295
|
-
for (n = ""; n !==
|
|
296
|
-
n =
|
|
297
|
-
return
|
|
298
|
-
}, L = (
|
|
288
|
+
}, y = /[一-鿿㐀-䶿豈- -〿-]/, ue = /[。!?!?\.]/, ge = /[;;]/, pe = /[,,、::]/, he = /[。!?!?,,、;;::]/, A = "", v = "", d = (e) => {
|
|
289
|
+
let t = 0;
|
|
290
|
+
for (const n of e)
|
|
291
|
+
t += y.test(n) ? 2 : 1;
|
|
292
|
+
return t;
|
|
293
|
+
}, fe = (e) => e.replace(/\r/g, "").split(`
|
|
294
|
+
`).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), Ee = (e) => {
|
|
295
|
+
let t = e, n = "";
|
|
296
|
+
for (; n !== t; )
|
|
297
|
+
n = t, t = t.replace(/(\d),(\d)/g, `$1${A}$2`);
|
|
298
|
+
for (n = ""; n !== t; )
|
|
299
|
+
n = t, t = t.replace(/(\d)\.(\d)/g, `$1${v}$2`);
|
|
300
|
+
return t;
|
|
301
|
+
}, L = (e) => e.split(A).join(",").split(v).join("."), Te = (e, t, n, o, s) => {
|
|
299
302
|
let a = -1, r = Number.POSITIVE_INFINITY;
|
|
300
|
-
const i = Math.max(1, n), c = Math.min(
|
|
303
|
+
const i = Math.max(1, n), c = Math.min(e.length, o);
|
|
301
304
|
for (let l = i; l <= c; l += 1) {
|
|
302
|
-
if (!s.test(
|
|
305
|
+
if (!s.test(e[l - 1]))
|
|
303
306
|
continue;
|
|
304
|
-
const u = Math.abs(l -
|
|
305
|
-
if (u < r && (r = u, a = l), l >
|
|
307
|
+
const u = Math.abs(l - t);
|
|
308
|
+
if (u < r && (r = u, a = l), l > t && a >= 0)
|
|
306
309
|
break;
|
|
307
310
|
}
|
|
308
311
|
return a;
|
|
309
|
-
},
|
|
312
|
+
}, de = (e, t, n, o) => {
|
|
310
313
|
let s = -1, a = Number.POSITIVE_INFINITY;
|
|
311
|
-
const r = Math.max(1, n), i = Math.min(
|
|
314
|
+
const r = Math.max(1, n), i = Math.min(e.length, o);
|
|
312
315
|
for (let c = r; c <= i; c += 1) {
|
|
313
|
-
if (
|
|
316
|
+
if (e[c - 1] !== " ")
|
|
314
317
|
continue;
|
|
315
|
-
const l = Math.abs(c -
|
|
316
|
-
if (l < a && (a = l, s = c), c >
|
|
318
|
+
const l = Math.abs(c - t);
|
|
319
|
+
if (l < a && (a = l, s = c), c > t && s >= 0)
|
|
317
320
|
break;
|
|
318
321
|
}
|
|
319
322
|
return s;
|
|
320
|
-
}, F = (
|
|
323
|
+
}, F = (e, t, n, o, s) => {
|
|
321
324
|
for (const a of s) {
|
|
322
|
-
const r =
|
|
323
|
-
t,
|
|
325
|
+
const r = Te(
|
|
324
326
|
e,
|
|
327
|
+
t,
|
|
325
328
|
n,
|
|
326
329
|
o,
|
|
327
330
|
a
|
|
@@ -329,48 +332,48 @@ const Xt = [
|
|
|
329
332
|
if (r >= 0)
|
|
330
333
|
return r;
|
|
331
334
|
}
|
|
332
|
-
return
|
|
333
|
-
},
|
|
335
|
+
return de(e, t, n, o);
|
|
336
|
+
}, me = (e, t) => {
|
|
334
337
|
const n = [];
|
|
335
|
-
let o =
|
|
336
|
-
for (; o && d(o) >
|
|
338
|
+
let o = e;
|
|
339
|
+
for (; o && d(o) > t; ) {
|
|
337
340
|
const s = d(o), a = Math.floor(s / 2);
|
|
338
341
|
let r = 0, i = 0, c = 0;
|
|
339
342
|
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 >=
|
|
343
|
+
if (c += y.test(o[g]) ? 2 : 1, !r && c >= a && (r = g + 1), c >= t) {
|
|
341
344
|
i = g + 1;
|
|
342
345
|
break;
|
|
343
346
|
}
|
|
344
347
|
i || (i = o.length), r || (r = Math.floor(o.length / 2));
|
|
345
348
|
const l = Math.max(1, Math.floor(r / 3));
|
|
346
349
|
let u = F(o, r, l, i, [
|
|
347
|
-
|
|
348
|
-
|
|
350
|
+
ge,
|
|
351
|
+
pe
|
|
349
352
|
]);
|
|
350
353
|
(u < 0 || u >= o.length) && (u = r), n.push(o.slice(0, u)), o = o.slice(u);
|
|
351
354
|
}
|
|
352
355
|
return o.trim() && n.push(o), n;
|
|
353
|
-
},
|
|
354
|
-
if (
|
|
355
|
-
return
|
|
356
|
-
const n =
|
|
356
|
+
}, be = (e, t) => {
|
|
357
|
+
if (e.length <= 1)
|
|
358
|
+
return e;
|
|
359
|
+
const n = e[e.length - 1], o = e.reduce((g, E) => g + E.length, 0) / e.length, s = Math.floor(o * t);
|
|
357
360
|
if (n.length >= s)
|
|
358
|
-
return
|
|
359
|
-
const r = `${
|
|
360
|
-
|
|
361
|
+
return e;
|
|
362
|
+
const r = `${e[e.length - 2]}${n}`, i = Math.floor(r.length / 2), c = Math.max(1, Math.floor(i / 3)), l = F(r, i, c, r.length, [
|
|
363
|
+
he
|
|
361
364
|
]);
|
|
362
365
|
if (l <= 0 || l >= r.length)
|
|
363
|
-
return
|
|
364
|
-
const u = [...
|
|
366
|
+
return e;
|
|
367
|
+
const u = [...e];
|
|
365
368
|
return u[u.length - 2] = r.slice(0, l), u[u.length - 1] = r.slice(l), u.filter(Boolean);
|
|
366
|
-
},
|
|
369
|
+
}, _e = (e, t = {}) => {
|
|
367
370
|
const n = {
|
|
368
|
-
...
|
|
369
|
-
...
|
|
370
|
-
}, o =
|
|
371
|
+
...ce,
|
|
372
|
+
...t
|
|
373
|
+
}, o = fe(e);
|
|
371
374
|
if (!o)
|
|
372
375
|
return [];
|
|
373
|
-
const s =
|
|
376
|
+
const s = Ee(o);
|
|
374
377
|
if (d(s) <= n.minSegmentLength)
|
|
375
378
|
return [L(s)];
|
|
376
379
|
const a = [], r = s.split(new RegExp("(?<=[。!?!?\\.])"));
|
|
@@ -380,63 +383,63 @@ const Xt = [
|
|
|
380
383
|
continue;
|
|
381
384
|
i += l;
|
|
382
385
|
const u = i[i.length - 1] ?? "";
|
|
383
|
-
d(i) >= n.minSegmentLength &&
|
|
386
|
+
d(i) >= n.minSegmentLength && ue.test(u) && (a.push(i), i = "");
|
|
384
387
|
}
|
|
385
388
|
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] :
|
|
387
|
-
return
|
|
389
|
+
const c = a.flatMap((l) => d(l) <= n.maxSegmentLength ? [l] : me(l, n.maxSegmentLength));
|
|
390
|
+
return be(c, n.rebalanceRatio).map(
|
|
388
391
|
L
|
|
389
392
|
);
|
|
390
393
|
}, T = {
|
|
391
394
|
minSegmentLength: 32,
|
|
392
395
|
maxSegmentLength: 64,
|
|
393
396
|
rebalanceRatio: 0.4
|
|
394
|
-
}, $ = /[一-鿿㐀-䶿豈- -〿-]/, D = /[。!?!?\.]/, B = /[;;]/,
|
|
395
|
-
let
|
|
396
|
-
for (const n of
|
|
397
|
-
|
|
398
|
-
return
|
|
399
|
-
},
|
|
400
|
-
`).map((
|
|
401
|
-
let
|
|
402
|
-
for (; n !==
|
|
403
|
-
n =
|
|
404
|
-
for (n = ""; n !==
|
|
405
|
-
n =
|
|
406
|
-
return
|
|
407
|
-
},
|
|
397
|
+
}, $ = /[一-鿿㐀-䶿豈- -〿-]/, D = /[。!?!?\.]/, B = /[;;]/, H = /[,,::]/, Ne = /[、]/, k = "", w = "", f = (e) => {
|
|
398
|
+
let t = 0;
|
|
399
|
+
for (const n of e)
|
|
400
|
+
t += $.test(n) ? 2 : 1;
|
|
401
|
+
return t;
|
|
402
|
+
}, Le = (e) => e.replace(/\r/g, "").split(`
|
|
403
|
+
`).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), Se = (e) => {
|
|
404
|
+
let t = e, n = "";
|
|
405
|
+
for (; n !== t; )
|
|
406
|
+
n = t, t = t.replace(/(\d),(\d)/g, `$1${k}$2`);
|
|
407
|
+
for (n = ""; n !== t; )
|
|
408
|
+
n = t, t = t.replace(/(\d)\.(\d)/g, `$1${w}$2`);
|
|
409
|
+
return t;
|
|
410
|
+
}, S = (e) => e.split(k).join(",").split(w).join("."), N = (e, t) => {
|
|
408
411
|
let n = 0;
|
|
409
|
-
for (let o = 0; o <
|
|
410
|
-
if (n += $.test(
|
|
412
|
+
for (let o = 0; o < e.length; o += 1)
|
|
413
|
+
if (n += $.test(e[o]) ? 2 : 1, n >= t)
|
|
411
414
|
return o + 1;
|
|
412
|
-
return
|
|
413
|
-
},
|
|
415
|
+
return e.length;
|
|
416
|
+
}, I = (e, t, n, o, s) => {
|
|
414
417
|
let a = -1, r = Number.POSITIVE_INFINITY;
|
|
415
|
-
const i = Math.max(1, n), c = Math.min(
|
|
418
|
+
const i = Math.max(1, n), c = Math.min(e.length - 1, o);
|
|
416
419
|
for (let l = i; l <= c; l += 1) {
|
|
417
|
-
if (!s.test(
|
|
420
|
+
if (!s.test(e[l - 1]))
|
|
418
421
|
continue;
|
|
419
|
-
const u = Math.abs(l -
|
|
420
|
-
if (u < r && (r = u, a = l), l >
|
|
422
|
+
const u = Math.abs(l - t);
|
|
423
|
+
if (u < r && (r = u, a = l), l > t && a >= 0)
|
|
421
424
|
break;
|
|
422
425
|
}
|
|
423
426
|
return a;
|
|
424
|
-
},
|
|
427
|
+
}, Ie = (e, t, n, o) => {
|
|
425
428
|
let s = -1, a = Number.POSITIVE_INFINITY;
|
|
426
|
-
const r = Math.max(1, n), i = Math.min(
|
|
429
|
+
const r = Math.max(1, n), i = Math.min(e.length - 1, o);
|
|
427
430
|
for (let c = r; c <= i; c += 1) {
|
|
428
|
-
if (
|
|
431
|
+
if (e[c - 1] !== " ")
|
|
429
432
|
continue;
|
|
430
|
-
const l = Math.abs(c -
|
|
431
|
-
if (l < a && (a = l, s = c), c >
|
|
433
|
+
const l = Math.abs(c - t);
|
|
434
|
+
if (l < a && (a = l, s = c), c > t && s >= 0)
|
|
432
435
|
break;
|
|
433
436
|
}
|
|
434
437
|
return s;
|
|
435
|
-
}, V = (
|
|
438
|
+
}, V = (e, t, n, o, s) => {
|
|
436
439
|
for (const r of s) {
|
|
437
|
-
const i =
|
|
438
|
-
t,
|
|
440
|
+
const i = I(
|
|
439
441
|
e,
|
|
442
|
+
t,
|
|
440
443
|
n,
|
|
441
444
|
o,
|
|
442
445
|
r
|
|
@@ -444,52 +447,52 @@ const Xt = [
|
|
|
444
447
|
if (i >= 0)
|
|
445
448
|
return i;
|
|
446
449
|
}
|
|
447
|
-
const a =
|
|
448
|
-
return a >= 0 ? a :
|
|
449
|
-
t,
|
|
450
|
+
const a = Ie(e, t, n, o);
|
|
451
|
+
return a >= 0 ? a : I(
|
|
450
452
|
e,
|
|
453
|
+
t,
|
|
451
454
|
n,
|
|
452
455
|
o,
|
|
453
|
-
|
|
456
|
+
Ne
|
|
454
457
|
);
|
|
455
|
-
},
|
|
458
|
+
}, xe = (e, t) => {
|
|
456
459
|
const n = [];
|
|
457
|
-
let o =
|
|
458
|
-
for (; o && f(o) >
|
|
459
|
-
const s = f(o), a = Math.min(Math.floor(s / 2),
|
|
460
|
+
let o = e.trim();
|
|
461
|
+
for (; o && f(o) > t; ) {
|
|
462
|
+
const s = f(o), a = Math.min(Math.floor(s / 2), t), r = N(o, a), i = Math.max(1, Math.floor(r / 3)), c = Math.max(
|
|
460
463
|
r + 1,
|
|
461
|
-
N(o,
|
|
464
|
+
N(o, t)
|
|
462
465
|
);
|
|
463
466
|
let l = V(o, r, i, c, [
|
|
464
467
|
B,
|
|
465
|
-
|
|
468
|
+
H
|
|
466
469
|
]);
|
|
467
470
|
(l < 0 || l >= o.length) && (l = r), n.push(o.slice(0, l).trim()), o = o.slice(l).trim();
|
|
468
471
|
}
|
|
469
472
|
return o && n.push(o), n;
|
|
470
|
-
},
|
|
471
|
-
if (
|
|
472
|
-
return
|
|
473
|
-
const n =
|
|
473
|
+
}, Re = (e, t) => {
|
|
474
|
+
if (e.length <= 1)
|
|
475
|
+
return e;
|
|
476
|
+
const n = e[e.length - 1], o = e.reduce((E, b) => E + f(b), 0) / e.length, s = Math.floor(o * t);
|
|
474
477
|
if (f(n) >= s)
|
|
475
|
-
return
|
|
476
|
-
const r = `${
|
|
478
|
+
return e;
|
|
479
|
+
const r = `${e[e.length - 2]}${n}`, i = Math.floor(f(r) / 2), c = N(r, i), l = Math.max(1, Math.floor(c / 3));
|
|
477
480
|
let u = V(r, c, l, r.length, [
|
|
478
481
|
D,
|
|
479
482
|
B,
|
|
480
|
-
|
|
483
|
+
H
|
|
481
484
|
]);
|
|
482
485
|
if (u <= 0 || u >= r.length)
|
|
483
|
-
return
|
|
484
|
-
const g = [...
|
|
486
|
+
return e;
|
|
487
|
+
const g = [...e];
|
|
485
488
|
return g[g.length - 2] = r.slice(0, u).trim(), g[g.length - 1] = r.slice(u).trim(), g.filter(Boolean);
|
|
486
|
-
},
|
|
487
|
-
const
|
|
488
|
-
if (!
|
|
489
|
+
}, Me = (e) => {
|
|
490
|
+
const t = Le(e);
|
|
491
|
+
if (!t)
|
|
489
492
|
return [];
|
|
490
|
-
const n =
|
|
493
|
+
const n = Se(t);
|
|
491
494
|
if (f(n) <= T.minSegmentLength)
|
|
492
|
-
return [
|
|
495
|
+
return [S(n)];
|
|
493
496
|
const o = [], s = n.split(new RegExp("(?<=[。!?!?\\.])"));
|
|
494
497
|
let a = "";
|
|
495
498
|
for (const i of s) {
|
|
@@ -500,13 +503,13 @@ const Xt = [
|
|
|
500
503
|
f(a) >= T.minSegmentLength && D.test(c) && (o.push(a.trim()), a = "");
|
|
501
504
|
}
|
|
502
505
|
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] :
|
|
504
|
-
return
|
|
506
|
+
const r = o.flatMap((i) => f(i) <= T.maxSegmentLength ? [i] : xe(i, T.maxSegmentLength));
|
|
507
|
+
return Re(
|
|
505
508
|
r,
|
|
506
509
|
T.rebalanceRatio
|
|
507
|
-
).map(
|
|
508
|
-
},
|
|
509
|
-
const
|
|
510
|
+
).map(S);
|
|
511
|
+
}, Oe = (e, t = {}) => t.strategy === "legacy" ? Me(e) : _e(e, t), U = (e) => e.type === "text" ? e.text || "" : (e.content || []).map(U).join(""), Pe = (e) => {
|
|
512
|
+
const t = e.content || [];
|
|
510
513
|
let n = "";
|
|
511
514
|
const o = [], s = [], a = {
|
|
512
515
|
[p.stop.type]: ({ position: r, actionCode: i }) => {
|
|
@@ -592,7 +595,7 @@ const Xt = [
|
|
|
592
595
|
});
|
|
593
596
|
}
|
|
594
597
|
};
|
|
595
|
-
return
|
|
598
|
+
return t.forEach((r) => {
|
|
596
599
|
var E, b;
|
|
597
600
|
if (r.type === "text") {
|
|
598
601
|
n += r.text || "";
|
|
@@ -614,46 +617,46 @@ const Xt = [
|
|
|
614
617
|
protectedRanges: s,
|
|
615
618
|
playments: o
|
|
616
619
|
};
|
|
617
|
-
}, x = (
|
|
618
|
-
const
|
|
619
|
-
if (
|
|
620
|
-
if (
|
|
621
|
-
return
|
|
622
|
-
const n =
|
|
623
|
-
return n.length ? n :
|
|
620
|
+
}, x = (e) => e.type === "text" || e.type === "customTag", Ce = (e) => {
|
|
621
|
+
const t = e.content || [];
|
|
622
|
+
if (e.type === "paragraph") return [e];
|
|
623
|
+
if (e.type === "doc")
|
|
624
|
+
return t.filter((o) => o.type === "paragraph");
|
|
625
|
+
const n = t.filter((o) => o.type === "paragraph");
|
|
626
|
+
return n.length ? n : t.some(x) ? [
|
|
624
627
|
{
|
|
625
628
|
type: "paragraph",
|
|
626
|
-
content:
|
|
629
|
+
content: t.filter(x)
|
|
627
630
|
}
|
|
628
631
|
] : [];
|
|
629
|
-
},
|
|
632
|
+
}, ye = (e, t) => {
|
|
630
633
|
let n = 0;
|
|
631
|
-
return
|
|
632
|
-
const s =
|
|
634
|
+
return t.map((o) => {
|
|
635
|
+
const s = e.indexOf(o, n), a = s >= 0 ? s : n, r = a + o.length;
|
|
633
636
|
return n = r, {
|
|
634
637
|
text: o,
|
|
635
638
|
start: a,
|
|
636
639
|
end: r
|
|
637
640
|
};
|
|
638
641
|
});
|
|
639
|
-
},
|
|
640
|
-
if (
|
|
642
|
+
}, Ae = (e, t) => e.reduce((n, o) => {
|
|
643
|
+
if (t.some(
|
|
641
644
|
(a) => o.start > a.start && o.start < a.end
|
|
642
645
|
) && n.length) {
|
|
643
646
|
const a = n[n.length - 1];
|
|
644
647
|
return a.text += o.text, a.end = o.end, n;
|
|
645
648
|
}
|
|
646
649
|
return n.push({ ...o }), n;
|
|
647
|
-
}, []),
|
|
648
|
-
const n =
|
|
649
|
-
if (n.length <= 1) return [
|
|
650
|
-
const o =
|
|
651
|
-
|
|
652
|
-
|
|
650
|
+
}, []), ve = (e, t, n, o) => e.position >= t && e.position < n ? !0 : !e.text && o && e.position === n, Fe = (e, t) => {
|
|
651
|
+
const n = Oe(e.text, t);
|
|
652
|
+
if (n.length <= 1) return [e];
|
|
653
|
+
const o = Ae(
|
|
654
|
+
ye(e.text, n),
|
|
655
|
+
e.protectedRanges || []
|
|
653
656
|
);
|
|
654
657
|
return o.map((s, a) => {
|
|
655
|
-
const r = a === o.length - 1, i =
|
|
656
|
-
(c) =>
|
|
658
|
+
const r = a === o.length - 1, i = e.playments.filter(
|
|
659
|
+
(c) => ve(c, s.start, s.end, r)
|
|
657
660
|
).map((c) => ({
|
|
658
661
|
...c,
|
|
659
662
|
position: c.position - s.start
|
|
@@ -663,14 +666,14 @@ const Xt = [
|
|
|
663
666
|
playments: i
|
|
664
667
|
};
|
|
665
668
|
});
|
|
666
|
-
},
|
|
669
|
+
}, Ke = (e, t = {}) => {
|
|
667
670
|
const n = {
|
|
668
671
|
playments: [],
|
|
669
672
|
sentences: []
|
|
670
673
|
};
|
|
671
|
-
return
|
|
672
|
-
const a =
|
|
673
|
-
!a.text && !a.playments.length ||
|
|
674
|
+
return Ce(e).forEach((s) => {
|
|
675
|
+
const a = Pe(s);
|
|
676
|
+
!a.text && !a.playments.length || Fe(a, t).forEach(
|
|
674
677
|
({ text: r, playments: i }) => {
|
|
675
678
|
n.sentences.push(r), n.playments.push(i);
|
|
676
679
|
}
|
|
@@ -679,32 +682,32 @@ const Xt = [
|
|
|
679
682
|
};
|
|
680
683
|
export {
|
|
681
684
|
h as DeleteMode,
|
|
682
|
-
|
|
685
|
+
Be as EditorConst,
|
|
683
686
|
R as LanguageOptions,
|
|
684
|
-
|
|
685
|
-
$
|
|
686
|
-
|
|
687
|
+
De as MAX_LANGUAGE_SELECTION_LENGTH,
|
|
688
|
+
$e as MAX_REPLACEMENT_TEXT_LENGTH,
|
|
689
|
+
Xe as NumberToTextTools,
|
|
687
690
|
X as StopOptions,
|
|
688
691
|
j as ToneOptions,
|
|
689
692
|
p as ToolConfig,
|
|
690
693
|
M as allToolTypes,
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
694
|
+
Ke as convertToTtsFormat,
|
|
695
|
+
ze as estimateTtsDuration,
|
|
696
|
+
we as getDefaultLockPayload,
|
|
697
|
+
je as getInitContent,
|
|
698
|
+
Ve as getLockPayloadLabel,
|
|
696
699
|
d as getVisualLength,
|
|
697
|
-
|
|
698
|
-
|
|
700
|
+
He as isInsertTagType,
|
|
701
|
+
ke as isLockableTagType,
|
|
699
702
|
_ as normalizeLanguageCode,
|
|
700
703
|
G as normalizeTtsContent,
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
704
|
+
Ue as resolveTtsEditorFeatures,
|
|
705
|
+
Ye as sanitizePastedHtml,
|
|
706
|
+
le as sanitizePastedText,
|
|
707
|
+
Oe as splitTextToSentences,
|
|
708
|
+
te as toCardinal,
|
|
709
|
+
oe as toColloquial,
|
|
710
|
+
Ge as toPhoneReading,
|
|
708
711
|
P as toPositional,
|
|
709
|
-
|
|
712
|
+
Pe as transformParagraph
|
|
710
713
|
};
|