pdf_viewer.js 150 KB

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