@pie-qti/player-elements 0.1.23 → 0.1.25

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.
Files changed (81) hide show
  1. package/dist/ItemToolBar-d36g3aw4-B6TGPyKt.js +3079 -0
  2. package/dist/ItemToolBar-d36g3aw4-B6TGPyKt.js.map +1 -0
  3. package/dist/ar-SA-BDmOol_3.js +854 -0
  4. package/dist/ar-SA-BDmOol_3.js.map +1 -0
  5. package/dist/{define-CqE08oOW.js → define-D80uAEx4.js} +2891 -4399
  6. package/dist/define-D80uAEx4.js.map +1 -0
  7. package/dist/dist-BSG0NOza.js +229 -0
  8. package/dist/dist-BSG0NOza.js.map +1 -0
  9. package/dist/{dist-CsEP48m1.js → dist-C8BDh5vZ.js} +1129 -760
  10. package/dist/dist-C8BDh5vZ.js.map +1 -0
  11. package/dist/dist-CQel8-vi.js +2507 -0
  12. package/dist/dist-CQel8-vi.js.map +1 -0
  13. package/dist/{dist-DQ_jFQFX.js → dist-L-bDDBry.js} +231 -147
  14. package/dist/dist-L-bDDBry.js.map +1 -0
  15. package/dist/{element-DU-n15ch.js → element-C5rTAwch.js} +2 -2
  16. package/dist/{element-DU-n15ch.js.map → element-C5rTAwch.js.map} +1 -1
  17. package/dist/{element-class-DBV-1lkb-BeszDwN_.js → element-class-B_qAd8ET-DGj15cBY.js} +4404 -3503
  18. package/dist/element-class-B_qAd8ET-DGj15cBY.js.map +1 -0
  19. package/dist/elements/BaseSvelteMountElement.d.ts +1 -0
  20. package/dist/elements/QtiAssessmentPlayerElement.d.ts +1 -0
  21. package/dist/elements.js +3 -3
  22. package/dist/es-ES-C98YtDtb.js +802 -0
  23. package/dist/es-ES-C98YtDtb.js.map +1 -0
  24. package/dist/fr-FR-CrmmiRPf.js +802 -0
  25. package/dist/fr-FR-CrmmiRPf.js.map +1 -0
  26. package/dist/index.js +2 -2
  27. package/dist/item-toolbar-element-BgqPFwsS.js +1990 -0
  28. package/dist/item-toolbar-element-BgqPFwsS.js.map +1 -0
  29. package/dist/{types-BFOGFD4R.js → language-tags-BwFWXo71.js} +24 -3
  30. package/dist/language-tags-BwFWXo71.js.map +1 -0
  31. package/dist/nl-NL-BRA_1Wcl.js +507 -0
  32. package/dist/nl-NL-BRA_1Wcl.js.map +1 -0
  33. package/dist/nl-NL-CAR7pgVz.js +802 -0
  34. package/dist/nl-NL-CAR7pgVz.js.map +1 -0
  35. package/dist/pie-DwmznDHb.js +363 -0
  36. package/dist/pie-DwmznDHb.js.map +1 -0
  37. package/dist/pie-assessment-toolkit-Cruxm385.js +5 -0
  38. package/dist/pie-assessment-toolkit-Cruxm385.js.map +1 -0
  39. package/dist/pie-assessment-toolkit-DJfg6laX.js +5 -0
  40. package/dist/pie-assessment-toolkit-DJfg6laX.js.map +1 -0
  41. package/dist/{pie-assessment-toolkit-element-BGOTMhdG.js → pie-assessment-toolkit-element-CT5UuvVY.js} +1679 -1245
  42. package/dist/pie-assessment-toolkit-element-CT5UuvVY.js.map +1 -0
  43. package/dist/pie-tool-calculator-Crfk-IZe.js +378 -0
  44. package/dist/pie-tool-calculator-Crfk-IZe.js.map +1 -0
  45. package/dist/{root-Dqg3cyBt.js → provider-gBXlGb0d.js} +4 -44
  46. package/dist/provider-gBXlGb0d.js.map +1 -0
  47. package/dist/register-players.js +1 -1
  48. package/dist/register.js +10603 -10162
  49. package/dist/register.js.map +1 -1
  50. package/dist/{resolveItems-DhQQhD2k.js → resolveItems-CNMvD8LP.js} +2 -2
  51. package/dist/{resolveItems-DhQQhD2k.js.map → resolveItems-CNMvD8LP.js.map} +1 -1
  52. package/dist/ro-RO-DTZbhL0e.js +802 -0
  53. package/dist/ro-RO-DTZbhL0e.js.map +1 -0
  54. package/dist/root-dCY6j_Hh.js +47 -0
  55. package/dist/root-dCY6j_Hh.js.map +1 -0
  56. package/dist/tag-names-DZGvnAgd.js +2495 -0
  57. package/dist/tag-names-DZGvnAgd.js.map +1 -0
  58. package/dist/th-TH-aqlT_oK3.js +802 -0
  59. package/dist/th-TH-aqlT_oK3.js.map +1 -0
  60. package/dist/tool-tts-inline-k3hLJUfp.js +4447 -0
  61. package/dist/tool-tts-inline-k3hLJUfp.js.map +1 -0
  62. package/dist/zh-CN-DCqaRRhU.js +802 -0
  63. package/dist/zh-CN-DCqaRRhU.js.map +1 -0
  64. package/package.json +8 -8
  65. package/dist/define-CqE08oOW.js.map +0 -1
  66. package/dist/dist-B1Rc9Jhz.js +0 -220
  67. package/dist/dist-B1Rc9Jhz.js.map +0 -1
  68. package/dist/dist-CQEJemjs.js +0 -5061
  69. package/dist/dist-CQEJemjs.js.map +0 -1
  70. package/dist/dist-CsEP48m1.js.map +0 -1
  71. package/dist/dist-DQ_jFQFX.js.map +0 -1
  72. package/dist/element-class-DBV-1lkb-BeszDwN_.js.map +0 -1
  73. package/dist/item-toolbar-element-iE73NEkH.js +0 -1922
  74. package/dist/item-toolbar-element-iE73NEkH.js.map +0 -1
  75. package/dist/pie-assessment-toolkit-element-BGOTMhdG.js.map +0 -1
  76. package/dist/pie-tool-calculator-CkQb5qxg.js +0 -2243
  77. package/dist/pie-tool-calculator-CkQb5qxg.js.map +0 -1
  78. package/dist/root-Dqg3cyBt.js.map +0 -1
  79. package/dist/tool-tts-inline-CA3VjWU4.js +0 -3670
  80. package/dist/tool-tts-inline-CA3VjWU4.js.map +0 -1
  81. package/dist/types-BFOGFD4R.js.map +0 -1
