MCPcopy
hub / github.com/fengyuanchen/cropperjs / $change

Method $change

packages/element-selection/src/index.ts:899–962  ·  view source on GitHub ↗

* 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,
  )

Source from the content-addressed store, hash-verified

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;

Callers 10

$initSelectionMethod · 0.95
$centerMethod · 0.95
$moveToMethod · 0.95
$resizeMethod · 0.95
$zoomMethod · 0.95
$resetMethod · 0.95
$clearMethod · 0.95
$handleActionMethod · 0.45
index.spec.tsFile · 0.45

Calls 5

$renderMethod · 0.95
isNumberFunction · 0.90
isPositiveNumberFunction · 0.90
getAdjustedSizesFunction · 0.90
$emitMethod · 0.80

Tested by

no test coverage detected