pdf_viewer.js 168 KB

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