@pie-qti/player-elements 0.1.24 → 0.1.26

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 (64) hide show
  1. package/dist/ItemToolBar-d36g3aw4-B6TGPyKt.js +3079 -0
  2. package/dist/ItemToolBar-d36g3aw4-B6TGPyKt.js.map +1 -0
  3. package/dist/{define-D7_K0JFy.js → define-D6MsIPs4.js} +1902 -4395
  4. package/dist/define-D6MsIPs4.js.map +1 -0
  5. package/dist/dist-BSG0NOza.js +229 -0
  6. package/dist/dist-BSG0NOza.js.map +1 -0
  7. package/dist/{dist-ffJZTPTU.js → dist-C8BDh5vZ.js} +987 -707
  8. package/dist/dist-C8BDh5vZ.js.map +1 -0
  9. package/dist/dist-CQel8-vi.js +2507 -0
  10. package/dist/dist-CQel8-vi.js.map +1 -0
  11. package/dist/{dist-BaQdJU08.js → dist-L-bDDBry.js} +116 -103
  12. package/dist/dist-L-bDDBry.js.map +1 -0
  13. package/dist/{element-class-DQy2cIPM-CldZrSRR.js → element-class-B_qAd8ET-MnL2rzKs.js} +4938 -4241
  14. package/dist/element-class-B_qAd8ET-MnL2rzKs.js.map +1 -0
  15. package/dist/{element-DSCNeDLu.js → element-rqU0mnAg.js} +2 -2
  16. package/dist/{element-DSCNeDLu.js.map → element-rqU0mnAg.js.map} +1 -1
  17. package/dist/elements.js +3 -3
  18. package/dist/index.js +2 -2
  19. package/dist/item-toolbar-element-BgqPFwsS.js +1990 -0
  20. package/dist/item-toolbar-element-BgqPFwsS.js.map +1 -0
  21. package/dist/{language-tags-DVlRltrl.js → language-tags-BwFWXo71.js} +3 -3
  22. package/dist/{language-tags-DVlRltrl.js.map → language-tags-BwFWXo71.js.map} +1 -1
  23. package/dist/{nl-NL-BeQBX6yq.js → nl-NL-BRA_1Wcl.js} +5 -3
  24. package/dist/nl-NL-BRA_1Wcl.js.map +1 -0
  25. package/dist/pie-DwmznDHb.js +363 -0
  26. package/dist/pie-DwmznDHb.js.map +1 -0
  27. package/dist/pie-assessment-toolkit-Cruxm385.js +5 -0
  28. package/dist/pie-assessment-toolkit-Cruxm385.js.map +1 -0
  29. package/dist/pie-assessment-toolkit-DJfg6laX.js +5 -0
  30. package/dist/pie-assessment-toolkit-DJfg6laX.js.map +1 -0
  31. package/dist/{pie-assessment-toolkit-element-CpiB3twr.js → pie-assessment-toolkit-element-CT5UuvVY.js} +1364 -1203
  32. package/dist/pie-assessment-toolkit-element-CT5UuvVY.js.map +1 -0
  33. package/dist/pie-tool-calculator-Crfk-IZe.js +378 -0
  34. package/dist/pie-tool-calculator-Crfk-IZe.js.map +1 -0
  35. package/dist/{provider-Y5PhmTAu.js → provider-gBXlGb0d.js} +3 -3
  36. package/dist/{provider-Y5PhmTAu.js.map → provider-gBXlGb0d.js.map} +1 -1
  37. package/dist/public/api.d.ts +1 -1
  38. package/dist/register-players.js +1 -1
  39. package/dist/register.js +26177 -20539
  40. package/dist/register.js.map +1 -1
  41. package/dist/{resolveItems-D8DJkv-4.js → resolveItems-D18skYZx.js} +2 -2
  42. package/dist/{resolveItems-D8DJkv-4.js.map → resolveItems-D18skYZx.js.map} +1 -1
  43. package/dist/{root-DSkIM1v3.js → root-dCY6j_Hh.js} +3 -3
  44. package/dist/{root-DSkIM1v3.js.map → root-dCY6j_Hh.js.map} +1 -1
  45. package/dist/tag-names-DZGvnAgd.js +2495 -0
  46. package/dist/tag-names-DZGvnAgd.js.map +1 -0
  47. package/dist/{tool-tts-inline-B71NTBbb.js → tool-tts-inline-k3hLJUfp.js} +1315 -1303
  48. package/dist/tool-tts-inline-k3hLJUfp.js.map +1 -0
  49. package/package.json +8 -8
  50. package/dist/define-D7_K0JFy.js.map +0 -1
  51. package/dist/dist-BRTWr852.js +0 -5809
  52. package/dist/dist-BRTWr852.js.map +0 -1
  53. package/dist/dist-BaQdJU08.js.map +0 -1
  54. package/dist/dist-DwvskOs6.js +0 -220
  55. package/dist/dist-DwvskOs6.js.map +0 -1
  56. package/dist/dist-ffJZTPTU.js.map +0 -1
  57. package/dist/element-class-DQy2cIPM-CldZrSRR.js.map +0 -1
  58. package/dist/item-toolbar-element-BW9Y_n5x.js +0 -1990
  59. package/dist/item-toolbar-element-BW9Y_n5x.js.map +0 -1
  60. package/dist/nl-NL-BeQBX6yq.js.map +0 -1
  61. package/dist/pie-assessment-toolkit-element-CpiB3twr.js.map +0 -1
  62. package/dist/pie-tool-calculator-BiWMTJe7.js +0 -2992
  63. package/dist/pie-tool-calculator-BiWMTJe7.js.map +0 -1
  64. package/dist/tool-tts-inline-B71NTBbb.js.map +0 -1
