import { FillGroupLayerBackgroundCommand } from "../commands/FillGroupLayerBackgroundCommand"; import { FillLayerBackgroundCommand } from "../commands/FillLayerBackgroundCommand"; export class BackgroundFillManager { constructor({ canvas, layers, commandManager, canvasManager, layerManager }) { this.canvas = canvas; this.layers = layers; this.commandManager = commandManager; this.canvasManager = canvasManager; this.layerManager = layerManager; } /** * 填充指定图层背景 * @param {string} layerId 图层ID * @param {string} fillColor 填充颜色 * @param {boolean} undoable 是否可撤销 * @returns {Promise} */ async fillLayerBackground(layerId, fillColor, undoable) { if (!layerId || !fillColor) { console.warn("图层ID或填充颜色不能为空"); return; } const command = new FillGroupLayerBackgroundCommand({ canvas: this.canvas, layers: this.layers, layerId, fillColor, canvasManager: this.canvasManager, layerManager: this.layerManager, // 是否实时更新 isRetimeUpdate: !undoable, }); command.undoable = undoable; if (this.commandManager) { await this.commandManager.execute(command); } else { await command.execute(); } } }