sibujs 1.2.0 → 1.4.0
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.
- package/README.md +29 -25
- package/dist/browser.cjs +804 -2
- package/dist/browser.d.cts +591 -1
- package/dist/browser.d.ts +591 -1
- package/dist/browser.js +50 -8
- package/dist/build.cjs +655 -237
- package/dist/build.js +15 -93
- package/dist/cdn.global.js +188 -7
- package/dist/chunk-2BYQDGN3.js +742 -0
- package/dist/chunk-32DY64NT.js +282 -0
- package/dist/chunk-3AIRKM3B.js +1263 -0
- package/dist/chunk-3X2YG6YM.js +505 -0
- package/dist/chunk-5X6PP2UK.js +28 -0
- package/dist/chunk-77L6NL3X.js +1097 -0
- package/dist/chunk-BGN5ZMP4.js +26 -0
- package/dist/chunk-BTU3TJDS.js +365 -0
- package/dist/chunk-CHF5OHIA.js +61 -0
- package/dist/chunk-CMBFNA7L.js +27 -0
- package/dist/chunk-CNZ35WI2.js +178 -0
- package/dist/chunk-DAHRH4ON.js +331 -0
- package/dist/chunk-EBGIRKQY.js +616 -0
- package/dist/chunk-EUZND3CB.js +27 -0
- package/dist/chunk-F3FA4F32.js +292 -0
- package/dist/chunk-JAKHTMQU.js +1000 -0
- package/dist/chunk-JCI5M6U6.js +956 -0
- package/dist/chunk-KQPDEVVS.js +398 -0
- package/dist/chunk-M4NLBH4I.js +725 -0
- package/dist/chunk-NEKUBFPT.js +60 -0
- package/dist/chunk-NYVAC6P5.js +37 -0
- package/dist/chunk-PTQJDMRT.js +146 -0
- package/dist/chunk-QWZG56ET.js +2744 -0
- package/dist/chunk-TSOKIX5Z.js +654 -0
- package/dist/chunk-UHNL42EF.js +2730 -0
- package/dist/chunk-VRW3FULF.js +725 -0
- package/dist/chunk-WZSPOOER.js +84 -0
- package/dist/chunk-YT6HQ6AM.js +14 -0
- package/dist/chunk-ZD6OAMTH.js +277 -0
- package/dist/chunk-ZWKZCBO6.js +317 -0
- package/dist/contracts-DDrwxvJ-.d.cts +245 -0
- package/dist/contracts-DDrwxvJ-.d.ts +245 -0
- package/dist/contracts-xo5ckdRP.d.cts +240 -0
- package/dist/contracts-xo5ckdRP.d.ts +240 -0
- package/dist/data.cjs +35 -2
- package/dist/data.d.cts +7 -0
- package/dist/data.d.ts +7 -0
- package/dist/data.js +9 -8
- package/dist/devtools.cjs +122 -0
- package/dist/devtools.d.cts +69 -461
- package/dist/devtools.d.ts +69 -461
- package/dist/devtools.js +127 -6
- package/dist/ecosystem.cjs +23 -6
- package/dist/ecosystem.d.cts +1 -1
- package/dist/ecosystem.d.ts +1 -1
- package/dist/ecosystem.js +10 -9
- package/dist/extras.cjs +1208 -88
- package/dist/extras.d.cts +6 -6
- package/dist/extras.d.ts +6 -6
- package/dist/extras.js +70 -33
- package/dist/index.cjs +663 -158
- package/dist/index.d.cts +398 -40
- package/dist/index.d.ts +398 -40
- package/dist/index.js +39 -21
- package/dist/introspect-BumjnBKr.d.cts +477 -0
- package/dist/introspect-CZrlcaYy.d.ts +477 -0
- package/dist/introspect-Cb0zgpi2.d.cts +477 -0
- package/dist/introspect-Y2xNXGSf.d.ts +477 -0
- package/dist/motion.js +4 -4
- package/dist/patterns.cjs +51 -24
- package/dist/patterns.d.cts +19 -57
- package/dist/patterns.d.ts +19 -57
- package/dist/patterns.js +8 -16
- package/dist/performance.js +4 -4
- package/dist/plugins.cjs +429 -82
- package/dist/plugins.d.cts +27 -4
- package/dist/plugins.d.ts +27 -4
- package/dist/plugins.js +156 -37
- package/dist/ssr-4PBXAOO3.js +40 -0
- package/dist/ssr-Do_SiVoL.d.cts +201 -0
- package/dist/ssr-Do_SiVoL.d.ts +201 -0
- package/dist/ssr.cjs +312 -60
- package/dist/ssr.d.cts +10 -1
- package/dist/ssr.d.ts +10 -1
- package/dist/ssr.js +13 -10
- package/dist/tagFactory-DaJ0YWX6.d.cts +47 -0
- package/dist/tagFactory-DaJ0YWX6.d.ts +47 -0
- package/dist/testing.cjs +233 -2
- package/dist/testing.d.cts +42 -1
- package/dist/testing.d.ts +42 -1
- package/dist/testing.js +129 -2
- package/dist/ui.cjs +374 -8
- package/dist/ui.d.cts +252 -2
- package/dist/ui.d.ts +252 -2
- package/dist/ui.js +329 -11
- package/dist/widgets.js +7 -7
- package/package.json +1 -1
package/dist/devtools.d.ts
CHANGED
|
@@ -1,477 +1,85 @@
|
|
|
1
|
-
|
|
1
|
+
export { D as DevToolsEvent, a as DevtoolsOverlayOptions, P as ProfilerResult, R as ReactiveNodeInfo, S as SibuError, c as checkLeaks, b as clearDebugValues, d as clearHMRState, e as clearPerformanceData, f as createDevtoolsOverlay, g as createErrorReporter, h as createHMRBoundary, i as createProfiler, j as debugLog, k as debugValue, l as devState, m as disableDebug, n as enableDebug, o as formatError, p as getActiveDevTools, q as getDebugValues, r as getDependencies, s as getPerformanceReport, t as getSignalName, u as getSubscriberCount, v as hmrState, w as initDevTools, x as inspectSignal, y as isDebugEnabled, z as isHMRAvailable, A as measureRender, B as perfTracker, C as registerHMR, E as runCleanups, F as startMeasure, G as trackCleanup, H as walkDependencyGraph, I as withErrorTracking } from './introspect-CZrlcaYy.js';
|
|
2
|
+
import './signal-BnWpq6WB.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
declare function debugLog(component: string, action: string, data?: unknown): void;
|
|
19
|
-
/**
|
|
20
|
-
* perfTracker tracks render timing for a component.
|
|
21
|
-
*/
|
|
22
|
-
declare function perfTracker(label: string): {
|
|
23
|
-
startMeasure: () => void;
|
|
24
|
-
endMeasure: () => number;
|
|
25
|
-
getAverageTime: () => number;
|
|
26
|
-
getRenderCount: () => number;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* measureRender wraps a component and measures its render time.
|
|
30
|
-
*/
|
|
31
|
-
declare function measureRender<P>(label: string, component: (props: P) => HTMLElement): (props: P) => HTMLElement;
|
|
32
|
-
/**
|
|
33
|
-
* Get all collected performance data.
|
|
34
|
-
*/
|
|
35
|
-
declare function getPerformanceReport(): Record<string, {
|
|
36
|
-
count: number;
|
|
37
|
-
average: number;
|
|
38
|
-
min: number;
|
|
39
|
-
max: number;
|
|
40
|
-
total: number;
|
|
41
|
-
}>;
|
|
42
|
-
/**
|
|
43
|
-
* Clear all performance data.
|
|
44
|
-
*/
|
|
45
|
-
declare function clearPerformanceData(): void;
|
|
46
|
-
declare function trackCleanup(component: string, cleanup: () => void): void;
|
|
47
|
-
declare function runCleanups(component: string): void;
|
|
48
|
-
declare function checkLeaks(): Record<string, number>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Sibu DevTools Bridge
|
|
52
|
-
*
|
|
53
|
-
* Architecture (React DevTools style):
|
|
54
|
-
*
|
|
55
|
-
* Sibu App Chrome Extension
|
|
56
|
-
* ┌──────────┐ ┌──────────────┐
|
|
57
|
-
* │ signal │──emit──▶│ │ Content │
|
|
58
|
-
* │ derived │ │ │ Script │
|
|
59
|
-
* │ effect │ ▼ │ │ │
|
|
60
|
-
* │ mount │ __SIBU_ │ ▼ │
|
|
61
|
-
* └──────────┘ DEVTOOLS_ │ Background │
|
|
62
|
-
* GLOBAL_ │ │ │
|
|
63
|
-
* HOOK__ │ ▼ │
|
|
64
|
-
* │ │ DevTools │
|
|
65
|
-
* │ │ Panel │
|
|
66
|
-
* ▼ └──────────────┘
|
|
67
|
-
* Bridge
|
|
68
|
-
* (postMessage)
|
|
69
|
-
*
|
|
70
|
-
* The hook is injected by the content script BEFORE the app loads.
|
|
71
|
-
* When initDevTools() is called, the bridge connects to the existing hook
|
|
72
|
-
* or creates one. Events are buffered until the panel connects.
|
|
73
|
-
*/
|
|
74
|
-
type DevToolsEvent = {
|
|
75
|
-
type: "state-change";
|
|
76
|
-
component: string;
|
|
77
|
-
key: string;
|
|
78
|
-
oldValue: unknown;
|
|
79
|
-
newValue: unknown;
|
|
80
|
-
timestamp: number;
|
|
81
|
-
} | {
|
|
82
|
-
type: "mount";
|
|
83
|
-
component: string;
|
|
84
|
-
element: HTMLElement;
|
|
85
|
-
timestamp: number;
|
|
86
|
-
} | {
|
|
87
|
-
type: "unmount";
|
|
88
|
-
component: string;
|
|
89
|
-
timestamp: number;
|
|
90
|
-
} | {
|
|
91
|
-
type: "render";
|
|
92
|
-
component: string;
|
|
93
|
-
duration: number;
|
|
94
|
-
timestamp: number;
|
|
95
|
-
} | {
|
|
96
|
-
type: "error";
|
|
97
|
-
component: string;
|
|
98
|
-
error: Error;
|
|
99
|
-
timestamp: number;
|
|
100
|
-
};
|
|
101
|
-
interface DevToolsConfig {
|
|
102
|
-
maxEvents?: number;
|
|
103
|
-
enabled?: boolean;
|
|
104
|
-
maxSignals?: number;
|
|
4
|
+
interface SignalNodeSnapshot {
|
|
5
|
+
/** Stable id for the node (assigned on first observation). */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Debug name, if the caller tagged the signal. */
|
|
8
|
+
name: string | null;
|
|
9
|
+
/** Runtime type tag: `"signal"`, `"derived"`, `"effect"`. */
|
|
10
|
+
kind: string;
|
|
11
|
+
/** Best-effort preview of the current value. */
|
|
12
|
+
value: string;
|
|
13
|
+
/** Ids of nodes that depend on this one. */
|
|
14
|
+
subscribers: string[];
|
|
15
|
+
/** Ids of nodes this one reads from. */
|
|
16
|
+
dependencies: string[];
|
|
17
|
+
/** Number of times the node has been re-evaluated since creation. */
|
|
18
|
+
evalCount: number;
|
|
105
19
|
}
|
|
106
|
-
interface
|
|
107
|
-
|
|
108
|
-
|
|
20
|
+
interface SignalGraphSnapshot {
|
|
21
|
+
capturedAt: number;
|
|
22
|
+
nodes: SignalNodeSnapshot[];
|
|
23
|
+
/** Total edge count for quick health checks. */
|
|
24
|
+
edgeCount: number;
|
|
109
25
|
}
|
|
110
|
-
declare function getActiveDevTools(): ReturnType<typeof initDevTools> | null;
|
|
111
|
-
/**
|
|
112
|
-
* Initialize Sibu DevTools.
|
|
113
|
-
* Connects to __SIBU_DEVTOOLS_GLOBAL_HOOK__ and starts tracking signals,
|
|
114
|
-
* computed values, effects, and components.
|
|
115
|
-
*/
|
|
116
|
-
declare function initDevTools(config?: DevToolsConfig): {
|
|
117
|
-
record: (event: DevToolsEvent) => void;
|
|
118
|
-
getEvents: (filter?: {
|
|
119
|
-
type?: string;
|
|
120
|
-
component?: string;
|
|
121
|
-
}) => DevToolsEvent[];
|
|
122
|
-
clearEvents: () => void;
|
|
123
|
-
registerComponent: (name: string, element: HTMLElement, state?: Record<string, unknown>) => void;
|
|
124
|
-
unregisterComponent: (name: string) => void;
|
|
125
|
-
getComponents: () => Map<string, ComponentEntry>;
|
|
126
|
-
getSignals: () => Array<{
|
|
127
|
-
id: number;
|
|
128
|
-
name: string;
|
|
129
|
-
type: string;
|
|
130
|
-
value: unknown;
|
|
131
|
-
subscriberCount: number;
|
|
132
|
-
}>;
|
|
133
|
-
isEnabled: () => boolean;
|
|
134
|
-
setEnabled: (v: boolean) => void;
|
|
135
|
-
snapshot: () => Record<string, unknown>;
|
|
136
|
-
highlightElement: (name: string) => void;
|
|
137
|
-
destroy: () => void;
|
|
138
|
-
};
|
|
139
|
-
declare function devState<T>(name: string, initial: T): [() => T, (value: T | ((prev: T) => T)) => void];
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Hot Module Replacement utilities for SibuJS.
|
|
143
|
-
* Preserves component state during development reloads.
|
|
144
|
-
*
|
|
145
|
-
* During development the HMR runtime keeps a global store of component state
|
|
146
|
-
* keyed by a developer-supplied ID. When a module is hot-reloaded the new
|
|
147
|
-
* component implementation can re-use the preserved state so that the user
|
|
148
|
-
* does not lose context (form values, scroll position, etc.).
|
|
149
|
-
*
|
|
150
|
-
* The utilities integrate with bundlers that expose a `module.hot` or
|
|
151
|
-
* `import.meta.hot` API (Webpack, Vite, Parcel, etc.).
|
|
152
|
-
*/
|
|
153
|
-
/**
|
|
154
|
-
* Create an HMR-aware state that persists across module reloads.
|
|
155
|
-
* During development, state is stored in a global map keyed by a unique `id`.
|
|
156
|
-
* On the first load the `initial` value is used; on subsequent hot reloads
|
|
157
|
-
* the previously stored value is restored.
|
|
158
|
-
*
|
|
159
|
-
* @param id Unique identifier for this state (should be stable across reloads)
|
|
160
|
-
* @param initial Initial value used on the very first load
|
|
161
|
-
* @returns A `[getter, setter]` tuple compatible with `signal`
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```ts
|
|
165
|
-
* const [count, setCount] = hmrState("MyCounter.count", 0);
|
|
166
|
-
* // After a hot reload, `count()` will still return the last known value.
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
declare function hmrState<T>(id: string, initial: T): [() => T, (value: T | ((prev: T) => T)) => void];
|
|
170
|
-
/**
|
|
171
|
-
* Register a component for HMR updates.
|
|
172
|
-
* When the module is hot-reloaded the component is re-rendered with preserved
|
|
173
|
-
* state by swapping out the old DOM element for the new one produced by the
|
|
174
|
-
* updated component function.
|
|
175
|
-
*
|
|
176
|
-
* @param id Stable identifier for the component
|
|
177
|
-
* @param component Factory function that returns the component's root element
|
|
178
|
-
* @param container Optional container element – if provided the initial element
|
|
179
|
-
* is automatically appended to it
|
|
180
|
-
* @returns An object with `update` (swap implementation) and `dispose` (clean up)
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```ts
|
|
184
|
-
* const hmr = registerHMR("MyWidget", () => MyWidget());
|
|
185
|
-
*
|
|
186
|
-
* // On hot update:
|
|
187
|
-
* hmr.update(() => MyWidgetV2());
|
|
188
|
-
*
|
|
189
|
-
* // On full teardown:
|
|
190
|
-
* hmr.dispose();
|
|
191
|
-
* ```
|
|
192
|
-
*/
|
|
193
|
-
declare function registerHMR(id: string, component: () => HTMLElement, container?: HTMLElement): {
|
|
194
|
-
/** Update the component implementation (called on hot reload) */
|
|
195
|
-
update: (newComponent: () => HTMLElement) => void;
|
|
196
|
-
/** Dispose the HMR registration */
|
|
197
|
-
dispose: () => void;
|
|
198
|
-
};
|
|
199
|
-
/**
|
|
200
|
-
* Create an HMR boundary.
|
|
201
|
-
* Components within the boundary are hot-reloaded independently. The boundary
|
|
202
|
-
* keeps track of accept/dispose callbacks and can wrap a component factory so
|
|
203
|
-
* that hot updates are handled transparently.
|
|
204
|
-
*
|
|
205
|
-
* @param id Stable boundary identifier
|
|
206
|
-
* @returns Boundary helpers: `wrap`, `accept`, `dispose`
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* const boundary = createHMRBoundary("settings-panel");
|
|
211
|
-
*
|
|
212
|
-
* const el = boundary.wrap(() => SettingsPanel());
|
|
213
|
-
* document.body.appendChild(el);
|
|
214
|
-
*
|
|
215
|
-
* boundary.accept(() => console.log("Hot update accepted"));
|
|
216
|
-
* boundary.dispose(() => console.log("Cleaning up old version"));
|
|
217
|
-
* ```
|
|
218
|
-
*/
|
|
219
|
-
declare function createHMRBoundary(id: string): {
|
|
220
|
-
/** Wrap a component for HMR support */
|
|
221
|
-
wrap: (component: () => HTMLElement) => HTMLElement;
|
|
222
|
-
/** Accept a hot update */
|
|
223
|
-
accept: (callback?: () => void) => void;
|
|
224
|
-
/** Dispose callback */
|
|
225
|
-
dispose: (callback: () => void) => void;
|
|
226
|
-
};
|
|
227
|
-
/**
|
|
228
|
-
* Clear all HMR state (useful for a full page refresh or test teardown).
|
|
229
|
-
*/
|
|
230
|
-
declare function clearHMRState(): void;
|
|
231
|
-
/**
|
|
232
|
-
* Check if HMR is available in the current environment.
|
|
233
|
-
* Returns `true` when any of the common bundler HMR APIs are detected
|
|
234
|
-
* (`module.hot` for Webpack, `import.meta.hot` for Vite, or the SibuJS
|
|
235
|
-
* custom hook).
|
|
236
|
-
*/
|
|
237
|
-
declare function isHMRAvailable(): boolean;
|
|
238
|
-
|
|
239
26
|
/**
|
|
240
|
-
*
|
|
241
|
-
*
|
|
27
|
+
* Capture a synchronous snapshot of the reactive graph. The hook
|
|
28
|
+
* provides a `getSignalNodes()` iterator that the core reactivity
|
|
29
|
+
* layer populates; this function walks it and produces a serializable
|
|
30
|
+
* view with dependency counts.
|
|
242
31
|
*
|
|
243
|
-
*
|
|
244
|
-
* errors with SibuJS-specific component context so that developers can quickly
|
|
245
|
-
* identify *which* component failed and *what* props were in play, regardless
|
|
246
|
-
* of whether source maps are available in the browser.
|
|
32
|
+
* Returns an empty snapshot when devtools are not enabled.
|
|
247
33
|
*/
|
|
34
|
+
declare function captureSignalGraph(): SignalGraphSnapshot;
|
|
248
35
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
* also forwarded so that the original error is preserved.
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* ```ts
|
|
257
|
-
* throw new SibuError("Render failed", {
|
|
258
|
-
* component: "UserCard",
|
|
259
|
-
* props: { userId: 42 },
|
|
260
|
-
* cause: originalError,
|
|
261
|
-
* });
|
|
262
|
-
* ```
|
|
263
|
-
*/
|
|
264
|
-
declare class SibuError extends Error {
|
|
265
|
-
component?: string;
|
|
266
|
-
props?: Record<string, unknown>;
|
|
267
|
-
constructor(message: string, options?: {
|
|
268
|
-
component?: string;
|
|
269
|
-
props?: Record<string, unknown>;
|
|
270
|
-
cause?: Error;
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Create a component error reporter that captures stack traces and maps them
|
|
275
|
-
* to component context.
|
|
276
|
-
*
|
|
277
|
-
* The reporter collects errors into an internal list, optionally logs them
|
|
278
|
-
* to the console, and forwards them to a user-supplied `onError` handler.
|
|
279
|
-
*
|
|
280
|
-
* @param options Configuration options
|
|
281
|
-
* @returns Reporter API
|
|
282
|
-
*
|
|
283
|
-
* @example
|
|
284
|
-
* ```ts
|
|
285
|
-
* const reporter = createErrorReporter({
|
|
286
|
-
* onError: (err) => analytics.track("component_error", err),
|
|
287
|
-
* logToConsole: true,
|
|
288
|
-
* maxErrors: 200,
|
|
289
|
-
* });
|
|
290
|
-
*
|
|
291
|
-
* reporter.report(new Error("oops"), { component: "Dashboard" });
|
|
292
|
-
* console.log(reporter.getErrors());
|
|
293
|
-
* ```
|
|
36
|
+
* Diff two snapshots and return a high-level summary: how many new
|
|
37
|
+
* nodes, how many removed, and which nodes re-evaluated between
|
|
38
|
+
* captures. Useful for regression tests that want to assert
|
|
39
|
+
* "navigating to /page X creates exactly N new signals".
|
|
294
40
|
*/
|
|
295
|
-
declare function
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
logToConsole?: boolean;
|
|
300
|
-
/** Max errors to retain */
|
|
301
|
-
maxErrors?: number;
|
|
302
|
-
}): {
|
|
303
|
-
/** Report an error with component context */
|
|
304
|
-
report: (error: Error, context?: {
|
|
305
|
-
component?: string;
|
|
306
|
-
props?: Record<string, unknown>;
|
|
307
|
-
}) => void;
|
|
308
|
-
/** Get all reported errors */
|
|
309
|
-
getErrors: () => SibuError[];
|
|
310
|
-
/** Clear error history */
|
|
311
|
-
clear: () => void;
|
|
312
|
-
/** Get error count by component */
|
|
313
|
-
getErrorsByComponent: () => Map<string, SibuError[]>;
|
|
41
|
+
declare function diffSignalGraphs(before: SignalGraphSnapshot, after: SignalGraphSnapshot): {
|
|
42
|
+
added: SignalNodeSnapshot[];
|
|
43
|
+
removed: SignalNodeSnapshot[];
|
|
44
|
+
reevaluated: SignalNodeSnapshot[];
|
|
314
45
|
};
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
* ```
|
|
331
|
-
*/
|
|
332
|
-
declare function withErrorTracking(name: string, component: () => HTMLElement, reporter?: ReturnType<typeof createErrorReporter>): () => HTMLElement;
|
|
333
|
-
/**
|
|
334
|
-
* Format an error with enhanced stack trace information.
|
|
335
|
-
* Adds component context markers to stack traces so that the developer can
|
|
336
|
-
* immediately see which SibuJS component is involved.
|
|
337
|
-
*
|
|
338
|
-
* @param error The error to format
|
|
339
|
-
* @param context Optional context to include in the formatted output
|
|
340
|
-
* @returns A formatted multi-line string suitable for `console.error`
|
|
341
|
-
*
|
|
342
|
-
* @example
|
|
343
|
-
* ```ts
|
|
344
|
-
* try {
|
|
345
|
-
* render();
|
|
346
|
-
* } catch (e) {
|
|
347
|
-
* console.error(formatError(e, { component: "App" }));
|
|
348
|
-
* }
|
|
349
|
-
* ```
|
|
350
|
-
*/
|
|
351
|
-
declare function formatError(error: Error, context?: {
|
|
352
|
-
component?: string;
|
|
353
|
-
}): string;
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Registers a reactive value for DevTools inspection.
|
|
357
|
-
* Uses an effect internally to track changes — the formatter is called
|
|
358
|
-
* on every update, and the latest snapshot is stored for DevTools.
|
|
359
|
-
*
|
|
360
|
-
* @param value Reactive getter (e.g., a signal)
|
|
361
|
-
* @param formatter Optional function to convert value to a display label
|
|
362
|
-
* @returns Dispose function to stop tracking
|
|
363
|
-
*/
|
|
364
|
-
declare function debugValue<T>(value: () => T, formatter?: (value: T) => string): () => void;
|
|
365
|
-
/**
|
|
366
|
-
* Returns all currently registered debug values.
|
|
367
|
-
*/
|
|
368
|
-
declare function getDebugValues(): Array<{
|
|
369
|
-
value: unknown;
|
|
370
|
-
label: string;
|
|
371
|
-
}>;
|
|
372
|
-
/**
|
|
373
|
-
* Clears all registered debug values.
|
|
374
|
-
*/
|
|
375
|
-
declare function clearDebugValues(): void;
|
|
376
|
-
|
|
377
|
-
interface ProfilerResult {
|
|
378
|
-
renderCount: () => number;
|
|
379
|
-
lastRenderTime: () => number;
|
|
380
|
-
averageRenderTime: () => number;
|
|
381
|
-
totalRenderTime: () => number;
|
|
382
|
-
reset: () => void;
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Creates a component profiler that tracks render counts and timings.
|
|
386
|
-
* Uses performance.now() for high-resolution timing.
|
|
387
|
-
* All outputs are reactive via signal.
|
|
388
|
-
*/
|
|
389
|
-
declare function createProfiler(_name: string): ProfilerResult;
|
|
390
|
-
/**
|
|
391
|
-
* Starts a render measurement for the given profiler.
|
|
392
|
-
* Returns a stop function that records the elapsed time.
|
|
393
|
-
*/
|
|
394
|
-
declare function startMeasure(profiler: ProfilerResult): () => void;
|
|
395
|
-
|
|
396
|
-
interface DevtoolsOverlayOptions {
|
|
397
|
-
enabled?: boolean;
|
|
398
|
-
position?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
46
|
+
interface ProfilerEvent {
|
|
47
|
+
/** Chrome tracing `name` field — effect/signal label. */
|
|
48
|
+
name: string;
|
|
49
|
+
/** Trace category. */
|
|
50
|
+
cat: string;
|
|
51
|
+
/** `"B"` = begin, `"E"` = end, `"I"` = instant. */
|
|
52
|
+
ph: "B" | "E" | "I";
|
|
53
|
+
/** Timestamp in microseconds since the profiler started. */
|
|
54
|
+
ts: number;
|
|
55
|
+
/** Fixed thread ID — sibujs has one reactive thread. */
|
|
56
|
+
tid: 0;
|
|
57
|
+
/** Fixed process ID. */
|
|
58
|
+
pid: 0;
|
|
59
|
+
/** Arbitrary metadata. */
|
|
60
|
+
args?: Record<string, unknown>;
|
|
399
61
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
toggle: () => void;
|
|
408
|
-
addPanel: (name: string, render: () => string) => void;
|
|
409
|
-
removePanel: (name: string) => void;
|
|
410
|
-
getPanels: () => Array<{
|
|
411
|
-
name: string;
|
|
412
|
-
render: () => string;
|
|
413
|
-
}>;
|
|
414
|
-
dispose: () => void;
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* DevTools introspection utilities for SibuJS.
|
|
419
|
-
*
|
|
420
|
-
* These functions allow dev tools to inspect the reactive dependency graph
|
|
421
|
-
* at runtime. They are designed to be zero-cost when not used — no overhead
|
|
422
|
-
* is added to the hot path. Information is read from tags already placed
|
|
423
|
-
* on signals/getters by signal, derived, etc.
|
|
424
|
-
*/
|
|
425
|
-
|
|
426
|
-
/** Info about a reactive node in the dependency graph */
|
|
427
|
-
interface ReactiveNodeInfo {
|
|
428
|
-
/** Debug name if provided (e.g., signal(0, { name: "count" })) */
|
|
429
|
-
name: string | undefined;
|
|
430
|
-
/** Internal signal reference */
|
|
431
|
-
signal: ReactiveSignal;
|
|
432
|
-
/** Number of subscribers */
|
|
433
|
-
subscriberCount: number;
|
|
62
|
+
interface TraceProfilerHandle {
|
|
63
|
+
/** Stop the profiler and return the collected events. */
|
|
64
|
+
stop: () => ProfilerEvent[];
|
|
65
|
+
/** Stop and return a Chrome tracing JSON blob ready for download. */
|
|
66
|
+
stopTrace: () => string;
|
|
67
|
+
/** Whether the profiler is currently recording. */
|
|
68
|
+
isRecording: () => boolean;
|
|
434
69
|
}
|
|
435
70
|
/**
|
|
436
|
-
*
|
|
437
|
-
*
|
|
71
|
+
* Start recording reactive effect timings. Returns a handle whose
|
|
72
|
+
* `stop()` method yields a list of Chrome tracing events — drop the
|
|
73
|
+
* JSON into `chrome://tracing` or `ui.perfetto.dev` to see the
|
|
74
|
+
* flamegraph.
|
|
438
75
|
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
* getSignalName(count); // "count"
|
|
442
|
-
*/
|
|
443
|
-
declare function getSignalName(getter: () => unknown): string | undefined;
|
|
444
|
-
/**
|
|
445
|
-
* Get the number of active subscribers for a signal getter.
|
|
446
|
-
*
|
|
447
|
-
* @example
|
|
448
|
-
* const [count] = signal(0);
|
|
449
|
-
* effect(() => count()); // +1 subscriber
|
|
450
|
-
* getSubscriberCount(count); // 1
|
|
451
|
-
*/
|
|
452
|
-
declare function getSubscriberCount(getter: () => unknown): number;
|
|
453
|
-
/**
|
|
454
|
-
* Get the dependency list of an effect or computed subscriber function.
|
|
455
|
-
* Returns signal references that the subscriber depends on.
|
|
76
|
+
* In production this is a no-op; the handle still returns an empty
|
|
77
|
+
* list so callers do not have to branch on `isDev()` themselves.
|
|
456
78
|
*
|
|
457
|
-
*
|
|
79
|
+
* Named `createTraceProfiler` to avoid colliding with the per-component
|
|
80
|
+
* render profiler in `componentProfiler.ts`, which tracks render counts
|
|
81
|
+
* rather than producing a trace file.
|
|
458
82
|
*/
|
|
459
|
-
declare function
|
|
460
|
-
/**
|
|
461
|
-
* Inspect a signal getter — returns name, signal ref, and subscriber count.
|
|
462
|
-
*/
|
|
463
|
-
declare function inspectSignal(getter: () => unknown): ReactiveNodeInfo | null;
|
|
464
|
-
/**
|
|
465
|
-
* Walk the full reactive graph starting from a signal getter.
|
|
466
|
-
* Returns a tree of signal → subscribers → their signals → etc.
|
|
467
|
-
* Useful for devtools visualization.
|
|
468
|
-
*
|
|
469
|
-
* Set maxDepth to limit traversal (default: 10).
|
|
470
|
-
*/
|
|
471
|
-
declare function walkDependencyGraph(getter: () => unknown, maxDepth?: number): {
|
|
472
|
-
name: string | undefined;
|
|
473
|
-
subscribers: number;
|
|
474
|
-
downstream: ReturnType<typeof walkDependencyGraph>[];
|
|
475
|
-
};
|
|
83
|
+
declare function createTraceProfiler(): TraceProfilerHandle;
|
|
476
84
|
|
|
477
|
-
export { type
|
|
85
|
+
export { type ProfilerEvent, type SignalGraphSnapshot, type SignalNodeSnapshot, type TraceProfilerHandle, captureSignalGraph, createTraceProfiler, diffSignalGraphs };
|