import{J as y,K as l,E as m,L as S}from"./utils.Bch77dSh.js";const a=[];function w(s,e){return{subscribe:x(s,e).subscribe}}function x(s,e=l){let t=null;const n=new Set;function u(i){if(S(s,i)&&(s=i,t)){const o=!a.length;for(const r of n)r[1](),a.push(r,s);if(o){for(let r=0;r<a.length;r+=2)a[r][0](a[r+1]);a.length=0}}}function f(i){u(i(s))}function b(i,o=l){const r=[i,o];return n.add(r),n.size===1&&(t=e(u,f)||l),i(s),()=>{n.delete(r),n.size===0&&t&&(t(),t=null)}}return{set:u,update:f,subscribe:b}}function v(s,e,t){const n=!Array.isArray(s),u=n?[s]:s;if(!u.every(Boolean))throw new Error("derived() expects stores as input, got a falsy value");const f=e.length<2;return w(t,(b,i)=>{let o=!1;const r=[];let d=0,p=l;const g=()=>{if(d)return;p();const c=e(n?r[0]:r,b,i);f?b(c):p=typeof c=="function"?c:l},_=u.map((c,h)=>y(c,E=>{r[h]=E,d&=~(1<<h),o&&g()},()=>{d|=1<<h}));return o=!0,g(),function(){m(_),p(),o=!1}})}function z(s){return{subscribe:s.subscribe.bind(s)}}function A(s){let e;return y(s,t=>e=t)(),e}class H{constructor(e,t){this.status=e,typeof t=="string"?this.body={message:t}:t?this.body=t:this.body={message:`Error: ${e}`}}toString(){return JSON.stringify(this.body)}}class J{constructor(e,t){this.status=e,this.location=t}}class K extends Error{constructor(e,t,n){super(n),this.status=e,this.text=t}}export{H,J as R,K as S,v as d,A as g,z as r,x as w};
