sprintify-ui 0.0.182 → 0.0.184
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/sprintify-ui.es.js +16888 -14992
- package/dist/style.css +1 -1
- package/dist/types/src/components/BaseCropper.vue.d.ts +57 -0
- package/dist/types/src/components/BaseCropperModal.vue.d.ts +27 -0
- package/dist/types/src/components/BaseDisplayRelativeTime.vue.d.ts +3 -3
- package/dist/types/src/components/BaseFilePicker.vue.d.ts +52 -37
- package/dist/types/src/components/BaseFilePickerCrop.vue.d.ts +57 -0
- package/dist/types/src/components/BaseFileUploader.vue.d.ts +65 -81
- package/dist/types/src/components/BaseMediaLibrary.vue.d.ts +20 -10
- package/dist/types/src/components/BaseTableColumn.vue.d.ts +1 -1
- package/dist/types/src/components/index.d.ts +4 -1
- package/dist/types/src/index.d.ts +24 -4
- package/dist/types/src/svg/BaseEmptyState.vue.d.ts +1 -1
- package/dist/types/src/types/ImagePickerResult.d.ts +5 -0
- package/dist/types/src/types/index.d.ts +28 -0
- package/dist/types/src/utils/blob.d.ts +3 -0
- package/dist/types/src/utils/cropper/avatar.d.ts +5 -0
- package/dist/types/src/utils/cropper/cover.d.ts +5 -0
- package/dist/types/src/utils/cropper/presetInterface.d.ts +7 -0
- package/dist/types/src/utils/cropper/presets.d.ts +6 -0
- package/dist/types/src/utils/fileValidations.d.ts +2 -0
- package/dist/types/src/utils/index.d.ts +3 -1
- package/dist/types/src/utils/resizeImageFromURI.d.ts +1 -0
- package/package.json +35 -32
- package/src/components/BaseCropper.stories.js +113 -0
- package/src/components/BaseCropper.vue +451 -0
- package/src/components/BaseCropperModal.stories.js +54 -0
- package/src/components/BaseCropperModal.vue +139 -0
- package/src/components/BaseFilePicker.stories.js +30 -3
- package/src/components/BaseFilePicker.vue +107 -75
- package/src/components/BaseFilePickerCrop.stories.js +134 -0
- package/src/components/BaseFilePickerCrop.vue +116 -0
- package/src/components/BaseFileUploader.stories.js +11 -7
- package/src/components/BaseFileUploader.vue +57 -86
- package/src/components/BaseMediaLibrary.stories.js +24 -5
- package/src/components/BaseMediaLibrary.vue +17 -2
- package/src/components/BaseTable.vue +1 -2
- package/src/components/index.ts +6 -0
- package/src/lang/en.json +6 -1
- package/src/lang/fr.json +6 -1
- package/src/types/ImagePickerResult.ts +5 -0
- package/src/types/index.ts +31 -0
- package/src/utils/blob.ts +30 -0
- package/src/utils/cropper/avatar.ts +33 -0
- package/src/utils/cropper/cover.ts +41 -0
- package/src/utils/cropper/presetInterface.ts +16 -0
- package/src/utils/cropper/presets.ts +7 -0
- package/src/utils/fileValidations.ts +26 -0
- package/src/utils/index.ts +12 -1
- package/src/utils/resizeImageFromURI.ts +118 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export default function resizeImageFromURI(
|
|
2
|
+
source: string,
|
|
3
|
+
height: number,
|
|
4
|
+
width: number
|
|
5
|
+
): Promise<string> {
|
|
6
|
+
const img = new Image();
|
|
7
|
+
img.src = source;
|
|
8
|
+
img.crossOrigin = 'anonymous';
|
|
9
|
+
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
img.onload = () => {
|
|
12
|
+
// Check if the image require resize at all
|
|
13
|
+
if (img.height <= height && img.width <= width) {
|
|
14
|
+
resolve(source);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Make sure the width and height preserve the original aspect ratio and adjust if needed
|
|
19
|
+
if (img.height > img.width) {
|
|
20
|
+
width = Math.floor(height * (img.width / img.height));
|
|
21
|
+
} else {
|
|
22
|
+
height = Math.floor(width * (img.height / img.width));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const resizingCanvas: HTMLCanvasElement =
|
|
26
|
+
document.createElement('canvas');
|
|
27
|
+
const resizingCanvasContext = resizingCanvas.getContext('2d');
|
|
28
|
+
|
|
29
|
+
if (!resizingCanvasContext) {
|
|
30
|
+
reject('Could not acquire context 2d');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Start with original image size
|
|
35
|
+
resizingCanvas.width = img.width;
|
|
36
|
+
resizingCanvas.height = img.height;
|
|
37
|
+
|
|
38
|
+
// Draw the original image on the (temp) resizing canvas
|
|
39
|
+
resizingCanvasContext.drawImage(
|
|
40
|
+
img,
|
|
41
|
+
0,
|
|
42
|
+
0,
|
|
43
|
+
resizingCanvas.width,
|
|
44
|
+
resizingCanvas.height
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const curImageDimensions = {
|
|
48
|
+
width: Math.floor(img.width),
|
|
49
|
+
height: Math.floor(img.height),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const halfImageDimensions = {
|
|
53
|
+
width: null as number | null,
|
|
54
|
+
height: null as number | null,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Quickly reduce the size by 50% each time in few iterations until the size is less then
|
|
58
|
+
// 2x time the target size - the motivation for it, is to reduce the aliasing that would have been
|
|
59
|
+
// created with direct reduction of very big image to small image
|
|
60
|
+
while (curImageDimensions.width * 0.5 > width) {
|
|
61
|
+
// Reduce the resizing canvas by half and refresh the image
|
|
62
|
+
halfImageDimensions.width = Math.floor(curImageDimensions.width * 0.5);
|
|
63
|
+
halfImageDimensions.height = Math.floor(
|
|
64
|
+
curImageDimensions.height * 0.5
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
resizingCanvasContext.drawImage(
|
|
68
|
+
resizingCanvas,
|
|
69
|
+
0,
|
|
70
|
+
0,
|
|
71
|
+
curImageDimensions.width,
|
|
72
|
+
curImageDimensions.height,
|
|
73
|
+
0,
|
|
74
|
+
0,
|
|
75
|
+
halfImageDimensions.width,
|
|
76
|
+
halfImageDimensions.height
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
curImageDimensions.width = halfImageDimensions.width;
|
|
80
|
+
curImageDimensions.height = halfImageDimensions.height;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Now do final resize for the resizingCanvas to meet the dimension requirements
|
|
84
|
+
// directly to the output canvas, that will output the final image
|
|
85
|
+
const outputCanvas: HTMLCanvasElement = document.createElement('canvas');
|
|
86
|
+
const outputCanvasContext = outputCanvas.getContext('2d');
|
|
87
|
+
|
|
88
|
+
outputCanvas.width = width;
|
|
89
|
+
outputCanvas.height = height;
|
|
90
|
+
|
|
91
|
+
if (!outputCanvasContext) {
|
|
92
|
+
reject('Could not acquire context 2d');
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
outputCanvasContext.drawImage(
|
|
97
|
+
resizingCanvas,
|
|
98
|
+
0,
|
|
99
|
+
0,
|
|
100
|
+
curImageDimensions.width,
|
|
101
|
+
curImageDimensions.height,
|
|
102
|
+
0,
|
|
103
|
+
0,
|
|
104
|
+
width,
|
|
105
|
+
height
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// output the canvas pixels as an image. params: format, quality
|
|
109
|
+
const base64ResizedImage = outputCanvas.toDataURL('image/jpeg', 0.85);
|
|
110
|
+
|
|
111
|
+
// Cleanup
|
|
112
|
+
resizingCanvas.remove();
|
|
113
|
+
outputCanvas.remove();
|
|
114
|
+
|
|
115
|
+
resolve(base64ResizedImage);
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|