Skip to content

Commit fa03501

Browse files
committed
build: release 1.1.2
1 parent adffe3e commit fa03501

13 files changed

+194
-86
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.1.2 (Oct 18, 2017)
4+
5+
- Normalize related decimal numbers when crop an image with canvas.
6+
37
## 1.1.1 (Oct 11, 2017)
48

59
- Supports to load in node environment (#237).

dist/cropper.common.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* Cropper.js v1.1.1
2+
* Cropper.js v1.1.2
33
* https://github.com/fengyuanchen/cropperjs
44
*
55
* Copyright (c) 2015-2017 Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2017-10-11T13:22:13.165Z
8+
* Date: 2017-10-18T13:27:02.189Z
99
*/
1010

1111
'use strict';
@@ -168,6 +168,8 @@ var TEMPLATE = '<div class="cropper-container">' + '<div class="cropper-wrap-box
168168

169169
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
170170

171+
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
172+
171173
/**
172174
* Check if the given value is not a number.
173175
*/
@@ -309,6 +311,21 @@ function proxy(fn, context) {
309311
};
310312
}
311313

314+
var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/i;
315+
316+
/**
317+
* Normalize decimal number.
318+
* Check out {@link http://0.30000000000000004.com/ }
319+
* @param {number} value - The value to normalize.
320+
* @param {number} [times=100000000000] - The times for normalizing.
321+
* @returns {number} Returns the normalized number.
322+
*/
323+
function normalizeDecimalNumber(value) {
324+
var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100000000000;
325+
326+
return REGEXP_DECIMALS.test(value) ? Math.round(value * times) / times : value;
327+
}
328+
312329
var REGEXP_SUFFIX = /^(width|height|left|top|marginLeft|marginTop)$/;
313330

314331
/**
@@ -927,9 +944,10 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
927944
});
928945
var width = Math.min(maxSizes.width, Math.max(minSizes.width, naturalWidth));
929946
var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));
947+
var params = [-imageNaturalWidth / 2, -imageNaturalHeight / 2, imageNaturalWidth, imageNaturalHeight];
930948

931-
canvas.width = width;
932-
canvas.height = height;
949+
canvas.width = normalizeDecimalNumber(width);
950+
canvas.height = normalizeDecimalNumber(height);
933951
context.fillStyle = fillColor;
934952
context.fillRect(0, 0, width, height);
935953
context.save();
@@ -938,7 +956,9 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
938956
context.scale(scaleX, scaleY);
939957
context.imageSmoothingEnabled = imageSmoothingEnabled;
940958
context.imageSmoothingQuality = imageSmoothingQuality;
941-
context.drawImage(image, Math.floor(-imageNaturalWidth / 2), Math.floor(-imageNaturalHeight / 2), Math.floor(imageNaturalWidth), Math.floor(imageNaturalHeight));
959+
context.drawImage.apply(context, [image].concat(_toConsumableArray(params.map(function (param) {
960+
return Math.floor(normalizeDecimalNumber(param));
961+
}))));
942962
context.restore();
943963
return canvas;
944964
}
@@ -2388,6 +2408,8 @@ var change = {
23882408
}
23892409
};
23902410

2411+
function _toConsumableArray$1(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
2412+
23912413
var methods = {
23922414
// Show the crop box manually
23932415
crop: function crop() {
@@ -3072,8 +3094,8 @@ var methods = {
30723094
var canvas = document.createElement('canvas');
30733095
var context = canvas.getContext('2d');
30743096

3075-
canvas.width = width;
3076-
canvas.height = height;
3097+
canvas.width = normalizeDecimalNumber(width);
3098+
canvas.height = normalizeDecimalNumber(height);
30773099

30783100
context.fillStyle = options.fillColor || 'transparent';
30793101
context.fillRect(0, 0, width, height);
@@ -3139,16 +3161,18 @@ var methods = {
31393161

31403162
// All the numerical parameters should be integer for `drawImage`
31413163
// https://github.com/fengyuanchen/cropper/issues/476
3142-
var params = [Math.floor(srcX), Math.floor(srcY), Math.floor(srcWidth), Math.floor(srcHeight)];
3164+
var params = [srcX, srcY, srcWidth, srcHeight];
31433165

31443166
// Avoid "IndexSizeError"
31453167
if (dstWidth > 0 && dstHeight > 0) {
31463168
var scale = width / initialWidth;
31473169

3148-
params.push(Math.floor(dstX * scale), Math.floor(dstY * scale), Math.floor(dstWidth * scale), Math.floor(dstHeight * scale));
3170+
params.push(dstX * scale, dstY * scale, dstWidth * scale, dstHeight * scale);
31493171
}
31503172

3151-
context.drawImage.apply(context, [source].concat(params));
3173+
context.drawImage.apply(context, [source].concat(_toConsumableArray$1(params.map(function (param) {
3174+
return Math.floor(normalizeDecimalNumber(param));
3175+
}))));
31523176

31533177
return canvas;
31543178
},

dist/cropper.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* Cropper.js v1.1.1
2+
* Cropper.js v1.1.2
33
* https://github.com/fengyuanchen/cropperjs
44
*
55
* Copyright (c) 2015-2017 Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2017-10-11T13:22:08.065Z
8+
* Date: 2017-10-18T13:26:08.981Z
99
*/
1010

