@arraypress/waveform-player 1.17.0 → 1.19.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.
@@ -64,6 +64,7 @@
64
64
  if (element.dataset.audioMode) options.audioMode = element.dataset.audioMode;
65
65
  if (element.dataset.style) options.waveformStyle = element.dataset.style;
66
66
  if (element.dataset.waveformStyle) options.waveformStyle = element.dataset.waveformStyle;
67
+ if (element.dataset.waveformGradient) options.waveformGradient = element.dataset.waveformGradient;
67
68
  setNum("barWidth");
68
69
  setNum("barSpacing");
69
70
  setNum("barRadius");
@@ -77,12 +78,6 @@
77
78
  if (element.dataset.colorPreset) options.colorPreset = element.dataset.colorPreset;
78
79
  if (element.dataset.waveformColor) options.waveformColor = parseColorValue(element.dataset.waveformColor);
79
80
  if (element.dataset.progressColor) options.progressColor = parseColorValue(element.dataset.progressColor);
80
- if (element.dataset.buttonColor) options.buttonColor = element.dataset.buttonColor;
81
- if (element.dataset.buttonHoverColor) options.buttonHoverColor = element.dataset.buttonHoverColor;
82
- if (element.dataset.textColor) options.textColor = element.dataset.textColor;
83
- if (element.dataset.textSecondaryColor) options.textSecondaryColor = element.dataset.textSecondaryColor;
84
- if (element.dataset.backgroundColor) options.backgroundColor = element.dataset.backgroundColor;
85
- if (element.dataset.borderColor) options.borderColor = element.dataset.borderColor;
86
81
  if (element.dataset.color) options.waveformColor = element.dataset.color;
87
82
  if (element.dataset.theme) options.colorPreset = element.dataset.theme;
88
83
  setBool("autoplay");
@@ -96,7 +91,7 @@
96
91
  setBool("singlePlay");
97
92
  setBool("playOnSeek");
98
93
  if (element.dataset.title) options.title = element.dataset.title;
99
- if (element.dataset.subtitle) options.subtitle = element.dataset.subtitle;
94
+ if (element.dataset.artist) options.artist = element.dataset.artist;
100
95
  if (element.dataset.album) options.album = element.dataset.album;
101
96
  if (element.dataset.artwork) options.artwork = element.dataset.artwork;
102
97
  if (element.dataset.waveform) options.waveform = element.dataset.waveform;
@@ -211,12 +206,20 @@
211
206
  }
212
207
 
213
208
  // src/js/drawing.js
