@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,325 @@
1
- "use strict";var v=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var j=(e,n)=>{for(var r in n)v(e,r,{get:n[r],enumerable:!0})},G=(e,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of V(n))!W.call(e,i)&&i!==r&&v(e,i,{get:()=>n[i],enumerable:!(o=M(n,i))||o.enumerable});return e};var H=e=>G(v({},"__esModule",{value:!0}),e);var Z={};j(Z,{readChildren:()=>Q});module.exports=H(Z);var z="__fluixi_signal_next_state__",F=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},t=globalThis[z]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:F,onSuspend:null,onError:null,observer:null};var y="1.0.0-alpha.83";function K(e){return t.observer=e,()=>{t.observer===e&&(t.observer=null)}}var h=[],L;function T(e){let n=t.observer;n&&n.created(e.parents===void 0?{...e,parents:h,origin:e.origin??L}:e)}function m(e){return t.observer?(h.push(e),!0):!1}function x(){h.pop()}function k(e){t.observer?.ran?.(e)}function g(e){t.observer?.disposed?.(e)}var $="__FLUIXI_DEVTOOLS_HOOK__",b=globalThis[$];if(typeof b?.inject=="function")try{b.inject({observeReactiveNodes:K,version:y})}catch{}function _(){return t.observer!=null}var R=0,S=1,l=2,w=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(t.untracked)return;let n=t.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}};var d=class extends w{constructor(r,o){super();this._threw=!1;this._initialized=!1;this.state=l;this.sources=null;this._fn=r,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(t.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===S&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===l)break}(this.state===l||!this._initialized)&&this.recompute(),this.state=R}recompute(){if(this.sources){for(let c of this.sources)c.observers?.delete(this);this.sources.clear()}let r=t.consumer,o=t.untracked,i=m(this);t.consumer=this,t.untracked=!1;let u,s=!1,a;try{u=this._fn()}catch(c){s=!0,a=c,u=this._value}finally{t.consumer=r,t.untracked=o,i&&x()}let I=!this._initialized||this._threw!==s||(s?a!==this._error:!this._equals(this._value,u));if(this._initialized=!0,this._threw=s,this._error=a,this._value=u,k(this),I){if(this.version++,this.observers)for(let c of[...this.observers])c.markDirty(l);O(this)}}markDirty(r){if(this.state>=r)return;let o=this.state===R;if(this.state=r,o){if(this.observers)for(let i of[...this.observers])i.markDirty(S);O(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function O(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}function C(e){return t.onSuspend?(t.onSuspend(e,t.owner),!0):!1}function D(){return t.owner}function A(e,n){let r=t.owner;t.owner=e;try{return n()}finally{t.owner=r}}function q(e){if(t.owner){if(t.owner.disposed){e();return}(t.owner.cleanups??=[]).push(e)}}function E(e){t.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function U(e){return!!e&&typeof e.then=="function"}E(()=>{});var Y=Symbol.for("signal"),B=Symbol.for("memo");function f(e,n,r){let o=n,i=D(),u=new d(()=>A(i,()=>{try{return o=e(o)}catch(a){if(U(a))return C(a),o;throw a}}),{equals:r?.equals}),s=(()=>u.get());return Object.defineProperty(s,Y,{value:!0,enumerable:!0}),Object.defineProperty(s,B,{value:!0,enumerable:!0}),T({kind:"memo",node:u,handle:s,name:r?.name}),_()&&q(()=>g(u)),s}var X=typeof window>"u"?!1:window.__FLUIXI_PROD__===!0,N=typeof process>"u"?X:!1,J=Symbol.for("signal");function P(e){return typeof e=="function"&&e[J]===!0}function p(e){if(typeof e=="function"&&!e.length){let n=e();return P(n)?n:p(n)}if(Array.isArray(e)){let n=[];for(let r=0;r<e.length;r++){let o=p(e[r]);Array.isArray(o)?n.push.apply(n,o):n.push(o)}return n}return e}function Q(e){let n=f(e);return N?f(()=>p(n()),void 0,{name:"children"}):f(()=>p(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/lib/signal/graph/children.ts
21
+ var children_exports = {};
22
+ __export(children_exports, {
23
+ readChildren: () => readChildren
24
+ });
25
+ module.exports = __toCommonJS(children_exports);
26
+
27
+ // src/version.generated.ts
28
+ var VERSION = "1.0.0-alpha.84";
29
+
30
+ // src/lib/signal/graph/state.ts
31
+ var MAJOR = VERSION.split(".")[0];
32
+ var KEY = `__fluixi_signal_state_v${MAJOR}__`;
33
+ var VERSIONS_KEY = `__fluixi_signal_builds_v${MAJOR}__`;
34
+ var defaultSchedule = (run) => {
35
+ if (typeof queueMicrotask === "function") queueMicrotask(run);
36
+ else void Promise.resolve().then(run);
37
+ };
38
+ function defaults() {
39
+ return {
40
+ consumer: null,
41
+ untracked: false,
42
+ owner: null,
43
+ queue: [],
44
+ scheduled: false,
45
+ flushing: false,
46
+ batchDepth: 0,
47
+ hostSchedule: defaultSchedule,
48
+ onSuspend: null,
49
+ onError: null,
50
+ observer: null
51
+ };
52
+ }
53
+ var realm = globalThis;
54
+ function backfillState(existing) {
55
+ const fresh = defaults();
56
+ const target = existing;
57
+ for (const field of Object.keys(fresh)) {
58
+ if (!(field in existing)) target[field] = fresh[field];
59
+ }
60
+ return existing;
61
+ }
62
+ function claim() {
63
+ const existing = realm[KEY];
64
+ return existing ? backfillState(existing) : realm[KEY] = defaults();
65
+ }
66
+ var G = claim();
67
+ (realm[VERSIONS_KEY] ??= []).push(VERSION);
68
+
69
+ // src/lib/signal/graph/observe.ts
70
+ function observeReactiveNodes(next) {
71
+ G.observer = next;
72
+ return () => {
73
+ if (G.observer === next) G.observer = null;
74
+ };
75
+ }
76
+ var running = [];
77
+ var origin;
78
+ function reportReactiveNode(report) {
79
+ const observer = G.observer;
80
+ if (observer) {
81
+ observer.created(
82
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
83
+ );
84
+ }
85
+ }
86
+ function enterReactiveRun(node) {
87
+ if (!G.observer) return false;
88
+ running.push(node);
89
+ return true;
90
+ }
91
+ function exitReactiveRun() {
92
+ running.pop();
93
+ }
94
+ function reportReactiveRun(node) {
95
+ G.observer?.ran?.(node);
96
+ }
97
+ function reportReactiveDispose(node) {
98
+ G.observer?.disposed?.(node);
99
+ }
100
+ var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
101
+ var hook = globalThis[HOOK];
102
+ if (typeof hook?.inject === "function") {
103
+ try {
104
+ hook.inject({ observeReactiveNodes, version: VERSION });
105
+ } catch {
106
+ }
107
+ }
108
+ function isObserved() {
109
+ return G.observer != null;
110
+ }
111
+
112
+ // src/lib/signal/graph/core.ts
113
+ var CLEAN = 0;
114
+ var CHECK = 1;
115
+ var DIRTY = 2;
116
+ var Source = class {
117
+ constructor() {
118
+ /** Computeds, and watched leaves, that read this node. */
119
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
+ this.observers = null;
121
+ /** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
122
+ this.watchers = null;
123
+ /** Bumped whenever this node's value actually changes (equality-gated). */
124
+ this.version = 0;
125
+ }
126
+ /** Settle this node so a reader sees a current value/version. Overridden by Computed. */
127
+ updateIfNecessary() {
128
+ }
129
+ /** Link the current consumer (if any) as an observer of this node. */
130
+ track() {
131
+ if (G.untracked) return;
132
+ const consumer = G.consumer;
133
+ if (!consumer) return;
134
+ (this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
135
+ (consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
136
+ }
137
+ };
138
+ var Computed = class extends Source {
139
+ constructor(fn, options) {
140
+ super();
141
+ this._threw = false;
142
+ this._initialized = false;
143
+ this.state = DIRTY;
144
+ /** Nodes this computation read on its last run. Rebuilt on every run. */
145
+ this.sources = null;
146
+ this._fn = fn;
147
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
148
+ }
149
+ get() {
150
+ if (G.consumer === this) {
151
+ throw new Error("Signal.Computed cannot read itself");
152
+ }
153
+ this.track();
154
+ this.updateIfNecessary();
155
+ if (this._threw) throw this._error;
156
+ return this._value;
157
+ }
158
+ /** Settle, if CHECK, verify sources; if DIRTY (or never run), recompute. */
159
+ updateIfNecessary() {
160
+ if (this.state === CHECK) {
161
+ if (this.sources) {
162
+ for (const s of this.sources) {
163
+ s.updateIfNecessary();
164
+ if (this.state === DIRTY) break;
165
+ }
166
+ }
167
+ }
168
+ if (this.state === DIRTY || !this._initialized) this.recompute();
169
+ this.state = CLEAN;
170
+ }
171
+ recompute() {
172
+ if (this.sources) {
173
+ for (const s of this.sources) s.observers?.delete(this);
174
+ this.sources.clear();
175
+ }
176
+ const prevConsumer = G.consumer;
177
+ const prevUntracked = G.untracked;
178
+ const watched = enterReactiveRun(this);
179
+ G.consumer = this;
180
+ G.untracked = false;
181
+ let next;
182
+ let threw = false;
183
+ let err;
184
+ try {
185
+ next = this._fn();
186
+ } catch (e) {
187
+ threw = true;
188
+ err = e;
189
+ next = this._value;
190
+ } finally {
191
+ G.consumer = prevConsumer;
192
+ G.untracked = prevUntracked;
193
+ if (watched) exitReactiveRun();
194
+ }
195
+ const changed = !this._initialized || this._threw !== threw || (threw ? err !== this._error : !this._equals(this._value, next));
196
+ this._initialized = true;
197
+ this._threw = threw;
198
+ this._error = err;
199
+ this._value = next;
200
+ reportReactiveRun(this);
201
+ if (changed) {
202
+ this.version++;
203
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
204
+ notifyWatchers(this);
205
+ }
206
+ }
207
+ /**
208
+ * Push a maybe-dirty mark. A direct observer of a changed node gets DIRTY; its
209
+ * own observers get CHECK (recurse), stopping where already marked, so the
210
+ * push is O(newly-dirtied) and never recomputes.
211
+ */
212
+ markDirty(level) {
213
+ if (this.state >= level) return;
214
+ const wasClean = this.state === CLEAN;
215
+ this.state = level;
216
+ if (wasClean) {
217
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(CHECK);
218
+ notifyWatchers(this);
219
+ }
220
+ }
221
+ peek() {
222
+ this.updateIfNecessary();
223
+ if (this._threw) throw this._error;
224
+ return this._value;
225
+ }
226
+ };
227
+ function notifyWatchers(node) {
228
+ if (!node.watchers) return;
229
+ for (const w of [...node.watchers]) w._notify(node);
230
+ }
231
+
232
+ // src/lib/signal/graph/runtime.ts
233
+ function reportSuspend(promise) {
234
+ if (G.onSuspend) {
235
+ G.onSuspend(promise, G.owner);
236
+ return true;
237
+ }
238
+ return false;
239
+ }
240
+ function getOwner() {
241
+ return G.owner;
242
+ }
243
+ function runWithOwner(owner, fn) {
244
+ const prev = G.owner;
245
+ G.owner = owner;
246
+ try {
247
+ return fn();
248
+ } finally {
249
+ G.owner = prev;
250
+ }
251
+ }
252
+ function onCleanup(fn) {
253
+ if (!G.owner) return;
254
+ if (G.owner.disposed) {
255
+ fn();
256
+ return;
257
+ }
258
+ (G.owner.cleanups ??= []).push(fn);
259
+ }
260
+ function setScheduler(fn) {
261
+ G.hostSchedule = fn ?? ((run) => void Promise.resolve().then(run));
262
+ }
263
+
264
+ // src/lib/signal/graph/compat.ts
265
+ function isThenable(v) {
266
+ return !!v && typeof v.then === "function";
267
+ }
268
+ setScheduler(() => {
269
+ });
270
+ var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
271
+ var $MEMO = /* @__PURE__ */ Symbol.for("memo");
272
+ function createMemo(fn, value, options) {
273
+ let prev = value;
274
+ const owner = getOwner();
275
+ const c = new Computed(
276
+ () => runWithOwner(owner, () => {
277
+ try {
278
+ return prev = fn(prev);
279
+ } catch (e) {
280
+ if (isThenable(e)) {
281
+ reportSuspend(e);
282
+ return prev;
283
+ }
284
+ throw e;
285
+ }
286
+ }),
287
+ { equals: options?.equals }
288
+ );
289
+ const read = (() => c.get());
290
+ Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
291
+ Object.defineProperty(read, $MEMO, { value: true, enumerable: true });
292
+ reportReactiveNode({ kind: "memo", node: c, handle: read, name: options?.name });
293
+ if (isObserved()) onCleanup(() => reportReactiveDispose(c));
294
+ return read;
295
+ }
296
+
297
+ // src/lib/signal/graph/detect.ts
298
+ var __BROWSER_PROD__ = typeof window === "undefined" ? false : window.__FLUIXI_PROD__ === true;
299
+ var __DEV__ = typeof process === "undefined" ? __BROWSER_PROD__ : false;
300
+ var $SIGNAL2 = /* @__PURE__ */ Symbol.for("signal");
301
+ function isSignal(value) {
302
+ return typeof value === "function" && value[$SIGNAL2] === true;
303
+ }
304
+
305
+ // src/lib/signal/graph/children.ts
306
+ function resolveChildrenValue(children) {
307
+ if (typeof children === "function" && !children.length) {
308
+ const result = children();
309
+ if (isSignal(result)) return result;
310
+ return resolveChildrenValue(result);
311
+ }
312
+ if (Array.isArray(children)) {
313
+ const results = [];
314
+ for (let i = 0; i < children.length; i++) {
315
+ const result = resolveChildrenValue(children[i]);
316
+ Array.isArray(result) ? results.push.apply(results, result) : results.push(result);
317
+ }
318
+ return results;
319
+ }
320
+ return children;
321
+ }
322
+ function readChildren(fn) {
323
+ const children = createMemo(fn);
324
+ return __DEV__ ? createMemo(() => resolveChildrenValue(children()), void 0, { name: "children" }) : createMemo(() => resolveChildrenValue(children()));
325
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * readChildren resolve a children thunk into a reactive accessor: unwrap nested
2
+ * readChildren: resolve a children thunk into a reactive accessor, unwrap nested
3
3
  * thunks, flatten arrays, and stop at signals/memos so they stay reactive. Built on
4
4
  * the TC39 memo (compat), so the resolution tracks TC39 signals correctly.
5
5
  */
@@ -1 +1,302 @@
1
- var I="__fluixi_signal_next_state__",M=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},n=globalThis[I]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:M,onSuspend:null,onError:null,observer:null};var w="1.0.0-alpha.83";function V(e){return n.observer=e,()=>{n.observer===e&&(n.observer=null)}}var v=[],W;function b(e){let t=n.observer;t&&t.created(e.parents===void 0?{...e,parents:v,origin:e.origin??W}:e)}function T(e){return n.observer?(v.push(e),!0):!1}function m(){v.pop()}function x(e){n.observer?.ran?.(e)}function k(e){n.observer?.disposed?.(e)}var j="__FLUIXI_DEVTOOLS_HOOK__",y=globalThis[j];if(typeof y?.inject=="function")try{y.inject({observeReactiveNodes:V,version:w})}catch{}function g(){return n.observer!=null}var _=0,R=1,l=2,h=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(n.untracked)return;let t=n.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}};var d=class extends h{constructor(r,o){super();this._threw=!1;this._initialized=!1;this.state=l;this.sources=null;this._fn=r,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(n.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===R&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===l)break}(this.state===l||!this._initialized)&&this.recompute(),this.state=_}recompute(){if(this.sources){for(let c of this.sources)c.observers?.delete(this);this.sources.clear()}let r=n.consumer,o=n.untracked,a=T(this);n.consumer=this,n.untracked=!1;let s,i=!1,u;try{s=this._fn()}catch(c){i=!0,u=c,s=this._value}finally{n.consumer=r,n.untracked=o,a&&m()}let P=!this._initialized||this._threw!==i||(i?u!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=u,this._value=s,x(this),P){if(this.version++,this.observers)for(let c of[...this.observers])c.markDirty(l);S(this)}}markDirty(r){if(this.state>=r)return;let o=this.state===_;if(this.state=r,o){if(this.observers)for(let a of[...this.observers])a.markDirty(R);S(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function S(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}function O(e){return n.onSuspend?(n.onSuspend(e,n.owner),!0):!1}function C(){return n.owner}function D(e,t){let r=n.owner;n.owner=e;try{return t()}finally{n.owner=r}}function A(e){if(n.owner){if(n.owner.disposed){e();return}(n.owner.cleanups??=[]).push(e)}}function q(e){n.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function G(e){return!!e&&typeof e.then=="function"}q(()=>{});var H=Symbol.for("signal"),z=Symbol.for("memo");function f(e,t,r){let o=t,a=C(),s=new d(()=>D(a,()=>{try{return o=e(o)}catch(u){if(G(u))return O(u),o;throw u}}),{equals:r?.equals}),i=(()=>s.get());return Object.defineProperty(i,H,{value:!0,enumerable:!0}),Object.defineProperty(i,z,{value:!0,enumerable:!0}),b({kind:"memo",node:s,handle:i,name:r?.name}),g()&&A(()=>k(s)),i}var F=typeof window>"u"?!1:window.__FLUIXI_PROD__===!0,E=typeof process>"u"?F:!1,K=Symbol.for("signal");function N(e){return typeof e=="function"&&e[K]===!0}function p(e){if(typeof e=="function"&&!e.length){let t=e();return N(t)?t:p(t)}if(Array.isArray(e)){let t=[];for(let r=0;r<e.length;r++){let o=p(e[r]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function he(e){let t=f(e);return E?f(()=>p(t()),void 0,{name:"children"}):f(()=>p(t()))}export{he as readChildren};
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
+ var origin;
52
+ function reportReactiveNode(report) {
53
+ const observer = G.observer;
54
+ if (observer) {
55
+ observer.created(
56
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
57
+ );
58
+ }
59
+ }
60
+ function enterReactiveRun(node) {
61
+ if (!G.observer) return false;
62
+ running.push(node);
63
+ return true;
64
+ }
65
+ function exitReactiveRun() {
66
+ running.pop();
67
+ }
68
+ function reportReactiveRun(node) {
69
+ G.observer?.ran?.(node);
70
+ }
71
+ function reportReactiveDispose(node) {
72
+ G.observer?.disposed?.(node);
73
+ }
74
+ var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
75
+ var hook = globalThis[HOOK];
76
+ if (typeof hook?.inject === "function") {
77
+ try {
78
+ hook.inject({ observeReactiveNodes, version: VERSION });
79
+ } catch {
80
+ }
81
+ }
82
+ function isObserved() {
83
+ return G.observer != null;
84
+ }
85
+
86
+ // src/lib/signal/graph/core.ts
87
+ var CLEAN = 0;
88
+ var CHECK = 1;
89
+ var DIRTY = 2;
90
+ var Source = class {
91
+ constructor() {
92
+ /** Computeds, and watched leaves, that read this node. */
93
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
+ this.observers = null;
95
+ /** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
96
+ this.watchers = null;
97
+ /** Bumped whenever this node's value actually changes (equality-gated). */
98
+ this.version = 0;
99
+ }
100
+ /** Settle this node so a reader sees a current value/version. Overridden by Computed. */
101
+ updateIfNecessary() {
102
+ }
103
+ /** Link the current consumer (if any) as an observer of this node. */
104
+ track() {
105
+ if (G.untracked) return;
106
+ const consumer = G.consumer;
107
+ if (!consumer) return;
108
+ (this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
109
+ (consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
110
+ }
111
+ };
112
+ var Computed = class extends Source {
113
+ constructor(fn, options) {
114
+ super();
115
+ this._threw = false;
116
+ this._initialized = false;
117
+ this.state = DIRTY;
118
+ /** Nodes this computation read on its last run. Rebuilt on every run. */
119
+ this.sources = null;
120
+ this._fn = fn;
121
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
122
+ }
123
+ get() {
124
+ if (G.consumer === this) {
125
+ throw new Error("Signal.Computed cannot read itself");
126
+ }
127
+ this.track();
128
+ this.updateIfNecessary();
129
+ if (this._threw) throw this._error;
130
+ return this._value;
131
+ }
132
+ /** Settle, if CHECK, verify sources; if DIRTY (or never run), recompute. */
133
+ updateIfNecessary() {
134
+ if (this.state === CHECK) {
135
+ if (this.sources) {
136
+ for (const s of this.sources) {
137
+ s.updateIfNecessary();
138
+ if (this.state === DIRTY) break;
139
+ }
140
+ }
141
+ }
142
+ if (this.state === DIRTY || !this._initialized) this.recompute();
143
+ this.state = CLEAN;
144
+ }
145
+ recompute() {
146
+ if (this.sources) {
147
+ for (const s of this.sources) s.observers?.delete(this);
148
+ this.sources.clear();
149
+ }
150
+ const prevConsumer = G.consumer;
151
+ const prevUntracked = G.untracked;
152
+ const watched = enterReactiveRun(this);
153
+ G.consumer = this;
154
+ G.untracked = false;
155
+ let next;
156
+ let threw = false;
157
+ let err;
158
+ try {
159
+ next = this._fn();
160
+ } catch (e) {
161
+ threw = true;
162
+ err = e;
163
+ next = this._value;
164
+ } finally {
165
+ G.consumer = prevConsumer;
166
+ G.untracked = prevUntracked;
167
+ if (watched) exitReactiveRun();
168
+ }
169
+ const changed = !this._initialized || this._threw !== threw || (threw ? err !== this._error : !this._equals(this._value, next));
170
+ this._initialized = true;
171
+ this._threw = threw;
172
+ this._error = err;
173
+ this._value = next;
174
+ reportReactiveRun(this);
175
+ if (changed) {
176
+ this.version++;
177
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
178
+ notifyWatchers(this);
179
+ }
180
+ }
181
+ /**
182
+ * Push a maybe-dirty mark. A direct observer of a changed node gets DIRTY; its
183
+ * own observers get CHECK (recurse), stopping where already marked, so the
184
+ * push is O(newly-dirtied) and never recomputes.
185
+ */
186
+ markDirty(level) {
187
+ if (this.state >= level) return;
188
+ const wasClean = this.state === CLEAN;
189
+ this.state = level;
190
+ if (wasClean) {
191
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(CHECK);
192
+ notifyWatchers(this);
193
+ }
194
+ }
195
+ peek() {
196
+ this.updateIfNecessary();
197
+ if (this._threw) throw this._error;
198
+ return this._value;
199
+ }
200
+ };
201
+ function notifyWatchers(node) {
202
+ if (!node.watchers) return;
203
+ for (const w of [...node.watchers]) w._notify(node);
204
+ }
205
+
206
+ // src/lib/signal/graph/runtime.ts
207
+ function reportSuspend(promise) {
208
+ if (G.onSuspend) {
209
+ G.onSuspend(promise, G.owner);
210
+ return true;
211
+ }
212
+ return false;
213
+ }
214
+ function getOwner() {
215
+ return G.owner;
216
+ }
217
+ function runWithOwner(owner, fn) {
218
+ const prev = G.owner;
219
+ G.owner = owner;
220
+ try {
221
+ return fn();
222
+ } finally {
223
+ G.owner = prev;
224
+ }
225
+ }
226
+ function onCleanup(fn) {
227
+ if (!G.owner) return;
228
+ if (G.owner.disposed) {
229
+ fn();
230
+ return;
231
+ }
232
+ (G.owner.cleanups ??= []).push(fn);
233
+ }
234
+ function setScheduler(fn) {
235
+ G.hostSchedule = fn ?? ((run) => void Promise.resolve().then(run));
236
+ }
237
+
238
+ // src/lib/signal/graph/compat.ts
239
+ function isThenable(v) {
240
+ return !!v && typeof v.then === "function";
241
+ }
242
+ setScheduler(() => {
243
+ });
244
+ var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
245
+ var $MEMO = /* @__PURE__ */ Symbol.for("memo");
246
+ function createMemo(fn, value, options) {
247
+ let prev = value;
248
+ const owner = getOwner();
249
+ const c = new Computed(
250
+ () => runWithOwner(owner, () => {
251
+ try {
252
+ return prev = fn(prev);
253
+ } catch (e) {
254
+ if (isThenable(e)) {
255
+ reportSuspend(e);
256
+ return prev;
257
+ }
258
+ throw e;
259
+ }
260
+ }),
261
+ { equals: options?.equals }
262
+ );
263
+ const read = (() => c.get());
264
+ Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
265
+ Object.defineProperty(read, $MEMO, { value: true, enumerable: true });
266
+ reportReactiveNode({ kind: "memo", node: c, handle: read, name: options?.name });
267
+ if (isObserved()) onCleanup(() => reportReactiveDispose(c));
268
+ return read;
269
+ }
270
+
271
+ // src/lib/signal/graph/detect.ts
272
+ var __BROWSER_PROD__ = typeof window === "undefined" ? false : window.__FLUIXI_PROD__ === true;
273
+ var __DEV__ = typeof process === "undefined" ? __BROWSER_PROD__ : false;
274
+ var $SIGNAL2 = /* @__PURE__ */ Symbol.for("signal");
275
+ function isSignal(value) {
276
+ return typeof value === "function" && value[$SIGNAL2] === true;
277
+ }
278
+
279
+ // src/lib/signal/graph/children.ts
280
+ function resolveChildrenValue(children) {
281
+ if (typeof children === "function" && !children.length) {
282
+ const result = children();
283
+ if (isSignal(result)) return result;
284
+ return resolveChildrenValue(result);
285
+ }
286
+ if (Array.isArray(children)) {
287
+ const results = [];
288
+ for (let i = 0; i < children.length; i++) {
289
+ const result = resolveChildrenValue(children[i]);
290
+ Array.isArray(result) ? results.push.apply(results, result) : results.push(result);
291
+ }
292
+ return results;
293
+ }
294
+ return children;
295
+ }
296
+ function readChildren(fn) {
297
+ const children = createMemo(fn);
298
+ return __DEV__ ? createMemo(() => resolveChildrenValue(children()), void 0, { name: "children" }) : createMemo(() => resolveChildrenValue(children()));
299
+ }
300
+ export {
301
+ readChildren
302
+ };