pdf_viewer.js 155 KB

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