<template>
	<div id="container"></div>
</template>

<script setup lang="ts">
import { useWindowSize } from '@vueuse/core';
import Konva from 'konva/lib';
import { onMounted } from 'vue';

const { width, height } = useWindowSize();

const initial = () => {
	const stage = new Konva.Stage({
		container: 'container',
		width: width.value,
		height: height.value,
	});

	const layer = new Konva.Layer({ draggable: true });

	const triangle = new Konva.RegularPolygon({
		x: stage.width() / 2,
		y: stage.height() / 2,
		sides: 3,
		radius: 70,
		fill: 'red',
		stroke: 'black',
		strokeWidth: 20,
		lineJoin: 'bevel',
	});

	triangle.on('mouseover', function () {
		this.lineJoin('round');
	});

	triangle.on('mouseout', function () {
		this.lineJoin('bevel');
	});

	layer.add(triangle);
	stage.add(layer);
};

onMounted(() => {
	initial();
});
</script>
