@smooth-player/svelte 1.0.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 ADDED
@@ -0,0 +1,20 @@
1
+ # @smooth-player/svelte
2
+
3
+ Svelte wrapper component for [`smooth-player`](https://www.npmjs.com/package/smooth-player).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install smooth-player @smooth-player/svelte
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```svelte
14
+ <script>
15
+ import "smooth-player/dist/smooth-player.css";
16
+ import { SmoothAudioPlayer } from "@smooth-player/svelte";
17
+ </script>
18
+
19
+ <SmoothAudioPlayer {tracks} accentColor="#0ed2a4" visualizer="spectrum" initialVolume={0.8} />
20
+ ```
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@smooth-player/svelte",
3
+ "version": "1.0.0",
4
+ "description": "Svelte component for Smooth Player",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "types": "./src/index.d.ts",
8
+ "svelte": "./src/SmoothAudioPlayer.svelte",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.d.ts",
12
+ "svelte": "./src/SmoothAudioPlayer.svelte",
13
+ "default": "./src/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "src",
18
+ "README.md"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "peerDependencies": {
24
+ "svelte": ">=4",
25
+ "smooth-player": "^1.0.0"
26
+ },
27
+ "scripts": {
28
+ "build": "echo \"No build step required for source-distributed Svelte component\"",
29
+ "typecheck": "echo \"Typecheck in consumer app (SvelteKit/Vite)\""
30
+ }
31
+ }
@@ -0,0 +1,93 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import {
4
+ SmoothPlayer,
5
+ CanvasSpectrumVisualizer,
6
+ CanvasWaveformVisualizer,
7
+ type AudioTrack,
8
+ type VisualizerMode,
9
+ } 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
+
15
+ export let tracks: AudioTrack[] = [];
16
+ export let accentColor = "#0ed2a4";
17
+ export let visualizer: VisualizerMode = "spectrum";
18
+ export let initialVolume = 0.8;
19
+
20
+ let root: HTMLElement;
21
+ let spectrumCanvas: HTMLCanvasElement;
22
+ let waveformCanvas: HTMLCanvasElement;
23
+
24
+ let player: SmoothPlayer;
25
+ let currentIndex = 0;
26
+ let isPlaying = false;
27
+
28
+ const applyTheme = () => {
29
+ player.setAccentColor(accentColor);
30
+ player.applyAccentColor(root);
31
+ };
32
+
33
+ $: if (player && root) {
34
+ applyTheme();
35
+ }
36
+
37
+ 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
+ };
65
+ });
66
+ </script>
67
+
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>
84
+
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>
89
+
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>
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
2
+ <path d="M17.5 6V18" stroke="currentColor" stroke-width="2.1" stroke-linecap="round"/>
3
+ <path d="M7.3 6.7C6.74 6.34 6 6.74 6 7.41V16.59C6 17.26 6.74 17.66 7.3 17.3L13.85 13.09C14.35 12.77 14.35 11.23 13.85 10.91L7.3 6.7Z" fill="currentColor"/>
4
+ </svg>
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
2
+ <rect x="7" y="6" width="3.6" height="12" rx="1.8" fill="currentColor"/>
3
+ <rect x="13.4" y="6" width="3.6" height="12" rx="1.8" fill="currentColor"/>
4
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
2
+ <path d="M8 6.75C8 6.14 8.67 5.77 9.18 6.12L17.12 11.37C17.58 11.68 17.58 12.32 17.12 12.63L9.18 17.88C8.67 18.23 8 17.86 8 17.25V6.75Z" fill="currentColor"/>
3
+ </svg>
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
2
+ <path d="M6.5 6V18" stroke="currentColor" stroke-width="2.1" stroke-linecap="round"/>
3
+ <path d="M16.7 6.7C17.26 6.34 18 6.74 18 7.41V16.59C18 17.26 17.26 17.66 16.7 17.3L10.15 13.09C9.65 12.77 9.65 11.23 10.15 10.91L16.7 6.7Z" fill="currentColor"/>
4
+ </svg>
package/src/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { AudioTrack, VisualizerMode } from "smooth-player";
2
+ import type { SvelteComponentTyped } from "svelte";
3
+
4
+ export interface SmoothAudioPlayerProps {
5
+ tracks: AudioTrack[];
6
+ accentColor?: string;
7
+ visualizer?: VisualizerMode;
8
+ initialVolume?: number;
9
+ }
10
+
11
+ export default class SmoothAudioPlayer extends SvelteComponentTyped<SmoothAudioPlayerProps> {}
12
+ export { SmoothAudioPlayer };
package/src/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import SmoothAudioPlayer from "./SmoothAudioPlayer.svelte";
2
+
3
+ export { SmoothAudioPlayer };
4
+ export default SmoothAudioPlayer;
@@ -0,0 +1,4 @@
1
+ declare module "*.svg" {
2
+ const src: string;
3
+ export default src;
4
+ }