2018-02-17 21:22:26 +09:00
|
|
|
/* Copyright 2018 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-07-27 19:23:33 +09:00
|
|
|
const compatibilityParams = Object.create(null);
|
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2022-02-14 20:01:30 +09:00
|
|
|
if (
|
|
|
|
typeof PDFJSDev !== "undefined" &&
|
|
|
|
PDFJSDev.test("LIB") &&
|
|
|
|
typeof navigator === "undefined"
|
|
|
|
) {
|
|
|
|
globalThis.navigator = Object.create(null);
|
|
|
|
}
|
|
|
|
const userAgent = navigator.userAgent || "";
|
|
|
|
const platform = navigator.platform || "";
|
|
|
|
const maxTouchPoints = navigator.maxTouchPoints || 1;
|
2021-07-27 19:23:33 +09:00
|
|
|
|
|
|
|
const isAndroid = /Android/.test(userAgent);
|
|
|
|
const isIOS =
|
|
|
|
/\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) ||
|
|
|
|
(platform === "MacIntel" && maxTouchPoints > 1);
|
|
|
|
|
|
|
|
// Limit canvas size to 5 mega-pixels on mobile.
|
|
|
|
// Support: Android, iOS
|
|
|
|
(function checkCanvasSizeLimitation() {
|
|
|
|
if (isIOS || isAndroid) {
|
|
|
|
compatibilityParams.maxCanvasPixels = 5242880;
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|
2018-02-17 23:08:28 +09:00
|
|
|
|
2018-02-17 21:22:26 +09:00
|
|
|
const OptionKind = {
|
2023-10-31 19:39:04 +09:00
|
|
|
BROWSER: 0x01,
|
2019-02-13 22:00:23 +09:00
|
|
|
VIEWER: 0x02,
|
|
|
|
API: 0x04,
|
|
|
|
WORKER: 0x08,
|
|
|
|
PREFERENCE: 0x80,
|
2018-02-17 21:22:26 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-09-08 19:33:59 +09:00
|
|
|
* NOTE: These options are used to generate the `default_preferences.json` file,
|
|
|
|
* see `OptionKind.PREFERENCE`, hence the values below must use only
|
|
|
|
* primitive types and cannot rely on any imported types.
|
2018-02-17 21:22:26 +09:00
|
|
|
*/
|
|
|
|
const defaultOptions = {
|
2023-10-31 19:39:04 +09:00
|
|
|
canvasMaxAreaInBytes: {
|
|
|
|
/** @type {number} */
|
|
|
|
value: -1,
|
2023-11-03 17:56:37 +09:00
|
|
|
kind: OptionKind.BROWSER + OptionKind.API,
|
2023-10-31 19:39:04 +09:00
|
|
|
},
|
|
|
|
isInAutomation: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
|
|
|
kind: OptionKind.BROWSER,
|
|
|
|
},
|
2024-02-02 00:08:40 +09:00
|
|
|
supportsCaretBrowsingMode: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
|
|
|
kind: OptionKind.BROWSER,
|
|
|
|
},
|
2023-10-31 19:39:04 +09:00
|
|
|
supportsDocumentFonts: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: true,
|
|
|
|
kind: OptionKind.BROWSER,
|
|
|
|
},
|
|
|
|
supportsIntegratedFind: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
|
|
|
kind: OptionKind.BROWSER,
|
|
|
|
},
|
|
|
|
supportsMouseWheelZoomCtrlKey: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: true,
|
|
|
|
kind: OptionKind.BROWSER,
|
|
|
|
},
|
|
|
|
supportsMouseWheelZoomMetaKey: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: true,
|
|
|
|
kind: OptionKind.BROWSER,
|
|
|
|
},
|
|
|
|
supportsPinchToZoom: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: true,
|
|
|
|
kind: OptionKind.BROWSER,
|
|
|
|
},
|
|
|
|
|
2022-06-29 18:13:03 +09:00
|
|
|
annotationEditorMode: {
|
2022-08-21 20:48:48 +09:00
|
|
|
/** @type {number} */
|
|
|
|
value: 0,
|
2022-06-01 17:38:08 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2022-06-05 17:00:08 +09:00
|
|
|
},
|
|
|
|
annotationMode: {
|
|
|
|
/** @type {number} */
|
|
|
|
value: 2,
|
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
*This is a follow-up to PRs 13867 and 13899.*
This patch is tagged `api-minor` for the following reasons:
- It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.
- For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.
- It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.
---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-08 21:36:28 +09:00
|
|
|
},
|
2018-03-20 07:24:56 +09:00
|
|
|
cursorToolOnLoad: {
|
|
|
|
/** @type {number} */
|
|
|
|
value: 0,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2018-03-20 07:24:56 +09:00
|
|
|
},
|
2024-01-29 01:12:24 +09:00
|
|
|
debuggerSrc: {
|
|
|
|
/** @type {string} */
|
|
|
|
value: "./debugger.mjs",
|
|
|
|
kind: OptionKind.VIEWER,
|
|
|
|
},
|
2022-12-12 22:24:27 +09:00
|
|
|
defaultZoomDelay: {
|
|
|
|
/** @type {number} */
|
2023-01-02 22:00:16 +09:00
|
|
|
value: 400,
|
2022-12-12 22:24:27 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
|
|
},
|
2018-02-17 23:08:28 +09:00
|
|
|
defaultZoomValue: {
|
|
|
|
/** @type {string} */
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
value: "",
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2018-02-17 23:08:28 +09:00
|
|
|
},
|
|
|
|
disableHistory: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
|
|
|
kind: OptionKind.VIEWER,
|
|
|
|
},
|
|
|
|
disablePageLabels: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2023-04-14 02:15:08 +09:00
|
|
|
},
|
2023-11-23 03:02:42 +09:00
|
|
|
enableHighlightEditor: {
|
|
|
|
// We'll probably want to make some experiments before enabling this
|
|
|
|
// in Firefox release, but it has to be temporary.
|
|
|
|
// TODO: remove it when unnecessary.
|
|
|
|
/** @type {boolean} */
|
2023-12-06 06:01:49 +09:00
|
|
|
value: typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING"),
|
2023-11-23 03:02:42 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2024-02-20 17:49:20 +09:00
|
|
|
},
|
|
|
|
enableML: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2023-11-23 03:02:42 +09:00
|
|
|
},
|
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
*Please note:* Most of the necessary API work was done in PR 10033, and the only remaining thing to do here was to implement it in the viewer.
The new preference should thus allow e.g. enterprise users to disable copying in the viewer, for PDF documents whose permissions specify that.
In order to simplify things the "copy"-permission was implemented using CSS, as suggested in https://bugzilla.mozilla.org/show_bug.cgi?id=792816#c55, which should hopefully suffice.[1]
The advantage of this approach, as opposed to e.g. disabling the `textLayer` completely, is first of all that it ensures that searching still works correctly even in copy-protected documents. Secondly this also greatly simplifies the overall implementation, since it doesn't require a lot of code for something that's disabled by default.
---
[1] As the discussion in the bug shows, this kind of copy-protection is not very strong and is also generally easy to remove/circumvent in various ways. Hence a simple solution, targeting "regular"-users rather than "power"-users is hopefully deemed acceptable here.
2020-04-08 23:53:31 +09:00
|
|
|
enablePermissions: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
|
|
},
|
2018-02-17 23:08:28 +09:00
|
|
|
enablePrintAutoRotate: {
|
|
|
|
/** @type {boolean} */
|
2021-03-19 20:27:23 +09:00
|
|
|
value: true,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2018-02-17 23:08:28 +09:00
|
|
|
},
|
2020-10-01 20:57:23 +09:00
|
|
|
enableScripting: {
|
|
|
|
/** @type {boolean} */
|
2021-09-12 08:04:11 +09:00
|
|
|
value: typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME"),
|
2020-10-01 20:57:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
|
|
},
|
2024-02-10 02:19:19 +09:00
|
|
|
enableStampEditor: {
|
|
|
|
// We'll probably want to make some experiments before enabling this
|
|
|
|
// in Firefox release, but it has to be temporary.
|
|
|
|
// TODO: remove it when unnecessary.
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: true,
|
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
|
|
},
|
2018-02-17 23:08:28 +09:00
|
|
|
externalLinkRel: {
|
|
|
|
/** @type {string} */
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
value: "noopener noreferrer nofollow",
|
2018-02-17 23:08:28 +09:00
|
|
|
kind: OptionKind.VIEWER,
|
|
|
|
},
|
|
|
|
externalLinkTarget: {
|
|
|
|
/** @type {number} */
|
|
|
|
value: 0,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2023-12-01 00:21:13 +09:00
|
|
|
},
|
|
|
|
highlightEditorColors: {
|
|
|
|
/** @type {string} */
|
|
|
|
value: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F",
|
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2018-02-17 23:08:28 +09:00
|
|
|
},
|
Add support for updating the document hash, off by default, when the browser history is updated (issue 5753)
This is *really* the best that we can do here, since other proposed solutions would interfere with (and break) the painstakingly implemented browsing history that's present in the default viewer.
I'm still not convinced that this is a good idea in general, but this patch implements it in a way where it is possible to toggle[1] for users that wish to have this feature. In particular, there's a couple of reasons why I'm not finding this feature necessary/great:
- It's already possible to easily obtain the current hash, by simply clicking on the `viewBookmark` button at any time.
- Hash changes requires a bit of special handling[2], i.e. extra code, to prevent issues when the browser history is traversed (see `PDFHistory._popState`). Currently this is only necessary when the user has manually changed the hash, with this patch it will always be the case (assuming the feature is active).
- It's not always possible to change the URL when updating the browser history. For example: In the Firefox built-in viewer, the URL cannot be modified for local files (i.e. those using the `file://` protocol).
This leads to inconsistent behaviour, and may in some cases even result in errors being thrown and the history thus not updating, if the browser prevents changes to the URL during `pushState`/`replaceState` calls.
---
[1] Using the `historyUpdateUrl` viewer preference.
[2] This depends, to a great extent, on browsers always firing `popstate` events *before* `hashchange` events, which may or may not actually be guaranteed.
2019-01-03 23:45:33 +09:00
|
|
|
historyUpdateUrl: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
Add support for updating the document hash, off by default, when the browser history is updated (issue 5753)
This is *really* the best that we can do here, since other proposed solutions would interfere with (and break) the painstakingly implemented browsing history that's present in the default viewer.
I'm still not convinced that this is a good idea in general, but this patch implements it in a way where it is possible to toggle[1] for users that wish to have this feature. In particular, there's a couple of reasons why I'm not finding this feature necessary/great:
- It's already possible to easily obtain the current hash, by simply clicking on the `viewBookmark` button at any time.
- Hash changes requires a bit of special handling[2], i.e. extra code, to prevent issues when the browser history is traversed (see `PDFHistory._popState`). Currently this is only necessary when the user has manually changed the hash, with this patch it will always be the case (assuming the feature is active).
- It's not always possible to change the URL when updating the browser history. For example: In the Firefox built-in viewer, the URL cannot be modified for local files (i.e. those using the `file://` protocol).
This leads to inconsistent behaviour, and may in some cases even result in errors being thrown and the history thus not updating, if the browser prevents changes to the URL during `pushState`/`replaceState` calls.
---
[1] Using the `historyUpdateUrl` viewer preference.
[2] This depends, to a great extent, on browsers always firing `popstate` events *before* `hashchange` events, which may or may not actually be guaranteed.
2019-01-03 23:45:33 +09:00
|
|
|
},
|
2020-02-17 22:04:55 +09:00
|
|
|
ignoreDestinationZoom: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
|
|
},
|
2018-02-17 23:08:28 +09:00
|
|
|
imageResourcesPath: {
|
|
|
|
/** @type {string} */
|
2023-03-29 21:30:54 +09:00
|
|
|
value:
|
|
|
|
typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")
|
|
|
|
? "resource://pdf.js/web/images/"
|
|
|
|
: "./images/",
|
2018-02-17 23:08:28 +09:00
|
|
|
kind: OptionKind.VIEWER,
|
|
|
|
},
|
|
|
|
maxCanvasPixels: {
|
|
|
|
/** @type {number} */
|
2019-02-02 18:09:05 +09:00
|
|
|
value: 16777216,
|
2018-02-17 23:08:28 +09:00
|
|
|
kind: OptionKind.VIEWER,
|
|
|
|
},
|
2022-07-06 20:50:45 +09:00
|
|
|
forcePageColors: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
|
|
},
|
2022-05-08 17:51:59 +09:00
|
|
|
pageColorsBackground: {
|
2022-05-04 22:37:13 +09:00
|
|
|
/** @type {string} */
|
|
|
|
value: "Canvas",
|
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
|
|
},
|
2022-05-08 17:51:59 +09:00
|
|
|
pageColorsForeground: {
|
2022-05-04 22:37:13 +09:00
|
|
|
/** @type {string} */
|
|
|
|
value: "CanvasText",
|
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
|
|
},
|
2018-02-17 23:08:28 +09:00
|
|
|
pdfBugEnabled: {
|
|
|
|
/** @type {boolean} */
|
2024-01-05 18:10:01 +09:00
|
|
|
value: typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING"),
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2018-02-17 23:08:28 +09:00
|
|
|
},
|
2020-04-20 20:09:33 +09:00
|
|
|
printResolution: {
|
|
|
|
/** @type {number} */
|
|
|
|
value: 150,
|
|
|
|
kind: OptionKind.VIEWER,
|
|
|
|
},
|
2018-02-17 23:08:28 +09:00
|
|
|
sidebarViewOnLoad: {
|
|
|
|
/** @type {number} */
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
value: -1,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2018-06-29 20:07:37 +09:00
|
|
|
},
|
|
|
|
scrollModeOnLoad: {
|
|
|
|
/** @type {number} */
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
value: -1,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2018-06-29 20:07:37 +09:00
|
|
|
},
|
|
|
|
spreadModeOnLoad: {
|
|
|
|
/** @type {number} */
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
value: -1,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2018-02-17 23:08:28 +09:00
|
|
|
},
|
|
|
|
textLayerMode: {
|
|
|
|
/** @type {number} */
|
|
|
|
value: 1,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
2018-02-17 23:08:28 +09:00
|
|
|
},
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
viewOnLoad: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: 0,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
},
|
2018-02-17 23:33:57 +09:00
|
|
|
|
2018-02-18 00:57:24 +09:00
|
|
|
cMapPacked: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: true,
|
|
|
|
kind: OptionKind.API,
|
|
|
|
},
|
|
|
|
cMapUrl: {
|
|
|
|
/** @type {string} */
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
value:
|
2023-04-28 01:01:07 +09:00
|
|
|
// eslint-disable-next-line no-nested-ternary
|
|
|
|
typeof PDFJSDev === "undefined"
|
|
|
|
? "../external/bcmaps/"
|
|
|
|
: PDFJSDev.test("MOZCENTRAL")
|
2023-11-26 01:28:14 +09:00
|
|
|
? "resource://pdf.js/web/cmaps/"
|
|
|
|
: "../web/cmaps/",
|
2018-02-18 00:57:24 +09:00
|
|
|
kind: OptionKind.API,
|
|
|
|
},
|
2018-02-18 06:08:45 +09:00
|
|
|
disableAutoFetch: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.API + OptionKind.PREFERENCE,
|
2018-02-18 06:51:03 +09:00
|
|
|
},
|
2018-02-18 05:57:20 +09:00
|
|
|
disableFontFace: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.API + OptionKind.PREFERENCE,
|
2018-02-18 05:57:20 +09:00
|
|
|
},
|
2018-02-18 06:22:10 +09:00
|
|
|
disableRange: {
|
|
|
|
/** @type {boolean} */
|
2018-06-21 15:12:30 +09:00
|
|
|
value: false,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.API + OptionKind.PREFERENCE,
|
2018-02-18 06:22:10 +09:00
|
|
|
},
|
2018-02-18 06:28:08 +09:00
|
|
|
disableStream: {
|
|
|
|
/** @type {boolean} */
|
2018-06-21 15:12:30 +09:00
|
|
|
value: false,
|
2019-02-13 22:00:23 +09:00
|
|
|
kind: OptionKind.API + OptionKind.PREFERENCE,
|
2018-02-18 06:28:08 +09:00
|
|
|
},
|
2019-07-20 20:39:34 +09:00
|
|
|
docBaseUrl: {
|
|
|
|
/** @type {string} */
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
value: "",
|
2019-07-20 20:39:34 +09:00
|
|
|
kind: OptionKind.API,
|
|
|
|
},
|
2021-03-19 18:11:40 +09:00
|
|
|
enableXfa: {
|
|
|
|
/** @type {boolean} */
|
2021-09-08 19:33:59 +09:00
|
|
|
value: true,
|
2021-05-07 21:37:47 +09:00
|
|
|
kind: OptionKind.API + OptionKind.PREFERENCE,
|
2021-03-19 18:11:40 +09:00
|
|
|
},
|
[api-minor] Change `Font.exportData` to, by default, stop exporting properties which are completely unused on the main-thread and/or in the API (PR 11773 follow-up)
For years now, the `Font.exportData` method has (because of its previous implementation) been exporting many properties despite them being completely unused on the main-thread and/or in the API.
This is unfortunate, since among those properties there's a number of potentially very large data-structures, containing e.g. Arrays and Objects, which thus have to be first structured cloned and then stored on the main-thread.
With the changes in this patch, we'll thus by default save memory for *every* `Font` instance created (there can be a lot in longer documents). The memory savings obviously depends a lot on the actual font data, but some approximate figures are: For non-embedded fonts it can save a couple of kilobytes, for simple embedded fonts a handful of kilobytes, and for composite fonts the size of this auxiliary can even be larger than the actual font program itself.
All-in-all, there's no good reason to keep exporting these properties by default when they're unused. However, since we cannot be sure that every property is unused in custom implementations of the PDF.js library, this patch adds a new `getDocument` option (named `fontExtraProperties`) that still allows access to the following properties:
- "cMap": An internal data structure, only used with composite fonts and never really intended to be exposed on the main-thread and/or in the API.
Note also that the `CMap`/`IdentityCMap` classes are a lot more complex than simple Objects, but only their "internal" properties survive the structured cloning used to send data to the main-thread. Given that CMaps can often be *very* large, not exporting them can also save a fair bit of memory.
- "defaultEncoding": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "differences": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful.
- "isSymbolicFont": An internal property, used during font parsing and building of the glyph mapping on the worker-thread.
- "seacMap": An internal map, only potentially used with *some* Type1/CFF fonts and never intended to be exposed in the API. The existing `Font.{charToGlyph, charToGlyphs}` functionality already takes this data into account when handling text.
- "toFontChar": The glyph map, necessary for mapping characters to glyphs in the font, which is built upon the various encoding information contained in the font dictionary and/or font program. This is not directly used on the main-thread and/or in the API.
- "toUnicode": The unicode map, necessary for text-extraction to work correctly, which is built upon the ToUnicode/CMap information contained in the font dictionary, but not directly used on the main-thread and/or in the API.
- "vmetrics": An array of width data used with fonts which are composite *and* vertical, but not directly used on the main-thread and/or in the API.
- "widths": An array of width data used with most fonts, but not directly used on the main-thread and/or in the API.
2020-04-03 18:51:46 +09:00
|
|
|
fontExtraProperties: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
|
|
|
kind: OptionKind.API,
|
|
|
|
},
|
2018-02-18 05:49:14 +09:00
|
|
|
isEvalSupported: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: true,
|
|
|
|
kind: OptionKind.API,
|
|
|
|
},
|
2022-10-07 05:05:32 +09:00
|
|
|
isOffscreenCanvasSupported: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: true,
|
|
|
|
kind: OptionKind.API,
|
|
|
|
},
|
2018-02-18 00:13:33 +09:00
|
|
|
maxImageSize: {
|
|
|
|
/** @type {number} */
|
|
|
|
value: -1,
|
|
|
|
kind: OptionKind.API,
|
|
|
|
},
|
2018-02-18 07:13:49 +09:00
|
|
|
pdfBug: {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
|
|
|
kind: OptionKind.API,
|
|
|
|
},
|
2020-12-11 10:32:18 +09:00
|
|
|
standardFontDataUrl: {
|
|
|
|
/** @type {string} */
|
|
|
|
value:
|
2023-04-28 01:01:07 +09:00
|
|
|
// eslint-disable-next-line no-nested-ternary
|
2023-03-18 20:09:25 +09:00
|
|
|
typeof PDFJSDev === "undefined"
|
2020-12-11 10:32:18 +09:00
|
|
|
? "../external/standard_fonts/"
|
2023-04-28 01:01:07 +09:00
|
|
|
: PDFJSDev.test("MOZCENTRAL")
|
2023-11-26 01:28:14 +09:00
|
|
|
? "resource://pdf.js/web/standard_fonts/"
|
|
|
|
: "../web/standard_fonts/",
|
2020-12-11 10:32:18 +09:00
|
|
|
kind: OptionKind.API,
|
|
|
|
},
|
2018-02-17 23:33:57 +09:00
|
|
|
verbosity: {
|
|
|
|
/** @type {number} */
|
|
|
|
value: 1,
|
|
|
|
kind: OptionKind.API,
|
|
|
|
},
|
|
|
|
|
|
|
|
workerPort: {
|
|
|
|
/** @type {Object} */
|
|
|
|
value: null,
|
|
|
|
kind: OptionKind.WORKER,
|
|
|
|
},
|
|
|
|
workerSrc: {
|
|
|
|
/** @type {string} */
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
value:
|
2023-03-14 00:56:42 +09:00
|
|
|
// eslint-disable-next-line no-nested-ternary
|
2023-03-18 20:09:25 +09:00
|
|
|
typeof PDFJSDev === "undefined"
|
2020-11-02 07:06:40 +09:00
|
|
|
? "../src/pdf.worker.js"
|
2023-03-14 00:56:42 +09:00
|
|
|
: PDFJSDev.test("MOZCENTRAL")
|
2023-11-26 01:28:14 +09:00
|
|
|
? "resource://pdf.js/build/pdf.worker.mjs"
|
|
|
|
: "../build/pdf.worker.mjs",
|
2018-02-17 23:33:57 +09:00
|
|
|
kind: OptionKind.WORKER,
|
|
|
|
},
|
2018-02-17 21:22:26 +09:00
|
|
|
};
|
2023-11-19 02:18:36 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
2023-12-08 00:58:09 +09:00
|
|
|
defaultOptions.defaultUrl = {
|
|
|
|
/** @type {string} */
|
|
|
|
value:
|
|
|
|
typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")
|
|
|
|
? ""
|
|
|
|
: "compressed.tracemonkey-pldi-09.pdf",
|
|
|
|
kind: OptionKind.VIEWER,
|
|
|
|
};
|
|
|
|
defaultOptions.sandboxBundleSrc = {
|
|
|
|
/** @type {string} */
|
|
|
|
value:
|
|
|
|
typeof PDFJSDev === "undefined"
|
|
|
|
? "../build/dev-sandbox/pdf.sandbox.mjs"
|
|
|
|
: "../build/pdf.sandbox.mjs",
|
|
|
|
kind: OptionKind.VIEWER,
|
|
|
|
};
|
2023-11-19 02:18:36 +09:00
|
|
|
defaultOptions.viewerCssTheme = {
|
|
|
|
/** @type {number} */
|
|
|
|
value: typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME") ? 2 : 0,
|
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
|
|
};
|
|
|
|
}
|
2023-03-18 20:09:25 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
2018-11-29 19:31:49 +09:00
|
|
|
defaultOptions.disablePreferences = {
|
|
|
|
/** @type {boolean} */
|
2020-12-17 22:32:05 +09:00
|
|
|
value: typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING"),
|
2018-11-29 19:31:49 +09:00
|
|
|
kind: OptionKind.VIEWER,
|
|
|
|
};
|
2018-06-23 20:01:43 +09:00
|
|
|
defaultOptions.locale = {
|
|
|
|
/** @type {string} */
|
2022-02-14 20:01:30 +09:00
|
|
|
value: navigator.language || "en-US",
|
2018-06-23 20:01:43 +09:00
|
|
|
kind: OptionKind.VIEWER,
|
|
|
|
};
|
2020-12-08 02:15:24 +09:00
|
|
|
} else if (PDFJSDev.test("CHROME")) {
|
2021-03-19 00:26:55 +09:00
|
|
|
defaultOptions.disableTelemetry = {
|
|
|
|
/** @type {boolean} */
|
|
|
|
value: false,
|
|
|
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
|
|
|
};
|
2018-06-23 20:01:43 +09:00
|
|
|
}
|
2018-02-17 21:22:26 +09:00
|
|
|
|
|
|
|
const userOptions = Object.create(null);
|
|
|
|
|
|
|
|
class AppOptions {
|
|
|
|
constructor() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error("Cannot initialize AppOptions.");
|
2018-02-17 21:22:26 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static get(name) {
|
2019-02-02 18:09:05 +09:00
|
|
|
const userOption = userOptions[name];
|
2018-02-17 21:22:26 +09:00
|
|
|
if (userOption !== undefined) {
|
|
|
|
return userOption;
|
|
|
|
}
|
2019-02-02 18:09:05 +09:00
|
|
|
const defaultOption = defaultOptions[name];
|
|
|
|
if (defaultOption !== undefined) {
|
2022-06-16 23:51:33 +09:00
|
|
|
return compatibilityParams[name] ?? defaultOption.value;
|
2019-02-02 18:09:05 +09:00
|
|
|
}
|
|
|
|
return undefined;
|
2018-02-17 21:22:26 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static getAll(kind = null) {
|
2019-02-02 18:09:05 +09:00
|
|
|
const options = Object.create(null);
|
|
|
|
for (const name in defaultOptions) {
|
|
|
|
const defaultOption = defaultOptions[name];
|
2019-02-13 22:00:23 +09:00
|
|
|
if (kind) {
|
2023-11-01 04:13:13 +09:00
|
|
|
if (!(kind & defaultOption.kind)) {
|
2019-02-13 22:00:23 +09:00
|
|
|
continue;
|
|
|
|
}
|
2023-11-01 04:13:13 +09:00
|
|
|
if (
|
|
|
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("LIB")) &&
|
|
|
|
kind === OptionKind.PREFERENCE
|
|
|
|
) {
|
2023-10-31 19:39:04 +09:00
|
|
|
if (defaultOption.kind & OptionKind.BROWSER) {
|
|
|
|
throw new Error(`Invalid kind for preference: ${name}`);
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const value = defaultOption.value,
|
|
|
|
valueType = typeof value;
|
2019-03-03 19:40:56 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
valueType === "boolean" ||
|
|
|
|
valueType === "string" ||
|
|
|
|
(valueType === "number" && Number.isInteger(value))
|
|
|
|
) {
|
2019-03-03 19:40:56 +09:00
|
|
|
options[name] = value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw new Error(`Invalid type for preference: ${name}`);
|
2019-02-13 22:00:23 +09:00
|
|
|
}
|
2018-02-17 21:22:26 +09:00
|
|
|
}
|
2019-02-02 18:09:05 +09:00
|
|
|
const userOption = userOptions[name];
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
options[name] =
|
|
|
|
userOption !== undefined
|
|
|
|
? userOption
|
2022-06-16 23:51:33 +09:00
|
|
|
: compatibilityParams[name] ?? defaultOption.value;
|
2018-02-17 21:22:26 +09:00
|
|
|
}
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
static set(name, value) {
|
|
|
|
userOptions[name] = value;
|
|
|
|
}
|
|
|
|
|
2023-10-16 00:08:00 +09:00
|
|
|
static setAll(options, init = false) {
|
|
|
|
if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && init) {
|
|
|
|
if (this.get("disablePreferences")) {
|
|
|
|
// Give custom implementations of the default viewer a simpler way to
|
|
|
|
// opt-out of having the `Preferences` override existing `AppOptions`.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Object.keys(userOptions).length) {
|
|
|
|
console.warn(
|
|
|
|
"setAll: The Preferences may override manually set AppOptions; " +
|
|
|
|
'please use the "disablePreferences"-option in order to prevent that.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add an `AppOptions.setAll` method, and use it in `PDFViewerApplication._readPreferences`
Given that it's generally faster to call *one* function and have it loop through an object, rather than looping through an object and calling a function for every iteration, this patch will reduce the total time spent in `PDFViewerApplication._readPreferences` ever so slightly.
Also, over time we've been adding more and more preferences, rather than removing them, so using the new `AppOptions.setAll` method should be generally beneficial as well.
While the effect of these changes is quite small, it does reduces the time it takes for the preferences to be fully initialized. Given the amount of asynchronous code during viewer initialization, every bit of time that we can save should thus help.
Especially considering the recently added `viewerCssTheme` preference, which needs to be read very early to reduce the risk of the viewer UI "flashing" visibly as the theme changes, I figured that a couple of small patches reducing the time spend reading preferences cannot hurt.
2020-11-17 21:44:15 +09:00
|
|
|
for (const name in options) {
|
|
|
|
userOptions[name] = options[name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-17 21:22:26 +09:00
|
|
|
static remove(name) {
|
|
|
|
delete userOptions[name];
|
|
|
|
}
|
2023-02-10 23:37:51 +09:00
|
|
|
}
|
2021-09-22 20:26:17 +09:00
|
|
|
|
2021-07-27 19:23:33 +09:00
|
|
|
export { AppOptions, compatibilityParams, OptionKind };
|