Re-factor how the "compatibility" values are specified in AppOptions

The intention with this change is to, more clearly, highlight when the default values may possibly be overridden by "compatibility" values.
This commit is contained in:
Jonas Jenwald 2019-02-02 10:09:05 +01:00
parent 9d8342002c
commit ef634b51e1

View File

@ -96,7 +96,8 @@ const defaultOptions = {
*/ */
maxCanvasPixels: { maxCanvasPixels: {
/** @type {number} */ /** @type {number} */
value: viewerCompatibilityParams.maxCanvasPixels || 16777216, value: 16777216,
compatibility: viewerCompatibilityParams.maxCanvasPixels,
kind: OptionKind.VIEWER, kind: OptionKind.VIEWER,
}, },
pdfBugEnabled: { pdfBugEnabled: {
@ -163,7 +164,8 @@ const defaultOptions = {
}, },
disableCreateObjectURL: { disableCreateObjectURL: {
/** @type {boolean} */ /** @type {boolean} */
value: apiCompatibilityParams.disableCreateObjectURL || false, value: false,
compatibility: apiCompatibilityParams.disableCreateObjectURL,
kind: OptionKind.API, kind: OptionKind.API,
}, },
disableFontFace: { disableFontFace: {
@ -241,22 +243,27 @@ class AppOptions {
} }
static get(name) { static get(name) {
let defaultOption = defaultOptions[name], userOption = userOptions[name]; const userOption = userOptions[name];
if (userOption !== undefined) { if (userOption !== undefined) {
return userOption; return userOption;
} }
return (defaultOption !== undefined ? defaultOption.value : undefined); const defaultOption = defaultOptions[name];
if (defaultOption !== undefined) {
return (defaultOption.compatibility || defaultOption.value);
}
return undefined;
} }
static getAll(kind = null) { static getAll(kind = null) {
let options = Object.create(null); const options = Object.create(null);
for (let name in defaultOptions) { for (const name in defaultOptions) {
let defaultOption = defaultOptions[name], userOption = userOptions[name]; const defaultOption = defaultOptions[name];
if (kind && defaultOption.kind !== kind) { if (kind && kind !== defaultOption.kind) {
continue; continue;
} }
options[name] = (userOption !== undefined ? const userOption = userOptions[name];
userOption : defaultOption.value); options[name] = (userOption !== undefined ? userOption :
(defaultOption.compatibility || defaultOption.value));
} }
return options; return options;
} }