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

export default {
    components: { Moveable },
    setup() {
        const containerRef = ref(null);
        const targetRef = ref(null);
        const moveableRef = ref(null);
        const onDrag = (e) => {
            e.target.style.transform = e.transform;
            targetRef.value.innerText = e.transform;
        };
        const onScale = (e) => {
            e.target.style.transform = e.drag.transform;
        };
        return { containerRef, targetRef, moveableRef, onDrag, onScale };
    }
};
</script>
<template>
    <div
        class="root"
        style="display: flex;justify-content: center;align-items: center;width: 700.2px;height: 700.2px;"
    >
        <div
            ref="containerRef"
            class="container2"
            style="width: 299px;height: 299px;outline: 10px solid #ccc;"
        >
            <div
                class="target2"
                ref="targetRef"
                style="width: 100px;height: 100px;"
            >Target</div>
            <Moveable
                ref="moveableRef"
                :target="targetRef"
                :draggable="true"
                :edgeDraggable="false"
                :startDragRotate="0"
                :throttleDragRotate="0"
                :keepRatio="false"
                :throttleScale="0"
                :snappable="true"
                :snapDirections="({ top: true, left: true, bottom: true, right: true, center: true, middle: true })"
                :elementSnapDirections="({ middle: true, center: true, top: true, left: true, bottom: true, right: true })"
                :snapThreshold="5"
                :elementGuidelines="[containerRef]"
                @drag="onDrag"
                @scale="onScale"/>
        </div>
    </div>
</template>