@smooth-player/svelte 1.0.0 → 2.1.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
@@ -11,10 +11,60 @@ npm install smooth-player @smooth-player/svelte
11
11
  ## Usage
12
12
 
13
13
  ```svelte
14
- <script>
14
+ <script lang="ts">
15
15
  import "smooth-player/dist/smooth-player.css";
16
16
  import { SmoothAudioPlayer } from "@smooth-player/svelte";
17
+ import type { PlaylistEntry } from "smooth-player";
18
+
19
+ const tracks: PlaylistEntry[] = [
20
+ {
21
+ id: "demo",
22
+ title: "Demo Playlist",
23
+ tracks: [
24
+ {
25
+ id: "song-1",
26
+ src: "https://cdn.pixabay.com/audio/2020/08/17/audio_613575b827.mp3",
27
+ metadata: { title: "Robot Gypsy Jazz", artist: "Frank Vanga" },
28
+ },
29
+ ],
30
+ },
31
+ ];
17
32
  </script>
18
33
 
19
- <SmoothAudioPlayer {tracks} accentColor="#0ed2a4" visualizer="spectrum" initialVolume={0.8} />
34
+ <SmoothAudioPlayer
35
+ {tracks}
36
+ accentColor="#0ed2a4"
37
+ backgroundColor="#0b1220"
38
+ visualizer="spectrum"
39
+ initialVolume={0.8}
40
+ uiOptions={{ showLogo: true }}
41
+ />
20
42
  ```
43
+
44
+ ## Component props
45
+
46
+ - `tracks: PlaylistEntry[]`
47
+ - `accentColor?: string`
48
+ - `backgroundColor?: string`
49
+ - `visualizer?: "spectrum" | "waveform" | "none"`
50
+ - `initialVolume?: number`
51
+ - `playerOptions?: Omit<SmoothPlayerOptions, "playlist" | "accentColor" | "backgroundColor" | "visualizer" | "initialVolume">`
52
+ - `uiOptions?: StandardPlayerUIMountOptions`
53
+
54
+ ## Prop Mapping
55
+
56
+ | Wrapper prop | Core equivalent |
57
+ | --- | --- |
58
+ | `tracks` | `new SmoothPlayer({ playlist: tracks })` |
59
+ | `accentColor` | `new SmoothPlayer({ accentColor })` |
60
+ | `backgroundColor` | `new SmoothPlayer({ backgroundColor })` |
61
+ | `visualizer` | `new SmoothPlayer({ visualizer })` |
62
+ | `initialVolume` | `new SmoothPlayer({ initialVolume })` |
63
+ | `playerOptions` | Spread into `SmoothPlayerOptions` |
64
+ | `uiOptions` | Passed to `mountPlayerUI(player, root, uiOptions)` |
65
+
66
+ ## Documentation
67
+
68
+ For the full list of player config options, runtime APIs, events, and UI options, see the main docs:
69
+
70
+ - [smooth-player README](https://github.com/marlenesco/smooth-player#readme)
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@smooth-player/svelte",
3
- "version": "1.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Svelte component for Smooth Player",
5
5
  "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/marlenesco/smooth-player"
9
+ },
6
10
  "main": "./src/index.js",
7
11
  "types": "./src/index.d.ts",
8
12
  "svelte": "./src/SmoothAudioPlayer.svelte",
@@ -22,7 +26,7 @@
22
26
  },
23
27
  "peerDependencies": {
24
28
  "svelte": ">=4",
25
- "smooth-player": "^1.0.0"
29
+ "smooth-player": "^2.0.0"
26
30
  },
