nuxt-musicfyplayer 1.0.0 → 2.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 CHANGED
@@ -1,16 +1,153 @@
1
+ ![musicfyplayer](https://github.com/Yizack/nuxt-musicfyplayer/assets/16264115/d1603014-8331-4327-9b65-4ff580c3624d)
2
+
1
3
  # nuxt-musicfyplayer
2
4
 
3
5
  [![npm version][npm-version-src]][npm-version-href]
4
6
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
7
  [![License][license-src]][license-href]
6
- [![Tests][tests-src]][tests-href]
7
8
  [![Nuxt][nuxt-src]][nuxt-href]
8
9
 
9
- Embed a simple and beautiful HTML music player from local or hosted audio on your website using MediaElement.js and ColorThief.js
10
+ Embed a simple HTML music player from local or hosted audio on your Nuxt app using MediaElement.js and ColorThief.js
10
11
 
11
12
  - [✨ Release Notes](https://github.com/Yizack/nuxt-musicfyplayer/blob/main/CHANGELOG.md)
12
13
  - [🏀 Online playground](https://stackblitz.com/github/yizack/nuxt-musicfyplayer?file=playground%2Fapp.vue)
13
14
 
15
+ ## Quick Setup
16
+
17
+ 1. Add `nuxt-musicfyplayer` dependency to your project
18
+
19
+ ```bash
20
+ # Using pnpm
21
+ pnpm add -D nuxt-musicfyplayer
22
+
23
+ # Using yarn
24
+ yarn add --dev nuxt-musicfyplayer
25
+
26
+ # Using npm
27
+ npm install --save-dev nuxt-musicfyplayer
28
+ ```
29
+
30
+ 2. Add `nuxt-musicfyplayer` to the `modules` section of `nuxt.config.ts`
31
+
32
+ ```js
33
+ export default defineNuxtConfig({
34
+ modules: [
35
+ 'nuxt-musicfyplayer'
36
+ ]
37
+ })
38
+ ```
39
+
40
+ That's it! You can now use `nuxt-musicfyplayer` in your Nuxt app ✨
41
+
42
+ ## Usage
43
+
44
+ In the project, use the component `<MusicfyPlayer :config="" />`, where `config` is the configuration options of the player.
45
+
46
+ ### Component properties
47
+
48
+ ## Size properties
49
+
50
+ | Property | Description | Default value |
51
+ |---------------------------------------|--------------------------|---------------|
52
+ | [`config`](#musicfyplayer-definition) | MusicfyPlayer definition | |
53
+ | `width` | Music player width | `100%` |
54
+ | `height` | Music player height | `450px` |
55
+
56
+ ## MusicfyPlayer Definition
57
+
58
+ Define your configuration options with the `defineMusicfyPlayer` composable.
59
+
60
+ | Property | Description |
61
+ |-------------------------------------|---------------------------------------|
62
+ | [`audio`](#audio-shared-properties) | The audio source properties |
63
+ | [`image`](#image-properties) | The image source (preferably squared) |
64
+ | [`color`](#color-properties) | Color options |
65
+
66
+ ## Audio shared properties
67
+
68
+ | Property | Description | Default value |
69
+ |------------|----------------------------------|---------------|
70
+ | `provider` | Provider of the audio source. | `local` |
71
+ | `type` | Content-type fo the audio source | `audio/mpeg` |
72
+ | [`...`](#supported-audio-providers) | Selected audio provider properties ||
73
+
74
+ ### Supported audio providers
75
+
76
+ | Provider | Value |
77
+ |--------------------------------------|----------|
78
+ | [URL](#local-audio-properties) | `local` |
79
+ | [Dropbox](#dropbox-audio-properties) | `dropbox`|
80
+
81
+ ### Local audio properties
82
+
83
+ | Audio property | Description | Required |
84
+ |----------------|---------------------------|----------|
85
+ | `src` | Audio source link | Yes |
86
+
87
+ ### Dropbox audio properties
88
+
89
+ | Audio property | Description | Required |
90
+ |----------------|---------------------------|----------|
91
+ | `id` | File identifier | Yes |
92
+ | `rlkey` | New file identifier param | No |
93
+
94
+ ## Image properties
95
+
96
+ | Property | Description | Required |
97
+ |----------|------------------------|----------|
98
+ | `src` | Image source link | Yes |
99
+ | `alt` | Image alternative text | No |
100
+
101
+ ## Color properties
102
+
103
+ | Property | Description | Default value |
104
+ |----------|---------------------------------------------------------------------------------------------|-----------------------|
105
+ | `class` | A custom class for your player's background color | `musicfyplayer-color` |
106
+ | `detect` | Detect the dominant color from the image source and use it as the player's background color | `false` |
107
+
108
+ ## Example
109
+
110
+ Use the emoji property to render an emoji by character.
111
+
112
+ ```html
113
+ <script setup lang="ts">
114
+ const config = defineMusicfyPlayer({
115
+ audio: {
116
+ provider: "dropbox",
117
+ id: "soep3xvq8aee4eh6hcj4r",
118
+ rlkey: "g7sqo9y5zl3f69oxftzo5auc5"
119
+ },
120
+ image: {
121
+ src: "https://dimatis.yizack.com/images/reminiscences.jpg",
122
+ alt: "Dimatis - Reminiscences"
123
+ },
124
+ color: {
125
+ detect: true
126
+ }
127
+ })
128
+ </script>
129
+
130
+ <template>
131
+ <MusicfyPlayer :config="config" width="100%" />
132
+ </template>
133
+ ```
134
+
135
+ ### More examples
136
+
137
+ Example of use on a website: [Dimatis Website](https://dimatis.yizack.com)
138
+
139
+ [![Live Demo](https://yizack.com/images/embeddable-music-player/embeddeds.jpg)](https://dimatis.yizack.com)
140
+
141
+ [![Live Demo](https://yizack.com/images/embeddable-music-player/embeddeds2.jpg)](https://dimatis.yizack.com/music/fly-again)
142
+
143
+ Check out the [🏀 Online playground](https://stackblitz.com/github/yizack/nuxt-musicfyplayer?file=playground%2Fapp.vue) for more examples.
144
+
145
+ ## Credits
146
+
147
+ - Detect dominant color with [ColorThief](https://lokeshdhakar.com/projects/color-thief/)
148
+ - Music player controls by [MediaElement.js](https://www.mediaelementjs.com/)
149
+ - [Nuxt](https://github.com/nuxt/nuxt), the JavaScript framework for creating SSR Vue applications and its [Module Author Guide](https://nuxt.com/docs/guide/going-further/modules)
150
+
14
151
  ## Development
15
152
 
16
153
  ```bash
@@ -38,17 +175,17 @@ npm run release
38
175
  ```
39
176
 
40
177
  <!-- Badges -->
41
- [npm-version-src]: https://img.shields.io/npm/v/nuxt-musicfyplayer/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
178
+ [npm-version-src]: https://img.shields.io/npm/v/nuxt-musicfyplayer/latest.svg?style=flat&colorA=020420&colorB=00DC82
42
179
  [npm-version-href]: https://npmjs.com/package/nuxt-musicfyplayer
43
180
 
44
- [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-musicfyplayer.svg?style=flat&colorA=18181B&colorB=28CF8D
181
+ [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-musicfyplayer.svg?style=flat&colorA=020420&colorB=00DC82
45
182
  [npm-downloads-href]: https://npmjs.com/package/nuxt-musicfyplayer
46
183
 
47
- [license-src]: https://img.shields.io/npm/l/nuxt-musicfyplayer.svg?style=flat&colorA=18181B&colorB=28CF8D
184
+ [license-src]: https://img.shields.io/npm/l/nuxt-musicfyplayer.svg?style=flat&colorA=020420&colorB=00DC82
48
185
  [license-href]: LICENSE
49
186
 
50
- [tests-src]: https://img.shields.io/github/actions/workflow/status/Yizack/nuxt-musicfyplayer/tests.yml?style=flat&colorA=18181B&colorB=28CF8D&label=tests
187
+ [tests-src]: https://img.shields.io/github/actions/workflow/status/Yizack/nuxt-musicfyplayer/tests.yml?style=flat&colorA=020420&colorB=00DC82&label=tests
51
188
  [tests-href]: https://github.com/Yizack/nuxt-musicfyplayer/actions/workflows/tests.yml
52
189
 
53
- [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
190
+ [nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js
54
191
  [nuxt-href]: https://nuxt.com
package/dist/module.json CHANGED
@@ -2,7 +2,11 @@
2
2
  "name": "nuxt-musicfyplayer",
3
3
  "configKey": "nuxtMusicfyPlayer",
4
4
  "compatibility": {
5
- "nuxt": "^3.0.0"
5
+ "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "1.0.0"
7
+ "version": "2.0.0",
8
+ "builder": {
9
+ "@nuxt/module-builder": "0.8.1",
10
+ "unbuild": "2.0.0"
11
+ }
8
12
  }
package/dist/module.mjs CHANGED
@@ -5,7 +5,7 @@ const module = defineNuxtModule({
5
5
  name: "nuxt-musicfyplayer",
6
6
  configKey: "nuxtMusicfyPlayer",
7
7
  compatibility: {
8
- nuxt: "^3.0.0"
8
+ nuxt: ">=3.0.0"
9
9
  }
10
10
  },
11
11
  setup() {
@@ -1,21 +1,29 @@
1
1
  <script setup lang='ts'>
2
- import { onMounted, ref, type Ref } from '#imports'
3
- import type { MusicfyPlayerConfig } from './../types/musicfyplayer'
4
2
  import ColorThief from 'colorthief'
3
+ import type { MusicfyPlayerConfig } from './../types/musicfyplayer'
4
+ import { onMounted, ref, type Ref } from '#imports'
5
5
 
6
6
  const props = defineProps({
7
7
  config: {
8
8
  type: Object as () => MusicfyPlayerConfig,
9
- required: true
10
- }
9
+ required: true,
10
+ },
11
+ width: {
12
+ type: String,
13
+ default: '100%',
14
+ },
15
+ height: {
16
+ type: String,
17
+ default: '450px',
18
+ },
11
19
  })
12
20
 
13
21
  const audio = ref() as Ref<HTMLAudioElement>
14
- const size = ref({ width: props.config.sizeWidth, height: props.config.sizeHeight })
22
+ const size = ref({ width: props.width, height: props.height })
15
23
  const backgroundColor = ref<string | undefined>()
16
24
 
17
25
  const generateColor = async () => {
18
- if (process.client && props.config.colorDetect) {
26
+ if (import.meta.client && props.config.colorDetect) {
19
27
  const img = new Image()
20
28
  img.crossOrigin = 'Anonymous'
21
29
  img.src = props.config.imageSrc
@@ -40,7 +48,7 @@ onMounted(async () => {
40
48
  timeAndDurationSeparator: '<span></span>',
41
49
  iPadUseNativeControls: false,
42
50
  iPhoneUseNativeControls: false,
43
- AndroidUseNativeControls: false
51
+ AndroidUseNativeControls: false,
44
52
  })
45
53
  })
46
54
  </script>
@@ -1,2 +1,2 @@
1
- import type { MusicfyPlayerConfig, MusicfyPlayerDefinition } from './../types/musicfyplayer';
1
+ import type { MusicfyPlayerConfig, MusicfyPlayerDefinition } from './../types/musicfyplayer.js';
2
2
  export declare const defineMusicfyPlayer: (config: MusicfyPlayerDefinition) => MusicfyPlayerConfig;
@@ -6,10 +6,6 @@ const srcDropbox = (id, rlkey) => {
6
6
  export const defineMusicfyPlayer = (config) => {
7
7
  const audioSrc = ref();
8
8
  const provider = config.audio.provider || "local";
9
- const size = {
10
- width: config.size?.width || "100%",
11
- height: config.size?.height || "100%"
12
- };
13
9
  switch (provider) {
14
10
  default:
15
11
  case "local":
@@ -19,16 +15,13 @@ export const defineMusicfyPlayer = (config) => {
19
15
  audioSrc.value = srcDropbox(config.audio.id, config.audio.rlkey);
20
16
  break;
21
17
  }
22
- if (!audioSrc.value) {
18
+ if (!audioSrc.value)
23
19
  throw new Error("Invalid audio source");
24
- }
25
20
  return {
26
21
  imageSrc: config.image.src,
27
- imageAlt: config.image.alt,
28
- audioType: config.audio.type,
22
+ imageAlt: config.image.alt || "Musicfy Player",
23
+ audioType: config.audio.type || "audio/mpeg",
29
24
  audioSrc: audioSrc.value,
30
- sizeWidth: size.width,
31
- sizeHeight: size.height,
32
25
  colorClass: config.color?.class || "musicfyplayer-color",
33
26
  colorDetect: config.color?.detect || false
34
27
  };
@@ -1,7 +1,15 @@
1
- declare module 'colorthief' {
2
- type RGBColor = [number, number, number];
3
- export default class ColorThief {
4
- getColor: (img: HTMLImageElement | null, quality?: number) => RGBColor | null;
5
- getPalette: (img: HTMLImageElement | null, colorCount: number, quality?: number) => RGBColor[] | null;
6
- }
7
- }
1
+ declare module 'colorthief' {
2
+ export type RGBColor = [number, number, number]
3
+ export default class ColorThief {
4
+ getColor: (
5
+ img: HTMLImageElement | null,
6
+ quality?: number,
7
+ ) => RGBColor | null
8
+
9
+ getPalette: (
10
+ img: HTMLImageElement | null,
11
+ colorCount: number,
12
+ quality?: number,
13
+ ) => RGBColor[] | null
14
+ }
15
+ }
@@ -1,13 +1,14 @@
1
- export interface MediaElementPlayer {
2
- new (node: HTMLAudioElement, options: MediaElementPlayerOptions): void;
3
- }
4
- export interface MediaElementPlayerOptions {
5
- iconSprite: string;
6
- audioHeight: number;
7
- features: ('playpause' | 'current' | 'progress' | 'duration' | 'tracks' | 'volume' | 'fullscreen')[];
8
- alwaysShowControls: boolean;
9
- timeAndDurationSeparator: string;
10
- iPadUseNativeControls: boolean;
11
- iPhoneUseNativeControls: boolean;
12
- AndroidUseNativeControls: boolean;
13
- }
1
+ export interface MediaElementPlayer {
2
+ new (node: HTMLAudioElement, options: MediaElementPlayerOptions): void
3
+ }
4
+
5
+ export interface MediaElementPlayerOptions {
6
+ iconSprite: string
7
+ audioHeight: number
8
+ features: ('playpause' | 'current' | 'progress' | 'duration' | 'tracks' | 'volume' | 'fullscreen')[]
9
+ alwaysShowControls: boolean
10
+ timeAndDurationSeparator: string
11
+ iPadUseNativeControls: boolean
12
+ iPhoneUseNativeControls: boolean
13
+ AndroidUseNativeControls: boolean
14
+ }
@@ -1,38 +1,67 @@
1
- export interface MusicfyPlayerDefinition {
2
- image: {
3
- src: string;
4
- alt: string;
5
- };
6
- audio: {
7
- provider: string;
8
- type: string;
9
- } & (LocalAudio | DropboxAudio);
10
- color?: {
11
- detect?: boolean;
12
- class?: string;
13
- };
14
- size?: {
15
- width: string;
16
- height: string;
17
- };
18
- }
19
- export interface LocalAudio {
20
- provider: 'local';
21
- src: string;
22
- }
23
- export interface DropboxAudio {
24
- provider: 'dropbox';
25
- id: string;
26
- rlkey?: string;
27
- }
28
- export type AudioConfig = LocalAudio | DropboxAudio;
29
- export interface MusicfyPlayerConfig {
30
- imageSrc: string;
31
- imageAlt: string;
32
- audioType: string;
33
- audioSrc: string;
34
- sizeWidth: string;
35
- sizeHeight: string;
36
- colorClass: string;
37
- colorDetect: boolean;
38
- }
1
+ export interface MusicfyPlayerDefinition {
2
+ /**
3
+ * Image configuration
4
+ */
5
+ image: {
6
+ src: string
7
+ /**
8
+ * Image alt text
9
+ * @default 'Musicfy Player'
10
+ */
11
+ alt?: string
12
+ }
13
+ audio: {
14
+ /**
15
+ * Audio provider
16
+ * @default 'local'
17
+ */
18
+ provider?: string
19
+ /**
20
+ * Audio type
21
+ * @default 'audio/mpeg'
22
+ */
23
+ type?: string
24
+ } & (LocalAudio | DropboxAudio)
25
+ /**
26
+ * Color configuration
27
+ */
28
+ color?: {
29
+ /**
30
+ * Set if the color should be detected from the image
31
+ * @default false
32
+ */
33
+ detect?: boolean
34
+ /**
35
+ * Custom class to apply to the player
36
+ * @default 'musicfyplayer-color'
37
+ */
38
+ class?: string
39
+ }
40
+ }
41
+
42
+ export interface LocalAudio {
43
+ provider?: 'local'
44
+ /**
45
+ * Path to the audio file
46
+ * @example '/path/to/audio.mp3'
47
+ * @example 'https://example.com/audio.mp3'
48
+ */
49
+ src: string
50
+ }
51
+
52
+ export interface DropboxAudio {
53
+ provider?: 'dropbox'
54
+ id: string
55
+ rlkey?: string
56
+ }
57
+
58
+ export type AudioConfig = LocalAudio | DropboxAudio
59
+
60
+ export interface MusicfyPlayerConfig {
61
+ imageSrc: string
62
+ imageAlt: string
63
+ audioType: string
64
+ audioSrc: string
65
+ colorClass: string
66
+ colorDetect: boolean
67
+ }
@@ -1,5 +1,5 @@
1
1
  import 'mediaelement/build/mediaelement-and-player.js';
2
- import type { MediaElementPlayer, MediaElementPlayerOptions } from '../types/mediaelement';
2
+ import type { MediaElementPlayer, MediaElementPlayerOptions } from '../types/mediaelement.js';
3
3
  declare global {
4
4
  interface Window {
5
5
  MediaElementPlayer: MediaElementPlayer | undefined;
@@ -0,0 +1,10 @@
1
+ import "mediaelement/build/mediaelement-and-player.js";
2
+ import { createError } from "h3";
3
+ export const mediaElementPlayer = (element, options) => {
4
+ const MediaElementPlayer = window.MediaElementPlayer;
5
+ if (!import.meta.client)
6
+ throw createError({ status: 500, message: "MediaElementPlayer is not available on server side" });
7
+ if (!MediaElementPlayer)
8
+ throw createError({ status: 500, message: "MediaElementPlayer is not available" });
9
+ return new MediaElementPlayer(element, options);
10
+ };
package/dist/types.d.mts CHANGED
@@ -1,16 +1 @@
1
-
2
- import type { ModuleOptions } from './module.js'
3
-
4
-
5
- declare module '@nuxt/schema' {
6
- interface NuxtConfig { ['nuxtMusicfyPlayer']?: Partial<ModuleOptions> }
7
- interface NuxtOptions { ['nuxtMusicfyPlayer']?: ModuleOptions }
8
- }
9
-
10
- declare module 'nuxt/schema' {
11
- interface NuxtConfig { ['nuxtMusicfyPlayer']?: Partial<ModuleOptions> }
12
- interface NuxtOptions { ['nuxtMusicfyPlayer']?: ModuleOptions }
13
- }
14
-
15
-
16
- export type { ModuleOptions, default } from './module.js'
1
+ export { type ModuleOptions, default } from './module.js'
package/dist/types.d.ts CHANGED
@@ -1,16 +1 @@
1
-
2
- import type { ModuleOptions } from './module'
3
-
4
-
5
- declare module '@nuxt/schema' {
6
- interface NuxtConfig { ['nuxtMusicfyPlayer']?: Partial<ModuleOptions> }
7
- interface NuxtOptions { ['nuxtMusicfyPlayer']?: ModuleOptions }
8
- }
9
-
10
- declare module 'nuxt/schema' {
11
- interface NuxtConfig { ['nuxtMusicfyPlayer']?: Partial<ModuleOptions> }
12
- interface NuxtOptions { ['nuxtMusicfyPlayer']?: ModuleOptions }
13
- }
14
-
15
-
16
- export type { ModuleOptions, default } from './module'
1
+ export { type ModuleOptions, default } from './module'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-musicfyplayer",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Embed a simple and beautiful HTML music player from local or hosted audio on your website using MediaElement.js and ColorThief.js",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -34,27 +34,29 @@
34
34
  "dev": "nuxi dev playground",
35
35
  "dev:build": "nuxi build playground",
36
36
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
37
- "release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
37
+ "release": "npm run lint && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
38
38
  "lint": "eslint .",
39
39
  "test": "echo \"Error: no test specified\"",
40
+ "test:types": "vue-tsc --noEmit",
40
41
  "test:watch": "vitest watch"
41
42
  },
42
43
  "dependencies": {
43
- "@nuxt/kit": "^3.10.1",
44
+ "@nuxt/kit": "^3.12.3",
44
45
  "colorthief": "^2.4.0",
45
- "mediaelement": "^7.0.3"
46
+ "mediaelement": "^7.0.5"
46
47
  },
47
48
  "devDependencies": {
48
- "@nuxt/devtools": "^1.0.8",
49
- "@nuxt/eslint-config": "^0.2.0",
50
- "@nuxt/module-builder": "^0.5.5",
51
- "@nuxt/schema": "^3.10.1",
52
- "@nuxt/test-utils": "^3.11.0",
53
- "@types/node": "^20.11.17",
49
+ "@nuxt/devtools": "^1.3.9",
50
+ "@nuxt/eslint-config": "^0.3.13",
51
+ "@nuxt/module-builder": "^0.8.1",
52
+ "@nuxt/schema": "^3.12.3",
53
+ "@nuxt/test-utils": "^3.13.1",
54
+ "@types/node": "^20.14.10",
54
55
  "changelogen": "^0.5.5",
55
- "eslint": "^8.56.0",
56
- "nuxt": "^3.10.1",
57
- "vitest": "^1.2.2"
56
+ "eslint": "^9.6.0",
57
+ "nuxt": "^3.12.3",
58
+ "vitest": "^1.6.0",
59
+ "vue-tsc": "^2.0.26"
58
60
  },
59
61
  "changelog": {
60
62
  "repo": {
@@ -62,5 +64,6 @@
62
64
  "provider": "github",
63
65
  "domain": "github.com"
64
66
  }
65
- }
67
+ },
68
+ "packageManager": "pnpm@9.4.0"
66
69
  }
File without changes
File without changes
File without changes
@@ -1,9 +0,0 @@
1
- import "mediaelement/build/mediaelement-and-player.js";
2
- export const mediaElementPlayer = (element, options) => {
3
- const MediaElementPlayer = window.MediaElementPlayer;
4
- if (!process.client)
5
- throw new Error("MediaElementPlayer is not available on server side");
6
- if (!MediaElementPlayer)
7
- throw new Error("MediaElementPlayer is not available");
8
- return new MediaElementPlayer(element, options);
9
- };