mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-21 20:52:12 -03:00
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.
This commit is contained in:
22
js/Canvas.js
22
js/Canvas.js
@@ -470,28 +470,10 @@ export class Canvas {
|
||||
* - this.canvasIO dla operacji I/O
|
||||
* - this.canvasState dla zarządzania stanem
|
||||
*
|
||||
* UWAGA: Metody delegujące do CanvasState zostały usunięte.
|
||||
* Używaj: canvas.canvasState.saveStateToDB(), canvas.canvasState.undo(), etc.
|
||||
* UWAGA: Metody delegujące do CanvasLayers i CanvasState zostały usunięte.
|
||||
* Używaj: canvas.canvasLayers.copySelectedLayers(), canvas.canvasState.undo(), etc.
|
||||
*/
|
||||
|
||||
// Delegacje do CanvasLayers
|
||||
async copySelectedLayers() { return this.canvasLayers.copySelectedLayers(); }
|
||||
async handlePaste(addMode) { return this.canvasLayers.handlePaste(addMode); }
|
||||
async addLayerWithImage(image, layerProps = {}, addMode = 'default') {
|
||||
return this.canvasLayers.addLayerWithImage(image, layerProps, addMode);
|
||||
}
|
||||
moveLayerUp() { return this.canvasLayers.moveLayerUp(); }
|
||||
moveLayerDown() { return this.canvasLayers.moveLayerDown(); }
|
||||
resizeLayer(scale) { return this.canvasLayers.resizeLayer(scale); }
|
||||
rotateLayer(angle) { return this.canvasLayers.rotateLayer(angle); }
|
||||
getLayerAtPosition(worldX, worldY) { return this.canvasLayers.getLayerAtPosition(worldX, worldY); }
|
||||
getHandles(layer) { return this.canvasLayers.getHandles(layer); }
|
||||
getHandleAtPosition(worldX, worldY) { return this.canvasLayers.getHandleAtPosition(worldX, worldY); }
|
||||
async mirrorHorizontal() { return this.canvasLayers.mirrorHorizontal(); }
|
||||
async mirrorVertical() { return this.canvasLayers.mirrorVertical(); }
|
||||
async getLayerImageData(layer) { return this.canvasLayers.getLayerImageData(layer); }
|
||||
showBlendModeMenu(x, y) { return this.canvasLayers.showBlendModeMenu(x, y); }
|
||||
|
||||
// Delegacje do CanvasInteractions
|
||||
handleMouseMove(e) { this.canvasInteractions.handleMouseMove(e); }
|
||||
|
||||
|
||||
@@ -374,7 +374,7 @@ export class CanvasIO {
|
||||
this.canvas.height / inputImage.height * 0.8
|
||||
);
|
||||
|
||||
const layer = await this.canvas.addLayerWithImage(image, {
|
||||
const layer = await this.canvas.canvasLayers.addLayerWithImage(image, {
|
||||
x: (this.canvas.width - inputImage.width * scale) / 2,
|
||||
y: (this.canvas.height - inputImage.height * scale) / 2,
|
||||
width: inputImage.width * scale,
|
||||
@@ -744,7 +744,7 @@ export class CanvasIO {
|
||||
img.src = result.image_data;
|
||||
});
|
||||
|
||||
await this.canvas.addLayerWithImage(img, {
|
||||
await this.canvas.canvasLayers.addLayerWithImage(img, {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: this.canvas.width,
|
||||
|
||||
@@ -86,16 +86,16 @@ export class CanvasInteractions {
|
||||
}
|
||||
this.interaction.lastClickTime = currentTime;
|
||||
|
||||
const transformTarget = this.canvas.getHandleAtPosition(worldCoords.x, worldCoords.y);
|
||||
const transformTarget = this.canvas.canvasLayers.getHandleAtPosition(worldCoords.x, worldCoords.y);
|
||||
if (transformTarget) {
|
||||
this.startLayerTransform(transformTarget.layer, transformTarget.handle, worldCoords);
|
||||
return;
|
||||
}
|
||||
|
||||
const clickedLayerResult = this.canvas.getLayerAtPosition(worldCoords.x, worldCoords.y);
|
||||
const clickedLayerResult = this.canvas.canvasLayers.getLayerAtPosition(worldCoords.x, worldCoords.y);
|
||||
if (clickedLayerResult) {
|
||||
if (e.shiftKey && this.canvas.selectedLayers.includes(clickedLayerResult.layer)) {
|
||||
this.canvas.showBlendModeMenu(e.clientX, e.clientY);
|
||||
this.canvas.canvasLayers.showBlendModeMenu(e.clientX, e.clientY);
|
||||
return;
|
||||
}
|
||||
this.startLayerDrag(clickedLayerResult.layer, worldCoords);
|
||||
@@ -399,7 +399,7 @@ export class CanvasInteractions {
|
||||
}
|
||||
|
||||
updateCursor(worldCoords) {
|
||||
const transformTarget = this.canvas.getHandleAtPosition(worldCoords.x, worldCoords.y);
|
||||
const transformTarget = this.canvas.canvasLayers.getHandleAtPosition(worldCoords.x, worldCoords.y);
|
||||
|
||||
if (transformTarget) {
|
||||
const handleName = transformTarget.handle;
|
||||
@@ -409,7 +409,7 @@ export class CanvasInteractions {
|
||||
'rot': 'grab'
|
||||
};
|
||||
this.canvas.canvas.style.cursor = cursorMap[handleName];
|
||||
} else if (this.canvas.getLayerAtPosition(worldCoords.x, worldCoords.y)) {
|
||||
} else if (this.canvas.canvasLayers.getLayerAtPosition(worldCoords.x, worldCoords.y)) {
|
||||
this.canvas.canvas.style.cursor = 'move';
|
||||
} else {
|
||||
this.canvas.canvas.style.cursor = 'default';
|
||||
@@ -432,7 +432,7 @@ export class CanvasInteractions {
|
||||
} else {
|
||||
this.interaction.mode = 'resizing';
|
||||
this.interaction.resizeHandle = handle;
|
||||
const handles = this.canvas.getHandles(layer);
|
||||
const handles = this.canvas.canvasLayers.getHandles(layer);
|
||||
const oppositeHandleKey = {
|
||||
'n': 's', 's': 'n', 'e': 'w', 'w': 'e',
|
||||
'nw': 'se', 'se': 'nw', 'ne': 'sw', 'sw': 'ne'
|
||||
|
||||
@@ -301,7 +301,7 @@ export class CanvasRenderer {
|
||||
ctx.moveTo(0, -layer.height / 2);
|
||||
ctx.lineTo(0, -layer.height / 2 - 20 / this.canvas.viewport.zoom);
|
||||
ctx.stroke();
|
||||
const handles = this.canvas.getHandles(layer);
|
||||
const handles = this.canvas.canvasLayers.getHandles(layer);
|
||||
ctx.fillStyle = '#ffffff';
|
||||
ctx.strokeStyle = '#000000';
|
||||
ctx.lineWidth = 1 / this.canvas.viewport.zoom;
|
||||
|
||||
@@ -175,6 +175,12 @@ canvas.imageReferenceManager.manualGarbageCollection()
|
||||
- Zaktualizowano wywołania w CanvasLayers.js i CanvasIO.js
|
||||
- Wszystkie operacje na stanie używają teraz bezpośrednio modułu `canvasState`
|
||||
|
||||
5. **Usunięcie metod delegujących do CanvasLayers** ✅
|
||||
- Usunięto 14 metod delegujących do CanvasLayers z Canvas.js
|
||||
- Zaktualizowano wszystkie wywołania w CanvasRenderer.js, CanvasIO.js i CanvasInteractions.js
|
||||
- Wszystkie operacje na warstwach używają teraz bezpośrednio modułu `canvasLayers`
|
||||
- Canvas.js zawiera teraz tylko główne operacje fasady i niezbędne metody pomocnicze
|
||||
|
||||
## Uwagi dla deweloperów
|
||||
|
||||
- ✅ **Refaktoryzacja zakończona** - wszystkie pliki zostały zaktualizowane
|
||||
|
||||
Reference in New Issue
Block a user