2
0

app.js 75 KB

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