@dudgy/podcast-widget 0.2.0 → 0.3.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/README.md CHANGED
@@ -61,7 +61,7 @@ podcast-widget/
61
61
  │ │ ├── player-state.ts # localStorage for player state + speed preference
62
62
  │ │ └── episode-provider.ts # FetchEpisodeProvider with caching + retry
63
63
  │ ├── ui/
64
- │ │ ├── utils.ts # formatTime, escapeHtml, getEpisodeImage
64
+ │ │ ├── utils.ts # Formatting, artwork fallback, seek tooltip
65
65
  │ │ ├── html-templates.ts # SVG icons, playlist rendering, speed options
66
66
  │ │ ├── player-controller.ts # Orchestrator: engine + storage + provider → events
67
67
  │ │ ├── mini-player.ts # Mini mode with configurable controls + inline playlist
@@ -73,6 +73,8 @@ podcast-widget/
73
73
  │ ├── styles/
74
74
  │ │ └── podcast-player.css # Plain CSS with custom property theming (pw- prefix)
75
75
  │ └── index.ts # Main barrel export
76
+ ├── tests/ # Unit tests (Vitest + jsdom)
77
+ ├── e2e/ # Browser tests (Playwright, Chrome + WebKit)
76
78
  ├── package.json # Dual ESM/CJS, subpath exports
77
79
  ├── tsconfig.json # Client-side TS config
78
80
  ├── tsconfig.server.json # Server-side (podcast-index) config
@@ -194,13 +196,15 @@ controller.playEpisode(2); // Load and play
194
196
  controller.setSpeed(1.5);
195
197
  controller.setVolume(0.8);
196
198
 
197
- controller.on('episode-change', ({ episode, index }) => {});
199
+ controller.on('episode-change', ({ episode, index }) => {}); // index is -1 if not in the list
198
200
  controller.on('episodes-loaded', ({ episodes }) => {});
199
201
  controller.on('episode-display', ({ imageUrl, title, show }) => {});
200
202
 
201
203
  controller.destroy();
202
204
  ```
203
205
 
206
+ **Restoring on page load.** `loadEpisodes()` restores the episode the listener last had loaded (paused, at its saved position). The episode is saved as a snapshot and matched by `id`, so episode IDs must be stable across fetches — use the feed's `guid` where possible rather than list position or a URL that may change. If the saved episode is still in the list, the fresh copy is used; if it has dropped out (e.g. its feed published something newer), it's restored from the snapshot with `getCurrentIndex() === -1`. With nothing saved, the first episode is cued. Saved resume positions are kept for listed episodes and the current one; others are cleaned up.
207
+
204
208
  ### EpisodeProvider
205
209
 
206
210
  Interface for loading episodes. The package ships `FetchEpisodeProvider` which fetches from a URL with caching and retry.
@@ -304,9 +308,30 @@ const headers = createPodcastIndexHeaders(apiKey, apiSecret);
304
308
  npm run build # Build
305
309
  npm run dev # Build + watch
306
310
  npm run typecheck # Type check
307
- npm test # Run tests
311
+ npm test # Unit tests (Vitest + jsdom)
312
+ npm run test:e2e # Build, then browser tests in Chrome and WebKit
313
+ ```
314
+
315
+ ### Browser tests
316
+
317
+ `e2e/` drives the built package in real browsers through a fixture page
318
+ (`e2e/fixture.html`). Requests are intercepted and answered from code — the page,
319
+ `dist/`, a test-controlled episode list, generated silent audio and test images — so
320
+ there's no server, network access or API keys, and results are repeatable.
321
+
322
+ They cover restoring the listener's episode and position, skip buttons, artwork
323
+ fallback, the seek tooltip, layout, and exact-match screenshots of the players
324
+ (`e2e/player.spec.ts-snapshots/`). After an intended visual change, regenerate the
325
+ screenshots and look at them before committing:
326
+
327
+ ```bash
328
+ npm run test:e2e -- --update-snapshots=all
308
329
  ```
309
330
 
331
+ Requirements: Google Chrome installed (the `chrome` project uses the system
332
+ browser), and Playwright's WebKit (`npx playwright install webkit`) with its system
333
+ libraries (`npx playwright install-deps webkit`, needs sudo).
334
+
310
335
  ### Testing in a Consumer Before Publishing
311
336
 
