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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Copyright 2016 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 |
+
|
16 |
+
import { RenderingStates, ScrollMode, SpreadMode } from "./ui_utils.js";
|
17 |
+
import { AppOptions } from "./app_options.js";
|
18 |
+
import { LinkTarget } from "./pdf_link_service.js";
|
19 |
+
import { PDFViewerApplication } from "./app.js";
|
20 |
+
|
21 |
+
/* eslint-disable-next-line no-unused-vars */
|
22 |
+
const pdfjsVersion =
|
23 |
+
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_VERSION") : void 0;
|
24 |
+
/* eslint-disable-next-line no-unused-vars */
|
25 |
+
const pdfjsBuild =
|
26 |
+
typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0;
|
27 |
+
|
28 |
+
const AppConstants =
|
29 |
+
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
|
30 |
+
? { LinkTarget, RenderingStates, ScrollMode, SpreadMode }
|
31 |
+
: null;
|
32 |
+
|
33 |
+
window.PDFViewerApplication = PDFViewerApplication;
|
34 |
+
window.PDFViewerApplicationConstants = AppConstants;
|
35 |
+
window.PDFViewerApplicationOptions = AppOptions;
|
36 |
+
|
37 |
+
function getViewerConfiguration() {
|
38 |
+
return {
|
39 |
+
appContainer: document.body,
|
40 |
+
principalContainer: document.getElementById("mainContainer"),
|
41 |
+
mainContainer: document.getElementById("viewerContainer"),
|
42 |
+
viewerContainer: document.getElementById("viewer"),
|
43 |
+
toolbar: {
|
44 |
+
container: document.getElementById("toolbarContainer"),
|
45 |
+
numPages: document.getElementById("numPages"),
|
46 |
+
pageNumber: document.getElementById("pageNumber"),
|
47 |
+
scaleSelect: document.getElementById("scaleSelect"),
|
48 |
+
customScaleOption: document.getElementById("customScaleOption"),
|
49 |
+
previous: document.getElementById("previous"),
|
50 |
+
next: document.getElementById("next"),
|
51 |
+
zoomIn: document.getElementById("zoomInButton"),
|
52 |
+
zoomOut: document.getElementById("zoomOutButton"),
|
53 |
+
print: document.getElementById("printButton"),
|
54 |
+
editorFreeTextButton: document.getElementById("editorFreeTextButton"),
|
55 |
+
editorFreeTextParamsToolbar: document.getElementById(
|
56 |
+
"editorFreeTextParamsToolbar"
|
57 |
+
),
|
58 |
+
editorHighlightButton: document.getElementById("editorHighlightButton"),
|
59 |
+
editorHighlightParamsToolbar: document.getElementById(
|
60 |
+
"editorHighlightParamsToolbar"
|
61 |
+
),
|
62 |
+
editorHighlightColorPicker: document.getElementById(
|
63 |
+
"editorHighlightColorPicker"
|
64 |
+
),
|
65 |
+
editorInkButton: document.getElementById("editorInkButton"),
|
66 |
+
editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
|
67 |
+
editorStampButton: document.getElementById("editorStampButton"),
|
68 |
+
editorStampParamsToolbar: document.getElementById(
|
69 |
+
"editorStampParamsToolbar"
|
70 |
+
),
|
71 |
+
download: document.getElementById("downloadButton"),
|
72 |
+
},
|
73 |
+
secondaryToolbar: {
|
74 |
+
toolbar: document.getElementById("secondaryToolbar"),
|
75 |
+
toggleButton: document.getElementById("secondaryToolbarToggleButton"),
|
76 |
+
presentationModeButton: document.getElementById("presentationMode"),
|
77 |
+
openFileButton:
|
78 |
+
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
|
79 |
+
? document.getElementById("secondaryOpenFile")
|
80 |
+
: null,
|
81 |
+
printButton: document.getElementById("secondaryPrint"),
|
82 |
+
downloadButton: document.getElementById("secondaryDownload"),
|
83 |
+
viewBookmarkButton: document.getElementById("viewBookmark"),
|
84 |
+
firstPageButton: document.getElementById("firstPage"),
|
85 |
+
lastPageButton: document.getElementById("lastPage"),
|
86 |
+
pageRotateCwButton: document.getElementById("pageRotateCw"),
|
87 |
+
pageRotateCcwButton: document.getElementById("pageRotateCcw"),
|
88 |
+
cursorSelectToolButton: document.getElementById("cursorSelectTool"),
|
89 |
+
cursorHandToolButton: document.getElementById("cursorHandTool"),
|
90 |
+
scrollPageButton: document.getElementById("scrollPage"),
|
91 |
+
scrollVerticalButton: document.getElementById("scrollVertical"),
|
92 |
+
scrollHorizontalButton: document.getElementById("scrollHorizontal"),
|
93 |
+
scrollWrappedButton: document.getElementById("scrollWrapped"),
|
94 |
+
spreadNoneButton: document.getElementById("spreadNone"),
|
95 |
+
spreadOddButton: document.getElementById("spreadOdd"),
|
96 |
+
spreadEvenButton: document.getElementById("spreadEven"),
|
97 |
+
imageAltTextSettingsButton: document.getElementById(
|
98 |
+
"imageAltTextSettings"
|
99 |
+
),
|
100 |
+
imageAltTextSettingsSeparator: document.getElementById(
|
101 |
+
"imageAltTextSettingsSeparator"
|
102 |
+
),
|
103 |
+
documentPropertiesButton: document.getElementById("documentProperties"),
|
104 |
+
},
|
105 |
+
sidebar: {
|
106 |
+
// Divs (and sidebar button)
|
107 |
+
outerContainer: document.getElementById("outerContainer"),
|
108 |
+
sidebarContainer: document.getElementById("sidebarContainer"),
|
109 |
+
toggleButton: document.getElementById("sidebarToggleButton"),
|
110 |
+
resizer: document.getElementById("sidebarResizer"),
|
111 |
+
// Buttons
|
112 |
+
thumbnailButton: document.getElementById("viewThumbnail"),
|
113 |
+
outlineButton: document.getElementById("viewOutline"),
|
114 |
+
attachmentsButton: document.getElementById("viewAttachments"),
|
115 |
+
layersButton: document.getElementById("viewLayers"),
|
116 |
+
// Views
|
117 |
+
thumbnailView: document.getElementById("thumbnailView"),
|
118 |
+
outlineView: document.getElementById("outlineView"),
|
119 |
+
attachmentsView: document.getElementById("attachmentsView"),
|
120 |
+
layersView: document.getElementById("layersView"),
|
121 |
+
// View-specific options
|
122 |
+
currentOutlineItemButton: document.getElementById("currentOutlineItem"),
|
123 |
+
},
|
124 |
+
findBar: {
|
125 |
+
bar: document.getElementById("findbar"),
|
126 |
+
toggleButton: document.getElementById("viewFindButton"),
|
127 |
+
findField: document.getElementById("findInput"),
|
128 |
+
highlightAllCheckbox: document.getElementById("findHighlightAll"),
|
129 |
+
caseSensitiveCheckbox: document.getElementById("findMatchCase"),
|
130 |
+
matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
|
131 |
+
entireWordCheckbox: document.getElementById("findEntireWord"),
|
132 |
+
findMsg: document.getElementById("findMsg"),
|
133 |
+
findResultsCount: document.getElementById("findResultsCount"),
|
134 |
+
findPreviousButton: document.getElementById("findPreviousButton"),
|
135 |
+
findNextButton: document.getElementById("findNextButton"),
|
136 |
+
},
|
137 |
+
passwordOverlay: {
|
138 |
+
dialog: document.getElementById("passwordDialog"),
|
139 |
+
label: document.getElementById("passwordText"),
|
140 |
+
input: document.getElementById("password"),
|
141 |
+
submitButton: document.getElementById("passwordSubmit"),
|
142 |
+
cancelButton: document.getElementById("passwordCancel"),
|
143 |
+
},
|
144 |
+
documentProperties: {
|
145 |
+
dialog: document.getElementById("documentPropertiesDialog"),
|
146 |
+
closeButton: document.getElementById("documentPropertiesClose"),
|
147 |
+
fields: {
|
148 |
+
fileName: document.getElementById("fileNameField"),
|
149 |
+
fileSize: document.getElementById("fileSizeField"),
|
150 |
+
title: document.getElementById("titleField"),
|
151 |
+
author: document.getElementById("authorField"),
|
152 |
+
subject: document.getElementById("subjectField"),
|
153 |
+
keywords: document.getElementById("keywordsField"),
|
154 |
+
creationDate: document.getElementById("creationDateField"),
|
155 |
+
modificationDate: document.getElementById("modificationDateField"),
|
156 |
+
creator: document.getElementById("creatorField"),
|
157 |
+
producer: document.getElementById("producerField"),
|
158 |
+
version: document.getElementById("versionField"),
|
159 |
+
pageCount: document.getElementById("pageCountField"),
|
160 |
+
pageSize: document.getElementById("pageSizeField"),
|
161 |
+
linearized: document.getElementById("linearizedField"),
|
162 |
+
},
|
163 |
+
},
|
164 |
+
altTextDialog: {
|
165 |
+
dialog: document.getElementById("altTextDialog"),
|
166 |
+
optionDescription: document.getElementById("descriptionButton"),
|
167 |
+
optionDecorative: document.getElementById("decorativeButton"),
|
168 |
+
textarea: document.getElementById("descriptionTextarea"),
|
169 |
+
cancelButton: document.getElementById("altTextCancel"),
|
170 |
+
saveButton: document.getElementById("altTextSave"),
|
171 |
+
},
|
172 |
+
newAltTextDialog: {
|
173 |
+
dialog: document.getElementById("newAltTextDialog"),
|
174 |
+
title: document.getElementById("newAltTextTitle"),
|
175 |
+
descriptionContainer: document.getElementById(
|
176 |
+
"newAltTextDescriptionContainer"
|
177 |
+
),
|
178 |
+
textarea: document.getElementById("newAltTextDescriptionTextarea"),
|
179 |
+
disclaimer: document.getElementById("newAltTextDisclaimer"),
|
180 |
+
learnMore: document.getElementById("newAltTextLearnMore"),
|
181 |
+
imagePreview: document.getElementById("newAltTextImagePreview"),
|
182 |
+
createAutomatically: document.getElementById(
|
183 |
+
"newAltTextCreateAutomatically"
|
184 |
+
),
|
185 |
+
createAutomaticallyButton: document.getElementById(
|
186 |
+
"newAltTextCreateAutomaticallyButton"
|
187 |
+
),
|
188 |
+
downloadModel: document.getElementById("newAltTextDownloadModel"),
|
189 |
+
downloadModelDescription: document.getElementById(
|
190 |
+
"newAltTextDownloadModelDescription"
|
191 |
+
),
|
192 |
+
error: document.getElementById("newAltTextError"),
|
193 |
+
errorCloseButton: document.getElementById("newAltTextCloseButton"),
|
194 |
+
cancelButton: document.getElementById("newAltTextCancel"),
|
195 |
+
notNowButton: document.getElementById("newAltTextNotNow"),
|
196 |
+
saveButton: document.getElementById("newAltTextSave"),
|
197 |
+
},
|
198 |
+
altTextSettingsDialog: {
|
199 |
+
dialog: document.getElementById("altTextSettingsDialog"),
|
200 |
+
createModelButton: document.getElementById("createModelButton"),
|
201 |
+
aiModelSettings: document.getElementById("aiModelSettings"),
|
202 |
+
learnMore: document.getElementById("altTextSettingsLearnMore"),
|
203 |
+
deleteModelButton: document.getElementById("deleteModelButton"),
|
204 |
+
downloadModelButton: document.getElementById("downloadModelButton"),
|
205 |
+
showAltTextDialogButton: document.getElementById(
|
206 |
+
"showAltTextDialogButton"
|
207 |
+
),
|
208 |
+
altTextSettingsCloseButton: document.getElementById(
|
209 |
+
"altTextSettingsCloseButton"
|
210 |
+
),
|
211 |
+
closeButton: document.getElementById("altTextSettingsCloseButton"),
|
212 |
+
},
|
213 |
+
annotationEditorParams: {
|
214 |
+
editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
|
215 |
+
editorFreeTextColor: document.getElementById("editorFreeTextColor"),
|
216 |
+
editorInkColor: document.getElementById("editorInkColor"),
|
217 |
+
editorInkThickness: document.getElementById("editorInkThickness"),
|
218 |
+
editorInkOpacity: document.getElementById("editorInkOpacity"),
|
219 |
+
editorStampAddImage: document.getElementById("editorStampAddImage"),
|
220 |
+
editorFreeHighlightThickness: document.getElementById(
|
221 |
+
"editorFreeHighlightThickness"
|
222 |
+
),
|
223 |
+
editorHighlightShowAll: document.getElementById("editorHighlightShowAll"),
|
224 |
+
},
|
225 |
+
printContainer: document.getElementById("printContainer"),
|
226 |
+
};
|
227 |
+
}
|
228 |
+
|
229 |
+
function webViewerLoad() {
|
230 |
+
const config = getViewerConfiguration();
|
231 |
+
|
232 |
+
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC")) {
|
233 |
+
// Give custom implementations of the default viewer a simpler way to
|
234 |
+
// set various `AppOptions`, by dispatching an event once all viewer
|
235 |
+
// files are loaded but *before* the viewer initialization has run.
|
236 |
+
const event = new CustomEvent("webviewerloaded", {
|
237 |
+
bubbles: true,
|
238 |
+
cancelable: true,
|
239 |
+
detail: {
|
240 |
+
source: window,
|
241 |
+
},
|
242 |
+
});
|
243 |
+
try {
|
244 |
+
// Attempt to dispatch the event at the embedding `document`,
|
245 |
+
// in order to support cases where the viewer is embedded in
|
246 |
+
// a *dynamically* created <iframe> element.
|
247 |
+
parent.document.dispatchEvent(event);
|
248 |
+
} catch (ex) {
|
249 |
+
// The viewer could be in e.g. a cross-origin <iframe> element,
|
250 |
+
// fallback to dispatching the event at the current `document`.
|
251 |
+
console.error(`webviewerloaded: ${ex}`);
|
252 |
+
document.dispatchEvent(event);
|
253 |
+
}
|
254 |
+
}
|
255 |
+
PDFViewerApplication.run(config);
|
256 |
+
}
|
257 |
+
|
258 |
+
// Block the "load" event until all pages are loaded, to ensure that printing
|
259 |
+
// works in Firefox; see https://bugzilla.mozilla.org/show_bug.cgi?id=1618553
|
260 |
+
document.blockUnblockOnload?.(true);
|
261 |
+
|
262 |
+
if (
|
263 |
+
document.readyState === "interactive" ||
|
264 |
+
document.readyState === "complete"
|
265 |
+
) {
|
266 |
+
webViewerLoad();
|
267 |
+
} else {
|
268 |
+
document.addEventListener("DOMContentLoaded", webViewerLoad, true);
|
269 |
+
}
|
270 |
+
|
271 |
+
export {
|
272 |
+
AppConstants as PDFViewerApplicationConstants,
|
273 |
+
AppOptions as PDFViewerApplicationOptions,
|
274 |
+
PDFViewerApplication,
|
275 |
+
};
|