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