1111
.cropper-container {

dist/cropper.esm.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* Cropper.js v1.1.1
2+
* Cropper.js v1.1.2
33
* https://github.com/fengyuanchen/cropperjs
44
*
55
* Copyright (c) 2015-2017 Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2017-10-11T13:22:13.165Z
8+
* Date: 2017-10-18T13:27:02.189Z
99
*/
1010

1111
var global = typeof window !== 'undefined' ? window : {};
@@ -166,6 +166,8 @@ var TEMPLATE = '<div class="cropper-container">' + '<div class="cropper-wrap-box
166166

167167
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
168168

169+
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
170+
169171
/**
170172
* Check if the given value is not a number.
171173
*/
@@ -307,6 +309,21 @@ function proxy(fn, context) {
307309
};
308310
}
309311

312+
var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/i;
313+
314+
/**
315+
* Normalize decimal number.
316+
* Check out {@link http://0.30000000000000004.com/ }
317+
* @param {number} value - The value to normalize.
318+
* @param {number} [times=100000000000] - The times for normalizing.
319+
* @returns {number} Returns the normalized number.
320+
*/
321+
function normalizeDecimalNumber(value) {
322+
var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100000000000;
323+
324+
return REGEXP_DECIMALS.test(value) ? Math.round(value * times) / times : value;
325+
}
326+
310327
var REGEXP_SUFFIX = /^(width|height|left|top|marginLeft|marginTop)$/;
311328

312329
/**
@@ -925,9 +942,10 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
925942
});
926943
var width = Math.min(maxSizes.width, Math.max(minSizes.width, naturalWidth));
927944
var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));
945+
var params = [-imageNaturalWidth / 2, -imageNaturalHeight / 2, imageNaturalWidth, imageNaturalHeight];
928946

929-
canvas.width = width;
930-
canvas.height = height;
947+
canvas.width = normalizeDecimalNumber(width);
948+
canvas.height = normalizeDecimalNumber(height);
931949
context.fillStyle = fillColor;
932950
context.fillRect(0, 0, width, height);
933951
context.save();
@@ -936,7 +954,9 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
936954
context.scale(scaleX, scaleY);
937955
context.imageSmoothingEnabled = imageSmoothingEnabled;
938956
context.imageSmoothingQuality = imageSmoothingQuality;
939-
context.drawImage(image, Math.floor(-imageNaturalWidth / 2), Math.floor(-imageNaturalHeight / 2), Math.floor(imageNaturalWidth), Math.floor(imageNaturalHeight));
957+
context.drawImage.apply(context, [image].concat(_toConsumableArray(params.map(function (param) {
958+
return Math.floor(normalizeDecimalNumber(param));
959+
}))));
940960
context.restore();
941961
return canvas;
942962
}
@@ -2386,6 +2406,8 @@ var change = {
23862406
}
23872407
};
23882408

2409+
function _toConsumableArray$1(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
2410+
23892411
var methods = {
23902412
// Show the crop box manually
23912413
crop: function crop() {
@@ -3070,8 +3092,8 @@ var methods = {
30703092
var canvas = document.createElement('canvas');
30713093
var context = canvas.getContext('2d');
30723094

3073-
canvas.width = width;
3074-
canvas.height = height;
3095+
canvas.width = normalizeDecimalNumber(width);
3096+
canvas.height = normalizeDecimalNumber(height);
30753097

30763098
context.fillStyle = options.fillColor || 'transparent';
30773099
context.fillRect(0, 0, width, height);
@@ -3137,16 +3159,18 @@ var methods = {
31373159

31383160
// All the numerical parameters should be integer for `drawImage`
31393161
// https://github.com/fengyuanchen/cropper/issues/476
3140-
var params = [Math.floor(srcX), Math.floor(srcY), Math.floor(srcWidth), Math.floor(srcHeight)];
3162+
var params = [srcX, srcY, srcWidth, srcHeight];
31413163

31423164
// Avoid "IndexSizeError"
31433165
if (dstWidth > 0 && dstHeight > 0) {
31443166
var scale = width / initialWidth;
31453167

3146-
params.push(Math.floor(dstX * scale), Math.floor(dstY * scale), Math.floor(dstWidth * scale), Math.floor(dstHeight * scale));
3168+
params.push(dstX * scale, dstY * scale, dstWidth * scale, dstHeight * scale);
31473169
}
31483170

3149-
context.drawImage.apply(context, [source].concat(params));
3171+
context.drawImage.apply(context, [source].concat(_toConsumableArray$1(params.map(function (param) {
3172+
return Math.floor(normalizeDecimalNumber(param));
3173+
}))));
31503174

31513175
return canvas;
31523176
},

dist/cropper.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* Cropper.js v1.1.1
2+
* Cropper.js v1.1.2
33
* https://github.com/fengyuanchen/cropperjs
44
*
55
* Copyright (c) 2015-2017 Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2017-10-11T13:22:13.165Z
8+
* Date: 2017-10-18T13:27:02.189Z
99
*/
1010

