@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,38 @@
1
+ "use strict";
2
+ /* Copyright 2022 Mozilla Foundation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var _IdManager_id;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.IdManager = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const utils_1 = require("../shared/utils");
21
+ class IdManager {
22
+ constructor(idPrefix = utils_1.AnnotationEditorPrefix) {
23
+ _IdManager_id.set(this, 0);
24
+ this.idPrefix = utils_1.AnnotationEditorPrefix;
25
+ // if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
26
+ Object.defineProperty(this, "reset", {
27
+ value: () => (tslib_1.__classPrivateFieldSet(this, _IdManager_id, 0, "f"))
28
+ });
29
+ // }
30
+ this.idPrefix = idPrefix;
31
+ }
32
+ get id() {
33
+ var _a, _b;
34
+ return `${this.idPrefix}${tslib_1.__classPrivateFieldSet(this, _IdManager_id, (_b = tslib_1.__classPrivateFieldGet(this, _IdManager_id, "f"), _a = _b++, _b), "f"), _a}`;
35
+ }
36
+ }
37
+ exports.IdManager = IdManager;
38
+ _IdManager_id = new WeakMap();
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Class to manage the images used by the editors.
3
+ * The main idea is to try to minimize the memory used by the images.
4
+ * The images are cached and reused when possible
5
+ * We use a refCounter to know when an image is not used anymore but we need to
6
+ * be able to restore an image after a remove+undo, so we keep a file reference
7
+ * or an url one.
8
+ */
9
+ export declare class ImageManager {
10
+ #private;
11
+ static get _isSVGFittingCanvas(): any;
12
+ getFromFile(file: any): Promise<any>;
13
+ getFromUrl(url: any): Promise<any>;
14
+ getFromId(id: any): Promise<any>;
15
+ getSvgUrl(id: any): any;
16
+ deleteId(id: any): void;
17
+ isValidId(id: any): any;
18
+ }
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ /* Copyright 2022 Mozilla Foundation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var _ImageManager_instances, _a, _ImageManager_baseId, _ImageManager_id, _ImageManager_cache, _ImageManager_get;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ImageManager = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const pdf_mjs_1 = require("pdfjs-dist/legacy/build/pdf.mjs");
21
+ const utils_1 = require("../shared/utils");
22
+ /**
23
+ * Class to manage the images used by the editors.
24
+ * The main idea is to try to minimize the memory used by the images.
25
+ * The images are cached and reused when possible
26
+ * We use a refCounter to know when an image is not used anymore but we need to
27
+ * be able to restore an image after a remove+undo, so we keep a file reference
28
+ * or an url one.
29
+ */
30
+ class ImageManager {
31
+ constructor() {
32
+ _ImageManager_instances.add(this);
33
+ _ImageManager_baseId.set(this, (0, utils_1.getUuid)());
34
+ _ImageManager_id.set(this, 0);
35
+ _ImageManager_cache.set(this, null);
36
+ }
37
+ static get _isSVGFittingCanvas() {
38
+ // By default, Firefox doesn't rescale without preserving the aspect ratio
39
+ // when drawing an SVG image on a canvas, see https://bugzilla.mozilla.org/1547776.
40
+ // The "workaround" is to append "svgView(preserveAspectRatio(none))" to the
41
+ // url, but according to comment #15, it seems that it leads to unexpected
42
+ // behavior in Safari.
43
+ const svg = `data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>`;
44
+ const canvas = new OffscreenCanvas(1, 3);
45
+ const ctx = canvas.getContext("2d", { willReadFrequently: true });
46
+ const image = new Image();
47
+ image.src = svg;
48
+ const promise = image.decode().then(() => {
49
+ ctx.drawImage(image, 0, 0, 1, 1, 0, 0, 1, 3);
50
+ return new Uint32Array(ctx.getImageData(0, 0, 1, 1).data.buffer)[0] === 0;
51
+ });
52
+ return (0, pdf_mjs_1.shadow)(this, "_isSVGFittingCanvas", promise);
53
+ }
54
+ getFromFile(file) {
55
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
56
+ const { lastModified, name, size, type } = file;
57
+ return tslib_1.__classPrivateFieldGet(this, _ImageManager_instances, "m", _ImageManager_get).call(this, `${lastModified}_${name}_${size}_${type}`, file);
58
+ });
59
+ }
60
+ getFromUrl(url) {
61
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
62
+ return tslib_1.__classPrivateFieldGet(this, _ImageManager_instances, "m", _ImageManager_get).call(this, url, url);
63
+ });
64
+ }
65
+ getFromId(id) {
66
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
67
+ tslib_1.__classPrivateFieldSet(this, _ImageManager_cache, tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f") || new Map(), "f");
68
+ const data = tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").get(id);
69
+ if (!data) {
70
+ return null;
71
+ }
72
+ if (data.bitmap) {
73
+ data.refCounter += 1;
74
+ return data;
75
+ }
76
+ if (data.file) {
77
+ return this.getFromFile(data.file);
78
+ }
79
+ return this.getFromUrl(data.url);
80
+ });
81
+ }
82
+ getSvgUrl(id) {
83
+ const data = tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").get(id);
84
+ if (!(data === null || data === void 0 ? void 0 : data.isSvg)) {
85
+ return null;
86
+ }
87
+ return data.svgUrl;
88
+ }
89
+ deleteId(id) {
90
+ tslib_1.__classPrivateFieldSet(this, _ImageManager_cache, tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f") || new Map(), "f");
91
+ const data = tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").get(id);
92
+ if (!data) {
93
+ return;
94
+ }
95
+ data.refCounter -= 1;
96
+ if (data.refCounter !== 0) {
97
+ return;
98
+ }
99
+ data.bitmap = null;
100
+ }
101
+ // We can use the id only if it belongs this manager.
102
+ // We must take care of having the right manager because we can copy/paste
103
+ // some images from other documents, hence it'd be a pity to use an id from an
104
+ // other manager.
105
+ isValidId(id) {
106
+ return id.startsWith(`image_${tslib_1.__classPrivateFieldGet(this, _ImageManager_baseId, "f")}_`);
107
+ }
108
+ }
109
+ exports.ImageManager = ImageManager;
110
+ _a = ImageManager, _ImageManager_baseId = new WeakMap(), _ImageManager_id = new WeakMap(), _ImageManager_cache = new WeakMap(), _ImageManager_instances = new WeakSet(), _ImageManager_get = function _ImageManager_get(key, rawData) {
111
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
112
+ var _b, _c;
113
+ tslib_1.__classPrivateFieldSet(this, _ImageManager_cache, tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f") || new Map(), "f");
114
+ let data = tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").get(key);
115
+ if (data === null) {
116
+ // We already tried to load the image but it failed.
117
+ return null;
118
+ }
119
+ if (data === null || data === void 0 ? void 0 : data.bitmap) {
120
+ data.refCounter += 1;
121
+ return data;
122
+ }
123
+ try {
124
+ data || (data = {
125
+ bitmap: null,
126
+ id: `image_${tslib_1.__classPrivateFieldGet(this, _ImageManager_baseId, "f")}_${tslib_1.__classPrivateFieldSet(this, _ImageManager_id, (_c = tslib_1.__classPrivateFieldGet(this, _ImageManager_id, "f"), _b = _c++, _c), "f"), _b}`,
127
+ refCounter: 0,
128
+ isSvg: false,
129
+ });
130
+ let image;
131
+ if (typeof rawData === "string") {
132
+ data.url = rawData;
133
+ image = yield (0, pdf_mjs_1.fetchData)(rawData, "blob");
134
+ }
135
+ else {
136
+ image = data.file = rawData;
137
+ }
138
+ if (image.type === "image/svg+xml") {
139
+ // Unfortunately, createImageBitmap doesn't work with SVG images.
140
+ // (see https://bugzilla.mozilla.org/1841972).
141
+ const mustRemoveAspectRatioPromise = _a._isSVGFittingCanvas;
142
+ const fileReader = new FileReader();
143
+ const imageElement = new Image();
144
+ const imagePromise = new Promise((resolve, reject) => {
145
+ imageElement.onload = () => {
146
+ data.bitmap = imageElement;
147
+ data.isSvg = true;
148
+ // @ts-expect-error(TS:2794)
149
+ resolve();
150
+ };
151
+ fileReader.onload = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
152
+ const url = (data.svgUrl = fileReader.result);
153
+ // We need to set the preserveAspectRatio to none in order to let
154
+ // the image fits the canvas when resizing.
155
+ // @ts-expect-error(TS:2332)
156
+ imageElement.src = (yield mustRemoveAspectRatioPromise)
157
+ ? `${url}#svgView(preserveAspectRatio(none))`
158
+ : url;
159
+ });
160
+ imageElement.onerror = fileReader.onerror = reject;
161
+ });
162
+ fileReader.readAsDataURL(image);
163
+ yield imagePromise;
164
+ }
165
+ else {
166
+ data.bitmap = yield createImageBitmap(image);
167
+ }
168
+ data.refCounter = 1;
169
+ }
170
+ catch (e) {
171
+ console.error(e);
172
+ data = null;
173
+ }
174
+ tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").set(key, data);
175
+ if (data) {
176
+ tslib_1.__classPrivateFieldGet(this, _ImageManager_cache, "f").set(data.id, data);
177
+ }
178
+ return data;
179
+ });
180
+ };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * This class aims to provide some methods:
3
+ * - to reorder elements in the DOM with respect to the visual order;
4
+ * - to create a link, using aria-owns, between spans in the textLayer and
5
+ * annotations in the annotationLayer. The goal is to help to know
6
+ * where the annotations are in the text flow.
7
+ */
8
+ declare class TextAccessibilityManager {
9
+ #private;
10
+ setTextMapping(textDivs: any): void;
11
+ /**
12
+ * Function called when the text layer has finished rendering.
13
+ */
14
+ enable(): void;
15
+ disable(): void;
16
+ /**
17
+ * Remove an aria-owns id from a node in the text layer.
18
+ * @param {HTMLElement} element
19
+ */
20
+ removePointerInTextLayer(element: any): void;
21
+ /**
22
+ * Find the text node which is the nearest and add an aria-owns attribute
23
+ * in order to correctly position this editor in the text flow.
24
+ * @param {HTMLElement} element
25
+ * @param {boolean} isRemovable
26
+ * @returns {string|null} The id in the struct tree if any.
27
+ */
28
+ addPointerInTextLayer(element: any, isRemovable: any): any;
29
+ /**
30
+ * Move a div in the DOM in order to respect the visual order.
31
+ * @param {HTMLDivElement} element
32
+ * @returns {string|null} The id in the struct tree if any.
33
+ */
34
+ moveElementInDOM(container: any, element: any, contentElement: any, isRemovable: any): any;
35
+ }
36
+ export { TextAccessibilityManager };
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ /* Copyright 2022 Mozilla Foundation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var _TextAccessibilityManager_instances, _a, _TextAccessibilityManager_enabled, _TextAccessibilityManager_textChildren, _TextAccessibilityManager_textNodes, _TextAccessibilityManager_waitingElements, _TextAccessibilityManager_compareElementPositions, _TextAccessibilityManager_addIdToAriaOwns;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.TextAccessibilityManager = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const ui_utils_1 = require("../shared/ui_utils");
21
+ /**
22
+ * This class aims to provide some methods:
23
+ * - to reorder elements in the DOM with respect to the visual order;
24
+ * - to create a link, using aria-owns, between spans in the textLayer and
25
+ * annotations in the annotationLayer. The goal is to help to know
26
+ * where the annotations are in the text flow.
27
+ */
28
+ class TextAccessibilityManager {
29
+ constructor() {
30
+ _TextAccessibilityManager_instances.add(this);
31
+ _TextAccessibilityManager_enabled.set(this, false);
32
+ _TextAccessibilityManager_textChildren.set(this, null);
33
+ _TextAccessibilityManager_textNodes.set(this, new Map());
34
+ _TextAccessibilityManager_waitingElements.set(this, new Map());
35
+ }
36
+ setTextMapping(textDivs) {
37
+ tslib_1.__classPrivateFieldSet(this, _TextAccessibilityManager_textChildren, textDivs, "f");
38
+ }
39
+ /**
40
+ * Function called when the text layer has finished rendering.
41
+ */
42
+ enable() {
43
+ if (tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_enabled, "f")) {
44
+ // throw new Error("TextAccessibilityManager is already enabled.");
45
+ }
46
+ if (!tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textChildren, "f")) {
47
+ throw new Error("Text divs and strings have not been set.");
48
+ }
49
+ tslib_1.__classPrivateFieldSet(this, _TextAccessibilityManager_enabled, true, "f");
50
+ tslib_1.__classPrivateFieldSet(this, _TextAccessibilityManager_textChildren, tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textChildren, "f").slice(), "f");
51
+ tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textChildren, "f").sort(tslib_1.__classPrivateFieldGet(_a, _a, "m", _TextAccessibilityManager_compareElementPositions));
52
+ if (tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textNodes, "f").size > 0) {
53
+ // Some links have been made before this manager has been disabled, hence
54
+ // we restore them.
55
+ const textChildren = tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textChildren, "f");
56
+ for (const [id, nodeIndex] of tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textNodes, "f")) {
57
+ const element = document.getElementById(id);
58
+ if (!element) {
59
+ // If the page was *fully* reset the element no longer exists, and it
60
+ // will be re-inserted later (i.e. when the annotationLayer renders).
61
+ tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textNodes, "f").delete(id);
62
+ continue;
63
+ }
64
+ tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_instances, "m", _TextAccessibilityManager_addIdToAriaOwns).call(this, id, textChildren[nodeIndex]);
65
+ }
66
+ }
67
+ for (const [element, isRemovable] of tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_waitingElements, "f")) {
68
+ this.addPointerInTextLayer(element, isRemovable);
69
+ }
70
+ tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_waitingElements, "f").clear();
71
+ }
72
+ disable() {
73
+ if (!tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_enabled, "f")) {
74
+ return;
75
+ }
76
+ // Don't clear this.#textNodes which is used to rebuild the aria-owns
77
+ // in case it's re-enabled at some point.
78
+ tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_waitingElements, "f").clear();
79
+ tslib_1.__classPrivateFieldSet(this, _TextAccessibilityManager_textChildren, null, "f");
80
+ tslib_1.__classPrivateFieldSet(this, _TextAccessibilityManager_enabled, false, "f");
81
+ }
82
+ /**
83
+ * Remove an aria-owns id from a node in the text layer.
84
+ * @param {HTMLElement} element
85
+ */
86
+ removePointerInTextLayer(element) {
87
+ if (!tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_enabled, "f")) {
88
+ tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_waitingElements, "f").delete(element);
89
+ return;
90
+ }
91
+ const children = tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textChildren, "f");
92
+ if (!children || children.length === 0) {
93
+ return;
94
+ }
95
+ const { id } = element;
96
+ const nodeIndex = tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textNodes, "f").get(id);
97
+ if (nodeIndex === undefined) {
98
+ return;
99
+ }
100
+ const node = children[nodeIndex];
101
+ tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textNodes, "f").delete(id);
102
+ let owns = node.getAttribute("aria-owns");
103
+ if (owns === null || owns === void 0 ? void 0 : owns.includes(id)) {
104
+ owns = owns
105
+ .split(" ")
106
+ .filter(x => x !== id)
107
+ .join(" ");
108
+ if (owns) {
109
+ node.setAttribute("aria-owns", owns);
110
+ }
111
+ else {
112
+ node.removeAttribute("aria-owns");
113
+ node.setAttribute("role", "presentation");
114
+ }
115
+ }
116
+ }
117
+ /**
118
+ * Find the text node which is the nearest and add an aria-owns attribute
119
+ * in order to correctly position this editor in the text flow.
120
+ * @param {HTMLElement} element
121
+ * @param {boolean} isRemovable
122
+ * @returns {string|null} The id in the struct tree if any.
123
+ */
124
+ addPointerInTextLayer(element, isRemovable) {
125
+ // todo: mocked highlight editor is null here
126
+ if (!element) {
127
+ console.warn("no element");
128
+ return;
129
+ }
130
+ const { id } = element;
131
+ if (!id) {
132
+ return null;
133
+ }
134
+ if (!tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_enabled, "f")) {
135
+ // The text layer needs to be there, so we postpone the association.
136
+ tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_waitingElements, "f").set(element, isRemovable);
137
+ return null;
138
+ }
139
+ if (isRemovable) {
140
+ this.removePointerInTextLayer(element);
141
+ }
142
+ const children = tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textChildren, "f");
143
+ if (!children || children.length === 0) {
144
+ return null;
145
+ }
146
+ const index = (0, ui_utils_1.binarySearchFirstItem)(children, node => tslib_1.__classPrivateFieldGet(_a, _a, "m", _TextAccessibilityManager_compareElementPositions).call(_a, element, node) < 0);
147
+ const nodeIndex = Math.max(0, index - 1);
148
+ const child = children[nodeIndex];
149
+ tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_instances, "m", _TextAccessibilityManager_addIdToAriaOwns).call(this, id, child);
150
+ tslib_1.__classPrivateFieldGet(this, _TextAccessibilityManager_textNodes, "f").set(id, nodeIndex);
151
+ const parent = child.parentNode;
152
+ // return parent?.classList.contains("markedContent") ? parent.id : null;
153
+ return (parent === null || parent === void 0 ? void 0 : parent.classList.contains("markedContent")) ||
154
+ (parent === null || parent === void 0 ? void 0 : parent.classList.contains("k-marked-content")) ? parent.id : null;
155
+ }
156
+ /**
157
+ * Move a div in the DOM in order to respect the visual order.
158
+ * @param {HTMLDivElement} element
159
+ * @returns {string|null} The id in the struct tree if any.
160
+ */
161
+ moveElementInDOM(container, element, contentElement, isRemovable) {
162
+ const id = this.addPointerInTextLayer(contentElement, isRemovable);
163
+ if (!container.hasChildNodes()) {
164
+ container.append(element);
165
+ return id;
166
+ }
167
+ // todo: use children to skip text nodes
168
+ // const children = Array.from(container.childNodes).filter(
169
+ const children = Array.from(container.children).filter(node => node !== element);
170
+ if (children.length === 0) {
171
+ return id;
172
+ }
173
+ const elementToCompare = contentElement || element;
174
+ const index = (0, ui_utils_1.binarySearchFirstItem)(children, node => tslib_1.__classPrivateFieldGet(_a, _a, "m", _TextAccessibilityManager_compareElementPositions).call(_a, elementToCompare, node) < 0);
175
+ if (index === 0) {
176
+ children[0].before(element);
177
+ }
178
+ else {
179
+ children[index - 1].after(element);
180
+ }
181
+ return id;
182
+ }
183
+ }
184
+ exports.TextAccessibilityManager = TextAccessibilityManager;
185
+ _a = TextAccessibilityManager, _TextAccessibilityManager_enabled = new WeakMap(), _TextAccessibilityManager_textChildren = new WeakMap(), _TextAccessibilityManager_textNodes = new WeakMap(), _TextAccessibilityManager_waitingElements = new WeakMap(), _TextAccessibilityManager_instances = new WeakSet(), _TextAccessibilityManager_compareElementPositions = function _TextAccessibilityManager_compareElementPositions(e1, e2) {
186
+ const rect1 = e1.getBoundingClientRect();
187
+ const rect2 = e2.getBoundingClientRect();
188
+ if (rect1.width === 0 && rect1.height === 0) {
189
+ return +1;
190
+ }
191
+ if (rect2.width === 0 && rect2.height === 0) {
192
+ return -1;
193
+ }
194
+ const top1 = rect1.y;
195
+ const bot1 = rect1.y + rect1.height;
196
+ const mid1 = rect1.y + rect1.height / 2;
197
+ const top2 = rect2.y;
198
+ const bot2 = rect2.y + rect2.height;
199
+ const mid2 = rect2.y + rect2.height / 2;
200
+ if (mid1 <= top2 && mid2 >= bot1) {
201
+ return -1;
202
+ }
203
+ if (mid2 <= top1 && mid1 >= bot2) {
204
+ return +1;
205
+ }
206
+ const centerX1 = rect1.x + rect1.width / 2;
207
+ const centerX2 = rect2.x + rect2.width / 2;
208
+ return centerX1 - centerX2;
209
+ }, _TextAccessibilityManager_addIdToAriaOwns = function _TextAccessibilityManager_addIdToAriaOwns(id, node) {
210
+ const owns = node.getAttribute("aria-owns");
211
+ if (!(owns === null || owns === void 0 ? void 0 : owns.includes(id))) {
212
+ node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
213
+ }
214
+ node.removeAttribute("role");
215
+ };
@@ -0,0 +1 @@
1
+ export declare function bindEvents(obj: any, element: any, names: any): void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /* Copyright 2022 Mozilla Foundation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.bindEvents = void 0;
18
+ function bindEvents(obj, element, names) {
19
+ for (const name of names) {
20
+ element.addEventListener(name, obj[name].bind(obj));
21
+ }
22
+ }
23
+ exports.bindEvents = bindEvents;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Event handler to suppress context menu.
3
+ */
4
+ export declare function noContextMenu(e: any): void;
5
+ export declare function getRGB(color: any): any;
6
+ export declare function getColorValues(colors: any): void;