@naersen/tts-rich-text 0.12.0 → 0.12.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,7 +1,7 @@
1
1
  const h = {
2
2
  DELETE_NODE: "deleteNode",
3
3
  CONVERT_TO_TEXT: "convertToText"
4
- }, ye = 256, ve = 256, p = {
4
+ }, $t = 256, Dt = 256, p = {
5
5
  stop: {
6
6
  label: "停顿",
7
7
  icon: "editor-stop",
@@ -70,7 +70,7 @@ const h = {
70
70
  type: "ignore",
71
71
  deleteMode: h.CONVERT_TO_TEXT
72
72
  }
73
- }, U = [
73
+ }, j = [
74
74
  { label: "笑声", value: "笑声", tag: "[laughter]" },
75
75
  { label: "叹气", value: "叹气", tag: "[sigh]" },
76
76
  { label: "吸气", value: "吸气", tag: "[sniff]" },
@@ -85,21 +85,34 @@ const h = {
85
85
  { label: "惊讶(哇)", value: "惊讶(哇)", tag: "[surprise-wa]" },
86
86
  { label: "惊讶(哟)", value: "惊讶(哟)", tag: "[surprise-yo]" },
87
87
  { label: "不满", value: "不满", tag: "[dissatisfaction-hnn]" }
88
- ], x = [
88
+ ], R = [
89
89
  { value: "zh", label: "中文" },
90
90
  { value: "en", label: "英语" },
91
- { value: "jp", label: "日语" },
92
- { value: "kr", label: "韩语" },
91
+ { value: "ja", label: "日语" },
92
+ { value: "ko", label: "韩语" },
93
93
  { value: "de", label: "德语" },
94
94
  { value: "fr", label: "法语" },
95
95
  { value: "es", label: "西班牙语" },
96
96
  { value: "it", label: "意大利语" },
97
97
  { value: "pt", label: "葡萄牙语" },
98
98
  { value: "ru", label: "俄语" }
99
- ], j = [
99
+ ], z = { jp: "ja", kr: "ko" }, _ = (t) => typeof t == "string" ? z[t] ?? t : t, G = (t) => {
100
+ var o, s;
101
+ const e = (o = t.attrs) == null ? void 0 : o.payload, n = t.type === "customTag" && ((s = t.attrs) == null ? void 0 : s.categ) === "language" && _(e == null ? void 0 : e.code) !== (e == null ? void 0 : e.code);
102
+ return {
103
+ ...t,
104
+ ...n && {
105
+ attrs: {
106
+ ...t.attrs,
107
+ payload: { ...e, code: _(e.code) }
108
+ }
109
+ },
110
+ ...t.content && { content: t.content.map(G) }
111
+ };
112
+ }, X = [
100
113
  { label: "停顿 0.5 秒", value: 0.5 },
101
114
  { label: "停顿 1 秒", value: 1 }
102
- ], Fe = {
115
+ ], Bt = {
103
116
  SENTENCE: "sentence",
104
117
  CUSTOM_TAG: "customTag",
105
118
  /**
@@ -107,16 +120,16 @@ const h = {
107
120
  * 工具栏与右键面板都要用它来主动收起气泡,避免两个浮层叠在一起。
108
121
  */
109
122
  BUBBLE_MENU_KEY: "ttsRichTextBubbleMenu"
110
- }, $e = (e) => {
111
- var t;
112
- return ((t = p[e]) == null ? void 0 : t.deleteMode) === h.DELETE_NODE;
113
- }, De = (e) => e === p.stop.type || e === p.customStop.type, Be = (e) => e === p.customStop.type ? { time: j[0].value } : {}, we = (e, t) => e === p.customStop.type ? `${t == null ? void 0 : t.time} 秒` : "", R = Object.keys(p), m = {
114
- tools: R.filter((e) => e !== p.tone.type),
115
- languages: x,
123
+ }, kt = (t) => {
124
+ var e;
125
+ return ((e = p[t]) == null ? void 0 : e.deleteMode) === h.DELETE_NODE;
126
+ }, wt = (t) => t === p.stop.type || t === p.customStop.type, Ht = (t) => t === p.customStop.type ? { time: X[0].value } : {}, Vt = (t, e) => t === p.customStop.type ? `${e == null ? void 0 : e.time} 秒` : "", M = Object.keys(p), m = {
127
+ tools: M.filter((t) => t !== p.tone.type),
128
+ languages: R,
116
129
  maxPinyinLength: 4,
117
130
  maxNumberLength: 16,
118
131
  enablePreview: !0
119
- }, z = {
132
+ }, Y = {
120
133
  1: {
121
134
  tools: [
122
135
  "customStop",
@@ -129,20 +142,20 @@ const h = {
129
142
  "upload",
130
143
  "ignore"
131
144
  ],
132
- languages: x.filter((e) => ["zh", "en"].includes(e.value))
145
+ languages: R.filter((t) => ["zh", "en"].includes(t.value))
133
146
  },
134
147
  2: m,
135
- 3: { tools: R.filter((e) => e !== p.language.type) }
136
- }, He = (e, t = {}) => {
137
- const n = z[e] ?? m;
148
+ 3: { tools: M.filter((t) => t !== p.language.type) }
149
+ }, Ut = (t, e = {}) => {
150
+ const n = Y[t] ?? m;
138
151
  return {
139
152
  ...m,
140
153
  ...n,
141
- ...t,
142
- tools: t.tools ?? n.tools ?? m.tools,
143
- languages: t.languages ?? n.languages ?? m.languages
154
+ ...e,
155
+ tools: e.tools ?? n.tools ?? m.tools,
156
+ languages: e.languages ?? n.languages ?? m.languages
144
157
  };
145
- }, Ve = () => ({
158
+ }, jt = () => ({
146
159
  type: "doc",
147
160
  content: [
148
161
  {
@@ -150,13 +163,13 @@ const h = {
150
163
  content: []
151
164
  }
152
165
  ]
153
- }), G = /[\u4e00-\u9fff]/, X = /\s/g, Y = 0.28, K = 0.14, ke = (e, t = 1) => {
154
- const n = Number.isFinite(t) && t > 0 ? t : 1;
155
- return Array.from(e.replace(X, "")).reduce(
156
- (l, s) => l + (G.test(s) ? Y : K),
166
+ }), K = /[\u4e00-\u9fff]/, W = /\s/g, q = 0.28, J = 0.14, zt = (t, e = 1) => {
167
+ const n = Number.isFinite(e) && e > 0 ? e : 1;
168
+ return Array.from(t.replace(W, "")).reduce(
169
+ (s, a) => s + (K.test(a) ? q : J),
157
170
  0
158
171
  ) / n;
159
- }, M = {
172
+ }, O = {
160
173
  0: "零",
161
174
  1: "一",
162
175
  2: "二",
@@ -167,7 +180,7 @@ const h = {
167
180
  7: "七",
168
181
  8: "八",
169
182
  9: "九"
170
- }, W = {
183
+ }, Z = {
171
184
  0: "洞",
172
185
  1: "幺",
173
186
  2: "二",
@@ -178,49 +191,49 @@ const h = {
178
191
  7: "七",
179
192
  8: "八",
180
193
  9: "九"
181
- }, q = ["", "十", "百", "千"], J = ["", "万", "亿", "万亿"];
182
- function Z(e) {
183
- return e ? e.split("").map((t) => M[t] || t).join("") : "";
194
+ }, Q = ["", "十", "百", "千"], tt = ["", "万", "亿", "万亿"];
195
+ function et(t) {
196
+ return t ? t.split("").map((e) => O[e] || e).join("") : "";
184
197
  }
185
- function Ue(e) {
186
- return e ? e.split("").map((t) => W[t] || t).join("") : "";
198
+ function Gt(t) {
199
+ return t ? t.split("").map((e) => Z[e] || e).join("") : "";
187
200
  }
188
- function Q(e) {
189
- const t = e.length;
201
+ function nt(t) {
202
+ const e = t.length;
190
203
  let n = "", o = !1;
191
- for (let l = 0; l < t; l++) {
192
- const s = e[l], r = t - 1 - l;
193
- s === "0" ? !o && n !== "" && (o = !0) : (o && (n += "零", o = !1), n += M[s] + q[r]);
204
+ for (let s = 0; s < e; s++) {
205
+ const a = t[s], r = e - 1 - s;
206
+ a === "0" ? !o && n !== "" && (o = !0) : (o && (n += "零", o = !1), n += O[a] + Q[r]);
194
207
  }
195
208
  return n.startsWith("一十") && n.length === 2 && (n = n.substring(1)), n;
196
209
  }
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 = [];
202
- for (let l = n; l > 0; l -= 4) {
203
- const s = Math.max(0, l - 4);
204
- o.unshift(e.substring(s, l));
210
+ function P(t) {
211
+ if (!t) return "";
212
+ if (t === "0" || (t = t.replace(/^0+/, "") || "0", t === "0")) return "零";
213
+ let e = "";
214
+ const n = t.length, o = [];
215
+ for (let s = n; s > 0; s -= 4) {
216
+ const a = Math.max(0, s - 4);
217
+ o.unshift(t.substring(a, s));
205
218
  }
206
- for (let l = 0; l < o.length; l++) {
207
- const s = o[l], r = Q(s);
219
+ for (let s = 0; s < o.length; s++) {
220
+ const a = o[s], r = nt(a);
208
221
  if (r !== "") {
209
- const i = o.length - 1 - l;
210
- t += r + J[i];
222
+ const i = o.length - 1 - s;
223
+ e += r + tt[i];
211
224
  }
212
225
  }
213
- return t;
226
+ return e;
214
227
  }
215
- function ee(e) {
216
- return O(e);
228
+ function ot(t) {
229
+ return P(t);
217
230
  }
218
- const je = [
219
- { label: "基数读法", func: Z },
231
+ const Xt = [
232
+ { label: "基数读法", func: et },
220
233
  // { label: '位数读法', func: toPhoneReading },
221
- { label: "位数读法", func: O },
222
- { label: "口语读法", func: ee }
223
- ], te = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u00AD\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFE00-\uFE0F\uFEFF\uFFFD\uE000-\uF8FF]/g, ne = /[\t\f\v\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, P = {
234
+ { label: "位数读法", func: P },
235
+ { label: "口语读法", func: ot }
236
+ ], rt = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u00AD\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFE00-\uFE0F\uFEFF\uFFFD\uE000-\uF8FF]/g, st = /[\t\f\v\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, C = {
224
237
  "‘": "'",
225
238
  "’": "'",
226
239
  "‚": "'",
@@ -252,178 +265,178 @@ const je = [
252
265
  "︔": ";",
253
266
  "︕": "!",
254
267
  "︖": "?"
255
- }, oe = new RegExp(`[${Object.keys(P).join("")}]`, "g"), re = (e) => e.replace(/[\uFF21-\uFF3A\uFF41-\uFF5A\uFF10-\uFF19]/g, (t) => String.fromCharCode(t.charCodeAt(0) - 65248)), se = (e) => re(e).replace(/\r\n?/g, `
268
+ }, at = new RegExp(`[${Object.keys(C).join("")}]`, "g"), it = (t) => t.replace(/[\uFF21-\uFF3A\uFF41-\uFF5A\uFF10-\uFF19]/g, (e) => String.fromCharCode(e.charCodeAt(0) - 65248)), lt = (t) => it(t).replace(/\r\n?/g, `
256
269
  `).replace(/[\u2028\u2029]/g, `
257
- `).replace(te, "").replace(ne, " ").replace(oe, (t) => P[t] || "").replace(/ *\n */g, `
270
+ `).replace(rt, "").replace(st, " ").replace(at, (e) => C[e] || "").replace(/ *\n */g, `
258
271
  `).replace(/\n{3,}/g, `
259
272
 
260
- `), ze = (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);
264
- let l = o.nextNode();
265
- for (; l; )
266
- l.textContent = se(l.textContent || ""), l = o.nextNode();
273
+ `), Yt = (t) => {
274
+ if (typeof window > "u" || !t)
275
+ return t;
276
+ const n = new DOMParser().parseFromString(t, "text/html"), o = n.createTreeWalker(n.body, NodeFilter.SHOW_TEXT);
277
+ let s = o.nextNode();
278
+ for (; s; )
279
+ s.textContent = lt(s.textContent || ""), s = o.nextNode();
267
280
  return n.body.innerHTML;
268
- }, ie = {
281
+ }, ct = {
269
282
  minSegmentLength: 32,
270
283
  maxSegmentLength: 128,
271
284
  rebalanceRatio: 0.4
272
- }, A = /[一-鿿㐀-䶿豈-﫿 -〿＀-￯]/, le = /[。!?!?\.]/, ae = /[;;]/, ce = /[,,、::]/, ue = /[。!?!?,,、;;::]/, C = "", y = "", T = (e) => {
273
- let t = 0;
274
- for (const n of e)
275
- t += A.test(n) ? 2 : 1;
276
- return t;
277
- }, ge = (e) => e.replace(/\r/g, "").split(`
278
- `).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), pe = (e) => {
279
- let t = e, n = "";
280
- for (; n !== t; )
281
- n = t, t = t.replace(/(\d),(\d)/g, `$1${C}$2`);
282
- for (n = ""; n !== t; )
283
- n = t, t = t.replace(/(\d)\.(\d)/g, `$1${y}$2`);
284
- return t;
285
- }, N = (e) => e.split(C).join(",").split(y).join("."), he = (e, t, n, o, l) => {
286
- let s = -1, r = Number.POSITIVE_INFINITY;
287
- const i = Math.max(1, n), c = Math.min(e.length, o);
288
- for (let a = i; a <= c; a += 1) {
289
- if (!l.test(e[a - 1]))
285
+ }, y = /[一-鿿㐀-䶿豈-﫿 -〿＀-￯]/, ut = /[。!?!?\.]/, gt = /[;;]/, pt = /[,,、::]/, ht = /[。!?!?,,、;;::]/, A = "", v = "", d = (t) => {
286
+ let e = 0;
287
+ for (const n of t)
288
+ e += y.test(n) ? 2 : 1;
289
+ return e;
290
+ }, ft = (t) => t.replace(/\r/g, "").split(`
291
+ `).map((e) => e.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), Et = (t) => {
292
+ let e = t, n = "";
293
+ for (; n !== e; )
294
+ n = e, e = e.replace(/(\d),(\d)/g, `$1${A}$2`);
295
+ for (n = ""; n !== e; )
296
+ n = e, e = e.replace(/(\d)\.(\d)/g, `$1${v}$2`);
297
+ return e;
298
+ }, L = (t) => t.split(A).join(",").split(v).join("."), Tt = (t, e, n, o, s) => {
299
+ let a = -1, r = Number.POSITIVE_INFINITY;
300
+ const i = Math.max(1, n), c = Math.min(t.length, o);
301
+ for (let l = i; l <= c; l += 1) {
302
+ if (!s.test(t[l - 1]))
290
303
  continue;
291
- const u = Math.abs(a - t);
292
- if (u < r && (r = u, s = a), a > t && s >= 0)
304
+ const u = Math.abs(l - e);
305
+ if (u < r && (r = u, a = l), l > e && a >= 0)
293
306
  break;
294
307
  }
295
- return s;
296
- }, fe = (e, t, n, o) => {
297
- let l = -1, s = Number.POSITIVE_INFINITY;
298
- const r = Math.max(1, n), i = Math.min(e.length, o);
308
+ return a;
309
+ }, dt = (t, e, n, o) => {
310
+ let s = -1, a = Number.POSITIVE_INFINITY;
311
+ const r = Math.max(1, n), i = Math.min(t.length, o);
299
312
  for (let c = r; c <= i; c += 1) {
300
- if (e[c - 1] !== " ")
313
+ if (t[c - 1] !== " ")
301
314
  continue;
302
- const a = Math.abs(c - t);
303
- if (a < s && (s = a, l = c), c > t && l >= 0)
315
+ const l = Math.abs(c - e);
316
+ if (l < a && (a = l, s = c), c > e && s >= 0)
304
317
  break;
305
318
  }
306
- return l;
307
- }, v = (e, t, n, o, l) => {
308
- for (const s of l) {
309
- const r = he(
310
- e,
319
+ return s;
320
+ }, F = (t, e, n, o, s) => {
321
+ for (const a of s) {
322
+ const r = Tt(
311
323
  t,
324
+ e,
312
325
  n,
313
326
  o,
314
- s
327
+ a
315
328
  );
316
329
  if (r >= 0)
317
330
  return r;
318
331
  }
319
- return fe(e, t, n, o);
320
- }, Ee = (e, t) => {
332
+ return dt(t, e, n, o);
333
+ }, mt = (t, e) => {
321
334
  const n = [];
322
- let o = e;
323
- for (; o && T(o) > t; ) {
324
- const l = T(o), s = Math.floor(l / 2);
335
+ let o = t;
336
+ for (; o && d(o) > e; ) {
337
+ const s = d(o), a = Math.floor(s / 2);
325
338
  let r = 0, i = 0, c = 0;
326
339
  for (let g = 0; g < o.length; g += 1)
327
- if (c += A.test(o[g]) ? 2 : 1, !r && c >= s && (r = g + 1), c >= t) {
340
+ if (c += y.test(o[g]) ? 2 : 1, !r && c >= a && (r = g + 1), c >= e) {
328
341
  i = g + 1;
329
342
  break;
330
343
  }
331
344
  i || (i = o.length), r || (r = Math.floor(o.length / 2));
332
- const a = Math.max(1, Math.floor(r / 3));
333
- let u = v(o, r, a, i, [
334
- ae,
335
- ce
345
+ const l = Math.max(1, Math.floor(r / 3));
346
+ let u = F(o, r, l, i, [
347
+ gt,
348
+ pt
336
349
  ]);
337
350
  (u < 0 || u >= o.length) && (u = r), n.push(o.slice(0, u)), o = o.slice(u);
338
351
  }
339
352
  return o.trim() && n.push(o), n;
340
- }, de = (e, t) => {
341
- if (e.length <= 1)
342
- return e;
343
- const n = e[e.length - 1], o = e.reduce((g, E) => g + E.length, 0) / e.length, l = Math.floor(o * t);
344
- if (n.length >= l)
345
- return e;
346
- const r = `${e[e.length - 2]}${n}`, i = Math.floor(r.length / 2), c = Math.max(1, Math.floor(i / 3)), a = v(r, i, c, r.length, [
347
- ue
353
+ }, bt = (t, e) => {
354
+ if (t.length <= 1)
355
+ return t;
356
+ const n = t[t.length - 1], o = t.reduce((g, E) => g + E.length, 0) / t.length, s = Math.floor(o * e);
357
+ if (n.length >= s)
358
+ return t;
359
+ const r = `${t[t.length - 2]}${n}`, i = Math.floor(r.length / 2), c = Math.max(1, Math.floor(i / 3)), l = F(r, i, c, r.length, [
360
+ ht
348
361
  ]);
349
- if (a <= 0 || a >= r.length)
350
- return e;
351
- const u = [...e];
352
- return u[u.length - 2] = r.slice(0, a), u[u.length - 1] = r.slice(a), u.filter(Boolean);
353
- }, Te = (e, t = {}) => {
362
+ if (l <= 0 || l >= r.length)
363
+ return t;
364
+ const u = [...t];
365
+ return u[u.length - 2] = r.slice(0, l), u[u.length - 1] = r.slice(l), u.filter(Boolean);
366
+ }, _t = (t, e = {}) => {
354
367
  const n = {
355
- ...ie,
356
- ...t
357
- }, o = ge(e);
368
+ ...ct,
369
+ ...e
370
+ }, o = ft(t);
358
371
  if (!o)
359
372
  return [];
360
- const l = pe(o);
361
- if (T(l) <= n.minSegmentLength)
362
- return [N(l)];
363
- const s = [], r = l.split(new RegExp("(?<=[。!?!?\\.])"));
373
+ const s = Et(o);
374
+ if (d(s) <= n.minSegmentLength)
375
+ return [L(s)];
376
+ const a = [], r = s.split(new RegExp("(?<=[。!?!?\\.])"));
364
377
  let i = "";
365
- for (const a of r) {
366
- if (!a)
378
+ for (const l of r) {
379
+ if (!l)
367
380
  continue;
368
- i += a;
381
+ i += l;
369
382
  const u = i[i.length - 1] ?? "";
370
- T(i) >= n.minSegmentLength && le.test(u) && (s.push(i), i = "");
383
+ d(i) >= n.minSegmentLength && ut.test(u) && (a.push(i), i = "");
371
384
  }
372
- i && (s.length > 0 && T(i) < n.minSegmentLength ? s[s.length - 1] += i : s.push(i));
373
- const c = s.flatMap((a) => T(a) <= n.maxSegmentLength ? [a] : Ee(a, n.maxSegmentLength));
374
- return de(c, n.rebalanceRatio).map(
375
- N
385
+ i && (a.length > 0 && d(i) < n.minSegmentLength ? a[a.length - 1] += i : a.push(i));
386
+ const c = a.flatMap((l) => d(l) <= n.maxSegmentLength ? [l] : mt(l, n.maxSegmentLength));
387
+ return bt(c, n.rebalanceRatio).map(
388
+ L
376
389
  );
377
- }, d = {
390
+ }, T = {
378
391
  minSegmentLength: 32,
379
392
  maxSegmentLength: 64,
380
393
  rebalanceRatio: 0.4
381
- }, F = /[一-鿿㐀-䶿豈-﫿 -〿＀-￯]/, $ = /[。!?!?\.]/, D = /[;;]/, B = /[,,::]/, me = /[、]/, w = "", H = "", f = (e) => {
382
- let t = 0;
383
- for (const n of e)
384
- t += F.test(n) ? 2 : 1;
385
- return t;
386
- }, be = (e) => e.replace(/\r/g, "").split(`
387
- `).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), _e = (e) => {
388
- let t = e, n = "";
389
- for (; n !== t; )
390
- n = t, t = t.replace(/(\d),(\d)/g, `$1${w}$2`);
391
- for (n = ""; n !== t; )
392
- n = t, t = t.replace(/(\d)\.(\d)/g, `$1${H}$2`);
393
- return t;
394
- }, L = (e) => e.split(w).join(",").split(H).join("."), _ = (e, t) => {
394
+ }, $ = /[一-鿿㐀-䶿豈-﫿 -〿＀-￯]/, D = /[。!?!?\.]/, B = /[;;]/, k = /[,,::]/, Nt = /[、]/, w = "", H = "", f = (t) => {
395
+ let e = 0;
396
+ for (const n of t)
397
+ e += $.test(n) ? 2 : 1;
398
+ return e;
399
+ }, Lt = (t) => t.replace(/\r/g, "").split(`
400
+ `).map((e) => e.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), It = (t) => {
401
+ let e = t, n = "";
402
+ for (; n !== e; )
403
+ n = e, e = e.replace(/(\d),(\d)/g, `$1${w}$2`);
404
+ for (n = ""; n !== e; )
405
+ n = e, e = e.replace(/(\d)\.(\d)/g, `$1${H}$2`);
406
+ return e;
407
+ }, I = (t) => t.split(w).join(",").split(H).join("."), N = (t, e) => {
395
408
  let n = 0;
396
- for (let o = 0; o < e.length; o += 1)
397
- if (n += F.test(e[o]) ? 2 : 1, n >= t)
409
+ for (let o = 0; o < t.length; o += 1)
410
+ if (n += $.test(t[o]) ? 2 : 1, n >= e)
398
411
  return o + 1;
399
- return e.length;
400
- }, I = (e, t, n, o, l) => {
401
- let s = -1, r = Number.POSITIVE_INFINITY;
402
- const i = Math.max(1, n), c = Math.min(e.length - 1, o);
403
- for (let a = i; a <= c; a += 1) {
404
- if (!l.test(e[a - 1]))
412
+ return t.length;
413
+ }, S = (t, e, n, o, s) => {
414
+ let a = -1, r = Number.POSITIVE_INFINITY;
415
+ const i = Math.max(1, n), c = Math.min(t.length - 1, o);
416
+ for (let l = i; l <= c; l += 1) {
417
+ if (!s.test(t[l - 1]))
405
418
  continue;
406
- const u = Math.abs(a - t);
407
- if (u < r && (r = u, s = a), a > t && s >= 0)
419
+ const u = Math.abs(l - e);
420
+ if (u < r && (r = u, a = l), l > e && a >= 0)
408
421
  break;
409
422
  }
410
- return s;
411
- }, Ne = (e, t, n, o) => {
412
- let l = -1, s = Number.POSITIVE_INFINITY;
413
- const r = Math.max(1, n), i = Math.min(e.length - 1, o);
423
+ return a;
424
+ }, St = (t, e, n, o) => {
425
+ let s = -1, a = Number.POSITIVE_INFINITY;
426
+ const r = Math.max(1, n), i = Math.min(t.length - 1, o);
414
427
  for (let c = r; c <= i; c += 1) {
415
- if (e[c - 1] !== " ")
428
+ if (t[c - 1] !== " ")
416
429
  continue;
417
- const a = Math.abs(c - t);
418
- if (a < s && (s = a, l = c), c > t && l >= 0)
430
+ const l = Math.abs(c - e);
431
+ if (l < a && (a = l, s = c), c > e && s >= 0)
419
432
  break;
420
433
  }
421
- return l;
422
- }, V = (e, t, n, o, l) => {
423
- for (const r of l) {
424
- const i = I(
425
- e,
434
+ return s;
435
+ }, V = (t, e, n, o, s) => {
436
+ for (const r of s) {
437
+ const i = S(
426
438
  t,
439
+ e,
427
440
  n,
428
441
  o,
429
442
  r
@@ -431,71 +444,71 @@ const je = [
431
444
  if (i >= 0)
432
445
  return i;
433
446
  }
434
- const s = Ne(e, t, n, o);
435
- return s >= 0 ? s : I(
436
- e,
447
+ const a = St(t, e, n, o);
448
+ return a >= 0 ? a : S(
437
449
  t,
450
+ e,
438
451
  n,
439
452
  o,
440
- me
453
+ Nt
441
454
  );
442
- }, Le = (e, t) => {
455
+ }, xt = (t, e) => {
443
456
  const n = [];
444
- let o = e.trim();
445
- for (; o && f(o) > t; ) {
446
- const l = f(o), s = Math.min(Math.floor(l / 2), t), r = _(o, s), i = Math.max(1, Math.floor(r / 3)), c = Math.max(
457
+ let o = t.trim();
458
+ for (; o && f(o) > e; ) {
459
+ const s = f(o), a = Math.min(Math.floor(s / 2), e), r = N(o, a), i = Math.max(1, Math.floor(r / 3)), c = Math.max(
447
460
  r + 1,
448
- _(o, t)
461
+ N(o, e)
449
462
  );
450
- let a = V(o, r, i, c, [
451
- D,
452
- B
463
+ let l = V(o, r, i, c, [
464
+ B,
465
+ k
453
466
  ]);
454
- (a < 0 || a >= o.length) && (a = r), n.push(o.slice(0, a).trim()), o = o.slice(a).trim();
467
+ (l < 0 || l >= o.length) && (l = r), n.push(o.slice(0, l).trim()), o = o.slice(l).trim();
455
468
  }
456
469
  return o && n.push(o), n;
457
- }, Ie = (e, t) => {
458
- if (e.length <= 1)
459
- return e;
460
- const n = e[e.length - 1], o = e.reduce((E, b) => E + f(b), 0) / e.length, l = Math.floor(o * t);
461
- if (f(n) >= l)
462
- return e;
463
- const r = `${e[e.length - 2]}${n}`, i = Math.floor(f(r) / 2), c = _(r, i), a = Math.max(1, Math.floor(c / 3));
464
- let u = V(r, c, a, r.length, [
465
- $,
470
+ }, Rt = (t, e) => {
471
+ if (t.length <= 1)
472
+ return t;
473
+ const n = t[t.length - 1], o = t.reduce((E, b) => E + f(b), 0) / t.length, s = Math.floor(o * e);
474
+ if (f(n) >= s)
475
+ return t;
476
+ const r = `${t[t.length - 2]}${n}`, i = Math.floor(f(r) / 2), c = N(r, i), l = Math.max(1, Math.floor(c / 3));
477
+ let u = V(r, c, l, r.length, [
466
478
  D,
467
- B
479
+ B,
480
+ k
468
481
  ]);
469
482
  if (u <= 0 || u >= r.length)
470
- return e;
471
- const g = [...e];
483
+ return t;
484
+ const g = [...t];
472
485
  return g[g.length - 2] = r.slice(0, u).trim(), g[g.length - 1] = r.slice(u).trim(), g.filter(Boolean);
473
- }, Se = (e) => {
474
- const t = be(e);
475
- if (!t)
486
+ }, Mt = (t) => {
487
+ const e = Lt(t);
488
+ if (!e)
476
489
  return [];
477
- const n = _e(t);
478
- if (f(n) <= d.minSegmentLength)
479
- return [L(n)];
480
- const o = [], l = n.split(new RegExp("(?<=[。!?!?\\.])"));
481
- let s = "";
482
- for (const i of l) {
490
+ const n = It(e);
491
+ if (f(n) <= T.minSegmentLength)
492
+ return [I(n)];
493
+ const o = [], s = n.split(new RegExp("(?<=[。!?!?\\.])"));
494
+ let a = "";
495
+ for (const i of s) {
483
496
  if (!i)
484
497
  continue;
485
- s += i;
486
- const c = s[s.length - 1] ?? "";
487
- f(s) >= d.minSegmentLength && $.test(c) && (o.push(s.trim()), s = "");
498
+ a += i;
499
+ const c = a[a.length - 1] ?? "";
500
+ f(a) >= T.minSegmentLength && D.test(c) && (o.push(a.trim()), a = "");
488
501
  }
489
- s && (o.length > 0 && f(s) < d.minSegmentLength ? o[o.length - 1] += s : o.push(s.trim()));
490
- const r = o.flatMap((i) => f(i) <= d.maxSegmentLength ? [i] : Le(i, d.maxSegmentLength));
491
- return Ie(
502
+ a && (o.length > 0 && f(a) < T.minSegmentLength ? o[o.length - 1] += a : o.push(a.trim()));
503
+ const r = o.flatMap((i) => f(i) <= T.maxSegmentLength ? [i] : xt(i, T.maxSegmentLength));
504
+ return Rt(
492
505
  r,
493
- d.rebalanceRatio
494
- ).map(L);
495
- }, xe = (e, t = {}) => t.strategy === "legacy" ? Se(e) : Te(e, t), k = (e) => e.type === "text" ? e.text || "" : (e.content || []).map(k).join(""), Re = (e) => {
496
- const t = e.content || [];
506
+ T.rebalanceRatio
507
+ ).map(I);
508
+ }, Ot = (t, e = {}) => e.strategy === "legacy" ? Mt(t) : _t(t, e), U = (t) => t.type === "text" ? t.text || "" : (t.content || []).map(U).join(""), Pt = (t) => {
509
+ const e = t.content || [];
497
510
  let n = "";
498
- const o = [], l = [], s = {
511
+ const o = [], s = [], a = {
499
512
  [p.stop.type]: ({ position: r, actionCode: i }) => {
500
513
  o.push({
501
514
  action: "insert",
@@ -526,43 +539,43 @@ const je = [
526
539
  actionCode: c
527
540
  });
528
541
  },
529
- [p.replace.type]: ({ payload: r, position: i, text: c, actionCode: a }) => {
542
+ [p.replace.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
530
543
  o.push({
531
544
  action: "replace",
532
545
  model: "replace",
533
546
  payload: `${r == null ? void 0 : r.text}`,
534
547
  position: i,
535
548
  text: c,
536
- actionCode: a
549
+ actionCode: l
537
550
  });
538
551
  },
539
- [p.pinyin.type]: ({ payload: r, position: i, text: c, actionCode: a }) => {
552
+ [p.pinyin.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
540
553
  o.push({
541
554
  action: "replace",
542
555
  model: "pinyin",
543
556
  payload: `${r == null ? void 0 : r.text}`,
544
557
  position: i,
545
558
  text: c,
546
- actionCode: a
559
+ actionCode: l
547
560
  });
548
561
  },
549
- [p.language.type]: ({ payload: r, position: i, text: c, actionCode: a }) => {
562
+ [p.language.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
550
563
  o.push({
551
564
  action: "language",
552
565
  model: "language",
553
- payload: `${r == null ? void 0 : r.code}`,
566
+ payload: `${_(r == null ? void 0 : r.code)}`,
554
567
  position: i,
555
568
  text: c,
556
- actionCode: a
569
+ actionCode: l
557
570
  });
558
571
  },
559
572
  [p.tone.type]: ({ payload: r, position: i, actionCode: c }) => {
560
573
  var u;
561
- const a = (u = U.find((g) => g.value === (r == null ? void 0 : r.code))) == null ? void 0 : u.tag;
562
- a && o.push({
574
+ const l = (u = j.find((g) => g.value === (r == null ? void 0 : r.code))) == null ? void 0 : u.tag;
575
+ l && o.push({
563
576
  action: "insert",
564
577
  model: "control",
565
- payload: a,
578
+ payload: l,
566
579
  position: i,
567
580
  text: "",
568
581
  actionCode: c
@@ -579,85 +592,85 @@ const je = [
579
592
  });
580
593
  }
581
594
  };
582
- return t.forEach((r) => {
595
+ return e.forEach((r) => {
583
596
  var E, b;
584
597
  if (r.type === "text") {
585
598
  n += r.text || "";
586
599
  return;
587
600
  }
588
601
  if (r.type !== "customTag") return;
589
- const i = (E = r.attrs) == null ? void 0 : E.categ, c = (b = r.attrs) == null ? void 0 : b.payload, a = n.length, u = k(r), g = s[i];
590
- u && l.push({
591
- start: a,
592
- end: a + u.length
602
+ const i = (E = r.attrs) == null ? void 0 : E.categ, c = (b = r.attrs) == null ? void 0 : b.payload, l = n.length, u = U(r), g = a[i];
603
+ u && s.push({
604
+ start: l,
605
+ end: l + u.length
593
606
  }), g && g({
594
607
  payload: c,
595
- position: a,
608
+ position: l,
596
609
  text: u,
597
610
  actionCode: i
598
611
  }), n += u;
599
612
  }), {
600
613
  text: n,
601
- protectedRanges: l,
614
+ protectedRanges: s,
602
615
  playments: o
603
616
  };
604
- }, S = (e) => e.type === "text" || e.type === "customTag", Me = (e) => {
605
- const t = e.content || [];
606
- if (e.type === "paragraph") return [e];
607
- if (e.type === "doc")
608
- return t.filter((o) => o.type === "paragraph");
609
- const n = t.filter((o) => o.type === "paragraph");
610
- return n.length ? n : t.some(S) ? [
617
+ }, x = (t) => t.type === "text" || t.type === "customTag", Ct = (t) => {
618
+ const e = t.content || [];
619
+ if (t.type === "paragraph") return [t];
620
+ if (t.type === "doc")
621
+ return e.filter((o) => o.type === "paragraph");
622
+ const n = e.filter((o) => o.type === "paragraph");
623
+ return n.length ? n : e.some(x) ? [
611
624
  {
612
625
  type: "paragraph",
613
- content: t.filter(S)
626
+ content: e.filter(x)
614
627
  }
615
628
  ] : [];
616
- }, Oe = (e, t) => {
629
+ }, yt = (t, e) => {
617
630
  let n = 0;
618
- return t.map((o) => {
619
- const l = e.indexOf(o, n), s = l >= 0 ? l : n, r = s + o.length;
631
+ return e.map((o) => {
632
+ const s = t.indexOf(o, n), a = s >= 0 ? s : n, r = a + o.length;
620
633
  return n = r, {
621
634
  text: o,
622
- start: s,
635
+ start: a,
623
636
  end: r
624
637
  };
625
638
  });
626
- }, Pe = (e, t) => e.reduce((n, o) => {
627
- if (t.some(
628
- (s) => o.start > s.start && o.start < s.end
639
+ }, At = (t, e) => t.reduce((n, o) => {
640
+ if (e.some(
641
+ (a) => o.start > a.start && o.start < a.end
629
642
  ) && n.length) {
630
- const s = n[n.length - 1];
631
- return s.text += o.text, s.end = o.end, n;
643
+ const a = n[n.length - 1];
644
+ return a.text += o.text, a.end = o.end, n;
632
645
  }
633
646
  return n.push({ ...o }), n;
634
- }, []), Ae = (e, t, n, o) => e.position >= t && e.position < n ? !0 : !e.text && o && e.position === n, Ce = (e, t) => {
635
- const n = xe(e.text, t);
636
- if (n.length <= 1) return [e];
637
- const o = Pe(
638
- Oe(e.text, n),
639
- e.protectedRanges || []
647
+ }, []), vt = (t, e, n, o) => t.position >= e && t.position < n ? !0 : !t.text && o && t.position === n, Ft = (t, e) => {
648
+ const n = Ot(t.text, e);
649
+ if (n.length <= 1) return [t];
650
+ const o = At(
651
+ yt(t.text, n),
652
+ t.protectedRanges || []
640
653
  );
641
- return o.map((l, s) => {
642
- const r = s === o.length - 1, i = e.playments.filter(
643
- (c) => Ae(c, l.start, l.end, r)
654
+ return o.map((s, a) => {
655
+ const r = a === o.length - 1, i = t.playments.filter(
656
+ (c) => vt(c, s.start, s.end, r)
644
657
  ).map((c) => ({
645
658
  ...c,
646
- position: c.position - l.start
659
+ position: c.position - s.start
647
660
  }));
648
661
  return {
649
- text: l.text,
662
+ text: s.text,
650
663
  playments: i
651
664
  };
652
665
  });
653
- }, Ge = (e, t = {}) => {
666
+ }, Kt = (t, e = {}) => {
654
667
  const n = {
655
668
  playments: [],
656
669
  sentences: []
657
670
  };
658
- return Me(e).forEach((l) => {
659
- const s = Re(l);
660
- !s.text && !s.playments.length || Ce(s, t).forEach(
671
+ return Ct(t).forEach((s) => {
672
+ const a = Pt(s);
673
+ !a.text && !a.playments.length || Ft(a, e).forEach(
661
674
  ({ text: r, playments: i }) => {
662
675
  n.sentences.push(r), n.playments.push(i);
663
676
  }
@@ -666,30 +679,32 @@ const je = [
666
679
  };
667
680
  export {
668
681
  h as DeleteMode,
669
- Fe as EditorConst,
670
- x as LanguageOptions,
671
- ve as MAX_LANGUAGE_SELECTION_LENGTH,
672
- ye as MAX_REPLACEMENT_TEXT_LENGTH,
673
- je as NumberToTextTools,
674
- j as StopOptions,
675
- U as ToneOptions,
682
+ Bt as EditorConst,
683
+ R as LanguageOptions,
684
+ Dt as MAX_LANGUAGE_SELECTION_LENGTH,
685
+ $t as MAX_REPLACEMENT_TEXT_LENGTH,
686
+ Xt as NumberToTextTools,
687
+ X as StopOptions,
688
+ j as ToneOptions,
676
689
  p as ToolConfig,
677
- R as allToolTypes,
678
- Ge as convertToTtsFormat,
679
- ke as estimateTtsDuration,
680
- Be as getDefaultLockPayload,
681
- Ve as getInitContent,
682
- we as getLockPayloadLabel,
683
- T as getVisualLength,
684
- $e as isInsertTagType,
685
- De as isLockableTagType,
686
- He as resolveTtsEditorFeatures,
687
- ze as sanitizePastedHtml,
688
- se as sanitizePastedText,
689
- xe as splitTextToSentences,
690
- Z as toCardinal,
691
- ee as toColloquial,
692
- Ue as toPhoneReading,
693
- O as toPositional,
694
- Re as transformParagraph
690
+ M as allToolTypes,
691
+ Kt as convertToTtsFormat,
692
+ zt as estimateTtsDuration,
693
+ Ht as getDefaultLockPayload,
694
+ jt as getInitContent,
695
+ Vt as getLockPayloadLabel,
696
+ d as getVisualLength,
697
+ kt as isInsertTagType,
698
+ wt as isLockableTagType,
699
+ _ as normalizeLanguageCode,
700
+ G as normalizeTtsContent,
701
+ Ut as resolveTtsEditorFeatures,
702
+ Yt as sanitizePastedHtml,
703
+ lt as sanitizePastedText,
704
+ Ot as splitTextToSentences,
705
+ et as toCardinal,
706
+ ot as toColloquial,
707
+ Gt as toPhoneReading,
708
+ P as toPositional,
709
+ Pt as transformParagraph
695
710
  };