- Implemented ComfyGenerateRequest type and associated functions for generating images using various architectures and modes. - Added functions for listing generation options and handling image uploads. - Created workflows for different generation modes including SDXL, Z-Image, Z-Image Turbo, and Anima. - Introduced GenerationJobStatus component to display the status of ongoing generation jobs. - Developed MaskControls for managing mask operations and displaying mask analysis. - Created palette items for tool selection, layer management, and generation settings.
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { commandIds } from "@commands/ids";
|
|
import type { AppStore } from "@editor/store";
|
|
import type { BrowserImageFile } from "@platform/browser/imageFiles";
|
|
|
|
export function importImageAsLayer(store: AppStore, image: BrowserImageFile): boolean {
|
|
const state = store.getState();
|
|
const artboard = state.editor.selection.artboardId
|
|
? state.document.artboards.find((candidate) => candidate.id === state.editor.selection.artboardId)
|
|
: state.document.artboards[0];
|
|
if (!artboard) {
|
|
image.release();
|
|
return false;
|
|
}
|
|
|
|
const assetId = crypto.randomUUID();
|
|
const layerId = crypto.randomUUID();
|
|
const center = state.editor.viewport.center;
|
|
store.dispatch(commandIds.documentAddAsset, { asset: { id: assetId, name: image.name, mimeType: image.mimeType, source: image.source, intrinsicSize: image.intrinsicSize } });
|
|
store.dispatch(commandIds.documentAddImageLayer, {
|
|
artboardId: artboard.id,
|
|
layer: {
|
|
id: layerId,
|
|
type: "image",
|
|
name: image.name,
|
|
visible: true,
|
|
locked: false,
|
|
opacity: 1,
|
|
assetId,
|
|
transform: { position: { x: center.x - image.intrinsicSize.w / 2, y: center.y - image.intrinsicSize.h / 2 }, scale: { x: 1, y: 1 }, rotation: 0 },
|
|
},
|
|
});
|
|
store.dispatch(commandIds.selectionSet, { artboardId: artboard.id, layerIds: [layerId] });
|
|
return true;
|
|
}
|