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