nuxt-musicfyplayer 2.1.4 → 2.1.5
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/dist/module.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<script setup>
|
2
|
-
import {
|
2
|
+
import { getImageAverageColor } from "./../utils/average-color";
|
3
3
|
import { onMounted, ref, useTemplateRef } from "#imports";
|
4
4
|
const props = defineProps({
|
5
5
|
config: {
|
@@ -21,14 +21,9 @@ const audio = useTemplateRef("audio");
|
|
21
21
|
const size = ref({ width: props.width, height: props.height });
|
22
22
|
const backgroundColor = ref();
|
23
23
|
if (import.meta.client && props.config.colorDetect) {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
img.onload = () => {
|
28
|
-
const fac = new FastAverageColor();
|
29
|
-
const color = fac.getColor(img);
|
30
|
-
backgroundColor.value = color ? color.rgba : void 0;
|
31
|
-
};
|
24
|
+
getImageAverageColor(props.config.imageSrc).then((color) => {
|
25
|
+
backgroundColor.value = color;
|
26
|
+
}).catch(console.error);
|
32
27
|
}
|
33
28
|
onMounted(async () => {
|
34
29
|
if (!audio.value) return;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getImageAverageColor: (src: string) => Promise<string>;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { FastAverageColor } from "fast-average-color";
|
2
|
+
const fac = new FastAverageColor();
|
3
|
+
export const getImageAverageColor = (src) => {
|
4
|
+
return new Promise((resolve, reject) => {
|
5
|
+
const img = new Image();
|
6
|
+
img.crossOrigin = "Anonymous";
|
7
|
+
img.src = src;
|
8
|
+
img.onload = () => {
|
9
|
+
const color = fac.getColor(img);
|
10
|
+
resolve(color.rgb);
|
11
|
+
};
|
12
|
+
img.onerror = () => {
|
13
|
+
reject(new Error(`Failed to load image: ${src}`));
|
14
|
+
};
|
15
|
+
});
|
16
|
+
};
|
package/package.json
CHANGED