pdf_viewer.js 119 KB

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