"use strict";(self["webpackChunkaida"]=self["webpackChunkaida"]||[]).push([[2511],{82511:function(e,s,t){t.r(s),t.d(s,{BrushRegistry:function(){return r},brushRegistry:function(){return i}});class r{constructor(){this.brushes=new Map,this.brushesByCategory=new Map,this.listeners={register:[],unregister:[]}}register(e,s,t={}){if(this.brushes.has(e))return console.warn(`笔刷 ${e} 已存在，请使用其他ID`),!1;const r={id:e,class:s,metadata:{...t,id:e}};this.brushes.set(e,r);const i=t.category||"默认";return this.brushesByCategory.has(i)||this.brushesByCategory.set(i,[]),this.brushesByCategory.get(i).push(r),this._triggerEvent("register",r),!0}unregister(e){if(!this.brushes.has(e))return!1;const s=this.brushes.get(e);this.brushes.delete(e);const t=s.metadata.category||"默认";if(this.brushesByCategory.has(t)){const s=this.brushesByCategory.get(t),r=s.findIndex((s=>s.id===e));-1!==r&&s.splice(r,1),0===s.length&&this.brushesByCategory.delete(t)}return this._triggerEvent("unregister",s),!0}getBrush(e){return this.brushes.get(e)||null}getAllBrushes(){return Array.from(this.brushes.values())}getBrushesByCategory(e){return this.brushesByCategory.get(e)||[]}getCategories(){return Array.from(this.brushesByCategory.keys())}createBrushInstance(e,s,t={}){const r=this.getBrush(e);if(!r)return console.error(`笔刷 ${e} 不存在`),null;try{return new r.class(s,{...t,id:r.id,...r.metadata})}catch(i){return console.error(`创建笔刷 ${e} 失败:`,i),null}}addEventListener(e,s){this.listeners[e]&&this.listeners[e].push(s)}removeEventListener(e,s){if(this.listeners[e]){const t=this.listeners[e].indexOf(s);-1!==t&&this.listeners[e].splice(t,1)}}_triggerEvent(e,s){this.listeners[e]&&this.listeners[e].forEach((t=>{try{t(s)}catch(r){console.error(`执行 ${e} 事件监听器出错:`,r)}}))}}const i=new r;s["default"]=i}}]);