app.js 75 KB

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