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.
- package/CHANGELOG.md +89 -74
- package/MIGRATION.md +192 -0
- package/README.md +243 -259
- package/dist/bin.js +1186 -0
- package/dist/bin.js.map +1 -0
- package/dist/blur.cjs +40 -412
- package/dist/blur.cjs.map +1 -1
- package/dist/blur.d.cts +5 -5
- package/dist/blur.d.ts +5 -5
- package/dist/blur.js +39 -393
- package/dist/blur.js.map +1 -1
- package/dist/blurDataUtils-DveBRtqE.d.cts +43 -0
- package/dist/blurDataUtils-yx9Q6HlU.d.ts +43 -0
- package/dist/blurService-D5TpMNji.d.ts +83 -0
- package/dist/blurService-DacwylJx.d.cts +83 -0
- package/dist/chunk-25GYKQ6J.js +158 -0
- package/dist/chunk-25GYKQ6J.js.map +1 -0
- package/dist/chunk-34L4TEE3.cjs +226 -0
- package/dist/chunk-34L4TEE3.cjs.map +1 -0
- package/dist/chunk-DFCSN3X7.cjs +158 -0
- package/dist/chunk-DFCSN3X7.cjs.map +1 -0
- package/dist/chunk-EWVIL57J.js +294 -0
- package/dist/chunk-EWVIL57J.js.map +1 -0
- package/dist/chunk-FP5YIWG5.cjs +135 -0
- package/dist/chunk-FP5YIWG5.cjs.map +1 -0
- package/dist/chunk-HILELQGS.js +226 -0
- package/dist/chunk-HILELQGS.js.map +1 -0
- package/dist/chunk-IDLLCVGB.js +2370 -0
- package/dist/chunk-IDLLCVGB.js.map +1 -0
- package/dist/chunk-J6A44Y3W.js +514 -0
- package/dist/chunk-J6A44Y3W.js.map +1 -0
- package/dist/chunk-LOSVFO56.cjs +145 -0
- package/dist/chunk-LOSVFO56.cjs.map +1 -0
- package/dist/chunk-MBQJ6NVJ.cjs +294 -0
- package/dist/chunk-MBQJ6NVJ.cjs.map +1 -0
- package/dist/chunk-MHGQEBPW.js +145 -0
- package/dist/chunk-MHGQEBPW.js.map +1 -0
- package/dist/chunk-QHU7FUO4.cjs +37 -0
- package/dist/chunk-QHU7FUO4.cjs.map +1 -0
- package/dist/chunk-S2IFAWJK.js +37 -0
- package/dist/chunk-S2IFAWJK.js.map +1 -0
- package/dist/chunk-TA5Y64JM.cjs +2370 -0
- package/dist/chunk-TA5Y64JM.cjs.map +1 -0
- package/dist/chunk-VYVZVUNI.js +135 -0
- package/dist/chunk-VYVZVUNI.js.map +1 -0
- package/dist/chunk-XKQMCY5Z.cjs +514 -0
- package/dist/chunk-XKQMCY5Z.cjs.map +1 -0
- package/dist/cli.cjs +273 -76
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +269 -73
- package/dist/cli.js.map +1 -1
- package/dist/headless.cjs +8 -1880
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +3 -1
- package/dist/headless.d.ts +3 -1
- package/dist/headless.js +25 -1886
- package/dist/headless.js.map +1 -1
- package/dist/index-BIdnqtW8.d.ts +234 -0
- package/dist/index-Brk_uHs6.d.cts +234 -0
- package/dist/{index-FVXXKf2v.d.ts → index-CPMlaQsC.d.ts} +76 -153
- package/dist/{index-FVXXKf2v.d.cts → index-DHINe-rA.d.cts} +76 -153
- package/dist/index.cjs +64 -532
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +63 -504
- package/dist/index.js.map +1 -1
- package/dist/{memoryAdapter-CBu7_3Pp.d.ts → memoryAdapter-Ck0ccZbF.d.cts} +3 -2
- package/dist/{memoryAdapter-BJjyLR-1.d.cts → memoryAdapter-DxEKaG0b.d.ts} +3 -2
- package/dist/placeholders-C4ftwaII.d.ts +5 -0
- package/dist/placeholders-x_3rt65M.d.cts +5 -0
- package/dist/react.cjs +1952 -3257
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +188 -50
- package/dist/react.d.ts +188 -50
- package/dist/react.js +1763 -3013
- package/dist/react.js.map +1 -1
- package/dist/server-handler.cjs +14 -0
- package/dist/server-handler.cjs.map +1 -0
- package/dist/server-handler.d.cts +3 -0
- package/dist/server-handler.d.ts +3 -0
- package/dist/server-handler.js +14 -0
- package/dist/server-handler.js.map +1 -0
- package/dist/server.cjs +1096 -532
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +77 -154
- package/dist/server.d.ts +77 -154
- package/dist/server.js +1050 -448
- package/dist/server.js.map +1 -1
- package/dist/storage.cjs +239 -232
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.d.cts +21 -5
- package/dist/storage.d.ts +21 -5
- package/dist/storage.js +227 -207
- package/dist/storage.js.map +1 -1
- package/dist/styles/animated-image.css +112 -0
- package/dist/styles/dropzone-and-tiles.css +247 -0
- package/dist/styles/modals-and-dock.css +248 -0
- package/dist/styles/primitives.css +197 -0
- package/dist/styles/quality-and-inputs.css +184 -0
- package/dist/styles/tokens.css +123 -0
- package/dist/styles.css +235 -220
- package/dist/types-BrP-o9nd.d.cts +85 -0
- package/dist/types-sZ3KoFQY.d.ts +85 -0
- package/dist/types-yShGNQnW.d.cts +61 -0
- package/dist/types-yShGNQnW.d.ts +61 -0
- package/dist/{types-CiLY0DwB.d.cts → upload-C5Trd6Dh.d.cts} +27 -53
- package/dist/{types-CiLY0DwB.d.ts → upload-C5Trd6Dh.d.ts} +27 -53
- package/package.json +92 -32
- package/dist/blurService-DqsnfPTd.d.cts +0 -172
- package/dist/blurService-DqsnfPTd.d.ts +0 -172
package/dist/headless.js
CHANGED
|
@@ -1,1888 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
(e) => {
|
|
27
|
-
e.preventDefault();
|
|
28
|
-
e.stopPropagation();
|
|
29
|
-
setIsDragging(false);
|
|
30
|
-
if (disabled) return;
|
|
31
|
-
const files = e.dataTransfer.files;
|
|
32
|
-
if (files && files.length > 0) {
|
|
33
|
-
onDrop(files);
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
[disabled, onDrop]
|
|
37
|
-
);
|
|
38
|
-
return {
|
|
39
|
-
isDragging,
|
|
40
|
-
dragHandlers: {
|
|
41
|
-
onDragEnter: handleDragEnter,
|
|
42
|
-
onDragLeave: handleDragLeave,
|
|
43
|
-
onDragOver: handleDragOver,
|
|
44
|
-
onDrop: handleDrop
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// src/types/quality.ts
|
|
50
|
-
var QUALITY_PRESETS = {
|
|
51
|
-
low: {
|
|
52
|
-
label: "Low",
|
|
53
|
-
labelAr: "\u0645\u0646\u062E\u0641\u0636\u0629",
|
|
54
|
-
value: 50,
|
|
55
|
-
description: "Smallest file \u2014 best for tiny thumbnails and icons",
|
|
56
|
-
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",
|
|
57
|
-
compressionRatio: 0.12
|
|
58
|
-
},
|
|
59
|
-
medium: {
|
|
60
|
-
label: "Medium",
|
|
61
|
-
labelAr: "\u0645\u062A\u0648\u0633\u0637\u0629",
|
|
62
|
-
value: 72,
|
|
63
|
-
description: "Balanced size and quality \u2014 suitable for most web images",
|
|
64
|
-
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",
|
|
65
|
-
compressionRatio: 0.22
|
|
66
|
-
},
|
|
67
|
-
high: {
|
|
68
|
-
label: "High",
|
|
69
|
-
labelAr: "\u0639\u0627\u0644\u064A\u0629",
|
|
70
|
-
value: 85,
|
|
71
|
-
description: "Recommended \u2014 sharp visuals with excellent compression",
|
|
72
|
-
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",
|
|
73
|
-
compressionRatio: 0.3
|
|
74
|
-
},
|
|
75
|
-
maximum: {
|
|
76
|
-
label: "Maximum",
|
|
77
|
-
labelAr: "\u0623\u0642\u0635\u0649 \u062C\u0648\u062F\u0629",
|
|
78
|
-
value: 95,
|
|
79
|
-
description: "Closest to original \u2014 large file, use for hero / print",
|
|
80
|
-
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",
|
|
81
|
-
compressionRatio: 0.55
|
|
82
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
HeadlessMultiUpload,
|
|
4
|
+
HeadlessSingleUpload,
|
|
5
|
+
ImageUploadProvider,
|
|
6
|
+
useDragAndDrop,
|
|
7
|
+
useFilePreview,
|
|
8
|
+
useImageUpload,
|
|
9
|
+
useImageUploadContext,
|
|
10
|
+
useMultiUpload,
|
|
11
|
+
useSingleUpload
|
|
12
|
+
} from "./chunk-IDLLCVGB.js";
|
|
13
|
+
import "./chunk-25GYKQ6J.js";
|
|
14
|
+
import "./chunk-HILELQGS.js";
|
|
15
|
+
export {
|
|
16
|
+
HeadlessMultiUpload,
|
|
17
|
+
HeadlessSingleUpload,
|
|
18
|
+
ImageUploadProvider,
|
|
19
|
+
useDragAndDrop,
|
|
20
|
+
useDragAndDrop as useDropzone,
|
|
21
|
+
useFilePreview,
|
|
22
|
+
useImageUpload,
|
|
23
|
+
useImageUploadContext,
|
|
24
|
+
useMultiUpload,
|
|
25
|
+
useSingleUpload
|
|
83
26
|
};
|
|
84
|
-
|
|
85
|
-
// src/types/presets.ts
|
|
86
|
-
var DEFAULT_ALLOWED_FORMATS = [
|
|
87
|
-
"image/jpeg",
|
|
88
|
-
"image/png",
|
|
89
|
-
"image/webp",
|
|
90
|
-
"image/avif",
|
|
91
|
-
"image/svg+xml"
|
|
92
|
-
];
|
|
93
|
-
var RASTER_ALLOWED_FORMATS = [
|
|
94
|
-
"image/jpeg",
|
|
95
|
-
"image/png",
|
|
96
|
-
"image/webp",
|
|
97
|
-
"image/avif"
|
|
98
|
-
];
|
|
99
|
-
var STANDARD_PRESETS = {
|
|
100
|
-
thumbnail: {
|
|
101
|
-
folder: "thumbnails",
|
|
102
|
-
maxDimensions: { width: 600, height: 600 },
|
|
103
|
-
maxSizeMB: 5,
|
|
104
|
-
quality: 78,
|
|
105
|
-
recommendedQualityLevel: "medium",
|
|
106
|
-
allowedFormats: RASTER_ALLOWED_FORMATS,
|
|
107
|
-
recommendationNote: {
|
|
108
|
-
en: "Thumbnails display at compact sizes \u2014 Medium quality keeps pages fast",
|
|
109
|
-
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"
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
avatar: {
|
|
113
|
-
folder: "avatars",
|
|
114
|
-
maxDimensions: { width: 512, height: 512 },
|
|
115
|
-
maxSizeMB: 5,
|
|
116
|
-
quality: 80,
|
|
117
|
-
recommendedQualityLevel: "medium",
|
|
118
|
-
allowedFormats: RASTER_ALLOWED_FORMATS,
|
|
119
|
-
recommendationNote: {
|
|
120
|
-
en: "Avatars display small \u2014 Medium quality balances sharpness and speed",
|
|
121
|
-
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"
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
card: {
|
|
125
|
-
folder: "cards",
|
|
126
|
-
maxDimensions: { width: 1200, height: 900 },
|
|
127
|
-
maxSizeMB: 8,
|
|
128
|
-
quality: 85,
|
|
129
|
-
recommendedQualityLevel: "high",
|
|
130
|
-
allowedFormats: DEFAULT_ALLOWED_FORMATS
|
|
131
|
-
},
|
|
132
|
-
cover: {
|
|
133
|
-
folder: "covers",
|
|
134
|
-
maxDimensions: { width: 1920, height: 1080 },
|
|
135
|
-
maxSizeMB: 10,
|
|
136
|
-
quality: 88,
|
|
137
|
-
recommendedQualityLevel: "high",
|
|
138
|
-
allowedFormats: DEFAULT_ALLOWED_FORMATS
|
|
139
|
-
},
|
|
140
|
-
hero: {
|
|
141
|
-
folder: "hero",
|
|
142
|
-
maxDimensions: { width: 2560, height: 1440 },
|
|
143
|
-
maxSizeMB: 15,
|
|
144
|
-
quality: 92,
|
|
145
|
-
recommendedQualityLevel: "maximum",
|
|
146
|
-
allowedFormats: DEFAULT_ALLOWED_FORMATS,
|
|
147
|
-
recommendationNote: {
|
|
148
|
-
en: "Full-width hero visuals benefit from Maximum quality to preserve fine detail",
|
|
149
|
-
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"
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
logo: {
|
|
153
|
-
folder: "logos",
|
|
154
|
-
maxDimensions: { width: 800, height: 800 },
|
|
155
|
-
maxSizeMB: 5,
|
|
156
|
-
quality: 90,
|
|
157
|
-
recommendedQualityLevel: "high",
|
|
158
|
-
allowedFormats: DEFAULT_ALLOWED_FORMATS,
|
|
159
|
-
recommendationNote: {
|
|
160
|
-
en: "Prefer SVG for vector logos \u2014 High quality preserves crisp edges on raster logos",
|
|
161
|
-
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"
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
original: {
|
|
165
|
-
folder: "originals",
|
|
166
|
-
maxDimensions: { width: 4096, height: 4096 },
|
|
167
|
-
maxSizeMB: 25,
|
|
168
|
-
quality: 95,
|
|
169
|
-
recommendedQualityLevel: "maximum",
|
|
170
|
-
allowedFormats: DEFAULT_ALLOWED_FORMATS
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
// src/utils/color.ts
|
|
175
|
-
var DEFAULT_BLUR_COLOR = "#F5F5F5";
|
|
176
|
-
function normalizeColorInput(value) {
|
|
177
|
-
if (!value) return null;
|
|
178
|
-
let next = value.trim();
|
|
179
|
-
if (!next) return null;
|
|
180
|
-
if (!next.startsWith("#")) {
|
|
181
|
-
next = `#${next}`;
|
|
182
|
-
}
|
|
183
|
-
const threeHex = /^#([0-9a-fA-F]{3})$/;
|
|
184
|
-
const sixHex = /^#([0-9a-fA-F]{6})$/;
|
|
185
|
-
if (threeHex.test(next)) {
|
|
186
|
-
const [, triplet] = next.match(threeHex) ?? [];
|
|
187
|
-
if (triplet) {
|
|
188
|
-
next = `#${triplet.split("").map((char) => char + char).join("")}`;
|
|
189
|
-
}
|
|
190
|
-
} else if (!sixHex.test(next)) {
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
return next.toUpperCase();
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// src/utils/validators.ts
|
|
197
|
-
function validateImageFile(file, maxSizeMB, locale = "en", allowedFormats) {
|
|
198
|
-
if (!file.type || !file.type.startsWith("image/")) {
|
|
199
|
-
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";
|
|
200
|
-
}
|
|
201
|
-
const fileSizeMB = file.size / (1024 * 1024);
|
|
202
|
-
if (fileSizeMB > maxSizeMB) {
|
|
203
|
-
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`;
|
|
204
|
-
}
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
function validateMultipleFiles(files, maxSizeMB, currentCount, maxImages, locale = "en") {
|
|
208
|
-
if (currentCount + files.length > maxImages) {
|
|
209
|
-
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.`;
|
|
210
|
-
}
|
|
211
|
-
const oversizedFiles = [];
|
|
212
|
-
for (const file of files) {
|
|
213
|
-
const fileSizeMB = file.size / (1024 * 1024);
|
|
214
|
-
if (fileSizeMB > maxSizeMB) {
|
|
215
|
-
oversizedFiles.push(file.name);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
if (oversizedFiles.length > 0) {
|
|
219
|
-
if (locale === "ar") {
|
|
220
|
-
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(", ")}`;
|
|
221
|
-
}
|
|
222
|
-
return `The following file${oversizedFiles.length > 1 ? "s are" : " is"} too large (max ${maxSizeMB}MB): ${oversizedFiles.join(", ")}`;
|
|
223
|
-
}
|
|
224
|
-
return null;
|
|
225
|
-
}
|
|
226
|
-
var DEFAULT_CONTEXT = {
|
|
227
|
-
endpoint: "/api/upload",
|
|
228
|
-
locale: "en",
|
|
229
|
-
storageKeyPrefix: "iuk",
|
|
230
|
-
requireAltText: true,
|
|
231
|
-
unstyled: false
|
|
232
|
-
};
|
|
233
|
-
var ImageUploadContext = createContext(DEFAULT_CONTEXT);
|
|
234
|
-
function ImageUploadProvider({
|
|
235
|
-
children,
|
|
236
|
-
endpoint = "/api/upload",
|
|
237
|
-
uploader,
|
|
238
|
-
headers,
|
|
239
|
-
withCredentials,
|
|
240
|
-
locale = "en",
|
|
241
|
-
translations,
|
|
242
|
-
renderImage,
|
|
243
|
-
storageKeyPrefix = "iuk",
|
|
244
|
-
requireAltText = true,
|
|
245
|
-
unstyled = false,
|
|
246
|
-
singleClassNames,
|
|
247
|
-
singleStyles,
|
|
248
|
-
multiClassNames,
|
|
249
|
-
multiStyles
|
|
250
|
-
}) {
|
|
251
|
-
const value = useMemo(
|
|
252
|
-
() => ({
|
|
253
|
-
endpoint,
|
|
254
|
-
uploader,
|
|
255
|
-
headers,
|
|
256
|
-
withCredentials,
|
|
257
|
-
locale,
|
|
258
|
-
translations,
|
|
259
|
-
renderImage,
|
|
260
|
-
storageKeyPrefix,
|
|
261
|
-
requireAltText,
|
|
262
|
-
unstyled,
|
|
263
|
-
singleClassNames,
|
|
264
|
-
singleStyles,
|
|
265
|
-
multiClassNames,
|
|
266
|
-
multiStyles
|
|
267
|
-
}),
|
|
268
|
-
[
|
|
269
|
-
endpoint,
|
|
270
|
-
uploader,
|
|
271
|
-
headers,
|
|
272
|
-
withCredentials,
|
|
273
|
-
locale,
|
|
274
|
-
translations,
|
|
275
|
-
renderImage,
|
|
276
|
-
storageKeyPrefix,
|
|
277
|
-
requireAltText,
|
|
278
|
-
unstyled,
|
|
279
|
-
singleClassNames,
|
|
280
|
-
singleStyles,
|
|
281
|
-
multiClassNames,
|
|
282
|
-
multiStyles
|
|
283
|
-
]
|
|
284
|
-
);
|
|
285
|
-
return /* @__PURE__ */ jsx(ImageUploadContext.Provider, { value, children });
|
|
286
|
-
}
|
|
287
|
-
function useImageUploadContext() {
|
|
288
|
-
return useContext(ImageUploadContext);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// src/react/i18n/ar.ts
|
|
292
|
-
var arTranslations = {
|
|
293
|
-
uploadWindow: "\u0646\u0627\u0641\u0630\u0629 \u0627\u0644\u0631\u0641\u0639",
|
|
294
|
-
tapToResume: "\u0627\u0636\u063A\u0637 \u0644\u0644\u0627\u0633\u062A\u0626\u0646\u0627\u0641",
|
|
295
|
-
restoreUploadWindow: "\u0627\u0633\u062A\u0639\u0627\u062F\u0629 \u0646\u0627\u0641\u0630\u0629 \u0627\u0644\u0631\u0641\u0639",
|
|
296
|
-
minimize: "\u062A\u0635\u063A\u064A\u0631",
|
|
297
|
-
minimizeUploader: "\u062A\u0635\u063A\u064A\u0631 \u0646\u0627\u0641\u0630\u0629 \u0627\u0644\u0631\u0641\u0639",
|
|
298
|
-
close: "\u0625\u063A\u0644\u0627\u0642",
|
|
299
|
-
editPrefix: "\u062A\u0639\u062F\u064A\u0644 - {title}",
|
|
300
|
-
uploadImage: "\u0631\u0641\u0639 \u0635\u0648\u0631\u0629",
|
|
301
|
-
uploadImages: "\u0631\u0641\u0639 \u0635\u0648\u0631",
|
|
302
|
-
noValidImageFiles: "\u0644\u0645 \u064A\u062A\u0645 \u0627\u0644\u0639\u062B\u0648\u0631 \u0639\u0644\u0649 \u0645\u0644\u0641\u0627\u062A \u0635\u0648\u0631 \u0635\u0627\u0644\u062D\u0629. \u064A\u0631\u062C\u0649 \u0627\u062E\u062A\u064A\u0627\u0631 \u0635\u0648\u0631 (JPEG, PNG, WebP, AVIF, SVG).",
|
|
303
|
-
selectedImagesSkipped: "\u062A\u0645 \u0627\u062E\u062A\u064A\u0627\u0631 {imageCount} \u0635\u0648\u0631\u0629. \u0648\u062A\u0645 \u062A\u062C\u0627\u0647\u0644 {skippedCount} \u0645\u0644\u0641 \u063A\u064A\u0631 \u0635\u0648\u0631\u064A.",
|
|
304
|
-
queued: "\u0641\u064A \u0627\u0644\u0627\u0646\u062A\u0638\u0627\u0631...",
|
|
305
|
-
retrying: "\u062C\u0627\u0631\u064A \u0625\u0639\u0627\u062F\u0629 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629...",
|
|
306
|
-
preparingUpload: "\u062C\u0627\u0631\u064A \u062A\u062C\u0647\u064A\u0632 \u0627\u0644\u0631\u0641\u0639...",
|
|
307
|
-
uploadFailed: "\u0641\u0634\u0644 \u0627\u0644\u0631\u0641\u0639",
|
|
308
|
-
failedCreatePreview: "\u062A\u0639\u0630\u0631 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u0645\u0639\u0627\u064A\u0646\u0629",
|
|
309
|
-
failedCreatePreviewFor: "\u062A\u0639\u0630\u0631 \u0625\u0646\u0634\u0627\u0621 \u0645\u0639\u0627\u064A\u0646\u0629 \u0644\u0644\u0645\u0644\u0641: {file}",
|
|
310
|
-
selectAll: "\u062A\u062D\u062F\u064A\u062F \u0627\u0644\u0643\u0644",
|
|
311
|
-
deselectAll: "\u0625\u0644\u063A\u0627\u0621 \u062A\u062D\u062F\u064A\u062F \u0627\u0644\u0643\u0644",
|
|
312
|
-
removeSelected: "\u062D\u0630\u0641 \u0627\u0644\u0645\u062D\u062F\u062F",
|
|
313
|
-
uploading: "\u062C\u0627\u0631\u064D \u0627\u0644\u0631\u0641\u0639",
|
|
314
|
-
someUploadsFailed: "\u0641\u0634\u0644 \u0631\u0641\u0639 \u0628\u0639\u0636 \u0627\u0644\u0645\u0644\u0641\u0627\u062A.",
|
|
315
|
-
retryFailedUploads: "\u0625\u0639\u0627\u062F\u0629 \u0631\u0641\u0639 \u0627\u0644\u0645\u0644\u0641\u0627\u062A \u0627\u0644\u0641\u0627\u0634\u0644\u0629",
|
|
316
|
-
needsAltBeforeSave: "\u064A\u0648\u062C\u062F {count} \u0635\u0648\u0631\u0629 \u0628\u062F\u0648\u0646 \u0646\u0635 \u0628\u062F\u064A\u0644. \u0623\u0636\u0641 \u0648\u0635\u0641\u064B\u0627 \u0642\u0628\u0644 \u0627\u0644\u062D\u0641\u0638 \u0645\u0646 \u0632\u0631 \u0627\u0644\u0648\u0635\u0641 \u0639\u0644\u0649 \u0643\u0644 \u0635\u0648\u0631\u0629.",
|
|
317
|
-
selectFilesAria: "\u0627\u062E\u062A\u064A\u0627\u0631 \u0645\u0644\u0641\u0627\u062A",
|
|
318
|
-
selectMoreFilesAria: "\u0627\u062E\u062A\u064A\u0627\u0631 \u0645\u0644\u0641\u0627\u062A \u0625\u0636\u0627\u0641\u064A\u0629",
|
|
319
|
-
selectFolderAria: "\u0627\u062E\u062A\u064A\u0627\u0631 \u0645\u062C\u0644\u062F",
|
|
320
|
-
dropImagesHere: "\u0623\u0633\u0642\u0637 \u0627\u0644\u0635\u0648\u0631 \u0647\u0646\u0627",
|
|
321
|
-
releaseToUpload: "\u0627\u062A\u0631\u0643 \u0644\u0644\u0625\u0641\u0644\u0627\u062A \u0648\u0627\u0644\u0631\u0641\u0639",
|
|
322
|
-
dragDropOrChoose: "\u0627\u0633\u062D\u0628 \u0648\u0623\u0641\u0644\u062A \u0627\u0644\u0635\u0648\u0631 \u0647\u0646\u0627\u060C \u0623\u0648 \u0627\u062E\u062A\u0631 \u0637\u0631\u064A\u0642\u0629 \u0627\u0644\u0631\u0641\u0639 \u0645\u0646 \u0627\u0644\u0623\u0633\u0641\u0644",
|
|
323
|
-
selectFiles: "\u0627\u062E\u062A\u064A\u0627\u0631 \u0645\u0644\u0641\u0627\u062A",
|
|
324
|
-
selectFolder: "\u0627\u062E\u062A\u064A\u0627\u0631 \u0645\u062C\u0644\u062F",
|
|
325
|
-
supportsFormats: "\u0627\u0644\u0635\u064A\u063A \u0627\u0644\u0645\u062F\u0639\u0648\u0645\u0629: JPEG, PNG, WebP, AVIF, SVG",
|
|
326
|
-
maxPerFile: "\u0627\u0644\u062D\u062F \u0627\u0644\u0623\u0642\u0635\u0649 {size}MB \u0644\u0643\u0644 \u0645\u0644\u0641",
|
|
327
|
-
upToSizeMB: "\u062D\u062A\u0649 {size} \u0645\u064A\u062C\u0627\u0628\u0627\u064A\u062A",
|
|
328
|
-
dropHere: "\u0623\u0633\u0642\u0637 \u0647\u0646\u0627",
|
|
329
|
-
addMore: "\u0625\u0636\u0627\u0641\u0629 \u0627\u0644\u0645\u0632\u064A\u062F",
|
|
330
|
-
files: "\u0645\u0644\u0641\u0627\u062A",
|
|
331
|
-
folder: "\u0645\u062C\u0644\u062F",
|
|
332
|
-
withoutAltText: "{count} \u0628\u062F\u0648\u0646 \u0646\u0635 \u0628\u062F\u064A\u0644",
|
|
333
|
-
saveImages: "\u062D\u0641\u0638 \u0627\u0644\u0635\u0648\u0631",
|
|
334
|
-
addAltBeforeSaving: "\u064A\u0631\u062C\u0649 \u0625\u0636\u0627\u0641\u0629 \u0646\u0635 \u0628\u062F\u064A\u0644 \u0642\u0628\u0644 \u0627\u0644\u062D\u0641\u0638. \u0627\u0636\u063A\u0637 \u0632\u0631 \u0627\u0644\u0648\u0635\u0641 \u0639\u0644\u0649 \u0627\u0644\u0635\u0648\u0631\u0629.",
|
|
335
|
-
missingDescription: "\u0627\u0644\u0648\u0635\u0641 \u0645\u0641\u0642\u0648\u062F",
|
|
336
|
-
saveImage: "\u062D\u0641\u0638 \u0627\u0644\u0635\u0648\u0631\u0629",
|
|
337
|
-
downloadImage: "\u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0635\u0648\u0631\u0629",
|
|
338
|
-
dragDropOrClickToUpload: "\u0627\u0633\u062D\u0628 \u0648\u0623\u0641\u0644\u062A \u0623\u0648 \u0627\u0646\u0642\u0631 \u0644\u0644\u0631\u0641\u0639",
|
|
339
|
-
browseFiles: "\u062A\u0635\u0641\u062D \u0627\u0644\u0645\u0644\u0641\u0627\u062A",
|
|
340
|
-
image: "\u0635\u0648\u0631\u0629",
|
|
341
|
-
processing: "\u062C\u0627\u0631\u064D \u0627\u0644\u0645\u0639\u0627\u0644\u062C\u0629...",
|
|
342
|
-
uploadImageAria: "\u0631\u0641\u0639 \u0635\u0648\u0631\u0629",
|
|
343
|
-
fileInputAria: "\u062D\u0642\u0644 \u0627\u062E\u062A\u064A\u0627\u0631 \u0645\u0644\u0641",
|
|
344
|
-
uploadingAlt: "\u062C\u0627\u0631\u064D \u0627\u0644\u0631\u0641\u0639",
|
|
345
|
-
previewAlt: "\u0645\u0639\u0627\u064A\u0646\u0629",
|
|
346
|
-
addImageDescription: "\u0625\u0636\u0627\u0641\u0629 \u0648\u0635\u0641 \u0644\u0644\u0635\u0648\u0631\u0629",
|
|
347
|
-
describeImagePlaceholder: "\u0635\u0641 \u0647\u0630\u0647 \u0627\u0644\u0635\u0648\u0631\u0629 \u0644\u0625\u0645\u0643\u0627\u0646\u064A\u0629 \u0627\u0644\u0648\u0635\u0648\u0644...",
|
|
348
|
-
characters: "\u062D\u0631\u0641",
|
|
349
|
-
usedForA11ySeo: "\u064A\u064F\u0633\u062A\u062E\u062F\u0645 \u0644\u0625\u0645\u0643\u0627\u0646\u064A\u0629 \u0627\u0644\u0648\u0635\u0648\u0644 \u0648\u062A\u062D\u0633\u064A\u0646 \u0627\u0644\u0638\u0647\u0648\u0631 \u0641\u064A \u0627\u0644\u0628\u062D\u062B",
|
|
350
|
-
cancel: "\u0625\u0644\u063A\u0627\u0621",
|
|
351
|
-
saveDescription: "\u062D\u0641\u0638 \u0627\u0644\u0648\u0635\u0641",
|
|
352
|
-
selectImageAria: "\u062A\u062D\u062F\u064A\u062F \u0627\u0644\u0635\u0648\u0631\u0629",
|
|
353
|
-
editAltTextAria: "\u062A\u0639\u062F\u064A\u0644 \u0627\u0644\u0646\u0635 \u0627\u0644\u0628\u062F\u064A\u0644",
|
|
354
|
-
addAltTextAria: "\u0625\u0636\u0627\u0641\u0629 \u0646\u0635 \u0628\u062F\u064A\u0644",
|
|
355
|
-
addDescriptionForA11y: "\u0623\u0636\u0641 \u0648\u0635\u0641\u064B\u0627 \u0644\u0625\u0645\u0643\u0627\u0646\u064A\u0629 \u0627\u0644\u0648\u0635\u0648\u0644",
|
|
356
|
-
adjustBlurColorAria: "\u0636\u0628\u0637 \u0627\u0644\u062A\u0645\u0648\u064A\u0647 \u0648\u0627\u0644\u0644\u0648\u0646",
|
|
357
|
-
adjustBlurColorTitle: "\u0645\u0639\u0627\u064A\u0646\u0629 \u0628\u064A\u0627\u0646\u0627\u062A \u0627\u0644\u062A\u0645\u0648\u064A\u0647 \u0648\u0636\u0628\u0637 \u0627\u0644\u0623\u0644\u0648\u0627\u0646",
|
|
358
|
-
removeImageAria: "\u062D\u0630\u0641 \u0627\u0644\u0635\u0648\u0631\u0629",
|
|
359
|
-
blurModal: {
|
|
360
|
-
title: "\u0645\u0639\u0627\u064A\u0646\u0629 \u0627\u0644\u062A\u0645\u0648\u064A\u0647 \u0648\u0627\u0644\u0644\u0648\u0646 \u0627\u0644\u0633\u0627\u0626\u062F",
|
|
361
|
-
closeModal: "\u0625\u063A\u0644\u0627\u0642 \u0627\u0644\u0645\u0639\u0627\u064A\u0646\u0629",
|
|
362
|
-
adjustColor: "\u0644\u0648\u0646 \u0627\u0644\u062E\u0644\u0641\u064A\u0629 \u0627\u0644\u0633\u0627\u0626\u062F",
|
|
363
|
-
clickToSample: "\u0627\u0646\u0642\u0631 \u0641\u064A \u0623\u064A \u0645\u0643\u0627\u0646 \u0639\u0644\u0649 \u0627\u0644\u0635\u0648\u0631\u0629 \u0644\u0627\u0644\u062A\u0642\u0627\u0637 \u0644\u0648\u0646 \u0627\u0644\u0628\u0643\u0633\u0644",
|
|
364
|
-
pickColorNote: "\u0627\u062E\u062A\u0631 \u0644\u0648\u0646\u064B\u0627 \u0645\u0646 \u0627\u0644\u0623\u062F\u0627\u0629\u060C \u0623\u0648 \u0623\u062F\u062E\u0644 \u0643\u0648\u062F HEX\u060C \u0623\u0648 \u0627\u0644\u062A\u0642\u0637 \u0645\u0628\u0627\u0634\u0631\u0629 \u0645\u0646 \u0627\u0644\u0635\u0648\u0631\u0629",
|
|
365
|
-
enterHexColor: "\u0623\u062F\u062E\u0644 \u0643\u0648\u062F \u0627\u0644\u0644\u0648\u0646 HEX",
|
|
366
|
-
hexPlaceholder: "F5F5F5",
|
|
367
|
-
enablePenMode: "\u0627\u0644\u062A\u0642\u0627\u0637 \u0644\u0648\u0646 \u0645\u0646 \u0627\u0644\u0635\u0648\u0631\u0629",
|
|
368
|
-
disablePenMode: "\u0625\u064A\u0642\u0627\u0641 \u0627\u0644\u0627\u0644\u062A\u0642\u0627\u0637",
|
|
369
|
-
penModeActive: "\u0648\u0636\u0639 \u0627\u0644\u0627\u0644\u062A\u0642\u0627\u0637 \u0645\u0641\u0639\u0644",
|
|
370
|
-
resetToDetected: "\u0627\u0633\u062A\u0639\u0627\u062F\u0629 \u0627\u0644\u0644\u0648\u0646 \u0627\u0644\u062A\u0644\u0642\u0627\u0626\u064A",
|
|
371
|
-
sampled: "\u062A\u0645 \u0627\u0644\u062A\u0642\u0627\u0637",
|
|
372
|
-
livePreview: "\u0645\u0639\u0627\u064A\u0646\u0629 \u062D\u064A\u0629 \u0644\u0644\u062A\u0645\u0648\u064A\u0647 \u0648\u0627\u0644\u0635\u0648\u0631\u0629",
|
|
373
|
-
showingOriginal: "\u0639\u0631\u0636 \u0627\u0644\u0635\u0648\u0631\u0629 \u0627\u0644\u0623\u0635\u0644\u064A\u0629 (\u0644\u0627 \u064A\u062A\u0648\u0641\u0631 \u062A\u0645\u0648\u064A\u0647 \u0628\u0639\u062F)",
|
|
374
|
-
saved: "\u0627\u0644\u062A\u0648\u0641\u064A\u0631 \u0641\u064A \u0627\u0644\u062D\u062C\u0645:",
|
|
375
|
-
accessibility: "\u0625\u0645\u0643\u0627\u0646\u064A\u0629 \u0627\u0644\u0648\u0635\u0648\u0644 \u0648\u0645\u062D\u0631\u0643\u0627\u062A \u0627\u0644\u0628\u062D\u062B",
|
|
376
|
-
altText: "\u0627\u0644\u0646\u0635 \u0627\u0644\u0628\u062F\u064A\u0644 \u0644\u0644\u0635\u0648\u0631\u0629 (Alt Text)",
|
|
377
|
-
altTextPlaceholder: "\u0635\u0641 \u0645\u062D\u062A\u0648\u0649 \u0627\u0644\u0635\u0648\u0631\u0629 \u0644\u0642\u0627\u0631\u0626\u0627\u062A \u0627\u0644\u0634\u0627\u0634\u0629 \u0648\u0645\u062D\u0631\u0643\u0627\u062A \u0627\u0644\u0628\u062D\u062B...",
|
|
378
|
-
saveAndClose: "\u062D\u0641\u0638 \u0648\u0625\u063A\u0644\u0627\u0642"
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
// src/react/i18n/en.ts
|
|
383
|
-
var enTranslations = {
|
|
384
|
-
uploadWindow: "Upload window",
|
|
385
|
-
tapToResume: "Tap to resume",
|
|
386
|
-
restoreUploadWindow: "Restore upload window",
|
|
387
|
-
minimize: "Minimize",
|
|
388
|
-
minimizeUploader: "Minimize uploader",
|
|
389
|
-
close: "Close",
|
|
390
|
-
editPrefix: "Edit - {title}",
|
|
391
|
-
uploadImage: "Upload Image",
|
|
392
|
-
uploadImages: "Upload Images",
|
|
393
|
-
noValidImageFiles: "No valid image files found. Please select image files (JPEG, PNG, WebP, AVIF, SVG).",
|
|
394
|
-
selectedImagesSkipped: "{imageCount} image{imageSuffix} selected. {skippedCount} non-image file{skippedSuffix} skipped.",
|
|
395
|
-
queued: "Queued...",
|
|
396
|
-
retrying: "Retrying...",
|
|
397
|
-
preparingUpload: "Preparing upload...",
|
|
398
|
-
uploadFailed: "Upload failed",
|
|
399
|
-
failedCreatePreview: "Failed to create preview",
|
|
400
|
-
failedCreatePreviewFor: "Failed to create preview for {file}",
|
|
401
|
-
selectAll: "Select All",
|
|
402
|
-
deselectAll: "Deselect All",
|
|
403
|
-
removeSelected: "Remove Selected",
|
|
404
|
-
uploading: "Uploading",
|
|
405
|
-
someUploadsFailed: "Some uploads failed.",
|
|
406
|
-
retryFailedUploads: "Retry Failed Uploads",
|
|
407
|
-
needsAltBeforeSave: "{count} image{suffix} need{verbSuffix} alt text before saving. Click the description button on each image.",
|
|
408
|
-
selectFilesAria: "Select files",
|
|
409
|
-
selectMoreFilesAria: "Select more files",
|
|
410
|
-
selectFolderAria: "Select folder",
|
|
411
|
-
dropImagesHere: "Drop images here",
|
|
412
|
-
releaseToUpload: "Release to upload",
|
|
413
|
-
dragDropOrChoose: "Drag and drop images here, or choose an option below",
|
|
414
|
-
selectFiles: "Select Files",
|
|
415
|
-
selectFolder: "Select Folder",
|
|
416
|
-
supportsFormats: "Supports: JPEG, PNG, WebP, AVIF, SVG",
|
|
417
|
-
maxPerFile: "Max {size}MB per file",
|
|
418
|
-
upToSizeMB: "Up to {size} MB",
|
|
419
|
-
dropHere: "Drop here",
|
|
420
|
-
addMore: "Add More",
|
|
421
|
-
files: "Files",
|
|
422
|
-
folder: "Folder",
|
|
423
|
-
withoutAltText: "{count} without alt text",
|
|
424
|
-
saveImages: "Save Images",
|
|
425
|
-
addAltBeforeSaving: "Please add alt text before saving. Click the description button on the image.",
|
|
426
|
-
missingDescription: "Missing description",
|
|
427
|
-
saveImage: "Save Image",
|
|
428
|
-
downloadImage: "Download Image",
|
|
429
|
-
dragDropOrClickToUpload: "Drag & drop or click to upload",
|
|
430
|
-
browseFiles: "Browse Files",
|
|
431
|
-
image: "Image",
|
|
432
|
-
processing: "Processing...",
|
|
433
|
-
uploadImageAria: "Upload image",
|
|
434
|
-
fileInputAria: "File input",
|
|
435
|
-
uploadingAlt: "Uploading",
|
|
436
|
-
previewAlt: "Preview",
|
|
437
|
-
addImageDescription: "Add Image Description",
|
|
438
|
-
describeImagePlaceholder: "Describe this image for accessibility...",
|
|
439
|
-
characters: "characters",
|
|
440
|
-
usedForA11ySeo: "Used for accessibility & SEO",
|
|
441
|
-
cancel: "Cancel",
|
|
442
|
-
saveDescription: "Save Description",
|
|
443
|
-
selectImageAria: "Select image",
|
|
444
|
-
editAltTextAria: "Edit alt text",
|
|
445
|
-
addAltTextAria: "Add alt text",
|
|
446
|
-
addDescriptionForA11y: "Add description for accessibility",
|
|
447
|
-
adjustBlurColorAria: "Adjust blur and color",
|
|
448
|
-
adjustBlurColorTitle: "Visualize blur data and adjust colors",
|
|
449
|
-
removeImageAria: "Remove image",
|
|
450
|
-
blurModal: {
|
|
451
|
-
title: "Blur & Dominant Color Inspector",
|
|
452
|
-
closeModal: "Close inspector",
|
|
453
|
-
adjustColor: "Dominant Backdrop Color",
|
|
454
|
-
clickToSample: "Click anywhere on the image preview to sample a pixel color",
|
|
455
|
-
pickColorNote: "Use the picker, enter a HEX code, or sample directly from the image",
|
|
456
|
-
enterHexColor: "Enter HEX color",
|
|
457
|
-
hexPlaceholder: "F5F5F5",
|
|
458
|
-
enablePenMode: "Eyedropper Sample",
|
|
459
|
-
disablePenMode: "Exit Eyedropper",
|
|
460
|
-
penModeActive: "Sampling Active",
|
|
461
|
-
resetToDetected: "Reset to Detected",
|
|
462
|
-
sampled: "Sampled",
|
|
463
|
-
livePreview: "Live Placeholder & Image Preview",
|
|
464
|
-
showingOriginal: "Showing original image (blur placeholder not generated yet)",
|
|
465
|
-
saved: "Size Saved:",
|
|
466
|
-
accessibility: "Accessibility & SEO",
|
|
467
|
-
altText: "Image Alt Text",
|
|
468
|
-
altTextPlaceholder: "Describe this image for screen readers and search engines...",
|
|
469
|
-
saveAndClose: "Save & Close"
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
// src/react/i18n.ts
|
|
474
|
-
function normalizeUploadLocale(locale) {
|
|
475
|
-
if (locale && locale.toLowerCase().startsWith("ar")) {
|
|
476
|
-
return "ar";
|
|
477
|
-
}
|
|
478
|
-
if (typeof document !== "undefined") {
|
|
479
|
-
const docLang = document.documentElement.getAttribute("lang") || document.documentElement.getAttribute("dir");
|
|
480
|
-
if (!locale && (docLang === "ar" || docLang === "rtl")) {
|
|
481
|
-
return "ar";
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return "en";
|
|
485
|
-
}
|
|
486
|
-
var uploadText = {
|
|
487
|
-
en: enTranslations,
|
|
488
|
-
ar: arTranslations
|
|
489
|
-
};
|
|
490
|
-
function resolveTranslations(locale, overrides) {
|
|
491
|
-
const base = uploadText[normalizeUploadLocale(locale)];
|
|
492
|
-
if (!overrides) return base;
|
|
493
|
-
return {
|
|
494
|
-
...base,
|
|
495
|
-
...overrides,
|
|
496
|
-
blurModal: {
|
|
497
|
-
...base.blurModal,
|
|
498
|
-
...overrides.blurModal || {}
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// src/react/utils/sessionMetaCache.ts
|
|
504
|
-
function readSessionJson(key) {
|
|
505
|
-
if (typeof window === "undefined") return null;
|
|
506
|
-
try {
|
|
507
|
-
const raw = window.sessionStorage.getItem(key);
|
|
508
|
-
return raw ? JSON.parse(raw) : null;
|
|
509
|
-
} catch {
|
|
510
|
-
return null;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
function writeSessionJson(key, value) {
|
|
514
|
-
if (typeof window === "undefined") return;
|
|
515
|
-
try {
|
|
516
|
-
window.sessionStorage.setItem(key, JSON.stringify(value));
|
|
517
|
-
} catch {
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
function createUploadSessionCache(storagePrefix = "iuk") {
|
|
521
|
-
const altKey = (id) => `${storagePrefix}:alt-meta:${id}`;
|
|
522
|
-
const blurKey = (id) => `${storagePrefix}:blur-meta:${id}`;
|
|
523
|
-
const writeAltMetaFor = (info, alt) => {
|
|
524
|
-
if (!alt?.trim()) return;
|
|
525
|
-
if (info.url) writeSessionJson(altKey(info.url), alt);
|
|
526
|
-
if (info.contentHash) writeSessionJson(altKey(info.contentHash), alt);
|
|
527
|
-
};
|
|
528
|
-
const readAltMetaFor = (info) => {
|
|
529
|
-
if (info.contentHash) {
|
|
530
|
-
const byHash = readSessionJson(altKey(info.contentHash));
|
|
531
|
-
if (byHash) return byHash;
|
|
532
|
-
}
|
|
533
|
-
if (info.url) {
|
|
534
|
-
const byUrl = readSessionJson(altKey(info.url));
|
|
535
|
-
if (byUrl) return byUrl;
|
|
536
|
-
}
|
|
537
|
-
return null;
|
|
538
|
-
};
|
|
539
|
-
const writeBlurMetaFor = (info, meta) => {
|
|
540
|
-
if (info.url) writeSessionJson(blurKey(info.url), meta);
|
|
541
|
-
if (info.contentHash) writeSessionJson(blurKey(info.contentHash), meta);
|
|
542
|
-
};
|
|
543
|
-
const readBlurMetaFor = (info) => {
|
|
544
|
-
if (info.contentHash) {
|
|
545
|
-
const byHash = readSessionJson(blurKey(info.contentHash));
|
|
546
|
-
if (byHash?.blurDataUrl || byHash?.blurColor) return byHash;
|
|
547
|
-
}
|
|
548
|
-
if (info.url) {
|
|
549
|
-
const byUrl = readSessionJson(blurKey(info.url));
|
|
550
|
-
if (byUrl?.blurDataUrl || byUrl?.blurColor) return byUrl;
|
|
551
|
-
}
|
|
552
|
-
return null;
|
|
553
|
-
};
|
|
554
|
-
return {
|
|
555
|
-
writeAltMetaFor,
|
|
556
|
-
readAltMetaFor,
|
|
557
|
-
writeBlurMetaFor,
|
|
558
|
-
readBlurMetaFor
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
var MIME_TO_EXT = {
|
|
562
|
-
"image/avif": "avif",
|
|
563
|
-
"image/webp": "webp",
|
|
564
|
-
"image/jpeg": "jpg",
|
|
565
|
-
"image/png": "png",
|
|
566
|
-
"image/svg+xml": "svg"
|
|
567
|
-
};
|
|
568
|
-
async function downloadImageWithFallback(url, format) {
|
|
569
|
-
if (!url || typeof window === "undefined") return;
|
|
570
|
-
try {
|
|
571
|
-
const sep = url.includes("?") ? "&" : "?";
|
|
572
|
-
const fetchUrl = `${url}${sep}t=${Date.now()}`;
|
|
573
|
-
const res = await fetch(fetchUrl, { cache: "no-store" });
|
|
574
|
-
const blob = await res.blob();
|
|
575
|
-
const objectUrl = URL.createObjectURL(blob);
|
|
576
|
-
const ext = format ?? MIME_TO_EXT[blob.type] ?? "avif";
|
|
577
|
-
const anchor = document.createElement("a");
|
|
578
|
-
anchor.href = objectUrl;
|
|
579
|
-
anchor.download = `image-${Date.now()}.${ext}`;
|
|
580
|
-
anchor.click();
|
|
581
|
-
URL.revokeObjectURL(objectUrl);
|
|
582
|
-
} catch {
|
|
583
|
-
window.open(url, "_blank", "noopener,noreferrer");
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
function useFilePreview() {
|
|
587
|
-
const createPreview = useCallback((file) => {
|
|
588
|
-
return new Promise((resolve, reject) => {
|
|
589
|
-
const reader = new FileReader();
|
|
590
|
-
reader.onloadend = () => {
|
|
591
|
-
resolve(reader.result);
|
|
592
|
-
};
|
|
593
|
-
reader.onerror = () => {
|
|
594
|
-
reject(new Error("Failed to read file"));
|
|
595
|
-
};
|
|
596
|
-
reader.readAsDataURL(file);
|
|
597
|
-
});
|
|
598
|
-
}, []);
|
|
599
|
-
return { createPreview };
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
// src/utils/formatters.ts
|
|
603
|
-
function formatFileSize(bytes) {
|
|
604
|
-
if (bytes <= 0) return "0 Bytes";
|
|
605
|
-
const k = 1024;
|
|
606
|
-
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
607
|
-
const i = Math.min(
|
|
608
|
-
sizes.length - 1,
|
|
609
|
-
Math.floor(Math.log(bytes) / Math.log(k))
|
|
610
|
-
);
|
|
611
|
-
return `${Math.round(bytes / Math.pow(k, i) * 100) / 100} ${sizes[i]}`;
|
|
612
|
-
}
|
|
613
|
-
function calculateReduction(original, optimized) {
|
|
614
|
-
if (original <= 0) return 0;
|
|
615
|
-
return Math.round((original - optimized) / original * 100);
|
|
616
|
-
}
|
|
617
|
-
var creativeMessages = [
|
|
618
|
-
"Sprinkling digital magic \u2728",
|
|
619
|
-
"Painting pixels with perfection \u{1F3A8}",
|
|
620
|
-
"Launching to the cloud \u{1F680}",
|
|
621
|
-
"Creating something beautiful \u2B50",
|
|
622
|
-
"Transforming your vision \u26A1",
|
|
623
|
-
"Weaving visual excellence \u{1F4AB}",
|
|
624
|
-
"Crafting your masterpiece \u{1F3AD}",
|
|
625
|
-
"Working our magic \u{1F52E}",
|
|
626
|
-
"Making it pixel-perfect \u2728",
|
|
627
|
-
"Keep calm, creating magic \u{1F3AA}",
|
|
628
|
-
"Hitting the sweet spot \u{1F3AF}",
|
|
629
|
-
"Artist mode activated \u{1F3A8}",
|
|
630
|
-
"Shooting for the stars \u{1F320}",
|
|
631
|
-
"Compressing with love \u{1F49D}",
|
|
632
|
-
"Enhancing quality \u{1F48E}",
|
|
633
|
-
"Polishing to perfection \u2728"
|
|
634
|
-
];
|
|
635
|
-
var creativeMessagesAr = [
|
|
636
|
-
"\u0646\u0636\u064A\u0641 \u0644\u0645\u0633\u0629 \u0631\u0642\u0645\u064A\u0629 \u0633\u0627\u062D\u0631\u0629 \u2728",
|
|
637
|
-
"\u0646\u0646\u0633\u0642 \u0627\u0644\u0628\u0643\u0633\u0644\u0627\u062A \u0628\u0625\u062A\u0642\u0627\u0646 \u{1F3A8}",
|
|
638
|
-
"\u0627\u0644\u0631\u0641\u0639 \u062C\u0627\u0631\u064D \u0625\u0644\u0649 \u0627\u0644\u0633\u062D\u0627\u0628\u0629 \u{1F680}",
|
|
639
|
-
"\u0646\u0635\u0646\u0639 \u0634\u064A\u0626\u0627\u064B \u062C\u0645\u064A\u0644\u0627\u064B \u2B50",
|
|
640
|
-
"\u0646\u062D\u0648\u0651\u0644 \u0631\u0624\u064A\u062A\u0643 \u0625\u0644\u0649 \u0648\u0627\u0642\u0639 \u26A1",
|
|
641
|
-
"\u0646\u0628\u0646\u064A \u062A\u062C\u0631\u0628\u0629 \u0628\u0635\u0631\u064A\u0629 \u0645\u0645\u064A\u0632\u0629 \u{1F4AB}",
|
|
642
|
-
"\u0646\u0635\u0642\u0644 \u0639\u0645\u0644\u0643 \u0628\u0627\u062D\u062A\u0631\u0627\u0641 \u{1F3AD}",
|
|
643
|
-
"\u0627\u0644\u0633\u062D\u0631 \u062C\u0627\u0631\u064D \u0627\u0644\u0622\u0646 \u{1F52E}",
|
|
644
|
-
"\u0646\u0636\u0628\u0637 \u0643\u0644 \u0628\u0643\u0633\u0644 \u0628\u0639\u0646\u0627\u064A\u0629 \u2728",
|
|
645
|
-
"\u0627\u0647\u062F\u0623\u060C \u0646\u062D\u0646 \u0646\u0647\u062A\u0645 \u0628\u0627\u0644\u062A\u0641\u0627\u0635\u064A\u0644 \u{1F3AA}",
|
|
646
|
-
"\u0646\u0642\u062A\u0631\u0628 \u0645\u0646 \u0627\u0644\u0646\u062A\u064A\u062C\u0629 \u0627\u0644\u0645\u062B\u0627\u0644\u064A\u0629 \u{1F3AF}",
|
|
647
|
-
"\u0648\u0636\u0639 \u0627\u0644\u0625\u0628\u062F\u0627\u0639 \u0645\u0641\u0639\u0644 \u{1F3A8}",
|
|
648
|
-
"\u0646\u0633\u062A\u0647\u062F\u0641 \u0623\u0641\u0636\u0644 \u0646\u062A\u064A\u062C\u0629 \u{1F320}",
|
|
649
|
-
"\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}",
|
|
650
|
-
"\u062A\u062D\u0633\u064A\u0646 \u0627\u0644\u062C\u0648\u062F\u0629 \u0645\u0633\u062A\u0645\u0631 \u{1F48E}",
|
|
651
|
-
"\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"
|
|
652
|
-
];
|
|
653
|
-
var lastMessageIndex = -1;
|
|
654
|
-
function getStatusMessage(progress, locale = "en") {
|
|
655
|
-
const list = locale === "ar" ? creativeMessagesAr : creativeMessages;
|
|
656
|
-
const clampedProgress = Math.max(0, Math.min(99, progress));
|
|
657
|
-
const messageIndex = Math.floor(clampedProgress / 100 * list.length);
|
|
658
|
-
const useRandom = Math.random() > 0.7;
|
|
659
|
-
let selectedIndex = useRandom ? Math.floor(Math.random() * list.length) : messageIndex;
|
|
660
|
-
if (selectedIndex === lastMessageIndex && list.length > 1) {
|
|
661
|
-
selectedIndex = (selectedIndex + 1) % list.length;
|
|
662
|
-
}
|
|
663
|
-
lastMessageIndex = selectedIndex;
|
|
664
|
-
if (progress >= 95) {
|
|
665
|
-
return locale === "ar" ? "\u{1F389} \u0627\u0642\u062A\u0631\u0628\u0646\u0627 \u062C\u062F\u0627\u064B..." : "\u{1F389} Almost there...";
|
|
666
|
-
}
|
|
667
|
-
if (progress >= 85) {
|
|
668
|
-
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...";
|
|
669
|
-
}
|
|
670
|
-
return list[selectedIndex];
|
|
671
|
-
}
|
|
672
|
-
function createSuccessMessage(originalSize, optimizedSize, compact = false, locale = "en") {
|
|
673
|
-
const reduction = calculateReduction(originalSize, optimizedSize);
|
|
674
|
-
const original = formatFileSize(originalSize);
|
|
675
|
-
const optimized = formatFileSize(optimizedSize);
|
|
676
|
-
if (compact) {
|
|
677
|
-
if (reduction > 50) {
|
|
678
|
-
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})`;
|
|
679
|
-
}
|
|
680
|
-
if (reduction > 0) {
|
|
681
|
-
return locale === "ar" ? `\u2713 \u0623\u0635\u063A\u0631 \u0628\u0646\u0633\u0628\u0629 ${reduction}% (${original} \u2192 ${optimized})` : `\u2713 ${reduction}% smaller (${original} \u2192 ${optimized})`;
|
|
682
|
-
}
|
|
683
|
-
return `\u2713 ${optimized}`;
|
|
684
|
-
}
|
|
685
|
-
if (reduction > 70) {
|
|
686
|
-
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})`;
|
|
687
|
-
}
|
|
688
|
-
if (reduction > 50) {
|
|
689
|
-
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})`;
|
|
690
|
-
}
|
|
691
|
-
if (reduction > 20) {
|
|
692
|
-
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})`;
|
|
693
|
-
}
|
|
694
|
-
return locale === "ar" ? `\u2713 \u0627\u0643\u062A\u0645\u0644 \u0627\u0644\u0631\u0641\u0639! (${original} \u2192 ${optimized})` : `\u2713 Upload complete! (${original} \u2192 ${optimized})`;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
// src/react/hooks/xhrUpload.ts
|
|
698
|
-
function parseErrorPayload(status, rawBody, fallbackLabel = "Upload failed") {
|
|
699
|
-
const statusInfo = `status ${status}`;
|
|
700
|
-
let parsed;
|
|
701
|
-
try {
|
|
702
|
-
const json = JSON.parse(rawBody);
|
|
703
|
-
if (json && typeof json === "object") {
|
|
704
|
-
parsed = json;
|
|
705
|
-
}
|
|
706
|
-
} catch {
|
|
707
|
-
parsed = void 0;
|
|
708
|
-
}
|
|
709
|
-
const candidateKeys = ["error", "message", "detail", "details"];
|
|
710
|
-
if (parsed) {
|
|
711
|
-
for (const key of candidateKeys) {
|
|
712
|
-
const val = parsed[key];
|
|
713
|
-
if (typeof val === "string" && val.trim()) {
|
|
714
|
-
return `${val.trim()} (${statusInfo})`;
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
if (rawBody && rawBody.trim()) {
|
|
719
|
-
return `${rawBody.trim()} (${statusInfo})`;
|
|
720
|
-
}
|
|
721
|
-
return `${fallbackLabel} (${statusInfo})`;
|
|
722
|
-
}
|
|
723
|
-
function buildUploadFormData(file, fields = {}) {
|
|
724
|
-
const {
|
|
725
|
-
preset,
|
|
726
|
-
folder,
|
|
727
|
-
bucket,
|
|
728
|
-
altText,
|
|
729
|
-
customFilename,
|
|
730
|
-
outputFormat,
|
|
731
|
-
quality,
|
|
732
|
-
maxDimensions,
|
|
733
|
-
metadata
|
|
734
|
-
} = fields;
|
|
735
|
-
const formData = new FormData();
|
|
736
|
-
formData.append("file", file);
|
|
737
|
-
if (preset) formData.append("preset", preset);
|
|
738
|
-
if (folder) formData.append("folder", folder);
|
|
739
|
-
if (bucket) formData.append("bucket", bucket);
|
|
740
|
-
if (altText) formData.append("altText", altText);
|
|
741
|
-
if (customFilename) formData.append("customFilename", customFilename);
|
|
742
|
-
if (outputFormat) formData.append("outputFormat", outputFormat);
|
|
743
|
-
if (quality !== void 0) formData.append("quality", String(quality));
|
|
744
|
-
if (maxDimensions) {
|
|
745
|
-
formData.append("maxWidth", String(maxDimensions.width));
|
|
746
|
-
formData.append("maxHeight", String(maxDimensions.height));
|
|
747
|
-
}
|
|
748
|
-
if (metadata && Object.keys(metadata).length > 0) {
|
|
749
|
-
formData.append("metadata", JSON.stringify(metadata));
|
|
750
|
-
}
|
|
751
|
-
return formData;
|
|
752
|
-
}
|
|
753
|
-
function uploadViaXhr(endpoint, formData, options = {}) {
|
|
754
|
-
const fallbackLabel = options.fallbackErrorLabel || "Upload failed";
|
|
755
|
-
if (typeof XMLHttpRequest === "undefined") {
|
|
756
|
-
return fetch(endpoint, {
|
|
757
|
-
method: "POST",
|
|
758
|
-
body: formData,
|
|
759
|
-
headers: options.headers,
|
|
760
|
-
credentials: options.withCredentials ? "include" : "same-origin"
|
|
761
|
-
}).then(async (res) => {
|
|
762
|
-
const text = await res.text();
|
|
763
|
-
if (!res.ok) {
|
|
764
|
-
throw new Error(parseErrorPayload(res.status, text, fallbackLabel));
|
|
765
|
-
}
|
|
766
|
-
return JSON.parse(text);
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
return new Promise((resolve, reject) => {
|
|
770
|
-
const xhr = new XMLHttpRequest();
|
|
771
|
-
xhr.open("POST", endpoint, true);
|
|
772
|
-
xhr.withCredentials = Boolean(options.withCredentials);
|
|
773
|
-
if (options.headers) {
|
|
774
|
-
for (const [key, value] of Object.entries(options.headers)) {
|
|
775
|
-
xhr.setRequestHeader(key, value);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
xhr.upload.onprogress = (event) => {
|
|
779
|
-
if (event.lengthComputable && event.total > 0) {
|
|
780
|
-
const pct = Math.min(
|
|
781
|
-
85,
|
|
782
|
-
Math.round(event.loaded / event.total * 85)
|
|
783
|
-
);
|
|
784
|
-
options.onUploadProgress?.(pct);
|
|
785
|
-
}
|
|
786
|
-
};
|
|
787
|
-
xhr.onload = () => {
|
|
788
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
789
|
-
try {
|
|
790
|
-
const parsed = JSON.parse(xhr.responseText);
|
|
791
|
-
resolve(parsed);
|
|
792
|
-
} catch {
|
|
793
|
-
reject(new Error("Invalid JSON response from upload endpoint"));
|
|
794
|
-
}
|
|
795
|
-
} else {
|
|
796
|
-
reject(
|
|
797
|
-
new Error(
|
|
798
|
-
parseErrorPayload(xhr.status, xhr.responseText, fallbackLabel)
|
|
799
|
-
)
|
|
800
|
-
);
|
|
801
|
-
}
|
|
802
|
-
};
|
|
803
|
-
xhr.onerror = () => {
|
|
804
|
-
reject(new Error("Network error during image upload"));
|
|
805
|
-
};
|
|
806
|
-
xhr.send(formData);
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
// src/react/hooks/useImageUpload.ts
|
|
811
|
-
function useImageUpload({
|
|
812
|
-
preset,
|
|
813
|
-
folder,
|
|
814
|
-
bucket,
|
|
815
|
-
metadata,
|
|
816
|
-
altText,
|
|
817
|
-
outputFormat,
|
|
818
|
-
quality,
|
|
819
|
-
maxDimensions,
|
|
820
|
-
customFilename: defaultCustomFilename,
|
|
821
|
-
endpoint: propEndpoint,
|
|
822
|
-
uploader: propUploader,
|
|
823
|
-
headers: propHeaders,
|
|
824
|
-
withCredentials: propWithCredentials,
|
|
825
|
-
locale: propLocale,
|
|
826
|
-
onSuccess,
|
|
827
|
-
onError,
|
|
828
|
-
onProgress
|
|
829
|
-
} = {}) {
|
|
830
|
-
const ctx = useImageUploadContext();
|
|
831
|
-
const uploadLocale = normalizeUploadLocale(propLocale || ctx.locale);
|
|
832
|
-
const ui = resolveTranslations(uploadLocale, ctx.translations);
|
|
833
|
-
const resolvedEndpoint = propEndpoint || ctx.endpoint || "/api/upload";
|
|
834
|
-
const resolvedUploader = propUploader || ctx.uploader;
|
|
835
|
-
const resolvedHeaders = propHeaders || ctx.headers;
|
|
836
|
-
const resolvedCredentials = propWithCredentials ?? ctx.withCredentials;
|
|
837
|
-
const [isUploading, setIsUploading] = useState(false);
|
|
838
|
-
const [progress, setProgress] = useState(0);
|
|
839
|
-
const [uploadMessage, setUploadMessage] = useState("");
|
|
840
|
-
const isMountedRef = useRef(true);
|
|
841
|
-
const timeoutsRef = useRef(/* @__PURE__ */ new Set());
|
|
842
|
-
const activeIntervalRef = useRef(null);
|
|
843
|
-
const clearProgressInterval = useCallback(() => {
|
|
844
|
-
if (activeIntervalRef.current) {
|
|
845
|
-
clearInterval(activeIntervalRef.current);
|
|
846
|
-
activeIntervalRef.current = null;
|
|
847
|
-
}
|
|
848
|
-
}, []);
|
|
849
|
-
const clearAllTimeouts = useCallback(() => {
|
|
850
|
-
timeoutsRef.current.forEach((t) => clearTimeout(t));
|
|
851
|
-
timeoutsRef.current.clear();
|
|
852
|
-
}, []);
|
|
853
|
-
const safeSetTimeout = useCallback((fn, ms) => {
|
|
854
|
-
const handle = setTimeout(() => {
|
|
855
|
-
timeoutsRef.current.delete(handle);
|
|
856
|
-
if (isMountedRef.current) {
|
|
857
|
-
fn();
|
|
858
|
-
}
|
|
859
|
-
}, ms);
|
|
860
|
-
timeoutsRef.current.add(handle);
|
|
861
|
-
return handle;
|
|
862
|
-
}, []);
|
|
863
|
-
useEffect(() => {
|
|
864
|
-
isMountedRef.current = true;
|
|
865
|
-
return () => {
|
|
866
|
-
isMountedRef.current = false;
|
|
867
|
-
clearProgressInterval();
|
|
868
|
-
clearAllTimeouts();
|
|
869
|
-
};
|
|
870
|
-
}, [clearProgressInterval, clearAllTimeouts]);
|
|
871
|
-
const uploadImage = useCallback(
|
|
872
|
-
async (file, customAltText, overrideCustomFilename) => {
|
|
873
|
-
clearProgressInterval();
|
|
874
|
-
clearAllTimeouts();
|
|
875
|
-
const originalSize = file.size;
|
|
876
|
-
setIsUploading(true);
|
|
877
|
-
setProgress(0);
|
|
878
|
-
setUploadMessage(ui.preparingUpload);
|
|
879
|
-
onProgress?.(0, ui.preparingUpload, file);
|
|
880
|
-
const reportProgress = (nextPct) => {
|
|
881
|
-
if (!isMountedRef.current) return;
|
|
882
|
-
setProgress((prev) => {
|
|
883
|
-
const clamped = Math.max(prev, Math.min(94, nextPct));
|
|
884
|
-
const msg = getStatusMessage(clamped, uploadLocale);
|
|
885
|
-
setUploadMessage(msg);
|
|
886
|
-
onProgress?.(clamped, msg, file);
|
|
887
|
-
return clamped;
|
|
888
|
-
});
|
|
889
|
-
};
|
|
890
|
-
try {
|
|
891
|
-
activeIntervalRef.current = setInterval(() => {
|
|
892
|
-
if (!isMountedRef.current) {
|
|
893
|
-
clearProgressInterval();
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
setProgress((prev) => {
|
|
897
|
-
const nextProgress = Math.min(prev + 6, 92);
|
|
898
|
-
const msg = getStatusMessage(nextProgress, uploadLocale);
|
|
899
|
-
setUploadMessage(msg);
|
|
900
|
-
onProgress?.(nextProgress, msg, file);
|
|
901
|
-
return nextProgress;
|
|
902
|
-
});
|
|
903
|
-
}, 300);
|
|
904
|
-
const finalAlt = customAltText || altText || void 0;
|
|
905
|
-
const finalCustomFilename = overrideCustomFilename || defaultCustomFilename || void 0;
|
|
906
|
-
const requestFields = {
|
|
907
|
-
preset,
|
|
908
|
-
folder,
|
|
909
|
-
bucket,
|
|
910
|
-
altText: finalAlt,
|
|
911
|
-
customFilename: finalCustomFilename,
|
|
912
|
-
outputFormat,
|
|
913
|
-
quality,
|
|
914
|
-
maxDimensions,
|
|
915
|
-
metadata
|
|
916
|
-
};
|
|
917
|
-
const data = resolvedUploader ? await resolvedUploader(file, {
|
|
918
|
-
...requestFields,
|
|
919
|
-
onUploadProgress: reportProgress
|
|
920
|
-
}) : await uploadViaXhr(
|
|
921
|
-
resolvedEndpoint,
|
|
922
|
-
buildUploadFormData(file, requestFields),
|
|
923
|
-
{
|
|
924
|
-
headers: resolvedHeaders,
|
|
925
|
-
withCredentials: resolvedCredentials,
|
|
926
|
-
fallbackErrorLabel: ui.uploadFailed,
|
|
927
|
-
onUploadProgress: reportProgress
|
|
928
|
-
}
|
|
929
|
-
);
|
|
930
|
-
clearProgressInterval();
|
|
931
|
-
if (!isMountedRef.current) return data;
|
|
932
|
-
setProgress(100);
|
|
933
|
-
const successMsg = createSuccessMessage(
|
|
934
|
-
originalSize,
|
|
935
|
-
data.size,
|
|
936
|
-
false,
|
|
937
|
-
uploadLocale
|
|
938
|
-
);
|
|
939
|
-
setUploadMessage(successMsg);
|
|
940
|
-
onProgress?.(100, successMsg, file);
|
|
941
|
-
safeSetTimeout(() => {
|
|
942
|
-
setUploadMessage("");
|
|
943
|
-
}, 5e3);
|
|
944
|
-
onSuccess?.(data, file);
|
|
945
|
-
return data;
|
|
946
|
-
} catch (err) {
|
|
947
|
-
clearProgressInterval();
|
|
948
|
-
if (!isMountedRef.current) return null;
|
|
949
|
-
const errorMsg = err instanceof Error ? err.message : ui.uploadFailed;
|
|
950
|
-
setUploadMessage("");
|
|
951
|
-
onError?.(errorMsg, file);
|
|
952
|
-
return null;
|
|
953
|
-
} finally {
|
|
954
|
-
clearProgressInterval();
|
|
955
|
-
if (isMountedRef.current) {
|
|
956
|
-
setIsUploading(false);
|
|
957
|
-
safeSetTimeout(() => {
|
|
958
|
-
setProgress(0);
|
|
959
|
-
}, 1e3);
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
},
|
|
963
|
-
[
|
|
964
|
-
preset,
|
|
965
|
-
folder,
|
|
966
|
-
bucket,
|
|
967
|
-
metadata,
|
|
968
|
-
altText,
|
|
969
|
-
outputFormat,
|
|
970
|
-
quality,
|
|
971
|
-
maxDimensions,
|
|
972
|
-
defaultCustomFilename,
|
|
973
|
-
resolvedEndpoint,
|
|
974
|
-
resolvedUploader,
|
|
975
|
-
resolvedHeaders,
|
|
976
|
-
resolvedCredentials,
|
|
977
|
-
uploadLocale,
|
|
978
|
-
ui.preparingUpload,
|
|
979
|
-
ui.uploadFailed,
|
|
980
|
-
onSuccess,
|
|
981
|
-
onError,
|
|
982
|
-
onProgress,
|
|
983
|
-
clearProgressInterval,
|
|
984
|
-
clearAllTimeouts,
|
|
985
|
-
safeSetTimeout
|
|
986
|
-
]
|
|
987
|
-
);
|
|
988
|
-
const reset = useCallback(() => {
|
|
989
|
-
clearProgressInterval();
|
|
990
|
-
clearAllTimeouts();
|
|
991
|
-
setIsUploading(false);
|
|
992
|
-
setProgress(0);
|
|
993
|
-
setUploadMessage("");
|
|
994
|
-
}, [clearProgressInterval, clearAllTimeouts]);
|
|
995
|
-
return {
|
|
996
|
-
uploadImage,
|
|
997
|
-
isUploading,
|
|
998
|
-
progress,
|
|
999
|
-
uploadMessage,
|
|
1000
|
-
reset
|
|
1001
|
-
};
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
// src/react/hooks/useSingleImageState.ts
|
|
1005
|
-
function resolveInitialQualityLevel(quality, preset) {
|
|
1006
|
-
const q = quality ?? preset?.quality;
|
|
1007
|
-
if (!q) return preset?.recommendedQualityLevel || "high";
|
|
1008
|
-
if (q <= 55) return "low";
|
|
1009
|
-
if (q <= 78) return "medium";
|
|
1010
|
-
return q <= 90 ? "high" : "maximum";
|
|
1011
|
-
}
|
|
1012
|
-
function useSingleImageState(props) {
|
|
1013
|
-
const {
|
|
1014
|
-
value,
|
|
1015
|
-
onChange,
|
|
1016
|
-
preset,
|
|
1017
|
-
folder,
|
|
1018
|
-
bucket,
|
|
1019
|
-
metadata,
|
|
1020
|
-
endpoint,
|
|
1021
|
-
uploader,
|
|
1022
|
-
headers,
|
|
1023
|
-
withCredentials,
|
|
1024
|
-
locale: propLocale,
|
|
1025
|
-
translations,
|
|
1026
|
-
initialAltText: propInitialAltText,
|
|
1027
|
-
maxSizeMB: propMaxSizeMB,
|
|
1028
|
-
maxDimensions,
|
|
1029
|
-
requireAltText: propRequireAltText,
|
|
1030
|
-
isOpen,
|
|
1031
|
-
onClose,
|
|
1032
|
-
outputFormat,
|
|
1033
|
-
quality: initialQualityProp,
|
|
1034
|
-
customFilename
|
|
1035
|
-
} = props;
|
|
1036
|
-
const ctx = useImageUploadContext();
|
|
1037
|
-
const locale = normalizeUploadLocale(propLocale || ctx.locale);
|
|
1038
|
-
const ui = resolveTranslations(locale, translations || ctx.translations);
|
|
1039
|
-
const requireAltText = propRequireAltText ?? ctx.requireAltText;
|
|
1040
|
-
const standardPreset = preset ? STANDARD_PRESETS[preset] : void 0;
|
|
1041
|
-
const maxSizeMB = propMaxSizeMB ?? standardPreset?.maxSizeMB ?? 10;
|
|
1042
|
-
const requiresManualCommit = Boolean(isOpen);
|
|
1043
|
-
const cache = useMemo(() => createUploadSessionCache(ctx.storageKeyPrefix || "iuk"), [ctx.storageKeyPrefix]);
|
|
1044
|
-
const objVal = typeof value === "object" && value ? value : null;
|
|
1045
|
-
const initPreview = typeof value === "string" ? value : objVal?.url || null;
|
|
1046
|
-
const initAlt = objVal?.altText || propInitialAltText || "";
|
|
1047
|
-
const initColor = objVal?.blurColor || DEFAULT_BLUR_COLOR;
|
|
1048
|
-
const [preview, setPreview] = useState(initPreview);
|
|
1049
|
-
const [altText, setAltText] = useState(initAlt);
|
|
1050
|
-
const [blurColor, setBlurColor] = useState(initColor);
|
|
1051
|
-
const [detectedBlurColor, setDetectedBlurColor] = useState(initColor);
|
|
1052
|
-
const [blurDataUrlState, setBlurDataUrlState] = useState(objVal?.blurDataUrl || "");
|
|
1053
|
-
const [hasColorOverride, setHasColorOverride] = useState(false);
|
|
1054
|
-
const [validationError, setValidationError] = useState("");
|
|
1055
|
-
const [showMissingAltWarning, setShowMissingAltWarning] = useState(false);
|
|
1056
|
-
const [editingAltText, setEditingAltText] = useState(false);
|
|
1057
|
-
const [sizeInfo, setSizeInfo] = useState(null);
|
|
1058
|
-
const [uploadedData, setUploadedData] = useState(objVal && "url" in objVal ? objVal : null);
|
|
1059
|
-
const [isBlurModalOpen, setIsBlurModalOpen] = useState(false);
|
|
1060
|
-
const [selectedFile, setSelectedFile] = useState(null);
|
|
1061
|
-
const [qualityLevel, setQualityLevel] = useState(() => resolveInitialQualityLevel(initialQualityProp, standardPreset));
|
|
1062
|
-
const fileInputRef = useRef(null);
|
|
1063
|
-
const lastAltRef = useRef(initAlt);
|
|
1064
|
-
const resetColorAndErrorState = () => {
|
|
1065
|
-
setValidationError("");
|
|
1066
|
-
setHasColorOverride(false);
|
|
1067
|
-
setBlurColor(DEFAULT_BLUR_COLOR);
|
|
1068
|
-
setDetectedBlurColor(DEFAULT_BLUR_COLOR);
|
|
1069
|
-
setIsBlurModalOpen(false);
|
|
1070
|
-
};
|
|
1071
|
-
const { createPreview } = useFilePreview();
|
|
1072
|
-
const { uploadImage, isUploading, progress, uploadMessage, reset } = useImageUpload({
|
|
1073
|
-
preset,
|
|
1074
|
-
folder,
|
|
1075
|
-
bucket,
|
|
1076
|
-
metadata,
|
|
1077
|
-
outputFormat,
|
|
1078
|
-
maxDimensions,
|
|
1079
|
-
customFilename,
|
|
1080
|
-
quality: QUALITY_PRESETS[qualityLevel].value,
|
|
1081
|
-
endpoint,
|
|
1082
|
-
uploader,
|
|
1083
|
-
headers,
|
|
1084
|
-
withCredentials,
|
|
1085
|
-
locale,
|
|
1086
|
-
onSuccess: (data) => {
|
|
1087
|
-
const nextPreviewUrl = /^(?:blob:|data:)/i.test(data.url) ? data.url : `${data.url}${data.url.includes("?") ? "&" : "?"}t=${Date.now()}`;
|
|
1088
|
-
setPreview(nextPreviewUrl);
|
|
1089
|
-
setSizeInfo({ original: data.originalSize || 0, optimized: data.size });
|
|
1090
|
-
const normColor = data.blurColor || DEFAULT_BLUR_COLOR;
|
|
1091
|
-
setBlurColor(normColor);
|
|
1092
|
-
setDetectedBlurColor(normColor);
|
|
1093
|
-
setHasColorOverride(false);
|
|
1094
|
-
setBlurDataUrlState(data.blurDataUrl || "");
|
|
1095
|
-
const keyInfo = { url: data.url, contentHash: data.contentHash };
|
|
1096
|
-
cache.writeBlurMetaFor(keyInfo, { blurDataUrl: data.blurDataUrl || "", blurColor: normColor });
|
|
1097
|
-
const payload = { ...data, altText, blurColor: normColor };
|
|
1098
|
-
setUploadedData(payload);
|
|
1099
|
-
lastAltRef.current = altText;
|
|
1100
|
-
cache.writeAltMetaFor(keyInfo, altText);
|
|
1101
|
-
if (!requiresManualCommit) onChange(payload);
|
|
1102
|
-
},
|
|
1103
|
-
onError: (errorMsg) => {
|
|
1104
|
-
setValidationError(errorMsg);
|
|
1105
|
-
setPreview(null);
|
|
1106
|
-
setUploadedData(null);
|
|
1107
|
-
}
|
|
1108
|
-
});
|
|
1109
|
-
useEffect(() => {
|
|
1110
|
-
const incomingObj = typeof value === "object" && value ? value : null;
|
|
1111
|
-
const nextPreview = typeof value === "string" ? value : incomingObj?.url || null;
|
|
1112
|
-
const rawAlt = incomingObj?.altText || propInitialAltText || "";
|
|
1113
|
-
const cachedAlt = cache.readAltMetaFor({ url: incomingObj ? incomingObj.url : nextPreview, contentHash: incomingObj?.contentHash ?? null });
|
|
1114
|
-
const nextAlt = rawAlt.trim() === "" && nextPreview === preview && (lastAltRef.current.trim() !== "" || cachedAlt?.trim()) ? lastAltRef.current.trim() || cachedAlt || rawAlt : rawAlt;
|
|
1115
|
-
const nextColor = incomingObj?.blurColor || DEFAULT_BLUR_COLOR;
|
|
1116
|
-
const stripCacheQuery = (u) => u && !/^(?:blob:|data:)/i.test(u) ? u.split("?")[0] : u;
|
|
1117
|
-
if (stripCacheQuery(nextPreview) !== stripCacheQuery(preview)) setPreview(nextPreview);
|
|
1118
|
-
if (nextAlt !== altText && (nextPreview !== preview || nextAlt.trim() !== "" || !altText.trim())) setAltText(nextAlt);
|
|
1119
|
-
const nextIsFallback = nextColor === DEFAULT_BLUR_COLOR;
|
|
1120
|
-
if (nextColor !== blurColor && (nextPreview !== preview || !hasColorOverride && (!nextIsFallback || blurColor === DEFAULT_BLUR_COLOR))) {
|
|
1121
|
-
setBlurColor(nextColor);
|
|
1122
|
-
setDetectedBlurColor(nextColor);
|
|
1123
|
-
setHasColorOverride(false);
|
|
1124
|
-
}
|
|
1125
|
-
const nextBlurUrl = incomingObj?.blurDataUrl || "";
|
|
1126
|
-
if (nextPreview !== preview || nextBlurUrl && nextBlurUrl !== blurDataUrlState) {
|
|
1127
|
-
setBlurDataUrlState(nextBlurUrl);
|
|
1128
|
-
}
|
|
1129
|
-
if (nextPreview) {
|
|
1130
|
-
const cached = cache.readBlurMetaFor({
|
|
1131
|
-
url: nextPreview,
|
|
1132
|
-
contentHash: incomingObj?.contentHash || uploadedData?.contentHash
|
|
1133
|
-
});
|
|
1134
|
-
if (cached?.blurDataUrl && !nextBlurUrl) setBlurDataUrlState(cached.blurDataUrl);
|
|
1135
|
-
if (cached?.blurColor && nextIsFallback && blurColor === DEFAULT_BLUR_COLOR) {
|
|
1136
|
-
setBlurColor(cached.blurColor);
|
|
1137
|
-
setDetectedBlurColor(cached.blurColor);
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
if (!value) {
|
|
1141
|
-
setUploadedData(null);
|
|
1142
|
-
setBlurDataUrlState("");
|
|
1143
|
-
setSizeInfo(null);
|
|
1144
|
-
setSelectedFile(null);
|
|
1145
|
-
if (fileInputRef.current) fileInputRef.current.value = "";
|
|
1146
|
-
} else if (incomingObj?.url) {
|
|
1147
|
-
setUploadedData((prev) => prev?.url === incomingObj.url ? prev : incomingObj);
|
|
1148
|
-
}
|
|
1149
|
-
}, [value, propInitialAltText]);
|
|
1150
|
-
const buildExistingImagePayload = (overrides = {}) => {
|
|
1151
|
-
const base = uploadedData ? { ...uploadedData } : objVal ? { ...objVal } : typeof value === "string" && value.trim() ? { url: value, blurDataUrl: "", blurColor: DEFAULT_BLUR_COLOR, altText: "", width: 0, height: 0, format: "webp", size: 0, contentHash: "existing-image", uploadedAt: (/* @__PURE__ */ new Date()).toISOString() } : null;
|
|
1152
|
-
if (!base) return null;
|
|
1153
|
-
return {
|
|
1154
|
-
...base,
|
|
1155
|
-
...overrides,
|
|
1156
|
-
url: (overrides.url ?? base.url) || preview || "",
|
|
1157
|
-
altText: overrides.altText ?? altText ?? base.altText ?? "",
|
|
1158
|
-
blurColor: overrides.blurColor ?? blurColor ?? base.blurColor ?? DEFAULT_BLUR_COLOR,
|
|
1159
|
-
blurDataUrl: overrides.blurDataUrl ?? base.blurDataUrl ?? blurDataUrlState ?? ""
|
|
1160
|
-
};
|
|
1161
|
-
};
|
|
1162
|
-
const commitIfAuto = (overrides) => {
|
|
1163
|
-
if (!requiresManualCommit) {
|
|
1164
|
-
const payload = buildExistingImagePayload(overrides);
|
|
1165
|
-
if (payload) onChange(payload);
|
|
1166
|
-
}
|
|
1167
|
-
};
|
|
1168
|
-
const applyBlurColor = (color, options = {}) => {
|
|
1169
|
-
const normalized = normalizeColorInput(color);
|
|
1170
|
-
if (!normalized) return;
|
|
1171
|
-
setBlurColor(normalized);
|
|
1172
|
-
setHasColorOverride(options.markOverride !== false);
|
|
1173
|
-
setUploadedData((prev) => prev ? { ...prev, blurColor: normalized } : prev);
|
|
1174
|
-
if (preview) cache.writeBlurMetaFor({ url: preview, contentHash: uploadedData?.contentHash }, { blurDataUrl: blurDataUrlState, blurColor: normalized });
|
|
1175
|
-
commitIfAuto({ blurColor: normalized });
|
|
1176
|
-
};
|
|
1177
|
-
const handleResetColor = () => {
|
|
1178
|
-
if (detectedBlurColor) applyBlurColor(detectedBlurColor, { markOverride: false });
|
|
1179
|
-
};
|
|
1180
|
-
const handleFileSelect = async (files) => {
|
|
1181
|
-
const file = files[0];
|
|
1182
|
-
if (!file) return;
|
|
1183
|
-
setSelectedFile(file);
|
|
1184
|
-
resetColorAndErrorState();
|
|
1185
|
-
const err = validateImageFile(file, maxSizeMB, locale);
|
|
1186
|
-
if (err) {
|
|
1187
|
-
setValidationError(err);
|
|
1188
|
-
return;
|
|
1189
|
-
}
|
|
1190
|
-
try {
|
|
1191
|
-
setPreview(await createPreview(file));
|
|
1192
|
-
setAltText("");
|
|
1193
|
-
lastAltRef.current = "";
|
|
1194
|
-
} catch {
|
|
1195
|
-
setValidationError(ui.failedCreatePreview);
|
|
1196
|
-
return;
|
|
1197
|
-
}
|
|
1198
|
-
await uploadImage(file, altText);
|
|
1199
|
-
};
|
|
1200
|
-
const handleRemoveTile = () => {
|
|
1201
|
-
setPreview(null);
|
|
1202
|
-
setAltText("");
|
|
1203
|
-
setBlurDataUrlState("");
|
|
1204
|
-
setSizeInfo(null);
|
|
1205
|
-
setUploadedData(null);
|
|
1206
|
-
setSelectedFile(null);
|
|
1207
|
-
resetColorAndErrorState();
|
|
1208
|
-
reset();
|
|
1209
|
-
if (fileInputRef.current) fileInputRef.current.value = "";
|
|
1210
|
-
if (!requiresManualCommit) onChange(null);
|
|
1211
|
-
};
|
|
1212
|
-
const handleAltTextSave = (newAltText) => {
|
|
1213
|
-
setAltText(newAltText);
|
|
1214
|
-
lastAltRef.current = newAltText;
|
|
1215
|
-
if (preview) cache.writeAltMetaFor({ url: preview, contentHash: uploadedData?.contentHash }, newAltText);
|
|
1216
|
-
setShowMissingAltWarning(false);
|
|
1217
|
-
setEditingAltText(false);
|
|
1218
|
-
commitIfAuto({ altText: newAltText });
|
|
1219
|
-
};
|
|
1220
|
-
const handleSaveImage = () => {
|
|
1221
|
-
if (requireAltText && preview && !altText?.trim()) {
|
|
1222
|
-
setShowMissingAltWarning(true);
|
|
1223
|
-
setValidationError(ui.addAltBeforeSaving);
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
setShowMissingAltWarning(false);
|
|
1227
|
-
setValidationError("");
|
|
1228
|
-
const payload = buildExistingImagePayload();
|
|
1229
|
-
if (payload) {
|
|
1230
|
-
lastAltRef.current = payload.altText || lastAltRef.current;
|
|
1231
|
-
cache.writeAltMetaFor({ url: payload.url, contentHash: payload.contentHash }, payload.altText || "");
|
|
1232
|
-
onChange(payload);
|
|
1233
|
-
}
|
|
1234
|
-
onClose?.();
|
|
1235
|
-
};
|
|
1236
|
-
const downloadUrl = uploadedData?.url ?? (typeof value === "string" ? value : objVal?.url) ?? null;
|
|
1237
|
-
const handleDownload = useCallback(async () => {
|
|
1238
|
-
if (downloadUrl) await downloadImageWithFallback(downloadUrl, uploadedData?.format);
|
|
1239
|
-
}, [downloadUrl, uploadedData?.format]);
|
|
1240
|
-
return {
|
|
1241
|
-
locale,
|
|
1242
|
-
ui,
|
|
1243
|
-
requireAltText,
|
|
1244
|
-
maxSizeMB,
|
|
1245
|
-
fileInputRef,
|
|
1246
|
-
preview,
|
|
1247
|
-
altText,
|
|
1248
|
-
blurColor,
|
|
1249
|
-
detectedBlurColor,
|
|
1250
|
-
blurDataUrlState,
|
|
1251
|
-
validationError,
|
|
1252
|
-
showMissingAltWarning,
|
|
1253
|
-
editingAltText,
|
|
1254
|
-
setEditingAltText,
|
|
1255
|
-
sizeInfo,
|
|
1256
|
-
uploadedData,
|
|
1257
|
-
isBlurModalOpen,
|
|
1258
|
-
setIsBlurModalOpen,
|
|
1259
|
-
selectedFile,
|
|
1260
|
-
qualityLevel,
|
|
1261
|
-
setQualityLevel,
|
|
1262
|
-
isUploading,
|
|
1263
|
-
progress,
|
|
1264
|
-
uploadMessage,
|
|
1265
|
-
currentImageData: uploadedData ?? objVal,
|
|
1266
|
-
canDownload: Boolean(downloadUrl),
|
|
1267
|
-
applyBlurColor,
|
|
1268
|
-
handleResetColor,
|
|
1269
|
-
handleFileSelect,
|
|
1270
|
-
handleRemoveTile,
|
|
1271
|
-
handleAltTextSave,
|
|
1272
|
-
handleSaveImage,
|
|
1273
|
-
handleDownload
|
|
1274
|
-
};
|
|
1275
|
-
}
|
|
1276
|
-
|
|
1277
|
-
// src/react/utils/slotStyles.ts
|
|
1278
|
-
var HIDDEN_INPUT_STYLE = {
|
|
1279
|
-
position: "absolute",
|
|
1280
|
-
width: 1,
|
|
1281
|
-
height: 1,
|
|
1282
|
-
padding: 0,
|
|
1283
|
-
margin: -1,
|
|
1284
|
-
overflow: "hidden",
|
|
1285
|
-
clip: "rect(0, 0, 0, 0)",
|
|
1286
|
-
whiteSpace: "nowrap",
|
|
1287
|
-
border: 0
|
|
1288
|
-
};
|
|
1289
|
-
function resolveUploadDataState(flags) {
|
|
1290
|
-
if (flags.disabled) return "disabled";
|
|
1291
|
-
if (flags.isDragging) return "dragging";
|
|
1292
|
-
if (flags.isUploading) return "uploading";
|
|
1293
|
-
if (flags.hasError) return "error";
|
|
1294
|
-
if (flags.hasContent) return "ready";
|
|
1295
|
-
return "idle";
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
// src/react/headless/useSingleUpload.ts
|
|
1299
|
-
var DEFAULT_ACCEPT = "image/jpeg,image/png,image/webp,image/avif,image/svg+xml";
|
|
1300
|
-
function useSingleUpload(options) {
|
|
1301
|
-
const { accept = DEFAULT_ACCEPT, disabled = false, error: externalError } = options;
|
|
1302
|
-
const {
|
|
1303
|
-
locale,
|
|
1304
|
-
ui,
|
|
1305
|
-
maxSizeMB,
|
|
1306
|
-
fileInputRef,
|
|
1307
|
-
preview,
|
|
1308
|
-
altText,
|
|
1309
|
-
blurColor,
|
|
1310
|
-
detectedBlurColor,
|
|
1311
|
-
blurDataUrlState,
|
|
1312
|
-
validationError,
|
|
1313
|
-
sizeInfo,
|
|
1314
|
-
uploadedData,
|
|
1315
|
-
qualityLevel,
|
|
1316
|
-
setQualityLevel,
|
|
1317
|
-
isUploading,
|
|
1318
|
-
progress,
|
|
1319
|
-
uploadMessage,
|
|
1320
|
-
currentImageData,
|
|
1321
|
-
canDownload,
|
|
1322
|
-
applyBlurColor,
|
|
1323
|
-
handleResetColor,
|
|
1324
|
-
handleFileSelect,
|
|
1325
|
-
handleRemoveTile,
|
|
1326
|
-
handleAltTextSave,
|
|
1327
|
-
handleSaveImage,
|
|
1328
|
-
handleDownload
|
|
1329
|
-
} = useSingleImageState(options);
|
|
1330
|
-
const { isDragging, dragHandlers } = useDragAndDrop({
|
|
1331
|
-
disabled,
|
|
1332
|
-
onDrop: (files) => {
|
|
1333
|
-
void handleFileSelect(files);
|
|
1334
|
-
}
|
|
1335
|
-
});
|
|
1336
|
-
const displayError = externalError || validationError || "";
|
|
1337
|
-
const blurDataUrl = blurDataUrlState || currentImageData?.blurDataUrl || "";
|
|
1338
|
-
const state = resolveUploadDataState({
|
|
1339
|
-
disabled,
|
|
1340
|
-
hasError: Boolean(displayError),
|
|
1341
|
-
isUploading,
|
|
1342
|
-
isDragging,
|
|
1343
|
-
hasContent: Boolean(preview)
|
|
1344
|
-
});
|
|
1345
|
-
const openFileDialog = () => {
|
|
1346
|
-
if (!disabled) fileInputRef.current?.click();
|
|
1347
|
-
};
|
|
1348
|
-
const getDropzoneProps = (overrides) => ({
|
|
1349
|
-
...overrides,
|
|
1350
|
-
role: overrides?.role ?? "button",
|
|
1351
|
-
tabIndex: overrides?.tabIndex ?? (disabled ? -1 : 0),
|
|
1352
|
-
"aria-label": overrides?.["aria-label"] ?? ui.uploadImageAria,
|
|
1353
|
-
"aria-disabled": disabled || void 0,
|
|
1354
|
-
"data-state": state,
|
|
1355
|
-
"data-dragging": isDragging || void 0,
|
|
1356
|
-
"data-uploading": isUploading || void 0,
|
|
1357
|
-
"data-disabled": disabled || void 0,
|
|
1358
|
-
"data-error": Boolean(displayError) || void 0,
|
|
1359
|
-
onClick: (event) => {
|
|
1360
|
-
if (event.target === fileInputRef.current) return;
|
|
1361
|
-
overrides?.onClick?.(event);
|
|
1362
|
-
if (!event.defaultPrevented && !disabled) openFileDialog();
|
|
1363
|
-
},
|
|
1364
|
-
onKeyDown: (event) => {
|
|
1365
|
-
overrides?.onKeyDown?.(event);
|
|
1366
|
-
if (!event.defaultPrevented && !disabled && event.target === event.currentTarget && (event.key === "Enter" || event.key === " ")) {
|
|
1367
|
-
event.preventDefault();
|
|
1368
|
-
openFileDialog();
|
|
1369
|
-
}
|
|
1370
|
-
},
|
|
1371
|
-
onDragEnter: (event) => {
|
|
1372
|
-
overrides?.onDragEnter?.(event);
|
|
1373
|
-
dragHandlers.onDragEnter(event);
|
|
1374
|
-
},
|
|
1375
|
-
onDragLeave: (event) => {
|
|
1376
|
-
overrides?.onDragLeave?.(event);
|
|
1377
|
-
dragHandlers.onDragLeave(event);
|
|
1378
|
-
},
|
|
1379
|
-
onDragOver: (event) => {
|
|
1380
|
-
overrides?.onDragOver?.(event);
|
|
1381
|
-
dragHandlers.onDragOver(event);
|
|
1382
|
-
},
|
|
1383
|
-
onDrop: (event) => {
|
|
1384
|
-
overrides?.onDrop?.(event);
|
|
1385
|
-
dragHandlers.onDrop(event);
|
|
1386
|
-
}
|
|
1387
|
-
});
|
|
1388
|
-
const getInputProps = (overrides) => ({
|
|
1389
|
-
...overrides,
|
|
1390
|
-
ref: fileInputRef,
|
|
1391
|
-
type: "file",
|
|
1392
|
-
accept: overrides?.accept ?? accept,
|
|
1393
|
-
disabled: overrides?.disabled ?? disabled,
|
|
1394
|
-
"aria-label": overrides?.["aria-label"] ?? ui.fileInputAria,
|
|
1395
|
-
style: overrides?.style ? { ...HIDDEN_INPUT_STYLE, ...overrides.style } : HIDDEN_INPUT_STYLE,
|
|
1396
|
-
onClick: (event) => {
|
|
1397
|
-
overrides?.onClick?.(event);
|
|
1398
|
-
event.stopPropagation();
|
|
1399
|
-
},
|
|
1400
|
-
onChange: (event) => {
|
|
1401
|
-
overrides?.onChange?.(event);
|
|
1402
|
-
if (!event.defaultPrevented) {
|
|
1403
|
-
const files = event.target.files;
|
|
1404
|
-
if (files && files.length > 0) void handleFileSelect(files);
|
|
1405
|
-
event.target.value = "";
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
});
|
|
1409
|
-
return {
|
|
1410
|
-
state,
|
|
1411
|
-
preview,
|
|
1412
|
-
uploadedData,
|
|
1413
|
-
altText,
|
|
1414
|
-
blurColor,
|
|
1415
|
-
detectedBlurColor,
|
|
1416
|
-
blurDataUrl,
|
|
1417
|
-
isDragging,
|
|
1418
|
-
isUploading,
|
|
1419
|
-
progress,
|
|
1420
|
-
uploadMessage,
|
|
1421
|
-
error: displayError,
|
|
1422
|
-
sizeInfo,
|
|
1423
|
-
qualityLevel,
|
|
1424
|
-
maxSizeMB,
|
|
1425
|
-
disabled,
|
|
1426
|
-
canDownload,
|
|
1427
|
-
locale,
|
|
1428
|
-
ui,
|
|
1429
|
-
openFileDialog,
|
|
1430
|
-
selectFiles: handleFileSelect,
|
|
1431
|
-
remove: handleRemoveTile,
|
|
1432
|
-
save: handleSaveImage,
|
|
1433
|
-
download: handleDownload,
|
|
1434
|
-
setQualityLevel,
|
|
1435
|
-
setAltText: handleAltTextSave,
|
|
1436
|
-
setBlurColor: (hex) => applyBlurColor(hex),
|
|
1437
|
-
resetBlurColor: handleResetColor,
|
|
1438
|
-
getDropzoneProps,
|
|
1439
|
-
getInputProps
|
|
1440
|
-
};
|
|
1441
|
-
}
|
|
1442
|
-
var EMPTY_IMAGES = [];
|
|
1443
|
-
function mapUploadedToPreview(img, prev) {
|
|
1444
|
-
const altText = prev?.altText && !img.altText?.trim() ? prev.altText : img.altText;
|
|
1445
|
-
return {
|
|
1446
|
-
id: img.url,
|
|
1447
|
-
url: img.url,
|
|
1448
|
-
file: null,
|
|
1449
|
-
uploadMessage: null,
|
|
1450
|
-
originalSize: img.originalSize,
|
|
1451
|
-
optimizedSize: img.size,
|
|
1452
|
-
data: { ...img, altText },
|
|
1453
|
-
altText,
|
|
1454
|
-
blurColor: img.blurColor || prev?.blurColor
|
|
1455
|
-
};
|
|
1456
|
-
}
|
|
1457
|
-
function resolveInitialQuality(q, fallback = "high") {
|
|
1458
|
-
if (!q) return fallback;
|
|
1459
|
-
return q <= 55 ? "low" : q <= 78 ? "medium" : q <= 90 ? "high" : "maximum";
|
|
1460
|
-
}
|
|
1461
|
-
function collectUploadedData(list, readyOnly) {
|
|
1462
|
-
return list.filter((p) => p.data && (!readyOnly || !p.isUploading)).map((p) => ({ ...p.data, altText: p.altText ?? p.data.altText, blurColor: p.blurColor ?? p.data.blurColor }));
|
|
1463
|
-
}
|
|
1464
|
-
function useMultiImageState(options) {
|
|
1465
|
-
const { onChange, preset, isOpen, onClose } = options;
|
|
1466
|
-
const value = options.value ?? EMPTY_IMAGES;
|
|
1467
|
-
const maxImages = options.maxImages ?? 999;
|
|
1468
|
-
const maxParallelUploads = options.maxParallelUploads ?? 2;
|
|
1469
|
-
const ctx = useImageUploadContext();
|
|
1470
|
-
const locale = normalizeUploadLocale(options.locale || ctx.locale);
|
|
1471
|
-
const ui = resolveTranslations(locale, options.translations || ctx.translations);
|
|
1472
|
-
const requireAltText = options.requireAltText ?? ctx.requireAltText;
|
|
1473
|
-
const standardPreset = preset ? STANDARD_PRESETS[preset] : void 0;
|
|
1474
|
-
const maxSizeMB = options.maxSizeMB ?? standardPreset?.maxSizeMB ?? 10;
|
|
1475
|
-
const requiresManualCommit = Boolean(isOpen);
|
|
1476
|
-
const [previews, setPreviews] = useState(() => value.map((img) => mapUploadedToPreview(img)));
|
|
1477
|
-
const previewsRef = useRef(previews);
|
|
1478
|
-
previewsRef.current = previews;
|
|
1479
|
-
const [validationError, setValidationError] = useState("");
|
|
1480
|
-
const [infoMessage, setInfoMessage] = useState("");
|
|
1481
|
-
const [selectedPreviews, setSelectedPreviews] = useState(() => /* @__PURE__ */ new Set());
|
|
1482
|
-
const [uploadStats, setUploadStats] = useState({ total: 0, completed: 0, failed: 0 });
|
|
1483
|
-
const [editingAltTextId, setEditingAltTextId] = useState(null);
|
|
1484
|
-
const [showMissingAltWarning, setShowMissingAltWarning] = useState(false);
|
|
1485
|
-
const [qualityLevel, setQualityLevel] = useState(
|
|
1486
|
-
() => resolveInitialQuality(options.quality ?? standardPreset?.quality, standardPreset?.recommendedQualityLevel)
|
|
1487
|
-
);
|
|
1488
|
-
const { createPreview } = useFilePreview();
|
|
1489
|
-
const infoTimeoutRef = useRef(null);
|
|
1490
|
-
useEffect(() => {
|
|
1491
|
-
return () => {
|
|
1492
|
-
if (infoTimeoutRef.current) clearTimeout(infoTimeoutRef.current);
|
|
1493
|
-
};
|
|
1494
|
-
}, []);
|
|
1495
|
-
useEffect(() => {
|
|
1496
|
-
setPreviews((current) => {
|
|
1497
|
-
const prevMap = /* @__PURE__ */ new Map();
|
|
1498
|
-
current.forEach((p) => {
|
|
1499
|
-
prevMap.set(p.id, p);
|
|
1500
|
-
if (p.url) prevMap.set(p.url, p);
|
|
1501
|
-
});
|
|
1502
|
-
const synced = value.map((img) => mapUploadedToPreview(img, prevMap.get(img.url)));
|
|
1503
|
-
const pending = current.filter(
|
|
1504
|
-
(p) => !value.some((img) => img.url === p.id || p.url && img.url === p.url) && (p.isUploading || Boolean(p.error))
|
|
1505
|
-
);
|
|
1506
|
-
const next = [...synced, ...pending];
|
|
1507
|
-
const isSame = next.length === current.length && next.every((it, idx) => {
|
|
1508
|
-
const p = current[idx];
|
|
1509
|
-
return p && p.id === it.id && p.url === it.url && p.altText === it.altText && p.blurColor === it.blurColor && p.isUploading === it.isUploading;
|
|
1510
|
-
});
|
|
1511
|
-
const resolved = isSame ? current : next;
|
|
1512
|
-
previewsRef.current = resolved;
|
|
1513
|
-
return resolved;
|
|
1514
|
-
});
|
|
1515
|
-
}, [value]);
|
|
1516
|
-
const emitImmediateChange = (nextPreviews) => {
|
|
1517
|
-
if (!requiresManualCommit) onChange(collectUploadedData(nextPreviews, true));
|
|
1518
|
-
};
|
|
1519
|
-
const patchByFile = (file, patch, emit = false) => {
|
|
1520
|
-
const next = previewsRef.current.map((p) => p.file === file ? { ...p, ...patch } : p);
|
|
1521
|
-
previewsRef.current = next;
|
|
1522
|
-
setPreviews(next);
|
|
1523
|
-
if (emit) emitImmediateChange(next);
|
|
1524
|
-
};
|
|
1525
|
-
const patchPreview = (id, patch) => {
|
|
1526
|
-
const next = previewsRef.current.map((p) => p.id === id ? patch(p) : p);
|
|
1527
|
-
previewsRef.current = next;
|
|
1528
|
-
setPreviews(next);
|
|
1529
|
-
emitImmediateChange(next);
|
|
1530
|
-
};
|
|
1531
|
-
const { uploadImage } = useImageUpload({
|
|
1532
|
-
preset,
|
|
1533
|
-
folder: options.folder,
|
|
1534
|
-
bucket: options.bucket,
|
|
1535
|
-
metadata: options.metadata,
|
|
1536
|
-
outputFormat: options.outputFormat,
|
|
1537
|
-
quality: QUALITY_PRESETS[qualityLevel].value,
|
|
1538
|
-
maxDimensions: options.maxDimensions,
|
|
1539
|
-
customFilename: options.customFilename,
|
|
1540
|
-
endpoint: options.endpoint,
|
|
1541
|
-
uploader: options.uploader,
|
|
1542
|
-
headers: options.headers,
|
|
1543
|
-
withCredentials: options.withCredentials,
|
|
1544
|
-
locale,
|
|
1545
|
-
onSuccess: (data, file) => {
|
|
1546
|
-
patchByFile(file, {
|
|
1547
|
-
url: data.url,
|
|
1548
|
-
uploadMessage: void 0,
|
|
1549
|
-
originalSize: data.originalSize,
|
|
1550
|
-
optimizedSize: data.size,
|
|
1551
|
-
data,
|
|
1552
|
-
blurColor: data.blurColor,
|
|
1553
|
-
error: void 0,
|
|
1554
|
-
isUploading: false,
|
|
1555
|
-
progress: 100
|
|
1556
|
-
}, true);
|
|
1557
|
-
setUploadStats((s) => ({ ...s, completed: s.completed + 1 }));
|
|
1558
|
-
},
|
|
1559
|
-
onError: (error, file) => {
|
|
1560
|
-
patchByFile(file, { uploadMessage: void 0, error, isUploading: false, progress: 0 });
|
|
1561
|
-
setUploadStats((s) => ({ ...s, failed: s.failed + 1 }));
|
|
1562
|
-
},
|
|
1563
|
-
onProgress: (progress, uploadMessage, file) => {
|
|
1564
|
-
patchByFile(file, { uploadMessage, progress, isUploading: true });
|
|
1565
|
-
}
|
|
1566
|
-
});
|
|
1567
|
-
const handleFileSelect = async (files) => {
|
|
1568
|
-
setValidationError("");
|
|
1569
|
-
setInfoMessage("");
|
|
1570
|
-
const allFiles = Array.from(files);
|
|
1571
|
-
const imageFiles = allFiles.filter((file) => file.type.startsWith("image/"));
|
|
1572
|
-
if (imageFiles.length === 0) {
|
|
1573
|
-
setValidationError(ui.noValidImageFiles);
|
|
1574
|
-
return;
|
|
1575
|
-
}
|
|
1576
|
-
if (allFiles.length > imageFiles.length) {
|
|
1577
|
-
const skipped = allFiles.length - imageFiles.length;
|
|
1578
|
-
const msg = ui.selectedImagesSkipped.replace("{imageCount}", String(imageFiles.length)).replace("{imageSuffix}", imageFiles.length > 1 ? "s" : "").replace("{skippedCount}", String(skipped)).replace("{skippedSuffix}", skipped > 1 ? "s" : "");
|
|
1579
|
-
setInfoMessage(msg);
|
|
1580
|
-
if (infoTimeoutRef.current) clearTimeout(infoTimeoutRef.current);
|
|
1581
|
-
infoTimeoutRef.current = setTimeout(() => setInfoMessage(""), 5e3);
|
|
1582
|
-
}
|
|
1583
|
-
const validationResult = validateMultipleFiles(imageFiles, maxSizeMB, previews.length, maxImages, locale);
|
|
1584
|
-
if (validationResult) {
|
|
1585
|
-
setValidationError(validationResult);
|
|
1586
|
-
return;
|
|
1587
|
-
}
|
|
1588
|
-
setUploadStats({ total: imageFiles.length, completed: 0, failed: 0 });
|
|
1589
|
-
const newPreviews = [];
|
|
1590
|
-
for (const file of imageFiles) {
|
|
1591
|
-
try {
|
|
1592
|
-
const url = await createPreview(file);
|
|
1593
|
-
newPreviews.push({
|
|
1594
|
-
id: `temp-${Date.now()}-${Math.random()}`,
|
|
1595
|
-
url,
|
|
1596
|
-
file,
|
|
1597
|
-
fileName: file.name,
|
|
1598
|
-
uploadMessage: ui.queued,
|
|
1599
|
-
originalSize: file.size,
|
|
1600
|
-
optimizedSize: null,
|
|
1601
|
-
isUploading: true,
|
|
1602
|
-
progress: 0
|
|
1603
|
-
});
|
|
1604
|
-
} catch {
|
|
1605
|
-
setValidationError(ui.failedCreatePreviewFor.replace("{file}", file.name));
|
|
1606
|
-
return;
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
const nextBatch = [...previewsRef.current, ...newPreviews];
|
|
1610
|
-
previewsRef.current = nextBatch;
|
|
1611
|
-
setPreviews(nextBatch);
|
|
1612
|
-
let nextIndex = 0;
|
|
1613
|
-
const workerCount = Math.max(1, Math.min(maxParallelUploads, imageFiles.length));
|
|
1614
|
-
await Promise.all(
|
|
1615
|
-
Array.from({ length: workerCount }, async () => {
|
|
1616
|
-
while (nextIndex < imageFiles.length) {
|
|
1617
|
-
const file = imageFiles[nextIndex];
|
|
1618
|
-
nextIndex += 1;
|
|
1619
|
-
await uploadImage(file);
|
|
1620
|
-
}
|
|
1621
|
-
})
|
|
1622
|
-
);
|
|
1623
|
-
};
|
|
1624
|
-
const removeIds = (ids) => {
|
|
1625
|
-
const next = previewsRef.current.filter((p) => !ids.has(p.id));
|
|
1626
|
-
previewsRef.current = next;
|
|
1627
|
-
setPreviews(next);
|
|
1628
|
-
emitImmediateChange(next);
|
|
1629
|
-
};
|
|
1630
|
-
const handleRemove = (id) => {
|
|
1631
|
-
removeIds(/* @__PURE__ */ new Set([id]));
|
|
1632
|
-
setSelectedPreviews((prev) => {
|
|
1633
|
-
if (!prev.has(id)) return prev;
|
|
1634
|
-
const copy = new Set(prev);
|
|
1635
|
-
copy.delete(id);
|
|
1636
|
-
return copy;
|
|
1637
|
-
});
|
|
1638
|
-
};
|
|
1639
|
-
const handleRemoveSelected = () => {
|
|
1640
|
-
removeIds(new Set(selectedPreviews));
|
|
1641
|
-
setSelectedPreviews(/* @__PURE__ */ new Set());
|
|
1642
|
-
};
|
|
1643
|
-
const toggleSelect = (id) => {
|
|
1644
|
-
setSelectedPreviews((prev) => {
|
|
1645
|
-
const copy = new Set(prev);
|
|
1646
|
-
if (copy.has(id)) copy.delete(id);
|
|
1647
|
-
else copy.add(id);
|
|
1648
|
-
return copy;
|
|
1649
|
-
});
|
|
1650
|
-
};
|
|
1651
|
-
const handleRetryFailed = async () => {
|
|
1652
|
-
for (const item of previews.filter((p) => p.error && p.file)) {
|
|
1653
|
-
if (item.file) {
|
|
1654
|
-
patchByFile(item.file, { error: void 0, isUploading: true, uploadMessage: ui.retrying });
|
|
1655
|
-
await uploadImage(item.file);
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
};
|
|
1659
|
-
const handleAltTextSave = (previewId, altText) => {
|
|
1660
|
-
patchPreview(previewId, (p) => ({ ...p, altText, data: p.data ? { ...p.data, altText } : p.data }));
|
|
1661
|
-
setEditingAltTextId(null);
|
|
1662
|
-
setShowMissingAltWarning(false);
|
|
1663
|
-
};
|
|
1664
|
-
const handleColorChange = (previewId, blurColor) => {
|
|
1665
|
-
patchPreview(previewId, (p) => ({ ...p, blurColor, data: p.data ? { ...p.data, blurColor } : p.data }));
|
|
1666
|
-
};
|
|
1667
|
-
const isUploading = previews.some((p) => p.isUploading);
|
|
1668
|
-
const hasFailedUploads = previews.some((p) => Boolean(p.error));
|
|
1669
|
-
const uploadingPreviews = previews.filter((p) => p.isUploading);
|
|
1670
|
-
const completedPreviews = previews.filter((p) => Boolean(p.data) && !p.isUploading);
|
|
1671
|
-
const imagesWithoutAlt = completedPreviews.filter((p) => !p.altText || !p.altText.trim());
|
|
1672
|
-
const editingTarget = editingAltTextId ? previews.find((p) => p.id === editingAltTextId) ?? null : null;
|
|
1673
|
-
const handleSaveImages = () => {
|
|
1674
|
-
if (requireAltText && imagesWithoutAlt.length > 0) {
|
|
1675
|
-
const count = imagesWithoutAlt.length;
|
|
1676
|
-
setShowMissingAltWarning(true);
|
|
1677
|
-
setValidationError(
|
|
1678
|
-
ui.needsAltBeforeSave.replace("{count}", String(count)).replace("{suffix}", count > 1 ? "s" : "").replace("{verbSuffix}", count > 1 ? "" : "s")
|
|
1679
|
-
);
|
|
1680
|
-
return;
|
|
1681
|
-
}
|
|
1682
|
-
setShowMissingAltWarning(false);
|
|
1683
|
-
setValidationError("");
|
|
1684
|
-
onChange(collectUploadedData(previews, false));
|
|
1685
|
-
onClose?.();
|
|
1686
|
-
};
|
|
1687
|
-
return {
|
|
1688
|
-
locale,
|
|
1689
|
-
ui,
|
|
1690
|
-
requireAltText,
|
|
1691
|
-
maxSizeMB,
|
|
1692
|
-
previews,
|
|
1693
|
-
validationError,
|
|
1694
|
-
infoMessage,
|
|
1695
|
-
selectedPreviews,
|
|
1696
|
-
setSelectedPreviews,
|
|
1697
|
-
uploadStats,
|
|
1698
|
-
editingAltTextId,
|
|
1699
|
-
setEditingAltTextId,
|
|
1700
|
-
showMissingAltWarning,
|
|
1701
|
-
qualityLevel,
|
|
1702
|
-
setQualityLevel,
|
|
1703
|
-
isUploading,
|
|
1704
|
-
hasFailedUploads,
|
|
1705
|
-
uploadingPreviews,
|
|
1706
|
-
completedPreviews,
|
|
1707
|
-
imagesWithoutAlt,
|
|
1708
|
-
editingTarget,
|
|
1709
|
-
handleFileSelect,
|
|
1710
|
-
handleRemove,
|
|
1711
|
-
handleRemoveSelected,
|
|
1712
|
-
toggleSelect,
|
|
1713
|
-
handleRetryFailed,
|
|
1714
|
-
handleAltTextSave,
|
|
1715
|
-
handleColorChange,
|
|
1716
|
-
handleSaveImages
|
|
1717
|
-
};
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
// src/react/headless/useMultiUpload.ts
|
|
1721
|
-
var DEFAULT_ACCEPT2 = "image/jpeg,image/png,image/webp,image/avif,image/svg+xml";
|
|
1722
|
-
function useMultiUpload(options) {
|
|
1723
|
-
const {
|
|
1724
|
-
accept = DEFAULT_ACCEPT2,
|
|
1725
|
-
disabled = false,
|
|
1726
|
-
error: externalError,
|
|
1727
|
-
maxImages = 999
|
|
1728
|
-
} = options;
|
|
1729
|
-
const fileInputRef = useRef(null);
|
|
1730
|
-
const folderInputRef = useRef(null);
|
|
1731
|
-
const {
|
|
1732
|
-
locale,
|
|
1733
|
-
ui,
|
|
1734
|
-
maxSizeMB,
|
|
1735
|
-
previews,
|
|
1736
|
-
validationError,
|
|
1737
|
-
infoMessage,
|
|
1738
|
-
selectedPreviews,
|
|
1739
|
-
setSelectedPreviews,
|
|
1740
|
-
uploadStats,
|
|
1741
|
-
qualityLevel,
|
|
1742
|
-
setQualityLevel,
|
|
1743
|
-
isUploading,
|
|
1744
|
-
hasFailedUploads,
|
|
1745
|
-
uploadingPreviews,
|
|
1746
|
-
completedPreviews,
|
|
1747
|
-
handleFileSelect,
|
|
1748
|
-
handleRemove,
|
|
1749
|
-
handleRemoveSelected,
|
|
1750
|
-
toggleSelect,
|
|
1751
|
-
handleRetryFailed,
|
|
1752
|
-
handleAltTextSave,
|
|
1753
|
-
handleColorChange,
|
|
1754
|
-
handleSaveImages
|
|
1755
|
-
} = useMultiImageState(options);
|
|
1756
|
-
const { isDragging, dragHandlers } = useDragAndDrop({
|
|
1757
|
-
disabled,
|
|
1758
|
-
onDrop: (files) => {
|
|
1759
|
-
void handleFileSelect(files);
|
|
1760
|
-
}
|
|
1761
|
-
});
|
|
1762
|
-
const displayError = externalError || validationError || "";
|
|
1763
|
-
const remainingCount = Math.max(0, maxImages - previews.length);
|
|
1764
|
-
const state = resolveUploadDataState({
|
|
1765
|
-
disabled,
|
|
1766
|
-
hasError: Boolean(displayError),
|
|
1767
|
-
isUploading,
|
|
1768
|
-
isDragging,
|
|
1769
|
-
hasContent: previews.length > 0
|
|
1770
|
-
});
|
|
1771
|
-
const openFileDialog = () => {
|
|
1772
|
-
if (!disabled) fileInputRef.current?.click();
|
|
1773
|
-
};
|
|
1774
|
-
const openFolderDialog = () => {
|
|
1775
|
-
if (!disabled) folderInputRef.current?.click();
|
|
1776
|
-
};
|
|
1777
|
-
const getDropzoneProps = (overrides) => ({
|
|
1778
|
-
...overrides,
|
|
1779
|
-
role: overrides?.role ?? "button",
|
|
1780
|
-
tabIndex: overrides?.tabIndex ?? (disabled ? -1 : 0),
|
|
1781
|
-
"aria-label": overrides?.["aria-label"] ?? ui.selectFilesAria,
|
|
1782
|
-
"aria-disabled": disabled || void 0,
|
|
1783
|
-
"data-state": state,
|
|
1784
|
-
"data-dragging": isDragging || void 0,
|
|
1785
|
-
"data-uploading": isUploading || void 0,
|
|
1786
|
-
"data-disabled": disabled || void 0,
|
|
1787
|
-
"data-error": Boolean(displayError) || void 0,
|
|
1788
|
-
onClick: (event) => {
|
|
1789
|
-
if (event.target === fileInputRef.current || event.target === folderInputRef.current) return;
|
|
1790
|
-
overrides?.onClick?.(event);
|
|
1791
|
-
if (!event.defaultPrevented && !disabled) openFileDialog();
|
|
1792
|
-
},
|
|
1793
|
-
onKeyDown: (event) => {
|
|
1794
|
-
overrides?.onKeyDown?.(event);
|
|
1795
|
-
if (!event.defaultPrevented && !disabled && event.target === event.currentTarget && (event.key === "Enter" || event.key === " ")) {
|
|
1796
|
-
event.preventDefault();
|
|
1797
|
-
openFileDialog();
|
|
1798
|
-
}
|
|
1799
|
-
},
|
|
1800
|
-
onDragEnter: (event) => {
|
|
1801
|
-
overrides?.onDragEnter?.(event);
|
|
1802
|
-
dragHandlers.onDragEnter(event);
|
|
1803
|
-
},
|
|
1804
|
-
onDragLeave: (event) => {
|
|
1805
|
-
overrides?.onDragLeave?.(event);
|
|
1806
|
-
dragHandlers.onDragLeave(event);
|
|
1807
|
-
},
|
|
1808
|
-
onDragOver: (event) => {
|
|
1809
|
-
overrides?.onDragOver?.(event);
|
|
1810
|
-
dragHandlers.onDragOver(event);
|
|
1811
|
-
},
|
|
1812
|
-
onDrop: (event) => {
|
|
1813
|
-
overrides?.onDrop?.(event);
|
|
1814
|
-
dragHandlers.onDrop(event);
|
|
1815
|
-
}
|
|
1816
|
-
});
|
|
1817
|
-
const buildInputProps = (ref, defaultAriaLabel, isFolder, overrides) => ({
|
|
1818
|
-
...overrides,
|
|
1819
|
-
...isFolder ? { webkitdirectory: "", directory: "" } : {},
|
|
1820
|
-
ref,
|
|
1821
|
-
type: "file",
|
|
1822
|
-
multiple: overrides?.multiple ?? true,
|
|
1823
|
-
accept: overrides?.accept ?? accept,
|
|
1824
|
-
disabled: overrides?.disabled ?? disabled,
|
|
1825
|
-
"aria-label": overrides?.["aria-label"] ?? defaultAriaLabel,
|
|
1826
|
-
style: overrides?.style ? { ...HIDDEN_INPUT_STYLE, ...overrides.style } : HIDDEN_INPUT_STYLE,
|
|
1827
|
-
onClick: (event) => {
|
|
1828
|
-
overrides?.onClick?.(event);
|
|
1829
|
-
event.stopPropagation();
|
|
1830
|
-
},
|
|
1831
|
-
onChange: (event) => {
|
|
1832
|
-
overrides?.onChange?.(event);
|
|
1833
|
-
if (!event.defaultPrevented) {
|
|
1834
|
-
const files = event.target.files;
|
|
1835
|
-
if (files && files.length > 0) void handleFileSelect(files);
|
|
1836
|
-
event.target.value = "";
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
});
|
|
1840
|
-
return {
|
|
1841
|
-
state,
|
|
1842
|
-
items: previews,
|
|
1843
|
-
completedItems: completedPreviews,
|
|
1844
|
-
uploadingItems: uploadingPreviews,
|
|
1845
|
-
selectedIds: selectedPreviews,
|
|
1846
|
-
stats: uploadStats,
|
|
1847
|
-
isDragging,
|
|
1848
|
-
isUploading,
|
|
1849
|
-
hasFailedUploads,
|
|
1850
|
-
error: displayError,
|
|
1851
|
-
infoMessage,
|
|
1852
|
-
qualityLevel,
|
|
1853
|
-
maxSizeMB,
|
|
1854
|
-
maxImages,
|
|
1855
|
-
remainingCount,
|
|
1856
|
-
disabled,
|
|
1857
|
-
locale,
|
|
1858
|
-
ui,
|
|
1859
|
-
openFileDialog,
|
|
1860
|
-
openFolderDialog,
|
|
1861
|
-
selectFiles: handleFileSelect,
|
|
1862
|
-
remove: handleRemove,
|
|
1863
|
-
removeSelected: handleRemoveSelected,
|
|
1864
|
-
toggleSelect,
|
|
1865
|
-
selectAll: () => setSelectedPreviews(new Set(previews.map((p) => p.id))),
|
|
1866
|
-
clearSelection: () => setSelectedPreviews(/* @__PURE__ */ new Set()),
|
|
1867
|
-
retryFailed: handleRetryFailed,
|
|
1868
|
-
save: handleSaveImages,
|
|
1869
|
-
setQualityLevel,
|
|
1870
|
-
setAltText: handleAltTextSave,
|
|
1871
|
-
setBlurColor: handleColorChange,
|
|
1872
|
-
getDropzoneProps,
|
|
1873
|
-
getInputProps: (overrides) => buildInputProps(fileInputRef, ui.selectFilesAria, false, overrides),
|
|
1874
|
-
getFolderInputProps: (overrides) => buildInputProps(folderInputRef, ui.selectFolderAria, true, overrides)
|
|
1875
|
-
};
|
|
1876
|
-
}
|
|
1877
|
-
function HeadlessSingleUpload(props) {
|
|
1878
|
-
const controller = useSingleUpload(props);
|
|
1879
|
-
return /* @__PURE__ */ jsx(Fragment, { children: props.children(controller) });
|
|
1880
|
-
}
|
|
1881
|
-
function HeadlessMultiUpload(props) {
|
|
1882
|
-
const controller = useMultiUpload(props);
|
|
1883
|
-
return /* @__PURE__ */ jsx(Fragment, { children: props.children(controller) });
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
export { HeadlessMultiUpload, HeadlessSingleUpload, ImageUploadProvider, useDragAndDrop, useDragAndDrop as useDropzone, useFilePreview, useImageUpload, useImageUploadContext, useMultiUpload, useSingleUpload };
|
|
1887
|
-
//# sourceMappingURL=headless.js.map
|
|
1888
27
|
//# sourceMappingURL=headless.js.map
|