Spaces:
Runtime error
Runtime error
fix constrains
Browse files
frontend/src/lib/Buttons/PPButton.svelte
CHANGED
@@ -24,6 +24,6 @@
|
|
24 |
@apply disabled:opacity-50 dark:bg-white dark:text-black bg-black text-white rounded-2xl text-xs shadow-sm focus:outline-none focus:border-gray-400;
|
25 |
} */
|
26 |
.button-paint {
|
27 |
-
@apply text-
|
28 |
}
|
29 |
</style>
|
|
|
24 |
@apply disabled:opacity-50 dark:bg-white dark:text-black bg-black text-white rounded-2xl text-xs shadow-sm focus:outline-none focus:border-gray-400;
|
25 |
} */
|
26 |
.button-paint {
|
27 |
+
@apply text-base font-mono bg-violet-100 text-violet-900 min-w-[25ch] flex justify-center items-center disabled:opacity-80 dark:bg-white dark:text-black rounded-2xl px-3 py-1 shadow-sm focus:outline-none focus:border-gray-400;
|
28 |
}
|
29 |
</style>
|
frontend/src/lib/Icons/Mask.svelte
CHANGED
@@ -4,8 +4,8 @@
|
|
4 |
|
5 |
<svg
|
6 |
class={classList}
|
7 |
-
width="
|
8 |
-
height="
|
9 |
viewBox="0 0 11 11"
|
10 |
fill="none"
|
11 |
xmlns="http://www.w3.org/2000/svg"
|
|
|
4 |
|
5 |
<svg
|
6 |
class={classList}
|
7 |
+
width="40"
|
8 |
+
height="40"
|
9 |
viewBox="0 0 11 11"
|
10 |
fill="none"
|
11 |
xmlns="http://www.w3.org/2000/svg"
|
frontend/src/lib/Icons/Move.svelte
CHANGED
@@ -4,8 +4,8 @@
|
|
4 |
|
5 |
<svg
|
6 |
class={classList}
|
7 |
-
width="
|
8 |
-
height="
|
9 |
viewBox="0 0 11 11"
|
10 |
fill="none"
|
11 |
xmlns="http://www.w3.org/2000/svg"
|
|
|
4 |
|
5 |
<svg
|
6 |
class={classList}
|
7 |
+
width="40"
|
8 |
+
height="40"
|
9 |
viewBox="0 0 11 11"
|
10 |
fill="none"
|
11 |
xmlns="http://www.w3.org/2000/svg"
|
frontend/src/lib/Icons/Undo.svelte
CHANGED
@@ -4,8 +4,8 @@
|
|
4 |
|
5 |
<svg
|
6 |
class={classList}
|
7 |
-
width="
|
8 |
-
height="
|
9 |
viewBox="0 0 10 9"
|
10 |
fill="none"
|
11 |
xmlns="http://www.w3.org/2000/svg"
|
|
|
4 |
|
5 |
<svg
|
6 |
class={classList}
|
7 |
+
width="40"
|
8 |
+
height="29"
|
9 |
viewBox="0 0 10 9"
|
10 |
fill="none"
|
11 |
xmlns="http://www.w3.org/2000/svg"
|
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,
|
57 |
maskCtx.restore();
|
58 |
}
|
59 |
function drawLine(points: { x: number; y: number; lastx: number; lasty: number }) {
|
@@ -211,12 +211,18 @@
|
|
211 |
</div>
|
212 |
{/if}
|
213 |
{#if !isDragging}
|
214 |
-
<div
|
|
|
|
|
|
|
215 |
<div class="py-3">
|
216 |
<PPButton {isLoading} on:click={() => dispatch('prompt')} />
|
217 |
</div>
|
218 |
</div>
|
219 |
-
<div
|
|
|
|
|
|
|
220 |
<div class="mx-4">
|
221 |
<DragButton
|
222 |
className={'p-1'}
|
@@ -225,10 +231,15 @@
|
|
225 |
on:click={toggleDrag}
|
226 |
/>
|
227 |
<div class="flex bg-white rounded-full mt-3 shadow-lg">
|
228 |
-
<MaskButton
|
|
|
|
|
|
|
|
|
|
|
229 |
{#if !dragEnabled}
|
230 |
<span class="border-gray-800 border-opacity-50 border-r-2 my-2" />
|
231 |
-
<UndoButton className={'p-1
|
232 |
{/if}
|
233 |
</div>
|
234 |
</div>
|
|
|
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 }) {
|
|
|
211 |
</div>
|
212 |
{/if}
|
213 |
{#if !isDragging}
|
214 |
+
<div
|
215 |
+
class="absolute top-full"
|
216 |
+
style={`transform: scale(${Math.max(2 - transform.k, 1)}); transform-origin: 0 0;`}
|
217 |
+
>
|
218 |
<div class="py-3">
|
219 |
<PPButton {isLoading} on:click={() => dispatch('prompt')} />
|
220 |
</div>
|
221 |
</div>
|
222 |
+
<div
|
223 |
+
class="absolute left-full"
|
224 |
+
style={`transform: scale(${Math.max(2 - transform.k, 1)}); transform-origin: 0 0;`}
|
225 |
+
>
|
226 |
<div class="mx-4">
|
227 |
<DragButton
|
228 |
className={'p-1'}
|
|
|
231 |
on:click={toggleDrag}
|
232 |
/>
|
233 |
<div class="flex bg-white rounded-full mt-3 shadow-lg">
|
234 |
+
<MaskButton
|
235 |
+
{isLoading}
|
236 |
+
className={'p-1'}
|
237 |
+
isActive={!dragEnabled}
|
238 |
+
on:click={toggleDrawMask}
|
239 |
+
/>
|
240 |
{#if !dragEnabled}
|
241 |
<span class="border-gray-800 border-opacity-50 border-r-2 my-2" />
|
242 |
+
<UndoButton className={'p-1'} {isLoading} on:click={cleanMask} />
|
243 |
{/if}
|
244 |
</div>
|
245 |
</div>
|
frontend/src/lib/utils.ts
CHANGED
@@ -45,12 +45,14 @@ export async function uploadImage(imagBlob: Blob, prompt: string): Promise<strin
|
|
45 |
console.log('uploaded images', url);
|
46 |
return url;
|
47 |
}
|
|
|
48 |
|
49 |
export function round(pos: number, size = 32) {
|
50 |
-
const value =
|
51 |
-
return Math.round(value)
|
52 |
}
|
53 |
|
|
|
54 |
function slugify(text: string) {
|
55 |
if (!text) return '';
|
56 |
return text
|
|
|
45 |
console.log('uploaded images', url);
|
46 |
return url;
|
47 |
}
|
48 |
+
const MAX = 512 * 5 - 512
|
49 |
|
50 |
export function round(pos: number, size = 32) {
|
51 |
+
const value = pos % size < size / 2 ? pos - (pos % size) : pos + size - (pos % size);
|
52 |
+
return Math.max(0, Math.min(Math.round(value), MAX))
|
53 |
}
|
54 |
|
55 |
+
|
56 |
function slugify(text: string) {
|
57 |
if (!text) return '';
|
58 |
return text
|