@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,473 @@
1
- var V="__fluixi_signal_next_state__",G=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[V]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:G,onSuspend:null,onError:null,observer:null};var _="1.0.0-alpha.83";function H(e){return r.observer=e,()=>{r.observer===e&&(r.observer=null)}}var m=[],z;function v(e){let t=r.observer;t&&t.created(e.parents===void 0?{...e,parents:m,origin:e.origin??z}:e)}function q(e){return r.observer?(m.push(e),!0):!1}function D(){m.pop()}function N(e){r.observer?.ran?.(e)}function E(e,t){r.observer?.wrote?.(e,t)}function h(e){r.observer?.disposed?.(e)}var F="__FLUIXI_DEVTOOLS_HOOK__",C=globalThis[F];if(typeof C?.inject=="function")try{C.inject({observeReactiveNodes:H,version:_})}catch{}function P(){return r.observer!=null}var A=0,I=1,l=2,w=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))}},T=class extends w{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++,E(this,r.consumer),this.observers)for(let n of[...this.observers])n.markDirty(l);y(this)}}peek(){return this._value}},d=class extends w{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=l;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===I&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===l)break}(this.state===l||!this._initialized)&&this.recompute(),this.state=A}recompute(){if(this.sources){for(let c of this.sources)c.observers?.delete(this);this.sources.clear()}let n=r.consumer,o=r.untracked,s=q(this);r.consumer=this,r.untracked=!1;let i,u=!1,a;try{i=this._fn()}catch(c){u=!0,a=c,i=this._value}finally{r.consumer=n,r.untracked=o,s&&D()}let p=!this._initialized||this._threw!==u||(u?a!==this._error:!this._equals(this._value,i));if(this._initialized=!0,this._threw=u,this._error=a,this._value=i,N(this),p){if(this.version++,this.observers)for(let c of[...this.observers])c.markDirty(l);y(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===A;if(this.state=n,o){if(this.observers)for(let s of[...this.observers])s.markDirty(I);y(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function y(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var b=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 K(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function x(e,t){let n=r.owner;r.owner=e;try{return t()}finally{r.owner=n}}function f(e){if(r.owner){if(r.owner.disposed){e();return}(r.owner.cleanups??=[]).push(e)}}function k(e,t=!0){if(!e.disposed){if(e.owned){for(let n=e.owned.length-1;n>=0;n--)k(e.owned[n]);e.owned=null}if(e.cleanups){for(let n=e.cleanups.length-1;n>=0;n--)e.cleanups[n]();e.cleanups=null}t&&(e.disposed=!0)}}function M(e){r.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function U(e){e.queued||(e.queued=!0,r.queue.push(e),!r.scheduled&&r.batchDepth===0&&(r.scheduled=!0,r.hostSchedule(R)))}function R(){if(r.scheduled=!1,r.flushing)return;r.flushing=!0;let e=0;try{for(;r.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=r.queue;r.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{r.flushing=!1}}function j(){r.batchDepth===0&&R()}var g=class{constructor(t,n=!1){this.queued=!1;this.disposed=!1;this.owner=K(r.owner),r.owner&&(r.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new d(()=>{k(this.owner,!1),x(this.owner,()=>{let o=t();typeof o=="function"&&(this.owner.cleanups??=[]).push(o)})}),v({kind:"effect",node:this.computed,handle:this,internal:!n}),this.watcher=new b(()=>U(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&r.onSuspend){r.onSuspend(t,this.owner);return}if(r.onError&&r.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,h(this.computed),this.watcher.unwatch(this.computed),k(this.owner))}};function W(e,t=!1){let n=new g(e,t);return()=>n.dispose()}M(()=>{});var Y=Symbol.for("signal");var $=Symbol.for("signal-node");function S(e,t){let n=new T(e,{equals:t?.equals}),o=(()=>n.get()),s=(i=>{let u=typeof i=="function"?i(n.peek()):i;return n.set(u),j(),u});return Object.defineProperty(o,Y,{value:!0,enumerable:!0}),Object.defineProperty(o,$,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),v({kind:"signal",node:n,handle:o,name:t?.name,set:s}),P()&&f(()=>h(n)),[o,s]}function O(e,t){let n=t;return W(()=>{n=e(n)},!0)}function ye(e,t=(n,o)=>n===o){let n=new Map;return O(()=>{let o=e();for(let[s,i]of n){let[u,a]=i,p=t(s,o);u()!==p&&a(p)}}),o=>{let s=n.get(o);if(!s){let[i,u]=S(!1);s=[i,u],n.set(o,s);let a=e();u(t(o,a))}return s[0]()}}function ke(e,t){let[n,o]=S(e(),t);return O(()=>{let s=e();t?.timeoutMs?setTimeout(()=>o(()=>s),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>s)):Promise.resolve().then(()=>o(()=>s))}),n}function ge(e,t){let n,o=(...s)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{n=void 0,e(...s)},t)};return f(()=>{n!==void 0&&clearTimeout(n)}),o}export{ge as createDebounce,ke as createDeferred,ye as createSelector};
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 reportReactiveWrite(node, by) {
72
+ G.observer?.wrote?.(node, by);
73
+ }
74
+ function reportReactiveDispose(node) {
75
+ G.observer?.disposed?.(node);
76
+ }
77
+ var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
78
+ var hook = globalThis[HOOK];
79
+ if (typeof hook?.inject === "function") {
80
+ try {
81
+ hook.inject({ observeReactiveNodes, version: VERSION });
82
+ } catch {
83
+ }
84
+ }
85
+ function isObserved() {
86
+ return G.observer != null;
87
+ }
88
+
89
+ // src/lib/signal/graph/core.ts
90
+ var CLEAN = 0;
91
+ var CHECK = 1;
92
+ var DIRTY = 2;
93
+ var Source = class {
94
+ constructor() {
95
+ /** Computeds, and watched leaves, that read this node. */
96
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
+ this.observers = null;
98
+ /** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
99
+ this.watchers = null;
100
+ /** Bumped whenever this node's value actually changes (equality-gated). */
101
+ this.version = 0;
102
+ }
103
+ /** Settle this node so a reader sees a current value/version. Overridden by Computed. */
104
+ updateIfNecessary() {
105
+ }
106
+ /** Link the current consumer (if any) as an observer of this node. */
107
+ track() {
108
+ if (G.untracked) return;
109
+ const consumer = G.consumer;
110
+ if (!consumer) return;
111
+ (this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
112
+ (consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
113
+ }
114
+ };
115
+ var State = class extends Source {
116
+ constructor(value, options) {
117
+ super();
118
+ this._value = value;
119
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
120
+ }
121
+ get() {
122
+ this.track();
123
+ return this._value;
124
+ }
125
+ set(next) {
126
+ if (this._equals(this._value, next)) return;
127
+ this._value = next;
128
+ this.version++;
129
+ reportReactiveWrite(this, G.consumer);
130
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
131
+ notifyWatchers(this);
132
+ }
133
+ /** Read without subscribing (peek). */
134
+ peek() {
135
+ return this._value;
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
+ var Watcher = class {
232
+ constructor(notify) {
233
+ this._watched = /* @__PURE__ */ new Set();
234
+ this._pending = /* @__PURE__ */ new Set();
235
+ this._notifyFn = notify;
236
+ }
237
+ watch(...nodes) {
238
+ for (const n of nodes) {
239
+ this._watched.add(n);
240
+ (n.watchers ??= /* @__PURE__ */ new Set()).add(this);
241
+ }
242
+ }
243
+ unwatch(...nodes) {
244
+ for (const n of nodes) {
245
+ this._watched.delete(n);
246
+ n.watchers?.delete(this);
247
+ this._pending.delete(n);
248
+ }
249
+ }
250
+ /** Watched nodes that may have changed since the last getPending(). */
251
+ getPending() {
252
+ const out = [...this._pending];
253
+ this._pending.clear();
254
+ return out;
255
+ }
256
+ /** @internal, a watched node became non-clean. Edge-triggered: notify once. */
257
+ _notify(node) {
258
+ if (!this._watched.has(node) || this._pending.has(node)) return;
259
+ const wasEmpty = this._pending.size === 0;
260
+ this._pending.add(node);
261
+ if (wasEmpty) this._notifyFn();
262
+ }
263
+ };
264
+
265
+ // src/lib/signal/graph/runtime.ts
266
+ function makeOwner(parent) {
267
+ return { cleanups: null, owned: null, parent, contexts: null };
268
+ }
269
+ function runWithOwner(owner, fn) {
270
+ const prev = G.owner;
271
+ G.owner = owner;
272
+ try {
273
+ return fn();
274
+ } finally {
275
+ G.owner = prev;
276
+ }
277
+ }
278
+ function onCleanup(fn) {
279
+ if (!G.owner) return;
280
+ if (G.owner.disposed) {
281
+ fn();
282
+ return;
283
+ }
284
+ (G.owner.cleanups ??= []).push(fn);
285
+ }
286
+ function disposeOwner(owner, final = true) {
287
+ if (owner.disposed) return;
288
+ if (owner.owned) {
289
+ for (let i = owner.owned.length - 1; i >= 0; i--) disposeOwner(owner.owned[i]);
290
+ owner.owned = null;
291
+ }
292
+ if (owner.cleanups) {
293
+ for (let i = owner.cleanups.length - 1; i >= 0; i--) owner.cleanups[i]();
294
+ owner.cleanups = null;
295
+ }
296
+ if (final) owner.disposed = true;
297
+ }
298
+ function setScheduler(fn) {
299
+ G.hostSchedule = fn ?? ((run) => void Promise.resolve().then(run));
300
+ }
301
+ function enqueue(e) {
302
+ if (e.queued) return;
303
+ e.queued = true;
304
+ G.queue.push(e);
305
+ if (!G.scheduled && G.batchDepth === 0) {
306
+ G.scheduled = true;
307
+ G.hostSchedule(flushSync);
308
+ }
309
+ }
310
+ function flushSync() {
311
+ G.scheduled = false;
312
+ if (G.flushing) return;
313
+ G.flushing = true;
314
+ let guard = 0;
315
+ try {
316
+ while (G.queue.length) {
317
+ if (++guard > 1e5) throw new Error("[fluixi] effect flush did not settle (cycle?)");
318
+ const batchOf = G.queue;
319
+ G.queue = [];
320
+ for (const e of batchOf) {
321
+ e.queued = false;
322
+ if (!e.disposed) e.run();
323
+ }
324
+ }
325
+ } finally {
326
+ G.flushing = false;
327
+ }
328
+ }
329
+ function afterWrite() {
330
+ if (G.batchDepth === 0) flushSync();
331
+ }
332
+ var EffectNode = class {
333
+ constructor(fn, report = false) {
334
+ this.queued = false;
335
+ this.disposed = false;
336
+ this.owner = makeOwner(G.owner);
337
+ if (G.owner) (G.owner.cleanups ??= []).push(() => this.dispose());
338
+ this.computed = new Computed(() => {
339
+ disposeOwner(this.owner, false);
340
+ runWithOwner(this.owner, () => {
341
+ const r = fn();
342
+ if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
343
+ });
344
+ });
345
+ reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report });
346
+ this.watcher = new Watcher(() => enqueue(this));
347
+ this.run();
348
+ this.watcher.watch(this.computed);
349
+ }
350
+ run() {
351
+ if (this.disposed) return;
352
+ this.watcher.getPending();
353
+ try {
354
+ this.computed.get();
355
+ } catch (e) {
356
+ if (e && typeof e.then === "function" && G.onSuspend) {
357
+ G.onSuspend(e, this.owner);
358
+ return;
359
+ }
360
+ if (G.onError && G.onError(e, this.owner)) return;
361
+ throw e;
362
+ }
363
+ }
364
+ dispose() {
365
+ if (this.disposed) return;
366
+ this.disposed = true;
367
+ reportReactiveDispose(this.computed);
368
+ this.watcher.unwatch(this.computed);
369
+ disposeOwner(this.owner);
370
+ }
371
+ };
372
+ function effect(fn, report = false) {
373
+ const node = new EffectNode(fn, report);
374
+ return () => node.dispose();
375
+ }
376
+
377
+ // src/lib/signal/graph/compat.ts
378
+ setScheduler(() => {
379
+ });
380
+ var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
381
+ var $NODE = /* @__PURE__ */ Symbol.for("signal-node");
382
+ function createSignal(value, options) {
383
+ const state = new State(value, { equals: options?.equals });
384
+ const read = (() => state.get());
385
+ const write = ((next) => {
386
+ const v = typeof next === "function" ? next(state.peek()) : next;
387
+ state.set(v);
388
+ afterWrite();
389
+ return v;
390
+ });
391
+ Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
392
+ Object.defineProperty(read, $NODE, {
393
+ value: {
394
+ get value() {
395
+ return state.peek();
396
+ },
397
+ get version() {
398
+ return state.version;
399
+ }
400
+ },
401
+ enumerable: false
402
+ });
403
+ reportReactiveNode({
404
+ kind: "signal",
405
+ node: state,
406
+ handle: read,
407
+ name: options?.name,
408
+ set: write
409
+ });
410
+ if (isObserved()) onCleanup(() => reportReactiveDispose(state));
411
+ return [read, write];
412
+ }
413
+ function createEffect(fn, value) {
414
+ let prev = value;
415
+ return effect(() => {
416
+ const r = fn(prev);
417
+ prev = r;
418
+ }, true);
419
+ }
420
+
421
+ // src/lib/signal/graph/derived.ts
422
+ function createSelector(source, fn = (k, v) => k === v) {
423
+ const map = /* @__PURE__ */ new Map();
424
+ createEffect(() => {
425
+ const value = source();
426
+ for (const [key, signal] of map) {
427
+ const [get, set] = signal;
428
+ const match = fn(key, value);
429
+ if (get() !== match) set(match);
430
+ }
431
+ });
432
+ return (key) => {
433
+ let signal = map.get(key);
434
+ if (!signal) {
435
+ const [get, set] = createSignal(false);
436
+ signal = [get, set];
437
+ map.set(key, signal);
438
+ const value = source();
439
+ set(fn(key, value));
440
+ }
441
+ return signal[0]();
442
+ };
443
+ }
444
+ function createDeferred(source, options) {
445
+ const [delayed, setDelayed] = createSignal(source(), options);
446
+ createEffect(() => {
447
+ const v = source();
448
+ if (options?.timeoutMs) setTimeout(() => setDelayed(() => v), options.timeoutMs);
449
+ else if (typeof requestIdleCallback === "function")
450
+ requestIdleCallback(() => setDelayed(() => v));
451
+ else Promise.resolve().then(() => setDelayed(() => v));
452
+ });
453
+ return delayed;
454
+ }
455
+ function createDebounce(fn, delay) {
456
+ let timer;
457
+ const debounced = (...args) => {
458
+ if (timer !== void 0) clearTimeout(timer);
459
+ timer = setTimeout(() => {
460
+ timer = void 0;
461
+ fn(...args);
462
+ }, delay);
463
+ };
464
+ onCleanup(() => {
465
+ if (timer !== void 0) clearTimeout(timer);
466
+ });
467
+ return debounced;
468
+ }
469
+ export {
470
+ createDebounce,
471
+ createDeferred,
472
+ createSelector
473
+ };
@@ -1 +1,66 @@
1
- "use strict";var e=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var s=(n,o)=>{for(var t in o)e(n,t,{get:o[t],enumerable:!0})},_=(n,o,t,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of u(o))!p.call(n,r)&&r!==t&&e(n,r,{get:()=>o[r],enumerable:!(i=c(o,r))||i.enumerable});return n};var a=n=>_(e({},"__esModule",{value:!0}),n);var g={};s(g,{__BROWSER_PROD__:()=>f,__DEV__:()=>m,isComponent:()=>E,isMemo:()=>A,isProvider:()=>T,isResource:()=>R,isSignal:()=>d,isSuspense:()=>O,makeArrayFlat:()=>y});module.exports=a(g);var f=typeof window>"u"?!1:window.__FLUIXI_PROD__===!0,m=typeof process>"u"?f:!1,x=Symbol.for("signal"),S=Symbol.for("memo"),b=Symbol.for("resource");function d(n){return typeof n=="function"&&n[x]===!0}function A(n){return typeof n=="function"&&n[S]===!0}function R(n){return typeof n=="function"&&n[b]===!0}function E(n){return typeof n=="function"&&n[Symbol.for("fluixi-component")]===!0}function O(n){return typeof n=="function"&&n[Symbol.for("fluixi-suspense")]===!0}function T(n){return typeof n=="function"&&n[Symbol.for("fluixi-provider")]===!0}function y(n){return Array.isArray(n)?n.length===2&&n[1]===" "?Array.isArray(n[0])?y(n[0]):(typeof n[0]=="function",n[0]):n.length===1&&typeof n[0]=="function"?n[0]:n: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/detect.ts
21
+ var detect_exports = {};
22
+ __export(detect_exports, {
23
+ __BROWSER_PROD__: () => __BROWSER_PROD__,
24
+ __DEV__: () => __DEV__,
25
+ isComponent: () => isComponent,
26
+ isMemo: () => isMemo,
27
+ isProvider: () => isProvider,
28
+ isResource: () => isResource,
29
+ isSignal: () => isSignal,
30
+ isSuspense: () => isSuspense,
31
+ makeArrayFlat: () => makeArrayFlat
32
+ });
33
+ module.exports = __toCommonJS(detect_exports);
34
+ var __BROWSER_PROD__ = typeof window === "undefined" ? false : window.__FLUIXI_PROD__ === true;
35
+ var __DEV__ = typeof process === "undefined" ? __BROWSER_PROD__ : false;
36
+ var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
37
+ var $MEMO = /* @__PURE__ */ Symbol.for("memo");
38
+ var $RESOURCE = /* @__PURE__ */ Symbol.for("resource");
39
+ function isSignal(value) {
40
+ return typeof value === "function" && value[$SIGNAL] === true;
41
+ }
42
+ function isMemo(value) {
43
+ return typeof value === "function" && value[$MEMO] === true;
44
+ }
45
+ function isResource(value) {
46
+ return typeof value === "function" && value[$RESOURCE] === true;
47
+ }
48
+ function isComponent(value) {
49
+ return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-component")] === true;
50
+ }
51
+ function isSuspense(value) {
52
+ return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-suspense")] === true;
53
+ }
54
+ function isProvider(value) {
55
+ return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-provider")] === true;
56
+ }
57
+ function makeArrayFlat(values) {
58
+ if (!Array.isArray(values)) return values;
59
+ if (values.length === 2 && values[1] === " ") {
60
+ if (Array.isArray(values[0])) return makeArrayFlat(values[0]);
61
+ if (typeof values[0] === "function") return values[0];
62
+ return values[0];
63
+ }
64
+ if (values.length === 1 && typeof values[0] === "function") return values[0];
65
+ return values;
66
+ }
@@ -1 +1,45 @@
1
- var o=typeof window>"u"?!1:window.__FLUIXI_PROD__===!0,f=typeof process>"u"?o:!1,r=Symbol.for("signal"),t=Symbol.for("memo"),e=Symbol.for("resource");function y(n){return typeof n=="function"&&n[r]===!0}function c(n){return typeof n=="function"&&n[t]===!0}function u(n){return typeof n=="function"&&n[e]===!0}function p(n){return typeof n=="function"&&n[Symbol.for("fluixi-component")]===!0}function s(n){return typeof n=="function"&&n[Symbol.for("fluixi-suspense")]===!0}function _(n){return typeof n=="function"&&n[Symbol.for("fluixi-provider")]===!0}function i(n){return Array.isArray(n)?n.length===2&&n[1]===" "?Array.isArray(n[0])?i(n[0]):(typeof n[0]=="function",n[0]):n.length===1&&typeof n[0]=="function"?n[0]:n:n}export{o as __BROWSER_PROD__,f as __DEV__,p as isComponent,c as isMemo,_ as isProvider,u as isResource,y as isSignal,s as isSuspense,i as makeArrayFlat};
1
+ // src/lib/signal/graph/detect.ts
2
+ var __BROWSER_PROD__ = typeof window === "undefined" ? false : window.__FLUIXI_PROD__ === true;
3
+ var __DEV__ = typeof process === "undefined" ? __BROWSER_PROD__ : false;
4
+ var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
5
+ var $MEMO = /* @__PURE__ */ Symbol.for("memo");
6
+ var $RESOURCE = /* @__PURE__ */ Symbol.for("resource");
7
+ function isSignal(value) {
8
+ return typeof value === "function" && value[$SIGNAL] === true;
9
+ }
10
+ function isMemo(value) {
11
+ return typeof value === "function" && value[$MEMO] === true;
12
+ }
13
+ function isResource(value) {
14
+ return typeof value === "function" && value[$RESOURCE] === true;
15
+ }
16
+ function isComponent(value) {
17
+ return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-component")] === true;
18
+ }
19
+ function isSuspense(value) {
20
+ return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-suspense")] === true;
21
+ }
22
+ function isProvider(value) {
23
+ return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-provider")] === true;
24
+ }
25
+ function makeArrayFlat(values) {
26
+ if (!Array.isArray(values)) return values;
27
+ if (values.length === 2 && values[1] === " ") {
28
+ if (Array.isArray(values[0])) return makeArrayFlat(values[0]);
29
+ if (typeof values[0] === "function") return values[0];
30
+ return values[0];
31
+ }
32
+ if (values.length === 1 && typeof values[0] === "function") return values[0];
33
+ return values;
34
+ }
35
+ export {
36
+ __BROWSER_PROD__,
37
+ __DEV__,
38
+ isComponent,
39
+ isMemo,
40
+ isProvider,
41
+ isResource,
42
+ isSignal,
43
+ isSuspense,
44
+ makeArrayFlat
45
+ };