Merge pull request #17222 from Snuffleupagus/rm-viewerCssTheme

Remove the `viewerCssTheme`-option, since it's partially broken
This commit is contained in:
Jonas Jenwald 2023-11-04 17:40:03 +01:00 committed by GitHub
commit 50f52b43a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 64 deletions

View File

@ -1,17 +1,6 @@
{
"type": "object",
"properties": {
"viewerCssTheme": {
"title": "Theme",
"description": "The theme to use.\n0 = Use system theme.\n1 = Light theme.\n2 = Dark theme.",
"type": "integer",
"enum": [
0,
1,
2
],
"default": 2
},
"showPreviousViewOnLoad": {
"description": "DEPRECATED. Set viewOnLoad to 1 to disable showing the last page/position on load.",
"type": "boolean",

View File

@ -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
*/

View File

@ -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,