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

export default {
    components: { Moveable },
    setup() {
        const spanRef = ref(null);
        const onDrag = e => {
            e.target.style.transform = e.transform;
            spanRef.value.innerHTML = `${e.translate[0]} x ${e.translate[1]}`;
        };
        return { spanRef, onDrag };
    }
};
</script>
<template>
    <div class="container">
        <span ref="spanRef">Position</span>
        <div
            class="preview"
            style="position: relative;width: 800px;height: 800px;transform: scale(0.67123);transform-origin: top left;background: #eee;"
        >
            <div
                class="target"
                style="top: 0px;left: 0px;transform: translate(150px, 100px);"
            >Target</div>
        </div>
        <Moveable
            :target="'.target'"
            :draggable="true"
            :snappable="true"
            snapContainer=".preview"
            :bounds="({ left: 0, top: 0 })"
            @drag="onDrag"/>
    </div>
</template>