@naersen/tts-rich-text 0.8.3 → 0.9.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 +21 -0
- package/README.md +39 -2
- package/dist/base.css +1 -1
- package/dist/components/tts-editor-root/index.vue.d.ts +44 -0
- package/dist/components/tts-rich-text/components/editor-context-menu.vue.d.ts +30 -0
- package/dist/components/tts-rich-text/components/editor-tool-button.vue.d.ts +11 -0
- package/dist/components/tts-rich-text/components/toolbar-popovers/lock-tip.vue.d.ts +9 -0
- package/dist/components/tts-rich-text/components/toolbar-popovers/stop-popover.vue.d.ts +1 -0
- package/dist/components/tts-rich-text/components/type/index.d.ts +2 -0
- package/dist/components/tts-rich-text/editor/index.d.ts +2 -0
- package/dist/components/tts-rich-text/editor/type.d.ts +37 -0
- package/dist/components/tts-rich-text/editor/useEditorToolbar.d.ts +1 -1
- package/dist/components/tts-rich-text/editor/useEditorToolkit.d.ts +115 -0
- package/dist/components/tts-rich-text/editor/useOverflowToolbar.d.ts +2 -0
- package/dist/components/tts-rich-text/editor/useRichTextEditor.d.ts +89 -0
- package/dist/components/tts-rich-text/index.d.ts +1 -0
- package/dist/components/tts-rich-text-editor/index.vue.d.ts +150 -2
- package/dist/core/config.d.ts +24 -0
- package/dist/core.js +189 -214
- package/dist/editor/index.d.ts +3 -0
- package/dist/index.js +4578 -4151
- package/package.json +89 -84
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
|
+
}, p = {
|
|
5
5
|
stop: {
|
|
6
6
|
label: "停顿",
|
|
7
7
|
icon: "editor-stop",
|
|
@@ -75,16 +75,27 @@ const h = {
|
|
|
75
75
|
{ value: "it", label: "意大利语" },
|
|
76
76
|
{ value: "pt", label: "葡萄牙语" },
|
|
77
77
|
{ value: "ru", label: "俄语" }
|
|
78
|
-
],
|
|
78
|
+
], v = [
|
|
79
79
|
{ label: "停顿 0.5 秒", value: 0.5 },
|
|
80
80
|
{ label: "停顿 1 秒", value: 1 }
|
|
81
|
-
],
|
|
82
|
-
|
|
81
|
+
], gt = {
|
|
82
|
+
SENTENCE: "sentence",
|
|
83
|
+
CUSTOM_TAG: "customTag",
|
|
84
|
+
/**
|
|
85
|
+
* 选中文本时浮出的气泡菜单插件 key。
|
|
86
|
+
* 工具栏与右键面板都要用它来主动收起气泡,避免两个浮层叠在一起。
|
|
87
|
+
*/
|
|
88
|
+
BUBBLE_MENU_KEY: "ttsRichTextBubbleMenu"
|
|
89
|
+
}, ft = (t) => {
|
|
90
|
+
var e;
|
|
91
|
+
return ((e = p[t]) == null ? void 0 : e.deleteMode) === h.DELETE_NODE;
|
|
92
|
+
}, ht = (t) => t === p.customStop.type ? { time: v[0].value } : {}, dt = (t, e) => t === p.customStop.type ? `${e == null ? void 0 : e.time} 秒` : "", D = Object.keys(p), d = {
|
|
93
|
+
tools: D,
|
|
83
94
|
languages: x,
|
|
84
95
|
maxPinyinLength: 4,
|
|
85
96
|
maxNumberLength: 16,
|
|
86
97
|
enablePreview: !0
|
|
87
|
-
},
|
|
98
|
+
}, w = {
|
|
88
99
|
1: {
|
|
89
100
|
tools: [
|
|
90
101
|
"customStop",
|
|
@@ -97,21 +108,19 @@ const h = {
|
|
|
97
108
|
"upload",
|
|
98
109
|
"ignore"
|
|
99
110
|
],
|
|
100
|
-
languages: x.filter(
|
|
101
|
-
(e) => ["zh", "en"].includes(e.value)
|
|
102
|
-
)
|
|
111
|
+
languages: x.filter((t) => ["zh", "en"].includes(t.value))
|
|
103
112
|
},
|
|
104
113
|
2: d
|
|
105
|
-
},
|
|
106
|
-
const n =
|
|
114
|
+
}, Tt = (t, e = {}) => {
|
|
115
|
+
const n = w[t] ?? d;
|
|
107
116
|
return {
|
|
108
117
|
...d,
|
|
109
118
|
...n,
|
|
110
|
-
...
|
|
111
|
-
tools:
|
|
112
|
-
languages:
|
|
119
|
+
...e,
|
|
120
|
+
tools: e.tools ?? n.tools ?? d.tools,
|
|
121
|
+
languages: e.languages ?? n.languages ?? d.languages
|
|
113
122
|
};
|
|
114
|
-
},
|
|
123
|
+
}, Et = () => ({
|
|
115
124
|
type: "doc",
|
|
116
125
|
content: [
|
|
117
126
|
{
|
|
@@ -119,10 +128,10 @@ const h = {
|
|
|
119
128
|
content: []
|
|
120
129
|
}
|
|
121
130
|
]
|
|
122
|
-
}),
|
|
123
|
-
const n = Number.isFinite(
|
|
124
|
-
return Array.from(
|
|
125
|
-
(s, a) => s + (
|
|
131
|
+
}), B = /[\u4e00-\u9fff]/, H = /\s/g, U = 0.28, V = 0.14, mt = (t, e = 1) => {
|
|
132
|
+
const n = Number.isFinite(e) && e > 0 ? e : 1;
|
|
133
|
+
return Array.from(t.replace(H, "")).reduce(
|
|
134
|
+
(s, a) => s + (B.test(a) ? U : V),
|
|
126
135
|
0
|
|
127
136
|
) / n;
|
|
128
137
|
}, R = {
|
|
@@ -136,7 +145,7 @@ const h = {
|
|
|
136
145
|
7: "七",
|
|
137
146
|
8: "八",
|
|
138
147
|
9: "九"
|
|
139
|
-
},
|
|
148
|
+
}, $ = {
|
|
140
149
|
0: "洞",
|
|
141
150
|
1: "幺",
|
|
142
151
|
2: "二",
|
|
@@ -147,49 +156,49 @@ const h = {
|
|
|
147
156
|
7: "七",
|
|
148
157
|
8: "八",
|
|
149
158
|
9: "九"
|
|
150
|
-
},
|
|
151
|
-
function
|
|
152
|
-
return
|
|
159
|
+
}, k = ["", "十", "百", "千"], j = ["", "万", "亿", "万亿"];
|
|
160
|
+
function X(t) {
|
|
161
|
+
return t ? t.split("").map((e) => R[e] || e).join("") : "";
|
|
153
162
|
}
|
|
154
|
-
function
|
|
155
|
-
return
|
|
163
|
+
function bt(t) {
|
|
164
|
+
return t ? t.split("").map((e) => $[e] || e).join("") : "";
|
|
156
165
|
}
|
|
157
|
-
function
|
|
158
|
-
const
|
|
166
|
+
function z(t) {
|
|
167
|
+
const e = t.length;
|
|
159
168
|
let n = "", o = !1;
|
|
160
|
-
for (let s = 0; s <
|
|
161
|
-
const a =
|
|
162
|
-
a === "0" ? !o && n !== "" && (o = !0) : (o && (n += "零", o = !1), n += R[a] +
|
|
169
|
+
for (let s = 0; s < e; s++) {
|
|
170
|
+
const a = t[s], r = e - 1 - s;
|
|
171
|
+
a === "0" ? !o && n !== "" && (o = !0) : (o && (n += "零", o = !1), n += R[a] + k[r]);
|
|
163
172
|
}
|
|
164
173
|
return n.startsWith("一十") && n.length === 2 && (n = n.substring(1)), n;
|
|
165
174
|
}
|
|
166
|
-
function y(
|
|
167
|
-
if (!
|
|
168
|
-
if (
|
|
169
|
-
let
|
|
170
|
-
const n =
|
|
175
|
+
function y(t) {
|
|
176
|
+
if (!t) return "";
|
|
177
|
+
if (t === "0" || (t = t.replace(/^0+/, "") || "0", t === "0")) return "零";
|
|
178
|
+
let e = "";
|
|
179
|
+
const n = t.length, o = [];
|
|
171
180
|
for (let s = n; s > 0; s -= 4) {
|
|
172
181
|
const a = Math.max(0, s - 4);
|
|
173
|
-
o.unshift(
|
|
182
|
+
o.unshift(t.substring(a, s));
|
|
174
183
|
}
|
|
175
184
|
for (let s = 0; s < o.length; s++) {
|
|
176
|
-
const a = o[s], r =
|
|
185
|
+
const a = o[s], r = z(a);
|
|
177
186
|
if (r !== "") {
|
|
178
187
|
const i = o.length - 1 - s;
|
|
179
|
-
|
|
188
|
+
e += r + j[i];
|
|
180
189
|
}
|
|
181
190
|
}
|
|
182
|
-
return
|
|
191
|
+
return e;
|
|
183
192
|
}
|
|
184
|
-
function
|
|
185
|
-
return y(
|
|
193
|
+
function G(t) {
|
|
194
|
+
return y(t);
|
|
186
195
|
}
|
|
187
|
-
const
|
|
188
|
-
{ label: "基数读法", func:
|
|
196
|
+
const _t = [
|
|
197
|
+
{ label: "基数读法", func: X },
|
|
189
198
|
// { label: '位数读法', func: toPhoneReading },
|
|
190
199
|
{ label: "位数读法", func: y },
|
|
191
|
-
{ label: "口语读法", func:
|
|
192
|
-
],
|
|
200
|
+
{ label: "口语读法", func: G }
|
|
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, O = {
|
|
193
202
|
"‘": "'",
|
|
194
203
|
"’": "'",
|
|
195
204
|
"‚": "'",
|
|
@@ -221,72 +230,69 @@ const Te = [
|
|
|
221
230
|
"︔": ";",
|
|
222
231
|
"︕": "!",
|
|
223
232
|
"︖": "?"
|
|
224
|
-
},
|
|
225
|
-
`[${Object.keys(I).join("")}]`,
|
|
226
|
-
"g"
|
|
227
|
-
), K = (e) => e.replace(/[\uFF21-\uFF3A\uFF41-\uFF5A\uFF10-\uFF19]/g, (t) => String.fromCharCode(t.charCodeAt(0) - 65248)), q = (e) => K(e).replace(/\r\n?/g, `
|
|
233
|
+
}, K = new RegExp(`[${Object.keys(O).join("")}]`, "g"), q = (t) => t.replace(/[\uFF21-\uFF3A\uFF41-\uFF5A\uFF10-\uFF19]/g, (e) => String.fromCharCode(e.charCodeAt(0) - 65248)), J = (t) => q(t).replace(/\r\n?/g, `
|
|
228
234
|
`).replace(/[\u2028\u2029]/g, `
|
|
229
|
-
`).replace(
|
|
235
|
+
`).replace(W, "").replace(Y, " ").replace(K, (e) => O[e] || "").replace(/ *\n */g, `
|
|
230
236
|
`).replace(/\n{3,}/g, `
|
|
231
237
|
|
|
232
|
-
`),
|
|
233
|
-
if (typeof window > "u" || !
|
|
234
|
-
return
|
|
235
|
-
const n = new DOMParser().parseFromString(
|
|
238
|
+
`), Nt = (t) => {
|
|
239
|
+
if (typeof window > "u" || !t)
|
|
240
|
+
return t;
|
|
241
|
+
const n = new DOMParser().parseFromString(t, "text/html"), o = n.createTreeWalker(n.body, NodeFilter.SHOW_TEXT);
|
|
236
242
|
let s = o.nextNode();
|
|
237
243
|
for (; s; )
|
|
238
|
-
s.textContent =
|
|
244
|
+
s.textContent = J(s.textContent || ""), s = o.nextNode();
|
|
239
245
|
return n.body.innerHTML;
|
|
240
|
-
},
|
|
246
|
+
}, Z = {
|
|
241
247
|
minSegmentLength: 32,
|
|
242
248
|
maxSegmentLength: 64,
|
|
243
249
|
rebalanceRatio: 0.4
|
|
244
|
-
},
|
|
245
|
-
let
|
|
246
|
-
for (const n of
|
|
247
|
-
|
|
248
|
-
return
|
|
249
|
-
},
|
|
250
|
-
`).map((
|
|
251
|
-
let
|
|
252
|
-
for (; n !==
|
|
253
|
-
n =
|
|
254
|
-
for (n = ""; n !==
|
|
255
|
-
n =
|
|
256
|
-
return
|
|
257
|
-
}, b = (
|
|
250
|
+
}, I = /[一-鿿㐀-䶿豈- -〿-]/, L = /[。!?!?\.]/, C = /[;;]/, P = /[,,::]/, Q = /[、]/, F = "", S = "", g = (t) => {
|
|
251
|
+
let e = 0;
|
|
252
|
+
for (const n of t)
|
|
253
|
+
e += I.test(n) ? 2 : 1;
|
|
254
|
+
return e;
|
|
255
|
+
}, tt = (t) => t.replace(/\r/g, "").split(`
|
|
256
|
+
`).map((e) => e.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), et = (t) => {
|
|
257
|
+
let e = t, n = "";
|
|
258
|
+
for (; n !== e; )
|
|
259
|
+
n = e, e = e.replace(/(\d),(\d)/g, `$1${F}$2`);
|
|
260
|
+
for (n = ""; n !== e; )
|
|
261
|
+
n = e, e = e.replace(/(\d)\.(\d)/g, `$1${S}$2`);
|
|
262
|
+
return e;
|
|
263
|
+
}, b = (t) => t.split(F).join(",").split(S).join("."), m = (t, e) => {
|
|
258
264
|
let n = 0;
|
|
259
|
-
for (let o = 0; o <
|
|
260
|
-
if (n +=
|
|
265
|
+
for (let o = 0; o < t.length; o += 1)
|
|
266
|
+
if (n += I.test(t[o]) ? 2 : 1, n >= e)
|
|
261
267
|
return o + 1;
|
|
262
|
-
return
|
|
263
|
-
}, _ = (
|
|
268
|
+
return t.length;
|
|
269
|
+
}, _ = (t, e, n, o, s) => {
|
|
264
270
|
let a = -1, r = Number.POSITIVE_INFINITY;
|
|
265
|
-
const i = Math.max(1, n), c = Math.min(
|
|
271
|
+
const i = Math.max(1, n), c = Math.min(t.length - 1, o);
|
|
266
272
|
for (let l = i; l <= c; l += 1) {
|
|
267
|
-
if (!s.test(
|
|
273
|
+
if (!s.test(t[l - 1]))
|
|
268
274
|
continue;
|
|
269
|
-
const u = Math.abs(l -
|
|
270
|
-
if (u < r && (r = u, a = l), l >
|
|
275
|
+
const u = Math.abs(l - e);
|
|
276
|
+
if (u < r && (r = u, a = l), l > e && a >= 0)
|
|
271
277
|
break;
|
|
272
278
|
}
|
|
273
279
|
return a;
|
|
274
|
-
},
|
|
280
|
+
}, nt = (t, e, n, o) => {
|
|
275
281
|
let s = -1, a = Number.POSITIVE_INFINITY;
|
|
276
|
-
const r = Math.max(1, n), i = Math.min(
|
|
282
|
+
const r = Math.max(1, n), i = Math.min(t.length - 1, o);
|
|
277
283
|
for (let c = r; c <= i; c += 1) {
|
|
278
|
-
if (
|
|
284
|
+
if (t[c - 1] !== " ")
|
|
279
285
|
continue;
|
|
280
|
-
const l = Math.abs(c -
|
|
281
|
-
if (l < a && (a = l, s = c), c >
|
|
286
|
+
const l = Math.abs(c - e);
|
|
287
|
+
if (l < a && (a = l, s = c), c > e && s >= 0)
|
|
282
288
|
break;
|
|
283
289
|
}
|
|
284
290
|
return s;
|
|
285
|
-
},
|
|
291
|
+
}, M = (t, e, n, o, s) => {
|
|
286
292
|
for (const r of s) {
|
|
287
293
|
const i = _(
|
|
288
|
-
e,
|
|
289
294
|
t,
|
|
295
|
+
e,
|
|
290
296
|
n,
|
|
291
297
|
o,
|
|
292
298
|
r
|
|
@@ -294,67 +300,54 @@ const Te = [
|
|
|
294
300
|
if (i >= 0)
|
|
295
301
|
return i;
|
|
296
302
|
}
|
|
297
|
-
const a =
|
|
298
|
-
e,
|
|
299
|
-
t,
|
|
300
|
-
n,
|
|
301
|
-
o
|
|
302
|
-
);
|
|
303
|
+
const a = nt(t, e, n, o);
|
|
303
304
|
return a >= 0 ? a : _(
|
|
304
|
-
e,
|
|
305
305
|
t,
|
|
306
|
+
e,
|
|
306
307
|
n,
|
|
307
308
|
o,
|
|
308
|
-
|
|
309
|
+
Q
|
|
309
310
|
);
|
|
310
|
-
},
|
|
311
|
+
}, ot = (t, e) => {
|
|
311
312
|
const n = [];
|
|
312
|
-
let o =
|
|
313
|
-
for (; o &&
|
|
314
|
-
const s =
|
|
315
|
-
Math.floor(s / 2),
|
|
316
|
-
t
|
|
317
|
-
), r = m(o, a), i = Math.max(1, Math.floor(r / 3)), c = Math.max(
|
|
313
|
+
let o = t.trim();
|
|
314
|
+
for (; o && g(o) > e; ) {
|
|
315
|
+
const s = g(o), a = Math.min(Math.floor(s / 2), e), r = m(o, a), i = Math.max(1, Math.floor(r / 3)), c = Math.max(
|
|
318
316
|
r + 1,
|
|
319
|
-
m(o,
|
|
320
|
-
);
|
|
321
|
-
let l = S(
|
|
322
|
-
o,
|
|
323
|
-
r,
|
|
324
|
-
i,
|
|
325
|
-
c,
|
|
326
|
-
[P, C]
|
|
317
|
+
m(o, e)
|
|
327
318
|
);
|
|
319
|
+
let l = M(o, r, i, c, [
|
|
320
|
+
C,
|
|
321
|
+
P
|
|
322
|
+
]);
|
|
328
323
|
(l < 0 || l >= o.length) && (l = r), n.push(o.slice(0, l).trim()), o = o.slice(l).trim();
|
|
329
324
|
}
|
|
330
325
|
return o && n.push(o), n;
|
|
331
|
-
},
|
|
332
|
-
if (
|
|
333
|
-
return
|
|
334
|
-
const n =
|
|
335
|
-
if (
|
|
336
|
-
return
|
|
337
|
-
const r = `${
|
|
338
|
-
let u =
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
[F, P, C]
|
|
344
|
-
);
|
|
326
|
+
}, rt = (t, e) => {
|
|
327
|
+
if (t.length <= 1)
|
|
328
|
+
return t;
|
|
329
|
+
const n = t[t.length - 1], o = t.reduce((T, E) => T + g(E), 0) / t.length, s = Math.floor(o * e);
|
|
330
|
+
if (g(n) >= s)
|
|
331
|
+
return t;
|
|
332
|
+
const r = `${t[t.length - 2]}${n}`, i = Math.floor(g(r) / 2), c = m(r, i), l = Math.max(1, Math.floor(c / 3));
|
|
333
|
+
let u = M(r, c, l, r.length, [
|
|
334
|
+
L,
|
|
335
|
+
C,
|
|
336
|
+
P
|
|
337
|
+
]);
|
|
345
338
|
if (u <= 0 || u >= r.length)
|
|
346
|
-
return
|
|
347
|
-
const
|
|
348
|
-
return
|
|
349
|
-
},
|
|
339
|
+
return t;
|
|
340
|
+
const f = [...t];
|
|
341
|
+
return f[f.length - 2] = r.slice(0, u).trim(), f[f.length - 1] = r.slice(u).trim(), f.filter(Boolean);
|
|
342
|
+
}, st = (t, e = {}) => {
|
|
350
343
|
const n = {
|
|
351
|
-
...
|
|
352
|
-
...
|
|
353
|
-
}, o =
|
|
344
|
+
...Z,
|
|
345
|
+
...e
|
|
346
|
+
}, o = tt(t);
|
|
354
347
|
if (!o)
|
|
355
348
|
return [];
|
|
356
|
-
const s =
|
|
357
|
-
if (
|
|
349
|
+
const s = et(o);
|
|
350
|
+
if (g(s) <= n.minSegmentLength)
|
|
358
351
|
return [b(s)];
|
|
359
352
|
const a = [], r = s.split(new RegExp("(?<=[。!?!?\\.])"));
|
|
360
353
|
let i = "";
|
|
@@ -363,19 +356,18 @@ const Te = [
|
|
|
363
356
|
continue;
|
|
364
357
|
i += l;
|
|
365
358
|
const u = i[i.length - 1] ?? "";
|
|
366
|
-
|
|
359
|
+
g(i) >= n.minSegmentLength && L.test(u) && (a.push(i.trim()), i = "");
|
|
367
360
|
}
|
|
368
|
-
i && (a.length > 0 &&
|
|
369
|
-
const c = a.flatMap((l) =>
|
|
370
|
-
return
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
const t = e.content || [];
|
|
361
|
+
i && (a.length > 0 && g(i) < n.minSegmentLength ? a[a.length - 1] += i : a.push(i.trim()));
|
|
362
|
+
const c = a.flatMap((l) => g(l) <= n.maxSegmentLength ? [l] : ot(l, n.maxSegmentLength));
|
|
363
|
+
return rt(c, n.rebalanceRatio).map(
|
|
364
|
+
b
|
|
365
|
+
);
|
|
366
|
+
}, A = (t) => t.type === "text" ? t.text || "" : (t.content || []).map(A).join(""), it = (t) => {
|
|
367
|
+
const e = t.content || [];
|
|
376
368
|
let n = "";
|
|
377
369
|
const o = [], s = [], a = {
|
|
378
|
-
[
|
|
370
|
+
[p.stop.type]: ({ position: r, actionCode: i }) => {
|
|
379
371
|
o.push({
|
|
380
372
|
action: "insert",
|
|
381
373
|
model: "control",
|
|
@@ -385,7 +377,7 @@ const Te = [
|
|
|
385
377
|
actionCode: i
|
|
386
378
|
});
|
|
387
379
|
},
|
|
388
|
-
[
|
|
380
|
+
[p.customStop.type]: ({ payload: r, position: i, actionCode: c }) => {
|
|
389
381
|
o.push({
|
|
390
382
|
action: "insert",
|
|
391
383
|
model: "control",
|
|
@@ -395,7 +387,7 @@ const Te = [
|
|
|
395
387
|
actionCode: c
|
|
396
388
|
});
|
|
397
389
|
},
|
|
398
|
-
[
|
|
390
|
+
[p.continue.type]: ({ position: r, text: i, actionCode: c }) => {
|
|
399
391
|
o.push({
|
|
400
392
|
action: "replace",
|
|
401
393
|
model: "replace",
|
|
@@ -405,12 +397,7 @@ const Te = [
|
|
|
405
397
|
actionCode: c
|
|
406
398
|
});
|
|
407
399
|
},
|
|
408
|
-
[
|
|
409
|
-
payload: r,
|
|
410
|
-
position: i,
|
|
411
|
-
text: c,
|
|
412
|
-
actionCode: l
|
|
413
|
-
}) => {
|
|
400
|
+
[p.replace.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
|
|
414
401
|
o.push({
|
|
415
402
|
action: "replace",
|
|
416
403
|
model: "replace",
|
|
@@ -420,7 +407,7 @@ const Te = [
|
|
|
420
407
|
actionCode: l
|
|
421
408
|
});
|
|
422
409
|
},
|
|
423
|
-
[
|
|
410
|
+
[p.pinyin.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
|
|
424
411
|
o.push({
|
|
425
412
|
action: "replace",
|
|
426
413
|
model: "pinyin",
|
|
@@ -430,12 +417,7 @@ const Te = [
|
|
|
430
417
|
actionCode: l
|
|
431
418
|
});
|
|
432
419
|
},
|
|
433
|
-
[
|
|
434
|
-
payload: r,
|
|
435
|
-
position: i,
|
|
436
|
-
text: c,
|
|
437
|
-
actionCode: l
|
|
438
|
-
}) => {
|
|
420
|
+
[p.language.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
|
|
439
421
|
o.push({
|
|
440
422
|
action: "language",
|
|
441
423
|
model: "language",
|
|
@@ -445,11 +427,7 @@ const Te = [
|
|
|
445
427
|
actionCode: l
|
|
446
428
|
});
|
|
447
429
|
},
|
|
448
|
-
[
|
|
449
|
-
position: r,
|
|
450
|
-
text: i,
|
|
451
|
-
actionCode: c
|
|
452
|
-
}) => {
|
|
430
|
+
[p.ignore.type]: ({ position: r, text: i, actionCode: c }) => {
|
|
453
431
|
o.push({
|
|
454
432
|
action: "replace",
|
|
455
433
|
model: "replace",
|
|
@@ -460,18 +438,18 @@ const Te = [
|
|
|
460
438
|
});
|
|
461
439
|
}
|
|
462
440
|
};
|
|
463
|
-
return
|
|
441
|
+
return e.forEach((r) => {
|
|
464
442
|
var T, E;
|
|
465
443
|
if (r.type === "text") {
|
|
466
444
|
n += r.text || "";
|
|
467
445
|
return;
|
|
468
446
|
}
|
|
469
447
|
if (r.type !== "customTag") return;
|
|
470
|
-
const i = (T = r.attrs) == null ? void 0 : T.categ, c = (E = r.attrs) == null ? void 0 : E.payload, l = n.length, u =
|
|
448
|
+
const i = (T = r.attrs) == null ? void 0 : T.categ, c = (E = r.attrs) == null ? void 0 : E.payload, l = n.length, u = A(r), f = a[i];
|
|
471
449
|
u && s.push({
|
|
472
450
|
start: l,
|
|
473
451
|
end: l + u.length
|
|
474
|
-
}),
|
|
452
|
+
}), f && f({
|
|
475
453
|
payload: c,
|
|
476
454
|
position: l,
|
|
477
455
|
text: u,
|
|
@@ -482,53 +460,46 @@ const Te = [
|
|
|
482
460
|
protectedRanges: s,
|
|
483
461
|
playments: o
|
|
484
462
|
};
|
|
485
|
-
}, N = (
|
|
486
|
-
const
|
|
487
|
-
if (
|
|
488
|
-
if (
|
|
489
|
-
return
|
|
490
|
-
const n =
|
|
491
|
-
|
|
492
|
-
);
|
|
493
|
-
return n.length ? n : t.some(N) ? [
|
|
463
|
+
}, N = (t) => t.type === "text" || t.type === "customTag", at = (t) => {
|
|
464
|
+
const e = t.content || [];
|
|
465
|
+
if (t.type === "paragraph") return [t];
|
|
466
|
+
if (t.type === "doc")
|
|
467
|
+
return e.filter((o) => o.type === "paragraph");
|
|
468
|
+
const n = e.filter((o) => o.type === "paragraph");
|
|
469
|
+
return n.length ? n : e.some(N) ? [
|
|
494
470
|
{
|
|
495
471
|
type: "paragraph",
|
|
496
|
-
content:
|
|
472
|
+
content: e.filter(N)
|
|
497
473
|
}
|
|
498
474
|
] : [];
|
|
499
|
-
},
|
|
475
|
+
}, lt = (t, e) => {
|
|
500
476
|
let n = 0;
|
|
501
|
-
return
|
|
502
|
-
const s =
|
|
477
|
+
return e.map((o) => {
|
|
478
|
+
const s = t.indexOf(o, n), a = s >= 0 ? s : n, r = a + o.length;
|
|
503
479
|
return n = r, {
|
|
504
480
|
text: o,
|
|
505
481
|
start: a,
|
|
506
482
|
end: r
|
|
507
483
|
};
|
|
508
484
|
});
|
|
509
|
-
},
|
|
510
|
-
if (
|
|
485
|
+
}, ct = (t, e) => t.reduce((n, o) => {
|
|
486
|
+
if (e.some(
|
|
511
487
|
(a) => o.start > a.start && o.start < a.end
|
|
512
488
|
) && n.length) {
|
|
513
489
|
const a = n[n.length - 1];
|
|
514
490
|
return a.text += o.text, a.end = o.end, n;
|
|
515
491
|
}
|
|
516
492
|
return n.push({ ...o }), n;
|
|
517
|
-
}, []),
|
|
518
|
-
const
|
|
519
|
-
if (
|
|
520
|
-
const n =
|
|
521
|
-
|
|
522
|
-
|
|
493
|
+
}, []), ut = (t, e, n, o) => t.position >= e && t.position < n ? !0 : !t.text && o && t.position === n, pt = (t) => {
|
|
494
|
+
const e = st(t.text);
|
|
495
|
+
if (e.length <= 1) return [t];
|
|
496
|
+
const n = ct(
|
|
497
|
+
lt(t.text, e),
|
|
498
|
+
t.protectedRanges || []
|
|
523
499
|
);
|
|
524
500
|
return n.map((o, s) => {
|
|
525
|
-
const a = s === n.length - 1, r =
|
|
526
|
-
(i) =>
|
|
527
|
-
i,
|
|
528
|
-
o.start,
|
|
529
|
-
o.end,
|
|
530
|
-
a
|
|
531
|
-
)
|
|
501
|
+
const a = s === n.length - 1, r = t.playments.filter(
|
|
502
|
+
(i) => ut(i, o.start, o.end, a)
|
|
532
503
|
).map((i) => ({
|
|
533
504
|
...i,
|
|
534
505
|
position: i.position - o.start
|
|
@@ -538,36 +509,40 @@ const Te = [
|
|
|
538
509
|
playments: r
|
|
539
510
|
};
|
|
540
511
|
});
|
|
541
|
-
},
|
|
542
|
-
const
|
|
512
|
+
}, xt = (t) => {
|
|
513
|
+
const e = {
|
|
543
514
|
playments: [],
|
|
544
515
|
sentences: []
|
|
545
516
|
};
|
|
546
|
-
return
|
|
547
|
-
const s =
|
|
548
|
-
!s.text && !s.playments.length ||
|
|
549
|
-
|
|
517
|
+
return at(t).forEach((o) => {
|
|
518
|
+
const s = it(o);
|
|
519
|
+
!s.text && !s.playments.length || pt(s).forEach(({ text: a, playments: r }) => {
|
|
520
|
+
e.sentences.push(a), e.playments.push(r);
|
|
550
521
|
});
|
|
551
|
-
}),
|
|
522
|
+
}), e;
|
|
552
523
|
};
|
|
553
524
|
export {
|
|
554
525
|
h as DeleteMode,
|
|
526
|
+
gt as EditorConst,
|
|
555
527
|
x as LanguageOptions,
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
528
|
+
_t as NumberToTextTools,
|
|
529
|
+
v as StopOptions,
|
|
530
|
+
p as ToolConfig,
|
|
531
|
+
D as allToolTypes,
|
|
532
|
+
xt as convertToTtsFormat,
|
|
533
|
+
mt as estimateTtsDuration,
|
|
534
|
+
ht as getDefaultLockPayload,
|
|
535
|
+
Et as getInitContent,
|
|
536
|
+
dt as getLockPayloadLabel,
|
|
537
|
+
g as getVisualLength,
|
|
538
|
+
ft as isInsertTagType,
|
|
539
|
+
Tt as resolveTtsEditorFeatures,
|
|
540
|
+
Nt as sanitizePastedHtml,
|
|
541
|
+
J as sanitizePastedText,
|
|
542
|
+
st as splitTextToSentences,
|
|
543
|
+
X as toCardinal,
|
|
544
|
+
G as toColloquial,
|
|
545
|
+
bt as toPhoneReading,
|
|
571
546
|
y as toPositional,
|
|
572
|
-
|
|
547
|
+
it as transformParagraph
|
|
573
548
|
};
|
package/dist/editor/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { useEditorContext, useEditorProvider, useRichTextEditor, type RichTextEditor, type UseRichTextEditorOptions } from '../components/tts-rich-text/editor/useRichTextEditor';
|
|
2
|
+
export { useEditorToolkit, type EditorToolkit } from '../components/tts-rich-text/editor/useEditorToolkit';
|
|
3
|
+
export { useEditorToolbar, type ToolbarItem } from '../components/tts-rich-text/editor/useEditorToolbar';
|
|
4
|
+
export { type EditorContextMenuState, type ToolMenuItem, type ToolModalOpeners } from '../components/tts-rich-text/editor/type';
|
|
2
5
|
export { createCustomTagNode, CustomTagName } from '../components/tts-rich-text/editor/nodes/tag-node';
|
|
3
6
|
export { createTtsCharacterCount } from '../components/tts-rich-text/editor/plugins/tts-character-count';
|
|
4
7
|
export { useSSETool, type UseSseToolOptions } from '../components/tts-rich-text/editor/useSSETool';
|