@fluixi/reactive 1.0.0-alpha.53

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 (176) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +343 -0
  3. package/dist/cdn/reactive.cjs +1 -0
  4. package/dist/cdn/reactive.d.ts +11 -0
  5. package/dist/cdn/reactive.d.ts.map +1 -0
  6. package/dist/cdn/reactive.global.js +1 -0
  7. package/dist/cdn/reactive.js +10 -0
  8. package/dist/cdn/reactive.mjs +1 -0
  9. package/dist/cdn/signal.cjs +1 -0
  10. package/dist/cdn/signal.d.ts +19 -0
  11. package/dist/cdn/signal.d.ts.map +1 -0
  12. package/dist/cdn/signal.global.js +1 -0
  13. package/dist/cdn/signal.js +18 -0
  14. package/dist/cdn/signal.mjs +1 -0
  15. package/dist/index.cjs +1 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +1 -0
  19. package/dist/index.mjs +1 -0
  20. package/dist/lib/index.cjs +1 -0
  21. package/dist/lib/index.d.ts +5 -0
  22. package/dist/lib/index.d.ts.map +1 -0
  23. package/dist/lib/index.js +4 -0
  24. package/dist/lib/index.mjs +1 -0
  25. package/dist/lib/observable/index.cjs +1 -0
  26. package/dist/lib/observable/index.d.ts +4 -0
  27. package/dist/lib/observable/index.d.ts.map +1 -0
  28. package/dist/lib/observable/index.js +3 -0
  29. package/dist/lib/observable/index.mjs +1 -0
  30. package/dist/lib/observable/observable.cjs +1 -0
  31. package/dist/lib/observable/observable.d.ts +383 -0
  32. package/dist/lib/observable/observable.d.ts.map +1 -0
  33. package/dist/lib/observable/observable.js +339 -0
  34. package/dist/lib/observable/observable.mjs +1 -0
  35. package/dist/lib/observable/subscription.cjs +1 -0
  36. package/dist/lib/observable/subscription.d.ts +70 -0
  37. package/dist/lib/observable/subscription.d.ts.map +1 -0
  38. package/dist/lib/observable/subscription.js +190 -0
  39. package/dist/lib/observable/subscription.mjs +1 -0
  40. package/dist/lib/observable/types.cjs +1 -0
  41. package/dist/lib/observable/types.d.ts +44 -0
  42. package/dist/lib/observable/types.d.ts.map +1 -0
  43. package/dist/lib/observable/types.js +1 -0
  44. package/dist/lib/observable/types.mjs +0 -0
  45. package/dist/lib/signal/cached-resource.cjs +1 -0
  46. package/dist/lib/signal/cached-resource.d.ts +94 -0
  47. package/dist/lib/signal/cached-resource.d.ts.map +1 -0
  48. package/dist/lib/signal/cached-resource.js +257 -0
  49. package/dist/lib/signal/cached-resource.mjs +1 -0
  50. package/dist/lib/signal/graph/children.cjs +1 -0
  51. package/dist/lib/signal/graph/children.d.ts +2 -0
  52. package/dist/lib/signal/graph/children.d.ts.map +1 -0
  53. package/dist/lib/signal/graph/children.js +30 -0
  54. package/dist/lib/signal/graph/children.mjs +1 -0
  55. package/dist/lib/signal/graph/compat.cjs +1 -0
  56. package/dist/lib/signal/graph/compat.d.ts +64 -0
  57. package/dist/lib/signal/graph/compat.d.ts.map +1 -0
  58. package/dist/lib/signal/graph/compat.js +178 -0
  59. package/dist/lib/signal/graph/compat.mjs +1 -0
  60. package/dist/lib/signal/graph/core.cjs +1 -0
  61. package/dist/lib/signal/graph/core.d.ts +95 -0
  62. package/dist/lib/signal/graph/core.d.ts.map +1 -0
  63. package/dist/lib/signal/graph/core.js +254 -0
  64. package/dist/lib/signal/graph/core.mjs +1 -0
  65. package/dist/lib/signal/graph/derived.cjs +1 -0
  66. package/dist/lib/signal/graph/derived.d.ts +14 -0
  67. package/dist/lib/signal/graph/derived.d.ts.map +1 -0
  68. package/dist/lib/signal/graph/derived.js +81 -0
  69. package/dist/lib/signal/graph/derived.mjs +1 -0
  70. package/dist/lib/signal/graph/detect.cjs +1 -0
  71. package/dist/lib/signal/graph/detect.d.ts +16 -0
  72. package/dist/lib/signal/graph/detect.d.ts.map +1 -0
  73. package/dist/lib/signal/graph/detect.js +36 -0
  74. package/dist/lib/signal/graph/detect.mjs +1 -0
  75. package/dist/lib/signal/graph/error-boundary.cjs +1 -0
  76. package/dist/lib/signal/graph/error-boundary.d.ts +16 -0
  77. package/dist/lib/signal/graph/error-boundary.d.ts.map +1 -0
  78. package/dist/lib/signal/graph/error-boundary.js +34 -0
  79. package/dist/lib/signal/graph/error-boundary.mjs +1 -0
  80. package/dist/lib/signal/graph/index.cjs +1 -0
  81. package/dist/lib/signal/graph/index.d.ts +21 -0
  82. package/dist/lib/signal/graph/index.d.ts.map +1 -0
  83. package/dist/lib/signal/graph/index.js +20 -0
  84. package/dist/lib/signal/graph/index.mjs +1 -0
  85. package/dist/lib/signal/graph/resource.cjs +1 -0
  86. package/dist/lib/signal/graph/resource.d.ts +36 -0
  87. package/dist/lib/signal/graph/resource.d.ts.map +1 -0
  88. package/dist/lib/signal/graph/resource.js +156 -0
  89. package/dist/lib/signal/graph/resource.mjs +1 -0
  90. package/dist/lib/signal/graph/runtime.cjs +1 -0
  91. package/dist/lib/signal/graph/runtime.d.ts +56 -0
  92. package/dist/lib/signal/graph/runtime.d.ts.map +1 -0
  93. package/dist/lib/signal/graph/runtime.js +277 -0
  94. package/dist/lib/signal/graph/runtime.mjs +1 -0
  95. package/dist/lib/signal/graph/signal-next.cjs +1 -0
  96. package/dist/lib/signal/graph/signal-next.d.ts +37 -0
  97. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -0
  98. package/dist/lib/signal/graph/signal-next.js +41 -0
  99. package/dist/lib/signal/graph/signal-next.mjs +1 -0
  100. package/dist/lib/signal/graph/ssr-hooks.cjs +1 -0
  101. package/dist/lib/signal/graph/ssr-hooks.d.ts +28 -0
  102. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -0
  103. package/dist/lib/signal/graph/ssr-hooks.js +45 -0
  104. package/dist/lib/signal/graph/ssr-hooks.mjs +1 -0
  105. package/dist/lib/signal/graph/state.cjs +1 -0
  106. package/dist/lib/signal/graph/state.d.ts +43 -0
  107. package/dist/lib/signal/graph/state.d.ts.map +1 -0
  108. package/dist/lib/signal/graph/state.js +37 -0
  109. package/dist/lib/signal/graph/state.mjs +1 -0
  110. package/dist/lib/signal/graph/suspense.cjs +1 -0
  111. package/dist/lib/signal/graph/suspense.d.ts +13 -0
  112. package/dist/lib/signal/graph/suspense.d.ts.map +1 -0
  113. package/dist/lib/signal/graph/suspense.js +36 -0
  114. package/dist/lib/signal/graph/suspense.mjs +1 -0
  115. package/dist/lib/signal/index-legacy.cjs +1 -0
  116. package/dist/lib/signal/index-legacy.d.ts +12 -0
  117. package/dist/lib/signal/index-legacy.d.ts.map +1 -0
  118. package/dist/lib/signal/index-legacy.js +11 -0
  119. package/dist/lib/signal/index-legacy.mjs +1 -0
  120. package/dist/lib/signal/index.cjs +1 -0
  121. package/dist/lib/signal/index.d.ts +12 -0
  122. package/dist/lib/signal/index.d.ts.map +1 -0
  123. package/dist/lib/signal/index.js +11 -0
  124. package/dist/lib/signal/index.mjs +1 -0
  125. package/dist/lib/signal/list.cjs +1 -0
  126. package/dist/lib/signal/list.d.ts +39 -0
  127. package/dist/lib/signal/list.d.ts.map +1 -0
  128. package/dist/lib/signal/list.js +172 -0
  129. package/dist/lib/signal/list.mjs +1 -0
  130. package/dist/lib/signal/signal.cjs +1 -0
  131. package/dist/lib/signal/signal.d.ts +295 -0
  132. package/dist/lib/signal/signal.d.ts.map +1 -0
  133. package/dist/lib/signal/signal.js +1219 -0
  134. package/dist/lib/signal/signal.mjs +1 -0
  135. package/dist/lib/signal/types.cjs +1 -0
  136. package/dist/lib/signal/types.d.ts +133 -0
  137. package/dist/lib/signal/types.d.ts.map +1 -0
  138. package/dist/lib/signal/types.js +38 -0
  139. package/dist/lib/signal/types.mjs +1 -0
  140. package/dist/lib/signal/utilities.cjs +1 -0
  141. package/dist/lib/signal/utilities.d.ts +355 -0
  142. package/dist/lib/signal/utilities.d.ts.map +1 -0
  143. package/dist/lib/signal/utilities.js +504 -0
  144. package/dist/lib/signal/utilities.mjs +1 -0
  145. package/dist/lib/store/index.cjs +1 -0
  146. package/dist/lib/store/index.d.ts +14 -0
  147. package/dist/lib/store/index.d.ts.map +1 -0
  148. package/dist/lib/store/index.js +11 -0
  149. package/dist/lib/store/index.mjs +1 -0
  150. package/dist/lib/store/setter.types.cjs +1 -0
  151. package/dist/lib/store/setter.types.d.ts +79 -0
  152. package/dist/lib/store/setter.types.d.ts.map +1 -0
  153. package/dist/lib/store/setter.types.js +65 -0
  154. package/dist/lib/store/setter.types.mjs +0 -0
  155. package/dist/lib/store/store.cjs +1 -0
  156. package/dist/lib/store/store.d.ts +86 -0
  157. package/dist/lib/store/store.d.ts.map +1 -0
  158. package/dist/lib/store/store.js +442 -0
  159. package/dist/lib/store/store.mjs +1 -0
  160. package/dist/lib/store/types.cjs +1 -0
  161. package/dist/lib/store/types.d.ts +57 -0
  162. package/dist/lib/store/types.d.ts.map +1 -0
  163. package/dist/lib/store/types.js +1 -0
  164. package/dist/lib/store/types.mjs +0 -0
  165. package/dist/lib/store/utils.cjs +1 -0
  166. package/dist/lib/store/utils.d.ts +13 -0
  167. package/dist/lib/store/utils.d.ts.map +1 -0
  168. package/dist/lib/store/utils.js +29 -0
  169. package/dist/lib/store/utils.mjs +1 -0
  170. package/dist/lib/subject.cjs +1 -0
  171. package/dist/lib/subject.d.ts +14 -0
  172. package/dist/lib/subject.d.ts.map +1 -0
  173. package/dist/lib/subject.js +169 -0
  174. package/dist/lib/subject.mjs +1 -0
  175. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  176. package/package.json +114 -0
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Derived signal utilities on the TC39 core: a keyed selector, a deferred
3
+ * (idle-scheduled) signal, and a debounce wrapper. They build their signals and
4
+ * effects on the TC39 graph (compat primitives) rather than the legacy signal.ts
5
+ * graph, so they track TC39 signals correctly.
6
+ */
7
+ import { createSignal, createEffect, onCleanup } from './compat.js';
8
+ /** Keyed selector: `selector(key)` is a fine-grained boolean that flips only when its own key's match changes. */
9
+ export function createSelector(source, fn = (k, v) => k === v) {
10
+ const map = new Map();
11
+ createEffect(() => {
12
+ const value = source();
13
+ for (const [key, signal] of map) {
14
+ const [get, set] = signal;
15
+ const match = fn(key, value);
16
+ if (get() !== match)
17
+ set(match);
18
+ }
19
+ });
20
+ return (key) => {
21
+ let signal = map.get(key);
22
+ if (!signal) {
23
+ const [get, set] = createSignal(false);
24
+ signal = [get, set];
25
+ map.set(key, signal);
26
+ const value = source();
27
+ set(fn(key, value));
28
+ }
29
+ return signal[0]();
30
+ };
31
+ }
32
+ /** A signal that tracks `source` but applies updates on idle/timeout, keeping the current UI responsive. */
33
+ export function createDeferred(source, options) {
34
+ const [delayed, setDelayed] = createSignal(source(), options);
35
+ createEffect(() => {
36
+ const v = source();
37
+ if (options?.timeoutMs)
38
+ setTimeout(() => setDelayed(() => v), options.timeoutMs);
39
+ else if (typeof requestIdleCallback === 'function')
40
+ requestIdleCallback(() => setDelayed(() => v));
41
+ else
42
+ Promise.resolve().then(() => setDelayed(() => v));
43
+ });
44
+ return delayed;
45
+ }
46
+ /**
47
+ * Debounce wrapper — delays invoking `fn` until `delay` ms after the last call.
48
+ * Pending timers are cancelled when the owning scope disposes (via onCleanup).
49
+ */
50
+ export function createDebounce(fn, delay) {
51
+ let timer;
52
+ const debounced = (...args) => {
53
+ if (timer !== undefined)
54
+ clearTimeout(timer);
55
+ timer = setTimeout(() => {
56
+ timer = undefined;
57
+ if (args.length > 0) {
58
+ let element = args[args.length - 1];
59
+ if (typeof element === 'object' &&
60
+ element &&
61
+ !element.tagName &&
62
+ element.target &&
63
+ element.target.tagName) {
64
+ element = element.target;
65
+ }
66
+ if (element &&
67
+ typeof element === 'object' &&
68
+ element.tagName &&
69
+ (element.tagName.toLowerCase() === 'input' ||
70
+ element.tagName.toLowerCase() === 'textarea'))
71
+ element.focus();
72
+ }
73
+ fn(...args);
74
+ }, delay);
75
+ };
76
+ onCleanup(() => {
77
+ if (timer !== undefined)
78
+ clearTimeout(timer);
79
+ });
80
+ return debounced;
81
+ }
@@ -0,0 +1 @@
1
+ var C="__fluixi_signal_next_state__",D=n=>{typeof queueMicrotask=="function"?queueMicrotask(n):Promise.resolve().then(n)},r=globalThis[C]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:D,onSuspend:null,onError:null};var S=0,_=1,c=2,f=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let e=r.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}},p=class extends f{constructor(e,t){super(),this._value=e,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(e){if(!this._equals(this._value,e)){if(this._value=e,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(c);w(this)}}peek(){return this._value}},d=class extends f{constructor(t,s){super();this._threw=!1;this._initialized=!1;this.state=c;this.sources=null;this._fn=t,this._equals=s?.equals===!1?()=>!1:s?.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===_&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===c)break}(this.state===c||!this._initialized)&&this.recompute(),this.state=S}recompute(){if(this.sources){for(let a of this.sources)a.observers?.delete(this);this.sources.clear()}let t=r.consumer,s=r.untracked;r.consumer=this,r.untracked=!1;let i,o=!1,u;try{i=this._fn()}catch(a){o=!0,u=a,i=this._value}finally{r.consumer=t,r.untracked=s}let l=!this._initialized||this._threw!==o||(o?u!==this._error:!this._equals(this._value,i));if(this._initialized=!0,this._threw=o,this._error=u,this._value=i,l){if(this.version++,this.observers)for(let a of[...this.observers])a.markDirty(c);w(this)}}markDirty(t){if(this.state>=t)return;let s=this.state===S;if(this.state=t,s){if(this.observers)for(let i of[...this.observers])i.markDirty(_);w(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function w(n){if(n.watchers)for(let e of[...n.watchers])e._notify(n)}var h=class{constructor(e){this._watched=new Set;this._pending=new Set;this._notifyFn=e}watch(...e){for(let t of e)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...e){for(let t of e)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let e=[...this._pending];return this._pending.clear(),e}_notify(e){if(!this._watched.has(e)||this._pending.has(e))return;let t=this._pending.size===0;this._pending.add(e),t&&this._notifyFn()}};function P(n){return{cleanups:null,owned:null,parent:n,contexts:null}}function m(n,e){let t=r.owner;r.owner=n;try{return e()}finally{r.owner=t}}function y(n){r.owner&&(r.owner.cleanups??=[]).push(n)}function v(n){if(n.owned){for(let e=n.owned.length-1;e>=0;e--)v(n.owned[e]);n.owned=null}if(n.cleanups){for(let e=n.cleanups.length-1;e>=0;e--)n.cleanups[e]();n.cleanups=null}}function k(n){r.hostSchedule=n??(e=>{Promise.resolve().then(e)})}function A(n){n.queued||(n.queued=!0,r.queue.push(n),!r.scheduled&&r.batchDepth===0&&(r.scheduled=!0,r.hostSchedule(b)))}function b(){if(r.scheduled=!1,r.flushing)return;r.flushing=!0;let n=0;try{for(;r.queue.length;){if(++n>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let e=r.queue;r.queue=[];for(let t of e)t.queued=!1,t.disposed||t.run()}}finally{r.flushing=!1}}function O(){r.batchDepth===0&&b()}var T=class{constructor(e){this.queued=!1;this.disposed=!1;this.owner=P(r.owner),r.owner&&(r.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new d(()=>{v(this.owner),m(this.owner,()=>{let t=e();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new h(()=>A(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(e){if(e&&typeof e.then=="function"&&r.onSuspend){r.onSuspend(e,this.owner);return}if(r.onError&&r.onError(e,this.owner))return;throw e}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),v(this.owner))}};function q(n){let e=new T(n);return()=>e.dispose()}k(()=>{});var N=Symbol.for("signal");var R=Symbol.for("signal-node");function g(n,e){let t=new p(n,{equals:e?.equals}),s=(()=>t.get()),i=(o=>{let u=typeof o=="function"?o(t.peek()):o;return t.set(u),O(),u});return Object.defineProperty(s,N,{value:!0,enumerable:!0}),Object.defineProperty(s,R,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[s,i]}function x(n,e){let t=e;return q(()=>{t=n(t)})}function Q(n,e=(t,s)=>t===s){let t=new Map;return x(()=>{let s=n();for(let[i,o]of t){let[u,l]=o,a=e(i,s);u()!==a&&l(a)}}),s=>{let i=t.get(s);if(!i){let[o,u]=g(!1);i=[o,u],t.set(s,i);let l=n();u(e(s,l))}return i[0]()}}function X(n,e){let[t,s]=g(n(),e);return x(()=>{let i=n();e?.timeoutMs?setTimeout(()=>s(()=>i),e.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>s(()=>i)):Promise.resolve().then(()=>s(()=>i))}),t}function Z(n,e){let t,s=(...i)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{if(t=void 0,i.length>0){let o=i[i.length-1];typeof o=="object"&&o&&!o.tagName&&o.target&&o.target.tagName&&(o=o.target),o&&typeof o=="object"&&o.tagName&&(o.tagName.toLowerCase()==="input"||o.tagName.toLowerCase()==="textarea")&&o.focus()}n(...i)},e)};return y(()=>{t!==void 0&&clearTimeout(t)}),s}export{Z as createDebounce,X as createDeferred,Q as createSelector};
@@ -0,0 +1 @@
1
+ "use strict";var e=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var p=(n,o)=>{for(var t in o)e(n,t,{get:o[t],enumerable:!0})},s=(n,o,t,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of y(o))!u.call(n,r)&&r!==t&&e(n,r,{get:()=>o[r],enumerable:!(i=c(o,r))||i.enumerable});return n};var m=n=>s(e({},"__esModule",{value:!0}),n);var d={};p(d,{__DEV__:()=>a,isComponent:()=>g,isMemo:()=>E,isProvider:()=>_,isResource:()=>T,isSignal:()=>A,isSuspense:()=>R,makeArrayFlat:()=>f});module.exports=m(d);var a=!1,x=Symbol.for("signal"),S=Symbol.for("memo"),b=Symbol.for("resource");function A(n){return typeof n=="function"&&n[x]===!0}function E(n){return typeof n=="function"&&n[S]===!0}function T(n){return typeof n=="function"&&n[b]===!0}function g(n){return typeof n=="function"&&n[Symbol.for("fluixi-component")]===!0}function R(n){return typeof n=="function"&&n[Symbol.for("fluixi-suspense")]===!0}function _(n){return typeof n=="function"&&n[Symbol.for("fluixi-provider")]===!0}function f(n){return Array.isArray(n)?n.length===2&&n[1]===" "?Array.isArray(n[0])?f(n[0]):(typeof n[0]=="function",n[0]):n.length===1&&typeof n[0]=="function"?n[0]:n:n}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Signal detection guards + small helpers. Graph-agnostic: they check global
3
+ * Symbol.for markers, which both the TC39 core and the legacy signal.ts stamp,
4
+ * so a value is recognised regardless of which graph made it. Kept out of
5
+ * signal.ts so it survives once that file is retired.
6
+ */
7
+ import type { Accessor, Resource } from '../signal.js';
8
+ export declare const __DEV__: boolean;
9
+ export declare function isSignal<T = any>(value: any): value is Accessor<T>;
10
+ export declare function isMemo<T = any>(value: any): value is Accessor<T>;
11
+ export declare function isResource<T = any>(value: any): value is Resource<T>;
12
+ export declare function isComponent(value: any): boolean;
13
+ export declare function isSuspense(value: any): boolean;
14
+ export declare function isProvider(value: any): boolean;
15
+ export declare function makeArrayFlat(values: any[]): any;
16
+ //# sourceMappingURL=detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../../../src/lib/signal/graph/detect.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEvD,eAAO,MAAM,OAAO,SAAwC,CAAC;AAM7D,wBAAgB,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAElE;AAED,wBAAgB,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAEpE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAE/C;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAE9C;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAE9C;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,CAShD"}
@@ -0,0 +1,36 @@
1
+ export const __DEV__ = process.env.NODE_ENV !== 'production';
2
+ const $SIGNAL = Symbol.for('signal');
3
+ const $MEMO = Symbol.for('memo');
4
+ const $RESOURCE = Symbol.for('resource');
5
+ export function isSignal(value) {
6
+ return typeof value === 'function' && value[$SIGNAL] === true;
7
+ }
8
+ export function isMemo(value) {
9
+ return typeof value === 'function' && value[$MEMO] === true;
10
+ }
11
+ export function isResource(value) {
12
+ return typeof value === 'function' && value[$RESOURCE] === true;
13
+ }
14
+ export function isComponent(value) {
15
+ return typeof value === 'function' && value[Symbol.for('fluixi-component')] === true;
16
+ }
17
+ export function isSuspense(value) {
18
+ return typeof value === 'function' && value[Symbol.for('fluixi-suspense')] === true;
19
+ }
20
+ export function isProvider(value) {
21
+ return typeof value === 'function' && value[Symbol.for('fluixi-provider')] === true;
22
+ }
23
+ export function makeArrayFlat(values) {
24
+ if (!Array.isArray(values))
25
+ return values;
26
+ if (values.length === 2 && values[1] === ' ') {
27
+ if (Array.isArray(values[0]))
28
+ return makeArrayFlat(values[0]);
29
+ if (typeof values[0] === 'function')
30
+ return values[0];
31
+ return values[0];
32
+ }
33
+ if (values.length === 1 && typeof values[0] === 'function')
34
+ return values[0];
35
+ return values;
36
+ }
@@ -0,0 +1 @@
1
+ var i=!1,o=Symbol.for("signal"),r=Symbol.for("memo"),t=Symbol.for("resource");function f(n){return typeof n=="function"&&n[o]===!0}function c(n){return typeof n=="function"&&n[r]===!0}function y(n){return typeof n=="function"&&n[t]===!0}function u(n){return typeof n=="function"&&n[Symbol.for("fluixi-component")]===!0}function p(n){return typeof n=="function"&&n[Symbol.for("fluixi-suspense")]===!0}function s(n){return typeof n=="function"&&n[Symbol.for("fluixi-provider")]===!0}function e(n){return Array.isArray(n)?n.length===2&&n[1]===" "?Array.isArray(n[0])?e(n[0]):(typeof n[0]=="function",n[0]):n.length===1&&typeof n[0]=="function"?n[0]:n:n}export{i as __DEV__,u as isComponent,c as isMemo,s as isProvider,y as isResource,f as isSignal,p as isSuspense,e as makeArrayFlat};
@@ -0,0 +1 @@
1
+ "use strict";var a=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var k=(r,e)=>{for(var t in e)a(r,t,{get:e[t],enumerable:!0})},g=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of S(e))!_.call(r,s)&&s!==t&&a(r,s,{get:()=>e[s],enumerable:!(o=x(e,s))||o.enumerable});return r};var O=r=>g(a({},"__esModule",{value:!0}),r);var I={};k(I,{ErrorContext:()=>c,createErrorBoundary:()=>R,provideErrorBoundary:()=>N});module.exports=O(I);var q="__fluixi_signal_next_state__",E=r=>{typeof queueMicrotask=="function"?queueMicrotask(r):Promise.resolve().then(r)},n=globalThis[q]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:E,onSuspend:null,onError:null};var C=2,l=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(n.untracked)return;let e=n.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}},u=class extends l{constructor(e,t){super(),this._value=e,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(e){if(!this._equals(this._value,e)){if(this._value=e,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(C);P(this)}}peek(){return this._value}};function P(r){if(r.watchers)for(let e of[...r.watchers])e._notify(r)}function f(r){return{cleanups:null,owned:null,parent:r,contexts:null}}function h(r){let e=Symbol("context");return{id:e,defaultValue:r,Provider:o=>{let s=n.owner,i=f(s);(i.contexts=new Map).set(e,o.value),s&&(s.owned??=[]).push(i),n.owner=i;try{return o.children}finally{n.owner=s}}}}function p(r,e){let t=r;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function w(r,e,t){let o=f(n.owner);(o.contexts=new Map).set(r.id,e),n.owner&&(n.owner.owned??=[]).push(o);let s=n.owner;n.owner=o;try{return t()}finally{n.owner=s}}function v(r){n.onError=r}function T(r){n.hostSchedule=r??(e=>{Promise.resolve().then(e)})}function y(){if(n.scheduled=!1,n.flushing)return;n.flushing=!0;let r=0;try{for(;n.queue.length;){if(++r>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let e=n.queue;n.queue=[];for(let t of e)t.queued=!1,t.disposed||t.run()}}finally{n.flushing=!1}}function m(){n.batchDepth===0&&y()}T(()=>{});var D=Symbol.for("signal");var A=Symbol.for("signal-node");function b(r,e){let t=new u(r,{equals:e?.equals}),o=(()=>t.get()),s=(i=>{let d=typeof i=="function"?i(t.peek()):i;return t.set(d),m(),d});return Object.defineProperty(o,D,{value:!0,enumerable:!0}),Object.defineProperty(o,A,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,s]}var c=h();v((r,e)=>{let t=p(e,c);return t?(t.setError(r),!0):!1});function R(){let[r,e]=b(void 0,{equals:!1});return{error:r,reset:()=>e(()=>{}),setError:o=>e(()=>o)}}function N(r,e){return w(c,r,e)}
@@ -0,0 +1,16 @@
1
+ export interface ErrorBoundary {
2
+ /** Reactive: the caught error, or undefined. */
3
+ error(): unknown;
4
+ /** Clear the error so children re-render (after a fix/retry). */
5
+ reset(): void;
6
+ }
7
+ interface InternalBoundary extends ErrorBoundary {
8
+ setError(e: unknown): void;
9
+ }
10
+ declare const ErrorContext: import("./runtime.js").Context<InternalBoundary | undefined>;
11
+ /** Create a boundary's reactive state (caught error + reset). */
12
+ export declare function createErrorBoundary(): ErrorBoundary;
13
+ /** Run `fn` (the boundary's children) so thrown errors inside report to `boundary`. */
14
+ export declare function provideErrorBoundary<R>(boundary: ErrorBoundary, fn: () => R): R;
15
+ export { ErrorContext };
16
+ //# sourceMappingURL=error-boundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../../../../src/lib/signal/graph/error-boundary.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,KAAK,IAAI,OAAO,CAAC;IACjB,iEAAiE;IACjE,KAAK,IAAI,IAAI,CAAC;CACf;AAED,UAAU,gBAAiB,SAAQ,aAAa;IAC9C,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC5B;AAED,QAAA,MAAM,YAAY,8DAAgD,CAAC;AAUnE,iEAAiE;AACjE,wBAAgB,mBAAmB,IAAI,aAAa,CAQnD;AAED,uFAAuF;AACvF,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAE/E;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Error boundaries ported onto the TC39 core (additive; legacy untouched).
3
+ *
4
+ * Same shape as the Suspense port: a boundary is a context carrying an error sink.
5
+ * When an effect under it throws a real (non-promise) error, the L1 effect's run()
6
+ * routes it here via the injected error handler, which records it on the nearest
7
+ * boundary (reactively, so the UI can swap to a fallback) and reports it handled.
8
+ */
9
+ import { createContext, readContextFrom, setErrorHandler, provide, } from './runtime.js';
10
+ import { createSignal } from './compat.js';
11
+ const ErrorContext = createContext();
12
+ // Wire the L1 effect's error path to the nearest boundary. Registered once.
13
+ setErrorHandler((error, owner) => {
14
+ const boundary = readContextFrom(owner, ErrorContext);
15
+ if (!boundary)
16
+ return false; // no boundary → not handled (rethrows)
17
+ boundary.setError(error);
18
+ return true;
19
+ });
20
+ /** Create a boundary's reactive state (caught error + reset). */
21
+ export function createErrorBoundary() {
22
+ const [error, setError] = createSignal(undefined, { equals: false });
23
+ const boundary = {
24
+ error,
25
+ reset: () => setError(() => undefined),
26
+ setError: (e) => setError(() => e),
27
+ };
28
+ return boundary;
29
+ }
30
+ /** Run `fn` (the boundary's children) so thrown errors inside report to `boundary`. */
31
+ export function provideErrorBoundary(boundary, fn) {
32
+ return provide(ErrorContext, boundary, fn);
33
+ }
34
+ export { ErrorContext };
@@ -0,0 +1 @@
1
+ var b="__fluixi_signal_next_state__",x=r=>{typeof queueMicrotask=="function"?queueMicrotask(r):Promise.resolve().then(r)},n=globalThis[b]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:x,onSuspend:null,onError:null};var S=2,a=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(n.untracked)return;let e=n.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}},u=class extends a{constructor(e,t){super(),this._value=e,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(e){if(!this._equals(this._value,e)){if(this._value=e,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(S);_(this)}}peek(){return this._value}};function _(r){if(r.watchers)for(let e of[...r.watchers])e._notify(r)}function c(r){return{cleanups:null,owned:null,parent:r,contexts:null}}function d(r){let e=Symbol("context");return{id:e,defaultValue:r,Provider:o=>{let s=n.owner,i=c(s);(i.contexts=new Map).set(e,o.value),s&&(s.owned??=[]).push(i),n.owner=i;try{return o.children}finally{n.owner=s}}}}function f(r,e){let t=r;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function h(r,e,t){let o=c(n.owner);(o.contexts=new Map).set(r.id,e),n.owner&&(n.owner.owned??=[]).push(o);let s=n.owner;n.owner=o;try{return t()}finally{n.owner=s}}function p(r){n.onError=r}function w(r){n.hostSchedule=r??(e=>{Promise.resolve().then(e)})}function v(){if(n.scheduled=!1,n.flushing)return;n.flushing=!0;let r=0;try{for(;n.queue.length;){if(++r>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let e=n.queue;n.queue=[];for(let t of e)t.queued=!1,t.disposed||t.run()}}finally{n.flushing=!1}}function T(){n.batchDepth===0&&v()}w(()=>{});var k=Symbol.for("signal");var g=Symbol.for("signal-node");function y(r,e){let t=new u(r,{equals:e?.equals}),o=(()=>t.get()),s=(i=>{let l=typeof i=="function"?i(t.peek()):i;return t.set(l),T(),l});return Object.defineProperty(o,k,{value:!0,enumerable:!0}),Object.defineProperty(o,g,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,s]}var m=d();p((r,e)=>{let t=f(e,m);return t?(t.setError(r),!0):!1});function H(){let[r,e]=y(void 0,{equals:!1});return{error:r,reset:()=>e(()=>{}),setError:o=>e(()=>o)}}function V(r,e){return h(m,r,e)}export{m as ErrorContext,H as createErrorBoundary,V as provideErrorBoundary};
@@ -0,0 +1 @@
1
+ "use strict";var p=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var q=(s,e)=>{for(var t in e)p(s,t,{get:e[t],enumerable:!0})},x=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of T(e))!g.call(s,o)&&o!==t&&p(s,o,{get:()=>e[o],enumerable:!(i=k(e,o))||i.enumerable});return s};var C=s=>x(p({},"__esModule",{value:!0}),s);var z={};q(z,{Computed:()=>n,Signal:()=>D,State:()=>a,Watcher:()=>u});module.exports=C(z);var N="__fluixi_signal_next_state__",E=s=>{typeof queueMicrotask=="function"?queueMicrotask(s):Promise.resolve().then(s)},r=globalThis[N]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:E,onSuspend:null,onError:null};var _=0,w=1,h=2,d=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let e=r.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}},a=class extends d{constructor(e,t){super(),this._value=e,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(e){if(!this._equals(this._value,e)){if(this._value=e,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(h);v(this)}}peek(){return this._value}},n=class extends d{constructor(t,i){super();this._threw=!1;this._initialized=!1;this.state=h;this.sources=null;this._fn=t,this._equals=i?.equals===!1?()=>!1:i?.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===w&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===h)break}(this.state===h||!this._initialized)&&this.recompute(),this.state=_}recompute(){if(this.sources){for(let c of this.sources)c.observers?.delete(this);this.sources.clear()}let t=r.consumer,i=r.untracked;r.consumer=this,r.untracked=!1;let o,l=!1,f;try{o=this._fn()}catch(c){l=!0,f=c,o=this._value}finally{r.consumer=t,r.untracked=i}let m=!this._initialized||this._threw!==l||(l?f!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=l,this._error=f,this._value=o,m){if(this.version++,this.observers)for(let c of[...this.observers])c.markDirty(h);v(this)}}markDirty(t){if(this.state>=t)return;let i=this.state===_;if(this.state=t,i){if(this.observers)for(let o of[...this.observers])o.markDirty(w);v(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function v(s){if(s.watchers)for(let e of[...s.watchers])e._notify(s)}var u=class{constructor(e){this._watched=new Set;this._pending=new Set;this._notifyFn=e}watch(...e){for(let t of e)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...e){for(let t of e)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let e=[...this._pending];return this._pending.clear(),e}_notify(e){if(!this._watched.has(e)||this._pending.has(e))return;let t=this._pending.size===0;this._pending.add(e),t&&this._notifyFn()}};function y(s){if(r.untracked)return s();r.untracked=!0;try{return s()}finally{r.untracked=!1}}function b(){return r.consumer}function S(s){return!!(s.observers&&s.observers.size)||!!(s.watchers&&s.watchers.size)}var D={State:a,Computed:n,subtle:{Watcher:u,untrack:y,currentComputed:b,hasSinks:S}};
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The TC39-shaped public surface for the L0 graph core: `Signal.State`,
3
+ * `Signal.Computed`, and the `Signal.subtle` namespace (Watcher / untrack /
4
+ * currentComputed / hasSinks). This mirrors the TC39 Signals proposal so the L1
5
+ * runtime (and, eventually, app code) can target the same shape that a native
6
+ * `globalThis.Signal` would expose — at which point L0 becomes a thin
7
+ * `globalThis.Signal ?? polyfill` swap.
8
+ */
9
+ import { State, Computed, Watcher, untrack, currentComputed, hasSinks } from './core.js';
10
+ export declare const Signal: {
11
+ readonly State: typeof State;
12
+ readonly Computed: typeof Computed;
13
+ readonly subtle: {
14
+ readonly Watcher: typeof Watcher;
15
+ readonly untrack: typeof untrack;
16
+ readonly currentComputed: typeof currentComputed;
17
+ readonly hasSinks: typeof hasSinks;
18
+ };
19
+ };
20
+ export { State, Computed, Watcher } from './core.js';
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/signal/graph/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEzF,eAAO,MAAM,MAAM;;;;;;;;;CAST,CAAC;AAEX,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The TC39-shaped public surface for the L0 graph core: `Signal.State`,
3
+ * `Signal.Computed`, and the `Signal.subtle` namespace (Watcher / untrack /
4
+ * currentComputed / hasSinks). This mirrors the TC39 Signals proposal so the L1
5
+ * runtime (and, eventually, app code) can target the same shape that a native
6
+ * `globalThis.Signal` would expose — at which point L0 becomes a thin
7
+ * `globalThis.Signal ?? polyfill` swap.
8
+ */
9
+ import { State, Computed, Watcher, untrack, currentComputed, hasSinks } from './core.js';
10
+ export const Signal = {
11
+ State,
12
+ Computed,
13
+ subtle: {
14
+ Watcher,
15
+ untrack,
16
+ currentComputed,
17
+ hasSinks,
18
+ },
19
+ };
20
+ export { State, Computed, Watcher } from './core.js';
@@ -0,0 +1 @@
1
+ var m="__fluixi_signal_next_state__",k=s=>{typeof queueMicrotask=="function"?queueMicrotask(s):Promise.resolve().then(s)},r=globalThis[m]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:k,onSuspend:null,onError:null};var v=0,_=1,n=2,d=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let e=r.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}},u=class extends d{constructor(e,t){super(),this._value=e,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(e){if(!this._equals(this._value,e)){if(this._value=e,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(n);p(this)}}peek(){return this._value}},c=class extends d{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=n;this.sources=null;this._fn=t,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===_&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===n)break}(this.state===n||!this._initialized)&&this.recompute(),this.state=v}recompute(){if(this.sources){for(let a of this.sources)a.observers?.delete(this);this.sources.clear()}let t=r.consumer,o=r.untracked;r.consumer=this,r.untracked=!1;let i,l=!1,f;try{i=this._fn()}catch(a){l=!0,f=a,i=this._value}finally{r.consumer=t,r.untracked=o}let S=!this._initialized||this._threw!==l||(l?f!==this._error:!this._equals(this._value,i));if(this._initialized=!0,this._threw=l,this._error=f,this._value=i,S){if(this.version++,this.observers)for(let a of[...this.observers])a.markDirty(n);p(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===v;if(this.state=t,o){if(this.observers)for(let i of[...this.observers])i.markDirty(_);p(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function p(s){if(s.watchers)for(let e of[...s.watchers])e._notify(s)}var h=class{constructor(e){this._watched=new Set;this._pending=new Set;this._notifyFn=e}watch(...e){for(let t of e)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...e){for(let t of e)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let e=[...this._pending];return this._pending.clear(),e}_notify(e){if(!this._watched.has(e)||this._pending.has(e))return;let t=this._pending.size===0;this._pending.add(e),t&&this._notifyFn()}};function w(s){if(r.untracked)return s();r.untracked=!0;try{return s()}finally{r.untracked=!1}}function y(){return r.consumer}function b(s){return!!(s.observers&&s.observers.size)||!!(s.watchers&&s.watchers.size)}var C={State:u,Computed:c,subtle:{Watcher:h,untrack:w,currentComputed:y,hasSinks:b}};export{c as Computed,C as Signal,u as State,h as Watcher};
@@ -0,0 +1 @@
1
+ "use strict";var C=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var de=Object.prototype.hasOwnProperty;var fe=(e,t)=>{for(var n in t)C(e,n,{get:t[n],enumerable:!0})},pe=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ce(t))!de.call(e,s)&&s!==n&&C(e,s,{get:()=>t[s],enumerable:!(o=le(t,s))||o.enumerable});return e};var he=e=>pe(C({},"__esModule",{value:!0}),e);var ke={};fe(ke,{createResource:()=>xe});module.exports=he(ke);var ve="__fluixi_signal_next_state__",Te=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[ve]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Te,onSuspend:null,onError:null};var H=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))}},_=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);A(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=H}recompute(){if(this.sources){for(let l of this.sources)l.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(l){i=!0,a=l,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 l of[...this.observers])l.markDirty(v);A(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===H;if(this.state=n,o){if(this.observers)for(let s of[...this.observers])s.markDirty(K);A(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function A(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var R=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 we(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 V(e){r.owner&&(r.owner.cleanups??=[]).push(e)}function E(e){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)E(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}}function U(e){r.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function ye(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=we(r.owner),r.owner&&(r.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new T(()=>{E(this.owner),N(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new R(()=>ye(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 _(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 j(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 be(e){return!!e&&typeof e.then=="function"}var M=Symbol();function xe(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=re(),a=i!==void 0?ne(i):void 0,w=a!==void 0,[l,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}),[se,p]=h(void 0,{equals:!1}),[ie,ue]=h(void 0,{equals:!1}),m=M,D=!1;J(()=>{let u=o();if(ie(),u===!1||u===null||u===void 0){m=M,d(()=>{f("unresolved"),p(void 0),y(void 0)});return}let g=D;if(D=!1,m!==M&&u===m&&!g)return;if(m=u,w){w=!1;return}let b=!1;V(()=>b=!0);let z=j(q),ae=j(l),F=z==="ready"||z==="refreshing";d(()=>{f(F?"refreshing":"pending"),y(void 0)});try{let c=s(u,{value:ae,refetching:F});be(c)?(p(c),te(c),c.then(x=>{b||(i!==void 0&&oe(i,x),d(()=>{P(()=>x),f("ready"),p(void 0)}))},x=>{b||d(()=>{y(x),f("errored"),p(void 0)})})):d(()=>{P(()=>c),f("ready"),p(void 0)})}catch(c){if(b)return;d(()=>{y(c),f("errored"),p(void 0)})}});let W=()=>{let u=q();return u==="pending"||u==="refreshing"},S=(()=>{let u=G();if(u)throw u;if(W()){let g=se();if(g)throw g}return l()});return Object.defineProperties(S,{state:{get:q},loading:{get:W},error:{get:G},latest:{get:l}}),Object.defineProperty(S,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(S,Symbol.for("signal"),{value:!0,enumerable:!0}),[S,{mutate:P,refetch:()=>{D=!0,ue(void 0)}}]}
@@ -0,0 +1,36 @@
1
+ type ResourceState = 'unresolved' | 'pending' | 'ready' | 'refreshing' | 'errored';
2
+ export interface ResourceActions<T> {
3
+ mutate: (v: T | ((prev: T | undefined) => T)) => unknown;
4
+ refetch: () => void;
5
+ }
6
+ export type ResourceReturn<T> = [
7
+ resource: (() => T | undefined) & {
8
+ loading: boolean;
9
+ error: unknown;
10
+ latest: T | undefined;
11
+ state: ResourceState;
12
+ },
13
+ actions: ResourceActions<T>
14
+ ];
15
+ /**
16
+ * createResource(fetcher, options?) or createResource(source, fetcher, options?).
17
+ * Matches the legacy state machine + SSR seeding (no first fetch when seeded).
18
+ *
19
+ * The two typed overloads infer `T` from the fetcher's return — without them the
20
+ * `unknown` implementation signature gives every call site `ResourceReturn<{}>`,
21
+ * so the accessor loses its type (the regression seen after the TC39-core switch).
22
+ */
23
+ type ResourceFetcherInfo<T> = {
24
+ value: T | undefined;
25
+ refetching: boolean;
26
+ };
27
+ export declare function createResource<T>(fetcher: (k: true, info: ResourceFetcherInfo<T>) => T | Promise<T>, options?: {
28
+ initialValue?: T;
29
+ name?: string;
30
+ }): ResourceReturn<T>;
31
+ export declare function createResource<T, S>(source: S | false | null | undefined | (() => S | false | null | undefined), fetcher: (k: S, info: ResourceFetcherInfo<T>) => T | Promise<T>, options?: {
32
+ initialValue?: T;
33
+ name?: string;
34
+ }): ResourceReturn<T>;
35
+ export {};
36
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../../src/lib/signal/graph/resource.ts"],"names":[],"mappings":"AA6BA,KAAK,aAAa,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,YAAY,GAAG,SAAS,CAAC;AAMnF,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,CAAC,KAAK,OAAO,CAAC;IACzD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AACD,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,QAAQ,EAAE,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,GAAG;QAChC,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,EAAE,OAAO,CAAC;QACf,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC;QACtB,KAAK,EAAE,aAAa,CAAC;KACtB;IACD,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;CAC5B,CAAC;AAIF;;;;;;;GAOG;AACH,KAAK,mBAAmB,CAAC,CAAC,IAAI;IAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,CAAC;AAC5E,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAClE,OAAO,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C,cAAc,CAAC,CAAC,CAAC,CAAC;AACrB,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EACjC,MAAM,EAAE,CAAC,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC,EAC3E,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAC/D,OAAO,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C,cAAc,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * createResource ported onto the TC39 core (L0+L1 via the compat layer). This is
3
+ * ADDITIVE — the legacy `createResource` in ../signal.ts stays intact; this is the
4
+ * parallel implementation that runs on the new graph.
5
+ *
6
+ * Resources are the one part of the surface that touches framework-coupled bits, so
7
+ * they're ported by hand. The SSR transport hooks (`nextResourceId`/`getServerData`/
8
+ * `trackResourcePromise`/`reportResourceData`) are standalone module functions, so we
9
+ * REUSE them from ../signal.ts — same `__FX_DATA__` seeding + async-SSR drain as legacy.
10
+ *
11
+ * Suspense boundary integration (throwing the pending promise to a boundary that
12
+ * increments/decrements) lands with the Suspense port; the throwing getter is here so
13
+ * a boundary built on the new effect can catch it.
14
+ */
15
+ import { createSignal, createEffect, batch, untrack, onCleanup, } from './compat.js';
16
+ // Standalone SSR hooks — graph-agnostic injectables.
17
+ import { nextResourceId, getServerData, trackResourcePromise, reportResourceData, } from './ssr-hooks.js';
18
+ function isPromise(v) {
19
+ return !!v && typeof v.then === 'function';
20
+ }
21
+ const UNSET = Symbol();
22
+ export function createResource(source, fetcherFn, options = {}) {
23
+ let s;
24
+ let fetcher;
25
+ if (typeof fetcherFn === 'function') {
26
+ s = typeof source === 'function' ? source : () => source;
27
+ fetcher = fetcherFn;
28
+ }
29
+ else {
30
+ s = () => true;
31
+ fetcher = source;
32
+ if (fetcherFn && typeof fetcherFn === 'object')
33
+ options = fetcherFn;
34
+ }
35
+ // SSR data transport: stable id; on the client seed from server-serialized value.
36
+ const ssrId = nextResourceId();
37
+ const seed = ssrId !== undefined ? getServerData(ssrId) : undefined;
38
+ let skipFirstFetch = seed !== undefined;
39
+ const [value, setValue] = createSignal(seed !== undefined ? seed.value : options.initialValue, { equals: false });
40
+ const [error, setError] = createSignal(undefined, { equals: false });
41
+ const [state, setState] = createSignal(seed !== undefined || options.initialValue !== undefined ? 'ready' : 'unresolved', { equals: false });
42
+ const [promise, setPromise] = createSignal(undefined, { equals: false });
43
+ const [track, trigger] = createSignal(undefined, { equals: false });
44
+ let prevKey = UNSET;
45
+ let manualRefetch = false;
46
+ createEffect(() => {
47
+ const val = s();
48
+ track();
49
+ if (val === false || val === null || val === undefined) {
50
+ prevKey = UNSET;
51
+ batch(() => {
52
+ setState('unresolved');
53
+ setPromise(undefined);
54
+ setError(undefined);
55
+ });
56
+ return;
57
+ }
58
+ const isManual = manualRefetch;
59
+ manualRefetch = false;
60
+ if (prevKey !== UNSET && val === prevKey && !isManual)
61
+ return;
62
+ prevKey = val;
63
+ if (skipFirstFetch) {
64
+ skipFirstFetch = false;
65
+ return; // seeded — source tracked, but no first fetch (no flash on hydration)
66
+ }
67
+ let cancelled = false;
68
+ onCleanup(() => (cancelled = true));
69
+ const currentState = untrack(state);
70
+ const currentValue = untrack(value);
71
+ const isRefreshing = currentState === 'ready' || currentState === 'refreshing';
72
+ batch(() => {
73
+ setState(isRefreshing ? 'refreshing' : 'pending');
74
+ setError(undefined);
75
+ });
76
+ try {
77
+ const res = fetcher(val, { value: currentValue, refetching: isRefreshing });
78
+ if (isPromise(res)) {
79
+ setPromise(res);
80
+ trackResourcePromise(res); // server async SSR: collect & await
81
+ res.then((v) => {
82
+ if (cancelled)
83
+ return;
84
+ if (ssrId !== undefined)
85
+ reportResourceData(ssrId, v); // serialize for hydration
86
+ batch(() => {
87
+ setValue(() => v);
88
+ setState('ready');
89
+ setPromise(undefined);
90
+ });
91
+ }, (e) => {
92
+ if (cancelled)
93
+ return;
94
+ batch(() => {
95
+ setError(e);
96
+ setState('errored');
97
+ setPromise(undefined);
98
+ });
99
+ });
100
+ }
101
+ else {
102
+ batch(() => {
103
+ setValue(() => res);
104
+ setState('ready');
105
+ setPromise(undefined);
106
+ });
107
+ }
108
+ }
109
+ catch (e) {
110
+ if (cancelled)
111
+ return;
112
+ batch(() => {
113
+ setError(e);
114
+ setState('errored');
115
+ setPromise(undefined);
116
+ });
117
+ }
118
+ });
119
+ const loading = () => {
120
+ const st = state();
121
+ return st === 'pending' || st === 'refreshing';
122
+ };
123
+ const resource = (() => {
124
+ const e = error();
125
+ if (e)
126
+ throw e;
127
+ if (loading()) {
128
+ const p = promise();
129
+ if (p)
130
+ throw p; // suspends — a boundary on the new effect catches this
131
+ }
132
+ return value();
133
+ });
134
+ Object.defineProperties(resource, {
135
+ state: { get: state },
136
+ loading: { get: loading },
137
+ error: { get: error },
138
+ latest: { get: value },
139
+ });
140
+ // Stamp the detection markers the legacy createResource sets (signal.ts) so the
141
+ // DOM runtime/control-flow recognise a resource accessor: $RESOURCE for
142
+ // isResource() (e.g. Show's `.loading` gate) and $SIGNAL for isSignal() so
143
+ // insert() reads it reactively instead of caching/freezing it.
144
+ Object.defineProperty(resource, Symbol.for('resource'), { value: true, enumerable: true });
145
+ Object.defineProperty(resource, Symbol.for('signal'), { value: true, enumerable: true });
146
+ return [
147
+ resource,
148
+ {
149
+ mutate: setValue,
150
+ refetch: () => {
151
+ manualRefetch = true;
152
+ trigger(undefined);
153
+ },
154
+ },
155
+ ];
156
+ }
@@ -0,0 +1 @@
1
+ var ae="__fluixi_signal_next_state__",le=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[ae]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:le,onSuspend:null,onError:null};var F=0,H=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))}},_=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===H&&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 l of this.sources)l.observers?.delete(this);this.sources.clear()}let n=r.consumer,o=r.untracked;r.consumer=this,r.untracked=!1;let i,s=!1,a;try{i=this._fn()}catch(l){s=!0,a=l,i=this._value}finally{r.consumer=n,r.untracked=o}let w=!this._initialized||this._threw!==s||(s?a!==this._error:!this._equals(this._value,i));if(this._initialized=!0,this._threw=s,this._error=a,this._value=i,w){if(this.version++,this.observers)for(let l of[...this.observers])l.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 i of[...this.observers])i.markDirty(H);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 R=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){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function ce(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function I(e,t){let n=r.owner;r.owner=e;try{return t()}finally{r.owner=n}}function N(e){r.owner&&(r.owner.cleanups??=[]).push(e)}function A(e){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)A(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}}function L(e){r.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function de(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 U(){r.batchDepth===0&&O()}function Y(e){r.batchDepth++;try{return e()}finally{--r.batchDepth===0&&O()}}var E=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=ce(r.owner),r.owner&&(r.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new T(()=>{A(this.owner),I(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new R(()=>de(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),A(this.owner))}};function $(e){let t=new E(e);return()=>t.dispose()}L(()=>{});var pe=Symbol.for("signal");var he=Symbol.for("signal-node");function h(e,t){let n=new _(e,{equals:t?.equals}),o=(()=>n.get()),i=(s=>{let a=typeof s=="function"?s(n.peek()):s;return n.set(a),U(),a});return Object.defineProperty(o,pe,{value:!0,enumerable:!0}),Object.defineProperty(o,he,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[o,i]}function B(e,t){let n=t;return $(()=>{n=e(n)})}function d(e){return Y(e)}function V(e){return K(e)}var J=null;function ee(e){J&&J(e)}var Q=null;function te(e){return Q?Q(e):void 0}var X=null;function ne(){return X?X():void 0}var Z=null;function re(e,t){Z&&Z(e,t)}function ve(e){return!!e&&typeof e.then=="function"}var j=Symbol();function Ae(e,t,n={}){let o,i;typeof t=="function"?(o=typeof e=="function"?e:()=>e,i=t):(o=()=>!0,i=e,t&&typeof t=="object"&&(n=t));let s=ne(),a=s!==void 0?te(s):void 0,w=a!==void 0,[l,P]=h(a!==void 0?a.value:n.initialValue,{equals:!1}),[M,y]=h(void 0,{equals:!1}),[q,f]=h(a!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[oe,p]=h(void 0,{equals:!1}),[se,ie]=h(void 0,{equals:!1}),m=j,D=!1;B(()=>{let u=o();if(se(),u===!1||u===null||u===void 0){m=j,d(()=>{f("unresolved"),p(void 0),y(void 0)});return}let g=D;if(D=!1,m!==j&&u===m&&!g)return;if(m=u,w){w=!1;return}let b=!1;N(()=>b=!0);let W=V(q),ue=V(l),z=W==="ready"||W==="refreshing";d(()=>{f(z?"refreshing":"pending"),y(void 0)});try{let c=i(u,{value:ue,refetching:z});ve(c)?(p(c),ee(c),c.then(x=>{b||(s!==void 0&&re(s,x),d(()=>{P(()=>x),f("ready"),p(void 0)}))},x=>{b||d(()=>{y(x),f("errored"),p(void 0)})})):d(()=>{P(()=>c),f("ready"),p(void 0)})}catch(c){if(b)return;d(()=>{y(c),f("errored"),p(void 0)})}});let G=()=>{let u=q();return u==="pending"||u==="refreshing"},S=(()=>{let u=M();if(u)throw u;if(G()){let g=oe();if(g)throw g}return l()});return Object.defineProperties(S,{state:{get:q},loading:{get:G},error:{get:M},latest:{get:l}}),Object.defineProperty(S,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(S,Symbol.for("signal"),{value:!0,enumerable:!0}),[S,{mutate:P,refetch:()=>{D=!0,ie(void 0)}}]}export{Ae as createResource};
@@ -0,0 +1 @@
1
+ "use strict";var w=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var q=(t,e)=>{for(var r in e)w(t,r,{get:e[r],enumerable:!0})},O=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of k(e))!g.call(t,o)&&o!==r&&w(t,o,{get:()=>e[o],enumerable:!(s=S(e,o))||s.enumerable});return t};var C=t=>O(w({},"__esModule",{value:!0}),t);var U={};q(U,{afterWrite:()=>Y,batch:()=>j,createContext:()=>N,createRoot:()=>H,effect:()=>L,flushSync:()=>f,getOwner:()=>W,onCleanup:()=>F,provide:()=>I,readContextFrom:()=>z,reportSuspend:()=>R,runWithOwner:()=>m,setErrorHandler:()=>M,setOwner:()=>A,setScheduler:()=>V,setSuspendHandler:()=>G,useContext:()=>P});module.exports=C(U);var E="__fluixi_signal_next_state__",D=t=>{typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t)},n=globalThis[E]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:D,onSuspend:null,onError:null};var T=0,_=1,a=2,v=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(n.untracked)return;let e=n.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}};var l=class extends v{constructor(r,s){super();this._threw=!1;this._initialized=!1;this.state=a;this.sources=null;this._fn=r,this._equals=s?.equals===!1?()=>!1:s?.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===_&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===a)break}(this.state===a||!this._initialized)&&this.recompute(),this.state=T}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let r=n.consumer,s=n.untracked;n.consumer=this,n.untracked=!1;let o,i=!1,p;try{o=this._fn()}catch(u){i=!0,p=u,o=this._value}finally{n.consumer=r,n.untracked=s}let x=!this._initialized||this._threw!==i||(i?p!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=i,this._error=p,this._value=o,x){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(a);b(this)}}markDirty(r){if(this.state>=r)return;let s=this.state===T;if(this.state=r,s){if(this.observers)for(let o of[...this.observers])o.markDirty(_);b(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function b(t){if(t.watchers)for(let e of[...t.watchers])e._notify(t)}var c=class{constructor(e){this._watched=new Set;this._pending=new Set;this._notifyFn=e}watch(...e){for(let r of e)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...e){for(let r of e)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let e=[...this._pending];return this._pending.clear(),e}_notify(e){if(!this._watched.has(e)||this._pending.has(e))return;let r=this._pending.size===0;this._pending.add(e),r&&this._notifyFn()}};function h(t){return{cleanups:null,owned:null,parent:t,contexts:null}}function N(t){let e=Symbol("context");return{id:e,defaultValue:t,Provider:s=>{let o=n.owner,i=h(o);(i.contexts=new Map).set(e,s.value),o&&(o.owned??=[]).push(i),n.owner=i;try{return s.children}finally{n.owner=o}}}}function P(t){let e=n.owner;for(;e;){if(e.contexts&&e.contexts.has(t.id))return e.contexts.get(t.id);e=e.parent}return t.defaultValue}function z(t,e){let r=t;for(;r;){if(r.contexts&&r.contexts.has(e.id))return r.contexts.get(e.id);r=r.parent}return e.defaultValue}function I(t,e,r){let s=h(n.owner);(s.contexts=new Map).set(t.id,e),n.owner&&(n.owner.owned??=[]).push(s);let o=n.owner;n.owner=s;try{return r()}finally{n.owner=o}}function G(t){n.onSuspend=t}function R(t){return n.onSuspend?(n.onSuspend(t,n.owner),!0):!1}function M(t){n.onError=t}function W(){return n.owner}function A(t){let e=n.owner;return n.owner=t,e}function m(t,e){let r=n.owner;n.owner=t;try{return e()}finally{n.owner=r}}function F(t){n.owner&&(n.owner.cleanups??=[]).push(t)}function d(t){if(t.owned){for(let e=t.owned.length-1;e>=0;e--)d(t.owned[e]);t.owned=null}if(t.cleanups){for(let e=t.cleanups.length-1;e>=0;e--)t.cleanups[e]();t.cleanups=null}}function H(t){let e=h(n.owner);n.owner&&(n.owner.owned??=[]).push(e);let r=n.owner;n.owner=e;try{return t(()=>d(e))}finally{n.owner=r}}function V(t){n.hostSchedule=t??(e=>{Promise.resolve().then(e)})}function K(t){t.queued||(t.queued=!0,n.queue.push(t),!n.scheduled&&n.batchDepth===0&&(n.scheduled=!0,n.hostSchedule(f)))}function f(){if(n.scheduled=!1,n.flushing)return;n.flushing=!0;let t=0;try{for(;n.queue.length;){if(++t>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let e=n.queue;n.queue=[];for(let r of e)r.queued=!1,r.disposed||r.run()}}finally{n.flushing=!1}}function Y(){n.batchDepth===0&&f()}function j(t){n.batchDepth++;try{return t()}finally{--n.batchDepth===0&&f()}}var y=class{constructor(e){this.queued=!1;this.disposed=!1;this.owner=h(n.owner),n.owner&&(n.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new l(()=>{d(this.owner),m(this.owner,()=>{let r=e();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new c(()=>K(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(e){if(e&&typeof e.then=="function"&&n.onSuspend){n.onSuspend(e,this.owner);return}if(n.onError&&n.onError(e,this.owner))return;throw e}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),d(this.owner))}};function L(t){let e=new y(t);return()=>e.dispose()}
@@ -0,0 +1,56 @@
1
+ export interface Owner {
2
+ cleanups: Array<() => void> | null;
3
+ owned: Owner[] | null;
4
+ parent: Owner | null;
5
+ /** Context values provided at this scope — useContext walks up the parent chain. */
6
+ contexts: Map<symbol, unknown> | null;
7
+ }
8
+ export interface Context<T> {
9
+ id: symbol;
10
+ defaultValue: T | undefined;
11
+ /** Component that stamps `value` for descendants: `<Ctx.Provider value=… >children</…>`. */
12
+ Provider: (props: {
13
+ value: T;
14
+ children?: unknown;
15
+ debug?: boolean;
16
+ }) => any;
17
+ }
18
+ export declare function createContext<T>(defaultValue?: T): Context<T>;
19
+ /** Read the nearest provided value for `context`, or its default. */
20
+ export declare function useContext<T>(context: {
21
+ id: symbol;
22
+ defaultValue?: T;
23
+ }): T | undefined;
24
+ /** Read `context` starting from a specific owner chain (not the current scope). */
25
+ export declare function readContextFrom<T>(owner: Owner | null, context: Context<T>): T | undefined;
26
+ /** Run `fn` in a child scope that provides `value` for `context`. */
27
+ export declare function provide<T, R>(context: Context<T>, value: T, fn: () => R): R;
28
+ /** Register how a thrown promise (a suspended read) is reported to a boundary. */
29
+ export declare function setSuspendHandler(fn: ((promise: Promise<unknown>, owner: Owner | null) => void) | null): void;
30
+ /** Report a suspended read (thrown promise) to the nearest boundary from the current owner. */
31
+ export declare function reportSuspend(promise: Promise<unknown>): boolean;
32
+ /** Register how a thrown error is routed to an error boundary. Return true if handled. */
33
+ export declare function setErrorHandler(fn: ((error: unknown, owner: Owner | null) => boolean) | null): void;
34
+ export declare function getOwner(): Owner | null;
35
+ /** Set the current owner directly, returning the previous one. (Framework render glue.) */
36
+ export declare function setOwner(owner: Owner | null): Owner | null;
37
+ export declare function runWithOwner<T>(owner: Owner | null, fn: () => T): T;
38
+ /** Register a teardown for the current owner scope. */
39
+ export declare function onCleanup(fn: () => void): void;
40
+ /** Create a root reactive scope with explicit disposal (TC39 has no ownership). */
41
+ export declare function createRoot<T>(fn: (dispose: () => void) => T): T;
42
+ export declare function setScheduler(fn: ((run: () => void) => void) | null): void;
43
+ /** Drain all pending effects now (synchronously). */
44
+ export declare function flushSync(): void;
45
+ /**
46
+ * Run pending effects after a write completes — but only at the top level (not
47
+ * inside a batch). A single write thus marks the WHOLE graph dirty first, then
48
+ * flushes once (legacy-equivalent synchronous effects, glitch-free). The `G.flushing`
49
+ * guard makes a write inside an effect a no-op here (the running loop drains it).
50
+ */
51
+ export declare function afterWrite(): void;
52
+ /** Group writes so dependent effects flush once, at the end. */
53
+ export declare function batch<T>(fn: () => T): T;
54
+ /** A re-running side effect. Runs once now, then again (G.scheduled) when deps change. */
55
+ export declare function effect(fn: () => void | (() => void)): () => void;
56
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/lib/signal/graph/runtime.ts"],"names":[],"mappings":"AAoBA,MAAM,WAAW,KAAK;IACpB,QAAQ,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;IACnC,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC;IACrB,oFAAoF;IACpF,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CACvC;AAUD,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,CAAC,GAAG,SAAS,CAAC;IAC5B,4FAA4F;IAI5F,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,GAAG,CAAC;CAC7E;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAsB7D;AAED,qEAAqE;AACrE,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,SAAS,CAOtF;AAED,mFAAmF;AACnF,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAO1F;AAED,qEAAqE;AACrE,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAW3E;AAGD,kFAAkF;AAClF,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,CAAC,GAAG,IAAI,GACpE,IAAI,CAEN;AAED,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAMhE;AAED,0FAA0F;AAC1F,wBAAgB,eAAe,CAC7B,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,KAAK,OAAO,CAAC,GAAG,IAAI,GAC5D,IAAI,CAEN;AAED,wBAAgB,QAAQ,IAAI,KAAK,GAAG,IAAI,CAEvC;AAED,2FAA2F;AAC3F,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,CAI1D;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAQnE;AAED,uDAAuD;AACvD,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAG9C;AAaD,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAU/D;AAGD,wBAAgB,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAEzE;AAYD,qDAAqD;AACrD,wBAAgB,SAAS,IAAI,IAAI,CAqBhC;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAEjC;AAED,gEAAgE;AAChE,wBAAgB,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAOvC;AA6DD,0FAA0F;AAC1F,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,MAAM,IAAI,CAGhE"}