@tradly/asset 1.0.7 → 1.0.8
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.
|
@@ -19,14 +19,19 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
19
19
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
20
20
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
21
21
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } // Helper: compress image on the client before upload
|
|
22
|
+
// - Downscale to fit within maxWidth/maxHeight.
|
|
23
|
+
// - Convert PNG to JPEG by default so quality applies (PNG ignores quality).
|
|
24
|
+
// - Skip SVG (vector) to avoid degradation.
|
|
22
25
|
var compressImage = function compressImage(file) {
|
|
23
26
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
24
27
|
_ref$maxWidth = _ref.maxWidth,
|
|
25
|
-
maxWidth = _ref$maxWidth === void 0 ?
|
|
28
|
+
maxWidth = _ref$maxWidth === void 0 ? 1300 : _ref$maxWidth,
|
|
26
29
|
_ref$maxHeight = _ref.maxHeight,
|
|
27
|
-
maxHeight = _ref$maxHeight === void 0 ?
|
|
30
|
+
maxHeight = _ref$maxHeight === void 0 ? 1300 : _ref$maxHeight,
|
|
28
31
|
_ref$quality = _ref.quality,
|
|
29
|
-
quality = _ref$quality === void 0 ? 0.85 : _ref$quality
|
|
32
|
+
quality = _ref$quality === void 0 ? 0.85 : _ref$quality,
|
|
33
|
+
_ref$convertPngToJpeg = _ref.convertPngToJpeg,
|
|
34
|
+
convertPngToJpeg = _ref$convertPngToJpeg === void 0 ? false : _ref$convertPngToJpeg;
|
|
30
35
|
return new Promise(function (resolve) {
|
|
31
36
|
// Non-image or SVG: skip compression to avoid losing vector quality
|
|
32
37
|
if (!file.type.startsWith("image/") || file.type === "image/svg+xml") {
|
|
@@ -55,17 +60,20 @@ var compressImage = function compressImage(file) {
|
|
|
55
60
|
return;
|
|
56
61
|
}
|
|
57
62
|
ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
|
|
63
|
+
|
|
64
|
+
// Use JPEG for PNG to allow lossy compression (optional)
|
|
65
|
+
var targetType = file.type === "image/png" && convertPngToJpeg ? "image/jpeg" : file.type;
|
|
58
66
|
canvas.toBlob(function (blob) {
|
|
59
67
|
if (!blob) {
|
|
60
68
|
resolve(file);
|
|
61
69
|
return;
|
|
62
70
|
}
|
|
63
71
|
var compressedFile = new File([blob], file.name, {
|
|
64
|
-
type:
|
|
72
|
+
type: targetType,
|
|
65
73
|
lastModified: Date.now()
|
|
66
74
|
});
|
|
67
75
|
resolve(compressedFile);
|
|
68
|
-
},
|
|
76
|
+
}, targetType, quality);
|
|
69
77
|
};
|
|
70
78
|
img.onerror = function () {
|
|
71
79
|
resolve(file);
|
|
@@ -12,15 +12,20 @@ import React, { useState } from "react";
|
|
|
12
12
|
import { CameraIcon } from "./Icons";
|
|
13
13
|
|
|
14
14
|
// Helper: compress image on the client before upload
|
|
15
|
+
// - Downscale to fit within maxWidth/maxHeight.
|
|
16
|
+
// - Convert PNG to JPEG by default so quality applies (PNG ignores quality).
|
|
17
|
+
// - Skip SVG (vector) to avoid degradation.
|
|
15
18
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
16
19
|
var compressImage = function compressImage(file) {
|
|
17
20
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
18
21
|
_ref$maxWidth = _ref.maxWidth,
|
|
19
|
-
maxWidth = _ref$maxWidth === void 0 ?
|
|
22
|
+
maxWidth = _ref$maxWidth === void 0 ? 1300 : _ref$maxWidth,
|
|
20
23
|
_ref$maxHeight = _ref.maxHeight,
|
|
21
|
-
maxHeight = _ref$maxHeight === void 0 ?
|
|
24
|
+
maxHeight = _ref$maxHeight === void 0 ? 1300 : _ref$maxHeight,
|
|
22
25
|
_ref$quality = _ref.quality,
|
|
23
|
-
quality = _ref$quality === void 0 ? 0.85 : _ref$quality
|
|
26
|
+
quality = _ref$quality === void 0 ? 0.85 : _ref$quality,
|
|
27
|
+
_ref$convertPngToJpeg = _ref.convertPngToJpeg,
|
|
28
|
+
convertPngToJpeg = _ref$convertPngToJpeg === void 0 ? false : _ref$convertPngToJpeg;
|
|
24
29
|
return new Promise(function (resolve) {
|
|
25
30
|
// Non-image or SVG: skip compression to avoid losing vector quality
|
|
26
31
|
if (!file.type.startsWith("image/") || file.type === "image/svg+xml") {
|
|
@@ -49,17 +54,20 @@ var compressImage = function compressImage(file) {
|
|
|
49
54
|
return;
|
|
50
55
|
}
|
|
51
56
|
ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
|
|
57
|
+
|
|
58
|
+
// Use JPEG for PNG to allow lossy compression (optional)
|
|
59
|
+
var targetType = file.type === "image/png" && convertPngToJpeg ? "image/jpeg" : file.type;
|
|
52
60
|
canvas.toBlob(function (blob) {
|
|
53
61
|
if (!blob) {
|
|
54
62
|
resolve(file);
|
|
55
63
|
return;
|
|
56
64
|
}
|
|
57
65
|
var compressedFile = new File([blob], file.name, {
|
|
58
|
-
type:
|
|
66
|
+
type: targetType,
|
|
59
67
|
lastModified: Date.now()
|
|
60
68
|
});
|
|
61
69
|
resolve(compressedFile);
|
|
62
|
-
},
|
|
70
|
+
}, targetType, quality);
|
|
63
71
|
};
|
|
64
72
|
img.onerror = function () {
|
|
65
73
|
resolve(file);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradly/asset",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "A reusable media gallery component for uploading and selecting images, videos, and files with Tradly authentication",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|