import{n as f,z as w,r as m,s as q,C as z}from"./scheduler.48e626f5.js";const a=[];function x(e,i){return{subscribe:A(e,i).subscribe}}function A(e,i=f){let n;const r=new Set;function u(t){if(q(e,t)&&(e=t,n)){const o=!a.length;for(const s of r)s[1](),a.push(s,e);if(o){for(let s=0;s<a.length;s+=2)a[s][0](a[s+1]);a.length=0}}}function l(t){u(t(e))}function b(t,o=f){const s=[t,o];return r.add(s),r.size===1&&(n=i(u,l)||f),t(e),()=>{r.delete(s),r.size===0&&n&&(n(),n=null)}}return{set:u,update:l,subscribe:b}}function C(e,i,n){const r=!Array.isArray(e),u=r?[e]:e;if(!u.every(Boolean))throw new Error("derived() expects stores as input, got a falsy value");const l=i.length<2;return x(n,(b,t)=>{let o=!1;const s=[];let d=0,p=f;const h=()=>{if(d)return;p();const c=i(r?s[0]:s,b,t);l?b(c):p=z(c)?c:f},y=u.map((c,g)=>w(c,_=>{s[g]=_,d&=~(1<<g),o&&h()},()=>{d|=1<<g}));return o=!0,h(),function(){m(y),p(),o=!1}})}export{C as d,x as r,A as w};
