@naersen/tts-rich-text 0.9.0 → 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/dist/core.js CHANGED
@@ -1,4 +1,4 @@
1
- const h = {
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: h.DELETE_NODE
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: h.DELETE_NODE
15
+ deleteMode: f.DELETE_NODE
16
16
  },
17
17
  continue: {
18
18
  label: "连续",
19
19
  icon: "editor-continue",
20
20
  type: "continue",
21
- deleteMode: h.CONVERT_TO_TEXT
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: h.CONVERT_TO_TEXT
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: h.CONVERT_TO_TEXT
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: h.CONVERT_TO_TEXT
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: h.CONVERT_TO_TEXT
71
+ deleteMode: f.CONVERT_TO_TEXT
66
72
  }
67
- }, x = [
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
- ], v = [
99
+ ], w = [
79
100
  { label: "停顿 0.5 秒", value: 0.5 },
80
101
  { label: "停顿 1 秒", value: 1 }
81
- ], gt = {
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
- }, 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,
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
- }, w = {
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((t) => ["zh", "en"].includes(t.value))
132
+ languages: x.filter((e) => ["zh", "en"].includes(e.value))
112
133
  },
113
- 2: d
114
- }, Tt = (t, e = {}) => {
115
- const n = w[t] ?? d;
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
- ...e,
120
- tools: e.tools ?? n.tools ?? d.tools,
121
- languages: e.languages ?? n.languages ?? d.languages
141
+ ...t,
142
+ tools: t.tools ?? n.tools ?? d.tools,
143
+ languages: t.languages ?? n.languages ?? d.languages
122
144
  };
123
- }, Et = () => ({
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
- }), 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),
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
- }, k = ["", "十", "百", "千"], j = ["", "万", "亿", "万亿"];
160
- function X(t) {
161
- return t ? t.split("").map((e) => R[e] || e).join("") : "";
181
+ }, j = ["", "十", "百", "千"], X = ["", "万", "亿", "万亿"];
182
+ function z(e) {
183
+ return e ? e.split("").map((t) => R[t] || t).join("") : "";
162
184
  }
163
- function bt(t) {
164
- return t ? t.split("").map((e) => $[e] || e).join("") : "";
185
+ function Ne(e) {
186
+ return e ? e.split("").map((t) => k[t] || t).join("") : "";
165
187
  }
166
- function z(t) {
167
- const e = t.length;
188
+ function G(e) {
189
+ const t = e.length;
168
190
  let n = "", o = !1;
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]);
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 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 = [];
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 a = Math.max(0, s - 4);
182
- o.unshift(t.substring(a, s));
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 a = o[s], r = z(a);
207
+ const l = o[s], r = G(l);
186
208
  if (r !== "") {
187
- const i = o.length - 1 - s;
188
- e += r + j[i];
209
+ const a = o.length - 1 - s;
210
+ t += r + X[a];
189
211
  }
190
212
  }
191
- return e;
213
+ return t;
192
214
  }
