1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #16508 from calixteman/restore_mk_annotation_layer_an_object

[api-minor] Make the AnnotationLayer an object in order to use it in the AnnotationEditorLayer
This commit is contained in:
calixteman 2023-06-02 23:12:50 +02:00 committed by GitHub
commit 63b61ca082
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 52 deletions

View file

@ -2597,13 +2597,25 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
*/
class AnnotationLayer {
static #appendElement(element, id, div, accessibilityManager) {
#accessibilityManager = null;
#annotationCanvasMap = null;
#div = null;
constructor({ div, accessibilityManager, annotationCanvasMap }) {
this.#div = div;
this.#accessibilityManager = accessibilityManager;
this.#annotationCanvasMap = annotationCanvasMap;
}
#appendElement(element, id) {
const contentElement = element.firstChild || element;
contentElement.id = `${AnnotationPrefix}${id}`;
div.append(element);
accessibilityManager?.moveElementInDOM(
div,
this.#div.append(element);
this.#accessibilityManager?.moveElementInDOM(
this.#div,
element,
contentElement,
/* isRemovable = */ false
@ -2616,13 +2628,14 @@ class AnnotationLayer {
* @param {AnnotationLayerParameters} params
* @memberof AnnotationLayer
*/
static render(params) {
const { annotations, div, viewport, accessibilityManager } = params;
setLayerDimensions(div, viewport);
render(params) {
const { annotations, viewport } = params;
const layer = this.#div;
setLayerDimensions(layer, viewport);
const elementParams = {
data: null,
layer: div,
layer,
page: params.page,
viewport,
linkService: params.linkService,
@ -2660,12 +2673,7 @@ class AnnotationLayer {
if (Array.isArray(rendered)) {
for (const renderedElement of rendered) {
renderedElement.style.zIndex = zIndex++;
AnnotationLayer.#appendElement(
renderedElement,
data.id,
div,
accessibilityManager
);
this.#appendElement(renderedElement, data.id);
}
} else {
// The accessibility manager will move the annotation in the DOM in
@ -2678,41 +2686,37 @@ class AnnotationLayer {
if (element instanceof PopupAnnotationElement) {
// Popup annotation elements should not be on top of other
// annotation elements to prevent interfering with mouse events.
div.prepend(rendered);
layer.prepend(rendered);
} else {
AnnotationLayer.#appendElement(
rendered,
data.id,
div,
accessibilityManager
);
this.#appendElement(rendered, data.id);
}
}
}
this.#setAnnotationCanvasMap(div, params.annotationCanvasMap);
this.#setAnnotationCanvasMap();
}
/**
* Update the annotation elements on existing annotation layer.
*
* @param {AnnotationLayerParameters} params
* @param {AnnotationLayerParameters} viewport
* @memberof AnnotationLayer
*/
static update(params) {
const { annotationCanvasMap, div, viewport } = params;
setLayerDimensions(div, { rotation: viewport.rotation });
update({ viewport }) {
const layer = this.#div;
setLayerDimensions(layer, { rotation: viewport.rotation });
this.#setAnnotationCanvasMap(div, annotationCanvasMap);
div.hidden = false;
this.#setAnnotationCanvasMap();
layer.hidden = false;
}
static #setAnnotationCanvasMap(div, annotationCanvasMap) {
if (!annotationCanvasMap) {
#setAnnotationCanvasMap() {
if (!this.#annotationCanvasMap) {
return;
}
for (const [id, canvas] of annotationCanvasMap) {
const element = div.querySelector(`[data-annotation-id="${id}"]`);
const layer = this.#div;
for (const [id, canvas] of this.#annotationCanvasMap) {
const element = layer.querySelector(`[data-annotation-id="${id}"]`);
if (!element) {
continue;
}
@ -2726,7 +2730,7 @@ class AnnotationLayer {
firstChild.before(canvas);
}
}
annotationCanvasMap.clear();
this.#annotationCanvasMap.clear();
}
}