sibujs 1.2.0 → 1.3.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.
Files changed (89) hide show
  1. package/README.md +29 -25
  2. package/dist/browser.cjs +804 -2
  3. package/dist/browser.d.cts +591 -1
  4. package/dist/browser.d.ts +591 -1
  5. package/dist/browser.js +50 -8
  6. package/dist/build.cjs +654 -144
  7. package/dist/build.js +14 -12
  8. package/dist/cdn.global.js +188 -7
  9. package/dist/chunk-2BYQDGN3.js +742 -0
  10. package/dist/chunk-32DY64NT.js +282 -0
  11. package/dist/chunk-3AIRKM3B.js +1263 -0
  12. package/dist/chunk-3X2YG6YM.js +505 -0
  13. package/dist/chunk-5X6PP2UK.js +28 -0
  14. package/dist/chunk-77L6NL3X.js +1097 -0
  15. package/dist/chunk-BGN5ZMP4.js +26 -0
  16. package/dist/chunk-BTU3TJDS.js +365 -0
  17. package/dist/chunk-CHF5OHIA.js +61 -0
  18. package/dist/chunk-CMBFNA7L.js +27 -0
  19. package/dist/chunk-DAHRH4ON.js +331 -0
  20. package/dist/chunk-EBGIRKQY.js +616 -0
  21. package/dist/chunk-EUZND3CB.js +27 -0
  22. package/dist/chunk-F3FA4F32.js +292 -0
  23. package/dist/chunk-JAKHTMQU.js +1000 -0
  24. package/dist/chunk-JCI5M6U6.js +956 -0
  25. package/dist/chunk-KQPDEVVS.js +398 -0
  26. package/dist/chunk-NEKUBFPT.js +60 -0
  27. package/dist/chunk-NYVAC6P5.js +37 -0
  28. package/dist/chunk-PTQJDMRT.js +146 -0
  29. package/dist/chunk-QWZG56ET.js +2744 -0
  30. package/dist/chunk-TSOKIX5Z.js +654 -0
  31. package/dist/chunk-VRW3FULF.js +725 -0
  32. package/dist/chunk-WZSPOOER.js +84 -0
  33. package/dist/chunk-YT6HQ6AM.js +14 -0
  34. package/dist/chunk-ZD6OAMTH.js +277 -0
  35. package/dist/contracts-DDrwxvJ-.d.cts +245 -0
  36. package/dist/contracts-DDrwxvJ-.d.ts +245 -0
  37. package/dist/data.cjs +35 -2
  38. package/dist/data.d.cts +7 -0
  39. package/dist/data.d.ts +7 -0
  40. package/dist/data.js +9 -8
  41. package/dist/devtools.cjs +122 -0
  42. package/dist/devtools.d.cts +69 -461
  43. package/dist/devtools.d.ts +69 -461
  44. package/dist/devtools.js +127 -6
  45. package/dist/ecosystem.cjs +23 -6
  46. package/dist/ecosystem.d.cts +1 -1
  47. package/dist/ecosystem.d.ts +1 -1
  48. package/dist/ecosystem.js +10 -9
  49. package/dist/extras.cjs +1207 -65
  50. package/dist/extras.d.cts +5 -5
  51. package/dist/extras.d.ts +5 -5
  52. package/dist/extras.js +69 -24
  53. package/dist/index.cjs +663 -144
  54. package/dist/index.d.cts +397 -17
  55. package/dist/index.d.ts +397 -17
  56. package/dist/index.js +39 -17
  57. package/dist/introspect-BumjnBKr.d.cts +477 -0
  58. package/dist/introspect-CZrlcaYy.d.ts +477 -0
  59. package/dist/introspect-Cb0zgpi2.d.cts +477 -0
  60. package/dist/introspect-Y2xNXGSf.d.ts +477 -0
  61. package/dist/motion.js +4 -4
  62. package/dist/patterns.cjs +51 -2
  63. package/dist/patterns.d.cts +18 -8
  64. package/dist/patterns.d.ts +18 -8
  65. package/dist/patterns.js +7 -7
  66. package/dist/performance.js +4 -4
  67. package/dist/plugins.cjs +428 -81
  68. package/dist/plugins.d.cts +27 -4
  69. package/dist/plugins.d.ts +27 -4
  70. package/dist/plugins.js +156 -37
  71. package/dist/ssr-4PBXAOO3.js +40 -0
  72. package/dist/ssr-Do_SiVoL.d.cts +201 -0
  73. package/dist/ssr-Do_SiVoL.d.ts +201 -0
  74. package/dist/ssr.cjs +312 -60
  75. package/dist/ssr.d.cts +10 -1
  76. package/dist/ssr.d.ts +10 -1
  77. package/dist/ssr.js +13 -10
  78. package/dist/tagFactory-DaJ0YWX6.d.cts +47 -0
  79. package/dist/tagFactory-DaJ0YWX6.d.ts +47 -0
  80. package/dist/testing.cjs +233 -2
  81. package/dist/testing.d.cts +42 -1
  82. package/dist/testing.d.ts +42 -1
  83. package/dist/testing.js +129 -2
  84. package/dist/ui.cjs +374 -3
  85. package/dist/ui.d.cts +252 -2
  86. package/dist/ui.d.ts +252 -2
  87. package/dist/ui.js +328 -8
  88. package/dist/widgets.js +7 -7
  89. package/package.json +1 -1
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Higher-order component utilities for SibuJS.
3
+ * These functions wrap or compose components to add behavior.
4
+ */
5
+ type Component<P = unknown> = (props: P) => HTMLElement;
6
+ /**
7
+ * Wraps a component with additional behavior that runs before/after rendering.
8
+ *
9
+ * @param WrappedComponent The component to wrap
10
+ * @param wrapper Function that receives the component and its props, returns enhanced element
11
+ * @returns A new component function
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const WithLogging = withWrapper(MyComponent, (Comp, props) => {
16
+ * console.log("Rendering with props:", props);
17
+ * return Comp(props);
18
+ * });
19
+ * ```
20
+ */
21
+ declare function withWrapper<P>(WrappedComponent: Component<P>, wrapper: (component: Component<P>, props: P) => HTMLElement): Component<P>;
22
+ /**
23
+ * Adds default props to a component. Missing props are filled from defaults.
24
+ *
25
+ * @param component The component to wrap
26
+ * @param defaults Default prop values
27
+ * @returns A new component with defaults applied
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const Button = withDefaults(RawButton, { type: "button", disabled: false });
32
+ * Button({ nodes: "Click" }); // type="button", disabled=false automatically
33
+ * ```
34
+ */
35
+ declare function withDefaults<P extends Record<string, unknown>>(component: Component<P>, defaults: Partial<P>): Component<Partial<P>>;
36
+ /**
37
+ * Composes multiple HOC wrappers into a single wrapper.
38
+ * Applied from right to left (like function composition).
39
+ *
40
+ * @param wrappers Array of HOC functions
41
+ * @returns A function that applies all wrappers to a component
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const enhance = compose(withAuth, withLogging, withTheme);
46
+ * const EnhancedPage = enhance(Page);
47
+ * ```
48
+ */
49
+ declare function compose(...wrappers: Array<(component: Component) => Component>): (component: Component) => Component;
50
+
51
+ /**
52
+ * composable wraps a setup function to create reusable stateful logic.
53
+ * Similar to Vue 3 composables — encapsulates reactive state and methods.
54
+ */
55
+ declare function composable<T>(setup: () => T): () => T;
56
+ /**
57
+ * RenderProp implements the render-prop pattern.
58
+ * The render function receives data and returns DOM nodes.
59
+ */
60
+ declare function RenderProp<T>(props: {
61
+ data: () => T;
62
+ render: (data: T) => HTMLElement;
63
+ }): HTMLElement;
64
+ /**
65
+ * withBoundary creates an isolated component boundary for debugging.
66
+ * Wraps component output in a named container with error isolation.
67
+ */
68
+ declare function withBoundary(name: string, component: (props?: unknown) => HTMLElement): (props?: unknown) => HTMLElement;
69
+ /**
70
+ * Slot pattern — provides named slots for component composition.
71
+ */
72
+ declare function createSlots(slots: Record<string, () => HTMLElement | HTMLElement[] | null>): {
73
+ renderSlot: (name: string, fallback?: () => HTMLElement) => HTMLElement | null;
74
+ hasSlot: (name: string) => boolean;
75
+ };
76
+
77
+ /**
78
+ * Functional component props with TypeScript inference for SibuJS.
79
+ *
80
+ * Provides utilities to define typed components with prop defaults,
81
+ * nodes slots, and prop mapping — all with full TypeScript inference.
82
+ */
83
+ /**
84
+ * Extract the props type from a component defined with defineComponent.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const Button = defineComponent<{ label: string }>({
89
+ * setup(props) { ... }
90
+ * });
91
+ * type ButtonProps = ComponentProps<typeof Button>; // { label: string }
92
+ * ```
93
+ */
94
+ type ComponentProps<T> = T extends (props: infer P) => HTMLElement ? P : never;
95
+ /**
96
+ * Props that include an optional nodes slot.
97
+ */
98
+ type WithNodes<Props> = Props & {
99
+ nodes?: Node | Node[];
100
+ };
101
+ /**
102
+ * Define a typed component with props inference, defaults, and a setup function.
103
+ *
104
+ * The `setup` function receives merged props (defaults + provided) and must
105
+ * return an HTMLElement. TypeScript infers the full props type from the generic.
106
+ *
107
+ * @param config Component configuration with optional defaults and a setup function
108
+ * @returns A component function that accepts props and returns an HTMLElement
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * const Button = defineComponent<{ label: string; variant?: 'primary' | 'secondary'; disabled?: boolean }>({
113
+ * defaults: { variant: 'primary', disabled: false },
114
+ * setup(props) {
115
+ * return button({
116
+ * class: `btn btn-${props.variant}`,
117
+ * disabled: props.disabled,
118
+ * nodes: props.label
119
+ * });
120
+ * }
121
+ * });
122
+ *
123
+ * // Usage: Button({ label: 'Click me' }) — TypeScript infers props
124
+ * ```
125
+ */
126
+ declare function defineComponent<Props extends Record<string, unknown>>(config: {
127
+ defaults?: Partial<Props>;
128
+ setup: (props: Props) => HTMLElement;
129
+ }): (props: Props) => HTMLElement;
130
+ /**
131
+ * Create a component with nodes slot support.
132
+ *
133
+ * Nodes are passed as a special `nodes` prop alongside the component's
134
+ * own props. This enables composition patterns where a parent component
135
+ * wraps arbitrary child content.
136
+ *
137
+ * @param config Component configuration with optional defaults and a setup function
138
+ * @returns A component function that accepts props (including nodes) and returns an HTMLElement
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * const Card = defineSlottedComponent<{ title: string }>({
143
+ * setup(props) {
144
+ * const el = div({ class: 'card' });
145
+ * el.appendChild(h2({ nodes: props.title }));
146
+ * if (props.nodes) {
147
+ * const nodes = Array.isArray(props.nodes) ? props.nodes : [props.nodes];
148
+ * nodes.forEach(child => el.appendChild(child));
149
+ * }
150
+ * return el;
151
+ * }
152
+ * });
153
+ *
154
+ * // Usage: Card({ title: 'Hello', nodes: p({ nodes: 'World' }) })
155
+ * ```
156
+ */
157
+ declare function defineSlottedComponent<Props extends Record<string, unknown>>(config: {
158
+ defaults?: Partial<Props>;
159
+ setup: (props: WithNodes<Props>) => HTMLElement;
160
+ }): (props: WithNodes<Props>) => HTMLElement;
161
+ /**
162
+ * Higher-order helper to create a component that maps outer props to inner props.
163
+ *
164
+ * Useful for adapting a generic component to a specific use case by transforming
165
+ * the prop interface without modifying the original component.
166
+ *
167
+ * @param component The inner component to forward mapped props to
168
+ * @param mapProps A function that transforms outer props into inner props
169
+ * @returns A new component that accepts outer props
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * const IconButton = defineComponent<{ icon: string; label: string; size: number }>({
174
+ * setup(props) { ... }
175
+ * });
176
+ *
177
+ * const SmallIconButton = withProps(IconButton, (outer: { icon: string; label: string }) => ({
178
+ * icon: outer.icon,
179
+ * label: outer.label,
180
+ * size: 16
181
+ * }));
182
+ *
183
+ * // Usage: SmallIconButton({ icon: 'star', label: 'Favorite' })
184
+ * ```
185
+ */
186
+ declare function withProps<OuterProps extends Record<string, unknown>, InnerProps extends Record<string, unknown>>(component: (props: InnerProps) => HTMLElement, mapProps: (outer: OuterProps) => InnerProps): (props: OuterProps) => HTMLElement;
187
+
188
+ /**
189
+ * Runtime prop validation and strict typing contracts for SibuJS.
190
+ * Provides runtime type checking for component props in development mode.
191
+ */
192
+ /** Validator function: returns true if valid, or an error message string. */
193
+ type Validator<T = unknown> = (value: T, propName: string) => true | string;
194
+ /** Built-in validators */
195
+ declare const validators: {
196
+ string: Validator;
197
+ number: Validator;
198
+ boolean: Validator;
199
+ function: Validator;
200
+ object: Validator;
201
+ array: Validator;
202
+ required: Validator;
203
+ oneOf: <T>(...values: T[]) => Validator<T>;
204
+ instanceOf: <T>(ctor: new (...args: unknown[]) => T) => Validator<T>;
205
+ arrayOf: (itemValidator: Validator) => Validator<unknown[]>;
206
+ shape: (schema: Record<string, Validator>) => Validator<Record<string, unknown>>;
207
+ optional: (validator: Validator) => Validator;
208
+ range: (min: number, max: number) => Validator<number>;
209
+ pattern: (regex: RegExp) => Validator<string>;
210
+ };
211
+ interface PropDef<T = unknown> {
212
+ type?: Validator<T>;
213
+ required?: boolean;
214
+ default?: T | (() => T);
215
+ validator?: Validator<T>;
216
+ }
217
+ type PropSchema<Props> = {
218
+ [K in keyof Props]: PropDef<Props[K]> | Validator<Props[K]>;
219
+ };
220
+ /**
221
+ * Validate props against a schema. Returns validated props with defaults applied.
222
+ * In production mode (process.env.NODE_ENV === 'production'), validation is skipped
223
+ * and only defaults are applied for performance.
224
+ */
225
+ declare function validateProps<Props extends Record<string, unknown>>(props: Partial<Props>, schema: PropSchema<Props>): Props;
226
+ /**
227
+ * Define a component with runtime prop validation.
228
+ * Validates props in development mode, applies defaults, then calls setup.
229
+ */
230
+ declare function defineStrictComponent<Props extends Record<string, unknown>>(config: {
231
+ name: string;
232
+ props: PropSchema<Props>;
233
+ setup: (props: Props) => HTMLElement;
234
+ }): (props: Partial<Props>) => HTMLElement;
235
+ /**
236
+ * Assert that a value satisfies a contract at runtime.
237
+ * No-op in production builds.
238
+ */
239
+ declare function assertType<T>(value: unknown, validator: Validator<T>, label?: string): asserts value is T;
240
+ /**
241
+ * Create a type guard function from a validator.
242
+ */
243
+ declare function createGuard<T>(validator: Validator<T>): (value: unknown) => value is T;
244
+
245
+ export { type ComponentProps as C, type PropDef as P, RenderProp as R, type Validator as V, type PropSchema as a, assertType as b, composable as c, compose as d, createGuard as e, createSlots as f, defineComponent as g, defineSlottedComponent as h, defineStrictComponent as i, validators as j, withDefaults as k, withProps as l, withWrapper as m, validateProps as v, withBoundary as w };
package/dist/data.cjs CHANGED
@@ -1265,6 +1265,13 @@ async function preloadRoute(route, context2) {
1265
1265
  }
