Skip to content
This repository was archived by the owner on Aug 1, 2020. It is now read-only.

Commit 54d7f0e

Browse files
committed
build: release 3.1.2
1 parent 9677715 commit 54d7f0e

File tree

12 files changed

+198
-97
lines changed

12 files changed

+198
-97
lines changed

CHANGELOG.md

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

3+
## 3.1.2 (Oct 18, 2017)
4+
5+
- Normalize related decimal numbers when crop an image with canvas (#918).
6+
- Ignore unnecessary files when publish to NPM (#928).
7+
38
## 3.1.1 (Oct 11, 2017)
49

510
- Supports to load in node environment.

dist/cropper.common.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* Cropper v3.1.1
2+
* Cropper v3.1.2
33
* https://github.com/fengyuanchen/cropper
44
*
55
* Copyright (c) 2014-2017 Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2017-10-11T13:34:24.201Z
8+
* Date: 2017-10-18T13:23:24.651Z
99
*/
1010

1111
'use strict';
@@ -170,6 +170,8 @@ var DEFAULTS = {
170170

171171
var TEMPLATE = '<div class="cropper-container">' + '<div class="cropper-wrap-box">' + '<div class="cropper-canvas"></div>' + '</div>' + '<div class="cropper-drag-box"></div>' + '<div class="cropper-crop-box">' + '<span class="cropper-view-box"></span>' + '<span class="cropper-dashed dashed-h"></span>' + '<span class="cropper-dashed dashed-v"></span>' + '<span class="cropper-center"></span>' + '<span class="cropper-face"></span>' + '<span class="cropper-line line-e" data-action="e"></span>' + '<span class="cropper-line line-n" data-action="n"></span>' + '<span class="cropper-line line-w" data-action="w"></span>' + '<span class="cropper-line line-s" data-action="s"></span>' + '<span class="cropper-point point-e" data-action="e"></span>' + '<span class="cropper-point point-n" data-action="n"></span>' + '<span class="cropper-point point-w" data-action="w"></span>' + '<span class="cropper-point point-s" data-action="s"></span>' + '<span class="cropper-point point-ne" data-action="ne"></span>' + '<span class="cropper-point point-nw" data-action="nw"></span>' + '<span class="cropper-point point-sw" data-action="sw"></span>' + '<span class="cropper-point point-se" data-action="se"></span>' + '</div>' + '</div>';
172172

173+
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); } }
174+
173175
/**
174176
* Check if the given value is a string.
175177
* @param {*} value - The value to check.
@@ -238,6 +240,21 @@ var objectKeys = Object.keys || function objectKeys(obj) {
238240
return keys;
239241
};
240242

243+
var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/i;
244+
245+
/**
246+
* Normalize decimal number.
247+
* Check out {@link http://0.30000000000000004.com/ }
248+
* @param {number} value - The value to normalize.
249+
* @param {number} [times=100000000000] - The times for normalizing.
250+
* @returns {number} Returns the normalized number.
251+
*/
252+
function normalizeDecimalNumber(value) {
253+
var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100000000000;
254+
255+
return REGEXP_DECIMALS.test(value) ? Math.round(value * times) / times : value;
256+
}
257+
241258
var location = global.location;
242259

243260
var REGEXP_ORIGINS = /^(https?:)\/\/([^:/?#]+):?(\d*)/i;
@@ -524,9 +541,10 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
524541
var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));
525542
var canvas = document.createElement('canvas');
526543
var context = canvas.getContext('2d');
544+
var params = [-imageNaturalWidth / 2, -imageNaturalHeight / 2, imageNaturalWidth, imageNaturalHeight];
527545

528-
canvas.width = width;
529-
canvas.height = height;
546+
canvas.width = normalizeDecimalNumber(width);
547+
canvas.height = normalizeDecimalNumber(height);
530548
context.fillStyle = fillColor;
531549
context.fillRect(0, 0, width, height);
532550
context.save();
@@ -535,7 +553,9 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
535553
context.scale(scaleX, scaleY);
536554
context.imageSmoothingEnabled = !!imageSmoothingEnabled;
537555
context.imageSmoothingQuality = imageSmoothingQuality;
538-
context.drawImage(image, Math.floor(-imageNaturalWidth / 2), Math.floor(-imageNaturalHeight / 2), Math.floor(imageNaturalWidth), Math.floor(imageNaturalHeight));
556+
context.drawImage.apply(context, [image].concat(_toConsumableArray($.map(params, function (param) {
557+
return Math.floor(normalizeDecimalNumber(param));
558+
}))));
539559
context.restore();
540560
return canvas;
541561
}
@@ -1978,6 +1998,8 @@ var change = {
19781998
}
19791999
};
19802000

