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:
@@ -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