1111
(function (global, factory) {
@@ -172,6 +172,8 @@ var TEMPLATE = '<div class="cropper-container">' + '<div class="cropper-wrap-box
172172

173173
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
174174

175+
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
176+
175177
/**
176178
* Check if the given value is not a number.
177179
*/
@@ -313,6 +315,21 @@ function proxy(fn, context) {
313315
};
314316
}
315317

318+
var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/i;
319+
320+
/**
321+
* Normalize decimal number.
322+
* Check out {@link http://0.30000000000000004.com/ }
323+
* @param {number} value - The value to normalize.
324+
* @param {number} [times=100000000000] - The times for normalizing.
325+
* @returns {number} Returns the normalized number.
326+
*/
327+
function normalizeDecimalNumber(value) {
328+
var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100000000000;
329+
330+
return REGEXP_DECIMALS.test(value) ? Math.round(value * times) / times : value;
331+
}
332+
316333
var REGEXP_SUFFIX = /^(width|height|left|top|marginLeft|marginTop)$/;
317334

318335
/**
@@ -931,9 +948,10 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
931948
});
932949
var width = Math.min(maxSizes.width, Math.max(minSizes.width, naturalWidth));
933950
var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));
951+
var params = [-imageNaturalWidth / 2, -imageNaturalHeight / 2, imageNaturalWidth, imageNaturalHeight];
934952

935-
canvas.width = width;
936-
canvas.height = height;
953+
canvas.width = normalizeDecimalNumber(width);
954+
canvas.height = normalizeDecimalNumber(height);
937955
context.fillStyle = fillColor;
938956
context.fillRect(0, 0, width, height);
939957
context.save();
@@ -942,7 +960,9 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
942960
context.scale(scaleX, scaleY);
943961
context.imageSmoothingEnabled = imageSmoothingEnabled;
944962
context.imageSmoothingQuality = imageSmoothingQuality;
945-
context.drawImage(image, Math.floor(-imageNaturalWidth / 2), Math.floor(-imageNaturalHeight / 2), Math.floor(imageNaturalWidth), Math.floor(imageNaturalHeight));
963+
context.drawImage.apply(context, [image].concat(_toConsumableArray(params.map(function (param) {
964+
return Math.floor(normalizeDecimalNumber(param));
965+
}))));
946966
context.restore();
947967
return canvas;
948968
}
@@ -2392,6 +2412,8 @@ var change = {
23922412
}
23932413
};
23942414

2415+
function _toConsumableArray$1(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
2416+
23952417
var methods = {
23962418
// Show the crop box manually
23972419
crop: function crop() {
@@ -3076,8 +3098,8 @@ var methods = {
30763098
var canvas = document.createElement('canvas');
30773099
var context = canvas.getContext('2d');
30783100

3079-
canvas.width = width;
3080-
canvas.height = height;
3101+
canvas.width = normalizeDecimalNumber(width);
3102+
canvas.height = normalizeDecimalNumber(height);
30813103

30823104
context.fillStyle = options.fillColor || 'transparent';
30833105
context.fillRect(0, 0, width, height);
@@ -3143,16 +3165,18 @@ var methods = {
31433165

31443166
// All the numerical parameters should be integer for `drawImage`
31453167
// https://github.com/fengyuanchen/cropper/issues/476
3146-
var params = [Math.floor(srcX), Math.floor(srcY), Math.floor(srcWidth), Math.floor(srcHeight)];
3168+
var params = [srcX, srcY, srcWidth, srcHeight];
31473169

31483170
// Avoid "IndexSizeError"
31493171
if (dstWidth > 0 && dstHeight > 0) {
31503172
var scale = width / initialWidth;
31513173

3152-
params.push(Math.floor(dstX * scale), Math.floor(dstY * scale), Math.floor(dstWidth * scale), Math.floor(dstHeight * scale));
3174+
params.push(dstX * scale, dstY * scale, dstWidth * scale, dstHeight * scale);
31533175
}
31543176

3155-
context.drawImage.apply(context, [source].concat(params));
3177+
context.drawImage.apply(context, [source].concat(_toConsumableArray$1(params.map(function (param) {
3178+
return Math.floor(normalizeDecimalNumber(param));
3179+
}))));
31563180

31573181
return canvas;
31583182
},

dist/cropper.min.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cropper.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/css/cropper.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* Cropper.js v1.1.1
2+
* Cropper.js v1.1.2
33
* https://github.com/fengyuanchen/cropperjs
44
*
55
* Copyright (c) 2015-2017 Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2017-10-11T13:22:08.065Z
8+
* Date: 2017-10-18T13:26:08.981Z
99
*/
1010

1111
.cropper-container {

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<div class="container">
4848
<div class="row">
4949
<div class="col-md">
50-
<h1>Cropper.js <small class="h6">v1.1.1</small></h1>
50+
<h1>Cropper.js <small class="h6">v1.1.2</small></h1>
5151
<p class="lead">JavaScript image cropper.</p>
5252
</div>
5353
<div class="col-md">

0 commit comments

Comments
 (0)