pdf_viewer.js 119 KB

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