@ytspar/devbar 1.3.1 → 1.4.1

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 (93) hide show
  1. package/README.md +43 -0
  2. package/dist/accessibility.d.ts +4 -0
  3. package/dist/accessibility.d.ts.map +1 -1
  4. package/dist/accessibility.js +57 -0
  5. package/dist/accessibility.js.map +1 -1
  6. package/dist/constants.d.ts +8 -23
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/constants.js +10 -3
  9. package/dist/constants.js.map +1 -1
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/modules/index.d.ts +1 -1
  15. package/dist/modules/index.d.ts.map +1 -1
  16. package/dist/modules/index.js +1 -0
  17. package/dist/modules/index.js.map +1 -1
  18. package/dist/modules/keyboard.d.ts +1 -1
  19. package/dist/modules/keyboard.d.ts.map +1 -1
  20. package/dist/modules/keyboard.js +4 -11
  21. package/dist/modules/keyboard.js.map +1 -1
  22. package/dist/modules/rendering/buttons.d.ts +19 -0
  23. package/dist/modules/rendering/buttons.d.ts.map +1 -0
  24. package/dist/modules/rendering/buttons.js +369 -0
  25. package/dist/modules/rendering/buttons.js.map +1 -0
  26. package/dist/modules/rendering/collapsed.d.ts +6 -0
  27. package/dist/modules/rendering/collapsed.d.ts.map +1 -0
  28. package/dist/modules/rendering/collapsed.js +124 -0
  29. package/dist/modules/rendering/collapsed.js.map +1 -0
  30. package/dist/modules/rendering/common.d.ts +21 -0
  31. package/dist/modules/rendering/common.d.ts.map +1 -0
  32. package/dist/modules/rendering/common.js +60 -0
  33. package/dist/modules/rendering/common.js.map +1 -0
  34. package/dist/modules/rendering/compact.d.ts +6 -0
  35. package/dist/modules/rendering/compact.d.ts.map +1 -0
  36. package/dist/modules/rendering/compact.js +107 -0
  37. package/dist/modules/rendering/compact.js.map +1 -0
  38. package/dist/modules/rendering/console.d.ts +7 -0
  39. package/dist/modules/rendering/console.d.ts.map +1 -0
  40. package/dist/modules/rendering/console.js +78 -0
  41. package/dist/modules/rendering/console.js.map +1 -0
  42. package/dist/modules/rendering/expanded.d.ts +13 -0
  43. package/dist/modules/rendering/expanded.d.ts.map +1 -0
  44. package/dist/modules/rendering/expanded.js +439 -0
  45. package/dist/modules/rendering/expanded.js.map +1 -0
  46. package/dist/modules/rendering/index.d.ts +22 -0
  47. package/dist/modules/rendering/index.d.ts.map +1 -0
  48. package/dist/modules/rendering/index.js +109 -0
  49. package/dist/modules/rendering/index.js.map +1 -0
  50. package/dist/modules/rendering/modals.d.ts +9 -0
  51. package/dist/modules/rendering/modals.d.ts.map +1 -0
  52. package/dist/modules/rendering/modals.js +1068 -0
  53. package/dist/modules/rendering/modals.js.map +1 -0
  54. package/dist/modules/rendering/settings.d.ts +6 -0
  55. package/dist/modules/rendering/settings.d.ts.map +1 -0
  56. package/dist/modules/rendering/settings.js +605 -0
  57. package/dist/modules/rendering/settings.js.map +1 -0
  58. package/dist/modules/rendering.d.ts +15 -16
  59. package/dist/modules/rendering.d.ts.map +1 -1
  60. package/dist/modules/rendering.js +15 -2919
  61. package/dist/modules/rendering.js.map +1 -1
  62. package/dist/modules/screenshot.d.ts +11 -2
  63. package/dist/modules/screenshot.d.ts.map +1 -1
  64. package/dist/modules/screenshot.js +32 -29
  65. package/dist/modules/screenshot.js.map +1 -1
  66. package/dist/modules/tooltips.d.ts +7 -5
  67. package/dist/modules/tooltips.d.ts.map +1 -1
  68. package/dist/modules/tooltips.js +133 -157
  69. package/dist/modules/tooltips.js.map +1 -1
  70. package/dist/modules/types.d.ts +7 -0
  71. package/dist/modules/types.d.ts.map +1 -1
  72. package/dist/modules/types.js +14 -1
  73. package/dist/modules/types.js.map +1 -1
  74. package/dist/modules/websocket.d.ts.map +1 -1
  75. package/dist/modules/websocket.js +334 -264
  76. package/dist/modules/websocket.js.map +1 -1
  77. package/dist/ui/buttons.d.ts.map +1 -1
  78. package/dist/ui/buttons.js +11 -9
  79. package/dist/ui/buttons.js.map +1 -1
  80. package/dist/ui/cards.js +3 -3
  81. package/dist/ui/cards.js.map +1 -1
  82. package/dist/ui/icons.d.ts +13 -0
  83. package/dist/ui/icons.d.ts.map +1 -1
  84. package/dist/ui/icons.js +24 -3
  85. package/dist/ui/icons.js.map +1 -1
  86. package/dist/ui/index.d.ts +1 -1
  87. package/dist/ui/index.d.ts.map +1 -1
  88. package/dist/ui/index.js.map +1 -1
  89. package/dist/ui/modals.d.ts +3 -2
  90. package/dist/ui/modals.d.ts.map +1 -1
  91. package/dist/ui/modals.js +28 -26
  92. package/dist/ui/modals.js.map +1 -1
  93. package/package.json +3 -4
