fix(style): keep Override Book Color working over a background texture, closes #6712 (#6765)

#3761 skipped the whole Override Book Color block rule when a background
texture is set, so the override also stopped forcing text and border
colors and book text could stay unreadable. With a texture, the override
now still forces text and border colors and fills block and span
backgrounds with transparent instead of the theme background, so the
texture shows through. Without the override or without a texture the
generated styles are unchanged.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Huang Xin 2026-10-14 00:13:42 +08:00 • committed by GitHub
parent 7e75d60f4b
commit a09e069133
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View file

@ -832,6 +832,17 @@ describe('getColorStyles branches (via getStyles)', () => {
);
});
it('keeps overriding text colors over a background texture, with transparent fills (#6712)', () => {
const vs = makeViewSettings({ overrideColor: true, backgroundTextureId: 'leaves' });
const theme = makeThemeCode({ isDarkMode: true, bg: '#1a1a1a', fg: '#e0e0e0' });
const css = getStyles(vs, theme);
const block = css.match(/section, aside, blockquote[^{]*\{([^}]*)\}/)![1]!;
expect(block).toContain('background-color: transparent !important');
expect(block).toContain('color: #e0e0e0 !important');
expect(block).toContain('border-color: #e0e0e0 !important');
expect(css).toMatch(/pre, span \{[^}]*background-color: transparent !important/);
});
it('makes svg/img backgrounds transparent when overrideColor is true', () => {
const vs = makeViewSettings({ overrideColor: true });
const theme = makeThemeCode();

View file

@ -335,6 +335,9 @@ const getColorStyles = (
) => {
const { bg, fg, primary, isDarkMode } = themeCode;
const hasBackgroundTexture = !!backgroundTextureId && backgroundTextureId !== 'none';
// Over a background texture, Override Book Color still forces the text
// colors but fills backgrounds with transparent so the texture shows (#6712).
const overrideBg = hasBackgroundTexture ? 'transparent' : bg;
const colorStyles = `
html {
--bg-texture-id: ${backgroundTextureId};
@ -360,12 +363,12 @@ const getColorStyles = (
}
section, aside, blockquote, article, nav, header, footer, main, figure,
div, p, font, h1, h2, h3, h4, h5, h6, li, span {
${overrideColor && !hasBackgroundTexture ? `background-color: ${bg} !important;` : ''}
${overrideColor && !hasBackgroundTexture ? `color: ${fg} !important;` : ''}
${overrideColor && !hasBackgroundTexture ? `border-color: ${fg} !important;` : ''}
${overrideColor ? `background-color: ${overrideBg} !important;` : ''}
${overrideColor ? `color: ${fg} !important;` : ''}
${overrideColor ? `border-color: ${fg} !important;` : ''}
}
pre, span { /* inline code blocks */
${overrideColor ? `background-color: ${bg} !important;` : ''}
${overrideColor ? `background-color: ${overrideBg} !important;` : ''}
}
a:any-link {
${overrideColor ? `color: ${primary} !important;` : isDarkMode ? `color: lightblue;` : ''}