@naersen/tts-rich-text 0.12.0 → 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
- }, ye = 256, ve = 256, p = {
4
+ }, $e = 256, De = 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" }, _ = (e) => typeof e == "string" ? z[e] ?? e : e, G = (e) => {
100
+ var o, s;
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
+ return {
103
+ ...e,
104
+ ...n && {
105
+ attrs: {
106
+ ...e.attrs,
107
+ payload: { ...t, code: _(t.code) }
108
+ }
109
+ },
110
+ ...e.content && { content: e.content.map(G) }
111
+ };
112
+ }, X = [
100
113
  { label: "停顿 0.5 秒", value: 0.5 },
101
114
  { label: "停顿 1 秒", value: 1 }
102
- ], Fe = {
115
+ ], Be = {
103
116
  SENTENCE: "sentence",
104
117
  CUSTOM_TAG: "customTag",
105
118
  /**
@@ -107,16 +120,19 @@ const h = {
107
120
  * 工具栏与右键面板都要用它来主动收起气泡,避免两个浮层叠在一起。
108
121
  */
109
122
  BUBBLE_MENU_KEY: "ttsRichTextBubbleMenu"
110
- }, $e = (e) => {
123
+ }, He = (e) => {
111
124
  var t;
112
125
  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,
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
+ languages: R,
116
129
  maxPinyinLength: 4,
117
130
  maxNumberLength: 16,
118
- enablePreview: !0
119
- }, z = {
131
+ enablePreview: !0,
132
+ enableContextMenu: !0,
133
+ // 保持已有业务项目的试听表现,需要句子高亮时由项目显式开启。
134
+ enableSentenceHighlight: !1
135
+ }, Y = {
120
136
  1: {
121
137
  tools: [
122
138
  "customStop",
@@ -129,12 +145,12 @@ const h = {
129
145
  "upload",
130
146
  "ignore"
131
147
  ],
132
- languages: x.filter((e) => ["zh", "en"].includes(e.value))
148
+ languages: R.filter((e) => ["zh", "en"].includes(e.value))
133
149
  },
134
150
  2: m,
135
- 3: { tools: R.filter((e) => e !== p.language.type) }
136
- }, He = (e, t = {}) => {
137
- const n = z[e] ?? m;
151
+ 3: { tools: M.filter((e) => e !== p.language.type) }
152
+ }, Ue = (e, t = {}) => {
153
+ const n = Y[e] ?? m;
138
154
  return {
139
155
  ...m,
140
156
  ...n,
@@ -142,7 +158,7 @@ const h = {
142
158
  tools: t.tools ?? n.tools ?? m.tools,
143
159
  languages: t.languages ?? n.languages ?? m.languages
144
160
  };
145
- }, Ve = () => ({
161
+ }, je = () => ({
146
162
  type: "doc",
147
163
  content: [
148
164
  {
@@ -150,13 +166,13 @@ const h = {
150
166
  content: []
151
167
  }
152
168
  ]
153
- }), G = /[\u4e00-\u9fff]/, X = /\s/g, Y = 0.28, K = 0.14, ke = (e, t = 1) => {
169
+ }), K = /[\u4e00-\u9fff]/, W = /\s/g, q = 0.28, J = 0.14, ze = (e, t = 1) => {
154
170
  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),
171
+ return Array.from(e.replace(W, "")).reduce(
172
+ (s, a) => s + (K.test(a) ? q : J),
157
173
  0
158
174
  ) / n;
159
- }, M = {
175
+ }, O = {
160
176
  0: "零",
161
177
  1: "一",
162
178
  2: "二",
@@ -167,7 +183,7 @@ const h = {
167
183
  7: "七",
168
184
  8: "八",
169
185
  9: "九"
170
- }, W = {
186
+ }, Z = {
171
187
  0: "洞",
172
188
  1: "幺",
173
189
  2: "二",
@@ -178,49 +194,49 @@ const h = {
178
194
  7: "七",
179
195
  8: "八",
180
196
  9: "九"
181
- }, q = ["", "十", "百", "千"], J = ["", "万", "亿", "万亿"];
182
- function Z(e) {
183
- return e ? e.split("").map((t) => M[t] || t).join("") : "";
197
+ }, Q = ["", "十", "百", "千"], ee = ["", "万", "亿", "万亿"];
198
+ function te(e) {
199
+ return e ? e.split("").map((t) => O[t] || t).join("") : "";
184
200
  }
185
- function Ue(e) {
186
- return e ? e.split("").map((t) => W[t] || t).join("") : "";
201
+ function Ge(e) {
202
+ return e ? e.split("").map((t) => Z[t] || t).join("") : "";
187
203
  }
188
- function Q(e) {
204
+ function ne(e) {
189
205
  const t = e.length;
190
206
  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]);
207
+ for (let s = 0; s < t; s++) {
208
+ const a = e[s], r = t - 1 - s;
209
+ a === "0" ? !o && n !== "" && (o = !0) : (o && (n += "零", o = !1), n += O[a] + Q[r]);
194
210
  }
195
211
  return n.startsWith("一十") && n.length === 2 && (n = n.substring(1)), n;
196
212
  }
197
- function O(e) {
213
+ function P(e) {
198
214
  if (!e) return "";
199
215
  if (e === "0" || (e = e.replace(/^0+/, "") || "0", e === "0")) return "零";
200
216
  let t = "";
201
217
  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));
218
+ for (let s = n; s > 0; s -= 4) {
219
+ const a = Math.max(0, s - 4);
220
+ o.unshift(e.substring(a, s));
205
221
  }
206
- for (let l = 0; l < o.length; l++) {
207
- const s = o[l], r = Q(s);
222
+ for (let s = 0; s < o.length; s++) {
223
+ const a = o[s], r = ne(a);
208
224
  if (r !== "") {
209
- const i = o.length - 1 - l;
210
- t += r + J[i];
225
+ const i = o.length - 1 - s;
226
+ t += r + ee[i];
211
227
  }
212
228
  }
213
229
  return t;
214
230
  }
215
- function ee(e) {
216
- return O(e);
231
+ function oe(e) {
232
+ return P(e);
217
233
  }
218
- const je = [
219
- { label: "基数读法", func: Z },
234
+ const Xe = [
235
+ { label: "基数读法", func: te },
220
236
  // { 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 = {
237
+ { label: "位数读法", func: P },
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 = {
224
240
  "‘": "'",
225
241
  "’": "'",
226
242
  "‚": "'",
@@ -252,175 +268,175 @@ const je = [
252
268
  "︔": ";",
253
269
  "︕": "!",
254
270
  "︖": "?"
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, `
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, `
256
272
  `).replace(/[\u2028\u2029]/g, `
257
- `).replace(te, "").replace(ne, " ").replace(oe, (t) => P[t] || "").replace(/ *\n */g, `
273
+ `).replace(re, "").replace(se, " ").replace(ae, (t) => C[t] || "").replace(/ *\n */g, `
258
274
  `).replace(/\n{3,}/g, `
259
275
 
260
- `), ze = (e) => {
276
+ `), Ye = (e) => {
261
277
  if (typeof window > "u" || !e)
262
278
  return e;
263
279
  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();
280
+ let s = o.nextNode();
281
+ for (; s; )
282
+ s.textContent = le(s.textContent || ""), s = o.nextNode();
267
283
  return n.body.innerHTML;
268
- }, ie = {
284
+ }, ce = {
269
285
  minSegmentLength: 32,
270
286
  maxSegmentLength: 128,
271
287
  rebalanceRatio: 0.4
272
- }, A = /[一-鿿㐀-䶿豈-﫿 -〿＀-￯]/, le = /[。!?!?\.]/, ae = /[;;]/, ce = /[,,、::]/, ue = /[。!?!?,,、;;::]/, C = "", y = "", T = (e) => {
288
+ }, y = /[一-鿿㐀-䶿豈-﫿 -〿＀-￯]/, ue = /[。!?!?\.]/, ge = /[;;]/, pe = /[,,、::]/, he = /[。!?!?,,、;;::]/, A = "", v = "", d = (e) => {
273
289
  let t = 0;
274
290
  for (const n of e)
275
- t += A.test(n) ? 2 : 1;
291
+ t += y.test(n) ? 2 : 1;
276
292
  return t;
277
- }, ge = (e) => e.replace(/\r/g, "").split(`
278
- `).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), pe = (e) => {
293
+ }, fe = (e) => e.replace(/\r/g, "").split(`
294
+ `).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), Ee = (e) => {
279
295
  let t = e, n = "";
280
296
  for (; n !== t; )
281
- n = t, t = t.replace(/(\d),(\d)/g, `$1${C}$2`);
297
+ n = t, t = t.replace(/(\d),(\d)/g, `$1${A}$2`);
282
298
  for (n = ""; n !== t; )
283
- n = t, t = t.replace(/(\d)\.(\d)/g, `$1${y}$2`);
299
+ n = t, t = t.replace(/(\d)\.(\d)/g, `$1${v}$2`);
284
300
  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;
301
+ }, L = (e) => e.split(A).join(",").split(v).join("."), Te = (e, t, n, o, s) => {
302
+ let a = -1, r = Number.POSITIVE_INFINITY;
287
303
  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]))
304
+ for (let l = i; l <= c; l += 1) {
305
+ if (!s.test(e[l - 1]))
290
306
  continue;
291
- const u = Math.abs(a - t);
292
- if (u < r && (r = u, s = a), a > t && s >= 0)
307
+ const u = Math.abs(l - t);
308
+ if (u < r && (r = u, a = l), l > t && a >= 0)
293
309
  break;
294
310
  }
295
- return s;
296
- }, fe = (e, t, n, o) => {
297
- let l = -1, s = Number.POSITIVE_INFINITY;
311
+ return a;
312
+ }, de = (e, t, n, o) => {
313
+ let s = -1, a = Number.POSITIVE_INFINITY;
298
314
  const r = Math.max(1, n), i = Math.min(e.length, o);
299
315
  for (let c = r; c <= i; c += 1) {
300
316
  if (e[c - 1] !== " ")
301
317
  continue;
302
- const a = Math.abs(c - t);
303
- if (a < s && (s = a, l = c), c > t && l >= 0)
318
+ const l = Math.abs(c - t);
319
+ if (l < a && (a = l, s = c), c > t && s >= 0)
304
320
  break;
305
321
  }
306
- return l;
307
- }, v = (e, t, n, o, l) => {
308
- for (const s of l) {
309
- const r = he(
322
+ return s;
323
+ }, F = (e, t, n, o, s) => {
324
+ for (const a of s) {
325
+ const r = Te(
310
326
  e,
311
327
  t,
312
328
  n,
313
329
  o,
314
- s
330
+ a
315
331
  );
316
332
  if (r >= 0)
317
333
  return r;
318
334
  }
319
- return fe(e, t, n, o);
320
- }, Ee = (e, t) => {
335
+ return de(e, t, n, o);
336
+ }, me = (e, t) => {
321
337
  const n = [];
322
338
  let o = e;
323
- for (; o && T(o) > t; ) {
324
- const l = T(o), s = Math.floor(l / 2);
339
+ for (; o && d(o) > t; ) {
340
+ const s = d(o), a = Math.floor(s / 2);
325
341
  let r = 0, i = 0, c = 0;
326
342
  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) {
343
+ if (c += y.test(o[g]) ? 2 : 1, !r && c >= a && (r = g + 1), c >= t) {
328
344
  i = g + 1;
329
345
  break;
330
346
  }
331
347
  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
348
+ const l = Math.max(1, Math.floor(r / 3));
349
+ let u = F(o, r, l, i, [
350
+ ge,
351
+ pe
336
352
  ]);
337
353
  (u < 0 || u >= o.length) && (u = r), n.push(o.slice(0, u)), o = o.slice(u);
338
354
  }
339
355
  return o.trim() && n.push(o), n;
340
- }, de = (e, t) => {
356
+ }, be = (e, t) => {
341
357
  if (e.length <= 1)
342
358
  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)
359
+ const n = e[e.length - 1], o = e.reduce((g, E) => g + E.length, 0) / e.length, s = Math.floor(o * t);
360
+ if (n.length >= s)
345
361
  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
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
348
364
  ]);
349
- if (a <= 0 || a >= r.length)
365
+ if (l <= 0 || l >= r.length)
350
366
  return e;
351
367
  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 = {}) => {
368
+ return u[u.length - 2] = r.slice(0, l), u[u.length - 1] = r.slice(l), u.filter(Boolean);
369
+ }, _e = (e, t = {}) => {
354
370
  const n = {
355
- ...ie,
371
+ ...ce,
356
372
  ...t
357
- }, o = ge(e);
373
+ }, o = fe(e);
358
374
  if (!o)
359
375
  return [];
360
- const l = pe(o);
361
- if (T(l) <= n.minSegmentLength)
362
- return [N(l)];
363
- const s = [], r = l.split(new RegExp("(?<=[。!?!?\\.])"));
376
+ const s = Ee(o);
377
+ if (d(s) <= n.minSegmentLength)
378
+ return [L(s)];
379
+ const a = [], r = s.split(new RegExp("(?<=[。!?!?\\.])"));
364
380
  let i = "";
365
- for (const a of r) {
366
- if (!a)
381
+ for (const l of r) {
382
+ if (!l)
367
383
  continue;
368
- i += a;
384
+ i += l;
369
385
  const u = i[i.length - 1] ?? "";
370
- T(i) >= n.minSegmentLength && le.test(u) && (s.push(i), i = "");
386
+ d(i) >= n.minSegmentLength && ue.test(u) && (a.push(i), i = "");
371
387
  }
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
388
+ i && (a.length > 0 && d(i) < n.minSegmentLength ? a[a.length - 1] += i : a.push(i));
389
+ const c = a.flatMap((l) => d(l) <= n.maxSegmentLength ? [l] : me(l, n.maxSegmentLength));
390
+ return be(c, n.rebalanceRatio).map(
391
+ L
376
392
  );
377
- }, d = {
393
+ }, T = {
378
394
  minSegmentLength: 32,
379
395
  maxSegmentLength: 64,
380
396
  rebalanceRatio: 0.4
381
- }, F = /[一-鿿㐀-䶿豈-﫿 -〿＀-￯]/, $ = /[。!?!?\.]/, D = /[;;]/, B = /[,,::]/, me = /[、]/, w = "", H = "", f = (e) => {
397
+ }, $ = /[一-鿿㐀-䶿豈-﫿 -〿＀-￯]/, D = /[。!?!?\.]/, B = /[;;]/, H = /[,,::]/, Ne = /[、]/, k = "", w = "", f = (e) => {
382
398
  let t = 0;
383
399
  for (const n of e)
384
- t += F.test(n) ? 2 : 1;
400
+ t += $.test(n) ? 2 : 1;
385
401
  return t;
386
- }, be = (e) => e.replace(/\r/g, "").split(`
387
- `).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), _e = (e) => {
402
+ }, Le = (e) => e.replace(/\r/g, "").split(`
403
+ `).map((t) => t.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim(), Se = (e) => {
388
404
  let t = e, n = "";
389
405
  for (; n !== t; )
390
- n = t, t = t.replace(/(\d),(\d)/g, `$1${w}$2`);
406
+ n = t, t = t.replace(/(\d),(\d)/g, `$1${k}$2`);
391
407
  for (n = ""; n !== t; )
392
- n = t, t = t.replace(/(\d)\.(\d)/g, `$1${H}$2`);
408
+ n = t, t = t.replace(/(\d)\.(\d)/g, `$1${w}$2`);
393
409
  return t;
394
- }, L = (e) => e.split(w).join(",").split(H).join("."), _ = (e, t) => {
410
+ }, S = (e) => e.split(k).join(",").split(w).join("."), N = (e, t) => {
395
411
  let n = 0;
396
412
  for (let o = 0; o < e.length; o += 1)
397
- if (n += F.test(e[o]) ? 2 : 1, n >= t)
413
+ if (n += $.test(e[o]) ? 2 : 1, n >= t)
398
414
  return o + 1;
399
415
  return e.length;
400
- }, I = (e, t, n, o, l) => {
401
- let s = -1, r = Number.POSITIVE_INFINITY;
416
+ }, I = (e, t, n, o, s) => {
417
+ let a = -1, r = Number.POSITIVE_INFINITY;
402
418
  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]))
419
+ for (let l = i; l <= c; l += 1) {
420
+ if (!s.test(e[l - 1]))
405
421
  continue;
406
- const u = Math.abs(a - t);
407
- if (u < r && (r = u, s = a), a > t && s >= 0)
422
+ const u = Math.abs(l - t);
423
+ if (u < r && (r = u, a = l), l > t && a >= 0)
408
424
  break;
409
425
  }
410
- return s;
411
- }, Ne = (e, t, n, o) => {
412
- let l = -1, s = Number.POSITIVE_INFINITY;
426
+ return a;
427
+ }, Ie = (e, t, n, o) => {
428
+ let s = -1, a = Number.POSITIVE_INFINITY;
413
429
  const r = Math.max(1, n), i = Math.min(e.length - 1, o);
414
430
  for (let c = r; c <= i; c += 1) {
415
431
  if (e[c - 1] !== " ")
416
432
  continue;
417
- const a = Math.abs(c - t);
418
- if (a < s && (s = a, l = c), c > t && l >= 0)
433
+ const l = Math.abs(c - t);
434
+ if (l < a && (a = l, s = c), c > t && s >= 0)
419
435
  break;
420
436
  }
421
- return l;
422
- }, V = (e, t, n, o, l) => {
423
- for (const r of l) {
437
+ return s;
438
+ }, V = (e, t, n, o, s) => {
439
+ for (const r of s) {
424
440
  const i = I(
425
441
  e,
426
442
  t,
@@ -431,71 +447,71 @@ const je = [
431
447
  if (i >= 0)
432
448
  return i;
433
449
  }
434
- const s = Ne(e, t, n, o);
435
- return s >= 0 ? s : I(
450
+ const a = Ie(e, t, n, o);
451
+ return a >= 0 ? a : I(
436
452
  e,
437
453
  t,
438
454
  n,
439
455
  o,
440
- me
456
+ Ne
441
457
  );
442
- }, Le = (e, t) => {
458
+ }, xe = (e, t) => {
443
459
  const n = [];
444
460
  let o = e.trim();
445
461
  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(
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(
447
463
  r + 1,
448
- _(o, t)
464
+ N(o, t)
449
465
  );
450
- let a = V(o, r, i, c, [
451
- D,
452
- B
466
+ let l = V(o, r, i, c, [
467
+ B,
468
+ H
453
469
  ]);
454
- (a < 0 || a >= o.length) && (a = r), n.push(o.slice(0, a).trim()), o = o.slice(a).trim();
470
+ (l < 0 || l >= o.length) && (l = r), n.push(o.slice(0, l).trim()), o = o.slice(l).trim();
455
471
  }
456
472
  return o && n.push(o), n;
457
- }, Ie = (e, t) => {
473
+ }, Re = (e, t) => {
458
474
  if (e.length <= 1)
459
475
  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)
476
+ const n = e[e.length - 1], o = e.reduce((E, b) => E + f(b), 0) / e.length, s = Math.floor(o * t);
477
+ if (f(n) >= s)
462
478
  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
- $,
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));
480
+ let u = V(r, c, l, r.length, [
466
481
  D,
467
- B
482
+ B,
483
+ H
468
484
  ]);
469
485
  if (u <= 0 || u >= r.length)
470
486
  return e;
471
487
  const g = [...e];
472
488
  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);
489
+ }, Me = (e) => {
490
+ const t = Le(e);
475
491
  if (!t)
476
492
  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) {
493
+ const n = Se(t);
494
+ if (f(n) <= T.minSegmentLength)
495
+ return [S(n)];
496
+ const o = [], s = n.split(new RegExp("(?<=[。!?!?\\.])"));
497
+ let a = "";
498
+ for (const i of s) {
483
499
  if (!i)
484
500
  continue;
485
- s += i;
486
- const c = s[s.length - 1] ?? "";
487
- f(s) >= d.minSegmentLength && $.test(c) && (o.push(s.trim()), s = "");
501
+ a += i;
502
+ const c = a[a.length - 1] ?? "";
503
+ f(a) >= T.minSegmentLength && D.test(c) && (o.push(a.trim()), a = "");
488
504
  }
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(
505
+ a && (o.length > 0 && f(a) < T.minSegmentLength ? o[o.length - 1] += a : o.push(a.trim()));
506
+ const r = o.flatMap((i) => f(i) <= T.maxSegmentLength ? [i] : xe(i, T.maxSegmentLength));
507
+ return Re(
492
508
  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) => {
509
+ T.rebalanceRatio
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) => {
496
512
  const t = e.content || [];
497
513
  let n = "";
498
- const o = [], l = [], s = {
514
+ const o = [], s = [], a = {
499
515
  [p.stop.type]: ({ position: r, actionCode: i }) => {
500
516
  o.push({
501
517
  action: "insert",
@@ -526,43 +542,43 @@ const je = [
526
542
  actionCode: c
527
543
  });
528
544
  },
529
- [p.replace.type]: ({ payload: r, position: i, text: c, actionCode: a }) => {
545
+ [p.replace.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
530
546
  o.push({
531
547
  action: "replace",
532
548
  model: "replace",
533
549
  payload: `${r == null ? void 0 : r.text}`,
534
550
  position: i,
535
551
  text: c,
536
- actionCode: a
552
+ actionCode: l
537
553
  });
538
554
  },
539
- [p.pinyin.type]: ({ payload: r, position: i, text: c, actionCode: a }) => {
555
+ [p.pinyin.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
540
556
  o.push({
541
557
  action: "replace",
542
558
  model: "pinyin",
543
559
  payload: `${r == null ? void 0 : r.text}`,
544
560
  position: i,
545
561
  text: c,
546
- actionCode: a
562
+ actionCode: l
547
563
  });
548
564
  },
549
- [p.language.type]: ({ payload: r, position: i, text: c, actionCode: a }) => {
565
+ [p.language.type]: ({ payload: r, position: i, text: c, actionCode: l }) => {
550
566
  o.push({
551
567
  action: "language",
552
568
  model: "language",
553
- payload: `${r == null ? void 0 : r.code}`,
569
+ payload: `${_(r == null ? void 0 : r.code)}`,
554
570
  position: i,
555
571
  text: c,
556
- actionCode: a
572
+ actionCode: l
557
573
  });
558
574
  },
559
575
  [p.tone.type]: ({ payload: r, position: i, actionCode: c }) => {
560
576
  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({
577
+ const l = (u = j.find((g) => g.value === (r == null ? void 0 : r.code))) == null ? void 0 : u.tag;
578
+ l && o.push({
563
579
  action: "insert",
564
580
  model: "control",
565
- payload: a,
581
+ payload: l,
566
582
  position: i,
567
583
  text: "",
568
584
  actionCode: c
@@ -586,78 +602,78 @@ const je = [
586
602
  return;
587
603
  }
588
604
  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
605
+ 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];
606
+ u && s.push({
607
+ start: l,
608
+ end: l + u.length
593
609
  }), g && g({
594
610
  payload: c,
595
- position: a,
611
+ position: l,
596
612
  text: u,
597
613
  actionCode: i
598
614
  }), n += u;
599
615
  }), {
600
616
  text: n,
601
- protectedRanges: l,
617
+ protectedRanges: s,
602
618
  playments: o
603
619
  };
604
- }, S = (e) => e.type === "text" || e.type === "customTag", Me = (e) => {
620
+ }, x = (e) => e.type === "text" || e.type === "customTag", Ce = (e) => {
605
621
  const t = e.content || [];
606
622
  if (e.type === "paragraph") return [e];
607
623
  if (e.type === "doc")
608
624
  return t.filter((o) => o.type === "paragraph");
609
625
  const n = t.filter((o) => o.type === "paragraph");
610
- return n.length ? n : t.some(S) ? [
626
+ return n.length ? n : t.some(x) ? [
611
627
  {
612
628
  type: "paragraph",
613
- content: t.filter(S)
629
+ content: t.filter(x)
614
630
  }
615
631
  ] : [];
616
- }, Oe = (e, t) => {
632
+ }, ye = (e, t) => {
617
633
  let n = 0;
618
634
  return t.map((o) => {
619
- const l = e.indexOf(o, n), s = l >= 0 ? l : n, r = s + o.length;
635
+ const s = e.indexOf(o, n), a = s >= 0 ? s : n, r = a + o.length;
620
636
  return n = r, {
621
637
  text: o,
622
- start: s,
638
+ start: a,
623
639
  end: r
624
640
  };
625
641
  });
626
- }, Pe = (e, t) => e.reduce((n, o) => {
642
+ }, Ae = (e, t) => e.reduce((n, o) => {
627
643
  if (t.some(
628
- (s) => o.start > s.start && o.start < s.end
644
+ (a) => o.start > a.start && o.start < a.end
629
645
  ) && n.length) {
630
- const s = n[n.length - 1];
631
- return s.text += o.text, s.end = o.end, n;
646
+ const a = n[n.length - 1];
647
+ return a.text += o.text, a.end = o.end, n;
632
648
  }
633
649
  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);
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);
636
652
  if (n.length <= 1) return [e];
637
- const o = Pe(
638
- Oe(e.text, n),
653
+ const o = Ae(
654
+ ye(e.text, n),
639
655
  e.protectedRanges || []
640
656
  );
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)
657
+ return o.map((s, a) => {
658
+ const r = a === o.length - 1, i = e.playments.filter(
659
+ (c) => ve(c, s.start, s.end, r)
644
660
  ).map((c) => ({
645
661
  ...c,
646
- position: c.position - l.start
662
+ position: c.position - s.start
647
663
  }));
648
664
  return {
649
- text: l.text,
665
+ text: s.text,
650
666
  playments: i
651
667
  };
652
668
  });
653
- }, Ge = (e, t = {}) => {
669
+ }, Ke = (e, t = {}) => {
654
670
  const n = {
655
671
  playments: [],
656
672
  sentences: []
657
673
  };
658
- return Me(e).forEach((l) => {
659
- const s = Re(l);
660
- !s.text && !s.playments.length || Ce(s, t).forEach(
674
+ return Ce(e).forEach((s) => {
675
+ const a = Pe(s);
676
+ !a.text && !a.playments.length || Fe(a, t).forEach(
661
677
  ({ text: r, playments: i }) => {
662
678
  n.sentences.push(r), n.playments.push(i);
663
679
  }
@@ -666,30 +682,32 @@ const je = [
666
682
  };
667
683
  export {
668
684
  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,
685
+ Be as EditorConst,
686
+ R as LanguageOptions,
687
+ De as MAX_LANGUAGE_SELECTION_LENGTH,
688
+ $e as MAX_REPLACEMENT_TEXT_LENGTH,
689
+ Xe as NumberToTextTools,
690
+ X as StopOptions,
691
+ j as ToneOptions,
676
692
  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
693
+ M as allToolTypes,
694
+ Ke as convertToTtsFormat,
695
+ ze as estimateTtsDuration,
696
+ we as getDefaultLockPayload,
697
+ je as getInitContent,
698
+ Ve as getLockPayloadLabel,
699
+ d as getVisualLength,
700
+ He as isInsertTagType,
701
+ ke as isLockableTagType,
702
+ _ as normalizeLanguageCode,
703
+ G as normalizeTtsContent,
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,
711
+ P as toPositional,
712
+ Pe as transformParagraph
695
713
  };