@@ -1,2923 +1,19 @@
1
1
  /**
2
- * Rendering: renderCollapsed, renderCompact, renderExpanded, renderOverlays,
3
- * console popups, modals, settings popover, and all DOM-creation UI code.
2
+ * Rendering barrel - re-exports from sub-modules under rendering/.
4
3
  *
5
- * Extracted from GlobalDevBar to reduce file size.
6
- */
7
- import { BUTTON_COLORS, CATEGORY_COLORS, CSS_COLORS, FONT_MONO, TAILWIND_BREAKPOINTS, } from '../constants.js';
8
- import { extractDocumentOutline, outlineToMarkdown } from '../outline.js';
9
- import { checkMissingTags, extractFavicons, extractPageSchema, isImageKey, schemaToMarkdown } from '../schema.js';
10
- import { ACCENT_COLOR_PRESETS, DEFAULT_SETTINGS, resolveSaveLocation } from '../settings.js';
11
- import { createEmptyMessage, createInfoBox, createModalBox, createModalContent, createModalHeader, createModalOverlay, createCloseButton, createStyledButton, createSvgIcon, getButtonStyles, } from '../ui/index.js';
12
- import { getResponsiveMetricVisibility } from './performance.js';
13
- import { runA11yAudit, groupViolationsByImpact, getImpactColor, getViolationCounts, preloadAxe, } from '../accessibility.js';
14
- import { calculateCostEstimate, closeDesignReviewConfirm, copyPathToClipboard, handleA11yAudit, handleDocumentOutline, handlePageSchema, handleSaveA11yAudit, handleSaveConsoleLogs, handleSaveOutline, handleSaveSchema, proceedWithDesignReview, showDesignReviewConfirmation, } from './screenshot.js';
15
- import { setThemeMode } from './theme.js';
16
- import { addTooltipTitle, attachBreakpointTooltip, attachButtonTooltip, attachClickToggleTooltip, attachInfoTooltip, attachMetricTooltip, attachTextTooltip, clearAllTooltips, } from './tooltips.js';
17
- /**
18
- * Capture the center of an element's bounding rect as a dot position.
19
- * Used to animate the collapsed circle to the same spot as the connection dot.
20
- */
21
- function captureDotPosition(state, element) {
22
- const rect = element.getBoundingClientRect();
23
- state.lastDotPosition = {
24
- left: rect.left + rect.width / 2,
25
- top: rect.top + rect.height / 2,
26
- bottom: window.innerHeight - (rect.top + rect.height / 2),
27
- };
28
- }
29
- /**
30
- * Create the connection indicator (outer wrapper + inner colored dot).
31
- * The caller is responsible for attaching tooltip and click handlers, since
32
- * those differ between compact and expanded modes.
33
- */
34
- function createConnectionIndicator(state) {
35
- const connIndicator = document.createElement('span');
36
- connIndicator.className = 'devbar-clickable';
37
- Object.assign(connIndicator.style, {
38
- width: '12px',
39
- height: '12px',
40
- borderRadius: '50%',
41
- backgroundColor: 'transparent',
42
- display: 'flex',
43
- alignItems: 'center',
44
- justifyContent: 'center',
45
- cursor: 'pointer',
46
- flexShrink: '0',
47
- });
48
- const connDot = document.createElement('span');
49
- connDot.className = 'devbar-conn-dot';
50
- Object.assign(connDot.style, {
51
- width: '6px',
52
- height: '6px',
53
- borderRadius: '50%',
54
- backgroundColor: state.sweetlinkConnected ? CSS_COLORS.primary : CSS_COLORS.textMuted,
55
- boxShadow: state.sweetlinkConnected ? `0 0 6px ${CSS_COLORS.primary}` : 'none',
56
- transition: 'all 300ms',
57
- });
58
- connIndicator.appendChild(connDot);
59
- return connIndicator;
60
- }
61
- /** Prevents re-entrant render calls during rapid clicks */
62
- let renderGuard = false;
63
- /**
64
- * Main render dispatch - creates container and delegates to appropriate renderer.
65
- */
66
- export function render(state, consoleCaptureSingleton, customControls) {
67
- if (state.destroyed)
68
- return;
69
- if (typeof document === 'undefined')
70
- return;
71
- if (renderGuard)
72
- return;
73
- renderGuard = true;
74
- // Clear any orphaned tooltips from previous render
75
- clearAllTooltips(state);
76
- // Remove existing overlay if any (modals append to body, need explicit cleanup)
77
- if (state.overlayElement) {
78
- state.overlayElement.remove();
79
- state.overlayElement = null;
80
- document.body.style.overflow = '';
81
- }
82
- // Remove existing container if any
83
- if (state.container) {
84
- state.container.remove();
85
- }
86
- // Create new container and append immediately so the devbar stays visible
87
- // even if content or overlay rendering throws
88
- state.container = document.createElement('div');
89
- state.container.setAttribute('data-devbar', 'true');
90
- state.container.setAttribute('role', 'toolbar');
91
- state.container.setAttribute('aria-label', 'DevBar');
92
- document.body.appendChild(state.container);
93
- try {
94
- if (state.collapsed) {
95
- renderCollapsed(state);
96
- }
97
- else if (state.compactMode) {
98
- renderCompact(state);
99
- }
100
- else {
101
- renderExpanded(state, customControls);
102
- }
103
- }
104
- catch (e) {
105
- console.error('[GlobalDevBar] Render failed:', e);
106
- }
107
- try {
108
- renderOverlays(state, consoleCaptureSingleton);
109
- }
110
- catch (e) {
111
- console.error('[GlobalDevBar] Overlay render failed:', e);
112
- }
113
- // Lock body scroll while a modal overlay is open
114
- if (state.overlayElement) {
115
- document.body.style.overflow = 'hidden';
116
- }
117
- renderGuard = false;
118
- }
119
- function renderOverlays(state, consoleCaptureSingleton) {
120
- // Safety: only one overlay at a time. First match wins; close the rest.
121
- // (Overlay cleanup already performed by render() before calling this.)
122
- if (state.consoleFilter) {
123
- state.showOutlineModal = false;
124
- state.showSchemaModal = false;
125
- state.showA11yModal = false;
126
- state.showDesignReviewConfirm = false;
127
- state.showSettingsPopover = false;
128
- renderConsolePopup(state, consoleCaptureSingleton);
129
- }
130
- else if (state.showOutlineModal) {
131
- state.showSchemaModal = false;
132
- state.showA11yModal = false;
133
- state.showDesignReviewConfirm = false;
134
- state.showSettingsPopover = false;
135
- renderOutlineModal(state);
136
- }
137
- else if (state.showSchemaModal) {
138
- state.showA11yModal = false;
139
- state.showDesignReviewConfirm = false;
140
- state.showSettingsPopover = false;
141
- renderSchemaModal(state);
142
- }
143
- else if (state.showA11yModal) {
144
- state.showDesignReviewConfirm = false;
145
- state.showSettingsPopover = false;
146
- renderA11yModal(state);
147
- }
148
- else if (state.showDesignReviewConfirm) {
149
- state.showSettingsPopover = false;
150
- renderDesignReviewConfirmModal(state);
151
- }
152
- else if (state.showSettingsPopover) {
153
- renderSettingsPopover(state);
154
- }
155
- }
156
- // ============================================================================
157
- // Collapsed State
158
- // ============================================================================
159
- function renderCollapsed(state) {
160
- if (!state.container)
161
- return;
162
- const { position, accentColor } = state.options;
163
- const { errorCount, warningCount } = state.getLogCounts();
164
- // Use captured dot position if available, otherwise fall back to preset positions
165
- // The 13px offset accounts for half the collapsed circle diameter (26px / 2)
166
- let posStyle;
167
- if (state.lastDotPosition) {
168
- // Position based on where the dot actually was
169
- const isTop = position.startsWith('top');
170
- posStyle = isTop
171
- ? { top: `${state.lastDotPosition.top - 13}px`, left: `${state.lastDotPosition.left - 13}px` }
172
- : {
173
- bottom: `${state.lastDotPosition.bottom - 13}px`,
174
- left: `${state.lastDotPosition.left - 13}px`,
175
- };
176
- // Clear after use so expand doesn't re-use stale values
177
- state.lastDotPosition = null;
178
- }
179
- else {
180
- // Fallback preset positions for when no dot position was captured
181
- const collapsedPositions = {
182
- 'bottom-left': { bottom: '27px', left: '86px' },
183
- 'bottom-right': { bottom: '27px', right: '29px' },
184
- 'top-left': { top: '27px', left: '86px' },
185
- 'top-right': { top: '27px', right: '29px' },
186
- 'bottom-center': { bottom: '19px', left: '50%', transform: 'translateX(-50%)' },
187
- };
188
- posStyle = collapsedPositions[position] ?? collapsedPositions['bottom-left'];
189
- }
190
- const wrapper = state.container;
191
- wrapper.className = 'devbar-collapse';
192
- state.resetPositionStyles(wrapper);
193
- // Set CSS variable for accent color (used by pulse animation)
194
- wrapper.style.setProperty('--devbar-color-accent', accentColor);
195
- Object.assign(wrapper.style, {
196
- position: 'fixed',
197
- ...posStyle,
198
- zIndex: '9999',
199
- backgroundColor: 'var(--devbar-color-bg-card)',
200
- border: `1px solid ${accentColor}`,
201
- borderRadius: '50%',
202
- color: accentColor,
203
- boxShadow: `0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 1px ${accentColor}1A`,
204
- backdropFilter: 'blur(8px)',
205
- WebkitBackdropFilter: 'blur(8px)',
206
- cursor: 'pointer',
207
- display: 'flex',
208
- alignItems: 'center',
209
- justifyContent: 'center',
210
- width: '26px',
211
- height: '26px',
212
- boxSizing: 'border-box',
213
- animation: 'devbar-collapse 150ms ease-out, devbar-collapsed-pulse 2s ease-in-out 0.2s 3',
214
- });
215
- wrapper.onclick = () => {
216
- state.collapsed = false;
217
- state.debug.state('Expanded DevBar');
218
- state.render();
219
- };
220
- // Create inner container for dot + chevron
221
- const innerContainer = document.createElement('span');
222
- Object.assign(innerContainer.style, {
223
- display: 'flex',
224
- alignItems: 'center',
225
- justifyContent: 'center',
226
- position: 'relative',
227
- });
228
- // Connection indicator dot (same size as in expanded state)
229
- const dot = document.createElement('span');
230
- Object.assign(dot.style, {
231
- width: '6px',
232
- height: '6px',
233
- borderRadius: '50%',
234
- backgroundColor: state.sweetlinkConnected ? CSS_COLORS.primary : CSS_COLORS.textMuted,
235
- boxShadow: state.sweetlinkConnected ? `0 0 6px ${CSS_COLORS.primary}` : 'none',
236
- transition: 'transform 150ms ease-out, opacity 150ms ease-out',
237
- });
238
- innerContainer.appendChild(dot);
239
- // Expand chevron indicator (appears on hover)
240
- const chevron = document.createElement('span');
241
- Object.assign(chevron.style, {
242
- position: 'absolute',
243
- width: '100%',
244
- height: '100%',
245
- display: 'flex',
246
- alignItems: 'center',
247
- justifyContent: 'center',
248
- opacity: '0',
249
- transition: 'opacity 150ms ease-out',
250
- fontSize: '10px',
251
- color: accentColor,
252
- });
253
- chevron.textContent = '\u2197';
254
- innerContainer.appendChild(chevron);
255
- attachTextTooltip(state, wrapper, () => `Click to expand DevBar${state.sweetlinkConnected ? ' (Sweetlink connected)' : ' (Sweetlink not connected)'}${errorCount > 0 ? `\n${errorCount} console error${errorCount === 1 ? '' : 's'}` : ''}`, {
256
- onEnter: () => {
257
- dot.style.opacity = '0';
258
- dot.style.transform = 'scale(0)';
259
- chevron.style.opacity = '1';
260
- },
261
- onLeave: () => {
262
- dot.style.opacity = '1';
263
- dot.style.transform = 'scale(1)';
264
- chevron.style.opacity = '0';
265
- },
266
- });
267
- wrapper.appendChild(innerContainer);
268
- // Error badge (absolute, top-right of circle, shifted left if warning badge exists)
269
- if (errorCount > 0) {
270
- wrapper.appendChild(state.createCollapsedBadge(errorCount, 'rgba(239, 68, 68, 0.95)', warningCount > 0 ? '12px' : '-6px'));
271
- }
272
- // Warning badge (absolute, top-right)
273
- if (warningCount > 0) {
274
- wrapper.appendChild(state.createCollapsedBadge(warningCount, 'rgba(245, 158, 11, 0.95)', '-6px'));
275
- }
276
- }
277
- // ============================================================================
278
- // Compact State
279
- // ============================================================================
280
- function renderCompact(state) {
281
- if (!state.container)
282
- return;
283
- const { position, accentColor } = state.options;
284
- const { errorCount, warningCount, infoCount } = state.getLogCounts();
285
- // Simple position styles - same anchor points as expanded mode
286
- const positionStyles = {
287
- 'bottom-left': { bottom: '20px', left: '80px' },
288
- 'bottom-right': { bottom: '20px', right: '16px' },
289
- 'top-left': { top: '20px', left: '80px' },
290
- 'top-right': { top: '20px', right: '16px' },
291
- 'bottom-center': { bottom: '12px', left: '50%', transform: 'translateX(-50%)' },
292
- };
293
- const posStyle = positionStyles[position] ?? positionStyles['bottom-left'];
294
- const wrapper = state.container;
295
- state.resetPositionStyles(wrapper);
296
- Object.assign(wrapper.style, {
297
- position: 'fixed',
298
- ...posStyle,
299
- zIndex: '9999',
300
- backgroundColor: 'var(--devbar-color-bg-card)',
301
- border: `1px solid ${accentColor}`,
302
- borderRadius: '20px',
303
- color: accentColor,
304
- boxShadow: `0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 1px ${accentColor}1A`,
305
- backdropFilter: 'blur(8px)',
306
- WebkitBackdropFilter: 'blur(8px)',
307
- padding: '6px 10px',
308
- display: 'flex',
309
- alignItems: 'center',
310
- gap: '8px',
311
- fontFamily: FONT_MONO,
312
- fontSize: '0.6875rem',
313
- });
314
- // Connection indicator
315
- const connIndicator = createConnectionIndicator(state);
316
- const connDot = connIndicator.querySelector('.devbar-conn-dot');
317
- attachTextTooltip(state, connIndicator, () => state.sweetlinkConnected ? 'Sweetlink connected' : 'Sweetlink disconnected');
318
- connIndicator.onclick = (e) => {
319
- e.stopPropagation();
320
- captureDotPosition(state, connDot);
321
- state.collapsed = true;
322
- state.debug.state('Collapsed DevBar from compact mode');
323
- state.render();
324
- };
325
- wrapper.appendChild(connIndicator);
326
- // Error badge
327
- if (errorCount > 0) {
328
- wrapper.appendChild(createConsoleBadge(state, 'error', errorCount, BUTTON_COLORS.error));
329
- }
330
- // Warning badge
331
- if (warningCount > 0) {
332
- wrapper.appendChild(createConsoleBadge(state, 'warn', warningCount, BUTTON_COLORS.warning));
333
- }
334
- // Info badge
335
- if (infoCount > 0) {
336
- wrapper.appendChild(createConsoleBadge(state, 'info', infoCount, BUTTON_COLORS.info));
337
- }
338
- // Screenshot button (if enabled)
339
- if (state.options.showScreenshot) {
340
- wrapper.appendChild(createScreenshotButton(state, accentColor));
341
- }
342
- // Settings gear button
343
- wrapper.appendChild(createSettingsButton(state));
344
- // Expand button (double-arrow)
345
- const expandBtn = document.createElement('button');
346
- expandBtn.type = 'button';
347
- Object.assign(expandBtn.style, {
348
- display: 'flex',
349
- alignItems: 'center',
350
- justifyContent: 'center',
351
- width: '18px',
352
- height: '18px',
353
- borderRadius: '50%',
354
- border: `1px solid ${accentColor}60`,
355
- backgroundColor: 'transparent',
356
- color: `${accentColor}99`,
357
- cursor: 'pointer',
358
- fontSize: '0.5rem',
359
- transition: 'all 150ms',
360
- });
361
- expandBtn.textContent = '\u27EB';
362
- attachTextTooltip(state, expandBtn, () => 'Expand DevBar', {
363
- onEnter: () => {
364
- expandBtn.style.backgroundColor = `${accentColor}20`;
365
- expandBtn.style.borderColor = accentColor;
366
- expandBtn.style.color = accentColor;
367
- },
368
- onLeave: () => {
369
- expandBtn.style.backgroundColor = 'transparent';
370
- expandBtn.style.borderColor = `${accentColor}60`;
371
- expandBtn.style.color = `${accentColor}99`;
372
- },
373
- });
374
- expandBtn.onclick = () => {
375
- state.toggleCompactMode();
376
- };
377
- wrapper.appendChild(expandBtn);
378
- }
379
- // ============================================================================
380
- // Expanded State
381
- // ============================================================================
382
- function renderExpanded(state, customControls) {
383
- if (!state.container)
384
- return;
385
- const { position, accentColor, showMetrics, showScreenshot, showConsoleBadges } = state.options;
386
- const { errorCount, warningCount, infoCount } = state.getLogCounts();
387
- // Dot offset from container edge in expanded mode:
388
- // border (1px) + padding (12px) + half indicator (6px) = 19px from left
389
- // border (1px) + padding (8px) + half indicator (6px) = 15px from top
390
- const DOT_OFFSET_LEFT = 19;
391
- const DOT_OFFSET_TOP = 15;
392
- const isCentered = position === 'bottom-center';
393
- let posStyle;
394
- // Use captured dot position to align the expanded bar's dot with where it was
395
- // Always use top/left positioning for precise alignment
396
- if (state.lastDotPosition && !isCentered) {
397
- const isRight = position.endsWith('right');
398
- if (isRight) {
399
- // For right-aligned, fall back to default
400
- const isTop = position.startsWith('top');
401
- posStyle = isTop ? { top: '20px', right: '16px' } : { bottom: '20px', right: '16px' };
402
- }
403
- else {
404
- // Use top positioning for precise dot alignment
405
- posStyle = {
406
- top: `${state.lastDotPosition.top - DOT_OFFSET_TOP}px`,
407
- left: `${state.lastDotPosition.left - DOT_OFFSET_LEFT}px`,
408
- };
409
- }
410
- // Clear the position after using it
411
- state.lastDotPosition = null;
412
- }
413
- else {
414
- const positionStyles = {
415
- 'bottom-left': { bottom: '20px', left: '80px' },
416
- 'bottom-right': { bottom: '20px', right: '16px' },
417
- 'top-left': { top: '20px', left: '80px' },
418
- 'top-right': { top: '20px', right: '16px' },
419
- 'bottom-center': { bottom: '12px', left: '50%', transform: 'translateX(-50%)' },
420
- };
421
- posStyle = positionStyles[position] ?? positionStyles['bottom-left'];
422
- }
423
- const sizeOverrides = state.options.sizeOverrides;
424
- const wrapper = state.container;
425
- state.resetPositionStyles(wrapper);
426
- // Calculate size values with overrides or defaults
427
- // Use fit-content so DevBar only takes space it needs, but allow expansion up to max
428
- // Centered: 16px margin each side. Left/right: 80px for Next.js bar + 16px margin
429
- const defaultWidth = 'fit-content';
430
- const defaultMinWidth = 'auto';
431
- const defaultMaxWidth = isCentered ? 'calc(100vw - 32px)' : 'calc(100vw - 96px)';
432
- Object.assign(wrapper.style, {
433
- position: 'fixed',
434
- ...posStyle,
435
- zIndex: '9999',
436
- backgroundColor: 'var(--devbar-color-bg-card)',
437
- border: `1px solid ${accentColor}`,
438
- borderRadius: '12px',
439
- color: accentColor,
440
- boxShadow: `0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 1px ${accentColor}1A`,
441
- backdropFilter: 'blur(8px)',
442
- WebkitBackdropFilter: 'blur(8px)',
443
- boxSizing: 'border-box',
444
- width: sizeOverrides?.width ?? defaultWidth,
445
- maxWidth: sizeOverrides?.maxWidth ?? defaultMaxWidth,
446
- minWidth: sizeOverrides?.minWidth ?? defaultMinWidth,
447
- cursor: 'default',
448
- });
449
- wrapper.ondblclick = (e) => {
450
- // Ignore double-clicks on interactive elements (buttons, inputs, selects)
451
- // to prevent rapid settings-button clicks from collapsing the devbar
452
- const target = e.target;
453
- if (target?.closest('button, input, select, a'))
454
- return;
455
- const dotEl = wrapper.querySelector('.devbar-status span span');
456
- if (dotEl) {
457
- captureDotPosition(state, dotEl);
458
- }
459
- state.collapsed = true;
460
- state.debug.state('Collapsed DevBar (double-click)');
461
- state.render();
462
- };
463
- // Main row - wrapping controlled by CSS media query
464
- const mainRow = document.createElement('div');
465
- mainRow.className = 'devbar-main';
466
- Object.assign(mainRow.style, {
467
- display: 'flex',
468
- alignItems: 'center',
469
- alignContent: 'flex-start',
470
- justifyContent: 'flex-start',
471
- gap: '0.5rem',
472
- padding: '0.5rem 0.75rem',
473
- minWidth: '0',
474
- boxSizing: 'border-box',
475
- fontFamily: FONT_MONO,
476
- fontSize: '0.6875rem',
477
- lineHeight: '1rem',
478
- });
479
- // Connection indicator (click to collapse)
480
- const connIndicator = createConnectionIndicator(state);
481
- attachTextTooltip(state, connIndicator, () => state.sweetlinkConnected
482
- ? 'Sweetlink connected (click to minimize)'
483
- : 'Sweetlink disconnected (click to minimize)');
484
- connIndicator.onclick = (e) => {
485
- e.stopPropagation();
486
- captureDotPosition(state, connIndicator);
487
- state.collapsed = true;
488
- state.debug.state('Collapsed DevBar (connection dot click)');
489
- state.render();
490
- };
491
- // Status row wrapper - keeps connection dot, info, and badges together
492
- const statusRow = document.createElement('div');
493
- statusRow.className = 'devbar-status';
494
- Object.assign(statusRow.style, {
495
- display: 'flex',
496
- alignItems: 'center',
497
- gap: '0.5rem',
498
- flexWrap: 'nowrap',
499
- flexShrink: '0',
500
- });
501
- statusRow.appendChild(connIndicator);
502
- // Info section
503
- const infoSection = document.createElement('div');
504
- infoSection.className = 'devbar-info';
505
- Object.assign(infoSection.style, {
506
- display: 'flex',
507
- alignItems: 'center',
508
- gap: '0.5rem',
509
- textTransform: 'uppercase',
510
- letterSpacing: '0.05em',
511
- flexShrink: '1',
512
- minWidth: '0',
513
- overflow: 'visible',
514
- });
515
- // Breakpoint info
516
- if (showMetrics.breakpoint && state.breakpointInfo) {
517
- const bp = state.breakpointInfo.tailwindBreakpoint;
518
- const breakpointData = TAILWIND_BREAKPOINTS[bp];
519
- const bpSpan = document.createElement('span');
520
- bpSpan.className = 'devbar-item';
521
- Object.assign(bpSpan.style, { opacity: '0.9', cursor: 'default' });
522
- // Use HTML tooltip for breakpoint info
523
- attachBreakpointTooltip(state, bpSpan, bp, state.breakpointInfo.dimensions, breakpointData?.label || '');
524
- let bpText = bp;
525
- if (bp !== 'base') {
526
- bpText =
527
- bp === 'sm'
528
- ? `${bp} - ${state.breakpointInfo.dimensions.split('x')[0]}`
529
- : `${bp} - ${state.breakpointInfo.dimensions}`;
530
- }
531
- bpSpan.textContent = bpText;
532
- infoSection.appendChild(bpSpan);
533
- }
534
- // Performance stats with responsive visibility
535
- if (state.perfStats) {
536
- const { visible, hidden } = getResponsiveMetricVisibility(state);
537
- const addSeparator = () => {
538
- const sep = document.createElement('span');
539
- sep.style.opacity = '0.4';
540
- sep.textContent = '|';
541
- infoSection.appendChild(sep);
542
- };
543
- // Metric configurations for reuse
544
- const metricConfigs = {
545
- fcp: {
546
- label: 'FCP',
547
- value: state.perfStats.fcp,
548
- title: 'First Contentful Paint (FCP)',
549
- description: 'Time until the first text or image renders on screen.',
550
- thresholds: { good: '<1.8s', needsWork: '1.8-3s', poor: '>3s' },
551
- },
552
- lcp: {
553
- label: 'LCP',
554
- value: state.perfStats.lcp,
555
- title: 'Largest Contentful Paint (LCP)',
556
- description: 'Time until the largest visible element renders on screen.',
557
- thresholds: { good: '<2.5s', needsWork: '2.5-4s', poor: '>4s' },
558
- },
559
- cls: {
560
- label: 'CLS',
561
- value: state.perfStats.cls,
562
- title: 'Cumulative Layout Shift (CLS)',
563
- description: 'Visual stability score. Higher values mean more unexpected layout shifts.',
564
- thresholds: { good: '<0.1', needsWork: '0.1-0.25', poor: '>0.25' },
565
- },
566
- inp: {
567
- label: 'INP',
568
- value: state.perfStats.inp,
569
- title: 'Interaction to Next Paint (INP)',
570
- description: 'Responsiveness to user input. Measures the longest interaction delay.',
571
- thresholds: { good: '<200ms', needsWork: '200-500ms', poor: '>500ms' },
572
- },
573
- pageSize: {
574
- label: '',
575
- value: state.perfStats.totalSize,
576
- title: 'Total Page Size',
577
- description: 'Compressed/transferred size including HTML, CSS, JS, images, and other resources.',
578
- },
579
- };
580
- // Render visible metrics
581
- for (const metric of visible) {
582
- if (!showMetrics[metric])
583
- continue;
584
- const config = metricConfigs[metric];
585
- addSeparator();
586
- const span = document.createElement('span');
587
- span.className = 'devbar-item';
588
- Object.assign(span.style, {
589
- opacity: metric === 'pageSize' ? '0.7' : '0.85',
590
- cursor: 'default',
591
- });
592
- span.textContent = config.label ? `${config.label} ${config.value}` : config.value;
593
- if (config.thresholds) {
594
- attachMetricTooltip(state, span, config.title, config.description, config.thresholds);
595
- }
596
- else {
597
- attachInfoTooltip(state, span, config.title, config.description);
598
- }
599
- infoSection.appendChild(span);
600
- }
601
- // Render ellipsis button for hidden metrics
602
- const hiddenMetricsEnabled = hidden.filter((m) => showMetrics[m]);
603
- if (hiddenMetricsEnabled.length > 0) {
604
- addSeparator();
605
- const ellipsisBtn = document.createElement('span');
606
- ellipsisBtn.className = 'devbar-item devbar-clickable';
607
- Object.assign(ellipsisBtn.style, {
608
- opacity: '0.7',
609
- cursor: 'pointer',
610
- padding: '0 2px',
611
- });
612
- ellipsisBtn.textContent = '\u00B7\u00B7\u00B7';
613
- // Attach click-toggle tooltip showing hidden metrics (for mobile support)
614
- attachClickToggleTooltip(state, ellipsisBtn, (tooltip) => {
615
- addTooltipTitle(state, tooltip, 'More Metrics');
616
- const metricsContainer = document.createElement('div');
617
- Object.assign(metricsContainer.style, {
618
- display: 'flex',
619
- flexDirection: 'column',
620
- gap: '6px',
621
- marginTop: '8px',
622
- });
623
- for (const metric of hiddenMetricsEnabled) {
624
- const config = metricConfigs[metric];
625
- const row = document.createElement('div');
626
- Object.assign(row.style, {
627
- display: 'flex',
628
- justifyContent: 'space-between',
629
- gap: '12px',
630
- });
631
- const labelSpan = document.createElement('span');
632
- Object.assign(labelSpan.style, { color: CSS_COLORS.textMuted });
633
- labelSpan.textContent = config.title.split('(')[0].trim();
634
- const valueSpan = document.createElement('span');
635
- Object.assign(valueSpan.style, { color: CSS_COLORS.text, fontWeight: '500' });
636
- valueSpan.textContent = config.value;
637
- row.appendChild(labelSpan);
638
- row.appendChild(valueSpan);
639
- metricsContainer.appendChild(row);
640
- }
641
- tooltip.appendChild(metricsContainer);
642
- });
643
- infoSection.appendChild(ellipsisBtn);
644
- }
645
- }
646
- statusRow.appendChild(infoSection);
647
- // Console badges - add to status row so they stay with info
648
- if (showConsoleBadges) {
649
- if (errorCount > 0) {
650
- statusRow.appendChild(createConsoleBadge(state, 'error', errorCount, BUTTON_COLORS.error));
651
- }
652
- if (warningCount > 0) {
653
- statusRow.appendChild(createConsoleBadge(state, 'warn', warningCount, BUTTON_COLORS.warning));
654
- }
655
- if (infoCount > 0) {
656
- statusRow.appendChild(createConsoleBadge(state, 'info', infoCount, BUTTON_COLORS.info));
657
- }
658
- }
659
- mainRow.appendChild(statusRow);
660
- // Action buttons - always render container for consistent height
661
- const actionsContainer = document.createElement('div');
662
- actionsContainer.className = 'devbar-actions';
663
- if (showScreenshot) {
664
- actionsContainer.appendChild(createScreenshotButton(state, accentColor));
665
- }
666
- actionsContainer.appendChild(createAIReviewButton(state));
667
- actionsContainer.appendChild(createOutlineButton(state));
668
- actionsContainer.appendChild(createSchemaButton(state));
669
- actionsContainer.appendChild(createA11yButton(state));
670
- actionsContainer.appendChild(createSettingsButton(state));
671
- actionsContainer.appendChild(createCompactToggleButton(state));
672
- mainRow.appendChild(actionsContainer);
673
- wrapper.appendChild(mainRow);
674
- // Render custom controls row if there are any
675
- if (customControls.length > 0) {
676
- const customRow = document.createElement('div');
677
- Object.assign(customRow.style, {
678
- display: 'flex',
679
- flexWrap: 'wrap',
680
- alignItems: 'center',
681
- gap: '0.5rem',
682
- padding: '0 0.75rem 0.5rem 0.75rem',
683
- borderTop: `1px solid ${accentColor}30`,
684
- marginTop: '0',
685
- paddingTop: '0.5rem',
686
- fontFamily: FONT_MONO,
687
- fontSize: '0.6875rem',
688
- });
689
- customControls.forEach((control) => {
690
- const btn = document.createElement('button');
691
- btn.type = 'button';
692
- const color = control.variant === 'warning' ? BUTTON_COLORS.warning : accentColor;
693
- const isActive = control.active ?? false;
694
- const isDisabled = control.disabled ?? false;
695
- Object.assign(btn.style, {
696
- padding: '4px 10px',
697
- backgroundColor: isActive ? `${color}33` : 'transparent',
698
- border: `1px solid ${isActive ? color : `${color}60`}`,
699
- borderRadius: '6px',
700
- color: isActive ? color : `${color}99`,
701
- fontSize: '0.625rem',
702
- cursor: isDisabled ? 'not-allowed' : 'pointer',
703
- opacity: isDisabled ? '0.5' : '1',
704
- transition: 'all 150ms',
705
- });
706
- btn.textContent = control.label;
707
- btn.disabled = isDisabled;
708
- if (!isDisabled) {
709
- btn.onmouseenter = () => {
710
- btn.style.backgroundColor = `${color}20`;
711
- btn.style.borderColor = color;
712
- btn.style.color = color;
713
- };
714
- btn.onmouseleave = () => {
715
- btn.style.backgroundColor = isActive ? `${color}33` : 'transparent';
716
- btn.style.borderColor = isActive ? color : `${color}60`;
717
- btn.style.color = isActive ? color : `${color}99`;
718
- };
719
- btn.onclick = () => control.onClick();
720
- }
721
- customRow.appendChild(btn);
722
- });
723
- wrapper.appendChild(customRow);
724
- }
725
- }
726
- // ============================================================================
727
- // Button Creators
728
- // ============================================================================
729
- function createConsoleBadge(state, type, count, color) {
730
- const labelMap = { error: 'error', warn: 'warning', info: 'info' };
731
- const label = labelMap[type];
732
- const isActive = state.consoleFilter === type;
733
- const badge = document.createElement('span');
734
- badge.className = 'devbar-badge';
735
- Object.assign(badge.style, {
736
- display: 'flex',
737
- alignItems: 'center',
738
- justifyContent: 'center',
739
- minWidth: '18px',
740
- height: '18px',
741
- padding: '0 5px',
742
- borderRadius: '9999px',
743
- backgroundColor: isActive ? color : `${color}E6`,
744
- color: '#fff',
745
- fontSize: '0.625rem',
746
- fontWeight: '600',
747
- cursor: 'pointer',
748
- boxShadow: isActive ? `0 0 8px ${color}CC` : 'none',
749
- });
750
- badge.textContent = count > 99 ? '99+' : String(count);
751
- attachTextTooltip(state, badge, () => `${count} console ${label}${count === 1 ? '' : 's'} (click to view)`);
752
- badge.onclick = () => {
753
- state.consoleFilter = state.consoleFilter === type ? null : type;
754
- state.showOutlineModal = false;
755
- state.showSchemaModal = false;
756
- state.showSettingsPopover = false;
757
- state.render();
758
- };
759
- return badge;
760
- }
761
- function createScreenshotButton(state, accentColor) {
762
- const btn = document.createElement('button');
763
- btn.type = 'button';
764
- btn.setAttribute('aria-label', 'Screenshot');
765
- const hasSuccessState = state.copiedToClipboard || state.copiedPath || state.lastScreenshot;
766
- const isDisabled = state.capturing;
767
- const effectiveSave = resolveSaveLocation(state.options.saveLocation, state.sweetlinkConnected);
768
- // Grey out only when effective save is 'local' but sweetlink not connected (explicit 'local' setting)
769
- const isGreyedOut = effectiveSave === 'local' && !state.sweetlinkConnected && !hasSuccessState;
770
- // Attach HTML tooltip
771
- attachButtonTooltip(state, btn, accentColor, (tooltip, h) => {
772
- if (state.copiedToClipboard) {
773
- h.addSuccess('Copied to clipboard!');
774
- return;
775
- }
776
- if (state.copiedPath) {
777
- h.addSuccess('Path copied to clipboard!');
778
- return;
779
- }
780
- if (state.lastScreenshot) {
781
- const screenshotPath = state.lastScreenshot;
782
- const isDownloaded = screenshotPath.endsWith('downloaded');
783
- if (isDownloaded) {
784
- h.addSuccess('Screenshot downloaded!');
785
- }
786
- else {
787
- h.addSuccess('Screenshot saved!', screenshotPath);
788
- const copyLink = document.createElement('div');
789
- Object.assign(copyLink.style, {
790
- color: accentColor,
791
- cursor: 'pointer',
792
- fontSize: '0.625rem',
793
- marginTop: '6px',
794
- opacity: '0.8',
795
- transition: 'opacity 150ms',
796
- });
797
- copyLink.textContent = 'copy path';
798
- copyLink.onmouseenter = () => {
799
- copyLink.style.opacity = '1';
800
- };
801
- copyLink.onmouseleave = () => {
802
- copyLink.style.opacity = '0.8';
803
- };
804
- copyLink.onclick = async (e) => {
805
- e.stopPropagation();
806
- try {
807
- await navigator.clipboard.writeText(screenshotPath);
808
- copyLink.textContent = '\u2713 copied!';
809
- copyLink.style.cursor = 'default';
810
- copyLink.onclick = null;
811
- }
812
- catch {
813
- copyLink.textContent = '\u00d7 failed to copy';
814
- copyLink.style.color = CSS_COLORS.error;
815
- }
816
- };
817
- tooltip.appendChild(copyLink);
818
- }
819
- return;
820
- }
821
- h.addTitle('Screenshot');
822
- h.addSectionHeader('Actions');
823
- if (effectiveSave === 'local' && !state.sweetlinkConnected) {
824
- h.addShortcut('Shift+Click', 'Copy to clipboard');
825
- h.addWarning('Sweetlink not connected. Switch save method to Auto or Download.');
826
- }
827
- else {
828
- const saveLabel = effectiveSave === 'local' ? 'Save to file' : 'Download';
829
- h.addShortcut('Click', saveLabel);
830
- h.addShortcut('Shift+Click', 'Copy to clipboard');
831
- h.addSectionHeader('Keyboard');
832
- h.addShortcut('Cmd or Ctrl+Shift+S', saveLabel);
833
- h.addShortcut('Cmd or Ctrl+Shift+C', 'Copy');
834
- }
835
- });
836
- Object.assign(btn.style, {
837
- display: 'flex',
838
- alignItems: 'center',
839
- justifyContent: 'center',
840
- width: '22px',
841
- height: '22px',
842
- minWidth: '22px',
843
- minHeight: '22px',
844
- flexShrink: '0',
845
- borderRadius: '50%',
846
- border: '1px solid',
847
- borderColor: hasSuccessState ? accentColor : `${accentColor}80`,
848
- backgroundColor: hasSuccessState ? `${accentColor}33` : 'transparent',
849
- color: hasSuccessState ? accentColor : `${accentColor}99`,
850
- cursor: !isDisabled ? 'pointer' : 'not-allowed',
851
- opacity: isGreyedOut ? '0.4' : '1',
852
- transition: 'all 150ms',
853
- });
854
- btn.disabled = isDisabled;
855
- btn.onclick = (e) => {
856
- // If we have a saved screenshot path, clicking copies the path
857
- if (state.lastScreenshot && !e.shiftKey) {
858
- copyPathToClipboard(state, state.lastScreenshot);
859
- }
860
- else {
861
- state.handleScreenshot(e.shiftKey);
862
- }
863
- };
864
- // Button content
865
- if (state.copiedToClipboard || state.copiedPath || state.lastScreenshot) {
866
- btn.textContent = '\u2713';
867
- btn.style.fontSize = '0.6rem';
868
- }
869
- else if (state.capturing) {
870
- btn.textContent = '...';
871
- btn.style.fontSize = '0.5rem';
872
- }
873
- else {
874
- // Camera icon SVG
875
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
876
- svg.setAttribute('width', '12');
877
- svg.setAttribute('height', '12');
878
- svg.setAttribute('viewBox', '0 0 50.8 50.8');
879
- svg.style.stroke = 'currentColor';
880
- svg.style.fill = 'none';
881
- const g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
882
- g.setAttribute('stroke-linecap', 'round');
883
- g.setAttribute('stroke-linejoin', 'round');
884
- g.setAttribute('stroke-width', '4');
885
- const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
886
- path.setAttribute('d', 'M19.844 7.938H7.938v11.905m0 11.113v11.906h11.905m23.019-11.906v11.906H30.956m11.906-23.018V7.938H30.956');
887
- const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
888
- circle.setAttribute('cx', '25.4');
889
- circle.setAttribute('cy', '25.4');
890
- circle.setAttribute('r', '8.731');
891
- g.appendChild(path);
892
- g.appendChild(circle);
893
- svg.appendChild(g);
894
- btn.appendChild(svg);
895
- }
896
- return btn;
897
- }
898
- function createAIReviewButton(state) {
899
- const btn = document.createElement('button');
900
- btn.type = 'button';
901
- btn.setAttribute('aria-label', 'AI Design Review');
902
- const hasError = !!state.designReviewError;
903
- const isActive = state.designReviewInProgress || !!state.lastDesignReview || hasError;
904
- const isDisabled = state.designReviewInProgress || !state.sweetlinkConnected;
905
- // Use error color (red) when there's an error, otherwise normal review color
906
- const buttonColor = hasError ? CSS_COLORS.error : BUTTON_COLORS.review;
907
- // Attach HTML tooltip
908
- attachButtonTooltip(state, btn, buttonColor, (_tooltip, h) => {
909
- if (state.designReviewInProgress) {
910
- h.addProgress('AI Design Review in progress...');
911
- return;
912
- }
913
- if (state.designReviewError) {
914
- h.addError('Design review failed', state.designReviewError);
915
- return;
916
- }
917
- if (state.lastDesignReview) {
918
- h.addSuccess('Design review saved!', state.lastDesignReview);
919
- return;
920
- }
921
- h.addTitle('AI Design Review');
922
- h.addDescription('Captures screenshot and sends to Claude for design analysis.');
923
- h.addSectionHeader('Requirements');
924
- h.addShortcut('API Key', 'ANTHROPIC_API_KEY');
925
- if (!state.sweetlinkConnected) {
926
- h.addWarning('Sweetlink not connected');
927
- }
928
- });
929
- Object.assign(btn.style, getButtonStyles(buttonColor, isActive, isDisabled));
930
- if (!state.sweetlinkConnected)
931
- btn.style.opacity = '0.5';
932
- btn.disabled = isDisabled;
933
- btn.onclick = () => showDesignReviewConfirmation(state);
934
- if (state.designReviewInProgress) {
935
- btn.textContent = '~';
936
- btn.style.fontSize = '0.5rem';
937
- btn.style.animation = 'pulse 1s infinite';
938
- }
939
- else if (state.designReviewError) {
940
- // Show 'x' for error state
941
- btn.textContent = '\u00D7';
942
- btn.style.fontSize = '0.875rem';
943
- btn.style.fontWeight = 'bold';
944
- }
945
- else if (state.lastDesignReview) {
946
- btn.textContent = 'v';
947
- btn.style.fontSize = '0.5rem';
948
- }
949
- else {
950
- 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 }));
951
- }
952
- return btn;
953
- }
954
- function createOutlineButton(state) {
955
- const btn = document.createElement('button');
956
- btn.type = 'button';
957
- btn.setAttribute('aria-label', 'Document Outline');
958
- const isActive = state.showOutlineModal || !!state.lastOutline;
959
- // Attach HTML tooltip
960
- attachButtonTooltip(state, btn, BUTTON_COLORS.outline, (_tooltip, h) => {
961
- if (state.lastOutline) {
962
- const isDownloaded = state.lastOutline.endsWith('downloaded');
963
- h.addSuccess(isDownloaded ? 'Outline downloaded!' : 'Outline saved!', isDownloaded ? undefined : state.lastOutline);
964
- return;
965
- }
966
- h.addTitle('Document Outline');
967
- h.addDescription('View page heading structure and save as markdown.');
968
- if (state.options.saveLocation === 'local' && !state.sweetlinkConnected) {
969
- h.addWarning('Sweetlink not connected. Switch save method to Auto or Download.');
970
- }
971
- });
972
- Object.assign(btn.style, getButtonStyles(BUTTON_COLORS.outline, isActive, false));
973
- btn.onclick = () => handleDocumentOutline(state);
974
- if (state.lastOutline) {
975
- btn.textContent = 'v';
976
- btn.style.fontSize = '0.5rem';
977
- }
978
- else {
979
- btn.appendChild(createSvgIcon('M3 4h18v2H3V4zm0 7h12v2H3v-2zm0 7h18v2H3v-2z', { fill: true }));
980
- }
981
- return btn;
982
- }
983
- function createSchemaButton(state) {
984
- const btn = document.createElement('button');
985
- btn.type = 'button';
986
- btn.setAttribute('aria-label', 'Page Schema');
987
- const isActive = state.showSchemaModal || !!state.lastSchema;
988
- // Attach HTML tooltip
989
- attachButtonTooltip(state, btn, BUTTON_COLORS.schema, (_tooltip, h) => {
990
- if (state.lastSchema) {
991
- const isDownloaded = state.lastSchema.endsWith('downloaded');
992
- h.addSuccess(isDownloaded ? 'Schema downloaded!' : 'Schema saved!', isDownloaded ? undefined : state.lastSchema);
993
- return;
994
- }
995
- h.addTitle('Page Schema');
996
- h.addDescription('View JSON-LD, Open Graph, and other structured data.');
997
- if (state.options.saveLocation === 'local' && !state.sweetlinkConnected) {
998
- h.addWarning('Sweetlink not connected. Switch save method to Auto or Download.');
999
- }
1000
- });
1001
- Object.assign(btn.style, getButtonStyles(BUTTON_COLORS.schema, isActive, false));
1002
- btn.onclick = () => handlePageSchema(state);
1003
- if (state.lastSchema) {
1004
- btn.textContent = 'v';
1005
- btn.style.fontSize = '0.5rem';
1006
- }
1007
- else {
1008
- 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 }));
1009
- }
1010
- return btn;
1011
- }
1012
- function createA11yButton(state) {
1013
- const btn = document.createElement('button');
1014
- btn.type = 'button';
1015
- btn.setAttribute('aria-label', 'Accessibility Audit');
1016
- const isActive = state.showA11yModal || !!state.lastA11yAudit;
1017
- attachButtonTooltip(state, btn, BUTTON_COLORS.a11y, (_tooltip, h) => {
1018
- if (state.lastA11yAudit) {
1019
- const isDownloaded = state.lastA11yAudit.endsWith('downloaded');
1020
- h.addSuccess(isDownloaded ? 'A11y report downloaded!' : 'A11y report saved!', isDownloaded ? undefined : state.lastA11yAudit);
1021
- return;
1022
- }
1023
- h.addTitle('Accessibility Audit');
1024
- h.addDescription('Run axe-core audit to check WCAG compliance.');
1025
- if (state.options.saveLocation === 'local' && !state.sweetlinkConnected) {
1026
- h.addWarning('Sweetlink not connected. Switch save method to Auto or Download.');
1027
- }
1028
- });
1029
- // Preload axe-core on hover
1030
- btn.addEventListener('mouseenter', () => preloadAxe(), { once: true });
1031
- Object.assign(btn.style, getButtonStyles(BUTTON_COLORS.a11y, isActive, false));
1032
- btn.onclick = () => handleA11yAudit(state);
1033
- if (state.lastA11yAudit) {
1034
- btn.textContent = 'v';
1035
- btn.style.fontSize = '0.5rem';
1036
- }
1037
- else {
1038
- // Accessibility/shield icon
1039
- btn.appendChild(createSvgIcon('M12 1L3 5v6c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V5l-9-4zm-2 16l-4-4 1.41-1.41L10 14.17l6.59-6.59L18 9l-8 8z', { fill: true }));
1040
- }
1041
- return btn;
1042
- }
1043
- /**
1044
- * Create the settings gear button.
1045
- */
1046
- function createSettingsButton(state) {
1047
- const btn = document.createElement('button');
1048
- btn.type = 'button';
1049
- btn.setAttribute('data-testid', 'devbar-settings-button');
1050
- btn.setAttribute('aria-label', 'Settings');
1051
- // Attach HTML tooltip
1052
- attachButtonTooltip(state, btn, CSS_COLORS.textSecondary, (_tooltip, h) => {
1053
- h.addTitle('Settings');
1054
- h.addSectionHeader('Keyboard');
1055
- h.addShortcut('Cmd or Ctrl+Shift+M', 'Toggle compact mode');
1056
- });
1057
- const isActive = state.showSettingsPopover;
1058
- const color = CSS_COLORS.textSecondary;
1059
- Object.assign(btn.style, {
1060
- display: 'flex',
1061
- alignItems: 'center',
1062
- justifyContent: 'center',
1063
- width: '22px',
1064
- height: '22px',
1065
- minWidth: '22px',
1066
- minHeight: '22px',
1067
- flexShrink: '0',
1068
- borderRadius: '50%',
1069
- border: `1px solid ${isActive ? color : `${color}60`}`,
1070
- backgroundColor: isActive ? `${color}20` : 'transparent',
1071
- color: isActive ? color : `${color}99`,
1072
- cursor: 'pointer',
1073
- transition: 'all 150ms',
1074
- });
1075
- btn.onclick = () => {
1076
- state.showSettingsPopover = !state.showSettingsPopover;
1077
- state.consoleFilter = null;
1078
- state.showOutlineModal = false;
1079
- state.showSchemaModal = false;
1080
- state.showDesignReviewConfirm = false;
1081
- state.render();
1082
- };
1083
- // Gear icon SVG
1084
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
1085
- svg.setAttribute('width', '12');
1086
- svg.setAttribute('height', '12');
1087
- svg.setAttribute('viewBox', '0 0 24 24');
1088
- svg.setAttribute('fill', 'none');
1089
- svg.setAttribute('stroke', 'currentColor');
1090
- svg.setAttribute('stroke-width', '2');
1091
- svg.setAttribute('stroke-linecap', 'round');
1092
- svg.setAttribute('stroke-linejoin', 'round');
1093
- const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
1094
- 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');
1095
- svg.appendChild(path);
1096
- const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
1097
- circle.setAttribute('cx', '12');
1098
- circle.setAttribute('cy', '12');
1099
- circle.setAttribute('r', '3');
1100
- svg.appendChild(circle);
1101
- btn.appendChild(svg);
1102
- return btn;
1103
- }
1104
- /**
1105
- * Create the compact mode toggle button with chevron icon.
4
+ * This file exists so that existing import paths
5
+ * import { render } from './rendering.js'
6
+ * continue to work without changes.
7
+ *
8
+ * The actual implementation is split across:
9
+ * rendering/collapsed.ts - collapsed bar rendering
10
+ * rendering/compact.ts - compact mode
11
+ * rendering/expanded.ts - expanded bar, info section, metrics, custom controls
12
+ * rendering/buttons.ts - button creators (screenshot, a11y, schema, etc.)
13
+ * rendering/console.ts - console popup
14
+ * rendering/modals.ts - outline, schema, a11y, design review modals
15
+ * rendering/settings.ts - settings popover
16
+ * rendering/common.ts - shared helpers (connection indicator, dot position)
1106
17
  */
