datasync-blob 1.0.1 → 1.1.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.
@@ -5,41 +5,78 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.DsBlob = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
- require("../DsBlob.css");
9
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
8
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
9
  class DsBlob extends _react.Component {
12
10
  constructor(props) {
13
11
  super(props);
14
- this.state = {};
12
+ this.state = {
13
+ hover_input: false,
14
+ hover_image: false
15
+ };
16
+ this.debugging = false;
15
17
  }
16
18
 
17
19
  //-----------------------------------------------------------------------------------------------------------------------------------------
18
20
  reduceImage = e => {
19
21
  let imageSource = e.path && e.path[0] || e.srcElement; //Safari compliancy
20
- //console.log("imageSource = ",imageSource);
22
+
23
+ if (this.debugging) console.log("imageSource = ", imageSource);
21
24
  var canvas = document.createElement('canvas'),
22
25
  context,
23
- maxWidth = 800,
24
- maxHeight = 800,
25
26
  width = imageSource.width,
26
27
  height = imageSource.height;
27
- if (width > height) {
28
- if (width > maxWidth) {
29
- height *= maxWidth / width;
30
- width = maxWidth;
28
+
29
+ //Exact size props are set
30
+ if (this.props.width && this.props.height) {
31
+ //Check image size
32
+ if (width > this.props.width || height > this.props.height) {
33
+ alert("L'image est trop grande, le format requis est " + this.props.width + "x" + this.props.height);
34
+ return;
31
35
  }
32
- } else {
33
- if (height > maxHeight) {
34
- width *= maxHeight / height;
35
- height = maxHeight;
36
+
37
+ //Check image size
38
+ if (width < this.props.width || height < this.props.height) {
39
+ alert("L'image est trop petite, le format requis est " + this.props.width + "x" + this.props.height);
40
+ return;
41
+ }
42
+ }
43
+
44
+ //Max size props are set
45
+ if (this.props.maxWidth && this.props.maxHeight) {
46
+ if (width > height) {
47
+ //Check resize is enabled
48
+ if (!this.props.reduceImage) {
49
+ alert("L'image est trop large ! la largeur maximale est de " + this.props.maxWidth);
50
+ return;
51
+ }
52
+ if (width > this.props.maxWidth) {
53
+ height *= this.props.maxWidth / width;
54
+ width = this.props.maxWidth;
55
+ }
56
+ } else {
57
+ if (height > this.props.maxHeight) {
58
+ //Check resize is enabled
59
+ if (!this.props.reduceImage) {
60
+ alert("L'image est trop haute, la hauteur maximale est de " + this.props.maxHeight);
61
+ return;
62
+ }
63
+ width *= this.props.maxHeight / height;
64
+ height = this.props.maxHeight;
65
+ }
36
66
  }
37
67
  }
68
+
69
+ //Build 2d picture
38
70
  canvas.width = width;
39
71
  canvas.height = height;
40
72
  context = canvas.getContext('2d');
41
73
  context.drawImage(imageSource, 0, 0, width, height);
42
- let canvasData = canvas.toDataURL('image/jpg', 0.6); //Jpeg quality reduced from 0.8 down to 0.6
74
+
75
+ //Jpeg conversion
76
+ let jpegCompressionRatio = this.props.jpegQuality && this.props.jpegQuality > 0 && this.props.jpegQuality < 1 ? this.props.jpegQuality : 1;
77
+ let canvasData = canvas.toDataURL('image/jpg', jpegCompressionRatio); //Jpeg conversion
78
+
79
+ if (this.debugging) console.log("jpegCompressionRatio->", jpegCompressionRatio, " canvasData.length = ", canvasData.length);
43
80
  if (this.props.removebase64) {
44
81
  //remove base64 prefix if property is set
45
82
  this.props.uploadPicture({
@@ -81,13 +118,13 @@ class DsBlob extends _react.Component {
81
118
  onInputChange = e => {
82
119
  const errs = [];
83
120
  const files = Array.from(e.target.files);
84
- const types = ['image/png', 'image/jpeg'];
121
+ const types = ['image/png', 'image/jpeg', 'image/gif'];
85
122
  const _1Mo = 1024 * 1024;
86
123
  const SizeLimit = 9;
87
- console.clear();
124
+
88
125
  //Reset input cache value - to assure trigger if user select the same file again
89
126
  e.target.value = null;
90
- console.log("onInputChange");
127
+ if (this.debugging) console.log("onInputChange");
91
128
  if (files.length > 1) {
92
129
  const msg = 'Pas plus d\'une image à la fois';
93
130
  alert(msg);
@@ -101,10 +138,10 @@ class DsBlob extends _react.Component {
101
138
  if (file.size > SizeLimit * _1Mo) {
102
139
  errs.push(`'${file.name}' image trop volumineuse (max:${SizeLimit}Méga-octets)`);
103
140
  }
104
- console.log(`errCount = ${errCount} vs errs.length = ${errs.length}`);
141
+ if (this.debugging) console.log(`errCount = ${errCount} vs errs.length = ${errs.length}`);
105
142
  if (errCount == errs.length) {
106
143
  //None new error occurs
107
- console.log("readImage:", file.name);
144
+ if (this.debugging) console.log("readImage::", file.name);
108
145
  this.readImage(file);
109
146
  }
110
147
  });
@@ -113,21 +150,70 @@ class DsBlob extends _react.Component {
113
150
  }
114
151
  };
115
152
  render() {
153
+ const upload_picture_label = {
154
+ cursor: "pointer"
155
+ };
156
+ const upload_picture_label_input = {
157
+ opacity: "0",
158
+ width: "0px",
159
+ height: "0px"
160
+ };
161
+ const div_show_image_hover = {
162
+ position: "relative",
163
+ margin: "0px",
164
+ opacity: "0.5"
165
+ };
166
+ const div_show_image = {
167
+ position: "relative",
168
+ margin: "0px"
169
+ };
170
+ const div_show_image_hover_input = {
171
+ display: "block",
172
+ top: "0px",
173
+ left: "0px",
174
+ position: "absolute"
175
+ };
176
+ const div_show_image_input = {
177
+ position: "absolute",
178
+ display: "none",
179
+ cursor: "pointer"
180
+ };
116
181
  return /*#__PURE__*/_react.default.createElement("div", null, !this.props.data && /*#__PURE__*/_react.default.createElement("label", {
117
182
  id: "upload-picture-label",
118
- className: this.props.buttonStyle
183
+ className: this.props.buttonStyle,
184
+ style: upload_picture_label
119
185
  }, this.props.Caption, /*#__PURE__*/_react.default.createElement("input", {
186
+ style: upload_picture_label_input,
120
187
  id: "nested-input",
121
188
  type: "file",
122
189
  accept: "image/*",
123
190
  onChange: this.onInputChange,
124
191
  multiple: true
125
192
  })), this.props.data && this.props.data.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
126
- class: "show-image"
193
+ class: "show-image",
194
+ style: div_show_image,
195
+ onMouseOver: () => {
196
+ this.setState({
197
+ hover_input: true,
198
+ hover_image: true
199
+ }, () => {
200
+ if (this.debugging) console.log("onMouseOver");
201
+ });
202
+ },
203
+ onMouseLeave: () => {
204
+ this.setState({
205
+ hover_input: false,
206
+ hover_image: false
207
+ }, () => {
208
+ if (this.debugging) console.log("onMouseLeave");
209
+ });
210
+ }
127
211
  }, /*#__PURE__*/_react.default.createElement("img", {
212
+ style: this.state.hover_image ? div_show_image_hover : div_show_image,
128
213
  src: this.props.removebase64 ? "data:image/png;base64" : "" + this.props.data,
129
214
  className: this.props.pictureStyle
130
215
  }), !this.props.readOnly && /*#__PURE__*/_react.default.createElement("input", {
216
+ style: this.state.hover_input ? div_show_image_hover_input : div_show_image_input,
131
217
  className: "btn btn-primary delete",
132
218
  type: "button",
133
219
  value: "Effacer",
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "datasync-blob",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Datasync Blob component",
5
5
  "main": "./dist/components/DsBlob.js",
6
- "files": ["./dist"],
6
+ "files": [
7
+ "./dist"
8
+ ],
7
9
  "repository": {
8
10
  "type": "git",
9
11
  "url": "https://github.com/pmabiala/datasync-blob.git"
@@ -18,17 +20,23 @@
18
20
  "@babel/preset-env": "^7.24.4",
19
21
  "@babel/preset-react": "^7.24.1",
20
22
  "@testing-library/react": "^14.2.2",
23
+ "javascript-obfuscator": "^4.1.1",
21
24
  "jest": "^29.7.0",
22
25
  "jest-environment-jsdom": "^29.7.0",
23
26
  "jest-transform-css": "^6.0.1",
24
27
  "react": "^18.2.0",
25
- "react-pdf": "^7.7.1"
28
+ "react-pdf": "^7.7.1",
29
+ "webpack": "^5.99.9",
30
+ "webpack-cli": "^6.0.1",
31
+ "webpack-node-externals": "^3.0.0",
32
+ "webpack-obfuscator": "^3.5.1"
26
33
  },
27
34
  "peerDependencies": {
28
35
  "react": "^ 18.2.0"
29
36
  },
30
37
  "scripts": {
31
- "build": "rm -r dist && babel src -d dist --ignore src/**/*.test.jsx && npm run copy-files",
38
+ "build_old": "rm -r dist && babel src -d dist --ignore src/**/*.test.jsx && npm run copy-files",
39
+ "build": "rm -r dist && babel src -d dist --ignore src/**/*.test.jsx && npm run copy-files && webpack --config webpack.config.js",
32
40
  "copy-files": "cp ./src/*.css dist/",
33
41
  "test": "jest --config jest.config.json"
34
42
  },
package/dist/DsBlob.css DELETED
@@ -1,33 +0,0 @@
1
- #upload-picture-label{
2
- cursor: pointer;
3
- }
4
-
5
- #upload-picture-label input{
6
- opacity: 0;
7
- width: 0px;
8
- height: 0px;
9
- }
10
-
11
- div.show-image {
12
- position: relative;
13
- /*float:left;*/
14
- margin:5px;
15
- }
16
- div.show-image:hover img{
17
- opacity:0.5;
18
- }
19
- div.show-image:hover input {
20
- display: block;
21
- }
22
- div.show-image input {
23
- position:absolute;
24
- display:none;
25
- }
26
- div.show-image input.update {
27
- top:0;
28
- left:0;
29
- }
30
- div.show-image input.delete {
31
- top:0;
32
- left:0px;
33
- }