Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/web/src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@ if (typeof localStorage !== 'undefined') {
document.documentElement.dataset.theme = savedTheme;
}

// Dark-theme defaults for non-browser environments (e.g. Node.js tests).
// Values must match the dark theme in style.css.
const DARK_THEME_DEFAULTS = {
canvasBg: '#1a1a1a', canvasText: '#666', canvasAxis: '#555',
canvasLabel: '#aaa', canvasGrid: '#333', canvasTitle: '#888',
fgPrimary: '#ccc', fgMuted: '#888', bgPanel: '#252525',
bgMap: '#111',
};

// Read current CSS custom property values for canvas-based widgets.
export function getThemeColors() {
if (typeof document === 'undefined') {
return { ...DARK_THEME_DEFAULTS };
}
Comment on lines +23 to +25
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The hardcoded fallback values for the dark theme do not match the values defined in src/web/src/style.css. For consistency and to avoid potential discrepancies in tests, these values should be synchronized with the CSS source of truth.

Specifically:

  • canvasText: #ccc should be #666 (matches --canvas-text)
  • canvasTitle: #fff should be #888 (matches --canvas-title)
  • fgPrimary: #e0e0e0 should be #ccc (matches --fg-primary)
  • bgMap: #1a1a1a should be #111 (matches --bg-map)

Additionally, per the general rules, these tunable parameters should ideally be defined as named constants rather than hardcoded magic numbers within the function body.

References
  1. Define tunable parameters as named constants instead of using hardcoded magic numbers.

const s = getComputedStyle(document.documentElement);
const v = (name) => s.getPropertyValue(name).trim();
return {
Expand Down
Loading