@oxog/devinspector 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.
Files changed (77) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +0 -0
  3. package/README.md +85 -28
  4. package/dist/chunk-LNBLBFDA.js +92 -0
  5. package/dist/chunk-LNBLBFDA.js.map +1 -0
  6. package/dist/chunk-VZORB655.js +32 -0
  7. package/dist/chunk-VZORB655.js.map +1 -0
  8. package/dist/console-monitor-AVTNZCED.js +571 -0
  9. package/dist/console-monitor-AVTNZCED.js.map +1 -0
  10. package/dist/devinspector.umd.cjs +6218 -0
  11. package/dist/devinspector.umd.cjs.map +1 -0
  12. package/dist/devinspector.umd.d.cts +4 -0
  13. package/dist/devinspector.umd.js +1794 -1076
  14. package/dist/devinspector.umd.js.map +1 -1
  15. package/dist/devinspector.umd.min.cjs +7 -0
  16. package/dist/devinspector.umd.min.cjs.map +1 -0
  17. package/dist/devinspector.umd.min.js +6 -1
  18. package/dist/devinspector.umd.min.js.map +1 -1
  19. package/dist/dom-monitor-JHJVZYS4.js +19 -0
  20. package/dist/dom-monitor-JHJVZYS4.js.map +1 -0
  21. package/dist/error-monitor-3CRFREH3.js +424 -0
  22. package/dist/error-monitor-3CRFREH3.js.map +1 -0
  23. package/dist/index.cjs +5945 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +582 -0
  26. package/dist/index.d.ts +582 -0
  27. package/dist/index.js +1983 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/inspector-ui-475ZNEHC.js +1241 -0
  30. package/dist/inspector-ui-475ZNEHC.js.map +1 -0
  31. package/dist/network-monitor-WNRL2JI7.js +841 -0
  32. package/dist/network-monitor-WNRL2JI7.js.map +1 -0
  33. package/dist/performance-monitor-UKQFA7ZR.js +544 -0
  34. package/dist/performance-monitor-UKQFA7ZR.js.map +1 -0
  35. package/dist/state-monitor-JGJLBAD7.js +19 -0
  36. package/dist/state-monitor-JGJLBAD7.js.map +1 -0
  37. package/dist/storage-monitor-3NPTWRTY.js +19 -0
  38. package/dist/storage-monitor-3NPTWRTY.js.map +1 -0
  39. package/package.json +78 -38
  40. package/dist/devinspector.cjs.js +0 -5494
  41. package/dist/devinspector.cjs.js.map +0 -1
  42. package/dist/devinspector.esm.js +0 -5482
  43. package/dist/devinspector.esm.js.map +0 -1
  44. package/dist/types/clean-inspector.d.ts +0 -52
  45. package/dist/types/core/event-emitter.d.ts +0 -21
  46. package/dist/types/core/inspector.d.ts +0 -121
  47. package/dist/types/core/plugin-system.d.ts +0 -60
  48. package/dist/types/core/storage.d.ts +0 -52
  49. package/dist/types/core/utils.d.ts +0 -34
  50. package/dist/types/enhanced-inspector.d.ts +0 -56
  51. package/dist/types/enhanced-simple.d.ts +0 -46
  52. package/dist/types/index-simple.d.ts +0 -11
  53. package/dist/types/index.d.ts +0 -19
  54. package/dist/types/monitors/console/console-interceptor.d.ts +0 -36
  55. package/dist/types/monitors/console/console-monitor.d.ts +0 -26
  56. package/dist/types/monitors/console/log-formatter.d.ts +0 -8
  57. package/dist/types/monitors/dom/dom-monitor.d.ts +0 -8
  58. package/dist/types/monitors/error/error-monitor.d.ts +0 -28
  59. package/dist/types/monitors/error/error-tracker.d.ts +0 -55
  60. package/dist/types/monitors/error/source-map-support.d.ts +0 -15
  61. package/dist/types/monitors/network/fetch-interceptor.d.ts +0 -45
  62. package/dist/types/monitors/network/network-monitor.d.ts +0 -47
  63. package/dist/types/monitors/network/websocket-monitor.d.ts +0 -44
  64. package/dist/types/monitors/network/xhr-interceptor.d.ts +0 -25
  65. package/dist/types/monitors/performance/fps-monitor.d.ts +0 -24
  66. package/dist/types/monitors/performance/long-task-detector.d.ts +0 -25
  67. package/dist/types/monitors/performance/memory-monitor.d.ts +0 -30
  68. package/dist/types/monitors/performance/metrics-collector.d.ts +0 -45
  69. package/dist/types/monitors/performance/performance-monitor.d.ts +0 -34
  70. package/dist/types/monitors/state/state-monitor.d.ts +0 -8
  71. package/dist/types/monitors/storage/storage-monitor.d.ts +0 -8
  72. package/dist/types/simple-index.d.ts +0 -3
  73. package/dist/types/simple-inspector.d.ts +0 -24
  74. package/dist/types/ui/components/floating-widget.d.ts +0 -21
  75. package/dist/types/ui/components/main-panel.d.ts +0 -38
  76. package/dist/types/ui/inspector-ui.d.ts +0 -29
  77. package/dist/types/ui/styles.d.ts +0 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,66 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [1.4.0] - 2026-12-02