312
337
  ```bash
package/dist/index.cjs CHANGED
@@ -198,10 +198,11 @@ var PlaybackStorage = class {
198
198
  } catch (e4) {
199
199
  }
200
200
  }
201
- cleanupPositions(currentEpisodeIds) {
201
+ /** Remove saved positions for episodes whose IDs aren't in `keepIds`. */
202
+ cleanupPositions(keepIds) {
202
203
  try {
203
204
  const positions = this.getPositions();
204
- const currentSet = new Set(currentEpisodeIds);
205
+ const currentSet = new Set(keepIds);
205
206
  let changed = false;
206
207
  for (const id of Object.keys(positions)) {
207
208
  if (!currentSet.has(id)) {
@@ -217,6 +218,19 @@ var PlaybackStorage = class {
217
218
  }
218
219
  };
219
220
 
221
+ // src/core/types.ts
222
+ var PLAYER_STATE_VERSION = 2;
223
+ var DEFAULT_CONFIG = {
224
+ storagePrefix: "podcast",
225
+ maxStoredPositions: 100,
226
+ positionSaveInterval: 5e3,
227
+ skipSeconds: 30,
228
+ episodeCacheTTL: 60 * 60 * 1e3
229
+ };
230
+ function resolveConfig(config) {
231
+ return { ...DEFAULT_CONFIG, ...config };
232
+ }
233
+
220
234
  // src/core/player-state.ts
221
235
  var PlayerStateStorage = class {
222
236
 
@@ -231,11 +245,22 @@ var PlayerStateStorage = class {
231
245
  } catch (e6) {
232
246
  }
233
247
  }
248
+ /**
249
+ * Load saved state, migrating older formats. Returns null if nothing usable
250
+ * is saved.
251
+ *
252
+ * Unversioned (v1) state stored only an index into the episode list, which
253
+ * can't be trusted once the list changes, so only its volume is kept.
254
+ */
234
255
  loadState() {
235
256
  try {
236
257
  const raw = localStorage.getItem(this.stateKey);
237
258
  if (!raw) return null;
238
- return JSON.parse(raw);
259
+ const data = JSON.parse(raw);
260
+ if (!data || typeof data !== "object") return null;
261
+ const volume = isVolume(data.volume) ? data.volume : 1;
262
+ const episode = data.v === PLAYER_STATE_VERSION && isEpisode(data.episode) ? data.episode : null;
263
+ return { v: PLAYER_STATE_VERSION, episode, volume };
239
264
  } catch (e7) {
240
265
  return null;
241
266
  }
@@ -257,6 +282,14 @@ var PlayerStateStorage = class {
257
282
  }
258
283
  }
259
284
  };
285
+ function isVolume(v) {
286
+ return typeof v === "number" && v >= 0 && v <= 1;
287
+ }
288
+ function isEpisode(e) {
289
+ if (!e || typeof e !== "object") return false;
290
+ const ep = e;
291
+ return typeof ep.id === "string" && typeof ep.audioUrl === "string" && typeof ep.title === "string" && typeof ep.feedName === "string";
292
+ }
260
293
 
261
294
  // src/core/episode-provider.ts
262
295
  var FetchEpisodeProvider = class {
@@ -314,18 +347,6 @@ var FetchEpisodeProvider = class {
314
347
  }
315
348
  };
316
349
 
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
350
  // src/ui/utils.ts
330
351
  function formatTime(seconds) {
331
352
  if (isNaN(seconds) || seconds < 0) return "00:00";
@@ -368,20 +389,75 @@ function escapeHtml(str) {
368
389
  function getEpisodeImage(episode) {
369
390
  return episode.image || episode.feedImage || episode.artwork || "";
370
391
  }
392
+ function setArtwork(img, url) {
393
+ if (!img) return;
394
+ img.hidden = !url;
395
+ if (url) img.src = url;
396
+ else img.removeAttribute("src");
397
+ }
398
+ function hideBrokenImages(root) {
399
+ const onError = (e) => {
400
+ const t = e.target;
401
+ if (t instanceof HTMLImageElement && _optionalChain([t, 'access', _13 => _13.parentElement, 'optionalAccess', _14 => _14.classList, 'access', _15 => _15.contains, 'call', _16 => _16("pw-art")])) t.hidden = true;
402
+ };
403
+ root.addEventListener("error", onError, true);
404
+ return () => root.removeEventListener("error", onError, true);
405
+ }
406
+ function attachSeekTooltip(bar, getDuration) {
407
+ const tip = document.createElement("div");
408
+ tip.className = "pw-seek-tooltip";
409
+ tip.setAttribute("aria-hidden", "true");
410
+ tip.hidden = true;
411
+ bar.appendChild(tip);
412
+ const onMove = (e) => {
413
+ const duration = getDuration();
414
+ if (e.pointerType === "touch" || !(duration > 0)) {
415
+ tip.hidden = true;
416
+ return;
417
+ }
418
+ const rect = bar.getBoundingClientRect();
419
+ const frac = Math.min(1, Math.max(0, (e.clientX - rect.left) / rect.width));
420
+ tip.textContent = formatTime(frac * duration);
421
+ tip.hidden = false;
422
+ const half = tip.offsetWidth / 2;
423
+ tip.style.left = `${Math.min(rect.width - half, Math.max(half, frac * rect.width))}px`;
424
+ };
425
+ const onLeave = () => {
426
+ tip.hidden = true;
427
+ };
428
+ bar.addEventListener("pointermove", onMove);
429
+ bar.addEventListener("pointerleave", onLeave);
430
+ return () => {
431
+ bar.removeEventListener("pointermove", onMove);
432
+ bar.removeEventListener("pointerleave", onLeave);
433
+ tip.remove();
434
+ };
435
+ }
371
436
 
372
437
  // src/ui/html-templates.ts
373
438
  var ICONS = {
374
439
  play: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',
375
440
  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>',
441
+ // Plain circular arrows; the seconds are drawn as text on top (see renderSkipButton)
442
+ skipBack: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z"/></svg>',
443
+ skipForward: '<svg viewBox="0 0 24 24" fill="currentColor"><path transform="matrix(-1 0 0 1 24 0)" d="M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z"/></svg>',
378
444
  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
445
  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
446
  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
447
  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
448
  playlist: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z"/></svg>',
449
+ note: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/></svg>',
383
450
  download: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"/></svg>'
384
451
  };
452
+ function renderArtwork(className, imageUrl) {
453
+ const img = imageUrl ? `<img src="${escapeHtml(imageUrl)}" alt="">` : '<img alt="" hidden>';
454
+ return `<span class="pw-art ${className}">${img}${ICONS.note}</span>`;
455
+ }
456
+ function renderSkipButton(direction, seconds, extraClass = "") {
457
+ const label = `${direction === "back" ? "Back" : "Forward"} ${seconds} seconds`;
458
+ const icon = direction === "back" ? ICONS.skipBack : ICONS.skipForward;
459
+ return `<button class="pw-btn pw-btn--skip pw-btn--skip-${direction} ${extraClass}" aria-label="${label}">${icon}<span class="pw-skip-label" aria-hidden="true">${seconds}</span></button>`;
460
+ }
385
461
  var SPEED_OPTIONS = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3];
386
462
  function renderPlaylistItem(episode, index, opts) {
387
463
  const imageUrl = getEpisodeImage(episode);
@@ -397,7 +473,7 @@ function renderPlaylistItem(episode, index, opts) {
397
473
  const feedLinkHtml = opts.feedPageUrl ? `<a href="${opts.feedPageUrl(episode.feedId)}" class="pw-view-feed" title="View show info" data-feed-link>${ICONS.info}</a>` : "";
398
474
  return `
