pdf.mjs 577 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2023 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. /******/ var __webpack_modules__ = ({
  23. /***/ 640:
  24. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  25. // EXPORTS
  26. __webpack_require__.d(__webpack_exports__, {
  27. AnnotationLayer: () => (/* binding */ AnnotationLayer),
  28. FreeTextAnnotationElement: () => (/* binding */ FreeTextAnnotationElement),
  29. InkAnnotationElement: () => (/* binding */ InkAnnotationElement),
  30. StampAnnotationElement: () => (/* binding */ StampAnnotationElement)
  31. });
  32. // EXTERNAL MODULE: ./src/shared/util.js
  33. var util = __webpack_require__(266);
  34. // EXTERNAL MODULE: ./src/display/display_utils.js
  35. var display_utils = __webpack_require__(473);
  36. // EXTERNAL MODULE: ./src/display/annotation_storage.js
  37. var annotation_storage = __webpack_require__(780);
  38. ;// CONCATENATED MODULE: ./src/shared/scripting_utils.js
  39. function makeColorComp(n) {
  40. return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
  41. }
  42. function scaleAndClamp(x) {
  43. return Math.max(0, Math.min(255, 255 * x));
  44. }
  45. class ColorConverters {
  46. static CMYK_G([c, y, m, k]) {
  47. return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
  48. }
  49. static G_CMYK([g]) {
  50. return ["CMYK", 0, 0, 0, 1 - g];
  51. }
  52. static G_RGB([g]) {
  53. return ["RGB", g, g, g];
  54. }
  55. static G_rgb([g]) {
  56. g = scaleAndClamp(g);
  57. return [g, g, g];
  58. }
  59. static G_HTML([g]) {
  60. const G = makeColorComp(g);
  61. return `#${G}${G}${G}`;
  62. }
  63. static RGB_G([r, g, b]) {
  64. return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
  65. }
  66. static RGB_rgb(color) {
  67. return color.map(scaleAndClamp);
  68. }
  69. static RGB_HTML(color) {
  70. return `#${color.map(makeColorComp).join("")}`;
  71. }
  72. static T_HTML() {
  73. return "#00000000";
  74. }
  75. static T_rgb() {
  76. return [null];
  77. }
  78. static CMYK_RGB([c, y, m, k]) {
  79. return ["RGB", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];
  80. }
  81. static CMYK_rgb([c, y, m, k]) {
  82. return [scaleAndClamp(1 - Math.min(1, c + k)), scaleAndClamp(1 - Math.min(1, m + k)), scaleAndClamp(1 - Math.min(1, y + k))];
  83. }
  84. static CMYK_HTML(components) {
  85. const rgb = this.CMYK_RGB(components).slice(1);
  86. return this.RGB_HTML(rgb);
  87. }
  88. static RGB_CMYK([r, g, b]) {
  89. const c = 1 - r;
  90. const m = 1 - g;
  91. const y = 1 - b;
  92. const k = Math.min(c, m, y);
  93. return ["CMYK", c, m, y, k];
  94. }
  95. }
  96. // EXTERNAL MODULE: ./src/display/xfa_layer.js
  97. var xfa_layer = __webpack_require__(160);
  98. ;// CONCATENATED MODULE: ./src/display/annotation_layer.js
  99. const DEFAULT_TAB_INDEX = 1000;
  100. const DEFAULT_FONT_SIZE = 9;
  101. const GetElementsByNameSet = new WeakSet();
  102. function getRectDims(rect) {
  103. return {
  104. width: rect[2] - rect[0],
  105. height: rect[3] - rect[1]
  106. };
  107. }
  108. class AnnotationElementFactory {
  109. static create(parameters) {
  110. const subtype = parameters.data.annotationType;
  111. switch (subtype) {
  112. case util.AnnotationType.LINK:
  113. return new LinkAnnotationElement(parameters);
  114. case util.AnnotationType.TEXT:
  115. return new TextAnnotationElement(parameters);
  116. case util.AnnotationType.WIDGET:
  117. const fieldType = parameters.data.fieldType;
  118. switch (fieldType) {
  119. case "Tx":
  120. return new TextWidgetAnnotationElement(parameters);
  121. case "Btn":
  122. if (parameters.data.radioButton) {
  123. return new RadioButtonWidgetAnnotationElement(parameters);
  124. } else if (parameters.data.checkBox) {
  125. return new CheckboxWidgetAnnotationElement(parameters);
  126. }
  127. return new PushButtonWidgetAnnotationElement(parameters);
  128. case "Ch":
  129. return new ChoiceWidgetAnnotationElement(parameters);
  130. case "Sig":
  131. return new SignatureWidgetAnnotationElement(parameters);
  132. }
  133. return new WidgetAnnotationElement(parameters);
  134. case util.AnnotationType.POPUP:
  135. return new PopupAnnotationElement(parameters);
  136. case util.AnnotationType.FREETEXT:
  137. return new FreeTextAnnotationElement(parameters);
  138. case util.AnnotationType.LINE:
  139. return new LineAnnotationElement(parameters);
  140. case util.AnnotationType.SQUARE:
  141. return new SquareAnnotationElement(parameters);
  142. case util.AnnotationType.CIRCLE:
  143. return new CircleAnnotationElement(parameters);
  144. case util.AnnotationType.POLYLINE:
  145. return new PolylineAnnotationElement(parameters);
  146. case util.AnnotationType.CARET:
  147. return new CaretAnnotationElement(parameters);
  148. case util.AnnotationType.INK:
  149. return new InkAnnotationElement(parameters);
  150. case util.AnnotationType.POLYGON:
  151. return new PolygonAnnotationElement(parameters);
  152. case util.AnnotationType.HIGHLIGHT:
  153. return new HighlightAnnotationElement(parameters);
  154. case util.AnnotationType.UNDERLINE:
  155. return new UnderlineAnnotationElement(parameters);
  156. case util.AnnotationType.SQUIGGLY:
  157. return new SquigglyAnnotationElement(parameters);
  158. case util.AnnotationType.STRIKEOUT:
  159. return new StrikeOutAnnotationElement(parameters);
  160. case util.AnnotationType.STAMP:
  161. return new StampAnnotationElement(parameters);
  162. case util.AnnotationType.FILEATTACHMENT:
  163. return new FileAttachmentAnnotationElement(parameters);
  164. default:
  165. return new AnnotationElement(parameters);
  166. }
  167. }
  168. }
  169. class AnnotationElement {
  170. #hasBorder = false;
  171. constructor(parameters, {
  172. isRenderable = false,
  173. ignoreBorder = false,
  174. createQuadrilaterals = false
  175. } = {}) {
  176. this.isRenderable = isRenderable;
  177. this.data = parameters.data;
  178. this.layer = parameters.layer;
  179. this.linkService = parameters.linkService;
  180. this.downloadManager = parameters.downloadManager;
  181. this.imageResourcesPath = parameters.imageResourcesPath;
  182. this.renderForms = parameters.renderForms;
  183. this.svgFactory = parameters.svgFactory;
  184. this.annotationStorage = parameters.annotationStorage;
  185. this.enableScripting = parameters.enableScripting;
  186. this.hasJSActions = parameters.hasJSActions;
  187. this._fieldObjects = parameters.fieldObjects;
  188. this.parent = parameters.parent;
  189. if (isRenderable) {
  190. this.container = this._createContainer(ignoreBorder);
  191. }
  192. if (createQuadrilaterals) {
  193. this._createQuadrilaterals();
  194. }
  195. }
  196. static _hasPopupData({
  197. titleObj,
  198. contentsObj,
  199. richText
  200. }) {
  201. return !!(titleObj?.str || contentsObj?.str || richText?.str);
  202. }
  203. get hasPopupData() {
  204. return AnnotationElement._hasPopupData(this.data);
  205. }
  206. _createContainer(ignoreBorder) {
  207. const {
  208. data,
  209. parent: {
  210. page,
  211. viewport
  212. }
  213. } = this;
  214. const container = document.createElement("section");
  215. container.setAttribute("data-annotation-id", data.id);
  216. if (!(this instanceof WidgetAnnotationElement)) {
  217. container.tabIndex = DEFAULT_TAB_INDEX;
  218. }
  219. container.style.zIndex = this.parent.zIndex++;
  220. if (this.data.popupRef) {
  221. container.setAttribute("aria-haspopup", "dialog");
  222. }
  223. if (data.noRotate) {
  224. container.classList.add("norotate");
  225. }
  226. const {
  227. pageWidth,
  228. pageHeight,
  229. pageX,
  230. pageY
  231. } = viewport.rawDims;
  232. if (!data.rect || this instanceof PopupAnnotationElement) {
  233. const {
  234. rotation
  235. } = data;
  236. if (!data.hasOwnCanvas && rotation !== 0) {
  237. this.setRotation(rotation, container);
  238. }
  239. return container;
  240. }
  241. const {
  242. width,
  243. height
  244. } = getRectDims(data.rect);
  245. const rect = util.Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]);
  246. if (!ignoreBorder && data.borderStyle.width > 0) {
  247. container.style.borderWidth = `${data.borderStyle.width}px`;
  248. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  249. const verticalRadius = data.borderStyle.verticalCornerRadius;
  250. if (horizontalRadius > 0 || verticalRadius > 0) {
  251. const radius = `calc(${horizontalRadius}px * var(--scale-factor)) / calc(${verticalRadius}px * var(--scale-factor))`;
  252. container.style.borderRadius = radius;
  253. } else if (this instanceof RadioButtonWidgetAnnotationElement) {
  254. const radius = `calc(${width}px * var(--scale-factor)) / calc(${height}px * var(--scale-factor))`;
  255. container.style.borderRadius = radius;
  256. }
  257. switch (data.borderStyle.style) {
  258. case util.AnnotationBorderStyleType.SOLID:
  259. container.style.borderStyle = "solid";
  260. break;
  261. case util.AnnotationBorderStyleType.DASHED:
  262. container.style.borderStyle = "dashed";
  263. break;
  264. case util.AnnotationBorderStyleType.BEVELED:
  265. (0,util.warn)("Unimplemented border style: beveled");
  266. break;
  267. case util.AnnotationBorderStyleType.INSET:
  268. (0,util.warn)("Unimplemented border style: inset");
  269. break;
  270. case util.AnnotationBorderStyleType.UNDERLINE:
  271. container.style.borderBottomStyle = "solid";
  272. break;
  273. default:
  274. break;
  275. }
  276. const borderColor = data.borderColor || null;
  277. if (borderColor) {
  278. this.#hasBorder = true;
  279. container.style.borderColor = util.Util.makeHexColor(borderColor[0] | 0, borderColor[1] | 0, borderColor[2] | 0);
  280. } else {
  281. container.style.borderWidth = 0;
  282. }
  283. }
  284. container.style.left = `${100 * (rect[0] - pageX) / pageWidth}%`;
  285. container.style.top = `${100 * (rect[1] - pageY) / pageHeight}%`;
  286. const {
  287. rotation
  288. } = data;
  289. if (data.hasOwnCanvas || rotation === 0) {
  290. container.style.width = `${100 * width / pageWidth}%`;
  291. container.style.height = `${100 * height / pageHeight}%`;
  292. } else {
  293. this.setRotation(rotation, container);
  294. }
  295. return container;
  296. }
  297. setRotation(angle, container = this.container) {
  298. if (!this.data.rect) {
  299. return;
  300. }
  301. const {
  302. pageWidth,
  303. pageHeight
  304. } = this.parent.viewport.rawDims;
  305. const {
  306. width,
  307. height
  308. } = getRectDims(this.data.rect);
  309. let elementWidth, elementHeight;
  310. if (angle % 180 === 0) {
  311. elementWidth = 100 * width / pageWidth;
  312. elementHeight = 100 * height / pageHeight;
  313. } else {
  314. elementWidth = 100 * height / pageWidth;
  315. elementHeight = 100 * width / pageHeight;
  316. }
  317. container.style.width = `${elementWidth}%`;
  318. container.style.height = `${elementHeight}%`;
  319. container.setAttribute("data-main-rotation", (360 - angle) % 360);
  320. }
  321. get _commonActions() {
  322. const setColor = (jsName, styleName, event) => {
  323. const color = event.detail[jsName];
  324. const colorType = color[0];
  325. const colorArray = color.slice(1);
  326. event.target.style[styleName] = ColorConverters[`${colorType}_HTML`](colorArray);
  327. this.annotationStorage.setValue(this.data.id, {
  328. [styleName]: ColorConverters[`${colorType}_rgb`](colorArray)
  329. });
  330. };
  331. return (0,util.shadow)(this, "_commonActions", {
  332. display: event => {
  333. const {
  334. display
  335. } = event.detail;
  336. const hidden = display % 2 === 1;
  337. this.container.style.visibility = hidden ? "hidden" : "visible";
  338. this.annotationStorage.setValue(this.data.id, {
  339. noView: hidden,
  340. noPrint: display === 1 || display === 2
  341. });
  342. },
  343. print: event => {
  344. this.annotationStorage.setValue(this.data.id, {
  345. noPrint: !event.detail.print
  346. });
  347. },
  348. hidden: event => {
  349. const {
  350. hidden
  351. } = event.detail;
  352. this.container.style.visibility = hidden ? "hidden" : "visible";
  353. this.annotationStorage.setValue(this.data.id, {
  354. noPrint: hidden,
  355. noView: hidden
  356. });
  357. },
  358. focus: event => {
  359. setTimeout(() => event.target.focus({
  360. preventScroll: false
  361. }), 0);
  362. },
  363. userName: event => {
  364. event.target.title = event.detail.userName;
  365. },
  366. readonly: event => {
  367. event.target.disabled = event.detail.readonly;
  368. },
  369. required: event => {
  370. this._setRequired(event.target, event.detail.required);
  371. },
  372. bgColor: event => {
  373. setColor("bgColor", "backgroundColor", event);
  374. },
  375. fillColor: event => {
  376. setColor("fillColor", "backgroundColor", event);
  377. },
  378. fgColor: event => {
  379. setColor("fgColor", "color", event);
  380. },
  381. textColor: event => {
  382. setColor("textColor", "color", event);
  383. },
  384. borderColor: event => {
  385. setColor("borderColor", "borderColor", event);
  386. },
  387. strokeColor: event => {
  388. setColor("strokeColor", "borderColor", event);
  389. },
  390. rotation: event => {
  391. const angle = event.detail.rotation;
  392. this.setRotation(angle);
  393. this.annotationStorage.setValue(this.data.id, {
  394. rotation: angle
  395. });
  396. }
  397. });
  398. }
  399. _dispatchEventFromSandbox(actions, jsEvent) {
  400. const commonActions = this._commonActions;
  401. for (const name of Object.keys(jsEvent.detail)) {
  402. const action = actions[name] || commonActions[name];
  403. action?.(jsEvent);
  404. }
  405. }
  406. _setDefaultPropertiesFromJS(element) {
  407. if (!this.enableScripting) {
  408. return;
  409. }
  410. const storedData = this.annotationStorage.getRawValue(this.data.id);
  411. if (!storedData) {
  412. return;
  413. }
  414. const commonActions = this._commonActions;
  415. for (const [actionName, detail] of Object.entries(storedData)) {
  416. const action = commonActions[actionName];
  417. if (action) {
  418. const eventProxy = {
  419. detail: {
  420. [actionName]: detail
  421. },
  422. target: element
  423. };
  424. action(eventProxy);
  425. delete storedData[actionName];
  426. }
  427. }
  428. }
  429. _createQuadrilaterals() {
  430. if (!this.container) {
  431. return;
  432. }
  433. const {
  434. quadPoints
  435. } = this.data;
  436. if (!quadPoints) {
  437. return;
  438. }
  439. const [rectBlX, rectBlY, rectTrX, rectTrY] = this.data.rect;
  440. if (quadPoints.length === 1) {
  441. const [, {
  442. x: trX,
  443. y: trY
  444. }, {
  445. x: blX,
  446. y: blY
  447. }] = quadPoints[0];
  448. if (rectTrX === trX && rectTrY === trY && rectBlX === blX && rectBlY === blY) {
  449. return;
  450. }
  451. }
  452. const {
  453. style
  454. } = this.container;
  455. let svgBuffer;
  456. if (this.#hasBorder) {
  457. const {
  458. borderColor,
  459. borderWidth
  460. } = style;
  461. style.borderWidth = 0;
  462. svgBuffer = ["url('data:image/svg+xml;utf8,", `<svg xmlns="http://www.w3.org/2000/svg"`, ` preserveAspectRatio="none" viewBox="0 0 1 1">`, `<g fill="transparent" stroke="${borderColor}" stroke-width="${borderWidth}">`];
  463. this.container.classList.add("hasBorder");
  464. }
  465. const width = rectTrX - rectBlX;
  466. const height = rectTrY - rectBlY;
  467. const {
  468. svgFactory
  469. } = this;
  470. const svg = svgFactory.createElement("svg");
  471. svg.classList.add("quadrilateralsContainer");
  472. svg.setAttribute("width", 0);
  473. svg.setAttribute("height", 0);
  474. const defs = svgFactory.createElement("defs");
  475. svg.append(defs);
  476. const clipPath = svgFactory.createElement("clipPath");
  477. const id = `clippath_${this.data.id}`;
  478. clipPath.setAttribute("id", id);
  479. clipPath.setAttribute("clipPathUnits", "objectBoundingBox");
  480. defs.append(clipPath);
  481. for (const [, {
  482. x: trX,
  483. y: trY
  484. }, {
  485. x: blX,
  486. y: blY
  487. }] of quadPoints) {
  488. const rect = svgFactory.createElement("rect");
  489. const x = (blX - rectBlX) / width;
  490. const y = (rectTrY - trY) / height;
  491. const rectWidth = (trX - blX) / width;
  492. const rectHeight = (trY - blY) / height;
  493. rect.setAttribute("x", x);
  494. rect.setAttribute("y", y);
  495. rect.setAttribute("width", rectWidth);
  496. rect.setAttribute("height", rectHeight);
  497. clipPath.append(rect);
  498. svgBuffer?.push(`<rect vector-effect="non-scaling-stroke" x="${x}" y="${y}" width="${rectWidth}" height="${rectHeight}"/>`);
  499. }
  500. if (this.#hasBorder) {
  501. svgBuffer.push(`</g></svg>')`);
  502. style.backgroundImage = svgBuffer.join("");
  503. }
  504. this.container.append(svg);
  505. this.container.style.clipPath = `url(#${id})`;
  506. }
  507. _createPopup() {
  508. const {
  509. container,
  510. data
  511. } = this;
  512. container.setAttribute("aria-haspopup", "dialog");
  513. const popup = new PopupAnnotationElement({
  514. data: {
  515. color: data.color,
  516. titleObj: data.titleObj,
  517. modificationDate: data.modificationDate,
  518. contentsObj: data.contentsObj,
  519. richText: data.richText,
  520. parentRect: data.rect,
  521. borderStyle: 0,
  522. id: `popup_${data.id}`,
  523. rotation: data.rotation
  524. },
  525. parent: this.parent,
  526. elements: [this]
  527. });
  528. this.parent.div.append(popup.render());
  529. }
  530. render() {
  531. (0,util.unreachable)("Abstract method `AnnotationElement.render` called");
  532. }
  533. _getElementsByName(name, skipId = null) {
  534. const fields = [];
  535. if (this._fieldObjects) {
  536. const fieldObj = this._fieldObjects[name];
  537. if (fieldObj) {
  538. for (const {
  539. page,
  540. id,
  541. exportValues
  542. } of fieldObj) {
  543. if (page === -1) {
  544. continue;
  545. }
  546. if (id === skipId) {
  547. continue;
  548. }
  549. const exportValue = typeof exportValues === "string" ? exportValues : null;
  550. const domElement = document.querySelector(`[data-element-id="${id}"]`);
  551. if (domElement && !GetElementsByNameSet.has(domElement)) {
  552. (0,util.warn)(`_getElementsByName - element not allowed: ${id}`);
  553. continue;
  554. }
  555. fields.push({
  556. id,
  557. exportValue,
  558. domElement
  559. });
  560. }
  561. }
  562. return fields;
  563. }
  564. for (const domElement of document.getElementsByName(name)) {
  565. const {
  566. exportValue
  567. } = domElement;
  568. const id = domElement.getAttribute("data-element-id");
  569. if (id === skipId) {
  570. continue;
  571. }
  572. if (!GetElementsByNameSet.has(domElement)) {
  573. continue;
  574. }
  575. fields.push({
  576. id,
  577. exportValue,
  578. domElement
  579. });
  580. }
  581. return fields;
  582. }
  583. show() {
  584. if (this.container) {
  585. this.container.hidden = false;
  586. }
  587. this.popup?.maybeShow();
  588. }
  589. hide() {
  590. if (this.container) {
  591. this.container.hidden = true;
  592. }
  593. this.popup?.forceHide();
  594. }
  595. getElementsToTriggerPopup() {
  596. return this.container;
  597. }
  598. addHighlightArea() {
  599. const triggers = this.getElementsToTriggerPopup();
  600. if (Array.isArray(triggers)) {
  601. for (const element of triggers) {
  602. element.classList.add("highlightArea");
  603. }
  604. } else {
  605. triggers.classList.add("highlightArea");
  606. }
  607. }
  608. get _isEditable() {
  609. return false;
  610. }
  611. _editOnDoubleClick() {
  612. if (!this._isEditable) {
  613. return;
  614. }
  615. const {
  616. annotationEditorType: mode,
  617. data: {
  618. id: editId
  619. }
  620. } = this;
  621. this.container.addEventListener("dblclick", () => {
  622. this.linkService.eventBus?.dispatch("switchannotationeditormode", {
  623. source: this,
  624. mode,
  625. editId
  626. });
  627. });
  628. }
  629. }
  630. class LinkAnnotationElement extends AnnotationElement {
  631. constructor(parameters, options = null) {
  632. super(parameters, {
  633. isRenderable: true,
  634. ignoreBorder: !!options?.ignoreBorder,
  635. createQuadrilaterals: true
  636. });
  637. this.isTooltipOnly = parameters.data.isTooltipOnly;
  638. }
  639. render() {
  640. const {
  641. data,
  642. linkService
  643. } = this;
  644. const link = document.createElement("a");
  645. link.setAttribute("data-element-id", data.id);
  646. let isBound = false;
  647. if (data.url) {
  648. linkService.addLinkAttributes(link, data.url, data.newWindow);
  649. isBound = true;
  650. } else if (data.action) {
  651. this._bindNamedAction(link, data.action);
  652. isBound = true;
  653. } else if (data.attachment) {
  654. this.#bindAttachment(link, data.attachment, data.attachmentDest);
  655. isBound = true;
  656. } else if (data.setOCGState) {
  657. this.#bindSetOCGState(link, data.setOCGState);
  658. isBound = true;
  659. } else if (data.dest) {
  660. this._bindLink(link, data.dest);
  661. isBound = true;
  662. } else {
  663. if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
  664. this._bindJSAction(link, data);
  665. isBound = true;
  666. }
  667. if (data.resetForm) {
  668. this._bindResetFormAction(link, data.resetForm);
  669. isBound = true;
  670. } else if (this.isTooltipOnly && !isBound) {
  671. this._bindLink(link, "");
  672. isBound = true;
  673. }
  674. }
  675. this.container.classList.add("linkAnnotation");
  676. if (isBound) {
  677. this.container.append(link);
  678. }
  679. return this.container;
  680. }
  681. #setInternalLink() {
  682. this.container.setAttribute("data-internal-link", "");
  683. }
  684. _bindLink(link, destination) {
  685. link.href = this.linkService.getDestinationHash(destination);
  686. link.onclick = () => {
  687. if (destination) {
  688. this.linkService.goToDestination(destination);
  689. }
  690. return false;
  691. };
  692. if (destination || destination === "") {
  693. this.#setInternalLink();
  694. }
  695. }
  696. _bindNamedAction(link, action) {
  697. link.href = this.linkService.getAnchorUrl("");
  698. link.onclick = () => {
  699. this.linkService.executeNamedAction(action);
  700. return false;
  701. };
  702. this.#setInternalLink();
  703. }
  704. #bindAttachment(link, attachment, dest = null) {
  705. link.href = this.linkService.getAnchorUrl("");
  706. link.onclick = () => {
  707. this.downloadManager?.openOrDownloadData(attachment.content, attachment.filename, dest);
  708. return false;
  709. };
  710. this.#setInternalLink();
  711. }
  712. #bindSetOCGState(link, action) {
  713. link.href = this.linkService.getAnchorUrl("");
  714. link.onclick = () => {
  715. this.linkService.executeSetOCGState(action);
  716. return false;
  717. };
  718. this.#setInternalLink();
  719. }
  720. _bindJSAction(link, data) {
  721. link.href = this.linkService.getAnchorUrl("");
  722. const map = new Map([["Action", "onclick"], ["Mouse Up", "onmouseup"], ["Mouse Down", "onmousedown"]]);
  723. for (const name of Object.keys(data.actions)) {
  724. const jsName = map.get(name);
  725. if (!jsName) {
  726. continue;
  727. }
  728. link[jsName] = () => {
  729. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  730. source: this,
  731. detail: {
  732. id: data.id,
  733. name
  734. }
  735. });
  736. return false;
  737. };
  738. }
  739. if (!link.onclick) {
  740. link.onclick = () => false;
  741. }
  742. this.#setInternalLink();
  743. }
  744. _bindResetFormAction(link, resetForm) {
  745. const otherClickAction = link.onclick;
  746. if (!otherClickAction) {
  747. link.href = this.linkService.getAnchorUrl("");
  748. }
  749. this.#setInternalLink();
  750. if (!this._fieldObjects) {
  751. (0,util.warn)(`_bindResetFormAction - "resetForm" action not supported, ` + "ensure that the `fieldObjects` parameter is provided.");
  752. if (!otherClickAction) {
  753. link.onclick = () => false;
  754. }
  755. return;
  756. }
  757. link.onclick = () => {
  758. otherClickAction?.();
  759. const {
  760. fields: resetFormFields,
  761. refs: resetFormRefs,
  762. include
  763. } = resetForm;
  764. const allFields = [];
  765. if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
  766. const fieldIds = new Set(resetFormRefs);
  767. for (const fieldName of resetFormFields) {
  768. const fields = this._fieldObjects[fieldName] || [];
  769. for (const {
  770. id
  771. } of fields) {
  772. fieldIds.add(id);
  773. }
  774. }
  775. for (const fields of Object.values(this._fieldObjects)) {
  776. for (const field of fields) {
  777. if (fieldIds.has(field.id) === include) {
  778. allFields.push(field);
  779. }
  780. }
  781. }
  782. } else {
  783. for (const fields of Object.values(this._fieldObjects)) {
  784. allFields.push(...fields);
  785. }
  786. }
  787. const storage = this.annotationStorage;
  788. const allIds = [];
  789. for (const field of allFields) {
  790. const {
  791. id
  792. } = field;
  793. allIds.push(id);
  794. switch (field.type) {
  795. case "text":
  796. {
  797. const value = field.defaultValue || "";
  798. storage.setValue(id, {
  799. value
  800. });
  801. break;
  802. }
  803. case "checkbox":
  804. case "radiobutton":
  805. {
  806. const value = field.defaultValue === field.exportValues;
  807. storage.setValue(id, {
  808. value
  809. });
  810. break;
  811. }
  812. case "combobox":
  813. case "listbox":
  814. {
  815. const value = field.defaultValue || "";
  816. storage.setValue(id, {
  817. value
  818. });
  819. break;
  820. }
  821. default:
  822. continue;
  823. }
  824. const domElement = document.querySelector(`[data-element-id="${id}"]`);
  825. if (!domElement) {
  826. continue;
  827. } else if (!GetElementsByNameSet.has(domElement)) {
  828. (0,util.warn)(`_bindResetFormAction - element not allowed: ${id}`);
  829. continue;
  830. }
  831. domElement.dispatchEvent(new Event("resetform"));
  832. }
  833. if (this.enableScripting) {
  834. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  835. source: this,
  836. detail: {
  837. id: "app",
  838. ids: allIds,
  839. name: "ResetForm"
  840. }
  841. });
  842. }
  843. return false;
  844. };
  845. }
  846. }
  847. class TextAnnotationElement extends AnnotationElement {
  848. constructor(parameters) {
  849. super(parameters, {
  850. isRenderable: true
  851. });
  852. }
  853. render() {
  854. this.container.classList.add("textAnnotation");
  855. const image = document.createElement("img");
  856. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  857. image.setAttribute("data-l10n-id", "pdfjs-text-annotation-type");
  858. image.setAttribute("data-l10n-args", JSON.stringify({
  859. type: this.data.name
  860. }));
  861. if (!this.data.popupRef && this.hasPopupData) {
  862. this._createPopup();
  863. }
  864. this.container.append(image);
  865. return this.container;
  866. }
  867. }
  868. class WidgetAnnotationElement extends AnnotationElement {
  869. render() {
  870. if (this.data.alternativeText) {
  871. this.container.title = this.data.alternativeText;
  872. }
  873. return this.container;
  874. }
  875. showElementAndHideCanvas(element) {
  876. if (this.data.hasOwnCanvas) {
  877. if (element.previousSibling?.nodeName === "CANVAS") {
  878. element.previousSibling.hidden = true;
  879. }
  880. element.hidden = false;
  881. }
  882. }
  883. _getKeyModifier(event) {
  884. return util.FeatureTest.platform.isMac ? event.metaKey : event.ctrlKey;
  885. }
  886. _setEventListener(element, elementData, baseName, eventName, valueGetter) {
  887. if (baseName.includes("mouse")) {
  888. element.addEventListener(baseName, event => {
  889. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  890. source: this,
  891. detail: {
  892. id: this.data.id,
  893. name: eventName,
  894. value: valueGetter(event),
  895. shift: event.shiftKey,
  896. modifier: this._getKeyModifier(event)
  897. }
  898. });
  899. });
  900. } else {
  901. element.addEventListener(baseName, event => {
  902. if (baseName === "blur") {
  903. if (!elementData.focused || !event.relatedTarget) {
  904. return;
  905. }
  906. elementData.focused = false;
  907. } else if (baseName === "focus") {
  908. if (elementData.focused) {
  909. return;
  910. }
  911. elementData.focused = true;
  912. }
  913. if (!valueGetter) {
  914. return;
  915. }
  916. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  917. source: this,
  918. detail: {
  919. id: this.data.id,
  920. name: eventName,
  921. value: valueGetter(event)
  922. }
  923. });
  924. });
  925. }
  926. }
  927. _setEventListeners(element, elementData, names, getter) {
  928. for (const [baseName, eventName] of names) {
  929. if (eventName === "Action" || this.data.actions?.[eventName]) {
  930. if (eventName === "Focus" || eventName === "Blur") {
  931. elementData ||= {
  932. focused: false
  933. };
  934. }
  935. this._setEventListener(element, elementData, baseName, eventName, getter);
  936. if (eventName === "Focus" && !this.data.actions?.Blur) {
  937. this._setEventListener(element, elementData, "blur", "Blur", null);
  938. } else if (eventName === "Blur" && !this.data.actions?.Focus) {
  939. this._setEventListener(element, elementData, "focus", "Focus", null);
  940. }
  941. }
  942. }
  943. }
  944. _setBackgroundColor(element) {
  945. const color = this.data.backgroundColor || null;
  946. element.style.backgroundColor = color === null ? "transparent" : util.Util.makeHexColor(color[0], color[1], color[2]);
  947. }
  948. _setTextStyle(element) {
  949. const TEXT_ALIGNMENT = ["left", "center", "right"];
  950. const {
  951. fontColor
  952. } = this.data.defaultAppearanceData;
  953. const fontSize = this.data.defaultAppearanceData.fontSize || DEFAULT_FONT_SIZE;
  954. const style = element.style;
  955. let computedFontSize;
  956. const BORDER_SIZE = 2;
  957. const roundToOneDecimal = x => Math.round(10 * x) / 10;
  958. if (this.data.multiLine) {
  959. const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
  960. const numberOfLines = Math.round(height / (util.LINE_FACTOR * fontSize)) || 1;
  961. const lineHeight = height / numberOfLines;
  962. computedFontSize = Math.min(fontSize, roundToOneDecimal(lineHeight / util.LINE_FACTOR));
  963. } else {
  964. const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
  965. computedFontSize = Math.min(fontSize, roundToOneDecimal(height / util.LINE_FACTOR));
  966. }
  967. style.fontSize = `calc(${computedFontSize}px * var(--scale-factor))`;
  968. style.color = util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
  969. if (this.data.textAlignment !== null) {
  970. style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  971. }
  972. }
  973. _setRequired(element, isRequired) {
  974. if (isRequired) {
  975. element.setAttribute("required", true);
  976. } else {
  977. element.removeAttribute("required");
  978. }
  979. element.setAttribute("aria-required", isRequired);
  980. }
  981. }
  982. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  983. constructor(parameters) {
  984. const isRenderable = parameters.renderForms || parameters.data.hasOwnCanvas || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  985. super(parameters, {
  986. isRenderable
  987. });
  988. }
  989. setPropertyOnSiblings(base, key, value, keyInStorage) {
  990. const storage = this.annotationStorage;
  991. for (const element of this._getElementsByName(base.name, base.id)) {
  992. if (element.domElement) {
  993. element.domElement[key] = value;
  994. }
  995. storage.setValue(element.id, {
  996. [keyInStorage]: value
  997. });
  998. }
  999. }
  1000. render() {
  1001. const storage = this.annotationStorage;
  1002. const id = this.data.id;
  1003. this.container.classList.add("textWidgetAnnotation");
  1004. let element = null;
  1005. if (this.renderForms) {
  1006. const storedData = storage.getValue(id, {
  1007. value: this.data.fieldValue
  1008. });
  1009. let textContent = storedData.value || "";
  1010. const maxLen = storage.getValue(id, {
  1011. charLimit: this.data.maxLen
  1012. }).charLimit;
  1013. if (maxLen && textContent.length > maxLen) {
  1014. textContent = textContent.slice(0, maxLen);
  1015. }
  1016. let fieldFormattedValues = storedData.formattedValue || this.data.textContent?.join("\n") || null;
  1017. if (fieldFormattedValues && this.data.comb) {
  1018. fieldFormattedValues = fieldFormattedValues.replaceAll(/\s+/g, "");
  1019. }
  1020. const elementData = {
  1021. userValue: textContent,
  1022. formattedValue: fieldFormattedValues,
  1023. lastCommittedValue: null,
  1024. commitKey: 1,
  1025. focused: false
  1026. };
  1027. if (this.data.multiLine) {
  1028. element = document.createElement("textarea");
  1029. element.textContent = fieldFormattedValues ?? textContent;
  1030. if (this.data.doNotScroll) {
  1031. element.style.overflowY = "hidden";
  1032. }
  1033. } else {
  1034. element = document.createElement("input");
  1035. element.type = "text";
  1036. element.setAttribute("value", fieldFormattedValues ?? textContent);
  1037. if (this.data.doNotScroll) {
  1038. element.style.overflowX = "hidden";
  1039. }
  1040. }
  1041. if (this.data.hasOwnCanvas) {
  1042. element.hidden = true;
  1043. }
  1044. GetElementsByNameSet.add(element);
  1045. element.setAttribute("data-element-id", id);
  1046. element.disabled = this.data.readOnly;
  1047. element.name = this.data.fieldName;
  1048. element.tabIndex = DEFAULT_TAB_INDEX;
  1049. this._setRequired(element, this.data.required);
  1050. if (maxLen) {
  1051. element.maxLength = maxLen;
  1052. }
  1053. element.addEventListener("input", event => {
  1054. storage.setValue(id, {
  1055. value: event.target.value
  1056. });
  1057. this.setPropertyOnSiblings(element, "value", event.target.value, "value");
  1058. elementData.formattedValue = null;
  1059. });
  1060. element.addEventListener("resetform", event => {
  1061. const defaultValue = this.data.defaultFieldValue ?? "";
  1062. element.value = elementData.userValue = defaultValue;
  1063. elementData.formattedValue = null;
  1064. });
  1065. let blurListener = event => {
  1066. const {
  1067. formattedValue
  1068. } = elementData;
  1069. if (formattedValue !== null && formattedValue !== undefined) {
  1070. event.target.value = formattedValue;
  1071. }
  1072. event.target.scrollLeft = 0;
  1073. };
  1074. if (this.enableScripting && this.hasJSActions) {
  1075. element.addEventListener("focus", event => {
  1076. if (elementData.focused) {
  1077. return;
  1078. }
  1079. const {
  1080. target
  1081. } = event;
  1082. if (elementData.userValue) {
  1083. target.value = elementData.userValue;
  1084. }
  1085. elementData.lastCommittedValue = target.value;
  1086. elementData.commitKey = 1;
  1087. if (!this.data.actions?.Focus) {
  1088. elementData.focused = true;
  1089. }
  1090. });
  1091. element.addEventListener("updatefromsandbox", jsEvent => {
  1092. this.showElementAndHideCanvas(jsEvent.target);
  1093. const actions = {
  1094. value(event) {
  1095. elementData.userValue = event.detail.value ?? "";
  1096. storage.setValue(id, {
  1097. value: elementData.userValue.toString()
  1098. });
  1099. event.target.value = elementData.userValue;
  1100. },
  1101. formattedValue(event) {
  1102. const {
  1103. formattedValue
  1104. } = event.detail;
  1105. elementData.formattedValue = formattedValue;
  1106. if (formattedValue !== null && formattedValue !== undefined && event.target !== document.activeElement) {
  1107. event.target.value = formattedValue;
  1108. }
  1109. storage.setValue(id, {
  1110. formattedValue
  1111. });
  1112. },
  1113. selRange(event) {
  1114. event.target.setSelectionRange(...event.detail.selRange);
  1115. },
  1116. charLimit: event => {
  1117. const {
  1118. charLimit
  1119. } = event.detail;
  1120. const {
  1121. target
  1122. } = event;
  1123. if (charLimit === 0) {
  1124. target.removeAttribute("maxLength");
  1125. return;
  1126. }
  1127. target.setAttribute("maxLength", charLimit);
  1128. let value = elementData.userValue;
  1129. if (!value || value.length <= charLimit) {
  1130. return;
  1131. }
  1132. value = value.slice(0, charLimit);
  1133. target.value = elementData.userValue = value;
  1134. storage.setValue(id, {
  1135. value
  1136. });
  1137. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  1138. source: this,
  1139. detail: {
  1140. id,
  1141. name: "Keystroke",
  1142. value,
  1143. willCommit: true,
  1144. commitKey: 1,
  1145. selStart: target.selectionStart,
  1146. selEnd: target.selectionEnd
  1147. }
  1148. });
  1149. }
  1150. };
  1151. this._dispatchEventFromSandbox(actions, jsEvent);
  1152. });
  1153. element.addEventListener("keydown", event => {
  1154. elementData.commitKey = 1;
  1155. let commitKey = -1;
  1156. if (event.key === "Escape") {
  1157. commitKey = 0;
  1158. } else if (event.key === "Enter" && !this.data.multiLine) {
  1159. commitKey = 2;
  1160. } else if (event.key === "Tab") {
  1161. elementData.commitKey = 3;
  1162. }
  1163. if (commitKey === -1) {
  1164. return;
  1165. }
  1166. const {
  1167. value
  1168. } = event.target;
  1169. if (elementData.lastCommittedValue === value) {
  1170. return;
  1171. }
  1172. elementData.lastCommittedValue = value;
  1173. elementData.userValue = value;
  1174. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  1175. source: this,
  1176. detail: {
  1177. id,
  1178. name: "Keystroke",
  1179. value,
  1180. willCommit: true,
  1181. commitKey,
  1182. selStart: event.target.selectionStart,
  1183. selEnd: event.target.selectionEnd
  1184. }
  1185. });
  1186. });
  1187. const _blurListener = blurListener;
  1188. blurListener = null;
  1189. element.addEventListener("blur", event => {
  1190. if (!elementData.focused || !event.relatedTarget) {
  1191. return;
  1192. }
  1193. if (!this.data.actions?.Blur) {
  1194. elementData.focused = false;
  1195. }
  1196. const {
  1197. value
  1198. } = event.target;
  1199. elementData.userValue = value;
  1200. if (elementData.lastCommittedValue !== value) {
  1201. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  1202. source: this,
  1203. detail: {
  1204. id,
  1205. name: "Keystroke",
  1206. value,
  1207. willCommit: true,
  1208. commitKey: elementData.commitKey,
  1209. selStart: event.target.selectionStart,
  1210. selEnd: event.target.selectionEnd
  1211. }
  1212. });
  1213. }
  1214. _blurListener(event);
  1215. });
  1216. if (this.data.actions?.Keystroke) {
  1217. element.addEventListener("beforeinput", event => {
  1218. elementData.lastCommittedValue = null;
  1219. const {
  1220. data,
  1221. target
  1222. } = event;
  1223. const {
  1224. value,
  1225. selectionStart,
  1226. selectionEnd
  1227. } = target;
  1228. let selStart = selectionStart,
  1229. selEnd = selectionEnd;
  1230. switch (event.inputType) {
  1231. case "deleteWordBackward":
  1232. {
  1233. const match = value.substring(0, selectionStart).match(/\w*[^\w]*$/);
  1234. if (match) {
  1235. selStart -= match[0].length;
  1236. }
  1237. break;
  1238. }
  1239. case "deleteWordForward":
  1240. {
  1241. const match = value.substring(selectionStart).match(/^[^\w]*\w*/);
  1242. if (match) {
  1243. selEnd += match[0].length;
  1244. }
  1245. break;
  1246. }
  1247. case "deleteContentBackward":
  1248. if (selectionStart === selectionEnd) {
  1249. selStart -= 1;
  1250. }
  1251. break;
  1252. case "deleteContentForward":
  1253. if (selectionStart === selectionEnd) {
  1254. selEnd += 1;
  1255. }
  1256. break;
  1257. }
  1258. event.preventDefault();
  1259. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  1260. source: this,
  1261. detail: {
  1262. id,
  1263. name: "Keystroke",
  1264. value,
  1265. change: data || "",
  1266. willCommit: false,
  1267. selStart,
  1268. selEnd
  1269. }
  1270. });
  1271. });
  1272. }
  1273. this._setEventListeners(element, elementData, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.value);
  1274. }
  1275. if (blurListener) {
  1276. element.addEventListener("blur", blurListener);
  1277. }
  1278. if (this.data.comb) {
  1279. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  1280. const combWidth = fieldWidth / maxLen;
  1281. element.classList.add("comb");
  1282. element.style.letterSpacing = `calc(${combWidth}px * var(--scale-factor) - 1ch)`;
  1283. }
  1284. } else {
  1285. element = document.createElement("div");
  1286. element.textContent = this.data.fieldValue;
  1287. element.style.verticalAlign = "middle";
  1288. element.style.display = "table-cell";
  1289. if (this.data.hasOwnCanvas) {
  1290. element.hidden = true;
  1291. }
  1292. }
  1293. this._setTextStyle(element);
  1294. this._setBackgroundColor(element);
  1295. this._setDefaultPropertiesFromJS(element);
  1296. this.container.append(element);
  1297. return this.container;
  1298. }
  1299. }
  1300. class SignatureWidgetAnnotationElement extends WidgetAnnotationElement {
  1301. constructor(parameters) {
  1302. super(parameters, {
  1303. isRenderable: !!parameters.data.hasOwnCanvas
  1304. });
  1305. }
  1306. }
  1307. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  1308. constructor(parameters) {
  1309. super(parameters, {
  1310. isRenderable: parameters.renderForms
  1311. });
  1312. }
  1313. render() {
  1314. const storage = this.annotationStorage;
  1315. const data = this.data;
  1316. const id = data.id;
  1317. let value = storage.getValue(id, {
  1318. value: data.exportValue === data.fieldValue
  1319. }).value;
  1320. if (typeof value === "string") {
  1321. value = value !== "Off";
  1322. storage.setValue(id, {
  1323. value
  1324. });
  1325. }
  1326. this.container.classList.add("buttonWidgetAnnotation", "checkBox");
  1327. const element = document.createElement("input");
  1328. GetElementsByNameSet.add(element);
  1329. element.setAttribute("data-element-id", id);
  1330. element.disabled = data.readOnly;
  1331. this._setRequired(element, this.data.required);
  1332. element.type = "checkbox";
  1333. element.name = data.fieldName;
  1334. if (value) {
  1335. element.setAttribute("checked", true);
  1336. }
  1337. element.setAttribute("exportValue", data.exportValue);
  1338. element.tabIndex = DEFAULT_TAB_INDEX;
  1339. element.addEventListener("change", event => {
  1340. const {
  1341. name,
  1342. checked
  1343. } = event.target;
  1344. for (const checkbox of this._getElementsByName(name, id)) {
  1345. const curChecked = checked && checkbox.exportValue === data.exportValue;
  1346. if (checkbox.domElement) {
  1347. checkbox.domElement.checked = curChecked;
  1348. }
  1349. storage.setValue(checkbox.id, {
  1350. value: curChecked
  1351. });
  1352. }
  1353. storage.setValue(id, {
  1354. value: checked
  1355. });
  1356. });
  1357. element.addEventListener("resetform", event => {
  1358. const defaultValue = data.defaultFieldValue || "Off";
  1359. event.target.checked = defaultValue === data.exportValue;
  1360. });
  1361. if (this.enableScripting && this.hasJSActions) {
  1362. element.addEventListener("updatefromsandbox", jsEvent => {
  1363. const actions = {
  1364. value(event) {
  1365. event.target.checked = event.detail.value !== "Off";
  1366. storage.setValue(id, {
  1367. value: event.target.checked
  1368. });
  1369. }
  1370. };
  1371. this._dispatchEventFromSandbox(actions, jsEvent);
  1372. });
  1373. this._setEventListeners(element, null, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.checked);
  1374. }
  1375. this._setBackgroundColor(element);
  1376. this._setDefaultPropertiesFromJS(element);
  1377. this.container.append(element);
  1378. return this.container;
  1379. }
  1380. }
  1381. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  1382. constructor(parameters) {
  1383. super(parameters, {
  1384. isRenderable: parameters.renderForms
  1385. });
  1386. }
  1387. render() {
  1388. this.container.classList.add("buttonWidgetAnnotation", "radioButton");
  1389. const storage = this.annotationStorage;
  1390. const data = this.data;
  1391. const id = data.id;
  1392. let value = storage.getValue(id, {
  1393. value: data.fieldValue === data.buttonValue
  1394. }).value;
  1395. if (typeof value === "string") {
  1396. value = value !== data.buttonValue;
  1397. storage.setValue(id, {
  1398. value
  1399. });
  1400. }
  1401. if (value) {
  1402. for (const radio of this._getElementsByName(data.fieldName, id)) {
  1403. storage.setValue(radio.id, {
  1404. value: false
  1405. });
  1406. }
  1407. }
  1408. const element = document.createElement("input");
  1409. GetElementsByNameSet.add(element);
  1410. element.setAttribute("data-element-id", id);
  1411. element.disabled = data.readOnly;
  1412. this._setRequired(element, this.data.required);
  1413. element.type = "radio";
  1414. element.name = data.fieldName;
  1415. if (value) {
  1416. element.setAttribute("checked", true);
  1417. }
  1418. element.tabIndex = DEFAULT_TAB_INDEX;
  1419. element.addEventListener("change", event => {
  1420. const {
  1421. name,
  1422. checked
  1423. } = event.target;
  1424. for (const radio of this._getElementsByName(name, id)) {
  1425. storage.setValue(radio.id, {
  1426. value: false
  1427. });
  1428. }
  1429. storage.setValue(id, {
  1430. value: checked
  1431. });
  1432. });
  1433. element.addEventListener("resetform", event => {
  1434. const defaultValue = data.defaultFieldValue;
  1435. event.target.checked = defaultValue !== null && defaultValue !== undefined && defaultValue === data.buttonValue;
  1436. });
  1437. if (this.enableScripting && this.hasJSActions) {
  1438. const pdfButtonValue = data.buttonValue;
  1439. element.addEventListener("updatefromsandbox", jsEvent => {
  1440. const actions = {
  1441. value: event => {
  1442. const checked = pdfButtonValue === event.detail.value;
  1443. for (const radio of this._getElementsByName(event.target.name)) {
  1444. const curChecked = checked && radio.id === id;
  1445. if (radio.domElement) {
  1446. radio.domElement.checked = curChecked;
  1447. }
  1448. storage.setValue(radio.id, {
  1449. value: curChecked
  1450. });
  1451. }
  1452. }
  1453. };
  1454. this._dispatchEventFromSandbox(actions, jsEvent);
  1455. });
  1456. this._setEventListeners(element, null, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.checked);
  1457. }
  1458. this._setBackgroundColor(element);
  1459. this._setDefaultPropertiesFromJS(element);
  1460. this.container.append(element);
  1461. return this.container;
  1462. }
  1463. }
  1464. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  1465. constructor(parameters) {
  1466. super(parameters, {
  1467. ignoreBorder: parameters.data.hasAppearance
  1468. });
  1469. }
  1470. render() {
  1471. const container = super.render();
  1472. container.classList.add("buttonWidgetAnnotation", "pushButton");
  1473. if (this.data.alternativeText) {
  1474. container.title = this.data.alternativeText;
  1475. }
  1476. const linkElement = container.lastChild;
  1477. if (this.enableScripting && this.hasJSActions && linkElement) {
  1478. this._setDefaultPropertiesFromJS(linkElement);
  1479. linkElement.addEventListener("updatefromsandbox", jsEvent => {
  1480. this._dispatchEventFromSandbox({}, jsEvent);
  1481. });
  1482. }
  1483. return container;
  1484. }
  1485. }
  1486. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  1487. constructor(parameters) {
  1488. super(parameters, {
  1489. isRenderable: parameters.renderForms
  1490. });
  1491. }
  1492. render() {
  1493. this.container.classList.add("choiceWidgetAnnotation");
  1494. const storage = this.annotationStorage;
  1495. const id = this.data.id;
  1496. const storedData = storage.getValue(id, {
  1497. value: this.data.fieldValue
  1498. });
  1499. const selectElement = document.createElement("select");
  1500. GetElementsByNameSet.add(selectElement);
  1501. selectElement.setAttribute("data-element-id", id);
  1502. selectElement.disabled = this.data.readOnly;
  1503. this._setRequired(selectElement, this.data.required);
  1504. selectElement.name = this.data.fieldName;
  1505. selectElement.tabIndex = DEFAULT_TAB_INDEX;
  1506. let addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
  1507. if (!this.data.combo) {
  1508. selectElement.size = this.data.options.length;
  1509. if (this.data.multiSelect) {
  1510. selectElement.multiple = true;
  1511. }
  1512. }
  1513. selectElement.addEventListener("resetform", event => {
  1514. const defaultValue = this.data.defaultFieldValue;
  1515. for (const option of selectElement.options) {
  1516. option.selected = option.value === defaultValue;
  1517. }
  1518. });
  1519. for (const option of this.data.options) {
  1520. const optionElement = document.createElement("option");
  1521. optionElement.textContent = option.displayValue;
  1522. optionElement.value = option.exportValue;
  1523. if (storedData.value.includes(option.exportValue)) {
  1524. optionElement.setAttribute("selected", true);
  1525. addAnEmptyEntry = false;
  1526. }
  1527. selectElement.append(optionElement);
  1528. }
  1529. let removeEmptyEntry = null;
  1530. if (addAnEmptyEntry) {
  1531. const noneOptionElement = document.createElement("option");
  1532. noneOptionElement.value = " ";
  1533. noneOptionElement.setAttribute("hidden", true);
  1534. noneOptionElement.setAttribute("selected", true);
  1535. selectElement.prepend(noneOptionElement);
  1536. removeEmptyEntry = () => {
  1537. noneOptionElement.remove();
  1538. selectElement.removeEventListener("input", removeEmptyEntry);
  1539. removeEmptyEntry = null;
  1540. };
  1541. selectElement.addEventListener("input", removeEmptyEntry);
  1542. }
  1543. const getValue = isExport => {
  1544. const name = isExport ? "value" : "textContent";
  1545. const {
  1546. options,
  1547. multiple
  1548. } = selectElement;
  1549. if (!multiple) {
  1550. return options.selectedIndex === -1 ? null : options[options.selectedIndex][name];
  1551. }
  1552. return Array.prototype.filter.call(options, option => option.selected).map(option => option[name]);
  1553. };
  1554. let selectedValues = getValue(false);
  1555. const getItems = event => {
  1556. const options = event.target.options;
  1557. return Array.prototype.map.call(options, option => {
  1558. return {
  1559. displayValue: option.textContent,
  1560. exportValue: option.value
  1561. };
  1562. });
  1563. };
  1564. if (this.enableScripting && this.hasJSActions) {
  1565. selectElement.addEventListener("updatefromsandbox", jsEvent => {
  1566. const actions = {
  1567. value(event) {
  1568. removeEmptyEntry?.();
  1569. const value = event.detail.value;
  1570. const values = new Set(Array.isArray(value) ? value : [value]);
  1571. for (const option of selectElement.options) {
  1572. option.selected = values.has(option.value);
  1573. }
  1574. storage.setValue(id, {
  1575. value: getValue(true)
  1576. });
  1577. selectedValues = getValue(false);
  1578. },
  1579. multipleSelection(event) {
  1580. selectElement.multiple = true;
  1581. },
  1582. remove(event) {
  1583. const options = selectElement.options;
  1584. const index = event.detail.remove;
  1585. options[index].selected = false;
  1586. selectElement.remove(index);
  1587. if (options.length > 0) {
  1588. const i = Array.prototype.findIndex.call(options, option => option.selected);
  1589. if (i === -1) {
  1590. options[0].selected = true;
  1591. }
  1592. }
  1593. storage.setValue(id, {
  1594. value: getValue(true),
  1595. items: getItems(event)
  1596. });
  1597. selectedValues = getValue(false);
  1598. },
  1599. clear(event) {
  1600. while (selectElement.length !== 0) {
  1601. selectElement.remove(0);
  1602. }
  1603. storage.setValue(id, {
  1604. value: null,
  1605. items: []
  1606. });
  1607. selectedValues = getValue(false);
  1608. },
  1609. insert(event) {
  1610. const {
  1611. index,
  1612. displayValue,
  1613. exportValue
  1614. } = event.detail.insert;
  1615. const selectChild = selectElement.children[index];
  1616. const optionElement = document.createElement("option");
  1617. optionElement.textContent = displayValue;
  1618. optionElement.value = exportValue;
  1619. if (selectChild) {
  1620. selectChild.before(optionElement);
  1621. } else {
  1622. selectElement.append(optionElement);
  1623. }
  1624. storage.setValue(id, {
  1625. value: getValue(true),
  1626. items: getItems(event)
  1627. });
  1628. selectedValues = getValue(false);
  1629. },
  1630. items(event) {
  1631. const {
  1632. items
  1633. } = event.detail;
  1634. while (selectElement.length !== 0) {
  1635. selectElement.remove(0);
  1636. }
  1637. for (const item of items) {
  1638. const {
  1639. displayValue,
  1640. exportValue
  1641. } = item;
  1642. const optionElement = document.createElement("option");
  1643. optionElement.textContent = displayValue;
  1644. optionElement.value = exportValue;
  1645. selectElement.append(optionElement);
  1646. }
  1647. if (selectElement.options.length > 0) {
  1648. selectElement.options[0].selected = true;
  1649. }
  1650. storage.setValue(id, {
  1651. value: getValue(true),
  1652. items: getItems(event)
  1653. });
  1654. selectedValues = getValue(false);
  1655. },
  1656. indices(event) {
  1657. const indices = new Set(event.detail.indices);
  1658. for (const option of event.target.options) {
  1659. option.selected = indices.has(option.index);
  1660. }
  1661. storage.setValue(id, {
  1662. value: getValue(true)
  1663. });
  1664. selectedValues = getValue(false);
  1665. },
  1666. editable(event) {
  1667. event.target.disabled = !event.detail.editable;
  1668. }
  1669. };
  1670. this._dispatchEventFromSandbox(actions, jsEvent);
  1671. });
  1672. selectElement.addEventListener("input", event => {
  1673. const exportValue = getValue(true);
  1674. storage.setValue(id, {
  1675. value: exportValue
  1676. });
  1677. event.preventDefault();
  1678. this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
  1679. source: this,
  1680. detail: {
  1681. id,
  1682. name: "Keystroke",
  1683. value: selectedValues,
  1684. changeEx: exportValue,
  1685. willCommit: false,
  1686. commitKey: 1,
  1687. keyDown: false
  1688. }
  1689. });
  1690. });
  1691. this._setEventListeners(selectElement, null, [["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"], ["input", "Action"], ["input", "Validate"]], event => event.target.value);
  1692. } else {
  1693. selectElement.addEventListener("input", function (event) {
  1694. storage.setValue(id, {
  1695. value: getValue(true)
  1696. });
  1697. });
  1698. }
  1699. if (this.data.combo) {
  1700. this._setTextStyle(selectElement);
  1701. } else {}
  1702. this._setBackgroundColor(selectElement);
  1703. this._setDefaultPropertiesFromJS(selectElement);
  1704. this.container.append(selectElement);
  1705. return this.container;
  1706. }
  1707. }
  1708. class PopupAnnotationElement extends AnnotationElement {
  1709. constructor(parameters) {
  1710. const {
  1711. data,
  1712. elements
  1713. } = parameters;
  1714. super(parameters, {
  1715. isRenderable: AnnotationElement._hasPopupData(data)
  1716. });
  1717. this.elements = elements;
  1718. }
  1719. render() {
  1720. this.container.classList.add("popupAnnotation");
  1721. const popup = new PopupElement({
  1722. container: this.container,
  1723. color: this.data.color,
  1724. titleObj: this.data.titleObj,
  1725. modificationDate: this.data.modificationDate,
  1726. contentsObj: this.data.contentsObj,
  1727. richText: this.data.richText,
  1728. rect: this.data.rect,
  1729. parentRect: this.data.parentRect || null,
  1730. parent: this.parent,
  1731. elements: this.elements,
  1732. open: this.data.open
  1733. });
  1734. const elementIds = [];
  1735. for (const element of this.elements) {
  1736. element.popup = popup;
  1737. elementIds.push(element.data.id);
  1738. element.addHighlightArea();
  1739. }
  1740. this.container.setAttribute("aria-controls", elementIds.map(id => `${util.AnnotationPrefix}${id}`).join(","));
  1741. return this.container;
  1742. }
  1743. }
  1744. class PopupElement {
  1745. #boundKeyDown = this.#keyDown.bind(this);
  1746. #boundHide = this.#hide.bind(this);
  1747. #boundShow = this.#show.bind(this);
  1748. #boundToggle = this.#toggle.bind(this);
  1749. #color = null;
  1750. #container = null;
  1751. #contentsObj = null;
  1752. #dateObj = null;
  1753. #elements = null;
  1754. #parent = null;
  1755. #parentRect = null;
  1756. #pinned = false;
  1757. #popup = null;
  1758. #rect = null;
  1759. #richText = null;
  1760. #titleObj = null;
  1761. #wasVisible = false;
  1762. constructor({
  1763. container,
  1764. color,
  1765. elements,
  1766. titleObj,
  1767. modificationDate,
  1768. contentsObj,
  1769. richText,
  1770. parent,
  1771. rect,
  1772. parentRect,
  1773. open
  1774. }) {
  1775. this.#container = container;
  1776. this.#titleObj = titleObj;
  1777. this.#contentsObj = contentsObj;
  1778. this.#richText = richText;
  1779. this.#parent = parent;
  1780. this.#color = color;
  1781. this.#rect = rect;
  1782. this.#parentRect = parentRect;
  1783. this.#elements = elements;
  1784. this.#dateObj = display_utils.PDFDateString.toDateObject(modificationDate);
  1785. this.trigger = elements.flatMap(e => e.getElementsToTriggerPopup());
  1786. for (const element of this.trigger) {
  1787. element.addEventListener("click", this.#boundToggle);
  1788. element.addEventListener("mouseenter", this.#boundShow);
  1789. element.addEventListener("mouseleave", this.#boundHide);
  1790. element.classList.add("popupTriggerArea");
  1791. }
  1792. for (const element of elements) {
  1793. element.container?.addEventListener("keydown", this.#boundKeyDown);
  1794. }
  1795. this.#container.hidden = true;
  1796. if (open) {
  1797. this.#toggle();
  1798. }
  1799. }
  1800. render() {
  1801. if (this.#popup) {
  1802. return;
  1803. }
  1804. const {
  1805. page: {
  1806. view
  1807. },
  1808. viewport: {
  1809. rawDims: {
  1810. pageWidth,
  1811. pageHeight,
  1812. pageX,
  1813. pageY
  1814. }
  1815. }
  1816. } = this.#parent;
  1817. const popup = this.#popup = document.createElement("div");
  1818. popup.className = "popup";
  1819. if (this.#color) {
  1820. const baseColor = popup.style.outlineColor = util.Util.makeHexColor(...this.#color);
  1821. if (CSS.supports("background-color", "color-mix(in srgb, red 30%, white)")) {
  1822. popup.style.backgroundColor = `color-mix(in srgb, ${baseColor} 30%, white)`;
  1823. } else {
  1824. const BACKGROUND_ENLIGHT = 0.7;
  1825. popup.style.backgroundColor = util.Util.makeHexColor(...this.#color.map(c => Math.floor(BACKGROUND_ENLIGHT * (255 - c) + c)));
  1826. }
  1827. }
  1828. const header = document.createElement("span");
  1829. header.className = "header";
  1830. const title = document.createElement("h1");
  1831. header.append(title);
  1832. ({
  1833. dir: title.dir,
  1834. str: title.textContent
  1835. } = this.#titleObj);
  1836. popup.append(header);
  1837. if (this.#dateObj) {
  1838. const modificationDate = document.createElement("span");
  1839. modificationDate.classList.add("popupDate");
  1840. modificationDate.setAttribute("data-l10n-id", "pdfjs-annotation-date-string");
  1841. modificationDate.setAttribute("data-l10n-args", JSON.stringify({
  1842. date: this.#dateObj.toLocaleDateString(),
  1843. time: this.#dateObj.toLocaleTimeString()
  1844. }));
  1845. header.append(modificationDate);
  1846. }
  1847. const contentsObj = this.#contentsObj;
  1848. const richText = this.#richText;
  1849. if (richText?.str && (!contentsObj?.str || contentsObj.str === richText.str)) {
  1850. xfa_layer.XfaLayer.render({
  1851. xfaHtml: richText.html,
  1852. intent: "richText",
  1853. div: popup
  1854. });
  1855. popup.lastChild.classList.add("richText", "popupContent");
  1856. } else {
  1857. const contents = this._formatContents(contentsObj);
  1858. popup.append(contents);
  1859. }
  1860. let useParentRect = !!this.#parentRect;
  1861. let rect = useParentRect ? this.#parentRect : this.#rect;
  1862. for (const element of this.#elements) {
  1863. if (!rect || util.Util.intersect(element.data.rect, rect) !== null) {
  1864. rect = element.data.rect;
  1865. useParentRect = true;
  1866. break;
  1867. }
  1868. }
  1869. const normalizedRect = util.Util.normalizeRect([rect[0], view[3] - rect[1] + view[1], rect[2], view[3] - rect[3] + view[1]]);
  1870. const HORIZONTAL_SPACE_AFTER_ANNOTATION = 5;
  1871. const parentWidth = useParentRect ? rect[2] - rect[0] + HORIZONTAL_SPACE_AFTER_ANNOTATION : 0;
  1872. const popupLeft = normalizedRect[0] + parentWidth;
  1873. const popupTop = normalizedRect[1];
  1874. const {
  1875. style
  1876. } = this.#container;
  1877. style.left = `${100 * (popupLeft - pageX) / pageWidth}%`;
  1878. style.top = `${100 * (popupTop - pageY) / pageHeight}%`;
  1879. this.#container.append(popup);
  1880. }
  1881. _formatContents({
  1882. str,
  1883. dir
  1884. }) {
  1885. const p = document.createElement("p");
  1886. p.classList.add("popupContent");
  1887. p.dir = dir;
  1888. const lines = str.split(/(?:\r\n?|\n)/);
  1889. for (let i = 0, ii = lines.length; i < ii; ++i) {
  1890. const line = lines[i];
  1891. p.append(document.createTextNode(line));
  1892. if (i < ii - 1) {
  1893. p.append(document.createElement("br"));
  1894. }
  1895. }
  1896. return p;
  1897. }
  1898. #keyDown(event) {
  1899. if (event.altKey || event.shiftKey || event.ctrlKey || event.metaKey) {
  1900. return;
  1901. }
  1902. if (event.key === "Enter" || event.key === "Escape" && this.#pinned) {
  1903. this.#toggle();
  1904. }
  1905. }
  1906. #toggle() {
  1907. this.#pinned = !this.#pinned;
  1908. if (this.#pinned) {
  1909. this.#show();
  1910. this.#container.addEventListener("click", this.#boundToggle);
  1911. this.#container.addEventListener("keydown", this.#boundKeyDown);
  1912. } else {
  1913. this.#hide();
  1914. this.#container.removeEventListener("click", this.#boundToggle);
  1915. this.#container.removeEventListener("keydown", this.#boundKeyDown);
  1916. }
  1917. }
  1918. #show() {
  1919. if (!this.#popup) {
  1920. this.render();
  1921. }
  1922. if (!this.isVisible) {
  1923. this.#container.hidden = false;
  1924. this.#container.style.zIndex = parseInt(this.#container.style.zIndex) + 1000;
  1925. } else if (this.#pinned) {
  1926. this.#container.classList.add("focused");
  1927. }
  1928. }
  1929. #hide() {
  1930. this.#container.classList.remove("focused");
  1931. if (this.#pinned || !this.isVisible) {
  1932. return;
  1933. }
  1934. this.#container.hidden = true;
  1935. this.#container.style.zIndex = parseInt(this.#container.style.zIndex) - 1000;
  1936. }
  1937. forceHide() {
  1938. this.#wasVisible = this.isVisible;
  1939. if (!this.#wasVisible) {
  1940. return;
  1941. }
  1942. this.#container.hidden = true;
  1943. }
  1944. maybeShow() {
  1945. if (!this.#wasVisible) {
  1946. return;
  1947. }
  1948. this.#wasVisible = false;
  1949. this.#container.hidden = false;
  1950. }
  1951. get isVisible() {
  1952. return this.#container.hidden === false;
  1953. }
  1954. }
  1955. class FreeTextAnnotationElement extends AnnotationElement {
  1956. constructor(parameters) {
  1957. super(parameters, {
  1958. isRenderable: true,
  1959. ignoreBorder: true
  1960. });
  1961. this.textContent = parameters.data.textContent;
  1962. this.textPosition = parameters.data.textPosition;
  1963. this.annotationEditorType = util.AnnotationEditorType.FREETEXT;
  1964. }
  1965. render() {
  1966. this.container.classList.add("freeTextAnnotation");
  1967. if (this.textContent) {
  1968. const content = document.createElement("div");
  1969. content.classList.add("annotationTextContent");
  1970. content.setAttribute("role", "comment");
  1971. for (const line of this.textContent) {
  1972. const lineSpan = document.createElement("span");
  1973. lineSpan.textContent = line;
  1974. content.append(lineSpan);
  1975. }
  1976. this.container.append(content);
  1977. }
  1978. if (!this.data.popupRef && this.hasPopupData) {
  1979. this._createPopup();
  1980. }
  1981. this._editOnDoubleClick();
  1982. return this.container;
  1983. }
  1984. get _isEditable() {
  1985. return this.data.hasOwnCanvas;
  1986. }
  1987. }
  1988. class LineAnnotationElement extends AnnotationElement {
  1989. #line = null;
  1990. constructor(parameters) {
  1991. super(parameters, {
  1992. isRenderable: true,
  1993. ignoreBorder: true
  1994. });
  1995. }
  1996. render() {
  1997. this.container.classList.add("lineAnnotation");
  1998. const data = this.data;
  1999. const {
  2000. width,
  2001. height
  2002. } = getRectDims(data.rect);
  2003. const svg = this.svgFactory.create(width, height, true);
  2004. const line = this.#line = this.svgFactory.createElement("svg:line");
  2005. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  2006. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  2007. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  2008. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  2009. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  2010. line.setAttribute("stroke", "transparent");
  2011. line.setAttribute("fill", "transparent");
  2012. svg.append(line);
  2013. this.container.append(svg);
  2014. if (!data.popupRef && this.hasPopupData) {
  2015. this._createPopup();
  2016. }
  2017. return this.container;
  2018. }
  2019. getElementsToTriggerPopup() {
  2020. return this.#line;
  2021. }
  2022. addHighlightArea() {
  2023. this.container.classList.add("highlightArea");
  2024. }
  2025. }
  2026. class SquareAnnotationElement extends AnnotationElement {
  2027. #square = null;
  2028. constructor(parameters) {
  2029. super(parameters, {
  2030. isRenderable: true,
  2031. ignoreBorder: true
  2032. });
  2033. }
  2034. render() {
  2035. this.container.classList.add("squareAnnotation");
  2036. const data = this.data;
  2037. const {
  2038. width,
  2039. height
  2040. } = getRectDims(data.rect);
  2041. const svg = this.svgFactory.create(width, height, true);
  2042. const borderWidth = data.borderStyle.width;
  2043. const square = this.#square = this.svgFactory.createElement("svg:rect");
  2044. square.setAttribute("x", borderWidth / 2);
  2045. square.setAttribute("y", borderWidth / 2);
  2046. square.setAttribute("width", width - borderWidth);
  2047. square.setAttribute("height", height - borderWidth);
  2048. square.setAttribute("stroke-width", borderWidth || 1);
  2049. square.setAttribute("stroke", "transparent");
  2050. square.setAttribute("fill", "transparent");
  2051. svg.append(square);
  2052. this.container.append(svg);
  2053. if (!data.popupRef && this.hasPopupData) {
  2054. this._createPopup();
  2055. }
  2056. return this.container;
  2057. }
  2058. getElementsToTriggerPopup() {
  2059. return this.#square;
  2060. }
  2061. addHighlightArea() {
  2062. this.container.classList.add("highlightArea");
  2063. }
  2064. }
  2065. class CircleAnnotationElement extends AnnotationElement {
  2066. #circle = null;
  2067. constructor(parameters) {
  2068. super(parameters, {
  2069. isRenderable: true,
  2070. ignoreBorder: true
  2071. });
  2072. }
  2073. render() {
  2074. this.container.classList.add("circleAnnotation");
  2075. const data = this.data;
  2076. const {
  2077. width,
  2078. height
  2079. } = getRectDims(data.rect);
  2080. const svg = this.svgFactory.create(width, height, true);
  2081. const borderWidth = data.borderStyle.width;
  2082. const circle = this.#circle = this.svgFactory.createElement("svg:ellipse");
  2083. circle.setAttribute("cx", width / 2);
  2084. circle.setAttribute("cy", height / 2);
  2085. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  2086. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  2087. circle.setAttribute("stroke-width", borderWidth || 1);
  2088. circle.setAttribute("stroke", "transparent");
  2089. circle.setAttribute("fill", "transparent");
  2090. svg.append(circle);
  2091. this.container.append(svg);
  2092. if (!data.popupRef && this.hasPopupData) {
  2093. this._createPopup();
  2094. }
  2095. return this.container;
  2096. }
  2097. getElementsToTriggerPopup() {
  2098. return this.#circle;
  2099. }
  2100. addHighlightArea() {
  2101. this.container.classList.add("highlightArea");
  2102. }
  2103. }
  2104. class PolylineAnnotationElement extends AnnotationElement {
  2105. #polyline = null;
  2106. constructor(parameters) {
  2107. super(parameters, {
  2108. isRenderable: true,
  2109. ignoreBorder: true
  2110. });
  2111. this.containerClassName = "polylineAnnotation";
  2112. this.svgElementName = "svg:polyline";
  2113. }
  2114. render() {
  2115. this.container.classList.add(this.containerClassName);
  2116. const data = this.data;
  2117. const {
  2118. width,
  2119. height
  2120. } = getRectDims(data.rect);
  2121. const svg = this.svgFactory.create(width, height, true);
  2122. let points = [];
  2123. for (const coordinate of data.vertices) {
  2124. const x = coordinate.x - data.rect[0];
  2125. const y = data.rect[3] - coordinate.y;
  2126. points.push(x + "," + y);
  2127. }
  2128. points = points.join(" ");
  2129. const polyline = this.#polyline = this.svgFactory.createElement(this.svgElementName);
  2130. polyline.setAttribute("points", points);
  2131. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  2132. polyline.setAttribute("stroke", "transparent");
  2133. polyline.setAttribute("fill", "transparent");
  2134. svg.append(polyline);
  2135. this.container.append(svg);
  2136. if (!data.popupRef && this.hasPopupData) {
  2137. this._createPopup();
  2138. }
  2139. return this.container;
  2140. }
  2141. getElementsToTriggerPopup() {
  2142. return this.#polyline;
  2143. }
  2144. addHighlightArea() {
  2145. this.container.classList.add("highlightArea");
  2146. }
  2147. }
  2148. class PolygonAnnotationElement extends PolylineAnnotationElement {
  2149. constructor(parameters) {
  2150. super(parameters);
  2151. this.containerClassName = "polygonAnnotation";
  2152. this.svgElementName = "svg:polygon";
  2153. }
  2154. }
  2155. class CaretAnnotationElement extends AnnotationElement {
  2156. constructor(parameters) {
  2157. super(parameters, {
  2158. isRenderable: true,
  2159. ignoreBorder: true
  2160. });
  2161. }
  2162. render() {
  2163. this.container.classList.add("caretAnnotation");
  2164. if (!this.data.popupRef && this.hasPopupData) {
  2165. this._createPopup();
  2166. }
  2167. return this.container;
  2168. }
  2169. }
  2170. class InkAnnotationElement extends AnnotationElement {
  2171. #polylines = [];
  2172. constructor(parameters) {
  2173. super(parameters, {
  2174. isRenderable: true,
  2175. ignoreBorder: true
  2176. });
  2177. this.containerClassName = "inkAnnotation";
  2178. this.svgElementName = "svg:polyline";
  2179. this.annotationEditorType = util.AnnotationEditorType.INK;
  2180. }
  2181. render() {
  2182. this.container.classList.add(this.containerClassName);
  2183. const data = this.data;
  2184. const {
  2185. width,
  2186. height
  2187. } = getRectDims(data.rect);
  2188. const svg = this.svgFactory.create(width, height, true);
  2189. for (const inkList of data.inkLists) {
  2190. let points = [];
  2191. for (const coordinate of inkList) {
  2192. const x = coordinate.x - data.rect[0];
  2193. const y = data.rect[3] - coordinate.y;
  2194. points.push(`${x},${y}`);
  2195. }
  2196. points = points.join(" ");
  2197. const polyline = this.svgFactory.createElement(this.svgElementName);
  2198. this.#polylines.push(polyline);
  2199. polyline.setAttribute("points", points);
  2200. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  2201. polyline.setAttribute("stroke", "transparent");
  2202. polyline.setAttribute("fill", "transparent");
  2203. if (!data.popupRef && this.hasPopupData) {
  2204. this._createPopup();
  2205. }
  2206. svg.append(polyline);
  2207. }
  2208. this.container.append(svg);
  2209. return this.container;
  2210. }
  2211. getElementsToTriggerPopup() {
  2212. return this.#polylines;
  2213. }
  2214. addHighlightArea() {
  2215. this.container.classList.add("highlightArea");
  2216. }
  2217. }
  2218. class HighlightAnnotationElement extends AnnotationElement {
  2219. constructor(parameters) {
  2220. super(parameters, {
  2221. isRenderable: true,
  2222. ignoreBorder: true,
  2223. createQuadrilaterals: true
  2224. });
  2225. }
  2226. render() {
  2227. if (!this.data.popupRef && this.hasPopupData) {
  2228. this._createPopup();
  2229. }
  2230. this.container.classList.add("highlightAnnotation");
  2231. return this.container;
  2232. }
  2233. }
  2234. class UnderlineAnnotationElement extends AnnotationElement {
  2235. constructor(parameters) {
  2236. super(parameters, {
  2237. isRenderable: true,
  2238. ignoreBorder: true,
  2239. createQuadrilaterals: true
  2240. });
  2241. }
  2242. render() {
  2243. if (!this.data.popupRef && this.hasPopupData) {
  2244. this._createPopup();
  2245. }
  2246. this.container.classList.add("underlineAnnotation");
  2247. return this.container;
  2248. }
  2249. }
  2250. class SquigglyAnnotationElement extends AnnotationElement {
  2251. constructor(parameters) {
  2252. super(parameters, {
  2253. isRenderable: true,
  2254. ignoreBorder: true,
  2255. createQuadrilaterals: true
  2256. });
  2257. }
  2258. render() {
  2259. if (!this.data.popupRef && this.hasPopupData) {
  2260. this._createPopup();
  2261. }
  2262. this.container.classList.add("squigglyAnnotation");
  2263. return this.container;
  2264. }
  2265. }
  2266. class StrikeOutAnnotationElement extends AnnotationElement {
  2267. constructor(parameters) {
  2268. super(parameters, {
  2269. isRenderable: true,
  2270. ignoreBorder: true,
  2271. createQuadrilaterals: true
  2272. });
  2273. }
  2274. render() {
  2275. if (!this.data.popupRef && this.hasPopupData) {
  2276. this._createPopup();
  2277. }
  2278. this.container.classList.add("strikeoutAnnotation");
  2279. return this.container;
  2280. }
  2281. }
  2282. class StampAnnotationElement extends AnnotationElement {
  2283. constructor(parameters) {
  2284. super(parameters, {
  2285. isRenderable: true,
  2286. ignoreBorder: true
  2287. });
  2288. }
  2289. render() {
  2290. this.container.classList.add("stampAnnotation");
  2291. if (!this.data.popupRef && this.hasPopupData) {
  2292. this._createPopup();
  2293. }
  2294. return this.container;
  2295. }
  2296. }
  2297. class FileAttachmentAnnotationElement extends AnnotationElement {
  2298. #trigger = null;
  2299. constructor(parameters) {
  2300. super(parameters, {
  2301. isRenderable: true
  2302. });
  2303. const {
  2304. filename,
  2305. content
  2306. } = this.data.file;
  2307. this.filename = (0,display_utils.getFilenameFromUrl)(filename, true);
  2308. this.content = content;
  2309. this.linkService.eventBus?.dispatch("fileattachmentannotation", {
  2310. source: this,
  2311. filename,
  2312. content
  2313. });
  2314. }
  2315. render() {
  2316. this.container.classList.add("fileAttachmentAnnotation");
  2317. const {
  2318. container,
  2319. data
  2320. } = this;
  2321. let trigger;
  2322. if (data.hasAppearance || data.fillAlpha === 0) {
  2323. trigger = document.createElement("div");
  2324. } else {
  2325. trigger = document.createElement("img");
  2326. trigger.src = `${this.imageResourcesPath}annotation-${/paperclip/i.test(data.name) ? "paperclip" : "pushpin"}.svg`;
  2327. if (data.fillAlpha && data.fillAlpha < 1) {
  2328. trigger.style = `filter: opacity(${Math.round(data.fillAlpha * 100)}%);`;
  2329. }
  2330. }
  2331. trigger.addEventListener("dblclick", this.#download.bind(this));
  2332. this.#trigger = trigger;
  2333. const {
  2334. isMac
  2335. } = util.FeatureTest.platform;
  2336. container.addEventListener("keydown", evt => {
  2337. if (evt.key === "Enter" && (isMac ? evt.metaKey : evt.ctrlKey)) {
  2338. this.#download();
  2339. }
  2340. });
  2341. if (!data.popupRef && this.hasPopupData) {
  2342. this._createPopup();
  2343. } else {
  2344. trigger.classList.add("popupTriggerArea");
  2345. }
  2346. container.append(trigger);
  2347. return container;
  2348. }
  2349. getElementsToTriggerPopup() {
  2350. return this.#trigger;
  2351. }
  2352. addHighlightArea() {
  2353. this.container.classList.add("highlightArea");
  2354. }
  2355. #download() {
  2356. this.downloadManager?.openOrDownloadData(this.content, this.filename);
  2357. }
  2358. }
  2359. class AnnotationLayer {
  2360. #accessibilityManager = null;
  2361. #annotationCanvasMap = null;
  2362. #editableAnnotations = new Map();
  2363. constructor({
  2364. div,
  2365. accessibilityManager,
  2366. annotationCanvasMap,
  2367. page,
  2368. viewport
  2369. }) {
  2370. this.div = div;
  2371. this.#accessibilityManager = accessibilityManager;
  2372. this.#annotationCanvasMap = annotationCanvasMap;
  2373. this.page = page;
  2374. this.viewport = viewport;
  2375. this.zIndex = 0;
  2376. }
  2377. #appendElement(element, id) {
  2378. const contentElement = element.firstChild || element;
  2379. contentElement.id = `${util.AnnotationPrefix}${id}`;
  2380. this.div.append(element);
  2381. this.#accessibilityManager?.moveElementInDOM(this.div, element, contentElement, false);
  2382. }
  2383. async render(params) {
  2384. const {
  2385. annotations
  2386. } = params;
  2387. const layer = this.div;
  2388. (0,display_utils.setLayerDimensions)(layer, this.viewport);
  2389. const popupToElements = new Map();
  2390. const elementParams = {
  2391. data: null,
  2392. layer,
  2393. linkService: params.linkService,
  2394. downloadManager: params.downloadManager,
  2395. imageResourcesPath: params.imageResourcesPath || "",
  2396. renderForms: params.renderForms !== false,
  2397. svgFactory: new display_utils.DOMSVGFactory(),
  2398. annotationStorage: params.annotationStorage || new annotation_storage.AnnotationStorage(),
  2399. enableScripting: params.enableScripting === true,
  2400. hasJSActions: params.hasJSActions,
  2401. fieldObjects: params.fieldObjects,
  2402. parent: this,
  2403. elements: null
  2404. };
  2405. for (const data of annotations) {
  2406. if (data.noHTML) {
  2407. continue;
  2408. }
  2409. const isPopupAnnotation = data.annotationType === util.AnnotationType.POPUP;
  2410. if (!isPopupAnnotation) {
  2411. const {
  2412. width,
  2413. height
  2414. } = getRectDims(data.rect);
  2415. if (width <= 0 || height <= 0) {
  2416. continue;
  2417. }
  2418. } else {
  2419. const elements = popupToElements.get(data.id);
  2420. if (!elements) {
  2421. continue;
  2422. }
  2423. elementParams.elements = elements;
  2424. }
  2425. elementParams.data = data;
  2426. const element = AnnotationElementFactory.create(elementParams);
  2427. if (!element.isRenderable) {
  2428. continue;
  2429. }
  2430. if (!isPopupAnnotation && data.popupRef) {
  2431. const elements = popupToElements.get(data.popupRef);
  2432. if (!elements) {
  2433. popupToElements.set(data.popupRef, [element]);
  2434. } else {
  2435. elements.push(element);
  2436. }
  2437. }
  2438. if (element.annotationEditorType > 0) {
  2439. this.#editableAnnotations.set(element.data.id, element);
  2440. }
  2441. const rendered = element.render();
  2442. if (data.hidden) {
  2443. rendered.style.visibility = "hidden";
  2444. }
  2445. this.#appendElement(rendered, data.id);
  2446. }
  2447. this.#setAnnotationCanvasMap();
  2448. }
  2449. update({
  2450. viewport
  2451. }) {
  2452. const layer = this.div;
  2453. this.viewport = viewport;
  2454. (0,display_utils.setLayerDimensions)(layer, {
  2455. rotation: viewport.rotation
  2456. });
  2457. this.#setAnnotationCanvasMap();
  2458. layer.hidden = false;
  2459. }
  2460. #setAnnotationCanvasMap() {
  2461. if (!this.#annotationCanvasMap) {
  2462. return;
  2463. }
  2464. const layer = this.div;
  2465. for (const [id, canvas] of this.#annotationCanvasMap) {
  2466. const element = layer.querySelector(`[data-annotation-id="${id}"]`);
  2467. if (!element) {
  2468. continue;
  2469. }
  2470. const {
  2471. firstChild
  2472. } = element;
  2473. if (!firstChild) {
  2474. element.append(canvas);
  2475. } else if (firstChild.nodeName === "CANVAS") {
  2476. firstChild.replaceWith(canvas);
  2477. } else {
  2478. firstChild.before(canvas);
  2479. }
  2480. }
  2481. this.#annotationCanvasMap.clear();
  2482. }
  2483. getEditableAnnotations() {
  2484. return Array.from(this.#editableAnnotations.values());
  2485. }
  2486. getEditableAnnotation(id) {
  2487. return this.#editableAnnotations.get(id);
  2488. }
  2489. }
  2490. /***/ }),
  2491. /***/ 780:
  2492. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  2493. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  2494. /* harmony export */ AnnotationStorage: () => (/* binding */ AnnotationStorage),
  2495. /* harmony export */ PrintAnnotationStorage: () => (/* binding */ PrintAnnotationStorage),
  2496. /* harmony export */ SerializableEmpty: () => (/* binding */ SerializableEmpty)
  2497. /* harmony export */ });
  2498. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  2499. /* harmony import */ var _editor_editor_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(115);
  2500. /* harmony import */ var _shared_murmurhash3_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(825);
  2501. const SerializableEmpty = Object.freeze({
  2502. map: null,
  2503. hash: "",
  2504. transfer: undefined
  2505. });
  2506. class AnnotationStorage {
  2507. #modified = false;
  2508. #storage = new Map();
  2509. constructor() {
  2510. this.onSetModified = null;
  2511. this.onResetModified = null;
  2512. this.onAnnotationEditor = null;
  2513. }
  2514. getValue(key, defaultValue) {
  2515. const value = this.#storage.get(key);
  2516. if (value === undefined) {
  2517. return defaultValue;
  2518. }
  2519. return Object.assign(defaultValue, value);
  2520. }
  2521. getRawValue(key) {
  2522. return this.#storage.get(key);
  2523. }
  2524. remove(key) {
  2525. this.#storage.delete(key);
  2526. if (this.#storage.size === 0) {
  2527. this.resetModified();
  2528. }
  2529. if (typeof this.onAnnotationEditor === "function") {
  2530. for (const value of this.#storage.values()) {
  2531. if (value instanceof _editor_editor_js__WEBPACK_IMPORTED_MODULE_1__.AnnotationEditor) {
  2532. return;
  2533. }
  2534. }
  2535. this.onAnnotationEditor(null);
  2536. }
  2537. }
  2538. setValue(key, value) {
  2539. const obj = this.#storage.get(key);
  2540. let modified = false;
  2541. if (obj !== undefined) {
  2542. for (const [entry, val] of Object.entries(value)) {
  2543. if (obj[entry] !== val) {
  2544. modified = true;
  2545. obj[entry] = val;
  2546. }
  2547. }
  2548. } else {
  2549. modified = true;
  2550. this.#storage.set(key, value);
  2551. }
  2552. if (modified) {
  2553. this.#setModified();
  2554. }
  2555. if (value instanceof _editor_editor_js__WEBPACK_IMPORTED_MODULE_1__.AnnotationEditor && typeof this.onAnnotationEditor === "function") {
  2556. this.onAnnotationEditor(value.constructor._type);
  2557. }
  2558. }
  2559. has(key) {
  2560. return this.#storage.has(key);
  2561. }
  2562. getAll() {
  2563. return this.#storage.size > 0 ? (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.objectFromMap)(this.#storage) : null;
  2564. }
  2565. setAll(obj) {
  2566. for (const [key, val] of Object.entries(obj)) {
  2567. this.setValue(key, val);
  2568. }
  2569. }
  2570. get size() {
  2571. return this.#storage.size;
  2572. }
  2573. #setModified() {
  2574. if (!this.#modified) {
  2575. this.#modified = true;
  2576. if (typeof this.onSetModified === "function") {
  2577. this.onSetModified();
  2578. }
  2579. }
  2580. }
  2581. resetModified() {
  2582. if (this.#modified) {
  2583. this.#modified = false;
  2584. if (typeof this.onResetModified === "function") {
  2585. this.onResetModified();
  2586. }
  2587. }
  2588. }
  2589. get print() {
  2590. return new PrintAnnotationStorage(this);
  2591. }
  2592. get serializable() {
  2593. if (this.#storage.size === 0) {
  2594. return SerializableEmpty;
  2595. }
  2596. const map = new Map(),
  2597. hash = new _shared_murmurhash3_js__WEBPACK_IMPORTED_MODULE_2__.MurmurHash3_64(),
  2598. transfer = [];
  2599. const context = Object.create(null);
  2600. let hasBitmap = false;
  2601. for (const [key, val] of this.#storage) {
  2602. const serialized = val instanceof _editor_editor_js__WEBPACK_IMPORTED_MODULE_1__.AnnotationEditor ? val.serialize(false, context) : val;
  2603. if (serialized) {
  2604. map.set(key, serialized);
  2605. hash.update(`${key}:${JSON.stringify(serialized)}`);
  2606. hasBitmap ||= !!serialized.bitmap;
  2607. }
  2608. }
  2609. if (hasBitmap) {
  2610. for (const value of map.values()) {
  2611. if (value.bitmap) {
  2612. transfer.push(value.bitmap);
  2613. }
  2614. }
  2615. }
  2616. return map.size > 0 ? {
  2617. map,
  2618. hash: hash.hexdigest(),
  2619. transfer
  2620. } : SerializableEmpty;
  2621. }
  2622. }
  2623. class PrintAnnotationStorage extends AnnotationStorage {
  2624. #serializable;
  2625. constructor(parent) {
  2626. super();
  2627. const {
  2628. map,
  2629. hash,
  2630. transfer
  2631. } = parent.serializable;
  2632. const clone = structuredClone(map, transfer ? {
  2633. transfer
  2634. } : null);
  2635. this.#serializable = {
  2636. map: clone,
  2637. hash,
  2638. transfer
  2639. };
  2640. }
  2641. get print() {
  2642. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Should not call PrintAnnotationStorage.print");
  2643. }
  2644. get serializable() {
  2645. return this.#serializable;
  2646. }
  2647. }
  2648. /***/ }),
  2649. /***/ 406:
  2650. /***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {
  2651. __webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
  2652. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  2653. /* harmony export */ PDFDataRangeTransport: () => (/* binding */ PDFDataRangeTransport),
  2654. /* harmony export */ PDFWorker: () => (/* binding */ PDFWorker),
  2655. /* harmony export */ build: () => (/* binding */ build),
  2656. /* harmony export */ getDocument: () => (/* binding */ getDocument),
  2657. /* harmony export */ version: () => (/* binding */ version)
  2658. /* harmony export */ });
  2659. /* unused harmony exports DefaultCanvasFactory, DefaultCMapReaderFactory, DefaultFilterFactory, DefaultStandardFontDataFactory, LoopbackPort, PDFDocumentLoadingTask, PDFDocumentProxy, PDFPageProxy, PDFWorkerUtil, RenderTask */
  2660. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  2661. /* harmony import */ var _annotation_storage_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(780);
  2662. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(473);
  2663. /* harmony import */ var _font_loader_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(742);
  2664. /* harmony import */ var display_node_utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(738);
  2665. /* harmony import */ var _canvas_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(250);
  2666. /* harmony import */ var _worker_options_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(368);
  2667. /* harmony import */ var _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(694);
  2668. /* harmony import */ var _metadata_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(472);
  2669. /* harmony import */ var _optional_content_config_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(890);
  2670. /* harmony import */ var _transport_stream_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(92);
  2671. /* harmony import */ var display_fetch_stream__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(171);
  2672. /* harmony import */ var display_network__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(474);
  2673. /* harmony import */ var display_node_stream__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(498);
  2674. /* harmony import */ var _xfa_text_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(521);
  2675. var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([display_node_utils__WEBPACK_IMPORTED_MODULE_4__, display_node_stream__WEBPACK_IMPORTED_MODULE_13__]);
  2676. ([display_node_utils__WEBPACK_IMPORTED_MODULE_4__, display_node_stream__WEBPACK_IMPORTED_MODULE_13__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
  2677. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  2678. const RENDERING_CANCELLED_TIMEOUT = 100;
  2679. const DELAYED_CLEANUP_TIMEOUT = 5000;
  2680. const DefaultCanvasFactory = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS ? display_node_utils__WEBPACK_IMPORTED_MODULE_4__.NodeCanvasFactory : _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.DOMCanvasFactory;
  2681. const DefaultCMapReaderFactory = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS ? display_node_utils__WEBPACK_IMPORTED_MODULE_4__.NodeCMapReaderFactory : _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.DOMCMapReaderFactory;
  2682. const DefaultFilterFactory = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS ? display_node_utils__WEBPACK_IMPORTED_MODULE_4__.NodeFilterFactory : _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.DOMFilterFactory;
  2683. const DefaultStandardFontDataFactory = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS ? display_node_utils__WEBPACK_IMPORTED_MODULE_4__.NodeStandardFontDataFactory : _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.DOMStandardFontDataFactory;
  2684. function getDocument(src) {
  2685. if (typeof src === "string" || src instanceof URL) {
  2686. src = {
  2687. url: src
  2688. };
  2689. } else if ((0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isArrayBuffer)(src)) {
  2690. src = {
  2691. data: src
  2692. };
  2693. }
  2694. if (typeof src !== "object") {
  2695. throw new Error("Invalid parameter in getDocument, need parameter object.");
  2696. }
  2697. if (!src.url && !src.data && !src.range) {
  2698. throw new Error("Invalid parameter object: need either .data, .range or .url");
  2699. }
  2700. const task = new PDFDocumentLoadingTask();
  2701. const {
  2702. docId
  2703. } = task;
  2704. const url = src.url ? getUrlProp(src.url) : null;
  2705. const data = src.data ? getDataProp(src.data) : null;
  2706. const httpHeaders = src.httpHeaders || null;
  2707. const withCredentials = src.withCredentials === true;
  2708. const password = src.password ?? null;
  2709. const rangeTransport = src.range instanceof PDFDataRangeTransport ? src.range : null;
  2710. const rangeChunkSize = Number.isInteger(src.rangeChunkSize) && src.rangeChunkSize > 0 ? src.rangeChunkSize : DEFAULT_RANGE_CHUNK_SIZE;
  2711. let worker = src.worker instanceof PDFWorker ? src.worker : null;
  2712. const verbosity = src.verbosity;
  2713. const docBaseUrl = typeof src.docBaseUrl === "string" && !(0,_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.isDataScheme)(src.docBaseUrl) ? src.docBaseUrl : null;
  2714. const cMapUrl = typeof src.cMapUrl === "string" ? src.cMapUrl : null;
  2715. const cMapPacked = src.cMapPacked !== false;
  2716. const CMapReaderFactory = src.CMapReaderFactory || DefaultCMapReaderFactory;
  2717. const standardFontDataUrl = typeof src.standardFontDataUrl === "string" ? src.standardFontDataUrl : null;
  2718. const StandardFontDataFactory = src.StandardFontDataFactory || DefaultStandardFontDataFactory;
  2719. const ignoreErrors = src.stopAtErrors !== true;
  2720. const maxImageSize = Number.isInteger(src.maxImageSize) && src.maxImageSize > -1 ? src.maxImageSize : -1;
  2721. const isEvalSupported = src.isEvalSupported !== false;
  2722. const isOffscreenCanvasSupported = typeof src.isOffscreenCanvasSupported === "boolean" ? src.isOffscreenCanvasSupported : !_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS;
  2723. const canvasMaxAreaInBytes = Number.isInteger(src.canvasMaxAreaInBytes) ? src.canvasMaxAreaInBytes : -1;
  2724. const disableFontFace = typeof src.disableFontFace === "boolean" ? src.disableFontFace : _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS;
  2725. const fontExtraProperties = src.fontExtraProperties === true;
  2726. const enableXfa = src.enableXfa === true;
  2727. const ownerDocument = src.ownerDocument || globalThis.document;
  2728. const disableRange = src.disableRange === true;
  2729. const disableStream = src.disableStream === true;
  2730. const disableAutoFetch = src.disableAutoFetch === true;
  2731. const pdfBug = src.pdfBug === true;
  2732. const length = rangeTransport ? rangeTransport.length : src.length ?? NaN;
  2733. const useSystemFonts = typeof src.useSystemFonts === "boolean" ? src.useSystemFonts : !_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS && !disableFontFace;
  2734. const useWorkerFetch = typeof src.useWorkerFetch === "boolean" ? src.useWorkerFetch : CMapReaderFactory === _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.DOMCMapReaderFactory && StandardFontDataFactory === _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.DOMStandardFontDataFactory && cMapUrl && standardFontDataUrl && (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.isValidFetchUrl)(cMapUrl, document.baseURI) && (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.isValidFetchUrl)(standardFontDataUrl, document.baseURI);
  2735. const canvasFactory = src.canvasFactory || new DefaultCanvasFactory({
  2736. ownerDocument
  2737. });
  2738. const filterFactory = src.filterFactory || new DefaultFilterFactory({
  2739. docId,
  2740. ownerDocument
  2741. });
  2742. const styleElement = null;
  2743. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.setVerbosityLevel)(verbosity);
  2744. const transportFactory = {
  2745. canvasFactory,
  2746. filterFactory
  2747. };
  2748. if (!useWorkerFetch) {
  2749. transportFactory.cMapReaderFactory = new CMapReaderFactory({
  2750. baseUrl: cMapUrl,
  2751. isCompressed: cMapPacked
  2752. });
  2753. transportFactory.standardFontDataFactory = new StandardFontDataFactory({
  2754. baseUrl: standardFontDataUrl
  2755. });
  2756. }
  2757. if (!worker) {
  2758. const workerParams = {
  2759. verbosity,
  2760. port: _worker_options_js__WEBPACK_IMPORTED_MODULE_6__.GlobalWorkerOptions.workerPort
  2761. };
  2762. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  2763. task._worker = worker;
  2764. }
  2765. const fetchDocParams = {
  2766. docId,
  2767. apiVersion: '4.0.379',
  2768. data,
  2769. password,
  2770. disableAutoFetch,
  2771. rangeChunkSize,
  2772. length,
  2773. docBaseUrl,
  2774. enableXfa,
  2775. evaluatorOptions: {
  2776. maxImageSize,
  2777. disableFontFace,
  2778. ignoreErrors,
  2779. isEvalSupported,
  2780. isOffscreenCanvasSupported,
  2781. canvasMaxAreaInBytes,
  2782. fontExtraProperties,
  2783. useSystemFonts,
  2784. cMapUrl: useWorkerFetch ? cMapUrl : null,
  2785. standardFontDataUrl: useWorkerFetch ? standardFontDataUrl : null
  2786. }
  2787. };
  2788. const transportParams = {
  2789. ignoreErrors,
  2790. isEvalSupported,
  2791. disableFontFace,
  2792. fontExtraProperties,
  2793. enableXfa,
  2794. ownerDocument,
  2795. disableAutoFetch,
  2796. pdfBug,
  2797. styleElement
  2798. };
  2799. worker.promise.then(function () {
  2800. if (task.destroyed) {
  2801. throw new Error("Loading aborted");
  2802. }
  2803. const workerIdPromise = _fetchDocument(worker, fetchDocParams);
  2804. const networkStreamPromise = new Promise(function (resolve) {
  2805. let networkStream;
  2806. if (rangeTransport) {
  2807. networkStream = new _transport_stream_js__WEBPACK_IMPORTED_MODULE_10__.PDFDataTransportStream({
  2808. length,
  2809. initialData: rangeTransport.initialData,
  2810. progressiveDone: rangeTransport.progressiveDone,
  2811. contentDispositionFilename: rangeTransport.contentDispositionFilename,
  2812. disableRange,
  2813. disableStream
  2814. }, rangeTransport);
  2815. } else if (!data) {
  2816. const createPDFNetworkStream = params => {
  2817. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS) {
  2818. return new display_node_stream__WEBPACK_IMPORTED_MODULE_13__.PDFNodeStream(params);
  2819. }
  2820. return (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.isValidFetchUrl)(params.url) ? new display_fetch_stream__WEBPACK_IMPORTED_MODULE_11__.PDFFetchStream(params) : new display_network__WEBPACK_IMPORTED_MODULE_12__.PDFNetworkStream(params);
  2821. };
  2822. networkStream = createPDFNetworkStream({
  2823. url,
  2824. length,
  2825. httpHeaders,
  2826. withCredentials,
  2827. rangeChunkSize,
  2828. disableRange,
  2829. disableStream
  2830. });
  2831. }
  2832. resolve(networkStream);
  2833. });
  2834. return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
  2835. if (task.destroyed) {
  2836. throw new Error("Loading aborted");
  2837. }
  2838. const messageHandler = new _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__.MessageHandler(docId, workerId, worker.port);
  2839. const transport = new WorkerTransport(messageHandler, task, networkStream, transportParams, transportFactory);
  2840. task._transport = transport;
  2841. messageHandler.send("Ready", null);
  2842. });
  2843. }).catch(task._capability.reject);
  2844. return task;
  2845. }
  2846. async function _fetchDocument(worker, source) {
  2847. if (worker.destroyed) {
  2848. throw new Error("Worker was destroyed");
  2849. }
  2850. const workerId = await worker.messageHandler.sendWithPromise("GetDocRequest", source, source.data ? [source.data.buffer] : null);
  2851. if (worker.destroyed) {
  2852. throw new Error("Worker was destroyed");
  2853. }
  2854. return workerId;
  2855. }
  2856. function getUrlProp(val) {
  2857. if (val instanceof URL) {
  2858. return val.href;
  2859. }
  2860. try {
  2861. return new URL(val, window.location).href;
  2862. } catch {
  2863. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS && typeof val === "string") {
  2864. return val;
  2865. }
  2866. }
  2867. throw new Error("Invalid PDF url data: " + "either string or URL-object is expected in the url property.");
  2868. }
  2869. function getDataProp(val) {
  2870. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS && typeof Buffer !== "undefined" && val instanceof Buffer) {
  2871. throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");
  2872. }
  2873. if (val instanceof Uint8Array && val.byteLength === val.buffer.byteLength) {
  2874. return val;
  2875. }
  2876. if (typeof val === "string") {
  2877. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.stringToBytes)(val);
  2878. }
  2879. if (typeof val === "object" && !isNaN(val?.length) || (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isArrayBuffer)(val)) {
  2880. return new Uint8Array(val);
  2881. }
  2882. throw new Error("Invalid PDF binary data: either TypedArray, " + "string, or array-like object is expected in the data property.");
  2883. }
  2884. class PDFDocumentLoadingTask {
  2885. static #docId = 0;
  2886. constructor() {
  2887. this._capability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  2888. this._transport = null;
  2889. this._worker = null;
  2890. this.docId = `d${PDFDocumentLoadingTask.#docId++}`;
  2891. this.destroyed = false;
  2892. this.onPassword = null;
  2893. this.onProgress = null;
  2894. }
  2895. get promise() {
  2896. return this._capability.promise;
  2897. }
  2898. async destroy() {
  2899. this.destroyed = true;
  2900. try {
  2901. if (this._worker?.port) {
  2902. this._worker._pendingDestroy = true;
  2903. }
  2904. await this._transport?.destroy();
  2905. } catch (ex) {
  2906. if (this._worker?.port) {
  2907. delete this._worker._pendingDestroy;
  2908. }
  2909. throw ex;
  2910. }
  2911. this._transport = null;
  2912. if (this._worker) {
  2913. this._worker.destroy();
  2914. this._worker = null;
  2915. }
  2916. }
  2917. }
  2918. class PDFDataRangeTransport {
  2919. constructor(length, initialData, progressiveDone = false, contentDispositionFilename = null) {
  2920. this.length = length;
  2921. this.initialData = initialData;
  2922. this.progressiveDone = progressiveDone;
  2923. this.contentDispositionFilename = contentDispositionFilename;
  2924. this._rangeListeners = [];
  2925. this._progressListeners = [];
  2926. this._progressiveReadListeners = [];
  2927. this._progressiveDoneListeners = [];
  2928. this._readyCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  2929. }
  2930. addRangeListener(listener) {
  2931. this._rangeListeners.push(listener);
  2932. }
  2933. addProgressListener(listener) {
  2934. this._progressListeners.push(listener);
  2935. }
  2936. addProgressiveReadListener(listener) {
  2937. this._progressiveReadListeners.push(listener);
  2938. }
  2939. addProgressiveDoneListener(listener) {
  2940. this._progressiveDoneListeners.push(listener);
  2941. }
  2942. onDataRange(begin, chunk) {
  2943. for (const listener of this._rangeListeners) {
  2944. listener(begin, chunk);
  2945. }
  2946. }
  2947. onDataProgress(loaded, total) {
  2948. this._readyCapability.promise.then(() => {
  2949. for (const listener of this._progressListeners) {
  2950. listener(loaded, total);
  2951. }
  2952. });
  2953. }
  2954. onDataProgressiveRead(chunk) {
  2955. this._readyCapability.promise.then(() => {
  2956. for (const listener of this._progressiveReadListeners) {
  2957. listener(chunk);
  2958. }
  2959. });
  2960. }
  2961. onDataProgressiveDone() {
  2962. this._readyCapability.promise.then(() => {
  2963. for (const listener of this._progressiveDoneListeners) {
  2964. listener();
  2965. }
  2966. });
  2967. }
  2968. transportReady() {
  2969. this._readyCapability.resolve();
  2970. }
  2971. requestDataRange(begin, end) {
  2972. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  2973. }
  2974. abort() {}
  2975. }
  2976. class PDFDocumentProxy {
  2977. constructor(pdfInfo, transport) {
  2978. this._pdfInfo = pdfInfo;
  2979. this._transport = transport;
  2980. }
  2981. get annotationStorage() {
  2982. return this._transport.annotationStorage;
  2983. }
  2984. get filterFactory() {
  2985. return this._transport.filterFactory;
  2986. }
  2987. get numPages() {
  2988. return this._pdfInfo.numPages;
  2989. }
  2990. get fingerprints() {
  2991. return this._pdfInfo.fingerprints;
  2992. }
  2993. get isPureXfa() {
  2994. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "isPureXfa", !!this._transport._htmlForXfa);
  2995. }
  2996. get allXfaHtml() {
  2997. return this._transport._htmlForXfa;
  2998. }
  2999. getPage(pageNumber) {
  3000. return this._transport.getPage(pageNumber);
  3001. }
  3002. getPageIndex(ref) {
  3003. return this._transport.getPageIndex(ref);
  3004. }
  3005. getDestinations() {
  3006. return this._transport.getDestinations();
  3007. }
  3008. getDestination(id) {
  3009. return this._transport.getDestination(id);
  3010. }
  3011. getPageLabels() {
  3012. return this._transport.getPageLabels();
  3013. }
  3014. getPageLayout() {
  3015. return this._transport.getPageLayout();
  3016. }
  3017. getPageMode() {
  3018. return this._transport.getPageMode();
  3019. }
  3020. getViewerPreferences() {
  3021. return this._transport.getViewerPreferences();
  3022. }
  3023. getOpenAction() {
  3024. return this._transport.getOpenAction();
  3025. }
  3026. getAttachments() {
  3027. return this._transport.getAttachments();
  3028. }
  3029. getJSActions() {
  3030. return this._transport.getDocJSActions();
  3031. }
  3032. getOutline() {
  3033. return this._transport.getOutline();
  3034. }
  3035. getOptionalContentConfig() {
  3036. return this._transport.getOptionalContentConfig();
  3037. }
  3038. getPermissions() {
  3039. return this._transport.getPermissions();
  3040. }
  3041. getMetadata() {
  3042. return this._transport.getMetadata();
  3043. }
  3044. getMarkInfo() {
  3045. return this._transport.getMarkInfo();
  3046. }
  3047. getData() {
  3048. return this._transport.getData();
  3049. }
  3050. saveDocument() {
  3051. return this._transport.saveDocument();
  3052. }
  3053. getDownloadInfo() {
  3054. return this._transport.downloadInfoCapability.promise;
  3055. }
  3056. cleanup(keepLoadedFonts = false) {
  3057. return this._transport.startCleanup(keepLoadedFonts || this.isPureXfa);
  3058. }
  3059. destroy() {
  3060. return this.loadingTask.destroy();
  3061. }
  3062. get loadingParams() {
  3063. return this._transport.loadingParams;
  3064. }
  3065. get loadingTask() {
  3066. return this._transport.loadingTask;
  3067. }
  3068. getFieldObjects() {
  3069. return this._transport.getFieldObjects();
  3070. }
  3071. hasJSActions() {
  3072. return this._transport.hasJSActions();
  3073. }
  3074. getCalculationOrderIds() {
  3075. return this._transport.getCalculationOrderIds();
  3076. }
  3077. }
  3078. class PDFPageProxy {
  3079. #delayedCleanupTimeout = null;
  3080. #pendingCleanup = false;
  3081. constructor(pageIndex, pageInfo, transport, pdfBug = false) {
  3082. this._pageIndex = pageIndex;
  3083. this._pageInfo = pageInfo;
  3084. this._transport = transport;
  3085. this._stats = pdfBug ? new _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.StatTimer() : null;
  3086. this._pdfBug = pdfBug;
  3087. this.commonObjs = transport.commonObjs;
  3088. this.objs = new PDFObjects();
  3089. this._maybeCleanupAfterRender = false;
  3090. this._intentStates = new Map();
  3091. this.destroyed = false;
  3092. }
  3093. get pageNumber() {
  3094. return this._pageIndex + 1;
  3095. }
  3096. get rotate() {
  3097. return this._pageInfo.rotate;
  3098. }
  3099. get ref() {
  3100. return this._pageInfo.ref;
  3101. }
  3102. get userUnit() {
  3103. return this._pageInfo.userUnit;
  3104. }
  3105. get view() {
  3106. return this._pageInfo.view;
  3107. }
  3108. getViewport({
  3109. scale,
  3110. rotation = this.rotate,
  3111. offsetX = 0,
  3112. offsetY = 0,
  3113. dontFlip = false
  3114. } = {}) {
  3115. return new _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.PageViewport({
  3116. viewBox: this.view,
  3117. scale,
  3118. rotation,
  3119. offsetX,
  3120. offsetY,
  3121. dontFlip
  3122. });
  3123. }
  3124. getAnnotations({
  3125. intent = "display"
  3126. } = {}) {
  3127. const intentArgs = this._transport.getRenderingIntent(intent);
  3128. return this._transport.getAnnotations(this._pageIndex, intentArgs.renderingIntent);
  3129. }
  3130. getJSActions() {
  3131. return this._transport.getPageJSActions(this._pageIndex);
  3132. }
  3133. get filterFactory() {
  3134. return this._transport.filterFactory;
  3135. }
  3136. get isPureXfa() {
  3137. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "isPureXfa", !!this._transport._htmlForXfa);
  3138. }
  3139. async getXfa() {
  3140. return this._transport._htmlForXfa?.children[this._pageIndex] || null;
  3141. }
  3142. render({
  3143. canvasContext,
  3144. viewport,
  3145. intent = "display",
  3146. annotationMode = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE,
  3147. transform = null,
  3148. background = null,
  3149. optionalContentConfigPromise = null,
  3150. annotationCanvasMap = null,
  3151. pageColors = null,
  3152. printAnnotationStorage = null
  3153. }) {
  3154. this._stats?.time("Overall");
  3155. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage);
  3156. this.#pendingCleanup = false;
  3157. this.#abortDelayedCleanup();
  3158. if (!optionalContentConfigPromise) {
  3159. optionalContentConfigPromise = this._transport.getOptionalContentConfig();
  3160. }
  3161. let intentState = this._intentStates.get(intentArgs.cacheKey);
  3162. if (!intentState) {
  3163. intentState = Object.create(null);
  3164. this._intentStates.set(intentArgs.cacheKey, intentState);
  3165. }
  3166. if (intentState.streamReaderCancelTimeout) {
  3167. clearTimeout(intentState.streamReaderCancelTimeout);
  3168. intentState.streamReaderCancelTimeout = null;
  3169. }
  3170. const intentPrint = !!(intentArgs.renderingIntent & _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.PRINT);
  3171. if (!intentState.displayReadyCapability) {
  3172. intentState.displayReadyCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  3173. intentState.operatorList = {
  3174. fnArray: [],
  3175. argsArray: [],
  3176. lastChunk: false,
  3177. separateAnnots: null
  3178. };
  3179. this._stats?.time("Page Request");
  3180. this._pumpOperatorList(intentArgs);
  3181. }
  3182. const complete = error => {
  3183. intentState.renderTasks.delete(internalRenderTask);
  3184. if (this._maybeCleanupAfterRender || intentPrint) {
  3185. this.#pendingCleanup = true;
  3186. }
  3187. this.#tryCleanup(!intentPrint);
  3188. if (error) {
  3189. internalRenderTask.capability.reject(error);
  3190. this._abortOperatorList({
  3191. intentState,
  3192. reason: error instanceof Error ? error : new Error(error)
  3193. });
  3194. } else {
  3195. internalRenderTask.capability.resolve();
  3196. }
  3197. this._stats?.timeEnd("Rendering");
  3198. this._stats?.timeEnd("Overall");
  3199. };
  3200. const internalRenderTask = new InternalRenderTask({
  3201. callback: complete,
  3202. params: {
  3203. canvasContext,
  3204. viewport,
  3205. transform,
  3206. background
  3207. },
  3208. objs: this.objs,
  3209. commonObjs: this.commonObjs,
  3210. annotationCanvasMap,
  3211. operatorList: intentState.operatorList,
  3212. pageIndex: this._pageIndex,
  3213. canvasFactory: this._transport.canvasFactory,
  3214. filterFactory: this._transport.filterFactory,
  3215. useRequestAnimationFrame: !intentPrint,
  3216. pdfBug: this._pdfBug,
  3217. pageColors
  3218. });
  3219. (intentState.renderTasks ||= new Set()).add(internalRenderTask);
  3220. const renderTask = internalRenderTask.task;
  3221. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
  3222. if (this.destroyed) {
  3223. complete();
  3224. return;
  3225. }
  3226. this._stats?.time("Rendering");
  3227. internalRenderTask.initializeGraphics({
  3228. transparency,
  3229. optionalContentConfig
  3230. });
  3231. internalRenderTask.operatorListChanged();
  3232. }).catch(complete);
  3233. return renderTask;
  3234. }
  3235. getOperatorList({
  3236. intent = "display",
  3237. annotationMode = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE,
  3238. printAnnotationStorage = null
  3239. } = {}) {
  3240. function operatorListChanged() {
  3241. if (intentState.operatorList.lastChunk) {
  3242. intentState.opListReadCapability.resolve(intentState.operatorList);
  3243. intentState.renderTasks.delete(opListTask);
  3244. }
  3245. }
  3246. const intentArgs = this._transport.getRenderingIntent(intent, annotationMode, printAnnotationStorage, true);
  3247. let intentState = this._intentStates.get(intentArgs.cacheKey);
  3248. if (!intentState) {
  3249. intentState = Object.create(null);
  3250. this._intentStates.set(intentArgs.cacheKey, intentState);
  3251. }
  3252. let opListTask;
  3253. if (!intentState.opListReadCapability) {
  3254. opListTask = Object.create(null);
  3255. opListTask.operatorListChanged = operatorListChanged;
  3256. intentState.opListReadCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  3257. (intentState.renderTasks ||= new Set()).add(opListTask);
  3258. intentState.operatorList = {
  3259. fnArray: [],
  3260. argsArray: [],
  3261. lastChunk: false,
  3262. separateAnnots: null
  3263. };
  3264. this._stats?.time("Page Request");
  3265. this._pumpOperatorList(intentArgs);
  3266. }
  3267. return intentState.opListReadCapability.promise;
  3268. }
  3269. streamTextContent({
  3270. includeMarkedContent = false,
  3271. disableNormalization = false
  3272. } = {}) {
  3273. const TEXT_CONTENT_CHUNK_SIZE = 100;
  3274. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  3275. pageIndex: this._pageIndex,
  3276. includeMarkedContent: includeMarkedContent === true,
  3277. disableNormalization: disableNormalization === true
  3278. }, {
  3279. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  3280. size(textContent) {
  3281. return textContent.items.length;
  3282. }
  3283. });
  3284. }
  3285. getTextContent(params = {}) {
  3286. if (this._transport._htmlForXfa) {
  3287. return this.getXfa().then(xfa => {
  3288. return _xfa_text_js__WEBPACK_IMPORTED_MODULE_14__.XfaText.textContent(xfa);
  3289. });
  3290. }
  3291. const readableStream = this.streamTextContent(params);
  3292. return new Promise(function (resolve, reject) {
  3293. function pump() {
  3294. reader.read().then(function ({
  3295. value,
  3296. done
  3297. }) {
  3298. if (done) {
  3299. resolve(textContent);
  3300. return;
  3301. }
  3302. Object.assign(textContent.styles, value.styles);
  3303. textContent.items.push(...value.items);
  3304. pump();
  3305. }, reject);
  3306. }
  3307. const reader = readableStream.getReader();
  3308. const textContent = {
  3309. items: [],
  3310. styles: Object.create(null)
  3311. };
  3312. pump();
  3313. });
  3314. }
  3315. getStructTree() {
  3316. return this._transport.getStructTree(this._pageIndex);
  3317. }
  3318. _destroy() {
  3319. this.destroyed = true;
  3320. const waitOn = [];
  3321. for (const intentState of this._intentStates.values()) {
  3322. this._abortOperatorList({
  3323. intentState,
  3324. reason: new Error("Page was destroyed."),
  3325. force: true
  3326. });
  3327. if (intentState.opListReadCapability) {
  3328. continue;
  3329. }
  3330. for (const internalRenderTask of intentState.renderTasks) {
  3331. waitOn.push(internalRenderTask.completed);
  3332. internalRenderTask.cancel();
  3333. }
  3334. }
  3335. this.objs.clear();
  3336. this.#pendingCleanup = false;
  3337. this.#abortDelayedCleanup();
  3338. return Promise.all(waitOn);
  3339. }
  3340. cleanup(resetStats = false) {
  3341. this.#pendingCleanup = true;
  3342. const success = this.#tryCleanup(false);
  3343. if (resetStats && success) {
  3344. this._stats &&= new _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.StatTimer();
  3345. }
  3346. return success;
  3347. }
  3348. #tryCleanup(delayed = false) {
  3349. this.#abortDelayedCleanup();
  3350. if (!this.#pendingCleanup || this.destroyed) {
  3351. return false;
  3352. }
  3353. if (delayed) {
  3354. this.#delayedCleanupTimeout = setTimeout(() => {
  3355. this.#delayedCleanupTimeout = null;
  3356. this.#tryCleanup(false);
  3357. }, DELAYED_CLEANUP_TIMEOUT);
  3358. return false;
  3359. }
  3360. for (const {
  3361. renderTasks,
  3362. operatorList
  3363. } of this._intentStates.values()) {
  3364. if (renderTasks.size > 0 || !operatorList.lastChunk) {
  3365. return false;
  3366. }
  3367. }
  3368. this._intentStates.clear();
  3369. this.objs.clear();
  3370. this.#pendingCleanup = false;
  3371. return true;
  3372. }
  3373. #abortDelayedCleanup() {
  3374. if (this.#delayedCleanupTimeout) {
  3375. clearTimeout(this.#delayedCleanupTimeout);
  3376. this.#delayedCleanupTimeout = null;
  3377. }
  3378. }
  3379. _startRenderPage(transparency, cacheKey) {
  3380. const intentState = this._intentStates.get(cacheKey);
  3381. if (!intentState) {
  3382. return;
  3383. }
  3384. this._stats?.timeEnd("Page Request");
  3385. intentState.displayReadyCapability?.resolve(transparency);
  3386. }
  3387. _renderPageChunk(operatorListChunk, intentState) {
  3388. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  3389. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  3390. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  3391. }
  3392. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  3393. intentState.operatorList.separateAnnots = operatorListChunk.separateAnnots;
  3394. for (const internalRenderTask of intentState.renderTasks) {
  3395. internalRenderTask.operatorListChanged();
  3396. }
  3397. if (operatorListChunk.lastChunk) {
  3398. this.#tryCleanup(true);
  3399. }
  3400. }
  3401. _pumpOperatorList({
  3402. renderingIntent,
  3403. cacheKey,
  3404. annotationStorageSerializable
  3405. }) {
  3406. const {
  3407. map,
  3408. transfer
  3409. } = annotationStorageSerializable;
  3410. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", {
  3411. pageIndex: this._pageIndex,
  3412. intent: renderingIntent,
  3413. cacheKey,
  3414. annotationStorage: map
  3415. }, transfer);
  3416. const reader = readableStream.getReader();
  3417. const intentState = this._intentStates.get(cacheKey);
  3418. intentState.streamReader = reader;
  3419. const pump = () => {
  3420. reader.read().then(({
  3421. value,
  3422. done
  3423. }) => {
  3424. if (done) {
  3425. intentState.streamReader = null;
  3426. return;
  3427. }
  3428. if (this._transport.destroyed) {
  3429. return;
  3430. }
  3431. this._renderPageChunk(value, intentState);
  3432. pump();
  3433. }, reason => {
  3434. intentState.streamReader = null;
  3435. if (this._transport.destroyed) {
  3436. return;
  3437. }
  3438. if (intentState.operatorList) {
  3439. intentState.operatorList.lastChunk = true;
  3440. for (const internalRenderTask of intentState.renderTasks) {
  3441. internalRenderTask.operatorListChanged();
  3442. }
  3443. this.#tryCleanup(true);
  3444. }
  3445. if (intentState.displayReadyCapability) {
  3446. intentState.displayReadyCapability.reject(reason);
  3447. } else if (intentState.opListReadCapability) {
  3448. intentState.opListReadCapability.reject(reason);
  3449. } else {
  3450. throw reason;
  3451. }
  3452. });
  3453. };
  3454. pump();
  3455. }
  3456. _abortOperatorList({
  3457. intentState,
  3458. reason,
  3459. force = false
  3460. }) {
  3461. if (!intentState.streamReader) {
  3462. return;
  3463. }
  3464. if (intentState.streamReaderCancelTimeout) {
  3465. clearTimeout(intentState.streamReaderCancelTimeout);
  3466. intentState.streamReaderCancelTimeout = null;
  3467. }
  3468. if (!force) {
  3469. if (intentState.renderTasks.size > 0) {
  3470. return;
  3471. }
  3472. if (reason instanceof _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.RenderingCancelledException) {
  3473. let delay = RENDERING_CANCELLED_TIMEOUT;
  3474. if (reason.extraDelay > 0 && reason.extraDelay < 1000) {
  3475. delay += reason.extraDelay;
  3476. }
  3477. intentState.streamReaderCancelTimeout = setTimeout(() => {
  3478. intentState.streamReaderCancelTimeout = null;
  3479. this._abortOperatorList({
  3480. intentState,
  3481. reason,
  3482. force: true
  3483. });
  3484. }, delay);
  3485. return;
  3486. }
  3487. }
  3488. intentState.streamReader.cancel(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException(reason.message)).catch(() => {});
  3489. intentState.streamReader = null;
  3490. if (this._transport.destroyed) {
  3491. return;
  3492. }
  3493. for (const [curCacheKey, curIntentState] of this._intentStates) {
  3494. if (curIntentState === intentState) {
  3495. this._intentStates.delete(curCacheKey);
  3496. break;
  3497. }
  3498. }
  3499. this.cleanup();
  3500. }
  3501. get stats() {
  3502. return this._stats;
  3503. }
  3504. }
  3505. class LoopbackPort {
  3506. #listeners = new Set();
  3507. #deferred = Promise.resolve();
  3508. postMessage(obj, transfer) {
  3509. const event = {
  3510. data: structuredClone(obj, transfer ? {
  3511. transfer
  3512. } : null)
  3513. };
  3514. this.#deferred.then(() => {
  3515. for (const listener of this.#listeners) {
  3516. listener.call(this, event);
  3517. }
  3518. });
  3519. }
  3520. addEventListener(name, listener) {
  3521. this.#listeners.add(listener);
  3522. }
  3523. removeEventListener(name, listener) {
  3524. this.#listeners.delete(listener);
  3525. }
  3526. terminate() {
  3527. this.#listeners.clear();
  3528. }
  3529. }
  3530. const PDFWorkerUtil = {
  3531. isWorkerDisabled: false,
  3532. fakeWorkerId: 0
  3533. };
  3534. {
  3535. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS) {
  3536. PDFWorkerUtil.isWorkerDisabled = true;
  3537. _worker_options_js__WEBPACK_IMPORTED_MODULE_6__.GlobalWorkerOptions.workerSrc ||= "./pdf.worker.mjs";
  3538. }
  3539. PDFWorkerUtil.isSameOrigin = function (baseUrl, otherUrl) {
  3540. let base;
  3541. try {
  3542. base = new URL(baseUrl);
  3543. if (!base.origin || base.origin === "null") {
  3544. return false;
  3545. }
  3546. } catch {
  3547. return false;
  3548. }
  3549. const other = new URL(otherUrl, base);
  3550. return base.origin === other.origin;
  3551. };
  3552. PDFWorkerUtil.createCDNWrapper = function (url) {
  3553. const wrapper = `await import("${url}");`;
  3554. return URL.createObjectURL(new Blob([wrapper], {
  3555. type: "text/javascript"
  3556. }));
  3557. };
  3558. }
  3559. class PDFWorker {
  3560. static #workerPorts;
  3561. constructor({
  3562. name = null,
  3563. port = null,
  3564. verbosity = (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.getVerbosityLevel)()
  3565. } = {}) {
  3566. this.name = name;
  3567. this.destroyed = false;
  3568. this.verbosity = verbosity;
  3569. this._readyCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  3570. this._port = null;
  3571. this._webWorker = null;
  3572. this._messageHandler = null;
  3573. if (port) {
  3574. if (PDFWorker.#workerPorts?.has(port)) {
  3575. throw new Error("Cannot use more than one PDFWorker per port.");
  3576. }
  3577. (PDFWorker.#workerPorts ||= new WeakMap()).set(port, this);
  3578. this._initializeFromPort(port);
  3579. return;
  3580. }
  3581. this._initialize();
  3582. }
  3583. get promise() {
  3584. return this._readyCapability.promise;
  3585. }
  3586. get port() {
  3587. return this._port;
  3588. }
  3589. get messageHandler() {
  3590. return this._messageHandler;
  3591. }
  3592. _initializeFromPort(port) {
  3593. this._port = port;
  3594. this._messageHandler = new _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__.MessageHandler("main", "worker", port);
  3595. this._messageHandler.on("ready", function () {});
  3596. this._readyCapability.resolve();
  3597. this._messageHandler.send("configure", {
  3598. verbosity: this.verbosity
  3599. });
  3600. }
  3601. _initialize() {
  3602. if (!PDFWorkerUtil.isWorkerDisabled && !PDFWorker.#mainThreadWorkerMessageHandler) {
  3603. let {
  3604. workerSrc
  3605. } = PDFWorker;
  3606. try {
  3607. if (!PDFWorkerUtil.isSameOrigin(window.location.href, workerSrc)) {
  3608. workerSrc = PDFWorkerUtil.createCDNWrapper(new URL(workerSrc, window.location).href);
  3609. }
  3610. const worker = new Worker(workerSrc, {
  3611. type: "module"
  3612. });
  3613. const messageHandler = new _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__.MessageHandler("main", "worker", worker);
  3614. const terminateEarly = () => {
  3615. worker.removeEventListener("error", onWorkerError);
  3616. messageHandler.destroy();
  3617. worker.terminate();
  3618. if (this.destroyed) {
  3619. this._readyCapability.reject(new Error("Worker was destroyed"));
  3620. } else {
  3621. this._setupFakeWorker();
  3622. }
  3623. };
  3624. const onWorkerError = () => {
  3625. if (!this._webWorker) {
  3626. terminateEarly();
  3627. }
  3628. };
  3629. worker.addEventListener("error", onWorkerError);
  3630. messageHandler.on("test", data => {
  3631. worker.removeEventListener("error", onWorkerError);
  3632. if (this.destroyed) {
  3633. terminateEarly();
  3634. return;
  3635. }
  3636. if (data) {
  3637. this._messageHandler = messageHandler;
  3638. this._port = worker;
  3639. this._webWorker = worker;
  3640. this._readyCapability.resolve();
  3641. messageHandler.send("configure", {
  3642. verbosity: this.verbosity
  3643. });
  3644. } else {
  3645. this._setupFakeWorker();
  3646. messageHandler.destroy();
  3647. worker.terminate();
  3648. }
  3649. });
  3650. messageHandler.on("ready", data => {
  3651. worker.removeEventListener("error", onWorkerError);
  3652. if (this.destroyed) {
  3653. terminateEarly();
  3654. return;
  3655. }
  3656. try {
  3657. sendTest();
  3658. } catch {
  3659. this._setupFakeWorker();
  3660. }
  3661. });
  3662. const sendTest = () => {
  3663. const testObj = new Uint8Array();
  3664. messageHandler.send("test", testObj, [testObj.buffer]);
  3665. };
  3666. sendTest();
  3667. return;
  3668. } catch {
  3669. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.info)("The worker has been disabled.");
  3670. }
  3671. }
  3672. this._setupFakeWorker();
  3673. }
  3674. _setupFakeWorker() {
  3675. if (!PDFWorkerUtil.isWorkerDisabled) {
  3676. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)("Setting up fake worker.");
  3677. PDFWorkerUtil.isWorkerDisabled = true;
  3678. }
  3679. PDFWorker._setupFakeWorkerGlobal.then(WorkerMessageHandler => {
  3680. if (this.destroyed) {
  3681. this._readyCapability.reject(new Error("Worker was destroyed"));
  3682. return;
  3683. }
  3684. const port = new LoopbackPort();
  3685. this._port = port;
  3686. const id = `fake${PDFWorkerUtil.fakeWorkerId++}`;
  3687. const workerHandler = new _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__.MessageHandler(id + "_worker", id, port);
  3688. WorkerMessageHandler.setup(workerHandler, port);
  3689. const messageHandler = new _shared_message_handler_js__WEBPACK_IMPORTED_MODULE_7__.MessageHandler(id, id + "_worker", port);
  3690. this._messageHandler = messageHandler;
  3691. this._readyCapability.resolve();
  3692. messageHandler.send("configure", {
  3693. verbosity: this.verbosity
  3694. });
  3695. }).catch(reason => {
  3696. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  3697. });
  3698. }
  3699. destroy() {
  3700. this.destroyed = true;
  3701. if (this._webWorker) {
  3702. this._webWorker.terminate();
  3703. this._webWorker = null;
  3704. }
  3705. PDFWorker.#workerPorts?.delete(this._port);
  3706. this._port = null;
  3707. if (this._messageHandler) {
  3708. this._messageHandler.destroy();
  3709. this._messageHandler = null;
  3710. }
  3711. }
  3712. static fromPort(params) {
  3713. if (!params?.port) {
  3714. throw new Error("PDFWorker.fromPort - invalid method signature.");
  3715. }
  3716. const cachedPort = this.#workerPorts?.get(params.port);
  3717. if (cachedPort) {
  3718. if (cachedPort._pendingDestroy) {
  3719. throw new Error("PDFWorker.fromPort - the worker is being destroyed.\n" + "Please remember to await `PDFDocumentLoadingTask.destroy()`-calls.");
  3720. }
  3721. return cachedPort;
  3722. }
  3723. return new PDFWorker(params);
  3724. }
  3725. static get workerSrc() {
  3726. if (_worker_options_js__WEBPACK_IMPORTED_MODULE_6__.GlobalWorkerOptions.workerSrc) {
  3727. return _worker_options_js__WEBPACK_IMPORTED_MODULE_6__.GlobalWorkerOptions.workerSrc;
  3728. }
  3729. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  3730. }
  3731. static get #mainThreadWorkerMessageHandler() {
  3732. try {
  3733. return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
  3734. } catch {
  3735. return null;
  3736. }
  3737. }
  3738. static get _setupFakeWorkerGlobal() {
  3739. const loader = async () => {
  3740. if (this.#mainThreadWorkerMessageHandler) {
  3741. return this.#mainThreadWorkerMessageHandler;
  3742. }
  3743. const worker = await import(/* webpackIgnore: true */ this.workerSrc);
  3744. return worker.WorkerMessageHandler;
  3745. };
  3746. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "_setupFakeWorkerGlobal", loader());
  3747. }
  3748. }
  3749. class WorkerTransport {
  3750. #methodPromises = new Map();
  3751. #pageCache = new Map();
  3752. #pagePromises = new Map();
  3753. #passwordCapability = null;
  3754. constructor(messageHandler, loadingTask, networkStream, params, factory) {
  3755. this.messageHandler = messageHandler;
  3756. this.loadingTask = loadingTask;
  3757. this.commonObjs = new PDFObjects();
  3758. this.fontLoader = new _font_loader_js__WEBPACK_IMPORTED_MODULE_3__.FontLoader({
  3759. ownerDocument: params.ownerDocument,
  3760. styleElement: params.styleElement
  3761. });
  3762. this._params = params;
  3763. this.canvasFactory = factory.canvasFactory;
  3764. this.filterFactory = factory.filterFactory;
  3765. this.cMapReaderFactory = factory.cMapReaderFactory;
  3766. this.standardFontDataFactory = factory.standardFontDataFactory;
  3767. this.destroyed = false;
  3768. this.destroyCapability = null;
  3769. this._networkStream = networkStream;
  3770. this._fullReader = null;
  3771. this._lastProgress = null;
  3772. this.downloadInfoCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  3773. this.setupMessageHandler();
  3774. }
  3775. #cacheSimpleMethod(name, data = null) {
  3776. const cachedPromise = this.#methodPromises.get(name);
  3777. if (cachedPromise) {
  3778. return cachedPromise;
  3779. }
  3780. const promise = this.messageHandler.sendWithPromise(name, data);
  3781. this.#methodPromises.set(name, promise);
  3782. return promise;
  3783. }
  3784. get annotationStorage() {
  3785. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "annotationStorage", new _annotation_storage_js__WEBPACK_IMPORTED_MODULE_1__.AnnotationStorage());
  3786. }
  3787. getRenderingIntent(intent, annotationMode = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE, printAnnotationStorage = null, isOpList = false) {
  3788. let renderingIntent = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.DISPLAY;
  3789. let annotationStorageSerializable = _annotation_storage_js__WEBPACK_IMPORTED_MODULE_1__.SerializableEmpty;
  3790. switch (intent) {
  3791. case "any":
  3792. renderingIntent = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.ANY;
  3793. break;
  3794. case "display":
  3795. break;
  3796. case "print":
  3797. renderingIntent = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.PRINT;
  3798. break;
  3799. default:
  3800. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`getRenderingIntent - invalid intent: ${intent}`);
  3801. }
  3802. switch (annotationMode) {
  3803. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.DISABLE:
  3804. renderingIntent += _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.ANNOTATIONS_DISABLE;
  3805. break;
  3806. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE:
  3807. break;
  3808. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE_FORMS:
  3809. renderingIntent += _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.ANNOTATIONS_FORMS;
  3810. break;
  3811. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode.ENABLE_STORAGE:
  3812. renderingIntent += _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.ANNOTATIONS_STORAGE;
  3813. const annotationStorage = renderingIntent & _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.PRINT && printAnnotationStorage instanceof _annotation_storage_js__WEBPACK_IMPORTED_MODULE_1__.PrintAnnotationStorage ? printAnnotationStorage : this.annotationStorage;
  3814. annotationStorageSerializable = annotationStorage.serializable;
  3815. break;
  3816. default:
  3817. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`getRenderingIntent - invalid annotationMode: ${annotationMode}`);
  3818. }
  3819. if (isOpList) {
  3820. renderingIntent += _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.RenderingIntentFlag.OPLIST;
  3821. }
  3822. return {
  3823. renderingIntent,
  3824. cacheKey: `${renderingIntent}_${annotationStorageSerializable.hash}`,
  3825. annotationStorageSerializable
  3826. };
  3827. }
  3828. destroy() {
  3829. if (this.destroyCapability) {
  3830. return this.destroyCapability.promise;
  3831. }
  3832. this.destroyed = true;
  3833. this.destroyCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  3834. this.#passwordCapability?.reject(new Error("Worker was destroyed during onPassword callback"));
  3835. const waitOn = [];
  3836. for (const page of this.#pageCache.values()) {
  3837. waitOn.push(page._destroy());
  3838. }
  3839. this.#pageCache.clear();
  3840. this.#pagePromises.clear();
  3841. if (this.hasOwnProperty("annotationStorage")) {
  3842. this.annotationStorage.resetModified();
  3843. }
  3844. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  3845. waitOn.push(terminated);
  3846. Promise.all(waitOn).then(() => {
  3847. this.commonObjs.clear();
  3848. this.fontLoader.clear();
  3849. this.#methodPromises.clear();
  3850. this.filterFactory.destroy();
  3851. this._networkStream?.cancelAllRequests(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException("Worker was terminated."));
  3852. if (this.messageHandler) {
  3853. this.messageHandler.destroy();
  3854. this.messageHandler = null;
  3855. }
  3856. this.destroyCapability.resolve();
  3857. }, this.destroyCapability.reject);
  3858. return this.destroyCapability.promise;
  3859. }
  3860. setupMessageHandler() {
  3861. const {
  3862. messageHandler,
  3863. loadingTask
  3864. } = this;
  3865. messageHandler.on("GetReader", (data, sink) => {
  3866. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
  3867. this._fullReader = this._networkStream.getFullReader();
  3868. this._fullReader.onProgress = evt => {
  3869. this._lastProgress = {
  3870. loaded: evt.loaded,
  3871. total: evt.total
  3872. };
  3873. };
  3874. sink.onPull = () => {
  3875. this._fullReader.read().then(function ({
  3876. value,
  3877. done
  3878. }) {
  3879. if (done) {
  3880. sink.close();
  3881. return;
  3882. }
  3883. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(value instanceof ArrayBuffer, "GetReader - expected an ArrayBuffer.");
  3884. sink.enqueue(new Uint8Array(value), 1, [value]);
  3885. }).catch(reason => {
  3886. sink.error(reason);
  3887. });
  3888. };
  3889. sink.onCancel = reason => {
  3890. this._fullReader.cancel(reason);
  3891. sink.ready.catch(readyReason => {
  3892. if (this.destroyed) {
  3893. return;
  3894. }
  3895. throw readyReason;
  3896. });
  3897. };
  3898. });
  3899. messageHandler.on("ReaderHeadersReady", data => {
  3900. const headersCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  3901. const fullReader = this._fullReader;
  3902. fullReader.headersReady.then(() => {
  3903. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  3904. if (this._lastProgress) {
  3905. loadingTask.onProgress?.(this._lastProgress);
  3906. }
  3907. fullReader.onProgress = evt => {
  3908. loadingTask.onProgress?.({
  3909. loaded: evt.loaded,
  3910. total: evt.total
  3911. });
  3912. };
  3913. }
  3914. headersCapability.resolve({
  3915. isStreamingSupported: fullReader.isStreamingSupported,
  3916. isRangeSupported: fullReader.isRangeSupported,
  3917. contentLength: fullReader.contentLength
  3918. });
  3919. }, headersCapability.reject);
  3920. return headersCapability.promise;
  3921. });
  3922. messageHandler.on("GetRangeReader", (data, sink) => {
  3923. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  3924. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  3925. if (!rangeReader) {
  3926. sink.close();
  3927. return;
  3928. }
  3929. sink.onPull = () => {
  3930. rangeReader.read().then(function ({
  3931. value,
  3932. done
  3933. }) {
  3934. if (done) {
  3935. sink.close();
  3936. return;
  3937. }
  3938. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(value instanceof ArrayBuffer, "GetRangeReader - expected an ArrayBuffer.");
  3939. sink.enqueue(new Uint8Array(value), 1, [value]);
  3940. }).catch(reason => {
  3941. sink.error(reason);
  3942. });
  3943. };
  3944. sink.onCancel = reason => {
  3945. rangeReader.cancel(reason);
  3946. sink.ready.catch(readyReason => {
  3947. if (this.destroyed) {
  3948. return;
  3949. }
  3950. throw readyReason;
  3951. });
  3952. };
  3953. });
  3954. messageHandler.on("GetDoc", ({
  3955. pdfInfo
  3956. }) => {
  3957. this._numPages = pdfInfo.numPages;
  3958. this._htmlForXfa = pdfInfo.htmlForXfa;
  3959. delete pdfInfo.htmlForXfa;
  3960. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  3961. });
  3962. messageHandler.on("DocException", function (ex) {
  3963. let reason;
  3964. switch (ex.name) {
  3965. case "PasswordException":
  3966. reason = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PasswordException(ex.message, ex.code);
  3967. break;
  3968. case "InvalidPDFException":
  3969. reason = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.InvalidPDFException(ex.message);
  3970. break;
  3971. case "MissingPDFException":
  3972. reason = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException(ex.message);
  3973. break;
  3974. case "UnexpectedResponseException":
  3975. reason = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.UnexpectedResponseException(ex.message, ex.status);
  3976. break;
  3977. case "UnknownErrorException":
  3978. reason = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.UnknownErrorException(ex.message, ex.details);
  3979. break;
  3980. default:
  3981. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("DocException - expected a valid Error.");
  3982. }
  3983. loadingTask._capability.reject(reason);
  3984. });
  3985. messageHandler.on("PasswordRequest", exception => {
  3986. this.#passwordCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  3987. if (loadingTask.onPassword) {
  3988. const updatePassword = password => {
  3989. if (password instanceof Error) {
  3990. this.#passwordCapability.reject(password);
  3991. } else {
  3992. this.#passwordCapability.resolve({
  3993. password
  3994. });
  3995. }
  3996. };
  3997. try {
  3998. loadingTask.onPassword(updatePassword, exception.code);
  3999. } catch (ex) {
  4000. this.#passwordCapability.reject(ex);
  4001. }
  4002. } else {
  4003. this.#passwordCapability.reject(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PasswordException(exception.message, exception.code));
  4004. }
  4005. return this.#passwordCapability.promise;
  4006. });
  4007. messageHandler.on("DataLoaded", data => {
  4008. loadingTask.onProgress?.({
  4009. loaded: data.length,
  4010. total: data.length
  4011. });
  4012. this.downloadInfoCapability.resolve(data);
  4013. });
  4014. messageHandler.on("StartRenderPage", data => {
  4015. if (this.destroyed) {
  4016. return;
  4017. }
  4018. const page = this.#pageCache.get(data.pageIndex);
  4019. page._startRenderPage(data.transparency, data.cacheKey);
  4020. });
  4021. messageHandler.on("commonobj", ([id, type, exportedData]) => {
  4022. if (this.destroyed) {
  4023. return null;
  4024. }
  4025. if (this.commonObjs.has(id)) {
  4026. return null;
  4027. }
  4028. switch (type) {
  4029. case "Font":
  4030. const params = this._params;
  4031. if ("error" in exportedData) {
  4032. const exportedError = exportedData.error;
  4033. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Error during font loading: ${exportedError}`);
  4034. this.commonObjs.resolve(id, exportedError);
  4035. break;
  4036. }
  4037. const inspectFont = params.pdfBug && globalThis.FontInspector?.enabled ? (font, url) => globalThis.FontInspector.fontAdded(font, url) : null;
  4038. const font = new _font_loader_js__WEBPACK_IMPORTED_MODULE_3__.FontFaceObject(exportedData, {
  4039. isEvalSupported: params.isEvalSupported,
  4040. disableFontFace: params.disableFontFace,
  4041. ignoreErrors: params.ignoreErrors,
  4042. inspectFont
  4043. });
  4044. this.fontLoader.bind(font).catch(reason => {
  4045. return messageHandler.sendWithPromise("FontFallback", {
  4046. id
  4047. });
  4048. }).finally(() => {
  4049. if (!params.fontExtraProperties && font.data) {
  4050. font.data = null;
  4051. }
  4052. this.commonObjs.resolve(id, font);
  4053. });
  4054. break;
  4055. case "CopyLocalImage":
  4056. const {
  4057. imageRef
  4058. } = exportedData;
  4059. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(imageRef, "The imageRef must be defined.");
  4060. for (const pageProxy of this.#pageCache.values()) {
  4061. for (const [, data] of pageProxy.objs) {
  4062. if (data.ref !== imageRef) {
  4063. continue;
  4064. }
  4065. if (!data.dataLen) {
  4066. return null;
  4067. }
  4068. this.commonObjs.resolve(id, structuredClone(data));
  4069. return data.dataLen;
  4070. }
  4071. }
  4072. break;
  4073. case "FontPath":
  4074. case "Image":
  4075. case "Pattern":
  4076. this.commonObjs.resolve(id, exportedData);
  4077. break;
  4078. default:
  4079. throw new Error(`Got unknown common object type ${type}`);
  4080. }
  4081. return null;
  4082. });
  4083. messageHandler.on("obj", ([id, pageIndex, type, imageData]) => {
  4084. if (this.destroyed) {
  4085. return;
  4086. }
  4087. const pageProxy = this.#pageCache.get(pageIndex);
  4088. if (pageProxy.objs.has(id)) {
  4089. return;
  4090. }
  4091. if (pageProxy._intentStates.size === 0) {
  4092. imageData?.bitmap?.close();
  4093. return;
  4094. }
  4095. switch (type) {
  4096. case "Image":
  4097. pageProxy.objs.resolve(id, imageData);
  4098. if (imageData?.dataLen > _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MAX_IMAGE_SIZE_TO_CACHE) {
  4099. pageProxy._maybeCleanupAfterRender = true;
  4100. }
  4101. break;
  4102. case "Pattern":
  4103. pageProxy.objs.resolve(id, imageData);
  4104. break;
  4105. default:
  4106. throw new Error(`Got unknown object type ${type}`);
  4107. }
  4108. });
  4109. messageHandler.on("DocProgress", data => {
  4110. if (this.destroyed) {
  4111. return;
  4112. }
  4113. loadingTask.onProgress?.({
  4114. loaded: data.loaded,
  4115. total: data.total
  4116. });
  4117. });
  4118. messageHandler.on("FetchBuiltInCMap", data => {
  4119. if (this.destroyed) {
  4120. return Promise.reject(new Error("Worker was destroyed."));
  4121. }
  4122. if (!this.cMapReaderFactory) {
  4123. return Promise.reject(new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter."));
  4124. }
  4125. return this.cMapReaderFactory.fetch(data);
  4126. });
  4127. messageHandler.on("FetchStandardFontData", data => {
  4128. if (this.destroyed) {
  4129. return Promise.reject(new Error("Worker was destroyed."));
  4130. }
  4131. if (!this.standardFontDataFactory) {
  4132. return Promise.reject(new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter."));
  4133. }
  4134. return this.standardFontDataFactory.fetch(data);
  4135. });
  4136. }
  4137. getData() {
  4138. return this.messageHandler.sendWithPromise("GetData", null);
  4139. }
  4140. saveDocument() {
  4141. if (this.annotationStorage.size <= 0) {
  4142. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)("saveDocument called while `annotationStorage` is empty, " + "please use the getData-method instead.");
  4143. }
  4144. const {
  4145. map,
  4146. transfer
  4147. } = this.annotationStorage.serializable;
  4148. return this.messageHandler.sendWithPromise("SaveDocument", {
  4149. isPureXfa: !!this._htmlForXfa,
  4150. numPages: this._numPages,
  4151. annotationStorage: map,
  4152. filename: this._fullReader?.filename ?? null
  4153. }, transfer).finally(() => {
  4154. this.annotationStorage.resetModified();
  4155. });
  4156. }
  4157. getPage(pageNumber) {
  4158. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  4159. return Promise.reject(new Error("Invalid page request."));
  4160. }
  4161. const pageIndex = pageNumber - 1,
  4162. cachedPromise = this.#pagePromises.get(pageIndex);
  4163. if (cachedPromise) {
  4164. return cachedPromise;
  4165. }
  4166. const promise = this.messageHandler.sendWithPromise("GetPage", {
  4167. pageIndex
  4168. }).then(pageInfo => {
  4169. if (this.destroyed) {
  4170. throw new Error("Transport destroyed");
  4171. }
  4172. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.pdfBug);
  4173. this.#pageCache.set(pageIndex, page);
  4174. return page;
  4175. });
  4176. this.#pagePromises.set(pageIndex, promise);
  4177. return promise;
  4178. }
  4179. getPageIndex(ref) {
  4180. if (typeof ref !== "object" || ref === null || !Number.isInteger(ref.num) || ref.num < 0 || !Number.isInteger(ref.gen) || ref.gen < 0) {
  4181. return Promise.reject(new Error("Invalid pageIndex request."));
  4182. }
  4183. return this.messageHandler.sendWithPromise("GetPageIndex", {
  4184. num: ref.num,
  4185. gen: ref.gen
  4186. });
  4187. }
  4188. getAnnotations(pageIndex, intent) {
  4189. return this.messageHandler.sendWithPromise("GetAnnotations", {
  4190. pageIndex,
  4191. intent
  4192. });
  4193. }
  4194. getFieldObjects() {
  4195. return this.#cacheSimpleMethod("GetFieldObjects");
  4196. }
  4197. hasJSActions() {
  4198. return this.#cacheSimpleMethod("HasJSActions");
  4199. }
  4200. getCalculationOrderIds() {
  4201. return this.messageHandler.sendWithPromise("GetCalculationOrderIds", null);
  4202. }
  4203. getDestinations() {
  4204. return this.messageHandler.sendWithPromise("GetDestinations", null);
  4205. }
  4206. getDestination(id) {
  4207. if (typeof id !== "string") {
  4208. return Promise.reject(new Error("Invalid destination request."));
  4209. }
  4210. return this.messageHandler.sendWithPromise("GetDestination", {
  4211. id
  4212. });
  4213. }
  4214. getPageLabels() {
  4215. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  4216. }
  4217. getPageLayout() {
  4218. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  4219. }
  4220. getPageMode() {
  4221. return this.messageHandler.sendWithPromise("GetPageMode", null);
  4222. }
  4223. getViewerPreferences() {
  4224. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  4225. }
  4226. getOpenAction() {
  4227. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  4228. }
  4229. getAttachments() {
  4230. return this.messageHandler.sendWithPromise("GetAttachments", null);
  4231. }
  4232. getDocJSActions() {
  4233. return this.#cacheSimpleMethod("GetDocJSActions");
  4234. }
  4235. getPageJSActions(pageIndex) {
  4236. return this.messageHandler.sendWithPromise("GetPageJSActions", {
  4237. pageIndex
  4238. });
  4239. }
  4240. getStructTree(pageIndex) {
  4241. return this.messageHandler.sendWithPromise("GetStructTree", {
  4242. pageIndex
  4243. });
  4244. }
  4245. getOutline() {
  4246. return this.messageHandler.sendWithPromise("GetOutline", null);
  4247. }
  4248. getOptionalContentConfig() {
  4249. return this.messageHandler.sendWithPromise("GetOptionalContentConfig", null).then(results => {
  4250. return new _optional_content_config_js__WEBPACK_IMPORTED_MODULE_9__.OptionalContentConfig(results);
  4251. });
  4252. }
  4253. getPermissions() {
  4254. return this.messageHandler.sendWithPromise("GetPermissions", null);
  4255. }
  4256. getMetadata() {
  4257. const name = "GetMetadata",
  4258. cachedPromise = this.#methodPromises.get(name);
  4259. if (cachedPromise) {
  4260. return cachedPromise;
  4261. }
  4262. const promise = this.messageHandler.sendWithPromise(name, null).then(results => {
  4263. return {
  4264. info: results[0],
  4265. metadata: results[1] ? new _metadata_js__WEBPACK_IMPORTED_MODULE_8__.Metadata(results[1]) : null,
  4266. contentDispositionFilename: this._fullReader?.filename ?? null,
  4267. contentLength: this._fullReader?.contentLength ?? null
  4268. };
  4269. });
  4270. this.#methodPromises.set(name, promise);
  4271. return promise;
  4272. }
  4273. getMarkInfo() {
  4274. return this.messageHandler.sendWithPromise("GetMarkInfo", null);
  4275. }
  4276. async startCleanup(keepLoadedFonts = false) {
  4277. if (this.destroyed) {
  4278. return;
  4279. }
  4280. await this.messageHandler.sendWithPromise("Cleanup", null);
  4281. for (const page of this.#pageCache.values()) {
  4282. const cleanupSuccessful = page.cleanup();
  4283. if (!cleanupSuccessful) {
  4284. throw new Error(`startCleanup: Page ${page.pageNumber} is currently rendering.`);
  4285. }
  4286. }
  4287. this.commonObjs.clear();
  4288. if (!keepLoadedFonts) {
  4289. this.fontLoader.clear();
  4290. }
  4291. this.#methodPromises.clear();
  4292. this.filterFactory.destroy(true);
  4293. }
  4294. get loadingParams() {
  4295. const {
  4296. disableAutoFetch,
  4297. enableXfa
  4298. } = this._params;
  4299. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "loadingParams", {
  4300. disableAutoFetch,
  4301. enableXfa
  4302. });
  4303. }
  4304. }
  4305. class PDFObjects {
  4306. #objs = Object.create(null);
  4307. #ensureObj(objId) {
  4308. return this.#objs[objId] ||= {
  4309. capability: new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability(),
  4310. data: null
  4311. };
  4312. }
  4313. get(objId, callback = null) {
  4314. if (callback) {
  4315. const obj = this.#ensureObj(objId);
  4316. obj.capability.promise.then(() => callback(obj.data));
  4317. return null;
  4318. }
  4319. const obj = this.#objs[objId];
  4320. if (!obj?.capability.settled) {
  4321. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  4322. }
  4323. return obj.data;
  4324. }
  4325. has(objId) {
  4326. const obj = this.#objs[objId];
  4327. return obj?.capability.settled ?? false;
  4328. }
  4329. resolve(objId, data = null) {
  4330. const obj = this.#ensureObj(objId);
  4331. obj.data = data;
  4332. obj.capability.resolve();
  4333. }
  4334. clear() {
  4335. for (const objId in this.#objs) {
  4336. const {
  4337. data
  4338. } = this.#objs[objId];
  4339. data?.bitmap?.close();
  4340. }
  4341. this.#objs = Object.create(null);
  4342. }
  4343. *[Symbol.iterator]() {
  4344. for (const objId in this.#objs) {
  4345. const {
  4346. capability,
  4347. data
  4348. } = this.#objs[objId];
  4349. if (!capability.settled) {
  4350. continue;
  4351. }
  4352. yield [objId, data];
  4353. }
  4354. }
  4355. }
  4356. class RenderTask {
  4357. #internalRenderTask = null;
  4358. constructor(internalRenderTask) {
  4359. this.#internalRenderTask = internalRenderTask;
  4360. this.onContinue = null;
  4361. }
  4362. get promise() {
  4363. return this.#internalRenderTask.capability.promise;
  4364. }
  4365. cancel(extraDelay = 0) {
  4366. this.#internalRenderTask.cancel(null, extraDelay);
  4367. }
  4368. get separateAnnots() {
  4369. const {
  4370. separateAnnots
  4371. } = this.#internalRenderTask.operatorList;
  4372. if (!separateAnnots) {
  4373. return false;
  4374. }
  4375. const {
  4376. annotationCanvasMap
  4377. } = this.#internalRenderTask;
  4378. return separateAnnots.form || separateAnnots.canvas && annotationCanvasMap?.size > 0;
  4379. }
  4380. }
  4381. class InternalRenderTask {
  4382. static #canvasInUse = new WeakSet();
  4383. constructor({
  4384. callback,
  4385. params,
  4386. objs,
  4387. commonObjs,
  4388. annotationCanvasMap,
  4389. operatorList,
  4390. pageIndex,
  4391. canvasFactory,
  4392. filterFactory,
  4393. useRequestAnimationFrame = false,
  4394. pdfBug = false,
  4395. pageColors = null
  4396. }) {
  4397. this.callback = callback;
  4398. this.params = params;
  4399. this.objs = objs;
  4400. this.commonObjs = commonObjs;
  4401. this.annotationCanvasMap = annotationCanvasMap;
  4402. this.operatorListIdx = null;
  4403. this.operatorList = operatorList;
  4404. this._pageIndex = pageIndex;
  4405. this.canvasFactory = canvasFactory;
  4406. this.filterFactory = filterFactory;
  4407. this._pdfBug = pdfBug;
  4408. this.pageColors = pageColors;
  4409. this.running = false;
  4410. this.graphicsReadyCallback = null;
  4411. this.graphicsReady = false;
  4412. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  4413. this.cancelled = false;
  4414. this.capability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  4415. this.task = new RenderTask(this);
  4416. this._cancelBound = this.cancel.bind(this);
  4417. this._continueBound = this._continue.bind(this);
  4418. this._scheduleNextBound = this._scheduleNext.bind(this);
  4419. this._nextBound = this._next.bind(this);
  4420. this._canvas = params.canvasContext.canvas;
  4421. }
  4422. get completed() {
  4423. return this.capability.promise.catch(function () {});
  4424. }
  4425. initializeGraphics({
  4426. transparency = false,
  4427. optionalContentConfig
  4428. }) {
  4429. if (this.cancelled) {
  4430. return;
  4431. }
  4432. if (this._canvas) {
  4433. if (InternalRenderTask.#canvasInUse.has(this._canvas)) {
  4434. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  4435. }
  4436. InternalRenderTask.#canvasInUse.add(this._canvas);
  4437. }
  4438. if (this._pdfBug && globalThis.StepperManager?.enabled) {
  4439. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  4440. this.stepper.init(this.operatorList);
  4441. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  4442. }
  4443. const {
  4444. canvasContext,
  4445. viewport,
  4446. transform,
  4447. background
  4448. } = this.params;
  4449. this.gfx = new _canvas_js__WEBPACK_IMPORTED_MODULE_5__.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, this.filterFactory, {
  4450. optionalContentConfig
  4451. }, this.annotationCanvasMap, this.pageColors);
  4452. this.gfx.beginDrawing({
  4453. transform,
  4454. viewport,
  4455. transparency,
  4456. background
  4457. });
  4458. this.operatorListIdx = 0;
  4459. this.graphicsReady = true;
  4460. this.graphicsReadyCallback?.();
  4461. }
  4462. cancel(error = null, extraDelay = 0) {
  4463. this.running = false;
  4464. this.cancelled = true;
  4465. this.gfx?.endDrawing();
  4466. InternalRenderTask.#canvasInUse.delete(this._canvas);
  4467. this.callback(error || new _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, extraDelay));
  4468. }
  4469. operatorListChanged() {
  4470. if (!this.graphicsReady) {
  4471. this.graphicsReadyCallback ||= this._continueBound;
  4472. return;
  4473. }
  4474. this.stepper?.updateOperatorList(this.operatorList);
  4475. if (this.running) {
  4476. return;
  4477. }
  4478. this._continue();
  4479. }
  4480. _continue() {
  4481. this.running = true;
  4482. if (this.cancelled) {
  4483. return;
  4484. }
  4485. if (this.task.onContinue) {
  4486. this.task.onContinue(this._scheduleNextBound);
  4487. } else {
  4488. this._scheduleNext();
  4489. }
  4490. }
  4491. _scheduleNext() {
  4492. if (this._useRequestAnimationFrame) {
  4493. window.requestAnimationFrame(() => {
  4494. this._nextBound().catch(this._cancelBound);
  4495. });
  4496. } else {
  4497. Promise.resolve().then(this._nextBound).catch(this._cancelBound);
  4498. }
  4499. }
  4500. async _next() {
  4501. if (this.cancelled) {
  4502. return;
  4503. }
  4504. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  4505. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  4506. this.running = false;
  4507. if (this.operatorList.lastChunk) {
  4508. this.gfx.endDrawing();
  4509. InternalRenderTask.#canvasInUse.delete(this._canvas);
  4510. this.callback();
  4511. }
  4512. }
  4513. }
  4514. }
  4515. const version = '4.0.379';
  4516. const build = '9e14d04fd';
  4517. __webpack_async_result__();
  4518. } catch(e) { __webpack_async_result__(e); } });
  4519. /***/ }),
  4520. /***/ 822:
  4521. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  4522. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  4523. /* harmony export */ BaseCMapReaderFactory: () => (/* binding */ BaseCMapReaderFactory),
  4524. /* harmony export */ BaseCanvasFactory: () => (/* binding */ BaseCanvasFactory),
  4525. /* harmony export */ BaseFilterFactory: () => (/* binding */ BaseFilterFactory),
  4526. /* harmony export */ BaseSVGFactory: () => (/* binding */ BaseSVGFactory),
  4527. /* harmony export */ BaseStandardFontDataFactory: () => (/* binding */ BaseStandardFontDataFactory)
  4528. /* harmony export */ });
  4529. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  4530. class BaseFilterFactory {
  4531. constructor() {
  4532. if (this.constructor === BaseFilterFactory) {
  4533. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Cannot initialize BaseFilterFactory.");
  4534. }
  4535. }
  4536. addFilter(maps) {
  4537. return "none";
  4538. }
  4539. addHCMFilter(fgColor, bgColor) {
  4540. return "none";
  4541. }
  4542. addHighlightHCMFilter(fgColor, bgColor, newFgColor, newBgColor) {
  4543. return "none";
  4544. }
  4545. destroy(keepHCM = false) {}
  4546. }
  4547. class BaseCanvasFactory {
  4548. constructor() {
  4549. if (this.constructor === BaseCanvasFactory) {
  4550. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Cannot initialize BaseCanvasFactory.");
  4551. }
  4552. }
  4553. create(width, height) {
  4554. if (width <= 0 || height <= 0) {
  4555. throw new Error("Invalid canvas size");
  4556. }
  4557. const canvas = this._createCanvas(width, height);
  4558. return {
  4559. canvas,
  4560. context: canvas.getContext("2d")
  4561. };
  4562. }
  4563. reset(canvasAndContext, width, height) {
  4564. if (!canvasAndContext.canvas) {
  4565. throw new Error("Canvas is not specified");
  4566. }
  4567. if (width <= 0 || height <= 0) {
  4568. throw new Error("Invalid canvas size");
  4569. }
  4570. canvasAndContext.canvas.width = width;
  4571. canvasAndContext.canvas.height = height;
  4572. }
  4573. destroy(canvasAndContext) {
  4574. if (!canvasAndContext.canvas) {
  4575. throw new Error("Canvas is not specified");
  4576. }
  4577. canvasAndContext.canvas.width = 0;
  4578. canvasAndContext.canvas.height = 0;
  4579. canvasAndContext.canvas = null;
  4580. canvasAndContext.context = null;
  4581. }
  4582. _createCanvas(width, height) {
  4583. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Abstract method `_createCanvas` called.");
  4584. }
  4585. }
  4586. class BaseCMapReaderFactory {
  4587. constructor({
  4588. baseUrl = null,
  4589. isCompressed = true
  4590. }) {
  4591. if (this.constructor === BaseCMapReaderFactory) {
  4592. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Cannot initialize BaseCMapReaderFactory.");
  4593. }
  4594. this.baseUrl = baseUrl;
  4595. this.isCompressed = isCompressed;
  4596. }
  4597. async fetch({
  4598. name
  4599. }) {
  4600. if (!this.baseUrl) {
  4601. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  4602. }
  4603. if (!name) {
  4604. throw new Error("CMap name must be specified.");
  4605. }
  4606. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  4607. const compressionType = this.isCompressed ? _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.CMapCompressionType.BINARY : _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.CMapCompressionType.NONE;
  4608. return this._fetchData(url, compressionType).catch(reason => {
  4609. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
  4610. });
  4611. }
  4612. _fetchData(url, compressionType) {
  4613. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Abstract method `_fetchData` called.");
  4614. }
  4615. }
  4616. class BaseStandardFontDataFactory {
  4617. constructor({
  4618. baseUrl = null
  4619. }) {
  4620. if (this.constructor === BaseStandardFontDataFactory) {
  4621. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Cannot initialize BaseStandardFontDataFactory.");
  4622. }
  4623. this.baseUrl = baseUrl;
  4624. }
  4625. async fetch({
  4626. filename
  4627. }) {
  4628. if (!this.baseUrl) {
  4629. throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
  4630. }
  4631. if (!filename) {
  4632. throw new Error("Font filename must be specified.");
  4633. }
  4634. const url = `${this.baseUrl}${filename}`;
  4635. return this._fetchData(url).catch(reason => {
  4636. throw new Error(`Unable to load font data at: ${url}`);
  4637. });
  4638. }
  4639. _fetchData(url) {
  4640. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Abstract method `_fetchData` called.");
  4641. }
  4642. }
  4643. class BaseSVGFactory {
  4644. constructor() {
  4645. if (this.constructor === BaseSVGFactory) {
  4646. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Cannot initialize BaseSVGFactory.");
  4647. }
  4648. }
  4649. create(width, height, skipDimensions = false) {
  4650. if (width <= 0 || height <= 0) {
  4651. throw new Error("Invalid SVG dimensions");
  4652. }
  4653. const svg = this._createSVG("svg:svg");
  4654. svg.setAttribute("version", "1.1");
  4655. if (!skipDimensions) {
  4656. svg.setAttribute("width", `${width}px`);
  4657. svg.setAttribute("height", `${height}px`);
  4658. }
  4659. svg.setAttribute("preserveAspectRatio", "none");
  4660. svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
  4661. return svg;
  4662. }
  4663. createElement(type) {
  4664. if (typeof type !== "string") {
  4665. throw new Error("Invalid SVG element type");
  4666. }
  4667. return this._createSVG(type);
  4668. }
  4669. _createSVG(type) {
  4670. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Abstract method `_createSVG` called.");
  4671. }
  4672. }
  4673. /***/ }),
  4674. /***/ 250:
  4675. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  4676. // EXPORTS
  4677. __webpack_require__.d(__webpack_exports__, {
  4678. CanvasGraphics: () => (/* binding */ CanvasGraphics)
  4679. });
  4680. // EXTERNAL MODULE: ./src/shared/util.js
  4681. var util = __webpack_require__(266);
  4682. // EXTERNAL MODULE: ./src/display/display_utils.js
  4683. var display_utils = __webpack_require__(473);
  4684. ;// CONCATENATED MODULE: ./src/display/pattern_helper.js
  4685. const PathType = {
  4686. FILL: "Fill",
  4687. STROKE: "Stroke",
  4688. SHADING: "Shading"
  4689. };
  4690. function applyBoundingBox(ctx, bbox) {
  4691. if (!bbox) {
  4692. return;
  4693. }
  4694. const width = bbox[2] - bbox[0];
  4695. const height = bbox[3] - bbox[1];
  4696. const region = new Path2D();
  4697. region.rect(bbox[0], bbox[1], width, height);
  4698. ctx.clip(region);
  4699. }
  4700. class BaseShadingPattern {
  4701. constructor() {
  4702. if (this.constructor === BaseShadingPattern) {
  4703. (0,util.unreachable)("Cannot initialize BaseShadingPattern.");
  4704. }
  4705. }
  4706. getPattern() {
  4707. (0,util.unreachable)("Abstract method `getPattern` called.");
  4708. }
  4709. }
  4710. class RadialAxialShadingPattern extends BaseShadingPattern {
  4711. constructor(IR) {
  4712. super();
  4713. this._type = IR[1];
  4714. this._bbox = IR[2];
  4715. this._colorStops = IR[3];
  4716. this._p0 = IR[4];
  4717. this._p1 = IR[5];
  4718. this._r0 = IR[6];
  4719. this._r1 = IR[7];
  4720. this.matrix = null;
  4721. }
  4722. _createGradient(ctx) {
  4723. let grad;
  4724. if (this._type === "axial") {
  4725. grad = ctx.createLinearGradient(this._p0[0], this._p0[1], this._p1[0], this._p1[1]);
  4726. } else if (this._type === "radial") {
  4727. grad = ctx.createRadialGradient(this._p0[0], this._p0[1], this._r0, this._p1[0], this._p1[1], this._r1);
  4728. }
  4729. for (const colorStop of this._colorStops) {
  4730. grad.addColorStop(colorStop[0], colorStop[1]);
  4731. }
  4732. return grad;
  4733. }
  4734. getPattern(ctx, owner, inverse, pathType) {
  4735. let pattern;
  4736. if (pathType === PathType.STROKE || pathType === PathType.FILL) {
  4737. const ownerBBox = owner.current.getClippedPathBoundingBox(pathType, (0,display_utils.getCurrentTransform)(ctx)) || [0, 0, 0, 0];
  4738. const width = Math.ceil(ownerBBox[2] - ownerBBox[0]) || 1;
  4739. const height = Math.ceil(ownerBBox[3] - ownerBBox[1]) || 1;
  4740. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", width, height, true);
  4741. const tmpCtx = tmpCanvas.context;
  4742. tmpCtx.clearRect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  4743. tmpCtx.beginPath();
  4744. tmpCtx.rect(0, 0, tmpCtx.canvas.width, tmpCtx.canvas.height);
  4745. tmpCtx.translate(-ownerBBox[0], -ownerBBox[1]);
  4746. inverse = util.Util.transform(inverse, [1, 0, 0, 1, ownerBBox[0], ownerBBox[1]]);
  4747. tmpCtx.transform(...owner.baseTransform);
  4748. if (this.matrix) {
  4749. tmpCtx.transform(...this.matrix);
  4750. }
  4751. applyBoundingBox(tmpCtx, this._bbox);
  4752. tmpCtx.fillStyle = this._createGradient(tmpCtx);
  4753. tmpCtx.fill();
  4754. pattern = ctx.createPattern(tmpCanvas.canvas, "no-repeat");
  4755. const domMatrix = new DOMMatrix(inverse);
  4756. pattern.setTransform(domMatrix);
  4757. } else {
  4758. applyBoundingBox(ctx, this._bbox);
  4759. pattern = this._createGradient(ctx);
  4760. }
  4761. return pattern;
  4762. }
  4763. }
  4764. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  4765. const coords = context.coords,
  4766. colors = context.colors;
  4767. const bytes = data.data,
  4768. rowSize = data.width * 4;
  4769. let tmp;
  4770. if (coords[p1 + 1] > coords[p2 + 1]) {
  4771. tmp = p1;
  4772. p1 = p2;
  4773. p2 = tmp;
  4774. tmp = c1;
  4775. c1 = c2;
  4776. c2 = tmp;
  4777. }
  4778. if (coords[p2 + 1] > coords[p3 + 1]) {
  4779. tmp = p2;
  4780. p2 = p3;
  4781. p3 = tmp;
  4782. tmp = c2;
  4783. c2 = c3;
  4784. c3 = tmp;
  4785. }
  4786. if (coords[p1 + 1] > coords[p2 + 1]) {
  4787. tmp = p1;
  4788. p1 = p2;
  4789. p2 = tmp;
  4790. tmp = c1;
  4791. c1 = c2;
  4792. c2 = tmp;
  4793. }
  4794. const x1 = (coords[p1] + context.offsetX) * context.scaleX;
  4795. const y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  4796. const x2 = (coords[p2] + context.offsetX) * context.scaleX;
  4797. const y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  4798. const x3 = (coords[p3] + context.offsetX) * context.scaleX;
  4799. const y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  4800. if (y1 >= y3) {
  4801. return;
  4802. }
  4803. const c1r = colors[c1],
  4804. c1g = colors[c1 + 1],
  4805. c1b = colors[c1 + 2];
  4806. const c2r = colors[c2],
  4807. c2g = colors[c2 + 1],
  4808. c2b = colors[c2 + 2];
  4809. const c3r = colors[c3],
  4810. c3g = colors[c3 + 1],
  4811. c3b = colors[c3 + 2];
  4812. const minY = Math.round(y1),
  4813. maxY = Math.round(y3);
  4814. let xa, car, cag, cab;
  4815. let xb, cbr, cbg, cbb;
  4816. for (let y = minY; y <= maxY; y++) {
  4817. if (y < y2) {
  4818. const k = y < y1 ? 0 : (y1 - y) / (y1 - y2);
  4819. xa = x1 - (x1 - x2) * k;
  4820. car = c1r - (c1r - c2r) * k;
  4821. cag = c1g - (c1g - c2g) * k;
  4822. cab = c1b - (c1b - c2b) * k;
  4823. } else {
  4824. let k;
  4825. if (y > y3) {
  4826. k = 1;
  4827. } else if (y2 === y3) {
  4828. k = 0;
  4829. } else {
  4830. k = (y2 - y) / (y2 - y3);
  4831. }
  4832. xa = x2 - (x2 - x3) * k;
  4833. car = c2r - (c2r - c3r) * k;
  4834. cag = c2g - (c2g - c3g) * k;
  4835. cab = c2b - (c2b - c3b) * k;
  4836. }
  4837. let k;
  4838. if (y < y1) {
  4839. k = 0;
  4840. } else if (y > y3) {
  4841. k = 1;
  4842. } else {
  4843. k = (y1 - y) / (y1 - y3);
  4844. }
  4845. xb = x1 - (x1 - x3) * k;
  4846. cbr = c1r - (c1r - c3r) * k;
  4847. cbg = c1g - (c1g - c3g) * k;
  4848. cbb = c1b - (c1b - c3b) * k;
  4849. const x1_ = Math.round(Math.min(xa, xb));
  4850. const x2_ = Math.round(Math.max(xa, xb));
  4851. let j = rowSize * y + x1_ * 4;
  4852. for (let x = x1_; x <= x2_; x++) {
  4853. k = (xa - x) / (xa - xb);
  4854. if (k < 0) {
  4855. k = 0;
  4856. } else if (k > 1) {
  4857. k = 1;
  4858. }
  4859. bytes[j++] = car - (car - cbr) * k | 0;
  4860. bytes[j++] = cag - (cag - cbg) * k | 0;
  4861. bytes[j++] = cab - (cab - cbb) * k | 0;
  4862. bytes[j++] = 255;
  4863. }
  4864. }
  4865. }
  4866. function drawFigure(data, figure, context) {
  4867. const ps = figure.coords;
  4868. const cs = figure.colors;
  4869. let i, ii;
  4870. switch (figure.type) {
  4871. case "lattice":
  4872. const verticesPerRow = figure.verticesPerRow;
  4873. const rows = Math.floor(ps.length / verticesPerRow) - 1;
  4874. const cols = verticesPerRow - 1;
  4875. for (i = 0; i < rows; i++) {
  4876. let q = i * verticesPerRow;
  4877. for (let j = 0; j < cols; j++, q++) {
  4878. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  4879. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  4880. }
  4881. }
  4882. break;
  4883. case "triangles":
  4884. for (i = 0, ii = ps.length; i < ii; i += 3) {
  4885. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  4886. }
  4887. break;
  4888. default:
  4889. throw new Error("illegal figure");
  4890. }
  4891. }
  4892. class MeshShadingPattern extends BaseShadingPattern {
  4893. constructor(IR) {
  4894. super();
  4895. this._coords = IR[2];
  4896. this._colors = IR[3];
  4897. this._figures = IR[4];
  4898. this._bounds = IR[5];
  4899. this._bbox = IR[7];
  4900. this._background = IR[8];
  4901. this.matrix = null;
  4902. }
  4903. _createMeshCanvas(combinedScale, backgroundColor, cachedCanvases) {
  4904. const EXPECTED_SCALE = 1.1;
  4905. const MAX_PATTERN_SIZE = 3000;
  4906. const BORDER_SIZE = 2;
  4907. const offsetX = Math.floor(this._bounds[0]);
  4908. const offsetY = Math.floor(this._bounds[1]);
  4909. const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
  4910. const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
  4911. const width = Math.min(Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  4912. const height = Math.min(Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  4913. const scaleX = boundsWidth / width;
  4914. const scaleY = boundsHeight / height;
  4915. const context = {
  4916. coords: this._coords,
  4917. colors: this._colors,
  4918. offsetX: -offsetX,
  4919. offsetY: -offsetY,
  4920. scaleX: 1 / scaleX,
  4921. scaleY: 1 / scaleY
  4922. };
  4923. const paddedWidth = width + BORDER_SIZE * 2;
  4924. const paddedHeight = height + BORDER_SIZE * 2;
  4925. const tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  4926. const tmpCtx = tmpCanvas.context;
  4927. const data = tmpCtx.createImageData(width, height);
  4928. if (backgroundColor) {
  4929. const bytes = data.data;
  4930. for (let i = 0, ii = bytes.length; i < ii; i += 4) {
  4931. bytes[i] = backgroundColor[0];
  4932. bytes[i + 1] = backgroundColor[1];
  4933. bytes[i + 2] = backgroundColor[2];
  4934. bytes[i + 3] = 255;
  4935. }
  4936. }
  4937. for (const figure of this._figures) {
  4938. drawFigure(data, figure, context);
  4939. }
  4940. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  4941. const canvas = tmpCanvas.canvas;
  4942. return {
  4943. canvas,
  4944. offsetX: offsetX - BORDER_SIZE * scaleX,
  4945. offsetY: offsetY - BORDER_SIZE * scaleY,
  4946. scaleX,
  4947. scaleY
  4948. };
  4949. }
  4950. getPattern(ctx, owner, inverse, pathType) {
  4951. applyBoundingBox(ctx, this._bbox);
  4952. let scale;
  4953. if (pathType === PathType.SHADING) {
  4954. scale = util.Util.singularValueDecompose2dScale((0,display_utils.getCurrentTransform)(ctx));
  4955. } else {
  4956. scale = util.Util.singularValueDecompose2dScale(owner.baseTransform);
  4957. if (this.matrix) {
  4958. const matrixScale = util.Util.singularValueDecompose2dScale(this.matrix);
  4959. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  4960. }
  4961. }
  4962. const temporaryPatternCanvas = this._createMeshCanvas(scale, pathType === PathType.SHADING ? null : this._background, owner.cachedCanvases);
  4963. if (pathType !== PathType.SHADING) {
  4964. ctx.setTransform(...owner.baseTransform);
  4965. if (this.matrix) {
  4966. ctx.transform(...this.matrix);
  4967. }
  4968. }
  4969. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  4970. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  4971. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  4972. }
  4973. }
  4974. class DummyShadingPattern extends BaseShadingPattern {
  4975. getPattern() {
  4976. return "hotpink";
  4977. }
  4978. }
  4979. function getShadingPattern(IR) {
  4980. switch (IR[0]) {
  4981. case "RadialAxial":
  4982. return new RadialAxialShadingPattern(IR);
  4983. case "Mesh":
  4984. return new MeshShadingPattern(IR);
  4985. case "Dummy":
  4986. return new DummyShadingPattern();
  4987. }
  4988. throw new Error(`Unknown IR type: ${IR[0]}`);
  4989. }
  4990. const PaintType = {
  4991. COLORED: 1,
  4992. UNCOLORED: 2
  4993. };
  4994. class TilingPattern {
  4995. static MAX_PATTERN_SIZE = 3000;
  4996. constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  4997. this.operatorList = IR[2];
  4998. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  4999. this.bbox = IR[4];
  5000. this.xstep = IR[5];
  5001. this.ystep = IR[6];
  5002. this.paintType = IR[7];
  5003. this.tilingType = IR[8];
  5004. this.color = color;
  5005. this.ctx = ctx;
  5006. this.canvasGraphicsFactory = canvasGraphicsFactory;
  5007. this.baseTransform = baseTransform;
  5008. }
  5009. createPatternCanvas(owner) {
  5010. const operatorList = this.operatorList;
  5011. const bbox = this.bbox;
  5012. const xstep = this.xstep;
  5013. const ystep = this.ystep;
  5014. const paintType = this.paintType;
  5015. const tilingType = this.tilingType;
  5016. const color = this.color;
  5017. const canvasGraphicsFactory = this.canvasGraphicsFactory;
  5018. (0,util.info)("TilingType: " + tilingType);
  5019. const x0 = bbox[0],
  5020. y0 = bbox[1],
  5021. x1 = bbox[2],
  5022. y1 = bbox[3];
  5023. const matrixScale = util.Util.singularValueDecompose2dScale(this.matrix);
  5024. const curMatrixScale = util.Util.singularValueDecompose2dScale(this.baseTransform);
  5025. const combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  5026. const dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  5027. const dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  5028. const tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  5029. const tmpCtx = tmpCanvas.context;
  5030. const graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  5031. graphics.groupLevel = owner.groupLevel;
  5032. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  5033. let adjustedX0 = x0;
  5034. let adjustedY0 = y0;
  5035. let adjustedX1 = x1;
  5036. let adjustedY1 = y1;
  5037. if (x0 < 0) {
  5038. adjustedX0 = 0;
  5039. adjustedX1 += Math.abs(x0);
  5040. }
  5041. if (y0 < 0) {
  5042. adjustedY0 = 0;
  5043. adjustedY1 += Math.abs(y0);
  5044. }
  5045. tmpCtx.translate(-(dimx.scale * adjustedX0), -(dimy.scale * adjustedY0));
  5046. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  5047. tmpCtx.save();
  5048. this.clipBbox(graphics, adjustedX0, adjustedY0, adjustedX1, adjustedY1);
  5049. graphics.baseTransform = (0,display_utils.getCurrentTransform)(graphics.ctx);
  5050. graphics.executeOperatorList(operatorList);
  5051. graphics.endDrawing();
  5052. return {
  5053. canvas: tmpCanvas.canvas,
  5054. scaleX: dimx.scale,
  5055. scaleY: dimy.scale,
  5056. offsetX: adjustedX0,
  5057. offsetY: adjustedY0
  5058. };
  5059. }
  5060. getSizeAndScale(step, realOutputSize, scale) {
  5061. step = Math.abs(step);
  5062. const maxSize = Math.max(TilingPattern.MAX_PATTERN_SIZE, realOutputSize);
  5063. let size = Math.ceil(step * scale);
  5064. if (size >= maxSize) {
  5065. size = maxSize;
  5066. } else {
  5067. scale = size / step;
  5068. }
  5069. return {
  5070. scale,
  5071. size
  5072. };
  5073. }
  5074. clipBbox(graphics, x0, y0, x1, y1) {
  5075. const bboxWidth = x1 - x0;
  5076. const bboxHeight = y1 - y0;
  5077. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5078. graphics.current.updateRectMinMax((0,display_utils.getCurrentTransform)(graphics.ctx), [x0, y0, x1, y1]);
  5079. graphics.clip();
  5080. graphics.endPath();
  5081. }
  5082. setFillAndStrokeStyleToContext(graphics, paintType, color) {
  5083. const context = graphics.ctx,
  5084. current = graphics.current;
  5085. switch (paintType) {
  5086. case PaintType.COLORED:
  5087. const ctx = this.ctx;
  5088. context.fillStyle = ctx.fillStyle;
  5089. context.strokeStyle = ctx.strokeStyle;
  5090. current.fillColor = ctx.fillStyle;
  5091. current.strokeColor = ctx.strokeStyle;
  5092. break;
  5093. case PaintType.UNCOLORED:
  5094. const cssColor = util.Util.makeHexColor(color[0], color[1], color[2]);
  5095. context.fillStyle = cssColor;
  5096. context.strokeStyle = cssColor;
  5097. current.fillColor = cssColor;
  5098. current.strokeColor = cssColor;
  5099. break;
  5100. default:
  5101. throw new util.FormatError(`Unsupported paint type: ${paintType}`);
  5102. }
  5103. }
  5104. getPattern(ctx, owner, inverse, pathType) {
  5105. let matrix = inverse;
  5106. if (pathType !== PathType.SHADING) {
  5107. matrix = util.Util.transform(matrix, owner.baseTransform);
  5108. if (this.matrix) {
  5109. matrix = util.Util.transform(matrix, this.matrix);
  5110. }
  5111. }
  5112. const temporaryPatternCanvas = this.createPatternCanvas(owner);
  5113. let domMatrix = new DOMMatrix(matrix);
  5114. domMatrix = domMatrix.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  5115. domMatrix = domMatrix.scale(1 / temporaryPatternCanvas.scaleX, 1 / temporaryPatternCanvas.scaleY);
  5116. const pattern = ctx.createPattern(temporaryPatternCanvas.canvas, "repeat");
  5117. pattern.setTransform(domMatrix);
  5118. return pattern;
  5119. }
  5120. }
  5121. ;// CONCATENATED MODULE: ./src/shared/image_utils.js
  5122. function convertToRGBA(params) {
  5123. switch (params.kind) {
  5124. case ImageKind.GRAYSCALE_1BPP:
  5125. return convertBlackAndWhiteToRGBA(params);
  5126. case ImageKind.RGB_24BPP:
  5127. return convertRGBToRGBA(params);
  5128. }
  5129. return null;
  5130. }
  5131. function convertBlackAndWhiteToRGBA({
  5132. src,
  5133. srcPos = 0,
  5134. dest,
  5135. width,
  5136. height,
  5137. nonBlackColor = 0xffffffff,
  5138. inverseDecode = false
  5139. }) {
  5140. const black = util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  5141. const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor];
  5142. const widthInSource = width >> 3;
  5143. const widthRemainder = width & 7;
  5144. const srcLength = src.length;
  5145. dest = new Uint32Array(dest.buffer);
  5146. let destPos = 0;
  5147. for (let i = 0; i < height; i++) {
  5148. for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
  5149. const elem = srcPos < srcLength ? src[srcPos] : 255;
  5150. dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping;
  5151. dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping;
  5152. dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping;
  5153. dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping;
  5154. dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping;
  5155. dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping;
  5156. dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping;
  5157. dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping;
  5158. }
  5159. if (widthRemainder === 0) {
  5160. continue;
  5161. }
  5162. const elem = srcPos < srcLength ? src[srcPos++] : 255;
  5163. for (let j = 0; j < widthRemainder; j++) {
  5164. dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
  5165. }
  5166. }
  5167. return {
  5168. srcPos,
  5169. destPos
  5170. };
  5171. }
  5172. function convertRGBToRGBA({
  5173. src,
  5174. srcPos = 0,
  5175. dest,
  5176. destPos = 0,
  5177. width,
  5178. height
  5179. }) {
  5180. let i = 0;
  5181. const len32 = src.length >> 2;
  5182. const src32 = new Uint32Array(src.buffer, srcPos, len32);
  5183. if (FeatureTest.isLittleEndian) {
  5184. for (; i < len32 - 2; i += 3, destPos += 4) {
  5185. const s1 = src32[i];
  5186. const s2 = src32[i + 1];
  5187. const s3 = src32[i + 2];
  5188. dest[destPos] = s1 | 0xff000000;
  5189. dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 0xff000000;
  5190. dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 0xff000000;
  5191. dest[destPos + 3] = s3 >>> 8 | 0xff000000;
  5192. }
  5193. for (let j = i * 4, jj = src.length; j < jj; j += 3) {
  5194. dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 0xff000000;
  5195. }
  5196. } else {
  5197. for (; i < len32 - 2; i += 3, destPos += 4) {
  5198. const s1 = src32[i];
  5199. const s2 = src32[i + 1];
  5200. const s3 = src32[i + 2];
  5201. dest[destPos] = s1 | 0xff;
  5202. dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 0xff;
  5203. dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 0xff;
  5204. dest[destPos + 3] = s3 << 8 | 0xff;
  5205. }
  5206. for (let j = i * 4, jj = src.length; j < jj; j += 3) {
  5207. dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 0xff;
  5208. }
  5209. }
  5210. return {
  5211. srcPos,
  5212. destPos
  5213. };
  5214. }
  5215. function grayToRGBA(src, dest) {
  5216. if (FeatureTest.isLittleEndian) {
  5217. for (let i = 0, ii = src.length; i < ii; i++) {
  5218. dest[i] = src[i] * 0x10101 | 0xff000000;
  5219. }
  5220. } else {
  5221. for (let i = 0, ii = src.length; i < ii; i++) {
  5222. dest[i] = src[i] * 0x1010100 | 0x000000ff;
  5223. }
  5224. }
  5225. }
  5226. ;// CONCATENATED MODULE: ./src/display/canvas.js
  5227. const MIN_FONT_SIZE = 16;
  5228. const MAX_FONT_SIZE = 100;
  5229. const MAX_GROUP_SIZE = 4096;
  5230. const EXECUTION_TIME = 15;
  5231. const EXECUTION_STEPS = 10;
  5232. const MAX_SIZE_TO_COMPILE = 1000;
  5233. const FULL_CHUNK_HEIGHT = 16;
  5234. function mirrorContextOperations(ctx, destCtx) {
  5235. if (ctx._removeMirroring) {
  5236. throw new Error("Context is already forwarding operations.");
  5237. }
  5238. ctx.__originalSave = ctx.save;
  5239. ctx.__originalRestore = ctx.restore;
  5240. ctx.__originalRotate = ctx.rotate;
  5241. ctx.__originalScale = ctx.scale;
  5242. ctx.__originalTranslate = ctx.translate;
  5243. ctx.__originalTransform = ctx.transform;
  5244. ctx.__originalSetTransform = ctx.setTransform;
  5245. ctx.__originalResetTransform = ctx.resetTransform;
  5246. ctx.__originalClip = ctx.clip;
  5247. ctx.__originalMoveTo = ctx.moveTo;
  5248. ctx.__originalLineTo = ctx.lineTo;
  5249. ctx.__originalBezierCurveTo = ctx.bezierCurveTo;
  5250. ctx.__originalRect = ctx.rect;
  5251. ctx.__originalClosePath = ctx.closePath;
  5252. ctx.__originalBeginPath = ctx.beginPath;
  5253. ctx._removeMirroring = () => {
  5254. ctx.save = ctx.__originalSave;
  5255. ctx.restore = ctx.__originalRestore;
  5256. ctx.rotate = ctx.__originalRotate;
  5257. ctx.scale = ctx.__originalScale;
  5258. ctx.translate = ctx.__originalTranslate;
  5259. ctx.transform = ctx.__originalTransform;
  5260. ctx.setTransform = ctx.__originalSetTransform;
  5261. ctx.resetTransform = ctx.__originalResetTransform;
  5262. ctx.clip = ctx.__originalClip;
  5263. ctx.moveTo = ctx.__originalMoveTo;
  5264. ctx.lineTo = ctx.__originalLineTo;
  5265. ctx.bezierCurveTo = ctx.__originalBezierCurveTo;
  5266. ctx.rect = ctx.__originalRect;
  5267. ctx.closePath = ctx.__originalClosePath;
  5268. ctx.beginPath = ctx.__originalBeginPath;
  5269. delete ctx._removeMirroring;
  5270. };
  5271. ctx.save = function ctxSave() {
  5272. destCtx.save();
  5273. this.__originalSave();
  5274. };
  5275. ctx.restore = function ctxRestore() {
  5276. destCtx.restore();
  5277. this.__originalRestore();
  5278. };
  5279. ctx.translate = function ctxTranslate(x, y) {
  5280. destCtx.translate(x, y);
  5281. this.__originalTranslate(x, y);
  5282. };
  5283. ctx.scale = function ctxScale(x, y) {
  5284. destCtx.scale(x, y);
  5285. this.__originalScale(x, y);
  5286. };
  5287. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  5288. destCtx.transform(a, b, c, d, e, f);
  5289. this.__originalTransform(a, b, c, d, e, f);
  5290. };
  5291. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  5292. destCtx.setTransform(a, b, c, d, e, f);
  5293. this.__originalSetTransform(a, b, c, d, e, f);
  5294. };
  5295. ctx.resetTransform = function ctxResetTransform() {
  5296. destCtx.resetTransform();
  5297. this.__originalResetTransform();
  5298. };
  5299. ctx.rotate = function ctxRotate(angle) {
  5300. destCtx.rotate(angle);
  5301. this.__originalRotate(angle);
  5302. };
  5303. ctx.clip = function ctxRotate(rule) {
  5304. destCtx.clip(rule);
  5305. this.__originalClip(rule);
  5306. };
  5307. ctx.moveTo = function (x, y) {
  5308. destCtx.moveTo(x, y);
  5309. this.__originalMoveTo(x, y);
  5310. };
  5311. ctx.lineTo = function (x, y) {
  5312. destCtx.lineTo(x, y);
  5313. this.__originalLineTo(x, y);
  5314. };
  5315. ctx.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
  5316. destCtx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  5317. this.__originalBezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
  5318. };
  5319. ctx.rect = function (x, y, width, height) {
  5320. destCtx.rect(x, y, width, height);
  5321. this.__originalRect(x, y, width, height);
  5322. };
  5323. ctx.closePath = function () {
  5324. destCtx.closePath();
  5325. this.__originalClosePath();
  5326. };
  5327. ctx.beginPath = function () {
  5328. destCtx.beginPath();
  5329. this.__originalBeginPath();
  5330. };
  5331. }
  5332. class CachedCanvases {
  5333. constructor(canvasFactory) {
  5334. this.canvasFactory = canvasFactory;
  5335. this.cache = Object.create(null);
  5336. }
  5337. getCanvas(id, width, height) {
  5338. let canvasEntry;
  5339. if (this.cache[id] !== undefined) {
  5340. canvasEntry = this.cache[id];
  5341. this.canvasFactory.reset(canvasEntry, width, height);
  5342. } else {
  5343. canvasEntry = this.canvasFactory.create(width, height);
  5344. this.cache[id] = canvasEntry;
  5345. }
  5346. return canvasEntry;
  5347. }
  5348. delete(id) {
  5349. delete this.cache[id];
  5350. }
  5351. clear() {
  5352. for (const id in this.cache) {
  5353. const canvasEntry = this.cache[id];
  5354. this.canvasFactory.destroy(canvasEntry);
  5355. delete this.cache[id];
  5356. }
  5357. }
  5358. }
  5359. function drawImageAtIntegerCoords(ctx, srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH) {
  5360. const [a, b, c, d, tx, ty] = (0,display_utils.getCurrentTransform)(ctx);
  5361. if (b === 0 && c === 0) {
  5362. const tlX = destX * a + tx;
  5363. const rTlX = Math.round(tlX);
  5364. const tlY = destY * d + ty;
  5365. const rTlY = Math.round(tlY);
  5366. const brX = (destX + destW) * a + tx;
  5367. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  5368. const brY = (destY + destH) * d + ty;
  5369. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  5370. ctx.setTransform(Math.sign(a), 0, 0, Math.sign(d), rTlX, rTlY);
  5371. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rWidth, rHeight);
  5372. ctx.setTransform(a, b, c, d, tx, ty);
  5373. return [rWidth, rHeight];
  5374. }
  5375. if (a === 0 && d === 0) {
  5376. const tlX = destY * c + tx;
  5377. const rTlX = Math.round(tlX);
  5378. const tlY = destX * b + ty;
  5379. const rTlY = Math.round(tlY);
  5380. const brX = (destY + destH) * c + tx;
  5381. const rWidth = Math.abs(Math.round(brX) - rTlX) || 1;
  5382. const brY = (destX + destW) * b + ty;
  5383. const rHeight = Math.abs(Math.round(brY) - rTlY) || 1;
  5384. ctx.setTransform(0, Math.sign(b), Math.sign(c), 0, rTlX, rTlY);
  5385. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, 0, 0, rHeight, rWidth);
  5386. ctx.setTransform(a, b, c, d, tx, ty);
  5387. return [rHeight, rWidth];
  5388. }
  5389. ctx.drawImage(srcImg, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
  5390. const scaleX = Math.hypot(a, b);
  5391. const scaleY = Math.hypot(c, d);
  5392. return [scaleX * destW, scaleY * destH];
  5393. }
  5394. function compileType3Glyph(imgData) {
  5395. const {
  5396. width,
  5397. height
  5398. } = imgData;
  5399. if (width > MAX_SIZE_TO_COMPILE || height > MAX_SIZE_TO_COMPILE) {
  5400. return null;
  5401. }
  5402. const POINT_TO_PROCESS_LIMIT = 1000;
  5403. const POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  5404. const width1 = width + 1;
  5405. let points = new Uint8Array(width1 * (height + 1));
  5406. let i, j, j0;
  5407. const lineSize = width + 7 & ~7;
  5408. let data = new Uint8Array(lineSize * height),
  5409. pos = 0;
  5410. for (const elem of imgData.data) {
  5411. let mask = 128;
  5412. while (mask > 0) {
  5413. data[pos++] = elem & mask ? 0 : 255;
  5414. mask >>= 1;
  5415. }
  5416. }
  5417. let count = 0;
  5418. pos = 0;
  5419. if (data[pos] !== 0) {
  5420. points[0] = 1;
  5421. ++count;
  5422. }
  5423. for (j = 1; j < width; j++) {
  5424. if (data[pos] !== data[pos + 1]) {
  5425. points[j] = data[pos] ? 2 : 1;
  5426. ++count;
  5427. }
  5428. pos++;
  5429. }
  5430. if (data[pos] !== 0) {
  5431. points[j] = 2;
  5432. ++count;
  5433. }
  5434. for (i = 1; i < height; i++) {
  5435. pos = i * lineSize;
  5436. j0 = i * width1;
  5437. if (data[pos - lineSize] !== data[pos]) {
  5438. points[j0] = data[pos] ? 1 : 8;
  5439. ++count;
  5440. }
  5441. let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  5442. for (j = 1; j < width; j++) {
  5443. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  5444. if (POINT_TYPES[sum]) {
  5445. points[j0 + j] = POINT_TYPES[sum];
  5446. ++count;
  5447. }
  5448. pos++;
  5449. }
  5450. if (data[pos - lineSize] !== data[pos]) {
  5451. points[j0 + j] = data[pos] ? 2 : 4;
  5452. ++count;
  5453. }
  5454. if (count > POINT_TO_PROCESS_LIMIT) {
  5455. return null;
  5456. }
  5457. }
  5458. pos = lineSize * (height - 1);
  5459. j0 = i * width1;
  5460. if (data[pos] !== 0) {
  5461. points[j0] = 8;
  5462. ++count;
  5463. }
  5464. for (j = 1; j < width; j++) {
  5465. if (data[pos] !== data[pos + 1]) {
  5466. points[j0 + j] = data[pos] ? 4 : 8;
  5467. ++count;
  5468. }
  5469. pos++;
  5470. }
  5471. if (data[pos] !== 0) {
  5472. points[j0 + j] = 4;
  5473. ++count;
  5474. }
  5475. if (count > POINT_TO_PROCESS_LIMIT) {
  5476. return null;
  5477. }
  5478. const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  5479. const path = new Path2D();
  5480. for (i = 0; count && i <= height; i++) {
  5481. let p = i * width1;
  5482. const end = p + width;
  5483. while (p < end && !points[p]) {
  5484. p++;
  5485. }
  5486. if (p === end) {
  5487. continue;
  5488. }
  5489. path.moveTo(p % width1, i);
  5490. const p0 = p;
  5491. let type = points[p];
  5492. do {
  5493. const step = steps[type];
  5494. do {
  5495. p += step;
  5496. } while (!points[p]);
  5497. const pp = points[p];
  5498. if (pp !== 5 && pp !== 10) {
  5499. type = pp;
  5500. points[p] = 0;
  5501. } else {
  5502. type = pp & 0x33 * type >> 4;
  5503. points[p] &= type >> 2 | type << 2;
  5504. }
  5505. path.lineTo(p % width1, p / width1 | 0);
  5506. if (!points[p]) {
  5507. --count;
  5508. }
  5509. } while (p0 !== p);
  5510. --i;
  5511. }
  5512. data = null;
  5513. points = null;
  5514. const drawOutline = function (c) {
  5515. c.save();
  5516. c.scale(1 / width, -1 / height);
  5517. c.translate(0, -height);
  5518. c.fill(path);
  5519. c.beginPath();
  5520. c.restore();
  5521. };
  5522. return drawOutline;
  5523. }
  5524. class CanvasExtraState {
  5525. constructor(width, height) {
  5526. this.alphaIsShape = false;
  5527. this.fontSize = 0;
  5528. this.fontSizeScale = 1;
  5529. this.textMatrix = util.IDENTITY_MATRIX;
  5530. this.textMatrixScale = 1;
  5531. this.fontMatrix = util.FONT_IDENTITY_MATRIX;
  5532. this.leading = 0;
  5533. this.x = 0;
  5534. this.y = 0;
  5535. this.lineX = 0;
  5536. this.lineY = 0;
  5537. this.charSpacing = 0;
  5538. this.wordSpacing = 0;
  5539. this.textHScale = 1;
  5540. this.textRenderingMode = util.TextRenderingMode.FILL;
  5541. this.textRise = 0;
  5542. this.fillColor = "#000000";
  5543. this.strokeColor = "#000000";
  5544. this.patternFill = false;
  5545. this.fillAlpha = 1;
  5546. this.strokeAlpha = 1;
  5547. this.lineWidth = 1;
  5548. this.activeSMask = null;
  5549. this.transferMaps = "none";
  5550. this.startNewPathAndClipBox([0, 0, width, height]);
  5551. }
  5552. clone() {
  5553. const clone = Object.create(this);
  5554. clone.clipBox = this.clipBox.slice();
  5555. return clone;
  5556. }
  5557. setCurrentPoint(x, y) {
  5558. this.x = x;
  5559. this.y = y;
  5560. }
  5561. updatePathMinMax(transform, x, y) {
  5562. [x, y] = util.Util.applyTransform([x, y], transform);
  5563. this.minX = Math.min(this.minX, x);
  5564. this.minY = Math.min(this.minY, y);
  5565. this.maxX = Math.max(this.maxX, x);
  5566. this.maxY = Math.max(this.maxY, y);
  5567. }
  5568. updateRectMinMax(transform, rect) {
  5569. const p1 = util.Util.applyTransform(rect, transform);
  5570. const p2 = util.Util.applyTransform(rect.slice(2), transform);
  5571. const p3 = util.Util.applyTransform([rect[0], rect[3]], transform);
  5572. const p4 = util.Util.applyTransform([rect[2], rect[1]], transform);
  5573. this.minX = Math.min(this.minX, p1[0], p2[0], p3[0], p4[0]);
  5574. this.minY = Math.min(this.minY, p1[1], p2[1], p3[1], p4[1]);
  5575. this.maxX = Math.max(this.maxX, p1[0], p2[0], p3[0], p4[0]);
  5576. this.maxY = Math.max(this.maxY, p1[1], p2[1], p3[1], p4[1]);
  5577. }
  5578. updateScalingPathMinMax(transform, minMax) {
  5579. util.Util.scaleMinMax(transform, minMax);
  5580. this.minX = Math.min(this.minX, minMax[0]);
  5581. this.maxX = Math.max(this.maxX, minMax[1]);
  5582. this.minY = Math.min(this.minY, minMax[2]);
  5583. this.maxY = Math.max(this.maxY, minMax[3]);
  5584. }
  5585. updateCurvePathMinMax(transform, x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
  5586. const box = util.Util.bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3);
  5587. if (minMax) {
  5588. minMax[0] = Math.min(minMax[0], box[0], box[2]);
  5589. minMax[1] = Math.max(minMax[1], box[0], box[2]);
  5590. minMax[2] = Math.min(minMax[2], box[1], box[3]);
  5591. minMax[3] = Math.max(minMax[3], box[1], box[3]);
  5592. return;
  5593. }
  5594. this.updateRectMinMax(transform, box);
  5595. }
  5596. getPathBoundingBox(pathType = PathType.FILL, transform = null) {
  5597. const box = [this.minX, this.minY, this.maxX, this.maxY];
  5598. if (pathType === PathType.STROKE) {
  5599. if (!transform) {
  5600. (0,util.unreachable)("Stroke bounding box must include transform.");
  5601. }
  5602. const scale = util.Util.singularValueDecompose2dScale(transform);
  5603. const xStrokePad = scale[0] * this.lineWidth / 2;
  5604. const yStrokePad = scale[1] * this.lineWidth / 2;
  5605. box[0] -= xStrokePad;
  5606. box[1] -= yStrokePad;
  5607. box[2] += xStrokePad;
  5608. box[3] += yStrokePad;
  5609. }
  5610. return box;
  5611. }
  5612. updateClipFromPath() {
  5613. const intersect = util.Util.intersect(this.clipBox, this.getPathBoundingBox());
  5614. this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
  5615. }
  5616. isEmptyClip() {
  5617. return this.minX === Infinity;
  5618. }
  5619. startNewPathAndClipBox(box) {
  5620. this.clipBox = box;
  5621. this.minX = Infinity;
  5622. this.minY = Infinity;
  5623. this.maxX = 0;
  5624. this.maxY = 0;
  5625. }
  5626. getClippedPathBoundingBox(pathType = PathType.FILL, transform = null) {
  5627. return util.Util.intersect(this.clipBox, this.getPathBoundingBox(pathType, transform));
  5628. }
  5629. }
  5630. function putBinaryImageData(ctx, imgData) {
  5631. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  5632. ctx.putImageData(imgData, 0, 0);
  5633. return;
  5634. }
  5635. const height = imgData.height,
  5636. width = imgData.width;
  5637. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  5638. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  5639. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  5640. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  5641. let srcPos = 0,
  5642. destPos;
  5643. const src = imgData.data;
  5644. const dest = chunkImgData.data;
  5645. let i, j, thisChunkHeight, elemsInThisChunk;
  5646. if (imgData.kind === util.ImageKind.GRAYSCALE_1BPP) {
  5647. const srcLength = src.byteLength;
  5648. const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  5649. const dest32DataLength = dest32.length;
  5650. const fullSrcDiff = width + 7 >> 3;
  5651. const white = 0xffffffff;
  5652. const black = util.FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  5653. for (i = 0; i < totalChunks; i++) {
  5654. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  5655. destPos = 0;
  5656. for (j = 0; j < thisChunkHeight; j++) {
  5657. const srcDiff = srcLength - srcPos;
  5658. let k = 0;
  5659. const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  5660. const kEndUnrolled = kEnd & ~7;
  5661. let mask = 0;
  5662. let srcByte = 0;
  5663. for (; k < kEndUnrolled; k += 8) {
  5664. srcByte = src[srcPos++];
  5665. dest32[destPos++] = srcByte & 128 ? white : black;
  5666. dest32[destPos++] = srcByte & 64 ? white : black;
  5667. dest32[destPos++] = srcByte & 32 ? white : black;
  5668. dest32[destPos++] = srcByte & 16 ? white : black;
  5669. dest32[destPos++] = srcByte & 8 ? white : black;
  5670. dest32[destPos++] = srcByte & 4 ? white : black;
  5671. dest32[destPos++] = srcByte & 2 ? white : black;
  5672. dest32[destPos++] = srcByte & 1 ? white : black;
  5673. }
  5674. for (; k < kEnd; k++) {
  5675. if (mask === 0) {
  5676. srcByte = src[srcPos++];
  5677. mask = 128;
  5678. }
  5679. dest32[destPos++] = srcByte & mask ? white : black;
  5680. mask >>= 1;
  5681. }
  5682. }
  5683. while (destPos < dest32DataLength) {
  5684. dest32[destPos++] = 0;
  5685. }
  5686. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5687. }
  5688. } else if (imgData.kind === util.ImageKind.RGBA_32BPP) {
  5689. j = 0;
  5690. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  5691. for (i = 0; i < fullChunks; i++) {
  5692. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  5693. srcPos += elemsInThisChunk;
  5694. ctx.putImageData(chunkImgData, 0, j);
  5695. j += FULL_CHUNK_HEIGHT;
  5696. }
  5697. if (i < totalChunks) {
  5698. elemsInThisChunk = width * partialChunkHeight * 4;
  5699. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  5700. ctx.putImageData(chunkImgData, 0, j);
  5701. }
  5702. } else if (imgData.kind === util.ImageKind.RGB_24BPP) {
  5703. thisChunkHeight = FULL_CHUNK_HEIGHT;
  5704. elemsInThisChunk = width * thisChunkHeight;
  5705. for (i = 0; i < totalChunks; i++) {
  5706. if (i >= fullChunks) {
  5707. thisChunkHeight = partialChunkHeight;
  5708. elemsInThisChunk = width * thisChunkHeight;
  5709. }
  5710. destPos = 0;
  5711. for (j = elemsInThisChunk; j--;) {
  5712. dest[destPos++] = src[srcPos++];
  5713. dest[destPos++] = src[srcPos++];
  5714. dest[destPos++] = src[srcPos++];
  5715. dest[destPos++] = 255;
  5716. }
  5717. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5718. }
  5719. } else {
  5720. throw new Error(`bad image kind: ${imgData.kind}`);
  5721. }
  5722. }
  5723. function putBinaryImageMask(ctx, imgData) {
  5724. if (imgData.bitmap) {
  5725. ctx.drawImage(imgData.bitmap, 0, 0);
  5726. return;
  5727. }
  5728. const height = imgData.height,
  5729. width = imgData.width;
  5730. const partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  5731. const fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  5732. const totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  5733. const chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  5734. let srcPos = 0;
  5735. const src = imgData.data;
  5736. const dest = chunkImgData.data;
  5737. for (let i = 0; i < totalChunks; i++) {
  5738. const thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  5739. ({
  5740. srcPos
  5741. } = convertBlackAndWhiteToRGBA({
  5742. src,
  5743. srcPos,
  5744. dest,
  5745. width,
  5746. height: thisChunkHeight,
  5747. nonBlackColor: 0
  5748. }));
  5749. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  5750. }
  5751. }
  5752. function copyCtxState(sourceCtx, destCtx) {
  5753. const properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font", "filter"];
  5754. for (const property of properties) {
  5755. if (sourceCtx[property] !== undefined) {
  5756. destCtx[property] = sourceCtx[property];
  5757. }
  5758. }
  5759. if (sourceCtx.setLineDash !== undefined) {
  5760. destCtx.setLineDash(sourceCtx.getLineDash());
  5761. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  5762. }
  5763. }
  5764. function resetCtxToDefault(ctx) {
  5765. ctx.strokeStyle = ctx.fillStyle = "#000000";
  5766. ctx.fillRule = "nonzero";
  5767. ctx.globalAlpha = 1;
  5768. ctx.lineWidth = 1;
  5769. ctx.lineCap = "butt";
  5770. ctx.lineJoin = "miter";
  5771. ctx.miterLimit = 10;
  5772. ctx.globalCompositeOperation = "source-over";
  5773. ctx.font = "10px sans-serif";
  5774. if (ctx.setLineDash !== undefined) {
  5775. ctx.setLineDash([]);
  5776. ctx.lineDashOffset = 0;
  5777. }
  5778. if (!util.isNodeJS) {
  5779. const {
  5780. filter
  5781. } = ctx;
  5782. if (filter !== "none" && filter !== "") {
  5783. ctx.filter = "none";
  5784. }
  5785. }
  5786. }
  5787. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  5788. const length = bytes.length;
  5789. for (let i = 3; i < length; i += 4) {
  5790. const alpha = bytes[i];
  5791. if (alpha === 0) {
  5792. bytes[i - 3] = r0;
  5793. bytes[i - 2] = g0;
  5794. bytes[i - 1] = b0;
  5795. } else if (alpha < 255) {
  5796. const alpha_ = 255 - alpha;
  5797. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  5798. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  5799. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  5800. }
  5801. }
  5802. }
  5803. function composeSMaskAlpha(maskData, layerData, transferMap) {
  5804. const length = maskData.length;
  5805. const scale = 1 / 255;
  5806. for (let i = 3; i < length; i += 4) {
  5807. const alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  5808. layerData[i] = layerData[i] * alpha * scale | 0;
  5809. }
  5810. }
  5811. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  5812. const length = maskData.length;
  5813. for (let i = 3; i < length; i += 4) {
  5814. const y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  5815. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  5816. }
  5817. }
  5818. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap, layerOffsetX, layerOffsetY, maskOffsetX, maskOffsetY) {
  5819. const hasBackdrop = !!backdrop;
  5820. const r0 = hasBackdrop ? backdrop[0] : 0;
  5821. const g0 = hasBackdrop ? backdrop[1] : 0;
  5822. const b0 = hasBackdrop ? backdrop[2] : 0;
  5823. const composeFn = subtype === "Luminosity" ? composeSMaskLuminosity : composeSMaskAlpha;
  5824. const PIXELS_TO_PROCESS = 1048576;
  5825. const chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  5826. for (let row = 0; row < height; row += chunkSize) {
  5827. const chunkHeight = Math.min(chunkSize, height - row);
  5828. const maskData = maskCtx.getImageData(layerOffsetX - maskOffsetX, row + (layerOffsetY - maskOffsetY), width, chunkHeight);
  5829. const layerData = layerCtx.getImageData(layerOffsetX, row + layerOffsetY, width, chunkHeight);
  5830. if (hasBackdrop) {
  5831. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  5832. }
  5833. composeFn(maskData.data, layerData.data, transferMap);
  5834. layerCtx.putImageData(layerData, layerOffsetX, row + layerOffsetY);
  5835. }
  5836. }
  5837. function composeSMask(ctx, smask, layerCtx, layerBox) {
  5838. const layerOffsetX = layerBox[0];
  5839. const layerOffsetY = layerBox[1];
  5840. const layerWidth = layerBox[2] - layerOffsetX;
  5841. const layerHeight = layerBox[3] - layerOffsetY;
  5842. if (layerWidth === 0 || layerHeight === 0) {
  5843. return;
  5844. }
  5845. genericComposeSMask(smask.context, layerCtx, layerWidth, layerHeight, smask.subtype, smask.backdrop, smask.transferMap, layerOffsetX, layerOffsetY, smask.offsetX, smask.offsetY);
  5846. ctx.save();
  5847. ctx.globalAlpha = 1;
  5848. ctx.globalCompositeOperation = "source-over";
  5849. ctx.setTransform(1, 0, 0, 1, 0, 0);
  5850. ctx.drawImage(layerCtx.canvas, 0, 0);
  5851. ctx.restore();
  5852. }
  5853. function getImageSmoothingEnabled(transform, interpolate) {
  5854. const scale = util.Util.singularValueDecompose2dScale(transform);
  5855. scale[0] = Math.fround(scale[0]);
  5856. scale[1] = Math.fround(scale[1]);
  5857. const actualScale = Math.fround((globalThis.devicePixelRatio || 1) * display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  5858. if (interpolate !== undefined) {
  5859. return interpolate;
  5860. } else if (scale[0] <= actualScale || scale[1] <= actualScale) {
  5861. return true;
  5862. }
  5863. return false;
  5864. }
  5865. const LINE_CAP_STYLES = ["butt", "round", "square"];
  5866. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  5867. const NORMAL_CLIP = {};
  5868. const EO_CLIP = {};
  5869. class CanvasGraphics {
  5870. constructor(canvasCtx, commonObjs, objs, canvasFactory, filterFactory, {
  5871. optionalContentConfig,
  5872. markedContentStack = null
  5873. }, annotationCanvasMap, pageColors) {
  5874. this.ctx = canvasCtx;
  5875. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  5876. this.stateStack = [];
  5877. this.pendingClip = null;
  5878. this.pendingEOFill = false;
  5879. this.res = null;
  5880. this.xobjs = null;
  5881. this.commonObjs = commonObjs;
  5882. this.objs = objs;
  5883. this.canvasFactory = canvasFactory;
  5884. this.filterFactory = filterFactory;
  5885. this.groupStack = [];
  5886. this.processingType3 = null;
  5887. this.baseTransform = null;
  5888. this.baseTransformStack = [];
  5889. this.groupLevel = 0;
  5890. this.smaskStack = [];
  5891. this.smaskCounter = 0;
  5892. this.tempSMask = null;
  5893. this.suspendedCtx = null;
  5894. this.contentVisible = true;
  5895. this.markedContentStack = markedContentStack || [];
  5896. this.optionalContentConfig = optionalContentConfig;
  5897. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  5898. this.cachedPatterns = new Map();
  5899. this.annotationCanvasMap = annotationCanvasMap;
  5900. this.viewportScale = 1;
  5901. this.outputScaleX = 1;
  5902. this.outputScaleY = 1;
  5903. this.pageColors = pageColors;
  5904. this._cachedScaleForStroking = [-1, 0];
  5905. this._cachedGetSinglePixelWidth = null;
  5906. this._cachedBitmapsMap = new Map();
  5907. }
  5908. getObject(data, fallback = null) {
  5909. if (typeof data === "string") {
  5910. return data.startsWith("g_") ? this.commonObjs.get(data) : this.objs.get(data);
  5911. }
  5912. return fallback;
  5913. }
  5914. beginDrawing({
  5915. transform,
  5916. viewport,
  5917. transparency = false,
  5918. background = null
  5919. }) {
  5920. const width = this.ctx.canvas.width;
  5921. const height = this.ctx.canvas.height;
  5922. const savedFillStyle = this.ctx.fillStyle;
  5923. this.ctx.fillStyle = background || "#ffffff";
  5924. this.ctx.fillRect(0, 0, width, height);
  5925. this.ctx.fillStyle = savedFillStyle;
  5926. if (transparency) {
  5927. const transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height);
  5928. this.compositeCtx = this.ctx;
  5929. this.transparentCanvas = transparentCanvas.canvas;
  5930. this.ctx = transparentCanvas.context;
  5931. this.ctx.save();
  5932. this.ctx.transform(...(0,display_utils.getCurrentTransform)(this.compositeCtx));
  5933. }
  5934. this.ctx.save();
  5935. resetCtxToDefault(this.ctx);
  5936. if (transform) {
  5937. this.ctx.transform(...transform);
  5938. this.outputScaleX = transform[0];
  5939. this.outputScaleY = transform[0];
  5940. }
  5941. this.ctx.transform(...viewport.transform);
  5942. this.viewportScale = viewport.scale;
  5943. this.baseTransform = (0,display_utils.getCurrentTransform)(this.ctx);
  5944. }
  5945. executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  5946. const argsArray = operatorList.argsArray;
  5947. const fnArray = operatorList.fnArray;
  5948. let i = executionStartIdx || 0;
  5949. const argsArrayLen = argsArray.length;
  5950. if (argsArrayLen === i) {
  5951. return i;
  5952. }
  5953. const chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  5954. const endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  5955. let steps = 0;
  5956. const commonObjs = this.commonObjs;
  5957. const objs = this.objs;
  5958. let fnId;
  5959. while (true) {
  5960. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  5961. stepper.breakIt(i, continueCallback);
  5962. return i;
  5963. }
  5964. fnId = fnArray[i];
  5965. if (fnId !== util.OPS.dependency) {
  5966. this[fnId].apply(this, argsArray[i]);
  5967. } else {
  5968. for (const depObjId of argsArray[i]) {
  5969. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  5970. if (!objsPool.has(depObjId)) {
  5971. objsPool.get(depObjId, continueCallback);
  5972. return i;
  5973. }
  5974. }
  5975. }
  5976. i++;
  5977. if (i === argsArrayLen) {
  5978. return i;
  5979. }
  5980. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  5981. if (Date.now() > endTime) {
  5982. continueCallback();
  5983. return i;
  5984. }
  5985. steps = 0;
  5986. }
  5987. }
  5988. }
  5989. #restoreInitialState() {
  5990. while (this.stateStack.length || this.inSMaskMode) {
  5991. this.restore();
  5992. }
  5993. this.ctx.restore();
  5994. if (this.transparentCanvas) {
  5995. this.ctx = this.compositeCtx;
  5996. this.ctx.save();
  5997. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  5998. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  5999. this.ctx.restore();
  6000. this.transparentCanvas = null;
  6001. }
  6002. }
  6003. endDrawing() {
  6004. this.#restoreInitialState();
  6005. this.cachedCanvases.clear();
  6006. this.cachedPatterns.clear();
  6007. for (const cache of this._cachedBitmapsMap.values()) {
  6008. for (const canvas of cache.values()) {
  6009. if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) {
  6010. canvas.width = canvas.height = 0;
  6011. }
  6012. }
  6013. cache.clear();
  6014. }
  6015. this._cachedBitmapsMap.clear();
  6016. this.#drawFilter();
  6017. }
  6018. #drawFilter() {
  6019. if (this.pageColors) {
  6020. const hcmFilterId = this.filterFactory.addHCMFilter(this.pageColors.foreground, this.pageColors.background);
  6021. if (hcmFilterId !== "none") {
  6022. const savedFilter = this.ctx.filter;
  6023. this.ctx.filter = hcmFilterId;
  6024. this.ctx.drawImage(this.ctx.canvas, 0, 0);
  6025. this.ctx.filter = savedFilter;
  6026. }
  6027. }
  6028. }
  6029. _scaleImage(img, inverseTransform) {
  6030. const width = img.width;
  6031. const height = img.height;
  6032. let widthScale = Math.max(Math.hypot(inverseTransform[0], inverseTransform[1]), 1);
  6033. let heightScale = Math.max(Math.hypot(inverseTransform[2], inverseTransform[3]), 1);
  6034. let paintWidth = width,
  6035. paintHeight = height;
  6036. let tmpCanvasId = "prescale1";
  6037. let tmpCanvas, tmpCtx;
  6038. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  6039. let newWidth = paintWidth,
  6040. newHeight = paintHeight;
  6041. if (widthScale > 2 && paintWidth > 1) {
  6042. newWidth = paintWidth >= 16384 ? Math.floor(paintWidth / 2) - 1 || 1 : Math.ceil(paintWidth / 2);
  6043. widthScale /= paintWidth / newWidth;
  6044. }
  6045. if (heightScale > 2 && paintHeight > 1) {
  6046. newHeight = paintHeight >= 16384 ? Math.floor(paintHeight / 2) - 1 || 1 : Math.ceil(paintHeight) / 2;
  6047. heightScale /= paintHeight / newHeight;
  6048. }
  6049. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  6050. tmpCtx = tmpCanvas.context;
  6051. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  6052. tmpCtx.drawImage(img, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  6053. img = tmpCanvas.canvas;
  6054. paintWidth = newWidth;
  6055. paintHeight = newHeight;
  6056. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  6057. }
  6058. return {
  6059. img,
  6060. paintWidth,
  6061. paintHeight
  6062. };
  6063. }
  6064. _createMaskCanvas(img) {
  6065. const ctx = this.ctx;
  6066. const {
  6067. width,
  6068. height
  6069. } = img;
  6070. const fillColor = this.current.fillColor;
  6071. const isPatternFill = this.current.patternFill;
  6072. const currentTransform = (0,display_utils.getCurrentTransform)(ctx);
  6073. let cache, cacheKey, scaled, maskCanvas;
  6074. if ((img.bitmap || img.data) && img.count > 1) {
  6075. const mainKey = img.bitmap || img.data.buffer;
  6076. cacheKey = JSON.stringify(isPatternFill ? currentTransform : [currentTransform.slice(0, 4), fillColor]);
  6077. cache = this._cachedBitmapsMap.get(mainKey);
  6078. if (!cache) {
  6079. cache = new Map();
  6080. this._cachedBitmapsMap.set(mainKey, cache);
  6081. }
  6082. const cachedImage = cache.get(cacheKey);
  6083. if (cachedImage && !isPatternFill) {
  6084. const offsetX = Math.round(Math.min(currentTransform[0], currentTransform[2]) + currentTransform[4]);
  6085. const offsetY = Math.round(Math.min(currentTransform[1], currentTransform[3]) + currentTransform[5]);
  6086. return {
  6087. canvas: cachedImage,
  6088. offsetX,
  6089. offsetY
  6090. };
  6091. }
  6092. scaled = cachedImage;
  6093. }
  6094. if (!scaled) {
  6095. maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  6096. putBinaryImageMask(maskCanvas.context, img);
  6097. }
  6098. let maskToCanvas = util.Util.transform(currentTransform, [1 / width, 0, 0, -1 / height, 0, 0]);
  6099. maskToCanvas = util.Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]);
  6100. const [minX, minY, maxX, maxY] = util.Util.getAxialAlignedBoundingBox([0, 0, width, height], maskToCanvas);
  6101. const drawnWidth = Math.round(maxX - minX) || 1;
  6102. const drawnHeight = Math.round(maxY - minY) || 1;
  6103. const fillCanvas = this.cachedCanvases.getCanvas("fillCanvas", drawnWidth, drawnHeight);
  6104. const fillCtx = fillCanvas.context;
  6105. const offsetX = minX;
  6106. const offsetY = minY;
  6107. fillCtx.translate(-offsetX, -offsetY);
  6108. fillCtx.transform(...maskToCanvas);
  6109. if (!scaled) {
  6110. scaled = this._scaleImage(maskCanvas.canvas, (0,display_utils.getCurrentTransformInverse)(fillCtx));
  6111. scaled = scaled.img;
  6112. if (cache && isPatternFill) {
  6113. cache.set(cacheKey, scaled);
  6114. }
  6115. }
  6116. fillCtx.imageSmoothingEnabled = getImageSmoothingEnabled((0,display_utils.getCurrentTransform)(fillCtx), img.interpolate);
  6117. drawImageAtIntegerCoords(fillCtx, scaled, 0, 0, scaled.width, scaled.height, 0, 0, width, height);
  6118. fillCtx.globalCompositeOperation = "source-in";
  6119. const inverse = util.Util.transform((0,display_utils.getCurrentTransformInverse)(fillCtx), [1, 0, 0, 1, -offsetX, -offsetY]);
  6120. fillCtx.fillStyle = isPatternFill ? fillColor.getPattern(ctx, this, inverse, PathType.FILL) : fillColor;
  6121. fillCtx.fillRect(0, 0, width, height);
  6122. if (cache && !isPatternFill) {
  6123. this.cachedCanvases.delete("fillCanvas");
  6124. cache.set(cacheKey, fillCanvas.canvas);
  6125. }
  6126. return {
  6127. canvas: fillCanvas.canvas,
  6128. offsetX: Math.round(offsetX),
  6129. offsetY: Math.round(offsetY)
  6130. };
  6131. }
  6132. setLineWidth(width) {
  6133. if (width !== this.current.lineWidth) {
  6134. this._cachedScaleForStroking[0] = -1;
  6135. }
  6136. this.current.lineWidth = width;
  6137. this.ctx.lineWidth = width;
  6138. }
  6139. setLineCap(style) {
  6140. this.ctx.lineCap = LINE_CAP_STYLES[style];
  6141. }
  6142. setLineJoin(style) {
  6143. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  6144. }
  6145. setMiterLimit(limit) {
  6146. this.ctx.miterLimit = limit;
  6147. }
  6148. setDash(dashArray, dashPhase) {
  6149. const ctx = this.ctx;
  6150. if (ctx.setLineDash !== undefined) {
  6151. ctx.setLineDash(dashArray);
  6152. ctx.lineDashOffset = dashPhase;
  6153. }
  6154. }
  6155. setRenderingIntent(intent) {}
  6156. setFlatness(flatness) {}
  6157. setGState(states) {
  6158. for (const [key, value] of states) {
  6159. switch (key) {
  6160. case "LW":
  6161. this.setLineWidth(value);
  6162. break;
  6163. case "LC":
  6164. this.setLineCap(value);
  6165. break;
  6166. case "LJ":
  6167. this.setLineJoin(value);
  6168. break;
  6169. case "ML":
  6170. this.setMiterLimit(value);
  6171. break;
  6172. case "D":
  6173. this.setDash(value[0], value[1]);
  6174. break;
  6175. case "RI":
  6176. this.setRenderingIntent(value);
  6177. break;
  6178. case "FL":
  6179. this.setFlatness(value);
  6180. break;
  6181. case "Font":
  6182. this.setFont(value[0], value[1]);
  6183. break;
  6184. case "CA":
  6185. this.current.strokeAlpha = value;
  6186. break;
  6187. case "ca":
  6188. this.current.fillAlpha = value;
  6189. this.ctx.globalAlpha = value;
  6190. break;
  6191. case "BM":
  6192. this.ctx.globalCompositeOperation = value;
  6193. break;
  6194. case "SMask":
  6195. this.current.activeSMask = value ? this.tempSMask : null;
  6196. this.tempSMask = null;
  6197. this.checkSMaskState();
  6198. break;
  6199. case "TR":
  6200. this.ctx.filter = this.current.transferMaps = this.filterFactory.addFilter(value);
  6201. break;
  6202. }
  6203. }
  6204. }
  6205. get inSMaskMode() {
  6206. return !!this.suspendedCtx;
  6207. }
  6208. checkSMaskState() {
  6209. const inSMaskMode = this.inSMaskMode;
  6210. if (this.current.activeSMask && !inSMaskMode) {
  6211. this.beginSMaskMode();
  6212. } else if (!this.current.activeSMask && inSMaskMode) {
  6213. this.endSMaskMode();
  6214. }
  6215. }
  6216. beginSMaskMode() {
  6217. if (this.inSMaskMode) {
  6218. throw new Error("beginSMaskMode called while already in smask mode");
  6219. }
  6220. const drawnWidth = this.ctx.canvas.width;
  6221. const drawnHeight = this.ctx.canvas.height;
  6222. const cacheId = "smaskGroupAt" + this.groupLevel;
  6223. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  6224. this.suspendedCtx = this.ctx;
  6225. this.ctx = scratchCanvas.context;
  6226. const ctx = this.ctx;
  6227. ctx.setTransform(...(0,display_utils.getCurrentTransform)(this.suspendedCtx));
  6228. copyCtxState(this.suspendedCtx, ctx);
  6229. mirrorContextOperations(ctx, this.suspendedCtx);
  6230. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  6231. }
  6232. endSMaskMode() {
  6233. if (!this.inSMaskMode) {
  6234. throw new Error("endSMaskMode called while not in smask mode");
  6235. }
  6236. this.ctx._removeMirroring();
  6237. copyCtxState(this.ctx, this.suspendedCtx);
  6238. this.ctx = this.suspendedCtx;
  6239. this.suspendedCtx = null;
  6240. }
  6241. compose(dirtyBox) {
  6242. if (!this.current.activeSMask) {
  6243. return;
  6244. }
  6245. if (!dirtyBox) {
  6246. dirtyBox = [0, 0, this.ctx.canvas.width, this.ctx.canvas.height];
  6247. } else {
  6248. dirtyBox[0] = Math.floor(dirtyBox[0]);
  6249. dirtyBox[1] = Math.floor(dirtyBox[1]);
  6250. dirtyBox[2] = Math.ceil(dirtyBox[2]);
  6251. dirtyBox[3] = Math.ceil(dirtyBox[3]);
  6252. }
  6253. const smask = this.current.activeSMask;
  6254. const suspendedCtx = this.suspendedCtx;
  6255. composeSMask(suspendedCtx, smask, this.ctx, dirtyBox);
  6256. this.ctx.save();
  6257. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  6258. this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
  6259. this.ctx.restore();
  6260. }
  6261. save() {
  6262. if (this.inSMaskMode) {
  6263. copyCtxState(this.ctx, this.suspendedCtx);
  6264. this.suspendedCtx.save();
  6265. } else {
  6266. this.ctx.save();
  6267. }
  6268. const old = this.current;
  6269. this.stateStack.push(old);
  6270. this.current = old.clone();
  6271. }
  6272. restore() {
  6273. if (this.stateStack.length === 0 && this.inSMaskMode) {
  6274. this.endSMaskMode();
  6275. }
  6276. if (this.stateStack.length !== 0) {
  6277. this.current = this.stateStack.pop();
  6278. if (this.inSMaskMode) {
  6279. this.suspendedCtx.restore();
  6280. copyCtxState(this.suspendedCtx, this.ctx);
  6281. } else {
  6282. this.ctx.restore();
  6283. }
  6284. this.checkSMaskState();
  6285. this.pendingClip = null;
  6286. this._cachedScaleForStroking[0] = -1;
  6287. this._cachedGetSinglePixelWidth = null;
  6288. }
  6289. }
  6290. transform(a, b, c, d, e, f) {
  6291. this.ctx.transform(a, b, c, d, e, f);
  6292. this._cachedScaleForStroking[0] = -1;
  6293. this._cachedGetSinglePixelWidth = null;
  6294. }
  6295. constructPath(ops, args, minMax) {
  6296. const ctx = this.ctx;
  6297. const current = this.current;
  6298. let x = current.x,
  6299. y = current.y;
  6300. let startX, startY;
  6301. const currentTransform = (0,display_utils.getCurrentTransform)(ctx);
  6302. const isScalingMatrix = currentTransform[0] === 0 && currentTransform[3] === 0 || currentTransform[1] === 0 && currentTransform[2] === 0;
  6303. const minMaxForBezier = isScalingMatrix ? minMax.slice(0) : null;
  6304. for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
  6305. switch (ops[i] | 0) {
  6306. case util.OPS.rectangle:
  6307. x = args[j++];
  6308. y = args[j++];
  6309. const width = args[j++];
  6310. const height = args[j++];
  6311. const xw = x + width;
  6312. const yh = y + height;
  6313. ctx.moveTo(x, y);
  6314. if (width === 0 || height === 0) {
  6315. ctx.lineTo(xw, yh);
  6316. } else {
  6317. ctx.lineTo(xw, y);
  6318. ctx.lineTo(xw, yh);
  6319. ctx.lineTo(x, yh);
  6320. }
  6321. if (!isScalingMatrix) {
  6322. current.updateRectMinMax(currentTransform, [x, y, xw, yh]);
  6323. }
  6324. ctx.closePath();
  6325. break;
  6326. case util.OPS.moveTo:
  6327. x = args[j++];
  6328. y = args[j++];
  6329. ctx.moveTo(x, y);
  6330. if (!isScalingMatrix) {
  6331. current.updatePathMinMax(currentTransform, x, y);
  6332. }
  6333. break;
  6334. case util.OPS.lineTo:
  6335. x = args[j++];
  6336. y = args[j++];
  6337. ctx.lineTo(x, y);
  6338. if (!isScalingMatrix) {
  6339. current.updatePathMinMax(currentTransform, x, y);
  6340. }
  6341. break;
  6342. case util.OPS.curveTo:
  6343. startX = x;
  6344. startY = y;
  6345. x = args[j + 4];
  6346. y = args[j + 5];
  6347. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  6348. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], args[j + 2], args[j + 3], x, y, minMaxForBezier);
  6349. j += 6;
  6350. break;
  6351. case util.OPS.curveTo2:
  6352. startX = x;
  6353. startY = y;
  6354. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  6355. current.updateCurvePathMinMax(currentTransform, startX, startY, x, y, args[j], args[j + 1], args[j + 2], args[j + 3], minMaxForBezier);
  6356. x = args[j + 2];
  6357. y = args[j + 3];
  6358. j += 4;
  6359. break;
  6360. case util.OPS.curveTo3:
  6361. startX = x;
  6362. startY = y;
  6363. x = args[j + 2];
  6364. y = args[j + 3];
  6365. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  6366. current.updateCurvePathMinMax(currentTransform, startX, startY, args[j], args[j + 1], x, y, x, y, minMaxForBezier);
  6367. j += 4;
  6368. break;
  6369. case util.OPS.closePath:
  6370. ctx.closePath();
  6371. break;
  6372. }
  6373. }
  6374. if (isScalingMatrix) {
  6375. current.updateScalingPathMinMax(currentTransform, minMaxForBezier);
  6376. }
  6377. current.setCurrentPoint(x, y);
  6378. }
  6379. closePath() {
  6380. this.ctx.closePath();
  6381. }
  6382. stroke(consumePath = true) {
  6383. const ctx = this.ctx;
  6384. const strokeColor = this.current.strokeColor;
  6385. ctx.globalAlpha = this.current.strokeAlpha;
  6386. if (this.contentVisible) {
  6387. if (typeof strokeColor === "object" && strokeColor?.getPattern) {
  6388. ctx.save();
  6389. ctx.strokeStyle = strokeColor.getPattern(ctx, this, (0,display_utils.getCurrentTransformInverse)(ctx), PathType.STROKE);
  6390. this.rescaleAndStroke(false);
  6391. ctx.restore();
  6392. } else {
  6393. this.rescaleAndStroke(true);
  6394. }
  6395. }
  6396. if (consumePath) {
  6397. this.consumePath(this.current.getClippedPathBoundingBox());
  6398. }
  6399. ctx.globalAlpha = this.current.fillAlpha;
  6400. }
  6401. closeStroke() {
  6402. this.closePath();
  6403. this.stroke();
  6404. }
  6405. fill(consumePath = true) {
  6406. const ctx = this.ctx;
  6407. const fillColor = this.current.fillColor;
  6408. const isPatternFill = this.current.patternFill;
  6409. let needRestore = false;
  6410. if (isPatternFill) {
  6411. ctx.save();
  6412. ctx.fillStyle = fillColor.getPattern(ctx, this, (0,display_utils.getCurrentTransformInverse)(ctx), PathType.FILL);
  6413. needRestore = true;
  6414. }
  6415. const intersect = this.current.getClippedPathBoundingBox();
  6416. if (this.contentVisible && intersect !== null) {
  6417. if (this.pendingEOFill) {
  6418. ctx.fill("evenodd");
  6419. this.pendingEOFill = false;
  6420. } else {
  6421. ctx.fill();
  6422. }
  6423. }
  6424. if (needRestore) {
  6425. ctx.restore();
  6426. }
  6427. if (consumePath) {
  6428. this.consumePath(intersect);
  6429. }
  6430. }
  6431. eoFill() {
  6432. this.pendingEOFill = true;
  6433. this.fill();
  6434. }
  6435. fillStroke() {
  6436. this.fill(false);
  6437. this.stroke(false);
  6438. this.consumePath();
  6439. }
  6440. eoFillStroke() {
  6441. this.pendingEOFill = true;
  6442. this.fillStroke();
  6443. }
  6444. closeFillStroke() {
  6445. this.closePath();
  6446. this.fillStroke();
  6447. }
  6448. closeEOFillStroke() {
  6449. this.pendingEOFill = true;
  6450. this.closePath();
  6451. this.fillStroke();
  6452. }
  6453. endPath() {
  6454. this.consumePath();
  6455. }
  6456. clip() {
  6457. this.pendingClip = NORMAL_CLIP;
  6458. }
  6459. eoClip() {
  6460. this.pendingClip = EO_CLIP;
  6461. }
  6462. beginText() {
  6463. this.current.textMatrix = util.IDENTITY_MATRIX;
  6464. this.current.textMatrixScale = 1;
  6465. this.current.x = this.current.lineX = 0;
  6466. this.current.y = this.current.lineY = 0;
  6467. }
  6468. endText() {
  6469. const paths = this.pendingTextPaths;
  6470. const ctx = this.ctx;
  6471. if (paths === undefined) {
  6472. ctx.beginPath();
  6473. return;
  6474. }
  6475. ctx.save();
  6476. ctx.beginPath();
  6477. for (const path of paths) {
  6478. ctx.setTransform(...path.transform);
  6479. ctx.translate(path.x, path.y);
  6480. path.addToPath(ctx, path.fontSize);
  6481. }
  6482. ctx.restore();
  6483. ctx.clip();
  6484. ctx.beginPath();
  6485. delete this.pendingTextPaths;
  6486. }
  6487. setCharSpacing(spacing) {
  6488. this.current.charSpacing = spacing;
  6489. }
  6490. setWordSpacing(spacing) {
  6491. this.current.wordSpacing = spacing;
  6492. }
  6493. setHScale(scale) {
  6494. this.current.textHScale = scale / 100;
  6495. }
  6496. setLeading(leading) {
  6497. this.current.leading = -leading;
  6498. }
  6499. setFont(fontRefName, size) {
  6500. const fontObj = this.commonObjs.get(fontRefName);
  6501. const current = this.current;
  6502. if (!fontObj) {
  6503. throw new Error(`Can't find font for ${fontRefName}`);
  6504. }
  6505. current.fontMatrix = fontObj.fontMatrix || util.FONT_IDENTITY_MATRIX;
  6506. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  6507. (0,util.warn)("Invalid font matrix for font " + fontRefName);
  6508. }
  6509. if (size < 0) {
  6510. size = -size;
  6511. current.fontDirection = -1;
  6512. } else {
  6513. current.fontDirection = 1;
  6514. }
  6515. this.current.font = fontObj;
  6516. this.current.fontSize = size;
  6517. if (fontObj.isType3Font) {
  6518. return;
  6519. }
  6520. const name = fontObj.loadedName || "sans-serif";
  6521. const typeface = fontObj.systemFontInfo?.css || `"${name}", ${fontObj.fallbackName}`;
  6522. let bold = "normal";
  6523. if (fontObj.black) {
  6524. bold = "900";
  6525. } else if (fontObj.bold) {
  6526. bold = "bold";
  6527. }
  6528. const italic = fontObj.italic ? "italic" : "normal";
  6529. let browserFontSize = size;
  6530. if (size < MIN_FONT_SIZE) {
  6531. browserFontSize = MIN_FONT_SIZE;
  6532. } else if (size > MAX_FONT_SIZE) {
  6533. browserFontSize = MAX_FONT_SIZE;
  6534. }
  6535. this.current.fontSizeScale = size / browserFontSize;
  6536. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  6537. }
  6538. setTextRenderingMode(mode) {
  6539. this.current.textRenderingMode = mode;
  6540. }
  6541. setTextRise(rise) {
  6542. this.current.textRise = rise;
  6543. }
  6544. moveText(x, y) {
  6545. this.current.x = this.current.lineX += x;
  6546. this.current.y = this.current.lineY += y;
  6547. }
  6548. setLeadingMoveText(x, y) {
  6549. this.setLeading(-y);
  6550. this.moveText(x, y);
  6551. }
  6552. setTextMatrix(a, b, c, d, e, f) {
  6553. this.current.textMatrix = [a, b, c, d, e, f];
  6554. this.current.textMatrixScale = Math.hypot(a, b);
  6555. this.current.x = this.current.lineX = 0;
  6556. this.current.y = this.current.lineY = 0;
  6557. }
  6558. nextLine() {
  6559. this.moveText(0, this.current.leading);
  6560. }
  6561. paintChar(character, x, y, patternTransform) {
  6562. const ctx = this.ctx;
  6563. const current = this.current;
  6564. const font = current.font;
  6565. const textRenderingMode = current.textRenderingMode;
  6566. const fontSize = current.fontSize / current.fontSizeScale;
  6567. const fillStrokeMode = textRenderingMode & util.TextRenderingMode.FILL_STROKE_MASK;
  6568. const isAddToPathSet = !!(textRenderingMode & util.TextRenderingMode.ADD_TO_PATH_FLAG);
  6569. const patternFill = current.patternFill && !font.missingFile;
  6570. let addToPath;
  6571. if (font.disableFontFace || isAddToPathSet || patternFill) {
  6572. addToPath = font.getPathGenerator(this.commonObjs, character);
  6573. }
  6574. if (font.disableFontFace || patternFill) {
  6575. ctx.save();
  6576. ctx.translate(x, y);
  6577. ctx.beginPath();
  6578. addToPath(ctx, fontSize);
  6579. if (patternTransform) {
  6580. ctx.setTransform(...patternTransform);
  6581. }
  6582. if (fillStrokeMode === util.TextRenderingMode.FILL || fillStrokeMode === util.TextRenderingMode.FILL_STROKE) {
  6583. ctx.fill();
  6584. }
  6585. if (fillStrokeMode === util.TextRenderingMode.STROKE || fillStrokeMode === util.TextRenderingMode.FILL_STROKE) {
  6586. ctx.stroke();
  6587. }
  6588. ctx.restore();
  6589. } else {
  6590. if (fillStrokeMode === util.TextRenderingMode.FILL || fillStrokeMode === util.TextRenderingMode.FILL_STROKE) {
  6591. ctx.fillText(character, x, y);
  6592. }
  6593. if (fillStrokeMode === util.TextRenderingMode.STROKE || fillStrokeMode === util.TextRenderingMode.FILL_STROKE) {
  6594. ctx.strokeText(character, x, y);
  6595. }
  6596. }
  6597. if (isAddToPathSet) {
  6598. const paths = this.pendingTextPaths ||= [];
  6599. paths.push({
  6600. transform: (0,display_utils.getCurrentTransform)(ctx),
  6601. x,
  6602. y,
  6603. fontSize,
  6604. addToPath
  6605. });
  6606. }
  6607. }
  6608. get isFontSubpixelAAEnabled() {
  6609. const {
  6610. context: ctx
  6611. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
  6612. ctx.scale(1.5, 1);
  6613. ctx.fillText("I", 0, 10);
  6614. const data = ctx.getImageData(0, 0, 10, 10).data;
  6615. let enabled = false;
  6616. for (let i = 3; i < data.length; i += 4) {
  6617. if (data[i] > 0 && data[i] < 255) {
  6618. enabled = true;
  6619. break;
  6620. }
  6621. }
  6622. return (0,util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  6623. }
  6624. showText(glyphs) {
  6625. const current = this.current;
  6626. const font = current.font;
  6627. if (font.isType3Font) {
  6628. return this.showType3Text(glyphs);
  6629. }
  6630. const fontSize = current.fontSize;
  6631. if (fontSize === 0) {
  6632. return undefined;
  6633. }
  6634. const ctx = this.ctx;
  6635. const fontSizeScale = current.fontSizeScale;
  6636. const charSpacing = current.charSpacing;
  6637. const wordSpacing = current.wordSpacing;
  6638. const fontDirection = current.fontDirection;
  6639. const textHScale = current.textHScale * fontDirection;
  6640. const glyphsLength = glyphs.length;
  6641. const vertical = font.vertical;
  6642. const spacingDir = vertical ? 1 : -1;
  6643. const defaultVMetrics = font.defaultVMetrics;
  6644. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  6645. const simpleFillText = current.textRenderingMode === util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  6646. ctx.save();
  6647. ctx.transform(...current.textMatrix);
  6648. ctx.translate(current.x, current.y + current.textRise);
  6649. if (fontDirection > 0) {
  6650. ctx.scale(textHScale, -1);
  6651. } else {
  6652. ctx.scale(textHScale, 1);
  6653. }
  6654. let patternTransform;
  6655. if (current.patternFill) {
  6656. ctx.save();
  6657. const pattern = current.fillColor.getPattern(ctx, this, (0,display_utils.getCurrentTransformInverse)(ctx), PathType.FILL);
  6658. patternTransform = (0,display_utils.getCurrentTransform)(ctx);
  6659. ctx.restore();
  6660. ctx.fillStyle = pattern;
  6661. }
  6662. let lineWidth = current.lineWidth;
  6663. const scale = current.textMatrixScale;
  6664. if (scale === 0 || lineWidth === 0) {
  6665. const fillStrokeMode = current.textRenderingMode & util.TextRenderingMode.FILL_STROKE_MASK;
  6666. if (fillStrokeMode === util.TextRenderingMode.STROKE || fillStrokeMode === util.TextRenderingMode.FILL_STROKE) {
  6667. lineWidth = this.getSinglePixelWidth();
  6668. }
  6669. } else {
  6670. lineWidth /= scale;
  6671. }
  6672. if (fontSizeScale !== 1.0) {
  6673. ctx.scale(fontSizeScale, fontSizeScale);
  6674. lineWidth /= fontSizeScale;
  6675. }
  6676. ctx.lineWidth = lineWidth;
  6677. if (font.isInvalidPDFjsFont) {
  6678. const chars = [];
  6679. let width = 0;
  6680. for (const glyph of glyphs) {
  6681. chars.push(glyph.unicode);
  6682. width += glyph.width;
  6683. }
  6684. ctx.fillText(chars.join(""), 0, 0);
  6685. current.x += width * widthAdvanceScale * textHScale;
  6686. ctx.restore();
  6687. this.compose();
  6688. return undefined;
  6689. }
  6690. let x = 0,
  6691. i;
  6692. for (i = 0; i < glyphsLength; ++i) {
  6693. const glyph = glyphs[i];
  6694. if (typeof glyph === "number") {
  6695. x += spacingDir * glyph * fontSize / 1000;
  6696. continue;
  6697. }
  6698. let restoreNeeded = false;
  6699. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  6700. const character = glyph.fontChar;
  6701. const accent = glyph.accent;
  6702. let scaledX, scaledY;
  6703. let width = glyph.width;
  6704. if (vertical) {
  6705. const vmetric = glyph.vmetric || defaultVMetrics;
  6706. const vx = -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
  6707. const vy = vmetric[2] * widthAdvanceScale;
  6708. width = vmetric ? -vmetric[0] : width;
  6709. scaledX = vx / fontSizeScale;
  6710. scaledY = (x + vy) / fontSizeScale;
  6711. } else {
  6712. scaledX = x / fontSizeScale;
  6713. scaledY = 0;
  6714. }
  6715. if (font.remeasure && width > 0) {
  6716. const measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  6717. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  6718. const characterScaleX = width / measuredWidth;
  6719. restoreNeeded = true;
  6720. ctx.save();
  6721. ctx.scale(characterScaleX, 1);
  6722. scaledX /= characterScaleX;
  6723. } else if (width !== measuredWidth) {
  6724. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  6725. }
  6726. }
  6727. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  6728. if (simpleFillText && !accent) {
  6729. ctx.fillText(character, scaledX, scaledY);
  6730. } else {
  6731. this.paintChar(character, scaledX, scaledY, patternTransform);
  6732. if (accent) {
  6733. const scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  6734. const scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  6735. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
  6736. }
  6737. }
  6738. }
  6739. const charWidth = vertical ? width * widthAdvanceScale - spacing * fontDirection : width * widthAdvanceScale + spacing * fontDirection;
  6740. x += charWidth;
  6741. if (restoreNeeded) {
  6742. ctx.restore();
  6743. }
  6744. }
  6745. if (vertical) {
  6746. current.y -= x;
  6747. } else {
  6748. current.x += x * textHScale;
  6749. }
  6750. ctx.restore();
  6751. this.compose();
  6752. return undefined;
  6753. }
  6754. showType3Text(glyphs) {
  6755. const ctx = this.ctx;
  6756. const current = this.current;
  6757. const font = current.font;
  6758. const fontSize = current.fontSize;
  6759. const fontDirection = current.fontDirection;
  6760. const spacingDir = font.vertical ? 1 : -1;
  6761. const charSpacing = current.charSpacing;
  6762. const wordSpacing = current.wordSpacing;
  6763. const textHScale = current.textHScale * fontDirection;
  6764. const fontMatrix = current.fontMatrix || util.FONT_IDENTITY_MATRIX;
  6765. const glyphsLength = glyphs.length;
  6766. const isTextInvisible = current.textRenderingMode === util.TextRenderingMode.INVISIBLE;
  6767. let i, glyph, width, spacingLength;
  6768. if (isTextInvisible || fontSize === 0) {
  6769. return;
  6770. }
  6771. this._cachedScaleForStroking[0] = -1;
  6772. this._cachedGetSinglePixelWidth = null;
  6773. ctx.save();
  6774. ctx.transform(...current.textMatrix);
  6775. ctx.translate(current.x, current.y);
  6776. ctx.scale(textHScale, fontDirection);
  6777. for (i = 0; i < glyphsLength; ++i) {
  6778. glyph = glyphs[i];
  6779. if (typeof glyph === "number") {
  6780. spacingLength = spacingDir * glyph * fontSize / 1000;
  6781. this.ctx.translate(spacingLength, 0);
  6782. current.x += spacingLength * textHScale;
  6783. continue;
  6784. }
  6785. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  6786. const operatorList = font.charProcOperatorList[glyph.operatorListId];
  6787. if (!operatorList) {
  6788. (0,util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  6789. continue;
  6790. }
  6791. if (this.contentVisible) {
  6792. this.processingType3 = glyph;
  6793. this.save();
  6794. ctx.scale(fontSize, fontSize);
  6795. ctx.transform(...fontMatrix);
  6796. this.executeOperatorList(operatorList);
  6797. this.restore();
  6798. }
  6799. const transformed = util.Util.applyTransform([glyph.width, 0], fontMatrix);
  6800. width = transformed[0] * fontSize + spacing;
  6801. ctx.translate(width, 0);
  6802. current.x += width * textHScale;
  6803. }
  6804. ctx.restore();
  6805. this.processingType3 = null;
  6806. }
  6807. setCharWidth(xWidth, yWidth) {}
  6808. setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  6809. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  6810. this.ctx.clip();
  6811. this.endPath();
  6812. }
  6813. getColorN_Pattern(IR) {
  6814. let pattern;
  6815. if (IR[0] === "TilingPattern") {
  6816. const color = IR[1];
  6817. const baseTransform = this.baseTransform || (0,display_utils.getCurrentTransform)(this.ctx);
  6818. const canvasGraphicsFactory = {
  6819. createCanvasGraphics: ctx => {
  6820. return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory, this.filterFactory, {
  6821. optionalContentConfig: this.optionalContentConfig,
  6822. markedContentStack: this.markedContentStack
  6823. });
  6824. }
  6825. };
  6826. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  6827. } else {
  6828. pattern = this._getPattern(IR[1], IR[2]);
  6829. }
  6830. return pattern;
  6831. }
  6832. setStrokeColorN() {
  6833. this.current.strokeColor = this.getColorN_Pattern(arguments);
  6834. }
  6835. setFillColorN() {
  6836. this.current.fillColor = this.getColorN_Pattern(arguments);
  6837. this.current.patternFill = true;
  6838. }
  6839. setStrokeRGBColor(r, g, b) {
  6840. const color = util.Util.makeHexColor(r, g, b);
  6841. this.ctx.strokeStyle = color;
  6842. this.current.strokeColor = color;
  6843. }
  6844. setFillRGBColor(r, g, b) {
  6845. const color = util.Util.makeHexColor(r, g, b);
  6846. this.ctx.fillStyle = color;
  6847. this.current.fillColor = color;
  6848. this.current.patternFill = false;
  6849. }
  6850. _getPattern(objId, matrix = null) {
  6851. let pattern;
  6852. if (this.cachedPatterns.has(objId)) {
  6853. pattern = this.cachedPatterns.get(objId);
  6854. } else {
  6855. pattern = getShadingPattern(this.getObject(objId));
  6856. this.cachedPatterns.set(objId, pattern);
  6857. }
  6858. if (matrix) {
  6859. pattern.matrix = matrix;
  6860. }
  6861. return pattern;
  6862. }
  6863. shadingFill(objId) {
  6864. if (!this.contentVisible) {
  6865. return;
  6866. }
  6867. const ctx = this.ctx;
  6868. this.save();
  6869. const pattern = this._getPattern(objId);
  6870. ctx.fillStyle = pattern.getPattern(ctx, this, (0,display_utils.getCurrentTransformInverse)(ctx), PathType.SHADING);
  6871. const inv = (0,display_utils.getCurrentTransformInverse)(ctx);
  6872. if (inv) {
  6873. const {
  6874. width,
  6875. height
  6876. } = ctx.canvas;
  6877. const [x0, y0, x1, y1] = util.Util.getAxialAlignedBoundingBox([0, 0, width, height], inv);
  6878. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  6879. } else {
  6880. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  6881. }
  6882. this.compose(this.current.getClippedPathBoundingBox());
  6883. this.restore();
  6884. }
  6885. beginInlineImage() {
  6886. (0,util.unreachable)("Should not call beginInlineImage");
  6887. }
  6888. beginImageData() {
  6889. (0,util.unreachable)("Should not call beginImageData");
  6890. }
  6891. paintFormXObjectBegin(matrix, bbox) {
  6892. if (!this.contentVisible) {
  6893. return;
  6894. }
  6895. this.save();
  6896. this.baseTransformStack.push(this.baseTransform);
  6897. if (Array.isArray(matrix) && matrix.length === 6) {
  6898. this.transform(...matrix);
  6899. }
  6900. this.baseTransform = (0,display_utils.getCurrentTransform)(this.ctx);
  6901. if (bbox) {
  6902. const width = bbox[2] - bbox[0];
  6903. const height = bbox[3] - bbox[1];
  6904. this.ctx.rect(bbox[0], bbox[1], width, height);
  6905. this.current.updateRectMinMax((0,display_utils.getCurrentTransform)(this.ctx), bbox);
  6906. this.clip();
  6907. this.endPath();
  6908. }
  6909. }
  6910. paintFormXObjectEnd() {
  6911. if (!this.contentVisible) {
  6912. return;
  6913. }
  6914. this.restore();
  6915. this.baseTransform = this.baseTransformStack.pop();
  6916. }
  6917. beginGroup(group) {
  6918. if (!this.contentVisible) {
  6919. return;
  6920. }
  6921. this.save();
  6922. if (this.inSMaskMode) {
  6923. this.endSMaskMode();
  6924. this.current.activeSMask = null;
  6925. }
  6926. const currentCtx = this.ctx;
  6927. if (!group.isolated) {
  6928. (0,util.info)("TODO: Support non-isolated groups.");
  6929. }
  6930. if (group.knockout) {
  6931. (0,util.warn)("Knockout groups not supported.");
  6932. }
  6933. const currentTransform = (0,display_utils.getCurrentTransform)(currentCtx);
  6934. if (group.matrix) {
  6935. currentCtx.transform(...group.matrix);
  6936. }
  6937. if (!group.bbox) {
  6938. throw new Error("Bounding box is required.");
  6939. }
  6940. let bounds = util.Util.getAxialAlignedBoundingBox(group.bbox, (0,display_utils.getCurrentTransform)(currentCtx));
  6941. const canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  6942. bounds = util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  6943. const offsetX = Math.floor(bounds[0]);
  6944. const offsetY = Math.floor(bounds[1]);
  6945. let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  6946. let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  6947. let scaleX = 1,
  6948. scaleY = 1;
  6949. if (drawnWidth > MAX_GROUP_SIZE) {
  6950. scaleX = drawnWidth / MAX_GROUP_SIZE;
  6951. drawnWidth = MAX_GROUP_SIZE;
  6952. }
  6953. if (drawnHeight > MAX_GROUP_SIZE) {
  6954. scaleY = drawnHeight / MAX_GROUP_SIZE;
  6955. drawnHeight = MAX_GROUP_SIZE;
  6956. }
  6957. this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]);
  6958. let cacheId = "groupAt" + this.groupLevel;
  6959. if (group.smask) {
  6960. cacheId += "_smask_" + this.smaskCounter++ % 2;
  6961. }
  6962. const scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight);
  6963. const groupCtx = scratchCanvas.context;
  6964. groupCtx.scale(1 / scaleX, 1 / scaleY);
  6965. groupCtx.translate(-offsetX, -offsetY);
  6966. groupCtx.transform(...currentTransform);
  6967. if (group.smask) {
  6968. this.smaskStack.push({
  6969. canvas: scratchCanvas.canvas,
  6970. context: groupCtx,
  6971. offsetX,
  6972. offsetY,
  6973. scaleX,
  6974. scaleY,
  6975. subtype: group.smask.subtype,
  6976. backdrop: group.smask.backdrop,
  6977. transferMap: group.smask.transferMap || null,
  6978. startTransformInverse: null
  6979. });
  6980. } else {
  6981. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  6982. currentCtx.translate(offsetX, offsetY);
  6983. currentCtx.scale(scaleX, scaleY);
  6984. currentCtx.save();
  6985. }
  6986. copyCtxState(currentCtx, groupCtx);
  6987. this.ctx = groupCtx;
  6988. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  6989. this.groupStack.push(currentCtx);
  6990. this.groupLevel++;
  6991. }
  6992. endGroup(group) {
  6993. if (!this.contentVisible) {
  6994. return;
  6995. }
  6996. this.groupLevel--;
  6997. const groupCtx = this.ctx;
  6998. const ctx = this.groupStack.pop();
  6999. this.ctx = ctx;
  7000. this.ctx.imageSmoothingEnabled = false;
  7001. if (group.smask) {
  7002. this.tempSMask = this.smaskStack.pop();
  7003. this.restore();
  7004. } else {
  7005. this.ctx.restore();
  7006. const currentMtx = (0,display_utils.getCurrentTransform)(this.ctx);
  7007. this.restore();
  7008. this.ctx.save();
  7009. this.ctx.setTransform(...currentMtx);
  7010. const dirtyBox = util.Util.getAxialAlignedBoundingBox([0, 0, groupCtx.canvas.width, groupCtx.canvas.height], currentMtx);
  7011. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  7012. this.ctx.restore();
  7013. this.compose(dirtyBox);
  7014. }
  7015. }
  7016. beginAnnotation(id, rect, transform, matrix, hasOwnCanvas) {
  7017. this.#restoreInitialState();
  7018. resetCtxToDefault(this.ctx);
  7019. this.ctx.save();
  7020. this.save();
  7021. if (this.baseTransform) {
  7022. this.ctx.setTransform(...this.baseTransform);
  7023. }
  7024. if (Array.isArray(rect) && rect.length === 4) {
  7025. const width = rect[2] - rect[0];
  7026. const height = rect[3] - rect[1];
  7027. if (hasOwnCanvas && this.annotationCanvasMap) {
  7028. transform = transform.slice();
  7029. transform[4] -= rect[0];
  7030. transform[5] -= rect[1];
  7031. rect = rect.slice();
  7032. rect[0] = rect[1] = 0;
  7033. rect[2] = width;
  7034. rect[3] = height;
  7035. const [scaleX, scaleY] = util.Util.singularValueDecompose2dScale((0,display_utils.getCurrentTransform)(this.ctx));
  7036. const {
  7037. viewportScale
  7038. } = this;
  7039. const canvasWidth = Math.ceil(width * this.outputScaleX * viewportScale);
  7040. const canvasHeight = Math.ceil(height * this.outputScaleY * viewportScale);
  7041. this.annotationCanvas = this.canvasFactory.create(canvasWidth, canvasHeight);
  7042. const {
  7043. canvas,
  7044. context
  7045. } = this.annotationCanvas;
  7046. this.annotationCanvasMap.set(id, canvas);
  7047. this.annotationCanvas.savedCtx = this.ctx;
  7048. this.ctx = context;
  7049. this.ctx.save();
  7050. this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
  7051. resetCtxToDefault(this.ctx);
  7052. } else {
  7053. resetCtxToDefault(this.ctx);
  7054. this.ctx.rect(rect[0], rect[1], width, height);
  7055. this.ctx.clip();
  7056. this.endPath();
  7057. }
  7058. }
  7059. this.current = new CanvasExtraState(this.ctx.canvas.width, this.ctx.canvas.height);
  7060. this.transform(...transform);
  7061. this.transform(...matrix);
  7062. }
  7063. endAnnotation() {
  7064. if (this.annotationCanvas) {
  7065. this.ctx.restore();
  7066. this.#drawFilter();
  7067. this.ctx = this.annotationCanvas.savedCtx;
  7068. delete this.annotationCanvas.savedCtx;
  7069. delete this.annotationCanvas;
  7070. }
  7071. }
  7072. paintImageMaskXObject(img) {
  7073. if (!this.contentVisible) {
  7074. return;
  7075. }
  7076. const count = img.count;
  7077. img = this.getObject(img.data, img);
  7078. img.count = count;
  7079. const ctx = this.ctx;
  7080. const glyph = this.processingType3;
  7081. if (glyph) {
  7082. if (glyph.compiled === undefined) {
  7083. glyph.compiled = compileType3Glyph(img);
  7084. }
  7085. if (glyph.compiled) {
  7086. glyph.compiled(ctx);
  7087. return;
  7088. }
  7089. }
  7090. const mask = this._createMaskCanvas(img);
  7091. const maskCanvas = mask.canvas;
  7092. ctx.save();
  7093. ctx.setTransform(1, 0, 0, 1, 0, 0);
  7094. ctx.drawImage(maskCanvas, mask.offsetX, mask.offsetY);
  7095. ctx.restore();
  7096. this.compose();
  7097. }
  7098. paintImageMaskXObjectRepeat(img, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
  7099. if (!this.contentVisible) {
  7100. return;
  7101. }
  7102. img = this.getObject(img.data, img);
  7103. const ctx = this.ctx;
  7104. ctx.save();
  7105. const currentTransform = (0,display_utils.getCurrentTransform)(ctx);
  7106. ctx.transform(scaleX, skewX, skewY, scaleY, 0, 0);
  7107. const mask = this._createMaskCanvas(img);
  7108. ctx.setTransform(1, 0, 0, 1, mask.offsetX - currentTransform[4], mask.offsetY - currentTransform[5]);
  7109. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  7110. const trans = util.Util.transform(currentTransform, [scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]]);
  7111. const [x, y] = util.Util.applyTransform([0, 0], trans);
  7112. ctx.drawImage(mask.canvas, x, y);
  7113. }
  7114. ctx.restore();
  7115. this.compose();
  7116. }
  7117. paintImageMaskXObjectGroup(images) {
  7118. if (!this.contentVisible) {
  7119. return;
  7120. }
  7121. const ctx = this.ctx;
  7122. const fillColor = this.current.fillColor;
  7123. const isPatternFill = this.current.patternFill;
  7124. for (const image of images) {
  7125. const {
  7126. data,
  7127. width,
  7128. height,
  7129. transform
  7130. } = image;
  7131. const maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  7132. const maskCtx = maskCanvas.context;
  7133. maskCtx.save();
  7134. const img = this.getObject(data, image);
  7135. putBinaryImageMask(maskCtx, img);
  7136. maskCtx.globalCompositeOperation = "source-in";
  7137. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this, (0,display_utils.getCurrentTransformInverse)(ctx), PathType.FILL) : fillColor;
  7138. maskCtx.fillRect(0, 0, width, height);
  7139. maskCtx.restore();
  7140. ctx.save();
  7141. ctx.transform(...transform);
  7142. ctx.scale(1, -1);
  7143. drawImageAtIntegerCoords(ctx, maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  7144. ctx.restore();
  7145. }
  7146. this.compose();
  7147. }
  7148. paintImageXObject(objId) {
  7149. if (!this.contentVisible) {
  7150. return;
  7151. }
  7152. const imgData = this.getObject(objId);
  7153. if (!imgData) {
  7154. (0,util.warn)("Dependent image isn't ready yet");
  7155. return;
  7156. }
  7157. this.paintInlineImageXObject(imgData);
  7158. }
  7159. paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  7160. if (!this.contentVisible) {
  7161. return;
  7162. }
  7163. const imgData = this.getObject(objId);
  7164. if (!imgData) {
  7165. (0,util.warn)("Dependent image isn't ready yet");
  7166. return;
  7167. }
  7168. const width = imgData.width;
  7169. const height = imgData.height;
  7170. const map = [];
  7171. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  7172. map.push({
  7173. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  7174. x: 0,
  7175. y: 0,
  7176. w: width,
  7177. h: height
  7178. });
  7179. }
  7180. this.paintInlineImageXObjectGroup(imgData, map);
  7181. }
  7182. applyTransferMapsToCanvas(ctx) {
  7183. if (this.current.transferMaps !== "none") {
  7184. ctx.filter = this.current.transferMaps;
  7185. ctx.drawImage(ctx.canvas, 0, 0);
  7186. ctx.filter = "none";
  7187. }
  7188. return ctx.canvas;
  7189. }
  7190. applyTransferMapsToBitmap(imgData) {
  7191. if (this.current.transferMaps === "none") {
  7192. return imgData.bitmap;
  7193. }
  7194. const {
  7195. bitmap,
  7196. width,
  7197. height
  7198. } = imgData;
  7199. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  7200. const tmpCtx = tmpCanvas.context;
  7201. tmpCtx.filter = this.current.transferMaps;
  7202. tmpCtx.drawImage(bitmap, 0, 0);
  7203. tmpCtx.filter = "none";
  7204. return tmpCanvas.canvas;
  7205. }
  7206. paintInlineImageXObject(imgData) {
  7207. if (!this.contentVisible) {
  7208. return;
  7209. }
  7210. const width = imgData.width;
  7211. const height = imgData.height;
  7212. const ctx = this.ctx;
  7213. this.save();
  7214. if (!util.isNodeJS) {
  7215. const {
  7216. filter
  7217. } = ctx;
  7218. if (filter !== "none" && filter !== "") {
  7219. ctx.filter = "none";
  7220. }
  7221. }
  7222. ctx.scale(1 / width, -1 / height);
  7223. let imgToPaint;
  7224. if (imgData.bitmap) {
  7225. imgToPaint = this.applyTransferMapsToBitmap(imgData);
  7226. } else if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  7227. imgToPaint = imgData;
  7228. } else {
  7229. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  7230. const tmpCtx = tmpCanvas.context;
  7231. putBinaryImageData(tmpCtx, imgData);
  7232. imgToPaint = this.applyTransferMapsToCanvas(tmpCtx);
  7233. }
  7234. const scaled = this._scaleImage(imgToPaint, (0,display_utils.getCurrentTransformInverse)(ctx));
  7235. ctx.imageSmoothingEnabled = getImageSmoothingEnabled((0,display_utils.getCurrentTransform)(ctx), imgData.interpolate);
  7236. drawImageAtIntegerCoords(ctx, scaled.img, 0, 0, scaled.paintWidth, scaled.paintHeight, 0, -height, width, height);
  7237. this.compose();
  7238. this.restore();
  7239. }
  7240. paintInlineImageXObjectGroup(imgData, map) {
  7241. if (!this.contentVisible) {
  7242. return;
  7243. }
  7244. const ctx = this.ctx;
  7245. let imgToPaint;
  7246. if (imgData.bitmap) {
  7247. imgToPaint = imgData.bitmap;
  7248. } else {
  7249. const w = imgData.width;
  7250. const h = imgData.height;
  7251. const tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  7252. const tmpCtx = tmpCanvas.context;
  7253. putBinaryImageData(tmpCtx, imgData);
  7254. imgToPaint = this.applyTransferMapsToCanvas(tmpCtx);
  7255. }
  7256. for (const entry of map) {
  7257. ctx.save();
  7258. ctx.transform(...entry.transform);
  7259. ctx.scale(1, -1);
  7260. drawImageAtIntegerCoords(ctx, imgToPaint, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  7261. ctx.restore();
  7262. }
  7263. this.compose();
  7264. }
  7265. paintSolidColorImageMask() {
  7266. if (!this.contentVisible) {
  7267. return;
  7268. }
  7269. this.ctx.fillRect(0, 0, 1, 1);
  7270. this.compose();
  7271. }
  7272. markPoint(tag) {}
  7273. markPointProps(tag, properties) {}
  7274. beginMarkedContent(tag) {
  7275. this.markedContentStack.push({
  7276. visible: true
  7277. });
  7278. }
  7279. beginMarkedContentProps(tag, properties) {
  7280. if (tag === "OC") {
  7281. this.markedContentStack.push({
  7282. visible: this.optionalContentConfig.isVisible(properties)
  7283. });
  7284. } else {
  7285. this.markedContentStack.push({
  7286. visible: true
  7287. });
  7288. }
  7289. this.contentVisible = this.isContentVisible();
  7290. }
  7291. endMarkedContent() {
  7292. this.markedContentStack.pop();
  7293. this.contentVisible = this.isContentVisible();
  7294. }
  7295. beginCompat() {}
  7296. endCompat() {}
  7297. consumePath(clipBox) {
  7298. const isEmpty = this.current.isEmptyClip();
  7299. if (this.pendingClip) {
  7300. this.current.updateClipFromPath();
  7301. }
  7302. if (!this.pendingClip) {
  7303. this.compose(clipBox);
  7304. }
  7305. const ctx = this.ctx;
  7306. if (this.pendingClip) {
  7307. if (!isEmpty) {
  7308. if (this.pendingClip === EO_CLIP) {
  7309. ctx.clip("evenodd");
  7310. } else {
  7311. ctx.clip();
  7312. }
  7313. }
  7314. this.pendingClip = null;
  7315. }
  7316. this.current.startNewPathAndClipBox(this.current.clipBox);
  7317. ctx.beginPath();
  7318. }
  7319. getSinglePixelWidth() {
  7320. if (!this._cachedGetSinglePixelWidth) {
  7321. const m = (0,display_utils.getCurrentTransform)(this.ctx);
  7322. if (m[1] === 0 && m[2] === 0) {
  7323. this._cachedGetSinglePixelWidth = 1 / Math.min(Math.abs(m[0]), Math.abs(m[3]));
  7324. } else {
  7325. const absDet = Math.abs(m[0] * m[3] - m[2] * m[1]);
  7326. const normX = Math.hypot(m[0], m[2]);
  7327. const normY = Math.hypot(m[1], m[3]);
  7328. this._cachedGetSinglePixelWidth = Math.max(normX, normY) / absDet;
  7329. }
  7330. }
  7331. return this._cachedGetSinglePixelWidth;
  7332. }
  7333. getScaleForStroking() {
  7334. if (this._cachedScaleForStroking[0] === -1) {
  7335. const {
  7336. lineWidth
  7337. } = this.current;
  7338. const {
  7339. a,
  7340. b,
  7341. c,
  7342. d
  7343. } = this.ctx.getTransform();
  7344. let scaleX, scaleY;
  7345. if (b === 0 && c === 0) {
  7346. const normX = Math.abs(a);
  7347. const normY = Math.abs(d);
  7348. if (normX === normY) {
  7349. if (lineWidth === 0) {
  7350. scaleX = scaleY = 1 / normX;
  7351. } else {
  7352. const scaledLineWidth = normX * lineWidth;
  7353. scaleX = scaleY = scaledLineWidth < 1 ? 1 / scaledLineWidth : 1;
  7354. }
  7355. } else if (lineWidth === 0) {
  7356. scaleX = 1 / normX;
  7357. scaleY = 1 / normY;
  7358. } else {
  7359. const scaledXLineWidth = normX * lineWidth;
  7360. const scaledYLineWidth = normY * lineWidth;
  7361. scaleX = scaledXLineWidth < 1 ? 1 / scaledXLineWidth : 1;
  7362. scaleY = scaledYLineWidth < 1 ? 1 / scaledYLineWidth : 1;
  7363. }
  7364. } else {
  7365. const absDet = Math.abs(a * d - b * c);
  7366. const normX = Math.hypot(a, b);
  7367. const normY = Math.hypot(c, d);
  7368. if (lineWidth === 0) {
  7369. scaleX = normY / absDet;
  7370. scaleY = normX / absDet;
  7371. } else {
  7372. const baseArea = lineWidth * absDet;
  7373. scaleX = normY > baseArea ? normY / baseArea : 1;
  7374. scaleY = normX > baseArea ? normX / baseArea : 1;
  7375. }
  7376. }
  7377. this._cachedScaleForStroking[0] = scaleX;
  7378. this._cachedScaleForStroking[1] = scaleY;
  7379. }
  7380. return this._cachedScaleForStroking;
  7381. }
  7382. rescaleAndStroke(saveRestore) {
  7383. const {
  7384. ctx
  7385. } = this;
  7386. const {
  7387. lineWidth
  7388. } = this.current;
  7389. const [scaleX, scaleY] = this.getScaleForStroking();
  7390. ctx.lineWidth = lineWidth || 1;
  7391. if (scaleX === 1 && scaleY === 1) {
  7392. ctx.stroke();
  7393. return;
  7394. }
  7395. const dashes = ctx.getLineDash();
  7396. if (saveRestore) {
  7397. ctx.save();
  7398. }
  7399. ctx.scale(scaleX, scaleY);
  7400. if (dashes.length > 0) {
  7401. const scale = Math.max(scaleX, scaleY);
  7402. ctx.setLineDash(dashes.map(x => x / scale));
  7403. ctx.lineDashOffset /= scale;
  7404. }
  7405. ctx.stroke();
  7406. if (saveRestore) {
  7407. ctx.restore();
  7408. }
  7409. }
  7410. isContentVisible() {
  7411. for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
  7412. if (!this.markedContentStack[i].visible) {
  7413. return false;
  7414. }
  7415. }
  7416. return true;
  7417. }
  7418. }
  7419. for (const op in util.OPS) {
  7420. if (CanvasGraphics.prototype[op] !== undefined) {
  7421. CanvasGraphics.prototype[util.OPS[op]] = CanvasGraphics.prototype[op];
  7422. }
  7423. }
  7424. /***/ }),
  7425. /***/ 473:
  7426. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  7427. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  7428. /* harmony export */ DOMCMapReaderFactory: () => (/* binding */ DOMCMapReaderFactory),
  7429. /* harmony export */ DOMCanvasFactory: () => (/* binding */ DOMCanvasFactory),
  7430. /* harmony export */ DOMFilterFactory: () => (/* binding */ DOMFilterFactory),
  7431. /* harmony export */ DOMSVGFactory: () => (/* binding */ DOMSVGFactory),
  7432. /* harmony export */ DOMStandardFontDataFactory: () => (/* binding */ DOMStandardFontDataFactory),
  7433. /* harmony export */ PDFDateString: () => (/* binding */ PDFDateString),
  7434. /* harmony export */ PageViewport: () => (/* binding */ PageViewport),
  7435. /* harmony export */ PixelsPerInch: () => (/* binding */ PixelsPerInch),
  7436. /* harmony export */ RenderingCancelledException: () => (/* binding */ RenderingCancelledException),
  7437. /* harmony export */ StatTimer: () => (/* binding */ StatTimer),
  7438. /* harmony export */ fetchData: () => (/* binding */ fetchData),
  7439. /* harmony export */ getColorValues: () => (/* binding */ getColorValues),
  7440. /* harmony export */ getCurrentTransform: () => (/* binding */ getCurrentTransform),
  7441. /* harmony export */ getCurrentTransformInverse: () => (/* binding */ getCurrentTransformInverse),
  7442. /* harmony export */ getFilenameFromUrl: () => (/* binding */ getFilenameFromUrl),
  7443. /* harmony export */ getPdfFilenameFromUrl: () => (/* binding */ getPdfFilenameFromUrl),
  7444. /* harmony export */ getRGB: () => (/* binding */ getRGB),
  7445. /* harmony export */ getXfaPageViewport: () => (/* binding */ getXfaPageViewport),
  7446. /* harmony export */ isDataScheme: () => (/* binding */ isDataScheme),
  7447. /* harmony export */ isPdfFile: () => (/* binding */ isPdfFile),
  7448. /* harmony export */ isValidFetchUrl: () => (/* binding */ isValidFetchUrl),
  7449. /* harmony export */ noContextMenu: () => (/* binding */ noContextMenu),
  7450. /* harmony export */ setLayerDimensions: () => (/* binding */ setLayerDimensions)
  7451. /* harmony export */ });
  7452. /* unused harmony export deprecated */
  7453. /* harmony import */ var _base_factory_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(822);
  7454. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(266);
  7455. const SVG_NS = "http://www.w3.org/2000/svg";
  7456. class PixelsPerInch {
  7457. static CSS = 96.0;
  7458. static PDF = 72.0;
  7459. static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
  7460. }
  7461. class DOMFilterFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseFilterFactory {
  7462. #_cache;
  7463. #_defs;
  7464. #docId;
  7465. #document;
  7466. #hcmFilter;
  7467. #hcmKey;
  7468. #hcmUrl;
  7469. #hcmHighlightFilter;
  7470. #hcmHighlightKey;
  7471. #hcmHighlightUrl;
  7472. #id = 0;
  7473. constructor({
  7474. docId,
  7475. ownerDocument = globalThis.document
  7476. } = {}) {
  7477. super();
  7478. this.#docId = docId;
  7479. this.#document = ownerDocument;
  7480. }
  7481. get #cache() {
  7482. return this.#_cache ||= new Map();
  7483. }
  7484. get #defs() {
  7485. if (!this.#_defs) {
  7486. const div = this.#document.createElement("div");
  7487. const {
  7488. style
  7489. } = div;
  7490. style.visibility = "hidden";
  7491. style.contain = "strict";
  7492. style.width = style.height = 0;
  7493. style.position = "absolute";
  7494. style.top = style.left = 0;
  7495. style.zIndex = -1;
  7496. const svg = this.#document.createElementNS(SVG_NS, "svg");
  7497. svg.setAttribute("width", 0);
  7498. svg.setAttribute("height", 0);
  7499. this.#_defs = this.#document.createElementNS(SVG_NS, "defs");
  7500. div.append(svg);
  7501. svg.append(this.#_defs);
  7502. this.#document.body.append(div);
  7503. }
  7504. return this.#_defs;
  7505. }
  7506. addFilter(maps) {
  7507. if (!maps) {
  7508. return "none";
  7509. }
  7510. let value = this.#cache.get(maps);
  7511. if (value) {
  7512. return value;
  7513. }
  7514. let tableR, tableG, tableB, key;
  7515. if (maps.length === 1) {
  7516. const mapR = maps[0];
  7517. const buffer = new Array(256);
  7518. for (let i = 0; i < 256; i++) {
  7519. buffer[i] = mapR[i] / 255;
  7520. }
  7521. key = tableR = tableG = tableB = buffer.join(",");
  7522. } else {
  7523. const [mapR, mapG, mapB] = maps;
  7524. const bufferR = new Array(256);
  7525. const bufferG = new Array(256);
  7526. const bufferB = new Array(256);
  7527. for (let i = 0; i < 256; i++) {
  7528. bufferR[i] = mapR[i] / 255;
  7529. bufferG[i] = mapG[i] / 255;
  7530. bufferB[i] = mapB[i] / 255;
  7531. }
  7532. tableR = bufferR.join(",");
  7533. tableG = bufferG.join(",");
  7534. tableB = bufferB.join(",");
  7535. key = `${tableR}${tableG}${tableB}`;
  7536. }
  7537. value = this.#cache.get(key);
  7538. if (value) {
  7539. this.#cache.set(maps, value);
  7540. return value;
  7541. }
  7542. const id = `g_${this.#docId}_transfer_map_${this.#id++}`;
  7543. const url = `url(#${id})`;
  7544. this.#cache.set(maps, url);
  7545. this.#cache.set(key, url);
  7546. const filter = this.#createFilter(id);
  7547. this.#addTransferMapConversion(tableR, tableG, tableB, filter);
  7548. return url;
  7549. }
  7550. addHCMFilter(fgColor, bgColor) {
  7551. const key = `${fgColor}-${bgColor}`;
  7552. if (this.#hcmKey === key) {
  7553. return this.#hcmUrl;
  7554. }
  7555. this.#hcmKey = key;
  7556. this.#hcmUrl = "none";
  7557. this.#hcmFilter?.remove();
  7558. if (!fgColor || !bgColor) {
  7559. return this.#hcmUrl;
  7560. }
  7561. const fgRGB = this.#getRGB(fgColor);
  7562. fgColor = _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.makeHexColor(...fgRGB);
  7563. const bgRGB = this.#getRGB(bgColor);
  7564. bgColor = _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.makeHexColor(...bgRGB);
  7565. this.#defs.style.color = "";
  7566. if (fgColor === "#000000" && bgColor === "#ffffff" || fgColor === bgColor) {
  7567. return this.#hcmUrl;
  7568. }
  7569. const map = new Array(256);
  7570. for (let i = 0; i <= 255; i++) {
  7571. const x = i / 255;
  7572. map[i] = x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
  7573. }
  7574. const table = map.join(",");
  7575. const id = `g_${this.#docId}_hcm_filter`;
  7576. const filter = this.#hcmHighlightFilter = this.#createFilter(id);
  7577. this.#addTransferMapConversion(table, table, table, filter);
  7578. this.#addGrayConversion(filter);
  7579. const getSteps = (c, n) => {
  7580. const start = fgRGB[c] / 255;
  7581. const end = bgRGB[c] / 255;
  7582. const arr = new Array(n + 1);
  7583. for (let i = 0; i <= n; i++) {
  7584. arr[i] = start + i / n * (end - start);
  7585. }
  7586. return arr.join(",");
  7587. };
  7588. this.#addTransferMapConversion(getSteps(0, 5), getSteps(1, 5), getSteps(2, 5), filter);
  7589. this.#hcmUrl = `url(#${id})`;
  7590. return this.#hcmUrl;
  7591. }
  7592. addHighlightHCMFilter(fgColor, bgColor, newFgColor, newBgColor) {
  7593. const key = `${fgColor}-${bgColor}-${newFgColor}-${newBgColor}`;
  7594. if (this.#hcmHighlightKey === key) {
  7595. return this.#hcmHighlightUrl;
  7596. }
  7597. this.#hcmHighlightKey = key;
  7598. this.#hcmHighlightUrl = "none";
  7599. this.#hcmHighlightFilter?.remove();
  7600. if (!fgColor || !bgColor) {
  7601. return this.#hcmHighlightUrl;
  7602. }
  7603. const [fgRGB, bgRGB] = [fgColor, bgColor].map(this.#getRGB.bind(this));
  7604. let fgGray = Math.round(0.2126 * fgRGB[0] + 0.7152 * fgRGB[1] + 0.0722 * fgRGB[2]);
  7605. let bgGray = Math.round(0.2126 * bgRGB[0] + 0.7152 * bgRGB[1] + 0.0722 * bgRGB[2]);
  7606. let [newFgRGB, newBgRGB] = [newFgColor, newBgColor].map(this.#getRGB.bind(this));
  7607. if (bgGray < fgGray) {
  7608. [fgGray, bgGray, newFgRGB, newBgRGB] = [bgGray, fgGray, newBgRGB, newFgRGB];
  7609. }
  7610. this.#defs.style.color = "";
  7611. const getSteps = (fg, bg, n) => {
  7612. const arr = new Array(256);
  7613. const step = (bgGray - fgGray) / n;
  7614. const newStart = fg / 255;
  7615. const newStep = (bg - fg) / (255 * n);
  7616. let prev = 0;
  7617. for (let i = 0; i <= n; i++) {
  7618. const k = Math.round(fgGray + i * step);
  7619. const value = newStart + i * newStep;
  7620. for (let j = prev; j <= k; j++) {
  7621. arr[j] = value;
  7622. }
  7623. prev = k + 1;
  7624. }
  7625. for (let i = prev; i < 256; i++) {
  7626. arr[i] = arr[prev - 1];
  7627. }
  7628. return arr.join(",");
  7629. };
  7630. const id = `g_${this.#docId}_hcm_highlight_filter`;
  7631. const filter = this.#hcmHighlightFilter = this.#createFilter(id);
  7632. this.#addGrayConversion(filter);
  7633. this.#addTransferMapConversion(getSteps(newFgRGB[0], newBgRGB[0], 5), getSteps(newFgRGB[1], newBgRGB[1], 5), getSteps(newFgRGB[2], newBgRGB[2], 5), filter);
  7634. this.#hcmHighlightUrl = `url(#${id})`;
  7635. return this.#hcmHighlightUrl;
  7636. }
  7637. destroy(keepHCM = false) {
  7638. if (keepHCM && (this.#hcmUrl || this.#hcmHighlightUrl)) {
  7639. return;
  7640. }
  7641. if (this.#_defs) {
  7642. this.#_defs.parentNode.parentNode.remove();
  7643. this.#_defs = null;
  7644. }
  7645. if (this.#_cache) {
  7646. this.#_cache.clear();
  7647. this.#_cache = null;
  7648. }
  7649. this.#id = 0;
  7650. }
  7651. #addGrayConversion(filter) {
  7652. const feColorMatrix = this.#document.createElementNS(SVG_NS, "feColorMatrix");
  7653. feColorMatrix.setAttribute("type", "matrix");
  7654. feColorMatrix.setAttribute("values", "0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0");
  7655. filter.append(feColorMatrix);
  7656. }
  7657. #createFilter(id) {
  7658. const filter = this.#document.createElementNS(SVG_NS, "filter");
  7659. filter.setAttribute("color-interpolation-filters", "sRGB");
  7660. filter.setAttribute("id", id);
  7661. this.#defs.append(filter);
  7662. return filter;
  7663. }
  7664. #appendFeFunc(feComponentTransfer, func, table) {
  7665. const feFunc = this.#document.createElementNS(SVG_NS, func);
  7666. feFunc.setAttribute("type", "discrete");
  7667. feFunc.setAttribute("tableValues", table);
  7668. feComponentTransfer.append(feFunc);
  7669. }
  7670. #addTransferMapConversion(rTable, gTable, bTable, filter) {
  7671. const feComponentTransfer = this.#document.createElementNS(SVG_NS, "feComponentTransfer");
  7672. filter.append(feComponentTransfer);
  7673. this.#appendFeFunc(feComponentTransfer, "feFuncR", rTable);
  7674. this.#appendFeFunc(feComponentTransfer, "feFuncG", gTable);
  7675. this.#appendFeFunc(feComponentTransfer, "feFuncB", bTable);
  7676. }
  7677. #getRGB(color) {
  7678. this.#defs.style.color = color;
  7679. return getRGB(getComputedStyle(this.#defs).getPropertyValue("color"));
  7680. }
  7681. }
  7682. class DOMCanvasFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseCanvasFactory {
  7683. constructor({
  7684. ownerDocument = globalThis.document
  7685. } = {}) {
  7686. super();
  7687. this._document = ownerDocument;
  7688. }
  7689. _createCanvas(width, height) {
  7690. const canvas = this._document.createElement("canvas");
  7691. canvas.width = width;
  7692. canvas.height = height;
  7693. return canvas;
  7694. }
  7695. }
  7696. async function fetchData(url, type = "text") {
  7697. if (isValidFetchUrl(url, document.baseURI)) {
  7698. const response = await fetch(url);
  7699. if (!response.ok) {
  7700. throw new Error(response.statusText);
  7701. }
  7702. switch (type) {
  7703. case "arraybuffer":
  7704. return response.arrayBuffer();
  7705. case "blob":
  7706. return response.blob();
  7707. case "json":
  7708. return response.json();
  7709. }
  7710. return response.text();
  7711. }
  7712. return new Promise((resolve, reject) => {
  7713. const request = new XMLHttpRequest();
  7714. request.open("GET", url, true);
  7715. request.responseType = type;
  7716. request.onreadystatechange = () => {
  7717. if (request.readyState !== XMLHttpRequest.DONE) {
  7718. return;
  7719. }
  7720. if (request.status === 200 || request.status === 0) {
  7721. let data;
  7722. switch (type) {
  7723. case "arraybuffer":
  7724. case "blob":
  7725. case "json":
  7726. data = request.response;
  7727. break;
  7728. default:
  7729. data = request.responseText;
  7730. break;
  7731. }
  7732. if (data) {
  7733. resolve(data);
  7734. return;
  7735. }
  7736. }
  7737. reject(new Error(request.statusText));
  7738. };
  7739. request.send(null);
  7740. });
  7741. }
  7742. class DOMCMapReaderFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseCMapReaderFactory {
  7743. _fetchData(url, compressionType) {
  7744. return fetchData(url, this.isCompressed ? "arraybuffer" : "text").then(data => {
  7745. return {
  7746. cMapData: data instanceof ArrayBuffer ? new Uint8Array(data) : (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.stringToBytes)(data),
  7747. compressionType
  7748. };
  7749. });
  7750. }
  7751. }
  7752. class DOMStandardFontDataFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseStandardFontDataFactory {
  7753. _fetchData(url) {
  7754. return fetchData(url, "arraybuffer").then(data => {
  7755. return new Uint8Array(data);
  7756. });
  7757. }
  7758. }
  7759. class DOMSVGFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseSVGFactory {
  7760. _createSVG(type) {
  7761. return document.createElementNS(SVG_NS, type);
  7762. }
  7763. }
  7764. class PageViewport {
  7765. constructor({
  7766. viewBox,
  7767. scale,
  7768. rotation,
  7769. offsetX = 0,
  7770. offsetY = 0,
  7771. dontFlip = false
  7772. }) {
  7773. this.viewBox = viewBox;
  7774. this.scale = scale;
  7775. this.rotation = rotation;
  7776. this.offsetX = offsetX;
  7777. this.offsetY = offsetY;
  7778. const centerX = (viewBox[2] + viewBox[0]) / 2;
  7779. const centerY = (viewBox[3] + viewBox[1]) / 2;
  7780. let rotateA, rotateB, rotateC, rotateD;
  7781. rotation %= 360;
  7782. if (rotation < 0) {
  7783. rotation += 360;
  7784. }
  7785. switch (rotation) {
  7786. case 180:
  7787. rotateA = -1;
  7788. rotateB = 0;
  7789. rotateC = 0;
  7790. rotateD = 1;
  7791. break;
  7792. case 90:
  7793. rotateA = 0;
  7794. rotateB = 1;
  7795. rotateC = 1;
  7796. rotateD = 0;
  7797. break;
  7798. case 270:
  7799. rotateA = 0;
  7800. rotateB = -1;
  7801. rotateC = -1;
  7802. rotateD = 0;
  7803. break;
  7804. case 0:
  7805. rotateA = 1;
  7806. rotateB = 0;
  7807. rotateC = 0;
  7808. rotateD = -1;
  7809. break;
  7810. default:
  7811. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  7812. }
  7813. if (dontFlip) {
  7814. rotateC = -rotateC;
  7815. rotateD = -rotateD;
  7816. }
  7817. let offsetCanvasX, offsetCanvasY;
  7818. let width, height;
  7819. if (rotateA === 0) {
  7820. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  7821. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  7822. width = (viewBox[3] - viewBox[1]) * scale;
  7823. height = (viewBox[2] - viewBox[0]) * scale;
  7824. } else {
  7825. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  7826. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  7827. width = (viewBox[2] - viewBox[0]) * scale;
  7828. height = (viewBox[3] - viewBox[1]) * scale;
  7829. }
  7830. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  7831. this.width = width;
  7832. this.height = height;
  7833. }
  7834. get rawDims() {
  7835. const {
  7836. viewBox
  7837. } = this;
  7838. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.shadow)(this, "rawDims", {
  7839. pageWidth: viewBox[2] - viewBox[0],
  7840. pageHeight: viewBox[3] - viewBox[1],
  7841. pageX: viewBox[0],
  7842. pageY: viewBox[1]
  7843. });
  7844. }
  7845. clone({
  7846. scale = this.scale,
  7847. rotation = this.rotation,
  7848. offsetX = this.offsetX,
  7849. offsetY = this.offsetY,
  7850. dontFlip = false
  7851. } = {}) {
  7852. return new PageViewport({
  7853. viewBox: this.viewBox.slice(),
  7854. scale,
  7855. rotation,
  7856. offsetX,
  7857. offsetY,
  7858. dontFlip
  7859. });
  7860. }
  7861. convertToViewportPoint(x, y) {
  7862. return _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.applyTransform([x, y], this.transform);
  7863. }
  7864. convertToViewportRectangle(rect) {
  7865. const topLeft = _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.applyTransform([rect[0], rect[1]], this.transform);
  7866. const bottomRight = _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.applyTransform([rect[2], rect[3]], this.transform);
  7867. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  7868. }
  7869. convertToPdfPoint(x, y) {
  7870. return _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.Util.applyInverseTransform([x, y], this.transform);
  7871. }
  7872. }
  7873. class RenderingCancelledException extends _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.BaseException {
  7874. constructor(msg, extraDelay = 0) {
  7875. super(msg, "RenderingCancelledException");
  7876. this.extraDelay = extraDelay;
  7877. }
  7878. }
  7879. function isDataScheme(url) {
  7880. const ii = url.length;
  7881. let i = 0;
  7882. while (i < ii && url[i].trim() === "") {
  7883. i++;
  7884. }
  7885. return url.substring(i, i + 5).toLowerCase() === "data:";
  7886. }
  7887. function isPdfFile(filename) {
  7888. return typeof filename === "string" && /\.pdf$/i.test(filename);
  7889. }
  7890. function getFilenameFromUrl(url, onlyStripPath = false) {
  7891. if (!onlyStripPath) {
  7892. [url] = url.split(/[#?]/, 1);
  7893. }
  7894. return url.substring(url.lastIndexOf("/") + 1);
  7895. }
  7896. function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
  7897. if (typeof url !== "string") {
  7898. return defaultFilename;
  7899. }
  7900. if (isDataScheme(url)) {
  7901. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.warn)('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
  7902. return defaultFilename;
  7903. }
  7904. const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  7905. const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  7906. const splitURI = reURI.exec(url);
  7907. let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  7908. if (suggestedFilename) {
  7909. suggestedFilename = suggestedFilename[0];
  7910. if (suggestedFilename.includes("%")) {
  7911. try {
  7912. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  7913. } catch {}
  7914. }
  7915. }
  7916. return suggestedFilename || defaultFilename;
  7917. }
  7918. class StatTimer {
  7919. started = Object.create(null);
  7920. times = [];
  7921. time(name) {
  7922. if (name in this.started) {
  7923. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.warn)(`Timer is already running for ${name}`);
  7924. }
  7925. this.started[name] = Date.now();
  7926. }
  7927. timeEnd(name) {
  7928. if (!(name in this.started)) {
  7929. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.warn)(`Timer has not been started for ${name}`);
  7930. }
  7931. this.times.push({
  7932. name,
  7933. start: this.started[name],
  7934. end: Date.now()
  7935. });
  7936. delete this.started[name];
  7937. }
  7938. toString() {
  7939. const outBuf = [];
  7940. let longest = 0;
  7941. for (const {
  7942. name
  7943. } of this.times) {
  7944. longest = Math.max(name.length, longest);
  7945. }
  7946. for (const {
  7947. name,
  7948. start,
  7949. end
  7950. } of this.times) {
  7951. outBuf.push(`${name.padEnd(longest)} ${end - start}ms\n`);
  7952. }
  7953. return outBuf.join("");
  7954. }
  7955. }
  7956. function isValidFetchUrl(url, baseUrl) {
  7957. try {
  7958. const {
  7959. protocol
  7960. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  7961. return protocol === "http:" || protocol === "https:";
  7962. } catch {
  7963. return false;
  7964. }
  7965. }
  7966. function noContextMenu(e) {
  7967. e.preventDefault();
  7968. }
  7969. function deprecated(details) {
  7970. console.log("Deprecated API usage: " + details);
  7971. }
  7972. let pdfDateStringRegex;
  7973. class PDFDateString {
  7974. static toDateObject(input) {
  7975. if (!input || typeof input !== "string") {
  7976. return null;
  7977. }
  7978. pdfDateStringRegex ||= new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  7979. const matches = pdfDateStringRegex.exec(input);
  7980. if (!matches) {
  7981. return null;
  7982. }
  7983. const year = parseInt(matches[1], 10);
  7984. let month = parseInt(matches[2], 10);
  7985. month = month >= 1 && month <= 12 ? month - 1 : 0;
  7986. let day = parseInt(matches[3], 10);
  7987. day = day >= 1 && day <= 31 ? day : 1;
  7988. let hour = parseInt(matches[4], 10);
  7989. hour = hour >= 0 && hour <= 23 ? hour : 0;
  7990. let minute = parseInt(matches[5], 10);
  7991. minute = minute >= 0 && minute <= 59 ? minute : 0;
  7992. let second = parseInt(matches[6], 10);
  7993. second = second >= 0 && second <= 59 ? second : 0;
  7994. const universalTimeRelation = matches[7] || "Z";
  7995. let offsetHour = parseInt(matches[8], 10);
  7996. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  7997. let offsetMinute = parseInt(matches[9], 10) || 0;
  7998. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  7999. if (universalTimeRelation === "-") {
  8000. hour += offsetHour;
  8001. minute += offsetMinute;
  8002. } else if (universalTimeRelation === "+") {
  8003. hour -= offsetHour;
  8004. minute -= offsetMinute;
  8005. }
  8006. return new Date(Date.UTC(year, month, day, hour, minute, second));
  8007. }
  8008. }
  8009. function getXfaPageViewport(xfaPage, {
  8010. scale = 1,
  8011. rotation = 0
  8012. }) {
  8013. const {
  8014. width,
  8015. height
  8016. } = xfaPage.attributes.style;
  8017. const viewBox = [0, 0, parseInt(width), parseInt(height)];
  8018. return new PageViewport({
  8019. viewBox,
  8020. scale,
  8021. rotation
  8022. });
  8023. }
  8024. function getRGB(color) {
  8025. if (color.startsWith("#")) {
  8026. const colorRGB = parseInt(color.slice(1), 16);
  8027. return [(colorRGB & 0xff0000) >> 16, (colorRGB & 0x00ff00) >> 8, colorRGB & 0x0000ff];
  8028. }
  8029. if (color.startsWith("rgb(")) {
  8030. return color.slice(4, -1).split(",").map(x => parseInt(x));
  8031. }
  8032. if (color.startsWith("rgba(")) {
  8033. return color.slice(5, -1).split(",").map(x => parseInt(x)).slice(0, 3);
  8034. }
  8035. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.warn)(`Not a valid color format: "${color}"`);
  8036. return [0, 0, 0];
  8037. }
  8038. function getColorValues(colors) {
  8039. const span = document.createElement("span");
  8040. span.style.visibility = "hidden";
  8041. document.body.append(span);
  8042. for (const name of colors.keys()) {
  8043. span.style.color = name;
  8044. const computedColor = window.getComputedStyle(span).color;
  8045. colors.set(name, getRGB(computedColor));
  8046. }
  8047. span.remove();
  8048. }
  8049. function getCurrentTransform(ctx) {
  8050. const {
  8051. a,
  8052. b,
  8053. c,
  8054. d,
  8055. e,
  8056. f
  8057. } = ctx.getTransform();
  8058. return [a, b, c, d, e, f];
  8059. }
  8060. function getCurrentTransformInverse(ctx) {
  8061. const {
  8062. a,
  8063. b,
  8064. c,
  8065. d,
  8066. e,
  8067. f
  8068. } = ctx.getTransform().invertSelf();
  8069. return [a, b, c, d, e, f];
  8070. }
  8071. function setLayerDimensions(div, viewport, mustFlip = false, mustRotate = true) {
  8072. if (viewport instanceof PageViewport) {
  8073. const {
  8074. pageWidth,
  8075. pageHeight
  8076. } = viewport.rawDims;
  8077. const {
  8078. style
  8079. } = div;
  8080. const useRound = _shared_util_js__WEBPACK_IMPORTED_MODULE_1__.FeatureTest.isCSSRoundSupported;
  8081. const w = `var(--scale-factor) * ${pageWidth}px`,
  8082. h = `var(--scale-factor) * ${pageHeight}px`;
  8083. const widthStr = useRound ? `round(${w}, 1px)` : `calc(${w})`,
  8084. heightStr = useRound ? `round(${h}, 1px)` : `calc(${h})`;
  8085. if (!mustFlip || viewport.rotation % 180 === 0) {
  8086. style.width = widthStr;
  8087. style.height = heightStr;
  8088. } else {
  8089. style.width = heightStr;
  8090. style.height = widthStr;
  8091. }
  8092. }
  8093. if (mustRotate) {
  8094. div.setAttribute("data-main-rotation", viewport.rotation);
  8095. }
  8096. }
  8097. /***/ }),
  8098. /***/ 423:
  8099. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  8100. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  8101. /* harmony export */ DrawLayer: () => (/* binding */ DrawLayer)
  8102. /* harmony export */ });
  8103. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(473);
  8104. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(266);
  8105. class DrawLayer {
  8106. #parent = null;
  8107. #id = 0;
  8108. #mapping = new Map();
  8109. constructor({
  8110. pageIndex
  8111. }) {
  8112. this.pageIndex = pageIndex;
  8113. }
  8114. setParent(parent) {
  8115. if (!this.#parent) {
  8116. this.#parent = parent;
  8117. return;
  8118. }
  8119. if (this.#parent !== parent) {
  8120. if (this.#mapping.size > 0) {
  8121. for (const root of this.#mapping.values()) {
  8122. root.remove();
  8123. parent.append(root);
  8124. }
  8125. }
  8126. this.#parent = parent;
  8127. }
  8128. }
  8129. static get _svgFactory() {
  8130. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.shadow)(this, "_svgFactory", new _display_utils_js__WEBPACK_IMPORTED_MODULE_0__.DOMSVGFactory());
  8131. }
  8132. static #setBox(element, {
  8133. x,
  8134. y,
  8135. width,
  8136. height
  8137. }) {
  8138. const {
  8139. style
  8140. } = element;
  8141. style.top = `${100 * y}%`;
  8142. style.left = `${100 * x}%`;
  8143. style.width = `${100 * width}%`;
  8144. style.height = `${100 * height}%`;
  8145. }
  8146. #createSVG(box) {
  8147. const svg = DrawLayer._svgFactory.create(1, 1, true);
  8148. this.#parent.append(svg);
  8149. DrawLayer.#setBox(svg, box);
  8150. return svg;
  8151. }
  8152. highlight({
  8153. outlines,
  8154. box
  8155. }, color, opacity) {
  8156. const id = this.#id++;
  8157. const root = this.#createSVG(box);
  8158. root.classList.add("highlight");
  8159. const defs = DrawLayer._svgFactory.createElement("defs");
  8160. root.append(defs);
  8161. const path = DrawLayer._svgFactory.createElement("path");
  8162. defs.append(path);
  8163. const pathId = `path_p${this.pageIndex}_${id}`;
  8164. path.setAttribute("id", pathId);
  8165. path.setAttribute("d", DrawLayer.#extractPathFromHighlightOutlines(outlines));
  8166. const clipPath = DrawLayer._svgFactory.createElement("clipPath");
  8167. defs.append(clipPath);
  8168. const clipPathId = `clip_${pathId}`;
  8169. clipPath.setAttribute("id", clipPathId);
  8170. clipPath.setAttribute("clipPathUnits", "objectBoundingBox");
  8171. const clipPathUse = DrawLayer._svgFactory.createElement("use");
  8172. clipPath.append(clipPathUse);
  8173. clipPathUse.setAttribute("href", `#${pathId}`);
  8174. clipPathUse.classList.add("clip");
  8175. const use = DrawLayer._svgFactory.createElement("use");
  8176. root.append(use);
  8177. root.setAttribute("fill", color);
  8178. root.setAttribute("fill-opacity", opacity);
  8179. use.setAttribute("href", `#${pathId}`);
  8180. this.#mapping.set(id, root);
  8181. return {
  8182. id,
  8183. clipPathId: `url(#${clipPathId})`
  8184. };
  8185. }
  8186. highlightOutline({
  8187. outlines,
  8188. box
  8189. }) {
  8190. const id = this.#id++;
  8191. const root = this.#createSVG(box);
  8192. root.classList.add("highlightOutline");
  8193. const defs = DrawLayer._svgFactory.createElement("defs");
  8194. root.append(defs);
  8195. const path = DrawLayer._svgFactory.createElement("path");
  8196. defs.append(path);
  8197. const pathId = `path_p${this.pageIndex}_${id}`;
  8198. path.setAttribute("id", pathId);
  8199. path.setAttribute("d", DrawLayer.#extractPathFromHighlightOutlines(outlines));
  8200. path.setAttribute("vector-effect", "non-scaling-stroke");
  8201. const use1 = DrawLayer._svgFactory.createElement("use");
  8202. root.append(use1);
  8203. use1.setAttribute("href", `#${pathId}`);
  8204. const use2 = use1.cloneNode();
  8205. root.append(use2);
  8206. use1.classList.add("mainOutline");
  8207. use2.classList.add("secondaryOutline");
  8208. this.#mapping.set(id, root);
  8209. return id;
  8210. }
  8211. static #extractPathFromHighlightOutlines(polygons) {
  8212. const buffer = [];
  8213. for (const polygon of polygons) {
  8214. let [prevX, prevY] = polygon;
  8215. buffer.push(`M${prevX} ${prevY}`);
  8216. for (let i = 2; i < polygon.length; i += 2) {
  8217. const x = polygon[i];
  8218. const y = polygon[i + 1];
  8219. if (x === prevX) {
  8220. buffer.push(`V${y}`);
  8221. prevY = y;
  8222. } else if (y === prevY) {
  8223. buffer.push(`H${x}`);
  8224. prevX = x;
  8225. }
  8226. }
  8227. buffer.push("Z");
  8228. }
  8229. return buffer.join(" ");
  8230. }
  8231. updateBox(id, box) {
  8232. DrawLayer.#setBox(this.#mapping.get(id), box);
  8233. }
  8234. rotate(id, angle) {
  8235. this.#mapping.get(id).setAttribute("data-main-rotation", angle);
  8236. }
  8237. changeColor(id, color) {
  8238. this.#mapping.get(id).setAttribute("fill", color);
  8239. }
  8240. changeOpacity(id, opacity) {
  8241. this.#mapping.get(id).setAttribute("fill-opacity", opacity);
  8242. }
  8243. addClass(id, className) {
  8244. this.#mapping.get(id).classList.add(className);
  8245. }
  8246. removeClass(id, className) {
  8247. this.#mapping.get(id).classList.remove(className);
  8248. }
  8249. remove(id) {
  8250. if (this.#parent === null) {
  8251. return;
  8252. }
  8253. this.#mapping.get(id).remove();
  8254. this.#mapping.delete(id);
  8255. }
  8256. destroy() {
  8257. this.#parent = null;
  8258. for (const root of this.#mapping.values()) {
  8259. root.remove();
  8260. }
  8261. this.#mapping.clear();
  8262. }
  8263. }
  8264. /***/ }),
  8265. /***/ 629:
  8266. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  8267. // EXPORTS
  8268. __webpack_require__.d(__webpack_exports__, {
  8269. AnnotationEditorLayer: () => (/* binding */ AnnotationEditorLayer)
  8270. });
  8271. // EXTERNAL MODULE: ./src/shared/util.js
  8272. var util = __webpack_require__(266);
  8273. // EXTERNAL MODULE: ./src/display/editor/editor.js + 2 modules
  8274. var editor_editor = __webpack_require__(115);
  8275. // EXTERNAL MODULE: ./src/display/editor/tools.js
  8276. var tools = __webpack_require__(812);
  8277. // EXTERNAL MODULE: ./src/display/annotation_layer.js + 1 modules
  8278. var annotation_layer = __webpack_require__(640);
  8279. ;// CONCATENATED MODULE: ./src/display/editor/freetext.js
  8280. class FreeTextEditor extends editor_editor.AnnotationEditor {
  8281. #boundEditorDivBlur = this.editorDivBlur.bind(this);
  8282. #boundEditorDivFocus = this.editorDivFocus.bind(this);
  8283. #boundEditorDivInput = this.editorDivInput.bind(this);
  8284. #boundEditorDivKeydown = this.editorDivKeydown.bind(this);
  8285. #color;
  8286. #content = "";
  8287. #editorDivId = `${this.id}-editor`;
  8288. #fontSize;
  8289. #initialData = null;
  8290. static _freeTextDefaultContent = "";
  8291. static _internalPadding = 0;
  8292. static _defaultColor = null;
  8293. static _defaultFontSize = 10;
  8294. static get _keyboardManager() {
  8295. const proto = FreeTextEditor.prototype;
  8296. const arrowChecker = self => self.isEmpty();
  8297. const small = tools.AnnotationEditorUIManager.TRANSLATE_SMALL;
  8298. const big = tools.AnnotationEditorUIManager.TRANSLATE_BIG;
  8299. return (0,util.shadow)(this, "_keyboardManager", new tools.KeyboardManager([[["ctrl+s", "mac+meta+s", "ctrl+p", "mac+meta+p"], proto.commitOrRemove, {
  8300. bubbles: true
  8301. }], [["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"], proto.commitOrRemove], [["ArrowLeft", "mac+ArrowLeft"], proto._translateEmpty, {
  8302. args: [-small, 0],
  8303. checker: arrowChecker
  8304. }], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], proto._translateEmpty, {
  8305. args: [-big, 0],
  8306. checker: arrowChecker
  8307. }], [["ArrowRight", "mac+ArrowRight"], proto._translateEmpty, {
  8308. args: [small, 0],
  8309. checker: arrowChecker
  8310. }], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], proto._translateEmpty, {
  8311. args: [big, 0],
  8312. checker: arrowChecker
  8313. }], [["ArrowUp", "mac+ArrowUp"], proto._translateEmpty, {
  8314. args: [0, -small],
  8315. checker: arrowChecker
  8316. }], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], proto._translateEmpty, {
  8317. args: [0, -big],
  8318. checker: arrowChecker
  8319. }], [["ArrowDown", "mac+ArrowDown"], proto._translateEmpty, {
  8320. args: [0, small],
  8321. checker: arrowChecker
  8322. }], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], proto._translateEmpty, {
  8323. args: [0, big],
  8324. checker: arrowChecker
  8325. }]]));
  8326. }
  8327. static _type = "freetext";
  8328. static _editorType = util.AnnotationEditorType.FREETEXT;
  8329. constructor(params) {
  8330. super({
  8331. ...params,
  8332. name: "freeTextEditor"
  8333. });
  8334. this.#color = params.color || FreeTextEditor._defaultColor || editor_editor.AnnotationEditor._defaultLineColor;
  8335. this.#fontSize = params.fontSize || FreeTextEditor._defaultFontSize;
  8336. }
  8337. static initialize(l10n) {
  8338. editor_editor.AnnotationEditor.initialize(l10n, {
  8339. strings: ["pdfjs-free-text-default-content"]
  8340. });
  8341. const style = getComputedStyle(document.documentElement);
  8342. this._internalPadding = parseFloat(style.getPropertyValue("--freetext-padding"));
  8343. }
  8344. static updateDefaultParams(type, value) {
  8345. switch (type) {
  8346. case util.AnnotationEditorParamsType.FREETEXT_SIZE:
  8347. FreeTextEditor._defaultFontSize = value;
  8348. break;
  8349. case util.AnnotationEditorParamsType.FREETEXT_COLOR:
  8350. FreeTextEditor._defaultColor = value;
  8351. break;
  8352. }
  8353. }
  8354. updateParams(type, value) {
  8355. switch (type) {
  8356. case util.AnnotationEditorParamsType.FREETEXT_SIZE:
  8357. this.#updateFontSize(value);
  8358. break;
  8359. case util.AnnotationEditorParamsType.FREETEXT_COLOR:
  8360. this.#updateColor(value);
  8361. break;
  8362. }
  8363. }
  8364. static get defaultPropertiesToUpdate() {
  8365. return [[util.AnnotationEditorParamsType.FREETEXT_SIZE, FreeTextEditor._defaultFontSize], [util.AnnotationEditorParamsType.FREETEXT_COLOR, FreeTextEditor._defaultColor || editor_editor.AnnotationEditor._defaultLineColor]];
  8366. }
  8367. get propertiesToUpdate() {
  8368. return [[util.AnnotationEditorParamsType.FREETEXT_SIZE, this.#fontSize], [util.AnnotationEditorParamsType.FREETEXT_COLOR, this.#color]];
  8369. }
  8370. #updateFontSize(fontSize) {
  8371. const setFontsize = size => {
  8372. this.editorDiv.style.fontSize = `calc(${size}px * var(--scale-factor))`;
  8373. this.translate(0, -(size - this.#fontSize) * this.parentScale);
  8374. this.#fontSize = size;
  8375. this.#setEditorDimensions();
  8376. };
  8377. const savedFontsize = this.#fontSize;
  8378. this.addCommands({
  8379. cmd: () => {
  8380. setFontsize(fontSize);
  8381. },
  8382. undo: () => {
  8383. setFontsize(savedFontsize);
  8384. },
  8385. mustExec: true,
  8386. type: util.AnnotationEditorParamsType.FREETEXT_SIZE,
  8387. overwriteIfSameType: true,
  8388. keepUndo: true
  8389. });
  8390. }
  8391. #updateColor(color) {
  8392. const savedColor = this.#color;
  8393. this.addCommands({
  8394. cmd: () => {
  8395. this.#color = this.editorDiv.style.color = color;
  8396. },
  8397. undo: () => {
  8398. this.#color = this.editorDiv.style.color = savedColor;
  8399. },
  8400. mustExec: true,
  8401. type: util.AnnotationEditorParamsType.FREETEXT_COLOR,
  8402. overwriteIfSameType: true,
  8403. keepUndo: true
  8404. });
  8405. }
  8406. _translateEmpty(x, y) {
  8407. this._uiManager.translateSelectedEditors(x, y, true);
  8408. }
  8409. getInitialTranslation() {
  8410. const scale = this.parentScale;
  8411. return [-FreeTextEditor._internalPadding * scale, -(FreeTextEditor._internalPadding + this.#fontSize) * scale];
  8412. }
  8413. rebuild() {
  8414. if (!this.parent) {
  8415. return;
  8416. }
  8417. super.rebuild();
  8418. if (this.div === null) {
  8419. return;
  8420. }
  8421. if (!this.isAttachedToDOM) {
  8422. this.parent.add(this);
  8423. }
  8424. }
  8425. enableEditMode() {
  8426. if (this.isInEditMode()) {
  8427. return;
  8428. }
  8429. this.parent.setEditingState(false);
  8430. this.parent.updateToolbar(util.AnnotationEditorType.FREETEXT);
  8431. super.enableEditMode();
  8432. this.overlayDiv.classList.remove("enabled");
  8433. this.editorDiv.contentEditable = true;
  8434. this._isDraggable = false;
  8435. this.div.removeAttribute("aria-activedescendant");
  8436. this.editorDiv.addEventListener("keydown", this.#boundEditorDivKeydown);
  8437. this.editorDiv.addEventListener("focus", this.#boundEditorDivFocus);
  8438. this.editorDiv.addEventListener("blur", this.#boundEditorDivBlur);
  8439. this.editorDiv.addEventListener("input", this.#boundEditorDivInput);
  8440. }
  8441. disableEditMode() {
  8442. if (!this.isInEditMode()) {
  8443. return;
  8444. }
  8445. this.parent.setEditingState(true);
  8446. super.disableEditMode();
  8447. this.overlayDiv.classList.add("enabled");
  8448. this.editorDiv.contentEditable = false;
  8449. this.div.setAttribute("aria-activedescendant", this.#editorDivId);
  8450. this._isDraggable = true;
  8451. this.editorDiv.removeEventListener("keydown", this.#boundEditorDivKeydown);
  8452. this.editorDiv.removeEventListener("focus", this.#boundEditorDivFocus);
  8453. this.editorDiv.removeEventListener("blur", this.#boundEditorDivBlur);
  8454. this.editorDiv.removeEventListener("input", this.#boundEditorDivInput);
  8455. this.div.focus({
  8456. preventScroll: true
  8457. });
  8458. this.isEditing = false;
  8459. this.parent.div.classList.add("freetextEditing");
  8460. }
  8461. focusin(event) {
  8462. if (!this._focusEventsAllowed) {
  8463. return;
  8464. }
  8465. super.focusin(event);
  8466. if (event.target !== this.editorDiv) {
  8467. this.editorDiv.focus();
  8468. }
  8469. }
  8470. onceAdded() {
  8471. if (this.width) {
  8472. this.#cheatInitialRect();
  8473. return;
  8474. }
  8475. this.enableEditMode();
  8476. this.editorDiv.focus();
  8477. if (this._initialOptions?.isCentered) {
  8478. this.center();
  8479. }
  8480. this._initialOptions = null;
  8481. }
  8482. isEmpty() {
  8483. return !this.editorDiv || this.editorDiv.innerText.trim() === "";
  8484. }
  8485. remove() {
  8486. this.isEditing = false;
  8487. if (this.parent) {
  8488. this.parent.setEditingState(true);
  8489. this.parent.div.classList.add("freetextEditing");
  8490. }
  8491. super.remove();
  8492. }
  8493. #extractText() {
  8494. const divs = this.editorDiv.getElementsByTagName("div");
  8495. if (divs.length === 0) {
  8496. return this.editorDiv.innerText;
  8497. }
  8498. const buffer = [];
  8499. for (const div of divs) {
  8500. buffer.push(div.innerText.replace(/\r\n?|\n/, ""));
  8501. }
  8502. return buffer.join("\n");
  8503. }
  8504. #setEditorDimensions() {
  8505. const [parentWidth, parentHeight] = this.parentDimensions;
  8506. let rect;
  8507. if (this.isAttachedToDOM) {
  8508. rect = this.div.getBoundingClientRect();
  8509. } else {
  8510. const {
  8511. currentLayer,
  8512. div
  8513. } = this;
  8514. const savedDisplay = div.style.display;
  8515. div.style.display = "hidden";
  8516. currentLayer.div.append(this.div);
  8517. rect = div.getBoundingClientRect();
  8518. div.remove();
  8519. div.style.display = savedDisplay;
  8520. }
  8521. if (this.rotation % 180 === this.parentRotation % 180) {
  8522. this.width = rect.width / parentWidth;
  8523. this.height = rect.height / parentHeight;
  8524. } else {
  8525. this.width = rect.height / parentWidth;
  8526. this.height = rect.width / parentHeight;
  8527. }
  8528. this.fixAndSetPosition();
  8529. }
  8530. commit() {
  8531. if (!this.isInEditMode()) {
  8532. return;
  8533. }
  8534. super.commit();
  8535. this.disableEditMode();
  8536. const savedText = this.#content;
  8537. const newText = this.#content = this.#extractText().trimEnd();
  8538. if (savedText === newText) {
  8539. return;
  8540. }
  8541. const setText = text => {
  8542. this.#content = text;
  8543. if (!text) {
  8544. this.remove();
  8545. return;
  8546. }
  8547. this.#setContent();
  8548. this._uiManager.rebuild(this);
  8549. this.#setEditorDimensions();
  8550. };
  8551. this.addCommands({
  8552. cmd: () => {
  8553. setText(newText);
  8554. },
  8555. undo: () => {
  8556. setText(savedText);
  8557. },
  8558. mustExec: false
  8559. });
  8560. this.#setEditorDimensions();
  8561. }
  8562. shouldGetKeyboardEvents() {
  8563. return this.isInEditMode();
  8564. }
  8565. enterInEditMode() {
  8566. this.enableEditMode();
  8567. this.editorDiv.focus();
  8568. }
  8569. dblclick(event) {
  8570. this.enterInEditMode();
  8571. }
  8572. keydown(event) {
  8573. if (event.target === this.div && event.key === "Enter") {
  8574. this.enterInEditMode();
  8575. event.preventDefault();
  8576. }
  8577. }
  8578. editorDivKeydown(event) {
  8579. FreeTextEditor._keyboardManager.exec(this, event);
  8580. }
  8581. editorDivFocus(event) {
  8582. this.isEditing = true;
  8583. }
  8584. editorDivBlur(event) {
  8585. this.isEditing = false;
  8586. }
  8587. editorDivInput(event) {
  8588. this.parent.div.classList.toggle("freetextEditing", this.isEmpty());
  8589. }
  8590. disableEditing() {
  8591. this.editorDiv.setAttribute("role", "comment");
  8592. this.editorDiv.removeAttribute("aria-multiline");
  8593. }
  8594. enableEditing() {
  8595. this.editorDiv.setAttribute("role", "textbox");
  8596. this.editorDiv.setAttribute("aria-multiline", true);
  8597. }
  8598. render() {
  8599. if (this.div) {
  8600. return this.div;
  8601. }
  8602. let baseX, baseY;
  8603. if (this.width) {
  8604. baseX = this.x;
  8605. baseY = this.y;
  8606. }
  8607. super.render();
  8608. this.editorDiv = document.createElement("div");
  8609. this.editorDiv.className = "internal";
  8610. this.editorDiv.setAttribute("id", this.#editorDivId);
  8611. this.editorDiv.setAttribute("data-l10n-id", "pdfjs-free-text");
  8612. this.enableEditing();
  8613. editor_editor.AnnotationEditor._l10nPromise.get("pdfjs-free-text-default-content").then(msg => this.editorDiv?.setAttribute("default-content", msg));
  8614. this.editorDiv.contentEditable = true;
  8615. const {
  8616. style
  8617. } = this.editorDiv;
  8618. style.fontSize = `calc(${this.#fontSize}px * var(--scale-factor))`;
  8619. style.color = this.#color;
  8620. this.div.append(this.editorDiv);
  8621. this.overlayDiv = document.createElement("div");
  8622. this.overlayDiv.classList.add("overlay", "enabled");
  8623. this.div.append(this.overlayDiv);
  8624. (0,tools.bindEvents)(this, this.div, ["dblclick", "keydown"]);
  8625. if (this.width) {
  8626. const [parentWidth, parentHeight] = this.parentDimensions;
  8627. if (this.annotationElementId) {
  8628. const {
  8629. position
  8630. } = this.#initialData;
  8631. let [tx, ty] = this.getInitialTranslation();
  8632. [tx, ty] = this.pageTranslationToScreen(tx, ty);
  8633. const [pageWidth, pageHeight] = this.pageDimensions;
  8634. const [pageX, pageY] = this.pageTranslation;
  8635. let posX, posY;
  8636. switch (this.rotation) {
  8637. case 0:
  8638. posX = baseX + (position[0] - pageX) / pageWidth;
  8639. posY = baseY + this.height - (position[1] - pageY) / pageHeight;
  8640. break;
  8641. case 90:
  8642. posX = baseX + (position[0] - pageX) / pageWidth;
  8643. posY = baseY - (position[1] - pageY) / pageHeight;
  8644. [tx, ty] = [ty, -tx];
  8645. break;
  8646. case 180:
  8647. posX = baseX - this.width + (position[0] - pageX) / pageWidth;
  8648. posY = baseY - (position[1] - pageY) / pageHeight;
  8649. [tx, ty] = [-tx, -ty];
  8650. break;
  8651. case 270:
  8652. posX = baseX + (position[0] - pageX - this.height * pageHeight) / pageWidth;
  8653. posY = baseY + (position[1] - pageY - this.width * pageWidth) / pageHeight;
  8654. [tx, ty] = [-ty, tx];
  8655. break;
  8656. }
  8657. this.setAt(posX * parentWidth, posY * parentHeight, tx, ty);
  8658. } else {
  8659. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  8660. }
  8661. this.#setContent();
  8662. this._isDraggable = true;
  8663. this.editorDiv.contentEditable = false;
  8664. } else {
  8665. this._isDraggable = false;
  8666. this.editorDiv.contentEditable = true;
  8667. }
  8668. return this.div;
  8669. }
  8670. #setContent() {
  8671. this.editorDiv.replaceChildren();
  8672. if (!this.#content) {
  8673. return;
  8674. }
  8675. for (const line of this.#content.split("\n")) {
  8676. const div = document.createElement("div");
  8677. div.append(line ? document.createTextNode(line) : document.createElement("br"));
  8678. this.editorDiv.append(div);
  8679. }
  8680. }
  8681. get contentDiv() {
  8682. return this.editorDiv;
  8683. }
  8684. static deserialize(data, parent, uiManager) {
  8685. let initialData = null;
  8686. if (data instanceof annotation_layer.FreeTextAnnotationElement) {
  8687. const {
  8688. data: {
  8689. defaultAppearanceData: {
  8690. fontSize,
  8691. fontColor
  8692. },
  8693. rect,
  8694. rotation,
  8695. id
  8696. },
  8697. textContent,
  8698. textPosition,
  8699. parent: {
  8700. page: {
  8701. pageNumber
  8702. }
  8703. }
  8704. } = data;
  8705. if (!textContent || textContent.length === 0) {
  8706. return null;
  8707. }
  8708. initialData = data = {
  8709. annotationType: util.AnnotationEditorType.FREETEXT,
  8710. color: Array.from(fontColor),
  8711. fontSize,
  8712. value: textContent.join("\n"),
  8713. position: textPosition,
  8714. pageIndex: pageNumber - 1,
  8715. rect,
  8716. rotation,
  8717. id,
  8718. deleted: false
  8719. };
  8720. }
  8721. const editor = super.deserialize(data, parent, uiManager);
  8722. editor.#fontSize = data.fontSize;
  8723. editor.#color = util.Util.makeHexColor(...data.color);
  8724. editor.#content = data.value;
  8725. editor.annotationElementId = data.id || null;
  8726. editor.#initialData = initialData;
  8727. return editor;
  8728. }
  8729. serialize(isForCopying = false) {
  8730. if (this.isEmpty()) {
  8731. return null;
  8732. }
  8733. if (this.deleted) {
  8734. return {
  8735. pageIndex: this.pageIndex,
  8736. id: this.annotationElementId,
  8737. deleted: true
  8738. };
  8739. }
  8740. const padding = FreeTextEditor._internalPadding * this.parentScale;
  8741. const rect = this.getRect(padding, padding);
  8742. const color = editor_editor.AnnotationEditor._colorManager.convert(this.isAttachedToDOM ? getComputedStyle(this.editorDiv).color : this.#color);
  8743. const serialized = {
  8744. annotationType: util.AnnotationEditorType.FREETEXT,
  8745. color,
  8746. fontSize: this.#fontSize,
  8747. value: this.#content,
  8748. pageIndex: this.pageIndex,
  8749. rect,
  8750. rotation: this.rotation,
  8751. structTreeParentId: this._structTreeParentId
  8752. };
  8753. if (isForCopying) {
  8754. return serialized;
  8755. }
  8756. if (this.annotationElementId && !this.#hasElementChanged(serialized)) {
  8757. return null;
  8758. }
  8759. serialized.id = this.annotationElementId;
  8760. return serialized;
  8761. }
  8762. #hasElementChanged(serialized) {
  8763. const {
  8764. value,
  8765. fontSize,
  8766. color,
  8767. rect,
  8768. pageIndex
  8769. } = this.#initialData;
  8770. return serialized.value !== value || serialized.fontSize !== fontSize || serialized.rect.some((x, i) => Math.abs(x - rect[i]) >= 1) || serialized.color.some((c, i) => c !== color[i]) || serialized.pageIndex !== pageIndex;
  8771. }
  8772. #cheatInitialRect(delayed = false) {
  8773. if (!this.annotationElementId) {
  8774. return;
  8775. }
  8776. this.#setEditorDimensions();
  8777. if (!delayed && (this.width === 0 || this.height === 0)) {
  8778. setTimeout(() => this.#cheatInitialRect(true), 0);
  8779. return;
  8780. }
  8781. const padding = FreeTextEditor._internalPadding * this.parentScale;
  8782. this.#initialData.rect = this.getRect(padding, padding);
  8783. }
  8784. }
  8785. // EXTERNAL MODULE: ./src/display/editor/color_picker.js
  8786. var color_picker = __webpack_require__(97);
  8787. // EXTERNAL MODULE: ./src/display/editor/outliner.js
  8788. var editor_outliner = __webpack_require__(405);
  8789. ;// CONCATENATED MODULE: ./src/display/editor/highlight.js
  8790. class HighlightEditor extends editor_editor.AnnotationEditor {
  8791. #boxes;
  8792. #clipPathId = null;
  8793. #colorPicker = null;
  8794. #focusOutlines = null;
  8795. #highlightDiv = null;
  8796. #highlightOutlines = null;
  8797. #id = null;
  8798. #lastPoint = null;
  8799. #opacity;
  8800. #outlineId = null;
  8801. static _defaultColor = null;
  8802. static _defaultOpacity = 1;
  8803. static _l10nPromise;
  8804. static _type = "highlight";
  8805. static _editorType = util.AnnotationEditorType.HIGHLIGHT;
  8806. constructor(params) {
  8807. super({
  8808. ...params,
  8809. name: "highlightEditor"
  8810. });
  8811. HighlightEditor._defaultColor ||= this._uiManager.highlightColors?.values().next().value || "#fff066";
  8812. this.color = params.color || HighlightEditor._defaultColor;
  8813. this.#opacity = params.opacity || HighlightEditor._defaultOpacity;
  8814. this.#boxes = params.boxes || null;
  8815. this._isDraggable = false;
  8816. this.#createOutlines();
  8817. this.#addToDrawLayer();
  8818. this.rotate(this.rotation);
  8819. }
  8820. #createOutlines() {
  8821. const outliner = new editor_outliner.Outliner(this.#boxes, 0.001);
  8822. this.#highlightOutlines = outliner.getOutlines();
  8823. ({
  8824. x: this.x,
  8825. y: this.y,
  8826. width: this.width,
  8827. height: this.height
  8828. } = this.#highlightOutlines.box);
  8829. const outlinerForOutline = new editor_outliner.Outliner(this.#boxes, 0.0025, 0.001, this._uiManager.direction === "ltr");
  8830. this.#focusOutlines = outlinerForOutline.getOutlines();
  8831. const {
  8832. lastPoint
  8833. } = this.#focusOutlines.box;
  8834. this.#lastPoint = [(lastPoint[0] - this.x) / this.width, (lastPoint[1] - this.y) / this.height];
  8835. }
  8836. static initialize(l10n) {
  8837. editor_editor.AnnotationEditor.initialize(l10n);
  8838. }
  8839. static updateDefaultParams(type, value) {
  8840. switch (type) {
  8841. case util.AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
  8842. HighlightEditor._defaultColor = value;
  8843. break;
  8844. }
  8845. }
  8846. get toolbarPosition() {
  8847. return this.#lastPoint;
  8848. }
  8849. updateParams(type, value) {
  8850. switch (type) {
  8851. case util.AnnotationEditorParamsType.HIGHLIGHT_COLOR:
  8852. this.#updateColor(value);
  8853. break;
  8854. }
  8855. }
  8856. static get defaultPropertiesToUpdate() {
  8857. return [[util.AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR, HighlightEditor._defaultColor]];
  8858. }
  8859. get propertiesToUpdate() {
  8860. return [[util.AnnotationEditorParamsType.HIGHLIGHT_COLOR, this.color || HighlightEditor._defaultColor]];
  8861. }
  8862. #updateColor(color) {
  8863. const savedColor = this.color;
  8864. this.addCommands({
  8865. cmd: () => {
  8866. this.color = color;
  8867. this.parent.drawLayer.changeColor(this.#id, color);
  8868. this.#colorPicker?.updateColor(color);
  8869. },
  8870. undo: () => {
  8871. this.color = savedColor;
  8872. this.parent.drawLayer.changeColor(this.#id, savedColor);
  8873. this.#colorPicker?.updateColor(savedColor);
  8874. },
  8875. mustExec: true,
  8876. type: util.AnnotationEditorParamsType.HIGHLIGHT_COLOR,
  8877. overwriteIfSameType: true,
  8878. keepUndo: true
  8879. });
  8880. }
  8881. async addEditToolbar() {
  8882. const toolbar = await super.addEditToolbar();
  8883. if (!toolbar) {
  8884. return null;
  8885. }
  8886. if (this._uiManager.highlightColors) {
  8887. this.#colorPicker = new color_picker.ColorPicker({
  8888. editor: this
  8889. });
  8890. toolbar.addColorPicker(this.#colorPicker);
  8891. }
  8892. return toolbar;
  8893. }
  8894. disableEditing() {
  8895. super.disableEditing();
  8896. this.div.classList.toggle("disabled", true);
  8897. }
  8898. enableEditing() {
  8899. super.enableEditing();
  8900. this.div.classList.toggle("disabled", false);
  8901. }
  8902. fixAndSetPosition() {
  8903. return super.fixAndSetPosition(0);
  8904. }
  8905. getRect(tx, ty) {
  8906. return super.getRect(tx, ty, 0);
  8907. }
  8908. onceAdded() {
  8909. this.parent.addUndoableEditor(this);
  8910. this.div.focus();
  8911. }
  8912. remove() {
  8913. super.remove();
  8914. this.#cleanDrawLayer();
  8915. }
  8916. rebuild() {
  8917. if (!this.parent) {
  8918. return;
  8919. }
  8920. super.rebuild();
  8921. if (this.div === null) {
  8922. return;
  8923. }
  8924. this.#addToDrawLayer();
  8925. if (!this.isAttachedToDOM) {
  8926. this.parent.add(this);
  8927. }
  8928. }
  8929. setParent(parent) {
  8930. let mustBeSelected = false;
  8931. if (this.parent && !parent) {
  8932. this.#cleanDrawLayer();
  8933. } else if (parent) {
  8934. this.#addToDrawLayer(parent);
  8935. mustBeSelected = !this.parent && this.div?.classList.contains("selectedEditor");
  8936. }
  8937. super.setParent(parent);
  8938. if (mustBeSelected) {
  8939. this.select();
  8940. }
  8941. }
  8942. #cleanDrawLayer() {
  8943. if (this.#id === null || !this.parent) {
  8944. return;
  8945. }
  8946. this.parent.drawLayer.remove(this.#id);
  8947. this.#id = null;
  8948. this.parent.drawLayer.remove(this.#outlineId);
  8949. this.#outlineId = null;
  8950. }
  8951. #addToDrawLayer(parent = this.parent) {
  8952. if (this.#id !== null) {
  8953. return;
  8954. }
  8955. ({
  8956. id: this.#id,
  8957. clipPathId: this.#clipPathId
  8958. } = parent.drawLayer.highlight(this.#highlightOutlines, this.color, this.#opacity));
  8959. if (this.#highlightDiv) {
  8960. this.#highlightDiv.style.clipPath = this.#clipPathId;
  8961. }
  8962. this.#outlineId = parent.drawLayer.highlightOutline(this.#focusOutlines);
  8963. }
  8964. static #rotateBbox({
  8965. x,
  8966. y,
  8967. width,
  8968. height
  8969. }, angle) {
  8970. switch (angle) {
  8971. case 90:
  8972. return {
  8973. x: 1 - y - height,
  8974. y: x,
  8975. width: height,
  8976. height: width
  8977. };
  8978. case 180:
  8979. return {
  8980. x: 1 - x - width,
  8981. y: 1 - y - height,
  8982. width,
  8983. height
  8984. };
  8985. case 270:
  8986. return {
  8987. x: y,
  8988. y: 1 - x - width,
  8989. width: height,
  8990. height: width
  8991. };
  8992. }
  8993. return {
  8994. x,
  8995. y,
  8996. width,
  8997. height
  8998. };
  8999. }
  9000. rotate(angle) {
  9001. const {
  9002. drawLayer
  9003. } = this.parent;
  9004. drawLayer.rotate(this.#id, angle);
  9005. drawLayer.rotate(this.#outlineId, angle);
  9006. drawLayer.updateBox(this.#id, HighlightEditor.#rotateBbox(this, angle));
  9007. drawLayer.updateBox(this.#outlineId, HighlightEditor.#rotateBbox(this.#focusOutlines.box, angle));
  9008. }
  9009. render() {
  9010. if (this.div) {
  9011. return this.div;
  9012. }
  9013. const div = super.render();
  9014. const highlightDiv = this.#highlightDiv = document.createElement("div");
  9015. div.append(highlightDiv);
  9016. highlightDiv.className = "internal";
  9017. highlightDiv.style.clipPath = this.#clipPathId;
  9018. const [parentWidth, parentHeight] = this.parentDimensions;
  9019. this.setDims(this.width * parentWidth, this.height * parentHeight);
  9020. (0,tools.bindEvents)(this, this.#highlightDiv, ["pointerover", "pointerleave"]);
  9021. this.enableEditing();
  9022. return div;
  9023. }
  9024. pointerover() {
  9025. this.parent.drawLayer.addClass(this.#outlineId, "hovered");
  9026. }
  9027. pointerleave() {
  9028. this.parent.drawLayer.removeClass(this.#outlineId, "hovered");
  9029. }
  9030. select() {
  9031. super.select();
  9032. this.parent?.drawLayer.removeClass(this.#outlineId, "hovered");
  9033. this.parent?.drawLayer.addClass(this.#outlineId, "selected");
  9034. }
  9035. unselect() {
  9036. super.unselect();
  9037. this.parent?.drawLayer.removeClass(this.#outlineId, "selected");
  9038. }
  9039. #serializeBoxes() {
  9040. const [pageWidth, pageHeight] = this.pageDimensions;
  9041. const boxes = this.#boxes;
  9042. const quadPoints = new Array(boxes.length * 8);
  9043. let i = 0;
  9044. for (const {
  9045. x,
  9046. y,
  9047. width,
  9048. height
  9049. } of boxes) {
  9050. const sx = x * pageWidth;
  9051. const sy = (1 - y - height) * pageHeight;
  9052. quadPoints[i] = quadPoints[i + 4] = sx;
  9053. quadPoints[i + 1] = quadPoints[i + 3] = sy;
  9054. quadPoints[i + 2] = quadPoints[i + 6] = sx + width * pageWidth;
  9055. quadPoints[i + 5] = quadPoints[i + 7] = sy + height * pageHeight;
  9056. i += 8;
  9057. }
  9058. return quadPoints;
  9059. }
  9060. #serializeOutlines() {
  9061. const [pageWidth, pageHeight] = this.pageDimensions;
  9062. const width = this.width * pageWidth;
  9063. const height = this.height * pageHeight;
  9064. const tx = this.x * pageWidth;
  9065. const ty = (1 - this.y - this.height) * pageHeight;
  9066. const outlines = [];
  9067. for (const outline of this.#highlightOutlines.outlines) {
  9068. const points = new Array(outline.length);
  9069. for (let i = 0; i < outline.length; i += 2) {
  9070. points[i] = tx + outline[i] * width;
  9071. points[i + 1] = ty + (1 - outline[i + 1]) * height;
  9072. }
  9073. outlines.push(points);
  9074. }
  9075. return outlines;
  9076. }
  9077. static deserialize(data, parent, uiManager) {
  9078. const editor = super.deserialize(data, parent, uiManager);
  9079. const {
  9080. rect,
  9081. color,
  9082. quadPoints
  9083. } = data;
  9084. editor.color = util.Util.makeHexColor(...color);
  9085. editor.#opacity = data.opacity;
  9086. const [pageWidth, pageHeight] = editor.pageDimensions;
  9087. editor.width = (rect[2] - rect[0]) / pageWidth;
  9088. editor.height = (rect[3] - rect[1]) / pageHeight;
  9089. const boxes = editor.#boxes = [];
  9090. for (let i = 0; i < quadPoints.length; i += 8) {
  9091. boxes.push({
  9092. x: quadPoints[4] / pageWidth,
  9093. y: 1 - quadPoints[i + 5] / pageHeight,
  9094. width: (quadPoints[i + 2] - quadPoints[i]) / pageWidth,
  9095. height: (quadPoints[i + 5] - quadPoints[i + 1]) / pageHeight
  9096. });
  9097. }
  9098. editor.#createOutlines();
  9099. return editor;
  9100. }
  9101. serialize(isForCopying = false) {
  9102. if (this.isEmpty() || isForCopying) {
  9103. return null;
  9104. }
  9105. const rect = this.getRect(0, 0);
  9106. const color = editor_editor.AnnotationEditor._colorManager.convert(this.color);
  9107. return {
  9108. annotationType: util.AnnotationEditorType.HIGHLIGHT,
  9109. color,
  9110. opacity: this.#opacity,
  9111. quadPoints: this.#serializeBoxes(),
  9112. outlines: this.#serializeOutlines(),
  9113. pageIndex: this.pageIndex,
  9114. rect,
  9115. rotation: 0,
  9116. structTreeParentId: this._structTreeParentId
  9117. };
  9118. }
  9119. static canCreateNewEmptyEditor() {
  9120. return false;
  9121. }
  9122. }
  9123. // EXTERNAL MODULE: ./src/display/display_utils.js
  9124. var display_utils = __webpack_require__(473);
  9125. ;// CONCATENATED MODULE: ./src/display/editor/ink.js
  9126. class InkEditor extends editor_editor.AnnotationEditor {
  9127. #baseHeight = 0;
  9128. #baseWidth = 0;
  9129. #boundCanvasPointermove = this.canvasPointermove.bind(this);
  9130. #boundCanvasPointerleave = this.canvasPointerleave.bind(this);
  9131. #boundCanvasPointerup = this.canvasPointerup.bind(this);
  9132. #boundCanvasPointerdown = this.canvasPointerdown.bind(this);
  9133. #canvasContextMenuTimeoutId = null;
  9134. #currentPath2D = new Path2D();
  9135. #disableEditing = false;
  9136. #hasSomethingToDraw = false;
  9137. #isCanvasInitialized = false;
  9138. #observer = null;
  9139. #realWidth = 0;
  9140. #realHeight = 0;
  9141. #requestFrameCallback = null;
  9142. static _defaultColor = null;
  9143. static _defaultOpacity = 1;
  9144. static _defaultThickness = 1;
  9145. static _type = "ink";
  9146. static _editorType = util.AnnotationEditorType.INK;
  9147. constructor(params) {
  9148. super({
  9149. ...params,
  9150. name: "inkEditor"
  9151. });
  9152. this.color = params.color || null;
  9153. this.thickness = params.thickness || null;
  9154. this.opacity = params.opacity || null;
  9155. this.paths = [];
  9156. this.bezierPath2D = [];
  9157. this.allRawPaths = [];
  9158. this.currentPath = [];
  9159. this.scaleFactor = 1;
  9160. this.translationX = this.translationY = 0;
  9161. this.x = 0;
  9162. this.y = 0;
  9163. this._willKeepAspectRatio = true;
  9164. }
  9165. static initialize(l10n) {
  9166. editor_editor.AnnotationEditor.initialize(l10n);
  9167. }
  9168. static updateDefaultParams(type, value) {
  9169. switch (type) {
  9170. case util.AnnotationEditorParamsType.INK_THICKNESS:
  9171. InkEditor._defaultThickness = value;
  9172. break;
  9173. case util.AnnotationEditorParamsType.INK_COLOR:
  9174. InkEditor._defaultColor = value;
  9175. break;
  9176. case util.AnnotationEditorParamsType.INK_OPACITY:
  9177. InkEditor._defaultOpacity = value / 100;
  9178. break;
  9179. }
  9180. }
  9181. updateParams(type, value) {
  9182. switch (type) {
  9183. case util.AnnotationEditorParamsType.INK_THICKNESS:
  9184. this.#updateThickness(value);
  9185. break;
  9186. case util.AnnotationEditorParamsType.INK_COLOR:
  9187. this.#updateColor(value);
  9188. break;
  9189. case util.AnnotationEditorParamsType.INK_OPACITY:
  9190. this.#updateOpacity(value);
  9191. break;
  9192. }
  9193. }
  9194. static get defaultPropertiesToUpdate() {
  9195. return [[util.AnnotationEditorParamsType.INK_THICKNESS, InkEditor._defaultThickness], [util.AnnotationEditorParamsType.INK_COLOR, InkEditor._defaultColor || editor_editor.AnnotationEditor._defaultLineColor], [util.AnnotationEditorParamsType.INK_OPACITY, Math.round(InkEditor._defaultOpacity * 100)]];
  9196. }
  9197. get propertiesToUpdate() {
  9198. return [[util.AnnotationEditorParamsType.INK_THICKNESS, this.thickness || InkEditor._defaultThickness], [util.AnnotationEditorParamsType.INK_COLOR, this.color || InkEditor._defaultColor || editor_editor.AnnotationEditor._defaultLineColor], [util.AnnotationEditorParamsType.INK_OPACITY, Math.round(100 * (this.opacity ?? InkEditor._defaultOpacity))]];
  9199. }
  9200. #updateThickness(thickness) {
  9201. const savedThickness = this.thickness;
  9202. this.addCommands({
  9203. cmd: () => {
  9204. this.thickness = thickness;
  9205. this.#fitToContent();
  9206. },
  9207. undo: () => {
  9208. this.thickness = savedThickness;
  9209. this.#fitToContent();
  9210. },
  9211. mustExec: true,
  9212. type: util.AnnotationEditorParamsType.INK_THICKNESS,
  9213. overwriteIfSameType: true,
  9214. keepUndo: true
  9215. });
  9216. }
  9217. #updateColor(color) {
  9218. const savedColor = this.color;
  9219. this.addCommands({
  9220. cmd: () => {
  9221. this.color = color;
  9222. this.#redraw();
  9223. },
  9224. undo: () => {
  9225. this.color = savedColor;
  9226. this.#redraw();
  9227. },
  9228. mustExec: true,
  9229. type: util.AnnotationEditorParamsType.INK_COLOR,
  9230. overwriteIfSameType: true,
  9231. keepUndo: true
  9232. });
  9233. }
  9234. #updateOpacity(opacity) {
  9235. opacity /= 100;
  9236. const savedOpacity = this.opacity;
  9237. this.addCommands({
  9238. cmd: () => {
  9239. this.opacity = opacity;
  9240. this.#redraw();
  9241. },
  9242. undo: () => {
  9243. this.opacity = savedOpacity;
  9244. this.#redraw();
  9245. },
  9246. mustExec: true,
  9247. type: util.AnnotationEditorParamsType.INK_OPACITY,
  9248. overwriteIfSameType: true,
  9249. keepUndo: true
  9250. });
  9251. }
  9252. rebuild() {
  9253. if (!this.parent) {
  9254. return;
  9255. }
  9256. super.rebuild();
  9257. if (this.div === null) {
  9258. return;
  9259. }
  9260. if (!this.canvas) {
  9261. this.#createCanvas();
  9262. this.#createObserver();
  9263. }
  9264. if (!this.isAttachedToDOM) {
  9265. this.parent.add(this);
  9266. this.#setCanvasDims();
  9267. }
  9268. this.#fitToContent();
  9269. }
  9270. remove() {
  9271. if (this.canvas === null) {
  9272. return;
  9273. }
  9274. if (!this.isEmpty()) {
  9275. this.commit();
  9276. }
  9277. this.canvas.width = this.canvas.height = 0;
  9278. this.canvas.remove();
  9279. this.canvas = null;
  9280. if (this.#canvasContextMenuTimeoutId) {
  9281. clearTimeout(this.#canvasContextMenuTimeoutId);
  9282. this.#canvasContextMenuTimeoutId = null;
  9283. }
  9284. this.#observer.disconnect();
  9285. this.#observer = null;
  9286. super.remove();
  9287. }
  9288. setParent(parent) {
  9289. if (!this.parent && parent) {
  9290. this._uiManager.removeShouldRescale(this);
  9291. } else if (this.parent && parent === null) {
  9292. this._uiManager.addShouldRescale(this);
  9293. }
  9294. super.setParent(parent);
  9295. }
  9296. onScaleChanging() {
  9297. const [parentWidth, parentHeight] = this.parentDimensions;
  9298. const width = this.width * parentWidth;
  9299. const height = this.height * parentHeight;
  9300. this.setDimensions(width, height);
  9301. }
  9302. enableEditMode() {
  9303. if (this.#disableEditing || this.canvas === null) {
  9304. return;
  9305. }
  9306. super.enableEditMode();
  9307. this._isDraggable = false;
  9308. this.canvas.addEventListener("pointerdown", this.#boundCanvasPointerdown);
  9309. }
  9310. disableEditMode() {
  9311. if (!this.isInEditMode() || this.canvas === null) {
  9312. return;
  9313. }
  9314. super.disableEditMode();
  9315. this._isDraggable = !this.isEmpty();
  9316. this.div.classList.remove("editing");
  9317. this.canvas.removeEventListener("pointerdown", this.#boundCanvasPointerdown);
  9318. }
  9319. onceAdded() {
  9320. this._isDraggable = !this.isEmpty();
  9321. }
  9322. isEmpty() {
  9323. return this.paths.length === 0 || this.paths.length === 1 && this.paths[0].length === 0;
  9324. }
  9325. #getInitialBBox() {
  9326. const {
  9327. parentRotation,
  9328. parentDimensions: [width, height]
  9329. } = this;
  9330. switch (parentRotation) {
  9331. case 90:
  9332. return [0, height, height, width];
  9333. case 180:
  9334. return [width, height, width, height];
  9335. case 270:
  9336. return [width, 0, height, width];
  9337. default:
  9338. return [0, 0, width, height];
  9339. }
  9340. }
  9341. #setStroke() {
  9342. const {
  9343. ctx,
  9344. color,
  9345. opacity,
  9346. thickness,
  9347. parentScale,
  9348. scaleFactor
  9349. } = this;
  9350. ctx.lineWidth = thickness * parentScale / scaleFactor;
  9351. ctx.lineCap = "round";
  9352. ctx.lineJoin = "round";
  9353. ctx.miterLimit = 10;
  9354. ctx.strokeStyle = `${color}${(0,tools.opacityToHex)(opacity)}`;
  9355. }
  9356. #startDrawing(x, y) {
  9357. this.canvas.addEventListener("contextmenu", display_utils.noContextMenu);
  9358. this.canvas.addEventListener("pointerleave", this.#boundCanvasPointerleave);
  9359. this.canvas.addEventListener("pointermove", this.#boundCanvasPointermove);
  9360. this.canvas.addEventListener("pointerup", this.#boundCanvasPointerup);
  9361. this.canvas.removeEventListener("pointerdown", this.#boundCanvasPointerdown);
  9362. this.isEditing = true;
  9363. if (!this.#isCanvasInitialized) {
  9364. this.#isCanvasInitialized = true;
  9365. this.#setCanvasDims();
  9366. this.thickness ||= InkEditor._defaultThickness;
  9367. this.color ||= InkEditor._defaultColor || editor_editor.AnnotationEditor._defaultLineColor;
  9368. this.opacity ??= InkEditor._defaultOpacity;
  9369. }
  9370. this.currentPath.push([x, y]);
  9371. this.#hasSomethingToDraw = false;
  9372. this.#setStroke();
  9373. this.#requestFrameCallback = () => {
  9374. this.#drawPoints();
  9375. if (this.#requestFrameCallback) {
  9376. window.requestAnimationFrame(this.#requestFrameCallback);
  9377. }
  9378. };
  9379. window.requestAnimationFrame(this.#requestFrameCallback);
  9380. }
  9381. #draw(x, y) {
  9382. const [lastX, lastY] = this.currentPath.at(-1);
  9383. if (this.currentPath.length > 1 && x === lastX && y === lastY) {
  9384. return;
  9385. }
  9386. const currentPath = this.currentPath;
  9387. let path2D = this.#currentPath2D;
  9388. currentPath.push([x, y]);
  9389. this.#hasSomethingToDraw = true;
  9390. if (currentPath.length <= 2) {
  9391. path2D.moveTo(...currentPath[0]);
  9392. path2D.lineTo(x, y);
  9393. return;
  9394. }
  9395. if (currentPath.length === 3) {
  9396. this.#currentPath2D = path2D = new Path2D();
  9397. path2D.moveTo(...currentPath[0]);
  9398. }
  9399. this.#makeBezierCurve(path2D, ...currentPath.at(-3), ...currentPath.at(-2), x, y);
  9400. }
  9401. #endPath() {
  9402. if (this.currentPath.length === 0) {
  9403. return;
  9404. }
  9405. const lastPoint = this.currentPath.at(-1);
  9406. this.#currentPath2D.lineTo(...lastPoint);
  9407. }
  9408. #stopDrawing(x, y) {
  9409. this.#requestFrameCallback = null;
  9410. x = Math.min(Math.max(x, 0), this.canvas.width);
  9411. y = Math.min(Math.max(y, 0), this.canvas.height);
  9412. this.#draw(x, y);
  9413. this.#endPath();
  9414. let bezier;
  9415. if (this.currentPath.length !== 1) {
  9416. bezier = this.#generateBezierPoints();
  9417. } else {
  9418. const xy = [x, y];
  9419. bezier = [[xy, xy.slice(), xy.slice(), xy]];
  9420. }
  9421. const path2D = this.#currentPath2D;
  9422. const currentPath = this.currentPath;
  9423. this.currentPath = [];
  9424. this.#currentPath2D = new Path2D();
  9425. const cmd = () => {
  9426. this.allRawPaths.push(currentPath);
  9427. this.paths.push(bezier);
  9428. this.bezierPath2D.push(path2D);
  9429. this.rebuild();
  9430. };
  9431. const undo = () => {
  9432. this.allRawPaths.pop();
  9433. this.paths.pop();
  9434. this.bezierPath2D.pop();
  9435. if (this.paths.length === 0) {
  9436. this.remove();
  9437. } else {
  9438. if (!this.canvas) {
  9439. this.#createCanvas();
  9440. this.#createObserver();
  9441. }
  9442. this.#fitToContent();
  9443. }
  9444. };
  9445. this.addCommands({
  9446. cmd,
  9447. undo,
  9448. mustExec: true
  9449. });
  9450. }
  9451. #drawPoints() {
  9452. if (!this.#hasSomethingToDraw) {
  9453. return;
  9454. }
  9455. this.#hasSomethingToDraw = false;
  9456. const thickness = Math.ceil(this.thickness * this.parentScale);
  9457. const lastPoints = this.currentPath.slice(-3);
  9458. const x = lastPoints.map(xy => xy[0]);
  9459. const y = lastPoints.map(xy => xy[1]);
  9460. const xMin = Math.min(...x) - thickness;
  9461. const xMax = Math.max(...x) + thickness;
  9462. const yMin = Math.min(...y) - thickness;
  9463. const yMax = Math.max(...y) + thickness;
  9464. const {
  9465. ctx
  9466. } = this;
  9467. ctx.save();
  9468. ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
  9469. for (const path of this.bezierPath2D) {
  9470. ctx.stroke(path);
  9471. }
  9472. ctx.stroke(this.#currentPath2D);
  9473. ctx.restore();
  9474. }
  9475. #makeBezierCurve(path2D, x0, y0, x1, y1, x2, y2) {
  9476. const prevX = (x0 + x1) / 2;
  9477. const prevY = (y0 + y1) / 2;
  9478. const x3 = (x1 + x2) / 2;
  9479. const y3 = (y1 + y2) / 2;
  9480. path2D.bezierCurveTo(prevX + 2 * (x1 - prevX) / 3, prevY + 2 * (y1 - prevY) / 3, x3 + 2 * (x1 - x3) / 3, y3 + 2 * (y1 - y3) / 3, x3, y3);
  9481. }
  9482. #generateBezierPoints() {
  9483. const path = this.currentPath;
  9484. if (path.length <= 2) {
  9485. return [[path[0], path[0], path.at(-1), path.at(-1)]];
  9486. }
  9487. const bezierPoints = [];
  9488. let i;
  9489. let [x0, y0] = path[0];
  9490. for (i = 1; i < path.length - 2; i++) {
  9491. const [x1, y1] = path[i];
  9492. const [x2, y2] = path[i + 1];
  9493. const x3 = (x1 + x2) / 2;
  9494. const y3 = (y1 + y2) / 2;
  9495. const control1 = [x0 + 2 * (x1 - x0) / 3, y0 + 2 * (y1 - y0) / 3];
  9496. const control2 = [x3 + 2 * (x1 - x3) / 3, y3 + 2 * (y1 - y3) / 3];
  9497. bezierPoints.push([[x0, y0], control1, control2, [x3, y3]]);
  9498. [x0, y0] = [x3, y3];
  9499. }
  9500. const [x1, y1] = path[i];
  9501. const [x2, y2] = path[i + 1];
  9502. const control1 = [x0 + 2 * (x1 - x0) / 3, y0 + 2 * (y1 - y0) / 3];
  9503. const control2 = [x2 + 2 * (x1 - x2) / 3, y2 + 2 * (y1 - y2) / 3];
  9504. bezierPoints.push([[x0, y0], control1, control2, [x2, y2]]);
  9505. return bezierPoints;
  9506. }
  9507. #redraw() {
  9508. if (this.isEmpty()) {
  9509. this.#updateTransform();
  9510. return;
  9511. }
  9512. this.#setStroke();
  9513. const {
  9514. canvas,
  9515. ctx
  9516. } = this;
  9517. ctx.setTransform(1, 0, 0, 1, 0, 0);
  9518. ctx.clearRect(0, 0, canvas.width, canvas.height);
  9519. this.#updateTransform();
  9520. for (const path of this.bezierPath2D) {
  9521. ctx.stroke(path);
  9522. }
  9523. }
  9524. commit() {
  9525. if (this.#disableEditing) {
  9526. return;
  9527. }
  9528. super.commit();
  9529. this.isEditing = false;
  9530. this.disableEditMode();
  9531. this.setInForeground();
  9532. this.#disableEditing = true;
  9533. this.div.classList.add("disabled");
  9534. this.#fitToContent(true);
  9535. this.select();
  9536. this.parent.addInkEditorIfNeeded(true);
  9537. this.moveInDOM();
  9538. this.div.focus({
  9539. preventScroll: true
  9540. });
  9541. }
  9542. focusin(event) {
  9543. if (!this._focusEventsAllowed) {
  9544. return;
  9545. }
  9546. super.focusin(event);
  9547. this.enableEditMode();
  9548. }
  9549. canvasPointerdown(event) {
  9550. if (event.button !== 0 || !this.isInEditMode() || this.#disableEditing) {
  9551. return;
  9552. }
  9553. this.setInForeground();
  9554. event.preventDefault();
  9555. if (!this.div.contains(document.activeElement)) {
  9556. this.div.focus({
  9557. preventScroll: true
  9558. });
  9559. }
  9560. this.#startDrawing(event.offsetX, event.offsetY);
  9561. }
  9562. canvasPointermove(event) {
  9563. event.preventDefault();
  9564. this.#draw(event.offsetX, event.offsetY);
  9565. }
  9566. canvasPointerup(event) {
  9567. event.preventDefault();
  9568. this.#endDrawing(event);
  9569. }
  9570. canvasPointerleave(event) {
  9571. this.#endDrawing(event);
  9572. }
  9573. #endDrawing(event) {
  9574. this.canvas.removeEventListener("pointerleave", this.#boundCanvasPointerleave);
  9575. this.canvas.removeEventListener("pointermove", this.#boundCanvasPointermove);
  9576. this.canvas.removeEventListener("pointerup", this.#boundCanvasPointerup);
  9577. this.canvas.addEventListener("pointerdown", this.#boundCanvasPointerdown);
  9578. if (this.#canvasContextMenuTimeoutId) {
  9579. clearTimeout(this.#canvasContextMenuTimeoutId);
  9580. }
  9581. this.#canvasContextMenuTimeoutId = setTimeout(() => {
  9582. this.#canvasContextMenuTimeoutId = null;
  9583. this.canvas.removeEventListener("contextmenu", display_utils.noContextMenu);
  9584. }, 10);
  9585. this.#stopDrawing(event.offsetX, event.offsetY);
  9586. this.addToAnnotationStorage();
  9587. this.setInBackground();
  9588. }
  9589. #createCanvas() {
  9590. this.canvas = document.createElement("canvas");
  9591. this.canvas.width = this.canvas.height = 0;
  9592. this.canvas.className = "inkEditorCanvas";
  9593. this.canvas.setAttribute("data-l10n-id", "pdfjs-ink-canvas");
  9594. this.div.append(this.canvas);
  9595. this.ctx = this.canvas.getContext("2d");
  9596. }
  9597. #createObserver() {
  9598. this.#observer = new ResizeObserver(entries => {
  9599. const rect = entries[0].contentRect;
  9600. if (rect.width && rect.height) {
  9601. this.setDimensions(rect.width, rect.height);
  9602. }
  9603. });
  9604. this.#observer.observe(this.div);
  9605. }
  9606. get isResizable() {
  9607. return !this.isEmpty() && this.#disableEditing;
  9608. }
  9609. render() {
  9610. if (this.div) {
  9611. return this.div;
  9612. }
  9613. let baseX, baseY;
  9614. if (this.width) {
  9615. baseX = this.x;
  9616. baseY = this.y;
  9617. }
  9618. super.render();
  9619. this.div.setAttribute("data-l10n-id", "pdfjs-ink");
  9620. const [x, y, w, h] = this.#getInitialBBox();
  9621. this.setAt(x, y, 0, 0);
  9622. this.setDims(w, h);
  9623. this.#createCanvas();
  9624. if (this.width) {
  9625. const [parentWidth, parentHeight] = this.parentDimensions;
  9626. this.setAspectRatio(this.width * parentWidth, this.height * parentHeight);
  9627. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  9628. this.#isCanvasInitialized = true;
  9629. this.#setCanvasDims();
  9630. this.setDims(this.width * parentWidth, this.height * parentHeight);
  9631. this.#redraw();
  9632. this.div.classList.add("disabled");
  9633. } else {
  9634. this.div.classList.add("editing");
  9635. this.enableEditMode();
  9636. }
  9637. this.#createObserver();
  9638. return this.div;
  9639. }
  9640. #setCanvasDims() {
  9641. if (!this.#isCanvasInitialized) {
  9642. return;
  9643. }
  9644. const [parentWidth, parentHeight] = this.parentDimensions;
  9645. this.canvas.width = Math.ceil(this.width * parentWidth);
  9646. this.canvas.height = Math.ceil(this.height * parentHeight);
  9647. this.#updateTransform();
  9648. }
  9649. setDimensions(width, height) {
  9650. const roundedWidth = Math.round(width);
  9651. const roundedHeight = Math.round(height);
  9652. if (this.#realWidth === roundedWidth && this.#realHeight === roundedHeight) {
  9653. return;
  9654. }
  9655. this.#realWidth = roundedWidth;
  9656. this.#realHeight = roundedHeight;
  9657. this.canvas.style.visibility = "hidden";
  9658. const [parentWidth, parentHeight] = this.parentDimensions;
  9659. this.width = width / parentWidth;
  9660. this.height = height / parentHeight;
  9661. this.fixAndSetPosition();
  9662. if (this.#disableEditing) {
  9663. this.#setScaleFactor(width, height);
  9664. }
  9665. this.#setCanvasDims();
  9666. this.#redraw();
  9667. this.canvas.style.visibility = "visible";
  9668. this.fixDims();
  9669. }
  9670. #setScaleFactor(width, height) {
  9671. const padding = this.#getPadding();
  9672. const scaleFactorW = (width - padding) / this.#baseWidth;
  9673. const scaleFactorH = (height - padding) / this.#baseHeight;
  9674. this.scaleFactor = Math.min(scaleFactorW, scaleFactorH);
  9675. }
  9676. #updateTransform() {
  9677. const padding = this.#getPadding() / 2;
  9678. this.ctx.setTransform(this.scaleFactor, 0, 0, this.scaleFactor, this.translationX * this.scaleFactor + padding, this.translationY * this.scaleFactor + padding);
  9679. }
  9680. static #buildPath2D(bezier) {
  9681. const path2D = new Path2D();
  9682. for (let i = 0, ii = bezier.length; i < ii; i++) {
  9683. const [first, control1, control2, second] = bezier[i];
  9684. if (i === 0) {
  9685. path2D.moveTo(...first);
  9686. }
  9687. path2D.bezierCurveTo(control1[0], control1[1], control2[0], control2[1], second[0], second[1]);
  9688. }
  9689. return path2D;
  9690. }
  9691. static #toPDFCoordinates(points, rect, rotation) {
  9692. const [blX, blY, trX, trY] = rect;
  9693. switch (rotation) {
  9694. case 0:
  9695. for (let i = 0, ii = points.length; i < ii; i += 2) {
  9696. points[i] += blX;
  9697. points[i + 1] = trY - points[i + 1];
  9698. }
  9699. break;
  9700. case 90:
  9701. for (let i = 0, ii = points.length; i < ii; i += 2) {
  9702. const x = points[i];
  9703. points[i] = points[i + 1] + blX;
  9704. points[i + 1] = x + blY;
  9705. }
  9706. break;
  9707. case 180:
  9708. for (let i = 0, ii = points.length; i < ii; i += 2) {
  9709. points[i] = trX - points[i];
  9710. points[i + 1] += blY;
  9711. }
  9712. break;
  9713. case 270:
  9714. for (let i = 0, ii = points.length; i < ii; i += 2) {
  9715. const x = points[i];
  9716. points[i] = trX - points[i + 1];
  9717. points[i + 1] = trY - x;
  9718. }
  9719. break;
  9720. default:
  9721. throw new Error("Invalid rotation");
  9722. }
  9723. return points;
  9724. }
  9725. static #fromPDFCoordinates(points, rect, rotation) {
  9726. const [blX, blY, trX, trY] = rect;
  9727. switch (rotation) {
  9728. case 0:
  9729. for (let i = 0, ii = points.length; i < ii; i += 2) {
  9730. points[i] -= blX;
  9731. points[i + 1] = trY - points[i + 1];
  9732. }
  9733. break;
  9734. case 90:
  9735. for (let i = 0, ii = points.length; i < ii; i += 2) {
  9736. const x = points[i];
  9737. points[i] = points[i + 1] - blY;
  9738. points[i + 1] = x - blX;
  9739. }
  9740. break;
  9741. case 180:
  9742. for (let i = 0, ii = points.length; i < ii; i += 2) {
  9743. points[i] = trX - points[i];
  9744. points[i + 1] -= blY;
  9745. }
  9746. break;
  9747. case 270:
  9748. for (let i = 0, ii = points.length; i < ii; i += 2) {
  9749. const x = points[i];
  9750. points[i] = trY - points[i + 1];
  9751. points[i + 1] = trX - x;
  9752. }
  9753. break;
  9754. default:
  9755. throw new Error("Invalid rotation");
  9756. }
  9757. return points;
  9758. }
  9759. #serializePaths(s, tx, ty, rect) {
  9760. const paths = [];
  9761. const padding = this.thickness / 2;
  9762. const shiftX = s * tx + padding;
  9763. const shiftY = s * ty + padding;
  9764. for (const bezier of this.paths) {
  9765. const buffer = [];
  9766. const points = [];
  9767. for (let j = 0, jj = bezier.length; j < jj; j++) {
  9768. const [first, control1, control2, second] = bezier[j];
  9769. const p10 = s * first[0] + shiftX;
  9770. const p11 = s * first[1] + shiftY;
  9771. const p20 = s * control1[0] + shiftX;
  9772. const p21 = s * control1[1] + shiftY;
  9773. const p30 = s * control2[0] + shiftX;
  9774. const p31 = s * control2[1] + shiftY;
  9775. const p40 = s * second[0] + shiftX;
  9776. const p41 = s * second[1] + shiftY;
  9777. if (j === 0) {
  9778. buffer.push(p10, p11);
  9779. points.push(p10, p11);
  9780. }
  9781. buffer.push(p20, p21, p30, p31, p40, p41);
  9782. points.push(p20, p21);
  9783. if (j === jj - 1) {
  9784. points.push(p40, p41);
  9785. }
  9786. }
  9787. paths.push({
  9788. bezier: InkEditor.#toPDFCoordinates(buffer, rect, this.rotation),
  9789. points: InkEditor.#toPDFCoordinates(points, rect, this.rotation)
  9790. });
  9791. }
  9792. return paths;
  9793. }
  9794. #getBbox() {
  9795. let xMin = Infinity;
  9796. let xMax = -Infinity;
  9797. let yMin = Infinity;
  9798. let yMax = -Infinity;
  9799. for (const path of this.paths) {
  9800. for (const [first, control1, control2, second] of path) {
  9801. const bbox = util.Util.bezierBoundingBox(...first, ...control1, ...control2, ...second);
  9802. xMin = Math.min(xMin, bbox[0]);
  9803. yMin = Math.min(yMin, bbox[1]);
  9804. xMax = Math.max(xMax, bbox[2]);
  9805. yMax = Math.max(yMax, bbox[3]);
  9806. }
  9807. }
  9808. return [xMin, yMin, xMax, yMax];
  9809. }
  9810. #getPadding() {
  9811. return this.#disableEditing ? Math.ceil(this.thickness * this.parentScale) : 0;
  9812. }
  9813. #fitToContent(firstTime = false) {
  9814. if (this.isEmpty()) {
  9815. return;
  9816. }
  9817. if (!this.#disableEditing) {
  9818. this.#redraw();
  9819. return;
  9820. }
  9821. const bbox = this.#getBbox();
  9822. const padding = this.#getPadding();
  9823. this.#baseWidth = Math.max(editor_editor.AnnotationEditor.MIN_SIZE, bbox[2] - bbox[0]);
  9824. this.#baseHeight = Math.max(editor_editor.AnnotationEditor.MIN_SIZE, bbox[3] - bbox[1]);
  9825. const width = Math.ceil(padding + this.#baseWidth * this.scaleFactor);
  9826. const height = Math.ceil(padding + this.#baseHeight * this.scaleFactor);
  9827. const [parentWidth, parentHeight] = this.parentDimensions;
  9828. this.width = width / parentWidth;
  9829. this.height = height / parentHeight;
  9830. this.setAspectRatio(width, height);
  9831. const prevTranslationX = this.translationX;
  9832. const prevTranslationY = this.translationY;
  9833. this.translationX = -bbox[0];
  9834. this.translationY = -bbox[1];
  9835. this.#setCanvasDims();
  9836. this.#redraw();
  9837. this.#realWidth = width;
  9838. this.#realHeight = height;
  9839. this.setDims(width, height);
  9840. const unscaledPadding = firstTime ? padding / this.scaleFactor / 2 : 0;
  9841. this.translate(prevTranslationX - this.translationX - unscaledPadding, prevTranslationY - this.translationY - unscaledPadding);
  9842. }
  9843. static deserialize(data, parent, uiManager) {
  9844. if (data instanceof annotation_layer.InkAnnotationElement) {
  9845. return null;
  9846. }
  9847. const editor = super.deserialize(data, parent, uiManager);
  9848. editor.thickness = data.thickness;
  9849. editor.color = util.Util.makeHexColor(...data.color);
  9850. editor.opacity = data.opacity;
  9851. const [pageWidth, pageHeight] = editor.pageDimensions;
  9852. const width = editor.width * pageWidth;
  9853. const height = editor.height * pageHeight;
  9854. const scaleFactor = editor.parentScale;
  9855. const padding = data.thickness / 2;
  9856. editor.#disableEditing = true;
  9857. editor.#realWidth = Math.round(width);
  9858. editor.#realHeight = Math.round(height);
  9859. const {
  9860. paths,
  9861. rect,
  9862. rotation
  9863. } = data;
  9864. for (let {
  9865. bezier
  9866. } of paths) {
  9867. bezier = InkEditor.#fromPDFCoordinates(bezier, rect, rotation);
  9868. const path = [];
  9869. editor.paths.push(path);
  9870. let p0 = scaleFactor * (bezier[0] - padding);
  9871. let p1 = scaleFactor * (bezier[1] - padding);
  9872. for (let i = 2, ii = bezier.length; i < ii; i += 6) {
  9873. const p10 = scaleFactor * (bezier[i] - padding);
  9874. const p11 = scaleFactor * (bezier[i + 1] - padding);
  9875. const p20 = scaleFactor * (bezier[i + 2] - padding);
  9876. const p21 = scaleFactor * (bezier[i + 3] - padding);
  9877. const p30 = scaleFactor * (bezier[i + 4] - padding);
  9878. const p31 = scaleFactor * (bezier[i + 5] - padding);
  9879. path.push([[p0, p1], [p10, p11], [p20, p21], [p30, p31]]);
  9880. p0 = p30;
  9881. p1 = p31;
  9882. }
  9883. const path2D = this.#buildPath2D(path);
  9884. editor.bezierPath2D.push(path2D);
  9885. }
  9886. const bbox = editor.#getBbox();
  9887. editor.#baseWidth = Math.max(editor_editor.AnnotationEditor.MIN_SIZE, bbox[2] - bbox[0]);
  9888. editor.#baseHeight = Math.max(editor_editor.AnnotationEditor.MIN_SIZE, bbox[3] - bbox[1]);
  9889. editor.#setScaleFactor(width, height);
  9890. return editor;
  9891. }
  9892. serialize() {
  9893. if (this.isEmpty()) {
  9894. return null;
  9895. }
  9896. const rect = this.getRect(0, 0);
  9897. const color = editor_editor.AnnotationEditor._colorManager.convert(this.ctx.strokeStyle);
  9898. return {
  9899. annotationType: util.AnnotationEditorType.INK,
  9900. color,
  9901. thickness: this.thickness,
  9902. opacity: this.opacity,
  9903. paths: this.#serializePaths(this.scaleFactor / this.parentScale, this.translationX, this.translationY, rect),
  9904. pageIndex: this.pageIndex,
  9905. rect,
  9906. rotation: this.rotation,
  9907. structTreeParentId: this._structTreeParentId
  9908. };
  9909. }
  9910. }
  9911. ;// CONCATENATED MODULE: ./src/display/editor/stamp.js
  9912. class StampEditor extends editor_editor.AnnotationEditor {
  9913. #bitmap = null;
  9914. #bitmapId = null;
  9915. #bitmapPromise = null;
  9916. #bitmapUrl = null;
  9917. #bitmapFile = null;
  9918. #bitmapFileName = "";
  9919. #canvas = null;
  9920. #observer = null;
  9921. #resizeTimeoutId = null;
  9922. #isSvg = false;
  9923. #hasBeenAddedInUndoStack = false;
  9924. static _type = "stamp";
  9925. static _editorType = util.AnnotationEditorType.STAMP;
  9926. constructor(params) {
  9927. super({
  9928. ...params,
  9929. name: "stampEditor"
  9930. });
  9931. this.#bitmapUrl = params.bitmapUrl;
  9932. this.#bitmapFile = params.bitmapFile;
  9933. }
  9934. static initialize(l10n) {
  9935. editor_editor.AnnotationEditor.initialize(l10n);
  9936. }
  9937. static get supportedTypes() {
  9938. const types = ["apng", "avif", "bmp", "gif", "jpeg", "png", "svg+xml", "webp", "x-icon"];
  9939. return (0,util.shadow)(this, "supportedTypes", types.map(type => `image/${type}`));
  9940. }
  9941. static get supportedTypesStr() {
  9942. return (0,util.shadow)(this, "supportedTypesStr", this.supportedTypes.join(","));
  9943. }
  9944. static isHandlingMimeForPasting(mime) {
  9945. return this.supportedTypes.includes(mime);
  9946. }
  9947. static paste(item, parent) {
  9948. parent.pasteEditor(util.AnnotationEditorType.STAMP, {
  9949. bitmapFile: item.getAsFile()
  9950. });
  9951. }
  9952. #getBitmapFetched(data, fromId = false) {
  9953. if (!data) {
  9954. this.remove();
  9955. return;
  9956. }
  9957. this.#bitmap = data.bitmap;
  9958. if (!fromId) {
  9959. this.#bitmapId = data.id;
  9960. this.#isSvg = data.isSvg;
  9961. }
  9962. if (data.file) {
  9963. this.#bitmapFileName = data.file.name;
  9964. }
  9965. this.#createCanvas();
  9966. }
  9967. #getBitmapDone() {
  9968. this.#bitmapPromise = null;
  9969. this._uiManager.enableWaiting(false);
  9970. if (this.#canvas) {
  9971. this.div.focus();
  9972. }
  9973. }
  9974. #getBitmap() {
  9975. if (this.#bitmapId) {
  9976. this._uiManager.enableWaiting(true);
  9977. this._uiManager.imageManager.getFromId(this.#bitmapId).then(data => this.#getBitmapFetched(data, true)).finally(() => this.#getBitmapDone());
  9978. return;
  9979. }
  9980. if (this.#bitmapUrl) {
  9981. const url = this.#bitmapUrl;
  9982. this.#bitmapUrl = null;
  9983. this._uiManager.enableWaiting(true);
  9984. this.#bitmapPromise = this._uiManager.imageManager.getFromUrl(url).then(data => this.#getBitmapFetched(data)).finally(() => this.#getBitmapDone());
  9985. return;
  9986. }
  9987. if (this.#bitmapFile) {
  9988. const file = this.#bitmapFile;
  9989. this.#bitmapFile = null;
  9990. this._uiManager.enableWaiting(true);
  9991. this.#bitmapPromise = this._uiManager.imageManager.getFromFile(file).then(data => this.#getBitmapFetched(data)).finally(() => this.#getBitmapDone());
  9992. return;
  9993. }
  9994. const input = document.createElement("input");
  9995. input.type = "file";
  9996. input.accept = StampEditor.supportedTypesStr;
  9997. this.#bitmapPromise = new Promise(resolve => {
  9998. input.addEventListener("change", async () => {
  9999. if (!input.files || input.files.length === 0) {
  10000. this.remove();
  10001. } else {
  10002. this._uiManager.enableWaiting(true);
  10003. const data = await this._uiManager.imageManager.getFromFile(input.files[0]);
  10004. this.#getBitmapFetched(data);
  10005. }
  10006. resolve();
  10007. });
  10008. input.addEventListener("cancel", () => {
  10009. this.remove();
  10010. resolve();
  10011. });
  10012. }).finally(() => this.#getBitmapDone());
  10013. input.click();
  10014. }
  10015. remove() {
  10016. if (this.#bitmapId) {
  10017. this.#bitmap = null;
  10018. this._uiManager.imageManager.deleteId(this.#bitmapId);
  10019. this.#canvas?.remove();
  10020. this.#canvas = null;
  10021. this.#observer?.disconnect();
  10022. this.#observer = null;
  10023. if (this.#resizeTimeoutId) {
  10024. clearTimeout(this.#resizeTimeoutId);
  10025. this.#resizeTimeoutId = null;
  10026. }
  10027. }
  10028. super.remove();
  10029. }
  10030. rebuild() {
  10031. if (!this.parent) {
  10032. if (this.#bitmapId) {
  10033. this.#getBitmap();
  10034. }
  10035. return;
  10036. }
  10037. super.rebuild();
  10038. if (this.div === null) {
  10039. return;
  10040. }
  10041. if (this.#bitmapId) {
  10042. this.#getBitmap();
  10043. }
  10044. if (!this.isAttachedToDOM) {
  10045. this.parent.add(this);
  10046. }
  10047. }
  10048. onceAdded() {
  10049. this._isDraggable = true;
  10050. this.div.focus();
  10051. }
  10052. isEmpty() {
  10053. return !(this.#bitmapPromise || this.#bitmap || this.#bitmapUrl || this.#bitmapFile);
  10054. }
  10055. get isResizable() {
  10056. return true;
  10057. }
  10058. render() {
  10059. if (this.div) {
  10060. return this.div;
  10061. }
  10062. let baseX, baseY;
  10063. if (this.width) {
  10064. baseX = this.x;
  10065. baseY = this.y;
  10066. }
  10067. super.render();
  10068. this.div.hidden = true;
  10069. if (this.#bitmap) {
  10070. this.#createCanvas();
  10071. } else {
  10072. this.#getBitmap();
  10073. }
  10074. if (this.width) {
  10075. const [parentWidth, parentHeight] = this.parentDimensions;
  10076. this.setAt(baseX * parentWidth, baseY * parentHeight, this.width * parentWidth, this.height * parentHeight);
  10077. }
  10078. return this.div;
  10079. }
  10080. #createCanvas() {
  10081. const {
  10082. div
  10083. } = this;
  10084. let {
  10085. width,
  10086. height
  10087. } = this.#bitmap;
  10088. const [pageWidth, pageHeight] = this.pageDimensions;
  10089. const MAX_RATIO = 0.75;
  10090. if (this.width) {
  10091. width = this.width * pageWidth;
  10092. height = this.height * pageHeight;
  10093. } else if (width > MAX_RATIO * pageWidth || height > MAX_RATIO * pageHeight) {
  10094. const factor = Math.min(MAX_RATIO * pageWidth / width, MAX_RATIO * pageHeight / height);
  10095. width *= factor;
  10096. height *= factor;
  10097. }
  10098. const [parentWidth, parentHeight] = this.parentDimensions;
  10099. this.setDims(width * parentWidth / pageWidth, height * parentHeight / pageHeight);
  10100. this._uiManager.enableWaiting(false);
  10101. const canvas = this.#canvas = document.createElement("canvas");
  10102. div.append(canvas);
  10103. div.hidden = false;
  10104. this.#drawBitmap(width, height);
  10105. this.#createObserver();
  10106. if (!this.#hasBeenAddedInUndoStack) {
  10107. this.parent.addUndoableEditor(this);
  10108. this.#hasBeenAddedInUndoStack = true;
  10109. }
  10110. this._uiManager._eventBus.dispatch("reporttelemetry", {
  10111. source: this,
  10112. details: {
  10113. type: "editing",
  10114. subtype: this.editorType,
  10115. data: {
  10116. action: "inserted_image"
  10117. }
  10118. }
  10119. });
  10120. this.addAltTextButton();
  10121. if (this.#bitmapFileName) {
  10122. canvas.setAttribute("aria-label", this.#bitmapFileName);
  10123. }
  10124. }
  10125. #setDimensions(width, height) {
  10126. const [parentWidth, parentHeight] = this.parentDimensions;
  10127. this.width = width / parentWidth;
  10128. this.height = height / parentHeight;
  10129. this.setDims(width, height);
  10130. if (this._initialOptions?.isCentered) {
  10131. this.center();
  10132. } else {
  10133. this.fixAndSetPosition();
  10134. }
  10135. this._initialOptions = null;
  10136. if (this.#resizeTimeoutId !== null) {
  10137. clearTimeout(this.#resizeTimeoutId);
  10138. }
  10139. const TIME_TO_WAIT = 200;
  10140. this.#resizeTimeoutId = setTimeout(() => {
  10141. this.#resizeTimeoutId = null;
  10142. this.#drawBitmap(width, height);
  10143. }, TIME_TO_WAIT);
  10144. }
  10145. #scaleBitmap(width, height) {
  10146. const {
  10147. width: bitmapWidth,
  10148. height: bitmapHeight
  10149. } = this.#bitmap;
  10150. let newWidth = bitmapWidth;
  10151. let newHeight = bitmapHeight;
  10152. let bitmap = this.#bitmap;
  10153. while (newWidth > 2 * width || newHeight > 2 * height) {
  10154. const prevWidth = newWidth;
  10155. const prevHeight = newHeight;
  10156. if (newWidth > 2 * width) {
  10157. newWidth = newWidth >= 16384 ? Math.floor(newWidth / 2) - 1 : Math.ceil(newWidth / 2);
  10158. }
  10159. if (newHeight > 2 * height) {
  10160. newHeight = newHeight >= 16384 ? Math.floor(newHeight / 2) - 1 : Math.ceil(newHeight / 2);
  10161. }
  10162. const offscreen = new OffscreenCanvas(newWidth, newHeight);
  10163. const ctx = offscreen.getContext("2d");
  10164. ctx.drawImage(bitmap, 0, 0, prevWidth, prevHeight, 0, 0, newWidth, newHeight);
  10165. bitmap = offscreen.transferToImageBitmap();
  10166. }
  10167. return bitmap;
  10168. }
  10169. #drawBitmap(width, height) {
  10170. width = Math.ceil(width);
  10171. height = Math.ceil(height);
  10172. const canvas = this.#canvas;
  10173. if (!canvas || canvas.width === width && canvas.height === height) {
  10174. return;
  10175. }
  10176. canvas.width = width;
  10177. canvas.height = height;
  10178. const bitmap = this.#isSvg ? this.#bitmap : this.#scaleBitmap(width, height);
  10179. const ctx = canvas.getContext("2d");
  10180. ctx.filter = this._uiManager.hcmFilter;
  10181. ctx.drawImage(bitmap, 0, 0, bitmap.width, bitmap.height, 0, 0, width, height);
  10182. }
  10183. getImageForAltText() {
  10184. return this.#canvas;
  10185. }
  10186. #serializeBitmap(toUrl) {
  10187. if (toUrl) {
  10188. if (this.#isSvg) {
  10189. const url = this._uiManager.imageManager.getSvgUrl(this.#bitmapId);
  10190. if (url) {
  10191. return url;
  10192. }
  10193. }
  10194. const canvas = document.createElement("canvas");
  10195. ({
  10196. width: canvas.width,
  10197. height: canvas.height
  10198. } = this.#bitmap);
  10199. const ctx = canvas.getContext("2d");
  10200. ctx.drawImage(this.#bitmap, 0, 0);
  10201. return canvas.toDataURL();
  10202. }
  10203. if (this.#isSvg) {
  10204. const [pageWidth, pageHeight] = this.pageDimensions;
  10205. const width = Math.round(this.width * pageWidth * display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  10206. const height = Math.round(this.height * pageHeight * display_utils.PixelsPerInch.PDF_TO_CSS_UNITS);
  10207. const offscreen = new OffscreenCanvas(width, height);
  10208. const ctx = offscreen.getContext("2d");
  10209. ctx.drawImage(this.#bitmap, 0, 0, this.#bitmap.width, this.#bitmap.height, 0, 0, width, height);
  10210. return offscreen.transferToImageBitmap();
  10211. }
  10212. return structuredClone(this.#bitmap);
  10213. }
  10214. #createObserver() {
  10215. this.#observer = new ResizeObserver(entries => {
  10216. const rect = entries[0].contentRect;
  10217. if (rect.width && rect.height) {
  10218. this.#setDimensions(rect.width, rect.height);
  10219. }
  10220. });
  10221. this.#observer.observe(this.div);
  10222. }
  10223. static deserialize(data, parent, uiManager) {
  10224. if (data instanceof annotation_layer.StampAnnotationElement) {
  10225. return null;
  10226. }
  10227. const editor = super.deserialize(data, parent, uiManager);
  10228. const {
  10229. rect,
  10230. bitmapUrl,
  10231. bitmapId,
  10232. isSvg,
  10233. accessibilityData
  10234. } = data;
  10235. if (bitmapId && uiManager.imageManager.isValidId(bitmapId)) {
  10236. editor.#bitmapId = bitmapId;
  10237. } else {
  10238. editor.#bitmapUrl = bitmapUrl;
  10239. }
  10240. editor.#isSvg = isSvg;
  10241. const [parentWidth, parentHeight] = editor.pageDimensions;
  10242. editor.width = (rect[2] - rect[0]) / parentWidth;
  10243. editor.height = (rect[3] - rect[1]) / parentHeight;
  10244. if (accessibilityData) {
  10245. editor.altTextData = accessibilityData;
  10246. }
  10247. return editor;
  10248. }
  10249. serialize(isForCopying = false, context = null) {
  10250. if (this.isEmpty()) {
  10251. return null;
  10252. }
  10253. const serialized = {
  10254. annotationType: util.AnnotationEditorType.STAMP,
  10255. bitmapId: this.#bitmapId,
  10256. pageIndex: this.pageIndex,
  10257. rect: this.getRect(0, 0),
  10258. rotation: this.rotation,
  10259. isSvg: this.#isSvg,
  10260. structTreeParentId: this._structTreeParentId
  10261. };
  10262. if (isForCopying) {
  10263. serialized.bitmapUrl = this.#serializeBitmap(true);
  10264. serialized.accessibilityData = this.altTextData;
  10265. return serialized;
  10266. }
  10267. const {
  10268. decorative,
  10269. altText
  10270. } = this.altTextData;
  10271. if (!decorative && altText) {
  10272. serialized.accessibilityData = {
  10273. type: "Figure",
  10274. alt: altText
  10275. };
  10276. }
  10277. if (context === null) {
  10278. return serialized;
  10279. }
  10280. context.stamps ||= new Map();
  10281. const area = this.#isSvg ? (serialized.rect[2] - serialized.rect[0]) * (serialized.rect[3] - serialized.rect[1]) : null;
  10282. if (!context.stamps.has(this.#bitmapId)) {
  10283. context.stamps.set(this.#bitmapId, {
  10284. area,
  10285. serialized
  10286. });
  10287. serialized.bitmap = this.#serializeBitmap(false);
  10288. } else if (this.#isSvg) {
  10289. const prevData = context.stamps.get(this.#bitmapId);
  10290. if (area > prevData.area) {
  10291. prevData.area = area;
  10292. prevData.serialized.bitmap.close();
  10293. prevData.serialized.bitmap = this.#serializeBitmap(false);
  10294. }
  10295. }
  10296. return serialized;
  10297. }
  10298. }
  10299. ;// CONCATENATED MODULE: ./src/display/editor/annotation_editor_layer.js
  10300. class AnnotationEditorLayer {
  10301. #accessibilityManager;
  10302. #allowClick = false;
  10303. #annotationLayer = null;
  10304. #boundPointerup = this.pointerup.bind(this);
  10305. #boundPointerUpAfterSelection = this.pointerUpAfterSelection.bind(this);
  10306. #boundPointerdown = this.pointerdown.bind(this);
  10307. #editorFocusTimeoutId = null;
  10308. #boundSelectionStart = this.selectionStart.bind(this);
  10309. #editors = new Map();
  10310. #hadPointerDown = false;
  10311. #isCleaningUp = false;
  10312. #isDisabling = false;
  10313. #textLayer = null;
  10314. #uiManager;
  10315. static _initialized = false;
  10316. static #editorTypes = new Map([FreeTextEditor, InkEditor, StampEditor, HighlightEditor].map(type => [type._editorType, type]));
  10317. constructor({
  10318. uiManager,
  10319. pageIndex,
  10320. div,
  10321. accessibilityManager,
  10322. annotationLayer,
  10323. drawLayer,
  10324. textLayer,
  10325. viewport,
  10326. l10n
  10327. }) {
  10328. const editorTypes = [...AnnotationEditorLayer.#editorTypes.values()];
  10329. if (!AnnotationEditorLayer._initialized) {
  10330. AnnotationEditorLayer._initialized = true;
  10331. for (const editorType of editorTypes) {
  10332. editorType.initialize(l10n);
  10333. }
  10334. }
  10335. uiManager.registerEditorTypes(editorTypes);
  10336. this.#uiManager = uiManager;
  10337. this.pageIndex = pageIndex;
  10338. this.div = div;
  10339. this.#accessibilityManager = accessibilityManager;
  10340. this.#annotationLayer = annotationLayer;
  10341. this.viewport = viewport;
  10342. this.#textLayer = textLayer;
  10343. this.drawLayer = drawLayer;
  10344. this.#uiManager.addLayer(this);
  10345. }
  10346. get isEmpty() {
  10347. return this.#editors.size === 0;
  10348. }
  10349. updateToolbar(mode) {
  10350. this.#uiManager.updateToolbar(mode);
  10351. }
  10352. updateMode(mode = this.#uiManager.getMode()) {
  10353. this.#cleanup();
  10354. switch (mode) {
  10355. case util.AnnotationEditorType.NONE:
  10356. this.disableTextSelection();
  10357. this.togglePointerEvents(false);
  10358. this.disableClick();
  10359. break;
  10360. case util.AnnotationEditorType.INK:
  10361. this.addInkEditorIfNeeded(false);
  10362. this.disableTextSelection();
  10363. this.togglePointerEvents(true);
  10364. this.disableClick();
  10365. break;
  10366. case util.AnnotationEditorType.HIGHLIGHT:
  10367. this.enableTextSelection();
  10368. this.togglePointerEvents(false);
  10369. this.disableClick();
  10370. break;
  10371. default:
  10372. this.disableTextSelection();
  10373. this.togglePointerEvents(true);
  10374. this.enableClick();
  10375. }
  10376. if (mode !== util.AnnotationEditorType.NONE) {
  10377. const {
  10378. classList
  10379. } = this.div;
  10380. for (const editorType of AnnotationEditorLayer.#editorTypes.values()) {
  10381. classList.toggle(`${editorType._type}Editing`, mode === editorType._editorType);
  10382. }
  10383. this.div.hidden = false;
  10384. }
  10385. }
  10386. addInkEditorIfNeeded(isCommitting) {
  10387. if (this.#uiManager.getMode() !== util.AnnotationEditorType.INK) {
  10388. return;
  10389. }
  10390. if (!isCommitting) {
  10391. for (const editor of this.#editors.values()) {
  10392. if (editor.isEmpty()) {
  10393. editor.setInBackground();
  10394. return;
  10395. }
  10396. }
  10397. }
  10398. const editor = this.#createAndAddNewEditor({
  10399. offsetX: 0,
  10400. offsetY: 0
  10401. }, false);
  10402. editor.setInBackground();
  10403. }
  10404. setEditingState(isEditing) {
  10405. this.#uiManager.setEditingState(isEditing);
  10406. }
  10407. addCommands(params) {
  10408. this.#uiManager.addCommands(params);
  10409. }
  10410. togglePointerEvents(enabled = false) {
  10411. this.div.classList.toggle("disabled", !enabled);
  10412. }
  10413. enable() {
  10414. this.togglePointerEvents(true);
  10415. const annotationElementIds = new Set();
  10416. for (const editor of this.#editors.values()) {
  10417. editor.enableEditing();
  10418. if (editor.annotationElementId) {
  10419. annotationElementIds.add(editor.annotationElementId);
  10420. }
  10421. }
  10422. if (!this.#annotationLayer) {
  10423. return;
  10424. }
  10425. const editables = this.#annotationLayer.getEditableAnnotations();
  10426. for (const editable of editables) {
  10427. editable.hide();
  10428. if (this.#uiManager.isDeletedAnnotationElement(editable.data.id)) {
  10429. continue;
  10430. }
  10431. if (annotationElementIds.has(editable.data.id)) {
  10432. continue;
  10433. }
  10434. const editor = this.deserialize(editable);
  10435. if (!editor) {
  10436. continue;
  10437. }
  10438. this.addOrRebuild(editor);
  10439. editor.enableEditing();
  10440. }
  10441. }
  10442. disable() {
  10443. this.#isDisabling = true;
  10444. this.togglePointerEvents(false);
  10445. const hiddenAnnotationIds = new Set();
  10446. for (const editor of this.#editors.values()) {
  10447. editor.disableEditing();
  10448. if (!editor.annotationElementId || editor.serialize() !== null) {
  10449. hiddenAnnotationIds.add(editor.annotationElementId);
  10450. continue;
  10451. }
  10452. this.getEditableAnnotation(editor.annotationElementId)?.show();
  10453. editor.remove();
  10454. }
  10455. if (this.#annotationLayer) {
  10456. const editables = this.#annotationLayer.getEditableAnnotations();
  10457. for (const editable of editables) {
  10458. const {
  10459. id
  10460. } = editable.data;
  10461. if (hiddenAnnotationIds.has(id) || this.#uiManager.isDeletedAnnotationElement(id)) {
  10462. continue;
  10463. }
  10464. editable.show();
  10465. }
  10466. }
  10467. this.#cleanup();
  10468. if (this.isEmpty) {
  10469. this.div.hidden = true;
  10470. }
  10471. const {
  10472. classList
  10473. } = this.div;
  10474. for (const editorType of AnnotationEditorLayer.#editorTypes.values()) {
  10475. classList.remove(`${editorType._type}Editing`);
  10476. }
  10477. this.disableTextSelection();
  10478. this.#isDisabling = false;
  10479. }
  10480. getEditableAnnotation(id) {
  10481. return this.#annotationLayer?.getEditableAnnotation(id) || null;
  10482. }
  10483. setActiveEditor(editor) {
  10484. const currentActive = this.#uiManager.getActive();
  10485. if (currentActive === editor) {
  10486. return;
  10487. }
  10488. this.#uiManager.setActiveEditor(editor);
  10489. }
  10490. enableTextSelection() {
  10491. if (this.#textLayer?.div) {
  10492. document.addEventListener("selectstart", this.#boundSelectionStart);
  10493. }
  10494. }
  10495. disableTextSelection() {
  10496. if (this.#textLayer?.div) {
  10497. document.removeEventListener("selectstart", this.#boundSelectionStart);
  10498. }
  10499. }
  10500. enableClick() {
  10501. this.div.addEventListener("pointerdown", this.#boundPointerdown);
  10502. this.div.addEventListener("pointerup", this.#boundPointerup);
  10503. }
  10504. disableClick() {
  10505. this.div.removeEventListener("pointerdown", this.#boundPointerdown);
  10506. this.div.removeEventListener("pointerup", this.#boundPointerup);
  10507. }
  10508. attach(editor) {
  10509. this.#editors.set(editor.id, editor);
  10510. const {
  10511. annotationElementId
  10512. } = editor;
  10513. if (annotationElementId && this.#uiManager.isDeletedAnnotationElement(annotationElementId)) {
  10514. this.#uiManager.removeDeletedAnnotationElement(editor);
  10515. }
  10516. }
  10517. detach(editor) {
  10518. this.#editors.delete(editor.id);
  10519. this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
  10520. if (!this.#isDisabling && editor.annotationElementId) {
  10521. this.#uiManager.addDeletedAnnotationElement(editor);
  10522. }
  10523. }
  10524. remove(editor) {
  10525. this.detach(editor);
  10526. this.#uiManager.removeEditor(editor);
  10527. editor.div.remove();
  10528. editor.isAttachedToDOM = false;
  10529. if (!this.#isCleaningUp) {
  10530. this.addInkEditorIfNeeded(false);
  10531. }
  10532. }
  10533. changeParent(editor) {
  10534. if (editor.parent === this) {
  10535. return;
  10536. }
  10537. if (editor.annotationElementId) {
  10538. this.#uiManager.addDeletedAnnotationElement(editor.annotationElementId);
  10539. editor_editor.AnnotationEditor.deleteAnnotationElement(editor);
  10540. editor.annotationElementId = null;
  10541. }
  10542. this.attach(editor);
  10543. editor.parent?.detach(editor);
  10544. editor.setParent(this);
  10545. if (editor.div && editor.isAttachedToDOM) {
  10546. editor.div.remove();
  10547. this.div.append(editor.div);
  10548. }
  10549. }
  10550. add(editor) {
  10551. this.changeParent(editor);
  10552. this.#uiManager.addEditor(editor);
  10553. this.attach(editor);
  10554. if (!editor.isAttachedToDOM) {
  10555. const div = editor.render();
  10556. this.div.append(div);
  10557. editor.isAttachedToDOM = true;
  10558. }
  10559. editor.fixAndSetPosition();
  10560. editor.onceAdded();
  10561. this.#uiManager.addToAnnotationStorage(editor);
  10562. }
  10563. moveEditorInDOM(editor) {
  10564. if (!editor.isAttachedToDOM) {
  10565. return;
  10566. }
  10567. const {
  10568. activeElement
  10569. } = document;
  10570. if (editor.div.contains(activeElement) && !this.#editorFocusTimeoutId) {
  10571. editor._focusEventsAllowed = false;
  10572. this.#editorFocusTimeoutId = setTimeout(() => {
  10573. this.#editorFocusTimeoutId = null;
  10574. if (!editor.div.contains(document.activeElement)) {
  10575. editor.div.addEventListener("focusin", () => {
  10576. editor._focusEventsAllowed = true;
  10577. }, {
  10578. once: true
  10579. });
  10580. activeElement.focus();
  10581. } else {
  10582. editor._focusEventsAllowed = true;
  10583. }
  10584. }, 0);
  10585. }
  10586. editor._structTreeParentId = this.#accessibilityManager?.moveElementInDOM(this.div, editor.div, editor.contentDiv, true);
  10587. }
  10588. addOrRebuild(editor) {
  10589. if (editor.needsToBeRebuilt()) {
  10590. editor.parent ||= this;
  10591. editor.rebuild();
  10592. } else {
  10593. this.add(editor);
  10594. }
  10595. }
  10596. addUndoableEditor(editor) {
  10597. const cmd = () => editor._uiManager.rebuild(editor);
  10598. const undo = () => {
  10599. editor.remove();
  10600. };
  10601. this.addCommands({
  10602. cmd,
  10603. undo,
  10604. mustExec: false
  10605. });
  10606. }
  10607. getNextId() {
  10608. return this.#uiManager.getId();
  10609. }
  10610. get #currentEditorType() {
  10611. return AnnotationEditorLayer.#editorTypes.get(this.#uiManager.getMode());
  10612. }
  10613. #createNewEditor(params) {
  10614. const editorType = this.#currentEditorType;
  10615. return editorType ? new editorType.prototype.constructor(params) : null;
  10616. }
  10617. canCreateNewEmptyEditor() {
  10618. return this.#currentEditorType?.canCreateNewEmptyEditor();
  10619. }
  10620. pasteEditor(mode, params) {
  10621. this.#uiManager.updateToolbar(mode);
  10622. this.#uiManager.updateMode(mode);
  10623. const {
  10624. offsetX,
  10625. offsetY
  10626. } = this.#getCenterPoint();
  10627. const id = this.getNextId();
  10628. const editor = this.#createNewEditor({
  10629. parent: this,
  10630. id,
  10631. x: offsetX,
  10632. y: offsetY,
  10633. uiManager: this.#uiManager,
  10634. isCentered: true,
  10635. ...params
  10636. });
  10637. if (editor) {
  10638. this.add(editor);
  10639. }
  10640. }
  10641. deserialize(data) {
  10642. return AnnotationEditorLayer.#editorTypes.get(data.annotationType ?? data.annotationEditorType)?.deserialize(data, this, this.#uiManager) || null;
  10643. }
  10644. #createAndAddNewEditor(event, isCentered, data = {}) {
  10645. const id = this.getNextId();
  10646. const editor = this.#createNewEditor({
  10647. parent: this,
  10648. id,
  10649. x: event.offsetX,
  10650. y: event.offsetY,
  10651. uiManager: this.#uiManager,
  10652. isCentered,
  10653. ...data
  10654. });
  10655. if (editor) {
  10656. this.add(editor);
  10657. }
  10658. return editor;
  10659. }
  10660. #getCenterPoint() {
  10661. const {
  10662. x,
  10663. y,
  10664. width,
  10665. height
  10666. } = this.div.getBoundingClientRect();
  10667. const tlX = Math.max(0, x);
  10668. const tlY = Math.max(0, y);
  10669. const brX = Math.min(window.innerWidth, x + width);
  10670. const brY = Math.min(window.innerHeight, y + height);
  10671. const centerX = (tlX + brX) / 2 - x;
  10672. const centerY = (tlY + brY) / 2 - y;
  10673. const [offsetX, offsetY] = this.viewport.rotation % 180 === 0 ? [centerX, centerY] : [centerY, centerX];
  10674. return {
  10675. offsetX,
  10676. offsetY
  10677. };
  10678. }
  10679. addNewEditor() {
  10680. this.#createAndAddNewEditor(this.#getCenterPoint(), true);
  10681. }
  10682. setSelected(editor) {
  10683. this.#uiManager.setSelected(editor);
  10684. }
  10685. toggleSelected(editor) {
  10686. this.#uiManager.toggleSelected(editor);
  10687. }
  10688. isSelected(editor) {
  10689. return this.#uiManager.isSelected(editor);
  10690. }
  10691. unselect(editor) {
  10692. this.#uiManager.unselect(editor);
  10693. }
  10694. selectionStart(_event) {
  10695. this.#textLayer?.div.addEventListener("pointerup", this.#boundPointerUpAfterSelection, {
  10696. once: true
  10697. });
  10698. }
  10699. pointerUpAfterSelection(event) {
  10700. const selection = document.getSelection();
  10701. if (selection.rangeCount === 0) {
  10702. return;
  10703. }
  10704. const range = selection.getRangeAt(0);
  10705. if (range.collapsed) {
  10706. return;
  10707. }
  10708. if (!this.#textLayer?.div.contains(range.commonAncestorContainer)) {
  10709. return;
  10710. }
  10711. const {
  10712. x: layerX,
  10713. y: layerY,
  10714. width: parentWidth,
  10715. height: parentHeight
  10716. } = this.#textLayer.div.getBoundingClientRect();
  10717. const bboxes = range.getClientRects();
  10718. let rotator;
  10719. switch (this.viewport.rotation) {
  10720. case 90:
  10721. rotator = (x, y, w, h) => ({
  10722. x: (y - layerY) / parentHeight,
  10723. y: 1 - (x + w - layerX) / parentWidth,
  10724. width: h / parentHeight,
  10725. height: w / parentWidth
  10726. });
  10727. break;
  10728. case 180:
  10729. rotator = (x, y, w, h) => ({
  10730. x: 1 - (x + w - layerX) / parentWidth,
  10731. y: 1 - (y + h - layerY) / parentHeight,
  10732. width: w / parentWidth,
  10733. height: h / parentHeight
  10734. });
  10735. break;
  10736. case 270:
  10737. rotator = (x, y, w, h) => ({
  10738. x: 1 - (y + h - layerY) / parentHeight,
  10739. y: (x - layerX) / parentWidth,
  10740. width: h / parentHeight,
  10741. height: w / parentWidth
  10742. });
  10743. break;
  10744. default:
  10745. rotator = (x, y, w, h) => ({
  10746. x: (x - layerX) / parentWidth,
  10747. y: (y - layerY) / parentHeight,
  10748. width: w / parentWidth,
  10749. height: h / parentHeight
  10750. });
  10751. break;
  10752. }
  10753. const boxes = [];
  10754. for (const {
  10755. x,
  10756. y,
  10757. width,
  10758. height
  10759. } of bboxes) {
  10760. if (width === 0 || height === 0) {
  10761. continue;
  10762. }
  10763. boxes.push(rotator(x, y, width, height));
  10764. }
  10765. if (boxes.length !== 0) {
  10766. this.#createAndAddNewEditor(event, false, {
  10767. boxes
  10768. });
  10769. }
  10770. selection.empty();
  10771. }
  10772. pointerup(event) {
  10773. const {
  10774. isMac
  10775. } = util.FeatureTest.platform;
  10776. if (event.button !== 0 || event.ctrlKey && isMac) {
  10777. return;
  10778. }
  10779. if (event.target !== this.div) {
  10780. return;
  10781. }
  10782. if (!this.#hadPointerDown) {
  10783. return;
  10784. }
  10785. this.#hadPointerDown = false;
  10786. if (!this.#allowClick) {
  10787. this.#allowClick = true;
  10788. return;
  10789. }
  10790. if (this.#uiManager.getMode() === util.AnnotationEditorType.STAMP) {
  10791. this.#uiManager.unselectAll();
  10792. return;
  10793. }
  10794. this.#createAndAddNewEditor(event, false);
  10795. }
  10796. pointerdown(event) {
  10797. if (this.#uiManager.getMode() === util.AnnotationEditorType.HIGHLIGHT) {
  10798. this.enableTextSelection();
  10799. }
  10800. if (this.#hadPointerDown) {
  10801. this.#hadPointerDown = false;
  10802. return;
  10803. }
  10804. const {
  10805. isMac
  10806. } = util.FeatureTest.platform;
  10807. if (event.button !== 0 || event.ctrlKey && isMac) {
  10808. return;
  10809. }
  10810. if (event.target !== this.div) {
  10811. return;
  10812. }
  10813. this.#hadPointerDown = true;
  10814. const editor = this.#uiManager.getActive();
  10815. this.#allowClick = !editor || editor.isEmpty();
  10816. }
  10817. findNewParent(editor, x, y) {
  10818. const layer = this.#uiManager.findParent(x, y);
  10819. if (layer === null || layer === this) {
  10820. return false;
  10821. }
  10822. layer.changeParent(editor);
  10823. return true;
  10824. }
  10825. destroy() {
  10826. if (this.#uiManager.getActive()?.parent === this) {
  10827. this.#uiManager.commitOrRemove();
  10828. this.#uiManager.setActiveEditor(null);
  10829. }
  10830. if (this.#editorFocusTimeoutId) {
  10831. clearTimeout(this.#editorFocusTimeoutId);
  10832. this.#editorFocusTimeoutId = null;
  10833. }
  10834. for (const editor of this.#editors.values()) {
  10835. this.#accessibilityManager?.removePointerInTextLayer(editor.contentDiv);
  10836. editor.setParent(null);
  10837. editor.isAttachedToDOM = false;
  10838. editor.div.remove();
  10839. }
  10840. this.div = null;
  10841. this.#editors.clear();
  10842. this.#uiManager.removeLayer(this);
  10843. }
  10844. #cleanup() {
  10845. this.#isCleaningUp = true;
  10846. for (const editor of this.#editors.values()) {
  10847. if (editor.isEmpty()) {
  10848. editor.remove();
  10849. }
  10850. }
  10851. this.#isCleaningUp = false;
  10852. }
  10853. render({
  10854. viewport
  10855. }) {
  10856. this.viewport = viewport;
  10857. (0,display_utils.setLayerDimensions)(this.div, viewport);
  10858. for (const editor of this.#uiManager.getEditors(this.pageIndex)) {
  10859. this.add(editor);
  10860. }
  10861. this.updateMode();
  10862. }
  10863. update({
  10864. viewport
  10865. }) {
  10866. this.#uiManager.commitOrRemove();
  10867. const oldRotation = this.viewport.rotation;
  10868. const rotation = viewport.rotation;
  10869. this.viewport = viewport;
  10870. (0,display_utils.setLayerDimensions)(this.div, {
  10871. rotation
  10872. });
  10873. if (oldRotation !== rotation) {
  10874. for (const editor of this.#editors.values()) {
  10875. editor.rotate(rotation);
  10876. }
  10877. }
  10878. this.updateMode();
  10879. }
  10880. get pageDimensions() {
  10881. const {
  10882. pageWidth,
  10883. pageHeight
  10884. } = this.viewport.rawDims;
  10885. return [pageWidth, pageHeight];
  10886. }
  10887. }
  10888. /***/ }),
  10889. /***/ 97:
  10890. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  10891. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  10892. /* harmony export */ ColorPicker: () => (/* binding */ ColorPicker)
  10893. /* harmony export */ });
  10894. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  10895. /* harmony import */ var _tools_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(812);
  10896. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(473);
  10897. class ColorPicker {
  10898. #boundKeyDown = this.#keyDown.bind(this);
  10899. #button = null;
  10900. #buttonSwatch = null;
  10901. #defaultColor;
  10902. #dropdown = null;
  10903. #dropdownWasFromKeyboard = false;
  10904. #isMainColorPicker = false;
  10905. #eventBus;
  10906. #uiManager = null;
  10907. static get _keyboardManager() {
  10908. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "_keyboardManager", new _tools_js__WEBPACK_IMPORTED_MODULE_1__.KeyboardManager([[["Escape", "mac+Escape"], ColorPicker.prototype._hideDropdownFromKeyboard], [[" ", "mac+ "], ColorPicker.prototype._colorSelectFromKeyboard], [["ArrowDown", "ArrowRight", "mac+ArrowDown", "mac+ArrowRight"], ColorPicker.prototype._moveToNext], [["ArrowUp", "ArrowLeft", "mac+ArrowUp", "mac+ArrowLeft"], ColorPicker.prototype._moveToPrevious], [["Home", "mac+Home"], ColorPicker.prototype._moveToBeginning], [["End", "mac+End"], ColorPicker.prototype._moveToEnd]]));
  10909. }
  10910. constructor({
  10911. editor = null,
  10912. uiManager = null
  10913. }) {
  10914. this.#isMainColorPicker = !editor;
  10915. this.#uiManager = editor?._uiManager || uiManager;
  10916. this.#eventBus = this.#uiManager._eventBus;
  10917. this.#defaultColor = editor?.color || this.#uiManager?.highlightColors.values().next().value || "#FFFF98";
  10918. }
  10919. renderButton() {
  10920. const button = this.#button = document.createElement("button");
  10921. button.className = "colorPicker";
  10922. button.tabIndex = "0";
  10923. button.setAttribute("data-l10n-id", "pdfjs-editor-colorpicker-button");
  10924. button.setAttribute("aria-haspopup", true);
  10925. button.addEventListener("click", this.#openDropdown.bind(this));
  10926. const swatch = this.#buttonSwatch = document.createElement("span");
  10927. swatch.className = "swatch";
  10928. swatch.style.backgroundColor = this.#defaultColor;
  10929. button.append(swatch);
  10930. return button;
  10931. }
  10932. renderMainDropdown() {
  10933. const dropdown = this.#dropdown = this.#getDropdownRoot(_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR);
  10934. dropdown.setAttribute("aria-orientation", "horizontal");
  10935. dropdown.setAttribute("aria-labelledby", "highlightColorPickerLabel");
  10936. return dropdown;
  10937. }
  10938. #getDropdownRoot(paramType) {
  10939. const div = document.createElement("div");
  10940. div.addEventListener("contextmenu", _display_utils_js__WEBPACK_IMPORTED_MODULE_2__.noContextMenu);
  10941. div.className = "dropdown";
  10942. div.role = "listbox";
  10943. div.setAttribute("aria-multiselectable", false);
  10944. div.setAttribute("aria-orientation", "vertical");
  10945. div.setAttribute("data-l10n-id", "pdfjs-editor-colorpicker-dropdown");
  10946. for (const [name, color] of this.#uiManager.highlightColors) {
  10947. const button = document.createElement("button");
  10948. button.tabIndex = "0";
  10949. button.role = "option";
  10950. button.setAttribute("data-color", color);
  10951. button.title = name;
  10952. button.setAttribute("data-l10n-id", `pdfjs-editor-colorpicker-${name}`);
  10953. const swatch = document.createElement("span");
  10954. button.append(swatch);
  10955. swatch.className = "swatch";
  10956. swatch.style.backgroundColor = color;
  10957. button.setAttribute("aria-selected", color === this.#defaultColor);
  10958. button.addEventListener("click", this.#colorSelect.bind(this, paramType, color));
  10959. div.append(button);
  10960. }
  10961. div.addEventListener("keydown", this.#boundKeyDown);
  10962. return div;
  10963. }
  10964. #colorSelect(type, color, event) {
  10965. event.stopPropagation();
  10966. this.#eventBus.dispatch("switchannotationeditorparams", {
  10967. source: this,
  10968. type,
  10969. value: color
  10970. });
  10971. }
  10972. _colorSelectFromKeyboard(event) {
  10973. const color = event.target.getAttribute("data-color");
  10974. if (!color) {
  10975. return;
  10976. }
  10977. this.#colorSelect(color, event);
  10978. }
  10979. _moveToNext(event) {
  10980. if (event.target === this.#button) {
  10981. this.#dropdown.firstChild?.focus();
  10982. return;
  10983. }
  10984. event.target.nextSibling?.focus();
  10985. }
  10986. _moveToPrevious(event) {
  10987. event.target.previousSibling?.focus();
  10988. }
  10989. _moveToBeginning() {
  10990. this.#dropdown.firstChild?.focus();
  10991. }
  10992. _moveToEnd() {
  10993. this.#dropdown.lastChild?.focus();
  10994. }
  10995. #keyDown(event) {
  10996. ColorPicker._keyboardManager.exec(this, event);
  10997. }
  10998. #openDropdown(event) {
  10999. if (this.#dropdown && !this.#dropdown.classList.contains("hidden")) {
  11000. this.hideDropdown();
  11001. return;
  11002. }
  11003. this.#button.addEventListener("keydown", this.#boundKeyDown);
  11004. this.#dropdownWasFromKeyboard = event.detail === 0;
  11005. if (this.#dropdown) {
  11006. this.#dropdown.classList.remove("hidden");
  11007. return;
  11008. }
  11009. const root = this.#dropdown = this.#getDropdownRoot(_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.HIGHLIGHT_COLOR);
  11010. this.#button.append(root);
  11011. }
  11012. hideDropdown() {
  11013. this.#dropdown?.classList.add("hidden");
  11014. }
  11015. _hideDropdownFromKeyboard() {
  11016. if (this.#isMainColorPicker || !this.#dropdown || this.#dropdown.classList.contains("hidden")) {
  11017. return;
  11018. }
  11019. this.hideDropdown();
  11020. this.#button.removeEventListener("keydown", this.#boundKeyDown);
  11021. this.#button.focus({
  11022. preventScroll: true,
  11023. focusVisible: this.#dropdownWasFromKeyboard
  11024. });
  11025. }
  11026. updateColor(color) {
  11027. if (this.#buttonSwatch) {
  11028. this.#buttonSwatch.style.backgroundColor = color;
  11029. }
  11030. if (!this.#dropdown) {
  11031. return;
  11032. }
  11033. const i = this.#uiManager.highlightColors.values();
  11034. for (const child of this.#dropdown.children) {
  11035. child.setAttribute("aria-selected", i.next().value === color);
  11036. }
  11037. }
  11038. destroy() {
  11039. this.#button?.remove();
  11040. this.#button = null;
  11041. this.#buttonSwatch = null;
  11042. this.#dropdown?.remove();
  11043. this.#dropdown = null;
  11044. }
  11045. }
  11046. /***/ }),
  11047. /***/ 115:
  11048. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  11049. // EXPORTS
  11050. __webpack_require__.d(__webpack_exports__, {
  11051. AnnotationEditor: () => (/* binding */ AnnotationEditor)
  11052. });
  11053. // EXTERNAL MODULE: ./src/display/editor/tools.js
  11054. var tools = __webpack_require__(812);
  11055. // EXTERNAL MODULE: ./src/shared/util.js
  11056. var util = __webpack_require__(266);
  11057. // EXTERNAL MODULE: ./src/display/display_utils.js
  11058. var display_utils = __webpack_require__(473);
  11059. ;// CONCATENATED MODULE: ./src/display/editor/alt_text.js
  11060. class AltText {
  11061. #altText = "";
  11062. #altTextDecorative = false;
  11063. #altTextButton = null;
  11064. #altTextTooltip = null;
  11065. #altTextTooltipTimeout = null;
  11066. #altTextWasFromKeyBoard = false;
  11067. #editor = null;
  11068. static _l10nPromise = null;
  11069. constructor(editor) {
  11070. this.#editor = editor;
  11071. }
  11072. static initialize(l10nPromise) {
  11073. AltText._l10nPromise ||= l10nPromise;
  11074. }
  11075. async render() {
  11076. const altText = this.#altTextButton = document.createElement("button");
  11077. altText.className = "altText";
  11078. const msg = await AltText._l10nPromise.get("pdfjs-editor-alt-text-button-label");
  11079. altText.textContent = msg;
  11080. altText.setAttribute("aria-label", msg);
  11081. altText.tabIndex = "0";
  11082. altText.addEventListener("contextmenu", display_utils.noContextMenu);
  11083. altText.addEventListener("pointerdown", event => event.stopPropagation());
  11084. const onClick = event => {
  11085. event.preventDefault();
  11086. this.#editor._uiManager.editAltText(this.#editor);
  11087. };
  11088. altText.addEventListener("click", onClick, {
  11089. capture: true
  11090. });
  11091. altText.addEventListener("keydown", event => {
  11092. if (event.target === altText && event.key === "Enter") {
  11093. this.#altTextWasFromKeyBoard = true;
  11094. onClick(event);
  11095. }
  11096. });
  11097. await this.#setState();
  11098. return altText;
  11099. }
  11100. finish() {
  11101. if (!this.#altTextButton) {
  11102. return;
  11103. }
  11104. this.#altTextButton.focus({
  11105. focusVisible: this.#altTextWasFromKeyBoard
  11106. });
  11107. this.#altTextWasFromKeyBoard = false;
  11108. }
  11109. get data() {
  11110. return {
  11111. altText: this.#altText,
  11112. decorative: this.#altTextDecorative
  11113. };
  11114. }
  11115. set data({
  11116. altText,
  11117. decorative
  11118. }) {
  11119. if (this.#altText === altText && this.#altTextDecorative === decorative) {
  11120. return;
  11121. }
  11122. this.#altText = altText;
  11123. this.#altTextDecorative = decorative;
  11124. this.#setState();
  11125. }
  11126. toggle(enabled = false) {
  11127. if (!this.#altTextButton) {
  11128. return;
  11129. }
  11130. if (!enabled && this.#altTextTooltipTimeout) {
  11131. clearTimeout(this.#altTextTooltipTimeout);
  11132. this.#altTextTooltipTimeout = null;
  11133. }
  11134. this.#altTextButton.disabled = !enabled;
  11135. }
  11136. destroy() {
  11137. this.#altTextButton?.remove();
  11138. this.#altTextButton = null;
  11139. this.#altTextTooltip = null;
  11140. }
  11141. async #setState() {
  11142. const button = this.#altTextButton;
  11143. if (!button) {
  11144. return;
  11145. }
  11146. if (!this.#altText && !this.#altTextDecorative) {
  11147. button.classList.remove("done");
  11148. this.#altTextTooltip?.remove();
  11149. return;
  11150. }
  11151. button.classList.add("done");
  11152. AltText._l10nPromise.get("pdfjs-editor-alt-text-edit-button-label").then(msg => {
  11153. button.setAttribute("aria-label", msg);
  11154. });
  11155. let tooltip = this.#altTextTooltip;
  11156. if (!tooltip) {
  11157. this.#altTextTooltip = tooltip = document.createElement("span");
  11158. tooltip.className = "tooltip";
  11159. tooltip.setAttribute("role", "tooltip");
  11160. const id = tooltip.id = `alt-text-tooltip-${this.#editor.id}`;
  11161. button.setAttribute("aria-describedby", id);
  11162. const DELAY_TO_SHOW_TOOLTIP = 100;
  11163. button.addEventListener("mouseenter", () => {
  11164. this.#altTextTooltipTimeout = setTimeout(() => {
  11165. this.#altTextTooltipTimeout = null;
  11166. this.#altTextTooltip.classList.add("show");
  11167. this.#editor._uiManager._eventBus.dispatch("reporttelemetry", {
  11168. source: this,
  11169. details: {
  11170. type: "editing",
  11171. subtype: this.#editor.editorType,
  11172. data: {
  11173. action: "alt_text_tooltip"
  11174. }
  11175. }
  11176. });
  11177. }, DELAY_TO_SHOW_TOOLTIP);
  11178. });
  11179. button.addEventListener("mouseleave", () => {
  11180. if (this.#altTextTooltipTimeout) {
  11181. clearTimeout(this.#altTextTooltipTimeout);
  11182. this.#altTextTooltipTimeout = null;
  11183. }
  11184. this.#altTextTooltip?.classList.remove("show");
  11185. });
  11186. }
  11187. tooltip.innerText = this.#altTextDecorative ? await AltText._l10nPromise.get("pdfjs-editor-alt-text-decorative-tooltip") : this.#altText;
  11188. if (!tooltip.parentNode) {
  11189. button.append(tooltip);
  11190. }
  11191. const element = this.#editor.getImageForAltText();
  11192. element?.setAttribute("aria-describedby", tooltip.id);
  11193. }
  11194. }
  11195. ;// CONCATENATED MODULE: ./src/display/editor/toolbar.js
  11196. class EditorToolbar {
  11197. #toolbar = null;
  11198. #colorPicker = null;
  11199. #editor;
  11200. #buttons = null;
  11201. constructor(editor) {
  11202. this.#editor = editor;
  11203. }
  11204. render() {
  11205. const editToolbar = this.#toolbar = document.createElement("div");
  11206. editToolbar.className = "editToolbar";
  11207. editToolbar.addEventListener("contextmenu", display_utils.noContextMenu);
  11208. editToolbar.addEventListener("pointerdown", EditorToolbar.#pointerDown);
  11209. const buttons = this.#buttons = document.createElement("div");
  11210. buttons.className = "buttons";
  11211. editToolbar.append(buttons);
  11212. const position = this.#editor.toolbarPosition;
  11213. if (position) {
  11214. const {
  11215. style
  11216. } = editToolbar;
  11217. const x = this.#editor._uiManager.direction === "ltr" ? 1 - position[0] : position[0];
  11218. style.insetInlineEnd = `${100 * x}%`;
  11219. style.top = `calc(${100 * position[1]}% + var(--editor-toolbar-vert-offset))`;
  11220. }
  11221. this.#addDeleteButton();
  11222. return editToolbar;
  11223. }
  11224. static #pointerDown(e) {
  11225. e.stopPropagation();
  11226. }
  11227. #focusIn(e) {
  11228. this.#editor._focusEventsAllowed = false;
  11229. e.preventDefault();
  11230. e.stopPropagation();
  11231. }
  11232. #focusOut(e) {
  11233. this.#editor._focusEventsAllowed = true;
  11234. e.preventDefault();
  11235. e.stopPropagation();
  11236. }
  11237. #addListenersToElement(element) {
  11238. element.addEventListener("focusin", this.#focusIn.bind(this), {
  11239. capture: true
  11240. });
  11241. element.addEventListener("focusout", this.#focusOut.bind(this), {
  11242. capture: true
  11243. });
  11244. element.addEventListener("contextmenu", display_utils.noContextMenu);
  11245. }
  11246. hide() {
  11247. this.#toolbar.classList.add("hidden");
  11248. this.#colorPicker?.hideDropdown();
  11249. }
  11250. show() {
  11251. this.#toolbar.classList.remove("hidden");
  11252. }
  11253. #addDeleteButton() {
  11254. const button = document.createElement("button");
  11255. button.className = "delete";
  11256. button.tabIndex = 0;
  11257. button.setAttribute("data-l10n-id", `pdfjs-editor-remove-${this.#editor.editorType}-button`);
  11258. this.#addListenersToElement(button);
  11259. button.addEventListener("click", e => {
  11260. this.#editor._uiManager.delete();
  11261. });
  11262. this.#buttons.append(button);
  11263. }
  11264. get #divider() {
  11265. const divider = document.createElement("div");
  11266. divider.className = "divider";
  11267. return divider;
  11268. }
  11269. addAltTextButton(button) {
  11270. this.#addListenersToElement(button);
  11271. this.#buttons.prepend(button, this.#divider);
  11272. }
  11273. addColorPicker(colorPicker) {
  11274. this.#colorPicker = colorPicker;
  11275. const button = colorPicker.renderButton();
  11276. this.#addListenersToElement(button);
  11277. this.#buttons.prepend(button, this.#divider);
  11278. }
  11279. remove() {
  11280. this.#toolbar.remove();
  11281. this.#colorPicker?.destroy();
  11282. this.#colorPicker = null;
  11283. }
  11284. }
  11285. ;// CONCATENATED MODULE: ./src/display/editor/editor.js
  11286. class AnnotationEditor {
  11287. #allResizerDivs = null;
  11288. #altText = null;
  11289. #keepAspectRatio = false;
  11290. #resizersDiv = null;
  11291. #savedDimensions = null;
  11292. #boundFocusin = this.focusin.bind(this);
  11293. #boundFocusout = this.focusout.bind(this);
  11294. #editToolbar = null;
  11295. #focusedResizerName = "";
  11296. #hasBeenClicked = false;
  11297. #isEditing = false;
  11298. #isInEditMode = false;
  11299. #isResizerEnabledForKeyboard = false;
  11300. #moveInDOMTimeout = null;
  11301. _initialOptions = Object.create(null);
  11302. _uiManager = null;
  11303. _focusEventsAllowed = true;
  11304. _l10nPromise = null;
  11305. #isDraggable = false;
  11306. #zIndex = AnnotationEditor._zIndex++;
  11307. static _borderLineWidth = -1;
  11308. static _colorManager = new tools.ColorManager();
  11309. static _zIndex = 1;
  11310. static get _resizerKeyboardManager() {
  11311. const resize = AnnotationEditor.prototype._resizeWithKeyboard;
  11312. const small = tools.AnnotationEditorUIManager.TRANSLATE_SMALL;
  11313. const big = tools.AnnotationEditorUIManager.TRANSLATE_BIG;
  11314. return (0,util.shadow)(this, "_resizerKeyboardManager", new tools.KeyboardManager([[["ArrowLeft", "mac+ArrowLeft"], resize, {
  11315. args: [-small, 0]
  11316. }], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], resize, {
  11317. args: [-big, 0]
  11318. }], [["ArrowRight", "mac+ArrowRight"], resize, {
  11319. args: [small, 0]
  11320. }], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], resize, {
  11321. args: [big, 0]
  11322. }], [["ArrowUp", "mac+ArrowUp"], resize, {
  11323. args: [0, -small]
  11324. }], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], resize, {
  11325. args: [0, -big]
  11326. }], [["ArrowDown", "mac+ArrowDown"], resize, {
  11327. args: [0, small]
  11328. }], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], resize, {
  11329. args: [0, big]
  11330. }], [["Escape", "mac+Escape"], AnnotationEditor.prototype._stopResizingWithKeyboard]]));
  11331. }
  11332. constructor(parameters) {
  11333. if (this.constructor === AnnotationEditor) {
  11334. (0,util.unreachable)("Cannot initialize AnnotationEditor.");
  11335. }
  11336. this.parent = parameters.parent;
  11337. this.id = parameters.id;
  11338. this.width = this.height = null;
  11339. this.pageIndex = parameters.parent.pageIndex;
  11340. this.name = parameters.name;
  11341. this.div = null;
  11342. this._uiManager = parameters.uiManager;
  11343. this.annotationElementId = null;
  11344. this._willKeepAspectRatio = false;
  11345. this._initialOptions.isCentered = parameters.isCentered;
  11346. this._structTreeParentId = null;
  11347. const {
  11348. rotation,
  11349. rawDims: {
  11350. pageWidth,
  11351. pageHeight,
  11352. pageX,
  11353. pageY
  11354. }
  11355. } = this.parent.viewport;
  11356. this.rotation = rotation;
  11357. this.pageRotation = (360 + rotation - this._uiManager.viewParameters.rotation) % 360;
  11358. this.pageDimensions = [pageWidth, pageHeight];
  11359. this.pageTranslation = [pageX, pageY];
  11360. const [width, height] = this.parentDimensions;
  11361. this.x = parameters.x / width;
  11362. this.y = parameters.y / height;
  11363. this.isAttachedToDOM = false;
  11364. this.deleted = false;
  11365. }
  11366. get editorType() {
  11367. return Object.getPrototypeOf(this).constructor._type;
  11368. }
  11369. static get _defaultLineColor() {
  11370. return (0,util.shadow)(this, "_defaultLineColor", this._colorManager.getHexCode("CanvasText"));
  11371. }
  11372. static deleteAnnotationElement(editor) {
  11373. const fakeEditor = new FakeEditor({
  11374. id: editor.parent.getNextId(),
  11375. parent: editor.parent,
  11376. uiManager: editor._uiManager
  11377. });
  11378. fakeEditor.annotationElementId = editor.annotationElementId;
  11379. fakeEditor.deleted = true;
  11380. fakeEditor._uiManager.addToAnnotationStorage(fakeEditor);
  11381. }
  11382. static initialize(l10n, options = null) {
  11383. AnnotationEditor._l10nPromise ||= new Map(["pdfjs-editor-alt-text-button-label", "pdfjs-editor-alt-text-edit-button-label", "pdfjs-editor-alt-text-decorative-tooltip", "pdfjs-editor-resizer-label-topLeft", "pdfjs-editor-resizer-label-topMiddle", "pdfjs-editor-resizer-label-topRight", "pdfjs-editor-resizer-label-middleRight", "pdfjs-editor-resizer-label-bottomRight", "pdfjs-editor-resizer-label-bottomMiddle", "pdfjs-editor-resizer-label-bottomLeft", "pdfjs-editor-resizer-label-middleLeft"].map(str => [str, l10n.get(str.replaceAll(/([A-Z])/g, c => `-${c.toLowerCase()}`))]));
  11384. if (options?.strings) {
  11385. for (const str of options.strings) {
  11386. AnnotationEditor._l10nPromise.set(str, l10n.get(str));
  11387. }
  11388. }
  11389. if (AnnotationEditor._borderLineWidth !== -1) {
  11390. return;
  11391. }
  11392. const style = getComputedStyle(document.documentElement);
  11393. AnnotationEditor._borderLineWidth = parseFloat(style.getPropertyValue("--outline-width")) || 0;
  11394. }
  11395. static updateDefaultParams(_type, _value) {}
  11396. static get defaultPropertiesToUpdate() {
  11397. return [];
  11398. }
  11399. static isHandlingMimeForPasting(mime) {
  11400. return false;
  11401. }
  11402. static paste(item, parent) {
  11403. (0,util.unreachable)("Not implemented");
  11404. }
  11405. get propertiesToUpdate() {
  11406. return [];
  11407. }
  11408. get _isDraggable() {
  11409. return this.#isDraggable;
  11410. }
  11411. set _isDraggable(value) {
  11412. this.#isDraggable = value;
  11413. this.div?.classList.toggle("draggable", value);
  11414. }
  11415. get isEnterHandled() {
  11416. return true;
  11417. }
  11418. center() {
  11419. const [pageWidth, pageHeight] = this.pageDimensions;
  11420. switch (this.parentRotation) {
  11421. case 90:
  11422. this.x -= this.height * pageHeight / (pageWidth * 2);
  11423. this.y += this.width * pageWidth / (pageHeight * 2);
  11424. break;
  11425. case 180:
  11426. this.x += this.width / 2;
  11427. this.y += this.height / 2;
  11428. break;
  11429. case 270:
  11430. this.x += this.height * pageHeight / (pageWidth * 2);
  11431. this.y -= this.width * pageWidth / (pageHeight * 2);
  11432. break;
  11433. default:
  11434. this.x -= this.width / 2;
  11435. this.y -= this.height / 2;
  11436. break;
  11437. }
  11438. this.fixAndSetPosition();
  11439. }
  11440. addCommands(params) {
  11441. this._uiManager.addCommands(params);
  11442. }
  11443. get currentLayer() {
  11444. return this._uiManager.currentLayer;
  11445. }
  11446. setInBackground() {
  11447. this.div.style.zIndex = 0;
  11448. }
  11449. setInForeground() {
  11450. this.div.style.zIndex = this.#zIndex;
  11451. }
  11452. setParent(parent) {
  11453. if (parent !== null) {
  11454. this.pageIndex = parent.pageIndex;
  11455. this.pageDimensions = parent.pageDimensions;
  11456. } else {
  11457. this.#stopResizing();
  11458. }
  11459. this.parent = parent;
  11460. }
  11461. focusin(event) {
  11462. if (!this._focusEventsAllowed) {
  11463. return;
  11464. }
  11465. if (!this.#hasBeenClicked) {
  11466. this.parent.setSelected(this);
  11467. } else {
  11468. this.#hasBeenClicked = false;
  11469. }
  11470. }
  11471. focusout(event) {
  11472. if (!this._focusEventsAllowed) {
  11473. return;
  11474. }
  11475. if (!this.isAttachedToDOM) {
  11476. return;
  11477. }
  11478. const target = event.relatedTarget;
  11479. if (target?.closest(`#${this.id}`)) {
  11480. return;
  11481. }
  11482. event.preventDefault();
  11483. if (!this.parent?.isMultipleSelection) {
  11484. this.commitOrRemove();
  11485. }
  11486. }
  11487. commitOrRemove() {
  11488. if (this.isEmpty()) {
  11489. this.remove();
  11490. } else {
  11491. this.commit();
  11492. }
  11493. }
  11494. commit() {
  11495. this.addToAnnotationStorage();
  11496. }
  11497. addToAnnotationStorage() {
  11498. this._uiManager.addToAnnotationStorage(this);
  11499. }
  11500. setAt(x, y, tx, ty) {
  11501. const [width, height] = this.parentDimensions;
  11502. [tx, ty] = this.screenToPageTranslation(tx, ty);
  11503. this.x = (x + tx) / width;
  11504. this.y = (y + ty) / height;
  11505. this.fixAndSetPosition();
  11506. }
  11507. #translate([width, height], x, y) {
  11508. [x, y] = this.screenToPageTranslation(x, y);
  11509. this.x += x / width;
  11510. this.y += y / height;
  11511. this.fixAndSetPosition();
  11512. }
  11513. translate(x, y) {
  11514. this.#translate(this.parentDimensions, x, y);
  11515. }
  11516. translateInPage(x, y) {
  11517. this.#translate(this.pageDimensions, x, y);
  11518. this.div.scrollIntoView({
  11519. block: "nearest"
  11520. });
  11521. }
  11522. drag(tx, ty) {
  11523. const [parentWidth, parentHeight] = this.parentDimensions;
  11524. this.x += tx / parentWidth;
  11525. this.y += ty / parentHeight;
  11526. if (this.parent && (this.x < 0 || this.x > 1 || this.y < 0 || this.y > 1)) {
  11527. const {
  11528. x,
  11529. y
  11530. } = this.div.getBoundingClientRect();
  11531. if (this.parent.findNewParent(this, x, y)) {
  11532. this.x -= Math.floor(this.x);
  11533. this.y -= Math.floor(this.y);
  11534. }
  11535. }
  11536. let {
  11537. x,
  11538. y
  11539. } = this;
  11540. const [bx, by] = this.#getBaseTranslation();
  11541. x += bx;
  11542. y += by;
  11543. this.div.style.left = `${(100 * x).toFixed(2)}%`;
  11544. this.div.style.top = `${(100 * y).toFixed(2)}%`;
  11545. this.div.scrollIntoView({
  11546. block: "nearest"
  11547. });
  11548. }
  11549. #getBaseTranslation() {
  11550. const [parentWidth, parentHeight] = this.parentDimensions;
  11551. const {
  11552. _borderLineWidth
  11553. } = AnnotationEditor;
  11554. const x = _borderLineWidth / parentWidth;
  11555. const y = _borderLineWidth / parentHeight;
  11556. switch (this.rotation) {
  11557. case 90:
  11558. return [-x, y];
  11559. case 180:
  11560. return [x, y];
  11561. case 270:
  11562. return [x, -y];
  11563. default:
  11564. return [-x, -y];
  11565. }
  11566. }
  11567. fixAndSetPosition(rotation = this.rotation) {
  11568. const [pageWidth, pageHeight] = this.pageDimensions;
  11569. let {
  11570. x,
  11571. y,
  11572. width,
  11573. height
  11574. } = this;
  11575. width *= pageWidth;
  11576. height *= pageHeight;
  11577. x *= pageWidth;
  11578. y *= pageHeight;
  11579. switch (rotation) {
  11580. case 0:
  11581. x = Math.max(0, Math.min(pageWidth - width, x));
  11582. y = Math.max(0, Math.min(pageHeight - height, y));
  11583. break;
  11584. case 90:
  11585. x = Math.max(0, Math.min(pageWidth - height, x));
  11586. y = Math.min(pageHeight, Math.max(width, y));
  11587. break;
  11588. case 180:
  11589. x = Math.min(pageWidth, Math.max(width, x));
  11590. y = Math.min(pageHeight, Math.max(height, y));
  11591. break;
  11592. case 270:
  11593. x = Math.min(pageWidth, Math.max(height, x));
  11594. y = Math.max(0, Math.min(pageHeight - width, y));
  11595. break;
  11596. }
  11597. this.x = x /= pageWidth;
  11598. this.y = y /= pageHeight;
  11599. const [bx, by] = this.#getBaseTranslation();
  11600. x += bx;
  11601. y += by;
  11602. const {
  11603. style
  11604. } = this.div;
  11605. style.left = `${(100 * x).toFixed(2)}%`;
  11606. style.top = `${(100 * y).toFixed(2)}%`;
  11607. this.moveInDOM();
  11608. }
  11609. static #rotatePoint(x, y, angle) {
  11610. switch (angle) {
  11611. case 90:
  11612. return [y, -x];
  11613. case 180:
  11614. return [-x, -y];
  11615. case 270:
  11616. return [-y, x];
  11617. default:
  11618. return [x, y];
  11619. }
  11620. }
  11621. screenToPageTranslation(x, y) {
  11622. return AnnotationEditor.#rotatePoint(x, y, this.parentRotation);
  11623. }
  11624. pageTranslationToScreen(x, y) {
  11625. return AnnotationEditor.#rotatePoint(x, y, 360 - this.parentRotation);
  11626. }
  11627. #getRotationMatrix(rotation) {
  11628. switch (rotation) {
  11629. case 90:
  11630. {
  11631. const [pageWidth, pageHeight] = this.pageDimensions;
  11632. return [0, -pageWidth / pageHeight, pageHeight / pageWidth, 0];
  11633. }
  11634. case 180:
  11635. return [-1, 0, 0, -1];
  11636. case 270:
  11637. {
  11638. const [pageWidth, pageHeight] = this.pageDimensions;
  11639. return [0, pageWidth / pageHeight, -pageHeight / pageWidth, 0];
  11640. }
  11641. default:
  11642. return [1, 0, 0, 1];
  11643. }
  11644. }
  11645. get parentScale() {
  11646. return this._uiManager.viewParameters.realScale;
  11647. }
  11648. get parentRotation() {
  11649. return (this._uiManager.viewParameters.rotation + this.pageRotation) % 360;
  11650. }
  11651. get parentDimensions() {
  11652. const {
  11653. parentScale,
  11654. pageDimensions: [pageWidth, pageHeight]
  11655. } = this;
  11656. const scaledWidth = pageWidth * parentScale;
  11657. const scaledHeight = pageHeight * parentScale;
  11658. return util.FeatureTest.isCSSRoundSupported ? [Math.round(scaledWidth), Math.round(scaledHeight)] : [scaledWidth, scaledHeight];
  11659. }
  11660. setDims(width, height) {
  11661. const [parentWidth, parentHeight] = this.parentDimensions;
  11662. this.div.style.width = `${(100 * width / parentWidth).toFixed(2)}%`;
  11663. if (!this.#keepAspectRatio) {
  11664. this.div.style.height = `${(100 * height / parentHeight).toFixed(2)}%`;
  11665. }
  11666. }
  11667. fixDims() {
  11668. const {
  11669. style
  11670. } = this.div;
  11671. const {
  11672. height,
  11673. width
  11674. } = style;
  11675. const widthPercent = width.endsWith("%");
  11676. const heightPercent = !this.#keepAspectRatio && height.endsWith("%");
  11677. if (widthPercent && heightPercent) {
  11678. return;
  11679. }
  11680. const [parentWidth, parentHeight] = this.parentDimensions;
  11681. if (!widthPercent) {
  11682. style.width = `${(100 * parseFloat(width) / parentWidth).toFixed(2)}%`;
  11683. }
  11684. if (!this.#keepAspectRatio && !heightPercent) {
  11685. style.height = `${(100 * parseFloat(height) / parentHeight).toFixed(2)}%`;
  11686. }
  11687. }
  11688. getInitialTranslation() {
  11689. return [0, 0];
  11690. }
  11691. #createResizers() {
  11692. if (this.#resizersDiv) {
  11693. return;
  11694. }
  11695. this.#resizersDiv = document.createElement("div");
  11696. this.#resizersDiv.classList.add("resizers");
  11697. const classes = this._willKeepAspectRatio ? ["topLeft", "topRight", "bottomRight", "bottomLeft"] : ["topLeft", "topMiddle", "topRight", "middleRight", "bottomRight", "bottomMiddle", "bottomLeft", "middleLeft"];
  11698. for (const name of classes) {
  11699. const div = document.createElement("div");
  11700. this.#resizersDiv.append(div);
  11701. div.classList.add("resizer", name);
  11702. div.setAttribute("data-resizer-name", name);
  11703. div.addEventListener("pointerdown", this.#resizerPointerdown.bind(this, name));
  11704. div.addEventListener("contextmenu", display_utils.noContextMenu);
  11705. div.tabIndex = -1;
  11706. }
  11707. this.div.prepend(this.#resizersDiv);
  11708. }
  11709. #resizerPointerdown(name, event) {
  11710. event.preventDefault();
  11711. const {
  11712. isMac
  11713. } = util.FeatureTest.platform;
  11714. if (event.button !== 0 || event.ctrlKey && isMac) {
  11715. return;
  11716. }
  11717. this.#altText?.toggle(false);
  11718. const boundResizerPointermove = this.#resizerPointermove.bind(this, name);
  11719. const savedDraggable = this._isDraggable;
  11720. this._isDraggable = false;
  11721. const pointerMoveOptions = {
  11722. passive: true,
  11723. capture: true
  11724. };
  11725. this.parent.togglePointerEvents(false);
  11726. window.addEventListener("pointermove", boundResizerPointermove, pointerMoveOptions);
  11727. const savedX = this.x;
  11728. const savedY = this.y;
  11729. const savedWidth = this.width;
  11730. const savedHeight = this.height;
  11731. const savedParentCursor = this.parent.div.style.cursor;
  11732. const savedCursor = this.div.style.cursor;
  11733. this.div.style.cursor = this.parent.div.style.cursor = window.getComputedStyle(event.target).cursor;
  11734. const pointerUpCallback = () => {
  11735. this.parent.togglePointerEvents(true);
  11736. this.#altText?.toggle(true);
  11737. this._isDraggable = savedDraggable;
  11738. window.removeEventListener("pointerup", pointerUpCallback);
  11739. window.removeEventListener("blur", pointerUpCallback);
  11740. window.removeEventListener("pointermove", boundResizerPointermove, pointerMoveOptions);
  11741. this.parent.div.style.cursor = savedParentCursor;
  11742. this.div.style.cursor = savedCursor;
  11743. this.#addResizeToUndoStack(savedX, savedY, savedWidth, savedHeight);
  11744. };
  11745. window.addEventListener("pointerup", pointerUpCallback);
  11746. window.addEventListener("blur", pointerUpCallback);
  11747. }
  11748. #addResizeToUndoStack(savedX, savedY, savedWidth, savedHeight) {
  11749. const newX = this.x;
  11750. const newY = this.y;
  11751. const newWidth = this.width;
  11752. const newHeight = this.height;
  11753. if (newX === savedX && newY === savedY && newWidth === savedWidth && newHeight === savedHeight) {
  11754. return;
  11755. }
  11756. this.addCommands({
  11757. cmd: () => {
  11758. this.width = newWidth;
  11759. this.height = newHeight;
  11760. this.x = newX;
  11761. this.y = newY;
  11762. const [parentWidth, parentHeight] = this.parentDimensions;
  11763. this.setDims(parentWidth * newWidth, parentHeight * newHeight);
  11764. this.fixAndSetPosition();
  11765. },
  11766. undo: () => {
  11767. this.width = savedWidth;
  11768. this.height = savedHeight;
  11769. this.x = savedX;
  11770. this.y = savedY;
  11771. const [parentWidth, parentHeight] = this.parentDimensions;
  11772. this.setDims(parentWidth * savedWidth, parentHeight * savedHeight);
  11773. this.fixAndSetPosition();
  11774. },
  11775. mustExec: true
  11776. });
  11777. }
  11778. #resizerPointermove(name, event) {
  11779. const [parentWidth, parentHeight] = this.parentDimensions;
  11780. const savedX = this.x;
  11781. const savedY = this.y;
  11782. const savedWidth = this.width;
  11783. const savedHeight = this.height;
  11784. const minWidth = AnnotationEditor.MIN_SIZE / parentWidth;
  11785. const minHeight = AnnotationEditor.MIN_SIZE / parentHeight;
  11786. const round = x => Math.round(x * 10000) / 10000;
  11787. const rotationMatrix = this.#getRotationMatrix(this.rotation);
  11788. const transf = (x, y) => [rotationMatrix[0] * x + rotationMatrix[2] * y, rotationMatrix[1] * x + rotationMatrix[3] * y];
  11789. const invRotationMatrix = this.#getRotationMatrix(360 - this.rotation);
  11790. const invTransf = (x, y) => [invRotationMatrix[0] * x + invRotationMatrix[2] * y, invRotationMatrix[1] * x + invRotationMatrix[3] * y];
  11791. let getPoint;
  11792. let getOpposite;
  11793. let isDiagonal = false;
  11794. let isHorizontal = false;
  11795. switch (name) {
  11796. case "topLeft":
  11797. isDiagonal = true;
  11798. getPoint = (w, h) => [0, 0];
  11799. getOpposite = (w, h) => [w, h];
  11800. break;
  11801. case "topMiddle":
  11802. getPoint = (w, h) => [w / 2, 0];
  11803. getOpposite = (w, h) => [w / 2, h];
  11804. break;
  11805. case "topRight":
  11806. isDiagonal = true;
  11807. getPoint = (w, h) => [w, 0];
  11808. getOpposite = (w, h) => [0, h];
  11809. break;
  11810. case "middleRight":
  11811. isHorizontal = true;
  11812. getPoint = (w, h) => [w, h / 2];
  11813. getOpposite = (w, h) => [0, h / 2];
  11814. break;
  11815. case "bottomRight":
  11816. isDiagonal = true;
  11817. getPoint = (w, h) => [w, h];
  11818. getOpposite = (w, h) => [0, 0];
  11819. break;
  11820. case "bottomMiddle":
  11821. getPoint = (w, h) => [w / 2, h];
  11822. getOpposite = (w, h) => [w / 2, 0];
  11823. break;
  11824. case "bottomLeft":
  11825. isDiagonal = true;
  11826. getPoint = (w, h) => [0, h];
  11827. getOpposite = (w, h) => [w, 0];
  11828. break;
  11829. case "middleLeft":
  11830. isHorizontal = true;
  11831. getPoint = (w, h) => [0, h / 2];
  11832. getOpposite = (w, h) => [w, h / 2];
  11833. break;
  11834. }
  11835. const point = getPoint(savedWidth, savedHeight);
  11836. const oppositePoint = getOpposite(savedWidth, savedHeight);
  11837. let transfOppositePoint = transf(...oppositePoint);
  11838. const oppositeX = round(savedX + transfOppositePoint[0]);
  11839. const oppositeY = round(savedY + transfOppositePoint[1]);
  11840. let ratioX = 1;
  11841. let ratioY = 1;
  11842. let [deltaX, deltaY] = this.screenToPageTranslation(event.movementX, event.movementY);
  11843. [deltaX, deltaY] = invTransf(deltaX / parentWidth, deltaY / parentHeight);
  11844. if (isDiagonal) {
  11845. const oldDiag = Math.hypot(savedWidth, savedHeight);
  11846. ratioX = ratioY = Math.max(Math.min(Math.hypot(oppositePoint[0] - point[0] - deltaX, oppositePoint[1] - point[1] - deltaY) / oldDiag, 1 / savedWidth, 1 / savedHeight), minWidth / savedWidth, minHeight / savedHeight);
  11847. } else if (isHorizontal) {
  11848. ratioX = Math.max(minWidth, Math.min(1, Math.abs(oppositePoint[0] - point[0] - deltaX))) / savedWidth;
  11849. } else {
  11850. ratioY = Math.max(minHeight, Math.min(1, Math.abs(oppositePoint[1] - point[1] - deltaY))) / savedHeight;
  11851. }
  11852. const newWidth = round(savedWidth * ratioX);
  11853. const newHeight = round(savedHeight * ratioY);
  11854. transfOppositePoint = transf(...getOpposite(newWidth, newHeight));
  11855. const newX = oppositeX - transfOppositePoint[0];
  11856. const newY = oppositeY - transfOppositePoint[1];
  11857. this.width = newWidth;
  11858. this.height = newHeight;
  11859. this.x = newX;
  11860. this.y = newY;
  11861. this.setDims(parentWidth * newWidth, parentHeight * newHeight);
  11862. this.fixAndSetPosition();
  11863. }
  11864. altTextFinish() {
  11865. this.#altText?.finish();
  11866. }
  11867. async addEditToolbar() {
  11868. if (this.#editToolbar || this.#isInEditMode) {
  11869. return this.#editToolbar;
  11870. }
  11871. this.#editToolbar = new EditorToolbar(this);
  11872. this.div.append(this.#editToolbar.render());
  11873. if (this.#altText) {
  11874. this.#editToolbar.addAltTextButton(await this.#altText.render());
  11875. }
  11876. return this.#editToolbar;
  11877. }
  11878. removeEditToolbar() {
  11879. if (!this.#editToolbar) {
  11880. return;
  11881. }
  11882. this.#editToolbar.remove();
  11883. this.#editToolbar = null;
  11884. this.#altText?.destroy();
  11885. }
  11886. getClientDimensions() {
  11887. return this.div.getBoundingClientRect();
  11888. }
  11889. async addAltTextButton() {
  11890. if (this.#altText) {
  11891. return;
  11892. }
  11893. AltText.initialize(AnnotationEditor._l10nPromise);
  11894. this.#altText = new AltText(this);
  11895. await this.addEditToolbar();
  11896. }
  11897. get altTextData() {
  11898. return this.#altText?.data;
  11899. }
  11900. set altTextData(data) {
  11901. if (!this.#altText) {
  11902. return;
  11903. }
  11904. this.#altText.data = data;
  11905. }
  11906. render() {
  11907. this.div = document.createElement("div");
  11908. this.div.setAttribute("data-editor-rotation", (360 - this.rotation) % 360);
  11909. this.div.className = this.name;
  11910. this.div.setAttribute("id", this.id);
  11911. this.div.setAttribute("tabIndex", 0);
  11912. this.setInForeground();
  11913. this.div.addEventListener("focusin", this.#boundFocusin);
  11914. this.div.addEventListener("focusout", this.#boundFocusout);
  11915. const [parentWidth, parentHeight] = this.parentDimensions;
  11916. if (this.parentRotation % 180 !== 0) {
  11917. this.div.style.maxWidth = `${(100 * parentHeight / parentWidth).toFixed(2)}%`;
  11918. this.div.style.maxHeight = `${(100 * parentWidth / parentHeight).toFixed(2)}%`;
  11919. }
  11920. const [tx, ty] = this.getInitialTranslation();
  11921. this.translate(tx, ty);
  11922. (0,tools.bindEvents)(this, this.div, ["pointerdown"]);
  11923. return this.div;
  11924. }
  11925. pointerdown(event) {
  11926. const {
  11927. isMac
  11928. } = util.FeatureTest.platform;
  11929. if (event.button !== 0 || event.ctrlKey && isMac) {
  11930. event.preventDefault();
  11931. return;
  11932. }
  11933. this.#hasBeenClicked = true;
  11934. if (this._isDraggable) {
  11935. this.#setUpDragSession(event);
  11936. return;
  11937. }
  11938. this.#selectOnPointerEvent(event);
  11939. }
  11940. #selectOnPointerEvent(event) {
  11941. const {
  11942. isMac
  11943. } = util.FeatureTest.platform;
  11944. if (event.ctrlKey && !isMac || event.shiftKey || event.metaKey && isMac) {
  11945. this.parent.toggleSelected(this);
  11946. } else {
  11947. this.parent.setSelected(this);
  11948. }
  11949. }
  11950. #setUpDragSession(event) {
  11951. const isSelected = this._uiManager.isSelected(this);
  11952. this._uiManager.setUpDragSession();
  11953. let pointerMoveOptions, pointerMoveCallback;
  11954. if (isSelected) {
  11955. pointerMoveOptions = {
  11956. passive: true,
  11957. capture: true
  11958. };
  11959. pointerMoveCallback = e => {
  11960. const [tx, ty] = this.screenToPageTranslation(e.movementX, e.movementY);
  11961. this._uiManager.dragSelectedEditors(tx, ty);
  11962. };
  11963. window.addEventListener("pointermove", pointerMoveCallback, pointerMoveOptions);
  11964. }
  11965. const pointerUpCallback = () => {
  11966. window.removeEventListener("pointerup", pointerUpCallback);
  11967. window.removeEventListener("blur", pointerUpCallback);
  11968. if (isSelected) {
  11969. window.removeEventListener("pointermove", pointerMoveCallback, pointerMoveOptions);
  11970. }
  11971. this.#hasBeenClicked = false;
  11972. if (!this._uiManager.endDragSession()) {
  11973. this.#selectOnPointerEvent(event);
  11974. }
  11975. };
  11976. window.addEventListener("pointerup", pointerUpCallback);
  11977. window.addEventListener("blur", pointerUpCallback);
  11978. }
  11979. moveInDOM() {
  11980. if (this.#moveInDOMTimeout) {
  11981. clearTimeout(this.#moveInDOMTimeout);
  11982. }
  11983. this.#moveInDOMTimeout = setTimeout(() => {
  11984. this.#moveInDOMTimeout = null;
  11985. this.parent?.moveEditorInDOM(this);
  11986. }, 0);
  11987. }
  11988. _setParentAndPosition(parent, x, y) {
  11989. parent.changeParent(this);
  11990. this.x = x;
  11991. this.y = y;
  11992. this.fixAndSetPosition();
  11993. }
  11994. getRect(tx, ty, rotation = this.rotation) {
  11995. const scale = this.parentScale;
  11996. const [pageWidth, pageHeight] = this.pageDimensions;
  11997. const [pageX, pageY] = this.pageTranslation;
  11998. const shiftX = tx / scale;
  11999. const shiftY = ty / scale;
  12000. const x = this.x * pageWidth;
  12001. const y = this.y * pageHeight;
  12002. const width = this.width * pageWidth;
  12003. const height = this.height * pageHeight;
  12004. switch (rotation) {
  12005. case 0:
  12006. return [x + shiftX + pageX, pageHeight - y - shiftY - height + pageY, x + shiftX + width + pageX, pageHeight - y - shiftY + pageY];
  12007. case 90:
  12008. return [x + shiftY + pageX, pageHeight - y + shiftX + pageY, x + shiftY + height + pageX, pageHeight - y + shiftX + width + pageY];
  12009. case 180:
  12010. return [x - shiftX - width + pageX, pageHeight - y + shiftY + pageY, x - shiftX + pageX, pageHeight - y + shiftY + height + pageY];
  12011. case 270:
  12012. return [x - shiftY - height + pageX, pageHeight - y - shiftX - width + pageY, x - shiftY + pageX, pageHeight - y - shiftX + pageY];
  12013. default:
  12014. throw new Error("Invalid rotation");
  12015. }
  12016. }
  12017. getRectInCurrentCoords(rect, pageHeight) {
  12018. const [x1, y1, x2, y2] = rect;
  12019. const width = x2 - x1;
  12020. const height = y2 - y1;
  12021. switch (this.rotation) {
  12022. case 0:
  12023. return [x1, pageHeight - y2, width, height];
  12024. case 90:
  12025. return [x1, pageHeight - y1, height, width];
  12026. case 180:
  12027. return [x2, pageHeight - y1, width, height];
  12028. case 270:
  12029. return [x2, pageHeight - y2, height, width];
  12030. default:
  12031. throw new Error("Invalid rotation");
  12032. }
  12033. }
  12034. onceAdded() {}
  12035. isEmpty() {
  12036. return false;
  12037. }
  12038. enableEditMode() {
  12039. this.#isInEditMode = true;
  12040. }
  12041. disableEditMode() {
  12042. this.#isInEditMode = false;
  12043. }
  12044. isInEditMode() {
  12045. return this.#isInEditMode;
  12046. }
  12047. shouldGetKeyboardEvents() {
  12048. return this.#isResizerEnabledForKeyboard;
  12049. }
  12050. needsToBeRebuilt() {
  12051. return this.div && !this.isAttachedToDOM;
  12052. }
  12053. rebuild() {
  12054. this.div?.addEventListener("focusin", this.#boundFocusin);
  12055. this.div?.addEventListener("focusout", this.#boundFocusout);
  12056. }
  12057. rotate(_angle) {}
  12058. serialize(isForCopying = false, context = null) {
  12059. (0,util.unreachable)("An editor must be serializable");
  12060. }
  12061. static deserialize(data, parent, uiManager) {
  12062. const editor = new this.prototype.constructor({
  12063. parent,
  12064. id: parent.getNextId(),
  12065. uiManager
  12066. });
  12067. editor.rotation = data.rotation;
  12068. const [pageWidth, pageHeight] = editor.pageDimensions;
  12069. const [x, y, width, height] = editor.getRectInCurrentCoords(data.rect, pageHeight);
  12070. editor.x = x / pageWidth;
  12071. editor.y = y / pageHeight;
  12072. editor.width = width / pageWidth;
  12073. editor.height = height / pageHeight;
  12074. return editor;
  12075. }
  12076. remove() {
  12077. this.div.removeEventListener("focusin", this.#boundFocusin);
  12078. this.div.removeEventListener("focusout", this.#boundFocusout);
  12079. if (!this.isEmpty()) {
  12080. this.commit();
  12081. }
  12082. if (this.parent) {
  12083. this.parent.remove(this);
  12084. } else {
  12085. this._uiManager.removeEditor(this);
  12086. }
  12087. if (this.#moveInDOMTimeout) {
  12088. clearTimeout(this.#moveInDOMTimeout);
  12089. this.#moveInDOMTimeout = null;
  12090. }
  12091. this.#stopResizing();
  12092. this.removeEditToolbar();
  12093. }
  12094. get isResizable() {
  12095. return false;
  12096. }
  12097. makeResizable() {
  12098. if (this.isResizable) {
  12099. this.#createResizers();
  12100. this.#resizersDiv.classList.remove("hidden");
  12101. (0,tools.bindEvents)(this, this.div, ["keydown"]);
  12102. }
  12103. }
  12104. get toolbarPosition() {
  12105. return null;
  12106. }
  12107. keydown(event) {
  12108. if (!this.isResizable || event.target !== this.div || event.key !== "Enter") {
  12109. return;
  12110. }
  12111. this._uiManager.setSelected(this);
  12112. this.#savedDimensions = {
  12113. savedX: this.x,
  12114. savedY: this.y,
  12115. savedWidth: this.width,
  12116. savedHeight: this.height
  12117. };
  12118. const children = this.#resizersDiv.children;
  12119. if (!this.#allResizerDivs) {
  12120. this.#allResizerDivs = Array.from(children);
  12121. const boundResizerKeydown = this.#resizerKeydown.bind(this);
  12122. const boundResizerBlur = this.#resizerBlur.bind(this);
  12123. for (const div of this.#allResizerDivs) {
  12124. const name = div.getAttribute("data-resizer-name");
  12125. div.setAttribute("role", "spinbutton");
  12126. div.addEventListener("keydown", boundResizerKeydown);
  12127. div.addEventListener("blur", boundResizerBlur);
  12128. div.addEventListener("focus", this.#resizerFocus.bind(this, name));
  12129. AnnotationEditor._l10nPromise.get(`pdfjs-editor-resizer-label-${name}`).then(msg => div.setAttribute("aria-label", msg));
  12130. }
  12131. }
  12132. const first = this.#allResizerDivs[0];
  12133. let firstPosition = 0;
  12134. for (const div of children) {
  12135. if (div === first) {
  12136. break;
  12137. }
  12138. firstPosition++;
  12139. }
  12140. const nextFirstPosition = (360 - this.rotation + this.parentRotation) % 360 / 90 * (this.#allResizerDivs.length / 4);
  12141. if (nextFirstPosition !== firstPosition) {
  12142. if (nextFirstPosition < firstPosition) {
  12143. for (let i = 0; i < firstPosition - nextFirstPosition; i++) {
  12144. this.#resizersDiv.append(this.#resizersDiv.firstChild);
  12145. }
  12146. } else if (nextFirstPosition > firstPosition) {
  12147. for (let i = 0; i < nextFirstPosition - firstPosition; i++) {
  12148. this.#resizersDiv.firstChild.before(this.#resizersDiv.lastChild);
  12149. }
  12150. }
  12151. let i = 0;
  12152. for (const child of children) {
  12153. const div = this.#allResizerDivs[i++];
  12154. const name = div.getAttribute("data-resizer-name");
  12155. AnnotationEditor._l10nPromise.get(`pdfjs-editor-resizer-label-${name}`).then(msg => child.setAttribute("aria-label", msg));
  12156. }
  12157. }
  12158. this.#setResizerTabIndex(0);
  12159. this.#isResizerEnabledForKeyboard = true;
  12160. this.#resizersDiv.firstChild.focus({
  12161. focusVisible: true
  12162. });
  12163. event.preventDefault();
  12164. event.stopImmediatePropagation();
  12165. }
  12166. #resizerKeydown(event) {
  12167. AnnotationEditor._resizerKeyboardManager.exec(this, event);
  12168. }
  12169. #resizerBlur(event) {
  12170. if (this.#isResizerEnabledForKeyboard && event.relatedTarget?.parentNode !== this.#resizersDiv) {
  12171. this.#stopResizing();
  12172. }
  12173. }
  12174. #resizerFocus(name) {
  12175. this.#focusedResizerName = this.#isResizerEnabledForKeyboard ? name : "";
  12176. }
  12177. #setResizerTabIndex(value) {
  12178. if (!this.#allResizerDivs) {
  12179. return;
  12180. }
  12181. for (const div of this.#allResizerDivs) {
  12182. div.tabIndex = value;
  12183. }
  12184. }
  12185. _resizeWithKeyboard(x, y) {
  12186. if (!this.#isResizerEnabledForKeyboard) {
  12187. return;
  12188. }
  12189. this.#resizerPointermove(this.#focusedResizerName, {
  12190. movementX: x,
  12191. movementY: y
  12192. });
  12193. }
  12194. #stopResizing() {
  12195. this.#isResizerEnabledForKeyboard = false;
  12196. this.#setResizerTabIndex(-1);
  12197. if (this.#savedDimensions) {
  12198. const {
  12199. savedX,
  12200. savedY,
  12201. savedWidth,
  12202. savedHeight
  12203. } = this.#savedDimensions;
  12204. this.#addResizeToUndoStack(savedX, savedY, savedWidth, savedHeight);
  12205. this.#savedDimensions = null;
  12206. }
  12207. }
  12208. _stopResizingWithKeyboard() {
  12209. this.#stopResizing();
  12210. this.div.focus();
  12211. }
  12212. select() {
  12213. this.makeResizable();
  12214. this.div?.classList.add("selectedEditor");
  12215. if (!this.#editToolbar) {
  12216. this.addEditToolbar().then(() => {
  12217. if (this.div?.classList.contains("selectedEditor")) {
  12218. this.#editToolbar?.show();
  12219. }
  12220. });
  12221. return;
  12222. }
  12223. this.#editToolbar?.show();
  12224. }
  12225. unselect() {
  12226. this.#resizersDiv?.classList.add("hidden");
  12227. this.div?.classList.remove("selectedEditor");
  12228. if (this.div?.contains(document.activeElement)) {
  12229. this._uiManager.currentLayer.div.focus();
  12230. }
  12231. this.#editToolbar?.hide();
  12232. }
  12233. updateParams(type, value) {}
  12234. disableEditing() {}
  12235. enableEditing() {}
  12236. enterInEditMode() {}
  12237. getImageForAltText() {
  12238. return null;
  12239. }
  12240. get contentDiv() {
  12241. return this.div;
  12242. }
  12243. get isEditing() {
  12244. return this.#isEditing;
  12245. }
  12246. set isEditing(value) {
  12247. this.#isEditing = value;
  12248. if (!this.parent) {
  12249. return;
  12250. }
  12251. if (value) {
  12252. this.parent.setSelected(this);
  12253. this.parent.setActiveEditor(this);
  12254. } else {
  12255. this.parent.setActiveEditor(null);
  12256. }
  12257. }
  12258. setAspectRatio(width, height) {
  12259. this.#keepAspectRatio = true;
  12260. const aspectRatio = width / height;
  12261. const {
  12262. style
  12263. } = this.div;
  12264. style.aspectRatio = aspectRatio;
  12265. style.height = "auto";
  12266. }
  12267. static get MIN_SIZE() {
  12268. return 16;
  12269. }
  12270. static canCreateNewEmptyEditor() {
  12271. return true;
  12272. }
  12273. }
  12274. class FakeEditor extends AnnotationEditor {
  12275. constructor(params) {
  12276. super(params);
  12277. this.annotationElementId = params.annotationElementId;
  12278. this.deleted = true;
  12279. }
  12280. serialize() {
  12281. return {
  12282. id: this.annotationElementId,
  12283. deleted: true,
  12284. pageIndex: this.pageIndex
  12285. };
  12286. }
  12287. }
  12288. /***/ }),
  12289. /***/ 405:
  12290. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  12291. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  12292. /* harmony export */ Outliner: () => (/* binding */ Outliner)
  12293. /* harmony export */ });
  12294. class Outliner {
  12295. #box;
  12296. #verticalEdges = [];
  12297. #intervals = [];
  12298. constructor(boxes, borderWidth = 0, innerMargin = 0, isLTR = true) {
  12299. let minX = Infinity;
  12300. let maxX = -Infinity;
  12301. let minY = Infinity;
  12302. let maxY = -Infinity;
  12303. const NUMBER_OF_DIGITS = 4;
  12304. const EPSILON = 10 ** -NUMBER_OF_DIGITS;
  12305. for (const {
  12306. x,
  12307. y,
  12308. width,
  12309. height
  12310. } of boxes) {
  12311. const x1 = Math.floor((x - borderWidth) / EPSILON) * EPSILON;
  12312. const x2 = Math.ceil((x + width + borderWidth) / EPSILON) * EPSILON;
  12313. const y1 = Math.floor((y - borderWidth) / EPSILON) * EPSILON;
  12314. const y2 = Math.ceil((y + height + borderWidth) / EPSILON) * EPSILON;
  12315. const left = [x1, y1, y2, true];
  12316. const right = [x2, y1, y2, false];
  12317. this.#verticalEdges.push(left, right);
  12318. minX = Math.min(minX, x1);
  12319. maxX = Math.max(maxX, x2);
  12320. minY = Math.min(minY, y1);
  12321. maxY = Math.max(maxY, y2);
  12322. }
  12323. const bboxWidth = maxX - minX + 2 * innerMargin;
  12324. const bboxHeight = maxY - minY + 2 * innerMargin;
  12325. const shiftedMinX = minX - innerMargin;
  12326. const shiftedMinY = minY - innerMargin;
  12327. const lastEdge = this.#verticalEdges.at(isLTR ? -1 : -2);
  12328. const lastPoint = [lastEdge[0], lastEdge[2]];
  12329. for (const edge of this.#verticalEdges) {
  12330. const [x, y1, y2] = edge;
  12331. edge[0] = (x - shiftedMinX) / bboxWidth;
  12332. edge[1] = (y1 - shiftedMinY) / bboxHeight;
  12333. edge[2] = (y2 - shiftedMinY) / bboxHeight;
  12334. }
  12335. this.#box = {
  12336. x: shiftedMinX,
  12337. y: shiftedMinY,
  12338. width: bboxWidth,
  12339. height: bboxHeight,
  12340. lastPoint
  12341. };
  12342. }
  12343. getOutlines() {
  12344. this.#verticalEdges.sort((a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2]);
  12345. const outlineVerticalEdges = [];
  12346. for (const edge of this.#verticalEdges) {
  12347. if (edge[3]) {
  12348. outlineVerticalEdges.push(...this.#breakEdge(edge));
  12349. this.#insert(edge);
  12350. } else {
  12351. this.#remove(edge);
  12352. outlineVerticalEdges.push(...this.#breakEdge(edge));
  12353. }
  12354. }
  12355. return this.#getOutlines(outlineVerticalEdges);
  12356. }
  12357. #getOutlines(outlineVerticalEdges) {
  12358. const edges = [];
  12359. const allEdges = new Set();
  12360. for (const edge of outlineVerticalEdges) {
  12361. const [x, y1, y2] = edge;
  12362. edges.push([x, y1, edge], [x, y2, edge]);
  12363. }
  12364. edges.sort((a, b) => a[1] - b[1] || a[0] - b[0]);
  12365. for (let i = 0, ii = edges.length; i < ii; i += 2) {
  12366. const edge1 = edges[i][2];
  12367. const edge2 = edges[i + 1][2];
  12368. edge1.push(edge2);
  12369. edge2.push(edge1);
  12370. allEdges.add(edge1);
  12371. allEdges.add(edge2);
  12372. }
  12373. const outlines = [];
  12374. let outline;
  12375. while (allEdges.size > 0) {
  12376. const edge = allEdges.values().next().value;
  12377. let [x, y1, y2, edge1, edge2] = edge;
  12378. allEdges.delete(edge);
  12379. let lastPointX = x;
  12380. let lastPointY = y1;
  12381. outline = [x, y2];
  12382. outlines.push(outline);
  12383. while (true) {
  12384. let e;
  12385. if (allEdges.has(edge1)) {
  12386. e = edge1;
  12387. } else if (allEdges.has(edge2)) {
  12388. e = edge2;
  12389. } else {
  12390. break;
  12391. }
  12392. allEdges.delete(e);
  12393. [x, y1, y2, edge1, edge2] = e;
  12394. if (lastPointX !== x) {
  12395. outline.push(lastPointX, lastPointY, x, lastPointY === y1 ? y1 : y2);
  12396. lastPointX = x;
  12397. }
  12398. lastPointY = lastPointY === y1 ? y2 : y1;
  12399. }
  12400. outline.push(lastPointX, lastPointY);
  12401. }
  12402. return {
  12403. outlines,
  12404. box: this.#box
  12405. };
  12406. }
  12407. #binarySearch(y) {
  12408. const array = this.#intervals;
  12409. let start = 0;
  12410. let end = array.length - 1;
  12411. while (start <= end) {
  12412. const middle = start + end >> 1;
  12413. const y1 = array[middle][0];
  12414. if (y1 === y) {
  12415. return middle;
  12416. }
  12417. if (y1 < y) {
  12418. start = middle + 1;
  12419. } else {
  12420. end = middle - 1;
  12421. }
  12422. }
  12423. return end + 1;
  12424. }
  12425. #insert([, y1, y2]) {
  12426. const index = this.#binarySearch(y1);
  12427. this.#intervals.splice(index, 0, [y1, y2]);
  12428. }
  12429. #remove([, y1, y2]) {
  12430. const index = this.#binarySearch(y1);
  12431. for (let i = index; i < this.#intervals.length; i++) {
  12432. const [start, end] = this.#intervals[i];
  12433. if (start !== y1) {
  12434. break;
  12435. }
  12436. if (start === y1 && end === y2) {
  12437. this.#intervals.splice(i, 1);
  12438. return;
  12439. }
  12440. }
  12441. for (let i = index - 1; i >= 0; i--) {
  12442. const [start, end] = this.#intervals[i];
  12443. if (start !== y1) {
  12444. break;
  12445. }
  12446. if (start === y1 && end === y2) {
  12447. this.#intervals.splice(i, 1);
  12448. return;
  12449. }
  12450. }
  12451. }
  12452. #breakEdge(edge) {
  12453. const [x, y1, y2] = edge;
  12454. const results = [[x, y1, y2]];
  12455. const index = this.#binarySearch(y2);
  12456. for (let i = 0; i < index; i++) {
  12457. const [start, end] = this.#intervals[i];
  12458. for (let j = 0, jj = results.length; j < jj; j++) {
  12459. const [, y3, y4] = results[j];
  12460. if (end <= y3 || y4 <= start) {
  12461. continue;
  12462. }
  12463. if (y3 >= start) {
  12464. if (y4 > end) {
  12465. results[j][1] = end;
  12466. } else {
  12467. if (jj === 1) {
  12468. return [];
  12469. }
  12470. results.splice(j, 1);
  12471. j--;
  12472. jj--;
  12473. }
  12474. continue;
  12475. }
  12476. results[j][2] = start;
  12477. if (y4 > end) {
  12478. results.push([x, end, y4]);
  12479. }
  12480. }
  12481. }
  12482. return results;
  12483. }
  12484. }
  12485. /***/ }),
  12486. /***/ 812:
  12487. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  12488. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  12489. /* harmony export */ AnnotationEditorUIManager: () => (/* binding */ AnnotationEditorUIManager),
  12490. /* harmony export */ ColorManager: () => (/* binding */ ColorManager),
  12491. /* harmony export */ KeyboardManager: () => (/* binding */ KeyboardManager),
  12492. /* harmony export */ bindEvents: () => (/* binding */ bindEvents),
  12493. /* harmony export */ opacityToHex: () => (/* binding */ opacityToHex)
  12494. /* harmony export */ });
  12495. /* unused harmony export CommandManager */
  12496. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  12497. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(473);
  12498. function bindEvents(obj, element, names) {
  12499. for (const name of names) {
  12500. element.addEventListener(name, obj[name].bind(obj));
  12501. }
  12502. }
  12503. function opacityToHex(opacity) {
  12504. return Math.round(Math.min(255, Math.max(1, 255 * opacity))).toString(16).padStart(2, "0");
  12505. }
  12506. class IdManager {
  12507. #id = 0;
  12508. getId() {
  12509. return `${_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorPrefix}${this.#id++}`;
  12510. }
  12511. }
  12512. class ImageManager {
  12513. #baseId = (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.getUuid)();
  12514. #id = 0;
  12515. #cache = null;
  12516. static get _isSVGFittingCanvas() {
  12517. const svg = `data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>`;
  12518. const canvas = new OffscreenCanvas(1, 3);
  12519. const ctx = canvas.getContext("2d");
  12520. const image = new Image();
  12521. image.src = svg;
  12522. const promise = image.decode().then(() => {
  12523. ctx.drawImage(image, 0, 0, 1, 1, 0, 0, 1, 3);
  12524. return new Uint32Array(ctx.getImageData(0, 0, 1, 1).data.buffer)[0] === 0;
  12525. });
  12526. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "_isSVGFittingCanvas", promise);
  12527. }
  12528. async #get(key, rawData) {
  12529. this.#cache ||= new Map();
  12530. let data = this.#cache.get(key);
  12531. if (data === null) {
  12532. return null;
  12533. }
  12534. if (data?.bitmap) {
  12535. data.refCounter += 1;
  12536. return data;
  12537. }
  12538. try {
  12539. data ||= {
  12540. bitmap: null,
  12541. id: `image_${this.#baseId}_${this.#id++}`,
  12542. refCounter: 0,
  12543. isSvg: false
  12544. };
  12545. let image;
  12546. if (typeof rawData === "string") {
  12547. data.url = rawData;
  12548. image = await (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.fetchData)(rawData, "blob");
  12549. } else {
  12550. image = data.file = rawData;
  12551. }
  12552. if (image.type === "image/svg+xml") {
  12553. const mustRemoveAspectRatioPromise = ImageManager._isSVGFittingCanvas;
  12554. const fileReader = new FileReader();
  12555. const imageElement = new Image();
  12556. const imagePromise = new Promise((resolve, reject) => {
  12557. imageElement.onload = () => {
  12558. data.bitmap = imageElement;
  12559. data.isSvg = true;
  12560. resolve();
  12561. };
  12562. fileReader.onload = async () => {
  12563. const url = data.svgUrl = fileReader.result;
  12564. imageElement.src = (await mustRemoveAspectRatioPromise) ? `${url}#svgView(preserveAspectRatio(none))` : url;
  12565. };
  12566. imageElement.onerror = fileReader.onerror = reject;
  12567. });
  12568. fileReader.readAsDataURL(image);
  12569. await imagePromise;
  12570. } else {
  12571. data.bitmap = await createImageBitmap(image);
  12572. }
  12573. data.refCounter = 1;
  12574. } catch (e) {
  12575. console.error(e);
  12576. data = null;
  12577. }
  12578. this.#cache.set(key, data);
  12579. if (data) {
  12580. this.#cache.set(data.id, data);
  12581. }
  12582. return data;
  12583. }
  12584. async getFromFile(file) {
  12585. const {
  12586. lastModified,
  12587. name,
  12588. size,
  12589. type
  12590. } = file;
  12591. return this.#get(`${lastModified}_${name}_${size}_${type}`, file);
  12592. }
  12593. async getFromUrl(url) {
  12594. return this.#get(url, url);
  12595. }
  12596. async getFromId(id) {
  12597. this.#cache ||= new Map();
  12598. const data = this.#cache.get(id);
  12599. if (!data) {
  12600. return null;
  12601. }
  12602. if (data.bitmap) {
  12603. data.refCounter += 1;
  12604. return data;
  12605. }
  12606. if (data.file) {
  12607. return this.getFromFile(data.file);
  12608. }
  12609. return this.getFromUrl(data.url);
  12610. }
  12611. getSvgUrl(id) {
  12612. const data = this.#cache.get(id);
  12613. if (!data?.isSvg) {
  12614. return null;
  12615. }
  12616. return data.svgUrl;
  12617. }
  12618. deleteId(id) {
  12619. this.#cache ||= new Map();
  12620. const data = this.#cache.get(id);
  12621. if (!data) {
  12622. return;
  12623. }
  12624. data.refCounter -= 1;
  12625. if (data.refCounter !== 0) {
  12626. return;
  12627. }
  12628. data.bitmap = null;
  12629. }
  12630. isValidId(id) {
  12631. return id.startsWith(`image_${this.#baseId}_`);
  12632. }
  12633. }
  12634. class CommandManager {
  12635. #commands = [];
  12636. #locked = false;
  12637. #maxSize;
  12638. #position = -1;
  12639. constructor(maxSize = 128) {
  12640. this.#maxSize = maxSize;
  12641. }
  12642. add({
  12643. cmd,
  12644. undo,
  12645. mustExec,
  12646. type = NaN,
  12647. overwriteIfSameType = false,
  12648. keepUndo = false
  12649. }) {
  12650. if (mustExec) {
  12651. cmd();
  12652. }
  12653. if (this.#locked) {
  12654. return;
  12655. }
  12656. const save = {
  12657. cmd,
  12658. undo,
  12659. type
  12660. };
  12661. if (this.#position === -1) {
  12662. if (this.#commands.length > 0) {
  12663. this.#commands.length = 0;
  12664. }
  12665. this.#position = 0;
  12666. this.#commands.push(save);
  12667. return;
  12668. }
  12669. if (overwriteIfSameType && this.#commands[this.#position].type === type) {
  12670. if (keepUndo) {
  12671. save.undo = this.#commands[this.#position].undo;
  12672. }
  12673. this.#commands[this.#position] = save;
  12674. return;
  12675. }
  12676. const next = this.#position + 1;
  12677. if (next === this.#maxSize) {
  12678. this.#commands.splice(0, 1);
  12679. } else {
  12680. this.#position = next;
  12681. if (next < this.#commands.length) {
  12682. this.#commands.splice(next);
  12683. }
  12684. }
  12685. this.#commands.push(save);
  12686. }
  12687. undo() {
  12688. if (this.#position === -1) {
  12689. return;
  12690. }
  12691. this.#locked = true;
  12692. this.#commands[this.#position].undo();
  12693. this.#locked = false;
  12694. this.#position -= 1;
  12695. }
  12696. redo() {
  12697. if (this.#position < this.#commands.length - 1) {
  12698. this.#position += 1;
  12699. this.#locked = true;
  12700. this.#commands[this.#position].cmd();
  12701. this.#locked = false;
  12702. }
  12703. }
  12704. hasSomethingToUndo() {
  12705. return this.#position !== -1;
  12706. }
  12707. hasSomethingToRedo() {
  12708. return this.#position < this.#commands.length - 1;
  12709. }
  12710. destroy() {
  12711. this.#commands = null;
  12712. }
  12713. }
  12714. class KeyboardManager {
  12715. constructor(callbacks) {
  12716. this.buffer = [];
  12717. this.callbacks = new Map();
  12718. this.allKeys = new Set();
  12719. const {
  12720. isMac
  12721. } = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FeatureTest.platform;
  12722. for (const [keys, callback, options = {}] of callbacks) {
  12723. for (const key of keys) {
  12724. const isMacKey = key.startsWith("mac+");
  12725. if (isMac && isMacKey) {
  12726. this.callbacks.set(key.slice(4), {
  12727. callback,
  12728. options
  12729. });
  12730. this.allKeys.add(key.split("+").at(-1));
  12731. } else if (!isMac && !isMacKey) {
  12732. this.callbacks.set(key, {
  12733. callback,
  12734. options
  12735. });
  12736. this.allKeys.add(key.split("+").at(-1));
  12737. }
  12738. }
  12739. }
  12740. }
  12741. #serialize(event) {
  12742. if (event.altKey) {
  12743. this.buffer.push("alt");
  12744. }
  12745. if (event.ctrlKey) {
  12746. this.buffer.push("ctrl");
  12747. }
  12748. if (event.metaKey) {
  12749. this.buffer.push("meta");
  12750. }
  12751. if (event.shiftKey) {
  12752. this.buffer.push("shift");
  12753. }
  12754. this.buffer.push(event.key);
  12755. const str = this.buffer.join("+");
  12756. this.buffer.length = 0;
  12757. return str;
  12758. }
  12759. exec(self, event) {
  12760. if (!this.allKeys.has(event.key)) {
  12761. return;
  12762. }
  12763. const info = this.callbacks.get(this.#serialize(event));
  12764. if (!info) {
  12765. return;
  12766. }
  12767. const {
  12768. callback,
  12769. options: {
  12770. bubbles = false,
  12771. args = [],
  12772. checker = null
  12773. }
  12774. } = info;
  12775. if (checker && !checker(self, event)) {
  12776. return;
  12777. }
  12778. callback.bind(self, ...args, event)();
  12779. if (!bubbles) {
  12780. event.stopPropagation();
  12781. event.preventDefault();
  12782. }
  12783. }
  12784. }
  12785. class ColorManager {
  12786. static _colorsMapping = new Map([["CanvasText", [0, 0, 0]], ["Canvas", [255, 255, 255]]]);
  12787. get _colors() {
  12788. const colors = new Map([["CanvasText", null], ["Canvas", null]]);
  12789. (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.getColorValues)(colors);
  12790. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "_colors", colors);
  12791. }
  12792. convert(color) {
  12793. const rgb = (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.getRGB)(color);
  12794. if (!window.matchMedia("(forced-colors: active)").matches) {
  12795. return rgb;
  12796. }
  12797. for (const [name, RGB] of this._colors) {
  12798. if (RGB.every((x, i) => x === rgb[i])) {
  12799. return ColorManager._colorsMapping.get(name);
  12800. }
  12801. }
  12802. return rgb;
  12803. }
  12804. getHexCode(name) {
  12805. const rgb = this._colors.get(name);
  12806. if (!rgb) {
  12807. return name;
  12808. }
  12809. return _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.Util.makeHexColor(...rgb);
  12810. }
  12811. }
  12812. class AnnotationEditorUIManager {
  12813. #activeEditor = null;
  12814. #allEditors = new Map();
  12815. #allLayers = new Map();
  12816. #altTextManager = null;
  12817. #annotationStorage = null;
  12818. #commandManager = new CommandManager();
  12819. #currentPageIndex = 0;
  12820. #deletedAnnotationsElementIds = new Set();
  12821. #draggingEditors = null;
  12822. #editorTypes = null;
  12823. #editorsToRescale = new Set();
  12824. #filterFactory = null;
  12825. #focusMainContainerTimeoutId = null;
  12826. #highlightColors = null;
  12827. #idManager = new IdManager();
  12828. #isEnabled = false;
  12829. #isWaiting = false;
  12830. #lastActiveElement = null;
  12831. #mainHighlightColorPicker = null;
  12832. #mode = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE;
  12833. #selectedEditors = new Set();
  12834. #pageColors = null;
  12835. #boundBlur = this.blur.bind(this);
  12836. #boundFocus = this.focus.bind(this);
  12837. #boundCopy = this.copy.bind(this);
  12838. #boundCut = this.cut.bind(this);
  12839. #boundPaste = this.paste.bind(this);
  12840. #boundKeydown = this.keydown.bind(this);
  12841. #boundOnEditingAction = this.onEditingAction.bind(this);
  12842. #boundOnPageChanging = this.onPageChanging.bind(this);
  12843. #boundOnScaleChanging = this.onScaleChanging.bind(this);
  12844. #boundOnRotationChanging = this.onRotationChanging.bind(this);
  12845. #previousStates = {
  12846. isEditing: false,
  12847. isEmpty: true,
  12848. hasSomethingToUndo: false,
  12849. hasSomethingToRedo: false,
  12850. hasSelectedEditor: false
  12851. };
  12852. #translation = [0, 0];
  12853. #translationTimeoutId = null;
  12854. #container = null;
  12855. #viewer = null;
  12856. static TRANSLATE_SMALL = 1;
  12857. static TRANSLATE_BIG = 10;
  12858. static get _keyboardManager() {
  12859. const proto = AnnotationEditorUIManager.prototype;
  12860. const arrowChecker = self => {
  12861. return self.#container.contains(document.activeElement) && document.activeElement.tagName !== "BUTTON" && self.hasSomethingToControl();
  12862. };
  12863. const textInputChecker = (_self, {
  12864. target: el
  12865. }) => {
  12866. if (el instanceof HTMLInputElement) {
  12867. const {
  12868. type
  12869. } = el;
  12870. return type !== "text" && type !== "number";
  12871. }
  12872. return true;
  12873. };
  12874. const small = this.TRANSLATE_SMALL;
  12875. const big = this.TRANSLATE_BIG;
  12876. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "_keyboardManager", new KeyboardManager([[["ctrl+a", "mac+meta+a"], proto.selectAll, {
  12877. checker: textInputChecker
  12878. }], [["ctrl+z", "mac+meta+z"], proto.undo, {
  12879. checker: textInputChecker
  12880. }], [["ctrl+y", "ctrl+shift+z", "mac+meta+shift+z", "ctrl+shift+Z", "mac+meta+shift+Z"], proto.redo, {
  12881. checker: textInputChecker
  12882. }], [["Backspace", "alt+Backspace", "ctrl+Backspace", "shift+Backspace", "mac+Backspace", "mac+alt+Backspace", "mac+ctrl+Backspace", "Delete", "ctrl+Delete", "shift+Delete", "mac+Delete"], proto.delete, {
  12883. checker: textInputChecker
  12884. }], [["Enter", "mac+Enter"], proto.addNewEditorFromKeyboard, {
  12885. checker: (self, {
  12886. target: el
  12887. }) => !(el instanceof HTMLButtonElement) && self.#container.contains(el) && !self.isEnterHandled
  12888. }], [[" ", "mac+ "], proto.addNewEditorFromKeyboard, {
  12889. checker: self => self.#container.contains(document.activeElement)
  12890. }], [["Escape", "mac+Escape"], proto.unselectAll], [["ArrowLeft", "mac+ArrowLeft"], proto.translateSelectedEditors, {
  12891. args: [-small, 0],
  12892. checker: arrowChecker
  12893. }], [["ctrl+ArrowLeft", "mac+shift+ArrowLeft"], proto.translateSelectedEditors, {
  12894. args: [-big, 0],
  12895. checker: arrowChecker
  12896. }], [["ArrowRight", "mac+ArrowRight"], proto.translateSelectedEditors, {
  12897. args: [small, 0],
  12898. checker: arrowChecker
  12899. }], [["ctrl+ArrowRight", "mac+shift+ArrowRight"], proto.translateSelectedEditors, {
  12900. args: [big, 0],
  12901. checker: arrowChecker
  12902. }], [["ArrowUp", "mac+ArrowUp"], proto.translateSelectedEditors, {
  12903. args: [0, -small],
  12904. checker: arrowChecker
  12905. }], [["ctrl+ArrowUp", "mac+shift+ArrowUp"], proto.translateSelectedEditors, {
  12906. args: [0, -big],
  12907. checker: arrowChecker
  12908. }], [["ArrowDown", "mac+ArrowDown"], proto.translateSelectedEditors, {
  12909. args: [0, small],
  12910. checker: arrowChecker
  12911. }], [["ctrl+ArrowDown", "mac+shift+ArrowDown"], proto.translateSelectedEditors, {
  12912. args: [0, big],
  12913. checker: arrowChecker
  12914. }]]));
  12915. }
  12916. constructor(container, viewer, altTextManager, eventBus, pdfDocument, pageColors, highlightColors) {
  12917. this.#container = container;
  12918. this.#viewer = viewer;
  12919. this.#altTextManager = altTextManager;
  12920. this._eventBus = eventBus;
  12921. this._eventBus._on("editingaction", this.#boundOnEditingAction);
  12922. this._eventBus._on("pagechanging", this.#boundOnPageChanging);
  12923. this._eventBus._on("scalechanging", this.#boundOnScaleChanging);
  12924. this._eventBus._on("rotationchanging", this.#boundOnRotationChanging);
  12925. this.#annotationStorage = pdfDocument.annotationStorage;
  12926. this.#filterFactory = pdfDocument.filterFactory;
  12927. this.#pageColors = pageColors;
  12928. this.#highlightColors = highlightColors || null;
  12929. this.viewParameters = {
  12930. realScale: _display_utils_js__WEBPACK_IMPORTED_MODULE_1__.PixelsPerInch.PDF_TO_CSS_UNITS,
  12931. rotation: 0
  12932. };
  12933. }
  12934. destroy() {
  12935. this.#removeKeyboardManager();
  12936. this.#removeFocusManager();
  12937. this._eventBus._off("editingaction", this.#boundOnEditingAction);
  12938. this._eventBus._off("pagechanging", this.#boundOnPageChanging);
  12939. this._eventBus._off("scalechanging", this.#boundOnScaleChanging);
  12940. this._eventBus._off("rotationchanging", this.#boundOnRotationChanging);
  12941. for (const layer of this.#allLayers.values()) {
  12942. layer.destroy();
  12943. }
  12944. this.#allLayers.clear();
  12945. this.#allEditors.clear();
  12946. this.#editorsToRescale.clear();
  12947. this.#activeEditor = null;
  12948. this.#selectedEditors.clear();
  12949. this.#commandManager.destroy();
  12950. this.#altTextManager?.destroy();
  12951. if (this.#focusMainContainerTimeoutId) {
  12952. clearTimeout(this.#focusMainContainerTimeoutId);
  12953. this.#focusMainContainerTimeoutId = null;
  12954. }
  12955. if (this.#translationTimeoutId) {
  12956. clearTimeout(this.#translationTimeoutId);
  12957. this.#translationTimeoutId = null;
  12958. }
  12959. }
  12960. get hcmFilter() {
  12961. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "hcmFilter", this.#pageColors ? this.#filterFactory.addHCMFilter(this.#pageColors.foreground, this.#pageColors.background) : "none");
  12962. }
  12963. get direction() {
  12964. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "direction", getComputedStyle(this.#container).direction);
  12965. }
  12966. get highlightColors() {
  12967. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "highlightColors", this.#highlightColors ? new Map(this.#highlightColors.split(",").map(pair => pair.split("=").map(x => x.trim()))) : null);
  12968. }
  12969. setMainHighlightColorPicker(colorPicker) {
  12970. this.#mainHighlightColorPicker = colorPicker;
  12971. }
  12972. editAltText(editor) {
  12973. this.#altTextManager?.editAltText(this, editor);
  12974. }
  12975. onPageChanging({
  12976. pageNumber
  12977. }) {
  12978. this.#currentPageIndex = pageNumber - 1;
  12979. }
  12980. focusMainContainer() {
  12981. this.#container.focus();
  12982. }
  12983. findParent(x, y) {
  12984. for (const layer of this.#allLayers.values()) {
  12985. const {
  12986. x: layerX,
  12987. y: layerY,
  12988. width,
  12989. height
  12990. } = layer.div.getBoundingClientRect();
  12991. if (x >= layerX && x <= layerX + width && y >= layerY && y <= layerY + height) {
  12992. return layer;
  12993. }
  12994. }
  12995. return null;
  12996. }
  12997. disableUserSelect(value = false) {
  12998. this.#viewer.classList.toggle("noUserSelect", value);
  12999. }
  13000. addShouldRescale(editor) {
  13001. this.#editorsToRescale.add(editor);
  13002. }
  13003. removeShouldRescale(editor) {
  13004. this.#editorsToRescale.delete(editor);
  13005. }
  13006. onScaleChanging({
  13007. scale
  13008. }) {
  13009. this.commitOrRemove();
  13010. this.viewParameters.realScale = scale * _display_utils_js__WEBPACK_IMPORTED_MODULE_1__.PixelsPerInch.PDF_TO_CSS_UNITS;
  13011. for (const editor of this.#editorsToRescale) {
  13012. editor.onScaleChanging();
  13013. }
  13014. }
  13015. onRotationChanging({
  13016. pagesRotation
  13017. }) {
  13018. this.commitOrRemove();
  13019. this.viewParameters.rotation = pagesRotation;
  13020. }
  13021. addToAnnotationStorage(editor) {
  13022. if (!editor.isEmpty() && this.#annotationStorage && !this.#annotationStorage.has(editor.id)) {
  13023. this.#annotationStorage.setValue(editor.id, editor);
  13024. }
  13025. }
  13026. #addFocusManager() {
  13027. window.addEventListener("focus", this.#boundFocus);
  13028. window.addEventListener("blur", this.#boundBlur);
  13029. }
  13030. #removeFocusManager() {
  13031. window.removeEventListener("focus", this.#boundFocus);
  13032. window.removeEventListener("blur", this.#boundBlur);
  13033. }
  13034. blur() {
  13035. if (!this.hasSelection) {
  13036. return;
  13037. }
  13038. const {
  13039. activeElement
  13040. } = document;
  13041. for (const editor of this.#selectedEditors) {
  13042. if (editor.div.contains(activeElement)) {
  13043. this.#lastActiveElement = [editor, activeElement];
  13044. editor._focusEventsAllowed = false;
  13045. break;
  13046. }
  13047. }
  13048. }
  13049. focus() {
  13050. if (!this.#lastActiveElement) {
  13051. return;
  13052. }
  13053. const [lastEditor, lastActiveElement] = this.#lastActiveElement;
  13054. this.#lastActiveElement = null;
  13055. lastActiveElement.addEventListener("focusin", () => {
  13056. lastEditor._focusEventsAllowed = true;
  13057. }, {
  13058. once: true
  13059. });
  13060. lastActiveElement.focus();
  13061. }
  13062. #addKeyboardManager() {
  13063. window.addEventListener("keydown", this.#boundKeydown);
  13064. }
  13065. #removeKeyboardManager() {
  13066. window.removeEventListener("keydown", this.#boundKeydown);
  13067. }
  13068. #addCopyPasteListeners() {
  13069. document.addEventListener("copy", this.#boundCopy);
  13070. document.addEventListener("cut", this.#boundCut);
  13071. document.addEventListener("paste", this.#boundPaste);
  13072. }
  13073. #removeCopyPasteListeners() {
  13074. document.removeEventListener("copy", this.#boundCopy);
  13075. document.removeEventListener("cut", this.#boundCut);
  13076. document.removeEventListener("paste", this.#boundPaste);
  13077. }
  13078. addEditListeners() {
  13079. this.#addKeyboardManager();
  13080. this.#addCopyPasteListeners();
  13081. }
  13082. removeEditListeners() {
  13083. this.#removeKeyboardManager();
  13084. this.#removeCopyPasteListeners();
  13085. }
  13086. copy(event) {
  13087. event.preventDefault();
  13088. this.#activeEditor?.commitOrRemove();
  13089. if (!this.hasSelection) {
  13090. return;
  13091. }
  13092. const editors = [];
  13093. for (const editor of this.#selectedEditors) {
  13094. const serialized = editor.serialize(true);
  13095. if (serialized) {
  13096. editors.push(serialized);
  13097. }
  13098. }
  13099. if (editors.length === 0) {
  13100. return;
  13101. }
  13102. event.clipboardData.setData("application/pdfjs", JSON.stringify(editors));
  13103. }
  13104. cut(event) {
  13105. this.copy(event);
  13106. this.delete();
  13107. }
  13108. paste(event) {
  13109. event.preventDefault();
  13110. const {
  13111. clipboardData
  13112. } = event;
  13113. for (const item of clipboardData.items) {
  13114. for (const editorType of this.#editorTypes) {
  13115. if (editorType.isHandlingMimeForPasting(item.type)) {
  13116. editorType.paste(item, this.currentLayer);
  13117. return;
  13118. }
  13119. }
  13120. }
  13121. let data = clipboardData.getData("application/pdfjs");
  13122. if (!data) {
  13123. return;
  13124. }
  13125. try {
  13126. data = JSON.parse(data);
  13127. } catch (ex) {
  13128. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`paste: "${ex.message}".`);
  13129. return;
  13130. }
  13131. if (!Array.isArray(data)) {
  13132. return;
  13133. }
  13134. this.unselectAll();
  13135. const layer = this.currentLayer;
  13136. try {
  13137. const newEditors = [];
  13138. for (const editor of data) {
  13139. const deserializedEditor = layer.deserialize(editor);
  13140. if (!deserializedEditor) {
  13141. return;
  13142. }
  13143. newEditors.push(deserializedEditor);
  13144. }
  13145. const cmd = () => {
  13146. for (const editor of newEditors) {
  13147. this.#addEditorToLayer(editor);
  13148. }
  13149. this.#selectEditors(newEditors);
  13150. };
  13151. const undo = () => {
  13152. for (const editor of newEditors) {
  13153. editor.remove();
  13154. }
  13155. };
  13156. this.addCommands({
  13157. cmd,
  13158. undo,
  13159. mustExec: true
  13160. });
  13161. } catch (ex) {
  13162. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`paste: "${ex.message}".`);
  13163. }
  13164. }
  13165. keydown(event) {
  13166. if (!this.isEditorHandlingKeyboard) {
  13167. AnnotationEditorUIManager._keyboardManager.exec(this, event);
  13168. }
  13169. }
  13170. onEditingAction(details) {
  13171. if (["undo", "redo", "delete", "selectAll"].includes(details.name)) {
  13172. this[details.name]();
  13173. }
  13174. }
  13175. #dispatchUpdateStates(details) {
  13176. const hasChanged = Object.entries(details).some(([key, value]) => this.#previousStates[key] !== value);
  13177. if (hasChanged) {
  13178. this._eventBus.dispatch("annotationeditorstateschanged", {
  13179. source: this,
  13180. details: Object.assign(this.#previousStates, details)
  13181. });
  13182. }
  13183. }
  13184. #dispatchUpdateUI(details) {
  13185. this._eventBus.dispatch("annotationeditorparamschanged", {
  13186. source: this,
  13187. details
  13188. });
  13189. }
  13190. setEditingState(isEditing) {
  13191. if (isEditing) {
  13192. this.#addFocusManager();
  13193. this.#addKeyboardManager();
  13194. this.#addCopyPasteListeners();
  13195. this.#dispatchUpdateStates({
  13196. isEditing: this.#mode !== _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE,
  13197. isEmpty: this.#isEmpty(),
  13198. hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
  13199. hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
  13200. hasSelectedEditor: false
  13201. });
  13202. } else {
  13203. this.#removeFocusManager();
  13204. this.#removeKeyboardManager();
  13205. this.#removeCopyPasteListeners();
  13206. this.#dispatchUpdateStates({
  13207. isEditing: false
  13208. });
  13209. this.disableUserSelect(false);
  13210. }
  13211. }
  13212. registerEditorTypes(types) {
  13213. if (this.#editorTypes) {
  13214. return;
  13215. }
  13216. this.#editorTypes = types;
  13217. for (const editorType of this.#editorTypes) {
  13218. this.#dispatchUpdateUI(editorType.defaultPropertiesToUpdate);
  13219. }
  13220. }
  13221. getId() {
  13222. return this.#idManager.getId();
  13223. }
  13224. get currentLayer() {
  13225. return this.#allLayers.get(this.#currentPageIndex);
  13226. }
  13227. getLayer(pageIndex) {
  13228. return this.#allLayers.get(pageIndex);
  13229. }
  13230. get currentPageIndex() {
  13231. return this.#currentPageIndex;
  13232. }
  13233. addLayer(layer) {
  13234. this.#allLayers.set(layer.pageIndex, layer);
  13235. if (this.#isEnabled) {
  13236. layer.enable();
  13237. } else {
  13238. layer.disable();
  13239. }
  13240. }
  13241. removeLayer(layer) {
  13242. this.#allLayers.delete(layer.pageIndex);
  13243. }
  13244. updateMode(mode, editId = null, isFromKeyboard = false) {
  13245. if (this.#mode === mode) {
  13246. return;
  13247. }
  13248. this.#mode = mode;
  13249. if (mode === _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE) {
  13250. this.setEditingState(false);
  13251. this.#disableAll();
  13252. return;
  13253. }
  13254. this.setEditingState(true);
  13255. this.#enableAll();
  13256. this.unselectAll();
  13257. for (const layer of this.#allLayers.values()) {
  13258. layer.updateMode(mode);
  13259. }
  13260. if (!editId && isFromKeyboard) {
  13261. this.addNewEditorFromKeyboard();
  13262. return;
  13263. }
  13264. if (!editId) {
  13265. return;
  13266. }
  13267. for (const editor of this.#allEditors.values()) {
  13268. if (editor.annotationElementId === editId) {
  13269. this.setSelected(editor);
  13270. editor.enterInEditMode();
  13271. break;
  13272. }
  13273. }
  13274. }
  13275. addNewEditorFromKeyboard() {
  13276. if (this.currentLayer.canCreateNewEmptyEditor()) {
  13277. this.currentLayer.addNewEditor();
  13278. }
  13279. }
  13280. updateToolbar(mode) {
  13281. if (mode === this.#mode) {
  13282. return;
  13283. }
  13284. this._eventBus.dispatch("switchannotationeditormode", {
  13285. source: this,
  13286. mode
  13287. });
  13288. }
  13289. updateParams(type, value) {
  13290. if (!this.#editorTypes) {
  13291. return;
  13292. }
  13293. switch (type) {
  13294. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.CREATE:
  13295. this.currentLayer.addNewEditor();
  13296. return;
  13297. case _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
  13298. this.#mainHighlightColorPicker?.updateColor(value);
  13299. break;
  13300. }
  13301. for (const editor of this.#selectedEditors) {
  13302. editor.updateParams(type, value);
  13303. }
  13304. for (const editorType of this.#editorTypes) {
  13305. editorType.updateDefaultParams(type, value);
  13306. }
  13307. }
  13308. enableWaiting(mustWait = false) {
  13309. if (this.#isWaiting === mustWait) {
  13310. return;
  13311. }
  13312. this.#isWaiting = mustWait;
  13313. for (const layer of this.#allLayers.values()) {
  13314. if (mustWait) {
  13315. layer.disableClick();
  13316. } else {
  13317. layer.enableClick();
  13318. }
  13319. layer.div.classList.toggle("waiting", mustWait);
  13320. }
  13321. }
  13322. #enableAll() {
  13323. if (!this.#isEnabled) {
  13324. this.#isEnabled = true;
  13325. for (const layer of this.#allLayers.values()) {
  13326. layer.enable();
  13327. }
  13328. }
  13329. }
  13330. #disableAll() {
  13331. this.unselectAll();
  13332. if (this.#isEnabled) {
  13333. this.#isEnabled = false;
  13334. for (const layer of this.#allLayers.values()) {
  13335. layer.disable();
  13336. }
  13337. }
  13338. }
  13339. getEditors(pageIndex) {
  13340. const editors = [];
  13341. for (const editor of this.#allEditors.values()) {
  13342. if (editor.pageIndex === pageIndex) {
  13343. editors.push(editor);
  13344. }
  13345. }
  13346. return editors;
  13347. }
  13348. getEditor(id) {
  13349. return this.#allEditors.get(id);
  13350. }
  13351. addEditor(editor) {
  13352. this.#allEditors.set(editor.id, editor);
  13353. }
  13354. removeEditor(editor) {
  13355. if (editor.div.contains(document.activeElement)) {
  13356. if (this.#focusMainContainerTimeoutId) {
  13357. clearTimeout(this.#focusMainContainerTimeoutId);
  13358. }
  13359. this.#focusMainContainerTimeoutId = setTimeout(() => {
  13360. this.focusMainContainer();
  13361. this.#focusMainContainerTimeoutId = null;
  13362. }, 0);
  13363. }
  13364. this.#allEditors.delete(editor.id);
  13365. this.unselect(editor);
  13366. if (!editor.annotationElementId || !this.#deletedAnnotationsElementIds.has(editor.annotationElementId)) {
  13367. this.#annotationStorage?.remove(editor.id);
  13368. }
  13369. }
  13370. addDeletedAnnotationElement(editor) {
  13371. this.#deletedAnnotationsElementIds.add(editor.annotationElementId);
  13372. editor.deleted = true;
  13373. }
  13374. isDeletedAnnotationElement(annotationElementId) {
  13375. return this.#deletedAnnotationsElementIds.has(annotationElementId);
  13376. }
  13377. removeDeletedAnnotationElement(editor) {
  13378. this.#deletedAnnotationsElementIds.delete(editor.annotationElementId);
  13379. editor.deleted = false;
  13380. }
  13381. #addEditorToLayer(editor) {
  13382. const layer = this.#allLayers.get(editor.pageIndex);
  13383. if (layer) {
  13384. layer.addOrRebuild(editor);
  13385. } else {
  13386. this.addEditor(editor);
  13387. }
  13388. }
  13389. setActiveEditor(editor) {
  13390. if (this.#activeEditor === editor) {
  13391. return;
  13392. }
  13393. this.#activeEditor = editor;
  13394. if (editor) {
  13395. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  13396. }
  13397. }
  13398. toggleSelected(editor) {
  13399. if (this.#selectedEditors.has(editor)) {
  13400. this.#selectedEditors.delete(editor);
  13401. editor.unselect();
  13402. this.#dispatchUpdateStates({
  13403. hasSelectedEditor: this.hasSelection
  13404. });
  13405. return;
  13406. }
  13407. this.#selectedEditors.add(editor);
  13408. editor.select();
  13409. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  13410. this.#dispatchUpdateStates({
  13411. hasSelectedEditor: true
  13412. });
  13413. }
  13414. setSelected(editor) {
  13415. for (const ed of this.#selectedEditors) {
  13416. if (ed !== editor) {
  13417. ed.unselect();
  13418. }
  13419. }
  13420. this.#selectedEditors.clear();
  13421. this.#selectedEditors.add(editor);
  13422. editor.select();
  13423. this.#dispatchUpdateUI(editor.propertiesToUpdate);
  13424. this.#dispatchUpdateStates({
  13425. hasSelectedEditor: true
  13426. });
  13427. }
  13428. isSelected(editor) {
  13429. return this.#selectedEditors.has(editor);
  13430. }
  13431. get firstSelectedEditor() {
  13432. return this.#selectedEditors.values().next().value;
  13433. }
  13434. unselect(editor) {
  13435. editor.unselect();
  13436. this.#selectedEditors.delete(editor);
  13437. this.#dispatchUpdateStates({
  13438. hasSelectedEditor: this.hasSelection
  13439. });
  13440. }
  13441. get hasSelection() {
  13442. return this.#selectedEditors.size !== 0;
  13443. }
  13444. get isEnterHandled() {
  13445. return this.#selectedEditors.size === 1 && this.firstSelectedEditor.isEnterHandled;
  13446. }
  13447. undo() {
  13448. this.#commandManager.undo();
  13449. this.#dispatchUpdateStates({
  13450. hasSomethingToUndo: this.#commandManager.hasSomethingToUndo(),
  13451. hasSomethingToRedo: true,
  13452. isEmpty: this.#isEmpty()
  13453. });
  13454. }
  13455. redo() {
  13456. this.#commandManager.redo();
  13457. this.#dispatchUpdateStates({
  13458. hasSomethingToUndo: true,
  13459. hasSomethingToRedo: this.#commandManager.hasSomethingToRedo(),
  13460. isEmpty: this.#isEmpty()
  13461. });
  13462. }
  13463. addCommands(params) {
  13464. this.#commandManager.add(params);
  13465. this.#dispatchUpdateStates({
  13466. hasSomethingToUndo: true,
  13467. hasSomethingToRedo: false,
  13468. isEmpty: this.#isEmpty()
  13469. });
  13470. }
  13471. #isEmpty() {
  13472. if (this.#allEditors.size === 0) {
  13473. return true;
  13474. }
  13475. if (this.#allEditors.size === 1) {
  13476. for (const editor of this.#allEditors.values()) {
  13477. return editor.isEmpty();
  13478. }
  13479. }
  13480. return false;
  13481. }
  13482. delete() {
  13483. this.commitOrRemove();
  13484. if (!this.hasSelection) {
  13485. return;
  13486. }
  13487. const editors = [...this.#selectedEditors];
  13488. const cmd = () => {
  13489. for (const editor of editors) {
  13490. editor.remove();
  13491. }
  13492. };
  13493. const undo = () => {
  13494. for (const editor of editors) {
  13495. this.#addEditorToLayer(editor);
  13496. }
  13497. };
  13498. this.addCommands({
  13499. cmd,
  13500. undo,
  13501. mustExec: true
  13502. });
  13503. }
  13504. commitOrRemove() {
  13505. this.#activeEditor?.commitOrRemove();
  13506. }
  13507. hasSomethingToControl() {
  13508. return this.#activeEditor || this.hasSelection;
  13509. }
  13510. #selectEditors(editors) {
  13511. this.#selectedEditors.clear();
  13512. for (const editor of editors) {
  13513. if (editor.isEmpty()) {
  13514. continue;
  13515. }
  13516. this.#selectedEditors.add(editor);
  13517. editor.select();
  13518. }
  13519. this.#dispatchUpdateStates({
  13520. hasSelectedEditor: true
  13521. });
  13522. }
  13523. selectAll() {
  13524. for (const editor of this.#selectedEditors) {
  13525. editor.commit();
  13526. }
  13527. this.#selectEditors(this.#allEditors.values());
  13528. }
  13529. unselectAll() {
  13530. if (this.#activeEditor) {
  13531. this.#activeEditor.commitOrRemove();
  13532. if (this.#mode !== _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType.NONE) {
  13533. return;
  13534. }
  13535. }
  13536. if (!this.hasSelection) {
  13537. return;
  13538. }
  13539. for (const editor of this.#selectedEditors) {
  13540. editor.unselect();
  13541. }
  13542. this.#selectedEditors.clear();
  13543. this.#dispatchUpdateStates({
  13544. hasSelectedEditor: false
  13545. });
  13546. }
  13547. translateSelectedEditors(x, y, noCommit = false) {
  13548. if (!noCommit) {
  13549. this.commitOrRemove();
  13550. }
  13551. if (!this.hasSelection) {
  13552. return;
  13553. }
  13554. this.#translation[0] += x;
  13555. this.#translation[1] += y;
  13556. const [totalX, totalY] = this.#translation;
  13557. const editors = [...this.#selectedEditors];
  13558. const TIME_TO_WAIT = 1000;
  13559. if (this.#translationTimeoutId) {
  13560. clearTimeout(this.#translationTimeoutId);
  13561. }
  13562. this.#translationTimeoutId = setTimeout(() => {
  13563. this.#translationTimeoutId = null;
  13564. this.#translation[0] = this.#translation[1] = 0;
  13565. this.addCommands({
  13566. cmd: () => {
  13567. for (const editor of editors) {
  13568. if (this.#allEditors.has(editor.id)) {
  13569. editor.translateInPage(totalX, totalY);
  13570. }
  13571. }
  13572. },
  13573. undo: () => {
  13574. for (const editor of editors) {
  13575. if (this.#allEditors.has(editor.id)) {
  13576. editor.translateInPage(-totalX, -totalY);
  13577. }
  13578. }
  13579. },
  13580. mustExec: false
  13581. });
  13582. }, TIME_TO_WAIT);
  13583. for (const editor of editors) {
  13584. editor.translateInPage(x, y);
  13585. }
  13586. }
  13587. setUpDragSession() {
  13588. if (!this.hasSelection) {
  13589. return;
  13590. }
  13591. this.disableUserSelect(true);
  13592. this.#draggingEditors = new Map();
  13593. for (const editor of this.#selectedEditors) {
  13594. this.#draggingEditors.set(editor, {
  13595. savedX: editor.x,
  13596. savedY: editor.y,
  13597. savedPageIndex: editor.pageIndex,
  13598. newX: 0,
  13599. newY: 0,
  13600. newPageIndex: -1
  13601. });
  13602. }
  13603. }
  13604. endDragSession() {
  13605. if (!this.#draggingEditors) {
  13606. return false;
  13607. }
  13608. this.disableUserSelect(false);
  13609. const map = this.#draggingEditors;
  13610. this.#draggingEditors = null;
  13611. let mustBeAddedInUndoStack = false;
  13612. for (const [{
  13613. x,
  13614. y,
  13615. pageIndex
  13616. }, value] of map) {
  13617. value.newX = x;
  13618. value.newY = y;
  13619. value.newPageIndex = pageIndex;
  13620. mustBeAddedInUndoStack ||= x !== value.savedX || y !== value.savedY || pageIndex !== value.savedPageIndex;
  13621. }
  13622. if (!mustBeAddedInUndoStack) {
  13623. return false;
  13624. }
  13625. const move = (editor, x, y, pageIndex) => {
  13626. if (this.#allEditors.has(editor.id)) {
  13627. const parent = this.#allLayers.get(pageIndex);
  13628. if (parent) {
  13629. editor._setParentAndPosition(parent, x, y);
  13630. } else {
  13631. editor.pageIndex = pageIndex;
  13632. editor.x = x;
  13633. editor.y = y;
  13634. }
  13635. }
  13636. };
  13637. this.addCommands({
  13638. cmd: () => {
  13639. for (const [editor, {
  13640. newX,
  13641. newY,
  13642. newPageIndex
  13643. }] of map) {
  13644. move(editor, newX, newY, newPageIndex);
  13645. }
  13646. },
  13647. undo: () => {
  13648. for (const [editor, {
  13649. savedX,
  13650. savedY,
  13651. savedPageIndex
  13652. }] of map) {
  13653. move(editor, savedX, savedY, savedPageIndex);
  13654. }
  13655. },
  13656. mustExec: true
  13657. });
  13658. return true;
  13659. }
  13660. dragSelectedEditors(tx, ty) {
  13661. if (!this.#draggingEditors) {
  13662. return;
  13663. }
  13664. for (const editor of this.#draggingEditors.keys()) {
  13665. editor.drag(tx, ty);
  13666. }
  13667. }
  13668. rebuild(editor) {
  13669. if (editor.parent === null) {
  13670. const parent = this.getLayer(editor.pageIndex);
  13671. if (parent) {
  13672. parent.changeParent(editor);
  13673. parent.addOrRebuild(editor);
  13674. } else {
  13675. this.addEditor(editor);
  13676. this.addToAnnotationStorage(editor);
  13677. editor.rebuild();
  13678. }
  13679. } else {
  13680. editor.parent.addOrRebuild(editor);
  13681. }
  13682. }
  13683. get isEditorHandlingKeyboard() {
  13684. return this.getActive()?.shouldGetKeyboardEvents() || this.#selectedEditors.size === 1 && this.firstSelectedEditor.shouldGetKeyboardEvents();
  13685. }
  13686. isActive(editor) {
  13687. return this.#activeEditor === editor;
  13688. }
  13689. getActive() {
  13690. return this.#activeEditor;
  13691. }
  13692. getMode() {
  13693. return this.#mode;
  13694. }
  13695. get imageManager() {
  13696. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "imageManager", new ImageManager());
  13697. }
  13698. }
  13699. /***/ }),
  13700. /***/ 171:
  13701. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  13702. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  13703. /* harmony export */ PDFFetchStream: () => (/* binding */ PDFFetchStream)
  13704. /* harmony export */ });
  13705. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  13706. /* harmony import */ var _network_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(253);
  13707. ;
  13708. function createFetchOptions(headers, withCredentials, abortController) {
  13709. return {
  13710. method: "GET",
  13711. headers,
  13712. signal: abortController.signal,
  13713. mode: "cors",
  13714. credentials: withCredentials ? "include" : "same-origin",
  13715. redirect: "follow"
  13716. };
  13717. }
  13718. function createHeaders(httpHeaders) {
  13719. const headers = new Headers();
  13720. for (const property in httpHeaders) {
  13721. const value = httpHeaders[property];
  13722. if (value === undefined) {
  13723. continue;
  13724. }
  13725. headers.append(property, value);
  13726. }
  13727. return headers;
  13728. }
  13729. function getArrayBuffer(val) {
  13730. if (val instanceof Uint8Array) {
  13731. return val.buffer;
  13732. }
  13733. if (val instanceof ArrayBuffer) {
  13734. return val;
  13735. }
  13736. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`getArrayBuffer - unexpected data format: ${val}`);
  13737. return new Uint8Array(val).buffer;
  13738. }
  13739. class PDFFetchStream {
  13740. constructor(source) {
  13741. this.source = source;
  13742. this.isHttp = /^https?:/i.test(source.url);
  13743. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  13744. this._fullRequestReader = null;
  13745. this._rangeRequestReaders = [];
  13746. }
  13747. get _progressiveDataLength() {
  13748. return this._fullRequestReader?._loaded ?? 0;
  13749. }
  13750. getFullReader() {
  13751. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  13752. this._fullRequestReader = new PDFFetchStreamReader(this);
  13753. return this._fullRequestReader;
  13754. }
  13755. getRangeReader(begin, end) {
  13756. if (end <= this._progressiveDataLength) {
  13757. return null;
  13758. }
  13759. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  13760. this._rangeRequestReaders.push(reader);
  13761. return reader;
  13762. }
  13763. cancelAllRequests(reason) {
  13764. this._fullRequestReader?.cancel(reason);
  13765. for (const reader of this._rangeRequestReaders.slice(0)) {
  13766. reader.cancel(reason);
  13767. }
  13768. }
  13769. }
  13770. class PDFFetchStreamReader {
  13771. constructor(stream) {
  13772. this._stream = stream;
  13773. this._reader = null;
  13774. this._loaded = 0;
  13775. this._filename = null;
  13776. const source = stream.source;
  13777. this._withCredentials = source.withCredentials || false;
  13778. this._contentLength = source.length;
  13779. this._headersCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  13780. this._disableRange = source.disableRange || false;
  13781. this._rangeChunkSize = source.rangeChunkSize;
  13782. if (!this._rangeChunkSize && !this._disableRange) {
  13783. this._disableRange = true;
  13784. }
  13785. this._abortController = new AbortController();
  13786. this._isStreamingSupported = !source.disableStream;
  13787. this._isRangeSupported = !source.disableRange;
  13788. this._headers = createHeaders(this._stream.httpHeaders);
  13789. const url = source.url;
  13790. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  13791. if (!(0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.validateResponseStatus)(response.status)) {
  13792. throw (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.createResponseStatusError)(response.status, url);
  13793. }
  13794. this._reader = response.body.getReader();
  13795. this._headersCapability.resolve();
  13796. const getResponseHeader = name => {
  13797. return response.headers.get(name);
  13798. };
  13799. const {
  13800. allowRangeRequests,
  13801. suggestedLength
  13802. } = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.validateRangeRequestCapabilities)({
  13803. getResponseHeader,
  13804. isHttp: this._stream.isHttp,
  13805. rangeChunkSize: this._rangeChunkSize,
  13806. disableRange: this._disableRange
  13807. });
  13808. this._isRangeSupported = allowRangeRequests;
  13809. this._contentLength = suggestedLength || this._contentLength;
  13810. this._filename = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.extractFilenameFromHeader)(getResponseHeader);
  13811. if (!this._isStreamingSupported && this._isRangeSupported) {
  13812. this.cancel(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException("Streaming is disabled."));
  13813. }
  13814. }).catch(this._headersCapability.reject);
  13815. this.onProgress = null;
  13816. }
  13817. get headersReady() {
  13818. return this._headersCapability.promise;
  13819. }
  13820. get filename() {
  13821. return this._filename;
  13822. }
  13823. get contentLength() {
  13824. return this._contentLength;
  13825. }
  13826. get isRangeSupported() {
  13827. return this._isRangeSupported;
  13828. }
  13829. get isStreamingSupported() {
  13830. return this._isStreamingSupported;
  13831. }
  13832. async read() {
  13833. await this._headersCapability.promise;
  13834. const {
  13835. value,
  13836. done
  13837. } = await this._reader.read();
  13838. if (done) {
  13839. return {
  13840. value,
  13841. done
  13842. };
  13843. }
  13844. this._loaded += value.byteLength;
  13845. this.onProgress?.({
  13846. loaded: this._loaded,
  13847. total: this._contentLength
  13848. });
  13849. return {
  13850. value: getArrayBuffer(value),
  13851. done: false
  13852. };
  13853. }
  13854. cancel(reason) {
  13855. this._reader?.cancel(reason);
  13856. this._abortController.abort();
  13857. }
  13858. }
  13859. class PDFFetchStreamRangeReader {
  13860. constructor(stream, begin, end) {
  13861. this._stream = stream;
  13862. this._reader = null;
  13863. this._loaded = 0;
  13864. const source = stream.source;
  13865. this._withCredentials = source.withCredentials || false;
  13866. this._readCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  13867. this._isStreamingSupported = !source.disableStream;
  13868. this._abortController = new AbortController();
  13869. this._headers = createHeaders(this._stream.httpHeaders);
  13870. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  13871. const url = source.url;
  13872. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  13873. if (!(0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.validateResponseStatus)(response.status)) {
  13874. throw (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.createResponseStatusError)(response.status, url);
  13875. }
  13876. this._readCapability.resolve();
  13877. this._reader = response.body.getReader();
  13878. }).catch(this._readCapability.reject);
  13879. this.onProgress = null;
  13880. }
  13881. get isStreamingSupported() {
  13882. return this._isStreamingSupported;
  13883. }
  13884. async read() {
  13885. await this._readCapability.promise;
  13886. const {
  13887. value,
  13888. done
  13889. } = await this._reader.read();
  13890. if (done) {
  13891. return {
  13892. value,
  13893. done
  13894. };
  13895. }
  13896. this._loaded += value.byteLength;
  13897. this.onProgress?.({
  13898. loaded: this._loaded
  13899. });
  13900. return {
  13901. value: getArrayBuffer(value),
  13902. done: false
  13903. };
  13904. }
  13905. cancel(reason) {
  13906. this._reader?.cancel(reason);
  13907. this._abortController.abort();
  13908. }
  13909. }
  13910. /***/ }),
  13911. /***/ 742:
  13912. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  13913. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  13914. /* harmony export */ FontFaceObject: () => (/* binding */ FontFaceObject),
  13915. /* harmony export */ FontLoader: () => (/* binding */ FontLoader)
  13916. /* harmony export */ });
  13917. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  13918. class FontLoader {
  13919. #systemFonts = new Set();
  13920. constructor({
  13921. ownerDocument = globalThis.document,
  13922. styleElement = null
  13923. }) {
  13924. this._document = ownerDocument;
  13925. this.nativeFontFaces = new Set();
  13926. this.styleElement = null;
  13927. this.loadingRequests = [];
  13928. this.loadTestFontId = 0;
  13929. }
  13930. addNativeFontFace(nativeFontFace) {
  13931. this.nativeFontFaces.add(nativeFontFace);
  13932. this._document.fonts.add(nativeFontFace);
  13933. }
  13934. removeNativeFontFace(nativeFontFace) {
  13935. this.nativeFontFaces.delete(nativeFontFace);
  13936. this._document.fonts.delete(nativeFontFace);
  13937. }
  13938. insertRule(rule) {
  13939. if (!this.styleElement) {
  13940. this.styleElement = this._document.createElement("style");
  13941. this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement);
  13942. }
  13943. const styleSheet = this.styleElement.sheet;
  13944. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  13945. }
  13946. clear() {
  13947. for (const nativeFontFace of this.nativeFontFaces) {
  13948. this._document.fonts.delete(nativeFontFace);
  13949. }
  13950. this.nativeFontFaces.clear();
  13951. this.#systemFonts.clear();
  13952. if (this.styleElement) {
  13953. this.styleElement.remove();
  13954. this.styleElement = null;
  13955. }
  13956. }
  13957. async loadSystemFont({
  13958. systemFontInfo: info,
  13959. _inspectFont
  13960. }) {
  13961. if (!info || this.#systemFonts.has(info.loadedName)) {
  13962. return;
  13963. }
  13964. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!this.disableFontFace, "loadSystemFont shouldn't be called when `disableFontFace` is set.");
  13965. if (this.isFontLoadingAPISupported) {
  13966. const {
  13967. loadedName,
  13968. src,
  13969. style
  13970. } = info;
  13971. const fontFace = new FontFace(loadedName, src, style);
  13972. this.addNativeFontFace(fontFace);
  13973. try {
  13974. await fontFace.load();
  13975. this.#systemFonts.add(loadedName);
  13976. _inspectFont?.(info);
  13977. } catch {
  13978. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Cannot load system font: ${info.baseFontName}, installing it could help to improve PDF rendering.`);
  13979. this.removeNativeFontFace(fontFace);
  13980. }
  13981. return;
  13982. }
  13983. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Not implemented: loadSystemFont without the Font Loading API.");
  13984. }
  13985. async bind(font) {
  13986. if (font.attached || font.missingFile && !font.systemFontInfo) {
  13987. return;
  13988. }
  13989. font.attached = true;
  13990. if (font.systemFontInfo) {
  13991. await this.loadSystemFont(font);
  13992. return;
  13993. }
  13994. if (this.isFontLoadingAPISupported) {
  13995. const nativeFontFace = font.createNativeFontFace();
  13996. if (nativeFontFace) {
  13997. this.addNativeFontFace(nativeFontFace);
  13998. try {
  13999. await nativeFontFace.loaded;
  14000. } catch (ex) {
  14001. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  14002. font.disableFontFace = true;
  14003. throw ex;
  14004. }
  14005. }
  14006. return;
  14007. }
  14008. const rule = font.createFontFaceRule();
  14009. if (rule) {
  14010. this.insertRule(rule);
  14011. if (this.isSyncFontLoadingSupported) {
  14012. return;
  14013. }
  14014. await new Promise(resolve => {
  14015. const request = this._queueLoadingCallback(resolve);
  14016. this._prepareFontLoadEvent(font, request);
  14017. });
  14018. }
  14019. }
  14020. get isFontLoadingAPISupported() {
  14021. const hasFonts = !!this._document?.fonts;
  14022. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "isFontLoadingAPISupported", hasFonts);
  14023. }
  14024. get isSyncFontLoadingSupported() {
  14025. let supported = false;
  14026. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS) {
  14027. supported = true;
  14028. } else if (typeof navigator !== "undefined" && typeof navigator?.userAgent === "string" && /Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent)) {
  14029. supported = true;
  14030. }
  14031. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "isSyncFontLoadingSupported", supported);
  14032. }
  14033. _queueLoadingCallback(callback) {
  14034. function completeRequest() {
  14035. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!request.done, "completeRequest() cannot be called twice.");
  14036. request.done = true;
  14037. while (loadingRequests.length > 0 && loadingRequests[0].done) {
  14038. const otherRequest = loadingRequests.shift();
  14039. setTimeout(otherRequest.callback, 0);
  14040. }
  14041. }
  14042. const {
  14043. loadingRequests
  14044. } = this;
  14045. const request = {
  14046. done: false,
  14047. complete: completeRequest,
  14048. callback
  14049. };
  14050. loadingRequests.push(request);
  14051. return request;
  14052. }
  14053. get _loadTestFont() {
  14054. const testFont = atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQA" + "FQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAA" + "ALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgA" + "AAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1" + "AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD" + "6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACM" + "AooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4D" + "IP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAA" + "AAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUA" + "AQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgAB" + "AAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABY" + "AAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAA" + "AC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAA" + "AAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQAC" + "AQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3" + "Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTj" + "FQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");
  14055. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow)(this, "_loadTestFont", testFont);
  14056. }
  14057. _prepareFontLoadEvent(font, request) {
  14058. function int32(data, offset) {
  14059. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  14060. }
  14061. function spliceString(s, offset, remove, insert) {
  14062. const chunk1 = s.substring(0, offset);
  14063. const chunk2 = s.substring(offset + remove);
  14064. return chunk1 + insert + chunk2;
  14065. }
  14066. let i, ii;
  14067. const canvas = this._document.createElement("canvas");
  14068. canvas.width = 1;
  14069. canvas.height = 1;
  14070. const ctx = canvas.getContext("2d");
  14071. let called = 0;
  14072. function isFontReady(name, callback) {
  14073. if (++called > 30) {
  14074. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)("Load test font never loaded.");
  14075. callback();
  14076. return;
  14077. }
  14078. ctx.font = "30px " + name;
  14079. ctx.fillText(".", 0, 20);
  14080. const imageData = ctx.getImageData(0, 0, 1, 1);
  14081. if (imageData.data[3] > 0) {
  14082. callback();
  14083. return;
  14084. }
  14085. setTimeout(isFontReady.bind(null, name, callback));
  14086. }
  14087. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  14088. let data = this._loadTestFont;
  14089. const COMMENT_OFFSET = 976;
  14090. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  14091. const CFF_CHECKSUM_OFFSET = 16;
  14092. const XXXX_VALUE = 0x58585858;
  14093. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  14094. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  14095. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  14096. }
  14097. if (i < loadTestFontId.length) {
  14098. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  14099. }
  14100. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.string32)(checksum));
  14101. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  14102. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  14103. this.insertRule(rule);
  14104. const div = this._document.createElement("div");
  14105. div.style.visibility = "hidden";
  14106. div.style.width = div.style.height = "10px";
  14107. div.style.position = "absolute";
  14108. div.style.top = div.style.left = "0px";
  14109. for (const name of [font.loadedName, loadTestFontId]) {
  14110. const span = this._document.createElement("span");
  14111. span.textContent = "Hi";
  14112. span.style.fontFamily = name;
  14113. div.append(span);
  14114. }
  14115. this._document.body.append(div);
  14116. isFontReady(loadTestFontId, () => {
  14117. div.remove();
  14118. request.complete();
  14119. });
  14120. }
  14121. }
  14122. class FontFaceObject {
  14123. constructor(translatedData, {
  14124. isEvalSupported = true,
  14125. disableFontFace = false,
  14126. ignoreErrors = false,
  14127. inspectFont = null
  14128. }) {
  14129. this.compiledGlyphs = Object.create(null);
  14130. for (const i in translatedData) {
  14131. this[i] = translatedData[i];
  14132. }
  14133. this.isEvalSupported = isEvalSupported !== false;
  14134. this.disableFontFace = disableFontFace === true;
  14135. this.ignoreErrors = ignoreErrors === true;
  14136. this._inspectFont = inspectFont;
  14137. }
  14138. createNativeFontFace() {
  14139. if (!this.data || this.disableFontFace) {
  14140. return null;
  14141. }
  14142. let nativeFontFace;
  14143. if (!this.cssFontInfo) {
  14144. nativeFontFace = new FontFace(this.loadedName, this.data, {});
  14145. } else {
  14146. const css = {
  14147. weight: this.cssFontInfo.fontWeight
  14148. };
  14149. if (this.cssFontInfo.italicAngle) {
  14150. css.style = `oblique ${this.cssFontInfo.italicAngle}deg`;
  14151. }
  14152. nativeFontFace = new FontFace(this.cssFontInfo.fontFamily, this.data, css);
  14153. }
  14154. this._inspectFont?.(this);
  14155. return nativeFontFace;
  14156. }
  14157. createFontFaceRule() {
  14158. if (!this.data || this.disableFontFace) {
  14159. return null;
  14160. }
  14161. const data = (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.bytesToString)(this.data);
  14162. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  14163. let rule;
  14164. if (!this.cssFontInfo) {
  14165. rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  14166. } else {
  14167. let css = `font-weight: ${this.cssFontInfo.fontWeight};`;
  14168. if (this.cssFontInfo.italicAngle) {
  14169. css += `font-style: oblique ${this.cssFontInfo.italicAngle}deg;`;
  14170. }
  14171. rule = `@font-face {font-family:"${this.cssFontInfo.fontFamily}";${css}src:${url}}`;
  14172. }
  14173. this._inspectFont?.(this, url);
  14174. return rule;
  14175. }
  14176. getPathGenerator(objs, character) {
  14177. if (this.compiledGlyphs[character] !== undefined) {
  14178. return this.compiledGlyphs[character];
  14179. }
  14180. let cmds;
  14181. try {
  14182. cmds = objs.get(this.loadedName + "_path_" + character);
  14183. } catch (ex) {
  14184. if (!this.ignoreErrors) {
  14185. throw ex;
  14186. }
  14187. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  14188. return this.compiledGlyphs[character] = function (c, size) {};
  14189. }
  14190. if (this.isEvalSupported && _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FeatureTest.isEvalSupported) {
  14191. const jsBuf = [];
  14192. for (const current of cmds) {
  14193. const args = current.args !== undefined ? current.args.join(",") : "";
  14194. jsBuf.push("c.", current.cmd, "(", args, ");\n");
  14195. }
  14196. return this.compiledGlyphs[character] = new Function("c", "size", jsBuf.join(""));
  14197. }
  14198. return this.compiledGlyphs[character] = function (c, size) {
  14199. for (const current of cmds) {
  14200. if (current.cmd === "scale") {
  14201. current.args = [size, -size];
  14202. }
  14203. c[current.cmd].apply(c, current.args);
  14204. }
  14205. };
  14206. }
  14207. }
  14208. /***/ }),
  14209. /***/ 472:
  14210. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  14211. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  14212. /* harmony export */ Metadata: () => (/* binding */ Metadata)
  14213. /* harmony export */ });
  14214. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  14215. class Metadata {
  14216. #metadataMap;
  14217. #data;
  14218. constructor({
  14219. parsedData,
  14220. rawData
  14221. }) {
  14222. this.#metadataMap = parsedData;
  14223. this.#data = rawData;
  14224. }
  14225. getRaw() {
  14226. return this.#data;
  14227. }
  14228. get(name) {
  14229. return this.#metadataMap.get(name) ?? null;
  14230. }
  14231. getAll() {
  14232. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.objectFromMap)(this.#metadataMap);
  14233. }
  14234. has(name) {
  14235. return this.#metadataMap.has(name);
  14236. }
  14237. }
  14238. /***/ }),
  14239. /***/ 474:
  14240. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  14241. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  14242. /* harmony export */ PDFNetworkStream: () => (/* binding */ PDFNetworkStream)
  14243. /* harmony export */ });
  14244. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  14245. /* harmony import */ var _network_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(253);
  14246. ;
  14247. const OK_RESPONSE = 200;
  14248. const PARTIAL_CONTENT_RESPONSE = 206;
  14249. function getArrayBuffer(xhr) {
  14250. const data = xhr.response;
  14251. if (typeof data !== "string") {
  14252. return data;
  14253. }
  14254. return (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.stringToBytes)(data).buffer;
  14255. }
  14256. class NetworkManager {
  14257. constructor(url, args = {}) {
  14258. this.url = url;
  14259. this.isHttp = /^https?:/i.test(url);
  14260. this.httpHeaders = this.isHttp && args.httpHeaders || Object.create(null);
  14261. this.withCredentials = args.withCredentials || false;
  14262. this.currXhrId = 0;
  14263. this.pendingRequests = Object.create(null);
  14264. }
  14265. requestRange(begin, end, listeners) {
  14266. const args = {
  14267. begin,
  14268. end
  14269. };
  14270. for (const prop in listeners) {
  14271. args[prop] = listeners[prop];
  14272. }
  14273. return this.request(args);
  14274. }
  14275. requestFull(listeners) {
  14276. return this.request(listeners);
  14277. }
  14278. request(args) {
  14279. const xhr = new XMLHttpRequest();
  14280. const xhrId = this.currXhrId++;
  14281. const pendingRequest = this.pendingRequests[xhrId] = {
  14282. xhr
  14283. };
  14284. xhr.open("GET", this.url);
  14285. xhr.withCredentials = this.withCredentials;
  14286. for (const property in this.httpHeaders) {
  14287. const value = this.httpHeaders[property];
  14288. if (value === undefined) {
  14289. continue;
  14290. }
  14291. xhr.setRequestHeader(property, value);
  14292. }
  14293. if (this.isHttp && "begin" in args && "end" in args) {
  14294. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  14295. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  14296. } else {
  14297. pendingRequest.expectedStatus = OK_RESPONSE;
  14298. }
  14299. xhr.responseType = "arraybuffer";
  14300. if (args.onError) {
  14301. xhr.onerror = function (evt) {
  14302. args.onError(xhr.status);
  14303. };
  14304. }
  14305. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  14306. xhr.onprogress = this.onProgress.bind(this, xhrId);
  14307. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  14308. pendingRequest.onDone = args.onDone;
  14309. pendingRequest.onError = args.onError;
  14310. pendingRequest.onProgress = args.onProgress;
  14311. xhr.send(null);
  14312. return xhrId;
  14313. }
  14314. onProgress(xhrId, evt) {
  14315. const pendingRequest = this.pendingRequests[xhrId];
  14316. if (!pendingRequest) {
  14317. return;
  14318. }
  14319. pendingRequest.onProgress?.(evt);
  14320. }
  14321. onStateChange(xhrId, evt) {
  14322. const pendingRequest = this.pendingRequests[xhrId];
  14323. if (!pendingRequest) {
  14324. return;
  14325. }
  14326. const xhr = pendingRequest.xhr;
  14327. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  14328. pendingRequest.onHeadersReceived();
  14329. delete pendingRequest.onHeadersReceived;
  14330. }
  14331. if (xhr.readyState !== 4) {
  14332. return;
  14333. }
  14334. if (!(xhrId in this.pendingRequests)) {
  14335. return;
  14336. }
  14337. delete this.pendingRequests[xhrId];
  14338. if (xhr.status === 0 && this.isHttp) {
  14339. pendingRequest.onError?.(xhr.status);
  14340. return;
  14341. }
  14342. const xhrStatus = xhr.status || OK_RESPONSE;
  14343. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  14344. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  14345. pendingRequest.onError?.(xhr.status);
  14346. return;
  14347. }
  14348. const chunk = getArrayBuffer(xhr);
  14349. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  14350. const rangeHeader = xhr.getResponseHeader("Content-Range");
  14351. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  14352. pendingRequest.onDone({
  14353. begin: parseInt(matches[1], 10),
  14354. chunk
  14355. });
  14356. } else if (chunk) {
  14357. pendingRequest.onDone({
  14358. begin: 0,
  14359. chunk
  14360. });
  14361. } else {
  14362. pendingRequest.onError?.(xhr.status);
  14363. }
  14364. }
  14365. getRequestXhr(xhrId) {
  14366. return this.pendingRequests[xhrId].xhr;
  14367. }
  14368. isPendingRequest(xhrId) {
  14369. return xhrId in this.pendingRequests;
  14370. }
  14371. abortRequest(xhrId) {
  14372. const xhr = this.pendingRequests[xhrId].xhr;
  14373. delete this.pendingRequests[xhrId];
  14374. xhr.abort();
  14375. }
  14376. }
  14377. class PDFNetworkStream {
  14378. constructor(source) {
  14379. this._source = source;
  14380. this._manager = new NetworkManager(source.url, {
  14381. httpHeaders: source.httpHeaders,
  14382. withCredentials: source.withCredentials
  14383. });
  14384. this._rangeChunkSize = source.rangeChunkSize;
  14385. this._fullRequestReader = null;
  14386. this._rangeRequestReaders = [];
  14387. }
  14388. _onRangeRequestReaderClosed(reader) {
  14389. const i = this._rangeRequestReaders.indexOf(reader);
  14390. if (i >= 0) {
  14391. this._rangeRequestReaders.splice(i, 1);
  14392. }
  14393. }
  14394. getFullReader() {
  14395. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  14396. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  14397. return this._fullRequestReader;
  14398. }
  14399. getRangeReader(begin, end) {
  14400. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  14401. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  14402. this._rangeRequestReaders.push(reader);
  14403. return reader;
  14404. }
  14405. cancelAllRequests(reason) {
  14406. this._fullRequestReader?.cancel(reason);
  14407. for (const reader of this._rangeRequestReaders.slice(0)) {
  14408. reader.cancel(reason);
  14409. }
  14410. }
  14411. }
  14412. class PDFNetworkStreamFullRequestReader {
  14413. constructor(manager, source) {
  14414. this._manager = manager;
  14415. const args = {
  14416. onHeadersReceived: this._onHeadersReceived.bind(this),
  14417. onDone: this._onDone.bind(this),
  14418. onError: this._onError.bind(this),
  14419. onProgress: this._onProgress.bind(this)
  14420. };
  14421. this._url = source.url;
  14422. this._fullRequestId = manager.requestFull(args);
  14423. this._headersReceivedCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  14424. this._disableRange = source.disableRange || false;
  14425. this._contentLength = source.length;
  14426. this._rangeChunkSize = source.rangeChunkSize;
  14427. if (!this._rangeChunkSize && !this._disableRange) {
  14428. this._disableRange = true;
  14429. }
  14430. this._isStreamingSupported = false;
  14431. this._isRangeSupported = false;
  14432. this._cachedChunks = [];
  14433. this._requests = [];
  14434. this._done = false;
  14435. this._storedError = undefined;
  14436. this._filename = null;
  14437. this.onProgress = null;
  14438. }
  14439. _onHeadersReceived() {
  14440. const fullRequestXhrId = this._fullRequestId;
  14441. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  14442. const getResponseHeader = name => {
  14443. return fullRequestXhr.getResponseHeader(name);
  14444. };
  14445. const {
  14446. allowRangeRequests,
  14447. suggestedLength
  14448. } = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.validateRangeRequestCapabilities)({
  14449. getResponseHeader,
  14450. isHttp: this._manager.isHttp,
  14451. rangeChunkSize: this._rangeChunkSize,
  14452. disableRange: this._disableRange
  14453. });
  14454. if (allowRangeRequests) {
  14455. this._isRangeSupported = true;
  14456. }
  14457. this._contentLength = suggestedLength || this._contentLength;
  14458. this._filename = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.extractFilenameFromHeader)(getResponseHeader);
  14459. if (this._isRangeSupported) {
  14460. this._manager.abortRequest(fullRequestXhrId);
  14461. }
  14462. this._headersReceivedCapability.resolve();
  14463. }
  14464. _onDone(data) {
  14465. if (data) {
  14466. if (this._requests.length > 0) {
  14467. const requestCapability = this._requests.shift();
  14468. requestCapability.resolve({
  14469. value: data.chunk,
  14470. done: false
  14471. });
  14472. } else {
  14473. this._cachedChunks.push(data.chunk);
  14474. }
  14475. }
  14476. this._done = true;
  14477. if (this._cachedChunks.length > 0) {
  14478. return;
  14479. }
  14480. for (const requestCapability of this._requests) {
  14481. requestCapability.resolve({
  14482. value: undefined,
  14483. done: true
  14484. });
  14485. }
  14486. this._requests.length = 0;
  14487. }
  14488. _onError(status) {
  14489. this._storedError = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.createResponseStatusError)(status, this._url);
  14490. this._headersReceivedCapability.reject(this._storedError);
  14491. for (const requestCapability of this._requests) {
  14492. requestCapability.reject(this._storedError);
  14493. }
  14494. this._requests.length = 0;
  14495. this._cachedChunks.length = 0;
  14496. }
  14497. _onProgress(evt) {
  14498. this.onProgress?.({
  14499. loaded: evt.loaded,
  14500. total: evt.lengthComputable ? evt.total : this._contentLength
  14501. });
  14502. }
  14503. get filename() {
  14504. return this._filename;
  14505. }
  14506. get isRangeSupported() {
  14507. return this._isRangeSupported;
  14508. }
  14509. get isStreamingSupported() {
  14510. return this._isStreamingSupported;
  14511. }
  14512. get contentLength() {
  14513. return this._contentLength;
  14514. }
  14515. get headersReady() {
  14516. return this._headersReceivedCapability.promise;
  14517. }
  14518. async read() {
  14519. if (this._storedError) {
  14520. throw this._storedError;
  14521. }
  14522. if (this._cachedChunks.length > 0) {
  14523. const chunk = this._cachedChunks.shift();
  14524. return {
  14525. value: chunk,
  14526. done: false
  14527. };
  14528. }
  14529. if (this._done) {
  14530. return {
  14531. value: undefined,
  14532. done: true
  14533. };
  14534. }
  14535. const requestCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  14536. this._requests.push(requestCapability);
  14537. return requestCapability.promise;
  14538. }
  14539. cancel(reason) {
  14540. this._done = true;
  14541. this._headersReceivedCapability.reject(reason);
  14542. for (const requestCapability of this._requests) {
  14543. requestCapability.resolve({
  14544. value: undefined,
  14545. done: true
  14546. });
  14547. }
  14548. this._requests.length = 0;
  14549. if (this._manager.isPendingRequest(this._fullRequestId)) {
  14550. this._manager.abortRequest(this._fullRequestId);
  14551. }
  14552. this._fullRequestReader = null;
  14553. }
  14554. }
  14555. class PDFNetworkStreamRangeRequestReader {
  14556. constructor(manager, begin, end) {
  14557. this._manager = manager;
  14558. const args = {
  14559. onDone: this._onDone.bind(this),
  14560. onError: this._onError.bind(this),
  14561. onProgress: this._onProgress.bind(this)
  14562. };
  14563. this._url = manager.url;
  14564. this._requestId = manager.requestRange(begin, end, args);
  14565. this._requests = [];
  14566. this._queuedChunk = null;
  14567. this._done = false;
  14568. this._storedError = undefined;
  14569. this.onProgress = null;
  14570. this.onClosed = null;
  14571. }
  14572. _close() {
  14573. this.onClosed?.(this);
  14574. }
  14575. _onDone(data) {
  14576. const chunk = data.chunk;
  14577. if (this._requests.length > 0) {
  14578. const requestCapability = this._requests.shift();
  14579. requestCapability.resolve({
  14580. value: chunk,
  14581. done: false
  14582. });
  14583. } else {
  14584. this._queuedChunk = chunk;
  14585. }
  14586. this._done = true;
  14587. for (const requestCapability of this._requests) {
  14588. requestCapability.resolve({
  14589. value: undefined,
  14590. done: true
  14591. });
  14592. }
  14593. this._requests.length = 0;
  14594. this._close();
  14595. }
  14596. _onError(status) {
  14597. this._storedError = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.createResponseStatusError)(status, this._url);
  14598. for (const requestCapability of this._requests) {
  14599. requestCapability.reject(this._storedError);
  14600. }
  14601. this._requests.length = 0;
  14602. this._queuedChunk = null;
  14603. }
  14604. _onProgress(evt) {
  14605. if (!this.isStreamingSupported) {
  14606. this.onProgress?.({
  14607. loaded: evt.loaded
  14608. });
  14609. }
  14610. }
  14611. get isStreamingSupported() {
  14612. return false;
  14613. }
  14614. async read() {
  14615. if (this._storedError) {
  14616. throw this._storedError;
  14617. }
  14618. if (this._queuedChunk !== null) {
  14619. const chunk = this._queuedChunk;
  14620. this._queuedChunk = null;
  14621. return {
  14622. value: chunk,
  14623. done: false
  14624. };
  14625. }
  14626. if (this._done) {
  14627. return {
  14628. value: undefined,
  14629. done: true
  14630. };
  14631. }
  14632. const requestCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  14633. this._requests.push(requestCapability);
  14634. return requestCapability.promise;
  14635. }
  14636. cancel(reason) {
  14637. this._done = true;
  14638. for (const requestCapability of this._requests) {
  14639. requestCapability.resolve({
  14640. value: undefined,
  14641. done: true
  14642. });
  14643. }
  14644. this._requests.length = 0;
  14645. if (this._manager.isPendingRequest(this._requestId)) {
  14646. this._manager.abortRequest(this._requestId);
  14647. }
  14648. this._close();
  14649. }
  14650. }
  14651. /***/ }),
  14652. /***/ 253:
  14653. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  14654. // EXPORTS
  14655. __webpack_require__.d(__webpack_exports__, {
  14656. createResponseStatusError: () => (/* binding */ createResponseStatusError),
  14657. extractFilenameFromHeader: () => (/* binding */ extractFilenameFromHeader),
  14658. validateRangeRequestCapabilities: () => (/* binding */ validateRangeRequestCapabilities),
  14659. validateResponseStatus: () => (/* binding */ validateResponseStatus)
  14660. });
  14661. // EXTERNAL MODULE: ./src/shared/util.js
  14662. var util = __webpack_require__(266);
  14663. ;// CONCATENATED MODULE: ./src/display/content_disposition.js
  14664. function getFilenameFromContentDispositionHeader(contentDisposition) {
  14665. let needsEncodingFixup = true;
  14666. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  14667. if (tmp) {
  14668. tmp = tmp[1];
  14669. let filename = rfc2616unquote(tmp);
  14670. filename = unescape(filename);
  14671. filename = rfc5987decode(filename);
  14672. filename = rfc2047decode(filename);
  14673. return fixupEncoding(filename);
  14674. }
  14675. tmp = rfc2231getparam(contentDisposition);
  14676. if (tmp) {
  14677. const filename = rfc2047decode(tmp);
  14678. return fixupEncoding(filename);
  14679. }
  14680. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  14681. if (tmp) {
  14682. tmp = tmp[1];
  14683. let filename = rfc2616unquote(tmp);
  14684. filename = rfc2047decode(filename);
  14685. return fixupEncoding(filename);
  14686. }
  14687. function toParamRegExp(attributePattern, flags) {
  14688. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  14689. }
  14690. function textdecode(encoding, value) {
  14691. if (encoding) {
  14692. if (!/^[\x00-\xFF]+$/.test(value)) {
  14693. return value;
  14694. }
  14695. try {
  14696. const decoder = new TextDecoder(encoding, {
  14697. fatal: true
  14698. });
  14699. const buffer = (0,util.stringToBytes)(value);
  14700. value = decoder.decode(buffer);
  14701. needsEncodingFixup = false;
  14702. } catch {}
  14703. }
  14704. return value;
  14705. }
  14706. function fixupEncoding(value) {
  14707. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  14708. value = textdecode("utf-8", value);
  14709. if (needsEncodingFixup) {
  14710. value = textdecode("iso-8859-1", value);
  14711. }
  14712. }
  14713. return value;
  14714. }
  14715. function rfc2231getparam(contentDispositionStr) {
  14716. const matches = [];
  14717. let match;
  14718. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  14719. while ((match = iter.exec(contentDispositionStr)) !== null) {
  14720. let [, n, quot, part] = match;
  14721. n = parseInt(n, 10);
  14722. if (n in matches) {
  14723. if (n === 0) {
  14724. break;
  14725. }
  14726. continue;
  14727. }
  14728. matches[n] = [quot, part];
  14729. }
  14730. const parts = [];
  14731. for (let n = 0; n < matches.length; ++n) {
  14732. if (!(n in matches)) {
  14733. break;
  14734. }
  14735. let [quot, part] = matches[n];
  14736. part = rfc2616unquote(part);
  14737. if (quot) {
  14738. part = unescape(part);
  14739. if (n === 0) {
  14740. part = rfc5987decode(part);
  14741. }
  14742. }
  14743. parts.push(part);
  14744. }
  14745. return parts.join("");
  14746. }
  14747. function rfc2616unquote(value) {
  14748. if (value.startsWith('"')) {
  14749. const parts = value.slice(1).split('\\"');
  14750. for (let i = 0; i < parts.length; ++i) {
  14751. const quotindex = parts[i].indexOf('"');
  14752. if (quotindex !== -1) {
  14753. parts[i] = parts[i].slice(0, quotindex);
  14754. parts.length = i + 1;
  14755. }
  14756. parts[i] = parts[i].replaceAll(/\\(.)/g, "$1");
  14757. }
  14758. value = parts.join('"');
  14759. }
  14760. return value;
  14761. }
  14762. function rfc5987decode(extvalue) {
  14763. const encodingend = extvalue.indexOf("'");
  14764. if (encodingend === -1) {
  14765. return extvalue;
  14766. }
  14767. const encoding = extvalue.slice(0, encodingend);
  14768. const langvalue = extvalue.slice(encodingend + 1);
  14769. const value = langvalue.replace(/^[^']*'/, "");
  14770. return textdecode(encoding, value);
  14771. }
  14772. function rfc2047decode(value) {
  14773. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  14774. return value;
  14775. }
  14776. return value.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  14777. if (encoding === "q" || encoding === "Q") {
  14778. text = text.replaceAll("_", " ");
  14779. text = text.replaceAll(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  14780. return String.fromCharCode(parseInt(hex, 16));
  14781. });
  14782. return textdecode(charset, text);
  14783. }
  14784. try {
  14785. text = atob(text);
  14786. } catch {}
  14787. return textdecode(charset, text);
  14788. });
  14789. }
  14790. return "";
  14791. }
  14792. // EXTERNAL MODULE: ./src/display/display_utils.js
  14793. var display_utils = __webpack_require__(473);
  14794. ;// CONCATENATED MODULE: ./src/display/network_utils.js
  14795. function validateRangeRequestCapabilities({
  14796. getResponseHeader,
  14797. isHttp,
  14798. rangeChunkSize,
  14799. disableRange
  14800. }) {
  14801. const returnValues = {
  14802. allowRangeRequests: false,
  14803. suggestedLength: undefined
  14804. };
  14805. const length = parseInt(getResponseHeader("Content-Length"), 10);
  14806. if (!Number.isInteger(length)) {
  14807. return returnValues;
  14808. }
  14809. returnValues.suggestedLength = length;
  14810. if (length <= 2 * rangeChunkSize) {
  14811. return returnValues;
  14812. }
  14813. if (disableRange || !isHttp) {
  14814. return returnValues;
  14815. }
  14816. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  14817. return returnValues;
  14818. }
  14819. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  14820. if (contentEncoding !== "identity") {
  14821. return returnValues;
  14822. }
  14823. returnValues.allowRangeRequests = true;
  14824. return returnValues;
  14825. }
  14826. function extractFilenameFromHeader(getResponseHeader) {
  14827. const contentDisposition = getResponseHeader("Content-Disposition");
  14828. if (contentDisposition) {
  14829. let filename = getFilenameFromContentDispositionHeader(contentDisposition);
  14830. if (filename.includes("%")) {
  14831. try {
  14832. filename = decodeURIComponent(filename);
  14833. } catch {}
  14834. }
  14835. if ((0,display_utils.isPdfFile)(filename)) {
  14836. return filename;
  14837. }
  14838. }
  14839. return null;
  14840. }
  14841. function createResponseStatusError(status, url) {
  14842. if (status === 404 || status === 0 && url.startsWith("file:")) {
  14843. return new util.MissingPDFException('Missing PDF "' + url + '".');
  14844. }
  14845. return new util.UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
  14846. }
  14847. function validateResponseStatus(status) {
  14848. return status === 200 || status === 206;
  14849. }
  14850. /***/ }),
  14851. /***/ 498:
  14852. /***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {
  14853. __webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
  14854. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  14855. /* harmony export */ PDFNodeStream: () => (/* binding */ PDFNodeStream)
  14856. /* harmony export */ });
  14857. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  14858. /* harmony import */ var _network_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(253);
  14859. ;
  14860. let fs, http, https, url;
  14861. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.isNodeJS) {
  14862. fs = await import(/* webpackIgnore: true */ "fs");
  14863. http = await import(/* webpackIgnore: true */ "http");
  14864. https = await import(/* webpackIgnore: true */ "https");
  14865. url = await import(/* webpackIgnore: true */ "url");
  14866. }
  14867. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  14868. function parseUrl(sourceUrl) {
  14869. const parsedUrl = url.parse(sourceUrl);
  14870. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  14871. return parsedUrl;
  14872. }
  14873. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  14874. return url.parse(`file:///${sourceUrl}`);
  14875. }
  14876. if (!parsedUrl.host) {
  14877. parsedUrl.protocol = "file:";
  14878. }
  14879. return parsedUrl;
  14880. }
  14881. class PDFNodeStream {
  14882. constructor(source) {
  14883. this.source = source;
  14884. this.url = parseUrl(source.url);
  14885. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  14886. this.isFsUrl = this.url.protocol === "file:";
  14887. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  14888. this._fullRequestReader = null;
  14889. this._rangeRequestReaders = [];
  14890. }
  14891. get _progressiveDataLength() {
  14892. return this._fullRequestReader?._loaded ?? 0;
  14893. }
  14894. getFullReader() {
  14895. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  14896. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  14897. return this._fullRequestReader;
  14898. }
  14899. getRangeReader(start, end) {
  14900. if (end <= this._progressiveDataLength) {
  14901. return null;
  14902. }
  14903. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  14904. this._rangeRequestReaders.push(rangeReader);
  14905. return rangeReader;
  14906. }
  14907. cancelAllRequests(reason) {
  14908. this._fullRequestReader?.cancel(reason);
  14909. for (const reader of this._rangeRequestReaders.slice(0)) {
  14910. reader.cancel(reason);
  14911. }
  14912. }
  14913. }
  14914. class BaseFullReader {
  14915. constructor(stream) {
  14916. this._url = stream.url;
  14917. this._done = false;
  14918. this._storedError = null;
  14919. this.onProgress = null;
  14920. const source = stream.source;
  14921. this._contentLength = source.length;
  14922. this._loaded = 0;
  14923. this._filename = null;
  14924. this._disableRange = source.disableRange || false;
  14925. this._rangeChunkSize = source.rangeChunkSize;
  14926. if (!this._rangeChunkSize && !this._disableRange) {
  14927. this._disableRange = true;
  14928. }
  14929. this._isStreamingSupported = !source.disableStream;
  14930. this._isRangeSupported = !source.disableRange;
  14931. this._readableStream = null;
  14932. this._readCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  14933. this._headersCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  14934. }
  14935. get headersReady() {
  14936. return this._headersCapability.promise;
  14937. }
  14938. get filename() {
  14939. return this._filename;
  14940. }
  14941. get contentLength() {
  14942. return this._contentLength;
  14943. }
  14944. get isRangeSupported() {
  14945. return this._isRangeSupported;
  14946. }
  14947. get isStreamingSupported() {
  14948. return this._isStreamingSupported;
  14949. }
  14950. async read() {
  14951. await this._readCapability.promise;
  14952. if (this._done) {
  14953. return {
  14954. value: undefined,
  14955. done: true
  14956. };
  14957. }
  14958. if (this._storedError) {
  14959. throw this._storedError;
  14960. }
  14961. const chunk = this._readableStream.read();
  14962. if (chunk === null) {
  14963. this._readCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  14964. return this.read();
  14965. }
  14966. this._loaded += chunk.length;
  14967. this.onProgress?.({
  14968. loaded: this._loaded,
  14969. total: this._contentLength
  14970. });
  14971. const buffer = new Uint8Array(chunk).buffer;
  14972. return {
  14973. value: buffer,
  14974. done: false
  14975. };
  14976. }
  14977. cancel(reason) {
  14978. if (!this._readableStream) {
  14979. this._error(reason);
  14980. return;
  14981. }
  14982. this._readableStream.destroy(reason);
  14983. }
  14984. _error(reason) {
  14985. this._storedError = reason;
  14986. this._readCapability.resolve();
  14987. }
  14988. _setReadableStream(readableStream) {
  14989. this._readableStream = readableStream;
  14990. readableStream.on("readable", () => {
  14991. this._readCapability.resolve();
  14992. });
  14993. readableStream.on("end", () => {
  14994. readableStream.destroy();
  14995. this._done = true;
  14996. this._readCapability.resolve();
  14997. });
  14998. readableStream.on("error", reason => {
  14999. this._error(reason);
  15000. });
  15001. if (!this._isStreamingSupported && this._isRangeSupported) {
  15002. this._error(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException("streaming is disabled"));
  15003. }
  15004. if (this._storedError) {
  15005. this._readableStream.destroy(this._storedError);
  15006. }
  15007. }
  15008. }
  15009. class BaseRangeReader {
  15010. constructor(stream) {
  15011. this._url = stream.url;
  15012. this._done = false;
  15013. this._storedError = null;
  15014. this.onProgress = null;
  15015. this._loaded = 0;
  15016. this._readableStream = null;
  15017. this._readCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  15018. const source = stream.source;
  15019. this._isStreamingSupported = !source.disableStream;
  15020. }
  15021. get isStreamingSupported() {
  15022. return this._isStreamingSupported;
  15023. }
  15024. async read() {
  15025. await this._readCapability.promise;
  15026. if (this._done) {
  15027. return {
  15028. value: undefined,
  15029. done: true
  15030. };
  15031. }
  15032. if (this._storedError) {
  15033. throw this._storedError;
  15034. }
  15035. const chunk = this._readableStream.read();
  15036. if (chunk === null) {
  15037. this._readCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  15038. return this.read();
  15039. }
  15040. this._loaded += chunk.length;
  15041. this.onProgress?.({
  15042. loaded: this._loaded
  15043. });
  15044. const buffer = new Uint8Array(chunk).buffer;
  15045. return {
  15046. value: buffer,
  15047. done: false
  15048. };
  15049. }
  15050. cancel(reason) {
  15051. if (!this._readableStream) {
  15052. this._error(reason);
  15053. return;
  15054. }
  15055. this._readableStream.destroy(reason);
  15056. }
  15057. _error(reason) {
  15058. this._storedError = reason;
  15059. this._readCapability.resolve();
  15060. }
  15061. _setReadableStream(readableStream) {
  15062. this._readableStream = readableStream;
  15063. readableStream.on("readable", () => {
  15064. this._readCapability.resolve();
  15065. });
  15066. readableStream.on("end", () => {
  15067. readableStream.destroy();
  15068. this._done = true;
  15069. this._readCapability.resolve();
  15070. });
  15071. readableStream.on("error", reason => {
  15072. this._error(reason);
  15073. });
  15074. if (this._storedError) {
  15075. this._readableStream.destroy(this._storedError);
  15076. }
  15077. }
  15078. }
  15079. function createRequestOptions(parsedUrl, headers) {
  15080. return {
  15081. protocol: parsedUrl.protocol,
  15082. auth: parsedUrl.auth,
  15083. host: parsedUrl.hostname,
  15084. port: parsedUrl.port,
  15085. path: parsedUrl.path,
  15086. method: "GET",
  15087. headers
  15088. };
  15089. }
  15090. class PDFNodeStreamFullReader extends BaseFullReader {
  15091. constructor(stream) {
  15092. super(stream);
  15093. const handleResponse = response => {
  15094. if (response.statusCode === 404) {
  15095. const error = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException(`Missing PDF "${this._url}".`);
  15096. this._storedError = error;
  15097. this._headersCapability.reject(error);
  15098. return;
  15099. }
  15100. this._headersCapability.resolve();
  15101. this._setReadableStream(response);
  15102. const getResponseHeader = name => {
  15103. return this._readableStream.headers[name.toLowerCase()];
  15104. };
  15105. const {
  15106. allowRangeRequests,
  15107. suggestedLength
  15108. } = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.validateRangeRequestCapabilities)({
  15109. getResponseHeader,
  15110. isHttp: stream.isHttp,
  15111. rangeChunkSize: this._rangeChunkSize,
  15112. disableRange: this._disableRange
  15113. });
  15114. this._isRangeSupported = allowRangeRequests;
  15115. this._contentLength = suggestedLength || this._contentLength;
  15116. this._filename = (0,_network_utils_js__WEBPACK_IMPORTED_MODULE_1__.extractFilenameFromHeader)(getResponseHeader);
  15117. };
  15118. this._request = null;
  15119. if (this._url.protocol === "http:") {
  15120. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  15121. } else {
  15122. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  15123. }
  15124. this._request.on("error", reason => {
  15125. this._storedError = reason;
  15126. this._headersCapability.reject(reason);
  15127. });
  15128. this._request.end();
  15129. }
  15130. }
  15131. class PDFNodeStreamRangeReader extends BaseRangeReader {
  15132. constructor(stream, start, end) {
  15133. super(stream);
  15134. this._httpHeaders = {};
  15135. for (const property in stream.httpHeaders) {
  15136. const value = stream.httpHeaders[property];
  15137. if (value === undefined) {
  15138. continue;
  15139. }
  15140. this._httpHeaders[property] = value;
  15141. }
  15142. this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
  15143. const handleResponse = response => {
  15144. if (response.statusCode === 404) {
  15145. const error = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException(`Missing PDF "${this._url}".`);
  15146. this._storedError = error;
  15147. return;
  15148. }
  15149. this._setReadableStream(response);
  15150. };
  15151. this._request = null;
  15152. if (this._url.protocol === "http:") {
  15153. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  15154. } else {
  15155. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  15156. }
  15157. this._request.on("error", reason => {
  15158. this._storedError = reason;
  15159. });
  15160. this._request.end();
  15161. }
  15162. }
  15163. class PDFNodeStreamFsFullReader extends BaseFullReader {
  15164. constructor(stream) {
  15165. super(stream);
  15166. let path = decodeURIComponent(this._url.path);
  15167. if (fileUriRegex.test(this._url.href)) {
  15168. path = path.replace(/^\//, "");
  15169. }
  15170. fs.lstat(path, (error, stat) => {
  15171. if (error) {
  15172. if (error.code === "ENOENT") {
  15173. error = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException(`Missing PDF "${path}".`);
  15174. }
  15175. this._storedError = error;
  15176. this._headersCapability.reject(error);
  15177. return;
  15178. }
  15179. this._contentLength = stat.size;
  15180. this._setReadableStream(fs.createReadStream(path));
  15181. this._headersCapability.resolve();
  15182. });
  15183. }
  15184. }
  15185. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  15186. constructor(stream, start, end) {
  15187. super(stream);
  15188. let path = decodeURIComponent(this._url.path);
  15189. if (fileUriRegex.test(this._url.href)) {
  15190. path = path.replace(/^\//, "");
  15191. }
  15192. this._setReadableStream(fs.createReadStream(path, {
  15193. start,
  15194. end: end - 1
  15195. }));
  15196. }
  15197. }
  15198. __webpack_async_result__();
  15199. } catch(e) { __webpack_async_result__(e); } }, 1);
  15200. /***/ }),
  15201. /***/ 738:
  15202. /***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {
  15203. __webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
  15204. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  15205. /* harmony export */ NodeCMapReaderFactory: () => (/* binding */ NodeCMapReaderFactory),
  15206. /* harmony export */ NodeCanvasFactory: () => (/* binding */ NodeCanvasFactory),
  15207. /* harmony export */ NodeFilterFactory: () => (/* binding */ NodeFilterFactory),
  15208. /* harmony export */ NodeStandardFontDataFactory: () => (/* binding */ NodeStandardFontDataFactory)
  15209. /* harmony export */ });
  15210. /* harmony import */ var _base_factory_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(822);
  15211. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(266);
  15212. ;
  15213. let fs, canvas, path2d_polyfill;
  15214. if (_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.isNodeJS) {
  15215. fs = await import(/* webpackIgnore: true */ "fs");
  15216. try {
  15217. canvas = await import(/* webpackIgnore: true */ "canvas");
  15218. } catch {}
  15219. try {
  15220. path2d_polyfill = await import(/* webpackIgnore: true */ "path2d-polyfill");
  15221. } catch {}
  15222. }
  15223. ;
  15224. const fetchData = function (url) {
  15225. return new Promise((resolve, reject) => {
  15226. fs.readFile(url, (error, data) => {
  15227. if (error || !data) {
  15228. reject(new Error(error));
  15229. return;
  15230. }
  15231. resolve(new Uint8Array(data));
  15232. });
  15233. });
  15234. };
  15235. class NodeFilterFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseFilterFactory {}
  15236. class NodeCanvasFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseCanvasFactory {
  15237. _createCanvas(width, height) {
  15238. return canvas.createCanvas(width, height);
  15239. }
  15240. }
  15241. class NodeCMapReaderFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseCMapReaderFactory {
  15242. _fetchData(url, compressionType) {
  15243. return fetchData(url).then(data => {
  15244. return {
  15245. cMapData: data,
  15246. compressionType
  15247. };
  15248. });
  15249. }
  15250. }
  15251. class NodeStandardFontDataFactory extends _base_factory_js__WEBPACK_IMPORTED_MODULE_0__.BaseStandardFontDataFactory {
  15252. _fetchData(url) {
  15253. return fetchData(url);
  15254. }
  15255. }
  15256. __webpack_async_result__();
  15257. } catch(e) { __webpack_async_result__(e); } }, 1);
  15258. /***/ }),
  15259. /***/ 890:
  15260. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  15261. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  15262. /* harmony export */ OptionalContentConfig: () => (/* binding */ OptionalContentConfig)
  15263. /* harmony export */ });
  15264. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  15265. /* harmony import */ var _shared_murmurhash3_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(825);
  15266. const INTERNAL = Symbol("INTERNAL");
  15267. class OptionalContentGroup {
  15268. #visible = true;
  15269. constructor(name, intent) {
  15270. this.name = name;
  15271. this.intent = intent;
  15272. }
  15273. get visible() {
  15274. return this.#visible;
  15275. }
  15276. _setVisible(internal, visible) {
  15277. if (internal !== INTERNAL) {
  15278. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)("Internal method `_setVisible` called.");
  15279. }
  15280. this.#visible = visible;
  15281. }
  15282. }
  15283. class OptionalContentConfig {
  15284. #cachedGetHash = null;
  15285. #groups = new Map();
  15286. #initialHash = null;
  15287. #order = null;
  15288. constructor(data) {
  15289. this.name = null;
  15290. this.creator = null;
  15291. if (data === null) {
  15292. return;
  15293. }
  15294. this.name = data.name;
  15295. this.creator = data.creator;
  15296. this.#order = data.order;
  15297. for (const group of data.groups) {
  15298. this.#groups.set(group.id, new OptionalContentGroup(group.name, group.intent));
  15299. }
  15300. if (data.baseState === "OFF") {
  15301. for (const group of this.#groups.values()) {
  15302. group._setVisible(INTERNAL, false);
  15303. }
  15304. }
  15305. for (const on of data.on) {
  15306. this.#groups.get(on)._setVisible(INTERNAL, true);
  15307. }
  15308. for (const off of data.off) {
  15309. this.#groups.get(off)._setVisible(INTERNAL, false);
  15310. }
  15311. this.#initialHash = this.getHash();
  15312. }
  15313. #evaluateVisibilityExpression(array) {
  15314. const length = array.length;
  15315. if (length < 2) {
  15316. return true;
  15317. }
  15318. const operator = array[0];
  15319. for (let i = 1; i < length; i++) {
  15320. const element = array[i];
  15321. let state;
  15322. if (Array.isArray(element)) {
  15323. state = this.#evaluateVisibilityExpression(element);
  15324. } else if (this.#groups.has(element)) {
  15325. state = this.#groups.get(element).visible;
  15326. } else {
  15327. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${element}`);
  15328. return true;
  15329. }
  15330. switch (operator) {
  15331. case "And":
  15332. if (!state) {
  15333. return false;
  15334. }
  15335. break;
  15336. case "Or":
  15337. if (state) {
  15338. return true;
  15339. }
  15340. break;
  15341. case "Not":
  15342. return !state;
  15343. default:
  15344. return true;
  15345. }
  15346. }
  15347. return operator === "And";
  15348. }
  15349. isVisible(group) {
  15350. if (this.#groups.size === 0) {
  15351. return true;
  15352. }
  15353. if (!group) {
  15354. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)("Optional content group not defined.");
  15355. return true;
  15356. }
  15357. if (group.type === "OCG") {
  15358. if (!this.#groups.has(group.id)) {
  15359. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${group.id}`);
  15360. return true;
  15361. }
  15362. return this.#groups.get(group.id).visible;
  15363. } else if (group.type === "OCMD") {
  15364. if (group.expression) {
  15365. return this.#evaluateVisibilityExpression(group.expression);
  15366. }
  15367. if (!group.policy || group.policy === "AnyOn") {
  15368. for (const id of group.ids) {
  15369. if (!this.#groups.has(id)) {
  15370. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${id}`);
  15371. return true;
  15372. }
  15373. if (this.#groups.get(id).visible) {
  15374. return true;
  15375. }
  15376. }
  15377. return false;
  15378. } else if (group.policy === "AllOn") {
  15379. for (const id of group.ids) {
  15380. if (!this.#groups.has(id)) {
  15381. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${id}`);
  15382. return true;
  15383. }
  15384. if (!this.#groups.get(id).visible) {
  15385. return false;
  15386. }
  15387. }
  15388. return true;
  15389. } else if (group.policy === "AnyOff") {
  15390. for (const id of group.ids) {
  15391. if (!this.#groups.has(id)) {
  15392. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${id}`);
  15393. return true;
  15394. }
  15395. if (!this.#groups.get(id).visible) {
  15396. return true;
  15397. }
  15398. }
  15399. return false;
  15400. } else if (group.policy === "AllOff") {
  15401. for (const id of group.ids) {
  15402. if (!this.#groups.has(id)) {
  15403. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${id}`);
  15404. return true;
  15405. }
  15406. if (this.#groups.get(id).visible) {
  15407. return false;
  15408. }
  15409. }
  15410. return true;
  15411. }
  15412. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Unknown optional content policy ${group.policy}.`);
  15413. return true;
  15414. }
  15415. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Unknown group type ${group.type}.`);
  15416. return true;
  15417. }
  15418. setVisibility(id, visible = true) {
  15419. if (!this.#groups.has(id)) {
  15420. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.warn)(`Optional content group not found: ${id}`);
  15421. return;
  15422. }
  15423. this.#groups.get(id)._setVisible(INTERNAL, !!visible);
  15424. this.#cachedGetHash = null;
  15425. }
  15426. get hasInitialVisibility() {
  15427. return this.#initialHash === null || this.getHash() === this.#initialHash;
  15428. }
  15429. getOrder() {
  15430. if (!this.#groups.size) {
  15431. return null;
  15432. }
  15433. if (this.#order) {
  15434. return this.#order.slice();
  15435. }
  15436. return [...this.#groups.keys()];
  15437. }
  15438. getGroups() {
  15439. return this.#groups.size > 0 ? (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.objectFromMap)(this.#groups) : null;
  15440. }
  15441. getGroup(id) {
  15442. return this.#groups.get(id) || null;
  15443. }
  15444. getHash() {
  15445. if (this.#cachedGetHash !== null) {
  15446. return this.#cachedGetHash;
  15447. }
  15448. const hash = new _shared_murmurhash3_js__WEBPACK_IMPORTED_MODULE_1__.MurmurHash3_64();
  15449. for (const [id, group] of this.#groups) {
  15450. hash.update(`${id}:${group.visible}`);
  15451. }
  15452. return this.#cachedGetHash = hash.hexdigest();
  15453. }
  15454. }
  15455. /***/ }),
  15456. /***/ 739:
  15457. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  15458. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  15459. /* harmony export */ renderTextLayer: () => (/* binding */ renderTextLayer),
  15460. /* harmony export */ updateTextLayer: () => (/* binding */ updateTextLayer)
  15461. /* harmony export */ });
  15462. /* unused harmony export TextLayerRenderTask */
  15463. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  15464. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(473);
  15465. const MAX_TEXT_DIVS_TO_RENDER = 100000;
  15466. const DEFAULT_FONT_SIZE = 30;
  15467. const DEFAULT_FONT_ASCENT = 0.8;
  15468. const ascentCache = new Map();
  15469. function getCtx(size, isOffscreenCanvasSupported) {
  15470. let ctx;
  15471. if (isOffscreenCanvasSupported && _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FeatureTest.isOffscreenCanvasSupported) {
  15472. ctx = new OffscreenCanvas(size, size).getContext("2d", {
  15473. alpha: false
  15474. });
  15475. } else {
  15476. const canvas = document.createElement("canvas");
  15477. canvas.width = canvas.height = size;
  15478. ctx = canvas.getContext("2d", {
  15479. alpha: false
  15480. });
  15481. }
  15482. return ctx;
  15483. }
  15484. function getAscent(fontFamily, isOffscreenCanvasSupported) {
  15485. const cachedAscent = ascentCache.get(fontFamily);
  15486. if (cachedAscent) {
  15487. return cachedAscent;
  15488. }
  15489. const ctx = getCtx(DEFAULT_FONT_SIZE, isOffscreenCanvasSupported);
  15490. ctx.font = `${DEFAULT_FONT_SIZE}px ${fontFamily}`;
  15491. const metrics = ctx.measureText("");
  15492. let ascent = metrics.fontBoundingBoxAscent;
  15493. let descent = Math.abs(metrics.fontBoundingBoxDescent);
  15494. if (ascent) {
  15495. const ratio = ascent / (ascent + descent);
  15496. ascentCache.set(fontFamily, ratio);
  15497. ctx.canvas.width = ctx.canvas.height = 0;
  15498. return ratio;
  15499. }
  15500. ctx.strokeStyle = "red";
  15501. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  15502. ctx.strokeText("g", 0, 0);
  15503. let pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  15504. descent = 0;
  15505. for (let i = pixels.length - 1 - 3; i >= 0; i -= 4) {
  15506. if (pixels[i] > 0) {
  15507. descent = Math.ceil(i / 4 / DEFAULT_FONT_SIZE);
  15508. break;
  15509. }
  15510. }
  15511. ctx.clearRect(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE);
  15512. ctx.strokeText("A", 0, DEFAULT_FONT_SIZE);
  15513. pixels = ctx.getImageData(0, 0, DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE).data;
  15514. ascent = 0;
  15515. for (let i = 0, ii = pixels.length; i < ii; i += 4) {
  15516. if (pixels[i] > 0) {
  15517. ascent = DEFAULT_FONT_SIZE - Math.floor(i / 4 / DEFAULT_FONT_SIZE);
  15518. break;
  15519. }
  15520. }
  15521. ctx.canvas.width = ctx.canvas.height = 0;
  15522. if (ascent) {
  15523. const ratio = ascent / (ascent + descent);
  15524. ascentCache.set(fontFamily, ratio);
  15525. return ratio;
  15526. }
  15527. ascentCache.set(fontFamily, DEFAULT_FONT_ASCENT);
  15528. return DEFAULT_FONT_ASCENT;
  15529. }
  15530. function appendText(task, geom, styles) {
  15531. const textDiv = document.createElement("span");
  15532. const textDivProperties = {
  15533. angle: 0,
  15534. canvasWidth: 0,
  15535. hasText: geom.str !== "",
  15536. hasEOL: geom.hasEOL,
  15537. fontSize: 0
  15538. };
  15539. task._textDivs.push(textDiv);
  15540. const tx = _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.Util.transform(task._transform, geom.transform);
  15541. let angle = Math.atan2(tx[1], tx[0]);
  15542. const style = styles[geom.fontName];
  15543. if (style.vertical) {
  15544. angle += Math.PI / 2;
  15545. }
  15546. const fontFamily = task._fontInspectorEnabled && style.fontSubstitution || style.fontFamily;
  15547. const fontHeight = Math.hypot(tx[2], tx[3]);
  15548. const fontAscent = fontHeight * getAscent(fontFamily, task._isOffscreenCanvasSupported);
  15549. let left, top;
  15550. if (angle === 0) {
  15551. left = tx[4];
  15552. top = tx[5] - fontAscent;
  15553. } else {
  15554. left = tx[4] + fontAscent * Math.sin(angle);
  15555. top = tx[5] - fontAscent * Math.cos(angle);
  15556. }
  15557. const scaleFactorStr = "calc(var(--scale-factor)*";
  15558. const divStyle = textDiv.style;
  15559. if (task._container === task._rootContainer) {
  15560. divStyle.left = `${(100 * left / task._pageWidth).toFixed(2)}%`;
  15561. divStyle.top = `${(100 * top / task._pageHeight).toFixed(2)}%`;
  15562. } else {
  15563. divStyle.left = `${scaleFactorStr}${left.toFixed(2)}px)`;
  15564. divStyle.top = `${scaleFactorStr}${top.toFixed(2)}px)`;
  15565. }
  15566. divStyle.fontSize = `${scaleFactorStr}${fontHeight.toFixed(2)}px)`;
  15567. divStyle.fontFamily = fontFamily;
  15568. textDivProperties.fontSize = fontHeight;
  15569. textDiv.setAttribute("role", "presentation");
  15570. textDiv.textContent = geom.str;
  15571. textDiv.dir = geom.dir;
  15572. if (task._fontInspectorEnabled) {
  15573. textDiv.dataset.fontName = style.fontSubstitutionLoadedName || geom.fontName;
  15574. }
  15575. if (angle !== 0) {
  15576. textDivProperties.angle = angle * (180 / Math.PI);
  15577. }
  15578. let shouldScaleText = false;
  15579. if (geom.str.length > 1) {
  15580. shouldScaleText = true;
  15581. } else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
  15582. const absScaleX = Math.abs(geom.transform[0]),
  15583. absScaleY = Math.abs(geom.transform[3]);
  15584. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  15585. shouldScaleText = true;
  15586. }
  15587. }
  15588. if (shouldScaleText) {
  15589. textDivProperties.canvasWidth = style.vertical ? geom.height : geom.width;
  15590. }
  15591. task._textDivProperties.set(textDiv, textDivProperties);
  15592. if (task._isReadableStream) {
  15593. task._layoutText(textDiv);
  15594. }
  15595. }
  15596. function layout(params) {
  15597. const {
  15598. div,
  15599. scale,
  15600. properties,
  15601. ctx,
  15602. prevFontSize,
  15603. prevFontFamily
  15604. } = params;
  15605. const {
  15606. style
  15607. } = div;
  15608. let transform = "";
  15609. if (properties.canvasWidth !== 0 && properties.hasText) {
  15610. const {
  15611. fontFamily
  15612. } = style;
  15613. const {
  15614. canvasWidth,
  15615. fontSize
  15616. } = properties;
  15617. if (prevFontSize !== fontSize || prevFontFamily !== fontFamily) {
  15618. ctx.font = `${fontSize * scale}px ${fontFamily}`;
  15619. params.prevFontSize = fontSize;
  15620. params.prevFontFamily = fontFamily;
  15621. }
  15622. const {
  15623. width
  15624. } = ctx.measureText(div.textContent);
  15625. if (width > 0) {
  15626. transform = `scaleX(${canvasWidth * scale / width})`;
  15627. }
  15628. }
  15629. if (properties.angle !== 0) {
  15630. transform = `rotate(${properties.angle}deg) ${transform}`;
  15631. }
  15632. if (transform.length > 0) {
  15633. style.transform = transform;
  15634. }
  15635. }
  15636. function render(task) {
  15637. if (task._canceled) {
  15638. return;
  15639. }
  15640. const textDivs = task._textDivs;
  15641. const capability = task._capability;
  15642. const textDivsLength = textDivs.length;
  15643. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  15644. capability.resolve();
  15645. return;
  15646. }
  15647. if (!task._isReadableStream) {
  15648. for (const textDiv of textDivs) {
  15649. task._layoutText(textDiv);
  15650. }
  15651. }
  15652. capability.resolve();
  15653. }
  15654. class TextLayerRenderTask {
  15655. constructor({
  15656. textContentSource,
  15657. container,
  15658. viewport,
  15659. textDivs,
  15660. textDivProperties,
  15661. textContentItemsStr,
  15662. isOffscreenCanvasSupported
  15663. }) {
  15664. this._textContentSource = textContentSource;
  15665. this._isReadableStream = textContentSource instanceof ReadableStream;
  15666. this._container = this._rootContainer = container;
  15667. this._textDivs = textDivs || [];
  15668. this._textContentItemsStr = textContentItemsStr || [];
  15669. this._isOffscreenCanvasSupported = isOffscreenCanvasSupported;
  15670. this._fontInspectorEnabled = !!globalThis.FontInspector?.enabled;
  15671. this._reader = null;
  15672. this._textDivProperties = textDivProperties || new WeakMap();
  15673. this._canceled = false;
  15674. this._capability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  15675. this._layoutTextParams = {
  15676. prevFontSize: null,
  15677. prevFontFamily: null,
  15678. div: null,
  15679. scale: viewport.scale * (globalThis.devicePixelRatio || 1),
  15680. properties: null,
  15681. ctx: getCtx(0, isOffscreenCanvasSupported)
  15682. };
  15683. const {
  15684. pageWidth,
  15685. pageHeight,
  15686. pageX,
  15687. pageY
  15688. } = viewport.rawDims;
  15689. this._transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];
  15690. this._pageWidth = pageWidth;
  15691. this._pageHeight = pageHeight;
  15692. (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.setLayerDimensions)(container, viewport);
  15693. this._capability.promise.finally(() => {
  15694. this._layoutTextParams = null;
  15695. }).catch(() => {});
  15696. }
  15697. get promise() {
  15698. return this._capability.promise;
  15699. }
  15700. cancel() {
  15701. this._canceled = true;
  15702. if (this._reader) {
  15703. this._reader.cancel(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException("TextLayer task cancelled.")).catch(() => {});
  15704. this._reader = null;
  15705. }
  15706. this._capability.reject(new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException("TextLayer task cancelled."));
  15707. }
  15708. _processItems(items, styleCache) {
  15709. for (const item of items) {
  15710. if (item.str === undefined) {
  15711. if (item.type === "beginMarkedContentProps" || item.type === "beginMarkedContent") {
  15712. const parent = this._container;
  15713. this._container = document.createElement("span");
  15714. this._container.classList.add("markedContent");
  15715. if (item.id !== null) {
  15716. this._container.setAttribute("id", `${item.id}`);
  15717. }
  15718. parent.append(this._container);
  15719. } else if (item.type === "endMarkedContent") {
  15720. this._container = this._container.parentNode;
  15721. }
  15722. continue;
  15723. }
  15724. this._textContentItemsStr.push(item.str);
  15725. appendText(this, item, styleCache);
  15726. }
  15727. }
  15728. _layoutText(textDiv) {
  15729. const textDivProperties = this._layoutTextParams.properties = this._textDivProperties.get(textDiv);
  15730. this._layoutTextParams.div = textDiv;
  15731. layout(this._layoutTextParams);
  15732. if (textDivProperties.hasText) {
  15733. this._container.append(textDiv);
  15734. }
  15735. if (textDivProperties.hasEOL) {
  15736. const br = document.createElement("br");
  15737. br.setAttribute("role", "presentation");
  15738. this._container.append(br);
  15739. }
  15740. }
  15741. _render() {
  15742. const capability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  15743. let styleCache = Object.create(null);
  15744. if (this._isReadableStream) {
  15745. const pump = () => {
  15746. this._reader.read().then(({
  15747. value,
  15748. done
  15749. }) => {
  15750. if (done) {
  15751. capability.resolve();
  15752. return;
  15753. }
  15754. Object.assign(styleCache, value.styles);
  15755. this._processItems(value.items, styleCache);
  15756. pump();
  15757. }, capability.reject);
  15758. };
  15759. this._reader = this._textContentSource.getReader();
  15760. pump();
  15761. } else if (this._textContentSource) {
  15762. const {
  15763. items,
  15764. styles
  15765. } = this._textContentSource;
  15766. this._processItems(items, styles);
  15767. capability.resolve();
  15768. } else {
  15769. throw new Error('No "textContentSource" parameter specified.');
  15770. }
  15771. capability.promise.then(() => {
  15772. styleCache = null;
  15773. render(this);
  15774. }, this._capability.reject);
  15775. }
  15776. }
  15777. function renderTextLayer(params) {
  15778. const task = new TextLayerRenderTask(params);
  15779. task._render();
  15780. return task;
  15781. }
  15782. function updateTextLayer({
  15783. container,
  15784. viewport,
  15785. textDivs,
  15786. textDivProperties,
  15787. isOffscreenCanvasSupported,
  15788. mustRotate = true,
  15789. mustRescale = true
  15790. }) {
  15791. if (mustRotate) {
  15792. (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.setLayerDimensions)(container, {
  15793. rotation: viewport.rotation
  15794. });
  15795. }
  15796. if (mustRescale) {
  15797. const ctx = getCtx(0, isOffscreenCanvasSupported);
  15798. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  15799. const params = {
  15800. prevFontSize: null,
  15801. prevFontFamily: null,
  15802. div: null,
  15803. scale,
  15804. properties: null,
  15805. ctx
  15806. };
  15807. for (const div of textDivs) {
  15808. params.properties = textDivProperties.get(div);
  15809. params.div = div;
  15810. layout(params);
  15811. }
  15812. }
  15813. }
  15814. /***/ }),
  15815. /***/ 92:
  15816. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  15817. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  15818. /* harmony export */ PDFDataTransportStream: () => (/* binding */ PDFDataTransportStream)
  15819. /* harmony export */ });
  15820. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  15821. /* harmony import */ var _display_utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(473);
  15822. class PDFDataTransportStream {
  15823. constructor({
  15824. length,
  15825. initialData,
  15826. progressiveDone = false,
  15827. contentDispositionFilename = null,
  15828. disableRange = false,
  15829. disableStream = false
  15830. }, pdfDataRangeTransport) {
  15831. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  15832. this._queuedChunks = [];
  15833. this._progressiveDone = progressiveDone;
  15834. this._contentDispositionFilename = contentDispositionFilename;
  15835. if (initialData?.length > 0) {
  15836. const buffer = initialData instanceof Uint8Array && initialData.byteLength === initialData.buffer.byteLength ? initialData.buffer : new Uint8Array(initialData).buffer;
  15837. this._queuedChunks.push(buffer);
  15838. }
  15839. this._pdfDataRangeTransport = pdfDataRangeTransport;
  15840. this._isStreamingSupported = !disableStream;
  15841. this._isRangeSupported = !disableRange;
  15842. this._contentLength = length;
  15843. this._fullRequestReader = null;
  15844. this._rangeReaders = [];
  15845. this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  15846. this._onReceiveData({
  15847. begin,
  15848. chunk
  15849. });
  15850. });
  15851. this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
  15852. this._onProgress({
  15853. loaded,
  15854. total
  15855. });
  15856. });
  15857. this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  15858. this._onReceiveData({
  15859. chunk
  15860. });
  15861. });
  15862. this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
  15863. this._onProgressiveDone();
  15864. });
  15865. this._pdfDataRangeTransport.transportReady();
  15866. }
  15867. _onReceiveData({
  15868. begin,
  15869. chunk
  15870. }) {
  15871. const buffer = chunk instanceof Uint8Array && chunk.byteLength === chunk.buffer.byteLength ? chunk.buffer : new Uint8Array(chunk).buffer;
  15872. if (begin === undefined) {
  15873. if (this._fullRequestReader) {
  15874. this._fullRequestReader._enqueue(buffer);
  15875. } else {
  15876. this._queuedChunks.push(buffer);
  15877. }
  15878. } else {
  15879. const found = this._rangeReaders.some(function (rangeReader) {
  15880. if (rangeReader._begin !== begin) {
  15881. return false;
  15882. }
  15883. rangeReader._enqueue(buffer);
  15884. return true;
  15885. });
  15886. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  15887. }
  15888. }
  15889. get _progressiveDataLength() {
  15890. return this._fullRequestReader?._loaded ?? 0;
  15891. }
  15892. _onProgress(evt) {
  15893. if (evt.total === undefined) {
  15894. this._rangeReaders[0]?.onProgress?.({
  15895. loaded: evt.loaded
  15896. });
  15897. } else {
  15898. this._fullRequestReader?.onProgress?.({
  15899. loaded: evt.loaded,
  15900. total: evt.total
  15901. });
  15902. }
  15903. }
  15904. _onProgressiveDone() {
  15905. this._fullRequestReader?.progressiveDone();
  15906. this._progressiveDone = true;
  15907. }
  15908. _removeRangeReader(reader) {
  15909. const i = this._rangeReaders.indexOf(reader);
  15910. if (i >= 0) {
  15911. this._rangeReaders.splice(i, 1);
  15912. }
  15913. }
  15914. getFullReader() {
  15915. (0,_shared_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  15916. const queuedChunks = this._queuedChunks;
  15917. this._queuedChunks = null;
  15918. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone, this._contentDispositionFilename);
  15919. }
  15920. getRangeReader(begin, end) {
  15921. if (end <= this._progressiveDataLength) {
  15922. return null;
  15923. }
  15924. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  15925. this._pdfDataRangeTransport.requestDataRange(begin, end);
  15926. this._rangeReaders.push(reader);
  15927. return reader;
  15928. }
  15929. cancelAllRequests(reason) {
  15930. this._fullRequestReader?.cancel(reason);
  15931. for (const reader of this._rangeReaders.slice(0)) {
  15932. reader.cancel(reason);
  15933. }
  15934. this._pdfDataRangeTransport.abort();
  15935. }
  15936. }
  15937. class PDFDataTransportStreamReader {
  15938. constructor(stream, queuedChunks, progressiveDone = false, contentDispositionFilename = null) {
  15939. this._stream = stream;
  15940. this._done = progressiveDone || false;
  15941. this._filename = (0,_display_utils_js__WEBPACK_IMPORTED_MODULE_1__.isPdfFile)(contentDispositionFilename) ? contentDispositionFilename : null;
  15942. this._queuedChunks = queuedChunks || [];
  15943. this._loaded = 0;
  15944. for (const chunk of this._queuedChunks) {
  15945. this._loaded += chunk.byteLength;
  15946. }
  15947. this._requests = [];
  15948. this._headersReady = Promise.resolve();
  15949. stream._fullRequestReader = this;
  15950. this.onProgress = null;
  15951. }
  15952. _enqueue(chunk) {
  15953. if (this._done) {
  15954. return;
  15955. }
  15956. if (this._requests.length > 0) {
  15957. const requestCapability = this._requests.shift();
  15958. requestCapability.resolve({
  15959. value: chunk,
  15960. done: false
  15961. });
  15962. } else {
  15963. this._queuedChunks.push(chunk);
  15964. }
  15965. this._loaded += chunk.byteLength;
  15966. }
  15967. get headersReady() {
  15968. return this._headersReady;
  15969. }
  15970. get filename() {
  15971. return this._filename;
  15972. }
  15973. get isRangeSupported() {
  15974. return this._stream._isRangeSupported;
  15975. }
  15976. get isStreamingSupported() {
  15977. return this._stream._isStreamingSupported;
  15978. }
  15979. get contentLength() {
  15980. return this._stream._contentLength;
  15981. }
  15982. async read() {
  15983. if (this._queuedChunks.length > 0) {
  15984. const chunk = this._queuedChunks.shift();
  15985. return {
  15986. value: chunk,
  15987. done: false
  15988. };
  15989. }
  15990. if (this._done) {
  15991. return {
  15992. value: undefined,
  15993. done: true
  15994. };
  15995. }
  15996. const requestCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  15997. this._requests.push(requestCapability);
  15998. return requestCapability.promise;
  15999. }
  16000. cancel(reason) {
  16001. this._done = true;
  16002. for (const requestCapability of this._requests) {
  16003. requestCapability.resolve({
  16004. value: undefined,
  16005. done: true
  16006. });
  16007. }
  16008. this._requests.length = 0;
  16009. }
  16010. progressiveDone() {
  16011. if (this._done) {
  16012. return;
  16013. }
  16014. this._done = true;
  16015. }
  16016. }
  16017. class PDFDataTransportStreamRangeReader {
  16018. constructor(stream, begin, end) {
  16019. this._stream = stream;
  16020. this._begin = begin;
  16021. this._end = end;
  16022. this._queuedChunk = null;
  16023. this._requests = [];
  16024. this._done = false;
  16025. this.onProgress = null;
  16026. }
  16027. _enqueue(chunk) {
  16028. if (this._done) {
  16029. return;
  16030. }
  16031. if (this._requests.length === 0) {
  16032. this._queuedChunk = chunk;
  16033. } else {
  16034. const requestsCapability = this._requests.shift();
  16035. requestsCapability.resolve({
  16036. value: chunk,
  16037. done: false
  16038. });
  16039. for (const requestCapability of this._requests) {
  16040. requestCapability.resolve({
  16041. value: undefined,
  16042. done: true
  16043. });
  16044. }
  16045. this._requests.length = 0;
  16046. }
  16047. this._done = true;
  16048. this._stream._removeRangeReader(this);
  16049. }
  16050. get isStreamingSupported() {
  16051. return false;
  16052. }
  16053. async read() {
  16054. if (this._queuedChunk) {
  16055. const chunk = this._queuedChunk;
  16056. this._queuedChunk = null;
  16057. return {
  16058. value: chunk,
  16059. done: false
  16060. };
  16061. }
  16062. if (this._done) {
  16063. return {
  16064. value: undefined,
  16065. done: true
  16066. };
  16067. }
  16068. const requestCapability = new _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  16069. this._requests.push(requestCapability);
  16070. return requestCapability.promise;
  16071. }
  16072. cancel(reason) {
  16073. this._done = true;
  16074. for (const requestCapability of this._requests) {
  16075. requestCapability.resolve({
  16076. value: undefined,
  16077. done: true
  16078. });
  16079. }
  16080. this._requests.length = 0;
  16081. this._stream._removeRangeReader(this);
  16082. }
  16083. }
  16084. /***/ }),
  16085. /***/ 368:
  16086. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  16087. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  16088. /* harmony export */ GlobalWorkerOptions: () => (/* binding */ GlobalWorkerOptions)
  16089. /* harmony export */ });
  16090. const GlobalWorkerOptions = Object.create(null);
  16091. GlobalWorkerOptions.workerPort = null;
  16092. GlobalWorkerOptions.workerSrc = "";
  16093. /***/ }),
  16094. /***/ 160:
  16095. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  16096. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  16097. /* harmony export */ XfaLayer: () => (/* binding */ XfaLayer)
  16098. /* harmony export */ });
  16099. /* harmony import */ var _xfa_text_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(521);
  16100. class XfaLayer {
  16101. static setupStorage(html, id, element, storage, intent) {
  16102. const storedData = storage.getValue(id, {
  16103. value: null
  16104. });
  16105. switch (element.name) {
  16106. case "textarea":
  16107. if (storedData.value !== null) {
  16108. html.textContent = storedData.value;
  16109. }
  16110. if (intent === "print") {
  16111. break;
  16112. }
  16113. html.addEventListener("input", event => {
  16114. storage.setValue(id, {
  16115. value: event.target.value
  16116. });
  16117. });
  16118. break;
  16119. case "input":
  16120. if (element.attributes.type === "radio" || element.attributes.type === "checkbox") {
  16121. if (storedData.value === element.attributes.xfaOn) {
  16122. html.setAttribute("checked", true);
  16123. } else if (storedData.value === element.attributes.xfaOff) {
  16124. html.removeAttribute("checked");
  16125. }
  16126. if (intent === "print") {
  16127. break;
  16128. }
  16129. html.addEventListener("change", event => {
  16130. storage.setValue(id, {
  16131. value: event.target.checked ? event.target.getAttribute("xfaOn") : event.target.getAttribute("xfaOff")
  16132. });
  16133. });
  16134. } else {
  16135. if (storedData.value !== null) {
  16136. html.setAttribute("value", storedData.value);
  16137. }
  16138. if (intent === "print") {
  16139. break;
  16140. }
  16141. html.addEventListener("input", event => {
  16142. storage.setValue(id, {
  16143. value: event.target.value
  16144. });
  16145. });
  16146. }
  16147. break;
  16148. case "select":
  16149. if (storedData.value !== null) {
  16150. html.setAttribute("value", storedData.value);
  16151. for (const option of element.children) {
  16152. if (option.attributes.value === storedData.value) {
  16153. option.attributes.selected = true;
  16154. } else if (option.attributes.hasOwnProperty("selected")) {
  16155. delete option.attributes.selected;
  16156. }
  16157. }
  16158. }
  16159. html.addEventListener("input", event => {
  16160. const options = event.target.options;
  16161. const value = options.selectedIndex === -1 ? "" : options[options.selectedIndex].value;
  16162. storage.setValue(id, {
  16163. value
  16164. });
  16165. });
  16166. break;
  16167. }
  16168. }
  16169. static setAttributes({
  16170. html,
  16171. element,
  16172. storage = null,
  16173. intent,
  16174. linkService
  16175. }) {
  16176. const {
  16177. attributes
  16178. } = element;
  16179. const isHTMLAnchorElement = html instanceof HTMLAnchorElement;
  16180. if (attributes.type === "radio") {
  16181. attributes.name = `${attributes.name}-${intent}`;
  16182. }
  16183. for (const [key, value] of Object.entries(attributes)) {
  16184. if (value === null || value === undefined) {
  16185. continue;
  16186. }
  16187. switch (key) {
  16188. case "class":
  16189. if (value.length) {
  16190. html.setAttribute(key, value.join(" "));
  16191. }
  16192. break;
  16193. case "dataId":
  16194. break;
  16195. case "id":
  16196. html.setAttribute("data-element-id", value);
  16197. break;
  16198. case "style":
  16199. Object.assign(html.style, value);
  16200. break;
  16201. case "textContent":
  16202. html.textContent = value;
  16203. break;
  16204. default:
  16205. if (!isHTMLAnchorElement || key !== "href" && key !== "newWindow") {
  16206. html.setAttribute(key, value);
  16207. }
  16208. }
  16209. }
  16210. if (isHTMLAnchorElement) {
  16211. linkService.addLinkAttributes(html, attributes.href, attributes.newWindow);
  16212. }
  16213. if (storage && attributes.dataId) {
  16214. this.setupStorage(html, attributes.dataId, element, storage);
  16215. }
  16216. }
  16217. static render(parameters) {
  16218. const storage = parameters.annotationStorage;
  16219. const linkService = parameters.linkService;
  16220. const root = parameters.xfaHtml;
  16221. const intent = parameters.intent || "display";
  16222. const rootHtml = document.createElement(root.name);
  16223. if (root.attributes) {
  16224. this.setAttributes({
  16225. html: rootHtml,
  16226. element: root,
  16227. intent,
  16228. linkService
  16229. });
  16230. }
  16231. const isNotForRichText = intent !== "richText";
  16232. const rootDiv = parameters.div;
  16233. rootDiv.append(rootHtml);
  16234. if (parameters.viewport) {
  16235. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  16236. rootDiv.style.transform = transform;
  16237. }
  16238. if (isNotForRichText) {
  16239. rootDiv.setAttribute("class", "xfaLayer xfaFont");
  16240. }
  16241. const textDivs = [];
  16242. if (root.children.length === 0) {
  16243. if (root.value) {
  16244. const node = document.createTextNode(root.value);
  16245. rootHtml.append(node);
  16246. if (isNotForRichText && _xfa_text_js__WEBPACK_IMPORTED_MODULE_0__.XfaText.shouldBuildText(root.name)) {
  16247. textDivs.push(node);
  16248. }
  16249. }
  16250. return {
  16251. textDivs
  16252. };
  16253. }
  16254. const stack = [[root, -1, rootHtml]];
  16255. while (stack.length > 0) {
  16256. const [parent, i, html] = stack.at(-1);
  16257. if (i + 1 === parent.children.length) {
  16258. stack.pop();
  16259. continue;
  16260. }
  16261. const child = parent.children[++stack.at(-1)[1]];
  16262. if (child === null) {
  16263. continue;
  16264. }
  16265. const {
  16266. name
  16267. } = child;
  16268. if (name === "#text") {
  16269. const node = document.createTextNode(child.value);
  16270. textDivs.push(node);
  16271. html.append(node);
  16272. continue;
  16273. }
  16274. const childHtml = child?.attributes?.xmlns ? document.createElementNS(child.attributes.xmlns, name) : document.createElement(name);
  16275. html.append(childHtml);
  16276. if (child.attributes) {
  16277. this.setAttributes({
  16278. html: childHtml,
  16279. element: child,
  16280. storage,
  16281. intent,
  16282. linkService
  16283. });
  16284. }
  16285. if (child.children?.length > 0) {
  16286. stack.push([child, -1, childHtml]);
  16287. } else if (child.value) {
  16288. const node = document.createTextNode(child.value);
  16289. if (isNotForRichText && _xfa_text_js__WEBPACK_IMPORTED_MODULE_0__.XfaText.shouldBuildText(name)) {
  16290. textDivs.push(node);
  16291. }
  16292. childHtml.append(node);
  16293. }
  16294. }
  16295. for (const el of rootDiv.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea")) {
  16296. el.setAttribute("readOnly", true);
  16297. }
  16298. return {
  16299. textDivs
  16300. };
  16301. }
  16302. static update(parameters) {
  16303. const transform = `matrix(${parameters.viewport.transform.join(",")})`;
  16304. parameters.div.style.transform = transform;
  16305. parameters.div.hidden = false;
  16306. }
  16307. }
  16308. /***/ }),
  16309. /***/ 521:
  16310. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  16311. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  16312. /* harmony export */ XfaText: () => (/* binding */ XfaText)
  16313. /* harmony export */ });
  16314. class XfaText {
  16315. static textContent(xfa) {
  16316. const items = [];
  16317. const output = {
  16318. items,
  16319. styles: Object.create(null)
  16320. };
  16321. function walk(node) {
  16322. if (!node) {
  16323. return;
  16324. }
  16325. let str = null;
  16326. const name = node.name;
  16327. if (name === "#text") {
  16328. str = node.value;
  16329. } else if (!XfaText.shouldBuildText(name)) {
  16330. return;
  16331. } else if (node?.attributes?.textContent) {
  16332. str = node.attributes.textContent;
  16333. } else if (node.value) {
  16334. str = node.value;
  16335. }
  16336. if (str !== null) {
  16337. items.push({
  16338. str
  16339. });
  16340. }
  16341. if (!node.children) {
  16342. return;
  16343. }
  16344. for (const child of node.children) {
  16345. walk(child);
  16346. }
  16347. }
  16348. walk(xfa);
  16349. return output;
  16350. }
  16351. static shouldBuildText(name) {
  16352. return !(name === "textarea" || name === "input" || name === "option" || name === "select");
  16353. }
  16354. }
  16355. /***/ }),
  16356. /***/ 907:
  16357. /***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {
  16358. __webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
  16359. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  16360. /* harmony export */ AbortException: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException),
  16361. /* harmony export */ AnnotationEditorLayer: () => (/* reexport safe */ _display_editor_annotation_editor_layer_js__WEBPACK_IMPORTED_MODULE_4__.AnnotationEditorLayer),
  16362. /* harmony export */ AnnotationEditorParamsType: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorParamsType),
  16363. /* harmony export */ AnnotationEditorType: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationEditorType),
  16364. /* harmony export */ AnnotationEditorUIManager: () => (/* reexport safe */ _display_editor_tools_js__WEBPACK_IMPORTED_MODULE_5__.AnnotationEditorUIManager),
  16365. /* harmony export */ AnnotationLayer: () => (/* reexport safe */ _display_annotation_layer_js__WEBPACK_IMPORTED_MODULE_6__.AnnotationLayer),
  16366. /* harmony export */ AnnotationMode: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.AnnotationMode),
  16367. /* harmony export */ CMapCompressionType: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.CMapCompressionType),
  16368. /* harmony export */ ColorPicker: () => (/* reexport safe */ _display_editor_color_picker_js__WEBPACK_IMPORTED_MODULE_7__.ColorPicker),
  16369. /* harmony export */ DOMSVGFactory: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.DOMSVGFactory),
  16370. /* harmony export */ DrawLayer: () => (/* reexport safe */ _display_draw_layer_js__WEBPACK_IMPORTED_MODULE_8__.DrawLayer),
  16371. /* harmony export */ FeatureTest: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.FeatureTest),
  16372. /* harmony export */ GlobalWorkerOptions: () => (/* reexport safe */ _display_worker_options_js__WEBPACK_IMPORTED_MODULE_9__.GlobalWorkerOptions),
  16373. /* harmony export */ ImageKind: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.ImageKind),
  16374. /* harmony export */ InvalidPDFException: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.InvalidPDFException),
  16375. /* harmony export */ MissingPDFException: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException),
  16376. /* harmony export */ OPS: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.OPS),
  16377. /* harmony export */ Outliner: () => (/* reexport safe */ _display_editor_outliner_js__WEBPACK_IMPORTED_MODULE_10__.Outliner),
  16378. /* harmony export */ PDFDataRangeTransport: () => (/* reexport safe */ _display_api_js__WEBPACK_IMPORTED_MODULE_1__.PDFDataRangeTransport),
  16379. /* harmony export */ PDFDateString: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.PDFDateString),
  16380. /* harmony export */ PDFWorker: () => (/* reexport safe */ _display_api_js__WEBPACK_IMPORTED_MODULE_1__.PDFWorker),
  16381. /* harmony export */ PasswordResponses: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PasswordResponses),
  16382. /* harmony export */ PermissionFlag: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PermissionFlag),
  16383. /* harmony export */ PixelsPerInch: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.PixelsPerInch),
  16384. /* harmony export */ PromiseCapability: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability),
  16385. /* harmony export */ RenderingCancelledException: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.RenderingCancelledException),
  16386. /* harmony export */ UnexpectedResponseException: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.UnexpectedResponseException),
  16387. /* harmony export */ Util: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.Util),
  16388. /* harmony export */ VerbosityLevel: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.VerbosityLevel),
  16389. /* harmony export */ XfaLayer: () => (/* reexport safe */ _display_xfa_layer_js__WEBPACK_IMPORTED_MODULE_11__.XfaLayer),
  16390. /* harmony export */ build: () => (/* reexport safe */ _display_api_js__WEBPACK_IMPORTED_MODULE_1__.build),
  16391. /* harmony export */ createValidAbsoluteUrl: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.createValidAbsoluteUrl),
  16392. /* harmony export */ fetchData: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.fetchData),
  16393. /* harmony export */ getDocument: () => (/* reexport safe */ _display_api_js__WEBPACK_IMPORTED_MODULE_1__.getDocument),
  16394. /* harmony export */ getFilenameFromUrl: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.getFilenameFromUrl),
  16395. /* harmony export */ getPdfFilenameFromUrl: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.getPdfFilenameFromUrl),
  16396. /* harmony export */ getXfaPageViewport: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.getXfaPageViewport),
  16397. /* harmony export */ isDataScheme: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.isDataScheme),
  16398. /* harmony export */ isPdfFile: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.isPdfFile),
  16399. /* harmony export */ noContextMenu: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.noContextMenu),
  16400. /* harmony export */ normalizeUnicode: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.normalizeUnicode),
  16401. /* harmony export */ renderTextLayer: () => (/* reexport safe */ _display_text_layer_js__WEBPACK_IMPORTED_MODULE_3__.renderTextLayer),
  16402. /* harmony export */ setLayerDimensions: () => (/* reexport safe */ _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__.setLayerDimensions),
  16403. /* harmony export */ shadow: () => (/* reexport safe */ _shared_util_js__WEBPACK_IMPORTED_MODULE_0__.shadow),
  16404. /* harmony export */ updateTextLayer: () => (/* reexport safe */ _display_text_layer_js__WEBPACK_IMPORTED_MODULE_3__.updateTextLayer),
  16405. /* harmony export */ version: () => (/* reexport safe */ _display_api_js__WEBPACK_IMPORTED_MODULE_1__.version)
  16406. /* harmony export */ });
  16407. /* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  16408. /* harmony import */ var _display_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(406);
  16409. /* harmony import */ var _display_display_utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(473);
  16410. /* harmony import */ var _display_text_layer_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(739);
  16411. /* harmony import */ var _display_editor_annotation_editor_layer_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(629);
  16412. /* harmony import */ var _display_editor_tools_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(812);
  16413. /* harmony import */ var _display_annotation_layer_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(640);
  16414. /* harmony import */ var _display_editor_color_picker_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(97);
  16415. /* harmony import */ var _display_draw_layer_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(423);
  16416. /* harmony import */ var _display_worker_options_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(368);
  16417. /* harmony import */ var _display_editor_outliner_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(405);
  16418. /* harmony import */ var _display_xfa_layer_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(160);
  16419. var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_display_api_js__WEBPACK_IMPORTED_MODULE_1__]);
  16420. _display_api_js__WEBPACK_IMPORTED_MODULE_1__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
  16421. const pdfjsVersion = '4.0.379';
  16422. const pdfjsBuild = '9e14d04fd';
  16423. __webpack_async_result__();
  16424. } catch(e) { __webpack_async_result__(e); } });
  16425. /***/ }),
  16426. /***/ 694:
  16427. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  16428. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  16429. /* harmony export */ MessageHandler: () => (/* binding */ MessageHandler)
  16430. /* harmony export */ });
  16431. /* harmony import */ var _util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  16432. const CallbackKind = {
  16433. UNKNOWN: 0,
  16434. DATA: 1,
  16435. ERROR: 2
  16436. };
  16437. const StreamKind = {
  16438. UNKNOWN: 0,
  16439. CANCEL: 1,
  16440. CANCEL_COMPLETE: 2,
  16441. CLOSE: 3,
  16442. ENQUEUE: 4,
  16443. ERROR: 5,
  16444. PULL: 6,
  16445. PULL_COMPLETE: 7,
  16446. START_COMPLETE: 8
  16447. };
  16448. function wrapReason(reason) {
  16449. if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
  16450. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.unreachable)('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
  16451. }
  16452. switch (reason.name) {
  16453. case "AbortException":
  16454. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.AbortException(reason.message);
  16455. case "MissingPDFException":
  16456. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.MissingPDFException(reason.message);
  16457. case "PasswordException":
  16458. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.PasswordException(reason.message, reason.code);
  16459. case "UnexpectedResponseException":
  16460. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.UnexpectedResponseException(reason.message, reason.status);
  16461. case "UnknownErrorException":
  16462. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.UnknownErrorException(reason.message, reason.details);
  16463. default:
  16464. return new _util_js__WEBPACK_IMPORTED_MODULE_0__.UnknownErrorException(reason.message, reason.toString());
  16465. }
  16466. }
  16467. class MessageHandler {
  16468. constructor(sourceName, targetName, comObj) {
  16469. this.sourceName = sourceName;
  16470. this.targetName = targetName;
  16471. this.comObj = comObj;
  16472. this.callbackId = 1;
  16473. this.streamId = 1;
  16474. this.streamSinks = Object.create(null);
  16475. this.streamControllers = Object.create(null);
  16476. this.callbackCapabilities = Object.create(null);
  16477. this.actionHandler = Object.create(null);
  16478. this._onComObjOnMessage = event => {
  16479. const data = event.data;
  16480. if (data.targetName !== this.sourceName) {
  16481. return;
  16482. }
  16483. if (data.stream) {
  16484. this.#processStreamMessage(data);
  16485. return;
  16486. }
  16487. if (data.callback) {
  16488. const callbackId = data.callbackId;
  16489. const capability = this.callbackCapabilities[callbackId];
  16490. if (!capability) {
  16491. throw new Error(`Cannot resolve callback ${callbackId}`);
  16492. }
  16493. delete this.callbackCapabilities[callbackId];
  16494. if (data.callback === CallbackKind.DATA) {
  16495. capability.resolve(data.data);
  16496. } else if (data.callback === CallbackKind.ERROR) {
  16497. capability.reject(wrapReason(data.reason));
  16498. } else {
  16499. throw new Error("Unexpected callback case");
  16500. }
  16501. return;
  16502. }
  16503. const action = this.actionHandler[data.action];
  16504. if (!action) {
  16505. throw new Error(`Unknown action from worker: ${data.action}`);
  16506. }
  16507. if (data.callbackId) {
  16508. const cbSourceName = this.sourceName;
  16509. const cbTargetName = data.sourceName;
  16510. new Promise(function (resolve) {
  16511. resolve(action(data.data));
  16512. }).then(function (result) {
  16513. comObj.postMessage({
  16514. sourceName: cbSourceName,
  16515. targetName: cbTargetName,
  16516. callback: CallbackKind.DATA,
  16517. callbackId: data.callbackId,
  16518. data: result
  16519. });
  16520. }, function (reason) {
  16521. comObj.postMessage({
  16522. sourceName: cbSourceName,
  16523. targetName: cbTargetName,
  16524. callback: CallbackKind.ERROR,
  16525. callbackId: data.callbackId,
  16526. reason: wrapReason(reason)
  16527. });
  16528. });
  16529. return;
  16530. }
  16531. if (data.streamId) {
  16532. this.#createStreamSink(data);
  16533. return;
  16534. }
  16535. action(data.data);
  16536. };
  16537. comObj.addEventListener("message", this._onComObjOnMessage);
  16538. }
  16539. on(actionName, handler) {
  16540. const ah = this.actionHandler;
  16541. if (ah[actionName]) {
  16542. throw new Error(`There is already an actionName called "${actionName}"`);
  16543. }
  16544. ah[actionName] = handler;
  16545. }
  16546. send(actionName, data, transfers) {
  16547. this.comObj.postMessage({
  16548. sourceName: this.sourceName,
  16549. targetName: this.targetName,
  16550. action: actionName,
  16551. data
  16552. }, transfers);
  16553. }
  16554. sendWithPromise(actionName, data, transfers) {
  16555. const callbackId = this.callbackId++;
  16556. const capability = new _util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  16557. this.callbackCapabilities[callbackId] = capability;
  16558. try {
  16559. this.comObj.postMessage({
  16560. sourceName: this.sourceName,
  16561. targetName: this.targetName,
  16562. action: actionName,
  16563. callbackId,
  16564. data
  16565. }, transfers);
  16566. } catch (ex) {
  16567. capability.reject(ex);
  16568. }
  16569. return capability.promise;
  16570. }
  16571. sendWithStream(actionName, data, queueingStrategy, transfers) {
  16572. const streamId = this.streamId++,
  16573. sourceName = this.sourceName,
  16574. targetName = this.targetName,
  16575. comObj = this.comObj;
  16576. return new ReadableStream({
  16577. start: controller => {
  16578. const startCapability = new _util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  16579. this.streamControllers[streamId] = {
  16580. controller,
  16581. startCall: startCapability,
  16582. pullCall: null,
  16583. cancelCall: null,
  16584. isClosed: false
  16585. };
  16586. comObj.postMessage({
  16587. sourceName,
  16588. targetName,
  16589. action: actionName,
  16590. streamId,
  16591. data,
  16592. desiredSize: controller.desiredSize
  16593. }, transfers);
  16594. return startCapability.promise;
  16595. },
  16596. pull: controller => {
  16597. const pullCapability = new _util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  16598. this.streamControllers[streamId].pullCall = pullCapability;
  16599. comObj.postMessage({
  16600. sourceName,
  16601. targetName,
  16602. stream: StreamKind.PULL,
  16603. streamId,
  16604. desiredSize: controller.desiredSize
  16605. });
  16606. return pullCapability.promise;
  16607. },
  16608. cancel: reason => {
  16609. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(reason instanceof Error, "cancel must have a valid reason");
  16610. const cancelCapability = new _util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  16611. this.streamControllers[streamId].cancelCall = cancelCapability;
  16612. this.streamControllers[streamId].isClosed = true;
  16613. comObj.postMessage({
  16614. sourceName,
  16615. targetName,
  16616. stream: StreamKind.CANCEL,
  16617. streamId,
  16618. reason: wrapReason(reason)
  16619. });
  16620. return cancelCapability.promise;
  16621. }
  16622. }, queueingStrategy);
  16623. }
  16624. #createStreamSink(data) {
  16625. const streamId = data.streamId,
  16626. sourceName = this.sourceName,
  16627. targetName = data.sourceName,
  16628. comObj = this.comObj;
  16629. const self = this,
  16630. action = this.actionHandler[data.action];
  16631. const streamSink = {
  16632. enqueue(chunk, size = 1, transfers) {
  16633. if (this.isCancelled) {
  16634. return;
  16635. }
  16636. const lastDesiredSize = this.desiredSize;
  16637. this.desiredSize -= size;
  16638. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  16639. this.sinkCapability = new _util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability();
  16640. this.ready = this.sinkCapability.promise;
  16641. }
  16642. comObj.postMessage({
  16643. sourceName,
  16644. targetName,
  16645. stream: StreamKind.ENQUEUE,
  16646. streamId,
  16647. chunk
  16648. }, transfers);
  16649. },
  16650. close() {
  16651. if (this.isCancelled) {
  16652. return;
  16653. }
  16654. this.isCancelled = true;
  16655. comObj.postMessage({
  16656. sourceName,
  16657. targetName,
  16658. stream: StreamKind.CLOSE,
  16659. streamId
  16660. });
  16661. delete self.streamSinks[streamId];
  16662. },
  16663. error(reason) {
  16664. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(reason instanceof Error, "error must have a valid reason");
  16665. if (this.isCancelled) {
  16666. return;
  16667. }
  16668. this.isCancelled = true;
  16669. comObj.postMessage({
  16670. sourceName,
  16671. targetName,
  16672. stream: StreamKind.ERROR,
  16673. streamId,
  16674. reason: wrapReason(reason)
  16675. });
  16676. },
  16677. sinkCapability: new _util_js__WEBPACK_IMPORTED_MODULE_0__.PromiseCapability(),
  16678. onPull: null,
  16679. onCancel: null,
  16680. isCancelled: false,
  16681. desiredSize: data.desiredSize,
  16682. ready: null
  16683. };
  16684. streamSink.sinkCapability.resolve();
  16685. streamSink.ready = streamSink.sinkCapability.promise;
  16686. this.streamSinks[streamId] = streamSink;
  16687. new Promise(function (resolve) {
  16688. resolve(action(data.data, streamSink));
  16689. }).then(function () {
  16690. comObj.postMessage({
  16691. sourceName,
  16692. targetName,
  16693. stream: StreamKind.START_COMPLETE,
  16694. streamId,
  16695. success: true
  16696. });
  16697. }, function (reason) {
  16698. comObj.postMessage({
  16699. sourceName,
  16700. targetName,
  16701. stream: StreamKind.START_COMPLETE,
  16702. streamId,
  16703. reason: wrapReason(reason)
  16704. });
  16705. });
  16706. }
  16707. #processStreamMessage(data) {
  16708. const streamId = data.streamId,
  16709. sourceName = this.sourceName,
  16710. targetName = data.sourceName,
  16711. comObj = this.comObj;
  16712. const streamController = this.streamControllers[streamId],
  16713. streamSink = this.streamSinks[streamId];
  16714. switch (data.stream) {
  16715. case StreamKind.START_COMPLETE:
  16716. if (data.success) {
  16717. streamController.startCall.resolve();
  16718. } else {
  16719. streamController.startCall.reject(wrapReason(data.reason));
  16720. }
  16721. break;
  16722. case StreamKind.PULL_COMPLETE:
  16723. if (data.success) {
  16724. streamController.pullCall.resolve();
  16725. } else {
  16726. streamController.pullCall.reject(wrapReason(data.reason));
  16727. }
  16728. break;
  16729. case StreamKind.PULL:
  16730. if (!streamSink) {
  16731. comObj.postMessage({
  16732. sourceName,
  16733. targetName,
  16734. stream: StreamKind.PULL_COMPLETE,
  16735. streamId,
  16736. success: true
  16737. });
  16738. break;
  16739. }
  16740. if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
  16741. streamSink.sinkCapability.resolve();
  16742. }
  16743. streamSink.desiredSize = data.desiredSize;
  16744. new Promise(function (resolve) {
  16745. resolve(streamSink.onPull?.());
  16746. }).then(function () {
  16747. comObj.postMessage({
  16748. sourceName,
  16749. targetName,
  16750. stream: StreamKind.PULL_COMPLETE,
  16751. streamId,
  16752. success: true
  16753. });
  16754. }, function (reason) {
  16755. comObj.postMessage({
  16756. sourceName,
  16757. targetName,
  16758. stream: StreamKind.PULL_COMPLETE,
  16759. streamId,
  16760. reason: wrapReason(reason)
  16761. });
  16762. });
  16763. break;
  16764. case StreamKind.ENQUEUE:
  16765. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(streamController, "enqueue should have stream controller");
  16766. if (streamController.isClosed) {
  16767. break;
  16768. }
  16769. streamController.controller.enqueue(data.chunk);
  16770. break;
  16771. case StreamKind.CLOSE:
  16772. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(streamController, "close should have stream controller");
  16773. if (streamController.isClosed) {
  16774. break;
  16775. }
  16776. streamController.isClosed = true;
  16777. streamController.controller.close();
  16778. this.#deleteStreamController(streamController, streamId);
  16779. break;
  16780. case StreamKind.ERROR:
  16781. (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.assert)(streamController, "error should have stream controller");
  16782. streamController.controller.error(wrapReason(data.reason));
  16783. this.#deleteStreamController(streamController, streamId);
  16784. break;
  16785. case StreamKind.CANCEL_COMPLETE:
  16786. if (data.success) {
  16787. streamController.cancelCall.resolve();
  16788. } else {
  16789. streamController.cancelCall.reject(wrapReason(data.reason));
  16790. }
  16791. this.#deleteStreamController(streamController, streamId);
  16792. break;
  16793. case StreamKind.CANCEL:
  16794. if (!streamSink) {
  16795. break;
  16796. }
  16797. new Promise(function (resolve) {
  16798. resolve(streamSink.onCancel?.(wrapReason(data.reason)));
  16799. }).then(function () {
  16800. comObj.postMessage({
  16801. sourceName,
  16802. targetName,
  16803. stream: StreamKind.CANCEL_COMPLETE,
  16804. streamId,
  16805. success: true
  16806. });
  16807. }, function (reason) {
  16808. comObj.postMessage({
  16809. sourceName,
  16810. targetName,
  16811. stream: StreamKind.CANCEL_COMPLETE,
  16812. streamId,
  16813. reason: wrapReason(reason)
  16814. });
  16815. });
  16816. streamSink.sinkCapability.reject(wrapReason(data.reason));
  16817. streamSink.isCancelled = true;
  16818. delete this.streamSinks[streamId];
  16819. break;
  16820. default:
  16821. throw new Error("Unexpected stream case");
  16822. }
  16823. }
  16824. async #deleteStreamController(streamController, streamId) {
  16825. await Promise.allSettled([streamController.startCall?.promise, streamController.pullCall?.promise, streamController.cancelCall?.promise]);
  16826. delete this.streamControllers[streamId];
  16827. }
  16828. destroy() {
  16829. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  16830. }
  16831. }
  16832. /***/ }),
  16833. /***/ 825:
  16834. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  16835. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  16836. /* harmony export */ MurmurHash3_64: () => (/* binding */ MurmurHash3_64)
  16837. /* harmony export */ });
  16838. /* harmony import */ var _util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(266);
  16839. const SEED = 0xc3d2e1f0;
  16840. const MASK_HIGH = 0xffff0000;
  16841. const MASK_LOW = 0xffff;
  16842. class MurmurHash3_64 {
  16843. constructor(seed) {
  16844. this.h1 = seed ? seed & 0xffffffff : SEED;
  16845. this.h2 = seed ? seed & 0xffffffff : SEED;
  16846. }
  16847. update(input) {
  16848. let data, length;
  16849. if (typeof input === "string") {
  16850. data = new Uint8Array(input.length * 2);
  16851. length = 0;
  16852. for (let i = 0, ii = input.length; i < ii; i++) {
  16853. const code = input.charCodeAt(i);
  16854. if (code <= 0xff) {
  16855. data[length++] = code;
  16856. } else {
  16857. data[length++] = code >>> 8;
  16858. data[length++] = code & 0xff;
  16859. }
  16860. }
  16861. } else if ((0,_util_js__WEBPACK_IMPORTED_MODULE_0__.isArrayBuffer)(input)) {
  16862. data = input.slice();
  16863. length = data.byteLength;
  16864. } else {
  16865. throw new Error("Wrong data format in MurmurHash3_64_update. " + "Input must be a string or array.");
  16866. }
  16867. const blockCounts = length >> 2;
  16868. const tailLength = length - blockCounts * 4;
  16869. const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
  16870. let k1 = 0,
  16871. k2 = 0;
  16872. let h1 = this.h1,
  16873. h2 = this.h2;
  16874. const C1 = 0xcc9e2d51,
  16875. C2 = 0x1b873593;
  16876. const C1_LOW = C1 & MASK_LOW,
  16877. C2_LOW = C2 & MASK_LOW;
  16878. for (let i = 0; i < blockCounts; i++) {
  16879. if (i & 1) {
  16880. k1 = dataUint32[i];
  16881. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  16882. k1 = k1 << 15 | k1 >>> 17;
  16883. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  16884. h1 ^= k1;
  16885. h1 = h1 << 13 | h1 >>> 19;
  16886. h1 = h1 * 5 + 0xe6546b64;
  16887. } else {
  16888. k2 = dataUint32[i];
  16889. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  16890. k2 = k2 << 15 | k2 >>> 17;
  16891. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  16892. h2 ^= k2;
  16893. h2 = h2 << 13 | h2 >>> 19;
  16894. h2 = h2 * 5 + 0xe6546b64;
  16895. }
  16896. }
  16897. k1 = 0;
  16898. switch (tailLength) {
  16899. case 3:
  16900. k1 ^= data[blockCounts * 4 + 2] << 16;
  16901. case 2:
  16902. k1 ^= data[blockCounts * 4 + 1] << 8;
  16903. case 1:
  16904. k1 ^= data[blockCounts * 4];
  16905. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  16906. k1 = k1 << 15 | k1 >>> 17;
  16907. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  16908. if (blockCounts & 1) {
  16909. h1 ^= k1;
  16910. } else {
  16911. h2 ^= k1;
  16912. }
  16913. }
  16914. this.h1 = h1;
  16915. this.h2 = h2;
  16916. }
  16917. hexdigest() {
  16918. let h1 = this.h1,
  16919. h2 = this.h2;
  16920. h1 ^= h2 >>> 1;
  16921. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  16922. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  16923. h1 ^= h2 >>> 1;
  16924. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  16925. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  16926. h1 ^= h2 >>> 1;
  16927. return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
  16928. }
  16929. }
  16930. /***/ }),
  16931. /***/ 266:
  16932. /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
  16933. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  16934. /* harmony export */ AbortException: () => (/* binding */ AbortException),
  16935. /* harmony export */ AnnotationBorderStyleType: () => (/* binding */ AnnotationBorderStyleType),
  16936. /* harmony export */ AnnotationEditorParamsType: () => (/* binding */ AnnotationEditorParamsType),
  16937. /* harmony export */ AnnotationEditorPrefix: () => (/* binding */ AnnotationEditorPrefix),
  16938. /* harmony export */ AnnotationEditorType: () => (/* binding */ AnnotationEditorType),
  16939. /* harmony export */ AnnotationMode: () => (/* binding */ AnnotationMode),
  16940. /* harmony export */ AnnotationPrefix: () => (/* binding */ AnnotationPrefix),
  16941. /* harmony export */ AnnotationType: () => (/* binding */ AnnotationType),
  16942. /* harmony export */ BaseException: () => (/* binding */ BaseException),
  16943. /* harmony export */ CMapCompressionType: () => (/* binding */ CMapCompressionType),
  16944. /* harmony export */ FONT_IDENTITY_MATRIX: () => (/* binding */ FONT_IDENTITY_MATRIX),
  16945. /* harmony export */ FeatureTest: () => (/* binding */ FeatureTest),
  16946. /* harmony export */ FormatError: () => (/* binding */ FormatError),
  16947. /* harmony export */ IDENTITY_MATRIX: () => (/* binding */ IDENTITY_MATRIX),
  16948. /* harmony export */ ImageKind: () => (/* binding */ ImageKind),
  16949. /* harmony export */ InvalidPDFException: () => (/* binding */ InvalidPDFException),
  16950. /* harmony export */ LINE_FACTOR: () => (/* binding */ LINE_FACTOR),
  16951. /* harmony export */ MAX_IMAGE_SIZE_TO_CACHE: () => (/* binding */ MAX_IMAGE_SIZE_TO_CACHE),
  16952. /* harmony export */ MissingPDFException: () => (/* binding */ MissingPDFException),
  16953. /* harmony export */ OPS: () => (/* binding */ OPS),
  16954. /* harmony export */ PasswordException: () => (/* binding */ PasswordException),
  16955. /* harmony export */ PasswordResponses: () => (/* binding */ PasswordResponses),
  16956. /* harmony export */ PermissionFlag: () => (/* binding */ PermissionFlag),
  16957. /* harmony export */ PromiseCapability: () => (/* binding */ PromiseCapability),
  16958. /* harmony export */ RenderingIntentFlag: () => (/* binding */ RenderingIntentFlag),
  16959. /* harmony export */ TextRenderingMode: () => (/* binding */ TextRenderingMode),
  16960. /* harmony export */ UnexpectedResponseException: () => (/* binding */ UnexpectedResponseException),
  16961. /* harmony export */ UnknownErrorException: () => (/* binding */ UnknownErrorException),
  16962. /* harmony export */ Util: () => (/* binding */ Util),
  16963. /* harmony export */ VerbosityLevel: () => (/* binding */ VerbosityLevel),
  16964. /* harmony export */ assert: () => (/* binding */ assert),
  16965. /* harmony export */ bytesToString: () => (/* binding */ bytesToString),
  16966. /* harmony export */ createValidAbsoluteUrl: () => (/* binding */ createValidAbsoluteUrl),
  16967. /* harmony export */ getUuid: () => (/* binding */ getUuid),
  16968. /* harmony export */ getVerbosityLevel: () => (/* binding */ getVerbosityLevel),
  16969. /* harmony export */ info: () => (/* binding */ info),
  16970. /* harmony export */ isArrayBuffer: () => (/* binding */ isArrayBuffer),
  16971. /* harmony export */ isNodeJS: () => (/* binding */ isNodeJS),
  16972. /* harmony export */ normalizeUnicode: () => (/* binding */ normalizeUnicode),
  16973. /* harmony export */ objectFromMap: () => (/* binding */ objectFromMap),
  16974. /* harmony export */ setVerbosityLevel: () => (/* binding */ setVerbosityLevel),
  16975. /* harmony export */ shadow: () => (/* binding */ shadow),
  16976. /* harmony export */ string32: () => (/* binding */ string32),
  16977. /* harmony export */ stringToBytes: () => (/* binding */ stringToBytes),
  16978. /* harmony export */ unreachable: () => (/* binding */ unreachable),
  16979. /* harmony export */ warn: () => (/* binding */ warn)
  16980. /* harmony export */ });
  16981. /* unused harmony exports AnnotationActionEventType, AnnotationFieldFlag, AnnotationFlag, AnnotationReplyType, BASELINE_FACTOR, DocumentActionEventType, getModificationDate, isArrayEqual, LINE_DESCENT_FACTOR, objectSize, PageActionEventType, stringToPDFString, stringToUTF8String, utf8StringToString */
  16982. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  16983. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  16984. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  16985. const MAX_IMAGE_SIZE_TO_CACHE = 10e6;
  16986. const LINE_FACTOR = 1.35;
  16987. const LINE_DESCENT_FACTOR = 0.35;
  16988. const BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
  16989. const RenderingIntentFlag = {
  16990. ANY: 0x01,
  16991. DISPLAY: 0x02,
  16992. PRINT: 0x04,
  16993. SAVE: 0x08,
  16994. ANNOTATIONS_FORMS: 0x10,
  16995. ANNOTATIONS_STORAGE: 0x20,
  16996. ANNOTATIONS_DISABLE: 0x40,
  16997. OPLIST: 0x100
  16998. };
  16999. const AnnotationMode = {
  17000. DISABLE: 0,
  17001. ENABLE: 1,
  17002. ENABLE_FORMS: 2,
  17003. ENABLE_STORAGE: 3
  17004. };
  17005. const AnnotationEditorPrefix = "pdfjs_internal_editor_";
  17006. const AnnotationEditorType = {
  17007. DISABLE: -1,
  17008. NONE: 0,
  17009. FREETEXT: 3,
  17010. HIGHLIGHT: 9,
  17011. STAMP: 13,
  17012. INK: 15
  17013. };
  17014. const AnnotationEditorParamsType = {
  17015. RESIZE: 1,
  17016. CREATE: 2,
  17017. FREETEXT_SIZE: 11,
  17018. FREETEXT_COLOR: 12,
  17019. FREETEXT_OPACITY: 13,
  17020. INK_COLOR: 21,
  17021. INK_THICKNESS: 22,
  17022. INK_OPACITY: 23,
  17023. HIGHLIGHT_COLOR: 31,
  17024. HIGHLIGHT_DEFAULT_COLOR: 32
  17025. };
  17026. const PermissionFlag = {
  17027. PRINT: 0x04,
  17028. MODIFY_CONTENTS: 0x08,
  17029. COPY: 0x10,
  17030. MODIFY_ANNOTATIONS: 0x20,
  17031. FILL_INTERACTIVE_FORMS: 0x100,
  17032. COPY_FOR_ACCESSIBILITY: 0x200,
  17033. ASSEMBLE: 0x400,
  17034. PRINT_HIGH_QUALITY: 0x800
  17035. };
  17036. const TextRenderingMode = {
  17037. FILL: 0,
  17038. STROKE: 1,
  17039. FILL_STROKE: 2,
  17040. INVISIBLE: 3,
  17041. FILL_ADD_TO_PATH: 4,
  17042. STROKE_ADD_TO_PATH: 5,
  17043. FILL_STROKE_ADD_TO_PATH: 6,
  17044. ADD_TO_PATH: 7,
  17045. FILL_STROKE_MASK: 3,
  17046. ADD_TO_PATH_FLAG: 4
  17047. };
  17048. const ImageKind = {
  17049. GRAYSCALE_1BPP: 1,
  17050. RGB_24BPP: 2,
  17051. RGBA_32BPP: 3
  17052. };
  17053. const AnnotationType = {
  17054. TEXT: 1,
  17055. LINK: 2,
  17056. FREETEXT: 3,
  17057. LINE: 4,
  17058. SQUARE: 5,
  17059. CIRCLE: 6,
  17060. POLYGON: 7,
  17061. POLYLINE: 8,
  17062. HIGHLIGHT: 9,
  17063. UNDERLINE: 10,
  17064. SQUIGGLY: 11,
  17065. STRIKEOUT: 12,
  17066. STAMP: 13,
  17067. CARET: 14,
  17068. INK: 15,
  17069. POPUP: 16,
  17070. FILEATTACHMENT: 17,
  17071. SOUND: 18,
  17072. MOVIE: 19,
  17073. WIDGET: 20,
  17074. SCREEN: 21,
  17075. PRINTERMARK: 22,
  17076. TRAPNET: 23,
  17077. WATERMARK: 24,
  17078. THREED: 25,
  17079. REDACT: 26
  17080. };
  17081. const AnnotationReplyType = {
  17082. GROUP: "Group",
  17083. REPLY: "R"
  17084. };
  17085. const AnnotationFlag = {
  17086. INVISIBLE: 0x01,
  17087. HIDDEN: 0x02,
  17088. PRINT: 0x04,
  17089. NOZOOM: 0x08,
  17090. NOROTATE: 0x10,
  17091. NOVIEW: 0x20,
  17092. READONLY: 0x40,
  17093. LOCKED: 0x80,
  17094. TOGGLENOVIEW: 0x100,
  17095. LOCKEDCONTENTS: 0x200
  17096. };
  17097. const AnnotationFieldFlag = {
  17098. READONLY: 0x0000001,
  17099. REQUIRED: 0x0000002,
  17100. NOEXPORT: 0x0000004,
  17101. MULTILINE: 0x0001000,
  17102. PASSWORD: 0x0002000,
  17103. NOTOGGLETOOFF: 0x0004000,
  17104. RADIO: 0x0008000,
  17105. PUSHBUTTON: 0x0010000,
  17106. COMBO: 0x0020000,
  17107. EDIT: 0x0040000,
  17108. SORT: 0x0080000,
  17109. FILESELECT: 0x0100000,
  17110. MULTISELECT: 0x0200000,
  17111. DONOTSPELLCHECK: 0x0400000,
  17112. DONOTSCROLL: 0x0800000,
  17113. COMB: 0x1000000,
  17114. RICHTEXT: 0x2000000,
  17115. RADIOSINUNISON: 0x2000000,
  17116. COMMITONSELCHANGE: 0x4000000
  17117. };
  17118. const AnnotationBorderStyleType = {
  17119. SOLID: 1,
  17120. DASHED: 2,
  17121. BEVELED: 3,
  17122. INSET: 4,
  17123. UNDERLINE: 5
  17124. };
  17125. const AnnotationActionEventType = {
  17126. E: "Mouse Enter",
  17127. X: "Mouse Exit",
  17128. D: "Mouse Down",
  17129. U: "Mouse Up",
  17130. Fo: "Focus",
  17131. Bl: "Blur",
  17132. PO: "PageOpen",
  17133. PC: "PageClose",
  17134. PV: "PageVisible",
  17135. PI: "PageInvisible",
  17136. K: "Keystroke",
  17137. F: "Format",
  17138. V: "Validate",
  17139. C: "Calculate"
  17140. };
  17141. const DocumentActionEventType = {
  17142. WC: "WillClose",
  17143. WS: "WillSave",
  17144. DS: "DidSave",
  17145. WP: "WillPrint",
  17146. DP: "DidPrint"
  17147. };
  17148. const PageActionEventType = {
  17149. O: "PageOpen",
  17150. C: "PageClose"
  17151. };
  17152. const VerbosityLevel = {
  17153. ERRORS: 0,
  17154. WARNINGS: 1,
  17155. INFOS: 5
  17156. };
  17157. const CMapCompressionType = {
  17158. NONE: 0,
  17159. BINARY: 1
  17160. };
  17161. const OPS = {
  17162. dependency: 1,
  17163. setLineWidth: 2,
  17164. setLineCap: 3,
  17165. setLineJoin: 4,
  17166. setMiterLimit: 5,
  17167. setDash: 6,
  17168. setRenderingIntent: 7,
  17169. setFlatness: 8,
  17170. setGState: 9,
  17171. save: 10,
  17172. restore: 11,
  17173. transform: 12,
  17174. moveTo: 13,
  17175. lineTo: 14,
  17176. curveTo: 15,
  17177. curveTo2: 16,
  17178. curveTo3: 17,
  17179. closePath: 18,
  17180. rectangle: 19,
  17181. stroke: 20,
  17182. closeStroke: 21,
  17183. fill: 22,
  17184. eoFill: 23,
  17185. fillStroke: 24,
  17186. eoFillStroke: 25,
  17187. closeFillStroke: 26,
  17188. closeEOFillStroke: 27,
  17189. endPath: 28,
  17190. clip: 29,
  17191. eoClip: 30,
  17192. beginText: 31,
  17193. endText: 32,
  17194. setCharSpacing: 33,
  17195. setWordSpacing: 34,
  17196. setHScale: 35,
  17197. setLeading: 36,
  17198. setFont: 37,
  17199. setTextRenderingMode: 38,
  17200. setTextRise: 39,
  17201. moveText: 40,
  17202. setLeadingMoveText: 41,
  17203. setTextMatrix: 42,
  17204. nextLine: 43,
  17205. showText: 44,
  17206. showSpacedText: 45,
  17207. nextLineShowText: 46,
  17208. nextLineSetSpacingShowText: 47,
  17209. setCharWidth: 48,
  17210. setCharWidthAndBounds: 49,
  17211. setStrokeColorSpace: 50,
  17212. setFillColorSpace: 51,
  17213. setStrokeColor: 52,
  17214. setStrokeColorN: 53,
  17215. setFillColor: 54,
  17216. setFillColorN: 55,
  17217. setStrokeGray: 56,
  17218. setFillGray: 57,
  17219. setStrokeRGBColor: 58,
  17220. setFillRGBColor: 59,
  17221. setStrokeCMYKColor: 60,
  17222. setFillCMYKColor: 61,
  17223. shadingFill: 62,
  17224. beginInlineImage: 63,
  17225. beginImageData: 64,
  17226. endInlineImage: 65,
  17227. paintXObject: 66,
  17228. markPoint: 67,
  17229. markPointProps: 68,
  17230. beginMarkedContent: 69,
  17231. beginMarkedContentProps: 70,
  17232. endMarkedContent: 71,
  17233. beginCompat: 72,
  17234. endCompat: 73,
  17235. paintFormXObjectBegin: 74,
  17236. paintFormXObjectEnd: 75,
  17237. beginGroup: 76,
  17238. endGroup: 77,
  17239. beginAnnotation: 80,
  17240. endAnnotation: 81,
  17241. paintImageMaskXObject: 83,
  17242. paintImageMaskXObjectGroup: 84,
  17243. paintImageXObject: 85,
  17244. paintInlineImageXObject: 86,
  17245. paintInlineImageXObjectGroup: 87,
  17246. paintImageXObjectRepeat: 88,
  17247. paintImageMaskXObjectRepeat: 89,
  17248. paintSolidColorImageMask: 90,
  17249. constructPath: 91
  17250. };
  17251. const PasswordResponses = {
  17252. NEED_PASSWORD: 1,
  17253. INCORRECT_PASSWORD: 2
  17254. };
  17255. let verbosity = VerbosityLevel.WARNINGS;
  17256. function setVerbosityLevel(level) {
  17257. if (Number.isInteger(level)) {
  17258. verbosity = level;
  17259. }
  17260. }
  17261. function getVerbosityLevel() {
  17262. return verbosity;
  17263. }
  17264. function info(msg) {
  17265. if (verbosity >= VerbosityLevel.INFOS) {
  17266. console.log(`Info: ${msg}`);
  17267. }
  17268. }
  17269. function warn(msg) {
  17270. if (verbosity >= VerbosityLevel.WARNINGS) {
  17271. console.log(`Warning: ${msg}`);
  17272. }
  17273. }
  17274. function unreachable(msg) {
  17275. throw new Error(msg);
  17276. }
  17277. function assert(cond, msg) {
  17278. if (!cond) {
  17279. unreachable(msg);
  17280. }
  17281. }
  17282. function _isValidProtocol(url) {
  17283. switch (url?.protocol) {
  17284. case "http:":
  17285. case "https:":
  17286. case "ftp:":
  17287. case "mailto:":
  17288. case "tel:":
  17289. return true;
  17290. default:
  17291. return false;
  17292. }
  17293. }
  17294. function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
  17295. if (!url) {
  17296. return null;
  17297. }
  17298. try {
  17299. if (options && typeof url === "string") {
  17300. if (options.addDefaultProtocol && url.startsWith("www.")) {
  17301. const dots = url.match(/\./g);
  17302. if (dots?.length >= 2) {
  17303. url = `http://${url}`;
  17304. }
  17305. }
  17306. if (options.tryConvertEncoding) {
  17307. try {
  17308. url = stringToUTF8String(url);
  17309. } catch {}
  17310. }
  17311. }
  17312. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  17313. if (_isValidProtocol(absoluteUrl)) {
  17314. return absoluteUrl;
  17315. }
  17316. } catch {}
  17317. return null;
  17318. }
  17319. function shadow(obj, prop, value, nonSerializable = false) {
  17320. Object.defineProperty(obj, prop, {
  17321. value,
  17322. enumerable: !nonSerializable,
  17323. configurable: true,
  17324. writable: false
  17325. });
  17326. return value;
  17327. }
  17328. const BaseException = function BaseExceptionClosure() {
  17329. function BaseException(message, name) {
  17330. if (this.constructor === BaseException) {
  17331. unreachable("Cannot initialize BaseException.");
  17332. }
  17333. this.message = message;
  17334. this.name = name;
  17335. }
  17336. BaseException.prototype = new Error();
  17337. BaseException.constructor = BaseException;
  17338. return BaseException;
  17339. }();
  17340. class PasswordException extends BaseException {
  17341. constructor(msg, code) {
  17342. super(msg, "PasswordException");
  17343. this.code = code;
  17344. }
  17345. }
  17346. class UnknownErrorException extends BaseException {
  17347. constructor(msg, details) {
  17348. super(msg, "UnknownErrorException");
  17349. this.details = details;
  17350. }
  17351. }
  17352. class InvalidPDFException extends BaseException {
  17353. constructor(msg) {
  17354. super(msg, "InvalidPDFException");
  17355. }
  17356. }
  17357. class MissingPDFException extends BaseException {
  17358. constructor(msg) {
  17359. super(msg, "MissingPDFException");
  17360. }
  17361. }
  17362. class UnexpectedResponseException extends BaseException {
  17363. constructor(msg, status) {
  17364. super(msg, "UnexpectedResponseException");
  17365. this.status = status;
  17366. }
  17367. }
  17368. class FormatError extends BaseException {
  17369. constructor(msg) {
  17370. super(msg, "FormatError");
  17371. }
  17372. }
  17373. class AbortException extends BaseException {
  17374. constructor(msg) {
  17375. super(msg, "AbortException");
  17376. }
  17377. }
  17378. function bytesToString(bytes) {
  17379. if (typeof bytes !== "object" || bytes?.length === undefined) {
  17380. unreachable("Invalid argument for bytesToString");
  17381. }
  17382. const length = bytes.length;
  17383. const MAX_ARGUMENT_COUNT = 8192;
  17384. if (length < MAX_ARGUMENT_COUNT) {
  17385. return String.fromCharCode.apply(null, bytes);
  17386. }
  17387. const strBuf = [];
  17388. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  17389. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  17390. const chunk = bytes.subarray(i, chunkEnd);
  17391. strBuf.push(String.fromCharCode.apply(null, chunk));
  17392. }
  17393. return strBuf.join("");
  17394. }
  17395. function stringToBytes(str) {
  17396. if (typeof str !== "string") {
  17397. unreachable("Invalid argument for stringToBytes");
  17398. }
  17399. const length = str.length;
  17400. const bytes = new Uint8Array(length);
  17401. for (let i = 0; i < length; ++i) {
  17402. bytes[i] = str.charCodeAt(i) & 0xff;
  17403. }
  17404. return bytes;
  17405. }
  17406. function string32(value) {
  17407. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  17408. }
  17409. function objectSize(obj) {
  17410. return Object.keys(obj).length;
  17411. }
  17412. function objectFromMap(map) {
  17413. const obj = Object.create(null);
  17414. for (const [key, value] of map) {
  17415. obj[key] = value;
  17416. }
  17417. return obj;
  17418. }
  17419. function isLittleEndian() {
  17420. const buffer8 = new Uint8Array(4);
  17421. buffer8[0] = 1;
  17422. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  17423. return view32[0] === 1;
  17424. }
  17425. function isEvalSupported() {
  17426. try {
  17427. new Function("");
  17428. return true;
  17429. } catch {
  17430. return false;
  17431. }
  17432. }
  17433. class FeatureTest {
  17434. static get isLittleEndian() {
  17435. return shadow(this, "isLittleEndian", isLittleEndian());
  17436. }
  17437. static get isEvalSupported() {
  17438. return shadow(this, "isEvalSupported", isEvalSupported());
  17439. }
  17440. static get isOffscreenCanvasSupported() {
  17441. return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
  17442. }
  17443. static get platform() {
  17444. if (typeof navigator !== "undefined" && typeof navigator?.platform === "string") {
  17445. return shadow(this, "platform", {
  17446. isMac: navigator.platform.includes("Mac")
  17447. });
  17448. }
  17449. return shadow(this, "platform", {
  17450. isMac: false
  17451. });
  17452. }
  17453. static get isCSSRoundSupported() {
  17454. return shadow(this, "isCSSRoundSupported", globalThis.CSS?.supports?.("width: round(1.5px, 1px)"));
  17455. }
  17456. }
  17457. const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
  17458. class Util {
  17459. static makeHexColor(r, g, b) {
  17460. return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
  17461. }
  17462. static scaleMinMax(transform, minMax) {
  17463. let temp;
  17464. if (transform[0]) {
  17465. if (transform[0] < 0) {
  17466. temp = minMax[0];
  17467. minMax[0] = minMax[1];
  17468. minMax[1] = temp;
  17469. }
  17470. minMax[0] *= transform[0];
  17471. minMax[1] *= transform[0];
  17472. if (transform[3] < 0) {
  17473. temp = minMax[2];
  17474. minMax[2] = minMax[3];
  17475. minMax[3] = temp;
  17476. }
  17477. minMax[2] *= transform[3];
  17478. minMax[3] *= transform[3];
  17479. } else {
  17480. temp = minMax[0];
  17481. minMax[0] = minMax[2];
  17482. minMax[2] = temp;
  17483. temp = minMax[1];
  17484. minMax[1] = minMax[3];
  17485. minMax[3] = temp;
  17486. if (transform[1] < 0) {
  17487. temp = minMax[2];
  17488. minMax[2] = minMax[3];
  17489. minMax[3] = temp;
  17490. }
  17491. minMax[2] *= transform[1];
  17492. minMax[3] *= transform[1];
  17493. if (transform[2] < 0) {
  17494. temp = minMax[0];
  17495. minMax[0] = minMax[1];
  17496. minMax[1] = temp;
  17497. }
  17498. minMax[0] *= transform[2];
  17499. minMax[1] *= transform[2];
  17500. }
  17501. minMax[0] += transform[4];
  17502. minMax[1] += transform[4];
  17503. minMax[2] += transform[5];
  17504. minMax[3] += transform[5];
  17505. }
  17506. static transform(m1, m2) {
  17507. return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]];
  17508. }
  17509. static applyTransform(p, m) {
  17510. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  17511. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  17512. return [xt, yt];
  17513. }
  17514. static applyInverseTransform(p, m) {
  17515. const d = m[0] * m[3] - m[1] * m[2];
  17516. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  17517. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  17518. return [xt, yt];
  17519. }
  17520. static getAxialAlignedBoundingBox(r, m) {
  17521. const p1 = this.applyTransform(r, m);
  17522. const p2 = this.applyTransform(r.slice(2, 4), m);
  17523. const p3 = this.applyTransform([r[0], r[3]], m);
  17524. const p4 = this.applyTransform([r[2], r[1]], m);
  17525. return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])];
  17526. }
  17527. static inverseTransform(m) {
  17528. const d = m[0] * m[3] - m[1] * m[2];
  17529. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  17530. }
  17531. static singularValueDecompose2dScale(m) {
  17532. const transpose = [m[0], m[2], m[1], m[3]];
  17533. const a = m[0] * transpose[0] + m[1] * transpose[2];
  17534. const b = m[0] * transpose[1] + m[1] * transpose[3];
  17535. const c = m[2] * transpose[0] + m[3] * transpose[2];
  17536. const d = m[2] * transpose[1] + m[3] * transpose[3];
  17537. const first = (a + d) / 2;
  17538. const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
  17539. const sx = first + second || 1;
  17540. const sy = first - second || 1;
  17541. return [Math.sqrt(sx), Math.sqrt(sy)];
  17542. }
  17543. static normalizeRect(rect) {
  17544. const r = rect.slice(0);
  17545. if (rect[0] > rect[2]) {
  17546. r[0] = rect[2];
  17547. r[2] = rect[0];
  17548. }
  17549. if (rect[1] > rect[3]) {
  17550. r[1] = rect[3];
  17551. r[3] = rect[1];
  17552. }
  17553. return r;
  17554. }
  17555. static intersect(rect1, rect2) {
  17556. const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
  17557. const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
  17558. if (xLow > xHigh) {
  17559. return null;
  17560. }
  17561. const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
  17562. const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
  17563. if (yLow > yHigh) {
  17564. return null;
  17565. }
  17566. return [xLow, yLow, xHigh, yHigh];
  17567. }
  17568. static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
  17569. const tvalues = [],
  17570. bounds = [[], []];
  17571. let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  17572. for (let i = 0; i < 2; ++i) {
  17573. if (i === 0) {
  17574. b = 6 * x0 - 12 * x1 + 6 * x2;
  17575. a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
  17576. c = 3 * x1 - 3 * x0;
  17577. } else {
  17578. b = 6 * y0 - 12 * y1 + 6 * y2;
  17579. a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
  17580. c = 3 * y1 - 3 * y0;
  17581. }
  17582. if (Math.abs(a) < 1e-12) {
  17583. if (Math.abs(b) < 1e-12) {
  17584. continue;
  17585. }
  17586. t = -c / b;
  17587. if (0 < t && t < 1) {
  17588. tvalues.push(t);
  17589. }
  17590. continue;
  17591. }
  17592. b2ac = b * b - 4 * c * a;
  17593. sqrtb2ac = Math.sqrt(b2ac);
  17594. if (b2ac < 0) {
  17595. continue;
  17596. }
  17597. t1 = (-b + sqrtb2ac) / (2 * a);
  17598. if (0 < t1 && t1 < 1) {
  17599. tvalues.push(t1);
  17600. }
  17601. t2 = (-b - sqrtb2ac) / (2 * a);
  17602. if (0 < t2 && t2 < 1) {
  17603. tvalues.push(t2);
  17604. }
  17605. }
  17606. let j = tvalues.length,
  17607. mt;
  17608. const jlen = j;
  17609. while (j--) {
  17610. t = tvalues[j];
  17611. mt = 1 - t;
  17612. bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
  17613. bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
  17614. }
  17615. bounds[0][jlen] = x0;
  17616. bounds[1][jlen] = y0;
  17617. bounds[0][jlen + 1] = x3;
  17618. bounds[1][jlen + 1] = y3;
  17619. bounds[0].length = bounds[1].length = jlen + 2;
  17620. return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
  17621. }
  17622. }
  17623. const PDFStringTranslateTable = (/* unused pure expression or super */ null && ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2d8, 0x2c7, 0x2c6, 0x2d9, 0x2dd, 0x2db, 0x2da, 0x2dc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018, 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x141, 0x152, 0x160, 0x178, 0x17d, 0x131, 0x142, 0x153, 0x161, 0x17e, 0, 0x20ac]));
  17624. function stringToPDFString(str) {
  17625. if (str[0] >= "\xEF") {
  17626. let encoding;
  17627. if (str[0] === "\xFE" && str[1] === "\xFF") {
  17628. encoding = "utf-16be";
  17629. if (str.length % 2 === 1) {
  17630. str = str.slice(0, -1);
  17631. }
  17632. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  17633. encoding = "utf-16le";
  17634. if (str.length % 2 === 1) {
  17635. str = str.slice(0, -1);
  17636. }
  17637. } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
  17638. encoding = "utf-8";
  17639. }
  17640. if (encoding) {
  17641. try {
  17642. const decoder = new TextDecoder(encoding, {
  17643. fatal: true
  17644. });
  17645. const buffer = stringToBytes(str);
  17646. const decoded = decoder.decode(buffer);
  17647. if (!decoded.includes("\x1b")) {
  17648. return decoded;
  17649. }
  17650. return decoded.replaceAll(/\x1b[^\x1b]*(?:\x1b|$)/g, "");
  17651. } catch (ex) {
  17652. warn(`stringToPDFString: "${ex}".`);
  17653. }
  17654. }
  17655. }
  17656. const strBuf = [];
  17657. for (let i = 0, ii = str.length; i < ii; i++) {
  17658. const charCode = str.charCodeAt(i);
  17659. if (charCode === 0x1b) {
  17660. while (++i < ii && str.charCodeAt(i) !== 0x1b) {}
  17661. continue;
  17662. }
  17663. const code = PDFStringTranslateTable[charCode];
  17664. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  17665. }
  17666. return strBuf.join("");
  17667. }
  17668. function stringToUTF8String(str) {
  17669. return decodeURIComponent(escape(str));
  17670. }
  17671. function utf8StringToString(str) {
  17672. return unescape(encodeURIComponent(str));
  17673. }
  17674. function isArrayBuffer(v) {
  17675. return typeof v === "object" && v?.byteLength !== undefined;
  17676. }
  17677. function isArrayEqual(arr1, arr2) {
  17678. if (arr1.length !== arr2.length) {
  17679. return false;
  17680. }
  17681. for (let i = 0, ii = arr1.length; i < ii; i++) {
  17682. if (arr1[i] !== arr2[i]) {
  17683. return false;
  17684. }
  17685. }
  17686. return true;
  17687. }
  17688. function getModificationDate(date = new Date()) {
  17689. const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")];
  17690. return buffer.join("");
  17691. }
  17692. class PromiseCapability {
  17693. #settled = false;
  17694. constructor() {
  17695. this.promise = new Promise((resolve, reject) => {
  17696. this.resolve = data => {
  17697. this.#settled = true;
  17698. resolve(data);
  17699. };
  17700. this.reject = reason => {
  17701. this.#settled = true;
  17702. reject(reason);
  17703. };
  17704. });
  17705. }
  17706. get settled() {
  17707. return this.#settled;
  17708. }
  17709. }
  17710. let NormalizeRegex = null;
  17711. let NormalizationMap = null;
  17712. function normalizeUnicode(str) {
  17713. if (!NormalizeRegex) {
  17714. NormalizeRegex = /([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu;
  17715. NormalizationMap = new Map([["ſt", "ſt"]]);
  17716. }
  17717. return str.replaceAll(NormalizeRegex, (_, p1, p2) => {
  17718. return p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2);
  17719. });
  17720. }
  17721. function getUuid() {
  17722. if (typeof crypto !== "undefined" && typeof crypto?.randomUUID === "function") {
  17723. return crypto.randomUUID();
  17724. }
  17725. const buf = new Uint8Array(32);
  17726. if (typeof crypto !== "undefined" && typeof crypto?.getRandomValues === "function") {
  17727. crypto.getRandomValues(buf);
  17728. } else {
  17729. for (let i = 0; i < 32; i++) {
  17730. buf[i] = Math.floor(Math.random() * 255);
  17731. }
  17732. }
  17733. return bytesToString(buf);
  17734. }
  17735. const AnnotationPrefix = "pdfjs_internal_id_";
  17736. /***/ })
  17737. /******/ });
  17738. /************************************************************************/
  17739. /******/ // The module cache
  17740. /******/ var __webpack_module_cache__ = {};
  17741. /******/
  17742. /******/ // The require function
  17743. /******/ function __webpack_require__(moduleId) {
  17744. /******/ // Check if module is in cache
  17745. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  17746. /******/ if (cachedModule !== undefined) {
  17747. /******/ return cachedModule.exports;
  17748. /******/ }
  17749. /******/ // Create a new module (and put it into the cache)
  17750. /******/ var module = __webpack_module_cache__[moduleId] = {
  17751. /******/ // no module.id needed
  17752. /******/ // no module.loaded needed
  17753. /******/ exports: {}
  17754. /******/ };
  17755. /******/
  17756. /******/ // Execute the module function
  17757. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  17758. /******/
  17759. /******/ // Return the exports of the module
  17760. /******/ return module.exports;
  17761. /******/ }
  17762. /******/
  17763. /************************************************************************/
  17764. /******/ /* webpack/runtime/async module */
  17765. /******/ (() => {
  17766. /******/ var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__";
  17767. /******/ var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__";
  17768. /******/ var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";
  17769. /******/ var resolveQueue = (queue) => {
  17770. /******/ if(queue && queue.d < 1) {
  17771. /******/ queue.d = 1;
  17772. /******/ queue.forEach((fn) => (fn.r--));
  17773. /******/ queue.forEach((fn) => (fn.r-- ? fn.r++ : fn()));
  17774. /******/ }
  17775. /******/ }
  17776. /******/ var wrapDeps = (deps) => (deps.map((dep) => {
  17777. /******/ if(dep !== null && typeof dep === "object") {
  17778. /******/ if(dep[webpackQueues]) return dep;
  17779. /******/ if(dep.then) {
  17780. /******/ var queue = [];
  17781. /******/ queue.d = 0;
  17782. /******/ dep.then((r) => {
  17783. /******/ obj[webpackExports] = r;
  17784. /******/ resolveQueue(queue);
  17785. /******/ }, (e) => {
  17786. /******/ obj[webpackError] = e;
  17787. /******/ resolveQueue(queue);
  17788. /******/ });
  17789. /******/ var obj = {};
  17790. /******/ obj[webpackQueues] = (fn) => (fn(queue));
  17791. /******/ return obj;
  17792. /******/ }
  17793. /******/ }
  17794. /******/ var ret = {};
  17795. /******/ ret[webpackQueues] = x => {};
  17796. /******/ ret[webpackExports] = dep;
  17797. /******/ return ret;
  17798. /******/ }));
  17799. /******/ __webpack_require__.a = (module, body, hasAwait) => {
  17800. /******/ var queue;
  17801. /******/ hasAwait && ((queue = []).d = -1);
  17802. /******/ var depQueues = new Set();
  17803. /******/ var exports = module.exports;
  17804. /******/ var currentDeps;
  17805. /******/ var outerResolve;
  17806. /******/ var reject;
  17807. /******/ var promise = new Promise((resolve, rej) => {
  17808. /******/ reject = rej;
  17809. /******/ outerResolve = resolve;
  17810. /******/ });
  17811. /******/ promise[webpackExports] = exports;
  17812. /******/ promise[webpackQueues] = (fn) => (queue && fn(queue), depQueues.forEach(fn), promise["catch"](x => {}));
  17813. /******/ module.exports = promise;
  17814. /******/ body((deps) => {
  17815. /******/ currentDeps = wrapDeps(deps);
  17816. /******/ var fn;
  17817. /******/ var getResult = () => (currentDeps.map((d) => {
  17818. /******/ if(d[webpackError]) throw d[webpackError];
  17819. /******/ return d[webpackExports];
  17820. /******/ }))
  17821. /******/ var promise = new Promise((resolve) => {
  17822. /******/ fn = () => (resolve(getResult));
  17823. /******/ fn.r = 0;
  17824. /******/ var fnQueue = (q) => (q !== queue && !depQueues.has(q) && (depQueues.add(q), q && !q.d && (fn.r++, q.push(fn))));
  17825. /******/ currentDeps.map((dep) => (dep[webpackQueues](fnQueue)));
  17826. /******/ });
  17827. /******/ return fn.r ? promise : getResult();
  17828. /******/ }, (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)));
  17829. /******/ queue && queue.d < 0 && (queue.d = 0);
  17830. /******/ };
  17831. /******/ })();
  17832. /******/
  17833. /******/ /* webpack/runtime/define property getters */
  17834. /******/ (() => {
  17835. /******/ // define getter functions for harmony exports
  17836. /******/ __webpack_require__.d = (exports, definition) => {
  17837. /******/ for(var key in definition) {
  17838. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  17839. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  17840. /******/ }
  17841. /******/ }
  17842. /******/ };
  17843. /******/ })();
  17844. /******/
  17845. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  17846. /******/ (() => {
  17847. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  17848. /******/ })();
  17849. /******/
  17850. /************************************************************************/
  17851. /******/
  17852. /******/ // startup
  17853. /******/ // Load entry module and return exports
  17854. /******/ // This entry module used 'module' so it can't be inlined
  17855. /******/ var __webpack_exports__ = __webpack_require__(907);
  17856. /******/ __webpack_exports__ = globalThis.pdfjsLib = await (globalThis.pdfjsLibPromise = __webpack_exports__);
  17857. /******/ var __webpack_exports__AbortException = __webpack_exports__.AbortException;
  17858. /******/ var __webpack_exports__AnnotationEditorLayer = __webpack_exports__.AnnotationEditorLayer;
  17859. /******/ var __webpack_exports__AnnotationEditorParamsType = __webpack_exports__.AnnotationEditorParamsType;
  17860. /******/ var __webpack_exports__AnnotationEditorType = __webpack_exports__.AnnotationEditorType;
  17861. /******/ var __webpack_exports__AnnotationEditorUIManager = __webpack_exports__.AnnotationEditorUIManager;
  17862. /******/ var __webpack_exports__AnnotationLayer = __webpack_exports__.AnnotationLayer;
  17863. /******/ var __webpack_exports__AnnotationMode = __webpack_exports__.AnnotationMode;
  17864. /******/ var __webpack_exports__CMapCompressionType = __webpack_exports__.CMapCompressionType;
  17865. /******/ var __webpack_exports__ColorPicker = __webpack_exports__.ColorPicker;
  17866. /******/ var __webpack_exports__DOMSVGFactory = __webpack_exports__.DOMSVGFactory;
  17867. /******/ var __webpack_exports__DrawLayer = __webpack_exports__.DrawLayer;
  17868. /******/ var __webpack_exports__FeatureTest = __webpack_exports__.FeatureTest;
  17869. /******/ var __webpack_exports__GlobalWorkerOptions = __webpack_exports__.GlobalWorkerOptions;
  17870. /******/ var __webpack_exports__ImageKind = __webpack_exports__.ImageKind;
  17871. /******/ var __webpack_exports__InvalidPDFException = __webpack_exports__.InvalidPDFException;
  17872. /******/ var __webpack_exports__MissingPDFException = __webpack_exports__.MissingPDFException;
  17873. /******/ var __webpack_exports__OPS = __webpack_exports__.OPS;
  17874. /******/ var __webpack_exports__Outliner = __webpack_exports__.Outliner;
  17875. /******/ var __webpack_exports__PDFDataRangeTransport = __webpack_exports__.PDFDataRangeTransport;
  17876. /******/ var __webpack_exports__PDFDateString = __webpack_exports__.PDFDateString;
  17877. /******/ var __webpack_exports__PDFWorker = __webpack_exports__.PDFWorker;
  17878. /******/ var __webpack_exports__PasswordResponses = __webpack_exports__.PasswordResponses;
  17879. /******/ var __webpack_exports__PermissionFlag = __webpack_exports__.PermissionFlag;
  17880. /******/ var __webpack_exports__PixelsPerInch = __webpack_exports__.PixelsPerInch;
  17881. /******/ var __webpack_exports__PromiseCapability = __webpack_exports__.PromiseCapability;
  17882. /******/ var __webpack_exports__RenderingCancelledException = __webpack_exports__.RenderingCancelledException;
  17883. /******/ var __webpack_exports__UnexpectedResponseException = __webpack_exports__.UnexpectedResponseException;
  17884. /******/ var __webpack_exports__Util = __webpack_exports__.Util;
  17885. /******/ var __webpack_exports__VerbosityLevel = __webpack_exports__.VerbosityLevel;
  17886. /******/ var __webpack_exports__XfaLayer = __webpack_exports__.XfaLayer;
  17887. /******/ var __webpack_exports__build = __webpack_exports__.build;
  17888. /******/ var __webpack_exports__createValidAbsoluteUrl = __webpack_exports__.createValidAbsoluteUrl;
  17889. /******/ var __webpack_exports__fetchData = __webpack_exports__.fetchData;
  17890. /******/ var __webpack_exports__getDocument = __webpack_exports__.getDocument;
  17891. /******/ var __webpack_exports__getFilenameFromUrl = __webpack_exports__.getFilenameFromUrl;
  17892. /******/ var __webpack_exports__getPdfFilenameFromUrl = __webpack_exports__.getPdfFilenameFromUrl;
  17893. /******/ var __webpack_exports__getXfaPageViewport = __webpack_exports__.getXfaPageViewport;
  17894. /******/ var __webpack_exports__isDataScheme = __webpack_exports__.isDataScheme;
  17895. /******/ var __webpack_exports__isPdfFile = __webpack_exports__.isPdfFile;
  17896. /******/ var __webpack_exports__noContextMenu = __webpack_exports__.noContextMenu;
  17897. /******/ var __webpack_exports__normalizeUnicode = __webpack_exports__.normalizeUnicode;
  17898. /******/ var __webpack_exports__renderTextLayer = __webpack_exports__.renderTextLayer;
  17899. /******/ var __webpack_exports__setLayerDimensions = __webpack_exports__.setLayerDimensions;
  17900. /******/ var __webpack_exports__shadow = __webpack_exports__.shadow;
  17901. /******/ var __webpack_exports__updateTextLayer = __webpack_exports__.updateTextLayer;
  17902. /******/ var __webpack_exports__version = __webpack_exports__.version;
  17903. /******/ export { __webpack_exports__AbortException as AbortException, __webpack_exports__AnnotationEditorLayer as AnnotationEditorLayer, __webpack_exports__AnnotationEditorParamsType as AnnotationEditorParamsType, __webpack_exports__AnnotationEditorType as AnnotationEditorType, __webpack_exports__AnnotationEditorUIManager as AnnotationEditorUIManager, __webpack_exports__AnnotationLayer as AnnotationLayer, __webpack_exports__AnnotationMode as AnnotationMode, __webpack_exports__CMapCompressionType as CMapCompressionType, __webpack_exports__ColorPicker as ColorPicker, __webpack_exports__DOMSVGFactory as DOMSVGFactory, __webpack_exports__DrawLayer as DrawLayer, __webpack_exports__FeatureTest as FeatureTest, __webpack_exports__GlobalWorkerOptions as GlobalWorkerOptions, __webpack_exports__ImageKind as ImageKind, __webpack_exports__InvalidPDFException as InvalidPDFException, __webpack_exports__MissingPDFException as MissingPDFException, __webpack_exports__OPS as OPS, __webpack_exports__Outliner as Outliner, __webpack_exports__PDFDataRangeTransport as PDFDataRangeTransport, __webpack_exports__PDFDateString as PDFDateString, __webpack_exports__PDFWorker as PDFWorker, __webpack_exports__PasswordResponses as PasswordResponses, __webpack_exports__PermissionFlag as PermissionFlag, __webpack_exports__PixelsPerInch as PixelsPerInch, __webpack_exports__PromiseCapability as PromiseCapability, __webpack_exports__RenderingCancelledException as RenderingCancelledException, __webpack_exports__UnexpectedResponseException as UnexpectedResponseException, __webpack_exports__Util as Util, __webpack_exports__VerbosityLevel as VerbosityLevel, __webpack_exports__XfaLayer as XfaLayer, __webpack_exports__build as build, __webpack_exports__createValidAbsoluteUrl as createValidAbsoluteUrl, __webpack_exports__fetchData as fetchData, __webpack_exports__getDocument as getDocument, __webpack_exports__getFilenameFromUrl as getFilenameFromUrl, __webpack_exports__getPdfFilenameFromUrl as getPdfFilenameFromUrl, __webpack_exports__getXfaPageViewport as getXfaPageViewport, __webpack_exports__isDataScheme as isDataScheme, __webpack_exports__isPdfFile as isPdfFile, __webpack_exports__noContextMenu as noContextMenu, __webpack_exports__normalizeUnicode as normalizeUnicode, __webpack_exports__renderTextLayer as renderTextLayer, __webpack_exports__setLayerDimensions as setLayerDimensions, __webpack_exports__shadow as shadow, __webpack_exports__updateTextLayer as updateTextLayer, __webpack_exports__version as version };
  17904. /******/
  17905. //# sourceMappingURL=pdf.mjs.map