* Changes the position and/or size of the selection. * @param {number} x The new position in the horizontal direction. * @param {number} y The new position in the vertical direction. * @param {number} [width] The new width. * @param {number} [height] The new height. * @param {number}
(
x: number,
y: number,
width: number = this.width,
height: number = this.height,
aspectRatio: number = this.aspectRatio,
_force = false,
)
| 897 | * @returns {CropperSelection} Returns `this` for chaining. |
| 898 | */ |
| 899 | $change( |
| 900 | x: number, |
| 901 | y: number, |
| 902 | width: number = this.width, |
| 903 | height: number = this.height, |
| 904 | aspectRatio: number = this.aspectRatio, |
| 905 | _force = false, |
| 906 | ): this { |
| 907 | if ( |
| 908 | this.$changing |
| 909 | || !isNumber(x) |
| 910 | || !isNumber(y) |
| 911 | || !isNumber(width) |
| 912 | || !isNumber(height) |
| 913 | || width < 0 |
| 914 | || height < 0 |
| 915 | ) { |
| 916 | return this; |
| 917 | } |
| 918 | |
| 919 | if (isPositiveNumber(aspectRatio)) { |
| 920 | ({ width, height } = getAdjustedSizes({ aspectRatio, width, height }, 'cover')); |
| 921 | } |
| 922 | |
| 923 | if (!this.precise) { |
| 924 | x = Math.round(x); |
| 925 | y = Math.round(y); |
| 926 | width = Math.round(width); |
| 927 | height = Math.round(height); |
| 928 | } |
| 929 | |
| 930 | if ( |
| 931 | x === this.x |
| 932 | && y === this.y |
| 933 | && width === this.width |
| 934 | && height === this.height |
| 935 | && Object.is(aspectRatio, this.aspectRatio) |
| 936 | && !_force |
| 937 | ) { |
| 938 | return this; |
| 939 | } |
| 940 | |
| 941 | if (this.hidden) { |
| 942 | this.hidden = false; |
| 943 | } |
| 944 | |
| 945 | if (this.$emit(EVENT_CHANGE, { |
| 946 | x, |
| 947 | y, |
| 948 | width, |
| 949 | height, |
| 950 | }) === false) { |
| 951 | return this; |
| 952 | } |
| 953 | |
| 954 | this.$changing = true; |
| 955 | this.x = x; |
| 956 | this.y = y; |
no test coverage detected