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:
parent
52fce0d17b
commit
aae8a21286
6
external/builder/builder.js
vendored
6
external/builder/builder.js
vendored
@ -270,12 +270,6 @@ 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);
|
||||||
}
|
}
|
||||||
|
18
web/app.js
18
web/app.js
@ -431,23 +431,21 @@ 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 (rule instanceof CSSMediaRule && rule.media?.[0] === mediaRule) {
|
if (
|
||||||
|
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 = mediaRegex.exec(rule.cssText);
|
const darkRules =
|
||||||
|
/^@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);
|
||||||
|
Loading…
Reference in New Issue
Block a user