pdf_viewer.js 121 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. (function webpackUniversalModuleDefinition(root, factory) {
  16. if(typeof exports === 'object' && typeof module === 'object')
  17. module.exports = factory();
  18. else if(typeof define === 'function' && define.amd)
  19. define("pdfjs-dist/web/pdf_viewer", [], factory);
  20. else if(typeof exports === 'object')
  21. exports["pdfjs-dist/web/pdf_viewer"] = factory();
  22. else
  23. root["pdfjs-dist/web/pdf_viewer"] = root.pdfjsDistWebPdfViewer = factory();
  24. })(this, function() {
  25. return /******/ (function(modules) { // webpackBootstrap
  26. /******/ // The module cache
  27. /******/ var installedModules = {};
  28. /******/
  29. /******/ // The require function
  30. /******/ function __w_pdfjs_require__(moduleId) {
  31. /******/
  32. /******/ // Check if module is in cache
  33. /******/ if(installedModules[moduleId]) {
  34. /******/ return installedModules[moduleId].exports;
  35. /******/ }
  36. /******/ // Create a new module (and put it into the cache)
  37. /******/ var module = installedModules[moduleId] = {
  38. /******/ i: moduleId,
  39. /******/ l: false,
  40. /******/ exports: {}
  41. /******/ };
  42. /******/
  43. /******/ // Execute the module function
  44. /******/ modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__);
  45. /******/
  46. /******/ // Flag the module as loaded
  47. /******/ module.l = true;
  48. /******/
  49. /******/ // Return the exports of the module
  50. /******/ return module.exports;
  51. /******/ }
  52. /******/
  53. /******/
  54. /******/ // expose the modules object (__webpack_modules__)
  55. /******/ __w_pdfjs_require__.m = modules;
  56. /******/
  57. /******/ // expose the module cache
  58. /******/ __w_pdfjs_require__.c = installedModules;
  59. /******/
  60. /******/ // identity function for calling harmony imports with the correct context
  61. /******/ __w_pdfjs_require__.i = function(value) { return value; };
  62. /******/
  63. /******/ // define getter function for harmony exports
  64. /******/ __w_pdfjs_require__.d = function(exports, name, getter) {
  65. /******/ if(!__w_pdfjs_require__.o(exports, name)) {
  66. /******/ Object.defineProperty(exports, name, {
  67. /******/ configurable: false,
  68. /******/ enumerable: true,
  69. /******/ get: getter
  70. /******/ });
  71. /******/ }
  72. /******/ };
  73. /******/
  74. /******/ // getDefaultExport function for compatibility with non-harmony modules
  75. /******/ __w_pdfjs_require__.n = function(module) {
  76. /******/ var getter = module && module.__esModule ?
  77. /******/ function getDefault() { return module['default']; } :
  78. /******/ function getModuleExports() { return module; };
  79. /******/ __w_pdfjs_require__.d(getter, 'a', getter);
  80. /******/ return getter;
  81. /******/ };
  82. /******/
  83. /******/ // Object.prototype.hasOwnProperty.call
  84. /******/ __w_pdfjs_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  85. /******/
  86. /******/ // __webpack_public_path__
  87. /******/ __w_pdfjs_require__.p = "";
  88. /******/
  89. /******/ // Load entry module and return exports
  90. /******/ return __w_pdfjs_require__(__w_pdfjs_require__.s = 12);
  91. /******/ })
  92. /************************************************************************/
  93. /******/ ([
  94. /* 0 */
  95. /***/ (function(module, exports, __w_pdfjs_require__) {
  96. "use strict";
  97. var pdfjsLib;
  98. if (typeof __pdfjsdev_webpack__ === 'undefined') {
  99. if (typeof window !== 'undefined' && window['pdfjs-dist/build/pdf']) {
  100. pdfjsLib = window['pdfjs-dist/build/pdf'];
  101. } else if (typeof require === 'function') {
  102. pdfjsLib = require('../build/pdf.js');
  103. } else {
  104. throw new Error('Neither `require` nor `window` found');
  105. }
  106. }
  107. module.exports = pdfjsLib;
  108. /***/ }),
  109. /* 1 */
  110. /***/ (function(module, exports, __w_pdfjs_require__) {
  111. "use strict";
  112. Object.defineProperty(exports, "__esModule", {
  113. value: true
  114. });
  115. exports.localized = exports.animationStarted = exports.normalizeWheelEventDelta = exports.binarySearchFirstItem = exports.watchScroll = exports.scrollIntoView = exports.getOutputScale = exports.approximateFraction = exports.roundToDivide = exports.getVisibleElements = exports.parseQueryString = exports.noContextMenuHandler = exports.getPDFFileNameFromURL = exports.ProgressBar = exports.EventBus = exports.mozL10n = exports.RendererType = exports.cloneObj = exports.VERTICAL_PADDING = exports.SCROLLBAR_PADDING = exports.MAX_AUTO_SCALE = exports.UNKNOWN_SCALE = exports.MAX_SCALE = exports.MIN_SCALE = exports.DEFAULT_SCALE = exports.DEFAULT_SCALE_VALUE = exports.CSS_UNITS = undefined;
  116. var _pdfjsLib = __w_pdfjs_require__(0);
  117. var CSS_UNITS = 96.0 / 72.0;
  118. var DEFAULT_SCALE_VALUE = 'auto';
  119. var DEFAULT_SCALE = 1.0;
  120. var MIN_SCALE = 0.25;
  121. var MAX_SCALE = 10.0;
  122. var UNKNOWN_SCALE = 0;
  123. var MAX_AUTO_SCALE = 1.25;
  124. var SCROLLBAR_PADDING = 40;
  125. var VERTICAL_PADDING = 5;
  126. var RendererType = {
  127. CANVAS: 'canvas',
  128. SVG: 'svg'
  129. };
  130. var mozL10n = typeof document !== 'undefined' ? document.mozL10n || document.webL10n : undefined;
  131. _pdfjsLib.PDFJS.disableFullscreen = _pdfjsLib.PDFJS.disableFullscreen === undefined ? false : _pdfjsLib.PDFJS.disableFullscreen;
  132. _pdfjsLib.PDFJS.useOnlyCssZoom = _pdfjsLib.PDFJS.useOnlyCssZoom === undefined ? false : _pdfjsLib.PDFJS.useOnlyCssZoom;
  133. _pdfjsLib.PDFJS.maxCanvasPixels = _pdfjsLib.PDFJS.maxCanvasPixels === undefined ? 16777216 : _pdfjsLib.PDFJS.maxCanvasPixels;
  134. _pdfjsLib.PDFJS.disableHistory = _pdfjsLib.PDFJS.disableHistory === undefined ? false : _pdfjsLib.PDFJS.disableHistory;
  135. _pdfjsLib.PDFJS.disableTextLayer = _pdfjsLib.PDFJS.disableTextLayer === undefined ? false : _pdfjsLib.PDFJS.disableTextLayer;
  136. _pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom = _pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom === undefined ? false : _pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom;
  137. {
  138. _pdfjsLib.PDFJS.locale = _pdfjsLib.PDFJS.locale === undefined && typeof navigator !== 'undefined' ? navigator.language : _pdfjsLib.PDFJS.locale;
  139. }
  140. function getOutputScale(ctx) {
  141. var devicePixelRatio = window.devicePixelRatio || 1;
  142. var backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  143. var pixelRatio = devicePixelRatio / backingStoreRatio;
  144. return {
  145. sx: pixelRatio,
  146. sy: pixelRatio,
  147. scaled: pixelRatio !== 1
  148. };
  149. }
  150. function scrollIntoView(element, spot, skipOverflowHiddenElements) {
  151. var parent = element.offsetParent;
  152. if (!parent) {
  153. console.error('offsetParent is not set -- cannot scroll');
  154. return;
  155. }
  156. var checkOverflow = skipOverflowHiddenElements || false;
  157. var offsetY = element.offsetTop + element.clientTop;
  158. var offsetX = element.offsetLeft + element.clientLeft;
  159. while (parent.clientHeight === parent.scrollHeight || checkOverflow && getComputedStyle(parent).overflow === 'hidden') {
  160. if (parent.dataset._scaleY) {
  161. offsetY /= parent.dataset._scaleY;
  162. offsetX /= parent.dataset._scaleX;
  163. }
  164. offsetY += parent.offsetTop;
  165. offsetX += parent.offsetLeft;
  166. parent = parent.offsetParent;
  167. if (!parent) {
  168. return;
  169. }
  170. }
  171. if (spot) {
  172. if (spot.top !== undefined) {
  173. offsetY += spot.top;
  174. }
  175. if (spot.left !== undefined) {
  176. offsetX += spot.left;
  177. parent.scrollLeft = offsetX;
  178. }
  179. }
  180. parent.scrollTop = offsetY;
  181. }
  182. function watchScroll(viewAreaElement, callback) {
  183. var debounceScroll = function debounceScroll(evt) {
  184. if (rAF) {
  185. return;
  186. }
  187. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  188. rAF = null;
  189. var currentY = viewAreaElement.scrollTop;
  190. var lastY = state.lastY;
  191. if (currentY !== lastY) {
  192. state.down = currentY > lastY;
  193. }
  194. state.lastY = currentY;
  195. callback(state);
  196. });
  197. };
  198. var state = {
  199. down: true,
  200. lastY: viewAreaElement.scrollTop,
  201. _eventHandler: debounceScroll
  202. };
  203. var rAF = null;
  204. viewAreaElement.addEventListener('scroll', debounceScroll, true);
  205. return state;
  206. }
  207. function parseQueryString(query) {
  208. var parts = query.split('&');
  209. var params = {};
  210. for (var i = 0, ii = parts.length; i < ii; ++i) {
  211. var param = parts[i].split('=');
  212. var key = param[0].toLowerCase();
  213. var value = param.length > 1 ? param[1] : null;
  214. params[decodeURIComponent(key)] = decodeURIComponent(value);
  215. }
  216. return params;
  217. }
  218. function binarySearchFirstItem(items, condition) {
  219. var minIndex = 0;
  220. var maxIndex = items.length - 1;
  221. if (items.length === 0 || !condition(items[maxIndex])) {
  222. return items.length;
  223. }
  224. if (condition(items[minIndex])) {
  225. return minIndex;
  226. }
  227. while (minIndex < maxIndex) {
  228. var currentIndex = minIndex + maxIndex >> 1;
  229. var currentItem = items[currentIndex];
  230. if (condition(currentItem)) {
  231. maxIndex = currentIndex;
  232. } else {
  233. minIndex = currentIndex + 1;
  234. }
  235. }
  236. return minIndex;
  237. }
  238. function approximateFraction(x) {
  239. if (Math.floor(x) === x) {
  240. return [x, 1];
  241. }
  242. var xinv = 1 / x;
  243. var limit = 8;
  244. if (xinv > limit) {
  245. return [1, limit];
  246. } else if (Math.floor(xinv) === xinv) {
  247. return [1, xinv];
  248. }
  249. var x_ = x > 1 ? xinv : x;
  250. var a = 0,
  251. b = 1,
  252. c = 1,
  253. d = 1;
  254. while (true) {
  255. var p = a + c,
  256. q = b + d;
  257. if (q > limit) {
  258. break;
  259. }
  260. if (x_ <= p / q) {
  261. c = p;
  262. d = q;
  263. } else {
  264. a = p;
  265. b = q;
  266. }
  267. }
  268. var result;
  269. if (x_ - a / b < c / d - x_) {
  270. result = x_ === x ? [a, b] : [b, a];
  271. } else {
  272. result = x_ === x ? [c, d] : [d, c];
  273. }
  274. return result;
  275. }
  276. function roundToDivide(x, div) {
  277. var r = x % div;
  278. return r === 0 ? x : Math.round(x - r + div);
  279. }
  280. function getVisibleElements(scrollEl, views, sortByVisibility) {
  281. var top = scrollEl.scrollTop,
  282. bottom = top + scrollEl.clientHeight;
  283. var left = scrollEl.scrollLeft,
  284. right = left + scrollEl.clientWidth;
  285. function isElementBottomBelowViewTop(view) {
  286. var element = view.div;
  287. var elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  288. return elementBottom > top;
  289. }
  290. var visible = [],
  291. view,
  292. element;
  293. var currentHeight, viewHeight, hiddenHeight, percentHeight;
  294. var currentWidth, viewWidth;
  295. var firstVisibleElementInd = views.length === 0 ? 0 : binarySearchFirstItem(views, isElementBottomBelowViewTop);
  296. for (var i = firstVisibleElementInd, ii = views.length; i < ii; i++) {
  297. view = views[i];
  298. element = view.div;
  299. currentHeight = element.offsetTop + element.clientTop;
  300. viewHeight = element.clientHeight;
  301. if (currentHeight > bottom) {
  302. break;
  303. }
  304. currentWidth = element.offsetLeft + element.clientLeft;
  305. viewWidth = element.clientWidth;
  306. if (currentWidth + viewWidth < left || currentWidth > right) {
  307. continue;
  308. }
  309. hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, currentHeight + viewHeight - bottom);
  310. percentHeight = (viewHeight - hiddenHeight) * 100 / viewHeight | 0;
  311. visible.push({
  312. id: view.id,
  313. x: currentWidth,
  314. y: currentHeight,
  315. view: view,
  316. percent: percentHeight
  317. });
  318. }
  319. var first = visible[0];
  320. var last = visible[visible.length - 1];
  321. if (sortByVisibility) {
  322. visible.sort(function (a, b) {
  323. var pc = a.percent - b.percent;
  324. if (Math.abs(pc) > 0.001) {
  325. return -pc;
  326. }
  327. return a.id - b.id;
  328. });
  329. }
  330. return {
  331. first: first,
  332. last: last,
  333. views: visible
  334. };
  335. }
  336. function noContextMenuHandler(e) {
  337. e.preventDefault();
  338. }
  339. function isDataSchema(url) {
  340. var i = 0,
  341. ii = url.length;
  342. while (i < ii && url[i].trim() === '') {
  343. i++;
  344. }
  345. return url.substr(i, 5).toLowerCase() === 'data:';
  346. }
  347. function getPDFFileNameFromURL(url) {
  348. var defaultFilename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'document.pdf';
  349. if (isDataSchema(url)) {
  350. console.warn('getPDFFileNameFromURL: ' + 'ignoring "data:" URL for performance reasons.');
  351. return defaultFilename;
  352. }
  353. var reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  354. var reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  355. var splitURI = reURI.exec(url);
  356. var suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  357. if (suggestedFilename) {
  358. suggestedFilename = suggestedFilename[0];
  359. if (suggestedFilename.indexOf('%') !== -1) {
  360. try {
  361. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  362. } catch (e) {}
  363. }
  364. }
  365. return suggestedFilename || defaultFilename;
  366. }
  367. function normalizeWheelEventDelta(evt) {
  368. var delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY);
  369. var angle = Math.atan2(evt.deltaY, evt.deltaX);
  370. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  371. delta = -delta;
  372. }
  373. var MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  374. var MOUSE_DOM_DELTA_LINE_MODE = 1;
  375. var MOUSE_PIXELS_PER_LINE = 30;
  376. var MOUSE_LINES_PER_PAGE = 30;
  377. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  378. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  379. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  380. delta /= MOUSE_LINES_PER_PAGE;
  381. }
  382. return delta;
  383. }
  384. function cloneObj(obj) {
  385. var result = {};
  386. for (var i in obj) {
  387. if (Object.prototype.hasOwnProperty.call(obj, i)) {
  388. result[i] = obj[i];
  389. }
  390. }
  391. return result;
  392. }
  393. var animationStarted = new Promise(function (resolve) {
  394. window.requestAnimationFrame(resolve);
  395. });
  396. var localized = new Promise(function (resolve, reject) {
  397. if (!mozL10n) {
  398. resolve();
  399. return;
  400. }
  401. if (mozL10n.getReadyState() !== 'loading') {
  402. resolve();
  403. return;
  404. }
  405. window.addEventListener('localized', function localized(evt) {
  406. resolve();
  407. });
  408. });
  409. var EventBus = function EventBusClosure() {
  410. function EventBus() {
  411. this._listeners = Object.create(null);
  412. }
  413. EventBus.prototype = {
  414. on: function EventBus_on(eventName, listener) {
  415. var eventListeners = this._listeners[eventName];
  416. if (!eventListeners) {
  417. eventListeners = [];
  418. this._listeners[eventName] = eventListeners;
  419. }
  420. eventListeners.push(listener);
  421. },
  422. off: function EventBus_on(eventName, listener) {
  423. var eventListeners = this._listeners[eventName];
  424. var i;
  425. if (!eventListeners || (i = eventListeners.indexOf(listener)) < 0) {
  426. return;
  427. }
  428. eventListeners.splice(i, 1);
  429. },
  430. dispatch: function EventBus_dispath(eventName) {
  431. var eventListeners = this._listeners[eventName];
  432. if (!eventListeners || eventListeners.length === 0) {
  433. return;
  434. }
  435. var args = Array.prototype.slice.call(arguments, 1);
  436. eventListeners.slice(0).forEach(function (listener) {
  437. listener.apply(null, args);
  438. });
  439. }
  440. };
  441. return EventBus;
  442. }();
  443. var ProgressBar = function ProgressBarClosure() {
  444. function clamp(v, min, max) {
  445. return Math.min(Math.max(v, min), max);
  446. }
  447. function ProgressBar(id, opts) {
  448. this.visible = true;
  449. this.div = document.querySelector(id + ' .progress');
  450. this.bar = this.div.parentNode;
  451. this.height = opts.height || 100;
  452. this.width = opts.width || 100;
  453. this.units = opts.units || '%';
  454. this.div.style.height = this.height + this.units;
  455. this.percent = 0;
  456. }
  457. ProgressBar.prototype = {
  458. updateBar: function ProgressBar_updateBar() {
  459. if (this._indeterminate) {
  460. this.div.classList.add('indeterminate');
  461. this.div.style.width = this.width + this.units;
  462. return;
  463. }
  464. this.div.classList.remove('indeterminate');
  465. var progressSize = this.width * this._percent / 100;
  466. this.div.style.width = progressSize + this.units;
  467. },
  468. get percent() {
  469. return this._percent;
  470. },
  471. set percent(val) {
  472. this._indeterminate = isNaN(val);
  473. this._percent = clamp(val, 0, 100);
  474. this.updateBar();
  475. },
  476. setWidth: function ProgressBar_setWidth(viewer) {
  477. if (viewer) {
  478. var container = viewer.parentNode;
  479. var scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  480. if (scrollbarWidth > 0) {
  481. this.bar.setAttribute('style', 'width: calc(100% - ' + scrollbarWidth + 'px);');
  482. }
  483. }
  484. },
  485. hide: function ProgressBar_hide() {
  486. if (!this.visible) {
  487. return;
  488. }
  489. this.visible = false;
  490. this.bar.classList.add('hidden');
  491. document.body.classList.remove('loadingInProgress');
  492. },
  493. show: function ProgressBar_show() {
  494. if (this.visible) {
  495. return;
  496. }
  497. this.visible = true;
  498. document.body.classList.add('loadingInProgress');
  499. this.bar.classList.remove('hidden');
  500. }
  501. };
  502. return ProgressBar;
  503. }();
  504. exports.CSS_UNITS = CSS_UNITS;
  505. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  506. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  507. exports.MIN_SCALE = MIN_SCALE;
  508. exports.MAX_SCALE = MAX_SCALE;
  509. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  510. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  511. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  512. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  513. exports.cloneObj = cloneObj;
  514. exports.RendererType = RendererType;
  515. exports.mozL10n = mozL10n;
  516. exports.EventBus = EventBus;
  517. exports.ProgressBar = ProgressBar;
  518. exports.getPDFFileNameFromURL = getPDFFileNameFromURL;
  519. exports.noContextMenuHandler = noContextMenuHandler;
  520. exports.parseQueryString = parseQueryString;
  521. exports.getVisibleElements = getVisibleElements;
  522. exports.roundToDivide = roundToDivide;
  523. exports.approximateFraction = approximateFraction;
  524. exports.getOutputScale = getOutputScale;
  525. exports.scrollIntoView = scrollIntoView;
  526. exports.watchScroll = watchScroll;
  527. exports.binarySearchFirstItem = binarySearchFirstItem;
  528. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  529. exports.animationStarted = animationStarted;
  530. exports.localized = localized;
  531. /***/ }),
  532. /* 2 */
  533. /***/ (function(module, exports, __w_pdfjs_require__) {
  534. "use strict";
  535. Object.defineProperty(exports, "__esModule", {
  536. value: true
  537. });
  538. exports.getGlobalEventBus = exports.attachDOMEventsToEventBus = undefined;
  539. var _ui_utils = __w_pdfjs_require__(1);
  540. function attachDOMEventsToEventBus(eventBus) {
  541. eventBus.on('documentload', function () {
  542. var event = document.createEvent('CustomEvent');
  543. event.initCustomEvent('documentload', true, true, {});
  544. window.dispatchEvent(event);
  545. });
  546. eventBus.on('pagerendered', function (e) {
  547. var event = document.createEvent('CustomEvent');
  548. event.initCustomEvent('pagerendered', true, true, {
  549. pageNumber: e.pageNumber,
  550. cssTransform: e.cssTransform
  551. });
  552. e.source.div.dispatchEvent(event);
  553. });
  554. eventBus.on('textlayerrendered', function (e) {
  555. var event = document.createEvent('CustomEvent');
  556. event.initCustomEvent('textlayerrendered', true, true, { pageNumber: e.pageNumber });
  557. e.source.textLayerDiv.dispatchEvent(event);
  558. });
  559. eventBus.on('pagechange', function (e) {
  560. var event = document.createEvent('UIEvents');
  561. event.initUIEvent('pagechange', true, true, window, 0);
  562. event.pageNumber = e.pageNumber;
  563. e.source.container.dispatchEvent(event);
  564. });
  565. eventBus.on('pagesinit', function (e) {
  566. var event = document.createEvent('CustomEvent');
  567. event.initCustomEvent('pagesinit', true, true, null);
  568. e.source.container.dispatchEvent(event);
  569. });
  570. eventBus.on('pagesloaded', function (e) {
  571. var event = document.createEvent('CustomEvent');
  572. event.initCustomEvent('pagesloaded', true, true, { pagesCount: e.pagesCount });
  573. e.source.container.dispatchEvent(event);
  574. });
  575. eventBus.on('scalechange', function (e) {
  576. var event = document.createEvent('UIEvents');
  577. event.initUIEvent('scalechange', true, true, window, 0);
  578. event.scale = e.scale;
  579. event.presetValue = e.presetValue;
  580. e.source.container.dispatchEvent(event);
  581. });
  582. eventBus.on('updateviewarea', function (e) {
  583. var event = document.createEvent('UIEvents');
  584. event.initUIEvent('updateviewarea', true, true, window, 0);
  585. event.location = e.location;
  586. e.source.container.dispatchEvent(event);
  587. });
  588. eventBus.on('find', function (e) {
  589. if (e.source === window) {
  590. return;
  591. }
  592. var event = document.createEvent('CustomEvent');
  593. event.initCustomEvent('find' + e.type, true, true, {
  594. query: e.query,
  595. phraseSearch: e.phraseSearch,
  596. caseSensitive: e.caseSensitive,
  597. highlightAll: e.highlightAll,
  598. findPrevious: e.findPrevious
  599. });
  600. window.dispatchEvent(event);
  601. });
  602. eventBus.on('attachmentsloaded', function (e) {
  603. var event = document.createEvent('CustomEvent');
  604. event.initCustomEvent('attachmentsloaded', true, true, { attachmentsCount: e.attachmentsCount });
  605. e.source.container.dispatchEvent(event);
  606. });
  607. eventBus.on('sidebarviewchanged', function (e) {
  608. var event = document.createEvent('CustomEvent');
  609. event.initCustomEvent('sidebarviewchanged', true, true, { view: e.view });
  610. e.source.outerContainer.dispatchEvent(event);
  611. });
  612. eventBus.on('pagemode', function (e) {
  613. var event = document.createEvent('CustomEvent');
  614. event.initCustomEvent('pagemode', true, true, { mode: e.mode });
  615. e.source.pdfViewer.container.dispatchEvent(event);
  616. });
  617. eventBus.on('namedaction', function (e) {
  618. var event = document.createEvent('CustomEvent');
  619. event.initCustomEvent('namedaction', true, true, { action: e.action });
  620. e.source.pdfViewer.container.dispatchEvent(event);
  621. });
  622. eventBus.on('presentationmodechanged', function (e) {
  623. var event = document.createEvent('CustomEvent');
  624. event.initCustomEvent('presentationmodechanged', true, true, {
  625. active: e.active,
  626. switchInProgress: e.switchInProgress
  627. });
  628. window.dispatchEvent(event);
  629. });
  630. eventBus.on('outlineloaded', function (e) {
  631. var event = document.createEvent('CustomEvent');
  632. event.initCustomEvent('outlineloaded', true, true, { outlineCount: e.outlineCount });
  633. e.source.container.dispatchEvent(event);
  634. });
  635. }
  636. var globalEventBus = null;
  637. function getGlobalEventBus() {
  638. if (globalEventBus) {
  639. return globalEventBus;
  640. }
  641. globalEventBus = new _ui_utils.EventBus();
  642. attachDOMEventsToEventBus(globalEventBus);
  643. return globalEventBus;
  644. }
  645. exports.attachDOMEventsToEventBus = attachDOMEventsToEventBus;
  646. exports.getGlobalEventBus = getGlobalEventBus;
  647. /***/ }),
  648. /* 3 */
  649. /***/ (function(module, exports, __w_pdfjs_require__) {
  650. "use strict";
  651. Object.defineProperty(exports, "__esModule", {
  652. value: true
  653. });
  654. exports.SimpleLinkService = exports.PDFLinkService = undefined;
  655. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  656. var _dom_events = __w_pdfjs_require__(2);
  657. var _ui_utils = __w_pdfjs_require__(1);
  658. var PDFLinkService = function PDFLinkServiceClosure() {
  659. function PDFLinkService(options) {
  660. options = options || {};
  661. this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
  662. this.baseUrl = null;
  663. this.pdfDocument = null;
  664. this.pdfViewer = null;
  665. this.pdfHistory = null;
  666. this._pagesRefCache = null;
  667. }
  668. PDFLinkService.prototype = {
  669. setDocument: function PDFLinkService_setDocument(pdfDocument, baseUrl) {
  670. this.baseUrl = baseUrl;
  671. this.pdfDocument = pdfDocument;
  672. this._pagesRefCache = Object.create(null);
  673. },
  674. setViewer: function PDFLinkService_setViewer(pdfViewer) {
  675. this.pdfViewer = pdfViewer;
  676. },
  677. setHistory: function PDFLinkService_setHistory(pdfHistory) {
  678. this.pdfHistory = pdfHistory;
  679. },
  680. get pagesCount() {
  681. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  682. },
  683. get page() {
  684. return this.pdfViewer.currentPageNumber;
  685. },
  686. set page(value) {
  687. this.pdfViewer.currentPageNumber = value;
  688. },
  689. navigateTo: function navigateTo(dest) {
  690. var _this = this;
  691. var goToDestination = function goToDestination(_ref) {
  692. var namedDest = _ref.namedDest,
  693. explicitDest = _ref.explicitDest;
  694. var destRef = explicitDest[0],
  695. pageNumber = void 0;
  696. if (destRef instanceof Object) {
  697. pageNumber = _this._cachedPageNumber(destRef);
  698. if (pageNumber === null) {
  699. _this.pdfDocument.getPageIndex(destRef).then(function (pageIndex) {
  700. _this.cachePageRef(pageIndex + 1, destRef);
  701. goToDestination({
  702. namedDest: namedDest,
  703. explicitDest: explicitDest
  704. });
  705. }).catch(function () {
  706. console.error('PDFLinkService.navigateTo: "' + destRef + '" is not ' + ('a valid page reference, for dest="' + dest + '".'));
  707. });
  708. return;
  709. }
  710. } else if ((destRef | 0) === destRef) {
  711. pageNumber = destRef + 1;
  712. } else {
  713. console.error('PDFLinkService.navigateTo: "' + destRef + '" is not ' + ('a valid destination reference, for dest="' + dest + '".'));
  714. return;
  715. }
  716. if (!pageNumber || pageNumber < 1 || pageNumber > _this.pagesCount) {
  717. console.error('PDFLinkService.navigateTo: "' + pageNumber + '" is not ' + ('a valid page number, for dest="' + dest + '".'));
  718. return;
  719. }
  720. _this.pdfViewer.scrollPageIntoView({
  721. pageNumber: pageNumber,
  722. destArray: explicitDest
  723. });
  724. if (_this.pdfHistory) {
  725. _this.pdfHistory.push({
  726. dest: explicitDest,
  727. hash: namedDest,
  728. page: pageNumber
  729. });
  730. }
  731. };
  732. new Promise(function (resolve, reject) {
  733. if (typeof dest === 'string') {
  734. _this.pdfDocument.getDestination(dest).then(function (destArray) {
  735. resolve({
  736. namedDest: dest,
  737. explicitDest: destArray
  738. });
  739. });
  740. return;
  741. }
  742. resolve({
  743. namedDest: '',
  744. explicitDest: dest
  745. });
  746. }).then(function (data) {
  747. if (!(data.explicitDest instanceof Array)) {
  748. console.error('PDFLinkService.navigateTo: "' + data.explicitDest + '" is' + (' not a valid destination array, for dest="' + dest + '".'));
  749. return;
  750. }
  751. goToDestination(data);
  752. });
  753. },
  754. getDestinationHash: function getDestinationHash(dest) {
  755. if (typeof dest === 'string') {
  756. return this.getAnchorUrl('#' + escape(dest));
  757. }
  758. if (dest instanceof Array) {
  759. var str = JSON.stringify(dest);
  760. return this.getAnchorUrl('#' + escape(str));
  761. }
  762. return this.getAnchorUrl('');
  763. },
  764. getAnchorUrl: function PDFLinkService_getAnchorUrl(anchor) {
  765. return (this.baseUrl || '') + anchor;
  766. },
  767. setHash: function PDFLinkService_setHash(hash) {
  768. var pageNumber, dest;
  769. if (hash.indexOf('=') >= 0) {
  770. var params = (0, _ui_utils.parseQueryString)(hash);
  771. if ('search' in params) {
  772. this.eventBus.dispatch('findfromurlhash', {
  773. source: this,
  774. query: params['search'].replace(/"/g, ''),
  775. phraseSearch: params['phrase'] === 'true'
  776. });
  777. }
  778. if ('nameddest' in params) {
  779. if (this.pdfHistory) {
  780. this.pdfHistory.updateNextHashParam(params.nameddest);
  781. }
  782. this.navigateTo(params.nameddest);
  783. return;
  784. }
  785. if ('page' in params) {
  786. pageNumber = params.page | 0 || 1;
  787. }
  788. if ('zoom' in params) {
  789. var zoomArgs = params.zoom.split(',');
  790. var zoomArg = zoomArgs[0];
  791. var zoomArgNumber = parseFloat(zoomArg);
  792. if (zoomArg.indexOf('Fit') === -1) {
  793. dest = [null, { name: 'XYZ' }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  794. } else {
  795. if (zoomArg === 'Fit' || zoomArg === 'FitB') {
  796. dest = [null, { name: zoomArg }];
  797. } else if (zoomArg === 'FitH' || zoomArg === 'FitBH' || zoomArg === 'FitV' || zoomArg === 'FitBV') {
  798. dest = [null, { name: zoomArg }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  799. } else if (zoomArg === 'FitR') {
  800. if (zoomArgs.length !== 5) {
  801. console.error('PDFLinkService_setHash: ' + 'Not enough parameters for \'FitR\'.');
  802. } else {
  803. dest = [null, { name: zoomArg }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  804. }
  805. } else {
  806. console.error('PDFLinkService_setHash: \'' + zoomArg + '\' is not a valid zoom value.');
  807. }
  808. }
  809. }
  810. if (dest) {
  811. this.pdfViewer.scrollPageIntoView({
  812. pageNumber: pageNumber || this.page,
  813. destArray: dest,
  814. allowNegativeOffset: true
  815. });
  816. } else if (pageNumber) {
  817. this.page = pageNumber;
  818. }
  819. if ('pagemode' in params) {
  820. this.eventBus.dispatch('pagemode', {
  821. source: this,
  822. mode: params.pagemode
  823. });
  824. }
  825. } else {
  826. if (/^\d+$/.test(hash) && hash <= this.pagesCount) {
  827. console.warn('PDFLinkService_setHash: specifying a page number ' + 'directly after the hash symbol (#) is deprecated, ' + 'please use the "#page=' + hash + '" form instead.');
  828. this.page = hash | 0;
  829. }
  830. dest = unescape(hash);
  831. try {
  832. dest = JSON.parse(dest);
  833. if (!(dest instanceof Array)) {
  834. dest = dest.toString();
  835. }
  836. } catch (ex) {}
  837. if (typeof dest === 'string' || isValidExplicitDestination(dest)) {
  838. if (this.pdfHistory) {
  839. this.pdfHistory.updateNextHashParam(dest);
  840. }
  841. this.navigateTo(dest);
  842. return;
  843. }
  844. console.error('PDFLinkService_setHash: \'' + unescape(hash) + '\' is not a valid destination.');
  845. }
  846. },
  847. executeNamedAction: function PDFLinkService_executeNamedAction(action) {
  848. switch (action) {
  849. case 'GoBack':
  850. if (this.pdfHistory) {
  851. this.pdfHistory.back();
  852. }
  853. break;
  854. case 'GoForward':
  855. if (this.pdfHistory) {
  856. this.pdfHistory.forward();
  857. }
  858. break;
  859. case 'NextPage':
  860. if (this.page < this.pagesCount) {
  861. this.page++;
  862. }
  863. break;
  864. case 'PrevPage':
  865. if (this.page > 1) {
  866. this.page--;
  867. }
  868. break;
  869. case 'LastPage':
  870. this.page = this.pagesCount;
  871. break;
  872. case 'FirstPage':
  873. this.page = 1;
  874. break;
  875. default:
  876. break;
  877. }
  878. this.eventBus.dispatch('namedaction', {
  879. source: this,
  880. action: action
  881. });
  882. },
  883. onFileAttachmentAnnotation: function onFileAttachmentAnnotation() {
  884. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  885. this.eventBus.dispatch('fileattachmentannotation', {
  886. source: this,
  887. id: params.id,
  888. filename: params.filename,
  889. content: params.content
  890. });
  891. },
  892. cachePageRef: function PDFLinkService_cachePageRef(pageNum, pageRef) {
  893. var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
  894. this._pagesRefCache[refStr] = pageNum;
  895. },
  896. _cachedPageNumber: function PDFLinkService_cachedPageNumber(pageRef) {
  897. var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
  898. return this._pagesRefCache && this._pagesRefCache[refStr] || null;
  899. }
  900. };
  901. function isValidExplicitDestination(dest) {
  902. if (!(dest instanceof Array)) {
  903. return false;
  904. }
  905. var destLength = dest.length,
  906. allowNull = true;
  907. if (destLength < 2) {
  908. return false;
  909. }
  910. var page = dest[0];
  911. if (!((typeof page === 'undefined' ? 'undefined' : _typeof(page)) === 'object' && typeof page.num === 'number' && (page.num | 0) === page.num && typeof page.gen === 'number' && (page.gen | 0) === page.gen) && !(typeof page === 'number' && (page | 0) === page && page >= 0)) {
  912. return false;
  913. }
  914. var zoom = dest[1];
  915. if (!((typeof zoom === 'undefined' ? 'undefined' : _typeof(zoom)) === 'object' && typeof zoom.name === 'string')) {
  916. return false;
  917. }
  918. switch (zoom.name) {
  919. case 'XYZ':
  920. if (destLength !== 5) {
  921. return false;
  922. }
  923. break;
  924. case 'Fit':
  925. case 'FitB':
  926. return destLength === 2;
  927. case 'FitH':
  928. case 'FitBH':
  929. case 'FitV':
  930. case 'FitBV':
  931. if (destLength !== 3) {
  932. return false;
  933. }
  934. break;
  935. case 'FitR':
  936. if (destLength !== 6) {
  937. return false;
  938. }
  939. allowNull = false;
  940. break;
  941. default:
  942. return false;
  943. }
  944. for (var i = 2; i < destLength; i++) {
  945. var param = dest[i];
  946. if (!(typeof param === 'number' || allowNull && param === null)) {
  947. return false;
  948. }
  949. }
  950. return true;
  951. }
  952. return PDFLinkService;
  953. }();
  954. var SimpleLinkService = function SimpleLinkServiceClosure() {
  955. function SimpleLinkService() {}
  956. SimpleLinkService.prototype = {
  957. get page() {
  958. return 0;
  959. },
  960. set page(value) {},
  961. navigateTo: function navigateTo(dest) {},
  962. getDestinationHash: function getDestinationHash(dest) {
  963. return '#';
  964. },
  965. getAnchorUrl: function getAnchorUrl(hash) {
  966. return '#';
  967. },
  968. setHash: function setHash(hash) {},
  969. executeNamedAction: function executeNamedAction(action) {},
  970. onFileAttachmentAnnotation: function onFileAttachmentAnnotation(params) {},
  971. cachePageRef: function cachePageRef(pageNum, pageRef) {}
  972. };
  973. return SimpleLinkService;
  974. }();
  975. exports.PDFLinkService = PDFLinkService;
  976. exports.SimpleLinkService = SimpleLinkService;
  977. /***/ }),
  978. /* 4 */
  979. /***/ (function(module, exports, __w_pdfjs_require__) {
  980. "use strict";
  981. Object.defineProperty(exports, "__esModule", {
  982. value: true
  983. });
  984. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = undefined;
  985. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  986. var _pdfjsLib = __w_pdfjs_require__(0);
  987. var _ui_utils = __w_pdfjs_require__(1);
  988. var _pdf_link_service = __w_pdfjs_require__(3);
  989. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  990. var AnnotationLayerBuilder = function () {
  991. function AnnotationLayerBuilder(options) {
  992. _classCallCheck(this, AnnotationLayerBuilder);
  993. this.pageDiv = options.pageDiv;
  994. this.pdfPage = options.pdfPage;
  995. this.renderInteractiveForms = options.renderInteractiveForms;
  996. this.linkService = options.linkService;
  997. this.downloadManager = options.downloadManager;
  998. this.div = null;
  999. }
  1000. _createClass(AnnotationLayerBuilder, [{
  1001. key: 'render',
  1002. value: function render(viewport) {
  1003. var _this = this;
  1004. var intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'display';
  1005. this.pdfPage.getAnnotations({ intent: intent }).then(function (annotations) {
  1006. var parameters = {
  1007. viewport: viewport.clone({ dontFlip: true }),
  1008. div: _this.div,
  1009. annotations: annotations,
  1010. page: _this.pdfPage,
  1011. renderInteractiveForms: _this.renderInteractiveForms,
  1012. linkService: _this.linkService,
  1013. downloadManager: _this.downloadManager
  1014. };
  1015. if (_this.div) {
  1016. _pdfjsLib.AnnotationLayer.update(parameters);
  1017. } else {
  1018. if (annotations.length === 0) {
  1019. return;
  1020. }
  1021. _this.div = document.createElement('div');
  1022. _this.div.className = 'annotationLayer';
  1023. _this.pageDiv.appendChild(_this.div);
  1024. parameters.div = _this.div;
  1025. _pdfjsLib.AnnotationLayer.render(parameters);
  1026. if (typeof _ui_utils.mozL10n !== 'undefined') {
  1027. _ui_utils.mozL10n.translate(_this.div);
  1028. }
  1029. }
  1030. });
  1031. }
  1032. }, {
  1033. key: 'hide',
  1034. value: function hide() {
  1035. if (!this.div) {
  1036. return;
  1037. }
  1038. this.div.setAttribute('hidden', 'true');
  1039. }
  1040. }]);
  1041. return AnnotationLayerBuilder;
  1042. }();
  1043. var DefaultAnnotationLayerFactory = function () {
  1044. function DefaultAnnotationLayerFactory() {
  1045. _classCallCheck(this, DefaultAnnotationLayerFactory);
  1046. }
  1047. _createClass(DefaultAnnotationLayerFactory, [{
  1048. key: 'createAnnotationLayerBuilder',
  1049. value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  1050. var renderInteractiveForms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  1051. return new AnnotationLayerBuilder({
  1052. pageDiv: pageDiv,
  1053. pdfPage: pdfPage,
  1054. renderInteractiveForms: renderInteractiveForms,
  1055. linkService: new _pdf_link_service.SimpleLinkService()
  1056. });
  1057. }
  1058. }]);
  1059. return DefaultAnnotationLayerFactory;
  1060. }();
  1061. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  1062. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  1063. /***/ }),
  1064. /* 5 */
  1065. /***/ (function(module, exports, __w_pdfjs_require__) {
  1066. "use strict";
  1067. Object.defineProperty(exports, "__esModule", {
  1068. value: true
  1069. });
  1070. exports.PDFPageView = undefined;
  1071. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  1072. var _ui_utils = __w_pdfjs_require__(1);
  1073. var _pdfjsLib = __w_pdfjs_require__(0);
  1074. var _dom_events = __w_pdfjs_require__(2);
  1075. var _pdf_rendering_queue = __w_pdfjs_require__(7);
  1076. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1077. var TEXT_LAYER_RENDER_DELAY = 200;
  1078. var PDFPageView = function () {
  1079. function PDFPageView(options) {
  1080. _classCallCheck(this, PDFPageView);
  1081. var container = options.container;
  1082. var defaultViewport = options.defaultViewport;
  1083. this.id = options.id;
  1084. this.renderingId = 'page' + this.id;
  1085. this.pageLabel = null;
  1086. this.rotation = 0;
  1087. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  1088. this.viewport = defaultViewport;
  1089. this.pdfPageRotate = defaultViewport.rotation;
  1090. this.hasRestrictedScaling = false;
  1091. this.enhanceTextSelection = options.enhanceTextSelection || false;
  1092. this.renderInteractiveForms = options.renderInteractiveForms || false;
  1093. this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
  1094. this.renderingQueue = options.renderingQueue;
  1095. this.textLayerFactory = options.textLayerFactory;
  1096. this.annotationLayerFactory = options.annotationLayerFactory;
  1097. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  1098. this.paintTask = null;
  1099. this.paintedViewportMap = new WeakMap();
  1100. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  1101. this.resume = null;
  1102. this.error = null;
  1103. this.onBeforeDraw = null;
  1104. this.onAfterDraw = null;
  1105. this.annotationLayer = null;
  1106. this.textLayer = null;
  1107. this.zoomLayer = null;
  1108. var div = document.createElement('div');
  1109. div.className = 'page';
  1110. div.style.width = Math.floor(this.viewport.width) + 'px';
  1111. div.style.height = Math.floor(this.viewport.height) + 'px';
  1112. div.setAttribute('data-page-number', this.id);
  1113. this.div = div;
  1114. container.appendChild(div);
  1115. }
  1116. _createClass(PDFPageView, [{
  1117. key: 'setPdfPage',
  1118. value: function setPdfPage(pdfPage) {
  1119. this.pdfPage = pdfPage;
  1120. this.pdfPageRotate = pdfPage.rotate;
  1121. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  1122. this.viewport = pdfPage.getViewport(this.scale * _ui_utils.CSS_UNITS, totalRotation);
  1123. this.stats = pdfPage.stats;
  1124. this.reset();
  1125. }
  1126. }, {
  1127. key: 'destroy',
  1128. value: function destroy() {
  1129. this.reset();
  1130. if (this.pdfPage) {
  1131. this.pdfPage.cleanup();
  1132. }
  1133. }
  1134. }, {
  1135. key: '_resetZoomLayer',
  1136. value: function _resetZoomLayer() {
  1137. var removeFromDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1138. if (!this.zoomLayer) {
  1139. return;
  1140. }
  1141. var zoomLayerCanvas = this.zoomLayer.firstChild;
  1142. this.paintedViewportMap.delete(zoomLayerCanvas);
  1143. zoomLayerCanvas.width = 0;
  1144. zoomLayerCanvas.height = 0;
  1145. if (removeFromDOM) {
  1146. this.zoomLayer.remove();
  1147. }
  1148. this.zoomLayer = null;
  1149. }
  1150. }, {
  1151. key: 'reset',
  1152. value: function reset() {
  1153. var keepZoomLayer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1154. var keepAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1155. this.cancelRendering();
  1156. var div = this.div;
  1157. div.style.width = Math.floor(this.viewport.width) + 'px';
  1158. div.style.height = Math.floor(this.viewport.height) + 'px';
  1159. var childNodes = div.childNodes;
  1160. var currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  1161. var currentAnnotationNode = keepAnnotations && this.annotationLayer && this.annotationLayer.div || null;
  1162. for (var i = childNodes.length - 1; i >= 0; i--) {
  1163. var node = childNodes[i];
  1164. if (currentZoomLayerNode === node || currentAnnotationNode === node) {
  1165. continue;
  1166. }
  1167. div.removeChild(node);
  1168. }
  1169. div.removeAttribute('data-loaded');
  1170. if (currentAnnotationNode) {
  1171. this.annotationLayer.hide();
  1172. } else {
  1173. this.annotationLayer = null;
  1174. }
  1175. if (!currentZoomLayerNode) {
  1176. if (this.canvas) {
  1177. this.paintedViewportMap.delete(this.canvas);
  1178. this.canvas.width = 0;
  1179. this.canvas.height = 0;
  1180. delete this.canvas;
  1181. }
  1182. this._resetZoomLayer();
  1183. }
  1184. if (this.svg) {
  1185. this.paintedViewportMap.delete(this.svg);
  1186. delete this.svg;
  1187. }
  1188. this.loadingIconDiv = document.createElement('div');
  1189. this.loadingIconDiv.className = 'loadingIcon';
  1190. div.appendChild(this.loadingIconDiv);
  1191. }
  1192. }, {
  1193. key: 'update',
  1194. value: function update(scale, rotation) {
  1195. this.scale = scale || this.scale;
  1196. if (typeof rotation !== 'undefined') {
  1197. this.rotation = rotation;
  1198. }
  1199. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  1200. this.viewport = this.viewport.clone({
  1201. scale: this.scale * _ui_utils.CSS_UNITS,
  1202. rotation: totalRotation
  1203. });
  1204. if (this.svg) {
  1205. this.cssTransform(this.svg, true);
  1206. this.eventBus.dispatch('pagerendered', {
  1207. source: this,
  1208. pageNumber: this.id,
  1209. cssTransform: true
  1210. });
  1211. return;
  1212. }
  1213. var isScalingRestricted = false;
  1214. if (this.canvas && _pdfjsLib.PDFJS.maxCanvasPixels > 0) {
  1215. var outputScale = this.outputScale;
  1216. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > _pdfjsLib.PDFJS.maxCanvasPixels) {
  1217. isScalingRestricted = true;
  1218. }
  1219. }
  1220. if (this.canvas) {
  1221. if (_pdfjsLib.PDFJS.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  1222. this.cssTransform(this.canvas, true);
  1223. this.eventBus.dispatch('pagerendered', {
  1224. source: this,
  1225. pageNumber: this.id,
  1226. cssTransform: true
  1227. });
  1228. return;
  1229. }
  1230. if (!this.zoomLayer) {
  1231. this.zoomLayer = this.canvas.parentNode;
  1232. this.zoomLayer.style.position = 'absolute';
  1233. }
  1234. }
  1235. if (this.zoomLayer) {
  1236. this.cssTransform(this.zoomLayer.firstChild);
  1237. }
  1238. this.reset(true, true);
  1239. }
  1240. }, {
  1241. key: 'cancelRendering',
  1242. value: function cancelRendering() {
  1243. if (this.paintTask) {
  1244. this.paintTask.cancel();
  1245. this.paintTask = null;
  1246. }
  1247. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  1248. this.resume = null;
  1249. if (this.textLayer) {
  1250. this.textLayer.cancel();
  1251. this.textLayer = null;
  1252. }
  1253. }
  1254. }, {
  1255. key: 'updatePosition',
  1256. value: function updatePosition() {
  1257. if (this.textLayer) {
  1258. this.textLayer.render(TEXT_LAYER_RENDER_DELAY);
  1259. }
  1260. }
  1261. }, {
  1262. key: 'cssTransform',
  1263. value: function cssTransform(target) {
  1264. var redrawAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1265. var width = this.viewport.width;
  1266. var height = this.viewport.height;
  1267. var div = this.div;
  1268. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + 'px';
  1269. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + 'px';
  1270. var relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  1271. var absRotation = Math.abs(relativeRotation);
  1272. var scaleX = 1,
  1273. scaleY = 1;
  1274. if (absRotation === 90 || absRotation === 270) {
  1275. scaleX = height / width;
  1276. scaleY = width / height;
  1277. }
  1278. var cssTransform = 'rotate(' + relativeRotation + 'deg) ' + 'scale(' + scaleX + ',' + scaleY + ')';
  1279. _pdfjsLib.CustomStyle.setProp('transform', target, cssTransform);
  1280. if (this.textLayer) {
  1281. var textLayerViewport = this.textLayer.viewport;
  1282. var textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  1283. var textAbsRotation = Math.abs(textRelativeRotation);
  1284. var scale = width / textLayerViewport.width;
  1285. if (textAbsRotation === 90 || textAbsRotation === 270) {
  1286. scale = width / textLayerViewport.height;
  1287. }
  1288. var textLayerDiv = this.textLayer.textLayerDiv;
  1289. var transX = void 0,
  1290. transY = void 0;
  1291. switch (textAbsRotation) {
  1292. case 0:
  1293. transX = transY = 0;
  1294. break;
  1295. case 90:
  1296. transX = 0;
  1297. transY = '-' + textLayerDiv.style.height;
  1298. break;
  1299. case 180:
  1300. transX = '-' + textLayerDiv.style.width;
  1301. transY = '-' + textLayerDiv.style.height;
  1302. break;
  1303. case 270:
  1304. transX = '-' + textLayerDiv.style.width;
  1305. transY = 0;
  1306. break;
  1307. default:
  1308. console.error('Bad rotation value.');
  1309. break;
  1310. }
  1311. _pdfjsLib.CustomStyle.setProp('transform', textLayerDiv, 'rotate(' + textAbsRotation + 'deg) ' + 'scale(' + scale + ', ' + scale + ') ' + 'translate(' + transX + ', ' + transY + ')');
  1312. _pdfjsLib.CustomStyle.setProp('transformOrigin', textLayerDiv, '0% 0%');
  1313. }
  1314. if (redrawAnnotations && this.annotationLayer) {
  1315. this.annotationLayer.render(this.viewport, 'display');
  1316. }
  1317. }
  1318. }, {
  1319. key: 'getPagePoint',
  1320. value: function getPagePoint(x, y) {
  1321. return this.viewport.convertToPdfPoint(x, y);
  1322. }
  1323. }, {
  1324. key: 'draw',
  1325. value: function draw() {
  1326. var _this = this;
  1327. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  1328. console.error('Must be in new state before drawing');
  1329. this.reset();
  1330. }
  1331. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  1332. var pdfPage = this.pdfPage;
  1333. var div = this.div;
  1334. var canvasWrapper = document.createElement('div');
  1335. canvasWrapper.style.width = div.style.width;
  1336. canvasWrapper.style.height = div.style.height;
  1337. canvasWrapper.classList.add('canvasWrapper');
  1338. if (this.annotationLayer && this.annotationLayer.div) {
  1339. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  1340. } else {
  1341. div.appendChild(canvasWrapper);
  1342. }
  1343. var textLayer = null;
  1344. if (this.textLayerFactory) {
  1345. var textLayerDiv = document.createElement('div');
  1346. textLayerDiv.className = 'textLayer';
  1347. textLayerDiv.style.width = canvasWrapper.style.width;
  1348. textLayerDiv.style.height = canvasWrapper.style.height;
  1349. if (this.annotationLayer && this.annotationLayer.div) {
  1350. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  1351. } else {
  1352. div.appendChild(textLayerDiv);
  1353. }
  1354. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.enhanceTextSelection);
  1355. }
  1356. this.textLayer = textLayer;
  1357. var renderContinueCallback = null;
  1358. if (this.renderingQueue) {
  1359. renderContinueCallback = function renderContinueCallback(cont) {
  1360. if (!_this.renderingQueue.isHighestPriority(_this)) {
  1361. _this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  1362. _this.resume = function () {
  1363. _this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  1364. cont();
  1365. };
  1366. return;
  1367. }
  1368. cont();
  1369. };
  1370. }
  1371. var finishPaintTask = function finishPaintTask(error) {
  1372. if (paintTask === _this.paintTask) {
  1373. _this.paintTask = null;
  1374. }
  1375. if (error === 'cancelled' || error instanceof _pdfjsLib.RenderingCancelledException) {
  1376. _this.error = null;
  1377. return Promise.resolve(undefined);
  1378. }
  1379. _this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  1380. if (_this.loadingIconDiv) {
  1381. div.removeChild(_this.loadingIconDiv);
  1382. delete _this.loadingIconDiv;
  1383. }
  1384. _this._resetZoomLayer(true);
  1385. _this.error = error;
  1386. _this.stats = pdfPage.stats;
  1387. if (_this.onAfterDraw) {
  1388. _this.onAfterDraw();
  1389. }
  1390. _this.eventBus.dispatch('pagerendered', {
  1391. source: _this,
  1392. pageNumber: _this.id,
  1393. cssTransform: false
  1394. });
  1395. if (error) {
  1396. return Promise.reject(error);
  1397. }
  1398. return Promise.resolve(undefined);
  1399. };
  1400. var paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  1401. paintTask.onRenderContinue = renderContinueCallback;
  1402. this.paintTask = paintTask;
  1403. var resultPromise = paintTask.promise.then(function () {
  1404. return finishPaintTask(null).then(function () {
  1405. if (textLayer) {
  1406. pdfPage.getTextContent({ normalizeWhitespace: true }).then(function textContentResolved(textContent) {
  1407. textLayer.setTextContent(textContent);
  1408. textLayer.render(TEXT_LAYER_RENDER_DELAY);
  1409. });
  1410. }
  1411. });
  1412. }, function (reason) {
  1413. return finishPaintTask(reason);
  1414. });
  1415. if (this.annotationLayerFactory) {
  1416. if (!this.annotationLayer) {
  1417. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.renderInteractiveForms);
  1418. }
  1419. this.annotationLayer.render(this.viewport, 'display');
  1420. }
  1421. div.setAttribute('data-loaded', true);
  1422. if (this.onBeforeDraw) {
  1423. this.onBeforeDraw();
  1424. }
  1425. return resultPromise;
  1426. }
  1427. }, {
  1428. key: 'paintOnCanvas',
  1429. value: function paintOnCanvas(canvasWrapper) {
  1430. var renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  1431. var result = {
  1432. promise: renderCapability.promise,
  1433. onRenderContinue: function onRenderContinue(cont) {
  1434. cont();
  1435. },
  1436. cancel: function cancel() {
  1437. renderTask.cancel();
  1438. }
  1439. };
  1440. var viewport = this.viewport;
  1441. var canvas = document.createElement('canvas');
  1442. canvas.id = this.renderingId;
  1443. canvas.setAttribute('hidden', 'hidden');
  1444. var isCanvasHidden = true;
  1445. var showCanvas = function showCanvas() {
  1446. if (isCanvasHidden) {
  1447. canvas.removeAttribute('hidden');
  1448. isCanvasHidden = false;
  1449. }
  1450. };
  1451. canvasWrapper.appendChild(canvas);
  1452. this.canvas = canvas;
  1453. canvas.mozOpaque = true;
  1454. var ctx = canvas.getContext('2d', { alpha: false });
  1455. var outputScale = (0, _ui_utils.getOutputScale)(ctx);
  1456. this.outputScale = outputScale;
  1457. if (_pdfjsLib.PDFJS.useOnlyCssZoom) {
  1458. var actualSizeViewport = viewport.clone({ scale: _ui_utils.CSS_UNITS });
  1459. outputScale.sx *= actualSizeViewport.width / viewport.width;
  1460. outputScale.sy *= actualSizeViewport.height / viewport.height;
  1461. outputScale.scaled = true;
  1462. }
  1463. if (_pdfjsLib.PDFJS.maxCanvasPixels > 0) {
  1464. var pixelsInViewport = viewport.width * viewport.height;
  1465. var maxScale = Math.sqrt(_pdfjsLib.PDFJS.maxCanvasPixels / pixelsInViewport);
  1466. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  1467. outputScale.sx = maxScale;
  1468. outputScale.sy = maxScale;
  1469. outputScale.scaled = true;
  1470. this.hasRestrictedScaling = true;
  1471. } else {
  1472. this.hasRestrictedScaling = false;
  1473. }
  1474. }
  1475. var sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  1476. var sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  1477. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  1478. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  1479. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + 'px';
  1480. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + 'px';
  1481. this.paintedViewportMap.set(canvas, viewport);
  1482. var transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  1483. var renderContext = {
  1484. canvasContext: ctx,
  1485. transform: transform,
  1486. viewport: this.viewport,
  1487. renderInteractiveForms: this.renderInteractiveForms
  1488. };
  1489. var renderTask = this.pdfPage.render(renderContext);
  1490. renderTask.onContinue = function (cont) {
  1491. showCanvas();
  1492. if (result.onRenderContinue) {
  1493. result.onRenderContinue(cont);
  1494. } else {
  1495. cont();
  1496. }
  1497. };
  1498. renderTask.promise.then(function () {
  1499. showCanvas();
  1500. renderCapability.resolve(undefined);
  1501. }, function (error) {
  1502. showCanvas();
  1503. renderCapability.reject(error);
  1504. });
  1505. return result;
  1506. }
  1507. }, {
  1508. key: 'paintOnSvg',
  1509. value: function paintOnSvg(wrapper) {
  1510. var _this2 = this;
  1511. var cancelled = false;
  1512. var ensureNotCancelled = function ensureNotCancelled() {
  1513. if (cancelled) {
  1514. if (_pdfjsLib.PDFJS.pdfjsNext) {
  1515. throw new _pdfjsLib.RenderingCancelledException('Rendering cancelled, page ' + _this2.id, 'svg');
  1516. } else {
  1517. throw 'cancelled';
  1518. }
  1519. }
  1520. };
  1521. var pdfPage = this.pdfPage;
  1522. var actualSizeViewport = this.viewport.clone({ scale: _ui_utils.CSS_UNITS });
  1523. var promise = pdfPage.getOperatorList().then(function (opList) {
  1524. ensureNotCancelled();
  1525. var svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  1526. return svgGfx.getSVG(opList, actualSizeViewport).then(function (svg) {
  1527. ensureNotCancelled();
  1528. _this2.svg = svg;
  1529. _this2.paintedViewportMap.set(svg, actualSizeViewport);
  1530. svg.style.width = wrapper.style.width;
  1531. svg.style.height = wrapper.style.height;
  1532. _this2.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  1533. wrapper.appendChild(svg);
  1534. });
  1535. });
  1536. return {
  1537. promise: promise,
  1538. onRenderContinue: function onRenderContinue(cont) {
  1539. cont();
  1540. },
  1541. cancel: function cancel() {
  1542. cancelled = true;
  1543. }
  1544. };
  1545. }
  1546. }, {
  1547. key: 'setPageLabel',
  1548. value: function setPageLabel(label) {
  1549. this.pageLabel = typeof label === 'string' ? label : null;
  1550. if (this.pageLabel !== null) {
  1551. this.div.setAttribute('data-page-label', this.pageLabel);
  1552. } else {
  1553. this.div.removeAttribute('data-page-label');
  1554. }
  1555. }
  1556. }, {
  1557. key: 'width',
  1558. get: function get() {
  1559. return this.viewport.width;
  1560. }
  1561. }, {
  1562. key: 'height',
  1563. get: function get() {
  1564. return this.viewport.height;
  1565. }
  1566. }]);
  1567. return PDFPageView;
  1568. }();
  1569. exports.PDFPageView = PDFPageView;
  1570. /***/ }),
  1571. /* 6 */
  1572. /***/ (function(module, exports, __w_pdfjs_require__) {
  1573. "use strict";
  1574. Object.defineProperty(exports, "__esModule", {
  1575. value: true
  1576. });
  1577. exports.DefaultTextLayerFactory = exports.TextLayerBuilder = undefined;
  1578. var _dom_events = __w_pdfjs_require__(2);
  1579. var _pdfjsLib = __w_pdfjs_require__(0);
  1580. var EXPAND_DIVS_TIMEOUT = 300;
  1581. var TextLayerBuilder = function TextLayerBuilderClosure() {
  1582. function TextLayerBuilder(options) {
  1583. this.textLayerDiv = options.textLayerDiv;
  1584. this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
  1585. this.textContent = null;
  1586. this.renderingDone = false;
  1587. this.pageIdx = options.pageIndex;
  1588. this.pageNumber = this.pageIdx + 1;
  1589. this.matches = [];
  1590. this.viewport = options.viewport;
  1591. this.textDivs = [];
  1592. this.findController = options.findController || null;
  1593. this.textLayerRenderTask = null;
  1594. this.enhanceTextSelection = options.enhanceTextSelection;
  1595. this._bindMouse();
  1596. }
  1597. TextLayerBuilder.prototype = {
  1598. _finishRendering: function TextLayerBuilder_finishRendering() {
  1599. this.renderingDone = true;
  1600. if (!this.enhanceTextSelection) {
  1601. var endOfContent = document.createElement('div');
  1602. endOfContent.className = 'endOfContent';
  1603. this.textLayerDiv.appendChild(endOfContent);
  1604. }
  1605. this.eventBus.dispatch('textlayerrendered', {
  1606. source: this,
  1607. pageNumber: this.pageNumber,
  1608. numTextDivs: this.textDivs.length
  1609. });
  1610. },
  1611. render: function TextLayerBuilder_render(timeout) {
  1612. var _this = this;
  1613. if (!this.textContent || this.renderingDone) {
  1614. return;
  1615. }
  1616. this.cancel();
  1617. this.textDivs = [];
  1618. var textLayerFrag = document.createDocumentFragment();
  1619. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  1620. textContent: this.textContent,
  1621. container: textLayerFrag,
  1622. viewport: this.viewport,
  1623. textDivs: this.textDivs,
  1624. timeout: timeout,
  1625. enhanceTextSelection: this.enhanceTextSelection
  1626. });
  1627. this.textLayerRenderTask.promise.then(function () {
  1628. _this.textLayerDiv.appendChild(textLayerFrag);
  1629. _this._finishRendering();
  1630. _this.updateMatches();
  1631. }, function (reason) {});
  1632. },
  1633. cancel: function TextLayerBuilder_cancel() {
  1634. if (this.textLayerRenderTask) {
  1635. this.textLayerRenderTask.cancel();
  1636. this.textLayerRenderTask = null;
  1637. }
  1638. },
  1639. setTextContent: function TextLayerBuilder_setTextContent(textContent) {
  1640. this.cancel();
  1641. this.textContent = textContent;
  1642. },
  1643. convertMatches: function TextLayerBuilder_convertMatches(matches, matchesLength) {
  1644. var i = 0;
  1645. var iIndex = 0;
  1646. var bidiTexts = this.textContent.items;
  1647. var end = bidiTexts.length - 1;
  1648. var queryLen = this.findController === null ? 0 : this.findController.state.query.length;
  1649. var ret = [];
  1650. if (!matches) {
  1651. return ret;
  1652. }
  1653. for (var m = 0, len = matches.length; m < len; m++) {
  1654. var matchIdx = matches[m];
  1655. while (i !== end && matchIdx >= iIndex + bidiTexts[i].str.length) {
  1656. iIndex += bidiTexts[i].str.length;
  1657. i++;
  1658. }
  1659. if (i === bidiTexts.length) {
  1660. console.error('Could not find a matching mapping');
  1661. }
  1662. var match = {
  1663. begin: {
  1664. divIdx: i,
  1665. offset: matchIdx - iIndex
  1666. }
  1667. };
  1668. if (matchesLength) {
  1669. matchIdx += matchesLength[m];
  1670. } else {
  1671. matchIdx += queryLen;
  1672. }
  1673. while (i !== end && matchIdx > iIndex + bidiTexts[i].str.length) {
  1674. iIndex += bidiTexts[i].str.length;
  1675. i++;
  1676. }
  1677. match.end = {
  1678. divIdx: i,
  1679. offset: matchIdx - iIndex
  1680. };
  1681. ret.push(match);
  1682. }
  1683. return ret;
  1684. },
  1685. renderMatches: function TextLayerBuilder_renderMatches(matches) {
  1686. if (matches.length === 0) {
  1687. return;
  1688. }
  1689. var bidiTexts = this.textContent.items;
  1690. var textDivs = this.textDivs;
  1691. var prevEnd = null;
  1692. var pageIdx = this.pageIdx;
  1693. var isSelectedPage = this.findController === null ? false : pageIdx === this.findController.selected.pageIdx;
  1694. var selectedMatchIdx = this.findController === null ? -1 : this.findController.selected.matchIdx;
  1695. var highlightAll = this.findController === null ? false : this.findController.state.highlightAll;
  1696. var infinity = {
  1697. divIdx: -1,
  1698. offset: undefined
  1699. };
  1700. function beginText(begin, className) {
  1701. var divIdx = begin.divIdx;
  1702. textDivs[divIdx].textContent = '';
  1703. appendTextToDiv(divIdx, 0, begin.offset, className);
  1704. }
  1705. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  1706. var div = textDivs[divIdx];
  1707. var content = bidiTexts[divIdx].str.substring(fromOffset, toOffset);
  1708. var node = document.createTextNode(content);
  1709. if (className) {
  1710. var span = document.createElement('span');
  1711. span.className = className;
  1712. span.appendChild(node);
  1713. div.appendChild(span);
  1714. return;
  1715. }
  1716. div.appendChild(node);
  1717. }
  1718. var i0 = selectedMatchIdx,
  1719. i1 = i0 + 1;
  1720. if (highlightAll) {
  1721. i0 = 0;
  1722. i1 = matches.length;
  1723. } else if (!isSelectedPage) {
  1724. return;
  1725. }
  1726. for (var i = i0; i < i1; i++) {
  1727. var match = matches[i];
  1728. var begin = match.begin;
  1729. var end = match.end;
  1730. var isSelected = isSelectedPage && i === selectedMatchIdx;
  1731. var highlightSuffix = isSelected ? ' selected' : '';
  1732. if (this.findController) {
  1733. this.findController.updateMatchPosition(pageIdx, i, textDivs, begin.divIdx);
  1734. }
  1735. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  1736. if (prevEnd !== null) {
  1737. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  1738. }
  1739. beginText(begin);
  1740. } else {
  1741. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  1742. }
  1743. if (begin.divIdx === end.divIdx) {
  1744. appendTextToDiv(begin.divIdx, begin.offset, end.offset, 'highlight' + highlightSuffix);
  1745. } else {
  1746. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, 'highlight begin' + highlightSuffix);
  1747. for (var n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  1748. textDivs[n0].className = 'highlight middle' + highlightSuffix;
  1749. }
  1750. beginText(end, 'highlight end' + highlightSuffix);
  1751. }
  1752. prevEnd = end;
  1753. }
  1754. if (prevEnd) {
  1755. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  1756. }
  1757. },
  1758. updateMatches: function TextLayerBuilder_updateMatches() {
  1759. if (!this.renderingDone) {
  1760. return;
  1761. }
  1762. var matches = this.matches;
  1763. var textDivs = this.textDivs;
  1764. var bidiTexts = this.textContent.items;
  1765. var clearedUntilDivIdx = -1;
  1766. for (var i = 0, len = matches.length; i < len; i++) {
  1767. var match = matches[i];
  1768. var begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  1769. for (var n = begin, end = match.end.divIdx; n <= end; n++) {
  1770. var div = textDivs[n];
  1771. div.textContent = bidiTexts[n].str;
  1772. div.className = '';
  1773. }
  1774. clearedUntilDivIdx = match.end.divIdx + 1;
  1775. }
  1776. if (this.findController === null || !this.findController.active) {
  1777. return;
  1778. }
  1779. var pageMatches, pageMatchesLength;
  1780. if (this.findController !== null) {
  1781. pageMatches = this.findController.pageMatches[this.pageIdx] || null;
  1782. pageMatchesLength = this.findController.pageMatchesLength ? this.findController.pageMatchesLength[this.pageIdx] || null : null;
  1783. }
  1784. this.matches = this.convertMatches(pageMatches, pageMatchesLength);
  1785. this.renderMatches(this.matches);
  1786. },
  1787. _bindMouse: function TextLayerBuilder_bindMouse() {
  1788. var div = this.textLayerDiv;
  1789. var self = this;
  1790. var expandDivsTimer = null;
  1791. div.addEventListener('mousedown', function (e) {
  1792. if (self.enhanceTextSelection && self.textLayerRenderTask) {
  1793. self.textLayerRenderTask.expandTextDivs(true);
  1794. if (expandDivsTimer) {
  1795. clearTimeout(expandDivsTimer);
  1796. expandDivsTimer = null;
  1797. }
  1798. return;
  1799. }
  1800. var end = div.querySelector('.endOfContent');
  1801. if (!end) {
  1802. return;
  1803. }
  1804. var adjustTop = e.target !== div;
  1805. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue('-moz-user-select') !== 'none';
  1806. if (adjustTop) {
  1807. var divBounds = div.getBoundingClientRect();
  1808. var r = Math.max(0, (e.pageY - divBounds.top) / divBounds.height);
  1809. end.style.top = (r * 100).toFixed(2) + '%';
  1810. }
  1811. end.classList.add('active');
  1812. });
  1813. div.addEventListener('mouseup', function (e) {
  1814. if (self.enhanceTextSelection && self.textLayerRenderTask) {
  1815. expandDivsTimer = setTimeout(function () {
  1816. if (self.textLayerRenderTask) {
  1817. self.textLayerRenderTask.expandTextDivs(false);
  1818. }
  1819. expandDivsTimer = null;
  1820. }, EXPAND_DIVS_TIMEOUT);
  1821. return;
  1822. }
  1823. var end = div.querySelector('.endOfContent');
  1824. if (!end) {
  1825. return;
  1826. }
  1827. end.style.top = '';
  1828. end.classList.remove('active');
  1829. });
  1830. }
  1831. };
  1832. return TextLayerBuilder;
  1833. }();
  1834. function DefaultTextLayerFactory() {}
  1835. DefaultTextLayerFactory.prototype = {
  1836. createTextLayerBuilder: function createTextLayerBuilder(textLayerDiv, pageIndex, viewport) {
  1837. var enhanceTextSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  1838. return new TextLayerBuilder({
  1839. textLayerDiv: textLayerDiv,
  1840. pageIndex: pageIndex,
  1841. viewport: viewport,
  1842. enhanceTextSelection: enhanceTextSelection
  1843. });
  1844. }
  1845. };
  1846. exports.TextLayerBuilder = TextLayerBuilder;
  1847. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  1848. /***/ }),
  1849. /* 7 */
  1850. /***/ (function(module, exports, __w_pdfjs_require__) {
  1851. "use strict";
  1852. Object.defineProperty(exports, "__esModule", {
  1853. value: true
  1854. });
  1855. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  1856. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1857. var CLEANUP_TIMEOUT = 30000;
  1858. var RenderingStates = {
  1859. INITIAL: 0,
  1860. RUNNING: 1,
  1861. PAUSED: 2,
  1862. FINISHED: 3
  1863. };
  1864. var PDFRenderingQueue = function () {
  1865. function PDFRenderingQueue() {
  1866. _classCallCheck(this, PDFRenderingQueue);
  1867. this.pdfViewer = null;
  1868. this.pdfThumbnailViewer = null;
  1869. this.onIdle = null;
  1870. this.highestPriorityPage = null;
  1871. this.idleTimeout = null;
  1872. this.printing = false;
  1873. this.isThumbnailViewEnabled = false;
  1874. }
  1875. _createClass(PDFRenderingQueue, [{
  1876. key: "setViewer",
  1877. value: function setViewer(pdfViewer) {
  1878. this.pdfViewer = pdfViewer;
  1879. }
  1880. }, {
  1881. key: "setThumbnailViewer",
  1882. value: function setThumbnailViewer(pdfThumbnailViewer) {
  1883. this.pdfThumbnailViewer = pdfThumbnailViewer;
  1884. }
  1885. }, {
  1886. key: "isHighestPriority",
  1887. value: function isHighestPriority(view) {
  1888. return this.highestPriorityPage === view.renderingId;
  1889. }
  1890. }, {
  1891. key: "renderHighestPriority",
  1892. value: function renderHighestPriority(currentlyVisiblePages) {
  1893. if (this.idleTimeout) {
  1894. clearTimeout(this.idleTimeout);
  1895. this.idleTimeout = null;
  1896. }
  1897. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  1898. return;
  1899. }
  1900. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  1901. if (this.pdfThumbnailViewer.forceRendering()) {
  1902. return;
  1903. }
  1904. }
  1905. if (this.printing) {
  1906. return;
  1907. }
  1908. if (this.onIdle) {
  1909. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  1910. }
  1911. }
  1912. }, {
  1913. key: "getHighestPriority",
  1914. value: function getHighestPriority(visible, views, scrolledDown) {
  1915. var visibleViews = visible.views;
  1916. var numVisible = visibleViews.length;
  1917. if (numVisible === 0) {
  1918. return false;
  1919. }
  1920. for (var i = 0; i < numVisible; ++i) {
  1921. var view = visibleViews[i].view;
  1922. if (!this.isViewFinished(view)) {
  1923. return view;
  1924. }
  1925. }
  1926. if (scrolledDown) {
  1927. var nextPageIndex = visible.last.id;
  1928. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  1929. return views[nextPageIndex];
  1930. }
  1931. } else {
  1932. var previousPageIndex = visible.first.id - 2;
  1933. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  1934. return views[previousPageIndex];
  1935. }
  1936. }
  1937. return null;
  1938. }
  1939. }, {
  1940. key: "isViewFinished",
  1941. value: function isViewFinished(view) {
  1942. return view.renderingState === RenderingStates.FINISHED;
  1943. }
  1944. }, {
  1945. key: "renderView",
  1946. value: function renderView(view) {
  1947. var _this = this;
  1948. switch (view.renderingState) {
  1949. case RenderingStates.FINISHED:
  1950. return false;
  1951. case RenderingStates.PAUSED:
  1952. this.highestPriorityPage = view.renderingId;
  1953. view.resume();
  1954. break;
  1955. case RenderingStates.RUNNING:
  1956. this.highestPriorityPage = view.renderingId;
  1957. break;
  1958. case RenderingStates.INITIAL:
  1959. this.highestPriorityPage = view.renderingId;
  1960. var continueRendering = function continueRendering() {
  1961. _this.renderHighestPriority();
  1962. };
  1963. view.draw().then(continueRendering, continueRendering);
  1964. break;
  1965. }
  1966. return true;
  1967. }
  1968. }]);
  1969. return PDFRenderingQueue;
  1970. }();
  1971. exports.RenderingStates = RenderingStates;
  1972. exports.PDFRenderingQueue = PDFRenderingQueue;
  1973. /***/ }),
  1974. /* 8 */
  1975. /***/ (function(module, exports, __w_pdfjs_require__) {
  1976. "use strict";
  1977. Object.defineProperty(exports, "__esModule", {
  1978. value: true
  1979. });
  1980. exports.DownloadManager = undefined;
  1981. var _pdfjsLib = __w_pdfjs_require__(0);
  1982. ;
  1983. function download(blobUrl, filename) {
  1984. var a = document.createElement('a');
  1985. if (a.click) {
  1986. a.href = blobUrl;
  1987. a.target = '_parent';
  1988. if ('download' in a) {
  1989. a.download = filename;
  1990. }
  1991. (document.body || document.documentElement).appendChild(a);
  1992. a.click();
  1993. a.parentNode.removeChild(a);
  1994. } else {
  1995. if (window.top === window && blobUrl.split('#')[0] === window.location.href.split('#')[0]) {
  1996. var padCharacter = blobUrl.indexOf('?') === -1 ? '?' : '&';
  1997. blobUrl = blobUrl.replace(/#|$/, padCharacter + '$&');
  1998. }
  1999. window.open(blobUrl, '_parent');
  2000. }
  2001. }
  2002. function DownloadManager() {}
  2003. DownloadManager.prototype = {
  2004. downloadUrl: function DownloadManager_downloadUrl(url, filename) {
  2005. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, 'http://example.com')) {
  2006. return;
  2007. }
  2008. download(url + '#pdfjs.action=download', filename);
  2009. },
  2010. downloadData: function DownloadManager_downloadData(data, filename, contentType) {
  2011. if (navigator.msSaveBlob) {
  2012. return navigator.msSaveBlob(new Blob([data], { type: contentType }), filename);
  2013. }
  2014. var blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, _pdfjsLib.PDFJS.disableCreateObjectURL);
  2015. download(blobUrl, filename);
  2016. },
  2017. download: function DownloadManager_download(blob, url, filename) {
  2018. if (navigator.msSaveBlob) {
  2019. if (!navigator.msSaveBlob(blob, filename)) {
  2020. this.downloadUrl(url, filename);
  2021. }
  2022. return;
  2023. }
  2024. if (_pdfjsLib.PDFJS.disableCreateObjectURL) {
  2025. this.downloadUrl(url, filename);
  2026. return;
  2027. }
  2028. var blobUrl = URL.createObjectURL(blob);
  2029. download(blobUrl, filename);
  2030. }
  2031. };
  2032. exports.DownloadManager = DownloadManager;
  2033. /***/ }),
  2034. /* 9 */
  2035. /***/ (function(module, exports, __w_pdfjs_require__) {
  2036. "use strict";
  2037. Object.defineProperty(exports, "__esModule", {
  2038. value: true
  2039. });
  2040. exports.PDFFindController = exports.FindStates = undefined;
  2041. var _pdfjsLib = __w_pdfjs_require__(0);
  2042. var _ui_utils = __w_pdfjs_require__(1);
  2043. var FindStates = {
  2044. FIND_FOUND: 0,
  2045. FIND_NOTFOUND: 1,
  2046. FIND_WRAPPED: 2,
  2047. FIND_PENDING: 3
  2048. };
  2049. var FIND_SCROLL_OFFSET_TOP = -50;
  2050. var FIND_SCROLL_OFFSET_LEFT = -400;
  2051. var CHARACTERS_TO_NORMALIZE = {
  2052. '\u2018': '\'',
  2053. '\u2019': '\'',
  2054. '\u201A': '\'',
  2055. '\u201B': '\'',
  2056. '\u201C': '"',
  2057. '\u201D': '"',
  2058. '\u201E': '"',
  2059. '\u201F': '"',
  2060. '\xBC': '1/4',
  2061. '\xBD': '1/2',
  2062. '\xBE': '3/4'
  2063. };
  2064. var PDFFindController = function PDFFindControllerClosure() {
  2065. function PDFFindController(options) {
  2066. this.pdfViewer = options.pdfViewer || null;
  2067. this.onUpdateResultsCount = null;
  2068. this.onUpdateState = null;
  2069. this.reset();
  2070. var replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
  2071. this.normalizationRegex = new RegExp('[' + replace + ']', 'g');
  2072. }
  2073. PDFFindController.prototype = {
  2074. reset: function PDFFindController_reset() {
  2075. var _this = this;
  2076. this.startedTextExtraction = false;
  2077. this.extractTextPromises = [];
  2078. this.pendingFindMatches = Object.create(null);
  2079. this.active = false;
  2080. this.pageContents = [];
  2081. this.pageMatches = [];
  2082. this.pageMatchesLength = null;
  2083. this.matchCount = 0;
  2084. this.selected = {
  2085. pageIdx: -1,
  2086. matchIdx: -1
  2087. };
  2088. this.offset = {
  2089. pageIdx: null,
  2090. matchIdx: null
  2091. };
  2092. this.pagesToSearch = null;
  2093. this.resumePageIdx = null;
  2094. this.state = null;
  2095. this.dirtyMatch = false;
  2096. this.findTimeout = null;
  2097. this._firstPagePromise = new Promise(function (resolve) {
  2098. _this.resolveFirstPage = resolve;
  2099. });
  2100. },
  2101. normalize: function PDFFindController_normalize(text) {
  2102. return text.replace(this.normalizationRegex, function (ch) {
  2103. return CHARACTERS_TO_NORMALIZE[ch];
  2104. });
  2105. },
  2106. _prepareMatches: function PDFFindController_prepareMatches(matchesWithLength, matches, matchesLength) {
  2107. function isSubTerm(matchesWithLength, currentIndex) {
  2108. var currentElem, prevElem, nextElem;
  2109. currentElem = matchesWithLength[currentIndex];
  2110. nextElem = matchesWithLength[currentIndex + 1];
  2111. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  2112. currentElem.skipped = true;
  2113. return true;
  2114. }
  2115. for (var i = currentIndex - 1; i >= 0; i--) {
  2116. prevElem = matchesWithLength[i];
  2117. if (prevElem.skipped) {
  2118. continue;
  2119. }
  2120. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  2121. break;
  2122. }
  2123. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  2124. currentElem.skipped = true;
  2125. return true;
  2126. }
  2127. }
  2128. return false;
  2129. }
  2130. var i, len;
  2131. matchesWithLength.sort(function (a, b) {
  2132. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  2133. });
  2134. for (i = 0, len = matchesWithLength.length; i < len; i++) {
  2135. if (isSubTerm(matchesWithLength, i)) {
  2136. continue;
  2137. }
  2138. matches.push(matchesWithLength[i].match);
  2139. matchesLength.push(matchesWithLength[i].matchLength);
  2140. }
  2141. },
  2142. calcFindPhraseMatch: function PDFFindController_calcFindPhraseMatch(query, pageIndex, pageContent) {
  2143. var matches = [];
  2144. var queryLen = query.length;
  2145. var matchIdx = -queryLen;
  2146. while (true) {
  2147. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  2148. if (matchIdx === -1) {
  2149. break;
  2150. }
  2151. matches.push(matchIdx);
  2152. }
  2153. this.pageMatches[pageIndex] = matches;
  2154. },
  2155. calcFindWordMatch: function PDFFindController_calcFindWordMatch(query, pageIndex, pageContent) {
  2156. var matchesWithLength = [];
  2157. var queryArray = query.match(/\S+/g);
  2158. var subquery, subqueryLen, matchIdx;
  2159. for (var i = 0, len = queryArray.length; i < len; i++) {
  2160. subquery = queryArray[i];
  2161. subqueryLen = subquery.length;
  2162. matchIdx = -subqueryLen;
  2163. while (true) {
  2164. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  2165. if (matchIdx === -1) {
  2166. break;
  2167. }
  2168. matchesWithLength.push({
  2169. match: matchIdx,
  2170. matchLength: subqueryLen,
  2171. skipped: false
  2172. });
  2173. }
  2174. }
  2175. if (!this.pageMatchesLength) {
  2176. this.pageMatchesLength = [];
  2177. }
  2178. this.pageMatchesLength[pageIndex] = [];
  2179. this.pageMatches[pageIndex] = [];
  2180. this._prepareMatches(matchesWithLength, this.pageMatches[pageIndex], this.pageMatchesLength[pageIndex]);
  2181. },
  2182. calcFindMatch: function PDFFindController_calcFindMatch(pageIndex) {
  2183. var pageContent = this.normalize(this.pageContents[pageIndex]);
  2184. var query = this.normalize(this.state.query);
  2185. var caseSensitive = this.state.caseSensitive;
  2186. var phraseSearch = this.state.phraseSearch;
  2187. var queryLen = query.length;
  2188. if (queryLen === 0) {
  2189. return;
  2190. }
  2191. if (!caseSensitive) {
  2192. pageContent = pageContent.toLowerCase();
  2193. query = query.toLowerCase();
  2194. }
  2195. if (phraseSearch) {
  2196. this.calcFindPhraseMatch(query, pageIndex, pageContent);
  2197. } else {
  2198. this.calcFindWordMatch(query, pageIndex, pageContent);
  2199. }
  2200. this.updatePage(pageIndex);
  2201. if (this.resumePageIdx === pageIndex) {
  2202. this.resumePageIdx = null;
  2203. this.nextPageMatch();
  2204. }
  2205. if (this.pageMatches[pageIndex].length > 0) {
  2206. this.matchCount += this.pageMatches[pageIndex].length;
  2207. this.updateUIResultsCount();
  2208. }
  2209. },
  2210. extractText: function extractText() {
  2211. var _this2 = this;
  2212. if (this.startedTextExtraction) {
  2213. return;
  2214. }
  2215. this.startedTextExtraction = true;
  2216. this.pageContents.length = 0;
  2217. var promise = Promise.resolve();
  2218. var _loop = function _loop(i, ii) {
  2219. var extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  2220. _this2.extractTextPromises[i] = extractTextCapability.promise;
  2221. promise = promise.then(function () {
  2222. return _this2.pdfViewer.getPageTextContent(i).then(function (textContent) {
  2223. var textItems = textContent.items;
  2224. var strBuf = [];
  2225. for (var j = 0, jj = textItems.length; j < jj; j++) {
  2226. strBuf.push(textItems[j].str);
  2227. }
  2228. _this2.pageContents[i] = strBuf.join('');
  2229. extractTextCapability.resolve(i);
  2230. });
  2231. });
  2232. };
  2233. for (var i = 0, ii = this.pdfViewer.pagesCount; i < ii; i++) {
  2234. _loop(i, ii);
  2235. }
  2236. },
  2237. executeCommand: function PDFFindController_executeCommand(cmd, state) {
  2238. var _this3 = this;
  2239. if (this.state === null || cmd !== 'findagain') {
  2240. this.dirtyMatch = true;
  2241. }
  2242. this.state = state;
  2243. this.updateUIState(FindStates.FIND_PENDING);
  2244. this._firstPagePromise.then(function () {
  2245. _this3.extractText();
  2246. clearTimeout(_this3.findTimeout);
  2247. if (cmd === 'find') {
  2248. _this3.findTimeout = setTimeout(_this3.nextMatch.bind(_this3), 250);
  2249. } else {
  2250. _this3.nextMatch();
  2251. }
  2252. });
  2253. },
  2254. updatePage: function PDFFindController_updatePage(index) {
  2255. if (this.selected.pageIdx === index) {
  2256. this.pdfViewer.currentPageNumber = index + 1;
  2257. }
  2258. var page = this.pdfViewer.getPageView(index);
  2259. if (page.textLayer) {
  2260. page.textLayer.updateMatches();
  2261. }
  2262. },
  2263. nextMatch: function PDFFindController_nextMatch() {
  2264. var _this4 = this;
  2265. var previous = this.state.findPrevious;
  2266. var currentPageIndex = this.pdfViewer.currentPageNumber - 1;
  2267. var numPages = this.pdfViewer.pagesCount;
  2268. this.active = true;
  2269. if (this.dirtyMatch) {
  2270. this.dirtyMatch = false;
  2271. this.selected.pageIdx = this.selected.matchIdx = -1;
  2272. this.offset.pageIdx = currentPageIndex;
  2273. this.offset.matchIdx = null;
  2274. this.hadMatch = false;
  2275. this.resumePageIdx = null;
  2276. this.pageMatches = [];
  2277. this.matchCount = 0;
  2278. this.pageMatchesLength = null;
  2279. for (var i = 0; i < numPages; i++) {
  2280. this.updatePage(i);
  2281. if (!(i in this.pendingFindMatches)) {
  2282. this.pendingFindMatches[i] = true;
  2283. this.extractTextPromises[i].then(function (pageIdx) {
  2284. delete _this4.pendingFindMatches[pageIdx];
  2285. _this4.calcFindMatch(pageIdx);
  2286. });
  2287. }
  2288. }
  2289. }
  2290. if (this.state.query === '') {
  2291. this.updateUIState(FindStates.FIND_FOUND);
  2292. return;
  2293. }
  2294. if (this.resumePageIdx) {
  2295. return;
  2296. }
  2297. var offset = this.offset;
  2298. this.pagesToSearch = numPages;
  2299. if (offset.matchIdx !== null) {
  2300. var numPageMatches = this.pageMatches[offset.pageIdx].length;
  2301. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  2302. this.hadMatch = true;
  2303. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  2304. this.updateMatch(true);
  2305. return;
  2306. }
  2307. this.advanceOffsetPage(previous);
  2308. }
  2309. this.nextPageMatch();
  2310. },
  2311. matchesReady: function PDFFindController_matchesReady(matches) {
  2312. var offset = this.offset;
  2313. var numMatches = matches.length;
  2314. var previous = this.state.findPrevious;
  2315. if (numMatches) {
  2316. this.hadMatch = true;
  2317. offset.matchIdx = previous ? numMatches - 1 : 0;
  2318. this.updateMatch(true);
  2319. return true;
  2320. }
  2321. this.advanceOffsetPage(previous);
  2322. if (offset.wrapped) {
  2323. offset.matchIdx = null;
  2324. if (this.pagesToSearch < 0) {
  2325. this.updateMatch(false);
  2326. return true;
  2327. }
  2328. }
  2329. return false;
  2330. },
  2331. updateMatchPosition: function PDFFindController_updateMatchPosition(pageIndex, index, elements, beginIdx) {
  2332. if (this.selected.matchIdx === index && this.selected.pageIdx === pageIndex) {
  2333. var spot = {
  2334. top: FIND_SCROLL_OFFSET_TOP,
  2335. left: FIND_SCROLL_OFFSET_LEFT
  2336. };
  2337. (0, _ui_utils.scrollIntoView)(elements[beginIdx], spot, true);
  2338. }
  2339. },
  2340. nextPageMatch: function PDFFindController_nextPageMatch() {
  2341. if (this.resumePageIdx !== null) {
  2342. console.error('There can only be one pending page.');
  2343. }
  2344. do {
  2345. var pageIdx = this.offset.pageIdx;
  2346. var matches = this.pageMatches[pageIdx];
  2347. if (!matches) {
  2348. this.resumePageIdx = pageIdx;
  2349. break;
  2350. }
  2351. } while (!this.matchesReady(matches));
  2352. },
  2353. advanceOffsetPage: function PDFFindController_advanceOffsetPage(previous) {
  2354. var offset = this.offset;
  2355. var numPages = this.extractTextPromises.length;
  2356. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  2357. offset.matchIdx = null;
  2358. this.pagesToSearch--;
  2359. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  2360. offset.pageIdx = previous ? numPages - 1 : 0;
  2361. offset.wrapped = true;
  2362. }
  2363. },
  2364. updateMatch: function PDFFindController_updateMatch(found) {
  2365. var state = FindStates.FIND_NOTFOUND;
  2366. var wrapped = this.offset.wrapped;
  2367. this.offset.wrapped = false;
  2368. if (found) {
  2369. var previousPage = this.selected.pageIdx;
  2370. this.selected.pageIdx = this.offset.pageIdx;
  2371. this.selected.matchIdx = this.offset.matchIdx;
  2372. state = wrapped ? FindStates.FIND_WRAPPED : FindStates.FIND_FOUND;
  2373. if (previousPage !== -1 && previousPage !== this.selected.pageIdx) {
  2374. this.updatePage(previousPage);
  2375. }
  2376. }
  2377. this.updateUIState(state, this.state.findPrevious);
  2378. if (this.selected.pageIdx !== -1) {
  2379. this.updatePage(this.selected.pageIdx);
  2380. }
  2381. },
  2382. updateUIResultsCount: function PDFFindController_updateUIResultsCount() {
  2383. if (this.onUpdateResultsCount) {
  2384. this.onUpdateResultsCount(this.matchCount);
  2385. }
  2386. },
  2387. updateUIState: function PDFFindController_updateUIState(state, previous) {
  2388. if (this.onUpdateState) {
  2389. this.onUpdateState(state, previous, this.matchCount);
  2390. }
  2391. }
  2392. };
  2393. return PDFFindController;
  2394. }();
  2395. exports.FindStates = FindStates;
  2396. exports.PDFFindController = PDFFindController;
  2397. /***/ }),
  2398. /* 10 */
  2399. /***/ (function(module, exports, __w_pdfjs_require__) {
  2400. "use strict";
  2401. Object.defineProperty(exports, "__esModule", {
  2402. value: true
  2403. });
  2404. exports.PDFHistory = undefined;
  2405. var _dom_events = __w_pdfjs_require__(2);
  2406. function PDFHistory(options) {
  2407. this.linkService = options.linkService;
  2408. this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
  2409. this.initialized = false;
  2410. this.initialDestination = null;
  2411. this.initialBookmark = null;
  2412. }
  2413. PDFHistory.prototype = {
  2414. initialize: function pdfHistoryInitialize(fingerprint) {
  2415. this.initialized = true;
  2416. this.reInitialized = false;
  2417. this.allowHashChange = true;
  2418. this.historyUnlocked = true;
  2419. this.isViewerInPresentationMode = false;
  2420. this.previousHash = window.location.hash.substring(1);
  2421. this.currentBookmark = '';
  2422. this.currentPage = 0;
  2423. this.updatePreviousBookmark = false;
  2424. this.previousBookmark = '';
  2425. this.previousPage = 0;
  2426. this.nextHashParam = '';
  2427. this.fingerprint = fingerprint;
  2428. this.currentUid = this.uid = 0;
  2429. this.current = {};
  2430. var state = window.history.state;
  2431. if (this._isStateObjectDefined(state)) {
  2432. if (state.target.dest) {
  2433. this.initialDestination = state.target.dest;
  2434. } else {
  2435. this.initialBookmark = state.target.hash;
  2436. }
  2437. this.currentUid = state.uid;
  2438. this.uid = state.uid + 1;
  2439. this.current = state.target;
  2440. } else {
  2441. if (state && state.fingerprint && this.fingerprint !== state.fingerprint) {
  2442. this.reInitialized = true;
  2443. }
  2444. this._pushOrReplaceState({ fingerprint: this.fingerprint }, true);
  2445. }
  2446. var self = this;
  2447. window.addEventListener('popstate', function pdfHistoryPopstate(evt) {
  2448. if (!self.historyUnlocked) {
  2449. return;
  2450. }
  2451. if (evt.state) {
  2452. self._goTo(evt.state);
  2453. return;
  2454. }
  2455. if (self.uid === 0) {
  2456. var previousParams = self.previousHash && self.currentBookmark && self.previousHash !== self.currentBookmark ? {
  2457. hash: self.currentBookmark,
  2458. page: self.currentPage
  2459. } : { page: 1 };
  2460. replacePreviousHistoryState(previousParams, function () {
  2461. updateHistoryWithCurrentHash();
  2462. });
  2463. } else {
  2464. updateHistoryWithCurrentHash();
  2465. }
  2466. });
  2467. function updateHistoryWithCurrentHash() {
  2468. self.previousHash = window.location.hash.slice(1);
  2469. self._pushToHistory({ hash: self.previousHash }, false, true);
  2470. self._updatePreviousBookmark();
  2471. }
  2472. function replacePreviousHistoryState(params, callback) {
  2473. self.historyUnlocked = false;
  2474. self.allowHashChange = false;
  2475. window.addEventListener('popstate', rewriteHistoryAfterBack);
  2476. history.back();
  2477. function rewriteHistoryAfterBack() {
  2478. window.removeEventListener('popstate', rewriteHistoryAfterBack);
  2479. window.addEventListener('popstate', rewriteHistoryAfterForward);
  2480. self._pushToHistory(params, false, true);
  2481. history.forward();
  2482. }
  2483. function rewriteHistoryAfterForward() {
  2484. window.removeEventListener('popstate', rewriteHistoryAfterForward);
  2485. self.allowHashChange = true;
  2486. self.historyUnlocked = true;
  2487. callback();
  2488. }
  2489. }
  2490. function pdfHistoryBeforeUnload() {
  2491. var previousParams = self._getPreviousParams(null, true);
  2492. if (previousParams) {
  2493. var replacePrevious = !self.current.dest && self.current.hash !== self.previousHash;
  2494. self._pushToHistory(previousParams, false, replacePrevious);
  2495. self._updatePreviousBookmark();
  2496. }
  2497. window.removeEventListener('beforeunload', pdfHistoryBeforeUnload);
  2498. }
  2499. window.addEventListener('beforeunload', pdfHistoryBeforeUnload);
  2500. window.addEventListener('pageshow', function pdfHistoryPageShow(evt) {
  2501. window.addEventListener('beforeunload', pdfHistoryBeforeUnload);
  2502. });
  2503. self.eventBus.on('presentationmodechanged', function (e) {
  2504. self.isViewerInPresentationMode = e.active;
  2505. });
  2506. },
  2507. clearHistoryState: function pdfHistory_clearHistoryState() {
  2508. this._pushOrReplaceState(null, true);
  2509. },
  2510. _isStateObjectDefined: function pdfHistory_isStateObjectDefined(state) {
  2511. return state && state.uid >= 0 && state.fingerprint && this.fingerprint === state.fingerprint && state.target && state.target.hash ? true : false;
  2512. },
  2513. _pushOrReplaceState: function pdfHistory_pushOrReplaceState(stateObj, replace) {
  2514. if (replace) {
  2515. window.history.replaceState(stateObj, '', document.URL);
  2516. } else {
  2517. window.history.pushState(stateObj, '', document.URL);
  2518. }
  2519. },
  2520. get isHashChangeUnlocked() {
  2521. if (!this.initialized) {
  2522. return true;
  2523. }
  2524. return this.allowHashChange;
  2525. },
  2526. _updatePreviousBookmark: function pdfHistory_updatePreviousBookmark() {
  2527. if (this.updatePreviousBookmark && this.currentBookmark && this.currentPage) {
  2528. this.previousBookmark = this.currentBookmark;
  2529. this.previousPage = this.currentPage;
  2530. this.updatePreviousBookmark = false;
  2531. }
  2532. },
  2533. updateCurrentBookmark: function pdfHistoryUpdateCurrentBookmark(bookmark, pageNum) {
  2534. if (this.initialized) {
  2535. this.currentBookmark = bookmark.substring(1);
  2536. this.currentPage = pageNum | 0;
  2537. this._updatePreviousBookmark();
  2538. }
  2539. },
  2540. updateNextHashParam: function pdfHistoryUpdateNextHashParam(param) {
  2541. if (this.initialized) {
  2542. this.nextHashParam = param;
  2543. }
  2544. },
  2545. push: function pdfHistoryPush(params, isInitialBookmark) {
  2546. if (!(this.initialized && this.historyUnlocked)) {
  2547. return;
  2548. }
  2549. if (params.dest && !params.hash) {
  2550. params.hash = this.current.hash && this.current.dest && this.current.dest === params.dest ? this.current.hash : this.linkService.getDestinationHash(params.dest).split('#')[1];
  2551. }
  2552. if (params.page) {
  2553. params.page |= 0;
  2554. }
  2555. if (isInitialBookmark) {
  2556. var target = window.history.state.target;
  2557. if (!target) {
  2558. this._pushToHistory(params, false);
  2559. this.previousHash = window.location.hash.substring(1);
  2560. }
  2561. this.updatePreviousBookmark = this.nextHashParam ? false : true;
  2562. if (target) {
  2563. this._updatePreviousBookmark();
  2564. }
  2565. return;
  2566. }
  2567. if (this.nextHashParam) {
  2568. if (this.nextHashParam === params.hash) {
  2569. this.nextHashParam = null;
  2570. this.updatePreviousBookmark = true;
  2571. return;
  2572. }
  2573. this.nextHashParam = null;
  2574. }
  2575. if (params.hash) {
  2576. if (this.current.hash) {
  2577. if (this.current.hash !== params.hash) {
  2578. this._pushToHistory(params, true);
  2579. } else {
  2580. if (!this.current.page && params.page) {
  2581. this._pushToHistory(params, false, true);
  2582. }
  2583. this.updatePreviousBookmark = true;
  2584. }
  2585. } else {
  2586. this._pushToHistory(params, true);
  2587. }
  2588. } else if (this.current.page && params.page && this.current.page !== params.page) {
  2589. this._pushToHistory(params, true);
  2590. }
  2591. },
  2592. _getPreviousParams: function pdfHistory_getPreviousParams(onlyCheckPage, beforeUnload) {
  2593. if (!(this.currentBookmark && this.currentPage)) {
  2594. return null;
  2595. } else if (this.updatePreviousBookmark) {
  2596. this.updatePreviousBookmark = false;
  2597. }
  2598. if (this.uid > 0 && !(this.previousBookmark && this.previousPage)) {
  2599. return null;
  2600. }
  2601. if (!this.current.dest && !onlyCheckPage || beforeUnload) {
  2602. if (this.previousBookmark === this.currentBookmark) {
  2603. return null;
  2604. }
  2605. } else if (this.current.page || onlyCheckPage) {
  2606. if (this.previousPage === this.currentPage) {
  2607. return null;
  2608. }
  2609. } else {
  2610. return null;
  2611. }
  2612. var params = {
  2613. hash: this.currentBookmark,
  2614. page: this.currentPage
  2615. };
  2616. if (this.isViewerInPresentationMode) {
  2617. params.hash = null;
  2618. }
  2619. return params;
  2620. },
  2621. _stateObj: function pdfHistory_stateObj(params) {
  2622. return {
  2623. fingerprint: this.fingerprint,
  2624. uid: this.uid,
  2625. target: params
  2626. };
  2627. },
  2628. _pushToHistory: function pdfHistory_pushToHistory(params, addPrevious, overwrite) {
  2629. if (!this.initialized) {
  2630. return;
  2631. }
  2632. if (!params.hash && params.page) {
  2633. params.hash = 'page=' + params.page;
  2634. }
  2635. if (addPrevious && !overwrite) {
  2636. var previousParams = this._getPreviousParams();
  2637. if (previousParams) {
  2638. var replacePrevious = !this.current.dest && this.current.hash !== this.previousHash;
  2639. this._pushToHistory(previousParams, false, replacePrevious);
  2640. }
  2641. }
  2642. this._pushOrReplaceState(this._stateObj(params), overwrite || this.uid === 0);
  2643. this.currentUid = this.uid++;
  2644. this.current = params;
  2645. this.updatePreviousBookmark = true;
  2646. },
  2647. _goTo: function pdfHistory_goTo(state) {
  2648. if (!(this.initialized && this.historyUnlocked && this._isStateObjectDefined(state))) {
  2649. return;
  2650. }
  2651. if (!this.reInitialized && state.uid < this.currentUid) {
  2652. var previousParams = this._getPreviousParams(true);
  2653. if (previousParams) {
  2654. this._pushToHistory(this.current, false);
  2655. this._pushToHistory(previousParams, false);
  2656. this.currentUid = state.uid;
  2657. window.history.back();
  2658. return;
  2659. }
  2660. }
  2661. this.historyUnlocked = false;
  2662. if (state.target.dest) {
  2663. this.linkService.navigateTo(state.target.dest);
  2664. } else {
  2665. this.linkService.setHash(state.target.hash);
  2666. }
  2667. this.currentUid = state.uid;
  2668. if (state.uid > this.uid) {
  2669. this.uid = state.uid;
  2670. }
  2671. this.current = state.target;
  2672. this.updatePreviousBookmark = true;
  2673. var currentHash = window.location.hash.substring(1);
  2674. if (this.previousHash !== currentHash) {
  2675. this.allowHashChange = false;
  2676. }
  2677. this.previousHash = currentHash;
  2678. this.historyUnlocked = true;
  2679. },
  2680. back: function pdfHistoryBack() {
  2681. this.go(-1);
  2682. },
  2683. forward: function pdfHistoryForward() {
  2684. this.go(1);
  2685. },
  2686. go: function pdfHistoryGo(direction) {
  2687. if (this.initialized && this.historyUnlocked) {
  2688. var state = window.history.state;
  2689. if (direction === -1 && state && state.uid > 0) {
  2690. window.history.back();
  2691. } else if (direction === 1 && state && state.uid < this.uid - 1) {
  2692. window.history.forward();
  2693. }
  2694. }
  2695. }
  2696. };
  2697. exports.PDFHistory = PDFHistory;
  2698. /***/ }),
  2699. /* 11 */
  2700. /***/ (function(module, exports, __w_pdfjs_require__) {
  2701. "use strict";
  2702. Object.defineProperty(exports, "__esModule", {
  2703. value: true
  2704. });
  2705. exports.PDFViewer = exports.PresentationModeState = undefined;
  2706. var _pdfjsLib = __w_pdfjs_require__(0);
  2707. var _ui_utils = __w_pdfjs_require__(1);
  2708. var _pdf_rendering_queue = __w_pdfjs_require__(7);
  2709. var _annotation_layer_builder = __w_pdfjs_require__(4);
  2710. var _dom_events = __w_pdfjs_require__(2);
  2711. var _pdf_page_view = __w_pdfjs_require__(5);
  2712. var _pdf_link_service = __w_pdfjs_require__(3);
  2713. var _text_layer_builder = __w_pdfjs_require__(6);
  2714. var PresentationModeState = {
  2715. UNKNOWN: 0,
  2716. NORMAL: 1,
  2717. CHANGING: 2,
  2718. FULLSCREEN: 3
  2719. };
  2720. var DEFAULT_CACHE_SIZE = 10;
  2721. var PDFViewer = function pdfViewer() {
  2722. function PDFPageViewBuffer(size) {
  2723. var data = [];
  2724. this.push = function cachePush(view) {
  2725. var i = data.indexOf(view);
  2726. if (i >= 0) {
  2727. data.splice(i, 1);
  2728. }
  2729. data.push(view);
  2730. if (data.length > size) {
  2731. data.shift().destroy();
  2732. }
  2733. };
  2734. this.resize = function (newSize) {
  2735. size = newSize;
  2736. while (data.length > size) {
  2737. data.shift().destroy();
  2738. }
  2739. };
  2740. }
  2741. function isSameScale(oldScale, newScale) {
  2742. if (newScale === oldScale) {
  2743. return true;
  2744. }
  2745. if (Math.abs(newScale - oldScale) < 1e-15) {
  2746. return true;
  2747. }
  2748. return false;
  2749. }
  2750. function isPortraitOrientation(size) {
  2751. return size.width <= size.height;
  2752. }
  2753. function PDFViewer(options) {
  2754. this.container = options.container;
  2755. this.viewer = options.viewer || options.container.firstElementChild;
  2756. this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
  2757. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  2758. this.downloadManager = options.downloadManager || null;
  2759. this.removePageBorders = options.removePageBorders || false;
  2760. this.enhanceTextSelection = options.enhanceTextSelection || false;
  2761. this.renderInteractiveForms = options.renderInteractiveForms || false;
  2762. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  2763. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  2764. this.defaultRenderingQueue = !options.renderingQueue;
  2765. if (this.defaultRenderingQueue) {
  2766. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  2767. this.renderingQueue.setViewer(this);
  2768. } else {
  2769. this.renderingQueue = options.renderingQueue;
  2770. }
  2771. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  2772. this.presentationModeState = PresentationModeState.UNKNOWN;
  2773. this._resetView();
  2774. if (this.removePageBorders) {
  2775. this.viewer.classList.add('removePageBorders');
  2776. }
  2777. }
  2778. PDFViewer.prototype = {
  2779. get pagesCount() {
  2780. return this._pages.length;
  2781. },
  2782. getPageView: function getPageView(index) {
  2783. return this._pages[index];
  2784. },
  2785. get pageViewsReady() {
  2786. return this._pageViewsReady;
  2787. },
  2788. get currentPageNumber() {
  2789. return this._currentPageNumber;
  2790. },
  2791. set currentPageNumber(val) {
  2792. if ((val | 0) !== val) {
  2793. throw new Error('Invalid page number.');
  2794. }
  2795. if (!this.pdfDocument) {
  2796. this._currentPageNumber = val;
  2797. return;
  2798. }
  2799. this._setCurrentPageNumber(val, true);
  2800. },
  2801. _setCurrentPageNumber: function PDFViewer_setCurrentPageNumber(val, resetCurrentPageView) {
  2802. if (this._currentPageNumber === val) {
  2803. if (resetCurrentPageView) {
  2804. this._resetCurrentPageView();
  2805. }
  2806. return;
  2807. }
  2808. if (!(0 < val && val <= this.pagesCount)) {
  2809. console.error('PDFViewer_setCurrentPageNumber: "' + val + '" is out of bounds.');
  2810. return;
  2811. }
  2812. var arg = {
  2813. source: this,
  2814. pageNumber: val,
  2815. pageLabel: this._pageLabels && this._pageLabels[val - 1]
  2816. };
  2817. this._currentPageNumber = val;
  2818. this.eventBus.dispatch('pagechanging', arg);
  2819. this.eventBus.dispatch('pagechange', arg);
  2820. if (resetCurrentPageView) {
  2821. this._resetCurrentPageView();
  2822. }
  2823. },
  2824. get currentPageLabel() {
  2825. return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
  2826. },
  2827. set currentPageLabel(val) {
  2828. var pageNumber = val | 0;
  2829. if (this._pageLabels) {
  2830. var i = this._pageLabels.indexOf(val);
  2831. if (i >= 0) {
  2832. pageNumber = i + 1;
  2833. }
  2834. }
  2835. this.currentPageNumber = pageNumber;
  2836. },
  2837. get currentScale() {
  2838. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  2839. },
  2840. set currentScale(val) {
  2841. if (isNaN(val)) {
  2842. throw new Error('Invalid numeric scale');
  2843. }
  2844. if (!this.pdfDocument) {
  2845. this._currentScale = val;
  2846. this._currentScaleValue = val !== _ui_utils.UNKNOWN_SCALE ? val.toString() : null;
  2847. return;
  2848. }
  2849. this._setScale(val, false);
  2850. },
  2851. get currentScaleValue() {
  2852. return this._currentScaleValue;
  2853. },
  2854. set currentScaleValue(val) {
  2855. if (!this.pdfDocument) {
  2856. this._currentScale = isNaN(val) ? _ui_utils.UNKNOWN_SCALE : val;
  2857. this._currentScaleValue = val.toString();
  2858. return;
  2859. }
  2860. this._setScale(val, false);
  2861. },
  2862. get pagesRotation() {
  2863. return this._pagesRotation;
  2864. },
  2865. set pagesRotation(rotation) {
  2866. if (!(typeof rotation === 'number' && rotation % 90 === 0)) {
  2867. throw new Error('Invalid pages rotation angle.');
  2868. }
  2869. this._pagesRotation = rotation;
  2870. if (!this.pdfDocument) {
  2871. return;
  2872. }
  2873. for (var i = 0, l = this._pages.length; i < l; i++) {
  2874. var pageView = this._pages[i];
  2875. pageView.update(pageView.scale, rotation);
  2876. }
  2877. this._setScale(this._currentScaleValue, true);
  2878. if (this.defaultRenderingQueue) {
  2879. this.update();
  2880. }
  2881. },
  2882. setDocument: function setDocument(pdfDocument) {
  2883. var _this = this;
  2884. if (this.pdfDocument) {
  2885. this._cancelRendering();
  2886. this._resetView();
  2887. }
  2888. this.pdfDocument = pdfDocument;
  2889. if (!pdfDocument) {
  2890. return;
  2891. }
  2892. var pagesCount = pdfDocument.numPages;
  2893. var pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  2894. this.pagesPromise = pagesCapability.promise;
  2895. pagesCapability.promise.then(function () {
  2896. _this._pageViewsReady = true;
  2897. _this.eventBus.dispatch('pagesloaded', {
  2898. source: _this,
  2899. pagesCount: pagesCount
  2900. });
  2901. });
  2902. var isOnePageRenderedResolved = false;
  2903. var onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  2904. this.onePageRendered = onePageRenderedCapability.promise;
  2905. var bindOnAfterAndBeforeDraw = function bindOnAfterAndBeforeDraw(pageView) {
  2906. pageView.onBeforeDraw = function () {
  2907. _this._buffer.push(pageView);
  2908. };
  2909. pageView.onAfterDraw = function () {
  2910. if (!isOnePageRenderedResolved) {
  2911. isOnePageRenderedResolved = true;
  2912. onePageRenderedCapability.resolve();
  2913. }
  2914. };
  2915. };
  2916. var firstPagePromise = pdfDocument.getPage(1);
  2917. this.firstPagePromise = firstPagePromise;
  2918. return firstPagePromise.then(function (pdfPage) {
  2919. var scale = _this.currentScale;
  2920. var viewport = pdfPage.getViewport(scale * _ui_utils.CSS_UNITS);
  2921. for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  2922. var textLayerFactory = null;
  2923. if (!_pdfjsLib.PDFJS.disableTextLayer) {
  2924. textLayerFactory = _this;
  2925. }
  2926. var pageView = new _pdf_page_view.PDFPageView({
  2927. container: _this.viewer,
  2928. eventBus: _this.eventBus,
  2929. id: pageNum,
  2930. scale: scale,
  2931. defaultViewport: viewport.clone(),
  2932. renderingQueue: _this.renderingQueue,
  2933. textLayerFactory: textLayerFactory,
  2934. annotationLayerFactory: _this,
  2935. enhanceTextSelection: _this.enhanceTextSelection,
  2936. renderInteractiveForms: _this.renderInteractiveForms,
  2937. renderer: _this.renderer
  2938. });
  2939. bindOnAfterAndBeforeDraw(pageView);
  2940. _this._pages.push(pageView);
  2941. }
  2942. onePageRenderedCapability.promise.then(function () {
  2943. if (_pdfjsLib.PDFJS.disableAutoFetch) {
  2944. pagesCapability.resolve();
  2945. return;
  2946. }
  2947. var getPagesLeft = pagesCount;
  2948. var _loop = function _loop(_pageNum) {
  2949. pdfDocument.getPage(_pageNum).then(function (pdfPage) {
  2950. var pageView = _this._pages[_pageNum - 1];
  2951. if (!pageView.pdfPage) {
  2952. pageView.setPdfPage(pdfPage);
  2953. }
  2954. _this.linkService.cachePageRef(_pageNum, pdfPage.ref);
  2955. if (--getPagesLeft === 0) {
  2956. pagesCapability.resolve();
  2957. }
  2958. });
  2959. };
  2960. for (var _pageNum = 1; _pageNum <= pagesCount; ++_pageNum) {
  2961. _loop(_pageNum);
  2962. }
  2963. });
  2964. _this.eventBus.dispatch('pagesinit', { source: _this });
  2965. if (_this.defaultRenderingQueue) {
  2966. _this.update();
  2967. }
  2968. if (_this.findController) {
  2969. _this.findController.resolveFirstPage();
  2970. }
  2971. });
  2972. },
  2973. setPageLabels: function PDFViewer_setPageLabels(labels) {
  2974. if (!this.pdfDocument) {
  2975. return;
  2976. }
  2977. if (!labels) {
  2978. this._pageLabels = null;
  2979. } else if (!(labels instanceof Array && this.pdfDocument.numPages === labels.length)) {
  2980. this._pageLabels = null;
  2981. console.error('PDFViewer_setPageLabels: Invalid page labels.');
  2982. } else {
  2983. this._pageLabels = labels;
  2984. }
  2985. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  2986. var pageView = this._pages[i];
  2987. var label = this._pageLabels && this._pageLabels[i];
  2988. pageView.setPageLabel(label);
  2989. }
  2990. },
  2991. _resetView: function _resetView() {
  2992. this._pages = [];
  2993. this._currentPageNumber = 1;
  2994. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  2995. this._currentScaleValue = null;
  2996. this._pageLabels = null;
  2997. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  2998. this._location = null;
  2999. this._pagesRotation = 0;
  3000. this._pagesRequests = [];
  3001. this._pageViewsReady = false;
  3002. this.viewer.textContent = '';
  3003. },
  3004. _scrollUpdate: function PDFViewer_scrollUpdate() {
  3005. if (this.pagesCount === 0) {
  3006. return;
  3007. }
  3008. this.update();
  3009. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  3010. this._pages[i].updatePosition();
  3011. }
  3012. },
  3013. _setScaleDispatchEvent: function pdfViewer_setScaleDispatchEvent(newScale, newValue, preset) {
  3014. var arg = {
  3015. source: this,
  3016. scale: newScale,
  3017. presetValue: preset ? newValue : undefined
  3018. };
  3019. this.eventBus.dispatch('scalechanging', arg);
  3020. this.eventBus.dispatch('scalechange', arg);
  3021. },
  3022. _setScaleUpdatePages: function pdfViewer_setScaleUpdatePages(newScale, newValue, noScroll, preset) {
  3023. this._currentScaleValue = newValue.toString();
  3024. if (isSameScale(this._currentScale, newScale)) {
  3025. if (preset) {
  3026. this._setScaleDispatchEvent(newScale, newValue, true);
  3027. }
  3028. return;
  3029. }
  3030. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  3031. this._pages[i].update(newScale);
  3032. }
  3033. this._currentScale = newScale;
  3034. if (!noScroll) {
  3035. var page = this._currentPageNumber,
  3036. dest;
  3037. if (this._location && !_pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  3038. page = this._location.pageNumber;
  3039. dest = [null, { name: 'XYZ' }, this._location.left, this._location.top, null];
  3040. }
  3041. this.scrollPageIntoView({
  3042. pageNumber: page,
  3043. destArray: dest,
  3044. allowNegativeOffset: true
  3045. });
  3046. }
  3047. this._setScaleDispatchEvent(newScale, newValue, preset);
  3048. if (this.defaultRenderingQueue) {
  3049. this.update();
  3050. }
  3051. },
  3052. _setScale: function PDFViewer_setScale(value, noScroll) {
  3053. var scale = parseFloat(value);
  3054. if (scale > 0) {
  3055. this._setScaleUpdatePages(scale, value, noScroll, false);
  3056. } else {
  3057. var currentPage = this._pages[this._currentPageNumber - 1];
  3058. if (!currentPage) {
  3059. return;
  3060. }
  3061. var hPadding = this.isInPresentationMode || this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  3062. var vPadding = this.isInPresentationMode || this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  3063. var pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale;
  3064. var pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  3065. switch (value) {
  3066. case 'page-actual':
  3067. scale = 1;
  3068. break;
  3069. case 'page-width':
  3070. scale = pageWidthScale;
  3071. break;
  3072. case 'page-height':
  3073. scale = pageHeightScale;
  3074. break;
  3075. case 'page-fit':
  3076. scale = Math.min(pageWidthScale, pageHeightScale);
  3077. break;
  3078. case 'auto':
  3079. var isLandscape = currentPage.width > currentPage.height;
  3080. var horizontalScale = isLandscape ? Math.min(pageHeightScale, pageWidthScale) : pageWidthScale;
  3081. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  3082. break;
  3083. default:
  3084. console.error('PDFViewer_setScale: "' + value + '" is an unknown zoom value.');
  3085. return;
  3086. }
  3087. this._setScaleUpdatePages(scale, value, noScroll, true);
  3088. }
  3089. },
  3090. _resetCurrentPageView: function _resetCurrentPageView() {
  3091. if (this.isInPresentationMode) {
  3092. this._setScale(this._currentScaleValue, true);
  3093. }
  3094. var pageView = this._pages[this._currentPageNumber - 1];
  3095. (0, _ui_utils.scrollIntoView)(pageView.div);
  3096. },
  3097. scrollPageIntoView: function PDFViewer_scrollPageIntoView(params) {
  3098. if (!this.pdfDocument) {
  3099. return;
  3100. }
  3101. if (arguments.length > 1 || typeof params === 'number') {
  3102. console.warn('Call of scrollPageIntoView() with obsolete signature.');
  3103. var paramObj = {};
  3104. if (typeof params === 'number') {
  3105. paramObj.pageNumber = params;
  3106. }
  3107. if (arguments[1] instanceof Array) {
  3108. paramObj.destArray = arguments[1];
  3109. }
  3110. params = paramObj;
  3111. }
  3112. var pageNumber = params.pageNumber || 0;
  3113. var dest = params.destArray || null;
  3114. var allowNegativeOffset = params.allowNegativeOffset || false;
  3115. if (this.isInPresentationMode || !dest) {
  3116. this._setCurrentPageNumber(pageNumber, true);
  3117. return;
  3118. }
  3119. var pageView = this._pages[pageNumber - 1];
  3120. if (!pageView) {
  3121. console.error('PDFViewer_scrollPageIntoView: ' + 'Invalid "pageNumber" parameter.');
  3122. return;
  3123. }
  3124. var x = 0,
  3125. y = 0;
  3126. var width = 0,
  3127. height = 0,
  3128. widthScale,
  3129. heightScale;
  3130. var changeOrientation = pageView.rotation % 180 === 0 ? false : true;
  3131. var pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
  3132. var pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
  3133. var scale = 0;
  3134. switch (dest[1].name) {
  3135. case 'XYZ':
  3136. x = dest[2];
  3137. y = dest[3];
  3138. scale = dest[4];
  3139. x = x !== null ? x : 0;
  3140. y = y !== null ? y : pageHeight;
  3141. break;
  3142. case 'Fit':
  3143. case 'FitB':
  3144. scale = 'page-fit';
  3145. break;
  3146. case 'FitH':
  3147. case 'FitBH':
  3148. y = dest[2];
  3149. scale = 'page-width';
  3150. if (y === null && this._location) {
  3151. x = this._location.left;
  3152. y = this._location.top;
  3153. }
  3154. break;
  3155. case 'FitV':
  3156. case 'FitBV':
  3157. x = dest[2];
  3158. width = pageWidth;
  3159. height = pageHeight;
  3160. scale = 'page-height';
  3161. break;
  3162. case 'FitR':
  3163. x = dest[2];
  3164. y = dest[3];
  3165. width = dest[4] - x;
  3166. height = dest[5] - y;
  3167. var hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  3168. var vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  3169. widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
  3170. heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
  3171. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  3172. break;
  3173. default:
  3174. console.error('PDFViewer_scrollPageIntoView: \'' + dest[1].name + '\' is not a valid destination type.');
  3175. return;
  3176. }
  3177. if (scale && scale !== this._currentScale) {
  3178. this.currentScaleValue = scale;
  3179. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  3180. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  3181. }
  3182. if (scale === 'page-fit' && !dest[4]) {
  3183. (0, _ui_utils.scrollIntoView)(pageView.div);
  3184. return;
  3185. }
  3186. var boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  3187. var left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  3188. var top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  3189. if (!allowNegativeOffset) {
  3190. left = Math.max(left, 0);
  3191. top = Math.max(top, 0);
  3192. }
  3193. (0, _ui_utils.scrollIntoView)(pageView.div, {
  3194. left: left,
  3195. top: top
  3196. });
  3197. },
  3198. _updateLocation: function _updateLocation(firstPage) {
  3199. var currentScale = this._currentScale;
  3200. var currentScaleValue = this._currentScaleValue;
  3201. var normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  3202. var pageNumber = firstPage.id;
  3203. var pdfOpenParams = '#page=' + pageNumber;
  3204. pdfOpenParams += '&zoom=' + normalizedScaleValue;
  3205. var currentPageView = this._pages[pageNumber - 1];
  3206. var container = this.container;
  3207. var topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  3208. var intLeft = Math.round(topLeft[0]);
  3209. var intTop = Math.round(topLeft[1]);
  3210. pdfOpenParams += ',' + intLeft + ',' + intTop;
  3211. this._location = {
  3212. pageNumber: pageNumber,
  3213. scale: normalizedScaleValue,
  3214. top: intTop,
  3215. left: intLeft,
  3216. pdfOpenParams: pdfOpenParams
  3217. };
  3218. },
  3219. update: function PDFViewer_update() {
  3220. var visible = this._getVisiblePages();
  3221. var visiblePages = visible.views;
  3222. if (visiblePages.length === 0) {
  3223. return;
  3224. }
  3225. var suggestedCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * visiblePages.length + 1);
  3226. this._buffer.resize(suggestedCacheSize);
  3227. this.renderingQueue.renderHighestPriority(visible);
  3228. var currentId = this._currentPageNumber;
  3229. var firstPage = visible.first;
  3230. for (var i = 0, ii = visiblePages.length, stillFullyVisible = false; i < ii; ++i) {
  3231. var page = visiblePages[i];
  3232. if (page.percent < 100) {
  3233. break;
  3234. }
  3235. if (page.id === currentId) {
  3236. stillFullyVisible = true;
  3237. break;
  3238. }
  3239. }
  3240. if (!stillFullyVisible) {
  3241. currentId = visiblePages[0].id;
  3242. }
  3243. if (!this.isInPresentationMode) {
  3244. this._setCurrentPageNumber(currentId);
  3245. }
  3246. this._updateLocation(firstPage);
  3247. this.eventBus.dispatch('updateviewarea', {
  3248. source: this,
  3249. location: this._location
  3250. });
  3251. },
  3252. containsElement: function containsElement(element) {
  3253. return this.container.contains(element);
  3254. },
  3255. focus: function focus() {
  3256. this.container.focus();
  3257. },
  3258. get isInPresentationMode() {
  3259. return this.presentationModeState === PresentationModeState.FULLSCREEN;
  3260. },
  3261. get isChangingPresentationMode() {
  3262. return this.presentationModeState === PresentationModeState.CHANGING;
  3263. },
  3264. get isHorizontalScrollbarEnabled() {
  3265. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  3266. },
  3267. _getVisiblePages: function _getVisiblePages() {
  3268. if (!this.isInPresentationMode) {
  3269. return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true);
  3270. }
  3271. var visible = [];
  3272. var currentPage = this._pages[this._currentPageNumber - 1];
  3273. visible.push({
  3274. id: currentPage.id,
  3275. view: currentPage
  3276. });
  3277. return {
  3278. first: currentPage,
  3279. last: currentPage,
  3280. views: visible
  3281. };
  3282. },
  3283. cleanup: function cleanup() {
  3284. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  3285. if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  3286. this._pages[i].reset();
  3287. }
  3288. }
  3289. },
  3290. _cancelRendering: function PDFViewer_cancelRendering() {
  3291. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  3292. if (this._pages[i]) {
  3293. this._pages[i].cancelRendering();
  3294. }
  3295. }
  3296. },
  3297. _ensurePdfPageLoaded: function _ensurePdfPageLoaded(pageView) {
  3298. var _this2 = this;
  3299. if (pageView.pdfPage) {
  3300. return Promise.resolve(pageView.pdfPage);
  3301. }
  3302. var pageNumber = pageView.id;
  3303. if (this._pagesRequests[pageNumber]) {
  3304. return this._pagesRequests[pageNumber];
  3305. }
  3306. var promise = this.pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  3307. if (!pageView.pdfPage) {
  3308. pageView.setPdfPage(pdfPage);
  3309. }
  3310. _this2._pagesRequests[pageNumber] = null;
  3311. return pdfPage;
  3312. });
  3313. this._pagesRequests[pageNumber] = promise;
  3314. return promise;
  3315. },
  3316. forceRendering: function forceRendering(currentlyVisiblePages) {
  3317. var _this3 = this;
  3318. var visiblePages = currentlyVisiblePages || this._getVisiblePages();
  3319. var pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, this.scroll.down);
  3320. if (pageView) {
  3321. this._ensurePdfPageLoaded(pageView).then(function () {
  3322. _this3.renderingQueue.renderView(pageView);
  3323. });
  3324. return true;
  3325. }
  3326. return false;
  3327. },
  3328. getPageTextContent: function getPageTextContent(pageIndex) {
  3329. return this.pdfDocument.getPage(pageIndex + 1).then(function (page) {
  3330. return page.getTextContent({ normalizeWhitespace: true });
  3331. });
  3332. },
  3333. createTextLayerBuilder: function createTextLayerBuilder(textLayerDiv, pageIndex, viewport) {
  3334. var enhanceTextSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  3335. return new _text_layer_builder.TextLayerBuilder({
  3336. textLayerDiv: textLayerDiv,
  3337. eventBus: this.eventBus,
  3338. pageIndex: pageIndex,
  3339. viewport: viewport,
  3340. findController: this.isInPresentationMode ? null : this.findController,
  3341. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  3342. });
  3343. },
  3344. createAnnotationLayerBuilder: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  3345. var renderInteractiveForms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  3346. return new _annotation_layer_builder.AnnotationLayerBuilder({
  3347. pageDiv: pageDiv,
  3348. pdfPage: pdfPage,
  3349. renderInteractiveForms: renderInteractiveForms,
  3350. linkService: this.linkService,
  3351. downloadManager: this.downloadManager
  3352. });
  3353. },
  3354. setFindController: function setFindController(findController) {
  3355. this.findController = findController;
  3356. },
  3357. getPagesOverview: function getPagesOverview() {
  3358. var pagesOverview = this._pages.map(function (pageView) {
  3359. var viewport = pageView.pdfPage.getViewport(1);
  3360. return {
  3361. width: viewport.width,
  3362. height: viewport.height,
  3363. rotation: viewport.rotation
  3364. };
  3365. });
  3366. if (!this.enablePrintAutoRotate) {
  3367. return pagesOverview;
  3368. }
  3369. var isFirstPagePortrait = isPortraitOrientation(pagesOverview[0]);
  3370. return pagesOverview.map(function (size) {
  3371. if (isFirstPagePortrait === isPortraitOrientation(size)) {
  3372. return size;
  3373. }
  3374. return {
  3375. width: size.height,
  3376. height: size.width,
  3377. rotation: (size.rotation + 90) % 360
  3378. };
  3379. });
  3380. }
  3381. };
  3382. return PDFViewer;
  3383. }();
  3384. exports.PresentationModeState = PresentationModeState;
  3385. exports.PDFViewer = PDFViewer;
  3386. /***/ }),
  3387. /* 12 */
  3388. /***/ (function(module, exports, __w_pdfjs_require__) {
  3389. "use strict";
  3390. var pdfjsLib = __w_pdfjs_require__(0);
  3391. var pdfjsWebPDFViewer = __w_pdfjs_require__(11);
  3392. var pdfjsWebPDFPageView = __w_pdfjs_require__(5);
  3393. var pdfjsWebPDFLinkService = __w_pdfjs_require__(3);
  3394. var pdfjsWebTextLayerBuilder = __w_pdfjs_require__(6);
  3395. var pdfjsWebAnnotationLayerBuilder = __w_pdfjs_require__(4);
  3396. var pdfjsWebPDFHistory = __w_pdfjs_require__(10);
  3397. var pdfjsWebPDFFindController = __w_pdfjs_require__(9);
  3398. var pdfjsWebUIUtils = __w_pdfjs_require__(1);
  3399. var pdfjsWebDownloadManager = __w_pdfjs_require__(8);
  3400. var PDFJS = pdfjsLib.PDFJS;
  3401. PDFJS.PDFViewer = pdfjsWebPDFViewer.PDFViewer;
  3402. PDFJS.PDFPageView = pdfjsWebPDFPageView.PDFPageView;
  3403. PDFJS.PDFLinkService = pdfjsWebPDFLinkService.PDFLinkService;
  3404. PDFJS.TextLayerBuilder = pdfjsWebTextLayerBuilder.TextLayerBuilder;
  3405. PDFJS.DefaultTextLayerFactory = pdfjsWebTextLayerBuilder.DefaultTextLayerFactory;
  3406. PDFJS.AnnotationLayerBuilder = pdfjsWebAnnotationLayerBuilder.AnnotationLayerBuilder;
  3407. PDFJS.DefaultAnnotationLayerFactory = pdfjsWebAnnotationLayerBuilder.DefaultAnnotationLayerFactory;
  3408. PDFJS.PDFHistory = pdfjsWebPDFHistory.PDFHistory;
  3409. PDFJS.PDFFindController = pdfjsWebPDFFindController.PDFFindController;
  3410. PDFJS.EventBus = pdfjsWebUIUtils.EventBus;
  3411. PDFJS.DownloadManager = pdfjsWebDownloadManager.DownloadManager;
  3412. PDFJS.ProgressBar = pdfjsWebUIUtils.ProgressBar;
  3413. exports.PDFJS = PDFJS;
  3414. /***/ })
  3415. /******/ ]);
  3416. });
  3417. //# sourceMappingURL=pdf_viewer.js.map