"use strict";(self["webpackChunkaida"]=self["webpackChunkaida"]||[]).push([[4160,3217],{23217:function(t,o,e){e.r(o),e.d(o,{Command:function(){return n},CompositeCommand:function(){return s},FunctionCommand:function(){return r}});e(21703);class n{constructor(t={}){this.name=t.name||"未命名命令",this.description=t.description||"",this.undoable=!1!==t.undoable,this.timestamp=Date.now()}execute(){throw new Error("子类必须实现execute方法")}undo(){if(!this.undoable)throw new Error("此命令不支持撤销");throw new Error("可撤销命令必须实现undo方法")}getInfo(){return{name:this.name,description:this.description,undoable:this.undoable,timestamp:this.timestamp}}}class s extends n{constructor(t=[],o={}){super({name:o.name||"复合命令",description:o.description||"批量执行多个命令",...o}),this.commands=Array.isArray(t)?t:[],this.executedCommands=[],this.isExecuting=!1}addCommand(t){if(!t||"function"!==typeof t.execute)throw new Error("无效的命令对象");return this.commands.push(t),this}addCommands(t){return Array.isArray(t)&&t.forEach((t=>this.addCommand(t))),this}async execute(){if(this.isExecuting)throw new Error("复合命令正在执行中");this.isExecuting=!0,this.executedCommands=[];try{const o=[];for(const e of this.commands)try{console.log(`📦 复合命令执行子命令: ${e.constructor.name}`);const t=e.execute(),n=this._isPromise(t)?await t:t;o.push(n),this.executedCommands.push(e),console.log(`✅ 子命令执行成功: ${e.constructor.name}`)}catch(t){throw console.error(`❌ 子命令执行失败: ${e.constructor.name}`,t),await this._rollbackExecutedCommands(),new Error(`复合命令执行失败：${t.message}`)}return this.isExecuting=!1,console.log(`✅ 复合命令执行完成，共执行 ${o.length} 个子命令`),o}catch(t){throw this.isExecuting=!1,t}}async undo(){if(this.isExecuting)throw new Error("复合命令正在执行中，无法撤销");if(0===this.executedCommands.length)return console.warn("没有已执行的子命令需要撤销"),!0;console.log(`↩️ 开始撤销复合命令，共 ${this.executedCommands.length} 个子命令`);try{const o=[...this.executedCommands].reverse(),e=[];for(const n of o)if("function"===typeof n.undo)try{console.log(`↩️ 撤销子命令: ${n.constructor.name}`);const t=n.undo(),o=this._isPromise(t)?await t:t;e.push(o),console.log(`✅ 子命令撤销成功: ${n.constructor.name}`)}catch(t){console.error(`❌ 子命令撤销失败: ${n.constructor.name}`,t)}else console.warn(`⚠️ 子命令不支持撤销: ${n.constructor.name}`);return this.executedCommands=[],console.log("✅ 复合命令撤销完成"),e}catch(t){throw console.error("❌ 复合命令撤销过程中发生错误:",t),t}}async _rollbackExecutedCommands(){console.log(`🔄 开始回滚已执行的 ${this.executedCommands.length} 个子命令`);const t=[...this.executedCommands].reverse();for(const e of t)if("function"===typeof e.undo)try{console.log(`🔄 回滚子命令: ${e.constructor.name}`);const t=e.undo();this._isPromise(t)&&await t,console.log(`✅ 子命令回滚成功: ${e.constructor.name}`)}catch(o){console.error(`❌ 子命令回滚失败: ${e.constructor.name}`,o)}this.executedCommands=[],console.log("✅ 回滚完成")}_isPromise(t){return t&&"object"===typeof t&&"function"===typeof t.then&&"function"===typeof t.catch}getInfo(){return{...super.getInfo(),commandCount:this.commands.length,executedCount:this.executedCommands.length,isExecuting:this.isExecuting,subCommands:this.commands.map((t=>t.getInfo?t.getInfo():t.constructor.name))}}}class r extends n{constructor(t,o=null,e={}){if(super({name:e.name||"函数命令",undoable:"function"===typeof o,...e}),"function"!==typeof t)throw new Error("执行函数不能为空");this.executeFn=t,this.undoFn=o,this.executeResult=null}async execute(){const t=this.executeFn();return this.executeResult=this._isPromise(t)?await t:t,this.executeResult}async undo(){if(!this.undoFn)throw new Error("此函数命令不支持撤销");const t=this.undoFn(this.executeResult);return this._isPromise(t)?await t:t}_isPromise(t){return t&&"object"===typeof t&&"function"===typeof t.then&&"function"===typeof t.catch}}},74160:function(t,o,e){e.r(o),e.d(o,{ToolCommand:function(){return s}});var n=e(23217);class s extends n.Command{constructor(t){super({...t,name:`切换工具: ${t.tool}`,description:`将工具切换为 ${t.tool}`}),this.toolManager=t.toolManager,this.tool=t.tool,this.previousTool=t.previousTool||null}execute(){return this.toolManager?(this.previousTool||(this.previousTool=this.toolManager.getCurrentTool()),this.toolManager.setTool(this.tool)):null}undo(){return this.toolManager&&this.previousTool?this.toolManager.setTool(this.previousTool):null}}}}]);