Liferay.Loader.define("frontend-js-web@4.0.60/liferay/util/get_crop_region.es", ['module', 'exports', 'require', 'frontend-js-metal-web$metal'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = getCropRegion;

    var _metal = require("frontend-js-metal-web$metal");

    /**
     * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
     * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
     */

    /**
     * Returns dimensions and coordinates representing a cropped region
     * @param {!Element} imagePreview Image that will be cropped
     * @param {!Object} region Object representing the coordinates which should be
     * cropped
     * @return {!Object} Object representing dimensions and coordinates of the
     * cropped image
     * @review
     */
    function getCropRegion(imagePreview, region) {
      if (!(0, _metal.isObject)(imagePreview) || (0, _metal.isObject)(imagePreview) && imagePreview.tagName !== 'IMG') {
        throw new TypeError('Parameter imagePreview must be an image');
      }

      if (!(0, _metal.isObject)(region)) {
        throw new TypeError('Parameter region must be an object');
      }

      var scaleX = imagePreview.naturalWidth / imagePreview.offsetWidth;
      var scaleY = imagePreview.naturalHeight / imagePreview.offsetHeight;
      var height = region.height ? region.height * scaleY : imagePreview.naturalHeight;
      var width = region.width ? region.width * scaleX : imagePreview.naturalWidth;
      var x = region.x ? Math.max(region.x * scaleX, 0) : 0;
      var y = region.y ? Math.max(region.y * scaleY, 0) : 0;
      return {
        height: height,
        width: width,
        x: x,
        y: y
      };
    }
    //# sourceMappingURL=get_crop_region.es.js.map
  }
});
//# sourceMappingURL=get_crop_region.es.js.map