399
475
  <div class="pw-playlist-item ${opts.isPlaying ? "pw-playing" : ""} ${hasSaved ? "pw-has-saved" : ""}" data-index="${index}">
400
- ${imageUrl ? `<img src="${escapeHtml(imageUrl)}" alt="${escapeHtml(episode.title)}" class="pw-episode-image">` : ""}
476
+ ${renderArtwork("pw-episode-image", imageUrl)}
401
477
  <div class="pw-episode-info">
402
478
  <div class="pw-episode-show">${escapeHtml(episode.feedName || "Unknown Show")}</div>
403
479
  <div class="pw-episode-title">${escapeHtml(episode.title)}</div>
@@ -433,11 +509,14 @@ var PlayerController = (_class3 = class extends EventEmitter {
433
509
 
434
510
 
435
511
  __init4() {this.episodes = []}
436
- __init5() {this.currentIndex = -1}
437
- __init6() {this.saveInterval = null}
438
- __init7() {this.cleanupFns = []}
512
+ /** The loaded episode. May not be in `episodes` (e.g. restored after its feed moved on). */
513
+ __init5() {this.currentEpisode = null}
514
+ /** Index of `currentEpisode` in `episodes`, or -1 if it isn't in the list. */
515
+ __init6() {this.currentIndex = -1}
516
+ __init7() {this.saveInterval = null}
517
+ __init8() {this.cleanupFns = []}
439
518
  constructor(engine, provider, config) {
440
- super();_class3.prototype.__init4.call(this);_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);;
519
+ super();_class3.prototype.__init4.call(this);_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);;
441
520
  this.config = resolveConfig(config);
442
521
  this.engine = engine;
443
522
  this.provider = provider;
@@ -448,12 +527,12 @@ var PlayerController = (_class3 = class extends EventEmitter {
448
527
  this.engine.playbackRate = savedSpeed;
449
528
  }
450
529
  const savedState = this.stateStorage.loadState();
451
- if (_optionalChain([savedState, 'optionalAccess', _13 => _13.volume]) != null) {
530
+ if (_optionalChain([savedState, 'optionalAccess', _17 => _17.volume]) != null) {
452
531
  this.engine.volume = savedState.volume;
453
532
  }
454
533
  this.engine.on("ended", () => {
455
- if (this.currentIndex >= 0) {
456
- this.storage.removePosition(this.episodes[this.currentIndex].id);
534
+ if (this.currentEpisode) {
535
+ this.storage.removePosition(this.currentEpisode.id);
457
536
  }
458
537
  this.stopPositionSaving();
459
538
  });
@@ -467,11 +546,17 @@ var PlayerController = (_class3 = class extends EventEmitter {
467
546
  // ─── Episode management ────────────────────────────────────────
468
547
  async loadEpisodes() {
469
548
  this.episodes = await this.provider.getEpisodes();
470
- this.storage.cleanupPositions(this.episodes.map((ep) => ep.id));
549
+ const saved = _nullishCoalesce(_optionalChain([this, 'access', _18 => _18.stateStorage, 'access', _19 => _19.loadState, 'call', _20 => _20(), 'optionalAccess', _21 => _21.episode]), () => ( null));
550
+ const keepIds = this.episodes.map((ep) => ep.id);
551
+ if (saved) keepIds.push(saved.id);
552
+ this.storage.cleanupPositions(keepIds);
471
553
  this.emit("episodes-loaded", { episodes: this.episodes });
472
- const savedState = this.stateStorage.loadState();
473
- if (savedState && savedState.currentEpisodeIndex >= 0 && savedState.currentEpisodeIndex < this.episodes.length) {
474
- this.loadEpisode(savedState.currentEpisodeIndex, false);
554
+ if (saved) {
555
+ const index = this.episodes.findIndex((ep) => ep.id === saved.id);
556
+ if (index >= 0) this.loadEpisode(index, false);
557
+ else this.select(saved, -1, false);
558
+ } else if (this.episodes.length > 0) {
559
+ this.loadEpisode(0, false);
475
560
  }
476
561
  return this.episodes;
477
562
  }
@@ -479,21 +564,22 @@ var PlayerController = (_class3 = class extends EventEmitter {
479
564
  return this.episodes;
480
565
  }
481
566
  getCurrentEpisode() {
482
- return this.currentIndex >= 0 ? this.episodes[this.currentIndex] : null;
567
+ return this.currentEpisode;
483
568
  }
569
+ /** Index of the current episode in the list, or -1 if none or not listed. */
484
570
  getCurrentIndex() {
485
571
  return this.currentIndex;
486
572
  }
487
573
  loadEpisode(index, autoPlay = false) {
488
574
  if (index < 0 || index >= this.episodes.length) return;
489
- const episode = this.episodes[index];
575
+ this.select(this.episodes[index], index, autoPlay);
576
+ }
577
+ select(episode, index, autoPlay) {
578
+ this.currentEpisode = episode;
490
579
  this.currentIndex = index;
491
580
  const savedPosition = this.storage.getPosition(episode.id);
492
581
  this.engine.load(episode.audioUrl, _nullishCoalesce(savedPosition, () => ( void 0)));
493
- this.stateStorage.saveState({
494
- currentEpisodeIndex: this.currentIndex,
495
- volume: this.engine.volume
496
- });
582
+ this.persistState();
497
583
  this.emit("episode-change", { episode, index });
498
584
  this.emit("episode-display", {
499
585
  imageUrl: getEpisodeImage(episode),
@@ -508,9 +594,8 @@ var PlayerController = (_class3 = class extends EventEmitter {
508
594
  this.loadEpisode(index, true);
509
595
  }
510
596
  async play() {
511
- if (this.episodes.length === 0) return;
512
- if (this.currentIndex === -1) {
513
- this.playEpisode(0);
597
+ if (!this.currentEpisode) {
598
+ if (this.episodes.length > 0) this.playEpisode(0);
514
599
  return;
515
600
  }
516
601
  await this.engine.play();
@@ -526,9 +611,13 @@ var PlayerController = (_class3 = class extends EventEmitter {
526
611
  }
527
612
  setVolume(v) {
528
613
  this.engine.volume = v;
614
+ this.persistState();
615
+ }
616
+ persistState() {
529
617
  this.stateStorage.saveState({
530
- currentEpisodeIndex: this.currentIndex,
531
- volume: v
618
+ v: PLAYER_STATE_VERSION,
619
+ episode: this.currentEpisode,
620
+ volume: this.engine.volume
532
621
  });
533
622
  }
534
623
  getPlaylistHtml(feedPageUrl) {
@@ -554,8 +643,8 @@ var PlayerController = (_class3 = class extends EventEmitter {
554
643
  }
555
644
  }
556
645
  saveCurrentPosition() {
557
- if (this.currentIndex < 0 || !this.engine.hasSrc) return;
558
- const episode = this.episodes[this.currentIndex];
646
+ const episode = this.currentEpisode;
647
+ if (!episode || !this.engine.hasSrc) return;
559
648
  if (this.engine.currentTime > 10) {
560
649
  this.storage.savePosition(episode.id, this.engine.currentTime, episode.duration);
561
650
  }
@@ -576,19 +665,19 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
576
665
 
577
666
 
578
667
 
579
- __init8() {this.cleanupFns = []}
668
+ __init9() {this.cleanupFns = []}
580
669
  // Element references (created during render)
581
- __init9() {this.artworkEl = null}
582
- __init10() {this.titleEl = null}
583
- __init11() {this.showEl = null}
584
- __init12() {this.playBtn = null}
585
- __init13() {this.pauseBtn = null}
586
- __init14() {this.progressBar = null}
587
- __init15() {this.progressContainer = null}
588
- __init16() {this.playlistContainer = null}
589
- __init17() {this.playlistOpen = false}
670
+ __init10() {this.artworkEl = null}
671
+ __init11() {this.titleEl = null}
672
+ __init12() {this.showEl = null}
673
+ __init13() {this.playBtn = null}
674
+ __init14() {this.pauseBtn = null}
675
+ __init15() {this.progressBar = null}
676
+ __init16() {this.progressContainer = null}
677
+ __init17() {this.playlistContainer = null}
678
+ __init18() {this.playlistOpen = false}
590
679
  constructor(opts) {
591
- super();_class4.prototype.__init8.call(this);_class4.prototype.__init9.call(this);_class4.prototype.__init10.call(this);_class4.prototype.__init11.call(this);_class4.prototype.__init12.call(this);_class4.prototype.__init13.call(this);_class4.prototype.__init14.call(this);_class4.prototype.__init15.call(this);_class4.prototype.__init16.call(this);_class4.prototype.__init17.call(this);;
680
+ super();_class4.prototype.__init9.call(this);_class4.prototype.__init10.call(this);_class4.prototype.__init11.call(this);_class4.prototype.__init12.call(this);_class4.prototype.__init13.call(this);_class4.prototype.__init14.call(this);_class4.prototype.__init15.call(this);_class4.prototype.__init16.call(this);_class4.prototype.__init17.call(this);_class4.prototype.__init18.call(this);;
592
681
  this.container = opts.container;
593
682
  this.controller = opts.controller;
594
683
  this.controls = {
@@ -604,16 +693,16 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
604
693
  const c = this.controls;
605
694
  let controlsHtml = "";
606
695
  if (c.skipBackward) {
607
- controlsHtml += `<button class="pw-btn pw-btn--mini pw-btn--skip-back" aria-label="Back ${this.controller.config.skipSeconds} seconds">${ICONS.skipBack}</button>`;
696
+ controlsHtml += renderSkipButton("back", this.controller.config.skipSeconds, "pw-btn--mini");
608
697
  }
609
698
  if (c.playPause) {
610
699
  controlsHtml += `
611
- <button class="pw-btn pw-btn--mini pw-play-btn" aria-label="Play">${ICONS.play}</button>
612
- <button class="pw-btn pw-btn--mini pw-pause-btn" aria-label="Pause" style="display:none">${ICONS.pause}</button>
700
+ <button class="pw-btn pw-btn--mini pw-btn--play pw-play-btn" aria-label="Play">${ICONS.play}</button>
701
+ <button class="pw-btn pw-btn--mini pw-btn--play pw-pause-btn" aria-label="Pause" style="display:none">${ICONS.pause}</button>
613
702
  `;
614
703
  }
615
704
  if (c.skipForward) {
616
- controlsHtml += `<button class="pw-btn pw-btn--mini pw-btn--skip-fwd" aria-label="Forward ${this.controller.config.skipSeconds} seconds">${ICONS.skipForward}</button>`;
705
+ controlsHtml += renderSkipButton("fwd", this.controller.config.skipSeconds, "pw-btn--mini");
617
706
  }
618
707
  if (c.volume) {
619
708
  controlsHtml += `
@@ -639,7 +728,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
639
728
  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>` : "";
640
729
  this.container.innerHTML = `
641
730
  <div class="pw-mini">
642
- <img class="pw-mini-artwork" src="" alt="Podcast artwork" style="display:none">
731
+ ${renderArtwork("pw-mini-artwork")}
643
732
  <div class="pw-mini-info">
644
733
  <div class="pw-mini-title">No episode playing</div>
645
734
  <div class="pw-mini-show"></div>
@@ -649,7 +738,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
649
738
  </div>
650
739
  ${c.playlist ? '<div class="pw-mini-playlist" style="display:none"></div>' : ""}
651
740
  `;
652
- this.artworkEl = this.container.querySelector(".pw-mini-artwork");
741
+ this.artworkEl = this.container.querySelector(".pw-mini-artwork img");
653
742
  this.titleEl = this.container.querySelector(".pw-mini-title");
654
743
  this.showEl = this.container.querySelector(".pw-mini-show");
655
744
  this.playBtn = this.container.querySelector(".pw-play-btn");
@@ -660,6 +749,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
660
749
  }
661
750
  bindEvents() {
662
751
  const { engine } = this.controller;
752
+ this.cleanupFns.push(hideBrokenImages(this.container));
663
753
  this.addClick(".pw-play-btn", () => this.controller.play());
664
754
  this.addClick(".pw-pause-btn", () => this.controller.pause());
665
755
  this.addClick(".pw-btn--skip-back", () => engine.skipBackward());
@@ -675,7 +765,8 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
675
765
  engine.seekToPercentage(Math.max(0, Math.min(100, pct)));
676
766
  };
677
767
  this.progressContainer.addEventListener("click", handler);
678
- this.cleanupFns.push(() => _optionalChain([this, 'access', _14 => _14.progressContainer, 'optionalAccess', _15 => _15.removeEventListener, 'call', _16 => _16("click", handler)]));
768
+ this.cleanupFns.push(() => _optionalChain([this, 'access', _22 => _22.progressContainer, 'optionalAccess', _23 => _23.removeEventListener, 'call', _24 => _24("click", handler)]));
769
+ this.cleanupFns.push(attachSeekTooltip(this.progressContainer, () => engine.duration));
679
770
  }
680
771
  const onTimeUpdate = (d) => {
681
772
  if (this.progressBar) {
@@ -719,14 +810,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
719
810
  const imageUrl = getEpisodeImage(episode);
720
811
  if (this.titleEl) this.titleEl.textContent = episode.title;
721
812
  if (this.showEl) this.showEl.textContent = episode.feedName;
722
- if (this.artworkEl) {
723
- if (imageUrl) {
724
- this.artworkEl.src = imageUrl;
725
- this.artworkEl.style.display = "block";
726
- } else {
727
- this.artworkEl.style.display = "none";
728
- }
729
- }
813
+ setArtwork(this.artworkEl, imageUrl);
730
814
  }
731
815
  updatePlayPauseState(playing) {
732
816
  if (this.playBtn) this.playBtn.style.display = playing ? "none" : "flex";
@@ -793,19 +877,19 @@ var FullPlayer = (_class5 = class extends EventEmitter {
793
877
 
794
878
 
795
879
 
796
- __init18() {this.cleanupFns = []}
880
+ __init19() {this.cleanupFns = []}
797
881
  // Element references
798
- __init19() {this.artworkEl = null}
799
- __init20() {this.trackNameEl = null}
800
- __init21() {this.trackTimeEl = null}
801
- __init22() {this.playBtn = null}
802
- __init23() {this.pauseBtn = null}
803
- __init24() {this.progressBar = null}
804
- __init25() {this.progressContainer = null}
805
- __init26() {this.playlistEl = null}
806
- __init27() {this.heroBg = null}
882
+ __init20() {this.artworkEl = null}
883
+ __init21() {this.trackNameEl = null}
884
+ __init22() {this.trackTimeEl = null}
885
+ __init23() {this.playBtn = null}
886
+ __init24() {this.pauseBtn = null}
887
+ __init25() {this.progressBar = null}
888
+ __init26() {this.progressContainer = null}
889
+ __init27() {this.playlistEl = null}
890
+ __init28() {this.heroBg = null}
807
891
  constructor(opts) {
808
- super();_class5.prototype.__init18.call(this);_class5.prototype.__init19.call(this);_class5.prototype.__init20.call(this);_class5.prototype.__init21.call(this);_class5.prototype.__init22.call(this);_class5.prototype.__init23.call(this);_class5.prototype.__init24.call(this);_class5.prototype.__init25.call(this);_class5.prototype.__init26.call(this);_class5.prototype.__init27.call(this);;
892
+ super();_class5.prototype.__init19.call(this);_class5.prototype.__init20.call(this);_class5.prototype.__init21.call(this);_class5.prototype.__init22.call(this);_class5.prototype.__init23.call(this);_class5.prototype.__init24.call(this);_class5.prototype.__init25.call(this);_class5.prototype.__init26.call(this);_class5.prototype.__init27.call(this);_class5.prototype.__init28.call(this);;
809
893
  this.container = opts.container;
810
894
  this.backdrop = _nullishCoalesce(opts.backdrop, () => ( null));
811
895
  this.controller = opts.controller;
@@ -845,7 +929,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
845
929
  const c = this.controls;
846
930
  let mainControlsHtml = "";
847
931
  if (c.skipBackward) {
848
- mainControlsHtml += `<button class="pw-btn pw-btn--skip pw-btn--skip-back" aria-label="Back ${this.controller.config.skipSeconds} seconds">${ICONS.skipBack}</button>`;
932
+ mainControlsHtml += renderSkipButton("back", this.controller.config.skipSeconds);
849
933
  }
850
934
  if (c.playPause) {
851
935
  mainControlsHtml += `
@@ -854,7 +938,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
854
938
  `;
855
939
  }
856
940
  if (c.skipForward) {
857
- mainControlsHtml += `<button class="pw-btn pw-btn--skip pw-btn--skip-fwd" aria-label="Forward ${this.controller.config.skipSeconds} seconds">${ICONS.skipForward}</button>`;
941
+ mainControlsHtml += renderSkipButton("fwd", this.controller.config.skipSeconds);
858
942
  }
859
943
  let secondaryHtml = "";
860
944
  if (c.volume) {
@@ -882,7 +966,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
882
966
  <div class="pw-hero-bg"></div>
883
967
  <button class="pw-btn-close" aria-label="Minimize player">${ICONS.close}</button>
884
968
  <div class="pw-now-playing">
885
- <img class="pw-artwork" src="" alt="Podcast artwork" style="display:none">
969
+ ${renderArtwork("pw-artwork")}
886
970
  <div class="pw-track-info">
887
971
  <div class="pw-track-name" aria-live="polite">Select an episode to play</div>
888
972
  <div class="pw-track-time" aria-live="off">00:00 / 00:00</div>
@@ -896,7 +980,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
896
980
  </div>
897
981
  ${playlistHtml}
898
982
  `;
899
- this.artworkEl = this.container.querySelector(".pw-artwork");
983
+ this.artworkEl = this.container.querySelector(".pw-artwork img");
900
984
  this.trackNameEl = this.container.querySelector(".pw-track-name");
901
985
  this.trackTimeEl = this.container.querySelector(".pw-track-time");
902
986
  this.playBtn = this.container.querySelector(".pw-play-btn");
@@ -908,11 +992,18 @@ var FullPlayer = (_class5 = class extends EventEmitter {
908
992
  }
909
993
  bindEvents() {
910
994
  const { engine } = this.controller;
995
+ this.cleanupFns.push(hideBrokenImages(this.container));
996
+ const art = this.artworkEl;
997
+ if (art) {
998
+ const onArtLoad = () => this.setHeroBackground(art.currentSrc || art.src);
999
+ art.addEventListener("load", onArtLoad);
1000
+ this.cleanupFns.push(() => art.removeEventListener("load", onArtLoad));
1001
+ }
911
1002
  this.addClick(".pw-btn-close", () => this.hide());
912
1003
  if (this.backdrop) {
913
1004
  const handler = () => this.hide();
914
1005
  this.backdrop.addEventListener("click", handler);
915
- this.cleanupFns.push(() => _optionalChain([this, 'access', _17 => _17.backdrop, 'optionalAccess', _18 => _18.removeEventListener, 'call', _19 => _19("click", handler)]));
1006
+ this.cleanupFns.push(() => _optionalChain([this, 'access', _25 => _25.backdrop, 'optionalAccess', _26 => _26.removeEventListener, 'call', _27 => _27("click", handler)]));
916
1007
  }
917
1008
  const feedLinkHandler = (e) => {
918
1009
  if (e.target.closest("[data-feed-link]")) this.hide();
@@ -933,7 +1024,8 @@ var FullPlayer = (_class5 = class extends EventEmitter {
933
1024
  engine.seekToPercentage(Math.max(0, Math.min(100, pct)));
934
1025
  };
935
1026
  this.progressContainer.addEventListener("click", handler);
936
- this.cleanupFns.push(() => _optionalChain([this, 'access', _20 => _20.progressContainer, 'optionalAccess', _21 => _21.removeEventListener, 'call', _22 => _22("click", handler)]));
1027
+ this.cleanupFns.push(() => _optionalChain([this, 'access', _28 => _28.progressContainer, 'optionalAccess', _29 => _29.removeEventListener, 'call', _30 => _30("click", handler)]));
1028
+ this.cleanupFns.push(attachSeekTooltip(this.progressContainer, () => engine.duration));
937
1029
  }
938
1030
  const onKeyDown = (e) => {
939
1031
  if (!this.isVisible) return;
@@ -1001,23 +1093,13 @@ var FullPlayer = (_class5 = class extends EventEmitter {
1001
1093
  if (this.trackNameEl) {
1002
1094
  this.trackNameEl.textContent = `${episode.feedName}: ${episode.title}`;
1003
1095
  }
1004
- if (this.artworkEl) {
1005
- if (imageUrl) {
1006
- this.artworkEl.src = imageUrl;
1007
- this.artworkEl.style.display = "block";
1008
- } else {
1009
- this.artworkEl.style.display = "none";
1010
- }
1011
- }
1012
- if (this.heroBg) {
1013
- if (imageUrl) {
1014
- this.heroBg.style.backgroundImage = `url("${imageUrl}")`;
1015
- this.heroBg.classList.add("pw-active");
1016
- } else {
1017
- this.heroBg.classList.remove("pw-active");
1018
- this.heroBg.style.backgroundImage = "";
1019
- }
1020
- }
1096
+ this.setHeroBackground("");
1097
+ setArtwork(this.artworkEl, imageUrl);
1098
+ }
1099
+ setHeroBackground(url) {
1100
+ if (!this.heroBg) return;
1101
+ this.heroBg.style.backgroundImage = url ? `url("${url.replace(/"/g, "%22")}")` : "";
1102
+ this.heroBg.classList.toggle("pw-active", !!url);
1021
1103
  }
1022
1104
  updatePlayPauseState(playing) {
1023
1105
  if (this.playBtn) this.playBtn.style.display = playing ? "none" : "flex";
@@ -1104,4 +1186,5 @@ var FullPlayer = (_class5 = class extends EventEmitter {
1104
1186
 
1105
1187
 
1106
1188
 
1107
- exports.AudioEngine = AudioEngine; exports.DEFAULT_CONFIG = DEFAULT_CONFIG; exports.EventEmitter = EventEmitter; exports.FetchEpisodeProvider = FetchEpisodeProvider; exports.FullPlayer = FullPlayer; exports.ICONS = ICONS; exports.MiniPlayer = MiniPlayer; exports.PlaybackStorage = PlaybackStorage; exports.PlayerController = PlayerController; exports.PlayerStateStorage = PlayerStateStorage; exports.SPEED_OPTIONS = SPEED_OPTIONS; exports.escapeHtml = escapeHtml; exports.formatDate = formatDate; exports.formatDuration = formatDuration; exports.formatTime = formatTime; exports.getEpisodeImage = getEpisodeImage; exports.renderPlaylist = renderPlaylist; exports.renderPlaylistItem = renderPlaylistItem; exports.resolveConfig = resolveConfig;
1189
+
1190
+ exports.AudioEngine = AudioEngine; exports.DEFAULT_CONFIG = DEFAULT_CONFIG; exports.EventEmitter = EventEmitter; exports.FetchEpisodeProvider = FetchEpisodeProvider; exports.FullPlayer = FullPlayer; exports.ICONS = ICONS; exports.MiniPlayer = MiniPlayer; exports.PLAYER_STATE_VERSION = PLAYER_STATE_VERSION; exports.PlaybackStorage = PlaybackStorage; exports.PlayerController = PlayerController; exports.PlayerStateStorage = PlayerStateStorage; exports.SPEED_OPTIONS = SPEED_OPTIONS; exports.escapeHtml = escapeHtml; exports.formatDate = formatDate; exports.formatDuration = formatDuration; exports.formatTime = formatTime; exports.getEpisodeImage = getEpisodeImage; exports.renderPlaylist = renderPlaylist; exports.renderPlaylistItem = renderPlaylistItem; exports.resolveConfig = resolveConfig;