nuxt-musicfyplayer 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Yizack Rangel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # nuxt-musicfyplayer
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![License][license-src]][license-href]
6
+ [![Tests][tests-src]][tests-href]
7
+ [![Nuxt][nuxt-src]][nuxt-href]
8
+
9
+ Embed a simple and beautiful HTML music player from local or hosted audio on your website using MediaElement.js and ColorThief.js
10
+
11
+ - [✨ Release Notes](https://github.com/Yizack/nuxt-musicfyplayer/blob/main/CHANGELOG.md)
12
+ - [🏀 Online playground](https://stackblitz.com/github/yizack/nuxt-musicfyplayer?file=playground%2Fapp.vue)
13
+
14
+ ## Development
15
+
16
+ ```bash
17
+ # Install dependencies
18
+ npm install
19
+
20
+ # Generate type stubs
21
+ npm run dev:prepare
22
+
23
+ # Develop with the playground
24
+ npm run dev
25
+
26
+ # Build the playground
27
+ npm run dev:build
28
+
29
+ # Run ESLint
30
+ npm run lint
31
+
32
+ # Run Vitest
33
+ npm run test
34
+ npm run test:watch
35
+
36
+ # Release new version
37
+ npm run release
38
+ ```
39
+
40
+ <!-- Badges -->
41
+ [npm-version-src]: https://img.shields.io/npm/v/nuxt-musicfyplayer/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
42
+ [npm-version-href]: https://npmjs.com/package/nuxt-musicfyplayer
43
+
44
+ [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-musicfyplayer.svg?style=flat&colorA=18181B&colorB=28CF8D
45
+ [npm-downloads-href]: https://npmjs.com/package/nuxt-musicfyplayer
46
+
47
+ [license-src]: https://img.shields.io/npm/l/nuxt-musicfyplayer.svg?style=flat&colorA=18181B&colorB=28CF8D
48
+ [license-href]: LICENSE
49
+
50
+ [tests-src]: https://img.shields.io/github/actions/workflow/status/Yizack/nuxt-musicfyplayer/tests.yml?style=flat&colorA=18181B&colorB=28CF8D&label=tests
51
+ [tests-href]: https://github.com/Yizack/nuxt-musicfyplayer/actions/workflows/tests.yml
52
+
53
+ [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
54
+ [nuxt-href]: https://nuxt.com
@@ -0,0 +1,5 @@
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)
@@ -0,0 +1,7 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ interface ModuleOptions {
4
+ }
5
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
6
+
7
+ export { type ModuleOptions, _default as default };
@@ -0,0 +1,7 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ interface ModuleOptions {
4
+ }
5
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
6
+
7
+ export { type ModuleOptions, _default as default };
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "nuxt-musicfyplayer",
3
+ "configKey": "nuxtMusicfyPlayer",
4
+ "compatibility": {
5
+ "nuxt": "^3.0.0"
6
+ },
7
+ "version": "1.0.0"
8
+ }
@@ -0,0 +1,22 @@
1
+ import { defineNuxtModule, createResolver, addComponent, addImportsDir } from '@nuxt/kit';
2
+
3
+ const module = defineNuxtModule({
4
+ meta: {
5
+ name: "nuxt-musicfyplayer",
6
+ configKey: "nuxtMusicfyPlayer",
7
+ compatibility: {
8
+ nuxt: "^3.0.0"
9
+ }
10
+ },
11
+ setup() {
12
+ const { resolve } = createResolver(import.meta.url);
13
+ addComponent({
14
+ name: "MusicfyPlayer",
15
+ global: true,
16
+ filePath: resolve("./runtime/components/MusicfyPlayer.vue")
17
+ });
18
+ addImportsDir(resolve("./runtime/composables"));
19
+ }
20
+ });
21
+
22
+ export { module as default };
@@ -0,0 +1 @@
1
+ .mejs__container,.mejs__controls{background:transparent!important}.mejs__container{min-width:100%!important;width:100%!important}.mejs__controls{display:flex!important;flex-direction:column!important;padding:0!important}.mejs__button{width:100%!important}.mejs__button>button{overflow:visible!important}.mejs__button,.mejs__time,.mejs__time-rail{height:0!important}.mejs__time-rail{margin:0!important;padding:0!important;width:100%!important}.mejs__time{display:flex!important;height:2rem!important;justify-content:space-between!important;padding:0!important}.mejs__pause button,.mejs__play button{margin:0;top:-.5rem}.mejs__currenttime,.mejs__duration{align-self:flex-end!important}.mejs__play button:before{content:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='%23fff' viewBox='4 3.5 9 9'%3E%3Cpath d='m11.596 8.697-6.363 3.692c-.54.313-1.233-.066-1.233-.697V4.308c0-.63.692-1.01 1.233-.696l6.363 3.692a.802.802 0 0 1 0 1.393'/%3E%3C/svg%3E")}.mejs__pause button:before{content:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='%23fff' viewBox='4 3.5 9 9'%3E%3Cpath d='M5.5 3.5A1.5 1.5 0 0 1 7 5v6a1.5 1.5 0 0 1-3 0V5a1.5 1.5 0 0 1 1.5-1.5m5 0A1.5 1.5 0 0 1 12 5v6a1.5 1.5 0 0 1-3 0V5a1.5 1.5 0 0 1 1.5-1.5'/%3E%3C/svg%3E")}.mejs__volume-button button{margin:0;right:3.5rem;top:-3.05rem}.mejs__volume-button.mejs__mute button:before{content:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='%23fff' viewBox='1 1.5 13 13'%3E%3Cpath d='M11.536 14.01A8.47 8.47 0 0 0 14.026 8a8.47 8.47 0 0 0-2.49-6.01l-.708.707A7.48 7.48 0 0 1 13.025 8c0 2.071-.84 3.946-2.197 5.303z'/%3E%3Cpath d='M10.121 12.596A6.48 6.48 0 0 0 12.025 8a6.48 6.48 0 0 0-1.904-4.596l-.707.707A5.48 5.48 0 0 1 11.025 8a5.48 5.48 0 0 1-1.61 3.89z'/%3E%3Cpath d='M8.707 11.182A4.49 4.49 0 0 0 10.025 8a4.49 4.49 0 0 0-1.318-3.182L8 5.525A3.5 3.5 0 0 1 9.025 8 3.5 3.5 0 0 1 8 10.475zM6.717 3.55A.5.5 0 0 1 7 4v8a.5.5 0 0 1-.812.39L3.825 10.5H1.5A.5.5 0 0 1 1 10V6a.5.5 0 0 1 .5-.5h2.325l2.363-1.89a.5.5 0 0 1 .529-.06'/%3E%3C/svg%3E")}.mejs__volume-button.mejs__unmute button:before{content:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='%23fff' viewBox='1 1.5 13 13'%3E%3Cpath d='M6.717 3.55A.5.5 0 0 1 7 4v8a.5.5 0 0 1-.812.39L3.825 10.5H1.5A.5.5 0 0 1 1 10V6a.5.5 0 0 1 .5-.5h2.325l2.363-1.89a.5.5 0 0 1 .529-.06m7.137 2.096a.5.5 0 0 1 0 .708L12.207 8l1.647 1.646a.5.5 0 0 1-.708.708L11.5 8.707l-1.646 1.647a.5.5 0 0 1-.708-.708L10.793 8 9.146 6.354a.5.5 0 1 1 .708-.708L11.5 7.293l1.646-1.647a.5.5 0 0 1 .708 0'/%3E%3C/svg%3E")}.mejs__horizontal-volume-slider{height:0!important;width:100%!important}.mejs__horizontal-volume-total{background:hsla(0,0%,100%,.3)!important;cursor:pointer;left:unset!important;right:0!important;top:-2.75rem!important}.mejs__pause svg.mejs__icon-pause,.mejs__play svg.mejs__icon-play,.mejs__replay svg.mejs__icon-replay{display:none}.musicfyplayer{border-radius:.5rem!important;overflow:hidden;text-align:center}@media (width <= 385px){.musicfyplayer{height:unset!important}}.musicfyplayer.musicfyplayer-color{background-color:#020420}.musicfyplayer .box{background:linear-gradient(rgba(0,0,0,.2),rgba(0,0,0,.8));display:flex;flex-direction:column;height:100%;position:relative}.musicfyplayer .controls{color:#fff;padding:1.5rem 1rem}.musicfyplayer .music{width:100%}.musicfyplayer .cover{background-color:rgba(0,0,0,.4);flex:1 1 0%}.musicfyplayer .box-1,.musicfyplayer .cover{height:100%;overflow-y:hidden}.musicfyplayer .box-2{box-sizing:border-box;height:100%;padding:.5rem;position:relative;width:100%}.musicfyplayer .box-3{height:100%;min-width:80px;position:relative;width:100%}.musicfyplayer .image{background-position:top!important;background-repeat:no-repeat!important;background-size:contain!important;max-height:100%;max-width:100%;position:relative}
@@ -0,0 +1,73 @@
1
+ <script setup lang='ts'>
2
+ import { onMounted, ref, type Ref } from '#imports'
3
+ import type { MusicfyPlayerConfig } from './../types/musicfyplayer'
4
+ import ColorThief from 'colorthief'
5
+
6
+ const props = defineProps({
7
+ config: {
8
+ type: Object as () => MusicfyPlayerConfig,
9
+ required: true
10
+ }
11
+ })
12
+
13
+ const audio = ref() as Ref<HTMLAudioElement>
14
+ const size = ref({ width: props.config.sizeWidth, height: props.config.sizeHeight })
15
+ const backgroundColor = ref<string | undefined>()
16
+
17
+ const generateColor = async () => {
18
+ if (process.client && props.config.colorDetect) {
19
+ const img = new Image()
20
+ img.crossOrigin = 'Anonymous'
21
+ img.src = props.config.imageSrc
22
+
23
+ img.onload = () => {
24
+ const colorThief = new ColorThief()
25
+ const color = colorThief.getColor(img)
26
+ backgroundColor.value = color ? `rgb(${color[0]}, ${color[1]}, ${color[2]})` : undefined
27
+ }
28
+ }
29
+ }
30
+
31
+ generateColor()
32
+
33
+ onMounted(async () => {
34
+ const { mediaElementPlayer } = await import('./../utils/mediaelement')
35
+ mediaElementPlayer(audio.value, {
36
+ iconSprite: '',
37
+ audioHeight: 40,
38
+ features: ['playpause', 'current', 'duration', 'progress', 'volume', 'tracks', 'fullscreen'],
39
+ alwaysShowControls: true,
40
+ timeAndDurationSeparator: '<span></span>',
41
+ iPadUseNativeControls: false,
42
+ iPhoneUseNativeControls: false,
43
+ AndroidUseNativeControls: false
44
+ })
45
+ })
46
+ </script>
47
+
48
+ <template>
49
+ <div class="musicfyplayer" :class="{ [`${config.colorClass}`]: config.colorClass }" :style="{ ...size, backgroundColor }">
50
+ <div class="box">
51
+ <div class="controls">
52
+ <div class="lecteur">
53
+ <audio ref="audio" class="music fc-media">
54
+ <source :src="config.audioSrc" :type="config.audioType">
55
+ </audio>
56
+ </div>
57
+ </div>
58
+ <div class="cover">
59
+ <div class="box-1">
60
+ <div class="box-2">
61
+ <div class="box-3">
62
+ <img class="image" :src="config.imageSrc" :alt="config.imageAlt">
63
+ </div>
64
+ </div>
65
+ </div>
66
+ </div>
67
+ </div>
68
+ </div>
69
+ </template>
70
+
71
+ <style>
72
+ @import "mediaelement/build/mediaelementplayer.min.css";@import "./../assets/css/musicfyplayer.css";
73
+ </style>
@@ -0,0 +1,2 @@
1
+ import type { MusicfyPlayerConfig, MusicfyPlayerDefinition } from './../types/musicfyplayer';
2
+ export declare const defineMusicfyPlayer: (config: MusicfyPlayerDefinition) => MusicfyPlayerConfig;
@@ -0,0 +1,35 @@
1
+ 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) => {
7
+ const audioSrc = ref();
8
+ const provider = config.audio.provider || "local";
9
+ const size = {
10
+ width: config.size?.width || "100%",
11
+ height: config.size?.height || "100%"
12
+ };
13
+ switch (provider) {
14
+ default:
15
+ case "local":
16
+ audioSrc.value = config.audio.src;
17
+ break;
18
+ case "dropbox":
19
+ audioSrc.value = srcDropbox(config.audio.id, config.audio.rlkey);
20
+ break;
21
+ }
22
+ if (!audioSrc.value) {
23
+ throw new Error("Invalid audio source");
24
+ }
25
+ return {
26
+ imageSrc: config.image.src,
27
+ imageAlt: config.image.alt,
28
+ audioType: config.audio.type,
29
+ audioSrc: audioSrc.value,
30
+ sizeWidth: size.width,
31
+ sizeHeight: size.height,
32
+ colorClass: config.color?.class || "musicfyplayer-color",
33
+ colorDetect: config.color?.detect || false
34
+ };
35
+ };
@@ -0,0 +1,7 @@
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
+ }
File without changes
@@ -0,0 +1,13 @@
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
+ }
File without changes
@@ -0,0 +1,38 @@
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
+ }
File without changes
@@ -0,0 +1,8 @@
1
+ import 'mediaelement/build/mediaelement-and-player.js';
2
+ import type { MediaElementPlayer, MediaElementPlayerOptions } from '../types/mediaelement';
3
+ declare global {
4
+ interface Window {
5
+ MediaElementPlayer: MediaElementPlayer | undefined;
6
+ }
7
+ }
8
+ export declare const mediaElementPlayer: (element: HTMLAudioElement, options: MediaElementPlayerOptions) => void;
@@ -0,0 +1,9 @@
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
+ };
@@ -0,0 +1,16 @@
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'
@@ -0,0 +1,16 @@
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'
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "nuxt-musicfyplayer",
3
+ "version": "1.0.0",
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
+ "keywords": [
6
+ "nuxt",
7
+ "nuxt3",
8
+ "music-player",
9
+ "music"
10
+ ],
11
+ "repository": "Yizack/nuxt-musicfyplayer",
12
+ "homepage": "https://github.com/Yizack/nuxt-musicfyplayer",
13
+ "author": {
14
+ "name": "Yizack Rangel",
15
+ "email": "yizackr@gmail.com",
16
+ "url": "https://yizack.com/"
17
+ },
18
+ "license": "MIT",
19
+ "type": "module",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/types.d.ts",
23
+ "import": "./dist/module.mjs",
24
+ "require": "./dist/module.cjs"
25
+ }
26
+ },
27
+ "main": "./dist/module.cjs",
28
+ "types": "./dist/types.d.ts",
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "scripts": {
33
+ "prepack": "nuxt-module-build build",
34
+ "dev": "nuxi dev playground",
35
+ "dev:build": "nuxi build playground",
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",
38
+ "lint": "eslint .",
39
+ "test": "echo \"Error: no test specified\"",
40
+ "test:watch": "vitest watch"
41
+ },
42
+ "dependencies": {
43
+ "@nuxt/kit": "^3.10.1",
44
+ "colorthief": "^2.4.0",
45
+ "mediaelement": "^7.0.3"
46
+ },
47
+ "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",
54
+ "changelogen": "^0.5.5",
55
+ "eslint": "^8.56.0",
56
+ "nuxt": "^3.10.1",
57
+ "vitest": "^1.2.2"
58
+ },
59
+ "changelog": {
60
+ "repo": {
61
+ "repo": "Yizack/nuxt-musicfyplayer",
62
+ "provider": "github",
63
+ "domain": "github.com"
64
+ }
65
+ }
66
+ }