2014-06-18 07:43:33 +09:00
|
|
|
/* Copyright 2014 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.
|
|
|
|
*/
|
|
|
|
|
2017-04-02 21:25:33 +09:00
|
|
|
import {
|
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
|
|
|
AnnotationBorderStyleType,
|
|
|
|
AnnotationType,
|
2020-12-06 03:32:13 +09:00
|
|
|
assert,
|
2021-07-27 16:25:36 +09:00
|
|
|
shadow,
|
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
|
|
|
stringToPDFString,
|
|
|
|
unreachable,
|
|
|
|
Util,
|
|
|
|
warn,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "../shared/util.js";
|
2021-09-30 20:30:55 +09:00
|
|
|
import {
|
|
|
|
DOMSVGFactory,
|
|
|
|
getFilenameFromUrl,
|
|
|
|
PDFDateString,
|
|
|
|
} from "./display_utils.js";
|
[api-minor] Fix the `AnnotationStorage` usage properly in the viewer/tests (PR 12107 and 12143 follow-up)
*The [api-minor] label probably ought to have been added to the original PR, given the changes to the `createAnnotationLayerBuilder` signature (if nothing else).*
This patch fixes the following things:
- Let the `AnnotationLayer.render` method create an `AnnotationStorage`-instance if none was provided, thus making the parameter *properly* optional. This not only fixes the reference tests, it also prevents issues when the viewer components are used.
- Stop exporting `AnnotationStorage` in the official API, i.e. the `src/pdf.js` file, since it's no longer necessary given the change above. Generally speaking, unless absolutely necessary we probably shouldn't export unused things in the API.
- Fix a number of JSDocs `typedef`s, in `src/display/` and `web/` code, to actually account for the new `annotationStorage` parameter.
- Update `web/interfaces.js` to account for the changes in `createAnnotationLayerBuilder`.
- Initialize the storage, in `AnnotationStorage`, using `Object.create(null)` rather than `{}` (which is the PDF.js default).
2020-07-31 23:13:26 +09:00
|
|
|
import { AnnotationStorage } from "./annotation_storage.js";
|
2020-12-04 21:46:32 +09:00
|
|
|
import { ColorConverters } from "../shared/scripting_utils.js";
|
2021-10-25 00:29:30 +09:00
|
|
|
import { XfaLayer } from "./xfa_layer.js";
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2021-08-05 19:58:36 +09:00
|
|
|
const DEFAULT_TAB_INDEX = 1000;
|
2021-09-14 19:06:28 +09:00
|
|
|
const GetElementsByNameSet = new WeakSet();
|
2021-08-05 19:58:36 +09:00
|
|
|
|
2015-12-17 23:55:11 +09:00
|
|
|
/**
|
|
|
|
* @typedef {Object} AnnotationElementParameters
|
|
|
|
* @property {Object} data
|
2015-12-23 05:31:56 +09:00
|
|
|
* @property {HTMLDivElement} layer
|
2015-12-17 23:55:11 +09:00
|
|
|
* @property {PDFPage} page
|
|
|
|
* @property {PageViewport} viewport
|
|
|
|
* @property {IPDFLinkService} linkService
|
2016-02-15 04:44:00 +09:00
|
|
|
* @property {DownloadManager} downloadManager
|
[api-minor] Fix the `AnnotationStorage` usage properly in the viewer/tests (PR 12107 and 12143 follow-up)
*The [api-minor] label probably ought to have been added to the original PR, given the changes to the `createAnnotationLayerBuilder` signature (if nothing else).*
This patch fixes the following things:
- Let the `AnnotationLayer.render` method create an `AnnotationStorage`-instance if none was provided, thus making the parameter *properly* optional. This not only fixes the reference tests, it also prevents issues when the viewer components are used.
- Stop exporting `AnnotationStorage` in the official API, i.e. the `src/pdf.js` file, since it's no longer necessary given the change above. Generally speaking, unless absolutely necessary we probably shouldn't export unused things in the API.
- Fix a number of JSDocs `typedef`s, in `src/display/` and `web/` code, to actually account for the new `annotationStorage` parameter.
- Update `web/interfaces.js` to account for the changes in `createAnnotationLayerBuilder`.
- Initialize the storage, in `AnnotationStorage`, using `Object.create(null)` rather than `{}` (which is the PDF.js default).
2020-07-31 23:13:26 +09:00
|
|
|
* @property {AnnotationStorage} [annotationStorage]
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
|
|
|
* for annotation icons. Include trailing slash.
|
[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
|
|
|
* @property {boolean} renderForms
|
2017-07-24 07:09:18 +09:00
|
|
|
* @property {Object} svgFactory
|
2020-10-29 03:16:56 +09:00
|
|
|
* @property {boolean} [enableScripting]
|
|
|
|
* @property {boolean} [hasJSActions]
|
2021-09-14 19:06:28 +09:00
|
|
|
* @property {Object} [fieldObjects]
|
2020-12-17 20:55:58 +09:00
|
|
|
* @property {Object} [mouseState]
|
2015-12-17 23:55:11 +09:00
|
|
|
*/
|
2014-12-26 04:44:16 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class AnnotationElementFactory {
|
2015-12-17 23:55:11 +09:00
|
|
|
/**
|
|
|
|
* @param {AnnotationElementParameters} parameters
|
|
|
|
* @returns {AnnotationElement}
|
|
|
|
*/
|
2017-08-27 07:30:00 +09:00
|
|
|
static create(parameters) {
|
2019-08-31 23:40:39 +09:00
|
|
|
const subtype = parameters.data.annotationType;
|
2015-12-17 23:55:11 +09:00
|
|
|
|
|
|
|
switch (subtype) {
|
|
|
|
case AnnotationType.LINK:
|
|
|
|
return new LinkAnnotationElement(parameters);
|
2014-12-26 04:44:16 +09:00
|
|
|
|
2015-12-17 23:55:11 +09:00
|
|
|
case AnnotationType.TEXT:
|
|
|
|
return new TextAnnotationElement(parameters);
|
2014-12-26 04:44:16 +09:00
|
|
|
|
2015-12-17 23:55:11 +09:00
|
|
|
case AnnotationType.WIDGET:
|
2019-08-31 23:40:39 +09:00
|
|
|
const fieldType = parameters.data.fieldType;
|
2016-09-06 06:46:52 +09:00
|
|
|
|
|
|
|
switch (fieldType) {
|
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
|
|
|
case "Tx":
|
2016-09-06 06:46:52 +09:00
|
|
|
return new TextWidgetAnnotationElement(parameters);
|
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
|
|
|
case "Btn":
|
2016-12-16 07:49:46 +09:00
|
|
|
if (parameters.data.radioButton) {
|
|
|
|
return new RadioButtonWidgetAnnotationElement(parameters);
|
|
|
|
} else if (parameters.data.checkBox) {
|
|
|
|
return new CheckboxWidgetAnnotationElement(parameters);
|
2016-11-04 21:01:42 +09:00
|
|
|
}
|
2017-11-21 07:00:19 +09:00
|
|
|
return new PushButtonWidgetAnnotationElement(parameters);
|
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
|
|
|
case "Ch":
|
2016-09-25 08:45:49 +09:00
|
|
|
return new ChoiceWidgetAnnotationElement(parameters);
|
2016-09-06 06:46:52 +09:00
|
|
|
}
|
2015-12-17 23:55:11 +09:00
|
|
|
return new WidgetAnnotationElement(parameters);
|
2014-12-26 04:44:16 +09:00
|
|
|
|
2015-12-23 05:31:56 +09:00
|
|
|
case AnnotationType.POPUP:
|
|
|
|
return new PopupAnnotationElement(parameters);
|
|
|
|
|
2019-04-14 01:45:22 +09:00
|
|
|
case AnnotationType.FREETEXT:
|
|
|
|
return new FreeTextAnnotationElement(parameters);
|
|
|
|
|
2017-04-03 03:50:17 +09:00
|
|
|
case AnnotationType.LINE:
|
|
|
|
return new LineAnnotationElement(parameters);
|
|
|
|
|
2017-07-24 07:11:27 +09:00
|
|
|
case AnnotationType.SQUARE:
|
|
|
|
return new SquareAnnotationElement(parameters);
|
|
|
|
|
2017-07-24 07:30:58 +09:00
|
|
|
case AnnotationType.CIRCLE:
|
|
|
|
return new CircleAnnotationElement(parameters);
|
|
|
|
|
2017-09-18 03:18:22 +09:00
|
|
|
case AnnotationType.POLYLINE:
|
|
|
|
return new PolylineAnnotationElement(parameters);
|
|
|
|
|
2019-04-10 06:35:32 +09:00
|
|
|
case AnnotationType.CARET:
|
|
|
|
return new CaretAnnotationElement(parameters);
|
|
|
|
|
2018-09-30 23:29:16 +09:00
|
|
|
case AnnotationType.INK:
|
|
|
|
return new InkAnnotationElement(parameters);
|
|
|
|
|
2017-09-23 23:50:49 +09:00
|
|
|
case AnnotationType.POLYGON:
|
|
|
|
return new PolygonAnnotationElement(parameters);
|
|
|
|
|
2016-01-01 23:31:46 +09:00
|
|
|
case AnnotationType.HIGHLIGHT:
|
|
|
|
return new HighlightAnnotationElement(parameters);
|
|
|
|
|
2015-12-28 08:33:41 +09:00
|
|
|
case AnnotationType.UNDERLINE:
|
|
|
|
return new UnderlineAnnotationElement(parameters);
|
|
|
|
|
2015-12-30 23:28:26 +09:00
|
|
|
case AnnotationType.SQUIGGLY:
|
|
|
|
return new SquigglyAnnotationElement(parameters);
|
|
|
|
|
2015-12-29 23:09:28 +09:00
|
|
|
case AnnotationType.STRIKEOUT:
|
|
|
|
return new StrikeOutAnnotationElement(parameters);
|
|
|
|
|
2017-09-16 23:37:50 +09:00
|
|
|
case AnnotationType.STAMP:
|
|
|
|
return new StampAnnotationElement(parameters);
|
|
|
|
|
2016-02-15 04:44:00 +09:00
|
|
|
case AnnotationType.FILEATTACHMENT:
|
|
|
|
return new FileAttachmentAnnotationElement(parameters);
|
|
|
|
|
2015-12-17 23:55:11 +09:00
|
|
|
default:
|
2016-01-12 12:44:44 +09:00
|
|
|
return new AnnotationElement(parameters);
|
2015-12-17 23:55:11 +09:00
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
|
|
|
}
|
2014-12-26 04:44:16 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class AnnotationElement {
|
2020-12-06 03:48:05 +09:00
|
|
|
constructor(
|
|
|
|
parameters,
|
|
|
|
{
|
|
|
|
isRenderable = false,
|
|
|
|
ignoreBorder = false,
|
|
|
|
createQuadrilaterals = false,
|
|
|
|
} = {}
|
|
|
|
) {
|
2017-08-27 07:24:27 +09:00
|
|
|
this.isRenderable = isRenderable;
|
2015-12-17 23:55:11 +09:00
|
|
|
this.data = parameters.data;
|
2015-12-23 05:31:56 +09:00
|
|
|
this.layer = parameters.layer;
|
2015-12-17 23:55:11 +09:00
|
|
|
this.page = parameters.page;
|
|
|
|
this.viewport = parameters.viewport;
|
|
|
|
this.linkService = parameters.linkService;
|
2016-02-15 04:44:00 +09:00
|
|
|
this.downloadManager = parameters.downloadManager;
|
2016-03-29 04:49:22 +09:00
|
|
|
this.imageResourcesPath = parameters.imageResourcesPath;
|
[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
|
|
|
this.renderForms = parameters.renderForms;
|
2017-07-24 07:09:18 +09:00
|
|
|
this.svgFactory = parameters.svgFactory;
|
2020-07-22 20:55:52 +09:00
|
|
|
this.annotationStorage = parameters.annotationStorage;
|
2020-10-29 03:16:56 +09:00
|
|
|
this.enableScripting = parameters.enableScripting;
|
|
|
|
this.hasJSActions = parameters.hasJSActions;
|
2021-09-14 19:06:28 +09:00
|
|
|
this._fieldObjects = parameters.fieldObjects;
|
2020-12-17 20:55:58 +09:00
|
|
|
this._mouseState = parameters.mouseState;
|
2015-12-17 23:55:11 +09:00
|
|
|
|
2016-01-12 12:44:44 +09:00
|
|
|
if (isRenderable) {
|
2017-04-03 03:31:21 +09:00
|
|
|
this.container = this._createContainer(ignoreBorder);
|
2016-01-12 12:44:44 +09:00
|
|
|
}
|
2020-12-06 03:48:05 +09:00
|
|
|
if (createQuadrilaterals) {
|
|
|
|
this.quadrilaterals = this._createQuadrilaterals(ignoreBorder);
|
|
|
|
}
|
2015-12-17 23:55:11 +09:00
|
|
|
}
|
2014-12-26 04:44:16 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
/**
|
|
|
|
* Create an empty container for the annotation's HTML element.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {boolean} ignoreBorder
|
|
|
|
* @memberof AnnotationElement
|
|
|
|
* @returns {HTMLSectionElement}
|
|
|
|
*/
|
|
|
|
_createContainer(ignoreBorder = false) {
|
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 data = this.data,
|
|
|
|
page = this.page,
|
|
|
|
viewport = this.viewport;
|
|
|
|
const container = document.createElement("section");
|
2017-08-27 07:24:27 +09:00
|
|
|
let width = data.rect[2] - data.rect[0];
|
|
|
|
let height = data.rect[3] - data.rect[1];
|
|
|
|
|
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
|
|
|
container.setAttribute("data-annotation-id", data.id);
|
2017-08-27 07:24:27 +09:00
|
|
|
|
|
|
|
// Do *not* modify `data.rect`, since that will corrupt the annotation
|
|
|
|
// position on subsequent calls to `_createContainer` (see issue 6804).
|
2019-08-31 23:40:39 +09:00
|
|
|
const rect = Util.normalizeRect([
|
2017-08-27 07:24:27 +09:00
|
|
|
data.rect[0],
|
|
|
|
page.view[3] - data.rect[1] + page.view[1],
|
|
|
|
data.rect[2],
|
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
|
|
|
page.view[3] - data.rect[3] + page.view[1],
|
2017-08-27 07:24:27 +09:00
|
|
|
]);
|
|
|
|
|
2021-11-07 02:36:49 +09:00
|
|
|
if (data.hasOwnCanvas) {
|
|
|
|
const transform = viewport.transform.slice();
|
|
|
|
const [scaleX, scaleY] = Util.singularValueDecompose2dScale(transform);
|
|
|
|
width = Math.ceil(width * scaleX);
|
|
|
|
height = Math.ceil(height * scaleY);
|
|
|
|
rect[0] *= scaleX;
|
|
|
|
rect[1] *= scaleY;
|
|
|
|
// Reset the scale part of the transform matrix (which must be diagonal
|
|
|
|
// or anti-diagonal) in order to avoid to rescale the canvas.
|
|
|
|
// The canvas for the annotation is correctly scaled when it is drawn
|
|
|
|
// (see `beginAnnotation` in canvas.js).
|
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
|
transform[i] = Math.sign(transform[i]);
|
|
|
|
}
|
|
|
|
container.style.transform = `matrix(${transform.join(",")})`;
|
|
|
|
} else {
|
|
|
|
container.style.transform = `matrix(${viewport.transform.join(",")})`;
|
|
|
|
}
|
|
|
|
|
2020-09-24 17:28:29 +09:00
|
|
|
container.style.transformOrigin = `${-rect[0]}px ${-rect[1]}px`;
|
2017-08-27 07:24:27 +09:00
|
|
|
|
|
|
|
if (!ignoreBorder && data.borderStyle.width > 0) {
|
2019-08-31 23:40:39 +09:00
|
|
|
container.style.borderWidth = `${data.borderStyle.width}px`;
|
2017-08-27 07:24:27 +09:00
|
|
|
if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
|
|
|
|
// Underline styles only have a bottom border, so we do not need
|
|
|
|
// to adjust for all borders. This yields a similar result as
|
|
|
|
// Adobe Acrobat/Reader.
|
2021-07-04 18:51:11 +09:00
|
|
|
width -= 2 * data.borderStyle.width;
|
|
|
|
height -= 2 * data.borderStyle.width;
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2014-12-26 04:44:16 +09:00
|
|
|
|
2019-08-31 23:40:39 +09:00
|
|
|
const horizontalRadius = data.borderStyle.horizontalCornerRadius;
|
|
|
|
const verticalRadius = data.borderStyle.verticalCornerRadius;
|
2017-08-27 07:24:27 +09:00
|
|
|
if (horizontalRadius > 0 || verticalRadius > 0) {
|
2019-08-31 23:40:39 +09:00
|
|
|
const radius = `${horizontalRadius}px / ${verticalRadius}px`;
|
2017-12-31 21:51:51 +09:00
|
|
|
container.style.borderRadius = radius;
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2014-12-26 04:44:16 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
switch (data.borderStyle.style) {
|
|
|
|
case AnnotationBorderStyleType.SOLID:
|
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
|
|
|
container.style.borderStyle = "solid";
|
2017-08-27 07:24:27 +09:00
|
|
|
break;
|
2015-12-03 08:20:18 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
case AnnotationBorderStyleType.DASHED:
|
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
|
|
|
container.style.borderStyle = "dashed";
|
2017-08-27 07:24:27 +09:00
|
|
|
break;
|
2015-12-03 08:20:18 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
case AnnotationBorderStyleType.BEVELED:
|
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
|
|
|
warn("Unimplemented border style: beveled");
|
2017-08-27 07:24:27 +09:00
|
|
|
break;
|
2014-06-18 07:43:33 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
case AnnotationBorderStyleType.INSET:
|
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
|
|
|
warn("Unimplemented border style: inset");
|
2017-08-27 07:24:27 +09:00
|
|
|
break;
|
2014-06-18 07:43:33 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
case AnnotationBorderStyleType.UNDERLINE:
|
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
|
|
|
container.style.borderBottomStyle = "solid";
|
2017-08-27 07:24:27 +09:00
|
|
|
break;
|
2014-06-18 07:43:33 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
default:
|
|
|
|
break;
|
2015-12-17 23:55:11 +09:00
|
|
|
}
|
2014-06-18 07:43:33 +09:00
|
|
|
|
2021-09-19 03:22:29 +09:00
|
|
|
const borderColor = data.borderColor || data.color || null;
|
|
|
|
if (borderColor) {
|
2020-10-30 22:51:50 +09:00
|
|
|
container.style.borderColor = Util.makeHexColor(
|
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
|
|
|
data.color[0] | 0,
|
|
|
|
data.color[1] | 0,
|
|
|
|
data.color[2] | 0
|
|
|
|
);
|
2017-08-27 07:24:27 +09:00
|
|
|
} else {
|
|
|
|
// Transparent (invisible) border, so do not draw it at all.
|
|
|
|
container.style.borderWidth = 0;
|
2016-02-23 08:21:28 +09:00
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2016-02-23 08:21:28 +09:00
|
|
|
|
2019-08-31 23:40:39 +09:00
|
|
|
container.style.left = `${rect[0]}px`;
|
|
|
|
container.style.top = `${rect[1]}px`;
|
2021-11-07 02:36:49 +09:00
|
|
|
|
|
|
|
if (data.hasOwnCanvas) {
|
|
|
|
container.style.width = container.style.height = "auto";
|
|
|
|
} else {
|
|
|
|
container.style.width = `${width}px`;
|
|
|
|
container.style.height = `${height}px`;
|
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2020-10-21 20:12:43 +09:00
|
|
|
/**
|
2020-12-06 04:16:40 +09:00
|
|
|
* Create quadrilaterals from the annotation's quadpoints.
|
2020-10-21 20:12:43 +09:00
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {boolean} ignoreBorder
|
|
|
|
* @memberof AnnotationElement
|
2020-12-06 04:16:40 +09:00
|
|
|
* @returns {Array<HTMLSectionElement>}
|
2020-10-21 20:12:43 +09:00
|
|
|
*/
|
|
|
|
_createQuadrilaterals(ignoreBorder = false) {
|
|
|
|
if (!this.data.quadPoints) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const quadrilaterals = [];
|
|
|
|
const savedRect = this.data.rect;
|
|
|
|
for (const quadPoint of this.data.quadPoints) {
|
2020-11-14 19:42:35 +09:00
|
|
|
this.data.rect = [
|
2020-10-21 20:12:43 +09:00
|
|
|
quadPoint[2].x,
|
|
|
|
quadPoint[2].y,
|
|
|
|
quadPoint[1].x,
|
|
|
|
quadPoint[1].y,
|
|
|
|
];
|
2020-11-14 19:42:35 +09:00
|
|
|
quadrilaterals.push(this._createContainer(ignoreBorder));
|
2020-10-21 20:12:43 +09:00
|
|
|
}
|
|
|
|
this.data.rect = savedRect;
|
|
|
|
return quadrilaterals;
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
/**
|
|
|
|
* Create a popup for the annotation's HTML element. This is used for
|
|
|
|
* annotations that do not have a Popup entry in the dictionary, but
|
|
|
|
* are of a type that works with popups (such as Highlight annotations).
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {HTMLDivElement|HTMLImageElement|null} trigger
|
|
|
|
* @param {Object} data
|
|
|
|
* @memberof AnnotationElement
|
|
|
|
*/
|
2020-11-06 01:49:32 +09:00
|
|
|
_createPopup(trigger, data) {
|
|
|
|
let container = this.container;
|
|
|
|
if (this.quadrilaterals) {
|
|
|
|
trigger = trigger || this.quadrilaterals;
|
|
|
|
container = this.quadrilaterals[0];
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
// If no trigger element is specified, create it.
|
|
|
|
if (!trigger) {
|
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
|
|
|
trigger = document.createElement("div");
|
2017-08-27 07:24:27 +09:00
|
|
|
trigger.style.height = container.style.height;
|
|
|
|
trigger.style.width = container.style.width;
|
|
|
|
container.appendChild(trigger);
|
|
|
|
}
|
2016-02-23 08:21:28 +09:00
|
|
|
|
2019-08-31 23:40:39 +09:00
|
|
|
const popupElement = new PopupElement({
|
2017-08-27 07:24:27 +09:00
|
|
|
container,
|
|
|
|
trigger,
|
|
|
|
color: data.color,
|
2021-09-25 00:30:56 +09:00
|
|
|
titleObj: data.titleObj,
|
2019-04-22 04:21:01 +09:00
|
|
|
modificationDate: data.modificationDate,
|
2021-09-25 00:30:56 +09:00
|
|
|
contentsObj: data.contentsObj,
|
2021-10-25 00:29:30 +09:00
|
|
|
richText: data.richText,
|
2017-08-27 07:24:27 +09:00
|
|
|
hideWrapper: true,
|
|
|
|
});
|
2019-08-31 23:40:39 +09:00
|
|
|
const popup = popupElement.render();
|
2014-06-18 07:43:33 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
// Position the popup next to the annotation's container.
|
|
|
|
popup.style.left = container.style.width;
|
2014-06-18 07:43:33 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
container.appendChild(popup);
|
2015-12-17 23:55:11 +09:00
|
|
|
}
|
2014-06-18 07:43:33 +09:00
|
|
|
|
2020-12-06 03:32:13 +09:00
|
|
|
/**
|
|
|
|
* Render the quadrilaterals of the annotation.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} className
|
|
|
|
* @memberof AnnotationElement
|
|
|
|
* @returns {Array<HTMLSectionElement>}
|
|
|
|
*/
|
|
|
|
_renderQuadrilaterals(className) {
|
|
|
|
if (
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("!PRODUCTION || TESTING")
|
|
|
|
) {
|
|
|
|
assert(this.quadrilaterals, "Missing quadrilaterals during rendering");
|
|
|
|
}
|
|
|
|
|
2021-04-24 19:36:01 +09:00
|
|
|
for (const quadrilateral of this.quadrilaterals) {
|
2020-12-06 03:32:13 +09:00
|
|
|
quadrilateral.className = className;
|
2021-04-24 19:36:01 +09:00
|
|
|
}
|
2020-12-06 03:32:13 +09:00
|
|
|
return this.quadrilaterals;
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
/**
|
2020-12-06 04:16:40 +09:00
|
|
|
* Render the annotation's HTML element(s).
|
2017-08-27 07:24:27 +09:00
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @memberof AnnotationElement
|
2020-12-06 04:16:40 +09:00
|
|
|
* @returns {HTMLSectionElement|Array<HTMLSectionElement>}
|
2017-08-27 07:24:27 +09:00
|
|
|
*/
|
|
|
|
render() {
|
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
|
|
|
unreachable("Abstract method `AnnotationElement.render` called");
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2021-07-27 16:25:36 +09:00
|
|
|
|
2021-09-14 19:06:28 +09:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
_getElementsByName(name, skipId = null) {
|
|
|
|
const fields = [];
|
|
|
|
|
|
|
|
if (this._fieldObjects) {
|
|
|
|
const fieldObj = this._fieldObjects[name];
|
|
|
|
if (fieldObj) {
|
|
|
|
for (const { page, id, exportValues } of fieldObj) {
|
|
|
|
if (page === -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (id === skipId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const exportValue =
|
|
|
|
typeof exportValues === "string" ? exportValues : null;
|
|
|
|
|
|
|
|
const domElement = document.getElementById(id);
|
|
|
|
if (domElement && !GetElementsByNameSet.has(domElement)) {
|
|
|
|
warn(`_getElementsByName - element not allowed: ${id}`);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fields.push({ id, exportValue, domElement });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fields;
|
|
|
|
}
|
|
|
|
// Fallback to a regular DOM lookup, to ensure that the standalone
|
|
|
|
// viewer components won't break.
|
|
|
|
for (const domElement of document.getElementsByName(name)) {
|
|
|
|
const { id, exportValue } = domElement;
|
|
|
|
if (id === skipId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!GetElementsByNameSet.has(domElement)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fields.push({ id, exportValue, domElement });
|
|
|
|
}
|
|
|
|
return fields;
|
|
|
|
}
|
|
|
|
|
2021-07-27 16:25:36 +09:00
|
|
|
static get platform() {
|
|
|
|
const platform = typeof navigator !== "undefined" ? navigator.platform : "";
|
|
|
|
|
|
|
|
return shadow(this, "platform", {
|
|
|
|
isWin: platform.includes("Win"),
|
|
|
|
isMac: platform.includes("Mac"),
|
|
|
|
});
|
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2014-06-18 07:43:33 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class LinkAnnotationElement extends AnnotationElement {
|
2021-10-21 20:31:16 +09:00
|
|
|
constructor(parameters, options = null) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.url ||
|
|
|
|
parameters.data.dest ||
|
2020-09-07 00:14:56 +09:00
|
|
|
parameters.data.action ||
|
2020-11-18 22:59:57 +09:00
|
|
|
parameters.data.isTooltipOnly ||
|
2021-09-27 04:04:11 +09:00
|
|
|
parameters.data.resetForm ||
|
2020-11-18 22:59:57 +09:00
|
|
|
(parameters.data.actions &&
|
|
|
|
(parameters.data.actions.Action ||
|
2021-01-24 03:09:26 +09:00
|
|
|
parameters.data.actions["Mouse Up"] ||
|
|
|
|
parameters.data.actions["Mouse Down"]))
|
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
|
|
|
);
|
2021-10-21 20:31:16 +09:00
|
|
|
super(parameters, {
|
|
|
|
isRenderable,
|
|
|
|
ignoreBorder: !!options?.ignoreBorder,
|
|
|
|
createQuadrilaterals: true,
|
|
|
|
});
|
2017-08-31 15:18:53 +09:00
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
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 { data, linkService } = this;
|
|
|
|
const link = document.createElement("a");
|
2018-02-13 22:03:52 +09:00
|
|
|
|
2019-09-11 20:17:41 +09:00
|
|
|
if (data.url) {
|
2021-09-30 20:30:55 +09:00
|
|
|
if (
|
|
|
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
|
|
|
!linkService.addLinkAttributes
|
|
|
|
) {
|
|
|
|
warn(
|
|
|
|
"LinkAnnotationElement.render - missing `addLinkAttributes`-method on the `linkService`-instance."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
linkService.addLinkAttributes?.(link, data.url, data.newWindow);
|
2019-09-11 20:17:41 +09:00
|
|
|
} else if (data.action) {
|
|
|
|
this._bindNamedAction(link, data.action);
|
2020-09-07 00:14:56 +09:00
|
|
|
} else if (data.dest) {
|
2019-09-11 20:17:41 +09:00
|
|
|
this._bindLink(link, data.dest);
|
2020-09-07 00:14:56 +09:00
|
|
|
} else {
|
2021-09-27 04:04:11 +09:00
|
|
|
let hasClickAction = false;
|
|
|
|
if (
|
|
|
|
data.actions &&
|
|
|
|
(data.actions.Action ||
|
|
|
|
data.actions["Mouse Up"] ||
|
|
|
|
data.actions["Mouse Down"]) &&
|
|
|
|
this.enableScripting &&
|
|
|
|
this.hasJSActions
|
|
|
|
) {
|
|
|
|
hasClickAction = true;
|
|
|
|
this._bindJSAction(link, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.resetForm) {
|
|
|
|
this._bindResetFormAction(link, data.resetForm);
|
|
|
|
} else if (!hasClickAction) {
|
|
|
|
this._bindLink(link, "");
|
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2014-06-18 07:43:33 +09:00
|
|
|
|
2020-12-06 04:29:21 +09:00
|
|
|
if (this.quadrilaterals) {
|
|
|
|
return this._renderQuadrilaterals("linkAnnotation").map(
|
|
|
|
(quadrilateral, index) => {
|
|
|
|
const linkElement = index === 0 ? link : link.cloneNode();
|
|
|
|
quadrilateral.appendChild(linkElement);
|
|
|
|
return quadrilateral;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.container.className = "linkAnnotation";
|
2017-08-27 07:24:27 +09:00
|
|
|
this.container.appendChild(link);
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind internal links to the link element.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} link
|
|
|
|
* @param {Object} destination
|
|
|
|
* @memberof LinkAnnotationElement
|
|
|
|
*/
|
|
|
|
_bindLink(link, destination) {
|
|
|
|
link.href = this.linkService.getDestinationHash(destination);
|
|
|
|
link.onclick = () => {
|
2015-12-17 23:55:11 +09:00
|
|
|
if (destination) {
|
2020-10-04 00:43:33 +09:00
|
|
|
this.linkService.goToDestination(destination);
|
2015-12-09 07:38:32 +09:00
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
return false;
|
|
|
|
};
|
2020-10-23 21:19:39 +09:00
|
|
|
if (destination || destination === /* isTooltipOnly = */ "") {
|
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
|
|
|
link.className = "internalLink";
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
|
|
|
}
|
2015-12-09 07:38:32 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
/**
|
|
|
|
* Bind named actions to the link element.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} link
|
|
|
|
* @param {Object} action
|
|
|
|
* @memberof LinkAnnotationElement
|
|
|
|
*/
|
|
|
|
_bindNamedAction(link, action) {
|
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
|
|
|
link.href = this.linkService.getAnchorUrl("");
|
2017-08-27 07:24:27 +09:00
|
|
|
link.onclick = () => {
|
|
|
|
this.linkService.executeNamedAction(action);
|
|
|
|
return false;
|
|
|
|
};
|
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
|
|
|
link.className = "internalLink";
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2020-11-18 22:59:57 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind JS actions to the link element.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} link
|
|
|
|
* @param {Object} data
|
|
|
|
* @memberof LinkAnnotationElement
|
|
|
|
*/
|
2020-12-17 21:08:13 +09:00
|
|
|
_bindJSAction(link, data) {
|
|
|
|
link.href = this.linkService.getAnchorUrl("");
|
2020-11-18 22:59:57 +09:00
|
|
|
const map = new Map([
|
|
|
|
["Action", "onclick"],
|
2021-01-24 03:09:26 +09:00
|
|
|
["Mouse Up", "onmouseup"],
|
|
|
|
["Mouse Down", "onmousedown"],
|
2020-11-18 22:59:57 +09:00
|
|
|
]);
|
|
|
|
for (const name of Object.keys(data.actions)) {
|
|
|
|
const jsName = map.get(name);
|
|
|
|
if (!jsName) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
link[jsName] = () => {
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
|
|
|
source: this,
|
|
|
|
detail: {
|
|
|
|
id: data.id,
|
|
|
|
name,
|
|
|
|
},
|
|
|
|
});
|
2020-11-18 22:59:57 +09:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
2021-09-18 04:04:04 +09:00
|
|
|
|
|
|
|
if (!link.onclick) {
|
|
|
|
link.onclick = () => false;
|
|
|
|
}
|
2020-11-18 22:59:57 +09:00
|
|
|
link.className = "internalLink";
|
|
|
|
}
|
2021-09-27 04:04:11 +09:00
|
|
|
|
|
|
|
_bindResetFormAction(link, resetForm) {
|
|
|
|
const otherClickAction = link.onclick;
|
|
|
|
if (!otherClickAction) {
|
|
|
|
link.href = this.linkService.getAnchorUrl("");
|
|
|
|
}
|
|
|
|
link.className = "internalLink";
|
|
|
|
|
|
|
|
if (!this._fieldObjects) {
|
|
|
|
warn(
|
|
|
|
`_bindResetFormAction - "resetForm" action not supported, ` +
|
|
|
|
"ensure that the `fieldObjects` parameter is provided."
|
|
|
|
);
|
|
|
|
if (!otherClickAction) {
|
|
|
|
link.onclick = () => false;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
link.onclick = () => {
|
|
|
|
if (otherClickAction) {
|
|
|
|
otherClickAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
fields: resetFormFields,
|
|
|
|
refs: resetFormRefs,
|
|
|
|
include,
|
|
|
|
} = resetForm;
|
|
|
|
|
|
|
|
const allFields = [];
|
|
|
|
if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
|
|
|
|
const fieldIds = new Set(resetFormRefs);
|
|
|
|
for (const fieldName of resetFormFields) {
|
|
|
|
const fields = this._fieldObjects[fieldName] || [];
|
|
|
|
for (const { id } of fields) {
|
|
|
|
fieldIds.add(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const fields of Object.values(this._fieldObjects)) {
|
|
|
|
for (const field of fields) {
|
|
|
|
if (fieldIds.has(field.id) === include) {
|
|
|
|
allFields.push(field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (const fields of Object.values(this._fieldObjects)) {
|
|
|
|
allFields.push(...fields);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const storage = this.annotationStorage;
|
|
|
|
const allIds = [];
|
|
|
|
for (const field of allFields) {
|
|
|
|
const { id } = field;
|
|
|
|
allIds.push(id);
|
|
|
|
switch (field.type) {
|
|
|
|
case "text": {
|
|
|
|
const value = field.defaultValue || "";
|
|
|
|
storage.setValue(id, { value, valueAsString: value });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "checkbox":
|
|
|
|
case "radiobutton": {
|
|
|
|
const value = field.defaultValue === field.exportValues;
|
|
|
|
storage.setValue(id, { value });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "combobox":
|
|
|
|
case "listbox": {
|
|
|
|
const value = field.defaultValue || "";
|
|
|
|
storage.setValue(id, { value });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const domElement = document.getElementById(id);
|
|
|
|
if (!domElement || !GetElementsByNameSet.has(domElement)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
domElement.dispatchEvent(new Event("resetform"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.enableScripting) {
|
|
|
|
// Update the values in the sandbox.
|
|
|
|
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
|
|
|
source: this,
|
|
|
|
detail: {
|
|
|
|
id: "app",
|
|
|
|
ids: allIds,
|
|
|
|
name: "ResetForm",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2015-04-19 19:27:51 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class TextAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable });
|
2015-12-17 23:55:11 +09:00
|
|
|
}
|
2015-12-17 10:26:03 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
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
|
|
|
this.container.className = "textAnnotation";
|
2017-08-27 07:24:27 +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
|
|
|
const image = document.createElement("img");
|
2017-08-27 07:24:27 +09:00
|
|
|
image.style.height = this.container.style.height;
|
|
|
|
image.style.width = this.container.style.width;
|
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
|
|
|
image.src =
|
|
|
|
this.imageResourcesPath +
|
|
|
|
"annotation-" +
|
|
|
|
this.data.name.toLowerCase() +
|
|
|
|
".svg";
|
|
|
|
image.alt = "[{{type}} Annotation]";
|
|
|
|
image.dataset.l10nId = "text_annotation_type";
|
|
|
|
image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });
|
2017-08-27 07:24:27 +09:00
|
|
|
|
|
|
|
if (!this.data.hasPopup) {
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(image, this.data);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2015-12-17 23:55:11 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
this.container.appendChild(image);
|
|
|
|
return this.container;
|
2015-12-16 00:48:55 +09:00
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2015-12-16 00:48:55 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class WidgetAnnotationElement extends AnnotationElement {
|
|
|
|
render() {
|
|
|
|
// Show only the container for unsupported field types.
|
2020-09-07 00:14:56 +09:00
|
|
|
if (this.data.alternativeText) {
|
|
|
|
this.container.title = this.data.alternativeText;
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
return this.container;
|
|
|
|
}
|
2020-11-18 22:59:57 +09:00
|
|
|
|
|
|
|
_getKeyModifier(event) {
|
2021-07-27 16:25:36 +09:00
|
|
|
const { isWin, isMac } = AnnotationElement.platform;
|
|
|
|
return (isWin && event.ctrlKey) || (isMac && event.metaKey);
|
2020-11-18 22:59:57 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
_setEventListener(element, baseName, eventName, valueGetter) {
|
2020-12-17 21:08:13 +09:00
|
|
|
if (baseName.includes("mouse")) {
|
|
|
|
// Mouse events
|
|
|
|
element.addEventListener(baseName, event => {
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
|
|
|
source: this,
|
|
|
|
detail: {
|
|
|
|
id: this.data.id,
|
|
|
|
name: eventName,
|
|
|
|
value: valueGetter(event),
|
|
|
|
shift: event.shiftKey,
|
|
|
|
modifier: this._getKeyModifier(event),
|
|
|
|
},
|
|
|
|
});
|
2020-12-17 21:08:13 +09:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Non mouse event
|
|
|
|
element.addEventListener(baseName, event => {
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
|
|
|
source: this,
|
|
|
|
detail: {
|
|
|
|
id: this.data.id,
|
|
|
|
name: eventName,
|
|
|
|
value: event.target.checked,
|
|
|
|
},
|
|
|
|
});
|
2020-12-17 21:08:13 +09:00
|
|
|
});
|
2020-11-18 22:59:57 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_setEventListeners(element, names, getter) {
|
|
|
|
for (const [baseName, eventName] of names) {
|
2021-01-24 03:09:26 +09:00
|
|
|
if (eventName === "Action" || this.data.actions?.[eventName]) {
|
2021-01-09 00:43:16 +09:00
|
|
|
this._setEventListener(element, baseName, eventName, getter);
|
|
|
|
}
|
2020-11-18 22:59:57 +09:00
|
|
|
}
|
|
|
|
}
|
2021-02-20 23:23:54 +09:00
|
|
|
|
2021-09-19 03:22:29 +09:00
|
|
|
_setBackgroundColor(element) {
|
|
|
|
const color = this.data.backgroundColor || null;
|
|
|
|
element.style.backgroundColor =
|
|
|
|
color === null
|
|
|
|
? "transparent"
|
|
|
|
: Util.makeHexColor(color[0], color[1], color[2]);
|
|
|
|
}
|
|
|
|
|
2021-05-04 01:03:16 +09:00
|
|
|
_dispatchEventFromSandbox(actions, jsEvent) {
|
|
|
|
const setColor = (jsName, styleName, event) => {
|
|
|
|
const color = event.detail[jsName];
|
|
|
|
event.target.style[styleName] = ColorConverters[`${color[0]}_HTML`](
|
|
|
|
color.slice(1)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const commonActions = {
|
|
|
|
display: event => {
|
|
|
|
const hidden = event.detail.display % 2 === 1;
|
|
|
|
event.target.style.visibility = hidden ? "hidden" : "visible";
|
|
|
|
this.annotationStorage.setValue(this.data.id, {
|
|
|
|
hidden,
|
|
|
|
print: event.detail.display === 0 || event.detail.display === 3,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
print: event => {
|
|
|
|
this.annotationStorage.setValue(this.data.id, {
|
|
|
|
print: event.detail.print,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
hidden: event => {
|
|
|
|
event.target.style.visibility = event.detail.hidden
|
|
|
|
? "hidden"
|
|
|
|
: "visible";
|
|
|
|
this.annotationStorage.setValue(this.data.id, {
|
|
|
|
hidden: event.detail.hidden,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
focus: event => {
|
|
|
|
setTimeout(() => event.target.focus({ preventScroll: false }), 0);
|
|
|
|
},
|
|
|
|
userName: event => {
|
|
|
|
// tooltip
|
|
|
|
event.target.title = event.detail.userName;
|
|
|
|
},
|
|
|
|
readonly: event => {
|
|
|
|
if (event.detail.readonly) {
|
|
|
|
event.target.setAttribute("readonly", "");
|
|
|
|
} else {
|
|
|
|
event.target.removeAttribute("readonly");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
required: event => {
|
|
|
|
if (event.detail.required) {
|
|
|
|
event.target.setAttribute("required", "");
|
|
|
|
} else {
|
|
|
|
event.target.removeAttribute("required");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
bgColor: event => {
|
|
|
|
setColor("bgColor", "backgroundColor", event);
|
|
|
|
},
|
|
|
|
fillColor: event => {
|
|
|
|
setColor("fillColor", "backgroundColor", event);
|
|
|
|
},
|
|
|
|
fgColor: event => {
|
|
|
|
setColor("fgColor", "color", event);
|
|
|
|
},
|
|
|
|
textColor: event => {
|
|
|
|
setColor("textColor", "color", event);
|
|
|
|
},
|
|
|
|
borderColor: event => {
|
|
|
|
setColor("borderColor", "borderColor", event);
|
|
|
|
},
|
|
|
|
strokeColor: event => {
|
|
|
|
setColor("strokeColor", "borderColor", event);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const name of Object.keys(jsEvent.detail)) {
|
|
|
|
const action = actions[name] || commonActions[name];
|
|
|
|
if (action) {
|
|
|
|
action(jsEvent);
|
2021-02-20 23:23:54 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2016-09-12 00:04:33 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable =
|
[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
|
|
|
parameters.renderForms ||
|
2016-09-25 08:45:49 +09:00
|
|
|
(!parameters.data.hasAppearance && !!parameters.data.fieldValue);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable });
|
2016-09-06 06:46:52 +09:00
|
|
|
}
|
|
|
|
|
2021-04-21 01:32:23 +09:00
|
|
|
setPropertyOnSiblings(base, key, value, keyInStorage) {
|
|
|
|
const storage = this.annotationStorage;
|
2021-09-14 19:06:28 +09:00
|
|
|
for (const element of this._getElementsByName(
|
|
|
|
base.name,
|
|
|
|
/* skipId = */ base.id
|
|
|
|
)) {
|
|
|
|
if (element.domElement) {
|
|
|
|
element.domElement[key] = value;
|
2021-04-21 01:32:23 +09:00
|
|
|
}
|
2021-09-14 19:06:28 +09:00
|
|
|
storage.setValue(element.id, { [keyInStorage]: value });
|
2021-04-21 01:32:23 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
2020-08-05 21:40:31 +09:00
|
|
|
const storage = this.annotationStorage;
|
|
|
|
const id = this.data.id;
|
2017-08-27 07:24:27 +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
|
|
|
this.container.className = "textWidgetAnnotation";
|
2017-08-27 07:24:27 +09:00
|
|
|
|
|
|
|
let element = null;
|
[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
|
|
|
if (this.renderForms) {
|
2017-08-27 07:24:27 +09:00
|
|
|
// NOTE: We cannot set the values using `element.value` below, since it
|
|
|
|
// prevents the AnnotationLayer rasterizer in `test/driver.js`
|
|
|
|
// from parsing the elements correctly for the reference tests.
|
2021-03-31 00:50:35 +09:00
|
|
|
const storedData = storage.getValue(id, {
|
2020-11-04 00:04:08 +09:00
|
|
|
value: this.data.fieldValue,
|
2021-03-31 00:50:35 +09:00
|
|
|
valueAsString: this.data.fieldValue,
|
|
|
|
});
|
|
|
|
const textContent = storedData.valueAsString || storedData.value || "";
|
2020-11-18 22:59:57 +09:00
|
|
|
const elementData = {
|
|
|
|
userValue: null,
|
|
|
|
formattedValue: null,
|
|
|
|
beforeInputSelectionRange: null,
|
|
|
|
beforeInputValue: null,
|
|
|
|
};
|
2020-08-05 21:40:31 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
if (this.data.multiLine) {
|
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
|
|
|
element = document.createElement("textarea");
|
2020-08-05 21:40:31 +09:00
|
|
|
element.textContent = textContent;
|
2017-08-27 07:24:27 +09:00
|
|
|
} else {
|
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
|
|
|
element = document.createElement("input");
|
|
|
|
element.type = "text";
|
2020-08-05 21:40:31 +09:00
|
|
|
element.setAttribute("value", textContent);
|
2016-09-07 05:26:57 +09:00
|
|
|
}
|
2021-09-14 19:06:28 +09:00
|
|
|
GetElementsByNameSet.add(element);
|
|
|
|
element.disabled = this.data.readOnly;
|
|
|
|
element.name = this.data.fieldName;
|
2021-08-05 19:58:36 +09:00
|
|
|
element.tabIndex = DEFAULT_TAB_INDEX;
|
2016-09-12 00:04:33 +09:00
|
|
|
|
2020-11-18 22:59:57 +09:00
|
|
|
elementData.userValue = textContent;
|
2020-10-01 20:57:23 +09:00
|
|
|
element.setAttribute("id", id);
|
|
|
|
|
2021-04-21 01:32:23 +09:00
|
|
|
element.addEventListener("input", event => {
|
2020-11-04 00:04:08 +09:00
|
|
|
storage.setValue(id, { value: event.target.value });
|
2021-04-21 01:32:23 +09:00
|
|
|
this.setPropertyOnSiblings(
|
|
|
|
element,
|
|
|
|
"value",
|
|
|
|
event.target.value,
|
|
|
|
"value"
|
|
|
|
);
|
2020-08-05 21:40:31 +09:00
|
|
|
});
|
|
|
|
|
2021-09-27 04:04:11 +09:00
|
|
|
element.addEventListener("resetform", event => {
|
|
|
|
const defaultValue = this.data.defaultFieldValue || "";
|
|
|
|
element.value = elementData.userValue = defaultValue;
|
|
|
|
delete elementData.formattedValue;
|
|
|
|
});
|
|
|
|
|
2020-11-18 22:59:57 +09:00
|
|
|
let blurListener = event => {
|
|
|
|
if (elementData.formattedValue) {
|
|
|
|
event.target.value = elementData.formattedValue;
|
|
|
|
}
|
2021-04-14 03:40:52 +09:00
|
|
|
// Reset the cursor position to the start of the field (issue 12359).
|
|
|
|
event.target.scrollLeft = 0;
|
2020-11-18 22:59:57 +09:00
|
|
|
elementData.beforeInputSelectionRange = null;
|
|
|
|
};
|
2020-09-10 17:37:13 +09:00
|
|
|
|
2020-10-29 03:16:56 +09:00
|
|
|
if (this.enableScripting && this.hasJSActions) {
|
2020-11-04 03:24:07 +09:00
|
|
|
element.addEventListener("focus", event => {
|
2020-11-18 22:59:57 +09:00
|
|
|
if (elementData.userValue) {
|
|
|
|
event.target.value = elementData.userValue;
|
2020-10-01 20:57:23 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-05-04 01:03:16 +09:00
|
|
|
element.addEventListener("updatefromsandbox", jsEvent => {
|
2020-11-18 22:59:57 +09:00
|
|
|
const actions = {
|
2021-05-04 01:03:16 +09:00
|
|
|
value(event) {
|
|
|
|
elementData.userValue = event.detail.value || "";
|
2020-11-18 22:59:57 +09:00
|
|
|
storage.setValue(id, { value: elementData.userValue.toString() });
|
2020-11-19 02:54:26 +09:00
|
|
|
if (!elementData.formattedValue) {
|
|
|
|
event.target.value = elementData.userValue;
|
|
|
|
}
|
2020-11-18 22:59:57 +09:00
|
|
|
},
|
2021-05-04 01:03:16 +09:00
|
|
|
valueAsString(event) {
|
|
|
|
elementData.formattedValue = event.detail.valueAsString || "";
|
2020-11-18 22:59:57 +09:00
|
|
|
if (event.target !== document.activeElement) {
|
|
|
|
// Input hasn't the focus so display formatted string
|
|
|
|
event.target.value = elementData.formattedValue;
|
2020-11-04 03:24:07 +09:00
|
|
|
}
|
2020-11-18 22:59:57 +09:00
|
|
|
storage.setValue(id, {
|
|
|
|
formattedValue: elementData.formattedValue,
|
|
|
|
});
|
|
|
|
},
|
2021-05-04 01:03:16 +09:00
|
|
|
selRange(event) {
|
|
|
|
const [selStart, selEnd] = event.detail.selRange;
|
2020-11-18 22:59:57 +09:00
|
|
|
if (selStart >= 0 && selEnd < event.target.value.length) {
|
|
|
|
event.target.setSelectionRange(selStart, selEnd);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
2021-05-04 01:03:16 +09:00
|
|
|
this._dispatchEventFromSandbox(actions, jsEvent);
|
2020-11-18 22:59:57 +09:00
|
|
|
});
|
|
|
|
|
2021-01-26 07:40:57 +09:00
|
|
|
// Even if the field hasn't any actions
|
|
|
|
// leaving it can still trigger some actions with Calculate
|
|
|
|
element.addEventListener("keydown", event => {
|
|
|
|
elementData.beforeInputValue = event.target.value;
|
|
|
|
// if the key is one of Escape, Enter or Tab
|
|
|
|
// then the data are committed
|
|
|
|
let commitKey = -1;
|
|
|
|
if (event.key === "Escape") {
|
|
|
|
commitKey = 0;
|
|
|
|
} else if (event.key === "Enter") {
|
|
|
|
commitKey = 2;
|
|
|
|
} else if (event.key === "Tab") {
|
|
|
|
commitKey = 3;
|
|
|
|
}
|
|
|
|
if (commitKey === -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Save the entered value
|
|
|
|
elementData.userValue = event.target.value;
|
|
|
|
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
|
|
|
source: this,
|
|
|
|
detail: {
|
|
|
|
id,
|
|
|
|
name: "Keystroke",
|
|
|
|
value: event.target.value,
|
|
|
|
willCommit: true,
|
|
|
|
commitKey,
|
|
|
|
selStart: event.target.selectionStart,
|
|
|
|
selEnd: event.target.selectionEnd,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const _blurListener = blurListener;
|
|
|
|
blurListener = null;
|
|
|
|
element.addEventListener("blur", event => {
|
|
|
|
if (this._mouseState.isDown) {
|
|
|
|
// Focus out using the mouse: data are committed
|
2020-11-18 22:59:57 +09:00
|
|
|
elementData.userValue = event.target.value;
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
|
|
|
source: this,
|
|
|
|
detail: {
|
|
|
|
id,
|
|
|
|
name: "Keystroke",
|
|
|
|
value: event.target.value,
|
|
|
|
willCommit: true,
|
2021-01-26 07:40:57 +09:00
|
|
|
commitKey: 1,
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
selStart: event.target.selectionStart,
|
|
|
|
selEnd: event.target.selectionEnd,
|
|
|
|
},
|
|
|
|
});
|
2021-01-26 07:40:57 +09:00
|
|
|
}
|
|
|
|
_blurListener(event);
|
|
|
|
});
|
|
|
|
element.addEventListener("mousedown", event => {
|
|
|
|
elementData.beforeInputValue = event.target.value;
|
|
|
|
elementData.beforeInputSelectionRange = null;
|
|
|
|
});
|
|
|
|
element.addEventListener("keyup", event => {
|
|
|
|
// keyup is triggered after input
|
|
|
|
if (event.target.selectionStart === event.target.selectionEnd) {
|
2020-11-18 22:59:57 +09:00
|
|
|
elementData.beforeInputSelectionRange = null;
|
2020-10-01 20:57:23 +09:00
|
|
|
}
|
2021-01-26 07:40:57 +09:00
|
|
|
});
|
|
|
|
element.addEventListener("select", event => {
|
|
|
|
elementData.beforeInputSelectionRange = [
|
|
|
|
event.target.selectionStart,
|
|
|
|
event.target.selectionEnd,
|
|
|
|
];
|
|
|
|
});
|
2020-11-18 22:59:57 +09:00
|
|
|
|
2021-01-26 07:40:57 +09:00
|
|
|
if (this.data.actions?.Keystroke) {
|
|
|
|
// We should use beforeinput but this
|
|
|
|
// event isn't available in Firefox
|
|
|
|
element.addEventListener("input", event => {
|
|
|
|
let selStart = -1;
|
|
|
|
let selEnd = -1;
|
|
|
|
if (elementData.beforeInputSelectionRange) {
|
|
|
|
[selStart, selEnd] = elementData.beforeInputSelectionRange;
|
|
|
|
}
|
|
|
|
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
|
|
|
source: this,
|
|
|
|
detail: {
|
|
|
|
id,
|
|
|
|
name: "Keystroke",
|
|
|
|
value: elementData.beforeInputValue,
|
|
|
|
change: event.data,
|
|
|
|
willCommit: false,
|
|
|
|
selStart,
|
|
|
|
selEnd,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2020-10-01 20:57:23 +09:00
|
|
|
}
|
2021-01-26 07:40:57 +09:00
|
|
|
|
|
|
|
this._setEventListeners(
|
|
|
|
element,
|
|
|
|
[
|
|
|
|
["focus", "Focus"],
|
|
|
|
["blur", "Blur"],
|
|
|
|
["mousedown", "Mouse Down"],
|
|
|
|
["mouseenter", "Mouse Enter"],
|
|
|
|
["mouseleave", "Mouse Exit"],
|
|
|
|
["mouseup", "Mouse Up"],
|
|
|
|
],
|
|
|
|
event => event.target.value
|
|
|
|
);
|
2020-10-01 20:57:23 +09:00
|
|
|
}
|
|
|
|
|
2020-11-18 22:59:57 +09:00
|
|
|
if (blurListener) {
|
|
|
|
element.addEventListener("blur", blurListener);
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
if (this.data.maxLen !== null) {
|
|
|
|
element.maxLength = this.data.maxLen;
|
2015-12-16 00:48:55 +09:00
|
|
|
}
|
2015-12-17 23:55:11 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
if (this.data.comb) {
|
2019-08-31 23:40:39 +09:00
|
|
|
const fieldWidth = this.data.rect[2] - this.data.rect[0];
|
|
|
|
const combWidth = fieldWidth / this.data.maxLen;
|
2015-12-17 23:55:11 +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
|
|
|
element.classList.add("comb");
|
2019-08-31 23:40:39 +09:00
|
|
|
element.style.letterSpacing = `calc(${combWidth}px - 1ch)`;
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
|
|
|
} else {
|
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
|
|
|
element = document.createElement("div");
|
2017-08-27 07:24:27 +09:00
|
|
|
element.textContent = this.data.fieldValue;
|
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
|
|
|
element.style.verticalAlign = "middle";
|
|
|
|
element.style.display = "table-cell";
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2015-12-16 00:48:55 +09:00
|
|
|
|
2021-01-22 06:33:43 +09:00
|
|
|
this._setTextStyle(element);
|
2021-09-19 03:22:29 +09:00
|
|
|
this._setBackgroundColor(element);
|
2015-12-17 23:55:11 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
this.container.appendChild(element);
|
|
|
|
return this.container;
|
2016-11-04 21:01:42 +09:00
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
/**
|
|
|
|
* Apply text styles to the text in the element.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {HTMLDivElement} element
|
|
|
|
* @memberof TextWidgetAnnotationElement
|
|
|
|
*/
|
2021-01-22 06:33:43 +09:00
|
|
|
_setTextStyle(element) {
|
|
|
|
const TEXT_ALIGNMENT = ["left", "center", "right"];
|
|
|
|
const { fontSize, fontColor } = this.data.defaultAppearanceData;
|
2019-08-31 23:40:39 +09:00
|
|
|
const style = element.style;
|
2017-08-27 07:24:27 +09:00
|
|
|
|
2021-01-22 06:33:43 +09:00
|
|
|
// TODO: If the font-size is zero, calculate it based on the height and
|
|
|
|
// width of the element.
|
|
|
|
// Not setting `style.fontSize` will use the default font-size for now.
|
|
|
|
if (fontSize) {
|
|
|
|
style.fontSize = `${fontSize}px`;
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2016-11-04 21:01:42 +09:00
|
|
|
|
2021-01-22 06:33:43 +09:00
|
|
|
style.color = Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
|
2016-11-04 21:01:42 +09:00
|
|
|
|
2021-01-22 06:33:43 +09:00
|
|
|
if (this.data.textAlignment !== null) {
|
|
|
|
style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
|
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
|
|
|
}
|
2016-11-04 21:01:42 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
|
|
|
|
constructor(parameters) {
|
[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
|
|
|
super(parameters, { isRenderable: parameters.renderForms });
|
2016-11-04 21:01:42 +09:00
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
2020-07-23 00:10:59 +09:00
|
|
|
const storage = this.annotationStorage;
|
|
|
|
const data = this.data;
|
|
|
|
const id = data.id;
|
2021-04-21 02:21:52 +09:00
|
|
|
let value = storage.getValue(id, {
|
2021-09-17 22:31:22 +09:00
|
|
|
value: data.exportValue === data.fieldValue,
|
2020-11-04 00:04:08 +09:00
|
|
|
}).value;
|
2021-04-21 02:21:52 +09:00
|
|
|
if (typeof value === "string") {
|
|
|
|
// The value has been changed through js and set in annotationStorage.
|
|
|
|
value = value !== "Off";
|
|
|
|
storage.setValue(id, { value });
|
|
|
|
}
|
2020-07-23 00:10:59 +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
|
|
|
this.container.className = "buttonWidgetAnnotation checkBox";
|
2017-08-27 07:24:27 +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
|
|
|
const element = document.createElement("input");
|
2021-09-14 19:06:28 +09:00
|
|
|
GetElementsByNameSet.add(element);
|
2020-07-23 00:10:59 +09:00
|
|
|
element.disabled = data.readOnly;
|
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
|
|
|
element.type = "checkbox";
|
2021-09-15 22:13:40 +09:00
|
|
|
element.name = data.fieldName;
|
2020-07-23 00:10:59 +09:00
|
|
|
if (value) {
|
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
|
|
|
element.setAttribute("checked", true);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2020-11-18 22:59:57 +09:00
|
|
|
element.setAttribute("id", id);
|
2021-09-15 22:13:40 +09:00
|
|
|
element.setAttribute("exportValue", data.exportValue);
|
2021-08-05 19:58:36 +09:00
|
|
|
element.tabIndex = DEFAULT_TAB_INDEX;
|
2016-11-04 21:01:42 +09:00
|
|
|
|
2021-09-14 19:06:28 +09:00
|
|
|
element.addEventListener("change", event => {
|
|
|
|
const { name, checked } = event.target;
|
|
|
|
for (const checkbox of this._getElementsByName(name, /* skipId = */ id)) {
|
|
|
|
const curChecked = checked && checkbox.exportValue === data.exportValue;
|
|
|
|
if (checkbox.domElement) {
|
|
|
|
checkbox.domElement.checked = curChecked;
|
2020-12-08 23:50:16 +09:00
|
|
|
}
|
2021-09-14 19:06:28 +09:00
|
|
|
storage.setValue(checkbox.id, { value: curChecked });
|
2020-12-08 23:50:16 +09:00
|
|
|
}
|
2021-09-15 22:13:40 +09:00
|
|
|
storage.setValue(id, { value: checked });
|
2020-07-23 00:10:59 +09:00
|
|
|
});
|
|
|
|
|
2021-09-27 04:04:11 +09:00
|
|
|
element.addEventListener("resetform", event => {
|
|
|
|
const defaultValue = data.defaultFieldValue || "Off";
|
|
|
|
event.target.checked = defaultValue === data.exportValue;
|
|
|
|
});
|
|
|
|
|
2020-11-18 22:59:57 +09:00
|
|
|
if (this.enableScripting && this.hasJSActions) {
|
2021-05-04 01:03:16 +09:00
|
|
|
element.addEventListener("updatefromsandbox", jsEvent => {
|
2020-11-18 22:59:57 +09:00
|
|
|
const actions = {
|
2021-05-04 01:03:16 +09:00
|
|
|
value(event) {
|
|
|
|
event.target.checked = event.detail.value !== "Off";
|
2020-11-18 22:59:57 +09:00
|
|
|
storage.setValue(id, { value: event.target.checked });
|
|
|
|
},
|
|
|
|
};
|
2021-05-04 01:03:16 +09:00
|
|
|
this._dispatchEventFromSandbox(actions, jsEvent);
|
2020-11-18 22:59:57 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
this._setEventListeners(
|
|
|
|
element,
|
|
|
|
[
|
|
|
|
["change", "Validate"],
|
|
|
|
["change", "Action"],
|
|
|
|
["focus", "Focus"],
|
|
|
|
["blur", "Blur"],
|
|
|
|
["mousedown", "Mouse Down"],
|
|
|
|
["mouseenter", "Mouse Enter"],
|
|
|
|
["mouseleave", "Mouse Exit"],
|
2021-01-24 03:09:26 +09:00
|
|
|
["mouseup", "Mouse Up"],
|
2020-11-18 22:59:57 +09:00
|
|
|
],
|
|
|
|
event => event.target.checked
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-19 03:22:29 +09:00
|
|
|
this._setBackgroundColor(element);
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
this.container.appendChild(element);
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
2016-11-04 21:01:42 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
|
|
|
|
constructor(parameters) {
|
[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
|
|
|
super(parameters, { isRenderable: parameters.renderForms });
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2016-11-04 21:01:42 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
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
|
|
|
this.container.className = "buttonWidgetAnnotation radioButton";
|
2020-07-23 00:29:35 +09:00
|
|
|
const storage = this.annotationStorage;
|
|
|
|
const data = this.data;
|
|
|
|
const id = data.id;
|
2021-04-21 02:21:52 +09:00
|
|
|
let value = storage.getValue(id, {
|
2020-11-04 00:04:08 +09:00
|
|
|
value: data.fieldValue === data.buttonValue,
|
|
|
|
}).value;
|
2021-04-21 02:21:52 +09:00
|
|
|
if (typeof value === "string") {
|
|
|
|
// The value has been changed through js and set in annotationStorage.
|
|
|
|
value = value !== data.buttonValue;
|
|
|
|
storage.setValue(id, { value });
|
|
|
|
}
|
2017-08-27 07:24:27 +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
|
|
|
const element = document.createElement("input");
|
2021-09-14 19:06:28 +09:00
|
|
|
GetElementsByNameSet.add(element);
|
2020-07-23 00:29:35 +09:00
|
|
|
element.disabled = data.readOnly;
|
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
|
|
|
element.type = "radio";
|
2020-07-23 00:29:35 +09:00
|
|
|
element.name = data.fieldName;
|
|
|
|
if (value) {
|
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
|
|
|
element.setAttribute("checked", true);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2020-11-18 22:59:57 +09:00
|
|
|
element.setAttribute("id", id);
|
2021-08-05 19:58:36 +09:00
|
|
|
element.tabIndex = DEFAULT_TAB_INDEX;
|
2017-08-27 07:24:27 +09:00
|
|
|
|
2021-09-14 19:06:28 +09:00
|
|
|
element.addEventListener("change", event => {
|
|
|
|
const { name, checked } = event.target;
|
|
|
|
for (const radio of this._getElementsByName(name, /* skipId = */ id)) {
|
|
|
|
storage.setValue(radio.id, { value: false });
|
2020-07-23 00:29:35 +09:00
|
|
|
}
|
2021-09-14 19:06:28 +09:00
|
|
|
storage.setValue(id, { value: checked });
|
2020-07-23 00:29:35 +09:00
|
|
|
});
|
|
|
|
|
2021-09-27 04:04:11 +09:00
|
|
|
element.addEventListener("resetform", event => {
|
|
|
|
const defaultValue = data.defaultFieldValue;
|
|
|
|
event.target.checked =
|
|
|
|
defaultValue !== null &&
|
|
|
|
defaultValue !== undefined &&
|
|
|
|
defaultValue === data.buttonValue;
|
|
|
|
});
|
|
|
|
|
2020-11-18 22:59:57 +09:00
|
|
|
if (this.enableScripting && this.hasJSActions) {
|
2021-03-07 01:19:57 +09:00
|
|
|
const pdfButtonValue = data.buttonValue;
|
2021-05-04 01:03:16 +09:00
|
|
|
element.addEventListener("updatefromsandbox", jsEvent => {
|
2020-11-18 22:59:57 +09:00
|
|
|
const actions = {
|
2021-09-14 19:06:28 +09:00
|
|
|
value: event => {
|
2021-05-04 01:03:16 +09:00
|
|
|
const checked = pdfButtonValue === event.detail.value;
|
2021-09-14 19:06:28 +09:00
|
|
|
for (const radio of this._getElementsByName(event.target.name)) {
|
|
|
|
const curChecked = checked && radio.id === id;
|
|
|
|
if (radio.domElement) {
|
|
|
|
radio.domElement.checked = curChecked;
|
|
|
|
}
|
|
|
|
storage.setValue(radio.id, { value: curChecked });
|
2020-11-18 22:59:57 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
2021-05-04 01:03:16 +09:00
|
|
|
this._dispatchEventFromSandbox(actions, jsEvent);
|
2020-11-18 22:59:57 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
this._setEventListeners(
|
|
|
|
element,
|
|
|
|
[
|
|
|
|
["change", "Validate"],
|
|
|
|
["change", "Action"],
|
|
|
|
["focus", "Focus"],
|
|
|
|
["blur", "Blur"],
|
|
|
|
["mousedown", "Mouse Down"],
|
|
|
|
["mouseenter", "Mouse Enter"],
|
|
|
|
["mouseleave", "Mouse Exit"],
|
2021-01-24 03:09:26 +09:00
|
|
|
["mouseup", "Mouse Up"],
|
2020-11-18 22:59:57 +09:00
|
|
|
],
|
|
|
|
event => event.target.checked
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-19 03:22:29 +09:00
|
|
|
this._setBackgroundColor(element);
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
this.container.appendChild(element);
|
|
|
|
return this.container;
|
2016-09-25 08:45:49 +09:00
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2016-09-25 08:45:49 +09:00
|
|
|
|
2017-11-21 07:00:19 +09:00
|
|
|
class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
|
2021-10-21 20:31:16 +09:00
|
|
|
constructor(parameters) {
|
|
|
|
super(parameters, { ignoreBorder: parameters.data.hasAppearance });
|
|
|
|
}
|
|
|
|
|
2017-11-21 07:00:19 +09:00
|
|
|
render() {
|
|
|
|
// The rendering and functionality of a push button widget annotation is
|
|
|
|
// equal to that of a link annotation, but may have more functionality, such
|
|
|
|
// as performing actions on form fields (resetting, submitting, et cetera).
|
2019-08-31 23:40:39 +09:00
|
|
|
const container = super.render();
|
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
|
|
|
container.className = "buttonWidgetAnnotation pushButton";
|
2020-09-07 00:14:56 +09:00
|
|
|
|
|
|
|
if (this.data.alternativeText) {
|
|
|
|
container.title = this.data.alternativeText;
|
|
|
|
}
|
|
|
|
|
2017-11-21 07:00:19 +09:00
|
|
|
return container;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
|
|
|
|
constructor(parameters) {
|
[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
|
|
|
super(parameters, { isRenderable: parameters.renderForms });
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2016-09-25 08:45:49 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
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
|
|
|
this.container.className = "choiceWidgetAnnotation";
|
2020-08-05 21:40:31 +09:00
|
|
|
const storage = this.annotationStorage;
|
|
|
|
const id = this.data.id;
|
2016-09-25 08:45:49 +09:00
|
|
|
|
2020-08-22 21:29:00 +09:00
|
|
|
// For printing/saving we currently only support choice widgets with one
|
|
|
|
// option selection. Therefore, listboxes (#12189) and comboboxes (#12224)
|
|
|
|
// are not properly printed/saved yet, so we only store the first item in
|
|
|
|
// the field value array instead of the entire array. Once support for those
|
|
|
|
// two field types is implemented, we should use the same pattern as the
|
2020-12-20 02:12:44 +09:00
|
|
|
// other interactive widgets where the return value of `getValue`
|
|
|
|
// is used and the full array of field values is stored.
|
|
|
|
storage.getValue(id, {
|
2020-11-04 00:04:08 +09:00
|
|
|
value:
|
|
|
|
this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : undefined,
|
|
|
|
});
|
2020-08-22 21:29:00 +09:00
|
|
|
|
2021-08-04 21:42:24 +09:00
|
|
|
let { fontSize } = this.data.defaultAppearanceData;
|
|
|
|
if (!fontSize) {
|
|
|
|
fontSize = 9;
|
|
|
|
}
|
|
|
|
const fontSizeStyle = `calc(${fontSize}px * var(--zoom-factor))`;
|
|
|
|
|
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 selectElement = document.createElement("select");
|
2021-09-14 19:06:28 +09:00
|
|
|
GetElementsByNameSet.add(selectElement);
|
2017-08-27 07:24:27 +09:00
|
|
|
selectElement.disabled = this.data.readOnly;
|
2020-04-27 23:51:18 +09:00
|
|
|
selectElement.name = this.data.fieldName;
|
2020-11-18 22:59:57 +09:00
|
|
|
selectElement.setAttribute("id", id);
|
2021-08-05 19:58:36 +09:00
|
|
|
selectElement.tabIndex = DEFAULT_TAB_INDEX;
|
2016-09-25 08:45:49 +09:00
|
|
|
|
2021-08-04 21:42:24 +09:00
|
|
|
selectElement.style.fontSize = `${fontSize}px`;
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
if (!this.data.combo) {
|
|
|
|
// List boxes have a size and (optionally) multiple selection.
|
|
|
|
selectElement.size = this.data.options.length;
|
|
|
|
if (this.data.multiSelect) {
|
|
|
|
selectElement.multiple = true;
|
2016-09-25 08:45:49 +09:00
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2016-09-25 08:45:49 +09:00
|
|
|
|
2021-09-27 04:04:11 +09:00
|
|
|
selectElement.addEventListener("resetform", event => {
|
|
|
|
const defaultValue = this.data.defaultFieldValue;
|
|
|
|
for (const option of selectElement.options) {
|
|
|
|
option.selected = option.value === defaultValue;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
// Insert the options into the choice field.
|
2019-08-31 23:40:39 +09:00
|
|
|
for (const option of this.data.options) {
|
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 optionElement = document.createElement("option");
|
2017-08-27 07:24:27 +09:00
|
|
|
optionElement.textContent = option.displayValue;
|
|
|
|
optionElement.value = option.exportValue;
|
2021-08-04 21:42:24 +09:00
|
|
|
if (this.data.combo) {
|
|
|
|
optionElement.style.fontSize = fontSizeStyle;
|
|
|
|
}
|
2020-08-22 20:57:12 +09:00
|
|
|
if (this.data.fieldValue.includes(option.exportValue)) {
|
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
|
|
|
optionElement.setAttribute("selected", true);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
|
|
|
selectElement.appendChild(optionElement);
|
|
|
|
}
|
|
|
|
|
2021-01-26 07:40:57 +09:00
|
|
|
const getValue = (event, isExport) => {
|
|
|
|
const name = isExport ? "value" : "textContent";
|
2020-08-05 21:40:31 +09:00
|
|
|
const options = event.target.options;
|
2021-01-26 07:40:57 +09:00
|
|
|
if (!event.target.multiple) {
|
|
|
|
return options.selectedIndex === -1
|
|
|
|
? null
|
|
|
|
: options[options.selectedIndex][name];
|
|
|
|
}
|
|
|
|
return Array.prototype.filter
|
|
|
|
.call(options, option => option.selected)
|
|
|
|
.map(option => option[name]);
|
|
|
|
};
|
|
|
|
|
|
|
|
const getItems = event => {
|
|
|
|
const options = event.target.options;
|
|
|
|
return Array.prototype.map.call(options, option => {
|
|
|
|
return { displayValue: option.textContent, exportValue: option.value };
|
|
|
|
});
|
|
|
|
};
|
2020-11-18 22:59:57 +09:00
|
|
|
|
|
|
|
if (this.enableScripting && this.hasJSActions) {
|
2021-05-04 01:03:16 +09:00
|
|
|
selectElement.addEventListener("updatefromsandbox", jsEvent => {
|
2020-11-18 22:59:57 +09:00
|
|
|
const actions = {
|
2021-05-04 01:03:16 +09:00
|
|
|
value(event) {
|
|
|
|
const value = event.detail.value;
|
2021-01-26 07:40:57 +09:00
|
|
|
const values = new Set(Array.isArray(value) ? value : [value]);
|
2021-10-01 16:06:17 +09:00
|
|
|
for (const option of selectElement.options) {
|
2021-01-26 07:40:57 +09:00
|
|
|
option.selected = values.has(option.value);
|
2021-10-01 16:06:17 +09:00
|
|
|
}
|
2021-01-26 07:40:57 +09:00
|
|
|
storage.setValue(id, {
|
|
|
|
value: getValue(event, /* isExport */ true),
|
|
|
|
});
|
|
|
|
},
|
2021-05-04 01:03:16 +09:00
|
|
|
multipleSelection(event) {
|
2021-01-26 07:40:57 +09:00
|
|
|
selectElement.multiple = true;
|
|
|
|
},
|
2021-05-04 01:03:16 +09:00
|
|
|
remove(event) {
|
2021-01-26 07:40:57 +09:00
|
|
|
const options = selectElement.options;
|
2021-05-04 01:03:16 +09:00
|
|
|
const index = event.detail.remove;
|
2021-01-26 07:40:57 +09:00
|
|
|
options[index].selected = false;
|
|
|
|
selectElement.remove(index);
|
|
|
|
if (options.length > 0) {
|
|
|
|
const i = Array.prototype.findIndex.call(
|
|
|
|
options,
|
|
|
|
option => option.selected
|
|
|
|
);
|
|
|
|
if (i === -1) {
|
|
|
|
options[0].selected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
storage.setValue(id, {
|
|
|
|
value: getValue(event, /* isExport */ true),
|
|
|
|
items: getItems(event),
|
|
|
|
});
|
|
|
|
},
|
2021-05-04 01:03:16 +09:00
|
|
|
clear(event) {
|
2021-01-26 07:40:57 +09:00
|
|
|
while (selectElement.length !== 0) {
|
|
|
|
selectElement.remove(0);
|
|
|
|
}
|
|
|
|
storage.setValue(id, { value: null, items: [] });
|
|
|
|
},
|
2021-05-04 01:03:16 +09:00
|
|
|
insert(event) {
|
|
|
|
const { index, displayValue, exportValue } = event.detail.insert;
|
2021-01-26 07:40:57 +09:00
|
|
|
const optionElement = document.createElement("option");
|
|
|
|
optionElement.textContent = displayValue;
|
|
|
|
optionElement.value = exportValue;
|
|
|
|
selectElement.insertBefore(
|
|
|
|
optionElement,
|
|
|
|
selectElement.children[index]
|
|
|
|
);
|
|
|
|
storage.setValue(id, {
|
|
|
|
value: getValue(event, /* isExport */ true),
|
|
|
|
items: getItems(event),
|
|
|
|
});
|
|
|
|
},
|
2021-05-04 01:03:16 +09:00
|
|
|
items(event) {
|
|
|
|
const { items } = event.detail;
|
2021-01-26 07:40:57 +09:00
|
|
|
while (selectElement.length !== 0) {
|
|
|
|
selectElement.remove(0);
|
|
|
|
}
|
|
|
|
for (const item of items) {
|
|
|
|
const { displayValue, exportValue } = item;
|
|
|
|
const optionElement = document.createElement("option");
|
|
|
|
optionElement.textContent = displayValue;
|
|
|
|
optionElement.value = exportValue;
|
|
|
|
selectElement.appendChild(optionElement);
|
2020-11-18 22:59:57 +09:00
|
|
|
}
|
2021-01-26 07:40:57 +09:00
|
|
|
if (selectElement.options.length > 0) {
|
|
|
|
selectElement.options[0].selected = true;
|
|
|
|
}
|
|
|
|
storage.setValue(id, {
|
|
|
|
value: getValue(event, /* isExport */ true),
|
|
|
|
items: getItems(event),
|
|
|
|
});
|
|
|
|
},
|
2021-05-04 01:03:16 +09:00
|
|
|
indices(event) {
|
|
|
|
const indices = new Set(event.detail.indices);
|
2021-10-01 16:06:17 +09:00
|
|
|
for (const option of event.target.options) {
|
|
|
|
option.selected = indices.has(option.index);
|
|
|
|
}
|
2021-01-26 07:40:57 +09:00
|
|
|
storage.setValue(id, {
|
|
|
|
value: getValue(event, /* isExport */ true),
|
|
|
|
});
|
2020-11-18 22:59:57 +09:00
|
|
|
},
|
2021-05-04 01:03:16 +09:00
|
|
|
editable(event) {
|
|
|
|
event.target.disabled = !event.detail.editable;
|
2020-11-18 22:59:57 +09:00
|
|
|
},
|
|
|
|
};
|
2021-05-04 01:03:16 +09:00
|
|
|
this._dispatchEventFromSandbox(actions, jsEvent);
|
2020-11-18 22:59:57 +09:00
|
|
|
});
|
|
|
|
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
selectElement.addEventListener("input", event => {
|
2021-01-26 07:40:57 +09:00
|
|
|
const exportValue = getValue(event, /* isExport */ true);
|
|
|
|
const value = getValue(event, /* isExport */ false);
|
|
|
|
storage.setValue(id, { value: exportValue });
|
2020-11-18 22:59:57 +09:00
|
|
|
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
|
|
|
|
source: this,
|
|
|
|
detail: {
|
|
|
|
id,
|
|
|
|
name: "Keystroke",
|
2021-01-26 07:40:57 +09:00
|
|
|
value,
|
|
|
|
changeEx: exportValue,
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
willCommit: true,
|
|
|
|
commitKey: 1,
|
|
|
|
keyDown: false,
|
|
|
|
},
|
|
|
|
});
|
2020-11-18 22:59:57 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
this._setEventListeners(
|
|
|
|
selectElement,
|
|
|
|
[
|
|
|
|
["focus", "Focus"],
|
|
|
|
["blur", "Blur"],
|
|
|
|
["mousedown", "Mouse Down"],
|
|
|
|
["mouseenter", "Mouse Enter"],
|
|
|
|
["mouseleave", "Mouse Exit"],
|
2021-01-24 03:09:26 +09:00
|
|
|
["mouseup", "Mouse Up"],
|
2021-01-26 07:40:57 +09:00
|
|
|
["input", "Action"],
|
2020-11-18 22:59:57 +09:00
|
|
|
],
|
|
|
|
event => event.target.checked
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
selectElement.addEventListener("input", function (event) {
|
|
|
|
storage.setValue(id, { value: getValue(event) });
|
|
|
|
});
|
|
|
|
}
|
2020-08-05 21:40:31 +09:00
|
|
|
|
2021-09-19 03:22:29 +09:00
|
|
|
this._setBackgroundColor(selectElement);
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
this.container.appendChild(selectElement);
|
|
|
|
return this.container;
|
2015-12-23 05:31:56 +09:00
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2015-12-23 05:31:56 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class PopupAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
2021-09-25 00:30:56 +09:00
|
|
|
const isRenderable = !!(
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
2021-09-25 00:30:56 +09:00
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable });
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2017-04-03 03:50:17 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
|
|
|
// Do not render popup annotations for parent elements with these types as
|
|
|
|
// they create the popups themselves (because of custom trigger divs).
|
2018-09-30 23:29:16 +09:00
|
|
|
const IGNORE_TYPES = [
|
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
|
|
|
"Line",
|
|
|
|
"Square",
|
|
|
|
"Circle",
|
|
|
|
"PolyLine",
|
|
|
|
"Polygon",
|
|
|
|
"Ink",
|
2018-09-30 23:29:16 +09:00
|
|
|
];
|
2015-12-23 05:31: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
|
|
|
this.container.className = "popupAnnotation";
|
2015-12-23 05:31:56 +09:00
|
|
|
|
2018-02-04 22:50:58 +09:00
|
|
|
if (IGNORE_TYPES.includes(this.data.parentType)) {
|
2017-08-27 07:24:27 +09:00
|
|
|
return this.container;
|
|
|
|
}
|
2015-12-23 05:31:56 +09:00
|
|
|
|
2019-08-31 23:40:39 +09:00
|
|
|
const selector = `[data-annotation-id="${this.data.parentId}"]`;
|
2020-10-21 20:12:43 +09:00
|
|
|
const parentElements = this.layer.querySelectorAll(selector);
|
|
|
|
if (parentElements.length === 0) {
|
2015-12-23 05:31:56 +09:00
|
|
|
return this.container;
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2015-12-23 05:31:56 +09:00
|
|
|
|
2019-08-31 23:40:39 +09:00
|
|
|
const popup = new PopupElement({
|
2017-08-27 07:24:27 +09:00
|
|
|
container: this.container,
|
2020-10-21 20:12:43 +09:00
|
|
|
trigger: Array.from(parentElements),
|
2017-08-27 07:24:27 +09:00
|
|
|
color: this.data.color,
|
2021-09-25 00:30:56 +09:00
|
|
|
titleObj: this.data.titleObj,
|
2019-04-22 04:21:01 +09:00
|
|
|
modificationDate: this.data.modificationDate,
|
2021-09-25 00:30:56 +09:00
|
|
|
contentsObj: this.data.contentsObj,
|
2021-10-25 00:29:30 +09:00
|
|
|
richText: this.data.richText,
|
2017-08-27 07:24:27 +09:00
|
|
|
});
|
2015-12-23 05:31:56 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
// Position the popup next to the parent annotation's container.
|
|
|
|
// PDF viewers ignore a popup annotation's rectangle.
|
2020-10-21 20:12:43 +09:00
|
|
|
const page = this.page;
|
|
|
|
const rect = Util.normalizeRect([
|
|
|
|
this.data.parentRect[0],
|
|
|
|
page.view[3] - this.data.parentRect[1] + page.view[1],
|
|
|
|
this.data.parentRect[2],
|
|
|
|
page.view[3] - this.data.parentRect[3] + page.view[1],
|
|
|
|
]);
|
|
|
|
const popupLeft =
|
|
|
|
rect[0] + this.data.parentRect[2] - this.data.parentRect[0];
|
|
|
|
const popupTop = rect[1];
|
2020-09-24 17:28:29 +09:00
|
|
|
|
2020-10-21 20:12:43 +09:00
|
|
|
this.container.style.transformOrigin = `${-popupLeft}px ${-popupTop}px`;
|
2020-09-24 17:28:29 +09:00
|
|
|
this.container.style.left = `${popupLeft}px`;
|
2020-11-03 15:44:21 +09:00
|
|
|
this.container.style.top = `${popupTop}px`;
|
2017-08-27 07:24:27 +09:00
|
|
|
|
|
|
|
this.container.appendChild(popup.render());
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
2015-12-23 05:31:56 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class PopupElement {
|
|
|
|
constructor(parameters) {
|
2015-12-27 23:07:18 +09:00
|
|
|
this.container = parameters.container;
|
|
|
|
this.trigger = parameters.trigger;
|
2015-12-23 05:31:56 +09:00
|
|
|
this.color = parameters.color;
|
2021-09-25 00:30:56 +09:00
|
|
|
this.titleObj = parameters.titleObj;
|
2019-04-22 04:21:01 +09:00
|
|
|
this.modificationDate = parameters.modificationDate;
|
2021-09-25 00:30:56 +09:00
|
|
|
this.contentsObj = parameters.contentsObj;
|
2021-10-25 00:29:30 +09:00
|
|
|
this.richText = parameters.richText;
|
2015-12-27 23:07:18 +09:00
|
|
|
this.hideWrapper = parameters.hideWrapper || false;
|
2015-12-23 05:31:56 +09:00
|
|
|
|
|
|
|
this.pinned = false;
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
|
|
|
const BACKGROUND_ENLIGHT = 0.7;
|
|
|
|
|
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 wrapper = document.createElement("div");
|
|
|
|
wrapper.className = "popupWrapper";
|
2017-08-27 07:24:27 +09:00
|
|
|
|
|
|
|
// For Popup annotations we hide the entire section because it contains
|
|
|
|
// only the popup. However, for Text annotations without a separate Popup
|
|
|
|
// annotation, we cannot hide the entire container as the image would
|
|
|
|
// disappear too. In that special case, hiding the wrapper suffices.
|
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
|
|
|
this.hideElement = this.hideWrapper ? wrapper : this.container;
|
2021-02-08 08:21:49 +09:00
|
|
|
this.hideElement.hidden = true;
|
2017-08-27 07:24:27 +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
|
|
|
const popup = document.createElement("div");
|
|
|
|
popup.className = "popup";
|
2017-08-27 07:24:27 +09:00
|
|
|
|
2019-08-31 23:40:39 +09:00
|
|
|
const color = this.color;
|
2017-08-27 07:24:27 +09:00
|
|
|
if (color) {
|
|
|
|
// Enlighten the color.
|
2019-08-31 23:40:39 +09:00
|
|
|
const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
|
|
|
|
const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
|
|
|
|
const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
|
2020-10-30 22:51:50 +09:00
|
|
|
popup.style.backgroundColor = Util.makeHexColor(r | 0, g | 0, b | 0);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2015-12-27 23:07:18 +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
|
|
|
const title = document.createElement("h1");
|
2021-09-25 00:30:56 +09:00
|
|
|
title.dir = this.titleObj.dir;
|
|
|
|
title.textContent = this.titleObj.str;
|
2019-04-22 04:21:01 +09:00
|
|
|
popup.appendChild(title);
|
|
|
|
|
|
|
|
// The modification date is shown in the popup instead of the creation
|
|
|
|
// date if it is available and can be parsed correctly, which is
|
|
|
|
// consistent with other viewers such as Adobe Acrobat.
|
|
|
|
const dateObject = PDFDateString.toDateObject(this.modificationDate);
|
|
|
|
if (dateObject) {
|
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 modificationDate = document.createElement("span");
|
2021-10-25 00:29:30 +09:00
|
|
|
modificationDate.className = "popupDate";
|
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
|
|
|
modificationDate.textContent = "{{date}}, {{time}}";
|
|
|
|
modificationDate.dataset.l10nId = "annotation_date_string";
|
2019-04-22 04:21:01 +09:00
|
|
|
modificationDate.dataset.l10nArgs = JSON.stringify({
|
|
|
|
date: dateObject.toLocaleDateString(),
|
|
|
|
time: dateObject.toLocaleTimeString(),
|
|
|
|
});
|
|
|
|
popup.appendChild(modificationDate);
|
|
|
|
}
|
|
|
|
|
2021-10-25 00:29:30 +09:00
|
|
|
if (
|
|
|
|
this.richText?.str &&
|
|
|
|
(!this.contentsObj?.str || this.contentsObj.str === this.richText.str)
|
|
|
|
) {
|
|
|
|
XfaLayer.render({
|
|
|
|
xfa: this.richText.html,
|
|
|
|
intent: "richText",
|
|
|
|
div: popup,
|
|
|
|
});
|
|
|
|
popup.lastChild.className = "richText popupContent";
|
|
|
|
} else {
|
|
|
|
const contents = this._formatContents(this.contentsObj);
|
|
|
|
popup.appendChild(contents);
|
|
|
|
}
|
2015-12-23 05:31:56 +09:00
|
|
|
|
2020-10-21 20:12:43 +09:00
|
|
|
if (!Array.isArray(this.trigger)) {
|
|
|
|
this.trigger = [this.trigger];
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
// Attach the event listeners to the trigger element.
|
2021-04-24 19:36:01 +09:00
|
|
|
for (const element of this.trigger) {
|
2020-10-21 20:12:43 +09:00
|
|
|
element.addEventListener("click", this._toggle.bind(this));
|
|
|
|
element.addEventListener("mouseover", this._show.bind(this, false));
|
|
|
|
element.addEventListener("mouseout", this._hide.bind(this, false));
|
2021-04-24 19:36:01 +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
|
|
|
popup.addEventListener("click", this._hide.bind(this, true));
|
2015-12-23 05:31:56 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
wrapper.appendChild(popup);
|
|
|
|
return wrapper;
|
|
|
|
}
|
2015-12-23 05:31:56 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
/**
|
|
|
|
* Format the contents of the popup by adding newlines where necessary.
|
|
|
|
*
|
|
|
|
* @private
|
2021-09-25 00:30:56 +09:00
|
|
|
* @param {Object<string, string>} contentsObj
|
2017-08-27 07:24:27 +09:00
|
|
|
* @memberof PopupElement
|
|
|
|
* @returns {HTMLParagraphElement}
|
|
|
|
*/
|
2021-09-25 00:30:56 +09:00
|
|
|
_formatContents({ str, dir }) {
|
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 p = document.createElement("p");
|
2021-10-25 00:29:30 +09:00
|
|
|
p.className = "popupContent";
|
2021-09-25 00:30:56 +09:00
|
|
|
p.dir = dir;
|
|
|
|
const lines = str.split(/(?:\r\n?|\n)/);
|
2017-08-27 07:24:27 +09:00
|
|
|
for (let i = 0, ii = lines.length; i < ii; ++i) {
|
2019-08-31 23:40:39 +09:00
|
|
|
const line = lines[i];
|
2017-08-27 07:24:27 +09:00
|
|
|
p.appendChild(document.createTextNode(line));
|
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 (i < ii - 1) {
|
|
|
|
p.appendChild(document.createElement("br"));
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
2015-12-23 05:31:56 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
/**
|
|
|
|
* Toggle the visibility of the popup.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @memberof PopupElement
|
|
|
|
*/
|
|
|
|
_toggle() {
|
|
|
|
if (this.pinned) {
|
|
|
|
this._hide(true);
|
|
|
|
} else {
|
|
|
|
this._show(true);
|
|
|
|
}
|
|
|
|
}
|
2017-04-03 03:50:17 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
/**
|
|
|
|
* Show the popup.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {boolean} pin
|
|
|
|
* @memberof PopupElement
|
|
|
|
*/
|
|
|
|
_show(pin = false) {
|
|
|
|
if (pin) {
|
|
|
|
this.pinned = true;
|
|
|
|
}
|
2021-02-08 08:21:49 +09:00
|
|
|
if (this.hideElement.hidden) {
|
|
|
|
this.hideElement.hidden = false;
|
2017-08-27 07:24:27 +09:00
|
|
|
this.container.style.zIndex += 1;
|
|
|
|
}
|
2017-04-03 03:50:17 +09:00
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
/**
|
|
|
|
* Hide the popup.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {boolean} unpin
|
|
|
|
* @memberof PopupElement
|
|
|
|
*/
|
|
|
|
_hide(unpin = true) {
|
|
|
|
if (unpin) {
|
|
|
|
this.pinned = false;
|
|
|
|
}
|
2021-02-08 08:21:49 +09:00
|
|
|
if (!this.hideElement.hidden && !this.pinned) {
|
|
|
|
this.hideElement.hidden = true;
|
2017-08-27 07:24:27 +09:00
|
|
|
this.container.style.zIndex -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-03 03:50:17 +09:00
|
|
|
|
2019-04-14 01:45:22 +09:00
|
|
|
class FreeTextAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable, ignoreBorder: true });
|
2019-04-14 01:45:22 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
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
|
|
|
this.container.className = "freeTextAnnotation";
|
2019-04-14 01:45:22 +09:00
|
|
|
|
|
|
|
if (!this.data.hasPopup) {
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(null, this.data);
|
2019-04-14 01:45:22 +09:00
|
|
|
}
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class LineAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable, ignoreBorder: true });
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2017-04-03 03:50:17 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
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
|
|
|
this.container.className = "lineAnnotation";
|
2017-08-27 07:24:27 +09:00
|
|
|
|
|
|
|
// Create an invisible line with the same starting and ending coordinates
|
|
|
|
// that acts as the trigger for the popup. Only the line itself should
|
|
|
|
// trigger the popup, not the entire container.
|
2019-08-31 23:40:39 +09:00
|
|
|
const data = this.data;
|
|
|
|
const width = data.rect[2] - data.rect[0];
|
|
|
|
const height = data.rect[3] - data.rect[1];
|
|
|
|
const svg = this.svgFactory.create(width, height);
|
2017-08-27 07:24:27 +09:00
|
|
|
|
|
|
|
// PDF coordinates are calculated from a bottom left origin, so transform
|
|
|
|
// the line coordinates to a top left origin for the SVG element.
|
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 line = this.svgFactory.createElement("svg:line");
|
|
|
|
line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
|
|
|
|
line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
|
|
|
|
line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
|
|
|
|
line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
|
2019-11-09 21:29:09 +09:00
|
|
|
// Ensure that the 'stroke-width' is always non-zero, since otherwise it
|
|
|
|
// won't be possible to open/close the popup (note e.g. issue 11122).
|
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
|
|
|
line.setAttribute("stroke-width", data.borderStyle.width || 1);
|
|
|
|
line.setAttribute("stroke", "transparent");
|
2021-10-08 03:39:10 +09:00
|
|
|
line.setAttribute("fill", "transparent");
|
2017-08-27 07:24:27 +09:00
|
|
|
|
|
|
|
svg.appendChild(line);
|
|
|
|
this.container.append(svg);
|
|
|
|
|
|
|
|
// Create the popup ourselves so that we can bind it to the line instead
|
|
|
|
// of to the entire container (which is the default).
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(line, data);
|
2017-08-27 07:24:27 +09:00
|
|
|
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
2017-04-03 03:50:17 +09:00
|
|
|
|
2017-07-24 07:11:27 +09:00
|
|
|
class SquareAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable, ignoreBorder: true });
|
2017-07-24 07:11:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
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
|
|
|
this.container.className = "squareAnnotation";
|
2017-07-24 07:11:27 +09:00
|
|
|
|
|
|
|
// Create an invisible square with the same rectangle that acts as the
|
|
|
|
// trigger for the popup. Only the square itself should trigger the
|
|
|
|
// popup, not the entire container.
|
2019-08-31 23:40:39 +09:00
|
|
|
const data = this.data;
|
|
|
|
const width = data.rect[2] - data.rect[0];
|
|
|
|
const height = data.rect[3] - data.rect[1];
|
|
|
|
const svg = this.svgFactory.create(width, height);
|
2017-07-24 07:11:27 +09:00
|
|
|
|
|
|
|
// The browser draws half of the borders inside the square and half of
|
|
|
|
// the borders outside the square by default. This behavior cannot be
|
|
|
|
// changed programmatically, so correct for that here.
|
2019-08-31 23:40:39 +09:00
|
|
|
const borderWidth = data.borderStyle.width;
|
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 square = this.svgFactory.createElement("svg:rect");
|
|
|
|
square.setAttribute("x", borderWidth / 2);
|
|
|
|
square.setAttribute("y", borderWidth / 2);
|
|
|
|
square.setAttribute("width", width - borderWidth);
|
|
|
|
square.setAttribute("height", height - borderWidth);
|
2019-11-09 21:29:09 +09:00
|
|
|
// Ensure that the 'stroke-width' is always non-zero, since otherwise it
|
|
|
|
// won't be possible to open/close the popup (note e.g. issue 11122).
|
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
|
|
|
square.setAttribute("stroke-width", borderWidth || 1);
|
|
|
|
square.setAttribute("stroke", "transparent");
|
2021-10-08 03:39:10 +09:00
|
|
|
square.setAttribute("fill", "transparent");
|
2017-07-24 07:11:27 +09:00
|
|
|
|
|
|
|
svg.appendChild(square);
|
|
|
|
this.container.append(svg);
|
|
|
|
|
|
|
|
// Create the popup ourselves so that we can bind it to the square instead
|
|
|
|
// of to the entire container (which is the default).
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(square, data);
|
2017-07-24 07:11:27 +09:00
|
|
|
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:30:58 +09:00
|
|
|
class CircleAnnotationElement extends AnnotationElement {
|
2017-08-27 07:24:27 +09:00
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable, ignoreBorder: true });
|
2017-07-24 07:30:58 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
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
|
|
|
this.container.className = "circleAnnotation";
|
2017-07-24 07:11:27 +09:00
|
|
|
|
2017-07-24 07:30:58 +09:00
|
|
|
// Create an invisible circle with the same ellipse that acts as the
|
|
|
|
// trigger for the popup. Only the circle itself should trigger the
|
|
|
|
// popup, not the entire container.
|
2019-08-31 23:40:39 +09:00
|
|
|
const data = this.data;
|
|
|
|
const width = data.rect[2] - data.rect[0];
|
|
|
|
const height = data.rect[3] - data.rect[1];
|
|
|
|
const svg = this.svgFactory.create(width, height);
|
2017-07-24 07:30:58 +09:00
|
|
|
|
|
|
|
// The browser draws half of the borders inside the circle and half of
|
|
|
|
// the borders outside the circle by default. This behavior cannot be
|
|
|
|
// changed programmatically, so correct for that here.
|
2019-08-31 23:40:39 +09:00
|
|
|
const borderWidth = data.borderStyle.width;
|
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 circle = this.svgFactory.createElement("svg:ellipse");
|
|
|
|
circle.setAttribute("cx", width / 2);
|
|
|
|
circle.setAttribute("cy", height / 2);
|
|
|
|
circle.setAttribute("rx", width / 2 - borderWidth / 2);
|
|
|
|
circle.setAttribute("ry", height / 2 - borderWidth / 2);
|
2019-11-09 21:29:09 +09:00
|
|
|
// Ensure that the 'stroke-width' is always non-zero, since otherwise it
|
|
|
|
// won't be possible to open/close the popup (note e.g. issue 11122).
|
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
|
|
|
circle.setAttribute("stroke-width", borderWidth || 1);
|
|
|
|
circle.setAttribute("stroke", "transparent");
|
2021-10-08 03:39:10 +09:00
|
|
|
circle.setAttribute("fill", "transparent");
|
2017-07-24 07:30:58 +09:00
|
|
|
|
|
|
|
svg.appendChild(circle);
|
|
|
|
this.container.append(svg);
|
|
|
|
|
|
|
|
// Create the popup ourselves so that we can bind it to the circle instead
|
|
|
|
// of to the entire container (which is the default).
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(circle, data);
|
2017-08-27 07:24:27 +09:00
|
|
|
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
2017-04-03 03:50:17 +09:00
|
|
|
|
2017-09-18 03:18:22 +09:00
|
|
|
class PolylineAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable, ignoreBorder: true });
|
2017-09-23 23:50:49 +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
|
|
|
this.containerClassName = "polylineAnnotation";
|
|
|
|
this.svgElementName = "svg:polyline";
|
2017-09-18 03:18:22 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-09-23 23:50:49 +09:00
|
|
|
this.container.className = this.containerClassName;
|
2017-09-18 03:18:22 +09:00
|
|
|
|
|
|
|
// Create an invisible polyline with the same points that acts as the
|
|
|
|
// trigger for the popup. Only the polyline itself should trigger the
|
|
|
|
// popup, not the entire container.
|
2019-08-31 23:40:39 +09:00
|
|
|
const data = this.data;
|
|
|
|
const width = data.rect[2] - data.rect[0];
|
|
|
|
const height = data.rect[3] - data.rect[1];
|
|
|
|
const svg = this.svgFactory.create(width, height);
|
2017-09-18 03:18:22 +09:00
|
|
|
|
|
|
|
// Convert the vertices array to a single points string that the SVG
|
|
|
|
// polyline element expects ("x1,y1 x2,y2 ..."). PDF coordinates are
|
|
|
|
// calculated from a bottom left origin, so transform the polyline
|
|
|
|
// coordinates to a top left origin for the SVG element.
|
|
|
|
let points = [];
|
2019-08-31 23:40:39 +09:00
|
|
|
for (const coordinate of data.vertices) {
|
|
|
|
const x = coordinate.x - data.rect[0];
|
|
|
|
const y = data.rect[3] - coordinate.y;
|
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
|
|
|
points.push(x + "," + y);
|
2017-09-18 03:18:22 +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
|
|
|
points = points.join(" ");
|
2017-09-18 03:18:22 +09:00
|
|
|
|
2019-08-31 23:40:39 +09:00
|
|
|
const polyline = this.svgFactory.createElement(this.svgElementName);
|
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
|
|
|
polyline.setAttribute("points", points);
|
2019-11-09 21:29:09 +09:00
|
|
|
// Ensure that the 'stroke-width' is always non-zero, since otherwise it
|
|
|
|
// won't be possible to open/close the popup (note e.g. issue 11122).
|
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
|
|
|
polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
|
|
|
|
polyline.setAttribute("stroke", "transparent");
|
2021-10-08 03:39:10 +09:00
|
|
|
polyline.setAttribute("fill", "transparent");
|
2017-09-18 03:18:22 +09:00
|
|
|
|
|
|
|
svg.appendChild(polyline);
|
|
|
|
this.container.append(svg);
|
|
|
|
|
|
|
|
// Create the popup ourselves so that we can bind it to the polyline
|
|
|
|
// instead of to the entire container (which is the default).
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(polyline, data);
|
2017-09-18 03:18:22 +09:00
|
|
|
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 23:50:49 +09:00
|
|
|
class PolygonAnnotationElement extends PolylineAnnotationElement {
|
|
|
|
constructor(parameters) {
|
|
|
|
// Polygons are specific forms of polylines, so reuse their logic.
|
|
|
|
super(parameters);
|
|
|
|
|
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
|
|
|
this.containerClassName = "polygonAnnotation";
|
|
|
|
this.svgElementName = "svg:polygon";
|
2017-09-23 23:50:49 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-10 06:35:32 +09:00
|
|
|
class CaretAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable, ignoreBorder: true });
|
2019-04-10 06:35:32 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
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
|
|
|
this.container.className = "caretAnnotation";
|
2019-04-10 06:35:32 +09:00
|
|
|
|
|
|
|
if (!this.data.hasPopup) {
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(null, this.data);
|
2019-04-10 06:35:32 +09:00
|
|
|
}
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-30 23:29:16 +09:00
|
|
|
class InkAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable, ignoreBorder: true });
|
2018-09-30 23:29:16 +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
|
|
|
this.containerClassName = "inkAnnotation";
|
2018-09-30 23:29:16 +09:00
|
|
|
|
|
|
|
// Use the polyline SVG element since it allows us to use coordinates
|
|
|
|
// directly and to draw both straight lines and curves.
|
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
|
|
|
this.svgElementName = "svg:polyline";
|
2018-09-30 23:29:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
this.container.className = this.containerClassName;
|
|
|
|
|
|
|
|
// Create an invisible polyline with the same points that acts as the
|
|
|
|
// trigger for the popup.
|
2019-08-31 23:40:39 +09:00
|
|
|
const data = this.data;
|
|
|
|
const width = data.rect[2] - data.rect[0];
|
|
|
|
const height = data.rect[3] - data.rect[1];
|
|
|
|
const svg = this.svgFactory.create(width, height);
|
2018-09-30 23:29:16 +09:00
|
|
|
|
2019-08-31 23:40:39 +09:00
|
|
|
for (const inkList of data.inkLists) {
|
2018-09-30 23:29:16 +09:00
|
|
|
// Convert the ink list to a single points string that the SVG
|
|
|
|
// polyline element expects ("x1,y1 x2,y2 ..."). PDF coordinates are
|
|
|
|
// calculated from a bottom left origin, so transform the polyline
|
|
|
|
// coordinates to a top left origin for the SVG element.
|
2019-08-31 23:40:39 +09:00
|
|
|
let points = [];
|
|
|
|
for (const coordinate of inkList) {
|
|
|
|
const x = coordinate.x - data.rect[0];
|
|
|
|
const y = data.rect[3] - coordinate.y;
|
|
|
|
points.push(`${x},${y}`);
|
2018-09-30 23:29:16 +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
|
|
|
points = points.join(" ");
|
2018-09-30 23:29:16 +09:00
|
|
|
|
2019-08-31 23:40:39 +09:00
|
|
|
const polyline = this.svgFactory.createElement(this.svgElementName);
|
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
|
|
|
polyline.setAttribute("points", points);
|
2019-11-09 21:29:09 +09:00
|
|
|
// Ensure that the 'stroke-width' is always non-zero, since otherwise it
|
|
|
|
// won't be possible to open/close the popup (note e.g. issue 11122).
|
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
|
|
|
polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
|
|
|
|
polyline.setAttribute("stroke", "transparent");
|
2021-10-08 03:39:10 +09:00
|
|
|
polyline.setAttribute("fill", "transparent");
|
2018-09-30 23:29:16 +09:00
|
|
|
|
|
|
|
// Create the popup ourselves so that we can bind it to the polyline
|
|
|
|
// instead of to the entire container (which is the default).
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(polyline, data);
|
2018-09-30 23:29:16 +09:00
|
|
|
|
|
|
|
svg.appendChild(polyline);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.container.append(svg);
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class HighlightAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, {
|
|
|
|
isRenderable,
|
|
|
|
ignoreBorder: true,
|
|
|
|
createQuadrilaterals: true,
|
|
|
|
});
|
2016-01-01 23:31:46 +09:00
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
|
|
|
if (!this.data.hasPopup) {
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(null, this.data);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2020-11-14 19:42:35 +09:00
|
|
|
|
|
|
|
if (this.quadrilaterals) {
|
2020-12-06 03:32:13 +09:00
|
|
|
return this._renderQuadrilaterals("highlightAnnotation");
|
2020-11-14 19:42:35 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
this.container.className = "highlightAnnotation";
|
|
|
|
return this.container;
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
|
|
|
}
|
2016-01-01 23:31:46 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class UnderlineAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, {
|
|
|
|
isRenderable,
|
|
|
|
ignoreBorder: true,
|
|
|
|
createQuadrilaterals: true,
|
|
|
|
});
|
2015-12-28 08:33:41 +09:00
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
|
|
|
if (!this.data.hasPopup) {
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(null, this.data);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2020-12-02 00:04:43 +09:00
|
|
|
|
|
|
|
if (this.quadrilaterals) {
|
2020-12-06 03:32:13 +09:00
|
|
|
return this._renderQuadrilaterals("underlineAnnotation");
|
2020-12-02 00:04:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
this.container.className = "underlineAnnotation";
|
2017-08-27 07:24:27 +09:00
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
2015-12-28 08:33:41 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class SquigglyAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, {
|
|
|
|
isRenderable,
|
|
|
|
ignoreBorder: true,
|
|
|
|
createQuadrilaterals: true,
|
|
|
|
});
|
2015-12-30 23:28:26 +09:00
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
|
|
|
if (!this.data.hasPopup) {
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(null, this.data);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2020-12-02 00:04:43 +09:00
|
|
|
|
|
|
|
if (this.quadrilaterals) {
|
2020-12-06 03:32:13 +09:00
|
|
|
return this._renderQuadrilaterals("squigglyAnnotation");
|
2020-12-02 00:04:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
this.container.className = "squigglyAnnotation";
|
2017-08-27 07:24:27 +09:00
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
2015-12-30 23:28:26 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class StrikeOutAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, {
|
|
|
|
isRenderable,
|
|
|
|
ignoreBorder: true,
|
|
|
|
createQuadrilaterals: true,
|
|
|
|
});
|
2015-12-29 23:09:28 +09:00
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
|
|
|
if (!this.data.hasPopup) {
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(null, this.data);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2020-12-02 00:04:43 +09:00
|
|
|
|
|
|
|
if (this.quadrilaterals) {
|
2020-12-06 03:32:13 +09:00
|
|
|
return this._renderQuadrilaterals("strikeoutAnnotation");
|
2020-12-02 00:04:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
this.container.className = "strikeoutAnnotation";
|
2017-08-27 07:24:27 +09:00
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
2015-12-29 23:09:28 +09:00
|
|
|
|
2017-09-16 23:37:50 +09:00
|
|
|
class StampAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
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 isRenderable = !!(
|
|
|
|
parameters.data.hasPopup ||
|
2021-09-25 00:30:56 +09:00
|
|
|
parameters.data.titleObj?.str ||
|
2021-10-25 00:29:30 +09:00
|
|
|
parameters.data.contentsObj?.str ||
|
|
|
|
parameters.data.richText?.str
|
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
|
|
|
);
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable, ignoreBorder: true });
|
2017-09-16 23:37:50 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
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
|
|
|
this.container.className = "stampAnnotation";
|
2017-09-16 23:37:50 +09:00
|
|
|
|
|
|
|
if (!this.data.hasPopup) {
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(null, this.data);
|
2017-09-16 23:37:50 +09:00
|
|
|
}
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class FileAttachmentAnnotationElement extends AnnotationElement {
|
|
|
|
constructor(parameters) {
|
2020-12-06 03:48:05 +09:00
|
|
|
super(parameters, { isRenderable: true });
|
2016-02-15 04:44:00 +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
|
|
|
const { filename, content } = this.data.file;
|
2018-10-01 18:55:25 +09:00
|
|
|
this.filename = getFilenameFromUrl(filename);
|
|
|
|
this.content = content;
|
|
|
|
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
this.linkService.eventBus?.dispatch("fileattachmentannotation", {
|
|
|
|
source: this,
|
|
|
|
id: stringToPDFString(filename),
|
|
|
|
filename,
|
|
|
|
content,
|
|
|
|
});
|
2016-02-15 04:44:00 +09:00
|
|
|
}
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
render() {
|
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
|
|
|
this.container.className = "fileAttachmentAnnotation";
|
2016-02-15 04:44:00 +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
|
|
|
const trigger = document.createElement("div");
|
2017-08-27 07:24:27 +09:00
|
|
|
trigger.style.height = this.container.style.height;
|
|
|
|
trigger.style.width = this.container.style.width;
|
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
|
|
|
trigger.addEventListener("dblclick", this._download.bind(this));
|
2017-08-27 07:24:27 +09:00
|
|
|
|
2021-09-25 00:30:56 +09:00
|
|
|
if (
|
|
|
|
!this.data.hasPopup &&
|
2021-10-25 00:29:30 +09:00
|
|
|
(this.data.titleObj?.str ||
|
|
|
|
this.data.contentsObj?.str ||
|
|
|
|
this.data.richText)
|
2021-09-25 00:30:56 +09:00
|
|
|
) {
|
2020-11-06 01:49:32 +09:00
|
|
|
this._createPopup(trigger, this.data);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2016-02-15 04:44:00 +09:00
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
this.container.appendChild(trigger);
|
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Download the file attachment associated with this annotation.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @memberof FileAttachmentAnnotationElement
|
|
|
|
*/
|
|
|
|
_download() {
|
2021-02-23 20:58:17 +09:00
|
|
|
this.downloadManager?.openOrDownloadData(
|
|
|
|
this.container,
|
|
|
|
this.content,
|
|
|
|
this.filename
|
|
|
|
);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
|
|
|
}
|
2016-02-15 04:44:00 +09:00
|
|
|
|
2015-12-17 23:55:11 +09:00
|
|
|
/**
|
|
|
|
* @typedef {Object} AnnotationLayerParameters
|
|
|
|
* @property {PageViewport} viewport
|
|
|
|
* @property {HTMLDivElement} div
|
|
|
|
* @property {Array} annotations
|
|
|
|
* @property {PDFPage} page
|
|
|
|
* @property {IPDFLinkService} linkService
|
2018-02-13 21:17:11 +09:00
|
|
|
* @property {DownloadManager} downloadManager
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
|
|
|
* for annotation icons. Include trailing slash.
|
[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
|
|
|
* @property {boolean} renderForms
|
2020-10-29 03:16:56 +09:00
|
|
|
* @property {boolean} [enableScripting] - Enable embedded script execution.
|
|
|
|
* @property {boolean} [hasJSActions] - Some fields have JS actions.
|
|
|
|
* The default value is `false`.
|
2015-12-17 23:55:11 +09:00
|
|
|
*/
|
|
|
|
|
2017-08-27 07:24:27 +09:00
|
|
|
class AnnotationLayer {
|
|
|
|
/**
|
|
|
|
* Render a new annotation layer with all annotation elements.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @param {AnnotationLayerParameters} parameters
|
|
|
|
* @memberof AnnotationLayer
|
|
|
|
*/
|
|
|
|
static render(parameters) {
|
2020-01-26 00:53:34 +09:00
|
|
|
const sortedAnnotations = [],
|
|
|
|
popupAnnotations = [];
|
|
|
|
// Ensure that Popup annotations are handled last, since they're dependant
|
|
|
|
// upon the parent annotation having already been rendered (please refer to
|
|
|
|
// the `PopupAnnotationElement.render` method); fixes issue 11362.
|
2019-08-31 23:40:39 +09:00
|
|
|
for (const data of parameters.annotations) {
|
2017-08-27 07:24:27 +09:00
|
|
|
if (!data) {
|
|
|
|
continue;
|
2015-12-17 23:55:11 +09:00
|
|
|
}
|
2020-01-26 00:53:34 +09:00
|
|
|
if (data.annotationType === AnnotationType.POPUP) {
|
|
|
|
popupAnnotations.push(data);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sortedAnnotations.push(data);
|
|
|
|
}
|
|
|
|
if (popupAnnotations.length) {
|
|
|
|
sortedAnnotations.push(...popupAnnotations);
|
|
|
|
}
|
|
|
|
|
2021-11-07 02:36:49 +09:00
|
|
|
const div = parameters.div;
|
|
|
|
|
2020-01-26 00:53:34 +09:00
|
|
|
for (const data of sortedAnnotations) {
|
2019-08-31 23:40:39 +09:00
|
|
|
const element = AnnotationElementFactory.create({
|
2017-08-27 07:24:27 +09:00
|
|
|
data,
|
2021-11-07 02:36:49 +09:00
|
|
|
layer: div,
|
2017-08-27 07:24:27 +09:00
|
|
|
page: parameters.page,
|
|
|
|
viewport: parameters.viewport,
|
|
|
|
linkService: parameters.linkService,
|
|
|
|
downloadManager: parameters.downloadManager,
|
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
|
|
|
imageResourcesPath: parameters.imageResourcesPath || "",
|
[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
|
|
|
renderForms: parameters.renderForms !== false,
|
2017-07-24 07:09:18 +09:00
|
|
|
svgFactory: new DOMSVGFactory(),
|
[api-minor] Fix the `AnnotationStorage` usage properly in the viewer/tests (PR 12107 and 12143 follow-up)
*The [api-minor] label probably ought to have been added to the original PR, given the changes to the `createAnnotationLayerBuilder` signature (if nothing else).*
This patch fixes the following things:
- Let the `AnnotationLayer.render` method create an `AnnotationStorage`-instance if none was provided, thus making the parameter *properly* optional. This not only fixes the reference tests, it also prevents issues when the viewer components are used.
- Stop exporting `AnnotationStorage` in the official API, i.e. the `src/pdf.js` file, since it's no longer necessary given the change above. Generally speaking, unless absolutely necessary we probably shouldn't export unused things in the API.
- Fix a number of JSDocs `typedef`s, in `src/display/` and `web/` code, to actually account for the new `annotationStorage` parameter.
- Update `web/interfaces.js` to account for the changes in `createAnnotationLayerBuilder`.
- Initialize the storage, in `AnnotationStorage`, using `Object.create(null)` rather than `{}` (which is the PDF.js default).
2020-07-31 23:13:26 +09:00
|
|
|
annotationStorage:
|
|
|
|
parameters.annotationStorage || new AnnotationStorage(),
|
2020-10-29 03:16:56 +09:00
|
|
|
enableScripting: parameters.enableScripting,
|
|
|
|
hasJSActions: parameters.hasJSActions,
|
2021-09-14 19:06:28 +09:00
|
|
|
fieldObjects: parameters.fieldObjects,
|
2020-12-17 20:55:58 +09:00
|
|
|
mouseState: parameters.mouseState || { isDown: false },
|
2017-08-27 07:24:27 +09:00
|
|
|
});
|
|
|
|
if (element.isRenderable) {
|
2020-10-21 20:12:43 +09:00
|
|
|
const rendered = element.render();
|
2020-11-04 00:04:08 +09:00
|
|
|
if (data.hidden) {
|
|
|
|
rendered.style.visibility = "hidden";
|
|
|
|
}
|
2020-10-21 20:12:43 +09:00
|
|
|
if (Array.isArray(rendered)) {
|
|
|
|
for (const renderedElement of rendered) {
|
2021-11-07 02:36:49 +09:00
|
|
|
div.appendChild(renderedElement);
|
2020-10-21 20:12:43 +09:00
|
|
|
}
|
|
|
|
} else {
|
2020-11-06 01:49:32 +09:00
|
|
|
if (element instanceof PopupAnnotationElement) {
|
|
|
|
// Popup annotation elements should not be on top of other
|
|
|
|
// annotation elements to prevent interfering with mouse events.
|
2021-11-07 02:36:49 +09:00
|
|
|
div.prepend(rendered);
|
2020-11-06 01:49:32 +09:00
|
|
|
} else {
|
2021-11-07 02:36:49 +09:00
|
|
|
div.appendChild(rendered);
|
2020-11-06 01:49:32 +09:00
|
|
|
}
|
2020-10-21 20:12:43 +09:00
|
|
|
}
|
2015-12-17 23:55:11 +09:00
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
2021-11-07 02:36:49 +09:00
|
|
|
|
|
|
|
this.#setAnnotationCanvasMap(div, parameters.annotationCanvasMap);
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the annotation elements on existing annotation layer.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @param {AnnotationLayerParameters} parameters
|
|
|
|
* @memberof AnnotationLayer
|
|
|
|
*/
|
|
|
|
static update(parameters) {
|
2021-11-07 02:36:49 +09:00
|
|
|
const { page, viewport, annotations, annotationCanvasMap, div } =
|
|
|
|
parameters;
|
|
|
|
const transform = viewport.transform;
|
|
|
|
const matrix = `matrix(${transform.join(",")})`;
|
|
|
|
|
|
|
|
let scale, ownMatrix;
|
|
|
|
for (const data of annotations) {
|
|
|
|
const elements = div.querySelectorAll(
|
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
|
|
|
`[data-annotation-id="${data.id}"]`
|
|
|
|
);
|
2020-10-21 20:12:43 +09:00
|
|
|
if (elements) {
|
2021-04-24 19:36:01 +09:00
|
|
|
for (const element of elements) {
|
2021-11-07 02:36:49 +09:00
|
|
|
if (data.hasOwnCanvas) {
|
|
|
|
const rect = Util.normalizeRect([
|
|
|
|
data.rect[0],
|
|
|
|
page.view[3] - data.rect[1] + page.view[1],
|
|
|
|
data.rect[2],
|
|
|
|
page.view[3] - data.rect[3] + page.view[1],
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (!ownMatrix) {
|
|
|
|
// When an annotation has its own canvas, then
|
|
|
|
// the scale has been already applied to the canvas,
|
|
|
|
// so we musn't scale it twice.
|
|
|
|
scale = Math.abs(transform[0] || transform[1]);
|
|
|
|
const ownTransform = transform.slice();
|
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
|
ownTransform[i] = Math.sign(ownTransform[i]);
|
|
|
|
}
|
|
|
|
ownMatrix = `matrix(${ownTransform.join(",")})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const left = rect[0] * scale;
|
|
|
|
const top = rect[1] * scale;
|
|
|
|
element.style.left = `${left}px`;
|
|
|
|
element.style.top = `${top}px`;
|
|
|
|
element.style.transformOrigin = `${-left}px ${-top}px`;
|
|
|
|
element.style.transform = ownMatrix;
|
|
|
|
} else {
|
|
|
|
element.style.transform = matrix;
|
|
|
|
}
|
2021-04-24 19:36:01 +09:00
|
|
|
}
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
|
|
|
}
|
2021-11-07 02:36:49 +09:00
|
|
|
|
|
|
|
this.#setAnnotationCanvasMap(div, annotationCanvasMap);
|
|
|
|
div.hidden = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static #setAnnotationCanvasMap(div, annotationCanvasMap) {
|
|
|
|
if (!annotationCanvasMap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (const [id, canvas] of annotationCanvasMap) {
|
|
|
|
const element = div.querySelector(`[data-annotation-id="${id}"]`);
|
|
|
|
if (!element) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { firstChild } = element;
|
|
|
|
if (firstChild.nodeName === "CANVAS") {
|
|
|
|
element.replaceChild(canvas, firstChild);
|
|
|
|
} else {
|
|
|
|
element.insertBefore(canvas, firstChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
annotationCanvasMap.clear();
|
2017-08-27 07:24:27 +09:00
|
|
|
}
|
|
|
|
}
|
2015-12-17 23:55:11 +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
|
|
|
export { AnnotationLayer };
|