(function(u,i){typeof exports=="object"&&typeof module<"u"?module.exports=i():typeof define=="function"&&define.amd?define(i):(u=typeof globalThis<"u"?globalThis:u||self,u.signal=i())})(this,function(){"use strict";const u=n=>function e(...t){return t.length>=n.length?n(...t):(...s)=>e(...t,...s)},i=n=>n&&n.constructor===o,T=n=>n.every(e=>e.value!==void 0),b=n=>n.some(e=>e.updated===!0),L=n=>n.sources.map(e=>e.value),a=(n,e)=>e===void 0||n.equals(n.value,e)?!1:(n.value=e,!0),h=n=>T(n.sources)?n.fn(...L(n)):void 0,y=(n,e,t)=>{e.add(t);for(let s=t.sinks.length-1;s>=0;s--){const r=t.sinks[s];e.has(r)||y(n,e,r)}return n.push(t),n},O=(n,e)=>{if(!a(n,e))return n;const s=y([],new Set,n);s.forEach(r=>r.updated=!1),n.updated=!0;for(let r=s.length-2;r>=0;r--){const f=s[r];b(f.sources)&&(f.updated=a(f,h(f)))}return n},v=Object.is,c=u((n,e,t={})=>{if(e=(Array.isArray(e)?e:[e]).filter(Boolean),n){if(e.length===0)throw new TypeError('"inputs" is empty array');if(e.some(r=>!i(r)))throw new TypeError('"inputs" contains non-signal or falsy value')}else throw new TypeError('"fn" is undefined');const s=(...r)=>{if(r.length===0)return s.value;throw new TypeError("read-only signal")};return s.equals=t.equals??v,s.fn=n,s.sources=e,s.sinks=[],s.stale=0,s.value=h(s),e.forEach(r=>r.sinks.push(s)),o(s)}),k=u((n,e)=>c((t,s)=>t(s),[n,e])),d=(n,e={})=>{const t=(...s)=>s.length===0?t.value:O(t,...s);return t.equals=e.equals??v,t.stale=0,t.value=n,t.sinks=[],o(t)},W=(n,e)=>{const t=n.sinks.indexOf(e);n.sinks.splice(t,1),n.dispose&&n.dispose()},l=u((n,e)=>{const t=c(n,e);return()=>W(e,t)}),E=u((n,e)=>{let t;const s=d();return c(r=>{t&&t();const f=n(r);t=i(f)&&l(s,f)},[e]),s}),w=u((n,e)=>{const t=d();return c(s=>n(s)&&t(s),e),t}),S=u((n,e)=>c(t=>n(t),e)),o=n=>(n.map=e=>S(e,n),n.filter=e=>w(e,n),n.ap=e=>k(e,n),n.chain=e=>E(e,n),n.on=e=>l(e,n),n.pipe=e=>e(n),n.constructor=o,n["fantasy-land/map"]=n.map,n["fantasy-land/filter"]=n.filter,n["fantasy-land/ap"]=n.ap,n["fantasy-land/chain"]=n.chain,n.toString=()=>`Signal(${n.value})`,n.toJSON=()=>n.value,n),j=u((n,e)=>{const t=(e.addEventListener||e.on).bind(e),s=(e.removeEventListener||e.off).bind(e),r=d(),f=p=>t(p,r),z=p=>s(p,r);return n.forEach(f),r.dispose=()=>n.forEach(z),r}),A=(n,...e)=>c((...t)=>n(...t),e),B=u((n,e,t)=>c(s=>{const[r,f]=n(e,s);return e=r,f},t)),J=u((n,e)=>{const t=d();return c(t,n),c(t,e),t}),N=u((n,e,t)=>c(s=>e=n(e,s),t)),X=u((n,e)=>{const t=typeof n=="function"?n():n,s=d(t);return c(s,e),s}),$=u((n,e)=>c(t=>(n(t),t),e));function q(n){this.f=n}q.prototype["@@transducer/step"]=(n,e)=>e;const x=u((n,e)=>(n=n(new q(n)),c(t=>n["@@transducer/step"](void 0,t),[e])));return o.of=o["fantasy-land/of"]=d,o.link=c,o.map=S,o.filter=w,o.ap=k,o.chain=E,o.on=l,o.isSignal=i,o.fromListeners=j,o.lift=A,o.loop=B,o.merge=J,o.scan=N,o.startWith=X,o.tap=$,o.transduce=x,o}); //# sourceMappingURL=signal.umd.cjs.map