Skip to content

Commit

Permalink
Add the possibility to move and resize background
Browse files Browse the repository at this point in the history
  • Loading branch information
Norserium committed Dec 4, 2019
1 parent a578092 commit 218646a
Show file tree
Hide file tree
Showing 28 changed files with 1,342 additions and 441 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ export default {
},
onHandlerMove(dragEvent) {
const shift = dragEvent.shift();
const widthResize = shift.left/2;
const heightResize = -shift.top/2;
const { height, width, left, top, } = this.resultCoordinates;
const coefficient = width / this.stencilCoordinates.width;
this.$emit('resize', new ResizeEvent(
dragEvent.nativeEvent,
{
left: widthResize,
right: widthResize,
top: heightResize,
bottom: heightResize,
},
{
compensate: true,
}
));
))
},
aspectRatios() {
return {
Expand Down
257 changes: 257 additions & 0 deletions example/docs/.vuepress/components/algorithm-tester.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
<script>
import { BoundingBox, ResizeEvent } from 'vue-advanced-cropper';
import {resize} from 'vue-advanced-cropper/src/core/algorithms'
export default {
name: 'AlgorithmTester',
components: {
BoundingBox,
},
data() {
return {
coordinates: {
cropper: {
width: 100,
height: 100,
left: 150,
top: 150,
},
stencil: {
width: 100,
height: 100,
left: 150,
top: 150,
},
current: {
width: 100,
height: 100,
left: 150,
top: 150,
},
area: {
width: 400,
height: 400,
left: 0,
top: 0,
},
},
stencilProps: `{\n\t"aspectRatio": 10/16\n}`,
};
},
computed: {
cropperStyle() {
return {
width: `${this.coordinates.cropper.width}px`,
height: `${this.coordinates.cropper.height}px`,
top: `${this.coordinates.cropper.top}px`,
left: `${this.coordinates.cropper.left}px`,
}
},
currentStyle() {
return {
width: `${this.coordinates.current.width}px`,
height: `${this.coordinates.current.height}px`,
top: `${this.coordinates.current.top}px`,
left: `${this.coordinates.current.left}px`,
}
},
stencilStyle() {
return {
width: `${this.coordinates.stencil.width}px`,
height: `${this.coordinates.stencil.height}px`,
top: `${this.coordinates.stencil.top}px`,
left: `${this.coordinates.stencil.left}px`,
}
},
areaStyle() {
return {
width: `${this.coordinates.area.width}px`,
height: `${this.coordinates.area.height}px`,
top: `${this.coordinates.area.top}px`,
left: `${this.coordinates.area.left}px`,
}
}
},
methods: {
onResizeStencil({directions}) {
this.coordinates.stencil.left -= directions.left
this.coordinates.stencil.top -= directions.top
this.coordinates.stencil.width += directions.right + directions.left
this.coordinates.stencil.height += directions.top + directions.bottom
},
onResizeArea({directions}) {
this.coordinates.area.left -= directions.left
this.coordinates.area.top -= directions.top
this.coordinates.area.width += directions.right + directions.left
this.coordinates.area.height += directions.top + directions.bottom
},
onResizeCurrent({directions}) {
this.coordinates.current.left -= directions.left
this.coordinates.current.top -= directions.top
this.coordinates.current.width += directions.right + directions.left
this.coordinates.current.height += directions.top + directions.bottom
},
onResize(complete) {
const coordinates = resize({
coordinates: {...this.coordinates.current},
restrictions: {
minWidth: 100,
minHeight: 100,
maxWidth: 400,
maxHeight: 400,
},
aspectRatio: {
minimum: 10/20,
},
allowedArea: {
left: this.coordinates.area.left,
top: this.coordinates.area.top,
bottom: this.coordinates.area.top + this.coordinates.area.height,
right: this.coordinates.area.left + this.coordinates.area.width,
},
coefficient: 1,
resizeEvent: new ResizeEvent({}, {
left: -(this.coordinates.stencil.left - this.coordinates.current.left),
top: -(this.coordinates.stencil.top - this.coordinates.current.top),
bottom: this.coordinates.stencil.top + this.coordinates.stencil.height - (this.coordinates.current.top + this.coordinates.current.height),
right: this.coordinates.stencil.left + this.coordinates.stencil.width - (this.coordinates.current.left + this.coordinates.current.width),
}, {
compensate: true
}),
complete
})
this.coordinates.current = {...coordinates}
}
}
};
</script>

<template>
<div class="bounding-box-example">
<div class="playground">
<div class="area-wrapper">
<div class="area">
<BoundingBox
class="area-box"
handler-component="simple-handler"
line-component="simple-line"
:style="areaStyle"
:lines-classnames="{default: 'line line--area'}"
:handlers-classnames="{default: 'handler handler--area'}"
@resize="onResizeArea"
/>
<BoundingBox
class="stencil-box"
handler-component="simple-handler"
line-component="simple-line"
:style="stencilStyle"
:lines-classnames="{default: 'line line--stencil'}"
:handlers-classnames="{default: 'handler handler--stencil'}"
@resize="onResizeStencil"
/>
<div
class="current-box"
:style="currentStyle"
/>
</div>
<div class="buttons">
<div class="button" @click="onResize(false)">
<img :src="require('../assets/icons/resize.svg')"/>
</div>
<div class="button button--complete" @click="onResize(true)">
<img :src="require('../assets/icons/resize.svg')"/>
</div>
</div>

</div>
</div>
<div class="options">
<div class="option">
Stencil props:
<textarea class="option__textarea" v-model="stencilProps"/>
</div>
</div>
</div>
</template>

<style lang="scss">
.bounding-box-example {
position: relative;
padding-top: 20px;
.playground {
position: relative;
}
.buttons {
position: absolute;
right: 20px;
bottom: 20px;
}
.button {
background: rgb(61, 82, 206);
border-radius: 50%;
height: 50px;
width: 50px;
margin-top: 10px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
&--complete {
background: #3fb37f;
}
}
.options {
border-top: solid 1px #EEE;
padding-top: 20px;
}
.option {
&__textarea {
display: block;
height: 150px;
width: 100%;
}
}
.area-wrapper {
display: flex;
align-items: center;
justify-content: center;
padding-top: 50px;
padding-bottom: 50px;
overflow: hidden;
}
.area {
width: 400px;
height: 400px;
position: relative;
outline: dashed 1px #EEE;
}
.current-box {
border: solid 1px rgba(255,150,150, 0.8);
}
.stencil-box, .area-box, .current-box {
pointer-events: none;
position: absolute;
}
.line {
pointer-events: all;
&--stencil {
border-color: rgba(#3fb37f, 0.5);
}
&--area {
border-color: rgba(#555, 0.5);
border-style: dotted;
}
}
.handler {
pointer-events: all;
&--stencil {
background: #3fb37f;
}
&--area {
background: #555;
opacity: 0.5;
}
}
}
</style>
2 changes: 1 addition & 1 deletion example/docs/.vuepress/components/home-page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<h1 class="presentation__title">
Advanced Cropper
<div class="presentation__version">
0.13
0.14
</div>
</h1>
</div>
Expand Down
34 changes: 34 additions & 0 deletions example/docs/.vuepress/components/mobile-fixed-example.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script>
import { Cropper } from 'vue-advanced-cropper';
export default {
components: {
Cropper,
},
data() {
return {
img: 'https://images.unsplash.com/photo-1527137342181-19aab11a8ee8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80',
};
},
};
</script>

<template>
<div class='mobile-fixed-example'>
<Cropper
:src="img"
:stencil-props="{
handlers: {},
movable: false,
scalable: false,
aspectRatio: 1,
}"
/>
</div>
</template>

<style lang="scss">
.mobile-fixed-example {
}
</style>
18 changes: 6 additions & 12 deletions example/docs/.vuepress/components/set-coordinates-example.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ export default {
<div class="set-coordinates-example">
<Cropper
ref="cropper"
classname="coodinates-cropper"
:stencil-props="{
minAspectRatio: 10/20,
}"
:src="image"
@change="updateSize"
classname="coodinates-cropper"
:src="image"
:stencil-props="{
minAspectRatio: 10/20,
}"
@change="updateSize"
/>
<div class="buttons">
<div class="button" title="Resize (x2)" @click="resize(2, 2)">
Expand Down Expand Up @@ -99,12 +99,10 @@ export default {
margin-bottom: 20px;
position: relative;
user-select: none;
.coodinates-cropper {
min-height: 400px;
background: black;
}
.size-info {
color: white;
position: absolute;
Expand All @@ -113,7 +111,6 @@ export default {
bottom: 10px;
opacity: 0.5;
}
.button {
background: rgba(black, 0.4);
display: flex;
Expand All @@ -128,14 +125,11 @@ export default {
background: black;
}
}
.buttons {
position: absolute;
left: 10px;
top: 50%;
transform: translateY(-50%);
}
}
</style>
4 changes: 4 additions & 0 deletions example/docs/.vuepress/styles/index.styl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.sidebar
.repo-link
display: none !important;

.navbar
background-color: #3fb37f;
background-image: url('/vue-advanced-cropper/background.png');
Expand Down
4 changes: 4 additions & 0 deletions example/docs/introduction/algorithm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Algorithm

## Tester
<algorithm-tester/>
Loading

0 comments on commit 218646a

Please sign in to comment.