@progress/kendo-pdfviewer-common 0.3.0-dev.202409251459 → 0.3.0-dev.202410100645
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/annotations/annotation-editor-layer-builder.js +139 -0
- package/dist/es/annotations/annotation-editor-layer.js +780 -0
- package/dist/es/annotations/annotation-editor-ui-manager.js +1690 -0
- package/dist/es/annotations/annotation-layer-builder.js +217 -0
- package/dist/es/annotations/annotation-layer.js +2793 -0
- package/dist/es/annotations/draw-layer-builder.js +65 -0
- package/dist/es/annotations/draw-layer.js +220 -0
- package/dist/es/annotations/editors/annotation-editor.js +1519 -0
- package/dist/es/annotations/editors/free-text-editor.js +783 -0
- package/dist/es/annotations/editors/highlight-editor.js +717 -0
- package/dist/es/annotations/editors/outliner.js +747 -0
- package/dist/es/annotations/helpers/annotation-storage.js +294 -0
- package/dist/es/annotations/helpers/color-manager.js +72 -0
- package/dist/es/annotations/helpers/command-manager.js +133 -0
- package/dist/es/annotations/helpers/id-manager.js +34 -0
- package/dist/es/annotations/helpers/image-manager.js +176 -0
- package/dist/es/annotations/helpers/text-accessibility-manager.js +212 -0
- package/dist/es/annotations/helpers/tools.js +19 -0
- package/dist/es/annotations/shared/display_utils.js +1024 -0
- package/dist/es/annotations/shared/event_utils.js +213 -0
- package/dist/es/annotations/shared/murmurhash3.js +126 -0
- package/dist/es/annotations/shared/scripting_utils.js +90 -0
- package/dist/es/annotations/shared/ui_utils.js +823 -0
- package/dist/es/annotations/shared/utils.js +909 -0
- package/dist/es/common/component.js +33 -0
- package/dist/es/common/core.js +91 -0
- package/dist/es/common/dom.js +11 -0
- package/dist/es/common/main.js +4 -0
- package/dist/es/common/math.js +1 -0
- package/dist/es/enums/PdfViewerInteractionMode.js +6 -0
- package/dist/es/links/link-service.js +505 -0
- package/dist/es/main.js +2 -0
- package/dist/es/scroller.js +29 -30
- package/dist/es/text/text-layer-builder.js +288 -0
- package/dist/es/utils.js +5 -5
- package/dist/es/widget/page.js +762 -0
- package/dist/es/widget/pdfviewer.js +1659 -0
- package/dist/es2015/annotations/annotation-editor-layer-builder.js +139 -0
- package/dist/es2015/annotations/annotation-editor-layer.js +780 -0
- package/dist/es2015/annotations/annotation-editor-ui-manager.js +1690 -0
- package/dist/es2015/annotations/annotation-layer-builder.js +217 -0
- package/dist/es2015/annotations/annotation-layer.js +2793 -0
- package/dist/es2015/annotations/draw-layer-builder.js +65 -0
- package/dist/es2015/annotations/draw-layer.js +220 -0
- package/dist/es2015/annotations/editors/annotation-editor.js +1519 -0
- package/dist/es2015/annotations/editors/free-text-editor.js +783 -0
- package/dist/es2015/annotations/editors/highlight-editor.js +717 -0
- package/dist/es2015/annotations/editors/outliner.js +747 -0
- package/dist/es2015/annotations/helpers/annotation-storage.js +294 -0
- package/dist/es2015/annotations/helpers/color-manager.js +72 -0
- package/dist/es2015/annotations/helpers/command-manager.js +133 -0
- package/dist/es2015/annotations/helpers/id-manager.js +34 -0
- package/dist/es2015/annotations/helpers/image-manager.js +176 -0
- package/dist/es2015/annotations/helpers/text-accessibility-manager.js +212 -0
- package/dist/es2015/annotations/helpers/tools.js +19 -0
- package/dist/es2015/annotations/shared/display_utils.js +1024 -0
- package/dist/es2015/annotations/shared/event_utils.js +213 -0
- package/dist/es2015/annotations/shared/murmurhash3.js +126 -0
- package/dist/es2015/annotations/shared/scripting_utils.js +90 -0
- package/dist/es2015/annotations/shared/ui_utils.js +823 -0
- package/dist/es2015/annotations/shared/utils.js +909 -0
- package/dist/es2015/common/component.js +33 -0
- package/dist/es2015/common/core.js +91 -0
- package/dist/es2015/common/dom.js +11 -0
- package/dist/es2015/common/main.js +4 -0
- package/dist/es2015/common/math.js +1 -0
- package/dist/es2015/enums/PdfViewerInteractionMode.js +6 -0
- package/dist/es2015/links/link-service.js +505 -0
- package/dist/es2015/main.js +2 -0
- package/dist/es2015/scroller.js +29 -30
- package/dist/es2015/text/text-layer-builder.js +288 -0
- package/dist/es2015/utils.js +5 -5
- package/dist/es2015/widget/page.js +762 -0
- package/dist/es2015/widget/pdfviewer.js +1659 -0
- package/dist/npm/annotations/annotation-editor-layer-builder.d.ts +39 -0
- package/dist/npm/annotations/annotation-editor-layer-builder.js +142 -0
- package/dist/npm/annotations/annotation-editor-layer.d.ts +196 -0
- package/dist/npm/annotations/annotation-editor-layer.js +783 -0
- package/dist/npm/annotations/annotation-editor-ui-manager.d.ts +281 -0
- package/dist/npm/annotations/annotation-editor-ui-manager.js +1694 -0
- package/dist/npm/annotations/annotation-layer-builder.d.ts +58 -0
- package/dist/npm/annotations/annotation-layer-builder.js +220 -0
- package/dist/npm/annotations/annotation-layer.d.ts +134 -0
- package/dist/npm/annotations/annotation-layer.js +2794 -0
- package/dist/npm/annotations/draw-layer-builder.d.ts +21 -0
- package/dist/npm/annotations/draw-layer-builder.js +68 -0
- package/dist/npm/annotations/draw-layer.d.ts +33 -0
- package/dist/npm/annotations/draw-layer.js +223 -0
- package/dist/npm/annotations/editors/annotation-editor.d.ts +349 -0
- package/dist/npm/annotations/editors/annotation-editor.js +1523 -0
- package/dist/npm/annotations/editors/free-text-editor.d.ts +108 -0
- package/dist/npm/annotations/editors/free-text-editor.js +786 -0
- package/dist/npm/annotations/editors/highlight-editor.d.ts +114 -0
- package/dist/npm/annotations/editors/highlight-editor.js +717 -0
- package/dist/npm/annotations/editors/outliner.d.ts +51 -0
- package/dist/npm/annotations/editors/outliner.js +750 -0
- package/dist/npm/annotations/helpers/annotation-storage.d.ts +98 -0
- package/dist/npm/annotations/helpers/annotation-storage.js +299 -0
- package/dist/npm/annotations/helpers/color-manager.d.ts +6 -0
- package/dist/npm/annotations/helpers/color-manager.js +76 -0
- package/dist/npm/annotations/helpers/command-manager.d.ts +42 -0
- package/dist/npm/annotations/helpers/command-manager.js +137 -0
- package/dist/npm/annotations/helpers/id-manager.d.ts +6 -0
- package/dist/npm/annotations/helpers/id-manager.js +38 -0
- package/dist/npm/annotations/helpers/image-manager.d.ts +18 -0
- package/dist/npm/annotations/helpers/image-manager.js +180 -0
- package/dist/npm/annotations/helpers/text-accessibility-manager.d.ts +36 -0
- package/dist/npm/annotations/helpers/text-accessibility-manager.js +215 -0
- package/dist/npm/annotations/helpers/tools.d.ts +1 -0
- package/dist/npm/annotations/helpers/tools.js +23 -0
- package/dist/npm/annotations/shared/display_utils.d.ts +6 -0
- package/dist/npm/annotations/shared/display_utils.js +1030 -0
- package/dist/npm/annotations/shared/event_utils.d.ts +33 -0
- package/dist/npm/annotations/shared/event_utils.js +165 -0
- package/dist/npm/annotations/shared/murmurhash3.d.ts +8 -0
- package/dist/npm/annotations/shared/murmurhash3.js +129 -0
- package/dist/npm/annotations/shared/scripting_utils.d.ts +17 -0
- package/dist/npm/annotations/shared/scripting_utils.js +93 -0
- package/dist/npm/annotations/shared/ui_utils.d.ts +54 -0
- package/dist/npm/annotations/shared/ui_utils.js +250 -0
- package/dist/npm/annotations/shared/utils.d.ts +148 -0
- package/dist/npm/annotations/shared/utils.js +872 -0
- package/dist/npm/common/component.d.ts +9 -0
- package/dist/npm/common/component.js +37 -0
- package/dist/npm/common/core.d.ts +18 -0
- package/dist/npm/common/core.js +112 -0
- package/dist/npm/common/dom.d.ts +3 -0
- package/dist/npm/common/dom.js +17 -0
- package/dist/npm/common/main.d.ts +4 -0
- package/dist/npm/common/main.js +7 -0
- package/dist/npm/common/math.d.ts +1 -0
- package/dist/npm/common/math.js +5 -0
- package/dist/npm/enums/PdfViewerInteractionMode.d.ts +4 -0
- package/dist/npm/enums/PdfViewerInteractionMode.js +9 -0
- package/dist/npm/links/link-service.d.ts +116 -0
- package/dist/npm/links/link-service.js +501 -0
- package/dist/npm/main.d.ts +2 -0
- package/dist/npm/main.js +2 -0
- package/dist/npm/scroller.d.ts +7 -3
- package/dist/npm/scroller.js +32 -32
- package/dist/npm/text/text-layer-builder.d.ts +30 -0
- package/dist/npm/text/text-layer-builder.js +291 -0
- package/dist/npm/utils.d.ts +20 -2
- package/dist/npm/utils.js +11 -8
- package/dist/npm/widget/page.d.ts +75 -0
- package/dist/npm/widget/page.js +763 -0
- package/dist/npm/widget/pdfviewer.d.ts +222 -0
- package/dist/npm/widget/pdfviewer.js +1663 -0
- package/package.json +13 -9
|
@@ -0,0 +1,783 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright 2022 Mozilla Foundation
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
var _AnnotationEditorLayer_instances, _a, _AnnotationEditorLayer_accessibilityManager, _AnnotationEditorLayer_allowClick, _AnnotationEditorLayer_annotationLayer, _AnnotationEditorLayer_clickAC, _AnnotationEditorLayer_editorFocusTimeoutId, _AnnotationEditorLayer_editors, _AnnotationEditorLayer_hadPointerDown, _AnnotationEditorLayer_isCleaningUp, _AnnotationEditorLayer_isDisabling, _AnnotationEditorLayer_textLayer, _AnnotationEditorLayer_textSelectionAC, _AnnotationEditorLayer_uiManager, _AnnotationEditorLayer_editorTypes, _AnnotationEditorLayer_textLayerPointerDown, _AnnotationEditorLayer_currentEditorType_get, _AnnotationEditorLayer_createNewEditor, _AnnotationEditorLayer_getCenterPoint, _AnnotationEditorLayer_cleanup;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AnnotationEditorLayer = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
// eslint-disable-next-line max-len
|
|
21
|
+
/** @typedef {import("./tools.js").AnnotationEditorUIManager} AnnotationEditorUIManager */
|
|
22
|
+
/** @typedef {import("../display_utils.js").PageViewport} PageViewport */
|
|
23
|
+
// eslint-disable-next-line max-len
|
|
24
|
+
/** @typedef {import("../../../web/text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */
|
|
25
|
+
/** @typedef {import("../../../web/interfaces").IL10n} IL10n */
|
|
26
|
+
// eslint-disable-next-line max-len
|
|
27
|
+
/** @typedef {import("../annotation_layer.js").AnnotationLayer} AnnotationLayer */
|
|
28
|
+
/** @typedef {import("../draw_layer.js").DrawLayer} DrawLayer */
|
|
29
|
+
const free_text_editor_1 = require("./editors/free-text-editor");
|
|
30
|
+
const pdf_mjs_1 = require("pdfjs-dist/legacy/build/pdf.mjs");
|
|
31
|
+
const annotation_editor_1 = require("./editors/annotation-editor");
|
|
32
|
+
const highlight_editor_1 = require("./editors/highlight-editor");
|
|
33
|
+
class AnnotationEditorLayer {
|
|
34
|
+
/**
|
|
35
|
+
* @param {AnnotationEditorLayerOptions} options
|
|
36
|
+
*/
|
|
37
|
+
constructor({ uiManager, pageIndex, div, accessibilityManager, annotationLayer, drawLayer, textLayer, viewport
|
|
38
|
+
// l10n
|
|
39
|
+
}) {
|
|
40
|
+
_AnnotationEditorLayer_instances.add(this);
|
|
41
|
+
// todo: props
|
|
42
|
+
this.drawLayer = null;
|
|
43
|
+
this.pageIndex = 0;
|
|
44
|
+
this.div = null;
|
|
45
|
+
this.viewport = null;
|
|
46
|
+
// todo: props
|
|
47
|
+
_AnnotationEditorLayer_accessibilityManager.set(this, void 0);
|
|
48
|
+
_AnnotationEditorLayer_allowClick.set(this, false);
|
|
49
|
+
_AnnotationEditorLayer_annotationLayer.set(this, null);
|
|
50
|
+
_AnnotationEditorLayer_clickAC.set(this, null);
|
|
51
|
+
_AnnotationEditorLayer_editorFocusTimeoutId.set(this, null);
|
|
52
|
+
_AnnotationEditorLayer_editors.set(this, new Map());
|
|
53
|
+
_AnnotationEditorLayer_hadPointerDown.set(this, false);
|
|
54
|
+
_AnnotationEditorLayer_isCleaningUp.set(this, false);
|
|
55
|
+
_AnnotationEditorLayer_isDisabling.set(this, false);
|
|
56
|
+
_AnnotationEditorLayer_textLayer.set(this, null);
|
|
57
|
+
_AnnotationEditorLayer_textSelectionAC.set(this, null);
|
|
58
|
+
_AnnotationEditorLayer_uiManager.set(this, null);
|
|
59
|
+
const editorTypes = [...tslib_1.__classPrivateFieldGet(_a, _a, "f", _AnnotationEditorLayer_editorTypes).values()];
|
|
60
|
+
if (!_a._initialized) {
|
|
61
|
+
_a._initialized = true;
|
|
62
|
+
for (const editorType of editorTypes) {
|
|
63
|
+
// editorType.initialize(l10n, uiManager);
|
|
64
|
+
editorType.initialize({}, uiManager);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
uiManager.registerEditorTypes(editorTypes);
|
|
68
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_uiManager, uiManager, "f");
|
|
69
|
+
this.pageIndex = pageIndex;
|
|
70
|
+
this.div = div;
|
|
71
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_accessibilityManager, accessibilityManager, "f");
|
|
72
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_annotationLayer, annotationLayer, "f");
|
|
73
|
+
this.viewport = viewport;
|
|
74
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_textLayer, textLayer, "f");
|
|
75
|
+
this.drawLayer = drawLayer;
|
|
76
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addLayer(this);
|
|
77
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f") || !tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f")) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// todo: ported from AnnotationEditorLayerBuilder
|
|
82
|
+
hide() {
|
|
83
|
+
if (!this.div) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.div.hidden = true;
|
|
87
|
+
}
|
|
88
|
+
show() {
|
|
89
|
+
if (!this.div || this.isInvisible) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.div.hidden = false;
|
|
93
|
+
}
|
|
94
|
+
// todo: ported from AnnotationEditorLayerBuilder
|
|
95
|
+
get isEmpty() {
|
|
96
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").size === 0;
|
|
97
|
+
}
|
|
98
|
+
get isInvisible() {
|
|
99
|
+
return (this.isEmpty && tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode() === pdf_mjs_1.AnnotationEditorType.NONE);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Update the toolbar if it's required to reflect the tool currently used.
|
|
103
|
+
* @param {number} mode
|
|
104
|
+
*/
|
|
105
|
+
// updateToolbar(mode) {
|
|
106
|
+
updateToolbar() {
|
|
107
|
+
// this.#uiManager.updateToolbar(mode);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The mode has changed: it must be updated.
|
|
111
|
+
* @param {number} mode
|
|
112
|
+
*/
|
|
113
|
+
updateMode(mode = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode()) {
|
|
114
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_cleanup).call(this);
|
|
115
|
+
switch (mode) {
|
|
116
|
+
case pdf_mjs_1.AnnotationEditorType.NONE:
|
|
117
|
+
this.disableTextSelection();
|
|
118
|
+
this.togglePointerEvents(false);
|
|
119
|
+
this.toggleAnnotationLayerPointerEvents(true);
|
|
120
|
+
this.disableClick();
|
|
121
|
+
return;
|
|
122
|
+
case pdf_mjs_1.AnnotationEditorType.INK:
|
|
123
|
+
// We always want to have an ink editor ready to draw in.
|
|
124
|
+
this.addInkEditorIfNeeded(false);
|
|
125
|
+
this.disableTextSelection();
|
|
126
|
+
this.togglePointerEvents(true);
|
|
127
|
+
this.disableClick();
|
|
128
|
+
break;
|
|
129
|
+
case pdf_mjs_1.AnnotationEditorType.HIGHLIGHT:
|
|
130
|
+
this.enableTextSelection();
|
|
131
|
+
this.togglePointerEvents(false);
|
|
132
|
+
this.disableClick();
|
|
133
|
+
break;
|
|
134
|
+
default:
|
|
135
|
+
this.disableTextSelection();
|
|
136
|
+
this.togglePointerEvents(true);
|
|
137
|
+
this.enableClick();
|
|
138
|
+
}
|
|
139
|
+
this.toggleAnnotationLayerPointerEvents(false);
|
|
140
|
+
const { classList } = this.div;
|
|
141
|
+
for (const editorType of tslib_1.__classPrivateFieldGet(_a, _a, "f", _AnnotationEditorLayer_editorTypes).values()) {
|
|
142
|
+
classList.toggle(`${editorType._type}Editing`, mode === editorType._editorType);
|
|
143
|
+
}
|
|
144
|
+
this.div.hidden = false;
|
|
145
|
+
}
|
|
146
|
+
hasTextLayer(textLayer) {
|
|
147
|
+
var _b;
|
|
148
|
+
return textLayer === ((_b = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f")) === null || _b === void 0 ? void 0 : _b.div);
|
|
149
|
+
// return textLayer === this.#textLayer || textLayer === this.#textLayer?.div;
|
|
150
|
+
}
|
|
151
|
+
addInkEditorIfNeeded(isCommitting) {
|
|
152
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode() !== pdf_mjs_1.AnnotationEditorType.INK) {
|
|
153
|
+
// We don't want to add an ink editor if we're not in ink mode!
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (!isCommitting) {
|
|
157
|
+
// We're removing an editor but an empty one can already exist so in this
|
|
158
|
+
// case we don't need to create a new one.
|
|
159
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values()) {
|
|
160
|
+
if (editor.isEmpty()) {
|
|
161
|
+
editor.setInBackground();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const newEditor = this.createAndAddNewEditor({ offsetX: 0, offsetY: 0 },
|
|
167
|
+
/* isCentered = */ false);
|
|
168
|
+
newEditor.setInBackground();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Set the editing state.
|
|
172
|
+
* @param {boolean} isEditing
|
|
173
|
+
*/
|
|
174
|
+
setEditingState(isEditing) {
|
|
175
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").setEditingState(isEditing);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Add some commands into the CommandManager (undo/redo stuff).
|
|
179
|
+
* @param {Object} params
|
|
180
|
+
*/
|
|
181
|
+
addCommands(params) {
|
|
182
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addCommands(params);
|
|
183
|
+
}
|
|
184
|
+
toggleDrawing(enabled = false) {
|
|
185
|
+
this.div.classList.toggle("drawing", !enabled);
|
|
186
|
+
// this.div.classList.toggle("k-drawing", !enabled);
|
|
187
|
+
}
|
|
188
|
+
togglePointerEvents(enabled = false) {
|
|
189
|
+
// this.div.classList.toggle("disabled", !enabled);
|
|
190
|
+
this.div.classList.toggle("k-annotation-editor-layer-disabled", !enabled);
|
|
191
|
+
}
|
|
192
|
+
toggleAnnotationLayerPointerEvents(enabled = false) {
|
|
193
|
+
var _b;
|
|
194
|
+
// this.#annotationLayer?.div.classList.toggle("disabled", !enabled);
|
|
195
|
+
(_b = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f")) === null || _b === void 0 ? void 0 : _b.div.classList.toggle("k-annotation-editor-layer-disabled", !enabled);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Enable pointer events on the main div in order to enable
|
|
199
|
+
* editor creation.
|
|
200
|
+
*/
|
|
201
|
+
enable() {
|
|
202
|
+
this.div.tabIndex = 0;
|
|
203
|
+
this.togglePointerEvents(true);
|
|
204
|
+
const annotationElementIds = new Set();
|
|
205
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values()) {
|
|
206
|
+
editor.enableEditing();
|
|
207
|
+
editor.show(true);
|
|
208
|
+
if (editor.annotationElementId) {
|
|
209
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").removeChangedExistingAnnotation(editor);
|
|
210
|
+
annotationElementIds.add(editor.annotationElementId);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f")) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const editables = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f").getEditableAnnotations();
|
|
217
|
+
for (const editable of editables) {
|
|
218
|
+
// The element must be hidden whatever its state is.
|
|
219
|
+
editable.hide();
|
|
220
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").isDeletedAnnotationElement(editable.data.id)) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (annotationElementIds.has(editable.data.id)) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const editor = this.deserialize(editable);
|
|
227
|
+
if (!editor) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
this.addOrRebuild(editor);
|
|
231
|
+
editor.enableEditing();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Disable editor creation.
|
|
236
|
+
*/
|
|
237
|
+
disable() {
|
|
238
|
+
var _b;
|
|
239
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_isDisabling, true, "f");
|
|
240
|
+
this.div.tabIndex = -1;
|
|
241
|
+
this.togglePointerEvents(false);
|
|
242
|
+
const changedAnnotations = new Map();
|
|
243
|
+
const resetAnnotations = new Map();
|
|
244
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values()) {
|
|
245
|
+
editor.disableEditing();
|
|
246
|
+
if (!editor.annotationElementId) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (editor.serialize() !== null) {
|
|
250
|
+
changedAnnotations.set(editor.annotationElementId, editor);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
resetAnnotations.set(editor.annotationElementId, editor);
|
|
255
|
+
}
|
|
256
|
+
(_b = this.getEditableAnnotation(editor.annotationElementId)) === null || _b === void 0 ? void 0 : _b.show();
|
|
257
|
+
editor.remove();
|
|
258
|
+
}
|
|
259
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f")) {
|
|
260
|
+
// Show the annotations that were hidden in enable().
|
|
261
|
+
const editables = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f").getEditableAnnotations();
|
|
262
|
+
for (const editable of editables) {
|
|
263
|
+
const { id } = editable.data;
|
|
264
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").isDeletedAnnotationElement(id)) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
let editor = resetAnnotations.get(id);
|
|
268
|
+
if (editor) {
|
|
269
|
+
editor.resetAnnotationElement(editable);
|
|
270
|
+
editor.show(false);
|
|
271
|
+
editable.show();
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
editor = changedAnnotations.get(id);
|
|
275
|
+
if (editor) {
|
|
276
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addChangedExistingAnnotation(editor);
|
|
277
|
+
editor.renderAnnotationElement(editable);
|
|
278
|
+
editor.show(false);
|
|
279
|
+
}
|
|
280
|
+
editable.show();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_cleanup).call(this);
|
|
284
|
+
if (this.isEmpty) {
|
|
285
|
+
this.div.hidden = true;
|
|
286
|
+
}
|
|
287
|
+
const { classList } = this.div;
|
|
288
|
+
for (const editorType of tslib_1.__classPrivateFieldGet(_a, _a, "f", _AnnotationEditorLayer_editorTypes).values()) {
|
|
289
|
+
classList.remove(`${editorType._type}Editing`);
|
|
290
|
+
}
|
|
291
|
+
this.disableTextSelection();
|
|
292
|
+
this.toggleAnnotationLayerPointerEvents(true);
|
|
293
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_isDisabling, false, "f");
|
|
294
|
+
}
|
|
295
|
+
getEditableAnnotation(id) {
|
|
296
|
+
var _b;
|
|
297
|
+
return ((_b = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_annotationLayer, "f")) === null || _b === void 0 ? void 0 : _b.getEditableAnnotation(id)) || null;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Set the current editor.
|
|
301
|
+
* @param {AnnotationEditor} editor
|
|
302
|
+
*/
|
|
303
|
+
setActiveEditor(editor) {
|
|
304
|
+
const currentActive = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getActive();
|
|
305
|
+
if (currentActive === editor) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").setActiveEditor(editor);
|
|
309
|
+
}
|
|
310
|
+
enableTextSelection() {
|
|
311
|
+
var _b;
|
|
312
|
+
this.div.tabIndex = -1;
|
|
313
|
+
if (((_b = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f")) === null || _b === void 0 ? void 0 : _b.div) && !tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textSelectionAC, "f")) {
|
|
314
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_textSelectionAC, new AbortController(), "f");
|
|
315
|
+
const signal = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").combinedSignal(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textSelectionAC, "f"));
|
|
316
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div.addEventListener("pointerdown", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_textLayerPointerDown).bind(this), { signal });
|
|
317
|
+
// this.#textLayer.div.classList.add("highlighting");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
disableTextSelection() {
|
|
321
|
+
var _b;
|
|
322
|
+
this.div.tabIndex = 0;
|
|
323
|
+
if (((_b = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f")) === null || _b === void 0 ? void 0 : _b.div) && tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textSelectionAC, "f")) {
|
|
324
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textSelectionAC, "f").abort();
|
|
325
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_textSelectionAC, null, "f");
|
|
326
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div.classList.remove("highlighting");
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
enableClick() {
|
|
330
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_clickAC, "f")) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_clickAC, new AbortController(), "f");
|
|
334
|
+
const signal = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").combinedSignal(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_clickAC, "f"));
|
|
335
|
+
this.div.addEventListener("pointerdown", this.pointerdown.bind(this), {
|
|
336
|
+
signal,
|
|
337
|
+
});
|
|
338
|
+
this.div.addEventListener("pointerup", this.pointerup.bind(this), {
|
|
339
|
+
signal,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
disableClick() {
|
|
343
|
+
var _b;
|
|
344
|
+
(_b = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_clickAC, "f")) === null || _b === void 0 ? void 0 : _b.abort();
|
|
345
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_clickAC, null, "f");
|
|
346
|
+
}
|
|
347
|
+
attach(editor) {
|
|
348
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").set(editor.id, editor);
|
|
349
|
+
const { annotationElementId } = editor;
|
|
350
|
+
if (annotationElementId &&
|
|
351
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").isDeletedAnnotationElement(annotationElementId)) {
|
|
352
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").removeDeletedAnnotationElement(editor);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
detach(editor) {
|
|
356
|
+
var _b;
|
|
357
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").delete(editor.id);
|
|
358
|
+
(_b = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_accessibilityManager, "f")) === null || _b === void 0 ? void 0 : _b.removePointerInTextLayer(editor.contentDiv);
|
|
359
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_isDisabling, "f") && editor.annotationElementId) {
|
|
360
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addDeletedAnnotationElement(editor);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Remove an editor.
|
|
365
|
+
* @param {AnnotationEditor} editor
|
|
366
|
+
*/
|
|
367
|
+
remove(editor) {
|
|
368
|
+
this.detach(editor);
|
|
369
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").removeEditor(editor);
|
|
370
|
+
editor.div.remove();
|
|
371
|
+
editor.isAttachedToDOM = false;
|
|
372
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_isCleaningUp, "f")) {
|
|
373
|
+
this.addInkEditorIfNeeded(/* isCommitting = */ false);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* An editor can have a different parent, for example after having
|
|
378
|
+
* being dragged and droped from a page to another.
|
|
379
|
+
* @param {AnnotationEditor} editor
|
|
380
|
+
*/
|
|
381
|
+
changeParent(editor) {
|
|
382
|
+
var _b;
|
|
383
|
+
if (editor.parent === this) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (editor.parent && editor.annotationElementId) {
|
|
387
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addDeletedAnnotationElement(editor.annotationElementId);
|
|
388
|
+
annotation_editor_1.AnnotationEditor.deleteAnnotationElement(editor);
|
|
389
|
+
editor.annotationElementId = null;
|
|
390
|
+
}
|
|
391
|
+
this.attach(editor);
|
|
392
|
+
(_b = editor.parent) === null || _b === void 0 ? void 0 : _b.detach(editor);
|
|
393
|
+
editor.setParent(this);
|
|
394
|
+
if (editor.div && editor.isAttachedToDOM) {
|
|
395
|
+
editor.div.remove();
|
|
396
|
+
this.div.append(editor.div);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Add a new editor in the current view.
|
|
401
|
+
* @param {AnnotationEditor} editor
|
|
402
|
+
*/
|
|
403
|
+
add(editor) {
|
|
404
|
+
if (editor.parent === this && editor.isAttachedToDOM) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
this.changeParent(editor);
|
|
408
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addEditor(editor);
|
|
409
|
+
this.attach(editor);
|
|
410
|
+
if (!editor.isAttachedToDOM) {
|
|
411
|
+
const div = editor.render();
|
|
412
|
+
this.div.append(div);
|
|
413
|
+
editor.isAttachedToDOM = true;
|
|
414
|
+
}
|
|
415
|
+
// The editor will be correctly moved into the DOM (see fixAndSetPosition).
|
|
416
|
+
editor.fixAndSetPosition();
|
|
417
|
+
editor.onceAdded();
|
|
418
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").addToAnnotationStorage(editor);
|
|
419
|
+
// editor._reportTelemetry(editor.telemetryInitialData);
|
|
420
|
+
// todo: this differs from pdf.js
|
|
421
|
+
// this.setActiveEditor(editor);
|
|
422
|
+
}
|
|
423
|
+
moveEditorInDOM(editor) {
|
|
424
|
+
var _b;
|
|
425
|
+
if (!editor.isAttachedToDOM) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const { activeElement } = document;
|
|
429
|
+
if (editor.div.contains(activeElement) && !tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editorFocusTimeoutId, "f")) {
|
|
430
|
+
// When the div is moved in the DOM the focus can move somewhere else,
|
|
431
|
+
// so we want to be sure that the focus will stay on the editor but we
|
|
432
|
+
// don't want to call any focus callbacks, hence we disable them and only
|
|
433
|
+
// re-enable them when the editor has the focus.
|
|
434
|
+
editor._focusEventsAllowed = false;
|
|
435
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_editorFocusTimeoutId, setTimeout(() => {
|
|
436
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_editorFocusTimeoutId, null, "f");
|
|
437
|
+
if (!editor.div.contains(document.activeElement)) {
|
|
438
|
+
editor.div.addEventListener("focusin", () => {
|
|
439
|
+
editor._focusEventsAllowed = true;
|
|
440
|
+
}, { once: true, signal: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f")._signal });
|
|
441
|
+
activeElement.focus();
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
editor._focusEventsAllowed = true;
|
|
445
|
+
}
|
|
446
|
+
}, 0), "f");
|
|
447
|
+
}
|
|
448
|
+
editor._structTreeParentId = (_b = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_accessibilityManager, "f")) === null || _b === void 0 ? void 0 : _b.moveElementInDOM(this.div, editor.div, editor.contentDiv,
|
|
449
|
+
/* isRemovable = */ true);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Add or rebuild depending if it has been removed or not.
|
|
453
|
+
* @param {AnnotationEditor} editor
|
|
454
|
+
*/
|
|
455
|
+
addOrRebuild(editor) {
|
|
456
|
+
if (editor.needsToBeRebuilt()) {
|
|
457
|
+
editor.parent || (editor.parent = this);
|
|
458
|
+
editor.rebuild();
|
|
459
|
+
editor.show();
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
this.add(editor);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Add a new editor and make this addition undoable.
|
|
467
|
+
* @param {AnnotationEditor} editor
|
|
468
|
+
*/
|
|
469
|
+
addUndoableEditor(editor) {
|
|
470
|
+
const cmd = () => editor._uiManager.rebuild(editor);
|
|
471
|
+
const undo = () => {
|
|
472
|
+
editor.remove();
|
|
473
|
+
};
|
|
474
|
+
this.addCommands({ cmd, undo, mustExec: false });
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Get an id for an editor.
|
|
478
|
+
* @returns {string}
|
|
479
|
+
*/
|
|
480
|
+
getNextId() {
|
|
481
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getId();
|
|
482
|
+
}
|
|
483
|
+
combinedSignal(abortController) {
|
|
484
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").combinedSignal(abortController);
|
|
485
|
+
}
|
|
486
|
+
canCreateNewEmptyEditor() {
|
|
487
|
+
var _b;
|
|
488
|
+
return (_b = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "a", _AnnotationEditorLayer_currentEditorType_get)) === null || _b === void 0 ? void 0 : _b.canCreateNewEmptyEditor();
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Paste some content into a new editor.
|
|
492
|
+
* @param {number} mode
|
|
493
|
+
* @param {Object} params
|
|
494
|
+
*/
|
|
495
|
+
pasteEditor(mode, params) {
|
|
496
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").updateToolbar(mode);
|
|
497
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").updateMode(mode);
|
|
498
|
+
const { offsetX, offsetY } = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_getCenterPoint).call(this);
|
|
499
|
+
const id = this.getNextId();
|
|
500
|
+
const editor = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_createNewEditor).call(this, Object.assign({ parent: this, id, x: offsetX, y: offsetY, uiManager: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f"), isCentered: true }, params));
|
|
501
|
+
if (editor) {
|
|
502
|
+
this.add(editor);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Create a new editor
|
|
507
|
+
* @param {Object} data
|
|
508
|
+
* @returns {AnnotationEditor | null}
|
|
509
|
+
*/
|
|
510
|
+
deserialize(data) {
|
|
511
|
+
var _b, _c;
|
|
512
|
+
return (((_c = tslib_1.__classPrivateFieldGet(_a, _a, "f", _AnnotationEditorLayer_editorTypes)
|
|
513
|
+
.get((_b = data.annotationType) !== null && _b !== void 0 ? _b : data.annotationEditorType)) === null || _c === void 0 ? void 0 : _c.deserialize(data, this, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f"))) || null);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Create and add a new editor.
|
|
517
|
+
* @param {PointerEvent} event
|
|
518
|
+
* @param {boolean} isCentered
|
|
519
|
+
* @param [Object] data
|
|
520
|
+
* @returns {AnnotationEditor}
|
|
521
|
+
*/
|
|
522
|
+
createAndAddNewEditor(event, isCentered, data = {}) {
|
|
523
|
+
const id = this.getNextId();
|
|
524
|
+
const editor = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_createNewEditor).call(this, Object.assign({ parent: this, id, x: event.offsetX, y: event.offsetY, uiManager: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f"), isCentered }, data));
|
|
525
|
+
if (editor) {
|
|
526
|
+
this.add(editor);
|
|
527
|
+
}
|
|
528
|
+
return editor;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Create and add a new editor.
|
|
532
|
+
*/
|
|
533
|
+
addNewEditor() {
|
|
534
|
+
this.createAndAddNewEditor(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_getCenterPoint).call(this), /* isCentered = */ true);
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Set the last selected editor.
|
|
538
|
+
* @param {AnnotationEditor} editor
|
|
539
|
+
*/
|
|
540
|
+
setSelected(editor) {
|
|
541
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").setSelected(editor);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Add or remove an editor the current selection.
|
|
545
|
+
* @param {AnnotationEditor} editor
|
|
546
|
+
*/
|
|
547
|
+
toggleSelected(editor) {
|
|
548
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").toggleSelected(editor);
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Check if the editor is selected.
|
|
552
|
+
* @param {AnnotationEditor} editor
|
|
553
|
+
*/
|
|
554
|
+
isSelected(editor) {
|
|
555
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").isSelected(editor);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Unselect an editor.
|
|
559
|
+
* @param {AnnotationEditor} editor
|
|
560
|
+
*/
|
|
561
|
+
unselect(editor) {
|
|
562
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").unselect(editor);
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Pointerup callback.
|
|
566
|
+
* @param {PointerEvent} event
|
|
567
|
+
*/
|
|
568
|
+
pointerup(event) {
|
|
569
|
+
const { isMac } = pdf_mjs_1.FeatureTest.platform;
|
|
570
|
+
if (event.button !== 0 || (event.ctrlKey && isMac)) {
|
|
571
|
+
// Don't create an editor on right click.
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
if (event.target !== this.div) {
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_hadPointerDown, "f")) {
|
|
578
|
+
// It can happen when the user starts a drag inside a text editor
|
|
579
|
+
// and then releases the mouse button outside of it. In such a case
|
|
580
|
+
// we don't want to create a new editor, hence we check that a pointerdown
|
|
581
|
+
// occurred on this div previously.
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_hadPointerDown, false, "f");
|
|
585
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_allowClick, "f")) {
|
|
586
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_allowClick, true, "f");
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode() === pdf_mjs_1.AnnotationEditorType.STAMP) {
|
|
590
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").unselectAll();
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
this.createAndAddNewEditor(event, /* isCentered = */ false);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Pointerdown callback.
|
|
597
|
+
* @param {PointerEvent} event
|
|
598
|
+
*/
|
|
599
|
+
pointerdown(event) {
|
|
600
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode() === pdf_mjs_1.AnnotationEditorType.HIGHLIGHT) {
|
|
601
|
+
this.enableTextSelection();
|
|
602
|
+
}
|
|
603
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_hadPointerDown, "f")) {
|
|
604
|
+
// It's possible to have a second pointerdown event before a pointerup one
|
|
605
|
+
// when the user puts a finger on a touchscreen and then add a second one
|
|
606
|
+
// to start a pinch-to-zoom gesture.
|
|
607
|
+
// That said, in case it's possible to have two pointerdown events with
|
|
608
|
+
// a mouse, we don't want to create a new editor in such a case either.
|
|
609
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_hadPointerDown, false, "f");
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
const { isMac } = pdf_mjs_1.FeatureTest.platform;
|
|
613
|
+
if (event.button !== 0 || (event.ctrlKey && isMac)) {
|
|
614
|
+
// Do nothing on right click.
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
if (event.target !== this.div) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_hadPointerDown, true, "f");
|
|
621
|
+
const editor = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getActive();
|
|
622
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_allowClick, !editor || editor.isEmpty(), "f");
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
*
|
|
626
|
+
* @param {AnnotationEditor} editor
|
|
627
|
+
* @param {number} x
|
|
628
|
+
* @param {number} y
|
|
629
|
+
* @returns
|
|
630
|
+
*/
|
|
631
|
+
findNewParent(editor, x, y) {
|
|
632
|
+
const layer = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").findParent(x, y);
|
|
633
|
+
if (layer === null || layer === this) {
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
layer.changeParent(editor);
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Destroy the main editor.
|
|
641
|
+
*/
|
|
642
|
+
destroy() {
|
|
643
|
+
var _b, _c;
|
|
644
|
+
if (((_b = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getActive()) === null || _b === void 0 ? void 0 : _b.parent) === this) {
|
|
645
|
+
// We need to commit the current editor before destroying the layer.
|
|
646
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").commitOrRemove();
|
|
647
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").setActiveEditor(null);
|
|
648
|
+
}
|
|
649
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editorFocusTimeoutId, "f")) {
|
|
650
|
+
clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editorFocusTimeoutId, "f"));
|
|
651
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_editorFocusTimeoutId, null, "f");
|
|
652
|
+
}
|
|
653
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values()) {
|
|
654
|
+
(_c = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_accessibilityManager, "f")) === null || _c === void 0 ? void 0 : _c.removePointerInTextLayer(editor.contentDiv);
|
|
655
|
+
editor.setParent(null);
|
|
656
|
+
editor.isAttachedToDOM = false;
|
|
657
|
+
editor.div.remove();
|
|
658
|
+
}
|
|
659
|
+
this.div = null;
|
|
660
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").clear();
|
|
661
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").removeLayer(this);
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Render the main editor.
|
|
665
|
+
* @param {RenderEditorLayerOptions} parameters
|
|
666
|
+
*/
|
|
667
|
+
render({ viewport }) {
|
|
668
|
+
this.viewport = viewport;
|
|
669
|
+
(0, pdf_mjs_1.setLayerDimensions)(this.div, viewport);
|
|
670
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getEditors(this.pageIndex)) {
|
|
671
|
+
this.add(editor);
|
|
672
|
+
editor.rebuild();
|
|
673
|
+
}
|
|
674
|
+
// We're maybe rendering a layer which was invisible when we started to edit
|
|
675
|
+
// so we must set the different callbacks for it.
|
|
676
|
+
this.updateMode();
|
|
677
|
+
}
|
|
678
|
+
// /**
|
|
679
|
+
// * Update the main editor.
|
|
680
|
+
// * @param {RenderEditorLayerOptions} parameters
|
|
681
|
+
// */
|
|
682
|
+
update({ viewport }) {
|
|
683
|
+
// Editors have their dimensions/positions in percent so to avoid any
|
|
684
|
+
// issues (see #15582), we must commit the current one before changing
|
|
685
|
+
// the viewport.
|
|
686
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").commitOrRemove();
|
|
687
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "m", _AnnotationEditorLayer_cleanup).call(this);
|
|
688
|
+
const oldRotation = this.viewport.rotation;
|
|
689
|
+
const rotation = viewport.rotation;
|
|
690
|
+
this.viewport = viewport;
|
|
691
|
+
// setLayerDimensions(this.div, { rotation });
|
|
692
|
+
// todo: fix parameters
|
|
693
|
+
// setLayerDimensions(this.div, { rotation } as PageViewport);
|
|
694
|
+
(0, pdf_mjs_1.setLayerDimensions)(this.div, viewport);
|
|
695
|
+
if (oldRotation !== rotation) {
|
|
696
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values()) {
|
|
697
|
+
editor.rotate(rotation);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
this.addInkEditorIfNeeded(/* isCommitting = */ false);
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Get page dimensions.
|
|
704
|
+
* @returns {Object} dimensions.
|
|
705
|
+
*/
|
|
706
|
+
get pageDimensions() {
|
|
707
|
+
const { pageWidth, pageHeight } = this.viewport.rawDims;
|
|
708
|
+
return [pageWidth, pageHeight];
|
|
709
|
+
}
|
|
710
|
+
get scale() {
|
|
711
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").viewParameters.realScale;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
exports.AnnotationEditorLayer = AnnotationEditorLayer;
|
|
715
|
+
_a = AnnotationEditorLayer, _AnnotationEditorLayer_accessibilityManager = new WeakMap(), _AnnotationEditorLayer_allowClick = new WeakMap(), _AnnotationEditorLayer_annotationLayer = new WeakMap(), _AnnotationEditorLayer_clickAC = new WeakMap(), _AnnotationEditorLayer_editorFocusTimeoutId = new WeakMap(), _AnnotationEditorLayer_editors = new WeakMap(), _AnnotationEditorLayer_hadPointerDown = new WeakMap(), _AnnotationEditorLayer_isCleaningUp = new WeakMap(), _AnnotationEditorLayer_isDisabling = new WeakMap(), _AnnotationEditorLayer_textLayer = new WeakMap(), _AnnotationEditorLayer_textSelectionAC = new WeakMap(), _AnnotationEditorLayer_uiManager = new WeakMap(), _AnnotationEditorLayer_instances = new WeakSet(), _AnnotationEditorLayer_textLayerPointerDown = function _AnnotationEditorLayer_textLayerPointerDown(event) {
|
|
716
|
+
// Unselect all the editors in order to let the user select some text
|
|
717
|
+
// without being annoyed by an editor toolbar.
|
|
718
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").unselectAll();
|
|
719
|
+
const { target } = event;
|
|
720
|
+
if (target === tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div ||
|
|
721
|
+
(target.classList.contains("endOfContent") && tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div.contains(target))) {
|
|
722
|
+
const { isMac } = pdf_mjs_1.FeatureTest.platform;
|
|
723
|
+
if (event.button !== 0 || (event.ctrlKey && isMac)) {
|
|
724
|
+
// Do nothing on right click.
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").showAllEditors("highlight", true);
|
|
728
|
+
// if (this.#uiManager.getMode() === AnnotationEditorType.HIGHLIGHT) {
|
|
729
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode() === pdf_mjs_1.AnnotationEditorType.NONE) {
|
|
730
|
+
// todo: do not continue with free highlight
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
// this.#textLayer.div.classList.add("free");
|
|
734
|
+
// todo: intentionally prevent free highlight
|
|
735
|
+
// this.toggleDrawing();
|
|
736
|
+
// HighlightEditor.startHighlighting(
|
|
737
|
+
// this,
|
|
738
|
+
// this.#uiManager.direction === "ltr",
|
|
739
|
+
// event
|
|
740
|
+
// );
|
|
741
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div.addEventListener("pointerup", () => {
|
|
742
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_textLayer, "f").div.classList.remove("free");
|
|
743
|
+
this.toggleDrawing(true);
|
|
744
|
+
}, { once: true, signal: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f")._signal });
|
|
745
|
+
event.preventDefault();
|
|
746
|
+
}
|
|
747
|
+
}, _AnnotationEditorLayer_currentEditorType_get = function _AnnotationEditorLayer_currentEditorType_get() {
|
|
748
|
+
return tslib_1.__classPrivateFieldGet(_a, _a, "f", _AnnotationEditorLayer_editorTypes).get(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_uiManager, "f").getMode());
|
|
749
|
+
}, _AnnotationEditorLayer_createNewEditor = function _AnnotationEditorLayer_createNewEditor(params) {
|
|
750
|
+
const editorType = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_instances, "a", _AnnotationEditorLayer_currentEditorType_get);
|
|
751
|
+
// return editorType ? new editorType.prototype.constructor(params) : null;
|
|
752
|
+
return editorType ? new editorType(params) : null;
|
|
753
|
+
}, _AnnotationEditorLayer_getCenterPoint = function _AnnotationEditorLayer_getCenterPoint() {
|
|
754
|
+
const { x, y, width, height } = this.div.getBoundingClientRect();
|
|
755
|
+
const tlX = Math.max(0, x);
|
|
756
|
+
const tlY = Math.max(0, y);
|
|
757
|
+
const brX = Math.min(window.innerWidth, x + width);
|
|
758
|
+
const brY = Math.min(window.innerHeight, y + height);
|
|
759
|
+
const centerX = (tlX + brX) / 2 - x;
|
|
760
|
+
const centerY = (tlY + brY) / 2 - y;
|
|
761
|
+
const [offsetX, offsetY] = this.viewport.rotation % 180 === 0
|
|
762
|
+
? [centerX, centerY]
|
|
763
|
+
: [centerY, centerX];
|
|
764
|
+
return { offsetX, offsetY };
|
|
765
|
+
}, _AnnotationEditorLayer_cleanup = function _AnnotationEditorLayer_cleanup() {
|
|
766
|
+
// When we're cleaning up, some editors are removed but we don't want
|
|
767
|
+
// to add a new one which will induce an addition in this.#editors, hence
|
|
768
|
+
// an infinite loop.
|
|
769
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_isCleaningUp, true, "f");
|
|
770
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorLayer_editors, "f").values()) {
|
|
771
|
+
if (editor.isEmpty()) {
|
|
772
|
+
editor.remove();
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorLayer_isCleaningUp, false, "f");
|
|
776
|
+
};
|
|
777
|
+
AnnotationEditorLayer._initialized = false;
|
|
778
|
+
_AnnotationEditorLayer_editorTypes = { value: new Map(
|
|
779
|
+
// [FreeTextEditor, InkEditor, StampEditor, HighlightEditor].map(type => [
|
|
780
|
+
[free_text_editor_1.FreeTextEditor, highlight_editor_1.HighlightEditor].map(type => [
|
|
781
|
+
type._editorType,
|
|
782
|
+
type
|
|
783
|
+
])) };
|