Rename CanvasMask to MaskEditorIntegration

Renamed the CanvasMask class and file to MaskEditorIntegration for improved clarity and consistency. Updated all references in Canvas and SAMDetectorIntegration to use the new name.
This commit is contained in:
Dariusz L
2025-07-27 17:39:13 +02:00
parent 0d6bfb01d6
commit 4019a8a88f
6 changed files with 489 additions and 19 deletions

View File

@@ -19,7 +19,7 @@ import {ImageReferenceManager} from "./ImageReferenceManager.js";
import {BatchPreviewManager} from "./BatchPreviewManager.js";
import {createModuleLogger} from "./utils/LoggerUtils.js";
import { debounce } from "./utils/CommonUtils.js";
import {CanvasMask} from "./CanvasMask.js";
import {MaskEditorIntegration} from "./MaskEditorIntegration";
import {CanvasSelection} from "./CanvasSelection.js";
import type { ComfyNode, Layer, Viewport, Point, AddMode, Shape, OutputAreaBounds } from './types';
@@ -51,7 +51,7 @@ export class Canvas {
canvasInteractions: CanvasInteractions;
canvasLayers: CanvasLayers;
canvasLayersPanel: CanvasLayersPanel;
canvasMask: CanvasMask;
canvasMask: MaskEditorIntegration;
canvasRenderer: CanvasRenderer;
canvasSelection: CanvasSelection;
canvasState: CanvasState;
@@ -146,7 +146,7 @@ export class Canvas {
this.maskTool = new MaskTool(this, {onStateChange: this.onStateChange});
this.shapeTool = new ShapeTool(this);
this.customShapeMenu = new CustomShapeMenu(this);
this.canvasMask = new CanvasMask(this);
this.canvasMask = new MaskEditorIntegration(this);
this.canvasState = new CanvasState(this);
this.canvasSelection = new CanvasSelection(this);
this.canvasInteractions = new CanvasInteractions(this);

View File

@@ -7,9 +7,9 @@ import {api} from "../../scripts/api.js";
import { createModuleLogger } from "./utils/LoggerUtils.js";
import { mask_editor_showing, mask_editor_listen_for_cancel } from "./utils/mask_utils.js";
const log = createModuleLogger('CanvasMask');
const log = createModuleLogger('MaskEditorIntegration');
export class CanvasMask {
export class MaskEditorIntegration {
canvas: any;
editorWasShowing: any;
maskEditorCancelled: any;

View File

@@ -269,7 +269,7 @@ function monitorSAMDetectorChanges(node: ComfyNode) {
setTimeout(checkForChanges, 500);
}
// Function to handle SAM Detector result (using same logic as CanvasMask.handleMaskEditorClose)
// Function to handle SAM Detector result (using same logic as MaskEditorIntegration.handleMaskEditorClose)
async function handleSAMDetectorResult(node: ComfyNode, resultImage: HTMLImageElement) {
try {
log.info("Handling SAM Detector result for node", node.id);
@@ -283,7 +283,7 @@ async function handleSAMDetectorResult(node: ComfyNode, resultImage: HTMLImageEl
const canvas = canvasWidget; // canvasWidget is the Canvas object, not canvasWidget.canvas
// Wait for the result image to load (same as CanvasMask)
// Wait for the result image to load (same as MaskEditorIntegration)
try {
// First check if the image is already loaded
if (resultImage.complete && resultImage.naturalWidth > 0) {
@@ -360,7 +360,7 @@ async function handleSAMDetectorResult(node: ComfyNode, resultImage: HTMLImageEl
const imageData = tempCtx.getImageData(0, 0, tempCanvas.width, tempCanvas.height);
const data = imageData.data;
// Convert to mask format (same as CanvasMask)
// Convert to mask format (same as MaskEditorIntegration)
for (let i = 0; i < data.length; i += 4) {
const originalAlpha = data[i + 3];
data[i] = 255;
@@ -372,7 +372,7 @@ async function handleSAMDetectorResult(node: ComfyNode, resultImage: HTMLImageEl
tempCtx.putImageData(imageData, 0, 0);
}
// Convert processed mask to image (same as CanvasMask)
// Convert processed mask to image (same as MaskEditorIntegration)
log.debug("Converting processed mask to image");
const maskAsImage = new Image();
maskAsImage.src = tempCanvas.toDataURL();
@@ -401,11 +401,11 @@ async function handleSAMDetectorResult(node: ComfyNode, resultImage: HTMLImageEl
// Use the addMask method which overlays on existing mask without clearing it
canvas.maskTool.addMask(maskAsImage);
// Update canvas and save state (same as CanvasMask)
// Update canvas and save state (same as MaskEditorIntegration)
canvas.render();
canvas.saveState();
// Create new preview image (same as CanvasMask)
// Create new preview image (same as MaskEditorIntegration)
log.debug("Creating new preview image");
const new_preview = new Image();
const blob = await canvas.canvasLayers.getFlattenedCanvasWithMaskAsBlob();