Skip to content

Commit 681c719

Browse files
committed
Refactor the code
1 parent cd8b561 commit 681c719

File tree

10 files changed

+33
-73
lines changed

10 files changed

+33
-73
lines changed

example/docs/.vuepress/components/getting-result-example.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default {
6161
<img
6262
:src="this.image"
6363
alt=""
64-
>>
64+
>
6565
</div>
6666
</div>
6767
</div>

example/docs/.vuepress/components/getting-result-second-example.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default {
6464
<img
6565
:src="this.image"
6666
alt=""
67-
>>
67+
>
6868
</div>
6969
</div>
7070

src/components/helpers/PreviewImage.vue

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ export default {
6060
},
6161
imageStyle() {
6262
const coefficient = this.previewHeight / this.height;
63-
const height = this.imageSize.height * coefficient;
64-
const width = this.imageSize.width * coefficient;
6563
return {
66-
width: `${width}px`,
67-
height: `${height}px`,
68-
left: `${-this.left*coefficient}px`,
69-
top: `${-this.top*coefficient}px`,
64+
width: `${this.imageSize.width * coefficient}px`,
65+
height: `${this.imageSize.height * coefficient}px`,
66+
left: `${-this.left * coefficient}px`,
67+
top: `${-this.top * coefficient}px`,
7068
};
7169
},
7270
},
@@ -95,7 +93,6 @@ export default {
9593
}
9694
},
9795
},
98-
9996
};
10097
</script>
10198

