nuxt-musicfyplayer 2.1.1 → 2.1.3

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-composable) | 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",
@@ -120,7 +120,7 @@ const config = defineMusicfyPlayer({
120
120
  rlkey: "g7sqo9y5zl3f69oxftzo5auc5"
121
121
  },
122
122
  image: {
123
- src: "https://dimatis.yizack.com/images/reminiscences.jpg",
123
+ src: "https://dimatis.music/images/reminiscences.jpg",
124
124
  alt: "Dimatis - Reminiscences"
125
125
  },
126
126
  color: {
package/dist/module.d.mts CHANGED
@@ -4,4 +4,5 @@ interface ModuleOptions {
4
4
  }
5
5
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
6
 
7
- export { type ModuleOptions, _default as default };
7
+ export { _default as default };
8
+ export type { ModuleOptions };
package/dist/module.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "2.1.1",
7
+ "version": "2.1.3",
8
8
  "builder": {
9
- "@nuxt/module-builder": "0.8.4",
10
- "unbuild": "2.0.0"
9
+ "@nuxt/module-builder": "1.0.0",
10
+ "unbuild": "3.5.0"
11
11
  }
12
12
  }
@@ -1,70 +1,52 @@
1
- <script setup lang='ts'>
2
- import ColorThief from 'colorthief'
3
- import type { MusicfyPlayerConfig } from './../types/musicfyplayer'
4
- import { onMounted, ref, type Ref } from '#imports'
5
-
6
- const props = defineProps({
7
- /**
8
- * The configuration of the player
9
- */
10
- config: {
11
- type: Object as () => MusicfyPlayerConfig,
12
- required: true,
13
- },
14
- /**
15
- * The width and height of the player
16
- * @default '100%'
17
- */
18
- width: {
19
- type: String,
20
- default: '100%',
21
- },
22
- /**
23
- * The height of the player
24
- * @default '450px'
25
- */
26
- height: {
27
- type: String,
28
- default: '450px',
29
- },
30
- })
31
-
32
- const audio = ref() as Ref<HTMLAudioElement>
33
- const size = ref({ width: props.width, height: props.height })
34
- const backgroundColor = ref<string | undefined>()
35
-
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
41
-
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
- }
47
- }
48
- }
49
-
50
- generateColor()
51
-
52
- onMounted(async () => {
53
- const { mediaElementPlayer } = await import('./../utils/mediaelement')
54
- mediaElementPlayer(audio.value, {
55
- iconSprite: '',
56
- audioHeight: 40,
57
- features: ['playpause', 'current', 'duration', 'progress', 'volume', 'tracks', 'fullscreen'],
58
- alwaysShowControls: true,
59
- timeAndDurationSeparator: '<span></span>',
60
- iPadUseNativeControls: false,
61
- iPhoneUseNativeControls: false,
62
- AndroidUseNativeControls: false,
63
- })
64
- })
65
- </script>
66
-
67
- <template>
1
+ <script setup>
2
+ import ColorThief from "colorthief";
3
+ import { onMounted, ref, useTemplateRef } from "#imports";
4
+ const props = defineProps({
5
+ config: {
6
+ type: Object,
7
+ required: true
8
+ },
9
+ width: {
10
+ type: String,
11
+ required: false,
12
+ default: "100%"
13
+ },
14
+ height: {
15
+ type: String,
16
+ required: false,
17
+ default: "450px"
18
+ }
19
+ });
20
+ const audio = useTemplateRef("audio");
21
+ const size = ref({ width: props.width, height: props.height });
22
+ const backgroundColor = ref();
23
+ if (import.meta.client && props.config.colorDetect) {
24
+ const img = new Image();
25
+ img.crossOrigin = "Anonymous";
26
+ img.src = props.config.imageSrc;
27
+ img.onload = () => {
28
+ const colorThief = new ColorThief();
29
+ const color = colorThief.getColor(img);
30
+ backgroundColor.value = color ? `rgb(${color[0]}, ${color[1]}, ${color[2]})` : void 0;
31
+ };
32
+ }
33
+ onMounted(async () => {
34
+ if (!audio.value) return;
35
+ const { mediaElementPlayer } = await import("./../utils/mediaelement");
36
+ mediaElementPlayer(audio.value, {
37
+ iconSprite: "",
38
+ audioHeight: 40,
39
+ features: ["playpause", "current", "duration", "progress", "volume", "tracks", "fullscreen"],
40
+ alwaysShowControls: true,
41
+ timeAndDurationSeparator: "<span></span>",
42
+ iPadUseNativeControls: false,
43
+ iPhoneUseNativeControls: false,
44
+ AndroidUseNativeControls: false
45
+ });
46
+ });
47
+ </script>
48
+
49
+ <template>
68
50
  <div class="musicfyplayer" :class="{ [`${config.colorClass}`]: config.colorClass }" :style="{ ...size, backgroundColor }">
69
51
  <div class="mp__box">
70
52
  <div class="mp__controls">
