app.js 73 KB

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