@@ -1,18 +1,19 @@
1
- //#region ../../node_modules/.bun/@pie-players+tts-server-core@0.3.68/node_modules/@pie-players/tts-server-core/dist/speech-marks.js
2
- var e = (e) => {
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) => {
3
4
  let t = Number(e);
4
5
  return Number.isFinite(t) ? t : null;
5
- }, t = (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), n = (n) => {
6
- let r = [], i = 0;
7
- for (let t of n.split(/\r?\n/)) {
8
- let n = t.trim();
9
- if (n) try {
10
- let t = JSON.parse(n);
11
- if (t.type && t.type !== "word") continue;
12
- let a = e(t.time);
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);
13
14
  if (a === null) continue;
14
- let o = typeof t.value == "string" ? t.value : "", s = e(t.start) ?? i, c = e(t.end) ?? s + Math.max(1, o.length);
15
- i = Math.max(c + 1, i), r.push({
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({
16
17
  time: a,
17
18
  type: "word",
18
19
  start: s,
@@ -21,8 +22,8 @@ var e = (e) => {
21
22
  });
22
23
  } catch {}
23
24
  }
24
- return t(r);
25
- }, r = (e) => {
25
+ return r(t);
26
+ }, a = (e) => {
26
27
  if (e.length < 2) return e;
27
28
  let t = e.map((e) => e.time).filter((e) => e >= 0), n = t.length ? Math.max(...t) : 0, r = [];
28
29
  for (let e = 1; e < t.length; e += 1) {
@@ -34,7 +35,7 @@ var e = (e) => {
34
35
  ...e,
35
36
  time: e.time * 1e3
36
37
  })) : e;
37
- }, i = (e, t) => {
38
+ }, o = (e, t) => {
38
39
  if (!e.length || !t.length) return 0;
39
40
  let n = t.toLowerCase(), r = [], i = 0;
40
41
  for (let t of e) {
@@ -50,40 +51,41 @@ var e = (e) => {
50
51
  return e[Math.floor(e.length / 2)];
51
52
  }
52
53
  return Math.max(0, Math.floor(e[0].start));
53
- }, a = (e, t) => {
54
+ }, s = (e, t) => {
54
55
  if (!e.length || !t.length) return e;
55
56
  let n = t.length;
56
57
  if (Math.max(...e.map((e) => e.end)) <= n + 2) return e;
57
- let r = i(e, t);
58
+ let r = o(e, t);
58
59
  return r <= 0 ? e : e.map((e) => ({
59
60
  ...e,
60
61
  start: e.start - r,
61
62
  end: e.end - r
62
63
  }));
63
- }, o = (e, n) => {
64
- if (!n.length) return e;
65
- let r = n.length;
66
- return t(e.map((e) => {
67
- let t = Math.max(0, Math.min(r, Math.floor(e.start))), n = Math.max(t + 1, Math.min(r, Math.floor(e.end)));
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)));
68
69
  return {
69
70
  ...e,
70
71
  start: t,
71
- end: n
72
+ end: r
72
73
  };
73
74
  }));
