@naersen/tts-rich-text 0.9.1 → 0.10.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 +11 -0
- package/README.md +10 -0
- package/dist/base.css +1 -1
- package/dist/components/tts-editor-root/index.vue.d.ts +2 -0
- package/dist/components/tts-rich-text/components/toolbar-popovers/language-popover.vue.d.ts +4 -1
- package/dist/components/tts-rich-text/editor/useEditorToolkit.d.ts +2 -0
- package/dist/components/tts-rich-text/editor/useRichTextEditor.d.ts +4 -0
- package/dist/components/tts-rich-text-editor/index.vue.d.ts +6 -0
- package/dist/core/config.d.ts +12 -3
- package/dist/core.js +265 -229
- package/dist/index.js +2519 -2483
- package/dist/type/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const f = {
|
|
2
2
|
DELETE_NODE: "deleteNode",
|
|
3
3
|
CONVERT_TO_TEXT: "convertToText"
|
|
4
4
|
}, p = {
|
|
@@ -6,37 +6,43 @@ const h = {
|
|
|
6
6
|
label: "停顿",
|
|
7
7
|
icon: "editor-stop",
|
|
8
8
|
type: "stop",
|
|
9
|
-
deleteMode:
|
|
9
|
+
deleteMode: f.DELETE_NODE
|
|
10
10
|
},
|
|
11
11
|
customStop: {
|
|
12
12
|
label: "长停顿",
|
|
13
13
|
icon: "editor-stop-long",
|
|
14
14
|
type: "customStop",
|
|
15
|
-
deleteMode:
|
|
15
|
+
deleteMode: f.DELETE_NODE
|
|
16
16
|
},
|
|
17
17
|
continue: {
|
|
18
18
|
label: "连续",
|
|
19
19
|
icon: "editor-continue",
|
|
20
20
|
type: "continue",
|
|
21
|
-
deleteMode:
|
|
21
|
+
deleteMode: f.CONVERT_TO_TEXT
|
|
22
22
|
},
|
|
23
23
|
pinyin: {
|
|
24
24
|
label: "拼音标注",
|
|
25
25
|
icon: "editor-pinyin",
|
|
26
26
|
type: "pinyin",
|
|
27
|
-
deleteMode:
|
|
27
|
+
deleteMode: f.CONVERT_TO_TEXT
|
|
28
28
|
},
|
|
29
29
|
replace: {
|
|
30
30
|
label: "替换",
|
|
31
31
|
icon: "editor-replace",
|
|
32
32
|
type: "replace",
|
|
33
|
-
deleteMode:
|
|
33
|
+
deleteMode: f.CONVERT_TO_TEXT
|
|
34
34
|
},
|
|
35
35
|
language: {
|
|
36
36
|
label: "语种标记",
|
|
37
37
|
icon: "editor-language",
|
|
38
38
|
type: "language",
|
|
39
|
-
deleteMode:
|
|
39
|
+
deleteMode: f.CONVERT_TO_TEXT
|
|
40
|
+
},
|
|
41
|
+
tone: {
|
|
42
|
+
label: "语气",
|
|
43
|
+
icon: "editor-tone",
|
|
44
|
+
type: "tone",
|
|
45
|
+
deleteMode: f.DELETE_NODE
|
|
40
46
|
},
|
|
41
47
|
number: {
|
|
42
48
|
label: "数字读法",
|
|
@@ -62,9 +68,24 @@ const h = {
|
|
|
62
68
|
label: "忽略读音",
|
|
63
69
|
icon: "editor-ingore",
|
|
64
70
|
type: "ignore",
|
|
65
|
-
deleteMode:
|
|
71
|
+
deleteMode: f.CONVERT_TO_TEXT
|
|
66
72
|
}
|
|
67
|
-
},
|
|
73
|
+
}, D = [
|
|
74
|
+
{ label: "笑声", value: "笑声", tag: "[laughter]" },
|
|
75
|
+
{ label: "叹气", value: "叹气", tag: "[sigh]" },
|
|
76
|
+
{ label: "吸气", value: "吸气", tag: "[sniff]" },
|
|
77
|
+
{ label: "确认", value: "确认", tag: "[confirmation-en]" },
|
|
78
|
+
{ label: "疑问", value: "疑问", tag: "[question-en]" },
|
|
79
|
+
{ label: "疑问(啊)", value: "疑问(啊)", tag: "[question-ah]" },
|
|
80
|
+
{ label: "疑问(哦)", value: "疑问(哦)", tag: "[question-oh]" },
|
|
81
|
+
{ label: "疑问(诶)", value: "疑问(诶)", tag: "[question-ei]" },
|
|
82
|
+
{ label: "疑问(咦)", value: "疑问(咦)", tag: "[question-yi]" },
|
|
83
|
+
{ label: "惊讶(啊)", value: "惊讶(啊)", tag: "[surprise-ah]" },
|
|
84
|
+
{ label: "惊讶(哦)", value: "惊讶(哦)", tag: "[surprise-oh]" },
|
|
85
|
+
{ label: "惊讶(哇)", value: "惊讶(哇)", tag: "[surprise-wa]" },
|
|
86
|
+
{ label: "惊讶(哟)", value: "惊讶(哟)", tag: "[surprise-yo]" },
|
|
87
|
+
{ label: "不满", value: "不满", tag: "[dissatisfaction-hnn]" }
|
|
88
|
+
], x = [
|
|
68
89
|
{ value: "zh", label: "中文" },
|
|
69
90
|
{ value: "en", label: "英语" },
|
|
70
91
|
{ value: "jp", label: "日语" },
|
|
@@ -75,10 +96,10 @@ const h = {
|
|
|
75
96
|
{ value: "it", label: "意大利语" },
|
|
76
97
|
{ value: "pt", label: "葡萄牙语" },
|
|
77
98
|
{ value: "ru", label: "俄语" }
|
|
78
|
-
],
|
|
99
|
+
], w = [
|
|
79
100
|
{ label: "停顿 0.5 秒", value: 0.5 },
|
|
80
101
|
{ label: "停顿 1 秒", value: 1 }
|
|
81
|
-
],
|
|
102
|
+
], fe = {
|
|
82
103
|
SENTENCE: "sentence",
|
|
83
104
|
CUSTOM_TAG: "customTag",
|
|
84
105
|
/**
|
|
@@ -86,16 +107,16 @@ const h = {
|
|
|
86
107
|
* 工具栏与右键面板都要用它来主动收起气泡,避免两个浮层叠在一起。
|
|
87
108
|
*/
|
|
88
109
|
BUBBLE_MENU_KEY: "ttsRichTextBubbleMenu"
|
|
89
|
-
},
|
|
90
|
-
var
|
|
91
|
-
return ((
|
|
92
|
-
},
|
|
93
|
-
tools:
|
|
110
|
+
}, he = (e) => {
|
|
111
|
+
var t;
|
|
112
|
+
return ((t = p[e]) == null ? void 0 : t.deleteMode) === f.DELETE_NODE;
|
|
113
|
+
}, de = (e) => e === p.stop.type || e === p.customStop.type, Te = (e) => e === p.customStop.type ? { time: w[0].value } : {}, Ee = (e, t) => e === p.customStop.type ? `${t == null ? void 0 : t.time} 秒` : "", y = Object.keys(p), d = {
|
|
114
|
+
tools: y.filter((e) => e !== p.tone.type),
|
|
94
115
|
languages: x,
|
|
95
116
|
maxPinyinLength: 4,
|
|
96
117
|
maxNumberLength: 16,
|
|
97
118
|
enablePreview: !0
|
|
98
|
-
},
|
|
119
|
+
}, B = {
|
|
99
120
|
1: {
|
|
100
121
|
tools: [
|
|
101
122
|
"customStop",
|
|
@@ -108,19 +129,20 @@ const h = {
|
|
|
108
129
|
"upload",
|
|
109
130
|
"ignore"
|
|
110
131
|
],
|
|
111
|
-
languages: x.filter((
|
|
132
|
+
languages: x.filter((e) => ["zh", "en"].includes(e.value))
|
|
112
133
|
},
|
|
113
|
-
2: d
|
|
114
|
-
|
|
115
|
-
|
|
134
|
+
2: d,
|
|
135
|
+
3: { tools: y.filter((e) => e !== p.language.type) }
|
|
136
|
+
}, me = (e, t = {}) => {
|
|
137
|
+
const n = B[e] ?? d;
|
|
116
138
|
return {
|
|
117
139
|
...d,
|
|
118
140
|
...n,
|
|
119
|
-
...
|
|
120
|
-
tools:
|
|
121
|
-
languages:
|
|
141
|
+
...t,
|
|
142
|
+
tools: t.tools ?? n.tools ?? d.tools,
|
|
143
|
+
languages: t.languages ?? n.languages ?? d.languages
|
|
122
144
|
};
|
|
123
|
-
},
|
|
145
|
+
}, be = () => ({
|
|
124
146
|
type: "doc",
|
|
125
147
|
content: [
|
|
126
148
|
{
|
|
@@ -128,10 +150,10 @@ const h = {
|
|
|
128
150
|
content: []
|
|
129
151
|
}
|
|
130
152
|
]
|
|
131
|
-
}),
|
|
132
|
-
const n = Number.isFinite(
|
|
133
|
-
return Array.from(
|
|
134
|
-
(s,
|
|
153
|
+
}), H = /[\u4e00-\u9fff]/, U = /\s/g, V = 0.28, $ = 0.14, _e = (e, t = 1) => {
|
|
154
|
+
const n = Number.isFinite(t) && t > 0 ? t : 1;
|
|
155
|
+
return Array.from(e.replace(U, "")).reduce(
|
|
156
|
+
(s, l) => s + (H.test(l) ? V : $),
|
|
135
157
|
0
|
|
136
158
|
) / n;
|
|
137
159
|
}, R = {
|
|
@@ -145,7 +167,7 @@ const h = {
|
|
|
145
167
|
7: "七",
|
|
146
168
|
8: "八",
|
|
147
169
|
9: "九"
|
|
148
|
-
},
|
|
170
|
+
}, k = {
|
|
149
171
|
0: "洞",
|
|
150
172
|
1: "幺",
|
|
151
173
|
2: "二",
|
|
@@ -156,49 +178,49 @@ const h = {
|
|
|
156
178
|
7: "七",
|
|
157
179
|
8: "八",
|
|
158
180
|
9: "九"
|
|
159
|
-
},
|
|
160
|
-
function
|
|
161
|
-
return
|
|
181
|
+
}, j = ["", "十", "百", "千"], X = ["", "万", "亿", "万亿"];
|
|
182
|
+
function z(e) {
|
|
183
|
+
return e ? e.split("").map((t) => R[t] || t).join("") : "";
|
|
162
184
|
}
|
|
163
|
-
function
|
|
164
|
-
return
|
|
185
|
+
function Ne(e) {
|
|
186
|
+
return e ? e.split("").map((t) => k[t] || t).join("") : "";
|
|
165
187
|
}
|
|
166
|
-
function
|
|
167
|
-
const
|
|
188
|
+
function G(e) {
|
|
189
|
+
const t = e.length;
|
|
168
190
|
let n = "", o = !1;
|
|
169
|
-
for (let s = 0; s <
|
|
170
|
-
const
|
|
171
|
-
|
|
191
|
+
for (let s = 0; s < t; s++) {
|
|
192
|
+
const l = e[s], r = t - 1 - s;
|
|
193
|
+
l === "0" ? !o && n !== "" && (o = !0) : (o && (n += "零", o = !1), n += R[l] + j[r]);
|
|
172
194
|
}
|
|
173
195
|
return n.startsWith("一十") && n.length === 2 && (n = n.substring(1)), n;
|
|
174
196
|
}
|
|
175
|
-
function
|
|
176
|
-
if (!
|
|
177
|
-
if (
|
|
178
|
-
let
|
|
179
|
-
const n =
|
|
197
|
+
function O(e) {
|
|
198
|
+
if (!e) return "";
|
|
199
|
+
if (e === "0" || (e = e.replace(/^0+/, "") || "0", e === "0")) return "零";
|
|
200
|
+
let t = "";
|
|
201
|
+
const n = e.length, o = [];
|
|
180
202
|
for (let s = n; s > 0; s -= 4) {
|
|
181
|
-
const
|
|
182
|
-
o.unshift(
|
|
203
|
+
const l = Math.max(0, s - 4);
|
|
204
|
+
o.unshift(e.substring(l, s));
|
|
183
205
|
}
|
|
184
206
|
for (let s = 0; s < o.length; s++) {
|
|
185
|
-
const
|
|
207
|
+
const l = o[s], r = G(l);
|
|
186
208
|
if (r !== "") {
|
|
187
|
-
const
|
|
188
|
-
|
|
209
|
+
const a = o.length - 1 - s;
|
|
210
|
+
t += r + X[a];
|
|
189
211
|
}
|
|
190
212
|
}
|
|
191
|
-
return
|
|
213
|
+
return t;
|
|
192
214
|
}
|
|
193
|
-
function
|
|
194
|
-
return
|
|
215
|
+
function q(e) {
|
|
216
|
+
return O(e);
|
|
195
217
|
}
|
|
196
|
-
const
|
|
197
|
-
{ label: "基数读法", func:
|
|
218
|
+
const xe = [
|
|
219
|
+
{ label: "基数读法", func: z },
|
|
198
220
|
// { label: '位数读法', func: toPhoneReading },
|
|
199
|
-
{ label: "位数读法", func:
|
|
200
|
-
{ label: "口语读法", func:
|
|
201
|
-
], W = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u00AD\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFE00-\uFE0F\uFEFF\uFFFD\uE000-\uF8FF]/g, Y = /[\t\f\v\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g,
|
|
221
|
+
{ label: "位数读法", func: O },
|
|
222
|
+
{ label: "口语读法", func: q }
|
|
223
|
+
], W = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u00AD\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFE00-\uFE0F\uFEFF\uFFFD\uE000-\uF8FF]/g, Y = /[\t\f\v\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, L = {
|
|
202
224
|
"‘": "'",
|
|
203
225
|
"’": "'",
|
|
204
226
|
"‚": "'",
|
|
@@ -230,319 +252,333 @@ const _t = [
|
|
|
230
252
|
"︔": ";",
|
|
231
253
|
"︕": "!",
|
|
232
254
|
"︖": "?"
|
|
233
|
-
}, K = new RegExp(`[${Object.keys(
|
|
255
|
+
}, K = new RegExp(`[${Object.keys(L).join("")}]`, "g"), J = (e) => e.replace(/[\uFF21-\uFF3A\uFF41-\uFF5A\uFF10-\uFF19]/g, (t) => String.fromCharCode(t.charCodeAt(0) - 65248)), Z = (e) => J(e).replace(/\r\n?/g, `
|
|
234
256
|
`).replace(/[\u2028\u2029]/g, `
|
|
235
|
-
`).replace(W, "").replace(Y, " ").replace(K, (
|
|
257
|
+
`).replace(W, "").replace(Y, " ").replace(K, (t) => L[t] || "").replace(/ *\n */g, `
|
|
236
258
|
`).replace(/\n{3,}/g, `
|
|
237
259
|
|
|
238
|
-
`),
|
|
239
|
-
if (typeof window > "u" || !
|
|
240
|
-
return
|
|
241
|
-
const n = new DOMParser().parseFromString(
|
|
260
|
+
`), ye = (e) => {
|
|
261
|
+
if (typeof window > "u" || !e)
|
|
262
|
+
return e;
|
|
263
|
+
const n = new DOMParser().parseFromString(e, "text/html"), o = n.createTreeWalker(n.body, NodeFilter.SHOW_TEXT);
|
|
242
264
|
let s = o.nextNode();
|
|
243
265
|
for (; s; )
|
|
244
|
-
s.textContent =
|
|
266
|
+
s.textContent = Z(s.textContent || ""), s = o.nextNode();
|
|
245
267
|
return n.body.innerHTML;
|
|
246
|
-
},
|
|
268
|
+
}, Q = {
|
|
247
269
|
minSegmentLength: 32,
|
|
248
270
|
maxSegmentLength: 64,
|
|
249
271
|
rebalanceRatio: 0.4
|
|
250
|
-
}, I = /[一-鿿㐀-䶿豈- -〿-]/,
|
|
251
|
-
let
|
|
252
|
-
for (const n of
|
|
253
|
-
|
|
254
|
-
return
|
|
255
|
-
},
|
|
256
|
-
`).map((
|
|
257
|
-
let
|
|
258
|
-
for (; n !==
|
|
259
|
-
n =
|
|
260
|
-
for (n = ""; n !==
|
|
261
|
-
n =
|
|
262
|
-
return
|
|
263
|
-
}, b = (
|
|
272
|
+
}, I = /[一-鿿㐀-䶿豈- -〿-]/, C = /[。!?!?\.]/, P = /[;;]/, S = /[,,::]/, ee = /[、]/, v = "", F = "", h = (e) => {
|
|
273
|
+
let t = 0;
|
|
274
|
+
for (const n of e)
|
|
275
|
+
t += I.test(n) ? 2 : 1;
|
|
276
|
+
return t;
|
|
277
|
+
}, te = (e) => e.replace(/\r/g, "").split(`
|
|
278
|
+
`).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), ne = (e) => {
|
|
279
|
+
let t = e, n = "";
|
|
280
|
+
for (; n !== t; )
|
|
281
|
+
n = t, t = t.replace(/(\d),(\d)/g, `$1${v}$2`);
|
|
282
|
+
for (n = ""; n !== t; )
|
|
283
|
+
n = t, t = t.replace(/(\d)\.(\d)/g, `$1${F}$2`);
|
|
284
|
+
return t;
|
|
285
|
+
}, b = (e) => e.split(v).join(",").split(F).join("."), m = (e, t) => {
|
|
264
286
|
let n = 0;
|
|
265
|
-
for (let o = 0; o <
|
|
266
|
-
if (n += I.test(
|
|
287
|
+
for (let o = 0; o < e.length; o += 1)
|
|
288
|
+
if (n += I.test(e[o]) ? 2 : 1, n >= t)
|
|
267
289
|
return o + 1;
|
|
268
|
-
return
|
|
269
|
-
}, _ = (
|
|
270
|
-
let
|
|
271
|
-
const
|
|
272
|
-
for (let
|
|
273
|
-
if (!s.test(
|
|
290
|
+
return e.length;
|
|
291
|
+
}, _ = (e, t, n, o, s) => {
|
|
292
|
+
let l = -1, r = Number.POSITIVE_INFINITY;
|
|
293
|
+
const a = Math.max(1, n), c = Math.min(e.length - 1, o);
|
|
294
|
+
for (let i = a; i <= c; i += 1) {
|
|
295
|
+
if (!s.test(e[i - 1]))
|
|
274
296
|
continue;
|
|
275
|
-
const u = Math.abs(
|
|
276
|
-
if (u < r && (r = u,
|
|
297
|
+
const u = Math.abs(i - t);
|
|
298
|
+
if (u < r && (r = u, l = i), i > t && l >= 0)
|
|
277
299
|
break;
|
|
278
300
|
}
|
|
279
|
-
return
|
|
280
|
-
},
|
|
281
|
-
let s = -1,
|
|
282
|
-
const r = Math.max(1, n),
|
|
283
|
-
for (let c = r; c <=
|
|
284
|
-
if (
|
|
301
|
+
return l;
|
|
302
|
+
}, oe = (e, t, n, o) => {
|
|
303
|
+
let s = -1, l = Number.POSITIVE_INFINITY;
|
|
304
|
+
const r = Math.max(1, n), a = Math.min(e.length - 1, o);
|
|
305
|
+
for (let c = r; c <= a; c += 1) {
|
|
306
|
+
if (e[c - 1] !== " ")
|
|
285
307
|
continue;
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
308
|
+
const i = Math.abs(c - t);
|
|
309
|
+
if (i < l && (l = i, s = c), c > t && s >= 0)
|
|
288
310
|
break;
|
|
289
311
|
}
|
|
290
312
|
return s;
|
|
291
|
-
}, M = (
|
|
313
|
+
}, M = (e, t, n, o, s) => {
|
|
292
314
|
for (const r of s) {
|
|
293
|
-
const
|
|
294
|
-
t,
|
|
315
|
+
const a = _(
|
|
295
316
|
e,
|
|
317
|
+
t,
|
|
296
318
|
n,
|
|
297
319
|
o,
|
|
298
320
|
r
|
|
299
321
|
);
|
|
300
|
-
if (
|
|
301
|
-
return
|
|
322
|
+
if (a >= 0)
|
|
323
|
+
return a;
|
|
302
324
|
}
|
|
303
|
-
const
|
|
304
|
-
return
|
|
305
|
-
t,
|
|
325
|
+
const l = oe(e, t, n, o);
|
|
326
|
+
return l >= 0 ? l : _(
|
|
306
327
|
e,
|
|
328
|
+
t,
|
|
307
329
|
n,
|
|
308
330
|
o,
|
|
309
|
-
|
|
331
|
+
ee
|
|
310
332
|
);
|
|
311
|
-
},
|
|
333
|
+
}, re = (e, t) => {
|
|
312
334
|
const n = [];
|
|
313
|
-
let o =
|
|
314
|
-
for (; o &&
|
|
315
|
-
const s =
|
|
335
|
+
let o = e.trim();
|
|
336
|
+
for (; o && h(o) > t; ) {
|
|
337
|
+
const s = h(o), l = Math.min(Math.floor(s / 2), t), r = m(o, l), a = Math.max(1, Math.floor(r / 3)), c = Math.max(
|
|
316
338
|
r + 1,
|
|
317
|
-
m(o,
|
|
339
|
+
m(o, t)
|
|
318
340
|
);
|
|
319
|
-
let
|
|
320
|
-
|
|
321
|
-
|
|
341
|
+
let i = M(o, r, a, c, [
|
|
342
|
+
P,
|
|
343
|
+
S
|
|
322
344
|
]);
|
|
323
|
-
(
|
|
345
|
+
(i < 0 || i >= o.length) && (i = r), n.push(o.slice(0, i).trim()), o = o.slice(i).trim();
|
|
324
346
|
}
|
|
325
347
|
return o && n.push(o), n;
|
|
326
|
-
},
|
|
327
|
-
if (
|
|
328
|
-
return
|
|
329
|
-
const n =
|
|
330
|
-
if (
|
|
331
|
-
return
|
|
332
|
-
const r = `${
|
|
333
|
-
let u = M(r, c,
|
|
334
|
-
L,
|
|
348
|
+
}, se = (e, t) => {
|
|
349
|
+
if (e.length <= 1)
|
|
350
|
+
return e;
|
|
351
|
+
const n = e[e.length - 1], o = e.reduce((T, E) => T + h(E), 0) / e.length, s = Math.floor(o * t);
|
|
352
|
+
if (h(n) >= s)
|
|
353
|
+
return e;
|
|
354
|
+
const r = `${e[e.length - 2]}${n}`, a = Math.floor(h(r) / 2), c = m(r, a), i = Math.max(1, Math.floor(c / 3));
|
|
355
|
+
let u = M(r, c, i, r.length, [
|
|
335
356
|
C,
|
|
336
|
-
P
|
|
357
|
+
P,
|
|
358
|
+
S
|
|
337
359
|
]);
|
|
338
360
|
if (u <= 0 || u >= r.length)
|
|
339
|
-
return
|
|
340
|
-
const
|
|
341
|
-
return
|
|
342
|
-
},
|
|
361
|
+
return e;
|
|
362
|
+
const g = [...e];
|
|
363
|
+
return g[g.length - 2] = r.slice(0, u).trim(), g[g.length - 1] = r.slice(u).trim(), g.filter(Boolean);
|
|
364
|
+
}, ae = (e, t = {}) => {
|
|
343
365
|
const n = {
|
|
344
|
-
...
|
|
345
|
-
...
|
|
346
|
-
}, o =
|
|
366
|
+
...Q,
|
|
367
|
+
...t
|
|
368
|
+
}, o = te(e);
|
|
347
369
|
if (!o)
|
|
348
370
|
return [];
|
|
349
|
-
const s =
|
|
350
|
-
if (
|
|
371
|
+
const s = ne(o);
|
|
372
|
+
if (h(s) <= n.minSegmentLength)
|
|
351
373
|
return [b(s)];
|
|
352
|
-
const
|
|
353
|
-
let
|
|
354
|
-
for (const
|
|
355
|
-
if (!
|
|
374
|
+
const l = [], r = s.split(new RegExp("(?<=[。!?!?\\.])"));
|
|
375
|
+
let a = "";
|
|
376
|
+
for (const i of r) {
|
|
377
|
+
if (!i)
|
|
356
378
|
continue;
|
|
357
|
-
|
|
358
|
-
const u =
|
|
359
|
-
|
|
379
|
+
a += i;
|
|
380
|
+
const u = a[a.length - 1] ?? "";
|
|
381
|
+
h(a) >= n.minSegmentLength && C.test(u) && (l.push(a.trim()), a = "");
|
|
360
382
|
}
|
|
361
|
-
|
|
362
|
-
const c =
|
|
363
|
-
return
|
|
383
|
+
a && (l.length > 0 && h(a) < n.minSegmentLength ? l[l.length - 1] += a : l.push(a.trim()));
|
|
384
|
+
const c = l.flatMap((i) => h(i) <= n.maxSegmentLength ? [i] : re(i, n.maxSegmentLength));
|
|
385
|
+
return se(c, n.rebalanceRatio).map(
|
|
364
386
|
b
|
|
365
387
|
);
|
|
366
|
-
}, A = (
|
|
367
|
-
const
|
|
388
|
+
}, A = (e) => e.type === "text" ? e.text || "" : (e.content || []).map(A).join(""), le = (e) => {
|
|
389
|
+
const t = e.content || [];
|
|
368
390
|
let n = "";
|
|
369
|
-
const o = [], s = [],
|
|
370
|
-
[p.stop.type]: ({ position: r, actionCode:
|
|
391
|
+
const o = [], s = [], l = {
|
|
392
|
+
[p.stop.type]: ({ position: r, actionCode: a }) => {
|
|
371
393
|
o.push({
|
|
372
394
|
action: "insert",
|
|
373
395
|
model: "control",
|
|
374
396
|
payload: "。 ",
|
|
375
397
|
position: r,
|
|
376
398
|
text: "",
|
|
377
|
-
actionCode:
|
|
399
|
+
actionCode: a
|
|
378
400
|
});
|
|
379
401
|
},
|
|
380
|
-
[p.customStop.type]: ({ payload: r, position:
|
|
402
|
+
[p.customStop.type]: ({ payload: r, position: a, actionCode: c }) => {
|
|
381
403
|
o.push({
|
|
382
404
|
action: "insert",
|
|
383
405
|
model: "control",
|
|
384
406
|
payload: `[stop:${r == null ? void 0 : r.time}]`,
|
|
385
|
-
position:
|
|
407
|
+
position: a,
|
|
386
408
|
text: "",
|
|
387
409
|
actionCode: c
|
|
388
410
|
});
|
|
389
411
|
},
|
|
390
|
-
[p.continue.type]: ({ position: r, text:
|
|
412
|
+
[p.continue.type]: ({ position: r, text: a, actionCode: c }) => {
|
|
391
413
|
o.push({
|
|
392
414
|
action: "replace",
|
|
393
415
|
model: "replace",
|
|
394
|
-
payload: `《${
|
|
416
|
+
payload: `《${a}》`,
|
|
395
417
|
position: r,
|
|
396
|
-
text:
|
|
418
|
+
text: a,
|
|
397
419
|
actionCode: c
|
|
398
420
|
});
|
|
399
421
|
},
|
|
400
|
-
[p.replace.type]: ({ payload: r, position:
|
|
422
|
+
[p.replace.type]: ({ payload: r, position: a, text: c, actionCode: i }) => {
|
|
401
423
|
o.push({
|
|
402
424
|
action: "replace",
|
|
403
425
|
model: "replace",
|
|
404
426
|
payload: `${r == null ? void 0 : r.text}`,
|
|
405
|
-
position:
|
|
427
|
+
position: a,
|
|
406
428
|
text: c,
|
|
407
|
-
actionCode:
|
|
429
|
+
actionCode: i
|
|
408
430
|
});
|
|
409
431
|
},
|
|
410
|
-
[p.pinyin.type]: ({ payload: r, position:
|
|
432
|
+
[p.pinyin.type]: ({ payload: r, position: a, text: c, actionCode: i }) => {
|
|
411
433
|
o.push({
|
|
412
434
|
action: "replace",
|
|
413
435
|
model: "pinyin",
|
|
414
436
|
payload: `${r == null ? void 0 : r.text}`,
|
|
415
|
-
position:
|
|
437
|
+
position: a,
|
|
416
438
|
text: c,
|
|
417
|
-
actionCode:
|
|
439
|
+
actionCode: i
|
|
418
440
|
});
|
|
419
441
|
},
|
|
420
|
-
[p.language.type]: ({ payload: r, position:
|
|
442
|
+
[p.language.type]: ({ payload: r, position: a, text: c, actionCode: i }) => {
|
|
421
443
|
o.push({
|
|
422
444
|
action: "language",
|
|
423
445
|
model: "language",
|
|
424
446
|
payload: `${r == null ? void 0 : r.code}`,
|
|
425
|
-
position:
|
|
447
|
+
position: a,
|
|
426
448
|
text: c,
|
|
427
|
-
actionCode:
|
|
449
|
+
actionCode: i
|
|
428
450
|
});
|
|
429
451
|
},
|
|
430
|
-
[p.
|
|
452
|
+
[p.tone.type]: ({ payload: r, position: a, actionCode: c }) => {
|
|
453
|
+
var u;
|
|
454
|
+
const i = (u = D.find((g) => g.value === (r == null ? void 0 : r.code))) == null ? void 0 : u.tag;
|
|
455
|
+
i && o.push({
|
|
456
|
+
action: "insert",
|
|
457
|
+
model: "control",
|
|
458
|
+
payload: i,
|
|
459
|
+
position: a,
|
|
460
|
+
text: "",
|
|
461
|
+
actionCode: c
|
|
462
|
+
});
|
|
463
|
+
},
|
|
464
|
+
[p.ignore.type]: ({ position: r, text: a, actionCode: c }) => {
|
|
431
465
|
o.push({
|
|
432
466
|
action: "replace",
|
|
433
467
|
model: "replace",
|
|
434
468
|
payload: " ",
|
|
435
469
|
position: r,
|
|
436
|
-
text:
|
|
470
|
+
text: a,
|
|
437
471
|
actionCode: c
|
|
438
472
|
});
|
|
439
473
|
}
|
|
440
474
|
};
|
|
441
|
-
return
|
|
475
|
+
return t.forEach((r) => {
|
|
442
476
|
var T, E;
|
|
443
477
|
if (r.type === "text") {
|
|
444
478
|
n += r.text || "";
|
|
445
479
|
return;
|
|
446
480
|
}
|
|
447
481
|
if (r.type !== "customTag") return;
|
|
448
|
-
const
|
|
482
|
+
const a = (T = r.attrs) == null ? void 0 : T.categ, c = (E = r.attrs) == null ? void 0 : E.payload, i = n.length, u = A(r), g = l[a];
|
|
449
483
|
u && s.push({
|
|
450
|
-
start:
|
|
451
|
-
end:
|
|
452
|
-
}),
|
|
484
|
+
start: i,
|
|
485
|
+
end: i + u.length
|
|
486
|
+
}), g && g({
|
|
453
487
|
payload: c,
|
|
454
|
-
position:
|
|
488
|
+
position: i,
|
|
455
489
|
text: u,
|
|
456
|
-
actionCode:
|
|
490
|
+
actionCode: a
|
|
457
491
|
}), n += u;
|
|
458
492
|
}), {
|
|
459
493
|
text: n,
|
|
460
494
|
protectedRanges: s,
|
|
461
495
|
playments: o
|
|
462
496
|
};
|
|
463
|
-
}, N = (
|
|
464
|
-
const
|
|
465
|
-
if (
|
|
466
|
-
if (
|
|
467
|
-
return
|
|
468
|
-
const n =
|
|
469
|
-
return n.length ? n :
|
|
497
|
+
}, N = (e) => e.type === "text" || e.type === "customTag", ie = (e) => {
|
|
498
|
+
const t = e.content || [];
|
|
499
|
+
if (e.type === "paragraph") return [e];
|
|
500
|
+
if (e.type === "doc")
|
|
501
|
+
return t.filter((o) => o.type === "paragraph");
|
|
502
|
+
const n = t.filter((o) => o.type === "paragraph");
|
|
503
|
+
return n.length ? n : t.some(N) ? [
|
|
470
504
|
{
|
|
471
505
|
type: "paragraph",
|
|
472
|
-
content:
|
|
506
|
+
content: t.filter(N)
|
|
473
507
|
}
|
|
474
508
|
] : [];
|
|
475
|
-
},
|
|
509
|
+
}, ce = (e, t) => {
|
|
476
510
|
let n = 0;
|
|
477
|
-
return
|
|
478
|
-
const s =
|
|
511
|
+
return t.map((o) => {
|
|
512
|
+
const s = e.indexOf(o, n), l = s >= 0 ? s : n, r = l + o.length;
|
|
479
513
|
return n = r, {
|
|
480
514
|
text: o,
|
|
481
|
-
start:
|
|
515
|
+
start: l,
|
|
482
516
|
end: r
|
|
483
517
|
};
|
|
484
518
|
});
|
|
485
|
-
},
|
|
486
|
-
if (
|
|
487
|
-
(
|
|
519
|
+
}, ue = (e, t) => e.reduce((n, o) => {
|
|
520
|
+
if (t.some(
|
|
521
|
+
(l) => o.start > l.start && o.start < l.end
|
|
488
522
|
) && n.length) {
|
|
489
|
-
const
|
|
490
|
-
return
|
|
523
|
+
const l = n[n.length - 1];
|
|
524
|
+
return l.text += o.text, l.end = o.end, n;
|
|
491
525
|
}
|
|
492
526
|
return n.push({ ...o }), n;
|
|
493
|
-
}, []),
|
|
494
|
-
const
|
|
495
|
-
if (
|
|
496
|
-
const n =
|
|
497
|
-
|
|
498
|
-
|
|
527
|
+
}, []), pe = (e, t, n, o) => e.position >= t && e.position < n ? !0 : !e.text && o && e.position === n, ge = (e) => {
|
|
528
|
+
const t = ae(e.text);
|
|
529
|
+
if (t.length <= 1) return [e];
|
|
530
|
+
const n = ue(
|
|
531
|
+
ce(e.text, t),
|
|
532
|
+
e.protectedRanges || []
|
|
499
533
|
);
|
|
500
534
|
return n.map((o, s) => {
|
|
501
|
-
const
|
|
502
|
-
(
|
|
503
|
-
).map((
|
|
504
|
-
...
|
|
505
|
-
position:
|
|
535
|
+
const l = s === n.length - 1, r = e.playments.filter(
|
|
536
|
+
(a) => pe(a, o.start, o.end, l)
|
|
537
|
+
).map((a) => ({
|
|
538
|
+
...a,
|
|
539
|
+
position: a.position - o.start
|
|
506
540
|
}));
|
|
507
541
|
return {
|
|
508
542
|
text: o.text,
|
|
509
543
|
playments: r
|
|
510
544
|
};
|
|
511
545
|
});
|
|
512
|
-
},
|
|
513
|
-
const
|
|
546
|
+
}, Re = (e) => {
|
|
547
|
+
const t = {
|
|
514
548
|
playments: [],
|
|
515
549
|
sentences: []
|
|
516
550
|
};
|
|
517
|
-
return
|
|
518
|
-
const s =
|
|
519
|
-
!s.text && !s.playments.length ||
|
|
520
|
-
|
|
551
|
+
return ie(e).forEach((o) => {
|
|
552
|
+
const s = le(o);
|
|
553
|
+
!s.text && !s.playments.length || ge(s).forEach(({ text: l, playments: r }) => {
|
|
554
|
+
t.sentences.push(l), t.playments.push(r);
|
|
521
555
|
});
|
|
522
|
-
}),
|
|
556
|
+
}), t;
|
|
523
557
|
};
|
|
524
558
|
export {
|
|
525
|
-
|
|
526
|
-
|
|
559
|
+
f as DeleteMode,
|
|
560
|
+
fe as EditorConst,
|
|
527
561
|
x as LanguageOptions,
|
|
528
|
-
|
|
529
|
-
|
|
562
|
+
xe as NumberToTextTools,
|
|
563
|
+
w as StopOptions,
|
|
564
|
+
D as ToneOptions,
|
|
530
565
|
p as ToolConfig,
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
566
|
+
y as allToolTypes,
|
|
567
|
+
Re as convertToTtsFormat,
|
|
568
|
+
_e as estimateTtsDuration,
|
|
569
|
+
Te as getDefaultLockPayload,
|
|
570
|
+
be as getInitContent,
|
|
571
|
+
Ee as getLockPayloadLabel,
|
|
572
|
+
h as getVisualLength,
|
|
573
|
+
he as isInsertTagType,
|
|
574
|
+
de as isLockableTagType,
|
|
575
|
+
me as resolveTtsEditorFeatures,
|
|
576
|
+
ye as sanitizePastedHtml,
|
|
577
|
+
Z as sanitizePastedText,
|
|
578
|
+
ae as splitTextToSentences,
|
|
579
|
+
z as toCardinal,
|
|
580
|
+
q as toColloquial,
|
|
581
|
+
Ne as toPhoneReading,
|
|
582
|
+
O as toPositional,
|
|
583
|
+
le as transformParagraph
|
|
548
584
|
};
|