2001+
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); } }
2002+
19812003
var methods = {
19822004
// Show the crop box manually
19832005
crop: function crop() {
@@ -2623,9 +2645,8 @@ var methods = {
26232645
var canvas = document.createElement('canvas');
26242646
var context = canvas.getContext('2d');
26252647

2626-
canvas.width = width;
2627-
canvas.height = height;
2628-
2648+
canvas.width = normalizeDecimalNumber(width);
2649+
canvas.height = normalizeDecimalNumber(height);
26292650
context.fillStyle = options.fillColor || 'transparent';
26302651
context.fillRect(0, 0, width, height);
26312652

@@ -2690,17 +2711,18 @@ var methods = {
26902711

26912712
// All the numerical parameters should be integer for `drawImage`
26922713
// https://github.com/fengyuanchen/cropper/issues/476
2693-
var params = [Math.floor(srcX), Math.floor(srcY), Math.floor(srcWidth), Math.floor(srcHeight)];
2714+
var params = [srcX, srcY, srcWidth, srcHeight];
26942715

26952716
// Avoid "IndexSizeError"
26962717
if (dstWidth > 0 && dstHeight > 0) {
26972718
var scale = width / initialWidth;
26982719

2699-
params.push(Math.floor(dstX * scale), Math.floor(dstY * scale), Math.floor(dstWidth * scale), Math.floor(dstHeight * scale));
2720+
params.push(dstX * scale, dstY * scale, dstWidth * scale, dstHeight * scale);
27002721
}
27012722

2702-
context.drawImage.apply(context, [source].concat(params));
2703-
2723+
context.drawImage.apply(context, [source].concat(_toConsumableArray$1($.map(params, function (param) {
2724+
return Math.floor(normalizeDecimalNumber(param));
2725+
}))));
27042726
return canvas;
27052727
},
27062728

dist/cropper.css

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

1111
.cropper-container {

dist/cropper.esm.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* Cropper v3.1.1
2+
* Cropper v3.1.2
33
* https://github.com/fengyuanchen/cropper
44
*
55
* Copyright (c) 2014-2017 Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2017-10-11T13:34:24.201Z
8+
* Date: 2017-10-18T13:23:24.651Z
99
*/
1010

1111
import $ from 'jquery';
@@ -166,6 +166,8 @@ var DEFAULTS = {
166166

167167
var TEMPLATE = '<div class="cropper-container">' + '<div class="cropper-wrap-box">' + '<div class="cropper-canvas"></div>' + '</div>' + '<div class="cropper-drag-box"></div>' + '<div class="cropper-crop-box">' + '<span class="cropper-view-box"></span>' + '<span class="cropper-dashed dashed-h"></span>' + '<span class="cropper-dashed dashed-v"></span>' + '<span class="cropper-center"></span>' + '<span class="cropper-face"></span>' + '<span class="cropper-line line-e" data-action="e"></span>' + '<span class="cropper-line line-n" data-action="n"></span>' + '<span class="cropper-line line-w" data-action="w"></span>' + '<span class="cropper-line line-s" data-action="s"></span>' + '<span class="cropper-point point-e" data-action="e"></span>' + '<span class="cropper-point point-n" data-action="n"></span>' + '<span class="cropper-point point-w" data-action="w"></span>' + '<span class="cropper-point point-s" data-action="s"></span>' + '<span class="cropper-point point-ne" data-action="ne"></span>' + '<span class="cropper-point point-nw" data-action="nw"></span>' + '<span class="cropper-point point-sw" data-action="sw"></span>' + '<span class="cropper-point point-se" data-action="se"></span>' + '</div>' + '</div>';
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 a string.
171173
* @param {*} value - The value to check.
@@ -234,6 +236,21 @@ var objectKeys = Object.keys || function objectKeys(obj) {
234236
return keys;
235237
};
236238

239+
var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/i;
240+
241+
/**
242+
* Normalize decimal number.
243+
* Check out {@link http://0.30000000000000004.com/ }
244+
* @param {number} value - The value to normalize.
245+
* @param {number} [times=100000000000] - The times for normalizing.
246+
* @returns {number} Returns the normalized number.
247+
*/
248+
function normalizeDecimalNumber(value) {
249+
var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100000000000;
250+
251+
return REGEXP_DECIMALS.test(value) ? Math.round(value * times) / times : value;
252+
}
253+
237254
var location = global.location;
238255

239256
var REGEXP_ORIGINS = /^(https?:)\/\/([^:/?#]+):?(\d*)/i;
@@ -520,9 +537,10 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
520537
var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));
521538
var canvas = document.createElement('canvas');
522539
var context = canvas.getContext('2d');
540+
var params = [-imageNaturalWidth / 2, -imageNaturalHeight / 2, imageNaturalWidth, imageNaturalHeight];
523541

524-
canvas.width = width;
525-
canvas.height = height;
542+
canvas.width = normalizeDecimalNumber(width);
543+
canvas.height = normalizeDecimalNumber(height);
526544
context.fillStyle = fillColor;
527545
context.fillRect(0, 0, width, height);
528546
context.save();
@@ -531,7 +549,9 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
531549
context.scale(scaleX, scaleY);
532550
context.imageSmoothingEnabled = !!imageSmoothingEnabled;
533551
context.imageSmoothingQuality = imageSmoothingQuality;
534-
context.drawImage(image, Math.floor(-imageNaturalWidth / 2), Math.floor(-imageNaturalHeight / 2), Math.floor(imageNaturalWidth), Math.floor(imageNaturalHeight));
552+
context.drawImage.apply(context, [image].concat(_toConsumableArray($.map(params, function (param) {
553+
return Math.floor(normalizeDecimalNumber(param));
554+
}))));
535555
context.restore();
536556
return canvas;
537557
}
@@ -1974,6 +1994,8 @@ var change = {
19741994
}
19751995
};
19761996

1997+
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); } }
1998+
19771999
var methods = {
19782000
// Show the crop box manually
19792001
crop: function crop() {
@@ -2619,9 +2641,8 @@ var methods = {
26192641
var canvas = document.createElement('canvas');
26202642
var context = canvas.getContext('2d');
26212643

2622-
canvas.width = width;
2623-
canvas.height = height;
2624-
2644+
canvas.width = normalizeDecimalNumber(width);
2645+
canvas.height = normalizeDecimalNumber(height);
26252646
context.fillStyle = options.fillColor || 'transparent';
26262647
context.fillRect(0, 0, width, height);
26272648

@@ -2686,17 +2707,18 @@ var methods = {
26862707

26872708
// All the numerical parameters should be integer for `drawImage`
26882709
// https://github.com/fengyuanchen/cropper/issues/476
2689-
var params = [Math.floor(srcX), Math.floor(srcY), Math.floor(srcWidth), Math.floor(srcHeight)];
2710+
var params = [srcX, srcY, srcWidth, srcHeight];
26902711

26912712
// Avoid "IndexSizeError"
26922713
if (dstWidth > 0 && dstHeight > 0) {
26932714
var scale = width / initialWidth;
26942715

2695-
params.push(Math.floor(dstX * scale), Math.floor(dstY * scale), Math.floor(dstWidth * scale), Math.floor(dstHeight * scale));
2716+
params.push(dstX * scale, dstY * scale, dstWidth * scale, dstHeight * scale);
26962717
}
26972718

2698-
context.drawImage.apply(context, [source].concat(params));
2699-
2719+
context.drawImage.apply(context, [source].concat(_toConsumableArray$1($.map(params, function (param) {
2720+
return Math.floor(normalizeDecimalNumber(param));
2721+
}))));
27002722
return canvas;
27012723
},
27022724

dist/cropper.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* Cropper v3.1.1
2+
* Cropper v3.1.2
33
* https://github.com/fengyuanchen/cropper
44
*
55
* Copyright (c) 2014-2017 Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2017-10-11T13:34:24.201Z
8+
* Date: 2017-10-18T13:23:24.651Z
99
*/
1010

1111
(function (global, factory) {
@@ -172,6 +172,8 @@ var DEFAULTS = {
172172

173173
var TEMPLATE = '<div class="cropper-container">' + '<div class="cropper-wrap-box">' + '<div class="cropper-canvas"></div>' + '</div>' + '<div class="cropper-drag-box"></div>' + '<div class="cropper-crop-box">' + '<span class="cropper-view-box"></span>' + '<span class="cropper-dashed dashed-h"></span>' + '<span class="cropper-dashed dashed-v"></span>' + '<span class="cropper-center"></span>' + '<span class="cropper-face"></span>' + '<span class="cropper-line line-e" data-action="e"></span>' + '<span class="cropper-line line-n" data-action="n"></span>' + '<span class="cropper-line line-w" data-action="w"></span>' + '<span class="cropper-line line-s" data-action="s"></span>' + '<span class="cropper-point point-e" data-action="e"></span>' + '<span class="cropper-point point-n" data-action="n"></span>' + '<span class="cropper-point point-w" data-action="w"></span>' + '<span class="cropper-point point-s" data-action="s"></span>' + '<span class="cropper-point point-ne" data-action="ne"></span>' + '<span class="cropper-point point-nw" data-action="nw"></span>' + '<span class="cropper-point point-sw" data-action="sw"></span>' + '<span class="cropper-point point-se" data-action="se"></span>' + '</div>' + '</div>';
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 a string.
177179
* @param {*} value - The value to check.
@@ -240,6 +242,21 @@ var objectKeys = Object.keys || function objectKeys(obj) {
240242
return keys;
241243
};
242244

245+
var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/i;
246+
247+
/**
248+
* Normalize decimal number.
249+
* Check out {@link http://0.30000000000000004.com/ }
250+
* @param {number} value - The value to normalize.
251+
* @param {number} [times=100000000000] - The times for normalizing.
252+
* @returns {number} Returns the normalized number.
253+
*/
254+
function normalizeDecimalNumber(value) {
255+
var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100000000000;
256+
257+
return REGEXP_DECIMALS.test(value) ? Math.round(value * times) / times : value;
258+
}
259+
243260
var location = global.location;
244261

245262
var REGEXP_ORIGINS = /^(https?:)\/\/([^:/?#]+):?(\d*)/i;
@@ -526,9 +543,10 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
526543
var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));
527544
var canvas = document.createElement('canvas');
528545
var context = canvas.getContext('2d');
546+
var params = [-imageNaturalWidth / 2, -imageNaturalHeight / 2, imageNaturalWidth, imageNaturalHeight];
529547

530-
canvas.width = width;
531-
canvas.height = height;
548+
canvas.width = normalizeDecimalNumber(width);
549+
canvas.height = normalizeDecimalNumber(height);
532550
context.fillStyle = fillColor;
533551
context.fillRect(0, 0, width, height);
534552
context.save();
@@ -537,7 +555,9 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
537555
context.scale(scaleX, scaleY);
538556
context.imageSmoothingEnabled = !!imageSmoothingEnabled;
539557
context.imageSmoothingQuality = imageSmoothingQuality;
540-
context.drawImage(image, Math.floor(-imageNaturalWidth / 2), Math.floor(-imageNaturalHeight / 2), Math.floor(imageNaturalWidth), Math.floor(imageNaturalHeight));
558+
context.drawImage.apply(context, [image].concat(_toConsumableArray($.map(params, function (param) {
559+
return Math.floor(normalizeDecimalNumber(param));
560+
}))));
541561
context.restore();
542562
return canvas;
543563
}
@@ -1980,6 +2000,8 @@ var change = {
19802000
}
19812001
};
19822002

2003+
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); } }
2004+
19832005
var methods = {
19842006
// Show the crop box manually
19852007
crop: function crop() {
@@ -2625,9 +2647,8 @@ var methods = {
26252647
var canvas = document.createElement('canvas');
26262648
var context = canvas.getContext('2d');
26272649

2628-
canvas.width = width;
2629-
canvas.height = height;
2630-
2650+
canvas.width = normalizeDecimalNumber(width);
2651+
canvas.height = normalizeDecimalNumber(height);
26312652
context.fillStyle = options.fillColor || 'transparent';
26322653
context.fillRect(0, 0, width, height);
26332654

@@ -2692,17 +2713,18 @@ var methods = {
26922713

26932714
// All the numerical parameters should be integer for `drawImage`
26942715
// https://github.com/fengyuanchen/cropper/issues/476
2695-
var params = [Math.floor(srcX), Math.floor(srcY), Math.floor(srcWidth), Math.floor(srcHeight)];
2716+
var params = [srcX, srcY, srcWidth, srcHeight];
26962717

26972718
// Avoid "IndexSizeError"
26982719
if (dstWidth > 0 && dstHeight > 0) {
26992720
var scale = width / initialWidth;
27002721

2701-
params.push(Math.floor(dstX * scale), Math.floor(dstY * scale), Math.floor(dstWidth * scale), Math.floor(dstHeight * scale));
2722+
params.push(dstX * scale, dstY * scale, dstWidth * scale, dstHeight * scale);
27022723
}
27032724

2704-
context.drawImage.apply(context, [source].concat(params));
2705-
2725+
context.drawImage.apply(context, [source].concat(_toConsumableArray$1($.map(params, function (param) {
2726+
return Math.floor(normalizeDecimalNumber(param));
2727+
}))));
27062728
return canvas;
27072729
},
27082730

0 commit comments

Comments
 (0)