@@ -83,8 +65,8 @@ onMounted(async () => {
83
65
  </div>
84
66
  </div>
85
67
  </div>
86
- </template>
87
-
68
+ </template>
69
+
88
70
  <style>
89
71
  @import "./../assets/css/musicfyplayer.css";
90
- </style>
72
+ </style>
@@ -0,0 +1,22 @@
1
+ import type { MusicfyPlayerConfig } from './../types/musicfyplayer.js';
2
+ type __VLS_Props = {
3
+ /**
4
+ * The configuration of the player
5
+ */
6
+ config: MusicfyPlayerConfig;
7
+ /**
8
+ * The width and height of the player
9
+ * @default '100%'
10
+ */
11
+ width?: string;
12
+ /**
13
+ * The height of the player
14
+ * @default '450px'
15
+ */
16
+ height?: string;
17
+ };
18
+ declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
19
+ width: string;
20
+ height: string;
21
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
22
+ export default _default;
@@ -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 = "local">(config: MusicfyPlayerComposableConfig<T>) => MusicfyPlayerConfig;
9
+ export declare const defineMusicfyPlayer: <T extends keyof Providers = "local">(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/dist/types.d.mts CHANGED
@@ -1 +1,3 @@
1
- export { type ModuleOptions, default } from './module.js'
1
+ export { default } from './module.mjs'
2
+
3
+ export { type ModuleOptions } from './module.mjs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-musicfyplayer",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
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",
@@ -16,19 +16,17 @@
16
16
  "author": {
17
17
  "name": "Yizack Rangel",
18
18
  "email": "yizackr@gmail.com",
19
- "url": "https://yizack.com/"
19
+ "url": "https://yizack.com"
20
20
  },
21
21
  "license": "MIT",
22
22
  "type": "module",
23
23
  "exports": {
24
24
  ".": {
25
- "types": "./dist/types.d.ts",
26
- "import": "./dist/module.mjs",
27
- "require": "./dist/module.cjs"
25
+ "types": "./dist/types.d.mts",
26
+ "import": "./dist/module.mjs"
28
27
  }
29
28
  },
30
- "main": "./dist/module.cjs",
31
- "types": "./dist/types.d.ts",
29
+ "main": "./dist/module.mjs",
32
30
  "files": [
33
31
  "dist"
34
32
  ],
@@ -39,34 +37,28 @@
39
37
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
40
38
  "release": "npm run lint && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
41
39
  "lint": "eslint .",
40
+ "lint:fix": "eslint . --fix",
42
41
  "test": "echo \"Error: no test specified\"",
43
42
  "test:types": "vue-tsc --noEmit",
44
43
  "test:watch": "vitest watch"
45
44
  },
46
45
  "dependencies": {
47
- "@nuxt/kit": "^3.13.2",
46
+ "@nuxt/kit": "^3.16.2",
48
47
  "colorthief": "2.4.0",
49
- "mediaelement": "^7.0.5"
48
+ "mediaelement": "^7.0.7"
50
49
  },
51
50
  "devDependencies": {
52
- "@nuxt/devtools": "^1.6.0",
53
- "@nuxt/eslint-config": "^0.5.7",
54
- "@nuxt/module-builder": "^0.8.4",
55
- "@nuxt/schema": "^3.13.2",
56
- "@nuxt/test-utils": "^3.14.3",
57
- "@types/node": "^22.7.5",
58
- "changelogen": "^0.5.7",
59
- "eslint": "^9.12.0",
60
- "nuxt": "^3.13.2",
61
- "vitest": "^2.1.2",
62
- "vue-tsc": "^2.1.6"
51
+ "@nuxt/devtools": "^2.3.2",
52
+ "@nuxt/eslint-config": "^1.3.0",
53
+ "@nuxt/module-builder": "^1.0.0",
54
+ "@nuxt/schema": "^3.16.2",
55
+ "@nuxt/test-utils": "^3.17.2",
56
+ "@types/node": "^22.14.0",
57
+ "changelogen": "^0.6.1",
58
+ "eslint": "^9.24.0",
59
+ "nuxt": "^3.16.2",
60
+ "vitest": "^3.1.1",
61
+ "vue-tsc": "^2.2.8"
63
62
  },
64
- "changelog": {
65
- "repo": {
66
- "repo": "Yizack/nuxt-musicfyplayer",
67
- "provider": "github",
68
- "domain": "github.com"
69
- }
70
- },
71
- "packageManager": "pnpm@9.12.1"
72
- }
63
+ "packageManager": "pnpm@10.7.1"
64
+ }
package/dist/module.cjs DELETED
@@ -1,5 +0,0 @@
1
- module.exports = function(...args) {
2
- return import('./module.mjs').then(m => m.default.call(this, ...args))
3
- }
4
- const _meta = module.exports.meta = require('./module.json')
5
- module.exports.getMeta = () => Promise.resolve(_meta)
package/dist/module.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import * as _nuxt_schema from '@nuxt/schema';
2
-
3
- interface ModuleOptions {
4
- }
5
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
-
7
- export { type ModuleOptions, _default as default };
package/dist/types.d.ts DELETED
@@ -1 +0,0 @@
1
- export { type ModuleOptions, default } from './module'