<script setup lang="ts">
import { nextTick, onBeforeMount } from 'vue';
import { Stage } from 'konva/lib/Stage';
import { useWindowSize } from '@vueuse/core';
import { Layer } from 'konva/lib/Layer';
import { Line } from 'konva/lib/shapes/Line';

const { width, height } = useWindowSize();

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

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

	const line1 = new Line({
		points: [5, 70, 140, 23, 250, 60, 300, 20],
		x: 0,
		y: 0,
		stroke: 'blue',
		strokeWidth: 2,
		lineCap: 'round',
		lineJoin: 'round',
	});
	layer.add(line1);

	const line2 = new Line({
		points: [5, 70, 140, 23, 250, 60, 300, 20],
		stroke: 'green',
		strokeWidth: 3,
		lineCap: 'square',
		dash: [33, 10],
	});
	layer.add(line2);
	line2.move({ x: 0, y: 10 });

	const line3 = new Line({
		points: [5, 70, 140, 23, 250, 60, 300, 20],
		stroke: 'red',
		strokeWidth: 3,
		lineCap: 'square',
		dash: [29, 20, 0.001, 20],
	});
	layer.add(line3);
	line3.move({ x: 0, y: 20 });

	const line4 = new Line({
		points: [23, 20, 23, 160, 70, 93, 150, 109, 290, 139, 270, 93],
		fill: '#00D2FF',
		stroke: 'black',
		strokeWidth: 5,
		closed: true,
	});
	layer.add(line4);
	line4.move({ x: 0, y: 80 });

	const line5 = new Line({
		points: [5, 70, 140, 23, 250, 60, 300, 20],
		stroke: 'green',
		strokeWidth: 10,
		lineJoin: 'round',
		lineCap: 'round',
		dash: [33, 26],
		tension: 0.5,
	});
	layer.add(line5);
	line5.move({ x: 0, y: 220 });

	const line6 = new Line({
		points: [5, 70, 140, 23, 250, 60, 300, 20],
		stroke: 'green',
		strokeWidth: 10,
		lineJoin: 'round',
		lineCap: 'round',
		dash: [33, 26],
		fill: 'red',
		tension: 0.5,
		closed: true,
	});
	layer.add(line6);
	line6.move({ x: 0, y: 300 });

	stage.add(layer);
};

onBeforeMount(() => {
	nextTick(() => initial());
});
</script>

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

<style scoped lang="scss"></style>