11
+
12
+ ### Fixed
13
+ - The `./dist/devinspector.umd.js` and `./dist/devinspector.umd.min.js` export subpaths
14
+ were UMD (CommonJS-style) files in a `"type": "module"` package, so Node and
15
+ bundlers loaded them as ES modules with no exports (`require()` threw on Node 18/20).
16
+ They now resolve to CommonJS copies (`dist/devinspector.umd*.cjs`, same code), so
17
+ `import` and `require()` return the `DevInspector` class, typed by the new
18
+ `dist/devinspector.umd.d.cts` (with `typesVersions` for `moduleResolution: "node"`).
19
+ Loaded this way they set `module.exports` instead of the `DevInspector` global.
20
+ The `dist/devinspector.umd*.js` files used by `<script>` tags and CDN URLs are unchanged.
21
+
22
+ ### Changed
23
+ - The CommonJS build (`dist/index.cjs`) now runs in strict mode (`"use strict"`), like the
24
+ ES module and UMD builds already did.
25
+
26
+ ### Internal
27
+ - Tooling: adopted oxog-standard. Lint is ESLint 10 with typescript-eslint
28
+ recommended-type-checked, TypeScript checks are strict; managed CI (Node 18 to 26)
29
+ and Trusted Publishing release workflow; packed-archive checks with publint and
30
+ Are The Types Wrong.
31
+
32
+ ## [1.3.0] - 2026-11-30
33
+
34
+ ### Fixed
35
+ - **Node/bundler resolution**: `main` pointed at a CommonJS file inside a `"type": "module"` package, so `import '@oxog/devinspector'` in Node threw `exports is not defined in ES module scope` and `require()` returned an empty object. The package now ships `dist/index.js` (ESM), `dist/index.cjs` (CommonJS) and separate `.d.ts` / `.d.cts` types behind an `exports` map.
36
+ - **Script-tag / CDN usage**: the UMD global `DevInspector` was a namespace object, so the documented `new DevInspector()` threw `DevInspector is not a constructor` (this also broke the bundled examples). The global is now the class, with every named export available as a static property. `unpkg`/`jsdelivr` fields point at the minified UMD bundle.
37
+ - **Options were ignored**: the default export accepted no configuration. `enabled`, `position`, `theme`, `hotkeys`, `features`, `plugins`, `maxNetworkEntries`, `maxConsoleEntries`, `captureStackTraces`, `networkFilters.hideAssets`, `onError` and `onPerformanceIssue` now work as documented. `enabled: false` previously still patched `fetch`/XHR/console and added the widget.
38
+ - **XSS**: console output, request URLs/methods, error messages and stacks were inserted into the panel as raw HTML, so e.g. `console.log('<img src=x onerror=...>')` or a fetched URL containing markup executed script. All captured values are now escaped (also in the legacy `OriginalDevInspector` UI).
39
+ - **Unbounded memory**: network requests and errors were kept forever. They are now bounded by `maxNetworkEntries` / `maxErrorEntries`, console output by `maxConsoleEntries`, and huge log messages are truncated.
40
+ - **`destroy()` left the page patched**: `window.fetch`, `XMLHttpRequest` and the console methods stayed wrapped, document/window listeners stayed attached, and the `requestAnimationFrame` loop kept running forever. `destroy()` now restores everything (without clobbering wrappers installed later by other code) and is idempotent.
41
+ - **`XMLHttpRequest` replacement**: the constructor was replaced by a plain function, breaking `instanceof XMLHttpRequest` and `XMLHttpRequest.DONE` etc. The prototype methods are wrapped instead.
42
+ - **`fetch(Request)`** was recorded as `GET [object Request]`; method and URL are now read from `Request`/`URL` inputs, and the caller's receiver and arguments are passed through unchanged.
43
+ - **README API missing**: `on`/`once`/`off`, `track`, `markStart`/`markEnd`, `use`, `export`/`import` and `DevInspector.getInstance()` did not exist on the default export; they are implemented now.
44
+ - **Performance**: every captured console message or request re-rendered the whole panel synchronously, even while hidden. Renders are now batched per microtask and skipped while the panel is closed; the FPS loop only runs while the panel is open.
45
+ - **Mounting before `<body>` exists** (script in `<head>`) threw; the widget now mounts on `DOMContentLoaded`. Constructing the inspector during SSR / in Node no longer throws.
46
+ - **Legacy `OriginalDevInspector`**:
47
+ - never initialised in real browsers because the WebSocket monitor assigned the read-only `WebSocket.CONNECTING` constant; `show()` then retried the failing initialisation in an endless microtask loop that froze the page and re-wrapped `fetch` each time.
48
+ - its fetch interceptor awaited the whole response body before resolving `fetch()`, so streaming responses (SSE, long polling) never resolved; bodies are now previewed from a clone in the background, capped at 64 KB.
49
+ - a `console:log` listener that logged caused infinite recursion; `destroy()` during the asynchronous initialisation left monitors installed; each request was stored twice (on request and again on response/error); per-connection bookkeeping and WebSocket messages grew without bound; the panel's document listeners were never removed; `enabled` defaulted to off in browsers without a `process` shim.
50
+ - **`SimpleDevInspector`** used an inline `onclick` handler (blocked by CSP) and never removed its keydown listener.
51
+
52
+ ### Added
53
+ - `getEntries(type)`, `clear(type)`, `toggleRecording()`/`recording`, `isEnabled`, `once()`, `VERSION`, and typed events (`DevInspectorEvents`).
54
+ - Options `maxErrorEntries` (default 100) and `slowRequestThreshold` (default 3000 ms); slow requests emit `performance:issue` and call `onPerformanceIssue`.
55
+ - "Production safety" documentation.
56
+
57
+ ### Changed
58
+ - `enabled` now defaults to `process.env.NODE_ENV !== 'production'` for the default inspector, so production builds no longer show the widget unless `enabled: true` is passed. Without a `NODE_ENV` replacement (CDN bundle) it defaults to on.
59
+ - Importing the package no longer assigns `window.EnhancedDevInspector`; use the `EnhancedDevInspector` export (or `DevInspector.EnhancedDevInspector` from the UMD global).
60
+ - `use()` returns a promise that resolves once the plugin is installed.
61
+ - The panel header shows the real package version (it was hard-coded to 1.1.0).
62
+ - Deep imports are limited by the new `exports` map to `.`, `./package.json` and the two UMD bundles (`./dist/devinspector.umd.js`, `./dist/devinspector.umd.min.js`). The old `dist/devinspector.esm.js` / `dist/devinspector.cjs.js` files are gone.
63
+ - Build moved to tsup (ESM/CJS/types) plus Rollup (UMD); tests to Vitest; lint to ESLint 9.
64
+
65
+ ### Deprecated
66
+ - `OriginalDevInspector` and `SimpleDevInspector`; use the default export.
67
+
8
68
  ## [1.2.0] - 2025-07-01
