UNPKG

2.84 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * JavaScript code in this page
4 *
5 * Copyright 2022 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * JavaScript code in this page
21 */
22"use strict";
23
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.AnnotationEditorLayerBuilder = void 0;
28
29var _pdf = require("../pdf");
30
31var _l10n_utils = require("./l10n_utils.js");
32
33class AnnotationEditorLayerBuilder {
34 #uiManager;
35
36 constructor(options) {
37 this.pageDiv = options.pageDiv;
38 this.pdfPage = options.pdfPage;
39 this.annotationStorage = options.annotationStorage || null;
40 this.l10n = options.l10n || _l10n_utils.NullL10n;
41 this.annotationEditorLayer = null;
42 this.div = null;
43 this._cancelled = false;
44 this.#uiManager = options.uiManager;
45 }
46
47 async render(viewport, intent = "display") {
48 if (intent !== "display") {
49 return;
50 }
51
52 if (this._cancelled) {
53 return;
54 }
55
56 const clonedViewport = viewport.clone({
57 dontFlip: true
58 });
59
60 if (this.div) {
61 this.annotationEditorLayer.update({
62 viewport: clonedViewport
63 });
64 this.show();
65 return;
66 }
67
68 this.div = document.createElement("div");
69 this.div.className = "annotationEditorLayer";
70 this.div.tabIndex = 0;
71 this.pageDiv.append(this.div);
72 this.annotationEditorLayer = new _pdf.AnnotationEditorLayer({
73 uiManager: this.#uiManager,
74 div: this.div,
75 annotationStorage: this.annotationStorage,
76 pageIndex: this.pdfPage._pageIndex,
77 l10n: this.l10n,
78 viewport: clonedViewport
79 });
80 const parameters = {
81 viewport: clonedViewport,
82 div: this.div,
83 annotations: null,
84 intent
85 };
86 this.annotationEditorLayer.render(parameters);
87 }
88
89 cancel() {
90 this._cancelled = true;
91 this.destroy();
92 }
93
94 hide() {
95 if (!this.div) {
96 return;
97 }
98
99 this.div.hidden = true;
100 }
101
102 show() {
103 if (!this.div) {
104 return;
105 }
106
107 this.div.hidden = false;
108 }
109
110 destroy() {
111 if (!this.div) {
112 return;
113 }
114
115 this.pageDiv = null;
116 this.annotationEditorLayer.destroy();
117 this.div.remove();
118 }
119
120}
121
122exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
\No newline at end of file