mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-23 13:32:11 -03:00
Refactor canvas creation to use createCanvas utility
Replaces direct usage of document.createElement('canvas') and manual context setup with the createCanvas utility across multiple utility modules. This change improves code consistency, reduces duplication, and centralizes canvas/context creation logic. Also updates notification usage in ClipboardManager to use showNotification and showInfoNotification utilities.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { createModuleLogger } from "./LoggerUtils.js";
|
||||
import { createCanvas } from "./CommonUtils.js";
|
||||
|
||||
const log = createModuleLogger('ImageAnalysis');
|
||||
|
||||
@@ -10,10 +11,7 @@ const log = createModuleLogger('ImageAnalysis');
|
||||
* @returns HTMLCanvasElement containing the distance field mask
|
||||
*/
|
||||
export function createDistanceFieldMask(image: HTMLImageElement, blendArea: number): HTMLCanvasElement {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = image.width;
|
||||
canvas.height = image.height;
|
||||
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
||||
const { canvas, ctx } = createCanvas(image.width, image.height, '2d', { willReadFrequently: true });
|
||||
|
||||
if (!ctx) {
|
||||
log.error('Failed to create canvas context for distance field mask');
|
||||
@@ -217,10 +215,7 @@ function calculateDistanceFromEdges(width: number, height: number): Float32Array
|
||||
* @returns HTMLCanvasElement containing the radial gradient mask
|
||||
*/
|
||||
export function createRadialGradientMask(width: number, height: number, blendArea: number): HTMLCanvasElement {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
const ctx = canvas.getContext('2d');
|
||||
const { canvas, ctx } = createCanvas(width, height);
|
||||
|
||||
if (!ctx) {
|
||||
log.error('Failed to create canvas context for radial gradient mask');
|
||||
|
||||
Reference in New Issue
Block a user