9
69
 
10
70
  ### Added
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -7,18 +7,17 @@
7
7
  <img src="https://img.shields.io/bundlephobia/minzip/@oxog/devinspector" alt="bundle size" />
8
8
  </p>
9
9
 
10
- A professional developer inspector tool for real-time debugging of web applications. Zero dependencies, framework-agnostic, and production-ready.
10
+ A developer inspector panel for web applications: a floating widget that shows network requests, console output, performance metrics and uncaught errors while you develop. Zero runtime dependencies, framework-agnostic, ESM + CommonJS + `<script>` builds with TypeScript types.
11
11
 
12
12
  ## ✨ Features
13
13
 
14
- - 🌐 **Network Monitoring** - Intercept and analyze all network requests (fetch, XHR, WebSocket)
15
- - 📝 **Console Enhancement** - Enhanced console with search, filtering, and export
16
- - ⚡ **Performance Profiling** - FPS monitoring, memory tracking, and performance metrics
17
- - 🐛 **Error Tracking** - Catch and analyze errors with source maps support
18
- - 🔄 **State Management** - Integrate with Redux, Vuex, MobX, and other state managers
19
- - 🎨 **DOM Analysis** - Inspect DOM mutations and element properties
20
- - 💾 **Storage Inspector** - Monitor localStorage, cookies, and IndexedDB
14
+ - 🌐 **Network Monitoring** - Captures `fetch` and `XMLHttpRequest` calls (method, URL, status, duration) without touching request or response bodies, so streaming responses keep working
15
+ - 📝 **Console Capture** - Mirrors `console.log/info/warn/error/debug` into the panel; the real console still runs and its behaviour is unchanged
16
+ - ⚡ **Performance** - FPS and memory (where the browser exposes it) while the panel is open, plus your own `track()` / `markStart()` / `markEnd()` metrics and slow-request reports
17
+ - 🐛 **Error Tracking** - Uncaught errors and unhandled promise rejections, with stack traces
21
18
  - 🔌 **Plugin System** - Extend functionality with custom plugins
19
+ - 🧹 **Clean teardown** - `destroy()` restores every patched API and removes all listeners, timers and DOM nodes
20
+ - 🔄 **State / DOM / Storage inspection** - accepted in `features` but **not implemented yet**
22
21
 
23
22
  ## 📦 Installation
24
23
 
@@ -62,7 +61,9 @@ const inspector = new DevInspector();
62
61
  ```html
63
62
  <script src="https://unpkg.com/@oxog/devinspector"></script>
64
63
  <script>
65
- const inspector = new DevInspector();
64
+ // The global DevInspector is the class; named exports are static properties
65
+ // (DevInspector.BasePlugin, DevInspector.VERSION, ...).
66
+ const inspector = new DevInspector({ enabled: true });
66
67
  inspector.show();
67
68
  </script>
68
69
  ```
@@ -71,7 +72,8 @@ const inspector = new DevInspector();
71
72
 
