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>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-09-07 02:08:56 +00:00
|
|
|
import { Vector2D } from "@/lib/vector2d";
|
2023-11-05 22:36:58 +00:00
|
|
|
import { advent22Store } from "@/plugins/store";
|
2023-09-06 16:25:35 +00:00
|
|
|
import { Options, Vue } from "vue-class-component";
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouse_event_validator(event: object, point: object): boolean {
|
|
|
|
if (!(event instanceof MouseEvent)) {
|
|
|
|
console.warn(event, "is not a MouseEvent!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(point instanceof Vector2D)) {
|
|
|
|
console.warn(point, "is not a Vector2D!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Options({
|
|
|
|
emits: {
|
|
|
|
mousedown: mouse_event_validator,
|
|
|
|
mouseup: mouse_event_validator,
|
|
|
|
mousemove: mouse_event_validator,
|
|
|
|
click: mouse_event_validator,
|
|
|
|
dblclick: mouse_event_validator,
|
|
|
|
},
|
|
|
|
})
|
2023-01-24 23:19:25 +00:00
|
|
|
export default class extends Vue {
|
2023-11-05 22:36:58 +00:00
|
|
|
public readonly store = advent22Store();
|
|
|
|
|
|
|
|
public mounted(): void {
|
|
|
|
new ResizeObserver(([first, ...rest]) => {
|
|
|
|
if (rest.length > 0)
|
|
|
|
console.warn(`Unexpected ${rest.length} extra entries!`);
|
|
|
|
|
|
|
|
this.store.set_calendar_aspect_ratio(first.contentRect);
|
|
|
|
}).observe(this.$el);
|
|
|
|
}
|
|
|
|
|
2023-09-06 16:25:35 +00:00
|
|
|
public transform_mouse_event(event: MouseEvent) {
|
2023-01-23 22:33:39 +00:00
|
|
|
const point = get_event_thous(event);
|
|
|
|
this.$emit(event.type, event, point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</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>
|