@@ -1,5 +1,91 @@
1
- //#region ../../node_modules/.bun/@pie-players+tts-client-server@0.3.67/node_modules/@pie-players/tts-client-server/dist/ServerTTSProvider.js
2
- function e(e, t) {
1
+ import { a as e, i as t } from "./pie-DwmznDHb.js";
2
+ //#region ../../node_modules/.bun/@pie-players+tts-server-core@0.3.73/node_modules/@pie-players/tts-server-core/dist/speech-marks.js
3
+ var n = (e) => {
4
+ let t = Number(e);
5
+ return Number.isFinite(t) ? t : null;
6
+ }, r = (e) => [...e].sort((e, t) => e.time === t.time ? e.start === t.start ? e.end - t.end : e.start - t.start : e.time - t.time), i = (e) => {
7
+ let t = [], i = 0;
8
+ for (let r of e.split(/\r?\n/)) {
9
+ let e = r.trim();
10
+ if (e) try {
11
+ let r = JSON.parse(e);
12
+ if (r.type && r.type !== "word") continue;
13
+ let a = n(r.time);
14
+ if (a === null) continue;
15
+ let o = typeof r.value == "string" ? r.value : "", s = n(r.start) ?? i, c = n(r.end) ?? s + Math.max(1, o.length);
16
+ i = Math.max(c + 1, i), t.push({
17
+ time: a,
18
+ type: "word",
19
+ start: s,
20
+ end: c,
21
+ value: o
22
+ });
23
+ } catch {}
24
+ }
25
+ return r(t);
26
+ }, a = (e) => {
27
+ if (e.length < 2) return e;
28
+ let t = e.map((e) => e.time).filter((e) => e >= 0), n = t.length ? Math.max(...t) : 0, r = [];
29
+ for (let e = 1; e < t.length; e += 1) {
30
+ let n = t[e] - t[e - 1];
31
+ n > 0 && Number.isFinite(n) && r.push(n);
32
+ }
33
+ let i = r.length > 0 ? [...r].sort((e, t) => e - t)[Math.floor(r.length / 2)] : 0;
34
+ return n > 0 && n < 100 && e.length > 3 || i > 0 && i < 10 ? e.map((e) => ({
35
+ ...e,
36
+ time: e.time * 1e3
37
+ })) : e;
38
+ }, o = (e, t) => {
39
+ if (!e.length || !t.length) return 0;
40
+ let n = t.toLowerCase(), r = [], i = 0;
41
+ for (let t of e) {
42
+ let e = t.value.trim().toLowerCase();
43
+ if (!e) continue;
44
+ let a = n.indexOf(e, i);
45
+ if (a < 0) continue;
46
+ let o = t.start - a;
47
+ if (o >= 0 && r.push(o), i = a + e.length, r.length >= 8) break;
48
+ }
49
+ if (r.length > 0) {
50
+ let e = [...r].sort((e, t) => e - t);
51
+ return e[Math.floor(e.length / 2)];
52
+ }
53
+ return Math.max(0, Math.floor(e[0].start));
54
+ }, s = (e, t) => {
55
+ if (!e.length || !t.length) return e;
56
+ let n = t.length;
57
+ if (Math.max(...e.map((e) => e.end)) <= n + 2) return e;
58
+ let r = o(e, t);
59
+ return r <= 0 ? e : e.map((e) => ({
60
+ ...e,
61
+ start: e.start - r,
62
+ end: e.end - r
63
+ }));
64
+ }, c = (e, t) => {
65
+ if (!t.length) return e;
66
+ let n = t.length;
67
+ return r(e.map((e) => {
68
+ let t = Math.max(0, Math.min(n, Math.floor(e.start))), r = Math.max(t + 1, Math.min(n, Math.floor(e.end)));
69
+ return {
70
+ ...e,
71
+ start: t,
72
+ end: r
73
+ };
74
+ }));
75
+ };
76
+ function l(e, t) {
77
+ return c(s(a(i(e)), t), t);
78
+ }
79
+ //#endregion
80
+ //#region ../../node_modules/.bun/@pie-players+tts-server-core@0.3.73/node_modules/@pie-players/tts-server-core/dist/speed-rate.js
81
+ function u(e, t = "medium") {
82
+ let n = Number(e ?? 1);
83
+ return Number.isFinite(n) ? n <= .95 ? "slow" : n >= 1.5 ? "fast" : t : t;
84
+ }
85
+ //#endregion
86
+ //#region ../../node_modules/.bun/@pie-players+tts-client-server@0.3.73/node_modules/@pie-players/tts-client-server/dist/ServerTTSProvider.js
87
+ var d = t("server-tts-provider", () => e());
88
+ function f(e, t) {
3
89
  if (typeof e != "string" || e.length === 0) return null;
4
90
  try {
5
91
  let n = typeof t.apiEndpoint == "string" && /^https?:\/\//i.test(t.apiEndpoint) ? t.apiEndpoint : void 0, r = n ? new URL(e, n) : new URL(e);
@@ -8,7 +94,7 @@ function e(e, t) {
8
94
  return null;
9
95
  }
10
96
  }
11
- function t(e, t) {
97
+ function p(e, t) {
12
98
  let n = Array.isArray(t.assetOrigins) ? t.assetOrigins.filter((e) => typeof e == "string" && e.length > 0).map((e) => {
13
99
  try {
14
100
  return new URL(e).origin;
@@ -26,7 +112,7 @@ function t(e, t) {
26
112
  }
27
113
  return n.includes(e.origin);
28
114
  }
29
- function n(e) {
115
+ function m(e) {
30
116
  let t = {};
31
117
  for (let [n, r] of Object.entries(e)) {
32
118
  let e = n.toLowerCase();
@@ -34,36 +120,23 @@ function n(e) {
34
120
  }
35
121
  return t;
36
122
  }
37
- var r = (e) => {
123
+ var h = (e) => {
38
124
  let t = (e.providerOptions && typeof e.providerOptions == "object" ? e.providerOptions : {}).__pieTelemetry;
39
125
  return typeof t == "function" ? t : void 0;
40
- }, i = {
126
+ }, g = {
41
127
  pie: 3e3,
42
128
  custom: 3e3
43
- }, a = /* @__PURE__ */ new Set(["polly", "google"]), o = (e) => {
44
- if (!e || l(e) !== "pie") return !1;
129
+ }, _ = /* @__PURE__ */ new Set(["polly", "google"]), v = (e) => {
130
+ if (!e || x(e) !== "pie") return !1;
45
131
  let t = (e.provider || "polly").toLowerCase();
46
- return a.has(t);
47
- }, s = (e) => e.replace(/\/+$/, ""), c = (e) => {
48
- let t = s(e.apiEndpoint), n = (e.provider || "").toLowerCase();
132
+ return _.has(t);
133
+ }, y = (e) => e.replace(/\/+$/, ""), b = (e) => {
134
+ let t = y(e.apiEndpoint), n = (e.provider || "").toLowerCase();
49
135
  return n === "polly" || n === "google" ? `${t}/${n}/voices` : `${t}/voices`;
50
- }, l = (e) => e.transportMode === "custom" ? "custom" : e.transportMode === "pie" ? "pie" : e.provider === "custom" ? "custom" : "pie", u = (e, t) => e.endpointMode ? e.endpointMode : t === "custom" ? "rootPost" : "synthesizePath", d = (e, t) => e.endpointValidationMode ? e.endpointValidationMode : t === "custom" ? "none" : "voices", f = (e) => Number.isFinite(e) ? e < 1 ? "slow" : e > 1 ? "fast" : "medium" : "medium", p = (e) => {
136
+ }, x = (e) => e.transportMode === "custom" ? "custom" : e.transportMode === "pie" ? "pie" : e.provider === "custom" ? "custom" : "pie", S = (e, t) => e.endpointMode ? e.endpointMode : t === "custom" ? "rootPost" : "synthesizePath", C = (e, t) => e.endpointValidationMode ? e.endpointValidationMode : t === "custom" ? "none" : "voices", w = (e) => {
51
137
  let t = e.providerOptions || {};
52
- return typeof t.speedRate == "string" ? t.speedRate : f(Number(e.rate ?? 1));
53
- }, m = (e) => {
54
- let t = [], n = 0, r = e.split("\n").map((e) => e.trim()).filter(Boolean);
55
- for (let e of r) try {
56
- let r = JSON.parse(e), i = typeof r.type == "string" ? r.type : "word", a = typeof r.time == "number" && Number.isFinite(r.time) ? r.time : 0, o = typeof r.value == "string" ? r.value : "", s = typeof r.start == "number" && Number.isFinite(r.start) ? r.start : null, c = typeof r.end == "number" && Number.isFinite(r.end) ? r.end : null, l = s ?? n, u = c ?? l + Math.max(1, o.length || String(r.value || "").length);
57
- n = Math.max(u + 1, n), t.push({
58
- time: a,
59
- type: i,
60
- start: l,
61
- end: u,
62
- value: o
63
- });
64
- } catch {}
65
- return t;
66
- }, h = (e) => {
138
+ return typeof t.speedRate == "string" ? t.speedRate : u(e.rate);
139
+ }, T = (e) => {
67
140
  if (!Array.isArray(e)) return [];
68
141
  let t = [], n = 0;
69
142
  for (let r of e) {
@@ -78,11 +151,11 @@ var r = (e) => {
78
151
  });
79
152
  }
80
153
  return t.sort((e, t) => e.time === t.time ? e.start === t.start ? e.end - t.end : e.start - t.start : e.time - t.time);
81
- }, g = {
154
+ }, E = {
82
155
  pie: {
83
156
  id: "pie",
84
157
  resolveSynthesisUrl: (e) => {
85
- let t = u(e, "pie"), n = s(e.apiEndpoint);
158
+ let t = S(e, "pie"), n = y(e.apiEndpoint);
86
159
  return t === "rootPost" ? n : `${n}/synthesize`;
87
160
  },
88
161
  buildRequestBody: (e, t) => {
@@ -100,67 +173,68 @@ var r = (e) => {
100
173
  includeSpeechMarks: !0
101
174
  };
102
175
  },
103
- parseResponse: async (e) => {
104
- let t = await e.json();
176
+ parseResponse: async (e, t, n, r, i) => {
177
+ let a = await e.json();
105
178
  return {
106
179
  audio: {
107
180
  kind: "base64",
108
- data: t.audio,
109
- contentType: t.contentType
181
+ data: a.audio,
182
+ contentType: a.contentType
110
183
  },
111
- speechMarks: Array.isArray(t.speechMarks) ? t.speechMarks : []
184
+ speechMarks: Array.isArray(a.speechMarks) ? a.speechMarks : []
112
185
  };
113
186
  }
114
187
  },
115
188
  custom: {
116
189
  id: "custom",
117
190
  resolveSynthesisUrl: (e) => {
118
- let t = u(e, "custom"), n = s(e.apiEndpoint);
191
+ let t = S(e, "custom"), n = y(e.apiEndpoint);
119
192
  return t === "synthesizePath" ? `${n}/synthesize` : n;
120
193
  },
121
194
  buildRequestBody: (e, t) => {
122
195
  let n = t.providerOptions || {}, r = typeof n.lang_id == "string" ? n.lang_id : t.language || "en-US", i = typeof n.cache != "boolean" || n.cache;
123
196
  return {
124
197
  text: e,
125
- speedRate: p(t),
198
+ speedRate: w(t),
126
199
  lang_id: r,
127
200
  cache: i
128
201
  };
129
202
  },
130
- parseResponse: async (r, i, a, o) => {
131
- let s = await r.json(), c = {};
132
- if (i.includeAuthOnAssetFetch) for (let [e, t] of Object.entries(a)) e.toLowerCase() === "authorization" && (c[e] = t);
133
- let l = [], u = h(s.speechMarks);
134
- if (u.length > 0) l = u;
135
- else if (typeof s.word == "string" && s.word.length > 0) {
136
- let r = e(s.word, i);
137
- if (r !== null) {
138
- let e = t(r, i) ? c : n(c), a = await fetch(r.toString(), {
139
- headers: e,
140
- signal: o,
203
+ parseResponse: async (e, t, n, r, i) => {
204
+ let a = await e.json(), o = {};
205
+ if (t.includeAuthOnAssetFetch) for (let [e, t] of Object.entries(n)) e.toLowerCase() === "authorization" && (o[e] = t);
206
+ let s = [], c = T(a.speechMarks);
207
+ if (c.length > 0) s = c;
208
+ else if (typeof a.word == "string" && a.word.length > 0) {
209
+ let e = f(a.word, t);
210
+ if (e !== null) {
211
+ let n = p(e, t) ? o : m(o), a = await fetch(e.toString(), {
212
+ headers: n,
213
+ signal: r,
141
214
  redirect: "error"
142
215
  });
143
- a.ok && (l = m(await a.text()));
216
+ a.ok && (s = l(await a.text(), i));
144
217
  }
145
218
  }
146
- let d = e(s.audioContent, i);
147
- if (d === null) throw Error("TTS server returned an invalid audio URL");
219
+ let u = f(a.audioContent, t);
220
+ if (u === null) throw Error("TTS server returned an invalid audio URL");
148
221
  return {
149
222
  audio: {
150
223
  kind: "url",
151
- url: d.toString()
224
+ url: u.toString()
152
225
  },
153
- speechMarks: l
226
+ speechMarks: s
154
227
  };
155
228
  }
156
229
  }
157
- }, _ = class {
230
+ }, D = class {
158
231
  config;
159
232
  adapter;
160
233
  currentAudio = null;
161
234
  pausedState = !1;
162
235
  wordTimings = [];
163
236
  highlightInterval = null;
237
+ highlightCursor = -1;
164
238
  intentionallyStopped = !1;
165
239
  activeSynthesisController = null;
166
240
  synthesisRunId = 0;
@@ -168,13 +242,13 @@ var r = (e) => {
168
242
  onPlaybackStart;
169
243
  onWordBoundary;
170
244
  constructor(e, t) {
171
- this.config = e, this.adapter = t, this.telemetryReporter = r(e);
245
+ this.config = e, this.adapter = t, this.telemetryReporter = h(e);
172
246
  }
173
247
  async emitTelemetry(e, t) {
174
248
  try {
175
249
  await this.telemetryReporter?.(e, t);
176
250
  } catch (e) {
177
- console.warn("[ServerTTSProvider] telemetry callback failed:", e);
251
+ d.warn("telemetry callback failed:", e);
178
252
  }
179
253
  }
180
254
  async speak(e) {
@@ -186,7 +260,7 @@ var r = (e) => {
186
260
  URL.revokeObjectURL(r);
187
261
  return;
188
262
  }
189
- return this.wordTimings = i, new Promise((e, n) => {
263
+ return this.wordTimings = i, this.highlightCursor = -1, new Promise((e, n) => {
190
264
  let i = new Audio(r);
191
265
  this.currentAudio = i, this.config.volume !== void 0 && (i.volume = Math.max(0, Math.min(1, this.config.volume))), i.onplay = () => {
192
266
  if (t === this.synthesisRunId && this.currentAudio === i) {
@@ -194,110 +268,111 @@ var r = (e) => {
194
268
  try {
195
269
  this.onPlaybackStart?.();
196
270
  } catch (e) {
197
- console.warn("[ServerTTSProvider] playback-start callback failed:", e);
271
+ d.warn("playback-start callback failed:", e);
198
272
  }
199
273
  this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting();
200
274
  }
201
275
  }, i.onended = () => {
202
- this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], e();
276
+ this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], this.highlightCursor = -1, e();
203
277
  }, i.onerror = (t) => {
204
- this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], this.intentionallyStopped ? e() : n(/* @__PURE__ */ Error("Failed to play audio from server"));
278
+ this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], this.highlightCursor = -1, this.intentionallyStopped ? e() : n(/* @__PURE__ */ Error("Failed to play audio from server"));
205
279
  }, i.onpause = () => {
206
280
  this.stopWordHighlighting(), this.pausedState = !0;
207
281
  }, i.play().catch(n);
208
282
  });
209
283
  }
210
- async synthesizeSpeech(r, i, a) {
211
- let o = Date.now();
284
+ async synthesizeSpeech(e, t, n) {
285
+ let r = Date.now();
212
286
  await this.emitTelemetry("pie-tool-backend-call-start", {
213
287
  toolId: "tts",
214
288
  backend: this.config.provider || "server",
215
289
  operation: "synthesize-speech"
216
290
  });
217
- let s = {
291
+ let i = {
218
292
  "Content-Type": "application/json",
219
293
  ...this.config.headers
220
294
  };
221
- this.config.authToken && (s.Authorization = `Bearer ${this.config.authToken}`);
222
- let c = this.adapter.resolveSynthesisUrl(this.config), l = this.adapter.buildRequestBody(r, this.config), u = await (async () => {
295
+ this.config.authToken && (i.Authorization = `Bearer ${this.config.authToken}`);
296
+ let a = this.adapter.resolveSynthesisUrl(this.config), o = this.adapter.buildRequestBody(e, this.config), s = await (async () => {
223
297
  try {
224
- return await fetch(c, {
298
+ return await fetch(a, {
225
299
  method: "POST",
226
- headers: s,
227
- body: JSON.stringify(l),
228
- signal: i
300
+ headers: i,
301
+ body: JSON.stringify(o),
302
+ signal: t
229
303
  });
230
304
  } catch (e) {
231
305
  throw await this.emitTelemetry("pie-tool-backend-call-error", {
232
306
  toolId: "tts",
233
307
  backend: this.config.provider || "server",
234
308
  operation: "synthesize-speech",
235
- duration: Date.now() - o,
309
+ duration: Date.now() - r,
236
310
  errorType: "TTSBackendNetworkError",
237
311
  message: e instanceof Error ? e.message : String(e)
238
312
  }), e;
239
313
  }
240
314
  })();
241
- if (!u.ok) {
242
- let e = await u.text().catch(() => ""), t = {};
243
- if (e) try {
244
- t = JSON.parse(e);
245
- } catch (t) {
246
- console.warn("[ServerTTSProvider] non-OK response body was not JSON", {
247
- status: u.status,
248
- url: c,
249
- rawBodyPreview: e.slice(0, 500),
250
- parseError: t instanceof Error ? t.message : String(t)
251
- });
315
+ if (!s.ok) {
316
+ let t = await s.text().catch(() => ""), n = {};
317
+ if (t) try {
318
+ n = JSON.parse(t);
319
+ } catch (e) {
320
+ d.warn("non-OK response body was not JSON", {
321
+ status: s.status,
322
+ url: a,
323
+ bodyLength: t.length,
324
+ parseError: e instanceof Error ? e.message : String(e)
325
+ }), d.debug("non-OK response body", { rawBodyPreview: t.slice(0, 500) });
252
326
  }
253
- let n = typeof t.message == "string" && t.message || (typeof t.error?.message == "string" ? t.error.message : void 0) || `Server returned ${u.status}`;
327
+ let i = typeof n.message == "string" && n.message || (typeof n.error?.message == "string" ? n.error.message : void 0) || `Server returned ${s.status}`;
254
328
  await this.emitTelemetry("pie-tool-backend-call-error", {
255
329
  toolId: "tts",
256
330
  backend: this.config.provider || "server",
257
331
  operation: "synthesize-speech",
258
- duration: Date.now() - o,
259
- statusCode: u.status,
332
+ duration: Date.now() - r,
333
+ statusCode: s.status,
260
334
  errorType: "TTSBackendRequestError",
261
- message: n
262
- });
263
- let i = r.replace(/\s+/g, " ").trim().slice(0, 120);
264
- throw console.error("[ServerTTSProvider] synthesize request failed", {
265
- status: u.status,
266
- url: c,
335
+ message: i
336
+ }), d.error("synthesize request failed", {
337
+ status: s.status,
338
+ url: a,
267
339
  backend: this.config.provider || "server",
268
- message: n,
269
- responseBody: t,
270
- textLength: r.length,
271
- textPreview: i.length < r.length ? `${i}…` : i
272
- }), Error(n);
340
+ message: i,
341
+ textLength: e.length
342
+ });
343
+ let o = e.replace(/\s+/g, " ").trim().slice(0, 120);
344
+ throw d.debug("synthesize request failed for text", {
345
+ responseBody: n,
346
+ textPreview: o.length < e.length ? `${o}…` : o
347
+ }), Error(i);
273
348
  }
274
- let d = await this.adapter.parseResponse(u, this.config, s, i);
275
- if (a !== this.synthesisRunId || i.aborted) throw Error("Synthesis superseded by a newer request");
276
- let f;
277
- if (d.audio.kind === "base64") f = this.base64ToBlob(d.audio.data, d.audio.contentType);
349
+ let c = await this.adapter.parseResponse(s, this.config, i, t, e);
350
+ if (n !== this.synthesisRunId || t.aborted) throw Error("Synthesis superseded by a newer request");
351
+ let l;
352
+ if (c.audio.kind === "base64") l = this.base64ToBlob(c.audio.data, c.audio.contentType);
278
353
  else {
279
- let r = d.audio.url, a = Date.now();
354
+ let e = c.audio.url, n = Date.now();
280
355
  await this.emitTelemetry("pie-tool-backend-call-start", {
281
356
  toolId: "tts",
282
357
  backend: this.config.provider || "server",
283
358
  operation: "fetch-synthesized-audio-asset"
284
359
  });
285
- let o = {};
286
- this.config.includeAuthOnAssetFetch && this.config.authToken && (o.Authorization = `Bearer ${this.config.authToken}`);
287
- let s = e(r, this.config);
288
- if (s === null) throw await this.emitTelemetry("pie-tool-backend-call-error", {
360
+ let r = {};
361
+ this.config.includeAuthOnAssetFetch && this.config.authToken && (r.Authorization = `Bearer ${this.config.authToken}`);
362
+ let i = f(e, this.config);
363
+ if (i === null) throw await this.emitTelemetry("pie-tool-backend-call-error", {
289
364
  toolId: "tts",
290
365
  backend: this.config.provider || "server",
291
366
  operation: "fetch-synthesized-audio-asset",
292
- duration: Date.now() - a,
367
+ duration: Date.now() - n,
293
368
  errorType: "TTSAssetInvalidUrl",
294
369
  message: "TTS asset URL rejected (non-http(s) or malformed)"
295
370
  }), Error("TTS asset URL rejected (non-http(s) or malformed)");
296
- let c = t(s, this.config) ? o : n(o), l = await (async () => {
371
+ let a = p(i, this.config) ? r : m(r), o = await (async () => {
297
372
  try {
298
- return await fetch(s.toString(), {
299
- headers: c,
300
- signal: i,
373
+ return await fetch(i.toString(), {
374
+ headers: a,
375
+ signal: t,
301
376
  redirect: "error"
302
377
  });
303
378
  } catch (e) {
@@ -305,37 +380,37 @@ var r = (e) => {
305
380
  toolId: "tts",
306
381
  backend: this.config.provider || "server",
307
382
  operation: "fetch-synthesized-audio-asset",
308
- duration: Date.now() - a,
383
+ duration: Date.now() - n,
309
384
  errorType: "TTSAssetNetworkError",
310
385
  message: e instanceof Error ? e.message : String(e)
311
386
  }), e;
312
387
  }
313
388
  })();
314
- if (!l.ok) throw await this.emitTelemetry("pie-tool-backend-call-error", {
389
+ if (!o.ok) throw await this.emitTelemetry("pie-tool-backend-call-error", {
315
390
  toolId: "tts",
316
391
  backend: this.config.provider || "server",
317
392
  operation: "fetch-synthesized-audio-asset",
318
- duration: Date.now() - a,
319
- statusCode: l.status,
393
+ duration: Date.now() - n,
394
+ statusCode: o.status,
320
395
  errorType: "TTSAssetFetchError",
321
- message: `Failed to download synthesized audio (${l.status})`
322
- }), Error(`Failed to download synthesized audio (${l.status})`);
323
- f = await l.blob(), await this.emitTelemetry("pie-tool-backend-call-success", {
396
+ message: `Failed to download synthesized audio (${o.status})`
397
+ }), Error(`Failed to download synthesized audio (${o.status})`);
398
+ l = await o.blob(), await this.emitTelemetry("pie-tool-backend-call-success", {
324
399
  toolId: "tts",
325
400
  backend: this.config.provider || "server",
326
401
  operation: "fetch-synthesized-audio-asset",
327
- duration: Date.now() - a
402
+ duration: Date.now() - n
328
403
  });
329
404
  }
330
- let p = URL.createObjectURL(f), m = this.parseSpeechMarks(d.speechMarks);
405
+ let u = URL.createObjectURL(l), h = this.parseSpeechMarks(c.speechMarks);
331
406
  return await this.emitTelemetry("pie-tool-backend-call-success", {
332
407
  toolId: "tts",
333
408
  backend: this.config.provider || "server",
334
409
  operation: "synthesize-speech",
335
- duration: Date.now() - o
410
+ duration: Date.now() - r
336
411
  }), {
337
- audioUrl: p,
338
- wordTimings: m
412
+ audioUrl: u,
413
+ wordTimings: h
339
414
  };
340
415
  }
341
416
  base64ToBlob(e, t) {
@@ -355,30 +430,39 @@ var r = (e) => {
355
430
  }
356
431
  startWordHighlighting() {
357
432
  if (this.stopWordHighlighting(), !this.currentAudio || !this.onWordBoundary || this.wordTimings.length === 0) {
358
- console.log("[ServerTTSProvider] Cannot start highlighting:", {
433
+ d.debug("cannot start word highlighting", {
359
434
  hasAudio: !!this.currentAudio,
360
435
  hasCallback: !!this.onWordBoundary,
361
436
  wordTimingsCount: this.wordTimings.length
362
437
  });
363
438
  return;
364
439
  }
365
- console.log("[ServerTTSProvider] Starting word highlighting with", this.wordTimings.length, "word timings"), console.log("[ServerTTSProvider] Playback rate:", this.currentAudio.playbackRate), console.log("[ServerTTSProvider] First 3 timings:", this.wordTimings.slice(0, 3));
366
- let e = -1;
367
- this.highlightInterval = window.setInterval(() => {
440
+ d.debug("starting word highlighting", {
441
+ wordTimingsCount: this.wordTimings.length,
442
+ playbackRate: this.currentAudio.playbackRate
443
+ }), this.highlightInterval = window.setInterval(() => {
368
444
  if (!this.currentAudio) {
369
445
  this.stopWordHighlighting();
370
446
  return;
371
447
  }
372
- let t = this.currentAudio.currentTime * 1e3;
373
- for (let n = 0; n < this.wordTimings.length; n++) {
374
- let r = this.wordTimings[n];
375
- if (t >= r.time && n > e) {
376
- this.onWordBoundary && (console.log("[ServerTTSProvider] Highlighting word at charIndex:", r.charIndex, "length:", r.length, "time:", r.time, "currentTime:", t), this.onWordBoundary(r.word, r.charIndex, r.length)), e = n;
377
- break;
378
- }
379
- }
448
+ let e = this.currentAudio.currentTime * 1e3, t = this.resolveCurrentWordIndex(e, this.highlightCursor);
449
+ if (t < 0 || t === this.highlightCursor) return;
450
+ this.highlightCursor = t;
451
+ let n = this.wordTimings[t];
452
+ d.debug("word boundary", {
453
+ wordIndex: n.wordIndex,
454
+ charIndex: n.charIndex,
455
+ length: n.length,
456
+ timingMs: n.time,
457
+ currentTimeMs: e
458
+ }), this.onWordBoundary?.(n.word, n.charIndex, n.length);
380
459
  }, 50);
381
460
  }
461
+ resolveCurrentWordIndex(e, t) {
462
+ let n = this.wordTimings, r = t < n.length ? t : -1;
463
+ for (r >= 0 && e < n[r].time && (r = -1); r + 1 < n.length && n[r + 1].time <= e;) r++;
464
+ return r;
465
+ }
382
466
  stopWordHighlighting() {
383
467
  this.highlightInterval !== null && (clearInterval(this.highlightInterval), this.highlightInterval = null);
384
468
  }
@@ -389,7 +473,7 @@ var r = (e) => {
389
473
  this.currentAudio && this.pausedState && (this.currentAudio.play(), this.pausedState = !1, this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting());
390
474
  }
391
475
  stop() {
392
- this.synthesisRunId += 1, this.activeSynthesisController &&= (this.activeSynthesisController.abort(), null), this.stopWordHighlighting(), this.currentAudio &&= (this.intentionallyStopped = !0, this.currentAudio.pause(), this.currentAudio.src && URL.revokeObjectURL(this.currentAudio.src), this.currentAudio.src = "", null), this.pausedState = !1, this.wordTimings = [];
476
+ this.synthesisRunId += 1, this.activeSynthesisController &&= (this.activeSynthesisController.abort(), null), this.stopWordHighlighting(), this.currentAudio &&= (this.intentionallyStopped = !0, this.currentAudio.pause(), this.currentAudio.src && URL.revokeObjectURL(this.currentAudio.src), this.currentAudio.src = "", null), this.pausedState = !1, this.wordTimings = [], this.highlightCursor = -1;
393
477
  }
394
478
  isPlaying() {
395
479
  return this.currentAudio !== null && !this.pausedState;
@@ -400,10 +484,10 @@ var r = (e) => {
400
484
  updateSettings(e) {
401
485
  e.rate !== void 0 && (this.config.rate = e.rate, this.config.providerOptions = {
402
486
  ...this.config.providerOptions || {},
403
- speedRate: f(Number(e.rate))
487
+ speedRate: u(e.rate)
404
488
  }), e.pitch !== void 0 && (this.config.pitch = e.pitch), e.voice !== void 0 && (this.config.voice = e.voice);
405
489
  }
406
- }, v = class {
490
+ }, O = class {
407
491
  providerId = "server-tts";
408
492
  providerName = "Server TTS";
409
493
  version = "1.0.0";
@@ -414,15 +498,15 @@ var r = (e) => {
414
498
  try {
415
499
  await this.telemetryReporter?.(e, t);
416
500
  } catch (e) {
417
- console.warn("[ServerTTSProvider] telemetry callback failed:", e);
501
+ d.warn("telemetry callback failed:", e);
418
502
  }
419
503
  }
420
504
  async initialize(e) {
421
505
  let t = e;
422
506
  if (!t.apiEndpoint) throw Error("apiEndpoint is required for ServerTTSProvider");
423
- this.config = t, this.telemetryReporter = r(t);
424
- let n = l(t);
425
- if (this.adapter = g[n], t.validateEndpoint) {
507
+ this.config = t, this.telemetryReporter = h(t);
508
+ let n = x(t);
509
+ if (this.adapter = E[n], t.validateEndpoint) {
426
510
  let e = Date.now();
427
511
  if (await this.emitTelemetry("pie-tool-backend-call-start", {
428
512
  toolId: "tts",
@@ -443,16 +527,16 @@ var r = (e) => {
443
527
  duration: Date.now() - e
444
528
  });
445
529
  }
446
- return new _(t, this.adapter);
530
+ return new D(t, this.adapter);
447
531
  }
448
532
  async testAPIAvailability() {
449
533
  if (!this.config || !this.adapter) return !1;
450
534
  try {
451
535
  let e = { ...this.config.headers };
452
536
  this.config.authToken && (e.Authorization = `Bearer ${this.config.authToken}`);
453
- let t = new AbortController(), n = setTimeout(() => t.abort(), 5e3), r = d(this.config, this.adapter.id);
537
+ let t = new AbortController(), n = setTimeout(() => t.abort(), 5e3), r = C(this.config, this.adapter.id);
454
538
  if (r === "none") return clearTimeout(n), !0;
455
- let i = r === "voices" ? c(this.config) : this.adapter.resolveSynthesisUrl(this.config), a = r === "voices" ? "GET" : "OPTIONS";
539
+ let i = r === "voices" ? b(this.config) : this.adapter.resolveSynthesisUrl(this.config), a = r === "voices" ? "GET" : "OPTIONS";
456
540
  try {
457
541
  let r = await fetch(i, {
458
542
  method: a,
@@ -479,7 +563,7 @@ var r = (e) => {
479
563
  }
480
564
  }
481
565
  getCapabilities() {
482
- let e = this.config ? l(this.config) : "pie";
566
+ let e = this.config ? x(this.config) : "pie";
483
567
  return {
484
568
  supportsPause: !0,
485
569
  supportsResume: !0,
@@ -487,8 +571,8 @@ var r = (e) => {
487
571
  supportsVoiceSelection: !0,
488
572
  supportsRateControl: !0,
489
573
  supportsPitchControl: !1,
490
- supportsSSML: o(this.config),
491
- maxTextLength: i[e]
574
+ supportsSSML: v(this.config),
575
+ maxTextLength: g[e]
492
576
  };
493
577
  }
494
578
  destroy() {
@@ -496,6 +580,6 @@ var r = (e) => {
496
580
  }
497
581
  };
498
582
  //#endregion
499
- export { v as ServerTTSProvider };
583
+ export { O as ServerTTSProvider };
500
584
 
501
- //# sourceMappingURL=dist-DQ_jFQFX.js.map
585
+ //# sourceMappingURL=dist-L-bDDBry.js.map