@ytspar/devbar 0.0.1 → 1.0.0-canary.2b99e1e

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 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,190 @@
1
1
  # @ytspar/devbar
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
3
+ [![npm](https://img.shields.io/npm/v/@ytspar/devbar)](https://www.npmjs.com/package/@ytspar/devbar)
4
4
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
5
+ Development toolbar with Sweetlink integration for browser-based development tools.
6
6
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
7
+ ## Features
8
8
 
9
- ## Purpose
9
+ - **Breakpoint indicator**: Shows current Tailwind breakpoint and viewport dimensions
10
+ - **Performance metrics**: FCP, LCP, and total page size
11
+ - **Console badges**: Error and warning counts with click-to-view logs
12
+ - **Screenshot capture**: Save to file or copy to clipboard
13
+ - **AI Design Review**: Send screenshots to Claude for design analysis
14
+ - **Document Outline**: View and export page heading structure
15
+ - **Page Schema**: View JSON-LD, Open Graph, and meta tag data
16
+ - **Sweetlink integration**: Real-time connection to dev server
10
17
 
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@ytspar/devbar`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
18
+ ## Installation
19
+
20
+ ```bash
21
+ pnpm add @ytspar/devbar
22
+
23
+ # Or install canary (latest from main)
24
+ pnpm add @ytspar/devbar@canary
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### Basic Setup (Vanilla JS)
30
+
31
+ ```typescript
32
+ import { initGlobalDevBar } from '@ytspar/devbar';
33
+
34
+ // Initialize with default options
35
+ initGlobalDevBar();
36
+
37
+ // Or with custom options
38
+ initGlobalDevBar({
39
+ position: 'bottom-left',
40
+ accentColor: '#10b981',
41
+ });
42
+ ```
43
+
44
+ ### In a Vite/React Project
45
+
46
+ ```typescript
47
+ // main.ts or App.tsx
48
+ if (import.meta.env.DEV) {
49
+ import('@ytspar/devbar').then(({ initGlobalDevBar }) => {
50
+ initGlobalDevBar({
51
+ position: 'bottom-center',
52
+ showTooltips: true,
53
+ });
54
+ });
55
+ }
56
+ ```
57
+
58
+ ### Positions
59
+
60
+ The devbar can be placed in five positions:
61
+
62
+ | Position | Description |
63
+ |----------|-------------|
64
+ | `bottom-left` | Bottom left corner (default) - leaves room for other dev tools on the right |
65
+ | `bottom-right` | Bottom right corner |
66
+ | `top-left` | Top left corner |
67
+ | `top-right` | Top right corner |
68
+ | `bottom-center` | Centered at bottom - ideal for focused development, responsive at mobile sizes |
15
69
 
16
- ## What is OIDC Trusted Publishing?
70
+ ```typescript
71
+ // Example: Center the devbar at the bottom
72
+ initGlobalDevBar({ position: 'bottom-center' });
73
+ ```
74
+
75
+ On mobile viewports (`<640px`), all positions automatically center and the action buttons wrap to a second row.
17
76
 
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
77
+ ### Configuration Options
19
78
 
20
- ## Setup Instructions
79
+ ```typescript
80
+ interface GlobalDevBarOptions {
81
+ /** Position of the devbar. Default: 'bottom-left' */
82
+ position?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right' | 'bottom-center';
21
83
 
22
- To properly configure OIDC trusted publishing for this package:
84
+ /** Primary accent color (CSS color). Default: '#10b981' (emerald) */
85
+ accentColor?: string;
23
86
 
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
87
+ /** Which metrics to show. Default: all enabled */
88
+ showMetrics?: {
89
+ breakpoint?: boolean; // Tailwind breakpoint indicator
90
+ fcp?: boolean; // First Contentful Paint
91
+ lcp?: boolean; // Largest Contentful Paint
92
+ pageSize?: boolean; // Total transfer size
93
+ };
28
94
 
29
- ## DO NOT USE THIS PACKAGE
95
+ /** Whether to show the screenshot button. Default: true */
96
+ showScreenshot?: boolean;
30
97
 
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
98
+ /** Whether to show console error/warning badges. Default: true */
99
+ showConsoleBadges?: boolean;
36
100
 
37
- ## More Information
101
+ /** Whether to show tooltips on hover. Default: true */
102
+ showTooltips?: boolean;
38
103
 
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
104
+ /** Size overrides for special layouts */
105
+ sizeOverrides?: {
106
+ width?: string;
107
+ maxWidth?: string;
108
+ minWidth?: string;
109
+ };
110
+ }
111
+ ```
42
112
 
43
- ---
113
+ ### Example: Minimal DevBar
44
114
 
45
- **Maintained for OIDC setup purposes only**
115
+ ```typescript
116
+ initGlobalDevBar({
117
+ showMetrics: {
118
+ breakpoint: true,
119
+ fcp: false,
120
+ lcp: false,
121
+ pageSize: false,
122
+ },
123
+ showScreenshot: false,
124
+ showConsoleBadges: true,
125
+ showTooltips: false, // Disable tooltips
126
+ });
127
+ ```
128
+
129
+ ### Custom Controls
130
+
131
+ Register custom buttons that appear in the devbar:
132
+
133
+ ```typescript
134
+ import { GlobalDevBar } from '@ytspar/devbar';
135
+
136
+ // Register a custom control
137
+ GlobalDevBar.registerControl({
138
+ id: 'my-control',
139
+ label: 'Reset State',
140
+ onClick: () => {
141
+ localStorage.clear();
142
+ location.reload();
143
+ },
144
+ variant: 'warning', // 'default' | 'warning'
145
+ });
146
+
147
+ // Unregister when done
148
+ GlobalDevBar.unregisterControl('my-control');
149
+ ```
150
+
151
+ ### Cleanup
152
+
153
+ ```typescript
154
+ import { destroyGlobalDevBar } from '@ytspar/devbar';
155
+
156
+ // Remove the devbar and cleanup listeners
157
+ destroyGlobalDevBar();
158
+ ```
159
+
160
+ ## Keyboard Shortcuts
161
+
162
+ - `Cmd/Ctrl + Shift + S`: Save screenshot to file
163
+ - `Cmd/Ctrl + Shift + C`: Copy screenshot to clipboard
164
+ - `Escape`: Close any open modal/popup
165
+
166
+ ## Integration with Sweetlink
167
+
168
+ The devbar automatically connects to the Sweetlink WebSocket server (port 9223) for:
169
+
170
+ - Screenshot saving to the project directory
171
+ - AI-powered design review via Claude
172
+ - Document outline and schema export
173
+
174
+ When Sweetlink is not running, the devbar still functions but file-saving features are disabled.
175
+
176
+ ## Early Console Capture
177
+
178
+ Console logs are captured from the moment the devbar module loads, before your app initializes. This catches:
179
+
180
+ - All `console.log/error/warn/info` calls
181
+ - Errors that occur during hydration
182
+ - Early initialization issues
183
+
184
+ ## Dependencies
185
+
186
+ - `html2canvas-pro` - Screenshot capture
187
+
188
+ ## License
189
+
190
+ MIT
@@ -0,0 +1,318 @@
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 { getThemeColors } from './constants.js';
11
+ import type { ConsoleLog, DebugConfig, DevBarControl, GlobalDevBarOptions, OutlineNode, PageSchema, SweetlinkCommand, ThemeMode } from './types.js';
12
+ export type { ConsoleLog, DebugConfig, SweetlinkCommand, OutlineNode, PageSchema, GlobalDevBarOptions, DevBarControl, ThemeMode, };
13
+ export type { DevBarPosition, DevBarSettings, MetricsVisibility } from './settings.js';
14
+ export { ACCENT_COLOR_PRESETS, DEFAULT_SETTINGS, getSettingsManager } from './settings.js';
15
+ interface EarlyConsoleCapture {
16
+ errorCount: number;
17
+ warningCount: number;
18
+ logs: ConsoleLog[];
19
+ originalConsole: {
20
+ log: typeof console.log;
21
+ error: typeof console.error;
22
+ warn: typeof console.warn;
23
+ info: typeof console.info;
24
+ } | null;
25
+ isPatched: boolean;
26
+ }
27
+ declare const earlyConsoleCapture: EarlyConsoleCapture;
28
+ export declare class GlobalDevBar {
29
+ private static customControls;
30
+ private options;
31
+ private debugConfig;
32
+ private debug;
33
+ private container;
34
+ private ws;
35
+ private consoleLogs;
36
+ private sweetlinkConnected;
37
+ private collapsed;
38
+ private capturing;
39
+ private copiedToClipboard;
40
+ private copiedPath;
41
+ private lastScreenshot;
42
+ private designReviewInProgress;
43
+ private lastDesignReview;
44
+ private designReviewError;
45
+ private showDesignReviewConfirm;
46
+ private apiKeyStatus;
47
+ private lastOutline;
48
+ private lastSchema;
49
+ private savingOutline;
50
+ private savingSchema;
51
+ private consoleFilter;
52
+ private showOutlineModal;
53
+ private showSchemaModal;
54
+ private breakpointInfo;
55
+ private perfStats;
56
+ private lcpValue;
57
+ private clsValue;
58
+ private inpValue;
59
+ private reconnectAttempts;
60
+ private readonly currentAppPort;
61
+ private readonly baseWsPort;
62
+ private wsVerified;
63
+ private serverProjectDir;
64
+ private lastDotPosition;
65
+ private reconnectTimeout;
66
+ private screenshotTimeout;
67
+ private copiedPathTimeout;
68
+ private designReviewTimeout;
69
+ private designReviewErrorTimeout;
70
+ private outlineTimeout;
71
+ private schemaTimeout;
72
+ private resizeHandler;
73
+ private keydownHandler;
74
+ private fcpObserver;
75
+ private lcpObserver;
76
+ private clsObserver;
77
+ private inpObserver;
78
+ private destroyed;
79
+ private themeMode;
80
+ private themeMediaQuery;
81
+ private themeMediaHandler;
82
+ private compactMode;
83
+ private showSettingsPopover;
84
+ private overlayElement;
85
+ private settingsManager;
86
+ constructor(options?: GlobalDevBarOptions);
87
+ /**
88
+ * Get tooltip class name(s) if tooltips are enabled, otherwise empty string
89
+ */
90
+ private tooltipClass;
91
+ /**
92
+ * Get current error and warning counts from the log array
93
+ */
94
+ private getLogCounts;
95
+ /**
96
+ * Create a collapsed count badge (used for error/warning counts in minimized state)
97
+ */
98
+ private createCollapsedBadge;
99
+ /**
100
+ * Register a custom control to be displayed in the devbar
101
+ */
102
+ static registerControl(control: DevBarControl): void;
103
+ /**
104
+ * Unregister a custom control by ID
105
+ */
106
+ static unregisterControl(id: string): void;
107
+ /**
108
+ * Get all registered custom controls
109
+ */
110
+ static getControls(): DevBarControl[];
111
+ /**
112
+ * Clear all custom controls
113
+ */
114
+ static clearControls(): void;
115
+ /**
116
+ * Initialize and mount the devbar
117
+ */
118
+ init(): void;
119
+ /**
120
+ * Get the current position
121
+ */
122
+ getPosition(): string;
123
+ /**
124
+ * Destroy the devbar and cleanup
125
+ */
126
+ destroy(): void;
127
+ private injectStyles;
128
+ private connectWebSocket;
129
+ private handleSweetlinkCommand;
130
+ /**
131
+ * Handle settings loaded from server
132
+ */
133
+ private handleSettingsLoaded;
134
+ /**
135
+ * Apply settings to the DevBar state and options
136
+ */
137
+ private applySettings;
138
+ /**
139
+ * Handle notification state updates with auto-clear timeout
140
+ */
141
+ private handleNotification;
142
+ private setupBreakpointDetection;
143
+ private setupPerformanceMonitoring;
144
+ private setupKeyboardShortcuts;
145
+ private setupTheme;
146
+ private loadCompactMode;
147
+ /**
148
+ * Get the current theme mode
149
+ */
150
+ getThemeMode(): ThemeMode;
151
+ /**
152
+ * Set the theme mode
153
+ */
154
+ setThemeMode(mode: ThemeMode): void;
155
+ /**
156
+ * Get the current effective theme colors
157
+ */
158
+ getColors(): ReturnType<typeof getThemeColors>;
159
+ /**
160
+ * Toggle compact mode
161
+ */
162
+ toggleCompactMode(): void;
163
+ /**
164
+ * Check if compact mode is enabled
165
+ */
166
+ isCompactMode(): boolean;
167
+ private copyPathToClipboard;
168
+ private handleScreenshot;
169
+ private handleDesignReview;
170
+ /**
171
+ * Show the design review confirmation modal
172
+ * Checks API key status first
173
+ */
174
+ private showDesignReviewConfirmation;
175
+ /**
176
+ * Calculate estimated cost for design review based on viewport size
177
+ */
178
+ private calculateCostEstimate;
179
+ /**
180
+ * Close the design review confirmation modal
181
+ */
182
+ private closeDesignReviewConfirm;
183
+ /**
184
+ * Proceed with design review after confirmation
185
+ */
186
+ private proceedWithDesignReview;
187
+ private handleDocumentOutline;
188
+ private handlePageSchema;
189
+ private handleSaveOutline;
190
+ private handleSaveSchema;
191
+ private clearConsoleLogs;
192
+ private render;
193
+ private renderOverlays;
194
+ private renderDesignReviewConfirmModal;
195
+ /**
196
+ * Render content when API key is not configured
197
+ */
198
+ private renderApiKeyNotConfiguredContent;
199
+ /**
200
+ * Render content when API key is configured (cost estimate and model info)
201
+ */
202
+ private renderApiKeyConfiguredContent;
203
+ private renderConsolePopup;
204
+ /**
205
+ * Render console log items into a container
206
+ */
207
+ private renderConsoleLogs;
208
+ private renderOutlineModal;
209
+ /**
210
+ * Recursively render outline nodes into a container element
211
+ */
212
+ private renderOutlineNodes;
213
+ private renderSchemaModal;
214
+ /**
215
+ * Render a section of schema data (either array or key-value object)
216
+ */
217
+ private renderSchemaSection;
218
+ /**
219
+ * Render JSON-LD items as formatted code blocks with syntax highlighting
220
+ */
221
+ private renderJsonLdItems;
222
+ /**
223
+ * Append syntax-highlighted JSON to an element using safe DOM methods
224
+ * Uses textContent for all text to prevent XSS
225
+ */
226
+ private appendHighlightedJson;
227
+ /**
228
+ * Render key-value pairs as rows with ellipsis overflow and hover tooltip
229
+ */
230
+ private renderKeyValueItems;
231
+ /**
232
+ * Render compact mode - single row with essential controls only
233
+ * Shows: connection dot, error/warn badges, screenshot button, settings gear
234
+ */
235
+ private renderCompact;
236
+ /**
237
+ * Create the settings gear button
238
+ */
239
+ private createSettingsButton;
240
+ /**
241
+ * Create the compact mode toggle button with chevron icon
242
+ */
243
+ private createCompactToggleButton;
244
+ /**
245
+ * Create a settings section with title
246
+ */
247
+ private createSettingsSection;
248
+ /**
249
+ * Create a toggle switch row
250
+ */
251
+ private createToggleRow;
252
+ /**
253
+ * Render the settings popover
254
+ */
255
+ private renderSettingsPopover;
256
+ /**
257
+ * Reset all settings to defaults
258
+ */
259
+ private resetToDefaults;
260
+ private renderCollapsed;
261
+ private renderExpanded;
262
+ /** Base styles for tooltip containers */
263
+ private readonly TOOLTIP_BASE_STYLES;
264
+ /** Create a tooltip container element */
265
+ private createTooltipContainer;
266
+ /** Add a bold title to tooltip (metric name, feature name, etc.) */
267
+ private addTooltipTitle;
268
+ /** Add a description paragraph to tooltip */
269
+ private addTooltipDescription;
270
+ /** Add a muted uppercase section header to tooltip */
271
+ private addTooltipSectionHeader;
272
+ /** Add a colored row with dot + label + value (for thresholds) */
273
+ private addTooltipColoredRow;
274
+ /** Add an info row with label + value (for breakpoint details) */
275
+ private addTooltipInfoRow;
276
+ /** Position tooltip above the anchor element, adjusting for screen edges */
277
+ private positionTooltip;
278
+ /** Attach an HTML tooltip to an element with custom content builder */
279
+ private attachHtmlTooltip;
280
+ /** Attach a metric tooltip with title, description, and colored thresholds */
281
+ private attachMetricTooltip;
282
+ /** Attach a breakpoint tooltip showing current breakpoint and all breakpoint ranges */
283
+ private attachBreakpointTooltip;
284
+ /** Attach a simple info tooltip with title and description */
285
+ private attachInfoTooltip;
286
+ /**
287
+ * Create a console badge for error/warning counts
288
+ */
289
+ private createConsoleBadge;
290
+ private createScreenshotButton;
291
+ /**
292
+ * Get the tooltip text for the screenshot button based on current state
293
+ */
294
+ private getScreenshotTooltip;
295
+ /**
296
+ * Get the tooltip text for the AI review button based on current state
297
+ */
298
+ private getAIReviewTooltip;
299
+ private createAIReviewButton;
300
+ private createOutlineButton;
301
+ private createSchemaButton;
302
+ }
303
+ /**
304
+ * Initialize and mount the GlobalDevBar
305
+ *
306
+ * HMR-safe: Uses window-based global that survives module reloads.
307
+ * If an instance already exists, it will be destroyed and recreated.
308
+ */
309
+ export declare function initGlobalDevBar(options?: GlobalDevBarOptions): GlobalDevBar;
310
+ /**
311
+ * Get the current GlobalDevBar instance
312
+ */
313
+ export declare function getGlobalDevBar(): GlobalDevBar | null;
314
+ /**
315
+ * Destroy the GlobalDevBar
316
+ */
317
+ export declare function destroyGlobalDevBar(): void;
318
+ export { earlyConsoleCapture };