Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/common/components/modal-popup/theme-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,23 @@ function ThemePopup({ params, customThemes, colorScheme, lightTheme, darkTheme,
let currentTheme = currentColorScheme === 'light' ? lightTheme : darkTheme;
let bg = '#FFFFFF';
let fg = '#000000';
let lc = '#0000EE';
let vlc = '#551A8B';
let inv = false;
if (currentTheme) {
bg = currentTheme.background;
fg = currentTheme.foreground;
lc = currentTheme.linkColor || '';
vlc = currentTheme.visitedLinkColor || '';
inv = currentTheme.invertImages;
}

let nameRef = useRef();
let [label, setLabel] = useState(params.theme?.label || '');
let [background, setBackground] = useState(params.theme?.background || bg);
let [foreground, setForeground] = useState(params.theme?.foreground || fg);
let [linkColor, setLinkColor] = useState(params.theme?.linkColor || params.theme?.foreground || lc);
let [visitedLinkColor, setVisitedLinkColor] = useState(params.theme?.visitedLinkColor || params.theme?.foreground || vlc);
let [invertImages, setInvertImages] = useState(params.theme?.invertImages ?? inv);

let themeIsDark = isDarkTheme(background, foreground);
Expand Down Expand Up @@ -136,6 +142,18 @@ function ThemePopup({ params, customThemes, colorScheme, lightTheme, darkTheme,
theme.label = label.trim();
theme.background = background;
theme.foreground = foreground;
if (linkColor && isValidHexColor(linkColor)) {
theme.linkColor = linkColor;
}
else {
delete theme.linkColor;
}
if (visitedLinkColor && isValidHexColor(visitedLinkColor)) {
theme.visitedLinkColor = visitedLinkColor;
}
else {
delete theme.visitedLinkColor;
}
if (invertImages) {
theme.invertImages = true;
}
Expand Down Expand Up @@ -181,6 +199,8 @@ function ThemePopup({ params, customThemes, colorScheme, lightTheme, darkTheme,
!nameInvalid
&& isValidHexColor(background)
&& isValidHexColor(foreground)
&& (!linkColor || isValidHexColor(linkColor))
&& (!visitedLinkColor || isValidHexColor(visitedLinkColor))
);

return (
Expand All @@ -202,6 +222,10 @@ function ThemePopup({ params, customThemes, colorScheme, lightTheme, darkTheme,
<div className="input"><ColorPicker color={background} onChange={handleBackgroundChange}/></div>
<label>{l10n.getString('reader-foreground')}</label>
<div className="input"><ColorPicker color={foreground} onChange={handleForegroundChange}/></div>
<label>{l10n.getString('reader-link-color')}</label>
<div className="input"><ColorPicker color={linkColor} onChange={setLinkColor}/></div>
<label>{l10n.getString('reader-visited-link-color')}</label>
<div className="input"><ColorPicker color={visitedLinkColor} onChange={setVisitedLinkColor}/></div>
<div></div>
<div>
<div className="option">
Expand Down
8 changes: 4 additions & 4 deletions src/common/defines.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export const INK_ANNOTATION_WIDTH_STEPS = [
export const TEXT_ANNOTATION_FONT_SIZE_STEPS = [6, 8, 10, 12, 14, 18, 24, 36, 48, 64, 72, 96, 144, 192];

export const DEFAULT_THEMES = [
{ id: 'dark', label: 'Dark', background: "#2E3440", foreground: "#D8DEE9" },
{ id: 'black', label: 'Black', background: "#000000", foreground: "#FFFFFF", invertImages: true },
{ id: 'snow', label: 'Snow', background: "#ECEFF4", foreground: "#3B4252" },
{ id: 'sepia', label: 'Sepia', background: "#F4ECD8", foreground: "#5B4636" }
{ id: 'dark', label: 'Dark', background: "#2E3440", foreground: "#D8DEE9", linkColor: "#88C0D0", visitedLinkColor: "#6E9FAB" },
{ id: 'black', label: 'Black', background: "#000000", foreground: "#FFFFFF", linkColor: "#6CB6FF", visitedLinkColor: "#5A92CC", invertImages: true },
{ id: 'snow', label: 'Snow', background: "#ECEFF4", foreground: "#3B4252", linkColor: "#4C6E96", visitedLinkColor: "#3D5975" },
{ id: 'sepia', label: 'Sepia', background: "#F4ECD8", foreground: "#5B4636", linkColor: "#8A4F3D", visitedLinkColor: "#6E3F31" }
];

export const A11Y_VIRT_CURSOR_DEBOUNCE_LENGTH = 500; // ms
Expand Down
2 changes: 2 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ export type Theme = {
label: string;
background: string;
foreground: string;
linkColor?: string;
visitedLinkColor?: string;
invertImages?: boolean;
};

Expand Down
2 changes: 2 additions & 0 deletions src/dom/common/dom-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,8 @@ abstract class DOMView<State extends DOMViewState, Data> {
root.style.colorScheme = themeColorScheme;
root.style.setProperty('--background-color', theme.background);
root.style.setProperty('--text-color', theme.foreground);
root.style.setProperty('--link-color', theme.linkColor || theme.foreground);
root.style.setProperty('--visited-link-color', theme.visitedLinkColor || theme.linkColor || theme.foreground);
}

this._theme = theme;
Expand Down
9 changes: 0 additions & 9 deletions src/dom/epub/stylesheets/_content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@
}
}

:root {
--link-color: #0000ee;
--visited-link-color: #551a8b;

&[data-color-scheme="dark"] {
--link-color: #63caff;
--visited-link-color: #0099e5;
}
}

:root {
font-size: calc(var(--content-scale) * 13pt) !important;
Expand Down
8 changes: 8 additions & 0 deletions src/dom/snapshot/stylesheets/inject.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ body.force-static-theme {
background-color: transparent !important;
color: var(--text-color);
}

:link {
color: var(--link-color) !important;
}

:visited {
color: var(--visited-link-color) !important;
}
}
7 changes: 0 additions & 7 deletions src/dom/snapshot/stylesheets/reading-mode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
background-color: var(--background-color);
color: var(--text-color);

--link-color: #0000ee;
--visited-link-color: #551a8b;

&[data-color-scheme="dark"] {
--link-color: #63caff;
--visited-link-color: #0099e5;
}
}

body {
Expand Down
6 changes: 6 additions & 0 deletions src/pdf/pdf-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,16 +543,22 @@ class PDFView {
if (this._colorScheme === 'light' && this._lightTheme) {
this._iframeWindow.theme = this._lightTheme;
root.style.setProperty('--background-color', this._lightTheme.background);
root.style.setProperty('--link-color', this._lightTheme.linkColor || this._lightTheme.foreground);
root.style.setProperty('--visited-link-color', this._lightTheme.visitedLinkColor || this._lightTheme.linkColor || this._lightTheme.foreground);
this._themeColorScheme = getModeBasedOnColors(this._lightTheme.background, this._lightTheme.foreground);
}
else if (this._colorScheme === 'dark' && this._darkTheme) {
this._iframeWindow.theme = this._darkTheme;
root.style.setProperty('--background-color', this._darkTheme.background);
root.style.setProperty('--link-color', this._darkTheme.linkColor || this._darkTheme.foreground);
root.style.setProperty('--visited-link-color', this._darkTheme.visitedLinkColor || this._darkTheme.linkColor || this._darkTheme.foreground);
this._themeColorScheme = getModeBasedOnColors(this._darkTheme.background, this._darkTheme.foreground);
}
else {
this._iframeWindow.theme = null;
root.style.setProperty('--background-color', '#FFFFFF');
root.style.setProperty('--link-color', '#121212');
root.style.setProperty('--visited-link-color', '#121212');
this._themeColorScheme = 'light';
}

Expand Down
Loading