1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

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

Reverts mozilla/pdf.js#13314, see https://groups.google.com/g/firefox-dev/c/vajhbYKDpPM

Given that `-moz-toolbar-prefers-color-scheme` was removed in https://bugzilla.mozilla.org/show_bug.cgi?id=1736038, unless we fix this before the next PDF.js update in mozilla-central we'll thus break dark mode in the Firefox built-in PDF Viewer.
This commit is contained in:
Jonas Jenwald 2021-10-17 12:17:42 +02:00
parent 52fce0d17b
commit aae8a21286
2 changed files with 8 additions and 16 deletions

View file

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