pdf_viewer.js 158 KB

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