pdf_viewer.js 151 KB

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