@arraypress/waveform-player 1.22.0 → 1.23.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/index.d.ts CHANGED
@@ -35,6 +35,15 @@ export type AudioMode = 'self' | 'external';
35
35
  /** Browser preload hint for the underlying `<audio>` element. */
36
36
  export type AudioPreload = 'auto' | 'metadata' | 'none';
37
37
 
38
+ /**
39
+ * CORS mode for the underlying `<audio>` element. Left unset by default so the
40
+ * player behaves like a plain `<audio>` and never forces a CORS request. Set
41
+ * `'anonymous'` / `'use-credentials'` only if you specifically need it — doing
42
+ * so breaks playback of media hosted on origins that don't send
43
+ * `Access-Control-Allow-Origin` (e.g. default-config S3/CDN).
44
+ */
45
+ export type AudioCrossOrigin = 'anonymous' | 'use-credentials';
46
+
38
47
  /** Vertical alignment of the play button relative to the waveform. */
39
48
  export type ButtonAlign = 'auto' | 'top' | 'center' | 'bottom';
40
49
 
@@ -83,6 +92,13 @@ export interface WaveformPlayerOptions {
83
92
  samples?: number;
84
93
  /** `<audio>` preload hint. @default 'metadata' */
85
94
  preload?: AudioPreload;
95
+ /**
96
+ * `<audio>` CORS mode. Unset by default so the player behaves like a plain
97
+ * `<audio>` and never forces a CORS request (which breaks playback of media
98
+ * on origins without `Access-Control-Allow-Origin`). Set only if you need it.
99
+ * @default null
100
+ */
101
+ crossOrigin?: AudioCrossOrigin | null;
86
102
  /** Whether the player owns its `<audio>` or delegates to an external controller. @default 'self' */
87
103
  audioMode?: AudioMode;
88
104
  /** Pre-computed peaks (array, .json URL, or JSON string). Skips Web Audio decoding when provided. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arraypress/waveform-player",
3
- "version": "1.22.0",
3
+ "version": "1.23.0",
4
4
  "description": "Lightweight, customizable audio player with waveform visualization",
5
5
  "type": "module",
6
6
  "types": "./index.d.ts",
package/src/js/core.js CHANGED
@@ -567,7 +567,13 @@ export class WaveformPlayer {
567
567
  }
568
568
  this.audio = new Audio();
569
569
  this.audio.preload = this.options.preload || 'metadata';
570
- this.audio.crossOrigin = 'anonymous';
570
+ // Only set crossOrigin when explicitly opted in. Setting it forces a
571
+ // CORS request that breaks playback of media on origins without
572
+ // Access-Control-Allow-Origin; the player never needs CORS-clean media
573
+ // for playback (no createMediaElementSource). See issue #18.
574
+ if (this.options.crossOrigin) {
575
+ this.audio.crossOrigin = this.options.crossOrigin;
576
+ }
571
577
  }
572
578
 
573
579
  // ============================================
@@ -1283,6 +1289,11 @@ export class WaveformPlayer {
1283
1289
  this.audio.preload = options.preload;
1284
1290
  }
1285
1291
 
1292
+ // Apply crossOrigin if it was changed for this track
1293
+ if (options.crossOrigin && this.audio) {
1294
+ this.audio.crossOrigin = options.crossOrigin;
1295
+ }
1296
+
1286
1297
  // Update artist only when explicitly provided. A null artist keeps the
1287
1298
  // existing artist, while an empty string removes it.
1288
1299
  if (artist !== null) {
package/src/js/themes.js CHANGED
@@ -147,6 +147,15 @@ export const DEFAULT_OPTIONS = {
147
147
  // every-frame scan means a higher value costs no extra extraction time.
148
148
  samples: DEFAULT_SAMPLES,
149
149
  preload: 'metadata',
150
+ // CORS mode for the underlying <audio> element. Left null by default so the
151
+ // player behaves like a plain <audio> and never forces a CORS request —
152
+ // setting 'anonymous' here would break playback of media hosted on origins
153
+ // that don't send Access-Control-Allow-Origin (default-config S3/CDN). The
154
+ // playback element is never fed to createMediaElementSource, so it never
155
+ // needs CORS-clean media; peak analysis uses a separate fetch() path with
156
+ // its own placeholder fallback. Set 'anonymous' / 'use-credentials' only if
157
+ // you specifically need it. See issue #18.
158
+ crossOrigin: null,
150
159
 
151
160
  // Audio mode — 'self' = player owns the <audio> element (default, current
152
161
  // behavior). 'external' = player is a visualization-only surface; no audio
package/src/js/utils.js CHANGED
@@ -175,6 +175,9 @@ export function parseDataAttributes(element) {
175
175
  if (element.dataset.preload) {
176
176
  options.preload = element.dataset.preload;
177
177
  }
178
+ if (element.dataset.crossOrigin) {
179
+ options.crossOrigin = element.dataset.crossOrigin;
180
+ }
178
181
  if (element.dataset.audioMode) options.audioMode = element.dataset.audioMode;
179
182
 
180
183
  // Waveform style attributes. `data-style` is a shorthand alias for