pdf_viewer.js 119 KB

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