1107
- function createCompactToggleButton(state) {
1108
- const btn = document.createElement('button');
1109
- btn.type = 'button';
1110
- btn.setAttribute('aria-label', state.compactMode ? 'Switch to expanded mode' : 'Switch to compact mode');
1111
- const isCompact = state.compactMode;
1112
- const { accentColor } = state.options;
1113
- const iconColor = CSS_COLORS.textSecondary;
1114
- Object.assign(btn.style, {
1115
- display: 'flex',
1116
- alignItems: 'center',
1117
- justifyContent: 'center',
1118
- width: '22px',
1119
- height: '22px',
1120
- minWidth: '22px',
1121
- minHeight: '22px',
1122
- flexShrink: '0',
1123
- borderRadius: '50%',
1124
- border: `1px solid ${accentColor}60`,
1125
- backgroundColor: 'transparent',
1126
- color: `${iconColor}99`,
1127
- cursor: 'pointer',
1128
- transition: 'all 150ms',
1129
- });
1130
- attachTextTooltip(state, btn, () => (isCompact ? 'Expand (Cmd or Ctrl+Shift+M)' : 'Compact (Cmd or Ctrl+Shift+M)'), {
1131
- onEnter: () => {
1132
- btn.style.borderColor = accentColor;
1133
- btn.style.backgroundColor = `${accentColor}20`;
1134
- btn.style.color = iconColor;
1135
- },
1136
- onLeave: () => {
1137
- btn.style.borderColor = `${accentColor}60`;
1138
- btn.style.backgroundColor = 'transparent';
1139
- btn.style.color = `${iconColor}99`;
1140
- },
1141
- });
1142
- btn.onclick = () => {
1143
- state.toggleCompactMode();
1144
- };
1145
- // Chevron icon SVG - points right when expanded, left when compact
1146
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
1147
- svg.setAttribute('width', '12');
1148
- svg.setAttribute('height', '12');
1149
- svg.setAttribute('viewBox', '0 0 24 24');
1150
- svg.setAttribute('fill', 'none');
1151
- svg.setAttribute('stroke', 'currentColor');
1152
- svg.setAttribute('stroke-width', '2');
1153
- svg.setAttribute('stroke-linecap', 'round');
1154
- svg.setAttribute('stroke-linejoin', 'round');
1155
- const path = document.createElementNS('http://www.w3.org/2000/svg', 'polyline');
1156
- // Left chevron (<) when expanded to shrink, right chevron (>) when compact to expand
1157
- path.setAttribute('points', isCompact ? '9 18 15 12 9 6' : '15 18 9 12 15 6');
1158
- svg.appendChild(path);
1159
- btn.appendChild(svg);
1160
- return btn;
1161
- }
1162
- // ============================================================================
1163
- // Console Popup
1164
- // ============================================================================
1165
- function renderConsolePopup(state, consoleCaptureSingleton) {
1166
- const filterType = state.consoleFilter;
1167
- if (!filterType)
1168
- return;
1169
- const logs = consoleCaptureSingleton
1170
- .getLogs()
1171
- .filter((log) => log.level === filterType);
1172
- const colorMap = { error: BUTTON_COLORS.error, warn: BUTTON_COLORS.warning, info: BUTTON_COLORS.info };
1173
- const color = colorMap[filterType];
1174
- const labelMap = { error: 'Errors', warn: 'Warnings', info: 'Info' };
1175
- const label = labelMap[filterType];
1176
- const closeModal = () => {
1177
- state.consoleFilter = null;
1178
- state.render();
1179
- };
1180
- const overlay = createModalOverlay(closeModal);
1181
- const modal = createModalBox(color);
1182
- const header = createModalHeader({
1183
- color,
1184
- title: `Console ${label} (${logs.length})`,
1185
- onClose: closeModal,
1186
- onCopyMd: async () => {
1187
- const lines = logs.map((log) => {
1188
- const time = new Date(log.timestamp).toLocaleTimeString();
1189
- return `[${time}] ${log.level}: ${log.message}`;
1190
- });
1191
- await navigator.clipboard.writeText(lines.join('\n'));
1192
- },
1193
- onSave: () => handleSaveConsoleLogs(state, logs),
1194
- onClear: () => state.clearConsoleLogs(),
1195
- sweetlinkConnected: state.sweetlinkConnected,
1196
- saveLocation: state.options.saveLocation,
1197
- isSaving: state.savingConsoleLogs,
1198
- savedPath: state.lastConsoleLogs,
1199
- });
1200
- modal.appendChild(header);
1201
- const content = createModalContent();
1202
- if (logs.length === 0) {
1203
- content.appendChild(createEmptyMessage(`No ${filterType}s recorded`));
1204
- }
1205
- else {
1206
- renderConsoleLogs(content, logs, color);
1207
- }
1208
- modal.appendChild(content);
1209
- overlay.appendChild(modal);
1210
- state.overlayElement = overlay;
1211
- document.body.appendChild(overlay);
1212
- }
1213
- function renderConsoleLogs(container, logs, color) {
1214
- logs.forEach((log, index) => {
1215
- const logItem = document.createElement('div');
1216
- Object.assign(logItem.style, {
1217
- padding: '8px 14px',
1218
- borderBottom: index < logs.length - 1 ? '1px solid rgba(255, 255, 255, 0.05)' : 'none',
1219
- });
1220
- const timestamp = document.createElement('span');
1221
- Object.assign(timestamp.style, {
1222
- color: CSS_COLORS.textMuted,
1223
- fontSize: '0.625rem',
1224
- marginRight: '8px',
1225
- });
1226
- timestamp.textContent = new Date(log.timestamp).toLocaleTimeString();
1227
- logItem.appendChild(timestamp);
1228
- const message = document.createElement('span');
1229
- Object.assign(message.style, {
1230
- color,
1231
- fontSize: '0.6875rem',
1232
- wordBreak: 'break-word',
1233
- whiteSpace: 'pre-wrap',
1234
- });
1235
- message.textContent = log.message;
1236
- logItem.appendChild(message);
1237
- container.appendChild(logItem);
1238
- });
1239
- }
1240
- // ============================================================================
1241
- // Outline / Schema Modals
1242
- // ============================================================================
1243
- function renderOutlineModal(state) {
1244
- const outline = extractDocumentOutline();
1245
- const color = BUTTON_COLORS.outline;
1246
- const closeModal = () => {
1247
- state.showOutlineModal = false;
1248
- state.render();
1249
- };
1250
- const overlay = createModalOverlay(closeModal);
1251
- const modal = createModalBox(color);
1252
- const header = createModalHeader({
1253
- color,
1254
- title: 'Document Outline',
1255
- onClose: closeModal,
1256
- onCopyMd: async () => {
1257
- const markdown = outlineToMarkdown(outline);
1258
- await navigator.clipboard.writeText(markdown);
1259
- },
1260
- onSave: () => handleSaveOutline(state),
1261
- sweetlinkConnected: state.sweetlinkConnected,
1262
- saveLocation: state.options.saveLocation,
1263
- isSaving: state.savingOutline,
1264
- savedPath: state.lastOutline,
1265
- });
1266
- modal.appendChild(header);
1267
- const content = createModalContent();
1268
- if (outline.length === 0) {
1269
- content.appendChild(createEmptyMessage('No semantic elements found in this document'));
1270
- }
1271
- else {
1272
- renderOutlineNodes(outline, content, 0);
1273
- }
1274
- modal.appendChild(content);
1275
- overlay.appendChild(modal);
1276
- state.overlayElement = overlay;
1277
- document.body.appendChild(overlay);
1278
- }
1279
- function renderOutlineNodes(nodes, parentEl, depth) {
1280
- for (const node of nodes) {
1281
- const nodeEl = document.createElement('div');
1282
- Object.assign(nodeEl.style, {
1283
- padding: `4px 0 4px ${depth * 16}px`,
1284
- });
1285
- const tagSpan = document.createElement('span');
1286
- const categoryColor = CATEGORY_COLORS[node.category || 'other'] || CATEGORY_COLORS.other;
1287
- Object.assign(tagSpan.style, {
1288
- color: categoryColor,
1289
- fontSize: '0.6875rem',
1290
- fontWeight: '500',
1291
- });
1292
- tagSpan.textContent = `<${node.tagName}>`;
1293
- nodeEl.appendChild(tagSpan);
1294
- if (node.category) {
1295
- const categorySpan = document.createElement('span');
1296
- Object.assign(categorySpan.style, {
1297
- color: CSS_COLORS.textMuted,
1298
- fontSize: '0.625rem',
1299
- marginLeft: '6px',
1300
- });
1301
- categorySpan.textContent = `[${node.category}]`;
1302
- nodeEl.appendChild(categorySpan);
1303
- }
1304
- const textSpan = document.createElement('span');
1305
- Object.assign(textSpan.style, {
1306
- color: '#d1d5db',
1307
- fontSize: '0.6875rem',
1308
- marginLeft: '8px',
1309
- });
1310
- const truncatedText = node.text.length > 60 ? `${node.text.slice(0, 60)}...` : node.text;
1311
- textSpan.textContent = truncatedText;
1312
- nodeEl.appendChild(textSpan);
1313
- if (node.id) {
1314
- const idSpan = document.createElement('span');
1315
- Object.assign(idSpan.style, {
1316
- color: '#9ca3af',
1317
- fontSize: '0.625rem',
1318
- marginLeft: '6px',
1319
- });
1320
- idSpan.textContent = `#${node.id}`;
1321
- nodeEl.appendChild(idSpan);
1322
- }
1323
- parentEl.appendChild(nodeEl);
1324
- if (node.children.length > 0) {
1325
- renderOutlineNodes(node.children, parentEl, depth + 1);
1326
- }
1327
- }
1328
- }
1329
- function renderSchemaModal(state) {
1330
- const schema = extractPageSchema();
1331
- const color = BUTTON_COLORS.schema;
1332
- const closeModal = () => {
1333
- state.showSchemaModal = false;
1334
- state.render();
1335
- };
1336
- const overlay = createModalOverlay(closeModal);
1337
- const modal = createModalBox(color);
1338
- const header = createModalHeader({
1339
- color,
1340
- title: 'Page Schema',
1341
- onClose: closeModal,
1342
- onCopyMd: async () => {
1343
- const markdown = schemaToMarkdown(schema);
1344
- await navigator.clipboard.writeText(markdown);
1345
- },
1346
- onSave: () => handleSaveSchema(state),
1347
- sweetlinkConnected: state.sweetlinkConnected,
1348
- saveLocation: state.options.saveLocation,
1349
- isSaving: state.savingSchema,
1350
- savedPath: state.lastSchema,
1351
- });
1352
- modal.appendChild(header);
1353
- const content = createModalContent();
1354
- const missingTags = checkMissingTags(schema);
1355
- const favicons = extractFavicons();
1356
- const hasContent = schema.jsonLd.length > 0 ||
1357
- Object.keys(schema.openGraph).length > 0 ||
1358
- Object.keys(schema.twitter).length > 0 ||
1359
- Object.keys(schema.metaTags).length > 0 ||
1360
- favicons.length > 0 ||
1361
- missingTags.length > 0;
1362
- if (!hasContent) {
1363
- content.appendChild(createEmptyMessage('No structured data found on this page'));
1364
- }
1365
- else {
1366
- if (missingTags.length > 0)
1367
- renderMissingTagsSection(content, missingTags);
1368
- renderSchemaSection(content, 'Open Graph', schema.openGraph, CSS_COLORS.info);
1369
- renderSchemaSection(content, 'Twitter Cards', schema.twitter, CSS_COLORS.cyan);
1370
- if (favicons.length > 0)
1371
- renderFaviconsSection(content, favicons);
1372
- renderSchemaSection(content, 'JSON-LD', schema.jsonLd, color);
1373
- renderSchemaSection(content, 'Meta Tags', schema.metaTags, CSS_COLORS.textMuted);
1374
- }
1375
- modal.appendChild(content);
1376
- overlay.appendChild(modal);
1377
- state.overlayElement = overlay;
1378
- document.body.appendChild(overlay);
1379
- }
1380
- function renderSchemaSectionHeader(section, title, color, count) {
1381
- const header = document.createElement('div');
1382
- Object.assign(header.style, {
1383
- display: 'flex',
1384
- alignItems: 'center',
1385
- gap: '8px',
1386
- marginBottom: '10px',
1387
- paddingBottom: '6px',
1388
- borderBottom: `1px solid ${color}30`,
1389
- });
1390
- const titleEl = document.createElement('h3');
1391
- Object.assign(titleEl.style, {
1392
- color,
1393
- fontSize: '0.8125rem',
1394
- fontWeight: '600',
1395
- margin: '0',
1396
- });
1397
- titleEl.textContent = title;
1398
- header.appendChild(titleEl);
1399
- const badge = document.createElement('span');
1400
- Object.assign(badge.style, {
1401
- color: `${color}cc`,
1402
- fontSize: '0.5625rem',
1403
- backgroundColor: `${color}18`,
1404
- padding: '1px 6px',
1405
- borderRadius: '8px',
1406
- letterSpacing: '0.03em',
1407
- });
1408
- badge.textContent = String(count);
1409
- header.appendChild(badge);
1410
- section.appendChild(header);
1411
- }
1412
- function renderSchemaSection(container, title, items, color) {
1413
- const count = Array.isArray(items) ? items.length : Object.keys(items).length;
1414
- if (count === 0)
1415
- return;
1416
- const section = document.createElement('div');
1417
- section.style.marginBottom = '20px';
1418
- renderSchemaSectionHeader(section, title, color, count);
1419
- if (Array.isArray(items)) {
1420
- renderJsonLdItems(section, items, color);
1421
- }
1422
- else {
1423
- renderKeyValueItems(section, items);
1424
- }
1425
- container.appendChild(section);
1426
- }
1427
- function renderJsonLdItems(container, items, color) {
1428
- items.forEach((item, i) => {
1429
- const itemEl = document.createElement('div');
1430
- itemEl.style.marginBottom = '10px';
1431
- // Extract @type for a meaningful label
1432
- const typed = item;
1433
- const schemaType = typeof typed?.['@type'] === 'string' ? typed['@type'] : null;
1434
- const itemHeader = document.createElement('div');
1435
- Object.assign(itemHeader.style, {
1436
- display: 'flex',
1437
- alignItems: 'center',
1438
- gap: '6px',
1439
- marginBottom: '4px',
1440
- });
1441
- const itemTitle = document.createElement('span');
1442
- Object.assign(itemTitle.style, {
1443
- color: '#9ca3af',
1444
- fontSize: '0.6875rem',
1445
- });
1446
- itemTitle.textContent = `Schema ${i + 1}`;
1447
- itemHeader.appendChild(itemTitle);
1448
- if (schemaType) {
1449
- const typeTag = document.createElement('span');
1450
- Object.assign(typeTag.style, {
1451
- color: `${color}cc`,
1452
- fontSize: '0.5625rem',
1453
- backgroundColor: `${color}15`,
1454
- border: `1px solid ${color}25`,
1455
- padding: '0 5px',
1456
- borderRadius: '3px',
1457
- });
1458
- typeTag.textContent = schemaType;
1459
- itemHeader.appendChild(typeTag);
1460
- }
1461
- itemEl.appendChild(itemHeader);
1462
- const codeEl = document.createElement('pre');
1463
- Object.assign(codeEl.style, {
1464
- backgroundColor: 'rgba(0, 0, 0, 0.25)',
1465
- borderRadius: '4px',
1466
- borderLeft: `2px solid ${color}50`,
1467
- padding: '10px 10px 10px 12px',
1468
- overflow: 'auto',
1469
- fontSize: '0.625rem',
1470
- margin: '0',
1471
- maxHeight: '300px',
1472
- });
1473
- appendHighlightedJson(codeEl, JSON.stringify(item, null, 2));
1474
- itemEl.appendChild(codeEl);
1475
- container.appendChild(itemEl);
1476
- });
1477
- }
1478
- function appendHighlightedJson(container, json) {
1479
- // Color map for different token types
1480
- const colors = {
1481
- key: CSS_COLORS.primary, // green
1482
- string: CSS_COLORS.warning, // amber/yellow
1483
- number: CSS_COLORS.purple, // purple
1484
- boolean: CSS_COLORS.info, // blue
1485
- nullVal: CSS_COLORS.error, // red
1486
- punct: CSS_COLORS.textMuted, // gray
1487
- };
1488
- // Simple tokenizer for JSON using matchAll for safety
1489
- const tokenPattern = /("(?:\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*")(\s*:)?|(\btrue\b|\bfalse\b)|(\bnull\b)|(-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?)|([{}[\],])|(\s+)/g;
1490
- for (const match of json.matchAll(tokenPattern)) {
1491
- const [, str, colon, bool, nullToken, num, punct, whitespace] = match;
1492
- if (whitespace) {
1493
- container.appendChild(document.createTextNode(whitespace));
1494
- }
1495
- else if (str !== undefined) {
1496
- const span = document.createElement('span');
1497
- span.style.color = colon ? colors.key : colors.string;
1498
- span.textContent = str;
1499
- container.appendChild(span);
1500
- if (colon) {
1501
- const colonSpan = document.createElement('span');
1502
- colonSpan.style.color = colors.punct;
1503
- colonSpan.textContent = ':';
1504
- container.appendChild(colonSpan);
1505
- }
1506
- }
1507
- else if (bool) {
1508
- const span = document.createElement('span');
1509
- span.style.color = colors.boolean;
1510
- span.textContent = bool;
1511
- container.appendChild(span);
1512
- }
1513
- else if (nullToken) {
1514
- const span = document.createElement('span');
1515
- span.style.color = colors.nullVal;
1516
- span.textContent = nullToken;
1517
- container.appendChild(span);
1518
- }
1519
- else if (num) {
1520
- const span = document.createElement('span');
1521
- span.style.color = colors.number;
1522
- span.textContent = num;
1523
- container.appendChild(span);
1524
- }
1525
- else if (punct) {
1526
- const span = document.createElement('span');
1527
- span.style.color = colors.punct;
1528
- span.textContent = punct;
1529
- container.appendChild(span);
1530
- }
1531
- }
1532
- }
1533
- function renderKeyValueItems(container, items) {
1534
- const entries = Object.entries(items);
1535
- entries.forEach(([key, value], i) => {
1536
- const isImage = isImageKey(key);
1537
- const row = document.createElement('div');
1538
- Object.assign(row.style, {
1539
- display: 'flex',
1540
- padding: isImage ? '6px 8px' : '3px 8px',
1541
- alignItems: 'flex-start',
1542
- borderRadius: '3px',
1543
- backgroundColor: i % 2 === 0 ? 'rgba(255, 255, 255, 0.02)' : 'transparent',
1544
- });
1545
- const keyEl = document.createElement('span');
1546
- Object.assign(keyEl.style, {
1547
- color: CSS_COLORS.textSecondary,
1548
- fontSize: '0.6875rem',
1549
- width: '120px',
1550
- minWidth: '120px',
1551
- maxWidth: '120px',
1552
- flexShrink: '0',
1553
- overflow: 'hidden',
1554
- textOverflow: 'ellipsis',
1555
- whiteSpace: 'nowrap',
1556
- paddingTop: isImage ? '2px' : '0',
1557
- });
1558
- keyEl.textContent = key;
1559
- if (key.length > 18)
1560
- keyEl.title = key;
1561
- row.appendChild(keyEl);
1562
- if (isImage && value) {
1563
- const valueCol = document.createElement('div');
1564
- Object.assign(valueCol.style, { flex: '1', minWidth: '0' });
1565
- // Image frame with subtle border — fixed height to prevent layout jitter
1566
- const frame = document.createElement('div');
1567
- Object.assign(frame.style, {
1568
- display: 'inline-block',
1569
- padding: '4px',
1570
- backgroundColor: 'rgba(0, 0, 0, 0.2)',
1571
- border: '1px solid rgba(255, 255, 255, 0.06)',
1572
- borderRadius: '4px',
1573
- marginBottom: '4px',
1574
- minHeight: '60px',
1575
- minWidth: '80px',
1576
- });
1577
- const thumb = document.createElement('img');
1578
- Object.assign(thumb.style, {
1579
- width: '200px',
1580
- height: '120px',
1581
- objectFit: 'contain',
1582
- borderRadius: '2px',
1583
- display: 'block',
1584
- });
1585
- thumb.src = value;
1586
- thumb.alt = key;
1587
- thumb.onerror = () => { frame.style.display = 'none'; };
1588
- thumb.onload = () => {
1589
- if (thumb.naturalWidth) {
1590
- dimEl.textContent = `${thumb.naturalWidth}\u00d7${thumb.naturalHeight}`;
1591
- }
1592
- };
1593
- frame.appendChild(thumb);
1594
- valueCol.appendChild(frame);
1595
- // Reserve space for dimension text to avoid reflow
1596
- const dimEl = document.createElement('div');
1597
- Object.assign(dimEl.style, {
1598
- color: CSS_COLORS.textMuted,
1599
- fontSize: '0.5625rem',
1600
- minHeight: '0.75rem',
1601
- letterSpacing: '0.02em',
1602
- });
1603
- valueCol.appendChild(dimEl);
1604
- const urlEl = document.createElement('div');
1605
- Object.assign(urlEl.style, {
1606
- color: CSS_COLORS.textMuted,
1607
- fontSize: '0.5625rem',
1608
- wordBreak: 'break-all',
1609
- opacity: '0.7',
1610
- });
1611
- urlEl.textContent = value;
1612
- valueCol.appendChild(urlEl);
1613
- row.appendChild(valueCol);
1614
- }
1615
- else {
1616
- const valueEl = document.createElement('span');
1617
- Object.assign(valueEl.style, {
1618
- color: CSS_COLORS.text,
1619
- fontSize: '0.6875rem',
1620
- flex: '1',
1621
- wordBreak: 'break-word',
1622
- whiteSpace: 'pre-wrap',
1623
- opacity: '0.85',
1624
- });
1625
- valueEl.textContent = String(value);
1626
- row.appendChild(valueEl);
1627
- }
1628
- container.appendChild(row);
1629
- });
1630
- }
1631
- /** Derive intended device/purpose from favicon label and declared size */
1632
- function faviconDevice(label, size) {
1633
- const s = parseInt(size || '', 10);
1634
- if (label.includes('apple'))
1635
- return { text: 'Apple home screen', color: CSS_COLORS.info };
1636
- if (size === 'any' || label.includes('svg'))
1637
- return { text: 'Scalable (any)', color: CSS_COLORS.cyan };
1638
- if (s >= 192)
1639
- return { text: 'Android / PWA', color: CSS_COLORS.primary };
1640
- if (s >= 48)
1641
- return { text: 'Taskbar / shortcut', color: CSS_COLORS.purple };
1642
- if (s > 0)
1643
- return { text: 'Browser tab', color: CSS_COLORS.textSecondary };
1644
- return { text: 'General', color: CSS_COLORS.textMuted };
1645
- }
1646
- function renderFaviconsSection(container, icons) {
1647
- const color = CSS_COLORS.purple;
1648
- const section = document.createElement('div');
1649
- section.style.marginBottom = '20px';
1650
- renderSchemaSectionHeader(section, 'Favicons', color, icons.length);
1651
- icons.forEach((icon, i) => {
1652
- const device = faviconDevice(icon.label, icon.size);
1653
- const row = document.createElement('div');
1654
- Object.assign(row.style, {
1655
- display: 'flex',
1656
- alignItems: 'center',
1657
- padding: '6px 8px',
1658
- gap: '10px',
1659
- borderRadius: '3px',
1660
- backgroundColor: i % 2 === 0 ? 'rgba(255, 255, 255, 0.02)' : 'transparent',
1661
- });
1662
- // Thumbnail frame
1663
- const frame = document.createElement('div');
1664
- Object.assign(frame.style, {
1665
- width: '32px',
1666
- height: '32px',
1667
- display: 'flex',
1668
- alignItems: 'center',
1669
- justifyContent: 'center',
1670
- backgroundColor: 'rgba(0, 0, 0, 0.25)',
1671
- border: '1px solid rgba(255, 255, 255, 0.06)',
1672
- borderRadius: '4px',
1673
- flexShrink: '0',
1674
- });
1675
- const thumb = document.createElement('img');
1676
- Object.assign(thumb.style, {
1677
- width: '22px',
1678
- height: '22px',
1679
- objectFit: 'contain',
1680
- });
1681
- thumb.src = icon.url;
1682
- thumb.alt = icon.label;
1683
- thumb.onerror = () => { frame.style.opacity = '0.3'; };
1684
- frame.appendChild(thumb);
1685
- row.appendChild(frame);
1686
- // Info column: label, device, dimensions + URL
1687
- const infoCol = document.createElement('div');
1688
- Object.assign(infoCol.style, {
1689
- flex: '1',
1690
- minWidth: '0',
1691
- display: 'flex',
1692
- flexDirection: 'column',
1693
- gap: '2px',
1694
- });
1695
- // Top row: label + device pill
1696
- const topRow = document.createElement('div');
1697
- Object.assign(topRow.style, {
1698
- display: 'flex',
1699
- alignItems: 'center',
1700
- gap: '6px',
1701
- });
1702
- const labelEl = document.createElement('span');
1703
- Object.assign(labelEl.style, {
1704
- color: CSS_COLORS.text,
1705
- fontSize: '0.6875rem',
1706
- fontWeight: '500',
1707
- overflow: 'hidden',
1708
- textOverflow: 'ellipsis',
1709
- whiteSpace: 'nowrap',
1710
- });
1711
- labelEl.textContent = icon.label;
1712
- if (icon.label.length > 24)
1713
- labelEl.title = icon.label;
1714
- topRow.appendChild(labelEl);
1715
- const devicePill = document.createElement('span');
1716
- Object.assign(devicePill.style, {
1717
- color: device.color,
1718
- fontSize: '0.5rem',
1719
- backgroundColor: `${device.color}12`,
1720
- padding: '1px 6px',
1721
- borderRadius: '6px',
1722
- letterSpacing: '0.03em',
1723
- whiteSpace: 'nowrap',
1724
- flexShrink: '0',
1725
- });
1726
- devicePill.textContent = device.text;
1727
- topRow.appendChild(devicePill);
1728
- infoCol.appendChild(topRow);
1729
- // Bottom row: declared size + actual dimensions + URL
1730
- const bottomRow = document.createElement('div');
1731
- Object.assign(bottomRow.style, {
1732
- display: 'flex',
1733
- alignItems: 'center',
1734
- gap: '6px',
1735
- fontSize: '0.5625rem',
1736
- color: CSS_COLORS.textMuted,
1737
- });
1738
- if (icon.size) {
1739
- const declaredEl = document.createElement('span');
1740
- declaredEl.textContent = icon.size;
1741
- declaredEl.style.opacity = '0.8';
1742
- bottomRow.appendChild(declaredEl);
1743
- }
1744
- // Actual dimensions (populated on load)
1745
- const dimEl = document.createElement('span');
1746
- dimEl.style.letterSpacing = '0.02em';
1747
- bottomRow.appendChild(dimEl);
1748
- thumb.onload = () => {
1749
- if (thumb.naturalWidth) {
1750
- const actual = `${thumb.naturalWidth}\u00d7${thumb.naturalHeight}`;
1751
- if (icon.size) {
1752
- dimEl.textContent = `\u2192 ${actual}`;
1753
- }
1754
- else {
1755
- dimEl.textContent = actual;
1756
- }
1757
- }
1758
- };
1759
- const sep = document.createElement('span');
1760
- sep.textContent = '\u00b7';
1761
- sep.style.opacity = '0.4';
1762
- bottomRow.appendChild(sep);
1763
- const urlEl = document.createElement('span');
1764
- Object.assign(urlEl.style, {
1765
- overflow: 'hidden',
1766
- textOverflow: 'ellipsis',
1767
- whiteSpace: 'nowrap',
1768
- opacity: '0.6',
1769
- });
1770
- urlEl.textContent = icon.url;
1771
- urlEl.title = icon.url;
1772
- bottomRow.appendChild(urlEl);
1773
- infoCol.appendChild(bottomRow);
1774
- row.appendChild(infoCol);
1775
- section.appendChild(row);
1776
- });
1777
- container.appendChild(section);
1778
- }
1779
- function renderMissingTagsSection(container, tags) {
1780
- const section = document.createElement('div');
1781
- section.style.marginBottom = '20px';
1782
- const errorCount = tags.filter((t) => t.severity === 'error').length;
1783
- const warnCount = tags.length - errorCount;
1784
- const hasErrors = errorCount > 0;
1785
- const sectionColor = hasErrors ? CSS_COLORS.error : CSS_COLORS.warning;
1786
- renderSchemaSectionHeader(section, 'Missing Tags', sectionColor, tags.length);
1787
- // Summary pill row
1788
- if (errorCount > 0 || warnCount > 0) {
1789
- const summary = document.createElement('div');
1790
- Object.assign(summary.style, {
1791
- display: 'flex',
1792
- gap: '8px',
1793
- marginBottom: '8px',
1794
- });
1795
- if (errorCount > 0) {
1796
- const errPill = document.createElement('span');
1797
- Object.assign(errPill.style, {
1798
- color: CSS_COLORS.error,
1799
- fontSize: '0.5625rem',
1800
- backgroundColor: `${CSS_COLORS.error}15`,
1801
- padding: '2px 8px',
1802
- borderRadius: '8px',
1803
- letterSpacing: '0.03em',
1804
- });
1805
- errPill.textContent = `${errorCount} error${errorCount > 1 ? 's' : ''}`;
1806
- summary.appendChild(errPill);
1807
- }
1808
- if (warnCount > 0) {
1809
- const warnPill = document.createElement('span');
1810
- Object.assign(warnPill.style, {
1811
- color: CSS_COLORS.warning,
1812
- fontSize: '0.5625rem',
1813
- backgroundColor: `${CSS_COLORS.warning}15`,
1814
- padding: '2px 8px',
1815
- borderRadius: '8px',
1816
- letterSpacing: '0.03em',
1817
- });
1818
- warnPill.textContent = `${warnCount} warning${warnCount > 1 ? 's' : ''}`;
1819
- summary.appendChild(warnPill);
1820
- }
1821
- section.appendChild(summary);
1822
- }
1823
- tags.forEach((tag, i) => {
1824
- const isError = tag.severity === 'error';
1825
- const tagColor = isError ? CSS_COLORS.error : CSS_COLORS.warning;
1826
- const row = document.createElement('div');
1827
- Object.assign(row.style, {
1828
- display: 'flex',
1829
- alignItems: 'center',
1830
- padding: '4px 8px',
1831
- gap: '8px',
1832
- borderRadius: '3px',
1833
- backgroundColor: i % 2 === 0 ? 'rgba(255, 255, 255, 0.02)' : 'transparent',
1834
- borderLeft: `2px solid ${tagColor}40`,
1835
- });
1836
- const icon = document.createElement('span');
1837
- Object.assign(icon.style, {
1838
- fontSize: '0.625rem',
1839
- flexShrink: '0',
1840
- width: '14px',
1841
- textAlign: 'center',
1842
- color: tagColor,
1843
- });
1844
- icon.textContent = isError ? '\u2718' : '\u26a0';
1845
- row.appendChild(icon);
1846
- const tagName = document.createElement('span');
1847
- Object.assign(tagName.style, {
1848
- color: CSS_COLORS.text,
1849
- fontSize: '0.6875rem',
1850
- width: '120px',
1851
- minWidth: '120px',
1852
- flexShrink: '0',
1853
- fontWeight: '500',
1854
- });
1855
- tagName.textContent = tag.tag;
1856
- row.appendChild(tagName);
1857
- const hint = document.createElement('span');
1858
- Object.assign(hint.style, {
1859
- color: CSS_COLORS.textMuted,
1860
- fontSize: '0.6875rem',
1861
- flex: '1',
1862
- opacity: '0.85',
1863
- });
1864
- hint.textContent = tag.hint;
1865
- row.appendChild(hint);
1866
- section.appendChild(row);
1867
- });
1868
- container.appendChild(section);
1869
- }
1870
- // ============================================================================
1871
- // Accessibility Audit Modal
1872
- // ============================================================================
1873
- function formatA11yMarkdown(result) {
1874
- const counts = getViolationCounts(result.violations);
1875
- const lines = [
1876
- '# Accessibility Audit Report',
1877
- '',
1878
- `**URL:** ${result.url}`,
1879
- `**Timestamp:** ${result.timestamp}`,
1880
- '',
1881
- '## Summary',
1882
- '',
1883
- `- **Total violations:** ${counts.total}`,
1884
- `- Critical: ${counts.critical}`,
1885
- `- Serious: ${counts.serious}`,
1886
- `- Moderate: ${counts.moderate}`,
1887
- `- Minor: ${counts.minor}`,
1888
- `- Passes: ${result.passes.length}`,
1889
- `- Incomplete: ${result.incomplete.length}`,
1890
- '',
1891
- ];
1892
- if (result.violations.length === 0) {
1893
- lines.push('No accessibility violations found.');
1894
- return lines.join('\n');
1895
- }
1896
- const grouped = groupViolationsByImpact(result.violations);
1897
- for (const [impact, violations] of grouped) {
1898
- if (violations.length === 0)
1899
- continue;
1900
- lines.push(`## ${impact.charAt(0).toUpperCase() + impact.slice(1)} (${violations.length})`);
1901
- lines.push('');
1902
- for (const v of violations) {
1903
- lines.push(`### ${v.id}`);
1904
- lines.push('');
1905
- lines.push(`**${v.help}**`);
1906
- lines.push('');
1907
- lines.push(v.description);
1908
- lines.push('');
1909
- lines.push(`- Help: ${v.helpUrl}`);
1910
- lines.push(`- Elements affected: ${v.nodes.length}`);
1911
- lines.push('');
1912
- for (const node of v.nodes.slice(0, 10)) {
1913
- const html = node.html.length > 120 ? `${node.html.slice(0, 120)}...` : node.html;
1914
- lines.push(` - \`${html}\``);
1915
- if (node.target.length > 0) {
1916
- lines.push(` Selector: \`${node.target.join(', ')}\``);
1917
- }
1918
- }
1919
- if (v.nodes.length > 10) {
1920
- lines.push(` - ... and ${v.nodes.length - 10} more`);
1921
- }
1922
- lines.push('');
1923
- }
1924
- }
1925
- return lines.join('\n');
1926
- }
1927
- function clearChildren(el) {
1928
- while (el.firstChild) {
1929
- el.removeChild(el.firstChild);
1930
- }
1931
- }
1932
- function renderA11yModal(state) {
1933
- const color = BUTTON_COLORS.a11y;
1934
- const closeModal = () => {
1935
- state.showA11yModal = false;
1936
- state.render();
1937
- };
1938
- const overlay = createModalOverlay(closeModal);
1939
- const modal = createModalBox(color);
1940
- // Show loading state initially
1941
- const loadingContent = createModalContent();
1942
- const loadingMsg = document.createElement('div');
1943
- Object.assign(loadingMsg.style, {
1944
- textAlign: 'center',
1945
- padding: '40px',
1946
- color: CSS_COLORS.textSecondary,
1947
- fontSize: '0.875rem',
1948
- });
1949
- loadingMsg.textContent = 'Running accessibility audit...';
1950
- loadingMsg.style.animation = 'pulse 1.5s ease-in-out infinite';
1951
- loadingContent.appendChild(loadingMsg);
1952
- // Temporary header without save/copy (shown during loading)
1953
- const loadingHeader = createModalHeader({
1954
- color,
1955
- title: 'Accessibility Audit',
1956
- onClose: closeModal,
1957
- onCopyMd: async () => { },
1958
- sweetlinkConnected: state.sweetlinkConnected,
1959
- saveLocation: state.options.saveLocation,
1960
- });
1961
- modal.appendChild(loadingHeader);
1962
- modal.appendChild(loadingContent);
1963
- overlay.appendChild(modal);
1964
- state.overlayElement = overlay;
1965
- document.body.appendChild(overlay);
1966
- // Run the audit async and replace content when done
1967
- runA11yAudit().then((result) => {
1968
- // Check modal is still open
1969
- if (!state.showA11yModal)
1970
- return;
1971
- const markdown = formatA11yMarkdown(result);
1972
- // Replace modal content
1973
- clearChildren(modal);
1974
- const violationCount = result.violations.length;
1975
- const titleText = violationCount === 0
1976
- ? 'Accessibility Audit \u2014 No Issues'
1977
- : `Accessibility Audit \u2014 ${violationCount} Violation${violationCount === 1 ? '' : 's'}`;
1978
- const header = createModalHeader({
1979
- color,
1980
- title: titleText,
1981
- onClose: closeModal,
1982
- onCopyMd: async () => {
1983
- await navigator.clipboard.writeText(markdown);
1984
- },
1985
- onSave: () => handleSaveA11yAudit(state, markdown),
1986
- sweetlinkConnected: state.sweetlinkConnected,
1987
- saveLocation: state.options.saveLocation,
1988
- isSaving: state.savingA11yAudit,
1989
- savedPath: state.lastA11yAudit,
1990
- });
1991
- modal.appendChild(header);
1992
- const content = createModalContent();
1993
- if (result.violations.length === 0) {
1994
- const successMsg = document.createElement('div');
1995
- Object.assign(successMsg.style, {
1996
- textAlign: 'center',
1997
- padding: '40px',
1998
- color: '#10b981',
1999
- fontSize: '0.875rem',
2000
- });
2001
- successMsg.textContent = 'No accessibility violations found!';
2002
- content.appendChild(successMsg);
2003
- // Show pass count
2004
- if (result.passes.length > 0) {
2005
- const passInfo = document.createElement('div');
2006
- Object.assign(passInfo.style, {
2007
- textAlign: 'center',
2008
- color: CSS_COLORS.textMuted,
2009
- fontSize: '0.75rem',
2010
- marginTop: '8px',
2011
- });
2012
- passInfo.textContent = `${result.passes.length} rules passed`;
2013
- content.appendChild(passInfo);
2014
- }
2015
- }
2016
- else {
2017
- // Summary bar
2018
- const counts = getViolationCounts(result.violations);
2019
- const summaryBar = document.createElement('div');
2020
- Object.assign(summaryBar.style, {
2021
- display: 'flex',
2022
- gap: '12px',
2023
- marginBottom: '16px',
2024
- padding: '10px 12px',
2025
- backgroundColor: `${color}10`,
2026
- border: `1px solid ${color}30`,
2027
- borderRadius: '6px',
2028
- flexWrap: 'wrap',
2029
- });
2030
- for (const impact of ['critical', 'serious', 'moderate', 'minor']) {
2031
- if (counts[impact] === 0)
2032
- continue;
2033
- const badge = document.createElement('span');
2034
- const impactColor = getImpactColor(impact);
2035
- Object.assign(badge.style, {
2036
- display: 'inline-flex',
2037
- alignItems: 'center',
2038
- gap: '4px',
2039
- fontSize: '0.6875rem',
2040
- fontWeight: '600',
2041
- color: impactColor,
2042
- });
2043
- const dot = document.createElement('span');
2044
- Object.assign(dot.style, {
2045
- width: '6px',
2046
- height: '6px',
2047
- borderRadius: '50%',
2048
- backgroundColor: impactColor,
2049
- });
2050
- badge.appendChild(dot);
2051
- badge.appendChild(document.createTextNode(`${counts[impact]} ${impact}`));
2052
- summaryBar.appendChild(badge);
2053
- }
2054
- content.appendChild(summaryBar);
2055
- // Grouped violations
2056
- const grouped = groupViolationsByImpact(result.violations);
2057
- for (const [impact, violations] of grouped) {
2058
- if (violations.length === 0)
2059
- continue;
2060
- renderA11yViolationGroup(content, impact, violations);
2061
- }
2062
- }
2063
- modal.appendChild(content);
2064
- }).catch((err) => {
2065
- if (!state.showA11yModal)
2066
- return;
2067
- clearChildren(modal);
2068
- const header = createModalHeader({
2069
- color: CSS_COLORS.error,
2070
- title: 'Accessibility Audit \u2014 Error',
2071
- onClose: closeModal,
2072
- onCopyMd: async () => { },
2073
- sweetlinkConnected: state.sweetlinkConnected,
2074
- saveLocation: state.options.saveLocation,
2075
- });
2076
- modal.appendChild(header);
2077
- const content = createModalContent();
2078
- content.appendChild(createInfoBox(CSS_COLORS.error, 'Audit Failed', `${err instanceof Error ? err.message : 'Unknown error'}`));
2079
- modal.appendChild(content);
2080
- });
2081
- }
2082
- function renderA11yViolationGroup(container, impact, violations) {
2083
- const impactColor = getImpactColor(impact);
2084
- const section = document.createElement('div');
2085
- section.style.marginBottom = '20px';
2086
- // Section header
2087
- const sectionTitle = document.createElement('h3');
2088
- Object.assign(sectionTitle.style, {
2089
- color: impactColor,
2090
- fontSize: '0.8125rem',
2091
- fontWeight: '600',
2092
- marginBottom: '10px',
2093
- borderBottom: `1px solid ${impactColor}40`,
2094
- paddingBottom: '6px',
2095
- textTransform: 'capitalize',
2096
- });
2097
- sectionTitle.textContent = `${impact} (${violations.length})`;
2098
- section.appendChild(sectionTitle);
2099
- for (const violation of violations) {
2100
- const violationEl = document.createElement('div');
2101
- Object.assign(violationEl.style, {
2102
- marginBottom: '12px',
2103
- padding: '10px 12px',
2104
- backgroundColor: `${impactColor}08`,
2105
- border: `1px solid ${impactColor}20`,
2106
- borderRadius: '6px',
2107
- });
2108
- // Rule ID
2109
- const ruleId = document.createElement('div');
2110
- Object.assign(ruleId.style, {
2111
- color: impactColor,
2112
- fontSize: '0.6875rem',
2113
- fontWeight: '600',
2114
- marginBottom: '4px',
2115
- });
2116
- ruleId.textContent = violation.id;
2117
- violationEl.appendChild(ruleId);
2118
- // Help text
2119
- const helpText = document.createElement('div');
2120
- Object.assign(helpText.style, {
2121
- color: CSS_COLORS.text,
2122
- fontSize: '0.75rem',
2123
- marginBottom: '4px',
2124
- });
2125
- helpText.textContent = violation.help;
2126
- violationEl.appendChild(helpText);
2127
- // Description
2128
- const desc = document.createElement('div');
2129
- Object.assign(desc.style, {
2130
- color: CSS_COLORS.textSecondary,
2131
- fontSize: '0.6875rem',
2132
- marginBottom: '6px',
2133
- });
2134
- desc.textContent = violation.description;
2135
- violationEl.appendChild(desc);
2136
- // Node count
2137
- const nodeCount = document.createElement('div');
2138
- Object.assign(nodeCount.style, {
2139
- color: CSS_COLORS.textMuted,
2140
- fontSize: '0.625rem',
2141
- marginBottom: '4px',
2142
- });
2143
- nodeCount.textContent = `${violation.nodes.length} element${violation.nodes.length === 1 ? '' : 's'} affected`;
2144
- violationEl.appendChild(nodeCount);
2145
- // Affected nodes (collapsed by default, show first 3)
2146
- const nodesPreview = document.createElement('div');
2147
- Object.assign(nodesPreview.style, {
2148
- marginTop: '6px',
2149
- });
2150
- const visibleNodes = violation.nodes.slice(0, 3);
2151
- for (const node of visibleNodes) {
2152
- const nodeEl = document.createElement('div');
2153
- Object.assign(nodeEl.style, {
2154
- padding: '3px 6px',
2155
- marginBottom: '2px',
2156
- backgroundColor: 'rgba(0,0,0,0.2)',
2157
- borderRadius: '3px',
2158
- fontSize: '0.625rem',
2159
- color: CSS_COLORS.textSecondary,
2160
- fontFamily: 'monospace',
2161
- whiteSpace: 'nowrap',
2162
- overflow: 'hidden',
2163
- textOverflow: 'ellipsis',
2164
- });
2165
- nodeEl.textContent = node.html.length > 100 ? `${node.html.slice(0, 100)}...` : node.html;
2166
- nodeEl.title = node.html;
2167
- nodesPreview.appendChild(nodeEl);
2168
- }
2169
- if (violation.nodes.length > 3) {
2170
- const moreBtn = document.createElement('button');
2171
- Object.assign(moreBtn.style, {
2172
- background: 'none',
2173
- border: 'none',
2174
- color: impactColor,
2175
- fontSize: '0.625rem',
2176
- cursor: 'pointer',
2177
- padding: '2px 0',
2178
- fontFamily: FONT_MONO,
2179
- });
2180
- moreBtn.textContent = `+ ${violation.nodes.length - 3} more`;
2181
- moreBtn.onclick = () => {
2182
- // Show remaining nodes
2183
- moreBtn.remove();
2184
- for (const node of violation.nodes.slice(3)) {
2185
- const nodeEl = document.createElement('div');
2186
- Object.assign(nodeEl.style, {
2187
- padding: '3px 6px',
2188
- marginBottom: '2px',
2189
- backgroundColor: 'rgba(0,0,0,0.2)',
2190
- borderRadius: '3px',
2191
- fontSize: '0.625rem',
2192
- color: CSS_COLORS.textSecondary,
2193
- fontFamily: 'monospace',
2194
- whiteSpace: 'nowrap',
2195
- overflow: 'hidden',
2196
- textOverflow: 'ellipsis',
2197
- });
2198
- nodeEl.textContent = node.html.length > 100 ? `${node.html.slice(0, 100)}...` : node.html;
2199
- nodeEl.title = node.html;
2200
- nodesPreview.appendChild(nodeEl);
2201
- }
2202
- };
2203
- nodesPreview.appendChild(moreBtn);
2204
- }
2205
- violationEl.appendChild(nodesPreview);
2206
- section.appendChild(violationEl);
2207
- }
2208
- container.appendChild(section);
2209
- }
2210
- // ============================================================================
2211
- // Design Review Confirmation Modal
2212
- // ============================================================================
2213
- function renderDesignReviewConfirmModal(state) {
2214
- const color = BUTTON_COLORS.review;
2215
- const closeModal = () => closeDesignReviewConfirm(state);
2216
- const overlay = createModalOverlay(closeModal);
2217
- // Override z-index for this modal to be above others
2218
- overlay.style.zIndex = '10003';
2219
- const modal = createModalBox(color);
2220
- modal.style.maxWidth = '450px';
2221
- // Header with title and close button
2222
- const header = document.createElement('div');
2223
- Object.assign(header.style, {
2224
- display: 'flex',
2225
- alignItems: 'center',
2226
- justifyContent: 'space-between',
2227
- padding: '14px 18px',
2228
- borderBottom: `1px solid ${color}40`,
2229
- backgroundColor: `${color}15`,
2230
- });
2231
- const title = document.createElement('span');
2232
- Object.assign(title.style, { color, fontSize: '0.875rem', fontWeight: '600' });
2233
- title.textContent = 'AI Design Review';
2234
- header.appendChild(title);
2235
- header.appendChild(createCloseButton(closeModal));
2236
- modal.appendChild(header);
2237
- // Content
2238
- const content = document.createElement('div');
2239
- Object.assign(content.style, {
2240
- padding: '18px',
2241
- color: CSS_COLORS.text,
2242
- fontSize: '0.8125rem',
2243
- lineHeight: '1.6',
2244
- });
2245
- if (state.apiKeyStatus === null) {
2246
- content.appendChild(createEmptyMessage('Checking API key configuration...'));
2247
- }
2248
- else if (!state.apiKeyStatus.configured) {
2249
- content.appendChild(renderApiKeyNotConfiguredContent());
2250
- }
2251
- else {
2252
- content.appendChild(renderApiKeyConfiguredContent(state));
2253
- }
2254
- modal.appendChild(content);
2255
- // Footer with buttons
2256
- const footer = document.createElement('div');
2257
- Object.assign(footer.style, {
2258
- display: 'flex',
2259
- justifyContent: 'flex-end',
2260
- gap: '10px',
2261
- padding: '14px 18px',
2262
- borderTop: `1px solid ${CSS_COLORS.border}`,
2263
- });
2264
- footer.appendChild(createCloseButton(closeModal, 'Cancel'));
2265
- if (state.apiKeyStatus?.configured) {
2266
- const proceedBtn = createStyledButton({ color, text: 'Run Review', padding: '8px 16px' });
2267
- proceedBtn.style.backgroundColor = `${color}20`;
2268
- proceedBtn.onclick = () => proceedWithDesignReview(state);
2269
- footer.appendChild(proceedBtn);
2270
- }
2271
- modal.appendChild(footer);
2272
- overlay.appendChild(modal);
2273
- state.overlayElement = overlay;
2274
- document.body.appendChild(overlay);
2275
- }
2276
- function renderApiKeyNotConfiguredContent() {
2277
- const wrapper = document.createElement('div');
2278
- wrapper.appendChild(createInfoBox(CSS_COLORS.error, 'API Key Not Configured', 'The ANTHROPIC_API_KEY environment variable is not set.'));
2279
- // Instructions
2280
- const instructions = document.createElement('div');
2281
- Object.assign(instructions.style, { marginBottom: '12px' });
2282
- const instructTitle = document.createElement('div');
2283
- Object.assign(instructTitle.style, {
2284
- color: CSS_COLORS.textSecondary,
2285
- fontWeight: '600',
2286
- marginBottom: '8px',
2287
- });
2288
- instructTitle.textContent = 'To configure:';
2289
- instructions.appendChild(instructTitle);
2290
- const steps = [
2291
- { text: '1. Get an API key from console.anthropic.com', highlight: false },
2292
- { text: '2. Add to your .env file:', highlight: false },
2293
- { text: ' ANTHROPIC_API_KEY=sk-ant-...', highlight: true },
2294
- { text: '3. Restart your dev server', highlight: false },
2295
- ];
2296
- steps.forEach(({ text, highlight }) => {
2297
- const stepDiv = document.createElement('div');
2298
- Object.assign(stepDiv.style, {
2299
- color: highlight ? CSS_COLORS.primary : CSS_COLORS.textMuted,
2300
- fontSize: '0.75rem',
2301
- marginBottom: '4px',
2302
- fontFamily: FONT_MONO,
2303
- });
2304
- stepDiv.textContent = text;
2305
- instructions.appendChild(stepDiv);
2306
- });
2307
- wrapper.appendChild(instructions);
2308
- return wrapper;
2309
- }
2310
- function renderApiKeyConfiguredContent(state) {
2311
- const wrapper = document.createElement('div');
2312
- Object.assign(wrapper.style, { marginBottom: '16px' });
2313
- const desc = document.createElement('p');
2314
- Object.assign(desc.style, { color: CSS_COLORS.textSecondary, marginBottom: '12px' });
2315
- desc.textContent = 'This will capture a screenshot and send it to Claude for design analysis.';
2316
- wrapper.appendChild(desc);
2317
- // Cost estimate
2318
- const estimate = calculateCostEstimate(state);
2319
- if (estimate) {
2320
- const costBox = createInfoBox(CSS_COLORS.primary, 'Estimated Cost', []);
2321
- // Remove default margin and adjust padding
2322
- costBox.style.marginBottom = '0';
2323
- costBox.style.padding = '12px';
2324
- const costDetails = document.createElement('div');
2325
- Object.assign(costDetails.style, {
2326
- display: 'flex',
2327
- justifyContent: 'space-between',
2328
- color: CSS_COLORS.textSecondary,
2329
- fontSize: '0.75rem',
2330
- });
2331
- const tokensSpan = document.createElement('span');
2332
- tokensSpan.textContent = `~${estimate.tokens.toLocaleString()} tokens`;
2333
- costDetails.appendChild(tokensSpan);
2334
- const priceSpan = document.createElement('span');
2335
- Object.assign(priceSpan.style, { color: CSS_COLORS.warning, fontWeight: '600' });
2336
- priceSpan.textContent = estimate.cost;
2337
- costDetails.appendChild(priceSpan);
2338
- costBox.appendChild(costDetails);
2339
- wrapper.appendChild(costBox);
2340
- }
2341
- // Model info
2342
- if (state.apiKeyStatus?.model) {
2343
- const modelDiv = document.createElement('div');
2344
- Object.assign(modelDiv.style, {
2345
- color: CSS_COLORS.textMuted,
2346
- fontSize: '0.6875rem',
2347
- marginTop: '12px',
2348
- });
2349
- modelDiv.textContent = `Model: ${state.apiKeyStatus.model}`;
2350
- wrapper.appendChild(modelDiv);
2351
- }
2352
- return wrapper;
2353
- }
2354
- // ============================================================================
2355
- // Settings Popover
2356
- // ============================================================================
2357
- function renderSettingsPopover(state) {
2358
- const { position, accentColor } = state.options;
2359
- const popover = document.createElement('div');
2360
- popover.setAttribute('data-devbar', 'true');
2361
- popover.setAttribute('data-devbar-overlay', 'true');
2362
- // Position: centered over the devbar on desktop, centered on screen on mobile
2363
- const isTop = position.startsWith('top');
2364
- const popoverWidth = 480;
2365
- const edgePad = 16;
2366
- let leftPx;
2367
- if (state.container && window.innerWidth > 640) {
2368
- const barRect = state.container.getBoundingClientRect();
2369
- const barCenter = barRect.left + barRect.width / 2;
2370
- leftPx = Math.max(edgePad, Math.min(barCenter - popoverWidth / 2, window.innerWidth - popoverWidth - edgePad));
2371
- }
2372
- else {
2373
- leftPx = Math.max(edgePad, (window.innerWidth - popoverWidth) / 2);
2374
- }
2375
- Object.assign(popover.style, {
2376
- position: 'fixed',
2377
- [isTop ? 'top' : 'bottom']: '70px',
2378
- left: `${leftPx}px`,
2379
- zIndex: '10003',
2380
- backgroundColor: 'var(--devbar-color-bg-elevated)',
2381
- border: `1px solid ${accentColor}`,
2382
- borderRadius: '8px',
2383
- boxShadow: `0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px ${accentColor}33`,
2384
- backdropFilter: 'blur(8px)',
2385
- WebkitBackdropFilter: 'blur(8px)',
2386
- width: `${popoverWidth}px`,
2387
- maxWidth: 'calc(100vw - 32px)',
2388
- maxHeight: 'calc(100vh - 100px)',
2389
- overflowY: 'auto',
2390
- fontFamily: FONT_MONO,
2391
- });
2392
- popover.appendChild(createSettingsHeader(state));
2393
- // Two-column grid for settings sections (collapses to 1 column on mobile via CSS)
2394
- const grid = document.createElement('div');
2395
- grid.className = 'devbar-settings-grid';
2396
- Object.assign(grid.style, {
2397
- display: 'grid',
2398
- gridTemplateColumns: '1fr 1fr',
2399
- });
2400
- // Left column: Theme + Display
2401
- const color = CSS_COLORS.textSecondary;
2402
- const leftCol = document.createElement('div');
2403
- Object.assign(leftCol.style, { borderRight: `1px solid ${color}20` });
2404
- leftCol.appendChild(createThemeSection(state));
2405
- leftCol.appendChild(createDisplaySection(state));
2406
- grid.appendChild(leftCol);
2407
- // Right column: Features + Metrics
2408
- const rightCol = document.createElement('div');
2409
- rightCol.appendChild(createFeaturesSection(state));
2410
- rightCol.appendChild(createMetricsSection(state));
2411
- grid.appendChild(rightCol);
2412
- popover.appendChild(grid);
2413
- popover.appendChild(createResetSection(state));
2414
- state.overlayElement = popover;
2415
- document.body.appendChild(popover);
2416
- }
2417
- // ============================================================================
2418
- // Settings Popover Section Builders
2419
- // ============================================================================
2420
- function createSettingsHeader(state) {
2421
- const { accentColor } = state.options;
2422
- const header = document.createElement('div');
2423
- Object.assign(header.style, {
2424
- display: 'flex',
2425
- alignItems: 'center',
2426
- justifyContent: 'space-between',
2427
- padding: '10px 14px',
2428
- borderBottom: `1px solid ${accentColor}30`,
2429
- position: 'sticky',
2430
- top: '0',
2431
- backgroundColor: 'var(--devbar-color-bg-elevated)',
2432
- zIndex: '1',
2433
- });
2434
- const title = document.createElement('span');
2435
- Object.assign(title.style, { color: accentColor, fontSize: '0.75rem', fontWeight: '600' });
2436
- title.textContent = 'Settings';
2437
- header.appendChild(title);
2438
- header.appendChild(createCloseButton(() => {
2439
- state.showSettingsPopover = false;
2440
- state.render();
2441
- }));
2442
- return header;
2443
- }
2444
- function createThemeSection(state) {
2445
- const { accentColor } = state.options;
2446
- const color = CSS_COLORS.textSecondary;
2447
- const themeSection = createSettingsSection('Theme');
2448
- const themeOptions = document.createElement('div');
2449
- Object.assign(themeOptions.style, { display: 'flex', gap: '6px' });
2450
- const themeModes = ['system', 'dark', 'light'];
2451
- themeModes.forEach((mode) => {
2452
- const btn = document.createElement('button');
2453
- const isActive = state.themeMode === mode;
2454
- Object.assign(btn.style, {
2455
- padding: '4px 10px',
2456
- backgroundColor: isActive ? `${accentColor}20` : 'transparent',
2457
- border: `1px solid ${isActive ? accentColor : `${color}40`}`,
2458
- borderRadius: '4px',
2459
- color: isActive ? accentColor : color,
2460
- fontSize: '0.625rem',
2461
- cursor: 'pointer',
2462
- textTransform: 'capitalize',
2463
- transition: 'all 150ms',
2464
- });
2465
- btn.textContent = mode;
2466
- btn.onclick = () => {
2467
- setThemeMode(state, mode);
2468
- };
2469
- themeOptions.appendChild(btn);
2470
- });
2471
- themeSection.appendChild(themeOptions);
2472
- return themeSection;
2473
- }
2474
- function createDisplaySection(state) {
2475
- const { accentColor } = state.options;
2476
- const color = CSS_COLORS.textSecondary;
2477
- const displaySection = createSettingsSection('Display');
2478
- // Position mini-map selector
2479
- const positionRow = document.createElement('div');
2480
- Object.assign(positionRow.style, { marginBottom: '10px' });
2481
- const posLabel = document.createElement('div');
2482
- Object.assign(posLabel.style, {
2483
- color: CSS_COLORS.text,
2484
- fontSize: '0.6875rem',
2485
- marginBottom: '6px',
2486
- });
2487
- posLabel.textContent = 'Position';
2488
- positionRow.appendChild(posLabel);
2489
- // Mini-map container (represents screen with ~16:10 aspect ratio)
2490
- const miniMap = document.createElement('div');
2491
- Object.assign(miniMap.style, {
2492
- position: 'relative',
2493
- width: '100%',
2494
- height: '70px',
2495
- backgroundColor: 'var(--devbar-color-bg-input)',
2496
- border: `1px solid ${color}30`,
2497
- borderRadius: '4px',
2498
- });
2499
- // Position indicator styles - rectangular bars representing DevBar
2500
- const positionConfigs = [
2501
- { value: 'top-left', style: { top: '6px', left: '6px' }, title: 'Top Left' },
2502
- { value: 'top-right', style: { top: '6px', right: '6px' }, title: 'Top Right' },
2503
- { value: 'bottom-left', style: { bottom: '6px', left: '6px' }, title: 'Bottom Left' },
2504
- { value: 'bottom-right', style: { bottom: '6px', right: '6px' }, title: 'Bottom Right' },
2505
- {
2506
- value: 'bottom-center',
2507
- style: { bottom: '6px', left: '50%', transform: 'translateX(-50%)' },
2508
- title: 'Bottom Center',
2509
- },
2510
- ];
2511
- positionConfigs.forEach(({ value, style, title: posTitle }) => {
2512
- const indicator = document.createElement('button');
2513
- indicator.setAttribute('data-position', value);
2514
- const isActive = state.options.position === value;
2515
- Object.assign(indicator.style, {
2516
- position: 'absolute',
2517
- width: '24px',
2518
- height: '6px',
2519
- backgroundColor: isActive ? accentColor : CSS_COLORS.textMuted,
2520
- border: `1px solid ${isActive ? accentColor : CSS_COLORS.textMuted}`,
2521
- borderRadius: '2px',
2522
- cursor: 'pointer',
2523
- padding: '0',
2524
- transition: 'all 150ms',
2525
- boxShadow: isActive ? `0 0 8px ${accentColor}60` : 'none',
2526
- opacity: isActive ? '1' : '0.5',
2527
- ...style,
2528
- });
2529
- indicator.title = posTitle;
2530
- indicator.onclick = () => {
2531
- state.options.position = value;
2532
- state.settingsManager.saveSettings({ position: value });
2533
- state.render();
2534
- };
2535
- // Hover effect
2536
- indicator.onmouseenter = () => {
2537
- if (!isActive) {
2538
- indicator.style.backgroundColor = accentColor;
2539
- indicator.style.borderColor = accentColor;
2540
- indicator.style.boxShadow = `0 0 6px ${accentColor}40`;
2541
- indicator.style.opacity = '1';
2542
- }
2543
- };
2544
- indicator.onmouseleave = () => {
2545
- if (!isActive) {
2546
- indicator.style.backgroundColor = CSS_COLORS.textMuted;
2547
- indicator.style.borderColor = CSS_COLORS.textMuted;
2548
- indicator.style.boxShadow = 'none';
2549
- indicator.style.opacity = '0.5';
2550
- }
2551
- };
2552
- miniMap.appendChild(indicator);
2553
- });
2554
- positionRow.appendChild(miniMap);
2555
- displaySection.appendChild(positionRow);
2556
- // Compact mode toggle
2557
- displaySection.appendChild(createToggleRow('Compact Mode', state.compactMode, accentColor, () => {
2558
- state.toggleCompactMode();
2559
- }));
2560
- // Keyboard shortcut hint
2561
- const shortcutHint = document.createElement('div');
2562
- Object.assign(shortcutHint.style, {
2563
- color: CSS_COLORS.textMuted,
2564
- fontSize: '0.5625rem',
2565
- marginTop: '2px',
2566
- marginBottom: '8px',
2567
- });
2568
- shortcutHint.textContent = 'Keyboard: Cmd or Ctrl+Shift+M';
2569
- displaySection.appendChild(shortcutHint);
2570
- // Accent color
2571
- const accentRow = document.createElement('div');
2572
- Object.assign(accentRow.style, { marginBottom: '6px' });
2573
- const accentLabel = document.createElement('div');
2574
- Object.assign(accentLabel.style, {
2575
- color: CSS_COLORS.text,
2576
- fontSize: '0.6875rem',
2577
- marginBottom: '6px',
2578
- });
2579
- accentLabel.textContent = 'Accent Color';
2580
- accentRow.appendChild(accentLabel);
2581
- const colorSwatches = document.createElement('div');
2582
- Object.assign(colorSwatches.style, {
2583
- display: 'flex',
2584
- gap: '6px',
2585
- flexWrap: 'wrap',
2586
- });
2587
- ACCENT_COLOR_PRESETS.forEach(({ name, value }) => {
2588
- const swatch = document.createElement('button');
2589
- const isActive = state.options.accentColor === value;
2590
- Object.assign(swatch.style, {
2591
- width: '24px',
2592
- height: '24px',
2593
- borderRadius: '50%',
2594
- backgroundColor: value,
2595
- border: isActive ? '2px solid #fff' : '2px solid transparent',
2596
- cursor: 'pointer',
2597
- transition: 'all 150ms',
2598
- boxShadow: isActive ? `0 0 8px ${value}` : 'none',
2599
- });
2600
- swatch.title = name;
2601
- swatch.onclick = () => {
2602
- state.options.accentColor = value;
2603
- state.settingsManager.saveSettings({ accentColor: value });
2604
- state.render();
2605
- };
2606
- colorSwatches.appendChild(swatch);
2607
- });
2608
- accentRow.appendChild(colorSwatches);
2609
- displaySection.appendChild(accentRow);
2610
- // Screenshot quality slider
2611
- const qualityRow = document.createElement('div');
2612
- Object.assign(qualityRow.style, { marginTop: '8px' });
2613
- const qualityHeader = document.createElement('div');
2614
- Object.assign(qualityHeader.style, {
2615
- display: 'flex',
2616
- alignItems: 'center',
2617
- justifyContent: 'space-between',
2618
- marginBottom: '6px',
2619
- });
2620
- const qualityLabel = document.createElement('span');
2621
- Object.assign(qualityLabel.style, {
2622
- color: CSS_COLORS.text,
2623
- fontSize: '0.6875rem',
2624
- });
2625
- qualityLabel.textContent = 'Screenshot Quality';
2626
- qualityHeader.appendChild(qualityLabel);
2627
- const qualityValue = document.createElement('span');
2628
- Object.assign(qualityValue.style, {
2629
- color: accentColor,
2630
- fontSize: '0.6875rem',
2631
- fontFamily: 'monospace',
2632
- minWidth: '28px',
2633
- textAlign: 'right',
2634
- });
2635
- const quality = state.options.screenshotQuality;
2636
- qualityValue.textContent = quality.toFixed(2);
2637
- qualityHeader.appendChild(qualityValue);
2638
- qualityRow.appendChild(qualityHeader);
2639
- // Wrapper: positions the visible track line behind the transparent range input
2640
- const sliderWrap = document.createElement('div');
2641
- Object.assign(sliderWrap.style, { position: 'relative', height: '20px' });
2642
- // Visible track rail (a real div, always renders)
2643
- const track = document.createElement('div');
2644
- Object.assign(track.style, {
2645
- position: 'absolute',
2646
- top: '50%',
2647
- left: '0',
2648
- right: '0',
2649
- height: '2px',
2650
- transform: 'translateY(-50%)',
2651
- borderRadius: '1px',
2652
- background: `${color}40`,
2653
- pointerEvents: 'none',
2654
- });
2655
- // Filled portion of the track
2656
- const trackFill = document.createElement('div');
2657
- Object.assign(trackFill.style, {
2658
- height: '100%',
2659
- width: `${quality * 100}%`,
2660
- borderRadius: '1px',
2661
- background: accentColor,
2662
- });
2663
- track.appendChild(trackFill);
2664
- sliderWrap.appendChild(track);
2665
- const qualitySlider = document.createElement('input');
2666
- qualitySlider.type = 'range';
2667
- qualitySlider.min = '0';
2668
- qualitySlider.max = '1';
2669
- qualitySlider.step = '0.01';
2670
- qualitySlider.value = String(quality);
2671
- Object.assign(qualitySlider.style, {
2672
- position: 'absolute',
2673
- top: '0',
2674
- left: '0',
2675
- width: '100%',
2676
- height: '100%',
2677
- appearance: 'none',
2678
- WebkitAppearance: 'none',
2679
- background: 'transparent',
2680
- outline: 'none',
2681
- cursor: 'pointer',
2682
- margin: '0',
2683
- });
2684
- // Style the thumb via a scoped style element
2685
- const sliderId = `devbar-quality-${Date.now()}`;
2686
- qualitySlider.id = sliderId;
2687
- const sliderStyle = document.createElement('style');
2688
- sliderStyle.textContent = [
2689
- `#${sliderId}::-webkit-slider-thumb {`,
2690
- ` -webkit-appearance: none;`,
2691
- ` width: 12px; height: 12px;`,
2692
- ` border-radius: 50%;`,
2693
- ` background: ${accentColor};`,
2694
- ` border: 2px solid ${CSS_COLORS.bg};`,
2695
- ` box-shadow: 0 0 4px ${accentColor}80;`,
2696
- ` cursor: grab;`,
2697
- `}`,
2698
- `#${sliderId}::-webkit-slider-thumb:active { cursor: grabbing; }`,
2699
- `#${sliderId}::-moz-range-thumb {`,
2700
- ` width: 12px; height: 12px;`,
2701
- ` border-radius: 50%;`,
2702
- ` background: ${accentColor};`,
2703
- ` border: 2px solid ${CSS_COLORS.bg};`,
2704
- ` box-shadow: 0 0 4px ${accentColor}80;`,
2705
- ` cursor: grab;`,
2706
- `}`,
2707
- `#${sliderId}::-webkit-slider-runnable-track { background: transparent; }`,
2708
- `#${sliderId}::-moz-range-track { background: transparent; }`,
2709
- ].join('\n');
2710
- sliderWrap.appendChild(sliderStyle);
2711
- qualitySlider.oninput = () => {
2712
- const val = parseFloat(qualitySlider.value);
2713
- qualityValue.textContent = val.toFixed(2);
2714
- trackFill.style.width = `${val * 100}%`;
2715
- state.options.screenshotQuality = val;
2716
- };
2717
- qualitySlider.onchange = () => {
2718
- state.settingsManager.saveSettings({ screenshotQuality: state.options.screenshotQuality });
2719
- };
2720
- sliderWrap.appendChild(qualitySlider);
2721
- qualityRow.appendChild(sliderWrap);
2722
- displaySection.appendChild(qualityRow);
2723
- return displaySection;
2724
- }
2725
- function createFeaturesSection(state) {
2726
- const { accentColor } = state.options;
2727
- const color = CSS_COLORS.textSecondary;
2728
- const featuresSection = createSettingsSection('Features');
2729
- featuresSection.appendChild(createToggleRow('Screenshot Button', state.options.showScreenshot, accentColor, () => {
2730
- state.options.showScreenshot = !state.options.showScreenshot;
2731
- state.settingsManager.saveSettings({ showScreenshot: state.options.showScreenshot });
2732
- state.render();
2733
- }));
2734
- featuresSection.appendChild(createToggleRow('Console Badges', state.options.showConsoleBadges, accentColor, () => {
2735
- state.options.showConsoleBadges = !state.options.showConsoleBadges;
2736
- state.settingsManager.saveSettings({ showConsoleBadges: state.options.showConsoleBadges });
2737
- state.render();
2738
- }));
2739
- featuresSection.appendChild(createToggleRow('Tooltips', state.options.showTooltips, accentColor, () => {
2740
- state.options.showTooltips = !state.options.showTooltips;
2741
- state.settingsManager.saveSettings({ showTooltips: state.options.showTooltips });
2742
- state.render();
2743
- }));
2744
- // Save location selector
2745
- const saveLocRow = document.createElement('div');
2746
- Object.assign(saveLocRow.style, { marginBottom: '6px' });
2747
- const saveLocLabel = document.createElement('div');
2748
- Object.assign(saveLocLabel.style, {
2749
- color: CSS_COLORS.text,
2750
- fontSize: '0.6875rem',
2751
- marginBottom: '6px',
2752
- });
2753
- saveLocLabel.textContent = 'Save Method';
2754
- saveLocRow.appendChild(saveLocLabel);
2755
- const saveLocOptions = document.createElement('div');
2756
- Object.assign(saveLocOptions.style, { display: 'flex', gap: '6px' });
2757
- const saveLocChoices = [
2758
- { value: 'auto', label: 'Auto' },
2759
- { value: 'download', label: 'Download' },
2760
- { value: 'local', label: 'Local' },
2761
- ];
2762
- saveLocChoices.forEach(({ value, label }) => {
2763
- const btn = document.createElement('button');
2764
- const isActive = state.options.saveLocation === value;
2765
- const isLocalDisabled = value === 'local' && !state.sweetlinkConnected;
2766
- Object.assign(btn.style, {
2767
- padding: '4px 10px',
2768
- backgroundColor: isActive ? `${accentColor}20` : 'transparent',
2769
- border: `1px solid ${isActive ? accentColor : `${color}40`}`,
2770
- borderRadius: '4px',
2771
- color: isActive ? accentColor : color,
2772
- fontSize: '0.625rem',
2773
- cursor: isLocalDisabled ? 'not-allowed' : 'pointer',
2774
- transition: 'all 150ms',
2775
- opacity: isLocalDisabled ? '0.5' : '1',
2776
- });
2777
- btn.textContent = label;
2778
- if (isLocalDisabled) {
2779
- btn.title = 'Sweetlink not connected';
2780
- }
2781
- btn.onclick = () => {
2782
- if (isLocalDisabled)
2783
- return;
2784
- state.options.saveLocation = value;
2785
- state.settingsManager.saveSettings({ saveLocation: value });
2786
- state.render();
2787
- };
2788
- saveLocOptions.appendChild(btn);
2789
- });
2790
- saveLocRow.appendChild(saveLocOptions);
2791
- featuresSection.appendChild(saveLocRow);
2792
- return featuresSection;
2793
- }
2794
- function createMetricsSection(state) {
2795
- const { accentColor } = state.options;
2796
- const metricsSection = createSettingsSection('Metrics');
2797
- const metricsToggles = [
2798
- { key: 'breakpoint', label: 'Breakpoint' },
2799
- { key: 'fcp', label: 'FCP' },
2800
- { key: 'lcp', label: 'LCP' },
2801
- { key: 'cls', label: 'CLS' },
2802
- { key: 'inp', label: 'INP' },
2803
- { key: 'pageSize', label: 'Page Size' },
2804
- ];
2805
- metricsToggles.forEach(({ key, label }) => {
2806
- const currentValue = state.options.showMetrics[key] ?? true;
2807
- metricsSection.appendChild(createToggleRow(label, currentValue, accentColor, () => {
2808
- state.options.showMetrics[key] = !state.options.showMetrics[key];
2809
- state.settingsManager.saveSettings({
2810
- showMetrics: {
2811
- breakpoint: state.options.showMetrics.breakpoint ?? true,
2812
- fcp: state.options.showMetrics.fcp ?? true,
2813
- lcp: state.options.showMetrics.lcp ?? true,
2814
- cls: state.options.showMetrics.cls ?? true,
2815
- inp: state.options.showMetrics.inp ?? true,
2816
- pageSize: state.options.showMetrics.pageSize ?? true,
2817
- },
2818
- });
2819
- state.render();
2820
- }));
2821
- });
2822
- return metricsSection;
2823
- }
2824
- function createResetSection(state) {
2825
- const color = CSS_COLORS.textSecondary;
2826
- const resetSection = document.createElement('div');
2827
- Object.assign(resetSection.style, {
2828
- padding: '10px 14px',
2829
- borderTop: `1px solid ${color}20`,
2830
- });
2831
- const resetBtn = createStyledButton({
2832
- color: CSS_COLORS.textMuted,
2833
- text: 'Reset to Defaults',
2834
- padding: '6px 12px',
2835
- fontSize: '0.625rem',
2836
- });
2837
- Object.assign(resetBtn.style, {
2838
- width: '100%',
2839
- justifyContent: 'center',
2840
- border: `1px solid transparent`,
2841
- });
2842
- const resetColor = CSS_COLORS.textMuted;
2843
- resetBtn.onmouseenter = () => {
2844
- resetBtn.style.border = `1px solid ${resetColor}`;
2845
- resetBtn.style.backgroundColor = `${resetColor}10`;
2846
- };
2847
- resetBtn.onmouseleave = () => {
2848
- resetBtn.style.border = '1px solid transparent';
2849
- resetBtn.style.backgroundColor = 'transparent';
2850
- };
2851
- resetBtn.onclick = () => {
2852
- state.settingsManager.resetToDefaults();
2853
- const defaults = DEFAULT_SETTINGS;
2854
- state.applySettings(defaults);
2855
- };
2856
- resetSection.appendChild(resetBtn);
2857
- return resetSection;
2858
- }
2859
- // ============================================================================
2860
- // Settings UI Helpers
2861
- // ============================================================================
2862
- function createSettingsSection(title, hasBorder = true) {
2863
- const color = CSS_COLORS.textSecondary;
2864
- const section = document.createElement('div');
2865
- Object.assign(section.style, {
2866
- padding: '10px 14px',
2867
- borderBottom: hasBorder ? `1px solid ${color}20` : 'none',
2868
- });
2869
- const sectionTitle = document.createElement('div');
2870
- Object.assign(sectionTitle.style, {
2871
- color,
2872
- fontSize: '0.625rem',
2873
- textTransform: 'uppercase',
2874
- letterSpacing: '0.1em',
2875
- marginBottom: '8px',
2876
- });
2877
- sectionTitle.textContent = title;
2878
- section.appendChild(sectionTitle);
2879
- return section;
2880
- }
2881
- function createToggleRow(label, checked, accentColor, onChange) {
2882
- const row = document.createElement('div');
2883
- Object.assign(row.style, {
2884
- display: 'flex',
2885
- alignItems: 'center',
2886
- justifyContent: 'space-between',
2887
- marginBottom: '6px',
2888
- });
2889
- const labelEl = document.createElement('span');
2890
- Object.assign(labelEl.style, { color: CSS_COLORS.text, fontSize: '0.6875rem' });
2891
- labelEl.textContent = label;
2892
- row.appendChild(labelEl);
2893
- const toggle = document.createElement('button');
2894
- Object.assign(toggle.style, {
2895
- width: '32px',
2896
- height: '18px',
2897
- borderRadius: '9px',
2898
- border: `1px solid ${checked ? accentColor : CSS_COLORS.border}`,
2899
- backgroundColor: checked ? accentColor : CSS_COLORS.bgInput,
2900
- position: 'relative',
2901
- cursor: 'pointer',
2902
- transition: 'all 150ms',
2903
- flexShrink: '0',
2904
- boxSizing: 'border-box',
2905
- });
2906
- const knob = document.createElement('span');
2907
- Object.assign(knob.style, {
2908
- position: 'absolute',
2909
- top: '2px',
2910
- left: checked ? '14px' : '2px',
2911
- width: '12px',
2912
- height: '12px',
2913
- borderRadius: '50%',
2914
- backgroundColor: checked ? '#fff' : CSS_COLORS.textMuted,
2915
- boxShadow: '0 1px 2px rgba(0,0,0,0.2)',
2916
- transition: 'left 150ms, background-color 150ms',
2917
- });
2918
- toggle.appendChild(knob);
2919
- toggle.onclick = onChange;
2920
- row.appendChild(toggle);
2921
- return row;
2922
- }
18
+ export { render } from './rendering/index.js';
2923
19
  //# sourceMappingURL=rendering.js.map