Spaces:
Runtime error
Runtime error
show frames from others
Browse files
frontend/src/lib/App.svelte
CHANGED
@@ -58,8 +58,11 @@
|
|
58 |
|
59 |
function onPaintMode(e: CustomEvent) {
|
60 |
const mode = e.detail.mode;
|
61 |
-
if (mode == 'paint') {
|
62 |
showModal = true;
|
|
|
|
|
|
|
63 |
}
|
64 |
}
|
65 |
function onClose() {
|
@@ -91,7 +94,7 @@
|
|
91 |
return base64Crop;
|
92 |
}
|
93 |
async function generateImage() {
|
94 |
-
|
95 |
$loadingState = 'Pending';
|
96 |
const prompt = $myPresence.currentPrompt;
|
97 |
const position = $myPresence.frame;
|
@@ -196,25 +199,15 @@
|
|
196 |
<Canvas bind:value={canvasEl} />
|
197 |
|
198 |
<main class="z-10 relative">
|
199 |
-
<PaintFrame transform={$currZoomTransform} />
|
200 |
-
|
201 |
-
{#if promptImgList && $showFrames}
|
202 |
-
{#each promptImgList as promptImg}
|
203 |
-
<Frame
|
204 |
-
color={COLORS[0]}
|
205 |
-
transform={$currZoomTransform}
|
206 |
-
position={promptImg?.position}
|
207 |
-
prompt={promptImg?.prompt}
|
208 |
-
/>
|
209 |
-
{/each}
|
210 |
-
{/if}
|
211 |
<!-- When others connected, iterate through others and show their cursors -->
|
212 |
{#if $others}
|
213 |
{#each [...$others] as { connectionId, presence } (connectionId)}
|
214 |
-
{#if presence?.isPrompting && presence?.
|
215 |
<Frame
|
216 |
color={COLORS[1 + (connectionId % (COLORS.length - 1))]}
|
217 |
-
position={presence?.
|
218 |
prompt={presence?.currentPrompt}
|
219 |
transform={$currZoomTransform}
|
220 |
/>
|
|
|
58 |
|
59 |
function onPaintMode(e: CustomEvent) {
|
60 |
const mode = e.detail.mode;
|
61 |
+
if (mode == 'paint' && !isPrompting) {
|
62 |
showModal = true;
|
63 |
+
myPresence.update({
|
64 |
+
isPrompting: true
|
65 |
+
});
|
66 |
}
|
67 |
}
|
68 |
function onClose() {
|
|
|
94 |
return base64Crop;
|
95 |
}
|
96 |
async function generateImage() {
|
97 |
+
if (isPrompting) return;
|
98 |
$loadingState = 'Pending';
|
99 |
const prompt = $myPresence.currentPrompt;
|
100 |
const position = $myPresence.frame;
|
|
|
199 |
<Canvas bind:value={canvasEl} />
|
200 |
|
201 |
<main class="z-10 relative">
|
202 |
+
<PaintFrame transform={$currZoomTransform} interactive={!isPrompting} />
|
203 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
<!-- When others connected, iterate through others and show their cursors -->
|
205 |
{#if $others}
|
206 |
{#each [...$others] as { connectionId, presence } (connectionId)}
|
207 |
+
{#if presence?.isPrompting && presence?.frame}
|
208 |
<Frame
|
209 |
color={COLORS[1 + (connectionId % (COLORS.length - 1))]}
|
210 |
+
position={presence?.frame}
|
211 |
prompt={presence?.currentPrompt}
|
212 |
transform={$currZoomTransform}
|
213 |
/>
|
frontend/src/lib/Canvas.svelte
CHANGED
@@ -41,7 +41,7 @@
|
|
41 |
onMount(() => {
|
42 |
const scale = width / containerEl.clientWidth;
|
43 |
const translatePadding = 0.1;
|
44 |
-
const scalePadding =
|
45 |
const zoomHandler = zoom()
|
46 |
.scaleExtent([1 / scale / scalePadding, 1])
|
47 |
// .extent([
|
@@ -57,7 +57,7 @@
|
|
57 |
|
58 |
const selection = select(canvasEl.parentElement)
|
59 |
.call(zoomHandler as any)
|
60 |
-
.call(zoomHandler.scaleTo as any, 1 / scale /
|
61 |
.on('pointermove', handlePointerMove)
|
62 |
.on('pointerleave', handlePointerLeave);
|
63 |
|
@@ -65,8 +65,8 @@
|
|
65 |
function zoomReset() {
|
66 |
console.log('zoom reset');
|
67 |
const scale = width / containerEl.clientWidth;
|
68 |
-
zoomHandler.scaleExtent([1 / scale / scalePadding, 1])
|
69 |
-
selection.call(zoomHandler.scaleTo as any, 1 / scale /
|
70 |
}
|
71 |
window.addEventListener('resize', zoomReset);
|
72 |
return () => {
|
@@ -125,9 +125,9 @@
|
|
125 |
|
126 |
// When the pointer leaves the page, set cursor presence to null
|
127 |
function handlePointerLeave() {
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
}
|
132 |
</script>
|
133 |
|
|
|
41 |
onMount(() => {
|
42 |
const scale = width / containerEl.clientWidth;
|
43 |
const translatePadding = 0.1;
|
44 |
+
const scalePadding = 3;
|
45 |
const zoomHandler = zoom()
|
46 |
.scaleExtent([1 / scale / scalePadding, 1])
|
47 |
// .extent([
|
|
|
57 |
|
58 |
const selection = select(canvasEl.parentElement)
|
59 |
.call(zoomHandler as any)
|
60 |
+
.call(zoomHandler.scaleTo as any, 1 / scale / 2)
|
61 |
.on('pointermove', handlePointerMove)
|
62 |
.on('pointerleave', handlePointerLeave);
|
63 |
|
|
|
65 |
function zoomReset() {
|
66 |
console.log('zoom reset');
|
67 |
const scale = width / containerEl.clientWidth;
|
68 |
+
zoomHandler.scaleExtent([1 / scale / scalePadding, 1]);
|
69 |
+
selection.call(zoomHandler.scaleTo as any, 1 / scale / 2);
|
70 |
}
|
71 |
window.addEventListener('resize', zoomReset);
|
72 |
return () => {
|
|
|
125 |
|
126 |
// When the pointer leaves the page, set cursor presence to null
|
127 |
function handlePointerLeave() {
|
128 |
+
myPresence.update({
|
129 |
+
cursor: null
|
130 |
+
});
|
131 |
}
|
132 |
</script>
|
133 |
|
frontend/src/lib/Frame.svelte
CHANGED
@@ -7,6 +7,7 @@
|
|
7 |
export let color = '';
|
8 |
export let position = { x: 0, y: 0 };
|
9 |
export let prompt = '';
|
|
|
10 |
|
11 |
$: coord = {
|
12 |
x: transform.applyX(position.x),
|
@@ -15,7 +16,7 @@
|
|
15 |
</script>
|
16 |
|
17 |
<div
|
18 |
-
class="frame z-0 flex relative"
|
19 |
style={`transform: translateX(${coord.x}px) translateY(${coord.y}px) scale(${transform.k});
|
20 |
background-image: linear-gradient(${color}, rgba(255,255,255,0));
|
21 |
color: ${color};
|
@@ -30,7 +31,7 @@
|
|
30 |
|
31 |
<style lang="postcss" scoped>
|
32 |
.frame {
|
33 |
-
@apply
|
34 |
transform-origin: 0 0;
|
35 |
}
|
36 |
.small-frame {
|
|
|
7 |
export let color = '';
|
8 |
export let position = { x: 0, y: 0 };
|
9 |
export let prompt = '';
|
10 |
+
export let interactive = false;
|
11 |
|
12 |
$: coord = {
|
13 |
x: transform.applyX(position.x),
|
|
|
16 |
</script>
|
17 |
|
18 |
<div
|
19 |
+
class="frame z-0 flex relative {!interactive ? 'pointer-events-none touch-none' : ''}"
|
20 |
style={`transform: translateX(${coord.x}px) translateY(${coord.y}px) scale(${transform.k});
|
21 |
background-image: linear-gradient(${color}, rgba(255,255,255,0));
|
22 |
color: ${color};
|
|
|
31 |
|
32 |
<style lang="postcss" scoped>
|
33 |
.frame {
|
34 |
+
@apply absolute top-0 left-0 border-2 border-spacing-3 border-sky-500 w-[512px] h-[512px];
|
35 |
transform-origin: 0 0;
|
36 |
}
|
37 |
.small-frame {
|
frontend/src/lib/Menu.svelte
CHANGED
@@ -1,8 +1,20 @@
|
|
1 |
<script lang="ts">
|
2 |
-
import {
|
3 |
-
import { createEventDispatcher } from 'svelte';
|
4 |
|
5 |
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
</script>
|
7 |
|
8 |
<div class="grid grid-cols-1 gap-3 w-max mx-auto">
|
|
|
1 |
<script lang="ts">
|
2 |
+
import { onMount, createEventDispatcher } from 'svelte';
|
|
|
3 |
|
4 |
const dispatch = createEventDispatcher();
|
5 |
+
|
6 |
+
const onKeyup = (e: KeyboardEvent) => {
|
7 |
+
e.preventDefault();
|
8 |
+
if (e.key === 'Enter') {
|
9 |
+
dispatch('paintMode', { mode: 'paint' });
|
10 |
+
}
|
11 |
+
};
|
12 |
+
onMount(() => {
|
13 |
+
window.addEventListener('keyup', onKeyup);
|
14 |
+
return () => {
|
15 |
+
window.removeEventListener('keyup', onKeyup);
|
16 |
+
};
|
17 |
+
});
|
18 |
</script>
|
19 |
|
20 |
<div class="grid grid-cols-1 gap-3 w-max mx-auto">
|
frontend/src/lib/PaintFrame.svelte
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
<script lang="ts">
|
2 |
import LoadingIcon from '$lib/LoadingIcon.svelte';
|
|
|
3 |
import { drag } from 'd3-drag';
|
4 |
import { select } from 'd3-selection';
|
5 |
import { round } from '$lib/utils';
|
@@ -14,20 +15,16 @@
|
|
14 |
|
15 |
export let transform: ZoomTransform;
|
16 |
export let color = 'black';
|
17 |
-
|
18 |
|
19 |
let position = {
|
20 |
-
x:
|
21 |
-
y:
|
22 |
};
|
23 |
|
24 |
let frameElement: HTMLDivElement;
|
25 |
-
$: coord = {
|
26 |
-
x: transform.applyX(position.x),
|
27 |
-
y: transform.applyY(position.y)
|
28 |
-
};
|
29 |
|
30 |
-
$: prompt = $myPresence?.currentPrompt
|
31 |
|
32 |
onMount(() => {
|
33 |
function dragstarted(event: Event) {
|
@@ -54,35 +51,11 @@
|
|
54 |
}
|
55 |
});
|
56 |
}
|
57 |
-
|
58 |
const dragHandler = drag().on('start', dragstarted).on('drag', dragged).on('end', dragended);
|
59 |
select(frameElement).call(dragHandler as any);
|
60 |
});
|
61 |
</script>
|
62 |
|
63 |
-
<div
|
64 |
-
|
65 |
-
class="frame z-0 flex relative"
|
66 |
-
style={`transform: translateX(${coord.x}px) translateY(${coord.y}px) scale(${transform.k});
|
67 |
-
background-image: linear-gradient(${color}, rgba(255,255,255,0));
|
68 |
-
color: ${color};
|
69 |
-
`}
|
70 |
-
>
|
71 |
-
<div class="small-frame z-0 flex relative" />
|
72 |
-
{$loadingState}
|
73 |
-
<LoadingIcon />
|
74 |
-
<h2 class="text-lg">Click to paint</h2>
|
75 |
-
|
76 |
-
<div class="absolute bottom-0 font-bold">{prompt}</div>
|
77 |
</div>
|
78 |
-
|
79 |
-
<style lang="postcss" scoped>
|
80 |
-
.frame {
|
81 |
-
@apply absolute top-0 left-0 border-2 border-spacing-3 border-sky-500 w-[512px] h-[512px];
|
82 |
-
transform-origin: 0 0;
|
83 |
-
}
|
84 |
-
.small-frame {
|
85 |
-
@apply pointer-events-none touch-none absolute top-1/2 left-1/2 border-2 border-spacing-3 border-sky-500 w-[256px] h-[256px];
|
86 |
-
transform: translateX(-50%) translateY(-50%);
|
87 |
-
}
|
88 |
-
</style>
|
|
|
1 |
<script lang="ts">
|
2 |
import LoadingIcon from '$lib/LoadingIcon.svelte';
|
3 |
+
import Frame from '$lib/Frame.svelte';
|
4 |
import { drag } from 'd3-drag';
|
5 |
import { select } from 'd3-selection';
|
6 |
import { round } from '$lib/utils';
|
|
|
15 |
|
16 |
export let transform: ZoomTransform;
|
17 |
export let color = 'black';
|
18 |
+
export let interactive = false;
|
19 |
|
20 |
let position = {
|
21 |
+
x: 768,
|
22 |
+
y: 768
|
23 |
};
|
24 |
|
25 |
let frameElement: HTMLDivElement;
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
$: prompt = $myPresence?.currentPrompt;
|
28 |
|
29 |
onMount(() => {
|
30 |
function dragstarted(event: Event) {
|
|
|
51 |
}
|
52 |
});
|
53 |
}
|
|
|
54 |
const dragHandler = drag().on('start', dragstarted).on('drag', dragged).on('end', dragended);
|
55 |
select(frameElement).call(dragHandler as any);
|
56 |
});
|
57 |
</script>
|
58 |
|
59 |
+
<div bind:this={frameElement}>
|
60 |
+
<Frame {color} {position} {prompt} {transform} {interactive} />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
frontend/src/lib/PromptModal.svelte
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
|
5 |
const dispatch = createEventDispatcher();
|
6 |
let prompt: string;
|
7 |
-
|
8 |
const myPresence = useMyPresence();
|
9 |
|
10 |
$: {
|
@@ -24,26 +24,34 @@
|
|
24 |
}
|
25 |
};
|
26 |
onMount(() => {
|
|
|
27 |
window.addEventListener('keyup', onKeyup);
|
28 |
return () => {
|
29 |
window.removeEventListener('keyup', onKeyup);
|
30 |
};
|
31 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
</script>
|
33 |
|
34 |
<form
|
35 |
class="fixed w-screen top-0 left-0 bottom-0 right-0 max-h-screen z-50 flex items-center justify-center bg-black bg-opacity-80 px-3"
|
36 |
-
on:submit|preventDefault={
|
37 |
on:click={() => dispatch('close')}
|
38 |
>
|
39 |
<input
|
|
|
|
|
40 |
on:click|stopPropagation
|
41 |
class="input"
|
42 |
placeholder="Type a prompt..."
|
43 |
title="Input prompt to generate image and obtain palette"
|
44 |
type="text"
|
45 |
name="prompt"
|
46 |
-
bind:value={prompt}
|
47 |
/>
|
48 |
</form>
|
49 |
|
|
|
4 |
|
5 |
const dispatch = createEventDispatcher();
|
6 |
let prompt: string;
|
7 |
+
let inputEl: HTMLInputElement;
|
8 |
const myPresence = useMyPresence();
|
9 |
|
10 |
$: {
|
|
|
24 |
}
|
25 |
};
|
26 |
onMount(() => {
|
27 |
+
inputEl.focus();
|
28 |
window.addEventListener('keyup', onKeyup);
|
29 |
return () => {
|
30 |
window.removeEventListener('keyup', onKeyup);
|
31 |
};
|
32 |
});
|
33 |
+
|
34 |
+
function onPrompt() {
|
35 |
+
if (prompt.trim() !== '') {
|
36 |
+
dispatch('prompt', prompt);
|
37 |
+
}
|
38 |
+
}
|
39 |
</script>
|
40 |
|
41 |
<form
|
42 |
class="fixed w-screen top-0 left-0 bottom-0 right-0 max-h-screen z-50 flex items-center justify-center bg-black bg-opacity-80 px-3"
|
43 |
+
on:submit|preventDefault={onPrompt}
|
44 |
on:click={() => dispatch('close')}
|
45 |
>
|
46 |
<input
|
47 |
+
bind:this={inputEl}
|
48 |
+
bind:value={prompt}
|
49 |
on:click|stopPropagation
|
50 |
class="input"
|
51 |
placeholder="Type a prompt..."
|
52 |
title="Input prompt to generate image and obtain palette"
|
53 |
type="text"
|
54 |
name="prompt"
|
|
|
55 |
/>
|
56 |
</form>
|
57 |
|