For mozcentral use Firefox color theme instead of system theme.

See: https://bugzilla.mozilla.org/show_bug.cgi?id=1701691
This commit is contained in:
Brendan Dahl 2021-04-28 12:00:28 -07:00
parent d10da907da
commit 2c713f9cb5
2 changed files with 16 additions and 7 deletions

View File

@ -269,6 +269,12 @@ function preprocessCSS(mode, source, destination) {
content = expandImports(content, source);
if (mode === "mozcentral") {
content = removePrefixed(content, hasPrefixedMozcentral);
// In the mozcentral version the color theme should be based on the Firefox
// theme instead of the system theme.
content = content.replace(
"prefers-color-scheme",
"-moz-toolbar-prefers-color-scheme"
);
}
fs.writeFileSync(destination, content);
}

View File

@ -424,20 +424,23 @@ const PDFViewerApplication = {
try {
const styleSheet = document.styleSheets[0];
const cssRules = styleSheet?.cssRules || [];
const mediaMatcher =
typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")
? "-moz-toolbar-prefers-color-scheme"
: "prefers-color-scheme";
const mediaRule = `(${mediaMatcher}: dark)`;
const mediaRegex = new RegExp(
`^@media \\(${mediaMatcher}: dark\\) {\\n\\s*([\\w\\s-.,:;/\\\\{}()]+)\\n}$`
);
for (let i = 0, ii = cssRules.length; i < ii; i++) {
const rule = cssRules[i];
if (
rule instanceof CSSMediaRule &&
rule.media?.[0] === "(prefers-color-scheme: dark)"
) {
if (rule instanceof CSSMediaRule && rule.media?.[0] === mediaRule) {
if (cssTheme === ViewerCssTheme.LIGHT) {
styleSheet.deleteRule(i);
return;
}
// cssTheme === ViewerCssTheme.DARK
const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(
rule.cssText
);
const darkRules = mediaRegex.exec(rule.cssText);
if (darkRules?.[1]) {
styleSheet.deleteRule(i);
styleSheet.insertRule(darkRules[1], i);