Revert "Revert "For mozcentral use Firefox color theme instead of system theme." since -moz-toolbar-prefers-color-scheme was removed"

This reverts commit aae8a2128685f4af94bee2466096bdc2473c0ba7.
This commit is contained in:
Brendan Dahl 2022-01-04 17:15:21 -08:00
parent e788665a26
commit 86c9a8970b
2 changed files with 16 additions and 8 deletions

View File

@ -270,6 +270,12 @@ function preprocessCSS(mode, source, destination) {
content = expandImports(content, source); content = expandImports(content, source);
if (mode === "mozcentral") { if (mode === "mozcentral") {
content = removePrefixed(content, hasPrefixedMozcentral); 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); fs.writeFileSync(destination, content);
} }

View File

@ -431,21 +431,23 @@ const PDFViewerApplication = {
try { try {
const styleSheet = document.styleSheets[0]; const styleSheet = document.styleSheets[0];
const cssRules = styleSheet?.cssRules || []; 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++) { for (let i = 0, ii = cssRules.length; i < ii; i++) {
const rule = cssRules[i]; const rule = cssRules[i];
if ( if (rule instanceof CSSMediaRule && rule.media?.[0] === mediaRule) {
rule instanceof CSSMediaRule &&
rule.media?.[0] === "(prefers-color-scheme: dark)"
) {
if (cssTheme === ViewerCssTheme.LIGHT) { if (cssTheme === ViewerCssTheme.LIGHT) {
styleSheet.deleteRule(i); styleSheet.deleteRule(i);
return; return;
} }
// cssTheme === ViewerCssTheme.DARK // cssTheme === ViewerCssTheme.DARK
const darkRules = const darkRules = mediaRegex.exec(rule.cssText);
/^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(
rule.cssText
);
if (darkRules?.[1]) { if (darkRules?.[1]) {
styleSheet.deleteRule(i); styleSheet.deleteRule(i);
styleSheet.insertRule(darkRules[1], i); styleSheet.insertRule(darkRules[1], i);