Skip to content

Commit

Permalink
build: release 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuanchen committed Oct 18, 2017
1 parent adffe3e commit fa03501
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 86 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.2 (Oct 18, 2017)

- Normalize related decimal numbers when crop an image with canvas.

## 1.1.1 (Oct 11, 2017)

- Supports to load in node environment (#237).
Expand Down
44 changes: 34 additions & 10 deletions dist/cropper.common.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*!
* Cropper.js v1.1.1
* Cropper.js v1.1.2
* https://github.com/fengyuanchen/cropperjs
*
* Copyright (c) 2015-2017 Chen Fengyuan
* Released under the MIT license
*
* Date: 2017-10-11T13:22:13.165Z
* Date: 2017-10-18T13:27:02.189Z
*/

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

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; };

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 not a number.
*/
Expand Down Expand Up @@ -309,6 +311,21 @@ function proxy(fn, context) {
};
}

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 REGEXP_SUFFIX = /^(width|height|left|top|marginLeft|marginTop)$/;

/**
Expand Down Expand Up @@ -927,9 +944,10 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
});
var width = Math.min(maxSizes.width, Math.max(minSizes.width, naturalWidth));
var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));
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();
Expand All @@ -938,7 +956,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(params.map(function (param) {
return Math.floor(normalizeDecimalNumber(param));
}))));
context.restore();
return canvas;
}
Expand Down Expand Up @@ -2388,6 +2408,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() {
Expand Down Expand Up @@ -3072,8 +3094,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);
Expand Down Expand Up @@ -3139,16 +3161,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(params.map(function (param) {
return Math.floor(normalizeDecimalNumber(param));
}))));

return canvas;
},
Expand Down
4 changes: 2 additions & 2 deletions dist/cropper.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*!
* Cropper.js v1.1.1
* Cropper.js v1.1.2
* https://github.com/fengyuanchen/cropperjs
*
* Copyright (c) 2015-2017 Chen Fengyuan
* Released under the MIT license
*
* Date: 2017-10-11T13:22:08.065Z
* Date: 2017-10-18T13:26:08.981Z
*/

.cropper-container {
Expand Down
44 changes: 34 additions & 10 deletions dist/cropper.esm.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*!
* Cropper.js v1.1.1
* Cropper.js v1.1.2
* https://github.com/fengyuanchen/cropperjs
*
* Copyright (c) 2015-2017 Chen Fengyuan
* Released under the MIT license
*
* Date: 2017-10-11T13:22:13.165Z
* Date: 2017-10-18T13:27:02.189Z
*/

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

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; };

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 not a number.
*/
Expand Down Expand Up @@ -307,6 +309,21 @@ function proxy(fn, context) {
};
}

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 REGEXP_SUFFIX = /^(width|height|left|top|marginLeft|marginTop)$/;

/**
Expand Down Expand Up @@ -925,9 +942,10 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
});
var width = Math.min(maxSizes.width, Math.max(minSizes.width, naturalWidth));
var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));
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();
Expand All @@ -936,7 +954,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(params.map(function (param) {
return Math.floor(normalizeDecimalNumber(param));
}))));
context.restore();
return canvas;
}
Expand Down Expand Up @@ -2386,6 +2406,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() {
Expand Down Expand Up @@ -3070,8 +3092,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);
Expand Down Expand Up @@ -3137,16 +3159,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(params.map(function (param) {
return Math.floor(normalizeDecimalNumber(param));
}))));

return canvas;
},
Expand Down
44 changes: 34 additions & 10 deletions dist/cropper.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*!
* Cropper.js v1.1.1
* Cropper.js v1.1.2
* https://github.com/fengyuanchen/cropperjs
*
* Copyright (c) 2015-2017 Chen Fengyuan
* Released under the MIT license
*
* Date: 2017-10-11T13:22:13.165Z
* Date: 2017-10-18T13:27:02.189Z
*/

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

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; };

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 not a number.
*/
Expand Down Expand Up @@ -313,6 +315,21 @@ function proxy(fn, context) {
};
}

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 REGEXP_SUFFIX = /^(width|height|left|top|marginLeft|marginTop)$/;

/**
Expand Down Expand Up @@ -931,9 +948,10 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
});
var width = Math.min(maxSizes.width, Math.max(minSizes.width, naturalWidth));
var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));
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();
Expand All @@ -942,7 +960,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(params.map(function (param) {
return Math.floor(normalizeDecimalNumber(param));
}))));
context.restore();
return canvas;
}
Expand Down Expand Up @@ -2392,6 +2412,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() {
Expand Down Expand Up @@ -3076,8 +3098,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);
Expand Down Expand Up @@ -3143,16 +3165,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(params.map(function (param) {
return Math.floor(normalizeDecimalNumber(param));
}))));

return canvas;
},
Expand Down
4 changes: 2 additions & 2 deletions dist/cropper.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/cropper.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/css/cropper.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*!
* Cropper.js v1.1.1
* Cropper.js v1.1.2
* https://github.com/fengyuanchen/cropperjs
*
* Copyright (c) 2015-2017 Chen Fengyuan
* Released under the MIT license
*
* Date: 2017-10-11T13:22:08.065Z
* Date: 2017-10-18T13:26:08.981Z
*/

.cropper-container {
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<div class="container">
<div class="row">
<div class="col-md">
<h1>Cropper.js <small class="h6">v1.1.1</small></h1>
<h1>Cropper.js <small class="h6">v1.1.2</small></h1>
<p class="lead">JavaScript image cropper.</p>
</div>
<div class="col-md">
Expand Down
Loading

0 comments on commit fa03501

Please sign in to comment.