app.js 74 KB

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