@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.
@@ -89,6 +89,7 @@ function parseDataAttributes(element) {
89
89
  if (element.dataset.audioMode) options.audioMode = element.dataset.audioMode;
90
90
  if (element.dataset.style) options.waveformStyle = element.dataset.style;
91
91
  if (element.dataset.waveformStyle) options.waveformStyle = element.dataset.waveformStyle;
92
+ if (element.dataset.waveformGradient) options.waveformGradient = element.dataset.waveformGradient;
92
93
  setNum("barWidth");
93
94
  setNum("barSpacing");
94
95
  setNum("barRadius");
@@ -102,12 +103,6 @@ function parseDataAttributes(element) {
102
103
  if (element.dataset.colorPreset) options.colorPreset = element.dataset.colorPreset;
103
104
  if (element.dataset.waveformColor) options.waveformColor = parseColorValue(element.dataset.waveformColor);
104
105
  if (element.dataset.progressColor) options.progressColor = parseColorValue(element.dataset.progressColor);
105
- if (element.dataset.buttonColor) options.buttonColor = element.dataset.buttonColor;
106
- if (element.dataset.buttonHoverColor) options.buttonHoverColor = element.dataset.buttonHoverColor;
107
- if (element.dataset.textColor) options.textColor = element.dataset.textColor;
108
- if (element.dataset.textSecondaryColor) options.textSecondaryColor = element.dataset.textSecondaryColor;
109
- if (element.dataset.backgroundColor) options.backgroundColor = element.dataset.backgroundColor;
110
- if (element.dataset.borderColor) options.borderColor = element.dataset.borderColor;
111
106
  if (element.dataset.color) options.waveformColor = element.dataset.color;
112
107
  if (element.dataset.theme) options.colorPreset = element.dataset.theme;
113
108
  setBool("autoplay");
@@ -121,7 +116,7 @@ function parseDataAttributes(element) {
121
116
  setBool("singlePlay");
122
117
  setBool("playOnSeek");
123
118
  if (element.dataset.title) options.title = element.dataset.title;
124
- if (element.dataset.subtitle) options.subtitle = element.dataset.subtitle;
119
+ if (element.dataset.artist) options.artist = element.dataset.artist;
125
120
  if (element.dataset.album) options.album = element.dataset.album;
126
121
  if (element.dataset.artwork) options.artwork = element.dataset.artwork;
127
122
  if (element.dataset.waveform) options.waveform = element.dataset.waveform;
@@ -236,12 +231,20 @@ function resampleData(data, targetLength) {
236
231
  }
237
232
 
238
233
  // src/js/drawing.js
239
- function makeFill(ctx, value, height) {
234
+ function makeFill(ctx, value, canvas, options) {
240
235
  if (!Array.isArray(value)) return value;
241
- if (value.length === 1) return value[0];
242
- const grad = ctx.createLinearGradient(0, 0, 0, height);
243
- value.forEach((c, i) => grad.addColorStop(i / (value.length - 1), c));
244
- return grad;
236
+ if (value.length < 2) return value[0];
237
+ const w = canvas.width;
238
+ const h = canvas.height;
239
+ const dir = options && options.waveformGradient;
240
+ const [x0, y0, x1, y1] = dir === "horizontal" ? [0, 0, w, 0] : dir === "diagonal" ? [0, 0, w, h] : [0, 0, 0, h];
241
+ try {
242
+ const grad = ctx.createLinearGradient(x0, y0, x1, y1);
243
+ value.forEach((c, i) => grad.addColorStop(i / (value.length - 1), c));
244
+ return grad;
245
+ } catch (e) {
246
+ return value[0];
247
+ }
245
248
  }
246
249
  function fillBar(ctx, x, y, w, h, radii) {
247
250
  const any = Array.isArray(radii) ? radii.some((r) => r > 0) : radii > 0;
@@ -281,8 +284,8 @@ function drawBars(ctx, canvas, peaks, progress, options) {
281
284
  const height = canvas.height;
282
285
  const progressWidth = progress * canvas.width;
283
286
  const radii = barRadii(options, dpr);
284
- const baseFill = makeFill(ctx, options.color, height);
285
- const progFill = makeFill(ctx, options.progressColor, height);
287
+ const baseFill = makeFill(ctx, options.color, canvas, options);
288
+ const progFill = makeFill(ctx, options.progressColor, canvas, options);
286
289
  ctx.clearRect(0, 0, canvas.width, canvas.height);
287
290
  ctx.fillStyle = baseFill;
288
291
  for (let i = 0; i < resampledPeaks.length; i++) {
@@ -318,8 +321,8 @@ function drawMirror(ctx, canvas, peaks, progress, options) {
318
321
  const r = barRadiusPx(options, dpr);
319
322
  const topRadii = [r, r, 0, 0];
320
323
  const botRadii = [0, 0, r, r];
321
- const baseFill = makeFill(ctx, options.color, height);
322
- const progFill = makeFill(ctx, options.progressColor, height);
324
+ const baseFill = makeFill(ctx, options.color, canvas, options);
325
+ const progFill = makeFill(ctx, options.progressColor, canvas, options);
323
326
  ctx.clearRect(0, 0, canvas.width, canvas.height);
324
327
  ctx.fillStyle = baseFill;
325
328
  for (let i = 0; i < resampledPeaks.length; i++) {
@@ -350,11 +353,13 @@ function drawLine(ctx, canvas, peaks, progress, options) {
350
353
  const amplitude = height * 0.35;
351
354
  ctx.clearRect(0, 0, width, height);
352
355
  const drawCurve = (color, lineWidth, endProgress = 1, addGlow = false) => {
356
+ const stroke = makeFill(ctx, color, canvas, options);
357
+ const solid = Array.isArray(color) ? color[color.length - 1] : color;
353
358
  if (addGlow) {
354
359
  ctx.shadowBlur = 12;
355
- ctx.shadowColor = color;
360
+ ctx.shadowColor = solid;
356
361
  }
357
- ctx.strokeStyle = color;
362
+ ctx.strokeStyle = stroke;
358
363
  ctx.lineWidth = lineWidth;
359
364
  ctx.lineCap = "round";
360
365
  ctx.lineJoin = "round";
@@ -410,8 +415,8 @@ function drawBlocks(ctx, canvas, peaks, progress, options) {
410
415
  const blockGap = 2 * dpr;
411
416
  const progressWidth = progress * canvas.width;
412
417
  const centerY = height / 2;
413
- const baseFill = makeFill(ctx, options.color, height);
414
- const progFill = makeFill(ctx, options.progressColor, height);
418
+ const baseFill = makeFill(ctx, options.color, canvas, options);
419
+ const progFill = makeFill(ctx, options.progressColor, canvas, options);
415
420
  ctx.clearRect(0, 0, canvas.width, canvas.height);
416
421
  for (let i = 0; i < resampledPeaks.length; i++) {
417
422
  const x = i * (barWidth + barSpacing);
@@ -438,8 +443,8 @@ function drawDots(ctx, canvas, peaks, progress, options) {
438
443
  const dotRadius = Math.max(1.5 * dpr, barWidth / 2);
439
444
  const progressWidth = progress * canvas.width;
440
445
  const centerY = height / 2;
441
- const baseFill = makeFill(ctx, options.color, height);
442
- const progFill = makeFill(ctx, options.progressColor, height);
446
+ const baseFill = makeFill(ctx, options.color, canvas, options);
447
+ const progFill = makeFill(ctx, options.progressColor, canvas, options);
443
448
  ctx.clearRect(0, 0, canvas.width, canvas.height);
444
449
  for (let i = 0; i < resampledPeaks.length; i++) {
445
450
  const x = i * (barWidth + barSpacing) + barWidth / 2;
@@ -462,14 +467,14 @@ function drawSeekbar(ctx, canvas, peaks, progress, options) {
462
467
  const borderRadius = barHeight / 2;
463
468
  const active = !!options.seekActive;
464
469
  ctx.clearRect(0, 0, width, height);
465
- ctx.fillStyle = options.color || "rgba(255, 255, 255, 0.2)";
470
+ ctx.fillStyle = makeFill(ctx, options.color, canvas, options) || "rgba(255, 255, 255, 0.2)";
466
471
  capsulePath(ctx, borderRadius, width, centerY, barHeight);
467
472
  ctx.fill();
468
473
  if (progress > 0) {
469
474
  const progressWidth = Math.max(borderRadius * 2, progress * width);
470
475
  ctx.save();
471
476
  ctx.globalAlpha = options.seekHandle && !active ? 0.7 : 1;
472
- ctx.fillStyle = options.progressColor || "rgba(255, 255, 255, 0.9)";
477
+ ctx.fillStyle = makeFill(ctx, options.progressColor, canvas, options) || "rgba(255, 255, 255, 0.9)";
473
478
  capsulePath(ctx, borderRadius, progressWidth, centerY, barHeight);
474
479
  ctx.fill();
475
480
  ctx.restore();
@@ -653,23 +658,11 @@ function detectColorScheme() {
653
658
  var COLOR_PRESETS = {
654
659
  dark: {
655
660
  waveformColor: "rgba(255, 255, 255, 0.3)",
656
- progressColor: "rgba(255, 255, 255, 0.9)",
657
- buttonColor: "rgba(255, 255, 255, 0.9)",
658
- buttonHoverColor: "rgba(255, 255, 255, 1)",
659
- textColor: "#ffffff",
660
- textSecondaryColor: "rgba(255, 255, 255, 0.6)",
661
- backgroundColor: "rgba(255, 255, 255, 0.03)",
662
- borderColor: "rgba(255, 255, 255, 0.1)"
661
+ progressColor: "rgba(255, 255, 255, 0.9)"
663
662
  },
664
663
  light: {
665
664
  waveformColor: "rgba(0, 0, 0, 0.2)",
666
- progressColor: "rgba(0, 0, 0, 0.8)",
667
- buttonColor: "rgba(0, 0, 0, 0.8)",
668
- buttonHoverColor: "rgba(0, 0, 0, 0.9)",
669
- textColor: "#333333",
670
- textSecondaryColor: "rgba(0, 0, 0, 0.6)",
671
- backgroundColor: "rgba(0, 0, 0, 0.02)",
672
- borderColor: "rgba(0, 0, 0, 0.1)"
665
+ progressColor: "rgba(0, 0, 0, 0.8)"
673
666
  }
674
667
  };
675
668
  function getColorPreset(presetName) {
@@ -722,17 +715,18 @@ var DEFAULT_OPTIONS = {
722
715
  barSpacing: 0,
723
716
  // Rounded bar caps (px). 0 = square; 1 = soft caps (default). Applies to bars/mirror.
724
717
  barRadius: 1,
718
+ // Gradient axis when waveformColor/progressColor is an array of stops:
719
+ // 'vertical' (top->bottom canvas gradient), 'horizontal' (hue sweep across the
720
+ // waveform) or 'diagonal'. Ignored for single colours.
721
+ waveformGradient: "vertical",
725
722
  // Color preset: null = auto-detect, 'dark' = force dark, 'light' = force light
726
723
  colorPreset: null,
727
- // Individual color overrides (null means use preset)
724
+ // Canvas colours (null = inherit the resolved preset; arrays = gradient
725
+ // stops, see waveformGradient). The DOM chrome (button, title, meta) is
726
+ // themed via CSS variables (--wfp-button-color / --wfp-text-color /
727
+ // --wfp-text-secondary-color), not JS options.
728
728
  waveformColor: null,
729
729
  progressColor: null,
730
- buttonColor: null,
731
- buttonHoverColor: null,
732
- textColor: null,
733
- textSecondaryColor: null,
734
- backgroundColor: null,
735
- borderColor: null,
736
730
  // Features
737
731
  autoplay: false,
738
732
  showControls: true,
@@ -762,7 +756,7 @@ var DEFAULT_OPTIONS = {
762
756
  seekLabel: null,
763
757
  // Content
764
758
  title: null,
765
- subtitle: null,
759
+ artist: null,
766
760
  artwork: null,
767
761
  album: "",
768
762
  // Message shown in the error state when audio fails to load.
@@ -776,7 +770,12 @@ var DEFAULT_OPTIONS = {
776
770
  onPause: null,
777
771
  onEnd: null,
778
772
  onError: null,
779
- onTimeUpdate: null
773
+ onTimeUpdate: null,
774
+ // Optional queue navigation — when set, the player registers Media Session
775
+ // nexttrack/previoustrack handlers (lock-screen skip buttons). Called with
776
+ // the player instance; wired by waveform-bar / -playlist.
777
+ onNextTrack: null,
778
+ onPreviousTrack: null
780
779
  };
781
780
  var STYLE_DEFAULTS = {
782
781
  bars: { barWidth: 3, barSpacing: 1 },
@@ -829,6 +828,7 @@ var WaveformPlayer = class _WaveformPlayer {
829
828
  const preset = getColorPreset(this.options.colorPreset);
830
829
  this._autoTheme = this.options.colorPreset == null || !COLOR_PRESETS[this.options.colorPreset];
831
830
  this._presetKeys = [];
831
+ this._scheme = this.options.colorPreset && COLOR_PRESETS[this.options.colorPreset] ? this.options.colorPreset : detectColorScheme();
832
832
  for (const [key, value] of Object.entries(preset)) {
833
833
  if (this.options[key] === null || this.options[key] === void 0) {
834
834
  this.options[key] = value;
@@ -935,7 +935,7 @@ var WaveformPlayer = class _WaveformPlayer {
935
935
  *
936
936
  * Clears the container, resolves button alignment (`auto` → `bottom` for
937
937
  * the `bars` style, `center` otherwise), and conditionally renders the play
938
- * button, info row (artwork/title/subtitle), BPM badge, playback-speed
938
+ * button, info row (artwork/title/artist), BPM badge, playback-speed
939
939
  * menu, and time display based on the relevant `show*` options. Caches the
940
940
  * canvas, controls, and text elements onto `this`, then sizes the canvas.
941
941
  * @private
@@ -956,12 +956,9 @@ var WaveformPlayer = class _WaveformPlayer {
956
956
  if (isPreview) {
957
957
  this.container.classList.add("waveform-layout-preview");
958
958
  }
959
+ this.container.classList.toggle("waveform-theme-light", this._scheme === "light");
959
960
  const buttonHTML = this.options.showControls ? `
960
- <button class="waveform-btn${this.options.buttonStyle === "minimal" ? " waveform-btn-minimal" : ""}" aria-label="Play/Pause" style="
961
- border-color: ${this.options.buttonColor};
962
- color: ${this.options.buttonColor};
963
- ${this.options.buttonSize != null ? `--wfp-btn-size: ${typeof this.options.buttonSize === "number" ? `${this.options.buttonSize}px` : this.options.buttonSize};` : ""}
964
- ">
961
+ <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};"` : ""}>
965
962
  <span class="waveform-icon-play">${this.options.playIcon}</span>
966
963
  <span class="waveform-icon-pause" style="display:none;">${this.options.pauseIcon}</span>
967
964
  </button>
@@ -978,12 +975,12 @@ var WaveformPlayer = class _WaveformPlayer {
978
975
  ">
979
976
  ` : ""}
980
977
  <div class="waveform-text">
981
- <span class="waveform-title" style="color: ${this.options.textColor};"></span>
982
- ${this.options.subtitle ? `<span class="waveform-subtitle" style="color: ${this.options.textSecondaryColor};">${this.options.subtitle}</span>` : ""}
978
+ <span class="waveform-title"></span>
979
+ ${this.options.artist ? `<span class="waveform-artist">${this.options.artist}</span>` : ""}
983
980
  </div>
984
981
  <div class="waveform-meta" style="display: flex; align-items: center; gap: 1rem;">
985
982
  ${this.options.showBPM ? `
986
- <span class="waveform-bpm" style="color: ${this.options.textSecondaryColor}; display: none;">
983
+ <span class="waveform-bpm" style="display: none;">
987
984
  <span class="bpm-value">--</span> BPM
988
985
  </span>
989
986
  ` : ""}
@@ -1000,7 +997,7 @@ var WaveformPlayer = class _WaveformPlayer {
1000
997
  </div>
1001
998
  ` : ""}
1002
999
  ${this.options.showTime ? `
1003
- <span class="waveform-time" style="color: ${this.options.textSecondaryColor};">
1000
+ <span class="waveform-time">
1004
1001
  <span class="time-current">0:00</span> / <span class="time-total">0:00</span>
1005
1002
  </span>
1006
1003
  ` : ""}
@@ -1031,7 +1028,7 @@ var WaveformPlayer = class _WaveformPlayer {
1031
1028
  this.canvas = this.container.querySelector("canvas");
1032
1029
  this.ctx = this.canvas.getContext("2d");
1033
1030
  this.titleEl = this.container.querySelector(".waveform-title");
1034
- this.subtitleEl = this.container.querySelector(".waveform-subtitle");
1031
+ this.artistEl = this.container.querySelector(".waveform-artist");
1035
1032
  this.artworkEl = this.container.querySelector(".waveform-artwork");
1036
1033
  if (this.artworkEl) {
1037
1034
  this.artworkEl.addEventListener("error", () => {
@@ -1192,6 +1189,12 @@ var WaveformPlayer = class _WaveformPlayer {
1192
1189
  this.applySeekLabel();
1193
1190
  this.updateSeekAccessibility();
1194
1191
  this.seekEl.addEventListener("keydown", (e) => {
1192
+ if (e.key === " " || e.key === "Spacebar") {
1193
+ e.preventDefault();
1194
+ e.stopPropagation();
1195
+ this.togglePlay();
1196
+ return;
1197
+ }
1195
1198
  const duration = this.getSeekDuration();
1196
1199
  if (!duration) return;
1197
1200
  const current = this.getSeekCurrentTime();
@@ -1304,14 +1307,7 @@ var WaveformPlayer = class _WaveformPlayer {
1304
1307
  initMediaSession() {
1305
1308
  if (!("mediaSession" in navigator) || !this.options.enableMediaSession) return;
1306
1309
  if (!this.audio) return;
1307
- navigator.mediaSession.metadata = new MediaMetadata({
1308
- title: this.options.title || "Unknown Track",
1309
- artist: this.options.subtitle || "",
1310
- album: this.options.album || "",
1311
- artwork: this.options.artwork ? [
1312
- { src: this.options.artwork, sizes: "512x512", type: "image/jpeg" }
1313
- ] : []
1314
- });
1310
+ this._applyMediaMetadata();
1315
1311
  navigator.mediaSession.setActionHandler("play", () => this.play());
1316
1312
  navigator.mediaSession.setActionHandler("pause", () => this.pause());
1317
1313
  navigator.mediaSession.setActionHandler("seekbackward", () => {
@@ -1325,6 +1321,54 @@ var WaveformPlayer = class _WaveformPlayer {
1325
1321
  this.seekTo(details.seekTime);
1326
1322
  }
1327
1323
  });
1324
+ const onNext = this.options.onNextTrack, onPrev = this.options.onPreviousTrack;
1325
+ try {
1326
+ navigator.mediaSession.setActionHandler("nexttrack", typeof onNext === "function" ? () => onNext(this) : null);
1327
+ } catch (e) {
1328
+ }
1329
+ try {
1330
+ navigator.mediaSession.setActionHandler("previoustrack", typeof onPrev === "function" ? () => onPrev(this) : null);
1331
+ } catch (e) {
1332
+ }
1333
+ }
1334
+ /**
1335
+ * Publish the current track's Media Session metadata (lock-screen /
1336
+ * Now-Playing title, artist, album, artwork). Idempotent — safe to re-call.
1337
+ * @private
1338
+ */
1339
+ _applyMediaMetadata() {
1340
+ if (!("mediaSession" in navigator) || !this.options.enableMediaSession) return;
1341
+ navigator.mediaSession.metadata = new MediaMetadata({
1342
+ title: this.options.title || "Unknown Track",
1343
+ artist: this.options.artist || "",
1344
+ album: this.options.album || "",
1345
+ artwork: this.options.artwork ? [
1346
+ { src: this.options.artwork, sizes: "512x512", type: "image/jpeg" }
1347
+ ] : []
1348
+ });
1349
+ }
1350
+ /**
1351
+ * Sync Media Session playback state + scrubber position on play/pause. iOS
1352
+ * ignores metadata set before the media is active, so we re-assert it on
1353
+ * play — that's what fixes the blank lock-screen card on mobile.
1354
+ * @param {'playing'|'paused'} state
1355
+ * @private
1356
+ */
1357
+ _updateMediaSession(state) {
1358
+ if (!("mediaSession" in navigator) || !this.options.enableMediaSession || !this.audio) return;
1359
+ try {
1360
+ if (state === "playing") this._applyMediaMetadata();
1361
+ navigator.mediaSession.playbackState = state;
1362
+ const d = this.audio.duration;
1363
+ if (navigator.mediaSession.setPositionState && d && isFinite(d)) {
1364
+ navigator.mediaSession.setPositionState({
1365
+ duration: d,
1366
+ playbackRate: this.audio.playbackRate || 1,
1367
+ position: clamp(this.audio.currentTime, 0, d)
1368
+ });
1369
+ }
1370
+ } catch (e) {
1371
+ }
1328
1372
  }
1329
1373
  // ============================================
1330
1374
  // Event Binding
@@ -1388,12 +1432,13 @@ var WaveformPlayer = class _WaveformPlayer {
1388
1432
  const endDrag = (e) => {
1389
1433
  if (!this._dragging) return;
1390
1434
  this._dragging = false;
1435
+ this._suppressClick = true;
1391
1436
  try {
1392
1437
  this.canvas.releasePointerCapture(e.pointerId);
1393
1438
  } catch (err) {
1394
1439
  }
1395
1440
  this._seekFromPointer(e.clientX);
1396
- if (!this._seekHover) this._hideHoverTip();
1441
+ if (!this._seekHover && !this.options.showHoverTime) this._hideHoverTip();
1397
1442
  this._updateSeekHandle();
1398
1443
  };
1399
1444
  this.canvas.addEventListener("pointerup", endDrag);
@@ -1496,19 +1541,19 @@ var WaveformPlayer = class _WaveformPlayer {
1496
1541
  *
1497
1542
  * Pauses any current playback, fully resets the audio element (self mode),
1498
1543
  * clears error/marker/progress state, merges the new metadata into
1499
- * `this.options`, updates the subtitle/artwork DOM, then calls
1544
+ * `this.options`, updates the artist/artwork DOM, then calls
1500
1545
  * {@link WaveformPlayer#load}. Auto-plays the new track unless
1501
1546
  * `options.autoplay === false`.
1502
1547
  * @param {string} url - Audio URL.
1503
1548
  * @param {string|null} [title=null] - Track title; keeps the existing
1504
1549
  * title when null.
1505
- * @param {string|null} [subtitle=null] - Track subtitle; pass `''` to hide
1506
- * the subtitle row, or null to keep the existing one.
1550
+ * @param {string|null} [artist=null] - Track artist; pass `''` to hide
1551
+ * the artist row, or null to keep the existing one.
1507
1552
  * @param {Object} [options={}] - Additional options to merge (e.g.
1508
1553
  * `preload`, `artwork`, `markers`, `autoplay`).
1509
1554
  * @returns {Promise<void>}
1510
1555
  */
1511
- async loadTrack(url, title = null, subtitle = null, options = {}) {
1556
+ async loadTrack(url, title = null, artist = null, options = {}) {
1512
1557
  if (this.isPlaying) {
1513
1558
  this.pause();
1514
1559
  }
@@ -1531,18 +1576,18 @@ var WaveformPlayer = class _WaveformPlayer {
1531
1576
  this.options = mergeOptions(this.options, {
1532
1577
  url,
1533
1578
  title: title || this.options.title,
1534
- subtitle: subtitle || this.options.subtitle,
1579
+ artist: artist || this.options.artist,
1535
1580
  ...options
1536
1581
  });
1537
1582
  if (options.preload && this.audio) {
1538
1583
  this.audio.preload = options.preload;
1539
1584
  }
1540
- if (this.subtitleEl) {
1541
- if (subtitle) {
1542
- this.subtitleEl.textContent = subtitle;
1543
- this.subtitleEl.style.display = "";
1544
- } else if (subtitle === "") {
1545
- this.subtitleEl.style.display = "none";
1585
+ if (this.artistEl) {
1586
+ if (artist) {
1587
+ this.artistEl.textContent = artist;
1588
+ this.artistEl.style.display = "";
1589
+ } else if (artist === "") {
1590
+ this.artistEl.style.display = "none";
1546
1591
  }
1547
1592
  }
1548
1593
  if (options.artwork && this.artworkEl) {
@@ -1725,19 +1770,20 @@ var WaveformPlayer = class _WaveformPlayer {
1725
1770
  }
1726
1771
  }
1727
1772
  /**
1728
- * Build a tooltip that follows the pointer over the waveform and shows the
1729
- * time at that position. Enabled by the `showHoverTime` option; works in both
1773
+ * Build the time tooltip that follows the pointer over the waveform. The
1774
+ * element is always created so **drag-scrub** can show the time you're
1775
+ * dragging to; the *hover* reveal is gated on `showHoverTime`. Works in both
1730
1776
  * self and external modes (it only needs {@link WaveformPlayer#getSeekDuration}).
1731
- * Uses the same pointer-X → percentage math as seeking.
1732
1777
  * @private
1733
1778
  */
1734
1779
  setupHoverTime() {
1735
- if (!this.options.showHoverTime || !this.seekEl) return;
1780
+ if (!this.seekEl) return;
1736
1781
  const tip = document.createElement("div");
1737
1782
  tip.className = "waveform-hover-time";
1738
1783
  tip.setAttribute("aria-hidden", "true");
1739
1784
  this.seekEl.appendChild(tip);
1740
1785
  this.hoverTimeEl = tip;
1786
+ if (!this.options.showHoverTime) return;
1741
1787
  this.seekEl.addEventListener("pointermove", (e) => {
1742
1788
  if (!this._dragging) this._updateHoverTip(e.clientX);
1743
1789
  });
@@ -1784,6 +1830,10 @@ var WaveformPlayer = class _WaveformPlayer {
1784
1830
  this.drawWaveform();
1785
1831
  this._updateSeekHandle();
1786
1832
  this._updateHoverTip(clientX);
1833
+ const dur = this.getSeekDuration();
1834
+ if (dur && this.currentTimeEl) {
1835
+ this.currentTimeEl.textContent = formatTime(this.progress * dur);
1836
+ }
1787
1837
  }
1788
1838
  /**
1789
1839
  * Create the draggable seek handle — a DOM circle over the playhead, shown
@@ -1827,6 +1877,10 @@ var WaveformPlayer = class _WaveformPlayer {
1827
1877
  * @fires WaveformPlayer#waveformplayer:request-seek
1828
1878
  */
1829
1879
  handleCanvasClick(event) {
1880
+ if (this._suppressClick) {
1881
+ this._suppressClick = false;
1882
+ return;
1883
+ }
1830
1884
  this._seekFromPointer(event.clientX);
1831
1885
  }
1832
1886
  /**
@@ -1910,6 +1964,7 @@ var WaveformPlayer = class _WaveformPlayer {
1910
1964
  this.isPlaying = true;
1911
1965
  this.setPlayButtonState(true);
1912
1966
  this.startSmoothUpdate();
1967
+ this._updateMediaSession("playing");
1913
1968
  this._emit("waveformplayer:play", { player: this, url: this.options.url });
1914
1969
  if (this.options.onPlay) {
1915
1970
  this.options.onPlay(this);
@@ -1928,6 +1983,7 @@ var WaveformPlayer = class _WaveformPlayer {
1928
1983
  this.isPlaying = false;
1929
1984
  this.setPlayButtonState(false);
1930
1985
  this.stopSmoothUpdate();
1986
+ this._updateMediaSession("paused");
1931
1987
  this._emit("waveformplayer:pause", { player: this, url: this.options.url });
1932
1988
  if (this.options.onPause) {
1933
1989
  this.options.onPause(this);
@@ -2070,33 +2126,21 @@ var WaveformPlayer = class _WaveformPlayer {
2070
2126
  * @public
2071
2127
  */
2072
2128
  refreshTheme() {
2073
- if (!this._autoTheme || !this._presetKeys || !this._presetKeys.length) return;
2129
+ if (!this._autoTheme) return;
2130
+ this._scheme = detectColorScheme();
2074
2131
  const preset = getColorPreset(this.options.colorPreset);
2075
- let changed = false;
2076
- for (const key of this._presetKeys) {
2077
- if (this.options[key] !== preset[key]) {
2078
- this.options[key] = preset[key];
2079
- changed = true;
2080
- }
2132
+ for (const key of this._presetKeys || []) {
2133
+ if (key in preset) this.options[key] = preset[key];
2081
2134
  }
2082
- if (changed) this._applyThemeColors();
2135
+ this._applyThemeColors();
2083
2136
  }
2084
2137
  /**
2085
- * Push the current resolved colours onto the live DOM (button border/icon,
2086
- * title, subtitle, time, BPM) and redraw the waveform.
2138
+ * Sync the theme class (CSS drives the DOM chrome colours via `--wfp-*`
2139
+ * variables) and redraw the canvas with the resolved waveform colours.
2087
2140
  * @private
2088
2141
  */
2089
2142
  _applyThemeColors() {
2090
- const o = this.options;
2091
- if (this.playBtn) {
2092
- this.playBtn.style.borderColor = o.buttonColor;
2093
- this.playBtn.style.color = o.buttonColor;
2094
- }
2095
- if (this.titleEl) this.titleEl.style.color = o.textColor;
2096
- if (this.subtitleEl) this.subtitleEl.style.color = o.textSecondaryColor;
2097
- this.container.querySelectorAll(".waveform-time, .waveform-bpm").forEach((el) => {
2098
- el.style.color = o.textSecondaryColor;
2099
- });
2143
+ this.container.classList.toggle("waveform-theme-light", this._scheme === "light");
2100
2144
  if (this.canvas) this.drawWaveform();
2101
2145
  }
2102
2146
  /**
@@ -2210,16 +2254,13 @@ var WaveformPlayer = class _WaveformPlayer {
2210
2254
  * directly: `WaveformBar.play(event.detail)`.
2211
2255
  *
2212
2256
  * @private
2213
- * @return {{url:string,title:?string,subtitle:?string,artist:?string,artwork:?string,player:WaveformPlayer}}
2257
+ * @return {{url:string,title:?string,artist:?string,artwork:?string,player:WaveformPlayer}}
2214
2258
  */
2215
2259
  _buildTrackDetail() {
2216
2260
  return {
2217
2261
  url: this.options.url,
2218
2262
  title: this.options.title,
2219
- subtitle: this.options.subtitle,
2220
- // Core has no separate `artist` option; mirror subtitle so the
2221
- // published event detail is self-consistent for controllers.
2222
- artist: this.options.artist || this.options.subtitle,
2263
+ artist: this.options.artist,
2223
2264
  artwork: this.options.artwork,
2224
2265
  markers: this.options.markers,
2225
2266
  waveform: this.options.waveform,