img-upload-kit 1.1.1 → 2.0.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +89 -74
  2. package/MIGRATION.md +192 -0
  3. package/README.md +243 -259
  4. package/dist/bin.js +1186 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/blur.cjs +40 -412
  7. package/dist/blur.cjs.map +1 -1
  8. package/dist/blur.d.cts +5 -5
  9. package/dist/blur.d.ts +5 -5
  10. package/dist/blur.js +39 -393
  11. package/dist/blur.js.map +1 -1
  12. package/dist/blurDataUtils-DveBRtqE.d.cts +43 -0
  13. package/dist/blurDataUtils-yx9Q6HlU.d.ts +43 -0
  14. package/dist/blurService-D5TpMNji.d.ts +83 -0
  15. package/dist/blurService-DacwylJx.d.cts +83 -0
  16. package/dist/chunk-25GYKQ6J.js +158 -0
  17. package/dist/chunk-25GYKQ6J.js.map +1 -0
  18. package/dist/chunk-34L4TEE3.cjs +226 -0
  19. package/dist/chunk-34L4TEE3.cjs.map +1 -0
  20. package/dist/chunk-DFCSN3X7.cjs +158 -0
  21. package/dist/chunk-DFCSN3X7.cjs.map +1 -0
  22. package/dist/chunk-EWVIL57J.js +294 -0
  23. package/dist/chunk-EWVIL57J.js.map +1 -0
  24. package/dist/chunk-FP5YIWG5.cjs +135 -0
  25. package/dist/chunk-FP5YIWG5.cjs.map +1 -0
  26. package/dist/chunk-HILELQGS.js +226 -0
  27. package/dist/chunk-HILELQGS.js.map +1 -0
  28. package/dist/chunk-IDLLCVGB.js +2370 -0
  29. package/dist/chunk-IDLLCVGB.js.map +1 -0
  30. package/dist/chunk-J6A44Y3W.js +514 -0
  31. package/dist/chunk-J6A44Y3W.js.map +1 -0
  32. package/dist/chunk-LOSVFO56.cjs +145 -0
  33. package/dist/chunk-LOSVFO56.cjs.map +1 -0
  34. package/dist/chunk-MBQJ6NVJ.cjs +294 -0
  35. package/dist/chunk-MBQJ6NVJ.cjs.map +1 -0
  36. package/dist/chunk-MHGQEBPW.js +145 -0
  37. package/dist/chunk-MHGQEBPW.js.map +1 -0
  38. package/dist/chunk-QHU7FUO4.cjs +37 -0
  39. package/dist/chunk-QHU7FUO4.cjs.map +1 -0
  40. package/dist/chunk-S2IFAWJK.js +37 -0
  41. package/dist/chunk-S2IFAWJK.js.map +1 -0
  42. package/dist/chunk-TA5Y64JM.cjs +2370 -0
  43. package/dist/chunk-TA5Y64JM.cjs.map +1 -0
  44. package/dist/chunk-VYVZVUNI.js +135 -0
  45. package/dist/chunk-VYVZVUNI.js.map +1 -0
  46. package/dist/chunk-XKQMCY5Z.cjs +514 -0
  47. package/dist/chunk-XKQMCY5Z.cjs.map +1 -0
  48. package/dist/cli.cjs +273 -76
  49. package/dist/cli.cjs.map +1 -1
  50. package/dist/cli.js +269 -73
  51. package/dist/cli.js.map +1 -1
  52. package/dist/headless.cjs +8 -1880
  53. package/dist/headless.cjs.map +1 -1
  54. package/dist/headless.d.cts +3 -1
  55. package/dist/headless.d.ts +3 -1
  56. package/dist/headless.js +25 -1886
  57. package/dist/headless.js.map +1 -1
  58. package/dist/index-BIdnqtW8.d.ts +234 -0
  59. package/dist/index-Brk_uHs6.d.cts +234 -0
  60. package/dist/{index-FVXXKf2v.d.ts → index-CPMlaQsC.d.ts} +76 -153
  61. package/dist/{index-FVXXKf2v.d.cts → index-DHINe-rA.d.cts} +76 -153
  62. package/dist/index.cjs +64 -532
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.d.cts +7 -4
  65. package/dist/index.d.ts +7 -4
  66. package/dist/index.js +63 -504
  67. package/dist/index.js.map +1 -1
  68. package/dist/{memoryAdapter-CBu7_3Pp.d.ts → memoryAdapter-Ck0ccZbF.d.cts} +3 -2
  69. package/dist/{memoryAdapter-BJjyLR-1.d.cts → memoryAdapter-DxEKaG0b.d.ts} +3 -2
  70. package/dist/placeholders-C4ftwaII.d.ts +5 -0
  71. package/dist/placeholders-x_3rt65M.d.cts +5 -0
  72. package/dist/react.cjs +1952 -3257
  73. package/dist/react.cjs.map +1 -1
  74. package/dist/react.d.cts +188 -50
  75. package/dist/react.d.ts +188 -50
  76. package/dist/react.js +1763 -3013
  77. package/dist/react.js.map +1 -1
  78. package/dist/server-handler.cjs +14 -0
  79. package/dist/server-handler.cjs.map +1 -0
  80. package/dist/server-handler.d.cts +3 -0
  81. package/dist/server-handler.d.ts +3 -0
  82. package/dist/server-handler.js +14 -0
  83. package/dist/server-handler.js.map +1 -0
  84. package/dist/server.cjs +1096 -532
  85. package/dist/server.cjs.map +1 -1
  86. package/dist/server.d.cts +77 -154
  87. package/dist/server.d.ts +77 -154
  88. package/dist/server.js +1050 -448
  89. package/dist/server.js.map +1 -1
  90. package/dist/storage.cjs +239 -232
  91. package/dist/storage.cjs.map +1 -1
  92. package/dist/storage.d.cts +21 -5
  93. package/dist/storage.d.ts +21 -5
  94. package/dist/storage.js +227 -207
  95. package/dist/storage.js.map +1 -1
  96. package/dist/styles/animated-image.css +112 -0
  97. package/dist/styles/dropzone-and-tiles.css +247 -0
  98. package/dist/styles/modals-and-dock.css +248 -0
  99. package/dist/styles/primitives.css +197 -0
  100. package/dist/styles/quality-and-inputs.css +184 -0
  101. package/dist/styles/tokens.css +123 -0
  102. package/dist/styles.css +235 -220
  103. package/dist/types-BrP-o9nd.d.cts +85 -0
  104. package/dist/types-sZ3KoFQY.d.ts +85 -0
  105. package/dist/types-yShGNQnW.d.cts +61 -0
  106. package/dist/types-yShGNQnW.d.ts +61 -0
  107. package/dist/{types-CiLY0DwB.d.cts → upload-C5Trd6Dh.d.cts} +27 -53
  108. package/dist/{types-CiLY0DwB.d.ts → upload-C5Trd6Dh.d.ts} +27 -53
  109. package/package.json +92 -32
  110. package/dist/blurService-DqsnfPTd.d.cts +0 -172
  111. package/dist/blurService-DqsnfPTd.d.ts +0 -172
