Skip to content

feat(theme): design tokens for every color, type and shape; theme objects - #4

Merged
pierreneter merged 1 commit into
p10node:mainfrom
mkroemer:theming
Nov 17, 2026
Merged

pierreneter merged 1 commit into
p10node:mainfrom
mkroemer:theming

Conversation

@mkroemer

Copy link
Copy Markdown
Contributor

This lets a host give the viewer its own look without overriding the stylesheet's selectors.

Every color in styles.css is now a --de-* custom property on .de-root, with the dark values on .de-root.de-dark. That includes the find highlights, collaboration status and avatars, the slideshow, tooltips, file badges, paper and placeholders, and the source editor's syntax colors, which moved to the root so a theme reaches them. Fonts, radii and shadows are tokens too.

theme still takes 'light' | 'dark' | 'auto', and now also an object:

<DocViewer
  src={file}
  theme={{
    mode: 'auto',
    tokens: { accent: '#7c3aed', font: 'Inter, sans-serif', radius: '4px' },
    dark: { accent: '#a78bfa' },
  }}
/>

Token names are typed and camelCase (accentHover sets --de-accent-hover, list in THEME_TOKENS). createTheme, themeStyle and useThemeRoot are exported for hosts that mount DocxView, XlsxView or PptxView in a root of their own. A host that cannot inject a style tag (CSP, extracted CSS, cascade layers) passes injectStyles={false} and imports @p10node/office-engine/styles.css. docs/theming.md describes it all.

Rendering is unchanged. I compared computed styles against the current stylesheet over DOCX, XLSX, PPTX and Markdown files, light and dark. The only differences are equivalent font stacks and the color button's swatch edge, which now follows swatch-border and so is visible in dark mode.

test/theme.test.ts keeps THEME_TOKENS and the stylesheet in step and fails on a literal color outside a token definition. e2e/viewer.spec.ts covers theme objects in both modes and injectStyles={false}. On current main (v0.13.2), bun run typecheck, bun test and the e2e suite pass in CI.

This is the first of a few small PRs I'd like to propose, each building on the one before: host icons, translatable UI texts (English and German), replaceable toolbar components, and a headless mode where the host draws its own controls from a controller. Happy to rename things or split this further if you prefer.

🤖 Generated with Claude Code

…ects

Every color in the stylesheet is now a --de-* token on .de-root, with the
dark values on .de-root.de-dark: find highlights, collaboration status,
avatars, slideshow, tooltips, file badges, paper and placeholders, and the
source editor's syntax colors (moved to the root so a theme reaches them).
Fonts, radii and shadows are tokens too. Rendering is unchanged: a
computed-style comparison against the previous stylesheet over DOCX, XLSX,
PPTX and Markdown, light and dark, differs only in equivalent font stacks
and the color-button swatch edge, which now follows swatch-border (visible
in dark).

- theme accepts { mode, tokens, light, dark } with typed camelCase token
  names (ThemeTokens); THEME_TOKENS, createTheme, themeStyle, useThemeRoot
- injectStyles={false} and @p10node/office-engine/styles.css for hosts that
  load the stylesheet themselves (CSP, extracted CSS, cascade layers)
- docs/theming.md; unit tests keep THEME_TOKENS and the stylesheet in step
  and reject literal colors outside token definitions; e2e for theme
  objects in both modes and for injectStyles=false

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pierreneter pierreneter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot for this, and for splitting the work into reviewable steps.

Approved. Merges cleanly; typecheck and unit tests pass on the tip, and I compared the resolved styles with main in light and dark.

Notes for the release, nothing to change before merging:

  • The exported Theme type is now ThemeMode | ThemeOptions, so a host that used it as the mode union stops compiling. I'll call it out in the notes.
  • color-mix() is new in styles.css. Chrome < 111, Safari < 16.2 and Firefox < 113 drop those declarations, so the XLSX range selection loses its fill there. A plain fallback declaration before each one would cover it, in a follow-up if you like.
  • Theme token values are written as given. That is fine in the browser; under SSR they land in the style attribute, so docs/theming.md could say they must not come from untrusted input.

@pierreneter
pierreneter merged commit 8ba9fa0 into p10node:main Nov 17, 2026
2 checks passed
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.

3 participants