File size: 1,640 Bytes
66ed450
4346adf
304976c
66ed450
 
 
 
32561d8
423b87b
d11af81
7d4e291
dc37474
8239db2
7cb7420
e5b9b7e
 
7cb7420
66ed450
 
 
4346adf
dc37474
 
d11af81
304976c
d11af81
8239db2
 
 
d11af81
d2b90f4
8239db2
 
 
 
 
 
304976c
8239db2
4346adf
 
 
 
 
 
304976c
66ed450
 
 
4346adf
66ed450
 
d2b90f4
d11af81
d2b90f4
 
66ed450
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<script lang="ts">
	import LoadingIcon from '$lib/Icons/LoadingIcon.svelte';

	import type { ZoomTransform } from 'd3-zoom';

	export let transform: ZoomTransform;
	export let color = '';
	export let position = { x: 0, y: 0 };
	export let prompt = '';
	export let loadingState = '';
	export let interactive = false;
	export let isDragging = false;
	export let isLoading = false;
	$: coord = {
		x: transform.applyX(position.x),
		y: transform.applyY(position.y)
	};
</script>

<div
	class="frame
	{!interactive ? 'pointer-events-none touch-none' : ''}
	{isDragging ? 'cursor-grabbing' : 'cursor-grab'}"
	style={`transform: translateX(${coord.x}px) translateY(${coord.y}px) scale(${transform.k}); border-color: ${color};`}
>
	{#if loadingState}
		<div class="col-span-2 row-start-1">
			<span class="text-white drop-shadow-lg">{loadingState}</span>
		</div>
	{/if}
	<div class="small-frame z-0 flex relative" />
	{#if isLoading}
		<div class="col-start-2 row-start-2">
			<LoadingIcon />
		</div>
	{/if}

	<h2 class="text-lg">Click to paint</h2>
	<div class="absolute bottom-0 font-bold text-lg">{prompt}</div>
	<div class="absolute top-full">
		<slot name="bottom" />
	</div>
	<div class="absolute left-full bottom-0">
		<slot name="right" />
	</div>
</div>

<style lang="postcss" scoped>
	.frame {
		@apply absolute top-0 left-0  grid grid-cols-3 grid-rows-3 border-2 border-spacing-3 border-sky-500 w-[512px] h-[512px];
		transform-origin: 0 0;
	}
	.small-frame {
		@apply pointer-events-none touch-none absolute top-1/2 left-1/2 border-2 border-spacing-3  w-[256px] h-[256px];
		transform: translateX(-50%) translateY(-50%);
	}
</style>