Skip to content

fix: correct OOXML theme color tint/shade resolution#270

Merged
jedrazb merged 3 commits intoeigenpal:mainfrom
sted:fix/theme-colors
Apr 17, 2026
Merged

fix: correct OOXML theme color tint/shade resolution#270
jedrazb merged 3 commits intoeigenpal:mainfrom
sted:fix/theme-colors

Conversation

@sted
Copy link
Copy Markdown
Contributor

@sted sted commented Apr 16, 2026

Summary

  • Fix tint/shade color formulas in colorResolver.ts: replaced HSL-based approach with the OOXML per-channel linear interpolation specified in ECMA-376 §17.3.2.41. The previous formula produced incorrect intermediate colors (e.g., a 20% tint of dark blue produced medium blue instead of very light blue).
  • Resolve theme colors for table cell backgrounds in toProseDoc.ts: table cells using theme fills (e.g., themeFill="accent1" with tint/shade modifiers) were rendering with no background because only the rgb property was checked, ignoring theme color references. Now threads the document theme through the conversion and calls resolveColor().
  • Add regression tests (17 new tests):
    • colorResolver.test.ts — covers resolveColor with real-world tint/shade values (`33`, `99`, `F2`) and edge cases (`FF` = no change, `00` = fully white/black).
    • toProseDoc.test.ts (new) — integration tests verifying that themed cell shading resolves to correct `backgroundColor` attrs on PM nodes.

Before / After

Table header rows and section rows using theme colors (common in Word's built-in table styles) now render with correct backgrounds instead of white.

Test plan

  • `bun run typecheck` passes
  • `bun test` — all 357 tests pass (340 existing + 17 new)
  • `bun run build` succeeds
  • Visual verification with DOCX files using themed table styles

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 16, 2026

@sted is attempting to deploy a commit to the EigenPal Team on Vercel.

A member of the Team first needs to authorize it.

Covers the tint/shade math fix and the theme color threading through
toProseDoc to table cell backgroundColor attrs. Uses real-world tint
values (33, 99, F2) from documents with themed table styles.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docx-editor Ready Ready Preview, Comment Apr 17, 2026 6:48am

Request Review

@jedrazb jedrazb merged commit 50a7b02 into eigenpal:main Apr 17, 2026
4 checks passed
jedrazb added a commit that referenced this pull request Apr 17, 2026
Adds `resolveColorToHex` as the single shared helper for converting any
`ColorValue` (rgb or themeColor+tint/shade) to a display-ready hex string,
with consistent handling of transparent/auto and missing-theme cases.

Applies it at every display-side call site so `themeFill`/`themeColor`
with `themeTint`/`themeShade` is honored everywhere, not just on table cells:

- `toProseDoc.ts` — replaces the inline resolution added in #270.
- `toFlowBlocks.ts` — paragraph shading now resolves themed fills (previously
  read `.fill.rgb` directly, silently dropping themed paragraph backgrounds).
- `clipboard.ts` — HTML copy now honors themed text color and shading when
  a theme is threaded through `ClipboardOptions`/`useClipboard` options.

Tests: +20 new pass (357 → 377 total), covering helper edge cases,
paragraph themed-shading end-to-end (Document → PM → flow blocks), and
clipboard HTML with themed runs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jedrazb added a commit that referenced this pull request Apr 17, 2026
* refactor: unify theme color resolution across display paths

Adds `resolveColorToHex` as the single shared helper for converting any
`ColorValue` (rgb or themeColor+tint/shade) to a display-ready hex string,
with consistent handling of transparent/auto and missing-theme cases.

Applies it at every display-side call site so `themeFill`/`themeColor`
with `themeTint`/`themeShade` is honored everywhere, not just on table cells:

- `toProseDoc.ts` — replaces the inline resolution added in #270.
- `toFlowBlocks.ts` — paragraph shading now resolves themed fills (previously
  read `.fill.rgb` directly, silently dropping themed paragraph backgrounds).
- `clipboard.ts` — HTML copy now honors themed text color and shading when
  a theme is threaded through `ClipboardOptions`/`useClipboard` options.

Tests: +20 new pass (357 → 377 total), covering helper edge cases,
paragraph themed-shading end-to-end (Document → PM → flow blocks), and
clipboard HTML with themed runs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(color): fix round-trip + simplify helper + unify toolbar swatches

Addresses review feedback on #272.

**fromProseDoc round-trip fix** — themed cells (`themeFill` + `themeFillTint`/`themeFillShade`) no longer lose their theme refs on save. Stores the parse-time resolved hex in a new `_originalResolvedFill` attr; if it still matches `attrs.backgroundColor` at save time, the user hasn't changed the color so `orig.shading` is preserved intact. If they have changed it, we write plain `{ fill: { rgb } }` as before.

**Helper simplification** — `resolveColorToHex` now uses `slice(1)` instead of a second `.replace(/^#/, '')` in the themed-color branch (`resolveColor` already guarantees the `#` prefix). Dedups the rgb-without-theme fallback by folding it into the single `rgb` branch below. Trims the docstring.

**Unify remaining sites** — three sites were hand-rolling the same `resolveColor(...).replace(/^#/, '')` pattern; all now use the helper:
- `DocxEditor.tsx:1474` (cell border color)
- `FormattingBar.tsx:597` (table border color picker value)
- `AdvancedColorPicker.tsx:222` (selected-cell hex comparison)

Plus two sites that read `.color?.rgb` directly and dropped themed text colors:
- `DocxEditor.tsx` text-color swatch readout
- `toolbarUtils.ts` `getSelectionFormatting` (new optional `theme` param)

**Tests** — 3 new round-trip tests in `toProseDoc.test.ts` proving themed `tint`/`shade` survive toProseDoc → fromProseDoc unchanged, and that user-initiated color changes still override theme refs with plain rgb.

380 pass (was 377), typecheck clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sted sted deleted the fix/theme-colors branch April 17, 2026 13:40
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.

2 participants