@pie-players/pie-section-player 0.3.17 → 0.3.20
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/README.md +76 -2
- package/dist/components/shared/player-action.d.ts +0 -2
- package/dist/components/shared/player-action.d.ts.map +1 -1
- package/dist/components/shared/player-preload.d.ts.map +1 -1
- package/dist/components/shared/section-player-runtime.d.ts +38 -7
- package/dist/components/shared/section-player-runtime.d.ts.map +1 -1
- package/dist/components/shared/section-player-view-state.d.ts.map +1 -1
- package/dist/contracts/layout-contract.d.ts +1 -1
- package/dist/contracts/layout-contract.d.ts.map +1 -1
- package/dist/contracts/layout-parity-metadata.d.ts.map +1 -1
- package/dist/controllers/SectionController.d.ts.map +1 -1
- package/dist/defineProperty-CyepwRr5-eHUSgEtz.js +33 -0
- package/dist/defineProperty-CyepwRr5.js +33 -0
- package/dist/dist-BCuSaTvi.js +393 -0
- package/dist/dist-BIgX-aC4-C5B4fLQK.js +389 -0
- package/dist/dist-DwP27yIs-gkxodgFn.js +201 -0
- package/dist/dist-S3IAfazl.js +201 -0
- package/dist/{index-BZq66Ke6-D8dZwpj4.js → module-COIydQYl-2o-TlgiW.js} +38152 -30086
- package/dist/pie-section-player.js +7438 -8680
- package/dist/player-preload-C_CjM5hv.js +6317 -0
- package/dist/tool-annotation-toolbar-BS_MjvXd.js +3974 -0
- package/dist/utils/player-preload.js +5 -5
- package/package.json +14 -14
- package/dist/index-CGqExkh0-DYpgzOOU.js +0 -338
- package/dist/index-CGqExkh0.js +0 -354
- package/dist/index-DF-Dk87f-lxErM8bo.js +0 -178
- package/dist/index-DF-Dk87f.js +0 -192
- package/dist/player-preload-Dxvgw3gW.js +0 -7023
- package/dist/tool-annotation-toolbar-BOoJpOXj.js +0 -4845
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { t as d } from "./defineProperty-CyepwRr5-eHUSgEtz.js";
|
|
2
|
+
var b = (e) => {
|
|
3
|
+
const t = (e.providerOptions && typeof e.providerOptions == "object" ? e.providerOptions : {}).__pieTelemetry;
|
|
4
|
+
return typeof t == "function" ? t : void 0;
|
|
5
|
+
}, S = {
|
|
6
|
+
pie: 3e3,
|
|
7
|
+
custom: 3e3
|
|
8
|
+
}, v = (e) => e.replace(/\/+$/, ""), k = (e) => {
|
|
9
|
+
const t = v(e.apiEndpoint), i = (e.provider || "").toLowerCase();
|
|
10
|
+
return i === "polly" || i === "google" ? `${t}/${i}/voices` : `${t}/voices`;
|
|
11
|
+
}, w = (e) => e.transportMode === "custom" ? "custom" : e.transportMode === "pie" ? "pie" : e.provider === "custom" ? "custom" : "pie", T = (e, t) => e.endpointMode ? e.endpointMode : t === "custom" ? "rootPost" : "synthesizePath", A = (e, t) => e.endpointValidationMode ? e.endpointValidationMode : t === "custom" ? "none" : "voices", R = (e) => {
|
|
12
|
+
const t = e.providerOptions || {};
|
|
13
|
+
if (typeof t.speedRate == "string") return t.speedRate;
|
|
14
|
+
const i = Number(e.rate ?? 1);
|
|
15
|
+
return !Number.isFinite(i) || i <= 0.95 ? "slow" : i >= 1.5 ? "fast" : "medium";
|
|
16
|
+
}, I = (e) => {
|
|
17
|
+
const t = [];
|
|
18
|
+
let i = 0;
|
|
19
|
+
const r = e.split(`
|
|
20
|
+
`).map((o) => o.trim()).filter(Boolean);
|
|
21
|
+
for (const o of r) try {
|
|
22
|
+
const s = JSON.parse(o), h = typeof s.type == "string" ? s.type : "word", n = typeof s.time == "number" && Number.isFinite(s.time) ? s.time : 0, a = typeof s.value == "string" ? s.value : "", l = typeof s.start == "number" && Number.isFinite(s.start) ? s.start : null, m = typeof s.end == "number" && Number.isFinite(s.end) ? s.end : null, g = l ?? i, c = m ?? g + Math.max(1, a.length || String(s.value || "").length);
|
|
23
|
+
i = Math.max(c + 1, i), t.push({
|
|
24
|
+
time: n,
|
|
25
|
+
type: h,
|
|
26
|
+
start: g,
|
|
27
|
+
end: c,
|
|
28
|
+
value: a
|
|
29
|
+
});
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
return t;
|
|
33
|
+
}, M = {
|
|
34
|
+
pie: {
|
|
35
|
+
id: "pie",
|
|
36
|
+
resolveSynthesisUrl: (e) => {
|
|
37
|
+
const t = T(e, "pie"), i = v(e.apiEndpoint);
|
|
38
|
+
return t === "rootPost" ? i : `${i}/synthesize`;
|
|
39
|
+
},
|
|
40
|
+
buildRequestBody: (e, t) => {
|
|
41
|
+
const i = t.providerOptions || {}, r = typeof t.engine == "string" ? t.engine : typeof i.engine == "string" ? i.engine : void 0, o = typeof i.sampleRate == "number" && Number.isFinite(i.sampleRate) ? i.sampleRate : void 0, s = i.format === "mp3" || i.format === "ogg" || i.format === "pcm" ? i.format : void 0, h = Array.isArray(i.speechMarkTypes) ? i.speechMarkTypes.filter((n) => n === "word" || n === "sentence" || n === "ssml") : void 0;
|
|
42
|
+
return {
|
|
43
|
+
text: e,
|
|
44
|
+
provider: t.provider || "polly",
|
|
45
|
+
voice: t.voice,
|
|
46
|
+
language: t.language,
|
|
47
|
+
rate: t.rate,
|
|
48
|
+
engine: r,
|
|
49
|
+
sampleRate: o,
|
|
50
|
+
format: s,
|
|
51
|
+
speechMarkTypes: h,
|
|
52
|
+
includeSpeechMarks: !0
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
parseResponse: async (e) => {
|
|
56
|
+
const t = await e.json();
|
|
57
|
+
return {
|
|
58
|
+
audio: {
|
|
59
|
+
kind: "base64",
|
|
60
|
+
data: t.audio,
|
|
61
|
+
contentType: t.contentType
|
|
62
|
+
},
|
|
63
|
+
speechMarks: Array.isArray(t.speechMarks) ? t.speechMarks : []
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
custom: {
|
|
68
|
+
id: "custom",
|
|
69
|
+
resolveSynthesisUrl: (e) => {
|
|
70
|
+
const t = T(e, "custom"), i = v(e.apiEndpoint);
|
|
71
|
+
return t === "synthesizePath" ? `${i}/synthesize` : i;
|
|
72
|
+
},
|
|
73
|
+
buildRequestBody: (e, t) => {
|
|
74
|
+
const i = t.providerOptions || {}, r = typeof i.lang_id == "string" ? i.lang_id : t.language || "en-US", o = typeof i.cache == "boolean" ? i.cache : !0;
|
|
75
|
+
return {
|
|
76
|
+
text: e,
|
|
77
|
+
speedRate: R(t),
|
|
78
|
+
lang_id: r,
|
|
79
|
+
cache: o
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
parseResponse: async (e, t, i, r) => {
|
|
83
|
+
const o = await e.json(), s = {};
|
|
84
|
+
if (t.includeAuthOnAssetFetch) for (const [n, a] of Object.entries(i)) n.toLowerCase() === "authorization" && (s[n] = a);
|
|
85
|
+
let h = [];
|
|
86
|
+
if (typeof o.word == "string" && o.word.length > 0) {
|
|
87
|
+
const n = await fetch(o.word, {
|
|
88
|
+
headers: s,
|
|
89
|
+
signal: r
|
|
90
|
+
});
|
|
91
|
+
n.ok && (h = I(await n.text()));
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
audio: {
|
|
95
|
+
kind: "url",
|
|
96
|
+
url: o.audioContent
|
|
97
|
+
},
|
|
98
|
+
speechMarks: h
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}, P = class {
|
|
103
|
+
constructor(e, t) {
|
|
104
|
+
d(this, "config", void 0), d(this, "adapter", void 0), d(this, "currentAudio", null), d(this, "pausedState", !1), d(this, "wordTimings", []), d(this, "highlightInterval", null), d(this, "intentionallyStopped", !1), d(this, "activeSynthesisController", null), d(this, "synthesisRunId", 0), d(this, "telemetryReporter", void 0), d(this, "onWordBoundary", void 0), this.config = e, this.adapter = t, this.telemetryReporter = b(e);
|
|
105
|
+
}
|
|
106
|
+
async emitTelemetry(e, t) {
|
|
107
|
+
try {
|
|
108
|
+
await this.telemetryReporter?.(e, t);
|
|
109
|
+
} catch (i) {
|
|
110
|
+
console.warn("[ServerTTSProvider] telemetry callback failed:", i);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async speak(e) {
|
|
114
|
+
this.stop(), this.intentionallyStopped = !1;
|
|
115
|
+
const t = ++this.synthesisRunId, i = new AbortController();
|
|
116
|
+
this.activeSynthesisController = i;
|
|
117
|
+
const { audioUrl: r, wordTimings: o } = await this.synthesizeSpeech(e, i.signal, t);
|
|
118
|
+
if (t !== this.synthesisRunId) {
|
|
119
|
+
URL.revokeObjectURL(r);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const s = this.config.rate || 1;
|
|
123
|
+
return this.wordTimings = o.map((h) => ({
|
|
124
|
+
...h,
|
|
125
|
+
time: h.time / s
|
|
126
|
+
})), new Promise((h, n) => {
|
|
127
|
+
const a = new Audio(r);
|
|
128
|
+
this.currentAudio = a, this.config.rate && (a.playbackRate = Math.max(0.25, Math.min(4, this.config.rate))), this.config.volume !== void 0 && (a.volume = Math.max(0, Math.min(1, this.config.volume))), a.onplay = () => {
|
|
129
|
+
this.pausedState = !1, this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting();
|
|
130
|
+
}, a.onended = () => {
|
|
131
|
+
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], h();
|
|
132
|
+
}, a.onerror = (l) => {
|
|
133
|
+
this.stopWordHighlighting(), URL.revokeObjectURL(r), this.currentAudio = null, this.wordTimings = [], this.intentionallyStopped ? h() : n(/* @__PURE__ */ new Error("Failed to play audio from server"));
|
|
134
|
+
}, a.onpause = () => {
|
|
135
|
+
this.stopWordHighlighting(), this.pausedState = !0;
|
|
136
|
+
}, a.play().catch(n);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async synthesizeSpeech(e, t, i) {
|
|
140
|
+
const r = Date.now();
|
|
141
|
+
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
142
|
+
toolId: "tts",
|
|
143
|
+
backend: this.config.provider || "server",
|
|
144
|
+
operation: "synthesize-speech"
|
|
145
|
+
});
|
|
146
|
+
const o = {
|
|
147
|
+
"Content-Type": "application/json",
|
|
148
|
+
...this.config.headers
|
|
149
|
+
};
|
|
150
|
+
this.config.authToken && (o.Authorization = `Bearer ${this.config.authToken}`);
|
|
151
|
+
const s = this.adapter.resolveSynthesisUrl(this.config), h = this.adapter.buildRequestBody(e, this.config), n = await (async () => {
|
|
152
|
+
try {
|
|
153
|
+
return await fetch(s, {
|
|
154
|
+
method: "POST",
|
|
155
|
+
headers: o,
|
|
156
|
+
body: JSON.stringify(h),
|
|
157
|
+
signal: t
|
|
158
|
+
});
|
|
159
|
+
} catch (c) {
|
|
160
|
+
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
161
|
+
toolId: "tts",
|
|
162
|
+
backend: this.config.provider || "server",
|
|
163
|
+
operation: "synthesize-speech",
|
|
164
|
+
duration: Date.now() - r,
|
|
165
|
+
errorType: "TTSBackendNetworkError",
|
|
166
|
+
message: c instanceof Error ? c.message : String(c)
|
|
167
|
+
}), c;
|
|
168
|
+
}
|
|
169
|
+
})();
|
|
170
|
+
if (!n.ok) {
|
|
171
|
+
const c = await n.json().catch(() => ({})), u = c.message || c.error?.message || `Server returned ${n.status}`;
|
|
172
|
+
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
173
|
+
toolId: "tts",
|
|
174
|
+
backend: this.config.provider || "server",
|
|
175
|
+
operation: "synthesize-speech",
|
|
176
|
+
duration: Date.now() - r,
|
|
177
|
+
statusCode: n.status,
|
|
178
|
+
errorType: "TTSBackendRequestError",
|
|
179
|
+
message: u
|
|
180
|
+
}), new Error(u);
|
|
181
|
+
}
|
|
182
|
+
const a = await this.adapter.parseResponse(n, this.config, o, t);
|
|
183
|
+
if (i !== this.synthesisRunId || t.aborted) throw new Error("Synthesis superseded by a newer request");
|
|
184
|
+
let l;
|
|
185
|
+
if (a.audio.kind === "base64") l = this.base64ToBlob(a.audio.data, a.audio.contentType);
|
|
186
|
+
else {
|
|
187
|
+
const c = a.audio.url, u = Date.now();
|
|
188
|
+
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
189
|
+
toolId: "tts",
|
|
190
|
+
backend: this.config.provider || "server",
|
|
191
|
+
operation: "fetch-synthesized-audio-asset"
|
|
192
|
+
});
|
|
193
|
+
const f = {};
|
|
194
|
+
this.config.includeAuthOnAssetFetch && this.config.authToken && (f.Authorization = `Bearer ${this.config.authToken}`);
|
|
195
|
+
const p = await (async () => {
|
|
196
|
+
try {
|
|
197
|
+
return await fetch(c, {
|
|
198
|
+
headers: f,
|
|
199
|
+
signal: t
|
|
200
|
+
});
|
|
201
|
+
} catch (y) {
|
|
202
|
+
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
203
|
+
toolId: "tts",
|
|
204
|
+
backend: this.config.provider || "server",
|
|
205
|
+
operation: "fetch-synthesized-audio-asset",
|
|
206
|
+
duration: Date.now() - u,
|
|
207
|
+
errorType: "TTSAssetNetworkError",
|
|
208
|
+
message: y instanceof Error ? y.message : String(y)
|
|
209
|
+
}), y;
|
|
210
|
+
}
|
|
211
|
+
})();
|
|
212
|
+
if (!p.ok) throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
213
|
+
toolId: "tts",
|
|
214
|
+
backend: this.config.provider || "server",
|
|
215
|
+
operation: "fetch-synthesized-audio-asset",
|
|
216
|
+
duration: Date.now() - u,
|
|
217
|
+
statusCode: p.status,
|
|
218
|
+
errorType: "TTSAssetFetchError",
|
|
219
|
+
message: `Failed to download synthesized audio (${p.status})`
|
|
220
|
+
}), /* @__PURE__ */ new Error(`Failed to download synthesized audio (${p.status})`);
|
|
221
|
+
l = await p.blob(), await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
222
|
+
toolId: "tts",
|
|
223
|
+
backend: this.config.provider || "server",
|
|
224
|
+
operation: "fetch-synthesized-audio-asset",
|
|
225
|
+
duration: Date.now() - u
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
const m = URL.createObjectURL(l), g = this.parseSpeechMarks(a.speechMarks);
|
|
229
|
+
return await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
230
|
+
toolId: "tts",
|
|
231
|
+
backend: this.config.provider || "server",
|
|
232
|
+
operation: "synthesize-speech",
|
|
233
|
+
duration: Date.now() - r
|
|
234
|
+
}), {
|
|
235
|
+
audioUrl: m,
|
|
236
|
+
wordTimings: g
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
base64ToBlob(e, t) {
|
|
240
|
+
const i = atob(e), r = new Array(i.length);
|
|
241
|
+
for (let o = 0; o < i.length; o++) r[o] = i.charCodeAt(o);
|
|
242
|
+
return new Blob([new Uint8Array(r)], { type: t });
|
|
243
|
+
}
|
|
244
|
+
parseSpeechMarks(e) {
|
|
245
|
+
return e.filter((t) => t.type === "word").map((t, i) => ({
|
|
246
|
+
time: t.time,
|
|
247
|
+
wordIndex: i,
|
|
248
|
+
charIndex: t.start,
|
|
249
|
+
length: t.end - t.start
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
startWordHighlighting() {
|
|
253
|
+
if (this.stopWordHighlighting(), !this.currentAudio || !this.onWordBoundary || this.wordTimings.length === 0) {
|
|
254
|
+
console.log("[ServerTTSProvider] Cannot start highlighting:", {
|
|
255
|
+
hasAudio: !!this.currentAudio,
|
|
256
|
+
hasCallback: !!this.onWordBoundary,
|
|
257
|
+
wordTimingsCount: this.wordTimings.length
|
|
258
|
+
});
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
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));
|
|
262
|
+
let e = -1;
|
|
263
|
+
this.highlightInterval = window.setInterval(() => {
|
|
264
|
+
if (!this.currentAudio) {
|
|
265
|
+
this.stopWordHighlighting();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const t = this.currentAudio.currentTime * 1e3;
|
|
269
|
+
for (let i = 0; i < this.wordTimings.length; i++) {
|
|
270
|
+
const r = this.wordTimings[i];
|
|
271
|
+
if (t >= r.time && i > e) {
|
|
272
|
+
this.onWordBoundary && (console.log("[ServerTTSProvider] Highlighting word at charIndex:", r.charIndex, "length:", r.length, "time:", r.time, "currentTime:", t), this.onWordBoundary("", r.charIndex, r.length)), e = i;
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}, 50);
|
|
277
|
+
}
|
|
278
|
+
stopWordHighlighting() {
|
|
279
|
+
this.highlightInterval !== null && (clearInterval(this.highlightInterval), this.highlightInterval = null);
|
|
280
|
+
}
|
|
281
|
+
pause() {
|
|
282
|
+
this.currentAudio && !this.pausedState && (this.currentAudio.pause(), this.stopWordHighlighting(), this.pausedState = !0);
|
|
283
|
+
}
|
|
284
|
+
resume() {
|
|
285
|
+
this.currentAudio && this.pausedState && (this.currentAudio.play(), this.pausedState = !1, this.onWordBoundary && this.wordTimings.length > 0 && this.startWordHighlighting());
|
|
286
|
+
}
|
|
287
|
+
stop() {
|
|
288
|
+
this.synthesisRunId += 1, this.activeSynthesisController && (this.activeSynthesisController.abort(), this.activeSynthesisController = null), this.stopWordHighlighting(), this.currentAudio && (this.intentionallyStopped = !0, this.currentAudio.pause(), this.currentAudio.src && URL.revokeObjectURL(this.currentAudio.src), this.currentAudio.src = "", this.currentAudio = null), this.pausedState = !1, this.wordTimings = [];
|
|
289
|
+
}
|
|
290
|
+
isPlaying() {
|
|
291
|
+
return this.currentAudio !== null && !this.pausedState;
|
|
292
|
+
}
|
|
293
|
+
isPaused() {
|
|
294
|
+
return this.pausedState;
|
|
295
|
+
}
|
|
296
|
+
updateSettings(e) {
|
|
297
|
+
e.rate !== void 0 && (this.config.rate = e.rate, this.currentAudio && (this.currentAudio.playbackRate = Math.max(0.25, Math.min(4, e.rate)))), e.pitch !== void 0 && (this.config.pitch = e.pitch), e.voice !== void 0 && (this.config.voice = e.voice);
|
|
298
|
+
}
|
|
299
|
+
}, C = class {
|
|
300
|
+
constructor() {
|
|
301
|
+
d(this, "providerId", "server-tts"), d(this, "providerName", "Server TTS"), d(this, "version", "1.0.0"), d(this, "config", null), d(this, "adapter", null), d(this, "telemetryReporter", void 0);
|
|
302
|
+
}
|
|
303
|
+
async emitTelemetry(e, t) {
|
|
304
|
+
try {
|
|
305
|
+
await this.telemetryReporter?.(e, t);
|
|
306
|
+
} catch (i) {
|
|
307
|
+
console.warn("[ServerTTSProvider] telemetry callback failed:", i);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
async initialize(e) {
|
|
311
|
+
const t = e;
|
|
312
|
+
if (!t.apiEndpoint) throw new Error("apiEndpoint is required for ServerTTSProvider");
|
|
313
|
+
if (this.config = t, this.telemetryReporter = b(t), this.adapter = M[w(t)], t.validateEndpoint) {
|
|
314
|
+
const i = Date.now();
|
|
315
|
+
if (await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
316
|
+
toolId: "tts",
|
|
317
|
+
backend: t.provider || "server",
|
|
318
|
+
operation: "validate-endpoint"
|
|
319
|
+
}), !await this.testAPIAvailability()) throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
320
|
+
toolId: "tts",
|
|
321
|
+
backend: t.provider || "server",
|
|
322
|
+
operation: "validate-endpoint",
|
|
323
|
+
duration: Date.now() - i,
|
|
324
|
+
errorType: "TTSEndpointValidationError",
|
|
325
|
+
message: `Server TTS API not available at ${t.apiEndpoint}`
|
|
326
|
+
}), /* @__PURE__ */ new Error(`Server TTS API not available at ${t.apiEndpoint}`);
|
|
327
|
+
await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
328
|
+
toolId: "tts",
|
|
329
|
+
backend: t.provider || "server",
|
|
330
|
+
operation: "validate-endpoint",
|
|
331
|
+
duration: Date.now() - i
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
return new P(t, this.adapter);
|
|
335
|
+
}
|
|
336
|
+
async testAPIAvailability() {
|
|
337
|
+
if (!this.config || !this.adapter) return !1;
|
|
338
|
+
try {
|
|
339
|
+
const e = { ...this.config.headers };
|
|
340
|
+
this.config.authToken && (e.Authorization = `Bearer ${this.config.authToken}`);
|
|
341
|
+
const t = new AbortController(), i = setTimeout(() => t.abort(), 5e3), r = A(this.config, this.adapter.id);
|
|
342
|
+
if (r === "none") return clearTimeout(i), !0;
|
|
343
|
+
const o = r === "voices" ? k(this.config) : this.adapter.resolveSynthesisUrl(this.config), s = r === "voices" ? "GET" : "OPTIONS";
|
|
344
|
+
try {
|
|
345
|
+
const h = await fetch(o, {
|
|
346
|
+
method: s,
|
|
347
|
+
headers: e,
|
|
348
|
+
signal: t.signal
|
|
349
|
+
});
|
|
350
|
+
return clearTimeout(i), h.ok || h.status === 405;
|
|
351
|
+
} catch {
|
|
352
|
+
return clearTimeout(i), !1;
|
|
353
|
+
}
|
|
354
|
+
} catch {
|
|
355
|
+
return !1;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
supportsFeature(e) {
|
|
359
|
+
switch (e) {
|
|
360
|
+
case "pause":
|
|
361
|
+
case "resume":
|
|
362
|
+
case "wordBoundary":
|
|
363
|
+
case "voiceSelection":
|
|
364
|
+
case "rateControl":
|
|
365
|
+
return !0;
|
|
366
|
+
case "pitchControl":
|
|
367
|
+
return !1;
|
|
368
|
+
default:
|
|
369
|
+
return !1;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
getCapabilities() {
|
|
373
|
+
return {
|
|
374
|
+
supportsPause: !0,
|
|
375
|
+
supportsResume: !0,
|
|
376
|
+
supportsWordBoundary: !0,
|
|
377
|
+
supportsVoiceSelection: !0,
|
|
378
|
+
supportsRateControl: !0,
|
|
379
|
+
supportsPitchControl: !1,
|
|
380
|
+
maxTextLength: S[this.config ? w(this.config) : "pie"]
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
destroy() {
|
|
384
|
+
this.config = null, this.adapter = null, this.telemetryReporter = void 0;
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
export {
|
|
388
|
+
C as ServerTTSProvider
|
|
389
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { t as s } from "./defineProperty-CyepwRr5-eHUSgEtz.js";
|
|
2
|
+
var n = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
s(this, "providerId", "desmos"), s(this, "providerName", "Desmos"), s(this, "supportedTypes", [
|
|
5
|
+
"basic",
|
|
6
|
+
"scientific",
|
|
7
|
+
"graphing"
|
|
8
|
+
]), s(this, "version", "1.10"), s(this, "initialized", !1), s(this, "apiKey", void 0), s(this, "proxyEndpoint", void 0), s(this, "isDevelopment", !1), s(this, "onTelemetry", void 0);
|
|
9
|
+
}
|
|
10
|
+
async emitTelemetry(t, o) {
|
|
11
|
+
try {
|
|
12
|
+
await this.onTelemetry?.(t, o);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
console.warn("[DesmosProvider] telemetry callback failed:", e);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
getApiKey() {
|
|
18
|
+
return this.apiKey;
|
|
19
|
+
}
|
|
20
|
+
async loadDesmosScript() {
|
|
21
|
+
return new Promise((t, o) => {
|
|
22
|
+
const e = document.createElement("script");
|
|
23
|
+
e.src = this.apiKey ? `https://www.desmos.com/api/v1.10/calculator.js?apiKey=${this.apiKey}` : "https://www.desmos.com/api/v1.10/calculator.js", e.async = !0, e.onload = () => {
|
|
24
|
+
window.Desmos ? (console.log("[DesmosProvider] Desmos API loaded successfully"), t()) : o(/* @__PURE__ */ new Error("Desmos API loaded but window.Desmos is undefined"));
|
|
25
|
+
}, e.onerror = () => {
|
|
26
|
+
o(/* @__PURE__ */ new Error("Failed to load Desmos API from CDN"));
|
|
27
|
+
}, document.head.appendChild(e);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async initialize(t) {
|
|
31
|
+
if (!this.initialized) {
|
|
32
|
+
if (this.onTelemetry = t?.onTelemetry, typeof window > "u") throw new Error("Desmos calculators can only be initialized in the browser");
|
|
33
|
+
if (this.isDevelopment = process.env.NODE_ENV === "development" || typeof process > "u" || !process.env.NODE_ENV, t?.proxyEndpoint) {
|
|
34
|
+
this.proxyEndpoint = t.proxyEndpoint;
|
|
35
|
+
const o = Date.now();
|
|
36
|
+
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
37
|
+
toolId: "calculator",
|
|
38
|
+
backend: "desmos",
|
|
39
|
+
operation: "proxy-auth-fetch"
|
|
40
|
+
});
|
|
41
|
+
try {
|
|
42
|
+
const e = await fetch(t.proxyEndpoint);
|
|
43
|
+
if (!e.ok) throw new Error(`Proxy endpoint returned ${e.status}`);
|
|
44
|
+
this.apiKey = (await e.json()).apiKey, await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
45
|
+
toolId: "calculator",
|
|
46
|
+
backend: "desmos",
|
|
47
|
+
operation: "proxy-auth-fetch",
|
|
48
|
+
duration: Date.now() - o
|
|
49
|
+
}), console.log("[DesmosProvider] Initialized with server-side proxy (SECURE)");
|
|
50
|
+
} catch (e) {
|
|
51
|
+
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
52
|
+
toolId: "calculator",
|
|
53
|
+
backend: "desmos",
|
|
54
|
+
operation: "proxy-auth-fetch",
|
|
55
|
+
duration: Date.now() - o,
|
|
56
|
+
errorType: "CalculatorProxyAuthError",
|
|
57
|
+
message: e instanceof Error ? e.message : String(e)
|
|
58
|
+
}), /* @__PURE__ */ new Error(`[DesmosProvider] Failed to fetch API key from proxy: ${e}`);
|
|
59
|
+
}
|
|
60
|
+
} else t?.apiKey ? (this.apiKey = t.apiKey, this.isDevelopment ? console.log("[DesmosProvider] Initialized with direct API key (DEVELOPMENT MODE)") : console.error(`⚠️ [DesmosProvider] SECURITY WARNING: API key exposed in client-side code!
|
|
61
|
+
This is insecure for production. Use proxyEndpoint instead.
|
|
62
|
+
See: https://pie-players.dev/docs/calculator-desmos#security`)) : console.warn(`[DesmosProvider] No API key or proxy endpoint provided.
|
|
63
|
+
Production usage requires authentication. Obtain API key from https://www.desmos.com/api
|
|
64
|
+
Recommended: Use proxyEndpoint for production, apiKey for development only.`);
|
|
65
|
+
if (!window.Desmos) {
|
|
66
|
+
console.log("[DesmosProvider] Loading Desmos API library...");
|
|
67
|
+
const o = Date.now();
|
|
68
|
+
await this.emitTelemetry("pie-tool-library-load-start", {
|
|
69
|
+
toolId: "calculator",
|
|
70
|
+
backend: "desmos",
|
|
71
|
+
operation: "desmos-script-load"
|
|
72
|
+
});
|
|
73
|
+
try {
|
|
74
|
+
await this.loadDesmosScript(), await this.emitTelemetry("pie-tool-library-load-success", {
|
|
75
|
+
toolId: "calculator",
|
|
76
|
+
backend: "desmos",
|
|
77
|
+
operation: "desmos-script-load",
|
|
78
|
+
duration: Date.now() - o
|
|
79
|
+
});
|
|
80
|
+
} catch (e) {
|
|
81
|
+
throw await this.emitTelemetry("pie-tool-library-load-error", {
|
|
82
|
+
toolId: "calculator",
|
|
83
|
+
backend: "desmos",
|
|
84
|
+
operation: "desmos-script-load",
|
|
85
|
+
duration: Date.now() - o,
|
|
86
|
+
errorType: "ToolLibraryLoadError",
|
|
87
|
+
message: e instanceof Error ? e.message : String(e)
|
|
88
|
+
}), e;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
this.initialized = !0;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async createCalculator(t, o, e) {
|
|
95
|
+
if (this.initialized || await this.initialize(), !this.supportsType(t)) throw new Error(`Desmos does not support calculator type: ${t}`);
|
|
96
|
+
return new a(this, t, o, e, this.apiKey);
|
|
97
|
+
}
|
|
98
|
+
supportsType(t) {
|
|
99
|
+
return this.supportedTypes.includes(t);
|
|
100
|
+
}
|
|
101
|
+
destroy() {
|
|
102
|
+
this.initialized = !1, this.onTelemetry = void 0;
|
|
103
|
+
}
|
|
104
|
+
getCapabilities() {
|
|
105
|
+
return {
|
|
106
|
+
supportsHistory: !1,
|
|
107
|
+
supportsGraphing: !0,
|
|
108
|
+
supportsExpressions: !0,
|
|
109
|
+
canExport: !0,
|
|
110
|
+
maxPrecision: 15,
|
|
111
|
+
inputMethods: [
|
|
112
|
+
"keyboard",
|
|
113
|
+
"mouse",
|
|
114
|
+
"touch"
|
|
115
|
+
]
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}, a = class {
|
|
119
|
+
constructor(t, o, e, i, r) {
|
|
120
|
+
if (s(this, "provider", void 0), s(this, "type", void 0), s(this, "Desmos", void 0), s(this, "calculator", void 0), s(this, "container", void 0), this.provider = t, this.type = o, this.container = e, this.Desmos = window.Desmos, !this.Desmos) throw new Error("Desmos API not available");
|
|
121
|
+
this._initializeCalculator(i, r);
|
|
122
|
+
}
|
|
123
|
+
_initializeCalculator(t, o) {
|
|
124
|
+
const e = {
|
|
125
|
+
...t?.desmos || {},
|
|
126
|
+
apiKey: o || t?.desmos?.apiKey
|
|
127
|
+
};
|
|
128
|
+
switch (t?.restrictedMode && Object.assign(e, {
|
|
129
|
+
expressionsTopbar: !1,
|
|
130
|
+
settingsMenu: !1,
|
|
131
|
+
zoomButtons: !1,
|
|
132
|
+
expressions: !1,
|
|
133
|
+
links: !1
|
|
134
|
+
}), this.type) {
|
|
135
|
+
case "graphing":
|
|
136
|
+
this.calculator = this.Desmos.GraphingCalculator(this.container, e);
|
|
137
|
+
break;
|
|
138
|
+
case "scientific":
|
|
139
|
+
this.calculator = this.Desmos.ScientificCalculator(this.container, e);
|
|
140
|
+
break;
|
|
141
|
+
case "basic":
|
|
142
|
+
this.calculator = this.Desmos.FourFunctionCalculator(this.container, e);
|
|
143
|
+
break;
|
|
144
|
+
default:
|
|
145
|
+
throw new Error(`Unsupported calculator type: ${this.type}`);
|
|
146
|
+
}
|
|
147
|
+
console.log(`[DesmosCalculator] Created ${this.type} calculator`);
|
|
148
|
+
}
|
|
149
|
+
getValue() {
|
|
150
|
+
if (this.type === "graphing" && this.calculator.getState) {
|
|
151
|
+
const t = this.calculator.getState();
|
|
152
|
+
return JSON.stringify(t);
|
|
153
|
+
}
|
|
154
|
+
return "";
|
|
155
|
+
}
|
|
156
|
+
setValue(t) {
|
|
157
|
+
if (this.type === "graphing" && this.calculator.setState) try {
|
|
158
|
+
const o = JSON.parse(t);
|
|
159
|
+
this.calculator.setState(o);
|
|
160
|
+
} catch (o) {
|
|
161
|
+
console.error("[DesmosCalculator] Failed to set state:", o);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
clear() {
|
|
165
|
+
this.calculator.setBlank && this.calculator.setBlank();
|
|
166
|
+
}
|
|
167
|
+
async evaluate(t) {
|
|
168
|
+
return this.type === "graphing" ? new Promise((o) => {
|
|
169
|
+
const e = `eval_${Date.now()}`;
|
|
170
|
+
this.calculator.setExpression({
|
|
171
|
+
id: e,
|
|
172
|
+
latex: t
|
|
173
|
+
}), setTimeout(() => {
|
|
174
|
+
const i = this.calculator.HelperExpression({ latex: t }).numericValue || t;
|
|
175
|
+
this.calculator.removeExpression({ id: e }), o(String(i));
|
|
176
|
+
}, 100);
|
|
177
|
+
}) : t;
|
|
178
|
+
}
|
|
179
|
+
resize() {
|
|
180
|
+
this.calculator.resize && this.calculator.resize();
|
|
181
|
+
}
|
|
182
|
+
exportState() {
|
|
183
|
+
let t = {};
|
|
184
|
+
return this.type === "graphing" && this.calculator.getState && (t = this.calculator.getState()), {
|
|
185
|
+
type: this.type,
|
|
186
|
+
provider: "desmos",
|
|
187
|
+
value: this.getValue(),
|
|
188
|
+
providerState: t
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
importState(t) {
|
|
192
|
+
if (t.provider !== "desmos") throw new Error(`Cannot import state from provider: ${t.provider}`);
|
|
193
|
+
t.providerState && this.calculator.setState ? this.calculator.setState(t.providerState) : t.value && this.setValue(t.value);
|
|
194
|
+
}
|
|
195
|
+
destroy() {
|
|
196
|
+
this.calculator && this.calculator.destroy && this.calculator.destroy(), this.container.replaceChildren(), console.log("[DesmosCalculator] destroyed");
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
export {
|
|
200
|
+
n as DesmosCalculatorProvider
|
|
201
|
+
};
|