package/dist/index.cjs CHANGED
@@ -1,533 +1,65 @@
1
- 'use strict';
2
-
3
- var blurhash = require('blurhash');
4
-
5
- // src/types/quality.ts
6
- var QUALITY_PRESETS = {
7
- low: {
8
- label: "Low",
9
- labelAr: "\u0645\u0646\u062E\u0641\u0636\u0629",
10
- value: 50,
11
- description: "Smallest file \u2014 best for tiny thumbnails and icons",
12
- descriptionAr: "\u0623\u0635\u063A\u0631 \u062D\u062C\u0645 \u2014 \u0645\u0646\u0627\u0633\u0628 \u0644\u0644\u0645\u0635\u063A\u0631\u0627\u062A \u0648\u0627\u0644\u0623\u064A\u0642\u0648\u0646\u0627\u062A \u0627\u0644\u0635\u063A\u064A\u0631\u0629",
13
- compressionRatio: 0.12
14
- },
15
- medium: {
16
- label: "Medium",
17
- labelAr: "\u0645\u062A\u0648\u0633\u0637\u0629",
18
- value: 72,
19
- description: "Balanced size and quality \u2014 suitable for most web images",
20
- descriptionAr: "\u062A\u0648\u0627\u0632\u0646 \u0628\u064A\u0646 \u0627\u0644\u062D\u062C\u0645 \u0648\u0627\u0644\u062C\u0648\u062F\u0629 \u2014 \u0645\u0646\u0627\u0633\u0628 \u0644\u0645\u0639\u0638\u0645 \u0635\u0648\u0631 \u0627\u0644\u0648\u064A\u0628",
21
- compressionRatio: 0.22
22
- },
23
- high: {
24
- label: "High",
25
- labelAr: "\u0639\u0627\u0644\u064A\u0629",
26
- value: 85,
27
- description: "Recommended \u2014 sharp visuals with excellent compression",
28
- descriptionAr: "\u0645\u0648\u0635\u0649 \u0628\u0647 \u2014 \u062C\u0648\u062F\u0629 \u0639\u0627\u0644\u064A\u0629 \u0648\u0636\u063A\u0637 \u0645\u0645\u062A\u0627\u0632",
29
- compressionRatio: 0.3
30
- },
31
- maximum: {
32
- label: "Maximum",
33
- labelAr: "\u0623\u0642\u0635\u0649 \u062C\u0648\u062F\u0629",
34
- value: 95,
35
- description: "Closest to original \u2014 large file, use for hero / print",
36
- descriptionAr: "\u0623\u0642\u0631\u0628 \u0644\u0644\u0623\u0635\u0644 \u2014 \u062D\u062C\u0645 \u0643\u0628\u064A\u0631\u060C \u0645\u0646\u0627\u0633\u0628 \u0644\u0644\u0635\u0648\u0631 \u0627\u0644\u0631\u0626\u064A\u0633\u064A\u0629 \u0648\u0627\u0644\u0637\u0628\u0627\u0639\u0629",
37
- compressionRatio: 0.55
38
- }
39
- };
40
-
41
- // src/types/presets.ts
42
- var DEFAULT_ALLOWED_FORMATS = [
43
- "image/jpeg",
44
- "image/png",
45
- "image/webp",
46
- "image/avif",
47
- "image/svg+xml"
48
- ];
49
- var RASTER_ALLOWED_FORMATS = [
50
- "image/jpeg",
51
- "image/png",
52
- "image/webp",
53
- "image/avif"
54
- ];
55
- var DEFAULT_IMAGE_DIMENSIONS = {
56
- width: 1920,
57
- height: 1080
58
- };
59
- var STANDARD_PRESETS = {
60
- thumbnail: {
61
- folder: "thumbnails",
62
- maxDimensions: { width: 600, height: 600 },
63
- maxSizeMB: 5,
64
- quality: 78,
65
- recommendedQualityLevel: "medium",
66
- allowedFormats: RASTER_ALLOWED_FORMATS,
67
- recommendationNote: {
68
- en: "Thumbnails display at compact sizes \u2014 Medium quality keeps pages fast",
69
- ar: "\u0627\u0644\u0645\u0635\u063A\u0631\u0627\u062A \u062A\u0639\u0631\u0636 \u0628\u0623\u062D\u062C\u0627\u0645 \u0635\u063A\u064A\u0631\u0629 \u2014 \u0627\u0644\u062C\u0648\u062F\u0629 \u0627\u0644\u0645\u062A\u0648\u0633\u0637\u0629 \u062A\u062D\u0627\u0641\u0638 \u0639\u0644\u0649 \u0633\u0631\u0639\u0629 \u0627\u0644\u0635\u0641\u062D\u0629"
70
- }
71
- },
72
- avatar: {
73
- folder: "avatars",
74
- maxDimensions: { width: 512, height: 512 },
75
- maxSizeMB: 5,
76
- quality: 80,
77
- recommendedQualityLevel: "medium",
78
- allowedFormats: RASTER_ALLOWED_FORMATS,
79
- recommendationNote: {
80
- en: "Avatars display small \u2014 Medium quality balances sharpness and speed",
81
- ar: "\u0627\u0644\u0635\u0648\u0631 \u0627\u0644\u0634\u062E\u0635\u064A\u0629 \u0635\u063A\u064A\u0631\u0629 \u2014 \u0627\u0644\u062C\u0648\u062F\u0629 \u0627\u0644\u0645\u062A\u0648\u0633\u0637\u0629 \u062A\u0648\u0627\u0632\u0646 \u0628\u064A\u0646 \u0627\u0644\u0648\u0636\u0648\u062D \u0648\u0627\u0644\u0633\u0631\u0639\u0629"
82
- }
83
- },
84
- card: {
85
- folder: "cards",
86
- maxDimensions: { width: 1200, height: 900 },
87
- maxSizeMB: 8,
88
- quality: 85,
89
- recommendedQualityLevel: "high",
90
- allowedFormats: DEFAULT_ALLOWED_FORMATS
91
- },
92
- cover: {
93
- folder: "covers",
94
- maxDimensions: { width: 1920, height: 1080 },
95
- maxSizeMB: 10,
96
- quality: 88,
97
- recommendedQualityLevel: "high",
98
- allowedFormats: DEFAULT_ALLOWED_FORMATS
99
- },
100
- hero: {
101
- folder: "hero",
102
- maxDimensions: { width: 2560, height: 1440 },
103
- maxSizeMB: 15,
104
- quality: 92,
105
- recommendedQualityLevel: "maximum",
106
- allowedFormats: DEFAULT_ALLOWED_FORMATS,
107
- recommendationNote: {
108
- en: "Full-width hero visuals benefit from Maximum quality to preserve fine detail",
109
- ar: "\u0627\u0644\u0635\u0648\u0631 \u0627\u0644\u0631\u0626\u064A\u0633\u064A\u0629 \u0628\u0639\u0631\u0636 \u0643\u0627\u0645\u0644 \u062A\u0633\u062A\u0641\u064A\u062F \u0645\u0646 \u0627\u0644\u062C\u0648\u062F\u0629 \u0627\u0644\u0642\u0635\u0648\u0649 \u0644\u0644\u062D\u0641\u0627\u0638 \u0639\u0644\u0649 \u0627\u0644\u062A\u0641\u0627\u0635\u064A\u0644 \u0627\u0644\u062F\u0642\u064A\u0642\u0629"
110
- }
111
- },
112
- logo: {
113
- folder: "logos",
114
- maxDimensions: { width: 800, height: 800 },
115
- maxSizeMB: 5,
116
- quality: 90,
117
- recommendedQualityLevel: "high",
118
- allowedFormats: DEFAULT_ALLOWED_FORMATS,
119
- recommendationNote: {
120
- en: "Prefer SVG for vector logos \u2014 High quality preserves crisp edges on raster logos",
121
- ar: "\u064A\u0641\u0636\u0644 SVG \u0644\u0644\u0634\u0639\u0627\u0631\u0627\u062A \u0627\u0644\u0645\u062A\u062C\u0647\u0629 \u2014 \u0627\u0644\u062C\u0648\u062F\u0629 \u0627\u0644\u0639\u0627\u0644\u064A\u0629 \u062A\u062D\u0627\u0641\u0638 \u0639\u0644\u0649 \u062D\u0648\u0627\u0641 \u0648\u0627\u0636\u062D\u0629"
122
- }
123
- },
124
- original: {
125
- folder: "originals",
126
- maxDimensions: { width: 4096, height: 4096 },
127
- maxSizeMB: 25,
128
- quality: 95,
129
- recommendedQualityLevel: "maximum",
130
- allowedFormats: DEFAULT_ALLOWED_FORMATS
131
- }
132
- };
133
- function defineUploadPresets(presets) {
134
- return presets;
135
- }
136
-
137
- // src/utils/color.ts
138
- var DEFAULT_BLUR_COLOR = "#F5F5F5";
139
- function normalizeColorInput(value) {
140
- if (!value) return null;
141
- let next = value.trim();
142
- if (!next) return null;
143
- if (!next.startsWith("#")) {
144
- next = `#${next}`;
145
- }
146
- const threeHex = /^#([0-9a-fA-F]{3})$/;
147
- const sixHex = /^#([0-9a-fA-F]{6})$/;
148
- if (threeHex.test(next)) {
149
- const [, triplet] = next.match(threeHex) ?? [];
150
- if (triplet) {
151
- next = `#${triplet.split("").map((char) => char + char).join("")}`;
152
- }
153
- } else if (!sixHex.test(next)) {
154
- return null;
155
- }
156
- return next.toUpperCase();
157
- }
158
- function hexToRgb(hex) {
159
- const normalized = hex.replace("#", "");
160
- const expanded = normalized.length === 3 ? normalized.split("").map((char) => char + char).join("") : normalized;
161
- const padded = expanded.padEnd(6, "0").slice(0, 6);
162
- const value = Number.parseInt(padded, 16);
163
- if (Number.isNaN(value)) {
164
- return { r: 245, g: 245, b: 245 };
165
- }
166
- return {
167
- r: value >> 16 & 255,
168
- g: value >> 8 & 255,
169
- b: value & 255
170
- };
171
- }
172
- function rgbToHex(r, g, b) {
173
- const clamp = (v) => Math.max(0, Math.min(255, Math.round(v)));
174
- const value = clamp(r) << 16 | clamp(g) << 8 | clamp(b);
175
- return `#${value.toString(16).padStart(6, "0").toUpperCase()}`;
176
- }
177
- function encodeBase64Ascii(str) {
178
- if (typeof btoa === "function") {
179
- return btoa(str);
180
- }
181
- return Buffer.from(str, "utf8").toString("base64");
182
- }
183
- function generateColorSvgDataURL(color = DEFAULT_BLUR_COLOR) {
184
- const safeColor = normalizeColorInput(color) || DEFAULT_BLUR_COLOR;
185
- const svg = `<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="${safeColor}"/></svg>`;
186
- return `data:image/svg+xml;base64,${encodeBase64Ascii(svg)}`;
187
- }
188
-
189
- // src/utils/formatters.ts
190
- function formatFileSize(bytes) {
191
- if (bytes <= 0) return "0 Bytes";
192
- const k = 1024;
193
- const sizes = ["Bytes", "KB", "MB", "GB"];
194
- const i = Math.min(
195
- sizes.length - 1,
196
- Math.floor(Math.log(bytes) / Math.log(k))
197
- );
198
- return `${Math.round(bytes / Math.pow(k, i) * 100) / 100} ${sizes[i]}`;
199
- }
200
- function calculateReduction(original, optimized) {
201
- if (original <= 0) return 0;
202
- return Math.round((original - optimized) / original * 100);
203
- }
204
- function estimateOutputSize(originalBytes, level) {
205
- return Math.round(originalBytes * QUALITY_PRESETS[level].compressionRatio);
206
- }
207
- var creativeMessages = [
208
- "Sprinkling digital magic \u2728",
209
- "Painting pixels with perfection \u{1F3A8}",
210
- "Launching to the cloud \u{1F680}",
211
- "Creating something beautiful \u2B50",
212
- "Transforming your vision \u26A1",
213
- "Weaving visual excellence \u{1F4AB}",
214
- "Crafting your masterpiece \u{1F3AD}",
215
- "Working our magic \u{1F52E}",
216
- "Making it pixel-perfect \u2728",
217
- "Keep calm, creating magic \u{1F3AA}",
218
- "Hitting the sweet spot \u{1F3AF}",
219
- "Artist mode activated \u{1F3A8}",
220
- "Shooting for the stars \u{1F320}",
221
- "Compressing with love \u{1F49D}",
222
- "Enhancing quality \u{1F48E}",
223
- "Polishing to perfection \u2728"
224
- ];
225
- var creativeMessagesAr = [
226
- "\u0646\u0636\u064A\u0641 \u0644\u0645\u0633\u0629 \u0631\u0642\u0645\u064A\u0629 \u0633\u0627\u062D\u0631\u0629 \u2728",
227
- "\u0646\u0646\u0633\u0642 \u0627\u0644\u0628\u0643\u0633\u0644\u0627\u062A \u0628\u0625\u062A\u0642\u0627\u0646 \u{1F3A8}",
228
- "\u0627\u0644\u0631\u0641\u0639 \u062C\u0627\u0631\u064D \u0625\u0644\u0649 \u0627\u0644\u0633\u062D\u0627\u0628\u0629 \u{1F680}",
229
- "\u0646\u0635\u0646\u0639 \u0634\u064A\u0626\u0627\u064B \u062C\u0645\u064A\u0644\u0627\u064B \u2B50",
230
- "\u0646\u062D\u0648\u0651\u0644 \u0631\u0624\u064A\u062A\u0643 \u0625\u0644\u0649 \u0648\u0627\u0642\u0639 \u26A1",
231
- "\u0646\u0628\u0646\u064A \u062A\u062C\u0631\u0628\u0629 \u0628\u0635\u0631\u064A\u0629 \u0645\u0645\u064A\u0632\u0629 \u{1F4AB}",
232
- "\u0646\u0635\u0642\u0644 \u0639\u0645\u0644\u0643 \u0628\u0627\u062D\u062A\u0631\u0627\u0641 \u{1F3AD}",
233
- "\u0627\u0644\u0633\u062D\u0631 \u062C\u0627\u0631\u064D \u0627\u0644\u0622\u0646 \u{1F52E}",
234
- "\u0646\u0636\u0628\u0637 \u0643\u0644 \u0628\u0643\u0633\u0644 \u0628\u0639\u0646\u0627\u064A\u0629 \u2728",
235
- "\u0627\u0647\u062F\u0623\u060C \u0646\u062D\u0646 \u0646\u0647\u062A\u0645 \u0628\u0627\u0644\u062A\u0641\u0627\u0635\u064A\u0644 \u{1F3AA}",
236
- "\u0646\u0642\u062A\u0631\u0628 \u0645\u0646 \u0627\u0644\u0646\u062A\u064A\u062C\u0629 \u0627\u0644\u0645\u062B\u0627\u0644\u064A\u0629 \u{1F3AF}",
237
- "\u0648\u0636\u0639 \u0627\u0644\u0625\u0628\u062F\u0627\u0639 \u0645\u0641\u0639\u0644 \u{1F3A8}",
238
- "\u0646\u0633\u062A\u0647\u062F\u0641 \u0623\u0641\u0636\u0644 \u0646\u062A\u064A\u062C\u0629 \u{1F320}",
239
- "\u0636\u063A\u0637 \u0630\u0643\u064A \u0645\u0639 \u0627\u0644\u062D\u0641\u0627\u0638 \u0639\u0644\u0649 \u0627\u0644\u062C\u0648\u062F\u0629 \u{1F49D}",
240
- "\u062A\u062D\u0633\u064A\u0646 \u0627\u0644\u062C\u0648\u062F\u0629 \u0645\u0633\u062A\u0645\u0631 \u{1F48E}",
241
- "\u0627\u0644\u0644\u0645\u0633\u0627\u062A \u0627\u0644\u0623\u062E\u064A\u0631\u0629 \u0642\u064A\u062F \u0627\u0644\u062A\u0646\u0641\u064A\u0630 \u2728"
242
- ];
243
- var lastMessageIndex = -1;
244
- function getStatusMessage(progress, locale = "en") {
245
- const list = locale === "ar" ? creativeMessagesAr : creativeMessages;
246
- const clampedProgress = Math.max(0, Math.min(99, progress));
247
- const messageIndex = Math.floor(clampedProgress / 100 * list.length);
248
- const useRandom = Math.random() > 0.7;
249
- let selectedIndex = useRandom ? Math.floor(Math.random() * list.length) : messageIndex;
250
- if (selectedIndex === lastMessageIndex && list.length > 1) {
251
- selectedIndex = (selectedIndex + 1) % list.length;
252
- }
253
- lastMessageIndex = selectedIndex;
254
- if (progress >= 95) {
255
- return locale === "ar" ? "\u{1F389} \u0627\u0642\u062A\u0631\u0628\u0646\u0627 \u062C\u062F\u0627\u064B..." : "\u{1F389} Almost there...";
256
- }
257
- if (progress >= 85) {
258
- return locale === "ar" ? "\u2728 \u0646\u0636\u0639 \u0627\u0644\u0644\u0645\u0633\u0627\u062A \u0627\u0644\u0623\u062E\u064A\u0631\u0629..." : "\u2728 Polishing the final details...";
259
- }
260
- return list[selectedIndex];
261
- }
262
- function createSuccessMessage(originalSize, optimizedSize, compact = false, locale = "en") {
263
- const reduction = calculateReduction(originalSize, optimizedSize);
264
- const original = formatFileSize(originalSize);
265
- const optimized = formatFileSize(optimizedSize);
266
- if (compact) {
267
- if (reduction > 50) {
268
- return locale === "ar" ? `\u{1F389} \u0623\u0635\u063A\u0631 \u0628\u0646\u0633\u0628\u0629 ${reduction}%! (${original} \u2192 ${optimized})` : `\u{1F389} ${reduction}% smaller! (${original} \u2192 ${optimized})`;
269
- }
270
- if (reduction > 0) {
271
- return locale === "ar" ? `\u2713 \u0623\u0635\u063A\u0631 \u0628\u0646\u0633\u0628\u0629 ${reduction}% (${original} \u2192 ${optimized})` : `\u2713 ${reduction}% smaller (${original} \u2192 ${optimized})`;
272
- }
273
- return `\u2713 ${optimized}`;
274
- }
275
- if (reduction > 70) {
276
- return locale === "ar" ? `\u{1F389} \u0631\u0627\u0626\u0639! \u062A\u0645 \u062A\u0642\u0644\u064A\u0644 \u0627\u0644\u062D\u062C\u0645 \u0628\u0646\u0633\u0628\u0629 ${reduction}% (${original} \u2192 ${optimized})` : `\u{1F389} Amazing! Reduced by ${reduction}% (${original} \u2192 ${optimized})`;
277
- }
278
- if (reduction > 50) {
279
- return locale === "ar" ? `\u2728 \u0645\u0645\u062A\u0627\u0632! \u062A\u0645 \u062A\u0642\u0644\u064A\u0644 \u0627\u0644\u062D\u062C\u0645 \u0628\u0646\u0633\u0628\u0629 ${reduction}% (${original} \u2192 ${optimized})` : `\u2728 Great! Reduced by ${reduction}% (${original} \u2192 ${optimized})`;
280
- }
281
- if (reduction > 20) {
282
- return locale === "ar" ? `\u2713 \u0627\u0643\u062A\u0645\u0644 \u0627\u0644\u0631\u0641\u0639! \u062A\u0645 \u062A\u0642\u0644\u064A\u0644 \u0627\u0644\u062D\u062C\u0645 \u0628\u0646\u0633\u0628\u0629 ${reduction}% (${original} \u2192 ${optimized})` : `\u2713 Upload complete! Reduced by ${reduction}% (${original} \u2192 ${optimized})`;
283
- }
284
- return locale === "ar" ? `\u2713 \u0627\u0643\u062A\u0645\u0644 \u0627\u0644\u0631\u0641\u0639! (${original} \u2192 ${optimized})` : `\u2713 Upload complete! (${original} \u2192 ${optimized})`;
285
- }
286
- function getFriendlyErrorMessage(error, locale = "en") {
287
- const lower = error.toLowerCase();
288
- if (lower.includes("size") || lower.includes("large") || lower.includes("exceeds")) {
289
- return locale === "ar" ? "\u0627\u0644\u0645\u0644\u0641 \u0643\u0628\u064A\u0631 \u062C\u062F\u0627\u064B. \u064A\u0631\u062C\u0649 \u0627\u062E\u062A\u064A\u0627\u0631 \u0635\u0648\u0631\u0629 \u0623\u0635\u063A\u0631." : "File is too large. Please choose a smaller image.";
290
- }
291
- if (lower.includes("type") || lower.includes("format")) {
292
- return locale === "ar" ? "\u0646\u0648\u0639 \u0627\u0644\u0645\u0644\u0641 \u063A\u064A\u0631 \u0635\u0627\u0644\u062D. \u064A\u0631\u062C\u0649 \u0631\u0641\u0639 \u0635\u0648\u0631\u0629 \u0635\u0627\u0644\u062D\u0629 (JPEG, PNG, WebP, AVIF, SVG)." : "Invalid file type. Please upload a valid image (JPEG, PNG, WebP, AVIF, SVG).";
293
- }
294
- if (lower.includes("network") || lower.includes("fetch")) {
295
- return locale === "ar" ? "\u062D\u062F\u062B \u062E\u0637\u0623 \u0641\u064A \u0627\u0644\u0634\u0628\u0643\u0629. \u064A\u0631\u062C\u0649 \u0627\u0644\u062A\u062D\u0642\u0642 \u0645\u0646 \u0627\u0644\u0627\u062A\u0635\u0627\u0644 \u0648\u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649." : "Network error. Please check your connection and try again.";
296
- }
297
- if (lower.includes("timeout") || lower.includes("timed out")) {
298
- return locale === "ar" ? "\u0627\u0646\u062A\u0647\u062A \u0645\u0647\u0644\u0629 \u0627\u0644\u0631\u0641\u0639. \u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649." : "Upload timed out. Please try again.";
299
- }
300
- if (error) return error;
301
- return locale === "ar" ? "\u0641\u0634\u0644 \u0627\u0644\u0631\u0641\u0639. \u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649." : "Upload failed. Please try again.";
302
- }
303
-
304
- // src/utils/validators.ts
305
- function validateImageFileStrict(file, maxSizeMB, allowedFormats) {
306
- const maxBytes = maxSizeMB * 1024 * 1024;
307
- if (file.size > maxBytes) {
308
- return {
309
- valid: false,
310
- error: `File size (${(file.size / 1024 / 1024).toFixed(2)}MB) exceeds maximum of ${maxSizeMB}MB`
311
- };
312
- }
313
- if (allowedFormats.length > 0 && !allowedFormats.includes(file.type)) {
314
- return {
315
- valid: false,
316
- error: `File type ${file.type || "unknown"} is not allowed. Allowed: ${allowedFormats.join(", ")}`
317
- };
318
- }
319
- return { valid: true };
320
- }
321
- function validateImageFile(file, maxSizeMB, locale = "en", allowedFormats) {
322
- if (!file.type || !file.type.startsWith("image/")) {
323
- return locale === "ar" ? "\u064A\u0631\u062C\u0649 \u0627\u062E\u062A\u064A\u0627\u0631 \u0645\u0644\u0641 \u0635\u0648\u0631\u0629 \u0635\u0627\u0644\u062D" : "Please select a valid image file";
324
- }
325
- if (allowedFormats && allowedFormats.length > 0 && !allowedFormats.includes(file.type)) {
326
- return locale === "ar" ? `\u0635\u064A\u063A\u0629 \u0627\u0644\u0645\u0644\u0641 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 (${file.type})` : `Unsupported image format (${file.type})`;
327
- }
328
- const fileSizeMB = file.size / (1024 * 1024);
329
- if (fileSizeMB > maxSizeMB) {
330
- return locale === "ar" ? `\u064A\u062C\u0628 \u0623\u0644\u0627 \u064A\u062A\u062C\u0627\u0648\u0632 \u062D\u062C\u0645 \u0627\u0644\u0645\u0644\u0641 ${maxSizeMB}MB` : `File size must be less than ${maxSizeMB}MB`;
331
- }
332
- return null;
333
- }
334
- function validateImageFileWithName(file, maxSizeMB, locale = "en") {
335
- if (!file.type || !file.type.startsWith("image/")) {
336
- return locale === "ar" ? `${file.name}: \u0644\u064A\u0633 \u0645\u0644\u0641 \u0635\u0648\u0631\u0629 \u0635\u0627\u0644\u062D\u0627\u064B` : `${file.name}: Not a valid image file`;
337
- }
338
- const fileSizeMB = file.size / (1024 * 1024);
339
- if (fileSizeMB > maxSizeMB) {
340
- return locale === "ar" ? `${file.name}: \u064A\u062C\u0628 \u0623\u0644\u0627 \u064A\u062A\u062C\u0627\u0648\u0632 \u062D\u062C\u0645 \u0627\u0644\u0645\u0644\u0641 ${maxSizeMB}MB` : `${file.name}: File size must be less than ${maxSizeMB}MB`;
341
- }
342
- return null;
343
- }
344
- function validateMultipleFiles(files, maxSizeMB, currentCount, maxImages, locale = "en") {
345
- if (currentCount + files.length > maxImages) {
346
- return locale === "ar" ? `\u064A\u0645\u0643\u0646 \u0631\u0641\u0639 ${maxImages} \u0635\u0648\u0631\u0629 \u0641\u0642\u0637. \u0627\u0644\u0645\u062A\u0628\u0642\u064A: ${maxImages - currentCount}.` : `Can only upload ${maxImages} images. ${maxImages - currentCount} remaining.`;
347
- }
348
- const oversizedFiles = [];
349
- for (const file of files) {
350
- const fileSizeMB = file.size / (1024 * 1024);
351
- if (fileSizeMB > maxSizeMB) {
352
- oversizedFiles.push(file.name);
353
- }
354
- }
355
- if (oversizedFiles.length > 0) {
356
- if (locale === "ar") {
357
- return `\u0627\u0644\u0645\u0644\u0641\u0627\u062A \u0627\u0644\u062A\u0627\u0644\u064A\u0629 \u0623\u0643\u0628\u0631 \u0645\u0646 \u0627\u0644\u062D\u062F \u0627\u0644\u0645\u0633\u0645\u0648\u062D (${maxSizeMB}MB): ${oversizedFiles.join(", ")}`;
358
- }
359
- return `The following file${oversizedFiles.length > 1 ? "s are" : " is"} too large (max ${maxSizeMB}MB): ${oversizedFiles.join(", ")}`;
360
- }
361
- return null;
362
- }
363
-
364
- // src/storage/memoryAdapter.ts
365
- function createMemoryStorageAdapter(options = {}) {
366
- const baseUrl = (options.baseUrl || "https://memory.local/uploads").replace(
367
- /\/+$/,
368
- ""
369
- );
370
- const store = /* @__PURE__ */ new Map();
371
- const toKey = (bucket, path) => `${bucket}::${path.replace(/^\/+/, "")}`;
372
- const getPublicUrl = (bucket, path) => {
373
- const cleanPath = path.replace(/^\/+/, "");
374
- return `${baseUrl}/${bucket}/${cleanPath}`;
375
- };
376
- return {
377
- async upload(params) {
378
- const cleanPath = params.path.replace(/^\/+/, "");
379
- const key = toKey(params.bucket, cleanPath);
380
- if (params.upsert === false && store.has(key)) {
381
- throw new Error(`Object already exists at ${params.bucket}/${cleanPath}`);
382
- }
383
- store.set(key, {
384
- bucket: params.bucket,
385
- path: cleanPath,
386
- data: new Uint8Array(params.data),
387
- contentType: params.contentType,
388
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
389
- metadata: params.metadata
390
- });
391
- return {
392
- bucket: params.bucket,
393
- path: cleanPath,
394
- url: getPublicUrl(params.bucket, cleanPath)
395
- };
396
- },
397
- async delete(bucket, path) {
398
- const key = toKey(bucket, path);
399
- store.delete(key);
400
- },
401
- getPublicUrl,
402
- async list(bucket, folder) {
403
- const cleanFolder = folder ? folder.replace(/^\/+|\/+$/g, "") : "";
404
- const entries = [];
405
- for (const obj of store.values()) {
406
- if (obj.bucket !== bucket) continue;
407
- if (cleanFolder && !obj.path.startsWith(`${cleanFolder}/`)) continue;
408
- const name = cleanFolder ? obj.path.slice(cleanFolder.length + 1) : obj.path;
409
- entries.push({
410
- name,
411
- id: `${obj.bucket}/${obj.path}`,
412
- createdAt: obj.createdAt,
413
- size: obj.data.byteLength
414
- });
415
- }
416
- return entries;
417
- },
418
- async deleteByUrl(url) {
419
- const prefix = `${baseUrl}/`;
420
- if (!url.startsWith(prefix)) return false;
421
- const rest = url.slice(prefix.length);
422
- const slashIdx = rest.indexOf("/");
423
- if (slashIdx === -1) return false;
424
- const bucket = rest.slice(0, slashIdx);
425
- const filePath = rest.slice(slashIdx + 1);
426
- const key = toKey(bucket, filePath);
427
- return store.delete(key);
428
- },
429
- getObject(bucket, path) {
430
- return store.get(toKey(bucket, path));
431
- },
432
- clear() {
433
- store.clear();
434
- },
435
- get size() {
436
- return store.size;
437
- }
438
- };
439
- }
440
- function getBlurData(image) {
441
- if (!image) {
442
- return {
443
- blurDataUrl: "",
444
- blurColor: "#E5E7EB",
445
- hasBlur: false
446
- };
447
- }
448
- return {
449
- blurDataUrl: image.blurDataUrl || "",
450
- blurColor: image.blurColor || "#E5E7EB",
451
- ...image.blurHash ? { blurHash: image.blurHash } : {},
452
- hasBlur: Boolean(image.blurDataUrl || image.blurHash)
453
- };
454
- }
455
- function getImagePropsWithBlur(image) {
456
- if (!image?.url) {
457
- return null;
458
- }
459
- const blurData = getBlurData(image);
460
- return {
461
- src: image.url,
462
- alt: image.altText || "",
463
- width: image.width || 1920,
464
- height: image.height || 1080,
465
- ...blurData.blurDataUrl && {
466
- placeholder: "blur",
467
- blurDataURL: blurData.blurDataUrl
468
- }
469
- };
470
- }
471
- function getBackgroundPropsWithBlur(image) {
472
- if (!image?.url) {
473
- return {
474
- backgroundColor: "#E5E7EB"
475
- };
476
- }
477
- const blurData = getBlurData(image);
478
- return {
479
- backgroundColor: blurData.blurColor,
480
- backgroundImage: `url(${image.url})`,
481
- backgroundSize: "cover",
482
- backgroundPosition: "center",
483
- backgroundRepeat: "no-repeat"
484
- };
485
- }
486
- function decodeBlurHashToDataURL(hash, width = 32, height = 32, punch = 1) {
487
- if (!hash || typeof document === "undefined") return null;
488
- const validation = blurhash.isBlurhashValid(hash);
489
- if (!validation.result) return null;
490
- try {
491
- const pixels = blurhash.decode(hash, width, height, punch);
492
- const canvas = document.createElement("canvas");
493
- canvas.width = width;
494
- canvas.height = height;
495
- const ctx = canvas.getContext("2d");
496
- if (!ctx) return null;
497
- const imageData = ctx.createImageData(width, height);
498
- imageData.data.set(pixels);
499
- ctx.putImageData(imageData, 0, 0);
500
- return canvas.toDataURL("image/png");
501
- } catch {
502
- return null;
503
- }
504
- }
505
-
506
- exports.DEFAULT_ALLOWED_FORMATS = DEFAULT_ALLOWED_FORMATS;
507
- exports.DEFAULT_BLUR_COLOR = DEFAULT_BLUR_COLOR;
508
- exports.DEFAULT_IMAGE_DIMENSIONS = DEFAULT_IMAGE_DIMENSIONS;
509
- exports.QUALITY_PRESETS = QUALITY_PRESETS;
510
- exports.RASTER_ALLOWED_FORMATS = RASTER_ALLOWED_FORMATS;
511
- exports.STANDARD_PRESETS = STANDARD_PRESETS;
512
- exports.calculateReduction = calculateReduction;
513
- exports.createMemoryStorageAdapter = createMemoryStorageAdapter;
514
- exports.createSuccessMessage = createSuccessMessage;
515
- exports.decodeBlurHashToDataURL = decodeBlurHashToDataURL;
516
- exports.defineUploadPresets = defineUploadPresets;
517
- exports.estimateOutputSize = estimateOutputSize;
518
- exports.formatFileSize = formatFileSize;
519
- exports.generateColorSvgDataURL = generateColorSvgDataURL;
520
- exports.getBackgroundPropsWithBlur = getBackgroundPropsWithBlur;
521
- exports.getBlurData = getBlurData;
522
- exports.getFriendlyErrorMessage = getFriendlyErrorMessage;
523
- exports.getImagePropsWithBlur = getImagePropsWithBlur;
524
- exports.getStatusMessage = getStatusMessage;
525
- exports.hexToRgb = hexToRgb;
526
- exports.normalizeColorInput = normalizeColorInput;
527
- exports.rgbToHex = rgbToHex;
528
- exports.validateImageFile = validateImageFile;
529
- exports.validateImageFileStrict = validateImageFileStrict;
530
- exports.validateImageFileWithName = validateImageFileWithName;
531
- exports.validateMultipleFiles = validateMultipleFiles;
532
- //# sourceMappingURL=index.cjs.map
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkLOSVFO56cjs = require('./chunk-LOSVFO56.cjs');
4
+
5
+
6
+
7
+
8
+
9
+ var _chunkFP5YIWG5cjs = require('./chunk-FP5YIWG5.cjs');
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ var _chunkDFCSN3X7cjs = require('./chunk-DFCSN3X7.cjs');
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+ var _chunk34L4TEE3cjs = require('./chunk-34L4TEE3.cjs');
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+ exports.DEFAULT_ALLOWED_FORMATS = _chunk34L4TEE3cjs.DEFAULT_ALLOWED_FORMATS; exports.DEFAULT_BLUR_COLOR = _chunk34L4TEE3cjs.DEFAULT_BLUR_COLOR; exports.DEFAULT_IMAGE_DIMENSIONS = _chunk34L4TEE3cjs.DEFAULT_IMAGE_DIMENSIONS; exports.QUALITY_PRESETS = _chunkDFCSN3X7cjs.QUALITY_PRESETS; exports.RASTER_ALLOWED_FORMATS = _chunk34L4TEE3cjs.RASTER_ALLOWED_FORMATS; exports.STANDARD_PRESETS = _chunk34L4TEE3cjs.STANDARD_PRESETS; exports.SVG_MIME_TYPE = _chunk34L4TEE3cjs.SVG_MIME_TYPE; exports.calculateReduction = _chunkDFCSN3X7cjs.calculateReduction; exports.createMemoryStorageAdapter = _chunkLOSVFO56cjs.createMemoryStorageAdapter; exports.createSuccessMessage = _chunkDFCSN3X7cjs.createSuccessMessage; exports.decodeBlurHashToDataURL = _chunkFP5YIWG5cjs.decodeBlurHashToDataURL; exports.defineUploadPresets = _chunk34L4TEE3cjs.defineUploadPresets; exports.estimateOutputSize = _chunkDFCSN3X7cjs.estimateOutputSize; exports.formatFileSize = _chunkDFCSN3X7cjs.formatFileSize; exports.generateColorSvgDataURL = _chunk34L4TEE3cjs.generateColorSvgDataURL; exports.getBackgroundPropsWithBlur = _chunkFP5YIWG5cjs.getBackgroundPropsWithBlur; exports.getBlurData = _chunkFP5YIWG5cjs.getBlurData; exports.getFriendlyErrorMessage = _chunkDFCSN3X7cjs.getFriendlyErrorMessage; exports.getImagePropsWithBlur = _chunkFP5YIWG5cjs.getImagePropsWithBlur; exports.getStatusMessage = _chunkDFCSN3X7cjs.getStatusMessage; exports.hexToRgb = _chunk34L4TEE3cjs.hexToRgb; exports.normalizeColorInput = _chunk34L4TEE3cjs.normalizeColorInput; exports.rgbToHex = _chunk34L4TEE3cjs.rgbToHex; exports.validateImageFile = _chunk34L4TEE3cjs.validateImageFile; exports.validateImageFileStrict = _chunk34L4TEE3cjs.validateImageFileStrict; exports.validateImageFileWithName = _chunk34L4TEE3cjs.validateImageFileWithName; exports.validateMultipleFiles = _chunk34L4TEE3cjs.validateMultipleFiles;
533
65
  //# sourceMappingURL=index.cjs.map