@dudgy/podcast-widget 0.1.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/index.js ADDED
@@ -0,0 +1,1088 @@
1
+ // src/core/event-emitter.ts
2
+ var EventEmitter = class {
3
+ listeners = /* @__PURE__ */ new Map();
4
+ on(event, handler) {
5
+ let set = this.listeners.get(event);
6
+ if (!set) {
7
+ set = /* @__PURE__ */ new Set();
8
+ this.listeners.set(event, set);
9
+ }
10
+ set.add(handler);
11
+ }
12
+ off(event, handler) {
13
+ this.listeners.get(event)?.delete(handler);
14
+ }
15
+ emit(event, data) {
16
+ this.listeners.get(event)?.forEach((fn) => fn(data));
17
+ }
18
+ removeAllListeners() {
19
+ this.listeners.clear();
20
+ }
21
+ };
22
+
23
+ // src/core/audio-engine.ts
24
+ var AudioEngine = class extends EventEmitter {
25
+ audio;
26
+ _isPlaying = false;
27
+ skipSeconds;
28
+ // Keep references to bound listeners so we can remove them in destroy()
29
+ onTimeUpdate;
30
+ onEnded;
31
+ onLoadedMetadata;
32
+ onError;
33
+ constructor(skipSeconds = 30) {
34
+ super();
35
+ this.skipSeconds = skipSeconds;
36
+ this.audio = new Audio();
37
+ this.onTimeUpdate = () => {
38
+ const pct = this.audio.duration ? this.audio.currentTime / this.audio.duration * 100 : 0;
39
+ this.emit("time-update", {
40
+ currentTime: this.audio.currentTime,
41
+ duration: this.audio.duration,
42
+ percentage: isNaN(pct) ? 0 : pct
43
+ });
44
+ };
45
+ this.onEnded = () => {
46
+ this._isPlaying = false;
47
+ this.emit("ended", void 0);
48
+ };
49
+ this.onLoadedMetadata = () => {
50
+ this.audio.playbackRate = this._playbackRate;
51
+ this.emit("loaded-metadata", { duration: this.audio.duration });
52
+ };
53
+ this.onError = () => {
54
+ const err = this.audio.error;
55
+ this.emit("error", {
56
+ error: new Error(err?.message ?? "Unknown audio error"),
57
+ context: `MediaError code ${err?.code}`
58
+ });
59
+ };
60
+ this.audio.addEventListener("timeupdate", this.onTimeUpdate);
61
+ this.audio.addEventListener("ended", this.onEnded);
62
+ this.audio.addEventListener("loadedmetadata", this.onLoadedMetadata);
63
+ this.audio.addEventListener("error", this.onError);
64
+ }
65
+ // ─── Playback ──────────────────────────────────────────────────
66
+ load(url, startPosition) {
67
+ this.audio.src = url;
68
+ this.audio.load();
69
+ if (startPosition != null && startPosition > 0) {
70
+ this.audio.currentTime = startPosition;
71
+ }
72
+ }
73
+ async play() {
74
+ try {
75
+ await this.audio.play();
76
+ this._isPlaying = true;
77
+ this.emit("play", {});
78
+ } catch (err) {
79
+ this._isPlaying = false;
80
+ this.emit("error", {
81
+ error: err instanceof Error ? err : new Error(String(err)),
82
+ context: "play() rejected"
83
+ });
84
+ throw err;
85
+ }
86
+ }
87
+ pause() {
88
+ this.audio.pause();
89
+ this._isPlaying = false;
90
+ this.emit("pause", { currentTime: this.audio.currentTime });
91
+ }
92
+ stop() {
93
+ this.audio.pause();
94
+ this.audio.currentTime = 0;
95
+ this._isPlaying = false;
96
+ this.emit("stop", void 0);
97
+ }
98
+ skipForward(seconds) {
99
+ if (!this.audio.src) return;
100
+ const s = seconds ?? this.skipSeconds;
101
+ this.audio.currentTime = Math.min(this.audio.currentTime + s, this.audio.duration || Infinity);
102
+ }
103
+ skipBackward(seconds) {
104
+ if (!this.audio.src) return;
105
+ const s = seconds ?? this.skipSeconds;
106
+ this.audio.currentTime = Math.max(this.audio.currentTime - s, 0);
107
+ }
108
+ seek(seconds) {
109
+ if (!this.audio.src) return;
110
+ this.audio.currentTime = Math.max(0, Math.min(seconds, this.audio.duration || 0));
111
+ }
112
+ seekToPercentage(pct) {
113
+ if (!this.audio.src || !this.audio.duration) return;
114
+ this.audio.currentTime = pct / 100 * this.audio.duration;
115
+ }
116
+ // ─── State ─────────────────────────────────────────────────────
117
+ get currentTime() {
118
+ return this.audio.currentTime;
119
+ }
120
+ get duration() {
121
+ return this.audio.duration || 0;
122
+ }
123
+ get isPlaying() {
124
+ return this._isPlaying;
125
+ }
126
+ get volume() {
127
+ return this.audio.volume;
128
+ }
129
+ set volume(v) {
130
+ this.audio.volume = Math.max(0, Math.min(1, v));
131
+ }
132
+ _playbackRate = 1;
133
+ get playbackRate() {
134
+ return this._playbackRate;
135
+ }
136
+ set playbackRate(r) {
137
+ this._playbackRate = r;
138
+ this.audio.playbackRate = r;
139
+ }
140
+ get hasSrc() {
141
+ return !!this.audio.src && this.audio.src !== window.location.href;
142
+ }
143
+ // ─── Cleanup ───────────────────────────────────────────────────
144
+ destroy() {
145
+ this.audio.removeEventListener("timeupdate", this.onTimeUpdate);
146
+ this.audio.removeEventListener("ended", this.onEnded);
147
+ this.audio.removeEventListener("loadedmetadata", this.onLoadedMetadata);
148
+ this.audio.removeEventListener("error", this.onError);
149
+ this.audio.pause();
150
+ this.audio.src = "";
151
+ this.removeAllListeners();
152
+ }
153
+ };
154
+
155
+ // src/core/playback-storage.ts
156
+ var PlaybackStorage = class {
157
+ storageKey;
158
+ maxItems;
159
+ constructor(config) {
160
+ this.storageKey = `${config.storagePrefix}PlaybackPositions`;
161
+ this.maxItems = config.maxStoredPositions;
162
+ }
163
+ getPositions() {
164
+ try {
165
+ const data = localStorage.getItem(this.storageKey);
166
+ return data ? JSON.parse(data) : {};
167
+ } catch {
168
+ return {};
169
+ }
170
+ }
171
+ savePosition(episodeId, position, duration) {
172
+ try {
173
+ const positions = this.getPositions();
174
+ const shouldSave = duration ? position > 10 && position < duration - 30 : position > 10;
175
+ if (!shouldSave) return;
176
+ positions[episodeId] = position;
177
+ const keys = Object.keys(positions);
178
+ if (keys.length > this.maxItems) {
179
+ for (let i = 0; i < keys.length - this.maxItems; i++) {
180
+ delete positions[keys[i]];
181
+ }
182
+ }
183
+ localStorage.setItem(this.storageKey, JSON.stringify(positions));
184
+ } catch {
185
+ }
186
+ }
187
+ getPosition(episodeId) {
188
+ const positions = this.getPositions();
189
+ return episodeId in positions ? positions[episodeId] : null;
190
+ }
191
+ removePosition(episodeId) {
192
+ try {
193
+ const positions = this.getPositions();
194
+ if (episodeId in positions) {
195
+ delete positions[episodeId];
196
+ localStorage.setItem(this.storageKey, JSON.stringify(positions));
197
+ }
198
+ } catch {
199
+ }
200
+ }
201
+ cleanupPositions(currentEpisodeIds) {
202
+ try {
203
+ const positions = this.getPositions();
204
+ const currentSet = new Set(currentEpisodeIds);
205
+ let changed = false;
206
+ for (const id of Object.keys(positions)) {
207
+ if (!currentSet.has(id)) {
208
+ delete positions[id];
209
+ changed = true;
210
+ }
211
+ }
212
+ if (changed) {
213
+ localStorage.setItem(this.storageKey, JSON.stringify(positions));
214
+ }
215
+ } catch {
216
+ }
217
+ }
218
+ };
219
+
220
+ // src/core/player-state.ts
221
+ var PlayerStateStorage = class {
222
+ stateKey;
223
+ speedKey;
224
+ constructor(config) {
225
+ this.stateKey = `${config.storagePrefix}PlayerState`;
226
+ this.speedKey = `${config.storagePrefix}PlayerSpeed`;
227
+ }
228
+ saveState(state) {
229
+ try {
230
+ localStorage.setItem(this.stateKey, JSON.stringify(state));
231
+ } catch {
232
+ }
233
+ }
234
+ loadState() {
235
+ try {
236
+ const raw = localStorage.getItem(this.stateKey);
237
+ if (!raw) return null;
238
+ return JSON.parse(raw);
239
+ } catch {
240
+ return null;
241
+ }
242
+ }
243
+ saveSpeed(speed) {
244
+ try {
245
+ localStorage.setItem(this.speedKey, speed.toString());
246
+ } catch {
247
+ }
248
+ }
249
+ loadSpeed() {
250
+ try {
251
+ const raw = localStorage.getItem(this.speedKey);
252
+ if (!raw) return null;
253
+ const speed = parseFloat(raw);
254
+ return speed >= 0.5 && speed <= 3 ? speed : null;
255
+ } catch {
256
+ return null;
257
+ }
258
+ }
259
+ };
260
+
261
+ // src/core/episode-provider.ts
262
+ var FetchEpisodeProvider = class {
263
+ url;
264
+ cacheKey;
265
+ cacheTTL;
266
+ constructor(url, config) {
267
+ this.url = url;
268
+ this.cacheKey = `${config.storagePrefix}EpisodesCache`;
269
+ this.cacheTTL = config.episodeCacheTTL;
270
+ }
271
+ async getEpisodes() {
272
+ const cached = this.readCache();
273
+ if (cached) return cached;
274
+ let lastError = null;
275
+ for (let attempt = 0; attempt < 2; attempt++) {
276
+ try {
277
+ const res = await fetch(this.url);
278
+ if (!res.ok) throw new Error(`API error: ${res.status}`);
279
+ const data = await res.json();
280
+ if (data.episodes && data.episodes.length > 0) {
281
+ this.writeCache(data.episodes);
282
+ return data.episodes;
283
+ }
284
+ return [];
285
+ } catch (err) {
286
+ lastError = err instanceof Error ? err : new Error(String(err));
287
+ if (attempt === 0) continue;
288
+ }
289
+ }
290
+ const stale = this.readCache(true);
291
+ if (stale) return stale;
292
+ throw lastError ?? new Error("Failed to fetch episodes");
293
+ }
294
+ readCache(ignoreExpiry = false) {
295
+ try {
296
+ const raw = localStorage.getItem(this.cacheKey);
297
+ if (!raw) return null;
298
+ const { episodes, timestamp } = JSON.parse(raw);
299
+ if (!ignoreExpiry && Date.now() - timestamp >= this.cacheTTL) return null;
300
+ if (!episodes || episodes.length === 0) return null;
301
+ return episodes;
302
+ } catch {
303
+ return null;
304
+ }
305
+ }
306
+ writeCache(episodes) {
307
+ try {
308
+ localStorage.setItem(
309
+ this.cacheKey,
310
+ JSON.stringify({ episodes, timestamp: Date.now() })
311
+ );
312
+ } catch {
313
+ }
314
+ }
315
+ };
316
+
317
+ // src/core/types.ts
318
+ var DEFAULT_CONFIG = {
319
+ storagePrefix: "podcast",
320
+ maxStoredPositions: 100,
321
+ positionSaveInterval: 5e3,
322
+ skipSeconds: 30,
323
+ episodeCacheTTL: 60 * 60 * 1e3
324
+ };
325
+ function resolveConfig(config) {
326
+ return { ...DEFAULT_CONFIG, ...config };
327
+ }
328
+
329
+ // src/ui/utils.ts
330
+ function formatTime(seconds) {
331
+ if (isNaN(seconds) || seconds < 0) return "00:00";
332
+ const h = Math.floor(seconds / 3600);
333
+ const m = Math.floor(seconds % 3600 / 60);
334
+ const s = Math.floor(seconds % 60);
335
+ const mm = m.toString().padStart(2, "0");
336
+ const ss = s.toString().padStart(2, "0");
337
+ return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`;
338
+ }
339
+ function formatDuration(seconds) {
340
+ if (!seconds) return "Unknown length";
341
+ return `${Math.floor(seconds / 60)} min`;
342
+ }
343
+ function formatDate(pubDateTime, pubDate) {
344
+ if (pubDateTime) {
345
+ try {
346
+ const d = new Date(pubDateTime);
347
+ return {
348
+ short: d.toLocaleDateString("en-CA"),
349
+ full: d.toLocaleString("en-US", {
350
+ year: "numeric",
351
+ month: "long",
352
+ day: "numeric",
353
+ hour: "numeric",
354
+ minute: "2-digit",
355
+ hour12: true
356
+ })
357
+ };
358
+ } catch {
359
+ }
360
+ }
361
+ return { short: pubDate || "Unknown date", full: "" };
362
+ }
363
+ function escapeHtml(str) {
364
+ const div = document.createElement("div");
365
+ div.textContent = str;
366
+ return div.innerHTML;
367
+ }
368
+ function getEpisodeImage(episode) {
369
+ return episode.image || episode.feedImage || episode.artwork || "";
370
+ }
371
+
372
+ // src/ui/html-templates.ts
373
+ var ICONS = {
374
+ play: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',
375
+ pause: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>',
376
+ skipBack: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M11.99 5V1l-5 5 5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6h-2c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8zm-1.1 11h-.85v-3.26l-1.01.31v-.69l1.77-.63h.09V16zm4.28-1.76c0 .32-.03.6-.1.82s-.17.42-.29.57-.28.26-.45.33-.37.1-.59.10-.41-.03-.59-.1-.33-.18-.46-.33-.23-.34-.3-.57-.11-.5-.11-.82v-.74c0-.32.03-.6.1-.82s.17-.42.29-.57.28-.26.45-.33.37-.1.59-.10.41.03.59.1.33.18.46.33.23.34.3.57.11.5.11.82v.74zm-.85-.86c0-.19-.01-.35-.04-.48s-.07-.23-.12-.31-.11-.14-.19-.17-.16-.05-.25-.05-.18.02-.25.05-.14.09-.19.17-.09.18-.12.31-.04.29-.04.48v.97c0 .19.01.35.04.48s.07.24.12.32.11.14.19.17.16.05.25.05.18-.02.25-.05.14-.09.19-.17.09-.19.11-.32.04-.29.04-.48v-.97z"/></svg>',
377
+ skipForward: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M18 13c0 3.31-2.69 6-6 6s-6-2.69-6-6 2.69-6 6-6v4l5-5-5-5v4c-4.42 0-8 3.58-8 8s3.58 8 8 8 8-3.58 8-8h-2zm-7.46 2.22v-.67c0-.31.02-.58.07-.8.05-.22.12-.42.22-.58.1-.16.22-.28.37-.37.14-.08.3-.12.5-.12.18 0 .35.04.49.12.14.08.27.2.37.37.1.16.17.36.22.58s.08.49.08.8v.67c0 .31-.03.58-.08.8-.05.22-.12.42-.22.58-.1.16-.23.28-.37.37-.14.08-.3.12-.49.12s-.36-.04-.5-.12c-.15-.08-.27-.2-.37-.37-.1-.16-.17-.36-.22-.58s-.07-.49-.07-.8zm.85.67c0 .25.04.45.11.59.07.14.2.21.38.21s.31-.07.38-.21c.07-.14.11-.34.11-.59v-.97c0-.25-.04-.45-.11-.59s-.2-.21-.38-.21-.31.07-.38.21c-.07.14-.11.34-.11.59v.97zm2.68-.87c0-.11.01-.21.04-.29.03-.08.06-.15.11-.2.05-.05.11-.09.18-.11s.14-.04.23-.04c.12 0 .22.02.3.07s.16.12.21.2.1.18.13.3c.03.11.05.24.05.38 0 .14-.02.27-.05.38-.03.11-.08.21-.13.3-.05.08-.12.15-.21.2s-.18.07-.3.07c-.09 0-.17-.01-.23-.04s-.13-.06-.18-.11c-.05-.05-.08-.12-.11-.2-.03-.08-.04-.18-.04-.29h-.01v-.62z"/></svg>',
378
+ expand: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/></svg>',
379
+ close: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>',
380
+ volume: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z"/></svg>',
381
+ info: '<svg viewBox="0 0 24 24" fill="currentColor" width="16" height="16"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>',
382
+ playlist: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z"/></svg>'
383
+ };
384
+ var SPEED_OPTIONS = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3];
385
+ function renderPlaylistItem(episode, index, opts) {
386
+ const imageUrl = getEpisodeImage(episode);
387
+ const { short: dateShort, full: dateFull } = formatDate(episode.pubDateTime, episode.pubDate);
388
+ const duration = formatDuration(episode.duration);
389
+ const hasSaved = opts.savedPosition !== null;
390
+ let savedHtml = "";
391
+ if (hasSaved) {
392
+ const m = Math.floor(opts.savedPosition / 60);
393
+ const s = Math.floor(opts.savedPosition % 60);
394
+ savedHtml = `<div class="pw-saved-position">Saved: ${m}:${s.toString().padStart(2, "0")}</div>`;
395
+ }
396
+ const feedLinkHtml = opts.feedPageUrl ? `<a href="${opts.feedPageUrl(episode.feedId)}" class="pw-view-feed" title="View show info" data-feed-link>${ICONS.info}</a>` : "";
397
+ return `
398
+ <div class="pw-playlist-item ${opts.isPlaying ? "pw-playing" : ""} ${hasSaved ? "pw-has-saved" : ""}" data-index="${index}">
399
+ ${imageUrl ? `<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(episode.title)}" class="pw-episode-image">` : ""}
400
+ <div class="pw-episode-info">
401
+ <div class="pw-episode-show">${escapeHtml(episode.feedName || "Unknown Show")}</div>
402
+ <div class="pw-episode-title">${escapeHtml(episode.title)}</div>
403
+ <div class="pw-episode-date"${dateFull ? ` title="${escapeHtml(dateFull)}"` : ""}>${escapeHtml(dateShort)}</div>
404
+ ${savedHtml}
405
+ </div>
406
+ <div class="pw-episode-actions">
407
+ <div class="pw-episode-duration">${escapeHtml(duration)}</div>
408
+ ${feedLinkHtml}
409
+ </div>
410
+ </div>
411
+ `;
412
+ }
413
+ function renderPlaylist(episodes, currentIndex, getPosition, feedPageUrl) {
414
+ if (episodes.length === 0) {
415
+ return '<div class="pw-playlist-item pw-empty">No episodes available</div>';
416
+ }
417
+ return episodes.map(
418
+ (ep, i) => renderPlaylistItem(ep, i, {
419
+ isPlaying: i === currentIndex,
420
+ savedPosition: getPosition(ep.id),
421
+ feedPageUrl
422
+ })
423
+ ).join("");
424
+ }
425
+
426
+ // src/ui/player-controller.ts
427
+ var PlayerController = class extends EventEmitter {
428
+ engine;
429
+ storage;
430
+ stateStorage;
431
+ config;
432
+ provider;
433
+ episodes = [];
434
+ currentIndex = -1;
435
+ saveInterval = null;
436
+ cleanupFns = [];
437
+ constructor(engine, provider, config) {
438
+ super();
439
+ this.config = resolveConfig(config);
440
+ this.engine = engine;
441
+ this.provider = provider;
442
+ this.storage = new PlaybackStorage(this.config);
443
+ this.stateStorage = new PlayerStateStorage(this.config);
444
+ const savedSpeed = this.stateStorage.loadSpeed();
445
+ if (savedSpeed !== null) {
446
+ this.engine.playbackRate = savedSpeed;
447
+ }
448
+ const savedState = this.stateStorage.loadState();
449
+ if (savedState?.volume != null) {
450
+ this.engine.volume = savedState.volume;
451
+ }
452
+ this.engine.on("ended", () => {
453
+ if (this.currentIndex >= 0) {
454
+ this.storage.removePosition(this.episodes[this.currentIndex].id);
455
+ }
456
+ this.stopPositionSaving();
457
+ });
458
+ this.engine.on("pause", () => {
459
+ this.saveCurrentPosition();
460
+ });
461
+ const onBeforeUnload = () => this.saveCurrentPosition();
462
+ window.addEventListener("beforeunload", onBeforeUnload);
463
+ this.cleanupFns.push(() => window.removeEventListener("beforeunload", onBeforeUnload));
464
+ }
465
+ // ─── Episode management ────────────────────────────────────────
466
+ async loadEpisodes() {
467
+ this.episodes = await this.provider.getEpisodes();
468
+ this.storage.cleanupPositions(this.episodes.map((ep) => ep.id));
469
+ this.emit("episodes-loaded", { episodes: this.episodes });
470
+ const savedState = this.stateStorage.loadState();
471
+ if (savedState && savedState.currentEpisodeIndex >= 0 && savedState.currentEpisodeIndex < this.episodes.length) {
472
+ this.loadEpisode(savedState.currentEpisodeIndex, false);
473
+ }
474
+ return this.episodes;
475
+ }
476
+ getEpisodes() {
477
+ return this.episodes;
478
+ }
479
+ getCurrentEpisode() {
480
+ return this.currentIndex >= 0 ? this.episodes[this.currentIndex] : null;
481
+ }
482
+ getCurrentIndex() {
483
+ return this.currentIndex;
484
+ }
485
+ loadEpisode(index, autoPlay = false) {
486
+ if (index < 0 || index >= this.episodes.length) return;
487
+ const episode = this.episodes[index];
488
+ this.currentIndex = index;
489
+ const savedPosition = this.storage.getPosition(episode.id);
490
+ this.engine.load(episode.audioUrl, savedPosition ?? void 0);
491
+ this.stateStorage.saveState({
492
+ currentEpisodeIndex: this.currentIndex,
493
+ volume: this.engine.volume
494
+ });
495
+ this.emit("episode-change", { episode, index });
496
+ this.emit("episode-display", {
497
+ imageUrl: getEpisodeImage(episode),
498
+ title: episode.title,
499
+ show: episode.feedName
500
+ });
501
+ if (autoPlay) {
502
+ this.play();
503
+ }
504
+ }
505
+ playEpisode(index) {
506
+ this.loadEpisode(index, true);
507
+ }
508
+ async play() {
509
+ if (this.episodes.length === 0) return;
510
+ if (this.currentIndex === -1) {
511
+ this.playEpisode(0);
512
+ return;
513
+ }
514
+ await this.engine.play();
515
+ this.startPositionSaving();
516
+ }
517
+ pause() {
518
+ this.engine.pause();
519
+ this.saveCurrentPosition();
520
+ }
521
+ setSpeed(speed) {
522
+ this.engine.playbackRate = speed;
523
+ this.stateStorage.saveSpeed(speed);
524
+ }
525
+ setVolume(v) {
526
+ this.engine.volume = v;
527
+ this.stateStorage.saveState({
528
+ currentEpisodeIndex: this.currentIndex,
529
+ volume: v
530
+ });
531
+ }
532
+ getPlaylistHtml(feedPageUrl) {
533
+ return renderPlaylist(
534
+ this.episodes,
535
+ this.currentIndex,
536
+ (id) => this.storage.getPosition(id),
537
+ feedPageUrl
538
+ );
539
+ }
540
+ // ─── Position saving ───────────────────────────────────────────
541
+ startPositionSaving() {
542
+ this.stopPositionSaving();
543
+ this.saveInterval = window.setInterval(
544
+ () => this.saveCurrentPosition(),
545
+ this.config.positionSaveInterval
546
+ );
547
+ }
548
+ stopPositionSaving() {
549
+ if (this.saveInterval !== null) {
550
+ clearInterval(this.saveInterval);
551
+ this.saveInterval = null;
552
+ }
553
+ }
554
+ saveCurrentPosition() {
555
+ if (this.currentIndex < 0 || !this.engine.hasSrc) return;
556
+ const episode = this.episodes[this.currentIndex];
557
+ if (this.engine.currentTime > 10) {
558
+ this.storage.savePosition(episode.id, this.engine.currentTime, episode.duration);
559
+ }
560
+ }
561
+ // ─── Cleanup ───────────────────────────────────────────────────
562
+ destroy() {
563
+ this.stopPositionSaving();
564
+ this.saveCurrentPosition();
565
+ this.cleanupFns.forEach((fn) => fn());
566
+ this.cleanupFns = [];
567
+ this.removeAllListeners();
568
+ }
569
+ };
570
+
571
+ // src/ui/mini-player.ts
572
+ var MiniPlayer = class extends EventEmitter {
573
+ container;
574
+ controller;
575
+ controls;
576
+ feedPageUrl;
577
+ cleanupFns = [];
578
+ // Element references (created during render)
579
+ artworkEl = null;
580
+ titleEl = null;
581
+ showEl = null;
582
+ playBtn = null;
583
+ pauseBtn = null;
584
+ progressBar = null;
585
+ progressContainer = null;
586
+ playlistContainer = null;
587
+ playlistOpen = false;
588
+ constructor(opts) {
589
+ super();
590
+ this.container = opts.container;
591
+ this.controller = opts.controller;
592
+ this.controls = {
593
+ playPause: true,
594
+ progress: true,
595
+ ...opts.controls
596
+ };
597
+ this.feedPageUrl = opts.feedPageUrl;
598
+ this.render();
599
+ this.bindEvents();
600
+ }
601
+ render() {
602
+ const c = this.controls;
603
+ let controlsHtml = "";
604
+ if (c.skipBackward) {
605
+ controlsHtml += `<button class="pw-btn pw-btn--mini pw-btn--skip-back" aria-label="Back ${this.controller.config.skipSeconds} seconds">${ICONS.skipBack}</button>`;
606
+ }
607
+ if (c.playPause) {
608
+ controlsHtml += `
609
+ <button class="pw-btn pw-btn--mini pw-play-btn" aria-label="Play">${ICONS.play}</button>
610
+ <button class="pw-btn pw-btn--mini pw-pause-btn" aria-label="Pause" style="display:none">${ICONS.pause}</button>
611
+ `;
612
+ }
613
+ if (c.skipForward) {
614
+ controlsHtml += `<button class="pw-btn pw-btn--mini pw-btn--skip-fwd" aria-label="Forward ${this.controller.config.skipSeconds} seconds">${ICONS.skipForward}</button>`;
615
+ }
616
+ if (c.volume) {
617
+ controlsHtml += `
618
+ <div class="pw-volume pw-volume--mini">
619
+ ${ICONS.volume}
620
+ <input type="range" min="0" max="100" value="${Math.round(this.controller.engine.volume * 100)}" class="pw-volume-slider" aria-label="Volume">
621
+ </div>
622
+ `;
623
+ }
624
+ if (c.speed) {
625
+ const currentSpeed = this.controller.engine.playbackRate;
626
+ const options = SPEED_OPTIONS.map(
627
+ (s) => `<option value="${s}"${s === currentSpeed ? " selected" : ""}>${s}\xD7</option>`
628
+ ).join("");
629
+ controlsHtml += `<select class="pw-speed-select" aria-label="Playback speed">${options}</select>`;
630
+ }
631
+ if (c.playlist) {
632
+ controlsHtml += `<button class="pw-btn pw-btn--mini pw-btn--playlist" aria-label="Toggle playlist">${ICONS.playlist}</button>`;
633
+ }
634
+ if (c.expand) {
635
+ controlsHtml += `<button class="pw-btn pw-btn--expand" aria-label="Expand player">${ICONS.expand}</button>`;
636
+ }
637
+ const progressHtml = c.progress ? `<div class="pw-mini-progress pw-progress-container" role="slider" aria-label="Seek" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"><div class="pw-mini-progress-bar"></div></div>` : "";
638
+ this.container.innerHTML = `
639
+ <div class="pw-mini">
640
+ <img class="pw-mini-artwork" src="" alt="Podcast artwork" style="display:none">
641
+ <div class="pw-mini-info">
642
+ <div class="pw-mini-title">No episode playing</div>
643
+ <div class="pw-mini-show"></div>
644
+ </div>
645
+ <div class="pw-mini-controls">${controlsHtml}</div>
646
+ ${progressHtml}
647
+ </div>
648
+ ${c.playlist ? '<div class="pw-mini-playlist" style="display:none"></div>' : ""}
649
+ `;
650
+ this.artworkEl = this.container.querySelector(".pw-mini-artwork");
651
+ this.titleEl = this.container.querySelector(".pw-mini-title");
652
+ this.showEl = this.container.querySelector(".pw-mini-show");
653
+ this.playBtn = this.container.querySelector(".pw-play-btn");
654
+ this.pauseBtn = this.container.querySelector(".pw-pause-btn");
655
+ this.progressBar = this.container.querySelector(".pw-mini-progress-bar");
656
+ this.progressContainer = this.container.querySelector(".pw-progress-container");
657
+ this.playlistContainer = this.container.querySelector(".pw-mini-playlist");
658
+ }
659
+ bindEvents() {
660
+ const { engine } = this.controller;
661
+ this.addClick(".pw-play-btn", () => this.controller.play());
662
+ this.addClick(".pw-pause-btn", () => this.controller.pause());
663
+ this.addClick(".pw-btn--skip-back", () => engine.skipBackward());
664
+ this.addClick(".pw-btn--skip-fwd", () => engine.skipForward());
665
+ this.addInput(".pw-volume-slider", (val) => this.controller.setVolume(parseInt(val) / 100));
666
+ this.addChange(".pw-speed-select", (val) => this.controller.setSpeed(parseFloat(val)));
667
+ this.addClick(".pw-btn--expand", () => this.emit("expand", void 0));
668
+ this.addClick(".pw-btn--playlist", () => this.togglePlaylist());
669
+ if (this.progressContainer) {
670
+ const handler = (e) => {
671
+ const rect = this.progressContainer.getBoundingClientRect();
672
+ const pct = (e.clientX - rect.left) / rect.width * 100;
673
+ engine.seekToPercentage(Math.max(0, Math.min(100, pct)));
674
+ };
675
+ this.progressContainer.addEventListener("click", handler);
676
+ this.cleanupFns.push(() => this.progressContainer?.removeEventListener("click", handler));
677
+ }
678
+ const onTimeUpdate = (d) => {
679
+ if (this.progressBar) {
680
+ this.progressBar.style.width = `${d.percentage}%`;
681
+ }
682
+ if (this.progressContainer) {
683
+ this.progressContainer.setAttribute("aria-valuenow", Math.round(d.percentage).toString());
684
+ }
685
+ };
686
+ engine.on("time-update", onTimeUpdate);
687
+ this.cleanupFns.push(() => engine.off("time-update", onTimeUpdate));
688
+ const onPlay = () => this.updatePlayPauseState(true);
689
+ const onPause = () => this.updatePlayPauseState(false);
690
+ const onStop = () => this.updatePlayPauseState(false);
691
+ engine.on("play", onPlay);
692
+ engine.on("pause", onPause);
693
+ engine.on("stop", onStop);
694
+ engine.on("ended", onStop);
695
+ this.cleanupFns.push(() => {
696
+ engine.off("play", onPlay);
697
+ engine.off("pause", onPause);
698
+ engine.off("stop", onStop);
699
+ engine.off("ended", onStop);
700
+ });
701
+ const onEpisodeChange = (d) => {
702
+ this.updateDisplay(d.episode);
703
+ this.updatePlaylistHighlight(d.index);
704
+ };
705
+ this.controller.on("episode-change", onEpisodeChange);
706
+ this.cleanupFns.push(() => this.controller.off("episode-change", onEpisodeChange));
707
+ const onEpisodesLoaded = () => {
708
+ if (this.playlistContainer) {
709
+ this.playlistContainer.innerHTML = this.controller.getPlaylistHtml(this.feedPageUrl);
710
+ this.bindPlaylistClicks();
711
+ }
712
+ };
713
+ this.controller.on("episodes-loaded", onEpisodesLoaded);
714
+ this.cleanupFns.push(() => this.controller.off("episodes-loaded", onEpisodesLoaded));
715
+ }
716
+ updateDisplay(episode) {
717
+ const imageUrl = getEpisodeImage(episode);
718
+ if (this.titleEl) this.titleEl.textContent = episode.title;
719
+ if (this.showEl) this.showEl.textContent = episode.feedName;
720
+ if (this.artworkEl) {
721
+ if (imageUrl) {
722
+ this.artworkEl.src = imageUrl;
723
+ this.artworkEl.style.display = "block";
724
+ } else {
725
+ this.artworkEl.style.display = "none";
726
+ }
727
+ }
728
+ }
729
+ updatePlayPauseState(playing) {
730
+ if (this.playBtn) this.playBtn.style.display = playing ? "none" : "flex";
731
+ if (this.pauseBtn) this.pauseBtn.style.display = playing ? "flex" : "none";
732
+ }
733
+ togglePlaylist() {
734
+ if (!this.playlistContainer) return;
735
+ this.playlistOpen = !this.playlistOpen;
736
+ this.playlistContainer.style.display = this.playlistOpen ? "block" : "none";
737
+ if (this.playlistOpen) {
738
+ this.playlistContainer.innerHTML = this.controller.getPlaylistHtml(this.feedPageUrl);
739
+ this.bindPlaylistClicks();
740
+ }
741
+ }
742
+ bindPlaylistClicks() {
743
+ if (!this.playlistContainer) return;
744
+ this.playlistContainer.querySelectorAll(".pw-playlist-item").forEach((item) => {
745
+ item.addEventListener("click", (e) => {
746
+ if (e.target.closest("[data-feed-link]")) return;
747
+ const index = parseInt(item.dataset.index || "0");
748
+ this.controller.playEpisode(index);
749
+ });
750
+ });
751
+ }
752
+ updatePlaylistHighlight(index) {
753
+ if (!this.playlistContainer) return;
754
+ this.playlistContainer.querySelectorAll(".pw-playlist-item").forEach((item, i) => {
755
+ item.classList.toggle("pw-playing", i === index);
756
+ });
757
+ }
758
+ // ─── Helpers ───────────────────────────────────────────────────
759
+ addClick(selector, handler) {
760
+ const el = this.container.querySelector(selector);
761
+ if (!el) return;
762
+ el.addEventListener("click", handler);
763
+ this.cleanupFns.push(() => el.removeEventListener("click", handler));
764
+ }
765
+ addInput(selector, handler) {
766
+ const el = this.container.querySelector(selector);
767
+ if (!el) return;
768
+ const fn = (e) => handler(e.target.value);
769
+ el.addEventListener("input", fn);
770
+ this.cleanupFns.push(() => el.removeEventListener("input", fn));
771
+ }
772
+ addChange(selector, handler) {
773
+ const el = this.container.querySelector(selector);
774
+ if (!el) return;
775
+ const fn = (e) => handler(e.target.value);
776
+ el.addEventListener("change", fn);
777
+ this.cleanupFns.push(() => el.removeEventListener("change", fn));
778
+ }
779
+ destroy() {
780
+ this.cleanupFns.forEach((fn) => fn());
781
+ this.cleanupFns = [];
782
+ this.removeAllListeners();
783
+ this.container.innerHTML = "";
784
+ }
785
+ };
786
+
787
+ // src/ui/full-player.ts
788
+ var FullPlayer = class extends EventEmitter {
789
+ container;
790
+ backdrop;
791
+ controller;
792
+ controls;
793
+ feedPageUrl;
794
+ cleanupFns = [];
795
+ // Element references
796
+ artworkEl = null;
797
+ trackNameEl = null;
798
+ trackTimeEl = null;
799
+ playBtn = null;
800
+ pauseBtn = null;
801
+ progressBar = null;
802
+ progressContainer = null;
803
+ playlistEl = null;
804
+ heroBg = null;
805
+ constructor(opts) {
806
+ super();
807
+ this.container = opts.container;
808
+ this.backdrop = opts.backdrop ?? null;
809
+ this.controller = opts.controller;
810
+ this.controls = {
811
+ playPause: true,
812
+ skipForward: true,
813
+ skipBackward: true,
814
+ volume: true,
815
+ speed: true,
816
+ progress: true,
817
+ playlist: true,
818
+ ...opts.controls
819
+ };
820
+ this.feedPageUrl = opts.feedPageUrl;
821
+ this.render();
822
+ this.bindEvents();
823
+ }
824
+ // ─── Public ────────────────────────────────────────────────────
825
+ show() {
826
+ this.container.style.display = "flex";
827
+ if (this.backdrop) this.backdrop.style.display = "block";
828
+ document.body.style.overflow = "hidden";
829
+ this.refreshPlaylist();
830
+ }
831
+ hide() {
832
+ this.container.style.display = "none";
833
+ if (this.backdrop) this.backdrop.style.display = "none";
834
+ document.body.style.overflow = "";
835
+ this.emit("close", void 0);
836
+ }
837
+ get isVisible() {
838
+ return this.container.style.display !== "none";
839
+ }
840
+ // ─── Render ────────────────────────────────────────────────────
841
+ render() {
842
+ const c = this.controls;
843
+ let mainControlsHtml = "";
844
+ if (c.skipBackward) {
845
+ mainControlsHtml += `<button class="pw-btn pw-btn--skip pw-btn--skip-back" aria-label="Back ${this.controller.config.skipSeconds} seconds">${ICONS.skipBack}</button>`;
846
+ }
847
+ if (c.playPause) {
848
+ mainControlsHtml += `
849
+ <button class="pw-btn pw-btn--play pw-play-btn" aria-label="Play">${ICONS.play}</button>
850
+ <button class="pw-btn pw-btn--play pw-pause-btn" aria-label="Pause" style="display:none">${ICONS.pause}</button>
851
+ `;
852
+ }
853
+ if (c.skipForward) {
854
+ mainControlsHtml += `<button class="pw-btn pw-btn--skip pw-btn--skip-fwd" aria-label="Forward ${this.controller.config.skipSeconds} seconds">${ICONS.skipForward}</button>`;
855
+ }
856
+ let secondaryHtml = "";
857
+ if (c.volume) {
858
+ secondaryHtml += `
859
+ <div class="pw-volume">
860
+ <span class="pw-volume-icon">${ICONS.volume}</span>
861
+ <input type="range" min="0" max="100" value="${Math.round(this.controller.engine.volume * 100)}" class="pw-volume-slider" aria-label="Volume">
862
+ </div>
863
+ `;
864
+ }
865
+ if (c.speed) {
866
+ const currentSpeed = this.controller.engine.playbackRate;
867
+ const options = SPEED_OPTIONS.map(
868
+ (s) => `<option value="${s}"${s === currentSpeed ? " selected" : ""}>${s}\xD7</option>`
869
+ ).join("");
870
+ secondaryHtml += `<select class="pw-speed-select" aria-label="Playback speed">${options}</select>`;
871
+ }
872
+ const progressHtml = c.progress ? `<div class="pw-progress pw-progress-container" role="slider" aria-label="Seek" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"><div class="pw-progress-bar"></div></div>` : "";
873
+ const playlistHtml = c.playlist ? `<div class="pw-playlist"><div class="pw-playlist-header">Latest Episodes</div><div class="pw-playlist-items"><div class="pw-playlist-item pw-loading">Loading episodes...</div></div></div>` : "";
874
+ this.container.innerHTML = `
875
+ <div class="pw-hero">
876
+ <div class="pw-hero-bg"></div>
877
+ <button class="pw-btn-close" aria-label="Minimize player">${ICONS.close}</button>
878
+ <div class="pw-now-playing">
879
+ <img class="pw-artwork" src="" alt="Podcast artwork" style="display:none">
880
+ <div class="pw-track-info">
881
+ <div class="pw-track-name" aria-live="polite">Select an episode to play</div>
882
+ <div class="pw-track-time" aria-live="off">00:00 / 00:00</div>
883
+ </div>
884
+ </div>
885
+ <div class="pw-controls">
886
+ <div class="pw-main-controls">${mainControlsHtml}</div>
887
+ ${progressHtml}
888
+ ${secondaryHtml ? `<div class="pw-secondary-controls">${secondaryHtml}</div>` : ""}
889
+ </div>
890
+ </div>
891
+ ${playlistHtml}
892
+ `;
893
+ this.artworkEl = this.container.querySelector(".pw-artwork");
894
+ this.trackNameEl = this.container.querySelector(".pw-track-name");
895
+ this.trackTimeEl = this.container.querySelector(".pw-track-time");
896
+ this.playBtn = this.container.querySelector(".pw-play-btn");
897
+ this.pauseBtn = this.container.querySelector(".pw-pause-btn");
898
+ this.progressBar = this.container.querySelector(".pw-progress-bar");
899
+ this.progressContainer = this.container.querySelector(".pw-progress-container");
900
+ this.playlistEl = this.container.querySelector(".pw-playlist-items");
901
+ this.heroBg = this.container.querySelector(".pw-hero-bg");
902
+ }
903
+ bindEvents() {
904
+ const { engine } = this.controller;
905
+ this.addClick(".pw-btn-close", () => this.hide());
906
+ if (this.backdrop) {
907
+ const handler = () => this.hide();
908
+ this.backdrop.addEventListener("click", handler);
909
+ this.cleanupFns.push(() => this.backdrop?.removeEventListener("click", handler));
910
+ }
911
+ const feedLinkHandler = (e) => {
912
+ if (e.target.closest("[data-feed-link]")) this.hide();
913
+ };
914
+ this.container.addEventListener("click", feedLinkHandler);
915
+ this.cleanupFns.push(() => this.container.removeEventListener("click", feedLinkHandler));
916
+ this.addClick(".pw-play-btn", () => this.controller.play());
917
+ this.addClick(".pw-pause-btn", () => this.controller.pause());
918
+ this.addClick(".pw-btn--skip-back", () => engine.skipBackward());
919
+ this.addClick(".pw-btn--skip-fwd", () => engine.skipForward());
920
+ this.addInput(".pw-volume-slider", (val) => this.controller.setVolume(parseInt(val) / 100));
921
+ this.addChange(".pw-speed-select", (val) => this.controller.setSpeed(parseFloat(val)));
922
+ if (this.progressContainer) {
923
+ const handler = (e) => {
924
+ const rect = this.progressContainer.getBoundingClientRect();
925
+ const pct = (e.clientX - rect.left) / rect.width * 100;
926
+ engine.seekToPercentage(Math.max(0, Math.min(100, pct)));
927
+ };
928
+ this.progressContainer.addEventListener("click", handler);
929
+ this.cleanupFns.push(() => this.progressContainer?.removeEventListener("click", handler));
930
+ }
931
+ const onKeyDown = (e) => {
932
+ if (!this.isVisible) return;
933
+ switch (e.key) {
934
+ case " ":
935
+ case "k":
936
+ e.preventDefault();
937
+ engine.isPlaying ? this.controller.pause() : this.controller.play();
938
+ break;
939
+ case "ArrowLeft":
940
+ e.preventDefault();
941
+ engine.skipBackward();
942
+ break;
943
+ case "ArrowRight":
944
+ e.preventDefault();
945
+ engine.skipForward();
946
+ break;
947
+ case "Escape":
948
+ e.preventDefault();
949
+ this.hide();
950
+ break;
951
+ }
952
+ };
953
+ document.addEventListener("keydown", onKeyDown);
954
+ this.cleanupFns.push(() => document.removeEventListener("keydown", onKeyDown));
955
+ const onTimeUpdate = (d) => {
956
+ if (this.progressBar) {
957
+ this.progressBar.style.width = `${d.percentage}%`;
958
+ }
959
+ if (this.progressContainer) {
960
+ this.progressContainer.setAttribute("aria-valuenow", Math.round(d.percentage).toString());
961
+ }
962
+ if (this.trackTimeEl) {
963
+ this.trackTimeEl.textContent = `${formatTime(d.currentTime)} / ${formatTime(d.duration)}`;
964
+ }
965
+ };
966
+ engine.on("time-update", onTimeUpdate);
967
+ this.cleanupFns.push(() => engine.off("time-update", onTimeUpdate));
968
+ const onPlay = () => this.updatePlayPauseState(true);
969
+ const onPause = () => this.updatePlayPauseState(false);
970
+ const onStop = () => this.updatePlayPauseState(false);
971
+ engine.on("play", onPlay);
972
+ engine.on("pause", onPause);
973
+ engine.on("stop", onStop);
974
+ engine.on("ended", onStop);
975
+ this.cleanupFns.push(() => {
976
+ engine.off("play", onPlay);
977
+ engine.off("pause", onPause);
978
+ engine.off("stop", onStop);
979
+ engine.off("ended", onStop);
980
+ });
981
+ const onEpisodeChange = (d) => {
982
+ this.updateDisplay(d.episode);
983
+ this.updatePlaylistHighlight(d.index);
984
+ };
985
+ this.controller.on("episode-change", onEpisodeChange);
986
+ this.cleanupFns.push(() => this.controller.off("episode-change", onEpisodeChange));
987
+ const onEpisodesLoaded = () => this.refreshPlaylist();
988
+ this.controller.on("episodes-loaded", onEpisodesLoaded);
989
+ this.cleanupFns.push(() => this.controller.off("episodes-loaded", onEpisodesLoaded));
990
+ }
991
+ // ─── Display updates ──────────────────────────────────────────
992
+ updateDisplay(episode) {
993
+ const imageUrl = getEpisodeImage(episode);
994
+ if (this.trackNameEl) {
995
+ this.trackNameEl.textContent = `${episode.feedName}: ${episode.title}`;
996
+ }
997
+ if (this.artworkEl) {
998
+ if (imageUrl) {
999
+ this.artworkEl.src = imageUrl;
1000
+ this.artworkEl.style.display = "block";
1001
+ } else {
1002
+ this.artworkEl.style.display = "none";
1003
+ }
1004
+ }
1005
+ if (this.heroBg) {
1006
+ if (imageUrl) {
1007
+ this.heroBg.style.backgroundImage = `url("${imageUrl}")`;
1008
+ this.heroBg.classList.add("pw-active");
1009
+ } else {
1010
+ this.heroBg.classList.remove("pw-active");
1011
+ this.heroBg.style.backgroundImage = "";
1012
+ }
1013
+ }
1014
+ }
1015
+ updatePlayPauseState(playing) {
1016
+ if (this.playBtn) this.playBtn.style.display = playing ? "none" : "flex";
1017
+ if (this.pauseBtn) this.pauseBtn.style.display = playing ? "flex" : "none";
1018
+ }
1019
+ refreshPlaylist() {
1020
+ if (!this.playlistEl) return;
1021
+ this.playlistEl.innerHTML = this.controller.getPlaylistHtml(this.feedPageUrl);
1022
+ this.bindPlaylistClicks();
1023
+ }
1024
+ bindPlaylistClicks() {
1025
+ if (!this.playlistEl) return;
1026
+ this.playlistEl.querySelectorAll(".pw-playlist-item").forEach((item) => {
1027
+ item.addEventListener("click", (e) => {
1028
+ if (e.target.closest("[data-feed-link]")) return;
1029
+ const index = parseInt(item.dataset.index || "0");
1030
+ this.controller.playEpisode(index);
1031
+ });
1032
+ });
1033
+ }
1034
+ updatePlaylistHighlight(index) {
1035
+ if (!this.playlistEl) return;
1036
+ this.playlistEl.querySelectorAll(".pw-playlist-item").forEach((item, i) => {
1037
+ item.classList.toggle("pw-playing", i === index);
1038
+ });
1039
+ }
1040
+ // ─── Helpers ───────────────────────────────────────────────────
1041
+ addClick(selector, handler) {
1042
+ const el = this.container.querySelector(selector);
1043
+ if (!el) return;
1044
+ el.addEventListener("click", handler);
1045
+ this.cleanupFns.push(() => el.removeEventListener("click", handler));
1046
+ }
1047
+ addInput(selector, handler) {
1048
+ const el = this.container.querySelector(selector);
1049
+ if (!el) return;
1050
+ const fn = (e) => handler(e.target.value);
1051
+ el.addEventListener("input", fn);
1052
+ this.cleanupFns.push(() => el.removeEventListener("input", fn));
1053
+ }
1054
+ addChange(selector, handler) {
1055
+ const el = this.container.querySelector(selector);
1056
+ if (!el) return;
1057
+ const fn = (e) => handler(e.target.value);
1058
+ el.addEventListener("change", fn);
1059
+ this.cleanupFns.push(() => el.removeEventListener("change", fn));
1060
+ }
1061
+ destroy() {
1062
+ this.cleanupFns.forEach((fn) => fn());
1063
+ this.cleanupFns = [];
1064
+ this.removeAllListeners();
1065
+ this.container.innerHTML = "";
1066
+ }
1067
+ };
1068
+ export {
1069
+ AudioEngine,
1070
+ DEFAULT_CONFIG,
1071
+ EventEmitter,
1072
+ FetchEpisodeProvider,
1073
+ FullPlayer,
1074
+ ICONS,
1075
+ MiniPlayer,
1076
+ PlaybackStorage,
1077
+ PlayerController,
1078
+ PlayerStateStorage,
1079
+ SPEED_OPTIONS,
1080
+ escapeHtml,
1081
+ formatDate,
1082
+ formatDuration,
1083
+ formatTime,
1084
+ getEpisodeImage,
1085
+ renderPlaylist,
1086
+ renderPlaylistItem,
1087
+ resolveConfig
1088
+ };