advanced-cropper
Version:
The core of the advanced cropper libraries family
46 lines (41 loc) • 2.75 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var tslib = require('tslib');
var index = require('../utils/index.js');
var utils = require('../service/utils.js');
var sizeRestrictions = require('../service/sizeRestrictions.js');
var helpers = require('../service/helpers.js');
var copyState = require('../state/copyState.js');
require('../types/index.js');
require('../state/setCoordinates.js');
var approximateSize = require('../service/approximateSize.js');
function rotateImageAlgorithm(state, settings, rotate) {
if (helpers.isInitializedState(state)) {
var result = copyState.copyState(state);
var angle = index.isNumber(rotate) ? rotate : rotate.angle;
var imageCenter = utils.rotatePoint(utils.getCenter(tslib.__assign({ left: 0, top: 0 }, helpers.getTransformedImageSize(state))), angle);
result.transforms.rotate += angle;
result.coordinates = tslib.__assign(tslib.__assign({}, approximateSize.approximateSize({
sizeRestrictions: helpers.getSizeRestrictions(result, settings),
aspectRatio: helpers.getAspectRatio(result, settings),
width: result.coordinates.width,
height: result.coordinates.height,
})), utils.rotatePoint(utils.getCenter(result.coordinates), angle));
var center = !index.isNumber(rotate) && rotate.center ? rotate.center : utils.getCenter(state.coordinates);
var shift = utils.diff(utils.getCenter(state.coordinates), utils.rotatePoint(utils.getCenter(state.coordinates), angle, center));
var imageSize = helpers.getTransformedImageSize(result);
result.coordinates.left -= imageCenter.left - imageSize.width / 2 + result.coordinates.width / 2 - shift.left;
result.coordinates.top -= imageCenter.top - imageSize.height / 2 + result.coordinates.height / 2 - shift.top;
// Check that visible area doesn't break the area restrictions:
result.visibleArea = utils.resizeToSizeRestrictions(result.visibleArea, sizeRestrictions.mergeSizeRestrictions(helpers.getAreaSizeRestrictions(result, settings), {
minWidth: result.coordinates.width,
minHeight: result.coordinates.height,
}));
result.coordinates = utils.moveToPositionRestrictions(result.coordinates, helpers.getPositionRestrictions(result, settings));
result.visibleArea = utils.applyMove(result.visibleArea, utils.diff(utils.getCenter(result.coordinates), utils.getCenter(state.coordinates)));
result.visibleArea = utils.moveToPositionRestrictions(result.visibleArea, helpers.getAreaPositionRestrictions(result, settings));
return result;
}
return state;
}
exports.rotateImageAlgorithm = rotateImageAlgorithm;