export function createPlugin(a){const b=new Map;return{use(c){let d=this.get(c.key);if(d)return d;let e=c(a)||{};return b.set(c,e),e},get(a){let c=Array.from(b.keys()).find(b=>b.key===a);return c?b.get(c):void 0},has(a){let b=this.get(a);return!!b},remove(a){const c=a=>{b.has(a)&&(a.dispose(),b.delete(a))};if("string"!=typeof a)return void c(a);let d=b.keys();for(let b of d)b.key===a&&c(b)},clear(){let a=b.keys();for(let b of a)b.dispose();b.clear()}}}export default function createMetaMethods(a){const b=createPlugin(a),c=a.dispose;return Object.defineProperties(a,{plugin:{value:b},search:{get:()=>(b,c)=>{let d=a.component;return d?d.type===b?[d].concat(d.search(b,c)):d.search(b,c):[]}},get:{get:()=>(b,c)=>{let d=a.component;return d?d.modelId===b||d.id===b?d:d.get(b,c):void 0}},filter:{get:()=>(b,c)=>{let d=a.component;return d?b(d)?[d].concat(d.filter(b,c)):d.filter(b,c):[]}},add:{get:()=>async b=>{let c=a.component;c?await c.add(b):a.component=b}},remove:{get:()=>async a=>{await a.removeFromParent()}},dispose:{get:()=>async()=>{b.clear(),"function"==typeof c&&(await c.call(a))}}}),a}