@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.
Files changed (149) hide show
  1. package/dist/es/annotations/annotation-editor-layer-builder.js +139 -0
  2. package/dist/es/annotations/annotation-editor-layer.js +780 -0
  3. package/dist/es/annotations/annotation-editor-ui-manager.js +1690 -0
  4. package/dist/es/annotations/annotation-layer-builder.js +217 -0
  5. package/dist/es/annotations/annotation-layer.js +2793 -0
  6. package/dist/es/annotations/draw-layer-builder.js +65 -0
  7. package/dist/es/annotations/draw-layer.js +220 -0
  8. package/dist/es/annotations/editors/annotation-editor.js +1519 -0
  9. package/dist/es/annotations/editors/free-text-editor.js +783 -0
  10. package/dist/es/annotations/editors/highlight-editor.js +717 -0
  11. package/dist/es/annotations/editors/outliner.js +747 -0
  12. package/dist/es/annotations/helpers/annotation-storage.js +294 -0
  13. package/dist/es/annotations/helpers/color-manager.js +72 -0
  14. package/dist/es/annotations/helpers/command-manager.js +133 -0
  15. package/dist/es/annotations/helpers/id-manager.js +34 -0
  16. package/dist/es/annotations/helpers/image-manager.js +176 -0
  17. package/dist/es/annotations/helpers/text-accessibility-manager.js +212 -0
  18. package/dist/es/annotations/helpers/tools.js +19 -0
  19. package/dist/es/annotations/shared/display_utils.js +1024 -0
  20. package/dist/es/annotations/shared/event_utils.js +213 -0
  21. package/dist/es/annotations/shared/murmurhash3.js +126 -0
  22. package/dist/es/annotations/shared/scripting_utils.js +90 -0
  23. package/dist/es/annotations/shared/ui_utils.js +823 -0
  24. package/dist/es/annotations/shared/utils.js +909 -0
  25. package/dist/es/common/component.js +33 -0
  26. package/dist/es/common/core.js +91 -0
  27. package/dist/es/common/dom.js +11 -0
  28. package/dist/es/common/main.js +4 -0
  29. package/dist/es/common/math.js +1 -0
  30. package/dist/es/enums/PdfViewerInteractionMode.js +6 -0
  31. package/dist/es/links/link-service.js +505 -0
  32. package/dist/es/main.js +2 -0
  33. package/dist/es/scroller.js +29 -30
  34. package/dist/es/text/text-layer-builder.js +288 -0
  35. package/dist/es/utils.js +5 -5
  36. package/dist/es/widget/page.js +762 -0
  37. package/dist/es/widget/pdfviewer.js +1659 -0
  38. package/dist/es2015/annotations/annotation-editor-layer-builder.js +139 -0
  39. package/dist/es2015/annotations/annotation-editor-layer.js +780 -0
  40. package/dist/es2015/annotations/annotation-editor-ui-manager.js +1690 -0
  41. package/dist/es2015/annotations/annotation-layer-builder.js +217 -0
  42. package/dist/es2015/annotations/annotation-layer.js +2793 -0
  43. package/dist/es2015/annotations/draw-layer-builder.js +65 -0
  44. package/dist/es2015/annotations/draw-layer.js +220 -0
  45. package/dist/es2015/annotations/editors/annotation-editor.js +1519 -0
  46. package/dist/es2015/annotations/editors/free-text-editor.js +783 -0
  47. package/dist/es2015/annotations/editors/highlight-editor.js +717 -0
  48. package/dist/es2015/annotations/editors/outliner.js +747 -0
  49. package/dist/es2015/annotations/helpers/annotation-storage.js +294 -0
  50. package/dist/es2015/annotations/helpers/color-manager.js +72 -0
  51. package/dist/es2015/annotations/helpers/command-manager.js +133 -0
  52. package/dist/es2015/annotations/helpers/id-manager.js +34 -0
  53. package/dist/es2015/annotations/helpers/image-manager.js +176 -0
  54. package/dist/es2015/annotations/helpers/text-accessibility-manager.js +212 -0
  55. package/dist/es2015/annotations/helpers/tools.js +19 -0
  56. package/dist/es2015/annotations/shared/display_utils.js +1024 -0
  57. package/dist/es2015/annotations/shared/event_utils.js +213 -0
  58. package/dist/es2015/annotations/shared/murmurhash3.js +126 -0
  59. package/dist/es2015/annotations/shared/scripting_utils.js +90 -0
  60. package/dist/es2015/annotations/shared/ui_utils.js +823 -0
  61. package/dist/es2015/annotations/shared/utils.js +909 -0
  62. package/dist/es2015/common/component.js +33 -0
  63. package/dist/es2015/common/core.js +91 -0
  64. package/dist/es2015/common/dom.js +11 -0
  65. package/dist/es2015/common/main.js +4 -0
  66. package/dist/es2015/common/math.js +1 -0
  67. package/dist/es2015/enums/PdfViewerInteractionMode.js +6 -0
  68. package/dist/es2015/links/link-service.js +505 -0
  69. package/dist/es2015/main.js +2 -0
  70. package/dist/es2015/scroller.js +29 -30
  71. package/dist/es2015/text/text-layer-builder.js +288 -0
  72. package/dist/es2015/utils.js +5 -5
  73. package/dist/es2015/widget/page.js +762 -0
  74. package/dist/es2015/widget/pdfviewer.js +1659 -0
  75. package/dist/npm/annotations/annotation-editor-layer-builder.d.ts +39 -0
  76. package/dist/npm/annotations/annotation-editor-layer-builder.js +142 -0
  77. package/dist/npm/annotations/annotation-editor-layer.d.ts +196 -0
  78. package/dist/npm/annotations/annotation-editor-layer.js +783 -0
  79. package/dist/npm/annotations/annotation-editor-ui-manager.d.ts +281 -0
  80. package/dist/npm/annotations/annotation-editor-ui-manager.js +1694 -0
  81. package/dist/npm/annotations/annotation-layer-builder.d.ts +58 -0
  82. package/dist/npm/annotations/annotation-layer-builder.js +220 -0
  83. package/dist/npm/annotations/annotation-layer.d.ts +134 -0
  84. package/dist/npm/annotations/annotation-layer.js +2794 -0
  85. package/dist/npm/annotations/draw-layer-builder.d.ts +21 -0
  86. package/dist/npm/annotations/draw-layer-builder.js +68 -0
  87. package/dist/npm/annotations/draw-layer.d.ts +33 -0
  88. package/dist/npm/annotations/draw-layer.js +223 -0
  89. package/dist/npm/annotations/editors/annotation-editor.d.ts +349 -0
  90. package/dist/npm/annotations/editors/annotation-editor.js +1523 -0
  91. package/dist/npm/annotations/editors/free-text-editor.d.ts +108 -0
  92. package/dist/npm/annotations/editors/free-text-editor.js +786 -0
  93. package/dist/npm/annotations/editors/highlight-editor.d.ts +114 -0
  94. package/dist/npm/annotations/editors/highlight-editor.js +717 -0
  95. package/dist/npm/annotations/editors/outliner.d.ts +51 -0
  96. package/dist/npm/annotations/editors/outliner.js +750 -0
  97. package/dist/npm/annotations/helpers/annotation-storage.d.ts +98 -0
  98. package/dist/npm/annotations/helpers/annotation-storage.js +299 -0
  99. package/dist/npm/annotations/helpers/color-manager.d.ts +6 -0
  100. package/dist/npm/annotations/helpers/color-manager.js +76 -0
  101. package/dist/npm/annotations/helpers/command-manager.d.ts +42 -0
  102. package/dist/npm/annotations/helpers/command-manager.js +137 -0
  103. package/dist/npm/annotations/helpers/id-manager.d.ts +6 -0
  104. package/dist/npm/annotations/helpers/id-manager.js +38 -0
  105. package/dist/npm/annotations/helpers/image-manager.d.ts +18 -0
  106. package/dist/npm/annotations/helpers/image-manager.js +180 -0
  107. package/dist/npm/annotations/helpers/text-accessibility-manager.d.ts +36 -0
  108. package/dist/npm/annotations/helpers/text-accessibility-manager.js +215 -0
  109. package/dist/npm/annotations/helpers/tools.d.ts +1 -0
  110. package/dist/npm/annotations/helpers/tools.js +23 -0
  111. package/dist/npm/annotations/shared/display_utils.d.ts +6 -0
  112. package/dist/npm/annotations/shared/display_utils.js +1030 -0
  113. package/dist/npm/annotations/shared/event_utils.d.ts +33 -0
  114. package/dist/npm/annotations/shared/event_utils.js +165 -0
  115. package/dist/npm/annotations/shared/murmurhash3.d.ts +8 -0
  116. package/dist/npm/annotations/shared/murmurhash3.js +129 -0
  117. package/dist/npm/annotations/shared/scripting_utils.d.ts +17 -0
  118. package/dist/npm/annotations/shared/scripting_utils.js +93 -0
  119. package/dist/npm/annotations/shared/ui_utils.d.ts +54 -0
  120. package/dist/npm/annotations/shared/ui_utils.js +250 -0
  121. package/dist/npm/annotations/shared/utils.d.ts +148 -0
  122. package/dist/npm/annotations/shared/utils.js +872 -0
  123. package/dist/npm/common/component.d.ts +9 -0
  124. package/dist/npm/common/component.js +37 -0
  125. package/dist/npm/common/core.d.ts +18 -0
  126. package/dist/npm/common/core.js +112 -0
  127. package/dist/npm/common/dom.d.ts +3 -0
  128. package/dist/npm/common/dom.js +17 -0
  129. package/dist/npm/common/main.d.ts +4 -0
  130. package/dist/npm/common/main.js +7 -0
  131. package/dist/npm/common/math.d.ts +1 -0
  132. package/dist/npm/common/math.js +5 -0
  133. package/dist/npm/enums/PdfViewerInteractionMode.d.ts +4 -0
  134. package/dist/npm/enums/PdfViewerInteractionMode.js +9 -0
  135. package/dist/npm/links/link-service.d.ts +116 -0
  136. package/dist/npm/links/link-service.js +501 -0
  137. package/dist/npm/main.d.ts +2 -0
  138. package/dist/npm/main.js +2 -0
  139. package/dist/npm/scroller.d.ts +7 -3
  140. package/dist/npm/scroller.js +32 -32
  141. package/dist/npm/text/text-layer-builder.d.ts +30 -0
  142. package/dist/npm/text/text-layer-builder.js +291 -0
  143. package/dist/npm/utils.d.ts +20 -2
  144. package/dist/npm/utils.js +11 -8
  145. package/dist/npm/widget/page.d.ts +75 -0
  146. package/dist/npm/widget/page.js +763 -0
  147. package/dist/npm/widget/pdfviewer.d.ts +222 -0
  148. package/dist/npm/widget/pdfviewer.js +1663 -0
  149. package/package.json +13 -9
