UNPKG

advanced-cropper

Version:

The core of the advanced cropper libraries family

38 lines (33 loc) 1.81 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var utils = require('../../service/utils.js'); require('../../types/index.js'); require('../../state/setCoordinates.js'); var types = require('./types.js'); var boundingBox = require('./boundingBox.js'); function fitToImage(coordinates, image, boundingBox$1) { if (boundingBox$1 === void 0) { boundingBox$1 = types.BoundingBoxType.Rectangle; } var imageCenter = utils.getCenter(tslib.__assign({ left: 0, top: 0 }, utils.rotateSize(image, -image.angle))); var center = utils.rotatePoint(utils.getCenter(coordinates), -image.angle, imageCenter); var boundingBoxSize = boundingBox.getBoundingBox(coordinates, image.angle, boundingBox$1); var boundingBoxCoordinates = tslib.__assign(tslib.__assign({}, boundingBoxSize), { left: center.left - boundingBoxSize.width / 2, top: center.top - boundingBoxSize.height / 2 }); var vector = utils.fitToPositionRestrictions(boundingBoxCoordinates, { left: imageCenter.left - image.width / 2, top: imageCenter.top - image.height / 2, right: imageCenter.left + image.width / 2, bottom: imageCenter.top + image.height / 2, }); var leftVector = utils.rotatePoint({ left: vector.left, top: 0 }, image.angle); var topVector = utils.rotatePoint({ left: 0, top: vector.top }, image.angle); return { left: leftVector.left + topVector.left, top: leftVector.top + topVector.top, }; } function moveToImage(coordinates, image, boundingBox) { if (boundingBox === void 0) { boundingBox = types.BoundingBoxType.Rectangle; } return utils.applyMove(coordinates, fitToImage(coordinates, image, boundingBox)); } exports.fitToImage = fitToImage; exports.moveToImage = moveToImage;