ui-kit-ck-consultant 0.5.216 → 0.5.217

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.js CHANGED
@@ -3028,6 +3028,56 @@ var DropzoneMultiple = /*#__PURE__*/function (_React$Component) {
3028
3028
 
3029
3029
  _this = _React$Component.call(this, props) || this;
3030
3030
 
3031
+ _this.resizeImage = function (base64, mime, callback) {
3032
+ if (callback === void 0) {
3033
+ callback = function callback() {};
3034
+ }
3035
+
3036
+ if (_this.props.maxImageSize && ['image/png', 'image/jpeg', 'image/jpg'].includes(mime)) {
3037
+ var image = new Image();
3038
+ image.src = base64;
3039
+
3040
+ image.onload = function () {
3041
+ var initialWidth = image.width;
3042
+ var initialHeight = image.height;
3043
+ var finalWidth = 0;
3044
+ var finalHeight = 0;
3045
+
3046
+ if (initialWidth > initialHeight) {
3047
+ if (initialWidth > _this.props.maxImageSize) {
3048
+ finalWidth = _this.props.maxImageSize;
3049
+ finalHeight = finalWidth * initialHeight / initialWidth;
3050
+ } else {
3051
+ finalWidth = initialWidth;
3052
+ finalHeight = initialHeight;
3053
+ }
3054
+ } else {
3055
+ if (initialHeight > _this.props.maxImageSize) {
3056
+ finalHeight = _this.props.maxImageSize;
3057
+ finalWidth = finalHeight * initialWidth / initialHeight;
3058
+ } else {
3059
+ finalWidth = initialWidth;
3060
+ finalHeight = initialHeight;
3061
+ }
3062
+ }
3063
+
3064
+ var canvas = document.createElement('canvas');
3065
+ var ctx = canvas.getContext('2d');
3066
+ canvas.width = finalWidth;
3067
+ canvas.height = finalHeight;
3068
+ ctx.drawImage(image, 0, 0, finalWidth, finalHeight);
3069
+ base64 = canvas.toDataURL(mime, 0.9);
3070
+ callback(base64);
3071
+ };
3072
+
3073
+ image.onerror = function () {
3074
+ callback(base64);
3075
+ };
3076
+ } else {
3077
+ callback(base64);
3078
+ }
3079
+ };
3080
+
3031
3081
  _this.handleDeleteFile = function (idx) {
3032
3082
  var files = _this.state.files;
3033
3083
  files.splice(idx, 1);
@@ -3073,22 +3123,23 @@ var DropzoneMultiple = /*#__PURE__*/function (_React$Component) {
3073
3123
  var reader = new window.FileReader();
3074
3124
 
3075
3125
  reader.onload = function () {
3076
- var base64 = reader.result;
3077
- var tmpFiles = _this.state.files;
3078
- tmpFiles.push({
3079
- base64: base64,
3080
- mime: file.type,
3081
- name: file.name,
3082
- extension: name[name.length - 1],
3083
- size: file.size
3084
- });
3085
-
3086
- _this.setState({
3087
- files: tmpFiles
3088
- }, function () {
3089
- _this.currentFile += 1;
3090
-
3091
- _this.nextFile(files);
3126
+ _this.resizeImage(reader.result, file.type, function (base64) {
3127
+ var tmpFiles = _this.state.files;
3128
+ tmpFiles.push({
3129
+ base64: base64,
3130
+ mime: file.type,
3131
+ name: file.name,
3132
+ extension: name[name.length - 1],
3133
+ size: file.size
3134
+ });
3135
+
3136
+ _this.setState({
3137
+ files: tmpFiles
3138
+ }, function () {
3139
+ _this.currentFile += 1;
3140
+
3141
+ _this.nextFile(files);
3142
+ });
3092
3143
  });
3093
3144
  };
3094
3145