mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-22 05:02:11 -03:00
Introduces the ability to open the current canvas in a mask editor, upload and retrieve mask edits, and apply them to the mask layer. Adds utility functions for mask editor state detection and control, a new 'Edit Mask' button in the UI, and methods for handling mask updates and preview refresh. Also adds a setMask method to MaskTool for precise mask placement.
44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
export function new_editor(app) {
|
|
if (!app) return false;
|
|
return app.ui.settings.getSettingValue('Comfy.MaskEditor.UseNewEditor')
|
|
}
|
|
|
|
function get_mask_editor_element(app) {
|
|
return new_editor(app) ? document.getElementById('maskEditor') : document.getElementById('maskCanvas')?.parentElement
|
|
}
|
|
|
|
export function mask_editor_showing(app) {
|
|
const editor = get_mask_editor_element(app);
|
|
return editor && editor.style.display !== "none";
|
|
}
|
|
|
|
export function hide_mask_editor() {
|
|
if (mask_editor_showing()) document.getElementById('maskEditor').style.display = 'none'
|
|
}
|
|
|
|
function get_mask_editor_cancel_button(app) {
|
|
if (document.getElementById("maskEditor_topBarCancelButton")) return document.getElementById("maskEditor_topBarCancelButton")
|
|
return get_mask_editor_element(app)?.parentElement?.lastChild?.childNodes[2]
|
|
}
|
|
|
|
function get_mask_editor_save_button(app) {
|
|
if (document.getElementById("maskEditor_topBarSaveButton")) return document.getElementById("maskEditor_topBarSaveButton")
|
|
return get_mask_editor_element(app)?.parentElement?.lastChild?.childNodes[2]
|
|
}
|
|
|
|
export function mask_editor_listen_for_cancel(app, callback) {
|
|
const cancel_button = get_mask_editor_cancel_button(app);
|
|
if (cancel_button && !cancel_button.filter_listener_added) {
|
|
cancel_button.addEventListener('click', callback);
|
|
cancel_button.filter_listener_added = true;
|
|
}
|
|
}
|
|
|
|
export function press_maskeditor_save(app) {
|
|
get_mask_editor_save_button(app)?.click()
|
|
}
|
|
|
|
export function press_maskeditor_cancel(app) {
|
|
get_mask_editor_cancel_button(app)?.click()
|
|
}
|