pdf_viewer.js 119 KB

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