diff --git a/docs/js/cropper.js b/docs/js/cropper.js
index 86e7c826..0669958b 100644
--- a/docs/js/cropper.js
+++ b/docs/js/cropper.js
@@ -1,11 +1,11 @@
/*!
- * Cropper v3.1.1
+ * Cropper v3.1.2
* https://github.com/fengyuanchen/cropper
*
* Copyright (c) 2014-2017 Chen Fengyuan
* Released under the MIT license
*
- * Date: 2017-10-11T13:34:24.201Z
+ * Date: 2017-10-18T13:23:24.651Z
*/
(function (global, factory) {
@@ -172,6 +172,8 @@ var DEFAULTS = {
var TEMPLATE = '
' + '
' + '
' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
';
+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); } }
+
/**
* Check if the given value is a string.
* @param {*} value - The value to check.
@@ -240,6 +242,21 @@ var objectKeys = Object.keys || function objectKeys(obj) {
return keys;
};
+var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/i;
+
+/**
+ * Normalize decimal number.
+ * Check out {@link http://0.30000000000000004.com/ }
+ * @param {number} value - The value to normalize.
+ * @param {number} [times=100000000000] - The times for normalizing.
+ * @returns {number} Returns the normalized number.
+ */
+function normalizeDecimalNumber(value) {
+ var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100000000000;
+
+ return REGEXP_DECIMALS.test(value) ? Math.round(value * times) / times : value;
+}
+
var location = global.location;
var REGEXP_ORIGINS = /^(https?:)\/\/([^:/?#]+):?(\d*)/i;
@@ -526,9 +543,10 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
+ var params = [-imageNaturalWidth / 2, -imageNaturalHeight / 2, imageNaturalWidth, imageNaturalHeight];
- canvas.width = width;
- canvas.height = height;
+ canvas.width = normalizeDecimalNumber(width);
+ canvas.height = normalizeDecimalNumber(height);
context.fillStyle = fillColor;
context.fillRect(0, 0, width, height);
context.save();
@@ -537,7 +555,9 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
context.scale(scaleX, scaleY);
context.imageSmoothingEnabled = !!imageSmoothingEnabled;
context.imageSmoothingQuality = imageSmoothingQuality;
- context.drawImage(image, Math.floor(-imageNaturalWidth / 2), Math.floor(-imageNaturalHeight / 2), Math.floor(imageNaturalWidth), Math.floor(imageNaturalHeight));
+ context.drawImage.apply(context, [image].concat(_toConsumableArray($.map(params, function (param) {
+ return Math.floor(normalizeDecimalNumber(param));
+ }))));
context.restore();
return canvas;
}
@@ -1980,6 +2000,8 @@ var change = {
}
};
+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); } }
+
var methods = {
// Show the crop box manually
crop: function crop() {
@@ -2625,9 +2647,8 @@ var methods = {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
- canvas.width = width;
- canvas.height = height;
-
+ canvas.width = normalizeDecimalNumber(width);
+ canvas.height = normalizeDecimalNumber(height);
context.fillStyle = options.fillColor || 'transparent';
context.fillRect(0, 0, width, height);
@@ -2692,17 +2713,18 @@ var methods = {
// All the numerical parameters should be integer for `drawImage`
// https://github.com/fengyuanchen/cropper/issues/476
- var params = [Math.floor(srcX), Math.floor(srcY), Math.floor(srcWidth), Math.floor(srcHeight)];
+ var params = [srcX, srcY, srcWidth, srcHeight];
// Avoid "IndexSizeError"
if (dstWidth > 0 && dstHeight > 0) {
var scale = width / initialWidth;
- params.push(Math.floor(dstX * scale), Math.floor(dstY * scale), Math.floor(dstWidth * scale), Math.floor(dstHeight * scale));
+ params.push(dstX * scale, dstY * scale, dstWidth * scale, dstHeight * scale);
}
- context.drawImage.apply(context, [source].concat(params));
-
+ context.drawImage.apply(context, [source].concat(_toConsumableArray$1($.map(params, function (param) {
+ return Math.floor(normalizeDecimalNumber(param));
+ }))));
return canvas;
},
diff --git a/package-lock.json b/package-lock.json
index 933e8aeb..674c9642 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "cropper",
- "version": "3.1.1",
+ "version": "3.1.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -731,9 +731,9 @@
}
},
"babel-preset-env": {
- "version": "1.6.0",
- "resolved": "https://registry.npmjs.org/babel-preset-env/-/babel-preset-env-1.6.0.tgz",
- "integrity": "sha512-OVgtQRuOZKckrILgMA5rvctvFZPv72Gua9Rt006AiPoB0DJKGN07UmaQA+qRrYgK71MVct8fFhT0EyNWYorVew==",
+ "version": "1.6.1",
+ "resolved": "https://registry.npmjs.org/babel-preset-env/-/babel-preset-env-1.6.1.tgz",
+ "integrity": "sha512-W6VIyA6Ch9ePMI7VptNn2wBM6dbG0eSz25HEiL40nQXCsXGTGZSTZu1Iap+cj3Q0S5a7T9+529l/5Bkvd+afNA==",
"dev": true,
"requires": {
"babel-plugin-check-es2015-constants": "6.22.0",
@@ -1893,14 +1893,14 @@
"dev": true
},
"eslint": {
- "version": "4.8.0",
- "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.8.0.tgz",
- "integrity": "sha1-Ip7w41Tg5h2DfHqA/fuoJeGZgV4=",
+ "version": "4.9.0",
+ "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.9.0.tgz",
+ "integrity": "sha1-doedJ0BoJhsZH+Dy9Wx0wvQgjos=",
"dev": true,
"requires": {
"ajv": "5.2.3",
"babel-code-frame": "6.26.0",
- "chalk": "2.1.0",
+ "chalk": "2.2.0",
"concat-stream": "1.6.0",
"cross-spawn": "5.1.0",
"debug": "3.1.0",
@@ -1953,14 +1953,14 @@
}
},
"chalk": {
- "version": "2.1.0",
- "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.1.0.tgz",
- "integrity": "sha512-LUHGS/dge4ujbXMJrnihYMcL4AoOweGnw9Tp3kQuqy1Kx5c1qKjqvMJZ6nVJPMWJtKCTN72ZogH3oeSO9g9rXQ==",
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.2.0.tgz",
+ "integrity": "sha512-0BMM/2hG3ZaoPfR6F+h/oWpZtsh3b/s62TjSM6MGCJWEbJDN1acqCXvyhhZsDSVFklpebUoQ5O1kKC7lOzrn9g==",
"dev": true,
"requires": {
"ansi-styles": "3.2.0",
"escape-string-regexp": "1.0.5",
- "supports-color": "4.4.0"
+ "supports-color": "4.5.0"
}
},
"debug": {
@@ -2018,9 +2018,9 @@
}
},
"supports-color": {
- "version": "4.4.0",
- "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz",
- "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==",
+ "version": "4.5.0",
+ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz",
+ "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=",
"dev": true,
"requires": {
"has-flag": "2.0.0"
@@ -2029,9 +2029,9 @@
}
},
"eslint-config-airbnb-base": {
- "version": "12.0.2",
- "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-12.0.2.tgz",
- "integrity": "sha512-rQqOvAzrMC3BBCH6Dd/1RenDi+RW4vdgnh8xcPf6sgd324ad6aX7hSZ52L1SfDGe2VsZR2yB5uPvDfXYvxHZmA==",
+ "version": "12.1.0",
+ "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-12.1.0.tgz",
+ "integrity": "sha512-/vjm0Px5ZCpmJqnjIzcFb9TKZrKWz0gnuG/7Gfkt0Db1ELJR51xkZth+t14rYdqWgX836XbuxtArbIHlVhbLBA==",
"dev": true,
"requires": {
"eslint-restricted-globals": "0.1.1"
@@ -2780,7 +2780,7 @@
"dev": true,
"requires": {
"ansi-escapes": "3.0.0",
- "chalk": "2.1.0",
+ "chalk": "2.2.0",
"cli-cursor": "2.1.0",
"cli-width": "2.2.0",
"external-editor": "2.0.5",
@@ -2811,14 +2811,14 @@
}
},
"chalk": {
- "version": "2.1.0",
- "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.1.0.tgz",
- "integrity": "sha512-LUHGS/dge4ujbXMJrnihYMcL4AoOweGnw9Tp3kQuqy1Kx5c1qKjqvMJZ6nVJPMWJtKCTN72ZogH3oeSO9g9rXQ==",
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.2.0.tgz",
+ "integrity": "sha512-0BMM/2hG3ZaoPfR6F+h/oWpZtsh3b/s62TjSM6MGCJWEbJDN1acqCXvyhhZsDSVFklpebUoQ5O1kKC7lOzrn9g==",
"dev": true,
"requires": {
"ansi-styles": "3.2.0",
"escape-string-regexp": "1.0.5",
- "supports-color": "4.4.0"
+ "supports-color": "4.5.0"
}
},
"has-flag": {
@@ -2837,9 +2837,9 @@
}
},
"supports-color": {
- "version": "4.4.0",
- "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz",
- "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==",
+ "version": "4.5.0",
+ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz",
+ "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=",
"dev": true,
"requires": {
"has-flag": "2.0.0"
@@ -7330,9 +7330,9 @@
}
},
"rollup-plugin-commonjs": {
- "version": "8.2.1",
- "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-8.2.1.tgz",
- "integrity": "sha512-ZTwAetmKimCsuWost/+n4FaOpMoczBRTx+kuQaZCIKXTx/R1wNBezuX5NS0vnPKM3hBoErdpAqmNyVSCi5XKbg==",
+ "version": "8.2.3",
+ "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-8.2.3.tgz",
+ "integrity": "sha512-WFkITnsa3sNsWtBfBMnjXVUN/6tWKVOUTq/2VhQhDjytPhpZ/y+oTa2tyBdu9caC9Rp29ZtnH+qo4zYO7n8/Ww==",
"dev": true,
"requires": {
"acorn": "5.1.2",
@@ -8350,13 +8350,21 @@
"dev": true
},
"uglify-js": {
- "version": "3.1.3",
- "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.1.3.tgz",
- "integrity": "sha512-5ZUOgufCHjN2mBBLfz63UtWTP6va2sSzBpNCM+/iqI6RnPzEhANmB0EKiKBYdQbc3v7KeomXJ2DJx0Xq9gvUvA==",
+ "version": "3.1.4",
+ "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.1.4.tgz",
+ "integrity": "sha512-DcbkPg11Lw2lAWpwCmQDX+qoR4JiII6ypsQmF6tscZtlxGPFAmSRUGuMoVT3/0EHqypVik/TpkH4ITiMJeQqQA==",
"dev": true,
"requires": {
"commander": "2.11.0",
- "source-map": "0.5.7"
+ "source-map": "0.6.1"
+ },
+ "dependencies": {
+ "source-map": {
+ "version": "0.6.1",
+ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
+ "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
+ "dev": true
+ }
}
},
"uniq": {
diff --git a/package.json b/package.json
index f9cc5f55..a503cedc 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "cropper",
"description": "A simple jQuery image cropping plugin.",
- "version": "3.1.1",
+ "version": "3.1.2",
"main": "dist/cropper.common.js",
"module": "dist/cropper.esm.js",
"browser": "dist/cropper.js",
@@ -52,11 +52,11 @@
},
"devDependencies": {
"babel-core": "^6.26.0",
- "babel-preset-env": "^1.6.0",
+ "babel-preset-env": "^1.6.1",
"cpy-cli": "^1.0.1",
"cssnano": "^3.10.0",
- "eslint": "^4.8.0",
- "eslint-config-airbnb-base": "^12.0.2",
+ "eslint": "^4.9.0",
+ "eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.7.0",
"jquery": "^3.2.1",
"node-qunit-phantomjs": "^1.5.0",
@@ -67,11 +67,11 @@
"postcss-url": "^7.1.2",
"rollup": "^0.50.0",
"rollup-plugin-babel": "^3.0.2",
- "rollup-plugin-commonjs": "^8.2.1",
+ "rollup-plugin-commonjs": "^8.2.3",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-watch": "^4.3.1",
"stylefmt": "^6.0.0",
- "uglify-js": "^3.1.3"
+ "uglify-js": "^3.1.4"
},
"peerDependencies": {
"jquery": ">= 1.9.1"