2023-01-23 22:33:39 +00:00
|
|
|
<template>
|
2023-09-07 01:17:14 +00:00
|
|
|
<svg
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
version="1.1"
|
|
|
|
|
viewBox="0 0 1000 1000"
|
|
|
|
|
preserveAspectRatio="none"
|
|
|
|
|
@contextmenu.prevent
|
|
|
|
|
@mousedown="transform_mouse_event"
|
|
|
|
|
@mousemove="transform_mouse_event"
|
|
|
|
|
@mouseup="transform_mouse_event"
|
|
|
|
|
@click="transform_mouse_event"
|
|
|
|
|
@dblclick="transform_mouse_event"
|
|
|
|
|
>
|
2023-01-23 22:33:39 +00:00
|
|
|
<slot name="default" />
|
|
|
|
|
</svg>
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-08-26 19:09:43 +00:00
|
|
|
<script setup lang="ts">
|
2024-08-23 16:38:04 +00:00
|
|
|
import { Vector2D } from "@/lib/rects/vector2d";
|
2023-01-23 22:33:39 +00:00
|
|
|
|
|
|
|
|
function get_event_thous(event: MouseEvent): Vector2D {
|
2023-11-09 23:08:35 +00:00
|
|
|
if (!(event.currentTarget instanceof SVGSVGElement)) {
|
2023-01-23 22:33:39 +00:00
|
|
|
return new Vector2D();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Vector2D(
|
2023-11-09 23:08:35 +00:00
|
|
|
Math.round((event.offsetX / event.currentTarget.clientWidth) * 1000),
|
|
|
|
|
Math.round((event.offsetY / event.currentTarget.clientHeight) * 1000),
|
2023-01-23 22:33:39 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-26 19:09:43 +00:00
|
|
|
const emit = defineEmits<{
|
2025-11-30 20:14:21 +00:00
|
|
|
(event: "mousedown", e: MouseEvent, point: Vector2D): void;
|
|
|
|
|
(event: "mouseup", e: MouseEvent, point: Vector2D): void;
|
|
|
|
|
(event: "mousemove", e: MouseEvent, point: Vector2D): void;
|
|
|
|
|
(event: "click", e: MouseEvent, point: Vector2D): void;
|
|
|
|
|
(event: "dblclick", e: MouseEvent, point: Vector2D): void;
|
2024-08-26 19:09:43 +00:00
|
|
|
}>();
|
2023-01-23 22:33:39 +00:00
|
|
|
|
2024-08-26 19:09:43 +00:00
|
|
|
function transform_mouse_event(event: MouseEvent) {
|
|
|
|
|
const point = get_event_thous(event);
|
2023-01-23 22:33:39 +00:00
|
|
|
|
2024-08-26 19:09:43 +00:00
|
|
|
// mute a useless typescript error
|
|
|
|
|
const event_type = event.type as "mousedown";
|
2025-12-04 18:51:57 +00:00
|
|
|
|
2024-08-26 19:09:43 +00:00
|
|
|
emit(event_type, event, point);
|
2023-01-23 22:33:39 +00:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
svg {
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
2023-01-23 23:49:29 +00:00
|
|
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
left: 0;
|
|
|
|
|
top: 0;
|
|
|
|
|
|
|
|
|
|
z-index: auto;
|
2023-01-23 22:33:39 +00:00
|
|
|
}
|
2023-09-07 01:17:14 +00:00
|
|
|
</style>
|