@ytspar/devbar 0.0.1 → 1.0.0-canary.e1f65d0
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 +168 -28
- package/dist/GlobalDevBar.d.ts +201 -0
- package/dist/GlobalDevBar.js +1979 -0
- package/dist/constants.d.ts +202 -0
- package/dist/constants.js +535 -0
- package/dist/earlyConsoleCapture.d.ts +34 -0
- package/dist/earlyConsoleCapture.js +77 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +13 -0
- package/dist/outline.d.ts +14 -0
- package/dist/outline.js +215 -0
- package/dist/schema.d.ts +14 -0
- package/dist/schema.js +113 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.js +8 -0
- package/dist/ui/buttons.d.ts +21 -0
- package/dist/ui/buttons.js +55 -0
- package/dist/ui/icons.d.ts +13 -0
- package/dist/ui/icons.js +25 -0
- package/dist/ui/index.d.ts +8 -0
- package/dist/ui/index.js +8 -0
- package/dist/ui/modals.d.ts +40 -0
- package/dist/ui/modals.js +144 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +13 -0
- package/package.json +58 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ytspar
|
|
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
CHANGED
|
@@ -1,45 +1,185 @@
|
|
|
1
1
|
# @ytspar/devbar
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Development toolbar with Sweetlink integration for browser-based development tools.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Breakpoint indicator**: Shows current Tailwind breakpoint and viewport dimensions
|
|
8
|
+
- **Performance metrics**: FCP, LCP, and total page size
|
|
9
|
+
- **Console badges**: Error and warning counts with click-to-view logs
|
|
10
|
+
- **Screenshot capture**: Save to file or copy to clipboard
|
|
11
|
+
- **AI Design Review**: Send screenshots to Claude for design analysis
|
|
12
|
+
- **Document Outline**: View and export page heading structure
|
|
13
|
+
- **Page Schema**: View JSON-LD, Open Graph, and meta tag data
|
|
14
|
+
- **Sweetlink integration**: Real-time connection to dev server
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add @ytspar/devbar
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Basic Setup (Vanilla JS)
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { initGlobalDevBar } from '@ytspar/devbar';
|
|
28
|
+
|
|
29
|
+
// Initialize with default options
|
|
30
|
+
initGlobalDevBar();
|
|
31
|
+
|
|
32
|
+
// Or with custom options
|
|
33
|
+
initGlobalDevBar({
|
|
34
|
+
position: 'bottom-left',
|
|
35
|
+
accentColor: '#10b981',
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### In a Vite/React Project
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// main.ts or App.tsx
|
|
43
|
+
if (import.meta.env.DEV) {
|
|
44
|
+
import('@ytspar/devbar').then(({ initGlobalDevBar }) => {
|
|
45
|
+
initGlobalDevBar({
|
|
46
|
+
position: 'bottom-center',
|
|
47
|
+
showTooltips: true,
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Positions
|
|
54
|
+
|
|
55
|
+
The devbar can be placed in five positions:
|
|
56
|
+
|
|
57
|
+
| Position | Description |
|
|
58
|
+
|----------|-------------|
|
|
59
|
+
| `bottom-left` | Bottom left corner (default) - leaves room for other dev tools on the right |
|
|
60
|
+
| `bottom-right` | Bottom right corner |
|
|
61
|
+
| `top-left` | Top left corner |
|
|
62
|
+
| `top-right` | Top right corner |
|
|
63
|
+
| `bottom-center` | Centered at bottom - ideal for focused development, responsive at mobile sizes |
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// Example: Center the devbar at the bottom
|
|
67
|
+
initGlobalDevBar({ position: 'bottom-center' });
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
On mobile viewports (`<640px`), all positions automatically center and the action buttons wrap to a second row.
|
|
71
|
+
|
|
72
|
+
### Configuration Options
|
|
4
73
|
|
|
5
|
-
|
|
74
|
+
```typescript
|
|
75
|
+
interface GlobalDevBarOptions {
|
|
76
|
+
/** Position of the devbar. Default: 'bottom-left' */
|
|
77
|
+
position?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right' | 'bottom-center';
|
|
6
78
|
|
|
7
|
-
|
|
79
|
+
/** Primary accent color (CSS color). Default: '#10b981' (emerald) */
|
|
80
|
+
accentColor?: string;
|
|
8
81
|
|
|
9
|
-
|
|
82
|
+
/** Which metrics to show. Default: all enabled */
|
|
83
|
+
showMetrics?: {
|
|
84
|
+
breakpoint?: boolean; // Tailwind breakpoint indicator
|
|
85
|
+
fcp?: boolean; // First Contentful Paint
|
|
86
|
+
lcp?: boolean; // Largest Contentful Paint
|
|
87
|
+
pageSize?: boolean; // Total transfer size
|
|
88
|
+
};
|
|
10
89
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
2. Enable secure, token-less publishing from CI/CD workflows
|
|
14
|
-
3. Establish provenance for packages published under this name
|
|
90
|
+
/** Whether to show the screenshot button. Default: true */
|
|
91
|
+
showScreenshot?: boolean;
|
|
15
92
|
|
|
16
|
-
|
|
93
|
+
/** Whether to show console error/warning badges. Default: true */
|
|
94
|
+
showConsoleBadges?: boolean;
|
|
17
95
|
|
|
18
|
-
|
|
96
|
+
/** Whether to show tooltips on hover. Default: true */
|
|
97
|
+
showTooltips?: boolean;
|
|
19
98
|
|
|
20
|
-
|
|
99
|
+
/** Size overrides for special layouts */
|
|
100
|
+
sizeOverrides?: {
|
|
101
|
+
width?: string;
|
|
102
|
+
maxWidth?: string;
|
|
103
|
+
minWidth?: string;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
```
|
|
21
107
|
|
|
22
|
-
|
|
108
|
+
### Example: Minimal DevBar
|
|
23
109
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
110
|
+
```typescript
|
|
111
|
+
initGlobalDevBar({
|
|
112
|
+
showMetrics: {
|
|
113
|
+
breakpoint: true,
|
|
114
|
+
fcp: false,
|
|
115
|
+
lcp: false,
|
|
116
|
+
pageSize: false,
|
|
117
|
+
},
|
|
118
|
+
showScreenshot: false,
|
|
119
|
+
showConsoleBadges: true,
|
|
120
|
+
showTooltips: false, // Disable tooltips
|
|
121
|
+
});
|
|
122
|
+
```
|
|
28
123
|
|
|
29
|
-
|
|
124
|
+
### Custom Controls
|
|
30
125
|
|
|
31
|
-
|
|
32
|
-
- Contains no executable code
|
|
33
|
-
- Provides no functionality
|
|
34
|
-
- Should not be installed as a dependency
|
|
35
|
-
- Exists only for administrative purposes
|
|
126
|
+
Register custom buttons that appear in the devbar:
|
|
36
127
|
|
|
37
|
-
|
|
128
|
+
```typescript
|
|
129
|
+
import { GlobalDevBar } from '@ytspar/devbar';
|
|
38
130
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
131
|
+
// Register a custom control
|
|
132
|
+
GlobalDevBar.registerControl({
|
|
133
|
+
id: 'my-control',
|
|
134
|
+
label: 'Reset State',
|
|
135
|
+
onClick: () => {
|
|
136
|
+
localStorage.clear();
|
|
137
|
+
location.reload();
|
|
138
|
+
},
|
|
139
|
+
variant: 'warning', // 'default' | 'warning'
|
|
140
|
+
});
|
|
42
141
|
|
|
43
|
-
|
|
142
|
+
// Unregister when done
|
|
143
|
+
GlobalDevBar.unregisterControl('my-control');
|
|
144
|
+
```
|
|
44
145
|
|
|
45
|
-
|
|
146
|
+
### Cleanup
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { destroyGlobalDevBar } from '@ytspar/devbar';
|
|
150
|
+
|
|
151
|
+
// Remove the devbar and cleanup listeners
|
|
152
|
+
destroyGlobalDevBar();
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Keyboard Shortcuts
|
|
156
|
+
|
|
157
|
+
- `Cmd/Ctrl + Shift + S`: Save screenshot to file
|
|
158
|
+
- `Cmd/Ctrl + Shift + C`: Copy screenshot to clipboard
|
|
159
|
+
- `Escape`: Close any open modal/popup
|
|
160
|
+
|
|
161
|
+
## Integration with Sweetlink
|
|
162
|
+
|
|
163
|
+
The devbar automatically connects to the Sweetlink WebSocket server (port 9223) for:
|
|
164
|
+
|
|
165
|
+
- Screenshot saving to the project directory
|
|
166
|
+
- AI-powered design review via Claude
|
|
167
|
+
- Document outline and schema export
|
|
168
|
+
|
|
169
|
+
When Sweetlink is not running, the devbar still functions but file-saving features are disabled.
|
|
170
|
+
|
|
171
|
+
## Early Console Capture
|
|
172
|
+
|
|
173
|
+
Console logs are captured from the moment the devbar module loads, before your app initializes. This catches:
|
|
174
|
+
|
|
175
|
+
- All `console.log/error/warn/info` calls
|
|
176
|
+
- Errors that occur during hydration
|
|
177
|
+
- Early initialization issues
|
|
178
|
+
|
|
179
|
+
## Dependencies
|
|
180
|
+
|
|
181
|
+
- `html2canvas-pro` - Screenshot capture
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GlobalDevBar - Vanilla JS implementation
|
|
3
|
+
*
|
|
4
|
+
* A development toolbar that displays breakpoint info, performance stats,
|
|
5
|
+
* console error/warning counts, and provides screenshot capabilities via Sweetlink.
|
|
6
|
+
*
|
|
7
|
+
* This is a vanilla JS replacement for the React-based GlobalDevBar component
|
|
8
|
+
* to avoid React dependency conflicts in host applications.
|
|
9
|
+
*/
|
|
10
|
+
import type { ConsoleLog, SweetlinkCommand, OutlineNode, PageSchema, GlobalDevBarOptions, DevBarControl } from './types.js';
|
|
11
|
+
export type { ConsoleLog, SweetlinkCommand, OutlineNode, PageSchema, GlobalDevBarOptions, DevBarControl };
|
|
12
|
+
interface EarlyConsoleCapture {
|
|
13
|
+
errorCount: number;
|
|
14
|
+
warningCount: number;
|
|
15
|
+
logs: ConsoleLog[];
|
|
16
|
+
originalConsole: {
|
|
17
|
+
log: typeof console.log;
|
|
18
|
+
error: typeof console.error;
|
|
19
|
+
warn: typeof console.warn;
|
|
20
|
+
info: typeof console.info;
|
|
21
|
+
} | null;
|
|
22
|
+
isPatched: boolean;
|
|
23
|
+
}
|
|
24
|
+
declare const earlyConsoleCapture: EarlyConsoleCapture;
|
|
25
|
+
export declare class GlobalDevBar {
|
|
26
|
+
private static customControls;
|
|
27
|
+
private options;
|
|
28
|
+
private container;
|
|
29
|
+
private ws;
|
|
30
|
+
private consoleLogs;
|
|
31
|
+
private sweetlinkConnected;
|
|
32
|
+
private collapsed;
|
|
33
|
+
private capturing;
|
|
34
|
+
private copiedToClipboard;
|
|
35
|
+
private copiedPath;
|
|
36
|
+
private lastScreenshot;
|
|
37
|
+
private designReviewInProgress;
|
|
38
|
+
private lastDesignReview;
|
|
39
|
+
private designReviewError;
|
|
40
|
+
private showDesignReviewConfirm;
|
|
41
|
+
private apiKeyStatus;
|
|
42
|
+
private lastOutline;
|
|
43
|
+
private lastSchema;
|
|
44
|
+
private consoleFilter;
|
|
45
|
+
private showOutlineModal;
|
|
46
|
+
private showSchemaModal;
|
|
47
|
+
private breakpointInfo;
|
|
48
|
+
private perfStats;
|
|
49
|
+
private lcpValue;
|
|
50
|
+
private reconnectAttempts;
|
|
51
|
+
private reconnectTimeout;
|
|
52
|
+
private screenshotTimeout;
|
|
53
|
+
private copiedPathTimeout;
|
|
54
|
+
private designReviewTimeout;
|
|
55
|
+
private designReviewErrorTimeout;
|
|
56
|
+
private outlineTimeout;
|
|
57
|
+
private schemaTimeout;
|
|
58
|
+
private resizeHandler;
|
|
59
|
+
private keydownHandler;
|
|
60
|
+
private fcpObserver;
|
|
61
|
+
private lcpObserver;
|
|
62
|
+
private destroyed;
|
|
63
|
+
private overlayElement;
|
|
64
|
+
constructor(options?: GlobalDevBarOptions);
|
|
65
|
+
/**
|
|
66
|
+
* Get tooltip class name(s) if tooltips are enabled, otherwise empty string
|
|
67
|
+
*/
|
|
68
|
+
private tooltipClass;
|
|
69
|
+
/**
|
|
70
|
+
* Get current error and warning counts from the log array
|
|
71
|
+
*/
|
|
72
|
+
private getLogCounts;
|
|
73
|
+
/**
|
|
74
|
+
* Create a collapsed count badge (used for error/warning counts in minimized state)
|
|
75
|
+
*/
|
|
76
|
+
private createCollapsedBadge;
|
|
77
|
+
/**
|
|
78
|
+
* Register a custom control to be displayed in the devbar
|
|
79
|
+
*/
|
|
80
|
+
static registerControl(control: DevBarControl): void;
|
|
81
|
+
/**
|
|
82
|
+
* Unregister a custom control by ID
|
|
83
|
+
*/
|
|
84
|
+
static unregisterControl(id: string): void;
|
|
85
|
+
/**
|
|
86
|
+
* Get all registered custom controls
|
|
87
|
+
*/
|
|
88
|
+
static getControls(): DevBarControl[];
|
|
89
|
+
/**
|
|
90
|
+
* Clear all custom controls
|
|
91
|
+
*/
|
|
92
|
+
static clearControls(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Initialize and mount the devbar
|
|
95
|
+
*/
|
|
96
|
+
init(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Destroy the devbar and cleanup
|
|
99
|
+
*/
|
|
100
|
+
destroy(): void;
|
|
101
|
+
private injectStyles;
|
|
102
|
+
private connectWebSocket;
|
|
103
|
+
private handleSweetlinkCommand;
|
|
104
|
+
/**
|
|
105
|
+
* Handle notification state updates with auto-clear timeout
|
|
106
|
+
*/
|
|
107
|
+
private handleNotification;
|
|
108
|
+
private setupBreakpointDetection;
|
|
109
|
+
private setupPerformanceMonitoring;
|
|
110
|
+
private setupKeyboardShortcuts;
|
|
111
|
+
private copyPathToClipboard;
|
|
112
|
+
private handleScreenshot;
|
|
113
|
+
private handleDesignReview;
|
|
114
|
+
/**
|
|
115
|
+
* Show the design review confirmation modal
|
|
116
|
+
* Checks API key status first
|
|
117
|
+
*/
|
|
118
|
+
private showDesignReviewConfirmation;
|
|
119
|
+
/**
|
|
120
|
+
* Calculate estimated cost for design review based on viewport size
|
|
121
|
+
*/
|
|
122
|
+
private calculateCostEstimate;
|
|
123
|
+
/**
|
|
124
|
+
* Close the design review confirmation modal
|
|
125
|
+
*/
|
|
126
|
+
private closeDesignReviewConfirm;
|
|
127
|
+
/**
|
|
128
|
+
* Proceed with design review after confirmation
|
|
129
|
+
*/
|
|
130
|
+
private proceedWithDesignReview;
|
|
131
|
+
private handleDocumentOutline;
|
|
132
|
+
private handlePageSchema;
|
|
133
|
+
private handleSaveOutline;
|
|
134
|
+
private handleSaveSchema;
|
|
135
|
+
private clearConsoleLogs;
|
|
136
|
+
private render;
|
|
137
|
+
private renderOverlays;
|
|
138
|
+
private renderDesignReviewConfirmModal;
|
|
139
|
+
/**
|
|
140
|
+
* Render content when API key is not configured
|
|
141
|
+
*/
|
|
142
|
+
private renderApiKeyNotConfiguredContent;
|
|
143
|
+
/**
|
|
144
|
+
* Render content when API key is configured (cost estimate and model info)
|
|
145
|
+
*/
|
|
146
|
+
private renderApiKeyConfiguredContent;
|
|
147
|
+
private renderConsolePopup;
|
|
148
|
+
/**
|
|
149
|
+
* Render console log items into a container
|
|
150
|
+
*/
|
|
151
|
+
private renderConsoleLogs;
|
|
152
|
+
private renderOutlineModal;
|
|
153
|
+
/**
|
|
154
|
+
* Recursively render outline nodes into a container element
|
|
155
|
+
*/
|
|
156
|
+
private renderOutlineNodes;
|
|
157
|
+
private renderSchemaModal;
|
|
158
|
+
/**
|
|
159
|
+
* Render a section of schema data (either array or key-value object)
|
|
160
|
+
*/
|
|
161
|
+
private renderSchemaSection;
|
|
162
|
+
/**
|
|
163
|
+
* Render JSON-LD items as formatted code blocks with syntax highlighting
|
|
164
|
+
*/
|
|
165
|
+
private renderJsonLdItems;
|
|
166
|
+
/**
|
|
167
|
+
* Append syntax-highlighted JSON to an element using safe DOM methods
|
|
168
|
+
* Uses textContent for all text to prevent XSS
|
|
169
|
+
*/
|
|
170
|
+
private appendHighlightedJson;
|
|
171
|
+
/**
|
|
172
|
+
* Render key-value pairs as rows with ellipsis overflow and hover tooltip
|
|
173
|
+
*/
|
|
174
|
+
private renderKeyValueItems;
|
|
175
|
+
private renderCollapsed;
|
|
176
|
+
private renderExpanded;
|
|
177
|
+
/**
|
|
178
|
+
* Create a console badge for error/warning counts
|
|
179
|
+
*/
|
|
180
|
+
private createConsoleBadge;
|
|
181
|
+
private createScreenshotButton;
|
|
182
|
+
private createAIReviewButton;
|
|
183
|
+
private createOutlineButton;
|
|
184
|
+
private createSchemaButton;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Initialize and mount the GlobalDevBar
|
|
188
|
+
*
|
|
189
|
+
* HMR-safe: Uses window-based global that survives module reloads.
|
|
190
|
+
* If an instance already exists, it will be destroyed and recreated.
|
|
191
|
+
*/
|
|
192
|
+
export declare function initGlobalDevBar(options?: GlobalDevBarOptions): GlobalDevBar;
|
|
193
|
+
/**
|
|
194
|
+
* Get the current GlobalDevBar instance
|
|
195
|
+
*/
|
|
196
|
+
export declare function getGlobalDevBar(): GlobalDevBar | null;
|
|
197
|
+
/**
|
|
198
|
+
* Destroy the GlobalDevBar
|
|
199
|
+
*/
|
|
200
|
+
export declare function destroyGlobalDevBar(): void;
|
|
201
|
+
export { earlyConsoleCapture };
|