@fluixi/reactive 1.0.0-alpha.83 → 1.0.0-alpha.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/dist/cdn/reactive.cjs +2673 -1
  2. package/dist/cdn/reactive.global.js +2 -1
  3. package/dist/cdn/reactive.mjs +2657 -1
  4. package/dist/cdn/signal.cjs +299 -1
  5. package/dist/cdn/signal.d.ts +1 -1
  6. package/dist/cdn/signal.global.js +2 -1
  7. package/dist/cdn/signal.js +1 -1
  8. package/dist/cdn/signal.mjs +276 -1
  9. package/dist/index.cjs +2673 -1
  10. package/dist/index.mjs +2657 -1
  11. package/dist/lib/index.cjs +2674 -1
  12. package/dist/lib/index.js +1 -1
  13. package/dist/lib/index.mjs +2659 -1
  14. package/dist/lib/observable/index.cjs +386 -1
  15. package/dist/lib/observable/index.mjs +364 -1
  16. package/dist/lib/observable/observable.cjs +384 -1
  17. package/dist/lib/observable/observable.d.ts +0 -137
  18. package/dist/lib/observable/observable.d.ts.map +1 -1
  19. package/dist/lib/observable/observable.js +0 -71
  20. package/dist/lib/observable/observable.mjs +361 -1
  21. package/dist/lib/observable/subscription.cjs +180 -1
  22. package/dist/lib/observable/subscription.d.ts +0 -12
  23. package/dist/lib/observable/subscription.d.ts.map +1 -1
  24. package/dist/lib/observable/subscription.js +0 -12
  25. package/dist/lib/observable/subscription.mjs +157 -1
  26. package/dist/lib/observable/types.cjs +18 -1
  27. package/dist/lib/observable/types.d.ts.map +1 -1
  28. package/dist/lib/predicates.cjs +44 -1
  29. package/dist/lib/predicates.d.ts +2 -2
  30. package/dist/lib/predicates.js +2 -2
  31. package/dist/lib/predicates.mjs +23 -1
  32. package/dist/lib/signal/api.cjs +571 -1
  33. package/dist/lib/signal/api.d.ts +211 -1
  34. package/dist/lib/signal/api.d.ts.map +1 -1
  35. package/dist/lib/signal/api.js +207 -12
  36. package/dist/lib/signal/api.mjs +548 -1
  37. package/dist/lib/signal/cached-resource.cjs +672 -1
  38. package/dist/lib/signal/cached-resource.d.ts +28 -16
  39. package/dist/lib/signal/cached-resource.d.ts.map +1 -1
  40. package/dist/lib/signal/cached-resource.js +35 -29
  41. package/dist/lib/signal/cached-resource.mjs +650 -1
  42. package/dist/lib/signal/graph/children.cjs +325 -1
  43. package/dist/lib/signal/graph/children.js +1 -1
  44. package/dist/lib/signal/graph/children.mjs +302 -1
  45. package/dist/lib/signal/graph/compat.cjs +578 -1
  46. package/dist/lib/signal/graph/compat.d.ts +13 -13
  47. package/dist/lib/signal/graph/compat.d.ts.map +1 -1
  48. package/dist/lib/signal/graph/compat.js +33 -31
  49. package/dist/lib/signal/graph/compat.mjs +556 -1
  50. package/dist/lib/signal/graph/core.cjs +295 -1
  51. package/dist/lib/signal/graph/core.d.ts +28 -24
  52. package/dist/lib/signal/graph/core.d.ts.map +1 -1
  53. package/dist/lib/signal/graph/core.js +38 -31
  54. package/dist/lib/signal/graph/core.mjs +273 -1
  55. package/dist/lib/signal/graph/debounced.cjs +668 -1
  56. package/dist/lib/signal/graph/debounced.d.ts +5 -5
  57. package/dist/lib/signal/graph/debounced.d.ts.map +1 -1
  58. package/dist/lib/signal/graph/debounced.js +5 -5
  59. package/dist/lib/signal/graph/debounced.mjs +645 -1
  60. package/dist/lib/signal/graph/derived.cjs +496 -1
  61. package/dist/lib/signal/graph/derived.d.ts +1 -1
  62. package/dist/lib/signal/graph/derived.js +1 -1
  63. package/dist/lib/signal/graph/derived.mjs +473 -1
  64. package/dist/lib/signal/graph/detect.cjs +66 -1
  65. package/dist/lib/signal/graph/detect.mjs +45 -1
  66. package/dist/lib/signal/graph/error-boundary.cjs +301 -1
  67. package/dist/lib/signal/graph/error-boundary.js +3 -3
  68. package/dist/lib/signal/graph/error-boundary.mjs +278 -1
  69. package/dist/lib/signal/graph/index.cjs +305 -1
  70. package/dist/lib/signal/graph/index.d.ts +7 -6
  71. package/dist/lib/signal/graph/index.d.ts.map +1 -1
  72. package/dist/lib/signal/graph/index.js +7 -6
  73. package/dist/lib/signal/graph/index.mjs +283 -1
  74. package/dist/lib/signal/graph/observe.cjs +163 -1
  75. package/dist/lib/signal/graph/observe.d.ts +8 -8
  76. package/dist/lib/signal/graph/observe.js +5 -5
  77. package/dist/lib/signal/graph/observe.mjs +140 -1
  78. package/dist/lib/signal/graph/resource.cjs +620 -1
  79. package/dist/lib/signal/graph/resource.d.ts +1 -1
  80. package/dist/lib/signal/graph/resource.js +7 -8
  81. package/dist/lib/signal/graph/resource.mjs +597 -1
  82. package/dist/lib/signal/graph/runtime.cjs +501 -1
  83. package/dist/lib/signal/graph/runtime.d.ts +7 -7
  84. package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
  85. package/dist/lib/signal/graph/runtime.js +34 -30
  86. package/dist/lib/signal/graph/runtime.mjs +478 -1
  87. package/dist/lib/signal/graph/signal-next.cjs +1208 -1
  88. package/dist/lib/signal/graph/signal-next.d.ts +5 -5
  89. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
  90. package/dist/lib/signal/graph/signal-next.js +14 -12
  91. package/dist/lib/signal/graph/signal-next.mjs +1186 -1
  92. package/dist/lib/signal/graph/ssr-hooks.cjs +60 -1
  93. package/dist/lib/signal/graph/ssr-hooks.d.ts +6 -7
  94. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
  95. package/dist/lib/signal/graph/ssr-hooks.js +6 -7
  96. package/dist/lib/signal/graph/ssr-hooks.mjs +39 -1
  97. package/dist/lib/signal/graph/state.cjs +72 -1
  98. package/dist/lib/signal/graph/state.d.ts +41 -10
  99. package/dist/lib/signal/graph/state.d.ts.map +1 -1
  100. package/dist/lib/signal/graph/state.js +83 -22
  101. package/dist/lib/signal/graph/state.mjs +49 -1
  102. package/dist/lib/signal/graph/suspense.cjs +301 -1
  103. package/dist/lib/signal/graph/suspense.js +4 -4
  104. package/dist/lib/signal/graph/suspense.mjs +278 -1
  105. package/dist/lib/signal/index-legacy.cjs +2540 -1
  106. package/dist/lib/signal/index-legacy.d.ts +1 -1
  107. package/dist/lib/signal/index-legacy.js +1 -1
  108. package/dist/lib/signal/index-legacy.mjs +2518 -1
  109. package/dist/lib/signal/index.cjs +1275 -1
  110. package/dist/lib/signal/index.d.ts +3 -2
  111. package/dist/lib/signal/index.d.ts.map +1 -1
  112. package/dist/lib/signal/index.js +7 -4
  113. package/dist/lib/signal/index.mjs +1253 -1
  114. package/dist/lib/signal/list.cjs +549 -1
  115. package/dist/lib/signal/list.d.ts +5 -5
  116. package/dist/lib/signal/list.js +5 -5
  117. package/dist/lib/signal/list.mjs +526 -1
  118. package/dist/lib/signal/resource-api.cjs +626 -1
  119. package/dist/lib/signal/resource-api.d.ts +5 -5
  120. package/dist/lib/signal/resource-api.js +5 -5
  121. package/dist/lib/signal/resource-api.mjs +603 -1
  122. package/dist/lib/signal/signal.cjs +2023 -1
  123. package/dist/lib/signal/signal.d.ts +4 -4
  124. package/dist/lib/signal/signal.d.ts.map +1 -1
  125. package/dist/lib/signal/signal.js +22 -23
  126. package/dist/lib/signal/signal.mjs +2000 -1
  127. package/dist/lib/signal/types.cjs +38 -1
  128. package/dist/lib/signal/types.d.ts.map +1 -1
  129. package/dist/lib/signal/types.js +2 -2
  130. package/dist/lib/signal/types.mjs +17 -1
  131. package/dist/lib/signal/utilities.cjs +1012 -1
  132. package/dist/lib/signal/utilities.d.ts +0 -108
  133. package/dist/lib/signal/utilities.d.ts.map +1 -1
  134. package/dist/lib/signal/utilities.js +0 -158
  135. package/dist/lib/signal/utilities.mjs +990 -1
  136. package/dist/lib/store/api.cjs +612 -1
  137. package/dist/lib/store/api.d.ts +33 -0
  138. package/dist/lib/store/api.d.ts.map +1 -1
  139. package/dist/lib/store/api.js +41 -8
  140. package/dist/lib/store/api.mjs +596 -1
  141. package/dist/lib/store/index.cjs +691 -1
  142. package/dist/lib/store/index.js +1 -1
  143. package/dist/lib/store/index.mjs +676 -1
  144. package/dist/lib/store/setter.types.cjs +18 -1
  145. package/dist/lib/store/setter.types.d.ts +43 -3
  146. package/dist/lib/store/setter.types.d.ts.map +1 -1
  147. package/dist/lib/store/store.cjs +658 -1
  148. package/dist/lib/store/store.d.ts +72 -0
  149. package/dist/lib/store/store.d.ts.map +1 -1
  150. package/dist/lib/store/store.js +148 -5
  151. package/dist/lib/store/store.mjs +644 -1
  152. package/dist/lib/store/types.cjs +18 -1
  153. package/dist/lib/store/types.d.ts +1 -1
  154. package/dist/lib/store/types.d.ts.map +1 -1
  155. package/dist/lib/store/utils.cjs +43 -1
  156. package/dist/lib/store/utils.d.ts +1 -1
  157. package/dist/lib/store/utils.js +1 -1
  158. package/dist/lib/store/utils.mjs +22 -1
  159. package/dist/lib/subject.cjs +450 -1
  160. package/dist/lib/subject.js +3 -91
  161. package/dist/lib/subject.mjs +427 -1
  162. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  163. package/dist/version.generated.cjs +27 -1
  164. package/dist/version.generated.d.ts +1 -1
  165. package/dist/version.generated.js +2 -2
  166. package/dist/version.generated.mjs +7 -1
  167. package/package.json +5 -4
