2018-11-08 21:18:18 +09:00
|
|
|
/* Copyright 2018 Mozilla Foundation
|
2014-09-21 02:21:49 +09:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-11-23 19:28:29 +09:00
|
|
|
/* eslint-disable getter-return */
|
2014-09-21 02:21:49 +09:00
|
|
|
|
2021-12-15 07:59:17 +09:00
|
|
|
/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
|
2021-12-15 21:54:29 +09:00
|
|
|
/** @typedef {import("./ui_utils").RenderingStates} RenderingStates */
|
2021-12-15 07:59:17 +09:00
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
|
|
|
* @interface
|
|
|
|
*/
|
2017-05-08 05:01:49 +09:00
|
|
|
class IPDFLinkService {
|
2018-10-11 17:23:51 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {number}
|
2018-10-11 17:23:51 +09:00
|
|
|
*/
|
|
|
|
get pagesCount() {}
|
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {number}
|
2014-09-21 02:21:49 +09:00
|
|
|
*/
|
2017-05-08 05:01:49 +09:00
|
|
|
get page() {}
|
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
|
|
|
* @param {number} value
|
|
|
|
*/
|
2017-05-08 05:01:49 +09:00
|
|
|
set page(value) {}
|
|
|
|
|
2017-08-21 18:56:49 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {number}
|
2017-08-21 18:56:49 +09:00
|
|
|
*/
|
|
|
|
get rotation() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} value
|
|
|
|
*/
|
|
|
|
set rotation(value) {}
|
|
|
|
|
2022-10-31 01:36:20 +09:00
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
get isInPresentationMode() {}
|
|
|
|
|
2019-08-21 06:43:24 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {boolean}
|
2019-08-21 06:43:24 +09:00
|
|
|
*/
|
|
|
|
get externalLinkEnabled() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {boolean} value
|
|
|
|
*/
|
|
|
|
set externalLinkEnabled(value) {}
|
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
2020-10-04 00:43:33 +09:00
|
|
|
* @param {string|Array} dest - The named, or explicit, PDF destination.
|
2014-09-21 02:21:49 +09:00
|
|
|
*/
|
2020-10-04 00:43:33 +09:00
|
|
|
async goToDestination(dest) {}
|
2017-05-08 05:01:49 +09:00
|
|
|
|
2020-10-04 01:08:30 +09:00
|
|
|
/**
|
2020-10-31 18:17:28 +09:00
|
|
|
* @param {number|string} val - The page number, or page label.
|
2020-10-04 01:08:30 +09:00
|
|
|
*/
|
2020-10-31 18:17:28 +09:00
|
|
|
goToPage(val) {}
|
2020-10-04 01:08:30 +09:00
|
|
|
|
2021-09-30 20:30:55 +09:00
|
|
|
/**
|
|
|
|
* @param {HTMLAnchorElement} link
|
|
|
|
* @param {string} url
|
|
|
|
* @param {boolean} [newWindow]
|
|
|
|
*/
|
|
|
|
addLinkAttributes(link, url, newWindow = false) {}
|
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
|
|
|
* @param dest - The PDF destination object.
|
|
|
|
* @returns {string} The hyperlink to the PDF object.
|
|
|
|
*/
|
2017-05-08 05:01:49 +09:00
|
|
|
getDestinationHash(dest) {}
|
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
|
|
|
* @param hash - The PDF parameters/hash.
|
|
|
|
* @returns {string} The hyperlink to the PDF object.
|
|
|
|
*/
|
2017-05-08 05:01:49 +09:00
|
|
|
getAnchorUrl(hash) {}
|
|
|
|
|
2014-09-22 20:41:17 +09:00
|
|
|
/**
|
|
|
|
* @param {string} hash
|
|
|
|
*/
|
2017-05-08 05:01:49 +09:00
|
|
|
setHash(hash) {}
|
|
|
|
|
2014-10-01 02:22:38 +09:00
|
|
|
/**
|
|
|
|
* @param {string} action
|
|
|
|
*/
|
2017-05-08 05:01:49 +09:00
|
|
|
executeNamedAction(action) {}
|
2015-04-28 00:25:32 +09:00
|
|
|
|
2022-09-01 00:50:28 +09:00
|
|
|
/**
|
|
|
|
* @param {Object} action
|
|
|
|
*/
|
|
|
|
executeSetOCGState(action) {}
|
|
|
|
|
2015-04-28 00:25:32 +09:00
|
|
|
/**
|
|
|
|
* @param {number} pageNum - page number.
|
|
|
|
* @param {Object} pageRef - reference to the page.
|
|
|
|
*/
|
2017-05-08 05:01:49 +09:00
|
|
|
cachePageRef(pageNum, pageRef) {}
|
|
|
|
}
|
2014-09-21 02:21:49 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @interface
|
|
|
|
*/
|
2017-05-08 05:01:49 +09:00
|
|
|
class IRenderableView {
|
Fix Viewer API definitions and include in CI
The Viewer API definitions do not compile because of missing imports and
anonymous objects are typed as `Object`. These issues were not caught
during CI because the test project was not compiling anything from the
Viewer API.
As an example of the first problem:
```
/**
* @implements MyInterface
*/
export class MyClass {
...
}
```
will generate a broken definition that doesn’t import MyInterface:
```
/**
* @implements MyInterface
*/
export class MyClass implements MyInterface {
...
}
```
This can be fixed by adding a typedef jsdoc to specify the import:
```
/** @typedef {import("./otherFile").MyInterface} MyInterface */
```
See https://github.com/jsdoc/jsdoc/issues/1537 and
https://github.com/microsoft/TypeScript/issues/22160 for more details.
As an example of the second problem:
```
/**
* Gets the size of the specified page, converted from PDF units to inches.
* @param {Object} An Object containing the properties: {Array} `view`,
* {number} `userUnit`, and {number} `rotate`.
*/
function getPageSizeInches({ view, userUnit, rotate }) {
...
}
```
generates the broken definition:
```
function getPageSizeInches({ view, userUnit, rotate }: Object) {
...
}
```
The jsdoc should specify the type of each nested property:
```
/**
* Gets the size of the specified page, converted from PDF units to inches.
* @param {Object} options An object containing the properties: {Array} `view`,
* {number} `userUnit`, and {number} `rotate`.
* @param {number[]} options.view
* @param {number} options.userUnit
* @param {number} options.rotate
*/
```
2021-08-26 07:44:06 +09:00
|
|
|
constructor() {
|
|
|
|
/** @type {function | null} */
|
|
|
|
this.resume = null;
|
|
|
|
}
|
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {string} - Unique ID for rendering queue.
|
2014-09-21 02:21:49 +09:00
|
|
|
*/
|
2017-05-08 05:01:49 +09:00
|
|
|
get renderingId() {}
|
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {RenderingStates}
|
2014-09-21 02:21:49 +09:00
|
|
|
*/
|
2017-05-08 05:01:49 +09:00
|
|
|
get renderingState() {}
|
|
|
|
|
2014-09-21 02:21:49 +09:00
|
|
|
/**
|
2014-12-18 05:47:14 +09:00
|
|
|
* @returns {Promise} Resolved on draw completion.
|
2014-09-21 02:21:49 +09:00
|
|
|
*/
|
2023-03-29 04:51:57 +09:00
|
|
|
async draw() {}
|
2017-05-08 05:01:49 +09:00
|
|
|
}
|
2014-09-21 02:21:49 +09:00
|
|
|
|
2021-12-15 07:59:17 +09:00
|
|
|
/**
|
|
|
|
* @interface
|
|
|
|
*/
|
|
|
|
class IDownloadManager {
|
|
|
|
/**
|
|
|
|
* @param {string} url
|
|
|
|
* @param {string} filename
|
2023-05-05 22:18:01 +09:00
|
|
|
* @param {Object} [options]
|
2021-12-15 07:59:17 +09:00
|
|
|
*/
|
2023-05-05 22:18:01 +09:00
|
|
|
downloadUrl(url, filename, options) {}
|
2021-12-15 07:59:17 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Uint8Array} data
|
|
|
|
* @param {string} filename
|
|
|
|
* @param {string} [contentType]
|
|
|
|
*/
|
|
|
|
downloadData(data, filename, contentType) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Uint8Array} data
|
|
|
|
* @param {string} filename
|
2023-10-16 23:20:46 +09:00
|
|
|
* @param {string | null} [dest]
|
2021-12-15 07:59:17 +09:00
|
|
|
* @returns {boolean} Indicating if the data was opened.
|
|
|
|
*/
|
2023-10-16 23:20:46 +09:00
|
|
|
openOrDownloadData(data, filename, dest = null) {}
|
2021-12-15 07:59:17 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Blob} blob
|
|
|
|
* @param {string} url
|
|
|
|
* @param {string} filename
|
2023-05-05 22:18:01 +09:00
|
|
|
* @param {Object} [options]
|
2021-12-15 07:59:17 +09:00
|
|
|
*/
|
2023-05-05 22:18:01 +09:00
|
|
|
download(blob, url, filename, options) {}
|
2021-12-15 07:59:17 +09:00
|
|
|
}
|
|
|
|
|
2017-05-04 10:05:53 +09:00
|
|
|
/**
|
|
|
|
* @interface
|
|
|
|
*/
|
|
|
|
class IL10n {
|
2018-03-20 21:42:45 +09:00
|
|
|
/**
|
2023-10-13 23:23:17 +09:00
|
|
|
* @returns {string} - The current locale.
|
2018-03-20 21:42:45 +09:00
|
|
|
*/
|
2023-10-13 23:23:17 +09:00
|
|
|
getLanguage() {}
|
2018-03-20 21:42:45 +09:00
|
|
|
|
2017-05-04 10:05:53 +09:00
|
|
|
/**
|
2023-10-13 23:23:17 +09:00
|
|
|
* @returns {string} - 'rtl' or 'ltr'.
|
2017-05-04 10:05:53 +09:00
|
|
|
*/
|
2023-10-13 23:23:17 +09:00
|
|
|
getDirection() {}
|
2017-05-04 10:05:53 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Translates text identified by the key and adds/formats data using the args
|
|
|
|
* property bag. If the key was not found, translation falls back to the
|
|
|
|
* fallback text.
|
[api-minor] Re-factor `NullL10n` and remove the hard-coded l10n strings (PR 17115 follow-up)
*Please note:* These changes only affect the GENERIC build, since `NullL10n` is only a stub elsewhere (see PR 17135).
After the changes in PR 17115, which modernized and improved l10n-handling, the `NullL10n`-implementation is no longer a good fallback for the "proper" `L10n`-classes.
To improve this situation, especially for the *standalone* viewer-components, this patch makes the following changes:
- Let the `NullL10n`-implementation extend an actual `L10n`-class, which is constant and lazily initialized, to ensure that it works *exactly* like the "proper" ones.
- Automatically bundle the "en-US" l10n-strings in the build, via the pre-processor, such that we don't need to remember to manually update them.
- Ensure that the *standalone* viewer-components register their DOM-elements for translation, similar to the default viewer, since this will allow future code improvements by using "data-l10n-id"/"data-l10n-args" in most (if not all) parts of the viewer.
- Remove the `NullL10n` from the `AnnotationLayer`, to avoid affecting bundle size too much.
For third-party users that access the `AnnotationLayer`, as exposed in the main PDF.js library, they'll now need to *manually* register it for translation. (However, the *standalone* viewer-components still works given the point above.)
2023-10-20 05:12:46 +09:00
|
|
|
* @param {Array | string} ids
|
2021-12-15 07:59:17 +09:00
|
|
|
* @param {Object | null} [args]
|
|
|
|
* @param {string} [fallback]
|
2017-05-04 10:05:53 +09:00
|
|
|
* @returns {Promise<string>}
|
|
|
|
*/
|
[api-minor] Re-factor `NullL10n` and remove the hard-coded l10n strings (PR 17115 follow-up)
*Please note:* These changes only affect the GENERIC build, since `NullL10n` is only a stub elsewhere (see PR 17135).
After the changes in PR 17115, which modernized and improved l10n-handling, the `NullL10n`-implementation is no longer a good fallback for the "proper" `L10n`-classes.
To improve this situation, especially for the *standalone* viewer-components, this patch makes the following changes:
- Let the `NullL10n`-implementation extend an actual `L10n`-class, which is constant and lazily initialized, to ensure that it works *exactly* like the "proper" ones.
- Automatically bundle the "en-US" l10n-strings in the build, via the pre-processor, such that we don't need to remember to manually update them.
- Ensure that the *standalone* viewer-components register their DOM-elements for translation, similar to the default viewer, since this will allow future code improvements by using "data-l10n-id"/"data-l10n-args" in most (if not all) parts of the viewer.
- Remove the `NullL10n` from the `AnnotationLayer`, to avoid affecting bundle size too much.
For third-party users that access the `AnnotationLayer`, as exposed in the main PDF.js library, they'll now need to *manually* register it for translation. (However, the *standalone* viewer-components still works given the point above.)
2023-10-20 05:12:46 +09:00
|
|
|
async get(ids, args = null, fallback) {}
|
2017-05-04 10:05:53 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Translates HTML element.
|
|
|
|
* @param {HTMLElement} element
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
2018-07-30 23:28:39 +09:00
|
|
|
async translate(element) {}
|
2023-10-26 00:10:58 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pause the localization.
|
|
|
|
*/
|
|
|
|
pause() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resume the localization.
|
|
|
|
*/
|
|
|
|
resume() {}
|
2017-04-24 03:52:58 +09:00
|
|
|
}
|
2018-11-08 21:18:18 +09:00
|
|
|
|
[api-minor] Remove the `xfaLayerFactory` in the viewer
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.
Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.
Hence this patch, which removes the `xfaLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.
---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
2022-12-07 08:13:44 +09:00
|
|
|
export { IDownloadManager, IL10n, IPDFLinkService, IRenderableView };
|