@ytspar/devbar 1.0.0-canary.cdf7fa2 → 1.0.0-canary.deff6e9

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 (122) hide show
  1. package/README.md +4 -0
  2. package/dist/GlobalDevBar.d.ts +111 -197
  3. package/dist/GlobalDevBar.d.ts.map +1 -0
  4. package/dist/GlobalDevBar.js +165 -2657
  5. package/dist/GlobalDevBar.js.map +1 -0
  6. package/dist/accessibility.d.ts +1 -0
  7. package/dist/accessibility.d.ts.map +1 -0
  8. package/dist/accessibility.js +1 -0
  9. package/dist/accessibility.js.map +1 -0
  10. package/dist/constants.d.ts +44 -12
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/constants.js +104 -121
  13. package/dist/constants.js.map +1 -0
  14. package/dist/debug.d.ts +4 -3
  15. package/dist/debug.d.ts.map +1 -0
  16. package/dist/debug.js +6 -4
  17. package/dist/debug.js.map +1 -0
  18. package/dist/earlyConsoleCapture.d.ts +4 -31
  19. package/dist/earlyConsoleCapture.d.ts.map +1 -0
  20. package/dist/earlyConsoleCapture.js +4 -74
  21. package/dist/earlyConsoleCapture.js.map +1 -0
  22. package/dist/index.d.ts +3 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +6 -1
  25. package/dist/index.js.map +1 -0
  26. package/dist/lazy/index.d.ts +1 -0
  27. package/dist/lazy/index.d.ts.map +1 -0
  28. package/dist/lazy/index.js +1 -0
  29. package/dist/lazy/index.js.map +1 -0
  30. package/dist/lazy/lazyHtml2Canvas.d.ts +5 -0
  31. package/dist/lazy/lazyHtml2Canvas.d.ts.map +1 -0
  32. package/dist/lazy/lazyHtml2Canvas.js +1 -0
  33. package/dist/lazy/lazyHtml2Canvas.js.map +1 -0
  34. package/dist/modules/index.d.ts +15 -0
  35. package/dist/modules/index.d.ts.map +1 -0
  36. package/dist/modules/index.js +14 -0
  37. package/dist/modules/index.js.map +1 -0
  38. package/dist/modules/keyboard.d.ts +15 -0
  39. package/dist/modules/keyboard.d.ts.map +1 -0
  40. package/dist/modules/keyboard.js +60 -0
  41. package/dist/modules/keyboard.js.map +1 -0
  42. package/dist/modules/performance.d.ts +26 -0
  43. package/dist/modules/performance.d.ts.map +1 -0
  44. package/dist/modules/performance.js +197 -0
  45. package/dist/modules/performance.js.map +1 -0
  46. package/dist/modules/rendering.d.ts +20 -0
  47. package/dist/modules/rendering.d.ts.map +1 -0
  48. package/dist/modules/rendering.js +1947 -0
  49. package/dist/modules/rendering.js.map +1 -0
  50. package/dist/modules/screenshot.d.ts +62 -0
  51. package/dist/modules/screenshot.d.ts.map +1 -0
  52. package/dist/modules/screenshot.js +325 -0
  53. package/dist/modules/screenshot.js.map +1 -0
  54. package/dist/modules/theme.d.ts +20 -0
  55. package/dist/modules/theme.d.ts.map +1 -0
  56. package/dist/modules/theme.js +60 -0
  57. package/dist/modules/theme.js.map +1 -0
  58. package/dist/modules/tooltips.d.ts +74 -0
  59. package/dist/modules/tooltips.d.ts.map +1 -0
  60. package/dist/modules/tooltips.js +553 -0
  61. package/dist/modules/tooltips.js.map +1 -0
  62. package/dist/modules/types.d.ts +118 -0
  63. package/dist/modules/types.d.ts.map +1 -0
  64. package/dist/modules/types.js +9 -0
  65. package/dist/modules/types.js.map +1 -0
  66. package/dist/modules/websocket.d.ts +16 -0
  67. package/dist/modules/websocket.d.ts.map +1 -0
  68. package/dist/modules/websocket.js +314 -0
  69. package/dist/modules/websocket.js.map +1 -0
  70. package/dist/network.d.ts +1 -0
  71. package/dist/network.d.ts.map +1 -0
  72. package/dist/network.js +5 -6
  73. package/dist/network.js.map +1 -0
  74. package/dist/outline.d.ts +1 -0
  75. package/dist/outline.d.ts.map +1 -0
  76. package/dist/outline.js +1 -0
  77. package/dist/outline.js.map +1 -0
  78. package/dist/presets.d.ts +9 -8
  79. package/dist/presets.d.ts.map +1 -0
  80. package/dist/presets.js +9 -8
  81. package/dist/presets.js.map +1 -0
  82. package/dist/schema.d.ts +1 -0
  83. package/dist/schema.d.ts.map +1 -0
  84. package/dist/schema.js +3 -3
  85. package/dist/schema.js.map +1 -0
  86. package/dist/settings.d.ts +7 -8
  87. package/dist/settings.d.ts.map +1 -0
  88. package/dist/settings.js +21 -17
  89. package/dist/settings.js.map +1 -0
  90. package/dist/storage.d.ts +1 -0
  91. package/dist/storage.d.ts.map +1 -0
  92. package/dist/storage.js +1 -0
  93. package/dist/storage.js.map +1 -0
  94. package/dist/types.d.ts +5 -4
  95. package/dist/types.d.ts.map +1 -0
  96. package/dist/types.js +3 -2
  97. package/dist/types.js.map +1 -0
  98. package/dist/ui/buttons.d.ts +3 -2
  99. package/dist/ui/buttons.d.ts.map +1 -0
  100. package/dist/ui/buttons.js +3 -2
  101. package/dist/ui/buttons.js.map +1 -0
  102. package/dist/ui/cards.d.ts +37 -0
  103. package/dist/ui/cards.d.ts.map +1 -0
  104. package/dist/ui/cards.js +134 -0
  105. package/dist/ui/cards.js.map +1 -0
  106. package/dist/ui/icons.d.ts +71 -2
  107. package/dist/ui/icons.d.ts.map +1 -0
  108. package/dist/ui/icons.js +148 -2
  109. package/dist/ui/icons.js.map +1 -0
  110. package/dist/ui/index.d.ts +3 -1
  111. package/dist/ui/index.d.ts.map +1 -0
  112. package/dist/ui/index.js +3 -1
  113. package/dist/ui/index.js.map +1 -0
  114. package/dist/ui/modals.d.ts +7 -2
  115. package/dist/ui/modals.d.ts.map +1 -0
  116. package/dist/ui/modals.js +51 -6
  117. package/dist/ui/modals.js.map +1 -0
  118. package/dist/utils.d.ts +3 -2
  119. package/dist/utils.d.ts.map +1 -0
  120. package/dist/utils.js +3 -2
  121. package/dist/utils.js.map +1 -0
  122. package/package.json +17 -14
@@ -4,137 +4,134 @@
4
4
  * A development toolbar that displays breakpoint info, performance stats,
5
5
  * console error/warning counts, and provides screenshot capabilities via Sweetlink.
6
6
  *
7
- * This is a vanilla JS replacement for the React-based GlobalDevBar component
8
- * to avoid React dependency conflicts in host applications.
7
+ * Framework-agnostic no React, Vue, or other framework dependencies.
8
+ *
9
+ * Implementation is split across focused modules in ./modules/:
10
+ * - websocket.ts — WebSocket connection, reconnection, port scanning, message handling
11
+ * - screenshot.ts — Screenshot capture, design review, clipboard operations
12
+ * - rendering.ts — renderBar(), renderConsolePopup(), renderModal(), all DOM creation
13
+ * - performance.ts — setupPerformanceMonitoring(), FCP/LCP/CLS/INP observers
14
+ * - theme.ts — setupTheme(), toggleTheme(), theme media query handling
15
+ * - keyboard.ts — setupKeyboardShortcuts(), handleKeydown()
16
+ * - tooltips.ts — tooltip creation, positioning, and management helpers
9
17
  */
10
- import * as html2canvasModule from 'html2canvas-pro';
11
- import { BASE_RECONNECT_DELAY_MS, BUTTON_COLORS, CATEGORY_COLORS, CLIPBOARD_NOTIFICATION_MS, COLORS, DESIGN_REVIEW_NOTIFICATION_MS, DEVBAR_SCREENSHOT_QUALITY, FONT_MONO, getEffectiveTheme, getThemeColors, MAX_CONSOLE_LOGS, MAX_RECONNECT_ATTEMPTS, MAX_RECONNECT_DELAY_MS, SCREENSHOT_BLUR_DELAY_MS, SCREENSHOT_NOTIFICATION_MS, SCREENSHOT_SCALE, TAILWIND_BREAKPOINTS, TOOLTIP_STYLES, WS_PORT, } from './constants.js';
18
+ import { CSS_COLORS, DEVBAR_STYLES, getThemeColors, MAX_RECONNECT_ATTEMPTS, WS_PORT, WS_PORT_OFFSET, } from './constants.js';
12
19
  import { DebugLogger, normalizeDebugConfig } from './debug.js';
13
- import { extractDocumentOutline, outlineToMarkdown } from './outline.js';
14
- import { extractPageSchema, schemaToMarkdown } from './schema.js';
15
- import { ACCENT_COLOR_PRESETS, DEFAULT_SETTINGS, getSettingsManager, } from './settings.js';
16
- import { createEmptyMessage, createInfoBox, createModalBox, createModalContent, createModalHeader, createModalOverlay, createStyledButton, createSvgIcon, getButtonStyles, } from './ui/index.js';
17
- import { canvasToDataUrl, copyCanvasToClipboard, delay, formatArgs, prepareForCapture, } from './utils.js';
20
+ import { getSettingsManager, } from './settings.js';
21
+ import { ConsoleCapture } from '@ytspar/sweetlink/browser/consoleCapture';
22
+ // Import module functions
23
+ import { connectWebSocket, handleNotification } from './modules/websocket.js';
24
+ import { handleScreenshot as moduleHandleScreenshot } from './modules/screenshot.js';
25
+ import { render as moduleRender } from './modules/rendering.js';
26
+ import { setupBreakpointDetection, setupPerformanceMonitoring, } from './modules/performance.js';
27
+ import { setupKeyboardShortcuts } from './modules/keyboard.js';
28
+ import { setupTheme, loadCompactMode, setThemeMode as moduleSetThemeMode, } from './modules/theme.js';
18
29
  export { ACCENT_COLOR_PRESETS, DEFAULT_SETTINGS, getSettingsManager } from './settings.js';
19
- const html2canvas = (html2canvasModule.default ??
20
- html2canvasModule);
21
- const earlyConsoleCapture = (() => {
22
- const ssrFallback = {
23
- errorCount: 0,
24
- warningCount: 0,
25
- logs: [],
26
- originalConsole: null,
27
- isPatched: false,
28
- };
29
- // Skip on server-side rendering
30
- if (typeof window === 'undefined')
31
- return ssrFallback;
32
- const capture = {
33
- errorCount: 0,
34
- warningCount: 0,
35
- logs: [],
36
- originalConsole: {
37
- log: console.log,
38
- error: console.error,
39
- warn: console.warn,
40
- info: console.info,
41
- },
42
- isPatched: false,
43
- };
44
- const captureLog = (level, args) => {
45
- capture.logs.push({ level, message: formatArgs(args), timestamp: Date.now() });
46
- if (capture.logs.length > MAX_CONSOLE_LOGS)
47
- capture.logs = capture.logs.slice(-MAX_CONSOLE_LOGS);
48
- };
49
- // Patch console immediately
50
- if (!capture.isPatched && capture.originalConsole) {
51
- console.log = (...args) => {
52
- captureLog('log', args);
53
- capture.originalConsole.log(...args);
54
- };
55
- console.error = (...args) => {
56
- captureLog('error', args);
57
- capture.errorCount++;
58
- capture.originalConsole.error(...args);
59
- };
60
- console.warn = (...args) => {
61
- captureLog('warn', args);
62
- capture.warningCount++;
63
- capture.originalConsole.warn(...args);
64
- };
65
- console.info = (...args) => {
66
- captureLog('info', args);
67
- capture.originalConsole.info(...args);
68
- };
69
- capture.isPatched = true;
70
- }
71
- return capture;
72
- })();
30
+ // html2canvas is lazy-loaded via getHtml2Canvas() to avoid bundling ~400KB upfront
31
+ // ============================================================================
32
+ // Console Capture (single implementation from @ytspar/sweetlink)
33
+ // ============================================================================
34
+ const consoleCapture = new ConsoleCapture({ trackCounts: true });
35
+ consoleCapture.importEarlyLogs();
36
+ consoleCapture.start();
73
37
  // ============================================================================
74
38
  // GlobalDevBar Class
75
39
  // ============================================================================
