Spaces:
Runtime error
Runtime error
cleanup
Browse filesFiles changed (3)
38 unmodified lines39404142434440 unmodified lines85868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316472 unmodified lines23723823924024124222 unmodified lines2652662672682692702715 unmodified lines27727827928028128228328428528628728828929038 unmodified linesisPrompting: false,currentPrompt: ''});function getKey({ position }: PromptImgObject): PromptImgKey {return `${position.x}_${position.y}`;}40 unmodified linesreturn base64Crop;}function getImageMask(cursor: { x: number; y: number }) {const tempCanvas = document.createElement('canvas');const canvasCrop = document.createElement('canvas');const mask = document.createElement('canvas');tempCanvas.width = 512;tempCanvas.height = 512;canvasCrop.width = 512;canvasCrop.height = 512;mask.width = 512;mask.height = 512;const tempCanvasCtx = tempCanvas.getContext('2d') as CanvasRenderingContext2D;const ctxCrop = canvasCrop.getContext('2d') as CanvasRenderingContext2D;const ctxMask = mask.getContext('2d') as CanvasRenderingContext2D;// crop image from point canvasctxCrop.save();ctxCrop.clearRect(0, 0, 512, 512);ctxCrop.globalCompositeOperation = 'source-over';ctxCrop.drawImage(canvasEl, cursor.x, cursor.y, 512, 512, 0, 0, 512, 512);ctxCrop.restore();// create black imagetempCanvasCtx.fillStyle = 'white';tempCanvasCtx.fillRect(0, 0, 512, 512);// create MaskctxMask.save();// ctxMask.clearRect(0, 0, 512, 512);ctxMask.drawImage(canvasCrop, 0, 0, 512, 512);ctxMask.globalCompositeOperation = 'source-out';ctxMask.drawImage(tempCanvas, 0, 0);ctxMask.restore();tempCanvasCtx.save();tempCanvasCtx.fillStyle = 'white';tempCanvasCtx.fillRect(0, 0, 512, 512);//random pixels// tempCanvasCtx.filter = 'blur(4px)';// const imageData = tempCanvasCtx.getImageData(0, 0, 512, 512);// const pix = imageData.data;// for (let i = 0, n = pix.length; i < n; i += 4) {// pix[i] = Math.round(255 * Math.random());// pix[i + 1] = Math.round(255 * Math.random());// pix[i + 2] = Math.round(255 * Math.random());// pix[i + 3] = 255;// }// tempCanvasCtx.putImageData(imageData, 0, 0);tempCanvasCtx.drawImage(canvasCrop, 0, 0, 512, 512);//convert canvas to base64const base64Crop = tempCanvas.toDataURL('image/png');tempCanvasCtx.restore();tempCanvasCtx.save();tempCanvasCtx.fillStyle = 'black';tempCanvasCtx.fillRect(0, 0, 512, 512);tempCanvasCtx.drawImage(mask, 0, 0, 512, 512);//convert canvas to base64const base64Mask = tempCanvas.toDataURL('image/png');tempCanvasCtx.restore();return { image: base64Crop, mask: base64Mask };}async function generateImage(_prompt: string) {// getImageMask($clickedPosition);// return;if (!_prompt || $isLoading == true) return;$loadingState = 'Pending';$isLoading = true;const sessionHash = crypto.randomUUID();const payload = {fn_index: 0,72 unmodified lines};}let modal = false;</script><!-- Show the current user's cursor location -->22 unmodified lines<Frame color={COLORS[0]} position={$clickedPosition} transform={$currZoomTransform} />{/if} -->{#if $myPresence?.cursor}<Frame color={COLORS[0]} position={$myPresence.cursor} transform={$currZoomTransform} /><Cursoremoji={EMOJIS[0]}color={COLORS[0]}5 unmodified lines<!-- When others connected, iterate through others and show their cursors -->{#if $others}{#each [...$others] as { connectionId, presence } (connectionId)}{#if presence?.cursor}<Framecolor={COLORS[1 + (connectionId % (COLORS.length - 1))]}position={presence?.cursor}prompt={presence?.currentPrompt}transform={$currZoomTransform}/><Cursoremoji={EMOJIS[1 + (connectionId % (EMOJIS.length - 1))]}color={COLORS[1 + (connectionId % (COLORS.length - 1))]}38 unmodified lines39404142434445464740 unmodified lines88899091929394959697989910010110272 unmodified lines17517617717817918018122 unmodified lines2042052062072082092105 unmodified lines21621721821922022122222322422522622722822923038 unmodified linesisPrompting: false,currentPrompt: ''});$: {console.log($others)}function getKey({ position }: PromptImgObject): PromptImgKey {return `${position.x}_${position.y}`;}40 unmodified linesreturn base64Crop;}async function generateImage(_prompt: string) {if (!_prompt || $isLoading == true) return;$loadingState = 'Pending';$isLoading = true;myPresence.update({currentPrompt: _prompt,isPrompting: true,cursor: $clickedPosition});const sessionHash = crypto.randomUUID();const payload = {fn_index: 0,72 unmodified lines};}let modal = false;let currentPrompt = '';</script><!-- Show the current user's cursor location -->22 unmodified lines<Frame color={COLORS[0]} position={$clickedPosition} transform={$currZoomTransform} />{/if} -->{#if $myPresence?.cursor}<!-- <Frame color={COLORS[0]} position={$myPresence.cursor} transform={$currZoomTransform} /> --><Cursoremoji={EMOJIS[0]}color={COLORS[0]}5 unmodified lines<!-- When others connected, iterate through others and show their cursors -->{#if $others}{#each [...$others] as { connectionId, presence } (connectionId)}{#if presence?.isPrompting && presence?.cursor}<Framecolor={COLORS[1 + (connectionId % (COLORS.length - 1))]}position={presence?.cursor}prompt={presence?.currentPrompt}transform={$currZoomTransform}/>{/if}{#if presence?.cursor}<Cursoremoji={EMOJIS[1 + (connectionId % (EMOJIS.length - 1))]}color={COLORS[1 + (connectionId % (COLORS.length - 1))]}
127 unmodified lines128129130131132133134135136127 unmodified lines// When the pointer leaves the page, set cursor presence to nullfunction handlePointerLeave() {myPresence.update({cursor: null});}</script>127 unmodified lines128129130131132133134135136127 unmodified lines// When the pointer leaves the page, set cursor presence to nullfunction handlePointerLeave() {// myPresence.update({// cursor: null// });}</script>
1234567891011<script lang="ts">import { createEventDispatcher, onMount } from 'svelte';const dispatch = createEventDispatcher();let prompt: string;const onKeyup = (e: KeyboardEvent) => {if (e.key === 'Escape') {dispatch('close');}};onMount(() => {1234567891011121314151617181920212223242526<script lang="ts">import { createEventDispatcher, onMount } from 'svelte';import { useMyPresence } from '$lib/liveblocks';const dispatch = createEventDispatcher();let prompt: string;const myPresence = useMyPresence();$: {myPresence.update({currentPrompt: prompt,isPrompting: true});}const onKeyup = (e: KeyboardEvent) => {if (e.key === 'Escape') {dispatch('close');myPresence.update({currentPrompt: '',isPrompting: false});}};onMount(() => {
frontend/src/lib/App.svelte+13-73
frontend/src/lib/Canvas.svelte+3-3
frontend/src/lib/PromptModal.svelte+15