@naersen/tts-rich-text 0.9.1 → 0.10.1

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,42 +1,48 @@
1
- const h = {
1
+ const f = {
2
2
  DELETE_NODE: "deleteNode",
3
3
  CONVERT_TO_TEXT: "convertToText"
4
- }, p = {
4
+ }, g = {
5
5
  stop: {
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
+ }, S = [
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
+ ], _ = [
68
89
  { value: "zh", label: "中文" },
69
90
  { value: "en", label: "英语" },
70
91
  { value: "jp", label: "日语" },
@@ -78,7 +99,7 @@ const h = {
78
99
  ], v = [
79
100
  { label: "停顿 0.5 秒", value: 0.5 },
80
101
  { label: "停顿 1 秒", value: 1 }
81
- ], gt = {
102
+ ], pe = {
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,
94
- languages: x,
110
+ }, fe = (e) => {
111
+ var t;
112
+ return ((t = g[e]) == null ? void 0 : t.deleteMode) === f.DELETE_NODE;
113
+ }, he = (e) => e === g.stop.type || e === g.customStop.type, de = (e) => e === g.customStop.type ? { time: v[0].value } : {}, Te = (e, t) => e === g.customStop.type ? `${t == null ? void 0 : t.time} 秒` : "", x = Object.keys(g), d = {
114
+ tools: x.filter((e) => e !== g.tone.type),
115
+ languages: _,
95
116
  maxPinyinLength: 4,
96
117
  maxNumberLength: 16,
97
118
  enablePreview: !0
98
- }, w = {
119
+ }, F = {
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: _.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: x.filter((e) => e !== g.language.type) }
136
+ }, Ee = (e, t = {}) => {
137
+ const n = F[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
+ }, me = () => ({
124
146
  type: "doc",
125
147
  content: [
126
148
  {
@@ -128,13 +150,13 @@ 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
+ }), A = /[\u4e00-\u9fff]/, M = /\s/g, D = 0.28, w = 0.14, be = (e, t = 1) => {
154
+ const n = Number.isFinite(t) && t > 0 ? t : 1;
155
+ return Array.from(e.replace(M, "")).reduce(
156
+ (s, a) => s + (A.test(a) ? D : w),
135
157
  0
136
158
  ) / n;
137
- }, R = {
159
+ }, N = {
138
160
  0: "零",
139
161
  1: "一",
140
162
  2: "二",
@@ -145,7 +167,7 @@ const h = {
145
167
  7: "七",
146
168
  8: "八",
147
169
  9: "九"
148
- }, $ = {
170
+ }, B = {
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
+ }, H = ["", "十", "百", "千"], k = ["", "万", "亿", "万亿"];
182
+ function U(e) {
183
+ return e ? e.split("").map((t) => N[t] || t).join("") : "";
162
184
  }
163
- function bt(t) {
164
- return t ? t.split("").map((e) => $[e] || e).join("") : "";
185
+ function _e(e) {
186
+ return e ? e.split("").map((t) => B[t] || t).join("") : "";
165
187
  }
166
- function z(t) {
167
- const e = t.length;
188
+ function $(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 a = e[s], r = t - 1 - s;
193
+ a === "0" ? !o && n !== "" && (o = !0) : (o && (n += "零", o = !1), n += N[a] + H[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 y(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
203
  const a = Math.max(0, s - 4);
182
- o.unshift(t.substring(a, s));
204
+ o.unshift(e.substring(a, s));
183
205
  }
184
206
  for (let s = 0; s < o.length; s++) {
185
- const a = o[s], r = z(a);
207
+ const a = o[s], r = $(a);
186
208
  if (r !== "") {
187
- const i = o.length - 1 - s;
188
- e += r + j[i];
209
+ const l = o.length - 1 - s;
210
+ t += r + k[l];
189
211
  }
190
212
  }
191
- return e;
213
+ return t;
192
214
  }
193
- function G(t) {
194
- return y(t);
215
+ function V(e) {
216
+ return y(e);
195
217
  }
196
- const _t = [
197
- { label: "基数读法", func: X },
218
+ const xe = [
219
+ { label: "基数读法", func: U },
198
220
  // { label: '位数读法', func: toPhoneReading },
199
221
  { 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 = {
222
+ { label: "口语读法", func: V }
223
+ ], j = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u00AD\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFE00-\uFE0F\uFEFF\uFFFD\uE000-\uF8FF]/g, X = /[\t\f\v\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, R = {
202
224
  "‘": "'",
203
225
  "’": "'",
204
226
  "‚": "'",
@@ -230,319 +252,322 @@ 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
+ }, z = new RegExp(`[${Object.keys(R).join("")}]`, "g"), G = (e) => e.replace(/[\uFF21-\uFF3A\uFF41-\uFF5A\uFF10-\uFF19]/g, (t) => String.fromCharCode(t.charCodeAt(0) - 65248)), q = (e) => G(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(j, "").replace(X, " ").replace(z, (t) => R[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
+ `), Ne = (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 = q(s.textContent || ""), s = o.nextNode();
245
267
  return n.body.innerHTML;
246
- }, Z = {
268
+ }, W = {
247
269
  minSegmentLength: 32,
248
- maxSegmentLength: 64,
270
+ maxSegmentLength: 128,
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) => {
264
- let n = 0;
265
- for (let o = 0; o < t.length; o += 1)
266
- if (n += I.test(t[o]) ? 2 : 1, n >= e)
267
- return o + 1;
268
- return t.length;
269
- }, _ = (t, e, n, o, s) => {
272
+ }, L = /[一-鿿㐀-䶿豈-﫿 -〿＀-￯]/, K = /[。!?!?\.]/, Y = /[;;]/, J = /[,,、::]/, Z = /[。!?!?,,、;;::]/, I = "", O = "", h = (e) => {
273
+ let t = 0;
274
+ for (const n of e)
275
+ t += L.test(n) ? 2 : 1;
276
+ return t;
277
+ }, Q = (e) => e.replace(/\r/g, "").split(`
278
+ `).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), ee = (e) => {
279
+ let t = e, n = "";
280
+ for (; n !== t; )
281
+ n = t, t = t.replace(/(\d),(\d)/g, `$1${I}$2`);
282
+ for (n = ""; n !== t; )
283
+ n = t, t = t.replace(/(\d)\.(\d)/g, `$1${O}$2`);
284
+ return t;
285
+ }, m = (e) => e.split(I).join(",").split(O).join("."), te = (e, t, n, o, s) => {
270
286
  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]))
287
+ const l = Math.max(1, n), c = Math.min(e.length, o);
288
+ for (let i = l; i <= c; i += 1) {
289
+ if (!s.test(e[i - 1]))
274
290
  continue;
275
- const u = Math.abs(l - e);
276
- if (u < r && (r = u, a = l), l > e && a >= 0)
291
+ const u = Math.abs(i - t);
292
+ if (u < r && (r = u, a = i), i > t && a >= 0)
277
293
  break;
278
294
  }
279
295
  return a;
280
- }, nt = (t, e, n, o) => {
296
+ }, ne = (e, t, n, o) => {
281
297
  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] !== " ")
298
+ const r = Math.max(1, n), l = Math.min(e.length, o);
299
+ for (let c = r; c <= l; c += 1) {
300
+ if (e[c - 1] !== " ")
285
301
  continue;
286
- const l = Math.abs(c - e);
287
- if (l < a && (a = l, s = c), c > e && s >= 0)
302
+ const i = Math.abs(c - t);
303
+ if (i < a && (a = i, s = c), c > t && s >= 0)
288
304
  break;
289
305
  }
290
306
  return s;
291
- }, M = (t, e, n, o, s) => {
292
- for (const r of s) {
293
- const i = _(
294
- t,
307
+ }, C = (e, t, n, o, s) => {
308
+ for (const a of s) {
309
+ const r = te(
295
310
  e,
311
+ t,
296
312
  n,
297
313
  o,
298
- r
314
+ a
299
315
  );
300
- if (i >= 0)
301
- return i;
316
+ if (r >= 0)
317
+ return r;
302
318
  }
303
- const a = nt(t, e, n, o);
304
- return a >= 0 ? a : _(
305
- t,
306
- e,
307
- n,
308
- o,
309
- Q
310
- );
311
- }, ot = (t, e) => {
319
+ return ne(e, t, n, o);
320
+ }, oe = (e, t) => {
312
321
  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(
316
- r + 1,
317
- m(o, e)
318
- );
319
- let l = M(o, r, i, c, [
320
- C,
321
- P
322
+ let o = e;
323
+ for (; o && h(o) > t; ) {
324
+ const s = h(o), a = Math.floor(s / 2);
325
+ let r = 0, l = 0, c = 0;
326
+ for (let p = 0; p < o.length; p += 1)
327
+ if (c += L.test(o[p]) ? 2 : 1, !r && c >= a && (r = p + 1), c >= t) {
328
+ l = p + 1;
329
+ break;
330
+ }
331
+ l || (l = o.length), r || (r = Math.floor(o.length / 2));
332
+ const i = Math.max(1, Math.floor(r / 3));
333
+ let u = C(o, r, i, l, [
334
+ Y,
335
+ J
322
336
  ]);
323
- (l < 0 || l >= o.length) && (l = r), n.push(o.slice(0, l).trim()), o = o.slice(l).trim();
337
+ (u < 0 || u >= o.length) && (u = r), n.push(o.slice(0, u)), o = o.slice(u);
324
338
  }
325
- 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,
335
- C,
336
- P
339
+ return o.trim() && n.push(o), n;
340
+ }, re = (e, t) => {
341
+ if (e.length <= 1)
342
+ return e;
343
+ const n = e[e.length - 1], o = e.reduce((p, T) => p + T.length, 0) / e.length, s = Math.floor(o * t);
344
+ if (n.length >= s)
345
+ return e;
346
+ const r = `${e[e.length - 2]}${n}`, l = Math.floor(r.length / 2), c = Math.max(1, Math.floor(l / 3)), i = C(r, l, c, r.length, [
347
+ Z
337
348
  ]);
338
- 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 = {}) => {
349
+ if (i <= 0 || i >= r.length)
350
+ return e;
351
+ const u = [...e];
352
+ return u[u.length - 2] = r.slice(0, i), u[u.length - 1] = r.slice(i), u.filter(Boolean);
353
+ }, se = (e, t = {}) => {
343
354
  const n = {
344
- ...Z,
345
- ...e
346
- }, o = tt(t);
355
+ ...W,
356
+ ...t
357
+ }, o = Q(e);
347
358
  if (!o)
348
359
  return [];
349
- const s = et(o);
350
- if (g(s) <= n.minSegmentLength)
351
- return [b(s)];
360
+ const s = ee(o);
361
+ if (h(s) <= n.minSegmentLength)
362
+ return [m(s)];
352
363
  const a = [], r = s.split(new RegExp("(?<=[。!?!?\\.])"));
353
- let i = "";
354
- for (const l of r) {
355
- if (!l)
364
+ let l = "";
365
+ for (const i of r) {
366
+ if (!i)
356
367
  continue;
357
- i += l;
358
- const u = i[i.length - 1] ?? "";
359
- g(i) >= n.minSegmentLength && L.test(u) && (a.push(i.trim()), i = "");
368
+ l += i;
369
+ const u = l[l.length - 1] ?? "";
370
+ h(l) >= n.minSegmentLength && K.test(u) && (a.push(l), l = "");
360
371
  }
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
372
+ l && (a.length > 0 && h(l) < n.minSegmentLength ? a[a.length - 1] += l : a.push(l));
373
+ const c = a.flatMap((i) => h(i) <= n.maxSegmentLength ? [i] : oe(i, n.maxSegmentLength));
374
+ return re(c, n.rebalanceRatio).map(
375
+ m
365
376
  );
366
- }, A = (t) => t.type === "text" ? t.text || "" : (t.content || []).map(A).join(""), it = (t) => {
367
- const e = t.content || [];
377
+ }, P = (e) => e.type === "text" ? e.text || "" : (e.content || []).map(P).join(""), le = (e) => {
378
+ const t = e.content || [];
368
379
  let n = "";
369
380
  const o = [], s = [], a = {
370
- [p.stop.type]: ({ position: r, actionCode: i }) => {
381
+ [g.stop.type]: ({ position: r, actionCode: l }) => {
371
382
  o.push({
372
383
  action: "insert",
373
384
  model: "control",
374
385
  payload: "。 ",
375
386
  position: r,
376
387
  text: "",
377
- actionCode: i
388
+ actionCode: l
378
389
  });
379
390
  },
380
- [p.customStop.type]: ({ payload: r, position: i, actionCode: c }) => {
391
+ [g.customStop.type]: ({ payload: r, position: l, actionCode: c }) => {
381
392
  o.push({
382
393
  action: "insert",
383
394
  model: "control",
384
395
  payload: `[stop:${r == null ? void 0 : r.time}]`,
385
- position: i,
396
+ position: l,
386
397
  text: "",
387
398
  actionCode: c
388
399
  });
389
400
  },
390
- [p.continue.type]: ({ position: r, text: i, actionCode: c }) => {
401
+ [g.continue.type]: ({ position: r, text: l, actionCode: c }) => {
391
402
  o.push({
392
403
  action: "replace",
393
404
  model: "replace",
394
- payload: `《${i}》`,
405
+ payload: `《${l}》`,
395
406
  position: r,
396
- text: i,
407
+ text: l,
397
408
  actionCode: c
398
409
  });
399
410
  },
400
- [p.replace.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
411
+ [g.replace.type]: ({ payload: r, position: l, text: c, actionCode: i }) => {
401
412
  o.push({
402
413
  action: "replace",
403
414
  model: "replace",
404
415
  payload: `${r == null ? void 0 : r.text}`,
405
- position: i,
416
+ position: l,
406
417
  text: c,
407
- actionCode: l
418
+ actionCode: i
408
419
  });
409
420
  },
410
- [p.pinyin.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
421
+ [g.pinyin.type]: ({ payload: r, position: l, text: c, actionCode: i }) => {
411
422
  o.push({
412
423
  action: "replace",
413
424
  model: "pinyin",
414
425
  payload: `${r == null ? void 0 : r.text}`,
415
- position: i,
426
+ position: l,
416
427
  text: c,
417
- actionCode: l
428
+ actionCode: i
418
429
  });
419
430
  },
420
- [p.language.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
431
+ [g.language.type]: ({ payload: r, position: l, text: c, actionCode: i }) => {
421
432
  o.push({
422
433
  action: "language",
423
434
  model: "language",
424
435
  payload: `${r == null ? void 0 : r.code}`,
425
- position: i,
436
+ position: l,
426
437
  text: c,
427
- actionCode: l
438
+ actionCode: i
439
+ });
440
+ },
441
+ [g.tone.type]: ({ payload: r, position: l, actionCode: c }) => {
442
+ var u;
443
+ const i = (u = S.find((p) => p.value === (r == null ? void 0 : r.code))) == null ? void 0 : u.tag;
444
+ i && o.push({
445
+ action: "insert",
446
+ model: "control",
447
+ payload: i,
448
+ position: l,
449
+ text: "",
450
+ actionCode: c
428
451
  });
429
452
  },
430
- [p.ignore.type]: ({ position: r, text: i, actionCode: c }) => {
453
+ [g.ignore.type]: ({ position: r, text: l, actionCode: c }) => {
431
454
  o.push({
432
455
  action: "replace",
433
456
  model: "replace",
434
457
  payload: " ",
435
458
  position: r,
436
- text: i,
459
+ text: l,
437
460
  actionCode: c
438
461
  });
439
462
  }
440
463
  };
441
- return e.forEach((r) => {
464
+ return t.forEach((r) => {
442
465
  var T, E;
443
466
  if (r.type === "text") {
444
467
  n += r.text || "";
445
468
  return;
446
469
  }
447
470
  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];
471
+ const l = (T = r.attrs) == null ? void 0 : T.categ, c = (E = r.attrs) == null ? void 0 : E.payload, i = n.length, u = P(r), p = a[l];
449
472
  u && s.push({
450
- start: l,
451
- end: l + u.length
452
- }), f && f({
473
+ start: i,
474
+ end: i + u.length
475
+ }), p && p({
453
476
  payload: c,
454
- position: l,
477
+ position: i,
455
478
  text: u,
456
- actionCode: i
479
+ actionCode: l
457
480
  }), n += u;
458
481
  }), {
459
482
  text: n,
460
483
  protectedRanges: s,
461
484
  playments: o
462
485
  };
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) ? [
486
+ }, b = (e) => e.type === "text" || e.type === "customTag", ae = (e) => {
487
+ const t = e.content || [];
488
+ if (e.type === "paragraph") return [e];
489
+ if (e.type === "doc")
490
+ return t.filter((o) => o.type === "paragraph");
491
+ const n = t.filter((o) => o.type === "paragraph");
492
+ return n.length ? n : t.some(b) ? [
470
493
  {
471
494
  type: "paragraph",
472
- content: e.filter(N)
495
+ content: t.filter(b)
473
496
  }
474
497
  ] : [];
475
- }, lt = (t, e) => {
498
+ }, ie = (e, t) => {
476
499
  let n = 0;
477
- return e.map((o) => {
478
- const s = t.indexOf(o, n), a = s >= 0 ? s : n, r = a + o.length;
500
+ return t.map((o) => {
501
+ const s = e.indexOf(o, n), a = s >= 0 ? s : n, r = a + o.length;
479
502
  return n = r, {
480
503
  text: o,
481
504
  start: a,
482
505
  end: r
483
506
  };
484
507
  });
485
- }, ct = (t, e) => t.reduce((n, o) => {
486
- if (e.some(
508
+ }, ce = (e, t) => e.reduce((n, o) => {
509
+ if (t.some(
487
510
  (a) => o.start > a.start && o.start < a.end
488
511
  ) && n.length) {
489
512
  const a = n[n.length - 1];
490
513
  return a.text += o.text, a.end = o.end, n;
491
514
  }
492
515
  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 || []
516
+ }, []), ue = (e, t, n, o) => e.position >= t && e.position < n ? !0 : !e.text && o && e.position === n, ge = (e) => {
517
+ const t = se(e.text);
518
+ if (t.length <= 1) return [e];
519
+ const n = ce(
520
+ ie(e.text, t),
521
+ e.protectedRanges || []
499
522
  );
500
523
  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
524
+ const a = s === n.length - 1, r = e.playments.filter(
525
+ (l) => ue(l, o.start, o.end, a)
526
+ ).map((l) => ({
527
+ ...l,
528
+ position: l.position - o.start
506
529
  }));
507
530
  return {
508
531
  text: o.text,
509
532
  playments: r
510
533
  };
511
534
  });
512
- }, xt = (t) => {
513
- const e = {
535
+ }, ye = (e) => {
536
+ const t = {
514
537
  playments: [],
515
538
  sentences: []
516
539
  };
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);
540
+ return ae(e).forEach((o) => {
541
+ const s = le(o);
542
+ !s.text && !s.playments.length || ge(s).forEach(({ text: a, playments: r }) => {
543
+ t.sentences.push(a), t.playments.push(r);
521
544
  });
522
- }), e;
545
+ }), t;
523
546
  };
524
547
  export {
525
- h as DeleteMode,
526
- gt as EditorConst,
527
- x as LanguageOptions,
528
- _t as NumberToTextTools,
548
+ f as DeleteMode,
549
+ pe as EditorConst,
550
+ _ as LanguageOptions,
551
+ xe as NumberToTextTools,
529
552
  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,
553
+ S as ToneOptions,
554
+ g as ToolConfig,
555
+ x as allToolTypes,
556
+ ye as convertToTtsFormat,
557
+ be as estimateTtsDuration,
558
+ de as getDefaultLockPayload,
559
+ me as getInitContent,
560
+ Te as getLockPayloadLabel,
561
+ h as getVisualLength,
562
+ fe as isInsertTagType,
563
+ he as isLockableTagType,
564
+ Ee as resolveTtsEditorFeatures,
565
+ Ne as sanitizePastedHtml,
566
+ q as sanitizePastedText,
567
+ se as splitTextToSentences,
568
+ U as toCardinal,
569
+ V as toColloquial,
570
+ _e as toPhoneReading,
546
571
  y as toPositional,
547
- it as transformParagraph
572
+ le as transformParagraph
548
573
  };