<script>
import Moveable from "vue-moveable";
import { throttle } from "@daybrush/utils";

export default {
    components: { Moveable },
    data() {
        return {};
    },
    methods: {
        onBeforeRotate(e) {
            e.setRotation(throttle(e.rotation, 45));
        },
        onRender(e) {
            e.target.style.cssText += e.cssText;
        },
        onBeforeRotateGroup(e) {
            e.setRotation(throttle(e.rotation, 45));
        },
        onRenderGroup(e) {
            e.events.forEach(ev => {
                ev.target.style.cssText += ev.cssText;
            });
        }
    }
};
</script>
<template>
    <div class="root">
        <div
            class="container"
            style="height: 400px;border: 1px solid black;"
        >
            <div class="target target1 group">Target1</div>
            <div class="target target2 group">Target2</div>
            <div class="target target3 group">Target3</div>
            <div
                class="target rotatable"
                style="position: absolute;width: 200px;height: 100px;top: 50px;"
            >Single Target</div>
            <Moveable
                :target="'.target.rotatable'"
                :resizable="true"
                :draggable="true"
                :rotatable="true"
                @beforeRotate="onBeforeRotate"
                @render="onRender"/>
            <Moveable
                :target="'.target.group'"
                :draggable="true"
                :rotatable="true"
                @beforeRotateGroup="onBeforeRotateGroup"
                @renderGroup="onRenderGroup"/>
        </div>
    </div>
</template>