@smooth-player/vue 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,12 +11,62 @@ npm install smooth-player @smooth-player/vue
11
11
  ## Usage
12
12
 
13
13
  ```vue
14
- <script setup>
14
+ <script setup lang="ts">
15
15
  import "smooth-player/dist/smooth-player.css";
16
16
  import { SmoothAudioPlayer } from "@smooth-player/vue";
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
34
  <template>
20
- <SmoothAudioPlayer :tracks="tracks" accent-color="#0ed2a4" visualizer="spectrum" :initial-volume="0.8" />
35
+ <SmoothAudioPlayer
36
+ :tracks="tracks"
37
+ accent-color="#0ed2a4"
38
+ background-color="#0b1220"
39
+ visualizer="spectrum"
40
+ :initial-volume="0.8"
41
+ :ui-options="{ showLogo: true }"
42
+ />
21
43
  </template>
22
44
  ```
45
+
46
+ ## Component props
47
+
48
+ - `tracks: PlaylistEntry[]`
49
+ - `accentColor?: string`
50
+ - `backgroundColor?: string`
51
+ - `visualizer?: "spectrum" | "waveform" | "none"`
52
+ - `initialVolume?: number`
53
+ - `playerOptions?: Omit<SmoothPlayerOptions, "playlist" | "accentColor" | "backgroundColor" | "visualizer" | "initialVolume">`
54
+ - `uiOptions?: StandardPlayerUIMountOptions`
55
+
56
+ ## Prop Mapping
57
+
58
+ | Wrapper prop | Core equivalent |
59
+ | --- | --- |
60
+ | `tracks` | `new SmoothPlayer({ playlist: tracks })` |
61
+ | `accentColor` | `new SmoothPlayer({ accentColor })` |
62
+ | `backgroundColor` | `new SmoothPlayer({ backgroundColor })` |
63
+ | `visualizer` | `new SmoothPlayer({ visualizer })` |
64
+ | `initialVolume` | `new SmoothPlayer({ initialVolume })` |
65
+ | `playerOptions` | Spread into `SmoothPlayerOptions` |
66
+ | `uiOptions` | Passed to `mountPlayerUI(player, root, uiOptions)` |
67
+
68
+ ## Documentation
69
+
70
+ For the full list of player config options, runtime APIs, events, and UI options, see the main docs:
71
+
72
+ - [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/vue",
3
- "version": "1.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Vue 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
  "exports": {
@@ -20,7 +24,7 @@
20
24
  },
21
25
  "peerDependencies": {
22
26
  "vue": ">=3.3.0",
23
- "smooth-player": "^1.0.0"
27
+ "smooth-player": "^2.0.0"
24
28
  },
25
29
  "scripts": {
26
30
  "build": "echo \"No build step required for source-distributed Vue component\"",
@@ -1,110 +1,73 @@
1
1
  <script setup lang="ts">
2
- import { onMounted, onBeforeUnmount, ref, computed, watch } from "vue";
2
+ import { onBeforeUnmount, ref, watch } from "vue";
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
12
  const props = withDefaults(defineProps<{
16
- tracks: AudioTrack[];
13
+ tracks: PlaylistEntry[];
17
14
  accentColor?: string;
15
+ backgroundColor?: string;
18
16
  visualizer?: VisualizerMode;
19
17
  initialVolume?: number;
18
+ playerOptions?: Omit<SmoothPlayerOptions, "playlist" | "accentColor" | "backgroundColor" | "visualizer" | "initialVolume">;
19
+ uiOptions?: StandardPlayerUIMountOptions;
20
20
  }>(), {
21
21
  accentColor: "#0ed2a4",
22
+ backgroundColor: "#0b1220",
22
23
  visualizer: "spectrum",
23
24
  initialVolume: 0.8,
24
25
  });
25
26
 
26
27
  const rootRef = ref<HTMLElement | null>(null);
27
- const spectrumRef = ref<HTMLCanvasElement | null>(null);
28
- const waveformRef = ref<HTMLCanvasElement | null>(null);
29
- const player = ref<SmoothPlayer | null>(null);
30
- const currentIndex = ref(0);
31
- const isPlaying = ref(false);
32
-
33
- const currentTrack = computed(() => props.tracks[currentIndex.value] ?? null);
34
-
35
- let spectrum: CanvasSpectrumVisualizer | null = null;
36
- let waveform: CanvasWaveformVisualizer | null = null;
37
-
38
- onMounted(() => {
39
- const instance = new SmoothPlayer({
40
- initialVolume: props.initialVolume,
41
- visualizer: props.visualizer,
28
+ let player: SmoothPlayer | null = null;
29
+ let destroyUI: (() => void) | null = null;
30
+
31
+ const teardown = () => {
32
+ destroyUI?.();
33
+ destroyUI = null;
34
+ player?.destroy();
35
+ player = null;
36
+ };
37
+
38
+ watch(
39
+ () => ({
40
+ root: rootRef.value,
41
+ tracks: props.tracks,
42
42
  accentColor: props.accentColor,
43
- });
44
- instance.setPlaylist(props.tracks, 0);
45
- player.value = instance;
46
-
47
- if (props.visualizer === "spectrum") {
48
- spectrum = new CanvasSpectrumVisualizer(spectrumRef.value!, instance, { color: "#3cc8d9" });
49
- spectrum.start();
50
- }
51
-
52
- if (props.visualizer === "waveform") {
53
- waveform = new CanvasWaveformVisualizer(waveformRef.value!, instance, { color: "#e7f0ff" });
54
- waveform.start();
55
- }
56
-
57
- instance.on("trackchange", ({ index }) => (currentIndex.value = index));
58
- instance.on("play", () => (isPlaying.value = true));
59
- instance.on("pause", () => (isPlaying.value = false));
60
-
61
- applyAccent();
62
- });
43
+ backgroundColor: props.backgroundColor,
44
+ visualizer: props.visualizer,
45
+ initialVolume: props.initialVolume,
46
+ playerOptions: props.playerOptions,
47
+ uiOptions: props.uiOptions,
48
+ }),
49
+ () => {
50
+ if (!rootRef.value) return;
51
+ teardown();
52
+ player = new SmoothPlayer({
53
+ ...props.playerOptions,
54
+ accentColor: props.accentColor,
55
+ backgroundColor: props.backgroundColor,
56
+ visualizer: props.visualizer,
57
+ initialVolume: props.initialVolume,
58
+ playlist: props.tracks,
59
+ });
60
+ const ui = mountPlayerUI(player, rootRef.value, props.uiOptions);
61
+ destroyUI = () => ui.destroy();
62
+ },
63
+ { immediate: true, deep: true },
64
+ );
63
65
 
64
66
  onBeforeUnmount(() => {
65
- spectrum?.stop();
66
- waveform?.stop();
67
- player.value?.destroy();
67
+ teardown();
68
68
  });
69
-
70
- watch(() => props.accentColor, () => applyAccent());
71
-
72
- function applyAccent() {
73
- if (!player.value || !rootRef.value) return;
74
- player.value.setAccentColor(props.accentColor);
75
- player.value.applyAccentColor(rootRef.value);
76
- }
77
-
78
- async function toggle() {
79
- await player.value?.toggle();
80
- }
81
69
  </script>
82
70
 
83
71
  <template>
84
- <section ref="rootRef" class="smooth-player">
85
- <div class="smooth-player__main">
86
- <div class="smooth-player__row">
87
- <h2 class="smooth-player__title">Smooth Player</h2>
88
- <div class="smooth-player__controls">
89
- <button class="secondary" @click="player?.previous()" aria-label="Previous">
90
- <img class="smooth-player__icon" :src="prevIcon" alt="" />
91
- </button>
92
- <button @click="toggle" :aria-label="isPlaying ? 'Pause' : 'Play'">
93
- <img class="smooth-player__icon" :src="isPlaying ? pauseIcon : playIcon" alt="" />
94
- </button>
95
- <button class="secondary" @click="player?.next()" aria-label="Next">
96
- <img class="smooth-player__icon" :src="nextIcon" alt="" />
97
- </button>
98
- </div>
99
- </div>
100
-
101
- <div class="smooth-player__meta">
102
- <strong>{{ currentTrack?.metadata?.title ?? "Unknown title" }}</strong>
103
- <div class="smooth-player__artist">{{ currentTrack?.metadata?.artist ?? "Unknown artist" }}</div>
104
- </div>
105
-
106
- <canvas ref="spectrumRef" id="spectrum" class="smooth-player__canvas" width="860" height="180" :hidden="props.visualizer !== 'spectrum'"></canvas>
107
- <canvas ref="waveformRef" id="waveform" class="smooth-player__canvas" width="860" height="120" :hidden="props.visualizer !== 'waveform'"></canvas>
108
- </div>
109
- </section>
72
+ <section ref="rootRef"></section>
110
73
  </template>
@@ -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
1
  import type { DefineComponent } from "vue";
2
- import type { AudioTrack, VisualizerMode } from "smooth-player";
2
+ import type {
3
+ PlaylistEntry,
4
+ SmoothPlayerOptions,
5
+ StandardPlayerUIMountOptions,
6
+ VisualizerMode,
7
+ } from "smooth-player";
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
  declare const SmoothAudioPlayer: DefineComponent<SmoothAudioPlayerProps>;