Generate the default_preferences.json
file from AppOptions
Currently any editing of the preferences require updates in *three* separate files, which isn't a great developer experience to say the least. This has annoyed me sufficiently to write this patch, which moves the definition of all preferences into `AppOptions` and adds a new `gulp` task to generate the `default_preferences.json` file for the builds where it's needed.
This commit is contained in:
parent
81f5835cd7
commit
0f0650f426
@ -18,4 +18,4 @@
|
|||||||
var EXPORTED_SYMBOLS = ["PdfJsDefaultPreferences"];
|
var EXPORTED_SYMBOLS = ["PdfJsDefaultPreferences"];
|
||||||
|
|
||||||
var PdfJsDefaultPreferences =
|
var PdfJsDefaultPreferences =
|
||||||
Object.freeze(PDFJSDev.json("$ROOT/web/default_preferences.json"));
|
Object.freeze(PDFJSDev.json("$ROOT/build/default_preferences.json"));
|
||||||
|
95
gulpfile.js
95
gulpfile.js
@ -51,6 +51,7 @@ var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline/';
|
|||||||
var GENERIC_DIR = BUILD_DIR + 'generic/';
|
var GENERIC_DIR = BUILD_DIR + 'generic/';
|
||||||
var COMPONENTS_DIR = BUILD_DIR + 'components/';
|
var COMPONENTS_DIR = BUILD_DIR + 'components/';
|
||||||
var IMAGE_DECODERS_DIR = BUILD_DIR + 'image_decoders';
|
var IMAGE_DECODERS_DIR = BUILD_DIR + 'image_decoders';
|
||||||
|
var DEFAULT_PREFERENCES_DIR = BUILD_DIR + 'default_preferences/';
|
||||||
var MINIFIED_DIR = BUILD_DIR + 'minified/';
|
var MINIFIED_DIR = BUILD_DIR + 'minified/';
|
||||||
var JSDOC_BUILD_DIR = BUILD_DIR + 'jsdoc/';
|
var JSDOC_BUILD_DIR = BUILD_DIR + 'jsdoc/';
|
||||||
var GH_PAGES_DIR = BUILD_DIR + 'gh-pages/';
|
var GH_PAGES_DIR = BUILD_DIR + 'gh-pages/';
|
||||||
@ -484,6 +485,80 @@ gulp.task('buildnumber', function (done) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gulp.task('default_preferences-pre', function() {
|
||||||
|
console.log();
|
||||||
|
console.log('### Building `default_preferences.json`');
|
||||||
|
|
||||||
|
// Refer to the comment in the 'lib' task below.
|
||||||
|
function babelPluginReplaceNonWebPackRequire(babel) {
|
||||||
|
return {
|
||||||
|
visitor: {
|
||||||
|
Identifier(path, state) {
|
||||||
|
if (path.node.name === '__non_webpack_require__') {
|
||||||
|
path.replaceWith(babel.types.identifier('require'));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function preprocess(content) {
|
||||||
|
content = preprocessor2.preprocessPDFJSCode(ctx, content);
|
||||||
|
return babel.transform(content, {
|
||||||
|
sourceType: 'module',
|
||||||
|
presets: undefined, // SKIP_BABEL
|
||||||
|
plugins: [
|
||||||
|
'@babel/plugin-transform-modules-commonjs',
|
||||||
|
babelPluginReplaceNonWebPackRequire,
|
||||||
|
],
|
||||||
|
}).code;
|
||||||
|
}
|
||||||
|
var babel = require('@babel/core');
|
||||||
|
var ctx = {
|
||||||
|
rootPath: __dirname,
|
||||||
|
saveComments: false,
|
||||||
|
defines: builder.merge(DEFINES, {
|
||||||
|
GENERIC: true,
|
||||||
|
LIB: true,
|
||||||
|
BUNDLE_VERSION: 0, // Dummy version
|
||||||
|
BUNDLE_BUILD: 0, // Dummy build
|
||||||
|
}),
|
||||||
|
map: {
|
||||||
|
'pdfjs-lib': '../pdf',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var preprocessor2 = require('./external/builder/preprocessor2.js');
|
||||||
|
var buildLib = merge([
|
||||||
|
gulp.src([
|
||||||
|
'src/{display,shared}/*.js',
|
||||||
|
'!src/shared/{cffStandardStrings,fonts_utils}.js',
|
||||||
|
'src/pdf.js',
|
||||||
|
], { base: 'src/', }),
|
||||||
|
gulp.src([
|
||||||
|
'web/*.js',
|
||||||
|
'!web/{pdfjs,preferences,viewer}.js',
|
||||||
|
], { base: '.', }),
|
||||||
|
]).pipe(transform('utf8', preprocess))
|
||||||
|
.pipe(gulp.dest(DEFAULT_PREFERENCES_DIR + 'lib/'));
|
||||||
|
return merge([
|
||||||
|
buildLib,
|
||||||
|
gulp.src('external/{streams,url}/*.js', { base: '.', })
|
||||||
|
.pipe(gulp.dest(DEFAULT_PREFERENCES_DIR)),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('default_preferences', gulp.series('default_preferences-pre',
|
||||||
|
function(done) {
|
||||||
|
var AppOptionsLib =
|
||||||
|
require('./' + DEFAULT_PREFERENCES_DIR + 'lib/web/app_options.js');
|
||||||
|
var AppOptions = AppOptionsLib.AppOptions;
|
||||||
|
var OptionKind = AppOptionsLib.OptionKind;
|
||||||
|
|
||||||
|
createStringSource('default_preferences.json', JSON.stringify(
|
||||||
|
AppOptions.getAll(OptionKind.PREFERENCE), null, 2))
|
||||||
|
.pipe(gulp.dest(BUILD_DIR))
|
||||||
|
.on('end', done);
|
||||||
|
}));
|
||||||
|
|
||||||
gulp.task('locale', function () {
|
gulp.task('locale', function () {
|
||||||
var VIEWER_LOCALE_OUTPUT = 'web/locale/';
|
var VIEWER_LOCALE_OUTPUT = 'web/locale/';
|
||||||
var METADATA_OUTPUT = 'extensions/firefox/';
|
var METADATA_OUTPUT = 'extensions/firefox/';
|
||||||
@ -608,7 +683,8 @@ function preprocessHTML(source, defines) {
|
|||||||
|
|
||||||
// Builds the generic production viewer that should be compatible with most
|
// Builds the generic production viewer that should be compatible with most
|
||||||
// modern HTML5 browsers.
|
// modern HTML5 browsers.
|
||||||
gulp.task('generic', gulp.series('buildnumber', 'locale', function () {
|
gulp.task('generic', gulp.series('buildnumber', 'default_preferences', 'locale',
|
||||||
|
function() {
|
||||||
console.log();
|
console.log();
|
||||||
console.log('### Creating generic viewer');
|
console.log('### Creating generic viewer');
|
||||||
var defines = builder.merge(DEFINES, { GENERIC: true, });
|
var defines = builder.merge(DEFINES, { GENERIC: true, });
|
||||||
@ -671,7 +747,8 @@ gulp.task('image_decoders', gulp.series('buildnumber', function() {
|
|||||||
return createImageDecodersBundle(defines).pipe(gulp.dest(IMAGE_DECODERS_DIR));
|
return createImageDecodersBundle(defines).pipe(gulp.dest(IMAGE_DECODERS_DIR));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
gulp.task('minified-pre', gulp.series('buildnumber', 'locale', function () {
|
gulp.task('minified-pre', gulp.series('buildnumber', 'default_preferences',
|
||||||
|
'locale', function() {
|
||||||
console.log();
|
console.log();
|
||||||
console.log('### Creating minified viewer');
|
console.log('### Creating minified viewer');
|
||||||
var defines = builder.merge(DEFINES, { MINIFIED: true, GENERIC: true, });
|
var defines = builder.merge(DEFINES, { MINIFIED: true, GENERIC: true, });
|
||||||
@ -766,7 +843,8 @@ function preprocessDefaultPreferences(content) {
|
|||||||
content + '\n');
|
content + '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
gulp.task('mozcentral-pre', gulp.series('buildnumber', 'locale', function () {
|
gulp.task('mozcentral-pre', gulp.series('buildnumber', 'default_preferences',
|
||||||
|
'locale', function() {
|
||||||
console.log();
|
console.log();
|
||||||
console.log('### Building mozilla-central extension');
|
console.log('### Building mozilla-central extension');
|
||||||
var defines = builder.merge(DEFINES, { MOZCENTRAL: true, SKIP_BABEL: true, });
|
var defines = builder.merge(DEFINES, { MOZCENTRAL: true, SKIP_BABEL: true, });
|
||||||
@ -816,7 +894,8 @@ gulp.task('mozcentral-pre', gulp.series('buildnumber', 'locale', function () {
|
|||||||
|
|
||||||
gulp.task('mozcentral', gulp.series('mozcentral-pre'));
|
gulp.task('mozcentral', gulp.series('mozcentral-pre'));
|
||||||
|
|
||||||
gulp.task('chromium-pre', gulp.series('buildnumber', 'locale', function () {
|
gulp.task('chromium-pre', gulp.series('buildnumber', 'default_preferences',
|
||||||
|
'locale', function() {
|
||||||
console.log();
|
console.log();
|
||||||
console.log('### Building Chromium extension');
|
console.log('### Building Chromium extension');
|
||||||
var defines = builder.merge(DEFINES, { CHROME: true, });
|
var defines = builder.merge(DEFINES, { CHROME: true, });
|
||||||
@ -883,7 +962,7 @@ gulp.task('jsdoc', function (done) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('lib', gulp.series('buildnumber', function () {
|
gulp.task('lib', gulp.series('buildnumber', 'default_preferences', function() {
|
||||||
// When we create a bundle, webpack is run on the source and it will replace
|
// When we create a bundle, webpack is run on the source and it will replace
|
||||||
// require with __webpack_require__. When we want to use the real require,
|
// require with __webpack_require__. When we want to use the real require,
|
||||||
// __non_webpack_require__ has to be used.
|
// __non_webpack_require__ has to be used.
|
||||||
@ -1077,7 +1156,7 @@ gulp.task('unittestcli', gulp.series('testing-pre', 'lib', function(done) {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
gulp.task('lint', function (done) {
|
gulp.task('lint', gulp.series('default_preferences', function(done) {
|
||||||
console.log();
|
console.log();
|
||||||
console.log('### Linting JS files');
|
console.log('### Linting JS files');
|
||||||
|
|
||||||
@ -1096,7 +1175,7 @@ gulp.task('lint', function (done) {
|
|||||||
|
|
||||||
if (!checkChromePreferencesFile(
|
if (!checkChromePreferencesFile(
|
||||||
'extensions/chromium/preferences_schema.json',
|
'extensions/chromium/preferences_schema.json',
|
||||||
'web/default_preferences.json')) {
|
'build/default_preferences.json')) {
|
||||||
done(new Error('chromium/preferences_schema is not in sync.'));
|
done(new Error('chromium/preferences_schema is not in sync.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1104,7 +1183,7 @@ gulp.task('lint', function (done) {
|
|||||||
console.log('files checked, no errors found');
|
console.log('files checked, no errors found');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
gulp.task('server', function () {
|
gulp.task('server', function () {
|
||||||
console.log();
|
console.log();
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
parseQueryString, PresentationModeState, ProgressBar, RendererType,
|
parseQueryString, PresentationModeState, ProgressBar, RendererType,
|
||||||
ScrollMode, SpreadMode, TextLayerMode
|
ScrollMode, SpreadMode, TextLayerMode
|
||||||
} from './ui_utils';
|
} from './ui_utils';
|
||||||
|
import { AppOptions, OptionKind } from './app_options';
|
||||||
import {
|
import {
|
||||||
build, createObjectURL, getDocument, getFilenameFromUrl, GlobalWorkerOptions,
|
build, createObjectURL, getDocument, getFilenameFromUrl, GlobalWorkerOptions,
|
||||||
InvalidPDFException, LinkTarget, loadScript, MissingPDFException, OPS,
|
InvalidPDFException, LinkTarget, loadScript, MissingPDFException, OPS,
|
||||||
@ -30,7 +31,6 @@ import {
|
|||||||
import { CursorTool, PDFCursorTools } from './pdf_cursor_tools';
|
import { CursorTool, PDFCursorTools } from './pdf_cursor_tools';
|
||||||
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
||||||
import { PDFSidebar, SidebarView } from './pdf_sidebar';
|
import { PDFSidebar, SidebarView } from './pdf_sidebar';
|
||||||
import { AppOptions } from './app_options';
|
|
||||||
import { OverlayManager } from './overlay_manager';
|
import { OverlayManager } from './overlay_manager';
|
||||||
import { PasswordPrompt } from './password_prompt';
|
import { PasswordPrompt } from './password_prompt';
|
||||||
import { PDFAttachmentViewer } from './pdf_attachment_viewer';
|
import { PDFAttachmentViewer } from './pdf_attachment_viewer';
|
||||||
@ -611,7 +611,7 @@ let PDFViewerApplication = {
|
|||||||
await this.close();
|
await this.close();
|
||||||
}
|
}
|
||||||
// Set the necessary global worker parameters, using the available options.
|
// 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) {
|
for (let key in workerParameters) {
|
||||||
GlobalWorkerOptions[key] = workerParameters[key];
|
GlobalWorkerOptions[key] = workerParameters[key];
|
||||||
}
|
}
|
||||||
@ -633,7 +633,7 @@ let PDFViewerApplication = {
|
|||||||
parameters.docBaseUrl = this.baseUrl;
|
parameters.docBaseUrl = this.baseUrl;
|
||||||
}
|
}
|
||||||
// Set the necessary API parameters, using the available options.
|
// 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) {
|
for (let key in apiParameters) {
|
||||||
parameters[key] = apiParameters[key];
|
parameters[key] = apiParameters[key];
|
||||||
}
|
}
|
||||||
|
@ -17,21 +17,21 @@ import { apiCompatibilityParams } from 'pdfjs-lib';
|
|||||||
import { viewerCompatibilityParams } from './viewer_compatibility';
|
import { viewerCompatibilityParams } from './viewer_compatibility';
|
||||||
|
|
||||||
const OptionKind = {
|
const OptionKind = {
|
||||||
VIEWER: 'viewer',
|
VIEWER: 0x02,
|
||||||
API: 'api',
|
API: 0x04,
|
||||||
WORKER: 'worker',
|
WORKER: 0x08,
|
||||||
|
PREFERENCE: 0x80,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PLEASE NOTE: To avoid introducing unnecessary dependencies, we specify the
|
* PLEASE NOTE: To avoid introducing unnecessary dependencies, we specify the
|
||||||
* values below *explicitly* rather than relying on imported types;
|
* values below *explicitly* rather than relying on imported types.
|
||||||
* compare with the format of `default_preferences.json`.
|
|
||||||
*/
|
*/
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
cursorToolOnLoad: {
|
cursorToolOnLoad: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: 0,
|
value: 0,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
defaultUrl: {
|
defaultUrl: {
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
@ -41,7 +41,7 @@ const defaultOptions = {
|
|||||||
defaultZoomValue: {
|
defaultZoomValue: {
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
value: '',
|
value: '',
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
disableHistory: {
|
disableHistory: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
@ -51,7 +51,7 @@ const defaultOptions = {
|
|||||||
disablePageLabels: {
|
disablePageLabels: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* The `disablePreferences` is, conditionally, defined below.
|
* The `disablePreferences` is, conditionally, defined below.
|
||||||
@ -59,17 +59,17 @@ const defaultOptions = {
|
|||||||
enablePrintAutoRotate: {
|
enablePrintAutoRotate: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
enableWebGL: {
|
enableWebGL: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
eventBusDispatchToDOM: {
|
eventBusDispatchToDOM: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
externalLinkRel: {
|
externalLinkRel: {
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
@ -79,12 +79,12 @@ const defaultOptions = {
|
|||||||
externalLinkTarget: {
|
externalLinkTarget: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: 0,
|
value: 0,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
historyUpdateUrl: {
|
historyUpdateUrl: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
imageResourcesPath: {
|
imageResourcesPath: {
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
@ -103,47 +103,47 @@ const defaultOptions = {
|
|||||||
pdfBugEnabled: {
|
pdfBugEnabled: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
renderer: {
|
renderer: {
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
value: 'canvas',
|
value: 'canvas',
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
renderInteractiveForms: {
|
renderInteractiveForms: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
sidebarViewOnLoad: {
|
sidebarViewOnLoad: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: -1,
|
value: -1,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
scrollModeOnLoad: {
|
scrollModeOnLoad: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: -1,
|
value: -1,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
spreadModeOnLoad: {
|
spreadModeOnLoad: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: -1,
|
value: -1,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
textLayerMode: {
|
textLayerMode: {
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
value: 1,
|
value: 1,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
useOnlyCssZoom: {
|
useOnlyCssZoom: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
viewOnLoad: {
|
viewOnLoad: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: 0,
|
value: 0,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
|
|
||||||
cMapPacked: {
|
cMapPacked: {
|
||||||
@ -160,7 +160,7 @@ const defaultOptions = {
|
|||||||
disableAutoFetch: {
|
disableAutoFetch: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.API,
|
kind: OptionKind.API + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
disableCreateObjectURL: {
|
disableCreateObjectURL: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
@ -171,17 +171,17 @@ const defaultOptions = {
|
|||||||
disableFontFace: {
|
disableFontFace: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.API,
|
kind: OptionKind.API + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
disableRange: {
|
disableRange: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.API,
|
kind: OptionKind.API + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
disableStream: {
|
disableStream: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.API,
|
kind: OptionKind.API + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
isEvalSupported: {
|
isEvalSupported: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
@ -258,8 +258,14 @@ class AppOptions {
|
|||||||
const options = Object.create(null);
|
const options = Object.create(null);
|
||||||
for (const name in defaultOptions) {
|
for (const name in defaultOptions) {
|
||||||
const defaultOption = defaultOptions[name];
|
const defaultOption = defaultOptions[name];
|
||||||
if (kind && kind !== defaultOption.kind) {
|
if (kind) {
|
||||||
continue;
|
if ((kind & defaultOption.kind) === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((kind & OptionKind.PREFERENCE) !== 0) {
|
||||||
|
options[name] = defaultOption.value;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const userOption = userOptions[name];
|
const userOption = userOptions[name];
|
||||||
options[name] = (userOption !== undefined ? userOption :
|
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 (!defaultPreferences) {
|
||||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
|
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
|
||||||
defaultPreferences = Promise.resolve(
|
defaultPreferences = Promise.resolve(
|
||||||
PDFJSDev.json('$ROOT/web/default_preferences.json'));
|
PDFJSDev.json('$ROOT/build/default_preferences.json'));
|
||||||
} else {
|
} else {
|
||||||
defaultPreferences = new Promise(function (resolve) {
|
defaultPreferences = new Promise(function(resolve, reject) {
|
||||||
let xhr = new XMLHttpRequest();
|
if (typeof SystemJS === 'object') {
|
||||||
xhr.open('GET', 'default_preferences.json');
|
SystemJS.import('./app_options').then(resolve, reject);
|
||||||
xhr.onload = xhr.onerror = function loaded() {
|
} else if (typeof require === 'function') {
|
||||||
try {
|
try {
|
||||||
resolve(JSON.parse(xhr.responseText));
|
resolve(require('./app_options.js'));
|
||||||
} catch (e) {
|
} catch (ex) {
|
||||||
console.error(`Unable to load default preferences: ${e}`);
|
reject(ex);
|
||||||
resolve({});
|
|
||||||
}
|
}
|
||||||
};
|
} else {
|
||||||
xhr.send();
|
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…
Reference in New Issue
Block a user