@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,823 @@
1
+ /* Copyright 2012 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
+ // const DEFAULT_SCALE_VALUE = "auto";
16
+ const DEFAULT_SCALE = 1.0;
17
+ // const DEFAULT_SCALE_DELTA = 1.1;
18
+ // const MIN_SCALE = 0.1;
19
+ // const MAX_SCALE = 10.0;
20
+ // const UNKNOWN_SCALE = 0;
21
+ // const MAX_AUTO_SCALE = 1.25;
22
+ // const SCROLLBAR_PADDING = 40;
23
+ // const VERTICAL_PADDING = 5;
24
+ const RenderingStates = {
25
+ INITIAL: 0,
26
+ RUNNING: 1,
27
+ PAUSED: 2,
28
+ FINISHED: 3,
29
+ };
30
+ const PresentationModeState = {
31
+ UNKNOWN: 0,
32
+ NORMAL: 1,
33
+ CHANGING: 2,
34
+ FULLSCREEN: 3,
35
+ };
36
+ // const SidebarView = {
37
+ // UNKNOWN: -1,
38
+ // NONE: 0,
39
+ // THUMBS: 1, // Default value.
40
+ // OUTLINE: 2,
41
+ // ATTACHMENTS: 3,
42
+ // LAYERS: 4,
43
+ // };
44
+ const TextLayerMode = {
45
+ DISABLE: 0,
46
+ ENABLE: 1,
47
+ ENABLE_PERMISSIONS: 2,
48
+ };
49
+ const ScrollMode = {
50
+ UNKNOWN: -1,
51
+ VERTICAL: 0, // Default value.
52
+ HORIZONTAL: 1,
53
+ WRAPPED: 2,
54
+ PAGE: 3,
55
+ };
56
+ // const SpreadMode = {
57
+ // UNKNOWN: -1,
58
+ // NONE: 0, // Default value.
59
+ // ODD: 1,
60
+ // EVEN: 2,
61
+ // };
62
+ // const CursorTool = {
63
+ // SELECT: 0, // The default value.
64
+ // HAND: 1,
65
+ // ZOOM: 2,
66
+ // };
67
+ // // Used by `PDFViewerApplication`, and by the API unit-tests.
68
+ // const AutoPrintRegExp = /\bprint\s*\(/;
69
+ // /**
70
+ // * Scale factors for the canvas, necessary with HiDPI displays.
71
+ // */
72
+ // class OutputScale {
73
+ // constructor() {
74
+ // const pixelRatio = window.devicePixelRatio || 1;
75
+ // /**
76
+ // * @type {number} Horizontal scale.
77
+ // */
78
+ // this.sx = pixelRatio;
79
+ // /**
80
+ // * @type {number} Vertical scale.
81
+ // */
82
+ // this.sy = pixelRatio;
83
+ // }
84
+ // /**
85
+ // * @type {boolean} Returns `true` when scaling is required, `false` otherwise.
86
+ // */
87
+ // get scaled() {
88
+ // return this.sx !== 1 || this.sy !== 1;
89
+ // }
90
+ // }
91
+ /**
92
+ * Scrolls specified element into view of its parent.
93
+ * @param {HTMLElement} element - The element to be visible.
94
+ * @param {Object} [spot] - An object with optional top and left properties,
95
+ * specifying the offset from the top left edge.
96
+ * @param {number} [spot.left]
97
+ * @param {number} [spot.top]
98
+ * @param {boolean} [scrollMatches] - When scrolling search results into view,
99
+ * ignore elements that either: Contains marked content identifiers,
100
+ * or have the CSS-rule `overflow: hidden;` set. The default value is `false`.
101
+ */
102
+ function scrollIntoView(element, spot, scrollMatches = false) {
103
+ // Assuming offsetParent is available (it's not available when viewer is in
104
+ // hidden iframe or object). We have to scroll: if the offsetParent is not set
105
+ // producing the error. See also animationStarted.
106
+ let parent = element.offsetParent;
107
+ if (!parent) {
108
+ console.error("offsetParent is not set -- cannot scroll");
109
+ return;
110
+ }
111
+ let offsetY = element.offsetTop + element.clientTop;
112
+ let offsetX = element.offsetLeft + element.clientLeft;
113
+ while ((parent.clientHeight === parent.scrollHeight &&
114
+ parent.clientWidth === parent.scrollWidth) ||
115
+ (scrollMatches &&
116
+ (parent.classList.contains("markedContent") || parent.classList.contains("k-marked-content") ||
117
+ getComputedStyle(parent).overflow === "hidden"))) {
118
+ offsetY += parent.offsetTop;
119
+ offsetX += parent.offsetLeft;
120
+ parent = parent.offsetParent;
121
+ if (!parent) {
122
+ return; // no need to scroll
123
+ }
124
+ }
125
+ if (spot) {
126
+ if (spot.top !== undefined) {
127
+ offsetY += spot.top;
128
+ }
129
+ if (spot.left !== undefined) {
130
+ offsetX += spot.left;
131
+ parent.scrollLeft = offsetX;
132
+ }
133
+ }
134
+ parent.scrollTop = offsetY;
135
+ }
136
+ // /**
137
+ // * Helper function to start monitoring the scroll event and converting them into
138
+ // * PDF.js friendly one: with scroll debounce and scroll direction.
139
+ // */
140
+ // function watchScroll(viewAreaElement, callback, abortSignal = undefined) {
141
+ // const debounceScroll = function (evt) {
142
+ // if (rAF) {
143
+ // return;
144
+ // }
145
+ // // schedule an invocation of scroll for next animation frame.
146
+ // rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
147
+ // rAF = null;
148
+ // const currentX = viewAreaElement.scrollLeft;
149
+ // const lastX = state.lastX;
150
+ // if (currentX !== lastX) {
151
+ // state.right = currentX > lastX;
152
+ // }
153
+ // state.lastX = currentX;
154
+ // const currentY = viewAreaElement.scrollTop;
155
+ // const lastY = state.lastY;
156
+ // if (currentY !== lastY) {
157
+ // state.down = currentY > lastY;
158
+ // }
159
+ // state.lastY = currentY;
160
+ // callback(state);
161
+ // });
162
+ // };
163
+ // const state = {
164
+ // right: true,
165
+ // down: true,
166
+ // lastX: viewAreaElement.scrollLeft,
167
+ // lastY: viewAreaElement.scrollTop,
168
+ // _eventHandler: debounceScroll,
169
+ // };
170
+ // let rAF = null;
171
+ // viewAreaElement.addEventListener("scroll", debounceScroll, {
172
+ // useCapture: true,
173
+ // signal: abortSignal,
174
+ // });
175
+ // abortSignal?.addEventListener(
176
+ // "abort",
177
+ // () => window.cancelAnimationFrame(rAF),
178
+ // { once: true }
179
+ // );
180
+ // return state;
181
+ // }
182
+ /**
183
+ * Helper function to parse query string (e.g. ?param1=value&param2=...).
184
+ * @param {string} query
185
+ * @returns {Map}
186
+ */
187
+ function parseQueryString(query) {
188
+ const params = new Map();
189
+ const urlSearchParams = new URLSearchParams(query);
190
+ for (const [key, value] of urlSearchParams) {
191
+ // for (const [key, value] of new URLSearchParams(query)) {
192
+ params.set(key.toLowerCase(), value);
193
+ }
194
+ return params;
195
+ }
196
+ // const InvisibleCharsRegExp = /[\x00-\x1F]/g;
197
+ // /**
198
+ // * @param {string} str
199
+ // * @param {boolean} [replaceInvisible]
200
+ // */
201
+ // function removeNullCharacters(str, replaceInvisible = false) {
202
+ // if (!InvisibleCharsRegExp.test(str)) {
203
+ // return str;
204
+ // }
205
+ // if (replaceInvisible) {
206
+ // return str.replaceAll(InvisibleCharsRegExp, m => (m === "\x00" ? "" : " "));
207
+ // }
208
+ // return str.replaceAll("\x00", "");
209
+ // }
210
+ /**
211
+ * Use binary search to find the index of the first item in a given array which
212
+ * passes a given condition. The items are expected to be sorted in the sense
213
+ * that if the condition is true for one item in the array, then it is also true
214
+ * for all following items.
215
+ *
216
+ * @returns {number} Index of the first array element to pass the test,
217
+ * or |items.length| if no such element exists.
218
+ */
219
+ function binarySearchFirstItem(items, condition, start = 0) {
220
+ let minIndex = start;
221
+ let maxIndex = items.length - 1;
222
+ if (maxIndex < 0 || !condition(items[maxIndex])) {
223
+ return items.length;
224
+ }
225
+ if (condition(items[minIndex])) {
226
+ return minIndex;
227
+ }
228
+ while (minIndex < maxIndex) {
229
+ const currentIndex = (minIndex + maxIndex) >> 1;
230
+ const currentItem = items[currentIndex];
231
+ if (condition(currentItem)) {
232
+ maxIndex = currentIndex;
233
+ }
234
+ else {
235
+ minIndex = currentIndex + 1;
236
+ }
237
+ }
238
+ return minIndex; /* === maxIndex */
239
+ }
240
+ // /**
241
+ // * Approximates float number as a fraction using Farey sequence (max order
242
+ // * of 8).
243
+ // * @param {number} x - Positive float number.
244
+ // * @returns {Array} Estimated fraction: the first array item is a numerator,
245
+ // * the second one is a denominator.
246
+ // * They are both natural numbers.
247
+ // */
248
+ // function approximateFraction(x) {
249
+ // // Fast paths for int numbers or their inversions.
250
+ // if (Math.floor(x) === x) {
251
+ // return [x, 1];
252
+ // }
253
+ // const xinv = 1 / x;
254
+ // const limit = 8;
255
+ // if (xinv > limit) {
256
+ // return [1, limit];
257
+ // } else if (Math.floor(xinv) === xinv) {
258
+ // return [1, xinv];
259
+ // }
260
+ // const x_ = x > 1 ? xinv : x;
261
+ // // a/b and c/d are neighbours in Farey sequence.
262
+ // let a = 0,
263
+ // b = 1,
264
+ // c = 1,
265
+ // d = 1;
266
+ // // Limiting search to order 8.
267
+ // while (true) {
268
+ // // Generating next term in sequence (order of q).
269
+ // const p = a + c,
270
+ // q = b + d;
271
+ // if (q > limit) {
272
+ // break;
273
+ // }
274
+ // if (x_ <= p / q) {
275
+ // c = p;
276
+ // d = q;
277
+ // } else {
278
+ // a = p;
279
+ // b = q;
280
+ // }
281
+ // }
282
+ // let result;
283
+ // // Select closest of the neighbours to x.
284
+ // if (x_ - a / b < c / d - x_) {
285
+ // result = x_ === x ? [a, b] : [b, a];
286
+ // } else {
287
+ // result = x_ === x ? [c, d] : [d, c];
288
+ // }
289
+ // return result;
290
+ // }
291
+ // /**
292
+ // * @param {number} x - A positive number to round to a multiple of `div`.
293
+ // * @param {number} div - A natural number.
294
+ // */
295
+ // function floorToDivide(x, div) {
296
+ // return x - (x % div);
297
+ // }
298
+ // /**
299
+ // * @typedef {Object} GetPageSizeInchesParameters
300
+ // * @property {number[]} view
301
+ // * @property {number} userUnit
302
+ // * @property {number} rotate
303
+ // */
304
+ // /**
305
+ // * @typedef {Object} PageSize
306
+ // * @property {number} width - In inches.
307
+ // * @property {number} height - In inches.
308
+ // */
309
+ // /**
310
+ // * Gets the size of the specified page, converted from PDF units to inches.
311
+ // * @param {GetPageSizeInchesParameters} params
312
+ // * @returns {PageSize}
313
+ // */
314
+ // function getPageSizeInches({ view, userUnit, rotate }) {
315
+ // const [x1, y1, x2, y2] = view;
316
+ // // We need to take the page rotation into account as well.
317
+ // const changeOrientation = rotate % 180 !== 0;
318
+ // const width = ((x2 - x1) / 72) * userUnit;
319
+ // const height = ((y2 - y1) / 72) * userUnit;
320
+ // return {
321
+ // width: changeOrientation ? height : width,
322
+ // height: changeOrientation ? width : height,
323
+ // };
324
+ // }
325
+ // /**
326
+ // * Helper function for getVisibleElements.
327
+ // *
328
+ // * @param {number} index - initial guess at the first visible element
329
+ // * @param {Array} views - array of pages, into which `index` is an index
330
+ // * @param {number} top - the top of the scroll pane
331
+ // * @returns {number} less than or equal to `index` that is definitely at or
332
+ // * before the first visible element in `views`, but not by too much. (Usually,
333
+ // * this will be the first element in the first partially visible row in
334
+ // * `views`, although sometimes it goes back one row further.)
335
+ // */
336
+ // function backtrackBeforeAllVisibleElements(index, views, top) {
337
+ // // binarySearchFirstItem's assumption is that the input is ordered, with only
338
+ // // one index where the conditions flips from false to true: [false ...,
339
+ // // true...]. With vertical scrolling and spreads, it is possible to have
340
+ // // [false ..., true, false, true ...]. With wrapped scrolling we can have a
341
+ // // similar sequence, with many more mixed true and false in the middle.
342
+ // //
343
+ // // So there is no guarantee that the binary search yields the index of the
344
+ // // first visible element. It could have been any of the other visible elements
345
+ // // that were preceded by a hidden element.
346
+ // // Of course, if either this element or the previous (hidden) element is also
347
+ // // the first element, there's nothing to worry about.
348
+ // if (index < 2) {
349
+ // return index;
350
+ // }
351
+ // // That aside, the possible cases are represented below.
352
+ // //
353
+ // // **** = fully hidden
354
+ // // A*B* = mix of partially visible and/or hidden pages
355
+ // // CDEF = fully visible
356
+ // //
357
+ // // (1) Binary search could have returned A, in which case we can stop.
358
+ // // (2) Binary search could also have returned B, in which case we need to
359
+ // // check the whole row.
360
+ // // (3) Binary search could also have returned C, in which case we need to
361
+ // // check the whole previous row.
362
+ // //
363
+ // // There's one other possibility:
364
+ // //
365
+ // // **** = fully hidden
366
+ // // ABCD = mix of fully and/or partially visible pages
367
+ // //
368
+ // // (4) Binary search could only have returned A.
369
+ // // Initially assume that we need to find the beginning of the current row
370
+ // // (case 1, 2, or 4), which means finding a page that is above the current
371
+ // // page's top. If the found page is partially visible, we're definitely not in
372
+ // // case 3, and this assumption is correct.
373
+ // let elt = views[index].div;
374
+ // let pageTop = elt.offsetTop + elt.clientTop;
375
+ // if (pageTop >= top) {
376
+ // // The found page is fully visible, so we're actually either in case 3 or 4,
377
+ // // and unfortunately we can't tell the difference between them without
378
+ // // scanning the entire previous row, so we just conservatively assume that
379
+ // // we do need to backtrack to that row. In both cases, the previous page is
380
+ // // in the previous row, so use its top instead.
381
+ // elt = views[index - 1].div;
382
+ // pageTop = elt.offsetTop + elt.clientTop;
383
+ // }
384
+ // // Now we backtrack to the first page that still has its bottom below
385
+ // // `pageTop`, which is the top of a page in the first visible row (unless
386
+ // // we're in case 4, in which case it's the row before that).
387
+ // // `index` is found by binary search, so the page at `index - 1` is
388
+ // // invisible and we can start looking for potentially visible pages from
389
+ // // `index - 2`. (However, if this loop terminates on its first iteration,
390
+ // // which is the case when pages are stacked vertically, `index` should remain
391
+ // // unchanged, so we use a distinct loop variable.)
392
+ // for (let i = index - 2; i >= 0; --i) {
393
+ // elt = views[i].div;
394
+ // if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
395
+ // // We have reached the previous row, so stop now.
396
+ // // This loop is expected to terminate relatively quickly because the
397
+ // // number of pages per row is expected to be small.
398
+ // break;
399
+ // }
400
+ // index = i;
401
+ // }
402
+ // return index;
403
+ // }
404
+ // /**
405
+ // * @typedef {Object} GetVisibleElementsParameters
406
+ // * @property {HTMLElement} scrollEl - A container that can possibly scroll.
407
+ // * @property {Array} views - Objects with a `div` property that contains an
408
+ // * HTMLElement, which should all be descendants of `scrollEl` satisfying the
409
+ // * relevant layout assumptions.
410
+ // * @property {boolean} sortByVisibility - If `true`, the returned elements are
411
+ // * sorted in descending order of the percent of their padding box that is
412
+ // * visible. The default value is `false`.
413
+ // * @property {boolean} horizontal - If `true`, the elements are assumed to be
414
+ // * laid out horizontally instead of vertically. The default value is `false`.
415
+ // * @property {boolean} rtl - If `true`, the `scrollEl` container is assumed to
416
+ // * be in right-to-left mode. The default value is `false`.
417
+ // */
418
+ // /**
419
+ // * Generic helper to find out what elements are visible within a scroll pane.
420
+ // *
421
+ // * Well, pretty generic. There are some assumptions placed on the elements
422
+ // * referenced by `views`:
423
+ // * - If `horizontal`, no left of any earlier element is to the right of the
424
+ // * left of any later element.
425
+ // * - Otherwise, `views` can be split into contiguous rows where, within a row,
426
+ // * no top of any element is below the bottom of any other element, and
427
+ // * between rows, no bottom of any element in an earlier row is below the
428
+ // * top of any element in a later row.
429
+ // *
430
+ // * (Here, top, left, etc. all refer to the padding edge of the element in
431
+ // * question. For pages, that ends up being equivalent to the bounding box of the
432
+ // * rendering canvas. Earlier and later refer to index in `views`, not page
433
+ // * layout.)
434
+ // *
435
+ // * @param {GetVisibleElementsParameters} params
436
+ // * @returns {Object} `{ first, last, views: [{ id, x, y, view, percent }] }`
437
+ // */
438
+ // function getVisibleElements({
439
+ // scrollEl,
440
+ // views,
441
+ // sortByVisibility = false,
442
+ // horizontal = false,
443
+ // rtl = false,
444
+ // }) {
445
+ // const top = scrollEl.scrollTop,
446
+ // bottom = top + scrollEl.clientHeight;
447
+ // const left = scrollEl.scrollLeft,
448
+ // right = left + scrollEl.clientWidth;
449
+ // // Throughout this "generic" function, comments will assume we're working with
450
+ // // PDF document pages, which is the most important and complex case. In this
451
+ // // case, the visible elements we're actually interested is the page canvas,
452
+ // // which is contained in a wrapper which adds no padding/border/margin, which
453
+ // // is itself contained in `view.div` which adds no padding (but does add a
454
+ // // border). So, as specified in this function's doc comment, this function
455
+ // // does all of its work on the padding edge of the provided views, starting at
456
+ // // offsetLeft/Top (which includes margin) and adding clientLeft/Top (which is
457
+ // // the border). Adding clientWidth/Height gets us the bottom-right corner of
458
+ // // the padding edge.
459
+ // function isElementBottomAfterViewTop(view) {
460
+ // const element = view.div;
461
+ // const elementBottom =
462
+ // element.offsetTop + element.clientTop + element.clientHeight;
463
+ // return elementBottom > top;
464
+ // }
465
+ // function isElementNextAfterViewHorizontally(view) {
466
+ // const element = view.div;
467
+ // const elementLeft = element.offsetLeft + element.clientLeft;
468
+ // const elementRight = elementLeft + element.clientWidth;
469
+ // return rtl ? elementLeft < right : elementRight > left;
470
+ // }
471
+ // const visible = [],
472
+ // ids = new Set(),
473
+ // numViews = views.length;
474
+ // let firstVisibleElementInd = binarySearchFirstItem(
475
+ // views,
476
+ // horizontal
477
+ // ? isElementNextAfterViewHorizontally
478
+ // : isElementBottomAfterViewTop
479
+ // );
480
+ // // Please note the return value of the `binarySearchFirstItem` function when
481
+ // // no valid element is found (hence the `firstVisibleElementInd` check below).
482
+ // if (
483
+ // firstVisibleElementInd > 0 &&
484
+ // firstVisibleElementInd < numViews &&
485
+ // !horizontal
486
+ // ) {
487
+ // // In wrapped scrolling (or vertical scrolling with spreads), with some page
488
+ // // sizes, isElementBottomAfterViewTop doesn't satisfy the binary search
489
+ // // condition: there can be pages with bottoms above the view top between
490
+ // // pages with bottoms below. This function detects and corrects that error;
491
+ // // see it for more comments.
492
+ // firstVisibleElementInd = backtrackBeforeAllVisibleElements(
493
+ // firstVisibleElementInd,
494
+ // views,
495
+ // top
496
+ // );
497
+ // }
498
+ // // lastEdge acts as a cutoff for us to stop looping, because we know all
499
+ // // subsequent pages will be hidden.
500
+ // //
501
+ // // When using wrapped scrolling or vertical scrolling with spreads, we can't
502
+ // // simply stop the first time we reach a page below the bottom of the view;
503
+ // // the tops of subsequent pages on the same row could still be visible. In
504
+ // // horizontal scrolling, we don't have that issue, so we can stop as soon as
505
+ // // we pass `right`, without needing the code below that handles the -1 case.
506
+ // let lastEdge = horizontal ? right : -1;
507
+ // for (let i = firstVisibleElementInd; i < numViews; i++) {
508
+ // const view = views[i],
509
+ // element = view.div;
510
+ // const currentWidth = element.offsetLeft + element.clientLeft;
511
+ // const currentHeight = element.offsetTop + element.clientTop;
512
+ // const viewWidth = element.clientWidth,
513
+ // viewHeight = element.clientHeight;
514
+ // const viewRight = currentWidth + viewWidth;
515
+ // const viewBottom = currentHeight + viewHeight;
516
+ // if (lastEdge === -1) {
517
+ // // As commented above, this is only needed in non-horizontal cases.
518
+ // // Setting lastEdge to the bottom of the first page that is partially
519
+ // // visible ensures that the next page fully below lastEdge is on the
520
+ // // next row, which has to be fully hidden along with all subsequent rows.
521
+ // if (viewBottom >= bottom) {
522
+ // lastEdge = viewBottom;
523
+ // }
524
+ // } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
525
+ // break;
526
+ // }
527
+ // if (
528
+ // viewBottom <= top ||
529
+ // currentHeight >= bottom ||
530
+ // viewRight <= left ||
531
+ // currentWidth >= right
532
+ // ) {
533
+ // continue;
534
+ // }
535
+ // const hiddenHeight =
536
+ // Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
537
+ // const hiddenWidth =
538
+ // Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
539
+ // const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
540
+ // fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
541
+ // const percent = (fractionHeight * fractionWidth * 100) | 0;
542
+ // visible.push({
543
+ // id: view.id,
544
+ // x: currentWidth,
545
+ // y: currentHeight,
546
+ // view,
547
+ // percent,
548
+ // widthPercent: (fractionWidth * 100) | 0,
549
+ // });
550
+ // ids.add(view.id);
551
+ // }
552
+ // const first = visible[0],
553
+ // last = visible.at(-1);
554
+ // if (sortByVisibility) {
555
+ // visible.sort(function (a, b) {
556
+ // const pc = a.percent - b.percent;
557
+ // if (Math.abs(pc) > 0.001) {
558
+ // return -pc;
559
+ // }
560
+ // return a.id - b.id; // ensure stability
561
+ // });
562
+ // }
563
+ // return { first, last, views: visible, ids };
564
+ // }
565
+ // function normalizeWheelEventDirection(evt) {
566
+ // let delta = Math.hypot(evt.deltaX, evt.deltaY);
567
+ // const angle = Math.atan2(evt.deltaY, evt.deltaX);
568
+ // if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
569
+ // // All that is left-up oriented has to change the sign.
570
+ // delta = -delta;
571
+ // }
572
+ // return delta;
573
+ // }
574
+ // function normalizeWheelEventDelta(evt) {
575
+ // const deltaMode = evt.deltaMode; // Avoid being affected by bug 1392460.
576
+ // let delta = normalizeWheelEventDirection(evt);
577
+ // const MOUSE_PIXELS_PER_LINE = 30;
578
+ // const MOUSE_LINES_PER_PAGE = 30;
579
+ // // Converts delta to per-page units
580
+ // if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
581
+ // delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
582
+ // } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
583
+ // delta /= MOUSE_LINES_PER_PAGE;
584
+ // }
585
+ // return delta;
586
+ // }
587
+ // function isValidRotation(angle) {
588
+ // return Number.isInteger(angle) && angle % 90 === 0;
589
+ // }
590
+ // function isValidScrollMode(mode) {
591
+ // return (
592
+ // Number.isInteger(mode) &&
593
+ // Object.values(ScrollMode).includes(mode) &&
594
+ // mode !== ScrollMode.UNKNOWN
595
+ // );
596
+ // }
597
+ // function isValidSpreadMode(mode) {
598
+ // return (
599
+ // Number.isInteger(mode) &&
600
+ // Object.values(SpreadMode).includes(mode) &&
601
+ // mode !== SpreadMode.UNKNOWN
602
+ // );
603
+ // }
604
+ // function isPortraitOrientation(size) {
605
+ // return size.width <= size.height;
606
+ // }
607
+ // /**
608
+ // * Promise that is resolved when DOM window becomes visible.
609
+ // */
610
+ // const animationStarted = new Promise(function (resolve) {
611
+ // if (
612
+ // typeof PDFJSDev !== "undefined" &&
613
+ // PDFJSDev.test("LIB") &&
614
+ // typeof window === "undefined"
615
+ // ) {
616
+ // // Prevent "ReferenceError: window is not defined" errors when running the
617
+ // // unit-tests in Node.js environments.
618
+ // setTimeout(resolve, 20);
619
+ // return;
620
+ // }
621
+ // window.requestAnimationFrame(resolve);
622
+ // });
623
+ // const docStyle =
624
+ // typeof PDFJSDev !== "undefined" &&
625
+ // PDFJSDev.test("LIB") &&
626
+ // typeof document === "undefined"
627
+ // ? null
628
+ // : document.documentElement.style;
629
+ // function clamp(v, min, max) {
630
+ // return Math.min(Math.max(v, min), max);
631
+ // }
632
+ // class ProgressBar {
633
+ // #classList = null;
634
+ // #disableAutoFetchTimeout = null;
635
+ // #percent = 0;
636
+ // #style = null;
637
+ // #visible = true;
638
+ // constructor(bar) {
639
+ // this.#classList = bar.classList;
640
+ // this.#style = bar.style;
641
+ // }
642
+ // get percent() {
643
+ // return this.#percent;
644
+ // }
645
+ // set percent(val) {
646
+ // this.#percent = clamp(val, 0, 100);
647
+ // if (isNaN(val)) {
648
+ // this.#classList.add("indeterminate");
649
+ // return;
650
+ // }
651
+ // this.#classList.remove("indeterminate");
652
+ // this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
653
+ // }
654
+ // setWidth(viewer) {
655
+ // if (!viewer) {
656
+ // return;
657
+ // }
658
+ // const container = viewer.parentNode;
659
+ // const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
660
+ // if (scrollbarWidth > 0) {
661
+ // this.#style.setProperty(
662
+ // "--progressBar-end-offset",
663
+ // `${scrollbarWidth}px`
664
+ // );
665
+ // }
666
+ // }
667
+ // setDisableAutoFetch(delay = /* ms = */ 5000) {
668
+ // if (this.#percent === 100 || isNaN(this.#percent)) {
669
+ // return;
670
+ // }
671
+ // if (this.#disableAutoFetchTimeout) {
672
+ // clearTimeout(this.#disableAutoFetchTimeout);
673
+ // }
674
+ // this.show();
675
+ // this.#disableAutoFetchTimeout = setTimeout(() => {
676
+ // this.#disableAutoFetchTimeout = null;
677
+ // this.hide();
678
+ // }, delay);
679
+ // }
680
+ // hide() {
681
+ // if (!this.#visible) {
682
+ // return;
683
+ // }
684
+ // this.#visible = false;
685
+ // this.#classList.add("hidden");
686
+ // this.#classList.add("k-hidden");
687
+ // }
688
+ // show() {
689
+ // if (this.#visible) {
690
+ // return;
691
+ // }
692
+ // this.#visible = true;
693
+ // this.#classList.remove("hidden");
694
+ // this.#classList.remove("k-hidden");
695
+ // }
696
+ // }
697
+ // /**
698
+ // * Get the active or focused element in current DOM.
699
+ // *
700
+ // * Recursively search for the truly active or focused element in case there are
701
+ // * shadow DOMs.
702
+ // *
703
+ // * @returns {Element} the truly active or focused element.
704
+ // */
705
+ // function getActiveOrFocusedElement() {
706
+ // let curRoot = document;
707
+ // let curActiveOrFocused =
708
+ // curRoot.activeElement || curRoot.querySelector(":focus");
709
+ // while (curActiveOrFocused?.shadowRoot) {
710
+ // curRoot = curActiveOrFocused.shadowRoot;
711
+ // curActiveOrFocused =
712
+ // curRoot.activeElement || curRoot.querySelector(":focus");
713
+ // }
714
+ // return curActiveOrFocused;
715
+ // }
716
+ // /**
717
+ // * Converts API PageLayout values to the format used by `BaseViewer`.
718
+ // * @param {string} layout - The API PageLayout value.
719
+ // * @returns {Object}
720
+ // */
721
+ // function apiPageLayoutToViewerModes(layout) {
722
+ // let scrollMode = ScrollMode.VERTICAL,
723
+ // spreadMode = SpreadMode.NONE;
724
+ // switch (layout) {
725
+ // case "SinglePage":
726
+ // scrollMode = ScrollMode.PAGE;
727
+ // break;
728
+ // case "OneColumn":
729
+ // break;
730
+ // case "TwoPageLeft":
731
+ // scrollMode = ScrollMode.PAGE;
732
+ // /* falls through */
733
+ // case "TwoColumnLeft":
734
+ // spreadMode = SpreadMode.ODD;
735
+ // break;
736
+ // case "TwoPageRight":
737
+ // scrollMode = ScrollMode.PAGE;
738
+ // /* falls through */
739
+ // case "TwoColumnRight":
740
+ // spreadMode = SpreadMode.EVEN;
741
+ // break;
742
+ // }
743
+ // return { scrollMode, spreadMode };
744
+ // }
745
+ // /**
746
+ // * Converts API PageMode values to the format used by `PDFSidebar`.
747
+ // * NOTE: There's also a "FullScreen" parameter which is not possible to support,
748
+ // * since the Fullscreen API used in browsers requires that entering
749
+ // * fullscreen mode only occurs as a result of a user-initiated event.
750
+ // * @param {string} mode - The API PageMode value.
751
+ // * @returns {number} A value from {SidebarView}.
752
+ // */
753
+ // function apiPageModeToSidebarView(mode) {
754
+ // switch (mode) {
755
+ // case "UseNone":
756
+ // return SidebarView.NONE;
757
+ // case "UseThumbs":
758
+ // return SidebarView.THUMBS;
759
+ // case "UseOutlines":
760
+ // return SidebarView.OUTLINE;
761
+ // case "UseAttachments":
762
+ // return SidebarView.ATTACHMENTS;
763
+ // case "UseOC":
764
+ // return SidebarView.LAYERS;
765
+ // }
766
+ // return SidebarView.NONE; // Default value.
767
+ // }
768
+ // function toggleCheckedBtn(button, toggle, view = null) {
769
+ // button.classList.toggle("toggled", toggle);
770
+ // button.classList.toggle("k-toggled", toggle);
771
+ // button.setAttribute("aria-checked", toggle);
772
+ // view?.classList.toggle("hidden", !toggle);
773
+ // view?.classList.toggle("k-hidden", !toggle);
774
+ // }
775
+ // function toggleExpandedBtn(button, toggle, view = null) {
776
+ // button.classList.toggle("toggled", toggle);
777
+ // button.classList.toggle("k-toggled", toggle);
778
+ // button.setAttribute("aria-expanded", toggle);
779
+ // view?.classList.toggle("hidden", !toggle);
780
+ // view?.classList.toggle("k-hidden", !toggle);
781
+ // }
782
+ export {
783
+ // animationStarted,
784
+ // apiPageLayoutToViewerModes,
785
+ // apiPageModeToSidebarView,
786
+ // approximateFraction,
787
+ // AutoPrintRegExp,
788
+ // backtrackBeforeAllVisibleElements, // only exported for testing
789
+ binarySearchFirstItem,
790
+ // CursorTool,
791
+ DEFAULT_SCALE,
792
+ // DEFAULT_SCALE_DELTA,
793
+ // DEFAULT_SCALE_VALUE,
794
+ // docStyle,
795
+ // floorToDivide,
796
+ // getActiveOrFocusedElement,
797
+ // getPageSizeInches,
798
+ // getVisibleElements,
799
+ // isPortraitOrientation,
800
+ // isValidRotation,
801
+ // isValidScrollMode,
802
+ // isValidSpreadMode,
803
+ // MAX_AUTO_SCALE,
804
+ // MAX_SCALE,
805
+ // MIN_SCALE,
806
+ // normalizeWheelEventDelta,
807
+ // normalizeWheelEventDirection,
808
+ // OutputScale,
809
+ parseQueryString, PresentationModeState,
810
+ // ProgressBar,
811
+ // removeNullCharacters,
812
+ RenderingStates,
813
+ // SCROLLBAR_PADDING,
814
+ scrollIntoView, ScrollMode,
815
+ // SidebarView,
816
+ // SpreadMode,
817
+ TextLayerMode,
818
+ // toggleCheckedBtn,
819
+ // toggleExpandedBtn,
820
+ // UNKNOWN_SCALE,
821
+ // VERTICAL_PADDING,
822
+ // watchScroll,
823
+ };