1266
1266
 
1267
1267
  // src/ui/socket.ts
1268
+ function validateWsUrl(raw) {
1269
+ const trimmed = raw.replace(/[\x00-\x20\x7f-\x9f]+/g, "").trim();
1270
+ if (!trimmed) return null;
1271
+ const lower = trimmed.toLowerCase();
1272
+ if (lower.startsWith("ws://") || lower.startsWith("wss://")) return trimmed;
1273
+ return null;
1274
+ }
1268
1275
  function socket(url, options) {
1269
1276
  const autoReconnect = options?.autoReconnect ?? false;
1270
1277
  const reconnectDelay = options?.reconnectDelay ?? 1e3;
@@ -1283,8 +1290,13 @@ function socket(url, options) {
1283
1290
  }
1284
1291
  function connect() {
1285
1292
  if (disposed) return;
1293
+ const safeUrl = validateWsUrl(getUrl());
1294
+ if (safeUrl === null) {
1295
+ setStatus("closed");
1296
+ return;
1297
+ }
1286
1298
  setStatus("connecting");
1287
- ws = new WebSocket(getUrl(), protocols);
1299
+ ws = new WebSocket(safeUrl, protocols);
1288
1300
  ws.onopen = () => {
1289
1301
  setStatus("open");
1290
1302
  reconnectCount = 0;
@@ -1345,7 +1357,23 @@ function socket(url, options) {
1345
1357
  return { data, status, send, close, dispose };
1346
1358
  }
1347
1359
 
1360
+ // src/utils/sanitize.ts
1361
+ function sanitizeUrl(url) {
1362
+ const trimmed = url.replace(/[\x00-\x20\x7f-\x9f]+/g, "").trim();
1363
+ if (!trimmed) return "";
1364
+ const lower = trimmed.toLowerCase();
1365
+ if (lower.startsWith("javascript:") || lower.startsWith("data:") || lower.startsWith("vbscript:") || lower.startsWith("blob:")) {
1366
+ return "";
1367
+ }
1368
+ return trimmed;
1369
+ }
1370
+
1348
1371
  // src/ui/stream.ts
1372
+ function validateSseUrl(raw) {
1373
+ const safe = sanitizeUrl(raw);
1374
+ if (!safe) return null;
1375
+ return safe;
1376
+ }
1349
1377
  function stream(url, options) {
1350
1378
  const autoReconnect = options?.autoReconnect ?? false;
1351
1379
  const [data, setData] = signal(null);
@@ -1356,8 +1384,13 @@ function stream(url, options) {
1356
1384
  let reconnectTimer = null;
1357
1385
  function connect() {
1358
1386
  if (disposed) return;
1387
+ const safeUrl = validateSseUrl(url);
1388
+ if (safeUrl === null) {
1389
+ setStatus("closed");
1390
+ return;
1391
+ }
1359
1392
  setStatus("connecting");
1360
- source = new EventSource(url, {
1393
+ source = new EventSource(safeUrl, {
1361
1394
  withCredentials: options?.withCredentials ?? false
1362
1395
  });
1363
1396
  source.onopen = () => {
package/dist/data.d.cts CHANGED
@@ -400,6 +400,9 @@ declare function preloadRoute(route: LoaderRoute, context: {
400
400
  /**
401
401
  * socket provides a reactive WebSocket connection with auto-reconnect
402
402
  * and optional heartbeat support.
403
+ *
404
+ * Security: the URL is validated against `ws://` / `wss://` only —
405
+ * `javascript:` and similar schemes are refused (status stays `"closed"`).
403
406
  */
404
407
  declare function socket(url: string | (() => string), options?: {
405
408
  protocols?: string | string[];
@@ -421,6 +424,10 @@ declare function socket(url: string | (() => string), options?: {
421
424
  /**
422
425
  * stream provides reactive Server-Sent Events (SSE) integration.
423
426
  * Wraps the EventSource API with reactive state for data, event name, and connection status.
427
+ *
428
+ * Security: the URL is passed through `sanitizeUrl()` — `javascript:`,
429
+ * `data:`, `vbscript:`, and `blob:` URIs are refused and the stream
430
+ * stays in `"closed"` state.
424
431
  */
425
432
  declare function stream(url: string, options?: {
426
433
  withCredentials?: boolean;
package/dist/data.d.ts CHANGED
@@ -400,6 +400,9 @@ declare function preloadRoute(route: LoaderRoute, context: {
400
400
  /**
401
401
  * socket provides a reactive WebSocket connection with auto-reconnect
402
402
  * and optional heartbeat support.
403
+ *
404
+ * Security: the URL is validated against `ws://` / `wss://` only —
405
+ * `javascript:` and similar schemes are refused (status stays `"closed"`).
403
406
  */
404
407
  declare function socket(url: string | (() => string), options?: {
405
408
  protocols?: string | string[];
@@ -421,6 +424,10 @@ declare function socket(url: string | (() => string), options?: {
421
424
  /**
422
425
  * stream provides reactive Server-Sent Events (SSE) integration.
423
426
  * Wraps the EventSource API with reactive state for data, event name, and connection status.
427
+ *
428
+ * Security: the URL is passed through `sanitizeUrl()` — `javascript:`,
429
+ * `data:`, `vbscript:`, and `blob:` URIs are refused and the stream
430
+ * stays in `"closed"` state.
424
431
  */
425
432
  declare function stream(url: string, options?: {
426
433
  withCredentials?: boolean;
package/dist/data.js CHANGED
@@ -19,14 +19,15 @@ import {
19
19
  syncAdapter,
20
20
  throttle,
21
21
  withRetry
22
- } from "./chunk-Z6POF5YC.js";
23
- import "./chunk-WR5D4EGH.js";
24
- import "./chunk-L6JRBDNS.js";
25
- import "./chunk-6SA3QQES.js";
26
- import "./chunk-CHJ27IGK.js";
27
- import "./chunk-V2XTI523.js";
28
- import "./chunk-UNXCEF6S.js";
29
- import "./chunk-MLKGABMK.js";
22
+ } from "./chunk-JAKHTMQU.js";
23
+ import "./chunk-BGN5ZMP4.js";
24
+ import "./chunk-NEKUBFPT.js";
25
+ import "./chunk-CMBFNA7L.js";
26
+ import "./chunk-CHF5OHIA.js";
27
+ import "./chunk-EUZND3CB.js";
28
+ import "./chunk-WZSPOOER.js";
29
+ import "./chunk-ZD6OAMTH.js";
30
+ import "./chunk-5X6PP2UK.js";
30
31
  export {
31
32
  calculateDelay,
32
33
  clearQueryCache,
package/dist/devtools.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var devtools_exports = {};
22
22
  __export(devtools_exports, {
23
23
  SibuError: () => SibuError,
24
+ captureSignalGraph: () => captureSignalGraph,
24
25
  checkLeaks: () => checkLeaks,
25
26
  clearDebugValues: () => clearDebugValues,
26
27
  clearHMRState: () => clearHMRState,
@@ -29,9 +30,11 @@ __export(devtools_exports, {
29
30
  createErrorReporter: () => createErrorReporter,
30
31
  createHMRBoundary: () => createHMRBoundary,
31
32
  createProfiler: () => createProfiler,
33
+ createTraceProfiler: () => createTraceProfiler,
32
34
  debugLog: () => debugLog,
33
35
  debugValue: () => debugValue,
34
36
  devState: () => devState,
37
+ diffSignalGraphs: () => diffSignalGraphs,
35
38
  disableDebug: () => disableDebug,
36
39
  enableDebug: () => enableDebug,
37
40
  formatError: () => formatError,
@@ -1411,9 +1414,126 @@ function walkDependencyGraph(getter, maxDepth = 10) {
1411
1414
  downstream
1412
1415
  };
1413
1416
  }
1417
+
1418
+ // src/devtools/signalGraph.ts
1419
+ function getHook() {
1420
+ if (!isDev()) return null;
1421
+ const g = globalThis;
1422
+ return g.__SIBU_DEVTOOLS_GLOBAL_HOOK__ ?? null;
1423
+ }
1424
+ function captureSignalGraph() {
1425
+ const hook = getHook();
1426
+ if (!hook || typeof hook.getSignalNodes !== "function") {
1427
+ return { capturedAt: Date.now(), nodes: [], edgeCount: 0 };
1428
+ }
1429
+ const nodes = [];
1430
+ let edgeCount = 0;
1431
+ for (const n of hook.getSignalNodes()) {
1432
+ nodes.push({
1433
+ id: n.id,
1434
+ name: n.name,
1435
+ kind: n.kind,
1436
+ value: n.value,
1437
+ subscribers: [...n.subscribers],
1438
+ dependencies: [...n.dependencies],
1439
+ evalCount: n.evalCount
1440
+ });
1441
+ edgeCount += n.dependencies.length;
1442
+ }
1443
+ return { capturedAt: Date.now(), nodes, edgeCount };
1444
+ }
1445
+ function diffSignalGraphs(before, after) {
1446
+ const beforeById = new Map(before.nodes.map((n) => [n.id, n]));
1447
+ const afterById = new Map(after.nodes.map((n) => [n.id, n]));
1448
+ const added = [];
1449
+ const removed = [];
1450
+ const reevaluated = [];
1451
+ for (const [id, node] of afterById) {
1452
+ if (!beforeById.has(id)) {
1453
+ added.push(node);
1454
+ continue;
1455
+ }
1456
+ const prev = beforeById.get(id);
1457
+ if (prev && prev.evalCount !== node.evalCount) reevaluated.push(node);
1458
+ }
1459
+ for (const [id, node] of beforeById) {
1460
+ if (!afterById.has(id)) removed.push(node);
1461
+ }
1462
+ return { added, removed, reevaluated };
1463
+ }
1464
+ function createTraceProfiler() {
1465
+ const events = [];
1466
+ const hook = getHook();
1467
+ if (!hook) {
1468
+ return {
1469
+ stop: () => events,
1470
+ stopTrace: () => JSON.stringify({ traceEvents: events }),
1471
+ isRecording: () => false
1472
+ };
1473
+ }
1474
+ const start = typeof performance !== "undefined" ? performance.now() : Date.now();
1475
+ let recording = true;
1476
+ const onEffectStart = (payload) => {
1477
+ if (!recording) return;
1478
+ const now = (typeof performance !== "undefined" ? performance.now() : Date.now()) - start;
1479
+ const label = payload.name ?? "effect";
1480
+ events.push({
1481
+ name: label,
1482
+ cat: "effect",
1483
+ ph: "B",
1484
+ ts: Math.floor(now * 1e3),
1485
+ tid: 0,
1486
+ pid: 0
1487
+ });
1488
+ };
1489
+ const onEffectEnd = (payload) => {
1490
+ if (!recording) return;
1491
+ const now = (typeof performance !== "undefined" ? performance.now() : Date.now()) - start;
1492
+ const label = payload.name ?? "effect";
1493
+ events.push({
1494
+ name: label,
1495
+ cat: "effect",
1496
+ ph: "E",
1497
+ ts: Math.floor(now * 1e3),
1498
+ tid: 0,
1499
+ pid: 0
1500
+ });
1501
+ };
1502
+ const onSignalSet = (payload) => {
1503
+ if (!recording) return;
1504
+ const now = (typeof performance !== "undefined" ? performance.now() : Date.now()) - start;
1505
+ const label = payload.name ?? "signal";
1506
+ events.push({
1507
+ name: label,
1508
+ cat: "signal",
1509
+ ph: "I",
1510
+ ts: Math.floor(now * 1e3),
1511
+ tid: 0,
1512
+ pid: 0,
1513
+ args: payload.args
1514
+ });
1515
+ };
1516
+ const offStart = hook.on("effect:start", onEffectStart);
1517
+ const offEnd = hook.on("effect:end", onEffectEnd);
1518
+ const offSet = hook.on("signal:set", onSignalSet);
1519
+ function stop() {
1520
+ if (!recording) return events;
1521
+ recording = false;
1522
+ offStart();
1523
+ offEnd();
1524
+ offSet();
1525
+ return events;
1526
+ }
1527
+ function stopTrace() {
1528
+ stop();
1529
+ return JSON.stringify({ traceEvents: events, displayTimeUnit: "ms" });
1530
+ }
1531
+ return { stop, stopTrace, isRecording: () => recording };
1532
+ }
1414
1533
  // Annotate the CommonJS export names for ESM import in node:
1415
1534
  0 && (module.exports = {
1416
1535
  SibuError,
1536
+ captureSignalGraph,
1417
1537
  checkLeaks,
1418
1538
  clearDebugValues,
1419
1539
  clearHMRState,
@@ -1422,9 +1542,11 @@ function walkDependencyGraph(getter, maxDepth = 10) {
1422
1542
  createErrorReporter,
1423
1543
  createHMRBoundary,
1424
1544
  createProfiler,
1545
+ createTraceProfiler,
1425
1546
  debugLog,
1426
1547
  debugValue,
1427
1548
  devState,
1549
+ diffSignalGraphs,
1428
1550
  disableDebug,
1429
1551
  enableDebug,
1430
1552
  formatError,