nuxt-musicfyplayer 2.1.0 → 2.1.2

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
@@ -49,13 +49,13 @@ In the project, use the component `<MusicfyPlayer :config="" />`, where `config`
49
49
 
50
50
  | Property | Description | Default value |
51
51
  |---------------------------------------|--------------------------|---------------|
52
- | [`config`](#musicfyplayer-definition) | MusicfyPlayer definition | |
52
+ | [`config`](#musicfyplayer-composale) | MusicfyPlayer composable | |
53
53
  | `width` | Music player width | `100%` |
54
54
  | `height` | Music player height | `450px` |
55
55
 
56
- ## MusicfyPlayer Definition
56
+ ## MusicfyPlayer composable
57
57
 
58
- Define your configuration options with the `defineMusicfyPlayer` composable.
58
+ Define your configuration options with the `useMusicfyPlayer` composable.
59
59
 
60
60
  | Property | Description |
61
61
  |-------------------------------------|---------------------------------------|
@@ -108,11 +108,11 @@ Define your configuration options with the `defineMusicfyPlayer` composable.
108
108
 
109
109
  ## Example
110
110
 
111
- Use the emoji property to render an emoji by character.
111
+ Use the `useMusicfyPlayer` composable to define the configuration options of the player.
112
112
 
113
113
  ```html
114
114
  <script setup lang="ts">
115
- const config = defineMusicfyPlayer({
115
+ const config = useMusicfyPlayer({
116
116
  audio: {
117
117
  provider: "dropbox",
118
118
  preload: "none",
package/dist/module.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "2.1.0",
7
+ "version": "2.1.2",
8
8
  "builder": {
9
- "@nuxt/module-builder": "0.8.3",
9
+ "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
11
11
  }
12
12
  }
@@ -1,55 +1,47 @@
1
1
  <script setup lang='ts'>
2
2
  import ColorThief from 'colorthief'
3
3
  import type { MusicfyPlayerConfig } from './../types/musicfyplayer'
4
- import { onMounted, ref, type Ref } from '#imports'
4
+ import { onMounted, ref, useTemplateRef } from '#imports'
5
5
 
6
- const props = defineProps({
6
+ const props = withDefaults(defineProps<{
7
7
  /**
8
8
  * The configuration of the player
9
9
  */
10
- config: {
11
- type: Object as () => MusicfyPlayerConfig,
12
- required: true,
13
- },
10
+ config: MusicfyPlayerConfig
14
11
  /**
15
12
  * The width and height of the player
16
13
  * @default '100%'
17
14
  */
18
- width: {
19
- type: String,
20
- default: '100%',
21
- },
15
+ width?: string
22
16
  /**
23
17
  * The height of the player
24
18
  * @default '450px'
25
19
  */
26
- height: {
27
- type: String,
28
- default: '450px',
29
- },
20
+ height?: string
21
+ }>(), {
22
+ width: '100%',
23
+ height: '450px',
30
24
  })
31
25
 
32
- const audio = ref() as Ref<HTMLAudioElement>
26
+ const audio = useTemplateRef<HTMLAudioElement>('audio')
27
+
33
28
  const size = ref({ width: props.width, height: props.height })
34
29
  const backgroundColor = ref<string | undefined>()
35
30
 
36
- const generateColor = async () => {
37
- if (import.meta.client && props.config.colorDetect) {
38
- const img = new Image()
39
- img.crossOrigin = 'Anonymous'
40
- img.src = props.config.imageSrc
31
+ if (import.meta.client && props.config.colorDetect) {
32
+ const img = new Image()
33
+ img.crossOrigin = 'Anonymous'
34
+ img.src = props.config.imageSrc
41
35
 
42
- img.onload = () => {
43
- const colorThief = new ColorThief()
44
- const color = colorThief.getColor(img)
45
- backgroundColor.value = color ? `rgb(${color[0]}, ${color[1]}, ${color[2]})` : undefined
46
- }
36
+ img.onload = () => {
37
+ const colorThief = new ColorThief()
38
+ const color = colorThief.getColor(img)
39
+ backgroundColor.value = color ? `rgb(${color[0]}, ${color[1]}, ${color[2]})` : undefined
47
40
  }
48
41
  }
49
42
 
50
- generateColor()
51
-
52
43
  onMounted(async () => {
44
+ if (!audio.value) return
53
45
  const { mediaElementPlayer } = await import('./../utils/mediaelement')
54
46
  mediaElementPlayer(audio.value, {
55
47
  iconSprite: '',
@@ -1,2 +1,9 @@
1
- import type { MusicfyPlayerConfig, MusicfyPlayerDefinition } from './../types/musicfyplayer.js';
2
- export declare const defineMusicfyPlayer: (config: MusicfyPlayerDefinition) => MusicfyPlayerConfig;
1
+ import type { Providers } from '../types/providers.js';
2
+ import type { MusicfyPlayerConfig, MusicfyPlayerComposableConfig } from './../types/musicfyplayer.js';
3
+ /**
4
+ * Musicfy Player composable
5
+ * @param config - Musicfy Player composable configuration
6
+ * @returns Musicfy Player configuration
7
+ */
8
+ export declare const useMusicfyPlayer: <T extends keyof Providers>(config: MusicfyPlayerComposableConfig<T>) => MusicfyPlayerConfig;
9
+ export declare const defineMusicfyPlayer: <T extends keyof Providers>(config: MusicfyPlayerComposableConfig<T>) => MusicfyPlayerConfig;
@@ -1,20 +1,9 @@
1
+ import { getSource } from "../utils/sources.js";
1
2
  import { ref } from "#imports";
2
- const srcDropbox = (id, rlkey) => {
3
- const dropboxBase = "https://www.dropbox.com";
4
- return rlkey ? `${dropboxBase}/scl/fi/${id}/?rlkey=${rlkey}&dl=1` : `${dropboxBase}/s/${id}?dl=1`;
5
- };
6
- export const defineMusicfyPlayer = (config) => {
3
+ export const useMusicfyPlayer = (config) => {
7
4
  const audioSrc = ref();
8
5
  const provider = config.audio.provider || "local";
9
- switch (provider) {
10
- default:
11
- case "local":
12
- audioSrc.value = config.audio.src;
13
- break;
14
- case "dropbox":
15
- audioSrc.value = srcDropbox(config.audio.id, config.audio.rlkey);
16
- break;
17
- }
6
+ audioSrc.value = getSource(provider, config.audio);
18
7
  if (!audioSrc.value) throw new Error("Invalid audio source");
19
8
  return {
20
9
  imageSrc: config.image.src,
@@ -26,3 +15,4 @@ export const defineMusicfyPlayer = (config) => {
26
15
  colorDetect: config.color?.detect || false
27
16
  };
28
17
  };
18
+ export const defineMusicfyPlayer = useMusicfyPlayer;
@@ -1,4 +1,6 @@
1
- export interface MusicfyPlayerDefinition {
1
+ import type { Providers } from './providers'
2
+
3
+ export interface MusicfyPlayerComposableConfig<T extends keyof Providers> {
2
4
  /**
3
5
  * Image configuration
4
6
  */
@@ -10,12 +12,15 @@ export interface MusicfyPlayerDefinition {
10
12
  */
11
13
  alt?: string
12
14
  }
15
+ /**
16
+ * Audio configuration
17
+ */
13
18
  audio: {
14
19
  /**
15
20
  * Audio provider
16
21
  * @default 'local'
17
22
  */
18
- provider?: string
23
+ provider?: T
19
24
  /**
20
25
  * Audio type
21
26
  * @default 'audio/mpeg'
@@ -26,7 +31,7 @@ export interface MusicfyPlayerDefinition {
26
31
  * @default 'auto'
27
32
  */
28
33
  preload?: 'auto' | 'metadata' | 'none'
29
- } & (LocalAudio | DropboxAudio)
34
+ } & Providers[T]
30
35
  /**
31
36
  * Color configuration
32
37
  */
@@ -44,30 +49,12 @@ export interface MusicfyPlayerDefinition {
44
49
  }
45
50
  }
46
51
 
47
- export interface LocalAudio {
48
- provider?: 'local'
49
- /**
50
- * Path to the audio file
51
- * @example '/path/to/audio.mp3'
52
- * @example 'https://example.com/audio.mp3'
53
- */
54
- src: string
55
- }
56
-
57
- export interface DropboxAudio {
58
- provider?: 'dropbox'
59
- id: string
60
- rlkey?: string
61
- }
62
-
63
- export type AudioConfig = LocalAudio | DropboxAudio
64
-
65
52
  export interface MusicfyPlayerConfig {
66
53
  imageSrc: string
67
54
  imageAlt: string
68
55
  audioType: string
69
56
  audioSrc: string
70
- audioPreload: MusicfyPlayerDefinition['audio']['preload']
57
+ audioPreload: MusicfyPlayerComposableConfig['audio']['preload']
71
58
  colorClass: string
72
59
  colorDetect: boolean
73
60
  }
@@ -0,0 +1,14 @@
1
+ export interface Providers {
2
+ local: {
3
+ /**
4
+ * Path to the audio file
5
+ * @example '/path/to/audio.mp3'
6
+ * @example 'https://example.com/audio.mp3'
7
+ */
8
+ src: string
9
+ }
10
+ dropbox: {
11
+ id: string
12
+ rlkey?: string
13
+ }
14
+ }
@@ -0,0 +1,2 @@
1
+ import type { Providers } from '../types/providers.js';
2
+ export declare const getSource: <T extends keyof Providers>(provider: T, config: Providers[keyof Providers]) => string;
@@ -0,0 +1,13 @@
1
+ const getDropboxSource = (id, rlkey) => {
2
+ const dropboxBase = "https://www.dropbox.com";
3
+ return rlkey ? `${dropboxBase}/scl/fi/${id}/?rlkey=${rlkey}&dl=1` : `${dropboxBase}/s/${id}?dl=1`;
4
+ };
5
+ export const getSource = (provider, config) => {
6
+ switch (provider) {
7
+ default:
8
+ case "local":
9
+ return config.src;
10
+ case "dropbox":
11
+ return getDropboxSource(config.id, config.rlkey);
12
+ }
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-musicfyplayer",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
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",
@@ -39,27 +39,28 @@
39
39
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
40
40
  "release": "npm run lint && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
41
41
  "lint": "eslint .",
42
+ "lint:fix": "eslint . --fix",
42
43
  "test": "echo \"Error: no test specified\"",
43
44
  "test:types": "vue-tsc --noEmit",
44
45
  "test:watch": "vitest watch"
45
46
  },
46
47
  "dependencies": {
47
- "@nuxt/kit": "^3.13.1",
48
- "colorthief": "^2.4.0",
49
- "mediaelement": "^7.0.5"
48
+ "@nuxt/kit": "^3.15.4",
49
+ "colorthief": "2.4.0",
50
+ "mediaelement": "^7.0.7"
50
51
  },
51
52
  "devDependencies": {
52
- "@nuxt/devtools": "^1.4.1",
53
- "@nuxt/eslint-config": "^0.5.6",
54
- "@nuxt/module-builder": "^0.8.3",
55
- "@nuxt/schema": "^3.13.1",
56
- "@nuxt/test-utils": "^3.14.1",
57
- "@types/node": "^22.5.4",
58
- "changelogen": "^0.5.5",
59
- "eslint": "^9.9.1",
60
- "nuxt": "^3.13.1",
61
- "vitest": "^2.0.5",
62
- "vue-tsc": "^2.1.6"
53
+ "@nuxt/devtools": "^2.0.0",
54
+ "@nuxt/eslint-config": "^1.0.1",
55
+ "@nuxt/module-builder": "^0.8.4",
56
+ "@nuxt/schema": "^3.15.4",
57
+ "@nuxt/test-utils": "^3.15.4",
58
+ "@types/node": "^22.13.1",
59
+ "changelogen": "^0.5.7",
60
+ "eslint": "^9.20.0",
61
+ "nuxt": "^3.15.4",
62
+ "vitest": "^3.0.5",
63
+ "vue-tsc": "^2.2.0"
63
64
  },
64
65
  "changelog": {
65
66
  "repo": {
@@ -68,5 +69,5 @@
68
69
  "domain": "github.com"
69
70
  }
70
71
  },
71
- "packageManager": "pnpm@9.9.0"
72
- }
72
+ "packageManager": "pnpm@10.2.1"
73
+ }