pdf_viewer.js 157 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844
  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. /******/ // define getter function for harmony exports
  61. /******/ __w_pdfjs_require__.d = function(exports, name, getter) {
  62. /******/ if(!__w_pdfjs_require__.o(exports, name)) {
  63. /******/ Object.defineProperty(exports, name, {
  64. /******/ configurable: false,
  65. /******/ enumerable: true,
  66. /******/ get: getter
  67. /******/ });
  68. /******/ }
  69. /******/ };
  70. /******/
  71. /******/ // getDefaultExport function for compatibility with non-harmony modules
  72. /******/ __w_pdfjs_require__.n = function(module) {
  73. /******/ var getter = module && module.__esModule ?
  74. /******/ function getDefault() { return module['default']; } :
  75. /******/ function getModuleExports() { return module; };
  76. /******/ __w_pdfjs_require__.d(getter, 'a', getter);
  77. /******/ return getter;
  78. /******/ };
  79. /******/
  80. /******/ // Object.prototype.hasOwnProperty.call
  81. /******/ __w_pdfjs_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  82. /******/
  83. /******/ // __webpack_public_path__
  84. /******/ __w_pdfjs_require__.p = "";
  85. /******/
  86. /******/ // Load entry module and return exports
  87. /******/ return __w_pdfjs_require__(__w_pdfjs_require__.s = 8);
  88. /******/ })
  89. /************************************************************************/
  90. /******/ ([
  91. /* 0 */
  92. /***/ (function(module, exports, __w_pdfjs_require__) {
  93. "use strict";
  94. var pdfjsLib;
  95. if (typeof window !== 'undefined' && window['pdfjs-dist/build/pdf']) {
  96. pdfjsLib = window['pdfjs-dist/build/pdf'];
  97. } else {
  98. pdfjsLib = require('../build/pdf.js');
  99. }
  100. module.exports = pdfjsLib;
  101. /***/ }),
  102. /* 1 */
  103. /***/ (function(module, exports, __w_pdfjs_require__) {
  104. "use strict";
  105. Object.defineProperty(exports, "__esModule", {
  106. value: true
  107. });
  108. exports.waitOnEventOrTimeout = exports.WaitOnType = 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.NullL10n = exports.mozL10n = exports.RendererType = exports.cloneObj = exports.VERTICAL_PADDING = exports.SCROLLBAR_PADDING = exports.MAX_AUTO_SCALE = exports.UNKNOWN_SCALE = exports.MAX_SCALE = exports.MIN_SCALE = exports.DEFAULT_SCALE = exports.DEFAULT_SCALE_VALUE = exports.CSS_UNITS = undefined;
  109. 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; }; }();
  110. 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; };
  111. var _pdfjsLib = __w_pdfjs_require__(0);
  112. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  113. var CSS_UNITS = 96.0 / 72.0;
  114. var DEFAULT_SCALE_VALUE = 'auto';
  115. var DEFAULT_SCALE = 1.0;
  116. var MIN_SCALE = 0.25;
  117. var MAX_SCALE = 10.0;
  118. var UNKNOWN_SCALE = 0;
  119. var MAX_AUTO_SCALE = 1.25;
  120. var SCROLLBAR_PADDING = 40;
  121. var VERTICAL_PADDING = 5;
  122. var RendererType = {
  123. CANVAS: 'canvas',
  124. SVG: 'svg'
  125. };
  126. function formatL10nValue(text, args) {
  127. if (!args) {
  128. return text;
  129. }
  130. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, function (all, name) {
  131. return name in args ? args[name] : '{{' + name + '}}';
  132. });
  133. }
  134. var NullL10n = {
  135. get: function get(property, args, fallback) {
  136. return Promise.resolve(formatL10nValue(fallback, args));
  137. },
  138. translate: function translate(element) {
  139. return Promise.resolve();
  140. }
  141. };
  142. _pdfjsLib.PDFJS.disableFullscreen = _pdfjsLib.PDFJS.disableFullscreen === undefined ? false : _pdfjsLib.PDFJS.disableFullscreen;
  143. _pdfjsLib.PDFJS.useOnlyCssZoom = _pdfjsLib.PDFJS.useOnlyCssZoom === undefined ? false : _pdfjsLib.PDFJS.useOnlyCssZoom;
  144. _pdfjsLib.PDFJS.maxCanvasPixels = _pdfjsLib.PDFJS.maxCanvasPixels === undefined ? 16777216 : _pdfjsLib.PDFJS.maxCanvasPixels;
  145. _pdfjsLib.PDFJS.disableHistory = _pdfjsLib.PDFJS.disableHistory === undefined ? false : _pdfjsLib.PDFJS.disableHistory;
  146. _pdfjsLib.PDFJS.disableTextLayer = _pdfjsLib.PDFJS.disableTextLayer === undefined ? false : _pdfjsLib.PDFJS.disableTextLayer;
  147. _pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom = _pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom === undefined ? false : _pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom;
  148. {
  149. _pdfjsLib.PDFJS.locale = _pdfjsLib.PDFJS.locale === undefined && typeof navigator !== 'undefined' ? navigator.language : _pdfjsLib.PDFJS.locale;
  150. }
  151. function getOutputScale(ctx) {
  152. var devicePixelRatio = window.devicePixelRatio || 1;
  153. var backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  154. var pixelRatio = devicePixelRatio / backingStoreRatio;
  155. return {
  156. sx: pixelRatio,
  157. sy: pixelRatio,
  158. scaled: pixelRatio !== 1
  159. };
  160. }
  161. function scrollIntoView(element, spot) {
  162. var skipOverflowHiddenElements = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  163. var parent = element.offsetParent;
  164. if (!parent) {
  165. console.error('offsetParent is not set -- cannot scroll');
  166. return;
  167. }
  168. var offsetY = element.offsetTop + element.clientTop;
  169. var offsetX = element.offsetLeft + element.clientLeft;
  170. while (parent.clientHeight === parent.scrollHeight || skipOverflowHiddenElements && getComputedStyle(parent).overflow === 'hidden') {
  171. if (parent.dataset._scaleY) {
  172. offsetY /= parent.dataset._scaleY;
  173. offsetX /= parent.dataset._scaleX;
  174. }
  175. offsetY += parent.offsetTop;
  176. offsetX += parent.offsetLeft;
  177. parent = parent.offsetParent;
  178. if (!parent) {
  179. return;
  180. }
  181. }
  182. if (spot) {
  183. if (spot.top !== undefined) {
  184. offsetY += spot.top;
  185. }
  186. if (spot.left !== undefined) {
  187. offsetX += spot.left;
  188. parent.scrollLeft = offsetX;
  189. }
  190. }
  191. parent.scrollTop = offsetY;
  192. }
  193. function watchScroll(viewAreaElement, callback) {
  194. var debounceScroll = function debounceScroll(evt) {
  195. if (rAF) {
  196. return;
  197. }
  198. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  199. rAF = null;
  200. var currentY = viewAreaElement.scrollTop;
  201. var lastY = state.lastY;
  202. if (currentY !== lastY) {
  203. state.down = currentY > lastY;
  204. }
  205. state.lastY = currentY;
  206. callback(state);
  207. });
  208. };
  209. var state = {
  210. down: true,
  211. lastY: viewAreaElement.scrollTop,
  212. _eventHandler: debounceScroll
  213. };
  214. var rAF = null;
  215. viewAreaElement.addEventListener('scroll', debounceScroll, true);
  216. return state;
  217. }
  218. function parseQueryString(query) {
  219. var parts = query.split('&');
  220. var params = Object.create(null);
  221. for (var i = 0, ii = parts.length; i < ii; ++i) {
  222. var param = parts[i].split('=');
  223. var key = param[0].toLowerCase();
  224. var value = param.length > 1 ? param[1] : null;
  225. params[decodeURIComponent(key)] = decodeURIComponent(value);
  226. }
  227. return params;
  228. }
  229. function binarySearchFirstItem(items, condition) {
  230. var minIndex = 0;
  231. var maxIndex = items.length - 1;
  232. if (items.length === 0 || !condition(items[maxIndex])) {
  233. return items.length;
  234. }
  235. if (condition(items[minIndex])) {
  236. return minIndex;
  237. }
  238. while (minIndex < maxIndex) {
  239. var currentIndex = minIndex + maxIndex >> 1;
  240. var currentItem = items[currentIndex];
  241. if (condition(currentItem)) {
  242. maxIndex = currentIndex;
  243. } else {
  244. minIndex = currentIndex + 1;
  245. }
  246. }
  247. return minIndex;
  248. }
  249. function approximateFraction(x) {
  250. if (Math.floor(x) === x) {
  251. return [x, 1];
  252. }
  253. var xinv = 1 / x;
  254. var limit = 8;
  255. if (xinv > limit) {
  256. return [1, limit];
  257. } else if (Math.floor(xinv) === xinv) {
  258. return [1, xinv];
  259. }
  260. var x_ = x > 1 ? xinv : x;
  261. var a = 0,
  262. b = 1,
  263. c = 1,
  264. d = 1;
  265. while (true) {
  266. var p = a + c,
  267. q = b + d;
  268. if (q > limit) {
  269. break;
  270. }
  271. if (x_ <= p / q) {
  272. c = p;
  273. d = q;
  274. } else {
  275. a = p;
  276. b = q;
  277. }
  278. }
  279. var result = void 0;
  280. if (x_ - a / b < c / d - x_) {
  281. result = x_ === x ? [a, b] : [b, a];
  282. } else {
  283. result = x_ === x ? [c, d] : [d, c];
  284. }
  285. return result;
  286. }
  287. function roundToDivide(x, div) {
  288. var r = x % div;
  289. return r === 0 ? x : Math.round(x - r + div);
  290. }
  291. function getVisibleElements(scrollEl, views) {
  292. var sortByVisibility = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  293. var top = scrollEl.scrollTop,
  294. bottom = top + scrollEl.clientHeight;
  295. var left = scrollEl.scrollLeft,
  296. right = left + scrollEl.clientWidth;
  297. function isElementBottomBelowViewTop(view) {
  298. var element = view.div;
  299. var elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  300. return elementBottom > top;
  301. }
  302. var visible = [],
  303. view = void 0,
  304. element = void 0;
  305. var currentHeight = void 0,
  306. viewHeight = void 0,
  307. hiddenHeight = void 0,
  308. percentHeight = void 0;
  309. var currentWidth = void 0,
  310. viewWidth = void 0;
  311. var firstVisibleElementInd = views.length === 0 ? 0 : binarySearchFirstItem(views, isElementBottomBelowViewTop);
  312. for (var i = firstVisibleElementInd, ii = views.length; i < ii; i++) {
  313. view = views[i];
  314. element = view.div;
  315. currentHeight = element.offsetTop + element.clientTop;
  316. viewHeight = element.clientHeight;
  317. if (currentHeight > bottom) {
  318. break;
  319. }
  320. currentWidth = element.offsetLeft + element.clientLeft;
  321. viewWidth = element.clientWidth;
  322. if (currentWidth + viewWidth < left || currentWidth > right) {
  323. continue;
  324. }
  325. hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, currentHeight + viewHeight - bottom);
  326. percentHeight = (viewHeight - hiddenHeight) * 100 / viewHeight | 0;
  327. visible.push({
  328. id: view.id,
  329. x: currentWidth,
  330. y: currentHeight,
  331. view: view,
  332. percent: percentHeight
  333. });
  334. }
  335. var first = visible[0];
  336. var last = visible[visible.length - 1];
  337. if (sortByVisibility) {
  338. visible.sort(function (a, b) {
  339. var pc = a.percent - b.percent;
  340. if (Math.abs(pc) > 0.001) {
  341. return -pc;
  342. }
  343. return a.id - b.id;
  344. });
  345. }
  346. return {
  347. first: first,
  348. last: last,
  349. views: visible
  350. };
  351. }
  352. function noContextMenuHandler(evt) {
  353. evt.preventDefault();
  354. }
  355. function isDataSchema(url) {
  356. var i = 0,
  357. ii = url.length;
  358. while (i < ii && url[i].trim() === '') {
  359. i++;
  360. }
  361. return url.substr(i, 5).toLowerCase() === 'data:';
  362. }
  363. function getPDFFileNameFromURL(url) {
  364. var defaultFilename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'document.pdf';
  365. if (isDataSchema(url)) {
  366. console.warn('getPDFFileNameFromURL: ' + 'ignoring "data:" URL for performance reasons.');
  367. return defaultFilename;
  368. }
  369. var reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  370. var reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  371. var splitURI = reURI.exec(url);
  372. var suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  373. if (suggestedFilename) {
  374. suggestedFilename = suggestedFilename[0];
  375. if (suggestedFilename.indexOf('%') !== -1) {
  376. try {
  377. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  378. } catch (ex) {}
  379. }
  380. }
  381. return suggestedFilename || defaultFilename;
  382. }
  383. function normalizeWheelEventDelta(evt) {
  384. var delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY);
  385. var angle = Math.atan2(evt.deltaY, evt.deltaX);
  386. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  387. delta = -delta;
  388. }
  389. var MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  390. var MOUSE_DOM_DELTA_LINE_MODE = 1;
  391. var MOUSE_PIXELS_PER_LINE = 30;
  392. var MOUSE_LINES_PER_PAGE = 30;
  393. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  394. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  395. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  396. delta /= MOUSE_LINES_PER_PAGE;
  397. }
  398. return delta;
  399. }
  400. function cloneObj(obj) {
  401. var result = Object.create(null);
  402. for (var i in obj) {
  403. if (Object.prototype.hasOwnProperty.call(obj, i)) {
  404. result[i] = obj[i];
  405. }
  406. }
  407. return result;
  408. }
  409. var WaitOnType = {
  410. EVENT: 'event',
  411. TIMEOUT: 'timeout'
  412. };
  413. function waitOnEventOrTimeout(_ref) {
  414. var target = _ref.target,
  415. name = _ref.name,
  416. _ref$delay = _ref.delay,
  417. delay = _ref$delay === undefined ? 0 : _ref$delay;
  418. if ((typeof target === 'undefined' ? 'undefined' : _typeof(target)) !== 'object' || !(name && typeof name === 'string') || !(Number.isInteger(delay) && delay >= 0)) {
  419. return Promise.reject(new Error('waitOnEventOrTimeout - invalid paramaters.'));
  420. }
  421. var capability = (0, _pdfjsLib.createPromiseCapability)();
  422. function handler(type) {
  423. if (target instanceof EventBus) {
  424. target.off(name, eventHandler);
  425. } else {
  426. target.removeEventListener(name, eventHandler);
  427. }
  428. if (timeout) {
  429. clearTimeout(timeout);
  430. }
  431. capability.resolve(type);
  432. }
  433. var eventHandler = handler.bind(null, WaitOnType.EVENT);
  434. if (target instanceof EventBus) {
  435. target.on(name, eventHandler);
  436. } else {
  437. target.addEventListener(name, eventHandler);
  438. }
  439. var timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  440. var timeout = setTimeout(timeoutHandler, delay);
  441. return capability.promise;
  442. }
  443. var animationStarted = new Promise(function (resolve) {
  444. window.requestAnimationFrame(resolve);
  445. });
  446. var mozL10n = void 0;
  447. var localized = Promise.resolve();
  448. var EventBus = function () {
  449. function EventBus() {
  450. _classCallCheck(this, EventBus);
  451. this._listeners = Object.create(null);
  452. }
  453. _createClass(EventBus, [{
  454. key: 'on',
  455. value: function on(eventName, listener) {
  456. var eventListeners = this._listeners[eventName];
  457. if (!eventListeners) {
  458. eventListeners = [];
  459. this._listeners[eventName] = eventListeners;
  460. }
  461. eventListeners.push(listener);
  462. }
  463. }, {
  464. key: 'off',
  465. value: function off(eventName, listener) {
  466. var eventListeners = this._listeners[eventName];
  467. var i = void 0;
  468. if (!eventListeners || (i = eventListeners.indexOf(listener)) < 0) {
  469. return;
  470. }
  471. eventListeners.splice(i, 1);
  472. }
  473. }, {
  474. key: 'dispatch',
  475. value: function dispatch(eventName) {
  476. var eventListeners = this._listeners[eventName];
  477. if (!eventListeners || eventListeners.length === 0) {
  478. return;
  479. }
  480. var args = Array.prototype.slice.call(arguments, 1);
  481. eventListeners.slice(0).forEach(function (listener) {
  482. listener.apply(null, args);
  483. });
  484. }
  485. }]);
  486. return EventBus;
  487. }();
  488. function clamp(v, min, max) {
  489. return Math.min(Math.max(v, min), max);
  490. }
  491. var ProgressBar = function () {
  492. function ProgressBar(id) {
  493. var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  494. height = _ref2.height,
  495. width = _ref2.width,
  496. units = _ref2.units;
  497. _classCallCheck(this, ProgressBar);
  498. this.visible = true;
  499. this.div = document.querySelector(id + ' .progress');
  500. this.bar = this.div.parentNode;
  501. this.height = height || 100;
  502. this.width = width || 100;
  503. this.units = units || '%';
  504. this.div.style.height = this.height + this.units;
  505. this.percent = 0;
  506. }
  507. _createClass(ProgressBar, [{
  508. key: '_updateBar',
  509. value: function _updateBar() {
  510. if (this._indeterminate) {
  511. this.div.classList.add('indeterminate');
  512. this.div.style.width = this.width + this.units;
  513. return;
  514. }
  515. this.div.classList.remove('indeterminate');
  516. var progressSize = this.width * this._percent / 100;
  517. this.div.style.width = progressSize + this.units;
  518. }
  519. }, {
  520. key: 'setWidth',
  521. value: function setWidth(viewer) {
  522. if (!viewer) {
  523. return;
  524. }
  525. var container = viewer.parentNode;
  526. var scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  527. if (scrollbarWidth > 0) {
  528. this.bar.setAttribute('style', 'width: calc(100% - ' + scrollbarWidth + 'px);');
  529. }
  530. }
  531. }, {
  532. key: 'hide',
  533. value: function hide() {
  534. if (!this.visible) {
  535. return;
  536. }
  537. this.visible = false;
  538. this.bar.classList.add('hidden');
  539. document.body.classList.remove('loadingInProgress');
  540. }
  541. }, {
  542. key: 'show',
  543. value: function show() {
  544. if (this.visible) {
  545. return;
  546. }
  547. this.visible = true;
  548. document.body.classList.add('loadingInProgress');
  549. this.bar.classList.remove('hidden');
  550. }
  551. }, {
  552. key: 'percent',
  553. get: function get() {
  554. return this._percent;
  555. },
  556. set: function set(val) {
  557. this._indeterminate = isNaN(val);
  558. this._percent = clamp(val, 0, 100);
  559. this._updateBar();
  560. }
  561. }]);
  562. return ProgressBar;
  563. }();
  564. exports.CSS_UNITS = CSS_UNITS;
  565. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  566. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  567. exports.MIN_SCALE = MIN_SCALE;
  568. exports.MAX_SCALE = MAX_SCALE;
  569. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  570. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  571. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  572. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  573. exports.cloneObj = cloneObj;
  574. exports.RendererType = RendererType;
  575. exports.mozL10n = mozL10n;
  576. exports.NullL10n = NullL10n;
  577. exports.EventBus = EventBus;
  578. exports.ProgressBar = ProgressBar;
  579. exports.getPDFFileNameFromURL = getPDFFileNameFromURL;
  580. exports.noContextMenuHandler = noContextMenuHandler;
  581. exports.parseQueryString = parseQueryString;
  582. exports.getVisibleElements = getVisibleElements;
  583. exports.roundToDivide = roundToDivide;
  584. exports.approximateFraction = approximateFraction;
  585. exports.getOutputScale = getOutputScale;
  586. exports.scrollIntoView = scrollIntoView;
  587. exports.watchScroll = watchScroll;
  588. exports.binarySearchFirstItem = binarySearchFirstItem;
  589. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  590. exports.animationStarted = animationStarted;
  591. exports.localized = localized;
  592. exports.WaitOnType = WaitOnType;
  593. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  594. /***/ }),
  595. /* 2 */
  596. /***/ (function(module, exports, __w_pdfjs_require__) {
  597. "use strict";
  598. Object.defineProperty(exports, "__esModule", {
  599. value: true
  600. });
  601. exports.getGlobalEventBus = exports.attachDOMEventsToEventBus = undefined;
  602. var _ui_utils = __w_pdfjs_require__(1);
  603. function attachDOMEventsToEventBus(eventBus) {
  604. eventBus.on('documentload', function () {
  605. var event = document.createEvent('CustomEvent');
  606. event.initCustomEvent('documentload', true, true, {});
  607. window.dispatchEvent(event);
  608. });
  609. eventBus.on('pagerendered', function (evt) {
  610. var event = document.createEvent('CustomEvent');
  611. event.initCustomEvent('pagerendered', true, true, {
  612. pageNumber: evt.pageNumber,
  613. cssTransform: evt.cssTransform
  614. });
  615. evt.source.div.dispatchEvent(event);
  616. });
  617. eventBus.on('textlayerrendered', function (evt) {
  618. var event = document.createEvent('CustomEvent');
  619. event.initCustomEvent('textlayerrendered', true, true, { pageNumber: evt.pageNumber });
  620. evt.source.textLayerDiv.dispatchEvent(event);
  621. });
  622. eventBus.on('pagechange', function (evt) {
  623. var event = document.createEvent('UIEvents');
  624. event.initUIEvent('pagechange', true, true, window, 0);
  625. event.pageNumber = evt.pageNumber;
  626. evt.source.container.dispatchEvent(event);
  627. });
  628. eventBus.on('pagesinit', function (evt) {
  629. var event = document.createEvent('CustomEvent');
  630. event.initCustomEvent('pagesinit', true, true, null);
  631. evt.source.container.dispatchEvent(event);
  632. });
  633. eventBus.on('pagesloaded', function (evt) {
  634. var event = document.createEvent('CustomEvent');
  635. event.initCustomEvent('pagesloaded', true, true, { pagesCount: evt.pagesCount });
  636. evt.source.container.dispatchEvent(event);
  637. });
  638. eventBus.on('scalechange', function (evt) {
  639. var event = document.createEvent('UIEvents');
  640. event.initUIEvent('scalechange', true, true, window, 0);
  641. event.scale = evt.scale;
  642. event.presetValue = evt.presetValue;
  643. evt.source.container.dispatchEvent(event);
  644. });
  645. eventBus.on('updateviewarea', function (evt) {
  646. var event = document.createEvent('UIEvents');
  647. event.initUIEvent('updateviewarea', true, true, window, 0);
  648. event.location = evt.location;
  649. evt.source.container.dispatchEvent(event);
  650. });
  651. eventBus.on('find', function (evt) {
  652. if (evt.source === window) {
  653. return;
  654. }
  655. var event = document.createEvent('CustomEvent');
  656. event.initCustomEvent('find' + evt.type, true, true, {
  657. query: evt.query,
  658. phraseSearch: evt.phraseSearch,
  659. caseSensitive: evt.caseSensitive,
  660. highlightAll: evt.highlightAll,
  661. findPrevious: evt.findPrevious
  662. });
  663. window.dispatchEvent(event);
  664. });
  665. eventBus.on('attachmentsloaded', function (evt) {
  666. var event = document.createEvent('CustomEvent');
  667. event.initCustomEvent('attachmentsloaded', true, true, { attachmentsCount: evt.attachmentsCount });
  668. evt.source.container.dispatchEvent(event);
  669. });
  670. eventBus.on('sidebarviewchanged', function (evt) {
  671. var event = document.createEvent('CustomEvent');
  672. event.initCustomEvent('sidebarviewchanged', true, true, { view: evt.view });
  673. evt.source.outerContainer.dispatchEvent(event);
  674. });
  675. eventBus.on('pagemode', function (evt) {
  676. var event = document.createEvent('CustomEvent');
  677. event.initCustomEvent('pagemode', true, true, { mode: evt.mode });
  678. evt.source.pdfViewer.container.dispatchEvent(event);
  679. });
  680. eventBus.on('namedaction', function (evt) {
  681. var event = document.createEvent('CustomEvent');
  682. event.initCustomEvent('namedaction', true, true, { action: evt.action });
  683. evt.source.pdfViewer.container.dispatchEvent(event);
  684. });
  685. eventBus.on('presentationmodechanged', function (evt) {
  686. var event = document.createEvent('CustomEvent');
  687. event.initCustomEvent('presentationmodechanged', true, true, {
  688. active: evt.active,
  689. switchInProgress: evt.switchInProgress
  690. });
  691. window.dispatchEvent(event);
  692. });
  693. eventBus.on('outlineloaded', function (evt) {
  694. var event = document.createEvent('CustomEvent');
  695. event.initCustomEvent('outlineloaded', true, true, { outlineCount: evt.outlineCount });
  696. evt.source.container.dispatchEvent(event);
  697. });
  698. }
  699. var globalEventBus = null;
  700. function getGlobalEventBus() {
  701. if (globalEventBus) {
  702. return globalEventBus;
  703. }
  704. globalEventBus = new _ui_utils.EventBus();
  705. attachDOMEventsToEventBus(globalEventBus);
  706. return globalEventBus;
  707. }
  708. exports.attachDOMEventsToEventBus = attachDOMEventsToEventBus;
  709. exports.getGlobalEventBus = getGlobalEventBus;
  710. /***/ }),
  711. /* 3 */
  712. /***/ (function(module, exports, __w_pdfjs_require__) {
  713. "use strict";
  714. Object.defineProperty(exports, "__esModule", {
  715. value: true
  716. });
  717. exports.SimpleLinkService = exports.PDFLinkService = undefined;
  718. 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; };
  719. 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; }; }();
  720. var _dom_events = __w_pdfjs_require__(2);
  721. var _ui_utils = __w_pdfjs_require__(1);
  722. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  723. var PDFLinkService = function () {
  724. function PDFLinkService() {
  725. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  726. eventBus = _ref.eventBus;
  727. _classCallCheck(this, PDFLinkService);
  728. this.eventBus = eventBus || (0, _dom_events.getGlobalEventBus)();
  729. this.baseUrl = null;
  730. this.pdfDocument = null;
  731. this.pdfViewer = null;
  732. this.pdfHistory = null;
  733. this._pagesRefCache = null;
  734. }
  735. _createClass(PDFLinkService, [{
  736. key: 'setDocument',
  737. value: function setDocument(pdfDocument, baseUrl) {
  738. this.baseUrl = baseUrl;
  739. this.pdfDocument = pdfDocument;
  740. this._pagesRefCache = Object.create(null);
  741. }
  742. }, {
  743. key: 'setViewer',
  744. value: function setViewer(pdfViewer) {
  745. this.pdfViewer = pdfViewer;
  746. }
  747. }, {
  748. key: 'setHistory',
  749. value: function setHistory(pdfHistory) {
  750. this.pdfHistory = pdfHistory;
  751. }
  752. }, {
  753. key: 'navigateTo',
  754. value: function navigateTo(dest) {
  755. var _this = this;
  756. var goToDestination = function goToDestination(_ref2) {
  757. var namedDest = _ref2.namedDest,
  758. explicitDest = _ref2.explicitDest;
  759. var destRef = explicitDest[0],
  760. pageNumber = void 0;
  761. if (destRef instanceof Object) {
  762. pageNumber = _this._cachedPageNumber(destRef);
  763. if (pageNumber === null) {
  764. _this.pdfDocument.getPageIndex(destRef).then(function (pageIndex) {
  765. _this.cachePageRef(pageIndex + 1, destRef);
  766. goToDestination({
  767. namedDest: namedDest,
  768. explicitDest: explicitDest
  769. });
  770. }).catch(function () {
  771. console.error('PDFLinkService.navigateTo: "' + destRef + '" is not ' + ('a valid page reference, for dest="' + dest + '".'));
  772. });
  773. return;
  774. }
  775. } else if ((destRef | 0) === destRef) {
  776. pageNumber = destRef + 1;
  777. } else {
  778. console.error('PDFLinkService.navigateTo: "' + destRef + '" is not ' + ('a valid destination reference, for dest="' + dest + '".'));
  779. return;
  780. }
  781. if (!pageNumber || pageNumber < 1 || pageNumber > _this.pagesCount) {
  782. console.error('PDFLinkService.navigateTo: "' + pageNumber + '" is not ' + ('a valid page number, for dest="' + dest + '".'));
  783. return;
  784. }
  785. if (_this.pdfHistory) {
  786. _this.pdfHistory.pushCurrentPosition();
  787. _this.pdfHistory.push({
  788. namedDest: namedDest,
  789. explicitDest: explicitDest,
  790. pageNumber: pageNumber
  791. });
  792. }
  793. _this.pdfViewer.scrollPageIntoView({
  794. pageNumber: pageNumber,
  795. destArray: explicitDest
  796. });
  797. };
  798. new Promise(function (resolve, reject) {
  799. if (typeof dest === 'string') {
  800. _this.pdfDocument.getDestination(dest).then(function (destArray) {
  801. resolve({
  802. namedDest: dest,
  803. explicitDest: destArray
  804. });
  805. });
  806. return;
  807. }
  808. resolve({
  809. namedDest: '',
  810. explicitDest: dest
  811. });
  812. }).then(function (data) {
  813. if (!(data.explicitDest instanceof Array)) {
  814. console.error('PDFLinkService.navigateTo: "' + data.explicitDest + '" is' + (' not a valid destination array, for dest="' + dest + '".'));
  815. return;
  816. }
  817. goToDestination(data);
  818. });
  819. }
  820. }, {
  821. key: 'getDestinationHash',
  822. value: function getDestinationHash(dest) {
  823. if (typeof dest === 'string') {
  824. return this.getAnchorUrl('#' + escape(dest));
  825. }
  826. if (dest instanceof Array) {
  827. var str = JSON.stringify(dest);
  828. return this.getAnchorUrl('#' + escape(str));
  829. }
  830. return this.getAnchorUrl('');
  831. }
  832. }, {
  833. key: 'getAnchorUrl',
  834. value: function getAnchorUrl(anchor) {
  835. return (this.baseUrl || '') + anchor;
  836. }
  837. }, {
  838. key: 'setHash',
  839. value: function setHash(hash) {
  840. var pageNumber = void 0,
  841. dest = void 0;
  842. if (hash.indexOf('=') >= 0) {
  843. var params = (0, _ui_utils.parseQueryString)(hash);
  844. if ('search' in params) {
  845. this.eventBus.dispatch('findfromurlhash', {
  846. source: this,
  847. query: params['search'].replace(/"/g, ''),
  848. phraseSearch: params['phrase'] === 'true'
  849. });
  850. }
  851. if ('nameddest' in params) {
  852. this.navigateTo(params.nameddest);
  853. return;
  854. }
  855. if ('page' in params) {
  856. pageNumber = params.page | 0 || 1;
  857. }
  858. if ('zoom' in params) {
  859. var zoomArgs = params.zoom.split(',');
  860. var zoomArg = zoomArgs[0];
  861. var zoomArgNumber = parseFloat(zoomArg);
  862. if (zoomArg.indexOf('Fit') === -1) {
  863. dest = [null, { name: 'XYZ' }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  864. } else {
  865. if (zoomArg === 'Fit' || zoomArg === 'FitB') {
  866. dest = [null, { name: zoomArg }];
  867. } else if (zoomArg === 'FitH' || zoomArg === 'FitBH' || zoomArg === 'FitV' || zoomArg === 'FitBV') {
  868. dest = [null, { name: zoomArg }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  869. } else if (zoomArg === 'FitR') {
  870. if (zoomArgs.length !== 5) {
  871. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  872. } else {
  873. dest = [null, { name: zoomArg }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  874. }
  875. } else {
  876. console.error('PDFLinkService.setHash: "' + zoomArg + '" is not ' + 'a valid zoom value.');
  877. }
  878. }
  879. }
  880. if (dest) {
  881. this.pdfViewer.scrollPageIntoView({
  882. pageNumber: pageNumber || this.page,
  883. destArray: dest,
  884. allowNegativeOffset: true
  885. });
  886. } else if (pageNumber) {
  887. this.page = pageNumber;
  888. }
  889. if ('pagemode' in params) {
  890. this.eventBus.dispatch('pagemode', {
  891. source: this,
  892. mode: params.pagemode
  893. });
  894. }
  895. } else {
  896. if (/^\d+$/.test(hash) && hash <= this.pagesCount) {
  897. console.warn('PDFLinkService_setHash: specifying a page number ' + 'directly after the hash symbol (#) is deprecated, ' + ('please use the "#page=' + hash + '" form instead.'));
  898. this.page = hash | 0;
  899. }
  900. dest = unescape(hash);
  901. try {
  902. dest = JSON.parse(dest);
  903. if (!(dest instanceof Array)) {
  904. dest = dest.toString();
  905. }
  906. } catch (ex) {}
  907. if (typeof dest === 'string' || isValidExplicitDestination(dest)) {
  908. this.navigateTo(dest);
  909. return;
  910. }
  911. console.error('PDFLinkService.setHash: "' + unescape(hash) + '" is not ' + 'a valid destination.');
  912. }
  913. }
  914. }, {
  915. key: 'executeNamedAction',
  916. value: function executeNamedAction(action) {
  917. switch (action) {
  918. case 'GoBack':
  919. if (this.pdfHistory) {
  920. this.pdfHistory.back();
  921. }
  922. break;
  923. case 'GoForward':
  924. if (this.pdfHistory) {
  925. this.pdfHistory.forward();
  926. }
  927. break;
  928. case 'NextPage':
  929. if (this.page < this.pagesCount) {
  930. this.page++;
  931. }
  932. break;
  933. case 'PrevPage':
  934. if (this.page > 1) {
  935. this.page--;
  936. }
  937. break;
  938. case 'LastPage':
  939. this.page = this.pagesCount;
  940. break;
  941. case 'FirstPage':
  942. this.page = 1;
  943. break;
  944. default:
  945. break;
  946. }
  947. this.eventBus.dispatch('namedaction', {
  948. source: this,
  949. action: action
  950. });
  951. }
  952. }, {
  953. key: 'onFileAttachmentAnnotation',
  954. value: function onFileAttachmentAnnotation(_ref3) {
  955. var id = _ref3.id,
  956. filename = _ref3.filename,
  957. content = _ref3.content;
  958. this.eventBus.dispatch('fileattachmentannotation', {
  959. source: this,
  960. id: id,
  961. filename: filename,
  962. content: content
  963. });
  964. }
  965. }, {
  966. key: 'cachePageRef',
  967. value: function cachePageRef(pageNum, pageRef) {
  968. var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
  969. this._pagesRefCache[refStr] = pageNum;
  970. }
  971. }, {
  972. key: '_cachedPageNumber',
  973. value: function _cachedPageNumber(pageRef) {
  974. var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
  975. return this._pagesRefCache && this._pagesRefCache[refStr] || null;
  976. }
  977. }, {
  978. key: 'pagesCount',
  979. get: function get() {
  980. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  981. }
  982. }, {
  983. key: 'page',
  984. get: function get() {
  985. return this.pdfViewer.currentPageNumber;
  986. },
  987. set: function set(value) {
  988. this.pdfViewer.currentPageNumber = value;
  989. }
  990. }]);
  991. return PDFLinkService;
  992. }();
  993. function isValidExplicitDestination(dest) {
  994. if (!(dest instanceof Array)) {
  995. return false;
  996. }
  997. var destLength = dest.length,
  998. allowNull = true;
  999. if (destLength < 2) {
  1000. return false;
  1001. }
  1002. var page = dest[0];
  1003. 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)) {
  1004. return false;
  1005. }
  1006. var zoom = dest[1];
  1007. if (!((typeof zoom === 'undefined' ? 'undefined' : _typeof(zoom)) === 'object' && typeof zoom.name === 'string')) {
  1008. return false;
  1009. }
  1010. switch (zoom.name) {
  1011. case 'XYZ':
  1012. if (destLength !== 5) {
  1013. return false;
  1014. }
  1015. break;
  1016. case 'Fit':
  1017. case 'FitB':
  1018. return destLength === 2;
  1019. case 'FitH':
  1020. case 'FitBH':
  1021. case 'FitV':
  1022. case 'FitBV':
  1023. if (destLength !== 3) {
  1024. return false;
  1025. }
  1026. break;
  1027. case 'FitR':
  1028. if (destLength !== 6) {
  1029. return false;
  1030. }
  1031. allowNull = false;
  1032. break;
  1033. default:
  1034. return false;
  1035. }
  1036. for (var i = 2; i < destLength; i++) {
  1037. var param = dest[i];
  1038. if (!(typeof param === 'number' || allowNull && param === null)) {
  1039. return false;
  1040. }
  1041. }
  1042. return true;
  1043. }
  1044. var SimpleLinkService = function () {
  1045. function SimpleLinkService() {
  1046. _classCallCheck(this, SimpleLinkService);
  1047. }
  1048. _createClass(SimpleLinkService, [{
  1049. key: 'navigateTo',
  1050. value: function navigateTo(dest) {}
  1051. }, {
  1052. key: 'getDestinationHash',
  1053. value: function getDestinationHash(dest) {
  1054. return '#';
  1055. }
  1056. }, {
  1057. key: 'getAnchorUrl',
  1058. value: function getAnchorUrl(hash) {
  1059. return '#';
  1060. }
  1061. }, {
  1062. key: 'setHash',
  1063. value: function setHash(hash) {}
  1064. }, {
  1065. key: 'executeNamedAction',
  1066. value: function executeNamedAction(action) {}
  1067. }, {
  1068. key: 'onFileAttachmentAnnotation',
  1069. value: function onFileAttachmentAnnotation(_ref4) {
  1070. var id = _ref4.id,
  1071. filename = _ref4.filename,
  1072. content = _ref4.content;
  1073. }
  1074. }, {
  1075. key: 'cachePageRef',
  1076. value: function cachePageRef(pageNum, pageRef) {}
  1077. }, {
  1078. key: 'page',
  1079. get: function get() {
  1080. return 0;
  1081. },
  1082. set: function set(value) {}
  1083. }]);
  1084. return SimpleLinkService;
  1085. }();
  1086. exports.PDFLinkService = PDFLinkService;
  1087. exports.SimpleLinkService = SimpleLinkService;
  1088. /***/ }),
  1089. /* 4 */
  1090. /***/ (function(module, exports, __w_pdfjs_require__) {
  1091. "use strict";
  1092. Object.defineProperty(exports, "__esModule", {
  1093. value: true
  1094. });
  1095. 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; }; }();
  1096. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1097. var CLEANUP_TIMEOUT = 30000;
  1098. var RenderingStates = {
  1099. INITIAL: 0,
  1100. RUNNING: 1,
  1101. PAUSED: 2,
  1102. FINISHED: 3
  1103. };
  1104. var PDFRenderingQueue = function () {
  1105. function PDFRenderingQueue() {
  1106. _classCallCheck(this, PDFRenderingQueue);
  1107. this.pdfViewer = null;
  1108. this.pdfThumbnailViewer = null;
  1109. this.onIdle = null;
  1110. this.highestPriorityPage = null;
  1111. this.idleTimeout = null;
  1112. this.printing = false;
  1113. this.isThumbnailViewEnabled = false;
  1114. }
  1115. _createClass(PDFRenderingQueue, [{
  1116. key: "setViewer",
  1117. value: function setViewer(pdfViewer) {
  1118. this.pdfViewer = pdfViewer;
  1119. }
  1120. }, {
  1121. key: "setThumbnailViewer",
  1122. value: function setThumbnailViewer(pdfThumbnailViewer) {
  1123. this.pdfThumbnailViewer = pdfThumbnailViewer;
  1124. }
  1125. }, {
  1126. key: "isHighestPriority",
  1127. value: function isHighestPriority(view) {
  1128. return this.highestPriorityPage === view.renderingId;
  1129. }
  1130. }, {
  1131. key: "renderHighestPriority",
  1132. value: function renderHighestPriority(currentlyVisiblePages) {
  1133. if (this.idleTimeout) {
  1134. clearTimeout(this.idleTimeout);
  1135. this.idleTimeout = null;
  1136. }
  1137. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  1138. return;
  1139. }
  1140. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  1141. if (this.pdfThumbnailViewer.forceRendering()) {
  1142. return;
  1143. }
  1144. }
  1145. if (this.printing) {
  1146. return;
  1147. }
  1148. if (this.onIdle) {
  1149. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  1150. }
  1151. }
  1152. }, {
  1153. key: "getHighestPriority",
  1154. value: function getHighestPriority(visible, views, scrolledDown) {
  1155. var visibleViews = visible.views;
  1156. var numVisible = visibleViews.length;
  1157. if (numVisible === 0) {
  1158. return false;
  1159. }
  1160. for (var i = 0; i < numVisible; ++i) {
  1161. var view = visibleViews[i].view;
  1162. if (!this.isViewFinished(view)) {
  1163. return view;
  1164. }
  1165. }
  1166. if (scrolledDown) {
  1167. var nextPageIndex = visible.last.id;
  1168. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  1169. return views[nextPageIndex];
  1170. }
  1171. } else {
  1172. var previousPageIndex = visible.first.id - 2;
  1173. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  1174. return views[previousPageIndex];
  1175. }
  1176. }
  1177. return null;
  1178. }
  1179. }, {
  1180. key: "isViewFinished",
  1181. value: function isViewFinished(view) {
  1182. return view.renderingState === RenderingStates.FINISHED;
  1183. }
  1184. }, {
  1185. key: "renderView",
  1186. value: function renderView(view) {
  1187. var _this = this;
  1188. switch (view.renderingState) {
  1189. case RenderingStates.FINISHED:
  1190. return false;
  1191. case RenderingStates.PAUSED:
  1192. this.highestPriorityPage = view.renderingId;
  1193. view.resume();
  1194. break;
  1195. case RenderingStates.RUNNING:
  1196. this.highestPriorityPage = view.renderingId;
  1197. break;
  1198. case RenderingStates.INITIAL:
  1199. this.highestPriorityPage = view.renderingId;
  1200. var continueRendering = function continueRendering() {
  1201. _this.renderHighestPriority();
  1202. };
  1203. view.draw().then(continueRendering, continueRendering);
  1204. break;
  1205. }
  1206. return true;
  1207. }
  1208. }]);
  1209. return PDFRenderingQueue;
  1210. }();
  1211. exports.RenderingStates = RenderingStates;
  1212. exports.PDFRenderingQueue = PDFRenderingQueue;
  1213. /***/ }),
  1214. /* 5 */
  1215. /***/ (function(module, exports, __w_pdfjs_require__) {
  1216. "use strict";
  1217. Object.defineProperty(exports, "__esModule", {
  1218. value: true
  1219. });
  1220. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = undefined;
  1221. 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; }; }();
  1222. var _pdfjsLib = __w_pdfjs_require__(0);
  1223. var _ui_utils = __w_pdfjs_require__(1);
  1224. var _pdf_link_service = __w_pdfjs_require__(3);
  1225. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1226. var AnnotationLayerBuilder = function () {
  1227. function AnnotationLayerBuilder(_ref) {
  1228. var pageDiv = _ref.pageDiv,
  1229. pdfPage = _ref.pdfPage,
  1230. linkService = _ref.linkService,
  1231. downloadManager = _ref.downloadManager,
  1232. _ref$renderInteractiv = _ref.renderInteractiveForms,
  1233. renderInteractiveForms = _ref$renderInteractiv === undefined ? false : _ref$renderInteractiv,
  1234. _ref$l10n = _ref.l10n,
  1235. l10n = _ref$l10n === undefined ? _ui_utils.NullL10n : _ref$l10n;
  1236. _classCallCheck(this, AnnotationLayerBuilder);
  1237. this.pageDiv = pageDiv;
  1238. this.pdfPage = pdfPage;
  1239. this.linkService = linkService;
  1240. this.downloadManager = downloadManager;
  1241. this.renderInteractiveForms = renderInteractiveForms;
  1242. this.l10n = l10n;
  1243. this.div = null;
  1244. }
  1245. _createClass(AnnotationLayerBuilder, [{
  1246. key: 'render',
  1247. value: function render(viewport) {
  1248. var _this = this;
  1249. var intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'display';
  1250. this.pdfPage.getAnnotations({ intent: intent }).then(function (annotations) {
  1251. var parameters = {
  1252. viewport: viewport.clone({ dontFlip: true }),
  1253. div: _this.div,
  1254. annotations: annotations,
  1255. page: _this.pdfPage,
  1256. renderInteractiveForms: _this.renderInteractiveForms,
  1257. linkService: _this.linkService,
  1258. downloadManager: _this.downloadManager
  1259. };
  1260. if (_this.div) {
  1261. _pdfjsLib.AnnotationLayer.update(parameters);
  1262. } else {
  1263. if (annotations.length === 0) {
  1264. return;
  1265. }
  1266. _this.div = document.createElement('div');
  1267. _this.div.className = 'annotationLayer';
  1268. _this.pageDiv.appendChild(_this.div);
  1269. parameters.div = _this.div;
  1270. _pdfjsLib.AnnotationLayer.render(parameters);
  1271. _this.l10n.translate(_this.div);
  1272. }
  1273. });
  1274. }
  1275. }, {
  1276. key: 'hide',
  1277. value: function hide() {
  1278. if (!this.div) {
  1279. return;
  1280. }
  1281. this.div.setAttribute('hidden', 'true');
  1282. }
  1283. }]);
  1284. return AnnotationLayerBuilder;
  1285. }();
  1286. var DefaultAnnotationLayerFactory = function () {
  1287. function DefaultAnnotationLayerFactory() {
  1288. _classCallCheck(this, DefaultAnnotationLayerFactory);
  1289. }
  1290. _createClass(DefaultAnnotationLayerFactory, [{
  1291. key: 'createAnnotationLayerBuilder',
  1292. value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  1293. var renderInteractiveForms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  1294. var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
  1295. return new AnnotationLayerBuilder({
  1296. pageDiv: pageDiv,
  1297. pdfPage: pdfPage,
  1298. renderInteractiveForms: renderInteractiveForms,
  1299. linkService: new _pdf_link_service.SimpleLinkService(),
  1300. l10n: l10n
  1301. });
  1302. }
  1303. }]);
  1304. return DefaultAnnotationLayerFactory;
  1305. }();
  1306. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  1307. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  1308. /***/ }),
  1309. /* 6 */
  1310. /***/ (function(module, exports, __w_pdfjs_require__) {
  1311. "use strict";
  1312. Object.defineProperty(exports, "__esModule", {
  1313. value: true
  1314. });
  1315. exports.PDFPageView = undefined;
  1316. 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; }; }();
  1317. var _ui_utils = __w_pdfjs_require__(1);
  1318. var _pdfjsLib = __w_pdfjs_require__(0);
  1319. var _dom_events = __w_pdfjs_require__(2);
  1320. var _pdf_rendering_queue = __w_pdfjs_require__(4);
  1321. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1322. var PDFPageView = function () {
  1323. function PDFPageView(options) {
  1324. _classCallCheck(this, PDFPageView);
  1325. var container = options.container;
  1326. var defaultViewport = options.defaultViewport;
  1327. this.id = options.id;
  1328. this.renderingId = 'page' + this.id;
  1329. this.pdfPage = null;
  1330. this.pageLabel = null;
  1331. this.rotation = 0;
  1332. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  1333. this.viewport = defaultViewport;
  1334. this.pdfPageRotate = defaultViewport.rotation;
  1335. this.hasRestrictedScaling = false;
  1336. this.enhanceTextSelection = options.enhanceTextSelection || false;
  1337. this.renderInteractiveForms = options.renderInteractiveForms || false;
  1338. this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
  1339. this.renderingQueue = options.renderingQueue;
  1340. this.textLayerFactory = options.textLayerFactory;
  1341. this.annotationLayerFactory = options.annotationLayerFactory;
  1342. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  1343. this.l10n = options.l10n || _ui_utils.NullL10n;
  1344. this.paintTask = null;
  1345. this.paintedViewportMap = new WeakMap();
  1346. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  1347. this.resume = null;
  1348. this.error = null;
  1349. this.onBeforeDraw = null;
  1350. this.onAfterDraw = null;
  1351. this.annotationLayer = null;
  1352. this.textLayer = null;
  1353. this.zoomLayer = null;
  1354. var div = document.createElement('div');
  1355. div.className = 'page';
  1356. div.style.width = Math.floor(this.viewport.width) + 'px';
  1357. div.style.height = Math.floor(this.viewport.height) + 'px';
  1358. div.setAttribute('data-page-number', this.id);
  1359. this.div = div;
  1360. container.appendChild(div);
  1361. }
  1362. _createClass(PDFPageView, [{
  1363. key: 'setPdfPage',
  1364. value: function setPdfPage(pdfPage) {
  1365. this.pdfPage = pdfPage;
  1366. this.pdfPageRotate = pdfPage.rotate;
  1367. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  1368. this.viewport = pdfPage.getViewport(this.scale * _ui_utils.CSS_UNITS, totalRotation);
  1369. this.stats = pdfPage.stats;
  1370. this.reset();
  1371. }
  1372. }, {
  1373. key: 'destroy',
  1374. value: function destroy() {
  1375. this.reset();
  1376. if (this.pdfPage) {
  1377. this.pdfPage.cleanup();
  1378. }
  1379. }
  1380. }, {
  1381. key: '_resetZoomLayer',
  1382. value: function _resetZoomLayer() {
  1383. var removeFromDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1384. if (!this.zoomLayer) {
  1385. return;
  1386. }
  1387. var zoomLayerCanvas = this.zoomLayer.firstChild;
  1388. this.paintedViewportMap.delete(zoomLayerCanvas);
  1389. zoomLayerCanvas.width = 0;
  1390. zoomLayerCanvas.height = 0;
  1391. if (removeFromDOM) {
  1392. this.zoomLayer.remove();
  1393. }
  1394. this.zoomLayer = null;
  1395. }
  1396. }, {
  1397. key: 'reset',
  1398. value: function reset() {
  1399. var keepZoomLayer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1400. var keepAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1401. this.cancelRendering();
  1402. var div = this.div;
  1403. div.style.width = Math.floor(this.viewport.width) + 'px';
  1404. div.style.height = Math.floor(this.viewport.height) + 'px';
  1405. var childNodes = div.childNodes;
  1406. var currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  1407. var currentAnnotationNode = keepAnnotations && this.annotationLayer && this.annotationLayer.div || null;
  1408. for (var i = childNodes.length - 1; i >= 0; i--) {
  1409. var node = childNodes[i];
  1410. if (currentZoomLayerNode === node || currentAnnotationNode === node) {
  1411. continue;
  1412. }
  1413. div.removeChild(node);
  1414. }
  1415. div.removeAttribute('data-loaded');
  1416. if (currentAnnotationNode) {
  1417. this.annotationLayer.hide();
  1418. } else {
  1419. this.annotationLayer = null;
  1420. }
  1421. if (!currentZoomLayerNode) {
  1422. if (this.canvas) {
  1423. this.paintedViewportMap.delete(this.canvas);
  1424. this.canvas.width = 0;
  1425. this.canvas.height = 0;
  1426. delete this.canvas;
  1427. }
  1428. this._resetZoomLayer();
  1429. }
  1430. if (this.svg) {
  1431. this.paintedViewportMap.delete(this.svg);
  1432. delete this.svg;
  1433. }
  1434. this.loadingIconDiv = document.createElement('div');
  1435. this.loadingIconDiv.className = 'loadingIcon';
  1436. div.appendChild(this.loadingIconDiv);
  1437. }
  1438. }, {
  1439. key: 'update',
  1440. value: function update(scale, rotation) {
  1441. this.scale = scale || this.scale;
  1442. if (typeof rotation !== 'undefined') {
  1443. this.rotation = rotation;
  1444. }
  1445. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  1446. this.viewport = this.viewport.clone({
  1447. scale: this.scale * _ui_utils.CSS_UNITS,
  1448. rotation: totalRotation
  1449. });
  1450. if (this.svg) {
  1451. this.cssTransform(this.svg, true);
  1452. this.eventBus.dispatch('pagerendered', {
  1453. source: this,
  1454. pageNumber: this.id,
  1455. cssTransform: true
  1456. });
  1457. return;
  1458. }
  1459. var isScalingRestricted = false;
  1460. if (this.canvas && _pdfjsLib.PDFJS.maxCanvasPixels > 0) {
  1461. var outputScale = this.outputScale;
  1462. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > _pdfjsLib.PDFJS.maxCanvasPixels) {
  1463. isScalingRestricted = true;
  1464. }
  1465. }
  1466. if (this.canvas) {
  1467. if (_pdfjsLib.PDFJS.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  1468. this.cssTransform(this.canvas, true);
  1469. this.eventBus.dispatch('pagerendered', {
  1470. source: this,
  1471. pageNumber: this.id,
  1472. cssTransform: true
  1473. });
  1474. return;
  1475. }
  1476. if (!this.zoomLayer && !this.canvas.hasAttribute('hidden')) {
  1477. this.zoomLayer = this.canvas.parentNode;
  1478. this.zoomLayer.style.position = 'absolute';
  1479. }
  1480. }
  1481. if (this.zoomLayer) {
  1482. this.cssTransform(this.zoomLayer.firstChild);
  1483. }
  1484. this.reset(true, true);
  1485. }
  1486. }, {
  1487. key: 'cancelRendering',
  1488. value: function cancelRendering() {
  1489. if (this.paintTask) {
  1490. this.paintTask.cancel();
  1491. this.paintTask = null;
  1492. }
  1493. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  1494. this.resume = null;
  1495. if (this.textLayer) {
  1496. this.textLayer.cancel();
  1497. this.textLayer = null;
  1498. }
  1499. }
  1500. }, {
  1501. key: 'cssTransform',
  1502. value: function cssTransform(target) {
  1503. var redrawAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1504. var width = this.viewport.width;
  1505. var height = this.viewport.height;
  1506. var div = this.div;
  1507. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + 'px';
  1508. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + 'px';
  1509. var relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  1510. var absRotation = Math.abs(relativeRotation);
  1511. var scaleX = 1,
  1512. scaleY = 1;
  1513. if (absRotation === 90 || absRotation === 270) {
  1514. scaleX = height / width;
  1515. scaleY = width / height;
  1516. }
  1517. var cssTransform = 'rotate(' + relativeRotation + 'deg) ' + 'scale(' + scaleX + ',' + scaleY + ')';
  1518. _pdfjsLib.CustomStyle.setProp('transform', target, cssTransform);
  1519. if (this.textLayer) {
  1520. var textLayerViewport = this.textLayer.viewport;
  1521. var textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  1522. var textAbsRotation = Math.abs(textRelativeRotation);
  1523. var scale = width / textLayerViewport.width;
  1524. if (textAbsRotation === 90 || textAbsRotation === 270) {
  1525. scale = width / textLayerViewport.height;
  1526. }
  1527. var textLayerDiv = this.textLayer.textLayerDiv;
  1528. var transX = void 0,
  1529. transY = void 0;
  1530. switch (textAbsRotation) {
  1531. case 0:
  1532. transX = transY = 0;
  1533. break;
  1534. case 90:
  1535. transX = 0;
  1536. transY = '-' + textLayerDiv.style.height;
  1537. break;
  1538. case 180:
  1539. transX = '-' + textLayerDiv.style.width;
  1540. transY = '-' + textLayerDiv.style.height;
  1541. break;
  1542. case 270:
  1543. transX = '-' + textLayerDiv.style.width;
  1544. transY = 0;
  1545. break;
  1546. default:
  1547. console.error('Bad rotation value.');
  1548. break;
  1549. }
  1550. _pdfjsLib.CustomStyle.setProp('transform', textLayerDiv, 'rotate(' + textAbsRotation + 'deg) ' + 'scale(' + scale + ', ' + scale + ') ' + 'translate(' + transX + ', ' + transY + ')');
  1551. _pdfjsLib.CustomStyle.setProp('transformOrigin', textLayerDiv, '0% 0%');
  1552. }
  1553. if (redrawAnnotations && this.annotationLayer) {
  1554. this.annotationLayer.render(this.viewport, 'display');
  1555. }
  1556. }
  1557. }, {
  1558. key: 'getPagePoint',
  1559. value: function getPagePoint(x, y) {
  1560. return this.viewport.convertToPdfPoint(x, y);
  1561. }
  1562. }, {
  1563. key: 'draw',
  1564. value: function draw() {
  1565. var _this = this;
  1566. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  1567. console.error('Must be in new state before drawing');
  1568. this.reset();
  1569. }
  1570. if (!this.pdfPage) {
  1571. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  1572. return Promise.reject(new Error('Page is not loaded'));
  1573. }
  1574. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  1575. var pdfPage = this.pdfPage;
  1576. var div = this.div;
  1577. var canvasWrapper = document.createElement('div');
  1578. canvasWrapper.style.width = div.style.width;
  1579. canvasWrapper.style.height = div.style.height;
  1580. canvasWrapper.classList.add('canvasWrapper');
  1581. if (this.annotationLayer && this.annotationLayer.div) {
  1582. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  1583. } else {
  1584. div.appendChild(canvasWrapper);
  1585. }
  1586. var textLayer = null;
  1587. if (this.textLayerFactory) {
  1588. var textLayerDiv = document.createElement('div');
  1589. textLayerDiv.className = 'textLayer';
  1590. textLayerDiv.style.width = canvasWrapper.style.width;
  1591. textLayerDiv.style.height = canvasWrapper.style.height;
  1592. if (this.annotationLayer && this.annotationLayer.div) {
  1593. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  1594. } else {
  1595. div.appendChild(textLayerDiv);
  1596. }
  1597. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.enhanceTextSelection);
  1598. }
  1599. this.textLayer = textLayer;
  1600. var renderContinueCallback = null;
  1601. if (this.renderingQueue) {
  1602. renderContinueCallback = function renderContinueCallback(cont) {
  1603. if (!_this.renderingQueue.isHighestPriority(_this)) {
  1604. _this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  1605. _this.resume = function () {
  1606. _this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  1607. cont();
  1608. };
  1609. return;
  1610. }
  1611. cont();
  1612. };
  1613. }
  1614. var finishPaintTask = function finishPaintTask(error) {
  1615. if (paintTask === _this.paintTask) {
  1616. _this.paintTask = null;
  1617. }
  1618. if (error === 'cancelled' || error instanceof _pdfjsLib.RenderingCancelledException) {
  1619. _this.error = null;
  1620. return Promise.resolve(undefined);
  1621. }
  1622. _this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  1623. if (_this.loadingIconDiv) {
  1624. div.removeChild(_this.loadingIconDiv);
  1625. delete _this.loadingIconDiv;
  1626. }
  1627. _this._resetZoomLayer(true);
  1628. _this.error = error;
  1629. _this.stats = pdfPage.stats;
  1630. if (_this.onAfterDraw) {
  1631. _this.onAfterDraw();
  1632. }
  1633. _this.eventBus.dispatch('pagerendered', {
  1634. source: _this,
  1635. pageNumber: _this.id,
  1636. cssTransform: false
  1637. });
  1638. if (error) {
  1639. return Promise.reject(error);
  1640. }
  1641. return Promise.resolve(undefined);
  1642. };
  1643. var paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  1644. paintTask.onRenderContinue = renderContinueCallback;
  1645. this.paintTask = paintTask;
  1646. var resultPromise = paintTask.promise.then(function () {
  1647. return finishPaintTask(null).then(function () {
  1648. if (textLayer) {
  1649. var readableStream = pdfPage.streamTextContent({ normalizeWhitespace: true });
  1650. textLayer.setTextContentStream(readableStream);
  1651. textLayer.render();
  1652. }
  1653. });
  1654. }, function (reason) {
  1655. return finishPaintTask(reason);
  1656. });
  1657. if (this.annotationLayerFactory) {
  1658. if (!this.annotationLayer) {
  1659. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.renderInteractiveForms, this.l10n);
  1660. }
  1661. this.annotationLayer.render(this.viewport, 'display');
  1662. }
  1663. div.setAttribute('data-loaded', true);
  1664. if (this.onBeforeDraw) {
  1665. this.onBeforeDraw();
  1666. }
  1667. return resultPromise;
  1668. }
  1669. }, {
  1670. key: 'paintOnCanvas',
  1671. value: function paintOnCanvas(canvasWrapper) {
  1672. var renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  1673. var result = {
  1674. promise: renderCapability.promise,
  1675. onRenderContinue: function onRenderContinue(cont) {
  1676. cont();
  1677. },
  1678. cancel: function cancel() {
  1679. renderTask.cancel();
  1680. }
  1681. };
  1682. var viewport = this.viewport;
  1683. var canvas = document.createElement('canvas');
  1684. canvas.id = this.renderingId;
  1685. canvas.setAttribute('hidden', 'hidden');
  1686. var isCanvasHidden = true;
  1687. var showCanvas = function showCanvas() {
  1688. if (isCanvasHidden) {
  1689. canvas.removeAttribute('hidden');
  1690. isCanvasHidden = false;
  1691. }
  1692. };
  1693. canvasWrapper.appendChild(canvas);
  1694. this.canvas = canvas;
  1695. canvas.mozOpaque = true;
  1696. var ctx = canvas.getContext('2d', { alpha: false });
  1697. var outputScale = (0, _ui_utils.getOutputScale)(ctx);
  1698. this.outputScale = outputScale;
  1699. if (_pdfjsLib.PDFJS.useOnlyCssZoom) {
  1700. var actualSizeViewport = viewport.clone({ scale: _ui_utils.CSS_UNITS });
  1701. outputScale.sx *= actualSizeViewport.width / viewport.width;
  1702. outputScale.sy *= actualSizeViewport.height / viewport.height;
  1703. outputScale.scaled = true;
  1704. }
  1705. if (_pdfjsLib.PDFJS.maxCanvasPixels > 0) {
  1706. var pixelsInViewport = viewport.width * viewport.height;
  1707. var maxScale = Math.sqrt(_pdfjsLib.PDFJS.maxCanvasPixels / pixelsInViewport);
  1708. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  1709. outputScale.sx = maxScale;
  1710. outputScale.sy = maxScale;
  1711. outputScale.scaled = true;
  1712. this.hasRestrictedScaling = true;
  1713. } else {
  1714. this.hasRestrictedScaling = false;
  1715. }
  1716. }
  1717. var sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  1718. var sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  1719. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  1720. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  1721. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + 'px';
  1722. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + 'px';
  1723. this.paintedViewportMap.set(canvas, viewport);
  1724. var transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  1725. var renderContext = {
  1726. canvasContext: ctx,
  1727. transform: transform,
  1728. viewport: this.viewport,
  1729. renderInteractiveForms: this.renderInteractiveForms
  1730. };
  1731. var renderTask = this.pdfPage.render(renderContext);
  1732. renderTask.onContinue = function (cont) {
  1733. showCanvas();
  1734. if (result.onRenderContinue) {
  1735. result.onRenderContinue(cont);
  1736. } else {
  1737. cont();
  1738. }
  1739. };
  1740. renderTask.promise.then(function () {
  1741. showCanvas();
  1742. renderCapability.resolve(undefined);
  1743. }, function (error) {
  1744. showCanvas();
  1745. renderCapability.reject(error);
  1746. });
  1747. return result;
  1748. }
  1749. }, {
  1750. key: 'paintOnSvg',
  1751. value: function paintOnSvg(wrapper) {
  1752. var _this2 = this;
  1753. var cancelled = false;
  1754. var ensureNotCancelled = function ensureNotCancelled() {
  1755. if (cancelled) {
  1756. if (_pdfjsLib.PDFJS.pdfjsNext) {
  1757. throw new _pdfjsLib.RenderingCancelledException('Rendering cancelled, page ' + _this2.id, 'svg');
  1758. } else {
  1759. throw 'cancelled';
  1760. }
  1761. }
  1762. };
  1763. var pdfPage = this.pdfPage;
  1764. var actualSizeViewport = this.viewport.clone({ scale: _ui_utils.CSS_UNITS });
  1765. var promise = pdfPage.getOperatorList().then(function (opList) {
  1766. ensureNotCancelled();
  1767. var svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  1768. return svgGfx.getSVG(opList, actualSizeViewport).then(function (svg) {
  1769. ensureNotCancelled();
  1770. _this2.svg = svg;
  1771. _this2.paintedViewportMap.set(svg, actualSizeViewport);
  1772. svg.style.width = wrapper.style.width;
  1773. svg.style.height = wrapper.style.height;
  1774. _this2.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  1775. wrapper.appendChild(svg);
  1776. });
  1777. });
  1778. return {
  1779. promise: promise,
  1780. onRenderContinue: function onRenderContinue(cont) {
  1781. cont();
  1782. },
  1783. cancel: function cancel() {
  1784. cancelled = true;
  1785. }
  1786. };
  1787. }
  1788. }, {
  1789. key: 'setPageLabel',
  1790. value: function setPageLabel(label) {
  1791. this.pageLabel = typeof label === 'string' ? label : null;
  1792. if (this.pageLabel !== null) {
  1793. this.div.setAttribute('data-page-label', this.pageLabel);
  1794. } else {
  1795. this.div.removeAttribute('data-page-label');
  1796. }
  1797. }
  1798. }, {
  1799. key: 'width',
  1800. get: function get() {
  1801. return this.viewport.width;
  1802. }
  1803. }, {
  1804. key: 'height',
  1805. get: function get() {
  1806. return this.viewport.height;
  1807. }
  1808. }]);
  1809. return PDFPageView;
  1810. }();
  1811. exports.PDFPageView = PDFPageView;
  1812. /***/ }),
  1813. /* 7 */
  1814. /***/ (function(module, exports, __w_pdfjs_require__) {
  1815. "use strict";
  1816. Object.defineProperty(exports, "__esModule", {
  1817. value: true
  1818. });
  1819. exports.DefaultTextLayerFactory = exports.TextLayerBuilder = undefined;
  1820. 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; }; }();
  1821. var _dom_events = __w_pdfjs_require__(2);
  1822. var _pdfjsLib = __w_pdfjs_require__(0);
  1823. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1824. var EXPAND_DIVS_TIMEOUT = 300;
  1825. var TextLayerBuilder = function () {
  1826. function TextLayerBuilder(_ref) {
  1827. var textLayerDiv = _ref.textLayerDiv,
  1828. eventBus = _ref.eventBus,
  1829. pageIndex = _ref.pageIndex,
  1830. viewport = _ref.viewport,
  1831. _ref$findController = _ref.findController,
  1832. findController = _ref$findController === undefined ? null : _ref$findController,
  1833. _ref$enhanceTextSelec = _ref.enhanceTextSelection,
  1834. enhanceTextSelection = _ref$enhanceTextSelec === undefined ? false : _ref$enhanceTextSelec;
  1835. _classCallCheck(this, TextLayerBuilder);
  1836. this.textLayerDiv = textLayerDiv;
  1837. this.eventBus = eventBus || (0, _dom_events.getGlobalEventBus)();
  1838. this.textContent = null;
  1839. this.textContentItemsStr = [];
  1840. this.textContentStream = null;
  1841. this.renderingDone = false;
  1842. this.pageIdx = pageIndex;
  1843. this.pageNumber = this.pageIdx + 1;
  1844. this.matches = [];
  1845. this.viewport = viewport;
  1846. this.textDivs = [];
  1847. this.findController = findController;
  1848. this.textLayerRenderTask = null;
  1849. this.enhanceTextSelection = enhanceTextSelection;
  1850. this._bindMouse();
  1851. }
  1852. _createClass(TextLayerBuilder, [{
  1853. key: '_finishRendering',
  1854. value: function _finishRendering() {
  1855. this.renderingDone = true;
  1856. if (!this.enhanceTextSelection) {
  1857. var endOfContent = document.createElement('div');
  1858. endOfContent.className = 'endOfContent';
  1859. this.textLayerDiv.appendChild(endOfContent);
  1860. }
  1861. this.eventBus.dispatch('textlayerrendered', {
  1862. source: this,
  1863. pageNumber: this.pageNumber,
  1864. numTextDivs: this.textDivs.length
  1865. });
  1866. }
  1867. }, {
  1868. key: 'render',
  1869. value: function render() {
  1870. var _this = this;
  1871. var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1872. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  1873. return;
  1874. }
  1875. this.cancel();
  1876. this.textDivs = [];
  1877. var textLayerFrag = document.createDocumentFragment();
  1878. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  1879. textContent: this.textContent,
  1880. textContentStream: this.textContentStream,
  1881. container: textLayerFrag,
  1882. viewport: this.viewport,
  1883. textDivs: this.textDivs,
  1884. textContentItemsStr: this.textContentItemsStr,
  1885. timeout: timeout,
  1886. enhanceTextSelection: this.enhanceTextSelection
  1887. });
  1888. this.textLayerRenderTask.promise.then(function () {
  1889. _this.textLayerDiv.appendChild(textLayerFrag);
  1890. _this._finishRendering();
  1891. _this.updateMatches();
  1892. }, function (reason) {});
  1893. }
  1894. }, {
  1895. key: 'cancel',
  1896. value: function cancel() {
  1897. if (this.textLayerRenderTask) {
  1898. this.textLayerRenderTask.cancel();
  1899. this.textLayerRenderTask = null;
  1900. }
  1901. }
  1902. }, {
  1903. key: 'setTextContentStream',
  1904. value: function setTextContentStream(readableStream) {
  1905. this.cancel();
  1906. this.textContentStream = readableStream;
  1907. }
  1908. }, {
  1909. key: 'setTextContent',
  1910. value: function setTextContent(textContent) {
  1911. this.cancel();
  1912. this.textContent = textContent;
  1913. }
  1914. }, {
  1915. key: 'convertMatches',
  1916. value: function convertMatches(matches, matchesLength) {
  1917. var i = 0;
  1918. var iIndex = 0;
  1919. var textContentItemsStr = this.textContentItemsStr;
  1920. var end = textContentItemsStr.length - 1;
  1921. var queryLen = this.findController === null ? 0 : this.findController.state.query.length;
  1922. var ret = [];
  1923. if (!matches) {
  1924. return ret;
  1925. }
  1926. for (var m = 0, len = matches.length; m < len; m++) {
  1927. var matchIdx = matches[m];
  1928. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  1929. iIndex += textContentItemsStr[i].length;
  1930. i++;
  1931. }
  1932. if (i === textContentItemsStr.length) {
  1933. console.error('Could not find a matching mapping');
  1934. }
  1935. var match = {
  1936. begin: {
  1937. divIdx: i,
  1938. offset: matchIdx - iIndex
  1939. }
  1940. };
  1941. if (matchesLength) {
  1942. matchIdx += matchesLength[m];
  1943. } else {
  1944. matchIdx += queryLen;
  1945. }
  1946. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  1947. iIndex += textContentItemsStr[i].length;
  1948. i++;
  1949. }
  1950. match.end = {
  1951. divIdx: i,
  1952. offset: matchIdx - iIndex
  1953. };
  1954. ret.push(match);
  1955. }
  1956. return ret;
  1957. }
  1958. }, {
  1959. key: 'renderMatches',
  1960. value: function renderMatches(matches) {
  1961. if (matches.length === 0) {
  1962. return;
  1963. }
  1964. var textContentItemsStr = this.textContentItemsStr;
  1965. var textDivs = this.textDivs;
  1966. var prevEnd = null;
  1967. var pageIdx = this.pageIdx;
  1968. var isSelectedPage = this.findController === null ? false : pageIdx === this.findController.selected.pageIdx;
  1969. var selectedMatchIdx = this.findController === null ? -1 : this.findController.selected.matchIdx;
  1970. var highlightAll = this.findController === null ? false : this.findController.state.highlightAll;
  1971. var infinity = {
  1972. divIdx: -1,
  1973. offset: undefined
  1974. };
  1975. function beginText(begin, className) {
  1976. var divIdx = begin.divIdx;
  1977. textDivs[divIdx].textContent = '';
  1978. appendTextToDiv(divIdx, 0, begin.offset, className);
  1979. }
  1980. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  1981. var div = textDivs[divIdx];
  1982. var content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  1983. var node = document.createTextNode(content);
  1984. if (className) {
  1985. var span = document.createElement('span');
  1986. span.className = className;
  1987. span.appendChild(node);
  1988. div.appendChild(span);
  1989. return;
  1990. }
  1991. div.appendChild(node);
  1992. }
  1993. var i0 = selectedMatchIdx,
  1994. i1 = i0 + 1;
  1995. if (highlightAll) {
  1996. i0 = 0;
  1997. i1 = matches.length;
  1998. } else if (!isSelectedPage) {
  1999. return;
  2000. }
  2001. for (var i = i0; i < i1; i++) {
  2002. var match = matches[i];
  2003. var begin = match.begin;
  2004. var end = match.end;
  2005. var isSelected = isSelectedPage && i === selectedMatchIdx;
  2006. var highlightSuffix = isSelected ? ' selected' : '';
  2007. if (this.findController) {
  2008. this.findController.updateMatchPosition(pageIdx, i, textDivs, begin.divIdx);
  2009. }
  2010. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  2011. if (prevEnd !== null) {
  2012. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  2013. }
  2014. beginText(begin);
  2015. } else {
  2016. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  2017. }
  2018. if (begin.divIdx === end.divIdx) {
  2019. appendTextToDiv(begin.divIdx, begin.offset, end.offset, 'highlight' + highlightSuffix);
  2020. } else {
  2021. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, 'highlight begin' + highlightSuffix);
  2022. for (var n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  2023. textDivs[n0].className = 'highlight middle' + highlightSuffix;
  2024. }
  2025. beginText(end, 'highlight end' + highlightSuffix);
  2026. }
  2027. prevEnd = end;
  2028. }
  2029. if (prevEnd) {
  2030. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  2031. }
  2032. }
  2033. }, {
  2034. key: 'updateMatches',
  2035. value: function updateMatches() {
  2036. if (!this.renderingDone) {
  2037. return;
  2038. }
  2039. var matches = this.matches;
  2040. var textDivs = this.textDivs;
  2041. var textContentItemsStr = this.textContentItemsStr;
  2042. var clearedUntilDivIdx = -1;
  2043. for (var i = 0, len = matches.length; i < len; i++) {
  2044. var match = matches[i];
  2045. var begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  2046. for (var n = begin, end = match.end.divIdx; n <= end; n++) {
  2047. var div = textDivs[n];
  2048. div.textContent = textContentItemsStr[n];
  2049. div.className = '';
  2050. }
  2051. clearedUntilDivIdx = match.end.divIdx + 1;
  2052. }
  2053. if (this.findController === null || !this.findController.active) {
  2054. return;
  2055. }
  2056. var pageMatches = void 0,
  2057. pageMatchesLength = void 0;
  2058. if (this.findController !== null) {
  2059. pageMatches = this.findController.pageMatches[this.pageIdx] || null;
  2060. pageMatchesLength = this.findController.pageMatchesLength ? this.findController.pageMatchesLength[this.pageIdx] || null : null;
  2061. }
  2062. this.matches = this.convertMatches(pageMatches, pageMatchesLength);
  2063. this.renderMatches(this.matches);
  2064. }
  2065. }, {
  2066. key: '_bindMouse',
  2067. value: function _bindMouse() {
  2068. var _this2 = this;
  2069. var div = this.textLayerDiv;
  2070. var expandDivsTimer = null;
  2071. div.addEventListener('mousedown', function (evt) {
  2072. if (_this2.enhanceTextSelection && _this2.textLayerRenderTask) {
  2073. _this2.textLayerRenderTask.expandTextDivs(true);
  2074. if (expandDivsTimer) {
  2075. clearTimeout(expandDivsTimer);
  2076. expandDivsTimer = null;
  2077. }
  2078. return;
  2079. }
  2080. var end = div.querySelector('.endOfContent');
  2081. if (!end) {
  2082. return;
  2083. }
  2084. var adjustTop = evt.target !== div;
  2085. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue('-moz-user-select') !== 'none';
  2086. if (adjustTop) {
  2087. var divBounds = div.getBoundingClientRect();
  2088. var r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  2089. end.style.top = (r * 100).toFixed(2) + '%';
  2090. }
  2091. end.classList.add('active');
  2092. });
  2093. div.addEventListener('mouseup', function () {
  2094. if (_this2.enhanceTextSelection && _this2.textLayerRenderTask) {
  2095. expandDivsTimer = setTimeout(function () {
  2096. if (_this2.textLayerRenderTask) {
  2097. _this2.textLayerRenderTask.expandTextDivs(false);
  2098. }
  2099. expandDivsTimer = null;
  2100. }, EXPAND_DIVS_TIMEOUT);
  2101. return;
  2102. }
  2103. var end = div.querySelector('.endOfContent');
  2104. if (!end) {
  2105. return;
  2106. }
  2107. end.style.top = '';
  2108. end.classList.remove('active');
  2109. });
  2110. }
  2111. }]);
  2112. return TextLayerBuilder;
  2113. }();
  2114. var DefaultTextLayerFactory = function () {
  2115. function DefaultTextLayerFactory() {
  2116. _classCallCheck(this, DefaultTextLayerFactory);
  2117. }
  2118. _createClass(DefaultTextLayerFactory, [{
  2119. key: 'createTextLayerBuilder',
  2120. value: function createTextLayerBuilder(textLayerDiv, pageIndex, viewport) {
  2121. var enhanceTextSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  2122. return new TextLayerBuilder({
  2123. textLayerDiv: textLayerDiv,
  2124. pageIndex: pageIndex,
  2125. viewport: viewport,
  2126. enhanceTextSelection: enhanceTextSelection
  2127. });
  2128. }
  2129. }]);
  2130. return DefaultTextLayerFactory;
  2131. }();
  2132. exports.TextLayerBuilder = TextLayerBuilder;
  2133. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  2134. /***/ }),
  2135. /* 8 */
  2136. /***/ (function(module, exports, __w_pdfjs_require__) {
  2137. "use strict";
  2138. var pdfjsLib = __w_pdfjs_require__(0);
  2139. var pdfjsWebPDFViewer = __w_pdfjs_require__(9);
  2140. var pdfjsWebPDFPageView = __w_pdfjs_require__(6);
  2141. var pdfjsWebPDFLinkService = __w_pdfjs_require__(3);
  2142. var pdfjsWebTextLayerBuilder = __w_pdfjs_require__(7);
  2143. var pdfjsWebAnnotationLayerBuilder = __w_pdfjs_require__(5);
  2144. var pdfjsWebPDFHistory = __w_pdfjs_require__(10);
  2145. var pdfjsWebPDFFindController = __w_pdfjs_require__(11);
  2146. var pdfjsWebUIUtils = __w_pdfjs_require__(1);
  2147. var pdfjsWebDownloadManager = __w_pdfjs_require__(12);
  2148. var pdfjsWebGenericL10n = __w_pdfjs_require__(13);
  2149. var PDFJS = pdfjsLib.PDFJS;
  2150. PDFJS.PDFViewer = pdfjsWebPDFViewer.PDFViewer;
  2151. PDFJS.PDFPageView = pdfjsWebPDFPageView.PDFPageView;
  2152. PDFJS.PDFLinkService = pdfjsWebPDFLinkService.PDFLinkService;
  2153. PDFJS.TextLayerBuilder = pdfjsWebTextLayerBuilder.TextLayerBuilder;
  2154. PDFJS.DefaultTextLayerFactory = pdfjsWebTextLayerBuilder.DefaultTextLayerFactory;
  2155. PDFJS.AnnotationLayerBuilder = pdfjsWebAnnotationLayerBuilder.AnnotationLayerBuilder;
  2156. PDFJS.DefaultAnnotationLayerFactory = pdfjsWebAnnotationLayerBuilder.DefaultAnnotationLayerFactory;
  2157. PDFJS.PDFHistory = pdfjsWebPDFHistory.PDFHistory;
  2158. PDFJS.PDFFindController = pdfjsWebPDFFindController.PDFFindController;
  2159. PDFJS.EventBus = pdfjsWebUIUtils.EventBus;
  2160. PDFJS.DownloadManager = pdfjsWebDownloadManager.DownloadManager;
  2161. PDFJS.ProgressBar = pdfjsWebUIUtils.ProgressBar;
  2162. PDFJS.GenericL10n = pdfjsWebGenericL10n.GenericL10n;
  2163. PDFJS.NullL10n = pdfjsWebUIUtils.NullL10n;
  2164. exports.PDFJS = PDFJS;
  2165. /***/ }),
  2166. /* 9 */
  2167. /***/ (function(module, exports, __w_pdfjs_require__) {
  2168. "use strict";
  2169. Object.defineProperty(exports, "__esModule", {
  2170. value: true
  2171. });
  2172. exports.PDFViewer = exports.PresentationModeState = undefined;
  2173. 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; }; }();
  2174. var _pdfjsLib = __w_pdfjs_require__(0);
  2175. var _ui_utils = __w_pdfjs_require__(1);
  2176. var _pdf_rendering_queue = __w_pdfjs_require__(4);
  2177. var _annotation_layer_builder = __w_pdfjs_require__(5);
  2178. var _dom_events = __w_pdfjs_require__(2);
  2179. var _pdf_page_view = __w_pdfjs_require__(6);
  2180. var _pdf_link_service = __w_pdfjs_require__(3);
  2181. var _text_layer_builder = __w_pdfjs_require__(7);
  2182. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2183. var PresentationModeState = {
  2184. UNKNOWN: 0,
  2185. NORMAL: 1,
  2186. CHANGING: 2,
  2187. FULLSCREEN: 3
  2188. };
  2189. var DEFAULT_CACHE_SIZE = 10;
  2190. function PDFPageViewBuffer(size) {
  2191. var data = [];
  2192. this.push = function cachePush(view) {
  2193. var i = data.indexOf(view);
  2194. if (i >= 0) {
  2195. data.splice(i, 1);
  2196. }
  2197. data.push(view);
  2198. if (data.length > size) {
  2199. data.shift().destroy();
  2200. }
  2201. };
  2202. this.resize = function (newSize) {
  2203. size = newSize;
  2204. while (data.length > size) {
  2205. data.shift().destroy();
  2206. }
  2207. };
  2208. }
  2209. function isSameScale(oldScale, newScale) {
  2210. if (newScale === oldScale) {
  2211. return true;
  2212. }
  2213. if (Math.abs(newScale - oldScale) < 1e-15) {
  2214. return true;
  2215. }
  2216. return false;
  2217. }
  2218. function isPortraitOrientation(size) {
  2219. return size.width <= size.height;
  2220. }
  2221. var PDFViewer = function () {
  2222. function PDFViewer(options) {
  2223. _classCallCheck(this, PDFViewer);
  2224. this.container = options.container;
  2225. this.viewer = options.viewer || options.container.firstElementChild;
  2226. this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
  2227. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  2228. this.downloadManager = options.downloadManager || null;
  2229. this.removePageBorders = options.removePageBorders || false;
  2230. this.enhanceTextSelection = options.enhanceTextSelection || false;
  2231. this.renderInteractiveForms = options.renderInteractiveForms || false;
  2232. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  2233. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  2234. this.l10n = options.l10n || _ui_utils.NullL10n;
  2235. this.defaultRenderingQueue = !options.renderingQueue;
  2236. if (this.defaultRenderingQueue) {
  2237. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  2238. this.renderingQueue.setViewer(this);
  2239. } else {
  2240. this.renderingQueue = options.renderingQueue;
  2241. }
  2242. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  2243. this.presentationModeState = PresentationModeState.UNKNOWN;
  2244. this._resetView();
  2245. if (this.removePageBorders) {
  2246. this.viewer.classList.add('removePageBorders');
  2247. }
  2248. }
  2249. _createClass(PDFViewer, [{
  2250. key: 'getPageView',
  2251. value: function getPageView(index) {
  2252. return this._pages[index];
  2253. }
  2254. }, {
  2255. key: '_setCurrentPageNumber',
  2256. value: function _setCurrentPageNumber(val) {
  2257. var resetCurrentPageView = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2258. if (this._currentPageNumber === val) {
  2259. if (resetCurrentPageView) {
  2260. this._resetCurrentPageView();
  2261. }
  2262. return;
  2263. }
  2264. if (!(0 < val && val <= this.pagesCount)) {
  2265. console.error('PDFViewer._setCurrentPageNumber: "' + val + '" is out of bounds.');
  2266. return;
  2267. }
  2268. var arg = {
  2269. source: this,
  2270. pageNumber: val,
  2271. pageLabel: this._pageLabels && this._pageLabels[val - 1]
  2272. };
  2273. this._currentPageNumber = val;
  2274. this.eventBus.dispatch('pagechanging', arg);
  2275. this.eventBus.dispatch('pagechange', arg);
  2276. if (resetCurrentPageView) {
  2277. this._resetCurrentPageView();
  2278. }
  2279. }
  2280. }, {
  2281. key: 'setDocument',
  2282. value: function setDocument(pdfDocument) {
  2283. var _this = this;
  2284. if (this.pdfDocument) {
  2285. this._cancelRendering();
  2286. this._resetView();
  2287. }
  2288. this.pdfDocument = pdfDocument;
  2289. if (!pdfDocument) {
  2290. return;
  2291. }
  2292. var pagesCount = pdfDocument.numPages;
  2293. var pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  2294. this.pagesPromise = pagesCapability.promise;
  2295. pagesCapability.promise.then(function () {
  2296. _this._pageViewsReady = true;
  2297. _this.eventBus.dispatch('pagesloaded', {
  2298. source: _this,
  2299. pagesCount: pagesCount
  2300. });
  2301. });
  2302. var isOnePageRenderedResolved = false;
  2303. var onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  2304. this.onePageRendered = onePageRenderedCapability.promise;
  2305. var bindOnAfterAndBeforeDraw = function bindOnAfterAndBeforeDraw(pageView) {
  2306. pageView.onBeforeDraw = function () {
  2307. _this._buffer.push(pageView);
  2308. };
  2309. pageView.onAfterDraw = function () {
  2310. if (!isOnePageRenderedResolved) {
  2311. isOnePageRenderedResolved = true;
  2312. onePageRenderedCapability.resolve();
  2313. }
  2314. };
  2315. };
  2316. var firstPagePromise = pdfDocument.getPage(1);
  2317. this.firstPagePromise = firstPagePromise;
  2318. firstPagePromise.then(function (pdfPage) {
  2319. var scale = _this.currentScale;
  2320. var viewport = pdfPage.getViewport(scale * _ui_utils.CSS_UNITS);
  2321. for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  2322. var textLayerFactory = null;
  2323. if (!_pdfjsLib.PDFJS.disableTextLayer) {
  2324. textLayerFactory = _this;
  2325. }
  2326. var pageView = new _pdf_page_view.PDFPageView({
  2327. container: _this.viewer,
  2328. eventBus: _this.eventBus,
  2329. id: pageNum,
  2330. scale: scale,
  2331. defaultViewport: viewport.clone(),
  2332. renderingQueue: _this.renderingQueue,
  2333. textLayerFactory: textLayerFactory,
  2334. annotationLayerFactory: _this,
  2335. enhanceTextSelection: _this.enhanceTextSelection,
  2336. renderInteractiveForms: _this.renderInteractiveForms,
  2337. renderer: _this.renderer,
  2338. l10n: _this.l10n
  2339. });
  2340. bindOnAfterAndBeforeDraw(pageView);
  2341. _this._pages.push(pageView);
  2342. }
  2343. onePageRenderedCapability.promise.then(function () {
  2344. if (_pdfjsLib.PDFJS.disableAutoFetch) {
  2345. pagesCapability.resolve();
  2346. return;
  2347. }
  2348. var getPagesLeft = pagesCount;
  2349. var _loop = function _loop(_pageNum) {
  2350. pdfDocument.getPage(_pageNum).then(function (pdfPage) {
  2351. var pageView = _this._pages[_pageNum - 1];
  2352. if (!pageView.pdfPage) {
  2353. pageView.setPdfPage(pdfPage);
  2354. }
  2355. _this.linkService.cachePageRef(_pageNum, pdfPage.ref);
  2356. if (--getPagesLeft === 0) {
  2357. pagesCapability.resolve();
  2358. }
  2359. }, function (reason) {
  2360. console.error('Unable to get page ' + _pageNum + ' to initialize viewer', reason);
  2361. if (--getPagesLeft === 0) {
  2362. pagesCapability.resolve();
  2363. }
  2364. });
  2365. };
  2366. for (var _pageNum = 1; _pageNum <= pagesCount; ++_pageNum) {
  2367. _loop(_pageNum);
  2368. }
  2369. });
  2370. _this.eventBus.dispatch('pagesinit', { source: _this });
  2371. if (_this.defaultRenderingQueue) {
  2372. _this.update();
  2373. }
  2374. if (_this.findController) {
  2375. _this.findController.resolveFirstPage();
  2376. }
  2377. }).catch(function (reason) {
  2378. console.error('Unable to initialize viewer', reason);
  2379. });
  2380. }
  2381. }, {
  2382. key: 'setPageLabels',
  2383. value: function setPageLabels(labels) {
  2384. if (!this.pdfDocument) {
  2385. return;
  2386. }
  2387. if (!labels) {
  2388. this._pageLabels = null;
  2389. } else if (!(labels instanceof Array && this.pdfDocument.numPages === labels.length)) {
  2390. this._pageLabels = null;
  2391. console.error('PDFViewer.setPageLabels: Invalid page labels.');
  2392. } else {
  2393. this._pageLabels = labels;
  2394. }
  2395. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  2396. var pageView = this._pages[i];
  2397. var label = this._pageLabels && this._pageLabels[i];
  2398. pageView.setPageLabel(label);
  2399. }
  2400. }
  2401. }, {
  2402. key: '_resetView',
  2403. value: function _resetView() {
  2404. this._pages = [];
  2405. this._currentPageNumber = 1;
  2406. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  2407. this._currentScaleValue = null;
  2408. this._pageLabels = null;
  2409. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  2410. this._location = null;
  2411. this._pagesRotation = 0;
  2412. this._pagesRequests = [];
  2413. this._pageViewsReady = false;
  2414. this.viewer.textContent = '';
  2415. }
  2416. }, {
  2417. key: '_scrollUpdate',
  2418. value: function _scrollUpdate() {
  2419. if (this.pagesCount === 0) {
  2420. return;
  2421. }
  2422. this.update();
  2423. }
  2424. }, {
  2425. key: '_setScaleDispatchEvent',
  2426. value: function _setScaleDispatchEvent(newScale, newValue) {
  2427. var preset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  2428. var arg = {
  2429. source: this,
  2430. scale: newScale,
  2431. presetValue: preset ? newValue : undefined
  2432. };
  2433. this.eventBus.dispatch('scalechanging', arg);
  2434. this.eventBus.dispatch('scalechange', arg);
  2435. }
  2436. }, {
  2437. key: '_setScaleUpdatePages',
  2438. value: function _setScaleUpdatePages(newScale, newValue) {
  2439. var noScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  2440. var preset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  2441. this._currentScaleValue = newValue.toString();
  2442. if (isSameScale(this._currentScale, newScale)) {
  2443. if (preset) {
  2444. this._setScaleDispatchEvent(newScale, newValue, true);
  2445. }
  2446. return;
  2447. }
  2448. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  2449. this._pages[i].update(newScale);
  2450. }
  2451. this._currentScale = newScale;
  2452. if (!noScroll) {
  2453. var page = this._currentPageNumber,
  2454. dest = void 0;
  2455. if (this._location && !_pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  2456. page = this._location.pageNumber;
  2457. dest = [null, { name: 'XYZ' }, this._location.left, this._location.top, null];
  2458. }
  2459. this.scrollPageIntoView({
  2460. pageNumber: page,
  2461. destArray: dest,
  2462. allowNegativeOffset: true
  2463. });
  2464. }
  2465. this._setScaleDispatchEvent(newScale, newValue, preset);
  2466. if (this.defaultRenderingQueue) {
  2467. this.update();
  2468. }
  2469. }
  2470. }, {
  2471. key: '_setScale',
  2472. value: function _setScale(value) {
  2473. var noScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2474. var scale = parseFloat(value);
  2475. if (scale > 0) {
  2476. this._setScaleUpdatePages(scale, value, noScroll, false);
  2477. } else {
  2478. var currentPage = this._pages[this._currentPageNumber - 1];
  2479. if (!currentPage) {
  2480. return;
  2481. }
  2482. var hPadding = this.isInPresentationMode || this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  2483. var vPadding = this.isInPresentationMode || this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  2484. var pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale;
  2485. var pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  2486. switch (value) {
  2487. case 'page-actual':
  2488. scale = 1;
  2489. break;
  2490. case 'page-width':
  2491. scale = pageWidthScale;
  2492. break;
  2493. case 'page-height':
  2494. scale = pageHeightScale;
  2495. break;
  2496. case 'page-fit':
  2497. scale = Math.min(pageWidthScale, pageHeightScale);
  2498. break;
  2499. case 'auto':
  2500. var isLandscape = currentPage.width > currentPage.height;
  2501. var horizontalScale = isLandscape ? Math.min(pageHeightScale, pageWidthScale) : pageWidthScale;
  2502. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  2503. break;
  2504. default:
  2505. console.error('PDFViewer._setScale: "' + value + '" is an unknown zoom value.');
  2506. return;
  2507. }
  2508. this._setScaleUpdatePages(scale, value, noScroll, true);
  2509. }
  2510. }
  2511. }, {
  2512. key: '_resetCurrentPageView',
  2513. value: function _resetCurrentPageView() {
  2514. if (this.isInPresentationMode) {
  2515. this._setScale(this._currentScaleValue, true);
  2516. }
  2517. var pageView = this._pages[this._currentPageNumber - 1];
  2518. (0, _ui_utils.scrollIntoView)(pageView.div);
  2519. }
  2520. }, {
  2521. key: 'scrollPageIntoView',
  2522. value: function scrollPageIntoView(params) {
  2523. if (arguments.length > 1 || typeof params === 'number') {
  2524. console.error('Call of scrollPageIntoView() with obsolete signature.');
  2525. return;
  2526. }
  2527. if (!this.pdfDocument) {
  2528. return;
  2529. }
  2530. var pageNumber = params.pageNumber || 0;
  2531. var dest = params.destArray || null;
  2532. var allowNegativeOffset = params.allowNegativeOffset || false;
  2533. if (this.isInPresentationMode || !dest) {
  2534. this._setCurrentPageNumber(pageNumber, true);
  2535. return;
  2536. }
  2537. var pageView = this._pages[pageNumber - 1];
  2538. if (!pageView) {
  2539. console.error('PDFViewer.scrollPageIntoView: Invalid "pageNumber" parameter.');
  2540. return;
  2541. }
  2542. var x = 0,
  2543. y = 0;
  2544. var width = 0,
  2545. height = 0,
  2546. widthScale = void 0,
  2547. heightScale = void 0;
  2548. var changeOrientation = pageView.rotation % 180 === 0 ? false : true;
  2549. var pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
  2550. var pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
  2551. var scale = 0;
  2552. switch (dest[1].name) {
  2553. case 'XYZ':
  2554. x = dest[2];
  2555. y = dest[3];
  2556. scale = dest[4];
  2557. x = x !== null ? x : 0;
  2558. y = y !== null ? y : pageHeight;
  2559. break;
  2560. case 'Fit':
  2561. case 'FitB':
  2562. scale = 'page-fit';
  2563. break;
  2564. case 'FitH':
  2565. case 'FitBH':
  2566. y = dest[2];
  2567. scale = 'page-width';
  2568. if (y === null && this._location) {
  2569. x = this._location.left;
  2570. y = this._location.top;
  2571. }
  2572. break;
  2573. case 'FitV':
  2574. case 'FitBV':
  2575. x = dest[2];
  2576. width = pageWidth;
  2577. height = pageHeight;
  2578. scale = 'page-height';
  2579. break;
  2580. case 'FitR':
  2581. x = dest[2];
  2582. y = dest[3];
  2583. width = dest[4] - x;
  2584. height = dest[5] - y;
  2585. var hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  2586. var vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  2587. widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
  2588. heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
  2589. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  2590. break;
  2591. default:
  2592. console.error('PDFViewer.scrollPageIntoView: "' + dest[1].name + '" ' + 'is not a valid destination type.');
  2593. return;
  2594. }
  2595. if (scale && scale !== this._currentScale) {
  2596. this.currentScaleValue = scale;
  2597. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  2598. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  2599. }
  2600. if (scale === 'page-fit' && !dest[4]) {
  2601. (0, _ui_utils.scrollIntoView)(pageView.div);
  2602. return;
  2603. }
  2604. var boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  2605. var left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  2606. var top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  2607. if (!allowNegativeOffset) {
  2608. left = Math.max(left, 0);
  2609. top = Math.max(top, 0);
  2610. }
  2611. (0, _ui_utils.scrollIntoView)(pageView.div, {
  2612. left: left,
  2613. top: top
  2614. });
  2615. }
  2616. }, {
  2617. key: '_updateLocation',
  2618. value: function _updateLocation(firstPage) {
  2619. var currentScale = this._currentScale;
  2620. var currentScaleValue = this._currentScaleValue;
  2621. var normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  2622. var pageNumber = firstPage.id;
  2623. var pdfOpenParams = '#page=' + pageNumber;
  2624. pdfOpenParams += '&zoom=' + normalizedScaleValue;
  2625. var currentPageView = this._pages[pageNumber - 1];
  2626. var container = this.container;
  2627. var topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  2628. var intLeft = Math.round(topLeft[0]);
  2629. var intTop = Math.round(topLeft[1]);
  2630. pdfOpenParams += ',' + intLeft + ',' + intTop;
  2631. this._location = {
  2632. pageNumber: pageNumber,
  2633. scale: normalizedScaleValue,
  2634. top: intTop,
  2635. left: intLeft,
  2636. pdfOpenParams: pdfOpenParams
  2637. };
  2638. }
  2639. }, {
  2640. key: 'update',
  2641. value: function update() {
  2642. var visible = this._getVisiblePages();
  2643. var visiblePages = visible.views;
  2644. if (visiblePages.length === 0) {
  2645. return;
  2646. }
  2647. var suggestedCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * visiblePages.length + 1);
  2648. this._buffer.resize(suggestedCacheSize);
  2649. this.renderingQueue.renderHighestPriority(visible);
  2650. var currentId = this._currentPageNumber;
  2651. var firstPage = visible.first;
  2652. var stillFullyVisible = false;
  2653. for (var i = 0, ii = visiblePages.length; i < ii; ++i) {
  2654. var page = visiblePages[i];
  2655. if (page.percent < 100) {
  2656. break;
  2657. }
  2658. if (page.id === currentId) {
  2659. stillFullyVisible = true;
  2660. break;
  2661. }
  2662. }
  2663. if (!stillFullyVisible) {
  2664. currentId = visiblePages[0].id;
  2665. }
  2666. if (!this.isInPresentationMode) {
  2667. this._setCurrentPageNumber(currentId);
  2668. }
  2669. this._updateLocation(firstPage);
  2670. this.eventBus.dispatch('updateviewarea', {
  2671. source: this,
  2672. location: this._location
  2673. });
  2674. }
  2675. }, {
  2676. key: 'containsElement',
  2677. value: function containsElement(element) {
  2678. return this.container.contains(element);
  2679. }
  2680. }, {
  2681. key: 'focus',
  2682. value: function focus() {
  2683. this.container.focus();
  2684. }
  2685. }, {
  2686. key: '_getVisiblePages',
  2687. value: function _getVisiblePages() {
  2688. if (!this.isInPresentationMode) {
  2689. return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true);
  2690. }
  2691. var visible = [];
  2692. var currentPage = this._pages[this._currentPageNumber - 1];
  2693. visible.push({
  2694. id: currentPage.id,
  2695. view: currentPage
  2696. });
  2697. return {
  2698. first: currentPage,
  2699. last: currentPage,
  2700. views: visible
  2701. };
  2702. }
  2703. }, {
  2704. key: 'cleanup',
  2705. value: function cleanup() {
  2706. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  2707. if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  2708. this._pages[i].reset();
  2709. }
  2710. }
  2711. }
  2712. }, {
  2713. key: '_cancelRendering',
  2714. value: function _cancelRendering() {
  2715. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  2716. if (this._pages[i]) {
  2717. this._pages[i].cancelRendering();
  2718. }
  2719. }
  2720. }
  2721. }, {
  2722. key: '_ensurePdfPageLoaded',
  2723. value: function _ensurePdfPageLoaded(pageView) {
  2724. var _this2 = this;
  2725. if (pageView.pdfPage) {
  2726. return Promise.resolve(pageView.pdfPage);
  2727. }
  2728. var pageNumber = pageView.id;
  2729. if (this._pagesRequests[pageNumber]) {
  2730. return this._pagesRequests[pageNumber];
  2731. }
  2732. var promise = this.pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  2733. if (!pageView.pdfPage) {
  2734. pageView.setPdfPage(pdfPage);
  2735. }
  2736. _this2._pagesRequests[pageNumber] = null;
  2737. return pdfPage;
  2738. }).catch(function (reason) {
  2739. console.error('Unable to get page for page view', reason);
  2740. _this2._pagesRequests[pageNumber] = null;
  2741. });
  2742. this._pagesRequests[pageNumber] = promise;
  2743. return promise;
  2744. }
  2745. }, {
  2746. key: 'forceRendering',
  2747. value: function forceRendering(currentlyVisiblePages) {
  2748. var _this3 = this;
  2749. var visiblePages = currentlyVisiblePages || this._getVisiblePages();
  2750. var pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, this.scroll.down);
  2751. if (pageView) {
  2752. this._ensurePdfPageLoaded(pageView).then(function () {
  2753. _this3.renderingQueue.renderView(pageView);
  2754. });
  2755. return true;
  2756. }
  2757. return false;
  2758. }
  2759. }, {
  2760. key: 'getPageTextContent',
  2761. value: function getPageTextContent(pageIndex) {
  2762. return this.pdfDocument.getPage(pageIndex + 1).then(function (page) {
  2763. return page.getTextContent({ normalizeWhitespace: true });
  2764. });
  2765. }
  2766. }, {
  2767. key: 'createTextLayerBuilder',
  2768. value: function createTextLayerBuilder(textLayerDiv, pageIndex, viewport) {
  2769. var enhanceTextSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  2770. return new _text_layer_builder.TextLayerBuilder({
  2771. textLayerDiv: textLayerDiv,
  2772. eventBus: this.eventBus,
  2773. pageIndex: pageIndex,
  2774. viewport: viewport,
  2775. findController: this.isInPresentationMode ? null : this.findController,
  2776. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  2777. });
  2778. }
  2779. }, {
  2780. key: 'createAnnotationLayerBuilder',
  2781. value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  2782. var renderInteractiveForms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  2783. var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
  2784. return new _annotation_layer_builder.AnnotationLayerBuilder({
  2785. pageDiv: pageDiv,
  2786. pdfPage: pdfPage,
  2787. renderInteractiveForms: renderInteractiveForms,
  2788. linkService: this.linkService,
  2789. downloadManager: this.downloadManager,
  2790. l10n: l10n
  2791. });
  2792. }
  2793. }, {
  2794. key: 'setFindController',
  2795. value: function setFindController(findController) {
  2796. this.findController = findController;
  2797. }
  2798. }, {
  2799. key: 'getPagesOverview',
  2800. value: function getPagesOverview() {
  2801. var pagesOverview = this._pages.map(function (pageView) {
  2802. var viewport = pageView.pdfPage.getViewport(1);
  2803. return {
  2804. width: viewport.width,
  2805. height: viewport.height,
  2806. rotation: viewport.rotation
  2807. };
  2808. });
  2809. if (!this.enablePrintAutoRotate) {
  2810. return pagesOverview;
  2811. }
  2812. var isFirstPagePortrait = isPortraitOrientation(pagesOverview[0]);
  2813. return pagesOverview.map(function (size) {
  2814. if (isFirstPagePortrait === isPortraitOrientation(size)) {
  2815. return size;
  2816. }
  2817. return {
  2818. width: size.height,
  2819. height: size.width,
  2820. rotation: (size.rotation + 90) % 360
  2821. };
  2822. });
  2823. }
  2824. }, {
  2825. key: 'pagesCount',
  2826. get: function get() {
  2827. return this._pages.length;
  2828. }
  2829. }, {
  2830. key: 'pageViewsReady',
  2831. get: function get() {
  2832. return this._pageViewsReady;
  2833. }
  2834. }, {
  2835. key: 'currentPageNumber',
  2836. get: function get() {
  2837. return this._currentPageNumber;
  2838. },
  2839. set: function set(val) {
  2840. if ((val | 0) !== val) {
  2841. throw new Error('Invalid page number.');
  2842. }
  2843. if (!this.pdfDocument) {
  2844. return;
  2845. }
  2846. this._setCurrentPageNumber(val, true);
  2847. }
  2848. }, {
  2849. key: 'currentPageLabel',
  2850. get: function get() {
  2851. return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
  2852. },
  2853. set: function set(val) {
  2854. var pageNumber = val | 0;
  2855. if (this._pageLabels) {
  2856. var i = this._pageLabels.indexOf(val);
  2857. if (i >= 0) {
  2858. pageNumber = i + 1;
  2859. }
  2860. }
  2861. this.currentPageNumber = pageNumber;
  2862. }
  2863. }, {
  2864. key: 'currentScale',
  2865. get: function get() {
  2866. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  2867. },
  2868. set: function set(val) {
  2869. if (isNaN(val)) {
  2870. throw new Error('Invalid numeric scale');
  2871. }
  2872. if (!this.pdfDocument) {
  2873. return;
  2874. }
  2875. this._setScale(val, false);
  2876. }
  2877. }, {
  2878. key: 'currentScaleValue',
  2879. get: function get() {
  2880. return this._currentScaleValue;
  2881. },
  2882. set: function set(val) {
  2883. if (!this.pdfDocument) {
  2884. return;
  2885. }
  2886. this._setScale(val, false);
  2887. }
  2888. }, {
  2889. key: 'pagesRotation',
  2890. get: function get() {
  2891. return this._pagesRotation;
  2892. },
  2893. set: function set(rotation) {
  2894. if (!(typeof rotation === 'number' && rotation % 90 === 0)) {
  2895. throw new Error('Invalid pages rotation angle.');
  2896. }
  2897. if (!this.pdfDocument) {
  2898. return;
  2899. }
  2900. this._pagesRotation = rotation;
  2901. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  2902. var pageView = this._pages[i];
  2903. pageView.update(pageView.scale, rotation);
  2904. }
  2905. this._setScale(this._currentScaleValue, true);
  2906. if (this.defaultRenderingQueue) {
  2907. this.update();
  2908. }
  2909. }
  2910. }, {
  2911. key: 'isInPresentationMode',
  2912. get: function get() {
  2913. return this.presentationModeState === PresentationModeState.FULLSCREEN;
  2914. }
  2915. }, {
  2916. key: 'isChangingPresentationMode',
  2917. get: function get() {
  2918. return this.presentationModeState === PresentationModeState.CHANGING;
  2919. }
  2920. }, {
  2921. key: 'isHorizontalScrollbarEnabled',
  2922. get: function get() {
  2923. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  2924. }
  2925. }, {
  2926. key: 'hasEqualPageSizes',
  2927. get: function get() {
  2928. var firstPageView = this._pages[0];
  2929. for (var i = 1, ii = this._pages.length; i < ii; ++i) {
  2930. var pageView = this._pages[i];
  2931. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  2932. return false;
  2933. }
  2934. }
  2935. return true;
  2936. }
  2937. }]);
  2938. return PDFViewer;
  2939. }();
  2940. exports.PresentationModeState = PresentationModeState;
  2941. exports.PDFViewer = PDFViewer;
  2942. /***/ }),
  2943. /* 10 */
  2944. /***/ (function(module, exports, __w_pdfjs_require__) {
  2945. "use strict";
  2946. Object.defineProperty(exports, "__esModule", {
  2947. value: true
  2948. });
  2949. exports.isDestsEqual = exports.PDFHistory = undefined;
  2950. 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; };
  2951. 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; }; }();
  2952. var _ui_utils = __w_pdfjs_require__(1);
  2953. var _dom_events = __w_pdfjs_require__(2);
  2954. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2955. var HASH_CHANGE_TIMEOUT = 1000;
  2956. var POSITION_UPDATED_THRESHOLD = 50;
  2957. var UPDATE_VIEWAREA_TIMEOUT = 2000;
  2958. function getCurrentHash() {
  2959. return document.location.hash;
  2960. }
  2961. function parseCurrentHash(linkService) {
  2962. var hash = unescape(getCurrentHash()).substring(1);
  2963. var params = (0, _ui_utils.parseQueryString)(hash);
  2964. var page = params.page | 0;
  2965. if (!(Number.isInteger(page) && page > 0 && page <= linkService.pagesCount)) {
  2966. page = null;
  2967. }
  2968. return {
  2969. hash: hash,
  2970. page: page
  2971. };
  2972. }
  2973. var PDFHistory = function () {
  2974. function PDFHistory(_ref) {
  2975. var _this = this;
  2976. var linkService = _ref.linkService,
  2977. eventBus = _ref.eventBus;
  2978. _classCallCheck(this, PDFHistory);
  2979. this.linkService = linkService;
  2980. this.eventBus = eventBus || (0, _dom_events.getGlobalEventBus)();
  2981. this.initialized = false;
  2982. this.initialBookmark = null;
  2983. this._boundEvents = Object.create(null);
  2984. this._isViewerInPresentationMode = false;
  2985. this._isPagesLoaded = false;
  2986. this.eventBus.on('presentationmodechanged', function (evt) {
  2987. _this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
  2988. });
  2989. this.eventBus.on('pagesloaded', function (evt) {
  2990. _this._isPagesLoaded = !!evt.pagesCount;
  2991. });
  2992. }
  2993. _createClass(PDFHistory, [{
  2994. key: 'initialize',
  2995. value: function initialize(fingerprint) {
  2996. var resetHistory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2997. if (!fingerprint || typeof fingerprint !== 'string') {
  2998. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  2999. return;
  3000. }
  3001. var reInitialized = this.initialized && this.fingerprint !== fingerprint;
  3002. this.fingerprint = fingerprint;
  3003. if (!this.initialized) {
  3004. this._bindEvents();
  3005. }
  3006. var state = window.history.state;
  3007. this.initialized = true;
  3008. this.initialBookmark = null;
  3009. this._popStateInProgress = false;
  3010. this._blockHashChange = 0;
  3011. this._currentHash = getCurrentHash();
  3012. this._numPositionUpdates = 0;
  3013. this._currentUid = this._uid = 0;
  3014. this._destination = null;
  3015. this._position = null;
  3016. if (!this._isValidState(state) || resetHistory) {
  3017. var _parseCurrentHash = parseCurrentHash(this.linkService),
  3018. hash = _parseCurrentHash.hash,
  3019. page = _parseCurrentHash.page;
  3020. if (!hash || reInitialized || resetHistory) {
  3021. this._pushOrReplaceState(null, true);
  3022. return;
  3023. }
  3024. this._pushOrReplaceState({
  3025. hash: hash,
  3026. page: page
  3027. }, true);
  3028. return;
  3029. }
  3030. var destination = state.destination;
  3031. this._updateInternalState(destination, state.uid, true);
  3032. if (destination.dest) {
  3033. this.initialBookmark = JSON.stringify(destination.dest);
  3034. this._destination.page = null;
  3035. } else if (destination.hash) {
  3036. this.initialBookmark = destination.hash;
  3037. } else if (destination.page) {
  3038. this.initialBookmark = 'page=' + destination.page;
  3039. }
  3040. }
  3041. }, {
  3042. key: 'push',
  3043. value: function push(_ref2) {
  3044. var namedDest = _ref2.namedDest,
  3045. explicitDest = _ref2.explicitDest,
  3046. pageNumber = _ref2.pageNumber;
  3047. if (!this.initialized) {
  3048. return;
  3049. }
  3050. if (namedDest && typeof namedDest !== 'string' || !(explicitDest instanceof Array) || !(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.linkService.pagesCount)) {
  3051. console.error('PDFHistory.push: Invalid parameters.');
  3052. return;
  3053. }
  3054. var hash = namedDest || JSON.stringify(explicitDest);
  3055. if (!hash) {
  3056. return;
  3057. }
  3058. var forceReplace = false;
  3059. if (this._destination && (this._destination.hash === hash || isDestsEqual(this._destination.dest, explicitDest))) {
  3060. if (this._destination.page) {
  3061. return;
  3062. }
  3063. forceReplace = true;
  3064. }
  3065. if (this._popStateInProgress && !forceReplace) {
  3066. return;
  3067. }
  3068. this._pushOrReplaceState({
  3069. dest: explicitDest,
  3070. hash: hash,
  3071. page: pageNumber
  3072. }, forceReplace);
  3073. }
  3074. }, {
  3075. key: 'pushCurrentPosition',
  3076. value: function pushCurrentPosition() {
  3077. if (!this.initialized || this._popStateInProgress) {
  3078. return;
  3079. }
  3080. this._tryPushCurrentPosition();
  3081. }
  3082. }, {
  3083. key: 'back',
  3084. value: function back() {
  3085. if (!this.initialized || this._popStateInProgress) {
  3086. return;
  3087. }
  3088. var state = window.history.state;
  3089. if (this._isValidState(state) && state.uid > 0) {
  3090. window.history.back();
  3091. }
  3092. }
  3093. }, {
  3094. key: 'forward',
  3095. value: function forward() {
  3096. if (!this.initialized || this._popStateInProgress) {
  3097. return;
  3098. }
  3099. var state = window.history.state;
  3100. if (this._isValidState(state) && state.uid < this._uid - 1) {
  3101. window.history.forward();
  3102. }
  3103. }
  3104. }, {
  3105. key: '_pushOrReplaceState',
  3106. value: function _pushOrReplaceState(destination) {
  3107. var forceReplace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  3108. var shouldReplace = forceReplace || !this._destination;
  3109. var newState = {
  3110. fingerprint: this.fingerprint,
  3111. uid: shouldReplace ? this._currentUid : this._uid,
  3112. destination: destination
  3113. };
  3114. this._updateInternalState(destination, newState.uid);
  3115. if (shouldReplace) {
  3116. window.history.replaceState(newState, '', document.URL);
  3117. } else {
  3118. window.history.pushState(newState, '', document.URL);
  3119. }
  3120. }
  3121. }, {
  3122. key: '_tryPushCurrentPosition',
  3123. value: function _tryPushCurrentPosition() {
  3124. var temporary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  3125. if (!this._position) {
  3126. return;
  3127. }
  3128. var position = this._position;
  3129. if (temporary) {
  3130. position = (0, _ui_utils.cloneObj)(this._position);
  3131. position.temporary = true;
  3132. }
  3133. if (!this._destination) {
  3134. this._pushOrReplaceState(position);
  3135. return;
  3136. }
  3137. if (this._destination.temporary) {
  3138. this._pushOrReplaceState(position, true);
  3139. return;
  3140. }
  3141. if (this._destination.hash === position.hash) {
  3142. return;
  3143. }
  3144. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  3145. return;
  3146. }
  3147. var forceReplace = false;
  3148. if (this._destination.page === position.first || this._destination.page === position.page) {
  3149. if (this._destination.dest || !this._destination.first) {
  3150. return;
  3151. }
  3152. forceReplace = true;
  3153. }
  3154. this._pushOrReplaceState(position, forceReplace);
  3155. }
  3156. }, {
  3157. key: '_isValidState',
  3158. value: function _isValidState(state) {
  3159. if (!state) {
  3160. return false;
  3161. }
  3162. if (state.fingerprint !== this.fingerprint) {
  3163. return false;
  3164. }
  3165. if (!Number.isInteger(state.uid) || state.uid < 0) {
  3166. return false;
  3167. }
  3168. if (state.destination === null || _typeof(state.destination) !== 'object') {
  3169. return false;
  3170. }
  3171. return true;
  3172. }
  3173. }, {
  3174. key: '_updateInternalState',
  3175. value: function _updateInternalState(destination, uid) {
  3176. var removeTemporary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  3177. if (removeTemporary && destination && destination.temporary) {
  3178. delete destination.temporary;
  3179. }
  3180. this._destination = destination;
  3181. this._currentUid = uid;
  3182. this._uid = this._currentUid + 1;
  3183. this._numPositionUpdates = 0;
  3184. }
  3185. }, {
  3186. key: '_updateViewarea',
  3187. value: function _updateViewarea(_ref3) {
  3188. var _this2 = this;
  3189. var location = _ref3.location;
  3190. if (this._updateViewareaTimeout) {
  3191. clearTimeout(this._updateViewareaTimeout);
  3192. this._updateViewareaTimeout = null;
  3193. }
  3194. this._position = {
  3195. hash: this._isViewerInPresentationMode ? 'page=' + location.pageNumber : location.pdfOpenParams.substring(1),
  3196. page: this.linkService.page,
  3197. first: location.pageNumber
  3198. };
  3199. if (this._popStateInProgress) {
  3200. return;
  3201. }
  3202. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  3203. this._numPositionUpdates++;
  3204. }
  3205. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  3206. this._updateViewareaTimeout = setTimeout(function () {
  3207. if (!_this2._popStateInProgress) {
  3208. _this2._tryPushCurrentPosition(true);
  3209. }
  3210. _this2._updateViewareaTimeout = null;
  3211. }, UPDATE_VIEWAREA_TIMEOUT);
  3212. }
  3213. }
  3214. }, {
  3215. key: '_popState',
  3216. value: function _popState(_ref4) {
  3217. var _this3 = this;
  3218. var state = _ref4.state;
  3219. var newHash = getCurrentHash(),
  3220. hashChanged = this._currentHash !== newHash;
  3221. this._currentHash = newHash;
  3222. if (!state || false) {
  3223. this._currentUid = this._uid;
  3224. var _parseCurrentHash2 = parseCurrentHash(this.linkService),
  3225. hash = _parseCurrentHash2.hash,
  3226. page = _parseCurrentHash2.page;
  3227. this._pushOrReplaceState({
  3228. hash: hash,
  3229. page: page
  3230. }, true);
  3231. return;
  3232. }
  3233. if (!this._isValidState(state)) {
  3234. return;
  3235. }
  3236. this._popStateInProgress = true;
  3237. if (hashChanged) {
  3238. this._blockHashChange++;
  3239. (0, _ui_utils.waitOnEventOrTimeout)({
  3240. target: window,
  3241. name: 'hashchange',
  3242. delay: HASH_CHANGE_TIMEOUT
  3243. }).then(function () {
  3244. _this3._blockHashChange--;
  3245. });
  3246. }
  3247. if (state.uid < this._currentUid && this._position && this._destination) {
  3248. var shouldGoBack = false;
  3249. if (this._destination.temporary) {
  3250. this._pushOrReplaceState(this._position);
  3251. shouldGoBack = true;
  3252. } else if (this._destination.page && this._destination.page !== this._position.first && this._destination.page !== this._position.page) {
  3253. this._pushOrReplaceState(this._destination);
  3254. this._pushOrReplaceState(this._position);
  3255. shouldGoBack = true;
  3256. }
  3257. if (shouldGoBack) {
  3258. this._currentUid = state.uid;
  3259. window.history.back();
  3260. return;
  3261. }
  3262. }
  3263. var destination = state.destination;
  3264. this._updateInternalState(destination, state.uid, true);
  3265. if (destination.dest) {
  3266. this.linkService.navigateTo(destination.dest);
  3267. } else if (destination.hash) {
  3268. this.linkService.setHash(destination.hash);
  3269. } else if (destination.page) {
  3270. this.linkService.page = destination.page;
  3271. }
  3272. Promise.resolve().then(function () {
  3273. _this3._popStateInProgress = false;
  3274. });
  3275. }
  3276. }, {
  3277. key: '_bindEvents',
  3278. value: function _bindEvents() {
  3279. var _this4 = this;
  3280. var _boundEvents = this._boundEvents,
  3281. eventBus = this.eventBus;
  3282. _boundEvents.updateViewarea = this._updateViewarea.bind(this);
  3283. _boundEvents.popState = this._popState.bind(this);
  3284. _boundEvents.pageHide = function (evt) {
  3285. if (!_this4._destination) {
  3286. _this4._tryPushCurrentPosition();
  3287. }
  3288. };
  3289. eventBus.on('updateviewarea', _boundEvents.updateViewarea);
  3290. window.addEventListener('popstate', _boundEvents.popState);
  3291. window.addEventListener('pagehide', _boundEvents.pageHide);
  3292. }
  3293. }, {
  3294. key: 'popStateInProgress',
  3295. get: function get() {
  3296. return this.initialized && (this._popStateInProgress || this._blockHashChange > 0);
  3297. }
  3298. }]);
  3299. return PDFHistory;
  3300. }();
  3301. function isDestsEqual(firstDest, secondDest) {
  3302. function isEntryEqual(first, second) {
  3303. if ((typeof first === 'undefined' ? 'undefined' : _typeof(first)) !== (typeof second === 'undefined' ? 'undefined' : _typeof(second))) {
  3304. return false;
  3305. }
  3306. if (first instanceof Array || second instanceof Array) {
  3307. return false;
  3308. }
  3309. if (first !== null && (typeof first === 'undefined' ? 'undefined' : _typeof(first)) === 'object' && second !== null) {
  3310. if (Object.keys(first).length !== Object.keys(second).length) {
  3311. return false;
  3312. }
  3313. for (var key in first) {
  3314. if (!isEntryEqual(first[key], second[key])) {
  3315. return false;
  3316. }
  3317. }
  3318. return true;
  3319. }
  3320. return first === second || Number.isNaN(first) && Number.isNaN(second);
  3321. }
  3322. if (!(firstDest instanceof Array && secondDest instanceof Array)) {
  3323. return false;
  3324. }
  3325. if (firstDest.length !== secondDest.length) {
  3326. return false;
  3327. }
  3328. for (var i = 0, ii = firstDest.length; i < ii; i++) {
  3329. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  3330. return false;
  3331. }
  3332. }
  3333. return true;
  3334. }
  3335. exports.PDFHistory = PDFHistory;
  3336. exports.isDestsEqual = isDestsEqual;
  3337. /***/ }),
  3338. /* 11 */
  3339. /***/ (function(module, exports, __w_pdfjs_require__) {
  3340. "use strict";
  3341. Object.defineProperty(exports, "__esModule", {
  3342. value: true
  3343. });
  3344. exports.PDFFindController = exports.FindState = undefined;
  3345. 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; }; }();
  3346. var _pdfjsLib = __w_pdfjs_require__(0);
  3347. var _ui_utils = __w_pdfjs_require__(1);
  3348. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3349. var FindState = {
  3350. FOUND: 0,
  3351. NOT_FOUND: 1,
  3352. WRAPPED: 2,
  3353. PENDING: 3
  3354. };
  3355. var FIND_SCROLL_OFFSET_TOP = -50;
  3356. var FIND_SCROLL_OFFSET_LEFT = -400;
  3357. var FIND_TIMEOUT = 250;
  3358. var CHARACTERS_TO_NORMALIZE = {
  3359. '\u2018': '\'',
  3360. '\u2019': '\'',
  3361. '\u201A': '\'',
  3362. '\u201B': '\'',
  3363. '\u201C': '"',
  3364. '\u201D': '"',
  3365. '\u201E': '"',
  3366. '\u201F': '"',
  3367. '\xBC': '1/4',
  3368. '\xBD': '1/2',
  3369. '\xBE': '3/4'
  3370. };
  3371. var PDFFindController = function () {
  3372. function PDFFindController(_ref) {
  3373. var pdfViewer = _ref.pdfViewer;
  3374. _classCallCheck(this, PDFFindController);
  3375. this.pdfViewer = pdfViewer;
  3376. this.onUpdateResultsCount = null;
  3377. this.onUpdateState = null;
  3378. this.reset();
  3379. var replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
  3380. this.normalizationRegex = new RegExp('[' + replace + ']', 'g');
  3381. }
  3382. _createClass(PDFFindController, [{
  3383. key: 'reset',
  3384. value: function reset() {
  3385. var _this = this;
  3386. this.startedTextExtraction = false;
  3387. this.extractTextPromises = [];
  3388. this.pendingFindMatches = Object.create(null);
  3389. this.active = false;
  3390. this.pageContents = [];
  3391. this.pageMatches = [];
  3392. this.pageMatchesLength = null;
  3393. this.matchCount = 0;
  3394. this.selected = {
  3395. pageIdx: -1,
  3396. matchIdx: -1
  3397. };
  3398. this.offset = {
  3399. pageIdx: null,
  3400. matchIdx: null
  3401. };
  3402. this.pagesToSearch = null;
  3403. this.resumePageIdx = null;
  3404. this.state = null;
  3405. this.dirtyMatch = false;
  3406. this.findTimeout = null;
  3407. this._firstPagePromise = new Promise(function (resolve) {
  3408. _this.resolveFirstPage = resolve;
  3409. });
  3410. }
  3411. }, {
  3412. key: 'normalize',
  3413. value: function normalize(text) {
  3414. return text.replace(this.normalizationRegex, function (ch) {
  3415. return CHARACTERS_TO_NORMALIZE[ch];
  3416. });
  3417. }
  3418. }, {
  3419. key: '_prepareMatches',
  3420. value: function _prepareMatches(matchesWithLength, matches, matchesLength) {
  3421. function isSubTerm(matchesWithLength, currentIndex) {
  3422. var currentElem = matchesWithLength[currentIndex];
  3423. var nextElem = matchesWithLength[currentIndex + 1];
  3424. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  3425. currentElem.skipped = true;
  3426. return true;
  3427. }
  3428. for (var i = currentIndex - 1; i >= 0; i--) {
  3429. var prevElem = matchesWithLength[i];
  3430. if (prevElem.skipped) {
  3431. continue;
  3432. }
  3433. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  3434. break;
  3435. }
  3436. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  3437. currentElem.skipped = true;
  3438. return true;
  3439. }
  3440. }
  3441. return false;
  3442. }
  3443. matchesWithLength.sort(function (a, b) {
  3444. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  3445. });
  3446. for (var i = 0, len = matchesWithLength.length; i < len; i++) {
  3447. if (isSubTerm(matchesWithLength, i)) {
  3448. continue;
  3449. }
  3450. matches.push(matchesWithLength[i].match);
  3451. matchesLength.push(matchesWithLength[i].matchLength);
  3452. }
  3453. }
  3454. }, {
  3455. key: 'calcFindPhraseMatch',
  3456. value: function calcFindPhraseMatch(query, pageIndex, pageContent) {
  3457. var matches = [];
  3458. var queryLen = query.length;
  3459. var matchIdx = -queryLen;
  3460. while (true) {
  3461. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  3462. if (matchIdx === -1) {
  3463. break;
  3464. }
  3465. matches.push(matchIdx);
  3466. }
  3467. this.pageMatches[pageIndex] = matches;
  3468. }
  3469. }, {
  3470. key: 'calcFindWordMatch',
  3471. value: function calcFindWordMatch(query, pageIndex, pageContent) {
  3472. var matchesWithLength = [];
  3473. var queryArray = query.match(/\S+/g);
  3474. for (var i = 0, len = queryArray.length; i < len; i++) {
  3475. var subquery = queryArray[i];
  3476. var subqueryLen = subquery.length;
  3477. var matchIdx = -subqueryLen;
  3478. while (true) {
  3479. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  3480. if (matchIdx === -1) {
  3481. break;
  3482. }
  3483. matchesWithLength.push({
  3484. match: matchIdx,
  3485. matchLength: subqueryLen,
  3486. skipped: false
  3487. });
  3488. }
  3489. }
  3490. if (!this.pageMatchesLength) {
  3491. this.pageMatchesLength = [];
  3492. }
  3493. this.pageMatchesLength[pageIndex] = [];
  3494. this.pageMatches[pageIndex] = [];
  3495. this._prepareMatches(matchesWithLength, this.pageMatches[pageIndex], this.pageMatchesLength[pageIndex]);
  3496. }
  3497. }, {
  3498. key: 'calcFindMatch',
  3499. value: function calcFindMatch(pageIndex) {
  3500. var pageContent = this.normalize(this.pageContents[pageIndex]);
  3501. var query = this.normalize(this.state.query);
  3502. var caseSensitive = this.state.caseSensitive;
  3503. var phraseSearch = this.state.phraseSearch;
  3504. var queryLen = query.length;
  3505. if (queryLen === 0) {
  3506. return;
  3507. }
  3508. if (!caseSensitive) {
  3509. pageContent = pageContent.toLowerCase();
  3510. query = query.toLowerCase();
  3511. }
  3512. if (phraseSearch) {
  3513. this.calcFindPhraseMatch(query, pageIndex, pageContent);
  3514. } else {
  3515. this.calcFindWordMatch(query, pageIndex, pageContent);
  3516. }
  3517. this.updatePage(pageIndex);
  3518. if (this.resumePageIdx === pageIndex) {
  3519. this.resumePageIdx = null;
  3520. this.nextPageMatch();
  3521. }
  3522. if (this.pageMatches[pageIndex].length > 0) {
  3523. this.matchCount += this.pageMatches[pageIndex].length;
  3524. this.updateUIResultsCount();
  3525. }
  3526. }
  3527. }, {
  3528. key: 'extractText',
  3529. value: function extractText() {
  3530. var _this2 = this;
  3531. if (this.startedTextExtraction) {
  3532. return;
  3533. }
  3534. this.startedTextExtraction = true;
  3535. this.pageContents.length = 0;
  3536. var promise = Promise.resolve();
  3537. var _loop = function _loop(i, ii) {
  3538. var extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  3539. _this2.extractTextPromises[i] = extractTextCapability.promise;
  3540. promise = promise.then(function () {
  3541. return _this2.pdfViewer.getPageTextContent(i).then(function (textContent) {
  3542. var textItems = textContent.items;
  3543. var strBuf = [];
  3544. for (var j = 0, jj = textItems.length; j < jj; j++) {
  3545. strBuf.push(textItems[j].str);
  3546. }
  3547. _this2.pageContents[i] = strBuf.join('');
  3548. extractTextCapability.resolve(i);
  3549. }, function (reason) {
  3550. console.error('Unable to get page ' + (i + 1) + ' text content', reason);
  3551. _this2.pageContents[i] = '';
  3552. extractTextCapability.resolve(i);
  3553. });
  3554. });
  3555. };
  3556. for (var i = 0, ii = this.pdfViewer.pagesCount; i < ii; i++) {
  3557. _loop(i, ii);
  3558. }
  3559. }
  3560. }, {
  3561. key: 'executeCommand',
  3562. value: function executeCommand(cmd, state) {
  3563. var _this3 = this;
  3564. if (this.state === null || cmd !== 'findagain') {
  3565. this.dirtyMatch = true;
  3566. }
  3567. this.state = state;
  3568. this.updateUIState(FindState.PENDING);
  3569. this._firstPagePromise.then(function () {
  3570. _this3.extractText();
  3571. clearTimeout(_this3.findTimeout);
  3572. if (cmd === 'find') {
  3573. _this3.findTimeout = setTimeout(_this3.nextMatch.bind(_this3), FIND_TIMEOUT);
  3574. } else {
  3575. _this3.nextMatch();
  3576. }
  3577. });
  3578. }
  3579. }, {
  3580. key: 'updatePage',
  3581. value: function updatePage(index) {
  3582. if (this.selected.pageIdx === index) {
  3583. this.pdfViewer.currentPageNumber = index + 1;
  3584. }
  3585. var page = this.pdfViewer.getPageView(index);
  3586. if (page.textLayer) {
  3587. page.textLayer.updateMatches();
  3588. }
  3589. }
  3590. }, {
  3591. key: 'nextMatch',
  3592. value: function nextMatch() {
  3593. var _this4 = this;
  3594. var previous = this.state.findPrevious;
  3595. var currentPageIndex = this.pdfViewer.currentPageNumber - 1;
  3596. var numPages = this.pdfViewer.pagesCount;
  3597. this.active = true;
  3598. if (this.dirtyMatch) {
  3599. this.dirtyMatch = false;
  3600. this.selected.pageIdx = this.selected.matchIdx = -1;
  3601. this.offset.pageIdx = currentPageIndex;
  3602. this.offset.matchIdx = null;
  3603. this.hadMatch = false;
  3604. this.resumePageIdx = null;
  3605. this.pageMatches = [];
  3606. this.matchCount = 0;
  3607. this.pageMatchesLength = null;
  3608. for (var i = 0; i < numPages; i++) {
  3609. this.updatePage(i);
  3610. if (!(i in this.pendingFindMatches)) {
  3611. this.pendingFindMatches[i] = true;
  3612. this.extractTextPromises[i].then(function (pageIdx) {
  3613. delete _this4.pendingFindMatches[pageIdx];
  3614. _this4.calcFindMatch(pageIdx);
  3615. });
  3616. }
  3617. }
  3618. }
  3619. if (this.state.query === '') {
  3620. this.updateUIState(FindState.FOUND);
  3621. return;
  3622. }
  3623. if (this.resumePageIdx) {
  3624. return;
  3625. }
  3626. var offset = this.offset;
  3627. this.pagesToSearch = numPages;
  3628. if (offset.matchIdx !== null) {
  3629. var numPageMatches = this.pageMatches[offset.pageIdx].length;
  3630. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  3631. this.hadMatch = true;
  3632. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  3633. this.updateMatch(true);
  3634. return;
  3635. }
  3636. this.advanceOffsetPage(previous);
  3637. }
  3638. this.nextPageMatch();
  3639. }
  3640. }, {
  3641. key: 'matchesReady',
  3642. value: function matchesReady(matches) {
  3643. var offset = this.offset;
  3644. var numMatches = matches.length;
  3645. var previous = this.state.findPrevious;
  3646. if (numMatches) {
  3647. this.hadMatch = true;
  3648. offset.matchIdx = previous ? numMatches - 1 : 0;
  3649. this.updateMatch(true);
  3650. return true;
  3651. }
  3652. this.advanceOffsetPage(previous);
  3653. if (offset.wrapped) {
  3654. offset.matchIdx = null;
  3655. if (this.pagesToSearch < 0) {
  3656. this.updateMatch(false);
  3657. return true;
  3658. }
  3659. }
  3660. return false;
  3661. }
  3662. }, {
  3663. key: 'updateMatchPosition',
  3664. value: function updateMatchPosition(pageIndex, matchIndex, elements, beginIdx) {
  3665. if (this.selected.matchIdx === matchIndex && this.selected.pageIdx === pageIndex) {
  3666. var spot = {
  3667. top: FIND_SCROLL_OFFSET_TOP,
  3668. left: FIND_SCROLL_OFFSET_LEFT
  3669. };
  3670. (0, _ui_utils.scrollIntoView)(elements[beginIdx], spot, true);
  3671. }
  3672. }
  3673. }, {
  3674. key: 'nextPageMatch',
  3675. value: function nextPageMatch() {
  3676. if (this.resumePageIdx !== null) {
  3677. console.error('There can only be one pending page.');
  3678. }
  3679. var matches = null;
  3680. do {
  3681. var pageIdx = this.offset.pageIdx;
  3682. matches = this.pageMatches[pageIdx];
  3683. if (!matches) {
  3684. this.resumePageIdx = pageIdx;
  3685. break;
  3686. }
  3687. } while (!this.matchesReady(matches));
  3688. }
  3689. }, {
  3690. key: 'advanceOffsetPage',
  3691. value: function advanceOffsetPage(previous) {
  3692. var offset = this.offset;
  3693. var numPages = this.extractTextPromises.length;
  3694. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  3695. offset.matchIdx = null;
  3696. this.pagesToSearch--;
  3697. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  3698. offset.pageIdx = previous ? numPages - 1 : 0;
  3699. offset.wrapped = true;
  3700. }
  3701. }
  3702. }, {
  3703. key: 'updateMatch',
  3704. value: function updateMatch() {
  3705. var found = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  3706. var state = FindState.NOT_FOUND;
  3707. var wrapped = this.offset.wrapped;
  3708. this.offset.wrapped = false;
  3709. if (found) {
  3710. var previousPage = this.selected.pageIdx;
  3711. this.selected.pageIdx = this.offset.pageIdx;
  3712. this.selected.matchIdx = this.offset.matchIdx;
  3713. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  3714. if (previousPage !== -1 && previousPage !== this.selected.pageIdx) {
  3715. this.updatePage(previousPage);
  3716. }
  3717. }
  3718. this.updateUIState(state, this.state.findPrevious);
  3719. if (this.selected.pageIdx !== -1) {
  3720. this.updatePage(this.selected.pageIdx);
  3721. }
  3722. }
  3723. }, {
  3724. key: 'updateUIResultsCount',
  3725. value: function updateUIResultsCount() {
  3726. if (this.onUpdateResultsCount) {
  3727. this.onUpdateResultsCount(this.matchCount);
  3728. }
  3729. }
  3730. }, {
  3731. key: 'updateUIState',
  3732. value: function updateUIState(state, previous) {
  3733. if (this.onUpdateState) {
  3734. this.onUpdateState(state, previous, this.matchCount);
  3735. }
  3736. }
  3737. }]);
  3738. return PDFFindController;
  3739. }();
  3740. exports.FindState = FindState;
  3741. exports.PDFFindController = PDFFindController;
  3742. /***/ }),
  3743. /* 12 */
  3744. /***/ (function(module, exports, __w_pdfjs_require__) {
  3745. "use strict";
  3746. Object.defineProperty(exports, "__esModule", {
  3747. value: true
  3748. });
  3749. exports.DownloadManager = undefined;
  3750. 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; }; }();
  3751. var _pdfjsLib = __w_pdfjs_require__(0);
  3752. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3753. ;
  3754. function _download(blobUrl, filename) {
  3755. var a = document.createElement('a');
  3756. if (a.click) {
  3757. a.href = blobUrl;
  3758. a.target = '_parent';
  3759. if ('download' in a) {
  3760. a.download = filename;
  3761. }
  3762. (document.body || document.documentElement).appendChild(a);
  3763. a.click();
  3764. a.parentNode.removeChild(a);
  3765. } else {
  3766. if (window.top === window && blobUrl.split('#')[0] === window.location.href.split('#')[0]) {
  3767. var padCharacter = blobUrl.indexOf('?') === -1 ? '?' : '&';
  3768. blobUrl = blobUrl.replace(/#|$/, padCharacter + '$&');
  3769. }
  3770. window.open(blobUrl, '_parent');
  3771. }
  3772. }
  3773. var DownloadManager = function () {
  3774. function DownloadManager() {
  3775. _classCallCheck(this, DownloadManager);
  3776. }
  3777. _createClass(DownloadManager, [{
  3778. key: 'downloadUrl',
  3779. value: function downloadUrl(url, filename) {
  3780. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, 'http://example.com')) {
  3781. return;
  3782. }
  3783. _download(url + '#pdfjs.action=download', filename);
  3784. }
  3785. }, {
  3786. key: 'downloadData',
  3787. value: function downloadData(data, filename, contentType) {
  3788. if (navigator.msSaveBlob) {
  3789. return navigator.msSaveBlob(new Blob([data], { type: contentType }), filename);
  3790. }
  3791. var blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, _pdfjsLib.PDFJS.disableCreateObjectURL);
  3792. _download(blobUrl, filename);
  3793. }
  3794. }, {
  3795. key: 'download',
  3796. value: function download(blob, url, filename) {
  3797. if (navigator.msSaveBlob) {
  3798. if (!navigator.msSaveBlob(blob, filename)) {
  3799. this.downloadUrl(url, filename);
  3800. }
  3801. return;
  3802. }
  3803. if (_pdfjsLib.PDFJS.disableCreateObjectURL) {
  3804. this.downloadUrl(url, filename);
  3805. return;
  3806. }
  3807. var blobUrl = URL.createObjectURL(blob);
  3808. _download(blobUrl, filename);
  3809. }
  3810. }]);
  3811. return DownloadManager;
  3812. }();
  3813. exports.DownloadManager = DownloadManager;
  3814. /***/ }),
  3815. /* 13 */
  3816. /***/ (function(module, exports, __w_pdfjs_require__) {
  3817. "use strict";
  3818. Object.defineProperty(exports, "__esModule", {
  3819. value: true
  3820. });
  3821. exports.GenericL10n = undefined;
  3822. 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; }; }();
  3823. __w_pdfjs_require__(14);
  3824. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3825. var webL10n = document.webL10n;
  3826. var GenericL10n = function () {
  3827. function GenericL10n(lang) {
  3828. _classCallCheck(this, GenericL10n);
  3829. this._lang = lang;
  3830. this._ready = new Promise(function (resolve, reject) {
  3831. webL10n.setLanguage(lang, function () {
  3832. resolve(webL10n);
  3833. });
  3834. });
  3835. }
  3836. _createClass(GenericL10n, [{
  3837. key: 'getDirection',
  3838. value: function getDirection() {
  3839. return this._ready.then(function (l10n) {
  3840. return l10n.getDirection();
  3841. });
  3842. }
  3843. }, {
  3844. key: 'get',
  3845. value: function get(property, args, fallback) {
  3846. return this._ready.then(function (l10n) {
  3847. return l10n.get(property, args, fallback);
  3848. });
  3849. }
  3850. }, {
  3851. key: 'translate',
  3852. value: function translate(element) {
  3853. return this._ready.then(function (l10n) {
  3854. return l10n.translate(element);
  3855. });
  3856. }
  3857. }]);
  3858. return GenericL10n;
  3859. }();
  3860. exports.GenericL10n = GenericL10n;
  3861. /***/ }),
  3862. /* 14 */
  3863. /***/ (function(module, exports, __w_pdfjs_require__) {
  3864. "use strict";
  3865. document.webL10n = function (window, document, undefined) {
  3866. var gL10nData = {};
  3867. var gTextData = '';
  3868. var gTextProp = 'textContent';
  3869. var gLanguage = '';
  3870. var gMacros = {};
  3871. var gReadyState = 'loading';
  3872. var gAsyncResourceLoading = true;
  3873. function getL10nResourceLinks() {
  3874. return document.querySelectorAll('link[type="application/l10n"]');
  3875. }
  3876. function getL10nDictionary() {
  3877. var script = document.querySelector('script[type="application/l10n"]');
  3878. return script ? JSON.parse(script.innerHTML) : null;
  3879. }
  3880. function getTranslatableChildren(element) {
  3881. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  3882. }
  3883. function getL10nAttributes(element) {
  3884. if (!element) return {};
  3885. var l10nId = element.getAttribute('data-l10n-id');
  3886. var l10nArgs = element.getAttribute('data-l10n-args');
  3887. var args = {};
  3888. if (l10nArgs) {
  3889. try {
  3890. args = JSON.parse(l10nArgs);
  3891. } catch (e) {
  3892. console.warn('could not parse arguments for #' + l10nId);
  3893. }
  3894. }
  3895. return {
  3896. id: l10nId,
  3897. args: args
  3898. };
  3899. }
  3900. function fireL10nReadyEvent(lang) {
  3901. var evtObject = document.createEvent('Event');
  3902. evtObject.initEvent('localized', true, false);
  3903. evtObject.language = lang;
  3904. document.dispatchEvent(evtObject);
  3905. }
  3906. function xhrLoadText(url, onSuccess, onFailure) {
  3907. onSuccess = onSuccess || function _onSuccess(data) {};
  3908. onFailure = onFailure || function _onFailure() {};
  3909. var xhr = new XMLHttpRequest();
  3910. xhr.open('GET', url, gAsyncResourceLoading);
  3911. if (xhr.overrideMimeType) {
  3912. xhr.overrideMimeType('text/plain; charset=utf-8');
  3913. }
  3914. xhr.onreadystatechange = function () {
  3915. if (xhr.readyState == 4) {
  3916. if (xhr.status == 200 || xhr.status === 0) {
  3917. onSuccess(xhr.responseText);
  3918. } else {
  3919. onFailure();
  3920. }
  3921. }
  3922. };
  3923. xhr.onerror = onFailure;
  3924. xhr.ontimeout = onFailure;
  3925. try {
  3926. xhr.send(null);
  3927. } catch (e) {
  3928. onFailure();
  3929. }
  3930. }
  3931. function parseResource(href, lang, successCallback, failureCallback) {
  3932. var baseURL = href.replace(/[^\/]*$/, '') || './';
  3933. function evalString(text) {
  3934. if (text.lastIndexOf('\\') < 0) return text;
  3935. return text.replace(/\\\\/g, '\\').replace(/\\n/g, '\n').replace(/\\r/g, '\r').replace(/\\t/g, '\t').replace(/\\b/g, '\b').replace(/\\f/g, '\f').replace(/\\{/g, '{').replace(/\\}/g, '}').replace(/\\"/g, '"').replace(/\\'/g, "'");
  3936. }
  3937. function parseProperties(text, parsedPropertiesCallback) {
  3938. var dictionary = {};
  3939. var reBlank = /^\s*|\s*$/;
  3940. var reComment = /^\s*#|^\s*$/;
  3941. var reSection = /^\s*\[(.*)\]\s*$/;
  3942. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  3943. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  3944. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  3945. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  3946. var currentLang = '*';
  3947. var genericLang = lang.split('-', 1)[0];
  3948. var skipLang = false;
  3949. var match = '';
  3950. function nextEntry() {
  3951. while (true) {
  3952. if (!entries.length) {
  3953. parsedRawLinesCallback();
  3954. return;
  3955. }
  3956. var line = entries.shift();
  3957. if (reComment.test(line)) continue;
  3958. if (extendedSyntax) {
  3959. match = reSection.exec(line);
  3960. if (match) {
  3961. currentLang = match[1].toLowerCase();
  3962. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  3963. continue;
  3964. } else if (skipLang) {
  3965. continue;
  3966. }
  3967. match = reImport.exec(line);
  3968. if (match) {
  3969. loadImport(baseURL + match[1], nextEntry);
  3970. return;
  3971. }
  3972. }
  3973. var tmp = line.match(reSplit);
  3974. if (tmp && tmp.length == 3) {
  3975. dictionary[tmp[1]] = evalString(tmp[2]);
  3976. }
  3977. }
  3978. }
  3979. nextEntry();
  3980. }
  3981. function loadImport(url, callback) {
  3982. xhrLoadText(url, function (content) {
  3983. parseRawLines(content, false, callback);
  3984. }, function () {
  3985. console.warn(url + ' not found.');
  3986. callback();
  3987. });
  3988. }
  3989. parseRawLines(text, true, function () {
  3990. parsedPropertiesCallback(dictionary);
  3991. });
  3992. }
  3993. xhrLoadText(href, function (response) {
  3994. gTextData += response;
  3995. parseProperties(response, function (data) {
  3996. for (var key in data) {
  3997. var id,
  3998. prop,
  3999. index = key.lastIndexOf('.');
  4000. if (index > 0) {
  4001. id = key.substring(0, index);
  4002. prop = key.substr(index + 1);
  4003. } else {
  4004. id = key;
  4005. prop = gTextProp;
  4006. }
  4007. if (!gL10nData[id]) {
  4008. gL10nData[id] = {};
  4009. }
  4010. gL10nData[id][prop] = data[key];
  4011. }
  4012. if (successCallback) {
  4013. successCallback();
  4014. }
  4015. });
  4016. }, failureCallback);
  4017. }
  4018. function loadLocale(lang, callback) {
  4019. if (lang) {
  4020. lang = lang.toLowerCase();
  4021. }
  4022. callback = callback || function _callback() {};
  4023. clear();
  4024. gLanguage = lang;
  4025. var langLinks = getL10nResourceLinks();
  4026. var langCount = langLinks.length;
  4027. if (langCount === 0) {
  4028. var dict = getL10nDictionary();
  4029. if (dict && dict.locales && dict.default_locale) {
  4030. console.log('using the embedded JSON directory, early way out');
  4031. gL10nData = dict.locales[lang];
  4032. if (!gL10nData) {
  4033. var defaultLocale = dict.default_locale.toLowerCase();
  4034. for (var anyCaseLang in dict.locales) {
  4035. anyCaseLang = anyCaseLang.toLowerCase();
  4036. if (anyCaseLang === lang) {
  4037. gL10nData = dict.locales[lang];
  4038. break;
  4039. } else if (anyCaseLang === defaultLocale) {
  4040. gL10nData = dict.locales[defaultLocale];
  4041. }
  4042. }
  4043. }
  4044. callback();
  4045. } else {
  4046. console.log('no resource to load, early way out');
  4047. }
  4048. fireL10nReadyEvent(lang);
  4049. gReadyState = 'complete';
  4050. return;
  4051. }
  4052. var onResourceLoaded = null;
  4053. var gResourceCount = 0;
  4054. onResourceLoaded = function onResourceLoaded() {
  4055. gResourceCount++;
  4056. if (gResourceCount >= langCount) {
  4057. callback();
  4058. fireL10nReadyEvent(lang);
  4059. gReadyState = 'complete';
  4060. }
  4061. };
  4062. function L10nResourceLink(link) {
  4063. var href = link.href;
  4064. this.load = function (lang, callback) {
  4065. parseResource(href, lang, callback, function () {
  4066. console.warn(href + ' not found.');
  4067. console.warn('"' + lang + '" resource not found');
  4068. gLanguage = '';
  4069. callback();
  4070. });
  4071. };
  4072. }
  4073. for (var i = 0; i < langCount; i++) {
  4074. var resource = new L10nResourceLink(langLinks[i]);
  4075. resource.load(lang, onResourceLoaded);
  4076. }
  4077. }
  4078. function clear() {
  4079. gL10nData = {};
  4080. gTextData = '';
  4081. gLanguage = '';
  4082. }
  4083. function getPluralRules(lang) {
  4084. var locales2rules = {
  4085. 'af': 3,
  4086. 'ak': 4,
  4087. 'am': 4,
  4088. 'ar': 1,
  4089. 'asa': 3,
  4090. 'az': 0,
  4091. 'be': 11,
  4092. 'bem': 3,
  4093. 'bez': 3,
  4094. 'bg': 3,
  4095. 'bh': 4,
  4096. 'bm': 0,
  4097. 'bn': 3,
  4098. 'bo': 0,
  4099. 'br': 20,
  4100. 'brx': 3,
  4101. 'bs': 11,
  4102. 'ca': 3,
  4103. 'cgg': 3,
  4104. 'chr': 3,
  4105. 'cs': 12,
  4106. 'cy': 17,
  4107. 'da': 3,
  4108. 'de': 3,
  4109. 'dv': 3,
  4110. 'dz': 0,
  4111. 'ee': 3,
  4112. 'el': 3,
  4113. 'en': 3,
  4114. 'eo': 3,
  4115. 'es': 3,
  4116. 'et': 3,
  4117. 'eu': 3,
  4118. 'fa': 0,
  4119. 'ff': 5,
  4120. 'fi': 3,
  4121. 'fil': 4,
  4122. 'fo': 3,
  4123. 'fr': 5,
  4124. 'fur': 3,
  4125. 'fy': 3,
  4126. 'ga': 8,
  4127. 'gd': 24,
  4128. 'gl': 3,
  4129. 'gsw': 3,
  4130. 'gu': 3,
  4131. 'guw': 4,
  4132. 'gv': 23,
  4133. 'ha': 3,
  4134. 'haw': 3,
  4135. 'he': 2,
  4136. 'hi': 4,
  4137. 'hr': 11,
  4138. 'hu': 0,
  4139. 'id': 0,
  4140. 'ig': 0,
  4141. 'ii': 0,
  4142. 'is': 3,
  4143. 'it': 3,
  4144. 'iu': 7,
  4145. 'ja': 0,
  4146. 'jmc': 3,
  4147. 'jv': 0,
  4148. 'ka': 0,
  4149. 'kab': 5,
  4150. 'kaj': 3,
  4151. 'kcg': 3,
  4152. 'kde': 0,
  4153. 'kea': 0,
  4154. 'kk': 3,
  4155. 'kl': 3,
  4156. 'km': 0,
  4157. 'kn': 0,
  4158. 'ko': 0,
  4159. 'ksb': 3,
  4160. 'ksh': 21,
  4161. 'ku': 3,
  4162. 'kw': 7,
  4163. 'lag': 18,
  4164. 'lb': 3,
  4165. 'lg': 3,
  4166. 'ln': 4,
  4167. 'lo': 0,
  4168. 'lt': 10,
  4169. 'lv': 6,
  4170. 'mas': 3,
  4171. 'mg': 4,
  4172. 'mk': 16,
  4173. 'ml': 3,
  4174. 'mn': 3,
  4175. 'mo': 9,
  4176. 'mr': 3,
  4177. 'ms': 0,
  4178. 'mt': 15,
  4179. 'my': 0,
  4180. 'nah': 3,
  4181. 'naq': 7,
  4182. 'nb': 3,
  4183. 'nd': 3,
  4184. 'ne': 3,
  4185. 'nl': 3,
  4186. 'nn': 3,
  4187. 'no': 3,
  4188. 'nr': 3,
  4189. 'nso': 4,
  4190. 'ny': 3,
  4191. 'nyn': 3,
  4192. 'om': 3,
  4193. 'or': 3,
  4194. 'pa': 3,
  4195. 'pap': 3,
  4196. 'pl': 13,
  4197. 'ps': 3,
  4198. 'pt': 3,
  4199. 'rm': 3,
  4200. 'ro': 9,
  4201. 'rof': 3,
  4202. 'ru': 11,
  4203. 'rwk': 3,
  4204. 'sah': 0,
  4205. 'saq': 3,
  4206. 'se': 7,
  4207. 'seh': 3,
  4208. 'ses': 0,
  4209. 'sg': 0,
  4210. 'sh': 11,
  4211. 'shi': 19,
  4212. 'sk': 12,
  4213. 'sl': 14,
  4214. 'sma': 7,
  4215. 'smi': 7,
  4216. 'smj': 7,
  4217. 'smn': 7,
  4218. 'sms': 7,
  4219. 'sn': 3,
  4220. 'so': 3,
  4221. 'sq': 3,
  4222. 'sr': 11,
  4223. 'ss': 3,
  4224. 'ssy': 3,
  4225. 'st': 3,
  4226. 'sv': 3,
  4227. 'sw': 3,
  4228. 'syr': 3,
  4229. 'ta': 3,
  4230. 'te': 3,
  4231. 'teo': 3,
  4232. 'th': 0,
  4233. 'ti': 4,
  4234. 'tig': 3,
  4235. 'tk': 3,
  4236. 'tl': 4,
  4237. 'tn': 3,
  4238. 'to': 0,
  4239. 'tr': 0,
  4240. 'ts': 3,
  4241. 'tzm': 22,
  4242. 'uk': 11,
  4243. 'ur': 3,
  4244. 've': 3,
  4245. 'vi': 0,
  4246. 'vun': 3,
  4247. 'wa': 4,
  4248. 'wae': 3,
  4249. 'wo': 0,
  4250. 'xh': 3,
  4251. 'xog': 3,
  4252. 'yo': 0,
  4253. 'zh': 0,
  4254. 'zu': 3
  4255. };
  4256. function isIn(n, list) {
  4257. return list.indexOf(n) !== -1;
  4258. }
  4259. function isBetween(n, start, end) {
  4260. return start <= n && n <= end;
  4261. }
  4262. var pluralRules = {
  4263. '0': function _(n) {
  4264. return 'other';
  4265. },
  4266. '1': function _(n) {
  4267. if (isBetween(n % 100, 3, 10)) return 'few';
  4268. if (n === 0) return 'zero';
  4269. if (isBetween(n % 100, 11, 99)) return 'many';
  4270. if (n == 2) return 'two';
  4271. if (n == 1) return 'one';
  4272. return 'other';
  4273. },
  4274. '2': function _(n) {
  4275. if (n !== 0 && n % 10 === 0) return 'many';
  4276. if (n == 2) return 'two';
  4277. if (n == 1) return 'one';
  4278. return 'other';
  4279. },
  4280. '3': function _(n) {
  4281. if (n == 1) return 'one';
  4282. return 'other';
  4283. },
  4284. '4': function _(n) {
  4285. if (isBetween(n, 0, 1)) return 'one';
  4286. return 'other';
  4287. },
  4288. '5': function _(n) {
  4289. if (isBetween(n, 0, 2) && n != 2) return 'one';
  4290. return 'other';
  4291. },
  4292. '6': function _(n) {
  4293. if (n === 0) return 'zero';
  4294. if (n % 10 == 1 && n % 100 != 11) return 'one';
  4295. return 'other';
  4296. },
  4297. '7': function _(n) {
  4298. if (n == 2) return 'two';
  4299. if (n == 1) return 'one';
  4300. return 'other';
  4301. },
  4302. '8': function _(n) {
  4303. if (isBetween(n, 3, 6)) return 'few';
  4304. if (isBetween(n, 7, 10)) return 'many';
  4305. if (n == 2) return 'two';
  4306. if (n == 1) return 'one';
  4307. return 'other';
  4308. },
  4309. '9': function _(n) {
  4310. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  4311. if (n == 1) return 'one';
  4312. return 'other';
  4313. },
  4314. '10': function _(n) {
  4315. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  4316. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  4317. return 'other';
  4318. },
  4319. '11': function _(n) {
  4320. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  4321. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  4322. if (n % 10 == 1 && n % 100 != 11) return 'one';
  4323. return 'other';
  4324. },
  4325. '12': function _(n) {
  4326. if (isBetween(n, 2, 4)) return 'few';
  4327. if (n == 1) return 'one';
  4328. return 'other';
  4329. },
  4330. '13': function _(n) {
  4331. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  4332. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  4333. if (n == 1) return 'one';
  4334. return 'other';
  4335. },
  4336. '14': function _(n) {
  4337. if (isBetween(n % 100, 3, 4)) return 'few';
  4338. if (n % 100 == 2) return 'two';
  4339. if (n % 100 == 1) return 'one';
  4340. return 'other';
  4341. },
  4342. '15': function _(n) {
  4343. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  4344. if (isBetween(n % 100, 11, 19)) return 'many';
  4345. if (n == 1) return 'one';
  4346. return 'other';
  4347. },
  4348. '16': function _(n) {
  4349. if (n % 10 == 1 && n != 11) return 'one';
  4350. return 'other';
  4351. },
  4352. '17': function _(n) {
  4353. if (n == 3) return 'few';
  4354. if (n === 0) return 'zero';
  4355. if (n == 6) return 'many';
  4356. if (n == 2) return 'two';
  4357. if (n == 1) return 'one';
  4358. return 'other';
  4359. },
  4360. '18': function _(n) {
  4361. if (n === 0) return 'zero';
  4362. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  4363. return 'other';
  4364. },
  4365. '19': function _(n) {
  4366. if (isBetween(n, 2, 10)) return 'few';
  4367. if (isBetween(n, 0, 1)) return 'one';
  4368. return 'other';
  4369. },
  4370. '20': function _(n) {
  4371. if ((isBetween(n % 10, 3, 4) || n % 10 == 9) && !(isBetween(n % 100, 10, 19) || isBetween(n % 100, 70, 79) || isBetween(n % 100, 90, 99))) return 'few';
  4372. if (n % 1000000 === 0 && n !== 0) return 'many';
  4373. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  4374. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  4375. return 'other';
  4376. },
  4377. '21': function _(n) {
  4378. if (n === 0) return 'zero';
  4379. if (n == 1) return 'one';
  4380. return 'other';
  4381. },
  4382. '22': function _(n) {
  4383. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  4384. return 'other';
  4385. },
  4386. '23': function _(n) {
  4387. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  4388. return 'other';
  4389. },
  4390. '24': function _(n) {
  4391. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  4392. if (isIn(n, [2, 12])) return 'two';
  4393. if (isIn(n, [1, 11])) return 'one';
  4394. return 'other';
  4395. }
  4396. };
  4397. var index = locales2rules[lang.replace(/-.*$/, '')];
  4398. if (!(index in pluralRules)) {
  4399. console.warn('plural form unknown for [' + lang + ']');
  4400. return function () {
  4401. return 'other';
  4402. };
  4403. }
  4404. return pluralRules[index];
  4405. }
  4406. gMacros.plural = function (str, param, key, prop) {
  4407. var n = parseFloat(param);
  4408. if (isNaN(n)) return str;
  4409. if (prop != gTextProp) return str;
  4410. if (!gMacros._pluralRules) {
  4411. gMacros._pluralRules = getPluralRules(gLanguage);
  4412. }
  4413. var index = '[' + gMacros._pluralRules(n) + ']';
  4414. if (n === 0 && key + '[zero]' in gL10nData) {
  4415. str = gL10nData[key + '[zero]'][prop];
  4416. } else if (n == 1 && key + '[one]' in gL10nData) {
  4417. str = gL10nData[key + '[one]'][prop];
  4418. } else if (n == 2 && key + '[two]' in gL10nData) {
  4419. str = gL10nData[key + '[two]'][prop];
  4420. } else if (key + index in gL10nData) {
  4421. str = gL10nData[key + index][prop];
  4422. } else if (key + '[other]' in gL10nData) {
  4423. str = gL10nData[key + '[other]'][prop];
  4424. }
  4425. return str;
  4426. };
  4427. function getL10nData(key, args, fallback) {
  4428. var data = gL10nData[key];
  4429. if (!data) {
  4430. console.warn('#' + key + ' is undefined.');
  4431. if (!fallback) {
  4432. return null;
  4433. }
  4434. data = fallback;
  4435. }
  4436. var rv = {};
  4437. for (var prop in data) {
  4438. var str = data[prop];
  4439. str = substIndexes(str, args, key, prop);
  4440. str = substArguments(str, args, key);
  4441. rv[prop] = str;
  4442. }
  4443. return rv;
  4444. }
  4445. function substIndexes(str, args, key, prop) {
  4446. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  4447. var reMatch = reIndex.exec(str);
  4448. if (!reMatch || !reMatch.length) return str;
  4449. var macroName = reMatch[1];
  4450. var paramName = reMatch[2];
  4451. var param;
  4452. if (args && paramName in args) {
  4453. param = args[paramName];
  4454. } else if (paramName in gL10nData) {
  4455. param = gL10nData[paramName];
  4456. }
  4457. if (macroName in gMacros) {
  4458. var macro = gMacros[macroName];
  4459. str = macro(str, param, key, prop);
  4460. }
  4461. return str;
  4462. }
  4463. function substArguments(str, args, key) {
  4464. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  4465. return str.replace(reArgs, function (matched_text, arg) {
  4466. if (args && arg in args) {
  4467. return args[arg];
  4468. }
  4469. if (arg in gL10nData) {
  4470. return gL10nData[arg];
  4471. }
  4472. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  4473. return matched_text;
  4474. });
  4475. }
  4476. function translateElement(element) {
  4477. var l10n = getL10nAttributes(element);
  4478. if (!l10n.id) return;
  4479. var data = getL10nData(l10n.id, l10n.args);
  4480. if (!data) {
  4481. console.warn('#' + l10n.id + ' is undefined.');
  4482. return;
  4483. }
  4484. if (data[gTextProp]) {
  4485. if (getChildElementCount(element) === 0) {
  4486. element[gTextProp] = data[gTextProp];
  4487. } else {
  4488. var children = element.childNodes;
  4489. var found = false;
  4490. for (var i = 0, l = children.length; i < l; i++) {
  4491. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  4492. if (found) {
  4493. children[i].nodeValue = '';
  4494. } else {
  4495. children[i].nodeValue = data[gTextProp];
  4496. found = true;
  4497. }
  4498. }
  4499. }
  4500. if (!found) {
  4501. var textNode = document.createTextNode(data[gTextProp]);
  4502. element.insertBefore(textNode, element.firstChild);
  4503. }
  4504. }
  4505. delete data[gTextProp];
  4506. }
  4507. for (var k in data) {
  4508. element[k] = data[k];
  4509. }
  4510. }
  4511. function getChildElementCount(element) {
  4512. if (element.children) {
  4513. return element.children.length;
  4514. }
  4515. if (typeof element.childElementCount !== 'undefined') {
  4516. return element.childElementCount;
  4517. }
  4518. var count = 0;
  4519. for (var i = 0; i < element.childNodes.length; i++) {
  4520. count += element.nodeType === 1 ? 1 : 0;
  4521. }
  4522. return count;
  4523. }
  4524. function translateFragment(element) {
  4525. element = element || document.documentElement;
  4526. var children = getTranslatableChildren(element);
  4527. var elementCount = children.length;
  4528. for (var i = 0; i < elementCount; i++) {
  4529. translateElement(children[i]);
  4530. }
  4531. translateElement(element);
  4532. }
  4533. return {
  4534. get: function get(key, args, fallbackString) {
  4535. var index = key.lastIndexOf('.');
  4536. var prop = gTextProp;
  4537. if (index > 0) {
  4538. prop = key.substr(index + 1);
  4539. key = key.substring(0, index);
  4540. }
  4541. var fallback;
  4542. if (fallbackString) {
  4543. fallback = {};
  4544. fallback[prop] = fallbackString;
  4545. }
  4546. var data = getL10nData(key, args, fallback);
  4547. if (data && prop in data) {
  4548. return data[prop];
  4549. }
  4550. return '{{' + key + '}}';
  4551. },
  4552. getData: function getData() {
  4553. return gL10nData;
  4554. },
  4555. getText: function getText() {
  4556. return gTextData;
  4557. },
  4558. getLanguage: function getLanguage() {
  4559. return gLanguage;
  4560. },
  4561. setLanguage: function setLanguage(lang, callback) {
  4562. loadLocale(lang, function () {
  4563. if (callback) callback();
  4564. });
  4565. },
  4566. getDirection: function getDirection() {
  4567. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  4568. var shortCode = gLanguage.split('-', 1)[0];
  4569. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  4570. },
  4571. translate: translateFragment,
  4572. getReadyState: function getReadyState() {
  4573. return gReadyState;
  4574. },
  4575. ready: function ready(callback) {
  4576. if (!callback) {
  4577. return;
  4578. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  4579. window.setTimeout(function () {
  4580. callback();
  4581. });
  4582. } else if (document.addEventListener) {
  4583. document.addEventListener('localized', function once() {
  4584. document.removeEventListener('localized', once);
  4585. callback();
  4586. });
  4587. }
  4588. }
  4589. };
  4590. }(window, document);
  4591. /***/ })
  4592. /******/ ]);
  4593. });
  4594. //# sourceMappingURL=pdf_viewer.js.map