76
40
  export class GlobalDevBar {
41
+ // Static storage for custom controls
42
+ static customControls = [];
43
+ // -- Public state exposed via DevBarState interface for modules --
44
+ options;
45
+ debugConfig;
46
+ debug;
47
+ container = null;
48
+ ws = null;
49
+ consoleLogs = [];
50
+ sweetlinkConnected = false;
51
+ collapsed = false;
52
+ capturing = false;
53
+ copiedToClipboard = false;
54
+ copiedPath = false;
55
+ lastScreenshot = null;
56
+ designReviewInProgress = false;
57
+ lastDesignReview = null;
58
+ designReviewError = null;
59
+ showDesignReviewConfirm = false;
60
+ apiKeyStatus = null;
61
+ lastOutline = null;
62
+ lastSchema = null;
63
+ savingOutline = false;
64
+ savingSchema = false;
65
+ consoleFilter = null;
66
+ savingConsoleLogs = false;
67
+ lastConsoleLogs = null;
68
+ consoleLogsTimeout;
69
+ // Modal states
70
+ showOutlineModal = false;
71
+ showSchemaModal = false;
72
+ // Track active HTML tooltips for cleanup on re-render
73
+ activeTooltips = new Set();
74
+ breakpointInfo = null;
75
+ perfStats = null;
76
+ lcpValue = null;
77
+ clsValue = 0;
78
+ inpValue = 0;
79
+ reconnectAttempts = 0;
80
+ // Port scanning state for multi-instance support
81
+ currentAppPort;
82
+ baseWsPort;
83
+ wsVerified = false;
84
+ serverProjectDir = null;
85
+ // Track the position of the connection indicator dot for smooth collapse
86
+ lastDotPosition = null;
87
+ reconnectTimeout = null;
88
+ screenshotTimeout = null;
89
+ copiedPathTimeout = null;
90
+ designReviewTimeout = null;
91
+ designReviewErrorTimeout = null;
92
+ outlineTimeout = null;
93
+ schemaTimeout = null;
94
+ resizeHandler = null;
95
+ keydownHandler = null;
96
+ fcpObserver = null;
97
+ lcpObserver = null;
98
+ clsObserver = null;
99
+ inpObserver = null;
100
+ destroyed = false;
101
+ // Theme state
102
+ themeMode = 'system';
103
+ themeMediaQuery = null;
104
+ themeMediaHandler = null;
105
+ // Compact mode state
106
+ compactMode = false;
107
+ // Settings popover state
108
+ showSettingsPopover = false;
109
+ // Overlay element for modals
110
+ overlayElement = null;
111
+ // Settings manager for persistence
112
+ settingsManager;
113
+ // Console log listener for real-time badge updates
114
+ logChangeListener = null;
77
115
  constructor(options = {}) {
78
- this.container = null;
79
- this.ws = null;
80
- this.consoleLogs = [];
81
- this.sweetlinkConnected = false;
82
- this.collapsed = false;
83
- this.capturing = false;
84
- this.copiedToClipboard = false;
85
- this.copiedPath = false;
86
- this.lastScreenshot = null;
87
- this.designReviewInProgress = false;
88
- this.lastDesignReview = null;
89
- this.designReviewError = null;
90
- this.showDesignReviewConfirm = false;
91
- this.apiKeyStatus = null;
92
- this.lastOutline = null;
93
- this.lastSchema = null;
94
- this.consoleFilter = null;
95
- // Modal states
96
- this.showOutlineModal = false;
97
- this.showSchemaModal = false;
98
- this.breakpointInfo = null;
99
- this.perfStats = null;
100
- this.lcpValue = null;
101
- this.clsValue = 0;
102
- this.inpValue = 0;
103
- this.reconnectAttempts = 0;
104
- // Track the position of the connection indicator dot for smooth collapse
105
- this.lastDotPosition = null;
106
- this.reconnectTimeout = null;
107
- this.screenshotTimeout = null;
108
- this.copiedPathTimeout = null;
109
- this.designReviewTimeout = null;
110
- this.designReviewErrorTimeout = null;
111
- this.outlineTimeout = null;
112
- this.schemaTimeout = null;
113
- this.resizeHandler = null;
114
- this.keydownHandler = null;
115
- this.fcpObserver = null;
116
- this.lcpObserver = null;
117
- this.clsObserver = null;
118
- this.inpObserver = null;
119
- this.destroyed = false;
120
- // Theme state
121
- this.themeMode = 'system';
122
- this.themeMediaQuery = null;
123
- this.themeMediaHandler = null;
124
- // Compact mode state
125
- this.compactMode = false;
126
- // Settings popover state
127
- this.showSettingsPopover = false;
128
- // Overlay element for modals
129
- this.overlayElement = null;
130
116
  // Initialize debug config first so we can log during construction
131
117
  this.debugConfig = normalizeDebugConfig(options.debug);
132
118
  this.debug = new DebugLogger(this.debugConfig);
133
119
  // Initialize settings manager
134
120
  this.settingsManager = getSettingsManager();
121
+ // Calculate app port from URL for multi-instance support
122
+ if (typeof window !== 'undefined') {
123
+ this.currentAppPort =
124
+ parseInt(window.location.port, 10) || (window.location.protocol === 'https:' ? 443 : 80);
125
+ // Calculate expected WS port (appPort + port offset) like SweetlinkBridge does
126
+ this.baseWsPort = this.currentAppPort > 0 ? this.currentAppPort + WS_PORT_OFFSET : WS_PORT;
127
+ }
128
+ else {
129
+ this.currentAppPort = 0;
130
+ this.baseWsPort = WS_PORT;
131
+ }
135
132
  this.options = {
136
133
  position: options.position ?? 'bottom-left',
137
- accentColor: options.accentColor ?? COLORS.primary,
134
+ accentColor: options.accentColor ?? CSS_COLORS.primary,
138
135
  showMetrics: {
139
136
  breakpoint: options.showMetrics?.breakpoint ?? true,
140
137
  fcp: options.showMetrics?.fcp ?? true,
@@ -151,28 +148,20 @@ export class GlobalDevBar {
151
148
  this.debug.lifecycle('GlobalDevBar constructed', { options: this.options });
152
149
  }
153
150
  /**
154
- * Get tooltip class name(s) if tooltips are enabled, otherwise empty string
151
+ * Get current error, warning, and info counts from the log array
155
152
  */
156
- tooltipClass(direction = 'left', ...additionalClasses) {
157
- if (!this.options.showTooltips) {
158
- return additionalClasses.join(' ');
159
- }
160
- return ['devbar-tooltip', `devbar-tooltip-${direction}`, ...additionalClasses].join(' ');
153
+ getLogCounts() {
154
+ return {
155
+ errorCount: consoleCapture.getErrorCount(),
156
+ warningCount: consoleCapture.getWarningCount(),
157
+ infoCount: consoleCapture.getInfoCount(),
158
+ };
161
159
  }
162
160
  /**
163
- * Get current error and warning counts from the log array
161
+ * Reset position style properties on an element to clear stale values
164
162
  */
165
- getLogCounts() {
166
- const logs = earlyConsoleCapture.logs;
167
- let errorCount = 0;
168
- let warningCount = 0;
169
- for (const log of logs) {
170
- if (log.level === 'error')
171
- errorCount++;
172
- else if (log.level === 'warn')
173
- warningCount++;
174
- }
175
- return { errorCount, warningCount };
163
+ resetPositionStyles(element) {
164
+ Object.assign(element.style, { top: '', bottom: '', left: '', right: '', transform: '' });
176
165
  }
177
166
  /**
178
167
  * Create a collapsed count badge (used for error/warning counts in minimized state)
@@ -250,23 +239,29 @@ export class GlobalDevBar {
250
239
  if (this.destroyed)
251
240
  return;
252
241
  this.debug.lifecycle('Initializing DevBar');
253
- // Inject tooltip styles
242
+ // Inject animation and utility CSS
254
243
  this.injectStyles();
255
- // Copy early captured logs
256
- this.consoleLogs = [...earlyConsoleCapture.logs];
257
- this.debug.lifecycle('Copied early console logs', { count: this.consoleLogs.length });
244
+ // Copy captured logs
245
+ this.consoleLogs = consoleCapture.getLogs();
246
+ this.debug.lifecycle('Copied console logs', { count: this.consoleLogs.length });
247
+ // Subscribe to log changes for real-time badge updates
248
+ this.logChangeListener = () => {
249
+ this.consoleLogs = consoleCapture.getLogs();
250
+ this.render();
251
+ };
252
+ consoleCapture.addListener(this.logChangeListener);
258
253
  // Setup theme
259
- this.setupTheme();
254
+ setupTheme(this);
260
255
  // Load compact mode from storage
261
- this.loadCompactMode();
256
+ loadCompactMode(this);
262
257
  // Setup WebSocket connection
263
258
  this.connectWebSocket();
264
259
  // Setup breakpoint detection
265
- this.setupBreakpointDetection();
260
+ setupBreakpointDetection(this);
266
261
  // Setup performance monitoring
267
- this.setupPerformanceMonitoring();
262
+ setupPerformanceMonitoring(this);
268
263
  // Setup keyboard shortcuts
269
- this.setupKeyboardShortcuts();
264
+ setupKeyboardShortcuts(this);
270
265
  // Initial render
271
266
  this.render();
272
267
  this.debug.lifecycle('DevBar initialized successfully');
@@ -300,6 +295,8 @@ export class GlobalDevBar {
300
295
  clearTimeout(this.outlineTimeout);
301
296
  if (this.schemaTimeout)
302
297
  clearTimeout(this.schemaTimeout);
298
+ if (this.consoleLogsTimeout)
299
+ clearTimeout(this.consoleLogsTimeout);
303
300
  // Remove event listeners
304
301
  if (this.resizeHandler)
305
302
  window.removeEventListener('resize', this.resizeHandler);
@@ -318,13 +315,13 @@ export class GlobalDevBar {
318
315
  if (this.themeMediaQuery && this.themeMediaHandler) {
319
316
  this.themeMediaQuery.removeEventListener('change', this.themeMediaHandler);
320
317
  }
321
- // Restore console
322
- if (earlyConsoleCapture.originalConsole) {
323
- console.log = earlyConsoleCapture.originalConsole.log;
324
- console.error = earlyConsoleCapture.originalConsole.error;
325
- console.warn = earlyConsoleCapture.originalConsole.warn;
326
- console.info = earlyConsoleCapture.originalConsole.info;
318
+ // Remove log change listener
319
+ if (this.logChangeListener) {
320
+ consoleCapture.removeListener(this.logChangeListener);
321
+ this.logChangeListener = null;
327
322
  }
323
+ // Restore console
324
+ consoleCapture.stop();
328
325
  // Remove DOM elements
329
326
  if (this.container) {
330
327
  this.container.remove();
@@ -337,203 +334,20 @@ export class GlobalDevBar {
337
334
  this.debug.lifecycle('DevBar destroyed');
338
335
  }
339
336
  injectStyles() {
340
- const styleId = 'devbar-tooltip-styles';
337
+ const styleId = 'devbar-styles';
341
338
  if (!document.getElementById(styleId)) {
342
339
  const style = document.createElement('style');
343
340
  style.id = styleId;
344
- style.textContent = TOOLTIP_STYLES;
341
+ style.textContent = DEVBAR_STYLES;
345
342
  document.head.appendChild(style);
346
343
  }
347
344
  }
348
- connectWebSocket() {
349
- if (this.destroyed)
350
- return;
351
- this.debug.ws('Connecting to WebSocket', { port: WS_PORT });
352
- const ws = new WebSocket(`ws://localhost:${WS_PORT}`);
353
- this.ws = ws;
354
- ws.onopen = () => {
355
- this.sweetlinkConnected = true;
356
- this.reconnectAttempts = 0;
357
- this.debug.ws('WebSocket connected');
358
- // Update settings manager with WebSocket connection
359
- this.settingsManager.setWebSocket(ws);
360
- this.settingsManager.setConnected(true);
361
- ws.send(JSON.stringify({ type: 'browser-client-ready' }));
362
- // Request settings from server
363
- ws.send(JSON.stringify({ type: 'load-settings' }));
364
- this.render();
365
- };
366
- ws.onmessage = async (event) => {
367
- try {
368
- const command = JSON.parse(event.data);
369
- this.debug.ws('Received command', { type: command.type });
370
- await this.handleSweetlinkCommand(command);
371
- }
372
- catch (e) {
373
- console.error('[GlobalDevBar] Error handling command:', e);
374
- }
375
- };
376
- ws.onclose = () => {
377
- this.sweetlinkConnected = false;
378
- this.settingsManager.setConnected(false);
379
- this.debug.ws('WebSocket disconnected');
380
- this.render();
381
- // Auto-reconnect with exponential backoff
382
- if (!this.destroyed && this.reconnectAttempts < MAX_RECONNECT_ATTEMPTS) {
383
- const delayMs = BASE_RECONNECT_DELAY_MS * 2 ** this.reconnectAttempts;
384
- this.reconnectAttempts++;
385
- this.debug.ws('Scheduling reconnect', { attempt: this.reconnectAttempts, delayMs });
386
- this.reconnectTimeout = setTimeout(() => this.connectWebSocket(), Math.min(delayMs, MAX_RECONNECT_DELAY_MS));
387
- }
388
- };
389
- ws.onerror = () => {
390
- // Error will trigger onclose, which handles reconnection
391
- this.debug.ws('WebSocket error');
392
- };
393
- }
394
- async handleSweetlinkCommand(command) {
395
- const ws = this.ws;
396
- if (!ws || ws.readyState !== WebSocket.OPEN)
397
- return;
398
- switch (command.type) {
399
- case 'screenshot': {
400
- const targetElement = command.selector
401
- ? document.querySelector(command.selector) || document.body
402
- : document.body;
403
- const canvas = await html2canvas(targetElement, {
404
- logging: false,
405
- useCORS: true,
406
- allowTaint: true,
407
- });
408
- ws.send(JSON.stringify({
409
- success: true,
410
- data: {
411
- screenshot: canvas.toDataURL('image/png'),
412
- width: canvas.width,
413
- height: canvas.height,
414
- selector: command.selector || 'body',
415
- },
416
- timestamp: Date.now(),
417
- }));
418
- break;
419
- }
420
- case 'get-logs': {
421
- let logs = this.consoleLogs;
422
- if (command.filter) {
423
- const filter = command.filter.toLowerCase();
424
- logs = logs.filter((log) => log.level.includes(filter) || log.message.toLowerCase().includes(filter));
425
- }
426
- ws.send(JSON.stringify({ success: true, data: logs, timestamp: Date.now() }));
427
- break;
428
- }
429
- case 'query-dom': {
430
- if (command.selector) {
431
- const elements = Array.from(document.querySelectorAll(command.selector));
432
- const results = elements.map((el) => {
433
- if (command.property)
434
- return el[command.property] ?? null;
435
- return {
436
- tagName: el.tagName,
437
- className: el.className,
438
- id: el.id,
439
- textContent: el.textContent?.trim().slice(0, 100),
440
- };
441
- });
442
- ws.send(JSON.stringify({
443
- success: true,
444
- data: { count: results.length, results },
445
- timestamp: Date.now(),
446
- }));
447
- }
448
- break;
449
- }
450
- case 'exec-js': {
451
- if (command.code) {
452
- try {
453
- // Use indirect eval to avoid strict mode issues
454
- const indirectEval = eval;
455
- const result = indirectEval(command.code);
456
- ws.send(JSON.stringify({ success: true, data: result, timestamp: Date.now() }));
457
- }
458
- catch (e) {
459
- ws.send(JSON.stringify({
460
- success: false,
461
- error: e instanceof Error ? e.message : 'Execution failed',
462
- timestamp: Date.now(),
463
- }));
464
- }
465
- }
466
- break;
467
- }
468
- case 'screenshot-saved':
469
- this.handleNotification('screenshot', command.path, SCREENSHOT_NOTIFICATION_MS);
470
- break;
471
- case 'design-review-saved':
472
- this.designReviewInProgress = false;
473
- this.handleNotification('designReview', command.reviewPath, DESIGN_REVIEW_NOTIFICATION_MS);
474
- break;
475
- case 'design-review-error':
476
- this.designReviewInProgress = false;
477
- this.designReviewError = command.error || 'Unknown error';
478
- console.error('[GlobalDevBar] Design review failed:', command.error);
479
- // Clear error after notification duration
480
- if (this.designReviewErrorTimeout)
481
- clearTimeout(this.designReviewErrorTimeout);
482
- this.designReviewErrorTimeout = setTimeout(() => {
483
- this.designReviewError = null;
484
- this.render();
485
- }, DESIGN_REVIEW_NOTIFICATION_MS);
486
- this.render();
487
- break;
488
- case 'api-key-status': {
489
- // Properties are at top level of the response
490
- const response = command;
491
- this.apiKeyStatus = {
492
- configured: response.configured ?? false,
493
- maskedKey: response.maskedKey,
494
- model: response.model,
495
- pricing: response.pricing,
496
- };
497
- // Re-render to update the confirmation modal
498
- this.render();
499
- break;
500
- }
501
- case 'outline-saved':
502
- this.handleNotification('outline', command.outlinePath, SCREENSHOT_NOTIFICATION_MS);
503
- break;
504
- case 'outline-error':
505
- console.error('[GlobalDevBar] Outline save failed:', command.error);
506
- break;
507
- case 'schema-saved':
508
- this.handleNotification('schema', command.schemaPath, SCREENSHOT_NOTIFICATION_MS);
509
- break;
510
- case 'schema-error':
511
- console.error('[GlobalDevBar] Schema save failed:', command.error);
512
- break;
513
- case 'settings-loaded':
514
- this.handleSettingsLoaded(command.settings);
515
- break;
516
- case 'settings-saved':
517
- this.debug.state('Settings saved to server', { path: command.settingsPath });
518
- break;
519
- case 'settings-error':
520
- console.error('[GlobalDevBar] Settings operation failed:', command.error);
521
- break;
522
- }
345
+ // Delegate to module functions, binding `this` as state
346
+ connectWebSocket(port) {
347
+ connectWebSocket(this, port);
523
348
  }
524
- /**
525
- * Handle settings loaded from server
526
- */
527
- handleSettingsLoaded(settings) {
528
- if (!settings) {
529
- this.debug.state('No server settings found, using local');
530
- return;
531
- }
532
- this.debug.state('Settings loaded from server', settings);
533
- // Update settings manager
534
- this.settingsManager.handleSettingsLoaded(settings);
535
- // Apply settings to local state
536
- this.applySettings(settings);
349
+ handleNotification(type, path, durationMs) {
350
+ handleNotification(this, type, path, durationMs);
537
351
  }
538
352
  /**
539
353
  * Apply settings to the DevBar state and options
@@ -552,254 +366,14 @@ export class GlobalDevBar {
552
366
  // Re-render with new settings
553
367
  this.render();
554
368
  }
555
- /**
556
- * Handle notification state updates with auto-clear timeout
557
- */
558
- handleNotification(type, path, durationMs) {
559
- if (!path)
560
- return;
561
- // Update the appropriate state
562
- switch (type) {
563
- case 'screenshot':
564
- this.lastScreenshot = path;
565
- if (this.screenshotTimeout)
566
- clearTimeout(this.screenshotTimeout);
567
- this.screenshotTimeout = setTimeout(() => {
568
- this.lastScreenshot = null;
569
- this.render();
570
- }, durationMs);
571
- break;
572
- case 'designReview':
573
- this.lastDesignReview = path;
574
- if (this.designReviewTimeout)
575
- clearTimeout(this.designReviewTimeout);
576
- this.designReviewTimeout = setTimeout(() => {
577
- this.lastDesignReview = null;
578
- this.render();
579
- }, durationMs);
580
- break;
581
- case 'outline':
582
- this.lastOutline = path;
583
- if (this.outlineTimeout)
584
- clearTimeout(this.outlineTimeout);
585
- this.outlineTimeout = setTimeout(() => {
586
- this.lastOutline = null;
587
- this.render();
588
- }, durationMs);
589
- break;
590
- case 'schema':
591
- this.lastSchema = path;
592
- if (this.schemaTimeout)
593
- clearTimeout(this.schemaTimeout);
594
- this.schemaTimeout = setTimeout(() => {
595
- this.lastSchema = null;
596
- this.render();
597
- }, durationMs);
598
- break;
599
- }
369
+ clearConsoleLogs() {
370
+ consoleCapture.clear();
371
+ this.consoleLogs = [];
372
+ this.consoleFilter = null;
600
373
  this.render();
601
374
  }
602
- setupBreakpointDetection() {
603
- const updateBreakpointInfo = () => {
604
- const width = window.innerWidth;
605
- const height = window.innerHeight;
606
- // Determine breakpoint by checking thresholds in descending order
607
- const breakpointOrder = [
608
- '2xl',
609
- 'xl',
610
- 'lg',
611
- 'md',
612
- 'sm',
613
- ];
614
- const tailwindBreakpoint = breakpointOrder.find((bp) => width >= TAILWIND_BREAKPOINTS[bp].min) ?? 'base';
615
- this.breakpointInfo = {
616
- tailwindBreakpoint,
617
- dimensions: `${width}x${height}`,
618
- };
619
- this.render();
620
- };
621
- updateBreakpointInfo();
622
- this.resizeHandler = updateBreakpointInfo;
623
- window.addEventListener('resize', this.resizeHandler);
624
- }
625
- setupPerformanceMonitoring() {
626
- const updatePerfStats = () => {
627
- // FCP
628
- const paintEntries = performance.getEntriesByType('paint');
629
- const fcpEntry = paintEntries.find((entry) => entry.name === 'first-contentful-paint');
630
- const fcp = fcpEntry ? `${Math.round(fcpEntry.startTime)}ms` : '-';
631
- // LCP (from cached value, updated by observer)
632
- const lcp = this.lcpValue !== null ? `${Math.round(this.lcpValue)}ms` : '-';
633
- // CLS (cumulative layout shift)
634
- const cls = this.clsValue > 0 ? this.clsValue.toFixed(3) : '-';
635
- // INP (Interaction to Next Paint)
636
- const inp = this.inpValue > 0 ? `${Math.round(this.inpValue)}ms` : '-';
637
- // Total Resource Size
638
- const resources = performance.getEntriesByType('resource');
639
- let totalBytes = 0;
640
- const navEntry = performance.getEntriesByType('navigation')[0];
641
- if (navEntry) {
642
- totalBytes += navEntry.transferSize || 0;
643
- }
644
- resources.forEach((entry) => {
645
- const resourceEntry = entry;
646
- totalBytes += resourceEntry.transferSize || 0;
647
- });
648
- const totalSize = totalBytes > 1024 * 1024
649
- ? `${(totalBytes / (1024 * 1024)).toFixed(1)} MB`
650
- : `${Math.round(totalBytes / 1024)} KB`;
651
- this.perfStats = { fcp, lcp, cls, inp, totalSize };
652
- this.debug.perf('Performance stats updated', this.perfStats);
653
- this.render();
654
- };
655
- if (document.readyState === 'complete') {
656
- setTimeout(updatePerfStats, 100);
657
- }
658
- else {
659
- window.addEventListener('load', () => setTimeout(updatePerfStats, 100));
660
- }
661
- // FCP Observer
662
- try {
663
- this.fcpObserver = new PerformanceObserver((list) => {
664
- const entries = list.getEntries();
665
- entries.forEach((entry) => {
666
- if (entry.name === 'first-contentful-paint') {
667
- updatePerfStats();
668
- }
669
- });
670
- });
671
- this.fcpObserver.observe({ type: 'paint', buffered: true });
672
- }
673
- catch (e) {
674
- console.warn('[GlobalDevBar] FCP PerformanceObserver not supported', e);
675
- }
676
- // LCP Observer
677
- try {
678
- this.lcpObserver = new PerformanceObserver((list) => {
679
- const entries = list.getEntries();
680
- const lastEntry = entries[entries.length - 1];
681
- if (lastEntry) {
682
- this.lcpValue = lastEntry.startTime;
683
- this.debug.perf('LCP updated', { lcp: this.lcpValue });
684
- updatePerfStats();
685
- }
686
- });
687
- this.lcpObserver.observe({ type: 'largest-contentful-paint', buffered: true });
688
- }
689
- catch (e) {
690
- console.warn('[GlobalDevBar] LCP PerformanceObserver not supported', e);
691
- }
692
- // CLS Observer (Cumulative Layout Shift)
693
- try {
694
- this.clsObserver = new PerformanceObserver((list) => {
695
- for (const entry of list.getEntries()) {
696
- // Only count layout shifts without recent user input
697
- const layoutShift = entry;
698
- if (!layoutShift.hadRecentInput && layoutShift.value) {
699
- this.clsValue += layoutShift.value;
700
- this.debug.perf('CLS updated', { cls: this.clsValue });
701
- updatePerfStats();
702
- }
703
- }
704
- });
705
- this.clsObserver.observe({ type: 'layout-shift', buffered: true });
706
- }
707
- catch (e) {
708
- console.warn('[GlobalDevBar] CLS PerformanceObserver not supported', e);
709
- }
710
- // INP Observer (Interaction to Next Paint)
711
- try {
712
- this.inpObserver = new PerformanceObserver((list) => {
713
- for (const entry of list.getEntries()) {
714
- const eventEntry = entry;
715
- if (eventEntry.duration && eventEntry.duration > this.inpValue) {
716
- this.inpValue = eventEntry.duration;
717
- this.debug.perf('INP updated', { inp: this.inpValue });
718
- updatePerfStats();
719
- }
720
- }
721
- });
722
- // durationThreshold filters out very short interactions
723
- this.inpObserver.observe({
724
- type: 'event',
725
- buffered: true,
726
- durationThreshold: 16,
727
- });
728
- }
729
- catch (e) {
730
- console.warn('[GlobalDevBar] INP PerformanceObserver not supported', e);
731
- }
732
- }
733
- setupKeyboardShortcuts() {
734
- this.keydownHandler = (e) => {
735
- // Close modals/popovers on Escape
736
- if (e.key === 'Escape') {
737
- if (this.showSettingsPopover) {
738
- this.showSettingsPopover = false;
739
- this.render();
740
- return;
741
- }
742
- if (this.consoleFilter ||
743
- this.showOutlineModal ||
744
- this.showSchemaModal ||
745
- this.showDesignReviewConfirm) {
746
- this.consoleFilter = null;
747
- this.showOutlineModal = false;
748
- this.showSchemaModal = false;
749
- this.showDesignReviewConfirm = false;
750
- this.render();
751
- return;
752
- }
753
- }
754
- if ((e.ctrlKey || e.metaKey) && e.shiftKey) {
755
- // Cmd/Ctrl+Shift+M: Toggle compact mode
756
- if (e.key === 'M' || e.key === 'm') {
757
- e.preventDefault();
758
- this.toggleCompactMode();
759
- return;
760
- }
761
- if (e.key === 'S' || e.key === 's') {
762
- e.preventDefault();
763
- if (this.sweetlinkConnected && !this.capturing) {
764
- this.handleScreenshot(false);
765
- }
766
- }
767
- else if (e.key === 'C' || e.key === 'c') {
768
- const selection = window.getSelection();
769
- if (!selection || selection.toString().length === 0) {
770
- e.preventDefault();
771
- if (!this.capturing) {
772
- this.handleScreenshot(true);
773
- }
774
- }
775
- }
776
- }
777
- };
778
- window.addEventListener('keydown', this.keydownHandler);
779
- }
780
- setupTheme() {
781
- // Load stored theme preference from settings manager
782
- const settings = this.settingsManager.getSettings();
783
- this.themeMode = settings.themeMode;
784
- this.debug.state('Theme loaded', { mode: this.themeMode });
785
- // Listen for system theme changes
786
- if (typeof window !== 'undefined' && window.matchMedia) {
787
- this.themeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
788
- this.themeMediaHandler = () => {
789
- if (this.themeMode === 'system') {
790
- this.debug.state('System theme changed', {
791
- effectiveTheme: getEffectiveTheme(this.themeMode),
792
- });
793
- this.render();
794
- }
795
- };
796
- this.themeMediaQuery.addEventListener('change', this.themeMediaHandler);
797
- }
798
- }
799
- loadCompactMode() {
800
- const settings = this.settingsManager.getSettings();
801
- this.compactMode = settings.compactMode;
802
- this.debug.state('Compact mode loaded', { compactMode: this.compactMode });
375
+ handleScreenshot(copyToClipboard) {
376
+ return moduleHandleScreenshot(this, copyToClipboard);
803
377
  }
804
378
  /**
805
379
  * Get the current theme mode
@@ -811,10 +385,7 @@ export class GlobalDevBar {
811
385
  * Set the theme mode
812
386
  */
813
387
  setThemeMode(mode) {
814
- this.themeMode = mode;
815
- this.settingsManager.saveSettings({ themeMode: mode });
816
- this.debug.state('Theme mode changed', { mode, effectiveTheme: getEffectiveTheme(mode) });
817
- this.render();
388
+ moduleSetThemeMode(this, mode);
818
389
  }
819
390
  /**
820
391
  * Get the current effective theme colors
@@ -837,2077 +408,13 @@ export class GlobalDevBar {
837
408
  isCompactMode() {
838
409
  return this.compactMode;
839
410
  }
840
- async copyPathToClipboard(path) {
841
- try {
842
- await navigator.clipboard.writeText(path);
843
- this.copiedPath = true;
844
- if (this.copiedPathTimeout)
845
- clearTimeout(this.copiedPathTimeout);
846
- this.copiedPathTimeout = setTimeout(() => {
847
- this.copiedPath = false;
848
- this.render();
849
- }, CLIPBOARD_NOTIFICATION_MS);
850
- this.render();
851
- }
852
- catch (error) {
853
- console.error('[GlobalDevBar] Failed to copy path:', error);
854
- }
855
- }
856
- async handleScreenshot(copyToClipboard = false) {
857
- if (this.capturing)
858
- return;
859
- if (!copyToClipboard && !this.sweetlinkConnected)
860
- return;
861
- let cleanup = null;
862
- try {
863
- this.capturing = true;
864
- this.render();
865
- cleanup = prepareForCapture();
866
- await delay(SCREENSHOT_BLUR_DELAY_MS);
867
- const canvas = await html2canvas(document.body, {
868
- logging: false,
869
- useCORS: true,
870
- allowTaint: true,
871
- scale: SCREENSHOT_SCALE,
872
- width: window.innerWidth,
873
- windowWidth: window.innerWidth,
874
- });
875
- // Restore page state
876
- cleanup();
877
- cleanup = null;
878
- if (copyToClipboard) {
879
- try {
880
- await copyCanvasToClipboard(canvas);
881
- this.copiedToClipboard = true;
882
- this.render();
883
- if (this.screenshotTimeout)
884
- clearTimeout(this.screenshotTimeout);
885
- this.screenshotTimeout = setTimeout(() => {
886
- this.copiedToClipboard = false;
887
- this.render();
888
- }, CLIPBOARD_NOTIFICATION_MS);
889
- }
890
- catch (e) {
891
- console.error('[GlobalDevBar] Failed to copy to clipboard:', e);
892
- }
893
- }
894
- else {
895
- const dataUrl = canvasToDataUrl(canvas, {
896
- format: 'jpeg',
897
- quality: DEVBAR_SCREENSHOT_QUALITY,
898
- });
899
- if (this.ws?.readyState === WebSocket.OPEN) {
900
- // Include web vitals metrics
901
- const webVitals = {};
902
- if (this.lcpValue !== null)
903
- webVitals.lcp = Math.round(this.lcpValue);
904
- if (this.clsValue > 0)
905
- webVitals.cls = this.clsValue;
906
- if (this.inpValue > 0)
907
- webVitals.inp = Math.round(this.inpValue);
908
- // Get FCP from performance entries
909
- const fcpEntry = performance
910
- .getEntriesByType('paint')
911
- .find((e) => e.name === 'first-contentful-paint');
912
- if (fcpEntry)
913
- webVitals.fcp = Math.round(fcpEntry.startTime);
914
- // Calculate page size
915
- let pageSize = 0;
916
- const navEntry = performance.getEntriesByType('navigation')[0];
917
- if (navEntry)
918
- pageSize += navEntry.transferSize || 0;
919
- performance.getEntriesByType('resource').forEach((entry) => {
920
- pageSize += entry.transferSize || 0;
921
- });
922
- this.ws.send(JSON.stringify({
923
- type: 'save-screenshot',
924
- data: {
925
- screenshot: dataUrl,
926
- width: canvas.width,
927
- height: canvas.height,
928
- logs: this.consoleLogs,
929
- url: window.location.href,
930
- timestamp: Date.now(),
931
- webVitals: Object.keys(webVitals).length > 0 ? webVitals : undefined,
932
- pageSize: pageSize > 0 ? pageSize : undefined,
933
- },
934
- }));
935
- }
936
- }
937
- }
938
- catch (e) {
939
- console.error('[GlobalDevBar] Screenshot failed:', e);
940
- if (cleanup)
941
- cleanup();
942
- }
943
- finally {
944
- this.capturing = false;
945
- this.render();
946
- }
947
- }
948
- async handleDesignReview() {
949
- if (this.designReviewInProgress || !this.sweetlinkConnected)
950
- return;
951
- let cleanup = null;
952
- try {
953
- this.designReviewInProgress = true;
954
- this.designReviewError = null; // Clear any previous error
955
- if (this.designReviewErrorTimeout) {
956
- clearTimeout(this.designReviewErrorTimeout);
957
- this.designReviewErrorTimeout = null;
958
- }
959
- this.render();
960
- cleanup = prepareForCapture();
961
- await delay(SCREENSHOT_BLUR_DELAY_MS);
962
- const canvas = await html2canvas(document.body, {
963
- logging: false,
964
- useCORS: true,
965
- allowTaint: true,
966
- scale: 1, // Full quality for design review
967
- width: window.innerWidth,
968
- windowWidth: window.innerWidth,
969
- });
970
- // Restore page state
971
- cleanup();
972
- cleanup = null;
973
- const dataUrl = canvasToDataUrl(canvas, { format: 'png' });
974
- if (this.ws?.readyState === WebSocket.OPEN) {
975
- this.ws.send(JSON.stringify({
976
- type: 'design-review-screenshot',
977
- data: {
978
- screenshot: dataUrl,
979
- width: canvas.width,
980
- height: canvas.height,
981
- logs: this.consoleLogs,
982
- url: window.location.href,
983
- timestamp: Date.now(),
984
- },
985
- }));
986
- }
987
- }
988
- catch (e) {
989
- console.error('[GlobalDevBar] Design review failed:', e);
990
- if (cleanup)
991
- cleanup();
992
- this.designReviewInProgress = false;
993
- this.render();
994
- }
995
- }
996
- /**
997
- * Show the design review confirmation modal
998
- * Checks API key status first
999
- */
1000
- showDesignReviewConfirmation() {
1001
- if (!this.sweetlinkConnected)
1002
- return;
1003
- // Request API key status from server
1004
- if (this.ws?.readyState === WebSocket.OPEN) {
1005
- this.ws.send(JSON.stringify({ type: 'check-api-key' }));
1006
- }
1007
- // Show the confirmation modal
1008
- this.showDesignReviewConfirm = true;
1009
- this.showOutlineModal = false;
1010
- this.showSchemaModal = false;
1011
- this.consoleFilter = null;
1012
- this.render();
1013
- }
1014
- /**
1015
- * Calculate estimated cost for design review based on viewport size
1016
- */
1017
- calculateCostEstimate() {
1018
- if (!this.apiKeyStatus?.pricing)
1019
- return null;
1020
- // Image token estimation for Claude Vision:
1021
- // Images are resized to fit within a bounding box, then tokenized
1022
- // Rough estimate: ~1 token per 1.5x1.5 pixels, or (width * height) / 750
1023
- const width = window.innerWidth;
1024
- const height = window.innerHeight;
1025
- const imageTokens = Math.ceil((width * height) / 750);
1026
- // Prompt is ~500 tokens, output up to 2048 tokens
1027
- const promptTokens = 500;
1028
- const estimatedOutputTokens = 1500; // Conservative estimate
1029
- const totalInputTokens = imageTokens + promptTokens;
1030
- const { input: inputPrice, output: outputPrice } = this.apiKeyStatus.pricing;
1031
- const inputCost = (totalInputTokens / 1000000) * inputPrice;
1032
- const outputCost = (estimatedOutputTokens / 1000000) * outputPrice;
1033
- const totalCost = inputCost + outputCost;
1034
- return {
1035
- tokens: totalInputTokens + estimatedOutputTokens,
1036
- cost: totalCost < 0.01 ? '<$0.01' : `~$${totalCost.toFixed(2)}`,
1037
- };
1038
- }
1039
- /**
1040
- * Close the design review confirmation modal
1041
- */
1042
- closeDesignReviewConfirm() {
1043
- this.showDesignReviewConfirm = false;
1044
- this.apiKeyStatus = null; // Reset so it's re-fetched next time
1045
- this.render();
1046
- }
1047
- /**
1048
- * Proceed with design review after confirmation
1049
- */
1050
- proceedWithDesignReview() {
1051
- this.showDesignReviewConfirm = false;
1052
- this.handleDesignReview();
1053
- }
1054
- handleDocumentOutline() {
1055
- // Toggle outline modal
1056
- this.showOutlineModal = !this.showOutlineModal;
1057
- this.showSchemaModal = false;
1058
- this.consoleFilter = null;
1059
- this.render();
1060
- }
1061
- handlePageSchema() {
1062
- // Toggle schema modal
1063
- this.showSchemaModal = !this.showSchemaModal;
1064
- this.showOutlineModal = false;
1065
- this.consoleFilter = null;
1066
- this.render();
1067
- }
1068
- handleSaveOutline() {
1069
- const outline = extractDocumentOutline();
1070
- const markdown = outlineToMarkdown(outline);
1071
- if (this.ws?.readyState === WebSocket.OPEN) {
1072
- this.ws.send(JSON.stringify({
1073
- type: 'save-outline',
1074
- data: {
1075
- outline,
1076
- markdown,
1077
- url: window.location.href,
1078
- title: document.title,
1079
- timestamp: Date.now(),
1080
- },
1081
- }));
1082
- }
1083
- }
1084
- handleSaveSchema() {
1085
- const schema = extractPageSchema();
1086
- const markdown = schemaToMarkdown(schema);
1087
- if (this.ws?.readyState === WebSocket.OPEN) {
1088
- this.ws.send(JSON.stringify({
1089
- type: 'save-schema',
1090
- data: {
1091
- schema,
1092
- markdown,
1093
- url: window.location.href,
1094
- title: document.title,
1095
- timestamp: Date.now(),
1096
- },
1097
- }));
1098
- }
1099
- }
1100
- clearConsoleLogs() {
1101
- // Clear the logs array
1102
- earlyConsoleCapture.logs = [];
1103
- earlyConsoleCapture.errorCount = 0;
1104
- earlyConsoleCapture.warningCount = 0;
1105
- this.consoleLogs = [];
1106
- this.consoleFilter = null;
1107
- this.render();
1108
- }
1109
411
  // ============================================================================
1110
- // Render Methods (Using Safe DOM Methods)
412
+ // Render (delegates to rendering module)
1111
413
  // ============================================================================
1112
414
  render() {
1113
- if (this.destroyed)
1114
- return;
1115
- if (typeof document === 'undefined')
1116
- return;
1117
- // Remove existing container if any
1118
- if (this.container) {
1119
- this.container.remove();
1120
- }
1121
- // Create new container
1122
- this.container = document.createElement('div');
1123
- this.container.setAttribute('data-devbar', 'true');
1124
- if (this.collapsed) {
1125
- this.renderCollapsed();
1126
- }
1127
- else if (this.compactMode) {
1128
- this.renderCompact();
1129
- }
1130
- else {
1131
- this.renderExpanded();
1132
- }
1133
- document.body.appendChild(this.container);
1134
- // Render overlays/modals
1135
- this.renderOverlays();
1136
- }
1137
- renderOverlays() {
1138
- // Remove existing overlay
1139
- if (this.overlayElement) {
1140
- this.overlayElement.remove();
1141
- this.overlayElement = null;
1142
- }
1143
- // Render console popup if filter is active
1144
- if (this.consoleFilter) {
1145
- this.renderConsolePopup();
1146
- }
1147
- // Render outline modal
1148
- if (this.showOutlineModal) {
1149
- this.renderOutlineModal();
1150
- }
1151
- // Render schema modal
1152
- if (this.showSchemaModal) {
1153
- this.renderSchemaModal();
1154
- }
1155
- // Render design review confirmation modal
1156
- if (this.showDesignReviewConfirm) {
1157
- this.renderDesignReviewConfirmModal();
1158
- }
1159
- // Render settings popover
1160
- if (this.showSettingsPopover) {
1161
- this.renderSettingsPopover();
1162
- }
1163
- }
1164
- renderDesignReviewConfirmModal() {
1165
- const color = BUTTON_COLORS.review;
1166
- const closeModal = () => this.closeDesignReviewConfirm();
1167
- const overlay = createModalOverlay(closeModal);
1168
- // Override z-index for this modal to be above others
1169
- overlay.style.zIndex = '10003';
1170
- const modal = createModalBox(color);
1171
- modal.style.maxWidth = '450px';
1172
- // Header with title and close button
1173
- const header = document.createElement('div');
1174
- Object.assign(header.style, {
1175
- display: 'flex',
1176
- alignItems: 'center',
1177
- justifyContent: 'space-between',
1178
- padding: '14px 18px',
1179
- borderBottom: `1px solid ${color}40`,
1180
- backgroundColor: `${color}15`,
1181
- });
1182
- const title = document.createElement('span');
1183
- Object.assign(title.style, { color, fontSize: '0.875rem', fontWeight: '600' });
1184
- title.textContent = 'AI Design Review';
1185
- header.appendChild(title);
1186
- const closeBtn = createStyledButton({
1187
- color: COLORS.textMuted,
1188
- text: '×',
1189
- padding: '0',
1190
- fontSize: '1.25rem',
1191
- });
1192
- closeBtn.style.border = 'none';
1193
- closeBtn.onclick = closeModal;
1194
- header.appendChild(closeBtn);
1195
- modal.appendChild(header);
1196
- // Content
1197
- const content = document.createElement('div');
1198
- Object.assign(content.style, {
1199
- padding: '18px',
1200
- color: COLORS.text,
1201
- fontSize: '0.8125rem',
1202
- lineHeight: '1.6',
1203
- });
1204
- if (this.apiKeyStatus === null) {
1205
- content.appendChild(createEmptyMessage('Checking API key configuration...'));
1206
- }
1207
- else if (!this.apiKeyStatus.configured) {
1208
- content.appendChild(this.renderApiKeyNotConfiguredContent());
1209
- }
1210
- else {
1211
- content.appendChild(this.renderApiKeyConfiguredContent());
1212
- }
1213
- modal.appendChild(content);
1214
- // Footer with buttons
1215
- const footer = document.createElement('div');
1216
- Object.assign(footer.style, {
1217
- display: 'flex',
1218
- justifyContent: 'flex-end',
1219
- gap: '10px',
1220
- padding: '14px 18px',
1221
- borderTop: `1px solid ${COLORS.border}`,
1222
- });
1223
- const cancelBtn = createStyledButton({
1224
- color: COLORS.textMuted,
1225
- text: 'Cancel',
1226
- padding: '8px 16px',
1227
- });
1228
- cancelBtn.onclick = closeModal;
1229
- footer.appendChild(cancelBtn);
1230
- if (this.apiKeyStatus?.configured) {
1231
- const proceedBtn = createStyledButton({ color, text: 'Run Review', padding: '8px 16px' });
1232
- proceedBtn.style.backgroundColor = `${color}20`;
1233
- proceedBtn.onclick = () => this.proceedWithDesignReview();
1234
- footer.appendChild(proceedBtn);
1235
- }
1236
- modal.appendChild(footer);
1237
- overlay.appendChild(modal);
1238
- document.body.appendChild(overlay);
1239
- }
1240
- /**
1241
- * Render content when API key is not configured
1242
- */
1243
- renderApiKeyNotConfiguredContent() {
1244
- const wrapper = document.createElement('div');
1245
- wrapper.appendChild(createInfoBox(COLORS.error, 'API Key Not Configured', 'The ANTHROPIC_API_KEY environment variable is not set.'));
1246
- // Instructions
1247
- const instructions = document.createElement('div');
1248
- Object.assign(instructions.style, { marginBottom: '12px' });
1249
- const instructTitle = document.createElement('div');
1250
- Object.assign(instructTitle.style, {
1251
- color: COLORS.textSecondary,
1252
- fontWeight: '600',
1253
- marginBottom: '8px',
1254
- });
1255
- instructTitle.textContent = 'To configure:';
1256
- instructions.appendChild(instructTitle);
1257
- const steps = [
1258
- { text: '1. Get an API key from console.anthropic.com', highlight: false },
1259
- { text: '2. Add to your .env file:', highlight: false },
1260
- { text: ' ANTHROPIC_API_KEY=sk-ant-...', highlight: true },
1261
- { text: '3. Restart your dev server', highlight: false },
1262
- ];
1263
- steps.forEach(({ text, highlight }) => {
1264
- const stepDiv = document.createElement('div');
1265
- Object.assign(stepDiv.style, {
1266
- color: highlight ? COLORS.primary : COLORS.textMuted,
1267
- fontSize: '0.75rem',
1268
- marginBottom: '4px',
1269
- fontFamily: FONT_MONO,
1270
- });
1271
- stepDiv.textContent = text;
1272
- instructions.appendChild(stepDiv);
1273
- });
1274
- wrapper.appendChild(instructions);
1275
- return wrapper;
1276
- }
1277
- /**
1278
- * Render content when API key is configured (cost estimate and model info)
1279
- */
1280
- renderApiKeyConfiguredContent() {
1281
- const wrapper = document.createElement('div');
1282
- Object.assign(wrapper.style, { marginBottom: '16px' });
1283
- const desc = document.createElement('p');
1284
- Object.assign(desc.style, { color: COLORS.textSecondary, marginBottom: '12px' });
1285
- desc.textContent = 'This will capture a screenshot and send it to Claude for design analysis.';
1286
- wrapper.appendChild(desc);
1287
- // Cost estimate
1288
- const estimate = this.calculateCostEstimate();
1289
- if (estimate) {
1290
- const costBox = createInfoBox(COLORS.primary, 'Estimated Cost', []);
1291
- // Remove default margin and adjust padding
1292
- costBox.style.marginBottom = '0';
1293
- costBox.style.padding = '12px';
1294
- const costDetails = document.createElement('div');
1295
- Object.assign(costDetails.style, {
1296
- display: 'flex',
1297
- justifyContent: 'space-between',
1298
- color: COLORS.textSecondary,
1299
- fontSize: '0.75rem',
1300
- });
1301
- const tokensSpan = document.createElement('span');
1302
- tokensSpan.textContent = `~${estimate.tokens.toLocaleString()} tokens`;
1303
- costDetails.appendChild(tokensSpan);
1304
- const priceSpan = document.createElement('span');
1305
- Object.assign(priceSpan.style, { color: COLORS.warning, fontWeight: '600' });
1306
- priceSpan.textContent = estimate.cost;
1307
- costDetails.appendChild(priceSpan);
1308
- costBox.appendChild(costDetails);
1309
- wrapper.appendChild(costBox);
1310
- }
1311
- // Model info
1312
- if (this.apiKeyStatus?.model) {
1313
- const modelDiv = document.createElement('div');
1314
- Object.assign(modelDiv.style, {
1315
- color: COLORS.textMuted,
1316
- fontSize: '0.6875rem',
1317
- marginTop: '12px',
1318
- });
1319
- modelDiv.textContent = `Model: ${this.apiKeyStatus.model}`;
1320
- if (this.apiKeyStatus.maskedKey) {
1321
- modelDiv.textContent += ` | Key: ${this.apiKeyStatus.maskedKey}`;
1322
- }
1323
- wrapper.appendChild(modelDiv);
1324
- }
1325
- return wrapper;
1326
- }
1327
- renderConsolePopup() {
1328
- const filterType = this.consoleFilter;
1329
- if (!filterType)
1330
- return;
1331
- const logs = earlyConsoleCapture.logs.filter((log) => log.level === filterType);
1332
- const color = filterType === 'error' ? BUTTON_COLORS.error : BUTTON_COLORS.warning;
1333
- const label = filterType === 'error' ? 'Errors' : 'Warnings';
1334
- const popup = document.createElement('div');
1335
- popup.setAttribute('data-devbar', 'true');
1336
- Object.assign(popup.style, {
1337
- position: 'fixed',
1338
- bottom: '60px',
1339
- left: '80px',
1340
- zIndex: '10002',
1341
- backgroundColor: 'rgba(17, 24, 39, 0.98)',
1342
- border: `1px solid ${color}`,
1343
- borderRadius: '8px',
1344
- boxShadow: `0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px ${color}33`,
1345
- backdropFilter: 'blur(8px)',
1346
- WebkitBackdropFilter: 'blur(8px)',
1347
- minWidth: '400px',
1348
- maxWidth: '600px',
1349
- maxHeight: '400px',
1350
- display: 'flex',
1351
- flexDirection: 'column',
1352
- fontFamily: FONT_MONO,
1353
- });
1354
- // Header
1355
- const header = document.createElement('div');
1356
- Object.assign(header.style, {
1357
- display: 'flex',
1358
- alignItems: 'center',
1359
- justifyContent: 'space-between',
1360
- padding: '10px 14px',
1361
- borderBottom: `1px solid ${color}40`,
1362
- });
1363
- const title = document.createElement('span');
1364
- Object.assign(title.style, { color, fontSize: '0.8125rem', fontWeight: '600' });
1365
- title.textContent = `Console ${label} (${logs.length})`;
1366
- header.appendChild(title);
1367
- const headerButtons = document.createElement('div');
1368
- Object.assign(headerButtons.style, { display: 'flex', gap: '8px' });
1369
- // Clear button
1370
- const clearBtn = createStyledButton({
1371
- color,
1372
- text: 'Clear All',
1373
- padding: '4px 10px',
1374
- borderRadius: '4px',
1375
- fontSize: '0.6875rem',
1376
- });
1377
- clearBtn.onclick = () => this.clearConsoleLogs();
1378
- headerButtons.appendChild(clearBtn);
1379
- // Close button - match Clear button padding for consistent height
1380
- const closeBtn = createStyledButton({
1381
- color,
1382
- text: '×',
1383
- padding: '4px 8px',
1384
- borderRadius: '4px',
1385
- fontSize: '0.75rem',
1386
- });
1387
- closeBtn.onclick = () => {
1388
- this.consoleFilter = null;
1389
- this.render();
1390
- };
1391
- headerButtons.appendChild(closeBtn);
1392
- header.appendChild(headerButtons);
1393
- popup.appendChild(header);
1394
- // Content
1395
- const content = document.createElement('div');
1396
- Object.assign(content.style, { flex: '1', overflow: 'auto', padding: '8px 0' });
1397
- if (logs.length === 0) {
1398
- const emptyMsg = document.createElement('div');
1399
- Object.assign(emptyMsg.style, {
1400
- padding: '20px',
1401
- textAlign: 'center',
1402
- color: COLORS.textMuted,
1403
- fontSize: '0.75rem',
1404
- });
1405
- emptyMsg.textContent = `No ${filterType}s recorded`;
1406
- content.appendChild(emptyMsg);
1407
- }
1408
- else {
1409
- this.renderConsoleLogs(content, logs, color);
1410
- }
1411
- popup.appendChild(content);
1412
- this.overlayElement = popup;
1413
- document.body.appendChild(popup);
1414
- }
1415
- /**
1416
- * Render console log items into a container
1417
- */
1418
- renderConsoleLogs(container, logs, color) {
1419
- logs.forEach((log, index) => {
1420
- const logItem = document.createElement('div');
1421
- Object.assign(logItem.style, {
1422
- padding: '8px 14px',
1423
- borderBottom: index < logs.length - 1 ? '1px solid rgba(255, 255, 255, 0.05)' : 'none',
1424
- });
1425
- const timestamp = document.createElement('span');
1426
- Object.assign(timestamp.style, {
1427
- color: COLORS.textMuted,
1428
- fontSize: '0.625rem',
1429
- marginRight: '8px',
1430
- });
1431
- timestamp.textContent = new Date(log.timestamp).toLocaleTimeString();
1432
- logItem.appendChild(timestamp);
1433
- const message = document.createElement('span');
1434
- Object.assign(message.style, {
1435
- color,
1436
- fontSize: '0.6875rem',
1437
- wordBreak: 'break-word',
1438
- whiteSpace: 'pre-wrap',
1439
- });
1440
- message.textContent =
1441
- log.message.length > 500 ? `${log.message.slice(0, 500)}...` : log.message;
1442
- logItem.appendChild(message);
1443
- container.appendChild(logItem);
1444
- });
1445
- }
1446
- renderOutlineModal() {
1447
- const outline = extractDocumentOutline();
1448
- const color = BUTTON_COLORS.outline;
1449
- const closeModal = () => {
1450
- this.showOutlineModal = false;
1451
- this.render();
1452
- };
1453
- const overlay = createModalOverlay(closeModal);
1454
- const modal = createModalBox(color);
1455
- const header = createModalHeader({
1456
- color,
1457
- title: 'Document Outline',
1458
- onClose: closeModal,
1459
- onCopyMd: async () => {
1460
- const markdown = outlineToMarkdown(outline);
1461
- await navigator.clipboard.writeText(markdown);
1462
- },
1463
- onSave: () => this.handleSaveOutline(),
1464
- sweetlinkConnected: this.sweetlinkConnected,
1465
- });
1466
- modal.appendChild(header);
1467
- const content = createModalContent();
1468
- if (outline.length === 0) {
1469
- content.appendChild(createEmptyMessage('No semantic elements found in this document'));
1470
- }
1471
- else {
1472
- this.renderOutlineNodes(outline, content, 0);
1473
- }
1474
- modal.appendChild(content);
1475
- overlay.appendChild(modal);
1476
- this.overlayElement = overlay;
1477
- document.body.appendChild(overlay);
1478
- }
1479
- /**
1480
- * Recursively render outline nodes into a container element
1481
- */
1482
- renderOutlineNodes(nodes, parentEl, depth) {
1483
- for (const node of nodes) {
1484
- const nodeEl = document.createElement('div');
1485
- Object.assign(nodeEl.style, {
1486
- padding: `4px 0 4px ${depth * 16}px`,
1487
- });
1488
- const tagSpan = document.createElement('span');
1489
- const categoryColor = CATEGORY_COLORS[node.category || 'other'] || CATEGORY_COLORS.other;
1490
- Object.assign(tagSpan.style, {
1491
- color: categoryColor,
1492
- fontSize: '0.6875rem',
1493
- fontWeight: '500',
1494
- });
1495
- tagSpan.textContent = `<${node.tagName}>`;
1496
- nodeEl.appendChild(tagSpan);
1497
- if (node.category) {
1498
- const categorySpan = document.createElement('span');
1499
- Object.assign(categorySpan.style, {
1500
- color: COLORS.textMuted,
1501
- fontSize: '0.625rem',
1502
- marginLeft: '6px',
1503
- });
1504
- categorySpan.textContent = `[${node.category}]`;
1505
- nodeEl.appendChild(categorySpan);
1506
- }
1507
- const textSpan = document.createElement('span');
1508
- Object.assign(textSpan.style, {
1509
- color: '#d1d5db',
1510
- fontSize: '0.6875rem',
1511
- marginLeft: '8px',
1512
- });
1513
- const truncatedText = node.text.length > 60 ? `${node.text.slice(0, 60)}...` : node.text;
1514
- textSpan.textContent = truncatedText;
1515
- nodeEl.appendChild(textSpan);
1516
- if (node.id) {
1517
- const idSpan = document.createElement('span');
1518
- Object.assign(idSpan.style, {
1519
- color: '#9ca3af',
1520
- fontSize: '0.625rem',
1521
- marginLeft: '6px',
1522
- });
1523
- idSpan.textContent = `#${node.id}`;
1524
- nodeEl.appendChild(idSpan);
1525
- }
1526
- parentEl.appendChild(nodeEl);
1527
- if (node.children.length > 0) {
1528
- this.renderOutlineNodes(node.children, parentEl, depth + 1);
1529
- }
1530
- }
1531
- }
1532
- renderSchemaModal() {
1533
- const schema = extractPageSchema();
1534
- const color = BUTTON_COLORS.schema;
1535
- const closeModal = () => {
1536
- this.showSchemaModal = false;
1537
- this.render();
1538
- };
1539
- const overlay = createModalOverlay(closeModal);
1540
- const modal = createModalBox(color);
1541
- const header = createModalHeader({
1542
- color,
1543
- title: 'Page Schema',
1544
- onClose: closeModal,
1545
- onCopyMd: async () => {
1546
- const markdown = schemaToMarkdown(schema);
1547
- await navigator.clipboard.writeText(markdown);
1548
- },
1549
- onSave: () => this.handleSaveSchema(),
1550
- sweetlinkConnected: this.sweetlinkConnected,
1551
- });
1552
- modal.appendChild(header);
1553
- const content = createModalContent();
1554
- const hasContent = schema.jsonLd.length > 0 ||
1555
- Object.keys(schema.openGraph).length > 0 ||
1556
- Object.keys(schema.twitter).length > 0 ||
1557
- Object.keys(schema.metaTags).length > 0;
1558
- if (!hasContent) {
1559
- content.appendChild(createEmptyMessage('No structured data found on this page'));
1560
- }
1561
- else {
1562
- this.renderSchemaSection(content, 'JSON-LD', schema.jsonLd, color);
1563
- this.renderSchemaSection(content, 'Open Graph', schema.openGraph, COLORS.info);
1564
- this.renderSchemaSection(content, 'Twitter Cards', schema.twitter, COLORS.cyan);
1565
- this.renderSchemaSection(content, 'Meta Tags', schema.metaTags, COLORS.textMuted);
1566
- }
1567
- modal.appendChild(content);
1568
- overlay.appendChild(modal);
1569
- this.overlayElement = overlay;
1570
- document.body.appendChild(overlay);
1571
- }
1572
- /**
1573
- * Render a section of schema data (either array or key-value object)
1574
- */
1575
- renderSchemaSection(container, title, items, color) {
1576
- const isEmpty = Array.isArray(items) ? items.length === 0 : Object.keys(items).length === 0;
1577
- if (isEmpty)
1578
- return;
1579
- const section = document.createElement('div');
1580
- section.style.marginBottom = '20px';
1581
- const sectionTitle = document.createElement('h3');
1582
- Object.assign(sectionTitle.style, {
1583
- color,
1584
- fontSize: '0.8125rem',
1585
- fontWeight: '600',
1586
- marginBottom: '10px',
1587
- borderBottom: `1px solid ${color}40`,
1588
- paddingBottom: '6px',
1589
- });
1590
- sectionTitle.textContent = title;
1591
- section.appendChild(sectionTitle);
1592
- if (Array.isArray(items)) {
1593
- this.renderJsonLdItems(section, items);
1594
- }
1595
- else {
1596
- this.renderKeyValueItems(section, items);
1597
- }
1598
- container.appendChild(section);
1599
- }
1600
- /**
1601
- * Render JSON-LD items as formatted code blocks with syntax highlighting
1602
- */
1603
- renderJsonLdItems(container, items) {
1604
- items.forEach((item, i) => {
1605
- const itemEl = document.createElement('div');
1606
- itemEl.style.marginBottom = '10px';
1607
- const itemTitle = document.createElement('div');
1608
- Object.assign(itemTitle.style, {
1609
- color: '#9ca3af',
1610
- fontSize: '0.6875rem',
1611
- marginBottom: '4px',
1612
- });
1613
- itemTitle.textContent = `Schema ${i + 1}`;
1614
- itemEl.appendChild(itemTitle);
1615
- const codeEl = document.createElement('pre');
1616
- Object.assign(codeEl.style, {
1617
- backgroundColor: 'rgba(0, 0, 0, 0.3)',
1618
- borderRadius: '4px',
1619
- padding: '10px',
1620
- overflow: 'auto',
1621
- fontSize: '0.625rem',
1622
- margin: '0',
1623
- maxHeight: '300px', // Taller for more content
1624
- });
1625
- // Syntax highlight the JSON using DOM methods for safety
1626
- this.appendHighlightedJson(codeEl, JSON.stringify(item, null, 2));
1627
- itemEl.appendChild(codeEl);
1628
- container.appendChild(itemEl);
1629
- });
1630
- }
1631
- /**
1632
- * Append syntax-highlighted JSON to an element using safe DOM methods
1633
- * Uses textContent for all text to prevent XSS
1634
- */
1635
- appendHighlightedJson(container, json) {
1636
- // Color map for different token types
1637
- const colors = {
1638
- key: COLORS.primary, // green
1639
- string: COLORS.warning, // amber/yellow
1640
- number: COLORS.purple, // purple
1641
- boolean: COLORS.info, // blue
1642
- nullVal: COLORS.error, // red
1643
- punct: COLORS.textMuted, // gray
1644
- };
1645
- // Simple tokenizer for JSON using matchAll for safety
1646
- const tokenPattern = /("(?:\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*")(\s*:)?|(\btrue\b|\bfalse\b)|(\bnull\b)|(-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?)|([{}[\],])|(\s+)/g;
1647
- for (const match of json.matchAll(tokenPattern)) {
1648
- const [, str, colon, bool, nullToken, num, punct, whitespace] = match;
1649
- if (whitespace) {
1650
- container.appendChild(document.createTextNode(whitespace));
1651
- }
1652
- else if (str !== undefined) {
1653
- const span = document.createElement('span');
1654
- span.style.color = colon ? colors.key : colors.string;
1655
- span.textContent = str;
1656
- container.appendChild(span);
1657
- if (colon) {
1658
- const colonSpan = document.createElement('span');
1659
- colonSpan.style.color = colors.punct;
1660
- colonSpan.textContent = ':';
1661
- container.appendChild(colonSpan);
1662
- }
1663
- }
1664
- else if (bool) {
1665
- const span = document.createElement('span');
1666
- span.style.color = colors.boolean;
1667
- span.textContent = bool;
1668
- container.appendChild(span);
1669
- }
1670
- else if (nullToken) {
1671
- const span = document.createElement('span');
1672
- span.style.color = colors.nullVal;
1673
- span.textContent = nullToken;
1674
- container.appendChild(span);
1675
- }
1676
- else if (num) {
1677
- const span = document.createElement('span');
1678
- span.style.color = colors.number;
1679
- span.textContent = num;
1680
- container.appendChild(span);
1681
- }
1682
- else if (punct) {
1683
- const span = document.createElement('span');
1684
- span.style.color = colors.punct;
1685
- span.textContent = punct;
1686
- container.appendChild(span);
1687
- }
1688
- }
1689
- }
1690
- /**
1691
- * Render key-value pairs as rows with ellipsis overflow and hover tooltip
1692
- */
1693
- renderKeyValueItems(container, items) {
1694
- for (const [key, value] of Object.entries(items)) {
1695
- const row = document.createElement('div');
1696
- Object.assign(row.style, {
1697
- display: 'flex',
1698
- marginBottom: '4px',
1699
- alignItems: 'flex-start',
1700
- });
1701
- const keyEl = document.createElement('span');
1702
- Object.assign(keyEl.style, {
1703
- color: '#9ca3af',
1704
- fontSize: '0.6875rem',
1705
- width: '120px',
1706
- minWidth: '120px',
1707
- maxWidth: '120px',
1708
- flexShrink: '0',
1709
- overflow: 'hidden',
1710
- textOverflow: 'ellipsis',
1711
- whiteSpace: 'nowrap',
1712
- });
1713
- keyEl.textContent = key;
1714
- // Show full key on hover if it might be truncated
1715
- if (key.length > 18) {
1716
- keyEl.title = key;
1717
- }
1718
- row.appendChild(keyEl);
1719
- const valueEl = document.createElement('span');
1720
- const strValue = String(value);
1721
- Object.assign(valueEl.style, {
1722
- color: '#d1d5db',
1723
- fontSize: '0.6875rem',
1724
- flex: '1',
1725
- wordBreak: 'break-word',
1726
- whiteSpace: 'pre-wrap',
1727
- });
1728
- valueEl.textContent = strValue;
1729
- row.appendChild(valueEl);
1730
- container.appendChild(row);
1731
- }
1732
- }
1733
- /**
1734
- * Render compact mode - single row with essential controls only
1735
- * Shows: connection dot, error/warn badges, screenshot button, settings gear
1736
- */
1737
- renderCompact() {
1738
- if (!this.container)
1739
- return;
1740
- const { position, accentColor } = this.options;
1741
- const { errorCount, warningCount } = this.getLogCounts();
1742
- const positionStyles = {
1743
- 'bottom-left': { bottom: '20px', left: '80px' },
1744
- 'bottom-right': { bottom: '20px', right: '16px' },
1745
- 'top-left': { top: '20px', left: '80px' },
1746
- 'top-right': { top: '20px', right: '16px' },
1747
- 'bottom-center': { bottom: '12px', left: '50%', transform: 'translateX(-50%)' },
1748
- };
1749
- const posStyle = positionStyles[position] ?? positionStyles['bottom-left'];
1750
- const wrapper = this.container;
1751
- // Reset position properties first
1752
- wrapper.style.top = '';
1753
- wrapper.style.bottom = '';
1754
- wrapper.style.left = '';
1755
- wrapper.style.right = '';
1756
- wrapper.style.transform = '';
1757
- Object.assign(wrapper.style, {
1758
- position: 'fixed',
1759
- ...posStyle,
1760
- zIndex: '9999',
1761
- backgroundColor: 'rgba(17, 24, 39, 0.95)',
1762
- border: `1px solid ${accentColor}`,
1763
- borderRadius: '20px',
1764
- color: accentColor,
1765
- boxShadow: `0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 1px ${accentColor}1A`,
1766
- backdropFilter: 'blur(8px)',
1767
- WebkitBackdropFilter: 'blur(8px)',
1768
- padding: '6px 10px',
1769
- display: 'flex',
1770
- alignItems: 'center',
1771
- gap: '8px',
1772
- fontFamily: FONT_MONO,
1773
- fontSize: '0.6875rem',
1774
- });
1775
- // Connection indicator
1776
- const connIndicator = document.createElement('span');
1777
- connIndicator.className = this.tooltipClass('left', 'devbar-clickable');
1778
- connIndicator.setAttribute('data-tooltip', this.sweetlinkConnected ? 'Sweetlink connected' : 'Sweetlink disconnected');
1779
- Object.assign(connIndicator.style, {
1780
- width: '12px',
1781
- height: '12px',
1782
- borderRadius: '50%',
1783
- display: 'flex',
1784
- alignItems: 'center',
1785
- justifyContent: 'center',
1786
- cursor: 'pointer',
1787
- });
1788
- connIndicator.onclick = (e) => {
1789
- e.stopPropagation();
1790
- this.collapsed = true;
1791
- this.debug.state('Collapsed DevBar from compact mode');
1792
- this.render();
1793
- };
1794
- const connDot = document.createElement('span');
1795
- Object.assign(connDot.style, {
1796
- width: '6px',
1797
- height: '6px',
1798
- borderRadius: '50%',
1799
- backgroundColor: this.sweetlinkConnected ? COLORS.primary : COLORS.textMuted,
1800
- boxShadow: this.sweetlinkConnected ? `0 0 6px ${COLORS.primary}` : 'none',
1801
- });
1802
- connIndicator.appendChild(connDot);
1803
- wrapper.appendChild(connIndicator);
1804
- // Error badge
1805
- if (errorCount > 0) {
1806
- wrapper.appendChild(this.createConsoleBadge('error', errorCount, BUTTON_COLORS.error));
1807
- }
1808
- // Warning badge
1809
- if (warningCount > 0) {
1810
- wrapper.appendChild(this.createConsoleBadge('warn', warningCount, BUTTON_COLORS.warning));
1811
- }
1812
- // Screenshot button (if enabled)
1813
- if (this.options.showScreenshot) {
1814
- wrapper.appendChild(this.createScreenshotButton(accentColor));
1815
- }
1816
- // Settings gear button
1817
- wrapper.appendChild(this.createSettingsButton());
1818
- // Expand button (double-arrow)
1819
- const expandBtn = document.createElement('button');
1820
- expandBtn.type = 'button';
1821
- expandBtn.className = this.tooltipClass('right');
1822
- expandBtn.setAttribute('data-tooltip', 'Expand DevBar');
1823
- Object.assign(expandBtn.style, {
1824
- display: 'flex',
1825
- alignItems: 'center',
1826
- justifyContent: 'center',
1827
- width: '18px',
1828
- height: '18px',
1829
- borderRadius: '50%',
1830
- border: `1px solid ${accentColor}60`,
1831
- backgroundColor: 'transparent',
1832
- color: `${accentColor}99`,
1833
- cursor: 'pointer',
1834
- fontSize: '0.5rem',
1835
- transition: 'all 150ms',
1836
- });
1837
- expandBtn.textContent = '⟫';
1838
- expandBtn.onmouseenter = () => {
1839
- expandBtn.style.backgroundColor = `${accentColor}20`;
1840
- expandBtn.style.borderColor = accentColor;
1841
- expandBtn.style.color = accentColor;
1842
- };
1843
- expandBtn.onmouseleave = () => {
1844
- expandBtn.style.backgroundColor = 'transparent';
1845
- expandBtn.style.borderColor = `${accentColor}60`;
1846
- expandBtn.style.color = `${accentColor}99`;
1847
- };
1848
- expandBtn.onclick = () => {
1849
- this.toggleCompactMode();
1850
- };
1851
- wrapper.appendChild(expandBtn);
1852
- }
1853
- /**
1854
- * Create the settings gear button
1855
- */
1856
- createSettingsButton() {
1857
- const btn = document.createElement('button');
1858
- btn.type = 'button';
1859
- btn.className = this.tooltipClass('right');
1860
- btn.setAttribute('data-tooltip', 'Settings (Cmd+Shift+M: toggle compact)');
1861
- const isActive = this.showSettingsPopover;
1862
- const color = COLORS.textSecondary;
1863
- Object.assign(btn.style, {
1864
- display: 'flex',
1865
- alignItems: 'center',
1866
- justifyContent: 'center',
1867
- width: '22px',
1868
- height: '22px',
1869
- minWidth: '22px',
1870
- minHeight: '22px',
1871
- flexShrink: '0',
1872
- borderRadius: '50%',
1873
- border: `1px solid ${isActive ? color : `${color}60`}`,
1874
- backgroundColor: isActive ? `${color}20` : 'transparent',
1875
- color: isActive ? color : `${color}99`,
1876
- cursor: 'pointer',
1877
- transition: 'all 150ms',
1878
- });
1879
- btn.onclick = () => {
1880
- this.showSettingsPopover = !this.showSettingsPopover;
1881
- this.consoleFilter = null;
1882
- this.showOutlineModal = false;
1883
- this.showSchemaModal = false;
1884
- this.showDesignReviewConfirm = false;
1885
- this.render();
1886
- };
1887
- // Gear icon SVG
1888
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
1889
- svg.setAttribute('width', '12');
1890
- svg.setAttribute('height', '12');
1891
- svg.setAttribute('viewBox', '0 0 24 24');
1892
- svg.setAttribute('fill', 'none');
1893
- svg.setAttribute('stroke', 'currentColor');
1894
- svg.setAttribute('stroke-width', '2');
1895
- svg.setAttribute('stroke-linecap', 'round');
1896
- svg.setAttribute('stroke-linejoin', 'round');
1897
- const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
1898
- path.setAttribute('d', 'M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z');
1899
- svg.appendChild(path);
1900
- const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
1901
- circle.setAttribute('cx', '12');
1902
- circle.setAttribute('cy', '12');
1903
- circle.setAttribute('r', '3');
1904
- svg.appendChild(circle);
1905
- btn.appendChild(svg);
1906
- return btn;
1907
- }
1908
- /**
1909
- * Create the compact mode toggle button with chevron icon
1910
- */
1911
- createCompactToggleButton() {
1912
- const btn = document.createElement('button');
1913
- btn.type = 'button';
1914
- btn.className = this.tooltipClass('right');
1915
- const isCompact = this.compactMode;
1916
- const tooltip = isCompact ? 'Expand (Cmd+Shift+M)' : 'Compact (Cmd+Shift+M)';
1917
- btn.setAttribute('data-tooltip', tooltip);
1918
- const color = COLORS.textSecondary;
1919
- Object.assign(btn.style, {
1920
- display: 'flex',
1921
- alignItems: 'center',
1922
- justifyContent: 'center',
1923
- width: '22px',
1924
- height: '22px',
1925
- minWidth: '22px',
1926
- minHeight: '22px',
1927
- flexShrink: '0',
1928
- borderRadius: '50%',
1929
- border: `1px solid ${color}60`,
1930
- backgroundColor: 'transparent',
1931
- color: `${color}99`,
1932
- cursor: 'pointer',
1933
- transition: 'all 150ms',
1934
- });
1935
- btn.onmouseenter = () => {
1936
- btn.style.borderColor = color;
1937
- btn.style.backgroundColor = `${color}20`;
1938
- btn.style.color = color;
1939
- };
1940
- btn.onmouseleave = () => {
1941
- btn.style.borderColor = `${color}60`;
1942
- btn.style.backgroundColor = 'transparent';
1943
- btn.style.color = `${color}99`;
1944
- };
1945
- btn.onclick = () => {
1946
- this.toggleCompactMode();
1947
- };
1948
- // Chevron icon SVG - points right when expanded, left when compact
1949
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
1950
- svg.setAttribute('width', '12');
1951
- svg.setAttribute('height', '12');
1952
- svg.setAttribute('viewBox', '0 0 24 24');
1953
- svg.setAttribute('fill', 'none');
1954
- svg.setAttribute('stroke', 'currentColor');
1955
- svg.setAttribute('stroke-width', '2');
1956
- svg.setAttribute('stroke-linecap', 'round');
1957
- svg.setAttribute('stroke-linejoin', 'round');
1958
- const path = document.createElementNS('http://www.w3.org/2000/svg', 'polyline');
1959
- // Right chevron (>) when not compact, left chevron (<) when compact
1960
- path.setAttribute('points', isCompact ? '15 18 9 12 15 6' : '9 18 15 12 9 6');
1961
- svg.appendChild(path);
1962
- btn.appendChild(svg);
1963
- return btn;
1964
- }
1965
- /**
1966
- * Create a settings section with title
1967
- */
1968
- createSettingsSection(title, hasBorder = true) {
1969
- const color = COLORS.textSecondary;
1970
- const section = document.createElement('div');
1971
- Object.assign(section.style, {
1972
- padding: '10px 14px',
1973
- borderBottom: hasBorder ? `1px solid ${color}20` : 'none',
1974
- });
1975
- const sectionTitle = document.createElement('div');
1976
- Object.assign(sectionTitle.style, {
1977
- color,
1978
- fontSize: '0.625rem',
1979
- textTransform: 'uppercase',
1980
- letterSpacing: '0.1em',
1981
- marginBottom: '8px',
1982
- });
1983
- sectionTitle.textContent = title;
1984
- section.appendChild(sectionTitle);
1985
- return section;
1986
- }
1987
- /**
1988
- * Create a toggle switch row
1989
- */
1990
- createToggleRow(label, checked, accentColor, onChange) {
1991
- const color = COLORS.textSecondary;
1992
- const row = document.createElement('div');
1993
- Object.assign(row.style, {
1994
- display: 'flex',
1995
- alignItems: 'center',
1996
- justifyContent: 'space-between',
1997
- marginBottom: '6px',
1998
- });
1999
- const labelEl = document.createElement('span');
2000
- Object.assign(labelEl.style, { color: COLORS.text, fontSize: '0.6875rem' });
2001
- labelEl.textContent = label;
2002
- row.appendChild(labelEl);
2003
- const toggle = document.createElement('button');
2004
- Object.assign(toggle.style, {
2005
- width: '32px',
2006
- height: '18px',
2007
- borderRadius: '9px',
2008
- border: 'none',
2009
- backgroundColor: checked ? accentColor : `${color}40`,
2010
- position: 'relative',
2011
- cursor: 'pointer',
2012
- transition: 'all 150ms',
2013
- flexShrink: '0',
2014
- });
2015
- const knob = document.createElement('span');
2016
- Object.assign(knob.style, {
2017
- position: 'absolute',
2018
- top: '2px',
2019
- left: checked ? '16px' : '2px',
2020
- width: '14px',
2021
- height: '14px',
2022
- borderRadius: '50%',
2023
- backgroundColor: '#fff',
2024
- transition: 'left 150ms',
2025
- });
2026
- toggle.appendChild(knob);
2027
- toggle.onclick = onChange;
2028
- row.appendChild(toggle);
2029
- return row;
2030
- }
2031
- /**
2032
- * Render the settings popover
2033
- */
2034
- renderSettingsPopover() {
2035
- const { position, accentColor } = this.options;
2036
- const color = COLORS.textSecondary;
2037
- const popover = document.createElement('div');
2038
- popover.setAttribute('data-devbar', 'true');
2039
- // Position based on devbar position
2040
- const isTop = position.startsWith('top');
2041
- const isRight = position.includes('right');
2042
- Object.assign(popover.style, {
2043
- position: 'fixed',
2044
- [isTop ? 'top' : 'bottom']: isTop ? '70px' : '70px',
2045
- [isRight ? 'right' : 'left']: isRight ? '16px' : '80px',
2046
- zIndex: '10003',
2047
- backgroundColor: 'rgba(17, 24, 39, 0.98)',
2048
- border: `1px solid ${accentColor}`,
2049
- borderRadius: '8px',
2050
- boxShadow: `0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px ${accentColor}33`,
2051
- backdropFilter: 'blur(8px)',
2052
- WebkitBackdropFilter: 'blur(8px)',
2053
- minWidth: '240px',
2054
- maxWidth: '280px',
2055
- maxHeight: 'calc(100vh - 100px)',
2056
- overflowY: 'auto',
2057
- fontFamily: FONT_MONO,
2058
- });
2059
- // Header
2060
- const header = document.createElement('div');
2061
- Object.assign(header.style, {
2062
- display: 'flex',
2063
- alignItems: 'center',
2064
- justifyContent: 'space-between',
2065
- padding: '10px 14px',
2066
- borderBottom: `1px solid ${accentColor}30`,
2067
- position: 'sticky',
2068
- top: '0',
2069
- backgroundColor: 'rgba(17, 24, 39, 0.98)',
2070
- zIndex: '1',
2071
- });
2072
- const title = document.createElement('span');
2073
- Object.assign(title.style, { color: accentColor, fontSize: '0.75rem', fontWeight: '600' });
2074
- title.textContent = 'Settings';
2075
- header.appendChild(title);
2076
- const closeBtn = createStyledButton({
2077
- color: COLORS.textMuted,
2078
- text: '×',
2079
- padding: '2px 6px',
2080
- fontSize: '0.875rem',
2081
- });
2082
- closeBtn.style.border = 'none';
2083
- closeBtn.onclick = () => {
2084
- this.showSettingsPopover = false;
2085
- this.render();
2086
- };
2087
- header.appendChild(closeBtn);
2088
- popover.appendChild(header);
2089
- // ========== THEME SECTION ==========
2090
- const themeSection = this.createSettingsSection('Theme');
2091
- const themeOptions = document.createElement('div');
2092
- Object.assign(themeOptions.style, { display: 'flex', gap: '6px' });
2093
- const themeModes = ['system', 'dark', 'light'];
2094
- themeModes.forEach((mode) => {
2095
- const btn = document.createElement('button');
2096
- const isActive = this.themeMode === mode;
2097
- Object.assign(btn.style, {
2098
- padding: '4px 10px',
2099
- backgroundColor: isActive ? `${accentColor}20` : 'transparent',
2100
- border: `1px solid ${isActive ? accentColor : `${color}40`}`,
2101
- borderRadius: '4px',
2102
- color: isActive ? accentColor : color,
2103
- fontSize: '0.625rem',
2104
- cursor: 'pointer',
2105
- textTransform: 'capitalize',
2106
- transition: 'all 150ms',
2107
- });
2108
- btn.textContent = mode;
2109
- btn.onclick = () => {
2110
- this.setThemeMode(mode);
2111
- };
2112
- themeOptions.appendChild(btn);
2113
- });
2114
- themeSection.appendChild(themeOptions);
2115
- popover.appendChild(themeSection);
2116
- // ========== DISPLAY SECTION ==========
2117
- const displaySection = this.createSettingsSection('Display');
2118
- // Position mini-map selector
2119
- const positionRow = document.createElement('div');
2120
- Object.assign(positionRow.style, { marginBottom: '10px' });
2121
- const posLabel = document.createElement('div');
2122
- Object.assign(posLabel.style, {
2123
- color: COLORS.text,
2124
- fontSize: '0.6875rem',
2125
- marginBottom: '6px',
2126
- });
2127
- posLabel.textContent = 'Position';
2128
- positionRow.appendChild(posLabel);
2129
- // Mini-map container
2130
- const miniMap = document.createElement('div');
2131
- Object.assign(miniMap.style, {
2132
- position: 'relative',
2133
- width: '100%',
2134
- height: '50px',
2135
- backgroundColor: 'rgba(10, 15, 26, 0.6)',
2136
- border: `1px solid ${color}30`,
2137
- borderRadius: '4px',
2138
- });
2139
- const positionConfigs = [
2140
- { value: 'top-left', style: { top: '8px', left: '10%' }, title: 'Top Left' },
2141
- { value: 'top-right', style: { top: '8px', right: '6%' }, title: 'Top Right' },
2142
- { value: 'bottom-left', style: { bottom: '8px', left: '10%' }, title: 'Bottom Left' },
2143
- { value: 'bottom-right', style: { bottom: '8px', right: '6%' }, title: 'Bottom Right' },
2144
- {
2145
- value: 'bottom-center',
2146
- style: { bottom: '6px', left: '50%', transform: 'translateX(-50%)' },
2147
- title: 'Bottom Center',
2148
- },
2149
- ];
2150
- positionConfigs.forEach(({ value, style, title }) => {
2151
- const indicator = document.createElement('button');
2152
- const isActive = this.options.position === value;
2153
- Object.assign(indicator.style, {
2154
- position: 'absolute',
2155
- width: '20px',
2156
- height: '6px',
2157
- backgroundColor: isActive ? accentColor : `${color}60`,
2158
- border: `1px solid ${isActive ? accentColor : `${color}40`}`,
2159
- borderRadius: '2px',
2160
- cursor: 'pointer',
2161
- padding: '0',
2162
- transition: 'all 150ms',
2163
- boxShadow: isActive ? `0 0 8px ${accentColor}60` : 'none',
2164
- ...style,
2165
- });
2166
- indicator.title = title;
2167
- indicator.onclick = () => {
2168
- this.options.position = value;
2169
- this.settingsManager.saveSettings({ position: value });
2170
- this.render();
2171
- };
2172
- // Hover effect
2173
- indicator.onmouseenter = () => {
2174
- if (!isActive) {
2175
- indicator.style.backgroundColor = accentColor;
2176
- indicator.style.borderColor = accentColor;
2177
- indicator.style.boxShadow = `0 0 6px ${accentColor}40`;
2178
- }
2179
- };
2180
- indicator.onmouseleave = () => {
2181
- if (!isActive) {
2182
- indicator.style.backgroundColor = `${color}60`;
2183
- indicator.style.borderColor = `${color}40`;
2184
- indicator.style.boxShadow = 'none';
2185
- }
2186
- };
2187
- miniMap.appendChild(indicator);
2188
- });
2189
- positionRow.appendChild(miniMap);
2190
- displaySection.appendChild(positionRow);
2191
- // Compact mode toggle
2192
- displaySection.appendChild(this.createToggleRow('Compact Mode', this.compactMode, accentColor, () => {
2193
- this.toggleCompactMode();
2194
- }));
2195
- // Keyboard shortcut hint
2196
- const shortcutHint = document.createElement('div');
2197
- Object.assign(shortcutHint.style, {
2198
- color: COLORS.textMuted,
2199
- fontSize: '0.5625rem',
2200
- marginTop: '2px',
2201
- marginBottom: '8px',
2202
- });
2203
- shortcutHint.textContent = 'Keyboard: Cmd+Shift+M';
2204
- displaySection.appendChild(shortcutHint);
2205
- // Accent color
2206
- const accentRow = document.createElement('div');
2207
- Object.assign(accentRow.style, { marginBottom: '6px' });
2208
- const accentLabel = document.createElement('div');
2209
- Object.assign(accentLabel.style, {
2210
- color: COLORS.text,
2211
- fontSize: '0.6875rem',
2212
- marginBottom: '6px',
2213
- });
2214
- accentLabel.textContent = 'Accent Color';
2215
- accentRow.appendChild(accentLabel);
2216
- const colorSwatches = document.createElement('div');
2217
- Object.assign(colorSwatches.style, {
2218
- display: 'flex',
2219
- gap: '6px',
2220
- flexWrap: 'wrap',
2221
- });
2222
- ACCENT_COLOR_PRESETS.forEach(({ name, value }) => {
2223
- const swatch = document.createElement('button');
2224
- const isActive = this.options.accentColor === value;
2225
- Object.assign(swatch.style, {
2226
- width: '24px',
2227
- height: '24px',
2228
- borderRadius: '50%',
2229
- backgroundColor: value,
2230
- border: isActive ? '2px solid #fff' : '2px solid transparent',
2231
- cursor: 'pointer',
2232
- transition: 'all 150ms',
2233
- boxShadow: isActive ? `0 0 8px ${value}` : 'none',
2234
- });
2235
- swatch.title = name;
2236
- swatch.onclick = () => {
2237
- this.options.accentColor = value;
2238
- this.settingsManager.saveSettings({ accentColor: value });
2239
- this.render();
2240
- };
2241
- colorSwatches.appendChild(swatch);
2242
- });
2243
- accentRow.appendChild(colorSwatches);
2244
- displaySection.appendChild(accentRow);
2245
- popover.appendChild(displaySection);
2246
- // ========== FEATURES SECTION ==========
2247
- const featuresSection = this.createSettingsSection('Features');
2248
- featuresSection.appendChild(this.createToggleRow('Screenshot Button', this.options.showScreenshot, accentColor, () => {
2249
- this.options.showScreenshot = !this.options.showScreenshot;
2250
- this.settingsManager.saveSettings({ showScreenshot: this.options.showScreenshot });
2251
- this.render();
2252
- }));
2253
- featuresSection.appendChild(this.createToggleRow('Console Badges', this.options.showConsoleBadges, accentColor, () => {
2254
- this.options.showConsoleBadges = !this.options.showConsoleBadges;
2255
- this.settingsManager.saveSettings({ showConsoleBadges: this.options.showConsoleBadges });
2256
- this.render();
2257
- }));
2258
- featuresSection.appendChild(this.createToggleRow('Tooltips', this.options.showTooltips, accentColor, () => {
2259
- this.options.showTooltips = !this.options.showTooltips;
2260
- this.settingsManager.saveSettings({ showTooltips: this.options.showTooltips });
2261
- this.render();
2262
- }));
2263
- popover.appendChild(featuresSection);
2264
- // ========== METRICS SECTION ==========
2265
- const metricsSection = this.createSettingsSection('Metrics');
2266
- const metricsToggles = [
2267
- { key: 'breakpoint', label: 'Breakpoint' },
2268
- { key: 'fcp', label: 'FCP' },
2269
- { key: 'lcp', label: 'LCP' },
2270
- { key: 'cls', label: 'CLS' },
2271
- { key: 'inp', label: 'INP' },
2272
- { key: 'pageSize', label: 'Page Size' },
2273
- ];
2274
- metricsToggles.forEach(({ key, label }) => {
2275
- const currentValue = this.options.showMetrics[key] ?? true;
2276
- metricsSection.appendChild(this.createToggleRow(label, currentValue, accentColor, () => {
2277
- this.options.showMetrics[key] = !this.options.showMetrics[key];
2278
- this.settingsManager.saveSettings({
2279
- showMetrics: {
2280
- breakpoint: this.options.showMetrics.breakpoint ?? true,
2281
- fcp: this.options.showMetrics.fcp ?? true,
2282
- lcp: this.options.showMetrics.lcp ?? true,
2283
- cls: this.options.showMetrics.cls ?? true,
2284
- inp: this.options.showMetrics.inp ?? true,
2285
- pageSize: this.options.showMetrics.pageSize ?? true,
2286
- },
2287
- });
2288
- this.render();
2289
- }));
2290
- });
2291
- popover.appendChild(metricsSection);
2292
- // ========== RESET SECTION ==========
2293
- const resetSection = document.createElement('div');
2294
- Object.assign(resetSection.style, {
2295
- padding: '10px 14px',
2296
- borderTop: `1px solid ${color}20`,
2297
- });
2298
- const resetBtn = createStyledButton({
2299
- color: COLORS.textMuted,
2300
- text: 'Reset to Defaults',
2301
- padding: '6px 12px',
2302
- fontSize: '0.625rem',
2303
- });
2304
- Object.assign(resetBtn.style, {
2305
- width: '100%',
2306
- justifyContent: 'center',
2307
- });
2308
- resetBtn.onclick = () => {
2309
- this.resetToDefaults();
2310
- };
2311
- resetSection.appendChild(resetBtn);
2312
- popover.appendChild(resetSection);
2313
- this.overlayElement = popover;
2314
- document.body.appendChild(popover);
2315
- }
2316
- /**
2317
- * Reset all settings to defaults
2318
- */
2319
- resetToDefaults() {
2320
- this.settingsManager.resetToDefaults();
2321
- const defaults = DEFAULT_SETTINGS;
2322
- this.applySettings(defaults);
2323
- }
2324
- renderCollapsed() {
2325
- if (!this.container)
2326
- return;
2327
- const { position, accentColor } = this.options;
2328
- const { errorCount, warningCount } = this.getLogCounts();
2329
- // Use captured dot position if available, otherwise fall back to preset positions
2330
- // The 13px offset accounts for half the collapsed circle diameter (26px / 2)
2331
- let posStyle;
2332
- if (this.lastDotPosition) {
2333
- // Position based on where the dot actually was
2334
- const isTop = position.startsWith('top');
2335
- posStyle = isTop
2336
- ? { top: `${this.lastDotPosition.top - 13}px`, left: `${this.lastDotPosition.left - 13}px` }
2337
- : {
2338
- bottom: `${this.lastDotPosition.bottom - 13}px`,
2339
- left: `${this.lastDotPosition.left - 13}px`,
2340
- };
2341
- }
2342
- else {
2343
- // Fallback preset positions for when no dot position was captured
2344
- const collapsedPositions = {
2345
- 'bottom-left': { bottom: '27px', left: '86px' },
2346
- 'bottom-right': { bottom: '27px', right: '29px' },
2347
- 'top-left': { top: '27px', left: '86px' },
2348
- 'top-right': { top: '27px', right: '29px' },
2349
- 'bottom-center': { bottom: '19px', left: '50%', transform: 'translateX(-50%)' },
2350
- };
2351
- posStyle = collapsedPositions[position] ?? collapsedPositions['bottom-left'];
2352
- }
2353
- const wrapper = this.container;
2354
- wrapper.className = this.tooltipClass('left', 'devbar-collapse');
2355
- wrapper.setAttribute('data-tooltip', `Click to expand DevBar${this.sweetlinkConnected ? ' (Sweetlink connected)' : ' (Sweetlink not connected)'}${errorCount > 0 ? `\n${errorCount} console error${errorCount === 1 ? '' : 's'}` : ''}`);
2356
- // Reset position properties first to avoid stale values
2357
- wrapper.style.top = '';
2358
- wrapper.style.bottom = '';
2359
- wrapper.style.left = '';
2360
- wrapper.style.right = '';
2361
- wrapper.style.transform = '';
2362
- Object.assign(wrapper.style, {
2363
- position: 'fixed',
2364
- ...posStyle,
2365
- zIndex: '9999',
2366
- backgroundColor: 'rgba(17, 24, 39, 0.95)',
2367
- border: `1px solid ${accentColor}`,
2368
- borderRadius: '50%',
2369
- color: accentColor,
2370
- boxShadow: `0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 1px ${accentColor}1A`,
2371
- backdropFilter: 'blur(8px)',
2372
- WebkitBackdropFilter: 'blur(8px)',
2373
- cursor: 'pointer',
2374
- display: 'flex',
2375
- alignItems: 'center',
2376
- justifyContent: 'center',
2377
- width: '26px',
2378
- height: '26px',
2379
- boxSizing: 'border-box',
2380
- animation: 'devbar-collapse 150ms ease-out',
2381
- });
2382
- wrapper.onclick = () => {
2383
- this.collapsed = false;
2384
- this.debug.state('Expanded DevBar');
2385
- this.render();
2386
- };
2387
- // Connection indicator dot (same size as in expanded state)
2388
- const dot = document.createElement('span');
2389
- Object.assign(dot.style, {
2390
- width: '6px',
2391
- height: '6px',
2392
- borderRadius: '50%',
2393
- backgroundColor: this.sweetlinkConnected ? COLORS.primary : COLORS.textMuted,
2394
- boxShadow: this.sweetlinkConnected ? `0 0 6px ${COLORS.primary}` : 'none',
2395
- });
2396
- wrapper.appendChild(dot);
2397
- // Error badge (absolute, top-right of circle, shifted left if warning badge exists)
2398
- if (errorCount > 0) {
2399
- wrapper.appendChild(this.createCollapsedBadge(errorCount, 'rgba(239, 68, 68, 0.95)', warningCount > 0 ? '12px' : '-6px'));
2400
- }
2401
- // Warning badge (absolute, top-right)
2402
- if (warningCount > 0) {
2403
- wrapper.appendChild(this.createCollapsedBadge(warningCount, 'rgba(245, 158, 11, 0.95)', '-6px'));
2404
- }
2405
- }
2406
- renderExpanded() {
2407
- if (!this.container)
2408
- return;
2409
- const { position, accentColor, showMetrics, showScreenshot, showConsoleBadges } = this.options;
2410
- const { errorCount, warningCount } = this.getLogCounts();
2411
- const positionStyles = {
2412
- 'bottom-left': { bottom: '20px', left: '80px' },
2413
- 'bottom-right': { bottom: '20px', right: '16px' },
2414
- 'top-left': { top: '20px', left: '80px' },
2415
- 'top-right': { top: '20px', right: '16px' },
2416
- 'bottom-center': { bottom: '12px', left: '50%', transform: 'translateX(-50%)' },
2417
- };
2418
- const posStyle = positionStyles[position] ?? positionStyles['bottom-left'];
2419
- const isCentered = position === 'bottom-center';
2420
- const sizeOverrides = this.options.sizeOverrides;
2421
- const wrapper = this.container;
2422
- // Reset position properties first to avoid stale values from previous renders
2423
- wrapper.style.top = '';
2424
- wrapper.style.bottom = '';
2425
- wrapper.style.left = '';
2426
- wrapper.style.right = '';
2427
- wrapper.style.transform = '';
2428
- // Calculate size values with overrides or defaults
2429
- // Width always fit-content, maxWidth prevents overlap with other dev bars
2430
- // BASE breakpoint (<640px) wraps buttons to centered second row via CSS
2431
- const defaultWidth = 'fit-content';
2432
- const defaultMinWidth = 'auto';
2433
- const defaultMaxWidth = isCentered ? 'calc(100vw - 140px)' : 'calc(100vw - 32px)';
2434
- Object.assign(wrapper.style, {
2435
- position: 'fixed',
2436
- ...posStyle,
2437
- zIndex: '9999',
2438
- backgroundColor: 'rgba(17, 24, 39, 0.95)',
2439
- border: `1px solid ${accentColor}`,
2440
- borderRadius: '12px',
2441
- color: accentColor,
2442
- boxShadow: `0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 1px ${accentColor}1A`,
2443
- backdropFilter: 'blur(8px)',
2444
- WebkitBackdropFilter: 'blur(8px)',
2445
- boxSizing: 'border-box',
2446
- width: sizeOverrides?.width ?? defaultWidth,
2447
- maxWidth: sizeOverrides?.maxWidth ?? defaultMaxWidth,
2448
- minWidth: sizeOverrides?.minWidth ?? defaultMinWidth,
2449
- cursor: 'default',
2450
- });
2451
- wrapper.ondblclick = () => {
2452
- // Capture dot position before collapsing
2453
- const dotEl = wrapper.querySelector('.devbar-status span span');
2454
- if (dotEl) {
2455
- const rect = dotEl.getBoundingClientRect();
2456
- this.lastDotPosition = {
2457
- left: rect.left + rect.width / 2,
2458
- top: rect.top + rect.height / 2,
2459
- bottom: window.innerHeight - (rect.top + rect.height / 2),
2460
- };
2461
- }
2462
- this.collapsed = true;
2463
- this.debug.state('Collapsed DevBar (double-click)');
2464
- this.render();
2465
- };
2466
- // Main row - wrapping controlled by CSS media query
2467
- const mainRow = document.createElement('div');
2468
- mainRow.className = 'devbar-main';
2469
- Object.assign(mainRow.style, {
2470
- display: 'flex',
2471
- alignItems: 'center',
2472
- alignContent: 'flex-start',
2473
- justifyContent: 'flex-start',
2474
- gap: '0.5rem',
2475
- padding: '0.5rem 0.75rem',
2476
- minWidth: '0',
2477
- boxSizing: 'border-box',
2478
- fontFamily: FONT_MONO,
2479
- fontSize: '0.6875rem',
2480
- lineHeight: '1rem',
2481
- });
2482
- // Connection indicator (click to collapse)
2483
- const connIndicator = document.createElement('span');
2484
- connIndicator.className = this.tooltipClass('left', 'devbar-clickable');
2485
- connIndicator.setAttribute('data-tooltip', this.sweetlinkConnected
2486
- ? 'Sweetlink connected (click to minimize)'
2487
- : 'Sweetlink disconnected (click to minimize)');
2488
- Object.assign(connIndicator.style, {
2489
- width: '12px',
2490
- height: '12px',
2491
- borderRadius: '50%',
2492
- backgroundColor: 'transparent',
2493
- display: 'flex',
2494
- alignItems: 'center',
2495
- justifyContent: 'center',
2496
- cursor: 'pointer',
2497
- flexShrink: '0',
2498
- });
2499
- connIndicator.onclick = (e) => {
2500
- e.stopPropagation();
2501
- // Capture dot position before collapsing (connDot is the inner 6px dot)
2502
- const rect = connIndicator.getBoundingClientRect();
2503
- this.lastDotPosition = {
2504
- left: rect.left + rect.width / 2,
2505
- top: rect.top + rect.height / 2,
2506
- bottom: window.innerHeight - (rect.top + rect.height / 2),
2507
- };
2508
- this.collapsed = true;
2509
- this.debug.state('Collapsed DevBar (connection dot click)');
2510
- this.render();
2511
- };
2512
- const connDot = document.createElement('span');
2513
- Object.assign(connDot.style, {
2514
- width: '6px',
2515
- height: '6px',
2516
- borderRadius: '50%',
2517
- backgroundColor: this.sweetlinkConnected ? COLORS.primary : COLORS.textMuted,
2518
- boxShadow: this.sweetlinkConnected ? `0 0 6px ${COLORS.primary}` : 'none',
2519
- transition: 'all 300ms',
2520
- });
2521
- connIndicator.appendChild(connDot);
2522
- // Status row wrapper - keeps connection dot, info, and badges together
2523
- const statusRow = document.createElement('div');
2524
- statusRow.className = 'devbar-status';
2525
- Object.assign(statusRow.style, {
2526
- display: 'flex',
2527
- alignItems: 'center',
2528
- gap: '0.5rem',
2529
- flexWrap: 'nowrap',
2530
- flexShrink: '0',
2531
- });
2532
- statusRow.appendChild(connIndicator);
2533
- // Info section
2534
- const infoSection = document.createElement('div');
2535
- infoSection.className = 'devbar-info';
2536
- Object.assign(infoSection.style, {
2537
- display: 'flex',
2538
- alignItems: 'center',
2539
- gap: '0.5rem',
2540
- textTransform: 'uppercase',
2541
- letterSpacing: '0.05em',
2542
- flexShrink: '1',
2543
- minWidth: '0',
2544
- overflow: 'visible',
2545
- });
2546
- // Breakpoint info
2547
- if (showMetrics.breakpoint && this.breakpointInfo) {
2548
- const bp = this.breakpointInfo.tailwindBreakpoint;
2549
- const breakpointData = TAILWIND_BREAKPOINTS[bp];
2550
- const bpSpan = document.createElement('span');
2551
- bpSpan.className = this.tooltipClass('left', 'devbar-item');
2552
- Object.assign(bpSpan.style, { opacity: '0.9', cursor: 'default' });
2553
- bpSpan.setAttribute('data-tooltip', `Tailwind Breakpoint: ${bp}\n${breakpointData?.label || ''}\n\nViewport: ${this.breakpointInfo.dimensions}\n\nBreakpoints:\nbase: <640px | sm: >=640px\nmd: >=768px | lg: >=1024px\nxl: >=1280px | 2xl: >=1536px`);
2554
- let bpText = bp;
2555
- if (bp !== 'base') {
2556
- bpText =
2557
- bp === 'sm'
2558
- ? `${bp} - ${this.breakpointInfo.dimensions.split('x')[0]}`
2559
- : `${bp} - ${this.breakpointInfo.dimensions}`;
2560
- }
2561
- bpSpan.textContent = bpText;
2562
- infoSection.appendChild(bpSpan);
2563
- }
2564
- // Performance stats
2565
- if (this.perfStats) {
2566
- const addSeparator = () => {
2567
- const sep = document.createElement('span');
2568
- sep.style.opacity = '0.4';
2569
- sep.textContent = '|';
2570
- infoSection.appendChild(sep);
2571
- };
2572
- if (showMetrics.fcp) {
2573
- addSeparator();
2574
- const fcpSpan = document.createElement('span');
2575
- fcpSpan.className = this.tooltipClass('left', 'devbar-item');
2576
- Object.assign(fcpSpan.style, { opacity: '0.85', cursor: 'default' });
2577
- fcpSpan.setAttribute('data-tooltip', 'First Contentful Paint (FCP): Time until first text/image renders.\n\nGood: <1.8s\nNeeds work: 1.8-3s\nPoor: >3s');
2578
- fcpSpan.textContent = `FCP ${this.perfStats.fcp}`;
2579
- infoSection.appendChild(fcpSpan);
2580
- }
2581
- if (showMetrics.lcp) {
2582
- addSeparator();
2583
- const lcpSpan = document.createElement('span');
2584
- lcpSpan.className = this.tooltipClass('left', 'devbar-item');
2585
- Object.assign(lcpSpan.style, { opacity: '0.85', cursor: 'default' });
2586
- lcpSpan.setAttribute('data-tooltip', 'Largest Contentful Paint (LCP): Time until largest visible element renders.\n\nGood: <2.5s\nNeeds work: 2.5-4s\nPoor: >4s');
2587
- lcpSpan.textContent = `LCP ${this.perfStats.lcp}`;
2588
- infoSection.appendChild(lcpSpan);
2589
- }
2590
- if (showMetrics.cls) {
2591
- addSeparator();
2592
- const clsSpan = document.createElement('span');
2593
- clsSpan.className = this.tooltipClass('left', 'devbar-item');
2594
- Object.assign(clsSpan.style, { opacity: '0.85', cursor: 'default' });
2595
- clsSpan.setAttribute('data-tooltip', 'Cumulative Layout Shift (CLS): Visual stability score.\nHigher values mean more unexpected layout shifts.\n\nGood: <0.1\nNeeds work: 0.1-0.25\nPoor: >0.25');
2596
- clsSpan.textContent = `CLS ${this.perfStats.cls}`;
2597
- infoSection.appendChild(clsSpan);
2598
- }
2599
- if (showMetrics.inp) {
2600
- addSeparator();
2601
- const inpSpan = document.createElement('span');
2602
- inpSpan.className = this.tooltipClass('left', 'devbar-item');
2603
- Object.assign(inpSpan.style, { opacity: '0.85', cursor: 'default' });
2604
- inpSpan.setAttribute('data-tooltip', 'Interaction to Next Paint (INP): Responsiveness to user input.\nMeasures the longest interaction delay.\n\nGood: <200ms\nNeeds work: 200-500ms\nPoor: >500ms');
2605
- inpSpan.textContent = `INP ${this.perfStats.inp}`;
2606
- infoSection.appendChild(inpSpan);
2607
- }
2608
- if (showMetrics.pageSize) {
2609
- addSeparator();
2610
- const sizeSpan = document.createElement('span');
2611
- sizeSpan.className = this.tooltipClass('left', 'devbar-item');
2612
- Object.assign(sizeSpan.style, { opacity: '0.7', cursor: 'default' });
2613
- sizeSpan.setAttribute('data-tooltip', 'Total page size (compressed/transferred).\nIncludes HTML, CSS, JS, images, and other resources.');
2614
- sizeSpan.textContent = this.perfStats.totalSize;
2615
- infoSection.appendChild(sizeSpan);
2616
- }
2617
- }
2618
- statusRow.appendChild(infoSection);
2619
- // Console badges - add to status row so they stay with info
2620
- if (showConsoleBadges) {
2621
- if (errorCount > 0) {
2622
- statusRow.appendChild(this.createConsoleBadge('error', errorCount, BUTTON_COLORS.error));
2623
- }
2624
- if (warningCount > 0) {
2625
- statusRow.appendChild(this.createConsoleBadge('warn', warningCount, BUTTON_COLORS.warning));
2626
- }
2627
- }
2628
- mainRow.appendChild(statusRow);
2629
- // Action buttons - always render container for consistent height
2630
- const actionsContainer = document.createElement('div');
2631
- actionsContainer.className = 'devbar-actions';
2632
- if (showScreenshot) {
2633
- actionsContainer.appendChild(this.createScreenshotButton(accentColor));
2634
- }
2635
- actionsContainer.appendChild(this.createAIReviewButton());
2636
- actionsContainer.appendChild(this.createOutlineButton());
2637
- actionsContainer.appendChild(this.createSchemaButton());
2638
- actionsContainer.appendChild(this.createSettingsButton());
2639
- actionsContainer.appendChild(this.createCompactToggleButton());
2640
- mainRow.appendChild(actionsContainer);
2641
- wrapper.appendChild(mainRow);
2642
- // Render custom controls row if there are any
2643
- if (GlobalDevBar.customControls.length > 0) {
2644
- const customRow = document.createElement('div');
2645
- Object.assign(customRow.style, {
2646
- display: 'flex',
2647
- flexWrap: 'wrap',
2648
- alignItems: 'center',
2649
- gap: '0.5rem',
2650
- padding: '0 0.75rem 0.5rem 0.75rem',
2651
- borderTop: `1px solid ${accentColor}30`,
2652
- marginTop: '0',
2653
- paddingTop: '0.5rem',
2654
- fontFamily: FONT_MONO,
2655
- fontSize: '0.6875rem',
2656
- });
2657
- GlobalDevBar.customControls.forEach((control) => {
2658
- const btn = document.createElement('button');
2659
- btn.type = 'button';
2660
- const color = control.variant === 'warning' ? BUTTON_COLORS.warning : accentColor;
2661
- const isActive = control.active ?? false;
2662
- const isDisabled = control.disabled ?? false;
2663
- Object.assign(btn.style, {
2664
- padding: '4px 10px',
2665
- backgroundColor: isActive ? `${color}33` : 'transparent',
2666
- border: `1px solid ${isActive ? color : `${color}60`}`,
2667
- borderRadius: '6px',
2668
- color: isActive ? color : `${color}99`,
2669
- fontSize: '0.625rem',
2670
- cursor: isDisabled ? 'not-allowed' : 'pointer',
2671
- opacity: isDisabled ? '0.5' : '1',
2672
- transition: 'all 150ms',
2673
- });
2674
- btn.textContent = control.label;
2675
- btn.disabled = isDisabled;
2676
- if (!isDisabled) {
2677
- btn.onmouseenter = () => {
2678
- btn.style.backgroundColor = `${color}20`;
2679
- btn.style.borderColor = color;
2680
- btn.style.color = color;
2681
- };
2682
- btn.onmouseleave = () => {
2683
- btn.style.backgroundColor = isActive ? `${color}33` : 'transparent';
2684
- btn.style.borderColor = isActive ? color : `${color}60`;
2685
- btn.style.color = isActive ? color : `${color}99`;
2686
- };
2687
- btn.onclick = () => control.onClick();
2688
- }
2689
- customRow.appendChild(btn);
2690
- });
2691
- wrapper.appendChild(customRow);
2692
- }
2693
- }
2694
- /**
2695
- * Create a console badge for error/warning counts
2696
- */
2697
- createConsoleBadge(type, count, color) {
2698
- const label = type === 'error' ? 'error' : 'warning';
2699
- const isActive = this.consoleFilter === type;
2700
- const badge = document.createElement('span');
2701
- badge.className = this.tooltipClass('right', 'devbar-badge');
2702
- badge.setAttribute('data-tooltip', `${count} console ${label}${count === 1 ? '' : 's'} (click to view)`);
2703
- Object.assign(badge.style, {
2704
- display: 'flex',
2705
- alignItems: 'center',
2706
- justifyContent: 'center',
2707
- minWidth: '18px',
2708
- height: '18px',
2709
- padding: '0 5px',
2710
- borderRadius: '9999px',
2711
- backgroundColor: isActive ? color : `${color}E6`,
2712
- color: '#fff',
2713
- fontSize: '0.625rem',
2714
- fontWeight: '600',
2715
- cursor: 'pointer',
2716
- boxShadow: isActive ? `0 0 8px ${color}CC` : 'none',
2717
- });
2718
- badge.textContent = count > 99 ? '99+' : String(count);
2719
- badge.onclick = () => {
2720
- this.consoleFilter = this.consoleFilter === type ? null : type;
2721
- this.showOutlineModal = false;
2722
- this.showSchemaModal = false;
2723
- this.render();
2724
- };
2725
- return badge;
2726
- }
2727
- createScreenshotButton(accentColor) {
2728
- const btn = document.createElement('button');
2729
- btn.type = 'button';
2730
- btn.className = this.tooltipClass('right');
2731
- const hasSuccessState = this.copiedToClipboard || this.copiedPath || this.lastScreenshot;
2732
- const tooltip = this.getScreenshotTooltip();
2733
- btn.setAttribute('data-tooltip', tooltip);
2734
- Object.assign(btn.style, {
2735
- display: 'flex',
2736
- alignItems: 'center',
2737
- justifyContent: 'center',
2738
- width: '22px',
2739
- height: '22px',
2740
- minWidth: '22px',
2741
- minHeight: '22px',
2742
- flexShrink: '0',
2743
- borderRadius: '50%',
2744
- border: '1px solid',
2745
- borderColor: hasSuccessState ? accentColor : `${accentColor}80`,
2746
- backgroundColor: hasSuccessState ? `${accentColor}33` : 'transparent',
2747
- color: hasSuccessState ? accentColor : `${accentColor}99`,
2748
- cursor: !this.capturing ? 'pointer' : 'not-allowed',
2749
- opacity: '1',
2750
- transition: 'all 150ms',
2751
- });
2752
- btn.disabled = this.capturing;
2753
- btn.onclick = (e) => {
2754
- // If we have a saved screenshot path, clicking copies the path
2755
- if (this.lastScreenshot && !e.shiftKey) {
2756
- this.copyPathToClipboard(this.lastScreenshot);
2757
- }
2758
- else {
2759
- this.handleScreenshot(e.shiftKey);
2760
- }
2761
- };
2762
- // Button content
2763
- if (this.copiedToClipboard || this.copiedPath || this.lastScreenshot) {
2764
- btn.textContent = '✓';
2765
- btn.style.fontSize = '0.6rem';
2766
- }
2767
- else if (this.capturing) {
2768
- btn.textContent = '...';
2769
- btn.style.fontSize = '0.5rem';
2770
- }
2771
- else {
2772
- // Camera icon SVG
2773
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
2774
- svg.setAttribute('width', '12');
2775
- svg.setAttribute('height', '12');
2776
- svg.setAttribute('viewBox', '0 0 50.8 50.8');
2777
- svg.style.stroke = 'currentColor';
2778
- svg.style.fill = 'none';
2779
- const g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
2780
- g.setAttribute('stroke-linecap', 'round');
2781
- g.setAttribute('stroke-linejoin', 'round');
2782
- g.setAttribute('stroke-width', '4');
2783
- const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
2784
- path.setAttribute('d', 'M19.844 7.938H7.938v11.905m0 11.113v11.906h11.905m23.019-11.906v11.906H30.956m11.906-23.018V7.938H30.956');
2785
- const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
2786
- circle.setAttribute('cx', '25.4');
2787
- circle.setAttribute('cy', '25.4');
2788
- circle.setAttribute('r', '8.731');
2789
- g.appendChild(path);
2790
- g.appendChild(circle);
2791
- svg.appendChild(g);
2792
- btn.appendChild(svg);
2793
- }
2794
- return btn;
2795
- }
2796
- /**
2797
- * Get the tooltip text for the screenshot button based on current state
2798
- */
2799
- getScreenshotTooltip() {
2800
- if (this.copiedToClipboard) {
2801
- return 'Copied to clipboard!';
2802
- }
2803
- if (this.copiedPath) {
2804
- return 'Path copied to clipboard!';
2805
- }
2806
- if (this.lastScreenshot) {
2807
- return `Screenshot saved!\n${this.lastScreenshot}\n\nClick to copy path`;
2808
- }
2809
- const baseTooltip = `Screenshot\n\nClick: Save to file\nShift+Click: Copy to clipboard\n\nKeyboard:\nCmd/Ctrl+Shift+S: Save\nCmd/Ctrl+Shift+C: Copy`;
2810
- return this.sweetlinkConnected
2811
- ? baseTooltip
2812
- : `${baseTooltip}\n\nWarning: Sweetlink not connected`;
2813
- }
2814
- /**
2815
- * Get the tooltip text for the AI review button based on current state
2816
- */
2817
- getAIReviewTooltip() {
2818
- if (this.designReviewInProgress) {
2819
- return 'AI Design Review in progress...';
2820
- }
2821
- if (this.designReviewError) {
2822
- return `Design review failed:\n${this.designReviewError}`;
2823
- }
2824
- if (this.lastDesignReview) {
2825
- return `Design review saved to:\n${this.lastDesignReview}`;
2826
- }
2827
- const baseTooltip = `AI Design Review\n\nCaptures screenshot and sends to\nClaude for design analysis.\n\nRequires ANTHROPIC_API_KEY.`;
2828
- return this.sweetlinkConnected
2829
- ? baseTooltip
2830
- : `${baseTooltip}\n\nWarning: Sweetlink not connected`;
2831
- }
2832
- createAIReviewButton() {
2833
- const btn = document.createElement('button');
2834
- btn.type = 'button';
2835
- btn.className = this.tooltipClass('right');
2836
- const tooltip = this.getAIReviewTooltip();
2837
- btn.setAttribute('data-tooltip', tooltip);
2838
- const hasError = !!this.designReviewError;
2839
- const isActive = this.designReviewInProgress || !!this.lastDesignReview || hasError;
2840
- const isDisabled = this.designReviewInProgress || !this.sweetlinkConnected;
2841
- // Use error color (red) when there's an error, otherwise normal review color
2842
- const buttonColor = hasError ? '#ef4444' : BUTTON_COLORS.review;
2843
- Object.assign(btn.style, getButtonStyles(buttonColor, isActive, isDisabled));
2844
- if (!this.sweetlinkConnected)
2845
- btn.style.opacity = '0.5';
2846
- btn.disabled = isDisabled;
2847
- btn.onclick = () => this.showDesignReviewConfirmation();
2848
- if (this.designReviewInProgress) {
2849
- btn.textContent = '~';
2850
- btn.style.fontSize = '0.5rem';
2851
- btn.style.animation = 'pulse 1s infinite';
2852
- }
2853
- else if (this.designReviewError) {
2854
- // Show 'x' for error state
2855
- btn.textContent = '×';
2856
- btn.style.fontSize = '0.875rem';
2857
- btn.style.fontWeight = 'bold';
2858
- }
2859
- else if (this.lastDesignReview) {
2860
- btn.textContent = 'v';
2861
- btn.style.fontSize = '0.5rem';
2862
- }
2863
- else {
2864
- btn.appendChild(createSvgIcon('M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 00-2.456 2.456zM16.894 20.567L16.5 21.75l-.394-1.183a2.25 2.25 0 00-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 001.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 001.423 1.423l1.183.394-1.183.394a2.25 2.25 0 00-1.423 1.423z', { fill: true }));
2865
- }
2866
- return btn;
2867
- }
2868
- createOutlineButton() {
2869
- const btn = document.createElement('button');
2870
- btn.type = 'button';
2871
- btn.className = this.tooltipClass('right');
2872
- const tooltip = this.lastOutline
2873
- ? `Outline saved to:\n${this.lastOutline}`
2874
- : `Document Outline\n\nView page heading structure and\nsave as markdown.`;
2875
- btn.setAttribute('data-tooltip', tooltip);
2876
- const isActive = this.showOutlineModal || !!this.lastOutline;
2877
- Object.assign(btn.style, getButtonStyles(BUTTON_COLORS.outline, isActive, false));
2878
- btn.onclick = () => this.handleDocumentOutline();
2879
- if (this.lastOutline) {
2880
- btn.textContent = 'v';
2881
- btn.style.fontSize = '0.5rem';
2882
- }
2883
- else {
2884
- btn.appendChild(createSvgIcon('M3 4h18v2H3V4zm0 7h12v2H3v-2zm0 7h18v2H3v-2z', { fill: true }));
2885
- }
2886
- return btn;
2887
- }
2888
- createSchemaButton() {
2889
- const btn = document.createElement('button');
2890
- btn.type = 'button';
2891
- btn.className = this.tooltipClass('right');
2892
- const tooltip = this.lastSchema
2893
- ? `Schema saved to:\n${this.lastSchema}`
2894
- : `Page Schema\n\nView JSON-LD, Open Graph, and\nother structured data.`;
2895
- btn.setAttribute('data-tooltip', tooltip);
2896
- const isActive = this.showSchemaModal || !!this.lastSchema;
2897
- Object.assign(btn.style, getButtonStyles(BUTTON_COLORS.schema, isActive, false));
2898
- btn.onclick = () => this.handlePageSchema();
2899
- if (this.lastSchema) {
2900
- btn.textContent = 'v';
2901
- btn.style.fontSize = '0.5rem';
2902
- }
2903
- else {
2904
- btn.appendChild(createSvgIcon('M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z', { fill: true }));
2905
- }
2906
- return btn;
415
+ moduleRender(this, consoleCapture, GlobalDevBar.customControls);
2907
416
  }
2908
417
  }
2909
- // Static storage for custom controls
2910
- GlobalDevBar.customControls = [];
2911
418
  // ============================================================================
2912
419
  // Convenience Functions
2913
420
  // ============================================================================
@@ -2963,5 +470,6 @@ export function destroyGlobalDevBar() {
2963
470
  setGlobalInstance(null);
2964
471
  }
2965
472
  }
2966
- // Re-export console capture for external use
2967
- export { earlyConsoleCapture };
473
+ // Re-export console capture instance for backward compatibility
474
+ export { consoleCapture as earlyConsoleCapture };
475
+ //# sourceMappingURL=GlobalDevBar.js.map