pdf_viewer.js 119 KB

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