UNPKG

advanced-cropper

Version:

The core of the advanced cropper libraries family

39 lines (34 loc) 1.31 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); require('tslib'); var utils = require('../service/utils.js'); var helpers = require('../service/helpers.js'); var index = require('../types/index.js'); require('../state/setCoordinates.js'); function defaultAreaSizeRestrictions(state, settings) { var boundary = state.boundary; var imageRestriction = settings.imageRestriction; var imageSize = helpers.getTransformedImageSize(state); var restrictions = { minWidth: 0, minHeight: 0, maxWidth: Infinity, maxHeight: Infinity, }; if (imageRestriction === index.ImageRestriction.fillArea) { restrictions.maxWidth = imageSize.width; restrictions.maxHeight = imageSize.height; } else if (imageRestriction === index.ImageRestriction.fitArea) { if (utils.ratio(boundary) > utils.ratio(imageSize)) { restrictions.maxHeight = imageSize.height; restrictions.maxWidth = imageSize.height * utils.ratio(boundary); } else { restrictions.maxWidth = imageSize.width; restrictions.maxHeight = imageSize.width / utils.ratio(boundary); } } return restrictions; } exports.defaultAreaSizeRestrictions = defaultAreaSizeRestrictions;