Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2021
Merged
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
6 changes: 0 additions & 6 deletions external/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,6 @@ 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);
}
Expand Down
18 changes: 8 additions & 10 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down