27
31
  "scripts": {
28
32
  "build": "echo \"No build step required for source-distributed Svelte component\"",
@@ -1,93 +1,69 @@
1
1
  <script lang="ts">
2
- import { onMount } from "svelte";
2
+ import { onDestroy, onMount } from "svelte";
3
3
  import {
4
4
  SmoothPlayer,
5
- CanvasSpectrumVisualizer,
6
- CanvasWaveformVisualizer,
7
- type AudioTrack,
5
+ mountPlayerUI,
6
+ type PlaylistEntry,
7
+ type SmoothPlayerOptions,
8
+ type StandardPlayerUIMountOptions,
8
9
  type VisualizerMode,
9
10
  } from "smooth-player";
10
- import prevIcon from "./assets/prev.svg";
11
- import nextIcon from "./assets/next.svg";
12
- import playIcon from "./assets/play.svg";
13
- import pauseIcon from "./assets/pause.svg";
14
11
 
15
- export let tracks: AudioTrack[] = [];
12
+ export let tracks: PlaylistEntry[] = [];
16
13
  export let accentColor = "#0ed2a4";
14
+ export let backgroundColor = "#0b1220";
17
15
  export let visualizer: VisualizerMode = "spectrum";
18
16
  export let initialVolume = 0.8;
17
+ export let playerOptions: Omit<SmoothPlayerOptions, "playlist" | "accentColor" | "backgroundColor" | "visualizer" | "initialVolume"> | undefined = undefined;
18
+ export let uiOptions: StandardPlayerUIMountOptions | undefined = undefined;
19
19
 
20
20
  let root: HTMLElement;
21
- let spectrumCanvas: HTMLCanvasElement;
22
- let waveformCanvas: HTMLCanvasElement;
21
+ let player: SmoothPlayer | null = null;
22
+ let destroyUI: (() => void) | null = null;
23
+ let mounted = false;
23
24
 
24
- let player: SmoothPlayer;
25
- let currentIndex = 0;
26
- let isPlaying = false;
27
-
28
- const applyTheme = () => {
29
- player.setAccentColor(accentColor);
30
- player.applyAccentColor(root);
25
+ const teardown = () => {
26
+ destroyUI?.();
27
+ destroyUI = null;
28
+ player?.destroy();
29
+ player = null;
31
30
  };
32
31
 
33
- $: if (player && root) {
34
- applyTheme();
35
- }
32
+ const setup = () => {
33
+ if (!mounted || !root) return;
34
+ teardown();
35
+ player = new SmoothPlayer({
36
+ ...playerOptions,
37
+ accentColor,
38
+ backgroundColor,
39
+ visualizer,
40
+ initialVolume,
41
+ playlist: tracks,
42
+ });
43
+ const ui = mountPlayerUI(player, root, uiOptions);
44
+ destroyUI = () => ui.destroy();
45
+ };
36
46
 
37
47
  onMount(() => {
38
- player = new SmoothPlayer({ initialVolume, visualizer, accentColor });
39
- player.setPlaylist(tracks, 0);
40
-
41
- let spectrum: CanvasSpectrumVisualizer | null = null;
42
- let waveform: CanvasWaveformVisualizer | null = null;
43
-
44
- if (visualizer === "spectrum") {
45
- spectrum = new CanvasSpectrumVisualizer(spectrumCanvas, player, { color: "#3cc8d9" });
46
- spectrum.start();
47
- }
48
-
49
- if (visualizer === "waveform") {
50
- waveform = new CanvasWaveformVisualizer(waveformCanvas, player, { color: "#e7f0ff" });
51
- waveform.start();
52
- }
53
-
54
- player.on("trackchange", ({ index }) => (currentIndex = index));
55
- player.on("play", () => (isPlaying = true));
56
- player.on("pause", () => (isPlaying = false));
57
-
58
- applyTheme();
59
-
60
- return () => {
61
- spectrum?.stop();
62
- waveform?.stop();
63
- player.destroy();
64
- };
48
+ mounted = true;
49
+ setup();
65
50
  });
66
- </script>
67
51
 
68
- <section bind:this={root} class="smooth-player">
69
- <div class="smooth-player__main">
70
- <div class="smooth-player__row">
71
- <h2 class="smooth-player__title">Smooth Player</h2>
72
- <div class="smooth-player__controls">
73
- <button class="secondary" on:click={() => player.previous()} aria-label="Previous">
74
- <img class="smooth-player__icon" src={prevIcon} alt="" />
75
- </button>
76
- <button on:click={() => player.toggle()} aria-label={isPlaying ? "Pause" : "Play"}>
77
- <img class="smooth-player__icon" src={isPlaying ? pauseIcon : playIcon} alt="" />
78
- </button>
79
- <button class="secondary" on:click={() => player.next()} aria-label="Next">
80
- <img class="smooth-player__icon" src={nextIcon} alt="" />
81
- </button>
82
- </div>
83
- </div>
52
+ onDestroy(() => {
53
+ mounted = false;
54
+ teardown();
55
+ });
84
56
 
85
- <div class="smooth-player__meta">
86
- <strong>{tracks[currentIndex]?.metadata?.title ?? "Unknown title"}</strong>
87
- <div class="smooth-player__artist">{tracks[currentIndex]?.metadata?.artist ?? "Unknown artist"}</div>
88
- </div>
57
+ $: if (mounted && root) {
58
+ tracks;
59
+ accentColor;
60
+ backgroundColor;
61
+ visualizer;
62
+ initialVolume;
63
+ playerOptions;
64
+ uiOptions;
65
+ setup();
66
+ }
67
+ </script>
89
68
 
90
- <canvas bind:this={spectrumCanvas} id="spectrum" class="smooth-player__canvas" width="860" height="180" hidden={visualizer !== "spectrum"}></canvas>
91
- <canvas bind:this={waveformCanvas} id="waveform" class="smooth-player__canvas" width="860" height="120" hidden={visualizer !== "waveform"}></canvas>
92
- </div>
93
- </section>
69
+ <section bind:this={root}></section>
@@ -0,0 +1,5 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
2
+ <path d="M5 7.5H19" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>
3
+ <path d="M5 12H19" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>
4
+ <path d="M5 16.5H19" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>
5
+ </svg>
package/src/index.d.ts CHANGED
@@ -1,11 +1,19 @@
1
- import type { AudioTrack, VisualizerMode } from "smooth-player";
1
+ import type {
2
+ PlaylistEntry,
3
+ SmoothPlayerOptions,
4
+ StandardPlayerUIMountOptions,
5
+ VisualizerMode,
6
+ } from "smooth-player";
2
7
  import type { SvelteComponentTyped } from "svelte";
3
8
 
4
9
  export interface SmoothAudioPlayerProps {
5
- tracks: AudioTrack[];
10
+ tracks: PlaylistEntry[];
6
11
  accentColor?: string;
12
+ backgroundColor?: string;
7
13
  visualizer?: VisualizerMode;
8
14
  initialVolume?: number;
15
+ playerOptions?: Omit<SmoothPlayerOptions, "playlist" | "accentColor" | "backgroundColor" | "visualizer" | "initialVolume">;
16
+ uiOptions?: StandardPlayerUIMountOptions;
9
17
  }
10
18
 
11
19
  export default class SmoothAudioPlayer extends SvelteComponentTyped<SmoothAudioPlayerProps> {}