sprintify-ui 0.0.183 → 0.0.185

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/sprintify-ui.es.js +16895 -14999
  2. package/dist/style.css +1 -1
  3. package/dist/types/src/components/BaseCropper.vue.d.ts +57 -0
  4. package/dist/types/src/components/BaseCropperModal.vue.d.ts +27 -0
  5. package/dist/types/src/components/BaseDisplayRelativeTime.vue.d.ts +3 -3
  6. package/dist/types/src/components/BaseFilePicker.vue.d.ts +52 -37
  7. package/dist/types/src/components/BaseFilePickerCrop.vue.d.ts +57 -0
  8. package/dist/types/src/components/BaseFileUploader.vue.d.ts +65 -81
  9. package/dist/types/src/components/BaseMediaLibrary.vue.d.ts +20 -10
  10. package/dist/types/src/components/BaseTableColumn.vue.d.ts +1 -1
  11. package/dist/types/src/components/index.d.ts +4 -1
  12. package/dist/types/src/index.d.ts +24 -4
  13. package/dist/types/src/svg/BaseEmptyState.vue.d.ts +1 -1
  14. package/dist/types/src/types/ImagePickerResult.d.ts +5 -0
  15. package/dist/types/src/types/index.d.ts +28 -0
  16. package/dist/types/src/utils/blob.d.ts +3 -0
  17. package/dist/types/src/utils/cropper/avatar.d.ts +5 -0
  18. package/dist/types/src/utils/cropper/cover.d.ts +5 -0
  19. package/dist/types/src/utils/cropper/presetInterface.d.ts +7 -0
  20. package/dist/types/src/utils/cropper/presets.d.ts +6 -0
  21. package/dist/types/src/utils/fileValidations.d.ts +2 -0
  22. package/dist/types/src/utils/index.d.ts +3 -1
  23. package/dist/types/src/utils/resizeImageFromURI.d.ts +1 -0
  24. package/package.json +35 -32
  25. package/src/components/BaseCropper.stories.js +113 -0
  26. package/src/components/BaseCropper.vue +451 -0
  27. package/src/components/BaseCropperModal.stories.js +54 -0
  28. package/src/components/BaseCropperModal.vue +139 -0
  29. package/src/components/BaseFilePicker.stories.js +30 -3
  30. package/src/components/BaseFilePicker.vue +107 -75
  31. package/src/components/BaseFilePickerCrop.stories.js +134 -0
  32. package/src/components/BaseFilePickerCrop.vue +116 -0
  33. package/src/components/BaseFileUploader.stories.js +11 -7
  34. package/src/components/BaseFileUploader.vue +57 -86
  35. package/src/components/BaseMediaLibrary.stories.js +24 -5
  36. package/src/components/BaseMediaLibrary.vue +17 -2
  37. package/src/components/index.ts +6 -0
  38. package/src/lang/en.json +6 -1
  39. package/src/lang/fr.json +13 -8
  40. package/src/types/ImagePickerResult.ts +5 -0
  41. package/src/types/index.ts +31 -0
  42. package/src/utils/blob.ts +30 -0
  43. package/src/utils/cropper/avatar.ts +33 -0
  44. package/src/utils/cropper/cover.ts +41 -0
  45. package/src/utils/cropper/presetInterface.ts +16 -0
  46. package/src/utils/cropper/presets.ts +7 -0
  47. package/src/utils/fileValidations.ts +26 -0
  48. package/src/utils/index.ts +12 -1
  49. 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
+ }