@naersen/tts-rich-text 0.10.4 → 0.12.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 +28 -0
- package/README.md +31 -1
- package/dist/base.css +1 -1
- package/dist/components/tts-editor-root/index.vue.d.ts +2 -0
- package/dist/components/tts-rich-text/editor/useEditorToolkit.d.ts +1 -0
- package/dist/components/tts-rich-text/editor/useRichTextEditor.d.ts +4 -1
- package/dist/components/tts-rich-text-editor/index.vue.d.ts +12 -2
- 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/transform-data.d.ts +2 -1
- package/dist/core.js +339 -219
- package/dist/index.js +2114 -2101
- package/dist/type/index.d.ts +5 -0
- package/package.json +1 -1
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
|
+
}, ye = 256, ve = 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
|
+
}, U = [
|
|
74
74
|
{ label: "笑声", value: "笑声", tag: "[laughter]" },
|
|
75
75
|
{ label: "叹气", value: "叹气", tag: "[sigh]" },
|
|
76
76
|
{ label: "吸气", value: "吸气", tag: "[sniff]" },
|
|
@@ -85,7 +85,7 @@ 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
|
+
], x = [
|
|
89
89
|
{ value: "zh", label: "中文" },
|
|
90
90
|
{ value: "en", label: "英语" },
|
|
91
91
|
{ value: "jp", label: "日语" },
|
|
@@ -96,10 +96,10 @@ const f = {
|
|
|
96
96
|
{ value: "it", label: "意大利语" },
|
|
97
97
|
{ value: "pt", label: "葡萄牙语" },
|
|
98
98
|
{ value: "ru", label: "俄语" }
|
|
99
|
-
],
|
|
99
|
+
], j = [
|
|
100
100
|
{ label: "停顿 0.5 秒", value: 0.5 },
|
|
101
101
|
{ label: "停顿 1 秒", value: 1 }
|
|
102
|
-
],
|
|
102
|
+
], Fe = {
|
|
103
103
|
SENTENCE: "sentence",
|
|
104
104
|
CUSTOM_TAG: "customTag",
|
|
105
105
|
/**
|
|
@@ -107,16 +107,16 @@ const f = {
|
|
|
107
107
|
* 工具栏与右键面板都要用它来主动收起气泡,避免两个浮层叠在一起。
|
|
108
108
|
*/
|
|
109
109
|
BUBBLE_MENU_KEY: "ttsRichTextBubbleMenu"
|
|
110
|
-
},
|
|
110
|
+
}, $e = (e) => {
|
|
111
111
|
var t;
|
|
112
|
-
return ((t =
|
|
113
|
-
},
|
|
114
|
-
tools:
|
|
115
|
-
languages:
|
|
112
|
+
return ((t = p[e]) == null ? void 0 : t.deleteMode) === h.DELETE_NODE;
|
|
113
|
+
}, De = (e) => e === p.stop.type || e === p.customStop.type, Be = (e) => e === p.customStop.type ? { time: j[0].value } : {}, we = (e, t) => e === p.customStop.type ? `${t == null ? void 0 : t.time} 秒` : "", R = Object.keys(p), m = {
|
|
114
|
+
tools: R.filter((e) => e !== p.tone.type),
|
|
115
|
+
languages: x,
|
|
116
116
|
maxPinyinLength: 4,
|
|
117
117
|
maxNumberLength: 16,
|
|
118
118
|
enablePreview: !0
|
|
119
|
-
},
|
|
119
|
+
}, z = {
|
|
120
120
|
1: {
|
|
121
121
|
tools: [
|
|
122
122
|
"customStop",
|
|
@@ -129,20 +129,20 @@ const f = {
|
|
|
129
129
|
"upload",
|
|
130
130
|
"ignore"
|
|
131
131
|
],
|
|
132
|
-
languages:
|
|
132
|
+
languages: x.filter((e) => ["zh", "en"].includes(e.value))
|
|
133
133
|
},
|
|
134
|
-
2:
|
|
135
|
-
3: { tools:
|
|
136
|
-
},
|
|
137
|
-
const n =
|
|
134
|
+
2: m,
|
|
135
|
+
3: { tools: R.filter((e) => e !== p.language.type) }
|
|
136
|
+
}, He = (e, t = {}) => {
|
|
137
|
+
const n = z[e] ?? m;
|
|
138
138
|
return {
|
|
139
|
-
...
|
|
139
|
+
...m,
|
|
140
140
|
...n,
|
|
141
141
|
...t,
|
|
142
|
-
tools: t.tools ?? n.tools ??
|
|
143
|
-
languages: t.languages ?? n.languages ??
|
|
142
|
+
tools: t.tools ?? n.tools ?? m.tools,
|
|
143
|
+
languages: t.languages ?? n.languages ?? m.languages
|
|
144
144
|
};
|
|
145
|
-
},
|
|
145
|
+
}, Ve = () => ({
|
|
146
146
|
type: "doc",
|
|
147
147
|
content: [
|
|
148
148
|
{
|
|
@@ -150,13 +150,13 @@ const f = {
|
|
|
150
150
|
content: []
|
|
151
151
|
}
|
|
152
152
|
]
|
|
153
|
-
}),
|
|
153
|
+
}), G = /[\u4e00-\u9fff]/, X = /\s/g, Y = 0.28, K = 0.14, ke = (e, t = 1) => {
|
|
154
154
|
const n = Number.isFinite(t) && t > 0 ? t : 1;
|
|
155
|
-
return Array.from(e.replace(
|
|
156
|
-
(
|
|
155
|
+
return Array.from(e.replace(X, "")).reduce(
|
|
156
|
+
(l, s) => l + (G.test(s) ? Y : K),
|
|
157
157
|
0
|
|
158
158
|
) / n;
|
|
159
|
-
},
|
|
159
|
+
}, M = {
|
|
160
160
|
0: "零",
|
|
161
161
|
1: "一",
|
|
162
162
|
2: "二",
|
|
@@ -167,7 +167,7 @@ const f = {
|
|
|
167
167
|
7: "七",
|
|
168
168
|
8: "八",
|
|
169
169
|
9: "九"
|
|
170
|
-
},
|
|
170
|
+
}, W = {
|
|
171
171
|
0: "洞",
|
|
172
172
|
1: "幺",
|
|
173
173
|
2: "二",
|
|
@@ -178,49 +178,49 @@ const f = {
|
|
|
178
178
|
7: "七",
|
|
179
179
|
8: "八",
|
|
180
180
|
9: "九"
|
|
181
|
-
},
|
|
182
|
-
function
|
|
183
|
-
return e ? e.split("").map((t) =>
|
|
181
|
+
}, q = ["", "十", "百", "千"], J = ["", "万", "亿", "万亿"];
|
|
182
|
+
function Z(e) {
|
|
183
|
+
return e ? e.split("").map((t) => M[t] || t).join("") : "";
|
|
184
184
|
}
|
|
185
|
-
function
|
|
186
|
-
return e ? e.split("").map((t) =>
|
|
185
|
+
function Ue(e) {
|
|
186
|
+
return e ? e.split("").map((t) => W[t] || t).join("") : "";
|
|
187
187
|
}
|
|
188
|
-
function
|
|
188
|
+
function Q(e) {
|
|
189
189
|
const t = e.length;
|
|
190
190
|
let n = "", o = !1;
|
|
191
|
-
for (let
|
|
192
|
-
const
|
|
193
|
-
|
|
191
|
+
for (let l = 0; l < t; l++) {
|
|
192
|
+
const s = e[l], r = t - 1 - l;
|
|
193
|
+
s === "0" ? !o && n !== "" && (o = !0) : (o && (n += "零", o = !1), n += M[s] + q[r]);
|
|
194
194
|
}
|
|
195
195
|
return n.startsWith("一十") && n.length === 2 && (n = n.substring(1)), n;
|
|
196
196
|
}
|
|
197
|
-
function
|
|
197
|
+
function O(e) {
|
|
198
198
|
if (!e) return "";
|
|
199
199
|
if (e === "0" || (e = e.replace(/^0+/, "") || "0", e === "0")) return "零";
|
|
200
200
|
let t = "";
|
|
201
201
|
const n = e.length, o = [];
|
|
202
|
-
for (let
|
|
203
|
-
const
|
|
204
|
-
o.unshift(e.substring(
|
|
202
|
+
for (let l = n; l > 0; l -= 4) {
|
|
203
|
+
const s = Math.max(0, l - 4);
|
|
204
|
+
o.unshift(e.substring(s, l));
|
|
205
205
|
}
|
|
206
|
-
for (let
|
|
207
|
-
const
|
|
206
|
+
for (let l = 0; l < o.length; l++) {
|
|
207
|
+
const s = o[l], r = Q(s);
|
|
208
208
|
if (r !== "") {
|
|
209
|
-
const
|
|
210
|
-
t += r +
|
|
209
|
+
const i = o.length - 1 - l;
|
|
210
|
+
t += r + J[i];
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
return t;
|
|
214
214
|
}
|
|
215
|
-
function
|
|
216
|
-
return
|
|
215
|
+
function ee(e) {
|
|
216
|
+
return O(e);
|
|
217
217
|
}
|
|
218
|
-
const
|
|
219
|
-
{ label: "基数读法", func:
|
|
218
|
+
const je = [
|
|
219
|
+
{ label: "基数读法", func: Z },
|
|
220
220
|
// { label: '位数读法', func: toPhoneReading },
|
|
221
|
-
{ label: "位数读法", func:
|
|
222
|
-
{ label: "口语读法", func:
|
|
223
|
-
],
|
|
221
|
+
{ label: "位数读法", func: O },
|
|
222
|
+
{ label: "口语读法", func: ee }
|
|
223
|
+
], te = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u00AD\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFE00-\uFE0F\uFEFF\uFFFD\uE000-\uF8FF]/g, ne = /[\t\f\v\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, P = {
|
|
224
224
|
"‘": "'",
|
|
225
225
|
"’": "'",
|
|
226
226
|
"‚": "'",
|
|
@@ -252,324 +252,444 @@ const Le = [
|
|
|
252
252
|
"︔": ";",
|
|
253
253
|
"︕": "!",
|
|
254
254
|
"︖": "?"
|
|
255
|
-
},
|
|
255
|
+
}, oe = new RegExp(`[${Object.keys(P).join("")}]`, "g"), re = (e) => e.replace(/[\uFF21-\uFF3A\uFF41-\uFF5A\uFF10-\uFF19]/g, (t) => String.fromCharCode(t.charCodeAt(0) - 65248)), se = (e) => re(e).replace(/\r\n?/g, `
|
|
256
256
|
`).replace(/[\u2028\u2029]/g, `
|
|
257
|
-
`).replace(
|
|
257
|
+
`).replace(te, "").replace(ne, " ").replace(oe, (t) => P[t] || "").replace(/ *\n */g, `
|
|
258
258
|
`).replace(/\n{3,}/g, `
|
|
259
259
|
|
|
260
|
-
`),
|
|
260
|
+
`), ze = (e) => {
|
|
261
261
|
if (typeof window > "u" || !e)
|
|
262
262
|
return e;
|
|
263
263
|
const n = new DOMParser().parseFromString(e, "text/html"), o = n.createTreeWalker(n.body, NodeFilter.SHOW_TEXT);
|
|
264
|
-
let
|
|
265
|
-
for (;
|
|
266
|
-
|
|
264
|
+
let l = o.nextNode();
|
|
265
|
+
for (; l; )
|
|
266
|
+
l.textContent = se(l.textContent || ""), l = o.nextNode();
|
|
267
267
|
return n.body.innerHTML;
|
|
268
|
-
},
|
|
268
|
+
}, ie = {
|
|
269
269
|
minSegmentLength: 32,
|
|
270
270
|
maxSegmentLength: 128,
|
|
271
271
|
rebalanceRatio: 0.4
|
|
272
|
-
},
|
|
272
|
+
}, A = /[一-鿿㐀-䶿豈- -〿-]/, le = /[。!?!?\.]/, ae = /[;;]/, ce = /[,,、::]/, ue = /[。!?!?,,、;;::]/, C = "", y = "", T = (e) => {
|
|
273
273
|
let t = 0;
|
|
274
274
|
for (const n of e)
|
|
275
|
-
t +=
|
|
275
|
+
t += A.test(n) ? 2 : 1;
|
|
276
276
|
return t;
|
|
277
|
-
},
|
|
278
|
-
`).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(),
|
|
277
|
+
}, ge = (e) => e.replace(/\r/g, "").split(`
|
|
278
|
+
`).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), pe = (e) => {
|
|
279
279
|
let t = e, n = "";
|
|
280
280
|
for (; n !== t; )
|
|
281
|
-
n = t, t = t.replace(/(\d),(\d)/g, `$1${
|
|
281
|
+
n = t, t = t.replace(/(\d),(\d)/g, `$1${C}$2`);
|
|
282
282
|
for (n = ""; n !== t; )
|
|
283
|
-
n = t, t = t.replace(/(\d)\.(\d)/g, `$1${
|
|
283
|
+
n = t, t = t.replace(/(\d)\.(\d)/g, `$1${y}$2`);
|
|
284
284
|
return t;
|
|
285
|
-
},
|
|
286
|
-
let
|
|
287
|
-
const
|
|
288
|
-
for (let
|
|
289
|
-
if (!
|
|
285
|
+
}, N = (e) => e.split(C).join(",").split(y).join("."), he = (e, t, n, o, l) => {
|
|
286
|
+
let s = -1, r = Number.POSITIVE_INFINITY;
|
|
287
|
+
const i = Math.max(1, n), c = Math.min(e.length, o);
|
|
288
|
+
for (let a = i; a <= c; a += 1) {
|
|
289
|
+
if (!l.test(e[a - 1]))
|
|
290
290
|
continue;
|
|
291
|
-
const u = Math.abs(
|
|
292
|
-
if (u < r && (r = u,
|
|
291
|
+
const u = Math.abs(a - t);
|
|
292
|
+
if (u < r && (r = u, s = a), a > t && s >= 0)
|
|
293
293
|
break;
|
|
294
294
|
}
|
|
295
|
-
return
|
|
296
|
-
},
|
|
297
|
-
let
|
|
298
|
-
const r = Math.max(1, n),
|
|
299
|
-
for (let c = r; c <=
|
|
295
|
+
return s;
|
|
296
|
+
}, fe = (e, t, n, o) => {
|
|
297
|
+
let l = -1, s = Number.POSITIVE_INFINITY;
|
|
298
|
+
const r = Math.max(1, n), i = Math.min(e.length, o);
|
|
299
|
+
for (let c = r; c <= i; c += 1) {
|
|
300
300
|
if (e[c - 1] !== " ")
|
|
301
301
|
continue;
|
|
302
|
-
const
|
|
303
|
-
if (
|
|
302
|
+
const a = Math.abs(c - t);
|
|
303
|
+
if (a < s && (s = a, l = c), c > t && l >= 0)
|
|
304
304
|
break;
|
|
305
305
|
}
|
|
306
|
-
return
|
|
307
|
-
},
|
|
308
|
-
for (const
|
|
309
|
-
const r =
|
|
306
|
+
return l;
|
|
307
|
+
}, v = (e, t, n, o, l) => {
|
|
308
|
+
for (const s of l) {
|
|
309
|
+
const r = he(
|
|
310
310
|
e,
|
|
311
311
|
t,
|
|
312
312
|
n,
|
|
313
313
|
o,
|
|
314
|
-
|
|
314
|
+
s
|
|
315
315
|
);
|
|
316
316
|
if (r >= 0)
|
|
317
317
|
return r;
|
|
318
318
|
}
|
|
319
|
-
return
|
|
320
|
-
},
|
|
319
|
+
return fe(e, t, n, o);
|
|
320
|
+
}, Ee = (e, t) => {
|
|
321
321
|
const n = [];
|
|
322
322
|
let o = e;
|
|
323
|
-
for (; o &&
|
|
324
|
-
const
|
|
325
|
-
let r = 0,
|
|
326
|
-
for (let
|
|
327
|
-
if (c +=
|
|
328
|
-
|
|
323
|
+
for (; o && T(o) > t; ) {
|
|
324
|
+
const l = T(o), s = Math.floor(l / 2);
|
|
325
|
+
let r = 0, i = 0, c = 0;
|
|
326
|
+
for (let g = 0; g < o.length; g += 1)
|
|
327
|
+
if (c += A.test(o[g]) ? 2 : 1, !r && c >= s && (r = g + 1), c >= t) {
|
|
328
|
+
i = g + 1;
|
|
329
329
|
break;
|
|
330
330
|
}
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
let u =
|
|
334
|
-
|
|
335
|
-
|
|
331
|
+
i || (i = o.length), r || (r = Math.floor(o.length / 2));
|
|
332
|
+
const a = Math.max(1, Math.floor(r / 3));
|
|
333
|
+
let u = v(o, r, a, i, [
|
|
334
|
+
ae,
|
|
335
|
+
ce
|
|
336
336
|
]);
|
|
337
337
|
(u < 0 || u >= o.length) && (u = r), n.push(o.slice(0, u)), o = o.slice(u);
|
|
338
338
|
}
|
|
339
339
|
return o.trim() && n.push(o), n;
|
|
340
|
-
},
|
|
340
|
+
}, de = (e, t) => {
|
|
341
341
|
if (e.length <= 1)
|
|
342
342
|
return e;
|
|
343
|
-
const n = e[e.length - 1], o = e.reduce((
|
|
344
|
-
if (n.length >=
|
|
343
|
+
const n = e[e.length - 1], o = e.reduce((g, E) => g + E.length, 0) / e.length, l = Math.floor(o * t);
|
|
344
|
+
if (n.length >= l)
|
|
345
345
|
return e;
|
|
346
|
-
const r = `${e[e.length - 2]}${n}`,
|
|
347
|
-
|
|
346
|
+
const r = `${e[e.length - 2]}${n}`, i = Math.floor(r.length / 2), c = Math.max(1, Math.floor(i / 3)), a = v(r, i, c, r.length, [
|
|
347
|
+
ue
|
|
348
348
|
]);
|
|
349
|
-
if (
|
|
349
|
+
if (a <= 0 || a >= r.length)
|
|
350
350
|
return e;
|
|
351
351
|
const u = [...e];
|
|
352
|
-
return u[u.length - 2] = r.slice(0,
|
|
353
|
-
},
|
|
352
|
+
return u[u.length - 2] = r.slice(0, a), u[u.length - 1] = r.slice(a), u.filter(Boolean);
|
|
353
|
+
}, Te = (e, t = {}) => {
|
|
354
354
|
const n = {
|
|
355
|
-
...
|
|
355
|
+
...ie,
|
|
356
356
|
...t
|
|
357
|
-
}, o =
|
|
357
|
+
}, o = ge(e);
|
|
358
358
|
if (!o)
|
|
359
359
|
return [];
|
|
360
|
-
const
|
|
361
|
-
if (
|
|
362
|
-
return [
|
|
363
|
-
const
|
|
364
|
-
let
|
|
365
|
-
for (const
|
|
366
|
-
if (!
|
|
360
|
+
const l = pe(o);
|
|
361
|
+
if (T(l) <= n.minSegmentLength)
|
|
362
|
+
return [N(l)];
|
|
363
|
+
const s = [], r = l.split(new RegExp("(?<=[。!?!?\\.])"));
|
|
364
|
+
let i = "";
|
|
365
|
+
for (const a of r) {
|
|
366
|
+
if (!a)
|
|
367
|
+
continue;
|
|
368
|
+
i += a;
|
|
369
|
+
const u = i[i.length - 1] ?? "";
|
|
370
|
+
T(i) >= n.minSegmentLength && le.test(u) && (s.push(i), i = "");
|
|
371
|
+
}
|
|
372
|
+
i && (s.length > 0 && T(i) < n.minSegmentLength ? s[s.length - 1] += i : s.push(i));
|
|
373
|
+
const c = s.flatMap((a) => T(a) <= n.maxSegmentLength ? [a] : Ee(a, n.maxSegmentLength));
|
|
374
|
+
return de(c, n.rebalanceRatio).map(
|
|
375
|
+
N
|
|
376
|
+
);
|
|
377
|
+
}, d = {
|
|
378
|
+
minSegmentLength: 32,
|
|
379
|
+
maxSegmentLength: 64,
|
|
380
|
+
rebalanceRatio: 0.4
|
|
381
|
+
}, F = /[一-鿿㐀-䶿豈- -〿-]/, $ = /[。!?!?\.]/, D = /[;;]/, B = /[,,::]/, me = /[、]/, w = "", H = "", f = (e) => {
|
|
382
|
+
let t = 0;
|
|
383
|
+
for (const n of e)
|
|
384
|
+
t += F.test(n) ? 2 : 1;
|
|
385
|
+
return t;
|
|
386
|
+
}, be = (e) => e.replace(/\r/g, "").split(`
|
|
387
|
+
`).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), _e = (e) => {
|
|
388
|
+
let t = e, n = "";
|
|
389
|
+
for (; n !== t; )
|
|
390
|
+
n = t, t = t.replace(/(\d),(\d)/g, `$1${w}$2`);
|
|
391
|
+
for (n = ""; n !== t; )
|
|
392
|
+
n = t, t = t.replace(/(\d)\.(\d)/g, `$1${H}$2`);
|
|
393
|
+
return t;
|
|
394
|
+
}, L = (e) => e.split(w).join(",").split(H).join("."), _ = (e, t) => {
|
|
395
|
+
let n = 0;
|
|
396
|
+
for (let o = 0; o < e.length; o += 1)
|
|
397
|
+
if (n += F.test(e[o]) ? 2 : 1, n >= t)
|
|
398
|
+
return o + 1;
|
|
399
|
+
return e.length;
|
|
400
|
+
}, I = (e, t, n, o, l) => {
|
|
401
|
+
let s = -1, r = Number.POSITIVE_INFINITY;
|
|
402
|
+
const i = Math.max(1, n), c = Math.min(e.length - 1, o);
|
|
403
|
+
for (let a = i; a <= c; a += 1) {
|
|
404
|
+
if (!l.test(e[a - 1]))
|
|
367
405
|
continue;
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
406
|
+
const u = Math.abs(a - t);
|
|
407
|
+
if (u < r && (r = u, s = a), a > t && s >= 0)
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
return s;
|
|
411
|
+
}, Ne = (e, t, n, o) => {
|
|
412
|
+
let l = -1, s = Number.POSITIVE_INFINITY;
|
|
413
|
+
const r = Math.max(1, n), i = Math.min(e.length - 1, o);
|
|
414
|
+
for (let c = r; c <= i; c += 1) {
|
|
415
|
+
if (e[c - 1] !== " ")
|
|
416
|
+
continue;
|
|
417
|
+
const a = Math.abs(c - t);
|
|
418
|
+
if (a < s && (s = a, l = c), c > t && l >= 0)
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
return l;
|
|
422
|
+
}, V = (e, t, n, o, l) => {
|
|
423
|
+
for (const r of l) {
|
|
424
|
+
const i = I(
|
|
425
|
+
e,
|
|
426
|
+
t,
|
|
427
|
+
n,
|
|
428
|
+
o,
|
|
429
|
+
r
|
|
430
|
+
);
|
|
431
|
+
if (i >= 0)
|
|
432
|
+
return i;
|
|
371
433
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
434
|
+
const s = Ne(e, t, n, o);
|
|
435
|
+
return s >= 0 ? s : I(
|
|
436
|
+
e,
|
|
437
|
+
t,
|
|
438
|
+
n,
|
|
439
|
+
o,
|
|
440
|
+
me
|
|
376
441
|
);
|
|
377
|
-
},
|
|
442
|
+
}, Le = (e, t) => {
|
|
443
|
+
const n = [];
|
|
444
|
+
let o = e.trim();
|
|
445
|
+
for (; o && f(o) > t; ) {
|
|
446
|
+
const l = f(o), s = Math.min(Math.floor(l / 2), t), r = _(o, s), i = Math.max(1, Math.floor(r / 3)), c = Math.max(
|
|
447
|
+
r + 1,
|
|
448
|
+
_(o, t)
|
|
449
|
+
);
|
|
450
|
+
let a = V(o, r, i, c, [
|
|
451
|
+
D,
|
|
452
|
+
B
|
|
453
|
+
]);
|
|
454
|
+
(a < 0 || a >= o.length) && (a = r), n.push(o.slice(0, a).trim()), o = o.slice(a).trim();
|
|
455
|
+
}
|
|
456
|
+
return o && n.push(o), n;
|
|
457
|
+
}, Ie = (e, t) => {
|
|
458
|
+
if (e.length <= 1)
|
|
459
|
+
return e;
|
|
460
|
+
const n = e[e.length - 1], o = e.reduce((E, b) => E + f(b), 0) / e.length, l = Math.floor(o * t);
|
|
461
|
+
if (f(n) >= l)
|
|
462
|
+
return e;
|
|
463
|
+
const r = `${e[e.length - 2]}${n}`, i = Math.floor(f(r) / 2), c = _(r, i), a = Math.max(1, Math.floor(c / 3));
|
|
464
|
+
let u = V(r, c, a, r.length, [
|
|
465
|
+
$,
|
|
466
|
+
D,
|
|
467
|
+
B
|
|
468
|
+
]);
|
|
469
|
+
if (u <= 0 || u >= r.length)
|
|
470
|
+
return e;
|
|
471
|
+
const g = [...e];
|
|
472
|
+
return g[g.length - 2] = r.slice(0, u).trim(), g[g.length - 1] = r.slice(u).trim(), g.filter(Boolean);
|
|
473
|
+
}, Se = (e) => {
|
|
474
|
+
const t = be(e);
|
|
475
|
+
if (!t)
|
|
476
|
+
return [];
|
|
477
|
+
const n = _e(t);
|
|
478
|
+
if (f(n) <= d.minSegmentLength)
|
|
479
|
+
return [L(n)];
|
|
480
|
+
const o = [], l = n.split(new RegExp("(?<=[。!?!?\\.])"));
|
|
481
|
+
let s = "";
|
|
482
|
+
for (const i of l) {
|
|
483
|
+
if (!i)
|
|
484
|
+
continue;
|
|
485
|
+
s += i;
|
|
486
|
+
const c = s[s.length - 1] ?? "";
|
|
487
|
+
f(s) >= d.minSegmentLength && $.test(c) && (o.push(s.trim()), s = "");
|
|
488
|
+
}
|
|
489
|
+
s && (o.length > 0 && f(s) < d.minSegmentLength ? o[o.length - 1] += s : o.push(s.trim()));
|
|
490
|
+
const r = o.flatMap((i) => f(i) <= d.maxSegmentLength ? [i] : Le(i, d.maxSegmentLength));
|
|
491
|
+
return Ie(
|
|
492
|
+
r,
|
|
493
|
+
d.rebalanceRatio
|
|
494
|
+
).map(L);
|
|
495
|
+
}, xe = (e, t = {}) => t.strategy === "legacy" ? Se(e) : Te(e, t), k = (e) => e.type === "text" ? e.text || "" : (e.content || []).map(k).join(""), Re = (e) => {
|
|
378
496
|
const t = e.content || [];
|
|
379
497
|
let n = "";
|
|
380
|
-
const o = [],
|
|
381
|
-
[
|
|
498
|
+
const o = [], l = [], s = {
|
|
499
|
+
[p.stop.type]: ({ position: r, actionCode: i }) => {
|
|
382
500
|
o.push({
|
|
383
501
|
action: "insert",
|
|
384
502
|
model: "control",
|
|
385
503
|
payload: "。 ",
|
|
386
504
|
position: r,
|
|
387
505
|
text: "",
|
|
388
|
-
actionCode:
|
|
506
|
+
actionCode: i
|
|
389
507
|
});
|
|
390
508
|
},
|
|
391
|
-
[
|
|
509
|
+
[p.customStop.type]: ({ payload: r, position: i, actionCode: c }) => {
|
|
392
510
|
o.push({
|
|
393
511
|
action: "insert",
|
|
394
512
|
model: "control",
|
|
395
513
|
payload: `[stop:${r == null ? void 0 : r.time}]`,
|
|
396
|
-
position:
|
|
514
|
+
position: i,
|
|
397
515
|
text: "",
|
|
398
516
|
actionCode: c
|
|
399
517
|
});
|
|
400
518
|
},
|
|
401
|
-
[
|
|
519
|
+
[p.continue.type]: ({ position: r, text: i, actionCode: c }) => {
|
|
402
520
|
o.push({
|
|
403
521
|
action: "replace",
|
|
404
522
|
model: "replace",
|
|
405
|
-
payload: `《${
|
|
523
|
+
payload: `《${i}》`,
|
|
406
524
|
position: r,
|
|
407
|
-
text:
|
|
525
|
+
text: i,
|
|
408
526
|
actionCode: c
|
|
409
527
|
});
|
|
410
528
|
},
|
|
411
|
-
[
|
|
529
|
+
[p.replace.type]: ({ payload: r, position: i, text: c, actionCode: a }) => {
|
|
412
530
|
o.push({
|
|
413
531
|
action: "replace",
|
|
414
532
|
model: "replace",
|
|
415
533
|
payload: `${r == null ? void 0 : r.text}`,
|
|
416
|
-
position:
|
|
534
|
+
position: i,
|
|
417
535
|
text: c,
|
|
418
|
-
actionCode:
|
|
536
|
+
actionCode: a
|
|
419
537
|
});
|
|
420
538
|
},
|
|
421
|
-
[
|
|
539
|
+
[p.pinyin.type]: ({ payload: r, position: i, text: c, actionCode: a }) => {
|
|
422
540
|
o.push({
|
|
423
541
|
action: "replace",
|
|
424
542
|
model: "pinyin",
|
|
425
543
|
payload: `${r == null ? void 0 : r.text}`,
|
|
426
|
-
position:
|
|
544
|
+
position: i,
|
|
427
545
|
text: c,
|
|
428
|
-
actionCode:
|
|
546
|
+
actionCode: a
|
|
429
547
|
});
|
|
430
548
|
},
|
|
431
|
-
[
|
|
549
|
+
[p.language.type]: ({ payload: r, position: i, text: c, actionCode: a }) => {
|
|
432
550
|
o.push({
|
|
433
551
|
action: "language",
|
|
434
552
|
model: "language",
|
|
435
553
|
payload: `${r == null ? void 0 : r.code}`,
|
|
436
|
-
position:
|
|
554
|
+
position: i,
|
|
437
555
|
text: c,
|
|
438
|
-
actionCode:
|
|
556
|
+
actionCode: a
|
|
439
557
|
});
|
|
440
558
|
},
|
|
441
|
-
[
|
|
559
|
+
[p.tone.type]: ({ payload: r, position: i, actionCode: c }) => {
|
|
442
560
|
var u;
|
|
443
|
-
const
|
|
444
|
-
|
|
561
|
+
const a = (u = U.find((g) => g.value === (r == null ? void 0 : r.code))) == null ? void 0 : u.tag;
|
|
562
|
+
a && o.push({
|
|
445
563
|
action: "insert",
|
|
446
564
|
model: "control",
|
|
447
|
-
payload:
|
|
448
|
-
position:
|
|
565
|
+
payload: a,
|
|
566
|
+
position: i,
|
|
449
567
|
text: "",
|
|
450
568
|
actionCode: c
|
|
451
569
|
});
|
|
452
570
|
},
|
|
453
|
-
[
|
|
571
|
+
[p.ignore.type]: ({ position: r, text: i, actionCode: c }) => {
|
|
454
572
|
o.push({
|
|
455
573
|
action: "replace",
|
|
456
574
|
model: "replace",
|
|
457
575
|
payload: " ",
|
|
458
576
|
position: r,
|
|
459
|
-
text:
|
|
577
|
+
text: i,
|
|
460
578
|
actionCode: c
|
|
461
579
|
});
|
|
462
580
|
}
|
|
463
581
|
};
|
|
464
582
|
return t.forEach((r) => {
|
|
465
|
-
var
|
|
583
|
+
var E, b;
|
|
466
584
|
if (r.type === "text") {
|
|
467
585
|
n += r.text || "";
|
|
468
586
|
return;
|
|
469
587
|
}
|
|
470
588
|
if (r.type !== "customTag") return;
|
|
471
|
-
const
|
|
472
|
-
u &&
|
|
473
|
-
start:
|
|
474
|
-
end:
|
|
475
|
-
}),
|
|
589
|
+
const i = (E = r.attrs) == null ? void 0 : E.categ, c = (b = r.attrs) == null ? void 0 : b.payload, a = n.length, u = k(r), g = s[i];
|
|
590
|
+
u && l.push({
|
|
591
|
+
start: a,
|
|
592
|
+
end: a + u.length
|
|
593
|
+
}), g && g({
|
|
476
594
|
payload: c,
|
|
477
|
-
position:
|
|
595
|
+
position: a,
|
|
478
596
|
text: u,
|
|
479
|
-
actionCode:
|
|
597
|
+
actionCode: i
|
|
480
598
|
}), n += u;
|
|
481
599
|
}), {
|
|
482
600
|
text: n,
|
|
483
|
-
protectedRanges:
|
|
601
|
+
protectedRanges: l,
|
|
484
602
|
playments: o
|
|
485
603
|
};
|
|
486
|
-
},
|
|
604
|
+
}, S = (e) => e.type === "text" || e.type === "customTag", Me = (e) => {
|
|
487
605
|
const t = e.content || [];
|
|
488
606
|
if (e.type === "paragraph") return [e];
|
|
489
607
|
if (e.type === "doc")
|
|
490
608
|
return t.filter((o) => o.type === "paragraph");
|
|
491
609
|
const n = t.filter((o) => o.type === "paragraph");
|
|
492
|
-
return n.length ? n : t.some(
|
|
610
|
+
return n.length ? n : t.some(S) ? [
|
|
493
611
|
{
|
|
494
612
|
type: "paragraph",
|
|
495
|
-
content: t.filter(
|
|
613
|
+
content: t.filter(S)
|
|
496
614
|
}
|
|
497
615
|
] : [];
|
|
498
|
-
},
|
|
616
|
+
}, Oe = (e, t) => {
|
|
499
617
|
let n = 0;
|
|
500
618
|
return t.map((o) => {
|
|
501
|
-
const
|
|
619
|
+
const l = e.indexOf(o, n), s = l >= 0 ? l : n, r = s + o.length;
|
|
502
620
|
return n = r, {
|
|
503
621
|
text: o,
|
|
504
|
-
start:
|
|
622
|
+
start: s,
|
|
505
623
|
end: r
|
|
506
624
|
};
|
|
507
625
|
});
|
|
508
|
-
},
|
|
626
|
+
}, Pe = (e, t) => e.reduce((n, o) => {
|
|
509
627
|
if (t.some(
|
|
510
|
-
(
|
|
628
|
+
(s) => o.start > s.start && o.start < s.end
|
|
511
629
|
) && n.length) {
|
|
512
|
-
const
|
|
513
|
-
return
|
|
630
|
+
const s = n[n.length - 1];
|
|
631
|
+
return s.text += o.text, s.end = o.end, n;
|
|
514
632
|
}
|
|
515
633
|
return n.push({ ...o }), n;
|
|
516
|
-
}, []),
|
|
517
|
-
const
|
|
518
|
-
if (
|
|
519
|
-
const
|
|
520
|
-
|
|
634
|
+
}, []), Ae = (e, t, n, o) => e.position >= t && e.position < n ? !0 : !e.text && o && e.position === n, Ce = (e, t) => {
|
|
635
|
+
const n = xe(e.text, t);
|
|
636
|
+
if (n.length <= 1) return [e];
|
|
637
|
+
const o = Pe(
|
|
638
|
+
Oe(e.text, n),
|
|
521
639
|
e.protectedRanges || []
|
|
522
640
|
);
|
|
523
|
-
return
|
|
524
|
-
const
|
|
525
|
-
(
|
|
526
|
-
).map((
|
|
527
|
-
...
|
|
528
|
-
position:
|
|
641
|
+
return o.map((l, s) => {
|
|
642
|
+
const r = s === o.length - 1, i = e.playments.filter(
|
|
643
|
+
(c) => Ae(c, l.start, l.end, r)
|
|
644
|
+
).map((c) => ({
|
|
645
|
+
...c,
|
|
646
|
+
position: c.position - l.start
|
|
529
647
|
}));
|
|
530
648
|
return {
|
|
531
|
-
text:
|
|
532
|
-
playments:
|
|
649
|
+
text: l.text,
|
|
650
|
+
playments: i
|
|
533
651
|
};
|
|
534
652
|
});
|
|
535
|
-
},
|
|
536
|
-
const
|
|
653
|
+
}, Ge = (e, t = {}) => {
|
|
654
|
+
const n = {
|
|
537
655
|
playments: [],
|
|
538
656
|
sentences: []
|
|
539
657
|
};
|
|
540
|
-
return
|
|
541
|
-
const s =
|
|
542
|
-
!s.text && !s.playments.length ||
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
658
|
+
return Me(e).forEach((l) => {
|
|
659
|
+
const s = Re(l);
|
|
660
|
+
!s.text && !s.playments.length || Ce(s, t).forEach(
|
|
661
|
+
({ text: r, playments: i }) => {
|
|
662
|
+
n.sentences.push(r), n.playments.push(i);
|
|
663
|
+
}
|
|
664
|
+
);
|
|
665
|
+
}), n;
|
|
546
666
|
};
|
|
547
667
|
export {
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
668
|
+
h as DeleteMode,
|
|
669
|
+
Fe as EditorConst,
|
|
670
|
+
x as LanguageOptions,
|
|
671
|
+
ve as MAX_LANGUAGE_SELECTION_LENGTH,
|
|
672
|
+
ye as MAX_REPLACEMENT_TEXT_LENGTH,
|
|
673
|
+
je as NumberToTextTools,
|
|
674
|
+
j as StopOptions,
|
|
675
|
+
U as ToneOptions,
|
|
676
|
+
p as ToolConfig,
|
|
677
|
+
R as allToolTypes,
|
|
678
|
+
Ge as convertToTtsFormat,
|
|
679
|
+
ke as estimateTtsDuration,
|
|
680
|
+
Be as getDefaultLockPayload,
|
|
681
|
+
Ve as getInitContent,
|
|
682
|
+
we as getLockPayloadLabel,
|
|
683
|
+
T as getVisualLength,
|
|
684
|
+
$e as isInsertTagType,
|
|
685
|
+
De as isLockableTagType,
|
|
686
|
+
He as resolveTtsEditorFeatures,
|
|
687
|
+
ze as sanitizePastedHtml,
|
|
688
|
+
se as sanitizePastedText,
|
|
689
|
+
xe as splitTextToSentences,
|
|
690
|
+
Z as toCardinal,
|
|
691
|
+
ee as toColloquial,
|
|
692
|
+
Ue as toPhoneReading,
|
|
693
|
+
O as toPositional,
|
|
694
|
+
Re as transformParagraph
|
|
575
695
|
};
|