pdf_viewer.js 218 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 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. })(globalThis, () => {
  32. return /******/ (() => { // webpackBootstrap
  33. /******/ "use strict";
  34. /******/ var __webpack_modules__ = ([
  35. /* 0 */,
  36. /* 1 */
  37. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  38. Object.defineProperty(exports, "__esModule", ({
  39. value: true
  40. }));
  41. exports.DefaultXfaLayerFactory = exports.DefaultTextLayerFactory = exports.DefaultStructTreeLayerFactory = exports.DefaultAnnotationLayerFactory = exports.DefaultAnnotationEditorLayerFactory = void 0;
  42. var _annotation_editor_layer_builder = __w_pdfjs_require__(2);
  43. var _annotation_layer_builder = __w_pdfjs_require__(5);
  44. var _l10n_utils = __w_pdfjs_require__(4);
  45. var _pdf_link_service = __w_pdfjs_require__(6);
  46. var _struct_tree_layer_builder = __w_pdfjs_require__(8);
  47. var _text_layer_builder = __w_pdfjs_require__(9);
  48. var _xfa_layer_builder = __w_pdfjs_require__(10);
  49. class DefaultAnnotationLayerFactory {
  50. createAnnotationLayerBuilder({
  51. pageDiv,
  52. pdfPage,
  53. annotationStorage = null,
  54. imageResourcesPath = "",
  55. renderForms = true,
  56. l10n = _l10n_utils.NullL10n,
  57. enableScripting = false,
  58. hasJSActionsPromise = null,
  59. mouseState = null,
  60. fieldObjectsPromise = null,
  61. annotationCanvasMap = null
  62. }) {
  63. return new _annotation_layer_builder.AnnotationLayerBuilder({
  64. pageDiv,
  65. pdfPage,
  66. imageResourcesPath,
  67. renderForms,
  68. linkService: new _pdf_link_service.SimpleLinkService(),
  69. l10n,
  70. annotationStorage,
  71. enableScripting,
  72. hasJSActionsPromise,
  73. fieldObjectsPromise,
  74. mouseState,
  75. annotationCanvasMap
  76. });
  77. }
  78. }
  79. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  80. class DefaultAnnotationEditorLayerFactory {
  81. createAnnotationEditorLayerBuilder({
  82. uiManager = null,
  83. pageDiv,
  84. pdfPage,
  85. l10n,
  86. annotationStorage = null
  87. }) {
  88. return new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  89. uiManager,
  90. pageDiv,
  91. pdfPage,
  92. l10n,
  93. annotationStorage
  94. });
  95. }
  96. }
  97. exports.DefaultAnnotationEditorLayerFactory = DefaultAnnotationEditorLayerFactory;
  98. class DefaultStructTreeLayerFactory {
  99. createStructTreeLayerBuilder({
  100. pdfPage
  101. }) {
  102. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  103. pdfPage
  104. });
  105. }
  106. }
  107. exports.DefaultStructTreeLayerFactory = DefaultStructTreeLayerFactory;
  108. class DefaultTextLayerFactory {
  109. createTextLayerBuilder({
  110. textLayerDiv,
  111. pageIndex,
  112. viewport,
  113. enhanceTextSelection = false,
  114. eventBus,
  115. highlighter
  116. }) {
  117. return new _text_layer_builder.TextLayerBuilder({
  118. textLayerDiv,
  119. pageIndex,
  120. viewport,
  121. enhanceTextSelection,
  122. eventBus,
  123. highlighter
  124. });
  125. }
  126. }
  127. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  128. class DefaultXfaLayerFactory {
  129. createXfaLayerBuilder({
  130. pageDiv,
  131. pdfPage,
  132. annotationStorage = null
  133. }) {
  134. return new _xfa_layer_builder.XfaLayerBuilder({
  135. pageDiv,
  136. pdfPage,
  137. annotationStorage,
  138. linkService: new _pdf_link_service.SimpleLinkService()
  139. });
  140. }
  141. }
  142. exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;
  143. /***/ }),
  144. /* 2 */
  145. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  146. Object.defineProperty(exports, "__esModule", ({
  147. value: true
  148. }));
  149. exports.AnnotationEditorLayerBuilder = void 0;
  150. var _pdfjsLib = __w_pdfjs_require__(3);
  151. var _l10n_utils = __w_pdfjs_require__(4);
  152. class AnnotationEditorLayerBuilder {
  153. #uiManager;
  154. constructor(options) {
  155. this.pageDiv = options.pageDiv;
  156. this.pdfPage = options.pdfPage;
  157. this.annotationStorage = options.annotationStorage || null;
  158. this.l10n = options.l10n || _l10n_utils.NullL10n;
  159. this.annotationEditorLayer = null;
  160. this.div = null;
  161. this._cancelled = false;
  162. this.#uiManager = options.uiManager;
  163. }
  164. async render(viewport, intent = "display") {
  165. if (intent !== "display") {
  166. return;
  167. }
  168. if (this._cancelled) {
  169. return;
  170. }
  171. const clonedViewport = viewport.clone({
  172. dontFlip: true
  173. });
  174. if (this.div) {
  175. this.annotationEditorLayer.update({
  176. viewport: clonedViewport
  177. });
  178. this.show();
  179. return;
  180. }
  181. this.div = document.createElement("div");
  182. this.div.className = "annotationEditorLayer";
  183. this.div.tabIndex = 0;
  184. this.pageDiv.append(this.div);
  185. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  186. uiManager: this.#uiManager,
  187. div: this.div,
  188. annotationStorage: this.annotationStorage,
  189. pageIndex: this.pdfPage._pageIndex,
  190. l10n: this.l10n,
  191. viewport: clonedViewport
  192. });
  193. const parameters = {
  194. viewport: clonedViewport,
  195. div: this.div,
  196. annotations: null,
  197. intent
  198. };
  199. this.annotationEditorLayer.render(parameters);
  200. }
  201. cancel() {
  202. this._cancelled = true;
  203. this.destroy();
  204. }
  205. hide() {
  206. if (!this.div) {
  207. return;
  208. }
  209. this.div.hidden = true;
  210. }
  211. show() {
  212. if (!this.div) {
  213. return;
  214. }
  215. this.div.hidden = false;
  216. }
  217. destroy() {
  218. if (!this.div) {
  219. return;
  220. }
  221. this.pageDiv = null;
  222. this.annotationEditorLayer.destroy();
  223. this.div.remove();
  224. }
  225. }
  226. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  227. /***/ }),
  228. /* 3 */
  229. /***/ ((module) => {
  230. let pdfjsLib;
  231. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  232. pdfjsLib = window["pdfjs-dist/build/pdf"];
  233. } else {
  234. pdfjsLib = require("../build/pdf.js");
  235. }
  236. module.exports = pdfjsLib;
  237. /***/ }),
  238. /* 4 */
  239. /***/ ((__unused_webpack_module, exports) => {
  240. Object.defineProperty(exports, "__esModule", ({
  241. value: true
  242. }));
  243. exports.NullL10n = void 0;
  244. exports.fixupLangCode = fixupLangCode;
  245. exports.getL10nFallback = getL10nFallback;
  246. const DEFAULT_L10N_STRINGS = {
  247. of_pages: "of {{pagesCount}}",
  248. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  249. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  250. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  251. document_properties_date_string: "{{date}}, {{time}}",
  252. document_properties_page_size_unit_inches: "in",
  253. document_properties_page_size_unit_millimeters: "mm",
  254. document_properties_page_size_orientation_portrait: "portrait",
  255. document_properties_page_size_orientation_landscape: "landscape",
  256. document_properties_page_size_name_a3: "A3",
  257. document_properties_page_size_name_a4: "A4",
  258. document_properties_page_size_name_letter: "Letter",
  259. document_properties_page_size_name_legal: "Legal",
  260. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  261. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  262. document_properties_linearized_yes: "Yes",
  263. document_properties_linearized_no: "No",
  264. print_progress_percent: "{{progress}}%",
  265. "toggle_sidebar.title": "Toggle Sidebar",
  266. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  267. additional_layers: "Additional Layers",
  268. page_landmark: "Page {{page}}",
  269. thumb_page_title: "Page {{page}}",
  270. thumb_page_canvas: "Thumbnail of Page {{page}}",
  271. find_reached_top: "Reached top of document, continued from bottom",
  272. find_reached_bottom: "Reached end of document, continued from top",
  273. "find_match_count[one]": "{{current}} of {{total}} match",
  274. "find_match_count[other]": "{{current}} of {{total}} matches",
  275. "find_match_count_limit[one]": "More than {{limit}} match",
  276. "find_match_count_limit[other]": "More than {{limit}} matches",
  277. find_not_found: "Phrase not found",
  278. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  279. error_message: "Message: {{message}}",
  280. error_stack: "Stack: {{stack}}",
  281. error_file: "File: {{file}}",
  282. error_line: "Line: {{line}}",
  283. rendering_error: "An error occurred while rendering the page.",
  284. page_scale_width: "Page Width",
  285. page_scale_fit: "Page Fit",
  286. page_scale_auto: "Automatic Zoom",
  287. page_scale_actual: "Actual Size",
  288. page_scale_percent: "{{scale}}%",
  289. loading: "Loading…",
  290. loading_error: "An error occurred while loading the PDF.",
  291. invalid_file_error: "Invalid or corrupted PDF file.",
  292. missing_file_error: "Missing PDF file.",
  293. unexpected_response_error: "Unexpected server response.",
  294. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  295. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  296. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  297. free_text_default_content: "Enter text…",
  298. editor_free_text_aria_label: "FreeText Editor",
  299. editor_ink_aria_label: "Ink Editor",
  300. editor_ink_canvas_aria_label: "User-created image"
  301. };
  302. function getL10nFallback(key, args) {
  303. switch (key) {
  304. case "find_match_count":
  305. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  306. break;
  307. case "find_match_count_limit":
  308. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  309. break;
  310. }
  311. return DEFAULT_L10N_STRINGS[key] || "";
  312. }
  313. const PARTIAL_LANG_CODES = {
  314. en: "en-US",
  315. es: "es-ES",
  316. fy: "fy-NL",
  317. ga: "ga-IE",
  318. gu: "gu-IN",
  319. hi: "hi-IN",
  320. hy: "hy-AM",
  321. nb: "nb-NO",
  322. ne: "ne-NP",
  323. nn: "nn-NO",
  324. pa: "pa-IN",
  325. pt: "pt-PT",
  326. sv: "sv-SE",
  327. zh: "zh-CN"
  328. };
  329. function fixupLangCode(langCode) {
  330. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  331. }
  332. function formatL10nValue(text, args) {
  333. if (!args) {
  334. return text;
  335. }
  336. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  337. return name in args ? args[name] : "{{" + name + "}}";
  338. });
  339. }
  340. const NullL10n = {
  341. async getLanguage() {
  342. return "en-us";
  343. },
  344. async getDirection() {
  345. return "ltr";
  346. },
  347. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  348. return formatL10nValue(fallback, args);
  349. },
  350. async translate(element) {}
  351. };
  352. exports.NullL10n = NullL10n;
  353. /***/ }),
  354. /* 5 */
  355. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  356. Object.defineProperty(exports, "__esModule", ({
  357. value: true
  358. }));
  359. exports.AnnotationLayerBuilder = void 0;
  360. var _pdfjsLib = __w_pdfjs_require__(3);
  361. var _l10n_utils = __w_pdfjs_require__(4);
  362. class AnnotationLayerBuilder {
  363. constructor({
  364. pageDiv,
  365. pdfPage,
  366. linkService,
  367. downloadManager,
  368. annotationStorage = null,
  369. imageResourcesPath = "",
  370. renderForms = true,
  371. l10n = _l10n_utils.NullL10n,
  372. enableScripting = false,
  373. hasJSActionsPromise = null,
  374. fieldObjectsPromise = null,
  375. mouseState = null,
  376. annotationCanvasMap = null
  377. }) {
  378. this.pageDiv = pageDiv;
  379. this.pdfPage = pdfPage;
  380. this.linkService = linkService;
  381. this.downloadManager = downloadManager;
  382. this.imageResourcesPath = imageResourcesPath;
  383. this.renderForms = renderForms;
  384. this.l10n = l10n;
  385. this.annotationStorage = annotationStorage;
  386. this.enableScripting = enableScripting;
  387. this._hasJSActionsPromise = hasJSActionsPromise;
  388. this._fieldObjectsPromise = fieldObjectsPromise;
  389. this._mouseState = mouseState;
  390. this._annotationCanvasMap = annotationCanvasMap;
  391. this.div = null;
  392. this._cancelled = false;
  393. }
  394. async render(viewport, intent = "display") {
  395. const [annotations, hasJSActions = false, fieldObjects = null] = await Promise.all([this.pdfPage.getAnnotations({
  396. intent
  397. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  398. if (this._cancelled || annotations.length === 0) {
  399. return;
  400. }
  401. const parameters = {
  402. viewport: viewport.clone({
  403. dontFlip: true
  404. }),
  405. div: this.div,
  406. annotations,
  407. page: this.pdfPage,
  408. imageResourcesPath: this.imageResourcesPath,
  409. renderForms: this.renderForms,
  410. linkService: this.linkService,
  411. downloadManager: this.downloadManager,
  412. annotationStorage: this.annotationStorage,
  413. enableScripting: this.enableScripting,
  414. hasJSActions,
  415. fieldObjects,
  416. mouseState: this._mouseState,
  417. annotationCanvasMap: this._annotationCanvasMap
  418. };
  419. if (this.div) {
  420. _pdfjsLib.AnnotationLayer.update(parameters);
  421. } else {
  422. this.div = document.createElement("div");
  423. this.div.className = "annotationLayer";
  424. this.pageDiv.append(this.div);
  425. parameters.div = this.div;
  426. _pdfjsLib.AnnotationLayer.render(parameters);
  427. this.l10n.translate(this.div);
  428. }
  429. }
  430. cancel() {
  431. this._cancelled = true;
  432. }
  433. hide() {
  434. if (!this.div) {
  435. return;
  436. }
  437. this.div.hidden = true;
  438. }
  439. }
  440. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  441. /***/ }),
  442. /* 6 */
  443. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  444. Object.defineProperty(exports, "__esModule", ({
  445. value: true
  446. }));
  447. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  448. var _ui_utils = __w_pdfjs_require__(7);
  449. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  450. const LinkTarget = {
  451. NONE: 0,
  452. SELF: 1,
  453. BLANK: 2,
  454. PARENT: 3,
  455. TOP: 4
  456. };
  457. exports.LinkTarget = LinkTarget;
  458. function addLinkAttributes(link, {
  459. url,
  460. target,
  461. rel,
  462. enabled = true
  463. } = {}) {
  464. if (!url || typeof url !== "string") {
  465. throw new Error('A valid "url" parameter must provided.');
  466. }
  467. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  468. if (enabled) {
  469. link.href = link.title = urlNullRemoved;
  470. } else {
  471. link.href = "";
  472. link.title = `Disabled: ${urlNullRemoved}`;
  473. link.onclick = () => {
  474. return false;
  475. };
  476. }
  477. let targetStr = "";
  478. switch (target) {
  479. case LinkTarget.NONE:
  480. break;
  481. case LinkTarget.SELF:
  482. targetStr = "_self";
  483. break;
  484. case LinkTarget.BLANK:
  485. targetStr = "_blank";
  486. break;
  487. case LinkTarget.PARENT:
  488. targetStr = "_parent";
  489. break;
  490. case LinkTarget.TOP:
  491. targetStr = "_top";
  492. break;
  493. }
  494. link.target = targetStr;
  495. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  496. }
  497. class PDFLinkService {
  498. #pagesRefCache = new Map();
  499. constructor({
  500. eventBus,
  501. externalLinkTarget = null,
  502. externalLinkRel = null,
  503. ignoreDestinationZoom = false
  504. } = {}) {
  505. this.eventBus = eventBus;
  506. this.externalLinkTarget = externalLinkTarget;
  507. this.externalLinkRel = externalLinkRel;
  508. this.externalLinkEnabled = true;
  509. this._ignoreDestinationZoom = ignoreDestinationZoom;
  510. this.baseUrl = null;
  511. this.pdfDocument = null;
  512. this.pdfViewer = null;
  513. this.pdfHistory = null;
  514. }
  515. setDocument(pdfDocument, baseUrl = null) {
  516. this.baseUrl = baseUrl;
  517. this.pdfDocument = pdfDocument;
  518. this.#pagesRefCache.clear();
  519. }
  520. setViewer(pdfViewer) {
  521. this.pdfViewer = pdfViewer;
  522. }
  523. setHistory(pdfHistory) {
  524. this.pdfHistory = pdfHistory;
  525. }
  526. get pagesCount() {
  527. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  528. }
  529. get page() {
  530. return this.pdfViewer.currentPageNumber;
  531. }
  532. set page(value) {
  533. this.pdfViewer.currentPageNumber = value;
  534. }
  535. get rotation() {
  536. return this.pdfViewer.pagesRotation;
  537. }
  538. set rotation(value) {
  539. this.pdfViewer.pagesRotation = value;
  540. }
  541. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  542. const destRef = explicitDest[0];
  543. let pageNumber;
  544. if (typeof destRef === "object" && destRef !== null) {
  545. pageNumber = this._cachedPageNumber(destRef);
  546. if (!pageNumber) {
  547. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  548. this.cachePageRef(pageIndex + 1, destRef);
  549. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  550. }).catch(() => {
  551. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  552. });
  553. return;
  554. }
  555. } else if (Number.isInteger(destRef)) {
  556. pageNumber = destRef + 1;
  557. } else {
  558. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  559. return;
  560. }
  561. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  562. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  563. return;
  564. }
  565. if (this.pdfHistory) {
  566. this.pdfHistory.pushCurrentPosition();
  567. this.pdfHistory.push({
  568. namedDest,
  569. explicitDest,
  570. pageNumber
  571. });
  572. }
  573. this.pdfViewer.scrollPageIntoView({
  574. pageNumber,
  575. destArray: explicitDest,
  576. ignoreDestinationZoom: this._ignoreDestinationZoom
  577. });
  578. }
  579. async goToDestination(dest) {
  580. if (!this.pdfDocument) {
  581. return;
  582. }
  583. let namedDest, explicitDest;
  584. if (typeof dest === "string") {
  585. namedDest = dest;
  586. explicitDest = await this.pdfDocument.getDestination(dest);
  587. } else {
  588. namedDest = null;
  589. explicitDest = await dest;
  590. }
  591. if (!Array.isArray(explicitDest)) {
  592. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  593. return;
  594. }
  595. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  596. }
  597. goToPage(val) {
  598. if (!this.pdfDocument) {
  599. return;
  600. }
  601. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  602. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  603. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  604. return;
  605. }
  606. if (this.pdfHistory) {
  607. this.pdfHistory.pushCurrentPosition();
  608. this.pdfHistory.pushPage(pageNumber);
  609. }
  610. this.pdfViewer.scrollPageIntoView({
  611. pageNumber
  612. });
  613. }
  614. addLinkAttributes(link, url, newWindow = false) {
  615. addLinkAttributes(link, {
  616. url,
  617. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  618. rel: this.externalLinkRel,
  619. enabled: this.externalLinkEnabled
  620. });
  621. }
  622. getDestinationHash(dest) {
  623. if (typeof dest === "string") {
  624. if (dest.length > 0) {
  625. return this.getAnchorUrl("#" + escape(dest));
  626. }
  627. } else if (Array.isArray(dest)) {
  628. const str = JSON.stringify(dest);
  629. if (str.length > 0) {
  630. return this.getAnchorUrl("#" + escape(str));
  631. }
  632. }
  633. return this.getAnchorUrl("");
  634. }
  635. getAnchorUrl(anchor) {
  636. return (this.baseUrl || "") + anchor;
  637. }
  638. setHash(hash) {
  639. if (!this.pdfDocument) {
  640. return;
  641. }
  642. let pageNumber, dest;
  643. if (hash.includes("=")) {
  644. const params = (0, _ui_utils.parseQueryString)(hash);
  645. if (params.has("search")) {
  646. this.eventBus.dispatch("findfromurlhash", {
  647. source: this,
  648. query: params.get("search").replace(/"/g, ""),
  649. phraseSearch: params.get("phrase") === "true"
  650. });
  651. }
  652. if (params.has("page")) {
  653. pageNumber = params.get("page") | 0 || 1;
  654. }
  655. if (params.has("zoom")) {
  656. const zoomArgs = params.get("zoom").split(",");
  657. const zoomArg = zoomArgs[0];
  658. const zoomArgNumber = parseFloat(zoomArg);
  659. if (!zoomArg.includes("Fit")) {
  660. dest = [null, {
  661. name: "XYZ"
  662. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  663. } else {
  664. if (zoomArg === "Fit" || zoomArg === "FitB") {
  665. dest = [null, {
  666. name: zoomArg
  667. }];
  668. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  669. dest = [null, {
  670. name: zoomArg
  671. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  672. } else if (zoomArg === "FitR") {
  673. if (zoomArgs.length !== 5) {
  674. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  675. } else {
  676. dest = [null, {
  677. name: zoomArg
  678. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  679. }
  680. } else {
  681. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  682. }
  683. }
  684. }
  685. if (dest) {
  686. this.pdfViewer.scrollPageIntoView({
  687. pageNumber: pageNumber || this.page,
  688. destArray: dest,
  689. allowNegativeOffset: true
  690. });
  691. } else if (pageNumber) {
  692. this.page = pageNumber;
  693. }
  694. if (params.has("pagemode")) {
  695. this.eventBus.dispatch("pagemode", {
  696. source: this,
  697. mode: params.get("pagemode")
  698. });
  699. }
  700. if (params.has("nameddest")) {
  701. this.goToDestination(params.get("nameddest"));
  702. }
  703. } else {
  704. dest = unescape(hash);
  705. try {
  706. dest = JSON.parse(dest);
  707. if (!Array.isArray(dest)) {
  708. dest = dest.toString();
  709. }
  710. } catch (ex) {}
  711. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  712. this.goToDestination(dest);
  713. return;
  714. }
  715. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  716. }
  717. }
  718. executeNamedAction(action) {
  719. switch (action) {
  720. case "GoBack":
  721. this.pdfHistory?.back();
  722. break;
  723. case "GoForward":
  724. this.pdfHistory?.forward();
  725. break;
  726. case "NextPage":
  727. this.pdfViewer.nextPage();
  728. break;
  729. case "PrevPage":
  730. this.pdfViewer.previousPage();
  731. break;
  732. case "LastPage":
  733. this.page = this.pagesCount;
  734. break;
  735. case "FirstPage":
  736. this.page = 1;
  737. break;
  738. default:
  739. break;
  740. }
  741. this.eventBus.dispatch("namedaction", {
  742. source: this,
  743. action
  744. });
  745. }
  746. cachePageRef(pageNum, pageRef) {
  747. if (!pageRef) {
  748. return;
  749. }
  750. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  751. this.#pagesRefCache.set(refStr, pageNum);
  752. }
  753. _cachedPageNumber(pageRef) {
  754. if (!pageRef) {
  755. return null;
  756. }
  757. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  758. return this.#pagesRefCache.get(refStr) || null;
  759. }
  760. isPageVisible(pageNumber) {
  761. return this.pdfViewer.isPageVisible(pageNumber);
  762. }
  763. isPageCached(pageNumber) {
  764. return this.pdfViewer.isPageCached(pageNumber);
  765. }
  766. static #isValidExplicitDestination(dest) {
  767. if (!Array.isArray(dest)) {
  768. return false;
  769. }
  770. const destLength = dest.length;
  771. if (destLength < 2) {
  772. return false;
  773. }
  774. const page = dest[0];
  775. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  776. return false;
  777. }
  778. const zoom = dest[1];
  779. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  780. return false;
  781. }
  782. let allowNull = true;
  783. switch (zoom.name) {
  784. case "XYZ":
  785. if (destLength !== 5) {
  786. return false;
  787. }
  788. break;
  789. case "Fit":
  790. case "FitB":
  791. return destLength === 2;
  792. case "FitH":
  793. case "FitBH":
  794. case "FitV":
  795. case "FitBV":
  796. if (destLength !== 3) {
  797. return false;
  798. }
  799. break;
  800. case "FitR":
  801. if (destLength !== 6) {
  802. return false;
  803. }
  804. allowNull = false;
  805. break;
  806. default:
  807. return false;
  808. }
  809. for (let i = 2; i < destLength; i++) {
  810. const param = dest[i];
  811. if (!(typeof param === "number" || allowNull && param === null)) {
  812. return false;
  813. }
  814. }
  815. return true;
  816. }
  817. }
  818. exports.PDFLinkService = PDFLinkService;
  819. class SimpleLinkService {
  820. constructor() {
  821. this.externalLinkEnabled = true;
  822. }
  823. get pagesCount() {
  824. return 0;
  825. }
  826. get page() {
  827. return 0;
  828. }
  829. set page(value) {}
  830. get rotation() {
  831. return 0;
  832. }
  833. set rotation(value) {}
  834. async goToDestination(dest) {}
  835. goToPage(val) {}
  836. addLinkAttributes(link, url, newWindow = false) {
  837. addLinkAttributes(link, {
  838. url,
  839. enabled: this.externalLinkEnabled
  840. });
  841. }
  842. getDestinationHash(dest) {
  843. return "#";
  844. }
  845. getAnchorUrl(hash) {
  846. return "#";
  847. }
  848. setHash(hash) {}
  849. executeNamedAction(action) {}
  850. cachePageRef(pageNum, pageRef) {}
  851. isPageVisible(pageNumber) {
  852. return true;
  853. }
  854. isPageCached(pageNumber) {
  855. return true;
  856. }
  857. }
  858. exports.SimpleLinkService = SimpleLinkService;
  859. /***/ }),
  860. /* 7 */
  861. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  862. Object.defineProperty(exports, "__esModule", ({
  863. value: true
  864. }));
  865. exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.OutputScale = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.AutoPrintRegExp = void 0;
  866. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  867. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  868. exports.approximateFraction = approximateFraction;
  869. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  870. exports.docStyle = void 0;
  871. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  872. exports.getPageSizeInches = getPageSizeInches;
  873. exports.getVisibleElements = getVisibleElements;
  874. exports.isPortraitOrientation = isPortraitOrientation;
  875. exports.isValidRotation = isValidRotation;
  876. exports.isValidScrollMode = isValidScrollMode;
  877. exports.isValidSpreadMode = isValidSpreadMode;
  878. exports.noContextMenuHandler = noContextMenuHandler;
  879. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  880. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  881. exports.parseQueryString = parseQueryString;
  882. exports.removeNullCharacters = removeNullCharacters;
  883. exports.roundToDivide = roundToDivide;
  884. exports.scrollIntoView = scrollIntoView;
  885. exports.watchScroll = watchScroll;
  886. var _pdfjsLib = __w_pdfjs_require__(3);
  887. const DEFAULT_SCALE_VALUE = "auto";
  888. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  889. const DEFAULT_SCALE = 1.0;
  890. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  891. const DEFAULT_SCALE_DELTA = 1.1;
  892. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  893. const MIN_SCALE = 0.1;
  894. exports.MIN_SCALE = MIN_SCALE;
  895. const MAX_SCALE = 10.0;
  896. exports.MAX_SCALE = MAX_SCALE;
  897. const UNKNOWN_SCALE = 0;
  898. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  899. const MAX_AUTO_SCALE = 1.25;
  900. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  901. const SCROLLBAR_PADDING = 40;
  902. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  903. const VERTICAL_PADDING = 5;
  904. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  905. const RenderingStates = {
  906. INITIAL: 0,
  907. RUNNING: 1,
  908. PAUSED: 2,
  909. FINISHED: 3
  910. };
  911. exports.RenderingStates = RenderingStates;
  912. const PresentationModeState = {
  913. UNKNOWN: 0,
  914. NORMAL: 1,
  915. CHANGING: 2,
  916. FULLSCREEN: 3
  917. };
  918. exports.PresentationModeState = PresentationModeState;
  919. const SidebarView = {
  920. UNKNOWN: -1,
  921. NONE: 0,
  922. THUMBS: 1,
  923. OUTLINE: 2,
  924. ATTACHMENTS: 3,
  925. LAYERS: 4
  926. };
  927. exports.SidebarView = SidebarView;
  928. const RendererType = {
  929. CANVAS: "canvas",
  930. SVG: "svg"
  931. };
  932. exports.RendererType = RendererType;
  933. const TextLayerMode = {
  934. DISABLE: 0,
  935. ENABLE: 1,
  936. ENABLE_ENHANCE: 2
  937. };
  938. exports.TextLayerMode = TextLayerMode;
  939. const ScrollMode = {
  940. UNKNOWN: -1,
  941. VERTICAL: 0,
  942. HORIZONTAL: 1,
  943. WRAPPED: 2,
  944. PAGE: 3
  945. };
  946. exports.ScrollMode = ScrollMode;
  947. const SpreadMode = {
  948. UNKNOWN: -1,
  949. NONE: 0,
  950. ODD: 1,
  951. EVEN: 2
  952. };
  953. exports.SpreadMode = SpreadMode;
  954. const AutoPrintRegExp = /\bprint\s*\(/;
  955. exports.AutoPrintRegExp = AutoPrintRegExp;
  956. class OutputScale {
  957. constructor() {
  958. const pixelRatio = window.devicePixelRatio || 1;
  959. this.sx = pixelRatio;
  960. this.sy = pixelRatio;
  961. }
  962. get scaled() {
  963. return this.sx !== 1 || this.sy !== 1;
  964. }
  965. }
  966. exports.OutputScale = OutputScale;
  967. function scrollIntoView(element, spot, scrollMatches = false) {
  968. let parent = element.offsetParent;
  969. if (!parent) {
  970. console.error("offsetParent is not set -- cannot scroll");
  971. return;
  972. }
  973. let offsetY = element.offsetTop + element.clientTop;
  974. let offsetX = element.offsetLeft + element.clientLeft;
  975. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  976. offsetY += parent.offsetTop;
  977. offsetX += parent.offsetLeft;
  978. parent = parent.offsetParent;
  979. if (!parent) {
  980. return;
  981. }
  982. }
  983. if (spot) {
  984. if (spot.top !== undefined) {
  985. offsetY += spot.top;
  986. }
  987. if (spot.left !== undefined) {
  988. offsetX += spot.left;
  989. parent.scrollLeft = offsetX;
  990. }
  991. }
  992. parent.scrollTop = offsetY;
  993. }
  994. function watchScroll(viewAreaElement, callback) {
  995. const debounceScroll = function (evt) {
  996. if (rAF) {
  997. return;
  998. }
  999. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  1000. rAF = null;
  1001. const currentX = viewAreaElement.scrollLeft;
  1002. const lastX = state.lastX;
  1003. if (currentX !== lastX) {
  1004. state.right = currentX > lastX;
  1005. }
  1006. state.lastX = currentX;
  1007. const currentY = viewAreaElement.scrollTop;
  1008. const lastY = state.lastY;
  1009. if (currentY !== lastY) {
  1010. state.down = currentY > lastY;
  1011. }
  1012. state.lastY = currentY;
  1013. callback(state);
  1014. });
  1015. };
  1016. const state = {
  1017. right: true,
  1018. down: true,
  1019. lastX: viewAreaElement.scrollLeft,
  1020. lastY: viewAreaElement.scrollTop,
  1021. _eventHandler: debounceScroll
  1022. };
  1023. let rAF = null;
  1024. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  1025. return state;
  1026. }
  1027. function parseQueryString(query) {
  1028. const params = new Map();
  1029. for (const [key, value] of new URLSearchParams(query)) {
  1030. params.set(key.toLowerCase(), value);
  1031. }
  1032. return params;
  1033. }
  1034. const NullCharactersRegExp = /\x00/g;
  1035. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  1036. function removeNullCharacters(str, replaceInvisible = false) {
  1037. if (typeof str !== "string") {
  1038. console.error(`The argument must be a string.`);
  1039. return str;
  1040. }
  1041. if (replaceInvisible) {
  1042. str = str.replace(InvisibleCharactersRegExp, " ");
  1043. }
  1044. return str.replace(NullCharactersRegExp, "");
  1045. }
  1046. function approximateFraction(x) {
  1047. if (Math.floor(x) === x) {
  1048. return [x, 1];
  1049. }
  1050. const xinv = 1 / x;
  1051. const limit = 8;
  1052. if (xinv > limit) {
  1053. return [1, limit];
  1054. } else if (Math.floor(xinv) === xinv) {
  1055. return [1, xinv];
  1056. }
  1057. const x_ = x > 1 ? xinv : x;
  1058. let a = 0,
  1059. b = 1,
  1060. c = 1,
  1061. d = 1;
  1062. while (true) {
  1063. const p = a + c,
  1064. q = b + d;
  1065. if (q > limit) {
  1066. break;
  1067. }
  1068. if (x_ <= p / q) {
  1069. c = p;
  1070. d = q;
  1071. } else {
  1072. a = p;
  1073. b = q;
  1074. }
  1075. }
  1076. let result;
  1077. if (x_ - a / b < c / d - x_) {
  1078. result = x_ === x ? [a, b] : [b, a];
  1079. } else {
  1080. result = x_ === x ? [c, d] : [d, c];
  1081. }
  1082. return result;
  1083. }
  1084. function roundToDivide(x, div) {
  1085. const r = x % div;
  1086. return r === 0 ? x : Math.round(x - r + div);
  1087. }
  1088. function getPageSizeInches({
  1089. view,
  1090. userUnit,
  1091. rotate
  1092. }) {
  1093. const [x1, y1, x2, y2] = view;
  1094. const changeOrientation = rotate % 180 !== 0;
  1095. const width = (x2 - x1) / 72 * userUnit;
  1096. const height = (y2 - y1) / 72 * userUnit;
  1097. return {
  1098. width: changeOrientation ? height : width,
  1099. height: changeOrientation ? width : height
  1100. };
  1101. }
  1102. function backtrackBeforeAllVisibleElements(index, views, top) {
  1103. if (index < 2) {
  1104. return index;
  1105. }
  1106. let elt = views[index].div;
  1107. let pageTop = elt.offsetTop + elt.clientTop;
  1108. if (pageTop >= top) {
  1109. elt = views[index - 1].div;
  1110. pageTop = elt.offsetTop + elt.clientTop;
  1111. }
  1112. for (let i = index - 2; i >= 0; --i) {
  1113. elt = views[i].div;
  1114. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  1115. break;
  1116. }
  1117. index = i;
  1118. }
  1119. return index;
  1120. }
  1121. function getVisibleElements({
  1122. scrollEl,
  1123. views,
  1124. sortByVisibility = false,
  1125. horizontal = false,
  1126. rtl = false
  1127. }) {
  1128. const top = scrollEl.scrollTop,
  1129. bottom = top + scrollEl.clientHeight;
  1130. const left = scrollEl.scrollLeft,
  1131. right = left + scrollEl.clientWidth;
  1132. function isElementBottomAfterViewTop(view) {
  1133. const element = view.div;
  1134. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  1135. return elementBottom > top;
  1136. }
  1137. function isElementNextAfterViewHorizontally(view) {
  1138. const element = view.div;
  1139. const elementLeft = element.offsetLeft + element.clientLeft;
  1140. const elementRight = elementLeft + element.clientWidth;
  1141. return rtl ? elementLeft < right : elementRight > left;
  1142. }
  1143. const visible = [],
  1144. ids = new Set(),
  1145. numViews = views.length;
  1146. let firstVisibleElementInd = (0, _pdfjsLib.binarySearchFirstItem)(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  1147. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  1148. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  1149. }
  1150. let lastEdge = horizontal ? right : -1;
  1151. for (let i = firstVisibleElementInd; i < numViews; i++) {
  1152. const view = views[i],
  1153. element = view.div;
  1154. const currentWidth = element.offsetLeft + element.clientLeft;
  1155. const currentHeight = element.offsetTop + element.clientTop;
  1156. const viewWidth = element.clientWidth,
  1157. viewHeight = element.clientHeight;
  1158. const viewRight = currentWidth + viewWidth;
  1159. const viewBottom = currentHeight + viewHeight;
  1160. if (lastEdge === -1) {
  1161. if (viewBottom >= bottom) {
  1162. lastEdge = viewBottom;
  1163. }
  1164. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  1165. break;
  1166. }
  1167. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  1168. continue;
  1169. }
  1170. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  1171. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  1172. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  1173. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  1174. const percent = fractionHeight * fractionWidth * 100 | 0;
  1175. visible.push({
  1176. id: view.id,
  1177. x: currentWidth,
  1178. y: currentHeight,
  1179. view,
  1180. percent,
  1181. widthPercent: fractionWidth * 100 | 0
  1182. });
  1183. ids.add(view.id);
  1184. }
  1185. const first = visible[0],
  1186. last = visible.at(-1);
  1187. if (sortByVisibility) {
  1188. visible.sort(function (a, b) {
  1189. const pc = a.percent - b.percent;
  1190. if (Math.abs(pc) > 0.001) {
  1191. return -pc;
  1192. }
  1193. return a.id - b.id;
  1194. });
  1195. }
  1196. return {
  1197. first,
  1198. last,
  1199. views: visible,
  1200. ids
  1201. };
  1202. }
  1203. function noContextMenuHandler(evt) {
  1204. evt.preventDefault();
  1205. }
  1206. function normalizeWheelEventDirection(evt) {
  1207. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  1208. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  1209. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  1210. delta = -delta;
  1211. }
  1212. return delta;
  1213. }
  1214. function normalizeWheelEventDelta(evt) {
  1215. let delta = normalizeWheelEventDirection(evt);
  1216. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  1217. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  1218. const MOUSE_PIXELS_PER_LINE = 30;
  1219. const MOUSE_LINES_PER_PAGE = 30;
  1220. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  1221. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  1222. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  1223. delta /= MOUSE_LINES_PER_PAGE;
  1224. }
  1225. return delta;
  1226. }
  1227. function isValidRotation(angle) {
  1228. return Number.isInteger(angle) && angle % 90 === 0;
  1229. }
  1230. function isValidScrollMode(mode) {
  1231. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  1232. }
  1233. function isValidSpreadMode(mode) {
  1234. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  1235. }
  1236. function isPortraitOrientation(size) {
  1237. return size.width <= size.height;
  1238. }
  1239. const animationStarted = new Promise(function (resolve) {
  1240. window.requestAnimationFrame(resolve);
  1241. });
  1242. exports.animationStarted = animationStarted;
  1243. const docStyle = document.documentElement.style;
  1244. exports.docStyle = docStyle;
  1245. function clamp(v, min, max) {
  1246. return Math.min(Math.max(v, min), max);
  1247. }
  1248. class ProgressBar {
  1249. #classList = null;
  1250. #percent = 0;
  1251. #visible = true;
  1252. constructor(id) {
  1253. if (arguments.length > 1) {
  1254. throw new Error("ProgressBar no longer accepts any additional options, " + "please use CSS rules to modify its appearance instead.");
  1255. }
  1256. const bar = document.getElementById(id);
  1257. this.#classList = bar.classList;
  1258. }
  1259. get percent() {
  1260. return this.#percent;
  1261. }
  1262. set percent(val) {
  1263. this.#percent = clamp(val, 0, 100);
  1264. if (isNaN(val)) {
  1265. this.#classList.add("indeterminate");
  1266. return;
  1267. }
  1268. this.#classList.remove("indeterminate");
  1269. docStyle.setProperty("--progressBar-percent", `${this.#percent}%`);
  1270. }
  1271. setWidth(viewer) {
  1272. if (!viewer) {
  1273. return;
  1274. }
  1275. const container = viewer.parentNode;
  1276. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  1277. if (scrollbarWidth > 0) {
  1278. docStyle.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  1279. }
  1280. }
  1281. hide() {
  1282. if (!this.#visible) {
  1283. return;
  1284. }
  1285. this.#visible = false;
  1286. this.#classList.add("hidden");
  1287. }
  1288. show() {
  1289. if (this.#visible) {
  1290. return;
  1291. }
  1292. this.#visible = true;
  1293. this.#classList.remove("hidden");
  1294. }
  1295. }
  1296. exports.ProgressBar = ProgressBar;
  1297. function getActiveOrFocusedElement() {
  1298. let curRoot = document;
  1299. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  1300. while (curActiveOrFocused?.shadowRoot) {
  1301. curRoot = curActiveOrFocused.shadowRoot;
  1302. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  1303. }
  1304. return curActiveOrFocused;
  1305. }
  1306. function apiPageLayoutToViewerModes(layout) {
  1307. let scrollMode = ScrollMode.VERTICAL,
  1308. spreadMode = SpreadMode.NONE;
  1309. switch (layout) {
  1310. case "SinglePage":
  1311. scrollMode = ScrollMode.PAGE;
  1312. break;
  1313. case "OneColumn":
  1314. break;
  1315. case "TwoPageLeft":
  1316. scrollMode = ScrollMode.PAGE;
  1317. case "TwoColumnLeft":
  1318. spreadMode = SpreadMode.ODD;
  1319. break;
  1320. case "TwoPageRight":
  1321. scrollMode = ScrollMode.PAGE;
  1322. case "TwoColumnRight":
  1323. spreadMode = SpreadMode.EVEN;
  1324. break;
  1325. }
  1326. return {
  1327. scrollMode,
  1328. spreadMode
  1329. };
  1330. }
  1331. function apiPageModeToSidebarView(mode) {
  1332. switch (mode) {
  1333. case "UseNone":
  1334. return SidebarView.NONE;
  1335. case "UseThumbs":
  1336. return SidebarView.THUMBS;
  1337. case "UseOutlines":
  1338. return SidebarView.OUTLINE;
  1339. case "UseAttachments":
  1340. return SidebarView.ATTACHMENTS;
  1341. case "UseOC":
  1342. return SidebarView.LAYERS;
  1343. }
  1344. return SidebarView.NONE;
  1345. }
  1346. /***/ }),
  1347. /* 8 */
  1348. /***/ ((__unused_webpack_module, exports) => {
  1349. Object.defineProperty(exports, "__esModule", ({
  1350. value: true
  1351. }));
  1352. exports.StructTreeLayerBuilder = void 0;
  1353. const PDF_ROLE_TO_HTML_ROLE = {
  1354. Document: null,
  1355. DocumentFragment: null,
  1356. Part: "group",
  1357. Sect: "group",
  1358. Div: "group",
  1359. Aside: "note",
  1360. NonStruct: "none",
  1361. P: null,
  1362. H: "heading",
  1363. Title: null,
  1364. FENote: "note",
  1365. Sub: "group",
  1366. Lbl: null,
  1367. Span: null,
  1368. Em: null,
  1369. Strong: null,
  1370. Link: "link",
  1371. Annot: "note",
  1372. Form: "form",
  1373. Ruby: null,
  1374. RB: null,
  1375. RT: null,
  1376. RP: null,
  1377. Warichu: null,
  1378. WT: null,
  1379. WP: null,
  1380. L: "list",
  1381. LI: "listitem",
  1382. LBody: null,
  1383. Table: "table",
  1384. TR: "row",
  1385. TH: "columnheader",
  1386. TD: "cell",
  1387. THead: "columnheader",
  1388. TBody: null,
  1389. TFoot: null,
  1390. Caption: null,
  1391. Figure: "figure",
  1392. Formula: null,
  1393. Artifact: null
  1394. };
  1395. const HEADING_PATTERN = /^H(\d+)$/;
  1396. class StructTreeLayerBuilder {
  1397. constructor({
  1398. pdfPage
  1399. }) {
  1400. this.pdfPage = pdfPage;
  1401. }
  1402. render(structTree) {
  1403. return this._walk(structTree);
  1404. }
  1405. _setAttributes(structElement, htmlElement) {
  1406. if (structElement.alt !== undefined) {
  1407. htmlElement.setAttribute("aria-label", structElement.alt);
  1408. }
  1409. if (structElement.id !== undefined) {
  1410. htmlElement.setAttribute("aria-owns", structElement.id);
  1411. }
  1412. if (structElement.lang !== undefined) {
  1413. htmlElement.setAttribute("lang", structElement.lang);
  1414. }
  1415. }
  1416. _walk(node) {
  1417. if (!node) {
  1418. return null;
  1419. }
  1420. const element = document.createElement("span");
  1421. if ("role" in node) {
  1422. const {
  1423. role
  1424. } = node;
  1425. const match = role.match(HEADING_PATTERN);
  1426. if (match) {
  1427. element.setAttribute("role", "heading");
  1428. element.setAttribute("aria-level", match[1]);
  1429. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  1430. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  1431. }
  1432. }
  1433. this._setAttributes(node, element);
  1434. if (node.children) {
  1435. if (node.children.length === 1 && "id" in node.children[0]) {
  1436. this._setAttributes(node.children[0], element);
  1437. } else {
  1438. for (const kid of node.children) {
  1439. element.append(this._walk(kid));
  1440. }
  1441. }
  1442. }
  1443. return element;
  1444. }
  1445. }
  1446. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  1447. /***/ }),
  1448. /* 9 */
  1449. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1450. Object.defineProperty(exports, "__esModule", ({
  1451. value: true
  1452. }));
  1453. exports.TextLayerBuilder = void 0;
  1454. var _pdfjsLib = __w_pdfjs_require__(3);
  1455. const EXPAND_DIVS_TIMEOUT = 300;
  1456. class TextLayerBuilder {
  1457. constructor({
  1458. textLayerDiv,
  1459. eventBus,
  1460. pageIndex,
  1461. viewport,
  1462. highlighter = null,
  1463. enhanceTextSelection = false
  1464. }) {
  1465. this.textLayerDiv = textLayerDiv;
  1466. this.eventBus = eventBus;
  1467. this.textContent = null;
  1468. this.textContentItemsStr = [];
  1469. this.textContentStream = null;
  1470. this.renderingDone = false;
  1471. this.pageNumber = pageIndex + 1;
  1472. this.viewport = viewport;
  1473. this.textDivs = [];
  1474. this.textLayerRenderTask = null;
  1475. this.highlighter = highlighter;
  1476. this.enhanceTextSelection = enhanceTextSelection;
  1477. this._bindMouse();
  1478. }
  1479. _finishRendering() {
  1480. this.renderingDone = true;
  1481. if (!this.enhanceTextSelection) {
  1482. const endOfContent = document.createElement("div");
  1483. endOfContent.className = "endOfContent";
  1484. this.textLayerDiv.append(endOfContent);
  1485. }
  1486. this.eventBus.dispatch("textlayerrendered", {
  1487. source: this,
  1488. pageNumber: this.pageNumber,
  1489. numTextDivs: this.textDivs.length
  1490. });
  1491. }
  1492. render(timeout = 0) {
  1493. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  1494. return;
  1495. }
  1496. this.cancel();
  1497. this.textDivs.length = 0;
  1498. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  1499. const textLayerFrag = document.createDocumentFragment();
  1500. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  1501. textContent: this.textContent,
  1502. textContentStream: this.textContentStream,
  1503. container: textLayerFrag,
  1504. viewport: this.viewport,
  1505. textDivs: this.textDivs,
  1506. textContentItemsStr: this.textContentItemsStr,
  1507. timeout,
  1508. enhanceTextSelection: this.enhanceTextSelection
  1509. });
  1510. this.textLayerRenderTask.promise.then(() => {
  1511. this.textLayerDiv.append(textLayerFrag);
  1512. this._finishRendering();
  1513. this.highlighter?.enable();
  1514. }, function (reason) {});
  1515. }
  1516. cancel() {
  1517. if (this.textLayerRenderTask) {
  1518. this.textLayerRenderTask.cancel();
  1519. this.textLayerRenderTask = null;
  1520. }
  1521. this.highlighter?.disable();
  1522. }
  1523. setTextContentStream(readableStream) {
  1524. this.cancel();
  1525. this.textContentStream = readableStream;
  1526. }
  1527. setTextContent(textContent) {
  1528. this.cancel();
  1529. this.textContent = textContent;
  1530. }
  1531. _bindMouse() {
  1532. const div = this.textLayerDiv;
  1533. let expandDivsTimer = null;
  1534. div.addEventListener("mousedown", evt => {
  1535. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  1536. this.textLayerRenderTask.expandTextDivs(true);
  1537. if (expandDivsTimer) {
  1538. clearTimeout(expandDivsTimer);
  1539. expandDivsTimer = null;
  1540. }
  1541. return;
  1542. }
  1543. const end = div.querySelector(".endOfContent");
  1544. if (!end) {
  1545. return;
  1546. }
  1547. let adjustTop = evt.target !== div;
  1548. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  1549. if (adjustTop) {
  1550. const divBounds = div.getBoundingClientRect();
  1551. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  1552. end.style.top = (r * 100).toFixed(2) + "%";
  1553. }
  1554. end.classList.add("active");
  1555. });
  1556. div.addEventListener("mouseup", () => {
  1557. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  1558. expandDivsTimer = setTimeout(() => {
  1559. if (this.textLayerRenderTask) {
  1560. this.textLayerRenderTask.expandTextDivs(false);
  1561. }
  1562. expandDivsTimer = null;
  1563. }, EXPAND_DIVS_TIMEOUT);
  1564. return;
  1565. }
  1566. const end = div.querySelector(".endOfContent");
  1567. if (!end) {
  1568. return;
  1569. }
  1570. end.style.top = "";
  1571. end.classList.remove("active");
  1572. });
  1573. }
  1574. }
  1575. exports.TextLayerBuilder = TextLayerBuilder;
  1576. /***/ }),
  1577. /* 10 */
  1578. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1579. Object.defineProperty(exports, "__esModule", ({
  1580. value: true
  1581. }));
  1582. exports.XfaLayerBuilder = void 0;
  1583. var _pdfjsLib = __w_pdfjs_require__(3);
  1584. class XfaLayerBuilder {
  1585. constructor({
  1586. pageDiv,
  1587. pdfPage,
  1588. annotationStorage = null,
  1589. linkService,
  1590. xfaHtml = null
  1591. }) {
  1592. this.pageDiv = pageDiv;
  1593. this.pdfPage = pdfPage;
  1594. this.annotationStorage = annotationStorage;
  1595. this.linkService = linkService;
  1596. this.xfaHtml = xfaHtml;
  1597. this.div = null;
  1598. this._cancelled = false;
  1599. }
  1600. render(viewport, intent = "display") {
  1601. if (intent === "print") {
  1602. const parameters = {
  1603. viewport: viewport.clone({
  1604. dontFlip: true
  1605. }),
  1606. div: this.div,
  1607. xfaHtml: this.xfaHtml,
  1608. annotationStorage: this.annotationStorage,
  1609. linkService: this.linkService,
  1610. intent
  1611. };
  1612. const div = document.createElement("div");
  1613. this.pageDiv.append(div);
  1614. parameters.div = div;
  1615. const result = _pdfjsLib.XfaLayer.render(parameters);
  1616. return Promise.resolve(result);
  1617. }
  1618. return this.pdfPage.getXfa().then(xfaHtml => {
  1619. if (this._cancelled || !xfaHtml) {
  1620. return {
  1621. textDivs: []
  1622. };
  1623. }
  1624. const parameters = {
  1625. viewport: viewport.clone({
  1626. dontFlip: true
  1627. }),
  1628. div: this.div,
  1629. xfaHtml,
  1630. annotationStorage: this.annotationStorage,
  1631. linkService: this.linkService,
  1632. intent
  1633. };
  1634. if (this.div) {
  1635. return _pdfjsLib.XfaLayer.update(parameters);
  1636. }
  1637. this.div = document.createElement("div");
  1638. this.pageDiv.append(this.div);
  1639. parameters.div = this.div;
  1640. return _pdfjsLib.XfaLayer.render(parameters);
  1641. }).catch(error => {
  1642. console.error(error);
  1643. });
  1644. }
  1645. cancel() {
  1646. this._cancelled = true;
  1647. }
  1648. hide() {
  1649. if (!this.div) {
  1650. return;
  1651. }
  1652. this.div.hidden = true;
  1653. }
  1654. }
  1655. exports.XfaLayerBuilder = XfaLayerBuilder;
  1656. /***/ }),
  1657. /* 11 */
  1658. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1659. Object.defineProperty(exports, "__esModule", ({
  1660. value: true
  1661. }));
  1662. exports.PDFViewer = exports.PDFSinglePageViewer = void 0;
  1663. var _ui_utils = __w_pdfjs_require__(7);
  1664. var _base_viewer = __w_pdfjs_require__(12);
  1665. class PDFViewer extends _base_viewer.BaseViewer {}
  1666. exports.PDFViewer = PDFViewer;
  1667. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  1668. _resetView() {
  1669. super._resetView();
  1670. this._scrollMode = _ui_utils.ScrollMode.PAGE;
  1671. this._spreadMode = _ui_utils.SpreadMode.NONE;
  1672. }
  1673. set scrollMode(mode) {}
  1674. _updateScrollMode() {}
  1675. set spreadMode(mode) {}
  1676. _updateSpreadMode() {}
  1677. }
  1678. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  1679. /***/ }),
  1680. /* 12 */
  1681. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1682. Object.defineProperty(exports, "__esModule", ({
  1683. value: true
  1684. }));
  1685. exports.PagesCountLimit = exports.PDFPageViewBuffer = exports.BaseViewer = void 0;
  1686. var _pdfjsLib = __w_pdfjs_require__(3);
  1687. var _ui_utils = __w_pdfjs_require__(7);
  1688. var _annotation_editor_layer_builder = __w_pdfjs_require__(2);
  1689. var _annotation_layer_builder = __w_pdfjs_require__(5);
  1690. var _app_options = __w_pdfjs_require__(13);
  1691. var _l10n_utils = __w_pdfjs_require__(4);
  1692. var _pdf_page_view = __w_pdfjs_require__(14);
  1693. var _pdf_rendering_queue = __w_pdfjs_require__(15);
  1694. var _pdf_link_service = __w_pdfjs_require__(6);
  1695. var _struct_tree_layer_builder = __w_pdfjs_require__(8);
  1696. var _text_highlighter = __w_pdfjs_require__(16);
  1697. var _text_layer_builder = __w_pdfjs_require__(9);
  1698. var _xfa_layer_builder = __w_pdfjs_require__(10);
  1699. const DEFAULT_CACHE_SIZE = 10;
  1700. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  1701. const PagesCountLimit = {
  1702. FORCE_SCROLL_MODE_PAGE: 15000,
  1703. FORCE_LAZY_PAGE_INIT: 7500,
  1704. PAUSE_EAGER_PAGE_INIT: 250
  1705. };
  1706. exports.PagesCountLimit = PagesCountLimit;
  1707. const ANNOTATION_EDITOR_MODE = _app_options.compatibilityParams.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.DISABLE;
  1708. function isValidAnnotationEditorMode(mode) {
  1709. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  1710. }
  1711. class PDFPageViewBuffer {
  1712. #buf = new Set();
  1713. #size = 0;
  1714. constructor(size) {
  1715. this.#size = size;
  1716. }
  1717. push(view) {
  1718. const buf = this.#buf;
  1719. if (buf.has(view)) {
  1720. buf.delete(view);
  1721. }
  1722. buf.add(view);
  1723. if (buf.size > this.#size) {
  1724. this.#destroyFirstView();
  1725. }
  1726. }
  1727. resize(newSize, idsToKeep = null) {
  1728. this.#size = newSize;
  1729. const buf = this.#buf;
  1730. if (idsToKeep) {
  1731. const ii = buf.size;
  1732. let i = 1;
  1733. for (const view of buf) {
  1734. if (idsToKeep.has(view.id)) {
  1735. buf.delete(view);
  1736. buf.add(view);
  1737. }
  1738. if (++i > ii) {
  1739. break;
  1740. }
  1741. }
  1742. }
  1743. while (buf.size > this.#size) {
  1744. this.#destroyFirstView();
  1745. }
  1746. }
  1747. has(view) {
  1748. return this.#buf.has(view);
  1749. }
  1750. [Symbol.iterator]() {
  1751. return this.#buf.keys();
  1752. }
  1753. #destroyFirstView() {
  1754. const firstView = this.#buf.keys().next().value;
  1755. firstView?.destroy();
  1756. this.#buf.delete(firstView);
  1757. }
  1758. }
  1759. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  1760. class BaseViewer {
  1761. #buffer = null;
  1762. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  1763. #annotationEditorUIManager = null;
  1764. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  1765. #enablePermissions = false;
  1766. #previousContainerHeight = 0;
  1767. #scrollModePageState = null;
  1768. #onVisibilityChange = null;
  1769. constructor(options) {
  1770. if (this.constructor === BaseViewer) {
  1771. throw new Error("Cannot initialize BaseViewer.");
  1772. }
  1773. const viewerVersion = '2.15.349';
  1774. if (_pdfjsLib.version !== viewerVersion) {
  1775. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  1776. }
  1777. this.container = options.container;
  1778. this.viewer = options.viewer || options.container.firstElementChild;
  1779. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  1780. throw new Error("Invalid `container` and/or `viewer` option.");
  1781. }
  1782. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  1783. throw new Error("The `container` must be absolutely positioned.");
  1784. }
  1785. this.eventBus = options.eventBus;
  1786. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  1787. this.downloadManager = options.downloadManager || null;
  1788. this.findController = options.findController || null;
  1789. this._scriptingManager = options.scriptingManager || null;
  1790. this.removePageBorders = options.removePageBorders || false;
  1791. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  1792. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  1793. this.#annotationEditorMode = options.annotationEditorMode ?? ANNOTATION_EDITOR_MODE;
  1794. this.imageResourcesPath = options.imageResourcesPath || "";
  1795. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  1796. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  1797. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  1798. this.maxCanvasPixels = options.maxCanvasPixels;
  1799. this.l10n = options.l10n || _l10n_utils.NullL10n;
  1800. this.#enablePermissions = options.enablePermissions || false;
  1801. this.pageColors = options.pageColors || null;
  1802. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  1803. if (this.pageColors.background || this.pageColors.foreground) {
  1804. console.warn("BaseViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  1805. }
  1806. this.pageColors = null;
  1807. }
  1808. this.defaultRenderingQueue = !options.renderingQueue;
  1809. if (this.defaultRenderingQueue) {
  1810. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  1811. this.renderingQueue.setViewer(this);
  1812. } else {
  1813. this.renderingQueue = options.renderingQueue;
  1814. }
  1815. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  1816. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  1817. this._onBeforeDraw = this._onAfterDraw = null;
  1818. this._resetView();
  1819. if (this.removePageBorders) {
  1820. this.viewer.classList.add("removePageBorders");
  1821. }
  1822. this.updateContainerHeightCss();
  1823. }
  1824. get pagesCount() {
  1825. return this._pages.length;
  1826. }
  1827. getPageView(index) {
  1828. return this._pages[index];
  1829. }
  1830. get pageViewsReady() {
  1831. if (!this._pagesCapability.settled) {
  1832. return false;
  1833. }
  1834. return this._pages.every(function (pageView) {
  1835. return pageView?.pdfPage;
  1836. });
  1837. }
  1838. get renderForms() {
  1839. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  1840. }
  1841. get enableScripting() {
  1842. return !!this._scriptingManager;
  1843. }
  1844. get currentPageNumber() {
  1845. return this._currentPageNumber;
  1846. }
  1847. set currentPageNumber(val) {
  1848. if (!Number.isInteger(val)) {
  1849. throw new Error("Invalid page number.");
  1850. }
  1851. if (!this.pdfDocument) {
  1852. return;
  1853. }
  1854. if (!this._setCurrentPageNumber(val, true)) {
  1855. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  1856. }
  1857. }
  1858. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  1859. if (this._currentPageNumber === val) {
  1860. if (resetCurrentPageView) {
  1861. this.#resetCurrentPageView();
  1862. }
  1863. return true;
  1864. }
  1865. if (!(0 < val && val <= this.pagesCount)) {
  1866. return false;
  1867. }
  1868. const previous = this._currentPageNumber;
  1869. this._currentPageNumber = val;
  1870. this.eventBus.dispatch("pagechanging", {
  1871. source: this,
  1872. pageNumber: val,
  1873. pageLabel: this._pageLabels?.[val - 1] ?? null,
  1874. previous
  1875. });
  1876. if (resetCurrentPageView) {
  1877. this.#resetCurrentPageView();
  1878. }
  1879. return true;
  1880. }
  1881. get currentPageLabel() {
  1882. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  1883. }
  1884. set currentPageLabel(val) {
  1885. if (!this.pdfDocument) {
  1886. return;
  1887. }
  1888. let page = val | 0;
  1889. if (this._pageLabels) {
  1890. const i = this._pageLabels.indexOf(val);
  1891. if (i >= 0) {
  1892. page = i + 1;
  1893. }
  1894. }
  1895. if (!this._setCurrentPageNumber(page, true)) {
  1896. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  1897. }
  1898. }
  1899. get currentScale() {
  1900. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  1901. }
  1902. set currentScale(val) {
  1903. if (isNaN(val)) {
  1904. throw new Error("Invalid numeric scale.");
  1905. }
  1906. if (!this.pdfDocument) {
  1907. return;
  1908. }
  1909. this._setScale(val, false);
  1910. }
  1911. get currentScaleValue() {
  1912. return this._currentScaleValue;
  1913. }
  1914. set currentScaleValue(val) {
  1915. if (!this.pdfDocument) {
  1916. return;
  1917. }
  1918. this._setScale(val, false);
  1919. }
  1920. get pagesRotation() {
  1921. return this._pagesRotation;
  1922. }
  1923. set pagesRotation(rotation) {
  1924. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  1925. throw new Error("Invalid pages rotation angle.");
  1926. }
  1927. if (!this.pdfDocument) {
  1928. return;
  1929. }
  1930. rotation %= 360;
  1931. if (rotation < 0) {
  1932. rotation += 360;
  1933. }
  1934. if (this._pagesRotation === rotation) {
  1935. return;
  1936. }
  1937. this._pagesRotation = rotation;
  1938. const pageNumber = this._currentPageNumber;
  1939. const updateArgs = {
  1940. rotation
  1941. };
  1942. for (const pageView of this._pages) {
  1943. pageView.update(updateArgs);
  1944. }
  1945. if (this._currentScaleValue) {
  1946. this._setScale(this._currentScaleValue, true);
  1947. }
  1948. this.eventBus.dispatch("rotationchanging", {
  1949. source: this,
  1950. pagesRotation: rotation,
  1951. pageNumber
  1952. });
  1953. if (this.defaultRenderingQueue) {
  1954. this.update();
  1955. }
  1956. }
  1957. get firstPagePromise() {
  1958. return this.pdfDocument ? this._firstPageCapability.promise : null;
  1959. }
  1960. get onePageRendered() {
  1961. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  1962. }
  1963. get pagesPromise() {
  1964. return this.pdfDocument ? this._pagesCapability.promise : null;
  1965. }
  1966. #initializePermissions(permissions) {
  1967. const params = {
  1968. annotationEditorMode: this.#annotationEditorMode,
  1969. annotationMode: this.#annotationMode,
  1970. textLayerMode: this.textLayerMode
  1971. };
  1972. if (!permissions) {
  1973. return params;
  1974. }
  1975. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  1976. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  1977. }
  1978. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  1979. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  1980. }
  1981. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  1982. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  1983. }
  1984. return params;
  1985. }
  1986. #onePageRenderedOrForceFetch() {
  1987. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  1988. return Promise.resolve();
  1989. }
  1990. const visibilityChangePromise = new Promise(resolve => {
  1991. this.#onVisibilityChange = () => {
  1992. if (document.visibilityState !== "hidden") {
  1993. return;
  1994. }
  1995. resolve();
  1996. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  1997. this.#onVisibilityChange = null;
  1998. };
  1999. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  2000. });
  2001. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  2002. }
  2003. setDocument(pdfDocument) {
  2004. if (this.pdfDocument) {
  2005. this.eventBus.dispatch("pagesdestroy", {
  2006. source: this
  2007. });
  2008. this._cancelRendering();
  2009. this._resetView();
  2010. if (this.findController) {
  2011. this.findController.setDocument(null);
  2012. }
  2013. if (this._scriptingManager) {
  2014. this._scriptingManager.setDocument(null);
  2015. }
  2016. if (this.#annotationEditorUIManager) {
  2017. this.#annotationEditorUIManager.destroy();
  2018. this.#annotationEditorUIManager = null;
  2019. }
  2020. }
  2021. this.pdfDocument = pdfDocument;
  2022. if (!pdfDocument) {
  2023. return;
  2024. }
  2025. const isPureXfa = pdfDocument.isPureXfa;
  2026. const pagesCount = pdfDocument.numPages;
  2027. const firstPagePromise = pdfDocument.getPage(1);
  2028. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  2029. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  2030. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  2031. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  2032. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  2033. this.eventBus.dispatch("scrollmodechanged", {
  2034. source: this,
  2035. mode
  2036. });
  2037. }
  2038. this._pagesCapability.promise.then(() => {
  2039. this.eventBus.dispatch("pagesloaded", {
  2040. source: this,
  2041. pagesCount
  2042. });
  2043. }, () => {});
  2044. this._onBeforeDraw = evt => {
  2045. const pageView = this._pages[evt.pageNumber - 1];
  2046. if (!pageView) {
  2047. return;
  2048. }
  2049. this.#buffer.push(pageView);
  2050. };
  2051. this.eventBus._on("pagerender", this._onBeforeDraw);
  2052. this._onAfterDraw = evt => {
  2053. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  2054. return;
  2055. }
  2056. this._onePageRenderedCapability.resolve({
  2057. timestamp: evt.timestamp
  2058. });
  2059. this.eventBus._off("pagerendered", this._onAfterDraw);
  2060. this._onAfterDraw = null;
  2061. if (this.#onVisibilityChange) {
  2062. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  2063. this.#onVisibilityChange = null;
  2064. }
  2065. };
  2066. this.eventBus._on("pagerendered", this._onAfterDraw);
  2067. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  2068. if (pdfDocument !== this.pdfDocument) {
  2069. return;
  2070. }
  2071. this._firstPageCapability.resolve(firstPdfPage);
  2072. this._optionalContentConfigPromise = optionalContentConfigPromise;
  2073. const {
  2074. annotationEditorMode,
  2075. annotationMode,
  2076. textLayerMode
  2077. } = this.#initializePermissions(permissions);
  2078. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  2079. const mode = annotationEditorMode;
  2080. if (isPureXfa) {
  2081. console.warn("Warning: XFA-editing is not implemented.");
  2082. } else if (isValidAnnotationEditorMode(mode)) {
  2083. this.eventBus.dispatch("annotationeditormodechanged", {
  2084. source: this,
  2085. mode
  2086. });
  2087. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus);
  2088. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  2089. this.#annotationEditorUIManager.updateMode(mode);
  2090. }
  2091. } else {
  2092. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  2093. }
  2094. }
  2095. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  2096. const scale = this.currentScale;
  2097. const viewport = firstPdfPage.getViewport({
  2098. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  2099. });
  2100. const textLayerFactory = textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !isPureXfa ? this : null;
  2101. const annotationLayerFactory = annotationMode !== _pdfjsLib.AnnotationMode.DISABLE ? this : null;
  2102. const xfaLayerFactory = isPureXfa ? this : null;
  2103. const annotationEditorLayerFactory = this.#annotationEditorUIManager ? this : null;
  2104. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  2105. const pageView = new _pdf_page_view.PDFPageView({
  2106. container: viewerElement,
  2107. eventBus: this.eventBus,
  2108. id: pageNum,
  2109. scale,
  2110. defaultViewport: viewport.clone(),
  2111. optionalContentConfigPromise,
  2112. renderingQueue: this.renderingQueue,
  2113. textLayerFactory,
  2114. textLayerMode,
  2115. annotationLayerFactory,
  2116. annotationMode,
  2117. xfaLayerFactory,
  2118. annotationEditorLayerFactory,
  2119. textHighlighterFactory: this,
  2120. structTreeLayerFactory: this,
  2121. imageResourcesPath: this.imageResourcesPath,
  2122. renderer: this.renderer,
  2123. useOnlyCssZoom: this.useOnlyCssZoom,
  2124. maxCanvasPixels: this.maxCanvasPixels,
  2125. pageColors: this.pageColors,
  2126. l10n: this.l10n
  2127. });
  2128. this._pages.push(pageView);
  2129. }
  2130. const firstPageView = this._pages[0];
  2131. if (firstPageView) {
  2132. firstPageView.setPdfPage(firstPdfPage);
  2133. this.linkService.cachePageRef(1, firstPdfPage.ref);
  2134. }
  2135. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  2136. this.#ensurePageViewVisible();
  2137. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  2138. this._updateSpreadMode();
  2139. }
  2140. this.#onePageRenderedOrForceFetch().then(async () => {
  2141. if (this.findController) {
  2142. this.findController.setDocument(pdfDocument);
  2143. }
  2144. if (this._scriptingManager) {
  2145. this._scriptingManager.setDocument(pdfDocument);
  2146. }
  2147. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  2148. this._pagesCapability.resolve();
  2149. return;
  2150. }
  2151. let getPagesLeft = pagesCount - 1;
  2152. if (getPagesLeft <= 0) {
  2153. this._pagesCapability.resolve();
  2154. return;
  2155. }
  2156. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  2157. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  2158. const pageView = this._pages[pageNum - 1];
  2159. if (!pageView.pdfPage) {
  2160. pageView.setPdfPage(pdfPage);
  2161. }
  2162. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  2163. if (--getPagesLeft === 0) {
  2164. this._pagesCapability.resolve();
  2165. }
  2166. }, reason => {
  2167. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  2168. if (--getPagesLeft === 0) {
  2169. this._pagesCapability.resolve();
  2170. }
  2171. });
  2172. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  2173. await promise;
  2174. }
  2175. }
  2176. });
  2177. this.eventBus.dispatch("pagesinit", {
  2178. source: this
  2179. });
  2180. pdfDocument.getMetadata().then(({
  2181. info
  2182. }) => {
  2183. if (pdfDocument !== this.pdfDocument) {
  2184. return;
  2185. }
  2186. if (info.Language) {
  2187. this.viewer.lang = info.Language;
  2188. }
  2189. });
  2190. if (this.defaultRenderingQueue) {
  2191. this.update();
  2192. }
  2193. }).catch(reason => {
  2194. console.error("Unable to initialize viewer", reason);
  2195. this._pagesCapability.reject(reason);
  2196. });
  2197. }
  2198. setPageLabels(labels) {
  2199. if (!this.pdfDocument) {
  2200. return;
  2201. }
  2202. if (!labels) {
  2203. this._pageLabels = null;
  2204. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  2205. this._pageLabels = null;
  2206. console.error(`setPageLabels: Invalid page labels.`);
  2207. } else {
  2208. this._pageLabels = labels;
  2209. }
  2210. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  2211. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  2212. }
  2213. }
  2214. _resetView() {
  2215. this._pages = [];
  2216. this._currentPageNumber = 1;
  2217. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  2218. this._currentScaleValue = null;
  2219. this._pageLabels = null;
  2220. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  2221. this._location = null;
  2222. this._pagesRotation = 0;
  2223. this._optionalContentConfigPromise = null;
  2224. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  2225. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  2226. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  2227. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  2228. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  2229. this._spreadMode = _ui_utils.SpreadMode.NONE;
  2230. this.#scrollModePageState = {
  2231. previousPageNumber: 1,
  2232. scrollDown: true,
  2233. pages: []
  2234. };
  2235. if (this._onBeforeDraw) {
  2236. this.eventBus._off("pagerender", this._onBeforeDraw);
  2237. this._onBeforeDraw = null;
  2238. }
  2239. if (this._onAfterDraw) {
  2240. this.eventBus._off("pagerendered", this._onAfterDraw);
  2241. this._onAfterDraw = null;
  2242. }
  2243. if (this.#onVisibilityChange) {
  2244. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  2245. this.#onVisibilityChange = null;
  2246. }
  2247. this.viewer.textContent = "";
  2248. this._updateScrollMode();
  2249. this.viewer.removeAttribute("lang");
  2250. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  2251. }
  2252. #ensurePageViewVisible() {
  2253. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  2254. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  2255. }
  2256. const pageNumber = this._currentPageNumber,
  2257. state = this.#scrollModePageState,
  2258. viewer = this.viewer;
  2259. viewer.textContent = "";
  2260. state.pages.length = 0;
  2261. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  2262. const pageView = this._pages[pageNumber - 1];
  2263. viewer.append(pageView.div);
  2264. state.pages.push(pageView);
  2265. } else {
  2266. const pageIndexSet = new Set(),
  2267. parity = this._spreadMode - 1;
  2268. if (parity === -1) {
  2269. pageIndexSet.add(pageNumber - 1);
  2270. } else if (pageNumber % 2 !== parity) {
  2271. pageIndexSet.add(pageNumber - 1);
  2272. pageIndexSet.add(pageNumber);
  2273. } else {
  2274. pageIndexSet.add(pageNumber - 2);
  2275. pageIndexSet.add(pageNumber - 1);
  2276. }
  2277. const spread = document.createElement("div");
  2278. spread.className = "spread";
  2279. if (this.isInPresentationMode) {
  2280. const dummyPage = document.createElement("div");
  2281. dummyPage.className = "dummyPage";
  2282. spread.append(dummyPage);
  2283. }
  2284. for (const i of pageIndexSet) {
  2285. const pageView = this._pages[i];
  2286. if (!pageView) {
  2287. continue;
  2288. }
  2289. spread.append(pageView.div);
  2290. state.pages.push(pageView);
  2291. }
  2292. viewer.append(spread);
  2293. }
  2294. state.scrollDown = pageNumber >= state.previousPageNumber;
  2295. state.previousPageNumber = pageNumber;
  2296. }
  2297. _scrollUpdate() {
  2298. if (this.pagesCount === 0) {
  2299. return;
  2300. }
  2301. this.update();
  2302. }
  2303. #scrollIntoView(pageView, pageSpot = null) {
  2304. const {
  2305. div,
  2306. id
  2307. } = pageView;
  2308. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  2309. this._setCurrentPageNumber(id);
  2310. this.#ensurePageViewVisible();
  2311. this.update();
  2312. }
  2313. if (!pageSpot && !this.isInPresentationMode) {
  2314. const left = div.offsetLeft + div.clientLeft,
  2315. right = left + div.clientWidth;
  2316. const {
  2317. scrollLeft,
  2318. clientWidth
  2319. } = this.container;
  2320. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  2321. pageSpot = {
  2322. left: 0,
  2323. top: 0
  2324. };
  2325. }
  2326. }
  2327. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  2328. }
  2329. #isSameScale(newScale) {
  2330. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  2331. }
  2332. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  2333. this._currentScaleValue = newValue.toString();
  2334. if (this.#isSameScale(newScale)) {
  2335. if (preset) {
  2336. this.eventBus.dispatch("scalechanging", {
  2337. source: this,
  2338. scale: newScale,
  2339. presetValue: newValue
  2340. });
  2341. }
  2342. return;
  2343. }
  2344. _ui_utils.docStyle.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  2345. const updateArgs = {
  2346. scale: newScale
  2347. };
  2348. for (const pageView of this._pages) {
  2349. pageView.update(updateArgs);
  2350. }
  2351. this._currentScale = newScale;
  2352. if (!noScroll) {
  2353. let page = this._currentPageNumber,
  2354. dest;
  2355. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  2356. page = this._location.pageNumber;
  2357. dest = [null, {
  2358. name: "XYZ"
  2359. }, this._location.left, this._location.top, null];
  2360. }
  2361. this.scrollPageIntoView({
  2362. pageNumber: page,
  2363. destArray: dest,
  2364. allowNegativeOffset: true
  2365. });
  2366. }
  2367. this.eventBus.dispatch("scalechanging", {
  2368. source: this,
  2369. scale: newScale,
  2370. presetValue: preset ? newValue : undefined
  2371. });
  2372. if (this.defaultRenderingQueue) {
  2373. this.update();
  2374. }
  2375. this.updateContainerHeightCss();
  2376. }
  2377. get _pageWidthScaleFactor() {
  2378. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  2379. return 2;
  2380. }
  2381. return 1;
  2382. }
  2383. _setScale(value, noScroll = false) {
  2384. let scale = parseFloat(value);
  2385. if (scale > 0) {
  2386. this._setScaleUpdatePages(scale, value, noScroll, false);
  2387. } else {
  2388. const currentPage = this._pages[this._currentPageNumber - 1];
  2389. if (!currentPage) {
  2390. return;
  2391. }
  2392. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  2393. vPadding = _ui_utils.VERTICAL_PADDING;
  2394. if (this.isInPresentationMode) {
  2395. hPadding = vPadding = 4;
  2396. } else if (this.removePageBorders) {
  2397. hPadding = vPadding = 0;
  2398. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  2399. [hPadding, vPadding] = [vPadding, hPadding];
  2400. }
  2401. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  2402. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  2403. switch (value) {
  2404. case "page-actual":
  2405. scale = 1;
  2406. break;
  2407. case "page-width":
  2408. scale = pageWidthScale;
  2409. break;
  2410. case "page-height":
  2411. scale = pageHeightScale;
  2412. break;
  2413. case "page-fit":
  2414. scale = Math.min(pageWidthScale, pageHeightScale);
  2415. break;
  2416. case "auto":
  2417. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  2418. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  2419. break;
  2420. default:
  2421. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  2422. return;
  2423. }
  2424. this._setScaleUpdatePages(scale, value, noScroll, true);
  2425. }
  2426. }
  2427. #resetCurrentPageView() {
  2428. const pageView = this._pages[this._currentPageNumber - 1];
  2429. if (this.isInPresentationMode) {
  2430. this._setScale(this._currentScaleValue, true);
  2431. }
  2432. this.#scrollIntoView(pageView);
  2433. }
  2434. pageLabelToPageNumber(label) {
  2435. if (!this._pageLabels) {
  2436. return null;
  2437. }
  2438. const i = this._pageLabels.indexOf(label);
  2439. if (i < 0) {
  2440. return null;
  2441. }
  2442. return i + 1;
  2443. }
  2444. scrollPageIntoView({
  2445. pageNumber,
  2446. destArray = null,
  2447. allowNegativeOffset = false,
  2448. ignoreDestinationZoom = false
  2449. }) {
  2450. if (!this.pdfDocument) {
  2451. return;
  2452. }
  2453. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  2454. if (!pageView) {
  2455. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  2456. return;
  2457. }
  2458. if (this.isInPresentationMode || !destArray) {
  2459. this._setCurrentPageNumber(pageNumber, true);
  2460. return;
  2461. }
  2462. let x = 0,
  2463. y = 0;
  2464. let width = 0,
  2465. height = 0,
  2466. widthScale,
  2467. heightScale;
  2468. const changeOrientation = pageView.rotation % 180 !== 0;
  2469. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  2470. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  2471. let scale = 0;
  2472. switch (destArray[1].name) {
  2473. case "XYZ":
  2474. x = destArray[2];
  2475. y = destArray[3];
  2476. scale = destArray[4];
  2477. x = x !== null ? x : 0;
  2478. y = y !== null ? y : pageHeight;
  2479. break;
  2480. case "Fit":
  2481. case "FitB":
  2482. scale = "page-fit";
  2483. break;
  2484. case "FitH":
  2485. case "FitBH":
  2486. y = destArray[2];
  2487. scale = "page-width";
  2488. if (y === null && this._location) {
  2489. x = this._location.left;
  2490. y = this._location.top;
  2491. } else if (typeof y !== "number" || y < 0) {
  2492. y = pageHeight;
  2493. }
  2494. break;
  2495. case "FitV":
  2496. case "FitBV":
  2497. x = destArray[2];
  2498. width = pageWidth;
  2499. height = pageHeight;
  2500. scale = "page-height";
  2501. break;
  2502. case "FitR":
  2503. x = destArray[2];
  2504. y = destArray[3];
  2505. width = destArray[4] - x;
  2506. height = destArray[5] - y;
  2507. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  2508. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  2509. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  2510. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  2511. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  2512. break;
  2513. default:
  2514. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  2515. return;
  2516. }
  2517. if (!ignoreDestinationZoom) {
  2518. if (scale && scale !== this._currentScale) {
  2519. this.currentScaleValue = scale;
  2520. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  2521. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  2522. }
  2523. }
  2524. if (scale === "page-fit" && !destArray[4]) {
  2525. this.#scrollIntoView(pageView);
  2526. return;
  2527. }
  2528. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  2529. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  2530. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  2531. if (!allowNegativeOffset) {
  2532. left = Math.max(left, 0);
  2533. top = Math.max(top, 0);
  2534. }
  2535. this.#scrollIntoView(pageView, {
  2536. left,
  2537. top
  2538. });
  2539. }
  2540. _updateLocation(firstPage) {
  2541. const currentScale = this._currentScale;
  2542. const currentScaleValue = this._currentScaleValue;
  2543. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  2544. const pageNumber = firstPage.id;
  2545. const currentPageView = this._pages[pageNumber - 1];
  2546. const container = this.container;
  2547. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  2548. const intLeft = Math.round(topLeft[0]);
  2549. const intTop = Math.round(topLeft[1]);
  2550. let pdfOpenParams = `#page=${pageNumber}`;
  2551. if (!this.isInPresentationMode) {
  2552. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  2553. }
  2554. this._location = {
  2555. pageNumber,
  2556. scale: normalizedScaleValue,
  2557. top: intTop,
  2558. left: intLeft,
  2559. rotation: this._pagesRotation,
  2560. pdfOpenParams
  2561. };
  2562. }
  2563. update() {
  2564. const visible = this._getVisiblePages();
  2565. const visiblePages = visible.views,
  2566. numVisiblePages = visiblePages.length;
  2567. if (numVisiblePages === 0) {
  2568. return;
  2569. }
  2570. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  2571. this.#buffer.resize(newCacheSize, visible.ids);
  2572. this.renderingQueue.renderHighestPriority(visible);
  2573. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  2574. const currentId = this._currentPageNumber;
  2575. let stillFullyVisible = false;
  2576. for (const page of visiblePages) {
  2577. if (page.percent < 100) {
  2578. break;
  2579. }
  2580. if (page.id === currentId && isSimpleLayout) {
  2581. stillFullyVisible = true;
  2582. break;
  2583. }
  2584. }
  2585. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  2586. this._updateLocation(visible.first);
  2587. this.eventBus.dispatch("updateviewarea", {
  2588. source: this,
  2589. location: this._location
  2590. });
  2591. }
  2592. containsElement(element) {
  2593. return this.container.contains(element);
  2594. }
  2595. focus() {
  2596. this.container.focus();
  2597. }
  2598. get _isContainerRtl() {
  2599. return getComputedStyle(this.container).direction === "rtl";
  2600. }
  2601. get isInPresentationMode() {
  2602. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  2603. }
  2604. get isChangingPresentationMode() {
  2605. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  2606. }
  2607. get isHorizontalScrollbarEnabled() {
  2608. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  2609. }
  2610. get isVerticalScrollbarEnabled() {
  2611. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  2612. }
  2613. _getVisiblePages() {
  2614. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  2615. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  2616. rtl = horizontal && this._isContainerRtl;
  2617. return (0, _ui_utils.getVisibleElements)({
  2618. scrollEl: this.container,
  2619. views,
  2620. sortByVisibility: true,
  2621. horizontal,
  2622. rtl
  2623. });
  2624. }
  2625. isPageVisible(pageNumber) {
  2626. if (!this.pdfDocument) {
  2627. return false;
  2628. }
  2629. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  2630. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  2631. return false;
  2632. }
  2633. return this._getVisiblePages().ids.has(pageNumber);
  2634. }
  2635. isPageCached(pageNumber) {
  2636. if (!this.pdfDocument) {
  2637. return false;
  2638. }
  2639. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  2640. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  2641. return false;
  2642. }
  2643. const pageView = this._pages[pageNumber - 1];
  2644. return this.#buffer.has(pageView);
  2645. }
  2646. cleanup() {
  2647. for (const pageView of this._pages) {
  2648. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  2649. pageView.reset();
  2650. }
  2651. }
  2652. }
  2653. _cancelRendering() {
  2654. for (const pageView of this._pages) {
  2655. pageView.cancelRendering();
  2656. }
  2657. }
  2658. async #ensurePdfPageLoaded(pageView) {
  2659. if (pageView.pdfPage) {
  2660. return pageView.pdfPage;
  2661. }
  2662. try {
  2663. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  2664. if (!pageView.pdfPage) {
  2665. pageView.setPdfPage(pdfPage);
  2666. }
  2667. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  2668. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  2669. }
  2670. return pdfPage;
  2671. } catch (reason) {
  2672. console.error("Unable to get page for page view", reason);
  2673. return null;
  2674. }
  2675. }
  2676. #getScrollAhead(visible) {
  2677. if (visible.first?.id === 1) {
  2678. return true;
  2679. } else if (visible.last?.id === this.pagesCount) {
  2680. return false;
  2681. }
  2682. switch (this._scrollMode) {
  2683. case _ui_utils.ScrollMode.PAGE:
  2684. return this.#scrollModePageState.scrollDown;
  2685. case _ui_utils.ScrollMode.HORIZONTAL:
  2686. return this.scroll.right;
  2687. }
  2688. return this.scroll.down;
  2689. }
  2690. #toggleLoadingIconSpinner(visibleIds) {
  2691. for (const id of visibleIds) {
  2692. const pageView = this._pages[id - 1];
  2693. pageView?.toggleLoadingIconSpinner(true);
  2694. }
  2695. for (const pageView of this.#buffer) {
  2696. if (visibleIds.has(pageView.id)) {
  2697. continue;
  2698. }
  2699. pageView.toggleLoadingIconSpinner(false);
  2700. }
  2701. }
  2702. forceRendering(currentlyVisiblePages) {
  2703. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  2704. const scrollAhead = this.#getScrollAhead(visiblePages);
  2705. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  2706. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  2707. this.#toggleLoadingIconSpinner(visiblePages.ids);
  2708. if (pageView) {
  2709. this.#ensurePdfPageLoaded(pageView).then(() => {
  2710. this.renderingQueue.renderView(pageView);
  2711. });
  2712. return true;
  2713. }
  2714. return false;
  2715. }
  2716. createTextLayerBuilder({
  2717. textLayerDiv,
  2718. pageIndex,
  2719. viewport,
  2720. enhanceTextSelection = false,
  2721. eventBus,
  2722. highlighter
  2723. }) {
  2724. return new _text_layer_builder.TextLayerBuilder({
  2725. textLayerDiv,
  2726. eventBus,
  2727. pageIndex,
  2728. viewport,
  2729. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection,
  2730. highlighter
  2731. });
  2732. }
  2733. createTextHighlighter({
  2734. pageIndex,
  2735. eventBus
  2736. }) {
  2737. return new _text_highlighter.TextHighlighter({
  2738. eventBus,
  2739. pageIndex,
  2740. findController: this.isInPresentationMode ? null : this.findController
  2741. });
  2742. }
  2743. createAnnotationLayerBuilder({
  2744. pageDiv,
  2745. pdfPage,
  2746. annotationStorage = this.pdfDocument?.annotationStorage,
  2747. imageResourcesPath = "",
  2748. renderForms = true,
  2749. l10n = _l10n_utils.NullL10n,
  2750. enableScripting = this.enableScripting,
  2751. hasJSActionsPromise = this.pdfDocument?.hasJSActions(),
  2752. mouseState = this._scriptingManager?.mouseState,
  2753. fieldObjectsPromise = this.pdfDocument?.getFieldObjects(),
  2754. annotationCanvasMap = null
  2755. }) {
  2756. return new _annotation_layer_builder.AnnotationLayerBuilder({
  2757. pageDiv,
  2758. pdfPage,
  2759. annotationStorage,
  2760. imageResourcesPath,
  2761. renderForms,
  2762. linkService: this.linkService,
  2763. downloadManager: this.downloadManager,
  2764. l10n,
  2765. enableScripting,
  2766. hasJSActionsPromise,
  2767. mouseState,
  2768. fieldObjectsPromise,
  2769. annotationCanvasMap
  2770. });
  2771. }
  2772. createAnnotationEditorLayerBuilder({
  2773. uiManager = this.#annotationEditorUIManager,
  2774. pageDiv,
  2775. pdfPage,
  2776. l10n,
  2777. annotationStorage = this.pdfDocument?.annotationStorage
  2778. }) {
  2779. return new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  2780. uiManager,
  2781. pageDiv,
  2782. pdfPage,
  2783. annotationStorage,
  2784. l10n
  2785. });
  2786. }
  2787. createXfaLayerBuilder({
  2788. pageDiv,
  2789. pdfPage,
  2790. annotationStorage = this.pdfDocument?.annotationStorage
  2791. }) {
  2792. return new _xfa_layer_builder.XfaLayerBuilder({
  2793. pageDiv,
  2794. pdfPage,
  2795. annotationStorage,
  2796. linkService: this.linkService
  2797. });
  2798. }
  2799. createStructTreeLayerBuilder({
  2800. pdfPage
  2801. }) {
  2802. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  2803. pdfPage
  2804. });
  2805. }
  2806. get hasEqualPageSizes() {
  2807. const firstPageView = this._pages[0];
  2808. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  2809. const pageView = this._pages[i];
  2810. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  2811. return false;
  2812. }
  2813. }
  2814. return true;
  2815. }
  2816. getPagesOverview() {
  2817. return this._pages.map(pageView => {
  2818. const viewport = pageView.pdfPage.getViewport({
  2819. scale: 1
  2820. });
  2821. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  2822. return {
  2823. width: viewport.width,
  2824. height: viewport.height,
  2825. rotation: viewport.rotation
  2826. };
  2827. }
  2828. return {
  2829. width: viewport.height,
  2830. height: viewport.width,
  2831. rotation: (viewport.rotation - 90) % 360
  2832. };
  2833. });
  2834. }
  2835. get optionalContentConfigPromise() {
  2836. if (!this.pdfDocument) {
  2837. return Promise.resolve(null);
  2838. }
  2839. if (!this._optionalContentConfigPromise) {
  2840. console.error("optionalContentConfigPromise: Not initialized yet.");
  2841. return this.pdfDocument.getOptionalContentConfig();
  2842. }
  2843. return this._optionalContentConfigPromise;
  2844. }
  2845. set optionalContentConfigPromise(promise) {
  2846. if (!(promise instanceof Promise)) {
  2847. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  2848. }
  2849. if (!this.pdfDocument) {
  2850. return;
  2851. }
  2852. if (!this._optionalContentConfigPromise) {
  2853. return;
  2854. }
  2855. this._optionalContentConfigPromise = promise;
  2856. const updateArgs = {
  2857. optionalContentConfigPromise: promise
  2858. };
  2859. for (const pageView of this._pages) {
  2860. pageView.update(updateArgs);
  2861. }
  2862. this.update();
  2863. this.eventBus.dispatch("optionalcontentconfigchanged", {
  2864. source: this,
  2865. promise
  2866. });
  2867. }
  2868. get scrollMode() {
  2869. return this._scrollMode;
  2870. }
  2871. set scrollMode(mode) {
  2872. if (this._scrollMode === mode) {
  2873. return;
  2874. }
  2875. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  2876. throw new Error(`Invalid scroll mode: ${mode}`);
  2877. }
  2878. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  2879. return;
  2880. }
  2881. this._previousScrollMode = this._scrollMode;
  2882. this._scrollMode = mode;
  2883. this.eventBus.dispatch("scrollmodechanged", {
  2884. source: this,
  2885. mode
  2886. });
  2887. this._updateScrollMode(this._currentPageNumber);
  2888. }
  2889. _updateScrollMode(pageNumber = null) {
  2890. const scrollMode = this._scrollMode,
  2891. viewer = this.viewer;
  2892. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  2893. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  2894. if (!this.pdfDocument || !pageNumber) {
  2895. return;
  2896. }
  2897. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  2898. this.#ensurePageViewVisible();
  2899. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  2900. this._updateSpreadMode();
  2901. }
  2902. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  2903. this._setScale(this._currentScaleValue, true);
  2904. }
  2905. this._setCurrentPageNumber(pageNumber, true);
  2906. this.update();
  2907. }
  2908. get spreadMode() {
  2909. return this._spreadMode;
  2910. }
  2911. set spreadMode(mode) {
  2912. if (this._spreadMode === mode) {
  2913. return;
  2914. }
  2915. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  2916. throw new Error(`Invalid spread mode: ${mode}`);
  2917. }
  2918. this._spreadMode = mode;
  2919. this.eventBus.dispatch("spreadmodechanged", {
  2920. source: this,
  2921. mode
  2922. });
  2923. this._updateSpreadMode(this._currentPageNumber);
  2924. }
  2925. _updateSpreadMode(pageNumber = null) {
  2926. if (!this.pdfDocument) {
  2927. return;
  2928. }
  2929. const viewer = this.viewer,
  2930. pages = this._pages;
  2931. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  2932. this.#ensurePageViewVisible();
  2933. } else {
  2934. viewer.textContent = "";
  2935. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  2936. for (const pageView of this._pages) {
  2937. viewer.append(pageView.div);
  2938. }
  2939. } else {
  2940. const parity = this._spreadMode - 1;
  2941. let spread = null;
  2942. for (let i = 0, ii = pages.length; i < ii; ++i) {
  2943. if (spread === null) {
  2944. spread = document.createElement("div");
  2945. spread.className = "spread";
  2946. viewer.append(spread);
  2947. } else if (i % 2 === parity) {
  2948. spread = spread.cloneNode(false);
  2949. viewer.append(spread);
  2950. }
  2951. spread.append(pages[i].div);
  2952. }
  2953. }
  2954. }
  2955. if (!pageNumber) {
  2956. return;
  2957. }
  2958. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  2959. this._setScale(this._currentScaleValue, true);
  2960. }
  2961. this._setCurrentPageNumber(pageNumber, true);
  2962. this.update();
  2963. }
  2964. _getPageAdvance(currentPageNumber, previous = false) {
  2965. switch (this._scrollMode) {
  2966. case _ui_utils.ScrollMode.WRAPPED:
  2967. {
  2968. const {
  2969. views
  2970. } = this._getVisiblePages(),
  2971. pageLayout = new Map();
  2972. for (const {
  2973. id,
  2974. y,
  2975. percent,
  2976. widthPercent
  2977. } of views) {
  2978. if (percent === 0 || widthPercent < 100) {
  2979. continue;
  2980. }
  2981. let yArray = pageLayout.get(y);
  2982. if (!yArray) {
  2983. pageLayout.set(y, yArray ||= []);
  2984. }
  2985. yArray.push(id);
  2986. }
  2987. for (const yArray of pageLayout.values()) {
  2988. const currentIndex = yArray.indexOf(currentPageNumber);
  2989. if (currentIndex === -1) {
  2990. continue;
  2991. }
  2992. const numPages = yArray.length;
  2993. if (numPages === 1) {
  2994. break;
  2995. }
  2996. if (previous) {
  2997. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  2998. const currentId = yArray[i],
  2999. expectedId = yArray[i + 1] - 1;
  3000. if (currentId < expectedId) {
  3001. return currentPageNumber - expectedId;
  3002. }
  3003. }
  3004. } else {
  3005. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  3006. const currentId = yArray[i],
  3007. expectedId = yArray[i - 1] + 1;
  3008. if (currentId > expectedId) {
  3009. return expectedId - currentPageNumber;
  3010. }
  3011. }
  3012. }
  3013. if (previous) {
  3014. const firstId = yArray[0];
  3015. if (firstId < currentPageNumber) {
  3016. return currentPageNumber - firstId + 1;
  3017. }
  3018. } else {
  3019. const lastId = yArray[numPages - 1];
  3020. if (lastId > currentPageNumber) {
  3021. return lastId - currentPageNumber + 1;
  3022. }
  3023. }
  3024. break;
  3025. }
  3026. break;
  3027. }
  3028. case _ui_utils.ScrollMode.HORIZONTAL:
  3029. {
  3030. break;
  3031. }
  3032. case _ui_utils.ScrollMode.PAGE:
  3033. case _ui_utils.ScrollMode.VERTICAL:
  3034. {
  3035. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  3036. break;
  3037. }
  3038. const parity = this._spreadMode - 1;
  3039. if (previous && currentPageNumber % 2 !== parity) {
  3040. break;
  3041. } else if (!previous && currentPageNumber % 2 === parity) {
  3042. break;
  3043. }
  3044. const {
  3045. views
  3046. } = this._getVisiblePages(),
  3047. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  3048. for (const {
  3049. id,
  3050. percent,
  3051. widthPercent
  3052. } of views) {
  3053. if (id !== expectedId) {
  3054. continue;
  3055. }
  3056. if (percent > 0 && widthPercent === 100) {
  3057. return 2;
  3058. }
  3059. break;
  3060. }
  3061. break;
  3062. }
  3063. }
  3064. return 1;
  3065. }
  3066. nextPage() {
  3067. const currentPageNumber = this._currentPageNumber,
  3068. pagesCount = this.pagesCount;
  3069. if (currentPageNumber >= pagesCount) {
  3070. return false;
  3071. }
  3072. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  3073. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  3074. return true;
  3075. }
  3076. previousPage() {
  3077. const currentPageNumber = this._currentPageNumber;
  3078. if (currentPageNumber <= 1) {
  3079. return false;
  3080. }
  3081. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  3082. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  3083. return true;
  3084. }
  3085. increaseScale(steps = 1) {
  3086. let newScale = this._currentScale;
  3087. do {
  3088. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  3089. newScale = Math.ceil(newScale * 10) / 10;
  3090. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  3091. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  3092. this.currentScaleValue = newScale;
  3093. }
  3094. decreaseScale(steps = 1) {
  3095. let newScale = this._currentScale;
  3096. do {
  3097. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  3098. newScale = Math.floor(newScale * 10) / 10;
  3099. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  3100. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  3101. this.currentScaleValue = newScale;
  3102. }
  3103. updateContainerHeightCss() {
  3104. const height = this.container.clientHeight;
  3105. if (height !== this.#previousContainerHeight) {
  3106. this.#previousContainerHeight = height;
  3107. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  3108. }
  3109. }
  3110. get annotationEditorMode() {
  3111. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  3112. }
  3113. set annotationEditorMode(mode) {
  3114. if (!this.#annotationEditorUIManager) {
  3115. throw new Error(`The AnnotationEditor is not enabled.`);
  3116. }
  3117. if (this.#annotationEditorMode === mode) {
  3118. return;
  3119. }
  3120. if (!isValidAnnotationEditorMode(mode)) {
  3121. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  3122. }
  3123. if (!this.pdfDocument) {
  3124. return;
  3125. }
  3126. this.#annotationEditorMode = mode;
  3127. this.eventBus.dispatch("annotationeditormodechanged", {
  3128. source: this,
  3129. mode
  3130. });
  3131. this.#annotationEditorUIManager.updateMode(mode);
  3132. }
  3133. set annotationEditorParams({
  3134. type,
  3135. value
  3136. }) {
  3137. if (!this.#annotationEditorUIManager) {
  3138. throw new Error(`The AnnotationEditor is not enabled.`);
  3139. }
  3140. this.#annotationEditorUIManager.updateParams(type, value);
  3141. }
  3142. }
  3143. exports.BaseViewer = BaseViewer;
  3144. /***/ }),
  3145. /* 13 */
  3146. /***/ ((__unused_webpack_module, exports) => {
  3147. Object.defineProperty(exports, "__esModule", ({
  3148. value: true
  3149. }));
  3150. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  3151. const compatibilityParams = Object.create(null);
  3152. exports.compatibilityParams = compatibilityParams;
  3153. {
  3154. const userAgent = navigator.userAgent || "";
  3155. const platform = navigator.platform || "";
  3156. const maxTouchPoints = navigator.maxTouchPoints || 1;
  3157. const isAndroid = /Android/.test(userAgent);
  3158. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  3159. (function checkCanvasSizeLimitation() {
  3160. if (isIOS || isAndroid) {
  3161. compatibilityParams.maxCanvasPixels = 5242880;
  3162. }
  3163. })();
  3164. (function checkResizeObserver() {
  3165. if (typeof ResizeObserver === "undefined") {
  3166. compatibilityParams.annotationEditorMode = -1;
  3167. }
  3168. })();
  3169. }
  3170. const OptionKind = {
  3171. VIEWER: 0x02,
  3172. API: 0x04,
  3173. WORKER: 0x08,
  3174. PREFERENCE: 0x80
  3175. };
  3176. exports.OptionKind = OptionKind;
  3177. const defaultOptions = {
  3178. annotationEditorMode: {
  3179. value: -1,
  3180. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3181. },
  3182. annotationMode: {
  3183. value: 2,
  3184. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3185. },
  3186. cursorToolOnLoad: {
  3187. value: 0,
  3188. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3189. },
  3190. defaultZoomValue: {
  3191. value: "",
  3192. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3193. },
  3194. disableHistory: {
  3195. value: false,
  3196. kind: OptionKind.VIEWER
  3197. },
  3198. disablePageLabels: {
  3199. value: false,
  3200. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3201. },
  3202. enablePermissions: {
  3203. value: false,
  3204. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3205. },
  3206. enablePrintAutoRotate: {
  3207. value: true,
  3208. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3209. },
  3210. enableScripting: {
  3211. value: true,
  3212. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3213. },
  3214. externalLinkRel: {
  3215. value: "noopener noreferrer nofollow",
  3216. kind: OptionKind.VIEWER
  3217. },
  3218. externalLinkTarget: {
  3219. value: 0,
  3220. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3221. },
  3222. historyUpdateUrl: {
  3223. value: false,
  3224. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3225. },
  3226. ignoreDestinationZoom: {
  3227. value: false,
  3228. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3229. },
  3230. imageResourcesPath: {
  3231. value: "./images/",
  3232. kind: OptionKind.VIEWER
  3233. },
  3234. maxCanvasPixels: {
  3235. value: 16777216,
  3236. kind: OptionKind.VIEWER
  3237. },
  3238. forcePageColors: {
  3239. value: false,
  3240. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3241. },
  3242. pageColorsBackground: {
  3243. value: "Canvas",
  3244. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3245. },
  3246. pageColorsForeground: {
  3247. value: "CanvasText",
  3248. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3249. },
  3250. pdfBugEnabled: {
  3251. value: false,
  3252. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3253. },
  3254. printResolution: {
  3255. value: 150,
  3256. kind: OptionKind.VIEWER
  3257. },
  3258. sidebarViewOnLoad: {
  3259. value: -1,
  3260. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3261. },
  3262. scrollModeOnLoad: {
  3263. value: -1,
  3264. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3265. },
  3266. spreadModeOnLoad: {
  3267. value: -1,
  3268. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3269. },
  3270. textLayerMode: {
  3271. value: 1,
  3272. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3273. },
  3274. useOnlyCssZoom: {
  3275. value: false,
  3276. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3277. },
  3278. viewerCssTheme: {
  3279. value: 0,
  3280. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3281. },
  3282. viewOnLoad: {
  3283. value: 0,
  3284. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3285. },
  3286. cMapPacked: {
  3287. value: true,
  3288. kind: OptionKind.API
  3289. },
  3290. cMapUrl: {
  3291. value: "../web/cmaps/",
  3292. kind: OptionKind.API
  3293. },
  3294. disableAutoFetch: {
  3295. value: false,
  3296. kind: OptionKind.API + OptionKind.PREFERENCE
  3297. },
  3298. disableFontFace: {
  3299. value: false,
  3300. kind: OptionKind.API + OptionKind.PREFERENCE
  3301. },
  3302. disableRange: {
  3303. value: false,
  3304. kind: OptionKind.API + OptionKind.PREFERENCE
  3305. },
  3306. disableStream: {
  3307. value: false,
  3308. kind: OptionKind.API + OptionKind.PREFERENCE
  3309. },
  3310. docBaseUrl: {
  3311. value: "",
  3312. kind: OptionKind.API
  3313. },
  3314. enableXfa: {
  3315. value: true,
  3316. kind: OptionKind.API + OptionKind.PREFERENCE
  3317. },
  3318. fontExtraProperties: {
  3319. value: false,
  3320. kind: OptionKind.API
  3321. },
  3322. isEvalSupported: {
  3323. value: true,
  3324. kind: OptionKind.API
  3325. },
  3326. maxImageSize: {
  3327. value: -1,
  3328. kind: OptionKind.API
  3329. },
  3330. pdfBug: {
  3331. value: false,
  3332. kind: OptionKind.API
  3333. },
  3334. standardFontDataUrl: {
  3335. value: "../web/standard_fonts/",
  3336. kind: OptionKind.API
  3337. },
  3338. verbosity: {
  3339. value: 1,
  3340. kind: OptionKind.API
  3341. },
  3342. workerPort: {
  3343. value: null,
  3344. kind: OptionKind.WORKER
  3345. },
  3346. workerSrc: {
  3347. value: "../build/pdf.worker.js",
  3348. kind: OptionKind.WORKER
  3349. }
  3350. };
  3351. {
  3352. defaultOptions.defaultUrl = {
  3353. value: "compressed.tracemonkey-pldi-09.pdf",
  3354. kind: OptionKind.VIEWER
  3355. };
  3356. defaultOptions.disablePreferences = {
  3357. value: false,
  3358. kind: OptionKind.VIEWER
  3359. };
  3360. defaultOptions.locale = {
  3361. value: navigator.language || "en-US",
  3362. kind: OptionKind.VIEWER
  3363. };
  3364. defaultOptions.renderer = {
  3365. value: "canvas",
  3366. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3367. };
  3368. defaultOptions.sandboxBundleSrc = {
  3369. value: "../build/pdf.sandbox.js",
  3370. kind: OptionKind.VIEWER
  3371. };
  3372. }
  3373. const userOptions = Object.create(null);
  3374. class AppOptions {
  3375. constructor() {
  3376. throw new Error("Cannot initialize AppOptions.");
  3377. }
  3378. static get(name) {
  3379. const userOption = userOptions[name];
  3380. if (userOption !== undefined) {
  3381. return userOption;
  3382. }
  3383. const defaultOption = defaultOptions[name];
  3384. if (defaultOption !== undefined) {
  3385. return compatibilityParams[name] ?? defaultOption.value;
  3386. }
  3387. return undefined;
  3388. }
  3389. static getAll(kind = null) {
  3390. const options = Object.create(null);
  3391. for (const name in defaultOptions) {
  3392. const defaultOption = defaultOptions[name];
  3393. if (kind) {
  3394. if ((kind & defaultOption.kind) === 0) {
  3395. continue;
  3396. }
  3397. if (kind === OptionKind.PREFERENCE) {
  3398. const value = defaultOption.value,
  3399. valueType = typeof value;
  3400. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  3401. options[name] = value;
  3402. continue;
  3403. }
  3404. throw new Error(`Invalid type for preference: ${name}`);
  3405. }
  3406. }
  3407. const userOption = userOptions[name];
  3408. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  3409. }
  3410. return options;
  3411. }
  3412. static set(name, value) {
  3413. userOptions[name] = value;
  3414. }
  3415. static setAll(options) {
  3416. for (const name in options) {
  3417. userOptions[name] = options[name];
  3418. }
  3419. }
  3420. static remove(name) {
  3421. delete userOptions[name];
  3422. }
  3423. static _hasUserOptions() {
  3424. return Object.keys(userOptions).length > 0;
  3425. }
  3426. }
  3427. exports.AppOptions = AppOptions;
  3428. /***/ }),
  3429. /* 14 */
  3430. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3431. Object.defineProperty(exports, "__esModule", ({
  3432. value: true
  3433. }));
  3434. exports.PDFPageView = void 0;
  3435. var _pdfjsLib = __w_pdfjs_require__(3);
  3436. var _ui_utils = __w_pdfjs_require__(7);
  3437. var _app_options = __w_pdfjs_require__(13);
  3438. var _l10n_utils = __w_pdfjs_require__(4);
  3439. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  3440. class PDFPageView {
  3441. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  3442. #useThumbnailCanvas = {
  3443. initialOptionalContent: true,
  3444. regularAnnotations: true
  3445. };
  3446. constructor(options) {
  3447. const container = options.container;
  3448. const defaultViewport = options.defaultViewport;
  3449. this.id = options.id;
  3450. this.renderingId = "page" + this.id;
  3451. this.pdfPage = null;
  3452. this.pageLabel = null;
  3453. this.rotation = 0;
  3454. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  3455. this.viewport = defaultViewport;
  3456. this.pdfPageRotate = defaultViewport.rotation;
  3457. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  3458. this.hasRestrictedScaling = false;
  3459. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  3460. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  3461. this.imageResourcesPath = options.imageResourcesPath || "";
  3462. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  3463. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  3464. this.pageColors = options.pageColors || null;
  3465. this.eventBus = options.eventBus;
  3466. this.renderingQueue = options.renderingQueue;
  3467. this.textLayerFactory = options.textLayerFactory;
  3468. this.annotationLayerFactory = options.annotationLayerFactory;
  3469. this.annotationEditorLayerFactory = options.annotationEditorLayerFactory;
  3470. this.xfaLayerFactory = options.xfaLayerFactory;
  3471. this.textHighlighter = options.textHighlighterFactory?.createTextHighlighter({
  3472. pageIndex: this.id - 1,
  3473. eventBus: this.eventBus
  3474. });
  3475. this.structTreeLayerFactory = options.structTreeLayerFactory;
  3476. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  3477. this.l10n = options.l10n || _l10n_utils.NullL10n;
  3478. this.paintTask = null;
  3479. this.paintedViewportMap = new WeakMap();
  3480. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  3481. this.resume = null;
  3482. this._renderError = null;
  3483. this._isStandalone = !this.renderingQueue?.hasViewer();
  3484. this._annotationCanvasMap = null;
  3485. this.annotationLayer = null;
  3486. this.annotationEditorLayer = null;
  3487. this.textLayer = null;
  3488. this.zoomLayer = null;
  3489. this.xfaLayer = null;
  3490. this.structTreeLayer = null;
  3491. const div = document.createElement("div");
  3492. div.className = "page";
  3493. div.style.width = Math.floor(this.viewport.width) + "px";
  3494. div.style.height = Math.floor(this.viewport.height) + "px";
  3495. div.setAttribute("data-page-number", this.id);
  3496. div.setAttribute("role", "region");
  3497. this.l10n.get("page_landmark", {
  3498. page: this.id
  3499. }).then(msg => {
  3500. div.setAttribute("aria-label", msg);
  3501. });
  3502. this.div = div;
  3503. container?.append(div);
  3504. if (this._isStandalone) {
  3505. const {
  3506. optionalContentConfigPromise
  3507. } = options;
  3508. if (optionalContentConfigPromise) {
  3509. optionalContentConfigPromise.then(optionalContentConfig => {
  3510. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  3511. return;
  3512. }
  3513. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  3514. });
  3515. }
  3516. }
  3517. }
  3518. setPdfPage(pdfPage) {
  3519. this.pdfPage = pdfPage;
  3520. this.pdfPageRotate = pdfPage.rotate;
  3521. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  3522. this.viewport = pdfPage.getViewport({
  3523. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  3524. rotation: totalRotation
  3525. });
  3526. this.reset();
  3527. }
  3528. destroy() {
  3529. this.reset();
  3530. if (this.pdfPage) {
  3531. this.pdfPage.cleanup();
  3532. }
  3533. }
  3534. async _renderAnnotationLayer() {
  3535. let error = null;
  3536. try {
  3537. await this.annotationLayer.render(this.viewport, "display");
  3538. } catch (ex) {
  3539. error = ex;
  3540. } finally {
  3541. this.eventBus.dispatch("annotationlayerrendered", {
  3542. source: this,
  3543. pageNumber: this.id,
  3544. error
  3545. });
  3546. }
  3547. }
  3548. async _renderAnnotationEditorLayer() {
  3549. let error = null;
  3550. try {
  3551. await this.annotationEditorLayer.render(this.viewport, "display");
  3552. } catch (ex) {
  3553. error = ex;
  3554. } finally {
  3555. this.eventBus.dispatch("annotationeditorlayerrendered", {
  3556. source: this,
  3557. pageNumber: this.id,
  3558. error
  3559. });
  3560. }
  3561. }
  3562. async _renderXfaLayer() {
  3563. let error = null;
  3564. try {
  3565. const result = await this.xfaLayer.render(this.viewport, "display");
  3566. if (this.textHighlighter) {
  3567. this._buildXfaTextContentItems(result.textDivs);
  3568. }
  3569. } catch (ex) {
  3570. error = ex;
  3571. } finally {
  3572. this.eventBus.dispatch("xfalayerrendered", {
  3573. source: this,
  3574. pageNumber: this.id,
  3575. error
  3576. });
  3577. }
  3578. }
  3579. async _buildXfaTextContentItems(textDivs) {
  3580. const text = await this.pdfPage.getTextContent();
  3581. const items = [];
  3582. for (const item of text.items) {
  3583. items.push(item.str);
  3584. }
  3585. this.textHighlighter.setTextMapping(textDivs, items);
  3586. this.textHighlighter.enable();
  3587. }
  3588. _resetZoomLayer(removeFromDOM = false) {
  3589. if (!this.zoomLayer) {
  3590. return;
  3591. }
  3592. const zoomLayerCanvas = this.zoomLayer.firstChild;
  3593. this.paintedViewportMap.delete(zoomLayerCanvas);
  3594. zoomLayerCanvas.width = 0;
  3595. zoomLayerCanvas.height = 0;
  3596. if (removeFromDOM) {
  3597. this.zoomLayer.remove();
  3598. }
  3599. this.zoomLayer = null;
  3600. }
  3601. reset({
  3602. keepZoomLayer = false,
  3603. keepAnnotationLayer = false,
  3604. keepAnnotationEditorLayer = false,
  3605. keepXfaLayer = false
  3606. } = {}) {
  3607. this.cancelRendering({
  3608. keepAnnotationLayer,
  3609. keepAnnotationEditorLayer,
  3610. keepXfaLayer
  3611. });
  3612. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  3613. const div = this.div;
  3614. div.style.width = Math.floor(this.viewport.width) + "px";
  3615. div.style.height = Math.floor(this.viewport.height) + "px";
  3616. const childNodes = div.childNodes,
  3617. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  3618. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  3619. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  3620. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null;
  3621. for (let i = childNodes.length - 1; i >= 0; i--) {
  3622. const node = childNodes[i];
  3623. switch (node) {
  3624. case zoomLayerNode:
  3625. case annotationLayerNode:
  3626. case annotationEditorLayerNode:
  3627. case xfaLayerNode:
  3628. continue;
  3629. }
  3630. node.remove();
  3631. }
  3632. div.removeAttribute("data-loaded");
  3633. if (annotationLayerNode) {
  3634. this.annotationLayer.hide();
  3635. }
  3636. if (annotationEditorLayerNode) {
  3637. this.annotationEditorLayer.hide();
  3638. } else {
  3639. this.annotationEditorLayer?.destroy();
  3640. }
  3641. if (xfaLayerNode) {
  3642. this.xfaLayer.hide();
  3643. }
  3644. if (!zoomLayerNode) {
  3645. if (this.canvas) {
  3646. this.paintedViewportMap.delete(this.canvas);
  3647. this.canvas.width = 0;
  3648. this.canvas.height = 0;
  3649. delete this.canvas;
  3650. }
  3651. this._resetZoomLayer();
  3652. }
  3653. if (this.svg) {
  3654. this.paintedViewportMap.delete(this.svg);
  3655. delete this.svg;
  3656. }
  3657. this.loadingIconDiv = document.createElement("div");
  3658. this.loadingIconDiv.className = "loadingIcon notVisible";
  3659. if (this._isStandalone) {
  3660. this.toggleLoadingIconSpinner(true);
  3661. }
  3662. this.loadingIconDiv.setAttribute("role", "img");
  3663. this.l10n.get("loading").then(msg => {
  3664. this.loadingIconDiv?.setAttribute("aria-label", msg);
  3665. });
  3666. div.append(this.loadingIconDiv);
  3667. }
  3668. update({
  3669. scale = 0,
  3670. rotation = null,
  3671. optionalContentConfigPromise = null
  3672. }) {
  3673. this.scale = scale || this.scale;
  3674. if (typeof rotation === "number") {
  3675. this.rotation = rotation;
  3676. }
  3677. if (optionalContentConfigPromise instanceof Promise) {
  3678. this._optionalContentConfigPromise = optionalContentConfigPromise;
  3679. optionalContentConfigPromise.then(optionalContentConfig => {
  3680. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  3681. return;
  3682. }
  3683. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  3684. });
  3685. }
  3686. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  3687. this.viewport = this.viewport.clone({
  3688. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  3689. rotation: totalRotation
  3690. });
  3691. if (this._isStandalone) {
  3692. _ui_utils.docStyle.setProperty("--scale-factor", this.viewport.scale);
  3693. }
  3694. if (this.svg) {
  3695. this.cssTransform({
  3696. target: this.svg,
  3697. redrawAnnotationLayer: true,
  3698. redrawAnnotationEditorLayer: true,
  3699. redrawXfaLayer: true
  3700. });
  3701. this.eventBus.dispatch("pagerendered", {
  3702. source: this,
  3703. pageNumber: this.id,
  3704. cssTransform: true,
  3705. timestamp: performance.now(),
  3706. error: this._renderError
  3707. });
  3708. return;
  3709. }
  3710. let isScalingRestricted = false;
  3711. if (this.canvas && this.maxCanvasPixels > 0) {
  3712. const outputScale = this.outputScale;
  3713. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  3714. isScalingRestricted = true;
  3715. }
  3716. }
  3717. if (this.canvas) {
  3718. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  3719. this.cssTransform({
  3720. target: this.canvas,
  3721. redrawAnnotationLayer: true,
  3722. redrawAnnotationEditorLayer: true,
  3723. redrawXfaLayer: true
  3724. });
  3725. this.eventBus.dispatch("pagerendered", {
  3726. source: this,
  3727. pageNumber: this.id,
  3728. cssTransform: true,
  3729. timestamp: performance.now(),
  3730. error: this._renderError
  3731. });
  3732. return;
  3733. }
  3734. if (!this.zoomLayer && !this.canvas.hidden) {
  3735. this.zoomLayer = this.canvas.parentNode;
  3736. this.zoomLayer.style.position = "absolute";
  3737. }
  3738. }
  3739. if (this.zoomLayer) {
  3740. this.cssTransform({
  3741. target: this.zoomLayer.firstChild
  3742. });
  3743. }
  3744. this.reset({
  3745. keepZoomLayer: true,
  3746. keepAnnotationLayer: true,
  3747. keepAnnotationEditorLayer: true,
  3748. keepXfaLayer: true
  3749. });
  3750. }
  3751. cancelRendering({
  3752. keepAnnotationLayer = false,
  3753. keepAnnotationEditorLayer = false,
  3754. keepXfaLayer = false
  3755. } = {}) {
  3756. if (this.paintTask) {
  3757. this.paintTask.cancel();
  3758. this.paintTask = null;
  3759. }
  3760. this.resume = null;
  3761. if (this.textLayer) {
  3762. this.textLayer.cancel();
  3763. this.textLayer = null;
  3764. }
  3765. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  3766. this.annotationLayer.cancel();
  3767. this.annotationLayer = null;
  3768. this._annotationCanvasMap = null;
  3769. }
  3770. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  3771. this.annotationEditorLayer.cancel();
  3772. this.annotationEditorLayer = null;
  3773. }
  3774. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  3775. this.xfaLayer.cancel();
  3776. this.xfaLayer = null;
  3777. this.textHighlighter?.disable();
  3778. }
  3779. if (this._onTextLayerRendered) {
  3780. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  3781. this._onTextLayerRendered = null;
  3782. }
  3783. }
  3784. cssTransform({
  3785. target,
  3786. redrawAnnotationLayer = false,
  3787. redrawAnnotationEditorLayer = false,
  3788. redrawXfaLayer = false
  3789. }) {
  3790. const width = this.viewport.width;
  3791. const height = this.viewport.height;
  3792. const div = this.div;
  3793. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  3794. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  3795. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  3796. const absRotation = Math.abs(relativeRotation);
  3797. let scaleX = 1,
  3798. scaleY = 1;
  3799. if (absRotation === 90 || absRotation === 270) {
  3800. scaleX = height / width;
  3801. scaleY = width / height;
  3802. }
  3803. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  3804. if (this.textLayer) {
  3805. const textLayerViewport = this.textLayer.viewport;
  3806. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  3807. const textAbsRotation = Math.abs(textRelativeRotation);
  3808. let scale = width / textLayerViewport.width;
  3809. if (textAbsRotation === 90 || textAbsRotation === 270) {
  3810. scale = width / textLayerViewport.height;
  3811. }
  3812. const textLayerDiv = this.textLayer.textLayerDiv;
  3813. let transX, transY;
  3814. switch (textAbsRotation) {
  3815. case 0:
  3816. transX = transY = 0;
  3817. break;
  3818. case 90:
  3819. transX = 0;
  3820. transY = "-" + textLayerDiv.style.height;
  3821. break;
  3822. case 180:
  3823. transX = "-" + textLayerDiv.style.width;
  3824. transY = "-" + textLayerDiv.style.height;
  3825. break;
  3826. case 270:
  3827. transX = "-" + textLayerDiv.style.width;
  3828. transY = 0;
  3829. break;
  3830. default:
  3831. console.error("Bad rotation value.");
  3832. break;
  3833. }
  3834. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  3835. textLayerDiv.style.transformOrigin = "0% 0%";
  3836. }
  3837. if (redrawAnnotationLayer && this.annotationLayer) {
  3838. this._renderAnnotationLayer();
  3839. }
  3840. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  3841. this._renderAnnotationEditorLayer();
  3842. }
  3843. if (redrawXfaLayer && this.xfaLayer) {
  3844. this._renderXfaLayer();
  3845. }
  3846. }
  3847. get width() {
  3848. return this.viewport.width;
  3849. }
  3850. get height() {
  3851. return this.viewport.height;
  3852. }
  3853. getPagePoint(x, y) {
  3854. return this.viewport.convertToPdfPoint(x, y);
  3855. }
  3856. toggleLoadingIconSpinner(viewVisible = false) {
  3857. this.loadingIconDiv?.classList.toggle("notVisible", !viewVisible);
  3858. }
  3859. draw() {
  3860. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  3861. console.error("Must be in new state before drawing");
  3862. this.reset();
  3863. }
  3864. const {
  3865. div,
  3866. pdfPage
  3867. } = this;
  3868. if (!pdfPage) {
  3869. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  3870. if (this.loadingIconDiv) {
  3871. this.loadingIconDiv.remove();
  3872. delete this.loadingIconDiv;
  3873. }
  3874. return Promise.reject(new Error("pdfPage is not loaded"));
  3875. }
  3876. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  3877. const canvasWrapper = document.createElement("div");
  3878. canvasWrapper.style.width = div.style.width;
  3879. canvasWrapper.style.height = div.style.height;
  3880. canvasWrapper.classList.add("canvasWrapper");
  3881. const lastDivBeforeTextDiv = this.annotationLayer?.div || this.annotationEditorLayer?.div;
  3882. if (lastDivBeforeTextDiv) {
  3883. lastDivBeforeTextDiv.before(canvasWrapper);
  3884. } else {
  3885. div.append(canvasWrapper);
  3886. }
  3887. let textLayer = null;
  3888. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  3889. const textLayerDiv = document.createElement("div");
  3890. textLayerDiv.className = "textLayer";
  3891. textLayerDiv.style.width = canvasWrapper.style.width;
  3892. textLayerDiv.style.height = canvasWrapper.style.height;
  3893. if (lastDivBeforeTextDiv) {
  3894. lastDivBeforeTextDiv.before(textLayerDiv);
  3895. } else {
  3896. div.append(textLayerDiv);
  3897. }
  3898. textLayer = this.textLayerFactory.createTextLayerBuilder({
  3899. textLayerDiv,
  3900. pageIndex: this.id - 1,
  3901. viewport: this.viewport,
  3902. enhanceTextSelection: this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE,
  3903. eventBus: this.eventBus,
  3904. highlighter: this.textHighlighter
  3905. });
  3906. }
  3907. this.textLayer = textLayer;
  3908. if (this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE && this.annotationLayerFactory) {
  3909. this._annotationCanvasMap ||= new Map();
  3910. this.annotationLayer ||= this.annotationLayerFactory.createAnnotationLayerBuilder({
  3911. pageDiv: div,
  3912. pdfPage,
  3913. imageResourcesPath: this.imageResourcesPath,
  3914. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  3915. l10n: this.l10n,
  3916. annotationCanvasMap: this._annotationCanvasMap
  3917. });
  3918. }
  3919. if (this.xfaLayer?.div) {
  3920. div.append(this.xfaLayer.div);
  3921. }
  3922. let renderContinueCallback = null;
  3923. if (this.renderingQueue) {
  3924. renderContinueCallback = cont => {
  3925. if (!this.renderingQueue.isHighestPriority(this)) {
  3926. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  3927. this.resume = () => {
  3928. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  3929. cont();
  3930. };
  3931. return;
  3932. }
  3933. cont();
  3934. };
  3935. }
  3936. const finishPaintTask = async (error = null) => {
  3937. if (paintTask === this.paintTask) {
  3938. this.paintTask = null;
  3939. }
  3940. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  3941. this._renderError = null;
  3942. return;
  3943. }
  3944. this._renderError = error;
  3945. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  3946. if (this.loadingIconDiv) {
  3947. this.loadingIconDiv.remove();
  3948. delete this.loadingIconDiv;
  3949. }
  3950. this._resetZoomLayer(true);
  3951. this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
  3952. this.eventBus.dispatch("pagerendered", {
  3953. source: this,
  3954. pageNumber: this.id,
  3955. cssTransform: false,
  3956. timestamp: performance.now(),
  3957. error: this._renderError
  3958. });
  3959. if (error) {
  3960. throw error;
  3961. }
  3962. };
  3963. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  3964. paintTask.onRenderContinue = renderContinueCallback;
  3965. this.paintTask = paintTask;
  3966. const resultPromise = paintTask.promise.then(() => {
  3967. return finishPaintTask(null).then(() => {
  3968. if (textLayer) {
  3969. const readableStream = pdfPage.streamTextContent({
  3970. includeMarkedContent: true
  3971. });
  3972. textLayer.setTextContentStream(readableStream);
  3973. textLayer.render();
  3974. }
  3975. if (this.annotationLayer) {
  3976. this._renderAnnotationLayer().then(() => {
  3977. if (this.annotationEditorLayerFactory) {
  3978. this.annotationEditorLayer ||= this.annotationEditorLayerFactory.createAnnotationEditorLayerBuilder({
  3979. pageDiv: div,
  3980. pdfPage,
  3981. l10n: this.l10n
  3982. });
  3983. this._renderAnnotationEditorLayer();
  3984. }
  3985. });
  3986. }
  3987. });
  3988. }, function (reason) {
  3989. return finishPaintTask(reason);
  3990. });
  3991. if (this.xfaLayerFactory) {
  3992. if (!this.xfaLayer) {
  3993. this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder({
  3994. pageDiv: div,
  3995. pdfPage
  3996. });
  3997. }
  3998. this._renderXfaLayer();
  3999. }
  4000. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  4001. this._onTextLayerRendered = event => {
  4002. if (event.pageNumber !== this.id) {
  4003. return;
  4004. }
  4005. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  4006. this._onTextLayerRendered = null;
  4007. if (!this.canvas) {
  4008. return;
  4009. }
  4010. this.pdfPage.getStructTree().then(tree => {
  4011. if (!tree) {
  4012. return;
  4013. }
  4014. if (!this.canvas) {
  4015. return;
  4016. }
  4017. const treeDom = this.structTreeLayer.render(tree);
  4018. treeDom.classList.add("structTree");
  4019. this.canvas.append(treeDom);
  4020. });
  4021. };
  4022. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  4023. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder({
  4024. pdfPage
  4025. });
  4026. }
  4027. div.setAttribute("data-loaded", true);
  4028. this.eventBus.dispatch("pagerender", {
  4029. source: this,
  4030. pageNumber: this.id
  4031. });
  4032. return resultPromise;
  4033. }
  4034. paintOnCanvas(canvasWrapper) {
  4035. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  4036. const result = {
  4037. promise: renderCapability.promise,
  4038. onRenderContinue(cont) {
  4039. cont();
  4040. },
  4041. cancel() {
  4042. renderTask.cancel();
  4043. },
  4044. get separateAnnots() {
  4045. return renderTask.separateAnnots;
  4046. }
  4047. };
  4048. const viewport = this.viewport;
  4049. const canvas = document.createElement("canvas");
  4050. canvas.setAttribute("role", "presentation");
  4051. canvas.hidden = true;
  4052. let isCanvasHidden = true;
  4053. const showCanvas = function () {
  4054. if (isCanvasHidden) {
  4055. canvas.hidden = false;
  4056. isCanvasHidden = false;
  4057. }
  4058. };
  4059. canvasWrapper.append(canvas);
  4060. this.canvas = canvas;
  4061. const ctx = canvas.getContext("2d", {
  4062. alpha: false
  4063. });
  4064. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  4065. if (this.useOnlyCssZoom) {
  4066. const actualSizeViewport = viewport.clone({
  4067. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  4068. });
  4069. outputScale.sx *= actualSizeViewport.width / viewport.width;
  4070. outputScale.sy *= actualSizeViewport.height / viewport.height;
  4071. }
  4072. if (this.maxCanvasPixels > 0) {
  4073. const pixelsInViewport = viewport.width * viewport.height;
  4074. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  4075. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  4076. outputScale.sx = maxScale;
  4077. outputScale.sy = maxScale;
  4078. this.hasRestrictedScaling = true;
  4079. } else {
  4080. this.hasRestrictedScaling = false;
  4081. }
  4082. }
  4083. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  4084. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  4085. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  4086. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  4087. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  4088. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  4089. this.paintedViewportMap.set(canvas, viewport);
  4090. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  4091. const renderContext = {
  4092. canvasContext: ctx,
  4093. transform,
  4094. viewport: this.viewport,
  4095. annotationMode: this.#annotationMode,
  4096. optionalContentConfigPromise: this._optionalContentConfigPromise,
  4097. annotationCanvasMap: this._annotationCanvasMap,
  4098. pageColors: this.pageColors
  4099. };
  4100. const renderTask = this.pdfPage.render(renderContext);
  4101. renderTask.onContinue = function (cont) {
  4102. showCanvas();
  4103. if (result.onRenderContinue) {
  4104. result.onRenderContinue(cont);
  4105. } else {
  4106. cont();
  4107. }
  4108. };
  4109. renderTask.promise.then(function () {
  4110. showCanvas();
  4111. renderCapability.resolve();
  4112. }, function (error) {
  4113. showCanvas();
  4114. renderCapability.reject(error);
  4115. });
  4116. return result;
  4117. }
  4118. paintOnSvg(wrapper) {
  4119. let cancelled = false;
  4120. const ensureNotCancelled = () => {
  4121. if (cancelled) {
  4122. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  4123. }
  4124. };
  4125. const pdfPage = this.pdfPage;
  4126. const actualSizeViewport = this.viewport.clone({
  4127. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  4128. });
  4129. const promise = pdfPage.getOperatorList({
  4130. annotationMode: this.#annotationMode
  4131. }).then(opList => {
  4132. ensureNotCancelled();
  4133. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  4134. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  4135. ensureNotCancelled();
  4136. this.svg = svg;
  4137. this.paintedViewportMap.set(svg, actualSizeViewport);
  4138. svg.style.width = wrapper.style.width;
  4139. svg.style.height = wrapper.style.height;
  4140. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  4141. wrapper.append(svg);
  4142. });
  4143. });
  4144. return {
  4145. promise,
  4146. onRenderContinue(cont) {
  4147. cont();
  4148. },
  4149. cancel() {
  4150. cancelled = true;
  4151. },
  4152. get separateAnnots() {
  4153. return false;
  4154. }
  4155. };
  4156. }
  4157. setPageLabel(label) {
  4158. this.pageLabel = typeof label === "string" ? label : null;
  4159. if (this.pageLabel !== null) {
  4160. this.div.setAttribute("data-page-label", this.pageLabel);
  4161. } else {
  4162. this.div.removeAttribute("data-page-label");
  4163. }
  4164. }
  4165. get thumbnailCanvas() {
  4166. const {
  4167. initialOptionalContent,
  4168. regularAnnotations
  4169. } = this.#useThumbnailCanvas;
  4170. return initialOptionalContent && regularAnnotations ? this.canvas : null;
  4171. }
  4172. }
  4173. exports.PDFPageView = PDFPageView;
  4174. /***/ }),
  4175. /* 15 */
  4176. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4177. Object.defineProperty(exports, "__esModule", ({
  4178. value: true
  4179. }));
  4180. exports.PDFRenderingQueue = void 0;
  4181. var _pdfjsLib = __w_pdfjs_require__(3);
  4182. var _ui_utils = __w_pdfjs_require__(7);
  4183. const CLEANUP_TIMEOUT = 30000;
  4184. class PDFRenderingQueue {
  4185. constructor() {
  4186. this.pdfViewer = null;
  4187. this.pdfThumbnailViewer = null;
  4188. this.onIdle = null;
  4189. this.highestPriorityPage = null;
  4190. this.idleTimeout = null;
  4191. this.printing = false;
  4192. this.isThumbnailViewEnabled = false;
  4193. }
  4194. setViewer(pdfViewer) {
  4195. this.pdfViewer = pdfViewer;
  4196. }
  4197. setThumbnailViewer(pdfThumbnailViewer) {
  4198. this.pdfThumbnailViewer = pdfThumbnailViewer;
  4199. }
  4200. isHighestPriority(view) {
  4201. return this.highestPriorityPage === view.renderingId;
  4202. }
  4203. hasViewer() {
  4204. return !!this.pdfViewer;
  4205. }
  4206. renderHighestPriority(currentlyVisiblePages) {
  4207. if (this.idleTimeout) {
  4208. clearTimeout(this.idleTimeout);
  4209. this.idleTimeout = null;
  4210. }
  4211. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  4212. return;
  4213. }
  4214. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  4215. return;
  4216. }
  4217. if (this.printing) {
  4218. return;
  4219. }
  4220. if (this.onIdle) {
  4221. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  4222. }
  4223. }
  4224. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  4225. const visibleViews = visible.views,
  4226. numVisible = visibleViews.length;
  4227. if (numVisible === 0) {
  4228. return null;
  4229. }
  4230. for (let i = 0; i < numVisible; i++) {
  4231. const view = visibleViews[i].view;
  4232. if (!this.isViewFinished(view)) {
  4233. return view;
  4234. }
  4235. }
  4236. const firstId = visible.first.id,
  4237. lastId = visible.last.id;
  4238. if (lastId - firstId + 1 > numVisible) {
  4239. const visibleIds = visible.ids;
  4240. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  4241. const holeId = scrolledDown ? firstId + i : lastId - i;
  4242. if (visibleIds.has(holeId)) {
  4243. continue;
  4244. }
  4245. const holeView = views[holeId - 1];
  4246. if (!this.isViewFinished(holeView)) {
  4247. return holeView;
  4248. }
  4249. }
  4250. }
  4251. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  4252. let preRenderView = views[preRenderIndex];
  4253. if (preRenderView && !this.isViewFinished(preRenderView)) {
  4254. return preRenderView;
  4255. }
  4256. if (preRenderExtra) {
  4257. preRenderIndex += scrolledDown ? 1 : -1;
  4258. preRenderView = views[preRenderIndex];
  4259. if (preRenderView && !this.isViewFinished(preRenderView)) {
  4260. return preRenderView;
  4261. }
  4262. }
  4263. return null;
  4264. }
  4265. isViewFinished(view) {
  4266. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  4267. }
  4268. renderView(view) {
  4269. switch (view.renderingState) {
  4270. case _ui_utils.RenderingStates.FINISHED:
  4271. return false;
  4272. case _ui_utils.RenderingStates.PAUSED:
  4273. this.highestPriorityPage = view.renderingId;
  4274. view.resume();
  4275. break;
  4276. case _ui_utils.RenderingStates.RUNNING:
  4277. this.highestPriorityPage = view.renderingId;
  4278. break;
  4279. case _ui_utils.RenderingStates.INITIAL:
  4280. this.highestPriorityPage = view.renderingId;
  4281. view.draw().finally(() => {
  4282. this.renderHighestPriority();
  4283. }).catch(reason => {
  4284. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  4285. return;
  4286. }
  4287. console.error(`renderView: "${reason}"`);
  4288. });
  4289. break;
  4290. }
  4291. return true;
  4292. }
  4293. }
  4294. exports.PDFRenderingQueue = PDFRenderingQueue;
  4295. /***/ }),
  4296. /* 16 */
  4297. /***/ ((__unused_webpack_module, exports) => {
  4298. Object.defineProperty(exports, "__esModule", ({
  4299. value: true
  4300. }));
  4301. exports.TextHighlighter = void 0;
  4302. class TextHighlighter {
  4303. constructor({
  4304. findController,
  4305. eventBus,
  4306. pageIndex
  4307. }) {
  4308. this.findController = findController;
  4309. this.matches = [];
  4310. this.eventBus = eventBus;
  4311. this.pageIdx = pageIndex;
  4312. this._onUpdateTextLayerMatches = null;
  4313. this.textDivs = null;
  4314. this.textContentItemsStr = null;
  4315. this.enabled = false;
  4316. }
  4317. setTextMapping(divs, texts) {
  4318. this.textDivs = divs;
  4319. this.textContentItemsStr = texts;
  4320. }
  4321. enable() {
  4322. if (!this.textDivs || !this.textContentItemsStr) {
  4323. throw new Error("Text divs and strings have not been set.");
  4324. }
  4325. if (this.enabled) {
  4326. throw new Error("TextHighlighter is already enabled.");
  4327. }
  4328. this.enabled = true;
  4329. if (!this._onUpdateTextLayerMatches) {
  4330. this._onUpdateTextLayerMatches = evt => {
  4331. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  4332. this._updateMatches();
  4333. }
  4334. };
  4335. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  4336. }
  4337. this._updateMatches();
  4338. }
  4339. disable() {
  4340. if (!this.enabled) {
  4341. return;
  4342. }
  4343. this.enabled = false;
  4344. if (this._onUpdateTextLayerMatches) {
  4345. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  4346. this._onUpdateTextLayerMatches = null;
  4347. }
  4348. }
  4349. _convertMatches(matches, matchesLength) {
  4350. if (!matches) {
  4351. return [];
  4352. }
  4353. const {
  4354. textContentItemsStr
  4355. } = this;
  4356. let i = 0,
  4357. iIndex = 0;
  4358. const end = textContentItemsStr.length - 1;
  4359. const result = [];
  4360. for (let m = 0, mm = matches.length; m < mm; m++) {
  4361. let matchIdx = matches[m];
  4362. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  4363. iIndex += textContentItemsStr[i].length;
  4364. i++;
  4365. }
  4366. if (i === textContentItemsStr.length) {
  4367. console.error("Could not find a matching mapping");
  4368. }
  4369. const match = {
  4370. begin: {
  4371. divIdx: i,
  4372. offset: matchIdx - iIndex
  4373. }
  4374. };
  4375. matchIdx += matchesLength[m];
  4376. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  4377. iIndex += textContentItemsStr[i].length;
  4378. i++;
  4379. }
  4380. match.end = {
  4381. divIdx: i,
  4382. offset: matchIdx - iIndex
  4383. };
  4384. result.push(match);
  4385. }
  4386. return result;
  4387. }
  4388. _renderMatches(matches) {
  4389. if (matches.length === 0) {
  4390. return;
  4391. }
  4392. const {
  4393. findController,
  4394. pageIdx
  4395. } = this;
  4396. const {
  4397. textContentItemsStr,
  4398. textDivs
  4399. } = this;
  4400. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  4401. const selectedMatchIdx = findController.selected.matchIdx;
  4402. const highlightAll = findController.state.highlightAll;
  4403. let prevEnd = null;
  4404. const infinity = {
  4405. divIdx: -1,
  4406. offset: undefined
  4407. };
  4408. function beginText(begin, className) {
  4409. const divIdx = begin.divIdx;
  4410. textDivs[divIdx].textContent = "";
  4411. return appendTextToDiv(divIdx, 0, begin.offset, className);
  4412. }
  4413. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  4414. let div = textDivs[divIdx];
  4415. if (div.nodeType === Node.TEXT_NODE) {
  4416. const span = document.createElement("span");
  4417. div.before(span);
  4418. span.append(div);
  4419. textDivs[divIdx] = span;
  4420. div = span;
  4421. }
  4422. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  4423. const node = document.createTextNode(content);
  4424. if (className) {
  4425. const span = document.createElement("span");
  4426. span.className = `${className} appended`;
  4427. span.append(node);
  4428. div.append(span);
  4429. return className.includes("selected") ? span.offsetLeft : 0;
  4430. }
  4431. div.append(node);
  4432. return 0;
  4433. }
  4434. let i0 = selectedMatchIdx,
  4435. i1 = i0 + 1;
  4436. if (highlightAll) {
  4437. i0 = 0;
  4438. i1 = matches.length;
  4439. } else if (!isSelectedPage) {
  4440. return;
  4441. }
  4442. for (let i = i0; i < i1; i++) {
  4443. const match = matches[i];
  4444. const begin = match.begin;
  4445. const end = match.end;
  4446. const isSelected = isSelectedPage && i === selectedMatchIdx;
  4447. const highlightSuffix = isSelected ? " selected" : "";
  4448. let selectedLeft = 0;
  4449. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  4450. if (prevEnd !== null) {
  4451. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  4452. }
  4453. beginText(begin);
  4454. } else {
  4455. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  4456. }
  4457. if (begin.divIdx === end.divIdx) {
  4458. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  4459. } else {
  4460. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  4461. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  4462. textDivs[n0].className = "highlight middle" + highlightSuffix;
  4463. }
  4464. beginText(end, "highlight end" + highlightSuffix);
  4465. }
  4466. prevEnd = end;
  4467. if (isSelected) {
  4468. findController.scrollMatchIntoView({
  4469. element: textDivs[begin.divIdx],
  4470. selectedLeft,
  4471. pageIndex: pageIdx,
  4472. matchIndex: selectedMatchIdx
  4473. });
  4474. }
  4475. }
  4476. if (prevEnd) {
  4477. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  4478. }
  4479. }
  4480. _updateMatches() {
  4481. if (!this.enabled) {
  4482. return;
  4483. }
  4484. const {
  4485. findController,
  4486. matches,
  4487. pageIdx
  4488. } = this;
  4489. const {
  4490. textContentItemsStr,
  4491. textDivs
  4492. } = this;
  4493. let clearedUntilDivIdx = -1;
  4494. for (let i = 0, ii = matches.length; i < ii; i++) {
  4495. const match = matches[i];
  4496. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  4497. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  4498. const div = textDivs[n];
  4499. div.textContent = textContentItemsStr[n];
  4500. div.className = "";
  4501. }
  4502. clearedUntilDivIdx = match.end.divIdx + 1;
  4503. }
  4504. if (!findController?.highlightMatches) {
  4505. return;
  4506. }
  4507. const pageMatches = findController.pageMatches[pageIdx] || null;
  4508. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  4509. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  4510. this._renderMatches(this.matches);
  4511. }
  4512. }
  4513. exports.TextHighlighter = TextHighlighter;
  4514. /***/ }),
  4515. /* 17 */
  4516. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4517. Object.defineProperty(exports, "__esModule", ({
  4518. value: true
  4519. }));
  4520. exports.DownloadManager = void 0;
  4521. var _pdfjsLib = __w_pdfjs_require__(3);
  4522. ;
  4523. function download(blobUrl, filename) {
  4524. const a = document.createElement("a");
  4525. if (!a.click) {
  4526. throw new Error('DownloadManager: "a.click()" is not supported.');
  4527. }
  4528. a.href = blobUrl;
  4529. a.target = "_parent";
  4530. if ("download" in a) {
  4531. a.download = filename;
  4532. }
  4533. (document.body || document.documentElement).append(a);
  4534. a.click();
  4535. a.remove();
  4536. }
  4537. class DownloadManager {
  4538. constructor() {
  4539. this._openBlobUrls = new WeakMap();
  4540. }
  4541. downloadUrl(url, filename) {
  4542. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  4543. console.error(`downloadUrl - not a valid URL: ${url}`);
  4544. return;
  4545. }
  4546. download(url + "#pdfjs.action=download", filename);
  4547. }
  4548. downloadData(data, filename, contentType) {
  4549. const blobUrl = URL.createObjectURL(new Blob([data], {
  4550. type: contentType
  4551. }));
  4552. download(blobUrl, filename);
  4553. }
  4554. openOrDownloadData(element, data, filename) {
  4555. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  4556. const contentType = isPdfData ? "application/pdf" : "";
  4557. if (isPdfData) {
  4558. let blobUrl = this._openBlobUrls.get(element);
  4559. if (!blobUrl) {
  4560. blobUrl = URL.createObjectURL(new Blob([data], {
  4561. type: contentType
  4562. }));
  4563. this._openBlobUrls.set(element, blobUrl);
  4564. }
  4565. let viewerUrl;
  4566. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  4567. try {
  4568. window.open(viewerUrl);
  4569. return true;
  4570. } catch (ex) {
  4571. console.error(`openOrDownloadData: ${ex}`);
  4572. URL.revokeObjectURL(blobUrl);
  4573. this._openBlobUrls.delete(element);
  4574. }
  4575. }
  4576. this.downloadData(data, filename, contentType);
  4577. return false;
  4578. }
  4579. download(blob, url, filename) {
  4580. const blobUrl = URL.createObjectURL(blob);
  4581. download(blobUrl, filename);
  4582. }
  4583. }
  4584. exports.DownloadManager = DownloadManager;
  4585. /***/ }),
  4586. /* 18 */
  4587. /***/ ((__unused_webpack_module, exports) => {
  4588. Object.defineProperty(exports, "__esModule", ({
  4589. value: true
  4590. }));
  4591. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  4592. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  4593. const WaitOnType = {
  4594. EVENT: "event",
  4595. TIMEOUT: "timeout"
  4596. };
  4597. exports.WaitOnType = WaitOnType;
  4598. function waitOnEventOrTimeout({
  4599. target,
  4600. name,
  4601. delay = 0
  4602. }) {
  4603. return new Promise(function (resolve, reject) {
  4604. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  4605. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  4606. }
  4607. function handler(type) {
  4608. if (target instanceof EventBus) {
  4609. target._off(name, eventHandler);
  4610. } else {
  4611. target.removeEventListener(name, eventHandler);
  4612. }
  4613. if (timeout) {
  4614. clearTimeout(timeout);
  4615. }
  4616. resolve(type);
  4617. }
  4618. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  4619. if (target instanceof EventBus) {
  4620. target._on(name, eventHandler);
  4621. } else {
  4622. target.addEventListener(name, eventHandler);
  4623. }
  4624. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  4625. const timeout = setTimeout(timeoutHandler, delay);
  4626. });
  4627. }
  4628. class EventBus {
  4629. constructor() {
  4630. this._listeners = Object.create(null);
  4631. }
  4632. on(eventName, listener, options = null) {
  4633. this._on(eventName, listener, {
  4634. external: true,
  4635. once: options?.once
  4636. });
  4637. }
  4638. off(eventName, listener, options = null) {
  4639. this._off(eventName, listener, {
  4640. external: true,
  4641. once: options?.once
  4642. });
  4643. }
  4644. dispatch(eventName, data) {
  4645. const eventListeners = this._listeners[eventName];
  4646. if (!eventListeners || eventListeners.length === 0) {
  4647. return;
  4648. }
  4649. let externalListeners;
  4650. for (const {
  4651. listener,
  4652. external,
  4653. once
  4654. } of eventListeners.slice(0)) {
  4655. if (once) {
  4656. this._off(eventName, listener);
  4657. }
  4658. if (external) {
  4659. (externalListeners ||= []).push(listener);
  4660. continue;
  4661. }
  4662. listener(data);
  4663. }
  4664. if (externalListeners) {
  4665. for (const listener of externalListeners) {
  4666. listener(data);
  4667. }
  4668. externalListeners = null;
  4669. }
  4670. }
  4671. _on(eventName, listener, options = null) {
  4672. const eventListeners = this._listeners[eventName] ||= [];
  4673. eventListeners.push({
  4674. listener,
  4675. external: options?.external === true,
  4676. once: options?.once === true
  4677. });
  4678. }
  4679. _off(eventName, listener, options = null) {
  4680. const eventListeners = this._listeners[eventName];
  4681. if (!eventListeners) {
  4682. return;
  4683. }
  4684. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  4685. if (eventListeners[i].listener === listener) {
  4686. eventListeners.splice(i, 1);
  4687. return;
  4688. }
  4689. }
  4690. }
  4691. }
  4692. exports.EventBus = EventBus;
  4693. class AutomationEventBus extends EventBus {
  4694. dispatch(eventName, data) {
  4695. throw new Error("Not implemented: AutomationEventBus.dispatch");
  4696. }
  4697. }
  4698. exports.AutomationEventBus = AutomationEventBus;
  4699. /***/ }),
  4700. /* 19 */
  4701. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4702. Object.defineProperty(exports, "__esModule", ({
  4703. value: true
  4704. }));
  4705. exports.GenericL10n = void 0;
  4706. __w_pdfjs_require__(20);
  4707. var _l10n_utils = __w_pdfjs_require__(4);
  4708. const webL10n = document.webL10n;
  4709. class GenericL10n {
  4710. constructor(lang) {
  4711. this._lang = lang;
  4712. this._ready = new Promise((resolve, reject) => {
  4713. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  4714. resolve(webL10n);
  4715. });
  4716. });
  4717. }
  4718. async getLanguage() {
  4719. const l10n = await this._ready;
  4720. return l10n.getLanguage();
  4721. }
  4722. async getDirection() {
  4723. const l10n = await this._ready;
  4724. return l10n.getDirection();
  4725. }
  4726. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  4727. const l10n = await this._ready;
  4728. return l10n.get(key, args, fallback);
  4729. }
  4730. async translate(element) {
  4731. const l10n = await this._ready;
  4732. return l10n.translate(element);
  4733. }
  4734. }
  4735. exports.GenericL10n = GenericL10n;
  4736. /***/ }),
  4737. /* 20 */
  4738. /***/ (() => {
  4739. document.webL10n = function (window, document, undefined) {
  4740. var gL10nData = {};
  4741. var gTextData = '';
  4742. var gTextProp = 'textContent';
  4743. var gLanguage = '';
  4744. var gMacros = {};
  4745. var gReadyState = 'loading';
  4746. var gAsyncResourceLoading = true;
  4747. function getL10nResourceLinks() {
  4748. return document.querySelectorAll('link[type="application/l10n"]');
  4749. }
  4750. function getL10nDictionary() {
  4751. var script = document.querySelector('script[type="application/l10n"]');
  4752. return script ? JSON.parse(script.innerHTML) : null;
  4753. }
  4754. function getTranslatableChildren(element) {
  4755. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  4756. }
  4757. function getL10nAttributes(element) {
  4758. if (!element) return {};
  4759. var l10nId = element.getAttribute('data-l10n-id');
  4760. var l10nArgs = element.getAttribute('data-l10n-args');
  4761. var args = {};
  4762. if (l10nArgs) {
  4763. try {
  4764. args = JSON.parse(l10nArgs);
  4765. } catch (e) {
  4766. console.warn('could not parse arguments for #' + l10nId);
  4767. }
  4768. }
  4769. return {
  4770. id: l10nId,
  4771. args: args
  4772. };
  4773. }
  4774. function xhrLoadText(url, onSuccess, onFailure) {
  4775. onSuccess = onSuccess || function _onSuccess(data) {};
  4776. onFailure = onFailure || function _onFailure() {};
  4777. var xhr = new XMLHttpRequest();
  4778. xhr.open('GET', url, gAsyncResourceLoading);
  4779. if (xhr.overrideMimeType) {
  4780. xhr.overrideMimeType('text/plain; charset=utf-8');
  4781. }
  4782. xhr.onreadystatechange = function () {
  4783. if (xhr.readyState == 4) {
  4784. if (xhr.status == 200 || xhr.status === 0) {
  4785. onSuccess(xhr.responseText);
  4786. } else {
  4787. onFailure();
  4788. }
  4789. }
  4790. };
  4791. xhr.onerror = onFailure;
  4792. xhr.ontimeout = onFailure;
  4793. try {
  4794. xhr.send(null);
  4795. } catch (e) {
  4796. onFailure();
  4797. }
  4798. }
  4799. function parseResource(href, lang, successCallback, failureCallback) {
  4800. var baseURL = href.replace(/[^\/]*$/, '') || './';
  4801. function evalString(text) {
  4802. if (text.lastIndexOf('\\') < 0) return text;
  4803. 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, "'");
  4804. }
  4805. function parseProperties(text, parsedPropertiesCallback) {
  4806. var dictionary = {};
  4807. var reBlank = /^\s*|\s*$/;
  4808. var reComment = /^\s*#|^\s*$/;
  4809. var reSection = /^\s*\[(.*)\]\s*$/;
  4810. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  4811. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  4812. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  4813. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  4814. var currentLang = '*';
  4815. var genericLang = lang.split('-', 1)[0];
  4816. var skipLang = false;
  4817. var match = '';
  4818. function nextEntry() {
  4819. while (true) {
  4820. if (!entries.length) {
  4821. parsedRawLinesCallback();
  4822. return;
  4823. }
  4824. var line = entries.shift();
  4825. if (reComment.test(line)) continue;
  4826. if (extendedSyntax) {
  4827. match = reSection.exec(line);
  4828. if (match) {
  4829. currentLang = match[1].toLowerCase();
  4830. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  4831. continue;
  4832. } else if (skipLang) {
  4833. continue;
  4834. }
  4835. match = reImport.exec(line);
  4836. if (match) {
  4837. loadImport(baseURL + match[1], nextEntry);
  4838. return;
  4839. }
  4840. }
  4841. var tmp = line.match(reSplit);
  4842. if (tmp && tmp.length == 3) {
  4843. dictionary[tmp[1]] = evalString(tmp[2]);
  4844. }
  4845. }
  4846. }
  4847. nextEntry();
  4848. }
  4849. function loadImport(url, callback) {
  4850. xhrLoadText(url, function (content) {
  4851. parseRawLines(content, false, callback);
  4852. }, function () {
  4853. console.warn(url + ' not found.');
  4854. callback();
  4855. });
  4856. }
  4857. parseRawLines(text, true, function () {
  4858. parsedPropertiesCallback(dictionary);
  4859. });
  4860. }
  4861. xhrLoadText(href, function (response) {
  4862. gTextData += response;
  4863. parseProperties(response, function (data) {
  4864. for (var key in data) {
  4865. var id,
  4866. prop,
  4867. index = key.lastIndexOf('.');
  4868. if (index > 0) {
  4869. id = key.substring(0, index);
  4870. prop = key.substring(index + 1);
  4871. } else {
  4872. id = key;
  4873. prop = gTextProp;
  4874. }
  4875. if (!gL10nData[id]) {
  4876. gL10nData[id] = {};
  4877. }
  4878. gL10nData[id][prop] = data[key];
  4879. }
  4880. if (successCallback) {
  4881. successCallback();
  4882. }
  4883. });
  4884. }, failureCallback);
  4885. }
  4886. function loadLocale(lang, callback) {
  4887. if (lang) {
  4888. lang = lang.toLowerCase();
  4889. }
  4890. callback = callback || function _callback() {};
  4891. clear();
  4892. gLanguage = lang;
  4893. var langLinks = getL10nResourceLinks();
  4894. var langCount = langLinks.length;
  4895. if (langCount === 0) {
  4896. var dict = getL10nDictionary();
  4897. if (dict && dict.locales && dict.default_locale) {
  4898. console.log('using the embedded JSON directory, early way out');
  4899. gL10nData = dict.locales[lang];
  4900. if (!gL10nData) {
  4901. var defaultLocale = dict.default_locale.toLowerCase();
  4902. for (var anyCaseLang in dict.locales) {
  4903. anyCaseLang = anyCaseLang.toLowerCase();
  4904. if (anyCaseLang === lang) {
  4905. gL10nData = dict.locales[lang];
  4906. break;
  4907. } else if (anyCaseLang === defaultLocale) {
  4908. gL10nData = dict.locales[defaultLocale];
  4909. }
  4910. }
  4911. }
  4912. callback();
  4913. } else {
  4914. console.log('no resource to load, early way out');
  4915. }
  4916. gReadyState = 'complete';
  4917. return;
  4918. }
  4919. var onResourceLoaded = null;
  4920. var gResourceCount = 0;
  4921. onResourceLoaded = function () {
  4922. gResourceCount++;
  4923. if (gResourceCount >= langCount) {
  4924. callback();
  4925. gReadyState = 'complete';
  4926. }
  4927. };
  4928. function L10nResourceLink(link) {
  4929. var href = link.href;
  4930. this.load = function (lang, callback) {
  4931. parseResource(href, lang, callback, function () {
  4932. console.warn(href + ' not found.');
  4933. console.warn('"' + lang + '" resource not found');
  4934. gLanguage = '';
  4935. callback();
  4936. });
  4937. };
  4938. }
  4939. for (var i = 0; i < langCount; i++) {
  4940. var resource = new L10nResourceLink(langLinks[i]);
  4941. resource.load(lang, onResourceLoaded);
  4942. }
  4943. }
  4944. function clear() {
  4945. gL10nData = {};
  4946. gTextData = '';
  4947. gLanguage = '';
  4948. }
  4949. function getPluralRules(lang) {
  4950. var locales2rules = {
  4951. 'af': 3,
  4952. 'ak': 4,
  4953. 'am': 4,
  4954. 'ar': 1,
  4955. 'asa': 3,
  4956. 'az': 0,
  4957. 'be': 11,
  4958. 'bem': 3,
  4959. 'bez': 3,
  4960. 'bg': 3,
  4961. 'bh': 4,
  4962. 'bm': 0,
  4963. 'bn': 3,
  4964. 'bo': 0,
  4965. 'br': 20,
  4966. 'brx': 3,
  4967. 'bs': 11,
  4968. 'ca': 3,
  4969. 'cgg': 3,
  4970. 'chr': 3,
  4971. 'cs': 12,
  4972. 'cy': 17,
  4973. 'da': 3,
  4974. 'de': 3,
  4975. 'dv': 3,
  4976. 'dz': 0,
  4977. 'ee': 3,
  4978. 'el': 3,
  4979. 'en': 3,
  4980. 'eo': 3,
  4981. 'es': 3,
  4982. 'et': 3,
  4983. 'eu': 3,
  4984. 'fa': 0,
  4985. 'ff': 5,
  4986. 'fi': 3,
  4987. 'fil': 4,
  4988. 'fo': 3,
  4989. 'fr': 5,
  4990. 'fur': 3,
  4991. 'fy': 3,
  4992. 'ga': 8,
  4993. 'gd': 24,
  4994. 'gl': 3,
  4995. 'gsw': 3,
  4996. 'gu': 3,
  4997. 'guw': 4,
  4998. 'gv': 23,
  4999. 'ha': 3,
  5000. 'haw': 3,
  5001. 'he': 2,
  5002. 'hi': 4,
  5003. 'hr': 11,
  5004. 'hu': 0,
  5005. 'id': 0,
  5006. 'ig': 0,
  5007. 'ii': 0,
  5008. 'is': 3,
  5009. 'it': 3,
  5010. 'iu': 7,
  5011. 'ja': 0,
  5012. 'jmc': 3,
  5013. 'jv': 0,
  5014. 'ka': 0,
  5015. 'kab': 5,
  5016. 'kaj': 3,
  5017. 'kcg': 3,
  5018. 'kde': 0,
  5019. 'kea': 0,
  5020. 'kk': 3,
  5021. 'kl': 3,
  5022. 'km': 0,
  5023. 'kn': 0,
  5024. 'ko': 0,
  5025. 'ksb': 3,
  5026. 'ksh': 21,
  5027. 'ku': 3,
  5028. 'kw': 7,
  5029. 'lag': 18,
  5030. 'lb': 3,
  5031. 'lg': 3,
  5032. 'ln': 4,
  5033. 'lo': 0,
  5034. 'lt': 10,
  5035. 'lv': 6,
  5036. 'mas': 3,
  5037. 'mg': 4,
  5038. 'mk': 16,
  5039. 'ml': 3,
  5040. 'mn': 3,
  5041. 'mo': 9,
  5042. 'mr': 3,
  5043. 'ms': 0,
  5044. 'mt': 15,
  5045. 'my': 0,
  5046. 'nah': 3,
  5047. 'naq': 7,
  5048. 'nb': 3,
  5049. 'nd': 3,
  5050. 'ne': 3,
  5051. 'nl': 3,
  5052. 'nn': 3,
  5053. 'no': 3,
  5054. 'nr': 3,
  5055. 'nso': 4,
  5056. 'ny': 3,
  5057. 'nyn': 3,
  5058. 'om': 3,
  5059. 'or': 3,
  5060. 'pa': 3,
  5061. 'pap': 3,
  5062. 'pl': 13,
  5063. 'ps': 3,
  5064. 'pt': 3,
  5065. 'rm': 3,
  5066. 'ro': 9,
  5067. 'rof': 3,
  5068. 'ru': 11,
  5069. 'rwk': 3,
  5070. 'sah': 0,
  5071. 'saq': 3,
  5072. 'se': 7,
  5073. 'seh': 3,
  5074. 'ses': 0,
  5075. 'sg': 0,
  5076. 'sh': 11,
  5077. 'shi': 19,
  5078. 'sk': 12,
  5079. 'sl': 14,
  5080. 'sma': 7,
  5081. 'smi': 7,
  5082. 'smj': 7,
  5083. 'smn': 7,
  5084. 'sms': 7,
  5085. 'sn': 3,
  5086. 'so': 3,
  5087. 'sq': 3,
  5088. 'sr': 11,
  5089. 'ss': 3,
  5090. 'ssy': 3,
  5091. 'st': 3,
  5092. 'sv': 3,
  5093. 'sw': 3,
  5094. 'syr': 3,
  5095. 'ta': 3,
  5096. 'te': 3,
  5097. 'teo': 3,
  5098. 'th': 0,
  5099. 'ti': 4,
  5100. 'tig': 3,
  5101. 'tk': 3,
  5102. 'tl': 4,
  5103. 'tn': 3,
  5104. 'to': 0,
  5105. 'tr': 0,
  5106. 'ts': 3,
  5107. 'tzm': 22,
  5108. 'uk': 11,
  5109. 'ur': 3,
  5110. 've': 3,
  5111. 'vi': 0,
  5112. 'vun': 3,
  5113. 'wa': 4,
  5114. 'wae': 3,
  5115. 'wo': 0,
  5116. 'xh': 3,
  5117. 'xog': 3,
  5118. 'yo': 0,
  5119. 'zh': 0,
  5120. 'zu': 3
  5121. };
  5122. function isIn(n, list) {
  5123. return list.indexOf(n) !== -1;
  5124. }
  5125. function isBetween(n, start, end) {
  5126. return start <= n && n <= end;
  5127. }
  5128. var pluralRules = {
  5129. '0': function (n) {
  5130. return 'other';
  5131. },
  5132. '1': function (n) {
  5133. if (isBetween(n % 100, 3, 10)) return 'few';
  5134. if (n === 0) return 'zero';
  5135. if (isBetween(n % 100, 11, 99)) return 'many';
  5136. if (n == 2) return 'two';
  5137. if (n == 1) return 'one';
  5138. return 'other';
  5139. },
  5140. '2': function (n) {
  5141. if (n !== 0 && n % 10 === 0) return 'many';
  5142. if (n == 2) return 'two';
  5143. if (n == 1) return 'one';
  5144. return 'other';
  5145. },
  5146. '3': function (n) {
  5147. if (n == 1) return 'one';
  5148. return 'other';
  5149. },
  5150. '4': function (n) {
  5151. if (isBetween(n, 0, 1)) return 'one';
  5152. return 'other';
  5153. },
  5154. '5': function (n) {
  5155. if (isBetween(n, 0, 2) && n != 2) return 'one';
  5156. return 'other';
  5157. },
  5158. '6': function (n) {
  5159. if (n === 0) return 'zero';
  5160. if (n % 10 == 1 && n % 100 != 11) return 'one';
  5161. return 'other';
  5162. },
  5163. '7': function (n) {
  5164. if (n == 2) return 'two';
  5165. if (n == 1) return 'one';
  5166. return 'other';
  5167. },
  5168. '8': function (n) {
  5169. if (isBetween(n, 3, 6)) return 'few';
  5170. if (isBetween(n, 7, 10)) return 'many';
  5171. if (n == 2) return 'two';
  5172. if (n == 1) return 'one';
  5173. return 'other';
  5174. },
  5175. '9': function (n) {
  5176. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  5177. if (n == 1) return 'one';
  5178. return 'other';
  5179. },
  5180. '10': function (n) {
  5181. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  5182. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  5183. return 'other';
  5184. },
  5185. '11': function (n) {
  5186. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  5187. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  5188. if (n % 10 == 1 && n % 100 != 11) return 'one';
  5189. return 'other';
  5190. },
  5191. '12': function (n) {
  5192. if (isBetween(n, 2, 4)) return 'few';
  5193. if (n == 1) return 'one';
  5194. return 'other';
  5195. },
  5196. '13': function (n) {
  5197. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  5198. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  5199. if (n == 1) return 'one';
  5200. return 'other';
  5201. },
  5202. '14': function (n) {
  5203. if (isBetween(n % 100, 3, 4)) return 'few';
  5204. if (n % 100 == 2) return 'two';
  5205. if (n % 100 == 1) return 'one';
  5206. return 'other';
  5207. },
  5208. '15': function (n) {
  5209. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  5210. if (isBetween(n % 100, 11, 19)) return 'many';
  5211. if (n == 1) return 'one';
  5212. return 'other';
  5213. },
  5214. '16': function (n) {
  5215. if (n % 10 == 1 && n != 11) return 'one';
  5216. return 'other';
  5217. },
  5218. '17': function (n) {
  5219. if (n == 3) return 'few';
  5220. if (n === 0) return 'zero';
  5221. if (n == 6) return 'many';
  5222. if (n == 2) return 'two';
  5223. if (n == 1) return 'one';
  5224. return 'other';
  5225. },
  5226. '18': function (n) {
  5227. if (n === 0) return 'zero';
  5228. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  5229. return 'other';
  5230. },
  5231. '19': function (n) {
  5232. if (isBetween(n, 2, 10)) return 'few';
  5233. if (isBetween(n, 0, 1)) return 'one';
  5234. return 'other';
  5235. },
  5236. '20': function (n) {
  5237. 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';
  5238. if (n % 1000000 === 0 && n !== 0) return 'many';
  5239. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  5240. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  5241. return 'other';
  5242. },
  5243. '21': function (n) {
  5244. if (n === 0) return 'zero';
  5245. if (n == 1) return 'one';
  5246. return 'other';
  5247. },
  5248. '22': function (n) {
  5249. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  5250. return 'other';
  5251. },
  5252. '23': function (n) {
  5253. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  5254. return 'other';
  5255. },
  5256. '24': function (n) {
  5257. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  5258. if (isIn(n, [2, 12])) return 'two';
  5259. if (isIn(n, [1, 11])) return 'one';
  5260. return 'other';
  5261. }
  5262. };
  5263. var index = locales2rules[lang.replace(/-.*$/, '')];
  5264. if (!(index in pluralRules)) {
  5265. console.warn('plural form unknown for [' + lang + ']');
  5266. return function () {
  5267. return 'other';
  5268. };
  5269. }
  5270. return pluralRules[index];
  5271. }
  5272. gMacros.plural = function (str, param, key, prop) {
  5273. var n = parseFloat(param);
  5274. if (isNaN(n)) return str;
  5275. if (prop != gTextProp) return str;
  5276. if (!gMacros._pluralRules) {
  5277. gMacros._pluralRules = getPluralRules(gLanguage);
  5278. }
  5279. var index = '[' + gMacros._pluralRules(n) + ']';
  5280. if (n === 0 && key + '[zero]' in gL10nData) {
  5281. str = gL10nData[key + '[zero]'][prop];
  5282. } else if (n == 1 && key + '[one]' in gL10nData) {
  5283. str = gL10nData[key + '[one]'][prop];
  5284. } else if (n == 2 && key + '[two]' in gL10nData) {
  5285. str = gL10nData[key + '[two]'][prop];
  5286. } else if (key + index in gL10nData) {
  5287. str = gL10nData[key + index][prop];
  5288. } else if (key + '[other]' in gL10nData) {
  5289. str = gL10nData[key + '[other]'][prop];
  5290. }
  5291. return str;
  5292. };
  5293. function getL10nData(key, args, fallback) {
  5294. var data = gL10nData[key];
  5295. if (!data) {
  5296. console.warn('#' + key + ' is undefined.');
  5297. if (!fallback) {
  5298. return null;
  5299. }
  5300. data = fallback;
  5301. }
  5302. var rv = {};
  5303. for (var prop in data) {
  5304. var str = data[prop];
  5305. str = substIndexes(str, args, key, prop);
  5306. str = substArguments(str, args, key);
  5307. rv[prop] = str;
  5308. }
  5309. return rv;
  5310. }
  5311. function substIndexes(str, args, key, prop) {
  5312. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  5313. var reMatch = reIndex.exec(str);
  5314. if (!reMatch || !reMatch.length) return str;
  5315. var macroName = reMatch[1];
  5316. var paramName = reMatch[2];
  5317. var param;
  5318. if (args && paramName in args) {
  5319. param = args[paramName];
  5320. } else if (paramName in gL10nData) {
  5321. param = gL10nData[paramName];
  5322. }
  5323. if (macroName in gMacros) {
  5324. var macro = gMacros[macroName];
  5325. str = macro(str, param, key, prop);
  5326. }
  5327. return str;
  5328. }
  5329. function substArguments(str, args, key) {
  5330. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  5331. return str.replace(reArgs, function (matched_text, arg) {
  5332. if (args && arg in args) {
  5333. return args[arg];
  5334. }
  5335. if (arg in gL10nData) {
  5336. return gL10nData[arg];
  5337. }
  5338. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  5339. return matched_text;
  5340. });
  5341. }
  5342. function translateElement(element) {
  5343. var l10n = getL10nAttributes(element);
  5344. if (!l10n.id) return;
  5345. var data = getL10nData(l10n.id, l10n.args);
  5346. if (!data) {
  5347. console.warn('#' + l10n.id + ' is undefined.');
  5348. return;
  5349. }
  5350. if (data[gTextProp]) {
  5351. if (getChildElementCount(element) === 0) {
  5352. element[gTextProp] = data[gTextProp];
  5353. } else {
  5354. var children = element.childNodes;
  5355. var found = false;
  5356. for (var i = 0, l = children.length; i < l; i++) {
  5357. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  5358. if (found) {
  5359. children[i].nodeValue = '';
  5360. } else {
  5361. children[i].nodeValue = data[gTextProp];
  5362. found = true;
  5363. }
  5364. }
  5365. }
  5366. if (!found) {
  5367. var textNode = document.createTextNode(data[gTextProp]);
  5368. element.prepend(textNode);
  5369. }
  5370. }
  5371. delete data[gTextProp];
  5372. }
  5373. for (var k in data) {
  5374. element[k] = data[k];
  5375. }
  5376. }
  5377. function getChildElementCount(element) {
  5378. if (element.children) {
  5379. return element.children.length;
  5380. }
  5381. if (typeof element.childElementCount !== 'undefined') {
  5382. return element.childElementCount;
  5383. }
  5384. var count = 0;
  5385. for (var i = 0; i < element.childNodes.length; i++) {
  5386. count += element.nodeType === 1 ? 1 : 0;
  5387. }
  5388. return count;
  5389. }
  5390. function translateFragment(element) {
  5391. element = element || document.documentElement;
  5392. var children = getTranslatableChildren(element);
  5393. var elementCount = children.length;
  5394. for (var i = 0; i < elementCount; i++) {
  5395. translateElement(children[i]);
  5396. }
  5397. translateElement(element);
  5398. }
  5399. return {
  5400. get: function (key, args, fallbackString) {
  5401. var index = key.lastIndexOf('.');
  5402. var prop = gTextProp;
  5403. if (index > 0) {
  5404. prop = key.substring(index + 1);
  5405. key = key.substring(0, index);
  5406. }
  5407. var fallback;
  5408. if (fallbackString) {
  5409. fallback = {};
  5410. fallback[prop] = fallbackString;
  5411. }
  5412. var data = getL10nData(key, args, fallback);
  5413. if (data && prop in data) {
  5414. return data[prop];
  5415. }
  5416. return '{{' + key + '}}';
  5417. },
  5418. getData: function () {
  5419. return gL10nData;
  5420. },
  5421. getText: function () {
  5422. return gTextData;
  5423. },
  5424. getLanguage: function () {
  5425. return gLanguage;
  5426. },
  5427. setLanguage: function (lang, callback) {
  5428. loadLocale(lang, function () {
  5429. if (callback) callback();
  5430. });
  5431. },
  5432. getDirection: function () {
  5433. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  5434. var shortCode = gLanguage.split('-', 1)[0];
  5435. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  5436. },
  5437. translate: translateFragment,
  5438. getReadyState: function () {
  5439. return gReadyState;
  5440. },
  5441. ready: function (callback) {
  5442. if (!callback) {
  5443. return;
  5444. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  5445. window.setTimeout(function () {
  5446. callback();
  5447. });
  5448. } else if (document.addEventListener) {
  5449. document.addEventListener('localized', function once() {
  5450. document.removeEventListener('localized', once);
  5451. callback();
  5452. });
  5453. }
  5454. }
  5455. };
  5456. }(window, document);
  5457. /***/ }),
  5458. /* 21 */
  5459. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5460. Object.defineProperty(exports, "__esModule", ({
  5461. value: true
  5462. }));
  5463. exports.PDFFindController = exports.FindState = void 0;
  5464. var _pdfjsLib = __w_pdfjs_require__(3);
  5465. var _pdf_find_utils = __w_pdfjs_require__(22);
  5466. var _ui_utils = __w_pdfjs_require__(7);
  5467. const FindState = {
  5468. FOUND: 0,
  5469. NOT_FOUND: 1,
  5470. WRAPPED: 2,
  5471. PENDING: 3
  5472. };
  5473. exports.FindState = FindState;
  5474. const FIND_TIMEOUT = 250;
  5475. const MATCH_SCROLL_OFFSET_TOP = -50;
  5476. const MATCH_SCROLL_OFFSET_LEFT = -400;
  5477. const CHARACTERS_TO_NORMALIZE = {
  5478. "\u2010": "-",
  5479. "\u2018": "'",
  5480. "\u2019": "'",
  5481. "\u201A": "'",
  5482. "\u201B": "'",
  5483. "\u201C": '"',
  5484. "\u201D": '"',
  5485. "\u201E": '"',
  5486. "\u201F": '"',
  5487. "\u00BC": "1/4",
  5488. "\u00BD": "1/2",
  5489. "\u00BE": "3/4"
  5490. };
  5491. const DIACRITICS_EXCEPTION = new Set([0x3099, 0x309a, 0x094d, 0x09cd, 0x0a4d, 0x0acd, 0x0b4d, 0x0bcd, 0x0c4d, 0x0ccd, 0x0d3b, 0x0d3c, 0x0d4d, 0x0dca, 0x0e3a, 0x0eba, 0x0f84, 0x1039, 0x103a, 0x1714, 0x1734, 0x17d2, 0x1a60, 0x1b44, 0x1baa, 0x1bab, 0x1bf2, 0x1bf3, 0x2d7f, 0xa806, 0xa82c, 0xa8c4, 0xa953, 0xa9c0, 0xaaf6, 0xabed, 0x0c56, 0x0f71, 0x0f72, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f80, 0x0f74]);
  5492. const DIACRITICS_EXCEPTION_STR = [...DIACRITICS_EXCEPTION.values()].map(x => String.fromCharCode(x)).join("");
  5493. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  5494. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  5495. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  5496. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  5497. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  5498. const SYLLABLES_LENGTHS = new Map();
  5499. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  5500. let noSyllablesRegExp = null;
  5501. let withSyllablesRegExp = null;
  5502. function normalize(text) {
  5503. const syllablePositions = [];
  5504. let m;
  5505. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  5506. let {
  5507. index
  5508. } = m;
  5509. for (const char of m[0]) {
  5510. let len = SYLLABLES_LENGTHS.get(char);
  5511. if (!len) {
  5512. len = char.normalize("NFD").length;
  5513. SYLLABLES_LENGTHS.set(char, len);
  5514. }
  5515. syllablePositions.push([len, index++]);
  5516. }
  5517. }
  5518. let normalizationRegex;
  5519. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  5520. normalizationRegex = noSyllablesRegExp;
  5521. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  5522. normalizationRegex = withSyllablesRegExp;
  5523. } else {
  5524. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  5525. const regexp = `([${replace}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(\\n)`;
  5526. if (syllablePositions.length === 0) {
  5527. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  5528. } else {
  5529. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  5530. }
  5531. }
  5532. const rawDiacriticsPositions = [];
  5533. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  5534. rawDiacriticsPositions.push([m[0].length, m.index]);
  5535. }
  5536. let normalized = text.normalize("NFD");
  5537. const positions = [[0, 0]];
  5538. let rawDiacriticsIndex = 0;
  5539. let syllableIndex = 0;
  5540. let shift = 0;
  5541. let shiftOrigin = 0;
  5542. let eol = 0;
  5543. let hasDiacritics = false;
  5544. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, i) => {
  5545. i -= shiftOrigin;
  5546. if (p1) {
  5547. const replacement = CHARACTERS_TO_NORMALIZE[match];
  5548. const jj = replacement.length;
  5549. for (let j = 1; j < jj; j++) {
  5550. positions.push([i - shift + j, shift - j]);
  5551. }
  5552. shift -= jj - 1;
  5553. return replacement;
  5554. }
  5555. if (p2) {
  5556. const hasTrailingDashEOL = p2.endsWith("\n");
  5557. const len = hasTrailingDashEOL ? p2.length - 2 : p2.length;
  5558. hasDiacritics = true;
  5559. let jj = len;
  5560. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  5561. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  5562. ++rawDiacriticsIndex;
  5563. }
  5564. for (let j = 1; j <= jj; j++) {
  5565. positions.push([i - 1 - shift + j, shift - j]);
  5566. }
  5567. shift -= jj;
  5568. shiftOrigin += jj;
  5569. if (hasTrailingDashEOL) {
  5570. i += len - 1;
  5571. positions.push([i - shift + 1, 1 + shift]);
  5572. shift += 1;
  5573. shiftOrigin += 1;
  5574. eol += 1;
  5575. return p2.slice(0, len);
  5576. }
  5577. return p2;
  5578. }
  5579. if (p3) {
  5580. positions.push([i - shift + 1, 1 + shift]);
  5581. shift += 1;
  5582. shiftOrigin += 1;
  5583. eol += 1;
  5584. return p3.charAt(0);
  5585. }
  5586. if (p4) {
  5587. positions.push([i - shift + 1, shift - 1]);
  5588. shift -= 1;
  5589. shiftOrigin += 1;
  5590. eol += 1;
  5591. return " ";
  5592. }
  5593. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  5594. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  5595. ++syllableIndex;
  5596. for (let j = 1; j <= newCharLen; j++) {
  5597. positions.push([i - (shift - j), shift - j]);
  5598. }
  5599. shift -= newCharLen;
  5600. shiftOrigin += newCharLen;
  5601. }
  5602. return p5;
  5603. });
  5604. positions.push([normalized.length, shift]);
  5605. return [normalized, positions, hasDiacritics];
  5606. }
  5607. function getOriginalIndex(diffs, pos, len) {
  5608. if (!diffs) {
  5609. return [pos, len];
  5610. }
  5611. const start = pos;
  5612. const end = pos + len;
  5613. let i = (0, _pdfjsLib.binarySearchFirstItem)(diffs, x => x[0] >= start);
  5614. if (diffs[i][0] > start) {
  5615. --i;
  5616. }
  5617. let j = (0, _pdfjsLib.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  5618. if (diffs[j][0] > end) {
  5619. --j;
  5620. }
  5621. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  5622. }
  5623. class PDFFindController {
  5624. constructor({
  5625. linkService,
  5626. eventBus
  5627. }) {
  5628. this._linkService = linkService;
  5629. this._eventBus = eventBus;
  5630. this.#reset();
  5631. eventBus._on("find", this.#onFind.bind(this));
  5632. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  5633. }
  5634. get highlightMatches() {
  5635. return this._highlightMatches;
  5636. }
  5637. get pageMatches() {
  5638. return this._pageMatches;
  5639. }
  5640. get pageMatchesLength() {
  5641. return this._pageMatchesLength;
  5642. }
  5643. get selected() {
  5644. return this._selected;
  5645. }
  5646. get state() {
  5647. return this._state;
  5648. }
  5649. setDocument(pdfDocument) {
  5650. if (this._pdfDocument) {
  5651. this.#reset();
  5652. }
  5653. if (!pdfDocument) {
  5654. return;
  5655. }
  5656. this._pdfDocument = pdfDocument;
  5657. this._firstPageCapability.resolve();
  5658. }
  5659. #onFind(state) {
  5660. if (!state) {
  5661. return;
  5662. }
  5663. const pdfDocument = this._pdfDocument;
  5664. const {
  5665. type
  5666. } = state;
  5667. if (this._state === null || this.#shouldDirtyMatch(state)) {
  5668. this._dirtyMatch = true;
  5669. }
  5670. this._state = state;
  5671. if (type !== "highlightallchange") {
  5672. this.#updateUIState(FindState.PENDING);
  5673. }
  5674. this._firstPageCapability.promise.then(() => {
  5675. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5676. return;
  5677. }
  5678. this.#extractText();
  5679. const findbarClosed = !this._highlightMatches;
  5680. const pendingTimeout = !!this._findTimeout;
  5681. if (this._findTimeout) {
  5682. clearTimeout(this._findTimeout);
  5683. this._findTimeout = null;
  5684. }
  5685. if (!type) {
  5686. this._findTimeout = setTimeout(() => {
  5687. this.#nextMatch();
  5688. this._findTimeout = null;
  5689. }, FIND_TIMEOUT);
  5690. } else if (this._dirtyMatch) {
  5691. this.#nextMatch();
  5692. } else if (type === "again") {
  5693. this.#nextMatch();
  5694. if (findbarClosed && this._state.highlightAll) {
  5695. this.#updateAllPages();
  5696. }
  5697. } else if (type === "highlightallchange") {
  5698. if (pendingTimeout) {
  5699. this.#nextMatch();
  5700. } else {
  5701. this._highlightMatches = true;
  5702. }
  5703. this.#updateAllPages();
  5704. } else {
  5705. this.#nextMatch();
  5706. }
  5707. });
  5708. }
  5709. scrollMatchIntoView({
  5710. element = null,
  5711. selectedLeft = 0,
  5712. pageIndex = -1,
  5713. matchIndex = -1
  5714. }) {
  5715. if (!this._scrollMatches || !element) {
  5716. return;
  5717. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  5718. return;
  5719. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  5720. return;
  5721. }
  5722. this._scrollMatches = false;
  5723. const spot = {
  5724. top: MATCH_SCROLL_OFFSET_TOP,
  5725. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  5726. };
  5727. (0, _ui_utils.scrollIntoView)(element, spot, true);
  5728. }
  5729. #reset() {
  5730. this._highlightMatches = false;
  5731. this._scrollMatches = false;
  5732. this._pdfDocument = null;
  5733. this._pageMatches = [];
  5734. this._pageMatchesLength = [];
  5735. this._state = null;
  5736. this._selected = {
  5737. pageIdx: -1,
  5738. matchIdx: -1
  5739. };
  5740. this._offset = {
  5741. pageIdx: null,
  5742. matchIdx: null,
  5743. wrapped: false
  5744. };
  5745. this._extractTextPromises = [];
  5746. this._pageContents = [];
  5747. this._pageDiffs = [];
  5748. this._hasDiacritics = [];
  5749. this._matchesCountTotal = 0;
  5750. this._pagesToSearch = null;
  5751. this._pendingFindMatches = new Set();
  5752. this._resumePageIdx = null;
  5753. this._dirtyMatch = false;
  5754. clearTimeout(this._findTimeout);
  5755. this._findTimeout = null;
  5756. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  5757. }
  5758. get #query() {
  5759. if (this._state.query !== this._rawQuery) {
  5760. this._rawQuery = this._state.query;
  5761. [this._normalizedQuery] = normalize(this._state.query);
  5762. }
  5763. return this._normalizedQuery;
  5764. }
  5765. #shouldDirtyMatch(state) {
  5766. if (state.query !== this._state.query) {
  5767. return true;
  5768. }
  5769. switch (state.type) {
  5770. case "again":
  5771. const pageNumber = this._selected.pageIdx + 1;
  5772. const linkService = this._linkService;
  5773. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  5774. return true;
  5775. }
  5776. return false;
  5777. case "highlightallchange":
  5778. return false;
  5779. }
  5780. return true;
  5781. }
  5782. #isEntireWord(content, startIdx, length) {
  5783. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  5784. if (match) {
  5785. const first = content.charCodeAt(startIdx);
  5786. const limit = match[1].charCodeAt(0);
  5787. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5788. return false;
  5789. }
  5790. }
  5791. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  5792. if (match) {
  5793. const last = content.charCodeAt(startIdx + length - 1);
  5794. const limit = match[1].charCodeAt(0);
  5795. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5796. return false;
  5797. }
  5798. }
  5799. return true;
  5800. }
  5801. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  5802. const matches = [],
  5803. matchesLength = [];
  5804. const diffs = this._pageDiffs[pageIndex];
  5805. let match;
  5806. while ((match = query.exec(pageContent)) !== null) {
  5807. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  5808. continue;
  5809. }
  5810. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  5811. if (matchLen) {
  5812. matches.push(matchPos);
  5813. matchesLength.push(matchLen);
  5814. }
  5815. }
  5816. this._pageMatches[pageIndex] = matches;
  5817. this._pageMatchesLength[pageIndex] = matchesLength;
  5818. }
  5819. #convertToRegExpString(query, hasDiacritics) {
  5820. const {
  5821. matchDiacritics
  5822. } = this._state;
  5823. let isUnicode = false;
  5824. query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  5825. if (p1) {
  5826. return `[ ]*\\${p1}[ ]*`;
  5827. }
  5828. if (p2) {
  5829. return `[ ]*${p2}[ ]*`;
  5830. }
  5831. if (p3) {
  5832. return "[ ]+";
  5833. }
  5834. if (matchDiacritics) {
  5835. return p4 || p5;
  5836. }
  5837. if (p4) {
  5838. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5839. }
  5840. if (hasDiacritics) {
  5841. isUnicode = true;
  5842. return `${p5}\\p{M}*`;
  5843. }
  5844. return p5;
  5845. });
  5846. const trailingSpaces = "[ ]*";
  5847. if (query.endsWith(trailingSpaces)) {
  5848. query = query.slice(0, query.length - trailingSpaces.length);
  5849. }
  5850. if (matchDiacritics) {
  5851. if (hasDiacritics) {
  5852. isUnicode = true;
  5853. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5854. }
  5855. }
  5856. return [isUnicode, query];
  5857. }
  5858. #calculateMatch(pageIndex) {
  5859. let query = this.#query;
  5860. if (query.length === 0) {
  5861. return;
  5862. }
  5863. const {
  5864. caseSensitive,
  5865. entireWord,
  5866. phraseSearch
  5867. } = this._state;
  5868. const pageContent = this._pageContents[pageIndex];
  5869. const hasDiacritics = this._hasDiacritics[pageIndex];
  5870. let isUnicode = false;
  5871. if (phraseSearch) {
  5872. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  5873. } else {
  5874. const match = query.match(/\S+/g);
  5875. if (match) {
  5876. query = match.sort().reverse().map(q => {
  5877. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  5878. isUnicode ||= isUnicodePart;
  5879. return `(${queryPart})`;
  5880. }).join("|");
  5881. }
  5882. }
  5883. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  5884. query = new RegExp(query, flags);
  5885. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  5886. if (this._state.highlightAll) {
  5887. this.#updatePage(pageIndex);
  5888. }
  5889. if (this._resumePageIdx === pageIndex) {
  5890. this._resumePageIdx = null;
  5891. this.#nextPageMatch();
  5892. }
  5893. const pageMatchesCount = this._pageMatches[pageIndex].length;
  5894. if (pageMatchesCount > 0) {
  5895. this._matchesCountTotal += pageMatchesCount;
  5896. this.#updateUIResultsCount();
  5897. }
  5898. }
  5899. #extractText() {
  5900. if (this._extractTextPromises.length > 0) {
  5901. return;
  5902. }
  5903. let promise = Promise.resolve();
  5904. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5905. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  5906. this._extractTextPromises[i] = extractTextCapability.promise;
  5907. promise = promise.then(() => {
  5908. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5909. return pdfPage.getTextContent();
  5910. }).then(textContent => {
  5911. const strBuf = [];
  5912. for (const textItem of textContent.items) {
  5913. strBuf.push(textItem.str);
  5914. if (textItem.hasEOL) {
  5915. strBuf.push("\n");
  5916. }
  5917. }
  5918. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5919. extractTextCapability.resolve();
  5920. }, reason => {
  5921. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5922. this._pageContents[i] = "";
  5923. this._pageDiffs[i] = null;
  5924. this._hasDiacritics[i] = false;
  5925. extractTextCapability.resolve();
  5926. });
  5927. });
  5928. }
  5929. }
  5930. #updatePage(index) {
  5931. if (this._scrollMatches && this._selected.pageIdx === index) {
  5932. this._linkService.page = index + 1;
  5933. }
  5934. this._eventBus.dispatch("updatetextlayermatches", {
  5935. source: this,
  5936. pageIndex: index
  5937. });
  5938. }
  5939. #updateAllPages() {
  5940. this._eventBus.dispatch("updatetextlayermatches", {
  5941. source: this,
  5942. pageIndex: -1
  5943. });
  5944. }
  5945. #nextMatch() {
  5946. const previous = this._state.findPrevious;
  5947. const currentPageIndex = this._linkService.page - 1;
  5948. const numPages = this._linkService.pagesCount;
  5949. this._highlightMatches = true;
  5950. if (this._dirtyMatch) {
  5951. this._dirtyMatch = false;
  5952. this._selected.pageIdx = this._selected.matchIdx = -1;
  5953. this._offset.pageIdx = currentPageIndex;
  5954. this._offset.matchIdx = null;
  5955. this._offset.wrapped = false;
  5956. this._resumePageIdx = null;
  5957. this._pageMatches.length = 0;
  5958. this._pageMatchesLength.length = 0;
  5959. this._matchesCountTotal = 0;
  5960. this.#updateAllPages();
  5961. for (let i = 0; i < numPages; i++) {
  5962. if (this._pendingFindMatches.has(i)) {
  5963. continue;
  5964. }
  5965. this._pendingFindMatches.add(i);
  5966. this._extractTextPromises[i].then(() => {
  5967. this._pendingFindMatches.delete(i);
  5968. this.#calculateMatch(i);
  5969. });
  5970. }
  5971. }
  5972. if (this.#query === "") {
  5973. this.#updateUIState(FindState.FOUND);
  5974. return;
  5975. }
  5976. if (this._resumePageIdx) {
  5977. return;
  5978. }
  5979. const offset = this._offset;
  5980. this._pagesToSearch = numPages;
  5981. if (offset.matchIdx !== null) {
  5982. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5983. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5984. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5985. this.#updateMatch(true);
  5986. return;
  5987. }
  5988. this.#advanceOffsetPage(previous);
  5989. }
  5990. this.#nextPageMatch();
  5991. }
  5992. #matchesReady(matches) {
  5993. const offset = this._offset;
  5994. const numMatches = matches.length;
  5995. const previous = this._state.findPrevious;
  5996. if (numMatches) {
  5997. offset.matchIdx = previous ? numMatches - 1 : 0;
  5998. this.#updateMatch(true);
  5999. return true;
  6000. }
  6001. this.#advanceOffsetPage(previous);
  6002. if (offset.wrapped) {
  6003. offset.matchIdx = null;
  6004. if (this._pagesToSearch < 0) {
  6005. this.#updateMatch(false);
  6006. return true;
  6007. }
  6008. }
  6009. return false;
  6010. }
  6011. #nextPageMatch() {
  6012. if (this._resumePageIdx !== null) {
  6013. console.error("There can only be one pending page.");
  6014. }
  6015. let matches = null;
  6016. do {
  6017. const pageIdx = this._offset.pageIdx;
  6018. matches = this._pageMatches[pageIdx];
  6019. if (!matches) {
  6020. this._resumePageIdx = pageIdx;
  6021. break;
  6022. }
  6023. } while (!this.#matchesReady(matches));
  6024. }
  6025. #advanceOffsetPage(previous) {
  6026. const offset = this._offset;
  6027. const numPages = this._linkService.pagesCount;
  6028. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  6029. offset.matchIdx = null;
  6030. this._pagesToSearch--;
  6031. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  6032. offset.pageIdx = previous ? numPages - 1 : 0;
  6033. offset.wrapped = true;
  6034. }
  6035. }
  6036. #updateMatch(found = false) {
  6037. let state = FindState.NOT_FOUND;
  6038. const wrapped = this._offset.wrapped;
  6039. this._offset.wrapped = false;
  6040. if (found) {
  6041. const previousPage = this._selected.pageIdx;
  6042. this._selected.pageIdx = this._offset.pageIdx;
  6043. this._selected.matchIdx = this._offset.matchIdx;
  6044. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  6045. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  6046. this.#updatePage(previousPage);
  6047. }
  6048. }
  6049. this.#updateUIState(state, this._state.findPrevious);
  6050. if (this._selected.pageIdx !== -1) {
  6051. this._scrollMatches = true;
  6052. this.#updatePage(this._selected.pageIdx);
  6053. }
  6054. }
  6055. #onFindBarClose(evt) {
  6056. const pdfDocument = this._pdfDocument;
  6057. this._firstPageCapability.promise.then(() => {
  6058. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  6059. return;
  6060. }
  6061. if (this._findTimeout) {
  6062. clearTimeout(this._findTimeout);
  6063. this._findTimeout = null;
  6064. }
  6065. if (this._resumePageIdx) {
  6066. this._resumePageIdx = null;
  6067. this._dirtyMatch = true;
  6068. }
  6069. this.#updateUIState(FindState.FOUND);
  6070. this._highlightMatches = false;
  6071. this.#updateAllPages();
  6072. });
  6073. }
  6074. #requestMatchesCount() {
  6075. const {
  6076. pageIdx,
  6077. matchIdx
  6078. } = this._selected;
  6079. let current = 0,
  6080. total = this._matchesCountTotal;
  6081. if (matchIdx !== -1) {
  6082. for (let i = 0; i < pageIdx; i++) {
  6083. current += this._pageMatches[i]?.length || 0;
  6084. }
  6085. current += matchIdx + 1;
  6086. }
  6087. if (current < 1 || current > total) {
  6088. current = total = 0;
  6089. }
  6090. return {
  6091. current,
  6092. total
  6093. };
  6094. }
  6095. #updateUIResultsCount() {
  6096. this._eventBus.dispatch("updatefindmatchescount", {
  6097. source: this,
  6098. matchesCount: this.#requestMatchesCount()
  6099. });
  6100. }
  6101. #updateUIState(state, previous = false) {
  6102. this._eventBus.dispatch("updatefindcontrolstate", {
  6103. source: this,
  6104. state,
  6105. previous,
  6106. matchesCount: this.#requestMatchesCount(),
  6107. rawQuery: this._state?.query ?? null
  6108. });
  6109. }
  6110. }
  6111. exports.PDFFindController = PDFFindController;
  6112. /***/ }),
  6113. /* 22 */
  6114. /***/ ((__unused_webpack_module, exports) => {
  6115. Object.defineProperty(exports, "__esModule", ({
  6116. value: true
  6117. }));
  6118. exports.CharacterType = void 0;
  6119. exports.getCharacterType = getCharacterType;
  6120. const CharacterType = {
  6121. SPACE: 0,
  6122. ALPHA_LETTER: 1,
  6123. PUNCT: 2,
  6124. HAN_LETTER: 3,
  6125. KATAKANA_LETTER: 4,
  6126. HIRAGANA_LETTER: 5,
  6127. HALFWIDTH_KATAKANA_LETTER: 6,
  6128. THAI_LETTER: 7
  6129. };
  6130. exports.CharacterType = CharacterType;
  6131. function isAlphabeticalScript(charCode) {
  6132. return charCode < 0x2e80;
  6133. }
  6134. function isAscii(charCode) {
  6135. return (charCode & 0xff80) === 0;
  6136. }
  6137. function isAsciiAlpha(charCode) {
  6138. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  6139. }
  6140. function isAsciiDigit(charCode) {
  6141. return charCode >= 0x30 && charCode <= 0x39;
  6142. }
  6143. function isAsciiSpace(charCode) {
  6144. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  6145. }
  6146. function isHan(charCode) {
  6147. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  6148. }
  6149. function isKatakana(charCode) {
  6150. return charCode >= 0x30a0 && charCode <= 0x30ff;
  6151. }
  6152. function isHiragana(charCode) {
  6153. return charCode >= 0x3040 && charCode <= 0x309f;
  6154. }
  6155. function isHalfwidthKatakana(charCode) {
  6156. return charCode >= 0xff60 && charCode <= 0xff9f;
  6157. }
  6158. function isThai(charCode) {
  6159. return (charCode & 0xff80) === 0x0e00;
  6160. }
  6161. function getCharacterType(charCode) {
  6162. if (isAlphabeticalScript(charCode)) {
  6163. if (isAscii(charCode)) {
  6164. if (isAsciiSpace(charCode)) {
  6165. return CharacterType.SPACE;
  6166. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  6167. return CharacterType.ALPHA_LETTER;
  6168. }
  6169. return CharacterType.PUNCT;
  6170. } else if (isThai(charCode)) {
  6171. return CharacterType.THAI_LETTER;
  6172. } else if (charCode === 0xa0) {
  6173. return CharacterType.SPACE;
  6174. }
  6175. return CharacterType.ALPHA_LETTER;
  6176. }
  6177. if (isHan(charCode)) {
  6178. return CharacterType.HAN_LETTER;
  6179. } else if (isKatakana(charCode)) {
  6180. return CharacterType.KATAKANA_LETTER;
  6181. } else if (isHiragana(charCode)) {
  6182. return CharacterType.HIRAGANA_LETTER;
  6183. } else if (isHalfwidthKatakana(charCode)) {
  6184. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  6185. }
  6186. return CharacterType.ALPHA_LETTER;
  6187. }
  6188. /***/ }),
  6189. /* 23 */
  6190. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6191. Object.defineProperty(exports, "__esModule", ({
  6192. value: true
  6193. }));
  6194. exports.PDFHistory = void 0;
  6195. exports.isDestArraysEqual = isDestArraysEqual;
  6196. exports.isDestHashesEqual = isDestHashesEqual;
  6197. var _ui_utils = __w_pdfjs_require__(7);
  6198. var _event_utils = __w_pdfjs_require__(18);
  6199. const HASH_CHANGE_TIMEOUT = 1000;
  6200. const POSITION_UPDATED_THRESHOLD = 50;
  6201. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  6202. function getCurrentHash() {
  6203. return document.location.hash;
  6204. }
  6205. class PDFHistory {
  6206. constructor({
  6207. linkService,
  6208. eventBus
  6209. }) {
  6210. this.linkService = linkService;
  6211. this.eventBus = eventBus;
  6212. this._initialized = false;
  6213. this._fingerprint = "";
  6214. this.reset();
  6215. this._boundEvents = null;
  6216. this.eventBus._on("pagesinit", () => {
  6217. this._isPagesLoaded = false;
  6218. this.eventBus._on("pagesloaded", evt => {
  6219. this._isPagesLoaded = !!evt.pagesCount;
  6220. }, {
  6221. once: true
  6222. });
  6223. });
  6224. }
  6225. initialize({
  6226. fingerprint,
  6227. resetHistory = false,
  6228. updateUrl = false
  6229. }) {
  6230. if (!fingerprint || typeof fingerprint !== "string") {
  6231. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  6232. return;
  6233. }
  6234. if (this._initialized) {
  6235. this.reset();
  6236. }
  6237. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  6238. this._fingerprint = fingerprint;
  6239. this._updateUrl = updateUrl === true;
  6240. this._initialized = true;
  6241. this._bindEvents();
  6242. const state = window.history.state;
  6243. this._popStateInProgress = false;
  6244. this._blockHashChange = 0;
  6245. this._currentHash = getCurrentHash();
  6246. this._numPositionUpdates = 0;
  6247. this._uid = this._maxUid = 0;
  6248. this._destination = null;
  6249. this._position = null;
  6250. if (!this._isValidState(state, true) || resetHistory) {
  6251. const {
  6252. hash,
  6253. page,
  6254. rotation
  6255. } = this._parseCurrentHash(true);
  6256. if (!hash || reInitialized || resetHistory) {
  6257. this._pushOrReplaceState(null, true);
  6258. return;
  6259. }
  6260. this._pushOrReplaceState({
  6261. hash,
  6262. page,
  6263. rotation
  6264. }, true);
  6265. return;
  6266. }
  6267. const destination = state.destination;
  6268. this._updateInternalState(destination, state.uid, true);
  6269. if (destination.rotation !== undefined) {
  6270. this._initialRotation = destination.rotation;
  6271. }
  6272. if (destination.dest) {
  6273. this._initialBookmark = JSON.stringify(destination.dest);
  6274. this._destination.page = null;
  6275. } else if (destination.hash) {
  6276. this._initialBookmark = destination.hash;
  6277. } else if (destination.page) {
  6278. this._initialBookmark = `page=${destination.page}`;
  6279. }
  6280. }
  6281. reset() {
  6282. if (this._initialized) {
  6283. this._pageHide();
  6284. this._initialized = false;
  6285. this._unbindEvents();
  6286. }
  6287. if (this._updateViewareaTimeout) {
  6288. clearTimeout(this._updateViewareaTimeout);
  6289. this._updateViewareaTimeout = null;
  6290. }
  6291. this._initialBookmark = null;
  6292. this._initialRotation = null;
  6293. }
  6294. push({
  6295. namedDest = null,
  6296. explicitDest,
  6297. pageNumber
  6298. }) {
  6299. if (!this._initialized) {
  6300. return;
  6301. }
  6302. if (namedDest && typeof namedDest !== "string") {
  6303. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  6304. return;
  6305. } else if (!Array.isArray(explicitDest)) {
  6306. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  6307. return;
  6308. } else if (!this._isValidPage(pageNumber)) {
  6309. if (pageNumber !== null || this._destination) {
  6310. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  6311. return;
  6312. }
  6313. }
  6314. const hash = namedDest || JSON.stringify(explicitDest);
  6315. if (!hash) {
  6316. return;
  6317. }
  6318. let forceReplace = false;
  6319. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  6320. if (this._destination.page) {
  6321. return;
  6322. }
  6323. forceReplace = true;
  6324. }
  6325. if (this._popStateInProgress && !forceReplace) {
  6326. return;
  6327. }
  6328. this._pushOrReplaceState({
  6329. dest: explicitDest,
  6330. hash,
  6331. page: pageNumber,
  6332. rotation: this.linkService.rotation
  6333. }, forceReplace);
  6334. if (!this._popStateInProgress) {
  6335. this._popStateInProgress = true;
  6336. Promise.resolve().then(() => {
  6337. this._popStateInProgress = false;
  6338. });
  6339. }
  6340. }
  6341. pushPage(pageNumber) {
  6342. if (!this._initialized) {
  6343. return;
  6344. }
  6345. if (!this._isValidPage(pageNumber)) {
  6346. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  6347. return;
  6348. }
  6349. if (this._destination?.page === pageNumber) {
  6350. return;
  6351. }
  6352. if (this._popStateInProgress) {
  6353. return;
  6354. }
  6355. this._pushOrReplaceState({
  6356. dest: null,
  6357. hash: `page=${pageNumber}`,
  6358. page: pageNumber,
  6359. rotation: this.linkService.rotation
  6360. });
  6361. if (!this._popStateInProgress) {
  6362. this._popStateInProgress = true;
  6363. Promise.resolve().then(() => {
  6364. this._popStateInProgress = false;
  6365. });
  6366. }
  6367. }
  6368. pushCurrentPosition() {
  6369. if (!this._initialized || this._popStateInProgress) {
  6370. return;
  6371. }
  6372. this._tryPushCurrentPosition();
  6373. }
  6374. back() {
  6375. if (!this._initialized || this._popStateInProgress) {
  6376. return;
  6377. }
  6378. const state = window.history.state;
  6379. if (this._isValidState(state) && state.uid > 0) {
  6380. window.history.back();
  6381. }
  6382. }
  6383. forward() {
  6384. if (!this._initialized || this._popStateInProgress) {
  6385. return;
  6386. }
  6387. const state = window.history.state;
  6388. if (this._isValidState(state) && state.uid < this._maxUid) {
  6389. window.history.forward();
  6390. }
  6391. }
  6392. get popStateInProgress() {
  6393. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  6394. }
  6395. get initialBookmark() {
  6396. return this._initialized ? this._initialBookmark : null;
  6397. }
  6398. get initialRotation() {
  6399. return this._initialized ? this._initialRotation : null;
  6400. }
  6401. _pushOrReplaceState(destination, forceReplace = false) {
  6402. const shouldReplace = forceReplace || !this._destination;
  6403. const newState = {
  6404. fingerprint: this._fingerprint,
  6405. uid: shouldReplace ? this._uid : this._uid + 1,
  6406. destination
  6407. };
  6408. this._updateInternalState(destination, newState.uid);
  6409. let newUrl;
  6410. if (this._updateUrl && destination?.hash) {
  6411. const baseUrl = document.location.href.split("#")[0];
  6412. if (!baseUrl.startsWith("file://")) {
  6413. newUrl = `${baseUrl}#${destination.hash}`;
  6414. }
  6415. }
  6416. if (shouldReplace) {
  6417. window.history.replaceState(newState, "", newUrl);
  6418. } else {
  6419. window.history.pushState(newState, "", newUrl);
  6420. }
  6421. }
  6422. _tryPushCurrentPosition(temporary = false) {
  6423. if (!this._position) {
  6424. return;
  6425. }
  6426. let position = this._position;
  6427. if (temporary) {
  6428. position = Object.assign(Object.create(null), this._position);
  6429. position.temporary = true;
  6430. }
  6431. if (!this._destination) {
  6432. this._pushOrReplaceState(position);
  6433. return;
  6434. }
  6435. if (this._destination.temporary) {
  6436. this._pushOrReplaceState(position, true);
  6437. return;
  6438. }
  6439. if (this._destination.hash === position.hash) {
  6440. return;
  6441. }
  6442. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  6443. return;
  6444. }
  6445. let forceReplace = false;
  6446. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  6447. if (this._destination.dest !== undefined || !this._destination.first) {
  6448. return;
  6449. }
  6450. forceReplace = true;
  6451. }
  6452. this._pushOrReplaceState(position, forceReplace);
  6453. }
  6454. _isValidPage(val) {
  6455. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  6456. }
  6457. _isValidState(state, checkReload = false) {
  6458. if (!state) {
  6459. return false;
  6460. }
  6461. if (state.fingerprint !== this._fingerprint) {
  6462. if (checkReload) {
  6463. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  6464. return false;
  6465. }
  6466. const [perfEntry] = performance.getEntriesByType("navigation");
  6467. if (perfEntry?.type !== "reload") {
  6468. return false;
  6469. }
  6470. } else {
  6471. return false;
  6472. }
  6473. }
  6474. if (!Number.isInteger(state.uid) || state.uid < 0) {
  6475. return false;
  6476. }
  6477. if (state.destination === null || typeof state.destination !== "object") {
  6478. return false;
  6479. }
  6480. return true;
  6481. }
  6482. _updateInternalState(destination, uid, removeTemporary = false) {
  6483. if (this._updateViewareaTimeout) {
  6484. clearTimeout(this._updateViewareaTimeout);
  6485. this._updateViewareaTimeout = null;
  6486. }
  6487. if (removeTemporary && destination?.temporary) {
  6488. delete destination.temporary;
  6489. }
  6490. this._destination = destination;
  6491. this._uid = uid;
  6492. this._maxUid = Math.max(this._maxUid, uid);
  6493. this._numPositionUpdates = 0;
  6494. }
  6495. _parseCurrentHash(checkNameddest = false) {
  6496. const hash = unescape(getCurrentHash()).substring(1);
  6497. const params = (0, _ui_utils.parseQueryString)(hash);
  6498. const nameddest = params.get("nameddest") || "";
  6499. let page = params.get("page") | 0;
  6500. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  6501. page = null;
  6502. }
  6503. return {
  6504. hash,
  6505. page,
  6506. rotation: this.linkService.rotation
  6507. };
  6508. }
  6509. _updateViewarea({
  6510. location
  6511. }) {
  6512. if (this._updateViewareaTimeout) {
  6513. clearTimeout(this._updateViewareaTimeout);
  6514. this._updateViewareaTimeout = null;
  6515. }
  6516. this._position = {
  6517. hash: location.pdfOpenParams.substring(1),
  6518. page: this.linkService.page,
  6519. first: location.pageNumber,
  6520. rotation: location.rotation
  6521. };
  6522. if (this._popStateInProgress) {
  6523. return;
  6524. }
  6525. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  6526. this._numPositionUpdates++;
  6527. }
  6528. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  6529. this._updateViewareaTimeout = setTimeout(() => {
  6530. if (!this._popStateInProgress) {
  6531. this._tryPushCurrentPosition(true);
  6532. }
  6533. this._updateViewareaTimeout = null;
  6534. }, UPDATE_VIEWAREA_TIMEOUT);
  6535. }
  6536. }
  6537. _popState({
  6538. state
  6539. }) {
  6540. const newHash = getCurrentHash(),
  6541. hashChanged = this._currentHash !== newHash;
  6542. this._currentHash = newHash;
  6543. if (!state) {
  6544. this._uid++;
  6545. const {
  6546. hash,
  6547. page,
  6548. rotation
  6549. } = this._parseCurrentHash();
  6550. this._pushOrReplaceState({
  6551. hash,
  6552. page,
  6553. rotation
  6554. }, true);
  6555. return;
  6556. }
  6557. if (!this._isValidState(state)) {
  6558. return;
  6559. }
  6560. this._popStateInProgress = true;
  6561. if (hashChanged) {
  6562. this._blockHashChange++;
  6563. (0, _event_utils.waitOnEventOrTimeout)({
  6564. target: window,
  6565. name: "hashchange",
  6566. delay: HASH_CHANGE_TIMEOUT
  6567. }).then(() => {
  6568. this._blockHashChange--;
  6569. });
  6570. }
  6571. const destination = state.destination;
  6572. this._updateInternalState(destination, state.uid, true);
  6573. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  6574. this.linkService.rotation = destination.rotation;
  6575. }
  6576. if (destination.dest) {
  6577. this.linkService.goToDestination(destination.dest);
  6578. } else if (destination.hash) {
  6579. this.linkService.setHash(destination.hash);
  6580. } else if (destination.page) {
  6581. this.linkService.page = destination.page;
  6582. }
  6583. Promise.resolve().then(() => {
  6584. this._popStateInProgress = false;
  6585. });
  6586. }
  6587. _pageHide() {
  6588. if (!this._destination || this._destination.temporary) {
  6589. this._tryPushCurrentPosition();
  6590. }
  6591. }
  6592. _bindEvents() {
  6593. if (this._boundEvents) {
  6594. return;
  6595. }
  6596. this._boundEvents = {
  6597. updateViewarea: this._updateViewarea.bind(this),
  6598. popState: this._popState.bind(this),
  6599. pageHide: this._pageHide.bind(this)
  6600. };
  6601. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  6602. window.addEventListener("popstate", this._boundEvents.popState);
  6603. window.addEventListener("pagehide", this._boundEvents.pageHide);
  6604. }
  6605. _unbindEvents() {
  6606. if (!this._boundEvents) {
  6607. return;
  6608. }
  6609. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  6610. window.removeEventListener("popstate", this._boundEvents.popState);
  6611. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  6612. this._boundEvents = null;
  6613. }
  6614. }
  6615. exports.PDFHistory = PDFHistory;
  6616. function isDestHashesEqual(destHash, pushHash) {
  6617. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  6618. return false;
  6619. }
  6620. if (destHash === pushHash) {
  6621. return true;
  6622. }
  6623. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  6624. if (nameddest === pushHash) {
  6625. return true;
  6626. }
  6627. return false;
  6628. }
  6629. function isDestArraysEqual(firstDest, secondDest) {
  6630. function isEntryEqual(first, second) {
  6631. if (typeof first !== typeof second) {
  6632. return false;
  6633. }
  6634. if (Array.isArray(first) || Array.isArray(second)) {
  6635. return false;
  6636. }
  6637. if (first !== null && typeof first === "object" && second !== null) {
  6638. if (Object.keys(first).length !== Object.keys(second).length) {
  6639. return false;
  6640. }
  6641. for (const key in first) {
  6642. if (!isEntryEqual(first[key], second[key])) {
  6643. return false;
  6644. }
  6645. }
  6646. return true;
  6647. }
  6648. return first === second || Number.isNaN(first) && Number.isNaN(second);
  6649. }
  6650. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  6651. return false;
  6652. }
  6653. if (firstDest.length !== secondDest.length) {
  6654. return false;
  6655. }
  6656. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  6657. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  6658. return false;
  6659. }
  6660. }
  6661. return true;
  6662. }
  6663. /***/ }),
  6664. /* 24 */
  6665. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6666. Object.defineProperty(exports, "__esModule", ({
  6667. value: true
  6668. }));
  6669. exports.PDFScriptingManager = void 0;
  6670. var _ui_utils = __w_pdfjs_require__(7);
  6671. var _pdfjsLib = __w_pdfjs_require__(3);
  6672. class PDFScriptingManager {
  6673. constructor({
  6674. eventBus,
  6675. sandboxBundleSrc = null,
  6676. scriptingFactory = null,
  6677. docPropertiesLookup = null
  6678. }) {
  6679. this._pdfDocument = null;
  6680. this._pdfViewer = null;
  6681. this._closeCapability = null;
  6682. this._destroyCapability = null;
  6683. this._scripting = null;
  6684. this._mouseState = Object.create(null);
  6685. this._ready = false;
  6686. this._eventBus = eventBus;
  6687. this._sandboxBundleSrc = sandboxBundleSrc;
  6688. this._scriptingFactory = scriptingFactory;
  6689. this._docPropertiesLookup = docPropertiesLookup;
  6690. if (!this._scriptingFactory) {
  6691. window.addEventListener("updatefromsandbox", event => {
  6692. this._eventBus.dispatch("updatefromsandbox", {
  6693. source: window,
  6694. detail: event.detail
  6695. });
  6696. });
  6697. }
  6698. }
  6699. setViewer(pdfViewer) {
  6700. this._pdfViewer = pdfViewer;
  6701. }
  6702. async setDocument(pdfDocument) {
  6703. if (this._pdfDocument) {
  6704. await this._destroyScripting();
  6705. }
  6706. this._pdfDocument = pdfDocument;
  6707. if (!pdfDocument) {
  6708. return;
  6709. }
  6710. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6711. if (!objects && !docActions) {
  6712. await this._destroyScripting();
  6713. return;
  6714. }
  6715. if (pdfDocument !== this._pdfDocument) {
  6716. return;
  6717. }
  6718. try {
  6719. this._scripting = this._createScripting();
  6720. } catch (error) {
  6721. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6722. await this._destroyScripting();
  6723. return;
  6724. }
  6725. this._internalEvents.set("updatefromsandbox", event => {
  6726. if (event?.source !== window) {
  6727. return;
  6728. }
  6729. this._updateFromSandbox(event.detail);
  6730. });
  6731. this._internalEvents.set("dispatcheventinsandbox", event => {
  6732. this._scripting?.dispatchEventInSandbox(event.detail);
  6733. });
  6734. this._internalEvents.set("pagechanging", ({
  6735. pageNumber,
  6736. previous
  6737. }) => {
  6738. if (pageNumber === previous) {
  6739. return;
  6740. }
  6741. this._dispatchPageClose(previous);
  6742. this._dispatchPageOpen(pageNumber);
  6743. });
  6744. this._internalEvents.set("pagerendered", ({
  6745. pageNumber
  6746. }) => {
  6747. if (!this._pageOpenPending.has(pageNumber)) {
  6748. return;
  6749. }
  6750. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6751. return;
  6752. }
  6753. this._dispatchPageOpen(pageNumber);
  6754. });
  6755. this._internalEvents.set("pagesdestroy", async event => {
  6756. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6757. await this._scripting?.dispatchEventInSandbox({
  6758. id: "doc",
  6759. name: "WillClose"
  6760. });
  6761. this._closeCapability?.resolve();
  6762. });
  6763. this._domEvents.set("mousedown", event => {
  6764. this._mouseState.isDown = true;
  6765. });
  6766. this._domEvents.set("mouseup", event => {
  6767. this._mouseState.isDown = false;
  6768. });
  6769. for (const [name, listener] of this._internalEvents) {
  6770. this._eventBus._on(name, listener);
  6771. }
  6772. for (const [name, listener] of this._domEvents) {
  6773. window.addEventListener(name, listener, true);
  6774. }
  6775. try {
  6776. const docProperties = await this._getDocProperties();
  6777. if (pdfDocument !== this._pdfDocument) {
  6778. return;
  6779. }
  6780. await this._scripting.createSandbox({
  6781. objects,
  6782. calculationOrder,
  6783. appInfo: {
  6784. platform: navigator.platform,
  6785. language: navigator.language
  6786. },
  6787. docInfo: { ...docProperties,
  6788. actions: docActions
  6789. }
  6790. });
  6791. this._eventBus.dispatch("sandboxcreated", {
  6792. source: this
  6793. });
  6794. } catch (error) {
  6795. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6796. await this._destroyScripting();
  6797. return;
  6798. }
  6799. await this._scripting?.dispatchEventInSandbox({
  6800. id: "doc",
  6801. name: "Open"
  6802. });
  6803. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6804. Promise.resolve().then(() => {
  6805. if (pdfDocument === this._pdfDocument) {
  6806. this._ready = true;
  6807. }
  6808. });
  6809. }
  6810. async dispatchWillSave(detail) {
  6811. return this._scripting?.dispatchEventInSandbox({
  6812. id: "doc",
  6813. name: "WillSave"
  6814. });
  6815. }
  6816. async dispatchDidSave(detail) {
  6817. return this._scripting?.dispatchEventInSandbox({
  6818. id: "doc",
  6819. name: "DidSave"
  6820. });
  6821. }
  6822. async dispatchWillPrint(detail) {
  6823. return this._scripting?.dispatchEventInSandbox({
  6824. id: "doc",
  6825. name: "WillPrint"
  6826. });
  6827. }
  6828. async dispatchDidPrint(detail) {
  6829. return this._scripting?.dispatchEventInSandbox({
  6830. id: "doc",
  6831. name: "DidPrint"
  6832. });
  6833. }
  6834. get mouseState() {
  6835. return this._mouseState;
  6836. }
  6837. get destroyPromise() {
  6838. return this._destroyCapability?.promise || null;
  6839. }
  6840. get ready() {
  6841. return this._ready;
  6842. }
  6843. get _internalEvents() {
  6844. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6845. }
  6846. get _domEvents() {
  6847. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6848. }
  6849. get _pageOpenPending() {
  6850. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6851. }
  6852. get _visitedPages() {
  6853. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6854. }
  6855. async _updateFromSandbox(detail) {
  6856. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6857. const {
  6858. id,
  6859. siblings,
  6860. command,
  6861. value
  6862. } = detail;
  6863. if (!id) {
  6864. switch (command) {
  6865. case "clear":
  6866. console.clear();
  6867. break;
  6868. case "error":
  6869. console.error(value);
  6870. break;
  6871. case "layout":
  6872. if (isInPresentationMode) {
  6873. return;
  6874. }
  6875. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  6876. this._pdfViewer.spreadMode = modes.spreadMode;
  6877. break;
  6878. case "page-num":
  6879. this._pdfViewer.currentPageNumber = value + 1;
  6880. break;
  6881. case "print":
  6882. await this._pdfViewer.pagesPromise;
  6883. this._eventBus.dispatch("print", {
  6884. source: this
  6885. });
  6886. break;
  6887. case "println":
  6888. console.log(value);
  6889. break;
  6890. case "zoom":
  6891. if (isInPresentationMode) {
  6892. return;
  6893. }
  6894. this._pdfViewer.currentScaleValue = value;
  6895. break;
  6896. case "SaveAs":
  6897. this._eventBus.dispatch("download", {
  6898. source: this
  6899. });
  6900. break;
  6901. case "FirstPage":
  6902. this._pdfViewer.currentPageNumber = 1;
  6903. break;
  6904. case "LastPage":
  6905. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  6906. break;
  6907. case "NextPage":
  6908. this._pdfViewer.nextPage();
  6909. break;
  6910. case "PrevPage":
  6911. this._pdfViewer.previousPage();
  6912. break;
  6913. case "ZoomViewIn":
  6914. if (isInPresentationMode) {
  6915. return;
  6916. }
  6917. this._pdfViewer.increaseScale();
  6918. break;
  6919. case "ZoomViewOut":
  6920. if (isInPresentationMode) {
  6921. return;
  6922. }
  6923. this._pdfViewer.decreaseScale();
  6924. break;
  6925. }
  6926. return;
  6927. }
  6928. if (isInPresentationMode) {
  6929. if (detail.focus) {
  6930. return;
  6931. }
  6932. }
  6933. delete detail.id;
  6934. delete detail.siblings;
  6935. const ids = siblings ? [id, ...siblings] : [id];
  6936. for (const elementId of ids) {
  6937. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  6938. if (element) {
  6939. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6940. detail
  6941. }));
  6942. } else {
  6943. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  6944. }
  6945. }
  6946. }
  6947. async _dispatchPageOpen(pageNumber, initialize = false) {
  6948. const pdfDocument = this._pdfDocument,
  6949. visitedPages = this._visitedPages;
  6950. if (initialize) {
  6951. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6952. }
  6953. if (!this._closeCapability) {
  6954. return;
  6955. }
  6956. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6957. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  6958. this._pageOpenPending.add(pageNumber);
  6959. return;
  6960. }
  6961. this._pageOpenPending.delete(pageNumber);
  6962. const actionsPromise = (async () => {
  6963. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6964. if (pdfDocument !== this._pdfDocument) {
  6965. return;
  6966. }
  6967. await this._scripting?.dispatchEventInSandbox({
  6968. id: "page",
  6969. name: "PageOpen",
  6970. pageNumber,
  6971. actions
  6972. });
  6973. })();
  6974. visitedPages.set(pageNumber, actionsPromise);
  6975. }
  6976. async _dispatchPageClose(pageNumber) {
  6977. const pdfDocument = this._pdfDocument,
  6978. visitedPages = this._visitedPages;
  6979. if (!this._closeCapability) {
  6980. return;
  6981. }
  6982. if (this._pageOpenPending.has(pageNumber)) {
  6983. return;
  6984. }
  6985. const actionsPromise = visitedPages.get(pageNumber);
  6986. if (!actionsPromise) {
  6987. return;
  6988. }
  6989. visitedPages.set(pageNumber, null);
  6990. await actionsPromise;
  6991. if (pdfDocument !== this._pdfDocument) {
  6992. return;
  6993. }
  6994. await this._scripting?.dispatchEventInSandbox({
  6995. id: "page",
  6996. name: "PageClose",
  6997. pageNumber
  6998. });
  6999. }
  7000. async _getDocProperties() {
  7001. if (this._docPropertiesLookup) {
  7002. return this._docPropertiesLookup(this._pdfDocument);
  7003. }
  7004. const {
  7005. docPropertiesLookup
  7006. } = __w_pdfjs_require__(25);
  7007. return docPropertiesLookup(this._pdfDocument);
  7008. }
  7009. _createScripting() {
  7010. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  7011. if (this._scripting) {
  7012. throw new Error("_createScripting: Scripting already exists.");
  7013. }
  7014. if (this._scriptingFactory) {
  7015. return this._scriptingFactory.createScripting({
  7016. sandboxBundleSrc: this._sandboxBundleSrc
  7017. });
  7018. }
  7019. const {
  7020. GenericScripting
  7021. } = __w_pdfjs_require__(25);
  7022. return new GenericScripting(this._sandboxBundleSrc);
  7023. }
  7024. async _destroyScripting() {
  7025. if (!this._scripting) {
  7026. this._pdfDocument = null;
  7027. this._destroyCapability?.resolve();
  7028. return;
  7029. }
  7030. if (this._closeCapability) {
  7031. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  7032. setTimeout(resolve, 1000);
  7033. })]).catch(reason => {});
  7034. this._closeCapability = null;
  7035. }
  7036. this._pdfDocument = null;
  7037. try {
  7038. await this._scripting.destroySandbox();
  7039. } catch (ex) {}
  7040. for (const [name, listener] of this._internalEvents) {
  7041. this._eventBus._off(name, listener);
  7042. }
  7043. this._internalEvents.clear();
  7044. for (const [name, listener] of this._domEvents) {
  7045. window.removeEventListener(name, listener, true);
  7046. }
  7047. this._domEvents.clear();
  7048. this._pageOpenPending.clear();
  7049. this._visitedPages.clear();
  7050. this._scripting = null;
  7051. delete this._mouseState.isDown;
  7052. this._ready = false;
  7053. this._destroyCapability?.resolve();
  7054. }
  7055. }
  7056. exports.PDFScriptingManager = PDFScriptingManager;
  7057. /***/ }),
  7058. /* 25 */
  7059. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7060. Object.defineProperty(exports, "__esModule", ({
  7061. value: true
  7062. }));
  7063. exports.GenericScripting = void 0;
  7064. exports.docPropertiesLookup = docPropertiesLookup;
  7065. var _pdfjsLib = __w_pdfjs_require__(3);
  7066. async function docPropertiesLookup(pdfDocument) {
  7067. const url = "",
  7068. baseUrl = url.split("#")[0];
  7069. let {
  7070. info,
  7071. metadata,
  7072. contentDispositionFilename,
  7073. contentLength
  7074. } = await pdfDocument.getMetadata();
  7075. if (!contentLength) {
  7076. const {
  7077. length
  7078. } = await pdfDocument.getDownloadInfo();
  7079. contentLength = length;
  7080. }
  7081. return { ...info,
  7082. baseURL: baseUrl,
  7083. filesize: contentLength,
  7084. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  7085. metadata: metadata?.getRaw(),
  7086. authors: metadata?.get("dc:creator"),
  7087. numPages: pdfDocument.numPages,
  7088. URL: url
  7089. };
  7090. }
  7091. class GenericScripting {
  7092. constructor(sandboxBundleSrc) {
  7093. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  7094. return window.pdfjsSandbox.QuickJSSandbox();
  7095. });
  7096. }
  7097. async createSandbox(data) {
  7098. const sandbox = await this._ready;
  7099. sandbox.create(data);
  7100. }
  7101. async dispatchEventInSandbox(event) {
  7102. const sandbox = await this._ready;
  7103. setTimeout(() => sandbox.dispatchEvent(event), 0);
  7104. }
  7105. async destroySandbox() {
  7106. const sandbox = await this._ready;
  7107. sandbox.nukeSandbox();
  7108. }
  7109. }
  7110. exports.GenericScripting = GenericScripting;
  7111. /***/ })
  7112. /******/ ]);
  7113. /************************************************************************/
  7114. /******/ // The module cache
  7115. /******/ var __webpack_module_cache__ = {};
  7116. /******/
  7117. /******/ // The require function
  7118. /******/ function __w_pdfjs_require__(moduleId) {
  7119. /******/ // Check if module is in cache
  7120. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  7121. /******/ if (cachedModule !== undefined) {
  7122. /******/ return cachedModule.exports;
  7123. /******/ }
  7124. /******/ // Create a new module (and put it into the cache)
  7125. /******/ var module = __webpack_module_cache__[moduleId] = {
  7126. /******/ // no module.id needed
  7127. /******/ // no module.loaded needed
  7128. /******/ exports: {}
  7129. /******/ };
  7130. /******/
  7131. /******/ // Execute the module function
  7132. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  7133. /******/
  7134. /******/ // Return the exports of the module
  7135. /******/ return module.exports;
  7136. /******/ }
  7137. /******/
  7138. /************************************************************************/
  7139. var __webpack_exports__ = {};
  7140. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  7141. (() => {
  7142. var exports = __webpack_exports__;
  7143. Object.defineProperty(exports, "__esModule", ({
  7144. value: true
  7145. }));
  7146. Object.defineProperty(exports, "AnnotationLayerBuilder", ({
  7147. enumerable: true,
  7148. get: function () {
  7149. return _annotation_layer_builder.AnnotationLayerBuilder;
  7150. }
  7151. }));
  7152. Object.defineProperty(exports, "DefaultAnnotationLayerFactory", ({
  7153. enumerable: true,
  7154. get: function () {
  7155. return _default_factory.DefaultAnnotationLayerFactory;
  7156. }
  7157. }));
  7158. Object.defineProperty(exports, "DefaultStructTreeLayerFactory", ({
  7159. enumerable: true,
  7160. get: function () {
  7161. return _default_factory.DefaultStructTreeLayerFactory;
  7162. }
  7163. }));
  7164. Object.defineProperty(exports, "DefaultTextLayerFactory", ({
  7165. enumerable: true,
  7166. get: function () {
  7167. return _default_factory.DefaultTextLayerFactory;
  7168. }
  7169. }));
  7170. Object.defineProperty(exports, "DefaultXfaLayerFactory", ({
  7171. enumerable: true,
  7172. get: function () {
  7173. return _default_factory.DefaultXfaLayerFactory;
  7174. }
  7175. }));
  7176. Object.defineProperty(exports, "DownloadManager", ({
  7177. enumerable: true,
  7178. get: function () {
  7179. return _download_manager.DownloadManager;
  7180. }
  7181. }));
  7182. Object.defineProperty(exports, "EventBus", ({
  7183. enumerable: true,
  7184. get: function () {
  7185. return _event_utils.EventBus;
  7186. }
  7187. }));
  7188. Object.defineProperty(exports, "GenericL10n", ({
  7189. enumerable: true,
  7190. get: function () {
  7191. return _genericl10n.GenericL10n;
  7192. }
  7193. }));
  7194. Object.defineProperty(exports, "LinkTarget", ({
  7195. enumerable: true,
  7196. get: function () {
  7197. return _pdf_link_service.LinkTarget;
  7198. }
  7199. }));
  7200. Object.defineProperty(exports, "NullL10n", ({
  7201. enumerable: true,
  7202. get: function () {
  7203. return _l10n_utils.NullL10n;
  7204. }
  7205. }));
  7206. Object.defineProperty(exports, "PDFFindController", ({
  7207. enumerable: true,
  7208. get: function () {
  7209. return _pdf_find_controller.PDFFindController;
  7210. }
  7211. }));
  7212. Object.defineProperty(exports, "PDFHistory", ({
  7213. enumerable: true,
  7214. get: function () {
  7215. return _pdf_history.PDFHistory;
  7216. }
  7217. }));
  7218. Object.defineProperty(exports, "PDFLinkService", ({
  7219. enumerable: true,
  7220. get: function () {
  7221. return _pdf_link_service.PDFLinkService;
  7222. }
  7223. }));
  7224. Object.defineProperty(exports, "PDFPageView", ({
  7225. enumerable: true,
  7226. get: function () {
  7227. return _pdf_page_view.PDFPageView;
  7228. }
  7229. }));
  7230. Object.defineProperty(exports, "PDFScriptingManager", ({
  7231. enumerable: true,
  7232. get: function () {
  7233. return _pdf_scripting_manager.PDFScriptingManager;
  7234. }
  7235. }));
  7236. Object.defineProperty(exports, "PDFSinglePageViewer", ({
  7237. enumerable: true,
  7238. get: function () {
  7239. return _pdf_viewer.PDFSinglePageViewer;
  7240. }
  7241. }));
  7242. Object.defineProperty(exports, "PDFViewer", ({
  7243. enumerable: true,
  7244. get: function () {
  7245. return _pdf_viewer.PDFViewer;
  7246. }
  7247. }));
  7248. Object.defineProperty(exports, "ProgressBar", ({
  7249. enumerable: true,
  7250. get: function () {
  7251. return _ui_utils.ProgressBar;
  7252. }
  7253. }));
  7254. Object.defineProperty(exports, "SimpleLinkService", ({
  7255. enumerable: true,
  7256. get: function () {
  7257. return _pdf_link_service.SimpleLinkService;
  7258. }
  7259. }));
  7260. Object.defineProperty(exports, "StructTreeLayerBuilder", ({
  7261. enumerable: true,
  7262. get: function () {
  7263. return _struct_tree_layer_builder.StructTreeLayerBuilder;
  7264. }
  7265. }));
  7266. Object.defineProperty(exports, "TextLayerBuilder", ({
  7267. enumerable: true,
  7268. get: function () {
  7269. return _text_layer_builder.TextLayerBuilder;
  7270. }
  7271. }));
  7272. Object.defineProperty(exports, "XfaLayerBuilder", ({
  7273. enumerable: true,
  7274. get: function () {
  7275. return _xfa_layer_builder.XfaLayerBuilder;
  7276. }
  7277. }));
  7278. Object.defineProperty(exports, "parseQueryString", ({
  7279. enumerable: true,
  7280. get: function () {
  7281. return _ui_utils.parseQueryString;
  7282. }
  7283. }));
  7284. var _default_factory = __w_pdfjs_require__(1);
  7285. var _pdf_link_service = __w_pdfjs_require__(6);
  7286. var _ui_utils = __w_pdfjs_require__(7);
  7287. var _pdf_viewer = __w_pdfjs_require__(11);
  7288. var _annotation_layer_builder = __w_pdfjs_require__(5);
  7289. var _download_manager = __w_pdfjs_require__(17);
  7290. var _event_utils = __w_pdfjs_require__(18);
  7291. var _genericl10n = __w_pdfjs_require__(19);
  7292. var _l10n_utils = __w_pdfjs_require__(4);
  7293. var _pdf_find_controller = __w_pdfjs_require__(21);
  7294. var _pdf_history = __w_pdfjs_require__(23);
  7295. var _pdf_page_view = __w_pdfjs_require__(14);
  7296. var _pdf_scripting_manager = __w_pdfjs_require__(24);
  7297. var _struct_tree_layer_builder = __w_pdfjs_require__(8);
  7298. var _text_layer_builder = __w_pdfjs_require__(9);
  7299. var _xfa_layer_builder = __w_pdfjs_require__(10);
  7300. const pdfjsVersion = '2.15.349';
  7301. const pdfjsBuild = 'b8aa9c622';
  7302. })();
  7303. /******/ return __webpack_exports__;
  7304. /******/ })()
  7305. ;
  7306. });
  7307. //# sourceMappingURL=pdf_viewer.js.map