@elmoorx/devtools 2.0.0-alpha.25
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/LICENSE +21 -0
- package/README.md +33 -0
- package/package.json +34 -0
- package/src/index.ts +160 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wafra Framework
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @wafra/devtools
|
|
2
|
+
|
|
3
|
+
> Browser DevTools extension: signal inspector, time-travel, profiler
|
|
4
|
+
|
|
5
|
+
Part of the [Wafra Framework](https://github.com/wafra/framework) — Build fast. Run anywhere. Stay secure.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @wafra/devtools
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { /* exports */ } from '@wafra/devtools';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- Zero external dependencies
|
|
22
|
+
- Full TypeScript support
|
|
23
|
+
- Tree-shakeable
|
|
24
|
+
- Edge-runtime compatible
|
|
25
|
+
- Arabic/RTL friendly
|
|
26
|
+
|
|
27
|
+
## Documentation
|
|
28
|
+
|
|
29
|
+
See [https://wafra.dev/docs/devtools](https://wafra.dev/docs/devtools)
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
MIT © Wafra Framework
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elmoorx/devtools",
|
|
3
|
+
"version": "2.0.0-alpha.25",
|
|
4
|
+
"description": "Browser DevTools extension: signal inspector, time-travel, profiler",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"types": "./src/index.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@elmoorx/runtime": "^1.0.0"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Wafra Framework",
|
|
16
|
+
"homepage": "https://wafra.dev/packages/devtools",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/wafra/framework",
|
|
20
|
+
"directory": "packages/devtools"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/wafra/framework/issues"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"wafra",
|
|
27
|
+
"framework",
|
|
28
|
+
"devtools"
|
|
29
|
+
],
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"exports": {
|
|
32
|
+
".": "./src/index.ts"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wafra DevTools — Browser debug panel
|
|
3
|
+
* ============================================
|
|
4
|
+
* Press Ctrl+Shift+W (or Cmd+Shift+W on Mac) to open.
|
|
5
|
+
*
|
|
6
|
+
* Shows:
|
|
7
|
+
* - Active signals (current value + dep count)
|
|
8
|
+
* - Active effects (call count + last run time)
|
|
9
|
+
* - Hydrated islands (location + size)
|
|
10
|
+
* - Performance timeline
|
|
11
|
+
* - Store snapshots
|
|
12
|
+
*
|
|
13
|
+
* Zero-cost in production — only included when NODE_ENV !== 'production'.
|
|
14
|
+
*
|
|
15
|
+
* Bundle impact: ~1.2kb (only in dev builds)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { $state, $effect } from "@wafra/runtime";
|
|
19
|
+
|
|
20
|
+
interface DevtoolsState {
|
|
21
|
+
signals: Map<string, { value: unknown; deps: number }>;
|
|
22
|
+
effects: Map<string, { runs: number; lastMs: number }>;
|
|
23
|
+
islands: Map<string, { id: string; element?: Element }>;
|
|
24
|
+
storeSnapshots: Map<string, unknown>;
|
|
25
|
+
open: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const devtools = $state<DevtoolsState>({
|
|
29
|
+
signals: new Map(),
|
|
30
|
+
effects: new Map(),
|
|
31
|
+
islands: new Map(),
|
|
32
|
+
storeSnapshots: new Map(),
|
|
33
|
+
open: false,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Track active signals
|
|
37
|
+
const originalState = (globalThis as any).$state;
|
|
38
|
+
if (typeof originalState === "function") {
|
|
39
|
+
let signalId = 0;
|
|
40
|
+
(globalThis as any).$state = function (initial: unknown) {
|
|
41
|
+
const id = `sig_${signalId++}`;
|
|
42
|
+
const sig = originalState(initial);
|
|
43
|
+
|
|
44
|
+
// Track value changes
|
|
45
|
+
const originalSet = sig.set;
|
|
46
|
+
sig.set = function (v: unknown) {
|
|
47
|
+
const resolved = typeof v === "function" ? v(sig._value) : v;
|
|
48
|
+
devtools().signals.set(id, { value: resolved, deps: sig._deps?.size || 0 });
|
|
49
|
+
return originalSet(v);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
devtools().signals.set(id, { value: initial, deps: 0 });
|
|
53
|
+
return sig;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Register an island with the devtools.
|
|
59
|
+
*/
|
|
60
|
+
export function registerIsland(id: string, element?: Element): void {
|
|
61
|
+
if (process.env.NODE_ENV === "production") return;
|
|
62
|
+
devtools().islands.set(id, { id, element });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Take a snapshot of a store's current state.
|
|
67
|
+
*/
|
|
68
|
+
export function snapshotStore(name: string, value: unknown): void {
|
|
69
|
+
if (process.env.NODE_ENV === "production") return;
|
|
70
|
+
devtools().storeSnapshots.set(name, value);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Inject the devtools panel into the page.
|
|
75
|
+
* Call this once at app startup (dev only).
|
|
76
|
+
*/
|
|
77
|
+
export function injectDevtools(): void {
|
|
78
|
+
if (process.env.NODE_ENV === "production") return;
|
|
79
|
+
if (typeof document === "undefined") return;
|
|
80
|
+
|
|
81
|
+
// Wait for DOM ready
|
|
82
|
+
if (document.readyState === "loading") {
|
|
83
|
+
document.addEventListener("DOMContentLoaded", injectDevtools);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Create panel container
|
|
88
|
+
const panel = document.createElement("div");
|
|
89
|
+
panel.id = "wafra-devtools";
|
|
90
|
+
panel.style.cssText = `
|
|
91
|
+
position: fixed; bottom: 0; right: 0; width: 400px; height: 300px;
|
|
92
|
+
background: #0A0A0F; color: #E4E4E7; border: 1px solid #A855F7;
|
|
93
|
+
border-radius: 8px 0 0 0; z-index: 99999; font-family: monospace;
|
|
94
|
+
font-size: 11px; padding: 12px; overflow: auto; display: none;
|
|
95
|
+
box-shadow: 0 0 40px rgba(168,85,247,0.3);
|
|
96
|
+
`;
|
|
97
|
+
document.body.appendChild(panel);
|
|
98
|
+
|
|
99
|
+
// Toggle with Ctrl+Shift+W
|
|
100
|
+
document.addEventListener("keydown", (e) => {
|
|
101
|
+
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === "W") {
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
panel.style.display = panel.style.display === "none" ? "block" : "none";
|
|
104
|
+
renderPanel(panel);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Auto-update every 500ms when open
|
|
109
|
+
setInterval(() => {
|
|
110
|
+
if (panel.style.display === "block") renderPanel(panel);
|
|
111
|
+
}, 500);
|
|
112
|
+
|
|
113
|
+
console.log("%c Wafra DevTools ", "background:#A855F7;color:white;padding:4px 8px;border-radius:4px;font-weight:bold");
|
|
114
|
+
console.log("Press Ctrl+Shift+W to toggle the debug panel");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function renderPanel(panel: HTMLElement): void {
|
|
118
|
+
const state = devtools();
|
|
119
|
+
const sigCount = state.signals.size;
|
|
120
|
+
const effCount = state.effects.size;
|
|
121
|
+
const islandCount = state.islands.size;
|
|
122
|
+
|
|
123
|
+
panel.innerHTML = `
|
|
124
|
+
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;border-bottom:1px solid #2A2A38;padding-bottom:8px">
|
|
125
|
+
<strong style="color:#A855F7">⚡ Wafra DevTools</strong>
|
|
126
|
+
<span style="color:#71717A;font-size:10px">v1.0</span>
|
|
127
|
+
</div>
|
|
128
|
+
<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px;margin-bottom:12px">
|
|
129
|
+
<div style="background:#14141B;padding:8px;border-radius:4px;text-align:center">
|
|
130
|
+
<div style="color:#A855F7;font-size:16px;font-weight:bold">${sigCount}</div>
|
|
131
|
+
<div style="color:#71717A;font-size:9px">SIGNALS</div>
|
|
132
|
+
</div>
|
|
133
|
+
<div style="background:#14141B;padding:8px;border-radius:4px;text-align:center">
|
|
134
|
+
<div style="color:#06B6D4;font-size:16px;font-weight:bold">${effCount}</div>
|
|
135
|
+
<div style="color:#71717A;font-size:9px">EFFECTS</div>
|
|
136
|
+
</div>
|
|
137
|
+
<div style="background:#14141B;padding:8px;border-radius:4px;text-align:center">
|
|
138
|
+
<div style="color:#10B981;font-size:16px;font-weight:bold">${islandCount}</div>
|
|
139
|
+
<div style="color:#71717A;font-size:9px">ISLANDS</div>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
<div style="margin-bottom:8px">
|
|
143
|
+
<div style="color:#A855F7;margin-bottom:4px">Signals:</div>
|
|
144
|
+
${[...state.signals.entries()].slice(0, 5).map(([id, info]) => `
|
|
145
|
+
<div style="background:#14141B;padding:4px 6px;border-radius:3px;margin-bottom:2px;color:#A1A1AA">
|
|
146
|
+
${id}: <span style="color:#06B6D4">${JSON.stringify(info.value).slice(0, 40)}</span>
|
|
147
|
+
<span style="color:#71717A">(${info.deps} deps)</span>
|
|
148
|
+
</div>
|
|
149
|
+
`).join("")}
|
|
150
|
+
</div>
|
|
151
|
+
<div>
|
|
152
|
+
<div style="color:#A855F7;margin-bottom:4px">Islands:</div>
|
|
153
|
+
${[...state.islands.entries()].slice(0, 5).map(([id, info]) => `
|
|
154
|
+
<div style="background:#14141B;padding:4px 6px;border-radius:3px;margin-bottom:2px;color:#A1A1AA">
|
|
155
|
+
${id}
|
|
156
|
+
</div>
|
|
157
|
+
`).join("")}
|
|
158
|
+
</div>
|
|
159
|
+
`;
|
|
160
|
+
}
|