74
75
  };
75
- function s(e, t) {
76
- return o(a(r(n(e)), t), t);
76
+ function l(e, t) {
77
+ return c(s(a(i(e)), t), t);
77
78
  }
78
79
  //#endregion
79
- //#region ../../node_modules/.bun/@pie-players+tts-server-core@0.3.68/node_modules/@pie-players/tts-server-core/dist/speed-rate.js
80
- function c(e, t = "medium") {
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") {
81
82
  let n = Number(e ?? 1);
82
83
  return Number.isFinite(n) ? n <= .95 ? "slow" : n >= 1.5 ? "fast" : t : t;
83
84
  }
84
85
  //#endregion
85
- //#region ../../node_modules/.bun/@pie-players+tts-client-server@0.3.68/node_modules/@pie-players/tts-client-server/dist/ServerTTSProvider.js
86
- function l(e, t) {
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) {
87
89
  if (typeof e != "string" || e.length === 0) return null;
88
90
  try {
89
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);
@@ -92,7 +94,7 @@ function l(e, t) {
92
94
  return null;
93
95
  }
94
96
  }
95
- function u(e, t) {
97
+ function p(e, t) {
96
98
  let n = Array.isArray(t.assetOrigins) ? t.assetOrigins.filter((e) => typeof e == "string" && e.length > 0).map((e) => {
97
99
  try {
98
100
  return new URL(e).origin;
@@ -110,7 +112,7 @@ function u(e, t) {
110
112
  }
111
113
  return n.includes(e.origin);
112
114
  }
113
- function d(e) {
115
+ function m(e) {
114
116
  let t = {};
115
117
  for (let [n, r] of Object.entries(e)) {
116
118
  let e = n.toLowerCase();
@@ -118,23 +120,23 @@ function d(e) {
118
120
  }
119
121
  return t;
120
122
  }
121
- var f = (e) => {
123
+ var h = (e) => {
122
124
  let t = (e.providerOptions && typeof e.providerOptions == "object" ? e.providerOptions : {}).__pieTelemetry;
123
125
  return typeof t == "function" ? t : void 0;
124
- }, p = {
126
+ }, g = {
125
127
  pie: 3e3,
126
128
  custom: 3e3
127
- }, m = /* @__PURE__ */ new Set(["polly", "google"]), h = (e) => {
128
- if (!e || v(e) !== "pie") return !1;
129
+ }, _ = /* @__PURE__ */ new Set(["polly", "google"]), v = (e) => {
130
+ if (!e || x(e) !== "pie") return !1;
129
131
  let t = (e.provider || "polly").toLowerCase();
130
- return m.has(t);
131
- }, g = (e) => e.replace(/\/+$/, ""), _ = (e) => {
132
- let t = g(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();
133
135
  return n === "polly" || n === "google" ? `${t}/${n}/voices` : `${t}/voices`;
134
- }, v = (e) => e.transportMode === "custom" ? "custom" : e.transportMode === "pie" ? "pie" : e.provider === "custom" ? "custom" : "pie", y = (e, t) => e.endpointMode ? e.endpointMode : t === "custom" ? "rootPost" : "synthesizePath", b = (e, t) => e.endpointValidationMode ? e.endpointValidationMode : t === "custom" ? "none" : "voices", x = (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) => {
135
137
  let t = e.providerOptions || {};
136
- return typeof t.speedRate == "string" ? t.speedRate : c(e.rate);
137
- }, S = (e) => {
138
+ return typeof t.speedRate == "string" ? t.speedRate : u(e.rate);
139
+ }, T = (e) => {
138
140
  if (!Array.isArray(e)) return [];
139
141
  let t = [], n = 0;
140
142
  for (let r of e) {
@@ -149,11 +151,11 @@ var f = (e) => {
149
151
  });
150
152
  }
151
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);
152
- }, C = {
154
+ }, E = {
153
155
  pie: {
154
156
  id: "pie",
155
157
  resolveSynthesisUrl: (e) => {
156
- let t = y(e, "pie"), n = g(e.apiEndpoint);
158
+ let t = S(e, "pie"), n = y(e.apiEndpoint);
157
159
  return t === "rootPost" ? n : `${n}/synthesize`;
158
160
  },
159
161
  buildRequestBody: (e, t) => {
@@ -186,14 +188,14 @@ var f = (e) => {
186
188
  custom: {
187
189
  id: "custom",
188
190
  resolveSynthesisUrl: (e) => {
189
- let t = y(e, "custom"), n = g(e.apiEndpoint);
191
+ let t = S(e, "custom"), n = y(e.apiEndpoint);
190
192
  return t === "synthesizePath" ? `${n}/synthesize` : n;
191
193
  },
192
194
  buildRequestBody: (e, t) => {
193
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;
194
196
  return {
195
197
  text: e,
196
- speedRate: x(t),
198
+ speedRate: w(t),
197
199
  lang_id: r,
198
200
  cache: i
199
201
  };
@@ -201,37 +203,38 @@ var f = (e) => {
201
203
  parseResponse: async (e, t, n, r, i) => {
202
204
  let a = await e.json(), o = {};
203
205
  if (t.includeAuthOnAssetFetch) for (let [e, t] of Object.entries(n)) e.toLowerCase() === "authorization" && (o[e] = t);
204
- let c = [], f = S(a.speechMarks);
205
- if (f.length > 0) c = f;
206
+ let s = [], c = T(a.speechMarks);
207
+ if (c.length > 0) s = c;
206
208
  else if (typeof a.word == "string" && a.word.length > 0) {
207
- let e = l(a.word, t);
209
+ let e = f(a.word, t);
208
210
  if (e !== null) {
209
- let n = u(e, t) ? o : d(o), a = await fetch(e.toString(), {
211
+ let n = p(e, t) ? o : m(o), a = await fetch(e.toString(), {
210
212
  headers: n,
211
213
  signal: r,
212
214
  redirect: "error"
213
215
  });
214
- a.ok && (c = s(await a.text(), i));
216
+ a.ok && (s = l(await a.text(), i));
215
217
  }
216
218
  }
217
- let p = l(a.audioContent, t);
218
- if (p === 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");
219
221
  return {
220
222
  audio: {
221
223
  kind: "url",
222
- url: p.toString()
224
+ url: u.toString()
223
225
  },
224
- speechMarks: c
226
+ speechMarks: s
225
227
  };
226
228
  }
227
229
  }
228
- }, w = class {
230
+ }, D = class {
229
231
  config;
230
232
  adapter;
231
233
  currentAudio = null;
232
234
  pausedState = !1;
233
235
  wordTimings = [];
234
236
  highlightInterval = null;
237
+ highlightCursor = -1;
235
238
  intentionallyStopped = !1;
236
239
  activeSynthesisController = null;
237
240
  synthesisRunId = 0;
@@ -239,13 +242,13 @@ var f = (e) => {
239
242
  onPlaybackStart;
240
243
  onWordBoundary;
241
244
  constructor(e, t) {
242
- this.config = e, this.adapter = t, this.telemetryReporter = f(e);
245
+ this.config = e, this.adapter = t, this.telemetryReporter = h(e);
243
246
  }
244
247
  async emitTelemetry(e, t) {
245
248
  try {
246
249
  await this.telemetryReporter?.(e, t);
247
250
  } catch (e) {
248
- console.warn("[ServerTTSProvider] telemetry callback failed:", e);
251
+ d.warn("telemetry callback failed:", e);
249
252
  }
250
253
  }
251
254
  async speak(e) {
@@ -257,7 +260,7 @@ var f = (e) => {
257
260
  URL.revokeObjectURL(r);
258
261
  return;
259
262
  }
260
- return this.wordTimings = i, new Promise((e, n) => {
263
+ return this.wordTimings = i, this.highlightCursor = -1, new Promise((e, n) => {
261
264
  let i = new Audio(r);
262
265
  this.currentAudio = i, this.config.volume !== void 0 && (i.volume = Math.max(0, Math.min(1, this.config.volume))), i.onplay = () => {
263
266
  if (t === this.synthesisRunId && this.currentAudio === i) {
@@ -265,14 +268,14 @@ var f = (e) => {
265
268
  try {
266
269
  this.onPlaybackStart?.();
267
270
  } catch (e) {
268
- console.warn("[ServerTTSProvider] playback-start callback failed:", e);
271
+ d.warn("playback-start callback failed:", e);
269
272
  }
270
273
  this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting();
271
274
  }
272
275
  }, i.onended = () => {
273
- 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();
274
277
  }, i.onerror = (t) => {
275
- 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"));
276
279
  }, i.onpause = () => {
277
280
  this.stopWordHighlighting(), this.pausedState = !0;
278
281
  }, i.play().catch(n);
@@ -314,12 +317,12 @@ var f = (e) => {
314
317
  if (t) try {
315
318
  n = JSON.parse(t);
316
319
  } catch (e) {
317
- console.warn("[ServerTTSProvider] non-OK response body was not JSON", {
320
+ d.warn("non-OK response body was not JSON", {
318
321
  status: s.status,
319
322
  url: a,
320
- rawBodyPreview: t.slice(0, 500),
323
+ bodyLength: t.length,
321
324
  parseError: e instanceof Error ? e.message : String(e)
322
- });
325
+ }), d.debug("non-OK response body", { rawBodyPreview: t.slice(0, 500) });
323
326
  }
324
327
  let i = typeof n.message == "string" && n.message || (typeof n.error?.message == "string" ? n.error.message : void 0) || `Server returned ${s.status}`;
325
328
  await this.emitTelemetry("pie-tool-backend-call-error", {
@@ -330,22 +333,23 @@ var f = (e) => {
330
333
  statusCode: s.status,
331
334
  errorType: "TTSBackendRequestError",
332
335
  message: i
333
- });
334
- let o = e.replace(/\s+/g, " ").trim().slice(0, 120);
335
- throw console.error("[ServerTTSProvider] synthesize request failed", {
336
+ }), d.error("synthesize request failed", {
336
337
  status: s.status,
337
338
  url: a,
338
339
  backend: this.config.provider || "server",
339
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", {
340
345
  responseBody: n,
341
- textLength: e.length,
342
346
  textPreview: o.length < e.length ? `${o}…` : o
343
347
  }), Error(i);
344
348
  }
345
349
  let c = await this.adapter.parseResponse(s, this.config, i, t, e);
346
350
  if (n !== this.synthesisRunId || t.aborted) throw Error("Synthesis superseded by a newer request");
347
- let f;
348
- if (c.audio.kind === "base64") f = this.base64ToBlob(c.audio.data, c.audio.contentType);
351
+ let l;
352
+ if (c.audio.kind === "base64") l = this.base64ToBlob(c.audio.data, c.audio.contentType);
349
353
  else {
350
354
  let e = c.audio.url, n = Date.now();
351
355
  await this.emitTelemetry("pie-tool-backend-call-start", {
@@ -355,7 +359,7 @@ var f = (e) => {
355
359
  });
356
360
  let r = {};
357
361
  this.config.includeAuthOnAssetFetch && this.config.authToken && (r.Authorization = `Bearer ${this.config.authToken}`);
358
- let i = l(e, this.config);
362
+ let i = f(e, this.config);
359
363
  if (i === null) throw await this.emitTelemetry("pie-tool-backend-call-error", {
360
364
  toolId: "tts",
361
365
  backend: this.config.provider || "server",
@@ -364,7 +368,7 @@ var f = (e) => {
364
368
  errorType: "TTSAssetInvalidUrl",
365
369
  message: "TTS asset URL rejected (non-http(s) or malformed)"
366
370
  }), Error("TTS asset URL rejected (non-http(s) or malformed)");
367
- let a = u(i, this.config) ? r : d(r), o = await (async () => {
371
+ let a = p(i, this.config) ? r : m(r), o = await (async () => {
368
372
  try {
369
373
  return await fetch(i.toString(), {
370
374
  headers: a,
@@ -391,22 +395,22 @@ var f = (e) => {
391
395
  errorType: "TTSAssetFetchError",
392
396
  message: `Failed to download synthesized audio (${o.status})`
393
397
  }), Error(`Failed to download synthesized audio (${o.status})`);
394
- f = await o.blob(), await this.emitTelemetry("pie-tool-backend-call-success", {
398
+ l = await o.blob(), await this.emitTelemetry("pie-tool-backend-call-success", {
395
399
  toolId: "tts",
396
400
  backend: this.config.provider || "server",
397
401
  operation: "fetch-synthesized-audio-asset",
398
402
  duration: Date.now() - n
399
403
  });
400
404
  }
401
- let p = URL.createObjectURL(f), m = this.parseSpeechMarks(c.speechMarks);
405
+ let u = URL.createObjectURL(l), h = this.parseSpeechMarks(c.speechMarks);
402
406
  return await this.emitTelemetry("pie-tool-backend-call-success", {
403
407
  toolId: "tts",
404
408
  backend: this.config.provider || "server",
405
409
  operation: "synthesize-speech",
406
410
  duration: Date.now() - r
407
411
  }), {
408
- audioUrl: p,
409
- wordTimings: m
412
+ audioUrl: u,
413
+ wordTimings: h
410
414
  };
411
415
  }
412
416
  base64ToBlob(e, t) {
@@ -426,30 +430,39 @@ var f = (e) => {
426
430
  }
427
431
  startWordHighlighting() {
428
432
  if (this.stopWordHighlighting(), !this.currentAudio || !this.onWordBoundary || this.wordTimings.length === 0) {
429
- console.log("[ServerTTSProvider] Cannot start highlighting:", {
433
+ d.debug("cannot start word highlighting", {
430
434
  hasAudio: !!this.currentAudio,
431
435
  hasCallback: !!this.onWordBoundary,
432
436
  wordTimingsCount: this.wordTimings.length
433
437
  });
434
438
  return;
435
439
  }
436
- 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));
437
- let e = -1;
438
- 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(() => {
439
444
  if (!this.currentAudio) {
440
445
  this.stopWordHighlighting();
441
446
  return;
442
447
  }
443
- let t = this.currentAudio.currentTime * 1e3;
444
- for (let n = 0; n < this.wordTimings.length; n++) {
445
- let r = this.wordTimings[n];
446
- if (t >= r.time && n > e) {
447
- 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;
448
- break;
449
- }
450
- }
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);
451
459
  }, 50);
452
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
+ }
453
466
  stopWordHighlighting() {
454
467
  this.highlightInterval !== null && (clearInterval(this.highlightInterval), this.highlightInterval = null);
455
468
  }
@@ -460,7 +473,7 @@ var f = (e) => {
460
473
  this.currentAudio && this.pausedState && (this.currentAudio.play(), this.pausedState = !1, this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting());
461
474
  }
462
475
  stop() {
463
- 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;
464
477
  }
465
478
  isPlaying() {
466
479
  return this.currentAudio !== null && !this.pausedState;
@@ -471,10 +484,10 @@ var f = (e) => {
471
484
  updateSettings(e) {
472
485
  e.rate !== void 0 && (this.config.rate = e.rate, this.config.providerOptions = {
473
486
  ...this.config.providerOptions || {},
474
- speedRate: c(e.rate)
487
+ speedRate: u(e.rate)
475
488
  }), e.pitch !== void 0 && (this.config.pitch = e.pitch), e.voice !== void 0 && (this.config.voice = e.voice);
476
489
  }
477
- }, T = class {
490
+ }, O = class {
478
491
  providerId = "server-tts";
479
492
  providerName = "Server TTS";
480
493
  version = "1.0.0";
@@ -485,15 +498,15 @@ var f = (e) => {
485
498
  try {
486
499
  await this.telemetryReporter?.(e, t);
487
500
  } catch (e) {
488
- console.warn("[ServerTTSProvider] telemetry callback failed:", e);
501
+ d.warn("telemetry callback failed:", e);
489
502
  }
490
503
  }
491
504
  async initialize(e) {
492
505
  let t = e;
493
506
  if (!t.apiEndpoint) throw Error("apiEndpoint is required for ServerTTSProvider");
494
- this.config = t, this.telemetryReporter = f(t);
495
- let n = v(t);
496
- if (this.adapter = C[n], t.validateEndpoint) {
507
+ this.config = t, this.telemetryReporter = h(t);
508
+ let n = x(t);
509
+ if (this.adapter = E[n], t.validateEndpoint) {
497
510
  let e = Date.now();
498
511
  if (await this.emitTelemetry("pie-tool-backend-call-start", {
499
512
  toolId: "tts",
@@ -514,16 +527,16 @@ var f = (e) => {
514
527
  duration: Date.now() - e
515
528
  });
516
529
  }
517
- return new w(t, this.adapter);
530
+ return new D(t, this.adapter);
518
531
  }
519
532
  async testAPIAvailability() {
520
533
  if (!this.config || !this.adapter) return !1;
521
534
  try {
522
535
  let e = { ...this.config.headers };
523
536
  this.config.authToken && (e.Authorization = `Bearer ${this.config.authToken}`);
524
- let t = new AbortController(), n = setTimeout(() => t.abort(), 5e3), r = b(this.config, this.adapter.id);
537
+ let t = new AbortController(), n = setTimeout(() => t.abort(), 5e3), r = C(this.config, this.adapter.id);
525
538
  if (r === "none") return clearTimeout(n), !0;
526
- let i = r === "voices" ? _(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";
527
540
  try {
528
541
  let r = await fetch(i, {
529
542
  method: a,
@@ -550,7 +563,7 @@ var f = (e) => {
550
563
  }
551
564
  }
552
565
  getCapabilities() {
553
- let e = this.config ? v(this.config) : "pie";
566
+ let e = this.config ? x(this.config) : "pie";
554
567
  return {
555
568
  supportsPause: !0,
556
569
  supportsResume: !0,
@@ -558,8 +571,8 @@ var f = (e) => {
558
571
  supportsVoiceSelection: !0,
559
572
  supportsRateControl: !0,
560
573
  supportsPitchControl: !1,
561
- supportsSSML: h(this.config),
562
- maxTextLength: p[e]
574
+ supportsSSML: v(this.config),
575
+ maxTextLength: g[e]
563
576
  };
564
577
  }
565
578
  destroy() {
@@ -567,6 +580,6 @@ var f = (e) => {
567
580
  }
568
581
  };
569
582
  //#endregion
570
- export { T as ServerTTSProvider };
583
+ export { O as ServerTTSProvider };
571
584
 
572
- //# sourceMappingURL=dist-BaQdJU08.js.map
585
+ //# sourceMappingURL=dist-L-bDDBry.js.map