193
- function G(t) {
194
- return y(t);
215
+ function q(e) {
216
+ return O(e);
195
217
  }
196
- const _t = [
197
- { label: "基数读法", func: X },
218
+ const xe = [
219
+ { label: "基数读法", func: z },
198
220
  // { label: '位数读法', func: toPhoneReading },
199
- { label: "位数读法", func: y },
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 = {
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(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, `
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, (e) => O[e] || "").replace(/ *\n */g, `
257
+ `).replace(W, "").replace(Y, " ").replace(K, (t) => L[t] || "").replace(/ *\n */g, `
236
258
  `).replace(/\n{3,}/g, `
237
259
 
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);
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 = J(s.textContent || ""), s = o.nextNode();
266
+ s.textContent = Z(s.textContent || ""), s = o.nextNode();
245
267
  return n.body.innerHTML;
246
- }, Z = {
268
+ }, Q = {
247
269
  minSegmentLength: 32,
248
270
  maxSegmentLength: 64,
249
271
  rebalanceRatio: 0.4
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) => {
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 < t.length; o += 1)
266
- if (n += I.test(t[o]) ? 2 : 1, n >= e)
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 t.length;
269
- }, _ = (t, e, n, o, s) => {
270
- let a = -1, r = Number.POSITIVE_INFINITY;
271
- const i = Math.max(1, n), c = Math.min(t.length - 1, o);
272
- for (let l = i; l <= c; l += 1) {
273
- if (!s.test(t[l - 1]))
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(l - e);
276
- if (u < r && (r = u, a = l), l > e && a >= 0)
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 a;
280
- }, nt = (t, e, n, o) => {
281
- let s = -1, a = Number.POSITIVE_INFINITY;
282
- const r = Math.max(1, n), i = Math.min(t.length - 1, o);
283
- for (let c = r; c <= i; c += 1) {
284
- if (t[c - 1] !== " ")
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 l = Math.abs(c - e);
287
- if (l < a && (a = l, s = c), c > e && s >= 0)
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 = (t, e, n, o, s) => {
313
+ }, M = (e, t, n, o, s) => {
292
314
  for (const r of s) {
293
- const i = _(
294
- t,
315
+ const a = _(
295
316
  e,
317
+ t,
296
318
  n,
297
319
  o,
298
320
  r
299
321
  );
300
- if (i >= 0)
301
- return i;
322
+ if (a >= 0)
323
+ return a;
302
324
  }
303
- const a = nt(t, e, n, o);
304
- return a >= 0 ? a : _(
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
- Q
331
+ ee
310
332
  );
311
- }, ot = (t, e) => {
333
+ }, re = (e, t) => {
312
334
  const n = [];
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(
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, e)
339
+ m(o, t)
318
340
  );
319
- let l = M(o, r, i, c, [
320
- C,
321
- P
341
+ let i = M(o, r, a, c, [
342
+ P,
343
+ S
322
344
  ]);
323
- (l < 0 || l >= o.length) && (l = r), n.push(o.slice(0, l).trim()), o = o.slice(l).trim();
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
- }, 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,
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 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 = {}) => {
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
- ...Z,
345
- ...e
346
- }, o = tt(t);
366
+ ...Q,
367
+ ...t
368
+ }, o = te(e);
347
369
  if (!o)
348
370
  return [];
349
- const s = et(o);
350
- if (g(s) <= n.minSegmentLength)
371
+ const s = ne(o);
372
+ if (h(s) <= n.minSegmentLength)
351
373
  return [b(s)];
352
- const a = [], r = s.split(new RegExp("(?<=[。!?!?\\.])"));
353
- let i = "";
354
- for (const l of r) {
355
- if (!l)
374
+ const l = [], r = s.split(new RegExp("(?<=[。!?!?\\.])"));
375
+ let a = "";
376
+ for (const i of r) {
377
+ if (!i)
356
378
  continue;
357
- i += l;
358
- const u = i[i.length - 1] ?? "";
359
- g(i) >= n.minSegmentLength && L.test(u) && (a.push(i.trim()), i = "");
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
- 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(
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 = (t) => t.type === "text" ? t.text || "" : (t.content || []).map(A).join(""), it = (t) => {
367
- const e = t.content || [];
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 = [], a = {
370
- [p.stop.type]: ({ position: r, actionCode: i }) => {
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: i
399
+ actionCode: a
378
400
  });
379
401
  },
380
- [p.customStop.type]: ({ payload: r, position: i, actionCode: c }) => {
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: i,
407
+ position: a,
386
408
  text: "",
387
409
  actionCode: c
388
410
  });
389
411
  },
390
- [p.continue.type]: ({ position: r, text: i, actionCode: c }) => {
412
+ [p.continue.type]: ({ position: r, text: a, actionCode: c }) => {
391
413
  o.push({
392
414
  action: "replace",
393
415
  model: "replace",
394
- payload: `《${i}》`,
416
+ payload: `《${a}》`,
395
417
  position: r,
396
- text: i,
418
+ text: a,
397
419
  actionCode: c
398
420
  });
399
421
  },
400
- [p.replace.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
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: i,
427
+ position: a,
406
428
  text: c,
407
- actionCode: l
429
+ actionCode: i
408
430
  });
409
431
  },
410
- [p.pinyin.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
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: i,
437
+ position: a,
416
438
  text: c,
417
- actionCode: l
439
+ actionCode: i
418
440
  });
419
441
  },
420
- [p.language.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
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: i,
447
+ position: a,
426
448
  text: c,
427
- actionCode: l
449
+ actionCode: i
428
450
  });
429
451
  },
430
- [p.ignore.type]: ({ position: r, text: i, actionCode: c }) => {
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: i,
470
+ text: a,
437
471
  actionCode: c
438
472
  });
439
473
  }
440
474
  };
441
- return e.forEach((r) => {
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 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];
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: l,
451
- end: l + u.length
452
- }), f && f({
484
+ start: i,
485
+ end: i + u.length
486
+ }), g && g({
453
487
  payload: c,
454
- position: l,
488
+ position: i,
455
489
  text: u,
456
- actionCode: i
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 = (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) ? [
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: e.filter(N)
506
+ content: t.filter(N)
473
507
  }
474
508
  ] : [];
475
- }, lt = (t, e) => {
509
+ }, ce = (e, t) => {
476
510
  let n = 0;
477
- return e.map((o) => {
478
- const s = t.indexOf(o, n), a = s >= 0 ? s : n, r = a + o.length;
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: a,
515
+ start: l,
482
516
  end: r
483
517
  };
484
518
  });
485
- }, ct = (t, e) => t.reduce((n, o) => {
486
- if (e.some(
487
- (a) => o.start > a.start && o.start < a.end
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 a = n[n.length - 1];
490
- return a.text += o.text, a.end = o.end, n;
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
- }, []), 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 || []
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 a = s === n.length - 1, r = t.playments.filter(
502
- (i) => ut(i, o.start, o.end, a)
503
- ).map((i) => ({
504
- ...i,
505
- position: i.position - o.start
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
- }, xt = (t) => {
513
- const e = {
546
+ }, Re = (e) => {
547
+ const t = {
514
548
  playments: [],
515
549
  sentences: []
516
550
  };
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);
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
- }), e;
556
+ }), t;
523
557
  };
524
558
  export {
525
- h as DeleteMode,
526
- gt as EditorConst,
559
+ f as DeleteMode,
560
+ fe as EditorConst,
527
561
  x as LanguageOptions,
528
- _t as NumberToTextTools,
529
- v as StopOptions,
562
+ xe as NumberToTextTools,
563
+ w as StopOptions,
564
+ D as ToneOptions,
530
565
  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,
546
- y as toPositional,
547
- it as transformParagraph
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
  };