2
0

pdf_viewer.js 157 KB

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