pdf_viewer.js 169 KB

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