Spaces:
Runtime error
Runtime error
cleaning up
Browse files- frontend/src/app.d.ts +2 -0
- frontend/src/lib/App.svelte +6 -6
- frontend/src/lib/Canvas.svelte +14 -11
- frontend/src/lib/Cursor.svelte +1 -1
- frontend/src/lib/PaintFrame.svelte +8 -11
- frontend/src/lib/PromptModal.svelte +0 -3
- frontend/src/lib/liveblocks/RoomProvider.svelte +1 -0
- frontend/src/lib/liveblocks/useBatch.ts +1 -0
- frontend/src/lib/liveblocks/useHistory.ts +1 -0
- frontend/src/lib/liveblocks/useList.ts +1 -0
- frontend/src/lib/liveblocks/useMyPresence.ts +1 -0
- frontend/src/lib/liveblocks/useObject.ts +1 -0
- frontend/src/lib/liveblocks/useOthers.ts +1 -0
- frontend/src/lib/liveblocks/useRoom.ts +1 -0
- frontend/src/lib/liveblocks/useStorage.ts +1 -0
- frontend/src/lib/utils.ts +3 -7
frontend/src/app.d.ts
CHANGED
@@ -15,5 +15,7 @@ declare global {
|
|
15 |
}
|
16 |
interface Event {
|
17 |
transform: ZoomTransform;
|
|
|
|
|
18 |
}
|
19 |
}
|
|
|
15 |
}
|
16 |
interface Event {
|
17 |
transform: ZoomTransform;
|
18 |
+
x: number;
|
19 |
+
y: number;
|
20 |
}
|
21 |
}
|
frontend/src/lib/App.svelte
CHANGED
@@ -60,9 +60,11 @@
|
|
60 |
let canvasEl: HTMLCanvasElement;
|
61 |
|
62 |
function onPaintMode(e: CustomEvent) {
|
63 |
-
|
|
|
64 |
}
|
65 |
async function onClose(e: CustomEvent) {
|
|
|
66 |
$isPrompting = false;
|
67 |
}
|
68 |
async function onPrompt(e: CustomEvent) {
|
@@ -132,7 +134,7 @@
|
|
132 |
$isLoading = false;
|
133 |
return;
|
134 |
case 'estimation':
|
135 |
-
const {
|
136 |
$loadingState = `On queue ${rank}/${queue_size}`;
|
137 |
break;
|
138 |
case 'process_generating':
|
@@ -176,8 +178,6 @@
|
|
176 |
}
|
177 |
};
|
178 |
}
|
179 |
-
let modal = false;
|
180 |
-
let currentPrompt = '';
|
181 |
</script>
|
182 |
|
183 |
<!-- Show the current user's cursor location -->
|
@@ -189,13 +189,13 @@
|
|
189 |
<PromptModal on:prompt={onPrompt} on:close={onClose} />
|
190 |
{/if}
|
191 |
<div class="fixed top-0 left-0 z-0 w-screen h-screen">
|
192 |
-
<Canvas bind:value={canvasEl}
|
193 |
|
194 |
<main class="z-10 relative">
|
195 |
<PaintFrame transform={$currZoomTransform} />
|
196 |
|
197 |
{#if promptImgList && $showFrames}
|
198 |
-
{#each promptImgList as promptImg
|
199 |
<Frame
|
200 |
color={COLORS[0]}
|
201 |
transform={$currZoomTransform}
|
|
|
60 |
let canvasEl: HTMLCanvasElement;
|
61 |
|
62 |
function onPaintMode(e: CustomEvent) {
|
63 |
+
console.log('onPaintMode', e.detail);
|
64 |
+
// const mode = e.detail.mode;
|
65 |
}
|
66 |
async function onClose(e: CustomEvent) {
|
67 |
+
console.log('onClose', e.detail);
|
68 |
$isPrompting = false;
|
69 |
}
|
70 |
async function onPrompt(e: CustomEvent) {
|
|
|
134 |
$isLoading = false;
|
135 |
return;
|
136 |
case 'estimation':
|
137 |
+
const { rank, queue_size } = data;
|
138 |
$loadingState = `On queue ${rank}/${queue_size}`;
|
139 |
break;
|
140 |
case 'process_generating':
|
|
|
178 |
}
|
179 |
};
|
180 |
}
|
|
|
|
|
181 |
</script>
|
182 |
|
183 |
<!-- Show the current user's cursor location -->
|
|
|
189 |
<PromptModal on:prompt={onPrompt} on:close={onClose} />
|
190 |
{/if}
|
191 |
<div class="fixed top-0 left-0 z-0 w-screen h-screen">
|
192 |
+
<Canvas bind:value={canvasEl} />
|
193 |
|
194 |
<main class="z-10 relative">
|
195 |
<PaintFrame transform={$currZoomTransform} />
|
196 |
|
197 |
{#if promptImgList && $showFrames}
|
198 |
+
{#each promptImgList as promptImg}
|
199 |
<Frame
|
200 |
color={COLORS[0]}
|
201 |
transform={$currZoomTransform}
|
frontend/src/lib/Canvas.svelte
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<script lang="ts">
|
2 |
-
import { zoom
|
3 |
import { select } from 'd3-selection';
|
4 |
import { onMount } from 'svelte';
|
5 |
import { PUBLIC_UPLOADS } from '$env/static/public';
|
@@ -17,7 +17,6 @@
|
|
17 |
|
18 |
let canvasEl: HTMLCanvasElement;
|
19 |
export { canvasEl as value };
|
20 |
-
let value = canvasEl;
|
21 |
|
22 |
let containerEl: HTMLDivElement;
|
23 |
let canvasCtx: CanvasRenderingContext2D;
|
@@ -69,19 +68,20 @@
|
|
69 |
canvasCtx = canvasEl.getContext('2d') as CanvasRenderingContext2D;
|
70 |
});
|
71 |
|
|
|
|
|
|
|
|
|
|
|
72 |
function renderImages(promptImgList: PromptImgObject[]) {
|
73 |
Promise.all(
|
74 |
promptImgList.map(
|
75 |
({ imgURL, position, id }) =>
|
76 |
-
new Promise((resolve) => {
|
77 |
const img = new Image();
|
78 |
img.crossOrigin = 'anonymous';
|
79 |
img.onload = () => {
|
80 |
-
const res = { img, position, id }
|
81 |
-
img: HTMLImageElement;
|
82 |
-
position: { x: number; y: number };
|
83 |
-
id: string;
|
84 |
-
};
|
85 |
canvasCtx.drawImage(img, position.x, position.y, img.width, img.height);
|
86 |
resolve(res);
|
87 |
};
|
@@ -106,8 +106,8 @@
|
|
106 |
// Update cursor presence to current pointer location
|
107 |
function handlePointerMove(event: PointerEvent) {
|
108 |
event.preventDefault();
|
109 |
-
const x = round($currZoomTransform.invertX(event.
|
110 |
-
const y = round($currZoomTransform.invertY(event.
|
111 |
|
112 |
myPresence.update({
|
113 |
cursor: {
|
@@ -125,7 +125,10 @@
|
|
125 |
}
|
126 |
</script>
|
127 |
|
128 |
-
<div
|
|
|
|
|
|
|
129 |
<canvas bind:this={canvasEl} {width} {height} class="absolute top-0 left-0 bg-white" />
|
130 |
<slot />
|
131 |
</div>
|
|
|
1 |
<script lang="ts">
|
2 |
+
import { zoom } from 'd3-zoom';
|
3 |
import { select } from 'd3-selection';
|
4 |
import { onMount } from 'svelte';
|
5 |
import { PUBLIC_UPLOADS } from '$env/static/public';
|
|
|
17 |
|
18 |
let canvasEl: HTMLCanvasElement;
|
19 |
export { canvasEl as value };
|
|
|
20 |
|
21 |
let containerEl: HTMLDivElement;
|
22 |
let canvasCtx: CanvasRenderingContext2D;
|
|
|
68 |
canvasCtx = canvasEl.getContext('2d') as CanvasRenderingContext2D;
|
69 |
});
|
70 |
|
71 |
+
type ImageRendered = {
|
72 |
+
img: HTMLImageElement;
|
73 |
+
position: { x: number; y: number };
|
74 |
+
id: string;
|
75 |
+
};
|
76 |
function renderImages(promptImgList: PromptImgObject[]) {
|
77 |
Promise.all(
|
78 |
promptImgList.map(
|
79 |
({ imgURL, position, id }) =>
|
80 |
+
new Promise<ImageRendered>((resolve) => {
|
81 |
const img = new Image();
|
82 |
img.crossOrigin = 'anonymous';
|
83 |
img.onload = () => {
|
84 |
+
const res: ImageRendered = { img, position, id };
|
|
|
|
|
|
|
|
|
85 |
canvasCtx.drawImage(img, position.x, position.y, img.width, img.height);
|
86 |
resolve(res);
|
87 |
};
|
|
|
106 |
// Update cursor presence to current pointer location
|
107 |
function handlePointerMove(event: PointerEvent) {
|
108 |
event.preventDefault();
|
109 |
+
const x = round($currZoomTransform.invertX(event.clientX));
|
110 |
+
const y = round($currZoomTransform.invertY(event.clientY));
|
111 |
|
112 |
myPresence.update({
|
113 |
cursor: {
|
|
|
125 |
}
|
126 |
</script>
|
127 |
|
128 |
+
<div
|
129 |
+
bind:this={containerEl}
|
130 |
+
class="absolute top-0 left-0 right-0 bottom-0 overflow-hidden z-0 bg-gray-800"
|
131 |
+
>
|
132 |
<canvas bind:this={canvasEl} {width} {height} class="absolute top-0 left-0 bg-white" />
|
133 |
<slot />
|
134 |
</div>
|
frontend/src/lib/Cursor.svelte
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
|
4 |
export let transform: ZoomTransform;
|
5 |
export let color = '';
|
6 |
-
export let emoji;
|
7 |
export let position = { x: 0, y: 0 };
|
8 |
|
9 |
$: coord = {
|
|
|
3 |
|
4 |
export let transform: ZoomTransform;
|
5 |
export let color = '';
|
6 |
+
export let emoji: string;
|
7 |
export let position = { x: 0, y: 0 };
|
8 |
|
9 |
$: coord = {
|
frontend/src/lib/PaintFrame.svelte
CHANGED
@@ -23,13 +23,11 @@
|
|
23 |
};
|
24 |
|
25 |
onMount(() => {
|
26 |
-
function dragstarted(event
|
27 |
-
|
28 |
}
|
29 |
|
30 |
-
function dragged(event:
|
31 |
-
console.log(event.sourceEvent.layerX);
|
32 |
-
const grid = 20;
|
33 |
const x = round(transform.invertX(event.x) - 512 / 2);
|
34 |
const y = round(transform.invertY(event.y) - 512 / 2);
|
35 |
position = {
|
@@ -38,13 +36,12 @@
|
|
38 |
};
|
39 |
}
|
40 |
|
41 |
-
function dragended(event
|
42 |
-
|
43 |
}
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
);
|
48 |
});
|
49 |
</script>
|
50 |
|
@@ -60,7 +57,7 @@
|
|
60 |
<LoadingIcon />
|
61 |
<h2 class="text-lg">Click to paint</h2>
|
62 |
|
63 |
-
<div class="absolute bottom-0 font-bold">{prompt}
|
64 |
</div>
|
65 |
|
66 |
<style lang="postcss" scoped>
|
|
|
23 |
};
|
24 |
|
25 |
onMount(() => {
|
26 |
+
function dragstarted(event: Event) {
|
27 |
+
console.log(event);
|
28 |
}
|
29 |
|
30 |
+
function dragged(event: Event) {
|
|
|
|
|
31 |
const x = round(transform.invertX(event.x) - 512 / 2);
|
32 |
const y = round(transform.invertY(event.y) - 512 / 2);
|
33 |
position = {
|
|
|
36 |
};
|
37 |
}
|
38 |
|
39 |
+
function dragended(event: Event) {
|
40 |
+
console.log(event);
|
41 |
}
|
42 |
|
43 |
+
const dragHandler = drag().on('start', dragstarted).on('drag', dragged).on('end', dragended);
|
44 |
+
select(frameElement).call(dragHandler as any);
|
|
|
45 |
});
|
46 |
</script>
|
47 |
|
|
|
57 |
<LoadingIcon />
|
58 |
<h2 class="text-lg">Click to paint</h2>
|
59 |
|
60 |
+
<div class="absolute bottom-0 font-bold">{prompt}</div>
|
61 |
</div>
|
62 |
|
63 |
<style lang="postcss" scoped>
|
frontend/src/lib/PromptModal.svelte
CHANGED
@@ -48,9 +48,6 @@
|
|
48 |
</form>
|
49 |
|
50 |
<style lang="postcss" scoped>
|
51 |
-
.link {
|
52 |
-
@apply text-xs underline font-bold hover:no-underline hover:text-gray-500 visited:text-gray-500;
|
53 |
-
}
|
54 |
.input {
|
55 |
@apply w-full max-w-sm text-sm disabled:opacity-50 italic placeholder:text-white text-white placeholder:text-opacity-50 bg-slate-900 border-2 border-white rounded-2xl px-2 shadow-sm focus:outline-none focus:border-gray-400 focus:ring-1;
|
56 |
}
|
|
|
48 |
</form>
|
49 |
|
50 |
<style lang="postcss" scoped>
|
|
|
|
|
|
|
51 |
.input {
|
52 |
@apply w-full max-w-sm text-sm disabled:opacity-50 italic placeholder:text-white text-white placeholder:text-opacity-50 bg-slate-900 border-2 border-white rounded-2xl px-2 shadow-sm focus:outline-none focus:border-gray-400 focus:ring-1;
|
53 |
}
|
frontend/src/lib/liveblocks/RoomProvider.svelte
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
https://liveblocks.io/docs/api-reference/liveblocks-react#RoomProvider
|
4 |
-->
|
5 |
<script lang="ts">
|
|
|
6 |
import { clientSymbol, roomSymbol } from "./symbols";
|
7 |
import type { Client, Room } from "@liveblocks/client";
|
8 |
import { getContext, onDestroy, setContext } from "svelte";
|
|
|
3 |
https://liveblocks.io/docs/api-reference/liveblocks-react#RoomProvider
|
4 |
-->
|
5 |
<script lang="ts">
|
6 |
+
// @ts-nocheck
|
7 |
import { clientSymbol, roomSymbol } from "./symbols";
|
8 |
import type { Client, Room } from "@liveblocks/client";
|
9 |
import { getContext, onDestroy, setContext } from "svelte";
|
frontend/src/lib/liveblocks/useBatch.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import { useRoom } from "./useRoom";
|
2 |
|
3 |
/**
|
|
|
1 |
+
// @ts-nocheck
|
2 |
import { useRoom } from "./useRoom";
|
3 |
|
4 |
/**
|
frontend/src/lib/liveblocks/useHistory.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
/**
|
2 |
* Works similarly to `liveblocks-react` useHistory
|
3 |
* https://liveblocks.io/docs/api-reference/liveblocks-react#useHistory
|
|
|
1 |
+
// @ts-nocheck
|
2 |
/**
|
3 |
* Works similarly to `liveblocks-react` useHistory
|
4 |
* https://liveblocks.io/docs/api-reference/liveblocks-react#useHistory
|
frontend/src/lib/liveblocks/useList.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import { LiveList } from "@liveblocks/client";
|
2 |
import { useStorage } from "./useStorage";
|
3 |
import { onDestroy } from "svelte";
|
|
|
1 |
+
// @ts-nocheck
|
2 |
import { LiveList } from "@liveblocks/client";
|
3 |
import { useStorage } from "./useStorage";
|
4 |
import { onDestroy } from "svelte";
|
frontend/src/lib/liveblocks/useMyPresence.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import type { Presence } from "@liveblocks/client";
|
2 |
import { onDestroy } from "svelte";
|
3 |
import { writable } from "svelte/store";
|
|
|
1 |
+
// @ts-nocheck
|
2 |
import type { Presence } from "@liveblocks/client";
|
3 |
import { onDestroy } from "svelte";
|
4 |
import { writable } from "svelte/store";
|
frontend/src/lib/liveblocks/useObject.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import { LiveObject } from "@liveblocks/client";
|
2 |
import { useStorage } from "./useStorage";
|
3 |
import { onDestroy } from "svelte";
|
|
|
1 |
+
// @ts-nocheck
|
2 |
import { LiveObject } from "@liveblocks/client";
|
3 |
import { useStorage } from "./useStorage";
|
4 |
import { onDestroy } from "svelte";
|
frontend/src/lib/liveblocks/useOthers.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import type { Others } from "@liveblocks/client";
|
2 |
import { onDestroy } from "svelte";
|
3 |
import type { Writable } from "svelte/store";
|
|
|
1 |
+
// @ts-nocheck
|
2 |
import type { Others } from "@liveblocks/client";
|
3 |
import { onDestroy } from "svelte";
|
4 |
import type { Writable } from "svelte/store";
|
frontend/src/lib/liveblocks/useRoom.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import { getContext } from "svelte";
|
2 |
import type { Room } from "@liveblocks/client";
|
3 |
import { roomSymbol } from "./symbols";
|
|
|
1 |
+
// @ts-nocheck
|
2 |
import { getContext } from "svelte";
|
3 |
import type { Room } from "@liveblocks/client";
|
4 |
import { roomSymbol } from "./symbols";
|
frontend/src/lib/liveblocks/useStorage.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import type { LiveObject } from "@liveblocks/client";
|
2 |
import type { Writable } from "svelte/store";
|
3 |
import { writable } from "svelte/store";
|
|
|
1 |
+
// @ts-nocheck
|
2 |
import type { LiveObject } from "@liveblocks/client";
|
3 |
import type { Writable } from "svelte/store";
|
4 |
import { writable } from "svelte/store";
|
frontend/src/lib/utils.ts
CHANGED
@@ -1,9 +1,5 @@
|
|
1 |
import { dev } from '$app/environment';
|
2 |
|
3 |
-
export function randomSeed() {
|
4 |
-
return BigInt(13248873089935215612 & (((1 << 63) - 1) * Math.random()));
|
5 |
-
}
|
6 |
-
|
7 |
export function base64ToBlob(base64image: string): Promise<Blob> {
|
8 |
return new Promise((resolve) => {
|
9 |
const img = new Image();
|
@@ -16,15 +12,15 @@ export function base64ToBlob(base64image: string): Promise<Blob> {
|
|
16 |
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
|
17 |
ctx.drawImage(img, 0, 0, w, h);
|
18 |
|
19 |
-
const imgBlob: Blob = await new Promise((
|
20 |
-
canvas.toBlob(
|
21 |
);
|
22 |
resolve(imgBlob);
|
23 |
};
|
24 |
img.src = base64image;
|
25 |
});
|
26 |
}
|
27 |
-
export async function uploadImage(imagBlob: Blob, prompt: string): string {
|
28 |
// simple regex slugify string for file name
|
29 |
const promptSlug = slugify(prompt);
|
30 |
const UPLOAD_URL = dev ? 'moon/uploads' : 'https://huggingface.co/uploads';
|
|
|
1 |
import { dev } from '$app/environment';
|
2 |
|
|
|
|
|
|
|
|
|
3 |
export function base64ToBlob(base64image: string): Promise<Blob> {
|
4 |
return new Promise((resolve) => {
|
5 |
const img = new Image();
|
|
|
12 |
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
|
13 |
ctx.drawImage(img, 0, 0, w, h);
|
14 |
|
15 |
+
const imgBlob: Blob = await new Promise((r) =>
|
16 |
+
canvas.toBlob(r as BlobCallback, 'image/jpeg', 0.95)
|
17 |
);
|
18 |
resolve(imgBlob);
|
19 |
};
|
20 |
img.src = base64image;
|
21 |
});
|
22 |
}
|
23 |
+
export async function uploadImage(imagBlob: Blob, prompt: string): Promise<string> {
|
24 |
// simple regex slugify string for file name
|
25 |
const promptSlug = slugify(prompt);
|
26 |
const UPLOAD_URL = dev ? 'moon/uploads' : 'https://huggingface.co/uploads';
|