@tradly/asset 1.0.7 → 1.0.9

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,20 @@ 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 ? 1600 : _ref$maxWidth,
28
+ maxWidth = _ref$maxWidth === void 0 ? 1300 : _ref$maxWidth,
26
29
  _ref$maxHeight = _ref.maxHeight,
27
- maxHeight = _ref$maxHeight === void 0 ? 1600 : _ref$maxHeight,
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;
35
+ console.log("compressImage", file, maxWidth, maxHeight, quality, convertPngToJpeg);
30
36
  return new Promise(function (resolve) {
31
37
  // Non-image or SVG: skip compression to avoid losing vector quality
32
38
  if (!file.type.startsWith("image/") || file.type === "image/svg+xml") {
@@ -55,17 +61,20 @@ var compressImage = function compressImage(file) {
55
61
  return;
56
62
  }
57
63
  ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
64
+
65
+ // Use JPEG for PNG to allow lossy compression (optional)
66
+ var targetType = file.type === "image/png" && convertPngToJpeg ? "image/jpeg" : file.type;
58
67
  canvas.toBlob(function (blob) {
59
68
  if (!blob) {
60
69
  resolve(file);
61
70
  return;
62
71
  }
63
72
  var compressedFile = new File([blob], file.name, {
64
- type: file.type,
73
+ type: targetType,
65
74
  lastModified: Date.now()
66
75
  });
67
76
  resolve(compressedFile);
68
- }, file.type, quality);
77
+ }, targetType, quality);
69
78
  };
70
79
  img.onerror = function () {
71
80
  resolve(file);
@@ -128,8 +137,8 @@ var FileUpload = function FileUpload(_ref2) {
128
137
  _context.n = 2;
129
138
  return Promise.all(fileList.map(function (file) {
130
139
  return compressImage(file, {
131
- maxWidth: 1600,
132
- maxHeight: 1600,
140
+ maxWidth: 1300,
141
+ maxHeight: 1300,
133
142
  quality: 0.85
134
143
  });
135
144
  }));
@@ -12,15 +12,21 @@ 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 ? 1600 : _ref$maxWidth,
22
+ maxWidth = _ref$maxWidth === void 0 ? 1300 : _ref$maxWidth,
20
23
  _ref$maxHeight = _ref.maxHeight,
21
- maxHeight = _ref$maxHeight === void 0 ? 1600 : _ref$maxHeight,
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;
29
+ console.log("compressImage", file, maxWidth, maxHeight, quality, convertPngToJpeg);
24
30
  return new Promise(function (resolve) {
25
31
  // Non-image or SVG: skip compression to avoid losing vector quality
26
32
  if (!file.type.startsWith("image/") || file.type === "image/svg+xml") {
@@ -49,17 +55,20 @@ var compressImage = function compressImage(file) {
49
55
  return;
50
56
  }
51
57
  ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
58
+
59
+ // Use JPEG for PNG to allow lossy compression (optional)
60
+ var targetType = file.type === "image/png" && convertPngToJpeg ? "image/jpeg" : file.type;
52
61
  canvas.toBlob(function (blob) {
53
62
  if (!blob) {
54
63
  resolve(file);
55
64
  return;
56
65
  }
57
66
  var compressedFile = new File([blob], file.name, {
58
- type: file.type,
67
+ type: targetType,
59
68
  lastModified: Date.now()
60
69
  });
61
70
  resolve(compressedFile);
62
- }, file.type, quality);
71
+ }, targetType, quality);
63
72
  };
64
73
  img.onerror = function () {
65
74
  resolve(file);
@@ -122,8 +131,8 @@ var FileUpload = function FileUpload(_ref2) {
122
131
  _context.n = 2;
123
132
  return Promise.all(fileList.map(function (file) {
124
133
  return compressImage(file, {
125
- maxWidth: 1600,
126
- maxHeight: 1600,
134
+ maxWidth: 1300,
135
+ maxHeight: 1300,
127
136
  quality: 0.85
128
137
  });
129
138
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradly/asset",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
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",