pdf_viewer.js 156 KB

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