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

Commit

Permalink
build: release 3.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuanchen committed Feb 25, 2018
1 parent 5ab7c59 commit ed053b9
Show file tree
Hide file tree
Showing 13 changed files with 3,406 additions and 1,126 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.1.5 (Feb 25, 2018)

- Fixed a bug of `getCroppedCanvas` method when provide `maxWidth` or `maxHeight` options (#953).

## 3.1.4 (Jan 13, 2018)

- Fixed a bug of rotation (#938).
Expand All @@ -21,11 +25,11 @@

- Added 4 new options to `getCroppedCanvas` method: `minWidth`, `minHeight`, `maxWidth` and `maxHeight`.
- Enhanced image scaling: the `scaleX` and `scaleY` values should only be `1` or `-1` before, but now they can be any numbers.
- Improved crop box resizing behaviour in the northeast, northwest, southeast and southwest directions.
- Improved crop box resizing behavior in the northeast, northwest, southeast and southwest directions.

## 3.0.0 (Sep 3, 2017)

- Improved crop box resizing behaviour in the east, west, south and north directions.
- Improved crop box resizing behavior in the east, west, south and north directions.

## 3.0.0-rc.3 (Jul 7, 2017)

Expand Down Expand Up @@ -89,7 +93,7 @@

## 2.3.1 (May 28, 2016)

- Improved the rotate and scale transform behaviour (#633, idea by afeibus).
- Improved the rotate and scale transform behavior (#633, idea by afeibus).
- Improved the `getCroppedCanvas` method to return the whole canvas if it is not cropped (#666, PR by @vinnymac).
- Check cross origin setting when load image by XMLHTTPRequest (#669)

Expand Down
112 changes: 42 additions & 70 deletions dist/cropper.common.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*!
* Cropper v3.1.4
* Cropper v3.1.5
* https://github.com/fengyuanchen/cropper
*
* Copyright (c) 2014-2018 Chen Fengyuan
* Released under the MIT license
*
* Date: 2018-01-13T09:37:52.890Z
* Date: 2018-02-25T09:07:38.300Z
*/

'use strict';
Expand Down Expand Up @@ -193,46 +193,6 @@ var createClass = function () {
};
}();









































var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
Expand Down Expand Up @@ -508,19 +468,24 @@ var isFinite = Number.isFinite || WINDOW.isFinite;
/**
* Get the max sizes in a rectangle under the given aspect ratio.
* @param {Object} data - The original sizes.
* @param {string} [type='contain'] - The adjust type.
* @returns {Object} The result sizes.
*/
function getContainSizes(_ref4) {
function getAdjustedSizes(_ref4) // or 'cover'
{
var aspectRatio = _ref4.aspectRatio,
height = _ref4.height,
width = _ref4.width;
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'contain';

var isValidNumber = function isValidNumber(value) {
return isFinite(value) && value > 0;
};

if (isValidNumber(width) && isValidNumber(height)) {
if (height * aspectRatio > width) {
var adjustedWidth = height * aspectRatio;

if (type === 'contain' && adjustedWidth > width || type === 'cover' && adjustedWidth < width) {
height = width / aspectRatio;
} else {
width = height * aspectRatio;
Expand Down Expand Up @@ -580,9 +545,7 @@ function getRotatedSizes(_ref5) {
* @returns {HTMLCanvasElement} The result canvas.
*/
function getSourceCanvas(image, _ref6, _ref7, _ref8) {
var imageNaturalWidth = _ref6.naturalWidth,
imageNaturalHeight = _ref6.naturalHeight,
_ref6$rotate = _ref6.rotate,
var _ref6$rotate = _ref6.rotate,
rotate = _ref6$rotate === undefined ? 0 : _ref6$rotate,
_ref6$scaleX = _ref6.scaleX,
scaleX = _ref6$scaleX === undefined ? 1 : _ref6$scaleX,
Expand All @@ -606,21 +569,21 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
_ref8$minHeight = _ref8.minHeight,
minHeight = _ref8$minHeight === undefined ? 0 : _ref8$minHeight;

var maxSizes = getContainSizes({
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var maxSizes = getAdjustedSizes({
aspectRatio: aspectRatio,
width: maxWidth,
height: maxHeight
});
var minSizes = getContainSizes({
var minSizes = getAdjustedSizes({
aspectRatio: aspectRatio,
width: minWidth,
height: minHeight
});
}, 'cover');
var width = Math.min(maxSizes.width, Math.max(minSizes.width, naturalWidth));
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];
var params = [-width / 2, -height / 2, width, height];

canvas.width = normalizeDecimalNumber(width);
canvas.height = normalizeDecimalNumber(height);
Expand All @@ -630,7 +593,7 @@ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
context.translate(width / 2, height / 2);
context.rotate(rotate * Math.PI / 180);
context.scale(scaleX, scaleY);
context.imageSmoothingEnabled = !!imageSmoothingEnabled;
context.imageSmoothingEnabled = imageSmoothingEnabled;
context.imageSmoothingQuality = imageSmoothingQuality;
context.drawImage.apply(context, [image].concat(toConsumableArray($.map(params, function (param) {
return Math.floor(normalizeDecimalNumber(param));
Expand Down Expand Up @@ -948,14 +911,14 @@ var render = {
}
}

var _getContainSizes = getContainSizes({
var _getAdjustedSizes = getAdjustedSizes({
aspectRatio: aspectRatio,
width: minCanvasWidth,
height: minCanvasHeight
});
}, 'cover');

minCanvasWidth = _getContainSizes.width;
minCanvasHeight = _getContainSizes.height;
minCanvasWidth = _getAdjustedSizes.width;
minCanvasHeight = _getAdjustedSizes.height;


canvas.minWidth = minCanvasWidth;
Expand Down Expand Up @@ -2691,30 +2654,39 @@ var methods = {
}

var _getData = this.getData(),
x = _getData.x,
y = _getData.y,
initialX = _getData.x,
initialY = _getData.y,
initialWidth = _getData.width,
initialHeight = _getData.height;

var ratio = source.width / Math.floor(canvasData.naturalWidth);

if (ratio !== 1) {
initialX *= ratio;
initialY *= ratio;
initialWidth *= ratio;
initialHeight *= ratio;
}

var aspectRatio = initialWidth / initialHeight;
var maxSizes = getContainSizes({
var maxSizes = getAdjustedSizes({
aspectRatio: aspectRatio,
width: options.maxWidth || Infinity,
height: options.maxHeight || Infinity
});
var minSizes = getContainSizes({
var minSizes = getAdjustedSizes({
aspectRatio: aspectRatio,
width: options.minWidth || 0,
height: options.minHeight || 0
});
}, 'cover');

var _getContainSizes = getContainSizes({
var _getAdjustedSizes = getAdjustedSizes({
aspectRatio: aspectRatio,
width: options.width || initialWidth,
height: options.height || initialHeight
width: options.width || (ratio !== 1 ? source.width : initialWidth),
height: options.height || (ratio !== 1 ? source.height : initialHeight)
}),
width = _getContainSizes.width,
height = _getContainSizes.height;
width = _getAdjustedSizes.width,
height = _getAdjustedSizes.height;

width = Math.min(maxSizes.width, Math.max(minSizes.width, width));
height = Math.min(maxSizes.height, Math.max(minSizes.height, height));
Expand Down Expand Up @@ -2743,8 +2715,8 @@ var methods = {
var sourceHeight = source.height;

// Source canvas parameters
var srcX = x;
var srcY = y;
var srcX = initialX;
var srcY = initialY;
var srcWidth = void 0;
var srcHeight = void 0;

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 v3.1.4
* Cropper v3.1.5
* https://github.com/fengyuanchen/cropper
*
* Copyright (c) 2014-2018 Chen Fengyuan
* Released under the MIT license
*
* Date: 2018-01-13T09:37:21.486Z
* Date: 2018-02-25T09:06:55.204Z
*/

.cropper-container {
Expand Down
Loading

0 comments on commit ed053b9

Please sign in to comment.