pdf_viewer.js 118 KB

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