File size: 1,150 Bytes
66ed450
 
304976c
 
66ed450
 
 
 
32561d8
73e6846
66ed450
 
32561d8
 
 
 
66ed450
32561d8
66ed450
 
 
304976c
 
 
 
 
 
 
 
 
 
73e6846
 
 
 
 
304976c
66ed450
 
 
304976c
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
<script lang="ts">
	import { spring } from 'svelte/motion';
	import LoadingIcon from '$lib/LoadingIcon.svelte';

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

	export let transform: ZoomTransform;
	export let color = '';
	export let position = { x: 0, y: 0 };
	export let images: string[];

	// Spring animation for cursor
	const coords = spring(position, {
		stiffness: 0.07,
		damping: 0.35
	});
	// Update spring when x and y change
	$: coords.set(position);
</script>

<div
	class="frame z-0 flex relative"
	style={`transform: translateX(${$coords.x}px) translateY(${$coords.y}px) scale(${transform.k});
			background-image: linear-gradient(${color}, rgba(255,255,255,0));
			color: ${color};
	`}
>
	<LoadingIcon />
	<h2 class="text-lg">Click to paint</h2>

	<div class="absolute bottom-0 font-bold">A cat on grass</div>
	{#if images}
		<div class="absolute top-0 left-0">
			<img class="w-full" src={images[0]} alt="A cat on grass" />
		</div>
	{/if}
</div>

<style lang="postcss" scoped>
	.frame {
		@apply pointer-events-none touch-none absolute top-0 left-0 border-2 border-sky-500 w-[512px] h-[512px];
		transform-origin: 0 0;
	}
</style>