UNPKG

advanced-cropper

Version:

The core of the advanced cropper libraries family

41 lines (36 loc) 1.63 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var utils = require('../service/utils.js'); var helpers = require('../service/helpers.js'); require('../types/index.js'); require('../state/setCoordinates.js'); var approximateSize = require('../service/approximateSize.js'); function defaultSize(state, settings) { var imageSize = state.imageSize, visibleArea = state.visibleArea; var sizeRestrictions = helpers.getSizeRestrictions(state, settings); var aspectRatio = helpers.getAspectRatio(state, settings); var area; if (visibleArea) { area = visibleArea; } else { var sizeRestrictions_1 = utils.positionToSizeRestrictions(helpers.getPositionRestrictions(state, settings)); area = { width: Math.max(sizeRestrictions_1.minWidth, Math.min(sizeRestrictions_1.maxWidth, imageSize.width)), height: Math.max(sizeRestrictions_1.minHeight, Math.min(sizeRestrictions_1.maxHeight, imageSize.height)), }; } var optimalRatio = Math.min(aspectRatio.maximum || Infinity, Math.max(aspectRatio.minimum || 0, utils.ratio(area))); var size = area.width < area.height ? { width: area.width * 0.8, height: (area.width * 0.8) / optimalRatio, } : { height: area.height * 0.8, width: area.height * 0.8 * optimalRatio, }; return approximateSize.approximateSize(tslib.__assign(tslib.__assign({}, size), { aspectRatio: aspectRatio, sizeRestrictions: sizeRestrictions })); } exports.defaultSize = defaultSize;