From 8ba9fa006dedcd64cb91eafa97f982112d757da6 Mon Sep 17 00:00:00 2001 From: Markus Date: Sat, 14 Nov 2026 10:43:37 +0100 Subject: [PATCH] feat(theme): design tokens for every color, type and shape; theme objects 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 --- README.md | 3 +- docs/api.md | 7 +- docs/features.md | 2 +- docs/theming.md | 90 ++++++++++ e2e/app/main.tsx | 1 + e2e/viewer.spec.ts | 29 ++++ package.json | 6 +- playground/main.tsx | 2 +- src/index.ts | 2 +- src/react/DocViewer.tsx | 22 ++- src/react/common/hooks.ts | 4 +- src/react/pptx/PptxView.tsx | 2 +- src/react/pptx/Slide.tsx | 4 +- src/react/styles.css | 333 +++++++++++++++++++++--------------- src/react/theme.ts | 81 +++++++++ test/theme.test.ts | 62 +++++++ 16 files changed, 493 insertions(+), 157 deletions(-) create mode 100644 docs/theming.md create mode 100644 src/react/theme.ts create mode 100644 test/theme.test.ts diff --git a/README.md b/README.md index 7bac394..45ca7a7 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ Also online at [p10node.github.io/office-engine](https://p10node.github.io/offic - [Features](docs/features.md): format coverage, editing, saving, limitations - [API](docs/api.md): props, custom views, `mount()`, ``, core API, CSP +- [Theming](docs/theming.md): design tokens, light / dark, loading the stylesheet yourself - [Real-time collaboration](docs/collaboration.md) - [Development](docs/development.md): playground, architecture, demo deploy, release @@ -75,7 +76,7 @@ Also online at [p10node.github.io/office-engine](https://p10node.github.io/offic - **File menu**: new, open (also DOC / XLS / PPT / RTF / OpenDocument / Pages / Keynote / Numbers / CSV / text / Markdown / HTML / SVG / diagrams), import CSV, rename, download as PDF / HTML / text / CSV, document details, print - **Comments**: threads with replies, resolve, edit / delete, @mentions; on DOCX text, XLSX cells and PPTX slides, stored in the file the way Word, Excel and PowerPoint store them - **Real-time collaboration**: live edits, avatars, collaborators' cursors, offline edits sync on reconnect -- **Dark mode**: `theme="dark"` or `"auto"` (follows the OS); documents keep their own colors +- **Dark mode and theming**: `theme="dark"` or `"auto"` (follows the OS), or a theme object with design tokens for colors, type and shape ([Theming](docs/theming.md)); documents keep their own colors - **Embed anywhere**: React component, hook, vanilla `mount()`, `` web component, single `