@fluixi/reactive 1.0.0-alpha.83 → 1.0.0-alpha.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/dist/cdn/reactive.cjs +2722 -1
  2. package/dist/cdn/reactive.global.js +2 -1
  3. package/dist/cdn/reactive.mjs +2706 -1
  4. package/dist/cdn/signal.cjs +299 -1
  5. package/dist/cdn/signal.d.ts +1 -1
  6. package/dist/cdn/signal.global.js +2 -1
  7. package/dist/cdn/signal.js +1 -1
  8. package/dist/cdn/signal.mjs +276 -1
  9. package/dist/index.cjs +2722 -1
  10. package/dist/index.mjs +2706 -1
  11. package/dist/lib/index.cjs +2723 -1
  12. package/dist/lib/index.js +1 -1
  13. package/dist/lib/index.mjs +2708 -1
  14. package/dist/lib/observable/index.cjs +386 -1
  15. package/dist/lib/observable/index.mjs +364 -1
  16. package/dist/lib/observable/observable.cjs +384 -1
  17. package/dist/lib/observable/observable.d.ts +0 -137
  18. package/dist/lib/observable/observable.d.ts.map +1 -1
  19. package/dist/lib/observable/observable.js +0 -71
  20. package/dist/lib/observable/observable.mjs +361 -1
  21. package/dist/lib/observable/subscription.cjs +180 -1
  22. package/dist/lib/observable/subscription.d.ts +0 -12
  23. package/dist/lib/observable/subscription.d.ts.map +1 -1
  24. package/dist/lib/observable/subscription.js +0 -12
  25. package/dist/lib/observable/subscription.mjs +157 -1
  26. package/dist/lib/observable/types.cjs +18 -1
  27. package/dist/lib/observable/types.d.ts.map +1 -1
  28. package/dist/lib/predicates.cjs +44 -1
  29. package/dist/lib/predicates.d.ts +2 -2
  30. package/dist/lib/predicates.js +2 -2
  31. package/dist/lib/predicates.mjs +23 -1
  32. package/dist/lib/signal/api.cjs +571 -1
  33. package/dist/lib/signal/api.d.ts +211 -1
  34. package/dist/lib/signal/api.d.ts.map +1 -1
  35. package/dist/lib/signal/api.js +207 -12
  36. package/dist/lib/signal/api.mjs +548 -1
  37. package/dist/lib/signal/cached-resource.cjs +672 -1
  38. package/dist/lib/signal/cached-resource.d.ts +28 -16
  39. package/dist/lib/signal/cached-resource.d.ts.map +1 -1
  40. package/dist/lib/signal/cached-resource.js +35 -29
  41. package/dist/lib/signal/cached-resource.mjs +650 -1
  42. package/dist/lib/signal/graph/children.cjs +325 -1
  43. package/dist/lib/signal/graph/children.js +1 -1
  44. package/dist/lib/signal/graph/children.mjs +302 -1
  45. package/dist/lib/signal/graph/compat.cjs +578 -1
  46. package/dist/lib/signal/graph/compat.d.ts +13 -13
  47. package/dist/lib/signal/graph/compat.d.ts.map +1 -1
  48. package/dist/lib/signal/graph/compat.js +33 -31
  49. package/dist/lib/signal/graph/compat.mjs +556 -1
  50. package/dist/lib/signal/graph/core.cjs +295 -1
  51. package/dist/lib/signal/graph/core.d.ts +28 -24
  52. package/dist/lib/signal/graph/core.d.ts.map +1 -1
  53. package/dist/lib/signal/graph/core.js +38 -31
  54. package/dist/lib/signal/graph/core.mjs +273 -1
  55. package/dist/lib/signal/graph/debounced.cjs +668 -1
  56. package/dist/lib/signal/graph/debounced.d.ts +5 -5
  57. package/dist/lib/signal/graph/debounced.d.ts.map +1 -1
  58. package/dist/lib/signal/graph/debounced.js +5 -5
  59. package/dist/lib/signal/graph/debounced.mjs +645 -1
  60. package/dist/lib/signal/graph/derived.cjs +496 -1
  61. package/dist/lib/signal/graph/derived.d.ts +1 -1
  62. package/dist/lib/signal/graph/derived.js +1 -1
  63. package/dist/lib/signal/graph/derived.mjs +473 -1
  64. package/dist/lib/signal/graph/detect.cjs +66 -1
  65. package/dist/lib/signal/graph/detect.mjs +45 -1
  66. package/dist/lib/signal/graph/error-boundary.cjs +301 -1
  67. package/dist/lib/signal/graph/error-boundary.js +3 -3
  68. package/dist/lib/signal/graph/error-boundary.mjs +278 -1
  69. package/dist/lib/signal/graph/index.cjs +305 -1
  70. package/dist/lib/signal/graph/index.d.ts +7 -6
  71. package/dist/lib/signal/graph/index.d.ts.map +1 -1
  72. package/dist/lib/signal/graph/index.js +7 -6
  73. package/dist/lib/signal/graph/index.mjs +283 -1
  74. package/dist/lib/signal/graph/observe.cjs +163 -1
  75. package/dist/lib/signal/graph/observe.d.ts +8 -8
  76. package/dist/lib/signal/graph/observe.js +5 -5
  77. package/dist/lib/signal/graph/observe.mjs +140 -1
  78. package/dist/lib/signal/graph/resource.cjs +620 -1
  79. package/dist/lib/signal/graph/resource.d.ts +1 -1
  80. package/dist/lib/signal/graph/resource.js +7 -8
  81. package/dist/lib/signal/graph/resource.mjs +597 -1
  82. package/dist/lib/signal/graph/runtime.cjs +501 -1
  83. package/dist/lib/signal/graph/runtime.d.ts +7 -7
  84. package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
  85. package/dist/lib/signal/graph/runtime.js +34 -30
  86. package/dist/lib/signal/graph/runtime.mjs +478 -1
  87. package/dist/lib/signal/graph/signal-next.cjs +1208 -1
  88. package/dist/lib/signal/graph/signal-next.d.ts +5 -5
  89. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
  90. package/dist/lib/signal/graph/signal-next.js +14 -12
  91. package/dist/lib/signal/graph/signal-next.mjs +1186 -1
  92. package/dist/lib/signal/graph/ssr-hooks.cjs +60 -1
  93. package/dist/lib/signal/graph/ssr-hooks.d.ts +6 -7
  94. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
  95. package/dist/lib/signal/graph/ssr-hooks.js +6 -7
  96. package/dist/lib/signal/graph/ssr-hooks.mjs +39 -1
  97. package/dist/lib/signal/graph/state.cjs +72 -1
  98. package/dist/lib/signal/graph/state.d.ts +41 -10
  99. package/dist/lib/signal/graph/state.d.ts.map +1 -1
  100. package/dist/lib/signal/graph/state.js +83 -22
  101. package/dist/lib/signal/graph/state.mjs +49 -1
  102. package/dist/lib/signal/graph/suspense.cjs +301 -1
  103. package/dist/lib/signal/graph/suspense.js +4 -4
  104. package/dist/lib/signal/graph/suspense.mjs +278 -1
  105. package/dist/lib/signal/index-legacy.cjs +2540 -1
  106. package/dist/lib/signal/index-legacy.d.ts +1 -1
  107. package/dist/lib/signal/index-legacy.js +1 -1
  108. package/dist/lib/signal/index-legacy.mjs +2518 -1
  109. package/dist/lib/signal/index.cjs +1275 -1
  110. package/dist/lib/signal/index.d.ts +3 -2
  111. package/dist/lib/signal/index.d.ts.map +1 -1
  112. package/dist/lib/signal/index.js +7 -4
  113. package/dist/lib/signal/index.mjs +1253 -1
  114. package/dist/lib/signal/list.cjs +549 -1
  115. package/dist/lib/signal/list.d.ts +5 -5
  116. package/dist/lib/signal/list.js +5 -5
  117. package/dist/lib/signal/list.mjs +526 -1
  118. package/dist/lib/signal/resource-api.cjs +626 -1
  119. package/dist/lib/signal/resource-api.d.ts +5 -5
  120. package/dist/lib/signal/resource-api.js +5 -5
  121. package/dist/lib/signal/resource-api.mjs +603 -1
  122. package/dist/lib/signal/signal.cjs +2023 -1
  123. package/dist/lib/signal/signal.d.ts +4 -4
  124. package/dist/lib/signal/signal.d.ts.map +1 -1
  125. package/dist/lib/signal/signal.js +22 -23
  126. package/dist/lib/signal/signal.mjs +2000 -1
  127. package/dist/lib/signal/types.cjs +38 -1
  128. package/dist/lib/signal/types.d.ts.map +1 -1
  129. package/dist/lib/signal/types.js +2 -2
  130. package/dist/lib/signal/types.mjs +17 -1
  131. package/dist/lib/signal/utilities.cjs +1012 -1
  132. package/dist/lib/signal/utilities.d.ts +0 -108
  133. package/dist/lib/signal/utilities.d.ts.map +1 -1
  134. package/dist/lib/signal/utilities.js +0 -158
  135. package/dist/lib/signal/utilities.mjs +990 -1
  136. package/dist/lib/store/api.cjs +661 -1
  137. package/dist/lib/store/api.d.ts +33 -0
  138. package/dist/lib/store/api.d.ts.map +1 -1
  139. package/dist/lib/store/api.js +41 -8
  140. package/dist/lib/store/api.mjs +645 -1
  141. package/dist/lib/store/index.cjs +740 -1
  142. package/dist/lib/store/index.js +1 -1
  143. package/dist/lib/store/index.mjs +725 -1
  144. package/dist/lib/store/setter.types.cjs +18 -1
  145. package/dist/lib/store/setter.types.d.ts +43 -3
  146. package/dist/lib/store/setter.types.d.ts.map +1 -1
  147. package/dist/lib/store/store.cjs +707 -1
  148. package/dist/lib/store/store.d.ts +72 -0
  149. package/dist/lib/store/store.d.ts.map +1 -1
  150. package/dist/lib/store/store.js +238 -8
  151. package/dist/lib/store/store.mjs +693 -1
  152. package/dist/lib/store/types.cjs +18 -1
  153. package/dist/lib/store/types.d.ts +1 -1
  154. package/dist/lib/store/types.d.ts.map +1 -1
  155. package/dist/lib/store/utils.cjs +43 -1
  156. package/dist/lib/store/utils.d.ts +1 -1
  157. package/dist/lib/store/utils.js +1 -1
  158. package/dist/lib/store/utils.mjs +22 -1
  159. package/dist/lib/subject.cjs +450 -1
  160. package/dist/lib/subject.js +3 -91
  161. package/dist/lib/subject.mjs +427 -1
  162. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  163. package/dist/version.generated.cjs +27 -1
  164. package/dist/version.generated.d.ts +1 -1
  165. package/dist/version.generated.js +2 -2
  166. package/dist/version.generated.mjs +7 -1
  167. package/package.json +5 -4
