pdf_viewer.js 158 KB

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