UNPKG

advanced-cropper

Version:

The core of the advanced cropper libraries family

62 lines (57 loc) 2.11 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 defaultAreaPositionRestrictions(state, settings) { var visibleArea = state.visibleArea, boundary = state.boundary; var imageRestriction = settings.imageRestriction; var imageSize = helpers.getTransformedImageSize(state); var restrictions = {}; if (imageRestriction === index.ImageRestriction.fillArea) { restrictions = { left: 0, top: 0, right: imageSize.width, bottom: imageSize.height, }; } else if (imageRestriction === index.ImageRestriction.fitArea) { if (utils.ratio(boundary) > utils.ratio(imageSize)) { restrictions = { top: 0, bottom: imageSize.height, }; if (visibleArea) { if (visibleArea.width > imageSize.width) { restrictions.left = -(visibleArea.width - imageSize.width) / 2; restrictions.right = imageSize.width - restrictions.left; } else { restrictions.left = 0; restrictions.right = imageSize.width; } } } else { restrictions = { left: 0, right: imageSize.width, }; if (visibleArea) { if (visibleArea.height > imageSize.height) { restrictions.top = -(visibleArea.height - imageSize.height) / 2; restrictions.bottom = imageSize.height - restrictions.top; } else { restrictions.top = 0; restrictions.bottom = imageSize.height; } } } } return restrictions; } exports.defaultAreaPositionRestrictions = defaultAreaPositionRestrictions;