UNPKG

advanced-cropper

Version:

The core of the advanced cropper libraries family

37 lines (32 loc) 1.66 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); require('tslib'); var utils = require('../../service/utils.js'); var helpers = require('../../service/helpers.js'); var copyState = require('../../state/copyState.js'); require('../../types/index.js'); require('../../state/setCoordinates.js'); var fitCoordinates = require('../../service/fitCoordinates.js'); function preventZoom(state, settings, action) { if (action && action.immediately && helpers.isInitializedState(state)) { var result = copyState.copyState(state); var imageSize = helpers.getTransformedImageSize(state); var restrictionsSize = helpers.getAreaSizeRestrictions(state, settings); var visibleAreaSize = { width: Math.max(Math.min(imageSize.width, restrictionsSize.maxWidth), restrictionsSize.minWidth), height: Math.max(Math.min(imageSize.height, restrictionsSize.maxHeight), restrictionsSize.minHeight), }; if (utils.ratio(result.boundary) > utils.ratio(imageSize)) { result.visibleArea.height = visibleAreaSize.height; result.visibleArea.width = visibleAreaSize.height * utils.ratio(result.boundary); } else { result.visibleArea.width = visibleAreaSize.width; result.visibleArea.height = visibleAreaSize.width / utils.ratio(result.boundary); } result.visibleArea = utils.moveToPositionRestrictions(result.visibleArea, helpers.getAreaPositionRestrictions(result, settings)); return fitCoordinates.fitCoordinates(result, settings); } return state; } exports.preventZoom = preventZoom;