feat: add ComfyUI integration for image generation
- Implemented ComfyUI API for generating images with various modes (text-to-image, image-to-image, inpaint, outpaint). - Created GenerateSheet and associated controls for user input on generation settings. - Added subtle scrollbar styles for improved UI experience. - Enhanced canvas input handling to ignore key events when focused on editable elements. - Optimized canvas resizing logic to prevent unnecessary dispatches. - Introduced error handling for generation failures and loading models. - Added functionality to upload images and masks for inpainting.
This commit is contained in:
@@ -72,6 +72,8 @@ export function useCanvasInput(
|
||||
};
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (isEditableKeyboardTarget(event.target)) return;
|
||||
|
||||
const consumed = panHandler.keyDown(keybindEventFromKeyboardEvent(event));
|
||||
if (consumed) {
|
||||
clearBrushPreview();
|
||||
@@ -80,6 +82,8 @@ export function useCanvasInput(
|
||||
};
|
||||
|
||||
const handleKeyUp = (event: KeyboardEvent) => {
|
||||
if (isEditableKeyboardTarget(event.target)) return;
|
||||
|
||||
const consumed = panHandler.keyUp(keybindEventFromKeyboardEvent(event));
|
||||
if (consumed) event.preventDefault();
|
||||
};
|
||||
@@ -236,6 +240,13 @@ export function useCanvasInput(
|
||||
return { isPanning };
|
||||
}
|
||||
|
||||
function isEditableKeyboardTarget(target: EventTarget | null) {
|
||||
return (
|
||||
target instanceof HTMLElement &&
|
||||
(target.isContentEditable || target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement)
|
||||
);
|
||||
}
|
||||
|
||||
function pointInsideCanvas(point: { x: number; y: number }, canvas: HTMLCanvasElement) {
|
||||
return point.x >= 0 && point.y >= 0 && point.x <= canvas.width && point.y <= canvas.height;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,34 @@
|
||||
import { useEffect, type RefObject } from "react";
|
||||
import { useEffect, useRef, type RefObject } from "react";
|
||||
import type { Dispatch } from "@commands/dispatcher";
|
||||
import { commandIds } from "@commands/ids";
|
||||
|
||||
export function useCanvasResize(canvasRef: RefObject<HTMLCanvasElement | null>, dispatch: Dispatch) {
|
||||
const lastSize = useRef<{ w: number; h: number }>();
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas) return;
|
||||
|
||||
let animationFrame: number | undefined;
|
||||
|
||||
const resizeObserver = new ResizeObserver(([entry]) => {
|
||||
if (!entry) return;
|
||||
|
||||
const width = Math.floor(entry.contentRect.width);
|
||||
const height = Math.floor(entry.contentRect.height);
|
||||
dispatch(commandIds.viewportSetSize, { w: width, h: height });
|
||||
if (lastSize.current?.w === width && lastSize.current.h === height) return;
|
||||
|
||||
if (animationFrame !== undefined) cancelAnimationFrame(animationFrame);
|
||||
animationFrame = requestAnimationFrame(() => {
|
||||
lastSize.current = { w: width, h: height };
|
||||
dispatch(commandIds.viewportSetSize, { w: width, h: height });
|
||||
});
|
||||
});
|
||||
|
||||
resizeObserver.observe(canvas);
|
||||
return () => resizeObserver.disconnect();
|
||||
return () => {
|
||||
if (animationFrame !== undefined) cancelAnimationFrame(animationFrame);
|
||||
resizeObserver.disconnect();
|
||||
};
|
||||
}, [canvasRef, dispatch]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user