compote-ui 0.16.0 → 0.18.0
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.
|
@@ -4,8 +4,8 @@ export interface ImageCropDialogProps {
|
|
|
4
4
|
open: boolean;
|
|
5
5
|
/** Source image (data URL, blob URL, or regular URL) */
|
|
6
6
|
imageSrc: string;
|
|
7
|
-
/** Called with the processed
|
|
8
|
-
onConfirm: (
|
|
7
|
+
/** Called with the processed Blob on crop or skip */
|
|
8
|
+
onConfirm: (blob: Blob) => void;
|
|
9
9
|
/** Called when the user cancels (Cancel button or clicking outside/Escape) */
|
|
10
10
|
onCancel: () => void;
|
|
11
11
|
/** Dialog title */
|
|
@@ -6,6 +6,6 @@ export interface ImageCropperProps extends UseImageCropperProps {
|
|
|
6
6
|
alt?: string;
|
|
7
7
|
getCroppedImage?: ReturnType<UseImageCropperReturn>['getCroppedImage'];
|
|
8
8
|
getCropData?: ReturnType<UseImageCropperReturn>['getCropData'];
|
|
9
|
-
/** Bindable: returns a processed (cropped + resized + converted)
|
|
10
|
-
getProcessedImage?: (opts?: ProcessImageOptions) => Promise<
|
|
9
|
+
/** Bindable: returns a processed (cropped + resized + converted) Blob in one call */
|
|
10
|
+
getProcessedImage?: (opts?: ProcessImageOptions) => Promise<Blob>;
|
|
11
11
|
}
|
|
@@ -22,6 +22,6 @@ export declare function fileToDataUrl(file: File): Promise<string>;
|
|
|
22
22
|
* Crop a full-resolution source image using natural pixel coordinates, then resize and convert.
|
|
23
23
|
* Use this instead of getCroppedImage() from Ark UI which outputs at CSS/display resolution.
|
|
24
24
|
*/
|
|
25
|
-
export declare function cropImage(src: string, crop: CropRegion, opts?: ProcessImageOptions): Promise<
|
|
26
|
-
/** Resize and convert an image without cropping, returns a
|
|
27
|
-
export declare function processImage(src: string, opts?: ProcessImageOptions): Promise<
|
|
25
|
+
export declare function cropImage(src: string, crop: CropRegion, opts?: ProcessImageOptions): Promise<Blob>;
|
|
26
|
+
/** Resize and convert an image without cropping, returns a Blob */
|
|
27
|
+
export declare function processImage(src: string, opts?: ProcessImageOptions): Promise<Blob>;
|
|
@@ -8,6 +8,16 @@ const defaults = {
|
|
|
8
8
|
quality: 0.85,
|
|
9
9
|
format: 'image/webp'
|
|
10
10
|
};
|
|
11
|
+
function canvasToBlob(canvas, format, quality) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
canvas.toBlob((blob) => {
|
|
14
|
+
if (blob)
|
|
15
|
+
resolve(blob);
|
|
16
|
+
else
|
|
17
|
+
reject(new Error('canvas.toBlob failed'));
|
|
18
|
+
}, format, quality);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
11
21
|
/** Load an image element from a src URL (data URL, blob URL, or regular URL) */
|
|
12
22
|
export function loadImage(src) {
|
|
13
23
|
return new Promise((resolve, reject) => {
|
|
@@ -45,9 +55,9 @@ export async function cropImage(src, crop, opts) {
|
|
|
45
55
|
canvas.height = height;
|
|
46
56
|
const ctx = canvas.getContext('2d');
|
|
47
57
|
ctx.drawImage(img, crop.x, crop.y, crop.width, crop.height, 0, 0, width, height);
|
|
48
|
-
return canvas
|
|
58
|
+
return canvasToBlob(canvas, format, quality);
|
|
49
59
|
}
|
|
50
|
-
/** Resize and convert an image without cropping, returns a
|
|
60
|
+
/** Resize and convert an image without cropping, returns a Blob */
|
|
51
61
|
export async function processImage(src, opts) {
|
|
52
62
|
const { maxWidth, maxHeight, quality, format } = { ...defaults, ...opts };
|
|
53
63
|
const img = await loadImage(src);
|
|
@@ -62,5 +72,5 @@ export async function processImage(src, opts) {
|
|
|
62
72
|
canvas.height = height;
|
|
63
73
|
const ctx = canvas.getContext('2d');
|
|
64
74
|
ctx.drawImage(img, 0, 0, width, height);
|
|
65
|
-
return canvas
|
|
75
|
+
return canvasToBlob(canvas, format, quality);
|
|
66
76
|
}
|