pdf.js/web/interfaces.js

214 lines
4.1 KiB
JavaScript
Raw Normal View History

/* 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.
*/
/* eslint-disable getter-return */
/**
* @interface
*/
2017-05-08 05:01:49 +09:00
class IPDFLinkService {
/**
* @type {number}
*/
get pagesCount() {}
/**
* @type {number}
*/
2017-05-08 05:01:49 +09:00
get page() {}
/**
* @param {number} value
*/
2017-05-08 05:01:49 +09:00
set page(value) {}
2017-08-21 18:56:49 +09:00
/**
* @type {number}
2017-08-21 18:56:49 +09:00
*/
get rotation() {}
/**
* @param {number} value
*/
set rotation(value) {}
2019-08-21 06:43:24 +09:00
/**
* @type {boolean}
2019-08-21 06:43:24 +09:00
*/
get externalLinkEnabled() {}
/**
* @param {boolean} value
*/
set externalLinkEnabled(value) {}
/**
* @param dest - The PDF destination object.
*/
2017-05-08 05:01:49 +09:00
navigateTo(dest) {}
/**
* @param dest - The PDF destination object.
* @returns {string} The hyperlink to the PDF object.
*/
2017-05-08 05:01:49 +09:00
getDestinationHash(dest) {}
/**
* @param hash - The PDF parameters/hash.
* @returns {string} The hyperlink to the PDF object.
*/
2017-05-08 05:01:49 +09:00
getAnchorUrl(hash) {}
/**
* @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) {}
/**
* @param {number} pageNum - page number.
* @param {Object} pageRef - reference to the page.
*/
2017-05-08 05:01:49 +09:00
cachePageRef(pageNum, pageRef) {}
/**
* @param {number} pageNumber
*/
isPageVisible(pageNumber) {}
2017-05-08 05:01:49 +09:00
}
/**
* @interface
*/
2017-05-08 05:01:49 +09:00
class IPDFHistory {
/**
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
* @param {Object} params
*/
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
initialize({ fingerprint, resetHistory = false, updateUrl = false, }) {}
reset() {}
/**
* @param {Object} params
*/
push({ namedDest = null, explicitDest, pageNumber, }) {}
pushCurrentPosition() {}
2017-05-08 05:01:49 +09:00
back() {}
forward() {}
2017-05-08 05:01:49 +09:00
}
/**
* @interface
*/
2017-05-08 05:01:49 +09:00
class IRenderableView {
/**
* @type {string} - Unique ID for rendering queue.
*/
2017-05-08 05:01:49 +09:00
get renderingId() {}
/**
* @type {RenderingStates}
*/
2017-05-08 05:01:49 +09:00
get renderingState() {}
/**
* @returns {Promise} Resolved on draw completion.
*/
2017-05-08 05:01:49 +09:00
draw() {}
resume() {}
}
2014-09-28 23:35:33 +09:00
/**
* @interface
*/
2017-05-08 05:01:49 +09:00
class IPDFTextLayerFactory {
2014-09-28 23:35:33 +09:00
/**
* @param {HTMLDivElement} textLayerDiv
* @param {number} pageIndex
* @param {PageViewport} viewport
* @param {boolean} enhanceTextSelection
2014-09-28 23:35:33 +09:00
* @returns {TextLayerBuilder}
*/
createTextLayerBuilder(textLayerDiv, pageIndex, viewport,
enhanceTextSelection = false) {}
2017-05-08 05:01:49 +09:00
}
2014-09-30 01:05:28 +09:00
/**
* @interface
*/
class IPDFAnnotationLayerFactory {
2014-09-30 01:05:28 +09:00
/**
* @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage
* @param {string} [imageResourcesPath] - Path for image resources, mainly
* for annotation icons. Include trailing slash.
* @param {boolean} renderInteractiveForms
* @param {IL10n} l10n
* @returns {AnnotationLayerBuilder}
2014-09-30 01:05:28 +09:00
*/
createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = '',
renderInteractiveForms = false,
l10n = undefined) {}
}
/**
* @interface
*/
class IL10n {
/**
* @returns {Promise<string>} - Resolves to the current locale.
*/
async getLanguage() {}
/**
* @returns {Promise<string>} - Resolves to 'rtl' or 'ltr'.
*/
async getDirection() {}
/**
* 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.
* @param {string} key
* @param {object} args
* @param {string} fallback
* @returns {Promise<string>}
*/
async get(key, args, fallback) { }
/**
* Translates HTML element.
* @param {HTMLElement} element
* @returns {Promise<void>}
*/
async translate(element) { }
}
export {
IPDFLinkService,
IPDFHistory,
IRenderableView,
IPDFTextLayerFactory,
IPDFAnnotationLayerFactory,
IL10n,
};