nuxt-glorious 1.3.2 → 1.3.3-1
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,6 @@
|
|
1
1
|
declare const _default: () => {
|
2
2
|
debounce: (callback: () => void, delay: number) => void;
|
3
3
|
numbersWithSeparateSamePrice: (value: String) => string;
|
4
|
+
compressImage: (file: any, MAX_WIDTH?: number, MAX_HEIGHT?: number, QUALITY?: number) => Promise<Blob>;
|
4
5
|
};
|
5
6
|
export default _default;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { GloriousStore } from "../stores/GloriousStore.mjs";
|
2
|
+
import compressImage from "../core/compressImage.mjs";
|
2
3
|
const numbersWithSeparateSamePrice = (value) => {
|
3
4
|
if (typeof value === "undefined") return "";
|
4
5
|
let nStr = value.match(/\d+/g)?.join("") + "";
|
@@ -23,6 +24,7 @@ const debounce = (callback, delay) => {
|
|
23
24
|
export default () => {
|
24
25
|
return {
|
25
26
|
debounce,
|
26
|
-
numbersWithSeparateSamePrice
|
27
|
+
numbersWithSeparateSamePrice,
|
28
|
+
compressImage
|
27
29
|
};
|
28
30
|
};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
export default (file, MAX_WIDTH = 600, MAX_HEIGHT = 600, QUALITY = 1) => {
|
2
|
+
return new Promise(function(resolve) {
|
3
|
+
const blobURL = URL.createObjectURL(file);
|
4
|
+
const img = new Image();
|
5
|
+
img.src = blobURL;
|
6
|
+
img.onload = function() {
|
7
|
+
URL.revokeObjectURL(this.src);
|
8
|
+
const [newWidth, newHeight] = calculateSize(img, MAX_WIDTH, MAX_HEIGHT);
|
9
|
+
const canvas = document.createElement("canvas");
|
10
|
+
canvas.width = newWidth;
|
11
|
+
canvas.height = newHeight;
|
12
|
+
const ctx = canvas.getContext("2d");
|
13
|
+
ctx.drawImage(img, 0, 0, newWidth, newHeight);
|
14
|
+
canvas.toBlob((blob) => resolve(blob), "image/jpeg", QUALITY);
|
15
|
+
};
|
16
|
+
});
|
17
|
+
};
|
18
|
+
function calculateSize(img, maxWidth, maxHeight) {
|
19
|
+
let width = img.width;
|
20
|
+
let height = img.height;
|
21
|
+
if (width > height) {
|
22
|
+
if (width > maxWidth) {
|
23
|
+
height = Math.round(height * maxWidth / width);
|
24
|
+
width = maxWidth;
|
25
|
+
}
|
26
|
+
} else {
|
27
|
+
if (height > maxHeight) {
|
28
|
+
width = Math.round(width * maxHeight / height);
|
29
|
+
height = maxHeight;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
return [width, height];
|
33
|
+
}
|
package/package.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"version": "1.3.
|
2
|
+
"version": "1.3.3-1",
|
3
3
|
"name": "nuxt-glorious",
|
4
4
|
"description": "This package provides many things needed by a project, including server requests and authentication, SEO and other requirements of a project.",
|
5
5
|
"repository": "sajadhzj/nuxt-glorious",
|