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