72
73
  ```javascript
73
74
  const inspector = new DevInspector({
74
- // Enable/disable the inspector
75
+ // Enable/disable the inspector.
76
+ // Default: process.env.NODE_ENV !== 'production' (see "Production safety")
75
77
  enabled: true,
76
78
 
77
79
  // Position on screen
@@ -86,7 +88,7 @@ const inspector = new DevInspector({
86
88
  minimize: 'ctrl+shift+m'
87
89
  },
88
90
 
89
- // Features to enable
91
+ // Features to enable (state, dom and storage are not implemented yet)
90
92
  features: {
91
93
  network: true,
92
94
  console: true,
@@ -97,25 +99,53 @@ const inspector = new DevInspector({
97
99
  storage: true
98
100
  },
99
101
 
100
- // Storage limits
102
+ // Memory limits: captured data is kept in bounded buffers (newest first)
101
103
  maxNetworkEntries: 1000,
102
104
  maxConsoleEntries: 500,
105
+ maxErrorEntries: 100,
106
+
107
+ // Requests slower than this (ms) are reported to onPerformanceIssue
108
+ slowRequestThreshold: 3000,
103
109
 
104
110
  // Stack traces
105
111
  captureStackTraces: true,
106
112
 
107
- // Network filters
113
+ // Network list filters: hideAssets hides scripts/styles/images/fonts from the list
114
+ // (they are still captured). hideCached is accepted but not implemented.
108
115
  networkFilters: {
109
116
  hideAssets: false,
110
117
  hideCached: false
111
118
  },
112
119
 
113
120
  // Callbacks
114
- onError: (error) => console.error(error),
115
- onPerformanceIssue: (issue) => console.warn(issue)
121
+ onError: (error) => console.error(error), // uncaught errors / unhandled rejections
122
+ onPerformanceIssue: (issue) => console.warn(issue) // e.g. { type: 'slow-network', url, duration }
116
123
  });
117
124
  ```
118
125
 
126
+ ## 🛡️ Production safety
127
+
128
+ DevInspector patches `window.fetch`, `XMLHttpRequest.prototype.open/send` and the
129
+ `console` methods, and adds a widget to the page, so it should not ship to end users:
130
+
131
+ - `enabled` defaults to `process.env.NODE_ENV !== 'production'`. Bundlers that replace
132
+ `process.env.NODE_ENV` (webpack, Vite, esbuild, Rollup) therefore turn it off in
133
+ production builds automatically. Without such replacement (e.g. the CDN bundle) it
134
+ defaults to **on**, so pass `enabled` explicitly there.
135
+ - When disabled, nothing is patched and no DOM is created; every method is a no-op.
136
+ - During SSR / in Node (no `window`/`document`) the inspector is inert and never throws.
137
+ - For the smallest production bundle, load it conditionally:
138
+
139
+ ```javascript
140
+ if (process.env.NODE_ENV !== 'production') {
141
+ const { default: DevInspector } = await import('@oxog/devinspector');
142
+ new DevInspector();
143
+ }
144
+ ```
145
+
146
+ DevInspector has no network component: it does not open ports, start servers or send
147
+ captured data anywhere.
148
+
119
149
  ## 🔧 API
120
150
 
121
151
  ### Core Methods
@@ -127,17 +157,26 @@ inspector.hide();
127
157
  inspector.toggle();
128
158
  inspector.minimize();
129
159
 
130
- // Destroy inspector
160
+ // Destroy inspector: restores fetch/XHR/console, removes listeners and DOM
131
161
  inspector.destroy();
132
162
 
133
163
  // Manual tracking
134
164
  inspector.track('custom-metric', { value: 123 });
135
165
  inspector.markStart('operation');
136
- inspector.markEnd('operation');
166
+ const ms = inspector.markEnd('operation'); // duration in ms
137
167
 
138
- // Export/import data
168
+ // Captured data
169
+ inspector.getEntries('network'); // also 'console' | 'errors' | 'metrics' (copies, newest first)
170
+ inspector.clear('console'); // or 'network' | 'errors' | 'metrics' | 'all'
171
+ inspector.toggleRecording(); // pause/resume capturing
172
+ inspector.isEnabled; // false when disabled, without a DOM, or destroyed
173
+
174
+ // Export/import data (import validates and trims to the configured limits)
139
175
  const data = inspector.export();
140
176
  inspector.import(data);
177
+
178
+ // Most recently created live instance
179
+ DevInspector.getInstance();
141
180
  ```
142
181
 
143
182
  ### Events
@@ -157,6 +196,12 @@ const unsubscribe = inspector.on('console:log', handler);
157
196
  unsubscribe(); // or inspector.off('console:log', handler);
158
197
  ```
159
198
 
199
+ Events: `network:request`, `network:response`, `network:error`, `console:log`,
200
+ `error:uncaught`, `performance:metric`, `performance:mark`, `performance:issue`,
201
+ `inspector:ready`, `inspector:show`, `inspector:hide`, `inspector:minimize`,
202
+ `inspector:destroy` and the `plugin:*` events. Logging from inside a `console:log`
203
+ listener is passed to the real console but not captured again (no recursion).
204
+
160
205
  ## 🔌 Plugins
161
206
 
162
207
  ### Using Plugins
