<script>
import Moveable from "vue3-moveable";

export default {
    components: { Moveable },
    setup() {
        const onClick = () => {
            const width = 50 + Math.floor(50 * Math.random());
            const height = 50 + Math.floor(50 * Math.random());
            document.querySelectorAll(".target")[Math.floor(Math.random() * 3)].style.cssText += `width: ${width}px;height: ${height}px`;
        };
        const onDrag = e => {
            e.target.style.transform = e.transform;
        };
        const onResize = e => {
            e.target.style.width = `${e.width}px`;
            e.target.style.height = `${e.height}px`;
            e.target.style.transform = e.drag.transform;
        };
        const onRotate = e => {
            e.target.style.transform = e.drag.transform;
        };
        return { onClick, onDrag, onResize, onRotate };
    }
};
</script>
<template>
    <div class="root">
        <div class="container">
            <button @click="onClick">Random Resize</button>
            <div class="target target1">Target1</div>
            <div class="target target2">Target2</div>
            <div class="target target3">Target3</div>
            <Moveable
                :target="'.target'"
                :individualGroupable="true"
                :draggable="true"
                :rotatable="true"
                :resizable="true"
                :useResizeObserver="true"
                @drag="onDrag"
                @resize="onResize"
                @rotate="onRotate"/>
        </div>
    </div>
</template>