@@ -0,0 +1,1519 @@
1
+ /* Copyright 2022 Mozilla Foundation
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ var _AnnotationEditor_instances, _a, _AnnotationEditor_x, _AnnotationEditor_y, _AnnotationEditor_disabled, _AnnotationEditor_keepAspectRatio, _AnnotationEditor_focusAC, _AnnotationEditor_hasBeenClicked, _AnnotationEditor_initialPosition, _AnnotationEditor_isEditing, _AnnotationEditor_isInEditMode, _AnnotationEditor_moveInDOMTimeout, _AnnotationEditor_prevDragX, _AnnotationEditor_prevDragY, _AnnotationEditor_isDraggable, _AnnotationEditor_zIndex, _AnnotationEditor_translate, _AnnotationEditor_rotatePoint, _AnnotationEditor_selectOnPointerEvent, _AnnotationEditor_setUpDragSession, _AnnotationEditor_addFocusListeners, _AnnotationEditor_stopResizing;
16
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
17
+ // import { AnnotationEditorType, shadow } from "../../shared/utils";
18
+ // import { AnnotationEditorType } from "../../shared/utils";
19
+ // import { FeatureTest } from "../../shared/utils";
20
+ import { IdManager } from "../helpers/id-manager";
21
+ import { ColorManager } from "../helpers/color-manager";
22
+ import { bindEvents } from "../helpers/tools";
23
+ import { shadow, FeatureTest } from "pdfjs-dist/legacy/build/pdf.mjs";
24
+ import { AnnotationEditorType } from "../shared/utils";
25
+ export class AnnotationEditor {
26
+ constructor(parameters) {
27
+ // if (this.constructor === AnnotationEditor) {
28
+ // unreachable("Cannot initialize AnnotationEditor.");
29
+ // }
30
+ _AnnotationEditor_instances.add(this);
31
+ // todo: properties
32
+ this.parent = null;
33
+ this.id = null;
34
+ this.width = null;
35
+ this.height = null;
36
+ this.pageIndex = 0;
37
+ this.name = "";
38
+ this.div = null;
39
+ this.annotationElementId = null;
40
+ this._willKeepAspectRatio = false;
41
+ // _initialOptions = {};
42
+ this._structTreeParentId = null;
43
+ this.rotation = 0;
44
+ this.pageRotation = 0;
45
+ this.pageDimensions = [];
46
+ this.pageTranslation = [];
47
+ // x = 0;
48
+ // y = 0;
49
+ _AnnotationEditor_x.set(this, 0);
50
+ _AnnotationEditor_y.set(this, 0);
51
+ this.isAttachedToDOM = false;
52
+ this.deleted = false;
53
+ // todo: end
54
+ // #accessibilityData = null;
55
+ // #allResizerDivs = null;
56
+ // #altText = null;
57
+ _AnnotationEditor_disabled.set(this, false);
58
+ _AnnotationEditor_keepAspectRatio.set(this, false);
59
+ // #resizersDiv = null;
60
+ // #savedDimensions = null;
61
+ _AnnotationEditor_focusAC.set(this, null);
62
+ // #focusedResizerName = "";
63
+ _AnnotationEditor_hasBeenClicked.set(this, false);
64
+ _AnnotationEditor_initialPosition.set(this, null);
65
+ _AnnotationEditor_isEditing.set(this, false);
66
+ _AnnotationEditor_isInEditMode.set(this, false);
67
+ // #isResizerEnabledForKeyboard = false;
68
+ _AnnotationEditor_moveInDOMTimeout.set(this, null);
69
+ _AnnotationEditor_prevDragX.set(this, 0);
70
+ _AnnotationEditor_prevDragY.set(this, 0);
71
+ // #telemetryTimeouts = null;
72
+ this._editToolbar = null;
73
+ this._initialOptions = Object.create(null);
74
+ this._isVisible = true;
75
+ this._uiManager = null;
76
+ this._focusEventsAllowed = true;
77
+ this._l10nPromise = null;
78
+ _AnnotationEditor_isDraggable.set(this, false);
79
+ _AnnotationEditor_zIndex.set(this, _a._zIndex++);
80
+ this.parent = parameters.parent;
81
+ this.id = parameters.id || _a.idManager.id;
82
+ this.width = this.height = null;
83
+ this.pageIndex = parameters.parent.pageIndex;
84
+ this.name = parameters.name;
85
+ this.div = null;
86
+ this._uiManager = parameters.uiManager;
87
+ this.annotationElementId = null;
88
+ this._willKeepAspectRatio = false;
89
+ this._initialOptions.isCentered = parameters.isCentered;
90
+ this._structTreeParentId = null;
91
+ const { rotation, rawDims: { pageWidth, pageHeight, pageX, pageY } } = this.parent.viewport;
92
+ this.rotation = rotation;
93
+ this.pageRotation =
94
+ (360 + rotation - this._uiManager.viewParameters.rotation) % 360;
95
+ this.pageDimensions = [pageWidth, pageHeight];
96
+ this.pageTranslation = [pageX, pageY];
97
+ const [width, height] = this.parentDimensions;
98
+ this.x = parameters.x / width;
99
+ this.y = parameters.y / height;
100
+ this.isAttachedToDOM = false;
101
+ this.deleted = false;
102
+ }
103
+ get x() {
104
+ return __classPrivateFieldGet(this, _AnnotationEditor_x, "f");
105
+ }
106
+ set x(value) {
107
+ __classPrivateFieldSet(this, _AnnotationEditor_x, value, "f");
108
+ }
109
+ get y() {
110
+ return __classPrivateFieldGet(this, _AnnotationEditor_y, "f");
111
+ }
112
+ set y(value) {
113
+ __classPrivateFieldSet(this, _AnnotationEditor_y, value, "f");
114
+ }
115
+ get editorType() {
116
+ return Object.getPrototypeOf(this).constructor._type;
117
+ }
118
+ static get _defaultLineColor() {
119
+ return shadow(this, "_defaultLineColor", this._colorManager.getHexCode("CanvasText"));
120
+ }
121
+ static deleteAnnotationElement(editor) {
122
+ const fakeEditor = new FakeEditor({
123
+ id: editor.parent.getNextId(),
124
+ parent: editor.parent,
125
+ uiManager: editor._uiManager,
126
+ });
127
+ fakeEditor.annotationElementId = editor.annotationElementId;
128
+ fakeEditor.deleted = true;
129
+ fakeEditor._uiManager.addToAnnotationStorage(fakeEditor);
130
+ }
131
+ static initialize(l10n, _uiManager, options) {
132
+ if (!l10n || !_uiManager || !options) {
133
+ return;
134
+ }
135
+ // static initialize() {
136
+ // AnnotationEditor._l10nPromise ||= new Map(
137
+ // [
138
+ // "pdfjs-editor-alt-text-button-label",
139
+ // "pdfjs-editor-alt-text-edit-button-label",
140
+ // "pdfjs-editor-alt-text-decorative-tooltip",
141
+ // "pdfjs-editor-new-alt-text-added-button-label",
142
+ // "pdfjs-editor-new-alt-text-missing-button-label",
143
+ // "pdfjs-editor-new-alt-text-to-review-button-label",
144
+ // "pdfjs-editor-resizer-label-topLeft",
145
+ // "pdfjs-editor-resizer-label-topMiddle",
146
+ // "pdfjs-editor-resizer-label-topRight",
147
+ // "pdfjs-editor-resizer-label-middleRight",
148
+ // "pdfjs-editor-resizer-label-bottomRight",
149
+ // "pdfjs-editor-resizer-label-bottomMiddle",
150
+ // "pdfjs-editor-resizer-label-bottomLeft",
151
+ // "pdfjs-editor-resizer-label-middleLeft",
152
+ // ].map(str => [
153
+ // str,
154
+ // l10n.get(str.replaceAll(/([A-Z])/g, c => `-${c.toLowerCase()}`)),
155
+ // ])
156
+ // );
157
+ // // The string isn't in the above list because the string has a parameter
158
+ // // (i.e. the guessed text) and we must pass it to the l10n function to get
159
+ // // the correct translation.
160
+ // AnnotationEditor._l10nPromise.set(
161
+ // "pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",
162
+ // l10n.get.bind(
163
+ // l10n,
164
+ // "pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer"
165
+ // )
166
+ // );
167
+ // if (options?.strings) {
168
+ // for (const str of options.strings) {
169
+ // AnnotationEditor._l10nPromise.set(str, l10n.get(str));
170
+ // }
171
+ // }
172
+ // if (AnnotationEditor._borderLineWidth !== -1) {
173
+ // return;
174
+ // }
175
+ // const style = getComputedStyle(document.documentElement);
176
+ // AnnotationEditor._borderLineWidth =
177
+ // parseFloat(style.getPropertyValue("--outline-width")) || 0;
178
+ }
179
+ /**
180
+ * Update the default parameters for this type of editor.
181
+ * @param {number} _type
182
+ * @param {*} _value
183
+ */
184
+ static updateDefaultParams(_type, _value) {
185
+ if (!_type || !_value) {
186
+ return;
187
+ }
188
+ }
189
+ /**
190
+ * Get the default properties to set in the UI for this type of editor.
191
+ * @returns {Array}
192
+ */
193
+ static get defaultPropertiesToUpdate() {
194
+ return [];
195
+ }
196
+ /**
197
+ * Check if this kind of editor is able to handle the given mime type for
198
+ * pasting.
199
+ * @param {string} mime
200
+ * @returns {boolean}
201
+ */
202
+ static isHandlingMimeForPasting(mime) {
203
+ if (!mime) {
204
+ return;
205
+ }
206
+ return false;
207
+ }
208
+ /**
209
+ * Extract the data from the clipboard item and delegate the creation of the
210
+ * editor to the parent.
211
+ * @param {DataTransferItem} item
212
+ * @param {AnnotationEditorLayer} parent
213
+ */
214
+ static paste(item, parent) {
215
+ if (!item || !parent) {
216
+ return;
217
+ }
218
+ // unreachable("Not implemented");
219
+ }
220
+ /**
221
+ * Get the properties to update in the UI for this editor.
222
+ * @returns {Array}
223
+ */
224
+ get propertiesToUpdate() {
225
+ return [];
226
+ }
227
+ get _isDraggable() {
228
+ return __classPrivateFieldGet(this, _AnnotationEditor_isDraggable, "f");
229
+ }
230
+ set _isDraggable(value) {
231
+ var _b;
232
+ __classPrivateFieldSet(this, _AnnotationEditor_isDraggable, value, "f");
233
+ // this.div?.classList.toggle("draggable", value);
234
+ (_b = this.div) === null || _b === void 0 ? void 0 : _b.classList.toggle("k-draggable", value);
235
+ }
236
+ /**
237
+ * @returns {boolean} true if the editor handles the Enter key itself.
238
+ */
239
+ get isEnterHandled() {
240
+ return true;
241
+ }
242
+ center() {
243
+ const [pageWidth, pageHeight] = this.pageDimensions;
244
+ switch (this.parentRotation) {
245
+ case 90:
246
+ this.x -= (this.height * pageHeight) / (pageWidth * 2);
247
+ this.y += (this.width * pageWidth) / (pageHeight * 2);
248
+ break;
249
+ case 180:
250
+ this.x += this.width / 2;
251
+ this.y += this.height / 2;
252
+ break;
253
+ case 270:
254
+ this.x += (this.height * pageHeight) / (pageWidth * 2);
255
+ this.y -= (this.width * pageWidth) / (pageHeight * 2);
256
+ break;
257
+ default:
258
+ this.x -= this.width / 2;
259
+ this.y -= this.height / 2;
260
+ break;
261
+ }
262
+ this.fixAndSetPosition();
263
+ }
264
+ /**
265
+ * Add some commands into the CommandManager (undo/redo stuff).
266
+ * @param {Object} params
267
+ */
268
+ addCommands(params) {
269
+ this._uiManager.addCommands(params);
270
+ }
271
+ get currentLayer() {
272
+ return this._uiManager.currentLayer;
273
+ }
274
+ /**
275
+ * This editor will be behind the others.
276
+ */
277
+ setInBackground() {
278
+ this.div.style.zIndex = 0;
279
+ }
280
+ /**
281
+ * This editor will be in the foreground.
282
+ */
283
+ setInForeground() {
284
+ this.div.style.zIndex = __classPrivateFieldGet(this, _AnnotationEditor_zIndex, "f");
285
+ }
286
+ setParent(parent) {
287
+ if (parent !== null) {
288
+ this.pageIndex = parent.pageIndex;
289
+ this.pageDimensions = parent.pageDimensions;
290
+ }
291
+ else {
292
+ // The editor is being removed from the DOM, so we need to stop resizing.
293
+ __classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_stopResizing).call(this);
294
+ }
295
+ this.parent = parent;
296
+ }
297
+ /**
298
+ * onfocus callback.
299
+ */
300
+ focusin(event) {
301
+ if (!event) {
302
+ return;
303
+ }
304
+ if (!this._focusEventsAllowed) {
305
+ return;
306
+ }
307
+ if (!__classPrivateFieldGet(this, _AnnotationEditor_hasBeenClicked, "f")) {
308
+ this.parent.setSelected(this);
309
+ }
310
+ else {
311
+ __classPrivateFieldSet(this, _AnnotationEditor_hasBeenClicked, false, "f");
312
+ }
313
+ }
314
+ /**
315
+ * onblur callback.
316
+ * @param {FocusEvent} event
317
+ */
318
+ focusout(event) {
319
+ var _b;
320
+ if (!this._focusEventsAllowed) {
321
+ return;
322
+ }
323
+ if (!this.isAttachedToDOM) {
324
+ return;
325
+ }
326
+ // In case of focusout, the relatedTarget is the element which
327
+ // is grabbing the focus.
328
+ // So if the related target is an element under the div for this
329
+ // editor, then the editor isn't unactive.
330
+ const target = event.relatedTarget;
331
+ if (target === null || target === void 0 ? void 0 : target.closest(`#${this.id}`)) {
332
+ return;
333
+ }
334
+ event.preventDefault();
335
+ if (!((_b = this.parent) === null || _b === void 0 ? void 0 : _b.isMultipleSelection)) {
336
+ this.commitOrRemove();
337
+ }
338
+ }
339
+ commitOrRemove() {
340
+ if (this.isEmpty()) {
341
+ this.remove();
342
+ }
343
+ else {
344
+ this.commit();
345
+ }
346
+ }
347
+ /**
348
+ * Commit the data contained in this editor.
349
+ */
350
+ commit() {
351
+ this.addToAnnotationStorage();
352
+ }
353
+ addToAnnotationStorage() {
354
+ this._uiManager.addToAnnotationStorage(this);
355
+ }
356
+ /**
357
+ * Set the editor position within its parent.
358
+ * @param {number} x
359
+ * @param {number} y
360
+ * @param {number} tx - x-translation in screen coordinates.
361
+ * @param {number} ty - y-translation in screen coordinates.
362
+ */
363
+ setAt(x, y, tx, ty) {
364
+ const [width, height] = this.parentDimensions;
365
+ [tx, ty] = this.screenToPageTranslation(tx, ty);
366
+ this.x = (x + tx) / width;
367
+ this.y = (y + ty) / height;
368
+ this.fixAndSetPosition();
369
+ }
370
+ /**
371
+ * Translate the editor position within its parent.
372
+ * @param {number} x - x-translation in screen coordinates.
373
+ * @param {number} y - y-translation in screen coordinates.
374
+ */
375
+ translate(x, y) {
376
+ // We don't change the initial position because the move here hasn't been
377
+ // done by the user.
378
+ __classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_translate).call(this, this.parentDimensions, x, y);
379
+ }
380
+ /**
381
+ * Translate the editor position within its page and adjust the scroll
382
+ * in order to have the editor in the view.
383
+ * @param {number} x - x-translation in page coordinates.
384
+ * @param {number} y - y-translation in page coordinates.
385
+ */
386
+ translateInPage(x, y) {
387
+ __classPrivateFieldSet(this, _AnnotationEditor_initialPosition, __classPrivateFieldGet(this, _AnnotationEditor_initialPosition, "f") || [this.x, this.y], "f");
388
+ __classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_translate).call(this, this.pageDimensions, x, y);
389
+ this.div.scrollIntoView({ block: "nearest" });
390
+ }
391
+ drag(tx, ty) {
392
+ __classPrivateFieldSet(this, _AnnotationEditor_initialPosition, __classPrivateFieldGet(this, _AnnotationEditor_initialPosition, "f") || [this.x, this.y], "f");
393
+ const [parentWidth, parentHeight] = this.parentDimensions;
394
+ this.x += tx / parentWidth;
395
+ this.y += ty / parentHeight;
396
+ if (this.parent && (this.x < 0 || this.x > 1 || this.y < 0 || this.y > 1)) {
397
+ // It's possible to not have a parent: for example, when the user is
398
+ // dragging all the selected editors but this one on a page which has been
399
+ // destroyed.
400
+ // It's why we need to check for it. In such a situation, it isn't really
401
+ // a problem to not find a new parent: it's something which is related to
402
+ // what the user is seeing, hence it depends on how pages are layed out.
403
+ // The element will be outside of its parent so change the parent.
404
+ const { x: xValue, y: yValue } = this.div.getBoundingClientRect();
405
+ if (this.parent.findNewParent(this, xValue, yValue)) {
406
+ this.x -= Math.floor(this.x);
407
+ this.y -= Math.floor(this.y);
408
+ }
409
+ }
410
+ // The editor can be moved wherever the user wants, so we don't need to fix
411
+ // the position: it'll be done when the user will release the mouse button.
412
+ let { x, y } = this;
413
+ const [bx, by] = this.getBaseTranslation();
414
+ x += bx;
415
+ y += by;
416
+ this.div.style.left = `${(100 * x).toFixed(2)}%`;
417
+ this.div.style.top = `${(100 * y).toFixed(2)}%`;
418
+ this.div.scrollIntoView({ block: "nearest" });
419
+ }
420
+ get _hasBeenMoved() {
421
+ return (!!__classPrivateFieldGet(this, _AnnotationEditor_initialPosition, "f") &&
422
+ (__classPrivateFieldGet(this, _AnnotationEditor_initialPosition, "f")[0] !== this.x ||
423
+ __classPrivateFieldGet(this, _AnnotationEditor_initialPosition, "f")[1] !== this.y));
424
+ }
425
+ /**
426
+ * Get the translation to take into account the editor border.
427
+ * The CSS engine positions the element by taking the border into account so
428
+ * we must apply the opposite translation to have the editor in the right
429
+ * position.
430
+ * @returns {Array<number>}
431
+ */
432
+ getBaseTranslation() {
433
+ const [parentWidth, parentHeight] = this.parentDimensions;
434
+ const { _borderLineWidth } = _a;
435
+ const x = _borderLineWidth / parentWidth;
436
+ const y = _borderLineWidth / parentHeight;
437
+ switch (this.rotation) {
438
+ case 90:
439
+ return [-x, y];
440
+ case 180:
441
+ return [x, y];
442
+ case 270:
443
+ return [x, -y];
444
+ default:
445
+ return [-x, -y];
446
+ }
447
+ }
448
+ /**
449
+ * @returns {boolean} true if position must be fixed (i.e. make the x and y
450
+ * living in the page).
451
+ */
452
+ get _mustFixPosition() {
453
+ return true;
454
+ }
455
+ /**
456
+ * Fix the position of the editor in order to keep it inside its parent page.
457
+ * @param {number} [rotation] - the rotation of the page.
458
+ */
459
+ fixAndSetPosition(rotation = this.rotation) {
460
+ if (rotation === undefined) {
461
+ return;
462
+ }
463
+ const [pageWidth, pageHeight] = this.pageDimensions;
464
+ let { x, y, width, height } = this;
465
+ width *= pageWidth;
466
+ height *= pageHeight;
467
+ x *= pageWidth;
468
+ y *= pageHeight;
469
+ if (this._mustFixPosition) {
470
+ switch (rotation) {
471
+ case 0:
472
+ x = Math.max(0, Math.min(pageWidth - width, x));
473
+ y = Math.max(0, Math.min(pageHeight - height, y));
474
+ break;
475
+ case 90:
476
+ x = Math.max(0, Math.min(pageWidth - height, x));
477
+ y = Math.min(pageHeight, Math.max(width, y));
478
+ break;
479
+ case 180:
480
+ x = Math.min(pageWidth, Math.max(width, x));
481
+ y = Math.min(pageHeight, Math.max(height, y));
482
+ break;
483
+ case 270:
484
+ x = Math.min(pageWidth, Math.max(height, x));
485
+ y = Math.max(0, Math.min(pageHeight - width, y));
486
+ break;
487
+ default: break;
488
+ }
489
+ }
490
+ this.x = x /= pageWidth;
491
+ this.y = y /= pageHeight;
492
+ const [bx, by] = this.getBaseTranslation();
493
+ x += bx;
494
+ y += by;
495
+ const { style } = this.div;
496
+ style.left = `${(100 * x).toFixed(2)}%`;
497
+ style.top = `${(100 * y).toFixed(2)}%`;
498
+ this.moveInDOM();
499
+ }
500
+ /**
501
+ * Convert a screen translation into a page one.
502
+ * @param {number} x
503
+ * @param {number} y
504
+ */
505
+ screenToPageTranslation(x, y) {
506
+ return __classPrivateFieldGet(_a, _a, "m", _AnnotationEditor_rotatePoint).call(_a, x, y, this.parentRotation);
507
+ }
508
+ /**
509
+ * Convert a page translation into a screen one.
510
+ * @param {number} x
511
+ * @param {number} y
512
+ */
513
+ pageTranslationToScreen(x, y) {
514
+ return __classPrivateFieldGet(_a, _a, "m", _AnnotationEditor_rotatePoint).call(_a, x, y, 360 - this.parentRotation);
515
+ }
516
+ // #getRotationMatrix(rotation) {
517
+ // switch (rotation) {
518
+ // case 90: {
519
+ // const [pageWidth, pageHeight] = this.pageDimensions;
520
+ // return [0, -pageWidth / pageHeight, pageHeight / pageWidth, 0];
521
+ // }
522
+ // case 180:
523
+ // return [-1, 0, 0, -1];
524
+ // case 270: {
525
+ // const [pageWidth, pageHeight] = this.pageDimensions;
526
+ // return [0, pageWidth / pageHeight, -pageHeight / pageWidth, 0];
527
+ // }
528
+ // default:
529
+ // return [1, 0, 0, 1];
530
+ // }
531
+ // }
532
+ get parentScale() {
533
+ return this._uiManager.viewParameters.realScale;
534
+ }
535
+ get parentRotation() {
536
+ return (this._uiManager.viewParameters.rotation + this.pageRotation) % 360;
537
+ }
538
+ get parentDimensions() {
539
+ const { parentScale, pageDimensions: [pageWidth, pageHeight] } = this;
540
+ const scaledWidth = pageWidth * parentScale;
541
+ const scaledHeight = pageHeight * parentScale;
542
+ return FeatureTest.isCSSRoundSupported
543
+ ? [Math.round(scaledWidth), Math.round(scaledHeight)]
544
+ : [scaledWidth, scaledHeight];
545
+ }
546
+ /**
547
+ * Set the dimensions of this editor.
548
+ * @param {number} width
549
+ * @param {number} height
550
+ */
551
+ setDims(width, height) {
552
+ const [parentWidth, parentHeight] = this.parentDimensions;
553
+ this.div.style.width = `${((100 * width) / parentWidth).toFixed(2)}%`;
554
+ if (!__classPrivateFieldGet(this, _AnnotationEditor_keepAspectRatio, "f")) {
555
+ this.div.style.height = `${((100 * height) / parentHeight).toFixed(2)}%`;
556
+ }
557
+ }
558
+ fixDims() {
559
+ // const { style } = this.div;
560
+ // const { height, width } = style;
561
+ // const widthPercent = width.endsWith("%");
562
+ // const heightPercent = !this.#keepAspectRatio && height.endsWith("%");
563
+ // if (widthPercent && heightPercent) {
564
+ // return;
565
+ // }
566
+ // const [parentWidth, parentHeight] = this.parentDimensions;
567
+ // if (!widthPercent) {
568
+ // style.width = `${((100 * parseFloat(width)) / parentWidth).toFixed(2)}%`;
569
+ // }
570
+ // if (!this.#keepAspectRatio && !heightPercent) {
571
+ // style.height = `${((100 * parseFloat(height)) / parentHeight).toFixed(
572
+ // 2
573
+ // )}%`;
574
+ // }
575
+ }
576
+ /**
577
+ * Get the translation used to position this editor when it's created.
578
+ * @returns {Array<number>}
579
+ */
580
+ getInitialTranslation() {
581
+ return [0, 0];
582
+ }
583
+ // #createResizers() {
584
+ // if (this.#resizersDiv) {
585
+ // return;
586
+ // }
587
+ // this.#resizersDiv = document.createElement("div");
588
+ // this.#resizersDiv.classList.add("resizers");
589
+ // // When the resizers are used with the keyboard, they're focusable, hence
590
+ // // we want to have them in this order (top left, top middle, top right, ...)
591
+ // // in the DOM to have the focus order correct.
592
+ // const classes = this._willKeepAspectRatio
593
+ // ? ["topLeft", "topRight", "bottomRight", "bottomLeft"]
594
+ // : [
595
+ // "topLeft",
596
+ // "topMiddle",
597
+ // "topRight",
598
+ // "middleRight",
599
+ // "bottomRight",
600
+ // "bottomMiddle",
601
+ // "bottomLeft",
602
+ // "middleLeft",
603
+ // ];
604
+ // const signal = this._uiManager._signal;
605
+ // for (const name of classes) {
606
+ // const div = document.createElement("div");
607
+ // this.#resizersDiv.append(div);
608
+ // div.classList.add("resizer", name);
609
+ // div.setAttribute("data-resizer-name", name);
610
+ // div.addEventListener(
611
+ // "pointerdown",
612
+ // this.#resizerPointerdown.bind(this, name),
613
+ // { signal }
614
+ // );
615
+ // div.addEventListener("contextmenu", noContextMenu, { signal });
616
+ // div.tabIndex = -1;
617
+ // }
618
+ // this.div.prepend(this.#resizersDiv);
619
+ // }
620
+ // #resizerPointerdown(name, event) {
621
+ // event.preventDefault();
622
+ // const { isMac } = FeatureTest.platform;
623
+ // if (event.button !== 0 || (event.ctrlKey && isMac)) {
624
+ // return;
625
+ // }
626
+ // this.#altText?.toggle(false);
627
+ // const savedDraggable = this._isDraggable;
628
+ // this._isDraggable = false;
629
+ // const ac = new AbortController();
630
+ // const signal = this._uiManager.combinedSignal(ac);
631
+ // this.parent.togglePointerEvents(false);
632
+ // window.addEventListener(
633
+ // "pointermove",
634
+ // this.#resizerPointermove.bind(this, name),
635
+ // { passive: true, capture: true, signal }
636
+ // );
637
+ // window.addEventListener("contextmenu", noContextMenu, { signal });
638
+ // const savedX = this.x;
639
+ // const savedY = this.y;
640
+ // const savedWidth = this.width;
641
+ // const savedHeight = this.height;
642
+ // const savedParentCursor = this.parent.div.style.cursor;
643
+ // const savedCursor = this.div.style.cursor;
644
+ // this.div.style.cursor = this.parent.div.style.cursor =
645
+ // window.getComputedStyle(event.target).cursor;
646
+ // const pointerUpCallback = () => {
647
+ // ac.abort();
648
+ // this.parent.togglePointerEvents(true);
649
+ // this.#altText?.toggle(true);
650
+ // this._isDraggable = savedDraggable;
651
+ // this.parent.div.style.cursor = savedParentCursor;
652
+ // this.div.style.cursor = savedCursor;
653
+ // this.#addResizeToUndoStack(savedX, savedY, savedWidth, savedHeight);
654
+ // };
655
+ // window.addEventListener("pointerup", pointerUpCallback, { signal });
656
+ // // If the user switches to another window (with alt+tab), then we end the
657
+ // // resize session.
658
+ // window.addEventListener("blur", pointerUpCallback, { signal });
659
+ // }
660
+ // #addResizeToUndoStack(savedX, savedY, savedWidth, savedHeight) {
661
+ // const newX = this.x;
662
+ // const newY = this.y;
663
+ // const newWidth = this.width;
664
+ // const newHeight = this.height;
665
+ // if (
666
+ // newX === savedX &&
667
+ // newY === savedY &&
668
+ // newWidth === savedWidth &&
669
+ // newHeight === savedHeight
670
+ // ) {
671
+ // return;
672
+ // }
673
+ // this.addCommands({
674
+ // cmd: () => {
675
+ // this.width = newWidth;
676
+ // this.height = newHeight;
677
+ // this.x = newX;
678
+ // this.y = newY;
679
+ // const [parentWidth, parentHeight] = this.parentDimensions;
680
+ // this.setDims(parentWidth * newWidth, parentHeight * newHeight);
681
+ // this.fixAndSetPosition();
682
+ // },
683
+ // undo: () => {
684
+ // this.width = savedWidth;
685
+ // this.height = savedHeight;
686
+ // this.x = savedX;
687
+ // this.y = savedY;
688
+ // const [parentWidth, parentHeight] = this.parentDimensions;
689
+ // this.setDims(parentWidth * savedWidth, parentHeight * savedHeight);
690
+ // this.fixAndSetPosition();
691
+ // },
692
+ // mustExec: true,
693
+ // });
694
+ // }
695
+ // #resizerPointermove(name, event) {
696
+ // const [parentWidth, parentHeight] = this.parentDimensions;
697
+ // const savedX = this.x;
698
+ // const savedY = this.y;
699
+ // const savedWidth = this.width;
700
+ // const savedHeight = this.height;
701
+ // const minWidth = AnnotationEditor.MIN_SIZE / parentWidth;
702
+ // const minHeight = AnnotationEditor.MIN_SIZE / parentHeight;
703
+ // // 10000 because we multiply by 100 and use toFixed(2) in fixAndSetPosition.
704
+ // // Without rounding, the positions of the corners other than the top left
705
+ // // one can be slightly wrong.
706
+ // const round = x => Math.round(x * 10000) / 10000;
707
+ // const rotationMatrix = this.#getRotationMatrix(this.rotation);
708
+ // const transf = (x, y) => [
709
+ // rotationMatrix[0] * x + rotationMatrix[2] * y,
710
+ // rotationMatrix[1] * x + rotationMatrix[3] * y,
711
+ // ];
712
+ // const invRotationMatrix = this.#getRotationMatrix(360 - this.rotation);
713
+ // const invTransf = (x, y) => [
714
+ // invRotationMatrix[0] * x + invRotationMatrix[2] * y,
715
+ // invRotationMatrix[1] * x + invRotationMatrix[3] * y,
716
+ // ];
717
+ // let getPoint;
718
+ // let getOpposite;
719
+ // let isDiagonal = false;
720
+ // let isHorizontal = false;
721
+ // switch (name) {
722
+ // case "topLeft":
723
+ // isDiagonal = true;
724
+ // getPoint = (w, h) => [0, 0];
725
+ // getOpposite = (w, h) => [w, h];
726
+ // break;
727
+ // case "topMiddle":
728
+ // getPoint = (w, h) => [w / 2, 0];
729
+ // getOpposite = (w, h) => [w / 2, h];
730
+ // break;
731
+ // case "topRight":
732
+ // isDiagonal = true;
733
+ // getPoint = (w, h) => [w, 0];
734
+ // getOpposite = (w, h) => [0, h];
735
+ // break;
736
+ // case "middleRight":
737
+ // isHorizontal = true;
738
+ // getPoint = (w, h) => [w, h / 2];
739
+ // getOpposite = (w, h) => [0, h / 2];
740
+ // break;
741
+ // case "bottomRight":
742
+ // isDiagonal = true;
743
+ // getPoint = (w, h) => [w, h];
744
+ // getOpposite = (w, h) => [0, 0];
745
+ // break;
746
+ // case "bottomMiddle":
747
+ // getPoint = (w, h) => [w / 2, h];
748
+ // getOpposite = (w, h) => [w / 2, 0];
749
+ // break;
750
+ // case "bottomLeft":
751
+ // isDiagonal = true;
752
+ // getPoint = (w, h) => [0, h];
753
+ // getOpposite = (w, h) => [w, 0];
754
+ // break;
755
+ // case "middleLeft":
756
+ // isHorizontal = true;
757
+ // getPoint = (w, h) => [0, h / 2];
758
+ // getOpposite = (w, h) => [w, h / 2];
759
+ // break;
760
+ // }
761
+ // const point = getPoint(savedWidth, savedHeight);
762
+ // const oppositePoint = getOpposite(savedWidth, savedHeight);
763
+ // let transfOppositePoint = transf(...oppositePoint);
764
+ // const oppositeX = round(savedX + transfOppositePoint[0]);
765
+ // const oppositeY = round(savedY + transfOppositePoint[1]);
766
+ // let ratioX = 1;
767
+ // let ratioY = 1;
768
+ // let [deltaX, deltaY] = this.screenToPageTranslation(
769
+ // event.movementX,
770
+ // event.movementY
771
+ // );
772
+ // [deltaX, deltaY] = invTransf(deltaX / parentWidth, deltaY / parentHeight);
773
+ // if (isDiagonal) {
774
+ // const oldDiag = Math.hypot(savedWidth, savedHeight);
775
+ // ratioX = ratioY = Math.max(
776
+ // Math.min(
777
+ // Math.hypot(
778
+ // oppositePoint[0] - point[0] - deltaX,
779
+ // oppositePoint[1] - point[1] - deltaY
780
+ // ) / oldDiag,
781
+ // // Avoid the editor to be larger than the page.
782
+ // 1 / savedWidth,
783
+ // 1 / savedHeight
784
+ // ),
785
+ // // Avoid the editor to be smaller than the minimum size.
786
+ // minWidth / savedWidth,
787
+ // minHeight / savedHeight
788
+ // );
789
+ // } else if (isHorizontal) {
790
+ // ratioX =
791
+ // Math.max(
792
+ // minWidth,
793
+ // Math.min(1, Math.abs(oppositePoint[0] - point[0] - deltaX))
794
+ // ) / savedWidth;
795
+ // } else {
796
+ // ratioY =
797
+ // Math.max(
798
+ // minHeight,
799
+ // Math.min(1, Math.abs(oppositePoint[1] - point[1] - deltaY))
800
+ // ) / savedHeight;
801
+ // }
802
+ // const newWidth = round(savedWidth * ratioX);
803
+ // const newHeight = round(savedHeight * ratioY);
804
+ // transfOppositePoint = transf(...getOpposite(newWidth, newHeight));
805
+ // const newX = oppositeX - transfOppositePoint[0];
806
+ // const newY = oppositeY - transfOppositePoint[1];
807
+ // this.width = newWidth;
808
+ // this.height = newHeight;
809
+ // this.x = newX;
810
+ // this.y = newY;
811
+ // this.setDims(parentWidth * newWidth, parentHeight * newHeight);
812
+ // this.fixAndSetPosition();
813
+ // }
814
+ // /**
815
+ // * Called when the alt text dialog is closed.
816
+ // */
817
+ // altTextFinish() {
818
+ // this.#altText?.finish();
819
+ // }
820
+ // /**
821
+ // * Add a toolbar for this editor.
822
+ // * @returns {Promise<EditorToolbar|null>}
823
+ // */
824
+ // async addEditToolbar() {
825
+ addEditToolbar() {
826
+ var _b;
827
+ (_b = this._uiManager) === null || _b === void 0 ? void 0 : _b.showEditorToolBar(this.div);
828
+ // if (this._editToolbar || this.#isInEditMode) {
829
+ // return this._editToolbar;
830
+ // }
831
+ // this._editToolbar = new EditorToolbar(this);
832
+ // this.div.append(this._editToolbar.render());
833
+ // if (this.#altText) {
834
+ // this._editToolbar.addAltTextButton(await this.#altText.render());
835
+ // }
836
+ // return this._editToolbar;
837
+ }
838
+ removeEditToolbar() {
839
+ this._uiManager.hideEditorToolBar();
840
+ // if (!this._editToolbar) {
841
+ // return;
842
+ // }
843
+ // this._editToolbar.remove();
844
+ // this._editToolbar = null;
845
+ // // We destroy the alt text but we don't null it because we want to be able
846
+ // // to restore it in case the user undoes the deletion.
847
+ // this.#altText?.destroy();
848
+ }
849
+ getClientDimensions() {
850
+ return this.div.getBoundingClientRect();
851
+ }
852
+ // async addAltTextButton() {
853
+ // if (this.#altText) {
854
+ // return;
855
+ // }
856
+ // AltText.initialize(AnnotationEditor._l10nPromise);
857
+ // this.#altText = new AltText(this);
858
+ // if (this.#accessibilityData) {
859
+ // this.#altText.data = this.#accessibilityData;
860
+ // this.#accessibilityData = null;
861
+ // }
862
+ // await this.addEditToolbar();
863
+ // }
864
+ // get altTextData() {
865
+ // return this.#altText?.data;
866
+ // }
867
+ // /**
868
+ // * Set the alt text data.
869
+ // */
870
+ // set altTextData(data) {
871
+ // if (!this.#altText) {
872
+ // return;
873
+ // }
874
+ // this.#altText.data = data;
875
+ // }
876
+ // get guessedAltText() {
877
+ // return this.#altText?.guessedText;
878
+ // }
879
+ // async setGuessedAltText(text) {
880
+ // await this.#altText?.setGuessedText(text);
881
+ // }
882
+ // serializeAltText(isForCopying) {
883
+ // return this.#altText?.serialize(isForCopying);
884
+ // }
885
+ // hasAltText() {
886
+ // return !!this.#altText && !this.#altText.isEmpty();
887
+ // }
888
+ // hasAltTextData() {
889
+ // return this.#altText?.hasData() ?? false;
890
+ // }
891
+ /**
892
+ * Render this editor in a div.
893
+ * @returns {HTMLDivElement | null}
894
+ */
895
+ render() {
896
+ this.div = document.createElement("div");
897
+ this.div.setAttribute("data-editor-rotation", (360 - this.rotation) % 360);
898
+ this.div.className = this.name;
899
+ this.div.setAttribute("id", this.id);
900
+ this.div.tabIndex = __classPrivateFieldGet(this, _AnnotationEditor_disabled, "f") ? -1 : 0;
901
+ if (!this._isVisible) {
902
+ // this.div.classList.add("hidden");
903
+ this.div.classList.add("k-hidden");
904
+ }
905
+ this.setInForeground();
906
+ __classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_addFocusListeners).call(this);
907
+ const [parentWidth, parentHeight] = this.parentDimensions;
908
+ if (this.parentRotation % 180 !== 0) {
909
+ this.div.style.maxWidth = `${((100 * parentHeight) / parentWidth).toFixed(2)}%`;
910
+ this.div.style.maxHeight = `${((100 * parentWidth) /
911
+ parentHeight).toFixed(2)}%`;
912
+ }
913
+ const [tx, ty] = this.getInitialTranslation();
914
+ this.translate(tx, ty);
915
+ bindEvents(this, this.div, ["pointerdown"]);
916
+ return this.div;
917
+ }
918
+ /**
919
+ * Onpointerdown callback.
920
+ * @param {PointerEvent} event
921
+ */
922
+ pointerdown(event) {
923
+ var _b;
924
+ const { isMac } = FeatureTest.platform;
925
+ if (event.button !== 0 || (event.ctrlKey && isMac)) {
926
+ // Avoid to focus this editor because of a non-left click.
927
+ event.preventDefault();
928
+ return;
929
+ }
930
+ __classPrivateFieldSet(this, _AnnotationEditor_hasBeenClicked, true, "f");
931
+ if (this._isDraggable) {
932
+ (_b = this._uiManager) === null || _b === void 0 ? void 0 : _b.hideEditorToolBar();
933
+ __classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_setUpDragSession).call(this, event);
934
+ return;
935
+ }
936
+ __classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_selectOnPointerEvent).call(this, event);
937
+ }
938
+ moveInDOM() {
939
+ // Moving the editor in the DOM can be expensive, so we wait a bit before.
940
+ // It's important to not block the UI (for example when changing the font
941
+ // size in a FreeText).
942
+ if (__classPrivateFieldGet(this, _AnnotationEditor_moveInDOMTimeout, "f")) {
943
+ clearTimeout(__classPrivateFieldGet(this, _AnnotationEditor_moveInDOMTimeout, "f"));
944
+ }
945
+ __classPrivateFieldSet(this, _AnnotationEditor_moveInDOMTimeout, setTimeout(() => {
946
+ var _b;
947
+ __classPrivateFieldSet(this, _AnnotationEditor_moveInDOMTimeout, null, "f");
948
+ (_b = this.parent) === null || _b === void 0 ? void 0 : _b.moveEditorInDOM(this);
949
+ }, 0), "f");
950
+ }
951
+ _setParentAndPosition(parent, x, y) {
952
+ parent.changeParent(this);
953
+ this.x = x;
954
+ this.y = y;
955
+ this.fixAndSetPosition();
956
+ }
957
+ /*
958
+ * Convert the current rect into a page one.
959
+ * @param {number} tx - x-translation in screen coordinates.
960
+ * @param {number} ty - y-translation in screen coordinates.
961
+ * @param {number} [rotation] - the rotation of the page.
962
+ */
963
+ getRect(tx, ty, rotation = this.rotation) {
964
+ const scale = this.parentScale;
965
+ const [pageWidth, pageHeight] = this.pageDimensions;
966
+ const [pageX, pageY] = this.pageTranslation;
967
+ const shiftX = tx / scale;
968
+ const shiftY = ty / scale;
969
+ const x = this.x * pageWidth;
970
+ const y = this.y * pageHeight;
971
+ const width = this.width * pageWidth;
972
+ const height = this.height * pageHeight;
973
+ switch (rotation) {
974
+ case 0:
975
+ return [
976
+ x + shiftX + pageX,
977
+ pageHeight - y - shiftY - height + pageY,
978
+ x + shiftX + width + pageX,
979
+ pageHeight - y - shiftY + pageY
980
+ ];
981
+ case 90:
982
+ return [
983
+ x + shiftY + pageX,
984
+ pageHeight - y + shiftX + pageY,
985
+ x + shiftY + height + pageX,
986
+ pageHeight - y + shiftX + width + pageY
987
+ ];
988
+ case 180:
989
+ return [
990
+ x - shiftX - width + pageX,
991
+ pageHeight - y + shiftY + pageY,
992
+ x - shiftX + pageX,
993
+ pageHeight - y + shiftY + height + pageY
994
+ ];
995
+ case 270:
996
+ return [
997
+ x - shiftY - height + pageX,
998
+ pageHeight - y - shiftX - width + pageY,
999
+ x - shiftY + pageX,
1000
+ pageHeight - y - shiftX + pageY
1001
+ ];
1002
+ default:
1003
+ throw new Error("Invalid rotation");
1004
+ }
1005
+ }
1006
+ getRectInCurrentCoords(rect, pageHeight) {
1007
+ const [x1, y1, x2, y2] = rect;
1008
+ const width = x2 - x1;
1009
+ const height = y2 - y1;
1010
+ switch (this.rotation) {
1011
+ case 0:
1012
+ return [x1, pageHeight - y2, width, height];
1013
+ case 90:
1014
+ return [x1, pageHeight - y1, height, width];
1015
+ case 180:
1016
+ return [x2, pageHeight - y1, width, height];
1017
+ case 270:
1018
+ return [x2, pageHeight - y2, height, width];
1019
+ default:
1020
+ // throw new Error("Invalid rotation");
1021
+ break;
1022
+ }
1023
+ }
1024
+ // /**
1025
+ // * Executed once this editor has been rendered.
1026
+ // */
1027
+ onceAdded() { }
1028
+ // /**
1029
+ // * Check if the editor contains something.
1030
+ // * @returns {boolean}
1031
+ // */
1032
+ isEmpty() {
1033
+ return false;
1034
+ }
1035
+ /**
1036
+ * Enable edit mode.
1037
+ */
1038
+ enableEditMode() {
1039
+ __classPrivateFieldSet(this, _AnnotationEditor_isInEditMode, true, "f");
1040
+ }
1041
+ /**
1042
+ * Disable edit mode.
1043
+ */
1044
+ disableEditMode() {
1045
+ __classPrivateFieldSet(this, _AnnotationEditor_isInEditMode, false, "f");
1046
+ }
1047
+ /**
1048
+ * Check if the editor is edited.
1049
+ * @returns {boolean}
1050
+ */
1051
+ isInEditMode() {
1052
+ return __classPrivateFieldGet(this, _AnnotationEditor_isInEditMode, "f");
1053
+ }
1054
+ // /**
1055
+ // * If it returns true, then this editor handles the keyboard
1056
+ // * events itself.
1057
+ // * @returns {boolean}
1058
+ // */
1059
+ // shouldGetKeyboardEvents() {
1060
+ // return this.#isResizerEnabledForKeyboard;
1061
+ // }
1062
+ /**
1063
+ * Check if this editor needs to be rebuilt or not.
1064
+ * @returns {boolean}
1065
+ */
1066
+ needsToBeRebuilt() {
1067
+ return this.div && !this.isAttachedToDOM;
1068
+ }
1069
+ /**
1070
+ * Rebuild the editor in case it has been removed on undo.
1071
+ *
1072
+ * To implement in subclasses.
1073
+ */
1074
+ rebuild() {
1075
+ __classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_addFocusListeners).call(this);
1076
+ }
1077
+ /**
1078
+ * Rotate the editor.
1079
+ * @param {number} angle
1080
+ */
1081
+ rotate(angle) {
1082
+ if (angle === undefined || angle === null) {
1083
+ return;
1084
+ }
1085
+ }
1086
+ /**
1087
+ * Serialize the editor.
1088
+ * The result of the serialization will be used to construct a
1089
+ * new annotation to add to the pdf document.
1090
+ *
1091
+ * To implement in subclasses.
1092
+ * @param {boolean} [isForCopying]
1093
+ * @param {Object | null} [context]
1094
+ * @returns {Object | null}
1095
+ */
1096
+ // @ts-expect-error (TS)
1097
+ // eslint-disable-next-line
1098
+ serialize(isForCopying = false, context = null) {
1099
+ // serialize() {
1100
+ }
1101
+ /**
1102
+ * Deserialize the editor.
1103
+ * The result of the deserialization is a new editor.
1104
+ *
1105
+ * @param {Object} data
1106
+ * @param {AnnotationEditorLayer} parent
1107
+ * @param {AnnotationEditorUIManager} uiManager
1108
+ * @returns {AnnotationEditor | null}
1109
+ */
1110
+ static deserialize(data, parent, uiManager) {
1111
+ // @ts-expect-error TS(2556):
1112
+ const editor = new this.prototype.constructor({
1113
+ parent,
1114
+ id: parent.getNextId(),
1115
+ uiManager,
1116
+ });
1117
+ editor.rotation = data.rotation;
1118
+ // editor.#accessibilityData = data.accessibilityData;
1119
+ const [pageWidth, pageHeight] = editor.pageDimensions;
1120
+ const [x, y, width, height] = editor.getRectInCurrentCoords(data.rect, pageHeight);
1121
+ editor.x = x / pageWidth;
1122
+ editor.y = y / pageHeight;
1123
+ editor.width = width / pageWidth;
1124
+ editor.height = height / pageHeight;
1125
+ return editor;
1126
+ }
1127
+ /**
1128
+ * Check if an existing annotation associated with this editor has been
1129
+ * modified.
1130
+ * @returns {boolean}
1131
+ */
1132
+ get hasBeenModified() {
1133
+ return (!!this.annotationElementId && (this.deleted || this.serialize() !== null));
1134
+ }
1135
+ /**
1136
+ * Remove this editor.
1137
+ * It's used on ctrl+backspace action.
1138
+ */
1139
+ remove() {
1140
+ var _b;
1141
+ (_b = __classPrivateFieldGet(this, _AnnotationEditor_focusAC, "f")) === null || _b === void 0 ? void 0 : _b.abort();
1142
+ __classPrivateFieldSet(this, _AnnotationEditor_focusAC, null, "f");
1143
+ if (!this.isEmpty()) {
1144
+ // The editor is removed but it can be back at some point thanks to
1145
+ // undo/redo so we must commit it before.
1146
+ this.commit();
1147
+ }
1148
+ if (this.parent) {
1149
+ this.parent.remove(this);
1150
+ }
1151
+ else {
1152
+ this._uiManager.removeEditor(this);
1153
+ }
1154
+ if (__classPrivateFieldGet(this, _AnnotationEditor_moveInDOMTimeout, "f")) {
1155
+ clearTimeout(__classPrivateFieldGet(this, _AnnotationEditor_moveInDOMTimeout, "f"));
1156
+ __classPrivateFieldSet(this, _AnnotationEditor_moveInDOMTimeout, null, "f");
1157
+ }
1158
+ __classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_stopResizing).call(this);
1159
+ this.removeEditToolbar();
1160
+ // if (this.#telemetryTimeouts) {
1161
+ // for (const timeout of this.#telemetryTimeouts.values()) {
1162
+ // clearTimeout(timeout);
1163
+ // }
1164
+ // this.#telemetryTimeouts = null;
1165
+ // }
1166
+ this.parent = null;
1167
+ }
1168
+ /**
1169
+ * @returns {boolean} true if this editor can be resized.
1170
+ */
1171
+ get isResizable() {
1172
+ return false;
1173
+ }
1174
+ /**
1175
+ * Add the resizers to this editor.
1176
+ */
1177
+ makeResizable() {
1178
+ // if (this.isResizable) {
1179
+ // this.#createResizers();
1180
+ // this.#resizersDiv.classList.remove("hidden");
1181
+ // this.#resizersDiv.classList.remove("k-hidden");
1182
+ // bindEvents(this, this.div, ["keydown"]);
1183
+ // }
1184
+ }
1185
+ get toolbarPosition() {
1186
+ return null;
1187
+ }
1188
+ _stopResizingWithKeyboard() {
1189
+ // this.#stopResizing();
1190
+ // this.div.focus();
1191
+ }
1192
+ /**
1193
+ * Select this editor.
1194
+ */
1195
+ select() {
1196
+ var _b;
1197
+ // this.makeResizable();
1198
+ // this.div?.classList.add("selectedEditor");
1199
+ (_b = this.div) === null || _b === void 0 ? void 0 : _b.classList.add("k-selected");
1200
+ // todo: manually show annotation toolbar
1201
+ this.addEditToolbar();
1202
+ // if (!this._editToolbar) {
1203
+ // this.addEditToolbar().then(() => {
1204
+ // if (this.div?.classList.contains("k-selected selectedEditor")) {
1205
+ // // The editor can have been unselected while we were waiting for the
1206
+ // // edit toolbar to be created, hence we want to be sure that this
1207
+ // // editor is still selected.
1208
+ // this._editToolbar?.show();
1209
+ // }
1210
+ // });
1211
+ // return;
1212
+ // }
1213
+ // this._editToolbar?.show();
1214
+ // this.#altText?.toggleAltTextBadge(false);
1215
+ }
1216
+ /**
1217
+ * Unselect this editor.
1218
+ */
1219
+ unselect() {
1220
+ var _b, _c;
1221
+ // this.#resizersDiv?.classList.add("hidden");
1222
+ // this.div?.classList.remove("selectedEditor");
1223
+ (_b = this.div) === null || _b === void 0 ? void 0 : _b.classList.remove("k-selected");
1224
+ if ((_c = this.div) === null || _c === void 0 ? void 0 : _c.contains(document.activeElement)) {
1225
+ // Don't use this.div.blur() because we don't know where the focus will
1226
+ // go.
1227
+ this._uiManager.currentLayer.div.focus({
1228
+ preventScroll: true,
1229
+ });
1230
+ }
1231
+ // this._editToolbar?.hide();
1232
+ // this.#altText?.toggleAltTextBadge(true);
1233
+ }
1234
+ /**
1235
+ * Update some parameters which have been changed through the UI.
1236
+ * @param {number} type
1237
+ * @param {*} value
1238
+ */
1239
+ updateParams(type, value) {
1240
+ if (type === undefined || !value) {
1241
+ return;
1242
+ }
1243
+ }
1244
+ /**
1245
+ * When the user disables the editing mode some editors can change some of
1246
+ * their properties.
1247
+ */
1248
+ disableEditing() { }
1249
+ /**
1250
+ * When the user enables the editing mode some editors can change some of
1251
+ * their properties.
1252
+ */
1253
+ enableEditing() { }
1254
+ /**
1255
+ * The editor is about to be edited.
1256
+ */
1257
+ enterInEditMode() { }
1258
+ /**
1259
+ * @returns {HTMLElement | null} the element requiring an alt text.
1260
+ */
1261
+ getImageForAltText() {
1262
+ return null;
1263
+ }
1264
+ /**
1265
+ * Get the div which really contains the displayed content.
1266
+ * @returns {HTMLDivElement | undefined}
1267
+ */
1268
+ get contentDiv() {
1269
+ return this.div;
1270
+ }
1271
+ /**
1272
+ * If true then the editor is currently edited.
1273
+ * @type {boolean}
1274
+ */
1275
+ get isEditing() {
1276
+ return __classPrivateFieldGet(this, _AnnotationEditor_isEditing, "f");
1277
+ }
1278
+ /**
1279
+ * When set to true, it means that this editor is currently edited.
1280
+ * @param {boolean} value
1281
+ */
1282
+ set isEditing(value) {
1283
+ __classPrivateFieldSet(this, _AnnotationEditor_isEditing, value, "f");
1284
+ if (!this.parent) {
1285
+ return;
1286
+ }
1287
+ if (value) {
1288
+ this.parent.setSelected(this);
1289
+ this.parent.setActiveEditor(this);
1290
+ }
1291
+ else {
1292
+ this.parent.setActiveEditor(null);
1293
+ }
1294
+ }
1295
+ /**
1296
+ * Set the aspect ratio to use when resizing.
1297
+ * @param {number} width
1298
+ * @param {number} height
1299
+ */
1300
+ setAspectRatio(width, height) {
1301
+ __classPrivateFieldSet(this, _AnnotationEditor_keepAspectRatio, true, "f");
1302
+ const aspectRatio = width / height;
1303
+ const { style } = this.div;
1304
+ style.aspectRatio = aspectRatio;
1305
+ style.height = "auto";
1306
+ }
1307
+ static get MIN_SIZE() {
1308
+ return 16;
1309
+ }
1310
+ static canCreateNewEmptyEditor() {
1311
+ return true;
1312
+ }
1313
+ /**
1314
+ * Get the data to report to the telemetry when the editor is added.
1315
+ * @returns {Object}
1316
+ */
1317
+ get telemetryInitialData() {
1318
+ return { action: "added" };
1319
+ }
1320
+ /**
1321
+ * The telemetry data to use when saving/printing.
1322
+ * @returns {Object|null}
1323
+ */
1324
+ get telemetryFinalData() {
1325
+ return null;
1326
+ }
1327
+ _reportTelemetry() {
1328
+ }
1329
+ // _reportTelemetry(data, mustWait = false) {
1330
+ // if (mustWait) {
1331
+ // this.#telemetryTimeouts ||= new Map();
1332
+ // const { action } = data;
1333
+ // let timeout = this.#telemetryTimeouts.get(action);
1334
+ // if (timeout) {
1335
+ // clearTimeout(timeout);
1336
+ // }
1337
+ // timeout = setTimeout(() => {
1338
+ // this._reportTelemetry(data);
1339
+ // this.#telemetryTimeouts.delete(action);
1340
+ // if (this.#telemetryTimeouts.size === 0) {
1341
+ // this.#telemetryTimeouts = null;
1342
+ // }
1343
+ // }, AnnotationEditor._telemetryTimeout);
1344
+ // this.#telemetryTimeouts.set(action, timeout);
1345
+ // return;
1346
+ // }
1347
+ // data.type ||= this.editorType;
1348
+ // this._uiManager._eventBus.dispatch("reporttelemetry", {
1349
+ // source: this,
1350
+ // details: {
1351
+ // type: "editing",
1352
+ // data,
1353
+ // },
1354
+ // });
1355
+ // }
1356
+ /**
1357
+ * Show or hide this editor.
1358
+ * @param {boolean|undefined} visible
1359
+ */
1360
+ show(visible = this._isVisible) {
1361
+ // this.div.classList.toggle("hidden", !visible);
1362
+ this.div.classList.toggle("k-hidden", !visible);
1363
+ this._isVisible = visible;
1364
+ }
1365
+ enable() {
1366
+ if (this.div) {
1367
+ this.div.tabIndex = 0;
1368
+ }
1369
+ __classPrivateFieldSet(this, _AnnotationEditor_disabled, false, "f");
1370
+ }
1371
+ disable() {
1372
+ if (this.div) {
1373
+ this.div.tabIndex = -1;
1374
+ }
1375
+ __classPrivateFieldSet(this, _AnnotationEditor_disabled, true, "f");
1376
+ }
1377
+ /**
1378
+ * Render an annotation in the annotation layer.
1379
+ * @param {Object} annotation
1380
+ * @returns {HTMLElement}
1381
+ */
1382
+ renderAnnotationElement(annotation) {
1383
+ let content = annotation.container.querySelector(".annotationContent") ||
1384
+ annotation.container.querySelector(".k-annotation-content ");
1385
+ if (!content) {
1386
+ content = document.createElement("div");
1387
+ // content.classList.add("annotationContent", this.editorType);
1388
+ content.classList.add("k-annotation-content ", this.editorType);
1389
+ annotation.container.prepend(content);
1390
+ }
1391
+ else if (content.nodeName === "CANVAS") {
1392
+ const canvas = content;
1393
+ content = document.createElement("div");
1394
+ // content.classList.add("annotationContent", this.editorType);
1395
+ content.classList.add("k-annotation-content ", this.editorType);
1396
+ canvas.before(content);
1397
+ }
1398
+ return content;
1399
+ }
1400
+ resetAnnotationElement(annotation) {
1401
+ const { firstChild } = annotation.container;
1402
+ if (firstChild.nodeName === "DIV" &&
1403
+ (firstChild.classList.contains("annotationContent") ||
1404
+ firstChild.classList.contains("k-annotation-content "))) {
1405
+ firstChild.remove();
1406
+ }
1407
+ }
1408
+ }
1409
+ _a = AnnotationEditor, _AnnotationEditor_x = new WeakMap(), _AnnotationEditor_y = new WeakMap(), _AnnotationEditor_disabled = new WeakMap(), _AnnotationEditor_keepAspectRatio = new WeakMap(), _AnnotationEditor_focusAC = new WeakMap(), _AnnotationEditor_hasBeenClicked = new WeakMap(), _AnnotationEditor_initialPosition = new WeakMap(), _AnnotationEditor_isEditing = new WeakMap(), _AnnotationEditor_isInEditMode = new WeakMap(), _AnnotationEditor_moveInDOMTimeout = new WeakMap(), _AnnotationEditor_prevDragX = new WeakMap(), _AnnotationEditor_prevDragY = new WeakMap(), _AnnotationEditor_isDraggable = new WeakMap(), _AnnotationEditor_zIndex = new WeakMap(), _AnnotationEditor_instances = new WeakSet(), _AnnotationEditor_translate = function _AnnotationEditor_translate([width, height], x, y) {
1410
+ [x, y] = this.screenToPageTranslation(x, y);
1411
+ this.x += x / width;
1412
+ this.y += y / height;
1413
+ this.fixAndSetPosition();
1414
+ }, _AnnotationEditor_rotatePoint = function _AnnotationEditor_rotatePoint(x, y, angle) {
1415
+ switch (angle) {
1416
+ case 90:
1417
+ return [y, -x];
1418
+ case 180:
1419
+ return [-x, -y];
1420
+ case 270:
1421
+ return [-y, x];
1422
+ default:
1423
+ return [x, y];
1424
+ }
1425
+ }, _AnnotationEditor_selectOnPointerEvent = function _AnnotationEditor_selectOnPointerEvent(event) {
1426
+ const { isMac } = FeatureTest.platform;
1427
+ const highlightEditor = event.target.closest(".k-highlight-editor");
1428
+ const freeTextEditor = event.target.closest(".k-free-text-editor");
1429
+ const annotationEditorMode = this._uiManager.getMode();
1430
+ // todo: manually prevent selecting a highlight annotation in freetext mode
1431
+ if ((annotationEditorMode === AnnotationEditorType.HIGHLIGHT && !highlightEditor) ||
1432
+ (annotationEditorMode === AnnotationEditorType.FREETEXT && !freeTextEditor)) {
1433
+ return;
1434
+ }
1435
+ if ((event.ctrlKey && !isMac) ||
1436
+ event.shiftKey ||
1437
+ (event.metaKey && isMac)) {
1438
+ this.parent.toggleSelected(this);
1439
+ }
1440
+ else {
1441
+ this.parent.setSelected(this);
1442
+ }
1443
+ }, _AnnotationEditor_setUpDragSession = function _AnnotationEditor_setUpDragSession(event) {
1444
+ const isSelected = this._uiManager.isSelected(this);
1445
+ this._uiManager.setUpDragSession();
1446
+ const ac = new AbortController();
1447
+ const signal = this._uiManager.combinedSignal(ac);
1448
+ if (isSelected) {
1449
+ // this.div.classList.add("moving");
1450
+ __classPrivateFieldSet(this, _AnnotationEditor_prevDragX, event.clientX, "f");
1451
+ __classPrivateFieldSet(this, _AnnotationEditor_prevDragY, event.clientY, "f");
1452
+ const pointerMoveCallback = e => {
1453
+ const { clientX: x, clientY: y } = e;
1454
+ const [tx, ty] = this.screenToPageTranslation(x - __classPrivateFieldGet(this, _AnnotationEditor_prevDragX, "f"), y - __classPrivateFieldGet(this, _AnnotationEditor_prevDragY, "f"));
1455
+ __classPrivateFieldSet(this, _AnnotationEditor_prevDragX, x, "f");
1456
+ __classPrivateFieldSet(this, _AnnotationEditor_prevDragY, y, "f");
1457
+ this._uiManager.dragSelectedEditors(tx, ty);
1458
+ };
1459
+ window.addEventListener("pointermove", pointerMoveCallback, {
1460
+ passive: true,
1461
+ capture: true,
1462
+ signal,
1463
+ });
1464
+ }
1465
+ const pointerUpCallback = () => {
1466
+ ac.abort();
1467
+ if (isSelected) {
1468
+ this.div.classList.remove("moving");
1469
+ }
1470
+ __classPrivateFieldSet(this, _AnnotationEditor_hasBeenClicked, false, "f");
1471
+ if (!this._uiManager.endDragSession()) {
1472
+ __classPrivateFieldGet(this, _AnnotationEditor_instances, "m", _AnnotationEditor_selectOnPointerEvent).call(this, event);
1473
+ }
1474
+ };
1475
+ window.addEventListener("pointerup", pointerUpCallback, { signal });
1476
+ // If the user is using alt+tab during the dragging session, the pointerup
1477
+ // event could be not fired, but a blur event is fired so we can use it in
1478
+ // order to interrupt the dragging session.
1479
+ window.addEventListener("blur", pointerUpCallback, { signal });
1480
+ }, _AnnotationEditor_addFocusListeners = function _AnnotationEditor_addFocusListeners() {
1481
+ if (__classPrivateFieldGet(this, _AnnotationEditor_focusAC, "f") || !this.div) {
1482
+ return;
1483
+ }
1484
+ __classPrivateFieldSet(this, _AnnotationEditor_focusAC, new AbortController(), "f");
1485
+ const signal = this._uiManager.combinedSignal(__classPrivateFieldGet(this, _AnnotationEditor_focusAC, "f"));
1486
+ this.div.addEventListener("focusin", this.focusin.bind(this), { signal });
1487
+ this.div.addEventListener("focusout", this.focusout.bind(this), { signal });
1488
+ }, _AnnotationEditor_stopResizing = function _AnnotationEditor_stopResizing() {
1489
+ // this.#isResizerEnabledForKeyboard = false;
1490
+ // this.#setResizerTabIndex(-1);
1491
+ // if (this.#savedDimensions) {
1492
+ // const { savedX, savedY, savedWidth, savedHeight } = this.#savedDimensions;
1493
+ // this.#addResizeToUndoStack(savedX, savedY, savedWidth, savedHeight);
1494
+ // this.#savedDimensions = null;
1495
+ // }
1496
+ };
1497
+ AnnotationEditor.idManager = new IdManager("annotation_editor_id_");
1498
+ AnnotationEditor._borderLineWidth = -1;
1499
+ AnnotationEditor._colorManager = new ColorManager();
1500
+ AnnotationEditor._zIndex = 1;
1501
+ // Time to wait (in ms) before sending the telemetry data.
1502
+ // We wait a bit to avoid sending too many requests when changing something
1503
+ // like the thickness of a line.
1504
+ AnnotationEditor._telemetryTimeout = 1000;
1505
+ // This class is used to fake an editor which has been deleted.
1506
+ class FakeEditor extends AnnotationEditor {
1507
+ constructor(params) {
1508
+ super(params);
1509
+ this.annotationElementId = params.annotationElementId;
1510
+ this.deleted = true;
1511
+ }
1512
+ serialize() {
1513
+ return {
1514
+ id: this.annotationElementId,
1515
+ deleted: true,
1516
+ pageIndex: this.pageIndex,
1517
+ };
1518
+ }
1519
+ }