@arraypress/waveform-player 1.17.0 → 1.18.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
@@ -104,7 +104,7 @@ In zero-config markup, pass a gradient as a JSON array: `data-waveform-color='["
104
104
  <div data-waveform-player
105
105
  data-url="track.mp3"
106
106
  data-title="My Song"
107
- data-subtitle="Artist Name"
107
+ data-artist="Artist Name"
108
108
  data-waveform-style="mirror"
109
109
  data-bar-radius="3"
110
110
  data-show-playback-speed="true"
@@ -156,7 +156,7 @@ const player = new WaveformPlayer('#player', {
156
156
  | `audioMode` | `'self' \| 'external'`| `'self'` | Own the `<audio>`, or delegate (see below) |
157
157
  | `markers` | `WaveformMarker[]` | `[]` | Chapter markers |
158
158
  | `showControls` | `boolean` | `true` | Show the play/pause button |
159
- | `showInfo` | `boolean` | `true` | Show title/subtitle/time |
159
+ | `showInfo` | `boolean` | `true` | Show title/artist/time |
160
160
  | `showPlaybackSpeed` | `boolean` | `false` | Show the speed menu |
161
161
  | `showBPM` | `boolean` | `false` | Detect + display BPM |
162
162
  | `autoplay` | `boolean` | `false` | Play on load |
@@ -227,7 +227,7 @@ Set `audioMode: 'external'` and the player becomes a visualization-only surface:
227
227
  const player = new WaveformPlayer(el, { audioMode: 'external' });
228
228
 
229
229
  el.addEventListener('waveformplayer:request-play', (e) => {
230
- audio.src = e.detail.url; // e.detail = { url, title, subtitle, artist, artwork, id, player }
230
+ audio.src = e.detail.url; // e.detail = { url, title, artist, artwork, id, player }
231
231
  audio.play();
232
232
  });
233
233
  audio.addEventListener('timeupdate', () => player.setProgress(audio.currentTime, audio.duration));
@@ -237,7 +237,7 @@ audio.addEventListener('pause', () => player.setPlayingState(false));
237
237
 
238
238
  | Event | Detail |
239
239
  | ------------------------------ | --------------------------------------------------- |
240
- | `waveformplayer:request-play` | `{ url, title, subtitle, artist, artwork, id, player }` |
240
+ | `waveformplayer:request-play` | `{ url, title, artist, artwork, id, player }` |
241
241
  | `waveformplayer:request-pause` | Same shape |
242
242
  | `waveformplayer:request-seek` | Same shape + `{ percent: 0..1 }` |
243
243
 
@@ -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.
@@ -829,6 +823,7 @@ var WaveformPlayer = class _WaveformPlayer {
829
823
  const preset = getColorPreset(this.options.colorPreset);
830
824
  this._autoTheme = this.options.colorPreset == null || !COLOR_PRESETS[this.options.colorPreset];
831
825
  this._presetKeys = [];
826
+ this._scheme = this.options.colorPreset && COLOR_PRESETS[this.options.colorPreset] ? this.options.colorPreset : detectColorScheme();
832
827
  for (const [key, value] of Object.entries(preset)) {
833
828
  if (this.options[key] === null || this.options[key] === void 0) {
834
829
  this.options[key] = value;
@@ -935,7 +930,7 @@ var WaveformPlayer = class _WaveformPlayer {
935
930
  *
936
931
  * Clears the container, resolves button alignment (`auto` → `bottom` for
937
932
  * the `bars` style, `center` otherwise), and conditionally renders the play
938
- * button, info row (artwork/title/subtitle), BPM badge, playback-speed
933
+ * button, info row (artwork/title/artist), BPM badge, playback-speed
939
934
  * menu, and time display based on the relevant `show*` options. Caches the
940
935
  * canvas, controls, and text elements onto `this`, then sizes the canvas.
941
936
  * @private
@@ -956,12 +951,9 @@ var WaveformPlayer = class _WaveformPlayer {
956
951
  if (isPreview) {
957
952
  this.container.classList.add("waveform-layout-preview");
958
953
  }
954
+ this.container.classList.toggle("waveform-theme-light", this._scheme === "light");
959
955
  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
- ">
956
+ <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
957
  <span class="waveform-icon-play">${this.options.playIcon}</span>
966
958
  <span class="waveform-icon-pause" style="display:none;">${this.options.pauseIcon}</span>
967
959
  </button>
@@ -978,12 +970,12 @@ var WaveformPlayer = class _WaveformPlayer {
978
970
  ">
979
971
  ` : ""}
