@fluixi/devtools 1.0.0-alpha.107 → 1.0.0-alpha.109

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 (65) hide show
  1. package/dist/callsite.mjs +4 -63
  2. package/dist/change-view.mjs +6 -106
  3. package/dist/chunk-2VDMQ3VF.mjs +520 -0
  4. package/dist/chunk-33U2S43X.mjs +121 -0
  5. package/dist/chunk-4P45Y5EB.mjs +214 -0
  6. package/dist/chunk-B3SAJ7QG.mjs +72 -0
  7. package/dist/chunk-CPZWLBCQ.mjs +35 -0
  8. package/dist/chunk-D25KZZBZ.mjs +212 -0
  9. package/dist/chunk-EBSROPWJ.mjs +314 -0
  10. package/dist/chunk-F664XLZL.mjs +743 -0
  11. package/dist/chunk-FY5K3QVT.mjs +35 -0
  12. package/dist/chunk-G7Z7CVP5.mjs +184 -0
  13. package/dist/chunk-GDQXCOQB.mjs +43 -0
  14. package/dist/chunk-L6XQGNMW.mjs +106 -0
  15. package/dist/chunk-MN6O673L.mjs +90 -0
  16. package/dist/chunk-NDUBBBNL.mjs +70 -0
  17. package/dist/chunk-NT7YMK77.mjs +157 -0
  18. package/dist/chunk-NVULLJDH.mjs +120 -0
  19. package/dist/chunk-NWLSDERQ.mjs +68 -0
  20. package/dist/chunk-OPIGF5XB.mjs +184 -0
  21. package/dist/chunk-P5I7DWFX.mjs +292 -0
  22. package/dist/chunk-PKARAAIS.mjs +75 -0
  23. package/dist/chunk-PSSBFXBD.mjs +155 -0
  24. package/dist/chunk-PTQ5VCYE.mjs +103 -0
  25. package/dist/chunk-PU4MJ5RU.mjs +107 -0
  26. package/dist/chunk-UAEJ3N7F.mjs +76 -0
  27. package/dist/chunk-V6DKWEYD.mjs +67 -0
  28. package/dist/chunk-VO2V7AC5.mjs +80 -0
  29. package/dist/chunk-WGQH7RUW.mjs +25 -0
  30. package/dist/chunk-Y5OQWBAM.mjs +777 -0
  31. package/dist/chunk-Z6KYHEKY.mjs +64 -0
  32. package/dist/copy.mjs +3 -39
  33. package/dist/describe.mjs +3 -31
  34. package/dist/detail-panel.mjs +6 -280
  35. package/dist/diff.mjs +4 -201
  36. package/dist/dom.mjs +7 -176
  37. package/dist/export.mjs +6 -207
  38. package/dist/float.mjs +5 -206
  39. package/dist/format.mjs +5 -151
  40. package/dist/graph-view.mjs +9 -875
  41. package/dist/highlight.mjs +6 -113
  42. package/dist/history.mjs +4 -70
  43. package/dist/hook.mjs +16 -1719
  44. package/dist/index.cjs +1 -1
  45. package/dist/index.mjs +106 -4673
  46. package/dist/inspector.mjs +11 -677
  47. package/dist/instrument.mjs +9 -486
  48. package/dist/kind-filter.mjs +6 -148
  49. package/dist/menu.mjs +4 -116
  50. package/dist/observe.mjs +14 -1510
  51. package/dist/palette.mjs +6 -28
  52. package/dist/path.mjs +3 -21
  53. package/dist/plugin.mjs +9 -57
  54. package/dist/plugins/context.mjs +6 -71
  55. package/dist/plugins/directives.mjs +8 -68
  56. package/dist/plugins/index.cjs +1 -1
  57. package/dist/plugins/index.mjs +13 -136
  58. package/dist/source.mjs +12 -93
  59. package/dist/timeline.mjs +7 -323
  60. package/dist/tree.mjs +11 -558
  61. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  62. package/dist/value-pane.mjs +6 -196
  63. package/dist/wire.cjs +1 -1
  64. package/dist/wire.mjs +6 -86
  65. package/package.json +3 -3