@@ -114,15 +111,15 @@ export default {
114111
</template>
115112

116113
<style lang="scss">
117-
.vue-preview-image{
114+
.vue-preview-image {
118115
overflow: hidden;
119-
position: relative;
116+
position: relative;
120117
&__image {
121-
pointer-events: none;
122-
position: absolute;
123-
// Workaround to prevent bugs at the websites with max-width
124-
// rule applied to img (Vuepress for example)
125-
max-width: unset !important;
118+
pointer-events: none;
119+
position: absolute;
120+
// Workaround to prevent bugs at the websites with max-width
121+
// rule applied to img (Vuepress for example)
122+
max-width: unset !important;
126123
}
127124
}
128125
</style>

src/components/service/BoundingBox.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ export default {
153153
},
154154
mounted() {
155155
this.touches = [];
156-
this.draggingAnchor = [];
157156
},
158157
methods: {
159158
onHandlerDrag(dragEvent, horizontalDirection, verticalDirection) {

src/components/service/CropperWrapper.vue

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export default {
3636
},
3737
mounted() {
3838
this.touches = [];
39-
this.draggingAnchor = [];
4039
},
4140
methods: {
4241
onTouchStart(e) {
@@ -81,7 +80,6 @@ export default {
8180
clientY: e.clientY,
8281
};
8382
this.touches = [touch];
84-
this.initAnchor(touch);
8583
e.stopPropagation();
8684
}
8785
},
@@ -100,20 +98,11 @@ export default {
10098
onMouseUp() {
10199
this.touches = [];
102100
},
103-
initAnchor(touch) {
104-
const container = this.$refs.container;
105-
const { left, top, } = container.getBoundingClientRect();
106-
107-
this.anchor = {
108-
x: touch.clientX - left,
109-
y: touch.clientY - top,
110-
};
111-
},
112101
calculateGeometricProperties(touches) {
113102
const container = this.$refs.container;
114103
const { left, top } = container.getBoundingClientRect();
115104
116-
const centerMass = { left: 0,top: 0 };
105+
const centerMass = { left: 0, top: 0 };
117106
let spread = 0;
118107
119108
touches.forEach(touch => {

src/components/service/PreviewResult.vue

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@ export default {
1717
imageClassname: {
1818
type: String,
1919
},
20-
resultCoordinates: {
21-
type: Object,
22-
default() {
23-
return {
24-
width: 0,
25-
height: 0,
26-
left: 0,
27-
top: 0,
28-
};
29-
},
30-
},
3120
stencilCoordinates: {
3221
type: Object,
3322
default() {
@@ -58,12 +47,10 @@ export default {
5847
},
5948
imageStyle() {
6049
const imageTransforms = this.img.transforms;
61-
const imageWidth = this.img.size.width;
62-
const imageHeight = this.img.size.height;
63-
const coefficient = this.img.coefficient;
64-
const height = imageHeight / coefficient;
65-
const width = imageWidth / coefficient;
6650
const flipped = imageTransforms.flipped;
51+
const coefficient = this.img.coefficient;
52+
const height = this.img.size.height / coefficient;
53+
const width = this.img.size.width / coefficient;
6754
6855
const result = {
6956
width: `${width}px`,
@@ -76,8 +63,6 @@ export default {
7663
result.left = `${-this.stencilCoordinates.left - (height - width)/2 + imageTransforms.translateX}px`;
7764
result.top = `${-this.stencilCoordinates.top - (width - height)/2 + imageTransforms.translateY}px`;
7865
} else {
79-
result.width = `${width}px`;
80-
result.height = `${height}px`;
8166
result.left = `${-this.stencilCoordinates.left + imageTransforms.translateX}px`;
8267
result.top = `${-this.stencilCoordinates.top + imageTransforms.translateY}px`;
8368
}

src/components/stencils/CircleStencil.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export default {
157157
box-sizing: content-box;
158158
cursor: move;
159159
&__preview {
160-
border-radius: 50%;
160+
border-radius: 50%;
161161
}
162162
}
163163
</style>

src/core/algorithms.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
VERTICAL_DIRECTIONS,
44
ALL_DIRECTIONS,
55
} from './constants';
6+
67
import { MoveEvent } from './events';
78

89

@@ -30,6 +31,7 @@ function fitConditions({ directions: oldDirections, coordinates, restrictions, p
3031
let currentWidth = getCurrentWidth(coordinates, directions);
3132
let currentHeight = getCurrentHeight(coordinates, directions);
3233

34+
// Prevent strange resizes when the width or height of stencil becomes smaller than 0
3335
if (currentWidth < 0) {
3436
if (directions.left < 0 && directions.right < 0) {
3537
directions.left = -(coordinates.width - restrictions.minWidth) / (directions.left / directions.right);
@@ -40,7 +42,6 @@ function fitConditions({ directions: oldDirections, coordinates, restrictions, p
4042
directions.right = -(coordinates.width - restrictions.minWidth);
4143
}
4244
}
43-
4445
if (currentHeight < 0) {
4546
if (directions.top < 0 && directions.bottom < 0) {
4647
directions.top = -(coordinates.height - restrictions.minHeight) / (directions.top / directions.bottom);
@@ -52,9 +53,9 @@ function fitConditions({ directions: oldDirections, coordinates, restrictions, p
5253
}
5354
}
5455

56+
// Prevent breaking limits
5557
let breaks = getBrokenLimits(coordinates, directions, allowedArea);
5658

57-
5859
if (mode === 'move') {
5960
if (breaks.left > 0 && breaks.right === 0) {
6061
directions.right += breaks.left;
@@ -88,8 +89,6 @@ function fitConditions({ directions: oldDirections, coordinates, restrictions, p
8889
}
8990
});
9091

91-
92-
9392
if (preserveAspectRatio) {
9493
const multiplier = Math.min(...ALL_DIRECTIONS.map(direction => maxResize[direction]));
9594
if (multiplier !== Infinity) {

src/core/constants.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
export const WEST = 1;
2-
export const WEST_NORTH = 2;
3-
export const NORTH = 3;
4-
export const EAST_NORTH = 4;
5-
export const EAST = 5;
6-
export const EAST_SOUTH = 6;
7-
export const SOUTH = 7;
8-
export const WEST_SOUTH = 8;
9-
101
export const HORIZONTAL_DIRECTIONS = ['left', 'right'];
112
export const VERTICAL_DIRECTIONS = ['top', 'bottom'];
123
export const ALL_DIRECTIONS = ['left', 'right', 'top', 'bottom'];

src/core/utils.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export function isUndefined(obj) {
4646
return typeof obj === 'undefined';
4747
}
4848

49+
export function isObject(obj) {
50+
return typeof obj === 'object' && obj !== null;
51+
}
52+
4953
export function addTimestamp(url) {
5054
const timestamp = `timestamp=${(new Date()).getTime()}`;
5155
return url + (url.indexOf('?') === -1 ? '?' : '&') + timestamp;
@@ -58,16 +62,12 @@ export function distance(firstPoint, secondPoint) {
5862
}
5963

6064
export function getSettings(param, defaultParams = {}) {
61-
if (typeof param === 'object' && param !== null) {
62-
return {
63-
enabled: true,
64-
...defaultParams,
65-
...param
66-
};
67-
} else {
68-
return {
69-
enabled: Boolean(param),
70-
...defaultParams,
71-
};
65+
let result = {
66+
enabled: Boolean(param),
67+
...defaultParams
68+
};
69+
if (isObject(param)) {
70+
result = { ...result, ...param };
7271
}
73-
}
72+
return result;
73+
}

0 commit comments

Comments
 (0)