Spaces:
Runtime error
Runtime error
ui improvements
Browse files
frontend/src/lib/App.svelte
CHANGED
@@ -51,6 +51,7 @@
|
|
51 |
}
|
52 |
function onClose() {
|
53 |
showModal = false;
|
|
|
54 |
}
|
55 |
|
56 |
function onPaint() {
|
@@ -142,7 +143,8 @@
|
|
142 |
}
|
143 |
websocket.close();
|
144 |
myPresence.update({
|
145 |
-
status: Status.ready
|
|
|
146 |
});
|
147 |
return;
|
148 |
case 'process_starts':
|
@@ -162,7 +164,7 @@
|
|
162 |
{$loadingState}
|
163 |
</div>
|
164 |
{#if showModal}
|
165 |
-
<PromptModal on:paint={onPaint} on:close={onClose} />
|
166 |
{/if}
|
167 |
<div class="fixed top-0 left-0 z-0 w-screen h-screen">
|
168 |
<PaintCanvas />
|
|
|
51 |
}
|
52 |
function onClose() {
|
53 |
showModal = false;
|
54 |
+
console.log('close Modal');
|
55 |
}
|
56 |
|
57 |
function onPaint() {
|
|
|
143 |
}
|
144 |
websocket.close();
|
145 |
myPresence.update({
|
146 |
+
status: Status.ready,
|
147 |
+
currentPrompt: ''
|
148 |
});
|
149 |
return;
|
150 |
case 'process_starts':
|
|
|
164 |
{$loadingState}
|
165 |
</div>
|
166 |
{#if showModal}
|
167 |
+
<PromptModal on:paint={onPaint} on:close={onClose} initPrompt={$myPresence?.currentPrompt} />
|
168 |
{/if}
|
169 |
<div class="fixed top-0 left-0 z-0 w-screen h-screen">
|
170 |
<PaintCanvas />
|
frontend/src/lib/PaintFrame.svelte
CHANGED
@@ -53,7 +53,7 @@
|
|
53 |
maskCtx.save();
|
54 |
maskCtx.clearRect(0, 0, 512, 512);
|
55 |
maskCtx.globalCompositeOperation = 'source-over';
|
56 |
-
maskCtx.drawImage($canvasEl, cursor.x, cursor.y, 512, 512, 0, 0, 512, 512);
|
57 |
maskCtx.restore();
|
58 |
}
|
59 |
function drawLine(points: { x: number; y: number; lastx: number; lasty: number }) {
|
@@ -122,9 +122,9 @@
|
|
122 |
function dragMoveHandler() {
|
123 |
function dragstarted(event: Event) {
|
124 |
if (isLoading) return;
|
125 |
-
|
126 |
const rect = (event.sourceEvent.target as HTMLElement).getBoundingClientRect();
|
127 |
-
|
|
|
128 |
offsetX = event.sourceEvent.targetTouches[0].pageX - rect.left;
|
129 |
offsetY = event.sourceEvent.targetTouches[0].pageY - rect.top;
|
130 |
} else {
|
@@ -238,7 +238,7 @@
|
|
238 |
</div>
|
239 |
<div
|
240 |
bind:this={frameElement}
|
241 |
-
class="absolute top-0 left-0 w-[512px] h-[512px] hand
|
242 |
{dragEnabled ? 'block' : 'hidden'}"
|
243 |
style={`transform: translateX(${coord.x}px) translateY(${coord.y}px) scale(${transform.k}); transform-origin: 0 0;`}
|
244 |
/>
|
|
|
53 |
maskCtx.save();
|
54 |
maskCtx.clearRect(0, 0, 512, 512);
|
55 |
maskCtx.globalCompositeOperation = 'source-over';
|
56 |
+
maskCtx.drawImage($canvasEl, cursor.x, cursor.y, 512, 512, cursor.x > 0 ? 0 : -cursor.x, cursor.y > 0 ? 0 : -cursor.y, 512, 512);
|
57 |
maskCtx.restore();
|
58 |
}
|
59 |
function drawLine(points: { x: number; y: number; lastx: number; lasty: number }) {
|
|
|
122 |
function dragMoveHandler() {
|
123 |
function dragstarted(event: Event) {
|
124 |
if (isLoading) return;
|
|
|
125 |
const rect = (event.sourceEvent.target as HTMLElement).getBoundingClientRect();
|
126 |
+
|
127 |
+
if (typeof TouchEvent !== 'undefined' && event.sourceEvent instanceof TouchEvent) {
|
128 |
offsetX = event.sourceEvent.targetTouches[0].pageX - rect.left;
|
129 |
offsetY = event.sourceEvent.targetTouches[0].pageY - rect.top;
|
130 |
} else {
|
|
|
238 |
</div>
|
239 |
<div
|
240 |
bind:this={frameElement}
|
241 |
+
class="absolute top-0 left-0 w-[512px] h-[512px] ring-8 hand
|
242 |
{dragEnabled ? 'block' : 'hidden'}"
|
243 |
style={`transform: translateX(${coord.x}px) translateY(${coord.y}px) scale(${transform.k}); transform-origin: 0 0;`}
|
244 |
/>
|
frontend/src/lib/PromptModal.svelte
CHANGED
@@ -1,22 +1,25 @@
|
|
1 |
<script lang="ts">
|
2 |
-
import { createEventDispatcher, onMount } from 'svelte';
|
3 |
import { useMyPresence } from '$lib/liveblocks';
|
4 |
import { Status } from '$lib/types';
|
5 |
|
6 |
const dispatch = createEventDispatcher();
|
7 |
-
let
|
|
|
8 |
let inputEl: HTMLInputElement;
|
|
|
9 |
const myPresence = useMyPresence();
|
10 |
|
11 |
const onKeyup = (e: KeyboardEvent) => {
|
12 |
if (e.key === 'Escape') {
|
13 |
-
cancel();
|
14 |
}
|
15 |
};
|
|
|
16 |
onMount(() => {
|
17 |
inputEl.focus();
|
18 |
inputEl.addEventListener('focusout', cancel);
|
19 |
-
prompt =
|
20 |
window.addEventListener('keyup', onKeyup);
|
21 |
return () => {
|
22 |
window.removeEventListener('keyup', onKeyup);
|
@@ -39,15 +42,18 @@
|
|
39 |
if (prompt.trim() !== '') {
|
40 |
console.log('Prompting with: ', prompt);
|
41 |
dispatch('paint');
|
|
|
42 |
}
|
43 |
}
|
44 |
function onInput(event: Event) {
|
45 |
const target = event.target as HTMLInputElement;
|
46 |
debouce(target.value);
|
47 |
}
|
48 |
-
function cancel() {
|
|
|
|
|
|
|
49 |
myPresence.update({
|
50 |
-
currentPrompt: '',
|
51 |
status: Status.ready
|
52 |
});
|
53 |
dispatch('close');
|
@@ -60,6 +66,7 @@
|
|
60 |
>
|
61 |
<div class="flex bg-white rounded-2xl px-2 w-full max-w-md">
|
62 |
<input
|
|
|
63 |
bind:this={inputEl}
|
64 |
on:click|stopPropagation
|
65 |
on:input={onInput}
|
@@ -69,8 +76,11 @@
|
|
69 |
type="text"
|
70 |
name="prompt"
|
71 |
/>
|
72 |
-
<button
|
73 |
-
|
|
|
|
|
|
|
74 |
>
|
75 |
</div>
|
76 |
</form>
|
|
|
1 |
<script lang="ts">
|
2 |
+
import { createEventDispatcher, onMount, tick } from 'svelte';
|
3 |
import { useMyPresence } from '$lib/liveblocks';
|
4 |
import { Status } from '$lib/types';
|
5 |
|
6 |
const dispatch = createEventDispatcher();
|
7 |
+
export let initPrompt = '';
|
8 |
+
let prompt: string;
|
9 |
let inputEl: HTMLInputElement;
|
10 |
+
let buttonEl: HTMLElement;
|
11 |
const myPresence = useMyPresence();
|
12 |
|
13 |
const onKeyup = (e: KeyboardEvent) => {
|
14 |
if (e.key === 'Escape') {
|
15 |
+
cancel(e);
|
16 |
}
|
17 |
};
|
18 |
+
|
19 |
onMount(() => {
|
20 |
inputEl.focus();
|
21 |
inputEl.addEventListener('focusout', cancel);
|
22 |
+
prompt = initPrompt;
|
23 |
window.addEventListener('keyup', onKeyup);
|
24 |
return () => {
|
25 |
window.removeEventListener('keyup', onKeyup);
|
|
|
42 |
if (prompt.trim() !== '') {
|
43 |
console.log('Prompting with: ', prompt);
|
44 |
dispatch('paint');
|
45 |
+
dispatch('close');
|
46 |
}
|
47 |
}
|
48 |
function onInput(event: Event) {
|
49 |
const target = event.target as HTMLInputElement;
|
50 |
debouce(target.value);
|
51 |
}
|
52 |
+
function cancel(event?: Event) {
|
53 |
+
console.log(event?.relatedTarget)
|
54 |
+
if (!(event instanceof KeyboardEvent) && event?.relatedTarget !== null) return;
|
55 |
+
|
56 |
myPresence.update({
|
|
|
57 |
status: Status.ready
|
58 |
});
|
59 |
dispatch('close');
|
|
|
66 |
>
|
67 |
<div class="flex bg-white rounded-2xl px-2 w-full max-w-md">
|
68 |
<input
|
69 |
+
value={prompt}
|
70 |
bind:this={inputEl}
|
71 |
on:click|stopPropagation
|
72 |
on:input={onInput}
|
|
|
76 |
type="text"
|
77 |
name="prompt"
|
78 |
/>
|
79 |
+
<button
|
80 |
+
bind:this={buttonEl}
|
81 |
+
on:click|preventDefault={onPrompt}
|
82 |
+
class="font-mono border-l-2 pl-2"
|
83 |
+
type="submit">Paint</button
|
84 |
>
|
85 |
</div>
|
86 |
</form>
|
frontend/src/lib/types.ts
CHANGED
@@ -34,4 +34,3 @@ export type PromptImgObject = {
|
|
34 |
};
|
35 |
|
36 |
export type PromptImgKey = string;
|
37 |
-
|
|
|
34 |
};
|
35 |
|
36 |
export type PromptImgKey = string;
|
|
frontend/src/lib/utils.ts
CHANGED
@@ -47,7 +47,8 @@ export async function uploadImage(imagBlob: Blob, prompt: string): Promise<strin
|
|
47 |
}
|
48 |
|
49 |
export function round(pos: number, size = 32) {
|
50 |
-
|
|
|
51 |
}
|
52 |
|
53 |
function slugify(text: string) {
|
|
|
47 |
}
|
48 |
|
49 |
export function round(pos: number, size = 32) {
|
50 |
+
const value = pos % size < size / 2 ? pos - (pos % size) : pos + size - (pos % size);
|
51 |
+
return Math.round(value);
|
52 |
}
|
53 |
|
54 |
function slugify(text: string) {
|