@fluixi/reactive 1.0.0-alpha.82 → 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 (169) hide show
  1. package/README.md +4 -0
  2. package/dist/cdn/reactive.cjs +2673 -1
  3. package/dist/cdn/reactive.global.js +2 -1
  4. package/dist/cdn/reactive.mjs +2657 -1
  5. package/dist/cdn/signal.cjs +299 -1
  6. package/dist/cdn/signal.d.ts +1 -1
  7. package/dist/cdn/signal.global.js +2 -1
  8. package/dist/cdn/signal.js +1 -1
  9. package/dist/cdn/signal.mjs +276 -1
  10. package/dist/index.cjs +2673 -1
  11. package/dist/index.mjs +2657 -1
  12. package/dist/lib/index.cjs +2674 -1
  13. package/dist/lib/index.js +1 -1
  14. package/dist/lib/index.mjs +2659 -1
  15. package/dist/lib/observable/index.cjs +386 -1
  16. package/dist/lib/observable/index.mjs +364 -1
  17. package/dist/lib/observable/observable.cjs +384 -1
  18. package/dist/lib/observable/observable.d.ts +0 -137
  19. package/dist/lib/observable/observable.d.ts.map +1 -1
  20. package/dist/lib/observable/observable.js +0 -71
  21. package/dist/lib/observable/observable.mjs +361 -1
  22. package/dist/lib/observable/subscription.cjs +180 -1
  23. package/dist/lib/observable/subscription.d.ts +0 -12
  24. package/dist/lib/observable/subscription.d.ts.map +1 -1
  25. package/dist/lib/observable/subscription.js +0 -12
  26. package/dist/lib/observable/subscription.mjs +157 -1
  27. package/dist/lib/observable/types.cjs +18 -1
  28. package/dist/lib/observable/types.d.ts.map +1 -1
  29. package/dist/lib/predicates.cjs +44 -1
  30. package/dist/lib/predicates.d.ts +2 -2
  31. package/dist/lib/predicates.js +2 -2
  32. package/dist/lib/predicates.mjs +23 -1
  33. package/dist/lib/signal/api.cjs +571 -1
  34. package/dist/lib/signal/api.d.ts +211 -1
  35. package/dist/lib/signal/api.d.ts.map +1 -1
  36. package/dist/lib/signal/api.js +207 -12
  37. package/dist/lib/signal/api.mjs +548 -1
  38. package/dist/lib/signal/cached-resource.cjs +672 -1
  39. package/dist/lib/signal/cached-resource.d.ts +28 -16
  40. package/dist/lib/signal/cached-resource.d.ts.map +1 -1
  41. package/dist/lib/signal/cached-resource.js +35 -29
  42. package/dist/lib/signal/cached-resource.mjs +650 -1
  43. package/dist/lib/signal/graph/children.cjs +325 -1
  44. package/dist/lib/signal/graph/children.js +1 -1
  45. package/dist/lib/signal/graph/children.mjs +302 -1
  46. package/dist/lib/signal/graph/compat.cjs +578 -1
  47. package/dist/lib/signal/graph/compat.d.ts +13 -13
  48. package/dist/lib/signal/graph/compat.d.ts.map +1 -1
  49. package/dist/lib/signal/graph/compat.js +51 -32
  50. package/dist/lib/signal/graph/compat.mjs +556 -1
  51. package/dist/lib/signal/graph/core.cjs +295 -1
  52. package/dist/lib/signal/graph/core.d.ts +28 -24
  53. package/dist/lib/signal/graph/core.d.ts.map +1 -1
  54. package/dist/lib/signal/graph/core.js +45 -31
  55. package/dist/lib/signal/graph/core.mjs +273 -1
  56. package/dist/lib/signal/graph/debounced.cjs +668 -1
  57. package/dist/lib/signal/graph/debounced.d.ts +5 -5
  58. package/dist/lib/signal/graph/debounced.d.ts.map +1 -1
  59. package/dist/lib/signal/graph/debounced.js +5 -5
  60. package/dist/lib/signal/graph/debounced.mjs +645 -1
  61. package/dist/lib/signal/graph/derived.cjs +496 -1
  62. package/dist/lib/signal/graph/derived.d.ts +1 -1
  63. package/dist/lib/signal/graph/derived.js +1 -1
  64. package/dist/lib/signal/graph/derived.mjs +473 -1
  65. package/dist/lib/signal/graph/detect.cjs +66 -1
  66. package/dist/lib/signal/graph/detect.mjs +45 -1
  67. package/dist/lib/signal/graph/error-boundary.cjs +301 -1
  68. package/dist/lib/signal/graph/error-boundary.js +3 -3
  69. package/dist/lib/signal/graph/error-boundary.mjs +278 -1
  70. package/dist/lib/signal/graph/index.cjs +305 -1
  71. package/dist/lib/signal/graph/index.d.ts +7 -6
  72. package/dist/lib/signal/graph/index.d.ts.map +1 -1
  73. package/dist/lib/signal/graph/index.js +7 -6
  74. package/dist/lib/signal/graph/index.mjs +283 -1
  75. package/dist/lib/signal/graph/observe.cjs +163 -0
  76. package/dist/lib/signal/graph/observe.d.ts +141 -0
  77. package/dist/lib/signal/graph/observe.d.ts.map +1 -0
  78. package/dist/lib/signal/graph/observe.js +149 -0
  79. package/dist/lib/signal/graph/observe.mjs +140 -0
  80. package/dist/lib/signal/graph/resource.cjs +620 -1
  81. package/dist/lib/signal/graph/resource.d.ts +1 -1
  82. package/dist/lib/signal/graph/resource.js +7 -8
  83. package/dist/lib/signal/graph/resource.mjs +597 -1
  84. package/dist/lib/signal/graph/runtime.cjs +501 -1
  85. package/dist/lib/signal/graph/runtime.d.ts +9 -9
  86. package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
  87. package/dist/lib/signal/graph/runtime.js +56 -37
  88. package/dist/lib/signal/graph/runtime.mjs +478 -1
  89. package/dist/lib/signal/graph/signal-next.cjs +1208 -1
  90. package/dist/lib/signal/graph/signal-next.d.ts +5 -5
  91. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
  92. package/dist/lib/signal/graph/signal-next.js +14 -12
  93. package/dist/lib/signal/graph/signal-next.mjs +1186 -1
  94. package/dist/lib/signal/graph/ssr-hooks.cjs +60 -1
  95. package/dist/lib/signal/graph/ssr-hooks.d.ts +6 -7
  96. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
  97. package/dist/lib/signal/graph/ssr-hooks.js +6 -7
  98. package/dist/lib/signal/graph/ssr-hooks.mjs +39 -1
  99. package/dist/lib/signal/graph/state.cjs +72 -1
  100. package/dist/lib/signal/graph/state.d.ts +43 -10
  101. package/dist/lib/signal/graph/state.d.ts.map +1 -1
  102. package/dist/lib/signal/graph/state.js +83 -21
  103. package/dist/lib/signal/graph/state.mjs +49 -1
  104. package/dist/lib/signal/graph/suspense.cjs +301 -1
  105. package/dist/lib/signal/graph/suspense.js +4 -4
  106. package/dist/lib/signal/graph/suspense.mjs +278 -1
  107. package/dist/lib/signal/index-legacy.cjs +2540 -1
  108. package/dist/lib/signal/index-legacy.d.ts +1 -1
  109. package/dist/lib/signal/index-legacy.js +1 -1
  110. package/dist/lib/signal/index-legacy.mjs +2518 -1
  111. package/dist/lib/signal/index.cjs +1275 -1
  112. package/dist/lib/signal/index.d.ts +5 -2
  113. package/dist/lib/signal/index.d.ts.map +1 -1
  114. package/dist/lib/signal/index.js +8 -3
  115. package/dist/lib/signal/index.mjs +1253 -1
  116. package/dist/lib/signal/list.cjs +549 -1
  117. package/dist/lib/signal/list.d.ts +5 -5
  118. package/dist/lib/signal/list.js +10 -10
  119. package/dist/lib/signal/list.mjs +526 -1
  120. package/dist/lib/signal/resource-api.cjs +626 -1
  121. package/dist/lib/signal/resource-api.d.ts +5 -5
  122. package/dist/lib/signal/resource-api.js +5 -5
  123. package/dist/lib/signal/resource-api.mjs +603 -1
  124. package/dist/lib/signal/signal.cjs +2023 -1
  125. package/dist/lib/signal/signal.d.ts +4 -4
  126. package/dist/lib/signal/signal.d.ts.map +1 -1
  127. package/dist/lib/signal/signal.js +22 -23
  128. package/dist/lib/signal/signal.mjs +2000 -1
  129. package/dist/lib/signal/types.cjs +38 -1
  130. package/dist/lib/signal/types.d.ts.map +1 -1
  131. package/dist/lib/signal/types.js +2 -2
  132. package/dist/lib/signal/types.mjs +17 -1
  133. package/dist/lib/signal/utilities.cjs +1012 -1
  134. package/dist/lib/signal/utilities.d.ts +0 -108
  135. package/dist/lib/signal/utilities.d.ts.map +1 -1
  136. package/dist/lib/signal/utilities.js +0 -158
  137. package/dist/lib/signal/utilities.mjs +990 -1
  138. package/dist/lib/store/api.cjs +612 -1
  139. package/dist/lib/store/api.d.ts +33 -0
  140. package/dist/lib/store/api.d.ts.map +1 -1
  141. package/dist/lib/store/api.js +41 -8
  142. package/dist/lib/store/api.mjs +596 -1
  143. package/dist/lib/store/index.cjs +691 -1
  144. package/dist/lib/store/index.js +1 -1
  145. package/dist/lib/store/index.mjs +676 -1
  146. package/dist/lib/store/setter.types.cjs +18 -1
  147. package/dist/lib/store/setter.types.d.ts +43 -3
  148. package/dist/lib/store/setter.types.d.ts.map +1 -1
  149. package/dist/lib/store/store.cjs +658 -1
  150. package/dist/lib/store/store.d.ts +72 -0
  151. package/dist/lib/store/store.d.ts.map +1 -1
  152. package/dist/lib/store/store.js +294 -11
  153. package/dist/lib/store/store.mjs +644 -1
  154. package/dist/lib/store/types.cjs +18 -1
  155. package/dist/lib/store/types.d.ts +1 -1
  156. package/dist/lib/store/types.d.ts.map +1 -1
  157. package/dist/lib/store/utils.cjs +43 -1
  158. package/dist/lib/store/utils.d.ts +1 -1
  159. package/dist/lib/store/utils.js +1 -1
  160. package/dist/lib/store/utils.mjs +22 -1
  161. package/dist/lib/subject.cjs +450 -1
  162. package/dist/lib/subject.js +3 -91
  163. package/dist/lib/subject.mjs +427 -1
  164. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  165. package/dist/version.generated.cjs +27 -1
  166. package/dist/version.generated.d.ts +1 -1
  167. package/dist/version.generated.js +2 -2
  168. package/dist/version.generated.mjs +7 -1
  169. package/package.json +5 -4