@@ -0,0 +1,314 @@
1
+ import {
2
+ componentSource,
3
+ installSourceMarker,
4
+ takeReactiveSource
5
+ } from "./chunk-L6XQGNMW.mjs";
6
+ import {
7
+ formatValue,
8
+ shorten
9
+ } from "./chunk-NT7YMK77.mjs";
10
+
11
+ // src/instrument.ts
12
+ import {
13
+ createSignal,
14
+ createMemo,
15
+ createEffect,
16
+ createResource,
17
+ createRoot,
18
+ untrack,
19
+ onCleanup,
20
+ getOwner,
21
+ runWithOwner,
22
+ Signal
23
+ } from "@fluixi/reactive/signal";
24
+ import { createStore } from "@fluixi/reactive/store";
25
+ var $NODE = /* @__PURE__ */ Symbol.for("signal-node");
26
+ var KIND_OF_BUILTIN = {
27
+ Show: "control",
28
+ For: "control",
29
+ Index: "control",
30
+ Switch: "control",
31
+ Match: "control",
32
+ Portal: "control",
33
+ Dynamic: "control",
34
+ ErrorBoundary: "control",
35
+ Suspense: "control",
36
+ SuspenseList: "control",
37
+ Await: "control",
38
+ Router: "router",
39
+ Outlet: "router",
40
+ Redirect: "router",
41
+ Link: "router"
42
+ };
43
+ var CORE_STATE = { 0: "clean", 1: "check", 2: "dirty" };
44
+ function nodeVersion(n) {
45
+ return n.core && typeof n.core.version === "number" ? n.core.version : n.runs;
46
+ }
47
+ function nodeState(n) {
48
+ return n.core && typeof n.core.state === "number" ? CORE_STATE[n.core.state] : void 0;
49
+ }
50
+ var fmt = (v) => formatValue(v);
51
+ var short = (s, n = 18) => shorten(s, n);
52
+ function createReactor() {
53
+ installSourceMarker();
54
+ const graph = /* @__PURE__ */ new Map();
55
+ const runsAtLastSample = /* @__PURE__ */ new Map();
56
+ const unnamed = /* @__PURE__ */ new Set();
57
+ const consumerStack = [];
58
+ let seq = 0;
59
+ let dispose = () => {
60
+ };
61
+ let rootOwner = null;
62
+ const claims = (node, value) => {
63
+ for (const dep of node.deps) {
64
+ const other = graph.get(dep);
65
+ if (other?.read && other.read() === value) return false;
66
+ }
67
+ return true;
68
+ };
69
+ const forget = (id) => {
70
+ const owner = getOwner() ?? rootOwner;
71
+ if (owner) {
72
+ runWithOwner(
73
+ owner,
74
+ () => onCleanup(() => {
75
+ graph.delete(id);
76
+ runsAtLastSample.delete(id);
77
+ unnamed.delete(id);
78
+ })
79
+ );
80
+ }
81
+ };
82
+ const recordRead = (sourceId) => {
83
+ const c = consumerStack[consumerStack.length - 1];
84
+ if (c != null) graph.get(c)?.deps.add(sourceId);
85
+ };
86
+ const recordWrite = (targetId) => {
87
+ const c = consumerStack[consumerStack.length - 1];
88
+ if (c != null && c !== targetId) graph.get(c)?.writes.add(targetId);
89
+ };
90
+ const base = (id, named, kind, fallback) => {
91
+ const mark = takeReactiveSource();
92
+ if (!named && !mark?.name) unnamed.add(id);
93
+ return {
94
+ id,
95
+ label: named ?? mark?.name ?? fallback,
96
+ kind,
97
+ deps: /* @__PURE__ */ new Set(),
98
+ writes: /* @__PURE__ */ new Set(),
99
+ runs: 0,
100
+ lastPulse: 0,
101
+ ...mark?.location ? { source: mark.location } : {}
102
+ };
103
+ };
104
+ const trackedCreateSignal = (value, options) => {
105
+ const id = seq++;
106
+ const [get, set] = createSignal(value, options);
107
+ const node = base(id, options?.name, "state", `s${id}`);
108
+ node.read = () => untrack(get);
109
+ node.detail = formatValue(value);
110
+ node.value = shorten(node.detail);
111
+ node.core = get[$NODE] ?? null;
112
+ graph.set(id, node);
113
+ forget(id);
114
+ const read = () => {
115
+ recordRead(id);
116
+ return get();
117
+ };
118
+ const write = (v) => {
119
+ recordWrite(id);
120
+ return set(typeof v === "function" ? v(untrack(get)) : v);
121
+ };
122
+ return [read, write];
123
+ };
124
+ const trackedCreateMemo = (fn, value, options) => {
125
+ const id = seq++;
126
+ const node = base(id, options?.name, "memo", `m${id}`);
127
+ graph.set(id, node);
128
+ forget(id);
129
+ const m = createMemo(() => {
130
+ node.core ??= Signal.subtle.currentComputed();
131
+ node.deps.clear();
132
+ node.writes.clear();
133
+ node.runs++;
134
+ consumerStack.push(id);
135
+ try {
136
+ return fn();
137
+ } finally {
138
+ consumerStack.pop();
139
+ }
140
+ }, value, options);
141
+ node.read = () => untrack(m);
142
+ return () => {
143
+ recordRead(id);
144
+ return m();
145
+ };
146
+ };
147
+ const trackedCreateEffect = (fn, options) => {
148
+ const id = seq++;
149
+ const node = base(id, options?.name, "effect", `e${id}`);
150
+ graph.set(id, node);
151
+ forget(id);
152
+ createEffect(() => {
153
+ node.core ??= Signal.subtle.currentComputed();
154
+ node.deps.clear();
155
+ node.writes.clear();
156
+ node.runs++;
157
+ node.lastPulse = performance.now();
158
+ consumerStack.push(id);
159
+ try {
160
+ fn();
161
+ } finally {
162
+ consumerStack.pop();
163
+ }
164
+ });
165
+ };
166
+ const trackedCreateStore = (initial, options) => {
167
+ const id = seq++;
168
+ const [proxy, setter] = createStore(initial, { immutable: true, ...options });
169
+ const node = base(id, options?.name, "store", `store${id}`);
170
+ node.read = () => {
171
+ try {
172
+ return untrack(() => JSON.stringify(proxy));
173
+ } catch {
174
+ return "{…}";
175
+ }
176
+ };
177
+ node.value = "{…}";
178
+ graph.set(id, node);
179
+ forget(id);
180
+ const recording = new Proxy(proxy, {
181
+ get(t, p, r) {
182
+ recordRead(id);
183
+ return Reflect.get(t, p, r);
184
+ }
185
+ });
186
+ const write = (...args) => {
187
+ recordWrite(id);
188
+ return setter(...args);
189
+ };
190
+ return [recording, write];
191
+ };
192
+ const trackedCreateResource = (...args) => {
193
+ const id = seq++;
194
+ const last = args[args.length - 1];
195
+ const name = last && typeof last === "object" && !Array.isArray(last) && typeof last !== "function" ? last.name : void 0;
196
+ const node = base(id, name, "resource", `res${id}`);
197
+ const [data, actions] = createResource(...args);
198
+ node.read = () => {
199
+ try {
200
+ return untrack(() => data.loading ? "⏳ loading" : JSON.stringify(data.latest));
201
+ } catch {
202
+ return "?";
203
+ }
204
+ };
205
+ node.value = "⏳ loading";
206
+ graph.set(id, node);
207
+ forget(id);
208
+ const accessor = (() => {
209
+ recordRead(id);
210
+ return data();
211
+ });
212
+ for (const k of ["loading", "error", "latest", "state"]) {
213
+ Object.defineProperty(accessor, k, { get: () => data[k] });
214
+ }
215
+ return [accessor, actions];
216
+ };
217
+ const trackedSignal = (value, options) => {
218
+ const [read, write] = trackedCreateSignal(value, options);
219
+ Object.defineProperty(read, "set", { value: write });
220
+ return read;
221
+ };
222
+ const trackedMemo = trackedCreateMemo;
223
+ const trackedEffect = trackedCreateEffect;
224
+ const trackedStore = (initial, options) => {
225
+ const [state, set] = trackedCreateStore(initial, options);
226
+ return new Proxy(state, {
227
+ get: (target, key) => key === "set" ? set : target[key],
228
+ has: (target, key) => key === "set" || Reflect.has(target, key)
229
+ });
230
+ };
231
+ const trackedResource = (...args) => {
232
+ const [accessor, controls] = trackedCreateResource(...args);
233
+ return Object.assign(accessor, controls);
234
+ };
235
+ const api = {
236
+ createSignal: trackedCreateSignal,
237
+ createMemo: trackedCreateMemo,
238
+ createEffect: trackedCreateEffect,
239
+ createStore: trackedCreateStore,
240
+ createResource: trackedCreateResource,
241
+ signal: trackedSignal,
242
+ memo: trackedMemo,
243
+ store: trackedStore,
244
+ effect: trackedEffect,
245
+ resource: trackedResource
246
+ };
247
+ return {
248
+ graph,
249
+ run(setup) {
250
+ dispose();
251
+ graph.clear();
252
+ runsAtLastSample.clear();
253
+ unnamed.clear();
254
+ seq = 0;
255
+ consumerStack.length = 0;
256
+ createRoot((d) => {
257
+ dispose = d;
258
+ rootOwner = getOwner();
259
+ setup(api);
260
+ });
261
+ },
262
+ sample() {
263
+ const changed = [];
264
+ const now = Date.now();
265
+ for (const node of graph.values()) {
266
+ if (!node.read) {
267
+ const seen = runsAtLastSample.get(node.id);
268
+ if (seen !== void 0 && node.runs > seen) {
269
+ node.lastPulse = now;
270
+ changed.push(node.id);
271
+ }
272
+ runsAtLastSample.set(node.id, node.runs);
273
+ continue;
274
+ }
275
+ const raw = node.read();
276
+ const stamped = raw?.$name;
277
+ if (node.kind === "memo" && typeof stamped === "string" && stamped && claims(node, raw)) {
278
+ node.kind = KIND_OF_BUILTIN[stamped] ?? "component";
279
+ node.declaredAt = componentSource(stamped);
280
+ node.source ??= node.declaredAt;
281
+ if (unnamed.has(node.id)) {
282
+ node.label = stamped;
283
+ unnamed.delete(node.id);
284
+ }
285
+ }
286
+ const detail = formatValue(raw);
287
+ const next = shorten(detail);
288
+ if (next !== node.value || detail !== node.detail) {
289
+ node.detail = detail;
290
+ node.value = next;
291
+ node.runs++;
292
+ node.lastPulse = now;
293
+ changed.push(node.id);
294
+ }
295
+ runsAtLastSample.set(node.id, node.runs);
296
+ }
297
+ return changed;
298
+ },
299
+ dispose() {
300
+ dispose();
301
+ dispose = () => {
302
+ };
303
+ }
304
+ };
305
+ }
306
+
307
+ export {
308
+ KIND_OF_BUILTIN,
309
+ nodeVersion,
310
+ nodeState,
311
+ fmt,
312
+ short,
313
+ createReactor
314
+ };