Commit Graph

117 Commits

Author SHA1 Message Date
Dariusz L
b89956d2ba Refactor code style and remove mask editor examples
This commit applies consistent code style changes (mainly spacing and formatting) across multiple JS files for improved readability and maintainability. Additionally, it removes the unused 'js/examples/mask_editor_examples.js' file.
2025-07-01 06:44:26 +02:00
Dariusz L
a0ceb3b97c Remove auto mask loading docs and clean up code comments
Deleted documentation files related to automatic mask loading. Cleaned up and streamlined comments across Canvas.js, CanvasInteractions.js, CanvasLayers.js, CanvasView.js, MaskTool.js, mask_utils.js, and example scripts for improved clarity and maintainability. No functional changes to core logic.
2025-07-01 06:42:20 +02:00
Dariusz L
30fb89451f Refactor canvas preview visibility and widget loading
Refactored Canvas.js to use an async waitForWidget method for reliably finding widgets before manipulating them. The setPreviewVisibility method is now async and simplified, with excessive debug logging removed. CanvasState.js now triggers a render after saving state. In CanvasView.js, initial state loading is deferred and preview visibility is managed in the Canvas constructor, removing redundant calls.
2025-07-01 06:32:06 +02:00
Dariusz L
40c1dbfb5d Add show/hide preview option for canvas image preview
Introduces a new 'show_preview' boolean option to CanvasNode and UI, allowing users to toggle the visibility of the canvas image preview widget. Updates Canvas.js with a setPreviewVisibility method to control the preview's display and size, and hooks this logic into CanvasView.js to respond to the new option. Adds detailed debug logging for widget state and size changes.
2025-07-01 05:09:48 +02:00
Dariusz L
688acd72fd Add cancel support to mask editor with state restore
Implemented logic in Canvas.js to save and restore mask state when the mask editor is cancelled. Added robust detection and event listener setup for the cancel button in mask_utils.js, including multiple selector strategies and fallback mechanisms. This improves user experience by allowing users to revert changes if they cancel out of the mask editor.
2025-06-30 22:57:06 +02:00
Dariusz L
acef58291c Add automatic mask loading to mask editor
Introduces functionality for automatically applying predefined masks in the ComfyUI mask editor. Adds new API methods and utilities in Canvas.js and mask_utils.js, including support for sending a clean image, handling both new and old mask editors, and flexible mask formats. Includes documentation, usage examples, and helper functions for mask processing and error handling.
2025-06-30 21:52:40 +02:00
Dariusz L
8a800a4bee Replace MaskEditor menu option with custom handler
Removes the default 'Open in MaskEditor' option from the menu and adds a new custom option with improved error handling and logging. This ensures the MaskEditor is opened through a controlled callback, providing better user feedback in case of errors.
2025-06-30 01:49:06 +02:00
Dariusz L
2624cf02a2 Add clipboard source toggle for paste operations
Introduces a clipboardPreference setting to choose between system clipboard and ComfyUI Clipspace as the source for paste operations in CanvasLayers. Adds a UI button in CanvasView to toggle the clipboard source, improving user control over paste behavior.
2025-06-30 01:14:13 +02:00
Dariusz L
62a5af4287 Enhance paste functionality and clipboard handling
Improves the paste operation in CanvasLayers to prioritize internal clipboard, then ComfyUI Clipspace, and finally the system clipboard, pasting images at the mouse position. Also clears the internal clipboard when the mouse leaves the canvas in CanvasInteractions.
2025-06-30 00:35:25 +02:00
Dariusz L
2eaa3d6620 Improve mask editor integration and mask application logic
Replaces the mask editor's image preparation to use a new method that combines the full image with the current mask, ensuring the editor starts with the correct state. Updates mask application logic to fully replace the mask area instead of blending, and refactors mask extraction and application in CanvasLayers for consistency and correctness, including a new getFlattenedCanvasForMaskEditor method.
2025-06-29 23:16:22 +02:00
Dariusz L
abb0f8ef53 Add export of canvas with mask as alpha channel
Introduces a new method to export the flattened canvas with the mask applied as the alpha channel. Updates UI actions to allow previewing, copying, and saving the image with mask alpha, and ensures node previews use the new export method. This enhances workflows that require the mask to be embedded as transparency in the output image.
2025-06-29 21:26:53 +02:00
Dariusz L
0bb54a0a6d Refactor image layer addition to use addLayer method
Replaces manual image layer creation with calls to canvas.addLayer, passing options and addMode. This streamlines image addition logic and ensures consistent handling of layer properties.
2025-06-29 20:56:58 +02:00
Dariusz L
8efb9d91b0 Remove legacy delegating methods from Canvas.js
Removed all remaining delegating methods from Canvas.js, including handleMouseMove and garbage collection helpers, as part of finalizing the refactor to a pure facade. Updated REFACTORING_GUIDE.md to reflect the completion of this refactor and clarify the new architecture.
2025-06-29 20:43:02 +02:00
Dariusz L
0b3bdaf769 Remove CanvasLayers delegation methods from Canvas.js
Eliminated 14 delegation methods to CanvasLayers from Canvas.js. Updated all relevant calls in CanvasRenderer.js, CanvasIO.js, and CanvasInteractions.js to use canvas.canvasLayers directly. This streamlines the Canvas class to only expose core facade operations and necessary helpers.
2025-06-29 20:39:31 +02:00
Dariusz L
1bb4909438 Remove CanvasState delegating methods from Canvas
Removed delegating methods to CanvasState from Canvas.js and updated all references to use canvas.canvasState directly for state operations (undo, redo, saveStateToDB). Updated CanvasInteractions.js, CanvasIO.js, CanvasLayers.js, and CanvasView.js accordingly. Updated REFACTORING_GUIDE.md to reflect the completion of this refactor.
2025-06-29 14:11:34 +02:00
Dariusz L
fd611c5777 Refactor CanvasLayers to use consistent canvas reference
Renamed the CanvasLayers constructor parameter from 'canvasLayers' to 'canvas' and updated all internal references accordingly for clarity and consistency. Adjusted CanvasView.js to call layer operations via canvas.canvasLayers. Updated REFACTORING_GUIDE.md to document these architectural changes and ensure all modules follow a unified naming convention.
2025-06-29 13:57:53 +02:00
Dariusz L
22627b7532 Delegate layer resize and rotate to CanvasLayers
Moved the resizeLayer and rotateLayer logic from Canvas.js to CanvasLayers.js, improving modularity and consistency. Updated REFACTORING_GUIDE.md to reflect these changes and document the current architecture and status.
2025-06-29 13:47:08 +02:00
Dariusz L
b4a662b036 Refactor CanvasView.js to use new Canvas facade modules
Updated all CanvasView.js method calls to use the new modular structure (canvasIO, canvasLayers, imageReferenceManager) as part of the Canvas facade refactor. Updated REFACTORING_GUIDE.md to reflect completed migration, document new usage patterns, and outline next steps. This improves code clarity and modularity while maintaining backward compatibility.
2025-06-29 13:42:52 +02:00
Dariusz L
d50a0443c3 Set default log level to DEBUG and add refactoring guide
Changed the default log level from NONE to DEBUG in both canvas_node.py and LoggerUtils.js to improve logging visibility during development. Added js/REFACTORING_GUIDE.md with detailed documentation on the recent Canvas module refactor, outlining architectural changes, migration instructions, and developer notes.
2025-06-29 04:44:08 +02:00
Dariusz L
9dcf38b36d Refactor Canvas class as facade and clean up CanvasLayers
Refactored the Canvas class to act as a facade, providing a simplified high-level interface and delegating detailed operations to internal modules. Added Polish documentation, grouped and clarified main operations, and moved legacy/delegation methods to the end for backward compatibility. Removed unused or redundant methods from CanvasLayers.js, such as removeLayer, moveLayer, addMattedLayer, isRotationHandle, getResizeHandle, handleBlendModeSelection, and getFlattenedCanvasAsDataURL, to streamline the codebase.
2025-06-29 04:41:48 +02:00
Dariusz L
7a7c8f2295 Add mask editor integration to canvas workflow
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.
2025-06-29 04:15:45 +02:00
Dariusz L
f6a491e83b Adjust text background height and padding in CanvasRenderer
Refines the calculation of text background height and vertical padding for multi-line text rendering, ensuring more consistent spacing and alignment.
2025-06-28 19:56:13 +02:00
Dariusz L
7a52be5a79 Show original image size in layer info overlay
Added originalWidth and originalHeight properties to layers in CanvasLayers.js. Updated CanvasRenderer.js to display the original image dimensions in the layer info overlay if available, and improved overlay rendering to support multiline text.
2025-06-28 19:54:34 +02:00
Dariusz L
4376a21147 Add 'fit on add' option for image placement
Introduces a 'fit_on_add' boolean option to control whether images are fit to the canvas when added or pasted. Updates image addition and paste logic in Canvas, CanvasLayers, and CanvasView to support new placement modes ('fit', 'center', 'mouse', 'default').
2025-06-28 19:48:57 +02:00
Dariusz L
8ead4176b5 Add paste mode to handlePaste for image positioning
The handlePaste method now accepts a pasteMode parameter to control image placement, allowing images to be pasted either at the mouse position or centered on the canvas. This improves user control when pasting images via keyboard shortcuts or UI buttons.
2025-06-28 19:30:24 +02:00
Dariusz L
81b2a9cc4e Remove redundant white background fill in CanvasIO
Eliminated unnecessary code that filled temporary canvases with a white background in two methods. This streamlines canvas creation and avoids redundant operations.
2025-06-28 09:44:43 +02:00
Dariusz L
2033ab168a Set default log level to NONE and remove logger docs
Changed the default log level for both Python and JavaScript module loggers from DEBUG to NONE to disable logging by default. Removed the README_LOGGER.md documentation file, and updated README.md to remove a reference to seamless integration.
2025-06-28 08:38:08 +02:00
Dariusz L
7c3a6f72c7 Defer canvas rendering with setTimeout for UI updates
Replaces direct calls to canvas.render() and node.onResize() with setTimeout to defer execution, ensuring UI updates occur after DOM changes. This helps prevent rendering issues and improves responsiveness when toggling mask controls and editor view.
2025-06-28 08:07:10 +02:00
Dariusz L
51eaac362a Rename brush softness to hardness in mask tool
Replaces all references to 'softness' with 'hardness' for brush controls in both CanvasView.js and MaskTool.js. Updates UI labels, slider IDs, and internal logic to use 'hardness' terminology, clarifying that a higher value means a harder brush edge.
2025-06-28 07:59:32 +02:00
Dariusz L
a1e00ca06a Add brush preview overlay to MaskTool
Introduces a brush preview overlay using a separate preview canvas in MaskTool. Mouse event handlers in CanvasInteractions and MaskTool are updated to support passing both world and view coordinates, enabling accurate brush preview rendering. The preview is shown or hidden appropriately on mouse enter/leave and while drawing.
2025-06-28 07:37:53 +02:00
Dariusz L
940f027b40 Increase logging level to DEBUG and enhance MaskTool callbacks
Set logging level to DEBUG in both Python and JavaScript loggers for improved debugging. Updated MaskTool to accept an onStateChange callback and trigger it after mask state changes, allowing Canvas to respond to mask updates.
2025-06-28 07:28:58 +02:00
Dariusz L
0078faf1fd Set default log level to NONE and improve logger checks
Changed the default log level to LogLevel.NONE in both Python and JavaScript logger utilities. Updated LayerForgeLogger to fully disable logging when the effective level is NONE, ensuring no logs are emitted for disabled modules.
2025-06-28 06:11:12 +02:00
Dariusz L
d783709287 Improve tooltip styling and positioning in CanvasView
Refactors the .painter-tooltip CSS for better appearance, responsiveness, and usability, including new scaling classes, table-based layout, and improved scrollbar styling. Updates shortcut help content to use tables instead of lists for clarity. Enhances tooltip positioning logic to prevent overflow outside the viewport and ensures proper display near screen edges.
2025-06-28 04:01:04 +02:00
Dariusz L
16730cf9a1 Refactor canvas help tooltip for mask mode support
Split help tooltip content into standard and mask mode shortcuts. Tooltip now dynamically displays relevant shortcuts based on whether the mask tool is active, improving user guidance during mask editing.
2025-06-28 03:37:23 +02:00
Dariusz L
092748ef85 Add descriptive titles to canvas control buttons
Added 'title' attributes to various canvas control buttons to provide tooltips with descriptive information about each button's function. This improves accessibility and user experience by clarifying the purpose of each control.
2025-06-28 02:37:58 +02:00
Dariusz L
319cbc1dcb Refactor blend mode menu handling in CanvasLayers
Replaces direct DOM removal with a dedicated closeBlendModeMenu method for consistency. Increases menu z-index for better stacking, and appends the menu to the canvas container if available instead of always using document.body.
2025-06-28 02:33:25 +02:00
Dariusz L
3957aa0f61 Refactor canvas state change handling and layer removal
Replaces the onInteractionEnd callback with onStateChange for more consistent state change notifications. Adds a removeSelectedLayers method to Canvas for cleaner layer removal logic. Updates UI event handlers to use the new methods and callbacks, and ensures state is saved after relevant operations. Cleans up redundant updateOutput calls and streamlines output update logic.
2025-06-28 02:26:06 +02:00
Dariusz L
f76f047fa6 Add onInteractionEnd callback to Canvas
Introduces an optional onInteractionEnd callback to the Canvas class, which is triggered at the end of user interactions. CanvasView now uses this callback to update output after interactions, improving responsiveness to user actions.
2025-06-28 01:35:18 +02:00
Dariusz L
375ed6a2b8 Refactor codebase for consistent formatting and style
This commit applies consistent code formatting across multiple files, including spacing, indentation, and object destructuring. No functional changes were made; the update improves code readability and maintainability.
2025-06-27 07:13:20 +02:00
Dariusz L
b40d645a79 Refactor canvas and mask handling for clarity and maintainability
Removed redundant comments and streamlined logic across canvas-related modules, including mask positioning, garbage collection, and WebSocket communication. Improved code readability and maintainability by eliminating unnecessary explanations and clarifying intent in both Python and JavaScript files. No functional changes were made; this is a cleanup and refactor for better developer experience.
2025-06-27 06:17:24 +02:00
Dariusz L
711722eb9f Revert "Refactor logging and formatting"
This reverts commit 83ce890ef4.
2025-06-27 05:50:47 +02:00
Dariusz L
83ce890ef4 Refactor logging and formatting
Improved code readability
2025-06-27 05:32:11 +02:00
Dariusz L
be4fae2964 Add WebSocket-based RAM output for CanvasNode
Introduces a WebSocket-based mechanism for CanvasNode to send and receive canvas image and mask data in RAM, enabling fast, diskless data transfer between frontend and backend. Adds a new WebSocketManager utility, updates CanvasIO to support RAM output mode, and modifies CanvasView to send canvas data via WebSocket before prompt execution. The backend (canvas_node.py) is updated to handle WebSocket data storage and retrieval, with improved locking and cleanup logic. This change improves workflow speed and reliability by avoiding unnecessary disk I/O and ensuring up-to-date canvas data is available during node execution.
2025-06-27 05:28:13 +02:00
Dariusz L
daf3abeea7 Add world-space positioning and resizing for mask tool
Introduces x/y coordinates to MaskTool for world-space positioning, allowing the mask to extend beyond the output area. Updates mask drawing, export, and rendering logic to account for mask position. Ensures mask position is updated when moving or resizing the canvas, and preserves mask content during canvas resizing. Improves mask extraction and rendering accuracy.
2025-06-26 22:09:28 +02:00
Dariusz L
f2998f0f08 Bump database version to 3
Incremented the DB_VERSION constant from 2 to 3 in preparation for database schema changes or upgrades.
2025-06-26 20:59:08 +02:00
Dariusz L
3ca0a32a14 Add operation-based auto garbage collection for images
Introduces an operation counter and threshold in ImageReferenceManager to trigger automatic garbage collection after a set number of canvas operations. Canvas now increments the operation count on save, undo, and redo, and exposes methods to set the operation threshold and retrieve stats including operation count. CanvasView displays the operation count and threshold after manual garbage collection.
2025-06-26 19:18:05 +02:00
Dariusz L
48005247fb Update Canvas.js 2025-06-26 18:42:55 +02:00
Dariusz L
a5a3280535 Fix mask canvas sizing to use canvasInstance dimensions
Updated initMaskCanvas to set maskCanvas width and height based on canvasInstance instead of mainCanvas, ensuring correct sizing.
2025-06-26 18:38:24 +02:00
Dariusz L
7d7076cc45 Add image garbage collection to canvas
Introduced ImageReferenceManager to track and clean up unused images from the database and cache. Added manual garbage collection controls to the UI and exposed related stats and cleanup methods in Canvas. Updated db.js with a method to retrieve all image IDs for cleanup purposes.
2025-06-26 18:28:50 +02:00
Dariusz L
dd6a9dfc85 Rename canvas size methods and labels to output area
Refactored method and variable names from 'canvas size' to 'output area size' across multiple files for clarity. Updated UI labels and related function calls to reflect this terminology change.
2025-06-26 18:06:40 +02:00