@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,33 @@
1
+ import { extend, deepExtend, isFunction } from "./core";
2
+ export class Component {
3
+ constructor(element, options) {
4
+ this.options = {
5
+ events: {}
6
+ };
7
+ this.element = element;
8
+ this.options = options;
9
+ }
10
+ destroy() {
11
+ this.element = null;
12
+ }
13
+ extendOptions(options) {
14
+ this.options = deepExtend(this.options, options);
15
+ }
16
+ setOptions(options) {
17
+ this.options = options;
18
+ }
19
+ trigger(eventName, args = {}) {
20
+ const eventData = {
21
+ defaultPrevented: false,
22
+ preventDefault: () => {
23
+ eventData.defaultPrevented = true;
24
+ }
25
+ };
26
+ if (isFunction(this.options.events[eventName])) {
27
+ this.options.events[eventName](extend(eventData, args, {
28
+ sender: this
29
+ }));
30
+ }
31
+ return eventData.defaultPrevented;
32
+ }
33
+ }
@@ -0,0 +1,91 @@
1
+ import { Component } from "./component";
2
+ // @ts-expect-error TS(2556): A spread argument must either have a tuple type or... Remove this comment to see the full error message
3
+ export const extend = (...args) => Object.assign(...args);
4
+ export const isObject = (value) => value && typeof (value) === "object" && !Array.isArray(value);
5
+ export const isHtmlElement = (element) => element instanceof HTMLElement;
6
+ export const isDomElement = (element) => element instanceof Element;
7
+ /* eslint-disable no-undef */
8
+ // @ts-expect-error TS(2304): Cannot find name 'DotNet'.
9
+ export const isDotNetObject = (value) => value && window && window.DotNet && window.DotNet.DotNetObject && value instanceof DotNet.DotNetObject;
10
+ /* eslint-enable no-undef */
11
+ export const deepExtend = (target, ...sources) => {
12
+ if (!sources.length) {
13
+ return target;
14
+ }
15
+ const source = sources.shift();
16
+ if (isObject(target) && isObject(source)) {
17
+ for (const key in source) {
18
+ if (source[key] instanceof Component) {
19
+ target[key] = source[key];
20
+ }
21
+ else if (isHtmlElement(source[key])) {
22
+ target[key] = source[key];
23
+ }
24
+ else if (key === "dotNetInstance" || isDotNetObject(source[key])) {
25
+ // avoid cloning a DotNetObject as it might have circular properties
26
+ // see https://github.com/telerik/blazor/issues/7507
27
+ // the check for the name of our own option - "dotNetInstance"
28
+ // is an additional guard against the Blazor API being different in other .NET versions
29
+ target[key] = source[key];
30
+ }
31
+ else if (source[key] && source[key].buffer && source[key].buffer instanceof ArrayBuffer) {
32
+ target[key] = source[key];
33
+ }
34
+ else if (isObject(source[key]) && Object.getPrototypeOf(source[key]) !== Object.prototype) {
35
+ target[key] = source[key];
36
+ }
37
+ else if (isObject(source[key])) {
38
+ if (!target[key] || !isObject(target[key])) {
39
+ extend(target, { [key]: {} });
40
+ }
41
+ deepExtend(target[key], source[key]);
42
+ }
43
+ else {
44
+ extend(target, { [key]: source[key] });
45
+ }
46
+ }
47
+ }
48
+ return deepExtend(target, ...sources);
49
+ };
50
+ export const isFunction = fn => typeof (fn) === "function";
51
+ export const isString = value => typeof (value) === "string";
52
+ export const toArray = value => Array.from(value);
53
+ export const isDefined = value => typeof (value) !== "undefined";
54
+ export const isNotNull = value => value !== null;
55
+ export const hasValue = value => isDefined(value) && isNotNull(value);
56
+ export const noop = function () { };
57
+ export const convertToHtml = (htmlString, ownerDocument) => {
58
+ const template = (ownerDocument || document).createElement('template');
59
+ template.innerHTML = htmlString.trim();
60
+ const content = template.content;
61
+ if (content.childNodes.length > 1) {
62
+ return content.childNodes;
63
+ }
64
+ return content.firstChild;
65
+ };
66
+ export const toPixel = value => parseFloat(value) + "px";
67
+ export const toClassSelector = (className) => (className === null || className === void 0 ? void 0 : className.startsWith(".")) ? className : `.${className}`;
68
+ export const mousewheelDelta = (e) => {
69
+ let delta = 0;
70
+ if (e.wheelDelta) {
71
+ delta = -e.wheelDelta / 120;
72
+ }
73
+ else if (e.detail) {
74
+ delta = e.detail / 3;
75
+ }
76
+ delta = delta > 0 ? Math.ceil(delta) : Math.floor(delta);
77
+ return delta;
78
+ };
79
+ export const createPromise = () => {
80
+ let resolveFn;
81
+ let rejectFn;
82
+ const promise = new Promise(function (resolve, reject) {
83
+ resolveFn = resolve;
84
+ rejectFn = reject;
85
+ });
86
+ // @ts-expect-error TS(2339): Property 'resolve' does not exist on type 'Promise... Remove this comment to see the full error message
87
+ promise.resolve = resolveFn;
88
+ // @ts-expect-error TS(2339): Property 'reject' does not exist on type 'Promise<... Remove this comment to see the full error message
89
+ promise.reject = rejectFn;
90
+ return promise;
91
+ };
@@ -0,0 +1,11 @@
1
+ export const addClass = (className, element) => {
2
+ element.classList.add(className);
3
+ };
4
+ export const removeClass = (className, element) => {
5
+ element.classList.remove(className);
6
+ };
7
+ export const hasClass = (className, element) => {
8
+ if (element instanceof HTMLElement) {
9
+ return element.classList.contains(className);
10
+ }
11
+ };
@@ -0,0 +1,4 @@
1
+ export * from './component';
2
+ export * from './core';
3
+ export * from './dom';
4
+ export * from './math';
@@ -0,0 +1 @@
1
+ export const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
@@ -0,0 +1,6 @@
1
+ export var PdfViewerInteractionMode;
2
+ (function (PdfViewerInteractionMode) {
3
+ PdfViewerInteractionMode[PdfViewerInteractionMode["TextSelection"] = 0] = "TextSelection";
4
+ PdfViewerInteractionMode[PdfViewerInteractionMode["Pan"] = 1] = "Pan";
5
+ })(PdfViewerInteractionMode || (PdfViewerInteractionMode = {}));
6
+ ;
@@ -0,0 +1,505 @@
1
+ /* Copyright 2015 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 _a, _PDFLinkService_isValidExplicitDest;
16
+ import { __awaiter, __classPrivateFieldGet } from "tslib";
17
+ import { parseQueryString } from "../annotations/shared/ui_utils";
18
+ const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
19
+ const LinkTarget = {
20
+ NONE: 0, // Default value.
21
+ SELF: 1,
22
+ BLANK: 2,
23
+ PARENT: 3,
24
+ TOP: 4,
25
+ };
26
+ /**
27
+ * @typedef {Object} PDFLinkServiceOptions
28
+ * @property {EventBus} eventBus - The application event bus.
29
+ * @property {number} [externalLinkTarget] - Specifies the `target` attribute
30
+ * for external links. Must use one of the values from {LinkTarget}.
31
+ * Defaults to using no target.
32
+ * @property {string} [externalLinkRel] - Specifies the `rel` attribute for
33
+ * external links. Defaults to stripping the referrer.
34
+ * @property {boolean} [ignoreDestinationZoom] - Ignores the zoom argument,
35
+ * thus preserving the current zoom level in the viewer, when navigating
36
+ * to internal destinations. The default value is `false`.
37
+ */
38
+ /**
39
+ * Performs navigation functions inside PDF, such as opening specified page,
40
+ * or destination.
41
+ * @implements {IPDFLinkService}
42
+ */
43
+ class PDFLinkService {
44
+ /**
45
+ * @param {PDFLinkServiceOptions} options
46
+ */
47
+ constructor({ eventBus = null, externalLinkTarget = null, externalLinkRel = null, ignoreDestinationZoom = false, } = {}) {
48
+ // todo: props
49
+ this.eventBus = null;
50
+ this.externalLinkTarget = null;
51
+ this.externalLinkRel = null;
52
+ this._ignoreDestinationZoom = null;
53
+ this.baseUrl = null;
54
+ this.pdfDocument = null;
55
+ this.pdfViewer = null;
56
+ this.pdfHistory = null;
57
+ // todo: props
58
+ this.externalLinkEnabled = true;
59
+ this.eventBus = eventBus;
60
+ this.externalLinkTarget = externalLinkTarget;
61
+ this.externalLinkRel = externalLinkRel;
62
+ this._ignoreDestinationZoom = ignoreDestinationZoom;
63
+ this.baseUrl = null;
64
+ this.pdfDocument = null;
65
+ this.pdfViewer = null;
66
+ this.pdfHistory = null;
67
+ }
68
+ setDocument(pdfDocument, baseUrl = null) {
69
+ this.baseUrl = baseUrl;
70
+ this.pdfDocument = pdfDocument;
71
+ }
72
+ setViewer(pdfViewer) {
73
+ this.pdfViewer = pdfViewer;
74
+ }
75
+ setHistory(pdfHistory) {
76
+ this.pdfHistory = pdfHistory;
77
+ }
78
+ /**
79
+ * @type {number}
80
+ */
81
+ get pagesCount() {
82
+ return this.pdfDocument ? this.pdfDocument.numPages : 0;
83
+ }
84
+ /**
85
+ * @type {number}
86
+ */
87
+ get page() {
88
+ return this.pdfDocument ? this.pdfViewer.currentPageNumber : 1;
89
+ }
90
+ /**
91
+ * @param {number} value
92
+ */
93
+ set page(value) {
94
+ if (this.pdfDocument) {
95
+ this.pdfViewer.currentPageNumber = value;
96
+ }
97
+ }
98
+ /**
99
+ * @type {number}
100
+ */
101
+ get rotation() {
102
+ return this.pdfDocument ? this.pdfViewer.pagesRotation : 0;
103
+ }
104
+ /**
105
+ * @param {number} value
106
+ */
107
+ set rotation(value) {
108
+ if (this.pdfDocument) {
109
+ this.pdfViewer.pagesRotation = value;
110
+ }
111
+ }
112
+ /**
113
+ * @type {boolean}
114
+ */
115
+ get isInPresentationMode() {
116
+ return this.pdfDocument ? this.pdfViewer.isInPresentationMode : false;
117
+ }
118
+ /**
119
+ * This method will, when available, also update the browser history.
120
+ *
121
+ * @param {string|Array} dest - The named, or explicit, PDF destination.
122
+ */
123
+ goToDestination(dest) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ if (!this.pdfDocument) {
126
+ return;
127
+ }
128
+ let namedDest, explicitDest, pageNumber;
129
+ if (typeof dest === "string") {
130
+ namedDest = dest;
131
+ explicitDest = yield this.pdfDocument.getDestination(dest);
132
+ }
133
+ else {
134
+ namedDest = null;
135
+ explicitDest = yield dest;
136
+ }
137
+ if (!Array.isArray(explicitDest)) {
138
+ // console.error(
139
+ // `goToDestination: "${explicitDest}" is not a valid destination array, for dest="${dest}".`
140
+ // );
141
+ return;
142
+ }
143
+ // Dest array looks like that: <page-ref> </XYZ|/FitXXX> <args..>
144
+ const [destRef] = explicitDest;
145
+ if (destRef && typeof destRef === "object") {
146
+ pageNumber = this.pdfDocument.cachedPageNumber(destRef);
147
+ if (!pageNumber) {
148
+ // Fetch the page reference if it's not yet available. This could
149
+ // only occur during loading, before all pages have been resolved.
150
+ try {
151
+ pageNumber = (yield this.pdfDocument.getPageIndex(destRef)) + 1;
152
+ }
153
+ catch (_b) {
154
+ console.error(`goToDestination: "${destRef}" is not a valid page reference, for dest="${dest}".`);
155
+ return;
156
+ }
157
+ }
158
+ }
159
+ else if (Number.isInteger(destRef)) {
160
+ pageNumber = destRef + 1;
161
+ }
162
+ if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
163
+ console.error(`goToDestination: "${pageNumber}" is not a valid page number, for dest="${dest}".`);
164
+ return;
165
+ }
166
+ if (this.pdfHistory) {
167
+ // Update the browser history before scrolling the new destination into
168
+ // view, to be able to accurately capture the current document position.
169
+ this.pdfHistory.pushCurrentPosition();
170
+ this.pdfHistory.push({ namedDest, explicitDest, pageNumber });
171
+ }
172
+ this.pdfViewer.scrollPageIntoView({
173
+ pageNumber,
174
+ destArray: explicitDest,
175
+ ignoreDestinationZoom: this._ignoreDestinationZoom,
176
+ });
177
+ });
178
+ }
179
+ /**
180
+ * This method will, when available, also update the browser history.
181
+ *
182
+ * @param {number|string} val - The page number, or page label.
183
+ */
184
+ goToPage(val) {
185
+ if (!this.pdfDocument) {
186
+ return;
187
+ }
188
+ const pageNumber = (typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val)) ||
189
+ val | 0;
190
+ if (!(Number.isInteger(pageNumber) &&
191
+ pageNumber > 0 &&
192
+ pageNumber <= this.pagesCount)) {
193
+ console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
194
+ return;
195
+ }
196
+ if (this.pdfHistory) {
197
+ // Update the browser history before scrolling the new page into view,
198
+ // to be able to accurately capture the current document position.
199
+ this.pdfHistory.pushCurrentPosition();
200
+ this.pdfHistory.pushPage(pageNumber);
201
+ }
202
+ this.pdfViewer.scrollPageIntoView({ pageNumber });
203
+ }
204
+ /**
205
+ * Adds various attributes (href, title, target, rel) to hyperlinks.
206
+ * @param {HTMLAnchorElement} link
207
+ * @param {string} url
208
+ * @param {boolean} [newWindow]
209
+ */
210
+ addLinkAttributes(link, url, newWindow = false) {
211
+ if (!url || typeof url !== "string") {
212
+ throw new Error('A valid "url" parameter must provided.');
213
+ }
214
+ const target = newWindow ? LinkTarget.BLANK : this.externalLinkTarget, rel = this.externalLinkRel;
215
+ if (this.externalLinkEnabled) {
216
+ link.href = link.title = url;
217
+ }
218
+ else {
219
+ link.href = "";
220
+ link.title = `Disabled: ${url}`;
221
+ link.onclick = () => false;
222
+ }
223
+ let targetStr = ""; // LinkTarget.NONE
224
+ switch (target) {
225
+ case LinkTarget.NONE:
226
+ break;
227
+ case LinkTarget.SELF:
228
+ targetStr = "_self";
229
+ break;
230
+ case LinkTarget.BLANK:
231
+ targetStr = "_blank";
232
+ break;
233
+ case LinkTarget.PARENT:
234
+ targetStr = "_parent";
235
+ break;
236
+ case LinkTarget.TOP:
237
+ targetStr = "_top";
238
+ break;
239
+ default: break;
240
+ }
241
+ link.target = targetStr;
242
+ link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
243
+ }
244
+ /**
245
+ * @param {string|Array} dest - The PDF destination object.
246
+ * @returns {string} The hyperlink to the PDF object.
247
+ */
248
+ getDestinationHash(dest) {
249
+ if (typeof dest === "string") {
250
+ if (dest.length > 0) {
251
+ return this.getAnchorUrl("#" + escape(dest));
252
+ }
253
+ }
254
+ else if (Array.isArray(dest)) {
255
+ const str = JSON.stringify(dest);
256
+ if (str.length > 0) {
257
+ return this.getAnchorUrl("#" + escape(str));
258
+ }
259
+ }
260
+ return this.getAnchorUrl("");
261
+ }
262
+ /**
263
+ * Prefix the full url on anchor links to make sure that links are resolved
264
+ * relative to the current URL instead of the one defined in <base href>.
265
+ * @param {string} anchor - The anchor hash, including the #.
266
+ * @returns {string} The hyperlink to the PDF object.
267
+ */
268
+ getAnchorUrl(anchor) {
269
+ return this.baseUrl ? this.baseUrl + anchor : anchor;
270
+ }
271
+ /**
272
+ * @param {string} hash
273
+ */
274
+ setHash(hash) {
275
+ if (!this.pdfDocument) {
276
+ return;
277
+ }
278
+ let pageNumber, dest;
279
+ if (hash.includes("=")) {
280
+ const params = parseQueryString(hash);
281
+ if (params.has("search")) {
282
+ const query = params.get("search").replaceAll('"', ""), phrase = params.get("phrase") === "true";
283
+ this.eventBus.dispatch("findfromurlhash", {
284
+ source: this,
285
+ query: phrase ? query : query.match(/\S+/g),
286
+ });
287
+ }
288
+ // borrowing syntax from "Parameters for Opening PDF Files"
289
+ if (params.has("page")) {
290
+ pageNumber = params.get("page") | 0 || 1;
291
+ }
292
+ if (params.has("zoom")) {
293
+ // Build the destination array.
294
+ const zoomArgs = params.get("zoom").split(","); // scale,left,top
295
+ const zoomArg = zoomArgs[0];
296
+ const zoomArgNumber = parseFloat(zoomArg);
297
+ if (!zoomArg.includes("Fit")) {
298
+ // If the zoomArg is a number, it has to get divided by 100. If it's
299
+ // a string, it should stay as it is.
300
+ dest = [
301
+ null,
302
+ { name: "XYZ" },
303
+ zoomArgs.length > 1 ? zoomArgs[1] | 0 : null,
304
+ zoomArgs.length > 2 ? zoomArgs[2] | 0 : null,
305
+ zoomArgNumber ? zoomArgNumber / 100 : zoomArg,
306
+ ];
307
+ }
308
+ else if (zoomArg === "Fit" || zoomArg === "FitB") {
309
+ dest = [null, { name: zoomArg }];
310
+ }
311
+ else if (zoomArg === "FitH" ||
312
+ zoomArg === "FitBH" ||
313
+ zoomArg === "FitV" ||
314
+ zoomArg === "FitBV") {
315
+ dest = [
316
+ null,
317
+ { name: zoomArg },
318
+ zoomArgs.length > 1 ? zoomArgs[1] | 0 : null,
319
+ ];
320
+ }
321
+ else if (zoomArg === "FitR") {
322
+ if (zoomArgs.length !== 5) {
323
+ console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
324
+ }
325
+ else {
326
+ dest = [
327
+ null,
328
+ { name: zoomArg },
329
+ zoomArgs[1] | 0,
330
+ zoomArgs[2] | 0,
331
+ zoomArgs[3] | 0,
332
+ zoomArgs[4] | 0,
333
+ ];
334
+ }
335
+ }
336
+ else {
337
+ console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
338
+ }
339
+ }
340
+ if (dest) {
341
+ this.pdfViewer.scrollPageIntoView({
342
+ pageNumber: pageNumber || this.page,
343
+ destArray: dest,
344
+ allowNegativeOffset: true,
345
+ });
346
+ }
347
+ else if (pageNumber) {
348
+ this.page = pageNumber; // simple page
349
+ }
350
+ if (params.has("pagemode")) {
351
+ this.eventBus.dispatch("pagemode", {
352
+ source: this,
353
+ mode: params.get("pagemode"),
354
+ });
355
+ }
356
+ // Ensure that this parameter is *always* handled last, in order to
357
+ // guarantee that it won't be overridden (e.g. by the "page" parameter).
358
+ if (params.has("nameddest")) {
359
+ this.goToDestination(params.get("nameddest"));
360
+ }
361
+ // if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
362
+ return;
363
+ // }
364
+ // // Support opening of PDF attachments in the Firefox PDF Viewer,
365
+ // // which uses a couple of non-standard hash parameters; refer to
366
+ // // `DownloadManager.openOrDownloadData` in the firefoxcom.js file.
367
+ // if (!params.has("filename") || !params.has("filedest")) {
368
+ // return;
369
+ // }
370
+ // hash = params.get("filedest");
371
+ }
372
+ // Named (or explicit) destination.
373
+ dest = unescape(hash);
374
+ try {
375
+ dest = JSON.parse(dest);
376
+ if (!Array.isArray(dest)) {
377
+ // Avoid incorrectly rejecting a valid named destination, such as
378
+ // e.g. "4.3" or "true", because `JSON.parse` converted its type.
379
+ dest = dest.toString();
380
+ }
381
+ }
382
+ catch (e) {
383
+ if (!e) {
384
+ return;
385
+ }
386
+ }
387
+ if (typeof dest === "string" || __classPrivateFieldGet(_a, _a, "m", _PDFLinkService_isValidExplicitDest).call(_a, dest)) {
388
+ this.goToDestination(dest);
389
+ return;
390
+ }
391
+ // console.error(
392
+ // `PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`
393
+ // );
394
+ }
395
+ /**
396
+ * @param {string} action
397
+ */
398
+ executeNamedAction(action) {
399
+ var _b, _c;
400
+ if (!this.pdfDocument) {
401
+ return;
402
+ }
403
+ // See PDF reference, table 8.45 - Named action
404
+ switch (action) {
405
+ case "GoBack":
406
+ (_b = this.pdfHistory) === null || _b === void 0 ? void 0 : _b.back();
407
+ break;
408
+ case "GoForward":
409
+ (_c = this.pdfHistory) === null || _c === void 0 ? void 0 : _c.forward();
410
+ break;
411
+ case "NextPage":
412
+ this.pdfViewer.nextPage();
413
+ break;
414
+ case "PrevPage":
415
+ this.pdfViewer.previousPage();
416
+ break;
417
+ case "LastPage":
418
+ this.page = this.pagesCount;
419
+ break;
420
+ case "FirstPage":
421
+ this.page = 1;
422
+ break;
423
+ default:
424
+ break; // No action according to spec
425
+ }
426
+ this.eventBus.dispatch("namedaction", {
427
+ source: this,
428
+ action,
429
+ });
430
+ }
431
+ /**
432
+ * @param {Object} action
433
+ */
434
+ executeSetOCGState(action) {
435
+ return __awaiter(this, void 0, void 0, function* () {
436
+ if (!this.pdfDocument) {
437
+ return;
438
+ }
439
+ const pdfDocument = this.pdfDocument, optionalContentConfig = yield this.pdfViewer.optionalContentConfigPromise;
440
+ if (pdfDocument !== this.pdfDocument) {
441
+ return; // The document was closed while the optional content resolved.
442
+ }
443
+ optionalContentConfig.setOCGState(action);
444
+ this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
445
+ });
446
+ }
447
+ }
448
+ _a = PDFLinkService, _PDFLinkService_isValidExplicitDest = function _PDFLinkService_isValidExplicitDest(dest) {
449
+ if (!Array.isArray(dest) || dest.length < 2) {
450
+ return false;
451
+ }
452
+ const [page, zoom, ...args] = dest;
453
+ if (!(typeof page === "object" &&
454
+ Number.isInteger(page === null || page === void 0 ? void 0 : page.num) &&
455
+ Number.isInteger(page === null || page === void 0 ? void 0 : page.gen)) &&
456
+ !Number.isInteger(page)) {
457
+ return false;
458
+ }
459
+ if (!(typeof zoom === "object" && typeof (zoom === null || zoom === void 0 ? void 0 : zoom.name) === "string")) {
460
+ return false;
461
+ }
462
+ const argsLen = args.length;
463
+ let allowNull = true;
464
+ switch (zoom.name) {
465
+ case "XYZ":
466
+ if (argsLen < 2 || argsLen > 3) {
467
+ return false;
468
+ }
469
+ break;
470
+ case "Fit":
471
+ case "FitB":
472
+ return argsLen === 0;
473
+ case "FitH":
474
+ case "FitBH":
475
+ case "FitV":
476
+ case "FitBV":
477
+ if (argsLen > 1) {
478
+ return false;
479
+ }
480
+ break;
481
+ case "FitR":
482
+ if (argsLen !== 4) {
483
+ return false;
484
+ }
485
+ allowNull = false;
486
+ break;
487
+ default:
488
+ return false;
489
+ }
490
+ for (const arg of args) {
491
+ if (!(typeof arg === "number" || (allowNull && arg === null))) {
492
+ return false;
493
+ }
494
+ }
495
+ return true;
496
+ };
497
+ // /**
498
+ // * @implements {IPDFLinkService}
499
+ // */
500
+ // class SimpleLinkService extends PDFLinkService {
501
+ // setDocument(pdfDocument, baseUrl = null) { }
502
+ // }
503
+ export { LinkTarget, PDFLinkService,
504
+ // SimpleLinkService
505
+ };
@@ -1,3 +1,5 @@
1
1
  export * from './scroller';
2
2
  export * from './search';
3
3
  export * from './utils';
4
+ export * from './widget/pdfviewer';
5
+ export * from './enums/PdfViewerInteractionMode';