@fluixi/reactive 1.0.0-alpha.100

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 (211) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +280 -0
  3. package/dist/cdn/reactive.cjs +2803 -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 +2 -0
  7. package/dist/cdn/reactive.js +10 -0
  8. package/dist/cdn/reactive.mjs +2787 -0
  9. package/dist/cdn/signal.cjs +299 -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 +2 -0
  13. package/dist/cdn/signal.js +18 -0
  14. package/dist/cdn/signal.mjs +276 -0
  15. package/dist/index.cjs +2803 -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 +2787 -0
  20. package/dist/lib/index.cjs +2804 -0
  21. package/dist/lib/index.d.ts +8 -0
  22. package/dist/lib/index.d.ts.map +1 -0
  23. package/dist/lib/index.js +11 -0
  24. package/dist/lib/index.mjs +2789 -0
  25. package/dist/lib/observable/index.cjs +386 -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 +364 -0
  30. package/dist/lib/observable/observable.cjs +384 -0
  31. package/dist/lib/observable/observable.d.ts +246 -0
  32. package/dist/lib/observable/observable.d.ts.map +1 -0
  33. package/dist/lib/observable/observable.js +268 -0
  34. package/dist/lib/observable/observable.mjs +361 -0
  35. package/dist/lib/observable/subscription.cjs +180 -0
  36. package/dist/lib/observable/subscription.d.ts +58 -0
  37. package/dist/lib/observable/subscription.d.ts.map +1 -0
  38. package/dist/lib/observable/subscription.js +177 -0
  39. package/dist/lib/observable/subscription.mjs +157 -0
  40. package/dist/lib/observable/types.cjs +18 -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/predicates.cjs +44 -0
  46. package/dist/lib/predicates.d.ts +37 -0
  47. package/dist/lib/predicates.d.ts.map +1 -0
  48. package/dist/lib/predicates.js +62 -0
  49. package/dist/lib/predicates.mjs +23 -0
  50. package/dist/lib/signal/api.cjs +592 -0
  51. package/dist/lib/signal/api.d.ts +227 -0
  52. package/dist/lib/signal/api.d.ts.map +1 -0
  53. package/dist/lib/signal/api.js +228 -0
  54. package/dist/lib/signal/api.mjs +569 -0
  55. package/dist/lib/signal/cached-resource.cjs +726 -0
  56. package/dist/lib/signal/cached-resource.d.ts +86 -0
  57. package/dist/lib/signal/cached-resource.d.ts.map +1 -0
  58. package/dist/lib/signal/cached-resource.js +250 -0
  59. package/dist/lib/signal/cached-resource.mjs +704 -0
  60. package/dist/lib/signal/graph/children.cjs +326 -0
  61. package/dist/lib/signal/graph/children.d.ts +2 -0
  62. package/dist/lib/signal/graph/children.d.ts.map +1 -0
  63. package/dist/lib/signal/graph/children.js +30 -0
  64. package/dist/lib/signal/graph/children.mjs +303 -0
  65. package/dist/lib/signal/graph/compat.cjs +590 -0
  66. package/dist/lib/signal/graph/compat.d.ts +66 -0
  67. package/dist/lib/signal/graph/compat.d.ts.map +1 -0
  68. package/dist/lib/signal/graph/compat.js +197 -0
  69. package/dist/lib/signal/graph/compat.mjs +568 -0
  70. package/dist/lib/signal/graph/core.cjs +295 -0
  71. package/dist/lib/signal/graph/core.d.ts +99 -0
  72. package/dist/lib/signal/graph/core.d.ts.map +1 -0
  73. package/dist/lib/signal/graph/core.js +268 -0
  74. package/dist/lib/signal/graph/core.mjs +273 -0
  75. package/dist/lib/signal/graph/debounced.cjs +680 -0
  76. package/dist/lib/signal/graph/debounced.d.ts +67 -0
  77. package/dist/lib/signal/graph/debounced.d.ts.map +1 -0
  78. package/dist/lib/signal/graph/debounced.js +92 -0
  79. package/dist/lib/signal/graph/debounced.mjs +657 -0
  80. package/dist/lib/signal/graph/derived.cjs +508 -0
  81. package/dist/lib/signal/graph/derived.d.ts +14 -0
  82. package/dist/lib/signal/graph/derived.d.ts.map +1 -0
  83. package/dist/lib/signal/graph/derived.js +65 -0
  84. package/dist/lib/signal/graph/derived.mjs +485 -0
  85. package/dist/lib/signal/graph/detect.cjs +66 -0
  86. package/dist/lib/signal/graph/detect.d.ts +17 -0
  87. package/dist/lib/signal/graph/detect.d.ts.map +1 -0
  88. package/dist/lib/signal/graph/detect.js +39 -0
  89. package/dist/lib/signal/graph/detect.mjs +45 -0
  90. package/dist/lib/signal/graph/error-boundary.cjs +313 -0
  91. package/dist/lib/signal/graph/error-boundary.d.ts +16 -0
  92. package/dist/lib/signal/graph/error-boundary.d.ts.map +1 -0
  93. package/dist/lib/signal/graph/error-boundary.js +34 -0
  94. package/dist/lib/signal/graph/error-boundary.mjs +290 -0
  95. package/dist/lib/signal/graph/index.cjs +305 -0
  96. package/dist/lib/signal/graph/index.d.ts +22 -0
  97. package/dist/lib/signal/graph/index.d.ts.map +1 -0
  98. package/dist/lib/signal/graph/index.js +21 -0
  99. package/dist/lib/signal/graph/index.mjs +283 -0
  100. package/dist/lib/signal/graph/observe.cjs +198 -0
  101. package/dist/lib/signal/graph/observe.d.ts +185 -0
  102. package/dist/lib/signal/graph/observe.d.ts.map +1 -0
  103. package/dist/lib/signal/graph/observe.js +198 -0
  104. package/dist/lib/signal/graph/observe.mjs +175 -0
  105. package/dist/lib/signal/graph/resource.cjs +632 -0
  106. package/dist/lib/signal/graph/resource.d.ts +39 -0
  107. package/dist/lib/signal/graph/resource.d.ts.map +1 -0
  108. package/dist/lib/signal/graph/resource.js +165 -0
  109. package/dist/lib/signal/graph/resource.mjs +609 -0
  110. package/dist/lib/signal/graph/runtime.cjs +522 -0
  111. package/dist/lib/signal/graph/runtime.d.ts +80 -0
  112. package/dist/lib/signal/graph/runtime.d.ts.map +1 -0
  113. package/dist/lib/signal/graph/runtime.js +358 -0
  114. package/dist/lib/signal/graph/runtime.mjs +499 -0
  115. package/dist/lib/signal/graph/signal-next.cjs +1249 -0
  116. package/dist/lib/signal/graph/signal-next.d.ts +38 -0
  117. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -0
  118. package/dist/lib/signal/graph/signal-next.js +44 -0
  119. package/dist/lib/signal/graph/signal-next.mjs +1227 -0
  120. package/dist/lib/signal/graph/ssr-hooks.cjs +89 -0
  121. package/dist/lib/signal/graph/ssr-hooks.d.ts +51 -0
  122. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -0
  123. package/dist/lib/signal/graph/ssr-hooks.js +80 -0
  124. package/dist/lib/signal/graph/ssr-hooks.mjs +68 -0
  125. package/dist/lib/signal/graph/state.cjs +72 -0
  126. package/dist/lib/signal/graph/state.d.ts +76 -0
  127. package/dist/lib/signal/graph/state.d.ts.map +1 -0
  128. package/dist/lib/signal/graph/state.js +99 -0
  129. package/dist/lib/signal/graph/state.mjs +49 -0
  130. package/dist/lib/signal/graph/suspense.cjs +313 -0
  131. package/dist/lib/signal/graph/suspense.d.ts +13 -0
  132. package/dist/lib/signal/graph/suspense.d.ts.map +1 -0
  133. package/dist/lib/signal/graph/suspense.js +36 -0
  134. package/dist/lib/signal/graph/suspense.mjs +290 -0
  135. package/dist/lib/signal/index-legacy.cjs +2582 -0
  136. package/dist/lib/signal/index-legacy.d.ts +12 -0
  137. package/dist/lib/signal/index-legacy.d.ts.map +1 -0
  138. package/dist/lib/signal/index-legacy.js +11 -0
  139. package/dist/lib/signal/index-legacy.mjs +2560 -0
  140. package/dist/lib/signal/index.cjs +1350 -0
  141. package/dist/lib/signal/index.d.ts +19 -0
  142. package/dist/lib/signal/index.d.ts.map +1 -0
  143. package/dist/lib/signal/index.js +19 -0
  144. package/dist/lib/signal/index.mjs +1328 -0
  145. package/dist/lib/signal/list.cjs +561 -0
  146. package/dist/lib/signal/list.d.ts +39 -0
  147. package/dist/lib/signal/list.d.ts.map +1 -0
  148. package/dist/lib/signal/list.js +172 -0
  149. package/dist/lib/signal/list.mjs +538 -0
  150. package/dist/lib/signal/resource-api.cjs +638 -0
  151. package/dist/lib/signal/resource-api.d.ts +19 -0
  152. package/dist/lib/signal/resource-api.d.ts.map +1 -0
  153. package/dist/lib/signal/resource-api.js +27 -0
  154. package/dist/lib/signal/resource-api.mjs +615 -0
  155. package/dist/lib/signal/signal.cjs +2035 -0
  156. package/dist/lib/signal/signal.d.ts +303 -0
  157. package/dist/lib/signal/signal.d.ts.map +1 -0
  158. package/dist/lib/signal/signal.js +1233 -0
  159. package/dist/lib/signal/signal.mjs +2012 -0
  160. package/dist/lib/signal/types.cjs +38 -0
  161. package/dist/lib/signal/types.d.ts +133 -0
  162. package/dist/lib/signal/types.d.ts.map +1 -0
  163. package/dist/lib/signal/types.js +38 -0
  164. package/dist/lib/signal/types.mjs +17 -0
  165. package/dist/lib/signal/utilities.cjs +1024 -0
  166. package/dist/lib/signal/utilities.d.ts +247 -0
  167. package/dist/lib/signal/utilities.d.ts.map +1 -0
  168. package/dist/lib/signal/utilities.js +346 -0
  169. package/dist/lib/signal/utilities.mjs +1002 -0
  170. package/dist/lib/store/api.cjs +662 -0
  171. package/dist/lib/store/api.d.ts +40 -0
  172. package/dist/lib/store/api.d.ts.map +1 -0
  173. package/dist/lib/store/api.js +63 -0
  174. package/dist/lib/store/api.mjs +646 -0
  175. package/dist/lib/store/index.cjs +741 -0
  176. package/dist/lib/store/index.d.ts +16 -0
  177. package/dist/lib/store/index.d.ts.map +1 -0
  178. package/dist/lib/store/index.js +13 -0
  179. package/dist/lib/store/index.mjs +726 -0
  180. package/dist/lib/store/setter.types.cjs +18 -0
  181. package/dist/lib/store/setter.types.d.ts +131 -0
  182. package/dist/lib/store/setter.types.d.ts.map +1 -0
  183. package/dist/lib/store/setter.types.js +65 -0
  184. package/dist/lib/store/setter.types.mjs +0 -0
  185. package/dist/lib/store/store.cjs +708 -0
  186. package/dist/lib/store/store.d.ts +142 -0
  187. package/dist/lib/store/store.d.ts.map +1 -0
  188. package/dist/lib/store/store.js +812 -0
  189. package/dist/lib/store/store.mjs +694 -0
  190. package/dist/lib/store/types.cjs +18 -0
  191. package/dist/lib/store/types.d.ts +57 -0
  192. package/dist/lib/store/types.d.ts.map +1 -0
  193. package/dist/lib/store/types.js +1 -0
  194. package/dist/lib/store/types.mjs +0 -0
  195. package/dist/lib/store/utils.cjs +43 -0
  196. package/dist/lib/store/utils.d.ts +13 -0
  197. package/dist/lib/store/utils.d.ts.map +1 -0
  198. package/dist/lib/store/utils.js +29 -0
  199. package/dist/lib/store/utils.mjs +22 -0
  200. package/dist/lib/subject.cjs +450 -0
  201. package/dist/lib/subject.d.ts +14 -0
  202. package/dist/lib/subject.d.ts.map +1 -0
  203. package/dist/lib/subject.js +81 -0
  204. package/dist/lib/subject.mjs +427 -0
  205. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  206. package/dist/version.generated.cjs +27 -0
  207. package/dist/version.generated.d.ts +3 -0
  208. package/dist/version.generated.d.ts.map +1 -0
  209. package/dist/version.generated.js +3 -0
  210. package/dist/version.generated.mjs +7 -0
  211. package/package.json +115 -0
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The type predicates this package needs, inlined.
3
+ *
4
+ * They came from `@fluixi/utils`, and the import was the only thing standing between
5
+ * this package and being installable on its own, a signals library that drags a
6
+ * framework's utility package behind it reads as a framework component, whatever the
7
+ * README says. Three predicates are not worth a dependency.
8
+ *
9
+ * These match the `@fluixi/utils` originals exactly, including the parts that look
10
+ * incidental. Each of those exclusions is load-bearing here.
11
+ */
12
+ /**
13
+ * A callable, excluding classes.
14
+ *
15
+ * The class check matters: a signal's setter accepts an updater function, and
16
+ * `set(SomeClass)` means "store this class", not "call it with the previous value".
17
+ * Without the exclusion the constructor would be invoked.
18
+ */
19
+ export declare function isFunction<T extends Function = Function>(value: unknown): value is T;
20
+ /**
21
+ * A plain-ish object: not null, not an array, not a function, and not one of the
22
+ * built-ins with their own identity.
23
+ *
24
+ * Date, RegExp, Map, Set and Error are excluded because a store must treat them as
25
+ * opaque values rather than walking into them, proxying a Date's internals produces
26
+ * an object that fails every method call on it.
27
+ */
28
+ export declare function isObject(value: unknown): value is Record<string | symbol, unknown>;
29
+ /**
30
+ * Thenable, rather than `instanceof Promise`.
31
+ *
32
+ * A resource fetcher may return a promise from another realm or another
33
+ * implementation, and those are still awaitable. Functions are included because a
34
+ * thenable function is legal, if unusual.
35
+ */
36
+ export declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
37
+ //# sourceMappingURL=predicates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../../src/lib/predicates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,CAKpF;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAUlF;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,CAO1E"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The type predicates this package needs, inlined.
3
+ *
4
+ * They came from `@fluixi/utils`, and the import was the only thing standing between
5
+ * this package and being installable on its own, a signals library that drags a
6
+ * framework's utility package behind it reads as a framework component, whatever the
7
+ * README says. Three predicates are not worth a dependency.
8
+ *
9
+ * These match the `@fluixi/utils` originals exactly, including the parts that look
10
+ * incidental. Each of those exclusions is load-bearing here.
11
+ */
12
+ /**
13
+ * A callable, excluding classes.
14
+ *
15
+ * The class check matters: a signal's setter accepts an updater function, and
16
+ * `set(SomeClass)` means "store this class", not "call it with the previous value".
17
+ * Without the exclusion the constructor would be invoked.
18
+ */
19
+ export function isFunction(value) {
20
+ return (typeof value === 'function' &&
21
+ !/^class\s/.test(Function.prototype.toString.call(value)));
22
+ }
23
+ /**
24
+ * A plain-ish object: not null, not an array, not a function, and not one of the
25
+ * built-ins with their own identity.
26
+ *
27
+ * Date, RegExp, Map, Set and Error are excluded because a store must treat them as
28
+ * opaque values rather than walking into them, proxying a Date's internals produces
29
+ * an object that fails every method call on it.
30
+ */
31
+ export function isObject(value) {
32
+ if (value == null)
33
+ return false;
34
+ if (Array.isArray(value))
35
+ return false;
36
+ if (typeof value === 'function')
37
+ return false;
38
+ if (value instanceof Date)
39
+ return false;
40
+ if (value instanceof RegExp)
41
+ return false;
42
+ if (value instanceof Map)
43
+ return false;
44
+ if (value instanceof Set)
45
+ return false;
46
+ if (value instanceof Error)
47
+ return false;
48
+ return typeof value === 'object';
49
+ }
50
+ /**
51
+ * Thenable, rather than `instanceof Promise`.
52
+ *
53
+ * A resource fetcher may return a promise from another realm or another
54
+ * implementation, and those are still awaitable. Functions are included because a
55
+ * thenable function is legal, if unusual.
56
+ */
57
+ export function isPromise(value) {
58
+ return (value instanceof Promise ||
59
+ (!!value &&
60
+ (typeof value === 'object' || typeof value === 'function') &&
61
+ 'then' in value));
62
+ }
@@ -0,0 +1,23 @@
1
+ // src/lib/predicates.ts
2
+ function isFunction(value) {
3
+ return typeof value === "function" && !/^class\s/.test(Function.prototype.toString.call(value));
4
+ }
5
+ function isObject(value) {
6
+ if (value == null) return false;
7
+ if (Array.isArray(value)) return false;
8
+ if (typeof value === "function") return false;
9
+ if (value instanceof Date) return false;
10
+ if (value instanceof RegExp) return false;
11
+ if (value instanceof Map) return false;
12
+ if (value instanceof Set) return false;
13
+ if (value instanceof Error) return false;
14
+ return typeof value === "object";
15
+ }
16
+ function isPromise(value) {
17
+ return value instanceof Promise || !!value && (typeof value === "object" || typeof value === "function") && "then" in value;
18
+ }
19
+ export {
20
+ isFunction,
21
+ isObject,
22
+ isPromise
23
+ };
@@ -0,0 +1,592 @@
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/api.ts
21
+ var api_exports = {};
22
+ __export(api_exports, {
23
+ childOwner: () => childOwner,
24
+ computed: () => computed,
25
+ context: () => context,
26
+ effect: () => effect2,
27
+ memo: () => memo,
28
+ renderEffect: () => renderEffect,
29
+ root: () => root,
30
+ signal: () => signal
31
+ });
32
+ module.exports = __toCommonJS(api_exports);
33
+
34
+ // src/version.generated.ts
35
+ var VERSION = "1.0.0-alpha.100";
36
+
37
+ // src/lib/signal/graph/state.ts
38
+ var MAJOR = VERSION.split(".")[0];
39
+ var KEY = `__fluixi_signal_state_v${MAJOR}__`;
40
+ var VERSIONS_KEY = `__fluixi_signal_builds_v${MAJOR}__`;
41
+ var defaultSchedule = (run) => {
42
+ if (typeof queueMicrotask === "function") queueMicrotask(run);
43
+ else void Promise.resolve().then(run);
44
+ };
45
+ function defaults() {
46
+ return {
47
+ consumer: null,
48
+ untracked: false,
49
+ owner: null,
50
+ queue: [],
51
+ scheduled: false,
52
+ flushing: false,
53
+ batchDepth: 0,
54
+ hostSchedule: defaultSchedule,
55
+ onSuspend: null,
56
+ onError: null,
57
+ observer: null
58
+ };
59
+ }
60
+ var realm = globalThis;
61
+ function backfillState(existing) {
62
+ const fresh = defaults();
63
+ const target = existing;
64
+ for (const field of Object.keys(fresh)) {
65
+ if (!(field in existing)) target[field] = fresh[field];
66
+ }
67
+ return existing;
68
+ }
69
+ function claim() {
70
+ const existing = realm[KEY];
71
+ return existing ? backfillState(existing) : realm[KEY] = defaults();
72
+ }
73
+ var G = claim();
74
+ (realm[VERSIONS_KEY] ??= []).push(VERSION);
75
+
76
+ // src/lib/signal/graph/observe.ts
77
+ function observeReactiveNodes(next) {
78
+ G.observer = next;
79
+ return () => {
80
+ if (G.observer === next) G.observer = null;
81
+ };
82
+ }
83
+ var running = [];
84
+ var origin;
85
+ var currentScope;
86
+ function reportReactiveNode(report) {
87
+ const observer = G.observer;
88
+ if (observer) {
89
+ observer.created(
90
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin, scope: report.scope ?? currentScope } : { ...report, scope: report.scope ?? currentScope }
91
+ );
92
+ }
93
+ }
94
+ function enterReactiveRun(node) {
95
+ if (!G.observer) return false;
96
+ running.push(node);
97
+ return true;
98
+ }
99
+ function exitReactiveRun() {
100
+ running.pop();
101
+ }
102
+ function reportReactiveRun(node) {
103
+ G.observer?.ran?.(node);
104
+ }
105
+ function reportReactiveWrite(node, by) {
106
+ G.observer?.wrote?.(node, by);
107
+ }
108
+ function reportReactiveContextCreated(id) {
109
+ G.observer?.contextCreated?.(id);
110
+ }
111
+ function reportReactiveContext(id, kind, value) {
112
+ const observer = G.observer;
113
+ if (!observer?.context || !running.length) return;
114
+ observer.context(running[running.length - 1], id, kind, value);
115
+ }
116
+ function reportReactiveDispose(node) {
117
+ G.observer?.disposed?.(node);
118
+ }
119
+ var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
120
+ var hook = globalThis[HOOK];
121
+ if (typeof hook?.inject === "function") {
122
+ try {
123
+ hook.inject({ observeReactiveNodes, version: VERSION });
124
+ } catch {
125
+ }
126
+ }
127
+ function isObserved() {
128
+ return G.observer != null;
129
+ }
130
+
131
+ // src/lib/signal/graph/core.ts
132
+ var CLEAN = 0;
133
+ var CHECK = 1;
134
+ var DIRTY = 2;
135
+ var Source = class {
136
+ constructor() {
137
+ /** Computeds, and watched leaves, that read this node. */
138
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
+ this.observers = null;
140
+ /** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
141
+ this.watchers = null;
142
+ /** Bumped whenever this node's value actually changes (equality-gated). */
143
+ this.version = 0;
144
+ }
145
+ /** Settle this node so a reader sees a current value/version. Overridden by Computed. */
146
+ updateIfNecessary() {
147
+ }
148
+ /** Link the current consumer (if any) as an observer of this node. */
149
+ track() {
150
+ if (G.untracked) return;
151
+ const consumer = G.consumer;
152
+ if (!consumer) return;
153
+ (this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
154
+ (consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
155
+ }
156
+ };
157
+ var State = class extends Source {
158
+ constructor(value, options) {
159
+ super();
160
+ this._value = value;
161
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
162
+ }
163
+ get() {
164
+ this.track();
165
+ return this._value;
166
+ }
167
+ set(next) {
168
+ if (this._equals(this._value, next)) return;
169
+ this._value = next;
170
+ this.version++;
171
+ reportReactiveWrite(this, G.consumer);
172
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
173
+ notifyWatchers(this);
174
+ }
175
+ /** Read without subscribing (peek). */
176
+ peek() {
177
+ return this._value;
178
+ }
179
+ };
180
+ var Computed = class extends Source {
181
+ constructor(fn, options) {
182
+ super();
183
+ this._threw = false;
184
+ this._initialized = false;
185
+ this.state = DIRTY;
186
+ /** Nodes this computation read on its last run. Rebuilt on every run. */
187
+ this.sources = null;
188
+ this._fn = fn;
189
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
190
+ }
191
+ get() {
192
+ if (G.consumer === this) {
193
+ throw new Error("Signal.Computed cannot read itself");
194
+ }
195
+ this.track();
196
+ this.updateIfNecessary();
197
+ if (this._threw) throw this._error;
198
+ return this._value;
199
+ }
200
+ /** Settle, if CHECK, verify sources; if DIRTY (or never run), recompute. */
201
+ updateIfNecessary() {
202
+ if (this.state === CHECK) {
203
+ if (this.sources) {
204
+ for (const s of this.sources) {
205
+ s.updateIfNecessary();
206
+ if (this.state === DIRTY) break;
207
+ }
208
+ }
209
+ }
210
+ if (this.state === DIRTY || !this._initialized) this.recompute();
211
+ this.state = CLEAN;
212
+ }
213
+ recompute() {
214
+ if (this.sources) {
215
+ for (const s of this.sources) s.observers?.delete(this);
216
+ this.sources.clear();
217
+ }
218
+ const prevConsumer = G.consumer;
219
+ const prevUntracked = G.untracked;
220
+ const watched = enterReactiveRun(this);
221
+ G.consumer = this;
222
+ G.untracked = false;
223
+ let next;
224
+ let threw = false;
225
+ let err;
226
+ try {
227
+ next = this._fn();
228
+ } catch (e) {
229
+ threw = true;
230
+ err = e;
231
+ next = this._value;
232
+ } finally {
233
+ G.consumer = prevConsumer;
234
+ G.untracked = prevUntracked;
235
+ if (watched) exitReactiveRun();
236
+ }
237
+ const changed = !this._initialized || this._threw !== threw || (threw ? err !== this._error : !this._equals(this._value, next));
238
+ this._initialized = true;
239
+ this._threw = threw;
240
+ this._error = err;
241
+ this._value = next;
242
+ reportReactiveRun(this);
243
+ if (changed) {
244
+ this.version++;
245
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
246
+ notifyWatchers(this);
247
+ }
248
+ }
249
+ /**
250
+ * Push a maybe-dirty mark. A direct observer of a changed node gets DIRTY; its
251
+ * own observers get CHECK (recurse), stopping where already marked, so the
252
+ * push is O(newly-dirtied) and never recomputes.
253
+ */
254
+ markDirty(level) {
255
+ if (this.state >= level) return;
256
+ const wasClean = this.state === CLEAN;
257
+ this.state = level;
258
+ if (wasClean) {
259
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(CHECK);
260
+ notifyWatchers(this);
261
+ }
262
+ }
263
+ peek() {
264
+ this.updateIfNecessary();
265
+ if (this._threw) throw this._error;
266
+ return this._value;
267
+ }
268
+ };
269
+ function notifyWatchers(node) {
270
+ if (!node.watchers) return;
271
+ for (const w of [...node.watchers]) w._notify(node);
272
+ }
273
+ var Watcher = class {
274
+ constructor(notify) {
275
+ this._watched = /* @__PURE__ */ new Set();
276
+ this._pending = /* @__PURE__ */ new Set();
277
+ this._notifyFn = notify;
278
+ }
279
+ watch(...nodes) {
280
+ for (const n of nodes) {
281
+ this._watched.add(n);
282
+ (n.watchers ??= /* @__PURE__ */ new Set()).add(this);
283
+ }
284
+ }
285
+ unwatch(...nodes) {
286
+ for (const n of nodes) {
287
+ this._watched.delete(n);
288
+ n.watchers?.delete(this);
289
+ this._pending.delete(n);
290
+ }
291
+ }
292
+ /** Watched nodes that may have changed since the last getPending(). */
293
+ getPending() {
294
+ const out = [...this._pending];
295
+ this._pending.clear();
296
+ return out;
297
+ }
298
+ /** @internal, a watched node became non-clean. Edge-triggered: notify once. */
299
+ _notify(node) {
300
+ if (!this._watched.has(node) || this._pending.has(node)) return;
301
+ const wasEmpty = this._pending.size === 0;
302
+ this._pending.add(node);
303
+ if (wasEmpty) this._notifyFn();
304
+ }
305
+ };
306
+ function untrack(fn) {
307
+ if (G.untracked) return fn();
308
+ G.untracked = true;
309
+ try {
310
+ return fn();
311
+ } finally {
312
+ G.untracked = false;
313
+ }
314
+ }
315
+
316
+ // src/lib/signal/graph/runtime.ts
317
+ function createChildOwner(parent) {
318
+ const owner = makeOwner(parent);
319
+ if (parent) (parent.owned ??= []).push(owner);
320
+ return owner;
321
+ }
322
+ function makeOwner(parent) {
323
+ return { cleanups: null, owned: null, parent, contexts: null };
324
+ }
325
+ function createContext(defaultValue, name) {
326
+ const id = Symbol(name ?? "context");
327
+ reportReactiveContextCreated(id);
328
+ const Provider = (props) => {
329
+ reportReactiveContext(id, "provide", props.value);
330
+ const parent = G.owner;
331
+ const owner = makeOwner(parent);
332
+ (owner.contexts = /* @__PURE__ */ new Map()).set(id, props.value);
333
+ if (parent) (parent.owned ??= []).push(owner);
334
+ G.owner = owner;
335
+ try {
336
+ return props.children;
337
+ } finally {
338
+ G.owner = parent;
339
+ }
340
+ };
341
+ return { id, defaultValue, Provider };
342
+ }
343
+ function reportSuspend(promise) {
344
+ if (G.onSuspend) {
345
+ G.onSuspend(promise, G.owner);
346
+ return true;
347
+ }
348
+ return false;
349
+ }
350
+ function getOwner() {
351
+ return G.owner;
352
+ }
353
+ function runWithOwner(owner, fn) {
354
+ const prev = G.owner;
355
+ G.owner = owner;
356
+ try {
357
+ return fn();
358
+ } finally {
359
+ G.owner = prev;
360
+ }
361
+ }
362
+ function onCleanup(fn) {
363
+ if (!G.owner) return;
364
+ if (G.owner.disposed) {
365
+ fn();
366
+ return;
367
+ }
368
+ (G.owner.cleanups ??= []).push(fn);
369
+ }
370
+ function disposeOwner(owner, final = true) {
371
+ if (owner.disposed) return;
372
+ if (owner.owned) {
373
+ for (let i = owner.owned.length - 1; i >= 0; i--) disposeOwner(owner.owned[i]);
374
+ owner.owned = null;
375
+ }
376
+ if (owner.cleanups) {
377
+ for (let i = owner.cleanups.length - 1; i >= 0; i--) owner.cleanups[i]();
378
+ owner.cleanups = null;
379
+ }
380
+ if (final) owner.disposed = true;
381
+ }
382
+ function createRoot(fn) {
383
+ const owner = makeOwner(G.owner);
384
+ if (G.owner) (G.owner.owned ??= []).push(owner);
385
+ const prev = G.owner;
386
+ G.owner = owner;
387
+ try {
388
+ return untrack(() => fn(() => disposeOwner(owner)));
389
+ } finally {
390
+ G.owner = prev;
391
+ }
392
+ }
393
+ function setScheduler(fn) {
394
+ G.hostSchedule = fn ?? ((run) => void Promise.resolve().then(run));
395
+ }
396
+ function enqueue(e) {
397
+ if (e.queued) return;
398
+ e.queued = true;
399
+ G.queue.push(e);
400
+ if (!G.scheduled && G.batchDepth === 0) {
401
+ G.scheduled = true;
402
+ G.hostSchedule(flushSync);
403
+ }
404
+ }
405
+ function flushSync() {
406
+ G.scheduled = false;
407
+ if (G.flushing) return;
408
+ G.flushing = true;
409
+ let guard = 0;
410
+ let failed = false;
411
+ let first;
412
+ try {
413
+ while (G.queue.length) {
414
+ if (++guard > 1e5) throw new Error("[fluixi] effect flush did not settle (cycle?)");
415
+ const batchOf = G.queue;
416
+ G.queue = [];
417
+ for (const e of batchOf) {
418
+ e.queued = false;
419
+ if (e.disposed) continue;
420
+ try {
421
+ e.run();
422
+ } catch (error) {
423
+ if (!failed) {
424
+ failed = true;
425
+ first = error;
426
+ }
427
+ }
428
+ }
429
+ }
430
+ } finally {
431
+ G.flushing = false;
432
+ }
433
+ if (failed) throw first;
434
+ }
435
+ function afterWrite() {
436
+ if (G.batchDepth === 0) flushSync();
437
+ }
438
+ var EffectNode = class {
439
+ constructor(fn, report = false, name) {
440
+ this.queued = false;
441
+ this.disposed = false;
442
+ this.owner = makeOwner(G.owner);
443
+ if (G.owner) (G.owner.cleanups ??= []).push(() => this.dispose());
444
+ this.computed = new Computed(() => {
445
+ disposeOwner(this.owner, false);
446
+ runWithOwner(this.owner, () => {
447
+ const r = fn();
448
+ if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
449
+ });
450
+ });
451
+ reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report, ...name ? { name } : {} });
452
+ this.watcher = new Watcher(() => enqueue(this));
453
+ this.run();
454
+ this.watcher.watch(this.computed);
455
+ }
456
+ run() {
457
+ if (this.disposed) return;
458
+ this.watcher.getPending();
459
+ try {
460
+ this.computed.get();
461
+ } catch (e) {
462
+ if (e && typeof e.then === "function" && G.onSuspend) {
463
+ G.onSuspend(e, this.owner);
464
+ return;
465
+ }
466
+ if (G.onError && G.onError(e, this.owner)) return;
467
+ throw e;
468
+ }
469
+ }
470
+ dispose() {
471
+ if (this.disposed) return;
472
+ this.disposed = true;
473
+ reportReactiveDispose(this.computed);
474
+ this.watcher.unwatch(this.computed);
475
+ disposeOwner(this.owner);
476
+ }
477
+ };
478
+ function effect(fn, report = false, name) {
479
+ const node = new EffectNode(fn, report, name);
480
+ return () => node.dispose();
481
+ }
482
+
483
+ // src/lib/signal/graph/compat.ts
484
+ function isThenable(v) {
485
+ return !!v && typeof v.then === "function";
486
+ }
487
+ setScheduler(() => {
488
+ });
489
+ var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
490
+ var $MEMO = /* @__PURE__ */ Symbol.for("memo");
491
+ var $NODE = /* @__PURE__ */ Symbol.for("signal-node");
492
+ function createSignal(value, options) {
493
+ const state = new State(value, { equals: options?.equals });
494
+ const read = (() => state.get());
495
+ const write = ((next) => {
496
+ const v = typeof next === "function" ? next(state.peek()) : next;
497
+ state.set(v);
498
+ afterWrite();
499
+ return v;
500
+ });
501
+ Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
502
+ Object.defineProperty(read, $NODE, {
503
+ value: {
504
+ get value() {
505
+ return state.peek();
506
+ },
507
+ get version() {
508
+ return state.version;
509
+ }
510
+ },
511
+ enumerable: false
512
+ });
513
+ reportReactiveNode({
514
+ kind: "signal",
515
+ node: state,
516
+ handle: read,
517
+ name: options?.name,
518
+ set: write
519
+ });
520
+ if (isObserved()) onCleanup(() => reportReactiveDispose(state));
521
+ return [read, write];
522
+ }
523
+ function createMemo(fn, value, options) {
524
+ let prev = value;
525
+ const owner = getOwner();
526
+ const c = new Computed(
527
+ () => runWithOwner(owner, () => {
528
+ try {
529
+ return prev = fn(prev);
530
+ } catch (e) {
531
+ if (isThenable(e)) {
532
+ reportSuspend(e);
533
+ return prev;
534
+ }
535
+ throw e;
536
+ }
537
+ }),
538
+ { equals: options?.equals }
539
+ );
540
+ const read = (() => c.get());
541
+ Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
542
+ Object.defineProperty(read, $MEMO, { value: true, enumerable: true });
543
+ reportReactiveNode({ kind: "memo", node: c, handle: read, name: options?.name });
544
+ if (isObserved()) onCleanup(() => reportReactiveDispose(c));
545
+ return read;
546
+ }
547
+ function createEffect(fn, value, options) {
548
+ let prev = value;
549
+ return effect(() => {
550
+ const r = fn(prev);
551
+ prev = r;
552
+ }, true, options?.name);
553
+ }
554
+ function createComputed(fn, value) {
555
+ let prev = value;
556
+ effect(() => {
557
+ prev = fn(prev);
558
+ });
559
+ }
560
+ function createRenderEffect(fn, value) {
561
+ let prev = value;
562
+ return effect(() => {
563
+ prev = fn(prev);
564
+ });
565
+ }
566
+
567
+ // src/lib/signal/api.ts
568
+ function signal(value, options) {
569
+ const [read, write] = createSignal(value, options);
570
+ return Object.assign(read, { set: write });
571
+ }
572
+ function memo(fn, value, options) {
573
+ return createMemo(fn, value, options);
574
+ }
575
+ function effect2(fn, value, options) {
576
+ return createEffect(fn, value, options);
577
+ }
578
+ function root(fn) {
579
+ return createRoot(fn);
580
+ }
581
+ function renderEffect(fn, value) {
582
+ return createRenderEffect(fn, value);
583
+ }
584
+ function computed(fn, value) {
585
+ createComputed(fn, value);
586
+ }
587
+ function context(defaultValue, name) {
588
+ return createContext(defaultValue, name);
589
+ }
590
+ function childOwner(parent) {
591
+ return createChildOwner(parent);
592
+ }