@arraypress/waveform-player 1.22.0 → 1.24.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.
@@ -94,6 +94,9 @@ function parseDataAttributes(element) {
94
94
  if (element.dataset.preload) {
95
95
  options.preload = element.dataset.preload;
96
96
  }
97
+ if (element.dataset.crossOrigin) {
98
+ options.crossOrigin = element.dataset.crossOrigin;
99
+ }
97
100
  if (element.dataset.audioMode) options.audioMode = element.dataset.audioMode;
98
101
  if (element.dataset.style) options.waveformStyle = element.dataset.style;
99
102
  if (element.dataset.waveformStyle) options.waveformStyle = element.dataset.waveformStyle;
@@ -702,6 +705,15 @@ var DEFAULT_OPTIONS = {
702
705
  // every-frame scan means a higher value costs no extra extraction time.
703
706
  samples: DEFAULT_SAMPLES,
704
707
  preload: "metadata",
708
+ // CORS mode for the underlying <audio> element. Left null by default so the
709
+ // player behaves like a plain <audio> and never forces a CORS request —
710
+ // setting 'anonymous' here would break playback of media hosted on origins
711
+ // that don't send Access-Control-Allow-Origin (default-config S3/CDN). The
712
+ // playback element is never fed to createMediaElementSource, so it never
713
+ // needs CORS-clean media; peak analysis uses a separate fetch() path with
714
+ // its own placeholder fallback. Set 'anonymous' / 'use-credentials' only if
715
+ // you specifically need it. See issue #18.
716
+ crossOrigin: null,
705
717
  // Audio mode — 'self' = player owns the <audio> element (default, current
706
718
  // behavior). 'external' = player is a visualization-only surface; no audio
707
719
  // element is created, play() dispatches `waveformplayer:request-play`
@@ -1262,7 +1274,9 @@ var WaveformPlayer = class _WaveformPlayer {
1262
1274
  }
1263
1275
  this.audio = new Audio();
1264
1276
  this.audio.preload = this.options.preload || "metadata";
1265
- this.audio.crossOrigin = "anonymous";
1277
+ if (this.options.crossOrigin) {
1278
+ this.audio.crossOrigin = this.options.crossOrigin;
1279
+ }
1266
1280
  }
1267
1281
  // ============================================
1268
1282
  // Feature Initialization
@@ -1732,6 +1746,7 @@ var WaveformPlayer = class _WaveformPlayer {
1732
1746
  this.setLoading(true);
1733
1747
  this.progress = 0;
1734
1748
  this.hasError = false;
1749
+ this.container.classList.remove("waveform-is-placeholder");
1735
1750
  if (this.audio) {
1736
1751
  this.audio.src = url;
1737
1752
  await new Promise((resolve, reject) => {
@@ -1767,6 +1782,7 @@ var WaveformPlayer = class _WaveformPlayer {
1767
1782
  } catch (error) {
1768
1783
  console.warn("[WaveformPlayer] Using placeholder waveform:", error);
1769
1784
  this.waveformData = generatePlaceholderWaveform(this.options.samples);
1785
+ this.container.classList.add("waveform-is-placeholder");
1770
1786
  }
1771
1787
  }
1772
1788
  this.drawWaveform();
@@ -1836,6 +1852,9 @@ var WaveformPlayer = class _WaveformPlayer {
1836
1852
  if (options.preload && this.audio) {
1837
1853
  this.audio.preload = options.preload;
1838
1854
  }
1855
+ if (options.crossOrigin && this.audio) {
1856
+ this.audio.crossOrigin = options.crossOrigin;
1857
+ }
1839
1858
  if (artist !== null) {
1840
1859
  this.syncArtist(artist);
1841
1860
  }