mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Merge pull request #10548 from Snuffleupagus/generate-default_preferences
Generate the `default_preferences.json` file from `AppOptions`
This commit is contained in:
commit
43491c19ee
6 changed files with 141 additions and 74 deletions
|
@ -21,6 +21,7 @@ import {
|
|||
parseQueryString, PresentationModeState, ProgressBar, RendererType,
|
||||
ScrollMode, SpreadMode, TextLayerMode
|
||||
} from './ui_utils';
|
||||
import { AppOptions, OptionKind } from './app_options';
|
||||
import {
|
||||
build, createObjectURL, getDocument, getFilenameFromUrl, GlobalWorkerOptions,
|
||||
InvalidPDFException, LinkTarget, loadScript, MissingPDFException, OPS,
|
||||
|
@ -30,7 +31,6 @@ import {
|
|||
import { CursorTool, PDFCursorTools } from './pdf_cursor_tools';
|
||||
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
||||
import { PDFSidebar, SidebarView } from './pdf_sidebar';
|
||||
import { AppOptions } from './app_options';
|
||||
import { OverlayManager } from './overlay_manager';
|
||||
import { PasswordPrompt } from './password_prompt';
|
||||
import { PDFAttachmentViewer } from './pdf_attachment_viewer';
|
||||
|
@ -611,7 +611,7 @@ let PDFViewerApplication = {
|
|||
await this.close();
|
||||
}
|
||||
// Set the necessary global worker parameters, using the available options.
|
||||
const workerParameters = AppOptions.getAll('worker');
|
||||
const workerParameters = AppOptions.getAll(OptionKind.WORKER);
|
||||
for (let key in workerParameters) {
|
||||
GlobalWorkerOptions[key] = workerParameters[key];
|
||||
}
|
||||
|
@ -633,7 +633,7 @@ let PDFViewerApplication = {
|
|||
parameters.docBaseUrl = this.baseUrl;
|
||||
}
|
||||
// Set the necessary API parameters, using the available options.
|
||||
const apiParameters = AppOptions.getAll('api');
|
||||
const apiParameters = AppOptions.getAll(OptionKind.API);
|
||||
for (let key in apiParameters) {
|
||||
parameters[key] = apiParameters[key];
|
||||
}
|
||||
|
|
|
@ -17,21 +17,21 @@ import { apiCompatibilityParams } from 'pdfjs-lib';
|
|||
import { viewerCompatibilityParams } from './viewer_compatibility';
|
||||
|
||||
const OptionKind = {
|
||||
VIEWER: 'viewer',
|
||||
API: 'api',
|
||||
WORKER: 'worker',
|
||||
VIEWER: 0x02,
|
||||
API: 0x04,
|
||||
WORKER: 0x08,
|
||||
PREFERENCE: 0x80,
|
||||
};
|
||||
|
||||
/**
|
||||
* PLEASE NOTE: To avoid introducing unnecessary dependencies, we specify the
|
||||
* values below *explicitly* rather than relying on imported types;
|
||||
* compare with the format of `default_preferences.json`.
|
||||
* values below *explicitly* rather than relying on imported types.
|
||||
*/
|
||||
const defaultOptions = {
|
||||
cursorToolOnLoad: {
|
||||
/** @type {number} */
|
||||
value: 0,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
defaultUrl: {
|
||||
/** @type {string} */
|
||||
|
@ -41,7 +41,7 @@ const defaultOptions = {
|
|||
defaultZoomValue: {
|
||||
/** @type {string} */
|
||||
value: '',
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
disableHistory: {
|
||||
/** @type {boolean} */
|
||||
|
@ -51,7 +51,7 @@ const defaultOptions = {
|
|||
disablePageLabels: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
/**
|
||||
* The `disablePreferences` is, conditionally, defined below.
|
||||
|
@ -59,17 +59,17 @@ const defaultOptions = {
|
|||
enablePrintAutoRotate: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
enableWebGL: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
eventBusDispatchToDOM: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
externalLinkRel: {
|
||||
/** @type {string} */
|
||||
|
@ -79,12 +79,12 @@ const defaultOptions = {
|
|||
externalLinkTarget: {
|
||||
/** @type {number} */
|
||||
value: 0,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
historyUpdateUrl: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
imageResourcesPath: {
|
||||
/** @type {string} */
|
||||
|
@ -103,47 +103,47 @@ const defaultOptions = {
|
|||
pdfBugEnabled: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
renderer: {
|
||||
/** @type {string} */
|
||||
value: 'canvas',
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
renderInteractiveForms: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
sidebarViewOnLoad: {
|
||||
/** @type {number} */
|
||||
value: -1,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
scrollModeOnLoad: {
|
||||
/** @type {number} */
|
||||
value: -1,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
spreadModeOnLoad: {
|
||||
/** @type {number} */
|
||||
value: -1,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
textLayerMode: {
|
||||
/** @type {number} */
|
||||
value: 1,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
useOnlyCssZoom: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
viewOnLoad: {
|
||||
/** @type {boolean} */
|
||||
value: 0,
|
||||
kind: OptionKind.VIEWER,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
|
||||
cMapPacked: {
|
||||
|
@ -160,7 +160,7 @@ const defaultOptions = {
|
|||
disableAutoFetch: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.API,
|
||||
kind: OptionKind.API + OptionKind.PREFERENCE,
|
||||
},
|
||||
disableCreateObjectURL: {
|
||||
/** @type {boolean} */
|
||||
|
@ -171,17 +171,17 @@ const defaultOptions = {
|
|||
disableFontFace: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.API,
|
||||
kind: OptionKind.API + OptionKind.PREFERENCE,
|
||||
},
|
||||
disableRange: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.API,
|
||||
kind: OptionKind.API + OptionKind.PREFERENCE,
|
||||
},
|
||||
disableStream: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.API,
|
||||
kind: OptionKind.API + OptionKind.PREFERENCE,
|
||||
},
|
||||
isEvalSupported: {
|
||||
/** @type {boolean} */
|
||||
|
@ -258,8 +258,14 @@ class AppOptions {
|
|||
const options = Object.create(null);
|
||||
for (const name in defaultOptions) {
|
||||
const defaultOption = defaultOptions[name];
|
||||
if (kind && kind !== defaultOption.kind) {
|
||||
continue;
|
||||
if (kind) {
|
||||
if ((kind & defaultOption.kind) === 0) {
|
||||
continue;
|
||||
}
|
||||
if ((kind & OptionKind.PREFERENCE) !== 0) {
|
||||
options[name] = defaultOption.value;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const userOption = userOptions[name];
|
||||
options[name] = (userOption !== undefined ? userOption :
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"viewOnLoad": 0,
|
||||
"defaultZoomValue": "",
|
||||
"sidebarViewOnLoad": -1,
|
||||
"cursorToolOnLoad": 0,
|
||||
"enableWebGL": false,
|
||||
"eventBusDispatchToDOM": false,
|
||||
"pdfBugEnabled": false,
|
||||
"disableRange": false,
|
||||
"disableStream": false,
|
||||
"disableAutoFetch": false,
|
||||
"disableFontFace": false,
|
||||
"textLayerMode": 1,
|
||||
"useOnlyCssZoom": false,
|
||||
"externalLinkTarget": 0,
|
||||
"renderer": "canvas",
|
||||
"renderInteractiveForms": false,
|
||||
"enablePrintAutoRotate": false,
|
||||
"disablePageLabels": false,
|
||||
"historyUpdateUrl": false,
|
||||
"scrollModeOnLoad": -1,
|
||||
"spreadModeOnLoad": -1
|
||||
}
|
|
@ -18,20 +18,25 @@ function getDefaultPreferences() {
|
|||
if (!defaultPreferences) {
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
|
||||
defaultPreferences = Promise.resolve(
|
||||
PDFJSDev.json('$ROOT/web/default_preferences.json'));
|
||||
PDFJSDev.json('$ROOT/build/default_preferences.json'));
|
||||
} else {
|
||||
defaultPreferences = new Promise(function (resolve) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'default_preferences.json');
|
||||
xhr.onload = xhr.onerror = function loaded() {
|
||||
defaultPreferences = new Promise(function(resolve, reject) {
|
||||
if (typeof SystemJS === 'object') {
|
||||
SystemJS.import('./app_options').then(resolve, reject);
|
||||
} else if (typeof require === 'function') {
|
||||
try {
|
||||
resolve(JSON.parse(xhr.responseText));
|
||||
} catch (e) {
|
||||
console.error(`Unable to load default preferences: ${e}`);
|
||||
resolve({});
|
||||
resolve(require('./app_options.js'));
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
} else {
|
||||
reject(new Error(
|
||||
'SystemJS or CommonJS must be used to load AppOptions.'));
|
||||
}
|
||||
}).then(function({ AppOptions, OptionKind, }) {
|
||||
return AppOptions.getAll(OptionKind.PREFERENCE);
|
||||
}, function(reason) {
|
||||
console.error(reason);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue