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,477 @@
1
+ import { R as ReactiveSignal } from './signal-BnWpq6WB.cjs';
2
+
3
+ /**
4
+ * Enable debug mode — enables verbose logging.
5
+ */
6
+ declare function enableDebug(): void;
7
+ /**
8
+ * Disable debug mode.
9
+ */
10
+ declare function disableDebug(): void;
11
+ /**
12
+ * Check if debug mode is active.
13
+ */
14
+ declare function isDebugEnabled(): boolean;
15
+ /**
16
+ * Log a debug message (only when debug mode is enabled).
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;
105
+ }
106
+ interface ComponentEntry {
107
+ element: HTMLElement;
108
+ state?: Record<string, unknown>;
109
+ }
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
+ /**
240
+ * Source map and debugging utilities for SibuJS.
241
+ * Provides enhanced error reporting with component context and stack traces.
242
+ *
243
+ * These utilities do not parse `.map` files at runtime; instead they enrich
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.
247
+ */
248
+ /**
249
+ * Enhanced error class with component context.
250
+ *
251
+ * Extends the native `Error` to carry the component name and the props that
252
+ * were active when the error was thrown. The `cause` property (ES2022) is
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
+ * ```
294
+ */
295
+ declare function createErrorReporter(options?: {
296
+ /** Custom error handler */
297
+ onError?: (error: SibuError) => void;
298
+ /** Whether to log to console (default `true`) */
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[]>;
314
+ };
315
+ /**
316
+ * Wrap a component factory with error tracking.
317
+ * Catches errors during rendering and reports them via the supplied reporter
318
+ * (or a default one). If the component throws, a fallback `<div>` with the
319
+ * error message is returned so the rest of the page is not broken.
320
+ *
321
+ * @param name Human-readable component name
322
+ * @param component Factory function that returns an `HTMLElement`
323
+ * @param reporter Optional error reporter (a default is created if omitted)
324
+ * @returns A wrapped factory function with identical signature
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * const SafeWidget = withErrorTracking("Widget", () => Widget(), reporter);
329
+ * document.body.appendChild(SafeWidget());
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";
399
+ }
400
+ /**
401
+ * Creates an in-browser devtools overlay manager.
402
+ * Manages panels and visibility state reactively.
403
+ * Does NOT create actual DOM elements — that's the consumer's job.
404
+ */
405
+ declare function createDevtoolsOverlay(options?: DevtoolsOverlayOptions): {
406
+ isEnabled: () => boolean;
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;
434
+ }
435
+ /**
436
+ * Get the debug name of a signal getter function.
437
+ * Returns undefined if no name was provided.
438
+ *
439
+ * @example
440
+ * const [count] = signal(0, { name: "count" });
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.
456
+ *
457
+ * Note: This reads the _deps Set that track.ts maintains on subscriber functions.
458
+ */
459
+ declare function getDependencies(subscriberFn: () => void): ReactiveSignal[];
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
+ };
476
+
477
+ export { measureRender as A, perfTracker as B, registerHMR as C, type DevToolsEvent as D, runCleanups as E, startMeasure as F, trackCleanup as G, walkDependencyGraph as H, withErrorTracking as I, type ProfilerResult as P, type ReactiveNodeInfo as R, SibuError as S, type DevtoolsOverlayOptions as a, clearDebugValues as b, checkLeaks as c, clearHMRState as d, clearPerformanceData as e, createDevtoolsOverlay as f, createErrorReporter as g, createHMRBoundary as h, createProfiler as i, debugLog as j, debugValue as k, devState as l, disableDebug as m, enableDebug as n, formatError as o, getActiveDevTools as p, getDebugValues as q, getDependencies as r, getPerformanceReport as s, getSignalName as t, getSubscriberCount as u, hmrState as v, initDevTools as w, inspectSignal as x, isDebugEnabled as y, isHMRAvailable as z };