@@ -1 +1,299 @@
1
- "use strict";var p=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var n in t)p(e,n,{get:t[n],enumerable:!0})},z=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of D(t))!E.call(e,s)&&s!==n&&p(e,s,{get:()=>t[s],enumerable:!(o=q(t,s))||o.enumerable});return e};var K=e=>z(p({},"__esModule",{value:!0}),e);var P={};I(P,{Computed:()=>l,State:()=>d,subtle:()=>L});module.exports=K(P);var G="__fluixi_signal_next_state__",H=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[G]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:H,onSuspend:null,onError:null,observer:null};var w="1.0.0-alpha.83";function j(e){return r.observer=e,()=>{r.observer===e&&(r.observer=null)}}var _=[];function m(e){return r.observer?(_.push(e),!0):!1}function R(){_.pop()}function g(e){r.observer?.ran?.(e)}function y(e,t){r.observer?.wrote?.(e,t)}var F="__FLUIXI_DEVTOOLS_HOOK__",k=globalThis[F];if(typeof k?.inject=="function")try{k.inject({observeReactiveNodes:j,version:w})}catch{}var x=0,T=1,a=2,v=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let t=r.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},d=class extends v{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,y(this,r.consumer),this.observers)for(let n of[...this.observers])n.markDirty(a);b(this)}}peek(){return this._value}},l=class extends v{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=a;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(r.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===T&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===a)break}(this.state===a||!this._initialized)&&this.recompute(),this.state=x}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let n=r.consumer,o=r.untracked,s=m(this);r.consumer=this,r.untracked=!1;let u,c=!1,f;try{u=this._fn()}catch(i){c=!0,f=i,u=this._value}finally{r.consumer=n,r.untracked=o,s&&R()}let C=!this._initialized||this._threw!==c||(c?f!==this._error:!this._equals(this._value,u));if(this._initialized=!0,this._threw=c,this._error=f,this._value=u,g(this),C){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(a);b(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===x;if(this.state=n,o){if(this.observers)for(let s of[...this.observers])s.markDirty(T);b(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function b(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var h=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function S(e){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function O(){return r.consumer}function N(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}var L={Watcher:h,untrack:S,currentComputed:O,hasSinks:N};
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/cdn/signal.ts
21
+ var signal_exports = {};
22
+ __export(signal_exports, {
23
+ Computed: () => Computed,
24
+ State: () => State,
25
+ subtle: () => subtle
26
+ });
27
+ module.exports = __toCommonJS(signal_exports);
28
+
29
+ // src/version.generated.ts
30
+ var VERSION = "1.0.0-alpha.84";
31
+
32
+ // src/lib/signal/graph/state.ts
33
+ var MAJOR = VERSION.split(".")[0];
34
+ var KEY = `__fluixi_signal_state_v${MAJOR}__`;
35
+ var VERSIONS_KEY = `__fluixi_signal_builds_v${MAJOR}__`;
36
+ var defaultSchedule = (run) => {
37
+ if (typeof queueMicrotask === "function") queueMicrotask(run);
38
+ else void Promise.resolve().then(run);
39
+ };
40
+ function defaults() {
41
+ return {
42
+ consumer: null,
43
+ untracked: false,
44
+ owner: null,
45
+ queue: [],
46
+ scheduled: false,
47
+ flushing: false,
48
+ batchDepth: 0,
49
+ hostSchedule: defaultSchedule,
50
+ onSuspend: null,
51
+ onError: null,
52
+ observer: null
53
+ };
54
+ }
55
+ var realm = globalThis;
56
+ function backfillState(existing) {
57
+ const fresh = defaults();
58
+ const target = existing;
59
+ for (const field of Object.keys(fresh)) {
60
+ if (!(field in existing)) target[field] = fresh[field];
61
+ }
62
+ return existing;
63
+ }
64
+ function claim() {
65
+ const existing = realm[KEY];
66
+ return existing ? backfillState(existing) : realm[KEY] = defaults();
67
+ }
68
+ var G = claim();
69
+ (realm[VERSIONS_KEY] ??= []).push(VERSION);
70
+
71
+ // src/lib/signal/graph/observe.ts
72
+ function observeReactiveNodes(next) {
73
+ G.observer = next;
74
+ return () => {
75
+ if (G.observer === next) G.observer = null;
76
+ };
77
+ }
78
+ var running = [];
79
+ function enterReactiveRun(node) {
80
+ if (!G.observer) return false;
81
+ running.push(node);
82
+ return true;
83
+ }
84
+ function exitReactiveRun() {
85
+ running.pop();
86
+ }
87
+ function reportReactiveRun(node) {
88
+ G.observer?.ran?.(node);
89
+ }
90
+ function reportReactiveWrite(node, by) {
91
+ G.observer?.wrote?.(node, by);
92
+ }
93
+ var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
94
+ var hook = globalThis[HOOK];
95
+ if (typeof hook?.inject === "function") {
96
+ try {
97
+ hook.inject({ observeReactiveNodes, version: VERSION });
98
+ } catch {
99
+ }
100
+ }
101
+
102
+ // src/lib/signal/graph/core.ts
103
+ var CLEAN = 0;
104
+ var CHECK = 1;
105
+ var DIRTY = 2;
106
+ var Source = class {
107
+ constructor() {
108
+ /** Computeds, and watched leaves, that read this node. */
109
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
+ this.observers = null;
111
+ /** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
112
+ this.watchers = null;
113
+ /** Bumped whenever this node's value actually changes (equality-gated). */
114
+ this.version = 0;
115
+ }
116
+ /** Settle this node so a reader sees a current value/version. Overridden by Computed. */
117
+ updateIfNecessary() {
118
+ }
119
+ /** Link the current consumer (if any) as an observer of this node. */
120
+ track() {
121
+ if (G.untracked) return;
122
+ const consumer = G.consumer;
123
+ if (!consumer) return;
124
+ (this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
125
+ (consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
126
+ }
127
+ };
128
+ var State = class extends Source {
129
+ constructor(value, options) {
130
+ super();
131
+ this._value = value;
132
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
133
+ }
134
+ get() {
135
+ this.track();
136
+ return this._value;
137
+ }
138
+ set(next) {
139
+ if (this._equals(this._value, next)) return;
140
+ this._value = next;
141
+ this.version++;
142
+ reportReactiveWrite(this, G.consumer);
143
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
144
+ notifyWatchers(this);
145
+ }
146
+ /** Read without subscribing (peek). */
147
+ peek() {
148
+ return this._value;
149
+ }
150
+ };
151
+ var Computed = class extends Source {
152
+ constructor(fn, options) {
153
+ super();
154
+ this._threw = false;
155
+ this._initialized = false;
156
+ this.state = DIRTY;
157
+ /** Nodes this computation read on its last run. Rebuilt on every run. */
158
+ this.sources = null;
159
+ this._fn = fn;
160
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
161
+ }
162
+ get() {
163
+ if (G.consumer === this) {
164
+ throw new Error("Signal.Computed cannot read itself");
165
+ }
166
+ this.track();
167
+ this.updateIfNecessary();
168
+ if (this._threw) throw this._error;
169
+ return this._value;
170
+ }
171
+ /** Settle, if CHECK, verify sources; if DIRTY (or never run), recompute. */
172
+ updateIfNecessary() {
173
+ if (this.state === CHECK) {
174
+ if (this.sources) {
175
+ for (const s of this.sources) {
176
+ s.updateIfNecessary();
177
+ if (this.state === DIRTY) break;
178
+ }
179
+ }
180
+ }
181
+ if (this.state === DIRTY || !this._initialized) this.recompute();
182
+ this.state = CLEAN;
183
+ }
184
+ recompute() {
185
+ if (this.sources) {
186
+ for (const s of this.sources) s.observers?.delete(this);
187
+ this.sources.clear();
188
+ }
189
+ const prevConsumer = G.consumer;
190
+ const prevUntracked = G.untracked;
191
+ const watched = enterReactiveRun(this);
192
+ G.consumer = this;
193
+ G.untracked = false;
194
+ let next;
195
+ let threw = false;
196
+ let err;
197
+ try {
198
+ next = this._fn();
199
+ } catch (e) {
200
+ threw = true;
201
+ err = e;
202
+ next = this._value;
203
+ } finally {
204
+ G.consumer = prevConsumer;
205
+ G.untracked = prevUntracked;
206
+ if (watched) exitReactiveRun();
207
+ }
208
+ const changed = !this._initialized || this._threw !== threw || (threw ? err !== this._error : !this._equals(this._value, next));
209
+ this._initialized = true;
210
+ this._threw = threw;
211
+ this._error = err;
212
+ this._value = next;
213
+ reportReactiveRun(this);
214
+ if (changed) {
215
+ this.version++;
216
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
217
+ notifyWatchers(this);
218
+ }
219
+ }
220
+ /**
221
+ * Push a maybe-dirty mark. A direct observer of a changed node gets DIRTY; its
222
+ * own observers get CHECK (recurse), stopping where already marked, so the
223
+ * push is O(newly-dirtied) and never recomputes.
224
+ */
225
+ markDirty(level) {
226
+ if (this.state >= level) return;
227
+ const wasClean = this.state === CLEAN;
228
+ this.state = level;
229
+ if (wasClean) {
230
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(CHECK);
231
+ notifyWatchers(this);
232
+ }
233
+ }
234
+ peek() {
235
+ this.updateIfNecessary();
236
+ if (this._threw) throw this._error;
237
+ return this._value;
238
+ }
239
+ };
240
+ function notifyWatchers(node) {
241
+ if (!node.watchers) return;
242
+ for (const w of [...node.watchers]) w._notify(node);
243
+ }
244
+ var Watcher = class {
245
+ constructor(notify) {
246
+ this._watched = /* @__PURE__ */ new Set();
247
+ this._pending = /* @__PURE__ */ new Set();
248
+ this._notifyFn = notify;
249
+ }
250
+ watch(...nodes) {
251
+ for (const n of nodes) {
252
+ this._watched.add(n);
253
+ (n.watchers ??= /* @__PURE__ */ new Set()).add(this);
254
+ }
255
+ }
256
+ unwatch(...nodes) {
257
+ for (const n of nodes) {
258
+ this._watched.delete(n);
259
+ n.watchers?.delete(this);
260
+ this._pending.delete(n);
261
+ }
262
+ }
263
+ /** Watched nodes that may have changed since the last getPending(). */
264
+ getPending() {
265
+ const out = [...this._pending];
266
+ this._pending.clear();
267
+ return out;
268
+ }
269
+ /** @internal, a watched node became non-clean. Edge-triggered: notify once. */
270
+ _notify(node) {
271
+ if (!this._watched.has(node) || this._pending.has(node)) return;
272
+ const wasEmpty = this._pending.size === 0;
273
+ this._pending.add(node);
274
+ if (wasEmpty) this._notifyFn();
275
+ }
276
+ };
277
+ function untrack(fn) {
278
+ if (G.untracked) return fn();
279
+ G.untracked = true;
280
+ try {
281
+ return fn();
282
+ } finally {
283
+ G.untracked = false;
284
+ }
285
+ }
286
+ function currentComputed() {
287
+ return G.consumer;
288
+ }
289
+ function hasSinks(node) {
290
+ return !!(node.observers && node.observers.size) || !!(node.watchers && node.watchers.size);
291
+ }
292
+
293
+ // src/cdn/signal.ts
294
+ var subtle = {
295
+ Watcher,
296
+ untrack,
297
+ currentComputed,
298
+ hasSinks
299
+ };
@@ -5,7 +5,7 @@
5
5
  * const c = new Signal.State(0); // window.Signal.State / .Computed / .subtle
6
6
  *
7
7
  * Exports the flat TC39 shape (State/Computed/subtle) as named bindings so the iife
8
- * global is `window.Signal = { State, Computed, subtle }` matching the future native
8
+ * global is `window.Signal = { State, Computed, subtle }`, matching the future native
9
9
  * globalThis.Signal, not a nested `Signal.Signal`.
10
10
  */
11
11
  import { Watcher, untrack, currentComputed, hasSinks } from '../lib/signal/graph/core.js';
@@ -1 +1,2 @@
1
- "use strict";var Signal=(()=>{var p=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var n in t)p(e,n,{get:t[n],enumerable:!0})},z=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of D(t))!E.call(e,s)&&s!==n&&p(e,s,{get:()=>t[s],enumerable:!(o=q(t,s))||o.enumerable});return e};var K=e=>z(p({},"__esModule",{value:!0}),e);var P={};I(P,{Computed:()=>l,State:()=>d,subtle:()=>L});var G="__fluixi_signal_next_state__",H=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[G]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:H,onSuspend:null,onError:null,observer:null};var w="1.0.0-alpha.83";function j(e){return r.observer=e,()=>{r.observer===e&&(r.observer=null)}}var _=[];function m(e){return r.observer?(_.push(e),!0):!1}function R(){_.pop()}function g(e){r.observer?.ran?.(e)}function y(e,t){r.observer?.wrote?.(e,t)}var F="__FLUIXI_DEVTOOLS_HOOK__",k=globalThis[F];if(typeof k?.inject=="function")try{k.inject({observeReactiveNodes:j,version:w})}catch{}var x=0,T=1,a=2,v=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let t=r.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},d=class extends v{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,y(this,r.consumer),this.observers)for(let n of[...this.observers])n.markDirty(a);b(this)}}peek(){return this._value}},l=class extends v{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=a;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(r.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===T&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===a)break}(this.state===a||!this._initialized)&&this.recompute(),this.state=x}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let n=r.consumer,o=r.untracked,s=m(this);r.consumer=this,r.untracked=!1;let u,c=!1,f;try{u=this._fn()}catch(i){c=!0,f=i,u=this._value}finally{r.consumer=n,r.untracked=o,s&&R()}let C=!this._initialized||this._threw!==c||(c?f!==this._error:!this._equals(this._value,u));if(this._initialized=!0,this._threw=c,this._error=f,this._value=u,g(this),C){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(a);b(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===x;if(this.state=n,o){if(this.observers)for(let s of[...this.observers])s.markDirty(T);b(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function b(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var h=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function S(e){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function O(){return r.consumer}function N(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}var L={Watcher:h,untrack:S,currentComputed:O,hasSinks:N};return K(P);})();
1
+ /*! @fluixi/reactive v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
+ "use strict";var Signal=(()=>{var b=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var z=(e,t)=>{for(var n in t)b(e,n,{get:t[n],enumerable:!0})},H=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of K(t))!j.call(e,s)&&s!==n&&b(e,s,{get:()=>t[s],enumerable:!(o=G(t,s))||o.enumerable});return e};var V=e=>H(b({},"__esModule",{value:!0}),e);var U={};z(U,{Computed:()=>h,State:()=>v,subtle:()=>Y});var a="1.0.0-alpha.84";var m=a.split(".")[0],_=`__fluixi_signal_state_v${m}__`,A=`__fluixi_signal_builds_v${m}__`,F=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)};function R(){return{consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:F,onSuspend:null,onError:null,observer:null}}var w=globalThis;function L(e){let t=R(),n=e;for(let o of Object.keys(t))o in e||(n[o]=t[o]);return e}function M(){let e=w[_];return e?L(e):w[_]=R()}var r=M();(w[A]??=[]).push(a);function P(e){return r.observer=e,()=>{r.observer===e&&(r.observer=null)}}var y=[];function S(e){return r.observer?(y.push(e),!0):!1}function x(){y.pop()}function T(e){r.observer?.ran?.(e)}function O(e,t){r.observer?.wrote?.(e,t)}var W="__FLUIXI_DEVTOOLS_HOOK__",g=globalThis[W];if(typeof g?.inject=="function")try{g.inject({observeReactiveNodes:P,version:a})}catch{}var N=0,C=1,u=2,d=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let t=r.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},v=class extends d{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,O(this,r.consumer),this.observers)for(let n of[...this.observers])n.markDirty(u);k(this)}}peek(){return this._value}},h=class extends d{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=u;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(r.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===C&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===u)break}(this.state===u||!this._initialized)&&this.recompute(),this.state=N}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let n=r.consumer,o=r.untracked,s=S(this);r.consumer=this,r.untracked=!1;let c,l=!1,p;try{c=this._fn()}catch(i){l=!0,p=i,c=this._value}finally{r.consumer=n,r.untracked=o,s&&x()}let I=!this._initialized||this._threw!==l||(l?p!==this._error:!this._equals(this._value,c));if(this._initialized=!0,this._threw=l,this._error=p,this._value=c,T(this),I){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(u);k(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===N;if(this.state=n,o){if(this.observers)for(let s of[...this.observers])s.markDirty(C);k(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function k(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var f=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function q(e){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function E(){return r.consumer}function D(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}var Y={Watcher:f,untrack:q,currentComputed:E,hasSinks:D};return V(U);})();
@@ -5,7 +5,7 @@
5
5
  * const c = new Signal.State(0); // window.Signal.State / .Computed / .subtle
6
6
  *
7
7
  * Exports the flat TC39 shape (State/Computed/subtle) as named bindings so the iife
8
- * global is `window.Signal = { State, Computed, subtle }` matching the future native
8
+ * global is `window.Signal = { State, Computed, subtle }`, matching the future native
9
9
  * globalThis.Signal, not a nested `Signal.Signal`.
10
10
  */
11
11
  import { Watcher, untrack, currentComputed, hasSinks } from '../lib/signal/graph/core.js';
@@ -1 +1,276 @@
1
- var C="__fluixi_signal_next_state__",q=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[C]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:q,onSuspend:null,onError:null,observer:null};var b="1.0.0-alpha.83";function D(e){return r.observer=e,()=>{r.observer===e&&(r.observer=null)}}var k=[];function _(e){return r.observer?(k.push(e),!0):!1}function m(){k.pop()}function R(e){r.observer?.ran?.(e)}function g(e,t){r.observer?.wrote?.(e,t)}var E="__FLUIXI_DEVTOOLS_HOOK__",w=globalThis[E];if(typeof w?.inject=="function")try{w.inject({observeReactiveNodes:D,version:b})}catch{}var y=0,x=1,i=2,c=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let t=r.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},h=class extends c{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,g(this,r.consumer),this.observers)for(let n of[...this.observers])n.markDirty(i);p(this)}}peek(){return this._value}},f=class extends c{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=i;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(r.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===x&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===i)break}(this.state===i||!this._initialized)&&this.recompute(),this.state=y}recompute(){if(this.sources){for(let s of this.sources)s.observers?.delete(this);this.sources.clear()}let n=r.consumer,o=r.untracked,d=_(this);r.consumer=this,r.untracked=!1;let a,u=!1,l;try{a=this._fn()}catch(s){u=!0,l=s,a=this._value}finally{r.consumer=n,r.untracked=o,d&&m()}let N=!this._initialized||this._threw!==u||(u?l!==this._error:!this._equals(this._value,a));if(this._initialized=!0,this._threw=u,this._error=l,this._value=a,R(this),N){if(this.version++,this.observers)for(let s of[...this.observers])s.markDirty(i);p(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===y;if(this.state=n,o){if(this.observers)for(let d of[...this.observers])d.markDirty(x);p(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function p(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var v=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function T(e){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function S(){return r.consumer}function O(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}var W={Watcher:v,untrack:T,currentComputed:S,hasSinks:O};export{f as Computed,h as State,W as subtle};
1
+ // src/version.generated.ts
2
+ var VERSION = "1.0.0-alpha.84";
3
+
4
+ // src/lib/signal/graph/state.ts
5
+ var MAJOR = VERSION.split(".")[0];
6
+ var KEY = `__fluixi_signal_state_v${MAJOR}__`;
7
+ var VERSIONS_KEY = `__fluixi_signal_builds_v${MAJOR}__`;
8
+ var defaultSchedule = (run) => {
9
+ if (typeof queueMicrotask === "function") queueMicrotask(run);
10
+ else void Promise.resolve().then(run);
11
+ };
12
+ function defaults() {
13
+ return {
14
+ consumer: null,
15
+ untracked: false,
16
+ owner: null,
17
+ queue: [],
18
+ scheduled: false,
19
+ flushing: false,
20
+ batchDepth: 0,
21
+ hostSchedule: defaultSchedule,
22
+ onSuspend: null,
23
+ onError: null,
24
+ observer: null
25
+ };
26
+ }
27
+ var realm = globalThis;
28
+ function backfillState(existing) {
29
+ const fresh = defaults();
30
+ const target = existing;
31
+ for (const field of Object.keys(fresh)) {
32
+ if (!(field in existing)) target[field] = fresh[field];
33
+ }
34
+ return existing;
35
+ }
36
+ function claim() {
37
+ const existing = realm[KEY];
38
+ return existing ? backfillState(existing) : realm[KEY] = defaults();
39
+ }
40
+ var G = claim();
41
+ (realm[VERSIONS_KEY] ??= []).push(VERSION);
42
+
43
+ // src/lib/signal/graph/observe.ts
44
+ function observeReactiveNodes(next) {
45
+ G.observer = next;
46
+ return () => {
47
+ if (G.observer === next) G.observer = null;
48
+ };
49
+ }
50
+ var running = [];
51
+ function enterReactiveRun(node) {
52
+ if (!G.observer) return false;
53
+ running.push(node);
54
+ return true;
55
+ }
56
+ function exitReactiveRun() {
57
+ running.pop();
58
+ }
59
+ function reportReactiveRun(node) {
60
+ G.observer?.ran?.(node);
61
+ }
62
+ function reportReactiveWrite(node, by) {
63
+ G.observer?.wrote?.(node, by);
64
+ }
65
+ var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
66
+ var hook = globalThis[HOOK];
67
+ if (typeof hook?.inject === "function") {
68
+ try {
69
+ hook.inject({ observeReactiveNodes, version: VERSION });
70
+ } catch {
71
+ }
72
+ }
73
+
74
+ // src/lib/signal/graph/core.ts
75
+ var CLEAN = 0;
76
+ var CHECK = 1;
77
+ var DIRTY = 2;
78
+ var Source = class {
79
+ constructor() {
80
+ /** Computeds, and watched leaves, that read this node. */
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ this.observers = null;
83
+ /** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
84
+ this.watchers = null;
85
+ /** Bumped whenever this node's value actually changes (equality-gated). */
86
+ this.version = 0;
87
+ }
88
+ /** Settle this node so a reader sees a current value/version. Overridden by Computed. */
89
+ updateIfNecessary() {
90
+ }
91
+ /** Link the current consumer (if any) as an observer of this node. */
92
+ track() {
93
+ if (G.untracked) return;
94
+ const consumer = G.consumer;
95
+ if (!consumer) return;
96
+ (this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
97
+ (consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
98
+ }
99
+ };
100
+ var State = class extends Source {
101
+ constructor(value, options) {
102
+ super();
103
+ this._value = value;
104
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
105
+ }
106
+ get() {
107
+ this.track();
108
+ return this._value;
109
+ }
110
+ set(next) {
111
+ if (this._equals(this._value, next)) return;
112
+ this._value = next;
113
+ this.version++;
114
+ reportReactiveWrite(this, G.consumer);
115
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
116
+ notifyWatchers(this);
117
+ }
118
+ /** Read without subscribing (peek). */
119
+ peek() {
120
+ return this._value;
121
+ }
122
+ };
123
+ var Computed = class extends Source {
124
+ constructor(fn, options) {
125
+ super();
126
+ this._threw = false;
127
+ this._initialized = false;
128
+ this.state = DIRTY;
129
+ /** Nodes this computation read on its last run. Rebuilt on every run. */
130
+ this.sources = null;
131
+ this._fn = fn;
132
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
133
+ }
134
+ get() {
135
+ if (G.consumer === this) {
136
+ throw new Error("Signal.Computed cannot read itself");
137
+ }
138
+ this.track();
139
+ this.updateIfNecessary();
140
+ if (this._threw) throw this._error;
141
+ return this._value;
142
+ }
143
+ /** Settle, if CHECK, verify sources; if DIRTY (or never run), recompute. */
144
+ updateIfNecessary() {
145
+ if (this.state === CHECK) {
146
+ if (this.sources) {
147
+ for (const s of this.sources) {
148
+ s.updateIfNecessary();
149
+ if (this.state === DIRTY) break;
150
+ }
151
+ }
152
+ }
153
+ if (this.state === DIRTY || !this._initialized) this.recompute();
154
+ this.state = CLEAN;
155
+ }
156
+ recompute() {
157
+ if (this.sources) {
158
+ for (const s of this.sources) s.observers?.delete(this);
159
+ this.sources.clear();
160
+ }
161
+ const prevConsumer = G.consumer;
162
+ const prevUntracked = G.untracked;
163
+ const watched = enterReactiveRun(this);
164
+ G.consumer = this;
165
+ G.untracked = false;
166
+ let next;
167
+ let threw = false;
168
+ let err;
169
+ try {
170
+ next = this._fn();
171
+ } catch (e) {
172
+ threw = true;
173
+ err = e;
174
+ next = this._value;
175
+ } finally {
176
+ G.consumer = prevConsumer;
177
+ G.untracked = prevUntracked;
178
+ if (watched) exitReactiveRun();
179
+ }
180
+ const changed = !this._initialized || this._threw !== threw || (threw ? err !== this._error : !this._equals(this._value, next));
181
+ this._initialized = true;
182
+ this._threw = threw;
183
+ this._error = err;
184
+ this._value = next;
185
+ reportReactiveRun(this);
186
+ if (changed) {
187
+ this.version++;
188
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
189
+ notifyWatchers(this);
190
+ }
191
+ }
192
+ /**
193
+ * Push a maybe-dirty mark. A direct observer of a changed node gets DIRTY; its
194
+ * own observers get CHECK (recurse), stopping where already marked, so the
195
+ * push is O(newly-dirtied) and never recomputes.
196
+ */
197
+ markDirty(level) {
198
+ if (this.state >= level) return;
199
+ const wasClean = this.state === CLEAN;
200
+ this.state = level;
201
+ if (wasClean) {
202
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(CHECK);
203
+ notifyWatchers(this);
204
+ }
205
+ }
206
+ peek() {
207
+ this.updateIfNecessary();
208
+ if (this._threw) throw this._error;
209
+ return this._value;
210
+ }
211
+ };
212
+ function notifyWatchers(node) {
213
+ if (!node.watchers) return;
214
+ for (const w of [...node.watchers]) w._notify(node);
215
+ }
216
+ var Watcher = class {
217
+ constructor(notify) {
218
+ this._watched = /* @__PURE__ */ new Set();
219
+ this._pending = /* @__PURE__ */ new Set();
220
+ this._notifyFn = notify;
221
+ }
222
+ watch(...nodes) {
223
+ for (const n of nodes) {
224
+ this._watched.add(n);
225
+ (n.watchers ??= /* @__PURE__ */ new Set()).add(this);
226
+ }
227
+ }
228
+ unwatch(...nodes) {
229
+ for (const n of nodes) {
230
+ this._watched.delete(n);
231
+ n.watchers?.delete(this);
232
+ this._pending.delete(n);
233
+ }
234
+ }
235
+ /** Watched nodes that may have changed since the last getPending(). */
236
+ getPending() {
237
+ const out = [...this._pending];
238
+ this._pending.clear();
239
+ return out;
240
+ }
241
+ /** @internal, a watched node became non-clean. Edge-triggered: notify once. */
242
+ _notify(node) {
243
+ if (!this._watched.has(node) || this._pending.has(node)) return;
244
+ const wasEmpty = this._pending.size === 0;
245
+ this._pending.add(node);
246
+ if (wasEmpty) this._notifyFn();
247
+ }
248
+ };
249
+ function untrack(fn) {
250
+ if (G.untracked) return fn();
251
+ G.untracked = true;
252
+ try {
253
+ return fn();
254
+ } finally {
255
+ G.untracked = false;
256
+ }
257
+ }
258
+ function currentComputed() {
259
+ return G.consumer;
260
+ }
261
+ function hasSinks(node) {
262
+ return !!(node.observers && node.observers.size) || !!(node.watchers && node.watchers.size);
263
+ }
264
+
265
+ // src/cdn/signal.ts
266
+ var subtle = {
267
+ Watcher,
268
+ untrack,
269
+ currentComputed,
270
+ hasSinks
271
+ };
272
+ export {
273
+ Computed,
274
+ State,
275
+ subtle
276
+ };