mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Remove the viewerCssTheme
-option, since it's partially broken
The `viewerCssTheme`-implementation has always been somewhat hacky, and now it's also *partially* broken ever since we've started using CSS nesting. Trying to support nested media queries would thus require a lot more parsing of the CSS rules, which seems inefficient and thus generally undesirable.[1] As discussed on Matrix, let's try to remove the `viewerCssTheme`-option and see if there's any (significant) fallout from this. --- [1] If this option is brought back, it seems to me that it (in Firefox) should probably be set through the platform-code that handles theming.
This commit is contained in:
parent
f528f6f07b
commit
d46578e959
3 changed files with 0 additions and 64 deletions
48
web/app.js
48
web/app.js
|
@ -85,12 +85,6 @@ const ViewOnLoad = {
|
|||
INITIAL: 1,
|
||||
};
|
||||
|
||||
const ViewerCssTheme = {
|
||||
AUTOMATIC: 0, // Default value.
|
||||
LIGHT: 1,
|
||||
DARK: 2,
|
||||
};
|
||||
|
||||
class DefaultExternalServices {
|
||||
constructor() {
|
||||
throw new Error("Cannot initialize DefaultExternalServices.");
|
||||
|
@ -233,7 +227,6 @@ const PDFViewerApplication = {
|
|||
if (AppOptions.get("pdfBugEnabled")) {
|
||||
await this._parseHashParams();
|
||||
}
|
||||
this._forceCssTheme();
|
||||
|
||||
// Ensure that the `L10n`-instance has been initialized before creating
|
||||
// e.g. the various viewer components.
|
||||
|
@ -347,47 +340,6 @@ const PDFViewerApplication = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_forceCssTheme() {
|
||||
const cssTheme = AppOptions.get("viewerCssTheme");
|
||||
if (
|
||||
cssTheme === ViewerCssTheme.AUTOMATIC ||
|
||||
!Object.values(ViewerCssTheme).includes(cssTheme)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const styleSheet = document.styleSheets[0];
|
||||
const cssRules = styleSheet?.cssRules || [];
|
||||
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 (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
|
||||
);
|
||||
if (darkRules?.[1]) {
|
||||
styleSheet.deleteRule(i);
|
||||
styleSheet.insertRule(darkRules[1], i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (reason) {
|
||||
console.error(`_forceCssTheme: "${reason?.message}".`);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
|
|
@ -218,11 +218,6 @@ const defaultOptions = {
|
|||
value: 1,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
viewerCssTheme: {
|
||||
/** @type {number} */
|
||||
value: typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME") ? 2 : 0,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
viewOnLoad: {
|
||||
/** @type {boolean} */
|
||||
value: 0,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue