<script>
import Moveable from "vue3-moveable";
import { ref } from "vue";

export default {
    components: { Moveable },
    setup() {
        const translate = ref([0, 0]);
        const targetRef = ref(null);
        const moveableRef = ref(null);
        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 onResizeEnd = e => {
            const lastEvent = e.lastEvent;
            if (lastEvent) {
                console.log(lastEvent.drag.transform);
            }
        };
        return { targetRef, moveableRef, onResize, onResizeEnd };
    }
};
</script>
<template>
    <div class="root">
        <div
            class="container"
            style="display: flex;"
        >
            <div
                class="target"
                ref="targetRef"
                style="position: relative;width: 200px;height: 100px;"
            >Target</div>
            <Moveable
                ref="moveableRef"
                :target="targetRef"
                :resizable="true"
                :keepRatio="true"
                :throttleResize="1"
                @resize="onResize"
                @resizeEnd="onResizeEnd"/>
        </div>
    </div>
</template>