@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,1694 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright 2014 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 _AnnotationEditorUIManager_instances, _AnnotationEditorUIManager_abortController, _AnnotationEditorUIManager_activeEditor, _AnnotationEditorUIManager_allEditors, _AnnotationEditorUIManager_allLayers, _AnnotationEditorUIManager_annotationStorage, _AnnotationEditorUIManager_changedExistingAnnotations, _AnnotationEditorUIManager_commandManager, _AnnotationEditorUIManager_currentPageIndex, _AnnotationEditorUIManager_deletedAnnotationsElementIds, _AnnotationEditorUIManager_draggingEditors, _AnnotationEditorUIManager_editorTypes, _AnnotationEditorUIManager_editorsToRescale, _AnnotationEditorUIManager_enableHighlightFloatingButton, _AnnotationEditorUIManager_focusMainContainerTimeoutId, _AnnotationEditorUIManager_focusManagerAC, _AnnotationEditorUIManager_highlightColors, _AnnotationEditorUIManager_highlightWhenShiftUp, _AnnotationEditorUIManager_highlightToolbar, _AnnotationEditorUIManager_idManager, _AnnotationEditorUIManager_isEnabled, _AnnotationEditorUIManager_isWaiting, _AnnotationEditorUIManager_lastActiveElement, _AnnotationEditorUIManager_mode, _AnnotationEditorUIManager_selectedEditors, _AnnotationEditorUIManager_selectedTextNode, _AnnotationEditorUIManager_showAllStates, _AnnotationEditorUIManager_previousStates, _AnnotationEditorUIManager_translation, _AnnotationEditorUIManager_translationTimeoutId, _AnnotationEditorUIManager_container, _AnnotationEditorUIManager_viewer, _AnnotationEditorUIManager_getAnchorElementForSelection, _AnnotationEditorUIManager_getLayerForTextLayer, _AnnotationEditorUIManager_displayHighlightToolbar, _AnnotationEditorUIManager_selectionChange, _AnnotationEditorUIManager_onSelectEnd, _AnnotationEditorUIManager_addSelectionListener, _AnnotationEditorUIManager_addFocusManager, _AnnotationEditorUIManager_removeFocusManager, _AnnotationEditorUIManager_addKeyboardManager, _AnnotationEditorUIManager_removeKeyboardManager, _AnnotationEditorUIManager_addCopyPasteListeners, _AnnotationEditorUIManager_removeCopyPasteListeners, _AnnotationEditorUIManager_addDragAndDropListeners, _AnnotationEditorUIManager_dispatchUpdateStates, _AnnotationEditorUIManager_dispatchUpdateUI, _AnnotationEditorUIManager_enableAll, _AnnotationEditorUIManager_disableAll, _AnnotationEditorUIManager_addEditorToLayer, _AnnotationEditorUIManager_lastSelectedEditor_get, _AnnotationEditorUIManager_isEmpty, _AnnotationEditorUIManager_selectEditors;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AnnotationEditorUIManager = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
// import { PixelsPerInch, shadow } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
21
|
+
const pdf_mjs_1 = require("pdfjs-dist/legacy/build/pdf.mjs");
|
|
22
|
+
// import { CommandManager } from "./helpers/command-manager";
|
|
23
|
+
const id_manager_1 = require("./helpers/id-manager");
|
|
24
|
+
// import { AnnotationEditorType } from "../shared/utils";
|
|
25
|
+
const command_manager_1 = require("./helpers/command-manager");
|
|
26
|
+
// import { ImageManager } from "./helpers/image-manager";
|
|
27
|
+
class AnnotationEditorUIManager {
|
|
28
|
+
// static get _keyboardManager() {
|
|
29
|
+
// const proto = AnnotationEditorUIManager.prototype;
|
|
30
|
+
// /**
|
|
31
|
+
// * If the focused element is an input, we don't want to handle the arrow.
|
|
32
|
+
// * For example, sliders can be controlled with the arrow keys.
|
|
33
|
+
// */
|
|
34
|
+
// const arrowChecker = self =>
|
|
35
|
+
// self.#container.contains(document.activeElement) &&
|
|
36
|
+
// document.activeElement.tagName !== "BUTTON" &&
|
|
37
|
+
// self.hasSomethingToControl();
|
|
38
|
+
// const textInputChecker = (_self, { target: el }) => {
|
|
39
|
+
// if (el instanceof HTMLInputElement) {
|
|
40
|
+
// const { type } = el;
|
|
41
|
+
// return type !== "text" && type !== "number";
|
|
42
|
+
// }
|
|
43
|
+
// return true;
|
|
44
|
+
// };
|
|
45
|
+
// const small = this.TRANSLATE_SMALL;
|
|
46
|
+
// const big = this.TRANSLATE_BIG;
|
|
47
|
+
// return shadow(
|
|
48
|
+
// this,
|
|
49
|
+
// "_keyboardManager",
|
|
50
|
+
// new KeyboardManager([
|
|
51
|
+
// [
|
|
52
|
+
// ["ctrl+a", "mac+meta+a"],
|
|
53
|
+
// proto.selectAll,
|
|
54
|
+
// { checker: textInputChecker },
|
|
55
|
+
// ],
|
|
56
|
+
// [["ctrl+z", "mac+meta+z"], proto.undo, { checker: textInputChecker }],
|
|
57
|
+
// [
|
|
58
|
+
// // On mac, depending of the OS version, the event.key is either "z" or
|
|
59
|
+
// // "Z" when the user presses "meta+shift+z".
|
|
60
|
+
// [
|
|
61
|
+
// "ctrl+y",
|
|
62
|
+
// "ctrl+shift+z",
|
|
63
|
+
// "mac+meta+shift+z",
|
|
64
|
+
// "ctrl+shift+Z",
|
|
65
|
+
// "mac+meta+shift+Z",
|
|
66
|
+
// ],
|
|
67
|
+
// proto.redo,
|
|
68
|
+
// { checker: textInputChecker },
|
|
69
|
+
// ],
|
|
70
|
+
// [
|
|
71
|
+
// [
|
|
72
|
+
// "Backspace",
|
|
73
|
+
// "alt+Backspace",
|
|
74
|
+
// "ctrl+Backspace",
|
|
75
|
+
// "shift+Backspace",
|
|
76
|
+
// "mac+Backspace",
|
|
77
|
+
// "mac+alt+Backspace",
|
|
78
|
+
// "mac+ctrl+Backspace",
|
|
79
|
+
// "Delete",
|
|
80
|
+
// "ctrl+Delete",
|
|
81
|
+
// "shift+Delete",
|
|
82
|
+
// "mac+Delete",
|
|
83
|
+
// ],
|
|
84
|
+
// proto.delete,
|
|
85
|
+
// { checker: textInputChecker },
|
|
86
|
+
// ],
|
|
87
|
+
// [
|
|
88
|
+
// ["Enter", "mac+Enter"],
|
|
89
|
+
// proto.addNewEditorFromKeyboard,
|
|
90
|
+
// {
|
|
91
|
+
// // Those shortcuts can be used in the toolbar for some other actions
|
|
92
|
+
// // like zooming, hence we need to check if the container has the
|
|
93
|
+
// // focus.
|
|
94
|
+
// checker: (self, { target: el }) =>
|
|
95
|
+
// !(el instanceof HTMLButtonElement) &&
|
|
96
|
+
// self.#container.contains(el) &&
|
|
97
|
+
// !self.isEnterHandled,
|
|
98
|
+
// },
|
|
99
|
+
// ],
|
|
100
|
+
// [
|
|
101
|
+
// [" ", "mac+ "],
|
|
102
|
+
// proto.addNewEditorFromKeyboard,
|
|
103
|
+
// {
|
|
104
|
+
// // Those shortcuts can be used in the toolbar for some other actions
|
|
105
|
+
// // like zooming, hence we need to check if the container has the
|
|
106
|
+
// // focus.
|
|
107
|
+
// checker: (self, { target: el }) =>
|
|
108
|
+
// !(el instanceof HTMLButtonElement) &&
|
|
109
|
+
// self.#container.contains(document.activeElement),
|
|
110
|
+
// },
|
|
111
|
+
// ],
|
|
112
|
+
// [["Escape", "mac+Escape"], proto.unselectAll],
|
|
113
|
+
// [
|
|
114
|
+
// ["ArrowLeft", "mac+ArrowLeft"],
|
|
115
|
+
// proto.translateSelectedEditors,
|
|
116
|
+
// { args: [-small, 0], checker: arrowChecker },
|
|
117
|
+
// ],
|
|
118
|
+
// [
|
|
119
|
+
// ["ctrl+ArrowLeft", "mac+shift+ArrowLeft"],
|
|
120
|
+
// proto.translateSelectedEditors,
|
|
121
|
+
// { args: [-big, 0], checker: arrowChecker },
|
|
122
|
+
// ],
|
|
123
|
+
// [
|
|
124
|
+
// ["ArrowRight", "mac+ArrowRight"],
|
|
125
|
+
// proto.translateSelectedEditors,
|
|
126
|
+
// { args: [small, 0], checker: arrowChecker },
|
|
127
|
+
// ],
|
|
128
|
+
// [
|
|
129
|
+
// ["ctrl+ArrowRight", "mac+shift+ArrowRight"],
|
|
130
|
+
// proto.translateSelectedEditors,
|
|
131
|
+
// { args: [big, 0], checker: arrowChecker },
|
|
132
|
+
// ],
|
|
133
|
+
// [
|
|
134
|
+
// ["ArrowUp", "mac+ArrowUp"],
|
|
135
|
+
// proto.translateSelectedEditors,
|
|
136
|
+
// { args: [0, -small], checker: arrowChecker },
|
|
137
|
+
// ],
|
|
138
|
+
// [
|
|
139
|
+
// ["ctrl+ArrowUp", "mac+shift+ArrowUp"],
|
|
140
|
+
// proto.translateSelectedEditors,
|
|
141
|
+
// { args: [0, -big], checker: arrowChecker },
|
|
142
|
+
// ],
|
|
143
|
+
// [
|
|
144
|
+
// ["ArrowDown", "mac+ArrowDown"],
|
|
145
|
+
// proto.translateSelectedEditors,
|
|
146
|
+
// { args: [0, small], checker: arrowChecker },
|
|
147
|
+
// ],
|
|
148
|
+
// [
|
|
149
|
+
// ["ctrl+ArrowDown", "mac+shift+ArrowDown"],
|
|
150
|
+
// proto.translateSelectedEditors,
|
|
151
|
+
// { args: [0, big], checker: arrowChecker },
|
|
152
|
+
// ],
|
|
153
|
+
// ])
|
|
154
|
+
// );
|
|
155
|
+
// }
|
|
156
|
+
constructor({ container = null, viewer, pdfViewer,
|
|
157
|
+
// altTextManager,
|
|
158
|
+
eventBus, pdfDocument,
|
|
159
|
+
// pageColors,
|
|
160
|
+
highlightColors = "",
|
|
161
|
+
// enableHighlightFloatingButton,
|
|
162
|
+
// enableUpdatedAddImage,
|
|
163
|
+
// enableNewAltTextWhenAddingImage,
|
|
164
|
+
// mlManager
|
|
165
|
+
}) {
|
|
166
|
+
_AnnotationEditorUIManager_instances.add(this);
|
|
167
|
+
// todo: props
|
|
168
|
+
// todo: extract to pdf viewer
|
|
169
|
+
this.pdfViewer = null;
|
|
170
|
+
this.annotationEditorMode = pdf_mjs_1.AnnotationEditorType.NONE;
|
|
171
|
+
this.viewParameters = {};
|
|
172
|
+
this.isShiftKeyDown = false;
|
|
173
|
+
this._eventBus = null;
|
|
174
|
+
// todo: props
|
|
175
|
+
_AnnotationEditorUIManager_abortController.set(this, new AbortController());
|
|
176
|
+
_AnnotationEditorUIManager_activeEditor.set(this, null);
|
|
177
|
+
_AnnotationEditorUIManager_allEditors.set(this, new Map());
|
|
178
|
+
_AnnotationEditorUIManager_allLayers.set(this, new Map());
|
|
179
|
+
// #altTextManager = null;
|
|
180
|
+
_AnnotationEditorUIManager_annotationStorage.set(this, null);
|
|
181
|
+
_AnnotationEditorUIManager_changedExistingAnnotations.set(this, null);
|
|
182
|
+
_AnnotationEditorUIManager_commandManager.set(this, new command_manager_1.CommandManager());
|
|
183
|
+
// #copyPasteAC = null;
|
|
184
|
+
_AnnotationEditorUIManager_currentPageIndex.set(this, 0);
|
|
185
|
+
_AnnotationEditorUIManager_deletedAnnotationsElementIds.set(this, new Set());
|
|
186
|
+
_AnnotationEditorUIManager_draggingEditors.set(this, null);
|
|
187
|
+
_AnnotationEditorUIManager_editorTypes.set(this, null);
|
|
188
|
+
_AnnotationEditorUIManager_editorsToRescale.set(this, new Set());
|
|
189
|
+
// todo: change default value
|
|
190
|
+
// #enableHighlightFloatingButton = false;
|
|
191
|
+
_AnnotationEditorUIManager_enableHighlightFloatingButton.set(this, true);
|
|
192
|
+
// #enableUpdatedAddImage = false;
|
|
193
|
+
// #enableNewAltTextWhenAddingImage = false;
|
|
194
|
+
// #filterFactory = null;
|
|
195
|
+
_AnnotationEditorUIManager_focusMainContainerTimeoutId.set(this, null);
|
|
196
|
+
_AnnotationEditorUIManager_focusManagerAC.set(this, null);
|
|
197
|
+
// todo: this is defined in "highlightEditorColors" in pdf.js as
|
|
198
|
+
// value: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F",
|
|
199
|
+
_AnnotationEditorUIManager_highlightColors.set(this, "");
|
|
200
|
+
_AnnotationEditorUIManager_highlightWhenShiftUp.set(this, false);
|
|
201
|
+
_AnnotationEditorUIManager_highlightToolbar.set(this, null);
|
|
202
|
+
_AnnotationEditorUIManager_idManager.set(this, new id_manager_1.IdManager());
|
|
203
|
+
_AnnotationEditorUIManager_isEnabled.set(this, false);
|
|
204
|
+
_AnnotationEditorUIManager_isWaiting.set(this, false);
|
|
205
|
+
// #keyboardManagerAC = null;
|
|
206
|
+
_AnnotationEditorUIManager_lastActiveElement.set(this, null);
|
|
207
|
+
// #mainHighlightColorPicker = null;
|
|
208
|
+
// #mlManager = null;
|
|
209
|
+
_AnnotationEditorUIManager_mode.set(this, pdf_mjs_1.AnnotationEditorType.NONE);
|
|
210
|
+
_AnnotationEditorUIManager_selectedEditors.set(this, new Set());
|
|
211
|
+
_AnnotationEditorUIManager_selectedTextNode.set(this, null);
|
|
212
|
+
// #pageColors = null;
|
|
213
|
+
_AnnotationEditorUIManager_showAllStates.set(this, null);
|
|
214
|
+
_AnnotationEditorUIManager_previousStates.set(this, {
|
|
215
|
+
isEditing: false,
|
|
216
|
+
isEmpty: true,
|
|
217
|
+
hasSomethingToUndo: false,
|
|
218
|
+
hasSomethingToRedo: false,
|
|
219
|
+
hasSelectedEditor: false,
|
|
220
|
+
hasSelectedText: false,
|
|
221
|
+
});
|
|
222
|
+
_AnnotationEditorUIManager_translation.set(this, [0, 0]);
|
|
223
|
+
_AnnotationEditorUIManager_translationTimeoutId.set(this, null);
|
|
224
|
+
_AnnotationEditorUIManager_container.set(this, null);
|
|
225
|
+
_AnnotationEditorUIManager_viewer.set(this, null);
|
|
226
|
+
// // const signal = (this._signal = this.#abortController.signal);
|
|
227
|
+
const signal = this._signal = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_abortController, "f").signal;
|
|
228
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_container, container, "f");
|
|
229
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_viewer, viewer, "f");
|
|
230
|
+
this.pdfViewer = pdfViewer;
|
|
231
|
+
// this.#altTextManager = altTextManager;
|
|
232
|
+
this._eventBus = eventBus;
|
|
233
|
+
this._eventBus._on("editingaction", this.onEditingAction.bind(this), {
|
|
234
|
+
signal,
|
|
235
|
+
});
|
|
236
|
+
this._eventBus._on("pagechanging", this.onPageChanging.bind(this), {
|
|
237
|
+
signal,
|
|
238
|
+
});
|
|
239
|
+
this._eventBus._on("scalechanging", this.onScaleChanging.bind(this), {
|
|
240
|
+
signal,
|
|
241
|
+
});
|
|
242
|
+
this._eventBus._on("rotationchanging", this.onRotationChanging.bind(this), {
|
|
243
|
+
signal,
|
|
244
|
+
});
|
|
245
|
+
this._eventBus._on("setpreference", this.onSetPreference.bind(this), {
|
|
246
|
+
signal,
|
|
247
|
+
});
|
|
248
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addSelectionListener).call(this);
|
|
249
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addDragAndDropListeners).call(this);
|
|
250
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addKeyboardManager).call(this);
|
|
251
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_annotationStorage, pdfDocument.annotationStorage, "f");
|
|
252
|
+
// this.#filterFactory = pdfDocument.filterFactory;
|
|
253
|
+
// this.#pageColors = pageColors;
|
|
254
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_highlightColors, highlightColors || "", "f");
|
|
255
|
+
// this.#enableHighlightFloatingButton = enableHighlightFloatingButton;
|
|
256
|
+
// this.#enableUpdatedAddImage = enableUpdatedAddImage;
|
|
257
|
+
// this.#enableNewAltTextWhenAddingImage = enableNewAltTextWhenAddingImage;
|
|
258
|
+
// this.#mlManager = mlManager || null;
|
|
259
|
+
this.viewParameters = {
|
|
260
|
+
realScale: pdf_mjs_1.PixelsPerInch.PDF_TO_CSS_UNITS,
|
|
261
|
+
rotation: 0,
|
|
262
|
+
};
|
|
263
|
+
// this.isShiftKeyDown = false;
|
|
264
|
+
// if ( typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
|
|
265
|
+
// window.uiManager = this;
|
|
266
|
+
// Object.defineProperty(this, "reset", {
|
|
267
|
+
// value: () => {
|
|
268
|
+
// this.selectAll();
|
|
269
|
+
// this.delete();
|
|
270
|
+
// this.#idManager.reset();
|
|
271
|
+
// },
|
|
272
|
+
// });
|
|
273
|
+
// }
|
|
274
|
+
}
|
|
275
|
+
destroy() {
|
|
276
|
+
var _a;
|
|
277
|
+
(_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_abortController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
|
|
278
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_abortController, null, "f");
|
|
279
|
+
this._signal = null;
|
|
280
|
+
for (const layer of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values()) {
|
|
281
|
+
layer.destroy();
|
|
282
|
+
}
|
|
283
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").clear();
|
|
284
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").clear();
|
|
285
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorsToRescale, "f").clear();
|
|
286
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_activeEditor, null, "f");
|
|
287
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").clear();
|
|
288
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").destroy();
|
|
289
|
+
// this.#altTextManager?.destroy();
|
|
290
|
+
// this.#highlightToolbar?.hide();
|
|
291
|
+
// this.#highlightToolbar = null;
|
|
292
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, "f")) {
|
|
293
|
+
clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, "f"));
|
|
294
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, null, "f");
|
|
295
|
+
}
|
|
296
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translationTimeoutId, "f")) {
|
|
297
|
+
clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translationTimeoutId, "f"));
|
|
298
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_translationTimeoutId, null, "f");
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// todo: new
|
|
302
|
+
getTextLayerForAnchor(anchorElement) {
|
|
303
|
+
if (!anchorElement) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
return anchorElement.closest(".textLayer") || anchorElement.closest(".k-text-layer");
|
|
307
|
+
}
|
|
308
|
+
combinedSignal(abortSignal) {
|
|
309
|
+
// eslint-disable-next-line
|
|
310
|
+
if (AbortSignal && AbortSignal["any"]) {
|
|
311
|
+
return AbortSignal.any([this._signal, abortSignal.signal]);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
// add this for the unit tests
|
|
315
|
+
// AbortSignal.any is an API since March 2024
|
|
316
|
+
// however, this API is not currently available in
|
|
317
|
+
// the node/jest-related bits version that we are using
|
|
318
|
+
return this._signal || abortSignal.signal;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// get mlManager() {
|
|
322
|
+
// return this.#mlManager;
|
|
323
|
+
// }
|
|
324
|
+
// get useNewAltTextFlow() {
|
|
325
|
+
// return this.#enableUpdatedAddImage;
|
|
326
|
+
// }
|
|
327
|
+
// get useNewAltTextWhenAddingImage() {
|
|
328
|
+
// return this.#enableNewAltTextWhenAddingImage;
|
|
329
|
+
// }
|
|
330
|
+
// get hcmFilter() {
|
|
331
|
+
// return shadow(
|
|
332
|
+
// this,
|
|
333
|
+
// "hcmFilter",
|
|
334
|
+
// this.#pageColors
|
|
335
|
+
// ? this.#filterFactory.addHCMFilter(
|
|
336
|
+
// this.#pageColors.foreground,
|
|
337
|
+
// this.#pageColors.background
|
|
338
|
+
// )
|
|
339
|
+
// : "none"
|
|
340
|
+
// );
|
|
341
|
+
// }
|
|
342
|
+
get direction() {
|
|
343
|
+
return (0, pdf_mjs_1.shadow)(this, "direction", getComputedStyle(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_container, "f")).direction);
|
|
344
|
+
}
|
|
345
|
+
get highlightColors() {
|
|
346
|
+
return (0, pdf_mjs_1.shadow)(this, "highlightColors", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightColors, "f")
|
|
347
|
+
? new Map(
|
|
348
|
+
// Array.from(
|
|
349
|
+
// this.#highlightColors
|
|
350
|
+
// .split(",")
|
|
351
|
+
// .map(pair => pair.split("=").map(x => x.trim()))
|
|
352
|
+
// )
|
|
353
|
+
)
|
|
354
|
+
: null);
|
|
355
|
+
}
|
|
356
|
+
get highlightColorNames() {
|
|
357
|
+
return (0, pdf_mjs_1.shadow)(this, "highlightColorNames", this.highlightColors
|
|
358
|
+
? new Map(Array.from(this.highlightColors, e => e.reverse()))
|
|
359
|
+
: null);
|
|
360
|
+
}
|
|
361
|
+
// setMainHighlightColorPicker(colorPicker) {
|
|
362
|
+
// this.#mainHighlightColorPicker = colorPicker;
|
|
363
|
+
// }
|
|
364
|
+
// editAltText(editor, firstTime = false) {
|
|
365
|
+
// this.#altTextManager?.editAltText(this, editor, firstTime);
|
|
366
|
+
// }
|
|
367
|
+
switchToMode(mode, callback) {
|
|
368
|
+
// Switching to a mode can be asynchronous.
|
|
369
|
+
this._eventBus.on("annotationeditormodechanged", callback, {
|
|
370
|
+
once: true,
|
|
371
|
+
signal: this._signal,
|
|
372
|
+
mode
|
|
373
|
+
});
|
|
374
|
+
this._eventBus.dispatch("showannotationeditorui", {
|
|
375
|
+
source: this,
|
|
376
|
+
mode,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
setPreference(name, value) {
|
|
380
|
+
this._eventBus.dispatch("setpreference", {
|
|
381
|
+
source: this,
|
|
382
|
+
name,
|
|
383
|
+
value,
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
// onSetPreference({ name, value }) {
|
|
387
|
+
onSetPreference({ name }) {
|
|
388
|
+
switch (name) {
|
|
389
|
+
case "enableNewAltTextWhenAddingImage":
|
|
390
|
+
// this.#enableNewAltTextWhenAddingImage = value;
|
|
391
|
+
break;
|
|
392
|
+
default: break;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
onPageChanging({ pageNumber }) {
|
|
396
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_currentPageIndex, pageNumber - 1, "f");
|
|
397
|
+
}
|
|
398
|
+
focusMainContainer() {
|
|
399
|
+
var _a;
|
|
400
|
+
(_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_container, "f")) === null || _a === void 0 ? void 0 : _a.focus();
|
|
401
|
+
}
|
|
402
|
+
findParent(x, y) {
|
|
403
|
+
for (const layer of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values()) {
|
|
404
|
+
const { x: layerX, y: layerY, width, height, } = layer.div.getBoundingClientRect();
|
|
405
|
+
if (x >= layerX &&
|
|
406
|
+
x <= layerX + width &&
|
|
407
|
+
y >= layerY &&
|
|
408
|
+
y <= layerY + height) {
|
|
409
|
+
return layer;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
disableUserSelect(value = false) {
|
|
415
|
+
var _a;
|
|
416
|
+
(_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_viewer, "f")) === null || _a === void 0 ? void 0 : _a.classList.toggle("noUserSelect", value);
|
|
417
|
+
}
|
|
418
|
+
addShouldRescale(editor) {
|
|
419
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorsToRescale, "f").add(editor);
|
|
420
|
+
}
|
|
421
|
+
removeShouldRescale(editor) {
|
|
422
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorsToRescale, "f").delete(editor);
|
|
423
|
+
}
|
|
424
|
+
onScaleChanging({ scale }) {
|
|
425
|
+
this.commitOrRemove();
|
|
426
|
+
this.viewParameters.realScale = scale * pdf_mjs_1.PixelsPerInch.PDF_TO_CSS_UNITS;
|
|
427
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorsToRescale, "f")) {
|
|
428
|
+
editor.onScaleChanging();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
onRotationChanging({ pagesRotation }) {
|
|
432
|
+
this.commitOrRemove();
|
|
433
|
+
this.viewParameters.rotation = pagesRotation;
|
|
434
|
+
}
|
|
435
|
+
highlightSelection(methodOfCreation = "") {
|
|
436
|
+
const selection = document.getSelection();
|
|
437
|
+
if (!selection || selection.isCollapsed) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
const { anchorNode, anchorOffset, focusNode, focusOffset } = selection;
|
|
441
|
+
const text = selection.toString();
|
|
442
|
+
const anchorElement = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_getAnchorElementForSelection).call(this, selection);
|
|
443
|
+
// const textLayer = anchorElement.closest(".textLayer");
|
|
444
|
+
const textLayer = this.getTextLayerForAnchor(anchorElement);
|
|
445
|
+
const boxes = this.getSelectionBoxes(textLayer);
|
|
446
|
+
if (!boxes) {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
selection.empty();
|
|
450
|
+
const layer = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_getLayerForTextLayer).call(this, textLayer);
|
|
451
|
+
const isNoneMode = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === pdf_mjs_1.AnnotationEditorType.NONE;
|
|
452
|
+
const callback = () => {
|
|
453
|
+
layer === null || layer === void 0 ? void 0 : layer.createAndAddNewEditor({ x: 0, y: 0 }, false, {
|
|
454
|
+
methodOfCreation,
|
|
455
|
+
boxes,
|
|
456
|
+
anchorNode,
|
|
457
|
+
anchorOffset,
|
|
458
|
+
focusNode,
|
|
459
|
+
focusOffset,
|
|
460
|
+
text,
|
|
461
|
+
});
|
|
462
|
+
if (isNoneMode) {
|
|
463
|
+
// this.showAllEditors("highlight", true, /* updateButton = */ true);
|
|
464
|
+
this.showAllEditors("highlight", true);
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
if (isNoneMode) {
|
|
468
|
+
this.switchToMode(pdf_mjs_1.AnnotationEditorType.HIGHLIGHT, callback);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
callback();
|
|
472
|
+
}
|
|
473
|
+
showEditorToolBar(anchor) {
|
|
474
|
+
if (!anchor) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
// todo: disable showing a toolbar for other annotations
|
|
478
|
+
const annotationEditorMode = this.getMode();
|
|
479
|
+
if (annotationEditorMode === pdf_mjs_1.AnnotationEditorType.HIGHLIGHT) {
|
|
480
|
+
const editor = anchor.closest(".highlightEditor");
|
|
481
|
+
if (!editor) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (annotationEditorMode === pdf_mjs_1.AnnotationEditorType.FREETEXT) {
|
|
486
|
+
const editor = anchor.closest(".freeTextEditor");
|
|
487
|
+
if (!editor) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (annotationEditorMode !== pdf_mjs_1.AnnotationEditorType.HIGHLIGHT &&
|
|
492
|
+
annotationEditorMode !== pdf_mjs_1.AnnotationEditorType.FREETEXT) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
this._eventBus.dispatch("kendoAnnotationEditorToolBarShow", {
|
|
496
|
+
source: this,
|
|
497
|
+
anchor: anchor
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
hideEditorToolBar() {
|
|
501
|
+
this._eventBus.dispatch("kendoAnnotationEditorToolBarHide", {
|
|
502
|
+
source: this,
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Add an editor in the annotation storage.
|
|
507
|
+
* @param {AnnotationEditor} editor
|
|
508
|
+
*/
|
|
509
|
+
addToAnnotationStorage(editor) {
|
|
510
|
+
if (!editor.isEmpty() &&
|
|
511
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_annotationStorage, "f") &&
|
|
512
|
+
!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_annotationStorage, "f").has(editor.id)) {
|
|
513
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_annotationStorage, "f").setValue(editor.id, editor);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
blur() {
|
|
517
|
+
this.isShiftKeyDown = false;
|
|
518
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightWhenShiftUp, "f")) {
|
|
519
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_highlightWhenShiftUp, false, "f");
|
|
520
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_onSelectEnd).call(this, "main_toolbar");
|
|
521
|
+
}
|
|
522
|
+
if (!this.hasSelection) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
// When several editors are selected and the window loses focus, we want to
|
|
526
|
+
// keep the last active element in order to be able to focus it again when
|
|
527
|
+
// the window gets the focus back but we don't want to trigger any focus
|
|
528
|
+
// callbacks else only one editor will be selected.
|
|
529
|
+
const { activeElement } = document;
|
|
530
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f")) {
|
|
531
|
+
if (editor.div.contains(activeElement)) {
|
|
532
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_lastActiveElement, [editor, activeElement], "f");
|
|
533
|
+
editor._focusEventsAllowed = false;
|
|
534
|
+
break;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
focus() {
|
|
539
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_lastActiveElement, "f")) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
const [lastEditor, lastActiveElement] = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_lastActiveElement, "f");
|
|
543
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_lastActiveElement, null, "f");
|
|
544
|
+
lastActiveElement.addEventListener("focusin", () => {
|
|
545
|
+
lastEditor._focusEventsAllowed = true;
|
|
546
|
+
}, { once: true, signal: this._signal });
|
|
547
|
+
lastActiveElement.focus();
|
|
548
|
+
}
|
|
549
|
+
addEditListeners() {
|
|
550
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addKeyboardManager).call(this);
|
|
551
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addCopyPasteListeners).call(this);
|
|
552
|
+
}
|
|
553
|
+
removeEditListeners() {
|
|
554
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_removeKeyboardManager).call(this);
|
|
555
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_removeCopyPasteListeners).call(this);
|
|
556
|
+
}
|
|
557
|
+
dragOver(event) {
|
|
558
|
+
for (const { type } of event.dataTransfer.items) {
|
|
559
|
+
for (const editorType of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f")) {
|
|
560
|
+
if (editorType.isHandlingMimeForPasting(type)) {
|
|
561
|
+
event.dataTransfer.dropEffect = "copy";
|
|
562
|
+
event.preventDefault();
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Drop callback.
|
|
570
|
+
* @param {DragEvent} event
|
|
571
|
+
*/
|
|
572
|
+
drop(event) {
|
|
573
|
+
for (const item of event.dataTransfer.items) {
|
|
574
|
+
for (const editorType of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f")) {
|
|
575
|
+
if (editorType.isHandlingMimeForPasting(item.type)) {
|
|
576
|
+
editorType.paste(item, this.currentLayer);
|
|
577
|
+
event.preventDefault();
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Copy callback.
|
|
585
|
+
* @param {ClipboardEvent} event
|
|
586
|
+
*/
|
|
587
|
+
copy(event) {
|
|
588
|
+
var _a;
|
|
589
|
+
event.preventDefault();
|
|
590
|
+
// An editor is being edited so just commit it.
|
|
591
|
+
(_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f")) === null || _a === void 0 ? void 0 : _a.commitOrRemove();
|
|
592
|
+
if (!this.hasSelection) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const editors = [];
|
|
596
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f")) {
|
|
597
|
+
const serialized = editor.serialize(/* isForCopying = */ true);
|
|
598
|
+
if (serialized) {
|
|
599
|
+
editors.push(serialized);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
if (editors.length === 0) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
event.clipboardData.setData("application/pdfjs", JSON.stringify(editors));
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Cut callback.
|
|
609
|
+
* @param {ClipboardEvent} event
|
|
610
|
+
*/
|
|
611
|
+
cut(event) {
|
|
612
|
+
this.copy(event);
|
|
613
|
+
this.delete();
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Paste callback.
|
|
617
|
+
* @param {ClipboardEvent} event
|
|
618
|
+
*/
|
|
619
|
+
paste(event) {
|
|
620
|
+
event.preventDefault();
|
|
621
|
+
const { clipboardData } = event;
|
|
622
|
+
for (const item of clipboardData.items) {
|
|
623
|
+
for (const editorType of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f")) {
|
|
624
|
+
if (editorType.isHandlingMimeForPasting(item.type)) {
|
|
625
|
+
editorType.paste(item, this.currentLayer);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
let data = clipboardData.getData("application/pdfjs");
|
|
631
|
+
if (!data) {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
try {
|
|
635
|
+
data = JSON.parse(data);
|
|
636
|
+
}
|
|
637
|
+
catch (ex) {
|
|
638
|
+
// warn(`paste: "${ex.message}".`);
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
if (!Array.isArray(data)) {
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
this.unselectAll();
|
|
645
|
+
const layer = this.currentLayer;
|
|
646
|
+
try {
|
|
647
|
+
const newEditors = [];
|
|
648
|
+
for (const editor of data) {
|
|
649
|
+
const deserializedEditor = layer.deserialize(editor);
|
|
650
|
+
if (!deserializedEditor) {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
newEditors.push(deserializedEditor);
|
|
654
|
+
}
|
|
655
|
+
const cmd = () => {
|
|
656
|
+
for (const editor of newEditors) {
|
|
657
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addEditorToLayer).call(this, editor);
|
|
658
|
+
}
|
|
659
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_selectEditors).call(this, newEditors);
|
|
660
|
+
};
|
|
661
|
+
const undo = () => {
|
|
662
|
+
for (const editor of newEditors) {
|
|
663
|
+
editor.remove();
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
this.addCommands({ cmd, undo, mustExec: true });
|
|
667
|
+
}
|
|
668
|
+
catch (ex) {
|
|
669
|
+
// warn(`paste: "${ex.message}".`);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
// /**
|
|
673
|
+
// * Keydown callback.
|
|
674
|
+
// * @param {KeyboardEvent} event
|
|
675
|
+
// */
|
|
676
|
+
// keydown(event) {
|
|
677
|
+
// if (!this.isShiftKeyDown && event.key === "Shift") {
|
|
678
|
+
// this.isShiftKeyDown = true;
|
|
679
|
+
// }
|
|
680
|
+
// if (
|
|
681
|
+
// this.#mode !== AnnotationEditorType.NONE &&
|
|
682
|
+
// !this.isEditorHandlingKeyboard
|
|
683
|
+
// ) {
|
|
684
|
+
// AnnotationEditorUIManager._keyboardManager.exec(this, event);
|
|
685
|
+
// }
|
|
686
|
+
// }
|
|
687
|
+
// /**
|
|
688
|
+
// * Keyup callback.
|
|
689
|
+
// * @param {KeyboardEvent} event
|
|
690
|
+
// */
|
|
691
|
+
// keyup(event) {
|
|
692
|
+
// if (this.isShiftKeyDown && event.key === "Shift") {
|
|
693
|
+
// this.isShiftKeyDown = false;
|
|
694
|
+
// if (this.#highlightWhenShiftUp) {
|
|
695
|
+
// this.#highlightWhenShiftUp = false;
|
|
696
|
+
// this.#onSelectEnd("main_toolbar");
|
|
697
|
+
// }
|
|
698
|
+
// }
|
|
699
|
+
// }
|
|
700
|
+
/**
|
|
701
|
+
* Execute an action for a given name.
|
|
702
|
+
* For example, the user can click on the "Undo" entry in the context menu
|
|
703
|
+
* and it'll trigger the undo action.
|
|
704
|
+
*/
|
|
705
|
+
onEditingAction({ name }) {
|
|
706
|
+
switch (name) {
|
|
707
|
+
case "undo":
|
|
708
|
+
case "redo":
|
|
709
|
+
case "delete":
|
|
710
|
+
case "selectAll":
|
|
711
|
+
this[name]();
|
|
712
|
+
break;
|
|
713
|
+
case "highlightSelection":
|
|
714
|
+
this.highlightSelection("context_menu");
|
|
715
|
+
break;
|
|
716
|
+
default: break;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Set the editing state.
|
|
721
|
+
* It can be useful to temporarily disable it when the user is editing a
|
|
722
|
+
* FreeText annotation.
|
|
723
|
+
* @param {boolean} isEditing
|
|
724
|
+
*/
|
|
725
|
+
setEditingState(isEditing) {
|
|
726
|
+
// setEditingState() {
|
|
727
|
+
if (isEditing) {
|
|
728
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addFocusManager).call(this);
|
|
729
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addCopyPasteListeners).call(this);
|
|
730
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
731
|
+
isEditing: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") !== pdf_mjs_1.AnnotationEditorType.NONE,
|
|
732
|
+
isEmpty: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_isEmpty).call(this),
|
|
733
|
+
hasSomethingToUndo: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").hasSomethingToUndo(),
|
|
734
|
+
hasSomethingToRedo: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").hasSomethingToRedo(),
|
|
735
|
+
hasSelectedEditor: false,
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_removeFocusManager).call(this);
|
|
740
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_removeCopyPasteListeners).call(this);
|
|
741
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
742
|
+
isEditing: false,
|
|
743
|
+
});
|
|
744
|
+
this.disableUserSelect(false);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
registerEditorTypes(types) {
|
|
748
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f")) {
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_editorTypes, types, "f");
|
|
752
|
+
for (const editorType of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f")) {
|
|
753
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, editorType.defaultPropertiesToUpdate);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Get an id.
|
|
758
|
+
* @returns {string}
|
|
759
|
+
*/
|
|
760
|
+
getId() {
|
|
761
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_idManager, "f").id;
|
|
762
|
+
}
|
|
763
|
+
get currentLayer() {
|
|
764
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").get(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_currentPageIndex, "f"));
|
|
765
|
+
}
|
|
766
|
+
getLayer(pageIndex) {
|
|
767
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").get(pageIndex);
|
|
768
|
+
}
|
|
769
|
+
get currentPageIndex() {
|
|
770
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_currentPageIndex, "f");
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Add a new layer for a page which will contains the editors.
|
|
774
|
+
* @param {AnnotationEditorLayer} layer
|
|
775
|
+
*/
|
|
776
|
+
addLayer(layer) {
|
|
777
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").set(layer.pageIndex, layer);
|
|
778
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_isEnabled, "f")) {
|
|
779
|
+
layer.enable();
|
|
780
|
+
}
|
|
781
|
+
else {
|
|
782
|
+
layer.disable();
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Remove a layer.
|
|
787
|
+
* @param {AnnotationEditorLayer} layer
|
|
788
|
+
*/
|
|
789
|
+
removeLayer(layer) {
|
|
790
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").delete(layer.pageIndex);
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Change the editor mode (None, FreeText, Ink, ...)
|
|
794
|
+
* @param {number} mode
|
|
795
|
+
* @param {string|null} editId
|
|
796
|
+
* @param {boolean} [isFromKeyboard] - true if the mode change is due to a
|
|
797
|
+
* keyboard action.
|
|
798
|
+
*/
|
|
799
|
+
updateMode(mode, editId = null, isFromKeyboard = false) {
|
|
800
|
+
// todo: set isFromKeyboard intentionally to allow editor creation
|
|
801
|
+
// updateMode(mode, editId = null, isFromKeyboard = true) {
|
|
802
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === mode) {
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_mode, mode, "f");
|
|
806
|
+
if (mode === pdf_mjs_1.AnnotationEditorType.NONE) {
|
|
807
|
+
this.setEditingState(false);
|
|
808
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_disableAll).call(this);
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
this.setEditingState(true);
|
|
812
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_enableAll).call(this);
|
|
813
|
+
this.unselectAll();
|
|
814
|
+
for (const layer of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values()) {
|
|
815
|
+
layer.updateMode(mode);
|
|
816
|
+
}
|
|
817
|
+
if (!editId && isFromKeyboard) {
|
|
818
|
+
this.addNewEditorFromKeyboard();
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
if (!editId) {
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values()) {
|
|
825
|
+
if (editor.annotationElementId === editId) {
|
|
826
|
+
this.setSelected(editor);
|
|
827
|
+
editor.enterInEditMode();
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
addNewEditorFromKeyboard() {
|
|
833
|
+
if (this.currentLayer.canCreateNewEmptyEditor()) {
|
|
834
|
+
this.currentLayer.addNewEditor();
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Update the toolbar if it's required to reflect the tool currently used.
|
|
839
|
+
* @param {number} mode
|
|
840
|
+
* @returns {undefined}
|
|
841
|
+
*/
|
|
842
|
+
updateToolbar(mode) {
|
|
843
|
+
if (mode === tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f")) {
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
this._eventBus.dispatch("switchannotationeditormode", {
|
|
847
|
+
source: this,
|
|
848
|
+
mode,
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Update a parameter in the current editor or globally.
|
|
853
|
+
* @param {number} type
|
|
854
|
+
* @param {*} value
|
|
855
|
+
*/
|
|
856
|
+
updateParams(type, value) {
|
|
857
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f")) {
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
switch (type) {
|
|
861
|
+
case pdf_mjs_1.AnnotationEditorParamsType.CREATE:
|
|
862
|
+
this.currentLayer.addNewEditor();
|
|
863
|
+
return;
|
|
864
|
+
case pdf_mjs_1.AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
|
|
865
|
+
// this.#mainHighlightColorPicker?.updateColor(value);
|
|
866
|
+
break;
|
|
867
|
+
case pdf_mjs_1.AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL:
|
|
868
|
+
// this._eventBus.dispatch("reporttelemetry", {
|
|
869
|
+
// source: this,
|
|
870
|
+
// details: {
|
|
871
|
+
// type: "editing",
|
|
872
|
+
// data: {
|
|
873
|
+
// type: "highlight",
|
|
874
|
+
// action: "toggle_visibility",
|
|
875
|
+
// },
|
|
876
|
+
// },
|
|
877
|
+
// });
|
|
878
|
+
(tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_showAllStates, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_showAllStates, "f") || new Map(), "f")).set(type, value);
|
|
879
|
+
this.showAllEditors("highlight", value);
|
|
880
|
+
break;
|
|
881
|
+
default: break;
|
|
882
|
+
}
|
|
883
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f")) {
|
|
884
|
+
editor.updateParams(type, value);
|
|
885
|
+
}
|
|
886
|
+
for (const editorType of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_editorTypes, "f")) {
|
|
887
|
+
editorType.updateDefaultParams(type, value);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
// showAllEditors(type, visible, updateButton = false) {
|
|
891
|
+
showAllEditors(type, visible) {
|
|
892
|
+
var _a, _b;
|
|
893
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values()) {
|
|
894
|
+
if (editor.editorType === type) {
|
|
895
|
+
editor.show(visible);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
const state = (_b = (_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_showAllStates, "f")) === null || _a === void 0 ? void 0 : _a.get(pdf_mjs_1.AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL)) !== null && _b !== void 0 ? _b : true;
|
|
899
|
+
if (state !== visible) {
|
|
900
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, [
|
|
901
|
+
[pdf_mjs_1.AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL, visible],
|
|
902
|
+
]);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
enableWaiting(mustWait = false) {
|
|
906
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_isWaiting, "f") === mustWait) {
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_isWaiting, mustWait, "f");
|
|
910
|
+
for (const layer of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values()) {
|
|
911
|
+
if (mustWait) {
|
|
912
|
+
layer.disableClick();
|
|
913
|
+
}
|
|
914
|
+
else {
|
|
915
|
+
layer.enableClick();
|
|
916
|
+
}
|
|
917
|
+
layer.div.classList.toggle("waiting", mustWait);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Get all the editors belonging to a given page.
|
|
922
|
+
* @param {number} pageIndex
|
|
923
|
+
* @returns {Array<AnnotationEditor>}
|
|
924
|
+
*/
|
|
925
|
+
getEditors(pageIndex) {
|
|
926
|
+
const editors = [];
|
|
927
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values()) {
|
|
928
|
+
if (editor.pageIndex === pageIndex) {
|
|
929
|
+
editors.push(editor);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
return editors;
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Get an editor with the given id.
|
|
936
|
+
* @param {string} id
|
|
937
|
+
* @returns {AnnotationEditor}
|
|
938
|
+
*/
|
|
939
|
+
getEditor(id) {
|
|
940
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").get(id);
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* Add a new editor.
|
|
944
|
+
* @param {AnnotationEditor} editor
|
|
945
|
+
*/
|
|
946
|
+
addEditor(editor) {
|
|
947
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").set(editor.id, editor);
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Remove an editor.
|
|
951
|
+
* @param {AnnotationEditor} editor
|
|
952
|
+
*/
|
|
953
|
+
removeEditor(editor) {
|
|
954
|
+
var _a;
|
|
955
|
+
if (editor.div.contains(document.activeElement)) {
|
|
956
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, "f")) {
|
|
957
|
+
clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, "f"));
|
|
958
|
+
}
|
|
959
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, setTimeout(() => {
|
|
960
|
+
// When the div is removed from DOM the focus can move on the
|
|
961
|
+
// document.body, so we need to move it back to the main container.
|
|
962
|
+
this.focusMainContainer();
|
|
963
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_focusMainContainerTimeoutId, null, "f");
|
|
964
|
+
}, 0), "f");
|
|
965
|
+
}
|
|
966
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").delete(editor.id);
|
|
967
|
+
this.unselect(editor);
|
|
968
|
+
if (!editor.annotationElementId ||
|
|
969
|
+
!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_deletedAnnotationsElementIds, "f").has(editor.annotationElementId)) {
|
|
970
|
+
(_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_annotationStorage, "f")) === null || _a === void 0 ? void 0 : _a.remove(editor.id);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* The annotation element with the given id has been deleted.
|
|
975
|
+
* @param {AnnotationEditor} editor
|
|
976
|
+
*/
|
|
977
|
+
addDeletedAnnotationElement(editor) {
|
|
978
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_deletedAnnotationsElementIds, "f").add(editor.annotationElementId);
|
|
979
|
+
this.addChangedExistingAnnotation(editor);
|
|
980
|
+
editor.deleted = true;
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Check if the annotation element with the given id has been deleted.
|
|
984
|
+
* @param {string} annotationElementId
|
|
985
|
+
* @returns {boolean}
|
|
986
|
+
*/
|
|
987
|
+
isDeletedAnnotationElement(annotationElementId) {
|
|
988
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_deletedAnnotationsElementIds, "f").has(annotationElementId);
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* The annotation element with the given id have been restored.
|
|
992
|
+
* @param {AnnotationEditor} editor
|
|
993
|
+
*/
|
|
994
|
+
removeDeletedAnnotationElement(editor) {
|
|
995
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_deletedAnnotationsElementIds, "f").delete(editor.annotationElementId);
|
|
996
|
+
this.removeChangedExistingAnnotation(editor);
|
|
997
|
+
editor.deleted = false;
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Set the given editor as the active one.
|
|
1001
|
+
* @param {AnnotationEditor} editor
|
|
1002
|
+
*/
|
|
1003
|
+
setActiveEditor(editor) {
|
|
1004
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f") === editor) {
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_activeEditor, editor, "f");
|
|
1008
|
+
if (editor) {
|
|
1009
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, editor.propertiesToUpdate);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Update the UI of the active editor.
|
|
1014
|
+
* @param {AnnotationEditor} editor
|
|
1015
|
+
*/
|
|
1016
|
+
updateUI(editor) {
|
|
1017
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "a", _AnnotationEditorUIManager_lastSelectedEditor_get) === editor) {
|
|
1018
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, editor.propertiesToUpdate);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Add or remove an editor the current selection.
|
|
1023
|
+
* @param {AnnotationEditor} editor
|
|
1024
|
+
*/
|
|
1025
|
+
toggleSelected(editor) {
|
|
1026
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").has(editor)) {
|
|
1027
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").delete(editor);
|
|
1028
|
+
editor.unselect();
|
|
1029
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
1030
|
+
hasSelectedEditor: this.hasSelection,
|
|
1031
|
+
});
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").add(editor);
|
|
1035
|
+
editor.select();
|
|
1036
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, editor.propertiesToUpdate);
|
|
1037
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
1038
|
+
hasSelectedEditor: true,
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Set the last selected editor.
|
|
1043
|
+
* @param {AnnotationEditor} editor
|
|
1044
|
+
*/
|
|
1045
|
+
setSelected(editor) {
|
|
1046
|
+
for (const selectedEditor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f")) {
|
|
1047
|
+
if (selectedEditor !== editor) {
|
|
1048
|
+
selectedEditor.unselect();
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").clear();
|
|
1052
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").add(editor);
|
|
1053
|
+
editor.select();
|
|
1054
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, editor.propertiesToUpdate);
|
|
1055
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
1056
|
+
hasSelectedEditor: true,
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Check if the editor is selected.
|
|
1061
|
+
* @param {AnnotationEditor} editor
|
|
1062
|
+
*/
|
|
1063
|
+
isSelected(editor) {
|
|
1064
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").has(editor);
|
|
1065
|
+
}
|
|
1066
|
+
get firstSelectedEditor() {
|
|
1067
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").values().next().value;
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Unselect an editor.
|
|
1071
|
+
* @param {AnnotationEditor} editor
|
|
1072
|
+
*/
|
|
1073
|
+
unselect(editor) {
|
|
1074
|
+
editor.unselect();
|
|
1075
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").delete(editor);
|
|
1076
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
1077
|
+
hasSelectedEditor: this.hasSelection,
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
get hasSelection() {
|
|
1081
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").size !== 0;
|
|
1082
|
+
}
|
|
1083
|
+
get isEnterHandled() {
|
|
1084
|
+
return (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").size === 1 &&
|
|
1085
|
+
this.firstSelectedEditor.isEnterHandled);
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Undo the last command.
|
|
1089
|
+
*/
|
|
1090
|
+
undo() {
|
|
1091
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").undo();
|
|
1092
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
1093
|
+
hasSomethingToUndo: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").hasSomethingToUndo(),
|
|
1094
|
+
hasSomethingToRedo: true,
|
|
1095
|
+
isEmpty: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_isEmpty).call(this),
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Redo the last undoed command.
|
|
1100
|
+
*/
|
|
1101
|
+
redo() {
|
|
1102
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").redo();
|
|
1103
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
1104
|
+
hasSomethingToUndo: true,
|
|
1105
|
+
hasSomethingToRedo: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").hasSomethingToRedo(),
|
|
1106
|
+
isEmpty: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_isEmpty).call(this),
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Add a command to execute (cmd) and another one to undo it.
|
|
1111
|
+
* @param {Object} params
|
|
1112
|
+
*/
|
|
1113
|
+
addCommands(params) {
|
|
1114
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_commandManager, "f").add(params);
|
|
1115
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
1116
|
+
hasSomethingToUndo: true,
|
|
1117
|
+
hasSomethingToRedo: false,
|
|
1118
|
+
isEmpty: tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_isEmpty).call(this),
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Delete the current editor or all.
|
|
1123
|
+
*/
|
|
1124
|
+
delete() {
|
|
1125
|
+
this.commitOrRemove();
|
|
1126
|
+
if (!this.hasSelection) {
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
const editors = [...tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f")];
|
|
1130
|
+
const cmd = () => {
|
|
1131
|
+
for (const editor of editors) {
|
|
1132
|
+
editor.remove();
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
const undo = () => {
|
|
1136
|
+
for (const editor of editors) {
|
|
1137
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addEditorToLayer).call(this, editor);
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
this.addCommands({ cmd, undo, mustExec: true });
|
|
1141
|
+
}
|
|
1142
|
+
commitOrRemove() {
|
|
1143
|
+
var _a;
|
|
1144
|
+
// An editor is being edited so just commit it.
|
|
1145
|
+
(_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f")) === null || _a === void 0 ? void 0 : _a.commitOrRemove();
|
|
1146
|
+
}
|
|
1147
|
+
hasSomethingToControl() {
|
|
1148
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f") || this.hasSelection;
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Select all the editors.
|
|
1152
|
+
*/
|
|
1153
|
+
selectAll() {
|
|
1154
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f")) {
|
|
1155
|
+
editor.commit();
|
|
1156
|
+
}
|
|
1157
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_selectEditors).call(this, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values());
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* Unselect all the selected editors.
|
|
1161
|
+
*/
|
|
1162
|
+
unselectAll() {
|
|
1163
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f")) {
|
|
1164
|
+
// An editor is being edited so just commit it.
|
|
1165
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f").commitOrRemove();
|
|
1166
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") !== pdf_mjs_1.AnnotationEditorType.NONE) {
|
|
1167
|
+
// If the mode is NONE, we want to really unselect the editor, hence we
|
|
1168
|
+
// mustn't return here.
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
if (!this.hasSelection) {
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f")) {
|
|
1176
|
+
editor.unselect();
|
|
1177
|
+
}
|
|
1178
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").clear();
|
|
1179
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
1180
|
+
hasSelectedEditor: false,
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
translateSelectedEditors(x, y, noCommit = false) {
|
|
1184
|
+
if (!noCommit) {
|
|
1185
|
+
this.commitOrRemove();
|
|
1186
|
+
}
|
|
1187
|
+
if (!this.hasSelection) {
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translation, "f")[0] += x;
|
|
1191
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translation, "f")[1] += y;
|
|
1192
|
+
const [totalX, totalY] = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translation, "f");
|
|
1193
|
+
const editors = [...tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f")];
|
|
1194
|
+
// We don't want to have an undo/redo for each translation so we wait a bit
|
|
1195
|
+
// before adding the command to the command manager.
|
|
1196
|
+
const TIME_TO_WAIT = 1000;
|
|
1197
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translationTimeoutId, "f")) {
|
|
1198
|
+
clearTimeout(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translationTimeoutId, "f"));
|
|
1199
|
+
}
|
|
1200
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_translationTimeoutId, setTimeout(() => {
|
|
1201
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_translationTimeoutId, null, "f");
|
|
1202
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translation, "f")[0] = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_translation, "f")[1] = 0;
|
|
1203
|
+
this.addCommands({
|
|
1204
|
+
cmd: () => {
|
|
1205
|
+
for (const editor of editors) {
|
|
1206
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").has(editor.id)) {
|
|
1207
|
+
editor.translateInPage(totalX, totalY);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
},
|
|
1211
|
+
undo: () => {
|
|
1212
|
+
for (const editor of editors) {
|
|
1213
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").has(editor.id)) {
|
|
1214
|
+
editor.translateInPage(-totalX, -totalY);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
},
|
|
1218
|
+
mustExec: false,
|
|
1219
|
+
});
|
|
1220
|
+
}, TIME_TO_WAIT), "f");
|
|
1221
|
+
for (const editor of editors) {
|
|
1222
|
+
editor.translateInPage(x, y);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Set up the drag session for moving the selected editors.
|
|
1227
|
+
*/
|
|
1228
|
+
setUpDragSession() {
|
|
1229
|
+
// // Note: don't use any references to the editor's parent which can be null
|
|
1230
|
+
// // if the editor belongs to a destroyed page.
|
|
1231
|
+
if (!this.hasSelection) {
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
// Avoid to have spurious text selection in the text layer when dragging.
|
|
1235
|
+
this.disableUserSelect(true);
|
|
1236
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_draggingEditors, new Map(), "f");
|
|
1237
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f")) {
|
|
1238
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_draggingEditors, "f").set(editor, {
|
|
1239
|
+
savedX: editor.x,
|
|
1240
|
+
savedY: editor.y,
|
|
1241
|
+
savedPageIndex: editor.pageIndex,
|
|
1242
|
+
newX: 0,
|
|
1243
|
+
newY: 0,
|
|
1244
|
+
newPageIndex: -1,
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Ends the drag session.
|
|
1250
|
+
* @returns {boolean} true if at least one editor has been moved.
|
|
1251
|
+
*/
|
|
1252
|
+
endDragSession() {
|
|
1253
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_draggingEditors, "f")) {
|
|
1254
|
+
return false;
|
|
1255
|
+
}
|
|
1256
|
+
this.disableUserSelect(false);
|
|
1257
|
+
const map = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_draggingEditors, "f");
|
|
1258
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_draggingEditors, null, "f");
|
|
1259
|
+
let mustBeAddedInUndoStack = false;
|
|
1260
|
+
for (const [{ x, y, pageIndex }, value] of map) {
|
|
1261
|
+
value.newX = x;
|
|
1262
|
+
value.newY = y;
|
|
1263
|
+
value.newPageIndex = pageIndex;
|
|
1264
|
+
mustBeAddedInUndoStack || (mustBeAddedInUndoStack = x !== value.savedX ||
|
|
1265
|
+
y !== value.savedY ||
|
|
1266
|
+
pageIndex !== value.savedPageIndex);
|
|
1267
|
+
}
|
|
1268
|
+
if (!mustBeAddedInUndoStack) {
|
|
1269
|
+
return false;
|
|
1270
|
+
}
|
|
1271
|
+
const move = (editor, x, y, pageIndex) => {
|
|
1272
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").has(editor.id)) {
|
|
1273
|
+
// The editor can be undone/redone on a page which is not visible (and
|
|
1274
|
+
// which potentially has no annotation editor layer), hence we need to
|
|
1275
|
+
// use the pageIndex instead of the parent.
|
|
1276
|
+
const parent = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").get(pageIndex);
|
|
1277
|
+
if (parent) {
|
|
1278
|
+
editor._setParentAndPosition(parent, x, y);
|
|
1279
|
+
}
|
|
1280
|
+
else {
|
|
1281
|
+
editor.pageIndex = pageIndex;
|
|
1282
|
+
editor.x = x;
|
|
1283
|
+
editor.y = y;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
this.addCommands({
|
|
1288
|
+
cmd: () => {
|
|
1289
|
+
for (const [editor, { newX, newY, newPageIndex }] of map) {
|
|
1290
|
+
move(editor, newX, newY, newPageIndex);
|
|
1291
|
+
}
|
|
1292
|
+
},
|
|
1293
|
+
undo: () => {
|
|
1294
|
+
for (const [editor, { savedX, savedY, savedPageIndex }] of map) {
|
|
1295
|
+
move(editor, savedX, savedY, savedPageIndex);
|
|
1296
|
+
}
|
|
1297
|
+
},
|
|
1298
|
+
mustExec: true,
|
|
1299
|
+
});
|
|
1300
|
+
return true;
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Drag the set of selected editors.
|
|
1304
|
+
* @param {number} tx
|
|
1305
|
+
* @param {number} ty
|
|
1306
|
+
*/
|
|
1307
|
+
dragSelectedEditors(tx, ty) {
|
|
1308
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_draggingEditors, "f")) {
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_draggingEditors, "f").keys()) {
|
|
1312
|
+
editor.drag(tx, ty);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* Rebuild the editor (usually on undo/redo actions) on a potentially
|
|
1317
|
+
* non-rendered page.
|
|
1318
|
+
* @param {AnnotationEditor} editor
|
|
1319
|
+
*/
|
|
1320
|
+
rebuild(editor) {
|
|
1321
|
+
if (editor.parent === null) {
|
|
1322
|
+
const parent = this.getLayer(editor.pageIndex);
|
|
1323
|
+
if (parent) {
|
|
1324
|
+
parent.changeParent(editor);
|
|
1325
|
+
parent.addOrRebuild(editor);
|
|
1326
|
+
}
|
|
1327
|
+
else {
|
|
1328
|
+
this.addEditor(editor);
|
|
1329
|
+
this.addToAnnotationStorage(editor);
|
|
1330
|
+
editor.rebuild();
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
else {
|
|
1334
|
+
editor.parent.addOrRebuild(editor);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
// get isEditorHandlingKeyboard() {
|
|
1338
|
+
// return (
|
|
1339
|
+
// this.getActive()?.shouldGetKeyboardEvents() ||
|
|
1340
|
+
// (this.#selectedEditors.size === 1 &&
|
|
1341
|
+
// this.firstSelectedEditor.shouldGetKeyboardEvents())
|
|
1342
|
+
// );
|
|
1343
|
+
// }
|
|
1344
|
+
/**
|
|
1345
|
+
* Is the current editor the one passed as argument?
|
|
1346
|
+
* @param {AnnotationEditor} editor
|
|
1347
|
+
* @returns
|
|
1348
|
+
*/
|
|
1349
|
+
isActive(editor) {
|
|
1350
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f") === editor;
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Get the current active editor.
|
|
1354
|
+
* @returns {AnnotationEditor|null}
|
|
1355
|
+
*/
|
|
1356
|
+
getActive() {
|
|
1357
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f");
|
|
1358
|
+
}
|
|
1359
|
+
getActiveEditor() {
|
|
1360
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_activeEditor, "f");
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Get the current editor mode.
|
|
1364
|
+
* @returns {number}
|
|
1365
|
+
*/
|
|
1366
|
+
getMode() {
|
|
1367
|
+
return tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f");
|
|
1368
|
+
}
|
|
1369
|
+
// get imageManager() {
|
|
1370
|
+
// return shadow(this, "imageManager", new ImageManager());
|
|
1371
|
+
// }
|
|
1372
|
+
getSelectionBoxes(textLayer) {
|
|
1373
|
+
if (!textLayer) {
|
|
1374
|
+
return null;
|
|
1375
|
+
}
|
|
1376
|
+
const selection = document.getSelection();
|
|
1377
|
+
for (let i = 0, ii = selection.rangeCount; i < ii; i++) {
|
|
1378
|
+
if (!textLayer.contains(selection.getRangeAt(i).commonAncestorContainer)) {
|
|
1379
|
+
return null;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
const { x: layerX, y: layerY, width: parentWidth, height: parentHeight, } = textLayer.getBoundingClientRect();
|
|
1383
|
+
// We must rotate the boxes because we want to have them in the non-rotated
|
|
1384
|
+
// page coordinates.
|
|
1385
|
+
let rotator;
|
|
1386
|
+
switch (textLayer.getAttribute("data-main-rotation")) {
|
|
1387
|
+
case "90":
|
|
1388
|
+
rotator = (x, y, w, h) => ({
|
|
1389
|
+
x: (y - layerY) / parentHeight,
|
|
1390
|
+
y: 1 - (x + w - layerX) / parentWidth,
|
|
1391
|
+
width: h / parentHeight,
|
|
1392
|
+
height: w / parentWidth,
|
|
1393
|
+
});
|
|
1394
|
+
break;
|
|
1395
|
+
case "180":
|
|
1396
|
+
rotator = (x, y, w, h) => ({
|
|
1397
|
+
x: 1 - (x + w - layerX) / parentWidth,
|
|
1398
|
+
y: 1 - (y + h - layerY) / parentHeight,
|
|
1399
|
+
width: w / parentWidth,
|
|
1400
|
+
height: h / parentHeight,
|
|
1401
|
+
});
|
|
1402
|
+
break;
|
|
1403
|
+
case "270":
|
|
1404
|
+
rotator = (x, y, w, h) => ({
|
|
1405
|
+
x: 1 - (y + h - layerY) / parentHeight,
|
|
1406
|
+
y: (x - layerX) / parentWidth,
|
|
1407
|
+
width: h / parentHeight,
|
|
1408
|
+
height: w / parentWidth,
|
|
1409
|
+
});
|
|
1410
|
+
break;
|
|
1411
|
+
default:
|
|
1412
|
+
rotator = (x, y, w, h) => ({
|
|
1413
|
+
x: (x - layerX) / parentWidth,
|
|
1414
|
+
y: (y - layerY) / parentHeight,
|
|
1415
|
+
width: w / parentWidth,
|
|
1416
|
+
height: h / parentHeight,
|
|
1417
|
+
});
|
|
1418
|
+
break;
|
|
1419
|
+
}
|
|
1420
|
+
const boxes = [];
|
|
1421
|
+
for (let i = 0, ii = selection.rangeCount; i < ii; i++) {
|
|
1422
|
+
const range = selection.getRangeAt(i);
|
|
1423
|
+
if (range.collapsed) {
|
|
1424
|
+
continue;
|
|
1425
|
+
}
|
|
1426
|
+
for (const { x, y, width, height } of range.getClientRects()) {
|
|
1427
|
+
if (width === 0 || height === 0) {
|
|
1428
|
+
continue;
|
|
1429
|
+
}
|
|
1430
|
+
boxes.push(rotator(x, y, width, height));
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
return boxes.length === 0 ? null : boxes;
|
|
1434
|
+
}
|
|
1435
|
+
addChangedExistingAnnotation({ annotationElementId, id }) {
|
|
1436
|
+
(tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_changedExistingAnnotations, tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_changedExistingAnnotations, "f") || new Map(), "f")).set(annotationElementId, id);
|
|
1437
|
+
}
|
|
1438
|
+
removeChangedExistingAnnotation({ annotationElementId }) {
|
|
1439
|
+
var _a;
|
|
1440
|
+
(_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_changedExistingAnnotations, "f")) === null || _a === void 0 ? void 0 : _a.delete(annotationElementId);
|
|
1441
|
+
}
|
|
1442
|
+
renderAnnotationElement(annotation) {
|
|
1443
|
+
var _a;
|
|
1444
|
+
const editorId = (_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_changedExistingAnnotations, "f")) === null || _a === void 0 ? void 0 : _a.get(annotation.data.id);
|
|
1445
|
+
if (!editorId) {
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
const editor = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_annotationStorage, "f").getRawValue(editorId);
|
|
1449
|
+
if (!editor) {
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === pdf_mjs_1.AnnotationEditorType.NONE && !editor.hasBeenModified) {
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
editor.renderAnnotationElement(annotation);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
exports.AnnotationEditorUIManager = AnnotationEditorUIManager;
|
|
1459
|
+
_AnnotationEditorUIManager_abortController = new WeakMap(), _AnnotationEditorUIManager_activeEditor = new WeakMap(), _AnnotationEditorUIManager_allEditors = new WeakMap(), _AnnotationEditorUIManager_allLayers = new WeakMap(), _AnnotationEditorUIManager_annotationStorage = new WeakMap(), _AnnotationEditorUIManager_changedExistingAnnotations = new WeakMap(), _AnnotationEditorUIManager_commandManager = new WeakMap(), _AnnotationEditorUIManager_currentPageIndex = new WeakMap(), _AnnotationEditorUIManager_deletedAnnotationsElementIds = new WeakMap(), _AnnotationEditorUIManager_draggingEditors = new WeakMap(), _AnnotationEditorUIManager_editorTypes = new WeakMap(), _AnnotationEditorUIManager_editorsToRescale = new WeakMap(), _AnnotationEditorUIManager_enableHighlightFloatingButton = new WeakMap(), _AnnotationEditorUIManager_focusMainContainerTimeoutId = new WeakMap(), _AnnotationEditorUIManager_focusManagerAC = new WeakMap(), _AnnotationEditorUIManager_highlightColors = new WeakMap(), _AnnotationEditorUIManager_highlightWhenShiftUp = new WeakMap(), _AnnotationEditorUIManager_highlightToolbar = new WeakMap(), _AnnotationEditorUIManager_idManager = new WeakMap(), _AnnotationEditorUIManager_isEnabled = new WeakMap(), _AnnotationEditorUIManager_isWaiting = new WeakMap(), _AnnotationEditorUIManager_lastActiveElement = new WeakMap(), _AnnotationEditorUIManager_mode = new WeakMap(), _AnnotationEditorUIManager_selectedEditors = new WeakMap(), _AnnotationEditorUIManager_selectedTextNode = new WeakMap(), _AnnotationEditorUIManager_showAllStates = new WeakMap(), _AnnotationEditorUIManager_previousStates = new WeakMap(), _AnnotationEditorUIManager_translation = new WeakMap(), _AnnotationEditorUIManager_translationTimeoutId = new WeakMap(), _AnnotationEditorUIManager_container = new WeakMap(), _AnnotationEditorUIManager_viewer = new WeakMap(), _AnnotationEditorUIManager_instances = new WeakSet(), _AnnotationEditorUIManager_getAnchorElementForSelection = function _AnnotationEditorUIManager_getAnchorElementForSelection({ anchorNode }) {
|
|
1460
|
+
return anchorNode.nodeType === Node.TEXT_NODE
|
|
1461
|
+
? anchorNode.parentElement
|
|
1462
|
+
: anchorNode;
|
|
1463
|
+
}, _AnnotationEditorUIManager_getLayerForTextLayer = function _AnnotationEditorUIManager_getLayerForTextLayer(textLayer) {
|
|
1464
|
+
const { currentLayer } = this;
|
|
1465
|
+
if (currentLayer.hasTextLayer(textLayer)) {
|
|
1466
|
+
return currentLayer;
|
|
1467
|
+
}
|
|
1468
|
+
for (const layer of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values()) {
|
|
1469
|
+
if (layer.hasTextLayer(textLayer)) {
|
|
1470
|
+
return layer;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
return null;
|
|
1474
|
+
}, _AnnotationEditorUIManager_displayHighlightToolbar = function _AnnotationEditorUIManager_displayHighlightToolbar() {
|
|
1475
|
+
const selection = document.getSelection();
|
|
1476
|
+
if (!selection || selection.isCollapsed) {
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1479
|
+
const anchorElement = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_getAnchorElementForSelection).call(this, selection);
|
|
1480
|
+
const textLayer = this.getTextLayerForAnchor(anchorElement);
|
|
1481
|
+
const boxes = this.getSelectionBoxes(textLayer);
|
|
1482
|
+
if (!boxes) {
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
this.showEditorToolBar(anchorElement);
|
|
1486
|
+
// this._eventBus.dispatch("showannotationeditorui", {
|
|
1487
|
+
// source: this,
|
|
1488
|
+
// details: Object.assign(this.#previousStates, details),
|
|
1489
|
+
// });
|
|
1490
|
+
// this.#highlightToolbar ||= new HighlightToolbar(this);
|
|
1491
|
+
// this.#highlightToolbar.show(textLayer, boxes, this.direction === "ltr");
|
|
1492
|
+
}, _AnnotationEditorUIManager_selectionChange = function _AnnotationEditorUIManager_selectionChange() {
|
|
1493
|
+
var _a, _b;
|
|
1494
|
+
const selection = document.getSelection();
|
|
1495
|
+
if (!selection || selection.isCollapsed) {
|
|
1496
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedTextNode, "f")) {
|
|
1497
|
+
// this.#highlightToolbar?.hide();
|
|
1498
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_selectedTextNode, null, "f");
|
|
1499
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
1500
|
+
hasSelectedText: false,
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
return;
|
|
1504
|
+
}
|
|
1505
|
+
const { anchorNode } = selection;
|
|
1506
|
+
if (anchorNode === tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedTextNode, "f")) {
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
const anchorElement = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_getAnchorElementForSelection).call(this, selection);
|
|
1510
|
+
// const textLayer = anchorElement.closest(".textLayer");
|
|
1511
|
+
const textLayer = this.getTextLayerForAnchor(anchorElement);
|
|
1512
|
+
if (!textLayer) {
|
|
1513
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedTextNode, "f")) {
|
|
1514
|
+
(_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightToolbar, "f")) === null || _a === void 0 ? void 0 : _a.hide();
|
|
1515
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_selectedTextNode, null, "f");
|
|
1516
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
1517
|
+
hasSelectedText: false,
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
(_b = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_highlightToolbar, "f")) === null || _b === void 0 ? void 0 : _b.hide();
|
|
1523
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_selectedTextNode, anchorNode, "f");
|
|
1524
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, {
|
|
1525
|
+
hasSelectedText: true,
|
|
1526
|
+
});
|
|
1527
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") !== pdf_mjs_1.AnnotationEditorType.HIGHLIGHT && tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") !== pdf_mjs_1.AnnotationEditorType.NONE) {
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1530
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === pdf_mjs_1.AnnotationEditorType.HIGHLIGHT) {
|
|
1531
|
+
// this.showAllEditors("highlight", true, /* updateButton = */ true);
|
|
1532
|
+
this.showAllEditors("highlight", true);
|
|
1533
|
+
}
|
|
1534
|
+
// this.#highlightWhenShiftUp = this.isShiftKeyDown;
|
|
1535
|
+
if (!this.isShiftKeyDown) {
|
|
1536
|
+
const activeLayer = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === pdf_mjs_1.AnnotationEditorType.HIGHLIGHT
|
|
1537
|
+
? tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_getLayerForTextLayer).call(this, textLayer)
|
|
1538
|
+
: null;
|
|
1539
|
+
activeLayer === null || activeLayer === void 0 ? void 0 : activeLayer.toggleDrawing();
|
|
1540
|
+
const abortController = new AbortController();
|
|
1541
|
+
const signal = this.combinedSignal(abortController);
|
|
1542
|
+
const pointerup = e => {
|
|
1543
|
+
if (e.type === "pointerup" && e.button !== 0) {
|
|
1544
|
+
// Do nothing on right click.
|
|
1545
|
+
return;
|
|
1546
|
+
}
|
|
1547
|
+
abortController.abort();
|
|
1548
|
+
activeLayer === null || activeLayer === void 0 ? void 0 : activeLayer.toggleDrawing(true);
|
|
1549
|
+
if (e.type === "pointerup") {
|
|
1550
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_onSelectEnd).call(this, "main_toolbar");
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
window.removeEventListener("pointerup", pointerup);
|
|
1554
|
+
window.addEventListener("pointerup", pointerup, { signal });
|
|
1555
|
+
window.removeEventListener("blur", pointerup);
|
|
1556
|
+
window.addEventListener("blur", pointerup, { signal });
|
|
1557
|
+
}
|
|
1558
|
+
}, _AnnotationEditorUIManager_onSelectEnd = function _AnnotationEditorUIManager_onSelectEnd(methodOfCreation = "") {
|
|
1559
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === pdf_mjs_1.AnnotationEditorType.HIGHLIGHT) {
|
|
1560
|
+
this.highlightSelection(methodOfCreation);
|
|
1561
|
+
}
|
|
1562
|
+
else if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_enableHighlightFloatingButton, "f")) {
|
|
1563
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_displayHighlightToolbar).call(this);
|
|
1564
|
+
}
|
|
1565
|
+
}, _AnnotationEditorUIManager_addSelectionListener = function _AnnotationEditorUIManager_addSelectionListener() {
|
|
1566
|
+
document.addEventListener("selectionchange", tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_selectionChange).bind(this), { signal: this._signal });
|
|
1567
|
+
}, _AnnotationEditorUIManager_addFocusManager = function _AnnotationEditorUIManager_addFocusManager() {
|
|
1568
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_focusManagerAC, "f")) {
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_focusManagerAC, new AbortController(), "f");
|
|
1572
|
+
const signal = this.combinedSignal(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_focusManagerAC, "f"));
|
|
1573
|
+
window.addEventListener("focus", this.focus.bind(this), { signal });
|
|
1574
|
+
window.addEventListener("blur", this.blur.bind(this), { signal });
|
|
1575
|
+
}, _AnnotationEditorUIManager_removeFocusManager = function _AnnotationEditorUIManager_removeFocusManager() {
|
|
1576
|
+
var _a;
|
|
1577
|
+
(_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_focusManagerAC, "f")) === null || _a === void 0 ? void 0 : _a.abort();
|
|
1578
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_focusManagerAC, null, "f");
|
|
1579
|
+
}, _AnnotationEditorUIManager_addKeyboardManager = function _AnnotationEditorUIManager_addKeyboardManager() {
|
|
1580
|
+
// if (this.#keyboardManagerAC) {
|
|
1581
|
+
// return;
|
|
1582
|
+
// }
|
|
1583
|
+
// this.#keyboardManagerAC = new AbortController();
|
|
1584
|
+
// const signal = this.combinedSignal(this.#keyboardManagerAC);
|
|
1585
|
+
// // The keyboard events are caught at the container level in order to be able
|
|
1586
|
+
// // to execute some callbacks even if the current page doesn't have focus.
|
|
1587
|
+
// window.addEventListener("keydown", this.keydown.bind(this), { signal });
|
|
1588
|
+
// window.addEventListener("keyup", this.keyup.bind(this), { signal });
|
|
1589
|
+
}, _AnnotationEditorUIManager_removeKeyboardManager = function _AnnotationEditorUIManager_removeKeyboardManager() {
|
|
1590
|
+
// this.#keyboardManagerAC?.abort();
|
|
1591
|
+
// this.#keyboardManagerAC = null;
|
|
1592
|
+
}, _AnnotationEditorUIManager_addCopyPasteListeners = function _AnnotationEditorUIManager_addCopyPasteListeners() {
|
|
1593
|
+
// if (this.#copyPasteAC) {
|
|
1594
|
+
// return;
|
|
1595
|
+
// }
|
|
1596
|
+
// this.#copyPasteAC = new AbortController();
|
|
1597
|
+
// const signal = this.combinedSignal(this.#copyPasteAC);
|
|
1598
|
+
// document.addEventListener("copy", this.copy.bind(this), { signal });
|
|
1599
|
+
// document.addEventListener("cut", this.cut.bind(this), { signal });
|
|
1600
|
+
// document.addEventListener("paste", this.paste.bind(this), { signal });
|
|
1601
|
+
}, _AnnotationEditorUIManager_removeCopyPasteListeners = function _AnnotationEditorUIManager_removeCopyPasteListeners() {
|
|
1602
|
+
// this.#copyPasteAC?.abort();
|
|
1603
|
+
// this.#copyPasteAC = null;
|
|
1604
|
+
}, _AnnotationEditorUIManager_addDragAndDropListeners = function _AnnotationEditorUIManager_addDragAndDropListeners() {
|
|
1605
|
+
const signal = this._signal;
|
|
1606
|
+
document.addEventListener("dragover", this.dragOver.bind(this), { signal });
|
|
1607
|
+
document.addEventListener("drop", this.drop.bind(this), { signal });
|
|
1608
|
+
}, _AnnotationEditorUIManager_dispatchUpdateStates = function _AnnotationEditorUIManager_dispatchUpdateStates(details) {
|
|
1609
|
+
if (!details) {
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
const hasChanged = Object.entries(details).some(([key, value]) => tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_previousStates, "f")[key] !== value);
|
|
1613
|
+
if (hasChanged) {
|
|
1614
|
+
this._eventBus.dispatch("annotationeditorstateschanged", {
|
|
1615
|
+
source: this,
|
|
1616
|
+
details: Object.assign(tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_previousStates, "f"), details),
|
|
1617
|
+
});
|
|
1618
|
+
// We could listen on our own event but it sounds like a bit weird and
|
|
1619
|
+
// it's a way to simpler to handle that stuff here instead of having to
|
|
1620
|
+
// add something in every place where an editor can be unselected.
|
|
1621
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_mode, "f") === pdf_mjs_1.AnnotationEditorType.HIGHLIGHT &&
|
|
1622
|
+
details.hasSelectedEditor === false) {
|
|
1623
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateUI).call(this, [
|
|
1624
|
+
[pdf_mjs_1.AnnotationEditorParamsType.HIGHLIGHT_FREE, true],
|
|
1625
|
+
]);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
}, _AnnotationEditorUIManager_dispatchUpdateUI = function _AnnotationEditorUIManager_dispatchUpdateUI(details) {
|
|
1629
|
+
this._eventBus.dispatch("annotationeditorparamschanged", {
|
|
1630
|
+
source: this,
|
|
1631
|
+
details,
|
|
1632
|
+
});
|
|
1633
|
+
}, _AnnotationEditorUIManager_enableAll = function _AnnotationEditorUIManager_enableAll() {
|
|
1634
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_isEnabled, "f")) {
|
|
1635
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_isEnabled, true, "f");
|
|
1636
|
+
for (const layer of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values()) {
|
|
1637
|
+
layer.enable();
|
|
1638
|
+
}
|
|
1639
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values()) {
|
|
1640
|
+
editor.enable();
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
}, _AnnotationEditorUIManager_disableAll = function _AnnotationEditorUIManager_disableAll() {
|
|
1644
|
+
this.unselectAll();
|
|
1645
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_isEnabled, "f")) {
|
|
1646
|
+
tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_isEnabled, false, "f");
|
|
1647
|
+
for (const layer of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").values()) {
|
|
1648
|
+
layer.disable();
|
|
1649
|
+
}
|
|
1650
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values()) {
|
|
1651
|
+
editor.disable();
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
}, _AnnotationEditorUIManager_addEditorToLayer = function _AnnotationEditorUIManager_addEditorToLayer(editor) {
|
|
1655
|
+
const layer = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allLayers, "f").get(editor.pageIndex);
|
|
1656
|
+
if (layer) {
|
|
1657
|
+
layer.addOrRebuild(editor);
|
|
1658
|
+
}
|
|
1659
|
+
else {
|
|
1660
|
+
this.addEditor(editor);
|
|
1661
|
+
this.addToAnnotationStorage(editor);
|
|
1662
|
+
}
|
|
1663
|
+
}, _AnnotationEditorUIManager_lastSelectedEditor_get = function _AnnotationEditorUIManager_lastSelectedEditor_get() {
|
|
1664
|
+
let ed = null;
|
|
1665
|
+
for (ed of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f")) {
|
|
1666
|
+
// Iterate to get the last element.
|
|
1667
|
+
}
|
|
1668
|
+
return ed;
|
|
1669
|
+
}, _AnnotationEditorUIManager_isEmpty = function _AnnotationEditorUIManager_isEmpty() {
|
|
1670
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").size === 0) {
|
|
1671
|
+
return true;
|
|
1672
|
+
}
|
|
1673
|
+
if (tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").size === 1) {
|
|
1674
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_allEditors, "f").values()) {
|
|
1675
|
+
return editor.isEmpty();
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
return false;
|
|
1679
|
+
}, _AnnotationEditorUIManager_selectEditors = function _AnnotationEditorUIManager_selectEditors(editors) {
|
|
1680
|
+
for (const editor of tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f")) {
|
|
1681
|
+
editor.unselect();
|
|
1682
|
+
}
|
|
1683
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").clear();
|
|
1684
|
+
for (const editor of editors) {
|
|
1685
|
+
if (editor.isEmpty()) {
|
|
1686
|
+
continue;
|
|
1687
|
+
}
|
|
1688
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_selectedEditors, "f").add(editor);
|
|
1689
|
+
editor.select();
|
|
1690
|
+
}
|
|
1691
|
+
tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_dispatchUpdateStates).call(this, { hasSelectedEditor: this.hasSelection });
|
|
1692
|
+
};
|
|
1693
|
+
AnnotationEditorUIManager.TRANSLATE_SMALL = 1; // page units.
|
|
1694
|
+
AnnotationEditorUIManager.TRANSLATE_BIG = 10; // page units.
|