@dudgy/podcast-widget 0.1.1 → 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 +31 -5
- package/dist/index.cjs +207 -105
- package/dist/index.d.cts +34 -5
- package/dist/index.d.ts +34 -5
- package/dist/index.js +176 -74
- package/dist/podcast-player.css +170 -36
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -198,10 +198,11 @@ var PlaybackStorage = class {
|
|
|
198
198
|
} catch (e4) {
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
|
|
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(
|
|
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
|
-
|
|
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,19 +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
|
-
|
|
377
|
-
|
|
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
|
-
playlist: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z"/></svg>'
|
|
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>',
|
|
450
|
+
download: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"/></svg>'
|
|
383
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
|
+
}
|
|
384
461
|
var SPEED_OPTIONS = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3];
|
|
385
462
|
function renderPlaylistItem(episode, index, opts) {
|
|
386
463
|
const imageUrl = getEpisodeImage(episode);
|
|
@@ -396,7 +473,7 @@ function renderPlaylistItem(episode, index, opts) {
|
|
|
396
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>` : "";
|
|
397
474
|
return `
|
|
398
475
|
<div class="pw-playlist-item ${opts.isPlaying ? "pw-playing" : ""} ${hasSaved ? "pw-has-saved" : ""}" data-index="${index}">
|
|
399
|
-
${
|
|
476
|
+
${renderArtwork("pw-episode-image", imageUrl)}
|
|
400
477
|
<div class="pw-episode-info">
|
|
401
478
|
<div class="pw-episode-show">${escapeHtml(episode.feedName || "Unknown Show")}</div>
|
|
402
479
|
<div class="pw-episode-title">${escapeHtml(episode.title)}</div>
|
|
@@ -405,6 +482,7 @@ function renderPlaylistItem(episode, index, opts) {
|
|
|
405
482
|
</div>
|
|
406
483
|
<div class="pw-episode-actions">
|
|
407
484
|
<div class="pw-episode-duration">${escapeHtml(duration)}</div>
|
|
485
|
+
<a href="${escapeHtml(episode.audioUrl)}" download="${escapeHtml(episode.title)}" target="_blank" class="pw-download-btn" title="Download episode" data-download>${ICONS.download}</a>
|
|
408
486
|
${feedLinkHtml}
|
|
409
487
|
</div>
|
|
410
488
|
</div>
|
|
@@ -431,11 +509,14 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
431
509
|
|
|
432
510
|
|
|
433
511
|
__init4() {this.episodes = []}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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 = []}
|
|
437
518
|
constructor(engine, provider, config) {
|
|
438
|
-
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);;
|
|
439
520
|
this.config = resolveConfig(config);
|
|
440
521
|
this.engine = engine;
|
|
441
522
|
this.provider = provider;
|
|
@@ -446,12 +527,12 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
446
527
|
this.engine.playbackRate = savedSpeed;
|
|
447
528
|
}
|
|
448
529
|
const savedState = this.stateStorage.loadState();
|
|
449
|
-
if (_optionalChain([savedState, 'optionalAccess',
|
|
530
|
+
if (_optionalChain([savedState, 'optionalAccess', _17 => _17.volume]) != null) {
|
|
450
531
|
this.engine.volume = savedState.volume;
|
|
451
532
|
}
|
|
452
533
|
this.engine.on("ended", () => {
|
|
453
|
-
if (this.
|
|
454
|
-
this.storage.removePosition(this.
|
|
534
|
+
if (this.currentEpisode) {
|
|
535
|
+
this.storage.removePosition(this.currentEpisode.id);
|
|
455
536
|
}
|
|
456
537
|
this.stopPositionSaving();
|
|
457
538
|
});
|
|
@@ -465,11 +546,17 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
465
546
|
// ─── Episode management ────────────────────────────────────────
|
|
466
547
|
async loadEpisodes() {
|
|
467
548
|
this.episodes = await this.provider.getEpisodes();
|
|
468
|
-
|
|
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);
|
|
469
553
|
this.emit("episodes-loaded", { episodes: this.episodes });
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
this.loadEpisode(
|
|
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);
|
|
473
560
|
}
|
|
474
561
|
return this.episodes;
|
|
475
562
|
}
|
|
@@ -477,21 +564,22 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
477
564
|
return this.episodes;
|
|
478
565
|
}
|
|
479
566
|
getCurrentEpisode() {
|
|
480
|
-
return this.
|
|
567
|
+
return this.currentEpisode;
|
|
481
568
|
}
|
|
569
|
+
/** Index of the current episode in the list, or -1 if none or not listed. */
|
|
482
570
|
getCurrentIndex() {
|
|
483
571
|
return this.currentIndex;
|
|
484
572
|
}
|
|
485
573
|
loadEpisode(index, autoPlay = false) {
|
|
486
574
|
if (index < 0 || index >= this.episodes.length) return;
|
|
487
|
-
|
|
575
|
+
this.select(this.episodes[index], index, autoPlay);
|
|
576
|
+
}
|
|
577
|
+
select(episode, index, autoPlay) {
|
|
578
|
+
this.currentEpisode = episode;
|
|
488
579
|
this.currentIndex = index;
|
|
489
580
|
const savedPosition = this.storage.getPosition(episode.id);
|
|
490
581
|
this.engine.load(episode.audioUrl, _nullishCoalesce(savedPosition, () => ( void 0)));
|
|
491
|
-
this.
|
|
492
|
-
currentEpisodeIndex: this.currentIndex,
|
|
493
|
-
volume: this.engine.volume
|
|
494
|
-
});
|
|
582
|
+
this.persistState();
|
|
495
583
|
this.emit("episode-change", { episode, index });
|
|
496
584
|
this.emit("episode-display", {
|
|
497
585
|
imageUrl: getEpisodeImage(episode),
|
|
@@ -506,9 +594,8 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
506
594
|
this.loadEpisode(index, true);
|
|
507
595
|
}
|
|
508
596
|
async play() {
|
|
509
|
-
if (this.
|
|
510
|
-
|
|
511
|
-
this.playEpisode(0);
|
|
597
|
+
if (!this.currentEpisode) {
|
|
598
|
+
if (this.episodes.length > 0) this.playEpisode(0);
|
|
512
599
|
return;
|
|
513
600
|
}
|
|
514
601
|
await this.engine.play();
|
|
@@ -524,9 +611,13 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
524
611
|
}
|
|
525
612
|
setVolume(v) {
|
|
526
613
|
this.engine.volume = v;
|
|
614
|
+
this.persistState();
|
|
615
|
+
}
|
|
616
|
+
persistState() {
|
|
527
617
|
this.stateStorage.saveState({
|
|
528
|
-
|
|
529
|
-
|
|
618
|
+
v: PLAYER_STATE_VERSION,
|
|
619
|
+
episode: this.currentEpisode,
|
|
620
|
+
volume: this.engine.volume
|
|
530
621
|
});
|
|
531
622
|
}
|
|
532
623
|
getPlaylistHtml(feedPageUrl) {
|
|
@@ -552,8 +643,8 @@ var PlayerController = (_class3 = class extends EventEmitter {
|
|
|
552
643
|
}
|
|
553
644
|
}
|
|
554
645
|
saveCurrentPosition() {
|
|
555
|
-
|
|
556
|
-
|
|
646
|
+
const episode = this.currentEpisode;
|
|
647
|
+
if (!episode || !this.engine.hasSrc) return;
|
|
557
648
|
if (this.engine.currentTime > 10) {
|
|
558
649
|
this.storage.savePosition(episode.id, this.engine.currentTime, episode.duration);
|
|
559
650
|
}
|
|
@@ -574,19 +665,19 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
574
665
|
|
|
575
666
|
|
|
576
667
|
|
|
577
|
-
|
|
668
|
+
__init9() {this.cleanupFns = []}
|
|
578
669
|
// Element references (created during render)
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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}
|
|
588
679
|
constructor(opts) {
|
|
589
|
-
super();_class4.prototype.
|
|
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);;
|
|
590
681
|
this.container = opts.container;
|
|
591
682
|
this.controller = opts.controller;
|
|
592
683
|
this.controls = {
|
|
@@ -602,16 +693,16 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
602
693
|
const c = this.controls;
|
|
603
694
|
let controlsHtml = "";
|
|
604
695
|
if (c.skipBackward) {
|
|
605
|
-
controlsHtml +=
|
|
696
|
+
controlsHtml += renderSkipButton("back", this.controller.config.skipSeconds, "pw-btn--mini");
|
|
606
697
|
}
|
|
607
698
|
if (c.playPause) {
|
|
608
699
|
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>
|
|
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>
|
|
611
702
|
`;
|
|
612
703
|
}
|
|
613
704
|
if (c.skipForward) {
|
|
614
|
-
controlsHtml +=
|
|
705
|
+
controlsHtml += renderSkipButton("fwd", this.controller.config.skipSeconds, "pw-btn--mini");
|
|
615
706
|
}
|
|
616
707
|
if (c.volume) {
|
|
617
708
|
controlsHtml += `
|
|
@@ -637,7 +728,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
637
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>` : "";
|
|
638
729
|
this.container.innerHTML = `
|
|
639
730
|
<div class="pw-mini">
|
|
640
|
-
|
|
731
|
+
${renderArtwork("pw-mini-artwork")}
|
|
641
732
|
<div class="pw-mini-info">
|
|
642
733
|
<div class="pw-mini-title">No episode playing</div>
|
|
643
734
|
<div class="pw-mini-show"></div>
|
|
@@ -647,7 +738,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
647
738
|
</div>
|
|
648
739
|
${c.playlist ? '<div class="pw-mini-playlist" style="display:none"></div>' : ""}
|
|
649
740
|
`;
|
|
650
|
-
this.artworkEl = this.container.querySelector(".pw-mini-artwork");
|
|
741
|
+
this.artworkEl = this.container.querySelector(".pw-mini-artwork img");
|
|
651
742
|
this.titleEl = this.container.querySelector(".pw-mini-title");
|
|
652
743
|
this.showEl = this.container.querySelector(".pw-mini-show");
|
|
653
744
|
this.playBtn = this.container.querySelector(".pw-play-btn");
|
|
@@ -658,6 +749,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
658
749
|
}
|
|
659
750
|
bindEvents() {
|
|
660
751
|
const { engine } = this.controller;
|
|
752
|
+
this.cleanupFns.push(hideBrokenImages(this.container));
|
|
661
753
|
this.addClick(".pw-play-btn", () => this.controller.play());
|
|
662
754
|
this.addClick(".pw-pause-btn", () => this.controller.pause());
|
|
663
755
|
this.addClick(".pw-btn--skip-back", () => engine.skipBackward());
|
|
@@ -673,7 +765,8 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
673
765
|
engine.seekToPercentage(Math.max(0, Math.min(100, pct)));
|
|
674
766
|
};
|
|
675
767
|
this.progressContainer.addEventListener("click", handler);
|
|
676
|
-
this.cleanupFns.push(() => _optionalChain([this, 'access',
|
|
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));
|
|
677
770
|
}
|
|
678
771
|
const onTimeUpdate = (d) => {
|
|
679
772
|
if (this.progressBar) {
|
|
@@ -717,14 +810,7 @@ var MiniPlayer = (_class4 = class extends EventEmitter {
|
|
|
717
810
|
const imageUrl = getEpisodeImage(episode);
|
|
718
811
|
if (this.titleEl) this.titleEl.textContent = episode.title;
|
|
719
812
|
if (this.showEl) this.showEl.textContent = episode.feedName;
|
|
720
|
-
|
|
721
|
-
if (imageUrl) {
|
|
722
|
-
this.artworkEl.src = imageUrl;
|
|
723
|
-
this.artworkEl.style.display = "block";
|
|
724
|
-
} else {
|
|
725
|
-
this.artworkEl.style.display = "none";
|
|
726
|
-
}
|
|
727
|
-
}
|
|
813
|
+
setArtwork(this.artworkEl, imageUrl);
|
|
728
814
|
}
|
|
729
815
|
updatePlayPauseState(playing) {
|
|
730
816
|
if (this.playBtn) this.playBtn.style.display = playing ? "none" : "flex";
|
|
@@ -791,19 +877,19 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
791
877
|
|
|
792
878
|
|
|
793
879
|
|
|
794
|
-
|
|
880
|
+
__init19() {this.cleanupFns = []}
|
|
795
881
|
// Element references
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
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}
|
|
805
891
|
constructor(opts) {
|
|
806
|
-
super();_class5.prototype.
|
|
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);;
|
|
807
893
|
this.container = opts.container;
|
|
808
894
|
this.backdrop = _nullishCoalesce(opts.backdrop, () => ( null));
|
|
809
895
|
this.controller = opts.controller;
|
|
@@ -815,6 +901,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
815
901
|
speed: true,
|
|
816
902
|
progress: true,
|
|
817
903
|
playlist: true,
|
|
904
|
+
download: true,
|
|
818
905
|
...opts.controls
|
|
819
906
|
};
|
|
820
907
|
this.feedPageUrl = opts.feedPageUrl;
|
|
@@ -842,7 +929,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
842
929
|
const c = this.controls;
|
|
843
930
|
let mainControlsHtml = "";
|
|
844
931
|
if (c.skipBackward) {
|
|
845
|
-
mainControlsHtml +=
|
|
932
|
+
mainControlsHtml += renderSkipButton("back", this.controller.config.skipSeconds);
|
|
846
933
|
}
|
|
847
934
|
if (c.playPause) {
|
|
848
935
|
mainControlsHtml += `
|
|
@@ -851,7 +938,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
851
938
|
`;
|
|
852
939
|
}
|
|
853
940
|
if (c.skipForward) {
|
|
854
|
-
mainControlsHtml +=
|
|
941
|
+
mainControlsHtml += renderSkipButton("fwd", this.controller.config.skipSeconds);
|
|
855
942
|
}
|
|
856
943
|
let secondaryHtml = "";
|
|
857
944
|
if (c.volume) {
|
|
@@ -869,6 +956,9 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
869
956
|
).join("");
|
|
870
957
|
secondaryHtml += `<select class="pw-speed-select" aria-label="Playback speed">${options}</select>`;
|
|
871
958
|
}
|
|
959
|
+
if (c.download) {
|
|
960
|
+
secondaryHtml += `<button class="pw-btn pw-btn--download" aria-label="Download episode">${ICONS.download}</button>`;
|
|
961
|
+
}
|
|
872
962
|
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
963
|
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
964
|
this.container.innerHTML = `
|
|
@@ -876,7 +966,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
876
966
|
<div class="pw-hero-bg"></div>
|
|
877
967
|
<button class="pw-btn-close" aria-label="Minimize player">${ICONS.close}</button>
|
|
878
968
|
<div class="pw-now-playing">
|
|
879
|
-
|
|
969
|
+
${renderArtwork("pw-artwork")}
|
|
880
970
|
<div class="pw-track-info">
|
|
881
971
|
<div class="pw-track-name" aria-live="polite">Select an episode to play</div>
|
|
882
972
|
<div class="pw-track-time" aria-live="off">00:00 / 00:00</div>
|
|
@@ -890,7 +980,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
890
980
|
</div>
|
|
891
981
|
${playlistHtml}
|
|
892
982
|
`;
|
|
893
|
-
this.artworkEl = this.container.querySelector(".pw-artwork");
|
|
983
|
+
this.artworkEl = this.container.querySelector(".pw-artwork img");
|
|
894
984
|
this.trackNameEl = this.container.querySelector(".pw-track-name");
|
|
895
985
|
this.trackTimeEl = this.container.querySelector(".pw-track-time");
|
|
896
986
|
this.playBtn = this.container.querySelector(".pw-play-btn");
|
|
@@ -902,11 +992,18 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
902
992
|
}
|
|
903
993
|
bindEvents() {
|
|
904
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
|
+
}
|
|
905
1002
|
this.addClick(".pw-btn-close", () => this.hide());
|
|
906
1003
|
if (this.backdrop) {
|
|
907
1004
|
const handler = () => this.hide();
|
|
908
1005
|
this.backdrop.addEventListener("click", handler);
|
|
909
|
-
this.cleanupFns.push(() => _optionalChain([this, 'access',
|
|
1006
|
+
this.cleanupFns.push(() => _optionalChain([this, 'access', _25 => _25.backdrop, 'optionalAccess', _26 => _26.removeEventListener, 'call', _27 => _27("click", handler)]));
|
|
910
1007
|
}
|
|
911
1008
|
const feedLinkHandler = (e) => {
|
|
912
1009
|
if (e.target.closest("[data-feed-link]")) this.hide();
|
|
@@ -919,6 +1016,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
919
1016
|
this.addClick(".pw-btn--skip-fwd", () => engine.skipForward());
|
|
920
1017
|
this.addInput(".pw-volume-slider", (val) => this.controller.setVolume(parseInt(val) / 100));
|
|
921
1018
|
this.addChange(".pw-speed-select", (val) => this.controller.setSpeed(parseFloat(val)));
|
|
1019
|
+
this.addClick(".pw-btn--download", () => this.downloadCurrentEpisode());
|
|
922
1020
|
if (this.progressContainer) {
|
|
923
1021
|
const handler = (e) => {
|
|
924
1022
|
const rect = this.progressContainer.getBoundingClientRect();
|
|
@@ -926,7 +1024,8 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
926
1024
|
engine.seekToPercentage(Math.max(0, Math.min(100, pct)));
|
|
927
1025
|
};
|
|
928
1026
|
this.progressContainer.addEventListener("click", handler);
|
|
929
|
-
this.cleanupFns.push(() => _optionalChain([this, 'access',
|
|
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));
|
|
930
1029
|
}
|
|
931
1030
|
const onKeyDown = (e) => {
|
|
932
1031
|
if (!this.isVisible) return;
|
|
@@ -994,23 +1093,13 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
994
1093
|
if (this.trackNameEl) {
|
|
995
1094
|
this.trackNameEl.textContent = `${episode.feedName}: ${episode.title}`;
|
|
996
1095
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
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
|
-
}
|
|
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);
|
|
1014
1103
|
}
|
|
1015
1104
|
updatePlayPauseState(playing) {
|
|
1016
1105
|
if (this.playBtn) this.playBtn.style.display = playing ? "none" : "flex";
|
|
@@ -1025,7 +1114,7 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
1025
1114
|
if (!this.playlistEl) return;
|
|
1026
1115
|
this.playlistEl.querySelectorAll(".pw-playlist-item").forEach((item) => {
|
|
1027
1116
|
item.addEventListener("click", (e) => {
|
|
1028
|
-
if (e.target.closest("[data-feed-link]")) return;
|
|
1117
|
+
if (e.target.closest("[data-feed-link]") || e.target.closest("[data-download]")) return;
|
|
1029
1118
|
const index = parseInt(item.dataset.index || "0");
|
|
1030
1119
|
this.controller.playEpisode(index);
|
|
1031
1120
|
});
|
|
@@ -1037,6 +1126,18 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
1037
1126
|
item.classList.toggle("pw-playing", i === index);
|
|
1038
1127
|
});
|
|
1039
1128
|
}
|
|
1129
|
+
// ─── Download ────────────────────────────────────────────────
|
|
1130
|
+
downloadCurrentEpisode() {
|
|
1131
|
+
const episode = this.controller.getCurrentEpisode();
|
|
1132
|
+
if (!episode) return;
|
|
1133
|
+
const a = document.createElement("a");
|
|
1134
|
+
a.href = episode.audioUrl;
|
|
1135
|
+
a.target = "_blank";
|
|
1136
|
+
a.download = episode.title || "episode";
|
|
1137
|
+
document.body.appendChild(a);
|
|
1138
|
+
a.click();
|
|
1139
|
+
document.body.removeChild(a);
|
|
1140
|
+
}
|
|
1040
1141
|
// ─── Helpers ───────────────────────────────────────────────────
|
|
1041
1142
|
addClick(selector, handler) {
|
|
1042
1143
|
const el = this.container.querySelector(selector);
|
|
@@ -1085,4 +1186,5 @@ var FullPlayer = (_class5 = class extends EventEmitter {
|
|
|
1085
1186
|
|
|
1086
1187
|
|
|
1087
1188
|
|
|
1088
|
-
|
|
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;
|