@@ -1 +1,163 @@
1
- "use strict";var v=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var k=(e,n)=>{for(var t in n)v(e,t,{get:n[t],enumerable:!0})},f=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of p(n))!b.call(e,i)&&i!==t&&v(e,i,{get:()=>n[i],enumerable:!(s=l(n,i))||s.enumerable});return e};var w=e=>f(v({},"__esModule",{value:!0}),e);var H={};k(H,{enterReactiveRun:()=>m,exitReactiveRun:()=>O,isObserved:()=>K,observeReactiveNodes:()=>d,reportReactiveBinding:()=>N,reportReactiveContext:()=>T,reportReactiveContextCreated:()=>E,reportReactiveDirective:()=>D,reportReactiveDispose:()=>C,reportReactiveMove:()=>q,reportReactiveNode:()=>x,reportReactiveProps:()=>S,reportReactiveRun:()=>y,reportReactiveWrite:()=>_,withReactiveOrigin:()=>h});module.exports=w(H);var R="__fluixi_signal_next_state__",g=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},o=globalThis[R]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:g,onSuspend:null,onError:null,observer:null};var a="1.0.0-alpha.83";function d(e){return o.observer=e,()=>{o.observer===e&&(o.observer=null)}}var r=[],u;function h(e,n){if(!o.observer)return n();let t=u;u=e;try{return n()}finally{u=t}}function x(e){let n=o.observer;n&&n.created(e.parents===void 0?{...e,parents:r,origin:e.origin??u}:e)}function m(e){return o.observer?(r.push(e),!0):!1}function O(){r.pop()}function y(e){o.observer?.ran?.(e)}function _(e,n){o.observer?.wrote?.(e,n)}function N(e,n,t,s){let i=o.observer;!i?.bound||!r.length||i.bound(r[r.length-1],e,n,t,s)}function S(e){let n=o.observer;!n?.props||!r.length||!e||n.props(r[r.length-1],e)}function D(e,n,t,s){let i=o.observer;!i?.directive||!r.length||i.directive(r[r.length-1],e,n,t,s)}function E(e){o.observer?.contextCreated?.(e)}function T(e,n,t){let s=o.observer;!s?.context||!r.length||s.context(r[r.length-1],e,n,t)}function q(e,n,t){o.observer?.moved?.(e,n,t)}function C(e){o.observer?.disposed?.(e)}var G="__FLUIXI_DEVTOOLS_HOOK__",c=globalThis[G];if(typeof c?.inject=="function")try{c.inject({observeReactiveNodes:d,version:a})}catch{}function K(){return o.observer!=null}
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/signal/graph/observe.ts
21
+ var observe_exports = {};
22
+ __export(observe_exports, {
23
+ enterReactiveRun: () => enterReactiveRun,
24
+ exitReactiveRun: () => exitReactiveRun,
25
+ isObserved: () => isObserved,
26
+ observeReactiveNodes: () => observeReactiveNodes,
27
+ reportReactiveBinding: () => reportReactiveBinding,
28
+ reportReactiveContext: () => reportReactiveContext,
29
+ reportReactiveContextCreated: () => reportReactiveContextCreated,
30
+ reportReactiveDirective: () => reportReactiveDirective,
31
+ reportReactiveDispose: () => reportReactiveDispose,
32
+ reportReactiveMove: () => reportReactiveMove,
33
+ reportReactiveNode: () => reportReactiveNode,
34
+ reportReactiveProps: () => reportReactiveProps,
35
+ reportReactiveRun: () => reportReactiveRun,
36
+ reportReactiveWrite: () => reportReactiveWrite,
37
+ withReactiveOrigin: () => withReactiveOrigin
38
+ });
39
+ module.exports = __toCommonJS(observe_exports);
40
+
41
+ // src/version.generated.ts
42
+ var VERSION = "1.0.0-alpha.85";
43
+
44
+ // src/lib/signal/graph/state.ts
45
+ var MAJOR = VERSION.split(".")[0];
46
+ var KEY = `__fluixi_signal_state_v${MAJOR}__`;
47
+ var VERSIONS_KEY = `__fluixi_signal_builds_v${MAJOR}__`;
48
+ var defaultSchedule = (run) => {
49
+ if (typeof queueMicrotask === "function") queueMicrotask(run);
50
+ else void Promise.resolve().then(run);
51
+ };
52
+ function defaults() {
53
+ return {
54
+ consumer: null,
55
+ untracked: false,
56
+ owner: null,
57
+ queue: [],
58
+ scheduled: false,
59
+ flushing: false,
60
+ batchDepth: 0,
61
+ hostSchedule: defaultSchedule,
62
+ onSuspend: null,
63
+ onError: null,
64
+ observer: null
65
+ };
66
+ }
67
+ var realm = globalThis;
68
+ function backfillState(existing) {
69
+ const fresh = defaults();
70
+ const target = existing;
71
+ for (const field of Object.keys(fresh)) {
72
+ if (!(field in existing)) target[field] = fresh[field];
73
+ }
74
+ return existing;
75
+ }
76
+ function claim() {
77
+ const existing = realm[KEY];
78
+ return existing ? backfillState(existing) : realm[KEY] = defaults();
79
+ }
80
+ var G = claim();
81
+ (realm[VERSIONS_KEY] ??= []).push(VERSION);
82
+
83
+ // src/lib/signal/graph/observe.ts
84
+ function observeReactiveNodes(next) {
85
+ G.observer = next;
86
+ return () => {
87
+ if (G.observer === next) G.observer = null;
88
+ };
89
+ }
90
+ var running = [];
91
+ var origin;
92
+ function withReactiveOrigin(owner, fn) {
93
+ if (!G.observer) return fn();
94
+ const previous = origin;
95
+ origin = owner;
96
+ try {
97
+ return fn();
98
+ } finally {
99
+ origin = previous;
100
+ }
101
+ }
102
+ function reportReactiveNode(report) {
103
+ const observer = G.observer;
104
+ if (observer) {
105
+ observer.created(
106
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
107
+ );
108
+ }
109
+ }
110
+ function enterReactiveRun(node) {
111
+ if (!G.observer) return false;
112
+ running.push(node);
113
+ return true;
114
+ }
115
+ function exitReactiveRun() {
116
+ running.pop();
117
+ }
118
+ function reportReactiveRun(node) {
119
+ G.observer?.ran?.(node);
120
+ }
121
+ function reportReactiveWrite(node, by) {
122
+ G.observer?.wrote?.(node, by);
123
+ }
124
+ function reportReactiveBinding(target, kind, name, accessor) {
125
+ const observer = G.observer;
126
+ if (!observer?.bound || !running.length) return;
127
+ observer.bound(running[running.length - 1], target, kind, name, accessor);
128
+ }
129
+ function reportReactiveProps(props) {
130
+ const observer = G.observer;
131
+ if (!observer?.props || !running.length || !props) return;
132
+ observer.props(running[running.length - 1], props);
133
+ }
134
+ function reportReactiveDirective(target, kind, name, accessor) {
135
+ const observer = G.observer;
136
+ if (!observer?.directive || !running.length) return;
137
+ observer.directive(running[running.length - 1], target, kind, name, accessor);
138
+ }
139
+ function reportReactiveContextCreated(id) {
140
+ G.observer?.contextCreated?.(id);
141
+ }
142
+ function reportReactiveContext(id, kind, value) {
143
+ const observer = G.observer;
144
+ if (!observer?.context || !running.length) return;
145
+ observer.context(running[running.length - 1], id, kind, value);
146
+ }
147
+ function reportReactiveMove(node, origin2, name) {
148
+ G.observer?.moved?.(node, origin2, name);
149
+ }
150
+ function reportReactiveDispose(node) {
151
+ G.observer?.disposed?.(node);
152
+ }
153
+ var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
154
+ var hook = globalThis[HOOK];
155
+ if (typeof hook?.inject === "function") {
156
+ try {
157
+ hook.inject({ observeReactiveNodes, version: VERSION });
158
+ } catch {
159
+ }
160
+ }
161
+ function isObserved() {
162
+ return G.observer != null;
163
+ }
@@ -9,24 +9,24 @@ export interface ReactiveNodeReport {
9
9
  name?: string;
10
10
  /**
11
11
  * How to write it, for a signal. A watcher setting the value through this goes through
12
- * the same path the application does writing the node directly marks its readers dirty
12
+ * the same path the application does, writing the node directly marks its readers dirty
13
13
  * without ever flushing them, so the page keeps whatever it last rendered.
14
14
  */
15
15
  set?: (value: unknown) => void;
16
16
  /**
17
17
  * The node this one was built for. A store creates a signal per key, lazily, wherever it
18
- * is first read the useful location is the store's, not the reader's.
18
+ * is first read, the useful location is the store's, not the reader's.
19
19
  */
20
20
  origin?: unknown;
21
21
  /**
22
- * The node is the framework's own plumbing a render effect, one per dom binding. A graph
22
+ * The node is the framework's own plumbing, a render effect, one per dom binding. A graph
23
23
  * does not show these, but it needs to know they exist: a row added to a list is created
24
24
  * inside one, and without it the row has no ancestor it can be attached to.
25
25
  */
26
26
  internal?: boolean;
27
27
  /**
28
28
  * The computations running when this node was made, outermost first. A component's wrapper
29
- * memo reads nothing itself, so what it created is the only thing tying it to the graph
29
+ * memo reads nothing itself, so what it created is the only thing tying it to the graph
30
30
  * and the whole chain is given because the nearest one is often a render effect, which no
31
31
  * graph shows.
32
32
  *
@@ -41,15 +41,15 @@ export interface ReactiveObserver {
41
41
  /** An effect was disposed. Memos and signals go with their owner and are not reported. */
42
42
  disposed?(node: unknown): void;
43
43
  /**
44
- * A signal was written, and by which computation nothing, when the write came from an
44
+ * A signal was written, and by which computation, nothing, when the write came from an
45
45
  * event handler, which is where most of them come from.
46
46
  */
47
47
  wrote?(node: unknown, by: unknown): void;
48
48
  /**
49
49
  * A node now belongs somewhere else, and is called something else.
50
50
  *
51
- * A store write replaces the object that held a value `set({ items: [...items, one] })`
52
- * builds a new array and the signals underneath it are the same signals in a new place.
51
+ * A store write replaces the object that held a value: `set({ items: [...items, one] })`
52
+ * builds a new array, and the signals underneath it are the same signals in a new place.
53
53
  * Without this they keep pointing at a node that no longer exists.
54
54
  */
55
55
  moved?(node: unknown, origin: unknown, name?: string): void;
@@ -93,7 +93,7 @@ export interface ReactiveObserver {
93
93
  /**
94
94
  * Watch the graph. Returns a function that stops watching.
95
95
  *
96
- * One observer at a time the last to register wins. Two tools watching one page at once is
96
+ * One observer at a time, the last to register wins. Two tools watching one page at once is
97
97
  * not a case worth carrying state for.
98
98
  */
99
99
  export declare function observeReactiveNodes(next: ReactiveObserver): () => void;
@@ -2,8 +2,8 @@
2
2
  * A place for a tool to watch the reactive graph from outside it.
3
3
  *
4
4
  * The runtime says a node exists, a computation re-ran, or an effect went away, and hands
5
- * over the node itself. It does nothing else. Edges are already on the node a source keeps
6
- * its `observers`, a consumer keeps its `sources` so a watcher reads the graph rather than
5
+ * over the node itself. It does nothing else. Edges are already on the node, a source keeps
6
+ * its `observers`, a consumer keeps its `sources`, so a watcher reads the graph rather than
7
7
  * reconstructing it, and nothing here wraps or replaces a primitive.
8
8
  *
9
9
  * Nothing is registered by default: an unwatched runtime pays one null check per node
@@ -12,14 +12,14 @@
12
12
  * @fluixi/devtools is the intended caller. Nothing in the framework reads it back.
13
13
  *
14
14
  * The observer lives on the shared graph state rather than in a module `let`, so a bundle
15
- * carrying two copies of this module still has one observer the same reason G exists.
15
+ * carrying two copies of this module still has one observer, the same reason G exists.
16
16
  */
17
17
  import { G } from './state.js';
18
18
  import { VERSION } from '../../../version.generated.js';
19
19
  /**
20
20
  * Watch the graph. Returns a function that stops watching.
21
21
  *
22
- * One observer at a time the last to register wins. Two tools watching one page at once is
22
+ * One observer at a time, the last to register wins. Two tools watching one page at once is
23
23
  * not a case worth carrying state for.
24
24
  */
25
25
  export function observeReactiveNodes(next) {
@@ -130,7 +130,7 @@ export function reportReactiveDispose(node) {
130
130
  * have to import a debugger to be debuggable. So a tool sets this global before any of the
131
131
  * app loads, and the runtime hands it the door on the way past.
132
132
  *
133
- * Set it too late and nothing happens the runtime only offers once, when this module is
133
+ * Set it too late and nothing happens, the runtime only offers once, when this module is
134
134
  * first evaluated. A browser agent has to run at document_start for that reason.
135
135
  */
136
136
  const HOOK = '__FLUIXI_DEVTOOLS_HOOK__';
@@ -1 +1,140 @@
1
- var c="__fluixi_signal_next_state__",d=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},o=globalThis[c]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:d,onSuspend:null,onError:null,observer:null};var v="1.0.0-alpha.83";function l(e){return o.observer=e,()=>{o.observer===e&&(o.observer=null)}}var r=[],u;function R(e,n){if(!o.observer)return n();let t=u;u=e;try{return n()}finally{u=t}}function g(e){let n=o.observer;n&&n.created(e.parents===void 0?{...e,parents:r,origin:e.origin??u}:e)}function h(e){return o.observer?(r.push(e),!0):!1}function x(){r.pop()}function m(e){o.observer?.ran?.(e)}function O(e,n){o.observer?.wrote?.(e,n)}function y(e,n,t,i){let s=o.observer;!s?.bound||!r.length||s.bound(r[r.length-1],e,n,t,i)}function _(e){let n=o.observer;!n?.props||!r.length||!e||n.props(r[r.length-1],e)}function N(e,n,t,i){let s=o.observer;!s?.directive||!r.length||s.directive(r[r.length-1],e,n,t,i)}function S(e){o.observer?.contextCreated?.(e)}function D(e,n,t){let i=o.observer;!i?.context||!r.length||i.context(r[r.length-1],e,n,t)}function E(e,n,t){o.observer?.moved?.(e,n,t)}function T(e){o.observer?.disposed?.(e)}var p="__FLUIXI_DEVTOOLS_HOOK__",a=globalThis[p];if(typeof a?.inject=="function")try{a.inject({observeReactiveNodes:l,version:v})}catch{}function q(){return o.observer!=null}export{h as enterReactiveRun,x as exitReactiveRun,q as isObserved,l as observeReactiveNodes,y as reportReactiveBinding,D as reportReactiveContext,S as reportReactiveContextCreated,N as reportReactiveDirective,T as reportReactiveDispose,E as reportReactiveMove,g as reportReactiveNode,_ as reportReactiveProps,m as reportReactiveRun,O as reportReactiveWrite,R as withReactiveOrigin};
1
+ // src/version.generated.ts
2
+ var VERSION = "1.0.0-alpha.85";
3
+
4
+ // src/lib/signal/graph/state.ts
5
+ var MAJOR = VERSION.split(".")[0];
6
+ var KEY = `__fluixi_signal_state_v${MAJOR}__`;
7
+ var VERSIONS_KEY = `__fluixi_signal_builds_v${MAJOR}__`;
8
+ var defaultSchedule = (run) => {
9
+ if (typeof queueMicrotask === "function") queueMicrotask(run);
10
+ else void Promise.resolve().then(run);
11
+ };
12
+ function defaults() {
13
+ return {
14
+ consumer: null,
15
+ untracked: false,
16
+ owner: null,
17
+ queue: [],
18
+ scheduled: false,
19
+ flushing: false,
20
+ batchDepth: 0,
21
+ hostSchedule: defaultSchedule,
22
+ onSuspend: null,
23
+ onError: null,
24
+ observer: null
25
+ };
26
+ }
27
+ var realm = globalThis;
28
+ function backfillState(existing) {
29
+ const fresh = defaults();
30
+ const target = existing;
31
+ for (const field of Object.keys(fresh)) {
32
+ if (!(field in existing)) target[field] = fresh[field];
33
+ }
34
+ return existing;
35
+ }
36
+ function claim() {
37
+ const existing = realm[KEY];
38
+ return existing ? backfillState(existing) : realm[KEY] = defaults();
39
+ }
40
+ var G = claim();
41
+ (realm[VERSIONS_KEY] ??= []).push(VERSION);
42
+
43
+ // src/lib/signal/graph/observe.ts
44
+ function observeReactiveNodes(next) {
45
+ G.observer = next;
46
+ return () => {
47
+ if (G.observer === next) G.observer = null;
48
+ };
49
+ }
50
+ var running = [];
51
+ var origin;
52
+ function withReactiveOrigin(owner, fn) {
53
+ if (!G.observer) return fn();
54
+ const previous = origin;
55
+ origin = owner;
56
+ try {
57
+ return fn();
58
+ } finally {
59
+ origin = previous;
60
+ }
61
+ }
62
+ function reportReactiveNode(report) {
63
+ const observer = G.observer;
64
+ if (observer) {
65
+ observer.created(
66
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
67
+ );
68
+ }
69
+ }
70
+ function enterReactiveRun(node) {
71
+ if (!G.observer) return false;
72
+ running.push(node);
73
+ return true;
74
+ }
75
+ function exitReactiveRun() {
76
+ running.pop();
77
+ }
78
+ function reportReactiveRun(node) {
79
+ G.observer?.ran?.(node);
80
+ }
81
+ function reportReactiveWrite(node, by) {
82
+ G.observer?.wrote?.(node, by);
83
+ }
84
+ function reportReactiveBinding(target, kind, name, accessor) {
85
+ const observer = G.observer;
86
+ if (!observer?.bound || !running.length) return;
87
+ observer.bound(running[running.length - 1], target, kind, name, accessor);
88
+ }
89
+ function reportReactiveProps(props) {
90
+ const observer = G.observer;
91
+ if (!observer?.props || !running.length || !props) return;
92
+ observer.props(running[running.length - 1], props);
93
+ }
94
+ function reportReactiveDirective(target, kind, name, accessor) {
95
+ const observer = G.observer;
96
+ if (!observer?.directive || !running.length) return;
97
+ observer.directive(running[running.length - 1], target, kind, name, accessor);
98
+ }
99
+ function reportReactiveContextCreated(id) {
100
+ G.observer?.contextCreated?.(id);
101
+ }
102
+ function reportReactiveContext(id, kind, value) {
103
+ const observer = G.observer;
104
+ if (!observer?.context || !running.length) return;
105
+ observer.context(running[running.length - 1], id, kind, value);
106
+ }
107
+ function reportReactiveMove(node, origin2, name) {
108
+ G.observer?.moved?.(node, origin2, name);
109
+ }
110
+ function reportReactiveDispose(node) {
111
+ G.observer?.disposed?.(node);
112
+ }
113
+ var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
114
+ var hook = globalThis[HOOK];
115
+ if (typeof hook?.inject === "function") {
116
+ try {
117
+ hook.inject({ observeReactiveNodes, version: VERSION });
118
+ } catch {
119
+ }
120
+ }
121
+ function isObserved() {
122
+ return G.observer != null;
123
+ }
124
+ export {
125
+ enterReactiveRun,
126
+ exitReactiveRun,
127
+ isObserved,
128
+ observeReactiveNodes,
129
+ reportReactiveBinding,
130
+ reportReactiveContext,
131
+ reportReactiveContextCreated,
132
+ reportReactiveDirective,
133
+ reportReactiveDispose,
134
+ reportReactiveMove,
135
+ reportReactiveNode,
136
+ reportReactiveProps,
137
+ reportReactiveRun,
138
+ reportReactiveWrite,
139
+ withReactiveOrigin
140
+ };