@@ -1 +1,626 @@
1
- "use strict";var A=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var fe=Object.prototype.hasOwnProperty;var pe=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},he=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of de(t))!fe.call(e,s)&&s!==n&&A(e,s,{get:()=>t[s],enumerable:!(o=le(t,s))||o.enumerable});return e};var ve=e=>he(A({},"__esModule",{value:!0}),e);var Re={};pe(Re,{resource:()=>ke});module.exports=ve(Re);var Te="__fluixi_signal_next_state__",we=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[Te]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:we,onSuspend:null,onError:null};var F=0,K=1,v=2,k=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))}},R=class extends k{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++,this.observers)for(let n of[...this.observers])n.markDirty(v);C(this)}}peek(){return this._value}},T=class extends k{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=v;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===K&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===v)break}(this.state===v||!this._initialized)&&this.recompute(),this.state=F}recompute(){if(this.sources){for(let c of this.sources)c.observers?.delete(this);this.sources.clear()}let n=r.consumer,o=r.untracked;r.consumer=this,r.untracked=!1;let s,i=!1,a;try{s=this._fn()}catch(c){i=!0,a=c,s=this._value}finally{r.consumer=n,r.untracked=o}let w=!this._initialized||this._threw!==i||(i?a!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=a,this._value=s,w){if(this.version++,this.observers)for(let c of[...this.observers])c.markDirty(v);C(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===F;if(this.state=n,o){if(this.observers)for(let s of[...this.observers])s.markDirty(K);C(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function C(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var _=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 L(e){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function ye(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function N(e,t){let n=r.owner;r.owner=e;try{return t()}finally{r.owner=n}}function j(e){if(r.owner){if(r.owner.disposed){e();return}(r.owner.cleanups??=[]).push(e)}}function E(e,t=!0){if(!e.disposed){if(e.owned){for(let n=e.owned.length-1;n>=0;n--)E(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 U(e){r.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function me(e){e.queued||(e.queued=!0,r.queue.push(e),!r.scheduled&&r.batchDepth===0&&(r.scheduled=!0,r.hostSchedule(O)))}function O(){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 Y(){r.batchDepth===0&&O()}function $(e){r.batchDepth++;try{return e()}finally{--r.batchDepth===0&&O()}}var I=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=ye(r.owner),r.owner&&(r.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new T(()=>{E(this.owner,!1),N(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new _(()=>me(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,this.watcher.unwatch(this.computed),E(this.owner))}};function B(e){let t=new I(e);return()=>t.dispose()}U(()=>{});var Se=Symbol.for("signal");var ge=Symbol.for("signal-node");function h(e,t){let n=new R(e,{equals:t?.equals}),o=(()=>n.get()),s=(i=>{let a=typeof i=="function"?i(n.peek()):i;return n.set(a),Y(),a});return Object.defineProperty(o,Se,{value:!0,enumerable:!0}),Object.defineProperty(o,ge,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[o,s]}function J(e,t){let n=t;return B(()=>{n=e(n)})}function d(e){return $(e)}function V(e){return L(e)}var Q=null;function te(e){Q&&Q(e)}var X=null;function ne(e){return X?X(e):void 0}var Z=null;function re(){return Z?Z():void 0}var ee=null;function oe(e,t){ee&&ee(e,t)}function xe(e){return!!e&&typeof e.then=="function"}var M=Symbol();function se(e,t,n={}){let o,s;typeof t=="function"?(o=typeof e=="function"?e:()=>e,s=t):(o=()=>!0,s=e,t&&typeof t=="object"&&(n=t));let i=n.transport===!1?void 0:re(),a=i!==void 0?ne(i):void 0,w=a!==void 0,[c,P]=h(a!==void 0?a.value:n.initialValue,{equals:!1}),[G,y]=h(void 0,{equals:!1}),[q,f]=h(a!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[ie,p]=h(void 0,{equals:!1}),[ue,ae]=h(void 0,{equals:!1}),m=M,D=!1;J(()=>{let u=o();if(ue(),u===!1||u===null||u===void 0){m=M,d(()=>{f("unresolved"),p(void 0),y(void 0)});return}let S=D;if(D=!1,m!==M&&u===m&&!S)return;if(m=u,w){w=!1;return}let g=!1;j(()=>g=!0);let z=V(q),ce=V(c),H=z==="ready"||z==="refreshing";d(()=>{f(H?"refreshing":"pending"),y(void 0)});try{let l=s(u,{value:ce,refetching:H});xe(l)?(p(l),te(l),l.then(x=>{g||(i!==void 0&&oe(i,x),d(()=>{P(()=>x),f("ready"),p(void 0)}))},x=>{g||d(()=>{y(x),f("errored"),p(void 0)})})):d(()=>{P(()=>l),f("ready"),p(void 0)})}catch(l){if(g)return;d(()=>{y(l),f("errored"),p(void 0)})}});let W=()=>{let u=q();return u==="pending"||u==="refreshing"},b=(()=>{let u=G();if(u)throw u;if(W()){let S=ie();if(S)throw S}return c()});return Object.defineProperties(b,{state:{get:q},loading:{get:W},error:{get:G},latest:{get:c}}),Object.defineProperty(b,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(b,Symbol.for("signal"),{value:!0,enumerable:!0}),[b,{mutate:P,refetch:()=>{D=!0,ae(void 0)}}]}function ke(...e){let[t,n]=se(...e);return Object.assign(t,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/resource-api.ts
21
+ var resource_api_exports = {};
22
+ __export(resource_api_exports, {
23
+ resource: () => resource
24
+ });
25
+ module.exports = __toCommonJS(resource_api_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 reportReactiveWrite(node, by) {
98
+ G.observer?.wrote?.(node, by);
99
+ }
100
+ function reportReactiveDispose(node) {
101
+ G.observer?.disposed?.(node);
102
+ }
103
+ var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
104
+ var hook = globalThis[HOOK];
105
+ if (typeof hook?.inject === "function") {
106
+ try {
107
+ hook.inject({ observeReactiveNodes, version: VERSION });
108
+ } catch {
109
+ }
110
+ }
111
+ function isObserved() {
112
+ return G.observer != null;
113
+ }
114
+
115
+ // src/lib/signal/graph/core.ts
116
+ var CLEAN = 0;
117
+ var CHECK = 1;
118
+ var DIRTY = 2;
119
+ var Source = class {
120
+ constructor() {
121
+ /** Computeds, and watched leaves, that read this node. */
122
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
+ this.observers = null;
124
+ /** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
125
+ this.watchers = null;
126
+ /** Bumped whenever this node's value actually changes (equality-gated). */
127
+ this.version = 0;
128
+ }
129
+ /** Settle this node so a reader sees a current value/version. Overridden by Computed. */
130
+ updateIfNecessary() {
131
+ }
132
+ /** Link the current consumer (if any) as an observer of this node. */
133
+ track() {
134
+ if (G.untracked) return;
135
+ const consumer = G.consumer;
136
+ if (!consumer) return;
137
+ (this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
138
+ (consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
139
+ }
140
+ };
141
+ var State = class extends Source {
142
+ constructor(value, options) {
143
+ super();
144
+ this._value = value;
145
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
146
+ }
147
+ get() {
148
+ this.track();
149
+ return this._value;
150
+ }
151
+ set(next) {
152
+ if (this._equals(this._value, next)) return;
153
+ this._value = next;
154
+ this.version++;
155
+ reportReactiveWrite(this, G.consumer);
156
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
157
+ notifyWatchers(this);
158
+ }
159
+ /** Read without subscribing (peek). */
160
+ peek() {
161
+ return this._value;
162
+ }
163
+ };
164
+ var Computed = class extends Source {
165
+ constructor(fn, options) {
166
+ super();
167
+ this._threw = false;
168
+ this._initialized = false;
169
+ this.state = DIRTY;
170
+ /** Nodes this computation read on its last run. Rebuilt on every run. */
171
+ this.sources = null;
172
+ this._fn = fn;
173
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
174
+ }
175
+ get() {
176
+ if (G.consumer === this) {
177
+ throw new Error("Signal.Computed cannot read itself");
178
+ }
179
+ this.track();
180
+ this.updateIfNecessary();
181
+ if (this._threw) throw this._error;
182
+ return this._value;
183
+ }
184
+ /** Settle, if CHECK, verify sources; if DIRTY (or never run), recompute. */
185
+ updateIfNecessary() {
186
+ if (this.state === CHECK) {
187
+ if (this.sources) {
188
+ for (const s of this.sources) {
189
+ s.updateIfNecessary();
190
+ if (this.state === DIRTY) break;
191
+ }
192
+ }
193
+ }
194
+ if (this.state === DIRTY || !this._initialized) this.recompute();
195
+ this.state = CLEAN;
196
+ }
197
+ recompute() {
198
+ if (this.sources) {
199
+ for (const s of this.sources) s.observers?.delete(this);
200
+ this.sources.clear();
201
+ }
202
+ const prevConsumer = G.consumer;
203
+ const prevUntracked = G.untracked;
204
+ const watched = enterReactiveRun(this);
205
+ G.consumer = this;
206
+ G.untracked = false;
207
+ let next;
208
+ let threw = false;
209
+ let err;
210
+ try {
211
+ next = this._fn();
212
+ } catch (e) {
213
+ threw = true;
214
+ err = e;
215
+ next = this._value;
216
+ } finally {
217
+ G.consumer = prevConsumer;
218
+ G.untracked = prevUntracked;
219
+ if (watched) exitReactiveRun();
220
+ }
221
+ const changed = !this._initialized || this._threw !== threw || (threw ? err !== this._error : !this._equals(this._value, next));
222
+ this._initialized = true;
223
+ this._threw = threw;
224
+ this._error = err;
225
+ this._value = next;
226
+ reportReactiveRun(this);
227
+ if (changed) {
228
+ this.version++;
229
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
230
+ notifyWatchers(this);
231
+ }
232
+ }
233
+ /**
234
+ * Push a maybe-dirty mark. A direct observer of a changed node gets DIRTY; its
235
+ * own observers get CHECK (recurse), stopping where already marked, so the
236
+ * push is O(newly-dirtied) and never recomputes.
237
+ */
238
+ markDirty(level) {
239
+ if (this.state >= level) return;
240
+ const wasClean = this.state === CLEAN;
241
+ this.state = level;
242
+ if (wasClean) {
243
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(CHECK);
244
+ notifyWatchers(this);
245
+ }
246
+ }
247
+ peek() {
248
+ this.updateIfNecessary();
249
+ if (this._threw) throw this._error;
250
+ return this._value;
251
+ }
252
+ };
253
+ function notifyWatchers(node) {
254
+ if (!node.watchers) return;
255
+ for (const w of [...node.watchers]) w._notify(node);
256
+ }
257
+ var Watcher = class {
258
+ constructor(notify) {
259
+ this._watched = /* @__PURE__ */ new Set();
260
+ this._pending = /* @__PURE__ */ new Set();
261
+ this._notifyFn = notify;
262
+ }
263
+ watch(...nodes) {
264
+ for (const n of nodes) {
265
+ this._watched.add(n);
266
+ (n.watchers ??= /* @__PURE__ */ new Set()).add(this);
267
+ }
268
+ }
269
+ unwatch(...nodes) {
270
+ for (const n of nodes) {
271
+ this._watched.delete(n);
272
+ n.watchers?.delete(this);
273
+ this._pending.delete(n);
274
+ }
275
+ }
276
+ /** Watched nodes that may have changed since the last getPending(). */
277
+ getPending() {
278
+ const out = [...this._pending];
279
+ this._pending.clear();
280
+ return out;
281
+ }
282
+ /** @internal, a watched node became non-clean. Edge-triggered: notify once. */
283
+ _notify(node) {
284
+ if (!this._watched.has(node) || this._pending.has(node)) return;
285
+ const wasEmpty = this._pending.size === 0;
286
+ this._pending.add(node);
287
+ if (wasEmpty) this._notifyFn();
288
+ }
289
+ };
290
+ function untrack(fn) {
291
+ if (G.untracked) return fn();
292
+ G.untracked = true;
293
+ try {
294
+ return fn();
295
+ } finally {
296
+ G.untracked = false;
297
+ }
298
+ }
299
+
300
+ // src/lib/signal/graph/runtime.ts
301
+ function makeOwner(parent) {
302
+ return { cleanups: null, owned: null, parent, contexts: null };
303
+ }
304
+ function runWithOwner(owner, fn) {
305
+ const prev = G.owner;
306
+ G.owner = owner;
307
+ try {
308
+ return fn();
309
+ } finally {
310
+ G.owner = prev;
311
+ }
312
+ }
313
+ function onCleanup(fn) {
314
+ if (!G.owner) return;
315
+ if (G.owner.disposed) {
316
+ fn();
317
+ return;
318
+ }
319
+ (G.owner.cleanups ??= []).push(fn);
320
+ }
321
+ function disposeOwner(owner, final = true) {
322
+ if (owner.disposed) return;
323
+ if (owner.owned) {
324
+ for (let i = owner.owned.length - 1; i >= 0; i--) disposeOwner(owner.owned[i]);
325
+ owner.owned = null;
326
+ }
327
+ if (owner.cleanups) {
328
+ for (let i = owner.cleanups.length - 1; i >= 0; i--) owner.cleanups[i]();
329
+ owner.cleanups = null;
330
+ }
331
+ if (final) owner.disposed = true;
332
+ }
333
+ function setScheduler(fn) {
334
+ G.hostSchedule = fn ?? ((run) => void Promise.resolve().then(run));
335
+ }
336
+ function enqueue(e) {
337
+ if (e.queued) return;
338
+ e.queued = true;
339
+ G.queue.push(e);
340
+ if (!G.scheduled && G.batchDepth === 0) {
341
+ G.scheduled = true;
342
+ G.hostSchedule(flushSync);
343
+ }
344
+ }
345
+ function flushSync() {
346
+ G.scheduled = false;
347
+ if (G.flushing) return;
348
+ G.flushing = true;
349
+ let guard = 0;
350
+ try {
351
+ while (G.queue.length) {
352
+ if (++guard > 1e5) throw new Error("[fluixi] effect flush did not settle (cycle?)");
353
+ const batchOf = G.queue;
354
+ G.queue = [];
355
+ for (const e of batchOf) {
356
+ e.queued = false;
357
+ if (!e.disposed) e.run();
358
+ }
359
+ }
360
+ } finally {
361
+ G.flushing = false;
362
+ }
363
+ }
364
+ function afterWrite() {
365
+ if (G.batchDepth === 0) flushSync();
366
+ }
367
+ function batch(fn) {
368
+ G.batchDepth++;
369
+ try {
370
+ return fn();
371
+ } finally {
372
+ if (--G.batchDepth === 0) flushSync();
373
+ }
374
+ }
375
+ var EffectNode = class {
376
+ constructor(fn, report = false) {
377
+ this.queued = false;
378
+ this.disposed = false;
379
+ this.owner = makeOwner(G.owner);
380
+ if (G.owner) (G.owner.cleanups ??= []).push(() => this.dispose());
381
+ this.computed = new Computed(() => {
382
+ disposeOwner(this.owner, false);
383
+ runWithOwner(this.owner, () => {
384
+ const r = fn();
385
+ if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
386
+ });
387
+ });
388
+ reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report });
389
+ this.watcher = new Watcher(() => enqueue(this));
390
+ this.run();
391
+ this.watcher.watch(this.computed);
392
+ }
393
+ run() {
394
+ if (this.disposed) return;
395
+ this.watcher.getPending();
396
+ try {
397
+ this.computed.get();
398
+ } catch (e) {
399
+ if (e && typeof e.then === "function" && G.onSuspend) {
400
+ G.onSuspend(e, this.owner);
401
+ return;
402
+ }
403
+ if (G.onError && G.onError(e, this.owner)) return;
404
+ throw e;
405
+ }
406
+ }
407
+ dispose() {
408
+ if (this.disposed) return;
409
+ this.disposed = true;
410
+ reportReactiveDispose(this.computed);
411
+ this.watcher.unwatch(this.computed);
412
+ disposeOwner(this.owner);
413
+ }
414
+ };
415
+ function effect(fn, report = false) {
416
+ const node = new EffectNode(fn, report);
417
+ return () => node.dispose();
418
+ }
419
+
420
+ // src/lib/signal/graph/compat.ts
421
+ setScheduler(() => {
422
+ });
423
+ var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
424
+ var $NODE = /* @__PURE__ */ Symbol.for("signal-node");
425
+ function createSignal(value, options) {
426
+ const state = new State(value, { equals: options?.equals });
427
+ const read = (() => state.get());
428
+ const write = ((next) => {
429
+ const v = typeof next === "function" ? next(state.peek()) : next;
430
+ state.set(v);
431
+ afterWrite();
432
+ return v;
433
+ });
434
+ Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
435
+ Object.defineProperty(read, $NODE, {
436
+ value: {
437
+ get value() {
438
+ return state.peek();
439
+ },
440
+ get version() {
441
+ return state.version;
442
+ }
443
+ },
444
+ enumerable: false
445
+ });
446
+ reportReactiveNode({
447
+ kind: "signal",
448
+ node: state,
449
+ handle: read,
450
+ name: options?.name,
451
+ set: write
452
+ });
453
+ if (isObserved()) onCleanup(() => reportReactiveDispose(state));
454
+ return [read, write];
455
+ }
456
+ function createEffect(fn, value) {
457
+ let prev = value;
458
+ return effect(() => {
459
+ const r = fn(prev);
460
+ prev = r;
461
+ }, true);
462
+ }
463
+ function batch2(fn) {
464
+ return batch(fn);
465
+ }
466
+ function untrack2(fn) {
467
+ return untrack(fn);
468
+ }
469
+
470
+ // src/lib/signal/graph/ssr-hooks.ts
471
+ var _resourceTracker = null;
472
+ function trackResourcePromise(p) {
473
+ if (_resourceTracker) _resourceTracker(p);
474
+ }
475
+ var _serverDataGetter = null;
476
+ function getServerData(id) {
477
+ return _serverDataGetter ? _serverDataGetter(id) : void 0;
478
+ }
479
+ var _resourceIdSource = null;
480
+ function nextResourceId() {
481
+ return _resourceIdSource ? _resourceIdSource() : void 0;
482
+ }
483
+ var _resourceDataSink = null;
484
+ function reportResourceData(id, value) {
485
+ if (_resourceDataSink) _resourceDataSink(id, value);
486
+ }
487
+
488
+ // src/lib/signal/graph/resource.ts
489
+ function isPromise(v) {
490
+ return !!v && typeof v.then === "function";
491
+ }
492
+ var UNSET = /* @__PURE__ */ Symbol();
493
+ function createResource(source, fetcherFn, options = {}) {
494
+ let s;
495
+ let fetcher;
496
+ if (typeof fetcherFn === "function") {
497
+ s = typeof source === "function" ? source : () => source;
498
+ fetcher = fetcherFn;
499
+ } else {
500
+ s = () => true;
501
+ fetcher = source;
502
+ if (fetcherFn && typeof fetcherFn === "object") options = fetcherFn;
503
+ }
504
+ const ssrId = options.transport === false ? void 0 : nextResourceId();
505
+ const seed = ssrId !== void 0 ? getServerData(ssrId) : void 0;
506
+ let skipFirstFetch = seed !== void 0;
507
+ const [value, setValue] = createSignal(
508
+ seed !== void 0 ? seed.value : options.initialValue,
509
+ { equals: false }
510
+ );
511
+ const [error, setError] = createSignal(void 0, { equals: false });
512
+ const [state, setState] = createSignal(
513
+ seed !== void 0 || options.initialValue !== void 0 ? "ready" : "unresolved",
514
+ { equals: false }
515
+ );
516
+ const [promise, setPromise] = createSignal(void 0, { equals: false });
517
+ const [track, trigger] = createSignal(void 0, { equals: false });
518
+ let prevKey = UNSET;
519
+ let manualRefetch = false;
520
+ createEffect(() => {
521
+ const val = s();
522
+ track();
523
+ if (val === false || val === null || val === void 0) {
524
+ prevKey = UNSET;
525
+ batch2(() => {
526
+ setState("unresolved");
527
+ setPromise(void 0);
528
+ setError(void 0);
529
+ });
530
+ return;
531
+ }
532
+ const isManual = manualRefetch;
533
+ manualRefetch = false;
534
+ if (prevKey !== UNSET && val === prevKey && !isManual) return;
535
+ prevKey = val;
536
+ if (skipFirstFetch) {
537
+ skipFirstFetch = false;
538
+ return;
539
+ }
540
+ let cancelled = false;
541
+ onCleanup(() => cancelled = true);
542
+ const currentState = untrack2(state);
543
+ const currentValue = untrack2(value);
544
+ const isRefreshing = currentState === "ready" || currentState === "refreshing";
545
+ batch2(() => {
546
+ setState(isRefreshing ? "refreshing" : "pending");
547
+ setError(void 0);
548
+ });
549
+ try {
550
+ const res = fetcher(val, { value: currentValue, refetching: isRefreshing });
551
+ if (isPromise(res)) {
552
+ setPromise(res);
553
+ trackResourcePromise(res);
554
+ res.then(
555
+ (v) => {
556
+ if (cancelled) return;
557
+ if (ssrId !== void 0) reportResourceData(ssrId, v);
558
+ batch2(() => {
559
+ setValue(() => v);
560
+ setState("ready");
561
+ setPromise(void 0);
562
+ });
563
+ },
564
+ (e) => {
565
+ if (cancelled) return;
566
+ batch2(() => {
567
+ setError(e);
568
+ setState("errored");
569
+ setPromise(void 0);
570
+ });
571
+ }
572
+ );
573
+ } else {
574
+ batch2(() => {
575
+ setValue(() => res);
576
+ setState("ready");
577
+ setPromise(void 0);
578
+ });
579
+ }
580
+ } catch (e) {
581
+ if (cancelled) return;
582
+ batch2(() => {
583
+ setError(e);
584
+ setState("errored");
585
+ setPromise(void 0);
586
+ });
587
+ }
588
+ });
589
+ const loading = () => {
590
+ const st = state();
591
+ return st === "pending" || st === "refreshing";
592
+ };
593
+ const resource2 = (() => {
594
+ const e = error();
595
+ if (e) throw e;
596
+ if (loading()) {
597
+ const p = promise();
598
+ if (p) throw p;
599
+ }
600
+ return value();
601
+ });
602
+ Object.defineProperties(resource2, {
603
+ state: { get: state },
604
+ loading: { get: loading },
605
+ error: { get: error },
606
+ latest: { get: value }
607
+ });
608
+ Object.defineProperty(resource2, /* @__PURE__ */ Symbol.for("resource"), { value: true, enumerable: true });
609
+ Object.defineProperty(resource2, /* @__PURE__ */ Symbol.for("signal"), { value: true, enumerable: true });
610
+ return [
611
+ resource2,
612
+ {
613
+ mutate: setValue,
614
+ refetch: () => {
615
+ manualRefetch = true;
616
+ trigger(void 0);
617
+ }
618
+ }
619
+ ];
620
+ }
621
+
622
+ // src/lib/signal/resource-api.ts
623
+ function resource(...args) {
624
+ const [read, actions] = createResource(...args);
625
+ return Object.assign(read, actions);
626
+ }
@@ -1,9 +1,9 @@
1
1
  /**
2
- * `resource` `createResource` as one binding instead of a tuple.
2
+ * `resource`: `createResource` as one binding instead of a tuple.
3
3
  *
4
4
  * const user = resource(userId, fetchUser);
5
5
  *
6
- * user(); // the value suspends under <Suspense>, exactly as before
6
+ * user(); // the value: suspends under <Suspense>, exactly as before
7
7
  * user.latest; // last settled value, kept across a refetch
8
8
  * user.loading; // boolean
9
9
  * user.error;
@@ -11,11 +11,11 @@
11
11
  * user.mutate(next);
12
12
  *
13
13
  * `createResource` already hands back a callable carrying `loading`/`error`/`latest`,
14
- * with only the two actions split into a second tuple slot so this mostly folds that
14
+ * with only the two actions split into a second tuple slot, so this mostly folds that
15
15
  * split away.
16
16
  *
17
- * The returned function IS the accessor `createResource` gave back, with the two actions
18
- * assigned onto it so suspending, tracking and SSR seeding are untouched, and a read is
17
+ * The returned function is the accessor `createResource` gave back, with the two actions
18
+ * assigned onto it, so suspending, tracking and SSR seeding are untouched, and a read is
19
19
  * the same call it always was.
20
20
  */
21
21
  import { createResource } from './graph/resource.js';
@@ -1,9 +1,9 @@
1
1
  /**
2
- * `resource` `createResource` as one binding instead of a tuple.
2
+ * `resource`: `createResource` as one binding instead of a tuple.
3
3
  *
4
4
  * const user = resource(userId, fetchUser);
5
5
  *
6
- * user(); // the value suspends under <Suspense>, exactly as before
6
+ * user(); // the value: suspends under <Suspense>, exactly as before
7
7
  * user.latest; // last settled value, kept across a refetch
8
8
  * user.loading; // boolean
9
9
  * user.error;
@@ -11,11 +11,11 @@
11
11
  * user.mutate(next);
12
12
  *
13
13
  * `createResource` already hands back a callable carrying `loading`/`error`/`latest`,
14
- * with only the two actions split into a second tuple slot so this mostly folds that
14
+ * with only the two actions split into a second tuple slot, so this mostly folds that
15
15
  * split away.
16
16
  *
17
- * The returned function IS the accessor `createResource` gave back, with the two actions
18
- * assigned onto it so suspending, tracking and SSR seeding are untouched, and a read is
17
+ * The returned function is the accessor `createResource` gave back, with the two actions
18
+ * assigned onto it, so suspending, tracking and SSR seeding are untouched, and a read is
19
19
  * the same call it always was.
20
20
  */
21
21
  import { createResource } from './graph/resource.js';