app.js 76 KB

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