Skip to content

feat(staged): theme Pikchr diagram colors to match the active theme - #846

Merged
matt2e merged 4 commits into
mainfrom
pikchr-color-scheme
Jul 2, 2026
Merged

feat(staged): theme Pikchr diagram colors to match the active theme#846
matt2e merged 4 commits into
mainfrom
pikchr-color-scheme

Conversation

@matt2e

@matt2e matt2e commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Pikchr renders diagrams with hard-coded black-on-white styling that clashes with the app's dark and light themes. This teaches the SVG sanitizer to remap Pikchr's default colors onto a themed palette so diagrams blend into the surrounding UI.

Changes

  • Themed palette (theme.ts, app.css): extend the diagram theme with pikchrInk, pikchrSurface, pikchrMuted, and accent colors (red/green/blue/yellow/orange/purple/cyan) derived from the active theme's syntax and accent colors, exposed as --pikchr-* CSS custom properties. The diagram canvas background is now derived from the theme rather than a hard-coded #ffffff.
  • Color remapping (pikchrRendering.ts): sanitizePikchrSvg maps common Pikchr colors — named (red, green, …), rgb(...), and hex — onto the themed CSS variables, and defaults stroke/text ink to var(--pikchr-ink). The sanitizer's allowed CSS color set is widened to accept var(--pikchr-*). Explicit numeric color literals (0xRRGGBB) from the diagram source are preserved so intentional author colors aren't overridden.
  • Source threading (diagramRendering.ts): the raw diagram source is passed into the sanitizer so numeric color literals can be detected and preserved.
  • Tests: added coverage for palette mapping, numeric-literal preservation, fill:none handling, and the exposed CSS variables across pikchrRendering.test.ts, renderMarkdown.test.ts, and theme.test.ts.

The follow-up commits tune the specific palette shades for better legibility.

matt2e added 4 commits July 2, 2026 16:29
Signed-off-by: Matt Toohey <contact@matttoohey.com>
Signed-off-by: Matt Toohey <contact@matttoohey.com>
Signed-off-by: Matt Toohey <contact@matttoohey.com>
Signed-off-by: Matt Toohey <contact@matttoohey.com>
@matt2e
matt2e requested review from baxen and wesbillman as code owners July 2, 2026 10:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08dfd0b5d1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

]);
const RGB_COLOR = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i;
const HEX_COLOR = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
const PIKCHR_NUMERIC_COLOR_LITERAL = /\b0x([0-9a-fA-F]{6})\b/g;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve all numeric Pikchr color literals

When a diagram uses Pikchr's decimal or shorter C-style numeric color literals (for example color 0, color 255, or fill 16777215), this regex does not add the rendered #000000/#0000ff/#ffffff key to preservedColors, so themePikchrColor later rewrites those explicit author colors to theme variables. Pikchr color expressions are 24-bit numeric values, not only six-digit 0xRRGGBB constants, so this breaks the intended preservation for supported numeric color syntax whenever the chosen value is one of the mapped colors.

Useful? React with 👍 / 👎.

@matt2e
matt2e merged commit 594ac94 into main Jul 2, 2026
4 checks passed
@matt2e
matt2e deleted the pikchr-color-scheme branch July 2, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant