import{a as m,e as v}from"./index.3whys8t3.js";const c=5,a=6,d=10;let T=(e,s,i,u)=>(e.events=e.events||{},e.events[i+d]||(e.events[i+d]=u(t=>{e.events[i].reduceRight((f,l)=>(l(f),f),{shared:{},...t})})),e.events[i]=e.events[i]||[],e.events[i].push(s),()=>{let t=e.events[i],f=t.indexOf(s);t.splice(f,1),t.length||(delete e.events[i],e.events[i+d](),delete e.events[i+d])}),O=1e3,N=(e,s)=>T(e,u=>{let t=s(u);t&&e.events[a].push(t)},c,u=>{let t=e.listen;e.listen=(...l)=>(!e.lc&&!e.active&&(e.active=!0,u()),t(...l));let f=e.off;return e.events[a]=[],e.off=()=>{f(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let l of e.events[a])l();e.events[a]=[]}},O)},()=>{e.listen=t,e.off=f}}),U=(e,s,i)=>{Array.isArray(e)||(e=[e]);let u,t,f=()=>{if(t===v)return;t=v;let r=e.map(n=>n.get());if(!u||r.some((n,p)=>n!==u[p])){u=r;let n=s(...r);n&&n.then&&n.t?n.then(p=>{u===r&&l.set(p)}):(l.set(n),t=v)}},l=m(void 0),g=l.get;l.get=()=>(f(),g());let h=f;return N(l,()=>{let r=e.map(n=>n.listen(h));return f(),()=>{for(let n of r)n()}}),l},E=(e,s)=>U(e,s);export{E as c};
