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