app.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  27. var _ui_utils = require("./ui_utils.js");
  28. var _pdf = require("../pdf");
  29. var _app_options = require("./app_options.js");
  30. var _event_utils = require("./event_utils.js");
  31. var _pdf_cursor_tools = require("./pdf_cursor_tools.js");
  32. var _pdf_link_service = require("./pdf_link_service.js");
  33. var _annotation_editor_params = require("./annotation_editor_params.js");
  34. var _overlay_manager = require("./overlay_manager.js");
  35. var _password_prompt = require("./password_prompt.js");
  36. var _pdf_attachment_viewer = require("./pdf_attachment_viewer.js");
  37. var _pdf_document_properties = require("./pdf_document_properties.js");
  38. var _pdf_find_bar = require("./pdf_find_bar.js");
  39. var _pdf_find_controller = require("./pdf_find_controller.js");
  40. var _pdf_history = require("./pdf_history.js");
  41. var _pdf_layer_viewer = require("./pdf_layer_viewer.js");
  42. var _pdf_outline_viewer = require("./pdf_outline_viewer.js");
  43. var _pdf_presentation_mode = require("./pdf_presentation_mode.js");
  44. var _pdf_rendering_queue = require("./pdf_rendering_queue.js");
  45. var _pdf_scripting_manager = require("./pdf_scripting_manager.js");
  46. var _pdf_sidebar = require("./pdf_sidebar.js");
  47. var _pdf_sidebar_resizer = require("./pdf_sidebar_resizer.js");
  48. var _pdf_thumbnail_viewer = require("./pdf_thumbnail_viewer.js");
  49. var _pdf_viewer = require("./pdf_viewer.js");
  50. var _secondary_toolbar = require("./secondary_toolbar.js");
  51. var _toolbar = require("./toolbar.js");
  52. var _view_history = require("./view_history.js");
  53. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  54. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  55. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  56. const ViewOnLoad = {
  57. UNKNOWN: -1,
  58. PREVIOUS: 0,
  59. INITIAL: 1
  60. };
  61. const ViewerCssTheme = {
  62. AUTOMATIC: 0,
  63. LIGHT: 1,
  64. DARK: 2
  65. };
  66. class DefaultExternalServices {
  67. constructor() {
  68. throw new Error("Cannot initialize DefaultExternalServices.");
  69. }
  70. static updateFindControlState(data) {}
  71. static updateFindMatchesCount(data) {}
  72. static initPassiveLoading(callbacks) {}
  73. static reportTelemetry(data) {}
  74. static createDownloadManager() {
  75. throw new Error("Not implemented: createDownloadManager");
  76. }
  77. static createPreferences() {
  78. throw new Error("Not implemented: createPreferences");
  79. }
  80. static createL10n(options) {
  81. throw new Error("Not implemented: createL10n");
  82. }
  83. static createScripting(options) {
  84. throw new Error("Not implemented: createScripting");
  85. }
  86. static get supportsIntegratedFind() {
  87. return (0, _pdf.shadow)(this, "supportsIntegratedFind", false);
  88. }
  89. static get supportsDocumentFonts() {
  90. return (0, _pdf.shadow)(this, "supportsDocumentFonts", true);
  91. }
  92. static get supportedMouseWheelZoomModifierKeys() {
  93. return (0, _pdf.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  94. ctrlKey: true,
  95. metaKey: true
  96. });
  97. }
  98. static get isInAutomation() {
  99. return (0, _pdf.shadow)(this, "isInAutomation", false);
  100. }
  101. static updateEditorStates(data) {
  102. throw new Error("Not implemented: updateEditorStates");
  103. }
  104. }
  105. exports.DefaultExternalServices = DefaultExternalServices;
  106. const PDFViewerApplication = {
  107. initialBookmark: document.location.hash.substring(1),
  108. _initializedCapability: (0, _pdf.createPromiseCapability)(),
  109. appConfig: null,
  110. pdfDocument: null,
  111. pdfLoadingTask: null,
  112. printService: null,
  113. pdfViewer: null,
  114. pdfThumbnailViewer: null,
  115. pdfRenderingQueue: null,
  116. pdfPresentationMode: null,
  117. pdfDocumentProperties: null,
  118. pdfLinkService: null,
  119. pdfHistory: null,
  120. pdfSidebar: null,
  121. pdfSidebarResizer: null,
  122. pdfOutlineViewer: null,
  123. pdfAttachmentViewer: null,
  124. pdfLayerViewer: null,
  125. pdfCursorTools: null,
  126. pdfScriptingManager: null,
  127. store: null,
  128. downloadManager: null,
  129. overlayManager: null,
  130. preferences: null,
  131. toolbar: null,
  132. secondaryToolbar: null,
  133. eventBus: null,
  134. l10n: null,
  135. annotationEditorParams: null,
  136. isInitialViewSet: false,
  137. downloadComplete: false,
  138. isViewerEmbedded: window.parent !== window,
  139. url: "",
  140. baseUrl: "",
  141. _downloadUrl: "",
  142. externalServices: DefaultExternalServices,
  143. _boundEvents: Object.create(null),
  144. documentInfo: null,
  145. metadata: null,
  146. _contentDispositionFilename: null,
  147. _contentLength: null,
  148. _saveInProgress: false,
  149. _wheelUnusedTicks: 0,
  150. _PDFBug: null,
  151. _hasAnnotationEditors: false,
  152. _title: document.title,
  153. _printAnnotationStoragePromise: null,
  154. async initialize(appConfig) {
  155. this.preferences = this.externalServices.createPreferences();
  156. this.appConfig = appConfig;
  157. await this._readPreferences();
  158. await this._parseHashParameters();
  159. this._forceCssTheme();
  160. await this._initializeL10n();
  161. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  162. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  163. }
  164. await this._initializeViewerComponents();
  165. this.bindEvents();
  166. this.bindWindowEvents();
  167. const appContainer = appConfig.appContainer || document.documentElement;
  168. this.l10n.translate(appContainer).then(() => {
  169. this.eventBus.dispatch("localized", {
  170. source: this
  171. });
  172. });
  173. this._initializedCapability.resolve();
  174. },
  175. async _readPreferences() {
  176. if (_app_options.AppOptions.get("disablePreferences")) {
  177. return;
  178. }
  179. if (_app_options.AppOptions._hasUserOptions()) {
  180. console.warn("_readPreferences: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  181. }
  182. try {
  183. _app_options.AppOptions.setAll(await this.preferences.getAll());
  184. } catch (reason) {
  185. console.error(`_readPreferences: "${reason?.message}".`);
  186. }
  187. },
  188. async _parseHashParameters() {
  189. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  190. return;
  191. }
  192. const hash = document.location.hash.substring(1);
  193. if (!hash) {
  194. return;
  195. }
  196. const {
  197. mainContainer,
  198. viewerContainer
  199. } = this.appConfig,
  200. params = (0, _ui_utils.parseQueryString)(hash);
  201. if (params.get("disableworker") === "true") {
  202. try {
  203. await loadFakeWorker();
  204. } catch (ex) {
  205. console.error(`_parseHashParameters: "${ex.message}".`);
  206. }
  207. }
  208. if (params.has("disablerange")) {
  209. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  210. }
  211. if (params.has("disablestream")) {
  212. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  213. }
  214. if (params.has("disableautofetch")) {
  215. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  216. }
  217. if (params.has("disablefontface")) {
  218. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  219. }
  220. if (params.has("disablehistory")) {
  221. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  222. }
  223. if (params.has("verbosity")) {
  224. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  225. }
  226. if (params.has("textlayer")) {
  227. switch (params.get("textlayer")) {
  228. case "off":
  229. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  230. break;
  231. case "visible":
  232. case "shadow":
  233. case "hover":
  234. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  235. try {
  236. await loadPDFBug(this);
  237. this._PDFBug.loadCSS();
  238. } catch (ex) {
  239. console.error(`_parseHashParameters: "${ex.message}".`);
  240. }
  241. break;
  242. }
  243. }
  244. if (params.has("pdfbug")) {
  245. _app_options.AppOptions.set("pdfBug", true);
  246. _app_options.AppOptions.set("fontExtraProperties", true);
  247. const enabled = params.get("pdfbug").split(",");
  248. try {
  249. await loadPDFBug(this);
  250. this._PDFBug.init({
  251. OPS: _pdf.OPS
  252. }, mainContainer, enabled);
  253. } catch (ex) {
  254. console.error(`_parseHashParameters: "${ex.message}".`);
  255. }
  256. }
  257. if (params.has("locale")) {
  258. _app_options.AppOptions.set("locale", params.get("locale"));
  259. }
  260. },
  261. async _initializeL10n() {
  262. this.l10n = this.externalServices.createL10n({
  263. locale: _app_options.AppOptions.get("locale")
  264. });
  265. const dir = await this.l10n.getDirection();
  266. document.getElementsByTagName("html")[0].dir = dir;
  267. },
  268. _forceCssTheme() {
  269. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  270. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  271. return;
  272. }
  273. try {
  274. const styleSheet = document.styleSheets[0];
  275. const cssRules = styleSheet?.cssRules || [];
  276. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  277. const rule = cssRules[i];
  278. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  279. if (cssTheme === ViewerCssTheme.LIGHT) {
  280. styleSheet.deleteRule(i);
  281. return;
  282. }
  283. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  284. if (darkRules?.[1]) {
  285. styleSheet.deleteRule(i);
  286. styleSheet.insertRule(darkRules[1], i);
  287. }
  288. return;
  289. }
  290. }
  291. } catch (reason) {
  292. console.error(`_forceCssTheme: "${reason?.message}".`);
  293. }
  294. },
  295. async _initializeViewerComponents() {
  296. const {
  297. appConfig,
  298. externalServices
  299. } = this;
  300. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  301. this.eventBus = eventBus;
  302. this.overlayManager = new _overlay_manager.OverlayManager();
  303. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  304. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  305. this.pdfRenderingQueue = pdfRenderingQueue;
  306. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  307. eventBus,
  308. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  309. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  310. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  311. });
  312. this.pdfLinkService = pdfLinkService;
  313. const downloadManager = externalServices.createDownloadManager();
  314. this.downloadManager = downloadManager;
  315. const findController = new _pdf_find_controller.PDFFindController({
  316. linkService: pdfLinkService,
  317. eventBus
  318. });
  319. this.findController = findController;
  320. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  321. eventBus,
  322. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  323. scriptingFactory: externalServices,
  324. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  325. });
  326. this.pdfScriptingManager = pdfScriptingManager;
  327. const container = appConfig.mainContainer,
  328. viewer = appConfig.viewerContainer;
  329. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  330. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  331. background: _app_options.AppOptions.get("pageColorsBackground"),
  332. foreground: _app_options.AppOptions.get("pageColorsForeground")
  333. } : null;
  334. this.pdfViewer = new _pdf_viewer.PDFViewer({
  335. container,
  336. viewer,
  337. eventBus,
  338. renderingQueue: pdfRenderingQueue,
  339. linkService: pdfLinkService,
  340. downloadManager,
  341. findController,
  342. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  343. renderer: _app_options.AppOptions.get("renderer"),
  344. l10n: this.l10n,
  345. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  346. annotationMode: _app_options.AppOptions.get("annotationMode"),
  347. annotationEditorMode,
  348. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  349. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  350. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  351. isOffscreenCanvasSupported: _app_options.AppOptions.get("isOffscreenCanvasSupported"),
  352. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  353. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  354. pageColors
  355. });
  356. pdfRenderingQueue.setViewer(this.pdfViewer);
  357. pdfLinkService.setViewer(this.pdfViewer);
  358. pdfScriptingManager.setViewer(this.pdfViewer);
  359. if (appConfig.sidebar?.thumbnailView) {
  360. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  361. container: appConfig.sidebar.thumbnailView,
  362. eventBus,
  363. renderingQueue: pdfRenderingQueue,
  364. linkService: pdfLinkService,
  365. l10n: this.l10n,
  366. pageColors
  367. });
  368. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  369. }
  370. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  371. this.pdfHistory = new _pdf_history.PDFHistory({
  372. linkService: pdfLinkService,
  373. eventBus
  374. });
  375. pdfLinkService.setHistory(this.pdfHistory);
  376. }
  377. if (!this.supportsIntegratedFind && appConfig.findBar) {
  378. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  379. }
  380. if (appConfig.annotationEditorParams) {
  381. if (annotationEditorMode !== _pdf.AnnotationEditorType.DISABLE) {
  382. this.annotationEditorParams = new _annotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  383. } else {
  384. for (const id of ["editorModeButtons", "editorModeSeparator"]) {
  385. document.getElementById(id)?.classList.add("hidden");
  386. }
  387. }
  388. }
  389. if (appConfig.documentProperties) {
  390. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => {
  391. return this._docFilename;
  392. });
  393. }
  394. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  395. container,
  396. eventBus,
  397. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  398. });
  399. if (appConfig.toolbar) {
  400. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  401. }
  402. if (appConfig.secondaryToolbar) {
  403. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, this.externalServices);
  404. }
  405. if (this.supportsFullscreen) {
  406. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  407. container,
  408. pdfViewer: this.pdfViewer,
  409. eventBus
  410. });
  411. }
  412. if (appConfig.passwordOverlay) {
  413. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  414. }
  415. if (appConfig.sidebar?.outlineView) {
  416. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  417. container: appConfig.sidebar.outlineView,
  418. eventBus,
  419. linkService: pdfLinkService,
  420. downloadManager
  421. });
  422. }
  423. if (appConfig.sidebar?.attachmentsView) {
  424. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  425. container: appConfig.sidebar.attachmentsView,
  426. eventBus,
  427. downloadManager
  428. });
  429. }
  430. if (appConfig.sidebar?.layersView) {
  431. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  432. container: appConfig.sidebar.layersView,
  433. eventBus,
  434. l10n: this.l10n
  435. });
  436. }
  437. if (appConfig.sidebar) {
  438. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  439. elements: appConfig.sidebar,
  440. pdfViewer: this.pdfViewer,
  441. pdfThumbnailViewer: this.pdfThumbnailViewer,
  442. eventBus,
  443. l10n: this.l10n
  444. });
  445. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  446. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  447. }
  448. },
  449. run(config) {
  450. this.initialize(config).then(webViewerInitialized);
  451. },
  452. get initialized() {
  453. return this._initializedCapability.settled;
  454. },
  455. get initializedPromise() {
  456. return this._initializedCapability.promise;
  457. },
  458. zoomIn(steps) {
  459. if (this.pdfViewer.isInPresentationMode) {
  460. return;
  461. }
  462. this.pdfViewer.increaseScale(steps, {
  463. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay")
  464. });
  465. },
  466. zoomOut(steps) {
  467. if (this.pdfViewer.isInPresentationMode) {
  468. return;
  469. }
  470. this.pdfViewer.decreaseScale(steps, {
  471. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay")
  472. });
  473. },
  474. zoomReset() {
  475. if (this.pdfViewer.isInPresentationMode) {
  476. return;
  477. }
  478. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  479. },
  480. get pagesCount() {
  481. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  482. },
  483. get page() {
  484. return this.pdfViewer.currentPageNumber;
  485. },
  486. set page(val) {
  487. this.pdfViewer.currentPageNumber = val;
  488. },
  489. get supportsPrinting() {
  490. return PDFPrintServiceFactory.instance.supportsPrinting;
  491. },
  492. get supportsFullscreen() {
  493. return (0, _pdf.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  494. },
  495. get supportsIntegratedFind() {
  496. return this.externalServices.supportsIntegratedFind;
  497. },
  498. get supportsDocumentFonts() {
  499. return this.externalServices.supportsDocumentFonts;
  500. },
  501. get loadingBar() {
  502. const barElement = document.getElementById("loadingBar");
  503. const bar = barElement ? new _ui_utils.ProgressBar(barElement) : null;
  504. return (0, _pdf.shadow)(this, "loadingBar", bar);
  505. },
  506. get supportedMouseWheelZoomModifierKeys() {
  507. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  508. },
  509. initPassiveLoading() {
  510. throw new Error("Not implemented: initPassiveLoading");
  511. },
  512. setTitleUsingUrl(url = "", downloadUrl = null) {
  513. this.url = url;
  514. this.baseUrl = url.split("#")[0];
  515. if (downloadUrl) {
  516. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  517. }
  518. if ((0, _pdf.isDataScheme)(url)) {
  519. this._hideViewBookmark();
  520. }
  521. let title = (0, _pdf.getPdfFilenameFromUrl)(url, "");
  522. if (!title) {
  523. try {
  524. title = decodeURIComponent((0, _pdf.getFilenameFromUrl)(url)) || url;
  525. } catch (ex) {
  526. title = url;
  527. }
  528. }
  529. this.setTitle(title);
  530. },
  531. setTitle(title = this._title) {
  532. this._title = title;
  533. if (this.isViewerEmbedded) {
  534. return;
  535. }
  536. const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  537. document.title = `${editorIndicator ? "* " : ""}${title}`;
  538. },
  539. get _docFilename() {
  540. return this._contentDispositionFilename || (0, _pdf.getPdfFilenameFromUrl)(this.url);
  541. },
  542. _hideViewBookmark() {
  543. const {
  544. secondaryToolbar
  545. } = this.appConfig;
  546. secondaryToolbar?.viewBookmarkButton.classList.add("hidden");
  547. if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) {
  548. document.getElementById("viewBookmarkSeparator")?.classList.add("hidden");
  549. }
  550. },
  551. async close() {
  552. this._unblockDocumentLoadEvent();
  553. this._hideViewBookmark();
  554. if (!this.pdfLoadingTask) {
  555. return;
  556. }
  557. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  558. try {
  559. await this.save();
  560. } catch (reason) {}
  561. }
  562. const promises = [];
  563. promises.push(this.pdfLoadingTask.destroy());
  564. this.pdfLoadingTask = null;
  565. if (this.pdfDocument) {
  566. this.pdfDocument = null;
  567. this.pdfThumbnailViewer?.setDocument(null);
  568. this.pdfViewer.setDocument(null);
  569. this.pdfLinkService.setDocument(null);
  570. this.pdfDocumentProperties?.setDocument(null);
  571. }
  572. this.pdfLinkService.externalLinkEnabled = true;
  573. this.store = null;
  574. this.isInitialViewSet = false;
  575. this.downloadComplete = false;
  576. this.url = "";
  577. this.baseUrl = "";
  578. this._downloadUrl = "";
  579. this.documentInfo = null;
  580. this.metadata = null;
  581. this._contentDispositionFilename = null;
  582. this._contentLength = null;
  583. this._saveInProgress = false;
  584. this._hasAnnotationEditors = false;
  585. promises.push(this.pdfScriptingManager.destroyPromise);
  586. this.setTitle();
  587. this.pdfSidebar?.reset();
  588. this.pdfOutlineViewer?.reset();
  589. this.pdfAttachmentViewer?.reset();
  590. this.pdfLayerViewer?.reset();
  591. this.pdfHistory?.reset();
  592. this.findBar?.reset();
  593. this.toolbar?.reset();
  594. this.secondaryToolbar?.reset();
  595. this._PDFBug?.cleanup();
  596. await Promise.all(promises);
  597. },
  598. async open(file, args) {
  599. if (this.pdfLoadingTask) {
  600. await this.close();
  601. }
  602. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  603. for (const key in workerParameters) {
  604. _pdf.GlobalWorkerOptions[key] = workerParameters[key];
  605. }
  606. const parameters = Object.create(null);
  607. if (typeof file === "string") {
  608. this.setTitleUsingUrl(file, file);
  609. parameters.url = file;
  610. } else if (file && "byteLength" in file) {
  611. parameters.data = file;
  612. } else if (file.url && file.originalUrl) {
  613. this.setTitleUsingUrl(file.originalUrl, file.url);
  614. parameters.url = file.url;
  615. }
  616. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  617. for (const key in apiParameters) {
  618. let value = apiParameters[key];
  619. if (key === "docBaseUrl" && !value) {}
  620. parameters[key] = value;
  621. }
  622. if (args) {
  623. for (const key in args) {
  624. parameters[key] = args[key];
  625. }
  626. }
  627. const loadingTask = (0, _pdf.getDocument)(parameters);
  628. this.pdfLoadingTask = loadingTask;
  629. loadingTask.onPassword = (updateCallback, reason) => {
  630. if (this.isViewerEmbedded) {
  631. this._unblockDocumentLoadEvent();
  632. }
  633. this.pdfLinkService.externalLinkEnabled = false;
  634. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  635. this.passwordPrompt.open();
  636. };
  637. loadingTask.onProgress = ({
  638. loaded,
  639. total
  640. }) => {
  641. this.progress(loaded / total);
  642. };
  643. return loadingTask.promise.then(pdfDocument => {
  644. this.load(pdfDocument);
  645. }, reason => {
  646. if (loadingTask !== this.pdfLoadingTask) {
  647. return undefined;
  648. }
  649. let key = "loading_error";
  650. if (reason instanceof _pdf.InvalidPDFException) {
  651. key = "invalid_file_error";
  652. } else if (reason instanceof _pdf.MissingPDFException) {
  653. key = "missing_file_error";
  654. } else if (reason instanceof _pdf.UnexpectedResponseException) {
  655. key = "unexpected_response_error";
  656. }
  657. return this.l10n.get(key).then(msg => {
  658. this._documentError(msg, {
  659. message: reason?.message
  660. });
  661. throw reason;
  662. });
  663. });
  664. },
  665. _ensureDownloadComplete() {
  666. if (this.pdfDocument && this.downloadComplete) {
  667. return;
  668. }
  669. throw new Error("PDF document not downloaded.");
  670. },
  671. async download() {
  672. const url = this._downloadUrl,
  673. filename = this._docFilename;
  674. try {
  675. this._ensureDownloadComplete();
  676. const data = await this.pdfDocument.getData();
  677. const blob = new Blob([data], {
  678. type: "application/pdf"
  679. });
  680. await this.downloadManager.download(blob, url, filename);
  681. } catch (reason) {
  682. await this.downloadManager.downloadUrl(url, filename);
  683. }
  684. },
  685. async save() {
  686. if (this._saveInProgress) {
  687. return;
  688. }
  689. this._saveInProgress = true;
  690. await this.pdfScriptingManager.dispatchWillSave();
  691. const url = this._downloadUrl,
  692. filename = this._docFilename;
  693. try {
  694. this._ensureDownloadComplete();
  695. const data = await this.pdfDocument.saveDocument();
  696. const blob = new Blob([data], {
  697. type: "application/pdf"
  698. });
  699. await this.downloadManager.download(blob, url, filename);
  700. } catch (reason) {
  701. console.error(`Error when saving the document: ${reason.message}`);
  702. await this.download();
  703. } finally {
  704. await this.pdfScriptingManager.dispatchDidSave();
  705. this._saveInProgress = false;
  706. }
  707. if (this._hasAnnotationEditors) {
  708. this.externalServices.reportTelemetry({
  709. type: "editing",
  710. data: {
  711. type: "save"
  712. }
  713. });
  714. }
  715. },
  716. downloadOrSave() {
  717. if (this.pdfDocument?.annotationStorage.size > 0) {
  718. this.save();
  719. } else {
  720. this.download();
  721. }
  722. },
  723. _documentError(message, moreInfo = null) {
  724. this._unblockDocumentLoadEvent();
  725. this._otherError(message, moreInfo);
  726. this.eventBus.dispatch("documenterror", {
  727. source: this,
  728. message,
  729. reason: moreInfo?.message ?? null
  730. });
  731. },
  732. _otherError(message, moreInfo = null) {
  733. const moreInfoText = [`PDF.js v${_pdf.version || "?"} (build: ${_pdf.build || "?"})`];
  734. if (moreInfo) {
  735. moreInfoText.push(`Message: ${moreInfo.message}`);
  736. if (moreInfo.stack) {
  737. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  738. } else {
  739. if (moreInfo.filename) {
  740. moreInfoText.push(`File: ${moreInfo.filename}`);
  741. }
  742. if (moreInfo.lineNumber) {
  743. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  744. }
  745. }
  746. }
  747. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  748. },
  749. progress(level) {
  750. if (!this.loadingBar || this.downloadComplete) {
  751. return;
  752. }
  753. const percent = Math.round(level * 100);
  754. if (percent <= this.loadingBar.percent) {
  755. return;
  756. }
  757. this.loadingBar.percent = percent;
  758. const disableAutoFetch = this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch");
  759. if (!disableAutoFetch || isNaN(percent)) {
  760. return;
  761. }
  762. if (this.disableAutoFetchLoadingBarTimeout) {
  763. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  764. this.disableAutoFetchLoadingBarTimeout = null;
  765. }
  766. this.loadingBar.show();
  767. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  768. this.loadingBar.hide();
  769. this.disableAutoFetchLoadingBarTimeout = null;
  770. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  771. },
  772. load(pdfDocument) {
  773. this.pdfDocument = pdfDocument;
  774. pdfDocument.getDownloadInfo().then(({
  775. length
  776. }) => {
  777. this._contentLength = length;
  778. this.downloadComplete = true;
  779. this.loadingBar?.hide();
  780. firstPagePromise.then(() => {
  781. this.eventBus.dispatch("documentloaded", {
  782. source: this
  783. });
  784. });
  785. });
  786. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  787. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  788. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  789. this.toolbar?.setPagesCount(pdfDocument.numPages, false);
  790. this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
  791. let baseDocumentUrl;
  792. baseDocumentUrl = null;
  793. if (baseDocumentUrl && (0, _pdf.isDataScheme)(baseDocumentUrl)) {
  794. baseDocumentUrl = null;
  795. }
  796. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  797. this.pdfDocumentProperties?.setDocument(pdfDocument);
  798. const pdfViewer = this.pdfViewer;
  799. pdfViewer.setDocument(pdfDocument);
  800. const {
  801. firstPagePromise,
  802. onePageRendered,
  803. pagesPromise
  804. } = pdfViewer;
  805. this.pdfThumbnailViewer?.setDocument(pdfDocument);
  806. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  807. page: null,
  808. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  809. scrollLeft: "0",
  810. scrollTop: "0",
  811. rotation: null,
  812. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  813. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  814. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  815. }).catch(() => {
  816. return Object.create(null);
  817. });
  818. firstPagePromise.then(pdfPage => {
  819. this.loadingBar?.setWidth(this.appConfig.viewerContainer);
  820. this._initializeAnnotationStorageCallbacks(pdfDocument);
  821. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  822. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  823. this._initializePdfHistory({
  824. fingerprint: pdfDocument.fingerprints[0],
  825. viewOnLoad,
  826. initialDest: openAction?.dest
  827. });
  828. const initialBookmark = this.initialBookmark;
  829. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  830. let hash = zoom ? `zoom=${zoom}` : null;
  831. let rotation = null;
  832. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  833. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  834. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  835. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  836. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  837. rotation = parseInt(stored.rotation, 10);
  838. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  839. sidebarView = stored.sidebarView | 0;
  840. }
  841. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  842. scrollMode = stored.scrollMode | 0;
  843. }
  844. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  845. spreadMode = stored.spreadMode | 0;
  846. }
  847. }
  848. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  849. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  850. }
  851. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  852. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  853. spreadMode = modes.spreadMode;
  854. }
  855. this.setInitialView(hash, {
  856. rotation,
  857. sidebarView,
  858. scrollMode,
  859. spreadMode
  860. });
  861. this.eventBus.dispatch("documentinit", {
  862. source: this
  863. });
  864. if (!this.isViewerEmbedded) {
  865. pdfViewer.focus();
  866. }
  867. await Promise.race([pagesPromise, new Promise(resolve => {
  868. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  869. })]);
  870. if (!initialBookmark && !hash) {
  871. return;
  872. }
  873. if (pdfViewer.hasEqualPageSizes) {
  874. return;
  875. }
  876. this.initialBookmark = initialBookmark;
  877. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  878. this.setInitialView(hash);
  879. }).catch(() => {
  880. this.setInitialView();
  881. }).then(function () {
  882. pdfViewer.update();
  883. });
  884. });
  885. pagesPromise.then(() => {
  886. this._unblockDocumentLoadEvent();
  887. this._initializeAutoPrint(pdfDocument, openActionPromise);
  888. }, reason => {
  889. this.l10n.get("loading_error").then(msg => {
  890. this._documentError(msg, {
  891. message: reason?.message
  892. });
  893. });
  894. });
  895. onePageRendered.then(data => {
  896. this.externalServices.reportTelemetry({
  897. type: "pageInfo",
  898. timestamp: data.timestamp
  899. });
  900. pdfDocument.getOutline().then(outline => {
  901. if (pdfDocument !== this.pdfDocument) {
  902. return;
  903. }
  904. this.pdfOutlineViewer?.render({
  905. outline,
  906. pdfDocument
  907. });
  908. });
  909. pdfDocument.getAttachments().then(attachments => {
  910. if (pdfDocument !== this.pdfDocument) {
  911. return;
  912. }
  913. this.pdfAttachmentViewer?.render({
  914. attachments
  915. });
  916. });
  917. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  918. if (pdfDocument !== this.pdfDocument) {
  919. return;
  920. }
  921. this.pdfLayerViewer?.render({
  922. optionalContentConfig,
  923. pdfDocument
  924. });
  925. });
  926. });
  927. this._initializePageLabels(pdfDocument);
  928. this._initializeMetadata(pdfDocument);
  929. },
  930. async _scriptingDocProperties(pdfDocument) {
  931. if (!this.documentInfo) {
  932. await new Promise(resolve => {
  933. this.eventBus._on("metadataloaded", resolve, {
  934. once: true
  935. });
  936. });
  937. if (pdfDocument !== this.pdfDocument) {
  938. return null;
  939. }
  940. }
  941. if (!this._contentLength) {
  942. await new Promise(resolve => {
  943. this.eventBus._on("documentloaded", resolve, {
  944. once: true
  945. });
  946. });
  947. if (pdfDocument !== this.pdfDocument) {
  948. return null;
  949. }
  950. }
  951. return {
  952. ...this.documentInfo,
  953. baseURL: this.baseUrl,
  954. filesize: this._contentLength,
  955. filename: this._docFilename,
  956. metadata: this.metadata?.getRaw(),
  957. authors: this.metadata?.get("dc:creator"),
  958. numPages: this.pagesCount,
  959. URL: this.url
  960. };
  961. },
  962. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  963. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  964. if (pdfDocument !== this.pdfDocument) {
  965. return;
  966. }
  967. let triggerAutoPrint = false;
  968. if (openAction?.action === "Print") {
  969. triggerAutoPrint = true;
  970. }
  971. if (javaScript) {
  972. javaScript.some(js => {
  973. if (!js) {
  974. return false;
  975. }
  976. console.warn("Warning: JavaScript support is not enabled");
  977. return true;
  978. });
  979. if (!triggerAutoPrint) {
  980. for (const js of javaScript) {
  981. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  982. triggerAutoPrint = true;
  983. break;
  984. }
  985. }
  986. }
  987. }
  988. if (triggerAutoPrint) {
  989. this.triggerPrinting();
  990. }
  991. },
  992. async _initializeMetadata(pdfDocument) {
  993. const {
  994. info,
  995. metadata,
  996. contentDispositionFilename,
  997. contentLength
  998. } = await pdfDocument.getMetadata();
  999. if (pdfDocument !== this.pdfDocument) {
  1000. return;
  1001. }
  1002. this.documentInfo = info;
  1003. this.metadata = metadata;
  1004. this._contentDispositionFilename ??= contentDispositionFilename;
  1005. this._contentLength ??= contentLength;
  1006. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdf.version || "?"} [${_pdf.build || "?"}])`);
  1007. let pdfTitle = info.Title;
  1008. const metadataTitle = metadata?.get("dc:title");
  1009. if (metadataTitle) {
  1010. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1011. pdfTitle = metadataTitle;
  1012. }
  1013. }
  1014. if (pdfTitle) {
  1015. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  1016. } else if (this._contentDispositionFilename) {
  1017. this.setTitle(this._contentDispositionFilename);
  1018. }
  1019. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1020. if (pdfDocument.loadingParams.enableXfa) {
  1021. console.warn("Warning: XFA Foreground documents are not supported");
  1022. } else {
  1023. console.warn("Warning: XFA support is not enabled");
  1024. }
  1025. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  1026. console.warn("Warning: Interactive form support is not enabled");
  1027. }
  1028. if (info.IsSignaturesPresent) {
  1029. console.warn("Warning: Digital signatures validation is not supported");
  1030. }
  1031. this.eventBus.dispatch("metadataloaded", {
  1032. source: this
  1033. });
  1034. },
  1035. async _initializePageLabels(pdfDocument) {
  1036. const labels = await pdfDocument.getPageLabels();
  1037. if (pdfDocument !== this.pdfDocument) {
  1038. return;
  1039. }
  1040. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1041. return;
  1042. }
  1043. const numLabels = labels.length;
  1044. let standardLabels = 0,
  1045. emptyLabels = 0;
  1046. for (let i = 0; i < numLabels; i++) {
  1047. const label = labels[i];
  1048. if (label === (i + 1).toString()) {
  1049. standardLabels++;
  1050. } else if (label === "") {
  1051. emptyLabels++;
  1052. } else {
  1053. break;
  1054. }
  1055. }
  1056. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  1057. return;
  1058. }
  1059. const {
  1060. pdfViewer,
  1061. pdfThumbnailViewer,
  1062. toolbar
  1063. } = this;
  1064. pdfViewer.setPageLabels(labels);
  1065. pdfThumbnailViewer?.setPageLabels(labels);
  1066. toolbar?.setPagesCount(numLabels, true);
  1067. toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1068. },
  1069. _initializePdfHistory({
  1070. fingerprint,
  1071. viewOnLoad,
  1072. initialDest = null
  1073. }) {
  1074. if (!this.pdfHistory) {
  1075. return;
  1076. }
  1077. this.pdfHistory.initialize({
  1078. fingerprint,
  1079. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1080. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1081. });
  1082. if (this.pdfHistory.initialBookmark) {
  1083. this.initialBookmark = this.pdfHistory.initialBookmark;
  1084. this.initialRotation = this.pdfHistory.initialRotation;
  1085. }
  1086. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1087. this.initialBookmark = JSON.stringify(initialDest);
  1088. this.pdfHistory.push({
  1089. explicitDest: initialDest,
  1090. pageNumber: null
  1091. });
  1092. }
  1093. },
  1094. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1095. if (pdfDocument !== this.pdfDocument) {
  1096. return;
  1097. }
  1098. const {
  1099. annotationStorage
  1100. } = pdfDocument;
  1101. annotationStorage.onSetModified = () => {
  1102. window.addEventListener("beforeunload", beforeUnload);
  1103. this._annotationStorageModified = true;
  1104. };
  1105. annotationStorage.onResetModified = () => {
  1106. window.removeEventListener("beforeunload", beforeUnload);
  1107. delete this._annotationStorageModified;
  1108. };
  1109. annotationStorage.onAnnotationEditor = typeStr => {
  1110. this._hasAnnotationEditors = !!typeStr;
  1111. this.setTitle();
  1112. if (typeStr) {
  1113. this.externalServices.reportTelemetry({
  1114. type: "editing",
  1115. data: {
  1116. type: typeStr
  1117. }
  1118. });
  1119. }
  1120. };
  1121. },
  1122. setInitialView(storedHash, {
  1123. rotation,
  1124. sidebarView,
  1125. scrollMode,
  1126. spreadMode
  1127. } = {}) {
  1128. const setRotation = angle => {
  1129. if ((0, _ui_utils.isValidRotation)(angle)) {
  1130. this.pdfViewer.pagesRotation = angle;
  1131. }
  1132. };
  1133. const setViewerModes = (scroll, spread) => {
  1134. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1135. this.pdfViewer.scrollMode = scroll;
  1136. }
  1137. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1138. this.pdfViewer.spreadMode = spread;
  1139. }
  1140. };
  1141. this.isInitialViewSet = true;
  1142. this.pdfSidebar?.setInitialView(sidebarView);
  1143. setViewerModes(scrollMode, spreadMode);
  1144. if (this.initialBookmark) {
  1145. setRotation(this.initialRotation);
  1146. delete this.initialRotation;
  1147. this.pdfLinkService.setHash(this.initialBookmark);
  1148. this.initialBookmark = null;
  1149. } else if (storedHash) {
  1150. setRotation(rotation);
  1151. this.pdfLinkService.setHash(storedHash);
  1152. }
  1153. this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1154. this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
  1155. if (!this.pdfViewer.currentScaleValue) {
  1156. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1157. }
  1158. },
  1159. _cleanup() {
  1160. if (!this.pdfDocument) {
  1161. return;
  1162. }
  1163. this.pdfViewer.cleanup();
  1164. this.pdfThumbnailViewer?.cleanup();
  1165. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  1166. },
  1167. forceRendering() {
  1168. this.pdfRenderingQueue.printing = !!this.printService;
  1169. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS;
  1170. this.pdfRenderingQueue.renderHighestPriority();
  1171. },
  1172. beforePrint() {
  1173. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => {
  1174. return this.pdfDocument?.annotationStorage.print;
  1175. });
  1176. if (this.printService) {
  1177. return;
  1178. }
  1179. if (!this.supportsPrinting) {
  1180. this.l10n.get("printing_not_supported").then(msg => {
  1181. this._otherError(msg);
  1182. });
  1183. return;
  1184. }
  1185. if (!this.pdfViewer.pageViewsReady) {
  1186. this.l10n.get("printing_not_ready").then(msg => {
  1187. window.alert(msg);
  1188. });
  1189. return;
  1190. }
  1191. const pagesOverview = this.pdfViewer.getPagesOverview();
  1192. const printContainer = this.appConfig.printContainer;
  1193. const printResolution = _app_options.AppOptions.get("printResolution");
  1194. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1195. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n);
  1196. this.printService = printService;
  1197. this.forceRendering();
  1198. this.setTitle();
  1199. printService.layout();
  1200. if (this._hasAnnotationEditors) {
  1201. this.externalServices.reportTelemetry({
  1202. type: "editing",
  1203. data: {
  1204. type: "print"
  1205. }
  1206. });
  1207. }
  1208. },
  1209. afterPrint() {
  1210. if (this._printAnnotationStoragePromise) {
  1211. this._printAnnotationStoragePromise.then(() => {
  1212. this.pdfScriptingManager.dispatchDidPrint();
  1213. });
  1214. this._printAnnotationStoragePromise = null;
  1215. }
  1216. if (this.printService) {
  1217. this.printService.destroy();
  1218. this.printService = null;
  1219. this.pdfDocument?.annotationStorage.resetModified();
  1220. }
  1221. this.forceRendering();
  1222. this.setTitle();
  1223. },
  1224. rotatePages(delta) {
  1225. this.pdfViewer.pagesRotation += delta;
  1226. },
  1227. requestPresentationMode() {
  1228. this.pdfPresentationMode?.request();
  1229. },
  1230. triggerPrinting() {
  1231. if (!this.supportsPrinting) {
  1232. return;
  1233. }
  1234. window.print();
  1235. },
  1236. bindEvents() {
  1237. const {
  1238. eventBus,
  1239. _boundEvents
  1240. } = this;
  1241. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1242. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1243. eventBus._on("resize", webViewerResize);
  1244. eventBus._on("hashchange", webViewerHashchange);
  1245. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1246. eventBus._on("afterprint", _boundEvents.afterPrint);
  1247. eventBus._on("pagerender", webViewerPageRender);
  1248. eventBus._on("pagerendered", webViewerPageRendered);
  1249. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1250. eventBus._on("pagechanging", webViewerPageChanging);
  1251. eventBus._on("scalechanging", webViewerScaleChanging);
  1252. eventBus._on("rotationchanging", webViewerRotationChanging);
  1253. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1254. eventBus._on("pagemode", webViewerPageMode);
  1255. eventBus._on("namedaction", webViewerNamedAction);
  1256. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1257. eventBus._on("presentationmode", webViewerPresentationMode);
  1258. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
  1259. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
  1260. eventBus._on("print", webViewerPrint);
  1261. eventBus._on("download", webViewerDownload);
  1262. eventBus._on("firstpage", webViewerFirstPage);
  1263. eventBus._on("lastpage", webViewerLastPage);
  1264. eventBus._on("nextpage", webViewerNextPage);
  1265. eventBus._on("previouspage", webViewerPreviousPage);
  1266. eventBus._on("zoomin", webViewerZoomIn);
  1267. eventBus._on("zoomout", webViewerZoomOut);
  1268. eventBus._on("zoomreset", webViewerZoomReset);
  1269. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1270. eventBus._on("scalechanged", webViewerScaleChanged);
  1271. eventBus._on("rotatecw", webViewerRotateCw);
  1272. eventBus._on("rotateccw", webViewerRotateCcw);
  1273. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1274. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1275. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1276. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1277. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1278. eventBus._on("documentproperties", webViewerDocumentProperties);
  1279. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1280. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1281. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1282. if (_app_options.AppOptions.get("pdfBug")) {
  1283. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1284. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1285. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1286. }
  1287. eventBus._on("fileinputchange", webViewerFileInputChange);
  1288. eventBus._on("openfile", webViewerOpenFile);
  1289. },
  1290. bindWindowEvents() {
  1291. const {
  1292. eventBus,
  1293. _boundEvents
  1294. } = this;
  1295. function addWindowResolutionChange(evt = null) {
  1296. if (evt) {
  1297. webViewerResolutionChange(evt);
  1298. }
  1299. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  1300. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  1301. once: true
  1302. });
  1303. _boundEvents.removeWindowResolutionChange ||= function () {
  1304. mediaQueryList.removeEventListener("change", addWindowResolutionChange);
  1305. _boundEvents.removeWindowResolutionChange = null;
  1306. };
  1307. }
  1308. addWindowResolutionChange();
  1309. _boundEvents.windowResize = () => {
  1310. eventBus.dispatch("resize", {
  1311. source: window
  1312. });
  1313. };
  1314. _boundEvents.windowHashChange = () => {
  1315. eventBus.dispatch("hashchange", {
  1316. source: window,
  1317. hash: document.location.hash.substring(1)
  1318. });
  1319. };
  1320. _boundEvents.windowBeforePrint = () => {
  1321. eventBus.dispatch("beforeprint", {
  1322. source: window
  1323. });
  1324. };
  1325. _boundEvents.windowAfterPrint = () => {
  1326. eventBus.dispatch("afterprint", {
  1327. source: window
  1328. });
  1329. };
  1330. _boundEvents.windowUpdateFromSandbox = event => {
  1331. eventBus.dispatch("updatefromsandbox", {
  1332. source: window,
  1333. detail: event.detail
  1334. });
  1335. };
  1336. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1337. window.addEventListener("wheel", webViewerWheel, {
  1338. passive: false
  1339. });
  1340. window.addEventListener("touchstart", webViewerTouchStart, {
  1341. passive: false
  1342. });
  1343. window.addEventListener("click", webViewerClick);
  1344. window.addEventListener("keydown", webViewerKeyDown);
  1345. window.addEventListener("resize", _boundEvents.windowResize);
  1346. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1347. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1348. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1349. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1350. },
  1351. unbindEvents() {
  1352. const {
  1353. eventBus,
  1354. _boundEvents
  1355. } = this;
  1356. eventBus._off("resize", webViewerResize);
  1357. eventBus._off("hashchange", webViewerHashchange);
  1358. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1359. eventBus._off("afterprint", _boundEvents.afterPrint);
  1360. eventBus._off("pagerender", webViewerPageRender);
  1361. eventBus._off("pagerendered", webViewerPageRendered);
  1362. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1363. eventBus._off("pagechanging", webViewerPageChanging);
  1364. eventBus._off("scalechanging", webViewerScaleChanging);
  1365. eventBus._off("rotationchanging", webViewerRotationChanging);
  1366. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1367. eventBus._off("pagemode", webViewerPageMode);
  1368. eventBus._off("namedaction", webViewerNamedAction);
  1369. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1370. eventBus._off("presentationmode", webViewerPresentationMode);
  1371. eventBus._off("print", webViewerPrint);
  1372. eventBus._off("download", webViewerDownload);
  1373. eventBus._off("firstpage", webViewerFirstPage);
  1374. eventBus._off("lastpage", webViewerLastPage);
  1375. eventBus._off("nextpage", webViewerNextPage);
  1376. eventBus._off("previouspage", webViewerPreviousPage);
  1377. eventBus._off("zoomin", webViewerZoomIn);
  1378. eventBus._off("zoomout", webViewerZoomOut);
  1379. eventBus._off("zoomreset", webViewerZoomReset);
  1380. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1381. eventBus._off("scalechanged", webViewerScaleChanged);
  1382. eventBus._off("rotatecw", webViewerRotateCw);
  1383. eventBus._off("rotateccw", webViewerRotateCcw);
  1384. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1385. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1386. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1387. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1388. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1389. eventBus._off("documentproperties", webViewerDocumentProperties);
  1390. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1391. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1392. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1393. if (_boundEvents.reportPageStatsPDFBug) {
  1394. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1395. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1396. _boundEvents.reportPageStatsPDFBug = null;
  1397. }
  1398. eventBus._off("fileinputchange", webViewerFileInputChange);
  1399. eventBus._off("openfile", webViewerOpenFile);
  1400. _boundEvents.beforePrint = null;
  1401. _boundEvents.afterPrint = null;
  1402. },
  1403. unbindWindowEvents() {
  1404. const {
  1405. _boundEvents
  1406. } = this;
  1407. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1408. window.removeEventListener("wheel", webViewerWheel, {
  1409. passive: false
  1410. });
  1411. window.removeEventListener("touchstart", webViewerTouchStart, {
  1412. passive: false
  1413. });
  1414. window.removeEventListener("click", webViewerClick);
  1415. window.removeEventListener("keydown", webViewerKeyDown);
  1416. window.removeEventListener("resize", _boundEvents.windowResize);
  1417. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1418. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1419. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1420. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1421. _boundEvents.removeWindowResolutionChange?.();
  1422. _boundEvents.windowResize = null;
  1423. _boundEvents.windowHashChange = null;
  1424. _boundEvents.windowBeforePrint = null;
  1425. _boundEvents.windowAfterPrint = null;
  1426. _boundEvents.windowUpdateFromSandbox = null;
  1427. },
  1428. accumulateWheelTicks(ticks) {
  1429. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  1430. this._wheelUnusedTicks = 0;
  1431. }
  1432. this._wheelUnusedTicks += ticks;
  1433. const wholeTicks = Math.trunc(this._wheelUnusedTicks);
  1434. this._wheelUnusedTicks -= wholeTicks;
  1435. return wholeTicks;
  1436. },
  1437. _unblockDocumentLoadEvent() {
  1438. document.blockUnblockOnload?.(false);
  1439. this._unblockDocumentLoadEvent = () => {};
  1440. },
  1441. get scriptingReady() {
  1442. return this.pdfScriptingManager.ready;
  1443. }
  1444. };
  1445. exports.PDFViewerApplication = PDFViewerApplication;
  1446. {
  1447. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1448. var validateFileURL = function (file) {
  1449. if (!file) {
  1450. return;
  1451. }
  1452. try {
  1453. const viewerOrigin = new URL(window.location.href).origin || "null";
  1454. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1455. return;
  1456. }
  1457. const fileOrigin = new URL(file, window.location.href).origin;
  1458. if (fileOrigin !== viewerOrigin) {
  1459. throw new Error("file origin does not match viewer's");
  1460. }
  1461. } catch (ex) {
  1462. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1463. PDFViewerApplication._documentError(msg, {
  1464. message: ex?.message
  1465. });
  1466. });
  1467. throw ex;
  1468. }
  1469. };
  1470. }
  1471. async function loadFakeWorker() {
  1472. _pdf.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  1473. await (0, _pdf.loadScript)(_pdf.PDFWorker.workerSrc);
  1474. }
  1475. async function loadPDFBug(self) {
  1476. const {
  1477. debuggerScriptPath
  1478. } = self.appConfig;
  1479. const {
  1480. PDFBug
  1481. } = await import(debuggerScriptPath);
  1482. self._PDFBug = PDFBug;
  1483. }
  1484. function reportPageStatsPDFBug({
  1485. pageNumber
  1486. }) {
  1487. if (!globalThis.Stats?.enabled) {
  1488. return;
  1489. }
  1490. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1491. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  1492. }
  1493. function webViewerInitialized() {
  1494. const {
  1495. appConfig,
  1496. eventBus
  1497. } = PDFViewerApplication;
  1498. let file;
  1499. const queryString = document.location.search.substring(1);
  1500. const params = (0, _ui_utils.parseQueryString)(queryString);
  1501. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  1502. validateFileURL(file);
  1503. const fileInput = appConfig.openFileInput;
  1504. fileInput.value = null;
  1505. fileInput.addEventListener("change", function (evt) {
  1506. const {
  1507. files
  1508. } = evt.target;
  1509. if (!files || files.length === 0) {
  1510. return;
  1511. }
  1512. eventBus.dispatch("fileinputchange", {
  1513. source: this,
  1514. fileInput: evt.target
  1515. });
  1516. });
  1517. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1518. evt.preventDefault();
  1519. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  1520. });
  1521. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1522. evt.preventDefault();
  1523. const {
  1524. files
  1525. } = evt.dataTransfer;
  1526. if (!files || files.length === 0) {
  1527. return;
  1528. }
  1529. eventBus.dispatch("fileinputchange", {
  1530. source: this,
  1531. fileInput: evt.dataTransfer
  1532. });
  1533. });
  1534. if (!PDFViewerApplication.supportsDocumentFonts) {
  1535. _app_options.AppOptions.set("disableFontFace", true);
  1536. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  1537. console.warn(msg);
  1538. });
  1539. }
  1540. if (!PDFViewerApplication.supportsPrinting) {
  1541. appConfig.toolbar?.print.classList.add("hidden");
  1542. appConfig.secondaryToolbar?.printButton.classList.add("hidden");
  1543. }
  1544. if (!PDFViewerApplication.supportsFullscreen) {
  1545. appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden");
  1546. }
  1547. if (PDFViewerApplication.supportsIntegratedFind) {
  1548. appConfig.toolbar?.viewFind.classList.add("hidden");
  1549. }
  1550. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1551. if (evt.target === this) {
  1552. eventBus.dispatch("resize", {
  1553. source: this
  1554. });
  1555. }
  1556. }, true);
  1557. try {
  1558. if (file) {
  1559. PDFViewerApplication.open(file);
  1560. } else {
  1561. PDFViewerApplication._hideViewBookmark();
  1562. }
  1563. } catch (reason) {
  1564. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1565. PDFViewerApplication._documentError(msg, reason);
  1566. });
  1567. }
  1568. }
  1569. function webViewerPageRender({
  1570. pageNumber
  1571. }) {
  1572. if (pageNumber === PDFViewerApplication.page) {
  1573. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
  1574. }
  1575. }
  1576. function webViewerPageRendered({
  1577. pageNumber,
  1578. error
  1579. }) {
  1580. if (pageNumber === PDFViewerApplication.page) {
  1581. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false);
  1582. }
  1583. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  1584. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1585. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(pageNumber - 1);
  1586. if (pageView && thumbnailView) {
  1587. thumbnailView.setImage(pageView);
  1588. }
  1589. }
  1590. if (error) {
  1591. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1592. PDFViewerApplication._otherError(msg, error);
  1593. });
  1594. }
  1595. }
  1596. function webViewerPageMode({
  1597. mode
  1598. }) {
  1599. let view;
  1600. switch (mode) {
  1601. case "thumbs":
  1602. view = _ui_utils.SidebarView.THUMBS;
  1603. break;
  1604. case "bookmarks":
  1605. case "outline":
  1606. view = _ui_utils.SidebarView.OUTLINE;
  1607. break;
  1608. case "attachments":
  1609. view = _ui_utils.SidebarView.ATTACHMENTS;
  1610. break;
  1611. case "layers":
  1612. view = _ui_utils.SidebarView.LAYERS;
  1613. break;
  1614. case "none":
  1615. view = _ui_utils.SidebarView.NONE;
  1616. break;
  1617. default:
  1618. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1619. return;
  1620. }
  1621. PDFViewerApplication.pdfSidebar?.switchView(view, true);
  1622. }
  1623. function webViewerNamedAction(evt) {
  1624. switch (evt.action) {
  1625. case "GoToPage":
  1626. PDFViewerApplication.appConfig.toolbar?.pageNumber.select();
  1627. break;
  1628. case "Find":
  1629. if (!PDFViewerApplication.supportsIntegratedFind) {
  1630. PDFViewerApplication?.findBar.toggle();
  1631. }
  1632. break;
  1633. case "Print":
  1634. PDFViewerApplication.triggerPrinting();
  1635. break;
  1636. case "SaveAs":
  1637. PDFViewerApplication.downloadOrSave();
  1638. break;
  1639. }
  1640. }
  1641. function webViewerPresentationModeChanged(evt) {
  1642. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1643. }
  1644. function webViewerSidebarViewChanged({
  1645. view
  1646. }) {
  1647. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  1648. if (PDFViewerApplication.isInitialViewSet) {
  1649. PDFViewerApplication.store?.set("sidebarView", view).catch(() => {});
  1650. }
  1651. }
  1652. function webViewerUpdateViewarea({
  1653. location
  1654. }) {
  1655. if (PDFViewerApplication.isInitialViewSet) {
  1656. PDFViewerApplication.store?.setMultiple({
  1657. page: location.pageNumber,
  1658. zoom: location.scale,
  1659. scrollLeft: location.left,
  1660. scrollTop: location.top,
  1661. rotation: location.rotation
  1662. }).catch(() => {});
  1663. }
  1664. if (PDFViewerApplication.appConfig.secondaryToolbar) {
  1665. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1666. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1667. }
  1668. }
  1669. function webViewerScrollModeChanged(evt) {
  1670. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1671. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  1672. }
  1673. }
  1674. function webViewerSpreadModeChanged(evt) {
  1675. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1676. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  1677. }
  1678. }
  1679. function webViewerResize() {
  1680. const {
  1681. pdfDocument,
  1682. pdfViewer,
  1683. pdfRenderingQueue
  1684. } = PDFViewerApplication;
  1685. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  1686. return;
  1687. }
  1688. if (!pdfDocument) {
  1689. return;
  1690. }
  1691. const currentScaleValue = pdfViewer.currentScaleValue;
  1692. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  1693. pdfViewer.currentScaleValue = currentScaleValue;
  1694. }
  1695. pdfViewer.update();
  1696. }
  1697. function webViewerHashchange(evt) {
  1698. const hash = evt.hash;
  1699. if (!hash) {
  1700. return;
  1701. }
  1702. if (!PDFViewerApplication.isInitialViewSet) {
  1703. PDFViewerApplication.initialBookmark = hash;
  1704. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  1705. PDFViewerApplication.pdfLinkService.setHash(hash);
  1706. }
  1707. }
  1708. {
  1709. var webViewerFileInputChange = function (evt) {
  1710. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  1711. return;
  1712. }
  1713. const file = evt.fileInput.files[0];
  1714. let url = URL.createObjectURL(file);
  1715. if (file.name) {
  1716. url = {
  1717. url,
  1718. originalUrl: file.name
  1719. };
  1720. }
  1721. PDFViewerApplication.open(url);
  1722. };
  1723. var webViewerOpenFile = function (evt) {
  1724. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  1725. fileInput.click();
  1726. };
  1727. }
  1728. function webViewerPresentationMode() {
  1729. PDFViewerApplication.requestPresentationMode();
  1730. }
  1731. function webViewerSwitchAnnotationEditorMode(evt) {
  1732. PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
  1733. }
  1734. function webViewerSwitchAnnotationEditorParams(evt) {
  1735. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  1736. }
  1737. function webViewerPrint() {
  1738. PDFViewerApplication.triggerPrinting();
  1739. }
  1740. function webViewerDownload() {
  1741. PDFViewerApplication.downloadOrSave();
  1742. }
  1743. function webViewerFirstPage() {
  1744. if (PDFViewerApplication.pdfDocument) {
  1745. PDFViewerApplication.page = 1;
  1746. }
  1747. }
  1748. function webViewerLastPage() {
  1749. if (PDFViewerApplication.pdfDocument) {
  1750. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1751. }
  1752. }
  1753. function webViewerNextPage() {
  1754. PDFViewerApplication.pdfViewer.nextPage();
  1755. }
  1756. function webViewerPreviousPage() {
  1757. PDFViewerApplication.pdfViewer.previousPage();
  1758. }
  1759. function webViewerZoomIn() {
  1760. PDFViewerApplication.zoomIn();
  1761. }
  1762. function webViewerZoomOut() {
  1763. PDFViewerApplication.zoomOut();
  1764. }
  1765. function webViewerZoomReset() {
  1766. PDFViewerApplication.zoomReset();
  1767. }
  1768. function webViewerPageNumberChanged(evt) {
  1769. const pdfViewer = PDFViewerApplication.pdfViewer;
  1770. if (evt.value !== "") {
  1771. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  1772. }
  1773. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1774. PDFViewerApplication.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1775. }
  1776. }
  1777. function webViewerScaleChanged(evt) {
  1778. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1779. }
  1780. function webViewerRotateCw() {
  1781. PDFViewerApplication.rotatePages(90);
  1782. }
  1783. function webViewerRotateCcw() {
  1784. PDFViewerApplication.rotatePages(-90);
  1785. }
  1786. function webViewerOptionalContentConfig(evt) {
  1787. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  1788. }
  1789. function webViewerSwitchScrollMode(evt) {
  1790. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  1791. }
  1792. function webViewerSwitchSpreadMode(evt) {
  1793. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  1794. }
  1795. function webViewerDocumentProperties() {
  1796. PDFViewerApplication.pdfDocumentProperties?.open();
  1797. }
  1798. function webViewerFindFromUrlHash(evt) {
  1799. PDFViewerApplication.eventBus.dispatch("find", {
  1800. source: evt.source,
  1801. type: "",
  1802. query: evt.query,
  1803. phraseSearch: evt.phraseSearch,
  1804. caseSensitive: false,
  1805. entireWord: false,
  1806. highlightAll: true,
  1807. findPrevious: false,
  1808. matchDiacritics: true
  1809. });
  1810. }
  1811. function webViewerUpdateFindMatchesCount({
  1812. matchesCount
  1813. }) {
  1814. if (PDFViewerApplication.supportsIntegratedFind) {
  1815. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  1816. } else {
  1817. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  1818. }
  1819. }
  1820. function webViewerUpdateFindControlState({
  1821. state,
  1822. previous,
  1823. matchesCount,
  1824. rawQuery
  1825. }) {
  1826. if (PDFViewerApplication.supportsIntegratedFind) {
  1827. PDFViewerApplication.externalServices.updateFindControlState({
  1828. result: state,
  1829. findPrevious: previous,
  1830. matchesCount,
  1831. rawQuery
  1832. });
  1833. } else {
  1834. PDFViewerApplication.findBar?.updateUIState(state, previous, matchesCount);
  1835. }
  1836. }
  1837. function webViewerScaleChanging(evt) {
  1838. PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale);
  1839. PDFViewerApplication.pdfViewer.update();
  1840. }
  1841. function webViewerRotationChanging(evt) {
  1842. if (PDFViewerApplication.pdfThumbnailViewer) {
  1843. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  1844. }
  1845. PDFViewerApplication.forceRendering();
  1846. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  1847. }
  1848. function webViewerPageChanging({
  1849. pageNumber,
  1850. pageLabel
  1851. }) {
  1852. PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel);
  1853. PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber);
  1854. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  1855. PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber);
  1856. }
  1857. const currentPage = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1858. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === _ui_utils.RenderingStates.RUNNING);
  1859. }
  1860. function webViewerResolutionChange(evt) {
  1861. PDFViewerApplication.pdfViewer.refresh();
  1862. }
  1863. function webViewerVisibilityChange(evt) {
  1864. if (document.visibilityState === "visible") {
  1865. setZoomDisabledTimeout();
  1866. }
  1867. }
  1868. let zoomDisabledTimeout = null;
  1869. function setZoomDisabledTimeout() {
  1870. if (zoomDisabledTimeout) {
  1871. clearTimeout(zoomDisabledTimeout);
  1872. }
  1873. zoomDisabledTimeout = setTimeout(function () {
  1874. zoomDisabledTimeout = null;
  1875. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  1876. }
  1877. function webViewerWheel(evt) {
  1878. const {
  1879. pdfViewer,
  1880. supportedMouseWheelZoomModifierKeys
  1881. } = PDFViewerApplication;
  1882. if (pdfViewer.isInPresentationMode) {
  1883. return;
  1884. }
  1885. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  1886. evt.preventDefault();
  1887. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  1888. return;
  1889. }
  1890. const deltaMode = evt.deltaMode;
  1891. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  1892. const previousScale = pdfViewer.currentScale;
  1893. let ticks = 0;
  1894. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  1895. if (Math.abs(delta) >= 1) {
  1896. ticks = Math.sign(delta);
  1897. } else {
  1898. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  1899. }
  1900. } else {
  1901. const PIXELS_PER_LINE_SCALE = 30;
  1902. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  1903. }
  1904. if (ticks < 0) {
  1905. PDFViewerApplication.zoomOut(-ticks);
  1906. } else if (ticks > 0) {
  1907. PDFViewerApplication.zoomIn(ticks);
  1908. }
  1909. const currentScale = pdfViewer.currentScale;
  1910. if (previousScale !== currentScale) {
  1911. const scaleCorrectionFactor = currentScale / previousScale - 1;
  1912. const [top, left] = pdfViewer.containerTopLeft;
  1913. const dx = evt.clientX - left;
  1914. const dy = evt.clientY - top;
  1915. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  1916. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  1917. }
  1918. } else {
  1919. setZoomDisabledTimeout();
  1920. }
  1921. }
  1922. function webViewerTouchStart(evt) {
  1923. if (evt.touches.length > 1) {
  1924. evt.preventDefault();
  1925. }
  1926. }
  1927. function webViewerClick(evt) {
  1928. if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
  1929. return;
  1930. }
  1931. const appConfig = PDFViewerApplication.appConfig;
  1932. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar?.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar?.toggleButton) {
  1933. PDFViewerApplication.secondaryToolbar.close();
  1934. }
  1935. }
  1936. function webViewerKeyDown(evt) {
  1937. if (PDFViewerApplication.overlayManager.active) {
  1938. return;
  1939. }
  1940. const {
  1941. eventBus,
  1942. pdfViewer
  1943. } = PDFViewerApplication;
  1944. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  1945. let handled = false,
  1946. ensureViewerFocused = false;
  1947. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  1948. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  1949. switch (evt.keyCode) {
  1950. case 70:
  1951. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  1952. PDFViewerApplication.findBar?.open();
  1953. handled = true;
  1954. }
  1955. break;
  1956. case 71:
  1957. if (!PDFViewerApplication.supportsIntegratedFind) {
  1958. const {
  1959. state
  1960. } = PDFViewerApplication.findController;
  1961. if (state) {
  1962. const eventState = Object.assign(Object.create(null), state, {
  1963. source: window,
  1964. type: "again",
  1965. findPrevious: cmd === 5 || cmd === 12
  1966. });
  1967. eventBus.dispatch("find", eventState);
  1968. }
  1969. handled = true;
  1970. }
  1971. break;
  1972. case 61:
  1973. case 107:
  1974. case 187:
  1975. case 171:
  1976. if (!isViewerInPresentationMode) {
  1977. PDFViewerApplication.zoomIn();
  1978. }
  1979. handled = true;
  1980. break;
  1981. case 173:
  1982. case 109:
  1983. case 189:
  1984. if (!isViewerInPresentationMode) {
  1985. PDFViewerApplication.zoomOut();
  1986. }
  1987. handled = true;
  1988. break;
  1989. case 48:
  1990. case 96:
  1991. if (!isViewerInPresentationMode) {
  1992. setTimeout(function () {
  1993. PDFViewerApplication.zoomReset();
  1994. });
  1995. handled = false;
  1996. }
  1997. break;
  1998. case 38:
  1999. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2000. PDFViewerApplication.page = 1;
  2001. handled = true;
  2002. ensureViewerFocused = true;
  2003. }
  2004. break;
  2005. case 40:
  2006. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2007. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2008. handled = true;
  2009. ensureViewerFocused = true;
  2010. }
  2011. break;
  2012. }
  2013. }
  2014. if (cmd === 1 || cmd === 8) {
  2015. switch (evt.keyCode) {
  2016. case 83:
  2017. eventBus.dispatch("download", {
  2018. source: window
  2019. });
  2020. handled = true;
  2021. break;
  2022. case 79:
  2023. {
  2024. eventBus.dispatch("openfile", {
  2025. source: window
  2026. });
  2027. handled = true;
  2028. }
  2029. break;
  2030. }
  2031. }
  2032. if (cmd === 3 || cmd === 10) {
  2033. switch (evt.keyCode) {
  2034. case 80:
  2035. PDFViewerApplication.requestPresentationMode();
  2036. handled = true;
  2037. PDFViewerApplication.externalServices.reportTelemetry({
  2038. type: "buttons",
  2039. data: {
  2040. id: "presentationModeKeyboard"
  2041. }
  2042. });
  2043. break;
  2044. case 71:
  2045. if (PDFViewerApplication.appConfig.toolbar) {
  2046. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2047. handled = true;
  2048. }
  2049. break;
  2050. }
  2051. }
  2052. if (handled) {
  2053. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2054. pdfViewer.focus();
  2055. }
  2056. evt.preventDefault();
  2057. return;
  2058. }
  2059. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2060. const curElementTagName = curElement?.tagName.toUpperCase();
  2061. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2062. if (evt.keyCode !== 27) {
  2063. return;
  2064. }
  2065. }
  2066. if (cmd === 0) {
  2067. let turnPage = 0,
  2068. turnOnlyIfPageFit = false;
  2069. switch (evt.keyCode) {
  2070. case 38:
  2071. case 33:
  2072. if (pdfViewer.isVerticalScrollbarEnabled) {
  2073. turnOnlyIfPageFit = true;
  2074. }
  2075. turnPage = -1;
  2076. break;
  2077. case 8:
  2078. if (!isViewerInPresentationMode) {
  2079. turnOnlyIfPageFit = true;
  2080. }
  2081. turnPage = -1;
  2082. break;
  2083. case 37:
  2084. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2085. turnOnlyIfPageFit = true;
  2086. }
  2087. case 75:
  2088. case 80:
  2089. turnPage = -1;
  2090. break;
  2091. case 27:
  2092. if (PDFViewerApplication.secondaryToolbar?.isOpen) {
  2093. PDFViewerApplication.secondaryToolbar.close();
  2094. handled = true;
  2095. }
  2096. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar?.opened) {
  2097. PDFViewerApplication.findBar.close();
  2098. handled = true;
  2099. }
  2100. break;
  2101. case 40:
  2102. case 34:
  2103. if (pdfViewer.isVerticalScrollbarEnabled) {
  2104. turnOnlyIfPageFit = true;
  2105. }
  2106. turnPage = 1;
  2107. break;
  2108. case 13:
  2109. case 32:
  2110. if (!isViewerInPresentationMode) {
  2111. turnOnlyIfPageFit = true;
  2112. }
  2113. turnPage = 1;
  2114. break;
  2115. case 39:
  2116. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2117. turnOnlyIfPageFit = true;
  2118. }
  2119. case 74:
  2120. case 78:
  2121. turnPage = 1;
  2122. break;
  2123. case 36:
  2124. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2125. PDFViewerApplication.page = 1;
  2126. handled = true;
  2127. ensureViewerFocused = true;
  2128. }
  2129. break;
  2130. case 35:
  2131. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2132. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2133. handled = true;
  2134. ensureViewerFocused = true;
  2135. }
  2136. break;
  2137. case 83:
  2138. PDFViewerApplication.pdfCursorTools?.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2139. break;
  2140. case 72:
  2141. PDFViewerApplication.pdfCursorTools?.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2142. break;
  2143. case 82:
  2144. PDFViewerApplication.rotatePages(90);
  2145. break;
  2146. case 115:
  2147. PDFViewerApplication.pdfSidebar?.toggle();
  2148. break;
  2149. }
  2150. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2151. if (turnPage > 0) {
  2152. pdfViewer.nextPage();
  2153. } else {
  2154. pdfViewer.previousPage();
  2155. }
  2156. handled = true;
  2157. }
  2158. }
  2159. if (cmd === 4) {
  2160. switch (evt.keyCode) {
  2161. case 13:
  2162. case 32:
  2163. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2164. break;
  2165. }
  2166. pdfViewer.previousPage();
  2167. handled = true;
  2168. break;
  2169. case 82:
  2170. PDFViewerApplication.rotatePages(-90);
  2171. break;
  2172. }
  2173. }
  2174. if (!handled && !isViewerInPresentationMode) {
  2175. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2176. ensureViewerFocused = true;
  2177. }
  2178. }
  2179. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2180. pdfViewer.focus();
  2181. }
  2182. if (handled) {
  2183. evt.preventDefault();
  2184. }
  2185. }
  2186. function beforeUnload(evt) {
  2187. evt.preventDefault();
  2188. evt.returnValue = "";
  2189. return false;
  2190. }
  2191. function webViewerAnnotationEditorStatesChanged(data) {
  2192. PDFViewerApplication.externalServices.updateEditorStates(data);
  2193. }
  2194. const PDFPrintServiceFactory = {
  2195. instance: {
  2196. supportsPrinting: false,
  2197. createPrintService() {
  2198. throw new Error("Not implemented: createPrintService");
  2199. }
  2200. }
  2201. };
  2202. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;