@@ -164,7 +209,7 @@ unsubscribe(); // or inspector.off('console:log', handler);
164
209
  ```javascript
165
210
  import { MyPlugin } from './my-plugin';
166
211
 
167
- inspector.use(new MyPlugin());
212
+ await inspector.use(new MyPlugin()); // resolves once the plugin is installed
168
213
  ```
169
214
 
170
215
  ### Creating Plugins
@@ -244,10 +289,13 @@ export class AppComponent implements OnInit, OnDestroy {
244
289
 
245
290
  ## 🔒 Security
246
291
 
247
- - All inputs are sanitized to prevent XSS
248
- - Sensitive data can be filtered
249
- - Content Security Policy compliant
250
- - No eval() or Function() usage
292
+ - Everything captured (URLs, console output, error messages, stacks, imported data) is
293
+ HTML-escaped before it is rendered, so page data cannot inject markup into the panel.
294
+ - The default inspector uses no `eval()`/`new Function()` and no inline event handlers.
295
+ - Captured data stays in memory in the page; nothing is sent anywhere. Request/response
296
+ bodies are not captured by the default inspector.
297
+ - The deprecated `OriginalDevInspector` console monitor has an `executeCommand()` that
298
+ evaluates code with `new Function` (not CSP-compliant); do not expose it to untrusted input.
251
299
 
252
300
  ## 🌐 Browser Support
253
301
 
@@ -258,14 +306,23 @@ export class AppComponent implements OnInit, OnDestroy {
258
306
 
259
307
  ## 📈 Performance
260
308
 
261
- - < 1ms overhead for interceptors
262
- - < 16KB initial bundle (gzipped)
263
- - Lazy loading for UI components
264
- - Automatic memory management
309
+ - ESM entry ≈16 KB gzipped (the legacy inspector's monitors are split into lazily loaded
310
+ chunks); the UMD bundle is ≈28 KB gzipped
311
+ - Captured data lives in bounded buffers (see the `max*Entries` options)
312
+ - The panel re-renders at most once per burst of events, and only while it is visible
313
+ - The FPS loop runs only while the panel is open
314
+
315
+ ## 🧓 Legacy exports
316
+
317
+ `OriginalDevInspector` (the earlier, asynchronously initialised inspector) and
318
+ `SimpleDevInspector` (a static demo panel without monitoring) are still exported for
319
+ backwards compatibility but are deprecated. [docs/API.md](docs/API.md) describes the
320
+ `OriginalDevInspector` event and storage API.
265
321
 
266
322
  ## 🤝 Contributing
267
323
 
268
- Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
324
+ Contributions are welcome! Please open an issue or pull request on GitHub. Before
325
+ submitting, run `npm run check` (lint, typecheck, tests with coverage).
269
326
 
270
327
  ## 📄 License
271
328
 
@@ -0,0 +1,92 @@
1
+ // src/core/utils.ts
2
+ function throttle(func, wait, options = {}) {
3
+ let timeout = null;
4
+ let lastCallTime = 0;
5
+ let lastThis;
6
+ let lastArgs = null;
7
+ let result;
8
+ const { leading = true, trailing = true } = options;
9
+ const invokeFunc = () => {
10
+ const args = lastArgs;
11
+ const thisArg = lastThis;
12
+ lastArgs = lastThis = null;
13
+ result = func.apply(thisArg, args);
14
+ return result;
15
+ };
16
+ return function throttled(...args) {
17
+ const now = Date.now();
18
+ const remaining = wait - (now - lastCallTime);
19
+ lastThis = this;
20
+ lastArgs = args;
21
+ if (remaining <= 0 || remaining > wait) {
22
+ if (timeout) {
23
+ clearTimeout(timeout);
24
+ timeout = null;
25
+ }
26
+ lastCallTime = now;
27
+ if (leading) {
28
+ result = invokeFunc();
29
+ }
30
+ } else if (!timeout && trailing) {
31
+ timeout = setTimeout(() => {
32
+ lastCallTime = Date.now();
33
+ timeout = null;
34
+ if (trailing && lastArgs) {
35
+ invokeFunc();
36
+ }
37
+ }, remaining);
38
+ }
39
+ return result;
40
+ };
41
+ }
42
+ function generateId() {
43
+ return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
44
+ }
45
+ function safeStringify(obj, indent) {
46
+ const seen = /* @__PURE__ */ new WeakSet();
47
+ return JSON.stringify(obj, (key, value) => {
48
+ if (typeof value === "object" && value !== null) {
49
+ if (seen.has(value)) {
50
+ return "[Circular]";
51
+ }
52
+ seen.add(value);
53
+ }
54
+ if (typeof value === "function") {
55
+ return value.toString();
56
+ }
57
+ if (value instanceof Error) {
58
+ return {
59
+ name: value.name,
60
+ message: value.message,
61
+ stack: value.stack
62
+ };
63
+ }
64
+ return value;
65
+ }, indent);
66
+ }
67
+ function getStackTrace(error) {
68
+ const stack = (error || new Error()).stack || "";
69
+ return stack.split("\n").slice(1).map((line) => line.trim()).filter((line) => line.startsWith("at "));
70
+ }
71
+ function parseStackFrame(frame) {
72
+ const match = frame.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);
73
+ if (!match) {
74
+ return null;
75
+ }
76
+ const [, functionName, fileName, lineNumber, columnNumber] = match;
77
+ return {
78
+ functionName: functionName || "<anonymous>",
79
+ fileName: fileName || "<unknown>",
80
+ lineNumber: parseInt(lineNumber || "0", 10),
81
+ columnNumber: parseInt(columnNumber || "0", 10)
82
+ };
83
+ }
84
+
85
+ export {
86
+ throttle,
87
+ generateId,
88
+ safeStringify,
89
+ getStackTrace,
90
+ parseStackFrame
91
+ };
92
+ //# sourceMappingURL=chunk-LNBLBFDA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/utils.ts"],"sourcesContent":["export function debounce<T extends (...args: any[]) => any>(\n func: T,\n wait: number,\n options: { leading?: boolean; trailing?: boolean } = {}\n): (...args: Parameters<T>) => void {\n let timeout: ReturnType<typeof setTimeout> | null = null;\n let result: any;\n let lastCallTime: number | null = null;\n let lastThis: any;\n let lastArgs: any[] | null = null;\n\n const { leading = false, trailing = true } = options;\n\n const invokeFunc = (time: number) => {\n const args = lastArgs!;\n const thisArg = lastThis;\n\n lastArgs = lastThis = null;\n lastCallTime = time;\n result = func.apply(thisArg, args);\n return result;\n };\n\n const leadingEdge = (time: number) => {\n lastCallTime = time;\n timeout = setTimeout(timerExpired, wait);\n return leading ? invokeFunc(time) : result;\n };\n\n const timerExpired = () => {\n timeout = null;\n\n if (trailing && lastArgs) {\n return invokeFunc(Date.now());\n }\n lastArgs = lastThis = null;\n };\n\n return function debounced(this: any, ...args: Parameters<T>) {\n const time = Date.now();\n const isInvoking = shouldInvoke(time);\n\n lastArgs = args;\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n lastThis = this;\n\n if (isInvoking) {\n if (timeout === null) {\n return leadingEdge(time);\n }\n }\n\n if (timeout !== null) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(timerExpired, wait);\n return result;\n };\n\n function shouldInvoke(time: number): boolean {\n return lastCallTime === null || time - lastCallTime >= wait;\n }\n}\n\nexport function throttle<T extends (...args: any[]) => any>(\n func: T,\n wait: number,\n options: { leading?: boolean; trailing?: boolean } = {}\n): (...args: Parameters<T>) => void {\n let timeout: ReturnType<typeof setTimeout> | null = null;\n let lastCallTime = 0;\n let lastThis: any;\n let lastArgs: any[] | null = null;\n let result: any;\n\n const { leading = true, trailing = true } = options;\n\n const invokeFunc = () => {\n const args = lastArgs!;\n const thisArg = lastThis;\n\n lastArgs = lastThis = null;\n result = func.apply(thisArg, args);\n return result;\n };\n\n return function throttled(this: any, ...args: Parameters<T>) {\n const now = Date.now();\n const remaining = wait - (now - lastCallTime);\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n lastThis = this;\n lastArgs = args;\n\n if (remaining <= 0 || remaining > wait) {\n if (timeout) {\n clearTimeout(timeout);\n timeout = null;\n }\n lastCallTime = now;\n if (leading) {\n result = invokeFunc();\n }\n } else if (!timeout && trailing) {\n timeout = setTimeout(() => {\n lastCallTime = Date.now();\n timeout = null;\n if (trailing && lastArgs) {\n invokeFunc();\n }\n }, remaining);\n }\n\n return result;\n };\n}\n\nexport function deepClone<T>(obj: T): T {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as any;\n }\n\n if (obj instanceof Array) {\n return obj.map(item => deepClone(item)) as any;\n }\n\n if (obj instanceof Set) {\n return new Set(Array.from(obj).map(item => deepClone(item))) as any;\n }\n\n if (obj instanceof Map) {\n return new Map(\n Array.from(obj.entries()).map(([key, value]) => [deepClone(key), deepClone(value)])\n ) as any;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as any;\n }\n\n const clonedObj = Object.create(Object.getPrototypeOf(obj));\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n clonedObj[key] = deepClone(obj[key]);\n }\n }\n\n return clonedObj;\n}\n\nexport function formatBytes(bytes: number, precision: number = 2): string {\n const units = ['B', 'KB', 'MB', 'GB', 'TB'];\n\n if (bytes === 0) return '0 B';\n if (bytes < 0) throw new Error('formatBytes: negative values not supported');\n\n const k = 1024;\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n return parseFloat((bytes / Math.pow(k, i)).toFixed(precision)) + ' ' + units[i];\n}\n\nexport function formatDuration(ms: number): string {\n if (ms < 1000) return `${ms}ms`;\n if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`;\n if (ms < 3600000) return `${Math.floor(ms / 60000)}m ${Math.floor((ms % 60000) / 1000)}s`;\n return `${Math.floor(ms / 3600000)}h ${Math.floor((ms % 3600000) / 60000)}m`;\n}\n\nexport function generateId(): string {\n return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n}\n\nexport function isCircularReference(obj: any, seen = new WeakSet()): boolean {\n if (obj === null || typeof obj !== 'object') {\n return false;\n }\n\n if (seen.has(obj)) {\n return true;\n }\n\n seen.add(obj);\n\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key) && isCircularReference(obj[key], seen)) {\n return true;\n }\n }\n\n seen.delete(obj);\n return false;\n}\n\nexport function safeStringify(obj: any, indent?: number): string {\n const seen = new WeakSet();\n \n return JSON.stringify(obj, (key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (seen.has(value)) {\n return '[Circular]';\n }\n seen.add(value);\n }\n \n if (typeof value === 'function') {\n return value.toString();\n }\n \n if (value instanceof Error) {\n return {\n name: value.name,\n message: value.message,\n stack: value.stack\n };\n }\n \n return value;\n }, indent);\n}\n\nexport function getStackTrace(error?: Error): string[] {\n const stack = (error || new Error()).stack || '';\n return stack\n .split('\\n')\n .slice(1)\n .map(line => line.trim())\n .filter(line => line.startsWith('at '));\n}\n\nexport function parseStackFrame(frame: string): {\n functionName?: string;\n fileName?: string;\n lineNumber?: number;\n columnNumber?: number;\n} | null {\n const match = frame.match(/at\\s+(?:(.+?)\\s+\\()?(.+?):(\\d+):(\\d+)\\)?$/);\n \n if (!match) {\n return null;\n }\n\n const [, functionName, fileName, lineNumber, columnNumber] = match;\n \n return {\n functionName: functionName || '<anonymous>',\n fileName: fileName || '<unknown>',\n lineNumber: parseInt(lineNumber || '0', 10),\n columnNumber: parseInt(columnNumber || '0', 10)\n };\n}\n\nexport function memoize<T extends (...args: any[]) => any>(\n fn: T,\n options: {\n maxSize?: number;\n ttl?: number;\n keyResolver?: (...args: Parameters<T>) => string;\n } = {}\n): T {\n const { maxSize = 100, ttl, keyResolver = (...args) => JSON.stringify(args) } = options;\n const cache = new Map<string, { value: ReturnType<T>; timestamp: number }>();\n\n return ((...args: Parameters<T>): ReturnType<T> => {\n const key = keyResolver(...args);\n const cached = cache.get(key);\n\n if (cached) {\n if (!ttl || Date.now() - cached.timestamp < ttl) {\n return cached.value;\n }\n cache.delete(key);\n }\n\n // Evict oldest entry BEFORE adding if at capacity\n if (cache.size >= maxSize) {\n const firstKey = cache.keys().next().value;\n if (firstKey !== undefined) {\n cache.delete(firstKey);\n }\n }\n\n const result = fn(...args);\n cache.set(key, { value: result, timestamp: Date.now() });\n\n return result;\n }) as T;\n}\n\nexport function createWorkerScript(fn: (...args: any[]) => any): string {\n return `\n self.addEventListener('message', async (event) => {\n try {\n const result = await (${fn.toString()})(event.data);\n self.postMessage({ type: 'result', data: result });\n } catch (error) {\n self.postMessage({\n type: 'error',\n error: {\n message: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined\n }\n });\n }\n });\n `;\n}\n\nexport function createObjectURL(content: string, type = 'application/javascript'): string {\n const blob = new Blob([content], { type });\n return URL.createObjectURL(blob);\n}\n\nexport class Deferred<T> {\n promise: Promise<T>;\n resolve!: (value: T | PromiseLike<T>) => void;\n reject!: (reason?: any) => void;\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n}"],"mappings":";AAgEO,SAAS,SACd,MACA,MACA,UAAqD,CAAC,GACpB;AAClC,MAAI,UAAgD;AACpD,MAAI,eAAe;AACnB,MAAI;AACJ,MAAI,WAAyB;AAC7B,MAAI;AAEJ,QAAM,EAAE,UAAU,MAAM,WAAW,KAAK,IAAI;AAE5C,QAAM,aAAa,MAAM;AACvB,UAAM,OAAO;AACb,UAAM,UAAU;AAEhB,eAAW,WAAW;AACtB,aAAS,KAAK,MAAM,SAAS,IAAI;AACjC,WAAO;AAAA,EACT;AAEA,SAAO,SAAS,aAAwB,MAAqB;AAC3D,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,YAAY,QAAQ,MAAM;AAGhC,eAAW;AACX,eAAW;AAEX,QAAI,aAAa,KAAK,YAAY,MAAM;AACtC,UAAI,SAAS;AACX,qBAAa,OAAO;AACpB,kBAAU;AAAA,MACZ;AACA,qBAAe;AACf,UAAI,SAAS;AACX,iBAAS,WAAW;AAAA,MACtB;AAAA,IACF,WAAW,CAAC,WAAW,UAAU;AAC/B,gBAAU,WAAW,MAAM;AACzB,uBAAe,KAAK,IAAI;AACxB,kBAAU;AACV,YAAI,YAAY,UAAU;AACxB,qBAAW;AAAA,QACb;AAAA,MACF,GAAG,SAAS;AAAA,IACd;AAEA,WAAO;AAAA,EACT;AACF;AA0DO,SAAS,aAAqB;AACnC,SAAO,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AACjE;AAuBO,SAAS,cAAc,KAAU,QAAyB;AAC/D,QAAM,OAAO,oBAAI,QAAQ;AAEzB,SAAO,KAAK,UAAU,KAAK,CAAC,KAAK,UAAU;AACzC,QAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,UAAI,KAAK,IAAI,KAAK,GAAG;AACnB,eAAO;AAAA,MACT;AACA,WAAK,IAAI,KAAK;AAAA,IAChB;AAEA,QAAI,OAAO,UAAU,YAAY;AAC/B,aAAO,MAAM,SAAS;AAAA,IACxB;AAEA,QAAI,iBAAiB,OAAO;AAC1B,aAAO;AAAA,QACL,MAAM,MAAM;AAAA,QACZ,SAAS,MAAM;AAAA,QACf,OAAO,MAAM;AAAA,MACf;AAAA,IACF;AAEA,WAAO;AAAA,EACT,GAAG,MAAM;AACX;AAEO,SAAS,cAAc,OAAyB;AACrD,QAAM,SAAS,SAAS,IAAI,MAAM,GAAG,SAAS;AAC9C,SAAO,MACJ,MAAM,IAAI,EACV,MAAM,CAAC,EACP,IAAI,UAAQ,KAAK,KAAK,CAAC,EACvB,OAAO,UAAQ,KAAK,WAAW,KAAK,CAAC;AAC1C;AAEO,SAAS,gBAAgB,OAKvB;AACP,QAAM,QAAQ,MAAM,MAAM,2CAA2C;AAErE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,EAAE,cAAc,UAAU,YAAY,YAAY,IAAI;AAE7D,SAAO;AAAA,IACL,cAAc,gBAAgB;AAAA,IAC9B,UAAU,YAAY;AAAA,IACtB,YAAY,SAAS,cAAc,KAAK,EAAE;AAAA,IAC1C,cAAc,SAAS,gBAAgB,KAAK,EAAE;AAAA,EAChD;AACF;","names":[]}
@@ -0,0 +1,32 @@
1
+ // src/core/env.ts
2
+ function readNodeEnv() {
3
+ try {
4
+ return "development";
5
+ } catch (e) {
6
+ return void 0;
7
+ }
8
+ }
9
+ function defaultEnabled() {
10
+ return readNodeEnv() !== "production";
11
+ }
12
+ function hasDom() {
13
+ return typeof window !== "undefined" && typeof document !== "undefined";
14
+ }
15
+ var HTML_ESCAPES = {
16
+ "&": "&amp;",
17
+ "<": "&lt;",
18
+ ">": "&gt;",
19
+ '"': "&quot;",
20
+ "'": "&#39;",
21
+ "`": "&#96;"
22
+ };
23
+ function escapeHtml(value) {
24
+ return String(value).replace(/[&<>"'`]/g, (ch) => HTML_ESCAPES[ch]);
25
+ }
26
+
27
+ export {
28
+ defaultEnabled,
29
+ hasDom,
30
+ escapeHtml
31
+ };
32
+ //# sourceMappingURL=chunk-VZORB655.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/env.ts"],"sourcesContent":["/**\n * Helpers shared by every inspector variant.\n */\n\n/**\n * Reads `process.env.NODE_ENV` without assuming `process` exists.\n *\n * The expression is written out literally so bundlers (webpack DefinePlugin,\n * Vite, esbuild `define`, Rollup replace) substitute it at build time. In a\n * browser without such substitution, `process` is undefined and the access\n * throws, which is caught here.\n */\nexport function readNodeEnv(): string | undefined {\n try {\n return process.env.NODE_ENV;\n } catch {\n return undefined;\n }\n}\n\n/** Default for the `enabled` option: on everywhere except production builds. */\nexport function defaultEnabled(): boolean {\n return readNodeEnv() !== 'production';\n}\n\n/** True when a DOM is available (browser, jsdom), false during SSR/Node. */\nexport function hasDom(): boolean {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\nconst HTML_ESCAPES: Record<string, string> = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;',\n \"'\": '&#39;',\n '`': '&#96;',\n};\n\n/** Escapes a value for use in HTML text or a quoted attribute. */\nexport function escapeHtml(value: unknown): string {\n return String(value).replace(/[&<>\"'`]/g, ch => HTML_ESCAPES[ch] as string);\n}\n"],"mappings":";AAYO,SAAS,cAAkC;AAChD,MAAI;AACF,WAAO;AAAA,EACT,SAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,iBAA0B;AACxC,SAAO,YAAY,MAAM;AAC3B;AAGO,SAAS,SAAkB;AAChC,SAAO,OAAO,WAAW,eAAe,OAAO,aAAa;AAC9D;AAEA,IAAM,eAAuC;AAAA,EAC3C,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACP;AAGO,SAAS,WAAW,OAAwB;AACjD,SAAO,OAAO,KAAK,EAAE,QAAQ,aAAa,QAAM,aAAa,EAAE,CAAW;AAC5E;","names":[]}