@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,294 @@
1
+ /* Copyright 2020 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 _AnnotationStorage_instances, _AnnotationStorage_modified, _AnnotationStorage_modifiedIds, _AnnotationStorage_storage, _AnnotationStorage_setModified, _PrintAnnotationStorage_serializable;
16
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
17
+ import { objectFromMap } from "../shared/utils";
18
+ import { AnnotationEditor } from "../../annotations/editors/annotation-editor";
19
+ import { MurmurHash3_64 } from "../shared/murmurhash3";
20
+ import { shadow } from "pdfjs-dist/legacy/build/pdf.mjs";
21
+ const SerializableEmpty = Object.freeze({
22
+ map: null,
23
+ hash: "",
24
+ transfer: undefined,
25
+ });
26
+ /**
27
+ * Key/value storage for annotation data in forms.
28
+ */
29
+ class AnnotationStorage {
30
+ constructor() {
31
+ _AnnotationStorage_instances.add(this);
32
+ // todo: props
33
+ this.onSetModified = null;
34
+ this.onResetModified = null;
35
+ this.onAnnotationEditor = null;
36
+ // todo: props
37
+ _AnnotationStorage_modified.set(this, false);
38
+ _AnnotationStorage_modifiedIds.set(this, null);
39
+ _AnnotationStorage_storage.set(this, new Map());
40
+ // Callbacks to signal when the modification state is set or reset.
41
+ // This is used by the viewer to only bind on `beforeunload` if forms
42
+ // are actually edited to prevent doing so unconditionally since that
43
+ // can have undesirable effects.
44
+ this.onSetModified = null;
45
+ this.onResetModified = null;
46
+ this.onAnnotationEditor = null;
47
+ }
48
+ /**
49
+ * Get the value for a given key if it exists, or return the default value.
50
+ * @param {string} key
51
+ * @param {Object} defaultValue
52
+ * @returns {Object}
53
+ */
54
+ getValue(key, defaultValue) {
55
+ const value = __classPrivateFieldGet(this, _AnnotationStorage_storage, "f").get(key);
56
+ if (value === undefined) {
57
+ return defaultValue;
58
+ }
59
+ return Object.assign(defaultValue, value);
60
+ }
61
+ /**
62
+ * Get the value for a given key.
63
+ * @param {string} key
64
+ * @returns {Object}
65
+ */
66
+ getRawValue(key) {
67
+ return __classPrivateFieldGet(this, _AnnotationStorage_storage, "f").get(key);
68
+ }
69
+ /**
70
+ * Remove a value from the storage.
71
+ * @param {string} key
72
+ */
73
+ remove(key) {
74
+ __classPrivateFieldGet(this, _AnnotationStorage_storage, "f").delete(key);
75
+ if (__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").size === 0) {
76
+ this.resetModified();
77
+ }
78
+ if (typeof this.onAnnotationEditor === "function") {
79
+ for (const value of __classPrivateFieldGet(this, _AnnotationStorage_storage, "f").values()) {
80
+ if (value instanceof AnnotationEditor) {
81
+ return;
82
+ }
83
+ }
84
+ this.onAnnotationEditor(null);
85
+ }
86
+ }
87
+ /**
88
+ * Set the value for a given key
89
+ * @param {string} key
90
+ * @param {Object} value
91
+ */
92
+ setValue(key, value) {
93
+ const obj = __classPrivateFieldGet(this, _AnnotationStorage_storage, "f").get(key);
94
+ let modified = false;
95
+ if (obj !== undefined) {
96
+ for (const [entry, val] of Object.entries(value)) {
97
+ if (obj[entry] !== val) {
98
+ modified = true;
99
+ obj[entry] = val;
100
+ }
101
+ }
102
+ }
103
+ else {
104
+ modified = true;
105
+ __classPrivateFieldGet(this, _AnnotationStorage_storage, "f").set(key, value);
106
+ }
107
+ if (modified) {
108
+ __classPrivateFieldGet(this, _AnnotationStorage_instances, "m", _AnnotationStorage_setModified).call(this);
109
+ }
110
+ if (value instanceof AnnotationEditor &&
111
+ typeof this.onAnnotationEditor === "function") {
112
+ this.onAnnotationEditor(value.constructor._type);
113
+ }
114
+ }
115
+ /**
116
+ * Check if the storage contains the given key.
117
+ * @param {string} key
118
+ * @returns {boolean}
119
+ */
120
+ has(key) {
121
+ return __classPrivateFieldGet(this, _AnnotationStorage_storage, "f").has(key);
122
+ }
123
+ /**
124
+ * @returns {Object | null}
125
+ */
126
+ getAll() {
127
+ return __classPrivateFieldGet(this, _AnnotationStorage_storage, "f").size > 0 ? objectFromMap(__classPrivateFieldGet(this, _AnnotationStorage_storage, "f")) : null;
128
+ }
129
+ /**
130
+ * @param {Object} obj
131
+ */
132
+ setAll(obj) {
133
+ for (const [key, val] of Object.entries(obj)) {
134
+ this.setValue(key, val);
135
+ }
136
+ }
137
+ get size() {
138
+ return __classPrivateFieldGet(this, _AnnotationStorage_storage, "f").size;
139
+ }
140
+ resetModified() {
141
+ if (__classPrivateFieldGet(this, _AnnotationStorage_modified, "f")) {
142
+ __classPrivateFieldSet(this, _AnnotationStorage_modified, false, "f");
143
+ if (typeof this.onResetModified === "function") {
144
+ this.onResetModified();
145
+ }
146
+ }
147
+ }
148
+ /**
149
+ * @returns {PrintAnnotationStorage}
150
+ */
151
+ get print() {
152
+ return new PrintAnnotationStorage(this);
153
+ }
154
+ /**
155
+ * PLEASE NOTE: Only intended for usage within the API itself.
156
+ * @ignore
157
+ */
158
+ get serializable() {
159
+ if (__classPrivateFieldGet(this, _AnnotationStorage_storage, "f").size === 0) {
160
+ return SerializableEmpty;
161
+ }
162
+ const map = new Map(), hash = new MurmurHash3_64(null), transfer = [];
163
+ const context = Object.create(null);
164
+ let hasBitmap = false;
165
+ for (const [key, val] of __classPrivateFieldGet(this, _AnnotationStorage_storage, "f")) {
166
+ const serialized = val instanceof AnnotationEditor
167
+ ? val.serialize(/* isForCopying = */ false, context)
168
+ : val;
169
+ if (serialized) {
170
+ map.set(key, serialized);
171
+ hash.update(`${key}:${JSON.stringify(serialized)}`);
172
+ hasBitmap || (hasBitmap = !!serialized.bitmap);
173
+ }
174
+ }
175
+ if (hasBitmap) {
176
+ // We must transfer the bitmap data separately, since it can be changed
177
+ // during serialization with SVG images.
178
+ for (const value of map.values()) {
179
+ if (value.bitmap) {
180
+ transfer.push(value.bitmap);
181
+ }
182
+ }
183
+ }
184
+ return map.size > 0
185
+ ? { map, hash: hash.hexdigest(), transfer }
186
+ : SerializableEmpty;
187
+ }
188
+ get editorStats() {
189
+ var _a;
190
+ let stats = null;
191
+ const typeToEditor = new Map();
192
+ for (const value of __classPrivateFieldGet(this, _AnnotationStorage_storage, "f").values()) {
193
+ if (!(value instanceof AnnotationEditor)) {
194
+ continue;
195
+ }
196
+ const editorStats = value.telemetryFinalData;
197
+ if (!editorStats) {
198
+ continue;
199
+ }
200
+ const { type } = editorStats;
201
+ if (!typeToEditor.has(type)) {
202
+ typeToEditor.set(type, Object.getPrototypeOf(value).constructor);
203
+ }
204
+ stats || (stats = Object.create(null));
205
+ const map = (stats[type] || (stats[type] = new Map()));
206
+ for (const [key, val] of Object.entries(editorStats)) {
207
+ if (key === "type") {
208
+ continue;
209
+ }
210
+ let counters = map.get(key);
211
+ if (!counters) {
212
+ counters = new Map();
213
+ map.set(key, counters);
214
+ }
215
+ const count = (_a = counters.get(val)) !== null && _a !== void 0 ? _a : 0;
216
+ counters.set(val, count + 1);
217
+ }
218
+ }
219
+ for (const [type, editor] of typeToEditor) {
220
+ stats[type] = editor.computeTelemetryFinalData(stats[type]);
221
+ }
222
+ return stats;
223
+ }
224
+ resetModifiedIds() {
225
+ __classPrivateFieldSet(this, _AnnotationStorage_modifiedIds, null, "f");
226
+ }
227
+ /**
228
+ * @returns {{ids: Set<string>, hash: string}}
229
+ */
230
+ get modifiedIds() {
231
+ if (__classPrivateFieldGet(this, _AnnotationStorage_modifiedIds, "f")) {
232
+ return __classPrivateFieldGet(this, _AnnotationStorage_modifiedIds, "f");
233
+ }
234
+ const ids = [];
235
+ for (const value of __classPrivateFieldGet(this, _AnnotationStorage_storage, "f").values()) {
236
+ if (!(value instanceof AnnotationEditor) ||
237
+ !value.annotationElementId ||
238
+ !(value.serialize())) {
239
+ continue;
240
+ }
241
+ ids.push(value.annotationElementId);
242
+ }
243
+ return (__classPrivateFieldSet(this, _AnnotationStorage_modifiedIds, {
244
+ ids: new Set(ids),
245
+ hash: ids.join(","),
246
+ }, "f"));
247
+ }
248
+ }
249
+ _AnnotationStorage_modified = new WeakMap(), _AnnotationStorage_modifiedIds = new WeakMap(), _AnnotationStorage_storage = new WeakMap(), _AnnotationStorage_instances = new WeakSet(), _AnnotationStorage_setModified = function _AnnotationStorage_setModified() {
250
+ if (!__classPrivateFieldGet(this, _AnnotationStorage_modified, "f")) {
251
+ __classPrivateFieldSet(this, _AnnotationStorage_modified, true, "f");
252
+ if (typeof this.onSetModified === "function") {
253
+ this.onSetModified();
254
+ }
255
+ }
256
+ };
257
+ /**
258
+ * A special `AnnotationStorage` for use during printing, where the serializable
259
+ * data is *frozen* upon initialization, to prevent scripting from modifying its
260
+ * contents. (Necessary since printing is triggered synchronously in browsers.)
261
+ */
262
+ class PrintAnnotationStorage extends AnnotationStorage {
263
+ constructor(parent) {
264
+ super();
265
+ _PrintAnnotationStorage_serializable.set(this, void 0);
266
+ const { map, hash, transfer } = parent.serializable;
267
+ // Create a *copy* of the data, since Objects are passed by reference in JS.
268
+ const clone = structuredClone(map, transfer ? { transfer } : null);
269
+ __classPrivateFieldSet(this, _PrintAnnotationStorage_serializable, { map: clone, hash, transfer }, "f");
270
+ }
271
+ /**
272
+ * @returns {PrintAnnotationStorage}
273
+ */
274
+ // eslint-disable-next-line getter-return
275
+ get print() {
276
+ // unreachable("Should not call PrintAnnotationStorage.print");
277
+ return null;
278
+ }
279
+ /**
280
+ * PLEASE NOTE: Only intended for usage within the API itself.
281
+ * @ignore
282
+ */
283
+ get serializable() {
284
+ return __classPrivateFieldGet(this, _PrintAnnotationStorage_serializable, "f");
285
+ }
286
+ get modifiedIds() {
287
+ return shadow(this, "modifiedIds", {
288
+ ids: new Set(),
289
+ hash: "",
290
+ });
291
+ }
292
+ }
293
+ _PrintAnnotationStorage_serializable = new WeakMap();
294
+ export { AnnotationStorage, PrintAnnotationStorage, SerializableEmpty };
@@ -0,0 +1,72 @@
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
+ import { shadow, Util } from "../shared/utils";
16
+ // import {} from "pdfjs-dist/legacy/build/pdf.mjs";
17
+ import { getColorValues, getRGB } from "../shared/display_utils";
18
+ export class ColorManager {
19
+ get _colors() {
20
+ if (
21
+ // typeof PDFJSDev !== "undefined" &&
22
+ // PDFJSDev.test("LIB") &&
23
+ typeof document === "undefined") {
24
+ return shadow(this, "_colors", ColorManager._colorsMapping);
25
+ }
26
+ const colors = new Map([
27
+ ["CanvasText", null],
28
+ ["Canvas", null]
29
+ ]);
30
+ getColorValues(colors);
31
+ return shadow(this, "_colors", colors);
32
+ }
33
+ /*
34
+ * In High Contrast Mode, the color on the screen is not always the
35
+ * real color used in the pdf.
36
+ * For example in some cases white can appear to be black but when saving
37
+ * we want to have white.
38
+ * @param {string} color
39
+ * @returns {Array<number>}
40
+ */
41
+ convert(color) {
42
+ const rgb = getRGB(color);
43
+ if (!window.matchMedia("(forced-colors: active)").matches) {
44
+ return rgb;
45
+ }
46
+ for (const [name, RGB] of this._colors) {
47
+ if (RGB.every((x, i) => x === rgb[i])) {
48
+ return ColorManager._colorsMapping.get(name);
49
+ }
50
+ }
51
+ return rgb;
52
+ }
53
+ /*
54
+ * An input element must have its color value as a hex string
55
+ * and not as color name.
56
+ * So this function converts a name into an hex string.
57
+ * @param {string} name
58
+ * @returns {string}
59
+ */
60
+ getHexCode(name) {
61
+ const rgb = this._colors.get(name);
62
+ if (!rgb) {
63
+ return name;
64
+ }
65
+ // @ts-expect-error TS(2556):
66
+ return Util.makeHexColor(...rgb);
67
+ }
68
+ }
69
+ ColorManager._colorsMapping = new Map([
70
+ ["CanvasText", [0, 0, 0]],
71
+ ["Canvas", [255, 255, 255]]
72
+ ]);
@@ -0,0 +1,133 @@
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 _CommandManager_commands, _CommandManager_locked, _CommandManager_maxSize, _CommandManager_position;
16
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
17
+ /*
18
+ * Class to handle undo/redo.
19
+ * Commands are just saved in a buffer.
20
+ * If we hit some memory issues we could likely use a circular buffer.
21
+ * It has to be used as a singleton.
22
+ */
23
+ export class CommandManager {
24
+ constructor(maxSize = 128) {
25
+ _CommandManager_commands.set(this, []);
26
+ _CommandManager_locked.set(this, false);
27
+ _CommandManager_maxSize.set(this, void 0);
28
+ _CommandManager_position.set(this, -1);
29
+ __classPrivateFieldSet(this, _CommandManager_maxSize, maxSize, "f");
30
+ }
31
+ /**
32
+ * @typedef {Object} addOptions
33
+ * @property {function} cmd
34
+ * @property {function} undo
35
+ * @property {function} [post]
36
+ * @property {boolean} mustExec
37
+ * @property {number} type
38
+ * @property {boolean} overwriteIfSameType
39
+ * @property {boolean} keepUndo
40
+ */
41
+ /*
42
+ * Add a new couple of commands to be used in case of redo/undo.
43
+ * @param {addOptions} options
44
+ */
45
+ add({ cmd, undo, post, mustExec, type = NaN, overwriteIfSameType = false, keepUndo = false, }) {
46
+ if (mustExec) {
47
+ cmd();
48
+ }
49
+ if (__classPrivateFieldGet(this, _CommandManager_locked, "f")) {
50
+ return;
51
+ }
52
+ const save = { cmd, undo, post, type };
53
+ if (__classPrivateFieldGet(this, _CommandManager_position, "f") === -1) {
54
+ if (__classPrivateFieldGet(this, _CommandManager_commands, "f").length > 0) {
55
+ // All the commands have been undone and then a new one is added
56
+ // hence we clear the queue.
57
+ __classPrivateFieldGet(this, _CommandManager_commands, "f").length = 0;
58
+ }
59
+ __classPrivateFieldSet(this, _CommandManager_position, 0, "f");
60
+ __classPrivateFieldGet(this, _CommandManager_commands, "f").push(save);
61
+ return;
62
+ }
63
+ if (overwriteIfSameType && __classPrivateFieldGet(this, _CommandManager_commands, "f")[__classPrivateFieldGet(this, _CommandManager_position, "f")].type === type) {
64
+ // For example when we change a color we don't want to
65
+ // be able to undo all the steps, hence we only want to
66
+ // keep the last undoable action in this sequence of actions.
67
+ if (keepUndo) {
68
+ save.undo = __classPrivateFieldGet(this, _CommandManager_commands, "f")[__classPrivateFieldGet(this, _CommandManager_position, "f")].undo;
69
+ }
70
+ __classPrivateFieldGet(this, _CommandManager_commands, "f")[__classPrivateFieldGet(this, _CommandManager_position, "f")] = save;
71
+ return;
72
+ }
73
+ const next = __classPrivateFieldGet(this, _CommandManager_position, "f") + 1;
74
+ if (next === __classPrivateFieldGet(this, _CommandManager_maxSize, "f")) {
75
+ __classPrivateFieldGet(this, _CommandManager_commands, "f").splice(0, 1);
76
+ }
77
+ else {
78
+ __classPrivateFieldSet(this, _CommandManager_position, next, "f");
79
+ if (next < __classPrivateFieldGet(this, _CommandManager_commands, "f").length) {
80
+ __classPrivateFieldGet(this, _CommandManager_commands, "f").splice(next);
81
+ }
82
+ }
83
+ __classPrivateFieldGet(this, _CommandManager_commands, "f").push(save);
84
+ }
85
+ /**
86
+ * Undo the last command.
87
+ */
88
+ undo() {
89
+ if (__classPrivateFieldGet(this, _CommandManager_position, "f") === -1) {
90
+ // Nothing to undo.
91
+ return;
92
+ }
93
+ // Avoid to insert something during the undo execution.
94
+ __classPrivateFieldSet(this, _CommandManager_locked, true, "f");
95
+ const { undo, post } = __classPrivateFieldGet(this, _CommandManager_commands, "f")[__classPrivateFieldGet(this, _CommandManager_position, "f")];
96
+ undo();
97
+ post === null || post === void 0 ? void 0 : post();
98
+ __classPrivateFieldSet(this, _CommandManager_locked, false, "f");
99
+ __classPrivateFieldSet(this, _CommandManager_position, __classPrivateFieldGet(this, _CommandManager_position, "f") - 1, "f");
100
+ }
101
+ /**
102
+ * Redo the last command.
103
+ */
104
+ redo() {
105
+ if (__classPrivateFieldGet(this, _CommandManager_position, "f") < __classPrivateFieldGet(this, _CommandManager_commands, "f").length - 1) {
106
+ __classPrivateFieldSet(this, _CommandManager_position, __classPrivateFieldGet(this, _CommandManager_position, "f") + 1, "f");
107
+ // Avoid to insert something during the redo execution.
108
+ __classPrivateFieldSet(this, _CommandManager_locked, true, "f");
109
+ const { cmd, post } = __classPrivateFieldGet(this, _CommandManager_commands, "f")[__classPrivateFieldGet(this, _CommandManager_position, "f")];
110
+ cmd();
111
+ post === null || post === void 0 ? void 0 : post();
112
+ __classPrivateFieldSet(this, _CommandManager_locked, false, "f");
113
+ }
114
+ }
115
+ /**
116
+ * Check if there is something to undo.
117
+ * @returns {boolean}
118
+ */
119
+ hasSomethingToUndo() {
120
+ return __classPrivateFieldGet(this, _CommandManager_position, "f") !== -1;
121
+ }
122
+ /**
123
+ * Check if there is something to redo.
124
+ * @returns {boolean}
125
+ */
126
+ hasSomethingToRedo() {
127
+ return __classPrivateFieldGet(this, _CommandManager_position, "f") < __classPrivateFieldGet(this, _CommandManager_commands, "f").length - 1;
128
+ }
129
+ destroy() {
130
+ __classPrivateFieldSet(this, _CommandManager_commands, null, "f");
131
+ }
132
+ }
133
+ _CommandManager_commands = new WeakMap(), _CommandManager_locked = new WeakMap(), _CommandManager_maxSize = new WeakMap(), _CommandManager_position = new WeakMap();
@@ -0,0 +1,34 @@
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 _IdManager_id;
16
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
17
+ import { AnnotationEditorPrefix } from "../shared/utils";
18
+ export class IdManager {
19
+ constructor(idPrefix = AnnotationEditorPrefix) {
20
+ _IdManager_id.set(this, 0);
21
+ this.idPrefix = AnnotationEditorPrefix;
22
+ // if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
23
+ Object.defineProperty(this, "reset", {
24
+ value: () => (__classPrivateFieldSet(this, _IdManager_id, 0, "f"))
25
+ });
26
+ // }
27
+ this.idPrefix = idPrefix;
28
+ }
29
+ get id() {
30
+ var _a, _b;
31
+ return `${this.idPrefix}${__classPrivateFieldSet(this, _IdManager_id, (_b = __classPrivateFieldGet(this, _IdManager_id, "f"), _a = _b++, _b), "f"), _a}`;
32
+ }
33
+ }
34
+ _IdManager_id = new WeakMap();