980
972
  <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>` : ""}
973
+ <span class="waveform-title"></span>
974
+ ${this.options.artist ? `<span class="waveform-artist">${this.options.artist}</span>` : ""}
983
975
  </div>
984
976
  <div class="waveform-meta" style="display: flex; align-items: center; gap: 1rem;">
985
977
  ${this.options.showBPM ? `
986
- <span class="waveform-bpm" style="color: ${this.options.textSecondaryColor}; display: none;">
978
+ <span class="waveform-bpm" style="display: none;">
987
979
  <span class="bpm-value">--</span> BPM
988
980
  </span>
989
981
  ` : ""}
@@ -1000,7 +992,7 @@ var WaveformPlayer = class _WaveformPlayer {
1000
992
  </div>
1001
993
  ` : ""}
1002
994
  ${this.options.showTime ? `
1003
- <span class="waveform-time" style="color: ${this.options.textSecondaryColor};">
995
+ <span class="waveform-time">
1004
996
  <span class="time-current">0:00</span> / <span class="time-total">0:00</span>
1005
997
  </span>
1006
998
  ` : ""}
@@ -1031,7 +1023,7 @@ var WaveformPlayer = class _WaveformPlayer {
1031
1023
  this.canvas = this.container.querySelector("canvas");
1032
1024
  this.ctx = this.canvas.getContext("2d");
1033
1025
  this.titleEl = this.container.querySelector(".waveform-title");
1034
- this.subtitleEl = this.container.querySelector(".waveform-subtitle");
1026
+ this.artistEl = this.container.querySelector(".waveform-artist");
1035
1027
  this.artworkEl = this.container.querySelector(".waveform-artwork");
1036
1028
  if (this.artworkEl) {
1037
1029
  this.artworkEl.addEventListener("error", () => {
@@ -1306,7 +1298,7 @@ var WaveformPlayer = class _WaveformPlayer {
1306
1298
  if (!this.audio) return;
1307
1299
  navigator.mediaSession.metadata = new MediaMetadata({
1308
1300
  title: this.options.title || "Unknown Track",
1309
- artist: this.options.subtitle || "",
1301
+ artist: this.options.artist || "",
1310
1302
  album: this.options.album || "",
1311
1303
  artwork: this.options.artwork ? [
1312
1304
  { src: this.options.artwork, sizes: "512x512", type: "image/jpeg" }
@@ -1393,7 +1385,7 @@ var WaveformPlayer = class _WaveformPlayer {
1393
1385
  } catch (err) {
1394
1386
  }
1395
1387
  this._seekFromPointer(e.clientX);
1396
- if (!this._seekHover) this._hideHoverTip();
1388
+ if (!this._seekHover && !this.options.showHoverTime) this._hideHoverTip();
1397
1389
  this._updateSeekHandle();
1398
1390
  };
1399
1391
  this.canvas.addEventListener("pointerup", endDrag);
@@ -1496,19 +1488,19 @@ var WaveformPlayer = class _WaveformPlayer {
1496
1488
  *
1497
1489
  * Pauses any current playback, fully resets the audio element (self mode),
1498
1490
  * clears error/marker/progress state, merges the new metadata into
1499
- * `this.options`, updates the subtitle/artwork DOM, then calls
1491
+ * `this.options`, updates the artist/artwork DOM, then calls
1500
1492
  * {@link WaveformPlayer#load}. Auto-plays the new track unless
1501
1493
  * `options.autoplay === false`.
1502
1494
  * @param {string} url - Audio URL.
1503
1495
  * @param {string|null} [title=null] - Track title; keeps the existing
1504
1496
  * 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.
1497
+ * @param {string|null} [artist=null] - Track artist; pass `''` to hide
1498
+ * the artist row, or null to keep the existing one.
1507
1499
  * @param {Object} [options={}] - Additional options to merge (e.g.
1508
1500
  * `preload`, `artwork`, `markers`, `autoplay`).
1509
1501
  * @returns {Promise<void>}
1510
1502
  */
1511
- async loadTrack(url, title = null, subtitle = null, options = {}) {
1503
+ async loadTrack(url, title = null, artist = null, options = {}) {
1512
1504
  if (this.isPlaying) {
1513
1505
  this.pause();
1514
1506
  }
@@ -1531,18 +1523,18 @@ var WaveformPlayer = class _WaveformPlayer {
1531
1523
  this.options = mergeOptions(this.options, {
1532
1524
  url,
1533
1525
  title: title || this.options.title,
1534
- subtitle: subtitle || this.options.subtitle,
1526
+ artist: artist || this.options.artist,
1535
1527
  ...options
1536
1528
  });
1537
1529
  if (options.preload && this.audio) {
1538
1530
  this.audio.preload = options.preload;
1539
1531
  }
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";
1532
+ if (this.artistEl) {
1533
+ if (artist) {
1534
+ this.artistEl.textContent = artist;
1535
+ this.artistEl.style.display = "";
1536
+ } else if (artist === "") {
1537
+ this.artistEl.style.display = "none";
1546
1538
  }
1547
1539
  }
1548
1540
  if (options.artwork && this.artworkEl) {
@@ -1725,19 +1717,20 @@ var WaveformPlayer = class _WaveformPlayer {
1725
1717
  }
1726
1718
  }
1727
1719
  /**
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
1720
+ * Build the time tooltip that follows the pointer over the waveform. The
1721
+ * element is always created so **drag-scrub** can show the time you're
1722
+ * dragging to; the *hover* reveal is gated on `showHoverTime`. Works in both
1730
1723
  * self and external modes (it only needs {@link WaveformPlayer#getSeekDuration}).
1731
- * Uses the same pointer-X → percentage math as seeking.
1732
1724
  * @private
1733
1725
  */
1734
1726
  setupHoverTime() {
1735
- if (!this.options.showHoverTime || !this.seekEl) return;
1727
+ if (!this.seekEl) return;
1736
1728
  const tip = document.createElement("div");
1737
1729
  tip.className = "waveform-hover-time";
1738
1730
  tip.setAttribute("aria-hidden", "true");
1739
1731
  this.seekEl.appendChild(tip);
1740
1732
  this.hoverTimeEl = tip;
1733
+ if (!this.options.showHoverTime) return;
1741
1734
  this.seekEl.addEventListener("pointermove", (e) => {
1742
1735
  if (!this._dragging) this._updateHoverTip(e.clientX);
1743
1736
  });
@@ -1784,6 +1777,10 @@ var WaveformPlayer = class _WaveformPlayer {
1784
1777
  this.drawWaveform();
1785
1778
  this._updateSeekHandle();
1786
1779
  this._updateHoverTip(clientX);
1780
+ const dur = this.getSeekDuration();
1781
+ if (dur && this.currentTimeEl) {
1782
+ this.currentTimeEl.textContent = formatTime(this.progress * dur);
1783
+ }
1787
1784
  }
1788
1785
  /**
1789
1786
  * Create the draggable seek handle — a DOM circle over the playhead, shown
@@ -2070,33 +2067,21 @@ var WaveformPlayer = class _WaveformPlayer {
2070
2067
  * @public
2071
2068
  */
2072
2069
  refreshTheme() {
2073
- if (!this._autoTheme || !this._presetKeys || !this._presetKeys.length) return;
2070
+ if (!this._autoTheme) return;
2071
+ this._scheme = detectColorScheme();
2074
2072
  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
- }
2073
+ for (const key of this._presetKeys || []) {
2074
+ if (key in preset) this.options[key] = preset[key];
2081
2075
  }
2082
- if (changed) this._applyThemeColors();
2076
+ this._applyThemeColors();
2083
2077
  }
2084
2078
  /**
2085
- * Push the current resolved colours onto the live DOM (button border/icon,
2086
- * title, subtitle, time, BPM) and redraw the waveform.
2079
+ * Sync the theme class (CSS drives the DOM chrome colours via `--wfp-*`
2080
+ * variables) and redraw the canvas with the resolved waveform colours.
2087
2081
  * @private
2088
2082
  */
2089
2083
  _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
- });
2084
+ this.container.classList.toggle("waveform-theme-light", this._scheme === "light");
2100
2085
  if (this.canvas) this.drawWaveform();
2101
2086
  }
2102
2087
  /**
@@ -2210,16 +2195,13 @@ var WaveformPlayer = class _WaveformPlayer {
2210
2195
  * directly: `WaveformBar.play(event.detail)`.
2211
2196
  *
2212
2197
  * @private
2213
- * @return {{url:string,title:?string,subtitle:?string,artist:?string,artwork:?string,player:WaveformPlayer}}
2198
+ * @return {{url:string,title:?string,artist:?string,artwork:?string,player:WaveformPlayer}}
2214
2199
  */
2215
2200
  _buildTrackDetail() {
2216
2201
  return {
2217
2202
  url: this.options.url,
2218
2203
  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,
2204
+ artist: this.options.artist,
2223
2205
  artwork: this.options.artwork,
2224
2206
  markers: this.options.markers,
2225
2207
  waveform: this.options.waveform,