214
- function makeFill(ctx, value, height) {
209
+ function makeFill(ctx, value, canvas, options) {
215
210
  if (!Array.isArray(value)) return value;
216
- if (value.length === 1) return value[0];
217
- const grad = ctx.createLinearGradient(0, 0, 0, height);
218
- value.forEach((c, i) => grad.addColorStop(i / (value.length - 1), c));
219
- return grad;
211
+ if (value.length < 2) return value[0];
212
+ const w = canvas.width;
213
+ const h = canvas.height;
214
+ const dir = options && options.waveformGradient;
215
+ const [x0, y0, x1, y1] = dir === "horizontal" ? [0, 0, w, 0] : dir === "diagonal" ? [0, 0, w, h] : [0, 0, 0, h];
216
+ try {
217
+ const grad = ctx.createLinearGradient(x0, y0, x1, y1);
218
+ value.forEach((c, i) => grad.addColorStop(i / (value.length - 1), c));
219
+ return grad;
220
+ } catch (e) {
221
+ return value[0];
222
+ }
220
223
  }
221
224
  function fillBar(ctx, x, y, w, h, radii) {
222
225
  const any = Array.isArray(radii) ? radii.some((r) => r > 0) : radii > 0;
@@ -256,8 +259,8 @@
256
259
  const height = canvas.height;
257
260
  const progressWidth = progress * canvas.width;
258
261
  const radii = barRadii(options, dpr);
259
- const baseFill = makeFill(ctx, options.color, height);
260
- const progFill = makeFill(ctx, options.progressColor, height);
262
+ const baseFill = makeFill(ctx, options.color, canvas, options);
263
+ const progFill = makeFill(ctx, options.progressColor, canvas, options);
261
264
  ctx.clearRect(0, 0, canvas.width, canvas.height);
262
265
  ctx.fillStyle = baseFill;
263
266
  for (let i = 0; i < resampledPeaks.length; i++) {
@@ -293,8 +296,8 @@
293
296
  const r = barRadiusPx(options, dpr);
294
297
  const topRadii = [r, r, 0, 0];
295
298
  const botRadii = [0, 0, r, r];
296
- const baseFill = makeFill(ctx, options.color, height);
297
- const progFill = makeFill(ctx, options.progressColor, height);
299
+ const baseFill = makeFill(ctx, options.color, canvas, options);
300
+ const progFill = makeFill(ctx, options.progressColor, canvas, options);
298
301
  ctx.clearRect(0, 0, canvas.width, canvas.height);
299
302
  ctx.fillStyle = baseFill;
300
303
  for (let i = 0; i < resampledPeaks.length; i++) {
@@ -325,11 +328,13 @@
325
328
  const amplitude = height * 0.35;
326
329
  ctx.clearRect(0, 0, width, height);
327
330
  const drawCurve = (color, lineWidth, endProgress = 1, addGlow = false) => {
331
+ const stroke = makeFill(ctx, color, canvas, options);
332
+ const solid = Array.isArray(color) ? color[color.length - 1] : color;
328
333
  if (addGlow) {
329
334
  ctx.shadowBlur = 12;
330
- ctx.shadowColor = color;
335
+ ctx.shadowColor = solid;
331
336
  }
332
- ctx.strokeStyle = color;
337
+ ctx.strokeStyle = stroke;
333
338
  ctx.lineWidth = lineWidth;
334
339
  ctx.lineCap = "round";
335
340
  ctx.lineJoin = "round";
@@ -385,8 +390,8 @@
385
390
  const blockGap = 2 * dpr;
386
391
  const progressWidth = progress * canvas.width;
387
392
  const centerY = height / 2;
388
- const baseFill = makeFill(ctx, options.color, height);
389
- const progFill = makeFill(ctx, options.progressColor, height);
393
+ const baseFill = makeFill(ctx, options.color, canvas, options);
394
+ const progFill = makeFill(ctx, options.progressColor, canvas, options);
390
395
  ctx.clearRect(0, 0, canvas.width, canvas.height);
391
396
  for (let i = 0; i < resampledPeaks.length; i++) {
392
397
  const x = i * (barWidth + barSpacing);
@@ -413,8 +418,8 @@
413
418
  const dotRadius = Math.max(1.5 * dpr, barWidth / 2);
414
419
  const progressWidth = progress * canvas.width;
415
420
  const centerY = height / 2;
416
- const baseFill = makeFill(ctx, options.color, height);
417
- const progFill = makeFill(ctx, options.progressColor, height);
421
+ const baseFill = makeFill(ctx, options.color, canvas, options);
422
+ const progFill = makeFill(ctx, options.progressColor, canvas, options);
418
423
  ctx.clearRect(0, 0, canvas.width, canvas.height);
419
424
  for (let i = 0; i < resampledPeaks.length; i++) {
420
425
  const x = i * (barWidth + barSpacing) + barWidth / 2;
@@ -437,14 +442,14 @@
437
442
  const borderRadius = barHeight / 2;
438
443
  const active = !!options.seekActive;
439
444
  ctx.clearRect(0, 0, width, height);
440
- ctx.fillStyle = options.color || "rgba(255, 255, 255, 0.2)";
445
+ ctx.fillStyle = makeFill(ctx, options.color, canvas, options) || "rgba(255, 255, 255, 0.2)";
441
446
  capsulePath(ctx, borderRadius, width, centerY, barHeight);
442
447
  ctx.fill();
443
448
  if (progress > 0) {
444
449
  const progressWidth = Math.max(borderRadius * 2, progress * width);
445
450
  ctx.save();
446
451
  ctx.globalAlpha = options.seekHandle && !active ? 0.7 : 1;
447
- ctx.fillStyle = options.progressColor || "rgba(255, 255, 255, 0.9)";
452
+ ctx.fillStyle = makeFill(ctx, options.progressColor, canvas, options) || "rgba(255, 255, 255, 0.9)";
448
453
  capsulePath(ctx, borderRadius, progressWidth, centerY, barHeight);
449
454
  ctx.fill();
450
455
  ctx.restore();
@@ -628,23 +633,11 @@
628
633
  var COLOR_PRESETS = {
629
634
  dark: {
630
635
  waveformColor: "rgba(255, 255, 255, 0.3)",
631
- progressColor: "rgba(255, 255, 255, 0.9)",
632
- buttonColor: "rgba(255, 255, 255, 0.9)",
633
- buttonHoverColor: "rgba(255, 255, 255, 1)",
634
- textColor: "#ffffff",
635
- textSecondaryColor: "rgba(255, 255, 255, 0.6)",
636
- backgroundColor: "rgba(255, 255, 255, 0.03)",
637
- borderColor: "rgba(255, 255, 255, 0.1)"
636
+ progressColor: "rgba(255, 255, 255, 0.9)"
638
637
  },
639
638
  light: {
640
639
  waveformColor: "rgba(0, 0, 0, 0.2)",
641
- progressColor: "rgba(0, 0, 0, 0.8)",
642
- buttonColor: "rgba(0, 0, 0, 0.8)",
643
- buttonHoverColor: "rgba(0, 0, 0, 0.9)",
644
- textColor: "#333333",
645
- textSecondaryColor: "rgba(0, 0, 0, 0.6)",
646
- backgroundColor: "rgba(0, 0, 0, 0.02)",
647
- borderColor: "rgba(0, 0, 0, 0.1)"
640
+ progressColor: "rgba(0, 0, 0, 0.8)"
648
641
  }
649
642
  };
650
643
  function getColorPreset(presetName) {
@@ -697,17 +690,18 @@
697
690
  barSpacing: 0,
698
691
  // Rounded bar caps (px). 0 = square; 1 = soft caps (default). Applies to bars/mirror.
699
692
  barRadius: 1,
693
+ // Gradient axis when waveformColor/progressColor is an array of stops:
694
+ // 'vertical' (top->bottom canvas gradient), 'horizontal' (hue sweep across the
695
+ // waveform) or 'diagonal'. Ignored for single colours.
696
+ waveformGradient: "vertical",
700
697
  // Color preset: null = auto-detect, 'dark' = force dark, 'light' = force light
701
698
  colorPreset: null,
702
- // Individual color overrides (null means use preset)
699
+ // Canvas colours (null = inherit the resolved preset; arrays = gradient
700
+ // stops, see waveformGradient). The DOM chrome (button, title, meta) is
701
+ // themed via CSS variables (--wfp-button-color / --wfp-text-color /
702
+ // --wfp-text-secondary-color), not JS options.
703
703
  waveformColor: null,
704
704
  progressColor: null,
705
- buttonColor: null,
706
- buttonHoverColor: null,
707
- textColor: null,
708
- textSecondaryColor: null,
709
- backgroundColor: null,
710
- borderColor: null,
711
705
  // Features
712
706
  autoplay: false,
713
707
  showControls: true,
@@ -737,7 +731,7 @@
737
731
  seekLabel: null,
738
732
  // Content
739
733
  title: null,
740
- subtitle: null,
734
+ artist: null,
741
735
  artwork: null,
742
736
  album: "",
743
737
  // Message shown in the error state when audio fails to load.
@@ -751,7 +745,12 @@
751
745
  onPause: null,
752
746
  onEnd: null,
753
747
  onError: null,
754
- onTimeUpdate: null
748
+ onTimeUpdate: null,
749
+ // Optional queue navigation — when set, the player registers Media Session
750
+ // nexttrack/previoustrack handlers (lock-screen skip buttons). Called with
751
+ // the player instance; wired by waveform-bar / -playlist.
752
+ onNextTrack: null,
753
+ onPreviousTrack: null
755
754
  };
756
755
  var STYLE_DEFAULTS = {
757
756
  bars: { barWidth: 3, barSpacing: 1 },
@@ -804,6 +803,7 @@
804
803
  const preset = getColorPreset(this.options.colorPreset);
805
804
  this._autoTheme = this.options.colorPreset == null || !COLOR_PRESETS[this.options.colorPreset];
806
805
  this._presetKeys = [];
806
+ this._scheme = this.options.colorPreset && COLOR_PRESETS[this.options.colorPreset] ? this.options.colorPreset : detectColorScheme();
807
807
  for (const [key, value] of Object.entries(preset)) {
808
808
  if (this.options[key] === null || this.options[key] === void 0) {
809
809
  this.options[key] = value;
@@ -910,7 +910,7 @@
910
910
  *
911
911
  * Clears the container, resolves button alignment (`auto` → `bottom` for
912
912
  * the `bars` style, `center` otherwise), and conditionally renders the play
913
- * button, info row (artwork/title/subtitle), BPM badge, playback-speed
913
+ * button, info row (artwork/title/artist), BPM badge, playback-speed
914
914
  * menu, and time display based on the relevant `show*` options. Caches the
915
915
  * canvas, controls, and text elements onto `this`, then sizes the canvas.
916
916
  * @private
@@ -931,12 +931,9 @@
931
931
  if (isPreview) {
932
932
  this.container.classList.add("waveform-layout-preview");
933
933
  }
934
+ this.container.classList.toggle("waveform-theme-light", this._scheme === "light");
934
935
  const buttonHTML = this.options.showControls ? `
935
- <button class="waveform-btn${this.options.buttonStyle === "minimal" ? " waveform-btn-minimal" : ""}" aria-label="Play/Pause" style="
936
- border-color: ${this.options.buttonColor};
937
- color: ${this.options.buttonColor};
938
- ${this.options.buttonSize != null ? `--wfp-btn-size: ${typeof this.options.buttonSize === "number" ? `${this.options.buttonSize}px` : this.options.buttonSize};` : ""}
939
- ">
936
+ <button class="waveform-btn${this.options.buttonStyle === "minimal" ? " waveform-btn-minimal" : ""}" aria-label="Play/Pause"${this.options.buttonSize != null ? ` style="--wfp-btn-size: ${typeof this.options.buttonSize === "number" ? `${this.options.buttonSize}px` : this.options.buttonSize};"` : ""}>
940
937
  <span class="waveform-icon-play">${this.options.playIcon}</span>
941
938
  <span class="waveform-icon-pause" style="display:none;">${this.options.pauseIcon}</span>
942
939
  </button>
@@ -953,12 +950,12 @@
953
950
  ">
954
951
  ` : ""}
955
952
  <div class="waveform-text">
956
- <span class="waveform-title" style="color: ${this.options.textColor};"></span>
957
- ${this.options.subtitle ? `<span class="waveform-subtitle" style="color: ${this.options.textSecondaryColor};">${this.options.subtitle}</span>` : ""}
953
+ <span class="waveform-title"></span>
954
+ ${this.options.artist ? `<span class="waveform-artist">${this.options.artist}</span>` : ""}
958
955
  </div>
959
956
  <div class="waveform-meta" style="display: flex; align-items: center; gap: 1rem;">
960
957
  ${this.options.showBPM ? `
961
- <span class="waveform-bpm" style="color: ${this.options.textSecondaryColor}; display: none;">
958
+ <span class="waveform-bpm" style="display: none;">
962
959
  <span class="bpm-value">--</span> BPM
963
960
  </span>
964
961
  ` : ""}
@@ -975,7 +972,7 @@
975
972
  </div>
976
973
  ` : ""}
977
974
  ${this.options.showTime ? `
978
- <span class="waveform-time" style="color: ${this.options.textSecondaryColor};">
975
+ <span class="waveform-time">
979
976
  <span class="time-current">0:00</span> / <span class="time-total">0:00</span>
980
977
  </span>
981
978
  ` : ""}
@@ -1006,7 +1003,7 @@
1006
1003
  this.canvas = this.container.querySelector("canvas");
1007
1004
  this.ctx = this.canvas.getContext("2d");
1008
1005
  this.titleEl = this.container.querySelector(".waveform-title");
1009
- this.subtitleEl = this.container.querySelector(".waveform-subtitle");
1006
+ this.artistEl = this.container.querySelector(".waveform-artist");
1010
1007
  this.artworkEl = this.container.querySelector(".waveform-artwork");
1011
1008
  if (this.artworkEl) {
1012
1009
  this.artworkEl.addEventListener("error", () => {
@@ -1167,6 +1164,12 @@
1167
1164
  this.applySeekLabel();
1168
1165
  this.updateSeekAccessibility();
1169
1166
  this.seekEl.addEventListener("keydown", (e) => {
1167
+ if (e.key === " " || e.key === "Spacebar") {
1168
+ e.preventDefault();
1169
+ e.stopPropagation();
1170
+ this.togglePlay();
1171
+ return;
1172
+ }
1170
1173
  const duration = this.getSeekDuration();
1171
1174
  if (!duration) return;
1172
1175
  const current = this.getSeekCurrentTime();
@@ -1279,14 +1282,7 @@
1279
1282
  initMediaSession() {
1280
1283
  if (!("mediaSession" in navigator) || !this.options.enableMediaSession) return;
1281
1284
  if (!this.audio) return;
1282
- navigator.mediaSession.metadata = new MediaMetadata({
1283
- title: this.options.title || "Unknown Track",
1284
- artist: this.options.subtitle || "",
1285
- album: this.options.album || "",
1286
- artwork: this.options.artwork ? [
1287
- { src: this.options.artwork, sizes: "512x512", type: "image/jpeg" }
1288
- ] : []
1289
- });
1285
+ this._applyMediaMetadata();
1290
1286
  navigator.mediaSession.setActionHandler("play", () => this.play());
1291
1287
  navigator.mediaSession.setActionHandler("pause", () => this.pause());
1292
1288
  navigator.mediaSession.setActionHandler("seekbackward", () => {
@@ -1300,6 +1296,54 @@
1300
1296
  this.seekTo(details.seekTime);
1301
1297
  }
1302
1298
  });
1299
+ const onNext = this.options.onNextTrack, onPrev = this.options.onPreviousTrack;
1300
+ try {
1301
+ navigator.mediaSession.setActionHandler("nexttrack", typeof onNext === "function" ? () => onNext(this) : null);
1302
+ } catch (e) {
1303
+ }
1304
+ try {
1305
+ navigator.mediaSession.setActionHandler("previoustrack", typeof onPrev === "function" ? () => onPrev(this) : null);
1306
+ } catch (e) {
1307
+ }
1308
+ }
1309
+ /**
1310
+ * Publish the current track's Media Session metadata (lock-screen /
1311
+ * Now-Playing title, artist, album, artwork). Idempotent — safe to re-call.
1312
+ * @private
1313
+ */
1314
+ _applyMediaMetadata() {
1315
+ if (!("mediaSession" in navigator) || !this.options.enableMediaSession) return;
1316
+ navigator.mediaSession.metadata = new MediaMetadata({
1317
+ title: this.options.title || "Unknown Track",
1318
+ artist: this.options.artist || "",
1319
+ album: this.options.album || "",
1320
+ artwork: this.options.artwork ? [
1321
+ { src: this.options.artwork, sizes: "512x512", type: "image/jpeg" }
1322
+ ] : []
1323
+ });
1324
+ }
1325
+ /**
1326
+ * Sync Media Session playback state + scrubber position on play/pause. iOS
1327
+ * ignores metadata set before the media is active, so we re-assert it on
1328
+ * play — that's what fixes the blank lock-screen card on mobile.
1329
+ * @param {'playing'|'paused'} state
1330
+ * @private
1331
+ */
1332
+ _updateMediaSession(state) {
1333
+ if (!("mediaSession" in navigator) || !this.options.enableMediaSession || !this.audio) return;
1334
+ try {
1335
+ if (state === "playing") this._applyMediaMetadata();
1336
+ navigator.mediaSession.playbackState = state;
1337
+ const d = this.audio.duration;
1338
+ if (navigator.mediaSession.setPositionState && d && isFinite(d)) {
1339
+ navigator.mediaSession.setPositionState({
1340
+ duration: d,
1341
+ playbackRate: this.audio.playbackRate || 1,
1342
+ position: clamp(this.audio.currentTime, 0, d)
1343
+ });
1344
+ }
1345
+ } catch (e) {
1346
+ }
1303
1347
  }
1304
1348
  // ============================================
1305
1349
  // Event Binding
@@ -1363,12 +1407,13 @@
1363
1407
  const endDrag = (e) => {
1364
1408
  if (!this._dragging) return;
1365
1409
  this._dragging = false;
1410
+ this._suppressClick = true;
1366
1411
  try {
1367
1412
  this.canvas.releasePointerCapture(e.pointerId);
1368
1413
  } catch (err) {
1369
1414
  }
1370
1415
  this._seekFromPointer(e.clientX);
1371
- if (!this._seekHover) this._hideHoverTip();
1416
+ if (!this._seekHover && !this.options.showHoverTime) this._hideHoverTip();
1372
1417
  this._updateSeekHandle();
1373
1418
  };
1374
1419
  this.canvas.addEventListener("pointerup", endDrag);
@@ -1471,19 +1516,19 @@
1471
1516
  *
1472
1517
  * Pauses any current playback, fully resets the audio element (self mode),
1473
1518
  * clears error/marker/progress state, merges the new metadata into
1474
- * `this.options`, updates the subtitle/artwork DOM, then calls
1519
+ * `this.options`, updates the artist/artwork DOM, then calls
1475
1520
  * {@link WaveformPlayer#load}. Auto-plays the new track unless
1476
1521
  * `options.autoplay === false`.
1477
1522
  * @param {string} url - Audio URL.
1478
1523
  * @param {string|null} [title=null] - Track title; keeps the existing
1479
1524
  * title when null.
1480
- * @param {string|null} [subtitle=null] - Track subtitle; pass `''` to hide
1481
- * the subtitle row, or null to keep the existing one.
1525
+ * @param {string|null} [artist=null] - Track artist; pass `''` to hide
1526
+ * the artist row, or null to keep the existing one.
1482
1527
  * @param {Object} [options={}] - Additional options to merge (e.g.
1483
1528
  * `preload`, `artwork`, `markers`, `autoplay`).
1484
1529
  * @returns {Promise<void>}
1485
1530
  */
1486
- async loadTrack(url, title = null, subtitle = null, options = {}) {
1531
+ async loadTrack(url, title = null, artist = null, options = {}) {
1487
1532
  if (this.isPlaying) {
1488
1533
  this.pause();
1489
1534
  }
@@ -1506,18 +1551,18 @@
1506
1551
  this.options = mergeOptions(this.options, {
1507
1552
  url,
1508
1553
  title: title || this.options.title,
1509
- subtitle: subtitle || this.options.subtitle,
1554
+ artist: artist || this.options.artist,
1510
1555
  ...options
1511
1556
  });
1512
1557
  if (options.preload && this.audio) {
1513
1558
  this.audio.preload = options.preload;
1514
1559
  }
1515
- if (this.subtitleEl) {
1516
- if (subtitle) {
1517
- this.subtitleEl.textContent = subtitle;
1518
- this.subtitleEl.style.display = "";
1519
- } else if (subtitle === "") {
1520
- this.subtitleEl.style.display = "none";
1560
+ if (this.artistEl) {
1561
+ if (artist) {
1562
+ this.artistEl.textContent = artist;
1563
+ this.artistEl.style.display = "";
1564
+ } else if (artist === "") {
1565
+ this.artistEl.style.display = "none";
1521
1566
  }
1522
1567
  }
1523
1568
  if (options.artwork && this.artworkEl) {
@@ -1700,19 +1745,20 @@
1700
1745
  }
1701
1746
  }
1702
1747
  /**
1703
- * Build a tooltip that follows the pointer over the waveform and shows the
1704
- * time at that position. Enabled by the `showHoverTime` option; works in both
1748
+ * Build the time tooltip that follows the pointer over the waveform. The
1749
+ * element is always created so **drag-scrub** can show the time you're
1750
+ * dragging to; the *hover* reveal is gated on `showHoverTime`. Works in both
1705
1751
  * self and external modes (it only needs {@link WaveformPlayer#getSeekDuration}).
1706
- * Uses the same pointer-X → percentage math as seeking.
1707
1752
  * @private
1708
1753
  */
1709
1754
  setupHoverTime() {
1710
- if (!this.options.showHoverTime || !this.seekEl) return;
1755
+ if (!this.seekEl) return;
1711
1756
  const tip = document.createElement("div");
1712
1757
  tip.className = "waveform-hover-time";
1713
1758
  tip.setAttribute("aria-hidden", "true");
1714
1759
  this.seekEl.appendChild(tip);
1715
1760
  this.hoverTimeEl = tip;
1761
+ if (!this.options.showHoverTime) return;
1716
1762
  this.seekEl.addEventListener("pointermove", (e) => {
1717
1763
  if (!this._dragging) this._updateHoverTip(e.clientX);
1718
1764
  });
@@ -1759,6 +1805,10 @@
1759
1805
  this.drawWaveform();
1760
1806
  this._updateSeekHandle();
1761
1807
  this._updateHoverTip(clientX);
1808
+ const dur = this.getSeekDuration();
1809
+ if (dur && this.currentTimeEl) {
1810
+ this.currentTimeEl.textContent = formatTime(this.progress * dur);
1811
+ }
1762
1812
  }
1763
1813
  /**
1764
1814
  * Create the draggable seek handle — a DOM circle over the playhead, shown
@@ -1802,6 +1852,10 @@
1802
1852
  * @fires WaveformPlayer#waveformplayer:request-seek
1803
1853
  */
1804
1854
  handleCanvasClick(event) {
1855
+ if (this._suppressClick) {
1856
+ this._suppressClick = false;
1857
+ return;
1858
+ }
1805
1859
  this._seekFromPointer(event.clientX);
1806
1860
  }
1807
1861
  /**
@@ -1885,6 +1939,7 @@
1885
1939
  this.isPlaying = true;
1886
1940
  this.setPlayButtonState(true);
1887
1941
  this.startSmoothUpdate();
1942
+ this._updateMediaSession("playing");
1888
1943
  this._emit("waveformplayer:play", { player: this, url: this.options.url });
1889
1944
  if (this.options.onPlay) {
1890
1945
  this.options.onPlay(this);
@@ -1903,6 +1958,7 @@
1903
1958
  this.isPlaying = false;
1904
1959
  this.setPlayButtonState(false);
1905
1960
  this.stopSmoothUpdate();
1961
+ this._updateMediaSession("paused");
1906
1962
  this._emit("waveformplayer:pause", { player: this, url: this.options.url });
1907
1963
  if (this.options.onPause) {
1908
1964
  this.options.onPause(this);
@@ -2045,33 +2101,21 @@
2045
2101
  * @public
2046
2102
  */
2047
2103
  refreshTheme() {
2048
- if (!this._autoTheme || !this._presetKeys || !this._presetKeys.length) return;
2104
+ if (!this._autoTheme) return;
2105
+ this._scheme = detectColorScheme();
2049
2106
  const preset = getColorPreset(this.options.colorPreset);
2050
- let changed = false;
2051
- for (const key of this._presetKeys) {
2052
- if (this.options[key] !== preset[key]) {
2053
- this.options[key] = preset[key];
2054
- changed = true;
2055
- }
2107
+ for (const key of this._presetKeys || []) {
2108
+ if (key in preset) this.options[key] = preset[key];
2056
2109
  }
2057
- if (changed) this._applyThemeColors();
2110
+ this._applyThemeColors();
2058
2111
  }
2059
2112
  /**
2060
- * Push the current resolved colours onto the live DOM (button border/icon,
2061
- * title, subtitle, time, BPM) and redraw the waveform.
2113
+ * Sync the theme class (CSS drives the DOM chrome colours via `--wfp-*`
2114
+ * variables) and redraw the canvas with the resolved waveform colours.
2062
2115
  * @private
2063
2116
  */
2064
2117
  _applyThemeColors() {
2065
- const o = this.options;
2066
- if (this.playBtn) {
2067
- this.playBtn.style.borderColor = o.buttonColor;
2068
- this.playBtn.style.color = o.buttonColor;
2069
- }
2070
- if (this.titleEl) this.titleEl.style.color = o.textColor;
2071
- if (this.subtitleEl) this.subtitleEl.style.color = o.textSecondaryColor;
2072
- this.container.querySelectorAll(".waveform-time, .waveform-bpm").forEach((el) => {
2073
- el.style.color = o.textSecondaryColor;
2074
- });
2118
+ this.container.classList.toggle("waveform-theme-light", this._scheme === "light");
2075
2119
  if (this.canvas) this.drawWaveform();
2076
2120
  }
2077
2121
  /**
@@ -2185,16 +2229,13 @@
2185
2229
  * directly: `WaveformBar.play(event.detail)`.
2186
2230
  *
2187
2231
  * @private
2188
- * @return {{url:string,title:?string,subtitle:?string,artist:?string,artwork:?string,player:WaveformPlayer}}
2232
+ * @return {{url:string,title:?string,artist:?string,artwork:?string,player:WaveformPlayer}}
2189
2233
  */
2190
2234
  _buildTrackDetail() {
2191
2235
  return {
2192
2236
  url: this.options.url,
2193
2237
  title: this.options.title,
2194
- subtitle: this.options.subtitle,
2195
- // Core has no separate `artist` option; mirror subtitle so the
2196
- // published event detail is self-consistent for controllers.
2197
- artist: this.options.artist || this.options.subtitle,
2238
+ artist: this.options.artist,
2198
2239
  artwork: this.options.artwork,
2199
2240
  markers: this.options.markers,
2200
2241
  waveform: this.options.waveform,