sales-frontend-components 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +35 -17
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +35 -17
- package/package.json +14 -14
package/dist/index.cjs.js
CHANGED
|
@@ -227,6 +227,18 @@ var _MessageEventManager = class _MessageEventManager2 {
|
|
|
227
227
|
};
|
|
228
228
|
__publicField(_MessageEventManager, "instance");
|
|
229
229
|
var MessageEventManager = _MessageEventManager;
|
|
230
|
+
function getCanvasExportFileInfo(imageUrl) {
|
|
231
|
+
const ext = imageUrl.split(".").pop()?.split("?")[0]?.toLowerCase();
|
|
232
|
+
switch (ext) {
|
|
233
|
+
case "jpg":
|
|
234
|
+
case "jpeg":
|
|
235
|
+
return { contentType: "image/jpeg", fileExt: "jpg" };
|
|
236
|
+
case "webp":
|
|
237
|
+
return { contentType: "image/webp", fileExt: "webp" };
|
|
238
|
+
default:
|
|
239
|
+
return { contentType: "image/png", fileExt: "png" };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
230
242
|
function base64ToBlob(base64String, contentType = "") {
|
|
231
243
|
const regex = /^data:([a-zA-Z0-9/+.-]+);base64,/;
|
|
232
244
|
const matches = base64String.match(regex);
|
|
@@ -320,41 +332,46 @@ async function imageUrlToFileFetch(imageUrl) {
|
|
|
320
332
|
const file = new File([blob], name, { type });
|
|
321
333
|
return file;
|
|
322
334
|
}
|
|
323
|
-
async function imageUrlToFile(imageUrl) {
|
|
324
|
-
|
|
325
|
-
const fileConvertType = getCookie$1(fileConvertTypeCookieKey);
|
|
326
|
-
if (fileConvertType === "fetch") {
|
|
335
|
+
async function imageUrlToFile(imageUrl, convertType) {
|
|
336
|
+
if (convertType === "fetch") {
|
|
327
337
|
return await imageUrlToFileFetch(imageUrl);
|
|
328
338
|
}
|
|
329
|
-
if (
|
|
339
|
+
if (convertType === "xhr") {
|
|
330
340
|
return await imageUrlToFileWithXMLHttpRequest(imageUrl);
|
|
331
341
|
}
|
|
332
342
|
return await imageUrlToFileWithCanvas(imageUrl);
|
|
333
343
|
}
|
|
334
344
|
async function imageUrlToFileWithCanvas(imageUrl) {
|
|
335
345
|
const newImage = new Image();
|
|
336
|
-
newImage.src = imageUrl;
|
|
337
|
-
newImage.crossOrigin = "Anonymous";
|
|
338
346
|
return new Promise((resolve, reject) => {
|
|
339
347
|
newImage.onload = () => {
|
|
340
348
|
const canvas = document.createElement("canvas");
|
|
341
349
|
canvas.width = newImage.width;
|
|
342
350
|
canvas.height = newImage.height;
|
|
343
351
|
const ctx = canvas.getContext("2d");
|
|
344
|
-
if (ctx) {
|
|
352
|
+
if (!ctx) {
|
|
353
|
+
reject(new Error("Failed to get canvas 2d context."));
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
try {
|
|
345
357
|
ctx.drawImage(newImage, 0, 0);
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
358
|
+
const { contentType, fileExt } = getCanvasExportFileInfo(imageUrl);
|
|
359
|
+
const dataUrl = canvas.toDataURL(contentType);
|
|
360
|
+
const blob = base64ToBlob(dataUrl, contentType);
|
|
361
|
+
resolve(blobToFile(blob, `image.${fileExt}`));
|
|
362
|
+
} catch (error) {
|
|
363
|
+
reject(
|
|
364
|
+
new Error(
|
|
365
|
+
`imageUrlToFileWithCanvas failed for "${imageUrl}". ${error instanceof Error ? error.message : "Unknown error"}`
|
|
366
|
+
)
|
|
367
|
+
);
|
|
353
368
|
}
|
|
354
369
|
};
|
|
355
370
|
newImage.onerror = (e) => {
|
|
356
371
|
reject(JSON.stringify(e));
|
|
357
372
|
};
|
|
373
|
+
newImage.crossOrigin = "Anonymous";
|
|
374
|
+
newImage.src = imageUrl;
|
|
358
375
|
});
|
|
359
376
|
}
|
|
360
377
|
async function imageUrlToFileWithXMLHttpRequest(imageUrl) {
|
|
@@ -4566,7 +4583,8 @@ function useCamera({
|
|
|
4566
4583
|
buttonText,
|
|
4567
4584
|
initData,
|
|
4568
4585
|
useNativeCamera = false,
|
|
4569
|
-
responseFileType
|
|
4586
|
+
responseFileType,
|
|
4587
|
+
convertType = "canvas"
|
|
4570
4588
|
} = {}) {
|
|
4571
4589
|
const convertedInitData = initData?.map((data, index) => ({ ...data, id: String(index + 1) }));
|
|
4572
4590
|
const [attachedPhotos, setAttachedPhotos] = React9.useState(convertedInitData || []);
|
|
@@ -4590,7 +4608,7 @@ function useCamera({
|
|
|
4590
4608
|
};
|
|
4591
4609
|
const processImage = async (uri) => {
|
|
4592
4610
|
if (responseFileType === "scheme") {
|
|
4593
|
-
const file = await imageUrlToFile(uri);
|
|
4611
|
+
const file = await imageUrlToFile(uri, convertType);
|
|
4594
4612
|
await imageHandler(file);
|
|
4595
4613
|
} else {
|
|
4596
4614
|
const file = await base64ToFile(uri, "image.jpg");
|
package/dist/index.d.ts
CHANGED
|
@@ -118,6 +118,7 @@ interface cameraOptions {
|
|
|
118
118
|
cameraOnly: boolean;
|
|
119
119
|
buttonText?: string;
|
|
120
120
|
responseFileType?: 'base64' | 'scheme';
|
|
121
|
+
convertType?: 'fetch' | 'xhr' | 'canvas';
|
|
121
122
|
resize: {
|
|
122
123
|
resizeRatio?: number;
|
|
123
124
|
processType?: 'quality' | 'px' | 'mixed';
|
|
@@ -175,7 +176,7 @@ interface AddImageInfo {
|
|
|
175
176
|
* responseFileType fetch로 이미지자원을 가져올때 ios이슈가 있어서,
|
|
176
177
|
* scheme, base64 두가지 타입으로 설정가능하도록 변경됨
|
|
177
178
|
*/
|
|
178
|
-
declare function useCamera({ onChange, resize: resizeOption, cameraOnly, onDelete, show, type, buttonText, initData, useNativeCamera, responseFileType }?: Partial<cameraOptions>): {
|
|
179
|
+
declare function useCamera({ onChange, resize: resizeOption, cameraOnly, onDelete, show, type, buttonText, initData, useNativeCamera, responseFileType, convertType }?: Partial<cameraOptions>): {
|
|
179
180
|
onClick: () => void;
|
|
180
181
|
getImage: (imageId: string) => AttachedPhoto | undefined;
|
|
181
182
|
deleteImage: (imageId: string) => void;
|
package/dist/index.esm.js
CHANGED
|
@@ -225,6 +225,18 @@ var _MessageEventManager = class _MessageEventManager2 {
|
|
|
225
225
|
};
|
|
226
226
|
__publicField(_MessageEventManager, "instance");
|
|
227
227
|
var MessageEventManager = _MessageEventManager;
|
|
228
|
+
function getCanvasExportFileInfo(imageUrl) {
|
|
229
|
+
const ext = imageUrl.split(".").pop()?.split("?")[0]?.toLowerCase();
|
|
230
|
+
switch (ext) {
|
|
231
|
+
case "jpg":
|
|
232
|
+
case "jpeg":
|
|
233
|
+
return { contentType: "image/jpeg", fileExt: "jpg" };
|
|
234
|
+
case "webp":
|
|
235
|
+
return { contentType: "image/webp", fileExt: "webp" };
|
|
236
|
+
default:
|
|
237
|
+
return { contentType: "image/png", fileExt: "png" };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
228
240
|
function base64ToBlob(base64String, contentType = "") {
|
|
229
241
|
const regex = /^data:([a-zA-Z0-9/+.-]+);base64,/;
|
|
230
242
|
const matches = base64String.match(regex);
|
|
@@ -318,41 +330,46 @@ async function imageUrlToFileFetch(imageUrl) {
|
|
|
318
330
|
const file = new File([blob], name, { type });
|
|
319
331
|
return file;
|
|
320
332
|
}
|
|
321
|
-
async function imageUrlToFile(imageUrl) {
|
|
322
|
-
|
|
323
|
-
const fileConvertType = getCookie$1(fileConvertTypeCookieKey);
|
|
324
|
-
if (fileConvertType === "fetch") {
|
|
333
|
+
async function imageUrlToFile(imageUrl, convertType) {
|
|
334
|
+
if (convertType === "fetch") {
|
|
325
335
|
return await imageUrlToFileFetch(imageUrl);
|
|
326
336
|
}
|
|
327
|
-
if (
|
|
337
|
+
if (convertType === "xhr") {
|
|
328
338
|
return await imageUrlToFileWithXMLHttpRequest(imageUrl);
|
|
329
339
|
}
|
|
330
340
|
return await imageUrlToFileWithCanvas(imageUrl);
|
|
331
341
|
}
|
|
332
342
|
async function imageUrlToFileWithCanvas(imageUrl) {
|
|
333
343
|
const newImage = new Image();
|
|
334
|
-
newImage.src = imageUrl;
|
|
335
|
-
newImage.crossOrigin = "Anonymous";
|
|
336
344
|
return new Promise((resolve, reject) => {
|
|
337
345
|
newImage.onload = () => {
|
|
338
346
|
const canvas = document.createElement("canvas");
|
|
339
347
|
canvas.width = newImage.width;
|
|
340
348
|
canvas.height = newImage.height;
|
|
341
349
|
const ctx = canvas.getContext("2d");
|
|
342
|
-
if (ctx) {
|
|
350
|
+
if (!ctx) {
|
|
351
|
+
reject(new Error("Failed to get canvas 2d context."));
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
343
355
|
ctx.drawImage(newImage, 0, 0);
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
356
|
+
const { contentType, fileExt } = getCanvasExportFileInfo(imageUrl);
|
|
357
|
+
const dataUrl = canvas.toDataURL(contentType);
|
|
358
|
+
const blob = base64ToBlob(dataUrl, contentType);
|
|
359
|
+
resolve(blobToFile(blob, `image.${fileExt}`));
|
|
360
|
+
} catch (error) {
|
|
361
|
+
reject(
|
|
362
|
+
new Error(
|
|
363
|
+
`imageUrlToFileWithCanvas failed for "${imageUrl}". ${error instanceof Error ? error.message : "Unknown error"}`
|
|
364
|
+
)
|
|
365
|
+
);
|
|
351
366
|
}
|
|
352
367
|
};
|
|
353
368
|
newImage.onerror = (e) => {
|
|
354
369
|
reject(JSON.stringify(e));
|
|
355
370
|
};
|
|
371
|
+
newImage.crossOrigin = "Anonymous";
|
|
372
|
+
newImage.src = imageUrl;
|
|
356
373
|
});
|
|
357
374
|
}
|
|
358
375
|
async function imageUrlToFileWithXMLHttpRequest(imageUrl) {
|
|
@@ -4564,7 +4581,8 @@ function useCamera({
|
|
|
4564
4581
|
buttonText,
|
|
4565
4582
|
initData,
|
|
4566
4583
|
useNativeCamera = false,
|
|
4567
|
-
responseFileType
|
|
4584
|
+
responseFileType,
|
|
4585
|
+
convertType = "canvas"
|
|
4568
4586
|
} = {}) {
|
|
4569
4587
|
const convertedInitData = initData?.map((data, index) => ({ ...data, id: String(index + 1) }));
|
|
4570
4588
|
const [attachedPhotos, setAttachedPhotos] = useState(convertedInitData || []);
|
|
@@ -4588,7 +4606,7 @@ function useCamera({
|
|
|
4588
4606
|
};
|
|
4589
4607
|
const processImage = async (uri) => {
|
|
4590
4608
|
if (responseFileType === "scheme") {
|
|
4591
|
-
const file = await imageUrlToFile(uri);
|
|
4609
|
+
const file = await imageUrlToFile(uri, convertType);
|
|
4592
4610
|
await imageHandler(file);
|
|
4593
4611
|
} else {
|
|
4594
4612
|
const file = await base64ToFile(uri, "image.jpg");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sales-frontend-components",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
"sales-frontend-stores": "0.0.15",
|
|
46
46
|
"sales-frontend-typescript-config": "0.0.2",
|
|
47
47
|
"sales-frontend-assets": "0.0.27",
|
|
48
|
-
"sales-frontend-api": "0.0.
|
|
49
|
-
"sales-frontend-design-system": "0.2.
|
|
50
|
-
"sales-frontend-bridge": "0.0.
|
|
51
|
-
"sales-frontend-hooks": "0.0.
|
|
52
|
-
"sales-frontend-solution": "0.0.
|
|
53
|
-
"sales-frontend-debug": "0.0.
|
|
48
|
+
"sales-frontend-api": "0.0.179",
|
|
49
|
+
"sales-frontend-design-system": "0.2.3",
|
|
50
|
+
"sales-frontend-bridge": "0.0.119",
|
|
51
|
+
"sales-frontend-hooks": "0.0.180",
|
|
52
|
+
"sales-frontend-solution": "0.0.59",
|
|
53
|
+
"sales-frontend-debug": "0.0.77",
|
|
54
54
|
"sales-frontend-vitest-config": "0.0.3"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
@@ -58,19 +58,19 @@
|
|
|
58
58
|
"react": ">=19.0.0",
|
|
59
59
|
"react-dom": ">=19.0.0",
|
|
60
60
|
"react-hook-form": "^7.58.1",
|
|
61
|
-
"sales-frontend-api": "0.0.
|
|
61
|
+
"sales-frontend-api": "0.0.179",
|
|
62
62
|
"sales-frontend-assets": "0.0.27",
|
|
63
63
|
"sales-frontend-stores": "0.0.15",
|
|
64
|
-
"sales-frontend-design-system": "0.2.
|
|
65
|
-
"sales-frontend-bridge": "0.0.
|
|
66
|
-
"sales-frontend-hooks": "0.0.
|
|
67
|
-
"sales-frontend-solution": "0.0.
|
|
64
|
+
"sales-frontend-design-system": "0.2.3",
|
|
65
|
+
"sales-frontend-bridge": "0.0.119",
|
|
66
|
+
"sales-frontend-hooks": "0.0.180",
|
|
67
|
+
"sales-frontend-solution": "0.0.59"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"classnames": "^2.5.1",
|
|
71
71
|
"dayjs": "^1.11.13",
|
|
72
|
-
"sales-frontend-utils": "0.0.
|
|
73
|
-
"sales-frontend-debug": "0.0.
|
|
72
|
+
"sales-frontend-utils": "0.0.71",
|
|
73
|
+
"sales-frontend-debug": "0.0.77"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"lint": "eslint . --max-warnings 0",
|